32#include "OsAbstraction.h"
38#if defined(HF_RTOS_FREERTOS)
50struct FreeRtosMutexBackend {
52 using RecursiveMutexHandle = OS_Mutex;
53 using MutexHandle = OS_Mutex;
56 static constexpr uint32_t MAX_DELAY =
static_cast<uint32_t
>(OS_WAIT_FOREVER);
57 static constexpr uint32_t TICK_RATE_HZ = configTICK_RATE_HZ;
61 static inline void createRecursive(RecursiveMutexHandle* h)
noexcept {
62 os_recursive_mutex_create(h,
"PlatMtx");
65 static inline void destroyRecursive(RecursiveMutexHandle* h)
noexcept {
67 os_recursive_mutex_delete(h);
72 static inline bool lockRecursive(RecursiveMutexHandle* h, uint32_t timeout_ticks)
noexcept {
73 return os_recursive_mutex_get(h,
static_cast<OS_Ulong
>(timeout_ticks)) == OS_SUCCESS;
76 static inline bool tryLockRecursive(RecursiveMutexHandle* h)
noexcept {
77 return os_recursive_mutex_get(h, OS_NO_WAIT) == OS_SUCCESS;
80 static inline void unlockRecursive(RecursiveMutexHandle* h)
noexcept {
81 os_recursive_mutex_put(h);
86 static inline void createMutex(MutexHandle* h)
noexcept {
87 os_mutex_create(h,
"PlatShrd", OS_INHERIT);
90 static inline void destroyMutex(MutexHandle* h)
noexcept {
97 static inline bool lockMutex(MutexHandle* h, uint32_t timeout_ticks)
noexcept {
98 return os_mutex_get(h,
static_cast<OS_Ulong
>(timeout_ticks)) == OS_SUCCESS;
101 static inline bool tryLockMutex(MutexHandle* h)
noexcept {
102 return os_mutex_get(h, OS_NO_WAIT) == OS_SUCCESS;
105 static inline void unlockMutex(MutexHandle* h)
noexcept {
111 static inline uint32_t getTickCount() noexcept {
112 return static_cast<uint32_t
>(os_time_get());
115 static inline uint32_t msToTicks(uint32_t ms)
noexcept {
116 return static_cast<uint32_t
>(pdMS_TO_TICKS(ms));
119 static inline void yield() noexcept {
125using PlatformMutexActiveBackend = FreeRtosMutexBackend;
128#define PLATFORM_MUTEX_BACKEND_CONFIGURED