foxBMS  1.0.0
The foxBMS Battery Management System API Documentation
sbc_fs8x_communication.c File Reference

Implementation of communication logic for NXP SBC FS8x. More...

#include <stdint.h>
#include <stddef.h>
#include "sbc_fs8x_map.h"
#include "sbc_fs8x_assert.h"
#include "sbc_fs8x_common.h"
#include "sbc_fs8x_communication.h"
Include dependency graph for sbc_fs8x_communication.c:

Go to the source code of this file.

Macros

#define FS8x_REG_ADDR_MASK   0x3FU
 
#define FS8x_REG_ADDR_SHIFT   0x01U
 
#define FS8x_I2C_READ_FRAME_LENGTH   1U
 
#define FS8x_I2C_ADDRESS_BASE   0x20U
 
#define FS8x_I2C_FRAME_SIZE   0x05U
 
#define FS8x_I2C_RX_SIZE   0x03U
 
#define FS8x_CRC_TBL_SIZE   256U
 
#define FS8x_COM_CRC_POLYNOM   0x1DU
 
#define FS8x_COM_CRC_INIT   0xFFU
 

Functions

static uint8_t FS8x_CalcCRC (const uint8_t *data, uint8_t dataLen)
 This function calculates CRC value of passed data array. Takes bytes in inverted order due to frame format. More...
 
static fs8x_status_t FS8x_CheckCRC (const uint8_t *data, uint8_t dataLen)
 Performs CRC check of the data array. More...
 
static fs8x_status_t FS8x_SPI_TransferData (SPI_INTERFACE_CONFIG_s *pSpiInterface, fs8x_tx_frame_t *txData, fs8x_rx_frame_t *rxData)
 Performs SPI transfer of the txData. Received frame is saved into rxData structure. More...
 
static void FS8x_SPI_CreateSendFrame (fs8x_tx_frame_t *txData, uint8_t *txFrame)
 Creates a raw frame for SPI transfer. More...
 
fs8x_status_t FS8x_ReadRegister (SPI_INTERFACE_CONFIG_s *pSpiInterface, fs8x_drv_data_t *drvData, bool isFailSafe, uint8_t address, fs8x_rx_frame_t *rxData)
 Performs a read from a single FS8x register. More...
 
fs8x_status_t FS8x_WriteRegister (SPI_INTERFACE_CONFIG_s *pSpiInterface, fs8x_drv_data_t *drvData, bool isFailSafe, uint8_t address, uint16_t writeData)
 Sends write command to the FS8x. More...
 
fs8x_status_t FS8x_WriteRegisterInit (SPI_INTERFACE_CONFIG_s *pSpiInterface, fs8x_drv_data_t *drvData, uint8_t address, uint16_t writeData)
 Performs a write to a single FS8x FS init register (during the INIT_FS phase only). More...
 
fs8x_status_t FS8x_UpdateRegister (SPI_INTERFACE_CONFIG_s *pSpiInterface, fs8x_drv_data_t *drvData, bool isFailSafe, uint8_t address, int16_t mask, uint16_t writeData)
 Performs update of a single register. It affects bits specified by a bit mask. More...
 

Variables

static const uint8_t FS8x_CRC_TABLE [FS8x_CRC_TBL_SIZE]
 CRC lookup table. More...
 

Detailed Description

Implementation of communication logic for NXP SBC FS8x.

Author
nxf44615
Version
1.1
Date
9-Oct-2018
Updated
2020-03-18 (date of last update) Adapted driver to pass interface configuration as parameter into the functions to enable the usage of multiple ICs in the system.

Definition in file sbc_fs8x_communication.c.

Macro Definition Documentation

◆ FS8x_COM_CRC_INIT

#define FS8x_COM_CRC_INIT   0xFFU

CRC initial value.

Definition at line 73 of file sbc_fs8x_communication.c.

◆ FS8x_COM_CRC_POLYNOM

#define FS8x_COM_CRC_POLYNOM   0x1DU

CRC polynom.

Definition at line 72 of file sbc_fs8x_communication.c.

◆ FS8x_CRC_TBL_SIZE

#define FS8x_CRC_TBL_SIZE   256U

Size of CRC table.

Definition at line 71 of file sbc_fs8x_communication.c.

◆ FS8x_I2C_ADDRESS_BASE

#define FS8x_I2C_ADDRESS_BASE   0x20U

I2C device base address

Definition at line 66 of file sbc_fs8x_communication.c.

◆ FS8x_I2C_FRAME_SIZE

#define FS8x_I2C_FRAME_SIZE   0x05U

Length of the complete I2C frame

Definition at line 67 of file sbc_fs8x_communication.c.

◆ FS8x_I2C_READ_FRAME_LENGTH

