In the μC/OS-ⅲ system, the task itself has five states.
1. sleep state
After calling the function ostaskcreate () to create a task, the task can be managed by μC/OS-ⅲ. The job code in sleep state has actually been written into the code space, but μC/OS-ⅲ does not know its existence. When you do not need μC/OS-ⅲ to manage a task, you can call the task deletion function ostaskdel () to delete it. Ostaskdel () does not actually Delete the code of a task, but does not allow the task to have the right to use the CPU.
2. Readiness
When a task is ready to run, it enters the ready state. In μC/OS-ⅲ, any number of tasks can be in the ready state.
3. Running State
The most important ready task enters the running state. For single-core CPUs, only one task can be run at any time.
4. waiting state
When a task waits for an event to continue running, the task enters the waiting state. Tasks in the waiting state will be placed in an equal representative corresponding to the waiting events of the task. When a task waits for an event, the task will be resumed after it is put back and becomes ready.
5,
Interrupted service state: If the CPU is allowed to be interrupted, when the interruption occurs, the running task is suspended and the CPU starts to execute the interrupt service subroutine ISR. The service is interrupted. Note that ISR programs should be as short as possible, and most of the work of interrupt processing should be completed at the manageable task level in the μC/OS-ⅲ system.
In the tasks of the μC/OS-ⅲ system, a task control block TCB is included ). This is a data structure used by the kernel to maintain task-related information. In μC/OS-ⅲ, each task must have its own TCB. The TCB of the task is allocated by the user in the user's bucket. When you call a task-related function, you must pass the TCB address of the task to the called function. Note that even if you understand the functions of each member in OS _tcb, you cannot directly access these Members in the application code, and you are not allowed to make any changes to them.
μC/OS-ⅲ has five internal system tasks
Among the five system tasks, idle tasks and timer tasks are required, and other tasks are optional.
1. Idle task: OS _idletask () ---- OS _core.c
OS _idletask () is the first task created by μC/OS-ⅲ and a task created by μC/OS-ⅲ. The priority of idle tasks is always set to OS _CFG_PRIO_MAX-1. In fact, a idle task is the only task that can use this priority (this priority is the lowest priority ). In this task, you can call some special processor control functions, such as setting the processor to a low power consumption state.
2. clock cycle task: OS _ticktask () --- OS _tick.c
Almost every real-time operating system requires a periodic clock source, called clock tick or system tick, to track task latency and task wait timeout. The clock cycle processing function of μC/OS-ⅲ is encapsulated in the OS _tick.c file.
OS _ticktask () is a system task that must be created by μC/OS-ⅲ. You can set the task priority. Generally, this task is set to a relatively high priority. This task is used to track tasks being demonstrated and wait for a kernel object task within a specified time. OS _ticktask () is a periodic task that waits for the signal sent by the ISR at the clock cycle.
3. Statistical task: OS _stattask () --- OS _stat.c
The statistical task in μC/OS-ⅲ is an optional system task. You can perform some statistical work during system running, for example, count the total CPU usage and the CPU usage of each task.
To use a statistical task, you must create the first and only application task in the main () function to call the osstattaskcpuusageint () function (for routine examples, see section 5.6.3 of the first version of this book, P83 ).
4. scheduled task: OS _tmrtask () --- OS _tmr.c
μC/OS-ⅲ can provide users with scheduled services. The scheduled service can periodically perform custom operations. In μC/OS-ⅲ, scheduled tasks are optional. You can create a timer for any data.
5. Interrupt service management task: OS _intqtask () --- OS _int.c
When the configuration constant OS _rj_isr_post_deferred_en in the OS _cfg.h file is set to 1, μ c/OS-III creates a task named OS _intqtask (), which is responsible for the "delay" (deferring) the behavior of the system post service function (OS Post Service) called in ISR.
A task is a program that considers the CPU as its exclusive. For a single CPU system, only one task is running at any time. μC/OS-ⅲ supports multi-task management and allows tasks with a number of tasks in an application. The maximum number of tasks is actually limited by the storage space available for processors.
Task Management in the μC/OS-ⅲ System