RTOS Wrapper
API reference
Loading...
Searching...
No Matches
Classes | Macros | Typedefs | Enumerations | Functions | Variables
os_freertos.h File Reference

FreeRTOS backend for the generic OS abstraction. More...

#include "FreeRTOS.h"
#include "task.h"
#include "semphr.h"
#include "queue.h"
#include "event_groups.h"
#include "timers.h"
#include "stream_buffer.h"
#include <stddef.h>
#include <stdint.h>

Go to the source code of this file.

Classes

struct  os_thread_start_t
 
struct  os_timer_cb_t
 

Macros

#define HF_OS_FREERTOS_PREFIXED   0
 
#define HF_OS_FREERTOS_SMP   0
 
#define HF_OS_FREERTOS_STATIC_QUEUE   0
 
#define OS_QUEUE_STORE_BYTES(item_words, length)   ((size_t)0)
 

Typedefs

typedef TaskHandle_t OS_Thread
 
typedef SemaphoreHandle_t OS_Mutex
 
typedef SemaphoreHandle_t OS_Semaphore
 
typedef QueueHandle_t OS_Queue
 
typedef EventGroupHandle_t OS_EventGroup
 
typedef TimerHandle_t OS_Timer
 
typedef StreamBufferHandle_t OS_StreamBuffer
 
typedef unsigned long OS_Ulong
 
typedef unsigned int OS_Uint
 
typedef uint8_t OS_Critical
 

Enumerations

enum  {
  OS_WAIT_FOREVER = portMAX_DELAY , OS_NO_WAIT = 0 , OS_SUCCESS = 0 , OS_AND = 1 ,
  OS_OR = 2 , OS_EVENT_CLEAR = 0x10 , OS_AUTO_START = 1 , OS_DONT_START = 0 ,
  OS_INHERIT = 0
}
 
enum  { OS_THREAD_READY = eReady , OS_THREAD_SUSPENDED = eSuspended , OS_THREAD_BLOCKED = eBlocked }
 

Functions

static OS_Ulong os_time_get (void)
 
static void os_thread_start_trampoline (void *p)
 
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)
 
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.
 
static int os_get_current_core_id (void)
 
static OS_Uint os_thread_resume (OS_Thread *t)
 
static OS_Uint os_thread_suspend (OS_Thread *t)
 
static OS_Uint os_thread_delete (OS_Thread *t)
 
static OS_Uint os_thread_terminate (OS_Thread *t)
 
static OS_Uint os_thread_info_get (OS_Thread *t, OS_Uint *state)
 
static OS_Uint os_thread_sleep (OS_Ulong ticks)
 
static OS_Uint os_thread_yield (void)
 
static int os_kernel_is_running (void)
 
static OS_Uint os_thread_is_current (const OS_Thread *t)
 
static int os_thread_is_live (const OS_Thread *t)
 
static void os_thread_clear (OS_Thread *t)
 
static int os_mutex_is_live (const OS_Mutex *m)
 
static int os_thread_state_is_suspended (OS_Uint state)
 
static OS_Uint os_mutex_create (OS_Mutex *m, const char *name, OS_Uint inherit)
 
static OS_Uint os_mutex_get (OS_Mutex *m, OS_Ulong wait)
 
static OS_Uint os_mutex_put (OS_Mutex *m)
 
static OS_Uint os_mutex_delete (OS_Mutex *m)
 
static OS_Uint os_recursive_mutex_create (OS_Mutex *m, const char *name)
 
static OS_Uint os_recursive_mutex_get (OS_Mutex *m, OS_Ulong wait)
 
static OS_Uint os_recursive_mutex_put (OS_Mutex *m)
 
static OS_Uint os_recursive_mutex_delete (OS_Mutex *m)
 
static OS_Uint os_semaphore_create (OS_Semaphore *s, const char *name, OS_Uint initial)
 
static OS_Uint os_semaphore_delete (OS_Semaphore *s)
 
static OS_Uint os_semaphore_put (OS_Semaphore *s)
 
static OS_Uint os_semaphore_get (OS_Semaphore *s, OS_Ulong wait)
 
static OS_Uint os_semaphore_info_get (OS_Semaphore *s, OS_Ulong *count)
 
static OS_Uint os_queue_create (OS_Queue *q, const char *name, OS_Uint item_words, void *store, OS_Ulong length)
 
static OS_Uint os_queue_delete (OS_Queue *q)
 
static OS_Uint os_queue_send (OS_Queue *q, void *msg, OS_Ulong wait)
 
static OS_Uint os_queue_receive (OS_Queue *q, void *msg, OS_Ulong wait)
 
static OS_Uint os_event_group_create (OS_EventGroup *g, const char *name)
 
static OS_Uint os_event_group_delete (OS_EventGroup *g)
 
static OS_Uint os_event_group_set (OS_EventGroup *g, OS_Ulong flags)
 
static OS_Uint os_event_group_clear (OS_EventGroup *g, OS_Ulong flags)
 
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.
 
static void os_timer_trampoline (TimerHandle_t timer)
 
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)
 
static OS_Uint os_timer_delete (OS_Timer *t)
 
static OS_Uint os_timer_activate (OS_Timer *t)
 
static OS_Uint os_timer_deactivate (OS_Timer *t)
 
static OS_Uint os_stream_buffer_create (OS_StreamBuffer *b, size_t capacity, size_t trigger)
 
static OS_Uint os_stream_buffer_delete (OS_StreamBuffer *b)
 
static OS_Uint os_stream_buffer_send (OS_StreamBuffer *b, const void *data, size_t len, OS_Ulong wait)
 
static OS_Uint os_stream_buffer_receive (OS_StreamBuffer *b, void *data, size_t len, OS_Ulong wait)
 
static void os_critical_enter (void)
 
static void os_critical_exit (void)
 

Variables

OS_Critical os_critical_mux
 

Detailed Description

FreeRTOS backend for the generic OS abstraction.

Included only by OsAbstraction.h when HF_RTOS_FREERTOS is selected. Do not include this header directly.

Supported flavors

Flavor Kernel headers Task affinity Critical section
Vanilla (CubeMX, ARM_CMx ports) flat FreeRTOS.h single core ISR masking
ESP-IDF SMP freertos/FreeRTOS.h pinned-to-core spinlock (portMUX_TYPE)

Both are detected here, at the port layer. A consumer build must not force-include a compatibility header or synthesize a freertos/ include directory to satisfy this backend.

See also
os/README.md

Macro Definition Documentation

◆ HF_OS_FREERTOS_PREFIXED

#define HF_OS_FREERTOS_PREFIXED   0

◆ HF_OS_FREERTOS_SMP

#define HF_OS_FREERTOS_SMP   0

◆ HF_OS_FREERTOS_STATIC_QUEUE

#define HF_OS_FREERTOS_STATIC_QUEUE   0

◆ OS_QUEUE_STORE_BYTES

#define OS_QUEUE_STORE_BYTES (   item_words,
  length 
)    ((size_t)0)

Typedef Documentation

◆ OS_Critical

typedef uint8_t OS_Critical

Unused on single-core; kept so the storage symbol is flavor-independent.

◆ OS_EventGroup

typedef EventGroupHandle_t OS_EventGroup

◆ OS_Mutex

typedef SemaphoreHandle_t OS_Mutex

◆ OS_Queue

typedef QueueHandle_t OS_Queue

◆ OS_Semaphore

typedef SemaphoreHandle_t OS_Semaphore

◆ OS_StreamBuffer

typedef StreamBufferHandle_t OS_StreamBuffer

◆ OS_Thread

typedef TaskHandle_t OS_Thread

Generic handle types used by the wrapper.

◆ OS_Timer

typedef TimerHandle_t OS_Timer

◆ OS_Uint

typedef unsigned int OS_Uint

◆ OS_Ulong

typedef unsigned long OS_Ulong

Common integral aliases.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
OS_WAIT_FOREVER 
OS_NO_WAIT 
OS_SUCCESS 
OS_AND 
OS_OR 
OS_EVENT_CLEAR 

OR into an event-group wait option: clear the awaited bits on success

OS_AUTO_START 
OS_DONT_START 
OS_INHERIT 

◆ anonymous enum

anonymous enum

Portable thread-state aliases (FreeRTOS eTaskState).

