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/i2c.h sl@0: // sl@0: sl@0: #ifndef I2C_H_ sl@0: #define I2C_H_ sl@0: sl@0: #include sl@0: #include "../t_iic.h" sl@0: sl@0: #define NUM_CHANNELS 3 // Arbitrary sl@0: sl@0: #ifdef LOG_I2C sl@0: #define I2C_PRINT(str) Kern::Printf str sl@0: #else sl@0: #define I2C_PRINT(str) sl@0: #endif sl@0: sl@0: _LIT(KI2cThreadName,"I2cChannelThread"); sl@0: sl@0: #ifndef STANDALONE_CHANNEL sl@0: #if defined(MASTER_MODE) sl@0: const TInt8 KI2cChannelNumBase = 10; // Arbitrary, real platform may consult the Configuration Repository sl@0: // Note limit of 5 bit representation (0-31) sl@0: sl@0: #else/*MASTER_MODE*/ sl@0: const TInt8 KI2cChannelNumBase = 10 + NUM_CHANNELS; // For Slave mode, want to provide different response sl@0: // If client assumes Master mode, should be informed not available sl@0: #endif/*MASTER_MODE*/ sl@0: #endif/*STANDALONE_CHANNEL*/ sl@0: sl@0: sl@0: #if defined(MASTER_MODE) sl@0: const TInt KI2cThreadPriority = 5; // Arbitrary, can be 0-7, 7 highest sl@0: #endif sl@0: sl@0: const TInt16 KI2cSlaveChannelIdBase = 0x1D00; // Arbitrary sl@0: sl@0: #ifdef MASTER_MODE sl@0: class DSimulatedIicBusChannelMasterI2c : public DIicBusChannelMaster sl@0: { sl@0: // platform specific implementation sl@0: public: sl@0: #ifdef STANDALONE_CHANNEL sl@0: IMPORT_C sl@0: #endif sl@0: DSimulatedIicBusChannelMasterI2c(const TBusType aBusType, const TChannelDuplex aChanDuplex); sl@0: inline TInt Create() {return DoCreate();} sl@0: TInt DoCreate(); sl@0: sl@0: sl@0: private: sl@0: TInt CheckHdr(TDes8* aHdr); // Check the header is valid for this channel sl@0: TInt StaticExtension(TUint aFunction, TAny* aParam1, TAny* aParam2); sl@0: public: sl@0: // gateway function for PSL implementation sl@0: TInt DoRequest(TIicBusTransaction* aTransaction); sl@0: TInt HandleSlaveTimeout(); sl@0: sl@0: // Test functions to allow simulating delayed processing of requests sl@0: static TBool IsRequestDelayed(DSimulatedIicBusChannelMasterI2c* aChan); sl@0: static void SetRequestDelayed(DSimulatedIicBusChannelMasterI2c* aChan,TBool aDelay); sl@0: sl@0: TInt ProcessTrans(); // Accessed by callback sl@0: inline TInt8 GetChanNum() {return iChannelNumber;}; sl@0: private: sl@0: TDynamicDfcQue* iDynamicDfcQ; sl@0: sl@0: static TInt8 iCurrentChanNum; sl@0: sl@0: TBool iReqDelayed; sl@0: }; sl@0: #ifndef STANDALONE_CHANNEL sl@0: TInt8 DSimulatedIicBusChannelMasterI2c::iCurrentChanNum = KI2cChannelNumBase; // Initialise static member of DSimulatedIicBusChannelMasterI2c sl@0: #endif sl@0: #endif/*MASTER_MODE*/ sl@0: sl@0: #ifdef SLAVE_MODE sl@0: class DSimulatedIicBusChannelSlaveI2c : 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: DSimulatedIicBusChannelSlaveI2c(const DIicBusChannel::TBusType aBusType, const DIicBusChannel::TChannelDuplex aChanDuplex); sl@0: ~DSimulatedIicBusChannelSlaveI2c(); sl@0: // gateway function for PSL implementation sl@0: TInt DoRequest(TInt aTrigger); sl@0: void ProcessData(TInt aTrigger, TIicBusSlaveCallback* aCb); sl@0: TInt StaticExtension(TUint aFunction, TAny* aParam1, TAny* aParam2); sl@0: sl@0: inline TInt Create() {return DoCreate();} sl@0: virtual TInt DoCreate(); sl@0: sl@0: static void SlaveAsyncSimCallback(TAny* aPtr); sl@0: inline void ChanCaptureCb(TInt aResult) {ChanCaptureCallback(aResult);} sl@0: sl@0: inline void SetChanNum(TInt8 aChanNum) {iChannelNumber = aChanNum;}; sl@0: sl@0: protected: sl@0: virtual void SendBusErrorAndReturn() {return;} // Not implemented in simulated PSL sl@0: sl@0: sl@0: private: sl@0: TInt CheckHdr(TDes8* aHdr); // Check the header is valid for this channel sl@0: virtual TInt CaptureChannelPsl(TBool aAsynch); sl@0: virtual TInt ReleaseChannelPsl(); sl@0: TInt PrepareTrigger(TInt aTrigger); sl@0: private: sl@0: sl@0: TInt8 iDeltaWordsToRx; sl@0: TInt8 iDeltaWordsToTx; sl@0: TInt8 iNumWordsWereRx; sl@0: TInt8 iNumWordsWereTx; sl@0: TInt8 iRxTxUnderOverRun; sl@0: sl@0: TInt8* iTxCheckBuf; sl@0: sl@0: TInt iBlockedTrigger; sl@0: TBool iBlockNotification; sl@0: sl@0: NTimer iSlaveTimer; // Used to simulate an asynchronous capture operation sl@0: }; sl@0: #endif/*SLAVE_MODE*/ sl@0: sl@0: #if defined(MASTER_MODE) && defined(SLAVE_MODE) sl@0: class DSimulatedIicBusChannelMasterSlaveI2c : public DIicBusChannelMasterSlave sl@0: { sl@0: public: sl@0: #ifdef STANDALONE_CHANNEL sl@0: IMPORT_C sl@0: #endif sl@0: DSimulatedIicBusChannelMasterSlaveI2c(TBusType /*aBusType*/, TChannelDuplex aChanDuplex, DSimulatedIicBusChannelMasterI2c* aMasterChan, DSimulatedIicBusChannelSlaveI2c* aSlaveChan); sl@0: sl@0: TInt StaticExtension(TUint aFunction, TAny* aParam1, TAny* aParam2); sl@0: }; sl@0: #endif/*(MASTER_MODE) && (SLAVE_MODE)*/ sl@0: sl@0: #endif /*I2C_H_*/