kerneltest/e32test/iic/iic_psl/spi.h
changeset 0 a41df078684a
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of the License "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // e32test/iic/iic_psl/spi.h
       
    15 //
       
    16 
       
    17 #ifndef SPI_H_
       
    18 #define SPI_H_
       
    19 
       
    20 #include <drivers/iic_channel.h>
       
    21 #include "../t_iic.h"
       
    22 
       
    23 #ifdef LOG_SPI
       
    24 #define SPI_PRINT(str) Kern::Printf str
       
    25 #else
       
    26 #define SPI_PRINT(str)
       
    27 #endif
       
    28 
       
    29 #ifndef STANDALONE_CHANNEL
       
    30 const TInt8 KSpiChannelNumBase = 1;	// Arbitrary, real platform may consult the Configuration Repository
       
    31 									// Note limit of 5 bit representation (0-31)
       
    32 #endif
       
    33 
       
    34 class THwDoneCallBack : public TDfc
       
    35 	{
       
    36 public:
       
    37 	inline THwDoneCallBack(THwDoneCbFn aFn, TAny* aPtr, TDfcQue* aQue, TInt aPriority) : TDfc(DfcFn, this, aQue, aPriority),iCbFn(aFn),iParam(aPtr) {}
       
    38 	inline ~THwDoneCallBack(){}
       
    39 	
       
    40 private:
       
    41 	inline static void DfcFn(TAny* aPtr)
       
    42 		{
       
    43 		THwDoneCallBack* pCb = (THwDoneCallBack*) aPtr;
       
    44 		pCb -> iCbFn(pCb->iParam);
       
    45 		}
       
    46 	
       
    47 private:
       
    48 	THwDoneCbFn iCbFn;
       
    49 	TAny* iParam;
       
    50 	};
       
    51 
       
    52 class DSimulatedIicBusChannelMasterSpi : public DIicBusChannelMaster
       
    53 	{
       
    54 	// platform specific implementation
       
    55 
       
    56 	enum TTestState
       
    57 		{
       
    58 		ETestNone=0,
       
    59 		ETestWaitPriorityTest,
       
    60 		ETestWaitTransOne,
       
    61 		ETestSlaveTimeOut
       
    62 		};
       
    63 	
       
    64 	enum TMyState
       
    65 		{
       
    66 		EIdle,
       
    67 		EBusy
       
    68 		};
       
    69 	
       
    70 	enum TIsrCause
       
    71 		{
       
    72 		EHwTransferDone,
       
    73 		ETimeExpired
       
    74 		};
       
    75 	
       
    76 public:
       
    77 #ifdef STANDALONE_CHANNEL
       
    78 	IMPORT_C
       
    79 #endif
       
    80 	DSimulatedIicBusChannelMasterSpi(const TBusType aBusType, const TChannelDuplex aChanDuplex);
       
    81 	~DSimulatedIicBusChannelMasterSpi(){iDynamicDfcQ->Destroy();};
       
    82 	inline TInt Create() {return DoCreate();}
       
    83 	TInt DoCreate();
       
    84 	TInt ReleaseChanArray();
       
    85 	void CompleteReq(TInt aResult);
       
    86 
       
    87 private:
       
    88 	TInt CheckHdr(TDes8* aHdr);	// Check the header is valid for this channel
       
    89 	virtual TInt StaticExtension(TUint aFunction, TAny* aParam1, TAny* aParam2);	
       
    90 
       
    91 	TInt CompareTransactionOne(TIicBusTransaction* aTransaction);
       
    92 
       
    93 public:
       
    94 	// gateway function for PSL implementation
       
    95 	TInt DoRequest(TIicBusTransaction* aTransaction);
       
    96 	TInt HandleSlaveTimeout();
       
    97 	// Test functions to allow simulating delayed processing of requests
       
    98 	static TBool IsRequestDelayed(DSimulatedIicBusChannelMasterSpi* aChan);
       
    99 	static void SetRequestDelayed(DSimulatedIicBusChannelMasterSpi* aChan,TBool aDelay);
       
   100 
       
   101 	TInt ProcessTrans(TIicBusTransaction* aTransaction); // Accessed by callback
       
   102 	TInt AsynchStateMachine(TInt aReason);
       
   103 	TInt DoSimulatedTransaction();
       
   104 	TInt DoHwPreparation();
       
   105 	static void TransactionTimerCallBack(TAny*);
       
   106 	
       
   107 	inline TInt8 GetChanNum() {return iChannelNumber;};
       
   108 private:
       
   109 	TDynamicDfcQue*	iDynamicDfcQ;	// Use TDynamicDfcQue since will want to DeRegister channels
       
   110 	
       
   111 	TIicBusTransaction* iCurrTrans;
       
   112 	
       
   113 	static TInt8 iCurrentChanNum;
       
   114 
       
   115 	TInt8 iTestState;
       
   116 	TInt8 iChannelState;
       
   117 	
       
   118 	TBool iReqDelayed;
       
   119 	THwDoneCallBack *iCb;
       
   120 	TInt iPriorityTestResult[KPriorityTestNum];
       
   121 	TBool iPriorityTestDone;
       
   122 	};
       
   123 #ifndef STANDALONE_CHANNEL
       
   124 TInt8 DSimulatedIicBusChannelMasterSpi::iCurrentChanNum = KSpiChannelNumBase; // Initialise static member of DSimulatedIicBusChannelMasterSpi
       
   125 #endif
       
   126 class DSimulatedIicBusChannelSlaveSpi : public DIicBusChannelSlave
       
   127 	{
       
   128 public:
       
   129 	// platform specific implementation
       
   130 #ifdef STANDALONE_CHANNEL
       
   131 	IMPORT_C
       
   132 #endif
       
   133 	DSimulatedIicBusChannelSlaveSpi(const DIicBusChannel::TBusType aBusType, const DIicBusChannel::TChannelDuplex aChanDuplex);
       
   134 	inline TInt Create() {return DoCreate();}
       
   135 	TInt DoCreate();
       
   136 	// gateway function for PSL implementation
       
   137 	TInt DoRequest(TInt aTrigger);
       
   138 	void ProcessData(TInt aTrigger, TIicBusSlaveCallback*  aCb);
       
   139 	virtual TInt StaticExtension(TUint aFunction, TAny* aParam1, TAny* aParam2);	
       
   140 	static void SlaveAsyncSimCallback(TAny* aPtr);
       
   141 	inline void ChanCaptureCb(TInt aResult) {ChanCaptureCallback(aResult);}
       
   142 	inline void SetChanNum(TInt8 aChanNum) {iChannelNumber = aChanNum;};
       
   143 protected:
       
   144 	virtual void SendBusErrorAndReturn() {return;} // Not implemented in simulated PSL
       
   145 
       
   146 	private:
       
   147 	TInt CheckHdr(TDes8* aHdr);	// Check the header is valid for this channel
       
   148 	virtual TInt CaptureChannelPsl(TDes8* aConfigHdr, TBool aAsynch);
       
   149 
       
   150 private:
       
   151 	NTimer iSlaveTimer;
       
   152 	};
       
   153 
       
   154 
       
   155 
       
   156 #endif /*SPI_H_*/