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