foxBMS  1.6.0
The foxBMS Battery Management System API Documentation
nxp_mc33775a-ll.c File Reference

Low level driver for the MC33775A. More...

#include "nxp_mc33775a-ll.h"
#include "spi_cfg.h"
#include "dma.h"
#include "fassert.h"
#include "io.h"
#include "mcu.h"
#include "os.h"
#include "spi.h"
#include <stdint.h>
Include dependency graph for nxp_mc33775a-ll.c:

Go to the source code of this file.

Macros

#define N775_WRITE_SPI_BUFFER_SIZE   (4u)
 
#define N775_READ_HEADER_SPI_BUFFER_SIZE   (3u)
 
#define N775_READ_PAYLOAD_SPI_BUFFER_SIZE   (4u)
 
#define N775_MAX_ANSWER_FRAMES   (30u)
 
#define N775_WAIT_TIME_AFTER_WRITE_US   (5u)
 
#define N775_WAIT_TIME_AFTER_READ_US   (5u)
 
#define N775_SPI_WRITE_TIMEOUT_US   (500u)
 
#define N775_SPI_READ_TIMEOUT_US   (2000u)
 

Functions

static void N775_ConvertMessageToBuffer (uint16_t *pBuffer, uc_msg_t message)
 Copies a message to the buffer to be passed to the SPI transmit functions. More...
 
static uint32_t N775_WaitForTxCompletedNotification (void)
 Wait for the SPI transmit communication to complete, using notifications. More...
 
static uint32_t N775_WaitForRxCompletedNotification (void)
 Wait for the SPI receive communication to complete, using notifications. More...
 
void N775_CommunicationWrite (uint16_t deviceAddress, uint16_t registerAddress, uint16_t value, SPI_INTERFACE_CONFIG_s *pSpiInterface)
 Write a value into a specific register in a specific device. More...
 
N775_COMMUNICATION_STATUS_e N775_CommunicationRead (uint16_t deviceAddress, uint16_t registerAddress, uint16_t *pValue, N775_STATE_s *pState)
 Read a value from a specific register in a specific device. More...
 
N775_COMMUNICATION_STATUS_e N775_CommunicationReadMultiple (uint16_t deviceAddress, uint16_t numberOfItems, uint16_t responseLength, uint16_t registerAddress, uint16_t *pValues, N775_STATE_s *pState)
 Read multiple values from specific registers in a specific device. More...
 
void N775_ResetMessageCounter (uint16_t deviceAddress, uint8_t string)
 Reset the message counter for one or all devices. More...
 
void N775_CommunicationComposeMessage (uint16_t cmd, uint16_t masterAddress, uint16_t deviceAddress, uint16_t registerAddress, uint16_t length, uint16_t *pValue, uc_msg_t *pMessage)
 Composes a message. More...
 
N775_COMMUNICATION_STATUS_e N775_CommunicationDecomposeMessage (uc_msg_t *pMessage, uint16_t *pCommand, uint16_t *pMasterAddress, uint16_t *pDeviceAddress, uint16_t *pRegisterAddress, uint16_t *pLength, uint16_t *pValue, uint8_t string)
 Decomposes and analysis a message. More...
 

Variables

static uint16_t referenceMessageCounter [BS_NR_OF_STRINGS][512]
 
static uint16_t n775ToTplTxBuffer [N775_WRITE_SPI_BUFFER_SIZE] = {0u}
 
static uint16_t n775ToTplRxBuffer [N775_WRITE_SPI_BUFFER_SIZE] = {0u}
 
static uint16_t n775FromTplTxBuffer [N775_WRITE_SPI_BUFFER_SIZE+((N775_READ_HEADER_SPI_BUFFER_SIZE+N775_READ_PAYLOAD_SPI_BUFFER_SIZE) *N775_MAX_ANSWER_FRAMES)] = {0u}
 
static uint16_t n775FromTplRxBuffer [N775_WRITE_SPI_BUFFER_SIZE+((N775_READ_HEADER_SPI_BUFFER_SIZE+N775_READ_PAYLOAD_SPI_BUFFER_SIZE) *N775_MAX_ANSWER_FRAMES)] = {0u}
 

Detailed Description

Low level driver for the MC33775A.

Author
NXP
Date
2022-07-29 (date of creation)
Updated
2023-09-05 (date of last update)
Version
v1.6.0
Prefix
N775

Definition in file nxp_mc33775a-ll.c.

