First public contribution.
1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test/iic/t_iic.cpp
17 // This file interacts with test-specific LDD to instigate tests of functionality
18 // that would normally be invoked by kernel-side device driver clients of the IIC.
21 #include <e32cmn_private.h>
23 #include <e32def_private.h>
26 //for memory leak checking
30 _LIT(testName,"t_iic");
32 _LIT(KIicProxyFileNameCtrlLess, "iic_client_ctrless.ldd"); // Kernel-side proxy LDD acting as a client of the IIC
33 _LIT(KIicProxyFileNameRootCtrlLess, "iic_client_ctrless");
34 _LIT(KIicProxySlaveFileNameCtrlLess, "iic_slaveclient_ctrless.ldd"); // Kernel-side proxy LDD acting as a slave client of the IIC
35 _LIT(KIicProxySlaveFileNameRootCtrlLess, "iic_slaveclient_ctrless");
36 _LIT(KIicProxyFileName, "iic_client.ldd"); // Kernel-side proxy LDD acting as a client of the IIC
37 _LIT(KIicProxyFileNameRoot, "iic_client");
38 _LIT(KIicProxySlaveFileName, "iic_slaveclient.ldd"); // Kernel-side proxy LDD acting as a slave client of the IIC
39 _LIT(KIicProxySlaveFileNameRoot, "iic_slaveclient");
41 #ifdef IIC_SIMULATED_PSL
42 _LIT(KSpiFileNameCtrlLess, "spi_ctrless.pdd"); // Simulated PSL bus implementation
43 _LIT(KI2cFileNameCtrlLess, "i2c_ctrless.pdd"); // Simulated PSL bus implementation
44 _LIT(KIicPslFileName, "iic_testpsl.pdd"); // Simulated PSL implementation
45 _LIT(KSpiFileName, "spi.pdd"); // Simulated PSL bus implementation
46 _LIT(KI2cFileName, "i2c.pdd"); // Simulated PSL bus implementation
49 _LIT(KIicPslFileNameRoot, "iic.pdd");
51 // Specify a stand-alone channel
52 GLDEF_D TBool aStandAloneChan;
54 GLDEF_D RTest gTest(testName);
57 // SPI has Master channel numbers 1,2 and 4, Slave channel number 3
58 GLDEF_D RBusDevIicClient gChanMasterSpi;
59 GLDEF_D RBusDevIicClient gChanSlaveSpi;
61 // I2C has Master channel numbers 10 and 11, if built with MASTER_MODE, only
62 // I2C has Slave channel numbers 12 and 13, if built with SLAVE_MODE, only
63 // I2C has Master channel number 10 and Slave channel number 11 if built with both MASTER_MODE and SLAVE_MODE
64 GLDEF_D RBusDevIicClient gChanMasterI2c;
65 GLDEF_D RBusDevIicClient gChanSlaveI2c;
67 LOCAL_C TInt CreateSingleUserSideTransfer(TUsideTferDesc*& aTfer, TInt8 aType, TInt8 aBufGran, TDes8* aBuf, TUsideTferDesc* aNext)
68 // Utility function to create a single transfer
70 aTfer = new TUsideTferDesc();
74 aTfer->iBufGranularity=aBufGran;
75 aTfer->iBuffer = aBuf;
80 LOCAL_C TInt CreateSingleUserSideTransaction(TUsideTracnDesc*& aTracn, TBusType aType, TDes8* aHdr, TUsideTferDesc* aHalfDupTrans, TUsideTferDesc* aFullDupTrans, TUint8 aFlags, TAny* aPreambleArg, TAny* aMultiTranscArg)
81 // Utility function to create a single transaction
83 aTracn = new TUsideTracnDesc();
88 aTracn->iHalfDuplexTrans=aHalfDupTrans;
89 aTracn->iFullDuplexTrans=aFullDupTrans;
90 aTracn->iFlags=aFlags;
91 aTracn->iPreambleArg = aPreambleArg;
92 aTracn->iMultiTranscArg = aMultiTranscArg;
97 //----------------------------------------------------------------------------------------------
98 //! @SYMTestCaseID KBASE-T_IIC-2402
100 //! @SYMPREQ PREQ2128,2129
101 //! @SYMTestCaseDesc This test case test the Master channel basic functionality
102 //! @SYMTestActions 0) Create a transaction and invoke the synchronous Queue Transaction API
104 //! 1) Re-use the transaction and invoke asynchronous Queue Transaction API. Wait for
105 //| the TRequestStatus to be completed.
107 //! 2) Instruct the Kernel-side proxy client to instigate testing of priority queuing.
108 //! The proxy uses controlIO to block the transaction queue, then queues 5 transactions in reverse
109 //! priority order. The proxy then uses controlIO to unblock the transaction queue and checks that
110 //! the transactions complete in priority order.
112 //! 3) Attempt to cancel a previously-completed asynchronous request for a queued transaction
114 //! 4) Use controlio to block request completion. Issue two asynchronous Queue Transaction requests.
115 //! Request cancellation of the second transaction. Wait for completion of the TRequestStatus for
116 //! the second request. Attempt to de-register the channel. Use controlio to unblock request completion.
117 //! Wait for completion of the TRequestStatus for the first request.
119 //! 5) Attempt to de-register a channel that is not busy.
121 //! 6) Attempt to queue a transaction on an invalid (de-registered) channel
123 //! 7) Instruct the Kernel-side proxy client to instigate construction of a valid full duplex transaction.
125 //! 8) Instruct the Kernel-side proxy client to instigate construction of a invalid full duplex transaction,
126 //! where both transfer in same direction
128 //! 9) Instruct the Kernel-side proxy client to instigate construction of a invalid full duplex transaction,
129 //! where with different node length (not the number of node on opposite linklist ) at the same
130 //! position on the opposite transfer linklist
132 //! 10) Instruct the Kernel-side proxy client to instigate construction of a valid full duplex transaction,
133 //! with different size for the last node
135 //! 11) Instruct the Kernel-side proxy client to instigate construction of a valid full duplex transaction,
136 //! with different number of transfer
139 //! @SYMTestExpectedResults 0) Kernel-side proxy client should return with KErrNone, exits otherwise.
140 //! 1) Kernel-side proxy client should return with KErrNone, exits otherwise. TRequestStatus should
141 //! be set to KErrNone, exits otherwise.
142 //! 2) Kernel-side proxy client should return with KErrNone, exits otherwise.
143 //! 3) Kernel-side proxy client should return with KErrNone, exits otherwise.TRequestStatus should
144 //! be set to KErrNone, exits otherwise.
145 //! 4) The TRequestStatus for the cancelled request should be set to KErrCancel, exits otherwise.
146 //! The attempt to de-register the channel should return KErrInUse, exits otherwise. The
147 //! TRequestStatus for the first request should be set to KErrNone, exits otherwise.
148 //! 5) Kernel-side proxy client should return with KErrNone or KErrArgument, exits otherwise.
149 //! 6) Kernel-side proxy client should return with KErrArgument, exits otherwise.
150 //! 7) Kernel-side proxy client should return with KErrNone, exits otherwise.
151 //! 8) Kernel-side proxy client should return with KErrNotSupported, exits otherwise.
152 //! 9) Kernel-side proxy client should return with KErrNotSupported, exits otherwise.
153 //! 10) Kernel-side proxy client should return with KErrNone, exits otherwise.
154 //! 11) Kernel-side proxy client should return with KErrNone, exits otherwise.
156 //! @SYMTestPriority High
157 //! @SYMTestStatus Implemented
158 //----------------------------------------------------------------------------------------------
159 LOCAL_C TInt MasterBasicTests()
161 // Exercise the Master Channel API with trivial data
164 gTest.Printf(_L("\n\nStarting MasterBasicTests\n"));
168 TUint32 busIdSpi = 0;
171 // SPI uses channel numbers 1,2,3 and 4
172 SET_BUS_TYPE(busIdSpi,ESpi);
173 SET_CHAN_NUM(busIdSpi,2);
174 TConfigSpiBufV01* spiBuf = NULL;
175 // aDeviceId=1 ... 100kHz ... aTimeoutPeriod=100 ... aTransactionWaitCycles=10 - arbitrary paarmeters.
176 r = CreateSpiBuf(spiBuf, ESpiWordWidth_8, 100000, ESpiPolarityLowRisingEdge, 100 ,ELittleEndian, EMsbFirst, 10, ESpiCSPinActiveLow);
179 // Use a single transfer
180 _LIT(halfDuplexText,"Half Duplex Text");
181 TBuf8<17> halfDuplexBuf_8;
182 halfDuplexBuf_8.Copy(halfDuplexText);
183 TUsideTferDesc* tfer = NULL;
184 r = CreateSingleUserSideTransfer(tfer, EMasterWrite, 8, &halfDuplexBuf_8, NULL);
187 // Create the transaction object
188 TUsideTracnDesc* tracn = NULL;
189 r = CreateSingleUserSideTransaction(tracn, ESpi, spiBuf, tfer, NULL, 0, NULL, NULL);
192 // Test basic queueing operations
193 // inline TInt QueueTransaction(TInt aBusId, TUsideTracnDesc* aTransaction)
194 gTest.Printf(_L("\n\nStarting synchronous QueueTransaction \n"));
195 r = gChanMasterSpi.QueueTransaction(busIdSpi, tracn);
196 gTest.Printf(_L("Synchronous QueueTransaction returned = %d\n"),r);
198 // inline void QueueTransaction(TRequestStatus& aStatus, TInt aBusId, TUsideTracnDesc* aTransaction)
199 gTest.Printf(_L("\n\nStarting asynchronous QueueTransaction \n"));
200 TRequestStatus status;
202 gChanMasterSpi.QueueTransaction(status, busIdSpi, tracn);
203 User::WaitForRequest(status);
204 if(status != KErrNone)
206 gTest.Printf(_L("TRequestStatus value after queue = %d\n"), status.Int());
210 // Test message with priorities
211 gTest.Printf(_L("\n\nStarting test for message with priorities\n\n"),r);
212 r = gChanMasterSpi.TestPriority(busIdSpi);
215 // Test cancel operation (on previously completed request)
217 // inline void CancelAsyncOperation(TRequestStatus* aStatus, TInt aBusId) {TInt* parms[2]; parms[0]=(TInt*)aStatus; parms[1]=(TInt*)aBusId;DoCancel((TInt)&parms[0]);}
218 gTest.Printf(_L("\n\nStarting CancelAsyncOperation \n"));
219 gChanMasterSpi.CancelAsyncOperation(&status, busIdSpi);
220 if(status == KRequestPending)
221 User::WaitForRequest(status);
222 if(status != KErrNone)
224 gTest.Printf(_L("TRequestStatus value after (belated) cancel = %d\n"), status.Int());
228 // Test cancel operation (on pending request)
229 // Also test that a channel with a transaction queued can not be de-registered.
231 // (1) create a second transaction object
232 // (2) use controlio/StaticExtension to block request completion
233 // (3) use asynchronous queue transaction for the two transaction objects
234 // (4) request cancellation of the second request
235 // (5) check that the TRequestStatus object associated with the second request is completed with KErrCancel
236 // (6) check that attempt to de-register the channel fails with KErrInUse
237 // (7) use controlio/StaticExtension to unblock request completion
238 // (8) check that the TRequestStatus object associated with the first request is completed with KErrNone
240 gTest.Printf(_L("\n\nStarting (successful) cancellation test\n\n"),r);
241 _LIT(halfDuplexText2,"2 Half Duplex Text 2");
242 TBuf8<21> halfDuplexBuf2_8;
243 halfDuplexBuf2_8.Copy(halfDuplexText2);
244 TUsideTferDesc* tfer2 = NULL;
245 r = CreateSingleUserSideTransfer(tfer2, EMasterRead, 16, &halfDuplexBuf2_8, NULL);
246 gTest(r == KErrNone);
248 TUsideTracnDesc* tracn2 = NULL;
252 // aDeviceId=1 ... 100kHz ... aTimeoutPeriod=100 ... aTransactionWaitCycles=10 - arbitrary paarmeters.
253 r = CreateSpiBuf(spiBuf, ESpiWordWidth_8, 100000, ESpiPolarityLowRisingEdge, 100 ,ELittleEndian, EMsbFirst, 10, ESpiCSPinActiveLow);
254 gTest(r == KErrNone);
256 r = CreateSingleUserSideTransaction(tracn2, ESpi, spiBuf, tfer2, NULL, 0, NULL, NULL);
257 gTest(r == KErrNone);
260 gTest.Printf(_L("Invoking BlockReqCompletion\n"));
261 r = gChanMasterSpi.BlockReqCompletion(busIdSpi);
262 gTest.Printf(_L("BlockReqCompletion returned = %d\n"),r);
263 gTest(r == KErrNone);
266 gTest.Printf(_L("Queueing first transaction \n"));
267 gChanMasterSpi.QueueTransaction(status, busIdSpi, tracn);
268 TRequestStatus status2;
270 gTest.Printf(_L("Queueing second transaction \n"));
271 gChanMasterSpi.QueueTransaction(status2, busIdSpi, tracn2);
275 gTest.Printf(_L("Issuing Cancel for second transaction\n"));
276 gChanMasterSpi.CancelAsyncOperation(&status2, busIdSpi);
277 gTest.Printf(_L("Returned from Cancel for second transaction\n"));
278 if(status2 == KRequestPending)
279 User::WaitForRequest(status2);
280 if(status2 != KErrCancel)
282 gTest.Printf(_L("TRequestStatus (2) value after cancel = %d\n"), status2.Int());
286 // If it is stand-alone channel, the client is reponsible for channel creation.
287 // So the RegisterChan and DeRegisterChan are not needed.
288 if (aStandAloneChan == 0)
290 gTest.Printf(_L("Invoking DeRegisterChan\n"));
291 r = gChanMasterSpi.DeRegisterChan(busIdSpi);
293 gTest.Printf(_L("DeRegisterChan returned = %d\n"),r);
297 gTest.Printf(_L("Invoking UnlockReqCompletion\n"));
298 r = gChanMasterSpi.UnblockReqCompletion(busIdSpi);
299 gTest.Printf(_L("UnblockReqCompletion returned = %d\n"),r);
303 User::WaitForRequest(status);
304 if(status != KErrNone)
306 gTest.Printf(_L("TRequestStatus value after queue = %d\n"), status.Int());
317 gTest.Printf(_L("\n\nStarting full duplex transaction creation test\n\n"),r);
319 TUint32 busIdSpiFd = 0;
322 // SPI uses channel numbers 1,2,3 and 4
323 SET_BUS_TYPE(busIdSpi,ESpi);
324 SET_CHAN_NUM(busIdSpi,4);
326 // Test creating a valid full duplex transaction
327 gTest.Printf(_L("\n\nStarting valid full duplex transaction test\n\n"),r);
328 r = gChanMasterSpi.TestValidFullDuplexTrans(busIdSpiFd);
331 // Test creating a full duplex transaction with both transfer in same direction (invalid)
332 gTest.Printf(_L("\n\nStarting invalid direction full duplex transaction test\n\n"),r);
333 r = gChanMasterSpi.TestInvalidFullDuplexTrans1(busIdSpiFd);
334 gTest.Printf(_L("Full duplex transaction with invalid direction returned = %d\n"),r);
335 gTest(r==KErrNotSupported);
337 // Test creating a full duplex transaction with different node length (not the number of node on opposite linklist )
338 // at the same position on the opposite transfer linklist
339 gTest.Printf(_L("\n\nStarting invalid transfer length full duplex transaction test\n\n"),r);
340 r = gChanMasterSpi.TestInvalidFullDuplexTrans2(busIdSpiFd);
341 gTest(r==KErrNotSupported);
343 // Test creating a valid full duplex transaction with different size for the last node
344 gTest.Printf(_L("\n\nStarting valid full duplex transaction test with diff size last node\n\n"),r);
345 r = gChanMasterSpi.TestLastNodeFullDuplexTrans(busIdSpiFd);
348 // Test creating a valid full duplex transaction with different number of transfer
349 gTest.Printf(_L("\n\nStarting valid full duplex transaction test with diff number of transfer\n\n"),r);
350 r = gChanMasterSpi.TestDiffNodeNumFullDuplexTrans(busIdSpiFd);
357 //----------------------------------------------------------------------------------------------
358 //! @SYMTestCaseID KBASE-T_IIC-2403
360 //! @SYMPREQ PREQ2128,2129
361 //! @SYMTestCaseDesc This test case tests the Master channel data handling for transactions
362 //! @SYMTestActions 0) Instruct the kernel-side proxy to construct a transaction of pre-defined data
363 //! and inform the simulated bus to expect to receive this data. Then the proxy invokes
364 //! the synchronous Queue Transaction API. On receipt of the transaction, the simulated bus
365 //! checks the header and transafer content of the transaction to confirm that it is correct.
367 //! @SYMTestExpectedResults 0) Kernel-side proxy client should return with KErrNone, exits otherwise.
369 //! @SYMTestPriority High
370 //! @SYMTestStatus Implemented
371 //----------------------------------------------------------------------------------------------
372 LOCAL_C TInt MasterTransactionTests()
374 // Exercise the Master Channel API with trivial data
377 gTest.Printf(_L("\n\nStarting MasterTransactionTests\n"));
381 // Prove that the simulated bus can access the transfer data contained within a transaction
382 // Do this by instructing the proxy client to:
383 // (1) Inform the bus of the test about to be informed
384 // (2) Send a transaction with a known number of transfers with known data
385 // (3) Check the result announced by the bus.
388 // SPI uses channel numbers 1,2,3 and 4
389 TUint32 busIdSpi = 0;
390 SET_BUS_TYPE(busIdSpi,ESpi);
391 SET_CHAN_NUM(busIdSpi,4); // Master, Full-duplex - required by TestBufferReUse
392 r = gChanMasterSpi.TestTracnOne(busIdSpi);
393 gTest.Printf(_L("TestTracnOne returned = %d\n"),r);
396 // Test that transfer and transaction buffers can be modifed for re-use
397 // This test modifies the content of a full-duplex transaction - so a full-duplex channel must be used
398 TRequestStatus status;
399 gChanMasterSpi.TestBufferReUse(busIdSpi, status);
400 User::WaitForRequest(status);
404 gTest.Printf(_L("TRequestStatus value after CaptureChannel = %d\n"),r);
405 gTest(r==KErrCompletion);
411 //----------------------------------------------------------------------------------------------
412 //! @SYMTestCaseID KBASE-T_IIC-2401
414 //! @SYMPREQ PREQ2128,2129
415 //! @SYMTestCaseDesc This test case test the Master channel preamble and multi-transaction functionality.
416 //! @SYMTestActions 0) Create a transaction that requires preamble support, and queue it for processing
418 //! 1) If the test has been invoked for preamble testing, wait for the preamble-specific
419 //! TRequestStatus to be completed.
421 //! 2) If the test has been invoked for multi-transaction testing, wait for the multi-transaction
422 //! -specific TRequestStatus to be completed.
425 //! @SYMTestExpectedResults 0) Kernel-side proxy client should return with KErrNone, exits otherwise.
426 //! 1) If waiting on the preamble-specific TRequestStatus, it should be set to KErrNone, exists otherwise.
427 //! 2) If waiting on the multi-transaction-specific TRequestStatus, it should be set to KErrNone, exists otherwise.
429 //! @SYMTestPriority High
430 //! @SYMTestStatus Implemented
431 //----------------------------------------------------------------------------------------------
432 LOCAL_C TInt MasterExtTests(TUint8 aFlags)
434 // Exercise the Master Channel API for Preamble functionality
437 // For the multi-transaction test, a bus Master might not know
438 // how much data to write to a Slave until it performs a single read on it.
439 // However, specifying a read separately from the subsequent write
440 // introduces the risk of allowing another transaction to go ahead of the
441 // following write and thus invalidating it. The multi-transaction feature of IIC
442 // allows a callback to be called(in the context of the bus channel) after
443 // the transfers of a preliminary transaction have taken place
444 // (could be a single read), without completing the overall transaction,
445 // then extend the delayed transaction by inserting more transfers
448 gTest.Printf(_L("\n\nStarting MasterExtTests\n"));
452 // Create a transaction that requires preamble support
453 // To prove required operation has executed, make callback complete a TRequestStatus object
454 TRequestStatus preamblestatus;
455 TRequestStatus multitranscstatus;
458 // SPI uses channel numbers 1,2,3 and 4
459 TUint32 busIdSpi = 0;
460 SET_BUS_TYPE(busIdSpi, ESpi);
461 SET_CHAN_NUM(busIdSpi, 1);
462 TConfigSpiBufV01* spiBuf = NULL;
463 // aDeviceId=1 ... 100kHz ... aTimeoutPeriod=100 ... aTransactionWaitCycles=10 - arbitrary paarmeters.
464 r = CreateSpiBuf(spiBuf, ESpiWordWidth_8, 100000,
465 ESpiPolarityLowRisingEdge, 100, ELittleEndian, EMsbFirst, 10,
470 // Use a single transfer
471 _LIT(extText, "Ext Text");
473 extBuf_8.Copy(extText);
474 TUsideTferDesc* tfer = NULL;
475 r = CreateSingleUserSideTransfer(tfer, EMasterRead, 8, &extBuf_8, NULL);
482 // Create the transaction object
483 TUsideTracnDesc* tracn = NULL;
484 r = CreateSingleUserSideTransaction(tracn, ESpi, spiBuf, tfer, NULL,
485 aFlags, (TAny*) &preamblestatus, (TAny*) &multitranscstatus);
494 // Send the transaction to the kernel-side proxy
495 // inline TInt QueueTransaction(TInt aBusId, TUsideTracnDesc* aTransaction)
496 gTest.Printf(_L("\nInvoke synchronous QueueTransaction for preamble test %x\n"), tracn);
498 r = gChanMasterSpi.QueueTransaction(busIdSpi, tracn);
499 gTest.Printf(_L("synchronous QueueTransaction returned = %d\n"), r);
503 // ... and wait for the TRequestStatus object to be completed
504 if (aFlags & KTransactionWithPreamble)
506 User::WaitForRequest(preamblestatus);
507 r = preamblestatus.Int();
510 gTest.Printf(_L("MasterPreambleTests: TRequestStatus completed with = %d\n"), r);
515 if (aFlags & KTransactionWithMultiTransc)
517 User::WaitForRequest(multitranscstatus);
520 gTest.Printf(_L("MasterMultiTranscTests: TRequestStatus completed with = %d\n"), r);
533 LOCAL_C TInt CreateSlaveChanI2cConfig(TConfigI2cBufV01*& aI2cBuf, TUint32& aBusIdI2c, TUint8 aChanNum)
535 // Initialise TConfigI2cBufV01 and the Bus Realisation Config for gChanSlaveI2c.
537 // - token containing the bus realisation variability.
538 // - pointer to a descriptor containing the device specific configuration option applicable to all transactions.
539 // - reference to variable to hold a platform-specific cookie that uniquely identifies the channel instance to be
540 // used by this client
542 SET_BUS_TYPE(aBusIdI2c,EI2c);
543 SET_CHAN_NUM(aBusIdI2c,aChanNum);
545 // clock speed=36Hz, aTimeoutPeriod=100 - arbitrary parameter
546 TInt r=CreateI2cBuf(aI2cBuf, EI2cAddr7Bit, 36, ELittleEndian, 100);
550 LOCAL_C TInt SyncCaptureGChanSlaveI2c(TInt& aChanId, TConfigI2cBufV01* aI2cBuf, TUint32 aBusIdI2c)
552 // Synchronous capture of a Slave channel. Need to provide:
553 // - token containing the bus realisation variability.
554 // - pointer to a descriptor containing the device specific configuration option applicable to all transactions.
555 // - reference to variable to hold a platform-specific cookie that uniquely identifies the channel instance to be used by this client
556 gTest.Printf(_L("\n\nStarting synchronous CaptureChannel \n"));
557 TInt r = gChanSlaveI2c.CaptureChannel(aBusIdI2c, aI2cBuf, aChanId );
558 gTest.Printf(_L("Synchronous CaptureChannel returned = %d, aChanId=0x%x\n"),r,aChanId);
563 LOCAL_C TInt AsyncCaptureGChanSlaveI2c(TInt& aChanId, TConfigI2cBufV01* aI2cBuf, TUint32 aBusIdI2c)
565 // Asynchronous capture of a Slave channel. Need to provide:
566 // - token containing the bus realisation variability.
567 // - pointer to a descriptor containing the device specific configuration option applicable to all transactions.
568 // - reference to variable to hold a platform-specific cookie that uniquely identifies the channel instance to be used by this client
569 // - pointer to TRequestStatus used to indicate operation completion
570 gTest.Printf(_L("\n\nStarting asynchronous CaptureChannel \n"));
571 TRequestStatus status;
572 TInt r = gChanSlaveI2c.CaptureChannel(aBusIdI2c, aI2cBuf, aChanId, status );
574 User::WaitForRequest(status);
576 if(r != KErrCompletion)
578 gTest.Printf(_L("TRequestStatus value after CaptureChannel = %d\n"),r);
579 gTest(r==KErrCompletion);
581 gTest.Printf(_L("Asynchronous CaptureChannel gave aChanId=0x%x\n"),aChanId);
585 //----------------------------------------------------------------------------------------------
586 //! @SYMTestCaseID KBASE-T_IIC-2399
588 //! @SYMPREQ PREQ2128,2129
589 //! @SYMTestCaseDesc This test case tests Slave channel capture and release APIs.
590 //! @SYMTestActions 0) Perform synchronous capture of a channel
592 //! 1) Release the channel
594 //! 2) Perform asynchronous capture of a channel
596 //! 3) Attempt synchronous capture of a channel that is already captured
598 //! 4) Attempt asynchronous capture of a channel that is already captured
600 //! 5) Release the channel
602 //! @SYMTestExpectedResults 0) Kernel-side proxy client should return with KErrCompletion, exits otherwise.
603 //! 1) Kernel-side proxy client should return with KErrNone, exits otherwise.
604 //! 2) Kernel-side proxy client should return with KErrNone, exits otherwise.
605 //! 3) Kernel-side proxy client should return with KErrInUse, exits otherwise.
606 //! 4) Kernel-side proxy client should return with KErrNone, exits otherwise. The associated
607 //! TRequestStatus should be set to KErrInUse, exits otherwise.
608 //! 5) Kernel-side proxy client should return with KErrNone, exits otherwise.
610 //! @SYMTestPriority High
611 //! @SYMTestStatus Implemented
612 //----------------------------------------------------------------------------------------------
613 LOCAL_C TInt SlaveChannelCaptureReleaseTests()
615 // Exercise the Slave Channel API for channel capture and release
618 gTest.Printf(_L("\n\nStarting SlaveChannelCaptureReleaseTests\n"));
622 // Create a I2C configuration buffer and the configuration data for use in capturing gChanSlaveI2c
623 TUint32 busIdI2c = 0;
624 TConfigI2cBufV01* i2cBuf=NULL;
625 r=CreateSlaveChanI2cConfig(i2cBuf, busIdI2c, 11); // 11 is the Slave channel number
628 // Synchronous capture of a Slave channel.
629 TInt chanId = 0; // Initialise to zero to silence compiler ...
630 r=SyncCaptureGChanSlaveI2c(chanId, i2cBuf, busIdI2c);
633 // Release the channel
634 gTest.Printf(_L("\n\nInvoke ReleaseChannel for chanId=0x%x \n"),chanId);
635 r = gChanSlaveI2c.ReleaseChannel( chanId );
636 gTest.Printf(_L("ReleaseChannel returned = %d\n"),r);
639 // Asynchronous capture of a Slave channel.
640 chanId = 0; // Re-initialise to zero to silence compiler ...
641 r=AsyncCaptureGChanSlaveI2c(chanId, i2cBuf, busIdI2c);
644 // Try capturing a slave channel that is already captured
646 // Create another instance of a client, and use to attempt duplicated capture
647 TInt dumChanId = 0; // Initialise to zero to silence compiler ...
648 RBusDevIicClient tempChanSlaveI2c;
649 TBufC<24> proxySlaveName;
650 if(aStandAloneChan == 0)
651 proxySlaveName = KIicProxySlaveFileNameRoot;
653 proxySlaveName = KIicProxySlaveFileNameRootCtrlLess;
654 r = tempChanSlaveI2c.Open(proxySlaveName);
656 r = tempChanSlaveI2c.InitSlaveClient();
659 // Synchronous capture
660 gTest.Printf(_L("\n\nStarting attempted synchronous CaptureChannel of previously-captured channel\n"));
661 r = tempChanSlaveI2c.CaptureChannel(busIdI2c, i2cBuf, dumChanId );
662 gTest.Printf(_L("Synchronous CaptureChannel returned = %d, dumChanId=0x%x\n"),r,dumChanId);
665 // Asynchronous capture
667 gTest.Printf(_L("\n\nStarting attempted asynchronous CaptureChannel of previously-captured channel\n"));
668 TRequestStatus status;
669 r = tempChanSlaveI2c.CaptureChannel(busIdI2c, i2cBuf, dumChanId, status );
671 User::WaitForRequest(status);
675 gTest.Printf(_L("TRequestStatus value after attempted CaptureChannel of previously-captured channel = %d\n"),r);
678 gTest.Printf(_L("Asynchronous CaptureChannel gave dumChanId=0x%x\n"),dumChanId);
680 tempChanSlaveI2c.Close();
682 // Clean up, release the channel
683 r = gChanSlaveI2c.ReleaseChannel( chanId );
684 gTest.Printf(_L("ReleaseChannel returned = %d\n"),r);
689 gTest.Printf(_L("\nSlaveChannelCaptureReleaseTests only supported when SLAVE_MODE is defined\n"));
694 //----------------------------------------------------------------------------------------------
695 //! @SYMTestCaseID KBASE-T_IIC-2400
697 //! @SYMPREQ PREQ2128,2129
698 //! @SYMTestCaseDesc This test case tests Slave channel capture operation for receive and transmit of data
699 //! @SYMTestActions 0) Check that the timeout threshold values can be updated
701 //! 1) Check that an Rx Buffer can be registered, and that a replacement buffer can be registered in its place
702 //! if a notification has not been requested.
704 //! 2) Specify a notification trigger for Rx events
706 //! 3) Attempt to register a replacement Rx buffer
708 //! 4) Use controlIO to instruct the simulated bus to indicate that it has received the required number of words
709 //! and wait for the TRequestStatus to be completed.
711 //! 5) Specify a notification trigger for Rx events, use controlIO to instruct the simulated bus to indicate that
712 //! it has received less than the required number of words and wait for the TRequestStatus to be completed.
714 //! 6) Specify a notification trigger for Rx events, use controlIO to instruct the simulated bus to indicate that
715 //! it has received more than the required number of words and wait for the TRequestStatus to be completed.
717 //! 7) Repeat steps 1-6, but for Tx
719 //! 8) Specify a notification trigger for Rx and Tx events. Use controlIO to instruct the simulated bus to indicate that
720 //! it has received the required number of words, then that it has transmitted the required number of words, and wait
721 //! for the TRequestStatus to be completed.
723 //! 9) Repeat step 8, but simulate Tx, then Rx.
725 //! 10) Specify a notification trigger for bus error events. Use controlIO to instruct the simulated bus to indicate that
726 //! it has encountered a bus error, and wait for the TRequestStatus to be completed.
728 //! 11) Use controlIO to instruct the simulated bus to block Master response. Specify a notification trigger for bus error
729 //! events. Use controlIO to instruct the simulated bus to indicate that it has received more than the required number
730 //! of words. Wait for the TRequestStatus to be completed (with KErrNone). Specify a notification trigger for Tx and
731 //! Tx Overrun, then use controlIO to instruct the simulated bus to unblock Master responses.Wait for the TRequestStatus
734 //! @SYMTestExpectedResults 0) Kernel-side proxy client should return with KErrNone, exits otherwise.
735 //! 1) Kernel-side proxy client should return with KErrNone, exits otherwise.
736 //! 2) Kernel-side proxy client should return with KErrNone, exits otherwise.
737 //! 3) Kernel-side proxy client should return with KErrAlreadyExists, exits otherwise.
738 //! 4) Kernel-side proxy client should return with KErrNone, exits otherwise. The associated
739 //! TRequestStatus should be set to KErrNone, exits otherwise.
740 //! 5) Kernel-side proxy client should return with KErrNone for both API calls, exits otherwise. The associated
741 //! TRequestStatus should be set to KErrNone, exits otherwise.
742 //! 6) Kernel-side proxy client should return with KErrNone for both API calls, exits otherwise. The associated
743 //! TRequestStatus should be set to KErrNone, exits otherwise.
744 //! 7) Results should be the same as for steps 1-6.
745 //! 8) Kernel-side proxy client should return with KErrNone for each API call, exits otherwise. The associated
746 //! TRequestStatus should be set to KErrNone, exits otherwise.
747 //! 9) Kernel-side proxy client should return with KErrNone for each API call, exits otherwise. The associated
748 //! TRequestStatus should be set to KErrNone, exits otherwise.
749 //! 10) Kernel-side proxy client should return with KErrNone for each API call, exits otherwise. The associated
750 //! TRequestStatus should be set to KErrNone, exits otherwise.
751 //! 11) Kernel-side proxy client should return with KErrNone for each API call, exits otherwise. The associated
752 //! TRequestStatus should be set to KErrNone in both cases, exits otherwise.
754 //! @SYMTestPriority High
755 //! @SYMTestStatus Implemented
756 //----------------------------------------------------------------------------------------------
758 LOCAL_C TInt SlaveRxTxNotificationTests()
760 // Exercise the Slave channel operation for receive and transmit of data
763 // The means to supply a buffer to be filled with data received from the Master, and the number of words expected.
764 // It is only after the reception of the number of words specified that the notification should be issued
765 // (or on under-run/overrun/timeout/bus specific error).
767 // The means to supply a buffer with data to be transmitted to the Master, and the number of words to transmit.
768 // It is only after the transmission of the number of words specified that the notification should be issued
769 // (or under-run/overrun/timeout/bus specific error).
771 // The means to enable and disable the events which will trigger the notification callback. These events are:
772 // 1) the complete reception of the number of words specified,
773 // 2) the complete transmission of the number of words specified,
774 // 3) errors: receive buffer under-run (the Master terminates the transaction or reverts the direction of
775 // transfer before all expected data has been received), receive buffer overrun
776 // (Master attempts to write more data than this channel expected to receive), transmit buffer overrun
777 // (Master attempts to read more data than supplied by client), transmit buffer under-run
778 // (the Master terminates the transaction or reverts the direction of transfer before all expected data
779 // has been transmitted to it), access timeout(1) error, or bus specific error (e.g. collision, framing).
781 gTest.Printf(_L("\n\nStarting SlaveRxTxNotificationTests\n"));
785 //Configure and capture a channel
786 gTest.Printf(_L("Create and capture channel\n"));
788 TConfigI2cBufV01* i2cBuf=NULL;
789 r=CreateSlaveChanI2cConfig(i2cBuf, busIdI2c, 11); // 11 is the Slave channel number
792 TInt chanId = 0; // Initialise to zero to silence compiler ...
793 r=SyncCaptureGChanSlaveI2c(chanId, i2cBuf, busIdI2c);
796 // Update wait times for Master and Client
797 // Delegate the operation of this test to the proxy client (iic_client). The proxy will read, modify, and reinstate
798 // the timeout values.
799 gTest.Printf(_L("Starting UpdateTimeoutValues\n"));
800 r=gChanSlaveI2c.UpdateTimeoutValues(busIdI2c, chanId);
804 // Receive and transmit buffers must be created by the client in Kernel heap and remain in their ownership throughout.
805 // Therefore, the kernel-side proxy will provide the buffer
806 // The buffers are of size KRxBufSizeInBytes and KRxBufSizeInBytes (currently 64)
812 // For Rx, specify buffer granularity=4 (32-bit words), 8 words to receive, offset of 16 bytes
813 // 64 bytes as 16 words: words 0-3 offset, words 4-11 data, words 12-15 unused
814 gTest.Printf(_L("Starting RegisterRxBuffer\n"));
815 r=gChanSlaveI2c.RegisterRxBuffer(chanId, 4, 8, 16);
818 // If a buffer is already registered but a notification has not yet been requested the API should return KErrNone
819 gTest.Printf(_L("Starting (repeated) RegisterRxBuffer\n"));
820 r=gChanSlaveI2c.RegisterRxBuffer(chanId, 4, 8, 16);
823 // Now set the notification trigger
824 TRequestStatus status;
825 TInt triggerMask=ERxAllBytes;
826 gTest.Printf(_L("Starting SetNotificationTrigger with ERxAllBytes\n"));
827 r=gChanSlaveI2c.SetNotificationTrigger(chanId,triggerMask,&status);
830 // If a buffer is registered and a notification has been requested the API should return KErrAlreadyExists
831 gTest.Printf(_L("Starting RegisterRxBuffer (to be rejected)\n"));
832 r=gChanSlaveI2c.RegisterRxBuffer(chanId, 4, 8, 16);
833 gTest(r==KErrAlreadyExists);
835 // Now instruct the bus implementation to represent receipt of the required number of words from the bus master.
836 gTest.Printf(_L("Starting SimulateRxNWords\n"));
837 r=gChanSlaveI2c.SimulateRxNWords(busIdI2c, chanId, 8);
840 // Wait for the notification
841 User::WaitForRequest(status);
845 gTest.Printf(_L("TRequestStatus value after receiving data = %d\n"),r);
848 gTest.Printf(_L("Starting Rx test completed OK\n"));
850 // Repeat for each error condition. Re-use the buffer previously registered.
853 triggerMask=ERxAllBytes|ERxUnderrun;
854 gTest.Printf(_L("Starting SetNotificationTrigger with ERxAllBytes\n"));
855 r=gChanSlaveI2c.SetNotificationTrigger(chanId,triggerMask,&status);
857 // Now instruct the bus implementation to represent the bus master transmitting less words than anticipated (Rx Underrun)
858 gTest.Printf(_L("Starting SimulateRxNWords for Underrun\n"));
859 r=gChanSlaveI2c.SimulateRxNWords(busIdI2c, chanId, 6);
862 // Wait for the notification
863 User::WaitForRequest(status);
867 gTest.Printf(_L("TRequestStatus value after receiving data = %d\n"),r);
870 gTest.Printf(_L("Rx Underrun test completed OK\n"));
871 // Re-set the notification trigger
872 triggerMask=ERxAllBytes|ERxOverrun;
873 gTest.Printf(_L("Starting SetNotificationTrigger\n"));
874 r=gChanSlaveI2c.SetNotificationTrigger(chanId,triggerMask,&status);
876 // Now instruct the bus implementation to represent the bus master attempting to transmit more words than
877 // anticipated (Rx Overrun)
878 gTest.Printf(_L("Starting SimulateRxNWords for Overrun\n"));
879 r=gChanSlaveI2c.SimulateRxNWords(busIdI2c, chanId, 10);
882 // Wait for the notification
883 User::WaitForRequest(status);
887 gTest.Printf(_L("TRequestStatus value after receiving data = %d\n"),r);
890 gTest.Printf(_L("Rx Overrun test completed OK\n"));
896 // For Tx, specify buffer granularity=4 (32-bit words), 12 words to transmit, offset of 8 bytes
897 // 64 bytes as 16 words: words 0-1 offset, words 2-13 data, words 14-15 unused
898 gTest.Printf(_L("\nStarting RegisterTxBuffer\n"));
899 r=gChanSlaveI2c.RegisterTxBuffer(chanId, 4, 12, 8);
902 // If a buffer is already registered but a notification has not yet been requested the API should return KErrNone
903 gTest.Printf(_L("Starting (repeated) RegisterTxBuffer\n"));
904 r=gChanSlaveI2c.RegisterTxBuffer(chanId, 4, 12, 8);
908 // Re-set the notification trigger
909 // Now set the notification trigger
910 gTest.Printf(_L("Starting SetNotificationTrigger\n"));
911 triggerMask=ETxAllBytes;
912 r=gChanSlaveI2c.SetNotificationTrigger(chanId,triggerMask,&status);
915 // If a buffer is already registered, a subsequent request to do the same should return KErrAlreadyExists
916 gTest.Printf(_L("Starting RegisterTxBuffer (to be rejected)\n"));
917 r=gChanSlaveI2c.RegisterTxBuffer(chanId, 4, 12, 8);
918 gTest(r==KErrAlreadyExists);
920 // Now instruct the bus implementation to represent transmission of the required number of words to the bus master.
921 gTest.Printf(_L("Starting SimulateTxNWords (to be rejected)\n"));
922 r=gChanSlaveI2c.SimulateTxNWords(busIdI2c, chanId, 12);
925 // Wait for the notification
926 User::WaitForRequest(status);
930 gTest.Printf(_L("TRequestStatus value after transmitting data = %d\n"),r);
933 gTest.Printf(_L("Tx test completed OK\n"));
935 // Repeat for each error condition. Re-use the buffer previously registered
937 // Re-set the notification trigger
938 gTest.Printf(_L("Starting SetNotificationTrigger\n"));
939 triggerMask=ETxAllBytes|ETxOverrun;
940 r=gChanSlaveI2c.SetNotificationTrigger(chanId,triggerMask,&status);
942 // Now instruct the bus implementation to represent transmission of less than the required number of words
943 // to the bus master (Tx Overrun)
944 gTest.Printf(_L("Starting SimulateTxNWords for Tx Overrun\n"));
945 r=gChanSlaveI2c.SimulateTxNWords(busIdI2c, chanId, 10);
948 // Wait for the notification
949 User::WaitForRequest(status);
953 gTest.Printf(_L("TRequestStatus value after transmitting data = %d\n"),r);
956 gTest.Printf(_L("Tx Overrun test completed OK\n"));
957 // Re-set the notification trigger
958 triggerMask=ETxAllBytes|ETxUnderrun;
959 gTest.Printf(_L("Starting SetNotificationTrigger\n"));
960 r=gChanSlaveI2c.SetNotificationTrigger(chanId,triggerMask,&status);
962 // Now instruct the bus implementation to represent the bus master attempting to read more words than
963 // anticipated (Tx Underrun)
964 gTest.Printf(_L("Starting SimulateTxNWords for Tx Underrun\n"));
965 r=gChanSlaveI2c.SimulateTxNWords(busIdI2c, chanId, 14);
968 // Wait for the notification
969 User::WaitForRequest(status);
973 gTest.Printf(_L("TRequestStatus value after transmitting data = %d\n"),r);
976 gTest.Printf(_L("Tx Underrun test completed OK\n"));
979 // Simultaneous Rx,Tx tests
981 // For these tests, the proxy client (iic_slaveclient) will check that the expected results are witnessed
982 // in the required order, and will complete the TRequestStatus when the sequence is complete (or error occurs).
984 // Set the notification trigger for both Rx and Tx
985 triggerMask=ERxAllBytes|ETxAllBytes;
986 gTest.Printf(_L("\nStarting SetNotificationTrigger with ERxAllBytes|ETxAllBytes\n"));
987 r=gChanSlaveI2c.SetNotificationTrigger(chanId,triggerMask,&status);
989 // Now instruct the bus implementation to represent receipt of the required number of words from the bus master.
990 gTest.Printf(_L("Starting SimulateRxNWords\n"));
991 r=gChanSlaveI2c.SimulateRxNWords(busIdI2c, chanId, 8);
993 // Now instruct the bus implementation to represent transmission of the required number of words to the bus master.
994 gTest.Printf(_L("Starting SimulateTxNWords\n"));
995 r=gChanSlaveI2c.SimulateTxNWords(busIdI2c, chanId, 12);
998 // Wait for the notification
999 User::WaitForRequest(status);
1003 gTest.Printf(_L("TRequestStatus value after receiving and transmitting data = %d\n"),r);
1006 gTest.Printf(_L("Rx, Tx test completed OK\n"));
1008 // Set the notification trigger for both Rx and Tx
1009 gTest.Printf(_L("Starting SetNotificationTrigger with ERxAllBytes|ETxAllBytes\n"));
1010 triggerMask=ERxAllBytes|ETxAllBytes;
1011 r=gChanSlaveI2c.SetNotificationTrigger(chanId,triggerMask,&status);
1013 // Now instruct the bus implementation to represent transmission of the required number of words to the bus master.
1014 gTest.Printf(_L("Starting SimulateTxNWords\n"));
1015 r=gChanSlaveI2c.SimulateTxNWords(busIdI2c, chanId, 12);
1017 // Now instruct the bus implementation to represent receipt of the required number of words from the bus master.
1018 gTest.Printf(_L("Starting SimulateRxNWords\n"));
1019 r=gChanSlaveI2c.SimulateRxNWords(busIdI2c, chanId, 8);
1022 // Wait for the notification
1023 User::WaitForRequest(status);
1027 gTest.Printf(_L("TRequestStatus value after receiving and transmitting data = %d\n"),r);
1030 gTest.Printf(_L("Tx, Rx test completed OK\n"));
1032 // Set the notification trigger for both Rx and Tx
1033 gTest.Printf(_L("Starting SetNotificationTrigger with ERxAllBytes|ETxAllBytes\n"));
1034 triggerMask=ERxAllBytes|ETxAllBytes;
1035 r=gChanSlaveI2c.SetNotificationTrigger(chanId,triggerMask,&status);
1037 // Now instruct the bus implementation to represent simultaneous transmission of the required number of words (12)
1038 // to the bus master and receipt of the required number of words (8) from the bus master
1039 gTest.Printf(_L("Starting SimulateRxTxNWords\n"));
1040 r=gChanSlaveI2c.SimulateRxTxNWords(busIdI2c, chanId, 8, 12);
1043 // Wait for the notification
1044 User::WaitForRequest(status);
1048 gTest.Printf(_L("TRequestStatus value after receiving and transmitting data = %d\n"),r);
1051 gTest.Printf(_L("Tx with Rx test completed OK\n"));
1053 // Clear the trigger mask - this is just invoking SetNotificationTrigger with a zero trigger
1054 // so that no subsequent triggers are expected (and so no TRequestStatus is provided)
1055 gTest.Printf(_L("Starting SetNotificationTrigger with 0\n"));
1057 r=gChanSlaveI2c.SetNotifNoTrigger(chanId,triggerMask);
1061 // Rx Overrun and Tx Underrun when both Rx and Tx notifications are requested
1063 gTest.Printf(_L("Starting RxOverrun-TxUnderrun with simultaneous Rx,Tx notification requests\n"));
1064 gChanSlaveI2c.TestOverrunUnderrun(busIdI2c,chanId,status);
1066 // Wait for the notification
1067 User::WaitForRequest(status);
1071 gTest.Printf(_L("TRequestStatus value after RxOverrun-TxUnderrun with simultaneous Rx,Tx notification requests= %d\n"),r);
1074 gTest.Printf(_L("RxOverrun-TxUnderrun with simultaneous Rx,Tx notification requests test completed OK\n"));
1081 // Simulate a bus error
1082 // A bus error will cause all pending bus activity to be aborted.
1083 // Request a notification, then simulate a bus error
1084 triggerMask=ERxAllBytes|ETxAllBytes;
1085 r=gChanSlaveI2c.SetNotificationTrigger(chanId,triggerMask,&status);
1087 gTest.Printf(_L("Starting SimulateBusErr\n"));
1088 r = gChanSlaveI2c.SimulateBusErr(busIdI2c,chanId);
1091 // Wait for the notification
1092 User::WaitForRequest(status);
1096 gTest.Printf(_L("TRequestStatus value after receiving data = %d\n"),r);
1099 gTest.Printf(_L("Bus error test completed OK\n"));
1101 // Clear the trigger mask and prepare for the next test
1102 // This is unnecessary if the SetNotificationTrigger for the following test
1103 // is called within the timeout period applied for Client responses ...
1104 // but it represents a Client ending a transaction cleanly, and so is
1105 // left here as an example
1106 gTest.Printf(_L("\nStarting SetNotificationTrigger with 0\n"));
1108 r=gChanSlaveI2c.SetNotificationTrigger(chanId,triggerMask,&status);
1111 // Simulate Master timeout
1113 // - Requesting a trigger for Tx
1114 // - simulating the Master performing a read (ie the PSL indicates a Tx event) to start the transaction
1115 // - provide a buffer for Tx, and request notification of Tx events, ie wait for Master response
1116 // - block the PSL Tx notification to the PIL, so that the PIL timeout timer expires when a simulated Tx event
1117 // is next requested
1119 // Indicate the test to be performed
1120 gTest.Printf(_L("\nStarting BlockNotification\n"));
1121 // Register a buffer for Tx, then set the notification trigger
1122 gTest.Printf(_L("RegisterTxBuffer - for Master to start the transaction\n"));
1123 r=gChanSlaveI2c.RegisterTxBuffer(chanId, 4, 12, 8);
1125 gTest.Printf(_L("SetNotificationTrigger - for Master to start the transaction\n"));
1126 triggerMask=ETxAllBytes;
1127 r=gChanSlaveI2c.SetNotificationTrigger(chanId,triggerMask,&status);
1129 // Now instruct the bus implementation to simulate the Master reading the expected number of words
1130 gTest.Printf(_L("Starting SimulateTxNWords\n"));
1131 r=gChanSlaveI2c.SimulateTxNWords(busIdI2c, chanId, 12);
1133 // Wait for the notification
1134 User::WaitForRequest(status);
1135 gTest.Printf(_L("Status request completed\n"));
1139 gTest.Printf(_L("TRequestStatus value after receiving data = %d\n"),r);
1142 // Client is now expected to perform its part of the transaction - so pretend we need another Tx
1143 // - but block completion of the Tx so that we generate a bus error
1144 gTest.Printf(_L("SetNotificationTrigger - for second part of the transaction\n"));
1145 triggerMask=ETxAllBytes;
1146 r=gChanSlaveI2c.SetNotificationTrigger(chanId,triggerMask,&status);
1148 gTest.Printf(_L("BlockNotification\n"));
1149 r=gChanSlaveI2c.BlockNotification(busIdI2c, chanId);
1151 // Now instruct the bus implementation to represent the bus master attempting to read the required number of words
1152 gTest.Printf(_L("\nStarting SimulateTxNWords\n"));
1153 r=gChanSlaveI2c.SimulateTxNWords(busIdI2c, chanId, 12);
1156 // Wait for the notification
1157 User::WaitForRequest(status);
1161 gTest.Printf(_L("TRequestStatus value after receiving data = %d\n"),r);
1164 gTest.Printf(_L("Blocked notification test completed OK\n"));
1165 // Re-set the notification trigger - for the 'blocked' Tx
1166 // This is required because, in the event of a bus error, the set of requested Rx,Tx
1167 // flags are cleared
1168 gTest.Printf(_L("Starting SetNotificationTrigger with ETxAllBytes\n"));
1169 triggerMask=ETxAllBytes;
1170 r=gChanSlaveI2c.SetNotificationTrigger(chanId,triggerMask,&status);
1173 gTest.Printf(_L("Starting UnblockNotification\n"));
1174 r=gChanSlaveI2c.UnblockNotification(busIdI2c, chanId);
1177 // Wait for the notification
1178 User::WaitForRequest(status);
1182 gTest.Printf(_L("TRequestStatus value after receiving data = %d\n"),r);
1185 gTest.Printf(_L("UnBlocked notification test completed OK\n"));
1186 // Clear the trigger mask
1187 gTest.Printf(_L("Starting SetNotificationTrigger with 0\n"));
1189 r=gChanSlaveI2c.SetNotificationTrigger(chanId,triggerMask,&status);
1192 // Release the channel
1193 r = gChanSlaveI2c.ReleaseChannel( chanId );
1198 gTest.Printf(_L("\nSlaveRxTxNotificationTests only supported when SLAVE_MODE is defined\n"));
1204 //----------------------------------------------------------------------------------------------
1205 //! @SYMTestCaseID KBASE-T_IIC-2404
1207 //! @SYMPREQ PREQ2128,2129
1208 //! @SYMTestCaseDesc This test case tests that MasterSlave channels can only be used in one mode at a time, and that
1209 //! if captured for Slave operation or with transactions queued for Master operation the channel can
1210 //! not be de-registered.
1211 //! @SYMTestActions 0) Capture the channel for Slave operation. Attempt to synchronously queue a transaction
1212 //! on the channel. Attempt to asynchronously queue a transaction on the channel. Attempt
1213 //! to de-register the channel.Release the Slave channel
1215 //! 1) Use controlio to block completion of queued transactions. Request asynchronous queue
1216 //! transaction. Attempt to capture the channel for Slave operation. Attempt to de-register
1217 //! the channel. Unblock completion of transactions and wait for the TRequestStatus for the
1218 //! transaction to be completed.
1220 //! @SYMTestExpectedResults 0) Once captured for Slave operation, attempts to queue a transaction or de-register the channel
1221 //! return KErrInUse, exits otherwise.
1222 //! 1) With a transaction queued, attempt to capture the channel returns KErrInUse, exits otherwise.
1223 //! Attempt to de-register channel returns KErrInUse, exits otherwise. The TRequestStatus should
1224 //! be set to KErrTimedOut, exits otherwise.
1227 //! @SYMTestPriority High
1228 //! @SYMTestStatus Implemented
1229 //----------------------------------------------------------------------------------------------
1230 LOCAL_C TInt MasterSlaveAcquisitionTests()
1232 // Test to check that:
1233 // (1) A Master-Slave channel that has been captured for use in Slave mode will not allow requests for
1234 // queing transactions to be accepted
1235 // (2) A Master-Slave channel that has been captured for use in Slave mode can not be de-registered
1236 // (3) A Master-Slave channel that has one or more transactions queued in its Master channel transaction queue
1237 // can not be captured for use in Slave Made
1238 // (4) A Master-Slave channel that has one or more transactions queued in its Master channel transaction queue
1239 // can not be de-registered
1242 gTest.Printf(_L("\n\nStarting MasterSlaveAcquisitionTests\n"));
1245 #if defined(MASTER_MODE) && defined(SLAVE_MODE)
1246 // Create a Master-Slave channel
1247 RBusDevIicClient chanMasterSlaveI2c;
1248 TBufC<18> proxyName;
1249 if(!aStandAloneChan)
1250 proxyName = KIicProxyFileNameRoot;
1252 proxyName = KIicProxyFileNameRootCtrlLess;
1253 r = chanMasterSlaveI2c.Open(proxyName);
1255 r = chanMasterSlaveI2c.InitSlaveClient(); // Initialise callback used for Slave processing
1258 // Capture the channel for Slave operation
1259 // Attempt to synchronously queue a transaction on the channel - expect KErrInUse as a response
1260 // Attempt to asynchronously queue a transaction on the channel - expect KErrInUse as a response
1261 // Attempt to de-register the channel - expect KErrInUse as a response
1262 // Release the Slave channel
1264 // Create a I2C configuration buffer and the configuration data for use in capturing gChanSlaveI2c
1265 TUint32 busIdI2c = 0;
1266 TConfigI2cBufV01* i2cBuf=NULL;
1267 r=CreateSlaveChanI2cConfig(i2cBuf, busIdI2c, 12); // 12 is the MasterSlave channel number
1271 gTest.Printf(_L("\nStarting synchronous CaptureChannel \n"));
1272 r = chanMasterSlaveI2c.CaptureChannel(busIdI2c, i2cBuf, chanId );
1273 gTest.Printf(_L("Synchronous CaptureChannel returned = %d, chanId=0x%x\n"),r,chanId);
1276 _LIT(halfDuplexText,"Half Duplex Text");
1277 TBuf8<17> halfDuplexBuf_8;
1278 halfDuplexBuf_8.Copy(halfDuplexText);
1279 TUsideTferDesc* tfer = NULL;
1280 r=CreateSingleUserSideTransfer(tfer, EMasterWrite, 8, &halfDuplexBuf_8, NULL);
1286 TUsideTracnDesc* tracn = NULL;
1287 r = CreateSingleUserSideTransaction(tracn, EI2c, i2cBuf, tfer, NULL, 0, NULL, NULL);
1294 gTest.Printf(_L("\nStarting synchronous QueueTransaction \n"));
1295 r = chanMasterSlaveI2c.QueueTransaction(busIdI2c, tracn);
1296 gTest.Printf(_L("Synchronous QueueTransaction returned = %d\n"),r);
1297 gTest(r==KErrInUse);
1298 gTest.Printf(_L("\nStarting asynchronous QueueTransaction \n"));
1299 TRequestStatus status;
1300 chanMasterSlaveI2c.QueueTransaction(status, busIdI2c, tracn);
1301 User::WaitForRequest(status);
1302 if(status != KErrInUse)
1304 gTest.Printf(_L("TRequestStatus value after queue = %d\n"),status.Int());
1305 gTest(r==KErrInUse);
1308 // // If it is stand-alone channel, the client is responsible for channel creation.
1309 // // So the RegisterChan and DeRegisterChan are not needed.
1310 if(aStandAloneChan == 0)
1312 gTest.Printf(_L("\nStarting deregistration of captured channel\n"));
1313 r = chanMasterSlaveI2c.DeRegisterChan(busIdI2c);
1314 gTest.Printf(_L("DeRegisterChan returned = %d\n"),r);
1315 gTest(r==KErrInUse);
1318 gTest.Printf(_L("\nInvoke ReleaseChannel for chanId=0x%x \n"),chanId);
1319 r = chanMasterSlaveI2c.ReleaseChannel( chanId );
1320 gTest.Printf(_L("ReleaseChannel returned = %d\n"),r);
1324 // Use ControlIO/StaticExtension to block transactions on the Master Channel
1325 // Queue an asynchronous transaction on the channel
1326 // Attempt to capture the channel for Slave operation - expect KErrInUse as a response
1327 // Attempt to de-register the channel - expect KErrInUse as a response
1328 // Unblock the channel
1329 // Check for (timed out) completion of the transaction
1331 gTest.Printf(_L("Invoking BlockReqCompletion\n"));
1332 r = chanMasterSlaveI2c.BlockReqCompletion(busIdI2c);
1333 gTest.Printf(_L("BlockReqCompletion returned = %d\n"),r);
1335 gTest.Printf(_L("Queueing first transaction \n"));
1336 chanMasterSlaveI2c.QueueTransaction(status, busIdI2c, tracn);
1340 gTest.Printf(_L("\nStarting synchronous CaptureChannel \n"));
1341 r = chanMasterSlaveI2c.CaptureChannel(busIdI2c, i2cBuf, chanId );
1342 gTest.Printf(_L("Synchronous CaptureChannel returned = %d, chanId=0x%x\n"),r,chanId);
1343 gTest(r==KErrInUse);
1345 // If it is stand-alone channel, the client is responsible for channel creation.
1346 // So the RegisterChan and DeRegisterChan are not needed.
1347 if(aStandAloneChan == 0)
1349 gTest.Printf(_L("\nStarting deregistration of channel\n"));
1350 r = chanMasterSlaveI2c.DeRegisterChan(busIdI2c);
1351 gTest.Printf(_L("DeRegisterChan returned = %d\n"),r);
1352 gTest(r==KErrInUse);
1354 gTest.Printf(_L("Invoking UnlockReqCompletion\n"));
1355 r = chanMasterSlaveI2c.UnblockReqCompletion(busIdI2c);
1356 gTest.Printf(_L("UnblockReqCompletion returned = %d\n"),r);
1360 User::WaitForRequest(status);
1362 if(r != KErrTimedOut)
1364 gTest.Printf(_L("TRequestStatus value after queue = %d\n"),r);
1365 gTest(r==KErrTimedOut);
1367 r=KErrNone; // Ensure error code is not propagated
1372 chanMasterSlaveI2c.Close();
1374 gTest.Printf(_L("\nMasterSlaveAcquisitionTests only supported when both MASTER_MODE and SLAVE_MODE are defined\n"));
1380 //----------------------------------------------------------------------------------------------
1381 //! @SYMTestCaseID KBASE-T_IIC-2404
1383 //! @SYMDEF DEF141732
1384 //! @SYMTestCaseDesc This test case tests the inline functions of DIicBusChannel interface.
1385 //! @SYMTestActions Call Kernel-side proxy client function to perform interface tests.
1386 //! @SYMTestExpectedResults Kernel-side proxy client should return with KErrNone.
1387 //! @SYMTestPriority Medium
1388 //! @SYMTestStatus Implemented
1389 //----------------------------------------------------------------------------------------------
1390 LOCAL_C TInt IicInterfaceInlineTests()
1392 if(aStandAloneChan == 1)
1394 gTest.Printf(_L("\n\nStarting IicInterfaceInlineTests\n"));
1396 r = gChanMasterSpi.TestIiicChannelInlineFunc();
1401 gTest.Printf(_L("\nIicInterfaceInlineTests can only be run in Standalone mode\n"));
1406 LOCAL_C TInt RunTests()
1408 // Utility method to invoke the separate tests
1412 r = IicInterfaceInlineTests();
1416 r = MasterBasicTests();
1420 r = SlaveRxTxNotificationTests();
1424 r = SlaveChannelCaptureReleaseTests();
1428 r = MasterExtTests(KTransactionWithPreamble);
1432 r = MasterExtTests(KTransactionWithMultiTransc);
1436 r = MasterExtTests(KTransactionWithMultiTransc|KTransactionWithPreamble);
1440 r = MasterTransactionTests();
1444 r = MasterSlaveAcquisitionTests();
1451 GLDEF_C TInt E32Main()
1457 gTest.Start(_L("Test IIC API\n"));
1461 // Turn off lazy dll unloading
1463 gTest(l.Connect()==KErrNone);
1464 gTest(l.CancelLazyDllUnload()==KErrNone);
1467 #ifdef IIC_SIMULATED_PSL
1468 gTest.Next(_L("Start the IIC with controller test\n"));
1469 aStandAloneChan = 0;
1470 gTest.Next(_L("Load Simulated IIC PSL bus driver"));
1471 r = User::LoadPhysicalDevice(KIicPslFileName);
1472 gTest.Printf(_L("return value r=%d"),r);
1473 gTest(r==KErrNone || r==KErrAlreadyExists);
1475 gTest.Next(_L("Load Simulated PSL SPI bus driver"));
1476 r = User::LoadPhysicalDevice(KSpiFileName);
1477 gTest.Printf(_L("return value r=%d"),r);
1478 gTest(r==KErrNone || r==KErrAlreadyExists);
1480 gTest.Next(_L("Load Simulated PSL I2C bus driver"));
1481 r = User::LoadPhysicalDevice(KI2cFileName);
1482 gTest.Printf(_L("return value r=%d"),r);
1483 gTest(r==KErrNone || r==KErrAlreadyExists);
1485 gTest.Next(_L("Load kernel-side proxy IIC client"));
1486 r = User::LoadLogicalDevice(KIicProxyFileName);
1487 gTest(r==KErrNone || r==KErrAlreadyExists);
1489 gTest.Next(_L("Load kernel-side proxy IIC slave client"));
1490 r = User::LoadLogicalDevice(KIicProxySlaveFileName);
1491 gTest(r==KErrNone || r==KErrAlreadyExists);
1494 // First ascertain what bus options are available.
1496 // SPI has Master channel numbers 1,2 and 4, Slave channel number 3
1497 // Open a Master SPI channel to the kernel side proxy
1498 TBufC<30> proxyName(KIicProxyFileNameRoot);
1499 r = gChanMasterSpi.Open(proxyName);
1502 // I2C has Master channel numbers 10 and 11, if built with MASTER_MODE, only
1503 // I2C has Slave channel numbers 12 and 13, if built with SLAVE_MODE, only
1504 // I2C has Master channel number 10 and Slave channel numer 11 if built with both MASTER_MODE and SLAVE_MODE
1505 // Open a Master I2C channel to the kernel side proxy
1506 r = gChanMasterI2c.Open(proxyName);
1508 TBufC<15> proxySlaveName(KIicProxySlaveFileNameRoot);
1509 r = gChanSlaveI2c.Open(proxySlaveName);
1511 r = gChanSlaveI2c.InitSlaveClient();
1518 gTest.Printf(_L("Tests completed OK, about to close channel\n"));
1520 gChanMasterSpi.Close();
1521 gChanMasterI2c.Close();
1522 gChanSlaveI2c.Close();
1524 UserSvr::HalFunction(EHalGroupKernel, EKernelHalSupervisorBarrier, 0, 0);
1527 gTest.Next(_L("Free kernel-side proxy IIC client"));
1528 TInt err = User::FreeLogicalDevice(KIicProxyFileNameRoot);
1529 gTest(err==KErrNone || err==KErrAlreadyExists);
1531 gTest.Next(_L("Free kernel-side proxy IIC slave client"));
1532 err = User::FreeLogicalDevice(KIicProxySlaveFileNameRoot);
1533 gTest(err==KErrNone || err==KErrAlreadyExists);
1535 gTest.Next(_L("Free Simulated PSL I2C bus driver"));
1536 err = User::FreePhysicalDevice(KI2cFileName);
1537 gTest(err==KErrNone);
1539 gTest.Next(_L("Free Simulated PSL SPI bus driver"));
1540 err = User::FreePhysicalDevice(KSpiFileName);
1541 gTest(err==KErrNone);
1543 gTest.Next(_L("Free Simulated IIC PSL bus driver"));
1544 err = User::FreePhysicalDevice(KIicPslFileNameRoot);
1545 gTest(err==KErrNone);
1547 gTest.Next(_L("Start the controller-less IIC test\n"));
1548 aStandAloneChan = 1;
1550 gTest.Next(_L("Load Simulated PSL SPI bus driver"));
1551 r = User::LoadPhysicalDevice(KSpiFileNameCtrlLess);
1552 gTest.Printf(_L("return value r=%d"),r);
1553 gTest(r==KErrNone || r==KErrAlreadyExists);
1555 gTest.Next(_L("Load Simulated PSL I2C bus driver"));
1556 r = User::LoadPhysicalDevice(KI2cFileNameCtrlLess);
1557 gTest.Printf(_L("return value r=%d"),r);
1558 gTest(r==KErrNone || r==KErrAlreadyExists);
1560 gTest.Next(_L("Load kernel-side proxy IIC client"));
1561 r = User::LoadLogicalDevice(KIicProxyFileNameCtrlLess);
1562 gTest(r==KErrNone || r==KErrAlreadyExists);
1564 gTest.Next(_L("Load kernel-side proxy IIC slave client"));
1565 r = User::LoadLogicalDevice(KIicProxySlaveFileNameCtrlLess);
1566 gTest(r==KErrNone || r==KErrAlreadyExists);
1568 // First ascertain what bus options are available.
1570 // SPI has Master channel numbers 1,2 and 4, Slave channel number 3
1571 // Open a Master SPI channel to the kernel side proxy
1572 TBufC<30> proxyNameCtrlLess(KIicProxyFileNameRootCtrlLess);
1573 r = gChanMasterSpi.Open(proxyNameCtrlLess);
1576 // I2C has Master channel numbers 10 and 11, if built with MASTER_MODE, only
1577 // I2C has Slave channel numbers 12 and 13, if built with SLAVE_MODE, only
1578 // I2C has Master channel number 10 and Slave channel numer 11 if built with both MASTER_MODE and SLAVE_MODE
1579 // Open a Master I2C channel to the kernel side proxy
1580 r = gChanMasterI2c.Open(proxyNameCtrlLess);
1583 TBufC<35> proxySlaveNameCtrlLess(KIicProxySlaveFileNameRootCtrlLess);
1585 r = gChanSlaveI2c.Open(proxySlaveNameCtrlLess);
1587 r = gChanSlaveI2c.InitSlaveClient();
1594 gTest.Printf(_L("Tests completed OK, about to close channel\n"));
1596 gChanMasterSpi.Close();
1597 gChanMasterI2c.Close();
1598 gChanSlaveI2c.Close();
1600 UserSvr::HalFunction(EHalGroupKernel, EKernelHalSupervisorBarrier, 0, 0);
1603 gTest.Next(_L("Free kernel-side proxy IIC client"));
1605 err = User::FreeLogicalDevice(KIicProxyFileNameRootCtrlLess);
1606 gTest(err==KErrNone || err==KErrAlreadyExists);
1607 gTest.Next(_L("Free kernel-side proxy IIC slave client"));
1608 err = User::FreeLogicalDevice(KIicProxySlaveFileNameRootCtrlLess);
1609 gTest(err==KErrNone || err==KErrAlreadyExists);
1611 gTest.Next(_L("Free Simulated PSL I2C bus driver"));
1612 err = User::FreePhysicalDevice(KI2cFileNameCtrlLess);
1613 gTest(err==KErrNone);
1615 gTest.Next(_L("Free Simulated PSL SPI bus driver"));
1616 err = User::FreePhysicalDevice(KSpiFileNameCtrlLess);
1617 gTest(err==KErrNone);
1619 gTest.Printf(_L("Don't do the test if it is not IIC_SIMULATED_PSL"));