27#if defined(__has_include)
28# if __has_include("freertos/FreeRTOS.h")
29# define HF_OS_FREERTOS_PREFIXED 1
31# define HF_OS_FREERTOS_PREFIXED 0
33#elif defined(ESP_PLATFORM)
34# define HF_OS_FREERTOS_PREFIXED 1
36# define HF_OS_FREERTOS_PREFIXED 0
39#if HF_OS_FREERTOS_PREFIXED
40# include "freertos/FreeRTOS.h"
41# include "freertos/task.h"
42# include "freertos/semphr.h"
43# include "freertos/queue.h"
44# include "freertos/event_groups.h"
45# include "freertos/timers.h"
46# include "freertos/stream_buffer.h"
52# include "event_groups.h"
54# include "stream_buffer.h"
64#if defined(ESP_PLATFORM) || \
65 (defined(portNUM_PROCESSORS) && (portNUM_PROCESSORS > 1)) || \
66 (defined(configNUM_CORES) && (configNUM_CORES > 1))
67# define HF_OS_FREERTOS_SMP 1
69# define HF_OS_FREERTOS_SMP 0
130 if (!params)
return 1;
131 params->
entry = entry;
134 stack_size /
sizeof(StackType_t), params,
159 OS_Uint auto_start,
int core_id)
161#if HF_OS_FREERTOS_SMP
164 if (!params)
return 1;
165 params->
entry = entry;
167 const BaseType_t affinity =
168 (core_id < 0) ? tskNO_AFFINITY : (BaseType_t)core_id;
170 stack_size /
sizeof(StackType_t),
171 params, priority, t, affinity);
182 priority, preempt, slice, auto_start);
189#if HF_OS_FREERTOS_SMP
190 return (
int)xPortGetCoreID();
203 *state = eTaskGetState(*t);
210{
return xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED; }
212{
return (t != 0 && *t != 0 && xTaskGetCurrentTaskHandle() == *t) ? 1u : 0u; }
223 return (t != 0) && (*t != 0);
233 return (m != 0) && (*m != 0);
237 return (state == (
OS_Uint)eSuspended) || (state == (
OS_Uint)eBlocked);
245 *m = xSemaphoreCreateMutex();
256 *m = xSemaphoreCreateRecursiveMutex();
267 *s = xSemaphoreCreateCounting(UINT16_MAX, initial);
276 *count = uxSemaphoreGetCount(*s);
288#if defined(configSUPPORT_STATIC_ALLOCATION) && (configSUPPORT_STATIC_ALLOCATION == 1)
289# define HF_OS_FREERTOS_STATIC_QUEUE 1
291# define HF_OS_FREERTOS_QUEUE_ALIGN (2U * sizeof(void *))
293# define OS_QUEUE_STORE_BYTES(item_words, length) \
294 ((HF_OS_FREERTOS_QUEUE_ALIGN - 1U) + sizeof(StaticQueue_t) + \
295 (size_t)(item_words) * sizeof(uint32_t) * (size_t)(length))
297# define HF_OS_FREERTOS_STATIC_QUEUE 0
298# define OS_QUEUE_STORE_BYTES(item_words, length) ((size_t)0)
306 const size_t item_size = (size_t)item_words *
sizeof(uint32_t);
307 if (item_size == 0U || length == 0U)
309#if HF_OS_FREERTOS_STATIC_QUEUE
312 const uintptr_t align = (uintptr_t)HF_OS_FREERTOS_QUEUE_ALIGN;
313 const uintptr_t cb = ((uintptr_t)store + align - 1U) & ~(align - 1U);
314 *q = xQueueCreateStatic((UBaseType_t)length, (UBaseType_t)item_size,
315 (uint8_t *)(cb +
sizeof(StaticQueue_t)), (StaticQueue_t *)cb);
318 *q = xQueueCreate((UBaseType_t)length, (UBaseType_t)item_size);
330 *g = xEventGroupCreate();
335{ xEventGroupSetBits(*g, flags);
return OS_SUCCESS; }
337{ xEventGroupClearBits(*g, flags);
return OS_SUCCESS; }
352 const EventBits_t want = (EventBits_t)flags;
353 const EventBits_t bits = xEventGroupWaitBits(*g, want, clear ? pdTRUE : pdFALSE,
354 all ? pdTRUE : pdFALSE, (TickType_t)wait);
357 const int met = all ? ((bits & want) == want) : ((bits & want) != 0U);
370 params->
cb(params->
id);
379 if (!params)
return 1;
383 *t = xTimerCreate(name, initial, reload != 0, (
void *)params,
406 *b = xStreamBufferCreate(capacity, trigger);
413{
return xStreamBufferReceive(*b, data, len, wait) > 0 ?
OS_SUCCESS : (
OS_Uint)1; }
419#if HF_OS_FREERTOS_SMP
void * OS_StreamBuffer
Definition os_cmsis.h:33
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
uint8_t OS_Critical
Definition os_cmsis.h:426
osSemaphoreId_t OS_Semaphore
Definition os_cmsis.h:29
osMutexId_t OS_Mutex
Definition os_cmsis.h:28
static void os_critical_enter(void)
Definition os_freertos.h:428
static OS_Uint os_semaphore_put(OS_Semaphore *s)
Definition os_freertos.h:271
static OS_Uint os_queue_delete(OS_Queue *q)
Definition os_freertos.h:322
static OS_Uint os_thread_create_pinned(OS_Thread *t, const char *name, void(*entry)(OS_Ulong), OS_Ulong input, uint8_t *stack, OS_Ulong stack_size, OS_Uint priority, OS_Uint preempt, OS_Ulong slice, OS_Uint auto_start, int core_id)
Core-affinity variant of os_thread_create.
Definition os_freertos.h:154
static OS_Uint os_queue_create(OS_Queue *q, const char *name, OS_Uint item_words, void *store, OS_Ulong length)
Definition os_freertos.h:301
static int os_mutex_is_live(const OS_Mutex *m)
Definition os_freertos.h:231
static OS_Uint os_semaphore_get(OS_Semaphore *s, OS_Ulong wait)
Definition os_freertos.h:272
static void os_thread_start_trampoline(void *p)
Definition os_freertos.h:109
static OS_Uint os_thread_suspend(OS_Thread *t)
Definition os_freertos.h:197
static OS_Uint os_thread_resume(OS_Thread *t)
Definition os_freertos.h:196
static OS_Uint os_recursive_mutex_create(OS_Mutex *m, const char *name)
Definition os_freertos.h:253
static OS_Uint os_event_group_set(OS_EventGroup *g, OS_Ulong flags)
Definition os_freertos.h:334
static OS_Uint os_mutex_put(OS_Mutex *m)
Definition os_freertos.h:249
static OS_Uint os_event_group_get(OS_EventGroup *g, OS_Ulong flags, OS_Uint option, OS_Ulong *actual, OS_Ulong wait)
Wait for event bits.
Definition os_freertos.h:347
OS_Critical os_critical_mux
Definition CriticalSection.cpp:11
static OS_Uint os_semaphore_create(OS_Semaphore *s, const char *name, OS_Uint initial)
Definition os_freertos.h:264
EventGroupHandle_t OS_EventGroup
Definition os_freertos.h:81
static OS_Uint os_event_group_delete(OS_EventGroup *g)
Definition os_freertos.h:333
static int os_kernel_is_running(void)
Definition os_freertos.h:209
static OS_Uint os_mutex_get(OS_Mutex *m, OS_Ulong wait)
Definition os_freertos.h:248
static OS_Uint os_mutex_delete(OS_Mutex *m)
Definition os_freertos.h:250
static OS_Uint os_event_group_clear(OS_EventGroup *g, OS_Ulong flags)
Definition os_freertos.h:336
static OS_Uint os_semaphore_info_get(OS_Semaphore *s, OS_Ulong *count)
Definition os_freertos.h:273
static void os_critical_exit(void)
Definition os_freertos.h:429
SemaphoreHandle_t OS_Semaphore
Definition os_freertos.h:79
StreamBufferHandle_t OS_StreamBuffer
Definition os_freertos.h:83
static OS_Uint os_timer_create(OS_Timer *t, const char *name, void(*cb)(OS_Ulong), OS_Ulong id, OS_Ulong initial, OS_Ulong reload, OS_Uint auto_act)
Definition os_freertos.h:373
static int os_thread_is_live(const OS_Thread *t)
Definition os_freertos.h:221
static OS_Uint os_stream_buffer_send(OS_StreamBuffer *b, const void *data, size_t len, OS_Ulong wait)
Definition os_freertos.h:410
static OS_Uint os_thread_create(OS_Thread *t, const char *name, void(*entry)(OS_Ulong), OS_Ulong input, uint8_t *stack, OS_Ulong stack_size, OS_Uint priority, OS_Uint preempt, OS_Ulong slice, OS_Uint auto_start)
Definition os_freertos.h:116
unsigned int OS_Uint
Definition os_freertos.h:87
static void os_thread_clear(OS_Thread *t)
Definition os_freertos.h:225
static void os_timer_trampoline(TimerHandle_t timer)
Definition os_freertos.h:367
static OS_Uint os_queue_receive(OS_Queue *q, void *msg, OS_Ulong wait)
Definition os_freertos.h:324
static OS_Uint os_thread_delete(OS_Thread *t)
Definition os_freertos.h:198
static int os_get_current_core_id(void)
Definition os_freertos.h:187
@ OS_AUTO_START
Definition os_freertos.h:96
@ OS_SUCCESS
Definition os_freertos.h:92
@ OS_EVENT_CLEAR
Definition os_freertos.h:95
@ OS_DONT_START
Definition os_freertos.h:97
@ OS_INHERIT
Definition os_freertos.h:98
@ OS_OR
Definition os_freertos.h:94
@ OS_WAIT_FOREVER
Definition os_freertos.h:90
@ OS_AND
Definition os_freertos.h:93
@ OS_NO_WAIT
Definition os_freertos.h:91
static OS_Uint os_timer_deactivate(OS_Timer *t)
Definition os_freertos.h:401
static OS_Uint os_mutex_create(OS_Mutex *m, const char *name, OS_Uint inherit)
Definition os_freertos.h:241
unsigned long OS_Ulong
Definition os_freertos.h:86
static OS_Uint os_recursive_mutex_put(OS_Mutex *m)
Definition os_freertos.h:260
static OS_Uint os_recursive_mutex_delete(OS_Mutex *m)
Definition os_freertos.h:261
static OS_Uint os_stream_buffer_receive(OS_StreamBuffer *b, void *data, size_t len, OS_Ulong wait)
Definition os_freertos.h:412
uint8_t OS_Critical
Definition os_freertos.h:426
static OS_Uint os_timer_activate(OS_Timer *t)
Definition os_freertos.h:400
static OS_Uint os_stream_buffer_delete(OS_StreamBuffer *b)
Definition os_freertos.h:409
static OS_Uint os_thread_terminate(OS_Thread *t)
Definition os_freertos.h:199
@ OS_THREAD_READY
Definition os_freertos.h:216
@ OS_THREAD_BLOCKED
Definition os_freertos.h:218
@ OS_THREAD_SUSPENDED
Definition os_freertos.h:217
static OS_Uint os_thread_yield(void)
Definition os_freertos.h:207
static OS_Ulong os_time_get(void)
Definition os_freertos.h:101
TaskHandle_t OS_Thread
Definition os_freertos.h:77
static OS_Uint os_event_group_create(OS_EventGroup *g, const char *name)
Definition os_freertos.h:327
TimerHandle_t OS_Timer
Definition os_freertos.h:82
static OS_Uint os_queue_send(OS_Queue *q, void *msg, OS_Ulong wait)
Definition os_freertos.h:323
static OS_Uint os_recursive_mutex_get(OS_Mutex *m, OS_Ulong wait)
Definition os_freertos.h:259
static OS_Uint os_thread_is_current(const OS_Thread *t)
Definition os_freertos.h:211
static OS_Uint os_thread_sleep(OS_Ulong ticks)
Definition os_freertos.h:206
SemaphoreHandle_t OS_Mutex
Definition os_freertos.h:78
static int os_thread_state_is_suspended(OS_Uint state)
Definition os_freertos.h:235
static OS_Uint os_timer_delete(OS_Timer *t)
Definition os_freertos.h:393
static OS_Uint os_stream_buffer_create(OS_StreamBuffer *b, size_t capacity, size_t trigger)
Definition os_freertos.h:404
QueueHandle_t OS_Queue
Definition os_freertos.h:80
static OS_Uint os_semaphore_delete(OS_Semaphore *s)
Definition os_freertos.h:270
static OS_Uint os_thread_info_get(OS_Thread *t, OS_Uint *state)
Definition os_freertos.h:200
unsigned long OS_Ulong
Definition os_none.h:34
Definition os_freertos.h:104
OS_Ulong arg
Definition os_freertos.h:106
void(* entry)(OS_Ulong)
Definition os_freertos.h:105
Definition os_freertos.h:362
OS_Ulong id
Definition os_freertos.h:364
void(* cb)(OS_Ulong)
Definition os_freertos.h:363