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