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>
Go to the source code of this file.
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)
◆ 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 | ) |
|
◆ RTOS_DEFINE_MUTEX
| #define RTOS_DEFINE_MUTEX |
( |
| NAME | ) |
|
◆ 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)]; \
\
.item_size = sizeof(ITEM), \
.item_count = (COUNT), \
}; \
\
QueueHandle_t NAME; \
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)]; \
\
.taskFunction = (void (*)(void))NAME, \
.period_ms = (PERIOD_MS), \
.priority = (PRIORITY), \
}; \
\
TaskHandle_t NAME##_handle
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
-
| NAME | Name of the task function. |
| PERIOD_MS | Execution period in milliseconds. |
| PRIORITY | FreeRTOS task priority. |
| STACK_SIZE | Stack size in bytes |
◆ RTOS_HANDLE_OF
| #define RTOS_HANDLE_OF |
( |
| NAME | ) |
|
Value:
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
-
| NAME | Name passed to RTOS_DEFINE_TASK. |
- Returns
- TaskHandle_t for the created task, or NULL if task creation failed.
◆ RTOS_stack_size_t
Stack size aliases.
| Enumerator |
|---|
| STACK_256 | |
| STACK_512 | |
| STACK_1024 | |
| STACK_2048 | |
| STACK_4096 | |
◆ RTOS_task_priority_t
Priority aliases.
| Enumerator |
|---|
| TASK_PRIORITY_LOW | |
| TASK_PRIORITY_NORMAL | |
| TASK_PRIORITY_HIGH | |
◆ 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
-
| ms | Delay duration in milliseconds. |
◆ RTOS_periodic_task_runner()
| void RTOS_periodic_task_runner |
( |
void * | arg | ) |
|