]> begriffs open source - cmsis-freertos/blob - Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/utility/trace.h
Initial commit
[cmsis-freertos] / Demo / CORTEX_AT91SAM3U256_IAR / AT91Lib / utility / trace.h
1 /* ----------------------------------------------------------------------------
2  *         ATMEL Microcontroller Software Support 
3  * ----------------------------------------------------------------------------
4  * Copyright (c) 2008, Atmel Corporation
5  *
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are met:
10  *
11  * - Redistributions of source code must retain the above copyright notice,
12  * this list of conditions and the disclaimer below.
13  *
14  * Atmel's name may not be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
20  * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
23  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  * ----------------------------------------------------------------------------
28  */
29
30 //------------------------------------------------------------------------------
31 /// \unit
32 ///
33 /// !Purpose
34 ///
35 /// Standard output methods for reporting debug information, warnings and
36 /// errors, which can be easily be turned on/off.
37 ///
38 /// !Usage
39 /// -# Initialize the DBGU using TRACE_CONFIGURE() if you intend to eventually
40 ///    disable ALL traces; otherwise use DBGU_Configure().
41 /// -# Uses the TRACE_DEBUG(), TRACE_INFO(), TRACE_WARNING(), TRACE_ERROR()
42 ///    TRACE_FATAL() macros to output traces throughout the program.
43 /// -# Each type of trace has a level : Debug 5, Info 4, Warning 3, Error 2
44 ///    and Fatal 1. Disable a group of traces by changing the value of 
45 ///    TRACE_LEVEL during compilation; traces with a level bigger than TRACE_LEVEL 
46 ///    are not generated. To generate no trace, use the reserved value 0.
47 /// -# Trace disabling can be static or dynamic. If dynamic disabling is selected
48 ///    the trace level can be modified in runtime. If static disabling is selected
49 ///    the disabled traces are not compiled.
50 ///
51 /// !Trace level description
52 /// -# TRACE_DEBUG (5): Traces whose only purpose is for debugging the program, 
53 ///    and which do not produce meaningful information otherwise.
54 /// -# TRACE_INFO (4): Informational trace about the program execution. Should  
55 ///    enable the user to see the execution flow.
56 /// -# TRACE_WARNING (3): Indicates that a minor error has happened. In most case
57 ///    it can be discarded safely; it may even be expected.
58 /// -# TRACE_ERROR (2): Indicates an error which may not stop the program execution, 
59 ///    but which indicates there is a problem with the code.
60 /// -# TRACE_FATAL (1): Indicates a major error which prevents the program from going
61 ///    any further.
62
63 //------------------------------------------------------------------------------
64
65 #ifndef TRACE_H
66 #define TRACE_H
67
68 //------------------------------------------------------------------------------
69 //         Headers
70 //------------------------------------------------------------------------------
71
72 #include <board.h>
73 #include <dbgu/dbgu.h>
74 #include <pio/pio.h>
75 #include <stdio.h>
76
77 //------------------------------------------------------------------------------
78 //         Global Definitions
79 //------------------------------------------------------------------------------
80
81 /// Softpack Version
82 #define SOFTPACK_VERSION "1.6RC1"
83
84 #define TRACE_LEVEL_DEBUG      5
85 #define TRACE_LEVEL_INFO       4
86 #define TRACE_LEVEL_WARNING    3
87 #define TRACE_LEVEL_ERROR      2
88 #define TRACE_LEVEL_FATAL      1
89 #define TRACE_LEVEL_NO_TRACE   0
90
91 // By default, all traces are output except the debug one.
92 #if !defined(TRACE_LEVEL)    
93 #define TRACE_LEVEL TRACE_LEVEL_INFO
94 #endif
95
96 // By default, trace level is static (not dynamic)
97 #if !defined(DYN_TRACES)
98 #define DYN_TRACES 0
99 #endif
100
101 #if defined(NOTRACE)
102 #error "Error: NOTRACE has to be not defined !"
103 #endif
104
105 #undef NOTRACE
106 #if (DYN_TRACES==0)
107     #if (TRACE_LEVEL == TRACE_LEVEL_NO_TRACE)
108         #define NOTRACE
109     #endif
110 #endif
111
112
113
114 //------------------------------------------------------------------------------
115 //         Global Macros
116 //------------------------------------------------------------------------------
117
118 //------------------------------------------------------------------------------
119 /// Initializes the DBGU
120 /// \param mode  DBGU mode.
121 /// \param baudrate  DBGU baudrate.
122 /// \param mck  Master clock frequency.
123 //------------------------------------------------------------------------------
124 #define TRACE_CONFIGURE(mode, baudrate, mck) { \
125     const Pin pinsDbgu[] = {PINS_DBGU}; \
126     PIO_Configure(pinsDbgu, PIO_LISTSIZE(pinsDbgu)); \
127     DBGU_Configure(mode, baudrate, mck); \
128     }
129
130 //------------------------------------------------------------------------------
131 /// Initializes the DBGU for ISP project
132 /// \param mode  DBGU mode.
133 /// \param baudrate  DBGU baudrate.
134 /// \param mck  Master clock frequency.
135 //------------------------------------------------------------------------------
136 #if (TRACE_LEVEL==0) && (DYNTRACE==0)
137 #define TRACE_CONFIGURE_ISP(mode, baudrate, mck) {}
138 #else
139 #define TRACE_CONFIGURE_ISP(mode, baudrate, mck) { \
140     const Pin pinsDbgu[] = {PINS_DBGU}; \
141     PIO_Configure(pinsDbgu, PIO_LISTSIZE(pinsDbgu)); \
142     DBGU_Configure(mode, baudrate, mck); \
143     }
144 #endif
145
146 //------------------------------------------------------------------------------
147 /// Outputs a formatted string using <printf> if the log level is high
148 /// enough. Can be disabled by defining TRACE_LEVEL=0 during compilation.
149 /// \param format  Formatted string to output.
150 /// \param ...  Additional parameters depending on formatted string.
151 //------------------------------------------------------------------------------
152 #if defined(NOTRACE)
153
154 // Empty macro
155 #define TRACE_DEBUG(...)      { }
156 #define TRACE_INFO(...)       { }
157 #define TRACE_WARNING(...)    { }               
158 #define TRACE_ERROR(...)      { }
159 #define TRACE_FATAL(...)      { while(1); }
160
161 #define TRACE_DEBUG_WP(...)   { }
162 #define TRACE_INFO_WP(...)    { }
163 #define TRACE_WARNING_WP(...) { }
164 #define TRACE_ERROR_WP(...)   { }
165 #define TRACE_FATAL_WP(...)   { while(1); }
166
167 #elif (DYN_TRACES == 1)
168
169 // Trace output depends on traceLevel value
170 #define TRACE_DEBUG(...)      { if (traceLevel >= TRACE_LEVEL_DEBUG)   { printf("-D- " __VA_ARGS__); } }
171 #define TRACE_INFO(...)       { if (traceLevel >= TRACE_LEVEL_INFO)    { printf("-I- " __VA_ARGS__); } }
172 #define TRACE_WARNING(...)    { if (traceLevel >= TRACE_LEVEL_WARNING) { printf("-W- " __VA_ARGS__); } }
173 #define TRACE_ERROR(...)      { if (traceLevel >= TRACE_LEVEL_ERROR)   { printf("-E- " __VA_ARGS__); } }
174 #define TRACE_FATAL(...)      { if (traceLevel >= TRACE_LEVEL_FATAL)   { printf("-F- " __VA_ARGS__); while(1); } }
175
176 #define TRACE_DEBUG_WP(...)   { if (traceLevel >= TRACE_LEVEL_DEBUG)   { printf(__VA_ARGS__); } }
177 #define TRACE_INFO_WP(...)    { if (traceLevel >= TRACE_LEVEL_INFO)    { printf(__VA_ARGS__); } }
178 #define TRACE_WARNING_WP(...) { if (traceLevel >= TRACE_LEVEL_WARNING) { printf(__VA_ARGS__); } }
179 #define TRACE_ERROR_WP(...)   { if (traceLevel >= TRACE_LEVEL_ERROR)   { printf(__VA_ARGS__); } }
180 #define TRACE_FATAL_WP(...)   { if (traceLevel >= TRACE_LEVEL_FATAL)   { printf(__VA_ARGS__); while(1); } }
181
182 #else
183
184 // Trace compilation depends on TRACE_LEVEL value
185 #if (TRACE_LEVEL >= TRACE_LEVEL_DEBUG)
186 #define TRACE_DEBUG(...)      { printf("-D- " __VA_ARGS__); }
187 #define TRACE_DEBUG_WP(...)   { printf(__VA_ARGS__); }
188 #else
189 #define TRACE_DEBUG(...)      { }
190 #define TRACE_DEBUG_WP(...)   { }
191 #endif
192
193 #if (TRACE_LEVEL >= TRACE_LEVEL_INFO)
194 #define TRACE_INFO(...)       { printf("-I- " __VA_ARGS__); }
195 #define TRACE_INFO_WP(...)    { printf(__VA_ARGS__); }
196 #else
197 #define TRACE_INFO(...)       { }
198 #define TRACE_INFO_WP(...)    { }
199 #endif
200
201 #if (TRACE_LEVEL >= TRACE_LEVEL_WARNING)
202 #define TRACE_WARNING(...)    { printf("-W- " __VA_ARGS__); }
203 #define TRACE_WARNING_WP(...) { printf(__VA_ARGS__); }
204 #else
205 #define TRACE_WARNING(...)    { }
206 #define TRACE_WARNING_WP(...) { }
207 #endif
208
209 #if (TRACE_LEVEL >= TRACE_LEVEL_ERROR)
210 #define TRACE_ERROR(...)      { printf("-E- " __VA_ARGS__); }
211 #define TRACE_ERROR_WP(...)   { printf(__VA_ARGS__); }
212 #else
213 #define TRACE_ERROR(...)      { }
214 #define TRACE_ERROR_WP(...)   { }
215 #endif
216
217 #if (TRACE_LEVEL >= TRACE_LEVEL_FATAL)
218 #define TRACE_FATAL(...)      { printf("-F- " __VA_ARGS__); while(1); }
219 #define TRACE_FATAL_WP(...)   { printf(__VA_ARGS__); while(1); }
220 #else
221 #define TRACE_FATAL(...)      { while(1); }
222 #define TRACE_FATAL_WP(...)   { while(1); }
223 #endif
224
225 #endif
226
227
228 //------------------------------------------------------------------------------
229 //         Exported variables
230 //------------------------------------------------------------------------------
231 // Depending on DYN_TRACES, traceLevel is a modifable runtime variable
232 // or a define
233 #if !defined(NOTRACE) && (DYN_TRACES == 1)
234     extern unsigned int traceLevel;
235 #endif
236
237 #endif //#ifndef TRACE_H
238