![]() |
Midnight Sun Firmware
|
ADBMS1818 library. More...
Classes | |
struct | AdbmsAfeSettings |
Afe Settings Data. More... | |
struct | AdbmsAfeStorage |
Runtime Data Storage. More... | |
struct | _PACKED |
Configuration for the AFE configuration register group A (CFGRA). More... | |
union | AdbmsAfeRegisterData |
Macros | |
#define | _PACKED |
#define | ADBMS_AFE_MAX_DEVICES 3 |
Maximum AFE devices in daisy chain config. More... | |
#define | ADBMS_AFE_MAX_CELLS_PER_DEVICE 18 |
Maximum x of each device. More... | |
#define | ADBMS_AFE_MAX_CELL_THERMISTORS_PER_DEVICE 16 |
#define | ADBMS_AFE_MAX_BOARD_THERMISTORS_PER_DEVICE 1 |
#define | ADBMS_AFE_MAX_CELLS (ADBMS_AFE_MAX_DEVICES * ADBMS_AFE_MAX_CELLS_PER_DEVICE) |
Maximum across all devices. | |
#define | ADBMS_AFE_MAX_CELL_THERMISTORS (ADBMS_AFE_MAX_DEVICES * ADBMS_AFE_MAX_CELL_THERMISTORS_PER_DEVICE) |
#define | ADBMS_AFE_MAX_BOARD_THERMISTORS (ADBMS_AFE_MAX_DEVICES * ADBMS_AFE_MAX_CELL_THERMISTORS_PER_DEVICE) |
#define | _PACKED |
Stores all member variables in a struct without padding. | |
#define | ADBMS1818_CELLS_IN_REG 3 |
Used internally by the ADBMS AFE driver (number of regs per reg group) | |
#define | ADBMS1818_GPIOS_IN_REG 3 |
#define | AUX_ADG731_NUM_PINS 32 |
Used for the external mux (ADG731) connected to the AFE. | |
#define | ADBMS1818_CMD_SIZE 4 |
Size of command code (2 bytes) + PEC (2 bytes) | |
#define | ADBMS1818_NUM_COMM_REG_BYTES 3 |
3 bytes are required to send 24 clock cycles with our SPI driver for the STCOMM command | |
#define | ADBMS1818_NUM_PWMR_REGS 6 |
Number of registers in PWM Register Group. See Table 70 on page 68. | |
#define | ADBMS1818_NUM_PSR_REGS 6 |
Macros for PWM/S control register group B. More... | |
#define | ADBMS1818_NUM_PWM_REGS_IN_PSR 3 |
#define | ADBMS1818_NUM_SCTL_REGS_IN_PSR 3 |
#define | ADBMS1818_NUM_PWMS_REGS 6 |
Number of registers in PWM/S Register Group. See Table 71 on page 68. | |
#define | ADBMS_AFE_MAX_CELLS_PER_DEVICE 18 |
Number of voltage cells connected to each device. | |
#define | ADBMS1818_WRCFGA_RESERVED (1 << 0) |
Command codes for ADBMS1818 AFE. More... | |
#define | ADBMS1818_WRCFGB_RESERVED (1 << 5) | (1 << 2) |
#define | ADBMS1818_RDCFGA_RESERVED (1 << 1) |
#define | ADBMS1818_RDCFGB_RESERVED (1 << 5) | (1 << 2) | (1 << 1) |
#define | ADBMS1818_RDCVA_RESERVED (1 << 2) |
#define | ADBMS1818_RDCVB_RESERVED (1 << 2) | (1 << 1) |
#define | ADBMS1818_RDCVC_RESERVED (1 << 3) |
#define | ADBMS1818_RDCVD_RESERVED (1 << 3) | (1 << 1) |
#define | ADBMS1818_RDCVE_RESERVED (1 << 3) | (1 << 0) |
#define | ADBMS1818_RDCVF_RESERVED (1 << 3) | (1 << 1) | (1 << 0) |
#define | ADBMS1818_RDAUXA_RESERVED ((1 << 3) | (1 << 2)) |
#define | ADBMS1818_RDAUXB_RESERVED ((1 << 3) | (1 << 2)) | (1 << 1) |
#define | ADBMS1818_RDAUXC_RESERVED ((1 << 3) | (1 << 2)) | (1 << 0) |
#define | ADBMS1818_RDAUXD_RESERVED ((1 << 3) | (1 << 2)) | (1 << 1) | (1 << 0) |
#define | ADBMS1818_RDSTATA_RESERVED (1 << 4) |
#define | ADBMS1818_RDSTATB_RESERVED (1 << 4) | (1 << 1) |
#define | ADBMS1818_WRSCTRL_RESERVED (1 << 4) | (1 << 2) |
#define | ADBMS1818_WRPWM_RESERVED (1 << 5) |
#define | ADBMS1818_WRPSB_RESERVED (1 << 4) | (1 << 3) | (1 << 2) |
#define | ADBMS1818_RDSCTRL_RESERVED (1 << 4) | (1 << 2) | (1 << 1) |
#define | ADBMS1818_RDPWM_RESERVED (1 << 5) | (1 << 2) |
#define | ADBMS1818_RDPSB_RESERVED (1 << 4) | (1 << 3) | (1 << 2) | (1 << 1) |
#define | ADBMS1818_STSCTRL_RESERVED (1 << 4) | (1 << 3) | (1 << 0) |
#define | ADBMS1818_CLRSCTRL_RESERVED (1 << 4) | (1 << 3) |
#define | ADBMS1818_ADCV_RESERVED ((1 << 9) | (1 << 6) | (1 << 5)) |
#define | ADBMS1818_ADOW_RESERVED ((1 << 3) | (1 << 5) | (1 << 9)) |
#define | ADBMS1818_CVST_RESERVED ((1 << 0) | (1 << 1) | (1 << 2) | (1 << 9)) |
#define | ADBMS1818_ADAX_RESERVED (1 << 10) | (1 << 6) | (1 << 5) |
#define | ADBMS1818_CLRCELL_RESERVED (1 << 0) | (1 << 4) | (1 << 8) | (1 << 9) | (1 << 10) |
#define | ADBMS1818_CLRAUX_RESERVED (1 << 1) | (1 << 4) | (1 << 8) | (1 << 9) | (1 << 10) |
#define | ADBMS1818_CLRSTAT_RESERVED (1 << 0) | (1 << 1) | (1 << 4) | (1 << 8) | (1 << 9) | (1 << 10) |
#define | ADBMS1818_PLADC_RESERVED (1 << 2) | (1 << 4) | (1 << 8) | (1 << 9) | (1 << 10) |
#define | ADBMS1818_DIAGN_RESERVED (1 << 0) | (1 << 2) | (1 << 4) | (1 << 8) | (1 << 9) | (1 << 10) |
#define | ADBMS1818_WRCOMM_RESERVED (1 << 0) | (1 << 5) | (1 << 8) | (1 << 9) | (1 << 10) |
#define | ADBMS1818_RDCOMM_RESERVED (1 << 1) | (1 << 5) | (1 << 8) | (1 << 9) | (1 << 10) |
#define | ADBMS1818_STCOMM_RESERVED (1 << 0) | (1 << 1) | (1 << 5) | (1 << 8) | (1 << 9) | (1 << 10) |
#define | ADBMS1818_GPIO1_PD_ON (0 << 3) |
GPIO pull-down configuration for the Config Register Group. More... | |
#define | ADBMS1818_GPIO1_PD_OFF (1 << 3) |
#define | ADBMS1818_GPIO2_PD_ON (0 << 4) |
#define | ADBMS1818_GPIO2_PD_OFF (1 << 4) |
#define | ADBMS1818_GPIO3_PD_ON (0 << 5) |
#define | ADBMS1818_GPIO3_PD_OFF (1 << 5) |
#define | ADBMS1818_GPIO4_PD_ON (0 << 6) |
#define | ADBMS1818_GPIO4_PD_OFF (1 << 6) |
#define | ADBMS1818_GPIO5_PD_ON (0 << 7) |
#define | ADBMS1818_GPIO5_PD_OFF (1 << 7) |
#define | ADBMS1818_GPIO6_PD_ON (0 << 0) |
#define | ADBMS1818_GPIO6_PD_OFF (1 << 0) |
#define | ADBMS1818_GPIO7_PD_ON (0 << 1) |
#define | ADBMS1818_GPIO7_PD_OFF (1 << 1) |
#define | ADBMS1818_GPIO8_PD_ON (0 << 2) |
#define | ADBMS1818_GPIO8_PD_OFF (1 << 2) |
#define | ADBMS1818_GPIO9_PD_ON (0 << 3) |
#define | ADBMS1818_GPIO9_PD_OFF (1 << 3) |
#define | ADBMS1818_CNVT_CELL_ALL 0x00 |
ADCV command macros for cell conversion. More... | |
#define | ADBMS1818_CNVT_CELL_1_7_13 0x01 |
#define | ADBMS1818_CNVT_CELL_2_8_14 0x02 |
#define | ADBMS1818_CNVT_CELL_3_9_15 0x03 |
#define | ADBMS1818_CNVT_CELL_4_10_16 0x04 |
#define | ADBMS1818_CNVT_CELL_5_11_17 0x05 |
#define | ADBMS1818_CNVT_CELL_6_12_18 0x06 |
#define | ADBMS1818_ADCV_DISCHARGE_NOT_PERMITTED (0 << 4) |
ADCV discharge permission macros. More... | |
#define | ADBMS1818_ADCV_DISCHARGE_PERMITTED (1 << 4) |
#define | ADBMS1818_ADAX_GPIO_ALL 0x00 |
ADAX command macros. More... | |
#define | ADBMS1818_ADAX_GPIO1_6 0x01 |
#define | ADBMS1818_ADAX_GPIO2_7 0x02 |
#define | ADBMS1818_ADAX_GPIO3_8 0x03 |
#define | ADBMS1818_ADAX_GPIO4_9 0x04 |
#define | ADBMS1818_ADAX_GPIO5 0x05 |
#define | ADBMS1818_ADAX_REF2 0x06 |
#define | ADBMS1818_ADAX_MODE_FAST (0 << 8) | (1 << 7) |
#define | ADBMS1818_ICOM_CSBM_LOW (1 << 3) |
Write Codes for ICOMn (n = 1, 2, 3) More... | |
#define | ADBMS1818_ICOM_CSBM_FALL_EDGE (1 << 3) | (1 << 0) |
#define | ADBMS1818_ICOM_CSBM_HIGH (1 << 3) | (1 << 1) |
#define | ADBMS1818_ICOM_NO_TRANSMIT (1 << 3) | (1 << 2) | (1 << 1) | (1 << 0) |
#define | ADBMS1818_FCOM_CSBM_LOW (0 << 0) |
Write Codes for FCOMn (n = 1, 2, 3) More... | |
#define | ADBMS1818_FCOM_CSBM_HIGH (1 << 3) | (1 << 0) |
#define | ADBMS1818_PWMC_DC_100 (0xF) |
PWM duty cycle configuration (100%). More... | |
Typedefs | |
typedef struct AdbmsAfeSettings | AdbmsAfeSettings |
Afe Settings Data. More... | |
typedef struct AdbmsAfeStorage | AdbmsAfeStorage |
Runtime Data Storage. More... | |
Functions | |
StatusCode | adbms_afe_init (AdbmsAfeStorage *afe, const AdbmsAfeSettings *config) |
Initializes the ADBMS AFE system with provided configuration settings. More... | |
StatusCode | adbms_afe_write_config (AdbmsAfeStorage *afe) |
Writes configuration bits onto CFGR (Configuration Register Group) More... | |
StatusCode | adbms_afe_trigger_cell_conv (AdbmsAfeStorage *afe) |
Triggers ADC conversion for all enabled cell voltage inputs. More... | |
StatusCode | adbms_afe_trigger_thermistor_conv (AdbmsAfeStorage *afe, uint8_t device_num, uint8_t thermistor_index) |
Triggers ADC conversion for the specified thermistor voltage inputs. More... | |
StatusCode | adbms_afe_trigger_board_temp_conv (AdbmsAfeStorage *afe, uint8_t device_num) |
Triggers ADC conversion for the specified board temperature thermistor input. More... | |
StatusCode | adbms_afe_read_cells (AdbmsAfeStorage *afe) |
Reads and stores cell voltages from the voltage cell registers of each afe. More... | |
StatusCode | adbms_afe_read_thermistor (AdbmsAfeStorage *afe, uint8_t device_num, uint8_t thermistor_index) |
Reads and stores thermistor voltages from the aux voltage registers of each afe. More... | |
StatusCode | adbms_afe_read_board_temp (AdbmsAfeStorage *afe, uint8_t device_num) |
Reads and stores board temperature thermistor voltage from the aux voltage registers of each afe. More... | |
StatusCode | adbms_afe_toggle_cell_discharge (AdbmsAfeStorage *afe, uint16_t cell, bool discharge) |
Mark cell for discharging in each device. More... | |
StatusCode | adbms_afe_set_discharge_pwm_cycle (AdbmsAfeStorage *afe, uint8_t duty_cycle) |
Sets the same discharge PWM duty cycle for all cells across all AFE devices. More... | |
void | crc15_init_table (void) |
Initiliaze the CRC15 table for PEC. More... | |
uint16_t | crc15_calculate (uint8_t *data, size_t len) |
Calculates CRC15 PEC value for given data. More... | |
ADBMS1818 library.
#define ADBMS1818_ADAX_GPIO1_6 0x01 |
Convert GPIO1 and GPIO6.
#define ADBMS1818_ADAX_GPIO2_7 0x02 |
Convert GPIO2 and GPIO7.
#define ADBMS1818_ADAX_GPIO3_8 0x03 |
Convert GPIO3 and GPIO8.
#define ADBMS1818_ADAX_GPIO4_9 0x04 |
Convert GPIO4 and GPIO9.
#define ADBMS1818_ADAX_GPIO5 0x05 |
Convert GPIO5 only.
#define ADBMS1818_ADAX_GPIO_ALL 0x00 |
ADAX command macros.
Convert GPIO1–GPIO5, 2nd reference, and GPIO6–GPIO9.
#define ADBMS1818_ADAX_MODE_FAST (0 << 8) | (1 << 7) |
Select fast ADC mode
#define ADBMS1818_ADAX_REF2 0x06 |
Convert 2nd reference only (VREF2).
#define ADBMS1818_ADAX_RESERVED (1 << 10) | (1 << 6) | (1 << 5) |
Start GPIOs ADC Conversion and Poll Status
#define ADBMS1818_ADCV_DISCHARGE_NOT_PERMITTED (0 << 4) |
ADCV discharge permission macros.
Determines if cell discharge is permitted during ADCV commands.
#define ADBMS1818_ADCV_RESERVED ((1 << 9) | (1 << 6) | (1 << 5)) |
Start Cell Voltage ADC Conversion and Poll Status
#define ADBMS1818_ADOW_RESERVED ((1 << 3) | (1 << 5) | (1 << 9)) |
Start Open Wire ADC Conversion and Poll Status
#define ADBMS1818_CLRAUX_RESERVED (1 << 1) | (1 << 4) | (1 << 8) | (1 << 9) | (1 << 10) |
Clear Auxillary Register Groups
#define ADBMS1818_CLRCELL_RESERVED (1 << 0) | (1 << 4) | (1 << 8) | (1 << 9) | (1 << 10) |
Clear Cell Voltage Register Groups
#define ADBMS1818_CLRSCTRL_RESERVED (1 << 4) | (1 << 3) |
Clear S COntrol Register Group
#define ADBMS1818_CLRSTAT_RESERVED (1 << 0) | (1 << 1) | (1 << 4) | (1 << 8) | (1 << 9) | (1 << 10) |
Clear Status Register Groups
#define ADBMS1818_CNVT_CELL_1_7_13 0x01 |
Convert cells 1, 7, and 13.
#define ADBMS1818_CNVT_CELL_2_8_14 0x02 |
Convert cells 2, 8, and 14.
#define ADBMS1818_CNVT_CELL_3_9_15 0x03 |
Convert cells 3, 9, and 15.
#define ADBMS1818_CNVT_CELL_4_10_16 0x04 |
Convert cells 4, 10, and 16.
#define ADBMS1818_CNVT_CELL_5_11_17 0x05 |
Convert cells 5, 11, and 17.
#define ADBMS1818_CNVT_CELL_6_12_18 0x06 |
Convert cells 6, 12, and 18.
#define ADBMS1818_CNVT_CELL_ALL 0x00 |
ADCV command macros for cell conversion.
Determines which cells to convert during ADCV commands. Convert all cells.
#define ADBMS1818_CVST_RESERVED ((1 << 0) | (1 << 1) | (1 << 2) | (1 << 9)) |
Start Self Test Cell Voltage Conversion and Poll Status
#define ADBMS1818_DIAGN_RESERVED (1 << 0) | (1 << 2) | (1 << 4) | (1 << 8) | (1 << 9) | (1 << 10) |
Diagnose MUX and Poll Status
#define ADBMS1818_FCOM_CSBM_HIGH (1 << 3) | (1 << 0) |
Transitions CSBM high at end of transmission
#define ADBMS1818_FCOM_CSBM_LOW (0 << 0) |
Write Codes for FCOMn (n = 1, 2, 3)
Holds CSBM low at end of transmission
#define ADBMS1818_GPIO1_PD_ON (0 << 3) |
GPIO pull-down configuration for the Config Register Group.
AdbmsAfeConfigReg isterXData
struct for details. #define ADBMS1818_ICOM_CSBM_FALL_EDGE (1 << 3) | (1 << 0) |
CSBM high then low signal
#define ADBMS1818_ICOM_CSBM_HIGH (1 << 3) | (1 << 1) |
CSBM high signal
#define ADBMS1818_ICOM_CSBM_LOW (1 << 3) |
Write Codes for ICOMn (n = 1, 2, 3)
CSBM low signal
#define ADBMS1818_ICOM_NO_TRANSMIT (1 << 3) | (1 << 2) | (1 << 1) | (1 << 0) |
No Data is tranmitted
#define ADBMS1818_NUM_PSR_REGS 6 |
Macros for PWM/S control register group B.
Number of registers in PWM/S Control register group B
#define ADBMS1818_NUM_PWM_REGS_IN_PSR 3 |
Number of PWM registers in the PWM/S control register group B
#define ADBMS1818_NUM_SCTL_REGS_IN_PSR 3 |
Number of SCTL registers in the PWM/S control register group B
#define ADBMS1818_PLADC_RESERVED (1 << 2) | (1 << 4) | (1 << 8) | (1 << 9) | (1 << 10) |
Poll ADC Conversion Status
#define ADBMS1818_PWMC_DC_100 (0xF) |
PWM duty cycle configuration (100%).
#define ADBMS1818_RDAUXA_RESERVED ((1 << 3) | (1 << 2)) |
Read Auxillary Reg Group A
#define ADBMS1818_RDAUXB_RESERVED ((1 << 3) | (1 << 2)) | (1 << 1) |
Read Auxillary Reg Group B
#define ADBMS1818_RDAUXC_RESERVED ((1 << 3) | (1 << 2)) | (1 << 0) |
Read Auxillary Reg Group C
#define ADBMS1818_RDAUXD_RESERVED ((1 << 3) | (1 << 2)) | (1 << 1) | (1 << 0) |
Read Auxillary Reg Group D
#define ADBMS1818_RDCFGA_RESERVED (1 << 1) |
Read Config Reg Group A
#define ADBMS1818_RDCFGB_RESERVED (1 << 5) | (1 << 2) | (1 << 1) |
Read Config Reg Group B
#define ADBMS1818_RDCOMM_RESERVED (1 << 1) | (1 << 5) | (1 << 8) | (1 << 9) | (1 << 10) |
Read COMM Register Group
#define ADBMS1818_RDCVA_RESERVED (1 << 2) |
Read Cell Voltage Reg Group A
#define ADBMS1818_RDCVB_RESERVED (1 << 2) | (1 << 1) |
Read Cell Voltage Reg Group B
#define ADBMS1818_RDCVC_RESERVED (1 << 3) |
Read Cell Voltage Reg Group C
#define ADBMS1818_RDCVD_RESERVED (1 << 3) | (1 << 1) |
Read Cell Voltage Reg Group D
#define ADBMS1818_RDCVE_RESERVED (1 << 3) | (1 << 0) |
Read Cell Voltage Reg Group E
#define ADBMS1818_RDCVF_RESERVED (1 << 3) | (1 << 1) | (1 << 0) |
Read Cell Voltage Reg Group F
#define ADBMS1818_RDPSB_RESERVED (1 << 4) | (1 << 3) | (1 << 2) | (1 << 1) |
Read PWM Register Group
#define ADBMS1818_RDPWM_RESERVED (1 << 5) | (1 << 2) |
Read PWM Register Group
#define ADBMS1818_RDSCTRL_RESERVED (1 << 4) | (1 << 2) | (1 << 1) |
Read S Control Register Group
#define ADBMS1818_RDSTATA_RESERVED (1 << 4) |
Read Status Register Group A
#define ADBMS1818_RDSTATB_RESERVED (1 << 4) | (1 << 1) |
Read Status Register Group B
#define ADBMS1818_STSCTRL_RESERVED (1 << 4) | (1 << 3) | (1 << 0) |
Start S Control Pulsing and Poll Status
#define ADBMS1818_WRCFGA_RESERVED (1 << 0) |
Command codes for ADBMS1818 AFE.
See Table 52 (p.61) Write Config Reg Group A
#define ADBMS1818_WRCFGB_RESERVED (1 << 5) | (1 << 2) |
Write Config Reg Group B
#define ADBMS1818_WRCOMM_RESERVED (1 << 0) | (1 << 5) | (1 << 8) | (1 << 9) | (1 << 10) |
Write COMM Register Group
#define ADBMS1818_WRPSB_RESERVED (1 << 4) | (1 << 3) | (1 << 2) |
Write PWM/S Control Register Group B
#define ADBMS1818_WRPWM_RESERVED (1 << 5) |
Write PWM Register Group
#define ADBMS1818_WRSCTRL_RESERVED (1 << 4) | (1 << 2) |
Write S Control Register Group
#define ADBMS_AFE_MAX_CELLS_PER_DEVICE 18 |
Maximum x of each device.
#define ADBMS_AFE_MAX_DEVICES 3 |
Maximum AFE devices in daisy chain config.
typedef struct AdbmsAfeSettings AdbmsAfeSettings |
Afe Settings Data.
Set by the user when adbms_afe_init
is called Stores SPI information, which cell and thermistor inputs are enabled, and number of things
SpiSettings
refer to spi.h
typedef struct AdbmsAfeStorage AdbmsAfeStorage |
Runtime Data Storage.
Stores settings, configs, and voltages for all AFE devices
0
corresponds to the first cell/thermistor value of the first AFE device.n * max_x_per_device
corresponds to the first value of the (n+1)th AFE device.enum AdbmsAfeAdcMode |
Discharge timeout options for the AFE.
See Table 72 on Page 68 for more details
enum AdbmsAfeRegister |
List of ADBMS AFE registers.
These registers are mapped to the s_read_reg[]
array in adbms_afe.c
StatusCode adbms_afe_init | ( | AdbmsAfeStorage * | afe, |
const AdbmsAfeSettings * | config | ||
) |
Initializes the ADBMS AFE system with provided configuration settings.
Validates user-defined configuration parameters, sets up SPI communication, calculates result buffer offsets, initializes the CRC15 lookup table, and writes configuration settings to all AFE devices
afe | Pointer to AdbmsAfeStorage struct, stores runtime data and settings of AFE |
config | Pointer to constant AdbmsAfeSettings struct, contains user-specified configuration parameters |
StatusCode adbms_afe_read_board_temp | ( | AdbmsAfeStorage * | afe, |
uint8_t | device_num | ||
) |
Reads and stores board temperature thermistor voltage from the aux voltage registers of each afe.
Received PEC and PEC of data is compared to see if data is valid Voltages are stored in the afe->board_thermistor_voltages
array
afe | Pointer to AdbmsAfeStorage struct, stores runtime data and settings of AFE |
device_num | Target device number |
s_read_register
StatusCode adbms_afe_read_cells | ( | AdbmsAfeStorage * | afe | ) |
Reads and stores cell voltages from the voltage cell registers of each afe.
RDCVx (x = A, B, C, D) command is sent to read converted voltage from respective register group Received PEC and PEC of data is compared to see if data is valid Voltages are stored in the afe->cell_voltages
array, if cell status is enabled
afe | Pointer to AdbmsAfeStorage struct, stores runtime data and settings of AFE |
s_read_register
StatusCode adbms_afe_read_thermistor | ( | AdbmsAfeStorage * | afe, |
uint8_t | device_num, | ||
uint8_t | thermistor_index | ||
) |
Reads and stores thermistor voltages from the aux voltage registers of each afe.
Received PEC and PEC of data is compared to see if data is valid Voltages are stored in the afe->thermistor_voltages
array
afe | Pointer to AdbmsAfeStorage struct, stores runtime data and settings of AFE |
device_num | Target device number |
thermistor_index | Thermistor index between 0-16 |
s_read_register
StatusCode adbms_afe_set_discharge_pwm_cycle | ( | AdbmsAfeStorage * | afe, |
uint8_t | duty_cycle | ||
) |
Sets the same discharge PWM duty cycle for all cells across all AFE devices.
Configures the PWM duty cycle registers on each AFE device so that all 18 cell discharge channels operate at the same specified duty cycle. Each register controls 2 channels, so 6 registers are written per device. Prepares a write command and transmits it to all AFE devices.
afe | Pointer to AdbmsAfeStorage struct containing runtime data and settings |
duty_cycle | 4-bit duty cycle value (0x0 to 0xF) to set for all PWM channels |
Initialize a buffer to store the PWM configuration command, while also accounting for the number of registers to write to (6) for each AFE, which is not known at compile time.
Since each AFE has 12 PWM channels for the PWMR group and each PWM register stores two 4-bit PWM values in a byte, there are 6 registers to iterate through and 2 PWM channels are configured at a time.
StatusCode adbms_afe_toggle_cell_discharge | ( | AdbmsAfeStorage * | afe, |
uint16_t | cell, | ||
bool | discharge | ||
) |
Mark cell for discharging in each device.
Device number is reverse indexed, since adbms_afe_write_config
writes configs in reverse order Appropriate bit in discharge_bitset
in AdbmsAfeConfigRegisterData
is marked (see adbms_afe_regs.h
) Only takes effect when config is rewritten with adbms_afe_write_config
afe | Pointer to AdbmsAfeStorage struct, stores runtime data and settings of AFE |
cell | Index of cell at device x (cell = cell # in device + (# of cells * device_number)) |
discharge | Is cell being discharged or not? |
cell
index is invalid StatusCode adbms_afe_trigger_board_temp_conv | ( | AdbmsAfeStorage * | afe, |
uint8_t | device_num | ||
) |
Triggers ADC conversion for the specified board temperature thermistor input.
Builds and transmits the ADCV command using the configured ADC mode to start aux voltage conversion across all AFE devices. Puts device into active mode before initiating conversion.
afe | Pointer to AdbmsAfeStorage struct, stores runtime data and settings of AFE |
device_num | Target device number |
StatusCode adbms_afe_trigger_cell_conv | ( | AdbmsAfeStorage * | afe | ) |
Triggers ADC conversion for all enabled cell voltage inputs.
Builds and transmits the ADCV command using the configured ADC mode to start cell voltage conversion across all AFE devices. Puts device into active mode before initiating conversion.
afe | Pointer to AdbmsAfeStorage struct containing runtime data and settings |
StatusCode adbms_afe_trigger_thermistor_conv | ( | AdbmsAfeStorage * | afe, |
uint8_t | device_num, | ||
uint8_t | thermistor_index | ||
) |
Triggers ADC conversion for the specified thermistor voltage inputs.
Builds and transmits the ADCV command using the configured ADC mode to start aux voltage conversion across all AFE devices. Puts device into active mode before initiating conversion.
afe | Pointer to AdbmsAfeStorage struct, stores runtime data and settings of AFE |
device_num | Target device number |
thermistor_index | Thermistor index between 0-16 |
StatusCode adbms_afe_write_config | ( | AdbmsAfeStorage * | afe | ) |
Writes configuration bits onto CFGR (Configuration Register Group)
Writes configuration bits to each of the AFE devices' configuration register bits
afe | Pointer to AdbmsAfeStorage struct, stores runtime data and settings of AFE |
spi_exchange
is incorrect in prv_write_config
STATUS_CODE_INTERNAL_ERROR if HAL transmission/receiving fails STATUS_CODE_TIMEOUT if transmission/receiving takes too long uint16_t crc15_calculate | ( | uint8_t * | data, |
size_t | len | ||
) |
Calculates CRC15 PEC value for given data.
data | the data to calculate the PEC for |
len | length of the data |
void crc15_init_table | ( | void | ) |
Initiliaze the CRC15 table for PEC.
Used for fast CRC15 lookups