/** @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" #include "dma_mbuf.h" //--local definitions----------------------------------------------------------- static void print_debug(char* str); #define BUFFER_SIZE 162 //(80 char line + \n) * 2 //--local variables------------------------------------------------------------- static struct DmaMultiBuffer mbuf; static uint8_t tx_buffer[BUFFER_SIZE]; //--public functions------------------------------------------------------------ #if DEBUG_TRACE || DEBUG_WARN || DEBUG_ERROR void _debug_init(enum UsartPeriph usart, enum GpioPort tx_port, enum GpioPin tx_pin) { gpio_configure(tx_port, tx_pin, GPIO_MODE_OUTPUT_FAST, GPIO_CONFIG_OUT_ALT_PUSH_PULL); usart_configure(usart, USART_CONFIG_8N1, 1000000); dma_mbuf_configure(&mbuf,usart_configure_tx_dma(usart), DMA_CONFIG_PRIO_LOW, tx_buffer, BUFFER_SIZE); debug_trace("\n"); debug_trace("------------------------------------------------------------------------------\n"); debug_trace("starting debug software\n"); debug_trace("compiled on " __DATE__ " at " __TIME__ "\n"); debug_trace("------------------------------------------------------------------------------\n"); } #endif #if DEBUG_TRACE void _debug_trace(char* format, ...) { print_debug("T:"); print_debug(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 //--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