-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathos_port_freertos.h
246 lines (199 loc) · 5.13 KB
/
os_port_freertos.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
/**
* @file os_port_freertos.h
* @brief RTOS abstraction layer (FreeRTOS)
*
* @section License
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
* Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* @author Oryx Embedded SARL (www.oryx-embedded.com)
* @version 2.4.4
**/
#ifndef _OS_PORT_FREERTOS_H
#define _OS_PORT_FREERTOS_H
//Dependencies
#ifdef IDF_VER
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/semphr.h"
#else
#include "FreeRTOS.h"
#include "task.h"
#include "semphr.h"
#endif
//Invalid task identifier
#define OS_INVALID_TASK_ID NULL
//Self task identifier
#define OS_SELF_TASK_ID NULL
//Task priority (normal)
#ifndef OS_TASK_PRIORITY_NORMAL
#define OS_TASK_PRIORITY_NORMAL (tskIDLE_PRIORITY + 1)
#endif
//Task priority (high)
#ifndef OS_TASK_PRIORITY_HIGH
#define OS_TASK_PRIORITY_HIGH (tskIDLE_PRIORITY + 2)
#endif
//Milliseconds to system ticks
#ifndef OS_MS_TO_SYSTICKS
#define OS_MS_TO_SYSTICKS(n) (n)
#endif
//System ticks to milliseconds
#ifndef OS_SYSTICKS_TO_MS
#define OS_SYSTICKS_TO_MS(n) (n)
#endif
//Retrieve 64-bit system time (not implemented)
#ifndef osGetSystemTime64
#define osGetSystemTime64() osGetSystemTime()
#endif
//Task prologue
#ifndef osEnterTask
#define osEnterTask()
#endif
//Task epilogue
#ifndef osExitTask
#define osExitTask()
#endif
//Interrupt service routine prologue
#ifndef osEnterIsr
#if defined(portENTER_SWITCHING_ISR)
#define osEnterIsr() portENTER_SWITCHING_ISR()
#else
#define osEnterIsr()
#endif
#endif
//Interrupt service routine epilogue
#ifndef osExitIsr
#if defined(__XTENSA__)
#define osExitIsr(flag) if(flag) portYIELD_FROM_ISR()
#elif defined(portEXIT_SWITCHING_ISR)
#define osExitIsr(flag) portEXIT_SWITCHING_ISR()
#elif defined(portEND_SWITCHING_ISR)
#define osExitIsr(flag) portEND_SWITCHING_ISR(flag)
#elif defined(portYIELD_FROM_ISR)
#define osExitIsr(flag) portYIELD_FROM_ISR(flag)
#else
#define osExitIsr(flag)
#endif
#endif
//Static object allocation
#ifndef configSUPPORT_STATIC_ALLOCATION
#define configSUPPORT_STATIC_ALLOCATION 0
#endif
//C++ guard
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief System time
**/
typedef TickType_t systime_t;
/**
* @brief Task identifier
**/
typedef TaskHandle_t OsTaskId;
/**
* @brief Task parameters
**/
typedef struct
{
#if (configSUPPORT_STATIC_ALLOCATION == 1)
StaticTask_t *tcb;
#ifdef IDF_VER
uint32_t *stack;
#else
StackType_t *stack;
#endif
#endif
size_t stackSize;
uint_t priority;
} OsTaskParameters;
/**
* @brief Event object
**/
typedef struct
{
SemaphoreHandle_t handle;
#if (configSUPPORT_STATIC_ALLOCATION == 1)
StaticSemaphore_t buffer;
#endif
} OsEvent;
/**
* @brief Semaphore object
**/
typedef struct
{
SemaphoreHandle_t handle;
#if (configSUPPORT_STATIC_ALLOCATION == 1)
StaticSemaphore_t buffer;
#endif
} OsSemaphore;
/**
* @brief Mutex object
**/
typedef struct
{
SemaphoreHandle_t handle;
#if (configSUPPORT_STATIC_ALLOCATION == 1)
StaticSemaphore_t buffer;
#endif
} OsMutex;
/**
* @brief Task routine
**/
typedef void (*OsTaskCode)(void *arg);
//Default task parameters
extern const OsTaskParameters OS_TASK_DEFAULT_PARAMS;
//Kernel management
void osInitKernel(void);
void osStartKernel(void);
//Task management
OsTaskId osCreateTask(const char_t *name, OsTaskCode taskCode, void *arg,
const OsTaskParameters *params);
void osDeleteTask(OsTaskId taskId);
void osDelayTask(systime_t delay);
void osSwitchTask(void);
void osSuspendAllTasks(void);
void osResumeAllTasks(void);
//Event management
bool_t osCreateEvent(OsEvent *event);
void osDeleteEvent(OsEvent *event);
void osSetEvent(OsEvent *event);
void osResetEvent(OsEvent *event);
bool_t osWaitForEvent(OsEvent *event, systime_t timeout);
bool_t osSetEventFromIsr(OsEvent *event);
//Semaphore management
bool_t osCreateSemaphore(OsSemaphore *semaphore, uint_t count);
void osDeleteSemaphore(OsSemaphore *semaphore);
bool_t osWaitForSemaphore(OsSemaphore *semaphore, systime_t timeout);
void osReleaseSemaphore(OsSemaphore *semaphore);
//Mutex management
bool_t osCreateMutex(OsMutex *mutex);
void osDeleteMutex(OsMutex *mutex);
void osAcquireMutex(OsMutex *mutex);
void osReleaseMutex(OsMutex *mutex);
//System time
systime_t osGetSystemTime(void);
//Memory management
void *osAllocMem(size_t size);
void osFreeMem(void *p);
//C++ guard
#ifdef __cplusplus
}
#endif
#endif