Import/adapt Master_Interface code
This commit is contained in:
@ -40,13 +40,13 @@ typedef struct {
|
||||
uint32_t chargingCheckTimestamp;
|
||||
|
||||
} AIRStateHandler;
|
||||
extern AIRStateHandler airstate;
|
||||
|
||||
AIRStateHandler init_AIR_State_Maschine();
|
||||
void init_AIR_State_Maschine();
|
||||
|
||||
void Update_AIR_Info(AIRStateHandler* airstate);
|
||||
uint8_t Update_AIR_State(AIRStateHandler* airstate);
|
||||
void Activate_TS(AIRStateHandler* airstate);
|
||||
void Deactivate_TS(AIRStateHandler* airstate);
|
||||
uint8_t Update_AIR_State();
|
||||
void Activate_TS();
|
||||
void Deactivate_TS();
|
||||
|
||||
void AIR_Precharge_Position();
|
||||
void AIR_Inactive_Position();
|
||||
|
||||
@ -10,9 +10,15 @@
|
||||
|
||||
#include "main.h"
|
||||
|
||||
#define SlavesTimeoutError 1
|
||||
#define SlavesErrorFrameError 2
|
||||
#define SLAVES_FRAME_TIMEOUT_ERROR 3
|
||||
#define SLAVES_TOO_FEW_TEMPS 4
|
||||
#define AMS_ERROR_SLAVE_TIMEOUT 1
|
||||
#define AMS_ERROR_SLAVE_PANIC 2
|
||||
#define AMS_ERROR_SLAVE_FRAME_TIMEOUT 3
|
||||
#define AMS_ERROR_SLAVE_TOO_FEW_TEMPS 4
|
||||
#define AMS_ERROR_SHUNT_TIMEOUT 6
|
||||
#define AMS_ERROR_MASTER_THRESH 7
|
||||
#define AMS_ERRORARG_MASTER_THRESH_UT 0
|
||||
#define AMS_ERRORARG_MASTER_THRESH_OT 1
|
||||
#define AMS_ERRORARG_MASTER_THRESH_UV 2
|
||||
#define AMS_ERRORARG_MASTER_THRESH_OV 3
|
||||
|
||||
#endif /* INC_AMS_ERRORCODES_H_ */
|
||||
|
||||
@ -17,13 +17,30 @@
|
||||
|
||||
#define CANFRAMEBUFFERSIZE 512
|
||||
|
||||
#define CAN_ID_SLAVE_EMERGENCY 0x001
|
||||
#define CAN_ID_CLOCK_SYNC 0x002
|
||||
#define CAN_ID_AMS_STATUS 0x0A
|
||||
#define CAN_ID_AUTOBOX_INFO 0x0B
|
||||
#define CAN_ID_MASTER_HEARTBEAT 0x010
|
||||
#define CAN_ID_SLAVE_EEPROM_WRITE 0x020
|
||||
#define CAN_ID_AMS_PANIC 0x42
|
||||
|
||||
#define CAN_ID_START_CHARGING 0x446
|
||||
|
||||
#define CAN_ID_SHUNT_BASE 0x520
|
||||
#define CAN_MASK_SHUNT 0xFF0
|
||||
#define CAN_ID_SHUNT_CURRENT 0x521
|
||||
#define CAN_ID_SHUNT_VOLTAGE_1 0x522
|
||||
#define CAN_ID_SHUNT_VOLTAGE_2 0x523
|
||||
#define CAN_ID_SHUNT_VOLTAGE_3 0x524
|
||||
#define CAN_ID_SHUNT_BUSBAR_TEMP 0x525
|
||||
#define CAN_ID_SHUNT_POWER 0x526
|
||||
#define CAN_ID_SHUNT_AMPERE_SECONDS 0x527
|
||||
#define CAN_ID_SHUNT_ENERGY 0x528
|
||||
|
||||
// Frame ID = Base Address + Slave ID + MessageNr.
|
||||
#define SLAVE_STATUS_BASE_ADDRESS 0x600
|
||||
#define SLAVE_CMD_BASE_ADDRESS 0x500 //
|
||||
#define SLAVE_EMERGENCY_ADDRESS 0x001 // Emergency Frame
|
||||
#define CLOCK_SYNC_ADDRESS 0x002
|
||||
#define MASTER_HEARTBEAT_ADDRESS 0x010
|
||||
#define SLAVE_EEPROM_WRITE_ADDRESS 0x020
|
||||
#define CAN_ID_SLAVE_STATUS_BASE 0x600
|
||||
#define CAN_MASK_SLAVE_STATUS 0xF00
|
||||
|
||||
typedef struct {
|
||||
int16_t FrameID;
|
||||
@ -47,6 +64,12 @@ void CAN_Init(FDCAN_HandleTypeDef* hcan);
|
||||
uint8_t CAN_Receive(FDCAN_HandleTypeDef* hcan);
|
||||
uint8_t CAN_Transmit(FDCAN_HandleTypeDef* hcan, uint16_t frameid,
|
||||
uint8_t* buffer, uint8_t datalen);
|
||||
void updateSlaveInfo(uint8_t slaveID, uint8_t MessageID, canFrame rxFrame);
|
||||
|
||||
void CAN_SendAbxStatus(FDCAN_HandleTypeDef* hcan);
|
||||
void CAN_SendAMSPanic(FDCAN_HandleTypeDef* hcan, AMSErrorHandle* error);
|
||||
|
||||
void CAN_HandleShuntMsg(canFrame* rxFrame);
|
||||
void CAN_HandleSlaveStatus(canFrame* rxFrame);
|
||||
void CAN_HandleSlaveEmergency(canFrame* rxFrame);
|
||||
|
||||
#endif /* INC_CAN_COMMUNICATION_H_ */
|
||||
|
||||
36
Core/Inc/Check_Shunt_Limits.h
Normal file
36
Core/Inc/Check_Shunt_Limits.h
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Check_Shunt_Limits.h
|
||||
*
|
||||
* Created on: Jun 16, 2022
|
||||
* Author: max
|
||||
*/
|
||||
|
||||
#ifndef INC_CHECK_SHUNT_LIMITS_H_
|
||||
#define INC_CHECK_SHUNT_LIMITS_H_
|
||||
|
||||
#include "CAN_Communication.h"
|
||||
#include "main.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define SHUNT_OVERCURRENT 0x0FFFFFFF // Shunt Overcurrent Limit
|
||||
#define SHUNT_TIMEOUT 500 // Timeout after 500ms
|
||||
#define SHUNT_OVERTEMP 0xFFFFFFFF // Overtermperature of the Busbar
|
||||
|
||||
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 ampere_seconds;
|
||||
|
||||
uint32_t last_message;
|
||||
} ShuntData;
|
||||
extern ShuntData shunt_data;
|
||||
|
||||
void CheckShuntLimits();
|
||||
|
||||
#endif /* INC_CHECK_SHUNT_LIMITS_H_ */
|
||||
16
Core/Inc/Fan_Control.h
Normal file
16
Core/Inc/Fan_Control.h
Normal file
@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Fan_Control.h
|
||||
*
|
||||
* Created on: Jun 23, 2022
|
||||
* Author: max
|
||||
*/
|
||||
|
||||
#ifndef INC_FAN_CONTROL_H_
|
||||
#define INC_FAN_CONTROL_H_
|
||||
|
||||
#include "main.h"
|
||||
|
||||
void Temp_Ctrl_Init(TIM_HandleTypeDef* htim, uint32_t channel);
|
||||
void Temp_Ctrl_Loop();
|
||||
|
||||
#endif /* INC_FAN_CONTROL_H_ */
|
||||
@ -14,20 +14,28 @@
|
||||
|
||||
#include "stm32g431xx.h"
|
||||
|
||||
#define NUMBEROFSLAVES 9
|
||||
#define NUMBEROFCELLS 10
|
||||
#define NUMBEROFTEMPS 32
|
||||
#include <stdint.h>
|
||||
|
||||
#define N_SLAVES 9
|
||||
#define N_CELLS_SERIES 10
|
||||
#define N_CELLS_PARALLEL 9
|
||||
#define N_TEMP_SENSORS 32
|
||||
|
||||
#define SLAVETIMEOUT 5000
|
||||
#define SLAVE_HEARTBEAT_FRAMES 11
|
||||
// 30% * 90 = 27, each sensor measures 2 cells
|
||||
#define SLAVE_MIN_TEMP_SENSORS 14
|
||||
|
||||
#define THRESH_UV 32768 /* 2.5V */
|
||||
#define THRESH_OV 55050 /* 4.2V */
|
||||
#define THRESH_UT 0 /* 0C */
|
||||
#define THRESH_OT 880 /* 55C */
|
||||
|
||||
typedef struct {
|
||||
|
||||
uint16_t slaveID;
|
||||
uint16_t cellVoltages[NUMBEROFCELLS];
|
||||
uint16_t cellTemps[NUMBEROFTEMPS];
|
||||
uint16_t cellVoltages[N_CELLS_SERIES];
|
||||
uint16_t cellTemps[N_TEMP_SENSORS];
|
||||
uint32_t timestamp;
|
||||
uint8_t error;
|
||||
uint8_t timeout;
|
||||
@ -36,9 +44,12 @@ typedef struct {
|
||||
|
||||
} SlaveHandler;
|
||||
|
||||
extern SlaveHandler slaves[NUMBEROFSLAVES];
|
||||
extern SlaveHandler slaves[N_SLAVES];
|
||||
|
||||
extern uint16_t min_voltage, max_voltage;
|
||||
extern int16_t min_temp, max_temp;
|
||||
|
||||
void initSlaves();
|
||||
uint8_t checkSlaveTimeout();
|
||||
uint8_t checkSlaves();
|
||||
|
||||
#endif /* INC_SLAVE_MONITORING_H_ */
|
||||
|
||||
15
Core/Inc/SoC_Estimation.h
Normal file
15
Core/Inc/SoC_Estimation.h
Normal file
@ -0,0 +1,15 @@
|
||||
#ifndef INC_SOC_ESTIMATION_H
|
||||
#define INC_SOC_ESTIMATION_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define SOCE_SHUNT_CURRENT_OFF_THRESH 20 /* mA */
|
||||
#define CELL_VOLTAGE_CONVERSION_FACTOR (5.0f / 65535) /* V/quantum */
|
||||
#define BATTERY_CAPACITY (N_CELLS_PARALLEL * 2.5f * 3600) /* As */
|
||||
|
||||
extern uint8_t current_soc;
|
||||
|
||||
void estimate_soc();
|
||||
float calculate_soc_for_ocv(float ocv);
|
||||
|
||||
#endif // INC_SOC_ESTIMATION_H
|
||||
@ -38,7 +38,7 @@ extern "C" {
|
||||
/* USER CODE BEGIN ET */
|
||||
typedef struct {
|
||||
uint8_t errorcode;
|
||||
uint8_t errorarg[8];
|
||||
uint8_t errorarg[7];
|
||||
} AMSErrorHandle;
|
||||
/* USER CODE END ET */
|
||||
|
||||
|
||||
17
Core/Inc/util.h
Normal file
17
Core/Inc/util.h
Normal file
@ -0,0 +1,17 @@
|
||||
#ifndef INC_UTIL_H
|
||||
#define INC_UTIL_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* @brief Perform linear interpolation.
|
||||
*
|
||||
* @param n_points Size of source_x and source_y
|
||||
* @param source_x x values for the interpolation source (sorted ascending)
|
||||
* @param source_y y values corresponding to source_x
|
||||
* @param target_x x value that a y value should be interpolated for
|
||||
*/
|
||||
float interp(uint32_t n_points, const float* source_x, const float* source_y,
|
||||
float target_x);
|
||||
|
||||
#endif // INC_UTIL_H
|
||||
Reference in New Issue
Block a user