copy files over from slave
This commit is contained in:
		
							
								
								
									
										106
									
								
								Core/Inc/ADBMS_Abstraction.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										106
									
								
								Core/Inc/ADBMS_Abstraction.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,106 @@
 | 
			
		||||
/*
 | 
			
		||||
 * ADBMS_Abstraction.h
 | 
			
		||||
 *
 | 
			
		||||
 *  Created on: 14.07.2022
 | 
			
		||||
 *      Author: max
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#ifndef INC_ADBMS_ABSTRACTION_H_
 | 
			
		||||
#define INC_ADBMS_ABSTRACTION_H_
 | 
			
		||||
 | 
			
		||||
#include "ADBMS_CMD_MAKROS.h"
 | 
			
		||||
#include "ADBMS_LL_Driver.h"
 | 
			
		||||
#include "main.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#define MAXIMUM_CELL_VOLTAGES 16
 | 
			
		||||
#define MAXIMUM_AUX_VOLTAGES  10
 | 
			
		||||
#define MAXIMUM_GPIO          10
 | 
			
		||||
 | 
			
		||||
//see table 103 in datasheet (page 71)
 | 
			
		||||
#define DEFAULT_UV 417	//VUV * 16 * 150 uV + 1.5 V     Default Setting 2.5V
 | 
			
		||||
#define DEFAULT_OV 1125 //VOV * 16 * 150 uV + 1.5 V		  Default Setting 4.2V
 | 
			
		||||
 | 
			
		||||
#define mV_from_ADBMS6830(x) (((((int16_t) (x))) * 0.150) + 1500)
 | 
			
		||||
 | 
			
		||||
struct ADBMS6830_Internal_Status {
 | 
			
		||||
  uint16 CS_FLT : 16; //ADC fault - mismatch between S- and C-ADC
 | 
			
		||||
  uint16 : 3;
 | 
			
		||||
  uint16 CCTS : 13; //Conversion counter
 | 
			
		||||
  uint16 VA_OV : 1; //5V analog supply overvoltage
 | 
			
		||||
  uint16 VA_UV : 1; //5V analog supply undervoltage
 | 
			
		||||
  uint16 VD_OV : 1; //3V digital supply overvoltage
 | 
			
		||||
  uint16 VD_UV : 1; //3V digital supply undervoltage
 | 
			
		||||
  uint16 CED : 1; //C-ADC single trim error (correctable)
 | 
			
		||||
  uint16 CMED : 1; //C-ADC multiple trim error (uncorrectable)
 | 
			
		||||
  uint16 SED : 1; //S-ADC single trim error (correctable)
 | 
			
		||||
  uint16 SMED : 1; //S-ADC multiple trim error (uncorrectable)
 | 
			
		||||
  uint16 VDEL : 1; //Latent supply voltage error
 | 
			
		||||
  uint16 VDE : 1; //Supply voltage error
 | 
			
		||||
  uint16 COMPARE : 1; //Comparasion between S- and C-ADC active
 | 
			
		||||
  uint16 SPIFLT : 1; //SPI fault
 | 
			
		||||
  uint16 SLEEP : 1; //Sleep mode previously entered
 | 
			
		||||
  uint16 THSD : 1; //Thermal shutdown
 | 
			
		||||
  uint16 TMODCHK : 1; //Test mode check
 | 
			
		||||
  uint16 OSCCHK : 1; //Oscillator check
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
typedef struct {
 | 
			
		||||
  int16_t cellVoltages[MAXIMUM_CELL_VOLTAGES];
 | 
			
		||||
  int16_t auxVoltages[MAXIMUM_AUX_VOLTAGES];
 | 
			
		||||
 | 
			
		||||
  struct ADBMS6830_Internal_Status status;
 | 
			
		||||
  uint16 internalDieTemp;
 | 
			
		||||
  uint16 analogSupplyVoltage;
 | 
			
		||||
  uint16 digitalSupplyVoltage;
 | 
			
		||||
  uint16 sumOfCellMeasurements;
 | 
			
		||||
  uint16 refVoltage;
 | 
			
		||||
 | 
			
		||||
  uint16 GPIO_Values[MAXIMUM_GPIO];
 | 
			
		||||
 | 
			
		||||
  uint32 overVoltage;
 | 
			
		||||
  uint32 underVoltage;
 | 
			
		||||
 | 
			
		||||
} Cell_Module;
 | 
			
		||||
 | 
			
		||||
uint8 amsReset();
 | 
			
		||||
 | 
			
		||||
uint8 initAMS(SPI_HandleTypeDef* hspi, uint8 numofcells, uint8 numofaux);
 | 
			
		||||
uint8 amsWakeUp();
 | 
			
		||||
 | 
			
		||||
uint8 amsCellMeasurement(Cell_Module* module);
 | 
			
		||||
uint8 amsConfigCellMeasurement(uint8 numberofChannels);
 | 
			
		||||
 | 
			
		||||
uint8 amsAuxAndStatusMeasurement(Cell_Module* module);
 | 
			
		||||
uint8 amsConfigAuxMeasurement(uint16 Channels);
 | 
			
		||||
 | 
			
		||||
uint8 amsConfigGPIO(uint16 gpios);
 | 
			
		||||
uint8 amsSetGPIO(uint16 gpios);
 | 
			
		||||
uint8 readGPIO(Cell_Module* module);
 | 
			
		||||
 | 
			
		||||
uint8 amsConfigBalancing(uint32 Channels, uint8 dutyCycle);
 | 
			
		||||
uint8 amsStartBalancing(uint8 dutyCycle);
 | 
			
		||||
uint8 amsStopBalancing();
 | 
			
		||||
 | 
			
		||||
uint8 amsSelfTest();
 | 
			
		||||
 | 
			
		||||
uint8 amsConfigOverUnderVoltage(uint16 overVoltage, uint16 underVoltage);
 | 
			
		||||
 | 
			
		||||
uint8 amsCheckUnderOverVoltage(Cell_Module* module);
 | 
			
		||||
uint8 amsConfigOverVoltage(uint16 overVoltage);
 | 
			
		||||
 | 
			
		||||
uint8 amscheckOpenCellWire(Cell_Module* module);
 | 
			
		||||
 | 
			
		||||
uint8 amsClearStatus();
 | 
			
		||||
uint8 amsClearAux();
 | 
			
		||||
uint8 amsClearCells();
 | 
			
		||||
 | 
			
		||||
uint8 amsSendWarning();
 | 
			
		||||
uint8 amsSendError();
 | 
			
		||||
 | 
			
		||||
uint8 amsClearWarning();
 | 
			
		||||
uint8 amsClearError();
 | 
			
		||||
 | 
			
		||||
uint8 amsReadCellVoltages(Cell_Module* module);
 | 
			
		||||
 | 
			
		||||
#endif /* INC_ADBMS_ABSTRACTION_H_ */
 | 
			
		||||
							
								
								
									
										171
									
								
								Core/Inc/ADBMS_CMD_MAKROS.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										171
									
								
								Core/Inc/ADBMS_CMD_MAKROS.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,171 @@
 | 
			
		||||
