First set: # define OS _TASK_STAT_EN 1
A statistical task is created in OSInit ();.
#if OS_TASK_STAT_EN > 0void OS_TaskStat (void *p_arg){ INT32U run; INT32U max; INT8S usage;#if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */ OS_CPU_SR cpu_sr = 0;#endif p_arg = p_arg; /* Prevent compiler warning for not using 'parg' */ while (OSStatRdy == OS_FALSE) { OSTimeDly(2 * OS_TICKS_PER_SEC / 10); /* Wait until statistic task is ready */ } max = OSIdleCtrMax / 100L; 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 (max > 0L) { usage = (INT8S)(100L - run / max); if (usage >= 0) { /* Make sure we don't have a negative percentage */ OSCPUUsage = usage; } else { OSCPUUsage = 0; } } else { OSCPUUsage = 0; max = OSIdleCtrMax / 100L; } OSTaskStatHook(); /* Invoke user definable hook */#if (OS_TASK_STAT_STK_CHK_EN > 0) && (OS_TASK_CREATE_EXT_EN > 0) OS_TaskStatStkChk(); /* Check the stacks for each task */#endif OSTimeDly(OS_TICKS_PER_SEC / 10); /* Accumulate OSIdleCtr for the next 1/10 second */ }}#endif
View CPU usage in ucos
Now you can output the relevant information in your task:
printf("\r\n\r\n Micrium uC/OS-II \r\n"); printf(" ST STM32 (Cortex-M3)\r\n\r\n"); printf(" uC/OS-II: V%ld.%ld%ld\r\n",OSVersion()/100,(OSVersion() % 100) / 10,(OSVersion() % 10)); printf(" TickRate: %ld \r\n",OS_TICKS_PER_SEC); printf(" CPU Usage: %ld% \r\n",OSCPUUsage); printf(" CPU Speed: %ld MHz \r\n",BSP_CPU_ClkFreq() / 1000000L); printf(" #Ticks: %ld \r\n",OSTime); printf(" #CtxSw: %ld \r\n",OSCtxSwCtr);
In sequence: version number, CPU usage, clock speed, task switching times, and so on!