Kernel uc/os-ii api manual for embedded device design

1 Introduction to uC/OS-II

uC/OS-II is a preemptive, hard real-time kernel based on task priority. Since its introduction in 1992, it has gained widespread use globally and is specifically designed for embedded systems. It has been ported to over 40 different CPU architectures, ranging from 8-bit to 64-bit processors. Notably, since version 2.51, the system has passed certification by the U.S. Federal Aviation Administration (FAA), making it suitable for critical applications such as aerospace systems. One of the key advantages of uC/OS-II is that it is available for free, making it an economical choice for developers working on embedded real-time operating systems.

2

Basic Structure of uC/OS-II Applications

Developing applications with uC/OS-II is straightforward once you understand its structure. Every application must include at least one task, and each task should be implemented as an infinite loop. Here’s a typical structure:

Void task ( void* pdata )

{

INT8U err;

InitTimer(); // optional

For( ;; )

{

// your application code

OSTimeDly(1); // optional

}

}

The reason for using an infinite loop is that the system allocates stack space for each task. When tasks are switched, the context is saved and restored, and a return instruction is used to resume execution. If a task exits the loop, it could corrupt the stack and cause undefined behavior. Therefore, tasks must run indefinitely. Programmers should ensure their tasks yield the CPU either voluntarily or through interrupts.

The InitTimer() function is essential for initializing the system timer. It should be called in the highest-priority task before starting multitasking. This ensures that the timer is initialized early enough to avoid issues during task scheduling. However, calling this function inside OSInit() or OSStart() may reduce system portability and performance, so it's best to call it explicitly in the highest-priority task.

3

Key uC/OS-II APIs Overview

uC/OS-II provides a set of APIs for managing tasks, synchronization, timing, and more. These APIs are crucial for developing efficient embedded applications. Among them, task management and time-related functions are particularly important for beginners. Below are some of the most commonly used APIs:

1) OSTaskCreate – This function creates a new task. It requires the task's entry point, parameters, stack pointer, and priority. After creation, the task is marked as ready to execute.

2) OSTaskSuspend – Suspends a specified task. If the suspended task has a higher priority than the current one, a task switch will occur.

3) OSTaskResume – Resumes a previously suspended task. Similar to OSTaskSuspend, it can trigger a task switch if the resumed task has a higher priority.

4) OS_ENTER_CRITICAL / OS_EXIT_CRITICAL – These macros are used to enter and exit critical sections, preventing interruptions. They are typically implemented as inline assembly and should be used sparingly to avoid disrupting system performance.

5) OSTimeDly – Suspends the current task for a specified period. This allows the system to schedule other tasks and is often used to implement delays or yield control.

4

Understanding uC/OS-II Multitasking Mechanism

uC/OS-II is a priority-based preemptive kernel, which means higher-priority tasks can interrupt lower-priority ones. While it appears that multiple tasks are running simultaneously, in reality, the CPU switches between them rapidly. This illusion of concurrency is achieved through context switching, where the CPU saves the state of one task and loads another.

To implement this, uC/OS-II uses interrupts—either soft or hardware—to trigger task switches. Each task has its own stack, managed via the Task Control Block (TCB). During a context switch, the system saves the current task's state, restores the next task's state, and resumes execution. This process ensures that tasks run independently and efficiently without interfering with each other.

Understanding how uC/OS-II manages multitasking helps developers write more reliable and optimized code. By leveraging the kernel’s features, programmers can create robust embedded systems that meet strict real-time requirements.

Low Voltage Transmission Line

We started to export 10kV Transmission Line Steel Pole to Philippines from 2004 and supply more than 50,000 pcs each year.

Our firm introduced whole set of good-sized numerical control hydraulic folding equipment(1280/16000) as well as equipped with a series of good-sized professional equipments of armor plate-flatted machine, lengthways cut machine, numerical control cut machine, auto-closed up machine, auto-arc-weld machine, hydraulic redressing straight machine, etc. The firm produces all sorts of conical, pyramidal, cylindrical steel poles with production range of dia 50mm-2250mm, thickness 1mm-25mm, once taking shape 16000mm long, and large-scale steel components. The firm also is equipped with a multicolor-spayed pipelining. At the meantime, for better service to the clients, our firm founded a branch com. The Yixing Jinlei Lighting Installation Com, which offers clients a succession of service from design to manufacture and fixing.

10kV Steel Pole, Low voltage Steel Power Pole, Steel Power Tubular Pole, Steel Tubular Post

JIANGSU XINJINLEI STEEL INDUSTRY CO.,LTD , https://www.steel-pole.com