os/kernelhwsrv/kerneltest/e32test/iic/iic_psl/i2c.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/iic/iic_psl/i2c.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,1068 @@
     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.cpp
    1.18 +//
    1.19 +
    1.20 +#include "i2c.h"
    1.21 +
    1.22 +#ifdef IIC_INSTRUMENTATION_MACRO
    1.23 +#include <drivers/iic_trace.h>
    1.24 +#endif
    1.25 +
    1.26 +
    1.27 +#if defined(MASTER_MODE) && !defined(SLAVE_MODE)
    1.28 +const TInt KChannelTypeArray[NUM_CHANNELS] = {DIicBusChannel::EMaster, DIicBusChannel::EMaster, DIicBusChannel::EMaster};
    1.29 +#elif defined(MASTER_MODE) && defined(SLAVE_MODE)
    1.30 +const TInt KChannelTypeArray[NUM_CHANNELS] = {DIicBusChannel::EMaster, DIicBusChannel::ESlave, DIicBusChannel::EMasterSlave};
    1.31 +#else
    1.32 +const TInt KChannelTypeArray[NUM_CHANNELS] = {DIicBusChannel::ESlave, DIicBusChannel::ESlave, DIicBusChannel::ESlave};
    1.33 +#endif
    1.34 +#define CHANNEL_TYPE(n) (KChannelTypeArray[n])	
    1.35 +#define CHANNEL_DUPLEX(n) (DIicBusChannel::EHalfDuplex)
    1.36 +
    1.37 +#ifdef STANDALONE_CHANNEL
    1.38 +_LIT(KPddNameI2c,"i2c_ctrless.pdd");
    1.39 +#else
    1.40 +_LIT(KPddNameI2c,"i2c.pdd");
    1.41 +#endif
    1.42 +
    1.43 +#ifndef STANDALONE_CHANNEL
    1.44 +LOCAL_C TInt8 AssignChanNum()
    1.45 +	{
    1.46 +	static TInt8 iBaseChanNum = KI2cChannelNumBase;
    1.47 +	I2C_PRINT(("I2C AssignChanNum - on entry, iBaseChanNum = 0x%x\n",iBaseChanNum));
    1.48 +	return iBaseChanNum++; // Arbitrary, for illustration
    1.49 +	}
    1.50 +#endif/*STANDALONE_CHANNEL*/
    1.51 +
    1.52 +#ifdef SLAVE_MODE
    1.53 +LOCAL_C TInt16 AssignSlaveChanId()
    1.54 +	{
    1.55 +	static TInt16 iBaseSlaveChanId = KI2cSlaveChannelIdBase;
    1.56 +	I2C_PRINT(("I2C AssignSlaveChanId - on entry, iBaseSlaveChanId = 0x%x\n",iBaseSlaveChanId));
    1.57 +	return iBaseSlaveChanId++; // Arbitrary, for illustration
    1.58 +	}
    1.59 +#endif/*SLAVE_MODE*/
    1.60 +
    1.61 +NONSHARABLE_CLASS(DSimulatedI2cDevice) : public DPhysicalDevice
    1.62 +	{
    1.63 +// Class to faciliate loading of the IIC classes
    1.64 +public:
    1.65 +	class TCaps
    1.66 +		{
    1.67 +	public:
    1.68 +		TVersion iVersion;
    1.69 +		};
    1.70 +public:
    1.71 +	DSimulatedI2cDevice();
    1.72 +	virtual TInt Install();
    1.73 +	virtual TInt Create(DBase*& aChannel, TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
    1.74 +	virtual TInt Validate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
    1.75 +	virtual void GetCaps(TDes8& aDes) const;
    1.76 +	inline static TVersion VersionRequired();
    1.77 +	};
    1.78 +
    1.79 +TVersion DSimulatedI2cDevice::VersionRequired()
    1.80 +	{
    1.81 +	I2C_PRINT(("DSimulatedI2cDevice::VersionRequired\n"));
    1.82 +	return TVersion(KIicClientMajorVersionNumber,KIicClientMinorVersionNumber,KIicClientBuildVersionNumber);
    1.83 +	}
    1.84 +
    1.85 +/** Factory class constructor */
    1.86 +DSimulatedI2cDevice::DSimulatedI2cDevice()
    1.87 +	{
    1.88 +	I2C_PRINT(("DSimulatedI2cDevice::DSimulatedI2cDevice\n"));
    1.89 +    iVersion = DSimulatedI2cDevice::VersionRequired();
    1.90 +	}
    1.91 +
    1.92 +TInt DSimulatedI2cDevice::Install()
    1.93 +    {
    1.94 +	I2C_PRINT(("DSimulatedI2cDevice::Install\n"));
    1.95 +    return(SetName(&KPddNameI2c));
    1.96 +    }
    1.97 +
    1.98 +/**  Called by the kernel's device driver framework to create a Physical Channel. */
    1.99 +TInt DSimulatedI2cDevice::Create(DBase*& /*aChannel*/, TInt /*aUint*/, const TDesC8* /*anInfo*/, const TVersion& /*aVer*/)
   1.100 +    {
   1.101 +	I2C_PRINT(("DSimulatedI2cDevice::Create\n"));
   1.102 +    return KErrNone;
   1.103 +    }
   1.104 +
   1.105 +/**  Called by the kernel's device driver framework to check if this PDD is suitable for use with a Logical Channel.*/
   1.106 +TInt DSimulatedI2cDevice::Validate(TInt /*aUnit*/, const TDesC8* /*anInfo*/, const TVersion& aVer)
   1.107 +    {
   1.108 +	I2C_PRINT(("DSimulatedI2cDevice::Validate\n"));
   1.109 +   	if (!Kern::QueryVersionSupported(DSimulatedI2cDevice::VersionRequired(),aVer))
   1.110 +		return(KErrNotSupported);
   1.111 +    return KErrNone;
   1.112 +    }
   1.113 +
   1.114 +/** Return the driver capabilities */
   1.115 +void DSimulatedI2cDevice::GetCaps(TDes8& aDes) const
   1.116 +    {
   1.117 +	I2C_PRINT(("DSimulatedI2cDevice::GetCaps\n"));
   1.118 +	// Create a capabilities object
   1.119 +	TCaps caps;
   1.120 +	caps.iVersion = iVersion;
   1.121 +	// Zero the buffer
   1.122 +	TInt maxLen = aDes.MaxLength();
   1.123 +	aDes.FillZ(maxLen);
   1.124 +	// Copy capabilities
   1.125 +	TInt size=sizeof(caps);
   1.126 +	if(size>maxLen)
   1.127 +	   size=maxLen;
   1.128 +	aDes.Copy((TUint8*)&caps,size);
   1.129 +    }
   1.130 +
   1.131 +// supported channels for this implementation
   1.132 +static DIicBusChannel* ChannelPtrArray[NUM_CHANNELS];
   1.133 +
   1.134 +
   1.135 +//DECLARE_EXTENSION_WITH_PRIORITY(BUS_IMPLMENTATION_PRIORITY)	
   1.136 +DECLARE_STANDARD_PDD()		// I2c test driver to be explicitly loaded as an LDD, not kernel extension
   1.137 +	{	
   1.138 +#ifndef STANDALONE_CHANNEL
   1.139 +	DIicBusChannel* chan=NULL;
   1.140 +	for(TInt i=0; i<NUM_CHANNELS; i++)
   1.141 +		{
   1.142 +	I2C_PRINT(("\n"));
   1.143 +#if defined(MASTER_MODE)
   1.144 +		if(CHANNEL_TYPE(i) == (DIicBusChannel::EMaster))
   1.145 +			{
   1.146 +			chan=new DSimulatedIicBusChannelMasterI2c(BUS_TYPE,CHANNEL_DUPLEX(i));
   1.147 +			if(!chan)
   1.148 +				return NULL;
   1.149 +			I2C_PRINT(("I2C chan created at 0x%x\n",chan));
   1.150 +			if(((DSimulatedIicBusChannelMasterI2c*)chan)->Create()!=KErrNone)
   1.151 +			    {
   1.152 +			    delete chan;
   1.153 +				return NULL;
   1.154 +                }
   1.155 +			}
   1.156 +#endif
   1.157 +#if defined(MASTER_MODE) && defined(SLAVE_MODE)
   1.158 +		if(CHANNEL_TYPE(i) == DIicBusChannel::EMasterSlave)
   1.159 +			{
   1.160 +			DIicBusChannel* chanM=new DSimulatedIicBusChannelMasterI2c(BUS_TYPE,CHANNEL_DUPLEX(i));
   1.161 +			if(!chanM)
   1.162 +				return NULL;
   1.163 +			DIicBusChannel* chanS=new DSimulatedIicBusChannelSlaveI2c(BUS_TYPE,CHANNEL_DUPLEX(i));
   1.164 +			if(!chanS)
   1.165 +			    {
   1.166 +			    delete chanM;
   1.167 +				return NULL;
   1.168 +			    }
   1.169 +			// For MasterSlave channel, the channel number for both the Master and Slave channels must be the same
   1.170 +			TInt8 msChanNum = ((DSimulatedIicBusChannelMasterI2c*)chanM)->GetChanNum();
   1.171 +			((DSimulatedIicBusChannelSlaveI2c*)chanS)->SetChanNum(msChanNum);
   1.172 +
   1.173 +			chan=new DSimulatedIicBusChannelMasterSlaveI2c(BUS_TYPE,CHANNEL_DUPLEX(i),(DSimulatedIicBusChannelMasterI2c*)chanM,(DSimulatedIicBusChannelSlaveI2c*)chanS); // Generic implementation
   1.174 +			if(!chan)
   1.175 +			    {
   1.176 +			    delete chanM;
   1.177 +			    delete chanS;
   1.178 +				return NULL;
   1.179 +			    }
   1.180 +			I2C_PRINT(("I2C chan created at 0x%x\n",chan));
   1.181 +			if(((DIicBusChannelMasterSlave*)chan)->DoCreate()!=KErrNone)
   1.182 +			    {
   1.183 +			    delete chanM;
   1.184 +			    delete chanS;
   1.185 +			    delete chan;
   1.186 +				return NULL;
   1.187 +			    }
   1.188 +			}
   1.189 +#endif
   1.190 +#if defined(SLAVE_MODE)
   1.191 +		if(CHANNEL_TYPE(i) == (DIicBusChannel::ESlave))
   1.192 +			{
   1.193 +			chan=new DSimulatedIicBusChannelSlaveI2c(BUS_TYPE,CHANNEL_DUPLEX(i));
   1.194 +			if(!chan)
   1.195 +				return NULL;
   1.196 +			I2C_PRINT(("I2C chan created at 0x%x\n",chan));
   1.197 +			if(((DSimulatedIicBusChannelSlaveI2c*)chan)->Create()!=KErrNone)
   1.198 +			    {
   1.199 +			    delete chan;
   1.200 +			    return NULL;
   1.201 +			    }
   1.202 +			}
   1.203 +#endif
   1.204 +#if !defined(MASTER_MODE) && !defined(SLAVE_MODE)
   1.205 +#error I2C mode not defined as Master, Slave nor Master-Slave
   1.206 +#endif
   1.207 +		if(chan == NULL)
   1.208 +			{
   1.209 +			I2C_PRINT(("\n\nI2C: Channel of type (%d) not created for index %d\n\n",CHANNEL_TYPE(i),i));
   1.210 +			return NULL;
   1.211 +			}
   1.212 +		ChannelPtrArray[i]=chan;
   1.213 +		}
   1.214 +	I2C_PRINT(("\nI2C PDD, channel creation loop done- about to invoke RegisterChannels\n\n"));
   1.215 +#ifdef IIC_INSTRUMENTATION_MACRO
   1.216 +	IIC_REGISTERCHANS_START_PSL_TRACE;
   1.217 +#endif
   1.218 +
   1.219 +	TInt r=DIicBusController::RegisterChannels(ChannelPtrArray,NUM_CHANNELS);
   1.220 +
   1.221 +#ifdef IIC_INSTRUMENTATION_MACRO
   1.222 +	IIC_REGISTERCHANS_END_PSL_TRACE;
   1.223 +#endif
   1.224 +	I2C_PRINT(("\nI2C - returned from RegisterChannels with r=%d\n",r));
   1.225 +	if(r!=KErrNone)
   1.226 +		{
   1.227 +		delete chan;
   1.228 +		return NULL;
   1.229 +		}
   1.230 +#endif
   1.231 +	return new DSimulatedI2cDevice;
   1.232 +	}
   1.233 +
   1.234 +
   1.235 +#ifdef MASTER_MODE
   1.236 +#ifdef STANDALONE_CHANNEL
   1.237 +EXPORT_C
   1.238 +#endif
   1.239 +DSimulatedIicBusChannelMasterI2c::DSimulatedIicBusChannelMasterI2c(const TBusType aBusType, const TChannelDuplex aChanDuplex)
   1.240 +	: DIicBusChannelMaster(aBusType,aChanDuplex)
   1.241 +	{
   1.242 +	I2C_PRINT(("DSimulatedIicBusChannelMasterI2c::DSimulatedIicBusChannelMasterI2c, aBusType=%d,aChanDuplex=%d\n",aBusType,aChanDuplex));
   1.243 +#ifndef STANDALONE_CHANNEL
   1.244 +	iChannelNumber = AssignChanNum();
   1.245 +#endif
   1.246 +	I2C_PRINT(("DSimulatedIicBusChannelMasterI2c::DSimulatedIicBusChannelMasterI2c, iChannelNumber=%d\n",iChannelNumber));
   1.247 +	}
   1.248 +
   1.249 +TInt DSimulatedIicBusChannelMasterI2c::DoCreate()
   1.250 +	{
   1.251 +	I2C_PRINT(("DSimulatedIicBusChannelMasterI2c::DoCreate\n"));
   1.252 +	TInt r=Init();	// PIL Base class initialisation
   1.253 +	r=Kern::DynamicDfcQCreate(iDynamicDfcQ,KI2cThreadPriority,KI2cThreadName);
   1.254 +	if(r == KErrNone)
   1.255 +		SetDfcQ((TDfcQue*)iDynamicDfcQ);
   1.256 +	DSimulatedIicBusChannelMasterI2c::SetRequestDelayed(this,EFalse);
   1.257 +	return r;
   1.258 +	}
   1.259 +
   1.260 +TInt DSimulatedIicBusChannelMasterI2c::CheckHdr(TDes8* aHdr)
   1.261 +	{
   1.262 +	I2C_PRINT(("DSimulatedIicBusChannelMasterI2c::CheckHdr\n"));
   1.263 +
   1.264 +	TConfigI2cBufV01* i2cBuf = (TConfigI2cBufV01*)aHdr;
   1.265 +	TConfigI2cV01* i2cPtr = &((*i2cBuf)());
   1.266 +
   1.267 +	// Check that the values for address type, clock speed, user operation and endianness are recognised
   1.268 +	if((i2cPtr->iAddrType < 0) || (i2cPtr->iAddrType > EI2cAddr10Bit))
   1.269 +		{
   1.270 +		I2C_PRINT(("ERROR: DSimulatedIicBusChannelMasterI2c::CheckHdr unrecognised address type identifier %d\n",i2cPtr->iAddrType));
   1.271 +		return KErrArgument;
   1.272 +		}
   1.273 +	if(i2cPtr->iClkSpeedHz < 0)
   1.274 +		{
   1.275 +		I2C_PRINT(("ERROR: DSimulatedIicBusChannelMasterI2c::CheckHdr negative clock speed specified %d\n",i2cPtr->iClkSpeedHz));
   1.276 +		return KErrArgument;
   1.277 +		}
   1.278 +	if((i2cPtr->iEndianness < 0) || (i2cPtr->iEndianness > ELittleEndian))
   1.279 +		{
   1.280 +		I2C_PRINT(("ERROR: DSimulatedIicBusChannelMasterI2c::CheckHdr unrecognised endianness identifier %d\n",i2cPtr->iEndianness));
   1.281 +		return KErrArgument;
   1.282 +		}
   1.283 +	// Values for the timeout period are arbitrary - can only check it is not a negative value
   1.284 +	if(i2cPtr->iTimeoutPeriod < 0)
   1.285 +		{
   1.286 +		I2C_PRINT(("ERROR: DSimulatedIicBusChannelMasterI2c::CheckHdr negative timeout period %d\n",i2cPtr->iTimeoutPeriod));
   1.287 +		return KErrArgument;
   1.288 +		}
   1.289 +	I2C_PRINT(("DSimulatedIicBusChannelMasterI2c::CheckHdr address type = %d\n",i2cPtr->iAddrType));
   1.290 +	I2C_PRINT(("DSimulatedIicBusChannelMasterI2c::CheckHdr clock speed ID = %d\n",i2cPtr->iClkSpeedHz));
   1.291 +	I2C_PRINT(("DSimulatedIicBusChannelMasterI2c::CheckHdr iEndianness ID = %d\n",i2cPtr->iEndianness));
   1.292 +	I2C_PRINT(("DSimulatedIicBusChannelMasterI2c::CheckHdr iTimeoutPeriod = %d\n",i2cPtr->iTimeoutPeriod));
   1.293 +	return KErrNone;
   1.294 +	}
   1.295 +
   1.296 +	// Gateway function for PSL implementation, invoked for DFC processing
   1.297 +TInt DSimulatedIicBusChannelMasterI2c::DoRequest(TIicBusTransaction* aTransaction)
   1.298 +	{
   1.299 +	I2C_PRINT(("DSimulatedIicBusChannelMasterI2c::DoRequest invoked with aTransaction=0x%x\n",aTransaction));
   1.300 +	TInt r = KErrNone;
   1.301 +
   1.302 +#ifdef IIC_INSTRUMENTATION_MACRO
   1.303 +	IIC_MPROCESSTRANS_START_PSL_TRACE;
   1.304 +#endif
   1.305 +
   1.306 +	I2C_PRINT(("DSimulatedIicBusChannelMasterI2c::ProcessTrans aTransaction->iHeader=0x%x\n",GetTransactionHeader(aTransaction)));
   1.307 +	I2C_PRINT(("DSimulatedIicBusChannelMasterI2c::ProcessTrans aTransaction->iHalfDuplexTrans=0x%x\n",GetTransHalfDuplexTferPtr(aTransaction)));
   1.308 +	I2C_PRINT(("DSimulatedIicBusChannelMasterI2c::ProcessTrans aTransaction->iFullDuplexTrans=0x%x\n",GetTransFullDuplexTferPtr(aTransaction)));
   1.309 +	I2C_PRINT(("DSimulatedIicBusChannelMasterI2c::ProcessTrans aTransaction->iCallback=0x%x\n",GetTransCallback(aTransaction)));
   1.310 +	I2C_PRINT(("DSimulatedIicBusChannelMasterI2c::ProcessTrans aTransaction->iFlags=0x%x\n",GetTransFlags(aTransaction)));
   1.311 +
   1.312 +	I2C_PRINT(("\nDSimulatedIicBusChannelMasterI2c::DoRequest, iHeader info \n"));
   1.313 +	TDes8* bufPtr = GetTransactionHeader(aTransaction);
   1.314 +	if(bufPtr == NULL)
   1.315 +		{
   1.316 +		I2C_PRINT(("DSimulatedIicBusChannelMasterI2c::DoRequest ERROR - NULL header\n"));
   1.317 +		return KErrCorrupt;
   1.318 +		}
   1.319 +	TConfigI2cV01 *buf = (TConfigI2cV01 *)(bufPtr->Ptr());
   1.320 +	I2C_PRINT(("DSimulatedIicBusChannelMasterI2c::DoRequest, header address type=0x%x\n",buf->iAddrType));
   1.321 +	I2C_PRINT(("DSimulatedIicBusChannelMasterI2c::DoRequest, header clock speed=0x%x\n",buf->iClkSpeedHz));
   1.322 +	I2C_PRINT(("DSimulatedIicBusChannelMasterI2c::DoRequest, header endianness=0x%x\n",buf->iEndianness));
   1.323 +	I2C_PRINT(("DSimulatedIicBusChannelMasterI2c::DoRequest, header timeout period=0x%x\n",buf->iTimeoutPeriod));
   1.324 +	(void)buf;	// Silence compiler when I2C_PRINT not used
   1.325 +
   1.326 +	TInt aTime=1000000/NKern::TickPeriod();
   1.327 +	r = StartSlaveTimeOutTimer(aTime);
   1.328 +	I2C_PRINT(("\nDSimulatedIicBusChannelMasterI2c::ProcessTrans, iHalfDuplexTrans info \n"));
   1.329 +	TIicBusTransfer* halfDuplexPtr=GetTransHalfDuplexTferPtr(aTransaction);
   1.330 +	while(halfDuplexPtr != NULL)
   1.331 +		{
   1.332 +		I2C_PRINT(("DSimulatedIicBusChannelMasterI2c::ProcessTrans transfer type=0x%x\n",GetTferType(halfDuplexPtr)));
   1.333 +		I2C_PRINT(("DSimulatedIicBusChannelMasterI2c::ProcessTrans granularity=0x%x\n",GetTferBufGranularity(halfDuplexPtr)));
   1.334 +		I2C_PRINT(("DSimulatedIicBusChannelMasterI2c::ProcessTrans transfer buffer=0x%x\n",GetTferBuffer(halfDuplexPtr)));
   1.335 +		I2C_PRINT(("DSimulatedIicBusChannelMasterI2c::ProcessTrans next transfer =0x%x\n",GetTferNextTfer(halfDuplexPtr)));
   1.336 +		halfDuplexPtr=GetTferNextTfer(halfDuplexPtr);
   1.337 +		}
   1.338 +	I2C_PRINT(("DSimulatedIicBusChannelMasterI2c::ProcessTrans - End of iHalfDuplexTrans info"));
   1.339 +
   1.340 +	while(IsRequestDelayed(this))
   1.341 +		{
   1.342 +		I2C_PRINT(("DSimulatedIicBusChannelMasterI2c::ProcessTrans - starting Sleep...\n"));
   1.343 +		NKern::Sleep(1000);	// 1000 is arbitrary
   1.344 +		I2C_PRINT(("DSimulatedIicBusChannelMasterI2c::ProcessTrans - completed Sleep, check if still delayed\n"));
   1.345 +		}; 
   1.346 +
   1.347 +	I2C_PRINT(("DSimulatedIicBusChannelMasterI2c::ProcessTrans - exiting\n"));
   1.348 +
   1.349 +	return r;
   1.350 +	}
   1.351 +
   1.352 +
   1.353 +TBool DSimulatedIicBusChannelMasterI2c::IsRequestDelayed(DSimulatedIicBusChannelMasterI2c* aChan)
   1.354 +	{
   1.355 +	I2C_PRINT(("DSimulatedIicBusChannelMasterI2c::IsRequestDelayed invoked for aChan=0x%x\n",aChan));
   1.356 +	return aChan->iReqDelayed;
   1.357 +	}
   1.358 +
   1.359 +void DSimulatedIicBusChannelMasterI2c::SetRequestDelayed(DSimulatedIicBusChannelMasterI2c* aChan,TBool aDelay) 
   1.360 +	{
   1.361 +	I2C_PRINT(("DSimulatedIicBusChannelMasterI2c::SetRequestDelayed invoked for aChan=0x%x, with aDelay=0x%d\n",aChan,aDelay));
   1.362 +	aChan->iReqDelayed=aDelay;
   1.363 +	}
   1.364 +
   1.365 +TInt DSimulatedIicBusChannelMasterI2c::HandleSlaveTimeout()
   1.366 +	{
   1.367 +	I2C_PRINT(("DSimulatedIicBusChannelMasterI2c::HandleSlaveTimeout invoked for this=0x%x\n",this));
   1.368 +	return KErrTimedOut;
   1.369 +	}
   1.370 +
   1.371 +TInt DSimulatedIicBusChannelMasterI2c::StaticExtension(TUint aFunction, TAny* aParam1, TAny* aParam2)
   1.372 +	{
   1.373 +	I2C_PRINT(("DSimulatedIicBusChannelMasterI2c::StaticExtension\n"));
   1.374 +	TInt r = KErrNone;
   1.375 +#ifdef IIC_INSTRUMENTATION_MACRO
   1.376 +	IIC_MSTATEXT_START_PSL_TRACE;
   1.377 +#endif
   1.378 +	(void)aParam1;
   1.379 +	(void)aParam2;
   1.380 +	
   1.381 +	// Test values of aFunction were shifted left one place by the (test) client driver
   1.382 +	// Return to its original value.
   1.383 +	if(aFunction>KTestControlIoPilOffset)
   1.384 +		aFunction >>= 1;
   1.385 +	switch(aFunction)
   1.386 +		{
   1.387 +		case(RBusDevIicClient::ECtlIoDumpChan):
   1.388 +			{
   1.389 +#ifdef _DEBUG
   1.390 +			DumpChannel();
   1.391 +#endif
   1.392 +			break;
   1.393 +			}
   1.394 +		case(RBusDevIicClient::ECtlIoBlockReqCompletion):
   1.395 +			{
   1.396 +			I2C_PRINT(("DSimulatedIicBusChannelMasterI2c::Blocking request completion\n"));
   1.397 +			SetRequestDelayed(this, ETrue);
   1.398 +			break;
   1.399 +			}
   1.400 +		case(RBusDevIicClient::ECtlIoUnblockReqCompletion):
   1.401 +			{
   1.402 +			I2C_PRINT(("DSimulatedIicBusChannelMasterI2c::Unlocking request completion\n"));
   1.403 +			SetRequestDelayed(this, EFalse);
   1.404 +			break;
   1.405 +			}
   1.406 +		case(RBusDevIicClient::ECtlIoDeRegChan):
   1.407 +			{
   1.408 +#ifndef STANDALONE_CHANNEL
   1.409 +#ifdef IIC_INSTRUMENTATION_MACRO
   1.410 +	IIC_DEREGISTERCHAN_START_PSL_TRACE;
   1.411 +#endif
   1.412 +			I2C_PRINT(("DSimulatedIicBusChannelMasterI2c: deregister channel\n"));
   1.413 +			r=DIicBusController::DeRegisterChannel(this);
   1.414 +
   1.415 +#ifdef IIC_INSTRUMENTATION_MACRO
   1.416 +	IIC_DEREGISTERCHAN_END_PSL_TRACE;
   1.417 +#endif/*IIC_INSTRUMENTATION_MACRO*/
   1.418 +	
   1.419 +#else/*STANDALONE_CHANNEL*/
   1.420 +			r = KErrNotSupported;
   1.421 +#endif/*STANDALONE_CHANNEL*/
   1.422 +			break;
   1.423 +			}
   1.424 +		default:
   1.425 +			{
   1.426 +			Kern::Printf("aFunction %d is not recognised \n",aFunction);
   1.427 +			r=KErrNotSupported;
   1.428 +			}
   1.429 +		}
   1.430 +		
   1.431 +#ifdef IIC_INSTRUMENTATION_MACRO
   1.432 +	IIC_MSTATEXT_END_PSL_TRACE;
   1.433 +#endif		
   1.434 +	return r;
   1.435 +	}
   1.436 +
   1.437 +//#ifdef MASTER_MODE
   1.438 +#endif
   1.439 +
   1.440 +#ifdef SLAVE_MODE
   1.441 +
   1.442 +void DSimulatedIicBusChannelSlaveI2c::SlaveAsyncSimCallback(TAny* aPtr)
   1.443 +	{
   1.444 +	// To support simulating an asynchronous capture operation
   1.445 +	// NOTE: this will be invoked in the context of DfcThread1
   1.446 +	I2C_PRINT(("SlaveAsyncSimCallback\n"));
   1.447 +	DSimulatedIicBusChannelSlaveI2c* channel = (DSimulatedIicBusChannelSlaveI2c*)aPtr;
   1.448 +	TInt r=KErrNone;// Just simulate successful capture
   1.449 +#ifdef IIC_INSTRUMENTATION_MACRO
   1.450 +	IIC_SCAPTCHANASYNC_END_PSL_TRACE;
   1.451 +#endif
   1.452 +	channel->ChanCaptureCb(r);
   1.453 +	}
   1.454 +
   1.455 +#ifdef STANDALONE_CHANNEL
   1.456 +EXPORT_C
   1.457 +#endif
   1.458 +DSimulatedIicBusChannelSlaveI2c::DSimulatedIicBusChannelSlaveI2c(const DIicBusChannel::TBusType aBusType, const DIicBusChannel::TChannelDuplex aChanDuplex)
   1.459 +	: DIicBusChannelSlave(aBusType,aChanDuplex,0), // 0 to be ignored by base class
   1.460 +	iBlockedTrigger(0),iBlockNotification(EFalse),
   1.461 +	iSlaveTimer(DSimulatedIicBusChannelSlaveI2c::SlaveAsyncSimCallback,this)
   1.462 +	{
   1.463 +	I2C_PRINT(("DSimulatedIicBusChannelSlaveI2c::DSimulatedIicBusChannelSlaveI2c, aBusType=%d,aChanDuplex=%d\n",aBusType,aChanDuplex));
   1.464 +#ifndef STANDALONE_CHANNEL
   1.465 +	iChannelNumber = AssignChanNum();
   1.466 +#endif
   1.467 +	iChannelId = AssignSlaveChanId();
   1.468 +	I2C_PRINT(("DSimulatedIicBusChannelSlaveI2c::DSimulatedIicBusChannelSlaveI2c, iChannelNumber=%d, iChannelId=0x%x\n",iChannelNumber,iChannelId));
   1.469 +	}
   1.470 +
   1.471 +DSimulatedIicBusChannelSlaveI2c::~DSimulatedIicBusChannelSlaveI2c()
   1.472 +	{
   1.473 +	I2C_PRINT(("DSimulatedIicBusChannelSlaveI2c::~DSimulatedIicBusChannelSlaveI2c\n"));
   1.474 +	}
   1.475 +
   1.476 +TInt DSimulatedIicBusChannelSlaveI2c::DoCreate()
   1.477 +	{
   1.478 +	I2C_PRINT(("DSimulatedIicBusChannelSlaveI2c::DoCreate\n"));
   1.479 +	TInt r=Init();	// PIL Base class initialisation
   1.480 +	return r;
   1.481 +	}
   1.482 +
   1.483 +
   1.484 +TInt DSimulatedIicBusChannelSlaveI2c::CaptureChannelPsl(TBool aAsynch)
   1.485 +	{
   1.486 +	I2C_PRINT(("DSimulatedIicBusChannelSlaveI2c::CaptureChannelPsl\n"));
   1.487 +	TInt r = KErrNone;
   1.488 +	if(aAsynch)
   1.489 +		{
   1.490 +#ifdef IIC_INSTRUMENTATION_MACRO
   1.491 +	IIC_SCAPTCHANASYNC_START_PSL_TRACE;
   1.492 +#endif
   1.493 +		// To simulate an asynchronous capture operation, just set a timer to expire
   1.494 +		iSlaveTimer.OneShot(1000, ETrue); // Arbitrary timeout - expiry executes callback in context of DfcThread1
   1.495 +		}
   1.496 +	else
   1.497 +		{
   1.498 +#ifdef IIC_INSTRUMENTATION_MACRO
   1.499 +	IIC_SCAPTCHANSYNC_START_PSL_TRACE;
   1.500 +#endif
   1.501 +		// PSL processing would happen here ...
   1.502 +		// Expected to include implementation of the header configuration information 
   1.503 +
   1.504 +		I2C_PRINT(("DSimulatedIicBusChannelSlaveI2c::CaptureChannelPsl (synchronous) ... no real processing to do \n"));
   1.505 +
   1.506 +#ifdef IIC_INSTRUMENTATION_MACRO
   1.507 +	IIC_SCAPTCHANSYNC_END_PSL_TRACE;
   1.508 +#endif
   1.509 +		}
   1.510 +
   1.511 +	return r;
   1.512 +	}
   1.513 +
   1.514 +TInt DSimulatedIicBusChannelSlaveI2c::ReleaseChannelPsl()
   1.515 +	{
   1.516 +	I2C_PRINT(("DSimulatedIicBusChannelSlaveI2c::ReleaseChannelPsl\n"));
   1.517 +#ifdef IIC_INSTRUMENTATION_MACRO
   1.518 +	IIC_SRELCHAN_START_PSL_TRACE;
   1.519 +#endif
   1.520 +	TInt r = KErrNone;
   1.521 +
   1.522 +	// PSL-specific processing would happen here ...
   1.523 +	I2C_PRINT(("DSimulatedIicBusChannelSlaveI2c::ReleaseChannelPsl ... no real processing to do \n"));
   1.524 +
   1.525 +#ifdef IIC_INSTRUMENTATION_MACRO
   1.526 +	IIC_SRELCHAN_END_PSL_TRACE;
   1.527 +#endif
   1.528 +
   1.529 +	return r;
   1.530 +	}
   1.531 +
   1.532 +
   1.533 +TInt DSimulatedIicBusChannelSlaveI2c::PrepareTrigger(TInt aTrigger)
   1.534 +	{
   1.535 +	I2C_PRINT(("DSimulatedIicBusChannelSlaveI2c::PrepareTrigger\n"));
   1.536 +#ifdef IIC_INSTRUMENTATION_MACRO
   1.537 +//	IIC_SNOTIFTRIG_START_PSL;
   1.538 +#endif
   1.539 +	TInt r=KErrNotSupported;
   1.540 +	if(aTrigger&EReceive)
   1.541 +		{
   1.542 +		I2C_PRINT(("DSimulatedIicBusChannelSlaveI2c::PrepareTrigger - prepare hardware for Rx\n"));
   1.543 +		r=KErrNone;
   1.544 +		}
   1.545 +	if(aTrigger&ETransmit)
   1.546 +		{
   1.547 +		I2C_PRINT(("DSimulatedIicBusChannelSlaveI2c::PrepareTrigger - prepare hardware for Tx\n"));
   1.548 +		r=KErrNone;
   1.549 +		}
   1.550 +	// Check for any additional triggers and make the necessary preparation
   1.551 +	// ... do nothing in simulated PSL
   1.552 +	r=KErrNone;
   1.553 +
   1.554 +#ifdef IIC_INSTRUMENTATION_MACRO
   1.555 +//	IIC_SNOTIFTRIG_END_PSL;
   1.556 +#endif
   1.557 +	return r;
   1.558 +	}
   1.559 +
   1.560 +TInt DSimulatedIicBusChannelSlaveI2c::CheckHdr(TDes8* /*aHdr*/)
   1.561 +	{
   1.562 +	I2C_PRINT(("DSimulatedIicBusChannelSlaveI2c::CheckHdr\n"));
   1.563 +	return KErrNone;
   1.564 +	}
   1.565 +
   1.566 +TInt DSimulatedIicBusChannelSlaveI2c::DoRequest(TInt aOperation)
   1.567 +	{
   1.568 +	I2C_PRINT(("DSimulatedIicBusChannelSlaveI2c::DoRequest\n"));
   1.569 +	TInt r = KErrNone;
   1.570 +
   1.571 +	switch(aOperation)
   1.572 +		{
   1.573 +		case(ESyncConfigPwrUp):
   1.574 +			{
   1.575 +			r=CaptureChannelPsl(EFalse);
   1.576 +			break;
   1.577 +			};
   1.578 +		case(EAsyncConfigPwrUp):
   1.579 +			{
   1.580 +			r=CaptureChannelPsl(ETrue);
   1.581 +			break;
   1.582 +			};
   1.583 +		case(EPowerDown):
   1.584 +			{
   1.585 +			r=ReleaseChannelPsl();
   1.586 +			break;
   1.587 +			};
   1.588 +		case(EAbort):
   1.589 +			{
   1.590 +			break;
   1.591 +			};
   1.592 +		default:
   1.593 +			{
   1.594 +			// The remaining operations are to instigate an Rx, Tx or just prepare for
   1.595 +			// overrun/underrun/bus error notifications.
   1.596 +			// Handle all these, and any unsupported operation in the following function
   1.597 +			r=PrepareTrigger(aOperation);
   1.598 +			break;
   1.599 +			};
   1.600 +		}
   1.601 +	return r;
   1.602 +	}
   1.603 +
   1.604 +void DSimulatedIicBusChannelSlaveI2c::ProcessData(TInt aTrigger, TIicBusSlaveCallback*  aCb)
   1.605 +	{
   1.606 +	I2C_PRINT(("DSimulatedIicBusChannelSlaveI2c::ProcessData\n"));
   1.607 +	// fills in iReturn, iRxWords and/or iTxWords
   1.608 +	//
   1.609 +	if(aTrigger & ERxAllBytes)
   1.610 +		{
   1.611 +		aCb->SetRxWords(iNumWordsWereRx);
   1.612 +		if(iRxTxUnderOverRun & ERxUnderrun)
   1.613 +			{
   1.614 +			aTrigger|=ERxUnderrun;
   1.615 +			iRxTxUnderOverRun&= ~ERxUnderrun;
   1.616 +			}
   1.617 +		if(iRxTxUnderOverRun & ERxOverrun)
   1.618 +			{
   1.619 +			aTrigger|=ERxOverrun;
   1.620 +			iRxTxUnderOverRun&= ~ERxOverrun;
   1.621 +			}
   1.622 +		}
   1.623 +	if(aTrigger & ETxAllBytes)
   1.624 +		{
   1.625 +		aCb->SetTxWords(iNumWordsWereTx);
   1.626 +		if(iRxTxUnderOverRun & ETxUnderrun)
   1.627 +			{
   1.628 +			aTrigger|=ETxUnderrun;
   1.629 +			iRxTxUnderOverRun&= ~ETxUnderrun;
   1.630 +			}
   1.631 +		if(iRxTxUnderOverRun & ETxOverrun)
   1.632 +			{
   1.633 +			aTrigger|=ETxOverrun;
   1.634 +			iRxTxUnderOverRun&= ~ETxOverrun;
   1.635 +			}
   1.636 +		}
   1.637 +
   1.638 +	aCb->SetTrigger(aTrigger);
   1.639 +	}
   1.640 +
   1.641 +TInt DSimulatedIicBusChannelSlaveI2c::StaticExtension(TUint aFunction, TAny* aParam1, TAny* aParam2)
   1.642 +	{
   1.643 +	I2C_PRINT(("DSimulatedIicBusChannelSlaveI2c::StaticExtension\n"));
   1.644 +#ifdef IIC_INSTRUMENTATION_MACRO
   1.645 +	IIC_SSTATEXT_START_PSL_TRACE;
   1.646 +#endif
   1.647 +	// Test values of aFunction were shifted left one place by the (test) client driver
   1.648 +	// and for Slave values the two msb were cleared
   1.649 +	// Return to its original value.
   1.650 +	if(aFunction>KTestControlIoPilOffset)
   1.651 +		{
   1.652 +		aFunction |= 0xC0000000;
   1.653 +		aFunction >>= 1;
   1.654 +		}
   1.655 +	TInt r = KErrNone;
   1.656 +	switch(aFunction)
   1.657 +		{
   1.658 +		case(RBusDevIicClient::ECtlIoDumpChan):
   1.659 +			{
   1.660 +#ifdef _DEBUG
   1.661 +			DumpChannel();
   1.662 +#endif
   1.663 +			break;
   1.664 +			}
   1.665 +		case(RBusDevIicClient::ECtlIoDeRegChan):
   1.666 +			{
   1.667 +#ifndef STANDALONE_CHANNEL
   1.668 +			I2C_PRINT(("DSimulatedIicBusChannelSlaveI2c: deregister channel\n"));
   1.669 +			// DIicBusController::DeRegisterChannel just removes the channel from the array of channels available 
   1.670 +			r=DIicBusController::DeRegisterChannel(this);
   1.671 +#else
   1.672 +			r = KErrNotSupported;
   1.673 +#endif
   1.674 +			break;
   1.675 +			}
   1.676 +
   1.677 +		case(RBusDevIicClient::ECtrlIoRxWords):
   1.678 +			{
   1.679 +			// Simulate receipt of a number of bytes
   1.680 +			// aParam1 represents the ChannelId
   1.681 +			// aParam2 specifies the number of bytes
   1.682 +			I2C_PRINT(("DSimulatedIicBusChannelSlaveI2c: ECtrlIoRxWords, channelId=0x%x, numBytes=0x%x\n",aParam1,aParam2));
   1.683 +
   1.684 +			// Load the buffer with simulated data
   1.685 +			if(iRxBuf == NULL)
   1.686 +				{
   1.687 +				I2C_PRINT(("DSimulatedIicBusChannelSlaveI2c: ECtrlIoRxWords, ERROR, iRxBuf == NULL\n"));
   1.688 +				r=KErrGeneral;
   1.689 +				break;
   1.690 +				}
   1.691 +			// Check for overrun-underrun conditions
   1.692 +			TInt trigger=ERxAllBytes;
   1.693 +			iNumWordsWereRx=(TInt8)((TInt)aParam2);
   1.694 +			iDeltaWordsToRx = (TInt8)(iNumWordsWereRx - iNumRxWords);
   1.695 +			if(iDeltaWordsToRx>0)
   1.696 +				{
   1.697 +				iNumWordsWereRx=iNumRxWords;
   1.698 +				iRxTxUnderOverRun |= ERxOverrun;
   1.699 +				}
   1.700 +			if(iDeltaWordsToRx<0)
   1.701 +				iRxTxUnderOverRun |= ERxUnderrun;
   1.702 +
   1.703 +			TInt8* ptr=(TInt8*)(iRxBuf+iRxOffset);
   1.704 +			TInt8 startVal=0x10;
   1.705 +			for(TInt8 numWords=0; numWords<iNumWordsWereRx; numWords++,startVal++)
   1.706 +				{
   1.707 +				for(TInt wordByte=0; wordByte<iRxGranularity; wordByte++,ptr++)
   1.708 +					{
   1.709 +					*ptr=startVal;
   1.710 +					}
   1.711 +				}
   1.712 +			if(iBlockNotification == EFalse)
   1.713 +				{
   1.714 +				//
   1.715 +				// Invoke DIicBusChannelSlave::NotifyClient - this will invoke ProcessData and invoke the client callback
   1.716 +				NotifyClient(trigger);
   1.717 +				}
   1.718 +			else
   1.719 +				{
   1.720 +				// Save the trigger value to notify when prompted.
   1.721 +				iBlockedTrigger=trigger;
   1.722 +				}
   1.723 +			break;
   1.724 +
   1.725 +			}
   1.726 +
   1.727 +		case(RBusDevIicClient::ECtrlIoUnblockNotification):
   1.728 +			{
   1.729 +			iBlockNotification=EFalse;
   1.730 +			NotifyClient(iBlockedTrigger);
   1.731 +			iBlockedTrigger=0;
   1.732 +			break;
   1.733 +			}
   1.734 +
   1.735 +		case(RBusDevIicClient::ECtrlIoBlockNotification):
   1.736 +			{
   1.737 +			iBlockNotification=ETrue;
   1.738 +			break;
   1.739 +			}
   1.740 +
   1.741 +		case(RBusDevIicClient::ECtrlIoTxWords):
   1.742 +			{
   1.743 +			I2C_PRINT(("DSimulatedIicBusChannelSlaveI2c: ECtrlIoTxWords, aParam1=0x%x, aParam2=0x%x\n",aParam1,aParam2));
   1.744 +			// Simulate transmission of a number of bytes
   1.745 +			// aParam1 represents the ChannelId
   1.746 +			// aParam2 specifies the number of bytes
   1.747 +			// Load the buffer with simulated data
   1.748 +			if(iTxBuf == NULL)
   1.749 +				{
   1.750 +				I2C_PRINT(("DSimulatedIicBusChannelSlaveI2c: ECtrlIoTxWords, ERROR, iTxBuf==NULL\n"));
   1.751 +				r=KErrGeneral;
   1.752 +				break;
   1.753 +				}
   1.754 +			// Check for overrun-underrun conditions
   1.755 +			TInt trigger=ETxAllBytes;
   1.756 +			iNumWordsWereTx=(TInt8)((TInt)aParam2);
   1.757 +			iDeltaWordsToTx = (TInt8)(iNumWordsWereTx - iNumTxWords);
   1.758 +			if(iDeltaWordsToTx>0)
   1.759 +				{
   1.760 +				iNumWordsWereTx=iNumTxWords;
   1.761 +				iRxTxUnderOverRun |= ETxUnderrun;
   1.762 +				}
   1.763 +			if(iDeltaWordsToTx<0)
   1.764 +				iRxTxUnderOverRun |= ETxOverrun;
   1.765 +
   1.766 +			// Initialise the check buffer
   1.767 +			if(iTxCheckBuf!=NULL)
   1.768 +				delete iTxCheckBuf;
   1.769 +			// iTxCheckBuf is a member of class DSimulatedIicBusChannelSlaveI2c, which 
   1.770 +			// is created here, and deleted not in ~DSimulatedIicBusChannelSlaveI2c()
   1.771 +			// but from client side. This is because in t_iic, 
   1.772 +			// we put a memory leak checking macro __KHEAP_MARKEND before
   1.773 +			// the pdd gets unloaded which will call ~DSimulatedIicBusChannelSlaveI2c().  
   1.774 +			// If we delete iTxCheckBuf in ~DSimulatedIicBusChannelSlaveI2c(),
   1.775 +			// we will get a memory leak panic in __KHEAP_MARKEND.
   1.776 +			// To support the test code, we moved iTxCheckBuf deletion to the client side. 
   1.777 +			iTxCheckBuf = new TInt8[iNumTxWords*iTxGranularity];
   1.778 +			memset(iTxCheckBuf,0,(iNumTxWords*iTxGranularity));
   1.779 +
   1.780 +			TInt8* srcPtr=(TInt8*)(iTxBuf+iTxOffset);
   1.781 +			TInt8* dstPtr=iTxCheckBuf;
   1.782 +			for(TInt8 numWords=0; numWords<iNumWordsWereTx; numWords++)
   1.783 +				{
   1.784 +				for(TInt wordByte=0; wordByte<iTxGranularity; wordByte++)
   1.785 +					*dstPtr++=*srcPtr++;
   1.786 +				}
   1.787 +			if(iBlockNotification == EFalse)
   1.788 +				{
   1.789 +				//
   1.790 +				// Invoke DIicBusChannelSlave::NotifyClient - this will invoke ProcessData and invoke the client callback
   1.791 +				NotifyClient(trigger);
   1.792 +				}
   1.793 +			else
   1.794 +				{
   1.795 +				// Save the trigger value to notify when prompted.
   1.796 +				iBlockedTrigger=trigger;
   1.797 +				}
   1.798 +			break;
   1.799 +			}
   1.800 +
   1.801 +		case(RBusDevIicClient::ECtrlIoRxTxWords):
   1.802 +			{
   1.803 +			I2C_PRINT(("DSimulatedIicBusChannelSlaveI2c: ECtrlIoRxTxWords, aParam1=0x%x, aParam2=0x%x\n",aParam1,aParam2));
   1.804 +			// Simulate transmission of a number of bytes
   1.805 +			// aParam1 represents the ChannelId
   1.806 +			// aParam2 represents a pointer to the two numbers of bytes
   1.807 +			// Check the buffers are available
   1.808 +			if(iTxBuf == NULL)
   1.809 +				{
   1.810 +				I2C_PRINT(("DSimulatedIicBusChannelSlaveI2c: ECtrlIoRxTxWords, ERROR, iTxBuf==NULL\n"));
   1.811 +				r=KErrGeneral;
   1.812 +				break;
   1.813 +				}
   1.814 +			if(iRxBuf == NULL)
   1.815 +				{
   1.816 +				I2C_PRINT(("DSimulatedIicBusChannelSlaveI2c: ECtrlIoRxTxWords, ERROR, iRxBuf==NULL\n"));
   1.817 +				r=KErrGeneral;
   1.818 +				break;
   1.819 +				}
   1.820 +			// Check for overrun-underrun conditions
   1.821 +			TInt trigger=ETxAllBytes|ERxAllBytes;
   1.822 +			iNumWordsWereRx=(TInt8)(*(TInt*)aParam2);
   1.823 +			TInt* tempPtr=((TInt*)(aParam2));
   1.824 +			iNumWordsWereTx=(TInt8)(*(++tempPtr));
   1.825 +
   1.826 +			iDeltaWordsToTx = (TInt8)(iNumWordsWereTx - iNumTxWords);
   1.827 +			if(iDeltaWordsToTx>0)
   1.828 +				{
   1.829 +				iNumWordsWereTx=iNumTxWords;
   1.830 +				iRxTxUnderOverRun |= ETxUnderrun;
   1.831 +				}
   1.832 +			if(iDeltaWordsToTx<0)
   1.833 +				iRxTxUnderOverRun |= ETxOverrun;
   1.834 +
   1.835 +
   1.836 +			iDeltaWordsToRx = (TInt8)(iNumWordsWereRx - iNumRxWords);
   1.837 +			if(iDeltaWordsToRx>0)
   1.838 +				{
   1.839 +				iNumWordsWereRx=iNumRxWords;
   1.840 +				iRxTxUnderOverRun |= ERxOverrun;
   1.841 +				}
   1.842 +			if(iDeltaWordsToRx<0)
   1.843 +				iRxTxUnderOverRun |= ERxUnderrun;
   1.844 +
   1.845 +
   1.846 +			// Initialise the buffers
   1.847 +			if(iTxCheckBuf!=NULL)
   1.848 +				delete iTxCheckBuf;
   1.849 +			iTxCheckBuf = new TInt8[iNumTxWords*iTxGranularity];
   1.850 +			memset(iTxCheckBuf,0,(iNumTxWords*iTxGranularity));
   1.851 +
   1.852 +			TInt8* srcPtr=(TInt8*)(iTxBuf+iTxOffset);
   1.853 +			TInt8* dstPtr=iTxCheckBuf;
   1.854 +			TInt8 numWords=0;
   1.855 +			for(numWords=0; numWords<iNumWordsWereTx; numWords++)
   1.856 +				{
   1.857 +				for(TInt wordByte=0; wordByte<iTxGranularity; wordByte++)
   1.858 +					*dstPtr++=*srcPtr++;
   1.859 +				}
   1.860 +
   1.861 +			TInt8* ptr=(TInt8*)(iRxBuf+iRxOffset);
   1.862 +			TInt8 startVal=0x10;
   1.863 +			for(numWords=0; numWords<iNumWordsWereRx; numWords++,startVal++)
   1.864 +				{
   1.865 +				for(TInt wordByte=0; wordByte<iRxGranularity; wordByte++,ptr++)
   1.866 +					{
   1.867 +					*ptr=startVal;
   1.868 +					}
   1.869 +				}		
   1.870 +			
   1.871 +			if(iBlockNotification == EFalse)
   1.872 +				{
   1.873 +				//
   1.874 +				// Invoke DIicBusChannelSlave::NotifyClient - this will invoke ProcessData and invoke the client callback
   1.875 +				NotifyClient(trigger);
   1.876 +				}
   1.877 +			else
   1.878 +				{
   1.879 +				// Save the trigger value to notify when prompted.
   1.880 +				iBlockedTrigger=trigger;
   1.881 +				}
   1.882 +			break;
   1.883 +			}
   1.884 +
   1.885 +		case(RBusDevIicClient::ECtrlIoTxChkBuf):
   1.886 +			{
   1.887 +			I2C_PRINT(("DSimulatedIicBusChannelSlaveI2c: ECtrlIoTxChkBuf, aParam1=0x%x, aParam2=0x%x\n",aParam1,aParam2));
   1.888 +			// Return the address of iTxCheckBuf to the address pointed to by a1
   1.889 +			// Both the simulated bus channel and the slave client are resident in the client process
   1.890 +			// so the client can use the pointer value for direct access
   1.891 +			TInt8** ptr = (TInt8**)aParam1;
   1.892 +			*ptr=iTxCheckBuf;
   1.893 +			break;
   1.894 +			}
   1.895 +
   1.896 +		case(RBusDevIicClient::ECtlIoBusError):
   1.897 +			{
   1.898 +			I2C_PRINT(("DSimulatedIicBusChannelSlaveI2c: ECtlIoBusError\n"));
   1.899 +			NotifyClient(EGeneralBusError);
   1.900 +			break;
   1.901 +			}
   1.902 +
   1.903 +		case(RBusDevIicClient::ECtrlIoUpdTimeout):
   1.904 +			{
   1.905 +			// For this test, do the following for the Master and Client timeout values:
   1.906 +			// (1) Read the current timeout value and check that it is set to the default
   1.907 +			// (2) Check setting to a neagtive value fails
   1.908 +			// (3) Set it to a new, different value
   1.909 +			// (4) Read it back to check success
   1.910 +			// (5) Return to the original value, and readback to confirm
   1.911 +			I2C_PRINT(("DSimulatedIicBusChannelSlaveI2c ECtrlIoUpdTimeout \n"));
   1.912 +
   1.913 +			TInt timeout = 0;
   1.914 +			TInt r=KErrNone;
   1.915 +			// Master timeout
   1.916 +			timeout=GetMasterWaitTime();
   1.917 +			if(timeout!=KSlaveDefMWaitTime)
   1.918 +				{
   1.919 +				I2C_PRINT(("ERROR: Initial Master Wait time != KSlaveDefMWaitTime (=%d) \n",timeout));
   1.920 +				return KErrGeneral;
   1.921 +				}
   1.922 +			r=SetMasterWaitTime(-1);
   1.923 +			if(r!=KErrArgument)
   1.924 +				{
   1.925 +				I2C_PRINT(("ERROR: Attempt to set negative Master wait time not rejected\n"));
   1.926 +				return KErrGeneral;
   1.927 +				}
   1.928 +			r=SetMasterWaitTime(KSlaveDefCWaitTime);
   1.929 +			if(r!=KErrNone)
   1.930 +				{
   1.931 +				I2C_PRINT(("ERROR: Attempt to set new valid Master wait time (%d) rejected\n",KSlaveDefCWaitTime));
   1.932 +				return KErrGeneral;
   1.933 +				}
   1.934 +			timeout=GetMasterWaitTime();
   1.935 +			if(timeout!=KSlaveDefCWaitTime)
   1.936 +				{
   1.937 +				I2C_PRINT(("ERROR: Master Wait time read back has unexpected value (=%d) \n",timeout));
   1.938 +				return KErrGeneral;
   1.939 +				}
   1.940 +			r=SetMasterWaitTime(KSlaveDefMWaitTime);
   1.941 +			if(r!=KErrNone)
   1.942 +				{
   1.943 +				I2C_PRINT(("ERROR: Attempt to set reset Master wait time (%d) rejected\n",KSlaveDefMWaitTime));
   1.944 +				return KErrGeneral;
   1.945 +				}
   1.946 +			timeout=GetMasterWaitTime();
   1.947 +			if(timeout!=KSlaveDefMWaitTime)
   1.948 +				{
   1.949 +				I2C_PRINT(("ERROR: Master Wait time read back of reset time has unexpected value (=%d) \n",timeout));
   1.950 +				return KErrGeneral;
   1.951 +				}
   1.952 +			// Client timeout
   1.953 +			timeout=GetClientWaitTime();
   1.954 +			if(timeout!=KSlaveDefCWaitTime)
   1.955 +				{
   1.956 +				I2C_PRINT(("ERROR: Initial Client Wait time != KSlaveDefCWaitTime (=%d) \n",timeout));
   1.957 +				return KErrGeneral;
   1.958 +				}
   1.959 +			r=SetClientWaitTime(-1);
   1.960 +			if(r!=KErrArgument)
   1.961 +				{
   1.962 +				I2C_PRINT(("ERROR: Attempt to set negative Client wait time not rejected\n"));
   1.963 +				return KErrGeneral;
   1.964 +				}
   1.965 +			r=SetClientWaitTime(KSlaveDefMWaitTime+1);
   1.966 +			if(r!=KErrNone)
   1.967 +				{
   1.968 +				I2C_PRINT(("ERROR: Attempt to set new valid Client wait time (%d) rejected\n",KSlaveDefMWaitTime));
   1.969 +				return KErrGeneral;
   1.970 +				}
   1.971 +			timeout=GetClientWaitTime();
   1.972 +			if(timeout!=KSlaveDefMWaitTime+1)
   1.973 +				{
   1.974 +				I2C_PRINT(("ERROR: Client Wait time read back has unexpected value (=%d) \n",timeout));
   1.975 +				return KErrGeneral;
   1.976 +				}
   1.977 +			r=SetClientWaitTime(KSlaveDefCWaitTime);
   1.978 +			if(r!=KErrNone)
   1.979 +				{
   1.980 +				I2C_PRINT(("ERROR: Attempt to set reset Client wait time (%d) rejected\n",KSlaveDefCWaitTime));
   1.981 +				return KErrGeneral;
   1.982 +				}
   1.983 +			timeout=GetClientWaitTime();
   1.984 +			if(timeout!=KSlaveDefCWaitTime)
   1.985 +				{
   1.986 +				I2C_PRINT(("ERROR: Client Wait time read back of reset time has unexpected value (=%d) \n",timeout));
   1.987 +				return KErrGeneral;
   1.988 +				}
   1.989 +			break;
   1.990 +			}
   1.991 +
   1.992 +		default:
   1.993 +			{
   1.994 +			Kern::Printf("aFunction %d is not recognised \n",aFunction);
   1.995 +			r=KErrNotSupported;
   1.996 +			}
   1.997 +		}
   1.998 +#ifdef IIC_INSTRUMENTATION_MACRO
   1.999 +	IIC_SSTATEXT_END_PSL_TRACE;
  1.1000 +#endif
  1.1001 +	return r;
  1.1002 +	}
  1.1003 +
  1.1004 +
  1.1005 +
  1.1006 +//#ifdef MASTER_MODE
  1.1007 +#endif
  1.1008 +
  1.1009 +#if defined(MASTER_MODE) && defined(SLAVE_MODE)
  1.1010 +#ifdef STANDALONE_CHANNEL
  1.1011 +EXPORT_C
  1.1012 +#endif
  1.1013 +DSimulatedIicBusChannelMasterSlaveI2c::DSimulatedIicBusChannelMasterSlaveI2c(TBusType /*aBusType*/, TChannelDuplex aChanDuplex, DSimulatedIicBusChannelMasterI2c* aMasterChan, DSimulatedIicBusChannelSlaveI2c* aSlaveChan)
  1.1014 +	: DIicBusChannelMasterSlave(EI2c, aChanDuplex, aMasterChan, aSlaveChan)
  1.1015 +	{}
  1.1016 +
  1.1017 +TInt DSimulatedIicBusChannelMasterSlaveI2c::StaticExtension(TUint aFunction, TAny* /*aParam1*/, TAny* /*aParam2*/)
  1.1018 +	{
  1.1019 +	I2C_PRINT(("DSimulatedIicBusChannelMasterSlaveI2c::StaticExtension, aFunction=0x%x\n",aFunction));
  1.1020 +	TInt r = KErrNone;
  1.1021 +
  1.1022 +	// Test values of aFunction were shifted left one place by the (test) client driver
  1.1023 +	// Return to its original value.
  1.1024 +	if(aFunction>KTestControlIoPilOffset)
  1.1025 +		aFunction >>= 1;
  1.1026 +	switch(aFunction)
  1.1027 +		{
  1.1028 +		case(RBusDevIicClient::ECtlIoDumpChan):
  1.1029 +			{
  1.1030 +#ifdef _DEBUG
  1.1031 +			DumpChannel();
  1.1032 +#endif
  1.1033 +			break;
  1.1034 +			}
  1.1035 +		case(RBusDevIicClient::ECtlIoDeRegChan):
  1.1036 +			{
  1.1037 +			I2C_PRINT(("DSimulatedIicBusChannelMasterSlaveI2c: deregister channel\n"));
  1.1038 +#ifndef STANDALONE_CHANNEL
  1.1039 +			r=DIicBusController::DeRegisterChannel(this);
  1.1040 +#else
  1.1041 +			return KErrNotSupported;
  1.1042 +#endif
  1.1043 +			break;
  1.1044 +			}
  1.1045 +		case(RBusDevIicClient::ECtlIoBlockReqCompletion):
  1.1046 +			{
  1.1047 +			I2C_PRINT(("DSimulatedIicBusChannelMasterSlaveI2c::Blocking request completion\n"));
  1.1048 +			((DSimulatedIicBusChannelMasterI2c*)iMasterChannel)->SetRequestDelayed(((DSimulatedIicBusChannelMasterI2c*)iMasterChannel), ETrue);
  1.1049 +			break;
  1.1050 +			}
  1.1051 +		case(RBusDevIicClient::ECtlIoUnblockReqCompletion):
  1.1052 +			{
  1.1053 +			I2C_PRINT(("DSimulatedIicBusChannelMasterSlaveI2c::Unlocking request completion\n"));
  1.1054 +			((DSimulatedIicBusChannelMasterI2c*)iMasterChannel)->SetRequestDelayed(((DSimulatedIicBusChannelMasterI2c*)iMasterChannel), EFalse);
  1.1055 +			break;
  1.1056 +			}
  1.1057 +		default:
  1.1058 +			{
  1.1059 +			Kern::Printf("aFunction %d is not recognised \n",aFunction);
  1.1060 +			r=KErrNotSupported;
  1.1061 +			}
  1.1062 +		}
  1.1063 +	return r;
  1.1064 +	}
  1.1065 +
  1.1066 +
  1.1067 +//#if defined(MASTER_MODE) && defined(SLAVE_MODE)
  1.1068 +#endif
  1.1069 +
  1.1070 +
  1.1071 +