This post was last edited by Rambo on 2018-8-15 13:29 uC/OS-II uses a preemptive real-time multitasking kernel. The preemptive real-time kernel runs the highest priority task that is ready at any time. uC/os-II's task scheduling is completely preemptive scheduling based on task priority, that is, once the highest priority task is in the ready state, it immediately preempts the processor resources of the running low-priority task. In order to simplify system design, uC/OS-II stipulates that all tasks have different priorities, because the priority of a task also uniquely identifies the task itself. UCOS task scheduling occurs in the following situations: 1) The high-priority task actively requests to suspend and give up the processor because it needs some critical resources. At this time, the low-priority task in the ready state will be scheduled for execution. This scheduling is also called task-level context switching. 2) The high-priority task has obtained the execution condition (such as the dormant clock has expired) in the clock interrupt handler because the clock beat arrives. Then it directly switches to the high-priority task in the interrupt state for execution. This scheduling is also called interrupt-level context switching. These two scheduling methods are very common in the execution process of uC/OS-II. Generally speaking, the former occurs in the system service, and the latter occurs in the clock interrupt service program. The scheduling work can be divided into two parts: finding the highest priority task and switching tasks. The highest priority task is found by establishing a ready task table. Each task in u C / OS has an independent stack space and a data structure called a task control block TCB (Task Control Block), in which the first member variable is the saved task stack pointer. The task scheduling module first uses the variable OSTCBHighRdy to record the TCB address of the current highest-level ready task, and then calls the OS_TASK_SW() function to switch tasks.