PER Firmware
Loading...
Searching...
No Matches
freertos.h
Go to the documentation of this file.
1
#ifndef PER_FREERTOS_H
2
#define PER_FREERTOS_H
3
12
// clang-format off
13
#define myIDENT(x) x
14
#define myXSTR(x) #x
15
#define mySTR(x) myXSTR(x)
16
#define __FREERTOS_PATH(x,y) mySTR(myIDENT(x)y)
17
#define _FREERTOS_PATH(y) __FREERTOS_PATH(_FREERTOS_DIR, y)
18
19
#if defined(STM32F407xx)
20
#define _FREERTOS_DIR external/STM32CubeF4/Middlewares/Third_Party/FreeRTOS/Source/
21
#elif defined(STM32G474xx)
22
#define _FREERTOS_DIR external/STM32CubeG4/Middlewares/Third_Party/FreeRTOS/Source/
23
#else
24
#error "Unsupported MCU arch"
25
#endif
26
27
#include _FREERTOS_PATH(include/FreeRTOS.h)
28
#include _FREERTOS_PATH(CMSIS_RTOS_V2/cmsis_os2.h)
29
30
#include _FREERTOS_PATH(include/list.h)
31
#include _FREERTOS_PATH(include/queue.h)
32
#include _FREERTOS_PATH(include/semphr.h)
33
#include _FREERTOS_PATH(include/task.h)
34
#include _FREERTOS_PATH(include/timers.h)
35
// clang-format on
36
37
#include <stdint.h>
38
39
// Stack size defs
40
#define STACK_256 (256)
41
#define STACK_512 (512)
42
#define STACK_1024 (1024)
43
#define STACK_2048 (2048)
44
#define STACK_4096 (4096)
45
46
typedef
struct
{
47
void (*taskFunction)(void);
48
uint32_t period_ms;
49
}
periodic_task_params_t
;
50
51
// this is the function actually scheduled by freertos
52
void
periodic_task_runner(
void
*arg);
53
62
#define DEFINE_TASK(NAME, PERIOD_MS, PRIORITY, STACK_SIZE) \
63
static_assert( \
64
(STACK_SIZE) % sizeof(StackType_t) == 0, \
65
"Stack size must be a multiple of StackType_t" \
66
); \
67
static StaticTask_t NAME##_tcb; \
68
static StackType_t NAME##_stack[(STACK_SIZE) / sizeof(StackType_t)]; \
69
periodic_task_params_t NAME##_params = { \
70
.taskFunction = (void (*)(void))NAME, \
71
.period_ms = (PERIOD_MS), \
72
}; \
73
osThreadAttr_t NAME##_attrs = { \
74
.name = #NAME, \
75
.attr_bits = osThreadDetached, \
76
.cb_mem = &NAME##_tcb, \
77
.cb_size = sizeof(StaticTask_t), \
78
.stack_mem = NAME##_stack, \
79
.stack_size = sizeof(NAME##_stack), \
80
.priority = (osPriority_t)(PRIORITY), \
81
}; \
82
osThreadId_t NAME##_handle;
83
87
#define START_TASK(NAME) \
88
(NAME##_handle = osThreadNew(periodic_task_runner, &NAME##_params, &NAME##_attrs))
89
93
#define getTaskHandle(NAME) (NAME##_handle)
94
98
#define DEFINE_QUEUE(NAME, ITEM, COUNT) \
99
static_assert(COUNT > 0, "Queue count must be greater than 0"); \
100
QueueHandle_t NAME; \
101
static StaticQueue_t NAME##_cb; \
102
static uint8_t NAME##_data[sizeof(ITEM) * (COUNT)];
103
107
#define INIT_QUEUE(NAME, ITEM, COUNT) \
108
(NAME = xQueueCreateStatic((COUNT), sizeof(ITEM), NAME##_data, &NAME##_cb))
109
113
#define DEFINE_SEMAPHORE(NAME) \
114
SemaphoreHandle_t NAME; \
115
static StaticSemaphore_t NAME##_cb;
116
117
// Aliases for clarity
118
#define DEFINE_MUTEX(NAME) DEFINE_SEMAPHORE(NAME)
119
#define DEFINE_COUNTING_SEMAPHORE(NAME) DEFINE_SEMAPHORE(NAME)
120
#define DEFINE_BINARY_SEMAPHORE(NAME) DEFINE_SEMAPHORE(NAME)
121
125
#define INIT_MUTEX(NAME) \
126
(NAME = xSemaphoreCreateMutexStatic(&(NAME##_cb)))
127
132
#define INIT_COUNTING_SEMAPHORE(NAME, MAX_COUNT) \
133
(NAME = xSemaphoreCreateCountingStatic((MAX_COUNT), (MAX_COUNT), &(NAME##_cb)))
134
138
#define INIT_BINARY_SEMAPHORE(NAME) \
139
(NAME = xSemaphoreCreateBinaryStatic(&(NAME##_cb)))
140
141
142
// Timing helper macros
143
#define getTick() xTaskGetTickCount()
144
#define getMS() (getTick() * portTICK_PERIOD_MS)
145
#define mDelay(ms) (osDelay(pdMS_TO_TICKS((ms))))
146
147
#endif
// PER_FREERTOS_H
periodic_task_params_t
Definition
freertos.h:46
common
freertos
freertos.h
Generated by
1.12.0