ChibiOS  21.6.0
chearly.h
Go to the documentation of this file.
1 /*
2  ChibiOS - Copyright (C) 2006,2007,2008,2009,2010,2011,2012,2013,2014,
3  2015,2016,2017,2018,2019,2020,2021 Giovanni Di Sirio.
4 
5  This file is part of ChibiOS.
6 
7  ChibiOS is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation version 3 of the License.
10 
11  ChibiOS is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 /**
21  * @file chearly.h
22  * @brief Early forward types declarations header.
23  *
24  * @addtogroup os_structures
25  * @{
26  */
27 
28 #ifndef CHEARLY_H
29 #define CHEARLY_H
30 
31 /* Port architecture-related definitions.*/
32 #if !defined(PORT_NEW_TYPES)
33 #include "chtypes.h"
34 #else
35 #include "chporttypes.h"
36 #endif
37 
38 /*===========================================================================*/
39 /* Module constants. */
40 /*===========================================================================*/
41 
42 /*===========================================================================*/
43 /* Module pre-compile time settings. */
44 /*===========================================================================*/
45 
46 /*===========================================================================*/
47 /* Derived constants and error checks. */
48 /*===========================================================================*/
49 
50 #if defined(PORT_DOES_NOT_PROVIDE_TYPES)
51 #if !defined(PORT_ARCH_SIZEOF_DATA_PTR)
52 #error "PORT_ARCH_SIZEOF_DATA_PTR not defined in chtypes.h"
53 #endif
54 
55 #if !defined(PORT_ARCH_SIZEOF_CODE_PTR)
56 #error "PORT_ARCH_SIZEOF_CODE_PTR not defined in chtypes.h"
57 #endif
58 
59 #if !defined(PORT_ARCH_REGISTERS_WIDTH)
60 #error "PORT_ARCH_REGISTERS_WIDTH not defined in chtypes.h"
61 #endif
62 
63 #if !defined(PORT_ARCH_REVERSE_ORDER)
64 #error "PORT_ARCH_REVERSE_ORDER not defined in chtypes.h"
65 #endif
66 #endif
67 
68 /*===========================================================================*/
69 /* Module data structures and types. */
70 /*===========================================================================*/
71 
72 #if defined(PORT_DOES_NOT_PROVIDE_TYPES) || defined(__DOXYGEN__)
73 /**
74  * @name Kernel types
75  * @{
76  */
77 typedef port_rtcnt_t rtcnt_t; /**< Realtime counter. */
78 typedef port_rttime_t rttime_t; /**< Realtime accumulator. */
79 typedef port_syssts_t syssts_t; /**< System status word. */
80 typedef port_stkalign_t stkalign_t; /**< Stack alignment type. */
81 
82 #if (PORT_ARCH_REGISTERS_WIDTH == 32) || defined(__DOXYGEN__)
83 typedef uint8_t tmode_t; /**< Thread flags. */
84 typedef uint8_t tstate_t; /**< Thread state. */
85 typedef uint8_t trefs_t; /**< Thread references counter. */
86 typedef uint8_t tslices_t; /**< Thread time slices counter.*/
87 typedef uint32_t tprio_t; /**< Thread priority. */
88 typedef int32_t msg_t; /**< Inter-thread message. */
89 typedef int32_t eventid_t; /**< Numeric event identifier. */
90 typedef uint32_t eventmask_t; /**< Mask of event identifiers. */
91 typedef uint32_t eventflags_t; /**< Mask of event flags. */
92 typedef int32_t cnt_t; /**< Generic signed counter. */
93 typedef uint32_t ucnt_t; /**< Generic unsigned counter. */
94 #elif PORT_ARCH_REGISTERS_WIDTH == 16
95 typedef uint8_t tmode_t; /**< Thread flags. */
96 typedef uint8_t tstate_t; /**< Thread state. */
97 typedef uint8_t trefs_t; /**< Thread references counter. */
98 typedef uint8_t tslices_t; /**< Thread time slices counter.*/
99 typedef uint16_t tprio_t; /**< Thread priority. */
100 typedef int16_t msg_t; /**< Inter-thread message. */
101 typedef int16_t eventid_t; /**< Numeric event identifier. */
102 typedef uint16_t eventmask_t; /**< Mask of event identifiers. */
103 typedef uint16_t eventflags_t; /**< Mask of event flags. */
104 typedef int16_t cnt_t; /**< Generic signed counter. */
105 typedef uint16_t ucnt_t; /**< Generic unsigned counter. */
106 #elif PORT_ARCH_REGISTERS_WIDTH == 8
107 typedef uint8_t tmode_t; /**< Thread flags. */
108 typedef uint8_t tstate_t; /**< Thread state. */
109 typedef uint8_t trefs_t; /**< Thread references counter. */
110 typedef uint8_t tslices_t; /**< Thread time slices counter.*/
111 typedef uint8_t tprio_t; /**< Thread priority. */
112 typedef int16_t msg_t; /**< Inter-thread message. */
113 typedef int8_t eventid_t; /**< Numeric event identifier. */
114 typedef uint8_t eventmask_t; /**< Mask of event identifiers. */
115 typedef uint8_t eventflags_t; /**< Mask of event flags. */
116 typedef int8_t cnt_t; /**< Generic signed counter. */
117 typedef uint8_t ucnt_t; /**< Generic unsigned counter. */
118 #else
119 #error "unsupported PORT_ARCH_REGISTERS_WIDTH value"
120 #endif
121 /** @} */
122 #endif /* defined(PORT_DOES_NOT_PROVIDE_TYPES) */
123 
124 /**
125  * @brief Type of a core identifier.
126  * @note Core identifiers have ranges from 0 to @p PORT_CORES_NUMBER - 1.
127  */
128 typedef unsigned core_id_t;
129 
130 /**
131  * @brief Type of a thread structure.
132  */
133 typedef struct ch_thread thread_t;
134 
135 /**
136  * @brief Type of an OS instance structure.
137  */
139 
140 /*===========================================================================*/
141 /* Module macros. */
142 /*===========================================================================*/
143 
144 /**
145  * @brief Utility to make the parameter a quoted string.
146  *
147  * @param[in] a literal to be string-ified
148  */
149 #define __CH_STRINGIFY(a) #a
150 
151 /**
152  * @brief Structure field offset utility.
153  *
154  * @param[in] st structured type name
155  * @param[in] m field name in the structured type
156  * @return The offset of the field in the structured type.
157  */
158 #define __CH_OFFSETOF(st, m) \
159  /*lint -save -e9005 -e9033 -e413 [11.8, 10.8, 1.3] Normal pointers
160  arithmetic, it is safe.*/ \
161  ((size_t)((char *)&((st *)0)->m - (char *)0)) \
162  /*lint -restore*/
163 
164 /**
165  * @brief Marks an expression result as used.
166  *
167  * @param[in] x a valid expression
168  */
169 #define __CH_USED(x) (void)(x)
170 
171 /**
172  * @brief Marks a boolean expression as likely true.
173  * @note No namespace prefix for this macro because it is commonly defined
174  * by operating systems.
175  *
176  * @param[in] x a valid expression
177  */
178 #if defined(PORT_LIKELY) || defined(__DOXYGEN__)
179 #define likely(x) PORT_LIKELY(x)
180 #else
181 #define likely(x) x
182 #endif
183 
184 /**
185  * @brief Marks a boolean expression as likely false.
186  * @note No namespace prefix for this macro because it is commonly defined
187  * by operating systems.
188  *
189  * @param[in] x a valid expression
190  */
191 #if defined(PORT_UNLIKELY) || defined(__DOXYGEN__)
192 #define unlikely(x) PORT_UNLIKELY(x)
193 #else
194 #define unlikely(x) x
195 #endif
196 
197 /*===========================================================================*/
198 /* External declarations. */
199 /*===========================================================================*/
200 
201 /* Early function prototypes required by the following headers.*/
202 #ifdef __cplusplus
203 extern "C" {
204 #endif
205  void chSysHalt(const char *reason);
206 #ifdef __cplusplus
207 }
208 #endif
209 
210 /*===========================================================================*/
211 /* Module inline functions. */
212 /*===========================================================================*/
213 
214 #endif /* CHEARLY_H */
215 
216 /** @} */
tprio_t
uint32_t tprio_t
Definition: chearly.h:87
core_id_t
unsigned core_id_t
Type of a core identifier.
Definition: chearly.h:128
port_stkalign_t
uint64_t port_stkalign_t
Type of stack and memory alignment enforcement.
Definition: chtypes.h:72
stkalign_t
port_stkalign_t stkalign_t
Definition: chearly.h:80
ch_os_instance
System instance data structure.
Definition: chobjects.h:394
rttime_t
port_rttime_t rttime_t
Definition: chearly.h:78
eventflags_t
uint32_t eventflags_t
Definition: chearly.h:91
eventmask_t
uint32_t eventmask_t
Definition: chearly.h:90
tstate_t
uint8_t tstate_t
Definition: chearly.h:84
msg_t
int32_t msg_t
Definition: chearly.h:88
ucnt_t
uint32_t ucnt_t
Definition: chearly.h:93
ch_thread
Structure representing a thread.
Definition: chobjects.h:156
cnt_t
int32_t cnt_t
Definition: chearly.h:92
syssts_t
port_syssts_t syssts_t
Definition: chearly.h:79
rtcnt_t
port_rtcnt_t rtcnt_t
Definition: chearly.h:77
port_rtcnt_t
uint32_t port_rtcnt_t
Realtime counter.
Definition: chtypes.h:54
tslices_t
uint8_t tslices_t
Definition: chearly.h:86
eventid_t
int32_t eventid_t
Definition: chearly.h:89
tmode_t
uint8_t tmode_t
Definition: chearly.h:83
port_rttime_t
uint64_t port_rttime_t
Realtime accumulator.
Definition: chtypes.h:59
chSysHalt
void chSysHalt(const char *reason)
Halts the system.
Definition: chsys.c:209
trefs_t
uint8_t trefs_t
Definition: chearly.h:85
chtypes.h
Template port system types.
port_syssts_t
uint32_t port_syssts_t
System status word.
Definition: chtypes.h:64