app_chargerpin_conn_detect.c.bak 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  1. #include "app_chargerpin_conn_detect.h"
  2. #include "system.h"
  3. #include "bsp_time.h"
  4. #include "bsp_adc.h"
  5. #include "ble_comm.h"
  6. #include "hal_led.h"
  7. #include "hal_mt.h"
  8. #include "app_flash.h"
  9. #include "app_pair_chargerpin.h"
  10. #include "app_one_wire.h"
  11. #include "fml_adc.h"
  12. #define SHELF_CHECK_ADC_VALUE 1800
  13. //=================debug=============
  14. #include "ringframe.h"
  15. extern char logbuftemp[50];
  16. extern int logbuftemp_len ;
  17. extern ringframe_t battlog;
  18. #define log(...) {logbuftemp_len = sprintf(logbuftemp,__VA_ARGS__); while(ringframe_in(&battlog,logbuftemp,logbuftemp_len)!=0){ringframe_throw(&battlog);}}
  19. //void cb_BLE_Client_PRADC(void* handle)
  20. //{
  21. //// BLE_Client_Rx_t* target = handle;
  22. // DEBUG_LOG("cb_BLE_Client_ERR:%d,%d\n", 1, 1);
  23. // BLE_Client_Rx_Regist(BLE_ERR, cb_BLE_Client_ERR);
  24. //}
  25. //=================debug=============
  26. extern void app_pair_client_process_case1(void);
  27. extern void app_pair_client_process(void);
  28. struct client_ram_type{
  29. char init;
  30. char statu;
  31. short adc_value;
  32. pair_line_t pair_line;
  33. unsigned int delay_pair_count;
  34. Event into_event;
  35. Event over_event;
  36. }client_ram;
  37. struct{
  38. char init;
  39. char statu;
  40. unsigned int pulluppcs_timer;
  41. short adc_value;
  42. pair_line_t pair_line;
  43. unsigned int delay_pair_count;
  44. Event into_event;
  45. Event over_event;
  46. }host_ram;
  47. extern void app_pair_host_process(void);
  48. extern void app_pair_host_process_case1(void);
  49. extern void app_pair_host_process_case2(void);
  50. void fml_adc_callback(uint32_t sample_point, Fml_Adc_All_Channel_Adc_Value_t all_adc_value)
  51. {
  52. #if 1
  53. switch(sample_point)
  54. {
  55. case FML_ADC_SAMPLE_POINT_0:
  56. case FML_ADC_SAMPLE_POINT_2:
  57. //PAIR_CHARGERPIN_PRINT("FML_ADC_SAMPLE_POINT_2 NULL %d\n",all_adc_value.channel_4_adc_value);
  58. if(host_ram.init)
  59. {
  60. if(host_ram.statu == 1)
  61. {
  62. host_ram.adc_value=all_adc_value.channel_4_adc_value;
  63. app_pair_host_process_case1();
  64. }
  65. }
  66. if(client_ram.init)
  67. {
  68. if(client_ram.statu == 1)
  69. {
  70. client_ram.adc_value=all_adc_value.channel_4_adc_value;
  71. app_pair_client_process_case1();
  72. }
  73. }
  74. break;
  75. case FML_ADC_SAMPLE_POINT_1:
  76. //PAIR_CHARGERPIN_PRINT("FML_ADC_SAMPLE_POINT_1 NULL %d\n",all_adc_value.channel_4_adc_value);
  77. if(host_ram.init)
  78. {
  79. if(host_ram.statu == 2)
  80. {
  81. host_ram.adc_value=all_adc_value.channel_4_adc_value;
  82. app_pair_host_process_case2();
  83. }
  84. }
  85. break;
  86. }
  87. #else
  88. static char asjdhaskjhdki=0;
  89. PAIR_CHARGERPIN_PRINT("ADC_Read fml_adc_callback %d\n", all_adc_value.channel_4_adc_value);
  90. if(asjdhaskjhdki%2==0)fml_adc_set_pin_channel(PIN_CHARGING, PIN_CHARGING_CHANNEL, NRF_GPIO_PIN_PULLUP);
  91. else fml_adc_set_pin_channel(PIN_CHARGING, PIN_CHARGING_CHANNEL, NRF_GPIO_PIN_NOPULL);
  92. asjdhaskjhdki++;
  93. #endif
  94. }
  95. //====================================================================================
  96. #define ADC_CHECKMS 1000
  97. #define PAIROVERTIME 3000
  98. #define DELAY_PAIR_COUNT 100
  99. void app_pair_host_init(Event into,Event over)
  100. {
  101. host_ram.init=1;
  102. host_ram.adc_value=0;
  103. host_ram.delay_pair_count=0;
  104. host_ram.pulluppcs_timer=0;
  105. host_ram.statu=0;
  106. host_ram.pair_line=DISCONNECT_CHARGE;
  107. host_ram.into_event=into;
  108. host_ram.over_event=over;
  109. fml_adc_sample_update_notify_register(fml_adc_callback);
  110. Process_Start(ADC_CHECKMS, "app_pair_host_process", app_pair_host_process);
  111. }
  112. void app_pair_host_uninit(void)
  113. {
  114. host_ram.init=0;
  115. Process_Stop(app_pair_host_process);
  116. }
  117. #define DISCON_HOST_MAX_ADC 1200
  118. //#define DISCON_HOST_MIN_ADC 600
  119. #define DISCON_HOST_MIN_ADC 1000
  120. #define CON_HOST_MAX_ADC DISCON_HOST_MIN_ADC
  121. #define CON_HOST_MIN_ADC 300
  122. static void null_pcs(void)
  123. {
  124. }
  125. #define UPPULL_MS 3
  126. //-------------------------------------------
  127. unsigned char shefcheck_buff[5];
  128. char shefcheck_event_fag=0;
  129. check_callbackt check_callbackt_ram;
  130. Event check_callback_find_hi_ram;
  131. void shefcheck_event(unsigned char *buff, int length)
  132. {
  133. shefcheck_event_fag=1;
  134. }
  135. char one_byte_receive_error_code=0;
  136. void one_byte_receive_Event_err_hander(unsigned char error_code)
  137. {
  138. one_byte_receive_error_code=1;
  139. }
  140. void check_callback_regist(check_callbackt evt)
  141. {
  142. check_callbackt_ram=evt;
  143. }
  144. void check_callback_find_hi_regist(Event evt)
  145. {
  146. check_callback_find_hi_ram=evt;
  147. }
  148. //-------------------------------------------
  149. void app_pair_host_process_case1(void)
  150. {
  151. if(mFlash.isHost!=HOST_SHOSE)
  152. {
  153. app_pair_host_uninit();
  154. app_pair_chargerpin_Init();
  155. PAIR_CHARGERPIN_PRINT("mFlash.isHost change %d %d\n",TIME_GetTicks(),mFlash.isHost );
  156. }
  157. //==============================s
  158. if(host_ram.adc_value>DISCON_HOST_MAX_ADC)
  159. {
  160. PAIR_CHARGERPIN_PRINT("CHARGE\n");
  161. if(host_ram.pair_line!=CHARGE)
  162. {
  163. PAIR_CHARGERPIN_INFO("INTO CHARGE %d\n", mFlash.isHost);
  164. host_ram.pair_line=CHARGE;
  165. }
  166. host_ram.statu=1;
  167. }
  168. PAIR_CHARGERPIN_PRINT("ADC f( %d ):isHost %d Ticks %d\n", host_ram.adc_value, mFlash.isHost,TIME_GetTicks());
  169. if(host_ram.adc_value>SHELF_CHECK_ADC_VALUE)
  170. {
  171. PAIR_CHARGERPIN_PRINT("------------check_callback_find_hi_ram-----check_callbackt_ram---------%d %d\n", mFlash.isHost, TIME_GetTicks());
  172. if(check_callbackt_ram)
  173. {
  174. host_ram.statu=11;
  175. host_ram.delay_pair_count=TIME_GetTicks();
  176. Process_UpdatePeroid(app_pair_host_process,100);
  177. Process_SetHoldOn(app_pair_host_process,1);
  178. one_byte_receive_init(shefcheck_buff,2,shefcheck_event);
  179. shefcheck_event_fag=0;
  180. one_byte_receive_Event_err_register(one_byte_receive_Event_err_hander);
  181. one_byte_receive_error_code=0;
  182. fml_adc_remove_pin_channel(PIN_CHARGING, PIN_CHARGING_CHANNEL);
  183. if(check_callback_find_hi_ram)check_callback_find_hi_ram();
  184. PAIR_CHARGERPIN_INFO("INTO SHELF_CHECK_ADC_VALUE %d\n", mFlash.isHost);
  185. PAIR_CHARGERPIN_PRINT("------------check_callback_find_hi_ram--------------%d %d\n", mFlash.isHost, TIME_GetTicks());
  186. return;
  187. }
  188. else
  189. {
  190. PAIR_CHARGERPIN_PRINT("check_callbackt_ram NULL\n");
  191. }
  192. }
  193. //==============================e
  194. fml_adc_set_pin_channel(PIN_CHARGING, PIN_CHARGING_CHANNEL, NRF_GPIO_PIN_PULLUP);
  195. PAIR_CHARGERPIN_PRINT("nrf_gpio_cfg_input(PIN_CHARGING, NRF_GPIO_PIN_PULLUP); %d \n",TIME_GetTicks() );
  196. host_ram.pulluppcs_timer = TIME_GetTicks();
  197. Process_Start(0, "null_pcs", null_pcs);
  198. Process_SetHoldOn(null_pcs, 1);
  199. host_ram.statu = 2;
  200. }
  201. void app_pair_host_process_case2(void)
  202. {
  203. fml_adc_set_pin_channel(PIN_CHARGING, PIN_CHARGING_CHANNEL, NRF_GPIO_PIN_NOPULL);
  204. Process_Stop(null_pcs);
  205. log("ad:%d,%d\n",host_ram.adc_value, host_ram.pair_line);
  206. PAIR_CHARGERPIN_PRINT("ADC ( %d ): pair_line %d\n", host_ram.adc_value, host_ram.pair_line);
  207. if(host_ram.adc_value>DISCON_HOST_MIN_ADC)
  208. {
  209. PAIR_CHARGERPIN_PRINT("DISCONNECT_CHARGE\n");
  210. if(host_ram.pair_line!=DISCONNECT_CHARGE)
  211. {
  212. PAIR_CHARGERPIN_INFO("INTO DISCONNECT_CHARGE %d\n", mFlash.isHost);
  213. host_ram.pair_line=DISCONNECT_CHARGE;
  214. }
  215. host_ram.statu=1;
  216. }
  217. else if(host_ram.adc_value>CON_HOST_MIN_ADC)
  218. {
  219. PAIR_CHARGERPIN_PRINT("CONNECT_NO_CHARGE\n");
  220. if(host_ram.pair_line!=CONNECT_NO_CHARGE)
  221. {
  222. host_ram.pair_line=CONNECT_NO_CHARGE;
  223. fml_adc_set_pin_channel(PIN_CHARGING, PIN_CHARGING_CHANNEL, NRF_GPIO_PIN_PULLUP);
  224. host_ram.delay_pair_count=TIME_GetTicks();
  225. Process_UpdatePeroid(app_pair_host_process,1);
  226. Process_SetHoldOn(app_pair_host_process,1);
  227. fml_adc_remove_pin_channel(PIN_CHARGING, PIN_CHARGING_CHANNEL);
  228. host_ram.statu=3;
  229. PAIR_CHARGERPIN_INFO("INTO CONNECT_NO_CHARGE %d\n", mFlash.isHost);
  230. }
  231. else
  232. {
  233. host_ram.statu=1;
  234. }
  235. }
  236. else
  237. {
  238. PAIR_CHARGERPIN_PRINT("ADCVALUE ======================================================ERROR %d\n", host_ram.adc_value);
  239. host_ram.statu=1;
  240. }
  241. }
  242. char host_into_fig_status=0;
  243. void host_into_fig(void *t)
  244. {
  245. static short count=0;
  246. static unsigned int bit_width = 0;
  247. static unsigned int now_bit = 0;
  248. switch(host_into_fig_status)
  249. {
  250. case 0:
  251. count=0;
  252. nrf_gpio_cfg(
  253. PIN_CHARGING,
  254. NRF_GPIO_PIN_DIR_OUTPUT,
  255. NRF_GPIO_PIN_INPUT_CONNECT,
  256. NRF_GPIO_PIN_NOPULL,
  257. NRF_GPIO_PIN_D0H1,
  258. NRF_GPIO_PIN_NOSENSE);
  259. nrf_gpio_cfg_watcher(PIN_CHARGING);
  260. host_into_fig_status = 1;
  261. nrf_gpio_pin_clear(PIN_CHARGING);
  262. break;
  263. case 1:
  264. count++;
  265. if(count>50)
  266. {
  267. host_into_fig_status = 2;
  268. nrf_gpio_pin_set(PIN_CHARGING);
  269. count=0;
  270. }
  271. break;
  272. case 2:
  273. count++;
  274. if(count>50)
  275. {
  276. host_into_fig_status = 20;
  277. nrf_gpio_pin_clear(PIN_CHARGING);
  278. TIME_UnRegist(host_into_fig);
  279. }
  280. break;
  281. case 10:
  282. count=0;
  283. nrf_gpio_cfg(
  284. PIN_CHARGING,
  285. NRF_GPIO_PIN_DIR_OUTPUT,
  286. NRF_GPIO_PIN_INPUT_CONNECT,
  287. NRF_GPIO_PIN_NOPULL,
  288. NRF_GPIO_PIN_D0H1,
  289. NRF_GPIO_PIN_NOSENSE);
  290. nrf_gpio_cfg_watcher(PIN_CHARGING);
  291. host_into_fig_status = 11;
  292. bit_width=0;
  293. nrf_gpio_pin_clear(PIN_CHARGING);
  294. now_bit = nrf_gpio_pin_read(PIN_CHARGING);
  295. break;
  296. case 11:
  297. if (now_bit == nrf_gpio_pin_read(PIN_CHARGING))
  298. {
  299. bit_width++;
  300. }
  301. else
  302. {
  303. if(now_bit==0)//上升
  304. {
  305. now_bit=1;
  306. }
  307. else//下降
  308. {
  309. now_bit=0;
  310. if((bit_width>48)&&(bit_width<60))
  311. {
  312. host_into_fig_status = 20;
  313. TIME_UnRegist(host_into_fig);
  314. }
  315. }
  316. bit_width=0;
  317. }
  318. count++;
  319. if(count>220)
  320. {
  321. host_into_fig_status = 30;
  322. TIME_UnRegist(host_into_fig);
  323. }
  324. break;
  325. }
  326. }
  327. void send_host_into_fig(void)
  328. {
  329. TIME_Regist(host_into_fig);
  330. host_into_fig_status=0;
  331. }
  332. char host_into_fig_senddone(void)
  333. {
  334. if(host_into_fig_status==20)return 1;
  335. else return 0;
  336. }
  337. char host_into_fig_receivedone(void)
  338. {
  339. if(host_into_fig_status==20)return 1;
  340. if(host_into_fig_status==30)return 2;
  341. else return 0;
  342. }
  343. void receive_host_into_fig(void)
  344. {
  345. TIME_Regist(host_into_fig);
  346. host_into_fig_status=10;
  347. }
  348. static void app_pair_host_process(void)
  349. {
  350. for(int i=1;i>0;i--)
  351. {
  352. switch(host_ram.statu)
  353. {
  354. case 0:
  355. fml_adc_set_pin_channel(PIN_CHARGING, PIN_CHARGING_CHANNEL, NRF_GPIO_PIN_NOPULL);
  356. host_ram.statu=1;
  357. break;
  358. case 1:
  359. break;
  360. case 2:
  361. break;
  362. case 3://
  363. if ((TIME_GetTicks() - host_ram.delay_pair_count > ADC_CHECKMS+ADC_CHECKMS))
  364. {
  365. PAIR_CHARGERPIN_PRINT(" UP pull over time %d \n", TIME_GetTicks());
  366. log("pull over time\n");
  367. nrf_gpio_cfg_input(PIN_CHARGING, NRF_GPIO_PIN_NOPULL);
  368. Process_UpdatePeroid(app_pair_host_process,ADC_CHECKMS);
  369. Process_SetHoldOn(app_pair_host_process,0);
  370. host_ram.statu=1;
  371. }
  372. else if(nrf_gpio_pin_read(PIN_CHARGING))//?áμ?é?à-D?o?ò?oó£??μ?÷clientò??-á??óé?
  373. {
  374. PAIR_CHARGERPIN_PRINT(" nrf_gpio_pin_read(PIN_CHARGING SUCCESS \n", TIME_GetTicks());
  375. host_ram.statu=4;
  376. host_ram.delay_pair_count=TIME_GetTicks();
  377. nrf_gpio_cfg_input(PIN_CHARGING, NRF_GPIO_PIN_NOPULL);
  378. }
  379. break;
  380. case 4:
  381. if(nrf_gpio_pin_read(PIN_CHARGING)==0)
  382. {
  383. host_ram.statu=5;
  384. host_ram.delay_pair_count=TIME_GetTicks();
  385. fml_adc_remove_pin_channel(PIN_CHARGING, PIN_CHARGING_CHANNEL);
  386. send_host_into_fig();
  387. }
  388. else if(TIME_GetTicks() - host_ram.delay_pair_count > 500)
  389. {
  390. PAIR_CHARGERPIN_PRINT(" wait low over time %d\n", nrf_gpio_pin_read(PIN_CHARGING));
  391. host_ram.statu=0;
  392. Process_UpdatePeroid(app_pair_host_process,ADC_CHECKMS);
  393. Process_SetHoldOn(app_pair_host_process,0);
  394. i=3;
  395. }
  396. break;
  397. case 5:
  398. if(host_into_fig_senddone())
  399. {
  400. host_ram.statu=6;
  401. host_ram.into_event();
  402. PAIR_CHARGERPIN_PRINT(" into_event %d \n", TIME_GetTicks());
  403. host_ram.delay_pair_count=TIME_GetTicks();
  404. }
  405. break;
  406. case 6:
  407. if (TIME_GetTicks() - host_ram.delay_pair_count > PAIROVERTIME)
  408. {
  409. PAIR_CHARGERPIN_PRINT(" over_event %d\n", TIME_GetTicks());
  410. host_ram.statu=0;
  411. host_ram.over_event();
  412. Process_UpdatePeroid(app_pair_host_process,ADC_CHECKMS);
  413. Process_SetHoldOn(app_pair_host_process,0);
  414. i=3;
  415. }
  416. break;
  417. //==============================s
  418. case 11:
  419. if((TIME_GetTicks() - host_ram.delay_pair_count > 5000)||(shefcheck_event_fag)||(one_byte_receive_error_code==1))
  420. {
  421. if(shefcheck_event_fag)
  422. {
  423. if(check_callbackt_ram)
  424. {
  425. check_callbackt_ram(shefcheck_buff[0]);
  426. PAIR_CHARGERPIN_INFO("check_callbackt_ram(shefcheck_buff[0]); %d\n", shefcheck_buff[0]);
  427. }
  428. }
  429. else
  430. {
  431. PAIR_CHARGERPIN_PRINT(" =====================wait low over time %d\n", nrf_gpio_pin_read(PIN_CHARGING));
  432. }
  433. if(one_byte_receive_error_code==1)
  434. {
  435. one_byte_receive_error_code=0;
  436. PAIR_CHARGERPIN_INFO("EXTI SHELF_CHECK_ADC_VALUE %d one_byte_receive_error_code\n", mFlash.isHost);
  437. }
  438. host_ram.statu=0;
  439. Process_UpdatePeroid(app_pair_host_process,ADC_CHECKMS);
  440. Process_SetHoldOn(app_pair_host_process,0);
  441. one_byte_receive_uninit();
  442. PAIR_CHARGERPIN_INFO("EXTI SHELF_CHECK_ADC_VALUE %d %d\n", mFlash.isHost,one_byte_receive_error_code);
  443. i=3;
  444. }
  445. break;
  446. //==============================s
  447. }
  448. }
  449. }
  450. //============================================================================================================
  451. #define CONN_MAX_ADC 1000
  452. #define CONN_MIN_ADC 750
  453. void app_pair_client_init(Event into,Event over)
  454. {
  455. client_ram.init=1;
  456. client_ram.adc_value=0;
  457. client_ram.delay_pair_count=0;
  458. client_ram.statu=0;
  459. client_ram.pair_line=DISCONNECT_CHARGE;
  460. client_ram.into_event=into;
  461. client_ram.over_event=over;
  462. fml_adc_sample_update_notify_register(fml_adc_callback);
  463. Process_Start(ADC_CHECKMS, "app_pair_client_process", app_pair_client_process);
  464. }
  465. void app_pair_client_uninit(void)
  466. {
  467. client_ram.init=0;
  468. Process_Stop(app_pair_client_process);
  469. }
  470. void app_pair_client_process_case1(void)
  471. {
  472. if(mFlash.isHost==HOST_SHOSE)
  473. {
  474. app_pair_client_uninit();
  475. app_pair_chargerpin_Init();
  476. PAIR_CHARGERPIN_PRINT("mFlash.isHost change %d %d\n",TIME_GetTicks(),mFlash.isHost );
  477. }
  478. log("ad:%d,%d\n",client_ram.adc_value, client_ram.pair_line);
  479. PAIR_CHARGERPIN_PRINT("ADC ( %d ):isHost %d Ticks %d\n", client_ram.adc_value, mFlash.isHost,TIME_GetTicks());
  480. if(client_ram.adc_value>CONN_MAX_ADC)
  481. {
  482. PAIR_CHARGERPIN_PRINT("CHARGE\n");
  483. if(client_ram.pair_line!=CHARGE)
  484. {
  485. PAIR_CHARGERPIN_INFO("INTO CHARGE %d\n", mFlash.isHost);
  486. client_ram.pair_line=CHARGE;
  487. }
  488. }
  489. else if((client_ram.adc_value>CONN_MIN_ADC)&&(client_ram.adc_value<CONN_MIN_ADC+100))
  490. {
  491. PAIR_CHARGERPIN_PRINT("CONNECT_NO_CHARGE\n");
  492. if(client_ram.pair_line!=CONNECT_NO_CHARGE)
  493. {
  494. PAIR_CHARGERPIN_INFO("INTO CONNECT_NO_CHARGE %d %d\n", mFlash.isHost,client_ram.adc_value);
  495. client_ram.pair_line=CONNECT_NO_CHARGE;
  496. fml_adc_remove_pin_channel(PIN_CHARGING, PIN_CHARGING_CHANNEL);
  497. nrf_gpio_cfg(
  498. PIN_CHARGING,
  499. NRF_GPIO_PIN_DIR_OUTPUT,
  500. NRF_GPIO_PIN_INPUT_CONNECT,
  501. NRF_GPIO_PIN_NOPULL,
  502. NRF_GPIO_PIN_D0H1,
  503. NRF_GPIO_PIN_NOSENSE);
  504. nrf_gpio_cfg_watcher(PIN_CHARGING);
  505. nrf_gpio_pin_set(PIN_CHARGING);//à-??100ms
  506. client_ram.delay_pair_count=TIME_GetTicks();
  507. Process_UpdatePeroid(app_pair_client_process,1);
  508. Process_SetHoldOn(app_pair_client_process,1);
  509. client_ram.statu=2;
  510. }
  511. }
  512. else
  513. {
  514. if(client_ram.pair_line!=DISCONNECT_CHARGE)
  515. {
  516. PAIR_CHARGERPIN_INFO("INTO DISCONNECT_CHARGE %d\n", mFlash.isHost);
  517. client_ram.pair_line=DISCONNECT_CHARGE;
  518. }
  519. }
  520. //==============================s
  521. if(client_ram.adc_value>SHELF_CHECK_ADC_VALUE)
  522. {
  523. if(check_callbackt_ram)
  524. {
  525. client_ram.statu=11;
  526. client_ram.delay_pair_count=TIME_GetTicks();
  527. Process_UpdatePeroid(app_pair_client_process,100);
  528. Process_SetHoldOn(app_pair_client_process,1);
  529. one_byte_receive_init(shefcheck_buff,2,shefcheck_event);
  530. shefcheck_event_fag=0;
  531. one_byte_receive_Event_err_register(one_byte_receive_Event_err_hander);
  532. one_byte_receive_error_code=0;
  533. fml_adc_remove_pin_channel(PIN_CHARGING, PIN_CHARGING_CHANNEL);
  534. PAIR_CHARGERPIN_INFO("INTO SHELF_CHECK_ADC_VALUE %d\n", 1);
  535. if(check_callback_find_hi_ram)
  536. {
  537. check_callback_find_hi_ram();
  538. }
  539. return;
  540. }
  541. else
  542. {
  543. PAIR_CHARGERPIN_PRINT("check_callbackt_ram NULL\n");
  544. }
  545. }
  546. //==============================e
  547. }
  548. static void app_pair_client_process(void)
  549. {
  550. for(int i=1;i>0;i--)
  551. {
  552. switch(client_ram.statu)
  553. {
  554. case 0:
  555. fml_adc_set_pin_channel(PIN_CHARGING, PIN_CHARGING_CHANNEL, NRF_GPIO_PIN_NOPULL);
  556. client_ram.statu=1;
  557. break;
  558. case 1:
  559. break;
  560. case 2:
  561. if(TIME_GetTicks() - client_ram.delay_pair_count > 100)//μè100ms
  562. {
  563. nrf_gpio_pin_clear(PIN_CHARGING);
  564. client_ram.statu=3;
  565. client_ram.delay_pair_count=TIME_GetTicks();
  566. }
  567. break;
  568. case 3:
  569. if(nrf_gpio_pin_read(PIN_CHARGING)==0)
  570. {
  571. receive_host_into_fig();
  572. client_ram.statu=4;
  573. }
  574. else if(TIME_GetTicks() - client_ram.delay_pair_count > 100)
  575. {
  576. PAIR_CHARGERPIN_PRINT(" wait low over time1 %d\n", nrf_gpio_pin_read(PIN_CHARGING));
  577. client_ram.statu=0;
  578. Process_UpdatePeroid(app_pair_client_process,ADC_CHECKMS);
  579. Process_SetHoldOn(app_pair_client_process,0);
  580. i=3;
  581. }
  582. break;
  583. case 4:
  584. if(host_into_fig_receivedone()==1)
  585. {
  586. client_ram.into_event();
  587. client_ram.delay_pair_count=TIME_GetTicks();
  588. PAIR_CHARGERPIN_PRINT(" into_event-C %d\n", TIME_GetTicks());
  589. client_ram.statu=5;
  590. }
  591. else if(host_into_fig_receivedone()==2)
  592. {
  593. PAIR_CHARGERPIN_PRINT(" wait low over time %d\n", nrf_gpio_pin_read(PIN_CHARGING));
  594. client_ram.statu=0;
  595. Process_UpdatePeroid(app_pair_client_process,ADC_CHECKMS);
  596. Process_SetHoldOn(app_pair_client_process,0);
  597. i=3;
  598. }
  599. break;
  600. case 5:
  601. if (TIME_GetTicks() - client_ram.delay_pair_count > PAIROVERTIME)
  602. {
  603. client_ram.statu=0;
  604. client_ram.over_event();
  605. Process_UpdatePeroid(app_pair_client_process,ADC_CHECKMS);
  606. Process_SetHoldOn(app_pair_client_process,0);
  607. PAIR_CHARGERPIN_PRINT(" over_event %d\n", TIME_GetTicks());
  608. i=3;
  609. }
  610. break;
  611. //==============================s
  612. case 11:
  613. if((TIME_GetTicks() - client_ram.delay_pair_count > 5000)||(shefcheck_event_fag)||(one_byte_receive_error_code==1))
  614. {
  615. if(shefcheck_event_fag)
  616. {
  617. if(check_callbackt_ram)
  618. {
  619. check_callbackt_ram(shefcheck_buff[0]);
  620. PAIR_CHARGERPIN_INFO("check_callbackt_ram(shefcheck_buff[0]); %d\n", shefcheck_buff[0]);
  621. }
  622. }
  623. else
  624. {
  625. PAIR_CHARGERPIN_PRINT(" =====================wait low over time %d\n", nrf_gpio_pin_read(PIN_CHARGING));
  626. }
  627. if(one_byte_receive_error_code==1)
  628. {
  629. one_byte_receive_error_code=0;
  630. PAIR_CHARGERPIN_INFO("EXTI SHELF_CHECK_ADC_VALUE %d one_byte_receive_error_code\n", mFlash.isHost);
  631. }
  632. client_ram.statu=0;
  633. Process_UpdatePeroid(app_pair_client_process,ADC_CHECKMS);
  634. Process_SetHoldOn(app_pair_client_process,0);
  635. one_byte_receive_uninit();
  636. PAIR_CHARGERPIN_INFO("EXTI SHELF_CHECK_ADC_VALUE %d %d\n", mFlash.isHost,one_byte_receive_error_code );
  637. i=3;
  638. }
  639. break;
  640. //==============================s
  641. }
  642. }
  643. }
  644. pair_line_t app_chargepin_pairline(void)
  645. {
  646. if (host_ram.init)
  647. {
  648. return host_ram.pair_line;
  649. }
  650. if (client_ram.init)
  651. {
  652. return client_ram.pair_line;
  653. }
  654. return NUL;
  655. }