]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_M7_SAMV71_Xplained/libchip_samv7/include/trace.h
Update version number ready for V8.2.1 release.
[freertos] / FreeRTOS / Demo / CORTEX_M7_SAMV71_Xplained / libchip_samv7 / include / trace.h
1 /* ----------------------------------------------------------------------------\r
2  *         SAM Software Package License\r
3  * ----------------------------------------------------------------------------\r
4  * Copyright (c) 2012, Atmel Corporation\r
5  *\r
6  * All rights reserved.\r
7  *\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
10  *\r
11  * - Redistributions of source code must retain the above copyright notice,\r
12  * this list of conditions and the disclaimer below.\r
13  *\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
16  *\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
28  */\r
29 \r
30 /**\r
31  *  \file\r
32  *\r
33  *  \par Purpose\r
34  *\r
35  *  Standard output methods for reporting debug information, warnings and\r
36  *  errors, which can be easily be turned on/off.\r
37  *\r
38  *  \par Usage\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
50  *\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
61  *     any further.\r
62  */\r
63 \r
64 #ifndef _TRACE_\r
65 #define _TRACE_\r
66 \r
67 /*\r
68  *         Headers\r
69  */\r
70 \r
71 #include "pio.h"\r
72 \r
73 #include <stdio.h>\r
74 \r
75 /*\r
76  *         Global Definitions\r
77  */\r
78 \r
79 /**  Softpack Version */\r
80 #define SOFTPACK_VERSION       "0.1"\r
81 \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
88 \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
92 #endif\r
93 \r
94 /* By default, trace level is static (not dynamic) */\r
95 #if !defined(DYN_TRACES)\r
96 #define DYN_TRACES 0\r
97 #endif\r
98 \r
99 #if defined(NOTRACE)\r
100 #error "Error: NOTRACE has to be not defined !"\r
101 #endif\r
102 \r
103 #undef NOTRACE\r
104 #if (DYN_TRACES==0)\r
105     #if (TRACE_LEVEL == TRACE_LEVEL_NO_TRACE)\r
106         #define NOTRACE\r
107     #endif\r
108 #endif\r
109 \r
110 \r
111 \r
112 /* ------------------------------------------------------------------------------\r
113  *         Global Macros\r
114  * ------------------------------------------------------------------------------\r
115  */\r
116 \r
117 extern void TRACE_CONFIGURE( uint32_t dwBaudRate, uint32_t dwMCk ) ;\r
118 \r
119 /**\r
120  *  Initializes the DBGU for ISP project\r
121  *\r
122  *  \param mode  DBGU mode.\r
123  *  \param baudrate  DBGU baudrate.\r
124  *  \param mck  Master clock frequency.\r
125  */\r
126 #ifndef DYNTRACE\r
127 #define DYNTRACE 0\r
128 #endif\r
129 \r
130 #if (TRACE_LEVEL==0) && (DYNTRACE==0)\r
131 #define TRACE_CONFIGURE_ISP(mode, baudrate, mck) {}\r
132 #else\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
137     }\r
138 #endif\r
139 \r
140 /**\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
144  */\r
145 #if defined(NOTRACE)\r
146 \r
147 /* Empty macro */\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
153 \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
159 \r
160 #elif (DYN_TRACES == 1)\r
161 \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
168 \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
174 \r
175 #else\r
176 \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
181 #else\r
182 #define TRACE_DEBUG(...)      { }\r
183 #define TRACE_DEBUG_WP(...)   { }\r
184 #endif\r
185 \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
189 #else\r
190 #define TRACE_INFO(...)       { }\r
191 #define TRACE_INFO_WP(...)    { }\r
192 #endif\r
193 \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
197 #else\r
198 #define TRACE_WARNING(...)    { }\r
199 #define TRACE_WARNING_WP(...) { }\r
200 #endif\r
201 \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
205 #else\r
206 #define TRACE_ERROR(...)      { }\r
207 #define TRACE_ERROR_WP(...)   { }\r
208 #endif\r
209 \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
213 #else\r
214 #define TRACE_FATAL(...)      { while(1); }\r
215 #define TRACE_FATAL_WP(...)   { while(1); }\r
216 #endif\r
217 \r
218 #endif\r
219 \r
220 \r
221 /**\r
222  *        Exported variables\r
223  */\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
227 #endif\r
228 \r
229 #endif //#ifndef TRACE_H\r
230 \r