mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-12-10 13:45:10 -05:00
Simplify uart_printf() a bit by using vuprintf(), that also makes removing a static buffer possible.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23504 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
1ddb91ad36
commit
1566705984
1 changed files with 15 additions and 19 deletions
|
|
@ -23,6 +23,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
#include <sprintf.h>
|
||||||
#include "inttypes.h"
|
#include "inttypes.h"
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
#include "cpu.h"
|
#include "cpu.h"
|
||||||
|
|
@ -58,25 +59,23 @@ void tx_writec(unsigned char c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int uart_push(void *user_data, unsigned char ch)
|
||||||
|
{
|
||||||
|
(void)user_data;
|
||||||
|
|
||||||
|
uart_send_byte(DEBUG_UART_PORT, ch);
|
||||||
|
if (ch == '\n')
|
||||||
|
uart_send_byte(DEBUG_UART_PORT, '\r');
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* General purpose debug function
|
* General purpose debug function
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
void uart_printf (const char *format, ...)
|
void uart_printf (const char *format, ...)
|
||||||
{
|
{
|
||||||
static bool debug_uart_init = false;
|
static bool debug_uart_init = false;
|
||||||
static char tx_buf [MAX_PRINTF_BUF];
|
|
||||||
|
|
||||||
int len;
|
|
||||||
unsigned char *ptr;
|
|
||||||
int j;
|
|
||||||
|
|
||||||
va_list ap;
|
va_list ap;
|
||||||
va_start(ap, format);
|
|
||||||
|
|
||||||
ptr = tx_buf;
|
|
||||||
len = vsnprintf(ptr, sizeof(tx_buf), format, ap);
|
|
||||||
va_end(ap);
|
|
||||||
|
|
||||||
if (!debug_uart_init)
|
if (!debug_uart_init)
|
||||||
{
|
{
|
||||||
|
|
@ -84,12 +83,9 @@ void uart_printf (const char *format, ...)
|
||||||
debug_uart_init = true;
|
debug_uart_init = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (j=0; j<len; j++)
|
va_start(ap, format);
|
||||||
{
|
vuprintf(uart_push, NULL, format, ap);
|
||||||
uart_send_byte (DEBUG_UART_PORT, tx_buf[j]);
|
va_end(ap);
|
||||||
if ( tx_buf[j] == '\n')
|
|
||||||
uart_send_byte (DEBUG_UART_PORT, '\r');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue