40#define UTIL_SYSTEM_CLOCK (240000000.0)
42#if defined(HF_RTOS_FREERTOS) || defined(HF_RTOS_THREADX) || defined(HF_RTOS_CMSIS)
44#if defined(HF_RTOS_CMSIS) && !defined(HF_RTOS_CMSIS_TICK_RATE_HZ)
52# define HF_RTOS_CMSIS_TICK_RATE_HZ 1000U
56#if defined(HF_RTOS_FREERTOS)
57static constexpr uint32_t
osTickRateHz =
static_cast<uint32_t
>(configTICK_RATE_HZ);
58#elif defined(HF_RTOS_CMSIS)
59static constexpr uint32_t
osTickRateHz = HF_RTOS_CMSIS_TICK_RATE_HZ;
76 const uint64_t ticks =
static_cast<uint64_t
>(milliseconds) *
osTickRateHz / 1000U;
77 if (ticks >= 0xFFFFFFFFULL)
return 0xFFFFFFFEU;
78 if (ticks == 0U && milliseconds != 0U)
return 1U;
79 return static_cast<uint32_t
>(ticks);
98 if (frequency == 0U)
return 0U;
100 return (ticks == 0U) ? 1U : ticks;
171 bool suppressVerbose=
true ) noexcept;
207 bool suppressVerbose=true ) noexcept;
255 OS_Uint auto_start,
bool suppressVerbose=true) noexcept;
271 OS_Uint auto_start,
int core_id,
272 bool suppressVerbose=true) noexcept;
314 void* queueStorage,
OS_Ulong queueSize,
bool suppressVerbose=true) noexcept;
331 bool suppressVerbose=true) noexcept;
341 bool suppressVerbose=true) noexcept;
359 uint32_t callbackExpirationInput, uint32_t initialTimeoutTicks,
360 uint32_t rescheduleTimeoutTicks,
OS_Uint autoActivate,
361 bool suppressVerbose=true ) noexcept;
399 bool suppressVerbose=true) noexcept;
422 bool suppressVerbose=true) noexcept;
457 bool suppressVerbose=true) noexcept;
466 bool suppressVerbose=true) noexcept;
479 OS_Ulong wait_option,
bool suppressVerbose=true) noexcept;
493#if defined(HF_RTOS_NONE) || defined(HF_MCU_FAMILY_NONE)
513 if (frequency == 0U)
return 0U;
515 return (ticks == 0U) ? 1U : ticks;
523#if defined(HF_RTOS_NONE_EXTERNAL_CLOCK)
525static inline void os_delay_msec(uint16_t msec) { hf_os_none_delay_us((uint64_t)msec * 1000U); }
529 hf_os_none_delay_us((uint64_t)t);
531 hf_os_none_delay_us((uint64_t)t * 1000U);
533 hf_os_none_delay_us((uint64_t)t * 1000000U);
538static inline void os_delay_msec(uint16_t msec) { (void)msec; }
563 OS_Uint,
bool =
true) noexcept {
return true; }
566 OS_Uint,
int ,
bool =
true) noexcept {
return true; }
Generic RTOS abstraction — public header.
bool os_semaphore_create_ex(OS_Semaphore *txSemaphore, const char *name, OS_Uint initial_count, bool suppressVerbose=true) noexcept
Function to Create TX semaphore.
Definition OsUtility.cpp:743
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.
Definition OsUtility.cpp:172
bool os_semaphore_get_ex(OS_Semaphore *txSemaphore, OS_Ulong wait_option, bool suppressVerbose=true) noexcept
Function to get (wait for) a TX semaphore.
Definition OsUtility.cpp:804
bool os_event_flags_set_ex(OS_EventGroup &eventFlags, OS_Ulong flagsToSet, bool suppressVerbose=true) noexcept
Set event flags in the event flag group.
Definition OsUtility.cpp:900
bool os_semaphore_put_ex(OS_Semaphore *txSemaphore, bool suppressVerbose=true) noexcept
Function to put (release) a TX semaphore.
Definition OsUtility.cpp:783
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.
Definition OsUtility.cpp:151
void os_stack_fault_handler(OS_Thread *thread)
Handler for stack faults in threads.
Definition OsUtility.cpp:947
bool os_timer_deactivate_ex(OS_Timer &timer, bool suppressVerbose=true) noexcept
Deactivates a OS timer.
Definition OsUtility.cpp:707
constexpr uint32_t os_convert_msec_to_delay_ticks(uint32_t milliseconds)
Converts milliseconds to delay ticks, rounding down but never to zero.
Definition OsUtility.h:74
bool os_event_flags_delete_ex(OS_EventGroup &eventFlags, bool suppressVerbose=true) noexcept
Deletes the specified event flag group and logs any error.
Definition OsUtility.cpp:877
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).
Definition OsUtility.cpp:367
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.
Definition OsUtility.cpp:513
time_unit_t
Units used to express time values.
Definition OsUtility.h:34
@ TIME_UNIT_MS
Definition OsUtility.h:36
@ TIME_UNIT_US
Definition OsUtility.h:35
@ TIME_UNIT_S
Definition OsUtility.h:37
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.
Definition OsUtility.cpp:627
bool os_thread_delete_ex(OS_Thread *txThread, bool suppressVerbose=true) noexcept
Function to Delete TX thread.
Definition OsUtility.cpp:392
uint32_t os_get_processor_cycle_count()
Gets the processor's current cycle count.
Definition OsUtility.cpp:117
bool os_mutex_put_ex(OS_Mutex &mutex_ptr, bool suppressVerbose=true) noexcept
Release a TX mutex.
Definition OsUtility.cpp:243
bool os_thread_resume_if_suspended(OS_Thread *txThread, bool suppressVerbose=true) noexcept
Function to Resume TX thread only if it is suspended.
Definition OsUtility.cpp:437
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.
Definition OsUtility.cpp:343
static constexpr uint32_t osTickRateHz
Definition OsUtility.h:57
bool os_thread_resume_ex(OS_Thread *thread, bool suppressVerbose=true)
Resumes the specified OS thread.
Definition OsUtility.cpp:406
constexpr uint32_t os_convert_delay_ticks_to_msec(uint32_t delayTicks)
Converts delay ticks to milliseconds.
Definition OsUtility.h:85
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.
Definition OsUtility.cpp:933
bool os_queue_delete_ex(OS_Queue &queue, bool suppressVerbose=true) noexcept
Deletes the specified queue and logs any error.
Definition OsUtility.cpp:540
uint32_t os_get_elapsed_time_msec()
Retrieves the elapsed time in milliseconds.
Definition OsUtility.cpp:65
bool os_thread_suspend_ex(OS_Thread *thread, bool suppressVerbose=true)
Suspends the specified OS thread.
Definition OsUtility.cpp:473
bool os_semaphore_delete_ex(OS_Semaphore *txSemaphore, bool suppressVerbose=true) noexcept
Function to Delete TX semaphore.
Definition OsUtility.cpp:763
bool os_mutex_get_ex(OS_Mutex &mutex_ptr, OS_Ulong wait_option, bool suppressVerbose=true) noexcept
Acquire (wait for) a TX mutex.
Definition OsUtility.cpp:200
OS_Ulong os_semaphore_get_count_ex(OS_Semaphore *txSemaphore, bool suppressVerbose=true) noexcept
Function to get TX semaphore count.
Definition OsUtility.cpp:824
bool os_mutex_delete_p(OS_Mutex *mutex, bool suppressVerbose=true) noexcept
Deletes the specified mutex and logs any error.
Definition OsUtility.cpp:301
bool os_event_flags_clear_ex(OS_EventGroup &eventFlags, OS_Ulong flagsToClear, bool suppressVerbose=true) noexcept
Clears event flags in the event flag group.
Definition OsUtility.cpp:915
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.
Definition OsUtility.h:96
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.
Definition OsUtility.cpp:580
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.
Definition OsUtility.cpp:564
bool os_mutex_delete_ex(OS_Mutex &mutex, bool suppressVerbose=true) noexcept
Deletes the specified mutex and logs any error.
Definition OsUtility.cpp:284
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.
Definition OsUtility.cpp:851
void os_delay_time(uint32_t timeBetweenSamples, time_unit_t timeUnit)
Delays execution for the specified number of time.
Definition OsUtility.cpp:38
void os_delay_msec(uint16_t msec)
Delays execution for the specified number of milliseconds.
Definition OsUtility.cpp:28
bool os_mutex_put_p(OS_Mutex *mutex_ptr, bool suppressVerbose=true) noexcept
Release a TX mutex.
Definition OsUtility.cpp:264
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 acqui...
Definition OsUtility.cpp:70
bool os_timer_activate_ex(OS_Timer &timer, bool suppressVerbose=true) noexcept
Activates a OS timer.
Definition OsUtility.cpp:683
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.
Definition OsUtility.cpp:659
bool os_mutex_get_p(OS_Mutex *mutex_ptr, OS_Ulong wait_option, bool suppressVerbose=true) noexcept
Acquire (wait for) a TX mutex.
Definition OsUtility.cpp:222
@ OS_INHERIT
Definition os_cmsis.h:56
@ OS_WAIT_FOREVER
Definition os_cmsis.h:48
osEventFlagsId_t OS_EventGroup
Definition os_cmsis.h:31
unsigned int OS_Uint
Definition os_cmsis.h:36
osMessageQueueId_t OS_Queue
Definition os_cmsis.h:30
unsigned long OS_Ulong
Definition os_cmsis.h:35
osThreadId_t OS_Thread
Definition os_cmsis.h:27
osTimerId_t OS_Timer
Definition os_cmsis.h:32
osSemaphoreId_t OS_Semaphore
Definition os_cmsis.h:29
osMutexId_t OS_Mutex
Definition os_cmsis.h:28