c/os-ii task management creating a task! - uio

12
C/OS-II Task Management Creating a task!

Upload: khangminh22

Post on 23-Nov-2023

1 views

Category:

Documents


0 download

TRANSCRIPT

𝜇C/OS-II Task Management

Creating a task!

Available services

• Task creation• Task stack & stack checking• Task deletion• Change a task’s priority• Suspend and resume a task• Get information about the task

Documentation: https://doc.micrium.com/display/osiidoc/Task+Management

Creating a task

• For uC/OS-II to manage a task, you must• Define stack size• Create task stack• Define task priority• Write/define the function/code of the task• Create task function to be handle by uC/OS-II by passing its address along

with other arguments to one of the two functions:• OSTaskCreate()• OSTaskCreateExt() [ Extended version that provides additional features ]

Creating a Task

• A task can be created• Prior to the start of multitasking• Or by another task

• At least one task must be created before multitasking ( i.e. before calling OSStart() )

• An ISR cannot create a task

Task Stack• Each task must have its own stack space

• Declared as being of type OS_STK• Must consist of contiguous memory locations

• Stack grows from high to low*• Pass pointer to top of stack when creating task

*Can be reversed in os_cpu.h by: #define OS_STK_GROWTH 0 (default 1 for Nios II)

Defining the task function/code• Looks like any other C function

• Containing a return (always void) and an argument• But the task must never return (infinite loop)

• A task must have one of the two structures:

Assigning task priorities

• Assigning task priorities is not trivial because of the complex nature of real-time systems• In most systems, not all tasks are considered critical• Noncritical tasks should obviously be given low priorities

• Most real-time systems have a combination of soft and hard requirements• In a soft real-time system, tasks are performed as quickly as possible, but they

don’t necessarily have to finish by specific times• In hard real-time systems, tasks have to be performed not only correctly but

on time

Task Priority• A priority is assigned to each task.

• The more important the task, the higher the priority given to it.

• With most kernels, you are generally responsible for deciding what priority each task gets.

• Static priority• Fixed priority at compile time.• Priority of task does not change during the application’s execution

• Dynamic priority• Priority of task can be changed during the application’s execution; each task can change its priority at run time• Desirable feature to have in real-time kernel to avoid priority inversions• uC/OS-II supports dynamic task priorities

OSTaskCreate

• Tasks are created in main()

Create task example

Initializing and start-up of multitasking

OSInit() is called automatically through the setup of the HAL for the NIOS system. Calling OSInit() once more in the main routine, will therefore reset this setup process and potentially create problems.

A basic uC/OS-II example