Std_ReturnType Bios_Spi_TransferData(uint8_t* txData, uint16_t frameLengthBytes, uint8_t* rxData) { Std_ReturnType status = E_NOT_OK; tBiosSpiRetStatus spiRet = BIOS_DSPI_OK; static uint32 txBuf = 0; static uint32 rxBuf= 0; /* First frame to send should contains 8bit general flags, which is stored in txData[3] */ txBuf = (txData[0]); txBuf = txBuf | (((uint32)txData[1])<<8); txBuf = txBuf | (((uint32)txData[2])<<16); txBuf = txBuf | (((uint32)txData[3])<<24); /* Call of blocking driver function. * Note: The byte order of txData and rxData is same within the FS8x driver and S32 SDK SPI driver, * i.e. [0] is the last transmitted/received byte. */ spiRet = Bios_Spi_MasterSynchExchange(BIOS_SBC_SPI_ID, txBuf, &rxBuf); if((spiRet == BIOS_DSPI_OK) && (rxData != NULL_PTR )) { rxData[0] = (rxBuf>>0)&0xFFU; rxData[1] = (rxBuf>>8)&0xFFU; rxData[2] = (rxBuf>>16)&0xFFU; rxData[3] = (rxBuf>>24)&0xFFU; status = E_OK; } return (status); } tBiosSpiRetStatus Bios_Spi_MasterSynchExchange(uint8 deviceHandler, uint32 txFrame, uint32 *rxFrame) { if (deviceHandler >= BIOS_DSPI_TOTAL_DEVICES) { return BIOS_DSPI_GENERIC_FAIL; } const tBiosSpiControl *spiControl = &bios_spi_drvControl[bios_spi_deviceMapping[deviceHandler].spiHandle]; uint32 cmd = ((uint32)bios_spi_deviceMapping[deviceHandler].attributeHandle << 28U) | ((uint32)bios_spi_deviceMapping[deviceHandler].chipSelectMask << 16U); spiControl->regs->SR.R = 0xFFFFFFFFUL; spiControl->regs->MCR.B.HALT = 0; SuspendOSInterrupts(); spiControl->regs->PUSHR.R = (DSPI_CONT_MASK | cmd | (txFrame >> 16)); spiControl->regs->PUSHR.R = (DSPI_EOQ_MASK | cmd | (txFrame & 0xFFFFU)) & 0x7FFFFFFFUL; ResumeOSInterrupts(); while ((spiControl->regs->SR.B.TCF != 1U) || (spiControl->regs->SR.B.RXCTR != 2U)) { OS_NOP(); } SuspendOSInterrupts(); uint32 popr = spiControl->regs->POPR.R; OS_NOP(); uint32 popr1 = spiControl->regs->POPR.R; ResumeOSInterrupts(); spiControl->regs->MCR.B.HALT = 1U; *rxFrame = (popr << 16) | (popr1 & 0xFFFFU); return BIOS_DSPI_OK; } void BIOS_ERROR_LOG_SBC(void) { SPI_Write_DATA_FRAME Write_Frame; SPI_Read_DATA_FRAME Read_Frame; uint8 Write_Buff[4]; Read_DF Read_Buff; Std_ReturnType SPI_Ret = E_NOT_OK; // Check MEMU errors and write to SBC Memory0 if needed if (MEMU.ERR_FLAG.R != 0U || FCCU.RF_S[0U].R != 0U || FCCU.RF_S[1U].R != 0U || FCCU.RF_S[2U].R != 0U || FCCU.RF_S[3U].R != 0U) { Write_Frame.St_Data_Tx.M_FS = 0U; Write_Frame.St_Data_Tx.Register_Address = 0b100011; Write_Frame.St_Data_Tx.W = 1; //Write -1 Write_Frame.St_Data_Tx.Data = 0x01; Write_Frame.St_Data_Tx.CRC = calculateCRC8(Write_Frame.buffer,4); // Write data into the memory address through SPI SPI_Ret = Bios_Spi_TransferData(Write_Frame.buffer,5U,Write_Buff); } if(SPI_Ret ==E_OK) { Read_Frame.St_Data_Rx.M_FS = 0U; Read_Frame.St_Data_Rx.Register_Address = 0b100011; Read_Frame.St_Data_Rx.R = 0; //Read - 0 // Read data into the memory address through SPI SPI_Ret = Bios_Spi_TransferData(Read_Frame.buffer,4U,Read_Buff.buffer); fetched_Value =Read_Buff.St_Read_MISO.Read_Data; } else if(fetched_Value == Read_Buff.St_Read_MISO.Read_Data) { fetched_Value = 0; } else { } #if 0 /*********************************************************************************************/ * Timeout Value=Desired Timeout Interval/Clock Period * For example, if you want a timeout interval of 100 microseconds: * Timeout Value=100μs/0.0625μs =1600 * So, you would set the timeout value register to 1600 to achieve a 100-microsecond timeout. * you can use the time resolution constant for a 16 MHz clock, which is (0.0625 \mu s). * Here’s the calculation: * Timeout=6400×0.0625μs=400μs * So, your timeout interval of 6400 corresponds to 400 microseconds. **********************************************************************************************/ FCCU.RF_TO.B.TO = bios_Fccu_CtrlConfig.recTimeout; // Check FCCU timeout while (FCCU.RF_TO.B.TO); { // Trigger FCCU error pin to SBC pin FCCU.EINOUT.B.EOUT0 = 1U; } #endif } // Function to calculate CRC-8 uint8_t calculateCRC8(uint8_t *data, uint8_t length) { uint8_t crc = 0x00; // Initial CRC value uint8_t polynomial = 0x07; // CRC-8 polynomial uint8_t i,j; for ( i = 0; i < length; i++) { crc ^= data[i]; // XOR with the current byte for ( j = 0; j < 8; j++) { if (crc & 0x80) { crc = (crc << 1) ^ polynomial; } else { crc <<= 1; } } } return crc; }