From 60f80e3c34fe14e6a21b7ba7a6e10fe09dfc8d34 Mon Sep 17 00:00:00 2001 From: cfif Date: Tue, 9 Dec 2025 13:08:54 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Inc/LoggerToSerialPort.h | 24 ++++++++++++++--- Src/LoggerToSerialPort.c | 57 +++++++++++++++++++++++++++++++--------- 2 files changed, 66 insertions(+), 15 deletions(-) diff --git a/Inc/LoggerToSerialPort.h b/Inc/LoggerToSerialPort.h index 3be2007..d082e10 100644 --- a/Inc/LoggerToSerialPort.h +++ b/Inc/LoggerToSerialPort.h @@ -8,16 +8,29 @@ #include "SerialPort.h" #include "LoggerInterface.h" #include "RtcIO.h" +#include + typedef struct { - tSerialPortIO *serialPortIo; + tSerialPortIO *serialPortIo_IN_VIRT; + tSerialPortIO *serialPortIo_OUT_VIRT; + tSerialPortIO *serialPortIo_PHYSIC; tRtcIO *rtc; uint32_t timeout; + uint32_t timeoutTransmittedLog; uint8_t authorLimit; bool open; tLoggerInterface logger; uint16_t flags; int32_t greenwichOffset; + + struct { + osThreadId_t id; + uint32_t stack[512]; + StaticTask_t controlBlock; + osThreadAttr_t attr; + } thread; + } tLoggerToSerialPort; #define SERIAL_LOGGER_SHOW_AUTHOR 0b1 << 0 @@ -28,13 +41,18 @@ typedef struct { void LoggerToSerialPort_Init( tLoggerToSerialPort *env, int32_t greenwichOffset, - tSerialPortIO *serialPortIo, + tSerialPortIO *serialPortIo_IN_VIRT, + tSerialPortIO *serialPortIo_OUT_VIRT, + tSerialPortIO *serialPortIo_PHYSIC, tRtcIO *rtc, - uint16_t flags + uint16_t flags, + uint32_t timeoutTransmittedLog // bool showDate, // bool showTime, // bool showLoglevel, // bool showAuthor ); +void LogTransmitter_StartThread(tLoggerToSerialPort *env); + #endif //UVEOS_ON_NATION_LOGGERTOSERIALPORT_H diff --git a/Src/LoggerToSerialPort.c b/Src/LoggerToSerialPort.c index bd915ff..d6e3d73 100644 --- a/Src/LoggerToSerialPort.c +++ b/Src/LoggerToSerialPort.c @@ -7,6 +7,7 @@ #include "AsciiStringAssmeblingUtils.h" #include "Rtc.h" #include +#include "CmsisRtosThreadUtils.h" #include CMSIS_device_header @@ -18,7 +19,7 @@ static void LoggerToSerialPort_TimeToString(time_t timestamp, char *strbuf) { static void LoggerToSerialPort_PrintLegend( tLoggerToSerialPort *env, - const char *authorStatic, + char *authorStatic, const uint8_t authorLen, eLoggerLevel loglevel ) { @@ -70,14 +71,14 @@ static void LoggerToSerialPort_PrintLegend( if (env->flags) vAsciiStringAdd(str, &strLen, ": ", 2); - SerialPortTransmit(env->serialPortIo, (uint8_t *) str, strLen, env->timeout); + SerialPortTransmit(env->serialPortIo_IN_VIRT, (uint8_t *) str, strLen, env->timeout); env->open = true; } static void LoggerToSerialPort_Logging( tLoggerToSerialPort *env, - const char *authorStatic, + char *authorStatic, const uint8_t authorLen, eLoggerLevel loglevel, char *msg, @@ -85,9 +86,9 @@ static void LoggerToSerialPort_Logging( bool complete ) { - uint32_t adr = *(uint32_t *)(env->serialPortIo->env); +// uint32_t adr = *(uint32_t *)(env->serialPortIo->env); - uint32_t timeoutLocal = env->timeout; +// uint32_t timeoutLocal = env->timeout; // Если это UART (виртуальный) // if (adr < PERIPH_BASE) { // env->timeout = 0; @@ -98,37 +99,69 @@ static void LoggerToSerialPort_Logging( } //выводим сообщение - SerialPortTransmit(env->serialPortIo, (uint8_t *) msg, msgLen, env->timeout); + SerialPortTransmit(env->serialPortIo_IN_VIRT, (uint8_t *) msg, msgLen, env->timeout); if (complete) { //переводим строку - SerialPortTransmit(env->serialPortIo, (uint8_t *) "\r\n", 2, env->timeout); + SerialPortTransmit(env->serialPortIo_IN_VIRT, (uint8_t *) "\r\n", 2, env->timeout); env->open = false; } else { env->open = true; } - env->timeout = timeoutLocal; +// env->timeout = timeoutLocal; } void LoggerToSerialPort_Init( tLoggerToSerialPort *env, int32_t greenwichOffset, - tSerialPortIO *serialPortIo, + tSerialPortIO *serialPortIo_IN_VIRT, + tSerialPortIO *serialPortIo_OUT_VIRT, + tSerialPortIO *serialPortIo_PHYSIC, tRtcIO *rtc, - uint16_t flags + uint16_t flags, + uint32_t timeoutTransmittedLog ) { - env->serialPortIo = serialPortIo; + env->serialPortIo_IN_VIRT = serialPortIo_IN_VIRT; + env->serialPortIo_OUT_VIRT = serialPortIo_OUT_VIRT; + env->serialPortIo_PHYSIC = serialPortIo_PHYSIC; env->open = false; - env->timeout = 200;// не ждем на каждой операции так как если порт исправен то все должно отрабатывать моментально + env->timeout = 0;// не ждем на каждой операции так как если порт исправен то все должно отрабатывать моментально env->logger.env = env; env->greenwichOffset = greenwichOffset; env->logger.logging = (LoggerGenericMethod) LoggerToSerialPort_Logging; env->rtc = rtc; env->flags = flags; + env->timeoutTransmittedLog = timeoutTransmittedLog; // env->showDate = showDate; // env->showTime = showTime; // env->showLoglevel = showLoglevel; // env->showAuthor = showAuthor; + + InitThreadAtrStatic(&env->thread.attr, "LogTransmitter", env->thread.controlBlock, env->thread.stack, + osPriorityNormal); + + LogTransmitter_StartThread(env); } + +extern uint8_t buf_USART2_TRANSMITTED[512]; + +static _Noreturn void LogTransmitter_Thread(tLoggerToSerialPort *env) { + for (;;) { + uint16_t len = env->serialPortIo_OUT_VIRT->receive(env->serialPortIo_OUT_VIRT->env, buf_USART2_TRANSMITTED, + sizeof(buf_USART2_TRANSMITTED), env->timeoutTransmittedLog); + + if (len > 0) { + len = env->serialPortIo_PHYSIC->transmit(env->serialPortIo_PHYSIC->env, buf_USART2_TRANSMITTED, + len, env->timeoutTransmittedLog); + } + } +} + + +void LogTransmitter_StartThread(tLoggerToSerialPort *env) { + if (!env->thread.id) { + env->thread.id = osThreadNew((osThreadFunc_t) (LogTransmitter_Thread), (void *) (env), &env->thread.attr); + } +} \ No newline at end of file