foxBMS  1.6.0
The foxBMS Battery Management System API Documentation
adi_ades183x_helpers.h File Reference

Headers for the diagnostic driver for the ADI analog front-end. More...

#include "adi_ades183x_cfg.h"
#include "adi_ades183x_defs.h"
#include <stdint.h>
Include dependency graph for adi_ades183x_helpers.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void ADI_TransmitCommand (uint16_t *command, ADI_STATE_s *adiState)
 send command to the ades183x daisy-chain (e.g., start voltage measurement). More...
 
void ADI_CopyCommandBits (const uint16_t *sourceCommand, uint16_t *destinationCommand)
 copy command bits in variables. More...
 
void ADI_WriteCommandConfigurationBits (uint16_t *configuredCommand, uint8_t position, uint8_t length, uint16_t configuration)
 write configuration bits in commands (e.g., channel in ADAX command). More...
 
void ADI_ReadDataBits (uint8_t receivedData, uint8_t *pDataToRead, uint8_t position, uint8_t mask)
 Helper function to read specific bits from received data. More...
 
void ADI_ReadRegister (uint16_t *registerToRead, uint8_t *data, ADI_STATE_s *adiState)
 send command to the ades183x daisy-chain to read a register. More...
 
void ADI_StoredConfigurationWriteToAfeGlobal (ADI_STATE_s *adiState)
 Sends data in the configuration stored in driver to all AFEs in the daisy chain, for all configuration registers. More...
 
STD_RETURN_TYPE_e ADI_CheckConfigurationRegister (ADI_CFG_REGISTER_SET_e registerSet, ADI_STATE_s *adiState)
 Compares the configuration stored in the AFE driver with the configuration read from the AFEs. More...
 
STD_RETURN_TYPE_e ADI_StoredConfigurationWriteToAfe (ADI_CFG_REGISTER_SET_e registerSet, ADI_STATE_s *adiState)
 Sends data in the configuration stored in driver to all AFEs in the daisy chain, for a specific configuration register. More...
 
void ADI_WriteRegisterGlobal (const uint16_t *registerToWrite, uint8_t *data, ADI_PEC_FAULT_INJECTION_e pecFaultInjection, ADI_STATE_s *adiState)
 Write the same 6 bytes to all devices in the daisy-chain. More...
 
void ADI_ClearCommandCounter (ADI_STATE_s *adiState)
 Send RSTCC to AFEs in daisy-chain and clear command counter of AFE driver. More...
 
void ADI_SpiTransmitReceiveData (ADI_STATE_s *adiState, uint16_t *pTxBuff, uint16_t *pRxBuff, uint32_t frameLength)
 Transmits and receives data on SPI. More...
 
void ADI_StoredConfigurationFillRegisterDataGlobal (ADI_CFG_REGISTER_SET_e registerSet, uint8_t registerOffset, uint8_t data, uint8_t position, uint8_t mask, ADI_STATE_s *adiState)
 Writes data in the configuration stored in AFE driver, for all AFEs in the daisy-chain. More...
 
void ADI_Wait (uint32_t waitTime)
 wait for a certain number of milliseconds More...
 
void ADI_WriteDataBits (uint8_t *pSentData, uint8_t dataToWrite, uint8_t position, uint8_t mask)
 Helper function to write specific bits in data to be sent. More...
 
void ADI_WriteRegister (const uint16_t *registerToWrite, uint8_t *data, ADI_PEC_FAULT_INJECTION_e pecFaultInjection, ADI_STATE_s *adiState)
 sends command to the ades183x daisy-chain to write data. More...
 

Detailed Description

Headers for the diagnostic driver for the ADI analog front-end.

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:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

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:

  • ″This product uses parts of foxBMS®″
  • ″This product includes parts of foxBMS®″
  • ″This product is derived from foxBMS®″
Author
foxBMS Team
Date
2022-12-06 (date of creation)
Updated
2023-10-12 (date of last update)
Version
v1.6.0
Prefix
ADI

Definition in file adi_ades183x_helpers.h.

Function Documentation

◆ ADI_CheckConfigurationRegister()

STD_RETURN_TYPE_e ADI_CheckConfigurationRegister ( ADI_CFG_REGISTER_SET_e  registerSet,
ADI_STATE_s adiState 
)

Compares the configuration stored in the AFE driver with the configuration read from the AFEs.

If the stored and read configuration match, the corresponding flag is set to true in the error table, otherwise it is set to false.

Parameters
registerSetconfiguration register to check
adiStatestate of the driver
Returns
STD_OK if check was OK, STD_NOT_OK otherwise

Definition at line 161 of file adi_ades183x_helpers.c.

◆ ADI_ClearCommandCounter()

void ADI_ClearCommandCounter ( ADI_STATE_s adiState)

