Обновление

This commit is contained in:
cfif 2025-12-09 13:08:54 +03:00
parent 62b73298e3
commit 60f80e3c34
2 changed files with 66 additions and 15 deletions

View File

@ -8,16 +8,29 @@
#include "SerialPort.h" #include "SerialPort.h"
#include "LoggerInterface.h" #include "LoggerInterface.h"
#include "RtcIO.h" #include "RtcIO.h"
#include <cmsis_os.h>
typedef struct { typedef struct {
tSerialPortIO *serialPortIo; tSerialPortIO *serialPortIo_IN_VIRT;
tSerialPortIO *serialPortIo_OUT_VIRT;
tSerialPortIO *serialPortIo_PHYSIC;
tRtcIO *rtc; tRtcIO *rtc;
uint32_t timeout; uint32_t timeout;
uint32_t timeoutTransmittedLog;
uint8_t authorLimit; uint8_t authorLimit;
bool open; bool open;
tLoggerInterface logger; tLoggerInterface logger;
uint16_t flags; uint16_t flags;
int32_t greenwichOffset; int32_t greenwichOffset;
struct {
osThreadId_t id;
uint32_t stack[512];
StaticTask_t controlBlock;
osThreadAttr_t attr;
} thread;
} tLoggerToSerialPort; } tLoggerToSerialPort;
#define SERIAL_LOGGER_SHOW_AUTHOR 0b1 << 0 #define SERIAL_LOGGER_SHOW_AUTHOR 0b1 << 0
@ -28,13 +41,18 @@ typedef struct {
void LoggerToSerialPort_Init( void LoggerToSerialPort_Init(
tLoggerToSerialPort *env, tLoggerToSerialPort *env,
int32_t greenwichOffset, int32_t greenwichOffset,
tSerialPortIO *serialPortIo, tSerialPortIO *serialPortIo_IN_VIRT,
tSerialPortIO *serialPortIo_OUT_VIRT,
tSerialPortIO *serialPortIo_PHYSIC,
tRtcIO *rtc, tRtcIO *rtc,
uint16_t flags uint16_t flags,
uint32_t timeoutTransmittedLog
// bool showDate, // bool showDate,
// bool showTime, // bool showTime,
// bool showLoglevel, // bool showLoglevel,
// bool showAuthor // bool showAuthor
); );
void LogTransmitter_StartThread(tLoggerToSerialPort *env);
#endif //UVEOS_ON_NATION_LOGGERTOSERIALPORT_H #endif //UVEOS_ON_NATION_LOGGERTOSERIALPORT_H

View File

@ -7,6 +7,7 @@
#include "AsciiStringAssmeblingUtils.h" #include "AsciiStringAssmeblingUtils.h"
#include "Rtc.h" #include "Rtc.h"
#include <time.h> #include <time.h>
#include "CmsisRtosThreadUtils.h"
#include CMSIS_device_header #include CMSIS_device_header
@ -18,7 +19,7 @@ static void LoggerToSerialPort_TimeToString(time_t timestamp, char *strbuf) {
static void LoggerToSerialPort_PrintLegend( static void LoggerToSerialPort_PrintLegend(
tLoggerToSerialPort *env, tLoggerToSerialPort *env,
const char *authorStatic, char *authorStatic,
const uint8_t authorLen, const uint8_t authorLen,
eLoggerLevel loglevel eLoggerLevel loglevel
) { ) {
@ -70,14 +71,14 @@ static void LoggerToSerialPort_PrintLegend(
if (env->flags) if (env->flags)
vAsciiStringAdd(str, &strLen, ": ", 2); 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; env->open = true;
} }
static void LoggerToSerialPort_Logging( static void LoggerToSerialPort_Logging(
tLoggerToSerialPort *env, tLoggerToSerialPort *env,
const char *authorStatic, char *authorStatic,
const uint8_t authorLen, const uint8_t authorLen,
eLoggerLevel loglevel, eLoggerLevel loglevel,
char *msg, char *msg,
@ -85,9 +86,9 @@ static void LoggerToSerialPort_Logging(
bool complete 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 (виртуальный) // Если это UART (виртуальный)
// if (adr < PERIPH_BASE) { // if (adr < PERIPH_BASE) {
// env->timeout = 0; // 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) { 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; env->open = false;
} else { } else {
env->open = true; env->open = true;
} }
env->timeout = timeoutLocal; // env->timeout = timeoutLocal;
} }
void LoggerToSerialPort_Init( void LoggerToSerialPort_Init(
tLoggerToSerialPort *env, tLoggerToSerialPort *env,
int32_t greenwichOffset, int32_t greenwichOffset,
tSerialPortIO *serialPortIo, tSerialPortIO *serialPortIo_IN_VIRT,
tSerialPortIO *serialPortIo_OUT_VIRT,
tSerialPortIO *serialPortIo_PHYSIC,
tRtcIO *rtc, 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->open = false;
env->timeout = 200;// не ждем на каждой операции так как если порт исправен то все должно отрабатывать моментально env->timeout = 0;// не ждем на каждой операции так как если порт исправен то все должно отрабатывать моментально
env->logger.env = env; env->logger.env = env;
env->greenwichOffset = greenwichOffset; env->greenwichOffset = greenwichOffset;
env->logger.logging = (LoggerGenericMethod) LoggerToSerialPort_Logging; env->logger.logging = (LoggerGenericMethod) LoggerToSerialPort_Logging;
env->rtc = rtc; env->rtc = rtc;
env->flags = flags; env->flags = flags;
env->timeoutTransmittedLog = timeoutTransmittedLog;
// env->showDate = showDate; // env->showDate = showDate;
// env->showTime = showTime; // env->showTime = showTime;
// env->showLoglevel = showLoglevel; // env->showLoglevel = showLoglevel;
// env->showAuthor = showAuthor; // 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);
}
}