OSAL函数分析-osal_start_reload_timer,osalAddTimer,osalFindTimer

<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>

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值