
+ + + + + + + + + + +
At the end of October, we successfully held a series of technical online lectures on the μC/OS real-time operating system with experts from Weston-embedded and Embedded office.
The second lecture was given by Zhang Aihua, the technical director of Micrium Software, focusing on the principles of the μC/OS-II and μC/OS-III kernels. We have compiled some Q&A after the class to help students and interested friends understand μC/OS. Let’s see if there’s anything you want to know!
+ + + + +
Q
Are there any reference materials related to μC/OS porting?
A
Porting μC/OS to a specific processor requires understanding the processor’s register context and stack handling to achieve proper task context saving. Task context switching should be based on the processor’s assembly instruction architecture, and you can refer to https://micrium.atlassian.net/wiki/spaces/osiiidoc/pages/131481/uC-OS-III+Port. It is recommended for beginners to analyze the porting code of processors with similar architectures based on the official development examples to complete the porting and verification work. The example download link is https://www.weston-embedded.com/micrium-examples.
Q
Since there are no message mailboxes in μC/OS-III, what service can replace it?
A
The mailbox is equivalent to a message queue of length 1. In μC/OS-III, queue services can be used to replace the application scenarios of mailboxes.
Q
Does μC/OS support creating tasks with the same priority?
A
μC/OS-III provides a time slice round-robin algorithm that allows the creation of tasks with the same priority. μC/OS-II only supports preemptive scheduling algorithms, and tasks must be assigned independent priority levels.
Q
How to achieve low power consumption in μC/OS?
A
When user tasks are blocked, μC/OS runs the lowest priority system task, which is the idle task. The idle task executes an infinite loop, calling OSTaskIdleHook() each time through the loop. To save power in the idle task, you can configure the processor to operate in low power mode in the hook function. μC/OS-III has added tickless mode and dynamic tick mode to meet the needs of low power application scenarios. For detailed information, refer to: https://micrium.atlassian.net/wiki/spaces/osiiidoc/pages/132263/The+Clock+Tick.
Q
What should be noted when switching from μC/OS-II to μC/OS-III?
A
For the work required to upgrade applications from μC/OS-II to μC/OS-III, you can refer to the document https://micrium.atlassian.net/wiki/spaces/osiiidoc/pages
/132367/Migrating+from+uC-OS-II+to+uC-OS-III.
Q
What does kernel configuration involve?
A
The μC/OS configuration file content involves the system services required for specific applications, supported tasks/priorities, etc. For specific information on each configuration item, refer to https://micrium.atlassian.net/wiki/spaces
/osiidoc/pages/163895/C+OS-II+Configuration+Manual and https://micrium.atlassian.net/wiki/spaces/osiiidoc/pages
/132525/uC-OS-III+Configuration+Manual.
Q
Does it support multi-core?
A
Currently, μC/OS does not support running on SMP architecture.
Q
Is there support for CPU task load statistics? Is there a method for estimating stack size and automation analysis tools?
A
μC/OS provides task statistics to track CPU utilization of tasks. Users can obtain task-related information through kernel-aware plugins provided by IDEs, visual analysis tools, etc. Some IDEs offer stack usage analysis to help determine how much stack space each task requires. You can also use RTOS visual analysis tools, such as Tracealyzer, to monitor stack usage at runtime and optimize task stack settings.
Q
How does the kernel access the task list?
A
In μC/OS applications, there is a defined data structure called the Task Control Block (TCB), which stores key information about tasks, such as priority and task stack. The task list structure is managed through a global variable provided by the kernel. For specific content, refer to the kernel scheduling principles.
Q
Do tasks with equal priority execute in time slices?
A
In μC/OS-III, tasks with equal priority can be configured with different time slice lengths, set during task creation.
Q
Does μC/OS-III provide space isolation and time isolation?
A
Currently, μC/OS-III has not released an MPU version and does not support space isolation implementation. μC/OS-II has provided versions with space isolation and time monitoring. For specific information, visit https://www.embedded-office.com/products/flexible-safety-rtos.
Q
Will μC/OS-II continue to be maintained?
A
Weston Embedded Solutions is responsible for the updates and commercial services of μC/OS-II. For version update information, refer to https://micrium.atlassian.net/wiki/spaces/osiidoc
/pages/163883/C+OS-II+Release+Notes.
Q
Are there any porting examples of μC/OS for RISC-V architecture?
A
μC/OS supports RISC-V porting examples. You can visit
https://github.com/weston-embedded/uC-OS3/tree/develop/Ports/RISC-V/RV32/GCC
https://github.com/RISCV-on-Microsemi-FPGA/uCOS.
Q
Are floating-point registers protected and restored during task switching by default?
A
If the processor supports FPU, then the porting code includes settings for the protection and restoration of floating-point registers. This part of the code is controlled by configuration switches and is not enabled by default.
Q
What code runs in the idle task? Can functionalities be added?
A
The idle task is an empty loop. The implementation in μC/OS-III is as follows:

Users can add functionalities in the OSIdleTaskHook() function. Note that the idle task cannot call blocking service functions.
Q
What does NKA KA interrupt type mean? Has the OS interrupt vector table been redirected?
A
NKA stands for Non-kernel aware interrupts, which do not require kernel involvement. KA stands for Kernel Aware interrupts, which are managed by the OS. The interrupt handling methods differ. Interrupts that do not require kernel involvement are handled similarly to bare-metal systems. For OS-managed interrupts, the OS needs to be notified. Sample code is as follows:

Please follow the latest updates and training news on the “Micrium Technology” WeChat official account.
WeChat consultation: bmrtech123
