PER Firmware
Loading...
Searching...
No Matches
rtos.h File Reference

Wrapper macros for FreeRTOS constructs (tasks, queues, semaphores) to simplify static memory allocation and initialization. More...

#include "FreeRTOS.h"
#include "list.h"
#include "queue.h"
#include "semphr.h"
#include "task.h"
#include "timers.h"
#include <stdint.h>
Include dependency graph for rtos.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  RTOS_periodic_task_params_t
 
struct  RTOS_queue_params_t
 

Macros

#define RTOS_DEFINE_TASK(NAME, PERIOD_MS, PRIORITY, STACK_SIZE)
 Defines a statically allocated periodic FreeRTOS task.
 
#define RTOS_START_TASK(NAME)
 Creates and starts a previously defined task.
 
#define RTOS_HANDLE_OF(NAME)
 Retrieves the FreeRTOS task handle for the defined task.
 
#define RTOS_DEFINE_QUEUE(NAME, ITEM, COUNT)
 Scaffolds the static memory for a FreeRTOS queue.
 
#define RTOS_INIT_QUEUE(NAME)
 Initializes the defined static queue.
 
#define RTOS_DEFINE_SEMAPHORE(NAME)
 Scaffolds the static memory for a semaphore (and related variants).
 
#define RTOS_DEFINE_MUTEX(NAME)
 
#define RTOS_DEFINE_COUNTING_SEMAPHORE(NAME)
 
#define RTOS_DEFINE_BINARY_SEMAPHORE(NAME)
 
#define RTOS_INIT_MUTEX(NAME)
 Initializes the defined mutex.
 
#define RTOS_INIT_COUNTING_SEMAPHORE(NAME, MAX_COUNT)
 Initializes the defined static counting semaphore.
 
#define RTOS_INIT_BINARY_SEMAPHORE(NAME)
 Initializes the defined static binary semaphore.
 

Enumerations

enum  RTOS_stack_size_t : size_t {
  STACK_256 = 256 , STACK_512 = 512 , STACK_1024 = 1024 , STACK_2048 = 2048 ,
  STACK_4096 = 4096
}
 Stack size aliases. More...
 
enum  RTOS_task_priority_t : UBaseType_t { TASK_PRIORITY_LOW = 8 , TASK_PRIORITY_NORMAL = 24 , TASK_PRIORITY_HIGH = 40 }
 Priority aliases. More...
 

Functions

static void RTOS_delay_ms (uint32_t ms)
 Delays the current task for the specified number of milliseconds.
 
void RTOS_periodic_task_runner (void *arg)
 

Detailed Description

Wrapper macros for FreeRTOS constructs (tasks, queues, semaphores) to simplify static memory allocation and initialization.

Author
Irving Wang (irvin.nosp@m.gw@p.nosp@m.urdue.nosp@m..edu)
Millan Kumar (kumar.nosp@m.798@.nosp@m.purdu.nosp@m.e.ed.nosp@m.u)
Ronak Jain (jain7.nosp@m.17@p.nosp@m.urdue.nosp@m..edu)

Macro Definition Documentation

◆ RTOS_DEFINE_BINARY_SEMAPHORE

#define RTOS_DEFINE_BINARY_SEMAPHORE ( NAME)
Value:
#define RTOS_DEFINE_SEMAPHORE(NAME)
Scaffolds the static memory for a semaphore (and related variants).
Definition rtos.h:160

◆ RTOS_DEFINE_COUNTING_SEMAPHORE

#define RTOS_DEFINE_COUNTING_SEMAPHORE ( NAME)
Value:

◆ RTOS_DEFINE_MUTEX

#define RTOS_DEFINE_MUTEX ( NAME)
Value:

◆ RTOS_DEFINE_QUEUE

#define RTOS_DEFINE_QUEUE ( NAME,
ITEM,
COUNT )
Value:
static_assert(COUNT > 0, "Queue count must be greater than 0"); \
\
static StaticQueue_t NAME##_cb; \
static uint8_t NAME##_data[sizeof(ITEM) * (COUNT)]; \
\
static RTOS_queue_params_t NAME##_params = { \
.item_size = sizeof(ITEM), \
.item_count = (COUNT), \
}; \
\
QueueHandle_t NAME; \
Definition rtos.h:126

Scaffolds the static memory for a FreeRTOS queue.

◆ RTOS_DEFINE_SEMAPHORE

#define RTOS_DEFINE_SEMAPHORE ( NAME)
Value:
SemaphoreHandle_t NAME; \
static StaticSemaphore_t NAME##_cb;