/*
 | 
			
		||||
 * ADBMS_CMD_MAKROS.h
 | 
			
		||||
 *
 | 
			
		||||
 *  Created on: 14.07.2022
 | 
			
		||||
 *      Author: max
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#ifndef INC_ADBMS_CMD_MAKROS_H_
 | 
			
		||||
#define INC_ADBMS_CMD_MAKROS_H_
 | 
			
		||||
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
#define WRCFGA 0x0001 // Write Configuration Register Group A
 | 
			
		||||
#define RDCFGA 0x0002 // Read Configuration Register Group A
 | 
			
		||||
#define WRCFGB 0x0024 // Write Configuration Register Group B
 | 
			
		||||
#define RDCFGB 0x0026 // Read Configuration Register Group B
 | 
			
		||||
 | 
			
		||||
#define WRPWMA 0x0020 // Write PWM Register Group A
 | 
			
		||||
#define RDPWMA 0x0022 // Read PWM Register Group A
 | 
			
		||||
#define WRPWMB 0x0021 // Write PWM Register Group B
 | 
			
		||||
#define RDPWMB 0x0023 // Read PWM Register Group B
 | 
			
		||||
 | 
			
		||||
#define RDCVA 0x0004 // Read Cell Voltage Register Group A
 | 
			
		||||
#define RDCVB 0x0006 // Read Cell Voltage Register Group B
 | 
			
		||||
#define RDCVC 0x0008 // Read Cell Voltage Register Group C
 | 
			
		||||
#define RDCVD 0x000A // Read Cell Voltage Register Group D
 | 
			
		||||
#define RDCVE 0x0009 // Read Cell Voltage Register Group E
 | 
			
		||||
#define RDCVF 0x000B // Read Cell Voltage Register Group F
 | 
			
		||||
#define RDCVALL 0x000C // Read All Cell Voltage Register Groups
 | 
			
		||||
 | 
			
		||||
#define RDACA 0x0044 // Read averaged Cell Voltage Register Group A
 | 
			
		||||
#define RDACB 0x0046 // Read averaged Cell Voltage Register Group B
 | 
			
		||||
#define RDACC 0x0048 // Read averaged Cell Voltage Register Group C
 | 
			
		||||
#define RDACD 0x004A // Read averaged Cell Voltage Register Group D
 | 
			
		||||
#define RDACE 0x0049 // Read averaged Cell Voltage Register Group E
 | 
			
		||||
#define RDACF 0x004B // Read averaged Cell Voltage Register Group F
 | 
			
		||||
#define RDACALL 0x004C // Read averaged All Cell Voltage Register Groups
 | 
			
		||||
 | 
			
		||||
#define RDAUXA 0x0019 // Read Auxilliary Register Group A
 | 
			
		||||
#define RDAUXB 0x001A // Read Auxilliary Register Group B
 | 
			
		||||
#define RDAUXC 0x001B // Read Auxilliary Register Group C
 | 
			
		||||
#define RDAUXD 0x001F // Read Auxilliary Register Group D
 | 
			
		||||
 | 
			
		||||
#define RDAUXALL 0x0035 // Read All Auxilliary and Status Register Groups
 | 
			
		||||
 | 
			
		||||
#define RDSTATA 0x0030 // Read Status Register Group A
 | 
			
		||||
#define RDSTATB 0x0031 // Read Status Register Group B
 | 
			
		||||
#define RDSTATC 0x0032 // Read Status Register Group C
 | 
			
		||||
#define RDSTATD 0x0033 // Read Status Register Group D
 | 
			
		||||
#define RDSTATE 0x0034 // Read Status Register Group E
 | 
			
		||||
 | 
			
		||||
#define ADCV 0x0260 // Start Cell Voltage Conversion with C-ADC
 | 
			
		||||
#define ADCV_OW_0 (1u << 0)
 | 
			
		||||
#define ADCV_OW_1 (1u << 1)
 | 
			
		||||
#define ADCV_RSTF (1u << 2)
 | 
			
		||||
#define ADCV_DCP  (1u << 4)
 | 
			
		||||
#define ADCV_CONT (1u << 7) // Continuous Mode
 | 
			
		||||
#define ADCV_RD   (1u << 8) // Redundancy Mode
 | 
			
		||||
 | 
			
		||||
#define ADSV 0x0168 // Start Cell Voltage Conversion with S-ADC
 | 
			
		||||
#define ADSV_OW_0 (1u << 0)
 | 
			
		||||
#define ADSV_OW_1 (1u << 1)
 | 
			
		||||
#define ADSV_DCP (1u << 4)
 | 
			
		||||
#define ADSV_CONT (1u << 7) // Continuous Mode
 | 
			
		||||
 | 
			
		||||
#define ADAX 0x0410 // Start GPIOs and Vref2 Conversion
 | 
			
		||||
#define ADAX_CONV_ALL 0x0000 // Convert all GPIOs, VREF2, VD, VA, ITEMP
 | 
			
		||||
#define ADAX_OW (1u << 8)
 | 
			
		||||
 | 
			
		||||
#define CLRCELL 0x0711 // Clear Cell Voltage Register Groups
 | 
			
		||||
#define CLRAUX  0x0712 // Clear Auxiliary Register Groups
 | 
			
		||||
#define CLOVUV 0x0715 // Clear Overvoltage and Undervoltage Flags
 | 
			
		||||
#define CLRFLAG 0x0717 // Clear all Flags
 | 
			
		||||
 | 
			
		||||
#define PLADC   0x0718 // Poll ADC Conversion Status
 | 
			
		||||
#define PLAUX   0x071E // Poll AUX Conversion Status
 | 
			
		||||
 | 
			
		||||
#define SRST   0x0027 //Soft reset
 | 
			
		||||
 | 
			
		||||
#define DIAGN   0x0715 // Diagnos MUX and Poll Status
 | 
			
		||||
#define WRCOMM  0x0721 // Write COMM Register Group
 | 
			
		||||
#define RDCOMM  0x0722 // Read COMM Register Group
 | 
			
		||||
#define STCOMM  0x0723 // Start I2C/SPI Communication
 | 
			
		||||
#define MUTE    0x0028 // Mute Discharge
 | 
			
		||||
#define UNMUTE  0x0029 // Unmute Discharge
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/* GPIO Selection for ADC Converion
 | 
			
		||||
 * 000: GPIO1 to 5, 2nd Reference, GPIO 6 to 9
 | 
			
		||||
 * 001: GPIO1 and GPIO6
 | 
			
		||||
 * 010 GPIO2 and GPIO7
 | 
			
		||||
 * 011 GPIO3 and GPIO8
 | 
			
		||||
 * 100 GPIO4 and GPIO9
 | 
			
		||||
 * 101 GPIO5
 | 
			
		||||
 * 110 2nd Reference
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#define CHG000 (0x00)
 | 
			
		||||
#define CHG001 (0x01)
 | 
			
		||||
#define CHG010 (0x02)
 | 
			
		||||
#define CHG011 (0x03)
 | 
			
		||||
#define CHG100 (0x04)
 | 
			
		||||
#define CHG101 (0x05)
 | 
			
		||||
#define CHG110 (0x06)
 | 
			
		||||
 | 
			
		||||
/* Status Group Selection
 | 
			
		||||
 * 000: SC,ITMP,VA,VD
 | 
			
		||||
 * 001: SC
 | 
			
		||||
 * 010: ITMP
 | 
			
		||||
 * 011: VA
 | 
			
		||||
 * 100: VD
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#define CHST000 (0x00)
 | 
			
		||||
#define CHST001 (0x01)
 | 
			
		||||
#define CHST010 (0x02)
 | 
			
		||||
#define CHST011 (0x03)
 | 
			
		||||
#define CHST100 (0x04)
 | 
			
		||||
 | 
			
		||||
#define PEC_FIELD_SIZE 2
 | 
			
		||||
 | 
			
		||||
#define CFG_GROUP_A_SIZE 6
 | 
			
		||||
#define CFG_GROUP_B_SIZE 6
 | 
			
		||||
 | 
			
		||||
#define PWM_GROUP_A_SIZE 6
 | 
			
		||||
#define PWM_GROUP_B_SIZE 2
 | 
			
		||||
 | 
			
		||||
#define CV_GROUP_A_SIZE  6
 | 
			
		||||
#define CV_GROUP_B_SIZE  6
 | 
			
		||||
#define CV_GROUP_C_SIZE  6
 | 
			
		||||
#define CV_GROUP_D_SIZE  6
 | 
			
		||||
#define CV_GROUP_E_SIZE  6
 | 
			
		||||
#define CV_GROUP_F_SIZE  6
 | 
			
		||||
 | 
			
		||||
#define AUX_GROUP_A_SIZE 6
 | 
			
		||||
#define AUX_GROUP_B_SIZE 6
 | 
			
		||||
#define AUX_GROUP_C_SIZE 6
 | 
			
		||||
#define AUX_GROUP_D_SIZE 6
 | 
			
		||||
 | 
			
		||||
#define STATUS_GROUP_A_SIZE        6
 | 
			
		||||
#define STATUS_GROUP_B_SIZE        6
 | 
			
		||||
#define STATUS_GROUP_C_SIZE        6
 | 
			
		||||
#define STATUS_GROUP_D_SIZE        6
 | 
			
		||||
#define STATUS_GROUP_E_SIZE        6
 | 
			
		||||
#define COMM_GROUP_SIZE            6
 | 
			
		||||
#define S_CONTROL_GROUP_SIZE       6
 | 
			
		||||
#define PWM_GROUP_SIZE             6
 | 
			
		||||
#define PWM_S_CONTROL_GROUP_B_SIZE 6
 | 
			
		||||
 | 
			
		||||
#define CFG_GROUP_A_ID 1
 | 
			
		||||
#define CFG_GROUP_B_ID 2
 | 
			
		||||
#define CV_GROUP_A_ID  3
 | 
			
		||||
#define CV_GROUP_B_ID  4
 | 
			
		||||
#define CV_GROUP_C_ID  5
 | 
			
		||||
#define CV_GROUP_D_ID  6
 | 
			
		||||
#define CV_GROUP_E_ID  7
 | 
			
		||||
#define CV_GROUP_F_ID  8
 | 
			
		||||
 | 
			
		||||
#define AUX_GROUP_A_ID 9
 | 
			
		||||
#define AUX_GROUP_B_ID 10
 | 
			
		||||
#define AUX_GROUP_C_ID 11
 | 
			
		||||
#define AUX_GROUP_D_ID 12
 | 
			
		||||
 | 
			
		||||
#define STATUS_GROUP_A_ID        13
 | 
			
		||||
#define STATUS_GROUP_B_ID        14
 | 
			
		||||
#define COMM_GROUP_ID            15
 | 
			
		||||
#define S_CONTROL_GROUP_ID       16
 | 
			
		||||
#define PWM_GROUP_ID             17
 | 
			
		||||
#define PWM_S_CONTROL_GROUP_B_ID 18
 | 
			
		||||
 | 
			
		||||
#endif /* INC_ADBMS_CMD_MAKROS_H_ */
 | 
			
		||||
							
								
								
									
										44
									
								
								Core/Inc/ADBMS_LL_Driver.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								Core/Inc/ADBMS_LL_Driver.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,44 @@
 | 
			
		||||
