z-stack代码分析--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();

//轮询TIMER与UART
Hal_ProcessPoll(); // This replaces MT_SerialPoll() and osal_check_timer().

//执行循环语句:tasksEvents[idx]是一个指针变量,指向存放任务idx的存储空间,初始化时由osal_memset()设为0
//只要不为空类型NULL,即有相对应任务事件发生,就break跳出循环体,通过下面的程序进行事件处理。
//如果为空,执行判断语句,即idx自增,再返回轮询有无各层的任务事件发生。
//如果执行完循环语句都没有检测到有事发生,进入睡眠。
do {
if (tasksEvents[idx]) // Task is highest priority that is ready.
{
break;
}
} while (++idx < tasksCnt);

if (idx < tasksCnt)
{
uint16 events;
//中断位状态
halIntState_t intState;

//中断暂停:保存此时的EA寄存器值,然后关闭中断
HAL_ENTER_CRITICAL_SECTION(intState);
//把有事件发生的任务idx的存储空间的地址赋给events
events = tasksEvents[idx];
//清除任务idx的事件tasksEvents[idx]=0(指针变量值为NULL)
tasksEvents[idx] = 0; // Clear the Events for this task.
//中断继续:还原中断值,恢复先前中断状态,启动中断
HAL_EXIT_CRITICAL_SECTION(intState);

//任务idx的事件处理函数
events = (tasksArr[idx])( idx, events );

//中断暂停
HAL_ENTER_CRITICAL_SECTION(intState);
//把刚才返回未处理的任务事件添加到当前任务中再进行处理
// 跳出if(idx<tasksCnt)循环,再进行if(tasksEvents[idx])判断并处理。
tasksEvents[idx] |= events; // Add back unprocessed events to the current task.
//中断继续
HAL_EXIT_CRITICAL_SECTION(intState);
}

//如果已定义POWER_SAVING,则执行此函数
//在OSAL循环中,如果没有任何事件需要执行的话,将调用此函数,设备将进入睡眠模式
#if defined( POWER_SAVING )
else // Complete pass through all task events with no activity?
{
osal_pwrmgr_powerconserve(); // Put the processor/system into sleep
}
#endif
}
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值