PER Firmware
Loading...
Searching...
No Matches
adbms6380.h File Reference

Low level BMS driver specific to ADBMS6380 chip. More...

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "adbms_config.h"
#include "phal_G4/spi/spi.h"
#include "strbuf/strbuf.h"
Include dependency graph for adbms6380.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  adbms6380_rega_config_t
 Configuration parameters for the CFGA register group. More...
 
struct  adbms6380_regb_config_t
 Configuration parameters for the CFGB register group. More...
 
struct  adbms6380_adcv_config_t
 Configuration parameters for the ADCV command. More...
 
struct  adbms6380_adax_config_t
 Configuration parameters for the ADAX (aux) command. More...
 
struct  adbms6380_chip_t
 Per-chip device-level measurements, register cache, and mismatch flags. More...
 
struct  adbms6380_t
 Daisy-chain ADBMS6380 device driver state, SPI transports, buffers, and error flags. More...
 

Functions

void ADBMS6380_init (adbms6380_t *dev, SPI_InitConfig_t *spi_ccw, SPI_InitConfig_t *spi_cw)
 Initialize the ADBMS6380 device driver instance, SPI buffers, and CS lines.
 
void ADBMS6380_wake (adbms6380_t *dev)
 Wake the daisy-chained set of ADBMS6380 devices.
 
void ADBMS6380_write_rega (adbms6380_t *dev, const adbms6380_rega_config_t *cfg)
 Encode and write REGA configuration to all chips in the daisy chain.
 
bool ADBMS6380_verify_rega (adbms6380_t *dev)
 Discover the active CCW/CW split point, read back REGA from all chips, and compare with cached configuration.
 
void ADBMS6380_write_regb (adbms6380_t *dev, const adbms6380_regb_config_t *cfg)
 Encode and write REGB configuration (OV/UV thresholds + discharge bits) to all chips.
 
bool ADBMS6380_verify_regb (adbms6380_t *dev)
 Read back REGB from all chips and compare with cached configuration.
 
bool ADBMS6380_has_rega_mismatch (const adbms6380_t *dev)
 Check whether any chip in the chain has a REGA mismatch error.
 
bool ADBMS6380_has_regb_mismatch (const adbms6380_t *dev)
 Check whether any chip in the chain has a REGB mismatch error.
 
void ADBMS6380_start_adcv (adbms6380_t *dev, const adbms6380_adcv_config_t *cfg)
 Issue the ADCV command to start cell voltage conversions across all chips.
 
void ADBMS6380_start_adax (adbms6380_t *dev, const adbms6380_adax_config_t *cfg)
 Issue the ADAX command to start GPIO/aux voltage conversions across all chips.
 
void ADBMS6380_read_cell_voltages (adbms6380_t *dev)
 Read all cell voltages from each chip.
 
void ADBMS6380_read_gpio_voltages (adbms6380_t *dev)
 Read all GPIO/aux voltages from each chip.
 
void ADBMS6380_read_temperatures (adbms6380_t *dev, const adbms6380_adax_config_t *cfg)
 Read all GPIO voltages, start the next ADAX conversion, and convert to cell and onboard temperatures.
 

Variables

static constexpr size_t ADBMS6380_CELL_COUNT = 16U
 
static constexpr size_t ADBMS6380_GPIO_COUNT = 10U
 
static constexpr uint32_t ADBMS6380_ADAX_ALL_CONV_TIME_MS = 20U
 
static constexpr size_t ADBMS6380_PEC_SIZE = 2U
 
static constexpr size_t ADBMS6380_COMMAND_RAW_SIZE = 2U
 
static constexpr size_t ADBMS6380_COMMAND_PKT_SIZE = ADBMS6380_COMMAND_RAW_SIZE + ADBMS6380_PEC_SIZE
 
static constexpr size_t ADBMS6380_SINGLE_DATA_RAW_SIZE = 6U
 
static constexpr size_t ADBMS6380_SINGLE_DATA_PKT_SIZE
 
static constexpr size_t ADBMS6380_RDCV_CMD_COUNT = 6U
 
static constexpr size_t ADBMS6380_RDAUX_CMD_COUNT = 4U
 
