From e34d1d13c81de528a7c22503e61fe3ddb805c961 Mon Sep 17 00:00:00 2001 From: cfif Date: Mon, 16 Mar 2026 13:38:26 +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 --- AdcTasks.c | 47 +++++++++++++++++++++++++++++++++++++++++++++-- AdcTasks.h | 6 ++++++ 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/AdcTasks.c b/AdcTasks.c index b6112a0..a9c4f96 100644 --- a/AdcTasks.c +++ b/AdcTasks.c @@ -8,13 +8,18 @@ void Adc_0_Init(tAdcTask *env, tAdcIO *adcIO, - tGpios *gpios) { + tGpios *gpios +) { env->adcIO = adcIO; env->access = osMutexNew(NULL); env->gpios = gpios; + env->isRandomSecuritySeed = false; + + env->queueRandom = osMessageQueueNew(1, 4, NULL); + InitThreadAtrStatic(&env->thread.attr, "Adc0", env->thread.controlBlock, env->thread.stack, osPriorityNormal); } @@ -78,7 +83,8 @@ static _Noreturn void Adc0_Thread(tAdcTask *env) { GpioPinSet(&env->gpios->power.BTS5120_2EKA_ShutoffValvePowerTXV.ShutSelTXV_SEL_Diag, false); GpioPinSet(&env->gpios->power.BTS5180_2EKA_ShutOFFValveFrontRear.ShutSel_SEL_Diag, false); - GpioPinSet(&env->gpios->power.BTS5180_2EKA_TwoWayValveAndReservePowerSupply.TwoWayValve_SEL_Diag, false); + GpioPinSet(&env->gpios->power.BTS5180_2EKA_TwoWayValveAndReservePowerSupply.TwoWayValve_SEL_Diag, + false); GpioPinSet(&env->gpios->power.BTS5180_2EKA_FrontRearIncarMotor.Incar_SEL_Diag, false); GpioPinSet(&env->gpios->power.BTS5180_2EKA_2xChannelPTCPower.PtcRelayDriver_SEL_Diag, false); @@ -91,6 +97,22 @@ static _Noreturn void Adc0_Thread(tAdcTask *env) { env->ADC_isUpdate = true; } + if (env->isRandomSecuritySeed) { + uint32_t seed = 0; + + for (uint8_t i = 0; i < 28; ++i) { + seed = seed | ((pData[i] & 1) << i); + } + + for (uint8_t i = 0; i < 4; ++i) { + seed = seed | (((pData[i] >> 1) & 1) << (i + 28)); + } + + osStatus_t status = osMessageQueuePut(env->queueRandom, &seed, 0, 0U); + + env->isRandomSecuritySeed = false; + } + //memcpy(env->ADC_Data, (uint8_t *)ADC_Pointer_Data, env->ADC_ChannelCount << 2); @@ -101,6 +123,27 @@ static _Noreturn void Adc0_Thread(tAdcTask *env) { } } + +uint32_t getRandom32(tAdcTask *env) { + + if (osMutexAcquire(env->access, 1000) == osOK) { + env->isRandomSecuritySeed = true; + osMutexRelease(env->access); + } else { + return 0; + } + + uint32_t random = 0; + + osStatus_t status = osMessageQueueGet(env->queueRandom, &random, 0, 1000); + + if (status == osOK) { + return random; + } + + return 0; +} + void Adc_0_StartThread(tAdcTask *env) { if (!env->thread.id) { env->thread.id = osThreadNew((osThreadFunc_t) (Adc0_Thread), (void *) (env), &env->thread.attr); diff --git a/AdcTasks.h b/AdcTasks.h index ac4137e..5d108a8 100644 --- a/AdcTasks.h +++ b/AdcTasks.h @@ -78,6 +78,10 @@ typedef struct { uint8_t ADC0_BTS5120_2EKA_Channel; bool ADC_isUpdate; + bool isRandomSecuritySeed; + + osMessageQueueId_t queueRandom; + struct { osThreadId_t id; uint32_t stack[256]; @@ -87,6 +91,8 @@ typedef struct { } tAdcTask; +uint32_t getRandom32(tAdcTask *env); + void Adc_0_Init(tAdcTask *env, tAdcIO *adcIO, tGpios *gpios);