本帖最后由 Just_Beat_It 于 2015-6-15 17:27 编辑
疑问一:while (OSStatRdy == OS_FALSE) {
OSTimeDly(2u *
OS_TICKS_PER_SEC / 10u); /* Wait until statistic task is ready
只要执行完OSStatInit();就会将OSStatRdy 变为OS_TRUE, 也就是说这句话在这之后只要一运行while
(OSStatRdy == OS_FALSE)就相当于while (0),不知道自己的理解对不对?
疑问二:OSIdleCtrMax/= 100uL;只要执行OS_TaskStat就会执行OSIdleCtrMax/= 100uL; OSIdleCtrMax为0.1s 执行OSIdleCtrMax/=
100uL,不就是为了得到1ms(0.1s/100)空闲任务计数的最大值吗?为什么要每次运行程序都要执行一遍
疑问三:OS_TaskStat走到(void)OSTaskSuspend(OS_PRIO_SELF);函数挂起自己什么时候被唤醒?OSIdleCtrRun是100个滴答时钟的空闲值吗?
下面是ucos II的OS_TaskStat函数的源码:
#if OS_TASK_STAT_EN > 0u
void OS_TaskStat (void *p_arg)
{
#if OS_CRITICAL_METHOD == 3u /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr = 0u;
#endif
p_arg = p_arg; /* Prevent compiler warning for not using 'p_arg' */
while (OSStatRdy == OS_FALSE) {
OSTimeDly(2u * OS_TICKS_PER_SEC / 10u); /* Wait until statistic task is ready */
}
OSIdleCtrMax /= 100uL;//1ms的计数最大值
if (OSIdleCtrMax == 0uL) {
OSCPUUsage = 0u;
#if OS_TASK_SUSPEND_EN > 0u
(void)OSTaskSuspend(OS_PRIO_SELF);
#else
for (;;) {
OSTimeDly(OS_TICKS_PER_SEC);//OS_TICKS_PER_SEC:1s的滴答数(1000ms/5ms = 200)
}
#endif
}
for (;;) {
OS_ENTER_CRITICAL();
//OSIdleCtrRun 为100个滴答时钟的空闲计数器值。(0.5s)
OSIdleCtrRun = OSIdleCtr; /* 获取过去的一秒空闲计数器的值 */
OSIdleCtr = 0uL; /* 重置下一秒空闲计数器 */
OS_EXIT_CRITICAL();
OSCPUUsage = (INT8U)(100uL - OSIdleCtrRun / OSIdleCtrMax);
OSTaskStatHook(); /* 调用用户自定义的钩子函数 */
#if (OS_TASK_STAT_STK_CHK_EN > 0u) && (OS_TASK_CREATE_EXT_EN > 0u)
OS_TaskStatStkChk(); /* 检查每个任务的堆栈 */
#endif
OSTimeDly(OS_TICKS_PER_SEC / 10u); /* 在接下来的0.1s积累osidlectr */
}
}
#endif
代码的中文备注是我自己写的,不一定对。 0.0
求各路大神指教。。。
|