debug USB stream

pull/130/head
Alex Voinea 2021-09-30 18:27:18 +02:00 committed by DRracer
parent 362d012eff
commit ea7d44a611
2 changed files with 32 additions and 27 deletions

View File

@ -2,7 +2,6 @@
#if defined(DEBUG_LOGIC) || defined(DEBUG_MODULES) || defined(DEBUG_HAL) #if defined(DEBUG_LOGIC) || defined(DEBUG_MODULES) || defined(DEBUG_HAL)
#include "hal/usart.h"
#include <avr/pgmspace.h> #include <avr/pgmspace.h>
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
@ -22,23 +21,23 @@ const char modules[] PROGMEM = "mod:";
const char hal[] PROGMEM = "hal:"; const char hal[] PROGMEM = "hal:";
#endif #endif
void __attribute__((noinline)) dbg_usart(const char *layer_P, const char *s) { void dbg_usb(const char *layer_P, const char *s) {
hu::usart1.WriteS_P(layer_P); fputs_P(layer_P, stdout);
hu::usart1.puts(s); puts(s);
} }
void __attribute__((noinline)) dbg_usart_P(const char *layer_P, const char *s_P) { void dbg_usb_P(const char *layer_P, const char *s_P) {
hu::usart1.WriteS_P(layer_P); fputs_P(layer_P, stdout);
hu::usart1.puts_P(s_P); puts_P(s_P);
} }
void __attribute__((noinline)) dbg_usart_sprintf_P(const char *fmt_P, ...) { void dbg_usb_fP(const char *layer_P, const char *fmt_P, ...) {
char tmp[30];
va_list argptr; va_list argptr;
va_start(argptr, fmt_P); va_start(argptr, fmt_P);
vsnprintf_P(tmp, 30, fmt_P, argptr); fputs_P(layer_P, stdout);
vfprintf_P(stdout, fmt_P, argptr);
putchar('\n');
va_end(argptr); va_end(argptr);
dbg_logic(tmp);
} }
} // namespace debug } // namespace debug

View File

@ -1,6 +1,7 @@
#pragma once #pragma once
#include <stdint.h> #include <stdint.h>
#include "config/config.h" #include "config/config.h"
#include <avr/pgmspace.h>
/// Enable DEBUG_LOGIC to compile debugging and error messages (beware of code base size ;) ) for the logic layer /// Enable DEBUG_LOGIC to compile debugging and error messages (beware of code base size ;) ) for the logic layer
//#define DEBUG_LOGIC //#define DEBUG_LOGIC
@ -21,48 +22,53 @@ namespace debug {
#if defined(DEBUG_LOGIC) && defined(__AVR__) #if defined(DEBUG_LOGIC) && defined(__AVR__)
extern const char logic[]; extern const char logic[];
#define dbg_logic(x) debug::dbg_usart(debug::logic, x) #define dbg_logic(x) debug::dbg_usb(debug::logic, x)
#define dbg_logic_P(x) debug::dbg_usart_P(debug::logic, x) #define dbg_logic_P(x) debug::dbg_usb_P(debug::logic, x)
#define dbg_logic_sprintf_P(fmt, ...) debug::dbg_usart_sprintf_P(fmt, __VA_ARGS__) #define dbg_logic_fP(fmt, ...) debug::dbg_usb_fP(debug::logic, fmt, __VA_ARGS__)
#else #else
#define dbg_logic(x) /* */ #define dbg_logic(x) /* */
#define dbg_logic_P(x) /* */ #define dbg_logic_P(x) /* */
#define dbg_logic_sprintf_P(fmt, ...) /* */ #define dbg_logic_fP(fmt, ...) /* */
#endif #endif
#if defined(DEBUG_MODULES) && defined(__AVR__) #if defined(DEBUG_MODULES) && defined(__AVR__)
extern const char modules[]; extern const char modules[];
#define dbg_modules(x) debug::dbg_usart(debug::modules, x) #define dbg_modules(x) debug::dbg_usb(debug::modules, x)
#define dbg_modules_P(x) debug::dbg_usart_P(debug::modules, x) #define dbg_modules_P(x) debug::dbg_usb_P(debug::modules, x)
#define dbg_modules_fP(fmt, ...) debug::dbg_usb_fP(debug::modules, fmt, __VA_ARGS__)
#else #else
#define dbg_modules(x) /* */ #define dbg_modules(x) /* */
#define dbg_modules_P(x) /* */ #define dbg_modules_P(x) /* */
#define dbg_modules_fP(fmt, ...) /* */
#endif #endif
#if defined(DEBUG_HAL) && defined(__AVR__) #if defined(DEBUG_HAL) && defined(__AVR__)
extern const char hal[]; extern const char hal[];
#define dbg_hal(x) debug::dbg_usart(debug::hal, x) #define dbg_hal(x) debug::dbg_usb(debug::hal, x)
#define dbg_hal_P(x) debug::dbg_usart_P(debug::hal, x) #define dbg_hal_P(x) debug::dbg_usb_P(debug::hal, x)
#define dbg_hal_fP(fmt, ...) debug::dbg_usb_fP(debug::hal, fmt, __VA_ARGS__)
#else #else
#define dbg_hal(x) /* */ #define dbg_hal(x) /* */
#define dbg_hal_P(x) /* */ #define dbg_hal_P(x) /* */
#define dbg_hal_fP(fmt, ...) /* */
#endif #endif
#if defined(DEBUG_LOGIC) || defined(DEBUG_MODULES) || defined(DEBUG_HAL) #if defined(DEBUG_LOGIC) || defined(DEBUG_MODULES) || defined(DEBUG_HAL)
/// Dump an error message onto the USART /// Dump an error message onto the usb
/// @param layer PROGMEM string /// @param layer PROGMEM string
/// @param s RAM string to be printed /// @param s RAM string to be printed
void dbg_usart(const char *layer_P, const char *s); void dbg_usb(const char *layer_P, const char *s);
/// Dump an error message onto the USART /// Dump an error message onto the usb
/// @param layer PROGMEM string /// @param layer PROGMEM string
/// @param s PROGMEM string to be printed /// @param s PROGMEM string to be printed
void dbg_usart_P(const char *layer_P, const char *s_P); void dbg_usb_P(const char *layer_P, const char *s_P);
/// Dump an error message onto the USART with sprintf-like formatting /// Dump an error message onto the usb
/// @param fmt_P PROGMEM format string /// @param layer PROGMEM string
void dbg_usart_sprintf_P(const char *fmt_P, ...); /// @param fmt PROGMEM format string
/// @param ... arguments passed to the formatting string
void dbg_usb_fP(const char *layer_P, const char *fmt_P, ...);
#endif #endif
} // namespace debug } // namespace debug