|
RTOS Wrapper
API reference
|
C-facing helper functions for delays, cycle counters, and creation of RTOS handles (queues, event groups, timers, mutexes, stream buffers). More...
#include "OsAbstraction.h"Go to the source code of this file.
Macros | |
| #define | UTIL_SYSTEM_CLOCK (240000000.0) |
Enumerations | |
| enum | time_unit_t { TIME_UNIT_US = 0 , TIME_UNIT_MS , TIME_UNIT_S } |
| Units used to express time values. More... | |
Functions | |
| constexpr uint32_t | os_convert_msec_to_delay_ticks (uint32_t milliseconds) |
| Converts milliseconds to delay ticks, rounding down but never to zero. | |
| constexpr uint32_t | os_convert_delay_ticks_to_msec (uint32_t delayTicks) |
| Converts delay ticks to milliseconds. | |
| constexpr uint32_t | os_convert_hz_to_delay_ticks (uint32_t frequency) |
| Converts a frequency to a period in delay ticks, rounding down but never to zero. | |
| void | os_delay_msec (uint16_t msec) |
| Delays execution for the specified number of milliseconds. | |
| void | os_delay_time (uint32_t timeBetweenSamples, time_unit_t timeUnit) |
| Delays execution for the specified number of time. | |
| uint32_t | os_get_elapsed_time_msec () |
| Retrieves the elapsed time in milliseconds. | |
| uint32_t | os_get_elapsed_processor_cycle_count (uint32_t startCycleCount, time_unit_t unit) |
| Function to get the elapsed time from a specified processor cycle count. The cycle count can be acquired through os_get_processor_cycle_count() function. | |
| uint32_t | os_get_processor_cycle_count () |
| Gets the processor's current cycle count. | |
| void | os_stack_fault_handler (OS_Thread *thread) |
| Handler for stack faults in threads. | |
| bool | os_mutex_create_ex (OS_Mutex &mutex, const char *mutexName, OS_Uint priority=OS_INHERIT, bool suppressVerbose=true) noexcept |
| Creates a mutex with the specified parameters. | |
| bool | os_mutex_get_ex (OS_Mutex &mutex_ptr, OS_Ulong wait_option, bool suppressVerbose=true) noexcept |
| Acquire (wait for) a TX mutex. | |
| bool | os_mutex_put_ex (OS_Mutex &mutex_ptr, bool suppressVerbose=true) noexcept |
| Release a TX mutex. | |
| bool | os_mutex_delete_ex (OS_Mutex &mutex, bool suppressVerbose=true) noexcept |
| Deletes the specified mutex and logs any error. | |
| bool | os_mutex_create_p (OS_Mutex *mutex, const char *mutexName, OS_Uint priority=OS_INHERIT, bool suppressVerbose=true) noexcept |
| Creates a mutex with the specified parameters. | |
| bool | os_mutex_get_p (OS_Mutex *mutex_ptr, OS_Ulong wait_option, bool suppressVerbose=true) noexcept |
| Acquire (wait for) a TX mutex. | |
| bool | os_mutex_put_p (OS_Mutex *mutex_ptr, bool suppressVerbose=true) noexcept |
| Release a TX mutex. | |
| bool | os_mutex_delete_p (OS_Mutex *mutex, bool suppressVerbose=true) noexcept |
| Deletes the specified mutex and logs any error. | |
| bool | os_thread_create_ex (OS_Thread *txThread, const char *name, void(*entry_function)(OS_Ulong id), OS_Ulong entry_input, uint8_t *stack, OS_Ulong stackSizeBytes, OS_Uint priority, OS_Uint preempt_threshold, OS_Ulong timeSliceAllowed, OS_Uint auto_start, bool suppressVerbose=true) noexcept |
| Function to Create TX thread. | |
| bool | os_thread_create_ex_pinned (OS_Thread *txThread, const char *name, void(*entry_function)(OS_Ulong id), OS_Ulong entry_input, uint8_t *stack, OS_Ulong stackSizeBytes, OS_Uint priority, OS_Uint preempt_threshold, OS_Ulong timeSliceAllowed, OS_Uint auto_start, int core_id, bool suppressVerbose=true) noexcept |
| Pinned-to-core variant of os_thread_create_ex (FreeRTOS / SMP). | |
| bool | os_thread_resume_ex (OS_Thread *thread, bool suppressVerbose=true) |
| Resumes the specified OS thread. | |
| bool | os_thread_resume_if_suspended (OS_Thread *txThread, bool suppressVerbose=true) noexcept |
| Function to Resume TX thread only if it is suspended. | |
| bool | os_thread_suspend_ex (OS_Thread *thread, bool suppressVerbose=true) |
| Suspends the specified OS thread. | |
| bool | os_thread_delete_ex (OS_Thread *txThread, bool suppressVerbose=true) noexcept |
| Function to Delete TX thread. | |
| bool | os_queue_create_ex (OS_Queue &queue, const char *queueName, OS_Uint messageSizeInWords, void *queueStorage, OS_Ulong queueSize, bool suppressVerbose=true) noexcept |
| Creates a queue with the specified parameters. | |
| bool | os_queue_delete_ex (OS_Queue &queue, bool suppressVerbose=true) noexcept |
| Deletes the specified queue and logs any error. | |
| bool | os_queue_send_ex (OS_Queue &queue, void *message, OS_Ulong wait_option=OS_WAIT_FOREVER, bool suppressVerbose=true) noexcept |
| Send a message to the queue. | |
| bool | os_queue_receive_ex (OS_Queue &queue, void *message, OS_Ulong wait_option=OS_WAIT_FOREVER, bool suppressVerbose=true) noexcept |
| Receive a message from the queue. | |
| bool | os_timer_create_ex (OS_Timer &timer, const char *name, void(*callback)(uint32_t), uint32_t callbackExpirationInput, uint32_t initialTimeoutTicks, uint32_t rescheduleTimeoutTicks, OS_Uint autoActivate, bool suppressVerbose=true) noexcept |
| Creates a OS timer and reports any errors associated with the creation. | |
| bool | os_timer_deactivate_and_delete_ex (OS_Timer &timer, bool suppressVerbose=true) noexcept |
| Stops and deletes a OS timer, reporting any errors associated with the operation. | |
| bool | os_timer_activate_ex (OS_Timer &timer, bool suppressVerbose=true) noexcept |
| Activates a OS timer. | |
| bool | os_timer_deactivate_ex (OS_Timer &timer, bool suppressVerbose=true) noexcept |
| Deactivates a OS timer. | |
| bool | os_semaphore_create_ex (OS_Semaphore *txSemaphore, const char *name, OS_Uint initial_count, bool suppressVerbose=true) noexcept |
| Function to Create TX semaphore. | |
| bool | os_semaphore_delete_ex (OS_Semaphore *txSemaphore, bool suppressVerbose=true) noexcept |
| Function to Delete TX semaphore. | |
| bool | os_semaphore_put_ex (OS_Semaphore *txSemaphore, bool suppressVerbose=true) noexcept |
| Function to put (release) a TX semaphore. | |
| bool | os_semaphore_get_ex (OS_Semaphore *txSemaphore, OS_Ulong wait_option, bool suppressVerbose=true) noexcept |
| Function to get (wait for) a TX semaphore. | |
| OS_Ulong | os_semaphore_get_count_ex (OS_Semaphore *txSemaphore, bool suppressVerbose=true) noexcept |
| Function to get TX semaphore count. | |
| bool | os_event_flags_create_ex (OS_EventGroup &eventFlags, const char *name, bool suppressVerbose=true) noexcept |
| Creates an event flag group with the specified parameters. | |
| bool | os_event_flags_delete_ex (OS_EventGroup &eventFlags, bool suppressVerbose=true) noexcept |
| Deletes the specified event flag group and logs any error. | |
| bool | os_event_flags_set_ex (OS_EventGroup &eventFlags, OS_Ulong flagsToSet, bool suppressVerbose=true) noexcept |
| Set event flags in the event flag group. | |
| bool | os_event_flags_clear_ex (OS_EventGroup &eventFlags, OS_Ulong flagsToClear, bool suppressVerbose=true) noexcept |
| Clears event flags in the event flag group. | |
| bool | os_event_flags_get_ex (OS_EventGroup &eventFlags, OS_Ulong flagsToGet, OS_Uint getOption, OS_Ulong &actualFlags, OS_Ulong wait_option, bool suppressVerbose=true) noexcept |
| Get event flags from the event flag group. | |
Variables | |
| static constexpr uint32_t | osTickRateHz = static_cast<uint32_t>(configTICK_RATE_HZ) |
C-facing helper functions for delays, cycle counters, and creation of RTOS handles (queues, event groups, timers, mutexes, stream buffers).
Sits on top of OsAbstraction.h and exposes a stable, RTOS-agnostic surface that the C++ wrappers (OsQueue, OsEventFlags, Mutex, BaseThread, ...) build on.
Thread-safety: each function is a thin pass-through to the underlying RTOS primitive. Most are safe from any task context; the ones that wrap xQueue* / xEventGroup* inherit the safety contract of the FreeRTOS primitive. ISR-safe variants are documented on the individual functions.
Allocation: the *_create_* helpers allocate the underlying RTOS object once. Steady-state operations (delay, cycle counts, send / receive) do not allocate.
| #define UTIL_SYSTEM_CLOCK (240000000.0) |
| enum time_unit_t |
Units used to express time values.
Defined here (not in Utility.h) so that C-facing function declarations below can reference it without a circular include.
| Enumerator | |
|---|---|
| TIME_UNIT_US | Microseconds |
| TIME_UNIT_MS | Milliseconds |
| TIME_UNIT_S | Seconds |
|
constexpr |
Converts delay ticks to milliseconds.
|
constexpr |
Converts a frequency to a period in delay ticks, rounding down but never to zero.
A frequency above the tick rate gives one tick (the fastest the kernel can run); 0 Hz gives 0.
|
constexpr |
Converts milliseconds to delay ticks, rounding down but never to zero.
A non-zero milliseconds gives at least one tick, so a short delay or timeout on a slow tick (1 ms at 100 Hz) waits one tick instead of none; 0 ms stays 0 ticks (no wait). Computed in 64 bits; a result that does not fit is clamped below UINT32_MAX, so a long timeout never turns into a wait-forever.
| void os_delay_msec | ( | uint16_t | msec | ) |
Delays execution for the specified number of milliseconds.
| msec | The delay duration in milliseconds. |
Contains the declaration and definition of the utility functions related to the FreeRTOS RTOS.
Note: These functions are not thread or interrupt-safe and should be called called with appropriate guards if used within an ISR or shared between tasks.
| void os_delay_time | ( | uint32_t | timeBetweenSamples, |
| time_unit_t | timeUnit | ||
| ) |
Delays execution for the specified number of time.
Currently only supports MSEC AND S, everything else just returns
| msec | The delay duration in milliseconds. |
|
noexcept |
Clears event flags in the event flag group.
| eventFlags | - The OS event flags to set |
| flagsToClear | - The flags to clear |
|
noexcept |
Creates an event flag group with the specified parameters.
| eventFlags | - The OS event flags to create |
| name | - The name for the event flag group |
|
noexcept |
Deletes the specified event flag group and logs any error.
| eventFlags | - The OS event flags to delete |
|
noexcept |
Get event flags from the event flag group.
| eventFlags | - The OS event flags to get |
| flagsToGet | - The flags to get |
| getOption | - The option on how to get the flags |
| actualFlags | - The actual flags gotten |
| wait_option | - The option on how to wait if the flags are not available |
|
noexcept |
Set event flags in the event flag group.
| eventFlags | - The OS event flags to set |
| flagsToSet | - The flags to set |
| uint32_t os_get_elapsed_processor_cycle_count | ( | uint32_t | startCycleCount, |
| time_unit_t | unit | ||
| ) |
Function to get the elapsed time from a specified processor cycle count. The cycle count can be acquired through os_get_processor_cycle_count() function.
| startCycleCount | : value of the cycle count DWT->CYCCNT at first position of the program. |
| unit | : UNIT_MS, if the result is requested in milliseconds. UNIT_US, if the result is requested in microseconds. UNIT_SEC, if the result is requested in seconds. |
| uint32_t os_get_elapsed_time_msec | ( | ) |
Retrieves the elapsed time in milliseconds.
| uint32_t os_get_processor_cycle_count | ( | ) |
Gets the processor's current cycle count.
|
noexcept |
Creates a mutex with the specified parameters.
| mutex | - The OS mutex to create |
| name | - The name fo rthe mutex |
| name | - The priority for the mutex |
| mutex | - The OS mutex to create |
| name | - The name fo rthe mutex |
| inherit | - The inherit property for the mutex |
|
noexcept |
Creates a mutex with the specified parameters.
| mutex | - The OS mutex to create |
| name | - The name fo rthe mutex |
| name | - The priority for the mutex |
|
noexcept |
Deletes the specified mutex and logs any error.
| mutex | - The OS mutex to delete |
|
noexcept |
Deletes the specified mutex and logs any error.
| mutex | - The OS mutex to delete |
Acquire (wait for) a TX mutex.
| mutex_ptr | Pointer to the mutex control block. |
| wait_option | Specifies the maximum time to wait for the mutex. |
| suppressVerbose | Flag to suppress verbose output. |
Acquire (wait for) a TX mutex.
| mutex_ptr | Pointer to the mutex control block. |
| wait_option | Specifies the maximum time to wait for the mutex. |
| suppressVerbose | Flag to suppress verbose output. |
|
noexcept |
Release a TX mutex.
| mutex_ptr | Pointer to the mutex control block. |
| suppressVerbose | Flag to suppress verbose output. |
|
noexcept |
Release a TX mutex.
| mutex_ptr | Pointer to the mutex control block. |
| suppressVerbose | Flag to suppress verbose output. |
|
noexcept |
Creates a queue with the specified parameters.
| queue | - The OS queue to create |
| queueName | - The name for the queue |
| messageSizeInWords | - The size of the messages that will be stored in the queue |
|
noexcept |
Deletes the specified queue and logs any error.
| queue | - The OS queue to delete |
|
noexcept |
Receive a message from the queue.
| queue | - The OS queue to receive the message from |
| message | - The received message |
| wait_option | - The option on how to wait if the queue is empty |
|
noexcept |
Send a message to the queue.
| queue | - The OS queue to send the message to |
| message | - The message to send |
| wait_option | - The option on how to wait if the queue is full |
|
noexcept |
Function to Create TX semaphore.
| txSemaphore | Pointer to the OS semaphore control block. |
| name | Name of the semaphore. |
| initial_count | Initial count of the semaphore. |
|
noexcept |
Function to Delete TX semaphore.
| txSemaphore | Pointer to the OS semaphore control block to be deleted. |
|
noexcept |
Function to get TX semaphore count.
| txSemaphore | Pointer to the OS semaphore control block. |
|
noexcept |
Function to get (wait for) a TX semaphore.
| txSemaphore | Pointer to the OS semaphore control block. |
| wait_option | Specifies the maximum time to wait for the semaphore. |
|
noexcept |
Function to put (release) a TX semaphore.
| txSemaphore | Pointer to the OS semaphore control block. |
| void os_stack_fault_handler | ( | OS_Thread * | thread | ) |
Handler for stack faults in threads.
| thread | The thread where the stack fault occurred. |
|
noexcept |
Function to Create TX thread.
| txThread | Pointer to the OS thread control block. |
| name | Name of the thread. |
| entry_function | Pointer to the thread's entry function. |
| entry_input | Input value for the thread's entry function. |
| stack | Pointer to the thread's stack. |
| stackSizeBytes | Size of the thread's stack in bytes. |
| priority | Priority of the thread. |
| preempt_threshold | Preemption threshold of the thread. |
| timeSliceAllowed | Maximum length of time (in ticks) that the thread can execute before OS will reschedule. |
| auto_start | OS_AUTO_START if the thread should start immediately, or OS_DONT_START if it should not start until explicitly resumed. |
Create the OS Thread
Add to the overall system thread count
TODO: log appropriate error here
|
noexcept |
Pinned-to-core variant of os_thread_create_ex (FreeRTOS / SMP).
Mirrors os_thread_create_ex but takes an additional core_id that is forwarded to os_thread_create_pinned. Pass core_id < 0 (e.g. -1) for "no affinity" — equivalent to the non-pinned variant.
| core_id | CPU core to pin the new task to (0 or 1 on ESP32-S3), or any value < 0 for no affinity. |
|
noexcept |
Function to Delete TX thread.
| txThread | Pointer to the OS thread control block to be deleted. |
| bool os_thread_resume_ex | ( | OS_Thread * | thread, |
| bool | suppressVerbose = true |
||
| ) |
Resumes the specified OS thread.
| thread | The OS thread to resume. |
|
noexcept |
Function to Resume TX thread only if it is suspended.
| txThread | Pointer to the OS thread control block to be resumed. |
| bool os_thread_suspend_ex | ( | OS_Thread * | thread, |
| bool | suppressVerbose = true |
||
| ) |
Suspends the specified OS thread.
| thread | The OS thread to resume. |
|
noexcept |
Activates a OS timer.
| timer | Reference to the timer to be activated. |
|
noexcept |
Creates a OS timer and reports any errors associated with the creation.
| timer | Reference to the timer control block. |
| name | Pointer to the name of the timer. |
| callback | Function pointer to the timer expiration callback function. |
| callbackExpirationInput | A uint32_t data point that can be passed to the expiration callback function. |
| initialTimeoutTicks | The initial expiration time in ticks. |
| rescheduleTimeoutTicks | The reschedule time in ticks. |
| autoActivate | Flag to indicate whether the timer should be automatically activated upon creation. |
Creates a OS timer and reports any errors associated with the creation.
| timer | Reference to timer control block. |
| name | Pointer to timer name. |
| callback | timer expiration callback function. |
| callbackExpirationInput | A uint32_t data point that can be passed to expiration callback function. |
| initialTimeoutTicks | Initial Expiration ticks. |
| rescheduleTimeoutTicks | Reschedule ticks. |
| autoActivate | The data value to set. |
|
noexcept |
Stops and deletes a OS timer, reporting any errors associated with the operation.
| timer | Reference to the timer to be stopped and deleted. |
Stops and deletes a OS timer, reporting any errors associated with the operation.
| timer | The timer to delete. |
|
noexcept |
Deactivates a OS timer.
| timer | Reference to the timer to be deactivated. |
|
staticconstexpr |
Kernel tick rate used by the millisecond/tick conversions.