Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test/iic/iic_psl/i2c.h
20 #include <drivers/iic_channel.h>
23 #define NUM_CHANNELS 3 // Arbitrary
26 #define I2C_PRINT(str) Kern::Printf str
28 #define I2C_PRINT(str)
31 _LIT(KI2cThreadName,"I2cChannelThread");
33 #ifndef STANDALONE_CHANNEL
34 #if defined(MASTER_MODE)
35 const TInt8 KI2cChannelNumBase = 10; // Arbitrary, real platform may consult the Configuration Repository
36 // Note limit of 5 bit representation (0-31)
39 const TInt8 KI2cChannelNumBase = 10 + NUM_CHANNELS; // For Slave mode, want to provide different response
40 // If client assumes Master mode, should be informed not available
42 #endif/*STANDALONE_CHANNEL*/
45 #if defined(MASTER_MODE)
46 const TInt KI2cThreadPriority = 5; // Arbitrary, can be 0-7, 7 highest
49 const TInt16 KI2cSlaveChannelIdBase = 0x1D00; // Arbitrary
52 class DSimulatedIicBusChannelMasterI2c : public DIicBusChannelMaster
54 // platform specific implementation
56 #ifdef STANDALONE_CHANNEL
59 DSimulatedIicBusChannelMasterI2c(const TBusType aBusType, const TChannelDuplex aChanDuplex);
60 inline TInt Create() {return DoCreate();}
65 TInt CheckHdr(TDes8* aHdr); // Check the header is valid for this channel
66 TInt StaticExtension(TUint aFunction, TAny* aParam1, TAny* aParam2);
68 // gateway function for PSL implementation
69 TInt DoRequest(TIicBusTransaction* aTransaction);
70 TInt HandleSlaveTimeout();
72 // Test functions to allow simulating delayed processing of requests
73 static TBool IsRequestDelayed(DSimulatedIicBusChannelMasterI2c* aChan);
74 static void SetRequestDelayed(DSimulatedIicBusChannelMasterI2c* aChan,TBool aDelay);
76 TInt ProcessTrans(); // Accessed by callback
77 inline TInt8 GetChanNum() {return iChannelNumber;};
79 TDynamicDfcQue* iDynamicDfcQ;
81 static TInt8 iCurrentChanNum;
85 #ifndef STANDALONE_CHANNEL
86 TInt8 DSimulatedIicBusChannelMasterI2c::iCurrentChanNum = KI2cChannelNumBase; // Initialise static member of DSimulatedIicBusChannelMasterI2c
91 class DSimulatedIicBusChannelSlaveI2c : public DIicBusChannelSlave
94 // platform specific implementation
95 #ifdef STANDALONE_CHANNEL
98 DSimulatedIicBusChannelSlaveI2c(const DIicBusChannel::TBusType aBusType, const DIicBusChannel::TChannelDuplex aChanDuplex);
99 ~DSimulatedIicBusChannelSlaveI2c();
100 // gateway function for PSL implementation
101 TInt DoRequest(TInt aTrigger);
102 void ProcessData(TInt aTrigger, TIicBusSlaveCallback* aCb);
103 TInt StaticExtension(TUint aFunction, TAny* aParam1, TAny* aParam2);
105 inline TInt Create() {return DoCreate();}
106 virtual TInt DoCreate();
108 static void SlaveAsyncSimCallback(TAny* aPtr);
109 inline void ChanCaptureCb(TInt aResult) {ChanCaptureCallback(aResult);}
111 inline void SetChanNum(TInt8 aChanNum) {iChannelNumber = aChanNum;};
114 virtual void SendBusErrorAndReturn() {return;} // Not implemented in simulated PSL
118 TInt CheckHdr(TDes8* aHdr); // Check the header is valid for this channel
119 virtual TInt CaptureChannelPsl(TBool aAsynch);
120 virtual TInt ReleaseChannelPsl();
121 TInt PrepareTrigger(TInt aTrigger);
124 TInt8 iDeltaWordsToRx;
125 TInt8 iDeltaWordsToTx;
126 TInt8 iNumWordsWereRx;
127 TInt8 iNumWordsWereTx;
128 TInt8 iRxTxUnderOverRun;
132 TInt iBlockedTrigger;
133 TBool iBlockNotification;
135 NTimer iSlaveTimer; // Used to simulate an asynchronous capture operation
139 #if defined(MASTER_MODE) && defined(SLAVE_MODE)
140 class DSimulatedIicBusChannelMasterSlaveI2c : public DIicBusChannelMasterSlave
143 #ifdef STANDALONE_CHANNEL
146 DSimulatedIicBusChannelMasterSlaveI2c(TBusType /*aBusType*/, TChannelDuplex aChanDuplex, DSimulatedIicBusChannelMasterI2c* aMasterChan, DSimulatedIicBusChannelSlaveI2c* aSlaveChan);
148 TInt StaticExtension(TUint aFunction, TAny* aParam1, TAny* aParam2);
150 #endif/*(MASTER_MODE) && (SLAVE_MODE)*/