ChibiOS  21.6.0
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  */
52 typedef 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 preempt field. */
70  uint8_t off_time; /**< @brief Offset of @p time field. */
71 } chdebug_t;
72 
73 /*===========================================================================*/
74 /* Module macros. */
75 /*===========================================================================*/
76 
77 /**
78  * @brief Access to the registry list header.
79  */
80 #if (CH_CFG_SMP_MODE == TRUE) || defined(__DOXYGEN__)
81 #define REG_HEADER(oip) (&ch_system.reglist.queue)
82 #else
83 #define REG_HEADER(oip) (&(oip)->reglist.queue)
84 #endif
85 
86 /**
87  * @brief Removes a thread from the registry list.
88  * @note This macro is not meant for use in application code.
89  *
90  * @param[in] tp thread to remove from the registry
91  */
92 #define REG_REMOVE(tp) (void) ch_queue_dequeue(&(tp)->rqueue)
93 
94 /**
95  * @brief Adds a thread to the registry list.
96  * @note This macro is not meant for use in application code.
97  *
98  * @param[in] oip pointer to the OS instance
99  * @param[in] tp thread to add to the registry
100  */
101 #define REG_INSERT(oip, tp) ch_queue_insert(REG_HEADER(oip), &(tp)->rqueue)
102 
103 /*===========================================================================*/
104 /* External declarations. */
105 /*===========================================================================*/
106 
107 #ifdef __cplusplus
108 extern "C" {
109 #endif
110  extern ROMCONST chdebug_t ch_debug;
111  thread_t *chRegFirstThread(void);
113  thread_t *chRegFindThreadByName(const char *name);
116 #ifdef __cplusplus
117 }
118 #endif
119 
120 #endif /* CH_CFG_USE_REGISTRY == TRUE */
121 
122 /*===========================================================================*/
123 /* Module inline functions. */
124 /*===========================================================================*/
125 
126 /**
127  * @brief Initializes a registry.
128  * @note Internal use only.
129  *
130  * @param[out] rp pointer to a @p registry_t structure
131  *
132  * @init
133  */
134 static inline void __reg_object_init(registry_t *rp) {
135 
136  ch_queue_init(&rp->queue);
137 }
138 
139 /**
140  * @brief Sets the current thread name.
141  * @pre This function only stores the pointer to the name if the option
142  * @p CH_CFG_USE_REGISTRY is enabled else no action is performed.
143  *
144  * @param[in] name thread name as a zero terminated string
145  *
146  * @api
147  */
148 static inline void chRegSetThreadName(const char *name) {
149 
150 #if CH_CFG_USE_REGISTRY == TRUE
151  __sch_get_currthread()->name = name;
152 #else
153  (void)name;
154 #endif
155 }
156 
157 /**
158  * @brief Returns the name of the specified thread.
159  * @pre This function only returns the pointer to the name if the option
160  * @p CH_CFG_USE_REGISTRY is enabled else @p NULL is returned.
161  *
162  * @param[in] tp pointer to the thread
163  *
164  * @return Thread name as a zero terminated string.
165  * @retval NULL if the thread name has not been set.
166  *
167  */
168 static inline const char *chRegGetThreadNameX(thread_t *tp) {
169 
170 #if CH_CFG_USE_REGISTRY == TRUE
171  return tp->name;
172 #else
173  (void)tp;
174  return NULL;
175 #endif
176 }
177 
178 /**
179  * @brief Changes the name of the specified thread.
180  * @pre This function only stores the pointer to the name if the option
181  * @p CH_CFG_USE_REGISTRY is enabled else no action is performed.
182  *
183  * @param[in] tp pointer to the thread
184  * @param[in] name thread name as a zero terminated string
185  *
186  * @xclass
187  */
188 static inline void chRegSetThreadNameX(thread_t *tp, const char *name) {
189 
190 #if CH_CFG_USE_REGISTRY == TRUE
191  tp->name = name;
192 #else
193  (void)tp;
194  (void)name;
195 #endif
196 }
197 
198 #endif /* CHREGISTRY_H */
199 
200 /** @} */
chdebug_t::off_ctx
uint8_t off_ctx
Offset of ctx field.
Definition: chregistry.h:61
stkalign_t
port_stkalign_t stkalign_t
Definition: chearly.h:80
chRegFindThreadByName
thread_t * chRegFindThreadByName(const char *name)
Retrieves a thread pointer by name.
Definition: chregistry.c:199
chdebug_t::off_name
uint8_t off_name
Offset of name field.
Definition: chregistry.h:64
chdebug_t::off_prio
uint8_t off_prio
Offset of prio field.
Definition: chregistry.h:60
chRegGetThreadNameX
static const char * chRegGetThreadNameX(thread_t *tp)
Returns the name of the specified thread.
Definition: chregistry.h:168
chdebug_t::version
uint16_t version
Encoded ChibiOS/RT version.
Definition: chregistry.h:56
chRegFindThreadByPointer
thread_t * chRegFindThreadByPointer(thread_t *tp)
Confirms that a pointer is a valid thread pointer.
Definition: chregistry.c:226
chdebug_t::off_newer
uint8_t off_newer
Offset of newer field.
Definition: chregistry.h:62
chdebug_t::zero
uint8_t zero
Must be zero.
Definition: chregistry.h:54
chdebug_t::off_flags
uint8_t off_flags
Offset of flags field.
Definition: chregistry.h:67
__sch_get_currthread
#define __sch_get_currthread()
Current thread pointer get macro.
Definition: chschd.h:137
chdebug_t::off_preempt
uint8_t off_preempt
Offset of preempt field.
Definition: chregistry.h:69
ch_thread::name
const char * name
Thread name or NULL.
Definition: chobjects.h:192
chdebug_t::off_older
uint8_t off_older
Offset of older field.
Definition: chregistry.h:63
chdebug_t::off_state
uint8_t off_state
Offset of state field.
Definition: chregistry.h:66
ch_thread
Structure representing a thread.
Definition: chobjects.h:156
chRegFindThreadByWorkingArea
thread_t * chRegFindThreadByWorkingArea(stkalign_t *wa)
Confirms that a working area is being used by some active thread.
Definition: chregistry.c:255
chdebug_t::off_time
uint8_t off_time
Offset of time field.
Definition: chregistry.h:70
ROMCONST
#define ROMCONST
ROM constant modifier.
Definition: chtypes.h:84
ch_registry
Type of a registry structure.
Definition: chobjects.h:128
chRegFirstThread
thread_t * chRegFirstThread(void)
Returns the first thread in the system.
Definition: chregistry.c:128
ch_queue_init
static void ch_queue_init(ch_queue_t *qp)
Queue initialization.
Definition: chlists.h:222
chdebug_t::off_stklimit
uint8_t off_stklimit
Offset of stklimit field.
Definition: chregistry.h:65
chdebug_t::off_refs
uint8_t off_refs
Offset of refs field.
Definition: chregistry.h:68
chdebug_t::timesize
uint8_t timesize
Size of a systime_t.
Definition: chregistry.h:58
chRegSetThreadNameX
static void chRegSetThreadNameX(thread_t *tp, const char *name)
Changes the name of the specified thread.
Definition: chregistry.h:188
ch_registry::queue
ch_queue_t queue
Registry queue header.
Definition: chobjects.h:132
chdebug_t::ptrsize
uint8_t ptrsize
Size of a pointer.
Definition: chregistry.h:57
chdebug_t::threadsize
uint8_t threadsize
Size of a thread_t.
Definition: chregistry.h:59
chRegNextThread
thread_t * chRegNextThread(thread_t *tp)
Returns the thread next to the specified one.
Definition: chregistry.c:156
__reg_object_init
static void __reg_object_init(registry_t *rp)
Initializes a registry.
Definition: chregistry.h:134
chRegSetThreadName
static void chRegSetThreadName(const char *name)
Sets the current thread name.
Definition: chregistry.h:148
chdebug_t
ChibiOS/RT memory signature record.
Definition: chregistry.h:52
chdebug_t::size
uint8_t size
Size of this structure.
Definition: chregistry.h:55