Prevent stack overflow on slave panic
This commit is contained in:
		@ -32,6 +32,7 @@ typedef struct {
 | 
			
		||||
  uint8_t error;
 | 
			
		||||
  uint8_t timeout;
 | 
			
		||||
  uint32_t frame_timestamps[SLAVE_HEARTBEAT_FRAMES];
 | 
			
		||||
  uint8_t error_frame[8];
 | 
			
		||||
 | 
			
		||||
} SlaveHandler;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -72,11 +72,9 @@ uint8_t CAN_Receive(FDCAN_HandleTypeDef* hcan) {
 | 
			
		||||
      uint8_t messageID = msg & 0x00F;
 | 
			
		||||
      updateSlaveInfo(slaveID, messageID, rxFrame);
 | 
			
		||||
    } else if (rxFrame.FrameID == SLAVE_EMERGENCY_ADDRESS) {
 | 
			
		||||
      AMSErrorHandle errorframe = {0};
 | 
			
		||||
      errorframe.errorcode = SlavesErrorFrameError;
 | 
			
		||||
      memcpy(errorframe.errorarg, rxFrame.data, 7);
 | 
			
		||||
 | 
			
		||||
      AMS_Error_Handler(&errorframe);
 | 
			
		||||
      uint8_t slave_id = rxFrame.data[0];
 | 
			
		||||
      slaves[slave_id].error = 1;
 | 
			
		||||
      memcpy(slaves[slave_id].error_frame, rxFrame.data, 8);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -13,6 +13,8 @@
 | 
			
		||||
#include "stm32g4xx_hal.h"
 | 
			
		||||
#include "stm32g4xx_hal_gpio.h"
 | 
			
		||||
 | 
			
		||||
#include <string.h>
 | 
			
		||||
 | 
			
		||||
SlaveHandler slaves[NUMBEROFSLAVES];
 | 
			
		||||
 | 
			
		||||
void initSlaves() {
 | 
			
		||||
@ -63,8 +65,12 @@ uint8_t checkSlaveTimeout() {
 | 
			
		||||
      return 1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (HAL_GetTick() < 20000) {
 | 
			
		||||
      continue;
 | 
			
		||||
    if (slaves[n].error) {
 | 
			
		||||
      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++) {
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user