CHERIoT RTOS
A compartmentalised RTOS for CHERIoT hardware
Loading...
Searching...
No Matches
event_groups.h
Go to the documentation of this file.
1#pragma once
2#include "FreeRTOS.h"
3#include <event.h>
4#include <stdint.h>
5#include <stdlib.h>
6
7/**
8 * \file
9 * \brief FreeRTOS event-group compatibility APIs.
10 *
11 * This file defines the compatibility wrappers for FreeRTOS's event groups.
12 * This is intended for porting code from FreeRTOS and should not be used in
13 * new CHERIoT software. The functions in this file wrap the APIs exposed in
14 * event.h. These are implemented in the `event_group` shared library, which
15 * must be linked to the final firmware image.
16 */
17
18/**
19 * Type for bits in an event group.
20 */
21typedef uint32_t EventBits_t;
22
23/**
24 * Type for event group handles.
25 */
26typedef struct EventGroup *EventGroupHandle_t;
27
28/**
29 * Create a new event group on the heap. Returns NULL on allocation failure.
30 */
32{
33 struct EventGroup *ret;
34 struct Timeout timeout = {0, UnlimitedTimeout};
35 int rv = eventgroup_create(&timeout, MALLOC_CAPABILITY, &ret);
36
37 if (rv == 0)
38 {
39 return ret;
40 }
41 return NULL;
42}
43
44/**
45 * Set bits in an event group. Returns the new value of the event group after
46 * this call. If the timeout expires, the new bits may not have been set.
47 */
49 const EventBits_t uxBitsToSet)
50{
51 EventBits_t ret;
52 struct Timeout timeout = {0, UnlimitedTimeout};
53 eventgroup_set(&timeout, xEventGroup, &ret, uxBitsToSet);
54 return ret;
55}
56
57/**
58 * Wait for bits in an event group to be set. Returns the new value of the
59 * bits that are currently set. Blocks until either the timeout expires or
60 * some or all `uxBitsToWaitFor` are set, depending on the value of
61 * `xWaitForAllBits`. If `xClearOnExit` is true, the bits that were set are
62 * cleared before returning.
63 */
65 const EventBits_t uxBitsToWaitFor,
66 const BaseType_t xClearOnExit,
67 const BaseType_t xWaitForAllBits,
68 TickType_t xTicksToWait)
69{
70 uint32_t ret;
71 struct Timeout timeout = {0, xTicksToWait};
72 int rv = eventgroup_wait(&timeout,
73 xEventGroup,
74 &ret,
75 uxBitsToWaitFor,
76 xWaitForAllBits,
77 xClearOnExit);
78 return ret;
79}
80
81/**
82 * Delete an event group.
83 */
84static inline void vEventGroupDelete(EventGroupHandle_t xEventGroup)
85{
86 eventgroup_destroy(MALLOC_CAPABILITY, xEventGroup);
87}
FreeRTOS porting layer.
int32_t BaseType_t
FreeRTOS default signed integer type.
Definition FreeRTOS.h:179
Ticks TickType_t
FreeRTOS type for durations expressed in ticks.
Definition FreeRTOS.h:175
Event-group APIs.
int __cheri_libcall eventgroup_wait(TimeoutArgument timeout, struct EventGroup *group, uint32_t *outBits, uint32_t bitsWanted, _Bool waitForAll, _Bool clearOnExit)
Wait for events in an event group.
int __cheri_libcall eventgroup_create(TimeoutArgument timeout, AllocatorCapability heapCapability, struct EventGroup **outGroup)
Create a new event group, allocated using heapCapability.
int __cheri_libcall eventgroup_destroy(AllocatorCapability heapCapability, struct EventGroup *group)
Destroy an event group.
int __cheri_libcall eventgroup_set(TimeoutArgument timeout, struct EventGroup *group, uint32_t *outBits, uint32_t bitsToSet)
Set one or more bits in an event group.
static EventBits_t xEventGroupWaitBits(EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToWaitFor, const BaseType_t xClearOnExit, const BaseType_t xWaitForAllBits, TickType_t xTicksToWait)
Wait for bits in an event group to be set.
static EventGroupHandle_t xEventGroupCreate(void)
Create a new event group on the heap.
uint32_t EventBits_t
Type for bits in an event group.
struct EventGroup * EventGroupHandle_t
Type for event group handles.
static void vEventGroupDelete(EventGroupHandle_t xEventGroup)
Delete an event group.
static EventBits_t xEventGroupSetBits(EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet)
Set bits in an event group.
Structure representing a timeout.
Definition timeout.h:47
static const Ticks UnlimitedTimeout
Value indicating an unbounded timeout for use with Timeout.
Definition timeout.h:22