Compare commits
4 Commits
998f9c93e4
...
2b3c79c11f
Author | SHA1 | Date | |
---|---|---|---|
2b3c79c11f | |||
a942a95ec0 | |||
2f79d17bd1 | |||
3e3c4272be |
File diff suppressed because one or more lines are too long
@ -10,6 +10,7 @@
|
|||||||
#define CAN_ID_AMS_IN 0x00B
|
#define CAN_ID_AMS_IN 0x00B
|
||||||
#define CAN_ID_AMS_ERROR 0x00C
|
#define CAN_ID_AMS_ERROR 0x00C
|
||||||
#define CAN_ID_SLAVE_STATUS_BASE 0x080
|
#define CAN_ID_SLAVE_STATUS_BASE 0x080
|
||||||
|
#define CAN_ID_AMS_SIGNALS 0x090
|
||||||
#define CAN_ID_SLAVE_LOG 0x4F4
|
#define CAN_ID_SLAVE_LOG 0x4F4
|
||||||
#define CAN_ID_SHUNT_BASE 0x520
|
#define CAN_ID_SHUNT_BASE 0x520
|
||||||
#define CAN_ID_SHUNT_CURRENT 0x521
|
#define CAN_ID_SHUNT_CURRENT 0x521
|
||||||
|
@ -43,6 +43,12 @@ extern "C" {
|
|||||||
/* USER CODE BEGIN EC */
|
/* USER CODE BEGIN EC */
|
||||||
extern int sdc_closed;
|
extern int sdc_closed;
|
||||||
extern int sdc_closed_nodelay;
|
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;
|
||||||
|
extern int precharge_opened;
|
||||||
/* USER CODE END EC */
|
/* USER CODE END EC */
|
||||||
|
|
||||||
/* Exported macro ------------------------------------------------------------*/
|
/* Exported macro ------------------------------------------------------------*/
|
||||||
|
@ -23,8 +23,7 @@ void can_init(FDCAN_HandleTypeDef *handle) {
|
|||||||
|
|
||||||
HAL_StatusTypeDef can_send_status() {
|
HAL_StatusTypeDef can_send_status() {
|
||||||
uint8_t data[8];
|
uint8_t data[8];
|
||||||
data[0] =
|
data[0] = ts_state.current_state | (sdc_closed << 7);
|
||||||
ts_state.current_state | (sdc_closed << 7); // | (sdc_closed_nodelay << 6);
|
|
||||||
data[1] = roundf(current_soc);
|
data[1] = roundf(current_soc);
|
||||||
ftcan_marshal_unsigned(&data[2], min_voltage, 2);
|
ftcan_marshal_unsigned(&data[2], min_voltage, 2);
|
||||||
ftcan_marshal_signed(&data[4], max_temp, 2);
|
ftcan_marshal_signed(&data[4], max_temp, 2);
|
||||||
@ -34,7 +33,14 @@ HAL_StatusTypeDef can_send_status() {
|
|||||||
} else {
|
} else {
|
||||||
data[7] = 0xFF;
|
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) | (precharge_opened << 6);
|
||||||
|
return ftcan_transmit(CAN_ID_AMS_SIGNALS, data, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
HAL_StatusTypeDef can_send_error(TSErrorKind kind, uint8_t arg) {
|
HAL_StatusTypeDef can_send_error(TSErrorKind kind, uint8_t arg) {
|
||||||
|
@ -61,6 +61,12 @@ UART_HandleTypeDef huart1;
|
|||||||
/* USER CODE BEGIN PV */
|
/* USER CODE BEGIN PV */
|
||||||
int sdc_closed = 0;
|
int sdc_closed = 0;
|
||||||
int sdc_closed_nodelay = 0;
|
int sdc_closed_nodelay = 0;
|
||||||
|
int ts_error;
|
||||||
|
int hv_active;
|
||||||
|
int neg_air_closed;
|
||||||
|
int pos_air_closed;
|
||||||
|
int precharge_closed;
|
||||||
|
int precharge_opened = 0;
|
||||||
/* USER CODE END PV */
|
/* USER CODE END PV */
|
||||||
|
|
||||||
/* Private function prototypes -----------------------------------------------*/
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
@ -99,6 +105,18 @@ static void update_sdc() {
|
|||||||
last[0] = last[1];
|
last[0] = last[1];
|
||||||
last[1] = sdc_closed_nodelay;
|
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 */
|
/* USER CODE END 0 */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -150,6 +168,7 @@ int main(void)
|
|||||||
|
|
||||||
/* USER CODE BEGIN 3 */
|
/* USER CODE BEGIN 3 */
|
||||||
update_sdc();
|
update_sdc();
|
||||||
|
update_tsal_signals();
|
||||||
|
|
||||||
slaves_check();
|
slaves_check();
|
||||||
shunt_check();
|
shunt_check();
|
||||||
@ -266,7 +285,7 @@ static void MX_FDCAN1_Init(void)
|
|||||||
hfdcan1.Init.RxBufferSize = FDCAN_DATA_BYTES_8;
|
hfdcan1.Init.RxBufferSize = FDCAN_DATA_BYTES_8;
|
||||||
hfdcan1.Init.TxEventsNbr = 0;
|
hfdcan1.Init.TxEventsNbr = 0;
|
||||||
hfdcan1.Init.TxBuffersNbr = 0;
|
hfdcan1.Init.TxBuffersNbr = 0;
|
||||||
hfdcan1.Init.TxFifoQueueElmtsNbr = 1;
|
hfdcan1.Init.TxFifoQueueElmtsNbr = 32;
|
||||||
hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION;
|
hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION;
|
||||||
hfdcan1.Init.TxElmtSize = FDCAN_DATA_BYTES_8;
|
hfdcan1.Init.TxElmtSize = FDCAN_DATA_BYTES_8;
|
||||||
if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK)
|
if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK)
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
#define SOC_ESTIMATION_NO_CURRENT_THRESH 200 // mA
|
#define SOC_ESTIMATION_NO_CURRENT_THRESH 200 // mA
|
||||||
#define SOC_ESTIMATION_NO_CURRENT_TIME 100000 // ms
|
#define SOC_ESTIMATION_NO_CURRENT_TIME 100000 // ms
|
||||||
#define SOC_ESTIMATION_BATTERY_CAPACITY 70300800 // mAs
|
#define SOC_ESTIMATION_BATTERY_CAPACITY 64800000 // mAs
|
||||||
ocv_soc_pair_t OCV_SOC_PAIRS[] = {
|
ocv_soc_pair_t OCV_SOC_PAIRS[] = {
|
||||||
{2500, 0.00f}, {2990, 3.97f}, {3230, 9.36f}, {3320, 12.60f},
|
{2500, 0.00f}, {2990, 3.97f}, {3230, 9.36f}, {3320, 12.60f},
|
||||||
{3350, 13.68f}, {3410, 20.15f}, {3530, 32.01f}, {3840, 66.53f},
|
{3350, 13.68f}, {3410, 20.15f}, {3530, 32.01f}, {3840, 66.53f},
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "shunt_monitoring.h"
|
#include "shunt_monitoring.h"
|
||||||
#include "stm32h7xx_hal.h"
|
|
||||||
#include "status_led.h"
|
#include "status_led.h"
|
||||||
|
#include "stm32h7xx_hal.h"
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
TSStateHandle ts_state;
|
TSStateHandle ts_state;
|
||||||
@ -11,6 +11,7 @@ TSStateHandle ts_state;
|
|||||||
static uint32_t precharge_95_reached_timestamp = 0;
|
static uint32_t precharge_95_reached_timestamp = 0;
|
||||||
static uint32_t charging_check_timestamp = 0;
|
static uint32_t charging_check_timestamp = 0;
|
||||||
static uint32_t discharge_begin_timestamp = 0;
|
static uint32_t discharge_begin_timestamp = 0;
|
||||||
|
static uint32_t precharge_opened_timestamp = 0;
|
||||||
|
|
||||||
void ts_sm_init() {
|
void ts_sm_init() {
|
||||||
ts_state.current_state = TS_INACTIVE;
|
ts_state.current_state = TS_INACTIVE;
|
||||||
@ -48,7 +49,7 @@ void ts_sm_update() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ts_sm_set_relay_positions(ts_state.current_state);
|
ts_sm_set_relay_positions(ts_state.current_state);
|
||||||
status_led_state(ts_state.current_state, (TSErrorKind) ts_state.error_type);
|
status_led_state(ts_state.current_state, (TSErrorKind)ts_state.error_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
TSState ts_sm_update_inactive() {
|
TSState ts_sm_update_inactive() {
|
||||||
@ -77,6 +78,13 @@ TSState ts_sm_update_active() {
|
|||||||
return TS_DISCHARGE;
|
return TS_DISCHARGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!precharge_closed && precharge_opened_timestamp == 0) {
|
||||||
|
precharge_opened_timestamp = HAL_GetTick();
|
||||||
|
} else if (precharge_opened_timestamp != 0 &&
|
||||||
|
HAL_GetTick() - precharge_opened_timestamp > 100) {
|
||||||
|
precharge_opened = 1;
|
||||||
|
}
|
||||||
|
|
||||||
return TS_ACTIVE;
|
return TS_ACTIVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,8 +98,11 @@ TSState ts_sm_update_precharge() {
|
|||||||
uint32_t now = HAL_GetTick();
|
uint32_t now = HAL_GetTick();
|
||||||
if (precharge_95_reached_timestamp == 0) {
|
if (precharge_95_reached_timestamp == 0) {
|
||||||
precharge_95_reached_timestamp = now;
|
precharge_95_reached_timestamp = now;
|
||||||
} else if ((now - precharge_95_reached_timestamp) >= PRECHARGE_95_DURATION) {
|
} else if ((now - precharge_95_reached_timestamp) >=
|
||||||
|
PRECHARGE_95_DURATION) {
|
||||||
precharge_95_reached_timestamp = 0;
|
precharge_95_reached_timestamp = 0;
|
||||||
|
precharge_opened_timestamp = 0;
|
||||||
|
precharge_opened = 0;
|
||||||
return TS_ACTIVE;
|
return TS_ACTIVE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -166,7 +177,7 @@ void ts_sm_set_relay_positions(TSState state) {
|
|||||||
case TS_CHARGING:
|
case TS_CHARGING:
|
||||||
ts_sm_set_relay_position(RELAY_NEG, 1);
|
ts_sm_set_relay_position(RELAY_NEG, 1);
|
||||||
ts_sm_set_relay_position(RELAY_POS, 1);
|
ts_sm_set_relay_position(RELAY_POS, 1);
|
||||||
ts_sm_set_relay_position(RELAY_PRECHARGE, 1);
|
ts_sm_set_relay_position(RELAY_PRECHARGE, !precharge_opened);
|
||||||
// TODO: Open precharge relay after a while
|
// TODO: Open precharge relay after a while
|
||||||
break;
|
break;
|
||||||
case TS_PRECHARGE:
|
case TS_PRECHARGE:
|
||||||
@ -222,7 +233,8 @@ void ts_sm_handle_ams_in(const uint8_t *data) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ts_sm_set_error_source(TSErrorSource source, TSErrorKind error_type, bool is_errored) {
|
void ts_sm_set_error_source(TSErrorSource source, TSErrorKind error_type,
|
||||||
|
bool is_errored) {
|
||||||
if (is_errored) {
|
if (is_errored) {
|
||||||
ts_state.error_source |= source;
|
ts_state.error_source |= source;
|
||||||
ts_state.error_type = error_type;
|
ts_state.error_type = error_type;
|
||||||
|
@ -11,7 +11,7 @@ FDCAN1.NominalTimeSeg1=31
|
|||||||
FDCAN1.NominalTimeSeg2=8
|
FDCAN1.NominalTimeSeg2=8
|
||||||
FDCAN1.RxFifo0ElmtsNbr=16
|
FDCAN1.RxFifo0ElmtsNbr=16
|
||||||
FDCAN1.StdFiltersNbr=32
|
FDCAN1.StdFiltersNbr=32
|
||||||
FDCAN1.TxFifoQueueElmtsNbr=1
|
FDCAN1.TxFifoQueueElmtsNbr=32
|
||||||
File.Version=6
|
File.Version=6
|
||||||
GPIO.groupedBy=Group By Peripherals
|
GPIO.groupedBy=Group By Peripherals
|
||||||
I2C1.IPParameters=Timing
|
I2C1.IPParameters=Timing
|
||||||
@ -288,7 +288,7 @@ RCC.Tim2OutputFreq_Value=64000000
|
|||||||
RCC.TraceFreq_Value=64000000
|
RCC.TraceFreq_Value=64000000
|
||||||
RCC.USART16Freq_Value=64000000
|
RCC.USART16Freq_Value=64000000
|
||||||
RCC.USART234578Freq_Value=64000000
|
RCC.USART234578Freq_Value=64000000
|
||||||
RCC.USBFreq_Value=21333333.333333332
|
RCC.USBFreq_Value=42666666.666666664
|
||||||
RCC.VCO1OutputFreq_Value=128000000
|
RCC.VCO1OutputFreq_Value=128000000
|
||||||
RCC.VCO2OutputFreq_Value=160000000
|
RCC.VCO2OutputFreq_Value=160000000
|
||||||
RCC.VCO3OutputFreq_Value=64500000
|
RCC.VCO3OutputFreq_Value=64500000
|
||||||
|
Loading…
x
Reference in New Issue
Block a user