/*
 | 
			
		||||
 * ADBMS_LL_Driver.h
 | 
			
		||||
 *
 | 
			
		||||
 *  Created on: 05.06.2022
 | 
			
		||||
 *      Author: max
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#ifndef ADBMS_LL_DRIVER_H_
 | 
			
		||||
#define ADBMS_LL_DRIVER_H_
 | 
			
		||||
 | 
			
		||||
#define TARGET_STM32
 | 
			
		||||
 | 
			
		||||
#include "main.h"
 | 
			
		||||
 | 
			
		||||
#ifdef TARGET_STM32
 | 
			
		||||
typedef uint8_t uint8;
 | 
			
		||||
typedef uint16_t uint16;
 | 
			
		||||
typedef uint32_t uint32;
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
uint8 adbmsDriverInit(SPI_HandleTypeDef* hspi);
 | 
			
		||||
uint8 calculateCommandPEC(uint8* data, uint8 datalen);
 | 
			
		||||
uint16 updateCommandPEC(uint16 currentPEC, uint8 din);
 | 
			
		||||
uint8 checkCommandPEC(uint8* data, uint8 datalen);
 | 
			
		||||
 | 
			
		||||
uint8 calculateDataPEC(uint8* data, uint8 datalen);
 | 
			
		||||
uint16 updateDataPEC(uint16 currentPEC, uint8 din);
 | 
			
		||||
uint8 checkDataPEC(uint8* data, uint8 datalen);
 | 
			
		||||
 | 
			
		||||
uint8 writeCMD(uint16 command, uint8* args, uint8 arglen);
 | 
			
		||||
uint8 readCMD(uint16 command, uint8* buffer, uint8 buflen);
 | 
			
		||||
uint8 pollCMD(uint16 command);
 | 
			
		||||
 | 
			
		||||
void mcuAdbmsCSLow();
 | 
			
		||||
void mcuAdbmsCSHigh();
 | 
			
		||||
 | 
			
		||||
uint8 mcuSPITransmit(uint8* buffer, uint8 buffersize);
 | 
			
		||||
uint8 mcuSPIReceive(uint8* buffer, uint8 buffersize);
 | 
			
		||||
uint8 mcuSPITransmitReceive(uint8* rxbuffer, uint8* txbuffer, uint8 buffersize);
 | 
			
		||||
 | 
			
		||||
uint8 wakeUpCmd();
 | 
			
		||||
void mcuDelay(uint16 delay);
 | 
			
		||||
 | 
			
		||||
#endif /* ADBMS_LL_DRIVER_H_ */
 | 
			
		||||
							
								
								
									
										36
									
								
								Core/Inc/AMS_CAN.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								Core/Inc/AMS_CAN.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,36 @@
 | 
			
		||||
