一孵延、函數(shù)原型
/*********************************************************************
* @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 //任務(wù)ID
* @param uint16 event_id - event to be notified with //事件ID
* @param UNINT16 timeout_value - in milliseconds. //設(shè)定觸發(fā)時間,以毫秒為單位
*
* @return SUCCESS, or NO_TIMER_AVAIL.//返回成功或設(shè)定時間無效
*/
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 );
}
二状共、應(yīng)用
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
該函數(shù)是一個定時函數(shù),網(wǎng)絡(luò)組建成功后峡继,每隔(SAMPLEAPP_SEND_PERIODIC_MSG_TIMEOUT+ (osal_rand() & 0x00FF))
即5s就會去執(zhí)行SAMPLEAPP_SEND_PERIODIC_MSG_EVT觸發(fā)的函數(shù)冯袍,即
執(zhí)行下面花括號中的內(nèi)容。
if(events&SAMPLEAPP_SEND_PERIODIC_MSG_EVT)
{
...
}