static constexpr size_t ADBMS6380_SPI_TX_BUFFER_SIZE
 
static constexpr size_t ADBMS6380_SPI_RX_BUFFER_SIZE
 
static constexpr uint8_t ADBMS6380_NO_BREAK_INDEX = 0x0FU
 

Detailed Description

Low level BMS driver specific to ADBMS6380 chip.

Author
Millan Kumar (kumar.nosp@m.798@.nosp@m.purdu.nosp@m.e.ed.nosp@m.u)

Function Documentation

◆ ADBMS6380_has_rega_mismatch()

bool ADBMS6380_has_rega_mismatch ( const adbms6380_t * dev)

Check whether any chip in the chain has a REGA mismatch error.

Parameters
devNon-null pointer to device state.
Returns
true if any chip has adbms6380_chip_t::err_rega_mismatch set.
Here is the caller graph for this function:

◆ ADBMS6380_has_regb_mismatch()

bool ADBMS6380_has_regb_mismatch ( const adbms6380_t * dev)

Check whether any chip in the chain has a REGB mismatch error.

Parameters
devNon-null pointer to device state.
Returns
true if any chip has adbms6380_chip_t::err_regb_mismatch set.
Here is the caller graph for this function:

◆ ADBMS6380_init()

void ADBMS6380_init ( adbms6380_t * dev,
SPI_InitConfig_t * spi_ccw,
SPI_InitConfig_t * spi_cw )

Initialize the ADBMS6380 device driver instance, SPI buffers, and CS lines.

Deasserts both CS lines high, initializes the internal TX strbuf, and clears discharge and error flags across all chips.

Parameters
devNon-null pointer to device state to initialize.
spi_ccwNon-null CCW SPI configuration.
spi_cwNon-null CW SPI configuration.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ADBMS6380_read_cell_voltages()

void ADBMS6380_read_cell_voltages ( adbms6380_t * dev)

Read all cell voltages from each chip.

Converts raw values to volts and populates each chip's cell_voltages array. If any command fails with a PEC error after retries, the successfully read cell voltages are still updated and the corresponding flag in err_cell_voltage_pecs is set.

Parameters
devNon-null pointer to device state.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ADBMS6380_read_gpio_voltages()

void ADBMS6380_read_gpio_voltages ( adbms6380_t * dev)

Read all GPIO/aux voltages from each chip.

Converts raw values to volts and populates each chip's gpio_voltages array. If any command fails with a PEC error after retries, the successfully read GPIO voltages are still updated and the corresponding flag in err_gpio_voltage_pecs is set.

Parameters
devNon-null pointer to device state.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ADBMS6380_read_temperatures()

void ADBMS6380_read_temperatures ( adbms6380_t * dev,
const adbms6380_adax_config_t * cfg )

Read all GPIO voltages, start the next ADAX conversion, and convert to cell and onboard temperatures.

Populates each chip's gpio_voltages, cell_temps, and board_temp fields.

Parameters
devNon-null pointer to device state.
cfgNon-null pointer to ADAX command parameters.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ADBMS6380_start_adax()

void ADBMS6380_start_adax ( adbms6380_t * dev,
const adbms6380_adax_config_t * cfg )

Issue the ADAX command to start GPIO/aux voltage conversions across all chips.

Parameters
devNon-null pointer to device state.
cfgNon-null pointer to ADAX command parameters.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ADBMS6380_start_adcv()

void ADBMS6380_start_adcv ( adbms6380_t * dev,
const adbms6380_adcv_config_t * cfg )

Issue the ADCV command to start cell voltage conversions across all chips.

Parameters
devNon-null pointer to device state.
cfgNon-null pointer to ADCV command parameters.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ADBMS6380_verify_rega()

bool ADBMS6380_verify_rega ( adbms6380_t * dev)

Discover the active CCW/CW split point, read back REGA from all chips, and compare with cached configuration.

Sets per-chip mismatch or PEC flags when the read-back fails or does not match the cached REGA data.

Parameters
devNon-null pointer to device state.
Returns
false on PEC error or when there is a mismatch; true otherwise.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ADBMS6380_verify_regb()

