foxBMS  1.1.2
The foxBMS Battery Management System API Documentation
sbc_fs8x_communication.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 - 2018, NXP Semiconductors, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * o Redistributions of source code must retain the above copyright notice, this list
9  * of conditions and the following disclaimer.
10  *
11  * o Redistributions in binary form must reproduce the above copyright notice, this
12  * list of conditions and the following disclaimer in the documentation and/or
13  * other materials provided with the distribution.
14  *
15  * o Neither the name of the copyright holder nor the names of its
16  * contributors may be used to endorse or promote products derived from this
17  * software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 /** @file sbc_fs8x_communication.c
32  * @brief Implementation of communication logic for NXP SBC FS8x.
33  *
34  * @author nxf44615
35  * @version 1.1
36  * @date 9-Oct-2018
37  * @copyright Copyright (c) 2016 - 2018, NXP Semiconductors, Inc.
38  *
39  * @updated 2020-03-18 (date of last update)
40  * Adapted driver to pass interface configuration as parameter into the
41  * functions to enable the usage of multiple ICs in the system.
42  */
43 
44 /*******************************************************************************
45  * Includes
46  ******************************************************************************/
47 
48 #include <stdint.h>
49 #include <stddef.h>
50 
51 #include "sbc_fs8x_map.h"
52 #include "sbc_fs8x_assert.h"
53 #include "sbc_fs8x_common.h"
54 #include "sbc_fs8x_communication.h"
55 
56 /*******************************************************************************
57  * Definitions
58  ******************************************************************************/
59 /* Data frame (SPI or I2C). */
60 /* #define FS8x_COMM_FRAME_SIZE (0x04U) */ /*!< Length of the communication frame */ /* Moved to sbc_fs8x_communication.h file */
61 #define FS8x_REG_ADDR_MASK 0x3FU /*!< Register address mask */
62 #define FS8x_REG_ADDR_SHIFT 0x01U /*!< SPI register address shift */
63 
64 /* I2C frame. */
65 #define FS8x_I2C_READ_FRAME_LENGTH 1U /*!< Length of the data frame for I2C read command. */
66 #define FS8x_I2C_ADDRESS_BASE 0x20U /*!< I2C device base address */
67 #define FS8x_I2C_FRAME_SIZE 0x05U /*!< Length of the complete I2C frame */
68 #define FS8x_I2C_RX_SIZE 0x03U /*!< Length of the received I2C data frame */
69 
70 /* CRC polynomial used for SPI and I2C communication. */
71 #define FS8x_CRC_TBL_SIZE 256U /*!< Size of CRC table. */
72 #define FS8x_COM_CRC_POLYNOM 0x1DU /*!< CRC polynom. */
73 #define FS8x_COM_CRC_INIT 0xFFU /*!< CRC initial value. */
74 
75 /*******************************************************************************
76  * Constants
77  ******************************************************************************/
78 
79 /** @brief CRC lookup table. */
80 static const uint8_t FS8x_CRC_TABLE[FS8x_CRC_TBL_SIZE] = {
81  0x00U, 0x1DU, 0x3AU, 0x27U, 0x74U, 0x69U, 0x4EU, 0x53U, 0xE8U, 0xF5U, 0xD2U, 0xCFU, 0x9CU,
82  0x81U, 0xA6U, 0xBBU, 0xCDU, 0xD0U, 0xF7U, 0xEAU, 0xB9U, 0xA4U, 0x83U, 0x9EU, 0x25U, 0x38U,
83  0x1FU, 0x02U, 0x51U, 0x4CU, 0x6BU, 0x76U, 0x87U, 0x9AU, 0xBDU, 0xA0U, 0xF3U, 0xEEU, 0xC9U,
84  0xD4U, 0x6FU, 0x72U, 0x55U, 0x48U, 0x1BU, 0x06U, 0x21U, 0x3CU, 0x4AU, 0x57U, 0x70U, 0x6DU,
85  0x3EU, 0x23U, 0x04U, 0x19U, 0xA2U, 0xBFU, 0x98U, 0x85U, 0xD6U, 0xCBU, 0xECU, 0xF1U, 0x13U,
86  0x0EU, 0x29U, 0x34U, 0x67U, 0x7AU, 0x5DU, 0x40U, 0xFBU, 0xE6U, 0xC1U, 0xDCU, 0x8FU, 0x92U,
87  0xB5U, 0xA8U, 0xDEU, 0xC3U, 0xE4U, 0xF9U, 0xAAU, 0xB7U, 0x90U, 0x8DU, 0x36U, 0x2BU, 0x0CU,
88  0x11U, 0x42U, 0x5FU, 0x78U, 0x65U, 0x94U, 0x89U, 0xAEU, 0xB3U, 0xE0U, 0xFDU, 0xDAU, 0xC7U,
89  0x7CU, 0x61U, 0x46U, 0x5BU, 0x08U, 0x15U, 0x32U, 0x2FU, 0x59U, 0x44U, 0x63U, 0x7EU, 0x2DU,
90  0x30U, 0x17U, 0x0AU, 0xB1U, 0xACU, 0x8BU, 0x96U, 0xC5U, 0xD8U, 0xFFU, 0xE2U, 0x26U, 0x3BU,
91  0x1CU, 0x01U, 0x52U, 0x4FU, 0x68U, 0x75U, 0xCEU, 0xD3U, 0xF4U, 0xE9U, 0xBAU, 0xA7U, 0x80U,
92  0x9DU, 0xEBU, 0xF6U, 0xD1U, 0xCCU, 0x9FU, 0x82U, 0xA5U, 0xB8U, 0x03U, 0x1EU, 0x39U, 0x24U,
93  0x77U, 0x6AU, 0x4DU, 0x50U, 0xA1U, 0xBCU, 0x9BU, 0x86U, 0xD5U, 0xC8U, 0xEFU, 0xF2U, 0x49U,
94  0x54U, 0x73U, 0x6EU, 0x3DU, 0x20U, 0x07U, 0x1AU, 0x6CU, 0x71U, 0x56U, 0x4BU, 0x18U, 0x05U,
95  0x22U, 0x3FU, 0x84U, 0x99U, 0xBEU, 0xA3U, 0xF0U, 0xEDU, 0xCAU, 0xD7U, 0x35U, 0x28U, 0x0FU,
96  0x12U, 0x41U, 0x5CU, 0x7BU, 0x66U, 0xDDU, 0xC0U, 0xE7U, 0xFAU, 0xA9U, 0xB4U, 0x93U, 0x8EU,
97  0xF8U, 0xE5U, 0xC2U, 0xDFU, 0x8CU, 0x91U, 0xB6U, 0xABU, 0x10U, 0x0DU, 0x2AU, 0x37U, 0x64U,
98  0x79U, 0x5EU, 0x43U, 0xB2U, 0xAFU, 0x88U, 0x95U, 0xC6U, 0xDBU, 0xFCU, 0xE1U, 0x5AU, 0x47U,
99  0x60U, 0x7DU, 0x2EU, 0x33U, 0x14U, 0x09U, 0x7FU, 0x62U, 0x45U, 0x58U, 0x0BU, 0x16U, 0x31U,
100  0x2CU, 0x97U, 0x8AU, 0xADU, 0xB0U, 0xE3U, 0xFEU, 0xD9U, 0xC4U
101 };
102 
103 /*******************************************************************************
104  * Local Functions Prototypes
105  ******************************************************************************/
106 
107 /** @brief This function calculates CRC value of passed data array.
108  * Takes bytes in inverted order due to frame format.
109  * @param [in] data Data array.
110  * @param [in] dataLen Length of the data array.
111  * @return CRC8 */
112 static uint8_t FS8x_CalcCRC(const uint8_t* data, uint8_t dataLen);
113 
114 /** @brief Performs CRC check of the data array.
115  *
116  * CRC is expected in the first array item (index 0).
117  * @param [in] data Data array.
118  * @param [in] dataLen Length of the data array.
119  * @return Returns @ref fs8xStatusOk if CRC is correct. */
120 static fs8x_status_t FS8x_CheckCRC(const uint8_t* data, uint8_t dataLen);
121 
122 #if (FS8x_COMM_TYPE == FS8x_COMM_SPI || FS8x_COMM_TYPE == FS8x_COMM_BOTH)
123 
124 /** @brief Performs SPI transfer of the txData. Received frame is saved into
125  * rxData structure.
126  * @param [in,out] pSpiInterface SPI communication interface config
127  * @param [in] txData TX data.
128  * @param [out] rxData RX data. Can be NULL in case of write-only command.
129  * @return @ref fs8x_status_t "Status return code." */
131  fs8x_rx_frame_t* rxData);
132 
133 /** @brief Creates a raw frame for SPI transfer.
134  * @param [in] txData TX data.
135  * @param [out] txFrame TX frame for SPI transfer. */
136 static void FS8x_SPI_CreateSendFrame(fs8x_tx_frame_t* txData, uint8_t* txFrame);
137 
138 #endif
139 
140 #if (FS8x_COMM_TYPE == FS8x_COMM_I2C || FS8x_COMM_TYPE == FS8x_COMM_BOTH)
141 
142 /** @brief Performs I2C register read.
143  * @param [in] drvData Driver run-time data.
144  * @param [in] txData TX data.
145  * @param [out] rxData RX data.
146  * @return @ref fs8x_status_t "Status return code." */
147 static fs8x_status_t FS8x_I2C_ReadRegister(fs8x_drv_data_t* drvData, fs8x_tx_frame_t* txData,
148  fs8x_rx_frame_t* rxData);
149 
150 /** @brief Performs I2C register write.
151  * @param [in] drvData Driver run-time data.
152  * @param [in] txData TX data.
153  * @return @ref fs8x_status_t "Status return code." */
154 static fs8x_status_t FS8x_I2C_WriteRegister(fs8x_drv_data_t* drvData, fs8x_tx_frame_t* txData);
155 
156 /** @brief Returns 7-bit I2C address.
157  * @param [in] drvData Driver run-time data.
158  * @param [in] txData TX data.
159  * @return FS8x I2C address. */
160 static uint8_t GetI2CAddress(fs8x_drv_data_t* drvData, fs8x_tx_frame_t* txData);
161 
162 #endif
163 
164 /*******************************************************************************
165  * Local Variables
166  ******************************************************************************/
167 
168 /*******************************************************************************
169  * Global Variables
170  ******************************************************************************/
171 
172 /*******************************************************************************
173  * Local Functions - Implementation
174  ******************************************************************************/
175 
176 #if (FS8x_COMM_TYPE == FS8x_COMM_SPI || FS8x_COMM_TYPE == FS8x_COMM_BOTH)
177 
178 /* Performs SPI transfer of the txData. Received frame is saved into
179  * rxData structure. */
181  fs8x_rx_frame_t* rxData)
182 {
183  fs8x_status_t status = fs8xStatusOk;
184  uint8_t txFrame[FS8x_COMM_FRAME_SIZE] = {0};
185  uint8_t rxFrame[FS8x_COMM_FRAME_SIZE] = {0};
186 
187  FS_ASSERT(txData != NULL);
188 
189  FS8x_SPI_CreateSendFrame(txData, txFrame);
190  status = MCU_SPI_TransferData(pSpiInterface, txFrame, FS8x_COMM_FRAME_SIZE, rxFrame);
191  if (status != fs8xStatusOk)
192  {
193  return status;
194  }
195 
196  status = FS8x_CheckCRC(rxFrame, FS8x_COMM_FRAME_SIZE);
197  if (status != fs8xStatusOk)
198  {
199  return status;
200  }
201 
202  if (rxData != NULL)
203  {
204  rxData->deviceStatus = rxFrame[3];
205  rxData->readData = (uint16_t)(rxFrame[2] << 8U | rxFrame[1]);
206  }
207  return status;
208 }
209 
210 /* Creates a raw frame for SPI transfer. */
211 static void FS8x_SPI_CreateSendFrame(fs8x_tx_frame_t* txData, uint8_t* txFrame)
212 {
213  FS_ASSERT(txData != NULL);
214  FS_ASSERT(txFrame != NULL);
215 
216  /* Selects register set (main x fail-safe). */
217  txFrame[3] |= txData->isFailSafe ? 0x80U : 0x00U;
218 
219  /* Sets address of the register. */
220  txFrame[3] |= FS8x_BO_SETVAL_EXT(txFrame[3], txData->registerAddress, \
222 
223  /* check if register is r or w */
224  switch (txData->commandType)
225  {
226  case fs8xRegRead:
227  /* Creates read command. */
228  txFrame[3] = FS8x_BO_SETVAL(txFrame[3], 0x00U, 0x01U);
229  /* No data to be sent. */
230  txFrame[2] = 0x00;
231  txFrame[1] = 0x00;
232  break;
233 
234  case fs8xRegWrite:
235  /* Creates write command. */
236  txFrame[3] = FS8x_BO_SETVAL(txFrame[3], 0x01U, 0x01U);
237  /* Sets data - MSB first. */
238  txFrame[2] = (uint8_t)(txData->writeData >> 8);
239  txFrame[1] = (uint8_t)(txData->writeData);
240  break;
241  }
242 
243  /* Sets CRC. */
244  txFrame[0] = FS8x_CalcCRC(txFrame, FS8x_COMM_FRAME_SIZE);
245 }
246 
247 #endif
248 
249 #if (FS8x_COMM_TYPE == FS8x_COMM_I2C || FS8x_COMM_TYPE == FS8x_COMM_BOTH)
250 
251 /* Performs I2C register read. */
252 static fs8x_status_t FS8x_I2C_ReadRegister(fs8x_drv_data_t* drvData, fs8x_tx_frame_t* txData,
253  fs8x_rx_frame_t* rxData)
254 {
255  fs8x_status_t status = fs8xStatusOk;
256  uint8_t i2cAddress;
257  uint8_t txFrame[FS8x_I2C_READ_FRAME_LENGTH] = {0};
258  uint8_t rxFrame[FS8x_I2C_FRAME_SIZE] = {0};
259 
260  FS_ASSERT(drvData != NULL);
261  FS_ASSERT(txData != NULL);
262  FS_ASSERT(rxData != NULL);
263 
264  i2cAddress = GetI2CAddress(drvData, txData);
265  txFrame[0] = txData->registerAddress;
266 
267  /* Send I2C write command with register address only */
268  status |= MCU_I2C_SendData(txFrame, FS8x_I2C_READ_FRAME_LENGTH, i2cAddress);
269  if (status != fs8xStatusOk)
270  {
271  return status;
272  }
273 
274  /* Read I2C response. */
275  status |= MCU_I2C_ReceiveData(FS8x_I2C_RX_SIZE, i2cAddress, rxFrame);
276  if (status != fs8xStatusOk)
277  {
278  return status;
279  }
280 
281  /* I2C response frame contains just data and CRC.
282  * The Device address and Register address is added
283  * for proper CRC check. */
284  rxFrame[3] = txData->registerAddress;
285  rxFrame[4] = (uint8_t)((i2cAddress << 1U) | 0x01U); /* R/W bit is 1 for I2C read */
286 
287  status = FS8x_CheckCRC(rxFrame, FS8x_I2C_FRAME_SIZE);
288  if (status != fs8xStatusOk)
289  {
290  return status;
291  }
292  rxData->readData = (uint16_t)(rxFrame[2] << 8U | rxFrame[1]);
293 
294  return status;
295 }
296 
297 /* Performs I2C register write. */
298 static fs8x_status_t FS8x_I2C_WriteRegister(fs8x_drv_data_t* drvData, fs8x_tx_frame_t* txData)
299 {
300  uint8_t txFrame[FS8x_I2C_FRAME_SIZE] = {0};
301  uint8_t i2cAddress = FS8x_I2C_ADDRESS_BASE;
302 
303  FS_ASSERT(drvData != NULL);
304  FS_ASSERT(txData != NULL);
305 
306  i2cAddress = GetI2CAddress(drvData, txData);
307 
308  txFrame[4] = (uint8_t)(i2cAddress << 1U); /* R/W bit is 0 for write */
309 
310  /* Sets address of the register (first two bits are ignored). */
311  txFrame[3] = txData->registerAddress & FS8x_REG_ADDR_MASK;
312 
313  /* Sets data - MSB first. */
314  txFrame[2] = (uint8_t)(txData->writeData >> 8);
315  txFrame[1] = (uint8_t)(txData->writeData);
316 
317  /* Sets CRC. */
318  txFrame[0] = FS8x_CalcCRC(txFrame, FS8x_I2C_FRAME_SIZE);
319 
320  return MCU_I2C_SendData(txFrame, FS8x_COMM_FRAME_SIZE, i2cAddress);
321 }
322 
323 /* Returns 7-bit I2C address. */
324 static uint8_t GetI2CAddress(fs8x_drv_data_t* drvData, fs8x_tx_frame_t* txData)
325 {
326  uint8_t i2cAddress = FS8x_I2C_ADDRESS_BASE;
327 
328  FS_ASSERT(drvData != NULL);
329  FS_ASSERT(txData != NULL);
330 
331  i2cAddress = FS8x_BO_SETVAL(i2cAddress, drvData->i2cAddressOtp << 1, 0x1EU);
332  if (txData->isFailSafe)
333  {
334  /* Set bit 33 if register is FS. */
335  i2cAddress = FS8x_BO_SETVAL(i2cAddress, 0x01U, 0x01U);
336  }
337  return i2cAddress;
338 }
339 
340 #endif
341 
342 /* This function calculates CRC value of passed data array.
343  * Takes bytes in inverted order due to frame format. */
344 static uint8_t FS8x_CalcCRC(const uint8_t* data, uint8_t dataLen)
345 {
346  uint8_t crc; /* Result. */
347  uint8_t tableIdx; /* Index to the CRC table. */
348  uint8_t dataIdx; /* Index to the data array (memory). */
349 
350  FS_ASSERT(data != NULL);
351  FS_ASSERT(dataLen > 0);
352 
353  /* Set CRC seed value. */
354  crc = FS8x_COM_CRC_INIT;
355 
356  for (dataIdx = dataLen - 1; dataIdx > 0; dataIdx--)
357  {
358  tableIdx = crc ^ data[dataIdx];
359  crc = FS8x_CRC_TABLE[tableIdx];
360  }
361  return crc;
362 }
363 
364 /* Performs CRC check of the data array. */
365 static fs8x_status_t FS8x_CheckCRC(const uint8_t* data, uint8_t dataLen)
366 {
367  uint8_t frameCrc; /* CRC value from resp. */
368  uint8_t compCrc; /* Computed CRC value. */
369 
370  FS_ASSERT(data != NULL);
371  FS_ASSERT(dataLen > 0);
372 
373  /* Check CRC. */
374  frameCrc = data[0];
375  compCrc = FS8x_CalcCRC(data, dataLen);
376  return (compCrc != frameCrc) ? fs8xStatusError : fs8xStatusOk;
377 }
378 
379 /*******************************************************************************
380  * API - Implementation
381  ******************************************************************************/
382 
383 /* Performs a single read register based on provided address.
384  * The response is returned in @ref fs8x_rx_frame_t structure. */
385 fs8x_status_t FS8x_ReadRegister(SPI_INTERFACE_CONFIG_s* pSpiInterface, fs8x_drv_data_t* drvData, bool isFailSafe,
386  uint8_t address, fs8x_rx_frame_t* rxData)
387 {
388  fs8x_tx_frame_t txData = {
389  .registerAddress = address,
390  .commandType = fs8xRegRead,
391  .isFailSafe = isFailSafe };
392 
393  FS_ASSERT(drvData != NULL);
394  FS_ASSERT(rxData != NULL);
395 
396  switch (drvData->communicationMode)
397  {
398 #if FS8x_COMM_TYPE == FS8x_COMM_SPI || FS8x_COMM_TYPE == FS8x_COMM_BOTH
399  case fs8xSPI:
400  return FS8x_SPI_TransferData(pSpiInterface, &txData, rxData);
401 #endif
402 #if FS8x_COMM_TYPE == FS8x_COMM_I2C || FS8x_COMM_TYPE == FS8x_COMM_BOTH
403  case fs8xI2C:
404  return FS8x_I2C_ReadRegister(drvData, &txData, rxData);
405 #endif
406  default:
407  return fs8xStatusError;
408  }
409 }
410 
411 /* Sends write command to the FS8x. */
412 fs8x_status_t FS8x_WriteRegister(SPI_INTERFACE_CONFIG_s* pSpiInterface, fs8x_drv_data_t* drvData, bool isFailSafe,
413  uint8_t address, uint16_t writeData)
414 {
415  fs8x_tx_frame_t txData = {
416  .registerAddress = address,
417  .writeData = writeData,
418  .commandType = fs8xRegWrite,
419  .isFailSafe = isFailSafe };
420 
421  FS_ASSERT(drvData != NULL);
422 
423  switch (drvData->communicationMode)
424  {
425 #if FS8x_COMM_TYPE == FS8x_COMM_SPI || FS8x_COMM_TYPE == FS8x_COMM_BOTH
426  case fs8xSPI:
427  return FS8x_SPI_TransferData(pSpiInterface, &txData, NULL);
428 #endif
429 #if FS8x_COMM_TYPE == FS8x_COMM_I2C || FS8x_COMM_TYPE == FS8x_COMM_BOTH
430  case fs8xI2C:
431  return FS8x_I2C_WriteRegister(drvData, &txData);
432 #endif
433  default:
434  return fs8xStatusError;
435  }
436 }
437 
438 /* Performs a write to a single FS8x FS init register (during the INIT_FS phase only). */
440  uint16_t writeData)
441 {
442  fs8x_status_t status = fs8xStatusOk;
443  uint16_t writeDataInv; /* Inverted register data. */
444  uint8_t addressNot; /* Address of _NOT_ register. */
445 
446  FS_ASSERT(drvData != NULL);
447 
448  status = FS8x_WriteRegister(pSpiInterface, drvData, true, address, writeData);
449 
450  /* _NOT_ registers has address +1 from normal register. */
451  addressNot = (uint8_t)(address + 1);
452  /* Inverted value should be written to _NOT_ register. */
453  writeDataInv = (uint16_t)~writeData;
454 
455  status |= FS8x_WriteRegister(pSpiInterface, drvData, true, addressNot, writeDataInv);
456 
457  return status;
458 }
459 
460 /* Performs update of a single register. It affects bits specified by a bit mask. */
462  uint8_t address, int16_t mask, uint16_t writeData)
463 {
464  fs8x_rx_frame_t rxTemp;
465  fs8x_status_t status;
466 
467  FS_ASSERT(drvData != NULL);
468 
469  status = FS8x_ReadRegister(pSpiInterface, drvData, isFailSafe, address, &rxTemp);
470  if (status != fs8xStatusOk)
471  {
472  return status;
473  }
474 
475  /* Update register value. */
476  rxTemp.readData = FS8x_BO_SETVAL(rxTemp.readData, writeData, mask);
477 
478  return FS8x_WriteRegister(pSpiInterface, drvData, isFailSafe, address, rxTemp.readData);
479 }
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.
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).
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.
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.
fs8x_status_t
Status return codes.
@ fs8xRegWrite
@ fs8xRegRead
@ fs8xI2C
@ fs8xSPI
@ fs8xStatusOk
@ fs8xStatusError
fs8x_status_t MCU_SPI_TransferData(SPI_INTERFACE_CONFIG_s *pSpiInterface, uint8_t *txFrame, uint16_t frameLengthBytes, uint8_t *rxFrame)
This function transfers single frame through blocking SPI communication in both directions....
Definition: nxpfs85xx.c:941
Assertion macro definition, for debugging purposes.
#define FS_ASSERT(x)
Assert macro for the SBC.
Driver common structures, enums, macros and configuration values.
#define FS8x_BO_SETVAL_EXT(data, value, mask, shift)
This macro updates value of bits specified by the mask. Additionally range check on the value is perf...
#define FS8x_BO_SETVAL(data, val, mask)
This macro updates value of bits specified by the mask. It is assumed that value is already shifted.
#define FS8x_CRC_TBL_SIZE
#define FS8x_COM_CRC_INIT
#define FS8x_I2C_FRAME_SIZE
static fs8x_status_t FS8x_CheckCRC(const uint8_t *data, uint8_t dataLen)
Performs CRC check of the data array.
#define FS8x_I2C_READ_FRAME_LENGTH
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 f...
#define FS8x_I2C_ADDRESS_BASE
#define FS8x_REG_ADDR_MASK
#define FS8x_I2C_RX_SIZE
static const uint8_t FS8x_CRC_TABLE[FS8x_CRC_TBL_SIZE]
CRC lookup table.
#define FS8x_REG_ADDR_SHIFT
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.
static void FS8x_SPI_CreateSendFrame(fs8x_tx_frame_t *txData, uint8_t *txFrame)
Creates a raw frame for SPI transfer.
This file contains functions for SPI/I2C communication.
#define FS8x_COMM_FRAME_SIZE
FS8x register map.
This data structure is used by the FS8x driver (this is the first parameter of most the FS8x function...
fs8x_commType_t communicationMode
Actual communication mode (SPI or I2C). See fs8x_commType_t for details.
uint8_t i2cAddressOtp
SBC I2C address.
Structure representing received data frame.
uint16_t readData
Content of a read register.
uint8_t deviceStatus
A device status is returned into this byte after a successful transfer.
Structure representing transmit data frame.
fs8x_command_type_t commandType
Command type (R/W).
uint8_t registerAddress
Register address.
bool isFailSafe
Main/Fail Safe register selection.
uint16_t writeData
Data to be written to the register.