commit 2415f2ceb7eee3576414209790890f3c878960af Author: cfif Date: Mon Jun 2 13:26:39 2025 +0300 Init diff --git a/CrashDetection.c b/CrashDetection.c new file mode 100644 index 0000000..0bfca77 --- /dev/null +++ b/CrashDetection.c @@ -0,0 +1,57 @@ +// +// Created by ilya on 05.04.24. +// +#include "CrashDetection.h" +#include "CmsisRtosThreadUtils.h" +#include "SystemDelayInterface.h" + +#define LOG_SIGN "Опр.Авар." +#define LOGGER env->logger + +void CrashDetection_Init( + tCrashDetection *env, + tAccelDataFlowInterface *accelData, + float *asi15threshold, + tCarFlipDetectionSettings *settings, + tLoggerInterface *logger +) { + env->logger = logger; + + CarCrashDetection_Init(&env->carCrashDetection, accelData, asi15threshold, settings); + env->emergencyEvents = CarCrashDetection_GetInterface(&env->carCrashDetection); + env->simulationInterface = CarCrashDetection_GetSimInterface(&env->carCrashDetection); + + InitThreadAtrStatic( + &env->thread.attr, + "CrashDetection", + env->thread.controlBlock, + env->thread.stack, + osPriorityNormal + ); + + env->thread.id = 0; +} + + +static _Noreturn void CrashDetection_Thread(tCrashDetection *env) { + for (;;) { + CarCrashDetection_Processing(&env->carCrashDetection, SystemWaitForever); + } +} + +void CrashDetection_StopThread(tCrashDetection *env) { + if(env->thread.id != NULL) { + if (osThreadTerminate(env->thread.id) == osOK) { + SystemDelayMs(100); + env->thread.id = NULL; + LoggerInfoStatic(LOGGER, LOG_SIGN, "Поток обработки данных акселерометра остановлен") + SystemDelayMs(500); + } + } +} + +void CrashDetection_StartThread(tCrashDetection *env) { + if (env->thread.id == NULL) { + env->thread.id = osThreadNew((osThreadFunc_t) (CrashDetection_Thread), (void *) (env), &env->thread.attr); + } +} \ No newline at end of file diff --git a/CrashDetection.h b/CrashDetection.h new file mode 100644 index 0000000..82a8856 --- /dev/null +++ b/CrashDetection.h @@ -0,0 +1,33 @@ +// +// Created by ilya on 05.04.24. +// + +#ifndef SMART_COMPONENTS_CRASHDETECTION_H +#define SMART_COMPONENTS_CRASHDETECTION_H +#include "CarCrashDetection.h" +#include "LoggerInterface.h" + +typedef struct { + tCarCrashDetection carCrashDetection; + tUveosEmergencyEventInterface emergencyEvents; + tUveosEmergencySimulationInterface simulationInterface; + tLoggerInterface *logger; + + struct { + osThreadId_t id; + uint32_t stack[512]; + StaticTask_t controlBlock; + osThreadAttr_t attr; + } thread; +} tCrashDetection; + +void CrashDetection_Init( + tCrashDetection *env, + tAccelDataFlowInterface *accelData, + float *asi15threshold, + tCarFlipDetectionSettings *settings, + tLoggerInterface *logger +); +void CrashDetection_StopThread(tCrashDetection *env); +void CrashDetection_StartThread(tCrashDetection *env); +#endif //SMART_COMPONENTS_CRASHDETECTION_H diff --git a/modular.json b/modular.json new file mode 100644 index 0000000..5e4ed34 --- /dev/null +++ b/modular.json @@ -0,0 +1,12 @@ +{ + "dep": [ + ], + "cmake": { + "inc_dirs": [ + "./" + ], + "srcs": [ + "./**.c" + ] + } +} \ No newline at end of file