Macro Definition Documentation

◆ N775_MAX_ANSWER_FRAMES

#define N775_MAX_ANSWER_FRAMES   (30u)

Maximum number of groups of registers that can be read, to limit buffer size. Groups can be of size 1 to 4 registers. One frame = header (e.g., register address) + payload (data, 1 to 4 registers)

Definition at line 69 of file nxp_mc33775a-ll.c.

◆ N775_READ_HEADER_SPI_BUFFER_SIZE

#define N775_READ_HEADER_SPI_BUFFER_SIZE   (3u)

Number of words (16 bits) in read answers that do not contain data

Definition at line 56 of file nxp_mc33775a-ll.c.

◆ N775_READ_PAYLOAD_SPI_BUFFER_SIZE

#define N775_READ_PAYLOAD_SPI_BUFFER_SIZE   (4u)

Number of words (16 bits) in read answers that contain data. Based on maximum payload, which is 4 register per answer frame.

Definition at line 61 of file nxp_mc33775a-ll.c.

◆ N775_SPI_READ_TIMEOUT_US

#define N775_SPI_READ_TIMEOUT_US   (2000u)

Timeout to wait in microseconds for reception of a read answer. After that time the communication is considered to have failed.

Definition at line 80 of file nxp_mc33775a-ll.c.

◆ N775_SPI_WRITE_TIMEOUT_US

#define N775_SPI_WRITE_TIMEOUT_US   (500u)

Timeout to wait in microseconds for SPI send interrupt.

Definition at line 75 of file nxp_mc33775a-ll.c.

◆ N775_WAIT_TIME_AFTER_READ_US

#define N775_WAIT_TIME_AFTER_READ_US   (5u)

Time to wait in microseconds after a read command

Definition at line 73 of file nxp_mc33775a-ll.c.

◆ N775_WAIT_TIME_AFTER_WRITE_US

#define N775_WAIT_TIME_AFTER_WRITE_US   (5u)

Time to wait in microseconds after a write command

Definition at line 71 of file nxp_mc33775a-ll.c.

◆ N775_WRITE_SPI_BUFFER_SIZE

#define N775_WRITE_SPI_BUFFER_SIZE   (4u)

Number of words (16 bits) used for write messages

Definition at line 54 of file nxp_mc33775a-ll.c.

Function Documentation

◆ N775_CommunicationComposeMessage()

void N775_CommunicationComposeMessage ( uint16_t  cmd,
uint16_t  masterAddress,
uint16_t  deviceAddress,
uint16_t  registerAddress,
uint16_t  length,
uint16_t *  pValue,
uc_msg_t *  pMessage 
)

Composes a message.

Parameters
cmd
masterAddress
deviceAddress
registerAddress
length
pValue
pMessage

Definition at line 386 of file nxp_mc33775a-ll.c.

◆ N775_CommunicationDecomposeMessage()

N775_COMMUNICATION_STATUS_e N775_CommunicationDecomposeMessage ( uc_msg_t *  pMessage,
uint16_t *  pCommand,
uint16_t *  pMasterAddress,
uint16_t *  pDeviceAddress,
uint16_t *  pRegisterAddress,
uint16_t *  pLength,
uint16_t *  pValue,
uint8_t  string 
)

Decomposes and analysis a message.

Parameters
pMessage
pCommand
pMasterAddress
pDeviceAddress
pRegisterAddress
pLength
pValue
string

Definition at line 414 of file nxp_mc33775a-ll.c.

◆ N775_CommunicationRead()

N775_COMMUNICATION_STATUS_e N775_CommunicationRead ( uint16_t  deviceAddress,
uint16_t  registerAddress,
uint16_t *  pValue,
N775_STATE_s pState 
)

Read a value from a specific register in a specific device.

Parameters
deviceAddress
registerAddress
pValue
pState
Returns
returns 0 on success and >=1 in error case

Definition at line 195 of file nxp_mc33775a-ll.c.

Here is the call graph for this function:

◆ N775_CommunicationReadMultiple()

N775_COMMUNICATION_STATUS_e N775_CommunicationReadMultiple ( uint16_t  deviceAddress,
uint16_t  numberOfItems,
uint16_t  responseLength,
uint16_t  registerAddress,
uint16_t *  pValues,
N775_STATE_s pState 
)

Read multiple values from specific registers in a specific device.

Parameters
deviceAddress
numberOfItems
responseLength
registerAddress
pValues
pState
Returns
returns 0 on success and >=1 in error case

