ChibiOS/RT 7.0.5
chtrace.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/chtrace.h
22 * @brief Tracer macros and structures.
23 *
24 * @addtogroup trace
25 * @{
26 */
27
28#ifndef CHTRACE_H
29#define CHTRACE_H
30
31/*===========================================================================*/
32/* Module constants. */
33/*===========================================================================*/
34
35/**
36 * @name Trace record types
37 * @{
38 */
39#define CH_TRACE_TYPE_UNUSED 0U
40#define CH_TRACE_TYPE_READY 1U
41#define CH_TRACE_TYPE_SWITCH 2U
42#define CH_TRACE_TYPE_ISR_ENTER 3U
43#define CH_TRACE_TYPE_ISR_LEAVE 4U
44#define CH_TRACE_TYPE_HALT 5U
45#define CH_TRACE_TYPE_USER 6U
46/** @} */
47
48/**
49 * @name Events to trace
50 * @{
51 */
52#define CH_DBG_TRACE_MASK_DISABLED 255U
53#define CH_DBG_TRACE_MASK_NONE 0U
54#define CH_DBG_TRACE_MASK_READY 1U
55#define CH_DBG_TRACE_MASK_SWITCH 2U
56#define CH_DBG_TRACE_MASK_ISR 4U
57#define CH_DBG_TRACE_MASK_HALT 8U
58#define CH_DBG_TRACE_MASK_USER 16U
59#define CH_DBG_TRACE_MASK_SLOW (CH_DBG_TRACE_MASK_READY | \
60 CH_DBG_TRACE_MASK_SWITCH | \
61 CH_DBG_TRACE_MASK_HALT | \
62 CH_DBG_TRACE_MASK_USER)
63#define CH_DBG_TRACE_MASK_ALL (CH_DBG_TRACE_MASK_READY | \
64 CH_DBG_TRACE_MASK_SWITCH | \
65 CH_DBG_TRACE_MASK_ISR | \
66 CH_DBG_TRACE_MASK_HALT | \
67 CH_DBG_TRACE_MASK_USER)
68/** @} */
69
70/*===========================================================================*/
71/* Module pre-compile time settings. */
72/*===========================================================================*/
73
74/**
75 * @name Debug related settings
76 * @{
77 */
78/**
79 * @brief Trace buffer entries.
80 */
81#if !defined(CH_DBG_TRACE_MASK) || defined(__DOXYGEN__)
82#define CH_DBG_TRACE_MASK CH_DBG_TRACE_MASK_DISABLED
83#endif
84
85/**
86 * @brief Trace buffer entries.
87 * @note The trace buffer is only allocated if @p CH_DBG_TRACE_MASK is
88 * different from @p CH_DBG_TRACE_MASK_DISABLED.
89 */
90#if !defined(CH_DBG_TRACE_BUFFER_SIZE) || defined(__DOXYGEN__)
91#define CH_DBG_TRACE_BUFFER_SIZE 128
92#endif
93/** @} */
94
95/*===========================================================================*/
96/* Derived constants and error checks. */
97/*===========================================================================*/
98
99/*===========================================================================*/
100/* Module data structures and types. */
101/*===========================================================================*/
102
103#if (CH_DBG_TRACE_MASK != CH_DBG_TRACE_MASK_DISABLED) || defined(__DOXYGEN__)
104/*lint -save -e46 [6.1] An uint32_t is required.*/
105/**
106 * @brief Trace buffer record.
107 */
108typedef struct {
109 /**
110 * @brief Record type.
111 */
112 uint32_t type:3;
113 /**
114 * @brief Switched out thread state.
115 */
116 uint32_t state:5;
117 /**
118 * @brief Accurate time stamp.
119 * @note This field only available if the post supports
120 * @p PORT_SUPPORTS_RT else it is set to zero.
121 */
122 uint32_t rtstamp:24;
123 /**
124 * @brief System time stamp of the switch event.
125 */
127 union {
128 /**
129 * @brief Structure representing a context switch.
130 */
131 struct {
132 /**
133 * @brief Switched in thread.
134 */
136 /**
137 * @brief Object where going to sleep.
138 */
139 void *wtobjp;
140 } sw;
141 /**
142 * @brief Structure representing a thread becoming ready.
143 */
144 struct {
145 /**
146 * @brief Thread made ready.
147 */
149 /**
150 * @brief Ready message.
151 */
153 } rdy;
154 /**
155 * @brief Structure representing an ISR enter.
156 */
157 struct {
158 /**
159 * @brief ISR function name taken using @p __func__.
160 */
161 const char *name;
162 } isr;
163 /**
164 * @brief Structure representing an halt.
165 */
166 struct {
167 /**
168 * @brief Halt error string.
169 */
170 const char *reason;
171 } halt;
172 /**
173 * @brief User trace structure.
174 */
175 struct {
176 /**
177 * @brief Trace user parameter 1.
178 */
179 void *up1;
180 /**
181 * @brief Trace user parameter 2.
182 */
183 void *up2;
184 } user;
185 } u;
187/*lint -restore*/
188
189/**
190 * @brief Trace buffer header.
191 */
192typedef struct {
193 /**
194 * @brief Suspended trace sources mask.
195 */
196 uint16_t suspended;
197 /**
198 * @brief Trace buffer size (entries).
199 */
200 uint16_t size;
201 /**
202 * @brief Pointer to the buffer front.
203 */
205 /**
206 * @brief Ring buffer.
207 */
210#endif /* CH_DBG_TRACE_MASK != CH_DBG_TRACE_MASK_DISABLED */
211
212/*===========================================================================*/
213/* Module macros. */
214/*===========================================================================*/
215
216/* When a trace feature is disabled the associated functions are replaced by
217 an empty macro. Note that the macros can be externally redefined in
218 order to interface 3rd parties tracing tools.*/
219#if CH_DBG_TRACE_MASK == CH_DBG_TRACE_MASK_DISABLED
220#if !defined(__trace_ready)
221#define __trace_ready(tp, msg)
222#endif
223#if !defined(__trace_switch)
224#define __trace_switch(ntp, otp)
225#endif
226#if !defined(__trace_isr_enter)
227#define __trace_isr_enter(isr)
228#endif
229#if !defined(__trace_isr_leave)
230#define __trace_isr_leave(isr)
231#endif
232#if !defined(__trace_halt)
233#define __trace_halt(reason)
234#endif
235#if !defined(chDbgWriteTraceI)
236#define chDbgWriteTraceI(up1, up2)
237#endif
238#if !defined(chDbgWriteTrace)
239#define chDbgWriteTrace(up1, up2)
240#endif
241#endif /* CH_DBG_TRACE_MASK == CH_DBG_TRACE_MASK_DISABLED */
242
243/*===========================================================================*/
244/* External declarations. */
245/*===========================================================================*/
246
247#ifdef __cplusplus
248extern "C" {
249#endif
250#if (CH_DBG_TRACE_MASK != CH_DBG_TRACE_MASK_DISABLED) || defined(__DOXYGEN__)
252 void __trace_ready(thread_t *tp, msg_t msg);
253 void __trace_switch(thread_t *ntp, thread_t *otp);
254 void __trace_isr_enter(const char *isr);
255 void __trace_isr_leave(const char *isr);
256 void __trace_halt(const char *reason);
257 void chTraceWriteI(void *up1, void *up2);
258 void chTraceWrite(void *up1, void *up2);
259 void chTraceSuspendI(uint16_t mask);
260 void chTraceSuspend(uint16_t mask);
261 void chTraceResumeI(uint16_t mask);
262 void chTraceResume(uint16_t mask);
263#endif /* CH_DBG_TRACE_MASK != CH_DBG_TRACE_MASK_DISABLED */
264#ifdef __cplusplus
265}
266#endif
267
268/*===========================================================================*/
269/* Module inline functions. */
270/*===========================================================================*/
271
272#endif /* CHTRACE_H */
273
274/** @} */
int32_t msg_t
Definition chearly.h:88
struct ch_thread thread_t
Type of a thread structure.
Definition chearly.h:133
uint64_t systime_t
Type of system time.
Definition chtime.h:107
#define __trace_halt(reason)
Definition chtrace.h:233
void chTraceResume(uint16_t mask)
Resumes one or more trace events.
Definition chtrace.c:283
#define __trace_ready(tp, msg)
Definition chtrace.h:221
#define __trace_isr_enter(isr)
Definition chtrace.h:227
void chTraceResumeI(uint16_t mask)
Resumes one or more trace events.
Definition chtrace.c:269
void chTraceWrite(void *up1, void *up2)
Adds an user trace record to the trace buffer.
Definition chtrace.c:227
#define __trace_switch(ntp, otp)
Definition chtrace.h:224
void chTraceSuspendI(uint16_t mask)
Suspends one or more trace events.
Definition chtrace.c:241
void chTraceWriteI(void *up1, void *up2)
Adds an user trace record to the trace buffer.
Definition chtrace.c:205
void chTraceSuspend(uint16_t mask)
Suspends one or more trace events.
Definition chtrace.c:255
#define CH_DBG_TRACE_BUFFER_SIZE
Trace buffer entries.
Definition chtrace.h:91
void __trace_object_init(trace_buffer_t *tbp)
Circular trace buffer initialization.
Definition chtrace.c:88
#define __trace_isr_leave(isr)
Definition chtrace.h:230
Trace buffer header.
Definition chtrace.h:192
trace_event_t * ptr
Pointer to the buffer front.
Definition chtrace.h:204
trace_event_t buffer[CH_DBG_TRACE_BUFFER_SIZE]
Ring buffer.
Definition chtrace.h:208
uint16_t size
Trace buffer size (entries).
Definition chtrace.h:200
uint16_t suspended
Suspended trace sources mask.
Definition chtrace.h:196
Trace buffer record.
Definition chtrace.h:108
void * up1
Trace user parameter 1.
Definition chtrace.h:179
uint32_t type
Record type.
Definition chtrace.h:112
thread_t * ntp
Switched in thread.
Definition chtrace.h:135
uint32_t state
Switched out thread state.
Definition chtrace.h:116
void * wtobjp
Object where going to sleep.
Definition chtrace.h:139
uint32_t rtstamp
Accurate time stamp.
Definition chtrace.h:122
systime_t time
System time stamp of the switch event.
Definition chtrace.h:126
thread_t * tp
Thread made ready.
Definition chtrace.h:148
const char * reason
Halt error string.
Definition chtrace.h:170
msg_t msg
Ready message.
Definition chtrace.h:152
const char * name
ISR function name taken using __func__.
Definition chtrace.h:161
void * up2
Trace user parameter 2.
Definition chtrace.h:183