diff --git a/srv/debug.c b/srv/debug.c index 00f1265..23d3794 100644 --- a/srv/debug.c +++ b/srv/debug.c @@ -11,6 +11,8 @@ #include "dma_mbuf.h" #include "format.h" +#if DEBUG_TRACE || DEBUG_WARN || DEBUG_ERROR + //--local definitions----------------------------------------------------------- @@ -27,8 +29,6 @@ static uint8_t tx_buffer[BUFFER_SIZE]; //--public functions------------------------------------------------------------ -#if DEBUG_TRACE || DEBUG_WARN || DEBUG_ERROR - void _debug_init(enum UsartPeriph usart, enum GpioPort tx_port, enum GpioPin tx_pin) { @@ -45,16 +45,12 @@ void _debug_init(enum UsartPeriph usart, enum GpioPort tx_port, debug_trace("------------------------------------------------------------------------------\n"); } -#endif - -#if DEBUG_TRACE - -void _debug_trace(char* format, ...) +void _debug_print(const char* restrict header, + const char* restrict format, ...) { - write_debug('T', nullptr); - write_debug(':', nullptr); va_list va; va_start(va, format); + format_vfctprintf(write_debug, nullptr, header, va); format_vfctprintf(write_debug, nullptr, format, va); va_end(va); write_debug('\n', nullptr); @@ -63,40 +59,13 @@ void _debug_trace(char* format, ...) while (dma_mbuf_switch(&mbuf)) {} } -#endif - -#if DEBUG_WARN - -void _debug_warn(char* format, ...) -{ - print_debug("W:"); - print_debug(format); - - //ensure everything is written when done - while (dma_mbuf_switch(&mbuf)) {} -} - -#endif - -#if DEBUG_ERROR - -void _debug_error(char* format, ...) -{ - print_debug("E:"); - print_debug(format); - - //ensure everything is written when done - while (dma_mbuf_switch(&mbuf)) {} -} - -#endif //--local functions------------------------------------------------------------- -#if DEBUG_TRACE || DEBUG_WARN || DEBUG_ERROR - static uint32_t write_debug(uint8_t c, void* arg) { + (void)arg; //unused, required because of FormatCallback + while (dma_mbuf_write_byte(&mbuf, c)) { //buffer is full, wait until transfer started @@ -106,5 +75,6 @@ static uint32_t write_debug(uint8_t c, void* arg) return 0; } -#endif +#endif //DEBUG_TRACE || DEBUG_WARN || DEBUG_ERROR + diff --git a/srv/debug.h b/srv/debug.h index b954511..7fcb31d 100644 --- a/srv/debug.h +++ b/srv/debug.h @@ -14,8 +14,8 @@ #include "../drv/gpio.h" #define DEBUG_TRACE 1 -#define DEBUG_WARN 0 -#define DEBUG_ERROR 0 +#define DEBUG_WARN 1 +#define DEBUG_ERROR 1 //--type definitions------------------------------------------------------------ @@ -27,19 +27,22 @@ #endif #if DEBUG_TRACE -#define debug_trace(format, ...) _debug_trace(format __VA_OPT__(,) __VA_ARGS__) +#define debug_trace(format, ...) _debug_print("T:", \ + format __VA_OPT__(,) __VA_ARGS__) #else #define debug_trace(format, ...) do {} while (0) #endif #if DEBUG_WARN -#define debug_warn(format, ...) _debug_warn(format __VA_OPT__(,) __VA_ARGS__) +#define debug_warn(format, ...) _debug_print("W:", \ + format __VA_OPT__(,) __VA_ARGS__) #else #define debug_warn(format, ...) do {} while (0) #endif #if DEBUG_ERROR -#define debug_error(format, ...) _debug_error(format __VA_OPT__(,) __VA_ARGS__) +#define debug_error(format, ...) _debug_print("E:", \ + format __VA_OPT__(,) __VA_ARGS__) #else #define debug_error(format, ...) do {} while (0) #endif @@ -47,12 +50,15 @@ //--functions------------------------------------------------------------------- +#if DEBUG_TRACE || DEBUG_WARN || DEBUG_ERROR + void _debug_init(enum UsartPeriph usart, enum GpioPort tx_port, enum GpioPin tx_pin); -void _debug_trace(char* format, ...); -void _debug_warn(char* format, ...); -void _debug_error(char* format, ...); +void _debug_print(const char* restrict header, + const char* restrict format, ...); + +#endif #endif //_DEBUG_H_