Send AMS Errors

This commit is contained in:
jazzpi
2022-06-24 04:38:00 +02:00
parent c8d6894e4b
commit 405b255936
6 changed files with 74 additions and 13 deletions

View File

@ -14,6 +14,8 @@
#include "stm32f4xx_hal_can.h"
#include "stm32f4xx_hal_def.h"
#include <stdint.h>
#define CAN_ID_SLAVE_ERROR 0x001
#define CAN_ID_AMS_SLAVE_HEARTBEAT_BASE 0x600
#define CAN_HEARTBEAT_TX_TIMEOUT 5 /* ms */
@ -24,9 +26,18 @@ void ams_can_handle_ams_msg(CAN_RxHeaderTypeDef* header, uint8_t* data);
void ams_can_handle_car_msg(CAN_RxHeaderTypeDef* header, uint8_t* data);
void ams_can_send_heartbeat();
void ams_can_send_error(AMS_ErrorCode error_code);
/**
* @brief Send an AMS Error via CAN.
*
* @param error_code The kind of error
* @param transmission_timeout How long to wait for the transmission to complete
* after starting it (in ms). Set to 0 for no wait.
*/
void ams_can_send_error(AMS_ErrorCode error_code,
uint32_t transmission_timeout);
HAL_StatusTypeDef ams_can_wait_for_free_mailbox(CAN_HandleTypeDef* handle,
uint32_t timeout);
HAL_StatusTypeDef ams_can_wait_for_free_mailboxes(CAN_HandleTypeDef* handle,
int num_mailboxes,
uint32_t timeout);
#endif /* INC_AMS_CAN_H_ */

View File

@ -20,6 +20,7 @@
#define CELL_UV_THRESHOLD 34100 // 2.6V
extern uint16_t cell_voltages[N_CELLS];
extern uint16_t max_voltage, min_voltage;
typedef enum { BQ_OFF, BQ_RDY, BQ_STDBY, BQ_INIT_PHASE, BQ_ERROR } BQ_Status;
extern BQ_Status bq_status;

View File

@ -40,7 +40,9 @@ typedef enum {
AMS_ERROR_UV,
AMS_ERROR_OV,
AMS_ERROR_UT,
AMS_ERROR_OT
AMS_ERROR_OT,
AMS_ERROR_BQ,
AMS_ERROR_TMP144
} AMS_ErrorCode;
/* USER CODE END ET */
@ -51,7 +53,12 @@ extern uint8_t slave_id;
/* Exported macro ------------------------------------------------------------*/
/* USER CODE BEGIN EM */
#define MAIN_LOOP_PERIOD 100 /* ms */
#define MAIN_LOOP_PERIOD 100 /* ms */
#define AMS_ERROR_TX_TIMEOUT 2 /* ms */
#define THRESH_UV 32768 /* 2.5V */
#define THRESH_OV 55050 /* 4.2V */
#define THRESH_UT 0 /* 0C */
#define THRESH_OT 880 /* 55C */
/* USER CODE END EM */
void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim);
@ -61,6 +68,7 @@ void Error_Handler(void);
/* USER CODE BEGIN EFP */
void update_status_leds();
void check_error_conditions();
void delay_period();
/* USER CODE END EFP */