123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- #include "drv_trigger.h"
- #include "bsp_time.h"
- #include "selfcheck.h"
- static volatile uint32_t trg = 0;
- static uint16_t dat = 0;
- static uint8_t dat_dex = 15;
- void drv_TrigNBit(uint8_t cnt,uint8_t flag)
- {
- int16_t _cnt = cnt-10;
- while(_cnt>0){
- _cnt = _cnt-30;
- if(flag>0){
- dat |= (0x0001<<dat_dex);
- }else{
- dat &= ~(0x0001<<dat_dex);
- }
- if(dat_dex>0) dat_dex--;
- }
- // SEGGER_RTT_printf(0,"dat=%04X(%d)\n",dat,dat_dex);
- }
- uint32_t drv_GetChargeTrig(void){
- return trg;
- }
- void drv_TrigProcess(void* t)
- {
-
- static uint8_t state = 0;
- static uint8_t cnt[2];
- static uint32_t trg_b = 0;
- static uint32_t dt_b = 0;
- uint32_t dt = *((uint32_t*)t);
-
- trg = nrf_gpio_pin_read(PIN_CHARGING);
-
- if(dt - dt_b > 1)
- {
- // SEGGER_RTT_printf(0,"-------------------------------------------->\r\n");
- }
-
-
- if(dt-dt_b==1){
- if(trg==0&&trg_b==0){ //低
- cnt[0]++;
- }else if(trg>0&&trg_b>0){ //高
- cnt[1]++;
- }else if(trg==0&&trg_b>0){ //高变低
- // SEGGER_RTT_printf(0,"H->L:cnt[0]=%d,cnt[1]=%d \n",cnt[0],cnt[1]);
-
- if(cnt[1]>37&&cnt[1]<53 && state==2){ //结束
- state = 0;
- if(cnt[0]>50) drv_TrigNBit(cnt[0]-50,0);
-
- uint8_t trg_dat = (uint8_t)(dat>>8);
- uint8_t trg_dat_f = ~((uint8_t)(dat>>0));
-
- //调用触发函数
- if(trg_dat>0&&trg_dat<4&&trg_dat==trg_dat_f){
- selfcheck_trigger_set_order(trg_dat);
- // SEGGER_RTT_printf(0,"******** selfcheck_trigger_set_order **********\n");
- }
- // SEGGER_RTT_printf(0,"trg_dat=%02X,trg_dat_f=%02X \n\n",trg_dat,trg_dat_f);
- // SEGGER_RTT_printf(0,"******** stop **********\n");
- }
-
- if(state==2){ //接收数据
- drv_TrigNBit(cnt[0],0);
- drv_TrigNBit(cnt[1],1);
- // SEGGER_RTT_printf(0,"******** data **********\n");
- }
-
- if(cnt[0]>37&&cnt[0]<53&&cnt[1]>38&&cnt[1]<53 && state==1){ //开始
- state = 2;
- dat = 0;
- dat_dex = 15;
- // SEGGER_RTT_printf(0,"******** start **********\n");
- }
-
- if(cnt[0]>90&&cnt[0]<110&&cnt[1]>10&&cnt[1]<180){ //准备开始
- state = 1;
- // SEGGER_RTT_printf(0,"******** ready **********\n");
- }
-
- cnt[0] = 0;cnt[1] = 0;
- }
- }
- trg_b = trg;
- dt_b = dt;
- }
- void drv_TriggerInit(void)
- {
- nrf_gpio_cfg_input(PIN_CHARGING,NRF_GPIO_PIN_NOPULL);
-
- TIME_Regist(drv_TrigProcess);
- }
|