21#if !defined(CHERIOT_EXPOSE_FREERTOS_SEMAPHORE) && \
22 !defined(CHERIOT_EXPOSE_FREERTOS_MUTEX) && \
23 !defined(CHERIOT_EXPOSE_FREERTOS_RECURSIVE_MUTEX)
24# error At least one out of CHERIOT_EXPOSE_FREERTOS_SEMAPHORE, \
25 CHERIOT_EXPOSE_FREERTOS_MUTEX, or CHERIOT_EXPOSE_FREERTOS_RECURSIVE_MUTEX \
29#ifdef CHERIOT_EXPOSE_FREERTOS_SEMAPHORE
30# define CHERIOT_FREERTOS_SEMAPHORE_CASE(x) \
31 case CheriotFreeRTOS_Semaphore: \
35# define CHERIOT_FREERTOS_SEMAPHORE_CASE(x)
38#ifdef CHERIOT_EXPOSE_FREERTOS_MUTEX
39# define CHERIOT_FREERTOS_MUTEX_CASE(x) \
40 case CheriotFreeRTOS_Mutex: \
44# define CHERIOT_FREERTOS_MUTEX_CASE(x)
47#ifdef CHERIOT_EXPOSE_FREERTOS_RECURSIVE_MUTEX
48# define CHERIOT_FREERTOS_RECURSIVE_MUTEX_CASE(x) \
49 case CheriotFreeRTOS_RecursiveMutex: \
53# define CHERIOT_FREERTOS_RECURSIVE_MUTEX_CASE(x)
62#ifdef CHERIOT_EXPOSE_FREERTOS_SEMAPHORE
68#ifdef CHERIOT_EXPOSE_FREERTOS_MUTEX
74#ifdef CHERIOT_EXPOSE_FREERTOS_RECURSIVE_MUTEX
93#ifdef CHERIOT_EXPOSE_FREERTOS_RECURSIVE_MUTEX
96#ifdef CHERIOT_EXPOSE_FREERTOS_MUTEX
99#ifdef CHERIOT_EXPOSE_FREERTOS_SEMAPHORE
103#if (defined(CHERIOT_EXPOSE_FREERTOS_SEMAPHORE) + \
104 defined(CHERIOT_EXPOSE_FREERTOS_MUTEX) + \
105 defined(CHERIOT_EXPOSE_FREERTOS_RECURSIVE_MUTEX)) > 1
106# define CHERIOT_FREERTOS_SEMAPHORE_SWITCH(x) switch (x->kind)
112# define CHERIOT_FREERTOS_SEMAPHORE_KIND_SET(x, y) x->kind = y
114# if defined(CHERIOT_EXPOSE_FREERTOS_RECURSIVE_MUTEX)
115# define CHERIOT_FREERTOS_SEMAPHORE_SWITCH(x) \
116 switch (CheriotFreeRTOS_RecursiveMutex)
117# elif defined(CHERIOT_EXPOSE_FREERTOS_MUTEX)
118# define CHERIOT_FREERTOS_SEMAPHORE_SWITCH(x) \
119 switch (CheriotFreeRTOS_Mutex)
120# elif defined(CHERIOT_EXPOSE_FREERTOS_SEMAPHORE)
121# define CHERIOT_FREERTOS_SEMAPHORE_SWITCH(x) \
122 switch (CheriotFreeRTOS_Semaphore)
125# define CHERIOT_FREERTOS_SEMAPHORE_KIND_SET(x, y)
134#ifdef CHERIOT_EXPOSE_FREERTOS_SEMAPHORE
146 pxSemaphoreBuffer->semaphore.
maxCount = uxMaxCount;
148 pxSemaphoreBuffer->semaphore.count = uxInitialCount;
151 atomic_init(&pxSemaphoreBuffer->semaphore.count, uxInitialCount);
153 CHERIOT_FREERTOS_SEMAPHORE_KIND_SET(pxSemaphoreBuffer,
155 return pxSemaphoreBuffer;
158# ifndef CHERIOT_NO_AMBIENT_MALLOC
170 if (semaphore != NULL)
202#ifdef CHERIOT_EXPOSE_FREERTOS_MUTEX
209 pxMutexBuffer->mutex.lockWord = 0;
211 return pxMutexBuffer;
214# ifndef CHERIOT_NO_AMBIENT_MALLOC
222 if (semaphore != NULL)
231#ifdef CHERIOT_EXPOSE_FREERTOS_RECURSIVE_MUTEX
239 pxMutexBuffer->recursiveMutex.
lock.lockWord = 0;
240 pxMutexBuffer->recursiveMutex.
depth = 0;
241 CHERIOT_FREERTOS_SEMAPHORE_KIND_SET(pxMutexBuffer,
243 return pxMutexBuffer;
246# ifndef CHERIOT_NO_AMBIENT_MALLOC
255 if (semaphore != NULL)
270__always_inline
static inline void
287 CHERIOT_FREERTOS_SEMAPHORE_SWITCH(xMutex)
289 CHERIOT_FREERTOS_SEMAPHORE_CASE(
return 0;)
290 CHERIOT_FREERTOS_RECURSIVE_MUTEX_CASE(
291 return xMutex->recursiveMutex.
lock.lockWord & 0xffff;)
292 CHERIOT_FREERTOS_MUTEX_CASE(
return xMutex->mutex.lockWord & 0xffff;)
307 CHERIOT_FREERTOS_SEMAPHORE_SWITCH(xSemaphore)
309 CHERIOT_FREERTOS_SEMAPHORE_CASE(
return xSemaphore->semaphore.count;)
310 CHERIOT_FREERTOS_RECURSIVE_MUTEX_CASE(
311 return xSemaphore->recursiveMutex.
lock.lockWord != 0;)
312 CHERIOT_FREERTOS_MUTEX_CASE(
return xSemaphore->mutex.lockWord != 0;)
327 CHERIOT_FREERTOS_SEMAPHORE_SWITCH(xSemaphore)
329 CHERIOT_FREERTOS_SEMAPHORE_CASE(
331 CHERIOT_FREERTOS_MUTEX_CASE(
334 CHERIOT_FREERTOS_RECURSIVE_MUTEX_CASE(;);
349__always_inline
static inline _Bool __attribute__((overloadable))
353 *pxHigherPriorityTaskWoken = 0;
361__always_inline
static inline _Bool __attribute__((overloadable))
375 CHERIOT_FREERTOS_SEMAPHORE_SWITCH(xSemaphore)
377 CHERIOT_FREERTOS_SEMAPHORE_CASE(
382 CHERIOT_FREERTOS_RECURSIVE_MUTEX_CASE(;);
395__always_inline
static inline _Bool __attribute__((overloadable))
399 *pxHigherPriorityTaskWoken = 0;
407__always_inline
static inline _Bool __attribute__((overloadable))
417__always_inline
static inline _Bool
422 CHERIOT_FREERTOS_SEMAPHORE_SWITCH(xMutex)
424 CHERIOT_FREERTOS_SEMAPHORE_CASE(;)
425 CHERIOT_FREERTOS_MUTEX_CASE(;)
426 CHERIOT_FREERTOS_RECURSIVE_MUTEX_CASE(
435__always_inline
static inline _Bool
439 CHERIOT_FREERTOS_SEMAPHORE_SWITCH(xMutex)
441 CHERIOT_FREERTOS_SEMAPHORE_CASE(;)
442 CHERIOT_FREERTOS_MUTEX_CASE(;)
443 CHERIOT_FREERTOS_RECURSIVE_MUTEX_CASE(
456 *ppxSemaphoreBuffer = xSemaphore;
int32_t BaseType_t
FreeRTOS default signed integer type.
Ticks TickType_t
FreeRTOS type for durations expressed in ticks.
uint32_t UBaseType_t
FreeRTOS default unsigned integer type.
uint16_t TaskHandle_t
FreeRTOS type representing a task handle, mapped to a thread ID in CHERIoT RTOS.
#define pdTRUE
FreeRTOS definition of true.
C compatible interface to synchronisation primitives.
int __cheri_libcall semaphore_get(TimeoutArgument timeout, struct CountingSemaphoreState *semaphore)
Semaphore get operation, decrements the semaphore count.
int __cheri_libcall recursivemutex_unlock(struct RecursiveMutexState *mutex)
Unlock a recursive mutex.
void __cheri_libcall flaglock_unlock(struct FlagLockState *lock)
Unlock a flag lock.
int __cheri_libcall flaglock_priority_inheriting_trylock(TimeoutArgument timeout, struct FlagLockState *lock)
Try to lock a flag lock.
int __cheri_libcall recursivemutex_trylock(TimeoutArgument timeout, struct RecursiveMutexState *lock)
Try to acquire a recursive mutex.
int __cheri_libcall semaphore_put(struct CountingSemaphoreState *semaphore)
Semaphore put operation.
static SemaphoreHandle_t xSemaphoreCreateBinary()
Create a heap-allocated binary semaphore.
static SemaphoreHandle_t xSemaphoreCreateCounting(UBaseType_t uxMaxCount, UBaseType_t uxInitialCount)
Allocate a counting semaphore on the heap.
static _Bool xSemaphoreTakeRecursive(SemaphoreHandle_t xMutex, TickType_t xTicksToWait)
Try to acquire a recursive mutex.
static BaseType_t xSemaphoreGetStaticBuffer(SemaphoreHandle_t xSemaphore, StaticSemaphore_t **ppxSemaphoreBuffer)
Launder a semaphore back into the type used to initialise it.
static void vSemaphoreDelete(SemaphoreHandle_t xSemaphore)
Delete a heap-allocated semaphore, of any kind.
static UBaseType_t uxSemaphoreGetCount(SemaphoreHandle_t xSemaphore)
Returns the current count of a counting semaphore, or whether a mutex or binary semaphore is availabl...
static SemaphoreHandle_t xSemaphoreCreateRecursiveMutex(void)
Create a heap-allocated recursive mutex.
static SemaphoreHandle_t xSemaphoreCreateRecursiveMutexStatic(StaticSemaphore_t *pxMutexBuffer)
Create a statically allocated recursive mutex.
static SemaphoreHandle_t xSemaphoreCreateCountingStatic(UBaseType_t uxMaxCount, UBaseType_t uxInitialCount, StaticSemaphore_t *pxSemaphoreBuffer)
Initialise a statically allocated semaphore.
static _Bool xSemaphoreGive(SemaphoreHandle_t xSemaphore)
A semaphore put (up) operation.
static SemaphoreHandle_t xSemaphoreCreateMutexStatic(StaticSemaphore_t *pxMutexBuffer)
Create statically allocated mutex.
static TaskHandle_t xSemaphoreGetMutexHolder(SemaphoreHandle_t xMutex)
Get the current owner (thread ID) of a mutex.
static _Bool xSemaphoreTakeFromISR(SemaphoreHandle_t xSemaphore, BaseType_t *pxHigherPriorityTaskWoken)
Take a semaphore from code that may run in an ISR.
static _Bool xSemaphoreGiveFromISR(SemaphoreHandle_t xSemaphore, BaseType_t *pxHigherPriorityTaskWoken)
Give a semaphore from code that may run in an ISR.
static SemaphoreHandle_t xSemaphoreCreateMutex()
Create a heap-allocated mutex.
static SemaphoreHandle_t xSemaphoreCreateBinaryStatic(StaticSemaphore_t *pxSemaphoreBuffer)
Create a statically allocated binary semaphore.
static _Bool xSemaphoreTake(SemaphoreHandle_t xSemaphore, TickType_t xTicksToWait)
A semaphore get (down) operation.
StaticSemaphore_t * SemaphoreHandle_t
Type for a handle to a counting semaphore.
CheriotFreeRTOS_SemaphoreKind
Enumeration used to differentiate the different kinds of FreeRTOS semaphores in this compatibility la...
@ CheriotFreeRTOS_Mutex
A non-recursive, priority-inheriting mutex.
@ CheriotFreeRTOS_Semaphore
A FreeRTOS counting or binary semaphore.
@ CheriotFreeRTOS_RecursiveMutex
A recursive mutex.
static _Bool xSemaphoreGiveRecursive(SemaphoreHandle_t xMutex)
Release a recursive mutex.
This file implements the C11 and C++23 C atomics interfaces.
State for a counting semaphore.
uint32_t maxCount
The maximum value for the counter.
State for a recursive mutex.
uint16_t depth
The count of the times the lock has been acquired by the same thread.
struct FlagLockState lock
The underlying lock.
Type used to define space for storing any of the exposed FreeRTOS semaphore types.
enum CheriotFreeRTOS_SemaphoreKind kind
The discriminator for the union above.
Structure representing a timeout.