]> git.sur5r.net Git - freertos/blob - Demo/Common/drivers/Atmel/at91lib/utility/trace.h
Start to re-arrange files to include FreeRTOS+ in main download.
[freertos] / Demo / Common / drivers / Atmel / at91lib / utility / trace.h
1 /* ----------------------------------------------------------------------------\r
2  *         ATMEL Microcontroller Software Support \r
3  * ----------------------------------------------------------------------------\r
4  * Copyright (c) 2008, 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     Title: Trace\r
32 \r
33     About: Purpose\r
34         Standard output methods for reporting debug information, warnings and\r
35         errors, which can be turned on/off.\r
36 \r
37     About: Usage\r
38         1 - Initialize the DBGU using <trace_CONFIGURE>.\r
39         2 - Uses the <trace_LOG> macro to output traces throughout the program.\r
40         3 - Turn off all traces by defining the NOTRACE symbol during\r
41             compilation.\r
42         4 - Disable a group of trace by changing the value of <trace_LEVEL>\r
43             during compilation; traces with a level below <trace_LEVEL> are not\r
44             generated.\r
45 */\r
46 \r
47 #ifndef TRACE_H\r
48 #define TRACE_H\r
49 \r
50 //------------------------------------------------------------------------------\r
51 //         Headers\r
52 //------------------------------------------------------------------------------\r
53 \r
54 #if !defined(NOTRACE)\r
55     #include <board.h>\r
56     #include <dbgu/dbgu.h>\r
57     #include <pio/pio.h>\r
58     #include <stdio.h>\r
59 #endif\r
60 \r
61 //------------------------------------------------------------------------------\r
62 //         Definitions\r
63 //------------------------------------------------------------------------------\r
64 /*\r
65     Constants: Trace levels\r
66         trace_FATAL - Indicates a major error which prevents the program from\r
67             going any further.\r
68         trace_ERROR - Indicates an error which may not stop the program\r
69             execution, but which indicates there is a problem with the code.\r
70         trace_WARNING - Indicates that a minor error has happened. In most case\r
71             it can be discarded safely; it may even be expected.\r
72         trace_INFO - Informational trace about the program execution. Should\r
73             enable the user to see the execution flow.\r
74         trace_DEBUG - Traces whose only purpose is for debugging the program,\r
75             and which do not produce meaningful information otherwise.\r
76 */\r
77 #define trace_DEBUG                     0\r
78 #define trace_INFO                      1\r
79 #define trace_WARNING                   2\r
80 #define trace_ERROR                     3\r
81 #define trace_FATAL                     4\r
82 \r
83 /*\r
84     Constant: trace_LEVEL\r
85         Minimum level of traces that are output. By default, all traces are\r
86         output; change the value of this symbol during compilation for a more\r
87         restrictive behavior.\r
88 */\r
89 #if !defined(trace_LEVEL)\r
90     #define trace_LEVEL                     0\r
91 #endif\r
92 \r
93 /*\r
94     Macro: trace_CONFIGURE\r
95         Initializes the DBGU unless the NOTRACE symbol has been defined.\r
96 \r
97     Parameters:\r
98         mode - DBGU mode.\r
99         baudrate - DBGU baudrate.\r
100         mck - Master clock frequency.\r
101 */\r
102 #if !defined(NOTRACE)\r
103     #define trace_CONFIGURE(mode, baudrate, mck) { \\r
104         const Pin pinsDbgu[] = {PINS_DBGU}; \\r
105         PIO_Configure(pinsDbgu, PIO_LISTSIZE(pinsDbgu)); \\r
106         DBGU_Configure(mode, baudrate, mck); \\r
107     }\r
108 #else\r
109     #define trace_CONFIGURE(...)\r
110 #endif\r
111 \r
112 /*\r
113     Macro: trace_LOG\r
114         Outputs a formatted string using <printf> if the log level is high\r
115         enough. Can be disabled by defining the NOTRACE symbol during\r
116         compilation.\r
117 \r
118     Parameters:\r
119         level - Trace level (see <Trace levels>).\r
120         format - Formatted string to output.\r
121         ... - Additional parameters, depending on the formatted string.\r
122 */\r
123 #if !defined(NOTRACE)\r
124     #define trace_LOG(level, ...) { \\r
125         if (level >= trace_LEVEL) { \\r
126             printf(__VA_ARGS__); \\r
127         } \\r
128     }\r
129 #else\r
130     #define trace_LOG(...)\r
131 #endif\r
132 \r
133 #endif //#ifndef TRACE_H\r
134 \r