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  * Copyright (C) 2010-2018 Oryx Embedded SARL. All rights reserved.
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22  *
23  * @author Oryx Embedded SARL (www.oryx-embedded.com)
24  * @version 1.9.0
25  **/
26 
27 #ifndef _OS_PORT_H
28 #define _OS_PORT_H
29 
30 //Dependencies
31 #include "os_port_config.h"
32 #include "compiler_port.h"
33 
34 //Compilation flags used to enable/disable features
35 #define ENABLED 1
36 #define DISABLED 0
37 
38 #define PTR_OFFSET(addr, offset) ((void *) ((uint8_t *) (addr) + (offset)))
39 
40 #define timeCompare(t1, t2) ((int32_t) ((t1) - (t2)))
41 
42 //Miscellaneous macros
43 #ifndef FALSE
44  #define FALSE 0
45 #endif
46 
47 #ifndef TRUE
48  #define TRUE 1
49 #endif
50 
51 #ifndef LSB
52  #define LSB(x) ((x) & 0xFF)
53 #endif
54 
55 #ifndef MSB
56  #define MSB(x) (((x) >> 8) & 0xFF)
57 #endif
58 
59 #ifndef MIN
60  #define MIN(a, b) ((a) < (b) ? (a) : (b))
61 #endif
62 
63 #ifndef MAX
64  #define MAX(a, b) ((a) > (b) ? (a) : (b))
65 #endif
66 
67 #ifndef arraysize
68  #define arraysize(a) (sizeof(a) / sizeof(a[0]))
69 #endif
70 
71 //Infinite delay
72 #define INFINITE_DELAY ((uint_t) -1)
73 //Maximum delay
74 #define MAX_DELAY (INFINITE_DELAY / 2)
75 
76 //Invalid handle value
77 #define OS_INVALID_HANDLE NULL
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 //CMSIS-RTOS port?
86 #elif defined(USE_CMSIS_RTOS)
87  #include "os_port_cmsis_rtos.h"
88 //CMSIS-RTOS2 port?
89 #elif defined(USE_CMSIS_RTOS2)
90  #include "os_port_cmsis_rtos2.h"
91 //FreeRTOS port?
92 #elif defined(USE_FREERTOS)
93  #include "os_port_freertos.h"
94 //Keil RTX port?
95 #elif defined(USE_RTX)
96  #include "os_port_rtx.h"
97 //Micrium uC/OS-II port?
98 #elif defined(USE_UCOS2)
99  #include "os_port_ucos2.h"
100 //Micrium uC/OS-III port?
101 #elif defined(USE_UCOS3)
102  #include "os_port_ucos3.h"
103 //Nut/OS port?
104 #elif defined(USE_NUTOS)
105  #include "os_port_nutos.h"
106 //Segger embOS port?
107 #elif defined(USE_EMBOS)
108  #include "os_port_embos.h"
109 //TI SYS/BIOS port?
110 #elif defined(USE_SYS_BIOS)
111  #include "os_port_sys_bios.h"
112 //Windows port?
113 #elif defined(_WIN32)
114  #include "os_port_windows.h"
115 //POSIX Threads port?
116 #elif defined(__linux__) || defined(__FreeBSD__)
117  #include "os_port_posix.h"
118 #endif
119 
120 //Delay routines
121 #ifndef usleep
122  #define usleep(delay) {volatile uint32_t n = delay * 4; while(n > 0) n--;}
123 #endif
124 
125 #ifndef sleep
126  #define sleep(delay) {volatile uint32_t n = delay * 4000; while(n > 0) n--;}
127 #endif
128 
129 #endif
RTOS abstraction layer (CMSIS-RTOS 2 / RTX v5)
RTOS abstraction layer (SYS/BIOS)
RTOS abstraction layer (ChibiOS/RT)
RTOS abstraction layer (CMSIS-RTOS)
RTOS-less environment.
RTOS abstraction layer (Micrium uC/OS-II)
RTOS abstraction layer (Windows)
RTOS abstraction layer (Segger embOS)
RTOS abstraction layer (FreeRTOS)
Compiler specific definitions.
RTOS abstraction layer (Keil RTX)
RTOS abstraction layer (POSIX Threads)
RTOS abstraction layer (Micrium uC/OS-III)