ChibiOS 21.11.4
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 */
77typedef port_rtcnt_t rtcnt_t; /**< Realtime counter. */
78typedef port_rttime_t rttime_t; /**< Realtime accumulator. */
79typedef port_syssts_t syssts_t; /**< System status word. */
80typedef port_stkalign_t stkalign_t; /**< Stack alignment type. */
81
82#if (PORT_ARCH_REGISTERS_WIDTH == 32) || defined(__DOXYGEN__)
83typedef uint8_t tmode_t; /**< Thread flags. */
84typedef uint8_t tstate_t; /**< Thread state. */
85typedef uint8_t trefs_t; /**< Thread references counter. */
86typedef uint8_t tslices_t; /**< Thread time slices counter.*/
87typedef uint32_t tprio_t; /**< Thread priority. */
88typedef int32_t msg_t; /**< Inter-thread message. */
89typedef int32_t eventid_t; /**< Numeric event identifier. */
90typedef uint32_t eventmask_t; /**< Mask of event identifiers. */
91typedef uint32_t eventflags_t; /**< Mask of event flags. */
92typedef int32_t cnt_t; /**< Generic signed counter. */
93typedef uint32_t ucnt_t; /**< Generic unsigned counter. */
94#elif PORT_ARCH_REGISTERS_WIDTH == 16
95typedef uint8_t tmode_t; /**< Thread flags. */
96typedef uint8_t tstate_t; /**< Thread state. */
97typedef uint8_t trefs_t; /**< Thread references counter. */
98typedef uint8_t tslices_t; /**< Thread time slices counter.*/
99typedef uint16_t tprio_t; /**< Thread priority. */
100typedef int16_t msg_t; /**< Inter-thread message. */
101typedef int16_t eventid_t; /**< Numeric event identifier. */
102typedef uint16_t eventmask_t; /**< Mask of event identifiers. */
103typedef uint16_t eventflags_t; /**< Mask of event flags. */
104typedef int16_t cnt_t; /**< Generic signed counter. */
105typedef uint16_t ucnt_t; /**< Generic unsigned counter. */
106#elif PORT_ARCH_REGISTERS_WIDTH == 8
107typedef uint8_t tmode_t; /**< Thread flags. */
108typedef uint8_t tstate_t; /**< Thread state. */
109typedef uint8_t trefs_t; /**< Thread references counter. */
110typedef uint8_t tslices_t; /**< Thread time slices counter.*/
111typedef uint8_t tprio_t; /**< Thread priority. */
112typedef int16_t msg_t; /**< Inter-thread message. */
113typedef int8_t eventid_t; /**< Numeric event identifier. */
114typedef uint8_t eventmask_t; /**< Mask of event identifiers. */
115typedef uint8_t eventflags_t; /**< Mask of event flags. */
116typedef int8_t cnt_t; /**< Generic signed counter. */
117typedef uint8_t ucnt_t; /**< Generic unsigned counter. */
118#else
119#error "unsupported PORT_ARCH_REGISTERS_WIDTH value"
120#endif
121/** @} */
122#endif
123
124/**
125 * @brief Type of a core identifier.
126 * @note Core identifiers have ranges from 0 to @p PORT_CORES_NUMBER - 1.
127 */
128typedef unsigned core_id_t;
129
130/**
131 * @brief Type of a thread structure.
132 */
133typedef 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 * @brief Safe cast of a queue pointer to a thread pointer.
199 * @note Casting to a thread pointer should always be performed using
200 * this macro. Casting to threads pointer is allowed by design
201 * and this is the single check point for this operation.
202 *
203 * @param[in] p pointer to a queue/list structure
204 * @return The pointer to the thread containing the queue/list
205 * element.
206 */
207#define threadref(p) ((thread_t *)(void *)(p))
208
209/*===========================================================================*/
210/* External declarations. */
211/*===========================================================================*/
212
213/* Early function prototypes required by the following headers.*/
214#ifdef __cplusplus
215extern "C" {
216#endif
217 void chSysHalt(const char *reason);
218#ifdef __cplusplus
219}
220#endif
221
222/*===========================================================================*/
223/* Module inline functions. */
224/*===========================================================================*/
225
226#endif /* CHEARLY_H */
227
228/** @} */
Template port system types.
int32_t cnt_t
Definition chearly.h:92
uint32_t eventflags_t
Definition chearly.h:91
uint8_t trefs_t
Definition chearly.h:85
int32_t msg_t
Definition chearly.h:88
unsigned core_id_t
Type of a core identifier.
Definition chearly.h:128
uint8_t tstate_t
Definition chearly.h:84
port_syssts_t syssts_t
Definition chearly.h:79
uint32_t tprio_t
Definition chearly.h:87
uint8_t tmode_t
Definition chearly.h:83
port_rttime_t rttime_t
Definition chearly.h:78
struct ch_os_instance os_instance_t
Type of an OS instance structure.
Definition chearly.h:138
port_rtcnt_t rtcnt_t
Definition chearly.h:77
uint8_t tslices_t
Definition chearly.h:86
uint32_t eventmask_t
Definition chearly.h:90
uint32_t ucnt_t
Definition chearly.h:93
int32_t eventid_t
Definition chearly.h:89
port_stkalign_t stkalign_t
Definition chearly.h:80
struct ch_thread thread_t
Type of a thread structure.
Definition chearly.h:133
void chSysHalt(const char *reason)
Halts the system.
Definition chsys.c:209
uint64_t port_stkalign_t
Type of stack and memory alignment enforcement.
Definition chtypes.h:72
uint32_t port_rtcnt_t
Realtime counter.
Definition chtypes.h:54
uint64_t port_rttime_t
Realtime accumulator.
Definition chtypes.h:59
uint32_t port_syssts_t
System status word.
Definition chtypes.h:64
System instance data structure.
Definition chobjects.h:394
Structure representing a thread.
Definition chobjects.h:156