/*
 | 
			
		||||
 * AMS_CAN.h
 | 
			
		||||
 *
 | 
			
		||||
 *  Created on: Mar 19, 2022
 | 
			
		||||
 *      Author: jasper
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#ifndef INC_AMS_CAN_H_
 | 
			
		||||
#define INC_AMS_CAN_H_
 | 
			
		||||
 | 
			
		||||
#include "main.h"
 | 
			
		||||
 | 
			
		||||
#include "stm32f3xx_hal.h"
 | 
			
		||||
#include "stm32f3xx_hal_can.h"
 | 
			
		||||
#include "stm32f3xx_hal_def.h"
 | 
			
		||||
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
 | 
			
		||||
void ams_can_init(CAN_HandleTypeDef* hcan);
 | 
			
		||||
 | 
			
		||||
void ams_can_handle_ams_msg(CAN_RxHeaderTypeDef* header, uint8_t* data);
 | 
			
		||||
 | 
			
		||||
void ams_can_send_status();
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Send an AMS Error via CAN.
 | 
			
		||||
 *
 | 
			
		||||
 * Data is taken from error_data
 | 
			
		||||
 */
 | 
			
		||||
void ams_can_send_error();
 | 
			
		||||
 | 
			
		||||
HAL_StatusTypeDef ams_can_wait_for_free_mailboxes(CAN_HandleTypeDef* handle,
 | 
			
		||||
                                                  int num_mailboxes,
 | 
			
		||||
                                                  uint32_t timeout);
 | 
			
		||||
