os_port.h
Go to the documentation of this file.
1 /**
2  * @file os_port.h
3  * @brief RTOS abstraction layer
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2025 Oryx Embedded SARL. All rights reserved.
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software Foundation,
23  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24  *
25  * @author Oryx Embedded SARL (www.oryx-embedded.com)
26  * @version 2.5.0
27  **/
28 
29 #ifndef _OS_PORT_H
30 #define _OS_PORT_H
31 
32 //Dependencies
33 #include "os_port_config.h"
34 #include "compiler_port.h"
35 
36 //Compilation flags used to enable/disable features
37 #define ENABLED 1
38 #define DISABLED 0
39 
40 #define timeCompare(t1, t2) ((int32_t) ((t1) - (t2)))
41 
42 //Miscellaneous macros
43 #if !defined(__AT32F403A_407_LIBRARY_VERSION) && \
44  !defined(__AT32F435_437_LIBRARY_VERSION)
45  #ifndef FALSE
46  #define FALSE 0
47  #endif
48 
49  #ifndef TRUE
50  #define TRUE 1
51  #endif
52 #endif
53 
54 #ifndef LSB
55  #define LSB(x) ((x) & 0xFF)
56 #endif
57 
58 #ifndef MSB
59  #define MSB(x) (((x) >> 8) & 0xFF)
60 #endif
61 
62 #ifndef MIN
63  #define MIN(a, b) ((a) < (b) ? (a) : (b))
64 #endif
65 
66 #ifndef MAX
67  #define MAX(a, b) ((a) > (b) ? (a) : (b))
68 #endif
69 
70 #ifndef arraysize
71  #define arraysize(a) (sizeof(a) / sizeof(a[0]))
72 #endif
73 
74 //Infinite delay
75 #define INFINITE_DELAY ((uint_t) -1)
76 //Maximum delay
77 #define MAX_DELAY (INFINITE_DELAY / 2)
78 
79 //No RTOS?
80 #if defined(USE_NO_RTOS)
81  #include "os_port_none.h"
82 //ChibiOS/RT port?
83 #elif defined(USE_CHIBIOS)
84  #include "os_port_chibios.h"
85 //CMX-RTX port?
86 #elif defined(USE_CMX_RTX)
87  #include "os_port_cmx_rtx.h"
88 //CMSIS-RTOS port?
89 #elif defined(USE_CMSIS_RTOS)
90  #include "os_port_cmsis_rtos.h"
91 //CMSIS-RTOS2 port?
92 #elif defined(USE_CMSIS_RTOS2)
93  #include "os_port_cmsis_rtos2.h"
94 //FreeRTOS port?
95 #elif defined(USE_FREERTOS)
96  #include "os_port_freertos.h"
97 //SafeRTOS port?
98 #elif defined(USE_SAFERTOS)
99  #include "os_port_safertos.h"
100 //Eclipse ThreadX port?
101 #elif defined(USE_THREADX)
102  #include "os_port_threadx.h"
103 //Keil RTX port?
104 #elif defined(USE_RTX)
105  #include "os_port_rtx.h"
106 //Micrium uC/OS-II port?
107 #elif defined(USE_UCOS2)
108  #include "os_port_ucos2.h"
109 //Micrium uC/OS-III port?
110 #elif defined(USE_UCOS3)
111  #include "os_port_ucos3.h"
112 //PX5 port?
113 #elif defined(USE_PX5)
114  #include "os_port_px5.h"
115 //Segger embOS port?
116 #elif defined(USE_EMBOS)
117  #include "os_port_embos.h"
118 //TI SYS/BIOS port?
119 #elif defined(USE_SYS_BIOS)
120  #include "os_port_sys_bios.h"
121 //Zephyr port?
122 #elif defined(USE_ZEPHYR)
123  #include "os_port_zephyr.h"
124 //Windows port?
125 #elif defined(_WIN32)
126  #include "os_port_windows.h"
127 //POSIX Threads port?
128 #elif defined(__linux__) || defined(__FreeBSD__)
129  #include "os_port_posix.h"
130 //Custom port?
131 #elif defined(USE_CUSTOM_OS)
132  #include "os_port_custom.h"
133 #endif
134 
135 //Fill block of memory
136 #ifndef osMemset
137  #include <string.h>
138  #define osMemset(p, value, length) (void) memset(p, value, length)
139 #endif
140 
141 //Copy block of memory
142 #ifndef osMemcpy
143  #include <string.h>
144  #define osMemcpy(dest, src, length) (void) memcpy(dest, src, length)
145 #endif
146 
147 //Move block of memory
148 #ifndef osMemmove
149  #include <string.h>
150  #define osMemmove(dest, src, length) (void) memmove(dest, src, length)
151 #endif
152 
153 //Compare two blocks of memory
154 #ifndef osMemcmp
155  #include <string.h>
156  #define osMemcmp(p1, p2, length) memcmp(p1, p2, length)
157 #endif
158 
159 //Search for the first occurrence of a given character
160 #ifndef osMemchr
161  #include <string.h>
162  #define osMemchr(p, c, length) memchr(p, c, length)
163 #endif
164 
165 //Get string length
166 #ifndef osStrlen
167  #include <string.h>
168  #define osStrlen(s) strlen(s)
169 #endif
170 
171 //Compare strings
172 #ifndef osStrcmp
173  #include <string.h>
174  #define osStrcmp(s1, s2) strcmp(s1, s2)
175 #endif
176 
177 //Compare substrings
178 #ifndef osStrncmp
179  #include <string.h>
180  #define osStrncmp(s1, s2, length) strncmp(s1, s2, length)
181 #endif
182 
183 //Compare strings without case
184 #ifndef osStrcasecmp
185  #include <string.h>
186  #define osStrcasecmp(s1, s2) strcasecmp(s1, s2)
187 #endif
188 
189 //Compare substrings without case
190 #ifndef osStrncasecmp
191  #include <string.h>
192  #define osStrncasecmp(s1, s2, length) strncasecmp(s1, s2, length)
193 #endif
194 
195 //Search for the first occurrence of a given character
196 #ifndef osStrchr
197  #include <string.h>
198  #define osStrchr(s, c) strchr(s, c)
199 #endif
200 
201 //Search for the first occurrence of a substring
202 #ifndef osStrstr
203  #include <string.h>
204  #define osStrstr(s1, s2) strstr(s1, s2)
205 #endif
206 
207 //Copy string
208 #ifndef osStrcpy
209  #include <string.h>
210  #define osStrcpy(s1, s2) (void) strcpy(s1, s2)
211 #endif
212 
213 //Copy characters from string
214 #ifndef osStrncpy
215  #include <string.h>
216  #define osStrncpy(s1, s2, length) (void) strncpy(s1, s2, length)
217 #endif
218 
219 //Concatenate strings
220 #ifndef osStrcat
221  #include <string.h>
222  #define osStrcat(s1, s2) (void) strcat(s1, s2)
223 #endif
224 
225 //Extract tokens from string
226 #ifndef osStrtok_r
227  #include <string.h>
228  #define osStrtok_r(s, delim, last) strtok_r(s, delim, last)
229 #endif
230 
231 //Format string
232 #ifndef osSprintf
233  #include <stdio.h>
234  #define osSprintf(dest, ...) sprintf(dest, __VA_ARGS__)
235 #endif
236 
237 //Format string
238 #ifndef osSnprintf
239  #include <stdio.h>
240  #define osSnprintf(dest, size, ...) snprintf(dest, size, __VA_ARGS__)
241 #endif
242 
243 //Format string
244 #ifndef osVsnprintf
245  #include <stdio.h>
246  #define osVsnprintf(dest, size, format, ap) vsnprintf(dest, size, format, ap)
247 #endif
248 
249 //Convert string to integer
250 #ifndef osAtoi
251  #include <stdlib.h>
252  #define osAtoi(s) atoi(s)
253 #endif
254 
255 //Convert string to unsigned long integer
256 #ifndef osStrtoul
257  #include <stdlib.h>
258  #define osStrtoul(s, endptr, base) strtoul(s, endptr, base)
259 #endif
260 
261 //Convert string to unsigned long long integer
262 #ifndef osStrtoull
263  #include <stdlib.h>
264  #define osStrtoull(s, endptr, base) strtoull(s, endptr, base)
265 #endif
266 
267 //Convert a character to lowercase
268 #ifndef osTolower
269  #include <ctype.h>
270  #define osTolower(c) tolower((uint8_t) (c))
271 #endif
272 
273 //Convert a character to uppercase
274 #ifndef osToupper
275  #include <ctype.h>
276  #define osToupper(c) toupper((uint8_t) (c))
277 #endif
278 
279 //Check if a character is an uppercase letter
280 #ifndef osIsupper
281  #include <ctype.h>
282  #define osIsupper(c) isupper((uint8_t) (c))
283 #endif
284 
285 //Check if a character is a decimal digit
286 #ifndef osIsdigit
287  #include <ctype.h>
288  #define osIsdigit(c) isdigit((uint8_t) (c))
289 #endif
290 
291 //Check if a character is a whitespace character
292 #ifndef osIsspace
293  #include <ctype.h>
294  #define osIsspace(c) isspace((uint8_t) (c))
295 #endif
296 
297 //Check if a character is a blank character
298 #ifndef osIsblank
299  #define osIsblank(c) ((c) == ' ' || (c) == '\t')
300 #endif
301 
302 #if !defined(__linux__) && !defined(__FreeBSD__)
303 
304 //Delay routines
305 #ifndef usleep
306  #define usleep(delay) {volatile uint32_t n = delay * 4; while(n > 0) n--;}
307 #endif
308 
309 #ifndef sleep
310  #define sleep(delay) {volatile uint32_t n = delay * 4000; while(n > 0) n--;}
311 #endif
312 
313 #endif
314 
315 //Task object (deprecated)
316 #define OsTask void
317 //Invalid handle value (deprecated)
318 #define OS_INVALID_HANDLE OS_INVALID_TASK_ID
319 
320 #endif
RTOS abstraction layer (CMSIS-RTOS)
RTOS abstraction layer (ChibiOS/RT)
RTOS abstraction layer (Keil RTX)
RTOS abstraction layer (CMSIS-RTOS 2 / RTX v5)
RTOS abstraction layer (Micrium uC/OS-II)
RTOS abstraction layer (Eclipse ThreadX)
RTOS abstraction layer (SYS/BIOS)
RTOS abstraction layer (SafeRTOS)
RTOS abstraction layer (FreeRTOS)
RTOS abstraction layer (PX5)
RTOS-less environment.
RTOS abstraction layer (Zephyr)
RTOS abstraction layer (Windows)
RTOS abstraction layer (POSIX Threads)
RTOS abstraction layer (Micrium uC/OS-III)
RTOS abstraction layer (CMX-RTX)
Compiler specific definitions.
RTOS abstraction layer (Segger embOS)