Port FT22 code
This commit is contained in:
28
Core/Inc/can.h
Normal file
28
Core/Inc/can.h
Normal file
@ -0,0 +1,28 @@
|
||||
#ifndef INC_CAN_H
|
||||
#define INC_CAN_H
|
||||
|
||||
#include "stm32f3xx_hal.h"
|
||||
#include "stm32f3xx_hal_can.h"
|
||||
#include "stm32f3xx_hal_def.h"
|
||||
|
||||
#define CAN_ID_SLAVE_PANIC 0x009
|
||||
#define CAN_ID_AMS_STATUS 0x00A
|
||||
#define CAN_ID_AMS_IN 0x00B
|
||||
#define CAN_ID_SLAVE_LOG 0x4F4
|
||||
#define CAN_ID_SHUNT_BASE 0x520
|
||||
#define CAN_ID_SHUNT_CURRENT 0x521
|
||||
#define CAN_ID_SHUNT_VOLTAGE1 0x522
|
||||
#define CAN_ID_SHUNT_VOLTAGE2 0x523
|
||||
#define CAN_ID_SHUNT_VOLTAGE3 0x524
|
||||
#define CAN_ID_SHUNT_TEMP 0x525
|
||||
#define CAN_ID_SHUNT_POWER 0x526
|
||||
#define CAN_ID_SHUNT_CURRENT_COUNTER 0x527
|
||||
#define CAN_ID_SHUNT_ENERGY_COUNTER 0x528
|
||||
|
||||
void can_init(CAN_HandleTypeDef *handle);
|
||||
HAL_StatusTypeDef can_transmit(uint8_t id, uint8_t *data, size_t datalen);
|
||||
HAL_StatusTypeDef can_send_status();
|
||||
|
||||
void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *handle);
|
||||
|
||||
#endif // INC_CAN_H
|
||||
29
Core/Inc/shunt_monitoring.h
Normal file
29
Core/Inc/shunt_monitoring.h
Normal file
@ -0,0 +1,29 @@
|
||||
#ifndef INC_SHUNT_MONITORING_H
|
||||
#define INC_SHUNT_MONITORING_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "stm32f3xx_hal.h"
|
||||
|
||||
#define THRESH_OVERCURRENT 300000 // mA
|
||||
|
||||
typedef struct {
|
||||
int32_t current;
|
||||
int32_t voltage1;
|
||||
int32_t voltage2;
|
||||
int32_t voltage3;
|
||||
int32_t busbartemp;
|
||||
int32_t power;
|
||||
int32_t energy;
|
||||
int32_t current_counter;
|
||||
|
||||
uint32_t last_message;
|
||||
} ShuntData;
|
||||
extern ShuntData shunt_data;
|
||||
|
||||
void shunt_init();
|
||||
void shunt_check();
|
||||
|
||||
void shunt_handle_can_msg(CAN_RxHeaderTypeDef *header, uint8_t *data);
|
||||
|
||||
#endif // INC_SHUNT_MONITORING_H
|
||||
49
Core/Inc/slave_monitoring.h
Normal file
49
Core/Inc/slave_monitoring.h
Normal file
@ -0,0 +1,49 @@
|
||||
#ifndef INC_SLAVE_MONITORING_H
|
||||
#define INC_SLAVE_MONITORING_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define N_SLAVES 6
|
||||
#define N_CELLS_SERIES 17
|
||||
#define N_CELLS_PARALLEL 5
|
||||
#define N_TEMP_SENSORS 32
|
||||
|
||||
#define SLAVE_TIMEOUT 500
|
||||
#define SLAVE_PANIC_OT 0
|
||||
#define SLAVE_PANIC_UT 1
|
||||
#define SLAVE_PANIC_OV 2
|
||||
#define SLAVE_PANIC_UV 3
|
||||
|
||||
typedef enum {
|
||||
SLAVE_ERR_NONE,
|
||||
SLAVE_ERR_TIMEOUT,
|
||||
SLAVE_ERR_OT,
|
||||
SLAVE_ERR_UT,
|
||||
SLAVE_ERR_OV,
|
||||
SLAVE_ERR_UV
|
||||
} SlaveErrorKind;
|
||||
|
||||
typedef struct {
|
||||
SlaveErrorKind kind;
|
||||
uint32_t data; // Cell/temperature ID etc
|
||||
} SlaveError;
|
||||
|
||||
typedef struct {
|
||||
uint8_t id;
|
||||
SlaveError error;
|
||||
uint16_t voltages[N_CELLS_SERIES];
|
||||
int16_t temperatures[N_TEMP_SENSORS];
|
||||
uint32_t last_message;
|
||||
} SlaveHandle;
|
||||
|
||||
extern SlaveHandle slaves[N_SLAVES];
|
||||
extern uint16_t min_voltage;
|
||||
extern int16_t max_temp;
|
||||
|
||||
void slaves_init();
|
||||
void slaves_check();
|
||||
|
||||
void slaves_handle_panic(uint8_t *data);
|
||||
void slaves_handle_log(uint8_t *data);
|
||||
|
||||
#endif // INC_SLAVE_MONITORING_H
|
||||
11
Core/Inc/soc_estimation.h
Normal file
11
Core/Inc/soc_estimation.h
Normal file
@ -0,0 +1,11 @@
|
||||
#ifndef INC_SOC_ESTIMATION_H
|
||||
#define INC_SOC_ESTIMATION_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
extern uint8_t current_soc;
|
||||
|
||||
void soc_init();
|
||||
void soc_update();
|
||||
|
||||
#endif // INC_SOC_ESTIMATION_H
|
||||
@ -55,6 +55,7 @@ void SVC_Handler(void);
|
||||
void DebugMon_Handler(void);
|
||||
void PendSV_Handler(void);
|
||||
void SysTick_Handler(void);
|
||||
void USB_LP_CAN_RX0_IRQHandler(void);
|
||||
/* USER CODE BEGIN EFP */
|
||||
|
||||
/* USER CODE END EFP */
|
||||
|
||||
60
Core/Inc/ts_state_machine.h
Normal file
60
Core/Inc/ts_state_machine.h
Normal file
@ -0,0 +1,60 @@
|
||||
#ifndef INC_TS_STATE_MACHINE_H
|
||||
#define INC_TS_STATE_MACHINE_H
|
||||
|
||||
#include "stm32f3xx_hal.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
// Minimum vehicle side voltage to exit precharge
|
||||
#define MIN_VEHICLE_SIDE_VOLTAGE 150000 // mV
|
||||
// Time to wait after reaching 95% of battery voltage before exiting precharge
|
||||
#define PRECHARGE_95_DURATION 500 // ms
|
||||
// Time to wait after there is no more error condition before exiting TS_ERROR
|
||||
#define NO_ERROR_TIME 1000 // ms
|
||||
// Time to wait for charger voltage before going to TS_ERROR
|
||||
#define MAX_CHARGING_CHECK_DURATION 2000 // ms
|
||||
// Time to wait between closing relays
|
||||
#define RELAY_CLOSE_WAIT 10 // ms
|
||||
|
||||
typedef enum {
|
||||
TS_INACTIVE,
|
||||
TS_ACTIVE,
|
||||
TS_PRECHARGE,
|
||||
TS_DISCHARGE,
|
||||
TS_ERROR,
|
||||
TS_CHARGING_CHECK,
|
||||
TS_CHARGING
|
||||
} TSState;
|
||||
|
||||
#define TS_ERROR_SOURCE_SHUNT (1 << 0)
|
||||
#define TS_ERROR_SOURCE_SLAVES (1 << 1)
|
||||
|
||||
typedef struct {
|
||||
TSState current_state;
|
||||
TSState target_state;
|
||||
uint32_t error;
|
||||
} TSStateHandle;
|
||||
|
||||
extern TSStateHandle ts_state;
|
||||
|
||||
void ts_sm_init();
|
||||
void ts_sm_update();
|
||||
|
||||
TSState ts_sm_update_inactive();
|
||||
TSState ts_sm_update_active();
|
||||
TSState ts_sm_update_precharge();
|
||||
TSState ts_sm_update_discharge();
|
||||
TSState ts_sm_update_error();
|
||||
TSState ts_sm_update_charging_check();
|
||||
TSState ts_sm_update_charging();
|
||||
|
||||
typedef enum { RELAY_NEG, RELAY_POS, RELAY_PRECHARGE } Relay;
|
||||
void ts_sm_set_relay_positions(TSState state);
|
||||
void ts_sm_set_relay_position(Relay relay, int closed);
|
||||
void ts_sm_check_close_wait(int *is_closed, int should_close);
|
||||
|
||||
void ts_sm_handle_ams_in(uint8_t *data);
|
||||
|
||||
void ts_sm_set_error_source(uint32_t flag, int state);
|
||||
|
||||
#endif // INC_TS_STATE_MACHINE_H
|
||||
12
Core/Inc/util.h
Normal file
12
Core/Inc/util.h
Normal file
@ -0,0 +1,12 @@
|
||||
#ifndef INC_UTIL_H
|
||||
#define INC_UTIL_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void set_error_led();
|
||||
|
||||
uint64_t ntohll(uint64_t netlonglong);
|
||||
uint32_t ntohl(uint32_t netlong);
|
||||
uint16_t ntohs(uint16_t netshort);
|
||||
|
||||
#endif // INC_UTIL_H
|
||||
Reference in New Issue
Block a user