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-2024 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.4.4
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 #endif
131 
132 //Fill block of memory
133 #ifndef osMemset
134  #include <string.h>
135  #define osMemset(p, value, length) (void) memset(p, value, length)
136 #endif
137 
138 //Copy block of memory
139 #ifndef osMemcpy
140  #include <string.h>
141  #define osMemcpy(dest, src, length) (void) memcpy(dest, src, length)
142 #endif
143 
144 //Move block of memory
145 #ifndef osMemmove
146  #include <string.h>
147  #define osMemmove(dest, src, length) (void) memmove(dest, src, length)
148 #endif
149 
150 //Compare two blocks of memory
151 #ifndef osMemcmp
152  #include <string.h>
153  #define osMemcmp(p1, p2, length) memcmp(p1, p2, length)
154 #endif
155 
156 //Search for the first occurrence of a given character
157 #ifndef osMemchr
158  #include <string.h>
159  #define osMemchr(p, c, length) memchr(p, c, length)
160 #endif
161 
162 //Get string length
163 #ifndef osStrlen
164  #include <string.h>
165  #define osStrlen(s) strlen(s)
166 #endif
167 
168 //Compare strings
169 #ifndef osStrcmp
170  #include <string.h>
171  #define osStrcmp(s1, s2) strcmp(s1, s2)
172 #endif
173 
174 //Compare substrings
175 #ifndef osStrncmp
176  #include <string.h>
177  #define osStrncmp(s1, s2, length) strncmp(s1, s2, length)
178 #endif
179 
180 //Compare strings without case
181 #ifndef osStrcasecmp
182  #include <string.h>
183  #define osStrcasecmp(s1, s2) strcasecmp(s1, s2)
184 #endif
185 
186 //Compare substrings without case
187 #ifndef osStrncasecmp
188  #include <string.h>
189  #define osStrncasecmp(s1, s2, length) strncasecmp(s1, s2, length)
190 #endif
191 
192 //Search for the first occurrence of a given character
193 #ifndef osStrchr
194  #include <string.h>
195  #define osStrchr(s, c) strchr(s, c)
196 #endif
197 
198 //Search for the first occurrence of a substring
199 #ifndef osStrstr
200  #include <string.h>
201  #define osStrstr(s1, s2) strstr(s1, s2)
202 #endif
203 
204 //Copy string
205 #ifndef osStrcpy
206  #include <string.h>
207  #define osStrcpy(s1, s2) (void) strcpy(s1, s2)
208 #endif
209 
210 //Copy characters from string
211 #ifndef osStrncpy
212  #include <string.h>
213  #define osStrncpy(s1, s2, length) (void) strncpy(s1, s2, length)
214 #endif
215 
216 //Concatenate strings
217 #ifndef osStrcat
218  #include <string.h>
219  #define osStrcat(s1, s2) (void) strcat(s1, s2)
220 #endif
221 
222 //Extract tokens from string
223 #ifndef osStrtok_r
224  #include <string.h>
225  #define osStrtok_r(s, delim, last) strtok_r(s, delim, last)
226 #endif
227 
228 //Format string
229 #ifndef osSprintf
230  #include <stdio.h>
231  #define osSprintf(dest, ...) sprintf(dest, __VA_ARGS__)
232 #endif
233 
234 //Format string
235 #ifndef osSnprintf
236  #include <stdio.h>
237  #define osSnprintf(dest, size, ...) snprintf(dest, size, __VA_ARGS__)
238 #endif
239 
240 //Format string
241 #ifndef osVsnprintf
242  #include <stdio.h>
243  #define osVsnprintf(dest, size, format, ap) vsnprintf(dest, size, format, ap)
244 #endif
245 
246 //Convert string to integer
247 #ifndef osAtoi
248  #include <stdlib.h>
249  #define osAtoi(s) atoi(s)
250 #endif
251 
252 //Convert string to unsigned long integer
253 #ifndef osStrtoul
254  #include <stdlib.h>
255  #define osStrtoul(s, endptr, base) strtoul(s, endptr, base)
256 #endif
257 
258 //Convert string to unsigned long long integer
259 #ifndef osStrtoull
260  #include <stdlib.h>
261  #define osStrtoull(s, endptr, base) strtoull(s, endptr, base)
262 #endif
263 
264 //Convert a character to lowercase
265 #ifndef osTolower
266  #include <ctype.h>
267  #define osTolower(c) tolower((uint8_t) (c))
268 #endif
269 
270 //Convert a character to uppercase
271 #ifndef osToupper
272  #include <ctype.h>
273  #define osToupper(c) toupper((uint8_t) (c))
274 #endif
275 
276 //Check if a character is an uppercase letter
277 #ifndef osIsupper
278  #include <ctype.h>
279  #define osIsupper(c) isupper((uint8_t) (c))
280 #endif
281 
282 //Check if a character is a decimal digit
283 #ifndef osIsdigit
284  #include <ctype.h>
285  #define osIsdigit(c) isdigit((uint8_t) (c))
286 #endif
287 
288 //Check if a character is a whitespace character
289 #ifndef osIsspace
290  #include <ctype.h>
291  #define osIsspace(c) isspace((uint8_t) (c))
292 #endif
293 
294 //Check if a character is a blank character
295 #ifndef osIsblank
296  #define osIsblank(c) ((c) == ' ' || (c) == '\t')
297 #endif
298 
299 #if !defined(__linux__) && !defined(__FreeBSD__)
300 
301 //Delay routines
302 #ifndef usleep
303  #define usleep(delay) {volatile uint32_t n = delay * 4; while(n > 0) n--;}
304 #endif
305 
306 #ifndef sleep
307  #define sleep(delay) {volatile uint32_t n = delay * 4000; while(n > 0) n--;}
308 #endif
309 
310 #endif
311 
312 //Task object (deprecated)
313 #define OsTask void
314 //Invalid handle value (deprecated)
315 #define OS_INVALID_HANDLE OS_INVALID_TASK_ID
316 
317 #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)