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-2019 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 1.9.6
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 
44 //Default trace level
45 #ifndef TRACE_LEVEL
46  #define TRACE_LEVEL TRACE_LEVEL_DEBUG
47 #endif
48 
49 //Trace output redirection
50 #ifndef TRACE_PRINTF
51  #define TRACE_PRINTF(...) osSuspendAllTasks(), fprintf(stderr, __VA_ARGS__), osResumeAllTasks()
52 #endif
53 
54 #ifndef TRACE_ARRAY
55  #define TRACE_ARRAY(p, a, n) osSuspendAllTasks(), debugDisplayArray(stderr, p, a, n), osResumeAllTasks()
56 #endif
57 
58 #ifndef TRACE_MPI
59  #define TRACE_MPI(p, a) osSuspendAllTasks(), mpiDump(stderr, p, a), osResumeAllTasks()
60 #endif
61 
62 //Debugging macros
63 #if (TRACE_LEVEL >= TRACE_LEVEL_FATAL)
64  #define TRACE_FATAL(...) TRACE_PRINTF(__VA_ARGS__)
65  #define TRACE_FATAL_ARRAY(p, a, n) TRACE_ARRAY(p, a, n)
66  #define TRACE_FATAL_MPI(p, a) TRACE_MPI(p, a)
67 #else
68  #define TRACE_FATAL(...)
69  #define TRACE_FATAL_ARRAY(p, a, n)
70  #define TRACE_FATAL_MPI(p, a)
71 #endif
72 
73 #if (TRACE_LEVEL >= TRACE_LEVEL_ERROR)
74  #define TRACE_ERROR(...) TRACE_PRINTF(__VA_ARGS__)
75  #define TRACE_ERROR_ARRAY(p, a, n) TRACE_ARRAY(p, a, n)
76  #define TRACE_ERROR_MPI(p, a) TRACE_MPI(p, a)
77 #else
78  #define TRACE_ERROR(...)
79  #define TRACE_ERROR_ARRAY(p, a, n)
80  #define TRACE_ERROR_MPI(p, a)
81 #endif
82 
83 #if (TRACE_LEVEL >= TRACE_LEVEL_WARNING)
84  #define TRACE_WARNING(...) TRACE_PRINTF(__VA_ARGS__)
85  #define TRACE_WARNING_ARRAY(p, a, n) TRACE_ARRAY(p, a, n)
86  #define TRACE_WARNING_MPI(p, a) TRACE_MPI(p, a)
87 #else
88  #define TRACE_WARNING(...)
89  #define TRACE_WARNING_ARRAY(p, a, n)
90  #define TRACE_WARNING_MPI(p, a)
91 #endif
92 
93 #if (TRACE_LEVEL >= TRACE_LEVEL_INFO)
94  #define TRACE_INFO(...) TRACE_PRINTF(__VA_ARGS__)
95  #define TRACE_INFO_ARRAY(p, a, n) TRACE_ARRAY(p, a, n)
96  #define TRACE_INFO_NET_BUFFER(p, b, o, n)
97  #define TRACE_INFO_MPI(p, a) TRACE_MPI(p, a)
98 #else
99  #define TRACE_INFO(...)
100  #define TRACE_INFO_ARRAY(p, a, n)
101  #define TRACE_INFO_NET_BUFFER(p, b, o, n)
102  #define TRACE_INFO_MPI(p, a)
103 #endif
104 
105 #if (TRACE_LEVEL >= TRACE_LEVEL_DEBUG)
106  #define TRACE_DEBUG(...) TRACE_PRINTF(__VA_ARGS__)
107  #define TRACE_DEBUG_ARRAY(p, a, n) TRACE_ARRAY(p, a, n)
108  #define TRACE_DEBUG_NET_BUFFER(p, b, o, n)
109  #define TRACE_DEBUG_MPI(p, a) TRACE_MPI(p, a)
110 #else
111  #define TRACE_DEBUG(...)
112  #define TRACE_DEBUG_ARRAY(p, a, n)
113  #define TRACE_DEBUG_NET_BUFFER(p, b, o, n)
114  #define TRACE_DEBUG_MPI(p, a)
115 #endif
116 
117 //C++ guard
118 #ifdef __cplusplus
119 extern "C" {
120 #endif
121 
122 //Debug related functions
123 void debugInit(uint32_t baudrate);
124 
125 void debugDisplayArray(FILE *stream,
126  const char_t *prepend, const void *data, size_t length);
127 
128 //Deprecated definitions
129 #define TRACE_LEVEL_NO_TRACE TRACE_LEVEL_OFF
130 
131 //C++ guard
132 #ifdef __cplusplus
133 }
134 #endif
135 
136 #endif
uint8_t length
Definition: dtls_misc.h:149
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
uint8_t data[]
Definition: dtls_misc.h:176
RTOS abstraction layer.