|
PER Firmware
|
Low level BMS driver specific to ADBMS6380 chip. More...
#include "adbms6380.h"#include <stdbool.h>#include <stddef.h>#include <stdint.h>#include <string.h>#include "commands.h"#include "phal_G4/gpio/gpio.h"#include "phal_G4/spi/spi.h"#include "rtos/rtos.h"#include "utils/countof.h"#include "pec.h"#include "thermistor.h"Functions | |
| static void | set_cs_low (SPI_InitConfig_t *spi) |
| static void | set_cs_high (SPI_InitConfig_t *spi) |
| static void | wake_spi (SPI_InitConfig_t *spi, size_t pulse_count) |
| static void | transfer_tx_spi (adbms6380_t *dev, SPI_InitConfig_t *spi) |
| static void | transfer_tx (adbms6380_t *dev) |
| static uint16_t | get_threshold_voltage_cfg (float threshold_voltage_v) |
| static int16_t | extract_i16 (const uint8_t *data, size_t idx) |
| static float | raw_to_v (int16_t raw) |
| static void | encode_adcv (uint8_t output_cmd[ADBMS6380_COMMAND_RAW_SIZE], const adbms6380_adcv_config_t *cfg) |
| static void | encode_adax (uint8_t output_cmd[ADBMS6380_COMMAND_RAW_SIZE], const adbms6380_adax_config_t *cfg) |
| static void | prepare_command (strbuf_t *output_buffer, const uint8_t command[ADBMS6380_COMMAND_RAW_SIZE]) |
| static void | prepare_data_packet (strbuf_t *output_buffer, const uint8_t data[ADBMS6380_SINGLE_DATA_RAW_SIZE]) |
| static void | pack_cfg_rega (uint8_t output_cfg_rega[ADBMS6380_SINGLE_DATA_RAW_SIZE], const adbms6380_rega_config_t *cfg) |
| static void | pack_cfg_regb (uint8_t output_cfg_regb[ADBMS6380_SINGLE_DATA_RAW_SIZE], const adbms6380_regb_config_t *cfg, const bool is_discharging[ADBMS6380_CELL_COUNT]) |
| static bool | check_data_pec (const uint8_t *rx_bytes, size_t rx_len) |
| static void | read_spi_packets (adbms6380_t *dev, SPI_InitConfig_t *spi, uint8_t *rx_dest, size_t rx_length) |
| static bool | read_response (adbms6380_t *dev, size_t rx_length_per_chip) |
| static bool | read_data_with_retries (adbms6380_t *dev) |
| static void | write_rega_spi (adbms6380_t *dev, SPI_InitConfig_t *spi) |
| static void | discover_ccw_chip_count (adbms6380_t *dev) |
| 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. | |
| static float | gpio_v_to_r2 (float v_out) |
| 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_PEC_FAIL_MAX_RETRIES = 3U |
| static constexpr uint32_t | ADBMS6380_WAKE_DELAY_MS = 1U |
| static constexpr uint32_t | ADBMS6380_PORT_REVERSE_DELAY_MS = 2U |
| static constexpr float | ADBMS6380_GPIO_R1_OHM = 10'000.0f |
| static constexpr float | ADBMS6380_GPIO_VIN_V = 3.0f |
| static constexpr float | ADBMS6380_DIVIDER_EPSILON_V = 0.00001f |
| static constexpr float | ADBMS6380_VOLTAGE_OFFSET_V = 1.5f |
| static constexpr float | ADBMS6380_ADC_LSB_V = 0.000150f |
| static constexpr float | ADBMS6380_THRESHOLD_SCALE = 16.0f |
| static constexpr int32_t | ADBMS6380_RAW_OFFSET_CODES = 10'000 |
| static constexpr uint8_t | ADBMS6380_THRESHOLD_BITS = 12U |
| static constexpr uint16_t | ADBMS6380_THRESHOLD_MASK = 0x0FFFU |
| static const uint8_t *const | RDCV_CMDS [] |
| static const uint8_t *const | RDAUX_CMDS [] |
Low level BMS driver specific to ADBMS6380 chip.
| bool ADBMS6380_has_rega_mismatch | ( | const adbms6380_t * | dev | ) |
Check whether any chip in the chain has a REGA mismatch error.
| dev | Non-null pointer to device state. |
| bool ADBMS6380_has_regb_mismatch | ( | const adbms6380_t * | dev | ) |
Check whether any chip in the chain has a REGB mismatch error.
| dev | Non-null pointer to device state. |
| 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.
| dev | Non-null pointer to device state to initialize. |
| spi_ccw | Non-null CCW SPI configuration. |
| spi_cw | Non-null CW SPI configuration. |
| 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.
| dev | Non-null pointer to device state. |
| 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.
| dev | Non-null pointer to device state. |
| 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.
| dev | Non-null pointer to device state. |
| cfg | Non-null pointer to ADAX command parameters. |
| 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.
| dev | Non-null pointer to device state. |
| cfg | Non-null pointer to ADAX command parameters. |
| 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.
| dev | Non-null pointer to device state. |
| cfg | Non-null pointer to ADCV command parameters. |
| 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.
| dev | Non-null pointer to device state. |
| 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.
| dev | Non-null pointer to device state. |
| 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.
| dev | Non-null pointer to device state. |
| 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.
| dev | Non-null pointer to device state. |
| cfg | Non-null pointer to REGA configuration parameters. |
| 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.
| dev | Non-null pointer to device state. |
| cfg | Non-null pointer to REGB configuration parameters. |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
static |
|
static |