From 77d453ed7de0a521a49ace4a9f03d36b90af057c Mon Sep 17 00:00:00 2001 From: cfif Date: Mon, 30 Mar 2026 14:25:13 +0300 Subject: [PATCH] Init --- MainModesArbiter.c | 44 +++++++++++++ MainModesArbiter.h | 72 +++++++++++++++++++++ MainModesArbiter_InitStage.c | 119 +++++++++++++++++++++++++++++++++++ MainModesArbiter_Private.h | 12 ++++ PeripheralInterfaces.c | 13 ++++ PeripheralInterfaces.h | 15 +++++ modular.json | 10 +++ 7 files changed, 285 insertions(+) create mode 100644 MainModesArbiter.c create mode 100644 MainModesArbiter.h create mode 100644 MainModesArbiter_InitStage.c create mode 100644 MainModesArbiter_Private.h create mode 100644 PeripheralInterfaces.c create mode 100644 PeripheralInterfaces.h create mode 100644 modular.json diff --git a/MainModesArbiter.c b/MainModesArbiter.c new file mode 100644 index 0000000..34acba1 --- /dev/null +++ b/MainModesArbiter.c @@ -0,0 +1,44 @@ +// +// Created by cfif on 05.05.23. +// +#include "MainModesArbiter_Private.h" + +void Mma_Init( + tMma *env, + tGpios *gpios, + tSerialPorts *serialPorts, + tCanPorts *canPorts, + tRtcs *rtcs +) { + env->gpios = gpios; + env->serialPorts = serialPorts; + env->canPorts = canPorts; + env->rtcs = rtcs; + + InitThreadAtrStatic(&env->thread.attr, "Mma", env->thread.controlBlock, env->thread.stack, osPriorityNormal); + env->thread.id = 0; +} + +static _Noreturn void Mma_Thread(tMma *env) { + + // Запуск устройства + Mma_InitStage(env); + + for (;;) { + + GpioPinSet(&env->gpios->Led.ledR1, true); + SystemDelayMs(500); + GpioPinSet(&env->gpios->Led.ledR1, false); + SystemDelayMs(500); + + } +} + + +void Mma_StartThread(tMma *env) { + if (!env->thread.id) { + env->thread.id = osThreadNew((osThreadFunc_t) (Mma_Thread), (void *) (env), &env->thread.attr); + } else { + osThreadResume(env->thread.id); + } +} \ No newline at end of file diff --git a/MainModesArbiter.h b/MainModesArbiter.h new file mode 100644 index 0000000..12cce5f --- /dev/null +++ b/MainModesArbiter.h @@ -0,0 +1,72 @@ +// +// Created by cfif on 05.05.23. +// + +#ifndef WATER_BOX_BSD_MAINMODESARBITER_H +#define WATER_BOX_BSD_MAINMODESARBITER_H + +#include "CmsisRtosThreadUtils.h" + +//Железные интерфейсы +#include "PeripheralInterfaces.h" + +//Подсистемы +#include "PowerManagement.h" +#include "Rtcs.h" +#include "CanPorts.h" +#include "LoggerToSerialPortV2.h" +#include "ComInt.h" +#include "Indication.h" +#include "CommandLines.h" +#include "ArbiterCommand.h" + +typedef struct { + // Преферийные интерфесы + tGpios *gpios; + tSerialPorts *serialPorts; + tCanPorts *canPorts; + tLoggerToSerialPortV2 slog; + tComInt comInt; + + tRtcs *rtcs; + + tPowerManagement power; + + tCommandLine cli; + + tIndication Indication; + + tTaskSerial TaskSerialUSB; + tTaskSerial TaskSerialUART; + + tTaskSerialToCanCyclic TaskSerialToCanCyclic0; + tTaskSerialToCanCyclic TaskSerialToCanCyclic1; + tTaskSerialToCanSpontany TaskSerialToCanSpontany; + + osMessageQueueId_t txDataQueue_Spontany; + osMessageQueueId_t txDataQueue_Cyclic0; + osMessageQueueId_t txDataQueue_Cyclic1; + + struct { + osThreadId_t id; + uint32_t stack[2048 * 1]; + StaticTask_t controlBlock; + osThreadAttr_t attr; + } thread; + + uint8_t data[46]; + + uint8_t BufFileWrite[512]; +} tMma; + +void Mma_Init( + tMma *env, + tGpios *gpios, + tSerialPorts *serialPorts, + tCanPorts *canPorts, + tRtcs *rtcs +); + +void Mma_StartThread(tMma *env); + +#endif //WATER_BOX_BSD_MAINMODESARBITER_H diff --git a/MainModesArbiter_InitStage.c b/MainModesArbiter_InitStage.c new file mode 100644 index 0000000..6970417 --- /dev/null +++ b/MainModesArbiter_InitStage.c @@ -0,0 +1,119 @@ +// +// Created by cfif on 05.05.23. +// + +#include "MainModesArbiter_Private.h" +#include "FirmwareMetadataSection.h" + +#define LOGGER &env->slog.logger + +const char LOG_TASK_MAIN[] = "Init"; + + +void Mma_InitComIntLog(tMma *env) { + Indication_Init(&env->Indication, HVAC_DEV_MODE_STARTUP); + LoggerToSerialPortV2_Init( + &env->slog, + 3, + &SERIAL_PORTS.cliVirtualPortOut_Io, + &SERIAL_PORTS.DEBUG_USART3_IO, + &env->rtcs->rtcI0, + SERIAL_LOGGER_SHOW_AUTHOR | SERIAL_LOGGER_SHOW_LOG_LEVEL, + 1000 + ); + env->slog.timeout = 0; + + LoggerInfoStatic(&env->slog.logger, LOG_TASK_MAIN, "Start logging") + +} + +static void Mma_InitSubSystems(tMma *env) { + + InitPeripheralInterfaces(); + + // Настройка таймера реального времени + time_t set_timestamp = 0; + RtcSet(&env->rtcs->rtcI0, &set_timestamp); + + Mma_InitComIntLog(env); + LoggerInfoStatic(&env->slog.logger, LOG_TASK_MAIN, "Subsystem initialization") + +/* + ComInt_Init( + &env->comInt, + &SERIAL_PORTS.Rs485_HalfDuplexIo, + NULL, + &SERIAL_PORTS.SerialPortUsbSnifferIO, + NULL, + &SERIAL_PORTS.cliVirtualOutIo, + &env->Indication.currentModeName + ); + + ComInt_StartThread(&env->comInt); + + CommandLine_Init(&env->cli, &env->serialPorts->cliVirtualInIo); + CommandLine_StartThread(&env->cli); + + + TaskSerialToCanCyclic0_Init(&env->TaskSerialToCanCyclic0, + &env->canPorts->Can1_IO); + + TaskSerialToCanCyclic0_StartThread(&env->TaskSerialToCanCyclic0); + + + TaskSerialToCanCyclic1_Init(&env->TaskSerialToCanCyclic1, + &env->canPorts->Can1_IO); + + TaskSerialToCanCyclic1_StartThread(&env->TaskSerialToCanCyclic1); + + + TaskSerialToCanSpontany_Init(&env->TaskSerialToCanSpontany, + &env->canPorts->Can1_IO, + &env->serialPorts->Rs232_IO, + &env->serialPorts->SerialPortUsbIO + + ); + + TaskSerialToCanSpontany_StartThread(&env->TaskSerialToCanSpontany); + + + TaskSerialUSB_Init(&env->TaskSerialUSB, + FROM_UART_USB, + &env->serialPorts->SerialPortUsbIO, + &env->TaskSerialToCanCyclic0, + &env->TaskSerialToCanCyclic1, + &env->TaskSerialToCanSpontany + ); + TaskSerialUSB_StartThread(&env->TaskSerialUSB); + + + TaskSerialUART_Init(&env->TaskSerialUART, + FROM_UART, + &env->serialPorts->Rs232_IO, + &env->TaskSerialToCanCyclic0, + &env->TaskSerialToCanCyclic1, + &env->TaskSerialToCanSpontany + ); + + TaskSerialUART_StartThread(&env->TaskSerialUART); + +*/ + LoggerInfoStatic(&env->slog.logger, LOG_TASK_MAIN, "End of subsystem initialization") + +} + + +static void Mma_RunSubThreads(tMma *env) { + Indication_SetMode(&env->Indication, HVAC_DEV_MODE_RUN); +} + +static void Mma_InitPower(tMma *env) { + +} + +void Mma_InitStage(tMma *env) { + Mma_InitSubSystems(env); + Mma_InitPower(env); + Mma_RunSubThreads(env); +} + diff --git a/MainModesArbiter_Private.h b/MainModesArbiter_Private.h new file mode 100644 index 0000000..cee9383 --- /dev/null +++ b/MainModesArbiter_Private.h @@ -0,0 +1,12 @@ +// +// Created by cfif on 05.05.23. +// + +#ifndef WATER_BOX_BSD_MAINMODESARBITER_PRIVATE_H +#define WATER_BOX_BSD_MAINMODESARBITER_PRIVATE_H + +#include "MainModesArbiter.h" + +void Mma_InitStage(tMma *env); + +#endif //WATER_BOX_BSD_MAINMODESARBITER_PRIVATE_H diff --git a/PeripheralInterfaces.c b/PeripheralInterfaces.c new file mode 100644 index 0000000..aa3de1f --- /dev/null +++ b/PeripheralInterfaces.c @@ -0,0 +1,13 @@ +// +// Created by cfif on 05.05.23. +// + +#include "PeripheralInterfaces.h" + + +void InitPeripheralInterfaces() { + Gpios_Init(); + SerialPorts_Init(&GPIOS.comIntDir); + CanPorts_Init(); + Rtcs_Init(); +} \ No newline at end of file diff --git a/PeripheralInterfaces.h b/PeripheralInterfaces.h new file mode 100644 index 0000000..d7c632e --- /dev/null +++ b/PeripheralInterfaces.h @@ -0,0 +1,15 @@ +// +// Created by cfif on 05.05.23. +// + +#ifndef WATER_BOX_BSD_PERIPHERALINTERFACES_H +#define WATER_BOX_BSD_PERIPHERALINTERFACES_H + +#include "Gpios.h" +#include "SerialPorts.h" +#include "CanPorts.h" +#include "Rtcs.h" + +void InitPeripheralInterfaces(); + +#endif //WATER_BOX_BSD_PERIPHERALINTERFACES_H diff --git a/modular.json b/modular.json new file mode 100644 index 0000000..0dd1901 --- /dev/null +++ b/modular.json @@ -0,0 +1,10 @@ +{ + "cmake": { + "inc_dirs": [ + "./" + ], + "srcs": [ + "./**.c" + ] + } +} \ No newline at end of file