bool ADBMS6380_verify_regb ( adbms6380_t * dev)

Read back REGB from all chips and compare with cached configuration.

Sets per-chip mismatch or PEC flags when the read-back fails or does not match the cached REGB data.

Parameters
devNon-null pointer to device state.
Returns
false on PEC error or when there is a mismatch; true otherwise.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ADBMS6380_wake()

void ADBMS6380_wake ( adbms6380_t * dev)

Wake the daisy-chained set of ADBMS6380 devices.

Toggles CS with blocking delay to bring each chip out of sleep/idle. If the harness break is already known, wakes only the reachable chips in each direction.

Parameters
devNon-null pointer to device state.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ADBMS6380_write_rega()

void ADBMS6380_write_rega ( adbms6380_t * dev,
const adbms6380_rega_config_t * cfg )

Encode and write REGA configuration to all chips in the daisy chain.

Parameters
devNon-null pointer to device state.
cfgNon-null pointer to REGA configuration parameters.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ADBMS6380_write_regb()

void ADBMS6380_write_regb ( adbms6380_t * dev,
const adbms6380_regb_config_t * cfg )

Encode and write REGB configuration (OV/UV thresholds + discharge bits) to all chips.

Parameters
devNon-null pointer to device state.
cfgNon-null pointer to REGB configuration parameters.
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ ADBMS6380_ADAX_ALL_CONV_TIME_MS

uint32_t ADBMS6380_ADAX_ALL_CONV_TIME_MS = 20U
staticconstexpr

◆ ADBMS6380_CELL_COUNT

size_t ADBMS6380_CELL_COUNT = 16U
staticconstexpr

◆ ADBMS6380_COMMAND_PKT_SIZE

size_t ADBMS6380_COMMAND_PKT_SIZE = ADBMS6380_COMMAND_RAW_SIZE + ADBMS6380_PEC_SIZE
staticconstexpr

◆ ADBMS6380_COMMAND_RAW_SIZE

size_t ADBMS6380_COMMAND_RAW_SIZE = 2U
staticconstexpr

◆ ADBMS6380_GPIO_COUNT

size_t ADBMS6380_GPIO_COUNT = 10U
staticconstexpr

◆ ADBMS6380_NO_BREAK_INDEX

uint8_t ADBMS6380_NO_BREAK_INDEX = 0x0FU
staticconstexpr

◆ ADBMS6380_PEC_SIZE

size_t ADBMS6380_PEC_SIZE = 2U
staticconstexpr

◆ ADBMS6380_RDAUX_CMD_COUNT

size_t ADBMS6380_RDAUX_CMD_COUNT = 4U
staticconstexpr

◆ ADBMS6380_RDCV_CMD_COUNT

size_t ADBMS6380_RDCV_CMD_COUNT = 6U
staticconstexpr

◆ ADBMS6380_SINGLE_DATA_PKT_SIZE

size_t ADBMS6380_SINGLE_DATA_PKT_SIZE
staticconstexpr
Initial value:
=
static constexpr size_t ADBMS6380_SINGLE_DATA_RAW_SIZE
Definition adbms6380.h:38
static constexpr size_t ADBMS6380_PEC_SIZE
Definition adbms6380.h:32

◆ ADBMS6380_SINGLE_DATA_RAW_SIZE

size_t ADBMS6380_SINGLE_DATA_RAW_SIZE = 6U
staticconstexpr

◆ ADBMS6380_SPI_RX_BUFFER_SIZE

size_t ADBMS6380_SPI_RX_BUFFER_SIZE
staticconstexpr
Initial value:
=
static constexpr size_t ADBMS6380_SINGLE_DATA_PKT_SIZE
Definition adbms6380.h:40
static constexpr size_t ADBMS_CHIP_COUNT
Definition adbms_config.h:20

◆ ADBMS6380_SPI_TX_BUFFER_SIZE

size_t ADBMS6380_SPI_TX_BUFFER_SIZE
staticconstexpr
Initial value:
=
static constexpr size_t ADBMS6380_COMMAND_PKT_SIZE
Definition adbms6380.h:36