Send AMS error messages
This commit is contained in:
parent
48ae56fbdf
commit
ce4d7253eb
@ -5,9 +5,12 @@
|
|||||||
#include "stm32f3xx_hal_can.h"
|
#include "stm32f3xx_hal_can.h"
|
||||||
#include "stm32f3xx_hal_def.h"
|
#include "stm32f3xx_hal_def.h"
|
||||||
|
|
||||||
|
#include "ts_state_machine.h"
|
||||||
|
|
||||||
#define CAN_ID_SLAVE_PANIC 0x009
|
#define CAN_ID_SLAVE_PANIC 0x009
|
||||||
#define CAN_ID_AMS_STATUS 0x00A
|
#define CAN_ID_AMS_STATUS 0x00A
|
||||||
#define CAN_ID_AMS_IN 0x00B
|
#define CAN_ID_AMS_IN 0x00B
|
||||||
|
#define CAN_ID_AMS_ERROR 0x00C
|
||||||
#define CAN_ID_SLAVE_STATUS 0x014
|
#define CAN_ID_SLAVE_STATUS 0x014
|
||||||
#define CAN_ID_SLAVE_LOG 0x4F4
|
#define CAN_ID_SLAVE_LOG 0x4F4
|
||||||
#define CAN_ID_SHUNT_BASE 0x520
|
#define CAN_ID_SHUNT_BASE 0x520
|
||||||
@ -22,6 +25,7 @@
|
|||||||
|
|
||||||
void can_init(CAN_HandleTypeDef *handle);
|
void can_init(CAN_HandleTypeDef *handle);
|
||||||
HAL_StatusTypeDef can_send_status();
|
HAL_StatusTypeDef can_send_status();
|
||||||
|
HAL_StatusTypeDef can_send_error(TSErrorKind kind, uint8_t arg);
|
||||||
|
|
||||||
void ftcan_msg_received_cb(uint16_t id, size_t datalen, const uint8_t *data);
|
void ftcan_msg_received_cb(uint16_t id, size_t datalen, const uint8_t *data);
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include "stm32f3xx_hal.h"
|
#include "stm32f3xx_hal.h"
|
||||||
|
|
||||||
#define THRESH_OVERCURRENT 300000 // mA
|
#define THRESH_OVERCURRENT 300000 // mA
|
||||||
|
#define THRESH_OVERTEMP 1000 // 1/10 °C
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t current;
|
int32_t current;
|
||||||
|
@ -29,6 +29,14 @@ typedef enum {
|
|||||||
TS_CHARGING
|
TS_CHARGING
|
||||||
} TSState;
|
} TSState;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
TS_ERRORKIND_NONE = 0x00,
|
||||||
|
TS_ERRORKIND_SLAVE_TIMEOUT = 0x01,
|
||||||
|
TS_ERRORKIND_SLAVE_PANIC = 0x02,
|
||||||
|
TS_ERRORKIND_SHUNT_TIMEOUT = 0x03,
|
||||||
|
TS_ERRORKIND_SHUNT_OVERCURRENT = 0x04,
|
||||||
|
TS_ERRORKIND_SHUNT_OVERTEMP = 0x05
|
||||||
|
} TSErrorKind;
|
||||||
#define TS_ERROR_SOURCE_SHUNT (1 << 0)
|
#define TS_ERROR_SOURCE_SHUNT (1 << 0)
|
||||||
#define TS_ERROR_SOURCE_SLAVES (1 << 1)
|
#define TS_ERROR_SOURCE_SLAVES (1 << 1)
|
||||||
|
|
||||||
|
@ -28,6 +28,13 @@ HAL_StatusTypeDef can_send_status() {
|
|||||||
return ftcan_transmit(CAN_ID_AMS_STATUS, data, sizeof(data));
|
return ftcan_transmit(CAN_ID_AMS_STATUS, data, sizeof(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HAL_StatusTypeDef can_send_error(TSErrorKind kind, uint8_t arg) {
|
||||||
|
uint8_t data[2];
|
||||||
|
data[0] = kind;
|
||||||
|
data[1] = arg;
|
||||||
|
return ftcan_transmit(CAN_ID_AMS_ERROR, data, sizeof(data));
|
||||||
|
}
|
||||||
|
|
||||||
void ftcan_msg_received_cb(uint16_t id, size_t datalen, const uint8_t *data) {
|
void ftcan_msg_received_cb(uint16_t id, size_t datalen, const uint8_t *data) {
|
||||||
if ((id & 0xFF0) == CAN_ID_SHUNT_BASE) {
|
if ((id & 0xFF0) == CAN_ID_SHUNT_BASE) {
|
||||||
shunt_handle_can_msg(id, data);
|
shunt_handle_can_msg(id, data);
|
||||||
|
@ -23,7 +23,14 @@ void shunt_init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void shunt_check() {
|
void shunt_check() {
|
||||||
int is_error = shunt_data.current >= THRESH_OVERCURRENT;
|
int is_error = 0;
|
||||||
|
if (shunt_data.current >= THRESH_OVERCURRENT) {
|
||||||
|
is_error = 1;
|
||||||
|
can_send_error(TS_ERRORKIND_SHUNT_OVERTEMP, 0);
|
||||||
|
} else if (shunt_data.busbartemp >= THRESH_OVERTEMP) {
|
||||||
|
is_error = 1;
|
||||||
|
can_send_error(TS_ERRORKIND_SHUNT_OVERTEMP, 0);
|
||||||
|
}
|
||||||
ts_sm_set_error_source(TS_ERROR_SOURCE_SHUNT, is_error);
|
ts_sm_set_error_source(TS_ERROR_SOURCE_SHUNT, is_error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include "slave_monitoring.h"
|
#include "slave_monitoring.h"
|
||||||
|
|
||||||
|
#include "can.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "ts_state_machine.h"
|
#include "ts_state_machine.h"
|
||||||
|
|
||||||
@ -60,14 +61,18 @@ void slaves_check() {
|
|||||||
uint16_t min_voltage_new = 0xFFFF;
|
uint16_t min_voltage_new = 0xFFFF;
|
||||||
int16_t max_temp_new = 0xFFFF;
|
int16_t max_temp_new = 0xFFFF;
|
||||||
for (int i = 0; i < N_SLAVES; i++) {
|
for (int i = 0; i < N_SLAVES; i++) {
|
||||||
|
// Update timeout errors
|
||||||
if (now - slaves[i].last_message >= SLAVE_TIMEOUT) {
|
if (now - slaves[i].last_message >= SLAVE_TIMEOUT) {
|
||||||
// Don't overwrite a different error kind
|
// Don't overwrite a different error kind
|
||||||
if (slaves[i].error.kind == SLAVE_ERR_NONE) {
|
if (slaves[i].error.kind == SLAVE_ERR_NONE) {
|
||||||
slaves[i].error.kind = SLAVE_ERR_TIMEOUT;
|
slaves[i].error.kind = SLAVE_ERR_TIMEOUT;
|
||||||
|
can_send_error(TS_ERRORKIND_SLAVE_TIMEOUT, slaves[i].id);
|
||||||
}
|
}
|
||||||
} else if (slaves[i].error.kind == SLAVE_ERR_TIMEOUT) {
|
} else if (slaves[i].error.kind == SLAVE_ERR_TIMEOUT) {
|
||||||
slaves[i].error.kind = SLAVE_ERR_NONE;
|
slaves[i].error.kind = SLAVE_ERR_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Determine min/max
|
||||||
if (slaves[i].min_voltage < min_voltage_new) {
|
if (slaves[i].min_voltage < min_voltage_new) {
|
||||||
min_voltage_new = slaves[i].min_voltage;
|
min_voltage_new = slaves[i].min_voltage;
|
||||||
}
|
}
|
||||||
@ -107,6 +112,7 @@ void slaves_handle_panic(const uint8_t *data) {
|
|||||||
}
|
}
|
||||||
slaves[idx].error.data = ftcan_unmarshal_unsigned(&data, 4);
|
slaves[idx].error.data = ftcan_unmarshal_unsigned(&data, 4);
|
||||||
slaves[idx].last_message = HAL_GetTick();
|
slaves[idx].last_message = HAL_GetTick();
|
||||||
|
can_send_error(TS_ERRORKIND_SLAVE_PANIC, slave_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void slaves_handle_status(const uint8_t *data) {
|
void slaves_handle_status(const uint8_t *data) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user