Compare commits
No commits in common. "26f2b4d545e486c2559a186003bdf0d12425ce03" and "254fec4f006d6e1fee5e0d345122fd32c9230f51" have entirely different histories.
26f2b4d545
...
254fec4f00
50
srv/debug.c
50
srv/debug.c
@ -11,8 +11,6 @@
|
|||||||
#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-----------------------------------------------------------
|
||||||
|
|
||||||
@ -29,6 +27,8 @@ 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,12 +45,16 @@ void _debug_init(enum UsartPeriph usart, enum GpioPort tx_port,
|
|||||||
debug_trace("------------------------------------------------------------------------------\n");
|
debug_trace("------------------------------------------------------------------------------\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void _debug_print(const char* restrict header,
|
#endif
|
||||||
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);
|
||||||
@ -59,16 +63,40 @@ void _debug_print(const char* restrict header,
|
|||||||
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
|
||||||
* Callback to use with format_vfctprintf() to print caracters to the debug port
|
|
||||||
*/
|
|
||||||
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
|
||||||
@ -78,5 +106,5 @@ static uint32_t write_debug(uint8_t c, void* arg)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif //DEBUG_TRACE || DEBUG_WARN || DEBUG_ERROR
|
#endif
|
||||||
|
|
||||||
|
|||||||
55
srv/debug.h
55
srv/debug.h
@ -14,8 +14,8 @@
|
|||||||
#include "../drv/gpio.h"
|
#include "../drv/gpio.h"
|
||||||
|
|
||||||
#define DEBUG_TRACE 1
|
#define DEBUG_TRACE 1
|
||||||
#define DEBUG_WARN 1
|
#define DEBUG_WARN 0
|
||||||
#define DEBUG_ERROR 1
|
#define DEBUG_ERROR 0
|
||||||
|
|
||||||
|
|
||||||
//--type definitions------------------------------------------------------------
|
//--type definitions------------------------------------------------------------
|
||||||
@ -27,40 +27,19 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if DEBUG_TRACE
|
#if DEBUG_TRACE
|
||||||
/**
|
#define debug_trace(format, ...) _debug_trace(format __VA_OPT__(,) __VA_ARGS__)
|
||||||
* Prints a trace message on the debug port. This function should return
|
|
||||||
* immediately, provided that the message's length doesn't exceed 80 caracters
|
|
||||||
* and that it isn't called in very quick succession. Otherwise, it will block
|
|
||||||
* until the internal buffering system is ready to accept the message
|
|
||||||
*/
|
|
||||||
#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__)
|
||||||
* Prints a warning message on the debug port. This function should return
|
|
||||||
* immediately, provided that the message's length doesn't exceed 80 caracters
|
|
||||||
* and that it isn't called in very quick succession. Otherwise, it will block
|
|
||||||
* until the internal buffering system is ready to accept the message
|
|
||||||
*/
|
|
||||||
#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__)
|
||||||
* Prints an error message on the debug port. This function should return
|
|
||||||
* immediately, provided that the message's length doesn't exceed 80 caracters
|
|
||||||
* and that it isn't called in very quick succession. Otherwise, it will block
|
|
||||||
* until the internal buffering system is ready to accept the message
|
|
||||||
*/
|
|
||||||
#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
|
||||||
@ -68,30 +47,12 @@
|
|||||||
|
|
||||||
//--functions-------------------------------------------------------------------
|
//--functions-------------------------------------------------------------------
|
||||||
|
|
||||||
#if DEBUG_TRACE || DEBUG_WARN || DEBUG_ERROR
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initializes the debug system to use the given usart peripheral on the given
|
|
||||||
* tx port, printing a banner if traces are enabled.
|
|
||||||
* The usart doesn't need to be configured, neither does the tx port.
|
|
||||||
*
|
|
||||||
* This function shouldn't be called directly. Instead, use the debug_init macro
|
|
||||||
*/
|
|
||||||
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, ...);
|
||||||
|
|
||||||
/**
|
|
||||||
* Prints a debug message on the debug port with the given header. This function
|
|
||||||
* should return immediately, provided that the message's length doesn't exceed
|
|
||||||
* 80 caracters and that it isn't called in very quick succession. Otherwise, it
|
|
||||||
* will block until the internal buffering system is ready to accept the message
|
|
||||||
*
|
|
||||||
* This function shouldn't be called directly. Instead, use the debug macros
|
|
||||||
*/
|
|
||||||
void _debug_print(const char* restrict header,
|
|
||||||
const char* restrict format, ...);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif //_DEBUG_H_
|
#endif //_DEBUG_H_
|
||||||
|
|
||||||
|
|||||||
26
srv/format.c
26
srv/format.c
@ -57,15 +57,8 @@ uint32_t format_vfctprintf(FormatCallback callback, void* arg,
|
|||||||
return render_format(callback, arg, format, va);
|
return render_format(callback, arg, format, va);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//--local functions-------------------------------------------------------------
|
//--local functions-------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
|
||||||
* FormatCallback to write into a regular buffer. A pointer to BufferArg shall
|
|
||||||
* be passed as arg.
|
|
||||||
*
|
|
||||||
* Returns 0 if everything went as expected, 1 otherwise
|
|
||||||
*/
|
|
||||||
static uint32_t buffer_write(uint8_t byte, void* arg)
|
static uint32_t buffer_write(uint8_t byte, void* arg)
|
||||||
{
|
{
|
||||||
struct BufferArg* buffer_arg = (struct BufferArg*)arg;
|
struct BufferArg* buffer_arg = (struct BufferArg*)arg;
|
||||||
@ -78,12 +71,6 @@ static uint32_t buffer_write(uint8_t byte, void* arg)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Renders the given format to the output defined by the provided callback,
|
|
||||||
* formatting accordingly the provided arguments
|
|
||||||
*
|
|
||||||
* Returns 0 if everything went as expected, 1 otherwise
|
|
||||||
*/
|
|
||||||
static uint32_t render_format(FormatCallback callback, void* arg,
|
static uint32_t render_format(FormatCallback callback, void* arg,
|
||||||
const char* restrict format, va_list va)
|
const char* restrict format, va_list va)
|
||||||
{
|
{
|
||||||
@ -170,12 +157,6 @@ static uint32_t render_format(FormatCallback callback, void* arg,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Formats a signed integer and renders it to the output defined by the provided
|
|
||||||
* callback
|
|
||||||
*
|
|
||||||
* Returns 0 if everything went as expected, 1 otherwise
|
|
||||||
*/
|
|
||||||
static uint32_t render_signed(FormatCallback callback, void* arg,
|
static uint32_t render_signed(FormatCallback callback, void* arg,
|
||||||
int32_t number, uint8_t base, uint8_t width)
|
int32_t number, uint8_t base, uint8_t width)
|
||||||
{
|
{
|
||||||
@ -214,12 +195,6 @@ static uint32_t render_signed(FormatCallback callback, void* arg,
|
|||||||
return render_unsigned(callback, arg, (uint32_t)number, base, 0, false);
|
return render_unsigned(callback, arg, (uint32_t)number, base, 0, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Formats an unsigned integer and renders it to the output defined by the
|
|
||||||
* provided callback
|
|
||||||
*
|
|
||||||
* Returns 0 if everything went as expected, 1 otherwise
|
|
||||||
*/
|
|
||||||
static uint32_t render_unsigned(FormatCallback callback, void* arg,
|
static uint32_t render_unsigned(FormatCallback callback, void* arg,
|
||||||
uint32_t number, uint8_t base, uint8_t width, bool zero_padding)
|
uint32_t number, uint8_t base, uint8_t width, bool zero_padding)
|
||||||
{
|
{
|
||||||
@ -262,4 +237,3 @@ static uint32_t render_unsigned(FormatCallback callback, void* arg,
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
24
srv/format.h
24
srv/format.h
@ -20,36 +20,12 @@ typedef uint32_t (*FormatCallback)(uint8_t byte, void* arg);
|
|||||||
|
|
||||||
//--functions-------------------------------------------------------------------
|
//--functions-------------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
|
||||||
* Custom implementation of snprintf. Print the given format into the given
|
|
||||||
* buffer with the attached arguments properly formated.
|
|
||||||
*
|
|
||||||
* This function only provided a minimal subset of the standard library's
|
|
||||||
* snprintf : %c, %s, %i, %d, %x as well as right-justified padding for %d and
|
|
||||||
* %x
|
|
||||||
*
|
|
||||||
* Returns 0 if everything went as expected, 1 otherwise
|
|
||||||
*/
|
|
||||||
uint32_t format_snprintf(char* restrict buffer, uint32_t buffer_size,
|
uint32_t format_snprintf(char* restrict buffer, uint32_t buffer_size,
|
||||||
const char* restrict format, ...);
|
const char* restrict format, ...);
|
||||||
|
|
||||||
/**
|
|
||||||
* Custom implementation of fprintf using a callback instead of a file pointer.
|
|
||||||
* Print the given format using the given callback with the attached arguments
|
|
||||||
* properly formated.
|
|
||||||
*
|
|
||||||
* This function only provided a minimal subset of the standard library's
|
|
||||||
* snprintf : %c, %s, %i, %d, %x as well as right-justified padding for %d and
|
|
||||||
* %x
|
|
||||||
*
|
|
||||||
* Returns 0 if everything went as expected, 1 otherwise
|
|
||||||
*/
|
|
||||||
uint32_t format_fctprintf(FormatCallback callback, void* arg,
|
uint32_t format_fctprintf(FormatCallback callback, void* arg,
|
||||||
const char* restrict format, ...);
|
const char* restrict format, ...);
|
||||||
|
|
||||||
/**
|
|
||||||
* Variadic variation of format_fctprintf(), see the later for more information
|
|
||||||
*/
|
|
||||||
uint32_t format_vfctprintf(FormatCallback callback, void* arg,
|
uint32_t format_vfctprintf(FormatCallback callback, void* arg,
|
||||||
const char* restrict format, va_list va);
|
const char* restrict format, va_list va);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user