foxBMS - Unit Tests
1.6.0
The foxBMS Unit Tests API Documentation
|
Driver for the SPI module. More...
#include "spi.h"
#include "HL_reg_spi.h"
#include "HL_spi.h"
#include "HL_sys_common.h"
#include "dma.h"
#include "fstd_types.h"
#include "fsystem.h"
#include "io.h"
#include "mcu.h"
#include "os.h"
#include "spi_cfg-helper.h"
#include <stdint.h>
Go to the source code of this file.
Macros | |
#define | SPI_FLAG_REGISTER_TRANSMISSION_ERRORS (0x5Fu) |
#define | SPI_HARDWARE_CHIP_SELECT_PIN_0 (0u) |
#define | SPI_HARDWARE_CHIP_SELECT_PIN_1 (1u) |
#define | SPI_HARDWARE_CHIP_SELECT_PIN_2 (2u) |
#define | SPI_HARDWARE_CHIP_SELECT_PIN_3 (3u) |
#define | SPI_HARDWARE_CHIP_SELECT_PIN_4 (4u) |
#define | SPI_HARDWARE_CHIP_SELECT_PIN_5 (5u) |
Functions | |
static void | SPI_InitializeChipSelects (void) |
static uint8_t | SPI_GetChipSelectPin (SPI_CHIP_SELECT_TYPE_e chipSelectType, uint32_t chipSelectPin) |
static uint8_t | SPI_GetHardwareChipSelectPin (uint8_t chipSelectPin) |
void | SPI_Initialize (void) |
Initializes the SPI module. More... | |
STD_RETURN_TYPE_e | SPI_TransmitDummyByte (SPI_INTERFACE_CONFIG_s *pSpiInterface, uint32_t delay) |
Sends a dummy byte to wake up the SPI interface. More... | |
STD_RETURN_TYPE_e | SPI_TransmitData (SPI_INTERFACE_CONFIG_s *pSpiInterface, uint16 *pTxBuff, uint32 frameLength) |
Transmits data on SPI without DMA. More... | |
STD_RETURN_TYPE_e | SPI_TransmitReceiveData (SPI_INTERFACE_CONFIG_s *pSpiInterface, uint16 *pTxBuff, uint16 *pRxBuff, uint32 frameLength) |
Transmits and receives data on SPI without DMA. More... | |
void | SPI_FramTransmitReceiveData (SPI_INTERFACE_CONFIG_s *pSpiInterface, uint16 *pTxBuff, uint16 *pRxBuff, uint32 frameLength) |
Transmits and receives data on SPI without DMA, wrapper for FRAM. More... | |
STD_RETURN_TYPE_e | SPI_TransmitReceiveDataDma (SPI_INTERFACE_CONFIG_s *pSpiInterface, uint16_t *pTxBuff, uint16_t *pRxBuff, uint32_t frameLength) |
Transmits and receives data on SPI with DMA. More... | |
STD_RETURN_TYPE_e | SPI_Lock (uint8_t spi) |
Locks SPI interfaces. More... | |
void | SPI_Unlock (uint8_t spi) |
Unlocks SPI interfaces. More... | |
void | SPI_SetFunctional (spiBASE_t *pNode, enum spiPinSelect bit, bool hardwareControlled) |
Sets the functional of a SPI pin. More... | |
STD_RETURN_TYPE_e | SPI_SlaveSetReceiveDataDma (SPI_INTERFACE_CONFIG_s *pSpiInterface, uint16_t *pTxBuff, uint16_t *pRxBuff, uint32_t frameLength) |
Transmits and receives data on SPI with DMA. More... | |
void | SPI_DmaSendLastByte (uint8_t spiIndex) |
Used to send last byte per SPI. More... | |
void UNIT_TEST_WEAK_IMPL | spiNotification (spiBASE_t *spi, uint32 flags) |
SPI Interrupt callback. More... | |
STD_RETURN_TYPE_e | SPI_CheckInterfaceAvailable (spiBASE_t *pNode) |
Returns STD_OK if the SPI interface can be used again. More... | |
uint8_t | SPI_GetSpiIndex (spiBASE_t *pNode) |
Returns index of SPI node. More... | |
void | TEST_SPI_InitializeChipSelects (void) |
uint8_t | TEST_SPI_GetChipSelectPin (SPI_CHIP_SELECT_TYPE_e csType, uint32_t csPin) |
uint8_t | TEST_SPI_GetHardwareChipSelectPin (uint8_t csPin) |
Variables | |
static uint32_t | spi_txLastWord [DMA_NUMBER_SPI_INTERFACES] = {0} |
Driver for the SPI module.
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:
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:
Definition in file spi.c.
#define SPI_FLAG_REGISTER_TRANSMISSION_ERRORS (0x5Fu) |
#define SPI_HARDWARE_CHIP_SELECT_PIN_0 (0u) |
#define SPI_HARDWARE_CHIP_SELECT_PIN_1 (1u) |
#define SPI_HARDWARE_CHIP_SELECT_PIN_2 (2u) |
#define SPI_HARDWARE_CHIP_SELECT_PIN_3 (3u) |
#define SPI_HARDWARE_CHIP_SELECT_PIN_4 (4u) |
#define SPI_HARDWARE_CHIP_SELECT_PIN_5 (5u) |
STD_RETURN_TYPE_e SPI_CheckInterfaceAvailable | ( | spiBASE_t * | pNode | ) |
Returns STD_OK if the SPI interface can be used again.
This function just checks for SPI_PENDING and groups SPI_READY and SPI_...
[in] | pNode | handle of the SPI node that should be checked |
void SPI_DmaSendLastByte | ( | uint8_t | spiIndex | ) |
void SPI_FramTransmitReceiveData | ( | SPI_INTERFACE_CONFIG_s * | pSpiInterface, |
uint16 * | pTxBuff, | ||
uint16 * | pRxBuff, | ||
uint32 | frameLength | ||
) |
Transmits and receives data on SPI without DMA, wrapper for FRAM.
This function can be used to send and receive data via SPI. SPI communication is performed in blocking mode and chip select is set/reset automatically. It does not drive the Chip Select (neither hardware nor software) as this is done directly in the FRAM functions.
pSpiInterface | pointer to SPI interface configuration |
pTxBuff | pointer to data that is transmitted by the SPI interface |
pRxBuff | pointer to data that is received by the SPI interface |
frameLength | number of bytes to be transmitted by the SPI interface |
|
static |
|
static |
uint8_t SPI_GetSpiIndex | ( | spiBASE_t * | pNode | ) |
void SPI_Initialize | ( | void | ) |
|
static |
STD_RETURN_TYPE_e SPI_Lock | ( | uint8_t | spi | ) |
Locks SPI interfaces.
This function is used to change the state of the SPI_busy_flags variable to "locked".
spi | SPI interface to be locked (0-4 on the TMS570LC4357) |
Definition at line 402 of file spi.c.
void SPI_SetFunctional | ( | spiBASE_t * | pNode, |
enum spiPinSelect | bit, | ||
bool | hardwareControlled | ||
) |
Sets the functional of a SPI pin.
SPI pins in this HAL can have functional state SPI (for when it is controlled by the SPI hardware) and functional state GIO (for when it is controlled as a GIO pin).
[in,out] | pNode | handle of the SPI node that should be configured |
[in] | bit | bit that should be manipulated, other pins remain unchanged |
[in] | hardwareControlled | Whether the bit should be hardware controlled (true) or not (false) |
STD_RETURN_TYPE_e SPI_SlaveSetReceiveDataDma | ( | SPI_INTERFACE_CONFIG_s * | pSpiInterface, |
uint16_t * | pTxBuff, | ||
uint16_t * | pRxBuff, | ||
uint32_t | frameLength | ||
) |
Transmits and receives data on SPI with DMA.
This function can be used to send and receive data via SPI. SPI communication is performed in blocking mode and chip select is set/reset automatically..
pSpiInterface | pointer to SPI interface configuration |
pTxBuff | pointer to data that is transmitted by the SPI interface |
pRxBuff | pointer to data that is received by the SPI interface |
frameLength | number of bytes to be transmitted by the SPI interface |
SPI receive works only with HW Chip Select
Definition at line 463 of file spi.c.
STD_RETURN_TYPE_e SPI_TransmitData | ( | SPI_INTERFACE_CONFIG_s * | pSpiInterface, |
uint16 * | pTxBuff, | ||
uint32 | frameLength | ||
) |
Transmits data on SPI without DMA.
This function can be used to send and receive data via SPI. SPI communication is performed in blocking mode and chip select is set/reset automatically.
pSpiInterface | pointer to SPI interface configuration |
pTxBuff | pointer to data that is transmitted by the SPI interface |
frameLength | number of bytes to be transmitted by the SPI interface |
SW Chip Select
Set SPI Chip Select pins as GIOs
Activate Chip Select
HW Chip Select
Activate HW Chip Select according to bitmask register CSNR by setting pins as SPI functional pins
First deactivate all HW Chip Selects
Bitmask = 0 --> HW CS active --> write to PC0 to set pin as SPI pin (and not GIO)
SW Chip Select
Deactivate Chip Select
Definition at line 169 of file spi.c.
STD_RETURN_TYPE_e SPI_TransmitDummyByte | ( | SPI_INTERFACE_CONFIG_s * | pSpiInterface, |
uint32_t | delay | ||
) |
STD_RETURN_TYPE_e SPI_TransmitReceiveData | ( | SPI_INTERFACE_CONFIG_s * | pSpiInterface, |
uint16 * | pTxBuff, | ||
uint16 * | pRxBuff, | ||
uint32 | frameLength | ||
) |
Transmits and receives data on SPI without DMA.
This function can be used to send and receive data via SPI. SPI communication is performed in blocking mode and chip select is set/reset automatically.
pSpiInterface | pointer to SPI interface configuration |
pTxBuff | pointer to data that is transmitted by the SPI interface |
pRxBuff | pointer to data that is received by the SPI interface |
frameLength | number of bytes to be transmitted by the SPI interface |
SW Chip Select
Set SPI Chip Select pins as GIOs
Activate Chip Select
HW Chip Select
Activate HW Chip Select according to bitmask register CSNR by setting pins as SPI functional pins
First deactivate all HW Chip Selects
Bitmask = 0 --> HW CS active --> write to PC0 to set pin as SPI pin (and not GIO)
SW Chip Select
Deactivate Chip Select
Definition at line 221 of file spi.c.
STD_RETURN_TYPE_e SPI_TransmitReceiveDataDma | ( | SPI_INTERFACE_CONFIG_s * | pSpiInterface, |
uint16_t * | pTxBuff, | ||
uint16_t * | pRxBuff, | ||
uint32_t | frameLength | ||
) |
Transmits and receives data on SPI with DMA.
This function can be used to send and receive data via SPI. SPI communication is performed in blocking mode and chip select is set/reset automatically..
pSpiInterface | pointer to SPI interface configuration |
pTxBuff | pointer to data that is transmitted by the SPI interface |
pRxBuff | pointer to data that is received by the SPI interface |
frameLength | number of bytes to be transmitted by the SPI interface |
SPI over DMA currently only compatible with HW Chip Select
Activate HW Chip Select according to bitmask register CSNR by setting pins as SPI functional pins
First deactivate all HW Chip Selects
Bitmask = 0 --> HW CS active --> write to PC0 to set pin as SPI pin (and not GIO)
Set number of Tx words to send Last word sent in ISR to set CSHOLD = 0
Send first word without DMA because when writing config to DAT1 the HW CS pin are asserted immediately, even if SPIEN bit in GCR1 is 0. The C2TDELAY is then taken into account before the transmission.
Definition at line 292 of file spi.c.
void SPI_Unlock | ( | uint8_t | spi | ) |
void UNIT_TEST_WEAK_IMPL spiNotification | ( | spiBASE_t * | spi, |
uint32 | flags | ||
) |
uint8_t TEST_SPI_GetChipSelectPin | ( | SPI_CHIP_SELECT_TYPE_e | csType, |
uint32_t | csPin | ||
) |
uint8_t TEST_SPI_GetHardwareChipSelectPin | ( | uint8_t | csPin | ) |
void TEST_SPI_InitializeChipSelects | ( | void | ) |
|
static |