函数的核心代码如下:
void OS_TaskStat (void *pdata)
{
INT32U run;
INT8S usage;
while (OSStatRdy == FALSE) {
OSTimeDly(2 * OS_TICKS_PER_SEC); /* Wait until statistic task is ready */
}
for (;;) {
OS_ENTER_CRITICAL();
OSIdleCtrRun = OSIdleCtr; /* Obtain the of the idle counter for the past second */
run = OSIdleCtr;
OSIdleCtr = 0L; /* Reset the idle counter for the next second */
OS_EXIT_CRITICAL();
if (OSIdleCtrMax > 0L) {
usage = (INT8S)(100L - 100L * run / OSIdleCtrMax);
if (usage >= 0) { /* Make sure we don't have a negative percentage */
OSCPUUsage = usage;
} else {
OSCPUUsage = 0;
}
} else {
OSCPUUsage = 0;
}
OSTaskStatHook(); /* Invoke user definable hook */
OSTimeDly(OS_TICKS_PER_SEC); /* Accumulate OSIdleCtr for the next second */
}
}
函数的作用是计算CPU的占用情况,对吧,我知道OSIdleCtrMax是在只有空闲任务时单位时间的计数,而OSIdleCtr应该是当前单位时间内空闲任务计数啊,可是为什么没有体现出这一点。我觉得应该先把OSIdleCtr清零,再延时1秒,这时的OSIdleCtr才可用
------解决方案--------------------
去看看邵贝贝的那本书吧。