app_chargerpin_conn_detect.c 19 KB

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