59 lines
1.4 KiB
C
59 lines
1.4 KiB
C
/*
|
|
* Slave_Monitoring.c
|
|
*
|
|
* Created on: Jun 15, 2022
|
|
* Author: max
|
|
*/
|
|
|
|
#include "Slave_Monitoring.h"
|
|
|
|
SlaveHandler slaves[NUMBEROFSLAVES];
|
|
|
|
void initSlaves() {
|
|
HAL_GPIO_WritePin(Slaves_Enable_GPIO_Port, Slaves_Enable_Pin, GPIO_PIN_RESET);
|
|
HAL_GPIO_WritePin(BOOT0_FF_DATA_GPIO_Port, BOOT0_FF_DATA_Pin, GPIO_PIN_RESET);
|
|
|
|
for (int i = 0; i < NUMBEROFSLAVES + 5; i++) {
|
|
HAL_GPIO_WritePin(BOOT0_FF_CLK_GPIO_Port, BOOT0_FF_CLK_Pin, GPIO_PIN_SET);
|
|
HAL_Delay(1);
|
|
HAL_GPIO_WritePin(BOOT0_FF_CLK_GPIO_Port, BOOT0_FF_CLK_Pin, GPIO_PIN_RESET);
|
|
HAL_Delay(1);
|
|
}
|
|
|
|
HAL_Delay(5);
|
|
HAL_GPIO_WritePin(Slaves_Enable_GPIO_Port, Slaves_Enable_Pin, GPIO_PIN_SET);
|
|
|
|
for (int n = 0; n < NUMBEROFSLAVES; n++) {
|
|
for (int i = 0; i < NUMBEROFTEMPS; i++)
|
|
slaves[n].cellTemps[i] = 30000;
|
|
|
|
for (int j = 0; j < NUMBEROFCELLS; j++)
|
|
slaves[n].cellVoltages[j] = 25000;
|
|
|
|
slaves[n].error = 0;
|
|
slaves[n].timeout = 0;
|
|
slaves[n].timestamp = HAL_GetTick();
|
|
slaves[n].slaveID = n;
|
|
}
|
|
}
|
|
|
|
uint8_t checkSlaveTimeout() {
|
|
if (HAL_GetTick() < 10000) {
|
|
return 0;
|
|
}
|
|
|
|
for (int n = 0; n < NUMBEROFSLAVES; n++) {
|
|
if (((int)(HAL_GetTick() - slaves[n].timestamp)) > SLAVETIMEOUT) {
|
|
slaves[n].timeout = 1;
|
|
|
|
AMSErrorHandle timeouterror;
|
|
timeouterror.errorcode = SlavesTimeoutError;
|
|
timeouterror.errorarg[0] = n;
|
|
|
|
AMS_Error_Handler(&timeouterror);
|
|
return 1;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|