Enumerator
OS_THREAD_READY 
OS_THREAD_SUSPENDED 
OS_THREAD_BLOCKED 

Function Documentation

◆ os_critical_enter()

static void os_critical_enter ( void  )
inlinestatic

◆ os_critical_exit()

static void os_critical_exit ( void  )
inlinestatic

◆ os_event_group_clear()

static OS_Uint os_event_group_clear ( OS_EventGroup *  g,
OS_Ulong  flags 
)
inlinestatic

◆ os_event_group_create()

static OS_Uint os_event_group_create ( OS_EventGroup *  g,
const char *  name 
)
inlinestatic

◆ os_event_group_delete()

static OS_Uint os_event_group_delete ( OS_EventGroup *  g)
inlinestatic

◆ os_event_group_get()

static OS_Uint os_event_group_get ( OS_EventGroup *  g,
OS_Ulong  flags,
OS_Uint  option,
OS_Ulong *  actual,
OS_Ulong  wait 
)
inlinestatic

Wait for event bits.

Parameters
optionOS_AND (all of flags) or OS_OR (any of them), optionally OR-ed with OS_EVENT_CLEAR to clear flags when the wait is satisfied. Without OS_EVENT_CLEAR no bit is cleared.
Returns
OS_SUCCESS when the condition was met; 1 on timeout. actual receives the bits seen (before any clear) either way.

◆ os_event_group_set()

static OS_Uint os_event_group_set ( OS_EventGroup *  g,
OS_Ulong  flags 
)
inlinestatic

◆ os_get_current_core_id()

static int os_get_current_core_id ( void  )
inlinestatic

Core index the calling task runs on; always 0 on single-core kernels.

◆ os_kernel_is_running()

static int os_kernel_is_running ( void  )
inlinestatic

◆ os_mutex_create()

static OS_Uint os_mutex_create ( OS_Mutex *  m,
const char *  name,
OS_Uint  inherit 
)
inlinestatic

◆ os_mutex_delete()

static OS_Uint os_mutex_delete ( OS_Mutex *  m)
inlinestatic

◆ os_mutex_get()

static OS_Uint os_mutex_get ( OS_Mutex *  m,
OS_Ulong  wait 
)
inlinestatic

◆ os_mutex_is_live()

static int os_mutex_is_live ( const OS_Mutex *  m)
inlinestatic

◆ os_mutex_put()

static OS_Uint os_mutex_put ( OS_Mutex *  m)
inlinestatic

◆ os_queue_create()

static OS_Uint os_queue_create ( OS_Queue *  q,
const char *  name,
OS_Uint  item_words,
void *  store,
OS_Ulong  length 
)
inlinestatic

◆ os_queue_delete()

static OS_Uint os_queue_delete ( OS_Queue *  q)
inlinestatic

◆ os_queue_receive()

static OS_Uint os_queue_receive ( OS_Queue *  q,
void *  msg,
OS_Ulong  wait 
)
inlinestatic

◆ os_queue_send()

static OS_Uint os_queue_send ( OS_Queue *  q,
void *  msg,
OS_Ulong  wait 
)
inlinestatic

◆ os_recursive_mutex_create()

static OS_Uint os_recursive_mutex_create ( OS_Mutex *  m,
const char *  name 
)
inlinestatic

◆ os_recursive_mutex_delete()

static OS_Uint os_recursive_mutex_delete ( OS_Mutex *  m)
inlinestatic

◆ os_recursive_mutex_get()

static OS_Uint os_recursive_mutex_get ( OS_Mutex *  m,
OS_Ulong  wait 
)
inlinestatic

◆ os_recursive_mutex_put()

static OS_Uint os_recursive_mutex_put ( OS_Mutex *  m)
inlinestatic

◆ os_semaphore_create()

static OS_Uint os_semaphore_create ( OS_Semaphore *  s,
const char *  name,
OS_Uint  initial 
)
inlinestatic

◆ os_semaphore_delete()

static OS_Uint os_semaphore_delete ( OS_Semaphore *  s)
inlinestatic

◆ os_semaphore_get()

static OS_Uint os_semaphore_get ( OS_Semaphore *  s,
OS_Ulong  wait 
)
inlinestatic

◆ os_semaphore_info_get()

