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-2023 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.2.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 PTR_OFFSET(addr, offset) ((void *) ((uint8_t *) (addr) + (offset)))
41 
42 #define timeCompare(t1, t2) ((int32_t) ((t1) - (t2)))
43 
44 //Miscellaneous macros
45 #if !defined(__AT32F403A_407_LIBRARY_VERSION) && \
46  !defined(__AT32F435_437_LIBRARY_VERSION)
47  #ifndef FALSE
48  #define FALSE 0
49  #endif
50 
51  #ifndef TRUE
52  #define TRUE 1
53  #endif
54 #endif
55 
56 #ifndef LSB
57  #define LSB(x) ((x) & 0xFF)
58 #endif
59 
60 #ifndef MSB
61  #define MSB(x) (((x) >> 8) & 0xFF)
62 #endif
63 
64 #ifndef MIN
65  #define MIN(a, b) ((a) < (b) ? (a) : (b))
66 #endif
67 
68 #ifndef MAX
69  #define MAX(a, b) ((a) > (b) ? (a) : (b))
70 #endif
71 
72 #ifndef arraysize
73  #define arraysize(a) (sizeof(a) / sizeof(a[0]))
74 #endif
75 
76 //Infinite delay
77 #define INFINITE_DELAY ((uint_t) -1)
78 //Maximum delay
79 #define MAX_DELAY (INFINITE_DELAY / 2)
80 
81 //No RTOS?
82 #if defined(USE_NO_RTOS)
83  #include "os_port_none.h"
84 //ChibiOS/RT port?
85 #elif defined(USE_CHIBIOS)
86  #include "os_port_chibios.h"
87 //CMX-RTX port?
88 #elif defined(USE_CMX_RTX)
89  #include "os_port_cmx_rtx.h"
90 //CMSIS-RTOS port?
91 #elif defined(USE_CMSIS_RTOS)
92  #include "os_port_cmsis_rtos.h"
93 //CMSIS-RTOS2 port?
94 #elif defined(USE_CMSIS_RTOS2)
95  #include "os_port_cmsis_rtos2.h"
96 //FreeRTOS port?
97 #elif defined(USE_FREERTOS)
98  #include "os_port_freertos.h"
99 //SafeRTOS port?
100 #elif defined(USE_SAFERTOS)
101  #include "os_port_safertos.h"
102 //Azure RTOS ThreadX port?
103 #elif defined(USE_THREADX)
104  #include "os_port_threadx.h"
105 //Keil RTX port?
106 #elif defined(USE_RTX)
107  #include "os_port_rtx.h"
108 //Micrium uC/OS-II port?
109 #elif defined(USE_UCOS2)
110  #include "os_port_ucos2.h"
111 //Micrium uC/OS-III port?
112 #elif defined(USE_UCOS3)
113  #include "os_port_ucos3.h"
114 //Segger embOS port?
115 #elif defined(USE_EMBOS)
116  #include "os_port_embos.h"
117 //TI SYS/BIOS port?
118 #elif defined(USE_SYS_BIOS)
119  #include "os_port_sys_bios.h"
120 //Zephyr port?
121 #elif defined(USE_ZEPHYR)
122  #include "os_port_zephyr.h"
123 //Windows port?
124 #elif defined(_WIN32)
125  #include "os_port_windows.h"
126 //POSIX Threads port?
127 #elif defined(__linux__) || defined(__FreeBSD__)
128  #include "os_port_posix.h"
129 #endif
130 
131 //Fill block of memory
132 #ifndef osMemset
133  #include <string.h>
134  #define osMemset(p, value, length) (void) memset(p, value, length)
135 #endif
136 
137 //Copy block of memory
138 #ifndef osMemcpy
139  #include <string.h>
140  #define osMemcpy(dest, src, length) (void) memcpy(dest, src, length)
141 #endif
142 
143 //Move block of memory
144 #ifndef osMemmove
145  #include <string.h>
146  #define osMemmove(dest, src, length) (void) memmove(dest, src, length)
147 #endif
148 
149 //Compare two blocks of memory
150 #ifndef osMemcmp
151  #include <string.h>
152  #define osMemcmp(p1, p2, length) memcmp(p1, p2, length)
153 #endif
154 
155 //Search for the first occurrence of a given character
156 #ifndef osMemchr
157  #include <string.h>
158  #define osMemchr(p, c, length) memchr(p, c, length)
159 #endif
160 
161 //Get string length
162 #ifndef osStrlen
163  #include <string.h>
164  #define osStrlen(s) strlen(s)
165 #endif
166 
167 //Compare strings
168 #ifndef osStrcmp
169  #include <string.h>
170  #define osStrcmp(s1, s2) strcmp(s1, s2)
171 #endif
172 
173 //Compare substrings
174 #ifndef osStrncmp
175  #include <string.h>
176  #define osStrncmp(s1, s2, length) strncmp(s1, s2, length)
177 #endif
178 
179 //Compare strings without case
180 #ifndef osStrcasecmp
181  #include <string.h>
182  #define osStrcasecmp(s1, s2) strcasecmp(s1, s2)
183 #endif
184 
185 //Compare substrings without case
186 #ifndef osStrncasecmp
187  #include <string.h>
188  #define osStrncasecmp(s1, s2, length) strncasecmp(s1, s2, length)
189 #endif
190 
191 //Search for the first occurrence of a given character
192 #ifndef osStrchr
193  #include <string.h>
194  #define osStrchr(s, c) strchr(s, c)
195 #endif
196 
197 //Search for the first occurrence of a substring
198 #ifndef osStrstr
199  #include <string.h>
200  #define osStrstr(s1, s2) strstr(s1, s2)
201 #endif
202 
203 //Copy string
204 #ifndef osStrcpy
205  #include <string.h>
206  #define osStrcpy(s1, s2) (void) strcpy(s1, s2)
207 #endif
208 
209 //Copy characters from string
210 #ifndef osStrncpy
211  #include <string.h>
212  #define osStrncpy(s1, s2, length) (void) strncpy(s1, s2, length)
213 #endif
214 
215 //Concatenate strings
216 #ifndef osStrcat
217  #include <string.h>
218  #define osStrcat(s1, s2) (void) strcat(s1, s2)
219 #endif
220 
221 //Extract tokens from string
222 #ifndef osStrtok_r
223  #include <string.h>
224  #define osStrtok_r(s, delim, last) strtok_r(s, delim, last)
225 #endif
226 
227 //Format string
228 #ifndef osSprintf
229  #include <stdio.h>
230  #define osSprintf(dest, ...) sprintf(dest, __VA_ARGS__)
231 #endif
232 
233 //Format string
234 #ifndef osSnprintf
235  #include <stdio.h>
236  #define osSnprintf(dest, size, ...) snprintf(dest, size, __VA_ARGS__)
237 #endif
238 
239 //Format string
240 #ifndef osVsnprintf
241  #include <stdio.h>
242  #define osVsnprintf(dest, size, format, ap) vsnprintf(dest, size, format, ap)
243 #endif
244 
245 //Convert string to unsigned long integer
246 #ifndef osStrtoul
247  #include <stdlib.h>
248  #define osStrtoul(s, endptr, base) strtoul(s, endptr, base)
249 #endif
250 
251 //Convert string to unsigned long long integer
252 #ifndef osStrtoull
253  #include <stdlib.h>
254  #define osStrtoull(s, endptr, base) strtoull(s, endptr, base)
255 #endif
256 
257 //Convert a character to lowercase
258 #ifndef osTolower
259  #include <ctype.h>
260  #define osTolower(c) tolower((uint8_t) (c))
261 #endif
262 
263 //Convert a character to uppercase
264 #ifndef osToupper
265  #include <ctype.h>
266  #define osToupper(c) toupper((uint8_t) (c))
267 #endif
268 
269 //Check if a character is an uppercase letter
270 #ifndef osIsupper
271  #include <ctype.h>
272  #define osIsupper(c) isupper((uint8_t) (c))
273 #endif
274 
275 //Check if a character is a decimal digit
276 #ifndef osIsdigit
277  #include <ctype.h>
278  #define osIsdigit(c) isdigit((uint8_t) (c))
279 #endif
280 
281 //Check if a character is a whitespace character
282 #ifndef osIsspace
283  #include <ctype.h>
284  #define osIsspace(c) isspace((uint8_t) (c))
285 #endif
286 
287 //Check if a character is a blank character
288 #ifndef osIsblank
289  #define osIsblank(c) ((c) == ' ' || (c) == '\t')
290 #endif
291 
292 #if !defined(__linux__) && !defined(__FreeBSD__)
293 
294 //Delay routines
295 #ifndef usleep
296  #define usleep(delay) {volatile uint32_t n = delay * 4; while(n > 0) n--;}
297 #endif
298 
299 #ifndef sleep
300  #define sleep(delay) {volatile uint32_t n = delay * 4000; while(n > 0) n--;}
301 #endif
302 
303 #endif
304 
305 //Task object (deprecated)
306 #define OsTask void
307 //Invalid handle value (deprecated)
308 #define OS_INVALID_HANDLE OS_INVALID_TASK_ID
309 
310 #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 (Azure RTOS ThreadX)
RTOS abstraction layer (SYS/BIOS)
RTOS abstraction layer (FreeRTOS)
RTOS-less environment.
RTOS abstraction layer (Windows)
RTOS abstraction layer (POSIX Threads)
RTOS abstraction layer (Micrium uC/OS-III)
Compiler specific definitions.
RTOS abstraction layer (Segger embOS)