debug.h
Go to the documentation of this file.
1 /**
2  * @file debug.h
3  * @brief Debugging facilities
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2022 Oryx Embedded SARL. All rights reserved.
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software Foundation,
23  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24  *
25  * @author Oryx Embedded SARL (www.oryx-embedded.com)
26  * @version 2.1.8
27  **/
28 
29 #ifndef _DEBUG_H
30 #define _DEBUG_H
31 
32 //Dependencies
33 #include <stdio.h>
34 #include "os_port.h"
35 
36 //Trace level definitions
37 #define TRACE_LEVEL_OFF 0
38 #define TRACE_LEVEL_FATAL 1
39 #define TRACE_LEVEL_ERROR 2
40 #define TRACE_LEVEL_WARNING 3
41 #define TRACE_LEVEL_INFO 4
42 #define TRACE_LEVEL_DEBUG 5
43 #define TRACE_LEVEL_VERBOSE 6
44 
45 //Default trace level
46 #ifndef TRACE_LEVEL
47  #define TRACE_LEVEL TRACE_LEVEL_DEBUG
48 #endif
49 
50 //Trace output redirection
51 #ifndef TRACE_PRINTF
52  #define TRACE_PRINTF(...) osSuspendAllTasks(), fprintf(stderr, __VA_ARGS__), osResumeAllTasks()
53 #endif
54 
55 #ifndef TRACE_ARRAY
56  #define TRACE_ARRAY(p, a, n) osSuspendAllTasks(), debugDisplayArray(stderr, p, a, n), osResumeAllTasks()
57 #endif
58 
59 #ifndef TRACE_MPI
60  #define TRACE_MPI(p, a) osSuspendAllTasks(), mpiDump(stderr, p, a), osResumeAllTasks()
61 #endif
62 
63 //Debugging macros
64 #if (TRACE_LEVEL >= TRACE_LEVEL_FATAL)
65  #define TRACE_FATAL(...) TRACE_PRINTF(__VA_ARGS__)
66  #define TRACE_FATAL_ARRAY(p, a, n) TRACE_ARRAY(p, a, n)
67  #define TRACE_FATAL_MPI(p, a) TRACE_MPI(p, a)
68 #else
69  #define TRACE_FATAL(...)
70  #define TRACE_FATAL_ARRAY(p, a, n)
71  #define TRACE_FATAL_MPI(p, a)
72 #endif
73 
74 #if (TRACE_LEVEL >= TRACE_LEVEL_ERROR)
75  #define TRACE_ERROR(...) TRACE_PRINTF(__VA_ARGS__)
76  #define TRACE_ERROR_ARRAY(p, a, n) TRACE_ARRAY(p, a, n)
77  #define TRACE_ERROR_MPI(p, a) TRACE_MPI(p, a)
78 #else
79  #define TRACE_ERROR(...)
80  #define TRACE_ERROR_ARRAY(p, a, n)
81  #define TRACE_ERROR_MPI(p, a)
82 #endif
83 
84 #if (TRACE_LEVEL >= TRACE_LEVEL_WARNING)
85  #define TRACE_WARNING(...) TRACE_PRINTF(__VA_ARGS__)
86  #define TRACE_WARNING_ARRAY(p, a, n) TRACE_ARRAY(p, a, n)
87  #define TRACE_WARNING_MPI(p, a) TRACE_MPI(p, a)
88 #else
89  #define TRACE_WARNING(...)
90  #define TRACE_WARNING_ARRAY(p, a, n)
91  #define TRACE_WARNING_MPI(p, a)
92 #endif
93 
94 #if (TRACE_LEVEL >= TRACE_LEVEL_INFO)
95  #define TRACE_INFO(...) TRACE_PRINTF(__VA_ARGS__)
96  #define TRACE_INFO_ARRAY(p, a, n) TRACE_ARRAY(p, a, n)
97  #define TRACE_INFO_NET_BUFFER(p, b, o, n)
98  #define TRACE_INFO_MPI(p, a) TRACE_MPI(p, a)
99 #else
100  #define TRACE_INFO(...)
101  #define TRACE_INFO_ARRAY(p, a, n)
102  #define TRACE_INFO_NET_BUFFER(p, b, o, n)
103  #define TRACE_INFO_MPI(p, a)
104 #endif
105 
106 #if (TRACE_LEVEL >= TRACE_LEVEL_DEBUG)
107  #define TRACE_DEBUG(...) TRACE_PRINTF(__VA_ARGS__)
108  #define TRACE_DEBUG_ARRAY(p, a, n) TRACE_ARRAY(p, a, n)
109  #define TRACE_DEBUG_NET_BUFFER(p, b, o, n)
110  #define TRACE_DEBUG_MPI(p, a) TRACE_MPI(p, a)
111 #else
112  #define TRACE_DEBUG(...)
113  #define TRACE_DEBUG_ARRAY(p, a, n)
114  #define TRACE_DEBUG_NET_BUFFER(p, b, o, n)
115  #define TRACE_DEBUG_MPI(p, a)
116 #endif
117 
118 #if (TRACE_LEVEL >= TRACE_LEVEL_VERBOSE)
119  #define TRACE_VERBOSE(...) TRACE_PRINTF(__VA_ARGS__)
120  #define TRACE_VERBOSE_ARRAY(p, a, n) TRACE_ARRAY(p, a, n)
121  #define TRACE_VERBOSE_NET_BUFFER(p, b, o, n)
122  #define TRACE_VERBOSE_MPI(p, a) TRACE_MPI(p, a)
123 #else
124  #define TRACE_VERBOSE(...)
125  #define TRACE_VERBOSE_ARRAY(p, a, n)
126  #define TRACE_VERBOSE_NET_BUFFER(p, b, o, n)
127  #define TRACE_VERBOSE_MPI(p, a)
128 #endif
129 
130 //C++ guard
131 #ifdef __cplusplus
132 extern "C" {
133 #endif
134 
135 //Debug related functions
136 void debugInit(uint32_t baudrate);
137 
138 void debugDisplayArray(FILE *stream,
139  const char_t *prepend, const void *data, size_t length);
140 
141 //Deprecated definitions
142 #define TRACE_LEVEL_NO_TRACE TRACE_LEVEL_OFF
143 
144 //C++ guard
145 #ifdef __cplusplus
146 }
147 #endif
148 
149 #endif
uint8_t length
Definition: coap_common.h:193
uint8_t data[]
Definition: ethernet.h:220
void debugDisplayArray(FILE *stream, const char_t *prepend, const void *data, size_t length)
Display the contents of an array.
Definition: debug.c:41
void debugInit(uint32_t baudrate)
char char_t
Definition: compiler_port.h:43
RTOS abstraction layer.