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