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-2019 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 1.9.6
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 //Invalid handle value
79 #define OS_INVALID_HANDLE NULL
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 //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 //Keil RTX port?
100 #elif defined(USE_RTX)
101  #include "os_port_rtx.h"
102 //Micrium uC/OS-II port?
103 #elif defined(USE_UCOS2)
104  #include "os_port_ucos2.h"
105 //Micrium uC/OS-III port?
106 #elif defined(USE_UCOS3)
107  #include "os_port_ucos3.h"
108 //Nut/OS port?
109 #elif defined(USE_NUTOS)
110  #include "os_port_nutos.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 //Delay routines
126 #ifndef usleep
127  #define usleep(delay) {volatile uint32_t n = delay * 4; while(n > 0) n--;}
128 #endif
129 
130 #ifndef sleep
131  #define sleep(delay) {volatile uint32_t n = delay * 4000; while(n > 0) n--;}
132 #endif
133 
134 #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 (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)