commit 1c1829fbbaa3f53c241b2b903f636a617d1f82e9 Author: cfif Date: Tue Sep 23 17:12:43 2025 +0300 Начало diff --git a/MainModesArbiter.c b/MainModesArbiter.c new file mode 100644 index 0000000..c6d8080 --- /dev/null +++ b/MainModesArbiter.c @@ -0,0 +1,42 @@ +// +// Created by cfif on 05.05.23. +// +#include "MainModesArbiter_Private.h" + +void Mma_Init( + tMma *env, + tGpios *gpios, + tSerialPorts *serialPorts, + tRtcs *rtcs +) { + env->gpios = gpios; + env->serialPorts = serialPorts; + 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.ledR, true); + SystemDelayMs(500); + GpioPinSet(&env->gpios->Led.ledR, 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..add0abc --- /dev/null +++ b/MainModesArbiter.h @@ -0,0 +1,57 @@ +// +// 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 "LoggerToSerialPort.h" +#include "ComInt.h" +#include "Indication.h" +#include "CommandLines.h" + +typedef struct { + // Преферийные интерфесы + tGpios *gpios; + tSerialPorts *serialPorts; + tLoggerToSerialPort slog; + tComInt comInt; + + tRtcs *rtcs; + + tPowerManagement power; + + tCommandLine cli; + + tIndication Indication; + + 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, + 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..fc3a013 --- /dev/null +++ b/MainModesArbiter_InitStage.c @@ -0,0 +1,72 @@ +// +// Created by cfif on 05.05.23. +// + +#include "MainModesArbiter_Private.h" +#include "FirmwareMetadataSection.h" + +#define LOGGER &env->slog.logger + +const char LOG_TASK_MAIN[] = "Initialization task"; + + +void Mma_InitComIntLog(tMma *env) { + Indication_Init(&env->Indication, HVAC_DEV_MODE_STARTUP); + LoggerToSerialPort_Init( + &env->slog, + 0, + &SERIAL_PORTS.cliVirtualInIo, + NULL, + SERIAL_LOGGER_SHOW_AUTHOR | SERIAL_LOGGER_SHOW_LOG_LEVEL + ); + env->slog.timeout = 0; + + LoggerInfoStatic(&env->slog.logger, LOG_TASK_MAIN, "Начало логирования") + +} + +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, "Инициализация подсистем") + + ComInt_Init( + &env->comInt, + &SERIAL_PORTS.Rs485_HalfDuplexIo, + NULL, + &SERIAL_PORTS.SerialPortUsbIO, + NULL, + &SERIAL_PORTS.cliVirtualOutIo, + &env->Indication.currentModeName + ); + + ComInt_StartThread(&env->comInt); + + CommandLine_Init(&env->cli, &env->serialPorts->cliVirtualInIo); + CommandLine_StartThread(&env->cli); + + LoggerInfoStatic(&env->slog.logger, LOG_TASK_MAIN, "Конец инициализации подсистем") + +} + + +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..971aa1f --- /dev/null +++ b/PeripheralInterfaces.c @@ -0,0 +1,12 @@ +// +// Created by cfif on 05.05.23. +// + +#include "PeripheralInterfaces.h" + + +void InitPeripheralInterfaces() { + Gpios_Init(); + SerialPorts_Init(&GPIOS.comIntDir); + Rtcs_Init(); +} \ No newline at end of file diff --git a/PeripheralInterfaces.h b/PeripheralInterfaces.h new file mode 100644 index 0000000..304e50d --- /dev/null +++ b/PeripheralInterfaces.h @@ -0,0 +1,14 @@ +// +// 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 "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