f303_ic_test.c 71 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277
  1. /* f303_ic_test.c
  2. *
  3. * Raydium TouchScreen driver.
  4. *
  5. * Copyright (c) 2021 Raydium tech Ltd.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. */
  18. #ifdef __KERNEL__
  19. #include <linux/delay.h>
  20. #include <linux/mutex.h>
  21. #include <linux/unistd.h>
  22. #include <linux/kernel.h>
  23. #include <linux/string.h>
  24. #include <linux/timer.h>
  25. #include <linux/fs.h>
  26. #include <asm/uaccess.h>
  27. #else
  28. #include <stdint.h>
  29. #include <string.h>
  30. #include <stdlib.h>
  31. #endif
  32. #define RM_F303_MAX_STR_LENGTH 8
  33. #include "../drv_interface.h"
  34. #include "ic_drv_global.h"
  35. #include "ic_drv_interface.h"
  36. #include "f303_ic_control.h"
  37. #include "f303_ic_test.h"
  38. #include "f303_ic_reg.h"
  39. #if !SELFTEST_3X
  40. #include "ic_drv_global_ft.h"
  41. #include "f303_ic_test_ft.h"
  42. #include "ic_drv_interface_ft.h"
  43. #endif
  44. STATUS ft_test_panel_model_check_3x(unsigned short u16_version);
  45. #if !SELFTEST_3X
  46. STATUS burn_data_log_to_flash_3x(void)
  47. {
  48. unsigned short u16_pram_start_addr = 0x1000;
  49. unsigned char u8_read_buf[4], u8_fw_version[4];
  50. unsigned short u16_index = 0, u16_retry = 0;
  51. unsigned int u32_read = 0, u32_flash_header_start_addr = 0xA000, u32_header_size = 0x400;
  52. unsigned int u32_write = 0;
  53. unsigned char *p_data = (unsigned char *)g_i16_raw_data_frame_buffer;
  54. if (g_u8_drv_interface == SPI_INTERFACE || g_u8_test_log_burn_times > 3) {
  55. /*flashless*/
  56. DEBUGOUT("return burn test log\r\n");
  57. return SUCCESS;
  58. }
  59. memset(g_i16_raw_data_frame_buffer, 0x0, 1024);
  60. memset(u8_fw_version, 0x0, sizeof(u8_fw_version));
  61. hardware_reset_3x(false);
  62. /*read info*/
  63. /*wearable_ic_test_read_info();*/
  64. /*read FW Version*/
  65. if (handle_ic_read(FW_FT_SRAM_FW_VERSION, 4, u8_fw_version, g_u8_drv_interface, I2C_BYTE_MODE) == ERROR)
  66. return ERROR;
  67. /* -------------*/
  68. /*read Header*/
  69. if (handle_ic_read(REG_SYSCON_BLKEN_ADDR, 4, (unsigned char *)(&u32_read), g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  70. return ERROR;
  71. u32_read |= 0x40;
  72. if (handle_ic_write(REG_SYSCON_BLKEN_ADDR, 4, (unsigned char *)&u32_read, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  73. return ERROR;
  74. u32_write = 0x00000000;
  75. if (handle_ic_write(REG_I2C_I2CFLASHPRO, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  76. return ERROR;
  77. /*Release flash power down mode*/
  78. u32_write = 0x28;
  79. if (handle_ic_write(REG_FLASHCTL_FLASH_ISPCTL, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  80. return ERROR;
  81. /*----write data-----*/
  82. memset(p_data, 0xFF, 1024);
  83. if (!stop_mcu_3x(0)) {
  84. DEBUGOUT("Stop MCU NG\r\n");
  85. return ERROR;
  86. }
  87. u32_write = 0x00000000;
  88. if (handle_ic_write(REG_I2C_I2CFLASHPRO, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  89. return ERROR;
  90. /*Unlock PRAM*/
  91. u32_write = 0x00000000;
  92. if (handle_ic_write(REG_FLASHCTL_FLASH_PRAM_LOCK, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  93. return ERROR;
  94. /* unlock key*/
  95. u32_write = FLKEY2_KEY;
  96. if (handle_ic_write(REG_FLASHCTL_FLASH_FLKEY2, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  97. return ERROR;
  98. u32_write = FLKEY1_KEY;
  99. if (handle_ic_write(REG_FLASHCTL_FLASH_FLKEY1, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  100. return ERROR;
  101. u32_write = FLKEY1_LOCK;
  102. if (handle_ic_write(REG_FLASHCTL_FLASH_FLKEY1, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  103. return ERROR;
  104. u32_write = FLKEY1_KEY;
  105. if (handle_ic_write(REG_FLASHCTL_FLASH_FLKEY1, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  106. return ERROR;
  107. u32_write = FLKEY2_LOCK;
  108. if (handle_ic_write(REG_FLASHCTL_FLASH_FLKEY2, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  109. return ERROR;
  110. /*clear Pram*/
  111. u16_index = 0;
  112. while (u16_index < 1024) {
  113. if (handle_ic_write(u16_pram_start_addr + u16_index, 64, p_data, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  114. return ERROR;
  115. u16_index += 64;
  116. }
  117. /*DEBUGOUT("[u8_fw_version]:%X\r\n", u8_fw_version);*/
  118. /*DEBUGOUT("[g_u32_wearable_test_result]:%X\r\n", g_u32_wearable_test_result);*/
  119. /*fill data*/
  120. memset(g_u16_raw_data_tmp, 0, sizeof(g_u16_raw_data_tmp));
  121. test_log_raw_data_remap_3x(g_i16_raw_data_1_short_buf, (short *)g_u16_raw_data_tmp, DATA_REMAP_TO_SENSOR_PAD);
  122. memcpy(p_data, g_u16_raw_data_tmp, 96);
  123. memset(g_u16_raw_data_tmp, 0, sizeof(g_u16_raw_data_tmp));
  124. test_log_raw_data_remap_3x(g_i16_raw_data_2_open_buf, (short *)g_u16_raw_data_tmp, DATA_REMAP_TO_SENSOR_PAD);
  125. memcpy((p_data + 96), g_u16_raw_data_tmp, 96);
  126. memset(g_u16_raw_data_tmp, 0, sizeof(g_u16_raw_data_tmp));
  127. test_log_raw_data_remap_3x((short *)g_u16_raw_data3_cc_buf, (short *)g_u16_raw_data_tmp, DATA_REMAP_TO_SENSOR_PAD);
  128. memcpy((p_data + 192), g_u16_raw_data_tmp, 96);
  129. memset(g_u16_raw_data_tmp, 0, sizeof(g_u16_raw_data_tmp));
  130. test_log_raw_data_remap_3x(g_i16_noise_peek_raw_data, (short *)g_u16_raw_data_tmp, DATA_REMAP_TO_SENSOR_PAD);
  131. memcpy((p_data + 288), g_u16_raw_data_tmp, 96);
  132. memset(g_u16_raw_data_tmp, 0, sizeof(g_u16_raw_data_tmp));
  133. test_log_raw_data_remap_3x(g_i16_display_pattern_avg_raw_data, (short *)g_u16_raw_data_tmp, DATA_REMAP_TO_SENSOR_PAD);
  134. memcpy((p_data + 384), g_u16_raw_data_tmp, 96);
  135. memset(g_u16_raw_data_tmp, 0, sizeof(g_u16_raw_data_tmp));
  136. test_log_raw_data_remap_3x(g_i16_display_pattern_no_dc_avg_raw_data, (short *)g_u16_raw_data_tmp, DATA_REMAP_TO_SENSOR_PAD);
  137. memcpy((p_data + 480), g_u16_raw_data_tmp, 96);
  138. memset(g_u16_raw_data_tmp, 0, sizeof(g_u16_raw_data_tmp));
  139. test_log_raw_data_remap_3x(g_i16_display_pattern_avg_raw_data_s2, (short *)g_u16_raw_data_tmp, DATA_REMAP_TO_SENSOR_PAD);
  140. memcpy((p_data + 576), g_u16_raw_data_tmp, 96);
  141. memset(g_u16_raw_data_tmp, 0, sizeof(g_u16_raw_data_tmp));
  142. test_log_raw_data_remap_3x(g_i16_display_pattern_no_dc_avg_raw_data_s2, (short *)g_u16_raw_data_tmp, DATA_REMAP_TO_SENSOR_PAD);
  143. memcpy((p_data + 672), g_u16_raw_data_tmp, 96);
  144. memset(g_u16_raw_data_tmp, 0, sizeof(g_u16_raw_data_tmp));
  145. test_log_raw_data_remap_3x((short *)g_u16_uc_buf, (short *)g_u16_raw_data_tmp, DATA_REMAP_TO_SENSOR_PAD);
  146. memcpy((p_data + 768), g_u16_raw_data_tmp, 96);
  147. /*---write data section---*/
  148. u16_index = 0;
  149. while (u16_index < 1024) {
  150. if (handle_ic_write(u16_pram_start_addr + u16_index, 64, (p_data + u16_index), g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  151. return ERROR;
  152. u16_index += 64;
  153. }
  154. u32_write = u16_pram_start_addr;
  155. if (handle_ic_write(REG_FLASHCTL_FLASH_PRAM_ADDR, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  156. return ERROR;
  157. u32_write = 0x300;
  158. if (handle_ic_write(REG_FLASHCTL_FLASH_PRAM_LENGTH, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  159. return ERROR;
  160. DEBUGOUT("g_st_test_info.u8_station_id:%x\r\n", g_st_test_info.u8_station_id);
  161. DEBUGOUT("u8_burn_times:%d\r\n", g_u8_test_log_burn_times);
  162. DEBUGOUT("ADDR:%x\r\n", u32_flash_header_start_addr + u32_header_size + (g_st_test_info.u8_station_id - 1) * 4096
  163. + (g_u8_test_log_burn_times - 1) * 0x400);
  164. /*flash addr , wrtie data section*/
  165. u32_write = u32_flash_header_start_addr + u32_header_size + (g_st_test_info.u8_station_id - 1) * 4096
  166. + (g_u8_test_log_burn_times - 1) * 0x400;
  167. if (handle_ic_write(REG_FLASHCTL_FLASH_ADDR, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  168. return ERROR;
  169. /*write trigger*/
  170. u32_write = 0x4;
  171. if (handle_ic_write(REG_FLASHCTL_FLASH_ISPCTL, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  172. return ERROR;
  173. /* check read trigger finished*/
  174. u16_retry = 1000;
  175. memset(u8_read_buf, 0, sizeof(u8_read_buf));
  176. if (handle_ic_read(REG_FLASHCTL_FLASH_ISPCTL, 4, u8_read_buf, g_u8_drv_interface, I2C_BYTE_MODE) == ERROR)
  177. return ERROR;
  178. while ((u8_read_buf[0] & 0x08) == 0 && u16_retry > 0) {
  179. if (handle_ic_read(REG_FLASHCTL_FLASH_ISPCTL, 4, u8_read_buf, g_u8_drv_interface, I2C_BYTE_MODE) == ERROR)
  180. return ERROR;
  181. delay_ms(1);
  182. u16_retry--;
  183. }
  184. if (u16_retry == 0) {
  185. DEBUGOUT("Write Trigger Error\r\n");
  186. return ERROR;
  187. }
  188. /*---end write data section---*/
  189. hardware_reset_3x(TRUE);
  190. return SUCCESS;
  191. }
  192. STATUS burn_header_log_to_flash_3x(bool is_test_finish, bool is_in_header_data_page)
  193. {
  194. unsigned short u16_pram_start_addr = 0x1000;
  195. unsigned char *p_header_data = (unsigned char *)g_u32_save_config;
  196. unsigned char u8_write_buf[64], u8_fw_version[4], u8_read_buf[4], u8_burn_full_times = 20, u8_count_1 = 0, u8_test_info[16];
  197. unsigned short u16_index = 0, u16_retry = 0;
  198. unsigned int u32_read = 0, u32_flash_header_start_addr = 0xA000 + (g_st_test_info.u8_station_id - 1) * 4096 + g_u8_test_log_burn_times / 5 * 0x100;
  199. unsigned int u32_write = 0, u32_temp = 0;
  200. bool b_is_first_read = true;
  201. DEBUGOUT("[u32_flash_header_start_addr ]:%d\r\n", u32_flash_header_start_addr);
  202. /*DEBUGOUT("[is_in_header_data_page ]:%d\r\n", is_in_header_data_page);*/
  203. if (!is_test_finish && is_in_header_data_page)
  204. memset(g_u32_save_config, 0, sizeof(g_u32_save_config));
  205. if (is_in_header_data_page)
  206. u32_flash_header_start_addr = 0xA000 + (g_st_test_info.u8_station_id - 1) * 4096 + g_u8_test_log_burn_times / 5 * 0x100;
  207. else
  208. u32_flash_header_start_addr = 0xA000 + (g_st_test_info.u8_station_id - 1) * 4096;
  209. if (g_u8_drv_interface == SPI_INTERFACE || g_u8_test_log_burn_times > 20)
  210. /*flashless*/
  211. return SUCCESS;
  212. memset(u8_write_buf, 0x0, sizeof(u8_write_buf));
  213. /*memset(g_u8_header_buf, 0x0 , sizeof(g_u8_header_buf));*/
  214. memset(u8_fw_version, 0x0, sizeof(u8_fw_version));
  215. hardware_reset_3x(false);
  216. /*read info*/
  217. if (read_flash_data(g_u32_dongle_flash_ini_addr, 16) != ERROR)
  218. memcpy(&u8_test_info, g_u8_data_buf, sizeof(u8_test_info));
  219. /*read FW Version*/
  220. if (handle_ic_read(FW_FT_SRAM_FW_VERSION, 4, u8_fw_version, g_u8_drv_interface, I2C_BYTE_MODE) == ERROR)
  221. return ERROR;
  222. /* -------------*/
  223. /*read Header*/
  224. if (handle_ic_read(REG_SYSCON_BLKEN_ADDR, 4, (unsigned char *)(&u32_read), g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  225. return ERROR;
  226. u32_read |= 0x40;
  227. if (handle_ic_write(REG_SYSCON_BLKEN_ADDR, 4, (unsigned char *)&u32_read, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  228. return ERROR;
  229. u32_write = 0x00000000;
  230. if (handle_ic_write(REG_I2C_I2CFLASHPRO, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  231. return ERROR;
  232. /*Release flash power down mode*/
  233. u32_write = 0x28;
  234. if (handle_ic_write(REG_FLASHCTL_FLASH_ISPCTL, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  235. return ERROR;
  236. DEBUGOUT("[header addr!]:%X\r\n", u32_flash_header_start_addr);
  237. while (u16_index < 256) {
  238. /*write flash addr*/
  239. u32_write = u32_flash_header_start_addr + u16_index;
  240. if (handle_ic_write(REG_FLASHCTL_FLASH_ADDR, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  241. return ERROR;
  242. /*Set Read trigger, Flh_read_trg[bit 6]*/
  243. u32_write = 0x40;
  244. if (handle_ic_write(REG_FLASHCTL_FLASH_ISPCTL, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  245. return ERROR;
  246. /* check read trigger finished*/
  247. u16_retry = 1000;
  248. memset(u8_read_buf, 0, sizeof(u8_read_buf));
  249. while ((u8_read_buf[0] & 0x40) != 0 && u16_retry > 0) {
  250. if (handle_ic_read(REG_FLASHCTL_FLASH_ISPCTL, 4, u8_read_buf, g_u8_drv_interface, I2C_BYTE_MODE) == ERROR)
  251. return ERROR;
  252. delay_ms(1);
  253. u16_retry--;
  254. }
  255. if (u16_retry == 0)
  256. return ERROR;
  257. /*Read Flash Data*/
  258. if (handle_ic_read(REG_FLASHCTL_FLASH_DATA, 4, (unsigned char *)(&u32_read), g_u8_drv_interface, I2C_BYTE_MODE) == ERROR)
  259. return ERROR;
  260. /*memcpy(&g_u8_header_buf[0] , &u32_read , 4);*/
  261. if (b_is_first_read && !is_in_header_data_page) {
  262. u32_temp = u32_read;
  263. while (u32_temp) {
  264. u8_count_1++;
  265. u32_temp = (u32_temp - 1) & u32_temp;
  266. }
  267. /*DEBUGOUT("u32_temp:%d\r\n", 32 - u8_count_1);*/
  268. if (32 - u8_count_1 >= u8_burn_full_times) {
  269. g_u8_test_log_burn_times = 32 - u8_count_1 + 1;
  270. DEBUGOUT("Burn Full times\r\n");
  271. hardware_reset_3x(TRUE);
  272. return SUCCESS;
  273. }
  274. g_u8_test_log_burn_times = 32 - u8_count_1 + 1;
  275. /*count how many times has been tested , each test would right shift one bit.*/
  276. u32_read = u32_read >> 1;
  277. DEBUGOUT("Burn times: %d\r\n", g_u8_test_log_burn_times);
  278. memcpy(&p_header_data[0], &u32_read, 4);
  279. b_is_first_read = false;
  280. } else
  281. memcpy(&p_header_data[u16_index], &u32_read, 4);
  282. u16_index += 4;
  283. }
  284. /* u16_auo_jig_cmd = g_u16_panel_jig_set_test_items;*/
  285. /* fill data*/
  286. if (g_u8_test_log_burn_times <= 5 || is_in_header_data_page) {
  287. memcpy(&p_header_data[8 + ((g_u8_test_log_burn_times - 1) % 5) * 48], &u8_test_info, 8);
  288. /*if ((g_st_test_info.u16_ft_eng_item & IC_TEST_ENG_ITEMS_PANEL_TEST_JIG))*/
  289. /* memcpy(&p_header_data[8 + ((g_u8_test_log_burn_times - 1) % 5) * 48 + 4] , &u16_auo_jig_cmd , 2);*/
  290. memcpy(&p_header_data[8 + ((g_u8_test_log_burn_times - 1) % 5) * 48 + 8], &g_st_test_thd.i16_ft_test_open_lower_thd, 2);
  291. memcpy(&p_header_data[8 + ((g_u8_test_log_burn_times - 1) % 5) * 48 + 10], &g_st_test_thd.i16_ft_test_short_upper_thd, 2);
  292. memcpy(&p_header_data[8 + ((g_u8_test_log_burn_times - 1) % 5) * 48 + 12], &g_st_test_thd.i16_ft_test_single_cc_lower_thd, 2);
  293. memcpy(&p_header_data[8 + ((g_u8_test_log_burn_times - 1) % 5) * 48 + 14], &g_st_test_thd.i16_ft_test_uniformity_cc_upper_thd, 2);
  294. memcpy(&p_header_data[8 + ((g_u8_test_log_burn_times - 1) % 5) * 48 + 16], &g_st_test_thd.i16_ft_test_uniformity_cc_lower_thd, 2);
  295. memcpy(&p_header_data[8 + ((g_u8_test_log_burn_times - 1) % 5) * 48 + 18], &g_st_test_thd.i16_ft_test_panel_test_1_thd, 2);
  296. memcpy(&p_header_data[8 + ((g_u8_test_log_burn_times - 1) % 5) * 48 + 20], &g_st_test_thd.i16_ft_test_panel_test_3_thd, 2);
  297. memcpy(&p_header_data[8 + ((g_u8_test_log_burn_times - 1) % 5) * 48 + 22], &g_st_test_thd.i16_ft_test_panel_test_2_thd, 2);
  298. memcpy(&p_header_data[8 + ((g_u8_test_log_burn_times - 1) % 5) * 48 + 24], &g_st_test_thd.i16_ft_test_panel_test_2_s2_thd, 2);
  299. memcpy(&p_header_data[8 + ((g_u8_test_log_burn_times - 1) % 5) * 48 + 26], &g_st_test_para_resv.u32_normal_fw_version, 4);
  300. memcpy(&p_header_data[8 + ((g_u8_test_log_burn_times - 1) % 5) * 48 + 30], &g_st_test_para_resv.u32_test_fw_version, 4);
  301. if (is_test_finish) { /*after testing, burn the result to flash*/
  302. DEBUGOUT("g_u8_channel_x: %d\r\n", g_u8_channel_x);
  303. DEBUGOUT("g_u8_channel_y: %d\r\n", g_u8_channel_y);
  304. memcpy(&p_header_data[8 + ((g_u8_test_log_burn_times - 1) % 5) * 48 + 34], &g_u32_wearable_test_result, 4);
  305. p_header_data[8 + ((g_u8_test_log_burn_times - 1) % 5) * 48 + 37] = p_header_data[8 + ((g_u8_test_log_burn_times - 1) % 5) * 48 + 34] ^ p_header_data[8 + ((g_u8_test_log_burn_times - 1) % 5) * 48 + 37];
  306. p_header_data[8 + ((g_u8_test_log_burn_times - 1) % 5) * 48 + 34] = p_header_data[8 + ((g_u8_test_log_burn_times - 1) % 5) * 48 + 34] ^ p_header_data[8 + ((g_u8_test_log_burn_times - 1) % 5) * 48 + 37];
  307. p_header_data[8 + ((g_u8_test_log_burn_times - 1) % 5) * 48 + 37] = p_header_data[8 + ((g_u8_test_log_burn_times - 1) % 5) * 48 + 34] ^ p_header_data[8 + ((g_u8_test_log_burn_times - 1) % 5) * 48 + 37];
  308. p_header_data[8 + ((g_u8_test_log_burn_times - 1) % 5) * 48 + 36] = p_header_data[8 + ((g_u8_test_log_burn_times - 1) % 5) * 48 + 35] ^ p_header_data[8 + ((g_u8_test_log_burn_times - 1) % 5) * 48 + 36];
  309. p_header_data[8 + ((g_u8_test_log_burn_times - 1) % 5) * 48 + 35] = p_header_data[8 + ((g_u8_test_log_burn_times - 1) % 5) * 48 + 35] ^ p_header_data[8 + ((g_u8_test_log_burn_times - 1) % 5) * 48 + 36];
  310. p_header_data[8 + ((g_u8_test_log_burn_times - 1) % 5) * 48 + 36] = p_header_data[8 + ((g_u8_test_log_burn_times - 1) % 5) * 48 + 35] ^ p_header_data[8 + ((g_u8_test_log_burn_times - 1) % 5) * 48 + 36];
  311. memcpy(&p_header_data[8 + ((g_u8_test_log_burn_times - 1) % 5) * 48 + 38], u8_fw_version, 4);
  312. memcpy(&p_header_data[8 + ((g_u8_test_log_burn_times - 1) % 5) * 48 + 42], &g_u8_channel_x, 1);
  313. memcpy(&p_header_data[8 + ((g_u8_test_log_burn_times - 1) % 5) * 48 + 43], &g_u8_channel_y, 1);
  314. }
  315. /* DEBUGOUT("g_u8_test_date0: %d\r\n", g_u8_test_date[0]);
  316. * DEBUGOUT("g_u8_test_date: %d\r\n", g_u8_test_date[1]);
  317. * DEBUGOUT("g_u8_test_date: %d\r\n", g_u8_test_date[2]);
  318. * DEBUGOUT("g_u8_test_date: %d\r\n", g_u8_test_date[3]);
  319. */
  320. memcpy(&p_header_data[8 + ((g_u8_test_log_burn_times - 1) % 5) * 48 + 44], &g_u8_test_date, 4);
  321. }
  322. /*----write data-----*/
  323. if (!stop_mcu_3x(0)) {
  324. DEBUGOUT("Stop MCU NG\r\n");
  325. return ERROR;
  326. }
  327. u32_write = 0x00000000;
  328. if (handle_ic_write(REG_I2C_I2CFLASHPRO, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  329. return ERROR;
  330. /*Unlock PRAM*/
  331. u32_write = 0x00000000;
  332. if (handle_ic_write(REG_FLASHCTL_FLASH_PRAM_LOCK, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  333. return ERROR;
  334. /* unlock key*/
  335. u32_write = FLKEY2_KEY;
  336. if (handle_ic_write(REG_FLASHCTL_FLASH_FLKEY2, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  337. return ERROR;
  338. u32_write = FLKEY1_KEY;
  339. if (handle_ic_write(REG_FLASHCTL_FLASH_FLKEY1, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  340. return ERROR;
  341. u32_write = FLKEY1_LOCK;
  342. if (handle_ic_write(REG_FLASHCTL_FLASH_FLKEY1, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  343. return ERROR;
  344. u32_write = FLKEY1_KEY;
  345. if (handle_ic_write(REG_FLASHCTL_FLASH_FLKEY1, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  346. return ERROR;
  347. u32_write = FLKEY2_LOCK;
  348. if (handle_ic_write(REG_FLASHCTL_FLASH_FLKEY2, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  349. return ERROR;
  350. /*clear Pram*/
  351. u16_index = 0;
  352. while (u16_index < 256) { /*totally 688(768) + 256 header bytes*/
  353. if (handle_ic_write(u16_pram_start_addr + u16_index, 64, u8_write_buf, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  354. return ERROR;
  355. u16_index += 64;
  356. }
  357. /*---write header section---*/
  358. u16_index = 0;
  359. while (u16_index < 256) { /*totally 256 bytes*/
  360. if (handle_ic_write(u16_pram_start_addr + u16_index, 64, &p_header_data[u16_index], g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  361. return ERROR;
  362. u16_index += 64;
  363. }
  364. u32_write = u16_pram_start_addr;
  365. if (handle_ic_write(REG_FLASHCTL_FLASH_PRAM_ADDR, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  366. return ERROR;
  367. u32_write = 0x00;
  368. if (handle_ic_write(REG_FLASHCTL_FLASH_PRAM_LENGTH, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  369. return ERROR;
  370. /*flash addr , wrtie data section*/
  371. u32_write = u32_flash_header_start_addr;
  372. if (handle_ic_write(REG_FLASHCTL_FLASH_ADDR, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  373. return ERROR;
  374. /*write trigger*/
  375. u32_write = 0x4;
  376. if (handle_ic_write(REG_FLASHCTL_FLASH_ISPCTL, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  377. return ERROR;
  378. /* check read trigger finished*/
  379. u16_retry = 1000;
  380. memset(u8_read_buf, 0, sizeof(u8_read_buf));
  381. if (handle_ic_read(REG_FLASHCTL_FLASH_ISPCTL, 4, u8_read_buf, g_u8_drv_interface, I2C_BYTE_MODE) == ERROR)
  382. return ERROR;
  383. while ((u8_read_buf[0] & 0x08) != 0 && u16_retry > 0) {
  384. if (handle_ic_read(REG_FLASHCTL_FLASH_ISPCTL, 4, u8_read_buf, g_u8_drv_interface, I2C_BYTE_MODE) == ERROR)
  385. return ERROR;
  386. delay_ms(1);
  387. u16_retry--;
  388. }
  389. if (u16_retry == 0)
  390. return ERROR;
  391. /*memset(g_u8_test_date , 0 , sizeof(g_u8_test_date)); */
  392. /*clear date*/
  393. /*---end write header section---*/
  394. hardware_reset_3x(TRUE);
  395. DEBUGOUT("End burn header\r\n");
  396. return SUCCESS;
  397. }
  398. #endif
  399. STATUS turn_on_flash_3x(void)
  400. {
  401. unsigned int u32_read = 0;
  402. /*Turn on Flash*/
  403. if (handle_ic_write(REG_I2C_I2CFLASHPRO, 4, (unsigned char *)&u32_read, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  404. return ERROR;
  405. u32_read = FLH_RELEASE_PD;
  406. if (handle_ic_write(REG_FLASHCTL_FLASH_ISPCTL, 4, (unsigned char *)&u32_read, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  407. return ERROR;
  408. return SUCCESS;
  409. }
  410. STATUS read_fpc_flash_3x(unsigned int u32_addr, unsigned int *p_u32_data)
  411. {
  412. unsigned int u32_read;
  413. /*Turn on Flash*/
  414. if (turn_on_flash_3x() == ERROR)
  415. return ERROR;
  416. if (handle_ic_read(REG_SYSCON_BLKEN_ADDR, 4, (unsigned char *)(&u32_read), g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  417. return ERROR;
  418. u32_read |= 0x40;
  419. if (handle_ic_write(REG_SYSCON_BLKEN_ADDR, 4, (unsigned char *)&u32_read, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  420. return ERROR;
  421. u32_read = 0x00000000;
  422. if (handle_ic_write(REG_I2C_I2CFLASHPRO, 4, (unsigned char *)&u32_read, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  423. return ERROR;
  424. if (handle_ic_write(REG_FLASHCTL_FLASH_ADDR, 4, (unsigned char *)&u32_addr, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  425. return ERROR;
  426. u32_read = 0x40;
  427. if (handle_ic_write(REG_FLASHCTL_FLASH_ISPCTL, 4, (unsigned char *)&u32_read, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  428. return ERROR;
  429. delay_ms(1);
  430. if (handle_ic_read(REG_FLASHCTL_FLASH_DATA, 4, (unsigned char *)(&u32_read), g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  431. return ERROR;
  432. *p_u32_data = u32_read;
  433. return SUCCESS;
  434. }
  435. STATUS set_test_info_thd_para_3x(void)
  436. {
  437. unsigned char u8_read_buf[96], u8_i;
  438. unsigned char *p_u8_input_buf;
  439. if (handle_ic_write(FT_TEST_INFO_ADDR, sizeof(g_st_test_info), (unsigned char *)&g_st_test_info, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  440. return ERROR;
  441. if (handle_ic_read(FT_TEST_INFO_ADDR, sizeof(g_st_test_info), (unsigned char *)u8_read_buf, g_u8_drv_interface, I2C_BYTE_MODE) == ERROR)
  442. return ERROR;
  443. p_u8_input_buf = (unsigned char *)&g_st_test_info;
  444. for (u8_i = 0; u8_i < sizeof(g_st_test_info); u8_i++) {
  445. if (p_u8_input_buf[u8_i] != u8_read_buf[u8_i]) {
  446. DEBUGOUT("Set INFO NG:[%d]=%d->%d\r\n", u8_i, p_u8_input_buf[u8_i], u8_read_buf[u8_i]);
  447. return ERROR;
  448. }
  449. }
  450. if (handle_ic_write(FT_TEST_THD_ADDR, sizeof(g_st_test_thd), (unsigned char *)&g_st_test_thd, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  451. return ERROR;
  452. if (handle_ic_read(FT_TEST_THD_ADDR, sizeof(g_st_test_thd), (unsigned char *)u8_read_buf, g_u8_drv_interface, I2C_BYTE_MODE) == ERROR)
  453. return ERROR;
  454. p_u8_input_buf = (unsigned char *)&g_st_test_thd;
  455. for (u8_i = 0; u8_i < sizeof(g_st_test_thd); u8_i++) {
  456. if (p_u8_input_buf[u8_i] != u8_read_buf[u8_i]) {
  457. DEBUGOUT("Set THD NG:[%d]=%d->%d\r\n", u8_i, p_u8_input_buf[u8_i], u8_read_buf[u8_i]);
  458. return ERROR;
  459. }
  460. }
  461. if (handle_ic_write(FT_TEST_PARA_ADDR, sizeof(g_st_test_para_resv), (unsigned char *)&g_st_test_para_resv, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  462. return ERROR;
  463. if (handle_ic_read(FT_TEST_PARA_ADDR, sizeof(g_st_test_para_resv), (unsigned char *)u8_read_buf, g_u8_drv_interface, I2C_BYTE_MODE) == ERROR)
  464. return ERROR;
  465. p_u8_input_buf = (unsigned char *)&g_st_test_para_resv;
  466. for (u8_i = 0; u8_i < sizeof(g_st_test_para_resv); u8_i++) {
  467. if (p_u8_input_buf[u8_i] != u8_read_buf[u8_i]) {
  468. DEBUGOUT("Set Para NG:[%d]=%d->%d\r\n", u8_i, p_u8_input_buf[u8_i], u8_read_buf[u8_i]);
  469. return ERROR;
  470. }
  471. }
  472. if (handle_ic_write(SRAM_FT_UC_CC_ADDR, 96, (unsigned char *)g_u16_uc_golden_cc_buf, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  473. return ERROR;
  474. if (handle_ic_read(SRAM_FT_UC_CC_ADDR, 96, (unsigned char *)u8_read_buf, g_u8_drv_interface, I2C_BYTE_MODE) == ERROR)
  475. return ERROR;
  476. p_u8_input_buf = (unsigned char *)g_u16_uc_golden_cc_buf;
  477. for (u8_i = 0; u8_i < 96; u8_i++) {
  478. if (p_u8_input_buf[u8_i] != u8_read_buf[u8_i]) {
  479. DEBUGOUT("Set PRAM_FT_FW_GOLDEN_CC_ADDR NG:[%d]=%d->%d\r\n", u8_i, p_u8_input_buf[u8_i], u8_read_buf[u8_i]);
  480. return ERROR;
  481. }
  482. }
  483. /*DEBUGOUT("g_u16_uc_golden_cc_buf[0]=%X,g_u16_uc_golden_cc_buf[1]=%X,g_u16_uc_golden_cc_buf[2]=%X,g_u16_uc_golden_cc_buf[3]=%X,g_u16_uc_golden_cc_buf[4]=%X,g_u16_uc_golden_cc_buf[5]=%X\r\n",g_u16_uc_golden_cc_buf[0],g_u16_uc_golden_cc_buf[1],g_u16_uc_golden_cc_buf[2],g_u16_uc_golden_cc_buf[3],g_u16_uc_golden_cc_buf[4],g_u16_uc_golden_cc_buf[5]);
  484. * DEBUGOUT("u8_read_buf[0]=%X,u8_read_buf[1]=%X,u8_read_buf[2]=%X,u8_read_buf[3]=%X,u8_read_buf[4]=%X,u8_read_buf[5]=%X\r\n",u8_read_buf[0],u8_read_buf[1],u8_read_buf[2],u8_read_buf[3],u8_read_buf[4],u8_read_buf[5]);
  485. */
  486. if (handle_ic_write(SRAM_FT_RAWDATA_3_CC_ADDR, 96, (unsigned char *)g_u16_raw_data3_golden_cc_buf, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  487. return ERROR;
  488. if (handle_ic_read(SRAM_FT_RAWDATA_3_CC_ADDR, 96, (unsigned char *)u8_read_buf, g_u8_drv_interface, I2C_BYTE_MODE) == ERROR)
  489. return ERROR;
  490. p_u8_input_buf = (unsigned char *)g_u16_raw_data3_golden_cc_buf;
  491. for (u8_i = 0; u8_i < 96; u8_i++) {
  492. if (p_u8_input_buf[u8_i] != u8_read_buf[u8_i]) {
  493. DEBUGOUT("Set PRAM_FT_OPEN_GOLDEN_CC_ADDR NG:[%d]=%d->%d\r\n", u8_i, p_u8_input_buf[u8_i], u8_read_buf[u8_i]);
  494. return ERROR;
  495. }
  496. }
  497. return SUCCESS;
  498. }
  499. void dump_image_data_3x(short *p_image_buf, unsigned char u8_remap)
  500. {
  501. short *p_i16_buf = (short *)g_u16_raw_data_tmp;
  502. unsigned char u8_i, u8_j;
  503. memset(p_i16_buf, 0, MAX_IMAGE_BUFFER_SIZE * 2);
  504. if (u8_remap) {
  505. for (u8_i = 0; u8_i < MAX_IMAGE_BUFFER_SIZE; u8_i++) {
  506. if (g_u8_wearable_pin_map[u8_i] != F303_NA_P)
  507. p_i16_buf[g_u8_wearable_pin_map[u8_i]] = p_image_buf[u8_i];
  508. }
  509. } else
  510. memcpy(p_i16_buf, p_image_buf, MAX_IMAGE_BUFFER_SIZE << 1);
  511. for (u8_j = 0; u8_j < g_u8_channel_y; u8_j++) {
  512. for (u8_i = 0; u8_i < g_u8_channel_x; u8_i++)
  513. DEBUGOUT("%4d, ", p_i16_buf[u8_i + u8_j * g_u8_channel_x]);
  514. DEBUGOUT("\r\n");
  515. }
  516. }
  517. void dump_image_hex_data_3x(short *p_image_buf)
  518. {
  519. short *p_i16_buf = (short *)g_u16_raw_data_tmp;
  520. unsigned char u8_i, u8_j;
  521. memset(p_i16_buf, 0, MAX_IMAGE_BUFFER_SIZE * 2);
  522. for (u8_i = 0; u8_i < MAX_IMAGE_BUFFER_SIZE; u8_i++) {
  523. if (g_u8_wearable_pin_map[u8_i] != F303_NA_P)
  524. p_i16_buf[g_u8_wearable_pin_map[u8_i]] = p_image_buf[u8_i];
  525. }
  526. for (u8_j = 0; u8_j < g_u8_channel_y; u8_j++) {
  527. for (u8_i = 0; u8_i < g_u8_channel_x; u8_i++)
  528. DEBUGOUT("%4X, ", (p_i16_buf[u8_i + u8_j * g_u8_channel_x] & 0x7ff));
  529. DEBUGOUT("\r\n");
  530. }
  531. }
  532. STATUS check_test_fw_status_3x(unsigned char u8_target_status, unsigned char *p_u8_result)
  533. {
  534. unsigned int u32_read;
  535. if (handle_ic_read(FW_FT_ARG1_ADDR, 4, (unsigned char *)(&u32_read), g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  536. return ERROR;
  537. if ((u32_read & FT_TEST_STUATUS_PATTERN) == FT_TEST_STUATUS_PATTERN) {
  538. if (((unsigned char)(u32_read & 0x00FF)) == u8_target_status)
  539. *p_u8_result = 1;
  540. else {
  541. DEBUGOUT("[CTFS] Test STATUS NG!! (%x:%x)\r\n", u8_target_status, u32_read);
  542. *p_u8_result = 0;
  543. return ERROR;
  544. }
  545. DEBUGOUT("[CTFS] Test FW STATUS (%x:%x)\r\n", u8_target_status, u32_read);
  546. } else {
  547. DEBUGOUT("[CTFS] Test STATUS Not Ready!! (%x:%x)\r\n", u8_target_status, u32_read);
  548. *p_u8_result = 0;
  549. }
  550. return SUCCESS;
  551. }
  552. STATUS ft_test_do_fw_test_3x(unsigned short u16_test_items)
  553. {
  554. unsigned char u8_write_data[5], u8_result;
  555. unsigned int u32_read_data;
  556. short i16_time_out = 0;
  557. #if ENABLE_TEST_TIME_MEASURMENT
  558. unsigned int u32_fun_time = 0;
  559. u32_fun_time = get_system_time();
  560. DEBUGOUT("ft_test_do_fw_test Start Time= %d\r\n", u32_fun_time);
  561. #endif
  562. g_u32_wearable_test_result &= ~WEARABLE_FT_TEST_RESULT_TEST_INIT_NG;
  563. if ((u16_test_items & (IC_TEST_ITEMS_OPEN | IC_TEST_ITEMS_SHORT | IC_TEST_ITEMS_UC | IC_TEST_ITEMS_UB)) == 0)
  564. return SUCCESS;
  565. memset(u8_write_data, 0, sizeof(u8_write_data));
  566. u8_write_data[1] = FT_CMD_DO_FT_TEST | 0x80;
  567. u8_write_data[2] = (unsigned char) u16_test_items;
  568. u8_write_data[3] = (unsigned char)(u16_test_items >> 8);
  569. DEBUGOUT("Star FW Test!!\r\n");
  570. if (handle_ic_write(FW_SYS_CMD_ADDR, 4, u8_write_data, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  571. return ERROR;
  572. /*Wait test fw finish INT */
  573. /*Wait 20 Sec*/
  574. i16_time_out = 1000;
  575. while (i16_time_out--) {
  576. delay_ms(20);
  577. #if ENABLE_WDT
  578. Chip_WWDT_Feed(LPC_WWDT);/* reload the Watchdog timer*/
  579. #endif
  580. if (!gpio_touch_int_pin_state_access() || (i16_time_out < 10)) {
  581. if (check_test_fw_status_3x(FT_CMD_DO_FT_TEST, &u8_result) == ERROR) {
  582. DEBUGOUT("[FWT] Wait Test CMD NG (0x%x:%d)\r\n", FT_CMD_DO_FT_TEST, i16_time_out);
  583. return ERROR;
  584. } else if (u8_result == TRUE) {
  585. break;
  586. }
  587. }
  588. }
  589. if (handle_ic_read(FW_SYS_CMD_ADDR, 4, (unsigned char *)(&u32_read_data), g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  590. return ERROR;
  591. DEBUGOUT("[FWT]SysCMD1:0x%x (%d)\r\n", u32_read_data, i16_time_out);
  592. if (i16_time_out == IC_TEST_TIME_OUT) {
  593. DEBUGOUT("[FWT] Wait Test CMD Timeout!! (0x%x)\r\n", FT_CMD_DO_FT_TEST);
  594. return ERROR;
  595. }
  596. #if ENABLE_TEST_TIME_MEASURMENT
  597. DEBUGOUT("[FWT] FW Test Time(%d)\r\n", get_system_time() - u32_fun_time);
  598. #endif
  599. return SUCCESS;
  600. }
  601. STATUS enter_fw_test_mode_3x(void)
  602. {
  603. unsigned char u8_result = 0;
  604. short i16_time_out = 0;
  605. #if ENABLE_TEST_TIME_MEASURMENT
  606. unsigned int u32_fun_time = 0;
  607. u32_fun_time = get_system_time();
  608. #endif
  609. g_u32_wearable_test_result &= ~WEARABLE_FT_TEST_RESULT_TEST_INIT_NG;
  610. DEBUGOUT("[EFTM] Start\r\n");
  611. if ((g_st_test_info.u16_ft_test_item & (IC_TEST_ITEMS_OPEN | IC_TEST_ITEMS_SHORT |
  612. IC_TEST_ITEMS_UC | IC_TEST_ITEMS_UB)) == 0) {
  613. return SUCCESS;
  614. }
  615. g_u8_is_normal_fw = FALSE;
  616. i16_time_out = 300;
  617. u8_result = 0;
  618. while (i16_time_out--) {
  619. if (!gpio_touch_int_pin_state_access() || (i16_time_out < 20)) {
  620. if (check_test_fw_status_3x(FT_CMD_INIT, &u8_result) == ERROR)
  621. goto IC_INIT_NG;
  622. else if (u8_result == TRUE)
  623. break;
  624. }
  625. delay_ms(5);
  626. }
  627. if (i16_time_out == IC_TEST_TIME_OUT) {
  628. DEBUGOUT("[EFTM] FW State Check NG\r\n");
  629. goto IC_INIT_NG;
  630. }
  631. DEBUGOUT("[EFTM] Enter FT mode\r\n");
  632. if (set_test_info_thd_para_3x() == ERROR) {
  633. DEBUGOUT("[RUPI] Set test info, thd, para NG!\r\n");
  634. return ERROR;
  635. }
  636. #if ENABLE_TEST_TIME_MEASURMENT
  637. DEBUGOUT("[EFTM] (%d)\r\n", get_system_time() - u32_fun_time);
  638. #endif
  639. return SUCCESS;
  640. IC_INIT_NG:
  641. g_u32_wearable_test_result = WEARABLE_FT_TEST_RESULT_TEST_INIT_NG;
  642. return ERROR;
  643. }
  644. STATUS ft_test_read_used_pin_infor_3x(unsigned char *p_u8_infor)
  645. {
  646. /*unsigned char u8_i;*/
  647. unsigned char u8_r_buf[2];
  648. /*get Pin remap*/
  649. if (handle_ic_read(FW_FT_PIN_ADDR, 48, p_u8_infor, g_u8_drv_interface, I2C_BYTE_MODE) == ERROR) {
  650. DEBUGOUT("[RUPI] NG!\r\n");
  651. return ERROR;
  652. }
  653. /*
  654. * for (u8_i = 0; u8_i < 36; u8_i++) {
  655. * DEBUGOUT("Pin[%d] remap=%d\r\n", u8_i, p_u8_infor[u8_i]);
  656. * }
  657. */
  658. if (handle_ic_read(FW_FT_CHANNEL_X_ADDR, 2, u8_r_buf, g_u8_drv_interface, I2C_BYTE_MODE) == ERROR) {
  659. DEBUGOUT("[RUPI] NG!\r\n");
  660. return ERROR;
  661. }
  662. g_u8_channel_x = u8_r_buf[0];
  663. g_u8_channel_y = u8_r_buf[1];
  664. DEBUGOUT("[RUPI] X:%d,Y:%d\r\n", g_u8_channel_x, g_u8_channel_y);
  665. return SUCCESS;
  666. }
  667. STATUS ft_test_ctrl_mbist_fun_3x(unsigned char u8_enable)
  668. {
  669. unsigned int u32_read;
  670. if (u8_enable) {
  671. if (handle_ic_read(REG_SYSCON_BLKEN_ADDR, 4, (unsigned char *)(&u32_read), g_u8_drv_interface, I2C_WORD_MODE) == ERROR) {
  672. DEBUGOUT("Data RAM Test NG !!!\r\n");
  673. return ERROR;
  674. }
  675. u32_read |= (1 << 29);
  676. if (handle_ic_write(REG_SYSCON_BLKEN_ADDR, 4, (unsigned char *)&u32_read, g_u8_drv_interface, I2C_WORD_MODE) == ERROR) {
  677. DEBUGOUT("Data RAM Test NG !!!\r\n");
  678. return ERROR;
  679. }
  680. } else {
  681. if (handle_ic_read(REG_SYSCON_BLKEN_ADDR, 4, (unsigned char *)(&u32_read), g_u8_drv_interface, I2C_WORD_MODE) == ERROR) {
  682. DEBUGOUT("Data RAM Test NG !!!\r\n");
  683. return ERROR;
  684. }
  685. u32_read &= ~(1 << 29);
  686. if (handle_ic_write(REG_SYSCON_BLKEN_ADDR, 4, (unsigned char *)&u32_read, g_u8_drv_interface, I2C_WORD_MODE) == ERROR) {
  687. DEBUGOUT("Data RAM Test NG !!!\r\n");
  688. return ERROR;
  689. }
  690. }
  691. return SUCCESS;
  692. }
  693. /*
  694. * STATUS ft_test_ram_test_3x(unsigned char u8_is_stop_mcu)
  695. * {
  696. * unsigned int u32_read;
  697. * unsigned char u8_retry_times = 2;
  698. * unsigned int u32_write = 0;
  699. * if ((g_st_test_info.u16_ft_test_info_1) == WEARBLE_FT_PRAM_SYSTEM_NG_CASE) {
  700. * g_u32_wearable_test_result = WEARABLE_FT_TEST_RESULT_PRAM_NG;
  701. * return ERROR;
  702. * }
  703. *
  704. * RETRY_RAM_TEST:
  705. *
  706. * if (u8_is_stop_mcu) {
  707. * stop_mcu_3x(TRUE);
  708. * }
  709. *
  710. * if (ft_test_ctrl_mbist_fun_3x(ENABLE) == ERROR) {
  711. * goto EXIT_ERROR;
  712. * }
  713. *
  714. * u32_write = 0x04000080;
  715. * if (handle_ic_write(RAM_WRITE_TEST_ADDR1, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR) {
  716. * goto EXIT_ERROR;
  717. * }
  718. *
  719. * u32_write = 0x00FE90FE;
  720. * if (handle_ic_write(RAM_WRITE_TEST_ADDR2, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR) {
  721. * goto EXIT_ERROR;
  722. * }
  723. *
  724. * u32_write = 0x0A800080;
  725. * if (handle_ic_write(RAM_WRITE_TEST_ADDR3, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR) {
  726. * goto EXIT_ERROR;
  727. * }
  728. *
  729. * delay_ms(5);
  730. *
  731. * if (handle_ic_read(RAM_READ_TEST_ADDR1, 4, (unsigned char *)(&u32_read), g_u8_drv_interface, I2C_WORD_MODE) == ERROR) {
  732. * goto EXIT_ERROR;
  733. * }
  734. *
  735. * if ((u32_read & 0xFE00) != 0) {
  736. * DEBUGOUT("RAM Test NG 954[0x%x]!!!\r\n", u32_read);
  737. * goto EXIT_ERROR;
  738. * }
  739. *
  740. * if (handle_ic_read(RAM_READ_TEST_ADDR2, 4, (unsigned char *)(&u32_read), g_u8_drv_interface, I2C_WORD_MODE) == ERROR) {
  741. * goto EXIT_ERROR;
  742. * }
  743. *
  744. * if (u32_read != 0x19007F00) {
  745. * DEBUGOUT("RAM Test NG B04[0x%x]!!!\r\n", u32_read);
  746. * goto EXIT_ERROR;
  747. * }
  748. *
  749. * if (handle_ic_read(RAM_READ_TEST_ADDR3, 4, (unsigned char *)(&u32_read), g_u8_drv_interface, I2C_WORD_MODE) == ERROR) {
  750. * goto EXIT_ERROR;
  751. * }
  752. *
  753. * if (u32_read != 0x40007F00) {
  754. * DEBUGOUT("RAM Test NG B08[0x%x]!!!\r\n", u32_read);
  755. * goto EXIT_ERROR;
  756. * }
  757. *
  758. * if (ft_test_ctrl_mbist_fun_3x(DISABLE) == ERROR) {
  759. * goto EXIT_ERROR;
  760. * } else {
  761. * DEBUGOUT("RAM Test Pass\r\n");
  762. * return SUCCESS;
  763. * }
  764. *
  765. * EXIT_ERROR:
  766. * if ((u8_retry_times-- > 0)) {
  767. * goto RETRY_RAM_TEST;
  768. * }
  769. *
  770. * ft_test_ctrl_mbist_fun_3x(DISABLE);
  771. * g_u32_wearable_test_result = WEARABLE_FT_TEST_RESULT_PRAM_NG;
  772. * DEBUGOUT("PRAM Test NG !!!\r\n");
  773. * return ERROR;
  774. * }
  775. */
  776. STATUS ft_test_ram_test_3x(unsigned char u8_is_stop_mcu)
  777. {
  778. unsigned int u32_read;
  779. unsigned char u8_retry_times = 2, u8_check_time = 8;
  780. unsigned int u32_write = 0;
  781. unsigned int u32_addr = 0;
  782. unsigned short u16_retry, u16DataBufLength;
  783. if ((g_st_test_info.u16_ft_test_info_1) == WEARBLE_FT_PRAM_SYSTEM_NG_CASE) {
  784. g_u32_wearable_test_result = WEARABLE_FT_TEST_RESULT_PRAM_NG;
  785. return ERROR;
  786. }
  787. RETRY_RAM_TEST:
  788. #if ENABLE_WDT
  789. /* reload the Watchdog timer*/
  790. Chip_WWDT_Feed(LPC_WWDT);
  791. #endif
  792. if (u8_is_stop_mcu)
  793. stop_mcu_3x(TRUE);
  794. u32_write = (USEFW_LOCK | CONFIG_LOCK | COMP_LOCK | BASEL_LOCK | INICO_LOCK);
  795. if (handle_ic_write(REG_FLASHCTL_FLASH_PRAM_LOCK, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  796. goto EXIT_ERROR;
  797. /* i2c tx buffer size = 0x38 (56)*/
  798. u16DataBufLength = 0x38;
  799. u32_addr = 0;
  800. while (u32_addr < u16DataBufLength) {
  801. g_u8_data_buf[u32_addr] = 0xFF;
  802. g_u8_data_buf[u32_addr + 1] = 0x00;
  803. g_u8_data_buf[u32_addr + 2] = 0xAA;
  804. g_u8_data_buf[u32_addr + 3] = 0x55;
  805. u32_addr += 4;
  806. }
  807. u32_addr = PRAM_BOOT_START;
  808. while (u32_addr < PRAM_BOOT_LENGTH) {
  809. if ((u32_addr + u16DataBufLength) > PRAM_BOOT_LENGTH)
  810. u16DataBufLength = PRAM_BOOT_LENGTH - u32_addr;
  811. if (handle_ic_write(u32_addr, u16DataBufLength, g_u8_data_buf, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  812. goto EXIT_ERROR;
  813. u32_addr += u16DataBufLength;
  814. #if ENABLE_WDT
  815. /* reload the Watchdog timer*/
  816. Chip_WWDT_Feed(LPC_WWDT);
  817. #endif
  818. }
  819. gpio_touch_reset_pin_control(FALSE);/*Low*/
  820. delay_ms(1);
  821. gpio_touch_reset_pin_control(TRUE);/*High*/
  822. delay_ms(25);
  823. g_u8_mute_i2c_err_log = TRUE;
  824. u16_retry = 150;
  825. do {
  826. #if ENABLE_WDT
  827. /* reload the Watchdog timer*/
  828. Chip_WWDT_Feed(LPC_WWDT);
  829. #endif
  830. delay_ms(35);
  831. if (handle_ic_read(REG_FLASHCTL_FLASH_STATE_REG_ADDR, 4, (unsigned char *)(&u32_read), g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  832. goto EXIT_ERROR;
  833. /*delay_ms(2);*/
  834. u16_retry--;
  835. } while (((u32_read & BLDR_FINISH) != BLDR_FINISH) && (u16_retry != 0));
  836. g_u8_mute_i2c_err_log = FALSE;
  837. if ((u32_read & BLDR_FINISH) != BLDR_FINISH) {
  838. g_u32_wearable_test_result |= WEARABLE_FT_TEST_RESULT_PRAM_NG;
  839. DEBUGOUT("PRAM Test NG !!!\r\n");
  840. return ERROR;
  841. }
  842. if ((u8_check_time-- > 0))
  843. goto RETRY_RAM_TEST;
  844. DEBUGOUT("RAM Test Pass\r\n");
  845. return SUCCESS;
  846. EXIT_ERROR:
  847. if ((u8_retry_times-- > 0)) {
  848. u8_check_time = 4;
  849. goto RETRY_RAM_TEST;
  850. }
  851. g_u32_wearable_test_result = WEARABLE_FT_TEST_RESULT_PRAM_NG;
  852. DEBUGOUT("PRAM Test NG !!!\r\n");
  853. g_u8_mute_i2c_err_log = FALSE;
  854. return ERROR;
  855. }
  856. STATUS ft_test_connect_test_3x(void)
  857. {
  858. unsigned char u8_retry = IC_TEST_RETRY_TIME;
  859. unsigned int u32_w_buf, u32_r_buf;
  860. unsigned int u32_test_addr = RM_DATAMEM0_BASE;
  861. char i8_str[8];
  862. if ((g_st_test_info.u16_ft_test_info_1) == WEARBLE_FT_I2C_SYSTEM_NG_CASE) {
  863. g_u32_wearable_test_result = WEARABLE_FT_TEST_RESULT_I2C_NG;
  864. return ERROR;
  865. }
  866. RETRY_CONNECT_TEST:
  867. if (g_u8_drv_interface == SPI_INTERFACE)
  868. snprintf(i8_str, RM_F303_MAX_STR_LENGTH, "SPI");
  869. else
  870. snprintf(i8_str, RM_F303_MAX_STR_LENGTH, "I2C");
  871. u32_w_buf = 0x55aa00ff;
  872. if (handle_ic_write(u32_test_addr, 4, (unsigned char *)&u32_w_buf, g_u8_drv_interface, I2C_WORD_MODE) == ERROR) {
  873. DEBUGOUT("%s Test Write NG!!\r\n", i8_str);
  874. goto NG_CASE;
  875. }
  876. if (handle_ic_read(u32_test_addr, 4, (unsigned char *)&u32_r_buf, g_u8_drv_interface, I2C_BYTE_MODE) == ERROR) {
  877. DEBUGOUT("%s Test Read NG!!\r\n", i8_str);
  878. goto NG_CASE;
  879. }
  880. if (u32_w_buf != u32_r_buf) {
  881. DEBUGOUT("%s Test Compare NG [%d], W=0x%x,R=0x%x\r\n", i8_str, 0, u32_w_buf, u32_r_buf);
  882. goto NG_CASE;
  883. }
  884. #if ENABLE_WDT
  885. Chip_WWDT_Feed(LPC_WWDT);/* reload the Watchdog timer*/
  886. #endif
  887. DEBUGOUT("%s Test Pass\r\n", i8_str);
  888. return SUCCESS;
  889. NG_CASE:
  890. if (--u8_retry > 0) {
  891. DEBUGOUT("%s Test Retry=%d\r\n", i8_str, u8_retry);
  892. if (hardware_reset_3x(TRUE) == ERROR)
  893. goto NG_CASE2;
  894. /*Stop MCU*/
  895. stop_mcu_3x(FALSE);
  896. goto RETRY_CONNECT_TEST;
  897. }
  898. NG_CASE2:
  899. g_u32_wearable_test_result = WEARABLE_FT_TEST_RESULT_I2C_NG;
  900. DEBUGOUT("%s Test NG !!!\r\n", i8_str);
  901. return ERROR;
  902. }
  903. STATUS ft_test_reset_pin_test_3x(void)
  904. {
  905. unsigned int u32_write = 0;
  906. if ((g_st_test_info.u16_ft_test_info_1) == WEARBLE_FT_RESET_PIN_SYSTEM_NG_CASE) {
  907. g_u32_wearable_test_result = WEARABLE_FT_TEST_RESULT_RESET_NG;
  908. return ERROR;
  909. }
  910. u32_write = 0x00000404;
  911. if (handle_ic_write(REG_SYSCON_MISCIER_ADDR, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  912. return ERROR;
  913. if (!gpio_touch_int_pin_state_access()) { /* check INT in high state*/
  914. g_u32_wearable_test_result = WEARABLE_FT_TEST_RESULT_INT_NG;
  915. return ERROR;
  916. }
  917. gpio_touch_reset_pin_control(FALSE);/*Low*/
  918. delay_ms(1);
  919. if (gpio_touch_int_pin_state_access()) {
  920. g_u32_wearable_test_result = WEARABLE_FT_TEST_RESULT_RESET_NG;
  921. DEBUGOUT("Reset Pin Test NG(Not High) !!!\r\n");
  922. return ERROR;
  923. }
  924. gpio_touch_reset_pin_control(TRUE);/*High*/
  925. delay_ms(25);
  926. DEBUGOUT("Reset Pin Test Pass !!!\r\n");
  927. return SUCCESS;
  928. }
  929. STATUS ft_test_panel_model_check_3x(unsigned short u16_version)
  930. {
  931. unsigned int u32_read;
  932. unsigned short u16_model_version;
  933. if (handle_ic_read(FW_FT_SRAM_FW_VERSION, 4, (unsigned char *)(&u32_read), g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  934. return ERROR;
  935. u16_model_version = (u32_read & 0x0000FFFF);
  936. DEBUGOUT("Panel Model Test! 0x%08X:0x%08X\r\n", u32_read, u16_version);
  937. DEBUGOUT("Panel Model 0x%08X\r\n", u16_model_version);
  938. if (u16_model_version == u16_version)
  939. return SUCCESS;
  940. DEBUGOUT("Panel Model NG! 0x%x:0x%x\r\n", u16_model_version, u16_version);
  941. return ERROR;
  942. }
  943. void ft_raw_data_checksum_cal_3x(unsigned short *u16_buffer)
  944. {
  945. unsigned char u8_i;
  946. u16_buffer[48] = 0x55AA;
  947. u16_buffer[49] = 0;
  948. for (u8_i = 0; u8_i < (MAX_SENSING_PIN_NUM - 1); u8_i++)
  949. u16_buffer[49] += u16_buffer[u8_i];
  950. DEBUGOUT("[RDCSA] %x:%x\r\n", u16_buffer[48], u16_buffer[49]);
  951. }
  952. void ft_test_result_checksum_cal_3x(unsigned char *u8_buffer)
  953. {
  954. unsigned char u8_i;
  955. u8_buffer[48] = 0x5A;
  956. u8_buffer[49] = 0;
  957. for (u8_i = 0; u8_i < (MAX_SENSING_PIN_NUM - 1); u8_i++)
  958. u8_buffer[49] += u8_buffer[u8_i];
  959. DEBUGOUT("[TRCSA] %x:%x\r\n", u8_buffer[48], u8_buffer[49]);
  960. }
  961. STATUS ft_raw_data_checksum_check_3x(unsigned short *u16_buffer)
  962. {
  963. unsigned char u8_i;
  964. unsigned short u16_sum = 0;
  965. if (u16_buffer[48] != 0x55AA) {
  966. DEBUGOUT("u16_buffer[34]:%x\r\n", u16_buffer[48]);
  967. DEBUGOUT("[RDCSC] Pattern NG! [0x%p](0x%x)\n", u16_buffer, u16_buffer[48]);
  968. return ERROR;
  969. }
  970. /*u16_buffer[35]=0;*/
  971. for (u8_i = 0; u8_i < (MAX_SENSING_PIN_NUM - 1); u8_i++)
  972. u16_sum += u16_buffer[u8_i];
  973. if (u16_buffer[49] != u16_sum) {
  974. DEBUGOUT("[RDCSC] Check SUM NG! [0x%p](0x%x:0x%x)\n", u16_buffer, u16_sum, u16_buffer[49]);
  975. return ERROR;
  976. }
  977. DEBUGOUT("[RDCSC] PASS (0x%x:0x%x)\r\n", u16_buffer[48], u16_buffer[49]);
  978. return SUCCESS;
  979. }
  980. STATUS ft_test_result_checksum_check_3x(unsigned char *u8_buffer)
  981. {
  982. unsigned char u8_i;
  983. unsigned char u8_sum = 0;
  984. if (u8_buffer[48] != 0x5A) {
  985. DEBUGOUT("[TRCSC] Pattern NG! [0x%p](0x%x:0x%x)\n", u8_buffer, u8_buffer[48], u8_buffer[49]);
  986. return ERROR;
  987. }
  988. /*u32_buffer[35]=0;*/
  989. for (u8_i = 0; u8_i < (MAX_SENSING_PIN_NUM - 1); u8_i++)
  990. u8_sum += u8_buffer[u8_i];
  991. if (u8_buffer[49] != u8_sum) {
  992. DEBUGOUT("[TRCSC] Check SUM NG! [0x%p](0x%x:0x%x)\n", u8_buffer, u8_sum, u8_buffer[49]);
  993. return ERROR;
  994. }
  995. DEBUGOUT("[TRCSC] PASS (0x%x:0x%x)\r\n", u8_buffer[48], u8_buffer[49]);
  996. return SUCCESS;
  997. }
  998. STATUS baseline_update_control_3x(bool b_enable_baseline_update)
  999. {
  1000. unsigned int u32_write_buf;
  1001. unsigned char u8_read;
  1002. short i16_time_out = 100;
  1003. if (b_enable_baseline_update) {
  1004. u32_write_buf = (SYS_CMD_FUNC_DIS_BS_UPDATE);
  1005. DEBUGOUT("[BUC] Enable Baseline update\r\n");
  1006. } else {
  1007. u32_write_buf = (DIS_BASELINE_UPDATE | SYS_CMD_FUNC_DIS_BS_UPDATE);
  1008. DEBUGOUT("[BUC] Disable Baseline update\r\n");
  1009. }
  1010. if (handle_ic_write(FW_SYS_CMD_ADDR, 4, (unsigned char *)&u32_write_buf, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  1011. return ERROR;
  1012. delay_ms(5);
  1013. while (i16_time_out--) {
  1014. if (handle_ic_read(FW_SYS_CMD_ADDR, 1, &u8_read, g_u8_drv_interface, I2C_BYTE_MODE) == SUCCESS) {
  1015. if (u8_read == 0x00)
  1016. break;
  1017. } else {
  1018. DEBUGOUT("[BUC] I2C Read NG\r\n");
  1019. return ERROR;
  1020. }
  1021. delay_ms(2);
  1022. }
  1023. if (i16_time_out == IC_TEST_TIME_OUT) {
  1024. DEBUGOUT("[BUC] Baseline Update Control (%d) NG\r\n", b_enable_baseline_update);
  1025. return ERROR;
  1026. }
  1027. return SUCCESS;
  1028. }
  1029. STATUS wait_fw_init_ready_3x(void)
  1030. {
  1031. unsigned short u16_time_out;
  1032. unsigned char u8_r_buf[2];
  1033. u16_time_out = 100;
  1034. /*Check FW Ready ?*/
  1035. do {
  1036. if (handle_ic_read(FW_FT_ARG0_ADDR, 2, u8_r_buf, g_u8_drv_interface, I2C_BYTE_MODE) == ERROR)
  1037. return ERROR;
  1038. DEBUGOUT("FW Flag = 0x%x,0x%x\r\n", u8_r_buf[0], u8_r_buf[1]);
  1039. if (u8_r_buf[0] == 0xAA && u8_r_buf[1] == 0x55)
  1040. return SUCCESS;
  1041. delay_ms(2);
  1042. } while (u16_time_out-- > 0);
  1043. return ERROR;
  1044. }
  1045. STATUS enter_normal_fw_3x(void)
  1046. {
  1047. unsigned char u8_pattern_noise_only = 0;
  1048. #if ENABLE_TEST_TIME_MEASURMENT
  1049. unsigned int u32_fun_time = 0;
  1050. u32_fun_time = get_system_time();
  1051. #endif
  1052. if (g_u8_is_normal_fw)
  1053. return SUCCESS;
  1054. #if !SELFTEST_3X
  1055. /*Set INT Falling Triggle*/
  1056. gpio_touch_int_trigger_control(FALSE);
  1057. #endif
  1058. g_u32_wearable_test_result &= ~WEARABLE_FT_TEST_RESULT_NORMAL_FW_RESET_NG;
  1059. if (g_u8_drv_interface == SPI_INTERFACE) {
  1060. if (hardware_reset_3x(TRUE) == ERROR) {
  1061. DEBUGOUT("[ENF]No INT, no OTP!!\r\n");
  1062. g_u32_wearable_test_result |= WEARABLE_FT_TEST_RESULT_NORMAL_FW_RESET_NG;
  1063. return ERROR;
  1064. }
  1065. #if !SELFTEST_3X
  1066. if (burn_pram_from_dongle_flash_3x() == ERROR)
  1067. return ERROR;
  1068. #endif
  1069. } else {
  1070. if ((g_st_test_info.u16_ft_test_item & ~(IC_TEST_ITEMS_SYSTEM | IC_TEST_ITEMS_PANEL_TEST_2)) == FALSE) {
  1071. u8_pattern_noise_only = TRUE;
  1072. DEBUGOUT("Panel Test!!!\r\n");
  1073. }
  1074. if (!u8_pattern_noise_only) {
  1075. /*PRAM Test*/
  1076. if (ft_test_ram_test_3x(1) == ERROR)
  1077. return ERROR;
  1078. }
  1079. if (hardware_reset_3x(FALSE) == ERROR) {
  1080. DEBUGOUT("[ENF]No INT, no OTP!!\r\n");
  1081. g_u32_wearable_test_result |= WEARABLE_FT_TEST_RESULT_NORMAL_FW_RESET_NG;
  1082. return ERROR;
  1083. }
  1084. }
  1085. if (wait_fw_init_ready_3x() == ERROR)
  1086. return ERROR;
  1087. if (ft_test_read_used_pin_infor_3x(g_u8_wearable_pin_map) == ERROR)
  1088. return ERROR;
  1089. #if ENABLE_TEST_TIME_MEASURMENT
  1090. DEBUGOUT("[ENF] (%d)\r\n", get_system_time() - u32_fun_time);
  1091. #endif
  1092. g_u8_is_normal_fw = TRUE;
  1093. return SUCCESS;
  1094. }
  1095. STATUS check_cc_bl_flag_3x(void)
  1096. {
  1097. unsigned char u8_read_buf[4];
  1098. unsigned char u8_is_cc_ready = 0;
  1099. unsigned char u8_fw_version[4];
  1100. short i16_time_out;
  1101. DEBUGOUT("[CCBF] Check CC BL Flag\r\n");
  1102. if (handle_ic_read(FW_FT_FW_VERSION, 4, u8_fw_version, g_u8_drv_interface, I2C_BYTE_MODE) == ERROR)
  1103. return ERROR;
  1104. i16_time_out = 20;
  1105. while (i16_time_out--) {
  1106. if (!u8_is_cc_ready) {
  1107. if (handle_ic_read(PRAM_ADDR_CC_INFO, 4, u8_read_buf, g_u8_drv_interface, I2C_BYTE_MODE) == ERROR)
  1108. return ERROR;
  1109. if ((u8_read_buf[0] >= 1) && (u8_read_buf[2] == u8_fw_version[2]) && (u8_read_buf[3] == u8_fw_version[3]))
  1110. u8_is_cc_ready = 1;
  1111. }
  1112. if (u8_is_cc_ready)
  1113. break;
  1114. delay_ms(1);
  1115. }
  1116. /*Check flag*/
  1117. if (i16_time_out == IC_TEST_TIME_OUT) {
  1118. DEBUGOUT("CC Flag=%d NG!!\r\n", u8_read_buf[0]);
  1119. DEBUGOUT("FW Ver=%X.%X:%X.%X NG!!\r\n", u8_fw_version[2], u8_fw_version[3], u8_read_buf[2], u8_read_buf[3]);
  1120. return ERROR;
  1121. }
  1122. return SUCCESS;
  1123. }
  1124. STATUS burn_cc_to_ic_flash_3x(void)
  1125. {
  1126. short i16_time_out = 1000;
  1127. unsigned int u32_cc_table;
  1128. unsigned char u8_fw_value[4];
  1129. unsigned int u32_write = 0;
  1130. #if SELFTEST_3X
  1131. unsigned int u32_read;
  1132. #endif
  1133. #if ENABLE_TEST_TIME_MEASURMENT_CC
  1134. DEBUGOUT("[BCTF] Before Switch to Bootloader\r\n");
  1135. g_u32_spend_time = get_system_time();
  1136. #endif
  1137. #if !SELFTEST /*210708 add, for fw use bootloader block*/
  1138. if (stop_mcu_3x(0) == ERROR)
  1139. return ERROR;
  1140. /*WRT boot-loader to PRAM first*/
  1141. u32_write = (USEFW_LOCK | CONFIG_LOCK | COMP_LOCK | BASEL_LOCK);
  1142. if (handle_ic_write(REG_FLASHCTL_FLASH_PRAM_LOCK, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  1143. return ERROR;
  1144. /*read flash data and write to pram (Bootloader)*/
  1145. if (handle_spiFlash_to_pram(PRAM_BOOT_START, PRAM_BOOT_LENGTH, PRAM_BOOT_START) == ERROR) {
  1146. DEBUGOUT("confirm crc error!!\r\n");
  1147. return ERROR;
  1148. }
  1149. /*check pram bootloader crc*/
  1150. if (check_pram_crc32_3x(PRAM_BOOT_START, PRAM_BOOT_CRC_LENGTH) == ERROR) {
  1151. DEBUGOUT("confirm bootloader crc error!!\r\n");
  1152. return ERROR;
  1153. }
  1154. /*read flash data and write to pram (Initial_code)*/
  1155. if (handle_spiFlash_to_pram(PRAM_DIS_INIT_START, PRAM_DIS_INIT_LENGTH, PRAM_DIS_INIT_START) == ERROR) {
  1156. DEBUGOUT("confirm crc error!!\r\n");
  1157. return ERROR;
  1158. }
  1159. /*check pram Initial code crc*/
  1160. if (check_pram_crc32_3x(PRAM_DIS_INIT_START, 0x7C) == ERROR) {
  1161. DEBUGOUT("confirm init crc error!!\r\n");
  1162. return ERROR;
  1163. }
  1164. #endif
  1165. /*Set Skip_Load = 1*/
  1166. u32_write = (BL_CRC_CHK | SKIP_LOAD);
  1167. if (handle_ic_write(REG_FLASHCTL_FLASH_STATE_REG_ADDR, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  1168. return ERROR;
  1169. /*wait sw rst finish*/
  1170. u32_write = BLKRST_SW_RST;
  1171. if (handle_ic_write(REG_SYSCON_BLKRST_ADDR, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  1172. return ERROR;
  1173. delay_ms(2);
  1174. if (wait_fw_state_3x(BOOT_RET_DATA_ADDR, WAIT_TEST_MODE, 1, i16_time_out) == ERROR) {
  1175. DEBUGOUT("[BCTF] Check Burn CC & BL Fail\r\n");
  1176. return ERROR;
  1177. }
  1178. #if ENABLE_TEST_TIME_MEASURMENT_CC
  1179. DEBUGOUT("[BCTF] End of Switch to Bootloader = %d\r\n", get_system_time() - g_u32_spend_time);
  1180. g_u32_spend_time = get_system_time();
  1181. DEBUGOUT("TICK=%d\r\n", get_system_time());
  1182. #endif
  1183. #if SELFTEST_3X
  1184. if (sysfs_burn_cc_bl()) {
  1185. /*Read Flash CC Table*/
  1186. if (read_fpc_flash_3x(FLASH_NORMAL_FW_CC_TABLE_ADDR, &u32_cc_table) == ERROR)
  1187. return ERROR;
  1188. DEBUGOUT("Flash Do CC FW Version=0x%04X\r\n", (u32_cc_table & 0xFFFF0000) >> 16);
  1189. DEBUGOUT("Flash Do CC Flag=0x%X\r\n", (u32_cc_table & 0x0000FFFF));
  1190. g_u32_fw_cc_version = u32_cc_table;
  1191. /*Read PRAM FW Version*/
  1192. if (handle_ic_read(FW_FT_SRAM_FW_VERSION, 4, u8_fw_value, g_u8_drv_interface, I2C_BYTE_MODE) == ERROR)
  1193. return ERROR;
  1194. DEBUGOUT("SRAM FW Version=0x%03x,0x%03x\r\n", u8_fw_value[3], u8_fw_value[2]);
  1195. if (((u32_cc_table & 0xFF000000) >> 24) != u8_fw_value[3] || ((u32_cc_table & 0x00FF0000) >> 16) != u8_fw_value[2]) {
  1196. DEBUGOUT("Flash CC Table FW Version is not match!\r\n");
  1197. if (handle_ic_read(REG_FLASHCTL_FLASH_STATE_REG_ADDR, 4, (unsigned char *)(&u32_read), g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  1198. DEBUGOUT("read 5000 0918 error\r\n");
  1199. DEBUGOUT("Flash 0x50000918=0x%08X\r\n", u32_read);
  1200. return ERROR;
  1201. }
  1202. return SUCCESS;
  1203. } else
  1204. return ERROR;
  1205. #else
  1206. if (burn_to_ic_flash_3x(COMP_AREA) == ERROR) {
  1207. DEBUGOUT("[BCTF] Burn CC & BL Fail\r\n");
  1208. return ERROR;
  1209. }
  1210. u32_write = 0x00000000;
  1211. if (handle_ic_write(BOOT_TEST_MODE_ADDR, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  1212. return ERROR;
  1213. /* clr sync_data(0x20000200) = 0 as finish*/
  1214. u32_write = 0x00000000;
  1215. if (handle_ic_write(BOOT_SYNC_DATA_ADDR, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  1216. return ERROR;
  1217. delay_ms(10);
  1218. if (wait_fw_state_3x(REG_FLASHCTL_FLASH_STATE_REG_ADDR, 0x4000, 2, i16_time_out) == ERROR) {
  1219. DEBUGOUT("[BCTF] Check Burn CC & BL Fail\r\n");
  1220. return ERROR;
  1221. }
  1222. #if ENABLE_AUO_VERIFY_LOG
  1223. if (read_fpc_flash_3x((unsigned int)(FLASH_FW_START + PRAM_FW_LENGTH - 4), &u32_i2c_read_data))
  1224. DEBUGOUT("Normal FW CRC=0x%08X\r\n", u32_i2c_read_data);
  1225. #endif
  1226. #if ENABLE_TEST_TIME_MEASURMENT_CC
  1227. DEBUGOUT("BCTF] Burn to flash finish[Tick=%d]!\r\n", get_system_time() - g_u32_spend_time);
  1228. #endif
  1229. /*Read Flash CC Table*/
  1230. if (read_fpc_flash_3x(FLASH_NORMAL_FW_CC_TABLE_ADDR, &u32_cc_table) == ERROR)
  1231. return ERROR;
  1232. DEBUGOUT("Flash Do CC FW Version=0x%04X\r\n", (u32_cc_table & 0xFFFF0000) >> 16);
  1233. DEBUGOUT("Flash Do CC Flag=0x%X\r\n", (u32_cc_table & 0x0000FFFF));
  1234. /*Read PRAM FW Version*/
  1235. if (handle_ic_read(FW_FT_SRAM_FW_VERSION, 4, u8_fw_value, g_u8_drv_interface, I2C_BYTE_MODE) == ERROR)
  1236. return ERROR;
  1237. DEBUGOUT("SRAM FW Version=0x%03x,0x%03x\r\n", u8_fw_value[3], u8_fw_value[2]);
  1238. if (((u32_cc_table & 0xFF000000) >> 24) != u8_fw_value[3] || ((u32_cc_table & 0x00FF0000) >> 16) != u8_fw_value[2]) {
  1239. DEBUGOUT("Flash CC Table FW Version is not match!\r\n");
  1240. return ERROR;
  1241. }
  1242. return SUCCESS;
  1243. #endif
  1244. }
  1245. STATUS do_calibration_3x(unsigned char u8_do_calibration_cmd, unsigned char u8_burn_flash)
  1246. {
  1247. unsigned char u8_value[4];
  1248. short u8_time_out = 100;
  1249. unsigned char u8_retry = IC_TEST_RETRY_TIME;
  1250. g_u32_wearable_test_result &= ~(WEARABLE_FT_TEST_RESULT_CC_CALIBRATION_NG | WEARABLE_FT_TEST_RESULT_BURN_CC_NG);
  1251. if (u8_do_calibration_cmd == TRUE) {
  1252. #if ENABLE_TEST_TIME_MEASURMENT_CC
  1253. DEBUGOUT("[DOCC] Start do calibration (%d)\r\n", get_system_time());
  1254. g_u32_spend_time = get_system_time();
  1255. #endif
  1256. while (u8_retry--) {
  1257. u8_value[0] = SYS_CMD_DO_CC_CAL;
  1258. if (handle_ic_write(FW_SYS_CMD_ADDR, 1, u8_value, g_u8_drv_interface, I2C_BYTE_MODE) == ERROR) /*Trigger Calibration*/
  1259. return ERROR;
  1260. u8_time_out = 400;
  1261. /* Wait calibration ready*/
  1262. while (u8_time_out--) {
  1263. delay_ms(10);/*20*/
  1264. if (handle_ic_read(FW_SYS_CMD_ADDR, 4, u8_value, g_u8_drv_interface, I2C_BYTE_MODE) == ERROR)
  1265. return ERROR;
  1266. else if (u8_value[0] == 0)
  1267. break;
  1268. #if ENABLE_WDT
  1269. Chip_WWDT_Feed(LPC_WWDT);/* reload the Watchdog timer*/
  1270. #endif
  1271. }
  1272. if (u8_time_out == IC_TEST_TIME_OUT) {
  1273. if (u8_retry) {
  1274. DEBUGOUT("[DOCC] Do CC Retry (%d,%d)", u8_retry, u8_value[0]);
  1275. hardware_reset_3x(TRUE);
  1276. #if !SELFTEST_3X
  1277. if (g_u8_drv_interface == SPI_INTERFACE) {
  1278. if (burn_pram_from_dongle_flash_3x() == ERROR)
  1279. return ERROR;
  1280. }
  1281. #endif
  1282. delay_ms(20);
  1283. continue;
  1284. } else {
  1285. g_u32_wearable_test_result |= WEARABLE_FT_TEST_RESULT_CC_CALIBRATION_NG;
  1286. DEBUGOUT("[DOCC] SYS CMD CC NG\r\n");
  1287. return ERROR;
  1288. }
  1289. } else {
  1290. if (check_cc_bl_flag_3x() == ERROR) {
  1291. if (u8_retry) {
  1292. DEBUGOUT("[DOCC] CC Flag Retry (%d)", u8_retry);
  1293. hardware_reset_3x(TRUE);
  1294. #if !SELFTEST_3X
  1295. if (g_u8_drv_interface == SPI_INTERFACE) {
  1296. if (burn_pram_from_dongle_flash_3x() == ERROR)
  1297. return ERROR;
  1298. }
  1299. #endif
  1300. delay_ms(20);
  1301. continue;
  1302. } else {
  1303. g_u32_wearable_test_result |= WEARABLE_FT_TEST_RESULT_CC_CALIBRATION_NG;
  1304. DEBUGOUT("[DOCC] CC Flag NG\r\n");
  1305. return ERROR;
  1306. }
  1307. } else /*Calibration OK*/
  1308. break;
  1309. }
  1310. }
  1311. #if ENABLE_TEST_TIME_MEASURMENT_CC
  1312. DEBUGOUT("[DOCC] Do CC Finish! [%d:%d]\r\n", get_system_time() - g_u32_spend_time, u8_time_out);
  1313. g_u32_spend_time = get_system_time();
  1314. #endif
  1315. }
  1316. if (u8_burn_flash == FALSE) {
  1317. DEBUGOUT("[DOCC] Do Calibration Finish \r\n");
  1318. return SUCCESS;
  1319. }
  1320. if (burn_cc_to_ic_flash_3x() == ERROR) {
  1321. DEBUGOUT("[DOCC] Burn to flash NG!\r\n");
  1322. hardware_reset_3x(TRUE);
  1323. g_u32_wearable_test_result |= WEARABLE_FT_TEST_RESULT_BURN_CC_NG;
  1324. return ERROR;
  1325. }
  1326. #if ENABLE_TEST_TIME_MEASURMENT_CC
  1327. DEBUGOUT("[DOCC] Burn CC Finish (%d)\r\n", get_system_time() - g_u32_spend_time);
  1328. #endif
  1329. DEBUGOUT("[DOCC] Burn CC Finish \r\n");
  1330. return SUCCESS;
  1331. }
  1332. STATUS hw_int_pin_Test_3x(void)
  1333. {
  1334. unsigned int u32_write = 0;
  1335. if ((g_st_test_info.u16_ft_test_info_1) == WEARBLE_FT_INT_SYSTEM_NG_CASE) {
  1336. g_u32_wearable_test_result = WEARABLE_FT_TEST_RESULT_INT_NG;
  1337. return ERROR;
  1338. }
  1339. /*Trigger INT to Low*/
  1340. u32_write = 0x00000004;
  1341. if (handle_ic_write(REG_SYSCON_MISCIER_ADDR, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  1342. return ERROR;
  1343. /*Read Pin state*/
  1344. if (!gpio_touch_int_pin_state_access()) {
  1345. /*DEBUGOUT("INT is LOW\r\n");*/
  1346. } else {
  1347. DEBUGOUT("INT Test NG!\r\n");
  1348. g_u32_wearable_test_result = WEARABLE_FT_TEST_RESULT_INT_NG;
  1349. return ERROR;
  1350. }
  1351. /*Trigger INT to High*/
  1352. u32_write = 0x00000404;
  1353. if (handle_ic_write(REG_SYSCON_MISCIER_ADDR, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  1354. return ERROR;
  1355. /*Read Pin state*/
  1356. if (gpio_touch_int_pin_state_access()) {
  1357. /*DEBUGOUT("INT is High\r\n");*/
  1358. } else {
  1359. DEBUGOUT("INT Test NG!\r\n");
  1360. g_u32_wearable_test_result = WEARABLE_FT_TEST_RESULT_INT_NG;
  1361. return ERROR;
  1362. }
  1363. gpio_touch_int_access(TRUE);
  1364. DEBUGOUT("INT Test Pass\r\n");
  1365. return SUCCESS;
  1366. }
  1367. STATUS read_test_fw_data_3x(unsigned short u16_test_items)
  1368. {
  1369. unsigned char u8_retry = IC_TEST_RETRY_TIME;
  1370. unsigned int u32_test_item_result;
  1371. #if ENABLE_TEST_TIME_MEASURMENT
  1372. unsigned int u32_fun_time = 0;
  1373. u32_fun_time = get_system_time();
  1374. #endif
  1375. g_u32_wearable_test_result &= ~(WEARABLE_FT_TEST_RESULT_GET_DATA_NG | WEARABLE_FT_TEST_RESULT_OPEN_NG
  1376. | WEARABLE_FT_TEST_RESULT_SHORT_NG | WEARABLE_FT_TEST_RESULT_UB_NG
  1377. | WEARABLE_FT_TEST_RESULT_UC_NG | WEARABLE_FT_TEST_RESULT_SINGLE_CC_OPEN_NG
  1378. | WEARABLE_FT_TEST_RESULT_SINGLE_CC_SHORT_NG);
  1379. if ((g_st_test_info.u16_ft_test_item & (IC_TEST_ITEMS_OPEN | IC_TEST_ITEMS_SHORT |
  1380. IC_TEST_ITEMS_UC | IC_TEST_ITEMS_UB)) == 0) {
  1381. return SUCCESS;
  1382. }
  1383. RETRY:
  1384. memset(g_i16_raw_data_1_short_buf, 0, sizeof(g_i16_raw_data_1_short_buf));
  1385. memset(g_i16_raw_data_2_open_buf, 0, sizeof(g_i16_raw_data_2_open_buf));
  1386. memset(g_u16_raw_data3_cc_buf, 0, sizeof(g_u16_raw_data3_cc_buf));
  1387. memset(g_u16_uc_buf, 0, sizeof(g_u16_uc_buf));
  1388. memset(g_u8_wearable_pin_map, F303_NA_P, sizeof(g_u8_wearable_pin_map));
  1389. if (handle_ic_read(FT_RAWDATA1_SHORT_BUF_ADDR, MAX_SENSING_PIN_NUM * 2, (unsigned char *)g_i16_raw_data_1_short_buf, g_u8_drv_interface, I2C_BYTE_MODE) == ERROR)
  1390. goto ERROR_EXIT;
  1391. if (handle_ic_read(FT_RAWDATA2_OPEN_BUF_ADDR, MAX_SENSING_PIN_NUM * 2, (unsigned char *)g_i16_raw_data_2_open_buf, g_u8_drv_interface, I2C_BYTE_MODE) == ERROR)
  1392. goto ERROR_EXIT;
  1393. if (handle_ic_read(FT_RAWDATA3_CC_BUF_ADDR, MAX_SENSING_PIN_NUM * 2, (unsigned char *)(g_u16_raw_data3_cc_buf), g_u8_drv_interface, I2C_BYTE_MODE) == ERROR)
  1394. goto ERROR_EXIT;
  1395. if (handle_ic_read(FT_UC_BUF_ADDR, MAX_SENSING_PIN_NUM * 2, (unsigned char *)g_u16_uc_buf, g_u8_drv_interface, I2C_BYTE_MODE) == ERROR)
  1396. goto ERROR_EXIT;
  1397. if (handle_ic_read(FT_TEST_RESULT_BUF_ADDR, MAX_SENSING_PIN_NUM, (unsigned char *)(g_u8_test_result), g_u8_drv_interface, I2C_BYTE_MODE) == ERROR)
  1398. goto ERROR_EXIT;
  1399. if (handle_ic_read(FT_TEST_ITEM_RESULT, 4, (unsigned char *)(&u32_test_item_result), g_u8_drv_interface, I2C_BYTE_MODE) == ERROR)
  1400. goto ERROR_EXIT;
  1401. if (ft_raw_data_checksum_check_3x((unsigned short *)g_i16_raw_data_1_short_buf) == ERROR)
  1402. goto ERROR_EXIT;
  1403. if (ft_raw_data_checksum_check_3x((unsigned short *)g_i16_raw_data_2_open_buf) == ERROR)
  1404. goto ERROR_EXIT;
  1405. if (ft_raw_data_checksum_check_3x((unsigned short *)g_u16_raw_data3_cc_buf) == ERROR)
  1406. goto ERROR_EXIT;
  1407. if (ft_raw_data_checksum_check_3x(g_u16_uc_buf) == ERROR)
  1408. goto ERROR_EXIT;
  1409. if (ft_test_result_checksum_check_3x(g_u8_test_result) == ERROR)
  1410. goto ERROR_EXIT;
  1411. if (ft_test_read_used_pin_infor_3x(g_u8_wearable_pin_map) == ERROR)
  1412. goto ERROR_EXIT;
  1413. #if ENABLE_TEST_RSU_DATA_SHOW
  1414. DEBUGOUT("Slow Data:\r\n");
  1415. dump_image_data_3x(g_i16_raw_data_1_short_buf, TRUE);
  1416. DEBUGOUT("Quick Data:\r\n");
  1417. dump_image_data_3x(g_i16_raw_data_2_open_buf, TRUE);
  1418. DEBUGOUT("P CC:\r\n");
  1419. dump_image_hex_data_3x((short *)g_u16_raw_data3_cc_buf);
  1420. DEBUGOUT("Open Golden CC:\r\n");
  1421. dump_image_hex_data_3x((short *)g_u16_raw_data3_golden_cc_buf);
  1422. DEBUGOUT("UC:\r\n");
  1423. dump_image_data_3x((short *)g_u16_uc_buf, TRUE);
  1424. DEBUGOUT("Golden UC:\r\n");
  1425. dump_image_data_3x((short *)g_u16_uc_golden_cc_buf, TRUE);
  1426. DEBUGOUT("test item result:0x%x\r\n", u32_test_item_result);
  1427. #endif
  1428. if (g_u8_print_debug_msg & PRINT_DEBUG_MSG_TYPE_4) {
  1429. DEBUGOUT("Slow Data:\r\n");
  1430. dump_image_data_3x(g_i16_raw_data_1_short_buf, TRUE);
  1431. DEBUGOUT("Quick Data:\r\n");
  1432. dump_image_data_3x(g_i16_raw_data_2_open_buf, TRUE);
  1433. DEBUGOUT("P CC:\r\n");
  1434. dump_image_data_3x((short *)g_u16_raw_data3_cc_buf, TRUE);
  1435. }
  1436. if (g_u8_print_debug_msg & PRINT_DEBUG_MSG_TYPE_5) {
  1437. DEBUGOUT("UC Data:\r\n");
  1438. dump_image_data_3x((short *)g_u16_uc_buf, TRUE);
  1439. }
  1440. #if ENABLE_TEST_TIME_MEASURMENT
  1441. DEBUGOUT("#read_test_data end=%d\r\n", get_system_time() - u32_fun_time);
  1442. #endif
  1443. g_u32_wearable_test_result |= u32_test_item_result;
  1444. DEBUGOUT("Read Test FW Result Finish\r\n");
  1445. return SUCCESS;
  1446. ERROR_EXIT:
  1447. if (u8_retry) {
  1448. u8_retry--;
  1449. DEBUGOUT("Read Test FW Result Retry:%d", u8_retry);
  1450. goto RETRY;
  1451. }
  1452. g_u32_wearable_test_result |= WEARABLE_FT_TEST_RESULT_GET_DATA_NG;
  1453. DEBUGOUT("Read Test FW Result NG\r\n");
  1454. return ERROR;
  1455. }
  1456. void test_item_message_3x(void)
  1457. {
  1458. unsigned short u16_test_item = g_st_test_info.u16_ft_test_item;
  1459. DEBUGOUT("================================\r\n");
  1460. DEBUGOUT("Enter 3x IC Test,(%d)\r\n", get_system_time());
  1461. DEBUGOUT("IC Test Items=0x%X\r\n", u16_test_item);
  1462. if (u16_test_item & IC_TEST_ITEMS_SYSTEM)
  1463. DEBUGOUT("Enable System Test\r\n");
  1464. if (u16_test_item & IC_TEST_ITEMS_OPEN)
  1465. DEBUGOUT("Enable Open Test\r\n");
  1466. if (u16_test_item & IC_TEST_ITEMS_SHORT)
  1467. DEBUGOUT("Enable Short Test\r\n");
  1468. if (u16_test_item & IC_TEST_ITEMS_UC)
  1469. DEBUGOUT("Enable Uniformity CC test\r\n");
  1470. if (u16_test_item & IC_TEST_ITEMS_UB)
  1471. DEBUGOUT("Enable Uniformity BL test\r\n");
  1472. if (u16_test_item & IC_TEST_ITEMS_BURN_FW)
  1473. DEBUGOUT("Enable Burn FW\r\n");
  1474. if (u16_test_item & IC_TEST_ITEMS_BURN_CC)
  1475. DEBUGOUT("Enable Burn CC\r\n");
  1476. }
  1477. STATUS burn_cc_3x(unsigned short u16_test_items)
  1478. {
  1479. unsigned char u8_retry = IC_TEST_RETRY_TIME;
  1480. #if ENABLE_AUO_VERIFY_LOG
  1481. unsigned int u32_flash_crc = 0;
  1482. #endif
  1483. #if ENABLE_TEST_TIME_MEASURMENT
  1484. unsigned int u32_fun_time = 0;
  1485. u32_fun_time = get_system_time();
  1486. #endif
  1487. g_u32_wearable_test_result &= ~(WEARABLE_FT_TEST_RESULT_BURN_CC_NG | WEARABLE_FT_TEST_RESULT_NORMAL_FW_NG
  1488. | WEARABLE_FT_TEST_RESULT_CC_CALIBRATION_NG);
  1489. if ((g_st_test_info.u16_ft_test_info_1) == WEARBLE_FT_BURN_CC_SYSTEM_NG_CASE) {
  1490. g_u32_wearable_test_result = WEARABLE_FT_TEST_RESULT_BURN_CC_NG;
  1491. return ERROR;
  1492. }
  1493. if ((g_st_test_info.u16_ft_test_item & (IC_TEST_ITEMS_BURN_CC)) == 0) {
  1494. g_u32_wearable_test_result &= ~WEARABLE_FT_TEST_RESULT_NORMAL_FW_RESET_NG;
  1495. return SUCCESS;
  1496. }
  1497. while (u8_retry--) {
  1498. if (enter_normal_fw_3x() == ERROR) {
  1499. if (u8_retry && !(g_u32_wearable_test_result & WEARABLE_FT_TEST_RESULT_PRAM_NG))
  1500. continue;
  1501. else {
  1502. g_u32_wearable_test_result |= WEARABLE_FT_TEST_RESULT_NORMAL_FW_NG;
  1503. DEBUGOUT("Enter Normal FW NG\r\n");
  1504. return ERROR;
  1505. }
  1506. }
  1507. /*Do CC*/
  1508. #if ENABLE_WDT
  1509. Chip_WWDT_Feed(LPC_WWDT);/* reload the Watchdog timer*/
  1510. #endif
  1511. DEBUGOUT("[BC] Burn CC Start!!\r\n");
  1512. if (g_u8_drv_interface == SPI_INTERFACE) {
  1513. /*flashless, bypass*/
  1514. DEBUGOUT("[BC]Flashless Burn CC ByPass!!\r\n");
  1515. return SUCCESS;
  1516. }
  1517. /*Burn CC to Flash*/
  1518. if (do_calibration_3x(TRUE, TRUE) == SUCCESS) {
  1519. DEBUGOUT("[BC] Burn CC Pass!!(%d)\r\n", u8_retry);
  1520. break;
  1521. }
  1522. if (u8_retry)
  1523. continue;
  1524. else {
  1525. DEBUGOUT("[BC] Burn CC NG!!\r\n");
  1526. return ERROR;
  1527. }
  1528. }
  1529. #if ENABLE_TEST_TIME_MEASURMENT
  1530. DEBUGOUT("[BC] Burn CC Time(%d)\r\n", get_system_time() - u32_fun_time);
  1531. #endif
  1532. return SUCCESS;
  1533. }
  1534. /*Use dongle ext.Flash to read test fw and write to pram*/
  1535. STATUS load_test_fw_3x(void)
  1536. {
  1537. STATUS u8_ret = ERROR;
  1538. #if ENABLE_TEST_TIME_MEASURMENT
  1539. unsigned int u32_fun_time = 0;
  1540. u32_fun_time = get_system_time();
  1541. DEBUGOUT("load_test_fw Start Time= %d\r\n", u32_fun_time);
  1542. #endif
  1543. g_u32_wearable_test_result &= ~(WEARABLE_FT_TEST_RESULT_LOAD_TESTFW_NG);
  1544. if (g_st_test_info.u16_ft_test_info_1 == WEARBLE_FT_LOAD_TEST_FW_SYSTEM_NG_CASE) {
  1545. g_u32_wearable_test_result = WEARABLE_FT_TEST_RESULT_LOAD_TESTFW_NG;
  1546. return ERROR;
  1547. }
  1548. if ((g_st_test_info.u16_ft_test_item & (IC_TEST_ITEMS_OPEN | IC_TEST_ITEMS_SHORT | IC_TEST_ITEMS_UC |
  1549. IC_TEST_ITEMS_UB)) == 0)
  1550. return SUCCESS;
  1551. DEBUGOUT("[LTFW] start load test fw\r\n");
  1552. #if SELFTEST_3X
  1553. u8_ret = raydium_upgrade_test_fw_3x(0);
  1554. #else
  1555. u8_ret = load_test_fw_ft_3x();
  1556. #endif
  1557. DEBUGOUT("[LTFW] Load test fw finish!!\r\n");
  1558. #if ENABLE_TEST_TIME_MEASURMENT
  1559. DEBUGOUT("load_test_fw Spend Time= %d\r\n", get_system_time() - u32_fun_time);
  1560. #endif
  1561. return u8_ret;
  1562. }
  1563. STATUS system_test_3x(void)
  1564. {
  1565. STATUS u8_test_result = SUCCESS;
  1566. unsigned short u16_panel_mode;
  1567. #if ENABLE_TEST_TIME_MEASURMENT
  1568. unsigned int u32_fun_time;
  1569. #endif
  1570. /*Clear Test Item Test result*/
  1571. g_u32_wearable_test_result &= ~(WEARABLE_FT_TEST_RESULT_I2C_NG | WEARABLE_FT_TEST_RESULT_INT_NG
  1572. | WEARABLE_FT_TEST_RESULT_RESET_NG | WEARABLE_FT_TEST_RESULT_PRAM_NG
  1573. | WEARABLE_FT_TEST_RESULT_IC_SUB_VERSION_NG | WEARABLE_FT_TEST_RESULT_IC_FW_VERIFY_NG);
  1574. if ((g_st_test_info.u16_ft_test_item & IC_TEST_ITEMS_SYSTEM) == FALSE)
  1575. return SUCCESS;
  1576. if (enable_ic_block_3x() == ERROR) {
  1577. DEBUGOUT("enable_ic_block NG!!!\r\n");
  1578. /*return ERROR;*/
  1579. }
  1580. stop_mcu_3x(1);
  1581. /*
  1582. * Check Dongle Ext Flash FW/Test FW version PK INI
  1583. *
  1584. * if (check_ext_flash_fw_version() == ERROR) {
  1585. * u8_test_result = ERROR;
  1586. * g_u32_wearable_test_result = WEARABLE_FT_TEST_RESULT_IC_FW_VERIFY_NG;
  1587. * goto ERROR_EXIT;
  1588. * }
  1589. */
  1590. #if ENABLE_TEST_TIME_MEASURMENT
  1591. u32_fun_time = get_system_time();
  1592. #endif
  1593. /*I2C or SPI Test*/
  1594. if (ft_test_connect_test_3x() == ERROR) {
  1595. u8_test_result = ERROR;
  1596. goto ERROR_EXIT;
  1597. }
  1598. #if ENABLE_TEST_TIME_MEASURMENT
  1599. DEBUGOUT("Interface test Spend Time= %d\r\n", get_system_time() - u32_fun_time);
  1600. #endif
  1601. if ((g_st_test_info.u16_ft_eng_item & IC_TEST_ENG_ITEMS_RESV_12)) {
  1602. DEBUGOUT("INI Model = 0x%08X\r\n", g_st_test_para_resv.u32_normal_fw_version);
  1603. u16_panel_mode = (g_st_test_para_resv.u32_normal_fw_version & 0x0000FFFF);
  1604. if (ft_test_panel_model_check_3x(u16_panel_mode) == ERROR) {
  1605. u8_test_result = ERROR;
  1606. g_u32_wearable_test_result = WEARABLE_FT_TEST_RESULT_IC_FW_VERIFY_NG;
  1607. goto ERROR_EXIT;
  1608. }
  1609. }
  1610. #if ENABLE_TEST_TIME_MEASURMENT
  1611. u32_fun_time = get_system_time();
  1612. #endif
  1613. /*INT Pin Test*/
  1614. if (hw_int_pin_Test_3x() == ERROR) {
  1615. u8_test_result = ERROR;
  1616. goto ERROR_EXIT;
  1617. }
  1618. #if ENABLE_TEST_TIME_MEASURMENT
  1619. DEBUGOUT("INT Spend Time= %d\r\n", get_system_time() - u32_fun_time);
  1620. #endif
  1621. #if ENABLE_TEST_TIME_MEASURMENT
  1622. u32_fun_time = get_system_time();
  1623. #endif
  1624. /*
  1625. * RAM Test
  1626. * if (ft_test_ram_test_3x(0) == ERROR) {
  1627. * u8_test_result = ERROR;
  1628. * goto ERROR_EXIT;
  1629. * }
  1630. */
  1631. #if ENABLE_TEST_TIME_MEASURMENT
  1632. DEBUGOUT("RAM Spend Time= %d\r\n", get_system_time() - u32_fun_time);
  1633. #endif
  1634. if ((g_st_test_info.u16_ft_eng_item & IC_TEST_ENG_ITEMS_RESV_11)) {
  1635. if (check_dev_sub_version_3x(g_st_test_para_resv.u8_para_resv_0[21]) == ERROR) {
  1636. u8_test_result = ERROR;
  1637. g_u32_wearable_test_result = WEARABLE_FT_TEST_RESULT_IC_SUB_VERSION_NG;
  1638. goto ERROR_EXIT;
  1639. }
  1640. }
  1641. #if ENABLE_TEST_TIME_MEASURMENT
  1642. u32_fun_time = get_system_time();
  1643. #endif
  1644. /*Reset Pin Test*/
  1645. if (ft_test_reset_pin_test_3x() == ERROR) {
  1646. u8_test_result = ERROR;
  1647. goto ERROR_EXIT;
  1648. }
  1649. #if ENABLE_TEST_TIME_MEASURMENT
  1650. DEBUGOUT("Reset Spend Time= %d\r\n", get_system_time() - u32_fun_time);
  1651. #endif
  1652. ERROR_EXIT:
  1653. if (u8_test_result == ERROR)
  1654. DEBUGOUT("System Test NG!!\r\n");
  1655. else
  1656. DEBUGOUT("System Test PASS\r\n");
  1657. return u8_test_result;
  1658. }
  1659. void do_ic_test_3x(void)
  1660. {
  1661. unsigned short u16_test_items;
  1662. #if ENABLE_TEST_TIME_MEASURMENT
  1663. unsigned char u8_ic_test_state;
  1664. #endif
  1665. #if ENABLE_TEST_TIME_MEASURMENT
  1666. unsigned int u32_fun_time = 0;
  1667. #endif
  1668. unsigned int u32_read_data = 0;
  1669. #if ENABLE_CONTROL_OPENSHORT_WDT
  1670. Chip_WWDT_SetTimeOut(LPC_WWDT, (WDT_OSC / 10) * 150);
  1671. #endif
  1672. g_u32_wearable_test_result &= ~(WEARABLE_FT_TEST_RESULT_POWER_ON_NG | WEARABLE_FT_TEST_RESULT_IC_VERSION_NG
  1673. | WEARABLE_FT_TEST_RESULT_MCU_HOLD_NG | WEARABLE_FT_TEST_RESULT_EXT_FLASH_EMPTY_NG
  1674. | WEARABLE_FT_TEST_RESULT_FLASH_ID_NG | WEARABLE_FT_TEST_RESULT_NORMAL_FW_VER_NG
  1675. | WEARABLE_FT_TEST_RESULT_PANEL_TEST_3_NG | WEARABLE_FT_TEST_RESULT_CB_NG | WEARABLE_FT_TEST_RESULT_TEST_FW_VER_NG
  1676. | WEARABLE_FT_TEST_RESULT_AUO_JIG_NG);
  1677. if (!wearable_ic_test_init()) {
  1678. g_u32_wearable_test_result |= WEARABLE_FT_TEST_RESULT_TEST_INIT_NG;
  1679. g_u8_ic_test_state = IC_TEST_EXIT;
  1680. return;
  1681. }
  1682. test_item_message_3x();
  1683. #if !SELFTEST_3X
  1684. if ((g_st_test_info.u16_ft_eng_item & IC_TEST_ENG_ITEMS_RESV_16)) {
  1685. DEBUGOUT("TEST STATUS= %d\r\n", g_u8_panel_jig_test_status);
  1686. DEBUGOUT("[burn_header_log_to_flash]\r\n");
  1687. if (!b_is_auo_jig_testing) {
  1688. b_is_auo_jig_testing = true;
  1689. g_u8_test_log_burn_times = 0;
  1690. if (!burn_header_log_to_flash_3x(FALSE, FALSE))
  1691. DEBUGOUT("[burn_header_log_to_flash_3x ERROR!]\r\n");
  1692. if (g_u8_test_log_burn_times > 5) {
  1693. if (!burn_header_log_to_flash_3x(FALSE, TRUE))
  1694. DEBUGOUT("[burn_header_log_to_flash_3x ERROR!]\r\n");
  1695. }
  1696. }
  1697. }
  1698. #endif
  1699. if (g_st_test_info.u16_ft_test_item == 0)
  1700. return;
  1701. /*
  1702. * if (g_st_test_info.u8_device_id != 2) {
  1703. * g_u32_wearable_test_result = WEARABLE_FT_TEST_RESULT_IC_VERSION_NG;
  1704. * return;
  1705. * }
  1706. */
  1707. /*handle_display_write(g_u8_display_pattern_sleep_to_active, sizeof(g_u8_display_pattern_sleep_to_active));*/
  1708. handle_ic_read(0x50001100, 4, (unsigned char *)(&u32_read_data), g_u8_drv_interface, I2C_WORD_MODE);
  1709. DEBUGOUT("display mode 0x%x\r\n", u32_read_data);
  1710. g_u8_ic_test_state = IC_TEST_INIT;
  1711. u16_test_items = g_st_test_info.u16_ft_test_item;
  1712. g_u32_wearable_test_result &= ~(WEARABLE_FT_TEST_RESULT_POWER_ON_NG | WEARABLE_FT_TEST_RESULT_IC_VERSION_NG
  1713. | WEARABLE_FT_TEST_RESULT_MCU_HOLD_NG | WEARABLE_FT_TEST_RESULT_EXT_FLASH_EMPTY_NG
  1714. | WEARABLE_FT_TEST_RESULT_FLASH_ID_NG | WEARABLE_FT_TEST_RESULT_NORMAL_FW_VER_NG
  1715. | WEARABLE_FT_TEST_RESULT_PANEL_TEST_3_NG | WEARABLE_FT_TEST_RESULT_CB_NG | WEARABLE_FT_TEST_RESULT_TEST_FW_VER_NG
  1716. | WEARABLE_FT_TEST_RESULT_AUO_JIG_NG);
  1717. while (u16_test_items) {
  1718. #if ENABLE_TEST_TIME_MEASURMENT
  1719. u8_ic_test_state = g_u8_ic_test_state;
  1720. g_u32_spend_time = get_system_time();
  1721. #endif
  1722. switch (g_u8_ic_test_state) {
  1723. case IC_TEST_INIT:
  1724. #if ENABLE_TEST_TIME_MEASURMENT
  1725. u32_fun_time = get_system_time();
  1726. #endif
  1727. g_u8_ic_test_state = IC_TEST_SYSTEM;
  1728. #if ENABLE_TEST_TIME_MEASURMENT
  1729. DEBUGOUT("IC_TEST_INIT Spend Time= %d\r\n", get_system_time() - u32_fun_time);
  1730. #endif
  1731. break;
  1732. case IC_TEST_SYSTEM:
  1733. if (system_test_3x() == SUCCESS ||
  1734. (g_st_test_info.u16_ft_eng_item & IC_TEST_ENG_ITEMS_TEST_ALL)) {
  1735. g_u8_ic_test_state = IC_TEST_BURN_FW;
  1736. } else {
  1737. g_u8_ic_test_state = IC_TEST_EXIT;
  1738. }
  1739. break;
  1740. case IC_TEST_BURN_FW:
  1741. if (burn_fw_3x() == ERROR) {
  1742. g_u32_wearable_test_result = WEARABLE_FT_TEST_RESULT_BURN_FW_NG;
  1743. g_u8_ic_test_state = IC_TEST_EXIT;
  1744. } else {
  1745. g_u8_ic_test_state = IC_TEST_LOAD_TEST_FW;
  1746. }
  1747. break;
  1748. case IC_TEST_LOAD_TEST_FW:
  1749. if (load_test_fw_3x() == ERROR) {
  1750. DEBUGOUT("Load Test FW NG!!\r\n");
  1751. g_u32_wearable_test_result = WEARABLE_FT_TEST_RESULT_LOAD_TESTFW_NG;
  1752. g_u8_ic_test_state = IC_TEST_EXIT;
  1753. } else {
  1754. g_u8_ic_test_state = IC_TEST_ENTER_FW_TEST_MODE;
  1755. }
  1756. break;
  1757. case IC_TEST_ENTER_FW_TEST_MODE:
  1758. if (enter_fw_test_mode_3x() == ERROR) {
  1759. DEBUGOUT("Enter FW Test Mode NG!!\r\n");
  1760. g_u8_ic_test_state = IC_TEST_EXIT;
  1761. } else {
  1762. g_u8_ic_test_state = IC_TEST_OPEN_SHORT;
  1763. }
  1764. break;
  1765. case IC_TEST_OPEN_SHORT:
  1766. if (ft_test_do_fw_test_3x(u16_test_items) == SUCCESS) {
  1767. DEBUGOUT("FW Test Finish! \r\n");
  1768. g_u8_ic_test_state = IC_TEST_READ_TEST_FW_DATA;
  1769. } else {
  1770. DEBUGOUT("FW Test NG!!\r\n");
  1771. g_u32_wearable_test_result = WEARABLE_FT_TEST_RESULT_TEST_INIT_NG;
  1772. g_u8_ic_test_state = IC_TEST_EXIT;
  1773. }
  1774. break;
  1775. case IC_TEST_READ_TEST_FW_DATA:
  1776. if (read_test_fw_data_3x(u16_test_items) == SUCCESS) {
  1777. g_u8_ic_test_state = IC_TEST_BURN_CC;
  1778. } else {
  1779. DEBUGOUT("Read Test FW Data NG!!\r\n");
  1780. g_u8_ic_test_state = IC_TEST_EXIT;
  1781. }
  1782. break;
  1783. case IC_TEST_BURN_CC:
  1784. if (burn_cc_3x(u16_test_items) == ERROR) {
  1785. DEBUGOUT("Burn CC NG!!\r\n");
  1786. g_u32_wearable_test_result |= WEARABLE_FT_TEST_RESULT_BURN_CC_NG;
  1787. g_u8_ic_test_state = IC_TEST_PANEL_PATTERN_TEST;
  1788. } else {
  1789. g_u8_ic_test_state = IC_TEST_PANEL_PATTERN_TEST;
  1790. }
  1791. break;
  1792. case IC_TEST_PANEL_PATTERN_TEST:
  1793. #if ENABLE_TEST_GPIO_MEASURMENT
  1794. Chip_GPIO_SetPinOutHigh(LPC_GPIO, DONGLE_GPIO_PORT_1, DONGLE_GPIO_PIN_10);
  1795. delay_ms(1);
  1796. Chip_GPIO_SetPinOutLow(LPC_GPIO, DONGLE_GPIO_PORT_1, DONGLE_GPIO_PIN_10);
  1797. #endif
  1798. DEBUGOUT("B g_u32_wearable_test_result = 0x%08x\r\n", g_u32_wearable_test_result);
  1799. #if !SELFTEST_3X
  1800. do_ic_panel_test_3x();
  1801. #endif
  1802. g_u8_ic_test_state = IC_TEST_EXIT;
  1803. break;
  1804. case IC_TEST_EXIT:
  1805. #if ENABLE_TEST_TIME_MEASURMENT
  1806. u32_fun_time = get_system_time();
  1807. DEBUGOUT("Final action Start Time= %d\r\n", u32_fun_time);
  1808. #endif
  1809. DEBUGOUT("g_u32_wearable_test_result = 0x%08x\r\n", g_u32_wearable_test_result);
  1810. DEBUGOUT("Exit IC Test!\r\n");
  1811. #if !SELFTEST_3X
  1812. gpio_touch_int_trigger_control(FALSE);
  1813. #endif
  1814. g_u8_ic_test_state = IC_TEST_INIT;
  1815. if ((g_st_test_info.u16_ft_test_item & (IC_TEST_ITEMS_OPEN | IC_TEST_ITEMS_SHORT)) == 0) {
  1816. ft_raw_data_checksum_cal_3x((unsigned short *)g_i16_raw_data_1_short_buf);
  1817. ft_raw_data_checksum_cal_3x((unsigned short *)g_i16_raw_data_2_open_buf);
  1818. ft_raw_data_checksum_cal_3x(g_u16_raw_data3_cc_buf);
  1819. }
  1820. ft_raw_data_checksum_cal_3x(g_u16_uc_buf);
  1821. ft_raw_data_checksum_cal_3x((unsigned short *)g_u16_raw_data3_golden_cc_buf);
  1822. ft_raw_data_checksum_cal_3x((unsigned short *)g_u16_uc_golden_cc_buf);
  1823. ft_test_result_checksum_cal_3x(g_u8_test_result);
  1824. #if !SELFTEST_3X
  1825. DEBUGOUT("g_u8_panel_jig_test_status= %d\r\n", g_u8_panel_jig_test_status);
  1826. if (g_u8_panel_jig_test_status == STATUS_DATA_PANEL_JIG_FINISH && (g_st_test_info.u16_ft_eng_item & IC_TEST_ENG_ITEMS_ENABLE_BURN_TEST_LOG)) {
  1827. b_is_auo_jig_testing = false;
  1828. burn_header_log_to_flash_3x(TRUE, TRUE);
  1829. memset(g_u32_save_config, 0, sizeof(g_u32_save_config));
  1830. if (!burn_data_log_to_flash_3x())
  1831. DEBUGOUT("[burn_log_to_flash ERROR!]\r\n");
  1832. }
  1833. #endif
  1834. /*
  1835. * if (g_u8_panel_jig_test_status == STATUS_DATA_PANEL_JIG_FINISH && (g_st_test_info.u16_ft_eng_item & IC_TEST_ENG_ITEMS_ENABLE_BURN_TEST_LOG)) {
  1836. * if (!burn_log_to_flash_3x())
  1837. * DEBUGOUT("[burn_log_to_flash ERROR!]\r\n");
  1838. * }
  1839. */
  1840. #if ENABLE_CONTROL_OPENSHORT_WDT
  1841. /*Chip_WWDT_SetTimeOut(LPC_WWDT, (WDT_OSC / 10) * 50);*/
  1842. #endif
  1843. u16_test_items = 0;
  1844. #if ENABLE_TEST_TIME_MEASURMENT
  1845. DEBUGOUT("Final action Spend Time= %d\r\n", get_system_time() - u32_fun_time);
  1846. #endif
  1847. break;
  1848. }
  1849. #if !SELFTEST_3X
  1850. update_dongle_test_status(g_u8_ic_test_state);
  1851. #endif
  1852. #if ENABLE_WDT
  1853. /* reload the Watchdog timer*/
  1854. Chip_WWDT_Feed(LPC_WWDT);
  1855. #endif
  1856. #if !SELFTEST_3X
  1857. if (g_u8_ic_power_on_ng) {
  1858. g_u32_wearable_test_result |= WEARABLE_FT_TEST_RESULT_POWER_ON_NG;
  1859. g_u8_ic_test_state = IC_TEST_EXIT;
  1860. }
  1861. #endif
  1862. #if ENABLE_TEST_TIME_MEASURMENT
  1863. DEBUGOUT("Test Item [%d] End (%d)\r\n", u8_ic_test_state, get_system_time() - g_u32_spend_time);
  1864. #endif
  1865. } /*while(u16_test_items)*/
  1866. }