numberOfItems = 0 --> corresponds to one frame (max_frames - 1): because first frame is for the mirroring of Tx So (numberOfItems - 1u) is used in the following

The function gets the device address The pack_msg function adds the chain address. Chain address = 1 used so (deviceAddress | (1u << 6u)) is used in the following

After transmission to daisy-chain, daisy-chain will normally answer Already prepare SPI slave for reception

Compute the number of answer frames needed by the MC33775A. Padding is used: always same number of registers in each answer frame (1,2,3 or 4 registers).

Additional answer frame if number of registers to read and number of registers per answer frame are not multiples Example: 22 registers to read, 4 registers per answer frame. Answer: (5*4 register) + (2 registers + 2 words padded with 0)

N775_WRITE_SPI_BUFFER_SIZE (4u): because of Tx mirroring, the command is received, too N775_READ_HEADER_SPI_BUFFER_SIZE + (responseLength - 1u) + 1u: size of one answer frame (responseLength - 1u) 0 --> 1 register --> (responseLength - 1u) +1u = 1 (responseLength - 1u) 1 --> 2 registers --> (responseLength - 1u) +1u = 2 (responseLength - 1u) 2 --> 3 registers --> (responseLength - 1u) +1u = 3 (responseLength - 1u) 3 --> 4 registers --> (responseLength - 1u) +1u = 4

Definition at line 207 of file nxp_mc33775a-ll.c.

Here is the call graph for this function:

◆ N775_CommunicationWrite()

void N775_CommunicationWrite ( uint16_t  deviceAddress,
uint16_t  registerAddress,
uint16_t  value,
SPI_INTERFACE_CONFIG_s pSpiInterface 
)

Write a value into a specific register in a specific device.

Parameters
deviceAddress
registerAddress
value
pSpiInterface

The function gets the device address The N775_CommunicationComposeMessage function adds the chain address. Chain address = 1 used so (deviceAddress | (1u << 6u)) is used

Definition at line 155 of file nxp_mc33775a-ll.c.

Here is the call graph for this function:

◆ N775_ConvertMessageToBuffer()

static void N775_ConvertMessageToBuffer ( uint16_t *  pBuffer,
uc_msg_t  message 
)
static

Copies a message to the buffer to be passed to the SPI transmit functions.

Parameters
pBuffer
message

Definition at line 125 of file nxp_mc33775a-ll.c.

◆ N775_ResetMessageCounter()

void N775_ResetMessageCounter ( uint16_t  deviceAddress,
uint8_t  string 
)

Reset the message counter for one or all devices.

Parameters
deviceAddress
string

Definition at line 379 of file nxp_mc33775a-ll.c.

◆ N775_WaitForRxCompletedNotification()

static uint32_t N775_WaitForRxCompletedNotification ( void  )
static

Wait for the SPI receive communication to complete, using notifications.

return N775_RX_NOTIFIED_VALUE if notification received, N775_NO_NOTIFIED_VALUE if timeout reached

Suspend task and wait for DMA RX notification, clear notification value on entry and exit

Definition at line 143 of file nxp_mc33775a-ll.c.

Here is the call graph for this function:

◆ N775_WaitForTxCompletedNotification()

static uint32_t N775_WaitForTxCompletedNotification ( void  )
static

Wait for the SPI transmit communication to complete, using notifications.

return N775_TX_NOTIFIED_VALUE if notification received, N775_NO_NOTIFIED_VALUE if timeout reached

Suspend task and wait for SPI send DMA RX finished notification, clear notification value on entry and exit

Definition at line 133 of file nxp_mc33775a-ll.c.

Here is the call graph for this function:

Variable Documentation

◆ n775FromTplRxBuffer

◆ n775FromTplTxBuffer

◆ n775ToTplRxBuffer

uint16_t n775ToTplRxBuffer[N775_WRITE_SPI_BUFFER_SIZE] = {0u}
static

Definition at line 87 of file nxp_mc33775a-ll.c.

◆ n775ToTplTxBuffer

uint16_t n775ToTplTxBuffer[N775_WRITE_SPI_BUFFER_SIZE] = {0u}
static

Definition at line 86 of file nxp_mc33775a-ll.c.

◆ referenceMessageCounter

uint16_t referenceMessageCounter[BS_NR_OF_STRINGS][512]
static

Definition at line 83 of file nxp_mc33775a-ll.c.