/** ****************************************************************************** * File Name : ltc681x.h * Description : This file provides code for the configuration * of ltc681x driver. ****************************************************************************** * @attention * *

© Copyright (c) 2021 Amogreentech Co., Ltd. * All rights reserved.

* ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef _LTC681X_H_ #define _LTC681X_H_ /* Includes ------------------------------------------------------------------*/ #include "hc32_ddl.h" /* Exported constants --------------------------------------------------------*/ /* Exported macro ------------------------------------------------------------*/ /* Exported define -----------------------------------------------------------*/ #define IC_LTC6813 #define MD_422HZ_1KHZ 0 #define MD_27KHZ_14KHZ 1 #define MD_7KHZ_3KHZ 2 #define MD_26HZ_2KHZ 3 #define ADC_OPT_ENABLED 1 #define ADC_OPT_DISABLED 0 #define CELL_CH_ALL 0 #define CELL_CH_1and7 1 #define CELL_CH_2and8 2 #define CELL_CH_3and9 3 #define CELL_CH_4and10 4 #define CELL_CH_5and11 5 #define CELL_CH_6and12 6 #define SELFTEST_1 1 #define SELFTEST_2 2 #define AUX_CH_ALL 0 #define AUX_CH_GPIO1 1 #define AUX_CH_GPIO2 2 #define AUX_CH_GPIO3 3 #define AUX_CH_GPIO4 4 #define AUX_CH_GPIO5 5 #define AUX_CH_VREF2 6 #define STAT_CH_ALL 0 #define STAT_CH_SOC 1 #define STAT_CH_ITEMP 2 #define STAT_CH_VREGA 3 #define STAT_CH_VREGD 4 #define DCP_DISABLED 0 #define DCP_ENABLED 1 #define PULL_UP_CURRENT 1 #define PULL_DOWN_CURRENT 0 #define NUM_RX_BYT 8 #define CELL 1 #define AUX 2 #define STAT 3 #define CFGR 0 #define CFGRB 4 #define CS_PIN_HIGH SPI1_NSS_HIGH #define CS_PIN_LOW SPI1_NSS_LOW /* Exported types ------------------------------------------------------------*/ //! Cell Voltage data structure. typedef struct { uint16_t c_codes[18]; //!< Cell Voltage Codes uint8_t pec_match[6]; //!< If a PEC error was detected during most recent read cmd } cv; //! AUX Reg Voltage Data typedef struct { uint16_t a_codes[12]; //!< Aux Voltage Codes uint8_t pec_match[4]; //!< If a PEC error was detected during most recent read cmd } ax; typedef struct { uint16_t stat_codes[4]; //!< A two dimensional array of the stat voltage codes. uint8_t flags[3]; //!< byte array that contains the uv/ov flag data uint8_t mux_fail[1]; //!< Mux self test status flag uint8_t thsd[1]; //!< Thermal shutdown status uint8_t pec_match[2]; //!< If a PEC error was detected during most recent read cmd } st; typedef struct { uint8_t tx_data[6]; uint8_t rx_data[8]; uint8_t rx_pec_match; //!< If a PEC error was detected during most recent read cmd } ic_register; typedef struct { uint16_t pec_count; uint16_t cfgr_pec; uint16_t cell_pec[6]; uint16_t aux_pec[4]; uint16_t stat_pec[2]; } pec_counter; typedef struct { uint8_t cell_channels; uint8_t stat_channels; uint8_t aux_channels; uint8_t num_cv_reg; uint8_t num_gpio_reg; uint8_t num_stat_reg; } register_cfg; typedef struct { ic_register config; ic_register configb; cv cells; ax aux; st stat; ic_register com; ic_register pwm; ic_register pwmb; ic_register sctrl; ic_register sctrlb; bool isospi_reverse; pec_counter crc_count; register_cfg ic_reg; long system_open_wire; } cell_asic; /* Exported variables ------------------------------------------------------- */ /* Exported functions ------------------------------------------------------- */ /*! calculates and returns the CRC15 @returns The calculated pec15 as an unsigned int */ uint16_t pec15_calc(uint8_t len, //!< the length of the data array being passed to the function uint8_t *data //!< the array of data that the PEC will be generated from ); /*! Wake isoSPI up from idle state */ void wakeup_idle(uint8_t total_ic);//!< number of ICs in the daisy chain /*! Wake the LTC6813 from the sleep state */ void wakeup_sleep(uint8_t total_ic); //!< number of ICs in the daisy chain /*! Sense a command to the bms IC. This code will calculate the PEC code for the transmitted command*/ void cmd_68(uint8_t tx_cmd[2]); //!< 2 Byte array containing the BMS command to be sent //! Writes an array of data to the daisy chain void write_68(uint8_t total_ic , //!< number of ICs in the daisy chain uint8_t tx_cmd[2], //!< 2 Byte array containing the BMS command to be sent uint8_t data[] //!< Array containing the data to be written to the BMS ICs ); //! Issues a command onto the daisy chain and reads back 6*total_ic data in the rx_data array int8_t read_68( uint8_t total_ic, //!< number of ICs in the daisy chain uint8_t tx_cmd[2], //!< 2 Byte array containing the BMS command to be sent uint8_t *rx_data); //!< Array that the read back data will be stored. /*! Starts the Mux Decoder diagnostic self test Running this command will start the Mux Decoder Diagnostic Self Test This test takes roughly 1mS to complete. The MUXFAIL bit will be updated, the bit will be set to 1 for a failure and 0 if the test has been passed. */ void LTC681x_diagn(void); /*! Starts cell voltage conversion Starts ADC conversions of the LTC6811 Cpin inputs. The type of ADC conversion executed can be changed by setting the following parameters: */ void LTC681x_adcv(uint8_t MD, //!< ADC Conversion Mode uint8_t DCP, //!< Controls if Discharge is permitted during conversion uint8_t CH //!< Sets which Cell channels are converted ); /*! Starts cell voltage and GPIO 1&2 conversion */ void LTC681x_adcvax( uint8_t MD, //!< ADC Conversion Mode uint8_t DCP //!< Controls if Discharge is permitted during conversion ); /*! Starts cell voltage self test conversion */ void LTC681x_cvst( uint8_t MD, //!< ADC Conversion Mode uint8_t ST //!< Self Test Mode ); /*! Starts cell voltage and SOC conversion */ void LTC681x_adcvsc( uint8_t MD, //!< ADC Conversion Mode uint8_t DCP //!< Controls if Discharge is permitted during conversion ); /*! Starts cell voltage overlap conversion */ void LTC681x_adol( uint8_t MD, //!< ADC Conversion Mode uint8_t DCP //!< Discharge permitted during conversion ); /*! Start an open wire Conversion */ void LTC681x_adow( uint8_t MD, //!< ADC Conversion Mode uint8_t PUP //!< Controls if Discharge is permitted during conversion ); /*! Start a GPIO and Vref2 Conversion */ void LTC681x_adax( uint8_t MD, //!< ADC Conversion Mode uint8_t CHG //!< Sets which GPIO channels are converted ); /*! Start an GPIO Redundancy test */ void LTC681x_adaxd( uint8_t MD, //!< ADC Conversion Mode uint8_t CHG //!< Sets which GPIO channels are converted ); /*! Start an Auxiliary Register Self Test Conversion */ void LTC681x_axst( uint8_t MD, //!< ADC Conversion Mode uint8_t ST //!< Sets if self test 1 or 2 is run ); /*! Start a Status ADC Conversion */ void LTC681x_adstat( uint8_t MD, //!< ADC Conversion Mode uint8_t CHST //!< Sets which Stat channels are converted ); /*! Start a Status register redundancy test Conversion */ void LTC681x_adstatd( uint8_t MD, //!< ADC Mode uint8_t CHST //!< Sets which Status channels are converted ); /*! Start a Status Register Self Test Conversion */ void LTC681x_statst( uint8_t MD, //!< ADC Conversion Mode uint8_t ST //!< Sets if self test 1 or 2 is run ); void LTC681x_rdcv_reg(uint8_t reg, //!