控制台改单写者发送:defaultTask唯一发串口其余任务写环形缓冲,杜绝日志交错与脏指针入UART;溢出钩子加指针窗口校验、崩溃上报改显式长度

This commit is contained in:
2026-09-24 23:47:23 +08:00
parent c075cfa076
commit 3763e699dc
8 changed files with 346 additions and 34 deletions
+10 -1
View File
@@ -3,10 +3,12 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include "dbg_log.h"
void lftpd_log_internal(const char* level, const char* format, ...) {
static char buffer[256]; /* static: called at depth in ftpTask, keep off-stack */
static char line[288]; /* static: 组装含前缀的整行,交给控制台单写者 */
va_list args;
va_start(args, format);
int err = vsnprintf(buffer, sizeof(buffer), format, args);
@@ -14,5 +16,12 @@ void lftpd_log_internal(const char* level, const char* format, ...) {
if (err >= sizeof(buffer)) {
return;
}
printf("%s %s\n", level, buffer);
/* 走控制台单写者(Src/usart.c):整行一次入缓冲,避免逐字符 fputc 交错 */
int n = snprintf(line, sizeof(line), "%s %s\r\n", level, buffer);
if (n > 0) {
if (n > (int)sizeof(line) - 1) {
n = (int)sizeof(line) - 1;
}
(void)dbg_console_write_line(line, (unsigned)n);
}
}