PER Firmware
Loading...
Searching...
No Matches
adbms.c File Reference

Primary logic and interface for ADBMS battery management system driver. More...

#include "adbms.h"
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "adbms6380.h"
#include "phal_G4/spi/spi.h"
#include "rtos/rtos.h"
Include dependency graph for adbms.c:

Functions

static void clear_discharging (adbms_bms_t *bms)
 
static void calculate_balance_cells (adbms_bms_t *bms, float min_voltage, float min_delta)
 
static void read_cells (adbms_bms_t *bms)
 
static void read_therms (adbms_bms_t *bms)
 
static bool is_valid_voltage (float voltage)
 
static bool is_valid_temp (float temp)
 
void ADBMS_init (adbms_bms_t *bms, SPI_InitConfig_t *spi_ccw, SPI_InitConfig_t *spi_cw)
 Initialize the ADBMS driver instance and underlying ADBMS6380 device chain.
 
void ADBMS_periodic (adbms_bms_t *bms, float min_voltage_for_balance, float min_delta_for_balance)
 Periodic service routine for connection, measurements, and balancing.
 

Variables

static constexpr uint32_t ADBMS_CHIP_SLEEP_CYCLE_MS = 2'500U
 
static constexpr uint8_t ADBMS_RECOVERY_MAX_ATTEMPTS = 4U
 
static constexpr float ADBMS_CELL_MIN_VALID_V = 1.0f
 
static constexpr float ADBMS_CELL_MAX_VALID_V = 5.0f
 
static constexpr float ADBMS_TEMP_MIN_VALID_C = -20.0f
 
static constexpr float ADBMS_TEMP_MAX_VALID_C = 100.0f
 
static constexpr adbms6380_rega_config_t ADBMS_REGA_CFG
 
static constexpr adbms6380_regb_config_t ADBMS_REGB_CFG
 
static constexpr adbms6380_adcv_config_t ADBMS_ADCV_CFG
 
static constexpr adbms6380_adax_config_t ADBMS_ADAX_CFG
 

Detailed Description

Primary logic and interface for ADBMS battery management system driver.

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

Function Documentation

◆ ADBMS_init()

void ADBMS_init ( adbms_bms_t * bms,
SPI_InitConfig_t * spi_ccw,
SPI_InitConfig_t * spi_cw )

Initialize the ADBMS driver instance and underlying ADBMS6380 device chain.

Sets the driver state to CONNECTING, clears discharge and error flags, deasserts CS on both SPI ports, and configures the internal SPI TX/RX buffers.

Parameters
bmsNon-null pointer to driver 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:

◆ ADBMS_periodic()

void ADBMS_periodic ( adbms_bms_t * bms,
float min_voltage_for_balance,
float min_delta_for_balance )

Periodic service routine for connection, measurements, and balancing.

Parameters
bmsNon-null pointer to driver state.
min_voltage_for_balanceMinimum pack voltage required to allow balancing.
min_delta_for_balanceVoltage delta above minimum to start discharging.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ calculate_balance_cells()

static void calculate_balance_cells ( adbms_bms_t * bms,
float min_voltage,
float min_delta )
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ clear_discharging()

static void clear_discharging ( adbms_bms_t * bms)
static
Here is the caller graph for this function:

◆ is_valid_temp()

static bool is_valid_temp ( float temp)
static
Here is the caller graph for this function:

◆ is_valid_voltage()

static bool is_valid_voltage ( float voltage)
static
Here is the caller graph for this function:

◆ read_cells()

static void read_cells ( adbms_bms_t * bms)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_therms()

static void read_therms ( adbms_bms_t * bms)
static
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ ADBMS_ADAX_CFG

adbms6380_adax_config_t ADBMS_ADAX_CFG
staticconstexpr
Initial value:
= {
.ch = 0b00000U,
.ow = false,
.pup = false,
}

◆ ADBMS_ADCV_CFG

adbms6380_adcv_config_t ADBMS_ADCV_CFG
staticconstexpr
Initial value:
= {
.ow = 0b00U,
.rd = false,
.cont = true,
.dcp = false,
.rstf = true,
}

◆ ADBMS_CELL_MAX_VALID_V

float ADBMS_CELL_MAX_VALID_V = 5.0f
staticconstexpr

◆ ADBMS_CELL_MIN_VALID_V

float ADBMS_CELL_MIN_VALID_V = 1.0f
staticconstexpr

◆ ADBMS_CHIP_SLEEP_CYCLE_MS

uint32_t ADBMS_CHIP_SLEEP_CYCLE_MS = 2'500U
staticconstexpr

◆ ADBMS_RECOVERY_MAX_ATTEMPTS

uint8_t ADBMS_RECOVERY_MAX_ATTEMPTS = 4U
staticconstexpr

◆ ADBMS_REGA_CFG

adbms6380_rega_config_t ADBMS_REGA_CFG
staticconstexpr
Initial value:
= {
.cth = 0b110U,
.refon = true,
}

◆ ADBMS_REGB_CFG

adbms6380_regb_config_t ADBMS_REGB_CFG
staticconstexpr
Initial value:
= {
.overvoltage_threshold_v = 4.2f,
.undervoltage_threshold_v = 3.0f,
}

◆ ADBMS_TEMP_MAX_VALID_C

float ADBMS_TEMP_MAX_VALID_C = 100.0f
staticconstexpr

◆ ADBMS_TEMP_MIN_VALID_C

float ADBMS_TEMP_MIN_VALID_C = -20.0f
staticconstexpr