1 /* ----------------------------------------------------------------------------
2 * ATMEL Microcontroller Software Support
3 * ----------------------------------------------------------------------------
4 * Copyright (c) 2008, Atmel Corporation
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
11 * - Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the disclaimer below.
14 * Atmel's name may not be used to endorse or promote products derived from
15 * this software without specific prior written permission.
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 * ----------------------------------------------------------------------------
30 //------------------------------------------------------------------------------
35 /// Standard output methods for reporting debug information, warnings and
36 /// errors, which can be easily be turned on/off.
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.
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
63 //------------------------------------------------------------------------------
68 //------------------------------------------------------------------------------
70 //------------------------------------------------------------------------------
73 #include <dbgu/dbgu.h>
77 //------------------------------------------------------------------------------
79 //------------------------------------------------------------------------------
82 #define SOFTPACK_VERSION "1.6RC1"
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
91 // By default, all traces are output except the debug one.
92 #if !defined(TRACE_LEVEL)
93 #define TRACE_LEVEL TRACE_LEVEL_INFO
96 // By default, trace level is static (not dynamic)
97 #if !defined(DYN_TRACES)
102 #error "Error: NOTRACE has to be not defined !"
107 #if (TRACE_LEVEL == TRACE_LEVEL_NO_TRACE)
114 //------------------------------------------------------------------------------
116 //------------------------------------------------------------------------------
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); \
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) {}
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); \
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 //------------------------------------------------------------------------------
155 #define TRACE_DEBUG(...) { }
156 #define TRACE_INFO(...) { }
157 #define TRACE_WARNING(...) { }
158 #define TRACE_ERROR(...) { }
159 #define TRACE_FATAL(...) { while(1); }
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); }
167 #elif (DYN_TRACES == 1)
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); } }
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); } }
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__); }
189 #define TRACE_DEBUG(...) { }
190 #define TRACE_DEBUG_WP(...) { }
193 #if (TRACE_LEVEL >= TRACE_LEVEL_INFO)
194 #define TRACE_INFO(...) { printf("-I- " __VA_ARGS__); }
195 #define TRACE_INFO_WP(...) { printf(__VA_ARGS__); }
197 #define TRACE_INFO(...) { }
198 #define TRACE_INFO_WP(...) { }
201 #if (TRACE_LEVEL >= TRACE_LEVEL_WARNING)
202 #define TRACE_WARNING(...) { printf("-W- " __VA_ARGS__); }
203 #define TRACE_WARNING_WP(...) { printf(__VA_ARGS__); }
205 #define TRACE_WARNING(...) { }
206 #define TRACE_WARNING_WP(...) { }
209 #if (TRACE_LEVEL >= TRACE_LEVEL_ERROR)
210 #define TRACE_ERROR(...) { printf("-E- " __VA_ARGS__); }
211 #define TRACE_ERROR_WP(...) { printf(__VA_ARGS__); }
213 #define TRACE_ERROR(...) { }
214 #define TRACE_ERROR_WP(...) { }
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); }
221 #define TRACE_FATAL(...) { while(1); }
222 #define TRACE_FATAL_WP(...) { while(1); }
228 //------------------------------------------------------------------------------
229 // Exported variables
230 //------------------------------------------------------------------------------
231 // Depending on DYN_TRACES, traceLevel is a modifable runtime variable
233 #if !defined(NOTRACE) && (DYN_TRACES == 1)
234 extern unsigned int traceLevel;
237 #endif //#ifndef TRACE_H