具体代码如下:
外部中断代码
HAL_ISR_FUNCTION( halKeyPort0Isr, P0INT_VECTOR )
{
HAL_ENTER_ISR();
if(HAL_KEY_SW_2_PXIFG & HAL_KEY_SW_2_BIT)
{
osal_start_timerEx (Hal_TaskID, HAL_KEY_EVENT,2000);
}
P0IFG = 0;
HAL_KEY_CPU_PORT_0_IF = 0;
CLEAR_SLEEP_MODE();
HAL_EXIT_ISR();
}
任务轮询函数:
uint16 Hal_ProcessEvent( uint8 task_id, uint16 events )
{
if (events & HAL_KEY_EVENT)
{
/* Check for keys */
HalSw2Poll();
return events ^ HAL_KEY_EVENT;
}
}
void HalSw2Poll (void)
{
//key2 始终采用中断触发方式
if(!(PICTL & HAL_KEY_SW_2_EDGEBIT))//判断是否配置为上升沿
{
#ifdef LOGE_DEBUG
printf("hal_key:%d: raiging edge\r\n",__LINE__);
#endif
if (!HAL_PUSH_BUTTON2())//采样到高电平
{
if(g_keys & HAL_KEY_SW_2)
{
#ifdef LOGE_DEBUG
printf("hal_key:%d: high\r\n",__LINE__);
#endif
(pHalKeyProcessFunction)(HAL_KEY_SW_2, HAL_KEY_STATE_NORMAL);
g_keys &= ~HAL_KEY_SW_2;
PICTL |= HAL_KEY_SW_2_EDGEBIT; /* Falling edge configuratinn */
zclSample_ZoneStatus |= SS_IAS_ZONE_STATUS_ALARM1_ALARMED;
}
}
}
else
{
#ifdef LOGE_DEBUG
printf("hal_key:%d: Falling edge\r\n",__LINE__);
#endif
if (HAL_PUSH_BUTTON2())//采样到低电平
{
if(g_keys & HAL_KEY_SW_2)
{
#ifdef LOGE_DEBUG
printf("hal_key:%d: low\r\n",__LINE__);
#endif
(pHalKeyProcessFunction)(HAL_KEY_SW_2, HAL_KEY_STATE_NORMAL);
g_keys &= ~HAL_KEY_SW_2;
PICTL &= ~(HAL_KEY_SW_2_EDGEBIT); /* Rising edge configuratinn */
zclSample_ZoneStatus &= ~(SS_IAS_ZONE_STATUS_ALARM1_ALARMED);
}
}
}
#ifdef LOGE_DEBUG
printf("hal_key:%d: HalSw2Poll\r\n",__LINE__);
#endif
}
当触发外部中断时,开启定时器osal_start_timerEx (Hal_TaskID, HAL_KEY_EVENT,2000); 还没有等到2000ms超时时间,就立即进入HalSw2Poll 函数,这是什么原因?我自己觉得应该要等到2000ms之后,才能进入HalSw2Poll 函数。
Viki Shi:
参考这边的类似问题:e2echina.ti.com/…/373769