1 /* ----------------------------------------------------------------------------
\r
2 * SAM Software Package License
\r
3 * ----------------------------------------------------------------------------
\r
4 * Copyright (c) 2012, 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
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 * \par traceLevels 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
76 * Global Definitions
\r
79 /** Softpack Version */
\r
80 #define SOFTPACK_VERSION "0.1"
\r
82 #define TRACE_LEVEL_DEBUG 5
\r
83 #define TRACE_LEVEL_INFO 4
\r
84 #define TRACE_LEVEL_WARNING 3
\r
85 #define TRACE_LEVEL_ERROR 2
\r
86 #define TRACE_LEVEL_FATAL 1
\r
87 #define TRACE_LEVEL_NO_TRACE 0
\r
89 /* By default, all traces are output except the debug one. */
\r
90 #if !defined(TRACE_LEVEL)
\r
91 #define TRACE_LEVEL TRACE_LEVEL_INFO
\r
94 /* By default, trace level is static (not dynamic) */
\r
95 #if !defined(DYN_TRACES)
\r
96 #define DYN_TRACES 0
\r
99 #if defined(NOTRACE)
\r
100 #error "Error: NOTRACE has to be not defined !"
\r
104 #if (DYN_TRACES==0)
\r
105 #if (TRACE_LEVEL == TRACE_LEVEL_NO_TRACE)
\r
112 /* ------------------------------------------------------------------------------
\r
114 * ------------------------------------------------------------------------------
\r
117 extern void TRACE_CONFIGURE( uint32_t dwBaudRate, uint32_t dwMCk ) ;
\r
120 * Initializes the DBGU for ISP project
\r
122 * \param mode DBGU mode.
\r
123 * \param baudrate DBGU baudrate.
\r
124 * \param mck Master clock frequency.
\r
130 #if (TRACE_LEVEL==0) && (DYNTRACE==0)
\r
131 #define TRACE_CONFIGURE_ISP(mode, baudrate, mck) {}
\r
133 #define TRACE_CONFIGURE_ISP(mode, baudrate, mck) { \
\r
134 const Pin pinsUART0[] = {PINS_UART}; \
\r
135 PIO_Configure(pinsUART0, PIO_LISTSIZE(pinsUART0)); \
\r
136 UART_Configure( baudrate, mck ) ; \
\r
141 * Outputs a formatted string using 'printf' if the log level is high
\r
142 * enough. Can be disabled by defining TRACE_LEVEL=0 during compilation.
\r
143 * \param ... Additional parameters depending on formatted string.
\r
145 #if defined(NOTRACE)
\r
148 #define TRACE_DEBUG(...) { }
\r
149 #define TRACE_INFO(...) { }
\r
150 #define TRACE_WARNING(...) { }
\r
151 #define TRACE_ERROR(...) { }
\r
152 #define TRACE_FATAL(...) { while(1); }
\r
154 #define TRACE_DEBUG_WP(...) { }
\r
155 #define TRACE_INFO_WP(...) { }
\r
156 #define TRACE_WARNING_WP(...) { }
\r
157 #define TRACE_ERROR_WP(...) { }
\r
158 #define TRACE_FATAL_WP(...) { while(1); }
\r
160 #elif (DYN_TRACES == 1)
\r
162 /* Trace output depends on dwTraceLevel value */
\r
163 #define TRACE_DEBUG(...) { if (dwTraceLevel >= TRACE_LEVEL_DEBUG) { printf("-D- " __VA_ARGS__); } }
\r
164 #define TRACE_INFO(...) { if (dwTraceLevel >= TRACE_LEVEL_INFO) { printf("-I- " __VA_ARGS__); } }
\r
165 #define TRACE_WARNING(...) { if (dwTraceLevel >= TRACE_LEVEL_WARNING) { printf("-W- " __VA_ARGS__); } }
\r
166 #define TRACE_ERROR(...) { if (dwTraceLevel >= TRACE_LEVEL_ERROR) { printf("-E- " __VA_ARGS__); } }
\r
167 #define TRACE_FATAL(...) { if (dwTraceLevel >= TRACE_LEVEL_FATAL) { printf("-F- " __VA_ARGS__); while(1); } }
\r
169 #define TRACE_DEBUG_WP(...) { if (dwTraceLevel >= TRACE_LEVEL_DEBUG) { printf(__VA_ARGS__); } }
\r
170 #define TRACE_INFO_WP(...) { if (dwTraceLevel >= TRACE_LEVEL_INFO) { printf(__VA_ARGS__); } }
\r
171 #define TRACE_WARNING_WP(...) { if (dwTraceLevel >= TRACE_LEVEL_WARNING) { printf(__VA_ARGS__); } }
\r
172 #define TRACE_ERROR_WP(...) { if (dwTraceLevel >= TRACE_LEVEL_ERROR) { printf(__VA_ARGS__); } }
\r
173 #define TRACE_FATAL_WP(...) { if (dwTraceLevel >= TRACE_LEVEL_FATAL) { printf(__VA_ARGS__); while(1); } }
\r
177 /* Trace compilation depends on TRACE_LEVEL value */
\r
178 #if (TRACE_LEVEL >= TRACE_LEVEL_DEBUG)
\r
179 #define TRACE_DEBUG(...) { printf("-D- " __VA_ARGS__); }
\r
180 #define TRACE_DEBUG_WP(...) { printf(__VA_ARGS__); }
\r
182 #define TRACE_DEBUG(...) { }
\r
183 #define TRACE_DEBUG_WP(...) { }
\r
186 #if (TRACE_LEVEL >= TRACE_LEVEL_INFO)
\r
187 #define TRACE_INFO(...) { printf("-I- " __VA_ARGS__); }
\r
188 #define TRACE_INFO_WP(...) { printf(__VA_ARGS__); }
\r
190 #define TRACE_INFO(...) { }
\r
191 #define TRACE_INFO_WP(...) { }
\r
194 #if (TRACE_LEVEL >= TRACE_LEVEL_WARNING)
\r
195 #define TRACE_WARNING(...) { printf("-W- " __VA_ARGS__); }
\r
196 #define TRACE_WARNING_WP(...) { printf(__VA_ARGS__); }
\r
198 #define TRACE_WARNING(...) { }
\r
199 #define TRACE_WARNING_WP(...) { }
\r
202 #if (TRACE_LEVEL >= TRACE_LEVEL_ERROR)
\r
203 #define TRACE_ERROR(...) { printf("-E- " __VA_ARGS__); }
\r
204 #define TRACE_ERROR_WP(...) { printf(__VA_ARGS__); }
\r
206 #define TRACE_ERROR(...) { }
\r
207 #define TRACE_ERROR_WP(...) { }
\r
210 #if (TRACE_LEVEL >= TRACE_LEVEL_FATAL)
\r
211 #define TRACE_FATAL(...) { printf("-F- " __VA_ARGS__); while(1); }
\r
212 #define TRACE_FATAL_WP(...) { printf(__VA_ARGS__); while(1); }
\r
214 #define TRACE_FATAL(...) { while(1); }
\r
215 #define TRACE_FATAL_WP(...) { while(1); }
\r
222 * Exported variables
\r
224 /** Depending on DYN_TRACES, dwTraceLevel is a modifable runtime variable or a define */
\r
225 #if !defined(NOTRACE) && (DYN_TRACES == 1)
\r
226 extern uint32_t dwTraceLevel ;
\r
229 #endif //#ifndef TRACE_H
\r