SAMV71 Xplained Ultra Software Package 1.3

trace.h

Go to the documentation of this file.
00001 /* ----------------------------------------------------------------------------
00002  *         SAM Software Package License
00003  * ----------------------------------------------------------------------------
00004  * Copyright (c) 2012, Atmel Corporation
00005  *
00006  * All rights reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions are met:
00010  *
00011  * - Redistributions of source code must retain the above copyright notice,
00012  * this list of conditions and the disclaimer below.
00013  *
00014  * Atmel's name may not be used to endorse or promote products derived from
00015  * this software without specific prior written permission.
00016  *
00017  * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00019  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
00020  * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00022  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
00023  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00024  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00025  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
00026  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  * ----------------------------------------------------------------------------
00028  */
00029 
00030 /**
00031  *  \file
00032  *
00033  *  \par Purpose
00034  *
00035  *  Standard output methods for reporting debug information, warnings and
00036  *  errors, which can be easily be turned on/off.
00037  *
00038  *  \par Usage
00039  *  -# Initialize the DBGU using TRACE_CONFIGURE() if you intend to eventually
00040  *     disable ALL traces; otherwise use DBGU_Configure().
00041  *  -# Uses the TRACE_DEBUG(), TRACE_INFO(), TRACE_WARNING(), TRACE_ERROR()
00042  *     TRACE_FATAL() macros to output traces throughout the program.
00043  *  -# Each type of trace has a level : Debug 5, Info 4, Warning 3, Error 2
00044  *     and Fatal 1. Disable a group of traces by changing the value of
00045  *     TRACE_LEVEL during compilation; traces with a level bigger than TRACE_LEVEL
00046  *     are not generated. To generate no trace, use the reserved value 0.
00047  *  -# Trace disabling can be static or dynamic. If dynamic disabling is selected
00048  *     the trace level can be modified in runtime. If static disabling is selected
00049  *     the disabled traces are not compiled.
00050  *
00051  *  \par traceLevels Trace level description
00052  *  -# TRACE_DEBUG (5): Traces whose only purpose is for debugging the program,
00053  *     and which do not produce meaningful information otherwise.
00054  *  -# TRACE_INFO (4): Informational trace about the program execution. Should
00055  *     enable the user to see the execution flow.
00056  *  -# TRACE_WARNING (3): Indicates that a minor error has happened. In most case
00057  *     it can be discarded safely; it may even be expected.
00058  *  -# TRACE_ERROR (2): Indicates an error which may not stop the program execution,
00059  *     but which indicates there is a problem with the code.
00060  *  -# TRACE_FATAL (1): Indicates a major error which prevents the program from going
00061  *     any further.
00062  */
00063 
00064 #ifndef _TRACE_
00065 #define _TRACE_
00066 
00067 /*
00068  *         Headers
00069  */
00070 
00071 #include "pio.h"
00072 
00073 #include <stdio.h>
00074 
00075 /*
00076  *         Global Definitions
00077  */
00078 
00079 /**  Softpack Version */
00080 #define SOFTPACK_VERSION       "1.3"
00081 
00082 #define TRACE_LEVEL_DEBUG      5
00083 #define TRACE_LEVEL_INFO       4
00084 #define TRACE_LEVEL_WARNING    3
00085 #define TRACE_LEVEL_ERROR      2
00086 #define TRACE_LEVEL_FATAL      1
00087 #define TRACE_LEVEL_NO_TRACE   0
00088 
00089 /* By default, all traces are output except the debug one. */
00090 #if !defined(TRACE_LEVEL)
00091 #define TRACE_LEVEL TRACE_LEVEL_INFO
00092 #endif
00093 
00094 /* By default, trace level is static (not dynamic) */
00095 #if !defined(DYN_TRACES)
00096 #define DYN_TRACES 0
00097 #endif
00098 
00099 #if defined(NOTRACE)
00100 #error "Error: NOTRACE has to be not defined !"
00101 #endif
00102 
00103 #undef NOTRACE
00104 #if (DYN_TRACES==0)
00105     #if (TRACE_LEVEL == TRACE_LEVEL_NO_TRACE)
00106         #define NOTRACE
00107     #endif
00108 #endif
00109 
00110 
00111 
00112 /* ------------------------------------------------------------------------------
00113  *         Global Macros
00114  * ------------------------------------------------------------------------------
00115  */
00116 
00117 extern void TRACE_CONFIGURE( uint32_t dwBaudRate, uint32_t dwMCk ) ;
00118 
00119 /**
00120  *  Initializes the DBGU for ISP project
00121  *
00122  *  \param mode  DBGU mode.
00123  *  \param baudrate  DBGU baudrate.
00124  *  \param mck  Master clock frequency.
00125  */
00126 #ifndef DYNTRACE
00127 #define DYNTRACE 0
00128 #endif
00129 
00130 #if (TRACE_LEVEL==0) && (DYNTRACE==0)
00131 #define TRACE_CONFIGURE_ISP(mode, baudrate, mck) {}
00132 #else
00133 #define TRACE_CONFIGURE_ISP(mode, baudrate, mck) { \
00134     const Pin pinsUART0[] = {PINS_UART}; \
00135     PIO_Configure(pinsUART0, PIO_LISTSIZE(pinsUART0)); \
00136     UART_Configure( baudrate, mck ) ; \
00137     }
00138 #endif
00139 
00140 /**
00141  *  Outputs a formatted string using 'printf' if the log level is high
00142  *  enough. Can be disabled by defining TRACE_LEVEL=0 during compilation.
00143  *  \param ...  Additional parameters depending on formatted string.
00144  */
00145 #if defined(NOTRACE)
00146 
00147 /* Empty macro */
00148 #define TRACE_DEBUG(...)      { }
00149 #define TRACE_INFO(...)       { }
00150 #define TRACE_WARNING(...)    { }
00151 #define TRACE_ERROR(...)      { }
00152 #define TRACE_FATAL(...)      { while(1); }
00153 
00154 #define TRACE_DEBUG_WP(...)   { }
00155 #define TRACE_INFO_WP(...)    { }
00156 #define TRACE_WARNING_WP(...) { }
00157 #define TRACE_ERROR_WP(...)   { }
00158 #define TRACE_FATAL_WP(...)   { while(1); }
00159 
00160 #elif (DYN_TRACES == 1)
00161 
00162 /* Trace output depends on dwTraceLevel value */
00163 #define TRACE_DEBUG(...)      { if (dwTraceLevel >= TRACE_LEVEL_DEBUG)   { printf("-D- " __VA_ARGS__); } }
00164 #define TRACE_INFO(...)       { if (dwTraceLevel >= TRACE_LEVEL_INFO)    { printf("-I- " __VA_ARGS__); } }
00165 #define TRACE_WARNING(...)    { if (dwTraceLevel >= TRACE_LEVEL_WARNING) { printf("-W- " __VA_ARGS__); } }
00166 #define TRACE_ERROR(...)      { if (dwTraceLevel >= TRACE_LEVEL_ERROR)   { printf("-E- " __VA_ARGS__); } }
00167 #define TRACE_FATAL(...)      { if (dwTraceLevel >= TRACE_LEVEL_FATAL)   { printf("-F- " __VA_ARGS__); while(1); } }
00168 
00169 #define TRACE_DEBUG_WP(...)   { if (dwTraceLevel >= TRACE_LEVEL_DEBUG)   { printf(__VA_ARGS__); } }
00170 #define TRACE_INFO_WP(...)    { if (dwTraceLevel >= TRACE_LEVEL_INFO)    { printf(__VA_ARGS__); } }
00171 #define TRACE_WARNING_WP(...) { if (dwTraceLevel >= TRACE_LEVEL_WARNING) { printf(__VA_ARGS__); } }
00172 #define TRACE_ERROR_WP(...)   { if (dwTraceLevel >= TRACE_LEVEL_ERROR)   { printf(__VA_ARGS__); } }
00173 #define TRACE_FATAL_WP(...)   { if (dwTraceLevel >= TRACE_LEVEL_FATAL)   { printf(__VA_ARGS__); while(1); } }
00174 
00175 #else
00176 
00177 /* Trace compilation depends on TRACE_LEVEL value */
00178 #if (TRACE_LEVEL >= TRACE_LEVEL_DEBUG)
00179 #define TRACE_DEBUG(...)      { printf("-D- " __VA_ARGS__); }
00180 #define TRACE_DEBUG_WP(...)   { printf(__VA_ARGS__); }
00181 #else
00182 #define TRACE_DEBUG(...)      { }
00183 #define TRACE_DEBUG_WP(...)   { }
00184 #endif
00185 
00186 #if (TRACE_LEVEL >= TRACE_LEVEL_INFO)
00187 #define TRACE_INFO(...)       { printf("-I- " __VA_ARGS__); }
00188 #define TRACE_INFO_WP(...)    { printf(__VA_ARGS__); }
00189 #else
00190 #define TRACE_INFO(...)       { }
00191 #define TRACE_INFO_WP(...)    { }
00192 #endif
00193 
00194 #if (TRACE_LEVEL >= TRACE_LEVEL_WARNING)
00195 #define TRACE_WARNING(...)    { printf("-W- " __VA_ARGS__); }
00196 #define TRACE_WARNING_WP(...) { printf(__VA_ARGS__); }
00197 #else
00198 #define TRACE_WARNING(...)    { }
00199 #define TRACE_WARNING_WP(...) { }
00200 #endif
00201 
00202 #if (TRACE_LEVEL >= TRACE_LEVEL_ERROR)
00203 #define TRACE_ERROR(...)      { printf("-E- " __VA_ARGS__); }
00204 #define TRACE_ERROR_WP(...)   { printf(__VA_ARGS__); }
00205 #else
00206 #define TRACE_ERROR(...)      { }
00207 #define TRACE_ERROR_WP(...)   { }
00208 #endif
00209 
00210 #if (TRACE_LEVEL >= TRACE_LEVEL_FATAL)
00211 #define TRACE_FATAL(...)      { printf("-F- " __VA_ARGS__); while(1); }
00212 #define TRACE_FATAL_WP(...)   { printf(__VA_ARGS__); while(1); }
00213 #else
00214 #define TRACE_FATAL(...)      { while(1); }
00215 #define TRACE_FATAL_WP(...)   { while(1); }
00216 #endif
00217 
00218 #endif
00219 
00220 
00221 /**
00222  *        Exported variables
00223  */
00224 /** Depending on DYN_TRACES, dwTraceLevel is a modifiable runtime variable or a define */
00225 #if !defined(NOTRACE) && (DYN_TRACES == 1)
00226     extern uint32_t dwTraceLevel ;
00227 #endif
00228 
00229 #endif //#ifndef TRACE_H
00230 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines