添加 ram_print_in_ram 函数

This commit is contained in:
2025-02-17 10:30:42 +08:00
parent ee725e07f1
commit fb1f54c530
2 changed files with 49 additions and 8 deletions

View File

@@ -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);

View File

@@ -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;
}