f303_ic_test.c 73 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319
  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. STATUS turn_on_flash_3x(void)
  399. {
  400. unsigned int u32_read = 0;
  401. /*Turn on Flash*/
  402. if (handle_ic_write(REG_I2C_I2CFLASHPRO, 4, (unsigned char *)&u32_read, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  403. return ERROR;
  404. u32_read = FLH_RELEASE_PD;
  405. if (handle_ic_write(REG_FLASHCTL_FLASH_ISPCTL, 4, (unsigned char *)&u32_read, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  406. return ERROR;
  407. return SUCCESS;
  408. }
  409. STATUS read_fpc_flash_3x(unsigned int u32_addr, unsigned int *p_u32_data)
  410. {
  411. unsigned int u32_read;
  412. /*Turn on Flash*/
  413. if (turn_on_flash_3x() == ERROR)
  414. return ERROR;
  415. if (handle_ic_read(REG_SYSCON_BLKEN_ADDR, 4, (unsigned char *)(&u32_read), g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  416. return ERROR;
  417. u32_read |= 0x40;
  418. if (handle_ic_write(REG_SYSCON_BLKEN_ADDR, 4, (unsigned char *)&u32_read, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  419. return ERROR;
  420. u32_read = 0x00000000;
  421. if (handle_ic_write(REG_I2C_I2CFLASHPRO, 4, (unsigned char *)&u32_read, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  422. return ERROR;
  423. if (handle_ic_write(REG_FLASHCTL_FLASH_ADDR, 4, (unsigned char *)&u32_addr, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  424. return ERROR;
  425. u32_read = 0x40;
  426. if (handle_ic_write(REG_FLASHCTL_FLASH_ISPCTL, 4, (unsigned char *)&u32_read, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  427. return ERROR;
  428. delay_ms(1);
  429. if (handle_ic_read(REG_FLASHCTL_FLASH_DATA, 4, (unsigned char *)(&u32_read), g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  430. return ERROR;
  431. *p_u32_data = u32_read;
  432. return SUCCESS;
  433. }
  434. STATUS set_test_info_thd_para_3x(void)
  435. {
  436. unsigned char u8_read_buf[96], u8_i;
  437. unsigned char *p_u8_input_buf;
  438. 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)
  439. return ERROR;
  440. 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)
  441. return ERROR;
  442. p_u8_input_buf = (unsigned char *)&g_st_test_info;
  443. for (u8_i = 0; u8_i < sizeof(g_st_test_info); u8_i++) {
  444. if (p_u8_input_buf[u8_i] != u8_read_buf[u8_i]) {
  445. DEBUGOUT("Set INFO NG:[%d]=%d->%d\r\n", u8_i, p_u8_input_buf[u8_i], u8_read_buf[u8_i]);
  446. return ERROR;
  447. }
  448. }
  449. 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)
  450. return ERROR;
  451. 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)
  452. return ERROR;
  453. p_u8_input_buf = (unsigned char *)&g_st_test_thd;
  454. for (u8_i = 0; u8_i < sizeof(g_st_test_thd); u8_i++) {
  455. if (p_u8_input_buf[u8_i] != u8_read_buf[u8_i]) {
  456. DEBUGOUT("Set THD NG:[%d]=%d->%d\r\n", u8_i, p_u8_input_buf[u8_i], u8_read_buf[u8_i]);
  457. return ERROR;
  458. }
  459. }
  460. 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)
  461. return ERROR;
  462. 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)
  463. return ERROR;
  464. p_u8_input_buf = (unsigned char *)&g_st_test_para_resv;
  465. for (u8_i = 0; u8_i < sizeof(g_st_test_para_resv); u8_i++) {
  466. if (p_u8_input_buf[u8_i] != u8_read_buf[u8_i]) {
  467. DEBUGOUT("Set Para NG:[%d]=%d->%d\r\n", u8_i, p_u8_input_buf[u8_i], u8_read_buf[u8_i]);
  468. return ERROR;
  469. }
  470. }
  471. 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)
  472. return ERROR;
  473. if (handle_ic_read(SRAM_FT_UC_CC_ADDR, 96, (unsigned char *)u8_read_buf, g_u8_drv_interface, I2C_BYTE_MODE) == ERROR)
  474. return ERROR;
  475. p_u8_input_buf = (unsigned char *)g_u16_uc_golden_cc_buf;
  476. for (u8_i = 0; u8_i < 96; u8_i++) {
  477. if (p_u8_input_buf[u8_i] != u8_read_buf[u8_i]) {
  478. 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]);
  479. return ERROR;
  480. }
  481. }
  482. /*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]);
  483. * 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]);
  484. */
  485. 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)
  486. return ERROR;
  487. if (handle_ic_read(SRAM_FT_RAWDATA_3_CC_ADDR, 96, (unsigned char *)u8_read_buf, g_u8_drv_interface, I2C_BYTE_MODE) == ERROR)
  488. return ERROR;
  489. p_u8_input_buf = (unsigned char *)g_u16_raw_data3_golden_cc_buf;
  490. for (u8_i = 0; u8_i < 96; u8_i++) {
  491. if (p_u8_input_buf[u8_i] != u8_read_buf[u8_i]) {
  492. 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]);
  493. return ERROR;
  494. }
  495. }
  496. return SUCCESS;
  497. }
  498. void dump_image_data_3x(short *p_image_buf, unsigned char u8_remap)
  499. {
  500. short *p_i16_buf = (short *)g_u16_raw_data_tmp;
  501. unsigned char u8_i, u8_j;
  502. memset(p_i16_buf, 0, MAX_IMAGE_BUFFER_SIZE * 2);
  503. if (u8_remap) {
  504. for (u8_i = 0; u8_i < MAX_IMAGE_BUFFER_SIZE; u8_i++) {
  505. if (g_u8_wearable_pin_map[u8_i] != F303_NA_P)
  506. p_i16_buf[g_u8_wearable_pin_map[u8_i]] = p_image_buf[u8_i];
  507. }
  508. } else
  509. memcpy(p_i16_buf, p_image_buf, MAX_IMAGE_BUFFER_SIZE << 1);
  510. for (u8_j = 0; u8_j < g_u8_channel_y; u8_j++) {
  511. for (u8_i = 0; u8_i < g_u8_channel_x; u8_i++)
  512. DEBUGOUT("%4d, ", p_i16_buf[u8_i + u8_j * g_u8_channel_x]);
  513. DEBUGOUT("\r\n");
  514. }
  515. }
  516. void dump_image_hex_data_3x(short *p_image_buf)
  517. {
  518. short *p_i16_buf = (short *)g_u16_raw_data_tmp;
  519. unsigned char u8_i, u8_j;
  520. memset(p_i16_buf, 0, MAX_IMAGE_BUFFER_SIZE * 2);
  521. for (u8_i = 0; u8_i < MAX_IMAGE_BUFFER_SIZE; u8_i++) {
  522. if (g_u8_wearable_pin_map[u8_i] != F303_NA_P)
  523. p_i16_buf[g_u8_wearable_pin_map[u8_i]] = p_image_buf[u8_i];
  524. }
  525. for (u8_j = 0; u8_j < g_u8_channel_y; u8_j++) {
  526. for (u8_i = 0; u8_i < g_u8_channel_x; u8_i++)
  527. DEBUGOUT("%4X, ", (p_i16_buf[u8_i + u8_j * g_u8_channel_x] & 0x7ff));
  528. DEBUGOUT("\r\n");
  529. }
  530. }
  531. STATUS check_test_fw_status_3x(unsigned char u8_target_status, unsigned char *p_u8_result)
  532. {
  533. unsigned int u32_read;
  534. if (handle_ic_read(FW_FT_ARG1_ADDR, 4, (unsigned char *)(&u32_read), g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  535. return ERROR;
  536. if ((u32_read & FT_TEST_STUATUS_PATTERN) == FT_TEST_STUATUS_PATTERN) {
  537. if (((unsigned char)(u32_read & 0x00FF)) == u8_target_status)
  538. *p_u8_result = 1;
  539. else {
  540. DEBUGOUT("[CTFS] Test STATUS NG!! (%x:%x)\r\n", u8_target_status, u32_read);
  541. *p_u8_result = 0;
  542. return ERROR;
  543. }
  544. DEBUGOUT("[CTFS] Test FW STATUS (%x:%x)\r\n", u8_target_status, u32_read);
  545. } else {
  546. DEBUGOUT("[CTFS] Test STATUS Not Ready!! (%x:%x)\r\n", u8_target_status, u32_read);
  547. *p_u8_result = 0;
  548. }
  549. return SUCCESS;
  550. }
  551. STATUS ft_test_do_fw_test_3x(unsigned short u16_test_items)
  552. {
  553. unsigned char u8_write_data[5], u8_result;
  554. unsigned int u32_read_data;
  555. short i16_time_out = 0;
  556. #if ENABLE_TEST_TIME_MEASURMENT
  557. unsigned int u32_fun_time = 0;
  558. u32_fun_time = get_system_time();
  559. DEBUGOUT("ft_test_do_fw_test Start Time= %d\r\n", u32_fun_time);
  560. #endif
  561. g_u32_wearable_test_result &= ~WEARABLE_FT_TEST_RESULT_TEST_INIT_NG;
  562. if ((u16_test_items & (IC_TEST_ITEMS_OPEN | IC_TEST_ITEMS_SHORT | IC_TEST_ITEMS_UC | IC_TEST_ITEMS_UB)) == 0)
  563. return SUCCESS;
  564. memset(u8_write_data, 0, sizeof(u8_write_data));
  565. u8_write_data[1] = FT_CMD_DO_FT_TEST | 0x80;
  566. u8_write_data[2] = (unsigned char) u16_test_items;
  567. u8_write_data[3] = (unsigned char)(u16_test_items >> 8);
  568. DEBUGOUT("Star FW Test!!\r\n");
  569. if (handle_ic_write(FW_SYS_CMD_ADDR, 4, u8_write_data, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  570. return ERROR;
  571. /*Wait test fw finish INT */
  572. /*Wait 20 Sec*/
  573. i16_time_out = 1000;
  574. while (i16_time_out--) {
  575. delay_ms(20);
  576. #if ENABLE_WDT
  577. Chip_WWDT_Feed(LPC_WWDT);/* reload the Watchdog timer*/
  578. #endif
  579. if (!gpio_touch_int_pin_state_access() || (i16_time_out < 10)) {
  580. if (check_test_fw_status_3x(FT_CMD_DO_FT_TEST, &u8_result) == ERROR) {
  581. DEBUGOUT("[FWT] Wait Test CMD NG (0x%x:%d)\r\n", FT_CMD_DO_FT_TEST, i16_time_out);
  582. return ERROR;
  583. } else if (u8_result == TRUE) {
  584. break;
  585. }
  586. }
  587. }
  588. if (handle_ic_read(FW_SYS_CMD_ADDR, 4, (unsigned char *)(&u32_read_data), g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  589. return ERROR;
  590. DEBUGOUT("[FWT]SysCMD1:0x%x (%d)\r\n", u32_read_data, i16_time_out);
  591. if (i16_time_out == IC_TEST_TIME_OUT) {
  592. DEBUGOUT("[FWT] Wait Test CMD Timeout!! (0x%x)\r\n", FT_CMD_DO_FT_TEST);
  593. return ERROR;
  594. }
  595. #if ENABLE_TEST_TIME_MEASURMENT
  596. DEBUGOUT("[FWT] FW Test Time(%d)\r\n", get_system_time() - u32_fun_time);
  597. #endif
  598. return SUCCESS;
  599. }
  600. STATUS enter_fw_test_mode_3x(void)
  601. {
  602. unsigned char u8_result = 0;
  603. short i16_time_out = 0;
  604. #if ENABLE_TEST_TIME_MEASURMENT
  605. unsigned int u32_fun_time = 0;
  606. u32_fun_time = get_system_time();
  607. #endif
  608. g_u32_wearable_test_result &= ~WEARABLE_FT_TEST_RESULT_TEST_INIT_NG;
  609. DEBUGOUT("[EFTM] Start\r\n");
  610. if ((g_st_test_info.u16_ft_test_item & (IC_TEST_ITEMS_OPEN | IC_TEST_ITEMS_SHORT |
  611. IC_TEST_ITEMS_UC | IC_TEST_ITEMS_UB)) == 0) {
  612. return SUCCESS;
  613. }
  614. g_u8_is_normal_fw = FALSE;
  615. i16_time_out = 300;
  616. u8_result = 0;
  617. while (i16_time_out--) {
  618. if (!gpio_touch_int_pin_state_access() || (i16_time_out < 20)) {
  619. if (check_test_fw_status_3x(FT_CMD_INIT, &u8_result) == ERROR)
  620. goto IC_INIT_NG;
  621. else if (u8_result == TRUE)
  622. break;
  623. }
  624. delay_ms(5);
  625. }
  626. if (i16_time_out == IC_TEST_TIME_OUT) {
  627. DEBUGOUT("[EFTM] FW State Check NG\r\n");
  628. goto IC_INIT_NG;
  629. }
  630. DEBUGOUT("[EFTM] Enter FT mode\r\n");
  631. if (set_test_info_thd_para_3x() == ERROR) {
  632. DEBUGOUT("[RUPI] Set test info, thd, para NG!\r\n");
  633. return ERROR;
  634. }
  635. #if ENABLE_TEST_TIME_MEASURMENT
  636. DEBUGOUT("[EFTM] (%d)\r\n", get_system_time() - u32_fun_time);
  637. #endif
  638. return SUCCESS;
  639. IC_INIT_NG:
  640. g_u32_wearable_test_result = WEARABLE_FT_TEST_RESULT_TEST_INIT_NG;
  641. return ERROR;
  642. }
  643. STATUS ft_test_read_used_pin_infor_3x(unsigned char *p_u8_infor)
  644. {
  645. /*unsigned char u8_i;*/
  646. unsigned char u8_r_buf[2];
  647. /*get Pin remap*/
  648. if (handle_ic_read(FW_FT_PIN_ADDR, 48, p_u8_infor, g_u8_drv_interface, I2C_BYTE_MODE) == ERROR) {
  649. DEBUGOUT("[RUPI] NG!\r\n");
  650. return ERROR;
  651. }
  652. /*
  653. * for (u8_i = 0; u8_i < 36; u8_i++) {
  654. * DEBUGOUT("Pin[%d] remap=%d\r\n", u8_i, p_u8_infor[u8_i]);
  655. * }
  656. */
  657. if (handle_ic_read(FW_FT_CHANNEL_X_ADDR, 2, u8_r_buf, g_u8_drv_interface, I2C_BYTE_MODE) == ERROR) {
  658. DEBUGOUT("[RUPI] NG!\r\n");
  659. return ERROR;
  660. }
  661. g_u8_channel_x = u8_r_buf[0];
  662. g_u8_channel_y = u8_r_buf[1];
  663. DEBUGOUT("[RUPI] X:%d,Y:%d\r\n", g_u8_channel_x, g_u8_channel_y);
  664. return SUCCESS;
  665. }
  666. STATUS ft_test_ctrl_mbist_fun_3x(unsigned char u8_enable)
  667. {
  668. unsigned int u32_read;
  669. if (u8_enable) {
  670. if (handle_ic_read(REG_SYSCON_BLKEN_ADDR, 4, (unsigned char *)(&u32_read), g_u8_drv_interface, I2C_WORD_MODE) == ERROR) {
  671. DEBUGOUT("Data RAM Test NG !!!\r\n");
  672. return ERROR;
  673. }
  674. u32_read |= (1 << 29);
  675. if (handle_ic_write(REG_SYSCON_BLKEN_ADDR, 4, (unsigned char *)&u32_read, g_u8_drv_interface, I2C_WORD_MODE) == ERROR) {
  676. DEBUGOUT("Data RAM Test NG !!!\r\n");
  677. return ERROR;
  678. }
  679. } else {
  680. if (handle_ic_read(REG_SYSCON_BLKEN_ADDR, 4, (unsigned char *)(&u32_read), g_u8_drv_interface, I2C_WORD_MODE) == ERROR) {
  681. DEBUGOUT("Data RAM Test NG !!!\r\n");
  682. return ERROR;
  683. }
  684. u32_read &= ~(1 << 29);
  685. if (handle_ic_write(REG_SYSCON_BLKEN_ADDR, 4, (unsigned char *)&u32_read, g_u8_drv_interface, I2C_WORD_MODE) == ERROR) {
  686. DEBUGOUT("Data RAM Test NG !!!\r\n");
  687. return ERROR;
  688. }
  689. }
  690. return SUCCESS;
  691. }
  692. /*
  693. * STATUS ft_test_ram_test_3x(unsigned char u8_is_stop_mcu)
  694. * {
  695. * unsigned int u32_read;
  696. * unsigned char u8_retry_times = 2;
  697. * unsigned int u32_write = 0;
  698. * if ((g_st_test_info.u16_ft_test_info_1) == WEARBLE_FT_PRAM_SYSTEM_NG_CASE) {
  699. * g_u32_wearable_test_result = WEARABLE_FT_TEST_RESULT_PRAM_NG;
  700. * return ERROR;
  701. * }
  702. *
  703. * RETRY_RAM_TEST:
  704. *
  705. * if (u8_is_stop_mcu) {
  706. * stop_mcu_3x(TRUE);
  707. * }
  708. *
  709. * if (ft_test_ctrl_mbist_fun_3x(ENABLE) == ERROR) {
  710. * goto EXIT_ERROR;
  711. * }
  712. *
  713. * u32_write = 0x04000080;
  714. * if (handle_ic_write(RAM_WRITE_TEST_ADDR1, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR) {
  715. * goto EXIT_ERROR;
  716. * }
  717. *
  718. * u32_write = 0x00FE90FE;
  719. * if (handle_ic_write(RAM_WRITE_TEST_ADDR2, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR) {
  720. * goto EXIT_ERROR;
  721. * }
  722. *
  723. * u32_write = 0x0A800080;
  724. * if (handle_ic_write(RAM_WRITE_TEST_ADDR3, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR) {
  725. * goto EXIT_ERROR;
  726. * }
  727. *
  728. * delay_ms(5);
  729. *
  730. * if (handle_ic_read(RAM_READ_TEST_ADDR1, 4, (unsigned char *)(&u32_read), g_u8_drv_interface, I2C_WORD_MODE) == ERROR) {
  731. * goto EXIT_ERROR;
  732. * }
  733. *
  734. * if ((u32_read & 0xFE00) != 0) {
  735. * DEBUGOUT("RAM Test NG 954[0x%x]!!!\r\n", u32_read);
  736. * goto EXIT_ERROR;
  737. * }
  738. *
  739. * if (handle_ic_read(RAM_READ_TEST_ADDR2, 4, (unsigned char *)(&u32_read), g_u8_drv_interface, I2C_WORD_MODE) == ERROR) {
  740. * goto EXIT_ERROR;
  741. * }
  742. *
  743. * if (u32_read != 0x19007F00) {
  744. * DEBUGOUT("RAM Test NG B04[0x%x]!!!\r\n", u32_read);
  745. * goto EXIT_ERROR;
  746. * }
  747. *
  748. * if (handle_ic_read(RAM_READ_TEST_ADDR3, 4, (unsigned char *)(&u32_read), g_u8_drv_interface, I2C_WORD_MODE) == ERROR) {
  749. * goto EXIT_ERROR;
  750. * }
  751. *
  752. * if (u32_read != 0x40007F00) {
  753. * DEBUGOUT("RAM Test NG B08[0x%x]!!!\r\n", u32_read);
  754. * goto EXIT_ERROR;
  755. * }
  756. *
  757. * if (ft_test_ctrl_mbist_fun_3x(DISABLE) == ERROR) {
  758. * goto EXIT_ERROR;
  759. * } else {
  760. * DEBUGOUT("RAM Test Pass\r\n");
  761. * return SUCCESS;
  762. * }
  763. *
  764. * EXIT_ERROR:
  765. * if ((u8_retry_times-- > 0)) {
  766. * goto RETRY_RAM_TEST;
  767. * }
  768. *
  769. * ft_test_ctrl_mbist_fun_3x(DISABLE);
  770. * g_u32_wearable_test_result = WEARABLE_FT_TEST_RESULT_PRAM_NG;
  771. * DEBUGOUT("PRAM Test NG !!!\r\n");
  772. * return ERROR;
  773. * }
  774. */
  775. STATUS ft_test_ram_test_3x(unsigned char u8_is_stop_mcu)
  776. {
  777. unsigned int u32_read;
  778. unsigned char u8_retry_times = 2, u8_check_time = 8;
  779. unsigned int u32_write = 0;
  780. unsigned int u32_addr = 0;
  781. unsigned short u16_retry, u16DataBufLength;
  782. if ((g_st_test_info.u16_ft_test_info_1) == WEARBLE_FT_PRAM_SYSTEM_NG_CASE) {
  783. g_u32_wearable_test_result = WEARABLE_FT_TEST_RESULT_PRAM_NG;
  784. return ERROR;
  785. }
  786. RETRY_RAM_TEST:
  787. #if ENABLE_WDT
  788. /* reload the Watchdog timer*/
  789. Chip_WWDT_Feed(LPC_WWDT);
  790. #endif
  791. if (u8_is_stop_mcu)
  792. stop_mcu_3x(TRUE);
  793. u32_write = (USEFW_LOCK | CONFIG_LOCK | COMP_LOCK | BASEL_LOCK | INICO_LOCK);
  794. if (handle_ic_write(REG_FLASHCTL_FLASH_PRAM_LOCK, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  795. goto EXIT_ERROR;
  796. /* i2c tx buffer size = 0x38 (56)*/
  797. u16DataBufLength = 0x38;
  798. u32_addr = 0;
  799. while (u32_addr < u16DataBufLength) {
  800. g_u8_data_buf[u32_addr] = 0xFF;
  801. g_u8_data_buf[u32_addr + 1] = 0x00;
  802. g_u8_data_buf[u32_addr + 2] = 0xAA;
  803. g_u8_data_buf[u32_addr + 3] = 0x55;
  804. u32_addr += 4;
  805. }
  806. u32_addr = PRAM_BOOT_START;
  807. while (u32_addr < PRAM_BOOT_LENGTH) {
  808. if ((u32_addr + u16DataBufLength) > PRAM_BOOT_LENGTH)
  809. u16DataBufLength = PRAM_BOOT_LENGTH - u32_addr;
  810. if (handle_ic_write(u32_addr, u16DataBufLength, g_u8_data_buf, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  811. goto EXIT_ERROR;
  812. u32_addr += u16DataBufLength;
  813. #if ENABLE_WDT
  814. /* reload the Watchdog timer*/
  815. Chip_WWDT_Feed(LPC_WWDT);
  816. #endif
  817. }
  818. gpio_touch_reset_pin_control(FALSE);/*Low*/
  819. delay_ms(1);
  820. gpio_touch_reset_pin_control(TRUE);/*High*/
  821. delay_ms(25);
  822. g_u8_mute_i2c_err_log = TRUE;
  823. u16_retry = 150;
  824. do {
  825. #if ENABLE_WDT
  826. /* reload the Watchdog timer*/
  827. Chip_WWDT_Feed(LPC_WWDT);
  828. #endif
  829. delay_ms(35);
  830. if (handle_ic_read(REG_FLASHCTL_FLASH_STATE_REG_ADDR, 4, (unsigned char *)(&u32_read), g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  831. goto EXIT_ERROR;
  832. /*delay_ms(2);*/
  833. u16_retry--;
  834. } while (((u32_read & BLDR_FINISH) != BLDR_FINISH) && (u16_retry != 0));
  835. g_u8_mute_i2c_err_log = FALSE;
  836. if ((u32_read & BLDR_FINISH) != BLDR_FINISH) {
  837. g_u32_wearable_test_result |= WEARABLE_FT_TEST_RESULT_PRAM_NG;
  838. DEBUGOUT("PRAM Test NG !!!\r\n");
  839. return ERROR;
  840. }
  841. if ((u8_check_time-- > 0))
  842. goto RETRY_RAM_TEST;
  843. DEBUGOUT("RAM Test Pass\r\n");
  844. return SUCCESS;
  845. EXIT_ERROR:
  846. if ((u8_retry_times-- > 0)) {
  847. u8_check_time = 4;
  848. goto RETRY_RAM_TEST;
  849. }
  850. g_u32_wearable_test_result = WEARABLE_FT_TEST_RESULT_PRAM_NG;
  851. DEBUGOUT("PRAM Test NG !!!\r\n");
  852. g_u8_mute_i2c_err_log = FALSE;
  853. return ERROR;
  854. }
  855. STATUS ft_test_connect_test_3x(void)
  856. {
  857. unsigned char u8_retry = IC_TEST_RETRY_TIME;
  858. unsigned int u32_w_buf, u32_r_buf;
  859. unsigned int u32_test_addr = RM_DATAMEM0_BASE;
  860. char i8_str[8];
  861. if ((g_st_test_info.u16_ft_test_info_1) == WEARBLE_FT_I2C_SYSTEM_NG_CASE) {
  862. g_u32_wearable_test_result = WEARABLE_FT_TEST_RESULT_I2C_NG;
  863. return ERROR;
  864. }
  865. RETRY_CONNECT_TEST:
  866. if (g_u8_drv_interface == SPI_INTERFACE)
  867. snprintf(i8_str, RM_F303_MAX_STR_LENGTH, "SPI");
  868. else
  869. snprintf(i8_str, RM_F303_MAX_STR_LENGTH, "I2C");
  870. u32_w_buf = 0x55aa00ff;
  871. if (handle_ic_write(u32_test_addr, 4, (unsigned char *)&u32_w_buf, g_u8_drv_interface, I2C_WORD_MODE) == ERROR) {
  872. DEBUGOUT("%s Test Write NG!!\r\n", i8_str);
  873. goto NG_CASE;
  874. }
  875. if (handle_ic_read(u32_test_addr, 4, (unsigned char *)&u32_r_buf, g_u8_drv_interface, I2C_BYTE_MODE) == ERROR) {
  876. DEBUGOUT("%s Test Read NG!!\r\n", i8_str);
  877. goto NG_CASE;
  878. }
  879. if (u32_w_buf != u32_r_buf) {
  880. DEBUGOUT("%s Test Compare NG [%d], W=0x%x,R=0x%x\r\n", i8_str, 0, u32_w_buf, u32_r_buf);
  881. goto NG_CASE;
  882. }
  883. #if ENABLE_WDT
  884. Chip_WWDT_Feed(LPC_WWDT);/* reload the Watchdog timer*/
  885. #endif
  886. DEBUGOUT("%s Test Pass\r\n", i8_str);
  887. return SUCCESS;
  888. NG_CASE:
  889. if (--u8_retry > 0) {
  890. DEBUGOUT("%s Test Retry=%d\r\n", i8_str, u8_retry);
  891. if (hardware_reset_3x(TRUE) == ERROR)
  892. goto NG_CASE2;
  893. /*Stop MCU*/
  894. stop_mcu_3x(FALSE);
  895. goto RETRY_CONNECT_TEST;
  896. }
  897. NG_CASE2:
  898. g_u32_wearable_test_result = WEARABLE_FT_TEST_RESULT_I2C_NG;
  899. DEBUGOUT("%s Test NG !!!\r\n", i8_str);
  900. return ERROR;
  901. }
  902. STATUS ft_test_reset_pin_test_3x(void)
  903. {
  904. unsigned int u32_write = 0;
  905. if ((g_st_test_info.u16_ft_test_info_1) == WEARBLE_FT_RESET_PIN_SYSTEM_NG_CASE) {
  906. g_u32_wearable_test_result = WEARABLE_FT_TEST_RESULT_RESET_NG;
  907. return ERROR;
  908. }
  909. u32_write = 0x00000404;
  910. if (handle_ic_write(REG_SYSCON_MISCIER_ADDR, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  911. return ERROR;
  912. if (!gpio_touch_int_pin_state_access()) { /* check INT in high state*/
  913. g_u32_wearable_test_result = WEARABLE_FT_TEST_RESULT_INT_NG;
  914. return ERROR;
  915. }
  916. gpio_touch_reset_pin_control(FALSE);/*Low*/
  917. delay_ms(1);
  918. if (gpio_touch_int_pin_state_access()) {
  919. g_u32_wearable_test_result = WEARABLE_FT_TEST_RESULT_RESET_NG;
  920. DEBUGOUT("Reset Pin Test NG(Not High) !!!\r\n");
  921. return ERROR;
  922. }
  923. gpio_touch_reset_pin_control(TRUE);/*High*/
  924. delay_ms(25);
  925. DEBUGOUT("Reset Pin Test Pass !!!\r\n");
  926. return SUCCESS;
  927. }
  928. STATUS ft_test_panel_model_check_3x(unsigned short u16_version)
  929. {
  930. unsigned int u32_read;
  931. unsigned short u16_model_version;
  932. if (handle_ic_read(FW_FT_SRAM_FW_VERSION, 4, (unsigned char *)(&u32_read), g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  933. return ERROR;
  934. u16_model_version = (u32_read & 0x0000FFFF);
  935. DEBUGOUT("Panel Model Test! 0x%08X:0x%08X\r\n", u32_read, u16_version);
  936. DEBUGOUT("Panel Model 0x%08X\r\n", u16_model_version);
  937. if (u16_model_version == u16_version)
  938. return SUCCESS;
  939. DEBUGOUT("Panel Model NG! 0x%x:0x%x\r\n", u16_model_version, u16_version);
  940. return ERROR;
  941. }
  942. void ft_raw_data_checksum_cal_3x(unsigned short *u16_buffer)
  943. {
  944. unsigned char u8_i;
  945. u16_buffer[48] = 0x55AA;
  946. u16_buffer[49] = 0;
  947. for (u8_i = 0; u8_i < (MAX_SENSING_PIN_NUM - 1); u8_i++)
  948. u16_buffer[49] += u16_buffer[u8_i];
  949. DEBUGOUT("[RDCSA] %x:%x\r\n", u16_buffer[48], u16_buffer[49]);
  950. }
  951. void ft_test_result_checksum_cal_3x(unsigned char *u8_buffer)
  952. {
  953. unsigned char u8_i;
  954. u8_buffer[48] = 0x5A;
  955. u8_buffer[49] = 0;
  956. for (u8_i = 0; u8_i < (MAX_SENSING_PIN_NUM - 1); u8_i++)
  957. u8_buffer[49] += u8_buffer[u8_i];
  958. DEBUGOUT("[TRCSA] %x:%x\r\n", u8_buffer[48], u8_buffer[49]);
  959. }
  960. STATUS ft_raw_data_checksum_check_3x(unsigned short *u16_buffer)
  961. {
  962. unsigned char u8_i;
  963. unsigned short u16_sum = 0;
  964. if (u16_buffer[48] != 0x55AA) {
  965. DEBUGOUT("u16_buffer[34]:%x\r\n", u16_buffer[48]);
  966. DEBUGOUT("[RDCSC] Pattern NG! [0x%x](0x%x)\r\n", (int)u16_buffer, u16_buffer[48]);
  967. return ERROR;
  968. }
  969. /*u16_buffer[35]=0;*/
  970. for (u8_i = 0; u8_i < (MAX_SENSING_PIN_NUM - 1); u8_i++)
  971. u16_sum += u16_buffer[u8_i];
  972. if (u16_buffer[49] != u16_sum) {
  973. DEBUGOUT("[RDCSC] Check SUM NG! [0x%x](0x%x:0x%x)\r\n", (int)u16_buffer, u16_sum, u16_buffer[49]);
  974. return ERROR;
  975. }
  976. DEBUGOUT("[RDCSC] PASS (0x%x:0x%x)\r\n", u16_buffer[48], u16_buffer[49]);
  977. return SUCCESS;
  978. }
  979. STATUS ft_test_result_checksum_check_3x(unsigned char *u8_buffer)
  980. {
  981. unsigned char u8_i;
  982. unsigned char u8_sum = 0;
  983. if (u8_buffer[48] != 0x5A) {
  984. DEBUGOUT("[TRCSC] Pattern NG! [0x%x](0x%x:0x%x)\r\n", (int)u8_buffer, u8_buffer[48], u8_buffer[49]);
  985. return ERROR;
  986. }
  987. /*u32_buffer[35]=0;*/
  988. for (u8_i = 0; u8_i < (MAX_SENSING_PIN_NUM - 1); u8_i++)
  989. u8_sum += u8_buffer[u8_i];
  990. if (u8_buffer[49] != u8_sum) {
  991. DEBUGOUT("[TRCSC] Check SUM NG! [0x%x](0x%x:0x%x)\r\n", (int)u8_buffer, u8_sum, u8_buffer[49]);
  992. return ERROR;
  993. }
  994. DEBUGOUT("[TRCSC] PASS (0x%x:0x%x)\r\n", u8_buffer[48], u8_buffer[49]);
  995. return SUCCESS;
  996. }
  997. STATUS baseline_update_control_3x(bool b_enable_baseline_update)
  998. {
  999. unsigned int u32_write_buf;
  1000. unsigned char u8_read;
  1001. short i16_time_out = 100;
  1002. if (b_enable_baseline_update) {
  1003. u32_write_buf = (SYS_CMD_FUNC_DIS_BS_UPDATE);
  1004. DEBUGOUT("[BUC] Enable Baseline update\r\n");
  1005. } else {
  1006. u32_write_buf = (DIS_BASELINE_UPDATE | SYS_CMD_FUNC_DIS_BS_UPDATE);
  1007. DEBUGOUT("[BUC] Disable Baseline update\r\n");
  1008. }
  1009. if (handle_ic_write(FW_SYS_CMD_ADDR, 4, (unsigned char *)&u32_write_buf, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  1010. return ERROR;
  1011. delay_ms(5);
  1012. while (i16_time_out--) {
  1013. if (handle_ic_read(FW_SYS_CMD_ADDR, 1, &u8_read, g_u8_drv_interface, I2C_BYTE_MODE) == SUCCESS) {
  1014. if (u8_read == 0x00)
  1015. break;
  1016. } else {
  1017. DEBUGOUT("[BUC] I2C Read NG\r\n");
  1018. return ERROR;
  1019. }
  1020. delay_ms(2);
  1021. }
  1022. if (i16_time_out == IC_TEST_TIME_OUT) {
  1023. DEBUGOUT("[BUC] Baseline Update Control (%d) NG\r\n", b_enable_baseline_update);
  1024. return ERROR;
  1025. }
  1026. return SUCCESS;
  1027. }
  1028. STATUS wait_fw_init_ready_3x(void)
  1029. {
  1030. unsigned short u16_time_out;
  1031. unsigned char u8_r_buf[2];
  1032. u16_time_out = 100;
  1033. /*Check FW Ready ?*/
  1034. do {
  1035. if (handle_ic_read(FW_FT_ARG0_ADDR, 2, u8_r_buf, g_u8_drv_interface, I2C_BYTE_MODE) == ERROR)
  1036. return ERROR;
  1037. DEBUGOUT("FW Flag = 0x%x,0x%x\r\n", u8_r_buf[0], u8_r_buf[1]);
  1038. if (u8_r_buf[0] == 0xAA && u8_r_buf[1] == 0x55)
  1039. return SUCCESS;
  1040. delay_ms(2);
  1041. } while (u16_time_out-- > 0);
  1042. return ERROR;
  1043. }
  1044. STATUS enter_normal_fw_3x(void)
  1045. {
  1046. unsigned char u8_pattern_noise_only = 0;
  1047. #if ENABLE_TEST_TIME_MEASURMENT
  1048. unsigned int u32_fun_time = 0;
  1049. u32_fun_time = get_system_time();
  1050. #endif
  1051. if (g_u8_is_normal_fw)
  1052. return SUCCESS;
  1053. #if !SELFTEST_3X
  1054. /*Set INT Falling Triggle*/
  1055. gpio_touch_int_trigger_control(FALSE);
  1056. #endif
  1057. g_u32_wearable_test_result &= ~WEARABLE_FT_TEST_RESULT_NORMAL_FW_RESET_NG;
  1058. if (g_u8_drv_interface == SPI_INTERFACE) {
  1059. if (hardware_reset_3x(TRUE) == ERROR) {
  1060. DEBUGOUT("[ENF]No INT, no OTP!!\r\n");
  1061. g_u32_wearable_test_result |= WEARABLE_FT_TEST_RESULT_NORMAL_FW_RESET_NG;
  1062. return ERROR;
  1063. }
  1064. #if !SELFTEST_3X
  1065. if (burn_pram_from_dongle_flash_3x() == ERROR)
  1066. return ERROR;
  1067. #endif
  1068. } else {
  1069. if ((g_st_test_info.u16_ft_test_item & ~(IC_TEST_ITEMS_SYSTEM | IC_TEST_ITEMS_PANEL_TEST_2)) == FALSE) {
  1070. u8_pattern_noise_only = TRUE;
  1071. DEBUGOUT("Panel Test!!!\r\n");
  1072. }
  1073. if (!u8_pattern_noise_only) {
  1074. /*PRAM Test*/
  1075. if (ft_test_ram_test_3x(1) == ERROR)
  1076. return ERROR;
  1077. }
  1078. if (hardware_reset_3x(FALSE) == ERROR) {
  1079. DEBUGOUT("[ENF]No INT, no OTP!!\r\n");
  1080. g_u32_wearable_test_result |= WEARABLE_FT_TEST_RESULT_NORMAL_FW_RESET_NG;
  1081. return ERROR;
  1082. }
  1083. }
  1084. if (wait_fw_init_ready_3x() == ERROR)
  1085. return ERROR;
  1086. if (ft_test_read_used_pin_infor_3x(g_u8_wearable_pin_map) == ERROR)
  1087. return ERROR;
  1088. #if ENABLE_TEST_TIME_MEASURMENT
  1089. DEBUGOUT("[ENF] (%d)\r\n", get_system_time() - u32_fun_time);
  1090. #endif
  1091. g_u8_is_normal_fw = TRUE;
  1092. return SUCCESS;
  1093. }
  1094. STATUS check_cc_bl_flag_3x(void)
  1095. {
  1096. unsigned char u8_read_buf[4];
  1097. unsigned char u8_is_cc_ready = 0;
  1098. unsigned char u8_fw_version[4];
  1099. short i16_time_out;
  1100. DEBUGOUT("[CCBF] Check CC BL Flag\r\n");
  1101. if (handle_ic_read(FW_FT_FW_VERSION, 4, u8_fw_version, g_u8_drv_interface, I2C_BYTE_MODE) == ERROR)
  1102. return ERROR;
  1103. i16_time_out = 20;
  1104. while (i16_time_out--) {
  1105. if (!u8_is_cc_ready) {
  1106. if (handle_ic_read(PRAM_ADDR_CC_INFO, 4, u8_read_buf, g_u8_drv_interface, I2C_BYTE_MODE) == ERROR)
  1107. return ERROR;
  1108. if ((u8_read_buf[0] >= 1) && (u8_read_buf[2] == u8_fw_version[2]) && (u8_read_buf[3] == u8_fw_version[3]))
  1109. u8_is_cc_ready = 1;
  1110. }
  1111. if (u8_is_cc_ready)
  1112. break;
  1113. delay_ms(1);
  1114. }
  1115. /*Check flag*/
  1116. if (i16_time_out == IC_TEST_TIME_OUT) {
  1117. DEBUGOUT("CC Flag=%d NG!!\r\n", u8_read_buf[0]);
  1118. 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]);
  1119. return ERROR;
  1120. }
  1121. return SUCCESS;
  1122. }
  1123. STATUS burn_cc_to_ic_flash_3x(void)
  1124. {
  1125. short i16_time_out = 1000;
  1126. unsigned int u32_cc_table;
  1127. unsigned char u8_fw_value[4];
  1128. unsigned int u32_write = 0;
  1129. #if SELFTEST_3X
  1130. unsigned int u32_read;
  1131. #endif
  1132. #if ENABLE_TEST_TIME_MEASURMENT_CC
  1133. DEBUGOUT("[BCTF] Before Switch to Bootloader\r\n");
  1134. g_u32_spend_time = get_system_time();
  1135. #endif
  1136. #if !SELFTEST /*210708 add, for fw use bootloader block*/
  1137. if (stop_mcu_3x(0) == ERROR)
  1138. return ERROR;
  1139. /*WRT boot-loader to PRAM first*/
  1140. u32_write = (USEFW_LOCK | CONFIG_LOCK | COMP_LOCK | BASEL_LOCK);
  1141. if (handle_ic_write(REG_FLASHCTL_FLASH_PRAM_LOCK, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  1142. return ERROR;
  1143. /*read flash data and write to pram (Bootloader)*/
  1144. if (handle_spiFlash_to_pram(PRAM_BOOT_START, PRAM_BOOT_LENGTH, PRAM_BOOT_START) == ERROR) {
  1145. DEBUGOUT("confirm crc error!!\r\n");
  1146. return ERROR;
  1147. }
  1148. /*check pram bootloader crc*/
  1149. if (check_pram_crc32_3x(PRAM_BOOT_START, PRAM_BOOT_CRC_LENGTH) == ERROR) {
  1150. DEBUGOUT("confirm bootloader crc error!!\r\n");
  1151. return ERROR;
  1152. }
  1153. /*read flash data and write to pram (Initial_code)*/
  1154. if (handle_spiFlash_to_pram(PRAM_DIS_INIT_START, PRAM_DIS_INIT_LENGTH, PRAM_DIS_INIT_START) == ERROR) {
  1155. DEBUGOUT("confirm crc error!!\r\n");
  1156. return ERROR;
  1157. }
  1158. /*check pram Initial code crc*/
  1159. if (check_pram_crc32_3x(PRAM_DIS_INIT_START, 0x7C) == ERROR) {
  1160. DEBUGOUT("confirm init crc error!!\r\n");
  1161. return ERROR;
  1162. }
  1163. #endif
  1164. /*Set Skip_Load = 1*/
  1165. u32_write = (BL_CRC_CHK | SKIP_LOAD);
  1166. if (handle_ic_write(REG_FLASHCTL_FLASH_STATE_REG_ADDR, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  1167. return ERROR;
  1168. /*wait sw rst finish*/
  1169. u32_write = BLKRST_SW_RST;
  1170. if (handle_ic_write(REG_SYSCON_BLKRST_ADDR, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  1171. return ERROR;
  1172. delay_ms(2);
  1173. if (wait_fw_state_3x(BOOT_RET_DATA_ADDR, WAIT_TEST_MODE, 1, i16_time_out) == ERROR) {
  1174. DEBUGOUT("[BCTF] Check Burn CC & BL Fail\r\n");
  1175. return ERROR;
  1176. }
  1177. #if ENABLE_TEST_TIME_MEASURMENT_CC
  1178. DEBUGOUT("[BCTF] End of Switch to Bootloader = %d\r\n", get_system_time() - g_u32_spend_time);
  1179. g_u32_spend_time = get_system_time();
  1180. DEBUGOUT("TICK=%d\r\n", get_system_time());
  1181. #endif
  1182. #if SELFTEST_3X
  1183. if (sysfs_burn_cc_bl()) {
  1184. /*Read Flash CC Table*/
  1185. if (read_fpc_flash_3x(FLASH_NORMAL_FW_CC_TABLE_ADDR, &u32_cc_table) == ERROR)
  1186. return ERROR;
  1187. DEBUGOUT("Flash Do CC FW Version=0x%04X\r\n", (u32_cc_table & 0xFFFF0000) >> 16);
  1188. DEBUGOUT("Flash Do CC Flag=0x%X\r\n", (u32_cc_table & 0x0000FFFF));
  1189. g_u32_fw_cc_version = u32_cc_table;
  1190. /*Read PRAM FW Version*/
  1191. if (handle_ic_read(FW_FT_SRAM_FW_VERSION, 4, u8_fw_value, g_u8_drv_interface, I2C_BYTE_MODE) == ERROR)
  1192. return ERROR;
  1193. DEBUGOUT("SRAM FW Version=0x%03x,0x%03x\r\n", u8_fw_value[3], u8_fw_value[2]);
  1194. if (((u32_cc_table & 0xFF000000) >> 24) != u8_fw_value[3] || ((u32_cc_table & 0x00FF0000) >> 16) != u8_fw_value[2]) {
  1195. DEBUGOUT("Flash CC Table FW Version is not match!\r\n");
  1196. if (handle_ic_read(REG_FLASHCTL_FLASH_STATE_REG_ADDR, 4, (unsigned char *)(&u32_read), g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  1197. DEBUGOUT("read 5000 0918 error\r\n");
  1198. DEBUGOUT("Flash 0x50000918=0x%08X\r\n", u32_read);
  1199. return ERROR;
  1200. }
  1201. return SUCCESS;
  1202. } else
  1203. return ERROR;
  1204. #else
  1205. if (burn_to_ic_flash_3x(COMP_AREA) == ERROR) {
  1206. DEBUGOUT("[BCTF] Burn CC & BL Fail\r\n");
  1207. return ERROR;
  1208. }
  1209. u32_write = 0x00000000;
  1210. if (handle_ic_write(BOOT_TEST_MODE_ADDR, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  1211. return ERROR;
  1212. /* clr sync_data(0x20000200) = 0 as finish*/
  1213. u32_write = 0x00000000;
  1214. if (handle_ic_write(BOOT_SYNC_DATA_ADDR, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  1215. return ERROR;
  1216. delay_ms(10);
  1217. if (wait_fw_state_3x(REG_FLASHCTL_FLASH_STATE_REG_ADDR, 0x4000, 2, i16_time_out) == ERROR) {
  1218. DEBUGOUT("[BCTF] Check Burn CC & BL Fail\r\n");
  1219. return ERROR;
  1220. }
  1221. #if ENABLE_AUO_VERIFY_LOG
  1222. if (read_fpc_flash_3x((unsigned int)(FLASH_FW_START + PRAM_FW_LENGTH - 4), &u32_i2c_read_data))
  1223. DEBUGOUT("Normal FW CRC=0x%08X\r\n", u32_i2c_read_data);
  1224. #endif
  1225. #if ENABLE_TEST_TIME_MEASURMENT_CC
  1226. DEBUGOUT("BCTF] Burn to flash finish[Tick=%d]!\r\n", get_system_time() - g_u32_spend_time);
  1227. #endif
  1228. /*Read Flash CC Table*/
  1229. if (read_fpc_flash_3x(FLASH_NORMAL_FW_CC_TABLE_ADDR, &u32_cc_table) == ERROR)
  1230. return ERROR;
  1231. DEBUGOUT("Flash Do CC FW Version=0x%04X\r\n", (u32_cc_table & 0xFFFF0000) >> 16);
  1232. DEBUGOUT("Flash Do CC Flag=0x%X\r\n", (u32_cc_table & 0x0000FFFF));
  1233. /*Read PRAM FW Version*/
  1234. if (handle_ic_read(FW_FT_SRAM_FW_VERSION, 4, u8_fw_value, g_u8_drv_interface, I2C_BYTE_MODE) == ERROR)
  1235. return ERROR;
  1236. DEBUGOUT("SRAM FW Version=0x%03x,0x%03x\r\n", u8_fw_value[3], u8_fw_value[2]);
  1237. if (((u32_cc_table & 0xFF000000) >> 24) != u8_fw_value[3] || ((u32_cc_table & 0x00FF0000) >> 16) != u8_fw_value[2]) {
  1238. DEBUGOUT("Flash CC Table FW Version is not match!\r\n");
  1239. return ERROR;
  1240. }
  1241. return SUCCESS;
  1242. #endif
  1243. }
  1244. STATUS do_calibration_3x(unsigned char u8_do_calibration_cmd, unsigned char u8_burn_flash)
  1245. {
  1246. unsigned char u8_value[4];
  1247. short u8_time_out = 100;
  1248. unsigned char u8_retry = IC_TEST_RETRY_TIME;
  1249. g_u32_wearable_test_result &= ~(WEARABLE_FT_TEST_RESULT_CC_CALIBRATION_NG | WEARABLE_FT_TEST_RESULT_BURN_CC_NG);
  1250. if (u8_do_calibration_cmd == TRUE) {
  1251. #if ENABLE_TEST_TIME_MEASURMENT_CC
  1252. DEBUGOUT("[DOCC] Start do calibration (%d)\r\n", get_system_time());
  1253. g_u32_spend_time = get_system_time();
  1254. #endif
  1255. while (u8_retry--) {
  1256. u8_value[0] = SYS_CMD_DO_CC_CAL;
  1257. if (handle_ic_write(FW_SYS_CMD_ADDR, 1, u8_value, g_u8_drv_interface, I2C_BYTE_MODE) == ERROR) /*Trigger Calibration*/
  1258. return ERROR;
  1259. u8_time_out = 400;
  1260. /* Wait calibration ready*/
  1261. while (u8_time_out--) {
  1262. delay_ms(10);/*20*/
  1263. if (handle_ic_read(FW_SYS_CMD_ADDR, 4, u8_value, g_u8_drv_interface, I2C_BYTE_MODE) == ERROR)
  1264. return ERROR;
  1265. else if (u8_value[0] == 0)
  1266. break;
  1267. #if ENABLE_WDT
  1268. Chip_WWDT_Feed(LPC_WWDT);/* reload the Watchdog timer*/
  1269. #endif
  1270. }
  1271. if (u8_time_out == IC_TEST_TIME_OUT) {
  1272. if (u8_retry) {
  1273. DEBUGOUT("[DOCC] Do CC Retry (%d,%d)", u8_retry, u8_value[0]);
  1274. hardware_reset_3x(TRUE);
  1275. #if !SELFTEST_3X
  1276. if (g_u8_drv_interface == SPI_INTERFACE) {
  1277. if (burn_pram_from_dongle_flash_3x() == ERROR)
  1278. return ERROR;
  1279. }
  1280. #endif
  1281. delay_ms(20);
  1282. continue;
  1283. } else {
  1284. g_u32_wearable_test_result |= WEARABLE_FT_TEST_RESULT_CC_CALIBRATION_NG;
  1285. DEBUGOUT("[DOCC] SYS CMD CC NG\r\n");
  1286. return ERROR;
  1287. }
  1288. } else {
  1289. if (check_cc_bl_flag_3x() == ERROR) {
  1290. if (u8_retry) {
  1291. DEBUGOUT("[DOCC] CC Flag Retry (%d)", u8_retry);
  1292. hardware_reset_3x(TRUE);
  1293. #if !SELFTEST_3X
  1294. if (g_u8_drv_interface == SPI_INTERFACE) {
  1295. if (burn_pram_from_dongle_flash_3x() == ERROR)
  1296. return ERROR;
  1297. }
  1298. #endif
  1299. delay_ms(20);
  1300. continue;
  1301. } else {
  1302. g_u32_wearable_test_result |= WEARABLE_FT_TEST_RESULT_CC_CALIBRATION_NG;
  1303. DEBUGOUT("[DOCC] CC Flag NG\r\n");
  1304. return ERROR;
  1305. }
  1306. } else /*Calibration OK*/
  1307. break;
  1308. }
  1309. }
  1310. #if ENABLE_TEST_TIME_MEASURMENT_CC
  1311. DEBUGOUT("[DOCC] Do CC Finish! [%d:%d]\r\n", get_system_time() - g_u32_spend_time, u8_time_out);
  1312. g_u32_spend_time = get_system_time();
  1313. #endif
  1314. }
  1315. if (u8_burn_flash == FALSE) {
  1316. DEBUGOUT("[DOCC] Do Calibration Finish \r\n");
  1317. return SUCCESS;
  1318. }
  1319. if (burn_cc_to_ic_flash_3x() == ERROR) {
  1320. DEBUGOUT("[DOCC] Burn to flash NG!\r\n");
  1321. hardware_reset_3x(TRUE);
  1322. g_u32_wearable_test_result |= WEARABLE_FT_TEST_RESULT_BURN_CC_NG;
  1323. return ERROR;
  1324. }
  1325. #if ENABLE_TEST_TIME_MEASURMENT_CC
  1326. DEBUGOUT("[DOCC] Burn CC Finish (%d)\r\n", get_system_time() - g_u32_spend_time);
  1327. #endif
  1328. DEBUGOUT("[DOCC] Burn CC Finish \r\n");
  1329. return SUCCESS;
  1330. }
  1331. STATUS hw_int_pin_Test_3x(void)
  1332. {
  1333. unsigned int u32_write = 0;
  1334. if ((g_st_test_info.u16_ft_test_info_1) == WEARBLE_FT_INT_SYSTEM_NG_CASE) {
  1335. g_u32_wearable_test_result = WEARABLE_FT_TEST_RESULT_INT_NG;
  1336. return ERROR;
  1337. }
  1338. /*Trigger INT to Low*/
  1339. u32_write = 0x00000004;
  1340. if (handle_ic_write(REG_SYSCON_MISCIER_ADDR, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  1341. return ERROR;
  1342. /*Read Pin state*/
  1343. if (!gpio_touch_int_pin_state_access()) {
  1344. /*DEBUGOUT("INT is LOW\r\n");*/
  1345. } else {
  1346. DEBUGOUT("INT Test NG!\r\n");
  1347. g_u32_wearable_test_result = WEARABLE_FT_TEST_RESULT_INT_NG;
  1348. return ERROR;
  1349. }
  1350. /*Trigger INT to High*/
  1351. u32_write = 0x00000404;
  1352. if (handle_ic_write(REG_SYSCON_MISCIER_ADDR, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  1353. return ERROR;
  1354. /*Read Pin state*/
  1355. if (gpio_touch_int_pin_state_access()) {
  1356. /*DEBUGOUT("INT is High\r\n");*/
  1357. } else {
  1358. DEBUGOUT("INT Test NG!\r\n");
  1359. g_u32_wearable_test_result = WEARABLE_FT_TEST_RESULT_INT_NG;
  1360. return ERROR;
  1361. }
  1362. gpio_touch_int_access(TRUE);
  1363. DEBUGOUT("INT Test Pass\r\n");
  1364. return SUCCESS;
  1365. }
  1366. STATUS read_test_fw_data_3x(unsigned short u16_test_items)
  1367. {
  1368. unsigned char u8_retry = IC_TEST_RETRY_TIME;
  1369. unsigned int u32_test_item_result;
  1370. #if ENABLE_TEST_TIME_MEASURMENT
  1371. unsigned int u32_fun_time = 0;
  1372. u32_fun_time = get_system_time();
  1373. #endif
  1374. g_u32_wearable_test_result &= ~(WEARABLE_FT_TEST_RESULT_GET_DATA_NG | WEARABLE_FT_TEST_RESULT_OPEN_NG
  1375. | WEARABLE_FT_TEST_RESULT_SHORT_NG | WEARABLE_FT_TEST_RESULT_UB_NG
  1376. | WEARABLE_FT_TEST_RESULT_UC_NG | WEARABLE_FT_TEST_RESULT_SINGLE_CC_OPEN_NG
  1377. | WEARABLE_FT_TEST_RESULT_SINGLE_CC_SHORT_NG);
  1378. if ((g_st_test_info.u16_ft_test_item & (IC_TEST_ITEMS_OPEN | IC_TEST_ITEMS_SHORT |
  1379. IC_TEST_ITEMS_UC | IC_TEST_ITEMS_UB)) == 0) {
  1380. return SUCCESS;
  1381. }
  1382. RETRY:
  1383. memset(g_i16_raw_data_1_short_buf, 0, sizeof(g_i16_raw_data_1_short_buf));
  1384. memset(g_i16_raw_data_2_open_buf, 0, sizeof(g_i16_raw_data_2_open_buf));
  1385. memset(g_u16_raw_data3_cc_buf, 0, sizeof(g_u16_raw_data3_cc_buf));
  1386. memset(g_u16_uc_buf, 0, sizeof(g_u16_uc_buf));
  1387. memset(g_u8_wearable_pin_map, F303_NA_P, sizeof(g_u8_wearable_pin_map));
  1388. 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)
  1389. goto ERROR_EXIT;
  1390. 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)
  1391. goto ERROR_EXIT;
  1392. 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)
  1393. goto ERROR_EXIT;
  1394. 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)
  1395. goto ERROR_EXIT;
  1396. 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)
  1397. goto ERROR_EXIT;
  1398. if (handle_ic_read(FT_TEST_ITEM_RESULT, 4, (unsigned char *)(&u32_test_item_result), g_u8_drv_interface, I2C_BYTE_MODE) == ERROR)
  1399. goto ERROR_EXIT;
  1400. if (ft_raw_data_checksum_check_3x((unsigned short *)g_i16_raw_data_1_short_buf) == ERROR)
  1401. goto ERROR_EXIT;
  1402. if (ft_raw_data_checksum_check_3x((unsigned short *)g_i16_raw_data_2_open_buf) == ERROR)
  1403. goto ERROR_EXIT;
  1404. if (ft_raw_data_checksum_check_3x((unsigned short *)g_u16_raw_data3_cc_buf) == ERROR)
  1405. goto ERROR_EXIT;
  1406. if (ft_raw_data_checksum_check_3x(g_u16_uc_buf) == ERROR)
  1407. goto ERROR_EXIT;
  1408. if (ft_test_result_checksum_check_3x(g_u8_test_result) == ERROR)
  1409. goto ERROR_EXIT;
  1410. if (ft_test_read_used_pin_infor_3x(g_u8_wearable_pin_map) == ERROR)
  1411. goto ERROR_EXIT;
  1412. #if ENABLE_TEST_RSU_DATA_SHOW
  1413. DEBUGOUT("Slow Data:\r\n");
  1414. dump_image_data_3x(g_i16_raw_data_1_short_buf, TRUE);
  1415. DEBUGOUT("Quick Data:\r\n");
  1416. dump_image_data_3x(g_i16_raw_data_2_open_buf, TRUE);
  1417. DEBUGOUT("P CC:\r\n");
  1418. dump_image_hex_data_3x((short *)g_u16_raw_data3_cc_buf);
  1419. DEBUGOUT("Open Golden CC:\r\n");
  1420. dump_image_hex_data_3x((short *)g_u16_raw_data3_golden_cc_buf);
  1421. DEBUGOUT("UC:\r\n");
  1422. dump_image_data_3x((short *)g_u16_uc_buf, TRUE);
  1423. DEBUGOUT("Golden UC:\r\n");
  1424. dump_image_data_3x((short *)g_u16_uc_golden_cc_buf, TRUE);
  1425. DEBUGOUT("test item result:0x%x\r\n", u32_test_item_result);
  1426. #endif
  1427. if (g_u8_print_debug_msg & PRINT_DEBUG_MSG_TYPE_4) {
  1428. DEBUGOUT("Slow Data:\r\n");
  1429. dump_image_data_3x(g_i16_raw_data_1_short_buf, TRUE);
  1430. DEBUGOUT("Quick Data:\r\n");
  1431. dump_image_data_3x(g_i16_raw_data_2_open_buf, TRUE);
  1432. DEBUGOUT("P CC:\r\n");
  1433. dump_image_data_3x((short *)g_u16_raw_data3_cc_buf, TRUE);
  1434. }
  1435. if (g_u8_print_debug_msg & PRINT_DEBUG_MSG_TYPE_5) {
  1436. DEBUGOUT("UC Data:\r\n");
  1437. dump_image_data_3x((short *)g_u16_uc_buf, TRUE);
  1438. }
  1439. #if ENABLE_TEST_TIME_MEASURMENT
  1440. DEBUGOUT("#read_test_data end=%d\r\n", get_system_time() - u32_fun_time);
  1441. #endif
  1442. g_u32_wearable_test_result |= u32_test_item_result;
  1443. DEBUGOUT("Read Test FW Result Finish\r\n");
  1444. return SUCCESS;
  1445. ERROR_EXIT:
  1446. if (u8_retry) {
  1447. u8_retry--;
  1448. DEBUGOUT("Read Test FW Result Retry:%d", u8_retry);
  1449. goto RETRY;
  1450. }
  1451. g_u32_wearable_test_result |= WEARABLE_FT_TEST_RESULT_GET_DATA_NG;
  1452. DEBUGOUT("Read Test FW Result NG\r\n");
  1453. return ERROR;
  1454. }
  1455. void test_item_message_3x(void)
  1456. {
  1457. unsigned short u16_test_item = g_st_test_info.u16_ft_test_item;
  1458. DEBUGOUT("================================\r\n");
  1459. DEBUGOUT("Enter 3x IC Test,(%d)\r\n", get_system_time());
  1460. DEBUGOUT("IC Test Items=0x%X\r\n", u16_test_item);
  1461. if (u16_test_item & IC_TEST_ITEMS_SYSTEM)
  1462. DEBUGOUT("Enable System Test\r\n");
  1463. if (u16_test_item & IC_TEST_ITEMS_OPEN)
  1464. DEBUGOUT("Enable Open Test\r\n");
  1465. if (u16_test_item & IC_TEST_ITEMS_SHORT)
  1466. DEBUGOUT("Enable Short Test\r\n");
  1467. if (u16_test_item & IC_TEST_ITEMS_UC)
  1468. DEBUGOUT("Enable Uniformity CC test\r\n");
  1469. if (u16_test_item & IC_TEST_ITEMS_UB)
  1470. DEBUGOUT("Enable Uniformity BL test\r\n");
  1471. if (u16_test_item & IC_TEST_ITEMS_BURN_FW)
  1472. DEBUGOUT("Enable Burn FW\r\n");
  1473. if (u16_test_item & IC_TEST_ITEMS_BURN_CC)
  1474. DEBUGOUT("Enable Burn CC\r\n");
  1475. }
  1476. STATUS burn_cc_3x(unsigned short u16_test_items)
  1477. {
  1478. unsigned char u8_retry = IC_TEST_RETRY_TIME;
  1479. #if ENABLE_AUO_VERIFY_LOG
  1480. unsigned int u32_flash_crc = 0;
  1481. #endif
  1482. #if ENABLE_TEST_TIME_MEASURMENT
  1483. unsigned int u32_fun_time = 0;
  1484. u32_fun_time = get_system_time();
  1485. #endif
  1486. g_u32_wearable_test_result &= ~(WEARABLE_FT_TEST_RESULT_BURN_CC_NG | WEARABLE_FT_TEST_RESULT_NORMAL_FW_NG
  1487. | WEARABLE_FT_TEST_RESULT_CC_CALIBRATION_NG);
  1488. if ((g_st_test_info.u16_ft_test_info_1) == WEARBLE_FT_BURN_CC_SYSTEM_NG_CASE) {
  1489. g_u32_wearable_test_result = WEARABLE_FT_TEST_RESULT_BURN_CC_NG;
  1490. return ERROR;
  1491. }
  1492. if ((g_st_test_info.u16_ft_test_item & (IC_TEST_ITEMS_BURN_CC)) == 0) {
  1493. g_u32_wearable_test_result &= ~WEARABLE_FT_TEST_RESULT_NORMAL_FW_RESET_NG;
  1494. return SUCCESS;
  1495. }
  1496. while (u8_retry--) {
  1497. if (enter_normal_fw_3x() == ERROR) {
  1498. if (u8_retry && !(g_u32_wearable_test_result & WEARABLE_FT_TEST_RESULT_PRAM_NG))
  1499. continue;
  1500. else {
  1501. g_u32_wearable_test_result |= WEARABLE_FT_TEST_RESULT_NORMAL_FW_NG;
  1502. DEBUGOUT("Enter Normal FW NG\r\n");
  1503. return ERROR;
  1504. }
  1505. }
  1506. /*Do CC*/
  1507. #if ENABLE_WDT
  1508. Chip_WWDT_Feed(LPC_WWDT);/* reload the Watchdog timer*/
  1509. #endif
  1510. DEBUGOUT("[BC] Burn CC Start!!\r\n");
  1511. if (g_u8_drv_interface == SPI_INTERFACE) {
  1512. /*flashless, bypass*/
  1513. DEBUGOUT("[BC]Flashless Burn CC ByPass!!\r\n");
  1514. return SUCCESS;
  1515. }
  1516. /*Burn CC to Flash*/
  1517. if (do_calibration_3x(TRUE, TRUE) == SUCCESS) {
  1518. DEBUGOUT("[BC] Burn CC Pass!!(%d)\r\n", u8_retry);
  1519. break;
  1520. }
  1521. if (u8_retry)
  1522. continue;
  1523. else {
  1524. DEBUGOUT("[BC] Burn CC NG!!\r\n");
  1525. return ERROR;
  1526. }
  1527. }
  1528. #if ENABLE_TEST_TIME_MEASURMENT
  1529. DEBUGOUT("[BC] Burn CC Time(%d)\r\n", get_system_time() - u32_fun_time);
  1530. #endif
  1531. return SUCCESS;
  1532. }
  1533. /*Use dongle ext.Flash to read test fw and write to pram*/
  1534. STATUS load_test_fw_3x(void)
  1535. {
  1536. STATUS u8_ret = ERROR;
  1537. #if ENABLE_TEST_TIME_MEASURMENT
  1538. unsigned int u32_fun_time = 0;
  1539. u32_fun_time = get_system_time();
  1540. DEBUGOUT("load_test_fw Start Time= %d\r\n", u32_fun_time);
  1541. #endif
  1542. g_u32_wearable_test_result &= ~(WEARABLE_FT_TEST_RESULT_LOAD_TESTFW_NG);
  1543. if (g_st_test_info.u16_ft_test_info_1 == WEARBLE_FT_LOAD_TEST_FW_SYSTEM_NG_CASE) {
  1544. g_u32_wearable_test_result = WEARABLE_FT_TEST_RESULT_LOAD_TESTFW_NG;
  1545. return ERROR;
  1546. }
  1547. if ((g_st_test_info.u16_ft_test_item & (IC_TEST_ITEMS_OPEN | IC_TEST_ITEMS_SHORT | IC_TEST_ITEMS_UC |
  1548. IC_TEST_ITEMS_UB)) == 0)
  1549. return SUCCESS;
  1550. DEBUGOUT("[LTFW] start load test fw\r\n");
  1551. #if SELFTEST_3X
  1552. u8_ret = raydium_upgrade_test_fw_3x(0);
  1553. #else
  1554. u8_ret = load_test_fw_ft_3x();
  1555. #endif
  1556. DEBUGOUT("[LTFW] Load test fw finish!!\r\n");
  1557. #if ENABLE_TEST_TIME_MEASURMENT
  1558. DEBUGOUT("load_test_fw Spend Time= %d\r\n", get_system_time() - u32_fun_time);
  1559. #endif
  1560. return u8_ret;
  1561. }
  1562. /*
  1563. * STATUS check_ext_flash_fw_version(void)
  1564. * {
  1565. * unsigned int u32_addr, u32_normal_fw_version, u32_test_fw_version;
  1566. * unsigned short u16_data_length = 0;
  1567. * u16_data_length = 4;
  1568. *
  1569. *
  1570. * //get normal FW version from ext flash//
  1571. * u32_addr = FLASH_NORMAL_FW_FW_VERSION_ADDR;
  1572. * if (read_flash_data(u32_addr, u16_data_length) == ERROR) {
  1573. * DEBUGOUT("Read Ext Flash NG [0x%08X] \r\n", u32_addr);
  1574. * return ERROR;
  1575. * }
  1576. * u32_normal_fw_version = 0;
  1577. * u32_normal_fw_version |= g_u8_data_buf[0];
  1578. * u32_normal_fw_version |= g_u8_data_buf[1] << 8;
  1579. * u32_normal_fw_version |= g_u8_data_buf[2] << 16;
  1580. * u32_normal_fw_version |= g_u8_data_buf[3] << 24;
  1581. * //DEBUGOUT("SPI Read_addr = 0x%08X, u16DataLength = %d \r\n", u32_normal_fw_version, u16_data_length);
  1582. */
  1583. /* Test FW Version*/
  1584. u32_addr = FLASH_TEST_FW_FW_VERSION_ADDR;
  1585. if (read_flash_data(u32_addr, u16_data_length) == ERROR) {
  1586. DEBUGOUT("Read Ext Flash NG [0x%08X] \r\n", u32_addr);
  1587. return ERROR;
  1588. }
  1589. u32_test_fw_version = 0;
  1590. u32_test_fw_version |= g_u8_data_buf[0];
  1591. u32_test_fw_version |= g_u8_data_buf[1] << 8;
  1592. u32_test_fw_version |= g_u8_data_buf[2] << 16;
  1593. u32_test_fw_version |= g_u8_data_buf[3] << 24;
  1594. /*DEBUGOUT("SPI Read_addr = 0x%08X, u16DataLength = %d \r\n", u32_test_fw_version, u16_data_length);*/
  1595. if (g_st_test_para_resv.u32_normal_fw_version != u32_normal_fw_version
  1596. || g_st_test_para_resv.u32_test_fw_version != u32_test_fw_version) {
  1597. DEBUGOUT("INI FW Version NG ,0x%08X VS 0x%08X \r\n", g_st_test_para_resv.u32_normal_fw_version, u32_normal_fw_version);
  1598. DEBUGOUT("INI Test FW Version NG ,0x%08X VS 0x%08X \r\n", g_st_test_para_resv.u32_test_fw_version, u32_test_fw_version);
  1599. return ERROR;
  1600. }
  1601. return SUCCESS;
  1602. }
  1603. #endif
  1604. STATUS system_test_3x(void)
  1605. {
  1606. STATUS u8_test_result = SUCCESS;
  1607. unsigned short u16_panel_mode;
  1608. #if ENABLE_TEST_TIME_MEASURMENT
  1609. unsigned int u32_fun_time;
  1610. #endif
  1611. /*Clear Test Item Test result*/
  1612. g_u32_wearable_test_result &= ~(WEARABLE_FT_TEST_RESULT_I2C_NG | WEARABLE_FT_TEST_RESULT_INT_NG
  1613. | WEARABLE_FT_TEST_RESULT_RESET_NG | WEARABLE_FT_TEST_RESULT_PRAM_NG
  1614. | WEARABLE_FT_TEST_RESULT_IC_SUB_VERSION_NG | WEARABLE_FT_TEST_RESULT_IC_FW_VERIFY_NG);
  1615. if ((g_st_test_info.u16_ft_test_item & IC_TEST_ITEMS_SYSTEM) == FALSE)
  1616. return SUCCESS;
  1617. if (enable_ic_block_3x() == ERROR) {
  1618. DEBUGOUT("enable_ic_block NG!!!\r\n");
  1619. /*return ERROR;*/
  1620. }
  1621. stop_mcu_3x(1);
  1622. /*
  1623. * Check Dongle Ext Flash FW/Test FW version PK INI
  1624. *
  1625. * if (check_ext_flash_fw_version() == ERROR) {
  1626. * u8_test_result = ERROR;
  1627. * g_u32_wearable_test_result = WEARABLE_FT_TEST_RESULT_IC_FW_VERIFY_NG;
  1628. * goto ERROR_EXIT;
  1629. * }
  1630. */
  1631. #if ENABLE_TEST_TIME_MEASURMENT
  1632. u32_fun_time = get_system_time();
  1633. #endif
  1634. /*I2C or SPI Test*/
  1635. if (ft_test_connect_test_3x() == ERROR) {
  1636. u8_test_result = ERROR;
  1637. goto ERROR_EXIT;
  1638. }
  1639. #if ENABLE_TEST_TIME_MEASURMENT
  1640. DEBUGOUT("Interface test Spend Time= %d\r\n", get_system_time() - u32_fun_time);
  1641. #endif
  1642. if ((g_st_test_info.u16_ft_eng_item & IC_TEST_ENG_ITEMS_RESV_12)) {
  1643. DEBUGOUT("INI Model = 0x%08X\r\n", g_st_test_para_resv.u32_normal_fw_version);
  1644. u16_panel_mode = (g_st_test_para_resv.u32_normal_fw_version & 0x0000FFFF);
  1645. if (ft_test_panel_model_check_3x(u16_panel_mode) == ERROR) {
  1646. u8_test_result = ERROR;
  1647. g_u32_wearable_test_result = WEARABLE_FT_TEST_RESULT_IC_FW_VERIFY_NG;
  1648. goto ERROR_EXIT;
  1649. }
  1650. }
  1651. #if ENABLE_TEST_TIME_MEASURMENT
  1652. u32_fun_time = get_system_time();
  1653. #endif
  1654. /*INT Pin Test*/
  1655. if (hw_int_pin_Test_3x() == ERROR) {
  1656. u8_test_result = ERROR;
  1657. goto ERROR_EXIT;
  1658. }
  1659. #if ENABLE_TEST_TIME_MEASURMENT
  1660. DEBUGOUT("INT Spend Time= %d\r\n", get_system_time() - u32_fun_time);
  1661. #endif
  1662. #if ENABLE_TEST_TIME_MEASURMENT
  1663. u32_fun_time = get_system_time();
  1664. #endif
  1665. /*
  1666. * RAM Test
  1667. * if (ft_test_ram_test_3x(0) == ERROR) {
  1668. * u8_test_result = ERROR;
  1669. * goto ERROR_EXIT;
  1670. * }
  1671. */
  1672. #if ENABLE_TEST_TIME_MEASURMENT
  1673. DEBUGOUT("RAM Spend Time= %d\r\n", get_system_time() - u32_fun_time);
  1674. #endif
  1675. if ((g_st_test_info.u16_ft_eng_item & IC_TEST_ENG_ITEMS_RESV_11)) {
  1676. if (check_dev_sub_version_3x(g_st_test_para_resv.u8_para_resv_0[21]) == ERROR) {
  1677. u8_test_result = ERROR;
  1678. g_u32_wearable_test_result = WEARABLE_FT_TEST_RESULT_IC_SUB_VERSION_NG;
  1679. goto ERROR_EXIT;
  1680. }
  1681. }
  1682. #if ENABLE_TEST_TIME_MEASURMENT
  1683. u32_fun_time = get_system_time();
  1684. #endif
  1685. /*Reset Pin Test*/
  1686. if (ft_test_reset_pin_test_3x() == ERROR) {
  1687. u8_test_result = ERROR;
  1688. goto ERROR_EXIT;
  1689. }
  1690. #if ENABLE_TEST_TIME_MEASURMENT
  1691. DEBUGOUT("Reset Spend Time= %d\r\n", get_system_time() - u32_fun_time);
  1692. #endif
  1693. ERROR_EXIT:
  1694. if (u8_test_result == ERROR)
  1695. DEBUGOUT("System Test NG!!\r\n");
  1696. else
  1697. DEBUGOUT("System Test PASS\r\n");
  1698. return u8_test_result;
  1699. }
  1700. void do_ic_test_3x(void)
  1701. {
  1702. unsigned short u16_test_items;
  1703. #if ENABLE_TEST_TIME_MEASURMENT
  1704. unsigned char u8_ic_test_state;
  1705. #endif
  1706. #if ENABLE_TEST_TIME_MEASURMENT
  1707. unsigned int u32_fun_time = 0;
  1708. #endif
  1709. unsigned int u32_read_data = 0;
  1710. #if ENABLE_CONTROL_OPENSHORT_WDT
  1711. Chip_WWDT_SetTimeOut(LPC_WWDT, (WDT_OSC / 10) * 150);
  1712. #endif
  1713. g_u32_wearable_test_result &= ~(WEARABLE_FT_TEST_RESULT_POWER_ON_NG | WEARABLE_FT_TEST_RESULT_IC_VERSION_NG
  1714. | WEARABLE_FT_TEST_RESULT_MCU_HOLD_NG | WEARABLE_FT_TEST_RESULT_EXT_FLASH_EMPTY_NG
  1715. | WEARABLE_FT_TEST_RESULT_FLASH_ID_NG | WEARABLE_FT_TEST_RESULT_NORMAL_FW_VER_NG
  1716. | WEARABLE_FT_TEST_RESULT_PANEL_TEST_3_NG | WEARABLE_FT_TEST_RESULT_CB_NG | WEARABLE_FT_TEST_RESULT_TEST_FW_VER_NG
  1717. | WEARABLE_FT_TEST_RESULT_AUO_JIG_NG);
  1718. if (!wearable_ic_test_init()) {
  1719. g_u32_wearable_test_result |= WEARABLE_FT_TEST_RESULT_TEST_INIT_NG;
  1720. g_u8_ic_test_state = IC_TEST_EXIT;
  1721. return;
  1722. }
  1723. test_item_message_3x();
  1724. #if !SELFTEST_3X
  1725. if ((g_st_test_info.u16_ft_eng_item & IC_TEST_ENG_ITEMS_RESV_16)) {
  1726. DEBUGOUT("TEST STATUS= %d\r\n", g_u8_panel_jig_test_status);
  1727. DEBUGOUT("[burn_header_log_to_flash]\r\n");
  1728. if (!b_is_auo_jig_testing) {
  1729. b_is_auo_jig_testing = true;
  1730. g_u8_test_log_burn_times = 0;
  1731. if (!burn_header_log_to_flash_3x(FALSE, FALSE))
  1732. DEBUGOUT("[burn_header_log_to_flash_3x ERROR!]\r\n");
  1733. if (g_u8_test_log_burn_times > 5) {
  1734. if (!burn_header_log_to_flash_3x(FALSE, TRUE))
  1735. DEBUGOUT("[burn_header_log_to_flash_3x ERROR!]\r\n");
  1736. }
  1737. }
  1738. }
  1739. #endif
  1740. if (g_st_test_info.u16_ft_test_item == 0)
  1741. return;
  1742. /*
  1743. * if (g_st_test_info.u8_device_id != 2) {
  1744. * g_u32_wearable_test_result = WEARABLE_FT_TEST_RESULT_IC_VERSION_NG;
  1745. * return;
  1746. * }
  1747. */
  1748. /*handle_display_write(g_u8_display_pattern_sleep_to_active, sizeof(g_u8_display_pattern_sleep_to_active));*/
  1749. handle_ic_read(0x50001100, 4, (unsigned char *)(&u32_read_data), g_u8_drv_interface, I2C_WORD_MODE);
  1750. DEBUGOUT("display mode 0x%x\r\n", u32_read_data);
  1751. g_u8_ic_test_state = IC_TEST_INIT;
  1752. u16_test_items = g_st_test_info.u16_ft_test_item;
  1753. g_u32_wearable_test_result &= ~(WEARABLE_FT_TEST_RESULT_POWER_ON_NG | WEARABLE_FT_TEST_RESULT_IC_VERSION_NG
  1754. | WEARABLE_FT_TEST_RESULT_MCU_HOLD_NG | WEARABLE_FT_TEST_RESULT_EXT_FLASH_EMPTY_NG
  1755. | WEARABLE_FT_TEST_RESULT_FLASH_ID_NG | WEARABLE_FT_TEST_RESULT_NORMAL_FW_VER_NG
  1756. | WEARABLE_FT_TEST_RESULT_PANEL_TEST_3_NG | WEARABLE_FT_TEST_RESULT_CB_NG | WEARABLE_FT_TEST_RESULT_TEST_FW_VER_NG
  1757. | WEARABLE_FT_TEST_RESULT_AUO_JIG_NG);
  1758. while (u16_test_items) {
  1759. #if ENABLE_TEST_TIME_MEASURMENT
  1760. u8_ic_test_state = g_u8_ic_test_state;
  1761. g_u32_spend_time = get_system_time();
  1762. #endif
  1763. switch (g_u8_ic_test_state) {
  1764. case IC_TEST_INIT:
  1765. #if ENABLE_TEST_TIME_MEASURMENT
  1766. u32_fun_time = get_system_time();
  1767. #endif
  1768. g_u8_ic_test_state = IC_TEST_SYSTEM;
  1769. #if ENABLE_TEST_TIME_MEASURMENT
  1770. DEBUGOUT("IC_TEST_INIT Spend Time= %d\r\n", get_system_time() - u32_fun_time);
  1771. #endif
  1772. break;
  1773. case IC_TEST_SYSTEM:
  1774. if (system_test_3x() == SUCCESS ||
  1775. (g_st_test_info.u16_ft_eng_item & IC_TEST_ENG_ITEMS_TEST_ALL)) {
  1776. g_u8_ic_test_state = IC_TEST_BURN_FW;
  1777. } else {
  1778. g_u8_ic_test_state = IC_TEST_EXIT;
  1779. }
  1780. break;
  1781. case IC_TEST_BURN_FW:
  1782. if (burn_fw_3x() == ERROR) {
  1783. g_u32_wearable_test_result = WEARABLE_FT_TEST_RESULT_BURN_FW_NG;
  1784. g_u8_ic_test_state = IC_TEST_EXIT;
  1785. } else {
  1786. g_u8_ic_test_state = IC_TEST_LOAD_TEST_FW;
  1787. }
  1788. break;
  1789. case IC_TEST_LOAD_TEST_FW:
  1790. if (load_test_fw_3x() == ERROR) {
  1791. DEBUGOUT("Load Test FW NG!!\r\n");
  1792. g_u32_wearable_test_result = WEARABLE_FT_TEST_RESULT_LOAD_TESTFW_NG;
  1793. g_u8_ic_test_state = IC_TEST_EXIT;
  1794. } else {
  1795. g_u8_ic_test_state = IC_TEST_ENTER_FW_TEST_MODE;
  1796. }
  1797. break;
  1798. case IC_TEST_ENTER_FW_TEST_MODE:
  1799. if (enter_fw_test_mode_3x() == ERROR) {
  1800. DEBUGOUT("Enter FW Test Mode NG!!\r\n");
  1801. g_u8_ic_test_state = IC_TEST_EXIT;
  1802. } else {
  1803. g_u8_ic_test_state = IC_TEST_OPEN_SHORT;
  1804. }
  1805. break;
  1806. case IC_TEST_OPEN_SHORT:
  1807. if (ft_test_do_fw_test_3x(u16_test_items) == SUCCESS) {
  1808. DEBUGOUT("FW Test Finish! \r\n");
  1809. g_u8_ic_test_state = IC_TEST_READ_TEST_FW_DATA;
  1810. } else {
  1811. DEBUGOUT("FW Test NG!!\r\n");
  1812. g_u32_wearable_test_result = WEARABLE_FT_TEST_RESULT_TEST_INIT_NG;
  1813. g_u8_ic_test_state = IC_TEST_EXIT;
  1814. }
  1815. break;
  1816. case IC_TEST_READ_TEST_FW_DATA:
  1817. if (read_test_fw_data_3x(u16_test_items) == SUCCESS) {
  1818. g_u8_ic_test_state = IC_TEST_BURN_CC;
  1819. } else {
  1820. DEBUGOUT("Read Test FW Data NG!!\r\n");
  1821. g_u8_ic_test_state = IC_TEST_EXIT;
  1822. }
  1823. break;
  1824. case IC_TEST_BURN_CC:
  1825. if (burn_cc_3x(u16_test_items) == ERROR) {
  1826. DEBUGOUT("Burn CC NG!!\r\n");
  1827. g_u32_wearable_test_result |= WEARABLE_FT_TEST_RESULT_BURN_CC_NG;
  1828. g_u8_ic_test_state = IC_TEST_PANEL_PATTERN_TEST;
  1829. } else {
  1830. g_u8_ic_test_state = IC_TEST_PANEL_PATTERN_TEST;
  1831. }
  1832. break;
  1833. case IC_TEST_PANEL_PATTERN_TEST:
  1834. #if ENABLE_TEST_GPIO_MEASURMENT
  1835. Chip_GPIO_SetPinOutHigh(LPC_GPIO, DONGLE_GPIO_PORT_1, DONGLE_GPIO_PIN_10);
  1836. delay_ms(1);
  1837. Chip_GPIO_SetPinOutLow(LPC_GPIO, DONGLE_GPIO_PORT_1, DONGLE_GPIO_PIN_10);
  1838. #endif
  1839. DEBUGOUT("B g_u32_wearable_test_result = 0x%08x\r\n", g_u32_wearable_test_result);
  1840. #if !SELFTEST_3X
  1841. do_ic_panel_test_3x();
  1842. #endif
  1843. g_u8_ic_test_state = IC_TEST_EXIT;
  1844. break;
  1845. case IC_TEST_EXIT:
  1846. #if ENABLE_TEST_TIME_MEASURMENT
  1847. u32_fun_time = get_system_time();
  1848. DEBUGOUT("Final action Start Time= %d\r\n", u32_fun_time);
  1849. #endif
  1850. DEBUGOUT("g_u32_wearable_test_result = 0x%08x\r\n", g_u32_wearable_test_result);
  1851. DEBUGOUT("Exit IC Test!\r\n");
  1852. #if !SELFTEST_3X
  1853. gpio_touch_int_trigger_control(FALSE);
  1854. #endif
  1855. g_u8_ic_test_state = IC_TEST_INIT;
  1856. if ((g_st_test_info.u16_ft_test_item & (IC_TEST_ITEMS_OPEN | IC_TEST_ITEMS_SHORT)) == 0) {
  1857. ft_raw_data_checksum_cal_3x((unsigned short *)g_i16_raw_data_1_short_buf);
  1858. ft_raw_data_checksum_cal_3x((unsigned short *)g_i16_raw_data_2_open_buf);
  1859. ft_raw_data_checksum_cal_3x(g_u16_raw_data3_cc_buf);
  1860. }
  1861. ft_raw_data_checksum_cal_3x(g_u16_uc_buf);
  1862. ft_raw_data_checksum_cal_3x((unsigned short *)g_u16_raw_data3_golden_cc_buf);
  1863. ft_raw_data_checksum_cal_3x((unsigned short *)g_u16_uc_golden_cc_buf);
  1864. ft_test_result_checksum_cal_3x(g_u8_test_result);
  1865. #if !SELFTEST_3X
  1866. DEBUGOUT("g_u8_panel_jig_test_status= %d\r\n", g_u8_panel_jig_test_status);
  1867. 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)) {
  1868. b_is_auo_jig_testing = false;
  1869. burn_header_log_to_flash_3x(TRUE, TRUE);
  1870. memset(g_u32_save_config, 0, sizeof(g_u32_save_config));
  1871. if (!burn_data_log_to_flash_3x())
  1872. DEBUGOUT("[burn_log_to_flash ERROR!]\r\n");
  1873. }
  1874. #endif
  1875. /*
  1876. * 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)) {
  1877. * if (!burn_log_to_flash_3x())
  1878. * DEBUGOUT("[burn_log_to_flash ERROR!]\r\n");
  1879. * }
  1880. */
  1881. #if ENABLE_CONTROL_OPENSHORT_WDT
  1882. /*Chip_WWDT_SetTimeOut(LPC_WWDT, (WDT_OSC / 10) * 50);*/
  1883. #endif
  1884. u16_test_items = 0;
  1885. #if ENABLE_TEST_TIME_MEASURMENT
  1886. DEBUGOUT("Final action Spend Time= %d\r\n", get_system_time() - u32_fun_time);
  1887. #endif
  1888. break;
  1889. }
  1890. #if !SELFTEST_3X
  1891. update_dongle_test_status(g_u8_ic_test_state);
  1892. #endif
  1893. #if ENABLE_WDT
  1894. /* reload the Watchdog timer*/
  1895. Chip_WWDT_Feed(LPC_WWDT);
  1896. #endif
  1897. #if !SELFTEST_3X
  1898. if (g_u8_ic_power_on_ng) {
  1899. g_u32_wearable_test_result |= WEARABLE_FT_TEST_RESULT_POWER_ON_NG;
  1900. g_u8_ic_test_state = IC_TEST_EXIT;
  1901. }
  1902. #endif
  1903. #if ENABLE_TEST_TIME_MEASURMENT
  1904. DEBUGOUT("Test Item [%d] End (%d)\r\n", u8_ic_test_state, get_system_time() - g_u32_spend_time);
  1905. #endif
  1906. } /*while(u16_test_items)*/
  1907. }