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