sl@0: // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // e32test/iic/iic_psl/spi.h sl@0: // sl@0: sl@0: #ifndef SPI_H_ sl@0: #define SPI_H_ sl@0: sl@0: #include sl@0: #include "../t_iic.h" sl@0: sl@0: #ifdef LOG_SPI sl@0: #define SPI_PRINT(str) Kern::Printf str sl@0: #else sl@0: #define SPI_PRINT(str) sl@0: #endif sl@0: sl@0: #ifndef STANDALONE_CHANNEL sl@0: const TInt8 KSpiChannelNumBase = 1; // Arbitrary, real platform may consult the Configuration Repository sl@0: // Note limit of 5 bit representation (0-31) sl@0: #endif sl@0: sl@0: class THwDoneCallBack : public TDfc sl@0: { sl@0: public: sl@0: inline THwDoneCallBack(THwDoneCbFn aFn, TAny* aPtr, TDfcQue* aQue, TInt aPriority) : TDfc(DfcFn, this, aQue, aPriority),iCbFn(aFn),iParam(aPtr) {} sl@0: inline ~THwDoneCallBack(){} sl@0: sl@0: private: sl@0: inline static void DfcFn(TAny* aPtr) sl@0: { sl@0: THwDoneCallBack* pCb = (THwDoneCallBack*) aPtr; sl@0: pCb -> iCbFn(pCb->iParam); sl@0: } sl@0: sl@0: private: sl@0: THwDoneCbFn iCbFn; sl@0: TAny* iParam; sl@0: }; sl@0: sl@0: class DSimulatedIicBusChannelMasterSpi : public DIicBusChannelMaster sl@0: { sl@0: // platform specific implementation sl@0: sl@0: enum TTestState sl@0: { sl@0: ETestNone=0, sl@0: ETestWaitPriorityTest, sl@0: ETestWaitTransOne, sl@0: ETestSlaveTimeOut sl@0: }; sl@0: sl@0: enum TMyState sl@0: { sl@0: EIdle, sl@0: EBusy sl@0: }; sl@0: sl@0: enum TIsrCause sl@0: { sl@0: EHwTransferDone, sl@0: ETimeExpired sl@0: }; sl@0: sl@0: public: sl@0: #ifdef STANDALONE_CHANNEL sl@0: IMPORT_C sl@0: #endif sl@0: DSimulatedIicBusChannelMasterSpi(const TBusType aBusType, const TChannelDuplex aChanDuplex); sl@0: ~DSimulatedIicBusChannelMasterSpi(){iDynamicDfcQ->Destroy();}; sl@0: inline TInt Create() {return DoCreate();} sl@0: TInt DoCreate(); sl@0: TInt ReleaseChanArray(); sl@0: void CompleteReq(TInt aResult); sl@0: sl@0: private: sl@0: TInt CheckHdr(TDes8* aHdr); // Check the header is valid for this channel sl@0: virtual TInt StaticExtension(TUint aFunction, TAny* aParam1, TAny* aParam2); sl@0: sl@0: TInt CompareTransactionOne(TIicBusTransaction* aTransaction); sl@0: sl@0: public: sl@0: // gateway function for PSL implementation sl@0: TInt DoRequest(TIicBusTransaction* aTransaction); sl@0: TInt HandleSlaveTimeout(); sl@0: // Test functions to allow simulating delayed processing of requests sl@0: static TBool IsRequestDelayed(DSimulatedIicBusChannelMasterSpi* aChan); sl@0: static void SetRequestDelayed(DSimulatedIicBusChannelMasterSpi* aChan,TBool aDelay); sl@0: sl@0: TInt ProcessTrans(TIicBusTransaction* aTransaction); // Accessed by callback sl@0: TInt AsynchStateMachine(TInt aReason); sl@0: TInt DoSimulatedTransaction(); sl@0: TInt DoHwPreparation(); sl@0: static void TransactionTimerCallBack(TAny*); sl@0: sl@0: inline TInt8 GetChanNum() {return iChannelNumber;}; sl@0: private: sl@0: TDynamicDfcQue* iDynamicDfcQ; // Use TDynamicDfcQue since will want to DeRegister channels sl@0: sl@0: TIicBusTransaction* iCurrTrans; sl@0: sl@0: static TInt8 iCurrentChanNum; sl@0: sl@0: TInt8 iTestState; sl@0: TInt8 iChannelState; sl@0: sl@0: TBool iReqDelayed; sl@0: THwDoneCallBack *iCb; sl@0: TInt iPriorityTestResult[KPriorityTestNum]; sl@0: TBool iPriorityTestDone; sl@0: }; sl@0: #ifndef STANDALONE_CHANNEL sl@0: TInt8 DSimulatedIicBusChannelMasterSpi::iCurrentChanNum = KSpiChannelNumBase; // Initialise static member of DSimulatedIicBusChannelMasterSpi sl@0: #endif sl@0: class DSimulatedIicBusChannelSlaveSpi : public DIicBusChannelSlave sl@0: { sl@0: public: sl@0: // platform specific implementation sl@0: #ifdef STANDALONE_CHANNEL sl@0: IMPORT_C sl@0: #endif sl@0: DSimulatedIicBusChannelSlaveSpi(const DIicBusChannel::TBusType aBusType, const DIicBusChannel::TChannelDuplex aChanDuplex); sl@0: inline TInt Create() {return DoCreate();} sl@0: TInt DoCreate(); sl@0: // gateway function for PSL implementation sl@0: TInt DoRequest(TInt aTrigger); sl@0: void ProcessData(TInt aTrigger, TIicBusSlaveCallback* aCb); sl@0: virtual TInt StaticExtension(TUint aFunction, TAny* aParam1, TAny* aParam2); sl@0: static void SlaveAsyncSimCallback(TAny* aPtr); sl@0: inline void ChanCaptureCb(TInt aResult) {ChanCaptureCallback(aResult);} sl@0: inline void SetChanNum(TInt8 aChanNum) {iChannelNumber = aChanNum;}; sl@0: protected: sl@0: virtual void SendBusErrorAndReturn() {return;} // Not implemented in simulated PSL sl@0: sl@0: private: sl@0: TInt CheckHdr(TDes8* aHdr); // Check the header is valid for this channel sl@0: virtual TInt CaptureChannelPsl(TDes8* aConfigHdr, TBool aAsynch); sl@0: sl@0: private: sl@0: NTimer iSlaveTimer; sl@0: }; sl@0: sl@0: sl@0: sl@0: #endif /*SPI_H_*/