Обновление
This commit is contained in:
parent
4947d63c9a
commit
e34d1d13c8
47
AdcTasks.c
47
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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue