RTEMS 6.1-rc1
trace.h
Go to the documentation of this file.
1/* ---------------------------------------------------------------------------- */
2/* Atmel Microcontroller Software Support */
3/* SAM Software Package License */
4/* ---------------------------------------------------------------------------- */
5/* Copyright (c) 2015, Atmel Corporation */
6/* */
7/* All rights reserved. */
8/* */
9/* Redistribution and use in source and binary forms, with or without */
10/* modification, are permitted provided that the following condition is met: */
11/* */
12/* - Redistributions of source code must retain the above copyright notice, */
13/* this list of conditions and the disclaimer below. */
14/* */
15/* Atmel's name may not be used to endorse or promote products derived from */
16/* this software without specific prior written permission. */
17/* */
18/* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR */
19/* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
20/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE */
21/* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, */
22/* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */
23/* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, */
24/* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */
25/* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */
26/* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
27/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
28/* ---------------------------------------------------------------------------- */
29
64#ifndef _TRACE_
65#define _TRACE_
66
67/*
68 * Headers
69 */
70
71#include "pio.h"
72
73#include <stdio.h>
74
75/*
76 * Global Definitions
77 */
78
80#define SOFTPACK_VERSION "1.5"
81
82
83#define TRACE_LEVEL_DEBUG 5
84#define TRACE_LEVEL_INFO 4
85#define TRACE_LEVEL_WARNING 3
86#define TRACE_LEVEL_ERROR 2
87#define TRACE_LEVEL_FATAL 1
88#define TRACE_LEVEL_NO_TRACE 0
89
90/* By default, all traces are output except the debug one. */
91#if !defined(TRACE_LEVEL)
92 #define TRACE_LEVEL TRACE_LEVEL_INFO
93#endif
94
95/* By default, trace level is static (not dynamic) */
96#if !defined(DYN_TRACES)
97 #define DYN_TRACES 0
98#endif
99
100#if defined(NOTRACE)
101 #error "Error: NOTRACE has to be not defined !"
102#endif
103
104#undef NOTRACE
105#if (DYN_TRACES==0)
106 #if (TRACE_LEVEL == TRACE_LEVEL_NO_TRACE)
107 #define NOTRACE
108 #endif
109#endif
110
111
112
113/* ------------------------------------------------------------------------------
114 * Global Macros
115 * ------------------------------------------------------------------------------
116 */
117
118extern void TRACE_CONFIGURE(uint32_t dwBaudRate, uint32_t dwMCk);
119
127#ifndef DYNTRACE
128 #define DYNTRACE 0
129#endif
130
131#if (TRACE_LEVEL==0) && (DYNTRACE==0)
132#define TRACE_CONFIGURE_ISP(mode, baudrate, mck) {}
133#else
134#define TRACE_CONFIGURE_ISP(mode, baudrate, mck) { \
135 const Pin pinsUART0[] = {PINS_UART}; \
136 PIO_Configure(pinsUART0, PIO_LISTSIZE(pinsUART0)); \
137 UART_Configure(baudrate, mck); \
138 }
139#endif
140
146#if defined(NOTRACE)
147
148 /* Empty macro */
149 #define TRACE_DEBUG(...) { }
150 #define TRACE_INFO(...) { }
151 #define TRACE_WARNING(...) { }
152 #define TRACE_ERROR(...) { }
153 #define TRACE_FATAL(...) { while (1); }
154
155 #define TRACE_DEBUG_WP(...) { }
156 #define TRACE_INFO_WP(...) { }
157 #define TRACE_WARNING_WP(...) { }
158 #define TRACE_ERROR_WP(...) { }
159 #define TRACE_FATAL_WP(...) { while (1); }
160
161#elif (DYN_TRACES == 1)
162
163 /* Trace output depends on dwTraceLevel value */
164 #define TRACE_DEBUG(...) { if (dwTraceLevel >= TRACE_LEVEL_DEBUG) { printf("-D- " __VA_ARGS__); } }
165 #define TRACE_INFO(...) { if (dwTraceLevel >= TRACE_LEVEL_INFO) { printf("-I- " __VA_ARGS__); } }
166 #define TRACE_WARNING(...) { if (dwTraceLevel >= TRACE_LEVEL_WARNING) { printf("-W- " __VA_ARGS__); } }
167 #define TRACE_ERROR(...) { if (dwTraceLevel >= TRACE_LEVEL_ERROR) { printf("-E- " __VA_ARGS__); } }
168 #define TRACE_FATAL(...) { if (dwTraceLevel >= TRACE_LEVEL_FATAL) { printf("-F- " __VA_ARGS__); while (1); } }
169
170 #define TRACE_DEBUG_WP(...) { if (dwTraceLevel >= TRACE_LEVEL_DEBUG) { printf(__VA_ARGS__); } }
171 #define TRACE_INFO_WP(...) { if (dwTraceLevel >= TRACE_LEVEL_INFO) { printf(__VA_ARGS__); } }
172 #define TRACE_WARNING_WP(...) { if (dwTraceLevel >= TRACE_LEVEL_WARNING) { printf(__VA_ARGS__); } }
173 #define TRACE_ERROR_WP(...) { if (dwTraceLevel >= TRACE_LEVEL_ERROR) { printf(__VA_ARGS__); } }
174 #define TRACE_FATAL_WP(...) { if (dwTraceLevel >= TRACE_LEVEL_FATAL) { printf(__VA_ARGS__); while (1); } }
175
176#else
177
178 /* Trace compilation depends on TRACE_LEVEL value */
179 #if (TRACE_LEVEL >= TRACE_LEVEL_DEBUG)
180 #define TRACE_DEBUG(...) { printf("-D- " __VA_ARGS__); }
181 #define TRACE_DEBUG_WP(...) { printf(__VA_ARGS__); }
182 #else
183 #define TRACE_DEBUG(...) { }
184 #define TRACE_DEBUG_WP(...) { }
185 #endif
186
187 #if (TRACE_LEVEL >= TRACE_LEVEL_INFO)
188 #define TRACE_INFO(...) { printf("-I- " __VA_ARGS__); }
189 #define TRACE_INFO_WP(...) { printf(__VA_ARGS__); }
190 #else
191 #define TRACE_INFO(...) { }
192 #define TRACE_INFO_WP(...) { }
193 #endif
194
195 #if (TRACE_LEVEL >= TRACE_LEVEL_WARNING)
196 #define TRACE_WARNING(...) { printf("-W- " __VA_ARGS__); }
197 #define TRACE_WARNING_WP(...) { printf(__VA_ARGS__); }
198 #else
199 #define TRACE_WARNING(...) { }
200 #define TRACE_WARNING_WP(...) { }
201 #endif
202
203 #if (TRACE_LEVEL >= TRACE_LEVEL_ERROR)
204 #define TRACE_ERROR(...) { printf("-E- " __VA_ARGS__); }
205 #define TRACE_ERROR_WP(...) { printf(__VA_ARGS__); }
206 #else
207 #define TRACE_ERROR(...) { }
208 #define TRACE_ERROR_WP(...) { }
209 #endif
210
211 #if (TRACE_LEVEL >= TRACE_LEVEL_FATAL)
212 #define TRACE_FATAL(...) { printf("-F- " __VA_ARGS__); while (1); }
213 #define TRACE_FATAL_WP(...) { printf(__VA_ARGS__); while (1); }
214 #else
215 #define TRACE_FATAL(...) { while (1); }
216 #define TRACE_FATAL_WP(...) { while (1); }
217 #endif
218
219#endif
220
221
226#if !defined(NOTRACE) && (DYN_TRACES == 1)
227 extern uint32_t dwTraceLevel;
228#endif
229
230#endif //#ifndef TRACE_H
231