Zigbee协议栈函数解析之osal_start_timerEx

2016-12-16  本文已影响0人  羽墨志

一、函数原型

/*********************************************************************
* @fn      osal_start_timerEx
*
* @brief
*
*   This function is called to start a timer to expire in n mSecs.
*   When the timer expires, the calling task will get the specified event.
*
* @param   uint8 taskID - task id to set timer for      //任务ID
* @param   uint16 event_id - event to be notified with  //事件ID
* @param   UNINT16 timeout_value - in milliseconds.     //设定触发时间,以毫秒为单位
*
* @return  SUCCESS, or NO_TIMER_AVAIL.//返回成功或设定时间无效
*/
uint8 osal_start_timerEx( uint8 taskID, uint16 event_id, uint16 timeout_value )
{
 halIntState_t intState;
 osalTimerRec_t *newTimer;

 HAL_ENTER_CRITICAL_SECTION( intState );  // Hold off interrupts.

 // Add timer
 newTimer = osalAddTimer( taskID, event_id, timeout_value );

 HAL_EXIT_CRITICAL_SECTION( intState );   // Re-enable interrupts.

 return ( (newTimer != NULL) ? SUCCESS : NO_TIMER_AVAIL );
}

二、应用
  osal_start_timerEx( SampleApp_TaskID, SAMPLEAPP_SEND_PERIODIC_MSG_EVT, (SAMPLEAPP_SEND_PERIODIC_MSG_TIMEOUT+ (osal_rand() & 0x00FF)) );
其中,#define SAMPLEAPP_SEND_PERIODIC_MSG_TIMEOUT 5000 //5000ms即5s

该函数是一个定时函数,网络组建成功后,每隔(SAMPLEAPP_SEND_PERIODIC_MSG_TIMEOUT+ (osal_rand() & 0x00FF))即5s就会去执行SAMPLEAPP_SEND_PERIODIC_MSG_EVT触发的函数,即
执行下面花括号中的内容。

if(events&SAMPLEAPP_SEND_PERIODIC_MSG_EVT)
{
    ...
}
上一篇下一篇

猜你喜欢

热点阅读