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 } }
ZigBee--osal_start_system函数
最新推荐文章于 2023-03-30 13:44:56 发布