Update debug service to use new dma_mbuf

This commit is contained in:
Steins7 2024-04-07 16:47:34 +02:00
parent c26b1cd703
commit 0d5deffa58
2 changed files with 64 additions and 20 deletions

View File

@ -8,20 +8,20 @@
//--includes-------------------------------------------------------------------- //--includes--------------------------------------------------------------------
#include "debug.h" #include "debug.h"
#include "dma_mbuf.h"
//--local definitions----------------------------------------------------------- //--local definitions-----------------------------------------------------------
#define BUFFER_SIZE 83 //80 char line + \n + 2 bytes for index static void print_debug(char* str);
#define BUFFER_NB 3 //1 buffer in write, one in transfer and one waiting
#define BUFFER_SIZE 162 //(80 char line + \n) * 2
//--local variables------------------------------------------------------------- //--local variables-------------------------------------------------------------
static enum UsartPeriph usart_periph; static struct DmaMultiBuffer mbuf;
static uint8_t tx_buffer1[BUFFER_SIZE]; static uint8_t tx_buffer[BUFFER_SIZE];
static uint8_t tx_buffer2[BUFFER_SIZE];
static uint8_t tx_buffer3[BUFFER_SIZE];
static uint8_t* tx_buffers[BUFFER_NB] = {tx_buffer1, tx_buffer2, tx_buffer3};
//--public functions------------------------------------------------------------ //--public functions------------------------------------------------------------
@ -31,30 +31,75 @@ static uint8_t* tx_buffers[BUFFER_NB] = {tx_buffer1, tx_buffer2, tx_buffer3};
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)
{ {
usart_periph = usart;
gpio_configure(tx_port, tx_pin, GPIO_MODE_OUTPUT_FAST, gpio_configure(tx_port, tx_pin, GPIO_MODE_OUTPUT_FAST,
GPIO_CONFIG_OUT_ALT_PUSH_PULL); GPIO_CONFIG_OUT_ALT_PUSH_PULL);
usart_configure(usart_periph, USART_CONFIG_8N1, 1152000); usart_configure(usart, USART_CONFIG_8N1, 1000000);
dma_mbuf_configure(&mbuf,usart_configure_tx_dma(usart),
usart_set_tx_buffer(USART_PERIPH_3, tx_buffers, BUFFER_SIZE, BUFFER_NB, DMA_CONFIG_PRIO_LOW, tx_buffer, BUFFER_SIZE);
DMA_CONFIG_PRIO_LOW);
debug_trace("\n"); debug_trace("\n");
debug_trace("--------------------------------------------------------------------------------\n"); debug_trace("------------------------------------------------------------------------------\n");
debug_trace("starting debug software\n"); debug_trace("starting debug software\n");
debug_trace("compiled on " __DATE__ " at " __TIME__ "\n"); debug_trace("compiled on " __DATE__ " at " __TIME__ "\n");
debug_trace("--------------------------------------------------------------------------------\n"); debug_trace("------------------------------------------------------------------------------\n");
} }
#endif
#if DEBUG_TRACE
void _debug_trace(char* format, ...) void _debug_trace(char* format, ...)
{ {
while(*format != '\0') { print_debug("T:");
while(usart_write_byte(usart_periph, *format)) {} print_debug(format);
++format;
//ensure everything is written when done
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 #endif
//--local functions------------------------------------------------------------- //--local functions-------------------------------------------------------------
#if DEBUG_TRACE || DEBUG_WARN || DEBUG_ERROR
static void print_debug(char* str)
{
while (*str != '\0') {
if (dma_mbuf_write_byte(&mbuf, *str))
{
//buffer is full, wait until transfer started
while (dma_mbuf_switch(&mbuf)) {}
}
++str;
}
}
#endif

View File

@ -13,12 +13,11 @@
#include "../drv/usart.h" #include "../drv/usart.h"
#include "../drv/gpio.h" #include "../drv/gpio.h"
#include "stdint.h"
#define DEBUG_TRACE 1 #define DEBUG_TRACE 1
#define DEBUG_WARN 0 #define DEBUG_WARN 0
#define DEBUG_ERROR 0 #define DEBUG_ERROR 0
//--type definitions------------------------------------------------------------ //--type definitions------------------------------------------------------------
#if DEBUG_TRACE || DEBUG_WARN || DEBUG_ERROR #if DEBUG_TRACE || DEBUG_WARN || DEBUG_ERROR