1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| bool detection_queue[110]; int detection_index=0; bool state=false; long long duration[110]; int message_index=0; long long tick=0; int threshold=12;
void WTimer1AIntHandler(){ unsigned long ulstatus = TimerIntStatus(WTIMER1_BASE,TIMER_TIMA_TIMEOUT); TimerIntClear(WTIMER1_BASE, ulstatus); int ReadPin1 = GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_4); int flag=((ReadPin1&GPIO_PIN_4) != GPIO_PIN_4); detection_queue[detection_index]=flag; int i=0,sum=0; for(i=0;i<=threshold;i++)sum+=(int)detection_queue[detection_index-i]; if(tick>threshold){ if(sum==threshold&&state==false){ state=true; duration[message_index]=tick; } if(sum==0&&state==true){ state=false; duration[message_index]=tick-duration[message_index]; UARTprintf("bottom up. message index is %d\nduration:%d\n",message_index,duration[message_index]); message_index++; message_index%=110; } } tick++; detection_index++; detection_index%=110; return ; } void Configurebottom(){ ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); GPIODirModeSet(GPIO_PORTF_BASE, GPIO_PIN_4, GPIO_DIR_MODE_IN); GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_4, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); SysCtlPeripheralEnable(SYSCTL_PERIPH_WTIMER1); TimerConfigure(WTIMER1_BASE,TIMER_CFG_PERIODIC); TimerLoadSet64(WTIMER1_BASE, clock/500); TimerIntRegister(WTIMER1_BASE, TIMER_A, WTimer1AIntHandler); IntMasterEnable(); TimerIntEnable(WTIMER1_BASE, TIMER_TIMA_TIMEOUT); IntEnable(INT_WTIMER1A); TimerEnable(WTIMER1_BASE, TIMER_A); }
Configurebottom();
|