添加 ram_print_in_ram 函数
This commit is contained in:
@@ -23,6 +23,8 @@ int ram_printf_init(void);
|
||||
|
||||
int32_t ram_printf(const char* fmt, ...);
|
||||
|
||||
int32_t ram_print_in_ram(const char* fmt, ...);
|
||||
|
||||
void ram_print_config(bool_t enable);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@@ -28,6 +28,33 @@ static str_format_context *p_log_ctxt;
|
||||
|
||||
extern struct uart_ctrl uart_e_ctrl;
|
||||
|
||||
#define BUFF_SIZE 2048
|
||||
typedef struct {
|
||||
int len;
|
||||
char buff[BUFF_SIZE];
|
||||
} buff_t;
|
||||
|
||||
static buff_t g_buff;
|
||||
|
||||
|
||||
static void ram_tx_fifo_flush(void)
|
||||
{
|
||||
while (uart_e_ctrl.tx_fifo_cnt(RAM_DL_UART)) __asm volatile("nop\n");
|
||||
}
|
||||
|
||||
static void puts_data() {
|
||||
int i = 0;
|
||||
int len = g_buff.len;
|
||||
char* data = g_buff.buff;
|
||||
while (i < len) {
|
||||
uart_e_ctrl.putc(RAM_DL_UART, *(data+i));
|
||||
i++;
|
||||
}
|
||||
ram_tx_fifo_flush();
|
||||
g_buff.len = 0;
|
||||
}
|
||||
|
||||
|
||||
int32_t ram_printf(const char* fmt, ...)
|
||||
{
|
||||
int res;
|
||||
@@ -39,13 +66,22 @@ int32_t ram_printf(const char *fmt, ...)
|
||||
va_start(ap, fmt);
|
||||
res = format_str_v_fn(p_log_ctxt, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
puts_data();
|
||||
return res;
|
||||
}
|
||||
|
||||
static void ram_tx_fifo_flush(void)
|
||||
int32_t ram_print_in_ram(const char* fmt, ...)
|
||||
{
|
||||
while (uart_e_ctrl.tx_fifo_cnt(RAM_DL_UART)) __asm volatile("nop\n");
|
||||
int res;
|
||||
va_list ap;
|
||||
|
||||
if (!g_is_print_enable)
|
||||
return 0;
|
||||
|
||||
va_start(ap, fmt);
|
||||
res = format_str_v_fn(p_log_ctxt, fmt, ap);
|
||||
va_end(ap);
|
||||
return res;
|
||||
}
|
||||
|
||||
StrFormatResult ram_uart_printf(void *user_data, const char *data, unsigned int len)
|
||||
@@ -54,11 +90,14 @@ StrFormatResult ram_uart_printf(void *user_data, const char *data, unsigned int
|
||||
int i = 0;
|
||||
|
||||
while (i < len) {
|
||||
uart_e_ctrl.putc(RAM_DL_UART, *(data+i));
|
||||
g_buff.buff[g_buff.len] = data[i];
|
||||
g_buff.len++;
|
||||
i++;
|
||||
if (g_buff.len >= BUFF_SIZE - 1) {
|
||||
break;
|
||||
}
|
||||
ram_tx_fifo_flush();
|
||||
|
||||
}
|
||||
g_buff.buff[g_buff.len] = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user