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