1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/iic/iic_psl/i2c.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,152 @@
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/i2c.h
1.18 +//
1.19 +
1.20 +#ifndef I2C_H_
1.21 +#define I2C_H_
1.22 +
1.23 +#include <drivers/iic_channel.h>
1.24 +#include "../t_iic.h"
1.25 +
1.26 +#define NUM_CHANNELS 3 // Arbitrary
1.27 +
1.28 +#ifdef LOG_I2C
1.29 +#define I2C_PRINT(str) Kern::Printf str
1.30 +#else
1.31 +#define I2C_PRINT(str)
1.32 +#endif
1.33 +
1.34 +_LIT(KI2cThreadName,"I2cChannelThread");
1.35 +
1.36 +#ifndef STANDALONE_CHANNEL
1.37 +#if defined(MASTER_MODE)
1.38 +const TInt8 KI2cChannelNumBase = 10; // Arbitrary, real platform may consult the Configuration Repository
1.39 + // Note limit of 5 bit representation (0-31)
1.40 +
1.41 +#else/*MASTER_MODE*/
1.42 +const TInt8 KI2cChannelNumBase = 10 + NUM_CHANNELS; // For Slave mode, want to provide different response
1.43 + // If client assumes Master mode, should be informed not available
1.44 +#endif/*MASTER_MODE*/
1.45 +#endif/*STANDALONE_CHANNEL*/
1.46 +
1.47 +
1.48 +#if defined(MASTER_MODE)
1.49 +const TInt KI2cThreadPriority = 5; // Arbitrary, can be 0-7, 7 highest
1.50 +#endif
1.51 +
1.52 +const TInt16 KI2cSlaveChannelIdBase = 0x1D00; // Arbitrary
1.53 +
1.54 +#ifdef MASTER_MODE
1.55 +class DSimulatedIicBusChannelMasterI2c : public DIicBusChannelMaster
1.56 + {
1.57 + // platform specific implementation
1.58 + public:
1.59 +#ifdef STANDALONE_CHANNEL
1.60 + IMPORT_C
1.61 +#endif
1.62 + DSimulatedIicBusChannelMasterI2c(const TBusType aBusType, const TChannelDuplex aChanDuplex);
1.63 + inline TInt Create() {return DoCreate();}
1.64 + TInt DoCreate();
1.65 +
1.66 +
1.67 +private:
1.68 + TInt CheckHdr(TDes8* aHdr); // Check the header is valid for this channel
1.69 + TInt StaticExtension(TUint aFunction, TAny* aParam1, TAny* aParam2);
1.70 +public:
1.71 + // gateway function for PSL implementation
1.72 + TInt DoRequest(TIicBusTransaction* aTransaction);
1.73 + TInt HandleSlaveTimeout();
1.74 +
1.75 + // Test functions to allow simulating delayed processing of requests
1.76 + static TBool IsRequestDelayed(DSimulatedIicBusChannelMasterI2c* aChan);
1.77 + static void SetRequestDelayed(DSimulatedIicBusChannelMasterI2c* aChan,TBool aDelay);
1.78 +
1.79 + TInt ProcessTrans(); // Accessed by callback
1.80 + inline TInt8 GetChanNum() {return iChannelNumber;};
1.81 +private:
1.82 + TDynamicDfcQue* iDynamicDfcQ;
1.83 +
1.84 + static TInt8 iCurrentChanNum;
1.85 +
1.86 + TBool iReqDelayed;
1.87 + };
1.88 +#ifndef STANDALONE_CHANNEL
1.89 +TInt8 DSimulatedIicBusChannelMasterI2c::iCurrentChanNum = KI2cChannelNumBase; // Initialise static member of DSimulatedIicBusChannelMasterI2c
1.90 +#endif
1.91 +#endif/*MASTER_MODE*/
1.92 +
1.93 +#ifdef SLAVE_MODE
1.94 +class DSimulatedIicBusChannelSlaveI2c : public DIicBusChannelSlave
1.95 + {
1.96 +public:
1.97 + // platform specific implementation
1.98 +#ifdef STANDALONE_CHANNEL
1.99 + IMPORT_C
1.100 +#endif
1.101 + DSimulatedIicBusChannelSlaveI2c(const DIicBusChannel::TBusType aBusType, const DIicBusChannel::TChannelDuplex aChanDuplex);
1.102 + ~DSimulatedIicBusChannelSlaveI2c();
1.103 + // gateway function for PSL implementation
1.104 + TInt DoRequest(TInt aTrigger);
1.105 + void ProcessData(TInt aTrigger, TIicBusSlaveCallback* aCb);
1.106 + TInt StaticExtension(TUint aFunction, TAny* aParam1, TAny* aParam2);
1.107 +
1.108 + inline TInt Create() {return DoCreate();}
1.109 + virtual TInt DoCreate();
1.110 +
1.111 + static void SlaveAsyncSimCallback(TAny* aPtr);
1.112 + inline void ChanCaptureCb(TInt aResult) {ChanCaptureCallback(aResult);}
1.113 +
1.114 + inline void SetChanNum(TInt8 aChanNum) {iChannelNumber = aChanNum;};
1.115 +
1.116 + protected:
1.117 + virtual void SendBusErrorAndReturn() {return;} // Not implemented in simulated PSL
1.118 +
1.119 +
1.120 + private:
1.121 + TInt CheckHdr(TDes8* aHdr); // Check the header is valid for this channel
1.122 + virtual TInt CaptureChannelPsl(TBool aAsynch);
1.123 + virtual TInt ReleaseChannelPsl();
1.124 + TInt PrepareTrigger(TInt aTrigger);
1.125 + private:
1.126 +
1.127 + TInt8 iDeltaWordsToRx;
1.128 + TInt8 iDeltaWordsToTx;
1.129 + TInt8 iNumWordsWereRx;
1.130 + TInt8 iNumWordsWereTx;
1.131 + TInt8 iRxTxUnderOverRun;
1.132 +
1.133 + TInt8* iTxCheckBuf;
1.134 +
1.135 + TInt iBlockedTrigger;
1.136 + TBool iBlockNotification;
1.137 +
1.138 + NTimer iSlaveTimer; // Used to simulate an asynchronous capture operation
1.139 + };
1.140 +#endif/*SLAVE_MODE*/
1.141 +
1.142 +#if defined(MASTER_MODE) && defined(SLAVE_MODE)
1.143 +class DSimulatedIicBusChannelMasterSlaveI2c : public DIicBusChannelMasterSlave
1.144 + {
1.145 +public:
1.146 +#ifdef STANDALONE_CHANNEL
1.147 + IMPORT_C
1.148 +#endif
1.149 + DSimulatedIicBusChannelMasterSlaveI2c(TBusType /*aBusType*/, TChannelDuplex aChanDuplex, DSimulatedIicBusChannelMasterI2c* aMasterChan, DSimulatedIicBusChannelSlaveI2c* aSlaveChan);
1.150 +
1.151 + TInt StaticExtension(TUint aFunction, TAny* aParam1, TAny* aParam2);
1.152 + };
1.153 +#endif/*(MASTER_MODE) && (SLAVE_MODE)*/
1.154 +
1.155 +#endif /*I2C_H_*/