µOS++ IIIe Reference 7.0.0
The third edition of µOS++, a POSIX inspired open source framework, written in C++
Loading...
Searching...
No Matches
trace.h
Go to the documentation of this file.
1/*
2 * This file is part of the µOS++ distribution.
3 * (https://github.com/micro-os-plus)
4 * Copyright (c) 2015 Liviu Ionescu.
5 *
6 * Permission is hereby granted, free of charge, to any person
7 * obtaining a copy of this software and associated documentation
8 * files (the "Software"), to deal in the Software without
9 * restriction, including without limitation the rights to use,
10 * copy, modify, merge, publish, distribute, sublicense, and/or
11 * sell copies of the Software, and to permit persons to whom
12 * the Software is furnished to do so, subject to the following
13 * conditions:
14 *
15 * The above copyright notice and this permission notice shall be
16 * included in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 * OTHER DEALINGS IN THE SOFTWARE.
26 */
27
28#ifndef CMSIS_PLUS_DIAG_TRACE_H_
29#define CMSIS_PLUS_DIAG_TRACE_H_
30
31// ----------------------------------------------------------------------------
32
33#if defined(__cplusplus)
34#include <cstdint>
35#include <cstddef>
36#include <cstdarg>
37#include <cstdlib>
38#else
39#include <stdint.h>
40#include <stdarg.h>
41#include <stdlib.h>
42#endif
43
44#include <sys/types.h>
45
46#if defined(__cplusplus)
47
48// To be effective, <stdio.h> must be included *before* this patch.
49#include <stdio.h>
50
51// This is a very annoying issue, some very old libraries still
52// define putchar() as a macro. This is abusive, since it prevents
53// the use of putchar() in other name spaces.
54#if defined(putchar)
55#undef putchar
56#endif
57
58#endif
59
60// ----------------------------------------------------------------------------
61
65inline void
66__attribute__((always_inline))
68{
69#if defined(__ARM_EABI__)
70 asm volatile ("bkpt 0");
71#endif
72}
73
74#if defined(TRACE)
75
76#if defined(__cplusplus)
77
78namespace os
79{
106 namespace trace
107 {
108 // ----------------------------------------------------------------------
109
110 void
111 initialize (void);
112
113 ssize_t
114 write (const void* buf, std::size_t nbyte);
115
116 // ----------------------------------------------------------------------
117
125 int
126 printf (const char* format, ...);
127
136 int
137 vprintf (const char* format, std::va_list args);
138
146 int
147 puts (const char* s);
148
156 int
157 putchar (int c);
158
166 void
167 dump_args (int argc, char* argv[]);
168
176 void
177 flush(void);
178
179 // ------------------------------------------------------------------------
180
184 inline void
185 __attribute__((always_inline))
186 dbg_bkpt (void)
187 {
189 }
190
191 } /* namespace trace */
192} /* namespace os */
193
194#endif /* defined(__cplusplus) */
195
196#if defined(__cplusplus)
197extern "C"
198{
199#endif
200
201 // ----- Implementation -----
202 // These functions must be implemented for a specific trace channel.
203
207 void
208 trace_initialize (void);
209
210 ssize_t
211 trace_write (const void* buf, size_t nbyte);
212
213 void
214 trace_flush (void);
215
216 // ----- Portable -----
217
218 int
219 trace_printf (const char* format, ...);
220
221 int
222 trace_vprintf (const char* format, va_list args);
223
224 int
225 trace_puts (const char* s);
226
227 int
229
230 void
231 trace_dump_args (int argc, char* argv[]);
232
233#if defined(__cplusplus)
234}
235#endif
236
237#else /* !defined(TRACE) */
238
239// Empty definitions when trace is not defined
240
241#if defined(__cplusplus)
242
243namespace os
244 {
245 namespace trace
246 {
247 // ----------------------------------------------------------------
248
249 inline void
250 initialize (void);
251
252 inline ssize_t
253 write (const void* buf, std::size_t nbyte);
254
255 // ----------------------------------------------------------------
256
257 inline int
258 printf (const char* format, ...);
259
260 inline int
261 vprintf (const char* format, std::va_list args);
262
263 inline int
264 puts (const char* s);
265
266 inline int
267 putchar (int c);
268
269 inline void
270 dump_args (int argc, char* argv[]);
271
272 // ----------------------------------------------------------------
273
274 inline void __attribute__((always_inline))
275 initialize (void)
276 {
277 }
278
279#pragma GCC diagnostic push
280#pragma GCC diagnostic ignored "-Wunused-parameter"
281
282 inline ssize_t __attribute__((always_inline))
283 write (const void* buf, std::size_t nbyte)
284 {
285 return static_cast<ssize_t> (nbyte);
286 }
287
288 inline void __attribute__((always_inline))
289 flush (void)
290 {
291 ;
292 }
293
294 inline int __attribute__((always_inline))
295 printf (const char* format, ...)
296 {
297 return 0;
298 }
299
300 inline int __attribute__((always_inline))
301 vprintf (const char* format, std::va_list args)
302 {
303 return 0;
304 }
305
306 inline int __attribute__((always_inline))
307 puts (const char* s)
308 {
309 return 0;
310 }
311
312 inline int __attribute__((always_inline))
313 putchar (int c)
314 {
315 return c;
316 }
317
318 inline void __attribute__((always_inline))
319 dump_args (int argc, char* argv[])
320 {
321 }
322
323#pragma GCC diagnostic pop
324
325 } /* namespace trace */
326 } /* namespace os */
327
328#endif /* defined(__cplusplus) */
329
330#if defined(__cplusplus)
331extern "C"
332 {
333#endif
334
335 inline void
336 trace_initialize (void);
337
338 // Implementation dependent
339 inline ssize_t
340 trace_write (const void* buf, size_t nbyte);
341
342 inline void
343 trace_flush (void);
344
345 inline int
346 trace_printf (const char* format, ...);
347
348 inline int
349 trace_vprintf (const char* format, va_list args);
350
351 inline int
352 trace_puts (const char* s);
353
354 inline int
355 trace_putchar (int c);
356
357 inline void
358 trace_dump_args (int argc, char* argv[]);
359
360#if defined(__cplusplus)
361 }
362#endif
363
364inline void
365__attribute__((always_inline))
366trace_initialize (void)
367 {
368 ;
369 }
370
371#pragma GCC diagnostic push
372#pragma GCC diagnostic ignored "-Wunused-parameter"
373
374#pragma GCC diagnostic push
375#if defined(__cplusplus)
376#pragma GCC diagnostic ignored "-Wold-style-cast"
377#endif
378
379inline ssize_t
380__attribute__((always_inline))
381trace_write (const void* buf, size_t nbyte)
382 {
383 return (ssize_t) (nbyte);
384 }
385
386inline void
387__attribute__((always_inline))
388trace_flush (void)
389 {
390 ;
391 }
392
393#pragma GCC diagnostic pop
394
395inline int
396__attribute__((always_inline))
397trace_printf (const char* format, ...)
398 {
399 return 0;
400 }
401
402inline int
403__attribute__((always_inline))
404trace_vprintf (const char* format, va_list args)
405 {
406 return 0;
407 }
408
409inline int
410__attribute__((always_inline))
411trace_puts (const char* s)
412 {
413 return 0;
414 }
415
416inline int
417__attribute__((always_inline))
418trace_putchar (int c)
419 {
420 return c;
421 }
422
423inline void
424__attribute__((always_inline))
425trace_dump_args (int argc, char* argv[])
426 {
427 }
428
429#pragma GCC diagnostic pop
430
431#endif /* defined(TRACE) */
432
433// ----------------------------------------------------------------------------
434
435#endif /* CMSIS_PLUS_DIAG_TRACE_H_ */
int puts(const char *s)
Write the string and a line terminator to the trace device.
Definition trace.cpp:108
int vprintf(const char *format, std::va_list args)
Write a formatted variable arguments list to the trace device.
Definition trace.cpp:86
int printf(const char *format,...)
Write a formatted string to the trace device.
Definition trace.cpp:74
int putchar(int c)
Write the single character to the trace device.
Definition trace.cpp:126
void dump_args(int argc, char *argv[])
Write the argv[] array to the trace device.
Definition trace.cpp:140
void dbg_bkpt(void)
Insert a BKPT0 for debugger usage.
Definition trace.h:186
void initialize(void)
Definition trace.cpp:50
ssize_t write(const void *buf, std::size_t nbyte)
Write the given number of bytes to the trace output channel.
Definition trace.cpp:60
void flush(void)
Flush the output.
Definition trace.cpp:66
System namespace.
int trace_putchar(int c)
void trace_flush(void)
Definition trace.cpp:177
int trace_vprintf(const char *format, va_list args)
void trace_initialize(void)
Definition trace.cpp:165
void trace_dbg_bkpt(void)
Insert a BKPT0 for debugger usage.
Definition trace.h:67
void trace_dump_args(int argc, char *argv[])
int trace_printf(const char *format,...)
ssize_t trace_write(const void *buf, size_t nbyte)
int trace_puts(const char *s)