1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/iic/iic_psl/spi.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,156 @@
1.4 +// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// e32test/iic/iic_psl/spi.h
1.18 +//
1.19 +
1.20 +#ifndef SPI_H_
1.21 +#define SPI_H_
1.22 +
1.23 +#include <drivers/iic_channel.h>
1.24 +#include "../t_iic.h"
1.25 +
1.26 +#ifdef LOG_SPI
1.27 +#define SPI_PRINT(str) Kern::Printf str
1.28 +#else
1.29 +#define SPI_PRINT(str)
1.30 +#endif
1.31 +
1.32 +#ifndef STANDALONE_CHANNEL
1.33 +const TInt8 KSpiChannelNumBase = 1; // Arbitrary, real platform may consult the Configuration Repository
1.34 + // Note limit of 5 bit representation (0-31)
1.35 +#endif
1.36 +
1.37 +class THwDoneCallBack : public TDfc
1.38 + {
1.39 +public:
1.40 + inline THwDoneCallBack(THwDoneCbFn aFn, TAny* aPtr, TDfcQue* aQue, TInt aPriority) : TDfc(DfcFn, this, aQue, aPriority),iCbFn(aFn),iParam(aPtr) {}
1.41 + inline ~THwDoneCallBack(){}
1.42 +
1.43 +private:
1.44 + inline static void DfcFn(TAny* aPtr)
1.45 + {
1.46 + THwDoneCallBack* pCb = (THwDoneCallBack*) aPtr;
1.47 + pCb -> iCbFn(pCb->iParam);
1.48 + }
1.49 +
1.50 +private:
1.51 + THwDoneCbFn iCbFn;
1.52 + TAny* iParam;
1.53 + };
1.54 +
1.55 +class DSimulatedIicBusChannelMasterSpi : public DIicBusChannelMaster
1.56 + {
1.57 + // platform specific implementation
1.58 +
1.59 + enum TTestState
1.60 + {
1.61 + ETestNone=0,
1.62 + ETestWaitPriorityTest,
1.63 + ETestWaitTransOne,
1.64 + ETestSlaveTimeOut
1.65 + };
1.66 +
1.67 + enum TMyState
1.68 + {
1.69 + EIdle,
1.70 + EBusy
1.71 + };
1.72 +
1.73 + enum TIsrCause
1.74 + {
1.75 + EHwTransferDone,
1.76 + ETimeExpired
1.77 + };
1.78 +
1.79 +public:
1.80 +#ifdef STANDALONE_CHANNEL
1.81 + IMPORT_C
1.82 +#endif
1.83 + DSimulatedIicBusChannelMasterSpi(const TBusType aBusType, const TChannelDuplex aChanDuplex);
1.84 + ~DSimulatedIicBusChannelMasterSpi(){iDynamicDfcQ->Destroy();};
1.85 + inline TInt Create() {return DoCreate();}
1.86 + TInt DoCreate();
1.87 + TInt ReleaseChanArray();
1.88 + void CompleteReq(TInt aResult);
1.89 +
1.90 +private:
1.91 + TInt CheckHdr(TDes8* aHdr); // Check the header is valid for this channel
1.92 + virtual TInt StaticExtension(TUint aFunction, TAny* aParam1, TAny* aParam2);
1.93 +
1.94 + TInt CompareTransactionOne(TIicBusTransaction* aTransaction);
1.95 +
1.96 +public:
1.97 + // gateway function for PSL implementation
1.98 + TInt DoRequest(TIicBusTransaction* aTransaction);
1.99 + TInt HandleSlaveTimeout();
1.100 + // Test functions to allow simulating delayed processing of requests
1.101 + static TBool IsRequestDelayed(DSimulatedIicBusChannelMasterSpi* aChan);
1.102 + static void SetRequestDelayed(DSimulatedIicBusChannelMasterSpi* aChan,TBool aDelay);
1.103 +
1.104 + TInt ProcessTrans(TIicBusTransaction* aTransaction); // Accessed by callback
1.105 + TInt AsynchStateMachine(TInt aReason);
1.106 + TInt DoSimulatedTransaction();
1.107 + TInt DoHwPreparation();
1.108 + static void TransactionTimerCallBack(TAny*);
1.109 +
1.110 + inline TInt8 GetChanNum() {return iChannelNumber;};
1.111 +private:
1.112 + TDynamicDfcQue* iDynamicDfcQ; // Use TDynamicDfcQue since will want to DeRegister channels
1.113 +
1.114 + TIicBusTransaction* iCurrTrans;
1.115 +
1.116 + static TInt8 iCurrentChanNum;
1.117 +
1.118 + TInt8 iTestState;
1.119 + TInt8 iChannelState;
1.120 +
1.121 + TBool iReqDelayed;
1.122 + THwDoneCallBack *iCb;
1.123 + TInt iPriorityTestResult[KPriorityTestNum];
1.124 + TBool iPriorityTestDone;
1.125 + };
1.126 +#ifndef STANDALONE_CHANNEL
1.127 +TInt8 DSimulatedIicBusChannelMasterSpi::iCurrentChanNum = KSpiChannelNumBase; // Initialise static member of DSimulatedIicBusChannelMasterSpi
1.128 +#endif
1.129 +class DSimulatedIicBusChannelSlaveSpi : public DIicBusChannelSlave
1.130 + {
1.131 +public:
1.132 + // platform specific implementation
1.133 +#ifdef STANDALONE_CHANNEL
1.134 + IMPORT_C
1.135 +#endif
1.136 + DSimulatedIicBusChannelSlaveSpi(const DIicBusChannel::TBusType aBusType, const DIicBusChannel::TChannelDuplex aChanDuplex);
1.137 + inline TInt Create() {return DoCreate();}
1.138 + TInt DoCreate();
1.139 + // gateway function for PSL implementation
1.140 + TInt DoRequest(TInt aTrigger);
1.141 + void ProcessData(TInt aTrigger, TIicBusSlaveCallback* aCb);
1.142 + virtual TInt StaticExtension(TUint aFunction, TAny* aParam1, TAny* aParam2);
1.143 + static void SlaveAsyncSimCallback(TAny* aPtr);
1.144 + inline void ChanCaptureCb(TInt aResult) {ChanCaptureCallback(aResult);}
1.145 + inline void SetChanNum(TInt8 aChanNum) {iChannelNumber = aChanNum;};
1.146 +protected:
1.147 + virtual void SendBusErrorAndReturn() {return;} // Not implemented in simulated PSL
1.148 +
1.149 + private:
1.150 + TInt CheckHdr(TDes8* aHdr); // Check the header is valid for this channel
1.151 + virtual TInt CaptureChannelPsl(TDes8* aConfigHdr, TBool aAsynch);
1.152 +
1.153 +private:
1.154 + NTimer iSlaveTimer;
1.155 + };
1.156 +
1.157 +
1.158 +
1.159 +#endif /*SPI_H_*/