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>
相关文章推荐
- C++学习笔记 C与C++部分对照
- 面试题总结9
- iOS开发 字符串过滤html标签
- 虚函数和纯虚函数的区别
- HDU-1556-Color the ball-线段树+区间更新+单点查询
- Activity,Fragment中onSaveInstanceState(Bundle outState)的调用时机
- 【Android】开机自启动Service
- 【Android】Service学习之本地服务
- fzu1752 A^BmodC
- 深入 char * ,char ** ,char a[ ] ,char *a[] 内核
- 封装的含义
- IOS视图位置可能变化解决问题
- windows2008 c盘清理
- I - Strategic Game - hdu 1054(最小点覆盖)
- ASP.NET MVC Cookie 身份验证
- Selenium2学习-031-WebUI自动化实战实例-029-JavaScript 在 Selenium 自动化中的应用实例之四(获取元素位置和大小)
- TRIGGER_15.8.3BACKUP
- j2ee、mvn、eclipse、Tomcat等中文乱码问题解决方法
- 常用网址
- 关于随机初始化局面BUG的改善探讨