Ucos ii kernel learning: Task status and task control block
After a task is created, it can be in one of the following five States.
These five statuses are:
1. Sleep Status
2. Readiness
3. Waiting status
4. Service Interruption status
5. Execution status
The following describes the meaning of each State and the method of switching between States.
Sleep Status: The sleep state (dormant) refers to the process in which the task resides and has not been handed over to ucos ii for management. To assign the task to ucos ii, one of the following two functions is called: ostaskcreate () or ostaskcreateext (). Once a task is created, the task is ready for running. A task can be created dynamically or dynamically before a multi-task starts. If a task is created by another task, and the task has a higher priority than the task that created it, the task just created will immediately gain control of the CPU. A task can return to the sleep state by calling ostaskdel () or calling this function to bring another task to sleep state.
Waiting status:A running task can delay itself by calling one of the two functions, which are ostimedly () or ostimedlyhmsm (). This task enters the waiting state. After this time, the next task with the highest priority and enters the ready state is immediately granted control of the CPU. After the waiting time passes, the system service function ostimetick () changes the delayed task to the ready state. A running task also waits for an event to occur by calling one of the following three functions: ossempend (), osmboxpend (), or osqpend (). After the call, the task enters the waiting state (waiting ). When a task is suspended due to a pending event (pend), the next task with the highest priority immediately gets control of the CPU. When an event occurs, the suspended task enters the ready state. The report of the event may come from another task or the interrupt service subroutine.
Service Interruption status:A running task can be interrupted unless the task is interrupted or ucos ii is interrupted. The interrupted task enters the interrupted service state (ISR ). In response to the interruption, the task being executed is suspended, and the interrupt service subprogram controls the CPU usage. Interrupt Service subprograms may report the occurrence of one or more events, and make one or more tasks ready. In this case, ucos ii must determine whether the interrupted task has the highest priority in the ready state task before returning the service interruption subroutine. If the interrupted service subroutine enables a task with a higher priority to enter the ready state, the new task with a higher priority will be run, otherwise, the interrupted task can continue to run.