static OS_Uint os_semaphore_info_get ( OS_Semaphore *  s,
OS_Ulong *  count 
)
inlinestatic

◆ os_semaphore_put()

static OS_Uint os_semaphore_put ( OS_Semaphore *  s)
inlinestatic

◆ os_stream_buffer_create()

static OS_Uint os_stream_buffer_create ( OS_StreamBuffer *  b,
size_t  capacity,
size_t  trigger 
)
inlinestatic

◆ os_stream_buffer_delete()

static OS_Uint os_stream_buffer_delete ( OS_StreamBuffer *  b)
inlinestatic

◆ os_stream_buffer_receive()

static OS_Uint os_stream_buffer_receive ( OS_StreamBuffer *  b,
void *  data,
size_t  len,
OS_Ulong  wait 
)
inlinestatic

◆ os_stream_buffer_send()

static OS_Uint os_stream_buffer_send ( OS_StreamBuffer *  b,
const void *  data,
size_t  len,
OS_Ulong  wait 
)
inlinestatic

◆ os_thread_clear()

static void os_thread_clear ( OS_Thread *  t)
inlinestatic

◆ os_thread_create()

static OS_Uint os_thread_create ( OS_Thread *  t,
const char *  name,
void(*)(OS_Ulong)  entry,
OS_Ulong  input,
uint8_t *  stack,
OS_Ulong  stack_size,
OS_Uint  priority,
OS_Uint  preempt,
OS_Ulong  slice,
OS_Uint  auto_start 
)
inlinestatic

◆ os_thread_create_pinned()

static OS_Uint os_thread_create_pinned ( OS_Thread *  t,
const char *  name,
void(*)(OS_Ulong)  entry,
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 
)
inlinestatic

Core-affinity variant of os_thread_create.

Parameters
core_idCPU core to pin to; negative means "no affinity".

On a single-core kernel there is nothing to pin to, so this degrades to os_thread_create and core_id is ignored. That is a property of the kernel, not a build workaround.

◆ os_thread_delete()

static OS_Uint os_thread_delete ( OS_Thread *  t)
inlinestatic

◆ os_thread_info_get()

static OS_Uint os_thread_info_get ( OS_Thread *  t,
OS_Uint *  state 
)
inlinestatic

◆ os_thread_is_current()

static OS_Uint os_thread_is_current ( const OS_Thread *  t)
inlinestatic

◆ os_thread_is_live()

static int os_thread_is_live ( const OS_Thread *  t)
inlinestatic

◆ os_thread_resume()

static OS_Uint os_thread_resume ( OS_Thread *  t)
inlinestatic

◆ os_thread_sleep()

static OS_Uint os_thread_sleep ( OS_Ulong  ticks)
inlinestatic

◆ os_thread_start_trampoline()

static void os_thread_start_trampoline ( void *  p)
inlinestatic

◆ os_thread_state_is_suspended()

static int os_thread_state_is_suspended ( OS_Uint  state)
inlinestatic

◆ os_thread_suspend()

static OS_Uint os_thread_suspend ( OS_Thread *  t)
inlinestatic

◆ os_thread_terminate()

static OS_Uint os_thread_terminate ( OS_Thread *  t)
inlinestatic

◆ os_thread_yield()

static OS_Uint os_thread_yield ( void  )
inlinestatic

◆ os_time_get()

static OS_Ulong os_time_get ( void  )
inlinestatic

◆ os_timer_activate()

static OS_Uint os_timer_activate ( OS_Timer *  t)
inlinestatic

◆ os_timer_create()

static OS_Uint os_timer_create ( OS_Timer *  t,
const char *  name,
void(*)(OS_Ulong)  cb,
OS_Ulong  id,
OS_Ulong  initial,
OS_Ulong  reload,
OS_Uint  auto_act 
)
inlinestatic

◆ os_timer_deactivate()

static OS_Uint os_timer_deactivate ( OS_Timer *  t)
inlinestatic

◆ os_timer_delete()

static OS_Uint os_timer_delete ( OS_Timer *  t)
inlinestatic

◆ os_timer_trampoline()

static void os_timer_trampoline ( TimerHandle_t  timer)
inlinestatic

Variable Documentation

◆ os_critical_mux

OS_Critical os_critical_mux
extern