您的位置:首页 > 其它

OSAL函数分析-osal_start_reload_timer,osalAddTimer,osalFindTimer

2015-08-03 16:58 232 查看
<span style="font-size:14px;">/*********************************************************************
* @fn      osalAddTimer
*
* @brief   Add a timer to the timer list.
*          Ints must be disabled.
*          添加一个节点到时间链表
* @param   task_id
* @param   event_flag
* @param   timeout
*
* @return  osalTimerRec_t * - pointer to newly created timer
*/
osalTimerRec_t * osalAddTimer( uint8 task_id, uint16 event_flag, uint32 timeout )
{
osalTimerRec_t *newTimer;
osalTimerRec_t *srchTimer;

// Look for an existing timer first
/*    检测这个任务ID和事件是否已经存在于链表之中
返回非 NULL的话,说明已经存在
*/
newTimer = osalFindTimer( task_id, event_flag );
if ( newTimer )
{
// Timer is found - update it.
/* 节点是存在的,更新时间   */
newTimer->timeout.time32 = timeout;
/* 返回该节点   */
return ( newTimer );
}
else
{
// New Timer
/* 节点是不存在的,重新创建一个节点   */
newTimer = osal_mem_alloc( sizeof( osalTimerRec_t ) );
if ( newTimer )
{
// Fill in new timer
/* 给新的节点赋值 */
newTimer->task_id = task_id;
newTimer->event_flag = event_flag;
newTimer->timeout.time32 = timeout;
newTimer->next = (void *)NULL;
newTimer->reloadTimeout = 0;

// Does the timer list already exist
/* 判断timer 时间链表是否存在 */
if ( timerHead == NULL )
{
// Start task list
timerHead = newTimer;
}
else
{
// Add it to the end of the timer list
/* 添加新建的节点到列表的最后 */
srchTimer = timerHead;

// Stop at the last record
/* 寻找表头 */
while ( srchTimer->next )
srchTimer = srchTimer->next;

// Add to the list
/* 添加入链表 */
srchTimer->next = newTimer;
}
/* 返回新节点   */
return ( newTimer );
}
else
{
return ( (osalTimerRec_t *)NULL );
}
}
}</span>


<span style="font-size:14px;">/*********************************************************************
* @fn      osalFindTimer
*
* @brief   Find a timer in a timer list.
*          Ints must be disabled.
*          寻找已有的Timer时间链表是否已经存在形参代指的任务号和事件
* @param   task_id
* @param   event_flag
*
* @return  osalTimerRec_t *
*/
osalTimerRec_t *osalFindTimer( uint8 task_id, uint16 event_flag )
{
osalTimerRec_t *srchTimer;

// Head of the timer list
srchTimer = timerHead;

// Stop when found or at the end
while ( srchTimer )
{
if ( srchTimer->event_flag == event_flag &&
srchTimer->task_id == task_id )
{
break;
}

// Not this one, check another
srchTimer = srchTimer->next;
}

return ( srchTimer );
}
</span>


<span style="font-size:14px;">/*********************************************************************
* @fn      osal_start_reload_timer
*
* @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
*   and the timer will be reloaded with the timeout value.
*
* @param   uint8 taskID - task id to set timer for
* @param   uint16 event_id - event to be notified with
* @param   UNINT16 timeout_value - in milliseconds.
*
* @return  SUCCESS, or NO_TIMER_AVAIL.
*/
uint8 osal_start_reload_timer( uint8 taskID, uint16 event_id, uint32 timeout_value )
{
halIntState_t intState;
osalTimerRec_t *newTimer;

HAL_ENTER_CRITICAL_SECTION( intState );                       /*   关中断                 */
// Add timer
newTimer = osalAddTimer( taskID, event_id, timeout_value );   /*   添加时间节点           */

if ( newTimer )                                               /*   假如不为空的话         */
{
// Load the reload timeout value
newTimer->reloadTimeout = timeout_value;                    /*   装载时间重新装载值     */
}

HAL_EXIT_CRITICAL_SECTION( intState );                        /*   开中断                 */

return ( (newTimer != NULL) ? SUCCESS : NO_TIMER_AVAIL );
}
</span>


osal_start_reload_timer()函数相对于osal_start_timerEx()函数,就是多了一句

<span style="font-size:14px;">  newTimer->reloadTimeout = timeout_value;                    /*   装载时间重新装载值     */</span>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: