ChibiOS/RT 7.0.5
chregistry.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 rt/include/chregistry.h
22 * @brief Threads registry macros and structures.
23 *
24 * @addtogroup registry
25 * @{
26 */
27
28#ifndef CHREGISTRY_H
29#define CHREGISTRY_H
30
31#if (CH_CFG_USE_REGISTRY == TRUE) || defined(__DOXYGEN__)
32
33/*===========================================================================*/
34/* Module constants. */
35/*===========================================================================*/
36
37/*===========================================================================*/
38/* Module pre-compile time settings. */
39/*===========================================================================*/
40
41/*===========================================================================*/
42/* Derived constants and error checks. */
43/*===========================================================================*/
44
45/*===========================================================================*/
46/* Module data structures and types. */
47/*===========================================================================*/
48
49/**
50 * @brief ChibiOS/RT memory signature record.
51 */
52typedef struct {
53 char identifier[4]; /**< @brief Always set to "main". */
54 uint8_t zero; /**< @brief Must be zero. */
55 uint8_t size; /**< @brief Size of this structure. */
56 uint16_t version; /**< @brief Encoded ChibiOS/RT version. */
57 uint8_t ptrsize; /**< @brief Size of a pointer. */
58 uint8_t timesize; /**< @brief Size of a @p systime_t. */
59 uint8_t threadsize; /**< @brief Size of a @p thread_t. */
60 uint8_t off_prio; /**< @brief Offset of @p prio field. */
61 uint8_t off_ctx; /**< @brief Offset of @p ctx field. */
62 uint8_t off_newer; /**< @brief Offset of @p newer field. */
63 uint8_t off_older; /**< @brief Offset of @p older field. */
64 uint8_t off_name; /**< @brief Offset of @p name field. */
65 uint8_t off_stklimit; /**< @brief Offset of @p stklimit field.*/
66 uint8_t off_state; /**< @brief Offset of @p state field. */
67 uint8_t off_flags; /**< @brief Offset of @p flags field. */
68 uint8_t off_refs; /**< @brief Offset of @p refs field. */
69 uint8_t off_preempt; /**< @brief Offset of @p ticks field. */
70 uint8_t off_time; /**< @brief Offset of @p time field. */
71 uint8_t off_reserved[4];
72 uint8_t intctxsize; /**< @brief Size of a @p port_intctx. */
73 uint8_t intervalsize; /**< @brief Size of a @p sysinterval_t. */
74 uint8_t instancesnum; /**< @brief Number of instances. */
75 uint8_t off_sys_state; /**< @brief Offset of @p state field. */
76 uint8_t off_sys_instances; /**< @brief Offset of @p instances array
77 field. */
78 uint8_t off_sys_reglist; /**< @brief Offset of @p reglist field. */
79 uint8_t off_sys_rfcu; /**< @brief Offset of @p rfcu field. */
80 uint8_t off_sys_reserved[4];
81 uint8_t off_inst_rlist_current; /**< @brief Offset of @p rlist.current
82 field. */
83 uint8_t off_inst_rlist; /**< @brief Offset of @p rlist field. */
84 uint8_t off_inst_vtlist; /**< @brief Offset of @p vtlist field. */
85 uint8_t off_inst_reglist; /**< @brief Offset of @p reglist field. */
86 uint8_t off_inst_core_id; /**< @brief Offset of @p core_id field. */
87 uint8_t off_inst_rfcu; /**< @brief Offset of @p rfcu field. */
88} chdebug_t;
89
90/*===========================================================================*/
91/* Module macros. */
92/*===========================================================================*/
93
94/**
95 * @brief Access to the registry list header.
96 */
97#if (CH_CFG_SMP_MODE == TRUE) || defined(__DOXYGEN__)
98#define REG_HEADER(oip) (&ch_system.reglist.queue)
99#else
100#define REG_HEADER(oip) (&(oip)->reglist.queue)
101#endif
102
103/**
104 * @brief Removes a thread from the registry list.
105 * @note This macro is not meant for use in application code.
106 *
107 * @param[in] tp thread to remove from the registry
108 */
109#define REG_REMOVE(tp) (void) ch_queue_dequeue(&(tp)->rqueue)
110
111/**
112 * @brief Adds a thread to the registry list.
113 * @note This macro is not meant for use in application code.
114 *
115 * @param[in] oip pointer to the OS instance
116 * @param[in] tp thread to add to the registry
117 */
118#define REG_INSERT(oip, tp) ch_queue_insert(REG_HEADER(oip), &(tp)->rqueue)
119
120/*===========================================================================*/
121/* External declarations. */
122/*===========================================================================*/
123
124#ifdef __cplusplus
125extern "C" {
126#endif
127 extern ROMCONST chdebug_t ch_debug;
130 thread_t *chRegFindThreadByName(const char *name);
133#ifdef __cplusplus
134}
135#endif
136
137#endif /* CH_CFG_USE_REGISTRY == TRUE */
138
139/*===========================================================================*/
140/* Module inline functions. */
141/*===========================================================================*/
142
143/**
144 * @brief Initializes a registry.
145 * @note Internal use only.
146 *
147 * @param[out] rp pointer to a @p registry_t structure
148 *
149 * @init
150 */
151static inline void __reg_object_init(registry_t *rp) {
152
153 ch_queue_init(&rp->queue);
154}
155
156/**
157 * @brief Sets the current thread name.
158 * @pre This function only stores the pointer to the name if the option
159 * @p CH_CFG_USE_REGISTRY is enabled else no action is performed.
160 *
161 * @param[in] name thread name as a zero terminated string
162 *
163 * @api
164 */
165static inline void chRegSetThreadName(const char *name) {
166
167#if CH_CFG_USE_REGISTRY == TRUE
168 __sch_get_currthread()->name = name;
169#else
170 (void)name;
171#endif
172}
173
174/**
175 * @brief Returns the name of the specified thread.
176 * @pre This function only returns the pointer to the name if the option
177 * @p CH_CFG_USE_REGISTRY is enabled else @p NULL is returned.
178 *
179 * @param[in] tp pointer to the thread
180 *
181 * @return Thread name as a zero terminated string.
182 * @retval NULL if the thread name has not been set.
183 *
184 */
185static inline const char *chRegGetThreadNameX(thread_t *tp) {
186
187#if CH_CFG_USE_REGISTRY == TRUE
188 return tp->name;
189#else
190 (void)tp;
191 return NULL;
192#endif
193}
194
195/**
196 * @brief Changes the name of the specified thread.
197 * @pre This function only stores the pointer to the name if the option
198 * @p CH_CFG_USE_REGISTRY is enabled else no action is performed.
199 *
200 * @param[in] tp pointer to the thread
201 * @param[in] name thread name as a zero terminated string
202 *
203 * @xclass
204 */
205static inline void chRegSetThreadNameX(thread_t *tp, const char *name) {
206
207#if CH_CFG_USE_REGISTRY == TRUE
208 tp->name = name;
209#else
210 (void)tp;
211 (void)name;
212#endif
213}
214
215#endif /* CHREGISTRY_H */
216
217/** @} */
static void ch_queue_init(ch_queue_t *qp)
Queue initialization.
Definition chlists.h:222
struct ch_registry registry_t
Type of a registry structure.
port_stkalign_t stkalign_t
Definition chearly.h:80
struct ch_thread thread_t
Type of a thread structure.
Definition chearly.h:133
ROMCONST chdebug_t ch_debug
Definition chregistry.c:77
thread_t * chRegFirstThread(void)
Returns the first thread in the system.
Definition chregistry.c:159
thread_t * chRegNextThread(thread_t *tp)
Returns the thread next to the specified one.
Definition chregistry.c:187
thread_t * chRegFindThreadByName(const char *name)
Retrieves a thread pointer by name.
Definition chregistry.c:230
static const char * chRegGetThreadNameX(thread_t *tp)
Returns the name of the specified thread.
Definition chregistry.h:185
static void __reg_object_init(registry_t *rp)
Initializes a registry.
Definition chregistry.h:151
static void chRegSetThreadNameX(thread_t *tp, const char *name)
Changes the name of the specified thread.
Definition chregistry.h:205
static void chRegSetThreadName(const char *name)
Sets the current thread name.
Definition chregistry.h:165
thread_t * chRegFindThreadByWorkingArea(stkalign_t *wa)
Confirms that a working area is being used by some active thread.
Definition chregistry.c:286
thread_t * chRegFindThreadByPointer(thread_t *tp)
Confirms that a pointer is a valid thread pointer.
Definition chregistry.c:257
#define __sch_get_currthread()
Current thread pointer get macro.
Definition chschd.h:137
ch_queue_t queue
Registry queue header.
Definition chobjects.h:132
const char * name
Thread name or NULL.
Definition chobjects.h:192
ChibiOS/RT memory signature record.
Definition chregistry.h:52
uint8_t off_flags
Offset of flags field.
Definition chregistry.h:67
uint8_t off_inst_vtlist
Offset of vtlist field.
Definition chregistry.h:84
uint8_t off_sys_rfcu
Offset of rfcu field.
Definition chregistry.h:79
uint8_t off_inst_rlist_current
Offset of rlist.current field.
Definition chregistry.h:81
uint8_t off_sys_reglist
Offset of reglist field.
Definition chregistry.h:78
uint8_t off_inst_core_id
Offset of core_id field.
Definition chregistry.h:86
uint8_t off_newer
Offset of newer field.
Definition chregistry.h:62
uint8_t off_inst_rlist
Offset of rlist field.
Definition chregistry.h:83
uint8_t intctxsize
Size of a port_intctx.
Definition chregistry.h:72
uint8_t off_sys_state
Offset of state field.
Definition chregistry.h:75
uint8_t intervalsize
Size of a sysinterval_t.
Definition chregistry.h:73
uint8_t off_preempt
Offset of ticks field.
Definition chregistry.h:69
uint8_t off_older
Offset of older field.
Definition chregistry.h:63
uint8_t off_refs
Offset of refs field.
Definition chregistry.h:68
uint8_t off_time
Offset of time field.
Definition chregistry.h:70
char identifier[4]
Always set to "main".
Definition chregistry.h:53
uint8_t timesize
Size of a systime_t.
Definition chregistry.h:58
uint8_t instancesnum
Number of instances.
Definition chregistry.h:74
uint8_t off_stklimit
Offset of stklimit field.
Definition chregistry.h:65
uint8_t size
Size of this structure.
Definition chregistry.h:55
uint8_t off_sys_reserved[4]
Definition chregistry.h:80
uint8_t ptrsize
Size of a pointer.
Definition chregistry.h:57
uint8_t off_name
Offset of name field.
Definition chregistry.h:64
uint8_t off_state
Offset of state field.
Definition chregistry.h:66
uint8_t off_sys_instances
Offset of instances array field.
Definition chregistry.h:76
uint8_t off_inst_rfcu
Offset of rfcu field.
Definition chregistry.h:87
uint8_t zero
Must be zero.
Definition chregistry.h:54
uint16_t version
Encoded ChibiOS/RT version.
Definition chregistry.h:56
uint8_t threadsize
Size of a thread_t.
Definition chregistry.h:59
uint8_t off_reserved[4]
Definition chregistry.h:71
uint8_t off_inst_reglist
Offset of reglist field.
Definition chregistry.h:85
uint8_t off_prio
Offset of prio field.
Definition chregistry.h:60
uint8_t off_ctx
Offset of ctx field.
Definition chregistry.h:61