void ams_can_send_log();
 | 
			
		||||
 | 
			
		||||
#endif /* INC_AMS_CAN_H_ */
 | 
			
		||||
							
								
								
									
										52
									
								
								Core/Inc/AMS_HighLevel.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										52
									
								
								Core/Inc/AMS_HighLevel.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,52 @@
 | 
			
		||||
/*
 | 
			
		||||
 * AMS_HighLevel.h
 | 
			
		||||
 *
 | 
			
		||||
 *  Created on: 20.07.2022
 | 
			
		||||
 *      Author: max
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#ifndef INC_AMS_HIGHLEVEL_H_
 | 
			
		||||
#define INC_AMS_HIGHLEVEL_H_
 | 
			
		||||
 | 
			
		||||
#include "ADBMS_Abstraction.h"
 | 
			
		||||
#include "ADBMS_CMD_MAKROS.h"
 | 
			
		||||
#include "ADBMS_LL_Driver.h"
 | 
			
		||||
#include "AMS_CAN.h"
 | 
			
		||||
 | 
			
		||||
typedef enum {
 | 
			
		||||
  AMSDEACTIVE,
 | 
			
		||||
  AMSIDLE,
 | 
			
		||||
  AMSCHARGING,
 | 
			
		||||
  AMSIDLEBALANCING,
 | 
			
		||||
  AMSDISCHARGING,
 | 
			
		||||
  AMSWARNING,
 | 
			
		||||
  AMSERROR
 | 
			
		||||
} amsState;
 | 
			
		||||
 | 
			
		||||
extern amsState currentAMSState;
 | 
			
		||||
extern Cell_Module module;
 | 
			
		||||
extern uint32_t balancedCells;
 | 
			
		||||
extern uint8_t BalancingActive;
 | 
			
		||||
extern uint8_t stateofcharge;
 | 
			
		||||
 | 
			
		||||
extern uint8_t amserrorcode;
 | 
			
		||||
extern uint8_t amswarningcode;
 | 
			
		||||
 | 
			
		||||
extern uint8_t numberofCells;
 | 
			
		||||
extern uint8_t numberofAux;
 | 
			
		||||
 | 
			
		||||
void AMS_Init(SPI_HandleTypeDef* hspi);
 | 
			
		||||
void AMS_Loop();
 | 
			
		||||
 | 
			
		||||
uint8_t AMS_Balancing_Loop();
 | 
			
		||||
uint8_t AMS_Idle_Loop();
 | 
			
		||||
uint8_t AMS_Warning_Loop();
 | 
			
		||||
uint8_t AMS_Error_Loop();
 | 
			
		||||
uint8_t AMS_Charging_Loop();
 | 
			
		||||
uint8_t AMS_Discharging_Loop();
 | 
			
		||||
 | 
			
		||||
uint8_t writeWarningLog(uint8_t warningCode);
 | 
			
		||||
uint8_t writeErrorLog(uint8_t errorCode);
 | 
			
		||||
uint8_t integrateCurrent();
 | 
			
		||||
 | 
			
		||||
#endif /* INC_AMS_HIGHLEVEL_H_ */
 | 
			
		||||
							
								
								
									
										18
									
								
								Core/Inc/TMP1075.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								Core/Inc/TMP1075.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,18 @@
 | 
			
		||||
