First implementation of debug service

For now, only basic traces are implemented. The rest will follow once a printf
function is implemented
This commit is contained in:
Steins7 2023-09-24 22:02:20 +02:00
parent cc54ca7ca8
commit b992e2b8fb
2 changed files with 119 additions and 0 deletions

60
srv/debug.c Normal file
View File

@ -0,0 +1,60 @@
/** @file debug.c
* Module handling various debug functions
*
* The module provides a range of functions and tools to make debug more
* convenient
*/
//--includes--------------------------------------------------------------------
#include "debug.h"
//--local definitions-----------------------------------------------------------
#define BUFFER_SIZE 83 //80 char line + \n + 2 bytes for index
#define BUFFER_NB 3 //1 buffer in write, one in transfer and one waiting
//--local variables-------------------------------------------------------------
static enum UsartPeriph usart_periph;
static uint8_t tx_buffer1[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------------------------------------------------------------
#if DEBUG_TRACE || DEBUG_WARN || DEBUG_ERROR
void _debug_init(enum UsartPeriph usart, enum GpioPort tx_port,
enum GpioPin tx_pin)
{
usart_periph = usart;
gpio_configure(tx_port, tx_pin, GPIO_MODE_OUTPUT_FAST,
GPIO_CONFIG_OUT_ALT_PUSH_PULL);
usart_configure(usart_periph, USART_CONFIG_8N1, 1152000);
usart_set_tx_buffer(USART_PERIPH_3, tx_buffers, BUFFER_SIZE, BUFFER_NB,
DMA_CONFIG_PRIO_LOW);
debug_trace("\n");
debug_trace("--------------------------------------------------------------------------------\n");
debug_trace("starting debug software\n");
debug_trace("compiled on " __DATE__ " at " __TIME__ "\n");
debug_trace("--------------------------------------------------------------------------------\n");
}
void _debug_trace(char* format, ...)
{
while(*format != '\0') {
while(usart_write_byte(usart_periph, *format)) {}
++format;
}
}
#endif
//--local functions-------------------------------------------------------------

59
srv/debug.h Normal file
View File

@ -0,0 +1,59 @@
/** @file debug.h
* Module handling various debug functions
*
* The module provides a range of functions and tools to make debug more
* convenient
*/
#ifndef _DEBUG_H_
#define _DEBUG_H_
//--includes--------------------------------------------------------------------
#include "../drv/usart.h"
#include "../drv/gpio.h"
#include "stdint.h"
#define DEBUG_TRACE 1
#define DEBUG_WARN 0
#define DEBUG_ERROR 0
//--type definitions------------------------------------------------------------
#if DEBUG_TRACE || DEBUG_WARN || DEBUG_ERROR
#define debug_init(usart, tx_port, tx_pin) _debug_init(usart, tx_port, tx_pin)
#else
#define debug_init(usart) do {} while (0)
#endif
#if DEBUG_TRACE
#define debug_trace(format, ...) _debug_trace(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__)
#else
#define debug_warn(format, ...) do {} while (0)
#endif
#if DEBUG_ERROR
#define debug_error(format, ...) _debug_error(format __VA_OPT__(,) __VA_ARGS__)
#else
#define debug_error(format, ...) do {} while (0)
#endif
//--functions-------------------------------------------------------------------
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, ...);
#endif //_DEBUG_H_