hdo  beta
/home/mrazik/Documents/web/old/hdo/at91lib/utility/trace.h
Zobrazit dokumentaci tohoto souboru.
00001 /* ----------------------------------------------------------------------------
00002  *         ATMEL Microcontroller Software Support 
00003  * ----------------------------------------------------------------------------
00004  * Copyright (c) 2008, 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 //------------------------------------------------------------------------------
00062 
00063 //------------------------------------------------------------------------------
00064 
00065 #ifndef TRACE_H
00066 #define TRACE_H
00067 
00068 //------------------------------------------------------------------------------
00069 //         Headers
00070 //------------------------------------------------------------------------------
00071 
00072 #include <board.h>
00073 #include <dbgu/dbgu.h>
00074 #include <pio/pio.h>
00075 #include <stdio.h>
00076 
00077 //------------------------------------------------------------------------------
00078 //         Global Definitions
00079 //------------------------------------------------------------------------------
00080 
00082 #define SOFTPACK_VERSION "1.5"
00083 
00084 #define TRACE_LEVEL_DEBUG      5
00085 #define TRACE_LEVEL_INFO       4
00086 #define TRACE_LEVEL_WARNING    3
00087 #define TRACE_LEVEL_ERROR      2
00088 #define TRACE_LEVEL_FATAL      1
00089 #define TRACE_LEVEL_NO_TRACE   0
00090 
00091 // By default, all traces are output except the debug one.
00092 #if !defined(TRACE_LEVEL)    
00093 #define TRACE_LEVEL TRACE_LEVEL_INFO
00094 #endif
00095 
00096 // By default, trace level is static (not dynamic)
00097 #if !defined(DYN_TRACES)
00098 #define DYN_TRACES 0
00099 #endif
00100 
00101 #if defined(NOTRACE)
00102 #error "Error: NOTRACE has to be not defined !"
00103 #endif
00104 
00105 #undef NOTRACE
00106 #if (TRACE_LEVEL == TRACE_LEVEL_NO_TRACE)
00107 #define NOTRACE
00108 #endif
00109 
00110 
00111 
00112 //------------------------------------------------------------------------------
00113 //         Global Macros
00114 //------------------------------------------------------------------------------
00115 
00116 //------------------------------------------------------------------------------
00121 //------------------------------------------------------------------------------
00122 #define TRACE_CONFIGURE(mode, baudrate, mck) { \
00123     const Pin pinsDbgu[] = {PINS_DBGU}; \
00124     PIO_Configure(pinsDbgu, PIO_LISTSIZE(pinsDbgu)); \
00125     DBGU_Configure(mode, baudrate, mck); \
00126     }
00127 
00128 //------------------------------------------------------------------------------
00133 //------------------------------------------------------------------------------
00134 #if (TRACE_LEVEL==0) && (DYNTRACE==0)
00135 #define TRACE_CONFIGURE_ISP(mode, baudrate, mck) {}
00136 #else
00137 #define TRACE_CONFIGURE_ISP(mode, baudrate, mck) { \
00138     const Pin pinsDbgu[] = {PINS_DBGU}; \
00139     PIO_Configure(pinsDbgu, PIO_LISTSIZE(pinsDbgu)); \
00140     DBGU_Configure(mode, baudrate, mck); \
00141     }
00142 #endif
00143 
00144 //------------------------------------------------------------------------------
00148 //------------------------------------------------------------------------------
00149 #if defined(NOTRACE)
00150 
00151 // Empty macro
00152 #define TRACE_DEBUG(...)      { }
00153 #define TRACE_INFO(...)       { }
00154 #define TRACE_WARNING(...)    { }               
00155 #define TRACE_ERROR(...)      { }
00156 #define TRACE_FATAL(...)      { while(1); }
00157 
00158 #define TRACE_DEBUG_WP(...)   { }
00159 #define TRACE_INFO_WP(...)    { }
00160 #define TRACE_WARNING_WP(...) { }
00161 #define TRACE_ERROR_WP(...)   { }
00162 #define TRACE_FATAL_WP(...)   { while(1); }
00163 
00164 #elif (DYN_TRACES == 1)
00165 
00166 // Trace output depends on traceLevel value
00167 #define TRACE_DEBUG(...)      { if (traceLevel >= TRACE_LEVEL_DEBUG)   { printf("-D- " __VA_ARGS__); } }
00168 #define TRACE_INFO(...)       { if (traceLevel >= TRACE_LEVEL_INFO)    { printf("-I- " __VA_ARGS__); } }
00169 #define TRACE_WARNING(...)    { if (traceLevel >= TRACE_LEVEL_WARNING) { printf("-W- " __VA_ARGS__); } }
00170 #define TRACE_ERROR(...)      { if (traceLevel >= TRACE_LEVEL_ERROR)   { printf("-E- " __VA_ARGS__); } }
00171 #define TRACE_FATAL(...)      { if (traceLevel >= TRACE_LEVEL_FATAL)   { printf("-F- " __VA_ARGS__); while(1); } }
00172 
00173 #define TRACE_DEBUG_WP(...)   { if (traceLevel >= TRACE_LEVEL_DEBUG)   { printf(__VA_ARGS__); } }
00174 #define TRACE_INFO_WP(...)    { if (traceLevel >= TRACE_LEVEL_INFO)    { printf(__VA_ARGS__); } }
00175 #define TRACE_WARNING_WP(...) { if (traceLevel >= TRACE_LEVEL_WARNING) { printf(__VA_ARGS__); } }
00176 #define TRACE_ERROR_WP(...)   { if (traceLevel >= TRACE_LEVEL_ERROR)   { printf(__VA_ARGS__); } }
00177 #define TRACE_FATAL_WP(...)   { if (traceLevel >= TRACE_LEVEL_FATAL)   { printf(__VA_ARGS__); while(1); } }
00178 
00179 #else
00180 
00181 // Trace compilation depends on TRACE_LEVEL value
00182 #if (TRACE_LEVEL >= TRACE_LEVEL_DEBUG)
00183 #define TRACE_DEBUG(...)      { printf("-D- " __VA_ARGS__); }
00184 #define TRACE_DEBUG_WP(...)   { printf(__VA_ARGS__); }
00185 #else
00186 #define TRACE_DEBUG(...)      { }
00187 #define TRACE_DEBUG_WP(...)   { }
00188 #endif
00189 
00190 #if (TRACE_LEVEL >= TRACE_LEVEL_INFO)
00191 #define TRACE_INFO(...)       { printf("-I- " __VA_ARGS__); }
00192 #define TRACE_INFO_WP(...)    { printf(__VA_ARGS__); }
00193 #else
00194 #define TRACE_INFO(...)       { }
00195 #define TRACE_INFO_WP(...)    { }
00196 #endif
00197 
00198 #if (TRACE_LEVEL >= TRACE_LEVEL_WARNING)
00199 #define TRACE_WARNING(...)    { printf("-W- " __VA_ARGS__); }
00200 #define TRACE_WARNING_WP(...) { printf(__VA_ARGS__); }
00201 #else
00202 #define TRACE_WARNING(...)    { }
00203 #define TRACE_WARNING_WP(...) { }
00204 #endif
00205 
00206 #if (TRACE_LEVEL >= TRACE_LEVEL_ERROR)
00207 #define TRACE_ERROR(...)      { printf("-E- " __VA_ARGS__); }
00208 #define TRACE_ERROR_WP(...)   { printf(__VA_ARGS__); }
00209 #else
00210 #define TRACE_ERROR(...)      { }
00211 #define TRACE_ERROR_WP(...)   { }
00212 #endif
00213 
00214 #if (TRACE_LEVEL >= TRACE_LEVEL_FATAL)
00215 #define TRACE_FATAL(...)      { printf("-F- " __VA_ARGS__); while(1); }
00216 #define TRACE_FATAL_WP(...)   { printf(__VA_ARGS__); while(1); }
00217 #else
00218 #define TRACE_FATAL(...)      { while(1); }
00219 #define TRACE_FATAL_WP(...)   { while(1); }
00220 #endif
00221 
00222 #endif
00223 
00224 
00225 //------------------------------------------------------------------------------
00226 //         Exported variables
00227 //------------------------------------------------------------------------------
00228 // Depending on DYN_TRACES, traceLevel is a modifable runtime variable
00229 // or a define
00230 #if !defined(NOTRACE) && (DYN_TRACES == 1)
00231     extern unsigned int traceLevel;
00232 #endif
00233 
00234 #endif //#ifndef TRACE_H
00235