ark_track.c 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502
  1. #include <linux/kernel.h>
  2. #include <linux/proc_fs.h>
  3. #include <linux/platform_device.h>
  4. #include <asm/setup.h>
  5. #include <linux/zlib.h>
  6. #include <linux/cdev.h>
  7. #include "ark_track.h"
  8. #include "ark1668e_carback.h"
  9. #include "ark_mcu.h"
  10. #include <asm/cacheflush.h>
  11. #include <linux/dma-mapping.h>
  12. #include <linux/vmalloc.h>
  13. const idmap_info radar_idmap[RADAR_MAX] =
  14. {
  15. //FL
  16. { "FL_00",FL_00,0},
  17. { "FL_01",FL_01,0},
  18. { "FL_02",FL_02,0},
  19. { "FL_03",FL_03,0},
  20. { "FL_04",FL_04,0},
  21. { "FL_05",FL_05,0},
  22. { "FL_06",FL_06,0},
  23. { "FL_10",FL_10,0},
  24. { "FL_11",FL_11,0},
  25. { "FL_12",FL_12,0},
  26. { "FL_13",FL_13,0},
  27. { "FL_14",FL_14,0},
  28. { "FL_15",FL_15,0},
  29. { "FL_16",FL_16,0},
  30. { "FL_20",FL_20,0},
  31. { "FL_21",FL_21,0},
  32. { "FL_22",FL_22,0},
  33. { "FL_23",FL_23,0},
  34. { "FL_24",FL_24,0},
  35. { "FL_25",FL_25,0},
  36. { "FL_26",FL_26,0},
  37. { "FL_30",FL_30,0},
  38. { "FL_31",FL_31,0},
  39. { "FL_32",FL_32,0},
  40. { "FL_33",FL_33,0},
  41. { "FL_34",FL_34,0},
  42. { "FL_35",FL_35,0},
  43. { "FL_36",FL_36,0},
  44. { "FL_40",FL_40,0},
  45. { "FL_41",FL_41,0},
  46. { "FL_42",FL_42,0},
  47. { "FL_43",FL_43,0},
  48. { "FL_44",FL_44,0},
  49. { "FL_45",FL_45,0},
  50. { "FL_46",FL_46,0},
  51. { "FL_50",FL_50,0},
  52. { "FL_51",FL_51,0},
  53. { "FL_52",FL_52,0},
  54. { "FL_53",FL_53,0},
  55. { "FL_54",FL_54,0},
  56. { "FL_55",FL_55,0},
  57. { "FL_56",FL_56,0},
  58. { "FL_60",FL_60,0},
  59. { "FL_61",FL_61,0},
  60. { "FL_62",FL_62,0},
  61. { "FL_63",FL_63,0},
  62. { "FL_64",FL_64,0},
  63. { "FL_65",FL_65,0},
  64. { "FL_66",FL_66,0},
  65. //FR
  66. { "FR_00",FR_00,1},
  67. { "FR_01",FR_01,1},
  68. { "FR_02",FR_02,1},
  69. { "FR_03",FR_03,1},
  70. { "FR_04",FR_04,1},
  71. { "FR_05",FR_05,1},
  72. { "FR_06",FR_06,1},
  73. { "FR_10",FR_10,1},
  74. { "FR_11",FR_11,1},
  75. { "FR_12",FR_12,1},
  76. { "FR_13",FR_13,1},
  77. { "FR_14",FR_14,1},
  78. { "FR_15",FR_15,1},
  79. { "FR_16",FR_16,1},
  80. { "FR_20",FR_20,1},
  81. { "FR_21",FR_21,1},
  82. { "FR_22",FR_22,1},
  83. { "FR_23",FR_23,1},
  84. { "FR_24",FR_24,1},
  85. { "FR_25",FR_25,1},
  86. { "FR_26",FR_26,1},
  87. { "FR_30",FR_30,1},
  88. { "FR_31",FR_31,1},
  89. { "FR_32",FR_32,1},
  90. { "FR_33",FR_33,1},
  91. { "FR_34",FR_34,1},
  92. { "FR_35",FR_35,1},
  93. { "FR_36",FR_36,1},
  94. { "FR_40",FR_40,1},
  95. { "FR_41",FR_41,1},
  96. { "FR_42",FR_42,1},
  97. { "FR_43",FR_43,1},
  98. { "FR_44",FR_44,1},
  99. { "FR_45",FR_45,1},
  100. { "FR_46",FR_46,1},
  101. { "FR_50",FR_50,1},
  102. { "FR_51",FR_51,1},
  103. { "FR_52",FR_52,1},
  104. { "FR_53",FR_53,1},
  105. { "FR_54",FR_54,1},
  106. { "FR_55",FR_55,1},
  107. { "FR_56",FR_56,1},
  108. { "FR_60",FR_60,1},
  109. { "FR_61",FR_61,1},
  110. { "FR_62",FR_62,1},
  111. { "FR_63",FR_63,1},
  112. { "FR_64",FR_64,1},
  113. { "FR_65",FR_65,1},
  114. { "FR_66",FR_66,1},
  115. //RL
  116. { "RL_00",RL_00,2},
  117. { "RL_01",RL_01,2},
  118. { "RL_02",RL_02,2},
  119. { "RL_03",RL_03,2},
  120. { "RL_04",RL_04,2},
  121. { "RL_05",RL_05,2},
  122. { "RL_06",RL_06,2},
  123. { "RL_10",RL_10,2},
  124. { "RL_11",RL_11,2},
  125. { "RL_12",RL_12,2},
  126. { "RL_13",RL_13,2},
  127. { "RL_14",RL_14,2},
  128. { "RL_15",RL_15,2},
  129. { "RL_16",RL_16,2},
  130. { "RL_20",RL_20,2},
  131. { "RL_21",RL_21,2},
  132. { "RL_22",RL_22,2},
  133. { "RL_23",RL_23,2},
  134. { "RL_24",RL_24,2},
  135. { "RL_25",RL_25,2},
  136. { "RL_26",RL_26,2},
  137. { "RL_30",RL_30,2},
  138. { "RL_31",RL_31,2},
  139. { "RL_32",RL_32,2},
  140. { "RL_33",RL_33,2},
  141. { "RL_34",RL_34,2},
  142. { "RL_35",RL_35,2},
  143. { "RL_36",RL_36,2},
  144. { "RL_40",RL_40,2},
  145. { "RL_41",RL_41,2},
  146. { "RL_42",RL_42,2},
  147. { "RL_43",RL_43,2},
  148. { "RL_44",RL_44,2},
  149. { "RL_45",RL_45,2},
  150. { "RL_46",RL_46,2},
  151. { "RL_50",RL_50,2},
  152. { "RL_51",RL_51,2},
  153. { "RL_52",RL_52,2},
  154. { "RL_53",RL_53,2},
  155. { "RL_54",RL_54,2},
  156. { "RL_55",RL_55,2},
  157. { "RL_56",RL_56,2},
  158. { "RL_60",RL_60,2},
  159. { "RL_61",RL_61,2},
  160. { "RL_62",RL_62,2},
  161. { "RL_63",RL_63,2},
  162. { "RL_64",RL_64,2},
  163. { "RL_65",RL_65,2},
  164. { "RL_66",RL_66,2},
  165. //RR
  166. { "RR_00",RR_00,3},
  167. { "RR_01",RR_01,3},
  168. { "RR_02",RR_02,3},
  169. { "RR_03",RR_03,3},
  170. { "RR_04",RR_04,3},
  171. { "RR_05",RR_05,3},
  172. { "RR_06",RR_06,3},
  173. { "RR_10",RR_10,3},
  174. { "RR_11",RR_11,3},
  175. { "RR_12",RR_12,3},
  176. { "RR_13",RR_13,3},
  177. { "RR_14",RR_14,3},
  178. { "RR_15",RR_15,3},
  179. { "RR_16",RR_16,3},
  180. { "RR_20",RR_20,3},
  181. { "RR_21",RR_21,3},
  182. { "RR_22",RR_22,3},
  183. { "RR_23",RR_23,3},
  184. { "RR_24",RR_24,3},
  185. { "RR_25",RR_25,3},
  186. { "RR_26",RR_26,3},
  187. { "RR_30",RR_30,3},
  188. { "RR_31",RR_31,3},
  189. { "RR_32",RR_32,3},
  190. { "RR_33",RR_33,3},
  191. { "RR_34",RR_34,3},
  192. { "RR_35",RR_35,3},
  193. { "RR_36",RR_36,3},
  194. { "RR_40",RR_40,3},
  195. { "RR_41",RR_41,3},
  196. { "RR_42",RR_42,3},
  197. { "RR_43",RR_43,3},
  198. { "RR_44",RR_44,3},
  199. { "RR_45",RR_45,3},
  200. { "RR_46",RR_46,3},
  201. { "RR_50",RR_50,3},
  202. { "RR_51",RR_51,3},
  203. { "RR_52",RR_52,3},
  204. { "RR_53",RR_53,3},
  205. { "RR_54",RR_54,3},
  206. { "RR_55",RR_55,3},
  207. { "RR_56",RR_56,3},
  208. { "RR_60",RR_60,3},
  209. { "RR_61",RR_61,3},
  210. { "RR_62",RR_62,3},
  211. { "RR_63",RR_63,3},
  212. { "RR_64",RR_64,3},
  213. { "RR_65",RR_65,3},
  214. { "RR_66",RR_66,3},
  215. };
  216. extern int dvr_detect_carback_signal(void);
  217. track_context *g_ptrack_context;
  218. static user_header* g_pheader_buf;
  219. static z_stream stream;
  220. static int initialized;
  221. unsigned int track_pic_id;
  222. unsigned int radar_pic_id;
  223. unsigned int car_pic_id;
  224. unsigned int track2_pic_id;//small track for vbox
  225. extern struct carback_context* g_carback_context;
  226. extern int first_draw_track;
  227. static user2_header* g_pheader2_buf;
  228. track_context2 *g_ptrack_context2 = NULL;
  229. #if 0
  230. static unsigned int get_time_ms(void)
  231. {
  232. struct timeval tv;
  233. //float s;
  234. do_gettimeofday(&tv);
  235. //s = tv.tv_usec; s *= 0.000001; s += tv.tv_sec;
  236. return tv.tv_sec * 1000 + tv.tv_usec / 1000;
  237. }
  238. #endif
  239. static void show_header_info(void)
  240. {
  241. user_header* p = g_pheader_buf;
  242. if(p == NULL) {
  243. printk(KERN_ERR "header_info_show error!\n");
  244. return;
  245. }
  246. ARKTRACK_DBGPRTK("header_buf ===>identity=0x%0x track_total=%d car_total=%d signal_total= %d radar_total=%d file_type=0x%0x file_size=0x%0x\n",\
  247. p->identity,p->track_total,p->car_total,p->signal_total,p->radar_total,p->file_type,p->file_size);
  248. ARKTRACK_DBGPRTK("track rect ===> pos_x=%d pos_y=%d width=%d height=%d\n",p->track_rect.pos_x,\
  249. p->track_rect.pos_y,p->track_rect.width,p->track_rect.height);
  250. ARKTRACK_DBGPRTK("car rect ===> pos_x=%d pos_y=%d width=%d height=%d\n",p->car_rect.pos_x,\
  251. p->car_rect.pos_y,p->car_rect.width,p->car_rect.height);
  252. ARKTRACK_DBGPRTK("signal rect ===> pos_x=%d pos_y=%d width=%d height=%d\n",p->signal_rect.pos_x,\
  253. p->signal_rect.pos_y,p->signal_rect.width,p->signal_rect.height);
  254. ARKTRACK_DBGPRTK("radar0 rect===> pos_x=%d pos_y=%d width=%d height=%d\n",p->radar_rect[0].pos_x,\
  255. p->radar_rect[0].pos_y,p->radar_rect[0].width,p->radar_rect[0].height);
  256. ARKTRACK_DBGPRTK("radar1 rect===> pos_x=%d pos_y=%d width=%d height=%d\n",p->radar_rect[1].pos_x,\
  257. p->radar_rect[1].pos_y,p->radar_rect[1].width,p->radar_rect[1].height);
  258. ARKTRACK_DBGPRTK("radar2 rect===> pos_x=%d pos_y=%d width=%d height=%d\n",p->radar_rect[2].pos_x,\
  259. p->radar_rect[2].pos_y,p->radar_rect[2].width,p->radar_rect[2].height);
  260. ARKTRACK_DBGPRTK("radar3 rect===> pos_x=%d pos_y=%d width=%d height=%d\n",p->radar_rect[3].pos_x,\
  261. p->radar_rect[3].pos_y,p->radar_rect[3].width,p->radar_rect[3].height);
  262. ARKTRACK_DBGPRTK("track2 rect===> pos_x=%d pos_y=%d width=%d height=%d\n",p->track2_rect.pos_x,\
  263. p->track2_rect.pos_y,p->track2_rect.width,p->track2_rect.height);
  264. ARKTRACK_DBGPRTK("track[0] image===> image_type=%d image_store_id=%d image_id=0x%0x image_offset=0x%0x image_size=0x%0x\n",\
  265. p->track[0].image_type,p->track[0].image_store_id,p->track[0].image_id,p->track[0].image_offset,p->track[0].image_size);
  266. ARKTRACK_DBGPRTK("car[0] image===> image_type=%d image_store_id=%d image_id=0x%0x image_offset=0x%0x image_size=0x%0x\n",\
  267. p->car[0].image_type,p->car[0].image_store_id,p->car[0].image_id,p->car[0].image_offset,p->car[0].image_size);
  268. ARKTRACK_DBGPRTK("signal[0] image===> image_type=%d image_store_id=%d image_id=0x%0x image_offset=0x%0x image_size=0x%0x\n",\
  269. p->signal[0].image_type,p->signal[0].image_store_id,p->signal[0].image_id,p->signal[0].image_offset,p->signal[0].image_size);
  270. ARKTRACK_DBGPRTK("radar[1] image===> image_type=%d image_store_id=%d image_id=0x%0x image_offset=0x%0x image_size=0x%0x\n",\
  271. p->radar[1].image_type,p->radar[1].image_store_id,p->radar[1].image_id,p->radar[1].image_offset,p->radar[1].image_size);
  272. ARKTRACK_DBGPRTK("track2[0]image===> image_type=%d image_store_id=%d image_id=0x%0x image_offset=0x%0x image_size=0x%0x\n",\
  273. p->track2[0].image_type,p->track2[0].image_store_id,p->track2[0].image_id,p->track2[0].image_offset,p->track2[0].image_size);
  274. }
  275. static int check_header_info(void)
  276. {
  277. int i;
  278. int fail = -1;
  279. user_header* p = g_pheader_buf;
  280. //check header info
  281. if(p->identity !=ARK_IDENTITY || p->track_total == 0 || p->file_size <= sizeof(user_header)){
  282. printk(KERN_ERR "identity info error!\n");
  283. return fail;
  284. }
  285. if(p->track_rect.width > g_carback_context->screen_width || p->track_rect.width == 0){
  286. printk(KERN_ERR "track rect width error!\n");
  287. return fail;
  288. }
  289. if(p->track_rect.height > g_carback_context->screen_height || p->track_rect.height == 0){
  290. printk(KERN_ERR "track rect height error!\n");
  291. return fail;
  292. }
  293. for(i = 0;i < TRACK_MAX; i++){
  294. if(TRACK_MAX < p->track[i].image_store_id){
  295. printk(KERN_ERR "track[%d].image_store_id error!\n",i);
  296. return fail;
  297. }
  298. }
  299. for(i = 0;i < CAR_MAX; i++){
  300. if(CAR_MAX < p->car[i].image_store_id){
  301. printk(KERN_ERR "track[%d].image_store_id error!\n",i);
  302. return fail;
  303. }
  304. }
  305. for(i = 0;i < p->radar_total; i++){
  306. if(RADAR_MAX < p->radar[i].image_store_id){
  307. printk(KERN_ERR "track[%d].image_store_id error!\n",i);
  308. return fail;
  309. }
  310. }
  311. for(i = 0;i < TRACK_MAX; i++){
  312. if(TRACK_MAX < p->track2[i].image_store_id){
  313. printk(KERN_ERR "track2[%d].image_store_id error!\n",i);
  314. return fail;
  315. }
  316. }
  317. return 0;
  318. }
  319. static bool is_radar_image_id(unsigned int image_id){
  320. int i;
  321. for(i = 0;i < RADAR_MAX; i++){
  322. if(radar_idmap[i].image_id == image_id){
  323. return true;
  324. }
  325. }
  326. return false;
  327. }
  328. int set_disp_track_id(unsigned int track_id)
  329. {
  330. static unsigned int pre_id = IMAGE_ID_NONE;
  331. track_context *p = g_ptrack_context;
  332. if(p == NULL){
  333. printk(KERN_ALERT "%s: g_ptrack_context NULL, error!\n", __FUNCTION__);
  334. return -1;
  335. }
  336. if(track_id >= TRACK_MAX && track_id < IMAGE_ID_NONE){
  337. printk(KERN_ERR "set disp track image id error!\n" );
  338. return -1;
  339. }
  340. if(pre_id != track_id || IMAGE_ID_NONE == track_id){
  341. p->disp_track_id = track_id;
  342. pre_id = track_id;
  343. }
  344. return 0;
  345. }
  346. int set_disp_car_id(unsigned int car_id)
  347. {
  348. static unsigned int pre_id = IMAGE_ID_NONE;
  349. track_context *p = g_ptrack_context;
  350. if(p == NULL){
  351. printk(KERN_ALERT "%s: g_ptrack_context NULL, error!\n", __FUNCTION__);
  352. return -1;
  353. }
  354. if(car_id >= CAR_MAX && car_id < IMAGE_ID_NONE){
  355. printk(KERN_ERR "set disp car image id error!\n" );
  356. return -1;
  357. }
  358. if(pre_id != car_id || IMAGE_ID_NONE == car_id){
  359. p->disp_car_id = car_id;
  360. pre_id = car_id;
  361. }
  362. return 0;
  363. }
  364. int set_disp_radar_id(unsigned int radar_id)
  365. {
  366. static unsigned int pre_id = IMAGE_ID_NONE;
  367. track_context *p = g_ptrack_context;
  368. unsigned int image_id;
  369. unsigned char channel;
  370. unsigned int mask = 0xff000000;
  371. unsigned int disp_id = 0;
  372. if(p == NULL){
  373. printk(KERN_ALERT "%s: g_ptrack_context NULL, error!\n", __FUNCTION__);
  374. return -1;
  375. }
  376. if(IMAGE_ID_NONE == radar_id){
  377. p->disp_radar_id = IMAGE_ID_NONE;
  378. pre_id = IMAGE_ID_NONE;
  379. return 0;
  380. }
  381. if(pre_id == radar_id){
  382. return 0;
  383. }
  384. for(channel = RADAR_CHANNEL_FL; channel <= RADAR_CHANNEL_RR;channel++){
  385. image_id = radar_id & (mask >> 8*channel);
  386. if(!is_radar_image_id(image_id)){
  387. printk(KERN_ERR "set disp radar id channel=%d ,error!\n",channel);
  388. continue;
  389. }
  390. disp_id |= image_id;
  391. }
  392. p->disp_radar_id = disp_id;
  393. pre_id = disp_id;
  394. //printk(KERN_ALERT "set disp radar id disp_id=0x%0x.\n",disp_id);
  395. return 0;
  396. }
  397. int set_disp_signal_id(unsigned int disp_signal_id)
  398. {
  399. static unsigned int pre_id = IMAGE_ID_NONE;
  400. track_context *p = g_ptrack_context;
  401. if(p == NULL){
  402. printk(KERN_ALERT "%s: g_ptrack_context NULL, error!\n", __FUNCTION__);
  403. return -1;
  404. }
  405. if(disp_signal_id >= SIGNAL_MAX && disp_signal_id < IMAGE_ID_NONE){
  406. printk(KERN_ERR "set disp signal image id error!\n" );
  407. return -1;
  408. }
  409. if(pre_id != disp_signal_id || IMAGE_ID_NONE == disp_signal_id){
  410. p->disp_signal_id = disp_signal_id;
  411. pre_id = disp_signal_id;
  412. }
  413. //printk(KERN_ALERT "++++++p->disp_signal_id = %d\n" ,p->disp_signal_id);
  414. return 0;
  415. }
  416. int set_disp_track2_id(unsigned int track2_id)
  417. {
  418. static unsigned int pre_id = IMAGE_ID_NONE;
  419. track_context *p = g_ptrack_context;
  420. if(p == NULL){
  421. printk(KERN_ALERT "%s: g_ptrack_context NULL, error!\n", __FUNCTION__);
  422. return -1;
  423. }
  424. if(track2_id >= TRACK_MAX && track2_id < IMAGE_ID_NONE){
  425. printk(KERN_ERR "set disp track2 image id error!\n" );
  426. return -1;
  427. }
  428. if(pre_id != track2_id || IMAGE_ID_NONE == track2_id){
  429. p->disp_track2_id = track2_id;
  430. pre_id = track2_id;
  431. }
  432. return 0;
  433. }
  434. /*
  435. *set_disp_mradar_id: radar new solution
  436. *
  437. *-------------------------front-----------------------
  438. *
  439. * mradar0 mradar1 mradar2 mradar3
  440. * +-----------------+
  441. * | |
  442. * | |
  443. * mradar8 | | mradar12
  444. * | |
  445. * mradar9 | | mradar13
  446. * | |
  447. * mradar10| | mradar14
  448. * | |
  449. * mradar11| | mradar15
  450. * | |
  451. * | |
  452. * +-----------------+
  453. * mradar4 mradar5 mradar6 mradar7
  454. *
  455. *-------------------------rear-----------------------
  456. */
  457. int set_disp_mradar_id(unsigned char *pimage_id)
  458. {
  459. static unsigned char pre_mradar_id[MRADAR_MAX]={0xF,0xF,0xF,0xF,0xF,0xF,0xF,0xF,0xF,0xF,0xF,0xF,0xF,0xF,0xF,0xF};
  460. unsigned char mradar_id[MRADAR_MAX];
  461. track_context2 *p = g_ptrack_context2;
  462. int i;
  463. if(p == NULL){
  464. //printk(KERN_ALERT "%s: no header2 ,set mradar id invalid!\n", __FUNCTION__);
  465. return 0;
  466. }
  467. memcpy(mradar_id, pimage_id, MRADAR_MAX);
  468. for(i = 0; i < MRADAR_MAX; i++){
  469. ARKTRACK_DBGPRTK("mradar_id[%d]=%d\n", i, mradar_id[i]);
  470. if(mradar_id[i] > 0xF){
  471. printk(KERN_ALERT "%s: mradar_id[%d]=%d, MRADAR_MAX=0xF, error.\n", __FUNCTION__, i, mradar_id[i]);
  472. return -1;
  473. }
  474. }
  475. for(i = 0; i < MRADAR_MAX; i++){
  476. if(pre_mradar_id[i] != mradar_id[i]){
  477. break;
  478. }
  479. }
  480. if(i < MRADAR_MAX){
  481. memcpy(p->disp_mradar_id, mradar_id, MRADAR_MAX);
  482. memcpy(pre_mradar_id, mradar_id, MRADAR_MAX);
  483. p->disp_mradar_id_change = 1;
  484. }
  485. return 0;
  486. }
  487. static int init_track_context(unsigned int addr)
  488. {
  489. int ret = -1;
  490. int size;
  491. int i;
  492. unsigned char *p;
  493. //printk(KERN_ALERT "init_track_context ...\n");
  494. if(addr == 0){
  495. printk(KERN_ERR "addr error!\n");
  496. return ret;
  497. }
  498. g_pheader_buf = (user_header*)addr;
  499. show_header_info();
  500. if(check_header_info() < 0){
  501. printk(KERN_ERR "identity info error!\n");
  502. return ret;
  503. }
  504. p = vzalloc(sizeof(track_context));
  505. if (p == NULL) {
  506. printk(KERN_ERR "%s %d: failed to allocate track_context\n",__FUNCTION__, __LINE__);
  507. return -ENOMEM;
  508. }
  509. g_ptrack_context = (track_context *)p;
  510. g_ptrack_context->disp_track_size = 4 * g_pheader_buf->track_rect.width * g_pheader_buf->track_rect.height;
  511. if(g_pheader_buf->track_total > 0){
  512. size = 4* g_pheader_buf->track_rect.width * g_pheader_buf->track_rect.height;
  513. p = vzalloc(size);
  514. if (p == NULL) {
  515. printk(KERN_ERR "%s %d: failed to allocate track\n",__FUNCTION__, __LINE__);
  516. ret = -ENOMEM;
  517. goto err_track2;
  518. }
  519. g_ptrack_context->disp_track_buf = p;
  520. g_ptrack_context->disp_track_size= size;
  521. }
  522. if(g_pheader_buf->car_total > 0){
  523. size = 4* g_pheader_buf->car_rect.width * g_pheader_buf->car_rect.height;
  524. p = vzalloc(size);
  525. if (p == NULL) {
  526. printk(KERN_ERR "%s %d: failed to allocate car\n",__FUNCTION__, __LINE__);
  527. ret = -ENOMEM;
  528. goto err_car;
  529. }
  530. g_ptrack_context->disp_car_buf = p;
  531. g_ptrack_context->disp_car_size= size;
  532. }
  533. if(g_pheader_buf->signal_total> 0){
  534. size = 4* g_pheader_buf->signal_rect.width * g_pheader_buf->signal_rect.height;
  535. p = vzalloc(size);
  536. if (p == NULL) {
  537. printk(KERN_ERR "%s %d: failed to allocate car\n",__FUNCTION__, __LINE__);
  538. ret = -ENOMEM;
  539. goto err_car;
  540. }
  541. g_ptrack_context->disp_signal_buf = p;
  542. g_ptrack_context->disp_signal_size= size;
  543. }
  544. if(g_pheader_buf->radar_total > 0){
  545. size = 4* g_pheader_buf->radar_rect[0].width * g_pheader_buf->radar_rect[0].height;
  546. for(i = 0; i < 4;i++){
  547. p = vzalloc(size);
  548. if (p == NULL) {
  549. printk(KERN_ERR "%s %d: failed to allocate radar\n",__FUNCTION__, __LINE__);
  550. ret = -ENOMEM;
  551. while(i-- >= 0){
  552. vfree(g_ptrack_context->disp_radar_buf[i]);
  553. }
  554. goto err_radar;
  555. }
  556. g_ptrack_context->disp_radar_buf[i] = p;
  557. g_ptrack_context->disp_radar_size = size;
  558. }
  559. }
  560. if(g_pheader_buf->track2_total > 0){
  561. size = 4* g_pheader_buf->track2_rect.width * g_pheader_buf->track2_rect.height;
  562. p = vzalloc(size);
  563. if (p == NULL) {
  564. printk(KERN_ERR "%s %d: failed to allocate track2\n",__FUNCTION__, __LINE__);
  565. ret = -ENOMEM;
  566. goto err_track2;
  567. }
  568. g_ptrack_context->disp_track2_buf = p;
  569. g_ptrack_context->disp_track2_size= size;
  570. }
  571. g_ptrack_context->pheader_buf = g_pheader_buf;
  572. g_ptrack_context->disp_xpos = g_pheader_buf->track_rect.pos_x;
  573. g_ptrack_context->disp_ypos = g_pheader_buf->track_rect.pos_y;
  574. g_ptrack_context->disp_width = g_carback_context->screen_width;
  575. g_ptrack_context->disp_height = g_carback_context->screen_height;
  576. memcpy(&g_ptrack_context->track_param,&g_pheader_buf->track_rect,sizeof(track_param_context));
  577. g_ptrack_context->file_type = g_pheader_buf->file_type;
  578. g_ptrack_context->disp_track_id = IMAGE_ID_NONE;
  579. g_ptrack_context->disp_car_id = IMAGE_ID_NONE;
  580. g_ptrack_context->disp_radar_id = IMAGE_ID_NONE;
  581. g_ptrack_context->disp_track2_id= IMAGE_ID_NONE;
  582. return 0;
  583. err_track2:
  584. for(i = 0; i < 4;i++)
  585. if(g_ptrack_context->disp_radar_buf[i])
  586. vfree(g_ptrack_context->disp_radar_buf[i]);
  587. err_radar:
  588. if(g_ptrack_context->disp_car_buf)
  589. vfree(g_ptrack_context->disp_car_buf);
  590. err_car:
  591. if(g_ptrack_context)
  592. vfree(g_ptrack_context);
  593. return ret;
  594. }
  595. static void show_header2_info(void)
  596. {
  597. user2_header* p = g_pheader2_buf;
  598. rect_info *prect;
  599. item_info *pitem;
  600. int i;
  601. if(p == NULL) {
  602. printk(KERN_ERR "header_info_show error!\n");
  603. return;
  604. }
  605. ARKTRACK_DBGPRTK("header2_buf ===>identity=0x%0x,file_type=0x%0x file_size=0x%0x\n", p->identity,p->file_type,p->file_size);
  606. for(i = 0; i < MRADAR_MAX; i++){
  607. prect = &p->mradar_rect[i];
  608. pitem = &p->mradar[i][0];
  609. ARKTRACK_DBGPRTK("mradar_rect[%d]===>total=%d, pos_x=%d pos_y=%d width=%d height=%d\n",\
  610. i, p->mradar_total[i], prect->pos_x, prect->pos_y, prect->width, prect->height);
  611. ARKTRACK_DBGPRTK("mradar[%d][0] ===> image_type=%d image_store_id=%d image_id=0x%0x image_offset=0x%0x image_size=0x%0x\n",\
  612. i, pitem->image_type, pitem->image_store_id, pitem->image_id, pitem->image_offset, pitem->image_size);
  613. }
  614. }
  615. static int check_header2_info(void)
  616. {
  617. int i, j;
  618. user2_header* p = g_pheader2_buf;
  619. if(p == NULL) {
  620. printk(KERN_ERR "check_header2_info error!\n");
  621. return -1;
  622. }
  623. //check header info
  624. if(p->identity != ARK_IDENTITY || p->file_size <= sizeof(user2_header)){
  625. printk(KERN_ERR "header2 identity info error!\n");
  626. return -1;
  627. }
  628. for(j = 0 ;j < MRADAR_MAX; j++){
  629. for(i = 0;i < MRADAR_ITEM_MAX; i++){
  630. if(MRADAR_MAX < p->mradar[j][i].image_id){
  631. printk(KERN_ALERT "track[%d].image_id error!\n",i);
  632. return -1;
  633. }
  634. }
  635. }
  636. printk(KERN_ALERT "check_header2_info success!\n");
  637. return 0;
  638. }
  639. static int init_track_context2(unsigned int addr)
  640. {
  641. unsigned int header2_addr_start;
  642. unsigned char *p;
  643. int ret = -1;
  644. int size;
  645. int i;
  646. //printk(KERN_ALERT "file_type=%0x ---> HEADER2_FILE_FLAG=%0x.\n", g_pheader_buf->file_type, HEADER2_FILE_FLAG);
  647. if((g_pheader_buf->file_type & 0x80000000) != HEADER2_FILE_FLAG){
  648. printk(KERN_ALERT "only header file.\n");
  649. return 0;
  650. }
  651. printk(KERN_ALERT "%s: start.\n", __func__);
  652. if(addr == 0){
  653. printk(KERN_ERR "addr error!\n");
  654. return -1;
  655. }
  656. //g_pheader2_buf = (user2_header*)(addr + g_pheader_buf->file_size);
  657. p = vzalloc(sizeof(user2_header));
  658. if (p == NULL) {
  659. printk(KERN_ERR "%s: failed to user2_header.\n",__FUNCTION__);
  660. return -1;
  661. }
  662. header2_addr_start = addr + g_pheader_buf->file_size;
  663. printk(KERN_ALERT "header2_addr_start=0x%0x.\n", header2_addr_start);
  664. memcpy(p, (void *)header2_addr_start, sizeof(user2_header));
  665. g_pheader2_buf = (user2_header*)p;
  666. show_header2_info();
  667. if(check_header2_info() < 0){
  668. printk(KERN_ALERT "check_header2_info failed!\n");
  669. return -1;
  670. }
  671. p = vzalloc(sizeof(track_context2));
  672. if (p == NULL) {
  673. printk(KERN_ERR "%s %d: failed to allocate track_context2\n",__FUNCTION__, __LINE__);
  674. return -1;
  675. }
  676. memset(p, 0 ,sizeof(track_context2));
  677. g_ptrack_context2 = (track_context2 *)p;
  678. g_ptrack_context2->pheader2_buf = g_pheader2_buf;
  679. g_ptrack_context2->file_type = g_pheader2_buf->file_type;
  680. memset(g_ptrack_context2->disp_mradar_id, 0x0F ,MRADAR_MAX);
  681. for(i = 0; i < MRADAR_MAX; i++){
  682. size = 4* g_pheader2_buf->mradar_rect[i].width * g_pheader2_buf->mradar_rect[i].height;
  683. p = vzalloc(size);
  684. if (p == NULL) {
  685. printk(KERN_ERR "%s %d: failed to allocate radar\n",__FUNCTION__, __LINE__);
  686. ret = -ENOMEM;
  687. while(i-- >= 0){
  688. vfree(g_ptrack_context2->disp_mradar_buf[i]);
  689. }
  690. vfree(g_pheader2_buf);
  691. return -1;
  692. }
  693. g_ptrack_context2->disp_mradar_buf[i] = p;
  694. g_ptrack_context2->disp_mradar_size[i]= size;
  695. memcpy(&g_ptrack_context2->mradar_param.mradar_rect[i], &g_pheader2_buf->mradar_rect[i], sizeof(rect_info));
  696. ARKTRACK_DBGPRTK("mradar_buf[%d]=0x%0x, size=0x%0x \n",i, p, size);
  697. }
  698. printk(KERN_ALERT "%s: success.\n", __func__);
  699. return 0;
  700. }
  701. static int get_radar_channel(unsigned int image_id){
  702. int i;
  703. int channel = -1;
  704. for(i = 0;i < RADAR_MAX; i++){
  705. if(radar_idmap[i].image_id == image_id){
  706. channel = radar_idmap[i].dis_channel;
  707. break;
  708. }
  709. }
  710. return channel;
  711. }
  712. static unsigned int get_picture_addr(enum image_type type, unsigned int id)
  713. {
  714. unsigned int offset;
  715. int i;
  716. if(type == IMAGE_TYPE_TRACK){
  717. offset = g_pheader_buf->track[id].image_offset;
  718. }
  719. else if(type == IMAGE_TYPE_CAR){
  720. offset = g_pheader_buf->car[id].image_offset;
  721. }
  722. else if(type == IMAGE_TYPE_SIGNAL){
  723. offset = g_pheader_buf->signal[id].image_offset;
  724. }
  725. else if(type == IMAGE_TYPE_RADAR){
  726. for(i = 0; i < RADAR_MAX;i++){
  727. if(g_pheader_buf->radar[i].image_id == id){
  728. offset = g_pheader_buf->radar[i].image_offset;
  729. break;
  730. }
  731. }
  732. }
  733. else if(type == IMAGE_TYPE_TRACK2){
  734. offset = g_pheader_buf->track2[id].image_offset;
  735. }
  736. return g_carback_context->track_data_virtaddr +offset;
  737. }
  738. static unsigned int get_picture_offset(enum image_type type, unsigned int id)
  739. {
  740. unsigned int offset = 0;
  741. int i;
  742. if(type == IMAGE_TYPE_TRACK){
  743. offset = g_pheader_buf->track[id].image_offset;
  744. }
  745. else if(type == IMAGE_TYPE_CAR){
  746. offset = g_pheader_buf->car[id].image_offset;
  747. }
  748. else if(type == IMAGE_TYPE_SIGNAL){
  749. offset = g_pheader_buf->signal[id].image_offset;
  750. }
  751. else if(type == IMAGE_TYPE_RADAR){
  752. for(i = 0; i < RADAR_MAX;i++){
  753. if(g_pheader_buf->radar[i].image_id == id){
  754. offset = g_pheader_buf->radar[i].image_offset;
  755. break;
  756. }
  757. }
  758. }
  759. else if(type == IMAGE_TYPE_TRACK2){
  760. offset = g_pheader_buf->track2[id].image_offset;
  761. }
  762. return offset;
  763. }
  764. static unsigned int get_picture_size(enum image_type type, unsigned int id)
  765. {
  766. unsigned int image_size = 0;
  767. int i;
  768. if(type == IMAGE_TYPE_TRACK){
  769. image_size = g_pheader_buf->track[id].image_size;
  770. }
  771. else if(type == IMAGE_TYPE_CAR){
  772. image_size = g_pheader_buf->car[id].image_size;
  773. }
  774. else if(type == IMAGE_TYPE_SIGNAL){
  775. image_size = g_pheader_buf->signal[id].image_size;
  776. }
  777. else if(type == IMAGE_TYPE_RADAR){
  778. for(i = 0; i < RADAR_MAX;i++){
  779. if(g_pheader_buf->radar[i].image_id == id){
  780. image_size = g_pheader_buf->radar[i].image_size;
  781. break;
  782. }
  783. }
  784. }
  785. else if(type == IMAGE_TYPE_TRACK2){
  786. image_size = g_pheader_buf->track2[id].image_size;
  787. }
  788. return image_size;
  789. }
  790. /* Returns length of decompressed data. */
  791. static int zlib_uncompress_block(void *dst, int dstlen, void *src, int srclen)
  792. {
  793. int err;
  794. stream.next_in = src;
  795. stream.avail_in = srclen;
  796. stream.next_out = dst;
  797. stream.avail_out = dstlen;
  798. err = zlib_inflateReset(&stream);
  799. if (err != Z_OK) {
  800. printk("zlib_inflateReset error %d\n", err);
  801. zlib_inflateEnd(&stream);
  802. zlib_inflateInit(&stream);
  803. }
  804. err = zlib_inflate(&stream, Z_FINISH);
  805. if (err != Z_STREAM_END)
  806. goto err;
  807. return stream.total_out;
  808. err:
  809. printk(KERN_ERR "Error %d while decompressing!\n", err);
  810. printk(KERN_ERR "%p(%d)->%p(%d)\n", src, srclen, dst, dstlen);
  811. return -EIO;
  812. }
  813. static int zlib_uncompress_init(void)
  814. {
  815. if (!initialized++) {
  816. stream.workspace = vmalloc(zlib_inflate_workspacesize());
  817. if ( !stream.workspace ) {
  818. initialized = 0;
  819. return -ENOMEM;
  820. }
  821. stream.next_in = NULL;
  822. stream.avail_in = 0;
  823. zlib_inflateInit(&stream);
  824. }
  825. return 0;
  826. }
  827. static void zlib_uncompress_exit(void)
  828. {
  829. if (!--initialized) {
  830. zlib_inflateEnd(&stream);
  831. vfree(stream.workspace);
  832. }
  833. }
  834. static void copy_line_data(unsigned int *dest,unsigned int *src,unsigned int width,enum cover_type cover)
  835. {
  836. unsigned int i;
  837. unsigned int* psrc = (unsigned int*)src;
  838. unsigned int* pdest = (unsigned int*)dest;
  839. if(cover == SRC_COVER_DST){
  840. memcpy(pdest,psrc,width*PIXEL_DATA_SIZE);
  841. }else if(cover == DST_COVER_SRC2){
  842. for(i = 0;i < width;i++){
  843. if(*pdest == PIXEL_DATA_NONE || *pdest == PIXEL_DATA_ZERO)
  844. *pdest = *psrc;
  845. psrc++;
  846. pdest++;
  847. }
  848. }
  849. else if(cover == SRC_COVER_DST2){
  850. for(i = 0;i < width;i++){
  851. if(*psrc == 0xFFFFFFFF || *psrc == PIXEL_DATA_NONE || *psrc == PIXEL_DATA_ZERO){
  852. psrc++;
  853. pdest++;
  854. continue;
  855. }
  856. *pdest = *psrc;
  857. psrc++;
  858. pdest++;
  859. }
  860. }
  861. }
  862. static int copy_pic_data(void *dest,void *src,enum image_type type,unsigned int id,enum cover_type cover)
  863. {
  864. unsigned int width;
  865. unsigned int height;
  866. unsigned int pos_x;
  867. unsigned int pos_y;
  868. track_param_context* p = &g_ptrack_context->track_param;
  869. unsigned int* dest_tmp;
  870. unsigned int* src_tmp;
  871. int radar_channel;
  872. int i;
  873. if(dest == NULL || src == NULL){
  874. printk(KERN_ERR "paint car dest src error!\n");
  875. return -1;
  876. }
  877. if(type == IMAGE_TYPE_TRACK){
  878. width = p->track_rect.width;
  879. height= p->track_rect.height;
  880. pos_x = p->track_rect.pos_x;
  881. pos_y = p->track_rect.pos_y;
  882. }
  883. else if(type == IMAGE_TYPE_CAR){
  884. width = p->car_rect.width;
  885. height= p->car_rect.height;
  886. pos_x = p->car_rect.pos_x;
  887. pos_y = p->car_rect.pos_y;
  888. }
  889. else if(type == IMAGE_TYPE_RADAR){
  890. radar_channel = get_radar_channel(id);
  891. if(radar_channel < 0){
  892. printk(KERN_ERR "get radar_channel error!\n");
  893. return -1;
  894. }
  895. width = p->radar_rect[radar_channel].width;
  896. height= p->radar_rect[radar_channel].height;
  897. pos_x = p->radar_rect[radar_channel].pos_x;
  898. pos_y = p->radar_rect[radar_channel].pos_y;
  899. }
  900. else if(type == IMAGE_TYPE_SIGNAL){
  901. width = p->signal_rect.width;
  902. height= p->signal_rect.height;
  903. pos_x = p->signal_rect.pos_x;
  904. pos_y = p->signal_rect.pos_y;
  905. }
  906. else if(type == IMAGE_TYPE_TRACK2){
  907. width = p->track2_rect.width;
  908. height= p->track2_rect.height;
  909. pos_x = p->track2_rect.pos_x;
  910. pos_y = p->track2_rect.pos_y;
  911. }
  912. else if(type == IMAGE_TYPE_MRADAR){
  913. mradar_param_context* p2 = &g_ptrack_context2->mradar_param;
  914. width = p2->mradar_rect[id].width;
  915. height= p2->mradar_rect[id].height;
  916. pos_x = p2->mradar_rect[id].pos_x;
  917. pos_y = p2->mradar_rect[id].pos_y;
  918. }
  919. else{
  920. printk(KERN_ERR "paint car type error!\n");
  921. return -1;
  922. }
  923. for(i = 0; i < height;i++){
  924. dest_tmp = dest + g_ptrack_context->disp_width * (pos_y + i) * PIXEL_DATA_SIZE + pos_x * PIXEL_DATA_SIZE;
  925. src_tmp = src + i * width * PIXEL_DATA_SIZE;
  926. copy_line_data(dest_tmp,src_tmp,width,cover);
  927. }
  928. return 0;
  929. }
  930. static unsigned int subjoin_car_pic(void *dest)
  931. {
  932. static unsigned int last_id = IMAGE_ID_NONE;
  933. track_context *p = g_ptrack_context;
  934. void *dest_car = p->disp_car_buf;
  935. unsigned int dest_size = p->disp_car_size;
  936. unsigned int fill_size = 0;
  937. unsigned int source_size;
  938. unsigned int source_offset;
  939. void *source;
  940. if(p->disp_car_id > CAR_MAX)
  941. return 0;
  942. if(first_draw_track)
  943. last_id = IMAGE_ID_NONE;
  944. source_offset = get_picture_offset(IMAGE_TYPE_CAR,p->disp_car_id);
  945. source_size = get_picture_size(IMAGE_TYPE_CAR,p->disp_car_id);
  946. //printk(KERN_ALERT "source_offset=%0x ,source_size=%0x\n",source_offset,source_size );
  947. if(source_size == 0 || source_offset < sizeof(user_header)){
  948. printk(KERN_ERR "subjoin car pic source error, disp_car_id=0x%0x.\n",p->disp_car_id);
  949. return 0;
  950. }
  951. if(last_id == IMAGE_ID_NONE || last_id != p->disp_car_id){
  952. source = (void*)get_picture_addr(IMAGE_TYPE_CAR,p->disp_car_id);
  953. fill_size = zlib_uncompress_block(dest_car, dest_size, source, source_size);
  954. if(fill_size != dest_size){
  955. printk(KERN_ERR " zlib uncompress car error!\n");
  956. return fill_size;
  957. }
  958. }
  959. copy_pic_data(dest,dest_car,IMAGE_TYPE_CAR,p->disp_car_id,SRC_COVER_DST);
  960. last_id = p->disp_car_id;
  961. return fill_size;
  962. }
  963. static unsigned int subjoin_signal_pic(void *dest)
  964. {
  965. static unsigned int last_id = IMAGE_ID_NONE;
  966. track_context *p = g_ptrack_context;
  967. void *dest_signal = p->disp_signal_buf;
  968. unsigned int dest_size = p->disp_signal_size;
  969. unsigned int fill_size = 0;
  970. unsigned int source_size;
  971. unsigned int source_offset;
  972. void *source;
  973. if(p->disp_signal_id > SIGNAL_MAX)
  974. return 0;
  975. if(first_draw_track)
  976. last_id = IMAGE_ID_NONE;
  977. source_offset = get_picture_offset(IMAGE_TYPE_SIGNAL,p->disp_signal_id);
  978. source_size = get_picture_size(IMAGE_TYPE_SIGNAL,p->disp_signal_id);
  979. //printk(KERN_ALERT "~~~~~~source_offset=%0x ,source_size=%0x\n",source_offset,source_size );
  980. if(source_size == 0 || source_offset < sizeof(user_header)){
  981. printk(KERN_ERR "subjoin signal pic source error, disp_signal_id=0x%0x.\n",p->disp_signal_id);
  982. return 0;
  983. }
  984. if(last_id == IMAGE_ID_NONE || last_id != p->disp_signal_id){
  985. source = (void*)get_picture_addr(IMAGE_TYPE_SIGNAL,p->disp_signal_id);
  986. fill_size = zlib_uncompress_block(dest_signal, dest_size, source, source_size);
  987. if(fill_size != dest_size){
  988. printk(KERN_ERR " zlib uncompress signal error!\n");
  989. return fill_size;
  990. }
  991. }
  992. copy_pic_data(dest,dest_signal,IMAGE_TYPE_SIGNAL,p->disp_signal_id,SRC_COVER_DST);
  993. last_id = p->disp_signal_id;
  994. return fill_size;
  995. }
  996. static unsigned int subjoin_track_pic(void *dest)
  997. {
  998. static unsigned int last_id = IMAGE_ID_NONE;
  999. track_context *p = g_ptrack_context;
  1000. void *dest_track = p->disp_track_buf;
  1001. unsigned int dest_size = p->disp_track_size;
  1002. unsigned int fill_size = 0;
  1003. unsigned int source_size;
  1004. unsigned int source_offset;
  1005. void *source;
  1006. if(p->disp_track_id > TRACK_MAX)
  1007. return 0;
  1008. if(first_draw_track)
  1009. last_id = IMAGE_ID_NONE;
  1010. source_offset = get_picture_offset(IMAGE_TYPE_TRACK,p->disp_track_id);
  1011. source_size = get_picture_size(IMAGE_TYPE_TRACK,p->disp_track_id);
  1012. if(source_size == 0 || source_offset < sizeof(user_header)){
  1013. printk(KERN_ERR "subjoin track pic source error, disp_track_id=0x%0x.\n",p->disp_track_id);
  1014. return 0;
  1015. }
  1016. if(last_id == IMAGE_ID_NONE || last_id != p->disp_track_id){
  1017. source = (void*)get_picture_addr(IMAGE_TYPE_TRACK,p->disp_track_id);
  1018. fill_size = zlib_uncompress_block(dest_track, dest_size, source, source_size);
  1019. if(fill_size != dest_size){
  1020. printk(KERN_ERR " zlib uncompress track error!\n");
  1021. return fill_size;
  1022. }
  1023. }
  1024. copy_pic_data(dest,dest_track,IMAGE_TYPE_TRACK,p->disp_track_id,SRC_COVER_DST);
  1025. last_id = p->disp_track_id;
  1026. //printk(KERN_ALERT "p->disp_track_id = %d",p->disp_track_id);
  1027. return fill_size;
  1028. }
  1029. static unsigned int subjoin_radar_pic(void *dest)
  1030. {
  1031. static unsigned int last_id = IMAGE_ID_NONE;
  1032. track_context *p = g_ptrack_context;
  1033. void *dest_radar = p->disp_radar_buf[0];
  1034. unsigned int dest_size = p->disp_radar_size;
  1035. unsigned int mask = 0xff000000;
  1036. unsigned int image_id;
  1037. unsigned char channel;
  1038. unsigned int fill_size = 0;
  1039. unsigned int source_size;
  1040. unsigned int source_offset;
  1041. void *source;
  1042. if(p->disp_radar_id == IMAGE_ID_NONE)
  1043. return 0;
  1044. if(first_draw_track)
  1045. last_id = IMAGE_ID_NONE;
  1046. for(channel = RADAR_CHANNEL_FL; channel <= RADAR_CHANNEL_RR;channel++){
  1047. image_id = p->disp_radar_id & (mask >> 8*channel);
  1048. if(!is_radar_image_id(image_id)){
  1049. printk(KERN_ERR " subjoin radar id channel=%d image_id=0x%0x, error!\n",channel,image_id);
  1050. continue;
  1051. }
  1052. dest_radar = p->disp_radar_buf[channel];
  1053. source_size = get_picture_size(IMAGE_TYPE_RADAR,image_id);
  1054. source_offset = get_picture_offset(IMAGE_TYPE_RADAR,image_id);
  1055. //printk(KERN_ALERT "channel=%d image_id=0x%0x ---> source_offset=%0x ,source_size=%0x \n",channel,image_id,source_offset,source_size );
  1056. if(source_size == 0 || source_offset < sizeof(user_header)){
  1057. printk(KERN_ERR "subjoin radar pic source error,channel=%d image_id=0x%0x.\n",channel,image_id);
  1058. continue;
  1059. }
  1060. if(last_id == IMAGE_ID_NONE || last_id != p->disp_radar_id){
  1061. source = (void*)get_picture_addr(IMAGE_TYPE_RADAR,image_id);
  1062. fill_size = zlib_uncompress_block(dest_radar, dest_size, source, source_size);
  1063. if(fill_size != dest_size){
  1064. printk(KERN_ERR " zlib uncompress radar error!\n");
  1065. return fill_size;
  1066. }
  1067. }
  1068. if(channel == RADAR_CHANNEL_RR){
  1069. copy_pic_data(dest,dest_radar,IMAGE_TYPE_RADAR,image_id,SRC_COVER_DST);
  1070. }
  1071. else{
  1072. copy_pic_data(dest,dest_radar,IMAGE_TYPE_RADAR,image_id,SRC_COVER_DST);
  1073. }
  1074. }
  1075. last_id = p->disp_radar_id;
  1076. return fill_size;
  1077. }
  1078. static unsigned int subjoin_track2_pic(void *dest)
  1079. {
  1080. static unsigned int last_id = IMAGE_ID_NONE;
  1081. track_context *p = g_ptrack_context;
  1082. void *dest_track2 = p->disp_track2_buf;
  1083. unsigned int dest_size = p->disp_track2_size;
  1084. unsigned int fill_size = 0;
  1085. unsigned int source_size;
  1086. unsigned int source_offset;
  1087. void *source;
  1088. if(p->disp_track2_id > TRACK_MAX)
  1089. return 0;
  1090. if(first_draw_track)
  1091. last_id = IMAGE_ID_NONE;
  1092. source_offset = get_picture_offset(IMAGE_TYPE_TRACK2,p->disp_track2_id);
  1093. source_size = get_picture_size(IMAGE_TYPE_TRACK2,p->disp_track2_id);
  1094. if(source_size == 0 || source_offset < sizeof(user_header)){
  1095. printk(KERN_ERR "subjoin track2 pic source error, disp_track2_id=0x%0x.\n",p->disp_track2_id);
  1096. return 0;
  1097. }
  1098. if(last_id == IMAGE_ID_NONE || last_id != p->disp_radar_id){
  1099. source = (void*)get_picture_addr(IMAGE_TYPE_TRACK2,p->disp_track2_id);
  1100. fill_size = zlib_uncompress_block(dest_track2, dest_size, source, source_size);
  1101. if(fill_size != dest_size){
  1102. printk(KERN_ERR " zlib uncompress track2 error!\n");
  1103. return fill_size;
  1104. }
  1105. }
  1106. copy_pic_data(dest,dest_track2,IMAGE_TYPE_TRACK2,p->disp_track2_id,SRC_COVER_DST);
  1107. last_id = p->disp_track2_id;
  1108. return fill_size;
  1109. }
  1110. static unsigned int subjoin_mradar_pic(void *dest)
  1111. {
  1112. static unsigned char last_mradar_id[MRADAR_MAX]={0xF,0xF,0xF,0xF,0xF,0xF,0xF,0xF,0xF,0xF,0xF,0xF,0xF,0xF,0xF,0xF};
  1113. track_context2 *p = g_ptrack_context2;
  1114. void *dest_buf;
  1115. unsigned int dest_size;
  1116. unsigned int fill_size = 0;
  1117. unsigned int source_size;
  1118. unsigned int source_offset;
  1119. void *source;
  1120. int i,item_id;
  1121. if(p == NULL)
  1122. return -1;
  1123. if(first_draw_track) {
  1124. for(i = 0; i < MRADAR_MAX; i++){
  1125. last_mradar_id[i] = 0x0F;
  1126. }
  1127. }
  1128. for(i = 0; i < MRADAR_MAX; i++){
  1129. if(p->disp_mradar_id[i] == 0x0F)
  1130. continue;
  1131. item_id = p->disp_mradar_id[i];
  1132. dest_buf = p->disp_mradar_buf[i];
  1133. dest_size = p->disp_mradar_size[i];
  1134. source_offset = g_pheader2_buf->mradar[i][item_id].image_offset + g_pheader_buf->file_size;
  1135. source_size = g_pheader2_buf->mradar[i][item_id].image_size;
  1136. //printk(KERN_ALERT "mradar[%d][%d]: source_offset=0x%0x ,source_size=0x%0x \n",i,item_id,source_offset,source_size);
  1137. if(source_size == 0 || source_offset < sizeof(user2_header)){
  1138. //printk(KERN_ERR "subjoin mradar pic source error, mradar[%d][%d].\n",i, item_id);
  1139. continue;
  1140. }
  1141. if(last_mradar_id[i] == 0x0F || last_mradar_id[i] != p->disp_mradar_id[i]){
  1142. source =(void*)(g_carback_context->track_data_virtaddr+source_offset);
  1143. fill_size = zlib_uncompress_block(dest_buf, dest_size, source, source_size);
  1144. if(fill_size != dest_size){
  1145. printk(KERN_ERR " zlib uncompress mradar error, fill_size=%0x, dest_size=%0x.\n", fill_size, dest_size);
  1146. return fill_size;
  1147. }
  1148. }
  1149. copy_pic_data(dest, dest_buf, IMAGE_TYPE_MRADAR, i, SRC_COVER_DST2);
  1150. }
  1151. for(i = 0; i < MRADAR_MAX; i++)
  1152. last_mradar_id[i] = p->disp_mradar_id[i];
  1153. p->disp_mradar_id_change = 0;
  1154. return fill_size;
  1155. }
  1156. int track_paint_init(void)
  1157. {
  1158. int ret = 0;
  1159. if(zlib_uncompress_init()){
  1160. printk(KERN_ERR "zlib uncompress init failed!\n" );
  1161. return -1;
  1162. }
  1163. if (*(volatile unsigned int*)g_carback_context->track_data_virtaddr != MKTAG('R', 'S', 'T', 'K')) {
  1164. printk(KERN_ALERT "reservingtrack check failed!\n" );
  1165. return -1;
  1166. }
  1167. if(init_track_context(g_carback_context->track_data_virtaddr) < 0){
  1168. printk(KERN_ERR "init track context failed.\n" );
  1169. return -1;
  1170. }
  1171. if(init_track_context2(g_carback_context->track_data_virtaddr) < 0){
  1172. printk(KERN_ERR "init track context2 failed.\n" );
  1173. g_ptrack_context2 = NULL;
  1174. return -1;
  1175. }
  1176. if(g_carback_context && g_carback_context->screen_width >= g_ptrack_context->disp_width && g_carback_context->screen_height>= g_ptrack_context->disp_height){
  1177. g_carback_context->track_disp_width = g_ptrack_context->disp_width;
  1178. g_carback_context->track_disp_height= g_ptrack_context->disp_height;
  1179. g_carback_context->track_disp_xpos = g_ptrack_context->disp_xpos;
  1180. g_carback_context->track_disp_ypos = g_ptrack_context->disp_ypos;
  1181. g_carback_context->ptrack_param = &g_ptrack_context->track_param;
  1182. g_carback_context->file_type = g_ptrack_context->file_type;
  1183. g_carback_context->pmradar_param = NULL;
  1184. if(g_ptrack_context2)
  1185. g_carback_context->pmradar_param = &g_ptrack_context2->mradar_param;
  1186. set_disp_track_id(TRACK_STRAIGHT_FORWARD_ID);
  1187. set_disp_car_id(CAR_NORMAL_STATUS_ID);
  1188. set_disp_radar_id(RADAR_NORMAL_STATUS_ID);
  1189. set_disp_track2_id(TRACK2_STRAIGHT_FORWARD_ID);
  1190. set_disp_signal_id(IMAGE_ID_NONE);
  1191. printk("track_paint init width=%d, height=%d,xpos=%d,ypos=%d.\n",g_carback_context->track_disp_width,\
  1192. g_carback_context->track_disp_height,g_carback_context->track_disp_xpos,g_carback_context->track_disp_ypos);
  1193. }
  1194. else{
  1195. printk(KERN_ALERT "track paint init out width or height fail!\n" );
  1196. ret = -1;
  1197. }
  1198. return ret;
  1199. }
  1200. void track_paint_deinit(void)
  1201. {
  1202. int i;
  1203. zlib_uncompress_exit();
  1204. if(g_ptrack_context->disp_track2_buf)
  1205. vfree(g_ptrack_context->disp_track2_buf);
  1206. for(i = 0; i < 4;i++)
  1207. if(g_ptrack_context->disp_radar_buf[i])
  1208. vfree(g_ptrack_context->disp_radar_buf[i]);
  1209. if(g_ptrack_context->disp_car_buf)
  1210. vfree(g_ptrack_context->disp_car_buf);
  1211. if(g_ptrack_context)
  1212. vfree(g_ptrack_context);
  1213. }
  1214. unsigned int track_paint_fill(void *dest, unsigned int width, unsigned int height)
  1215. {
  1216. static unsigned int last_track_id = 0;
  1217. static unsigned int last_car_id = 0;
  1218. static unsigned int last_radar_id = 0;
  1219. static unsigned int last_signal_id = -1;
  1220. static unsigned int last_track2_id= 0;
  1221. track_context *p = g_ptrack_context;
  1222. user_header* ph = g_pheader_buf;
  1223. if(p == NULL || g_carback_context == NULL){
  1224. printk(KERN_ERR "track_paint_fill g_ptrack_context or carback_context null\n" );
  1225. return 0;
  1226. }
  1227. if( width > p->disp_width || height > p->disp_height){
  1228. printk(KERN_ERR "track paint fill width height error!\n" );
  1229. return 0;
  1230. }
  1231. if(p->disp_track_id > TRACK_MAX && p->disp_track_id < IMAGE_ID_NONE)
  1232. return 0;
  1233. if(!g_carback_context->track_setting){
  1234. memset(dest,0,g_carback_context->track_display_size);
  1235. last_track_id = 0;
  1236. last_car_id = 0;
  1237. last_radar_id = 0;
  1238. last_signal_id = -1;
  1239. last_track2_id= 0;
  1240. return g_carback_context->track_display_size;
  1241. }
  1242. if (p->disp_track_id == IMAGE_ID_NONE){
  1243. memset(dest,0,p->disp_track_size);
  1244. if(ph->car_total)
  1245. subjoin_car_pic(dest);
  1246. if(ph->radar_total)
  1247. subjoin_radar_pic(dest);
  1248. last_track_id = p->disp_track_id;
  1249. last_car_id = p->disp_car_id;
  1250. last_radar_id = p->disp_radar_id;
  1251. return p->disp_track_size;
  1252. }
  1253. if( g_carback_context->carback_signal ){
  1254. if(last_track_id == p->disp_track_id && last_car_id == p->disp_car_id &&
  1255. last_radar_id == p->disp_radar_id &&last_track2_id == p->disp_track2_id && last_signal_id == p->disp_signal_id ){
  1256. if(g_ptrack_context2 == NULL || !g_ptrack_context2->disp_mradar_id_change)
  1257. return 0;
  1258. }
  1259. }
  1260. if( !g_carback_context->carback_signal ){
  1261. if(last_signal_id != p->disp_signal_id)
  1262. memset(dest,0,g_carback_context->track_display_size);
  1263. if(ph->signal_total)
  1264. subjoin_signal_pic(dest);
  1265. }else{
  1266. if(g_carback_context->layer_status){
  1267. if(ph->track_total )
  1268. subjoin_track_pic(dest);
  1269. if(ph->car_total)
  1270. subjoin_car_pic(dest);
  1271. if(ph->radar_total)
  1272. subjoin_radar_pic(dest);
  1273. if(ph->track2_total)
  1274. subjoin_track2_pic(dest);
  1275. if(g_ptrack_context2) {
  1276. subjoin_mradar_pic(dest);
  1277. }
  1278. }
  1279. }
  1280. if(g_carback_context->layer_status){
  1281. last_track_id = p->disp_track_id;
  1282. last_car_id = p->disp_car_id;
  1283. last_radar_id = p->disp_radar_id;
  1284. last_track2_id= p->disp_track2_id;
  1285. }
  1286. last_signal_id = p->disp_signal_id;
  1287. return g_carback_context->track_display_size;
  1288. }