tao_z
2022-05-25 1044ba0d2286698d0da28112bffc0f114bef2134
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*
 * This file is part of the 0‡00…8OS++ distribution.
 *   (https://github.com/micro-os-plus)
 * Copyright (c) 2014 Liviu Ionescu.
 *
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or
 * sell copies of the Software, and to permit persons to whom
 * the Software is furnished to do so, subject to the following
 * conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 */
 
#ifndef DIAG_TRACE_H_
#define DIAG_TRACE_H_
 
// ----------------------------------------------------------------------------
 
#include <unistd.h>
 
// ----------------------------------------------------------------------------
 
// The trace device is an independent output channel, intended for debug
// purposes.
//
// The API is simple, and mimics the standard output calls:
// - trace_printf()
// - trace_puts()
// - trace_putchar();
//
// The implementation is done in
// - trace_write()
//
// Trace support is enabled by adding the TRACE definition.
// By default the trace messages are forwarded to the ITM output,
// but can be rerouted via any device or completely suppressed by
// changing the definitions required in system/src/diag/trace_impl.c
// (currently OS_USE_TRACE_ITM, OS_USE_TRACE_SEMIHOSTING_DEBUG/_STDOUT).
//
// When TRACE is not defined, all functions are inlined to empty bodies.
// This has the advantage that the trace call do not need to be conditionally
// compiled with #ifdef TRACE/#endif
 
 
#if defined(TRACE)
 
#if defined(__cplusplus)
extern "C"
{
#endif
 
  void
  trace_initialize(void);
 
  // Implementation dependent
  ssize_t
  trace_write(const char* buf, size_t nbyte);
 
  // ----- Portable -----
 
  int
  trace_printf(const char* format, ...);
 
  int
  trace_puts(const char *s);
 
  int
  trace_putchar(int c);
 
  void
  trace_dump_args(int argc, char* argv[]);
 
#if defined(__cplusplus)
}
#endif
 
#else // !defined(TRACE)
 
#if defined(__cplusplus)
extern "C"
{
#endif
 
  inline void
  trace_initialize(void);
 
  // Implementation dependent
  inline ssize_t
  trace_write(const char* buf, size_t nbyte);
 
  inline int
  trace_printf(const char* format, ...);
 
  inline int
  trace_puts(const char *s);
 
  inline int
  trace_putchar(int c);
 
  inline void
  trace_dump_args(int argc, char* argv[]);
 
#if defined(__cplusplus)
}
#endif
 
inline void
__attribute__((always_inline))
trace_initialize(void)
{
}
 
// Empty definitions when trace is not defined
inline ssize_t
__attribute__((always_inline))
trace_write(const char* buf __attribute__((unused)),
    size_t nbyte __attribute__((unused)))
{
  return 0;
}
 
inline int
__attribute__((always_inline))
trace_printf(const char* format __attribute__((unused)), ...)
  {
    return 0;
  }
 
inline int
__attribute__((always_inline))
trace_puts(const char *s __attribute__((unused)))
{
  return 0;
}
 
inline int
__attribute__((always_inline))
trace_putchar(int c)
{
  return c;
}
 
inline void
__attribute__((always_inline))
trace_dump_args(int argc __attribute__((unused)),
    char* argv[] __attribute__((unused)))
{
}
 
#endif // defined(TRACE)
 
// ----------------------------------------------------------------------------
 
#endif // DIAG_TRACE_H_