CMSIS-RTOS
Version 1.03
Real-Time Operating System: API and RTX Reference Implementation.
|
Define, create, and control thread functions. More...
Macros | |
#define | osThreadDef(name, priority, instances, stacksz) |
Create a Thread Definition with function, priority, and stack requirements. More... | |
#define | osThread(name) &os_thread_def_##name |
Access a Thread definition. More... | |
Enumerations | |
enum | osPriority { osPriorityIdle = -3, osPriorityLow = -2, osPriorityBelowNormal = -1, osPriorityNormal = 0, osPriorityAboveNormal = +1, osPriorityHigh = +2, osPriorityRealtime = +3, osPriorityError = 0x84 } |
Priority used for thread control. More... | |
Functions | |
osThreadId | osThreadCreate (const osThreadDef_t *thread_def, void *argument) |
Create a thread and add it to Active Threads and set it to state READY. More... | |
osThreadId | osThreadGetId (void) |
Return the thread ID of the current running thread. More... | |
osStatus | osThreadTerminate (osThreadId thread_id) |
Terminate execution of a thread and remove it from Active Threads. More... | |
osStatus | osThreadSetPriority (osThreadId thread_id, osPriority priority) |
Change priority of an active thread. More... | |
osPriority | osThreadGetPriority (osThreadId thread_id) |
Get current priority of an active thread. More... | |
osStatus | osThreadYield (void) |
Pass control to next thread that is in state READY. More... | |
The Thread Management function group allows 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:
A CMSIS-RTOS assumes that threads are scheduled as shown in the figure Thread State and State Transitions. The thread states change as follows:
#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. The argument instances defines the number of times that osThreadCreate can be called for the same osThreadDef.
Code Example
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 compliant 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 | ( | const 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.
Code Example
osThreadId osThreadGetId | ( | void | ) |
Get the thread ID of the current running thread.
Code Example
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.
Code Example
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.
Code Example
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.
Code Example
osStatus osThreadYield | ( | void | ) |
Pass control to the 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.
Code Example