ChibiOS 21.11.4
chobjects.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 chobjects.h
22 * @brief Operating System Objects macros and structures.
23 *
24 * @addtogroup os_structures
25 * @{
26 */
27
28#ifndef CHOBJECTS_H
29#define CHOBJECTS_H
30
31/*===========================================================================*/
32/* Module constants. */
33/*===========================================================================*/
34
35/*===========================================================================*/
36/* Module pre-compile time settings. */
37/*===========================================================================*/
38
39/*===========================================================================*/
40/* Derived constants and error checks. */
41/*===========================================================================*/
42
43/*===========================================================================*/
44/* Module data structures and types. */
45/*===========================================================================*/
46
47/**
48 * @brief Global state of the operating system.
49 */
56
57/**
58 * @brief Type of a Virtual Timer.
59 */
61
62/**
63 * @brief Type of a Virtual Timer callback function.
64 *
65 * @param[in] vtp pointer to the @p virtual_timer_t calling this callback
66 * @param[in] p optional argument to the callback
67 * @return The interval to be reloaded into the timer or zero.
68 * @retval 0 if the timer must not be reloaded.
69 */
70typedef void (*vtfunc_t)(virtual_timer_t *vtp, void *p);
71
72/**
73 * @brief Structure representing a Virtual Timer.
74 */
76 /**
77 * @brief Delta list element.
78 */
80 /**
81 * @brief Timer callback function pointer.
82 */
84 /**
85 * @brief Timer callback function parameter.
86 */
87 void *par;
88 /**
89 * @brief Current reload interval.
90 */
92};
93
94/**
95 * @brief Type of virtual timers list header.
96 * @note The timers list is implemented as a double link bidirectional list
97 * in order to make the unlink time constant, the reset of a virtual
98 * timer is often used in the code.
99 */
101 /**
102 * @brief Delta list header.
103 */
105#if (CH_CFG_ST_TIMEDELTA == 0) || defined(__DOXYGEN__)
106 /**
107 * @brief System Time counter.
108 */
110#endif
111#if (CH_CFG_ST_TIMEDELTA > 0) || defined(__DOXYGEN__)
112 /**
113 * @brief System time of the last tick event.
114 */
116#endif
117#if (CH_CFG_USE_TIMESTAMP == TRUE) || defined(__DOXYGEN__)
118 /**
119 * @brief Last generated time stamp.
120 */
121 volatile uint64_t laststamp;
122#endif
124
125/**
126 * @brief Type of a registry structure.
127 */
128typedef struct ch_registry {
129 /**
130 * @brief Registry queue header.
131 */
134
135/**
136 * @brief Type of a thread reference.
137 */
139
140/**
141 * @brief Type of a threads queue.
142 */
143typedef struct ch_threads_queue {
144 /**
145 * @brief Threads queue header.
146 */
149
150/**
151 * @brief Structure representing a thread.
152 * @note Not all the listed fields are always needed, by switching off some
153 * not needed ChibiOS/RT subsystems it is possible to save RAM space
154 * by shrinking this structure.
155 */
156struct ch_thread {
157 /**
158 * @brief Shared list headers.
159 */
160 union {
161 /**
162 * @brief Threads lists element.
163 */
165 /**
166 * @brief Threads queues element.
167 */
169 /**
170 * @brief Threads ordered queues element.
171 */
174 /**
175 * @brief Processor context.
176 */
178#if (CH_CFG_USE_REGISTRY == TRUE) || defined(__DOXYGEN__)
179 /**
180 * @brief Registry queue element.
181 */
183#endif
184 /**
185 * @brief OS instance owner of this thread.
186 */
188#if (CH_CFG_USE_REGISTRY == TRUE) || defined(__DOXYGEN__)
189 /**
190 * @brief Thread name or @p NULL.
191 */
192 const char *name;
193#endif
194#if (CH_DBG_ENABLE_STACK_CHECK == TRUE) || (CH_CFG_USE_DYNAMIC == TRUE) || \
195 defined(__DOXYGEN__)
196 /**
197 * @brief Working area base address.
198 * @note This pointer is used for stack overflow checks and for
199 * dynamic threading.
200 */
202#endif
203 /**
204 * @brief Current thread state.
205 */
207 /**
208 * @brief Various thread flags.
209 */
211#if (CH_CFG_USE_REGISTRY == TRUE) || defined(__DOXYGEN__)
212 /**
213 * @brief References to this thread.
214 */
216#endif
217 /**
218 * @brief Number of ticks remaining to this thread.
219 */
220#if (CH_CFG_TIME_QUANTUM > 0) || defined(__DOXYGEN__)
222#endif
223#if (CH_DBG_THREADS_PROFILING == TRUE) || defined(__DOXYGEN__)
224 /**
225 * @brief Thread consumed time in ticks.
226 * @note This field can overflow.
227 */
228 volatile systime_t time;
229#endif
230 /**
231 * @brief State-specific fields.
232 * @note All the fields declared in this union are only valid in the
233 * specified state or condition and are thus volatile.
234 */
235 union {
236 /**
237 * @brief Thread wakeup code.
238 * @note This field contains the low level message sent to the thread
239 * by the waking thread or interrupt handler. The value is valid
240 * after exiting the @p chSchWakeupS() function.
241 */
243 /**
244 * @brief Thread exit code.
245 * @note The thread termination code is stored in this field in order
246 * to be retrieved by the thread performing a @p chThdWait() on
247 * this thread.
248 */
250 /**
251 * @brief Pointer to a generic "wait" object.
252 * @note This field is used to get a generic pointer to a synchronization
253 * object and is valid when the thread is in one of the wait
254 * states.
255 */
256 void *wtobjp;
257 /**
258 * @brief Pointer to a generic thread reference object.
259 * @note This field is used to get a pointer to a synchronization
260 * object and is valid when the thread is in @p CH_STATE_SUSPENDED
261 * state.
262 */
264#if (CH_CFG_USE_MESSAGES == TRUE) || defined(__DOXYGEN__)
265 /**
266 * @brief Thread sent message.
267 */
269#endif
270#if (CH_CFG_USE_SEMAPHORES == TRUE) || defined(__DOXYGEN__)
271 /**
272 * @brief Pointer to a generic semaphore object.
273 * @note This field is used to get a pointer to a synchronization
274 * object and is valid when the thread is in @p CH_STATE_WTSEM
275 * state.
276 */
278#endif
279#if (CH_CFG_USE_MUTEXES == TRUE) || defined(__DOXYGEN__)
280 /**
281 * @brief Pointer to a generic mutex object.
282 * @note This field is used to get a pointer to a synchronization
283 * object and is valid when the thread is in @p CH_STATE_WTMTX
284 * state.
285 */
287#endif
288#if (CH_CFG_USE_EVENTS == TRUE) || defined(__DOXYGEN__)
289 /**
290 * @brief Enabled events mask.
291 * @note This field is only valid while the thread is in the
292 * @p CH_STATE_WTOREVT or @p CH_STATE_WTANDEVT states.
293 */
295#endif
296 } u;
297#if (CH_CFG_USE_WAITEXIT == TRUE) || defined(__DOXYGEN__)
298 /**
299 * @brief Termination waiting list.
300 */
302#endif
303#if (CH_CFG_USE_MESSAGES == TRUE) || defined(__DOXYGEN__)
304 /**
305 * @brief Messages queue.
306 */
308#endif
309#if (CH_CFG_USE_EVENTS == TRUE) || defined(__DOXYGEN__)
310 /**
311 * @brief Pending events mask.
312 */
314#endif
315#if (CH_CFG_USE_MUTEXES == TRUE) || defined(__DOXYGEN__)
316 /**
317 * @brief List of the mutexes owned by this thread.
318 * @note The list is terminated by a @p NULL in this field.
319 */
321 /**
322 * @brief Thread's own, non-inherited, priority.
323 */
325#endif
326#if ((CH_CFG_USE_DYNAMIC == TRUE) && (CH_CFG_USE_MEMPOOLS == TRUE)) || \
327 defined(__DOXYGEN__)
328 /**
329 * @brief Memory Pool where the thread workspace is returned.
330 */
331 void *mpool;
332#endif
333#if (CH_DBG_STATISTICS == TRUE) || defined(__DOXYGEN__)
334 /**
335 * @brief Thread statistics.
336 */
338#endif
339#if defined(CH_CFG_THREAD_EXTRA_FIELDS)
340 /* Extra fields defined in chconf.h.*/
342#endif
343};
344
345/**
346 * @brief Type of a ready list header.
347 */
348typedef struct ch_ready_list {
349 /**
350 * @brief Threads ordered queues header.
351 * @note The priority field must be initialized to zero.
352 */
354 /**
355 * @brief The currently running thread.
356 */
359
360/**
361 * @brief Type of an system instance configuration.
362 */
363typedef struct ch_os_instance_config {
364 /**
365 * @brief Instance name.
366 */
367 const char *name;
368#if (CH_DBG_ENABLE_STACK_CHECK == TRUE) || (CH_CFG_USE_DYNAMIC == TRUE) || \
369 defined(__DOXYGEN__)
370 /**
371 * @brief Lower limit of the main function thread stack.
372 */
374 /**
375 * @brief Upper limit of the main function thread stack.
376 */
378#endif
379#if (CH_CFG_NO_IDLE_THREAD == FALSE) || defined(__DOXYGEN__)
380 /**
381 * @brief Lower limit of the dedicated idle thread stack.
382 */
384 /**
385 * @brief Upper limit of the dedicated idle thread stack.
386 */
388#endif
390
391/**
392 * @brief System instance data structure.
393 */
395 /**
396 * @brief Ready list header.
397 */
399 /**
400 * @brief Virtual timers delta list header.
401 */
403#if ((CH_CFG_USE_REGISTRY == TRUE) && (CH_CFG_SMP_MODE == FALSE)) || \
404 defined(__DOXYGEN__)
405 /**
406 * @brief Registry header.
407 * @note This field is present only if the SMP mode is disabled.
408 */
410#endif
411 /**
412 * @brief Core associated to this instance.
413 */
415#if (CH_CFG_SMP_MODE == FALSE) || defined(__DOXYGEN__)
416 /**
417 * @brief Runtime Faults Collection Unit for this instance.
418 * @note This field is present only if the SMP mode is disabled.
419 */
421#endif
422 /**
423 * @brief Pointer to the instance configuration data.
424 */
426 /**
427 * @brief Main thread descriptor.
428 */
430 /**
431 * @brief System debug.
432 */
434#if (CH_DBG_TRACE_MASK != CH_DBG_TRACE_MASK_DISABLED) || defined(__DOXYGEN__)
435 /**
436 * @brief Trace buffer.
437 */
439#endif
440#if (CH_DBG_STATISTICS == TRUE) || defined(__DOXYGEN__)
441 /**
442 * @brief Global kernel statistics.
443 */
445#endif
446#if defined(PORT_INSTANCE_EXTRA_FIELDS) || defined(__DOXYGEN__)
447 /* Extra fields from port layer.*/
448 PORT_INSTANCE_EXTRA_FIELDS
449#endif
450 /* Extra fields from configuration.*/
452};
453
454/**
455 * @brief Type of system data structure.
456 */
457typedef struct ch_system {
458 /**
459 * @brief Operating system state.
460 */
462 /**
463 * @brief Initialized OS instances or @p NULL.
464 */
466#if (CH_CFG_USE_TM == TRUE) || defined(__DOXYGEN__)
467 /**
468 * @brief Time measurement calibration data.
469 */
471#endif
472#if ((CH_CFG_USE_REGISTRY == TRUE) && (CH_CFG_SMP_MODE == TRUE)) || \
473 defined(__DOXYGEN__)
474 /**
475 * @brief Registry header.
476 * @note This field is present only if the SMP mode is enabled.
477 */
479#endif
480#if (CH_CFG_SMP_MODE == TRUE) || defined(__DOXYGEN__)
481 /**
482 * @brief Runtime Faults Collection Unit.
483 * @note This field is present only if the SMP mode is enabled.
484 */
486#endif
487#if defined(PORT_SYSTEM_EXTRA_FIELDS) || defined(__DOXYGEN__)
488 /* Extra fields from port layer.*/
489 PORT_SYSTEM_EXTRA_FIELDS
490#endif
491 /* Extra fields from configuration.*/
494
495/*===========================================================================*/
496/* Module macros. */
497/*===========================================================================*/
498
499/*===========================================================================*/
500/* External declarations. */
501/*===========================================================================*/
502
503#ifdef __cplusplus
504extern "C" {
505#endif
506
507#ifdef __cplusplus
508}
509#endif
510
511/*===========================================================================*/
512/* Module inline functions. */
513/*===========================================================================*/
514
515#endif /* CHOBJECTS_H */
516
517/** @} */
struct ch_system_debug system_debug_t
System debug data structure.
#define CH_CFG_THREAD_EXTRA_FIELDS
Threads descriptor structure extension.
#define CH_CFG_SYSTEM_EXTRA_FIELDS
System structure extension.
#define CH_CFG_OS_INSTANCE_EXTRA_FIELDS
OS instance structure extension.
struct ch_priority_queue ch_priority_queue_t
Type of a generic priority-ordered bidirectional linked list header and element.
Definition chlists.h:78
struct ch_list ch_list_t
Type of a generic single link list header and element.
Definition chlists.h:50
struct ch_delta_list ch_delta_list_t
Type of a generic bidirectional linked delta list header and element.
Definition chlists.h:95
struct ch_queue ch_queue_t
Type of a generic bidirectional linked list header and element.
Definition chlists.h:63
struct ch_ready_list ready_list_t
Type of a ready list header.
uint8_t trefs_t
Definition chearly.h:85
struct ch_virtual_timers_list virtual_timers_list_t
Type of virtual timers list header.
struct ch_virtual_timer virtual_timer_t
Type of a Virtual Timer.
Definition chobjects.h:60
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
uint32_t tprio_t
Definition chearly.h:87
struct ch_registry registry_t
Type of a registry structure.
uint8_t tmode_t
Definition chearly.h:83
struct ch_system ch_system_t
Type of system data structure.
struct ch_os_instance os_instance_t
Type of an OS instance structure.
Definition chearly.h:138
struct ch_os_instance_config os_instance_config_t
Type of an system instance configuration.
uint8_t tslices_t
Definition chearly.h:86
uint32_t eventmask_t
Definition chearly.h:90
void(* vtfunc_t)(virtual_timer_t *vtp, void *p)
Type of a Virtual Timer callback function.
Definition chobjects.h:70
thread_t * thread_reference_t
Type of a thread reference.
Definition chobjects.h:138
port_stkalign_t stkalign_t
Definition chearly.h:80
system_state_t
Global state of the operating system.
Definition chobjects.h:50
struct ch_thread thread_t
Type of a thread structure.
Definition chearly.h:133
@ ch_sys_uninit
Definition chobjects.h:51
@ ch_sys_running
Definition chobjects.h:53
@ ch_sys_initializing
Definition chobjects.h:52
@ ch_sys_halted
Definition chobjects.h:54
#define PORT_CORES_NUMBER
Definition chport.h:126
struct ch_rfcu rfcu_t
Type of an RFCU structure.
uint64_t systime_t
Type of system time.
Definition chtime.h:107
uint64_t sysinterval_t
Type of time interval.
Definition chtime.h:119
Mutex structure.
Definition chmtx.h:57
Type of an system instance configuration.
Definition chobjects.h:363
stkalign_t * mainthread_base
Lower limit of the main function thread stack.
Definition chobjects.h:373
stkalign_t * idlethread_base
Lower limit of the dedicated idle thread stack.
Definition chobjects.h:383
stkalign_t * idlethread_end
Upper limit of the dedicated idle thread stack.
Definition chobjects.h:387
stkalign_t * mainthread_end
Upper limit of the main function thread stack.
Definition chobjects.h:377
const char * name
Instance name.
Definition chobjects.h:367
System instance data structure.
Definition chobjects.h:394
kernel_stats_t kernel_stats
Global kernel statistics.
Definition chobjects.h:444
registry_t reglist
Registry header.
Definition chobjects.h:409
rfcu_t rfcu
Runtime Faults Collection Unit for this instance.
Definition chobjects.h:420
const os_instance_config_t * config
Pointer to the instance configuration data.
Definition chobjects.h:425
thread_t mainthread
Main thread descriptor.
Definition chobjects.h:429
virtual_timers_list_t vtlist
Virtual timers delta list header.
Definition chobjects.h:402
core_id_t core_id
Core associated to this instance.
Definition chobjects.h:414
system_debug_t dbg
System debug.
Definition chobjects.h:433
ready_list_t rlist
Ready list header.
Definition chobjects.h:398
trace_buffer_t trace_buffer
Trace buffer.
Definition chobjects.h:438
Type of a ready list header.
Definition chobjects.h:348
thread_t * current
The currently running thread.
Definition chobjects.h:357
ch_priority_queue_t pqueue
Threads ordered queues header.
Definition chobjects.h:353
Type of a registry structure.
Definition chobjects.h:128
ch_queue_t queue
Registry queue header.
Definition chobjects.h:132
Semaphore structure.
Type of system data structure.
Definition chobjects.h:457
tm_calibration_t tmc
Time measurement calibration data.
Definition chobjects.h:470
os_instance_t * instances[PORT_CORES_NUMBER]
Initialized OS instances or NULL.
Definition chobjects.h:465
rfcu_t rfcu
Runtime Faults Collection Unit.
Definition chobjects.h:485
system_state_t state
Operating system state.
Definition chobjects.h:461
registry_t reglist
Registry header.
Definition chobjects.h:478
Structure representing a thread.
Definition chobjects.h:156
ch_queue_t queue
Threads queues element.
Definition chobjects.h:168
union ch_thread::@065317322233202114332352372014266163076165303275 hdr
Shared list headers.
struct ch_mutex * wtmtxp
Pointer to a generic mutex object.
Definition chobjects.h:286
time_measurement_t stats
Thread statistics.
Definition chobjects.h:337
msg_t rdymsg
Thread wakeup code.
Definition chobjects.h:242
tprio_t realprio
Thread's own, non-inherited, priority.
Definition chobjects.h:324
void * mpool
Memory Pool where the thread workspace is returned.
Definition chobjects.h:331
const char * name
Thread name or NULL.
Definition chobjects.h:192
struct ch_mutex * mtxlist
List of the mutexes owned by this thread.
Definition chobjects.h:320
eventmask_t epending
Pending events mask.
Definition chobjects.h:313
ch_list_t list
Threads lists element.
Definition chobjects.h:164
ch_list_t waiting
Termination waiting list.
Definition chobjects.h:301
thread_reference_t * wttrp
Pointer to a generic thread reference object.
Definition chobjects.h:263
void * wtobjp
Pointer to a generic "wait" object.
Definition chobjects.h:256
stkalign_t * wabase
Working area base address.
Definition chobjects.h:201
msg_t exitcode
Thread exit code.
Definition chobjects.h:249
msg_t sentmsg
Thread sent message.
Definition chobjects.h:268
tslices_t ticks
Number of ticks remaining to this thread.
Definition chobjects.h:221
tstate_t state
Current thread state.
Definition chobjects.h:206
volatile systime_t time
Thread consumed time in ticks.
Definition chobjects.h:228
eventmask_t ewmask
Enabled events mask.
Definition chobjects.h:294
ch_priority_queue_t pqueue
Threads ordered queues element.
Definition chobjects.h:172
ch_queue_t msgqueue
Messages queue.
Definition chobjects.h:307
struct port_context ctx
Processor context.
Definition chobjects.h:177
trefs_t refs
References to this thread.
Definition chobjects.h:215
struct ch_semaphore * wtsemp
Pointer to a generic semaphore object.
Definition chobjects.h:277
ch_queue_t rqueue
Registry queue element.
Definition chobjects.h:182
union ch_thread::@250330312022121344252011223135034045240103044261 u
State-specific fields.
tmode_t flags
Various thread flags.
Definition chobjects.h:210
os_instance_t * owner
OS instance owner of this thread.
Definition chobjects.h:187
Type of a threads queue.
Definition chobjects.h:143
ch_queue_t queue
Threads queue header.
Definition chobjects.h:147
Structure representing a Virtual Timer.
Definition chobjects.h:75
ch_delta_list_t dlist
Delta list element.
Definition chobjects.h:79
void * par
Timer callback function parameter.
Definition chobjects.h:87
sysinterval_t reload
Current reload interval.
Definition chobjects.h:91
vtfunc_t func
Timer callback function pointer.
Definition chobjects.h:83
Type of virtual timers list header.
Definition chobjects.h:100
volatile uint64_t laststamp
Last generated time stamp.
Definition chobjects.h:121
ch_delta_list_t dlist
Delta list header.
Definition chobjects.h:104
volatile systime_t systime
System Time counter.
Definition chobjects.h:109
systime_t lasttime
System time of the last tick event.
Definition chobjects.h:115
Type of a kernel statistics structure.
Definition chstats.h:56
Platform dependent part of the thread_t structure.
Definition chcore.h:169
Type of a thread queue.
Definition osal.h:238
Type of a Time Measurement object.
Definition chtm.h:79
Type of a time measurement calibration data.
Definition chtm.h:63
Trace buffer header.
Definition chtrace.h:192