debug #2

Merged
Steins7 merged 11 commits from debug into rework 2024-04-20 11:15:32 +00:00
2 changed files with 23 additions and 47 deletions
Showing only changes of commit 84deb788a0 - Show all commits

View File

@ -11,6 +11,8 @@
#include "dma_mbuf.h" #include "dma_mbuf.h"
#include "format.h" #include "format.h"
#if DEBUG_TRACE || DEBUG_WARN || DEBUG_ERROR
//--local definitions----------------------------------------------------------- //--local definitions-----------------------------------------------------------
@ -27,8 +29,6 @@ static uint8_t tx_buffer[BUFFER_SIZE];
//--public functions------------------------------------------------------------ //--public functions------------------------------------------------------------
#if DEBUG_TRACE || DEBUG_WARN || DEBUG_ERROR
void _debug_init(enum UsartPeriph usart, enum GpioPort tx_port, void _debug_init(enum UsartPeriph usart, enum GpioPort tx_port,
enum GpioPin tx_pin) enum GpioPin tx_pin)
{ {
@ -45,16 +45,12 @@ void _debug_init(enum UsartPeriph usart, enum GpioPort tx_port,
debug_trace("------------------------------------------------------------------------------\n"); debug_trace("------------------------------------------------------------------------------\n");
} }
#endif void _debug_print(const char* restrict header,
const char* restrict format, ...)
#if DEBUG_TRACE
void _debug_trace(char* format, ...)
{ {
write_debug('T', nullptr);
write_debug(':', nullptr);
va_list va; va_list va;
va_start(va, format); va_start(va, format);
format_vfctprintf(write_debug, nullptr, header, va);
format_vfctprintf(write_debug, nullptr, format, va); format_vfctprintf(write_debug, nullptr, format, va);
va_end(va); va_end(va);
write_debug('\n', nullptr); write_debug('\n', nullptr);
@ -63,40 +59,13 @@ void _debug_trace(char* format, ...)
while (dma_mbuf_switch(&mbuf)) {} 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------------------------------------------------------------- //--local functions-------------------------------------------------------------
#if DEBUG_TRACE || DEBUG_WARN || DEBUG_ERROR
static uint32_t write_debug(uint8_t c, void* arg) static uint32_t write_debug(uint8_t c, void* arg)
{ {
(void)arg; //unused, required because of FormatCallback
while (dma_mbuf_write_byte(&mbuf, c)) while (dma_mbuf_write_byte(&mbuf, c))
{ {
//buffer is full, wait until transfer started //buffer is full, wait until transfer started
@ -106,5 +75,6 @@ static uint32_t write_debug(uint8_t c, void* arg)
return 0; return 0;
} }
#endif #endif //DEBUG_TRACE || DEBUG_WARN || DEBUG_ERROR

View File

@ -14,8 +14,8 @@
#include "../drv/gpio.h" #include "../drv/gpio.h"
#define DEBUG_TRACE 1 #define DEBUG_TRACE 1
#define DEBUG_WARN 0 #define DEBUG_WARN 1
#define DEBUG_ERROR 0 #define DEBUG_ERROR 1
//--type definitions------------------------------------------------------------ //--type definitions------------------------------------------------------------
@ -27,19 +27,22 @@
#endif #endif
#if DEBUG_TRACE #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 #else
#define debug_trace(format, ...) do {} while (0) #define debug_trace(format, ...) do {} while (0)
#endif #endif
#if DEBUG_WARN #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 #else
#define debug_warn(format, ...) do {} while (0) #define debug_warn(format, ...) do {} while (0)
#endif #endif
#if DEBUG_ERROR #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 #else
#define debug_error(format, ...) do {} while (0) #define debug_error(format, ...) do {} while (0)
#endif #endif
@ -47,12 +50,15 @@
//--functions------------------------------------------------------------------- //--functions-------------------------------------------------------------------
#if DEBUG_TRACE || DEBUG_WARN || DEBUG_ERROR
void _debug_init(enum UsartPeriph usart, enum GpioPort tx_port, void _debug_init(enum UsartPeriph usart, enum GpioPort tx_port,
enum GpioPin tx_pin); 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_ #endif //_DEBUG_H_