![]() |
CMSIS-RTOS
Version 1.00
CMSIS-RTOS API: Generic RTOS interface for Cortex-M processor-based devices.
|
Define, create, and control thread functions. More...
Defines | |
#define | osThreadDef(name, priority, instances, stacksz) |
Create a Thread Definition with function, priority, and stack requirements. | |
#define | osThread(name) &os_thread_def_##name |
Access a Thread defintion. | |
Enumerations | |
enum | osPriority { osPriorityIdle = -3, osPriorityLow = -2, osPriorityBelowNormal = -1, osPriorityNormal = 0, osPriorityAboveNormal = +1, osPriorityHigh = +2, osPriorityRealtime = +3, osPriorityError = 0x84 } |
Functions | |
osThreadId | osThreadCreate (osThreadDef_t *thread_def, void *argument) |
Create a thread and add it to Active Threads and set it to state READY. | |
osThreadId | osThreadGetId (void) |
Return the thread ID of the current running thread. | |
osStatus | osThreadTerminate (osThreadId thread_id) |
Terminate execution of a thread and remove it from Active Threads. | |
osStatus | osThreadSetPriority (osThreadId thread_id, osPriority priority) |
Change priority of an active thread. | |
osPriority | osThreadGetPriority (osThreadId thread_id) |
Get current priority of an active thread. | |
osStatus | osThreadYield (void) |
Pass control to next thread that is in state READY. |
The Thread Management function group allow defining, creating, and controlling thread functions in the system. The function main is a special thread function that is started at system initialization and has the initial priority osPriorityNormal.
Threads can be in the following states:
The CMSIS-RTOS assumes that threads are scheduled as shown in the figure Thread State and State Transitions. The thread states change as described below:
#define osThread | ( | name | ) | &os_thread_def_##name |
Access to the thread definition for the function osThreadCreate.
name | name of the thread definition object. |
#define osThreadDef | ( | name, | |
priority, | |||
instances, | |||
stacksz | |||
) |
Define the attributes of a thread functions that can be created by the function osThreadCreate using osThread.
name | name of the thread function. |
priority | initial priority of the thread function. |
instances | number of possible thread instances. |
stacksz | stack size (in bytes) requirements for the thread function. |
enum osPriority |
The osPriority value specifies the priority for a thread. The default thread priority should be osPriorityNormal. If a Thread is active that has a higher priority than the currently executing thread, then a thread switch occurs immediately to execute the new task.
To prevent from a priority inversion, a CMSIS-RTOS complained OS may optionally implement a priority inheritance method. A priority inversion occurs when a high priority thread is waiting for a resource or event that is controlled by a thread with a lower priority.
osThreadId osThreadCreate | ( | osThreadDef_t * | thread_def, |
void * | argument | ||
) |
[in] | thread_def | thread definition referenced with osThread. |
[in] | argument | pointer that is passed to the thread function as start argument. |
Start a thread function by adding it to the Active Threads list and set it to state READY. The thread function receives the argument pointer as function argument when the function is started. When the priority of the created thread function is higher than the current RUNNING thread, the created thread function starts instantly and becomes the new RUNNING thread.
osThreadId osThreadGetId | ( | void | ) |
Get the thread ID of the current running thread.
osPriority osThreadGetPriority | ( | osThreadId | thread_id | ) |
[in] | thread_id | thread ID obtained by osThreadCreate or osThreadGetId. |
Get the priority of an active thread. In case of a failure the value osPriorityError is returned.
osStatus osThreadSetPriority | ( | osThreadId | thread_id, |
osPriority | priority | ||
) |
[in] | thread_id | thread ID obtained by osThreadCreate or osThreadGetId. |
[in] | priority | new priority value for the thread function. |
Change the priority of an active thread.
osStatus osThreadTerminate | ( | osThreadId | thread_id | ) |
[in] | thread_id | thread ID obtained by osThreadCreate or osThreadGetId. |
Remove the thread function from the active thread list. If the thread is currently RUNNING the execution will stop.
osStatus osThreadYield | ( | void | ) |
Pass control to next thread that is in state READY. If there is no other thread in the state READY, the current thread continues execution and no thread switching occurs.