|
PER Firmware
|
Primary logic and interface for ADBMS battery management system driver. More...
#include "adbms.h"#include <stdbool.h>#include <stddef.h>#include <stdint.h>#include <string.h>#include "adbms6380.h"#include "commands.h"#include "common/phal/spi.h"#include "common/strbuf/strbuf.h"#include "thermistor.h"Functions | |
| void | adbms_init (adbms_bms_t *bms, SPI_InitConfig_t *spi, uint8_t *tx_buf) |
| Initialize the ADBMS driver instance and TX buffer. | |
| bool | adbms_write_rega (adbms_bms_t *bms) |
| Calculate and write REGA configuration to all modules. | |
| bool | adbms_write_regb (adbms_bms_t *bms) |
| Calculate and write REGB configuration to all modules. | |
| bool | adbms_read_and_check_rega (adbms_bms_t *bms) |
| Read back REGA and compare with cached configuration. | |
| bool | adbms_read_and_check_regb (adbms_bms_t *bms) |
| Read back REGB and compare with cached configuration. | |
| void | adbms_connect (adbms_bms_t *bms) |
| Perform the connect/bring-up sequence for all modules. | |
| void | adbms_calculate_balance_cells (adbms_bms_t *bms, float min_voltage, float min_delta) |
| Compute per-cell discharge flags based on pack voltage spread. | |
| void | adbms_balance_and_update_regb (adbms_bms_t *bms, float min_voltage, float min_delta) |
| Compute discharge flags and write REGB to apply balancing. | |
| void | adbms_read_cells (adbms_bms_t *bms) |
| Read all cell voltages and update module/pack statistics. | |
| void | adbms_read_therms (adbms_bms_t *bms) |
| Read all GPIO/thermistor values (voltage and calculate temperature) and update module/pack statistics. | |
| 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. | |
Primary logic and interface for ADBMS battery management system driver.
| void adbms_balance_and_update_regb | ( | adbms_bms_t * | bms, |
| float | min_voltage, | ||
| float | min_delta ) |
Compute discharge flags and write REGB to apply balancing.
Calls adbms_calculate_balance_cells(), writes REGB, and verifies it.
| bms | Pointer to driver state. |
| min_voltage | Minimum pack voltage required to allow balancing. |
| min_delta | Voltage delta above minimum to start discharging. |
| void adbms_calculate_balance_cells | ( | adbms_bms_t * | bms, |
| float | min_voltage, | ||
| float | min_delta ) |
Compute per-cell discharge flags based on pack voltage spread.
If balancing is disabled, clears all discharge flags. If the pack minimum voltage is below min_voltage, no balancing occurs. Otherwise, discharges cells above (min + delta).
| bms | Pointer to driver state. |
| min_voltage | Minimum pack voltage required to allow balancing. |
| min_delta | Voltage delta above minimum to start discharging. |
| void adbms_connect | ( | adbms_bms_t * | bms | ) |
Perform the connect/bring-up sequence for all modules.
Writes REGA/REGB, verifies read-back, and starts ADCV conversions.
| bms | Pointer to driver state. |
| void adbms_init | ( | adbms_bms_t * | bms, |
| SPI_InitConfig_t * | spi, | ||
| uint8_t * | tx_buf ) |
Initialize the ADBMS driver instance and TX buffer.
Sets the driver state to idle, clears discharge flags (and discharged enabled), and sets the provided SPI config and TX buffer into the internal strbuf.
| bms | Pointer to driver state to initialize. |
| spi | SPI configuration used for ADBMS transactions. |
| tx_buf | Backing buffer for TX command/data packets. |
| 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.
If idle, attempts to connect. When connected, reads cells and thermistors, then updates balancing + REGB.
| bms | Pointer to driver state. |
| min_voltage_for_balance | Minimum pack voltage required to allow balancing. |
| min_delta_for_balance | Voltage delta above minimum to start discharging. |
| bool adbms_read_and_check_rega | ( | adbms_bms_t * | bms | ) |
Read back REGA and compare with cached configuration.
Sets per-module and aggregated mismatch flags when the read-back does not match the cached REGA data.
| bms | Pointer to driver state. |
| bool adbms_read_and_check_regb | ( | adbms_bms_t * | bms | ) |
Read back REGB and compare with cached configuration.
Sets per-module and aggregated mismatch flags when the read-back does not match the cached REGB data.
| bms | Pointer to driver state. |
| void adbms_read_cells | ( | adbms_bms_t * | bms | ) |
Read all cell voltages and update module/pack statistics.
Updates per-module min/max/avg/sum and aggregated min/max/avg/sum for the full pack.
| bms | Pointer to driver state. |
| void adbms_read_therms | ( | adbms_bms_t * | bms | ) |
Read all GPIO/thermistor values (voltage and calculate temperature) and update module/pack statistics.
Updates per-module min/max/avg for thermistor temperatures and aggregated min/max/avg for the full pack.
| bms | Pointer to driver state. |
| bool adbms_write_rega | ( | adbms_bms_t * | bms | ) |
Calculate and write REGA configuration to all modules.
| bms | Pointer to driver state. |
| bool adbms_write_regb | ( | adbms_bms_t * | bms | ) |
Calculate and write REGB configuration to all modules.
Computes REGB with OV/UV thresholds and discharge flags, then writes the configuration to all modules.
| bms | Pointer to driver state. |