// ***************** debug_printf.c ************************************ // Risc-Dsp runtime library // // This file implements printf function with output to selected port // // (c) multicore.ru // // ********************************************************************* #include "debug_printf.h" #include "uart.h" #include #include #define VT0_OUT *(volatile int *)(0xb8400000) static unsigned int out_mode = 0; static unsigned int print_count = 0; // // Function: set_out_mode // set output mode // // Parameters: mode - OUT_DISABLE,OUT_FROM_UART or OUT_FROM_VT void set_out_mode(unsigned mode) { out_mode = mode; } // // Function: vt_puts // out from vitrual terminal // // Parameters: const char* str - string // int vt_puts(const char *str) { do { VT0_OUT = *str; } while (*str++); return 0; } // // Function: debug_puts // put string selected port // // Parameters: const char* str - string // int debug_puts(const char *str) { int ret; if (out_mode == OUT_FROM_UART) { ret = uart_puts(0, str); } else if (out_mode == OUT_FROM_VT) { ret = vt_puts(str); } else { // none ret = 0; } return ret; } // // Function: debug_printf // print string to selected port, analog of c-library printf function // // Parameters: const char* format - string to be printed // int debug_printf(const char *format, ...) { char buffer[1024]; // print statistic: sprintf(buffer, "[%08u] : ", print_count); print_count = print_count + 1; debug_puts(buffer); // print string va_list args; va_start(args, format); vsprintf(buffer, format, args); return debug_puts(buffer); } // // Function: uart_printf // print string to selected port, analog of c-library printf function // // Parameters: unsigned int num - number of UART port // const char* format - string to be printed // int uart_printf(unsigned int num, const char *format, ...) { char buffer[1024]; // print string va_list args; va_start(args, format); vsprintf(buffer, format, args); return uart_puts(num, buffer); }