foxBMS
1.1.0
The foxBMS Battery Management System API Documentation
|
Driver for the LTC monitoring chip. More...
#include "ltc.h"
#include "ltc_6806_cfg.h"
#include "HL_spi.h"
#include "HL_system.h"
#include "database.h"
#include "diag.h"
#include "io.h"
#include "ltc_pec.h"
#include "os.h"
#include "mic_plausibility.h"
Go to the source code of this file.
Macros | |
#define | LTC_FUEL_CELL_LSB_RESOLUTION_mV (1.5f) |
#define | LTC_FUELCELL_POSITIVE_FULLSCALE_RANGE_mV ((int16_t)((0x7FF * LTC_FUEL_CELL_LSB_RESOLUTION_mV))) |
#define | LTC_FUELCELL_NEGATIVE_FULLSCALE_RANGE_mV ((int16_t)((((~0x001) + 1) & 0x7FF) * (-LTC_FUEL_CELL_LSB_RESOLUTION_mV))) |
#define | LTC_LTC6820CONTROL_GIODIR (hetREG1->DIR) |
#define | LTC_LTC6820CONTROL_GIOPORT (hetREG1->DOUT) |
#define | LTC_LTC6820_FORWARD_ENABLE_PIN (22U) |
#define | LTC_LTC6820_FORWARD_SPI1_MASTER_PIN (24U) |
#define | LTC_LTC6820_REVERSE_ENABLE_PIN (23U) |
#define | LTC_LTC6820_REVERSE_MASTER_PIN (25U) |
#define | LTC_PORT_EXPANDER_TI_INPUT_REG_ADR (0x00u) |
#define | LTC_PORT_EXPANDER_TI_OUTPUT_REG_ADR (0x01u) |
#define | LTC_PORT_EXPANDER_TI_CONFIG_REG_ADR (0x03u) |
Functions | |
static void | LTC_SetFirstMeasurementCycleFinished (LTC_STATE_s *ltc_state) |
sets the measurement initialization status. More... | |
static void | LTC_Initialize_Database (LTC_STATE_s *ltc_state) |
in the database, initializes the fields related to the LTC drivers. More... | |
static void | LTC_SaveLastStates (LTC_STATE_s *ltc_state) |
Saves the last state and the last substate. More... | |
static void | LTC_StateTransition (LTC_STATE_s *ltc_state, LTC_STATEMACH_e state, uint8_t substate, uint16_t timer_ms) |
function for setting LTC_Trigger state transitions More... | |
static void | LTC_CondBasedStateTransition (LTC_STATE_s *ltc_state, STD_RETURN_TYPE_e retVal, DIAG_ID_e diagCode, LTC_STATEMACH_e state_ok, uint8_t substate_ok, uint16_t timer_ms_ok, LTC_STATEMACH_e state_nok, uint8_t substate_nok, uint16_t timer_ms_nok) |
condition-based state transition depending on retVal More... | |
static void | LTC_ResetErrorTable (LTC_STATE_s *ltc_state) |
resets the error table. More... | |
static STD_RETURN_TYPE_e | LTC_Init (SPI_INTERFACE_CONFIG_s *pSpiInterface, uint16_t *pTxBuff, uint16_t *pRxBuff, uint32_t frameLength) |
initialize the daisy-chain. More... | |
static STD_RETURN_TYPE_e | LTC_StartVoltageMeasurement (SPI_INTERFACE_CONFIG_s *pSpiInterface, LTC_ADCMODE_e adcMode, LTC_ADCMEAS_CHAN_e adcMeasCh) |
tells the LTC daisy-chain to start measuring the voltage on all cells. More... | |
static STD_RETURN_TYPE_e | LTC_StartOpenWireMeasurement (SPI_INTERFACE_CONFIG_s *pSpiInterface, LTC_ADCMODE_e adcMode, uint8_t PUP) |
tells LTC daisy-chain to start measuring the voltage on GPIOS. More... | |
static void | LTC_SaveRXtoVoltagebuffer_Fuelcell (LTC_STATE_s *ltc_state, uint16_t *pRxBuff, uint8_t registerSet, uint8_t stringNumber) |
saves the voltage values read from the LTC daisy-chain. More... | |
static STD_RETURN_TYPE_e | LTC_RX_PECCheck (LTC_STATE_s *ltc_state, uint16_t *DataBufferSPI_RX_with_PEC, uint8_t stringNumber) |
checks if the data received from the daisy-chain is not corrupt. More... | |
static STD_RETURN_TYPE_e | LTC_RX (uint16_t *Command, SPI_INTERFACE_CONFIG_s *pSpiInterface, uint16_t *pTxBuff, uint16_t *pRxBuff, uint32_t frameLength) |
send command to the LTC daisy-chain and receives data from the LTC daisy-chain. More... | |
static uint32_t | LTC_GetSPIClock (SPI_INTERFACE_CONFIG_s *pSpiInterface) |
gets the frequency of the SPI clock. More... | |
static void | LTC_SetTransferTimes (LTC_STATE_s *ltc_state) |
sets the transfer time needed to receive/send data with the LTC daisy-chain. More... | |
static LTC_RETURN_TYPE_e | LTC_CheckStateRequest (LTC_STATE_s *ltc_state, LTC_REQUEST_s statereq) |
checks the state requests that are made. More... | |
void | LTC_SaveVoltages (LTC_STATE_s *ltc_state, uint8_t stringNumber) |
stores the measured voltages in the database. More... | |
void | LTC_SaveTemperatures (LTC_STATE_s *ltc_state, uint8_t stringNumber) |
stores the measured temperatures and the measured multiplexer feedbacks in the database. More... | |
void | LTC_SaveAllGPIOMeasurement (LTC_STATE_s *ltc_state) |
stores the measured GPIOs in the database. More... | |
uint8_t | LTC_CheckReEntrance (LTC_STATE_s *ltc_state) |
re-entrance check of LTC state machine trigger function More... | |
LTC_REQUEST_s | LTC_GetStateRequest (LTC_STATE_s *ltc_state) |
gets the current state request. More... | |
LTC_STATEMACH_e | LTC_GetState (LTC_STATE_s *ltc_state) |
gets the current state. More... | |
LTC_REQUEST_s | LTC_TransferStateRequest (LTC_STATE_s *ltc_state, uint8_t *pBusIDptr, LTC_ADCMODE_e *pAdcModeptr, LTC_ADCMEAS_CHAN_e *pAdcMeasChptr) |
transfers the current state request to the state machine. More... | |
LTC_RETURN_TYPE_e | LTC_SetStateRequest (LTC_STATE_s *ltc_state, LTC_REQUEST_s statereq) |
sets the current state request of the state variable ltc_state. More... | |
void | LTC_Trigger (LTC_STATE_s *ltc_state) |
trigger function for the LTC driver state machine. More... | |
bool | LTC_IsFirstMeasurementCycleFinished (LTC_STATE_s *ltc_state) |
gets the measurement initialization status. More... | |
void | LTC_monitoringPinInit (void) |
Sets the transceiver pins to enable LTC6820 IC. More... | |
Driver for the LTC monitoring chip.
SPDX-License-Identifier: BSD-3-Clause
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
We kindly request you to use one or more of the following phrases to refer to foxBMS in your hardware, software, documentation or advertising materials:
Definition in file ltc_6806.c.
#define LTC_FUEL_CELL_LSB_RESOLUTION_mV (1.5f) |
Value of the LSB in mV
Definition at line 99 of file ltc_6806.c.
#define LTC_FUELCELL_NEGATIVE_FULLSCALE_RANGE_mV ((int16_t)((((~0x001) + 1) & 0x7FF) * (-LTC_FUEL_CELL_LSB_RESOLUTION_mV))) |
Value for negative full scale measurement for fuel cell
Definition at line 112 of file ltc_6806.c.
#define LTC_FUELCELL_POSITIVE_FULLSCALE_RANGE_mV ((int16_t)((0x7FF * LTC_FUEL_CELL_LSB_RESOLUTION_mV))) |
Value for positive full scale measurement for fuel cell
Definition at line 107 of file ltc_6806.c.
#define LTC_LTC6820_FORWARD_ENABLE_PIN (22U) |
LTC 6820 GPIO configuration
Definition at line 79 of file ltc_6806.c.
#define LTC_LTC6820_FORWARD_SPI1_MASTER_PIN (24U) |
LTC 6820 GPIO configuration
Definition at line 80 of file ltc_6806.c.
#define LTC_LTC6820_REVERSE_ENABLE_PIN (23U) |
LTC 6820 GPIO configuration
Definition at line 82 of file ltc_6806.c.
#define LTC_LTC6820_REVERSE_MASTER_PIN (25U) |
LTC 6820 GPIO configuration
Definition at line 83 of file ltc_6806.c.
#define LTC_LTC6820CONTROL_GIODIR (hetREG1->DIR) |
LTC 6820 GPIO configuration
Definition at line 76 of file ltc_6806.c.
#define LTC_LTC6820CONTROL_GIOPORT (hetREG1->DOUT) |
LTC 6820 GPIO configuration
Definition at line 77 of file ltc_6806.c.
#define LTC_PORT_EXPANDER_TI_CONFIG_REG_ADR (0x03u) |
TI port expander register addresses
Definition at line 92 of file ltc_6806.c.
#define LTC_PORT_EXPANDER_TI_INPUT_REG_ADR (0x00u) |
TI port expander register addresses
Definition at line 90 of file ltc_6806.c.
#define LTC_PORT_EXPANDER_TI_OUTPUT_REG_ADR (0x01u) |
TI port expander register addresses
Definition at line 91 of file ltc_6806.c.
uint8_t LTC_CheckReEntrance | ( | LTC_STATE_s * | ltc_state | ) |
re-entrance check of LTC state machine trigger function
This function is not re-entrant and should only be called time- or event-triggered. It increments the triggerentry counter from the state variable ltc_state. It should never be called by two different processes, so if it is the case, triggerentry should never be higher than 0 when this function is called.
ltc_state | state of the ltc state machine |
Definition at line 529 of file ltc_6806.c.
|
static |
checks the state requests that are made.
This function checks the validity of the state requests. The results of the checked is returned immediately.
ltc_state | state of the ltc state machine |
statereq | state request to be checked |
Definition at line 1712 of file ltc_6806.c.
|
static |
condition-based state transition depending on retVal
If retVal is STD_OK, after timer_ms_ok is elapsed the LTC statemachine will transition into state_ok and substate_ok, otherwise after timer_ms_nok the statemachine will transition to state_nok and substate_nok. Depending on value of retVal the corresponding diagnosis entry will be called.
ltc_state | state of the ltc state machine |
retVal | condition to determine if statemachine will transition into ok or nok states |
diagCode | symbolic IDs for diagnosis entry, called with DIAG_EVENT_OK if retVal is STD_OK, DIAG_EVENT_NOT_OK otherwise |
state_ok | state to transition into if retVal is STD_OK |
substate_ok | substate to transition into if retVal is STD_OK |
timer_ms_ok | transition into state_ok, substate_ok after timer_ms_ok elapsed |
state_nok | state to transition into if retVal is STD_NOT_OK |
substate_nok | substate to transition into if retVal is STD_NOT_OK |
timer_ms_nok | transition into state_nok, substate_nok after timer_ms_nok elapsed |
Definition at line 382 of file ltc_6806.c.
|
static |
gets the frequency of the SPI clock.
This function reads the configuration from the SPI handle directly.
pSpiInterface | pointer to SPI configuration |
Definition at line 1634 of file ltc_6806.c.
LTC_STATEMACH_e LTC_GetState | ( | LTC_STATE_s * | ltc_state | ) |
gets the current state.
This function is used in the functioning of the LTC state machine.
ltc_state | state of the ltc state machine |
Definition at line 572 of file ltc_6806.c.
LTC_REQUEST_s LTC_GetStateRequest | ( | LTC_STATE_s * | ltc_state | ) |
gets the current state request.
This function is used in the functioning of the LTC state machine.
ltc_state | state of the ltc state machine |
Definition at line 552 of file ltc_6806.c.
|
static |
initialize the daisy-chain.
To initialize the LTC6804 daisy-chain, a dummy byte (0x00) is sent.
pSpiInterface | pointer to SPI configuration |
pTxBuff | transmit buffer |
pRxBuff | receive buffer |
frameLength | number of words to transmit |
Definition at line 1402 of file ltc_6806.c.
|
static |
in the database, initializes the fields related to the LTC drivers.
This function loops through all the LTC-related data fields in the database and sets them to 0. It should be called in the initialization or re-initialization routine of the LTC driver.
ltc_state | state of the ltc state machine |
Definition at line 309 of file ltc_6806.c.
bool LTC_IsFirstMeasurementCycleFinished | ( | LTC_STATE_s * | ltc_state | ) |
gets the measurement initialization status.
ltc_state | state of the ltc state machine |
Definition at line 1733 of file ltc_6806.c.
void LTC_monitoringPinInit | ( | void | ) |
Sets the transceiver pins to enable LTC6820 IC.
Definition at line 1752 of file ltc_6806.c.
|
static |
resets the error table.
This function should be called during initialization or before starting a new measurement cycle
ltc_state | state of the ltc state machine |
Definition at line 1454 of file ltc_6806.c.
|
static |
send command to the LTC daisy-chain and receives data from the LTC daisy-chain.
This is the core function to receive data from the LTC6804 daisy-chain. A 2 byte command is sent with the corresponding PEC. Example: read configuration register (RDCFG). Only command has to be set, the function calculates the PEC automatically. The data send is: 2 bytes (COMMAND) 2 bytes (PEC) The data received is: 6 bytes (LTC1) 2 bytes (PEC) + 6 bytes (LTC2) 2 bytes (PEC) + 6 bytes (LTC3) 2 bytes (PEC) + ... + 6 bytes (LTC{LTC_N_LTC}) 2 bytes (PEC)
The function does not check the PECs. This has to be done elsewhere.
Command | command sent to the daisy-chain |
pSpiInterface | pointer to SPI configuration |
pTxBuff | transmit buffer |
pRxBuff | receive buffer |
frameLength | number of words to transmit |
Definition at line 1598 of file ltc_6806.c.
|
static |
checks if the data received from the daisy-chain is not corrupt.
This function computes the PEC (CRC) from the data received by the daisy-chain. It compares it with the PEC sent by the LTCs. If there are errors, the array the error table is updated to locate the LTCs in daisy-chain that transmitted corrupt data.
ltc_state | state of the ltc state machine |
DataBufferSPI_RX_with_PEC | data obtained from the SPI transmission |
stringNumber | string addressed |
Definition at line 1535 of file ltc_6806.c.
void LTC_SaveAllGPIOMeasurement | ( | LTC_STATE_s * | ltc_state | ) |
stores the measured GPIOs in the database.
This function loops through the data of all modules in the LTC daisy-chain that are stored in the ltc_allgpiovoltage buffer and writes them in the database. At each write iteration, the variable named "state" and related to voltages in the database is incremented.
ltc_state | state of the ltc state machine |
Definition at line 511 of file ltc_6806.c.
|
static |
Saves the last state and the last substate.
ltc_state | state of the ltc state machine |
Definition at line 345 of file ltc_6806.c.
|
static |
saves the voltage values read from the LTC daisy-chain.
After a voltage measurement was initiated to measure the voltages of the cells, the result is read via SPI from the daisy-chain. There are 6 register to read _(A,B,C,D,E,F,G,H,I) to get all cell voltages. Only one register can be read at a time. This function is called to store the result from the transmission in a buffer.
ltc_state | state of the ltc state machine |
pRxBuff | receive buffer |
registerSet | voltage register that was read (voltage register A,B,C,D,E,F,G,H or I) |
stringNumber | string addressed |
Definition at line 1299 of file ltc_6806.c.
void LTC_SaveTemperatures | ( | LTC_STATE_s * | ltc_state, |
uint8_t | stringNumber | ||
) |
stores the measured temperatures and the measured multiplexer feedbacks in the database.
This function loops through the temperature and multiplexer feedback data of all modules in the LTC daisy-chain that are stored in the LTC_MultiplexerVoltages buffer and writes them in the database. At each write iteration, the variables named "state" and related to temperatures and multiplexer feedbacks in the database are incremented.
ltc_state | state of the ltc state machine |
stringNumber | string addressed |
Definition at line 463 of file ltc_6806.c.
void LTC_SaveVoltages | ( | LTC_STATE_s * | ltc_state, |
uint8_t | stringNumber | ||
) |
stores the measured voltages in the database.
This function loops through the data of all modules in the LTC daisy-chain that are stored in the LTC_CellVoltages buffer and writes them in the database. At each write iteration, the variable named "state" and related to voltages in the database is incremented.
ltc_state | state of the ltc state machine |
stringNumber | string addressed |
Definition at line 402 of file ltc_6806.c.
|
static |
sets the measurement initialization status.
Definition at line 1746 of file ltc_6806.c.
LTC_RETURN_TYPE_e LTC_SetStateRequest | ( | LTC_STATE_s * | ltc_state, |
LTC_REQUEST_s | statereq | ||
) |
sets the current state request of the state variable ltc_state.
This function is used to make a state request to the state machine,e.g, start voltage measurement, read result of voltage measurement, re-initialization It calls LTC_CheckStateRequest() to check if the request is valid. The state request is rejected if is not valid. The result of the check is returned immediately, so that the requester can act in case it made a non-valid state request.
ltc_state | state of the ltc state machine |
statereq | state request to set |
Definition at line 610 of file ltc_6806.c.
|
static |
sets the transfer time needed to receive/send data with the LTC daisy-chain.
This function gets the clock frequency and uses the number of LTCs in the daisy-chain.
ltc_state | state of the ltc state machine |
Definition at line 1675 of file ltc_6806.c.
|
static |
tells LTC daisy-chain to start measuring the voltage on GPIOS.
This function sends an instruction to the daisy-chain via SPI to start the measurement.
pSpiInterface | pointer to SPI configuration |
adcMode | LTC ADCmeasurement mode (fast, normal or filtered) |
PUP | pull-up bit for pull-up or pull-down current (0: pull-down, 1: pull-up) |
Definition at line 1503 of file ltc_6806.c.
|
static |
tells the LTC daisy-chain to start measuring the voltage on all cells.
This function sends an instruction to the daisy-chain via SPI, in order to start voltage measurement for all cells.
pSpiInterface | pointer to SPI configuration |
adcMode | LTC ADCmeasurement mode (fast, normal or filtered) |
adcMeasCh | number of cell voltage measured (2 cells or all cells) |
Definition at line 1480 of file ltc_6806.c.
|
static |
function for setting LTC_Trigger state transitions
ltc_state | state of the ltc state machine |
state | state to transition into |
substate | substate to transition into |
timer_ms | transition into state, substate after timer elapsed |
Definition at line 358 of file ltc_6806.c.
LTC_REQUEST_s LTC_TransferStateRequest | ( | LTC_STATE_s * | ltc_state, |
uint8_t * | pBusIDptr, | ||
LTC_ADCMODE_e * | pAdcModeptr, | ||
LTC_ADCMEAS_CHAN_e * | pAdcMeasChptr | ||
) |
transfers the current state request to the state machine.
This function takes the current state request from ltc_state and transfers it to the state machine. It resets the value from ltc_state to LTC_STATE_NO_REQUEST
ltc_state | state of the ltc state machine |
pBusIDptr | bus ID, main or backup (deprecated) |
pAdcModeptr | LTC ADCmeasurement mode (fast, normal or filtered) |
pAdcMeasChptr | number of channels measured for GPIOS (one at a time for multiplexers or all five GPIOs) |
Definition at line 590 of file ltc_6806.c.
void LTC_Trigger | ( | LTC_STATE_s * | ltc_state | ) |
trigger function for the LTC driver state machine.
This function contains the sequence of events in the LTC state machine. It must be called time-triggered, every 1ms.
Definition at line 625 of file ltc_6806.c.
|
static |
local copies of database tables
Definition at line 132 of file ltc_6806.c.
|
static |
Broadcast, Pull-down current, All cells, normal mode, 100ms
Definition at line 241 of file ltc_6806.c.
|
static |
Broadcast, Pull-up current, All cells, normal mode, 100ms
Definition at line 239 of file ltc_6806.c.
|
static |
local copies of database tables
Definition at line 131 of file ltc_6806.c.
|
static |
local copies of database tables
Definition at line 130 of file ltc_6806.c.
|
static |
All cells, normal mode
Definition at line 215 of file ltc_6806.c.
|
static |
Definition at line 195 of file ltc_6806.c.
|
static |
Definition at line 202 of file ltc_6806.c.
|
static |
Definition at line 203 of file ltc_6806.c.
|
static |
Definition at line 204 of file ltc_6806.c.
|
static |
Definition at line 205 of file ltc_6806.c.
|
static |
Definition at line 206 of file ltc_6806.c.
|
static |
Definition at line 207 of file ltc_6806.c.
|
static |
Definition at line 208 of file ltc_6806.c.
|
static |
Definition at line 209 of file ltc_6806.c.
|
static |
Definition at line 210 of file ltc_6806.c.
|
static |
Definition at line 194 of file ltc_6806.c.
|
static |
init in LTC_ResetErrorTable-function
Definition at line 137 of file ltc_6806.c.
|
static |
local copies of database tables
Definition at line 133 of file ltc_6806.c.
|
static |
stores information on the detected open wires locally
Definition at line 136 of file ltc_6806.c.
|
static |
local definition of plausible cell voltage values for the LTC 6806
Definition at line 140 of file ltc_6806.c.
uint16_t ltc_RxPecBuffer[LTC_N_BYTES_FOR_DATA_TRANSMISSION] = {0} |
PEC buffer for RX and TX
Definition at line 121 of file ltc_6806.c.
LTC_STATE_s ltc_stateBase |
This variable contains the internal state of the LTC state machine.
Definition at line 147 of file ltc_6806.c.
uint16_t ltc_TxPecBuffer[LTC_N_BYTES_FOR_DATA_TRANSMISSION] = {0} |
PEC buffer for RX and TX
Definition at line 122 of file ltc_6806.c.
|
static |
index of used cells
Definition at line 127 of file ltc_6806.c.