Send TSAL signals via CAN

This commit is contained in:
Jasper Blanckenburg 2024-09-04 12:33:26 +02:00
parent 998f9c93e4
commit 3e3c4272be
4 changed files with 33 additions and 3 deletions

View File

@ -10,6 +10,7 @@
#define CAN_ID_AMS_IN 0x00B
#define CAN_ID_AMS_ERROR 0x00C
#define CAN_ID_SLAVE_STATUS_BASE 0x080
#define CAN_ID_AMS_SIGNALS 0x090
#define CAN_ID_SLAVE_LOG 0x4F4
#define CAN_ID_SHUNT_BASE 0x520
#define CAN_ID_SHUNT_CURRENT 0x521

View File

@ -43,6 +43,11 @@ extern "C" {
/* USER CODE BEGIN EC */
extern int sdc_closed;
extern int sdc_closed_nodelay;
extern int ts_error;
extern int hv_active;
extern int neg_air_closed;
extern int pos_air_closed;
extern int precharge_closed;
/* USER CODE END EC */
/* Exported macro ------------------------------------------------------------*/

View File

@ -23,8 +23,7 @@ void can_init(FDCAN_HandleTypeDef *handle) {
HAL_StatusTypeDef can_send_status() {
uint8_t data[8];
data[0] =
ts_state.current_state | (sdc_closed << 7); // | (sdc_closed_nodelay << 6);
data[0] = ts_state.current_state | (sdc_closed << 7);
data[1] = roundf(current_soc);
ftcan_marshal_unsigned(&data[2], min_voltage, 2);
ftcan_marshal_signed(&data[4], max_temp, 2);
@ -34,7 +33,14 @@ HAL_StatusTypeDef can_send_status() {
} else {
data[7] = 0xFF;
}
return ftcan_transmit(CAN_ID_AMS_STATUS, data, sizeof(data));
HAL_StatusTypeDef ret = ftcan_transmit(CAN_ID_AMS_STATUS, data, sizeof(data));
if (ret != HAL_OK) {
return ret;
}
data[0] = (sdc_closed_nodelay << 0) | (ts_error << 1) | (hv_active << 2) |
(neg_air_closed << 3) | (pos_air_closed << 4) |
(precharge_closed << 5);
return ftcan_transmit(CAN_ID_AMS_SIGNALS, data, 1);
}
HAL_StatusTypeDef can_send_error(TSErrorKind kind, uint8_t arg) {

View File

@ -61,6 +61,11 @@ UART_HandleTypeDef huart1;
/* USER CODE BEGIN PV */
int sdc_closed = 0;
int sdc_closed_nodelay = 0;
int ts_error;
int hv_active;
int neg_air_closed;
int pos_air_closed;
int precharge_closed;
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
@ -99,6 +104,18 @@ static void update_sdc() {
last[0] = last[1];
last[1] = sdc_closed_nodelay;
}
static void update_tsal_signals() {
ts_error = HAL_GPIO_ReadPin(TS_ERROR_GPIO_Port, TS_ERROR_Pin) == GPIO_PIN_SET;
hv_active =
HAL_GPIO_ReadPin(HV_ACTIVE_GPIO_Port, HV_ACTIVE_Pin) == GPIO_PIN_SET;
neg_air_closed = HAL_GPIO_ReadPin(NEG_AIR_CLOSED_GPIO_Port,
NEG_AIR_CLOSED_Pin) == GPIO_PIN_SET;
pos_air_closed = HAL_GPIO_ReadPin(POS_AIR_CLOSED_GPIO_Port,
POS_AIR_CLOSED_Pin) == GPIO_PIN_SET;
precharge_closed = HAL_GPIO_ReadPin(PRECHARGE_CLOSED_GPIO_Port,
PRECHARGE_CLOSED_Pin) == GPIO_PIN_SET;
}
/* USER CODE END 0 */
/**
@ -150,6 +167,7 @@ int main(void)
/* USER CODE BEGIN 3 */
update_sdc();
update_tsal_signals();
slaves_check();
shunt_check();