#define FS8x_I2C_READ_FRAME_LENGTH   1U

Length of the data frame for I2C read command.

Definition at line 65 of file sbc_fs8x_communication.c.

◆ FS8x_I2C_RX_SIZE

#define FS8x_I2C_RX_SIZE   0x03U

Length of the received I2C data frame

Definition at line 68 of file sbc_fs8x_communication.c.

◆ FS8x_REG_ADDR_MASK

#define FS8x_REG_ADDR_MASK   0x3FU

< Length of the communication frame Register address mask

Definition at line 61 of file sbc_fs8x_communication.c.

◆ FS8x_REG_ADDR_SHIFT

#define FS8x_REG_ADDR_SHIFT   0x01U

SPI register address shift

Definition at line 62 of file sbc_fs8x_communication.c.

Function Documentation

◆ FS8x_CalcCRC()

static uint8_t FS8x_CalcCRC ( const uint8_t *  data,
uint8_t  dataLen 
)
static

This function calculates CRC value of passed data array. Takes bytes in inverted order due to frame format.

Parameters
[in]dataData array.
[in]dataLenLength of the data array.
Returns
CRC8

Definition at line 344 of file sbc_fs8x_communication.c.

◆ FS8x_CheckCRC()

static fs8x_status_t FS8x_CheckCRC ( const uint8_t *  data,
uint8_t  dataLen 
)
static

Performs CRC check of the data array.

CRC is expected in the first array item (index 0).

Parameters
[in]dataData array.
[in]dataLenLength of the data array.
Returns
Returns fs8xStatusOk if CRC is correct.

Definition at line 365 of file sbc_fs8x_communication.c.

Here is the call graph for this function:

◆ FS8x_SPI_CreateSendFrame()

static void FS8x_SPI_CreateSendFrame ( fs8x_tx_frame_t txData,
uint8_t *  txFrame 
)
static

Creates a raw frame for SPI transfer.

Parameters
[in]txDataTX data.
[out]txFrameTX frame for SPI transfer.

Definition at line 211 of file sbc_fs8x_communication.c.

Here is the call graph for this function:

◆ FS8x_SPI_TransferData()

static fs8x_status_t FS8x_SPI_TransferData ( SPI_INTERFACE_CONFIG_s pSpiInterface,
fs8x_tx_frame_t txData,
fs8x_rx_frame_t rxData 
)
static

Performs SPI transfer of the txData. Received frame is saved into rxData structure.

Parameters
[in,out]pSpiInterfaceSPI communication interface config
[in]txDataTX data.
[out]rxDataRX data. Can be NULL in case of write-only command.
Returns
Status return code.

Definition at line 180 of file sbc_fs8x_communication.c.

Here is the call graph for this function:

Variable Documentation

◆ FS8x_CRC_TABLE

const uint8_t FS8x_CRC_TABLE[FS8x_CRC_TBL_SIZE]
static
Initial value:
= {
0x00U, 0x1DU, 0x3AU, 0x27U, 0x74U, 0x69U, 0x4EU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U, 0x9BU, 0x86U, 0xD5U, 0xC8U, 0xEFU, 0xF2U, 0x49U,
0x54U, 0x73U, 0x6EU, 0x3DU, 0x20U, 0x07U, 0x1AU, 0x6CU, 0x71U, 0x56U, 0x4BU, 0x18U, 0x05U,
0x22U, 0x3FU, 0x84U, 0x99U, 0xBEU, 0xA3U, 0xF0U, 0xEDU, 0xCAU, 0xD7U, 0x35U, 0x28U, 0x0FU,
0x12U, 0x41U, 0x5CU, 0x7BU, 0x66U, 0xDDU, 0xC0U, 0xE7U, 0xFAU, 0xA9U, 0xB4U, 0x93U, 0x8EU,
0xF8U, 0xE5U, 0xC2U, 0xDFU, 0x8CU, 0x91U, 0xB6U, 0xABU, 0x10U, 0x0DU, 0x2AU, 0x37U, 0x64U,
0x79U, 0x5EU, 0x43U, 0xB2U, 0xAFU, 0x88U, 0x95U, 0xC6U, 0xDBU, 0xFCU, 0xE1U, 0x5AU, 0x47U,
0x60U, 0x7DU, 0x2EU, 0x33U, 0x14U, 0x09U, 0x7FU, 0x62U, 0x45U, 0x58U, 0x0BU, 0x16U, 0x31U,
0x2CU, 0x97U, 0x8AU, 0xADU, 0xB0U, 0xE3U, 0xFEU, 0xD9U, 0xC4U
}

CRC lookup table.

Definition at line 80 of file sbc_fs8x_communication.c.