osal

    xiaoxiao2021-03-25  153

    /*********************************************************************  * @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

     */

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

    [cpp]  view plain  copy 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     }   }  
    转载请注明原文地址: https://ju.6miu.com/read-23008.html

    最新回复(0)