Send RSTCC to AFEs in daisy-chain and clear command counter of AFE driver.

Parameters
adiStatestate of the driver

SM_SPI_CNT: SPI Frame Counter Reset driver stored value of command counter by sending RSTCC command.

Definition at line 547 of file adi_ades183x_helpers.c.

Here is the call graph for this function:

◆ ADI_CopyCommandBits()

void ADI_CopyCommandBits ( const uint16_t *  sourceCommand,
uint16_t *  destinationCommand 
)

copy command bits in variables.

The commands are defined as const. As some of them have configuration bits, they are first copied in a non-const variable. They can then be configured with ADI_WriteCommandConfigurationBits().

Parameters
sourceCommandcommand definition from command list
destinationCommandcopied command bits from command definition

Definition at line 260 of file adi_ades183x_helpers.c.

◆ ADI_ReadDataBits()

void ADI_ReadDataBits ( uint8_t  receivedData,
uint8_t *  pDataToRead,
uint8_t  position,
uint8_t  mask 
)

Helper function to read specific bits from received data.

Parameters
receivedDatadata received from the AFEs
pDataToReadspecific bits read from received data
positionposition where to read the bits in received data
maskmask corresponding to bits to read

Definition at line 268 of file adi_ades183x_helpers.c.

◆ ADI_ReadRegister()

void ADI_ReadRegister ( uint16_t *  registerToRead,
uint8_t *  data,
ADI_STATE_s adiState 
)

send command to the ades183x daisy-chain to read a register.

This is the core function to receive data from the ades183x daisy-chain. A 2 byte command is sent with the corresponding PEC. Example: Read configuration register (RDCFG). The data send is: 2 bytes (COMMAND) 2 bytes (PEC) The data received is: 6 bytes (IC1) 2 bytes (PEC) + 6 bytes (IC2) 2 bytes (PEC)

  • 6 bytes (IC3) 2 bytes (PEC)
  • ...
  • 6 bytes (IC{ADI_N_ADI}) 2 bytes (PEC) The function does not check the PECs. This has to be done elsewhere.
    Parameters
    registerToReadregister to be read
    dataread data
    adiStatestate of the driver

SM_SPI_PEC: SPI Packet Error Code Calculate PEC for command.

SM_SPI_PEC: SPI Packet Error Code PEC check on read value.

SM_SPI_CNT: SPI Frame Counter Compare driver stored value of command counter with values sent by the AFEs.

command counter flag stays set as soon as an error was detected it can only be reset within the reset function

Definition at line 284 of file adi_ades183x_helpers.c.

Here is the call graph for this function:

◆ ADI_SpiTransmitReceiveData()

void ADI_SpiTransmitReceiveData ( ADI_STATE_s adiState,
uint16_t *  pTxBuff,
uint16_t *  pRxBuff,
uint32_t  frameLength 
)

Transmits and receives data on SPI.

Parameters
adiStatestate of the ADI driver
pTxBuffpointer to data that is transmitted by the SPI interface
pRxBuffpointer to data that is received by the SPI interface
frameLengthnumber of bytes to be transmitted by the SPI interface

Definition at line 398 of file adi_ades183x_helpers.c.

Here is the call graph for this function:

◆ ADI_StoredConfigurationFillRegisterDataGlobal()

void ADI_StoredConfigurationFillRegisterDataGlobal ( ADI_CFG_REGISTER_SET_e  registerSet,
uint8_t  registerOffset,
uint8_t  data,
uint8_t  position,
uint8_t  mask,
ADI_STATE_s adiState 
)

Writes data in the configuration stored in AFE driver, for all AFEs in the daisy-chain.

Does the same as ADI_StoredConfigurationFillRegisterData(), but for all AFEs in the daisy chain.

Parameters
registerSetconfiguration register to address
registerOffsetposition of byte to address in configuration register
datadata to write to byte in register
positionposition where to store the data in byte
maskmask corresponding to data to store
adiStatestate of the driver

Definition at line 456 of file adi_ades183x_helpers.c.

Here is the call graph for this function:

◆ ADI_StoredConfigurationWriteToAfe()

STD_RETURN_TYPE_e ADI_StoredConfigurationWriteToAfe ( ADI_CFG_REGISTER_SET_e  registerSet,
ADI_STATE_s adiState 
)

Sends data in the configuration stored in driver to all AFEs in the daisy chain, for a specific configuration register.

Parameters
registerSetconfiguration register to write
adiStatestate of the driver
Returns
STD_OK if check made after writing was OK, STD_NOT_OK otherwise

Definition at line 226 of file adi_ades183x_helpers.c.

Here is the call graph for this function:

◆ ADI_StoredConfigurationWriteToAfeGlobal()

