Christina Quast | 53b2105 | 2014-12-09 15:34:35 +0100 | [diff] [blame] | 1 | /* ---------------------------------------------------------------------------- |
| 2 | * ATMEL Microcontroller Software Support |
| 3 | * ---------------------------------------------------------------------------- |
| 4 | * Copyright (c) 2008, Atmel Corporation |
| 5 | * |
| 6 | * All rights reserved. |
| 7 | * |
| 8 | * Redistribution and use in source and binary forms, with or without |
| 9 | * modification, are permitted provided that the following conditions are met: |
| 10 | * |
| 11 | * - Redistributions of source code must retain the above copyright notice, |
| 12 | * this list of conditions and the disclaimer below. |
| 13 | * |
| 14 | * Atmel's name may not be used to endorse or promote products derived from |
| 15 | * this software without specific prior written permission. |
| 16 | * |
| 17 | * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR |
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE |
| 20 | * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, |
| 23 | * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 24 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 25 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
| 26 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | * ---------------------------------------------------------------------------- |
| 28 | */ |
| 29 | |
| 30 | /** |
| 31 | * \file |
| 32 | * |
| 33 | * \par Purpose |
| 34 | * |
| 35 | * Standard output methods for reporting debug information, warnings and |
| 36 | * errors, which can be easily be turned on/off. |
| 37 | * |
| 38 | * \par Usage |
| 39 | * -# Initialize the DBGU using TRACE_CONFIGURE() if you intend to eventually |
| 40 | * disable ALL traces; otherwise use DBGU_Configure(). |
| 41 | * -# Uses the TRACE_DEBUG(), TRACE_INFO(), TRACE_WARNING(), TRACE_ERROR() |
| 42 | * TRACE_FATAL() macros to output traces throughout the program. |
| 43 | * -# Each type of trace has a level : Debug 5, Info 4, Warning 3, Error 2 |
| 44 | * and Fatal 1. Disable a group of traces by changing the value of |
| 45 | * TRACE_LEVEL during compilation; traces with a level bigger than TRACE_LEVEL |
| 46 | * are not generated. To generate no trace, use the reserved value 0. |
| 47 | * -# Trace disabling can be static or dynamic. If dynamic disabling is selected |
| 48 | * the trace level can be modified in runtime. If static disabling is selected |
| 49 | * the disabled traces are not compiled. |
| 50 | * |
| 51 | * \par traceLevels Trace level description |
| 52 | * -# TRACE_DEBUG (5): Traces whose only purpose is for debugging the program, |
| 53 | * and which do not produce meaningful information otherwise. |
| 54 | * -# TRACE_INFO (4): Informational trace about the program execution. Should |
| 55 | * enable the user to see the execution flow. |
| 56 | * -# TRACE_WARNING (3): Indicates that a minor error has happened. In most case |
| 57 | * it can be discarded safely; it may even be expected. |
| 58 | * -# TRACE_ERROR (2): Indicates an error which may not stop the program execution, |
| 59 | * but which indicates there is a problem with the code. |
| 60 | * -# TRACE_FATAL (1): Indicates a major error which prevents the program from going |
| 61 | * any further. |
| 62 | */ |
| 63 | |
| 64 | #ifndef _TRACE_ |
| 65 | #define _TRACE_ |
| 66 | |
| 67 | /* |
| 68 | * Headers |
| 69 | */ |
Christina Quast | 99f9f7b | 2014-12-13 13:30:31 +0100 | [diff] [blame] | 70 | #include "board.h" |
Christina Quast | 53b2105 | 2014-12-09 15:34:35 +0100 | [diff] [blame] | 71 | #include "pio.h" |
| 72 | |
| 73 | #include <stdio.h> |
| 74 | |
| 75 | /* |
| 76 | * Global Definitions |
| 77 | */ |
| 78 | |
| 79 | /** Softpack Version */ |
| 80 | #define SOFTPACK_VERSION "2.0" |
| 81 | |
| 82 | #define TRACE_LEVEL_DEBUG 5 |
| 83 | #define TRACE_LEVEL_INFO 4 |
| 84 | #define TRACE_LEVEL_WARNING 3 |
| 85 | #define TRACE_LEVEL_ERROR 2 |
| 86 | #define TRACE_LEVEL_FATAL 1 |
| 87 | #define TRACE_LEVEL_NO_TRACE 0 |
| 88 | |
| 89 | /* By default, all traces are output except the debug one. */ |
| 90 | #if !defined(TRACE_LEVEL) |
| 91 | #define TRACE_LEVEL TRACE_LEVEL_INFO |
| 92 | #endif |
| 93 | |
| 94 | /* By default, trace level is static (not dynamic) */ |
| 95 | #if !defined(DYN_TRACES) |
| 96 | #define DYN_TRACES 0 |
| 97 | #endif |
| 98 | |
| 99 | #if defined(NOTRACE) |
| 100 | #error "Error: NOTRACE has to be not defined !" |
| 101 | #endif |
| 102 | |
| 103 | #undef NOTRACE |
| 104 | #if (DYN_TRACES==0) |
| 105 | #if (TRACE_LEVEL == TRACE_LEVEL_NO_TRACE) |
| 106 | #define NOTRACE |
| 107 | #endif |
| 108 | #endif |
| 109 | |
| 110 | |
| 111 | |
| 112 | /* ------------------------------------------------------------------------------ |
| 113 | * Global Macros |
| 114 | * ------------------------------------------------------------------------------ |
| 115 | */ |
| 116 | |
| 117 | extern void TRACE_CONFIGURE( uint32_t dwBaudRate, uint32_t dwMCk ) ; |
| 118 | |
| 119 | /** |
| 120 | * Initializes the DBGU for ISP project |
| 121 | * |
| 122 | * \param mode DBGU mode. |
| 123 | * \param baudrate DBGU baudrate. |
| 124 | * \param mck Master clock frequency. |
| 125 | */ |
| 126 | #ifndef DYNTRACE |
| 127 | #define DYNTRACE 0 |
| 128 | #endif |
| 129 | |
| 130 | #if (TRACE_LEVEL==0) && (DYNTRACE==0) |
| 131 | #define TRACE_CONFIGURE_ISP(mode, baudrate, mck) {} |
| 132 | #else |
| 133 | #define TRACE_CONFIGURE_ISP(mode, baudrate, mck) { \ |
| 134 | const Pin pinsUART0[] = {PINS_UART}; \ |
| 135 | PIO_Configure(pinsUART0, PIO_LISTSIZE(pinsUART0)); \ |
| 136 | UART_Configure( baudrate, mck ) ; \ |
| 137 | } |
| 138 | #endif |
| 139 | |
| 140 | /** |
| 141 | * Outputs a formatted string using 'printf' if the log level is high |
| 142 | * enough. Can be disabled by defining TRACE_LEVEL=0 during compilation. |
| 143 | * \param ... Additional parameters depending on formatted string. |
| 144 | */ |
| 145 | #if defined(NOTRACE) |
| 146 | |
| 147 | /* Empty macro */ |
| 148 | #define TRACE_DEBUG(...) { } |
| 149 | #define TRACE_INFO(...) { } |
| 150 | #define TRACE_WARNING(...) { } |
| 151 | #define TRACE_ERROR(...) { } |
| 152 | #define TRACE_FATAL(...) { while(1); } |
| 153 | |
| 154 | #define TRACE_DEBUG_WP(...) { } |
| 155 | #define TRACE_INFO_WP(...) { } |
| 156 | #define TRACE_WARNING_WP(...) { } |
| 157 | #define TRACE_ERROR_WP(...) { } |
| 158 | #define TRACE_FATAL_WP(...) { while(1); } |
| 159 | |
| 160 | #elif (DYN_TRACES == 1) |
| 161 | |
| 162 | /* Trace output depends on dwTraceLevel value */ |
| 163 | #define TRACE_DEBUG(...) { if (dwTraceLevel >= TRACE_LEVEL_DEBUG) { printf("-D- " __VA_ARGS__); } } |
| 164 | #define TRACE_INFO(...) { if (dwTraceLevel >= TRACE_LEVEL_INFO) { printf("-I- " __VA_ARGS__); } } |
| 165 | #define TRACE_WARNING(...) { if (dwTraceLevel >= TRACE_LEVEL_WARNING) { printf("-W- " __VA_ARGS__); } } |
| 166 | #define TRACE_ERROR(...) { if (dwTraceLevel >= TRACE_LEVEL_ERROR) { printf("-E- " __VA_ARGS__); } } |
| 167 | #define TRACE_FATAL(...) { if (dwTraceLevel >= TRACE_LEVEL_FATAL) { printf("-F- " __VA_ARGS__); while(1); } } |
| 168 | |
| 169 | #define TRACE_DEBUG_WP(...) { if (dwTraceLevel >= TRACE_LEVEL_DEBUG) { printf(__VA_ARGS__); } } |
| 170 | #define TRACE_INFO_WP(...) { if (dwTraceLevel >= TRACE_LEVEL_INFO) { printf(__VA_ARGS__); } } |
| 171 | #define TRACE_WARNING_WP(...) { if (dwTraceLevel >= TRACE_LEVEL_WARNING) { printf(__VA_ARGS__); } } |
| 172 | #define TRACE_ERROR_WP(...) { if (dwTraceLevel >= TRACE_LEVEL_ERROR) { printf(__VA_ARGS__); } } |
| 173 | #define TRACE_FATAL_WP(...) { if (dwTraceLevel >= TRACE_LEVEL_FATAL) { printf(__VA_ARGS__); while(1); } } |
| 174 | |
| 175 | #else |
| 176 | |
| 177 | /* Trace compilation depends on TRACE_LEVEL value */ |
| 178 | #if (TRACE_LEVEL >= TRACE_LEVEL_DEBUG) |
Christina Quast | 19d2635 | 2015-01-03 21:43:09 +0100 | [diff] [blame] | 179 | #define TRACE_DEBUG(...) { printf("-D- " __VA_ARGS__); printf("(%s func. %s)\n\r", __FILE__, __FUNCTION__); } |
Christina Quast | 53b2105 | 2014-12-09 15:34:35 +0100 | [diff] [blame] | 180 | #define TRACE_DEBUG_WP(...) { printf(__VA_ARGS__); } |
| 181 | #else |
| 182 | #define TRACE_DEBUG(...) { } |
| 183 | #define TRACE_DEBUG_WP(...) { } |
| 184 | #endif |
| 185 | |
| 186 | #if (TRACE_LEVEL >= TRACE_LEVEL_INFO) |
| 187 | #define TRACE_INFO(...) { printf("-I- " __VA_ARGS__); } |
| 188 | #define TRACE_INFO_WP(...) { printf(__VA_ARGS__); } |
| 189 | #else |
| 190 | #define TRACE_INFO(...) { } |
| 191 | #define TRACE_INFO_WP(...) { } |
| 192 | #endif |
| 193 | |
| 194 | #if (TRACE_LEVEL >= TRACE_LEVEL_WARNING) |
| 195 | #define TRACE_WARNING(...) { printf("-W- " __VA_ARGS__); } |
| 196 | #define TRACE_WARNING_WP(...) { printf(__VA_ARGS__); } |
| 197 | #else |
| 198 | #define TRACE_WARNING(...) { } |
| 199 | #define TRACE_WARNING_WP(...) { } |
| 200 | #endif |
| 201 | |
| 202 | #if (TRACE_LEVEL >= TRACE_LEVEL_ERROR) |
| 203 | #define TRACE_ERROR(...) { printf("-E- " __VA_ARGS__); } |
| 204 | #define TRACE_ERROR_WP(...) { printf(__VA_ARGS__); } |
| 205 | #else |
| 206 | #define TRACE_ERROR(...) { } |
| 207 | #define TRACE_ERROR_WP(...) { } |
| 208 | #endif |
| 209 | |
| 210 | #if (TRACE_LEVEL >= TRACE_LEVEL_FATAL) |
| 211 | #define TRACE_FATAL(...) { printf("-F- " __VA_ARGS__); while(1); } |
| 212 | #define TRACE_FATAL_WP(...) { printf(__VA_ARGS__); while(1); } |
| 213 | #else |
| 214 | #define TRACE_FATAL(...) { while(1); } |
| 215 | #define TRACE_FATAL_WP(...) { while(1); } |
| 216 | #endif |
| 217 | |
| 218 | #endif |
| 219 | |
Christina Quast | ce8fa7e | 2015-03-13 13:09:51 +0100 | [diff] [blame] | 220 | #if defined(USB_NO_DEBUG) |
| 221 | #undef TRACE_DEBUG_WP |
| 222 | #define TRACE_DEBUG(...) { } |
| 223 | |
| 224 | #undef TRACE_INFO_WP |
| 225 | #define TRACE_INFO_WP(...) { } |
| 226 | #endif |
Christina Quast | 53b2105 | 2014-12-09 15:34:35 +0100 | [diff] [blame] | 227 | |
| 228 | /** |
| 229 | * Exported variables |
| 230 | */ |
| 231 | /** Depending on DYN_TRACES, dwTraceLevel is a modifable runtime variable or a define */ |
| 232 | #if !defined(NOTRACE) && (DYN_TRACES == 1) |
| 233 | extern uint32_t dwTraceLevel ; |
| 234 | #endif |
| 235 | |
| 236 | #endif //#ifndef TRACE_H |
| 237 | |