From fb1f54c53035f50160ab6d288b88ea44c6a05d8c Mon Sep 17 00:00:00 2001 From: andy <1414772332@qq.com> Date: Mon, 17 Feb 2025 10:30:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20ram=5Fprint=5Fin=5Fram=20?= =?UTF-8?q?=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mfgtool/ram/inc/ram_printf.h | 4 ++- mfgtool/ram/src/ram_printf.c | 53 +++++++++++++++++++++++++++++++----- 2 files changed, 49 insertions(+), 8 deletions(-) diff --git a/mfgtool/ram/inc/ram_printf.h b/mfgtool/ram/inc/ram_printf.h index 1c5d195..15d06e4 100644 --- a/mfgtool/ram/inc/ram_printf.h +++ b/mfgtool/ram/inc/ram_printf.h @@ -21,7 +21,9 @@ extern "C" { int ram_printf_init(void); -int32_t ram_printf(const char *fmt, ...); +int32_t ram_printf(const char* fmt, ...); + +int32_t ram_print_in_ram(const char* fmt, ...); void ram_print_config(bool_t enable); diff --git a/mfgtool/ram/src/ram_printf.c b/mfgtool/ram/src/ram_printf.c index c1fda22..5f4084b 100644 --- a/mfgtool/ram/src/ram_printf.c +++ b/mfgtool/ram/src/ram_printf.c @@ -28,7 +28,34 @@ static str_format_context *p_log_ctxt; extern struct uart_ctrl uart_e_ctrl; -int32_t ram_printf(const char *fmt, ...) +#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; va_list ap; @@ -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; }