Scaffolds the static memory for a semaphore (and related variants).

◆ RTOS_DEFINE_TASK

#define RTOS_DEFINE_TASK ( NAME,
PERIOD_MS,
PRIORITY,
STACK_SIZE )
Value:
static_assert( \
(STACK_SIZE) % sizeof(StackType_t) == 0, \
"Stack size must be a multiple of StackType_t" \
); \
\
static StaticTask_t NAME##_tcb; \
static StackType_t NAME##_stack[(STACK_SIZE) / sizeof(StackType_t)]; \
\
static RTOS_periodic_task_params_t NAME##_params = { \
.taskFunction = (void (*)(void))NAME, \
.period_ms = (PERIOD_MS), \
.priority = (PRIORITY), \
}; \
\
TaskHandle_t NAME##_handle
Definition rtos.h:53

Defines a statically allocated periodic FreeRTOS task.

Allocates memory statically here: task control block (TCB), stack, task parameters, and task handle

The task is not created until RTOS_START_TASK is called.

The task will be executed periodically by periodic_task_runner.

Parameters
NAMEName of the task function.
PERIOD_MSExecution period in milliseconds.
PRIORITYFreeRTOS task priority.
STACK_SIZEStack size in bytes

◆ RTOS_HANDLE_OF

#define RTOS_HANDLE_OF ( NAME)
Value:
(NAME##_handle)

Retrieves the FreeRTOS task handle for the defined task.

◆ RTOS_INIT_BINARY_SEMAPHORE

#define RTOS_INIT_BINARY_SEMAPHORE ( NAME)
Value:
(NAME = xSemaphoreCreateBinaryStatic(&(NAME##_cb)))

Initializes the defined static binary semaphore.

◆ RTOS_INIT_COUNTING_SEMAPHORE

#define RTOS_INIT_COUNTING_SEMAPHORE ( NAME,
MAX_COUNT )
Value:
(NAME = xSemaphoreCreateCountingStatic((MAX_COUNT), 0, &(NAME##_cb)))

Initializes the defined static counting semaphore.

Note
initial count is set to 0 (empty)

◆ RTOS_INIT_MUTEX

#define RTOS_INIT_MUTEX ( NAME)
Value:
(NAME = xSemaphoreCreateMutexStatic(&(NAME##_cb)))

Initializes the defined mutex.

◆ RTOS_INIT_QUEUE

#define RTOS_INIT_QUEUE ( NAME)
Value:
(NAME = xQueueCreateStatic( \
NAME##_params.item_count, \
NAME##_params.item_size, \
NAME##_data, \
&NAME##_cb))

Initializes the defined static queue.

◆ RTOS_START_TASK

#define RTOS_START_TASK ( NAME)
Value:
(NAME##_handle = xTaskCreateStatic( \
#NAME, \
sizeof(NAME##_stack) / sizeof(StackType_t), \
&NAME##_params, \
NAME##_params.priority, \
NAME##_stack, \
&NAME##_tcb))
void RTOS_periodic_task_runner(void *arg)
Definition rtos.c:13

Creates and starts a previously defined task.

Creates the task using xTaskCreateStatic() and stores the resulting task handle in the handle generated by RTOS_DEFINE_TASK.

This macro should be called once after the scheduler has been initialized and before vTaskStartScheduler().

Parameters
NAMEName passed to RTOS_DEFINE_TASK.
Returns
TaskHandle_t for the created task, or NULL if task creation failed.

Enumeration Type Documentation

◆ RTOS_stack_size_t

enum RTOS_stack_size_t : size_t

Stack size aliases.

Enumerator
STACK_256 
STACK_512 
STACK_1024 
STACK_2048 
STACK_4096 

◆ RTOS_task_priority_t

enum RTOS_task_priority_t : UBaseType_t

Priority aliases.

Enumerator
TASK_PRIORITY_LOW 
TASK_PRIORITY_NORMAL 
TASK_PRIORITY_HIGH 

Function Documentation

◆ RTOS_delay_ms()

static void RTOS_delay_ms ( uint32_t ms)
inlinestatic

Delays the current task for the specified number of milliseconds.

This is a convenience wrapper around vTaskDelay() that automatically converts milliseconds to FreeRTOS ticks.

Parameters
msDelay duration in milliseconds.
Here is the caller graph for this function:

◆ RTOS_periodic_task_runner()

void RTOS_periodic_task_runner ( void * arg)