foxBMS - Unit Tests
1.5.0
The foxBMS Unit Tests API Documentation
|
#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>
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 *n775_state) |
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 *n775_state) |
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} |
#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 56 of file nxp_mc33775a-ll.c.
#define N775_READ_HEADER_SPI_BUFFER_SIZE (3u) |
Number of words (16 bits) in read answers that do not contain data
Definition at line 43 of file nxp_mc33775a-ll.c.
#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 48 of file nxp_mc33775a-ll.c.
#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 67 of file nxp_mc33775a-ll.c.
#define N775_SPI_WRITE_TIMEOUT_US (500u) |
Timeout to wait in microseconds for SPI send interrupt.
Definition at line 62 of file nxp_mc33775a-ll.c.
#define N775_WAIT_TIME_AFTER_READ_US (5u) |
Time to wait in microseconds after a read command
Definition at line 60 of file nxp_mc33775a-ll.c.
#define N775_WAIT_TIME_AFTER_WRITE_US (5u) |
Time to wait in microseconds after a write command
Definition at line 58 of file nxp_mc33775a-ll.c.
#define N775_WRITE_SPI_BUFFER_SIZE (4u) |
Number of words (16 bits) used for write messages
Definition at line 41 of file nxp_mc33775a-ll.c.
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.
cmd | |
masterAddress | |
deviceAddress | |
registerAddress | |
length | |
pValue | |
pMessage |
Definition at line 373 of file nxp_mc33775a-ll.c.
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.
pMessage | |
pCommand | |
pMasterAddress | |
pDeviceAddress | |
pRegisterAddress | |
pLength | |
pValue | |
string |
Definition at line 401 of file nxp_mc33775a-ll.c.
N775_COMMUNICATION_STATUS_e N775_CommunicationRead | ( | uint16_t | deviceAddress, |
uint16_t | registerAddress, | ||
uint16_t * | pValue, | ||
N775_STATE_s * | n775_state | ||
) |
Read a value from a specific register in a specific device.
deviceAddress | |
registerAddress | |
pValue | |
n775_state |
Definition at line 182 of file nxp_mc33775a-ll.c.
N775_COMMUNICATION_STATUS_e N775_CommunicationReadMultiple | ( | uint16_t | deviceAddress, |
uint16_t | numberOfItems, | ||
uint16_t | responseLength, | ||
uint16_t | registerAddress, | ||
uint16_t * | pValues, | ||
N775_STATE_s * | n775_state | ||
) |
Read multiple values from specific registers in a specific device.
deviceAddress | |
numberOfItems | |
responseLength | |
registerAddress | |
pValues | |
n775_state |
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 194 of file nxp_mc33775a-ll.c.
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.
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 142 of file nxp_mc33775a-ll.c.
|
static |
Copies a message to the buffer to be passed to the SPI transmit functions.
pBuffer | |
message |
Definition at line 112 of file nxp_mc33775a-ll.c.
void N775_ResetMessageCounter | ( | uint16_t | deviceAddress, |
uint8_t | string | ||
) |
Reset the message counter for one or all devices.
deviceAddress | |
string |
Definition at line 366 of file nxp_mc33775a-ll.c.
|
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 130 of file nxp_mc33775a-ll.c.
|
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 120 of file nxp_mc33775a-ll.c.
|
static |
Definition at line 78 of file nxp_mc33775a-ll.c.
|
static |
Definition at line 75 of file nxp_mc33775a-ll.c.
|
static |
Definition at line 74 of file nxp_mc33775a-ll.c.
|
static |
Definition at line 73 of file nxp_mc33775a-ll.c.
|
static |
Definition at line 70 of file nxp_mc33775a-ll.c.