Prevent stack overflow on slave panic

This commit is contained in:
jazzpi 2022-08-04 16:20:18 +02:00
parent e3a226be54
commit 77f600ddb3
3 changed files with 12 additions and 7 deletions

View File

@ -32,6 +32,7 @@ typedef struct {
uint8_t error; uint8_t error;
uint8_t timeout; uint8_t timeout;
uint32_t frame_timestamps[SLAVE_HEARTBEAT_FRAMES]; uint32_t frame_timestamps[SLAVE_HEARTBEAT_FRAMES];
uint8_t error_frame[8];
} SlaveHandler; } SlaveHandler;

View File

@ -72,11 +72,9 @@ uint8_t CAN_Receive(FDCAN_HandleTypeDef* hcan) {
uint8_t messageID = msg & 0x00F; uint8_t messageID = msg & 0x00F;
updateSlaveInfo(slaveID, messageID, rxFrame); updateSlaveInfo(slaveID, messageID, rxFrame);
} else if (rxFrame.FrameID == SLAVE_EMERGENCY_ADDRESS) { } else if (rxFrame.FrameID == SLAVE_EMERGENCY_ADDRESS) {
AMSErrorHandle errorframe = {0}; uint8_t slave_id = rxFrame.data[0];
errorframe.errorcode = SlavesErrorFrameError; slaves[slave_id].error = 1;
memcpy(errorframe.errorarg, rxFrame.data, 7); memcpy(slaves[slave_id].error_frame, rxFrame.data, 8);
AMS_Error_Handler(&errorframe);
} }
} }

View File

@ -13,6 +13,8 @@
#include "stm32g4xx_hal.h" #include "stm32g4xx_hal.h"
#include "stm32g4xx_hal_gpio.h" #include "stm32g4xx_hal_gpio.h"
#include <string.h>
SlaveHandler slaves[NUMBEROFSLAVES]; SlaveHandler slaves[NUMBEROFSLAVES];
void initSlaves() { void initSlaves() {
@ -63,8 +65,12 @@ uint8_t checkSlaveTimeout() {
return 1; return 1;
} }
if (HAL_GetTick() < 20000) { if (slaves[n].error) {
continue; AMSErrorHandle errorframe;
errorframe.errorcode = SlavesErrorFrameError;
memcpy(errorframe.errorarg, slaves[n].error_frame, 7);
AMS_Error_Handler(&errorframe);
return 1;
} }
for (int i = 0; i < SLAVE_HEARTBEAT_FRAMES; i++) { for (int i = 0; i < SLAVE_HEARTBEAT_FRAMES; i++) {