Mod Library
Sun Devil Rocketry's hardware agnostic utility library
Toggle main menu visibility
Loading...
Searching...
No Matches
debug_sdr.h
Go to the documentation of this file.
1
28
29
/* Define to prevent recursive inclusion -------------------------------------*/
30
#ifndef DEBUG_H
31
#define DEBUG_H
32
33
#ifdef __cplusplus
34
extern
"C"
{
35
#endif
36
37
/* Includes ------------------------------------------------------------------*/
38
#include <stdbool.h>
39
#include <stdio.h>
40
41
#include "main.h"
42
43
/* Constants -----------------------------------------------------------------*/
44
#ifndef DEBUG_INTF_BUF_SIZE
/* allow the project to override the buffer length if needed */
45
#define DEBUG_INTF_BUF_SIZE 2048
/* bytes */
46
#endif
47
48
#define DEBUG_MSG_PREAMBLE_MAX_LEN 22
/* "[XX:XX:XX.XXX ERROR]: " */
49
#define DEBUG_MSG_MAX_LEN 128
/* total length allowed incl newline */
50
#define DEBUG_MSG_USER_MAX_LEN (DEBUG_MSG_MAX_LEN - DEBUG_MSG_PREAMBLE_MAX_LEN)
51
/* max length of the user provided msg */
52
53
/* Types ---------------------------------------------------------------------*/
54
typedef
void (*debug_write_callback)(
void
*, size_t);
55
typedef
void (*overflow_callback)(
const
char
*, size_t);
56
57
/* this handle is exposed here, but will only be modified internally */
58
typedef
struct
_DEBUG_HANDLE
{
59
debug_write_callback write_function;
/* callback to a function to write to the log (async) */
60
overflow_callback overflow_function;
/* callback to a function to handle overflow events */
61
/* the default handling is to clear the debug buffer and */
62
/* then add a message indicating that it has overflowed */
63
64
uint8_t tx_buf[DEBUG_INTF_BUF_SIZE];
/* the log message buffer */
65
uint8_t* buf_tx_head;
/* the address of the next message to be sent over the wire*/
66
uint8_t* buf_put_head;
/* the address to put the next message */
67
size_t
buffer_size_cnt;
/* the amount of unsent data in the buffer */
68
bool
transmitting;
/* flag to indicate whether we're currently transmitting */
69
} DEBUG_HANDLE;
70
71
typedef
enum
_DEBUG_STATUS {
72
DEBUG_OK = 0,
73
DEBUG_FAIL,
74
DEBUG_OVERFLOW
75
} DEBUG_STATUS;
76
77
typedef
enum
_DEBUG_LEVEL {
78
LOG_LVL_INFO,
79
LOG_LVL_WARN,
80
LOG_LVL_ERROR
/* note: "debug" errors will not trigger in release builds */
81
} DEBUG_LEVEL;
82
83
/* Exported functions prototypes ---------------------------------------------*/
84
85
DEBUG_STATUS
debug_init
86
(
87
debug_write_callback write_function,
88
overflow_callback overflow_function
89
);
90
91
void
debug_clear
92
(
93
void
94
);
95
96
DEBUG_STATUS
debug_log
97
(
98
const
char
* message,
99
size_t
len,
100
DEBUG_LEVEL log_level
101
);
102
103
void
debug_callback_handler
104
(
105
void
106
);
107
108
/* Debug Only Alias Macros --------------------------------------------------------------*/
109
117
#if defined( DEBUG ) || !defined( RELBLD )
118
#define debug_assert( condition, error ) \
119
do { if ( !(condition) ) error_fail_fast( error ); } while(0)
120
#else
121
#define debug_assert( condition, error ) \
122
do { } while(0)
123
#endif
124
125
134
#if defined( DEBUG ) || !defined( RELBLD )
135
#define debug_log_assert( condition, msg, level ) \
136
do { if ( !(condition) ) debug_log(msg, strlen(msg), level); } while(0)
137
#else
138
#define debug_log_assert( condition, msg, level ) \
139
do { } while(0)
140
#endif
141
142
150
#if defined( DEBUG ) || !defined( RELBLD )
151
#define debug_log_msg( msg, level ) \
152
do { debug_log(msg, strlen(msg), level); } while(0)
153
#else
154
#define debug_log_msg( msg, level ) \
155
do { } while(0)
156
#endif
157
158
166
#if defined( EMULATOR )
167
#define debug_ignore_emulator_warnings_start() \
168
_Pragma("GCC diagnostic push") \
169
_Pragma("GCC diagnostic ignored \"-Wformat\"") \
170
_Pragma("GCC diagnostic ignored \"-Wdiscarded-qualifiers\"")
171
#else
172
#define debug_ignore_emulator_warnings_start()
/* do nothing */
173
#endif
174
175
183
#if defined( EMULATOR )
184
#define debug_ignore_emulator_warnings_stop() \
185
_Pragma("GCC diagnostic pop")
186
#else
187
#define debug_ignore_emulator_warnings_stop()
/* do nothing */
188
#endif
189
190
191
#endif
/* DEBUG_H */
debug_callback_handler
void debug_callback_handler(void)
The function to call after a write completes.
Definition
debug_sdr.c:225
debug_log
DEBUG_STATUS debug_log(const char *message, size_t len, DEBUG_LEVEL log_level)
Add to the debug buffer.
Definition
debug_sdr.c:144
debug_clear
void debug_clear(void)
Reset the circular buffer.
Definition
debug_sdr.c:121
debug_init
DEBUG_STATUS debug_init(debug_write_callback write_function, overflow_callback overflow_function)
Initializes the debug module.
Definition
debug_sdr.c:83
_DEBUG_HANDLE
Definition
debug_sdr.h:58
debug_sdr
debug_sdr.h
Generated by
1.18.0