#ifndef INC_TMP1075_H_
 | 
			
		||||
#define INC_TMP1075_H_
 | 
			
		||||
 | 
			
		||||
#include "AMS_CAN.h"
 | 
			
		||||
#include "common_defs.h"
 | 
			
		||||
#include "stm32f3xx_hal.h"
 | 
			
		||||
#include "stm32f3xx_hal_def.h"
 | 
			
		||||
#include "stm32f3xx_hal_i2c.h"
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
 | 
			
		||||
extern uint32_t tmp1075_failed_sensors;
 | 
			
		||||
extern int16_t tmp1075_temps[N_TEMP_SENSORS];
 | 
			
		||||
HAL_StatusTypeDef tmp1075_init(I2C_HandleTypeDef* hi2c);
 | 
			
		||||
HAL_StatusTypeDef tmp1075_measure();
 | 
			
		||||
HAL_StatusTypeDef tmp1075_sensor_init(int n);
 | 
			
		||||
HAL_StatusTypeDef tmp1075_sensor_read(int n, int16_t* res);
 | 
			
		||||
 | 
			
		||||
#endif // INC_TMP1075_H_
 | 
			
		||||
							
								
								
									
										14
									
								
								Core/Inc/common_defs.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								Core/Inc/common_defs.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,14 @@
 | 
			
		||||
/*
 | 
			
		||||
 * common_defs.h
 | 
			
		||||
 *
 | 
			
		||||
 *  Created on: 23 Mar 2022
 | 
			
		||||
 *      Author: Jasper
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#ifndef INC_COMMON_DEFS_H_
 | 
			
		||||
#define INC_COMMON_DEFS_H_
 | 
			
		||||
 | 
			
		||||
#define N_CELLS        14
 | 
			
		||||
#define N_TEMP_SENSORS 14
 | 
			
		||||
 | 
			
		||||
#endif /* INC_COMMON_DEFS_H_ */
 | 
			
		||||
							
								
								
									
										17
									
								
								Core/Inc/eeprom.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								Core/Inc/eeprom.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,17 @@
 | 
			
		||||
#ifndef INC_EEPROM_H_
 | 
			
		||||
#define INC_EEPROM_H_
 | 
			
		||||
 | 
			
		||||
#include "stm32f3xx_hal.h"
 | 
			
		||||
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
 | 
			
		||||
__attribute__((packed)) typedef struct {
 | 
			
		||||
  uint8_t id;
 | 
			
		||||
} EEPROMConfig;
 | 
			
		||||
 | 
			
		||||
extern EEPROMConfig eeprom_config;
 | 
			
		||||
 | 
			
		||||
void eeprom_init(I2C_HandleTypeDef* hi2c);
 | 
			
		||||
void eeprom_config_save();
 | 
			
		||||
 | 
			
		||||
#endif // INC_EEPROM_H_
 | 
			
		||||
							
								
								
									
										41
									
								
								Core/Inc/errors.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								Core/Inc/errors.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,41 @@
 | 
			
		||||
#ifndef INC_ERRORS_H
 | 
			
		||||
#define INC_ERRORS_H
 | 
			
		||||
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
 | 
			
		||||
#define ERROR_SOURCE_VOLTAGES                     (1 << 0)
 | 
			
		||||
#define ERROR_SOURCE_TEMPERATURES                 (1 << 1)
 | 
			
		||||
#define ERROR_SOURCE_TOO_FEW_WORKING_TEMP_SENSORS (1 << 2)
 | 
			
		||||
#define ERROR_SOURCE_OPEN_CELL_CONNECTION         (1 << 3)
 | 
			
		||||
#define ERROR_SOURCE_EEPROM                       (1 << 4)
 | 
			
		||||
#define ERROR_SOURCE_INTERNAL                     (1 << 5)
 | 
			
		||||
 | 
			
		||||
#define ERROR_TIME_THRESH 150 // ms
 | 
			
		||||
 | 
			
		||||
typedef enum {
 | 
			
		||||
  SEK_OVERTEMP = 0x0,
 | 
			
		||||
  SEK_UNDERTEMP = 0x1,
 | 
			
		||||
  SEK_OVERVOLT = 0x2,
 | 
			
		||||
  SEK_UNDERVOLT = 0x3,
 | 
			
		||||
  SEK_TOO_FEW_TEMPS = 0x4,
 | 
			
		||||
  SEK_OPENWIRE = 0x5,
 | 
			
		||||
  SEK_EEPROM_ERR = 0x6,
 | 
			
		||||
  SEK_INTERNAL_BMS_TIMEOUT = 0x7,
 | 
			
		||||
  SEK_INTERNAL_BMS_CHECKSUM_FAIL = 0x8,
 | 
			
		||||
  SEK_INTERNAL_BMS_OVERTEMP = 0x9,
 | 
			
		||||
  SEK_INTERNAL_BMS_FAULT = 0xA,
 | 
			
		||||
} SlaveErrorKind;
 | 
			
		||||
 | 
			
		||||
typedef struct {
 | 
			
		||||
  int error_sources;
 | 
			
		||||
  SlaveErrorKind data_kind;
 | 
			
		||||
  uint8_t data[4];
 | 
			
		||||
  uint32_t errors_since;
 | 
			
		||||
} SlaveErrorData;
 | 
			
		||||
 | 
			
		||||
extern SlaveErrorData error_data;
 | 
			
		||||
 | 
			
		||||
void set_error_source(int source);
 | 
			
		||||
void clear_error_source(int source);
 | 
			
		||||
 | 
			
		||||
#endif // INC_ERRORS_H
 | 
			
		||||
		Reference in New Issue
	
	Block a user