58 #include "HL_reg_spi.h"
60 #include "HL_sys_common.h"
74 #define SPI_FLAG_REGISTER_TRANSMISSION_ERRORS (0x5Fu)
80 #define SPI_HARDWARE_CHIP_SELECT_PIN_0 (0u)
81 #define SPI_HARDWARE_CHIP_SELECT_PIN_1 (1u)
82 #define SPI_HARDWARE_CHIP_SELECT_PIN_2 (2u)
83 #define SPI_HARDWARE_CHIP_SELECT_PIN_3 (3u)
84 #define SPI_HARDWARE_CHIP_SELECT_PIN_4 (4u)
85 #define SPI_HARDWARE_CHIP_SELECT_PIN_5 (5u)
100 switch (chipSelectPin) {
123 return mappedHardwareChipSelectPin;
129 uint8_t mappedChipSelectPin = (uint8_t)chipSelectPin;
136 return mappedChipSelectPin;
162 uint16_t txDummy[1] = {0x00};
194 if (((pSpiInterface->
pConfig->CSNR >> csNumber) & 0x1u) == 0u) {
198 pSpiInterface->
pNode->PC0 |= (uint32_t)1u << csNumber;
202 uint32_t spiRetval = spiTransmitData(pSpiInterface->
pNode, pSpiInterface->
pConfig, frameLength, pTxBuff);
224 uint32 frameLength) {
251 if (((pSpiInterface->
pConfig->CSNR >> csNumber) & 0x1u) == 0u) {
255 pSpiInterface->
pNode->PC0 |= (uint32_t)1u << csNumber;
260 spiTransmitAndReceiveData(pSpiInterface->
pNode, pSpiInterface->
pConfig, frameLength, pTxBuff, pRxBuff);
282 uint32 frameLength) {
288 (void)spiTransmitAndReceiveData(pSpiInterface->
pNode, pSpiInterface->
pConfig, frameLength, pTxBuff, pRxBuff);
295 uint32_t frameLength) {
321 if (((pSpiInterface->
pConfig->CSNR >> csNumber) & 0x1u) == 0u) {
325 pSpiInterface->
pNode->PC0 |= (uint32_t)1u << csNumber;
330 uint32 Chip_Select_Hold = 0u;
331 if (pSpiInterface->
pConfig->CS_HOLD == TRUE) {
334 Chip_Select_Hold = 0U;
337 if (pSpiInterface->
pConfig->WDEL == TRUE) {
342 SPIDATAFMT_t DataFormat = pSpiInterface->
pConfig->DFSEL;
343 uint8 ChipSelect = pSpiInterface->
pConfig->CSNR;
354 (uint32_t)(&pTxBuff[1u]);
360 ((frameLength - 2u) << 16U) | 1U;
363 dmaRAMREG->PCP[(dmaChannel_t)
dma_spiDmaChannels[spiIndex].rxChannel].IDADDR = (uint32_t)pRxBuff;
365 dmaRAMREG->PCP[(dmaChannel_t)
dma_spiDmaChannels[spiIndex].rxChannel].ITCOUNT = (frameLength << 16U) | 1U;
369 dmaSetChEnable((dmaChannel_t)
dma_spiDmaChannels[spiIndex].txChannel, (dmaTriggerType_t)DMA_HW);
370 dmaSetChEnable((dmaChannel_t)
dma_spiDmaChannels[spiIndex].rxChannel, (dmaTriggerType_t)DMA_HW);
378 uint32_t txBuffer = pTxBuff[0u];
379 txBuffer |= ((uint32)DataFormat << 24U) | ((uint32)ChipSelect << 16U) | (WDelay) | (Chip_Select_Hold);
385 pSpiInterface->
pNode->DAT1 = txBuffer;
388 (timeoutIterations > 0u)) {
428 extern void SPI_SetFunctional(spiBASE_t *pNode,
enum spiPinSelect bit,
bool hardwareControlled) {
433 spi_config_reg_t configRegisterBuffer = {0};
434 if (pNode == spiREG1) {
435 spi1GetConfigValue(&configRegisterBuffer, CurrentValue);
436 }
else if (pNode == spiREG2) {
437 spi2GetConfigValue(&configRegisterBuffer, CurrentValue);
438 }
else if (pNode == spiREG3) {
439 spi3GetConfigValue(&configRegisterBuffer, CurrentValue);
440 }
else if (pNode == spiREG4) {
441 spi4GetConfigValue(&configRegisterBuffer, CurrentValue);
442 }
else if (pNode == spiREG5) {
443 spi5GetConfigValue(&configRegisterBuffer, CurrentValue);
448 uint32_t newPc0 = configRegisterBuffer.CONFIG_PC0;
450 if (hardwareControlled ==
false) {
452 newPc0 &= ~(uint32_t)((uint32_t)1u << (uint8_t)(bit));
455 newPc0 |= (uint32_t)((uint32_t)1u << (uint8_t)(bit));
459 spiSetFunctional(pNode, newPc0);
466 uint32_t frameLength) {
485 SPIDATAFMT_t DataFormat = pSpiInterface->
pConfig->DFSEL;
493 (frameLength << 16U) | 1U;
500 (frameLength << 16U) | 1U;
516 if (((pSpiInterface->
pConfig->CSNR >> csNumber) & 0x1u) == 0u) {
518 pSpiInterface->
pNode->PC0 |= (uint32_t)1u << csNumber;
547 const SpiDataStatus_t spiStatus = SpiTxStatus(pNode);
549 if (spiStatus == SPI_PENDING) {
557 uint8_t spiIndex = 0u;
559 if (pNode == spiREG1) {
561 }
else if (pNode == spiREG2) {
563 }
else if (pNode == spiREG3) {
565 }
else if (pNode == spiREG4) {
567 }
else if (pNode == spiREG5) {
578 #ifdef UNITY_UNIT_TEST
#define BS_NR_OF_STRINGS
Number of parallel strings in the battery pack.
Headers for the driver for the DMA module.
spiBASE_t * dma_spiInterfaces[DMA_NUMBER_SPI_INTERFACES]
DMA_CHANNEL_CONFIG_s dma_spiDmaChannels[DMA_NUMBER_SPI_INTERFACES]
#define DMA_NUMBER_SPI_INTERFACES
#define FAS_ASSERT(x)
Assertion macro that asserts that x is true.
#define FAS_TRAP
Define that evaluates to essential boolean false thus tripping an assert.
Definition of foxBMS standard types.
#define NULL_PTR
Null pointer.
Function to switch between user mode and privilege mode.
#define FSYS_SwitchToUserMode()
Switch back to user mode.
long FSYS_RaisePrivilege(void)
Raise privilege.
#define UNIT_TEST_WEAK_IMPL
void IO_PinSet(volatile uint32_t *pRegisterAddress, uint32_t pin)
Set pin by writing in pin output register.
void IO_PinReset(volatile uint32_t *pRegisterAddress, uint32_t pin)
Reset pin by writing in pin output register.
Header for the driver for the IO module.
void MCU_Delay_us(uint32_t delay_us)
Wait blocking a certain time in microseconds.
Headers for the driver for the MCU module.
#define MCU_LARGEST_PIN_NUMBER
largest pin number that exists in TMS570LC4357
Declaration of the OS wrapper interface.
void OS_ExitTaskCritical(void)
Exit Critical interface function for use in FreeRTOS-Tasks and FreeRTOS-ISR.
void OS_EnterTaskCritical(void)
Enter Critical interface function for use in FreeRTOS-Tasks and FreeRTOS-ISR.
uint8_t TEST_SPI_GetHardwareChipSelectPin(uint8_t csPin)
static void SPI_InitializeChipSelects(void)
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.
static uint8_t SPI_GetChipSelectPin(SPI_CHIP_SELECT_TYPE_e chipSelectType, uint32_t chipSelectPin)
void SPI_SetFunctional(spiBASE_t *pNode, enum spiPinSelect bit, bool hardwareControlled)
Sets the functional of a SPI pin.
#define SPI_HARDWARE_CHIP_SELECT_PIN_1
STD_RETURN_TYPE_e SPI_CheckInterfaceAvailable(spiBASE_t *pNode)
Returns STD_OK if the SPI interface can be used again.
void SPI_DmaSendLastByte(uint8_t spiIndex)
Used to send last byte per SPI.
STD_RETURN_TYPE_e SPI_TransmitDummyByte(SPI_INTERFACE_CONFIG_s *pSpiInterface, uint32_t delay)
Sends a dummy byte to wake up the SPI interface.
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.
#define SPI_HARDWARE_CHIP_SELECT_PIN_5
STD_RETURN_TYPE_e SPI_Lock(uint8_t spi)
Locks SPI interfaces.
#define SPI_HARDWARE_CHIP_SELECT_PIN_3
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.
#define SPI_HARDWARE_CHIP_SELECT_PIN_0
void SPI_Unlock(uint8_t spi)
Unlocks SPI interfaces.
STD_RETURN_TYPE_e SPI_TransmitData(SPI_INTERFACE_CONFIG_s *pSpiInterface, uint16 *pTxBuff, uint32 frameLength)
Transmits data on SPI without DMA.
static uint8_t SPI_GetHardwareChipSelectPin(uint8_t chipSelectPin)
void UNIT_TEST_WEAK_IMPL spiNotification(spiBASE_t *spi, uint32 flags)
SPI Interrupt callback.
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.
void TEST_SPI_InitializeChipSelects(void)
uint8_t SPI_GetSpiIndex(spiBASE_t *pNode)
Returns index of SPI node.
uint8_t TEST_SPI_GetChipSelectPin(SPI_CHIP_SELECT_TYPE_e csType, uint32_t csPin)
#define SPI_HARDWARE_CHIP_SELECT_PIN_2
#define SPI_HARDWARE_CHIP_SELECT_PIN_4
#define SPI_FLAG_REGISTER_TRANSMISSION_ERRORS
static uint32_t spi_txLastWord[DMA_NUMBER_SPI_INTERFACES]
void SPI_Initialize(void)
Initializes the SPI module.
Headers for the driver for the SPI module.
Headers for the configuration for the SPI module.
#define SPI_HARDWARE_CHIP_SELECT_3_ACTIVE
#define SPI_HARDWARE_CHIP_SELECT_0_ACTIVE
#define SPI_HARDWARE_CHIP_SELECT_1_ACTIVE
#define SPI_HARDWARE_CHIP_SELECT_4_ACTIVE
#define SPI_HARDWARE_CHIP_SELECT_5_ACTIVE
#define SPI_HARDWARE_CHIP_SELECT_2_ACTIVE
#define SPI_HARDWARE_CHIP_SELECT_DISABLE_ALL
SPI_INTERFACE_CONFIG_s spi_mxmInterface
SPI_INTERFACE_CONFIG_s spi_sbcMcuInterface
SPI_INTERFACE_CONFIG_s spi_nxp775InterfaceTx[BS_NR_OF_STRINGS]
SPI_BUSY_STATE_e spi_busyFlags[]
SPI_INTERFACE_CONFIG_s spi_framInterface
SPI_INTERFACE_CONFIG_s spi_nxp775InterfaceRx[BS_NR_OF_STRINGS]
SPI_INTERFACE_CONFIG_s spi_ltcInterface[BS_NR_OF_STRINGS]
const uint8_t spi_nrBusyFlags
SPI_INTERFACE_CONFIG_s spi_spsInterface
#define SPI_HARDWARE_CHIP_SELECT_FIELD_POSITION
#define SPI_DATA_FORMAT_FIELD_POSITION
#define SPI_TX_EMPTY_TIMEOUT_ITERATIONS
#define SPI_MAX_NUMBER_HW_CS
#define SPI_TX_BUFFER_EMPTY_FLAG_POSITION
#define SPI_PC0_CLEAR_HW_CS_MASK
@ SPI_CHIP_SELECT_SOFTWARE
@ SPI_CHIP_SELECT_HARDWARE
SPI_CHIP_SELECT_TYPE_e csType
volatile uint32_t * pGioPort