void ADI_StoredConfigurationWriteToAfeGlobal ( ADI_STATE_s adiState)

Sends data in the configuration stored in driver to all AFEs in the daisy chain, for all configuration registers.

Parameters
adiStatestate of the driver

Definition at line 531 of file adi_ades183x_helpers.c.

Here is the call graph for this function:

◆ ADI_TransmitCommand()

void ADI_TransmitCommand ( uint16_t *  command,
ADI_STATE_s adiState 
)

send command to the ades183x daisy-chain (e.g., start voltage measurement).

Parameters
commandcommand to be sent
adiStatestate of the driver

SM_SPI_PEC: SPI Packet Error Code Calculate PEC for command.

SM_SPI_CNT: SPI Frame Counter Increment driver stored value of command counter if command causes increase.

If command increments AFE command counter, increment driver command counter

Definition at line 480 of file adi_ades183x_helpers.c.

Here is the call graph for this function:

◆ ADI_Wait()

void ADI_Wait ( uint32_t  waitTime)

wait for a certain number of milliseconds

This function is used to wait for a definite amount of time. In foxBMS, block task running ades183x. The task cannot be woken up before the time has elapsed.

Parameters
waitTimetime in ms during which task will be blocked

Definition at line 563 of file adi_ades183x_helpers.c.

Here is the call graph for this function:

◆ ADI_WriteCommandConfigurationBits()

void ADI_WriteCommandConfigurationBits ( uint16_t *  configuredCommand,
uint8_t  position,
uint8_t  length,
uint16_t  configuration 
)

write configuration bits in commands (e.g., channel in ADAX command).

Parameters
configuredCommandcommand in which bits are configured
positionstart bit of configuration field to write
lengthlength of configuration field to write
configurationconfiguration to write to the configuration field

Definition at line 204 of file adi_ades183x_helpers.c.

◆ ADI_WriteDataBits()

void ADI_WriteDataBits ( uint8_t *  pSentData,
uint8_t  dataToWrite,
uint8_t  position,
uint8_t  mask 
)

Helper function to write specific bits in data to be sent.

Parameters
pSentDatadata to send to the AFEs
dataToWritespecific bits to write in data to be sent
positionposition where to write the bits in data to send
maskmask corresponding to bits to write

Definition at line 572 of file adi_ades183x_helpers.c.

◆ ADI_WriteRegister()

void ADI_WriteRegister ( const uint16_t *  registerToWrite,
uint8_t *  data,
ADI_PEC_FAULT_INJECTION_e  pecFaultInjection,
ADI_STATE_s adiState 
)

sends command to the ades183x daisy-chain to write data.

This is the core function to transmit data to the ades183x daisy-chain. The data sent is: COMMAND + 6 bytes (IC1) + 6 bytes (IC2)

  • 6 bytes (IC3)
  • ...
  • 6 bytes (IC{ADI_N_ADI}) A 2 byte command is sent with the corresponding PEC. Example: write configuration register (WRCFG). The command has to be set and then the function calculates the PEC automatically. The function calculates the needed PEC to send the data to the daisy-chain. The sent data has the format: 2 byte-COMMAND (2 bytes PEC) + 6 bytes (IC1) (2 bytes PEC)
  • 6 bytes (IC2) (2 bytes PEC)
  • 6 bytes (IC3) (2 bytes PEC)
  • ...
  • 6 bytes (IC{ADI_N_ADI}) (2 bytes PEC) The pecFaultInjection parameters is used to inject faults in the command PEC or in the data PEC. It is used for diagnostics. The default value is ADI_PEC_NO_FAULT_INJECTION, in this case the correct PECs are transmitted.
    Parameters
    registerToWriteregister to write
    datadata to write in register
    adiStatestate of the driver
    pecFaultInjectionused for diagnostics to inject faults in PEC

SM_SPI_PEC: SPI Packet Error Code Calculate PEC for command.

SM_SPI_PEC: SPI Packet Error Code Calculate PEC for values to be sent to the daisy-chain.

SM_SPI_CNT: SPI Frame Counter Increment driver stored value of command counter if command causes increase.

Definition at line 588 of file adi_ades183x_helpers.c.

Here is the call graph for this function:

◆ ADI_WriteRegisterGlobal()

void ADI_WriteRegisterGlobal ( const uint16_t *  registerToWrite,
uint8_t *  data,
ADI_PEC_FAULT_INJECTION_e  pecFaultInjection,
ADI_STATE_s adiState 
)

Write the same 6 bytes to all devices in the daisy-chain.

Parameters
registerToWriteregister to write
datadata to write in register
pecFaultInjectionused for diagnostics to inject faults in PEC
adiStatestate of the driver

Definition at line 513 of file adi_ades183x_helpers.c.

Here is the call graph for this function: