author | William Roberts <williamr@symbian.org> |
Fri, 23 Jul 2010 10:28:58 +0100 | |
branch | GCC_SURGE |
changeset 223 | 9b475c7a1224 |
parent 90 | 947f0dc9f7a8 |
child 257 | 3e88ff8f41d5 |
child 261 | 4dbffe5c974e |
permissions | -rw-r--r-- |
0 | 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.cpp |
|
15 |
// |
|
16 |
#include "spi.h" |
|
17 |
||
18 |
#ifdef IIC_INSTRUMENTATION_MACRO |
|
19 |
#include <drivers/iic_trace.h> |
|
20 |
#endif |
|
21 |
||
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
22 |
#ifndef STANDALONE_CHANNEL |
0 | 23 |
#define NUM_CHANNELS 4 // Arbitrary |
24 |
||
25 |
// Macros to be updated(?) with interaction with Configuration Repository |
|
26 |
const TInt KChannelTypeArray[NUM_CHANNELS] = {DIicBusChannel::EMaster, DIicBusChannel::EMaster, DIicBusChannel::ESlave, DIicBusChannel::EMaster}; |
|
27 |
#define CHANNEL_TYPE(n) (KChannelTypeArray[n]) |
|
28 |
const DIicBusChannel::TChannelDuplex KChannelDuplexArray[NUM_CHANNELS] = {DIicBusChannel::EHalfDuplex, DIicBusChannel::EHalfDuplex, DIicBusChannel::EHalfDuplex, DIicBusChannel::EFullDuplex}; |
|
29 |
#define CHANNEL_DUPLEX(n) (KChannelDuplexArray[n]) |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
30 |
#endif/*STANDALONE_CHANNEL*/ |
0 | 31 |
|
32 |
#ifdef LOG_SPI |
|
33 |
#define SPI_PRINT(str) Kern::Printf str |
|
34 |
#else |
|
35 |
#define SPI_PRINT(str) |
|
36 |
#endif |
|
37 |
||
38 |
_LIT(KSpiThreadName,"SpiChannelThread"); |
|
39 |
||
40 |
const TInt KSpiThreadPriority = 5; // Arbitrary, can be 0-7, 7 highest |
|
41 |
||
42 |
#ifdef STANDALONE_CHANNEL |
|
43 |
_LIT(KPddNameSpi,"spi_ctrless.pdd"); |
|
44 |
#else |
|
45 |
_LIT(KPddNameSpi,"spi.pdd"); |
|
46 |
#endif |
|
47 |
||
48 |
#ifndef STANDALONE_CHANNEL |
|
49 |
LOCAL_C TInt8 AssignChanNum() |
|
50 |
{ |
|
51 |
static TInt8 iBaseChanNum = KSpiChannelNumBase; |
|
52 |
SPI_PRINT(("SPI AssignChanNum - on entry, iBaseCanNum = 0x%x\n",iBaseChanNum)); |
|
53 |
return iBaseChanNum++; // Arbitrary, for illustration |
|
54 |
} |
|
55 |
#endif |
|
56 |
||
57 |
NONSHARABLE_CLASS(DSimulatedSpiDevice) : public DPhysicalDevice |
|
58 |
{ |
|
59 |
// Class to faciliate loading of the IIC classes |
|
60 |
public: |
|
61 |
class TCaps |
|
62 |
{ |
|
63 |
public: |
|
64 |
TVersion iVersion; |
|
65 |
}; |
|
66 |
public: |
|
67 |
DSimulatedSpiDevice(); |
|
68 |
virtual TInt Install(); |
|
69 |
virtual TInt Create(DBase*& aChannel, TInt aUnit, const TDesC8* anInfo, const TVersion& aVer); |
|
70 |
virtual TInt Validate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer); |
|
71 |
virtual void GetCaps(TDes8& aDes) const; |
|
72 |
inline static TVersion VersionRequired(); |
|
73 |
}; |
|
74 |
||
75 |
TVersion DSimulatedSpiDevice::VersionRequired() |
|
76 |
{ |
|
77 |
SPI_PRINT(("DSimulatedSpiDevice::VersionRequired\n")); |
|
78 |
return TVersion(KIicClientMajorVersionNumber,KIicClientMinorVersionNumber,KIicClientBuildVersionNumber); |
|
79 |
} |
|
80 |
||
81 |
/** Factory class constructor */ |
|
82 |
DSimulatedSpiDevice::DSimulatedSpiDevice() |
|
83 |
{ |
|
84 |
SPI_PRINT(("DSimulatedSpiDevice::DSimulatedSpiDevice\n")); |
|
85 |
iVersion = DSimulatedSpiDevice::VersionRequired(); |
|
86 |
} |
|
87 |
||
88 |
TInt DSimulatedSpiDevice::Install() |
|
89 |
{ |
|
90 |
SPI_PRINT(("DSimulatedSpiDevice::Install\n")); |
|
91 |
return(SetName(&KPddNameSpi)); |
|
92 |
} |
|
93 |
||
94 |
/** Called by the kernel's device driver framework to create a Physical Channel. */ |
|
95 |
TInt DSimulatedSpiDevice::Create(DBase*& /*aChannel*/, TInt /*aUint*/, const TDesC8* /*anInfo*/, const TVersion& /*aVer*/) |
|
96 |
{ |
|
97 |
SPI_PRINT(("DSimulatedSpiDevice::Create\n")); |
|
98 |
return KErrNone; |
|
99 |
} |
|
100 |
||
101 |
/** Called by the kernel's device driver framework to check if this PDD is suitable for use with a Logical Channel.*/ |
|
102 |
TInt DSimulatedSpiDevice::Validate(TInt /*aUnit*/, const TDesC8* /*anInfo*/, const TVersion& aVer) |
|
103 |
{ |
|
104 |
SPI_PRINT(("DSimulatedSpiDevice::Validate\n")); |
|
105 |
if (!Kern::QueryVersionSupported(DSimulatedSpiDevice::VersionRequired(),aVer)) |
|
106 |
return(KErrNotSupported); |
|
107 |
return KErrNone; |
|
108 |
} |
|
109 |
||
110 |
/** Return the driver capabilities */ |
|
111 |
void DSimulatedSpiDevice::GetCaps(TDes8& aDes) const |
|
112 |
{ |
|
113 |
SPI_PRINT(("DSimulatedSpiDevice::GetCaps\n")); |
|
114 |
// Create a capabilities object |
|
115 |
TCaps caps; |
|
116 |
caps.iVersion = iVersion; |
|
117 |
// Zero the buffer |
|
118 |
TInt maxLen = aDes.MaxLength(); |
|
119 |
aDes.FillZ(maxLen); |
|
120 |
// Copy capabilities |
|
121 |
TInt size=sizeof(caps); |
|
122 |
if(size>maxLen) |
|
123 |
size=maxLen; |
|
124 |
aDes.Copy((TUint8*)&caps,size); |
|
125 |
} |
|
126 |
||
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
127 |
#ifndef STANDALONE_CHANNEL |
0 | 128 |
// supported channels for this implementation |
129 |
static DIicBusChannel* ChannelPtrArray[NUM_CHANNELS]; |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
130 |
#endif |
0 | 131 |
|
132 |
//DECLARE_EXTENSION_WITH_PRIORITY(BUS_IMPLMENTATION_PRIORITY) |
|
133 |
DECLARE_STANDARD_PDD() // SPI test driver to be explicitly loaded as an LDD, not kernel extension |
|
134 |
{ |
|
135 |
SPI_PRINT(("\n\nSPI PDD, channel creation loop follows ...\n")); |
|
136 |
||
137 |
#ifndef STANDALONE_CHANNEL |
|
138 |
DIicBusChannel* chan=NULL; |
|
139 |
for(TInt i=0; i<NUM_CHANNELS; i++) |
|
140 |
{ |
|
141 |
SPI_PRINT(("\n")); |
|
142 |
if(CHANNEL_TYPE(i) == (DIicBusChannel::EMaster)) |
|
143 |
{ |
|
144 |
chan=new DSimulatedIicBusChannelMasterSpi(BUS_TYPE,CHANNEL_DUPLEX(i)); |
|
145 |
if(!chan) |
|
146 |
return NULL; |
|
147 |
SPI_PRINT(("SPI chan created at 0x%x\n",chan)); |
|
148 |
if(((DSimulatedIicBusChannelMasterSpi*)chan)->Create()!=KErrNone) |
|
149 |
return NULL; |
|
150 |
} |
|
151 |
else if(CHANNEL_TYPE(i) == DIicBusChannel::EMasterSlave) |
|
152 |
{ |
|
153 |
DIicBusChannel* chanM=new DSimulatedIicBusChannelMasterSpi(BUS_TYPE,CHANNEL_DUPLEX(i)); |
|
154 |
if(!chanM) |
|
155 |
return NULL; |
|
156 |
DIicBusChannel* chanS=new DSimulatedIicBusChannelSlaveSpi(BUS_TYPE,CHANNEL_DUPLEX(i)); |
|
157 |
if(!chanS) |
|
158 |
return NULL; |
|
159 |
// For MasterSlave channel, the channel number for both the Master and Slave channels must be the same |
|
160 |
TInt8 msChanNum = ((DSimulatedIicBusChannelMasterSpi*)chanM)->GetChanNum(); |
|
161 |
((DSimulatedIicBusChannelSlaveSpi*)chanS)->SetChanNum(msChanNum); |
|
162 |
||
163 |
chan=new DIicBusChannelMasterSlave(BUS_TYPE,CHANNEL_DUPLEX(i),(DIicBusChannelMaster*)chanM,(DIicBusChannelSlave*)chanS); // Generic implementation |
|
164 |
if(!chan) |
|
165 |
return NULL; |
|
166 |
SPI_PRINT(("SPI chan created at 0x%x\n",chan)); |
|
167 |
if(((DIicBusChannelMasterSlave*)chan)->DoCreate()!=KErrNone) |
|
168 |
return NULL; |
|
169 |
} |
|
170 |
else |
|
171 |
{ |
|
172 |
chan=new DSimulatedIicBusChannelSlaveSpi(BUS_TYPE,CHANNEL_DUPLEX(i)); |
|
173 |
if(!chan) |
|
174 |
return NULL; |
|
175 |
SPI_PRINT(("SPI chan created at 0x%x\n",chan)); |
|
176 |
if(((DSimulatedIicBusChannelSlaveSpi*)chan)->Create()!=KErrNone) |
|
177 |
return NULL; |
|
178 |
} |
|
179 |
ChannelPtrArray[i]=chan; |
|
180 |
} |
|
181 |
SPI_PRINT(("\nSPI PDD, channel creation loop done- about to invoke RegisterChannels\n\n")); |
|
182 |
#ifdef IIC_INSTRUMENTATION_MACRO |
|
183 |
IIC_REGISTERCHANS_START_PSL_TRACE; |
|
184 |
#endif |
|
185 |
||
186 |
TInt r = KErrNone; |
|
187 |
r=DIicBusController::RegisterChannels(ChannelPtrArray,NUM_CHANNELS); |
|
188 |
||
189 |
#ifdef IIC_INSTRUMENTATION_MACRO |
|
190 |
IIC_REGISTERCHANS_END_PSL_TRACE; |
|
191 |
#endif |
|
192 |
SPI_PRINT(("\nSPI - returned from RegisterChannels with r=%d\n",r)); |
|
193 |
if(r!=KErrNone) |
|
194 |
{ |
|
195 |
delete chan; |
|
196 |
return NULL; |
|
197 |
} |
|
198 |
#endif |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
199 |
return new DSimulatedSpiDevice; |
0 | 200 |
} |
201 |
||
202 |
#ifdef STANDALONE_CHANNEL |
|
203 |
EXPORT_C |
|
204 |
#endif |
|
205 |
DSimulatedIicBusChannelMasterSpi::DSimulatedIicBusChannelMasterSpi(const TBusType aBusType, const TChannelDuplex aChanDuplex) |
|
206 |
: DIicBusChannelMaster(aBusType,aChanDuplex) |
|
207 |
{ |
|
208 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::DSimulatedIicBusChannelMasterSpi, aBusType=%d,aChanDuplex=%d\n",aBusType,aChanDuplex)); |
|
209 |
#ifndef STANDALONE_CHANNEL |
|
210 |
iChannelNumber = AssignChanNum(); |
|
211 |
#endif |
|
212 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::DSimulatedIicBusChannelMasterSpi, iChannelNumber=%d\n",iChannelNumber)); |
|
213 |
iTestState = ETestNone; |
|
214 |
iChannelState = EIdle; |
|
215 |
} |
|
216 |
||
217 |
// The time-out call back invoked when the Slave exeecds the allowed response time |
|
218 |
TInt DSimulatedIicBusChannelMasterSpi::HandleSlaveTimeout() |
|
219 |
{ |
|
220 |
SPI_PRINT(("HandleSlaveTimeout \n")); |
|
221 |
return AsynchStateMachine(ETimeExpired); |
|
222 |
} |
|
223 |
||
224 |
TInt DSimulatedIicBusChannelMasterSpi::DoCreate() |
|
225 |
{ |
|
226 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::DoCreate\n")); |
|
227 |
TInt r=Init(); // PIL Base class initialisation |
|
228 |
r=Kern::DynamicDfcQCreate(iDynamicDfcQ,KSpiThreadPriority,KSpiThreadName); |
|
229 |
if(r == KErrNone) |
|
230 |
SetDfcQ((TDfcQue*)iDynamicDfcQ); |
|
231 |
DSimulatedIicBusChannelMasterSpi::SetRequestDelayed(this,EFalse); |
|
232 |
return r; |
|
233 |
} |
|
234 |
||
235 |
TInt DSimulatedIicBusChannelMasterSpi::CheckHdr(TDes8* aHdr) |
|
236 |
{ |
|
237 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::CheckHdr\n")); |
|
238 |
||
239 |
TConfigSpiBufV01* spiBuf = (TConfigSpiBufV01*)aHdr; |
|
240 |
TConfigSpiV01* spiPtr = &((*spiBuf)()); |
|
241 |
||
242 |
// Valid values for the device ID will depend on the bus configuration |
|
243 |
// |
|
244 |
// Check that the values for word width, clock speed and clock mode are recognised |
|
245 |
if((spiPtr->iWordWidth < 0) || (spiPtr->iWordWidth > ESpiWordWidth_16)) |
|
246 |
{ |
|
247 |
SPI_PRINT(("ERROR: DSimulatedIicBusChannelMasterSpi::CheckHdr unrecognised word width identifier %d\n",spiPtr->iWordWidth)); |
|
248 |
return KErrArgument; |
|
249 |
} |
|
250 |
if(spiPtr->iClkSpeedHz < 0) |
|
251 |
{ |
|
252 |
SPI_PRINT(("ERROR: DSimulatedIicBusChannelMasterSpi::CheckHdr negative clock speed specified %d\n",spiPtr->iClkSpeedHz)); |
|
253 |
return KErrArgument; |
|
254 |
} |
|
255 |
if((spiPtr->iClkMode < 0) || (spiPtr->iClkMode > ESpiPolarityHighRisingEdge)) |
|
256 |
{ |
|
257 |
SPI_PRINT(("ERROR: DSimulatedIicBusChannelMasterSpi::CheckHdr unrecognised clock mode identifier %d\n",spiPtr->iClkMode)); |
|
258 |
return KErrArgument; |
|
259 |
} |
|
260 |
// Values for the timeout period are arbitrary - can only check it is not a negative value |
|
261 |
if(spiPtr->iTimeoutPeriod < 0) |
|
262 |
{ |
|
263 |
SPI_PRINT(("ERROR: DSimulatedIicBusChannelMasterSpi::CheckHdr negative timeout period %d\n",spiPtr->iTimeoutPeriod)); |
|
264 |
return KErrArgument; |
|
265 |
} |
|
266 |
if((spiPtr->iEndianness < 0) || (spiPtr->iEndianness > ELittleEndian)) |
|
267 |
{ |
|
268 |
SPI_PRINT(("ERROR: DSimulatedIicBusChannelMasterSpi::CheckHdr unrecognised endianness identifier %d\n",spiPtr->iEndianness)); |
|
269 |
return KErrArgument; |
|
270 |
} |
|
271 |
if((spiPtr->iBitOrder < 0) || (spiPtr->iBitOrder > EMsbFirst)) |
|
272 |
{ |
|
273 |
SPI_PRINT(("ERROR: DSimulatedIicBusChannelMasterSpi::CheckHdr unrecognised bit order identifier %d\n",spiPtr->iBitOrder)); |
|
274 |
return KErrArgument; |
|
275 |
} |
|
276 |
if((spiPtr->iSSPinActiveMode < 0) || (spiPtr->iSSPinActiveMode > ESpiCSPinActiveHigh)) |
|
277 |
{ |
|
278 |
SPI_PRINT(("ERROR: DSimulatedIicBusChannelMasterSpi::CheckHdr unrecognised Slave select pin mode identifier %d\n",spiPtr->iSSPinActiveMode)); |
|
279 |
return KErrArgument; |
|
280 |
} |
|
281 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::CheckHdr word width = %d\n",spiPtr->iWordWidth)); |
|
282 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::CheckHdr clock speed = %d\n",spiPtr->iClkSpeedHz)); |
|
283 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::CheckHdr clock mode = %d\n",spiPtr->iClkMode)); |
|
284 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::CheckHdr timeout period = %d\n",spiPtr->iTimeoutPeriod)); |
|
285 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::CheckHdr endianness = %d\n",spiPtr->iEndianness)); |
|
286 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::CheckHdr bit order = %d\n",spiPtr->iBitOrder)); |
|
287 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::CheckHdr transaction wait cycles = %d\n",spiPtr->iTransactionWaitCycles)); |
|
288 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::CheckHdr slave select pin mode = %d\n",spiPtr->iSSPinActiveMode)); |
|
289 |
||
290 |
// For the set of tests expecft the following values |
|
291 |
// ESpiWordWidth_8, 100kHz, ESpiPolarityLowRisingEdge,aTimeoutPeriod=100 |
|
292 |
// EBigEndian, EMsbFirst, 10 wait cycles, Slave select active low |
|
293 |
if( (spiPtr->iWordWidth != ESpiWordWidth_8) || |
|
294 |
(spiPtr->iClkSpeedHz != 100000) || |
|
295 |
(spiPtr->iClkMode != ESpiPolarityLowRisingEdge) || |
|
296 |
(spiPtr->iTimeoutPeriod != 100) || |
|
297 |
(spiPtr->iEndianness != ELittleEndian) || |
|
298 |
(spiPtr->iBitOrder != EMsbFirst) || |
|
299 |
(spiPtr->iTransactionWaitCycles != 10) || |
|
300 |
(spiPtr->iSSPinActiveMode != ESpiCSPinActiveLow) ) |
|
301 |
return KErrCorrupt; |
|
302 |
return KErrNone; |
|
303 |
} |
|
304 |
||
305 |
TInt DSimulatedIicBusChannelMasterSpi::CompareTransactionOne(TIicBusTransaction* aTransaction) |
|
306 |
// Compares the indicated TIicBusTransaction with the expected content |
|
307 |
// Returns KErrNone if there is a match, KErrCorrupt otherwise. |
|
308 |
{ |
|
309 |
TInt i; |
|
310 |
// Check the transaction header |
|
311 |
// Should contain the default header for SPI |
|
312 |
TDes8* bufPtr = GetTransactionHeader(aTransaction); |
|
313 |
if(bufPtr == NULL) |
|
314 |
{ |
|
315 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::CompareTransactionOne ERROR - NULL header\n")); |
|
316 |
return KErrCorrupt; |
|
317 |
} |
|
318 |
TConfigSpiV01 *buf = (TConfigSpiV01 *)(bufPtr->Ptr()); |
|
319 |
if(buf->iWordWidth != ESpiWordWidth_8) |
|
320 |
{ |
|
321 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::CompareTransactionOne ERROR - Header wordwidth mis-match\n")); |
|
322 |
return KErrCorrupt; |
|
323 |
} |
|
324 |
if(buf->iClkSpeedHz !=100000) |
|
325 |
{ |
|
326 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::CompareTransactionOne ERROR - Header clockspeed mis-match\n")); |
|
327 |
return KErrCorrupt; |
|
328 |
} |
|
329 |
if(buf->iClkMode != ESpiPolarityLowRisingEdge) |
|
330 |
{ |
|
331 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::CompareTransactionOne ERROR - Header polarity mis-match\n")); |
|
332 |
return KErrCorrupt; |
|
333 |
} |
|
334 |
if(buf->iTimeoutPeriod != 100) |
|
335 |
{ |
|
336 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::CompareTransactionOne ERROR - Header timeout mis-match\n")); |
|
337 |
return KErrCorrupt; |
|
338 |
} |
|
339 |
||
340 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::CompareTransactionOne header OK\n")); |
|
341 |
||
342 |
// Check the half-duplex transfer list |
|
343 |
TIicBusTransfer* tfer = GetTransHalfDuplexTferPtr(aTransaction); |
|
344 |
if(tfer == NULL) |
|
345 |
{ |
|
346 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::CompareTransactionOne ERROR - NULL half-duplex transfer\n")); |
|
347 |
return KErrCorrupt; |
|
348 |
} |
|
349 |
// Process each transfer in the list |
|
350 |
TInt8 dummy; |
|
351 |
||
352 |
// tfer1 = new TIicBusTransfer(TIicBusTransfer::EMasterWrite,8,buf1); |
|
353 |
// buf1 contains copy of TUint8 KTransOneTferOne[21] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20}; |
|
354 |
dummy=GetTferType(tfer); |
|
355 |
if(dummy!=TIicBusTransfer::EMasterWrite) |
|
356 |
{ |
|
357 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::CompareTransactionOne ERROR - tfer1 type=%d\n")); |
|
358 |
return KErrCorrupt; |
|
359 |
} |
|
360 |
dummy=GetTferBufGranularity(tfer); |
|
361 |
if(dummy!=8) |
|
362 |
{ |
|
363 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::CompareTransactionOne ERROR - tfer1 granularity=%d\n",dummy)); |
|
364 |
return KErrCorrupt; |
|
365 |
} |
|
366 |
if((bufPtr = (TDes8*)GetTferBuffer(tfer)) == NULL) |
|
367 |
{ |
|
368 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::CompareTransactionOne ERROR - tfer1 buffer NULL\n")); |
|
369 |
return KErrCorrupt; |
|
370 |
} |
|
371 |
for(i=0;i<21;++i) |
|
372 |
{ |
|
373 |
if((*bufPtr)[i]!=i) |
|
374 |
{ |
|
375 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::CompareTransactionOne ERROR tfer1 buffer element %d has 0x%x\n",i,(*bufPtr)[i])); |
|
376 |
return KErrCorrupt; |
|
377 |
} |
|
378 |
} |
|
379 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::CompareTransactionOne tfer1 OK\n")); |
|
380 |
||
381 |
||
382 |
tfer=GetTferNextTfer(tfer); |
|
383 |
// tfer2 = new TIicBusTransfer(TIicBusTransfer::EMasterRead,8,buf2); |
|
384 |
// buf2 contains copy of TUint8 KTransOneTferTwo[8] = {17,18,19,20,21,22,23,24}; |
|
385 |
dummy=GetTferType(tfer); |
|
386 |
if(dummy!=TIicBusTransfer::EMasterRead) |
|
387 |
{ |
|
388 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::CompareTransactionOne ERROR - tfer2 type=%d\n",dummy)); |
|
389 |
return KErrCorrupt; |
|
390 |
} |
|
391 |
dummy=GetTferBufGranularity(tfer); |
|
392 |
if(dummy!=8) |
|
393 |
{ |
|
394 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::CompareTransactionOne ERROR - tfer2 granularity=%d\n",dummy)); |
|
395 |
return KErrCorrupt; |
|
396 |
} |
|
397 |
if((bufPtr = (TDes8*)GetTferBuffer(tfer)) == NULL) |
|
398 |
{ |
|
399 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::CompareTransactionOne ERROR - tfer2 buffer NULL\n")); |
|
400 |
return KErrCorrupt; |
|
401 |
} |
|
402 |
for(i=0;i<8;++i) |
|
403 |
{ |
|
404 |
if((*bufPtr)[i]!=(17+i)) |
|
405 |
{ |
|
406 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::CompareTransactionOne ERROR tfer2 buffer element %d has 0x%x\n",i,(*bufPtr)[i])); |
|
407 |
return KErrCorrupt; |
|
408 |
} |
|
409 |
} |
|
410 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::CompareTransactionOne tfer2 OK\n")); |
|
411 |
||
412 |
tfer=GetTferNextTfer(tfer); |
|
413 |
// tfer3 = new TIicBusTransfer(TIicBusTransfer::EMasterWrite,8,buf3); |
|
414 |
// buf2 contains copy of TUint8 KTransOneTferThree[6] = {87,85,83,81,79,77}; |
|
415 |
dummy=GetTferType(tfer); |
|
416 |
if(dummy!=TIicBusTransfer::EMasterWrite) |
|
417 |
{ |
|
418 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::CompareTransactionOne ERROR - tfer3 type=%d\n")); |
|
419 |
return KErrCorrupt; |
|
420 |
} |
|
421 |
dummy=GetTferBufGranularity(tfer); |
|
422 |
if(dummy!=8) |
|
423 |
{ |
|
424 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::CompareTransactionOne ERROR - tfer3 granularity=%d\n",dummy)); |
|
425 |
return KErrCorrupt; |
|
426 |
} |
|
427 |
if((bufPtr = (TDes8*)GetTferBuffer(tfer)) == NULL) |
|
428 |
{ |
|
429 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::CompareTransactionOne ERROR - tfer3 buffer NULL\n")); |
|
430 |
return KErrCorrupt; |
|
431 |
} |
|
432 |
for(i=0;i<6;++i) |
|
433 |
{ |
|
434 |
if((*bufPtr)[i]!=(87-(2*i))) |
|
435 |
{ |
|
436 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::CompareTransactionOne ERROR tfer3 buffer element %d has 0x%x\n",i,(*bufPtr)[i])); |
|
437 |
return KErrCorrupt; |
|
438 |
} |
|
439 |
} |
|
440 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::CompareTransactionOne tfer3 OK\n")); |
|
441 |
||
442 |
// Shouldn't be any more transfers in the half duplex list |
|
443 |
if((tfer=GetTferNextTfer(tfer))!=NULL) |
|
444 |
{ |
|
445 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::CompareTransactionOne ERROR - tfer3 iNext=0x%x\n",tfer)); |
|
446 |
return KErrCorrupt; |
|
447 |
} |
|
448 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::CompareTransactionOne half-duplex transfer OK\n")); |
|
449 |
||
450 |
// The full duplex transfer should be represented by a NULL pointer |
|
451 |
if((tfer=GetTransFullDuplexTferPtr(aTransaction))!=NULL) |
|
452 |
{ |
|
453 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::CompareTransactionOne ERROR - full duplex pointer=0x%x\n",tfer)); |
|
454 |
return KErrCorrupt; |
|
455 |
} |
|
456 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::CompareTransactionOne full duplex pointer is NULL (OK)\n")); |
|
457 |
||
458 |
// Synchronous transaction, so check the callback pointer is NULL |
|
459 |
TIicBusCallback* dumCb = NULL; |
|
460 |
dumCb=GetTransCallback(aTransaction); |
|
461 |
if(dumCb!=NULL) |
|
462 |
{ |
|
463 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::CompareTransactionOne ERROR - callback pointer=0x%x\n",dumCb)); |
|
464 |
return KErrCorrupt; |
|
465 |
} |
|
466 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::CompareTransactionOne callback pointer is NULL (OK)\n")); |
|
467 |
||
468 |
// Check the transaction flags are set to zero |
|
469 |
TUint8 dumFlags; |
|
470 |
dumFlags=GetTransFlags(aTransaction); |
|
471 |
if(dumFlags!=0) |
|
472 |
{ |
|
473 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::CompareTransactionOne ERROR - flags=0x%x\n",dumFlags)); |
|
474 |
return KErrCorrupt; |
|
475 |
} |
|
476 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::CompareTransactionOne flags are zero (OK)\n")); |
|
477 |
||
478 |
return KErrNone; |
|
479 |
} |
|
480 |
||
481 |
||
482 |
// The THwCallbackFunc gets called if the hardware preparation completes successfully. |
|
483 |
void THwCallbackFunc(TAny* aPtr) |
|
484 |
{ |
|
485 |
SPI_PRINT(("Hardware preparation completed, calling the callback function")); |
|
486 |
DSimulatedIicBusChannelMasterSpi* aChanMasterSpi=(DSimulatedIicBusChannelMasterSpi* )aPtr; |
|
487 |
TInt r = aChanMasterSpi->DoSimulatedTransaction(); |
|
488 |
((DSimulatedIicBusChannelMasterSpi*)aChanMasterSpi)->CompleteReq(r); |
|
489 |
} |
|
490 |
||
491 |
TInt DSimulatedIicBusChannelMasterSpi::DoSimulatedTransaction() |
|
492 |
{ |
|
493 |
TInt r = AsynchStateMachine(EHwTransferDone); |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
494 |
CancelTimeOut(); |
0 | 495 |
return r; |
496 |
} |
|
497 |
||
498 |
TInt DSimulatedIicBusChannelMasterSpi::DoHwPreparation() |
|
499 |
{ |
|
500 |
SPI_PRINT(("Preparing hardware for the transaction")); |
|
501 |
||
502 |
TInt r = KErrNone; |
|
503 |
// The hardware preparation can either complete successfully or fail. |
|
504 |
// If successful, invoke the callback function of THwDoneCallBack |
|
505 |
// if not, execute the timeout machanism |
|
506 |
// Currently DoHwPreparation is just a simple function. It should be more complicated |
|
507 |
// for the real hardware. |
|
508 |
switch(iTestState) |
|
509 |
{ |
|
510 |
case (ETestSlaveTimeOut): |
|
511 |
{ |
|
512 |
// In the timeout test, do nothing until the timeout callback function is invoked. |
|
513 |
SPI_PRINT(("Simulating the timeout process.")); |
|
514 |
break; |
|
515 |
} |
|
516 |
case (ETestNone): |
|
517 |
{ |
|
518 |
// Pretend the hardware preparation's been done, and a callback function is invoked to call |
|
519 |
// the Asynchronous State Machine |
|
520 |
SPI_PRINT(("Hardware preparing work is executing normally.")); |
|
521 |
iCb->Enque(); |
|
522 |
break; |
|
523 |
} |
|
524 |
default: |
|
525 |
{ |
|
526 |
SPI_PRINT(("Not a valid test.")); |
|
527 |
r = KErrNotSupported; |
|
528 |
break; |
|
529 |
} |
|
530 |
} |
|
531 |
||
532 |
return r; |
|
533 |
} |
|
534 |
||
535 |
// Gateway function for PSL implementation, invoked for DFC processing |
|
536 |
TInt DSimulatedIicBusChannelMasterSpi::DoRequest(TIicBusTransaction* aTransaction) |
|
537 |
{ |
|
538 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::DoRequest invoked with aTransaction=0x%x\n",aTransaction)); |
|
539 |
||
540 |
TInt r = KErrNone; |
|
541 |
iCurrTrans=aTransaction; |
|
542 |
||
543 |
// Check if the Asynchronous State Machine is available. If not, then return KErrInUse. |
|
544 |
// This is used to stop the second transaction executing if the machine has already been holding |
|
545 |
// by a transaction. However, this situation cannot be tested because of the malfunction in PIL |
|
546 |
if(iChannelState!= EIdle) |
|
547 |
return KErrInUse; |
|
548 |
||
549 |
iChannelState = EBusy; |
|
550 |
#ifdef IIC_INSTRUMENTATION_MACRO |
|
551 |
IIC_MPROCESSTRANS_START_PSL_TRACE; |
|
552 |
#endif |
|
553 |
r = ProcessTrans(aTransaction); |
|
554 |
||
555 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::DoRequest - exiting\n")); |
|
556 |
return r; |
|
557 |
} |
|
558 |
||
559 |
TInt DSimulatedIicBusChannelMasterSpi::ProcessTrans(TIicBusTransaction* aTransaction) |
|
560 |
{ |
|
561 |
TInt r=KErrNone; |
|
562 |
||
563 |
switch(iTestState) |
|
564 |
{ |
|
565 |
case(ETestWaitTransOne): |
|
566 |
{ |
|
567 |
// The transaction received should exhibit the expected data |
|
568 |
// Return KErrArgument if this is not the case |
|
569 |
// The timer should be started at the beginning of every transaction |
|
570 |
// For simplicity, we omit the timer here. |
|
571 |
r=CompareTransactionOne(iCurrTrans); |
|
572 |
iChannelState = EIdle; |
|
573 |
CompleteRequest(KErrNone); |
|
574 |
break; |
|
575 |
} |
|
576 |
case(ETestSlaveTimeOut): |
|
577 |
{ |
|
578 |
// Test the timeout funciton |
|
579 |
SPI_PRINT(("Test the slave timeout function\n")); |
|
580 |
||
581 |
// Simulate a timeout |
|
582 |
// Start a timer and then wait for the Slave response to timeout |
|
583 |
// A real bus would use its own means to identify a timeout |
|
584 |
TInt aTime=1000000/NKern::TickPeriod(); |
|
585 |
r = StartSlaveTimeOutTimer(aTime); |
|
586 |
if(r != KErrNone) |
|
587 |
return r; |
|
588 |
r = DoHwPreparation(); |
|
589 |
break; |
|
590 |
} |
|
591 |
case(ETestWaitPriorityTest): |
|
592 |
{ |
|
593 |
static TInt TranCount = 0; |
|
594 |
if(TranCount >= KPriorityTestNum) return KErrUnknown; |
|
595 |
// block the channel |
|
596 |
while(IsRequestDelayed(this)) |
|
597 |
{ |
|
598 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::DoRequest - starting Sleep...\n")); |
|
599 |
NKern::Sleep(1000); // 1000 is arbitrary |
|
600 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::DoRequest - completed Sleep, check if still delayed\n")); |
|
601 |
}; |
|
602 |
// get transaction header |
|
603 |
TDes8* bufPtr = GetTransactionHeader(aTransaction); |
|
604 |
if(bufPtr == NULL) |
|
605 |
{ |
|
606 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::DoRequest ERROR - NULL header\n")); |
|
607 |
return KErrCorrupt; |
|
608 |
} |
|
609 |
||
610 |
if(TranCount == 0) |
|
611 |
{ |
|
612 |
// ignore the blocking transaction |
|
613 |
TranCount++; |
|
614 |
} |
|
615 |
else |
|
616 |
{ |
|
617 |
// store transaction header |
|
618 |
iPriorityTestResult[TranCount++] = (*bufPtr)[0]; |
|
619 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::DoRequest Priority test transaction no.:%d Priority:%d", |
|
620 |
(*bufPtr)[0], aTransaction->iKey)); |
|
621 |
} |
|
622 |
iChannelState = EIdle; |
|
623 |
CompleteRequest(KErrNone); |
|
624 |
if(TranCount == KPriorityTestNum) iPriorityTestDone = ETrue; |
|
625 |
break; |
|
626 |
} |
|
627 |
||
628 |
||
629 |
||
630 |
case(ETestNone): |
|
631 |
{ |
|
632 |
SPI_PRINT(("Nothing to be tested, just do the usual transaction")); |
|
633 |
||
634 |
// Start the timer on the Slave response. |
|
635 |
// Since no timeout, this timer will be cancelled in the THwCallbackFunc |
|
636 |
r = StartSlaveTimeOutTimer(100000); |
|
637 |
if(r != KErrNone) |
|
638 |
return r; |
|
639 |
// Use a class THwDoneCallBack derived from TDfc to trigger the asynchronous state machine |
|
640 |
// when the hardware preparation completes successfully. |
|
641 |
// The priority is set with an arbitrary number 5 |
|
642 |
iCb = new THwDoneCallBack(THwCallbackFunc, this, iDynamicDfcQ, 5); |
|
643 |
r = DoHwPreparation(); |
|
644 |
break; |
|
645 |
} |
|
646 |
default: |
|
647 |
{ |
|
648 |
SPI_PRINT(("Test status not matched")); |
|
649 |
return KErrNotSupported; |
|
650 |
} |
|
651 |
} |
|
652 |
||
653 |
return r; |
|
654 |
} |
|
655 |
||
656 |
||
657 |
TInt DSimulatedIicBusChannelMasterSpi::AsynchStateMachine(TInt aReason) |
|
658 |
{ |
|
659 |
TInt r=KErrNone; |
|
660 |
||
661 |
// The asynchronous state machine has two states, it could either be idle or busy. |
|
662 |
// Initially, it's in idle state. When a user queues a transaction, the hardware preparation starts |
|
663 |
// and the state changes to busy. After the hardware preparation completes, either successfully or not, |
|
664 |
// the state machine will do the corresponding work for the transaction and then goes back to the idle state. |
|
665 |
switch(iChannelState) |
|
666 |
{ |
|
667 |
case(EIdle): |
|
668 |
{ |
|
669 |
return KErrGeneral; |
|
670 |
} |
|
671 |
case (EBusy): |
|
672 |
{ |
|
673 |
switch(aReason) |
|
674 |
{ |
|
675 |
case(EHwTransferDone): |
|
676 |
{ |
|
677 |
||
678 |
// Simulate processing - for now, do nothing! |
|
679 |
// |
|
680 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::AsynchStateMachine aTransaction->iHeader=0x%x\n",GetTransactionHeader(iCurrTrans))); |
|
681 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::AsynchStateMachine aTransaction->iHalfDuplexTrans=0x%x\n",GetTransHalfDuplexTferPtr(iCurrTrans))); |
|
682 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::AsynchStateMachine aTransaction->iFullDuplexTrans=0x%x\n",GetTransFullDuplexTferPtr(iCurrTrans))); |
|
683 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::AsynchStateMachine aTransaction->iCallback=0x%x\n",GetTransCallback(iCurrTrans))); |
|
684 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::AsynchStateMachine aTransaction->iFlags=0x%x\n",GetTransFlags(iCurrTrans))); |
|
685 |
||
686 |
SPI_PRINT(("\nDSimulatedIicBusChannelMasterSpi::AsynchStateMachine, iHeader info \n")); |
|
687 |
TDes8* bufPtr = GetTransactionHeader(iCurrTrans); |
|
688 |
if(bufPtr == NULL) |
|
689 |
{ |
|
690 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::AsynchStateMachine ERROR - NULL header\n")); |
|
691 |
return KErrCorrupt; |
|
692 |
} |
|
693 |
TConfigSpiV01 *buf = (TConfigSpiV01 *)(bufPtr->Ptr()); |
|
694 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::AsynchStateMachine, header word width=0x%x\n",buf->iWordWidth)); |
|
695 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::AsynchStateMachine, header clock speed=0x%x\n",buf->iClkSpeedHz)); |
|
696 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::AsynchStateMachine, header clock mode=0x%x\n",buf->iClkMode)); |
|
697 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::AsynchStateMachine, header timeout period=0x%x\n",buf->iTimeoutPeriod)); |
|
698 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::AsynchStateMachine, header endianness=0x%x\n",buf->iEndianness)); |
|
699 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::AsynchStateMachine, header bit order=0x%x\n",buf->iBitOrder)); |
|
700 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::AsynchStateMachine, header wait cycles=0x%x\n",buf->iTransactionWaitCycles)); |
|
701 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::AsynchStateMachine, header Slave select pin mode=0x%x\n",buf->iSSPinActiveMode)); |
|
702 |
(void)buf; // Silence compiler when SPI_PRINT not used |
|
703 |
||
704 |
SPI_PRINT(("\nDSimulatedIicBusChannelMasterSpi::AsynchStateMachine, iHalfDuplexTrans info \n")); |
|
705 |
TIicBusTransfer* halfDuplexPtr=GetTransHalfDuplexTferPtr(iCurrTrans); |
|
706 |
while(halfDuplexPtr != NULL) |
|
707 |
{ |
|
708 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::AsynchStateMachine transfer type=0x%x\n",GetTferType(halfDuplexPtr))); |
|
709 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::AsynchStateMachine granularity=0x%x\n",GetTferBufGranularity(halfDuplexPtr))); |
|
710 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::AsynchStateMachine transfer buffer=0x%x\n",GetTferBuffer(halfDuplexPtr))); |
|
711 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::AsynchStateMachine next transfer =0x%x\n",GetTferNextTfer(halfDuplexPtr))); |
|
712 |
halfDuplexPtr=GetTferNextTfer(halfDuplexPtr); |
|
713 |
} |
|
714 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::AsynchStateMachine - End of iHalfDuplexTrans info")); |
|
715 |
||
716 |
while(IsRequestDelayed(this)) |
|
717 |
{ |
|
718 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::AsynchStateMachine - starting Sleep...\n")); |
|
719 |
NKern::Sleep(1000); // 1000 is arbitrary |
|
720 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::AsynchStateMachine - completed Sleep, check if still delayed\n")); |
|
721 |
}; |
|
722 |
||
723 |
iChannelState=EIdle; |
|
724 |
delete iCb; |
|
725 |
break; |
|
726 |
} |
|
727 |
case(ETimeExpired): |
|
728 |
{ |
|
729 |
SPI_PRINT(("Time expired, the Asynchrnous State Machine will be Idle again, and wait for the next request.")); |
|
730 |
iChannelState=EIdle; |
|
731 |
r = KErrTimedOut; |
|
732 |
break; |
|
733 |
} |
|
734 |
default: |
|
735 |
{ |
|
736 |
SPI_PRINT(("Request can not be handled, return error code.")); |
|
737 |
return KErrNotSupported; |
|
738 |
} |
|
739 |
} |
|
740 |
break; |
|
741 |
} |
|
742 |
default: |
|
743 |
{ |
|
744 |
SPI_PRINT(("No matched state")); |
|
745 |
return KErrGeneral; |
|
746 |
} |
|
747 |
} |
|
748 |
return r; |
|
749 |
} |
|
750 |
||
751 |
||
752 |
TBool DSimulatedIicBusChannelMasterSpi::IsRequestDelayed(DSimulatedIicBusChannelMasterSpi* aChan) |
|
753 |
{ |
|
754 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::IsRequestDelayed invoked for aChan=0x%x\n",aChan)); |
|
755 |
return aChan->iReqDelayed; |
|
756 |
} |
|
757 |
||
758 |
void DSimulatedIicBusChannelMasterSpi::SetRequestDelayed(DSimulatedIicBusChannelMasterSpi* aChan,TBool aDelay) |
|
759 |
{ |
|
760 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::SetRequestDelayed invoked for aChan=0x%x, with aDelay=0x%d\n",aChan,aDelay)); |
|
761 |
aChan->iReqDelayed=aDelay; |
|
762 |
} |
|
763 |
||
764 |
TInt DSimulatedIicBusChannelMasterSpi::StaticExtension(TUint aFunction, TAny* aParam1, TAny* aParam2) |
|
765 |
{ |
|
766 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::StaticExtension\n")); |
|
767 |
#ifdef IIC_INSTRUMENTATION_MACRO |
|
768 |
IIC_MSTATEXT_START_PSL_TRACE; |
|
769 |
#endif |
|
770 |
(void)aParam1; |
|
771 |
(void)aParam2; |
|
772 |
TInt r = KErrNone; |
|
773 |
// Test values of aFunction were shifted left one place by the (test) client driver |
|
774 |
// and for Slave values the two msb were cleared |
|
775 |
// Return to its original value. |
|
776 |
if(aFunction>KTestControlIoPilOffset) |
|
777 |
aFunction >>= 1; |
|
778 |
switch(aFunction) |
|
779 |
{ |
|
780 |
case(RBusDevIicClient::ECtlIoDumpChan): |
|
781 |
{ |
|
782 |
#ifdef _DEBUG |
|
783 |
DumpChannel(); |
|
784 |
#endif |
|
785 |
break; |
|
786 |
} |
|
787 |
case(RBusDevIicClient::ECtlIoBlockReqCompletion): |
|
788 |
{ |
|
789 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::Blocking request completion\n")); |
|
790 |
SetRequestDelayed(this, ETrue); |
|
791 |
break; |
|
792 |
} |
|
793 |
case(RBusDevIicClient::ECtlIoUnblockReqCompletion): |
|
794 |
{ |
|
795 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi::Unlocking request completion\n")); |
|
796 |
SetRequestDelayed(this, EFalse); |
|
797 |
break; |
|
798 |
} |
|
799 |
case(RBusDevIicClient::ECtlIoDeRegChan): |
|
800 |
{ |
|
801 |
#ifdef IIC_INSTRUMENTATION_MACRO |
|
802 |
IIC_DEREGISTERCHAN_START_PSL_TRACE; |
|
803 |
#endif |
|
804 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi: deregister channel\n")); |
|
805 |
#ifndef STANDALONE_CHANNEL |
|
806 |
r=DIicBusController::DeRegisterChannel(this); |
|
807 |
#endif |
|
808 |
||
809 |
#ifdef IIC_INSTRUMENTATION_MACRO |
|
810 |
IIC_DEREGISTERCHAN_END_PSL_TRACE; |
|
811 |
#endif |
|
812 |
break; |
|
813 |
} |
|
814 |
||
815 |
case(RBusDevIicClient::ECtlIoPriorityTest): |
|
816 |
{ |
|
817 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi: warned to expect priority test\n")); |
|
818 |
iPriorityTestDone = EFalse; |
|
819 |
iTestState=ETestWaitPriorityTest; |
|
820 |
break; |
|
821 |
} |
|
822 |
case(RBusDevIicClient::EGetTestResult): |
|
823 |
{ |
|
824 |
if(!iPriorityTestDone) return KErrNotReady; |
|
825 |
||
826 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi: get priority test order\n")); |
|
827 |
||
828 |
//iPriorityTestResult[0] is the blocking transaction, ignore it. start from entry 1. |
|
829 |
for(TInt i=1; i<KPriorityTestNum; i++) |
|
830 |
{ |
|
831 |
if(iPriorityTestResult[i]!=(KPriorityTestNum-i-1)) |
|
832 |
{ |
|
833 |
r = KErrGeneral; |
|
834 |
break; |
|
835 |
} |
|
836 |
} |
|
837 |
r = KErrNone; |
|
838 |
break; |
|
839 |
} |
|
840 |
||
841 |
case(RBusDevIicClient::ECtlIoTracnOne): |
|
842 |
{ |
|
843 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi: warned to expect Transaction One\n")); |
|
844 |
iTestState=ETestWaitTransOne; |
|
845 |
break; |
|
846 |
} |
|
847 |
case(RBusDevIicClient::ECtlIoNone): |
|
848 |
{ |
|
849 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi: terminate ControlIO state\n")); |
|
850 |
iTestState=ETestNone; |
|
851 |
break; |
|
852 |
} |
|
853 |
case(RBusDevIicClient::ECtlIoSetTimeOutFlag): |
|
854 |
{ |
|
855 |
SPI_PRINT(("DSimulatedIicBusChannelMasterSpi: test slave time out\n")); |
|
856 |
iTestState=ETestSlaveTimeOut; |
|
857 |
break; |
|
858 |
} |
|
859 |
default: |
|
860 |
{ |
|
861 |
Kern::Printf("aFunction %d is not recognised \n",aFunction); |
|
862 |
r=KErrNotSupported; |
|
863 |
} |
|
864 |
} |
|
865 |
#ifdef IIC_INSTRUMENTATION_MACRO |
|
866 |
IIC_MSTATEXT_END_PSL_TRACE; |
|
867 |
#endif |
|
868 |
return r; |
|
869 |
} |
|
870 |
||
871 |
void DSimulatedIicBusChannelMasterSpi::CompleteReq(TInt aResult) |
|
872 |
{ |
|
873 |
#ifdef IIC_INSTRUMENTATION_MACRO |
|
874 |
IIC_MPROCESSTRANS_END_PSL_TRACE; |
|
875 |
#endif |
|
876 |
CompleteRequest(aResult); |
|
877 |
} |
|
878 |
||
879 |
||
880 |
void DSimulatedIicBusChannelSlaveSpi::SlaveAsyncSimCallback(TAny* aPtr) |
|
881 |
{ |
|
882 |
SPI_PRINT(("SlaveAsyncSimCallback\n")); |
|
883 |
DSimulatedIicBusChannelSlaveSpi* channel = (DSimulatedIicBusChannelSlaveSpi*)aPtr; |
|
884 |
TInt r=KErrNone; // Just simulate successfull capture |
|
885 |
#ifdef IIC_INSTRUMENTATION_MACRO |
|
886 |
IIC_SCAPTCHANASYNC_END_PSL_TRACE; |
|
887 |
#endif |
|
888 |
channel->ChanCaptureCb(r); |
|
889 |
} |
|
890 |
||
891 |
#ifdef STANDALONE_CHANNEL |
|
892 |
EXPORT_C |
|
893 |
#endif |
|
894 |
DSimulatedIicBusChannelSlaveSpi::DSimulatedIicBusChannelSlaveSpi(const DIicBusChannel::TBusType aBusType, const DIicBusChannel::TChannelDuplex aChanDuplex) |
|
895 |
: DIicBusChannelSlave(aBusType,aChanDuplex,0), // 0 to be ignored by base class |
|
896 |
iSlaveTimer(SlaveAsyncSimCallback,this) |
|
897 |
{ |
|
898 |
SPI_PRINT(("DSimulatedIicBusChannelSlaveSpi::DSimulatedIicBusChannelSlaveSpi, aBusType=%d,aChanDuplex=%d\n",aBusType,aChanDuplex)); |
|
899 |
#ifndef STANDALONE_CHANNEL |
|
900 |
iChannelNumber = AssignChanNum(); |
|
901 |
#endif |
|
902 |
SPI_PRINT(("DSimulatedIicBusChannelSlaveSpi::DSimulatedIicBusChannelSlaveSpi, iChannelNumber=%d\n",iChannelNumber)); |
|
903 |
} |
|
904 |
||
905 |
TInt DSimulatedIicBusChannelSlaveSpi::CaptureChannelPsl(TDes8* /*aConfigHdr*/, TBool aAsynch) |
|
906 |
{ |
|
907 |
SPI_PRINT(("DSimulatedIicBusChannelSlaveSpi::CaptureChannelPsl, aAsynch=%d\n",aAsynch)); |
|
908 |
TInt r = KErrNone; |
|
909 |
if(aAsynch) |
|
910 |
{ |
|
911 |
#ifdef IIC_INSTRUMENTATION_MACRO |
|
912 |
IIC_SCAPTCHANASYNC_START_PSL_TRACE; |
|
913 |
#endif |
|
914 |
// To simulate an asynchronous operation, just set a timer to expire |
|
915 |
iSlaveTimer.OneShot(1000, ETrue); // Arbitrary timeout - expiry executes callback in context of DfcThread1 |
|
916 |
} |
|
917 |
else |
|
918 |
{ |
|
919 |
#ifdef IIC_INSTRUMENTATION_MACRO |
|
920 |
IIC_SCAPTCHANSYNC_START_PSL_TRACE; |
|
921 |
#endif |
|
922 |
// PSL processing would happen here ... |
|
923 |
// Expected to include implementation of the header configuration information |
|
924 |
#ifdef IIC_INSTRUMENTATION_MACRO |
|
925 |
IIC_SCAPTCHANSYNC_END_PSL_TRACE; |
|
926 |
#endif |
|
927 |
} |
|
928 |
SPI_PRINT(("DSimulatedIicBusChannelSlaveI2c::CaptureChanSync ... no real processing to do \n")); |
|
929 |
||
930 |
return r; |
|
931 |
} |
|
932 |
||
933 |
TInt DSimulatedIicBusChannelSlaveSpi::CheckHdr(TDes8* /*aHdr*/) |
|
934 |
{ |
|
935 |
SPI_PRINT(("DSimulatedIicBusChannelSlaveSpi::CheckHdr\n")); |
|
936 |
return KErrNone; |
|
937 |
} |
|
938 |
||
939 |
TInt DSimulatedIicBusChannelSlaveSpi::DoCreate() |
|
940 |
{ |
|
941 |
SPI_PRINT(("DSimulatedIicBusChannelSlaveSpi::DoCreate\n")); |
|
942 |
TInt r=Init(); // PIL Base class initialisation |
|
943 |
return r; |
|
944 |
} |
|
945 |
||
946 |
TInt DSimulatedIicBusChannelSlaveSpi::DoRequest(TInt /*aTrigger*/) |
|
947 |
{ |
|
948 |
SPI_PRINT(("DSimulatedIicBusChannelSlaveSpi::DoRequest\n")); |
|
949 |
return KErrNotSupported; |
|
950 |
} |
|
951 |
||
952 |
void DSimulatedIicBusChannelSlaveSpi::ProcessData(TInt /*aTrigger*/, TIicBusSlaveCallback* /*aCb*/) |
|
953 |
{ |
|
954 |
SPI_PRINT(("DSimulatedIicBusChannelSlaveSpi::ProcessData\n")); |
|
955 |
} |
|
956 |
||
957 |
TInt DSimulatedIicBusChannelSlaveSpi::StaticExtension(TUint aFunction, TAny* aParam1, TAny* aParam2) |
|
958 |
{ |
|
959 |
SPI_PRINT(("DSimulatedIicBusChannelSlaveSpi::StaticExtension\n")); |
|
960 |
#ifdef IIC_INSTRUMENTATION_MACRO |
|
961 |
IIC_SSTATEXT_START_PSL_TRACE; |
|
962 |
#endif |
|
963 |
(void)aParam1; |
|
964 |
(void)aParam2; |
|
965 |
// Test values of aFunction were shifted left one place by the (test) client driver |
|
966 |
// and for Slave values the two msb were cleared |
|
967 |
// Return to its original value. |
|
968 |
if(aFunction>KTestControlIoPilOffset) |
|
969 |
{ |
|
970 |
aFunction |= 0xC0000000; |
|
971 |
aFunction >>= 1; |
|
972 |
} |
|
973 |
TInt r = KErrNone; |
|
974 |
switch(aFunction) |
|
975 |
{ |
|
976 |
case(RBusDevIicClient::ECtlIoDumpChan): |
|
977 |
{ |
|
978 |
#ifdef _DEBUG |
|
979 |
DumpChannel(); |
|
980 |
#endif |
|
981 |
break; |
|
982 |
} |
|
983 |
default: |
|
984 |
{ |
|
985 |
Kern::Printf("aFunction %d is not recognised \n",aFunction); |
|
986 |
r=KErrNotSupported; |
|
987 |
} |
|
988 |
} |
|
989 |
||
990 |
#ifdef IIC_INSTRUMENTATION_MACRO |
|
991 |
IIC_SSTATEXT_START_PSL_TRACE; |
|
992 |
#endif |
|
993 |
(void)aFunction; |
|
994 |
return r; |
|
995 |
} |
|
996 |
||
997 |
||
998 |
||
999 |
||
1000 |
||
1001 |