//***************************************************************************** // (C) Automotive Lighting Reutlingen GmbH // Tuebinger Strasse 123, 72762 Reutlingen, Germany // // Automotive Lighting Reutlingen GmbH owns all the rights to this work. // This work shall not be copied, reproduced, used, modified, transferred // or its information shall not be disclosed without the prior written // authorization of Automotive Lighting Reutlingen GmbH. //***************************************************************************** //----------------------------------------------------------------------------- /// \file CddSpi.c /// /// \brief Complex Driver Spi /// This module provides services for SPI transmission in Motorola Master Mode for a multislave scenario. /// It provides 2 different operation modes: SINGLE OPERATION Mode and CYCLIC OPERATION Mode /// The SINGLE OPERATION Mode is used to provide asynchronous single transmissions when they are demanded. /// The CYCLIC OPERATION Mode is used to provide cyclic transmissions in which a set of /// Transmission and Reception Callbacks are called to send data from the Upper Software Layer and receive /// data from Lower Software Layer with a configurable period. /// //----------------------------------------------------------------------------- //============================================================================= // includes //============================================================================= #include #include #include #include #include #include #include //Derived implementation headers #include /* #if (CDDBUCK_CHIP_SELECT == CDDBUCk_CHIP_CPSQ5352) #include <../Gen/CddCPSQ5352_Com.h> #else #include <../Gen/CddTps92520_Com.h> #endif */ //Sequence context #define CDDSPI_SEQ_CONTEXT_INITIALIZED_MSK 0x01U #define CDDSPI_SEQ_CONTEXT_COMPLETE_MSK 0x02U #define CDDSPI_SEQ_CONTEXT_INITIALIZED_POS 0U #define CDDSPI_SEQ_CONTEXT_COMPLETE_POS 1U typedef struct tsCddSpiIfcCfg { CONST_AL uint8 ucIfcMap; #if (CDDSPI_SINGLE_OPERATION == STD_ON) CONST_AL teCddSpiIfcSingleMode eIfcSingleMode; #endif #if (CDDSPI_CYCLIC_OPERATION == STD_ON) CONST_AL teCddSpiIfcCyclicMode eIfcCyclicMode; uint8 ucSeqMap; #endif }tsCddSpiIfcCfg; #if (CDDSPI_CYCLIC_OPERATION == STD_ON) typedef void (*tfpCddSpiRxCb)(uint16 unId, uint32 ulData); //receive callback function typedef uint32 (*tfpCddSpiTxCb)(uint16 unId); //send callback function typedef uint8 (*tfpCddSpiCrc) (uint8* pucData, uint32 ulLength, uint8 ucStartVal, boolean boFirstCall); //crc callback function typedef struct tsCddSpiCbData { tsCddSpiDevCb sDevCb; CONST_AL uint16 unCbId; }tsCddSpiCbData; typedef struct tsCddSpiDevSeqData { tsCddSpiCbData* psCbData; uint16* punTxBuff; //tx buffer uint16* punRxBuff; //rx buffer CONST_AL teCddSpiDev eDev; //device #if (CDDSPI_CRC_ENABLE == STD_ON) boolean boTxCrcError; CONST_AL uint8 ucCrcErrBit; #endif }tsCddSpiDevSeqData; typedef struct tsCddSpiSeqData { tsCddSpiDevSeqData* psDevData; CONST_AL uint8 ucDeviceCount; //Number of devices uint8 ucFramesCount; //number of frames to be sent }tsCddSpiSeqData; typedef struct tsCddSpiSeqHandler { CONST_AL teCddSpiIfc eSpiIfc; uint8 ucCycleCnt; CONST_AL uint8 ucPrescaler; CONST_AL uint8 ucTimeOutMax; uint8 ucTimeOutCnt; uint8 ucSeqContext; uint8 ucIntDevIdx; }tsCddSpiSeqHandler; #endif #if (CDDSPI_DEBUG == STD_ON) //#include #endif //Spi driver state STATIC_AL uint8 CddSpi_ucState = CDDSPI_STATE_RESET; STATIC_AL uint8 CddSpi_CycleCount=0; //Spi status fault #if (CDDSPI_STATUS_FAULT == STD_ON) STATIC_AL uint8 CddSpi_ucStatusFaultVal; #endif //Spi driver profiling #if ((CDDSPI_DEBUG == STD_ON) && (CDDSPI_DEBUG_PROFILE == STD_ON)) STATIC_AL volatile tsCddSpiProfile CddSpi_sProfile; #endif STATIC_AL tsCddSpiIfcCfg CddSpi_asIfcCfg[CddSpi_eIfc_Count] = { { #if (CDDSPI_SINGLE_OPERATION == STD_ON) .eIfcSingleMode = CDDSPI_SINGLE_POLLING , #endif #if (CDDSPI_CYCLIC_OPERATION == STD_ON) .eIfcCyclicMode = CDDSPI_CYCLIC_INTERRUPT , #endif .ucIfcMap = 0 }, { #if (CDDSPI_SINGLE_OPERATION == STD_ON) .eIfcSingleMode = CDDSPI_SINGLE_POLLING , #endif #if (CDDSPI_CYCLIC_OPERATION == STD_ON) .eIfcCyclicMode = CDDSPI_CYCLIC_POLLING , #endif .ucIfcMap = 1 }, };