refactor: move files around, add external interface header file for ADBMS6830 HAL

This commit is contained in:
Kilian Bracher 2025-02-06 20:26:06 +01:00
parent eb2dba0106
commit cd21cc0ff4
Signed by: k.bracher
SSH Key Fingerprint: SHA256:mXpyZkK7RDiJ7qeHCKJX108woM0cl5TrCvNBJASu6lM
9 changed files with 110 additions and 94 deletions

View File

@ -10,59 +10,15 @@
#include "ADBMS_CMD_MAKROS.h"
#include "ADBMS_LL_Driver.h"
#include "ADBMS_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_t CS_FLT : 16; //ADC fault - mismatch between S- and C-ADC
uint16_t : 3;
uint16_t CCTS : 13; //Conversion counter
uint16_t SMED : 1; //S-ADC multiple trim error (uncorrectable)
uint16_t SED : 1; //S-ADC single trim error (correctable)
uint16_t CMED : 1; //C-ADC multiple trim error (uncorrectable)
uint16_t CED : 1; //C-ADC single trim error (correctable)
uint16_t VD_UV : 1; //3V digital supply undervoltage
uint16_t VD_OV : 1; //3V digital supply overvoltage
uint16_t VA_UV : 1; //5V analog supply undervoltage
uint16_t VA_OV : 1; //5V analog supply overvoltage
uint16_t OSCCHK : 1; //Oscillator check
uint16_t TMODCHK : 1; //Test mode check
uint16_t THSD : 1; //Thermal shutdown
uint16_t SLEEP : 1; //Sleep mode previously entered
uint16_t SPIFLT : 1; //SPI fault
uint16_t COMPARE : 1; //Comparasion between S- and C-ADC active
uint16_t VDE : 1; //Supply voltage error
uint16_t VDEL : 1; //Latent supply voltage error
};
typedef struct {
int16_t cellVoltages[MAXIMUM_CELL_VOLTAGES];
int16_t auxVoltages[MAXIMUM_AUX_VOLTAGES];
struct ADBMS6830_Internal_Status status;
uint16_t internalDieTemp;
uint16_t analogSupplyVoltage;
uint16_t digitalSupplyVoltage;
uint16_t sumOfCellMeasurements;
uint16_t refVoltage;
uint16_t GPIO_Values[MAXIMUM_GPIO];
uint32_t overVoltage;
uint32_t underVoltage;
} Cell_Module;
HAL_StatusTypeDef amsReset();
HAL_StatusTypeDef initAMS(SPI_HandleTypeDef* hspi);

View File

@ -0,0 +1,86 @@
#ifndef ADBMS_DRIVER_H
#define ADBMS_DRIVER_H
#include <stdint.h>
#define ERROR_TIME_THRESH 150 // ms
typedef enum {
SEK_OVERTEMP,
SEK_UNDERTEMP,
SEK_OVERVOLT,
SEK_UNDERVOLT,
SEK_TOO_FEW_TEMPS,
SEK_OPENWIRE,
SEK_EEPROM_ERR,
SEK_INTERNAL_BMS_TIMEOUT,
SEK_INTERNAL_BMS_CHECKSUM_FAIL,
SEK_INTERNAL_BMS_OVERTEMP,
SEK_INTERNAL_BMS_FAULT,
SEK_1WIRE_ERR,
SEK_DS18B20_TIMEOUT,
NUM_ERROR_KINDS
} SlaveErrorKind;
typedef struct {
uint8_t data[4];
uint32_t errors_since;
} SlaveErrorData;
struct ADBMS6830_Internal_Status {
uint16_t CS_FLT : 16; //ADC fault - mismatch between S- and C-ADC
uint16_t : 3;
uint16_t CCTS : 13; //Conversion counter
uint16_t SMED : 1; //S-ADC multiple trim error (uncorrectable)
uint16_t SED : 1; //S-ADC single trim error (correctable)
uint16_t CMED : 1; //C-ADC multiple trim error (uncorrectable)
uint16_t CED : 1; //C-ADC single trim error (correctable)
uint16_t VD_UV : 1; //3V digital supply undervoltage
uint16_t VD_OV : 1; //3V digital supply overvoltage
uint16_t VA_UV : 1; //5V analog supply undervoltage
uint16_t VA_OV : 1; //5V analog supply overvoltage
uint16_t OSCCHK : 1; //Oscillator check
uint16_t TMODCHK : 1; //Test mode check
uint16_t THSD : 1; //Thermal shutdown
uint16_t SLEEP : 1; //Sleep mode previously entered
uint16_t SPIFLT : 1; //SPI fault
uint16_t COMPARE : 1; //Comparasion between S- and C-ADC active
uint16_t VDE : 1; //Supply voltage error
uint16_t VDEL : 1; //Latent supply voltage error
};
#define MAXIMUM_CELL_VOLTAGES 16
#define MAXIMUM_AUX_VOLTAGES 10
#define MAXIMUM_GPIO 10
typedef struct {
int16_t cellVoltages[MAXIMUM_CELL_VOLTAGES];
int16_t auxVoltages[MAXIMUM_AUX_VOLTAGES];
struct ADBMS6830_Internal_Status status;
uint16_t internalDieTemp;
uint16_t analogSupplyVoltage;
uint16_t digitalSupplyVoltage;
uint16_t sumOfCellMeasurements;
uint16_t refVoltage;
uint16_t GPIO_Values[MAXIMUM_GPIO];
uint32_t overVoltage;
uint32_t underVoltage;
} Cell_Module;
extern uint32_t error_sources; // Bitfield of error sources
extern SlaveErrorData error_data[NUM_ERROR_KINDS];
[[gnu::nonnull]]
void AMS_Init(SPI_HandleTypeDef* hspi);
uint8_t AMS_Idle_Loop();
#undef MAXIMUM_CELL_VOLTAGES
#undef MAXIMUM_AUX_VOLTAGES
#undef MAXIMUM_GPIO
#endif // ADBMS_DRIVER_H

