SAMV71 Xplained Ultra Software Package 1.5

trace.h

Go to the documentation of this file.
00001 /* ---------------------------------------------------------------------------- */
00002 /*                  Atmel Microcontroller Software Support                      */
00003 /*                       SAM Software Package License                           */
00004 /* ---------------------------------------------------------------------------- */
00005 /* Copyright (c) 2015, Atmel Corporation                                        */
00006 /*                                                                              */
00007 /* All rights reserved.                                                         */
00008 /*                                                                              */
00009 /* Redistribution and use in source and binary forms, with or without           */
00010 /* modification, are permitted provided that the following condition is met:    */
00011 /*                                                                              */
00012 /* - Redistributions of source code must retain the above copyright notice,     */
00013 /* this list of conditions and the disclaimer below.                            */
00014 /*                                                                              */
00015 /* Atmel's name may not be used to endorse or promote products derived from     */
00016 /* this software without specific prior written permission.                     */
00017 /*                                                                              */
00018 /* DISCLAIMER:  THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR   */
00019 /* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
00020 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE   */
00021 /* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,      */
00022 /* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */
00023 /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,  */
00024 /* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF    */
00025 /* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING         */
00026 /* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
00027 /* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                           */
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.5"
00081 
00082 
00083 #define TRACE_LEVEL_DEBUG      5
00084 #define TRACE_LEVEL_INFO       4
00085 #define TRACE_LEVEL_WARNING    3
00086 #define TRACE_LEVEL_ERROR      2
00087 #define TRACE_LEVEL_FATAL      1
00088 #define TRACE_LEVEL_NO_TRACE   0
00089 
00090 /* By default, all traces are output except the debug one. */
00091 #if !defined(TRACE_LEVEL)
00092     #define TRACE_LEVEL TRACE_LEVEL_INFO
00093 #endif
00094 
00095 /* By default, trace level is static (not dynamic) */
00096 #if !defined(DYN_TRACES)
00097     #define DYN_TRACES 0
00098 #endif
00099 
00100 #if defined(NOTRACE)
00101     #error "Error: NOTRACE has to be not defined !"
00102 #endif
00103 
00104 #undef NOTRACE
00105 #if (DYN_TRACES==0)
00106     #if (TRACE_LEVEL == TRACE_LEVEL_NO_TRACE)
00107         #define NOTRACE
00108     #endif
00109 #endif
00110 
00111 
00112 
00113 /* ------------------------------------------------------------------------------
00114  *         Global Macros
00115  * ------------------------------------------------------------------------------
00116  */
00117 
00118 extern void TRACE_CONFIGURE(uint32_t dwBaudRate, uint32_t dwMCk);
00119 
00120 /**
00121  *  Initializes the DBGU for ISP project
00122  *
00123  *  \param mode  DBGU mode.
00124  *  \param baudrate  DBGU baudrate.
00125  *  \param mck  Master clock frequency.
00126  */
00127 #ifndef DYNTRACE
00128     #define DYNTRACE 0
00129 #endif
00130 
00131 #if (TRACE_LEVEL==0) && (DYNTRACE==0)
00132 #define TRACE_CONFIGURE_ISP(mode, baudrate, mck) {}
00133 #else
00134 #define TRACE_CONFIGURE_ISP(mode, baudrate, mck) { \
00135         const Pin pinsUART0[] = {PINS_UART}; \
00136         PIO_Configure(pinsUART0, PIO_LISTSIZE(pinsUART0)); \
00137         UART_Configure(baudrate, mck); \
00138     }
00139 #endif
00140 
00141 /**
00142  *  Outputs a formatted string using 'printf' if the log level is high
00143  *  enough. Can be disabled by defining TRACE_LEVEL=0 during compilation.
00144  *  \param ...  Additional parameters depending on formatted string.
00145  */
00146 #if defined(NOTRACE)
00147 
00148     /* Empty macro */
00149     #define TRACE_DEBUG(...)      { }
00150     #define TRACE_INFO(...)       { }
00151     #define TRACE_WARNING(...)    { }
00152     #define TRACE_ERROR(...)      { }
00153     #define TRACE_FATAL(...)      { while (1); }
00154 
00155     #define TRACE_DEBUG_WP(...)   { }
00156     #define TRACE_INFO_WP(...)    { }
00157     #define TRACE_WARNING_WP(...) { }
00158     #define TRACE_ERROR_WP(...)   { }
00159     #define TRACE_FATAL_WP(...)   { while (1); }
00160 
00161 #elif (DYN_TRACES == 1)
00162 
00163     /* Trace output depends on dwTraceLevel value */
00164     #define TRACE_DEBUG(...)      { if (dwTraceLevel >= TRACE_LEVEL_DEBUG)   { printf("-D- " __VA_ARGS__); } }
00165     #define TRACE_INFO(...)       { if (dwTraceLevel >= TRACE_LEVEL_INFO)    { printf("-I- " __VA_ARGS__); } }
00166     #define TRACE_WARNING(...)    { if (dwTraceLevel >= TRACE_LEVEL_WARNING) { printf("-W- " __VA_ARGS__); } }
00167     #define TRACE_ERROR(...)      { if (dwTraceLevel >= TRACE_LEVEL_ERROR)   { printf("-E- " __VA_ARGS__); } }
00168     #define TRACE_FATAL(...)      { if (dwTraceLevel >= TRACE_LEVEL_FATAL)   { printf("-F- " __VA_ARGS__); while (1); } }
00169 
00170     #define TRACE_DEBUG_WP(...)   { if (dwTraceLevel >= TRACE_LEVEL_DEBUG)   { printf(__VA_ARGS__); } }
00171     #define TRACE_INFO_WP(...)    { if (dwTraceLevel >= TRACE_LEVEL_INFO)    { printf(__VA_ARGS__); } }
00172     #define TRACE_WARNING_WP(...) { if (dwTraceLevel >= TRACE_LEVEL_WARNING) { printf(__VA_ARGS__); } }
00173     #define TRACE_ERROR_WP(...)   { if (dwTraceLevel >= TRACE_LEVEL_ERROR)   { printf(__VA_ARGS__); } }
00174     #define TRACE_FATAL_WP(...)   { if (dwTraceLevel >= TRACE_LEVEL_FATAL)   { printf(__VA_ARGS__); while (1); } }
00175 
00176 #else
00177 
00178     /* Trace compilation depends on TRACE_LEVEL value */
00179     #if (TRACE_LEVEL >= TRACE_LEVEL_DEBUG)
00180         #define TRACE_DEBUG(...)      { printf("-D- " __VA_ARGS__); }
00181         #define TRACE_DEBUG_WP(...)   { printf(__VA_ARGS__); }
00182     #else
00183         #define TRACE_DEBUG(...)      { }
00184         #define TRACE_DEBUG_WP(...)   { }
00185     #endif
00186 
00187     #if (TRACE_LEVEL >= TRACE_LEVEL_INFO)
00188         #define TRACE_INFO(...)       { printf("-I- " __VA_ARGS__); }
00189         #define TRACE_INFO_WP(...)    { printf(__VA_ARGS__); }
00190     #else
00191         #define TRACE_INFO(...)       { }
00192         #define TRACE_INFO_WP(...)    { }
00193     #endif
00194 
00195     #if (TRACE_LEVEL >= TRACE_LEVEL_WARNING)
00196         #define TRACE_WARNING(...)    { printf("-W- " __VA_ARGS__); }
00197         #define TRACE_WARNING_WP(...) { printf(__VA_ARGS__); }
00198     #else
00199         #define TRACE_WARNING(...)    { }
00200         #define TRACE_WARNING_WP(...) { }
00201     #endif
00202 
00203     #if (TRACE_LEVEL >= TRACE_LEVEL_ERROR)
00204         #define TRACE_ERROR(...)      { printf("-E- " __VA_ARGS__); }
00205         #define TRACE_ERROR_WP(...)   { printf(__VA_ARGS__); }
00206     #else
00207         #define TRACE_ERROR(...)      { }
00208         #define TRACE_ERROR_WP(...)   { }
00209     #endif
00210 
00211     #if (TRACE_LEVEL >= TRACE_LEVEL_FATAL)
00212         #define TRACE_FATAL(...)      { printf("-F- " __VA_ARGS__); while (1); }
00213         #define TRACE_FATAL_WP(...)   { printf(__VA_ARGS__); while (1); }
00214     #else
00215         #define TRACE_FATAL(...)      { while (1); }
00216         #define TRACE_FATAL_WP(...)   { while (1); }
00217     #endif
00218 
00219 #endif
00220 
00221 
00222 /**
00223  *        Exported variables
00224  */
00225 /** Depending on DYN_TRACES, dwTraceLevel is a modifiable runtime variable or a define */
00226 #if !defined(NOTRACE) && (DYN_TRACES == 1)
00227     extern uint32_t dwTraceLevel;
00228 #endif
00229 
00230 #endif //#ifndef TRACE_H
00231 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines