osal_start_system运行操作系统函数

/*********************************************************************
 * @fn      osal_start_system
 *
 * @brief
 *
 *   This function is the main loop function of the task system.  It
 *   will look through all task events and call the task_event_processor()
 *   function for the task with the event.  If there are no events (for
 *   all tasks), this function puts the processor into Sleep.
 *   This Function doesn't return.
 *
 * @param   void
 *
 * @return  none

 */

注解:这个是任务系统轮询的主要函数。他会查找发生的事件然后调用相应的事件执行函数。如果没有事件登记要发生,那么就进入睡眠模式。这个函数是永远不会返回的。

void osal_start_system( void )
{
#if !defined ( ZBIT ) && !defined ( UBIT )
  for(;;)  // Forever Loop
#endif
  {
    uint8 idx = 0;
   
    osalTimeUpdate();  //扫描哪个事件被触发了,然后置相应的标志位
    Hal_ProcessPoll();  // This replaces MT_SerialPoll() and osal_check_timer().
    
    do {
      if (tasksEvents[idx])  // Task is highest priority that is ready.
      {
        break;           //得到待处理的最高优先级任务索引号  idx
      }
    } while (++idx < tasksCnt);

    if (idx < tasksCnt)
    {
      uint16 events;
      halIntState_t intState;

      HAL_ENTER_CRITICAL_SECTION(intState);  //进入临界区,保护
      events = tasksEvents[idx];            //提取需要处理的任务中的事件
      tasksEvents[idx] = 0;  // Clear the Events for this task.清除本次任务的事件
      HAL_EXIT_CRITICAL_SECTION(intState);   //退出临界区

      events = (tasksArr[idx])( idx, events );  ///通过指针调用任务处理函数,关键

      HAL_ENTER_CRITICAL_SECTION(intState);   ///进入临界区
      tasksEvents[idx] |= events;  // Add back unprocessed events to the current task.保存未处理的事件
      HAL_EXIT_CRITICAL_SECTION(intState);   //退出临界区
    }
#if defined( POWER_SAVING )
    else  // Complete pass through all task events with no activity?
    {
      osal_pwrmgr_powerconserve();  // Put the processor/system into sleep
    }
#endif
  }
}



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值