View File

@ -0,0 +1,18 @@
//
// Created by kbracher on 2/6/25.
//
#ifndef AMS_MASTER_CODE_ADBMS_ERROR_H
#define AMS_MASTER_CODE_ADBMS_ERROR_H
#include "ADBMS_Driver.h"
#include <limits.h>
static_assert(sizeof(error_sources) * CHAR_BIT >= NUM_ERROR_KINDS,
"error_sources is too small to hold all error sources");
void set_error_source(SlaveErrorKind source);
void clear_error_source(SlaveErrorKind source);
#endif //AMS_MASTER_CODE_ADBMS_ERROR_H

View File

@ -32,8 +32,4 @@ extern bool BalancingActive;
extern uint8_t numberofCells;
void AMS_Init(SPI_HandleTypeDef* hspi);
uint8_t AMS_Idle_Loop();
#endif /* INC_AMS_HIGHLEVEL_H_ */

View File

@ -1,41 +0,0 @@
#ifndef INC_ERRORS_H
#define INC_ERRORS_H
#include <limits.h>
#include <stdint.h>
#include <strings.h>
#define ERROR_TIME_THRESH 150 // ms
typedef enum {
SEK_OVERTEMP,
SEK_UNDERTEMP,
SEK_OVERVOLT,
SEK_UNDERVOLT,
SEK_TOO_FEW_TEMPS,
SEK_OPENWIRE,
SEK_EEPROM_ERR,
SEK_INTERNAL_BMS_TIMEOUT,
SEK_INTERNAL_BMS_CHECKSUM_FAIL,
SEK_INTERNAL_BMS_OVERTEMP,
SEK_INTERNAL_BMS_FAULT,
SEK_1WIRE_ERR,
SEK_DS18B20_TIMEOUT,
NUM_ERROR_KINDS
} SlaveErrorKind;
typedef struct {
uint8_t data[4];
uint32_t errors_since;
} SlaveErrorData;
extern uint32_t error_sources; // Bitfield of error sources
extern SlaveErrorData error_data[NUM_ERROR_KINDS];
static_assert(sizeof(error_sources) * CHAR_BIT >= NUM_ERROR_KINDS,
"error_sources is too small to hold all error sources");
void set_error_source(SlaveErrorKind source);
void clear_error_source(SlaveErrorKind source);
#endif // INC_ERRORS_H

View File

@ -390,6 +390,7 @@ HAL_StatusTypeDef amsSendI2C(const uint8_t addresses[static N_BMS], uint8_t * da
return HAL_OK;
}
//Each selected BMS must have a corresponding address, and the data array for that BMS must be at least datalens[i] bytes long
HAL_StatusTypeDef amsReadI2C(const uint8_t addresses[static N_BMS], uint8_t * data[static N_BMS], const uint8_t datalens[static N_BMS], uint32_t bms_mask) {
uint8_t buffer[CMD_BUFFER_SIZE(COMM_GROUP_SIZE)] = {};

View File

@ -1,4 +1,4 @@
#include "errors.h"
#include "ADBMS_Error.h"
#include "stm32h7xx_hal.h"
SlaveErrorData error_data[NUM_ERROR_KINDS] = {};

View File

@ -5,11 +5,11 @@
* Author: max
*/
#include "AMS_HighLevel.h"
#include "ADBMS_HighLevel.h"
#include "ADBMS_Abstraction.h"
#include "ADBMS_LL_Driver.h"
#include "config_ADBMS6830.h"
#include "errors.h"
#include "ADBMS_Driver.h"
#include "stm32h7xx_hal.h"
#include "swo_log.h"
#include <stdint.h>

View File

@ -1,6 +1,6 @@
#include "slave_monitoring.h"
#include "AMS_HighLevel.h"
#include "ADBMS_Driver.h"
#include "can.h"
#include "main.h"
#include "ts_state_machine.h"