sl@0: // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // e32test/iic/t_iic.cpp sl@0: // sl@0: sl@0: // This file interacts with test-specific LDD to instigate tests of functionality sl@0: // that would normally be invoked by kernel-side device driver clients of the IIC. sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include "t_iic.h" sl@0: sl@0: //for memory leak checking sl@0: #include sl@0: #include sl@0: sl@0: _LIT(testName,"t_iic"); sl@0: sl@0: _LIT(KIicProxyFileNameCtrlLess, "iic_client_ctrless.ldd"); // Kernel-side proxy LDD acting as a client of the IIC sl@0: _LIT(KIicProxyFileNameRootCtrlLess, "iic_client_ctrless"); sl@0: _LIT(KIicProxySlaveFileNameCtrlLess, "iic_slaveclient_ctrless.ldd"); // Kernel-side proxy LDD acting as a slave client of the IIC sl@0: _LIT(KIicProxySlaveFileNameRootCtrlLess, "iic_slaveclient_ctrless"); sl@0: _LIT(KIicProxyFileName, "iic_client.ldd"); // Kernel-side proxy LDD acting as a client of the IIC sl@0: _LIT(KIicProxyFileNameRoot, "iic_client"); sl@0: _LIT(KIicProxySlaveFileName, "iic_slaveclient.ldd"); // Kernel-side proxy LDD acting as a slave client of the IIC sl@0: _LIT(KIicProxySlaveFileNameRoot, "iic_slaveclient"); sl@0: sl@0: #ifdef IIC_SIMULATED_PSL sl@0: _LIT(KSpiFileNameCtrlLess, "spi_ctrless.pdd"); // Simulated PSL bus implementation sl@0: _LIT(KI2cFileNameCtrlLess, "i2c_ctrless.pdd"); // Simulated PSL bus implementation sl@0: _LIT(KIicPslFileName, "iic_testpsl.pdd"); // Simulated PSL implementation sl@0: _LIT(KSpiFileName, "spi.pdd"); // Simulated PSL bus implementation sl@0: _LIT(KI2cFileName, "i2c.pdd"); // Simulated PSL bus implementation sl@0: #endif sl@0: sl@0: _LIT(KIicPslFileNameRoot, "iic.pdd"); sl@0: sl@0: // Specify a stand-alone channel sl@0: GLDEF_D TBool aStandAloneChan; sl@0: sl@0: GLDEF_D RTest gTest(testName); sl@0: sl@0: sl@0: // SPI has Master channel numbers 1,2 and 4, Slave channel number 3 sl@0: GLDEF_D RBusDevIicClient gChanMasterSpi; sl@0: GLDEF_D RBusDevIicClient gChanSlaveSpi; sl@0: sl@0: // I2C has Master channel numbers 10 and 11, if built with MASTER_MODE, only sl@0: // I2C has Slave channel numbers 12 and 13, if built with SLAVE_MODE, only sl@0: // I2C has Master channel number 10 and Slave channel number 11 if built with both MASTER_MODE and SLAVE_MODE sl@0: GLDEF_D RBusDevIicClient gChanMasterI2c; sl@0: GLDEF_D RBusDevIicClient gChanSlaveI2c; sl@0: sl@0: LOCAL_C TInt CreateSingleUserSideTransfer(TUsideTferDesc*& aTfer, TInt8 aType, TInt8 aBufGran, TDes8* aBuf, TUsideTferDesc* aNext) sl@0: // Utility function to create a single transfer sl@0: { sl@0: aTfer = new TUsideTferDesc(); sl@0: if(aTfer==NULL) sl@0: return KErrNoMemory; sl@0: aTfer->iType=aType; sl@0: aTfer->iBufGranularity=aBufGran; sl@0: aTfer->iBuffer = aBuf; sl@0: aTfer->iNext = aNext; sl@0: return KErrNone; sl@0: } sl@0: sl@0: LOCAL_C TInt CreateSingleUserSideTransaction(TUsideTracnDesc*& aTracn, TBusType aType, TDes8* aHdr, TUsideTferDesc* aHalfDupTrans, TUsideTferDesc* aFullDupTrans, TUint8 aFlags, TAny* aPreambleArg, TAny* aMultiTranscArg) sl@0: // Utility function to create a single transaction sl@0: { sl@0: aTracn = new TUsideTracnDesc(); sl@0: if(aTracn==NULL) sl@0: return KErrNoMemory; sl@0: aTracn->iType=aType; sl@0: aTracn->iHeader=aHdr; sl@0: aTracn->iHalfDuplexTrans=aHalfDupTrans; sl@0: aTracn->iFullDuplexTrans=aFullDupTrans; sl@0: aTracn->iFlags=aFlags; sl@0: aTracn->iPreambleArg = aPreambleArg; sl@0: aTracn->iMultiTranscArg = aMultiTranscArg; sl@0: return KErrNone; sl@0: } sl@0: sl@0: sl@0: //---------------------------------------------------------------------------------------------- sl@0: //! @SYMTestCaseID KBASE-T_IIC-2402 sl@0: //! @SYMTestType UT sl@0: //! @SYMPREQ PREQ2128,2129 sl@0: //! @SYMTestCaseDesc This test case test the Master channel basic functionality sl@0: //! @SYMTestActions 0) Create a transaction and invoke the synchronous Queue Transaction API sl@0: //! sl@0: //! 1) Re-use the transaction and invoke asynchronous Queue Transaction API. Wait for sl@0: //| the TRequestStatus to be completed. sl@0: //! sl@0: //! 2) Instruct the Kernel-side proxy client to instigate testing of priority queuing. sl@0: //! The proxy uses controlIO to block the transaction queue, then queues 5 transactions in reverse sl@0: //! priority order. The proxy then uses controlIO to unblock the transaction queue and checks that sl@0: //! the transactions complete in priority order. sl@0: //! sl@0: //! 3) Attempt to cancel a previously-completed asynchronous request for a queued transaction sl@0: //! sl@0: //! 4) Use controlio to block request completion. Issue two asynchronous Queue Transaction requests. sl@0: //! Request cancellation of the second transaction. Wait for completion of the TRequestStatus for sl@0: //! the second request. Attempt to de-register the channel. Use controlio to unblock request completion. sl@0: //! Wait for completion of the TRequestStatus for the first request. sl@0: //! sl@0: //! 5) Attempt to de-register a channel that is not busy. sl@0: //! sl@0: //! 6) Attempt to queue a transaction on an invalid (de-registered) channel sl@0: //! sl@0: //! 7) Instruct the Kernel-side proxy client to instigate construction of a valid full duplex transaction. sl@0: //! sl@0: //! 8) Instruct the Kernel-side proxy client to instigate construction of a invalid full duplex transaction, sl@0: //! where both transfer in same direction sl@0: //! sl@0: //! 9) Instruct the Kernel-side proxy client to instigate construction of a invalid full duplex transaction, sl@0: //! where with different node length (not the number of node on opposite linklist ) at the same sl@0: //! position on the opposite transfer linklist sl@0: //! sl@0: //! 10) Instruct the Kernel-side proxy client to instigate construction of a valid full duplex transaction, sl@0: //! with different size for the last node sl@0: //! sl@0: //! 11) Instruct the Kernel-side proxy client to instigate construction of a valid full duplex transaction, sl@0: //! with different number of transfer sl@0: //! sl@0: //! sl@0: //! @SYMTestExpectedResults 0) Kernel-side proxy client should return with KErrNone, exits otherwise. sl@0: //! 1) Kernel-side proxy client should return with KErrNone, exits otherwise. TRequestStatus should sl@0: //! be set to KErrNone, exits otherwise. sl@0: //! 2) Kernel-side proxy client should return with KErrNone, exits otherwise. sl@0: //! 3) Kernel-side proxy client should return with KErrNone, exits otherwise.TRequestStatus should sl@0: //! be set to KErrNone, exits otherwise. sl@0: //! 4) The TRequestStatus for the cancelled request should be set to KErrCancel, exits otherwise. sl@0: //! The attempt to de-register the channel should return KErrInUse, exits otherwise. The sl@0: //! TRequestStatus for the first request should be set to KErrNone, exits otherwise. sl@0: //! 5) Kernel-side proxy client should return with KErrNone or KErrArgument, exits otherwise. sl@0: //! 6) Kernel-side proxy client should return with KErrArgument, exits otherwise. sl@0: //! 7) Kernel-side proxy client should return with KErrNone, exits otherwise. sl@0: //! 8) Kernel-side proxy client should return with KErrNotSupported, exits otherwise. sl@0: //! 9) Kernel-side proxy client should return with KErrNotSupported, exits otherwise. sl@0: //! 10) Kernel-side proxy client should return with KErrNone, exits otherwise. sl@0: //! 11) Kernel-side proxy client should return with KErrNone, exits otherwise. sl@0: //! sl@0: //! @SYMTestPriority High sl@0: //! @SYMTestStatus Implemented sl@0: //---------------------------------------------------------------------------------------------- sl@0: LOCAL_C TInt MasterBasicTests() sl@0: // sl@0: // Exercise the Master Channel API with trivial data sl@0: // sl@0: { sl@0: gTest.Printf(_L("\n\nStarting MasterBasicTests\n")); sl@0: sl@0: TInt r=KErrNone; sl@0: sl@0: TUint32 busIdSpi = 0; sl@0: sl@0: // Use the SPI bus sl@0: // SPI uses channel numbers 1,2,3 and 4 sl@0: SET_BUS_TYPE(busIdSpi,ESpi); sl@0: SET_CHAN_NUM(busIdSpi,2); sl@0: TConfigSpiBufV01* spiBuf = NULL; sl@0: // aDeviceId=1 ... 100kHz ... aTimeoutPeriod=100 ... aTransactionWaitCycles=10 - arbitrary paarmeters. sl@0: r = CreateSpiBuf(spiBuf, ESpiWordWidth_8, 100000, ESpiPolarityLowRisingEdge, 100 ,ELittleEndian, EMsbFirst, 10, ESpiCSPinActiveLow); sl@0: gTest(r==KErrNone); sl@0: sl@0: // Use a single transfer sl@0: _LIT(halfDuplexText,"Half Duplex Text"); sl@0: TBuf8<17> halfDuplexBuf_8; sl@0: halfDuplexBuf_8.Copy(halfDuplexText); sl@0: TUsideTferDesc* tfer = NULL; sl@0: r = CreateSingleUserSideTransfer(tfer, EMasterWrite, 8, &halfDuplexBuf_8, NULL); sl@0: gTest(r==KErrNone); sl@0: sl@0: // Create the transaction object sl@0: TUsideTracnDesc* tracn = NULL; sl@0: r = CreateSingleUserSideTransaction(tracn, ESpi, spiBuf, tfer, NULL, 0, NULL, NULL); sl@0: gTest(r==KErrNone); sl@0: sl@0: // Test basic queueing operations sl@0: // inline TInt QueueTransaction(TInt aBusId, TUsideTracnDesc* aTransaction) sl@0: gTest.Printf(_L("\n\nStarting synchronous QueueTransaction \n")); sl@0: r = gChanMasterSpi.QueueTransaction(busIdSpi, tracn); sl@0: gTest.Printf(_L("Synchronous QueueTransaction returned = %d\n"),r); sl@0: gTest(r==KErrNone); sl@0: // inline void QueueTransaction(TRequestStatus& aStatus, TInt aBusId, TUsideTracnDesc* aTransaction) sl@0: gTest.Printf(_L("\n\nStarting asynchronous QueueTransaction \n")); sl@0: TRequestStatus status; sl@0: sl@0: gChanMasterSpi.QueueTransaction(status, busIdSpi, tracn); sl@0: User::WaitForRequest(status); sl@0: if(status != KErrNone) sl@0: { sl@0: gTest.Printf(_L("TRequestStatus value after queue = %d\n"), status.Int()); sl@0: gTest(EFalse); sl@0: } sl@0: sl@0: // Test message with priorities sl@0: gTest.Printf(_L("\n\nStarting test for message with priorities\n\n"),r); sl@0: r = gChanMasterSpi.TestPriority(busIdSpi); sl@0: gTest(r==KErrNone); sl@0: sl@0: // Test cancel operation (on previously completed request) sl@0: sl@0: // inline void CancelAsyncOperation(TRequestStatus* aStatus, TInt aBusId) {TInt* parms[2]; parms[0]=(TInt*)aStatus; parms[1]=(TInt*)aBusId;DoCancel((TInt)&parms[0]);} sl@0: gTest.Printf(_L("\n\nStarting CancelAsyncOperation \n")); sl@0: gChanMasterSpi.CancelAsyncOperation(&status, busIdSpi); sl@0: if(status == KRequestPending) sl@0: User::WaitForRequest(status); sl@0: if(status != KErrNone) sl@0: { sl@0: gTest.Printf(_L("TRequestStatus value after (belated) cancel = %d\n"), status.Int()); sl@0: gTest(EFalse); sl@0: } sl@0: sl@0: // Test cancel operation (on pending request) sl@0: // Also test that a channel with a transaction queued can not be de-registered. sl@0: // For this: sl@0: // (1) create a second transaction object sl@0: // (2) use controlio/StaticExtension to block request completion sl@0: // (3) use asynchronous queue transaction for the two transaction objects sl@0: // (4) request cancellation of the second request sl@0: // (5) check that the TRequestStatus object associated with the second request is completed with KErrCancel sl@0: // (6) check that attempt to de-register the channel fails with KErrInUse sl@0: // (7) use controlio/StaticExtension to unblock request completion sl@0: // (8) check that the TRequestStatus object associated with the first request is completed with KErrNone sl@0: // sl@0: gTest.Printf(_L("\n\nStarting (successful) cancellation test\n\n"),r); sl@0: _LIT(halfDuplexText2,"2 Half Duplex Text 2"); sl@0: TBuf8<21> halfDuplexBuf2_8; sl@0: halfDuplexBuf2_8.Copy(halfDuplexText2); sl@0: TUsideTferDesc* tfer2 = NULL; sl@0: r = CreateSingleUserSideTransfer(tfer2, EMasterRead, 16, &halfDuplexBuf2_8, NULL); sl@0: gTest(r == KErrNone); sl@0: sl@0: TUsideTracnDesc* tracn2 = NULL; sl@0: delete spiBuf; sl@0: spiBuf = NULL; sl@0: sl@0: // aDeviceId=1 ... 100kHz ... aTimeoutPeriod=100 ... aTransactionWaitCycles=10 - arbitrary paarmeters. sl@0: r = CreateSpiBuf(spiBuf, ESpiWordWidth_8, 100000, ESpiPolarityLowRisingEdge, 100 ,ELittleEndian, EMsbFirst, 10, ESpiCSPinActiveLow); sl@0: gTest(r == KErrNone); sl@0: sl@0: r = CreateSingleUserSideTransaction(tracn2, ESpi, spiBuf, tfer2, NULL, 0, NULL, NULL); sl@0: gTest(r == KErrNone); sl@0: sl@0: // sl@0: gTest.Printf(_L("Invoking BlockReqCompletion\n")); sl@0: r = gChanMasterSpi.BlockReqCompletion(busIdSpi); sl@0: gTest.Printf(_L("BlockReqCompletion returned = %d\n"),r); sl@0: gTest(r == KErrNone); sl@0: sl@0: // sl@0: gTest.Printf(_L("Queueing first transaction \n")); sl@0: gChanMasterSpi.QueueTransaction(status, busIdSpi, tracn); sl@0: TRequestStatus status2; sl@0: sl@0: gTest.Printf(_L("Queueing second transaction \n")); sl@0: gChanMasterSpi.QueueTransaction(status2, busIdSpi, tracn2); sl@0: // sl@0: User::After(50000); sl@0: // sl@0: gTest.Printf(_L("Issuing Cancel for second transaction\n")); sl@0: gChanMasterSpi.CancelAsyncOperation(&status2, busIdSpi); sl@0: gTest.Printf(_L("Returned from Cancel for second transaction\n")); sl@0: if(status2 == KRequestPending) sl@0: User::WaitForRequest(status2); sl@0: if(status2 != KErrCancel) sl@0: { sl@0: gTest.Printf(_L("TRequestStatus (2) value after cancel = %d\n"), status2.Int()); sl@0: gTest(EFalse); sl@0: } sl@0: sl@0: // If it is stand-alone channel, the client is reponsible for channel creation. sl@0: // So the RegisterChan and DeRegisterChan are not needed. sl@0: if (aStandAloneChan == 0) sl@0: { sl@0: gTest.Printf(_L("Invoking DeRegisterChan\n")); sl@0: r = gChanMasterSpi.DeRegisterChan(busIdSpi); sl@0: sl@0: gTest.Printf(_L("DeRegisterChan returned = %d\n"),r); sl@0: gTest(r==KErrInUse); sl@0: } sl@0: // sl@0: gTest.Printf(_L("Invoking UnlockReqCompletion\n")); sl@0: r = gChanMasterSpi.UnblockReqCompletion(busIdSpi); sl@0: gTest.Printf(_L("UnblockReqCompletion returned = %d\n"),r); sl@0: // sl@0: User::After(50000); sl@0: // sl@0: User::WaitForRequest(status); sl@0: if(status != KErrNone) sl@0: { sl@0: gTest.Printf(_L("TRequestStatus value after queue = %d\n"), status.Int()); sl@0: gTest(EFalse); sl@0: } sl@0: sl@0: // Clean up sl@0: delete spiBuf; sl@0: delete tfer; sl@0: delete tracn; sl@0: delete tfer2; sl@0: delete tracn2; sl@0: sl@0: gTest.Printf(_L("\n\nStarting full duplex transaction creation test\n\n"),r); sl@0: sl@0: TUint32 busIdSpiFd = 0; sl@0: sl@0: // Use the SPI bus sl@0: // SPI uses channel numbers 1,2,3 and 4 sl@0: SET_BUS_TYPE(busIdSpi,ESpi); sl@0: SET_CHAN_NUM(busIdSpi,4); sl@0: sl@0: // Test creating a valid full duplex transaction sl@0: gTest.Printf(_L("\n\nStarting valid full duplex transaction test\n\n"),r); sl@0: r = gChanMasterSpi.TestValidFullDuplexTrans(busIdSpiFd); sl@0: gTest(r==KErrNone); sl@0: sl@0: // Test creating a full duplex transaction with both transfer in same direction (invalid) sl@0: gTest.Printf(_L("\n\nStarting invalid direction full duplex transaction test\n\n"),r); sl@0: r = gChanMasterSpi.TestInvalidFullDuplexTrans1(busIdSpiFd); sl@0: gTest.Printf(_L("Full duplex transaction with invalid direction returned = %d\n"),r); sl@0: gTest(r==KErrNotSupported); sl@0: sl@0: // Test creating a full duplex transaction with different node length (not the number of node on opposite linklist ) sl@0: // at the same position on the opposite transfer linklist sl@0: gTest.Printf(_L("\n\nStarting invalid transfer length full duplex transaction test\n\n"),r); sl@0: r = gChanMasterSpi.TestInvalidFullDuplexTrans2(busIdSpiFd); sl@0: gTest(r==KErrNotSupported); sl@0: sl@0: // Test creating a valid full duplex transaction with different size for the last node sl@0: gTest.Printf(_L("\n\nStarting valid full duplex transaction test with diff size last node\n\n"),r); sl@0: r = gChanMasterSpi.TestLastNodeFullDuplexTrans(busIdSpiFd); sl@0: gTest(r==KErrNone); sl@0: sl@0: // Test creating a valid full duplex transaction with different number of transfer sl@0: gTest.Printf(_L("\n\nStarting valid full duplex transaction test with diff number of transfer\n\n"),r); sl@0: r = gChanMasterSpi.TestDiffNodeNumFullDuplexTrans(busIdSpiFd); sl@0: gTest(r==KErrNone); sl@0: sl@0: return KErrNone; sl@0: } sl@0: sl@0: sl@0: //---------------------------------------------------------------------------------------------- sl@0: //! @SYMTestCaseID KBASE-T_IIC-2403 sl@0: //! @SYMTestType UT sl@0: //! @SYMPREQ PREQ2128,2129 sl@0: //! @SYMTestCaseDesc This test case tests the Master channel data handling for transactions sl@0: //! @SYMTestActions 0) Instruct the kernel-side proxy to construct a transaction of pre-defined data sl@0: //! and inform the simulated bus to expect to receive this data. Then the proxy invokes sl@0: //! the synchronous Queue Transaction API. On receipt of the transaction, the simulated bus sl@0: //! checks the header and transafer content of the transaction to confirm that it is correct. sl@0: //! sl@0: //! @SYMTestExpectedResults 0) Kernel-side proxy client should return with KErrNone, exits otherwise. sl@0: //! sl@0: //! @SYMTestPriority High sl@0: //! @SYMTestStatus Implemented sl@0: //---------------------------------------------------------------------------------------------- sl@0: LOCAL_C TInt MasterTransactionTests() sl@0: // sl@0: // Exercise the Master Channel API with trivial data sl@0: // sl@0: { sl@0: gTest.Printf(_L("\n\nStarting MasterTransactionTests\n")); sl@0: sl@0: TInt r = KErrNone; sl@0: sl@0: // Prove that the simulated bus can access the transfer data contained within a transaction sl@0: // Do this by instructing the proxy client to: sl@0: // (1) Inform the bus of the test about to be informed sl@0: // (2) Send a transaction with a known number of transfers with known data sl@0: // (3) Check the result announced by the bus. sl@0: // sl@0: // Use the SPI bus sl@0: // SPI uses channel numbers 1,2,3 and 4 sl@0: TUint32 busIdSpi = 0; sl@0: SET_BUS_TYPE(busIdSpi,ESpi); sl@0: SET_CHAN_NUM(busIdSpi,4); // Master, Full-duplex - required by TestBufferReUse sl@0: r = gChanMasterSpi.TestTracnOne(busIdSpi); sl@0: gTest.Printf(_L("TestTracnOne returned = %d\n"),r); sl@0: gTest(r==KErrNone); sl@0: sl@0: // Test that transfer and transaction buffers can be modifed for re-use sl@0: // This test modifies the content of a full-duplex transaction - so a full-duplex channel must be used sl@0: TRequestStatus status; sl@0: gChanMasterSpi.TestBufferReUse(busIdSpi, status); sl@0: User::WaitForRequest(status); sl@0: r=status.Int(); sl@0: if(r != KErrNone) sl@0: { sl@0: gTest.Printf(_L("TRequestStatus value after CaptureChannel = %d\n"),r); sl@0: gTest(r==KErrCompletion); sl@0: } sl@0: sl@0: return KErrNone; sl@0: } sl@0: sl@0: //---------------------------------------------------------------------------------------------- sl@0: //! @SYMTestCaseID KBASE-T_IIC-2401 sl@0: //! @SYMTestType UT sl@0: //! @SYMPREQ PREQ2128,2129 sl@0: //! @SYMTestCaseDesc This test case test the Master channel preamble and multi-transaction functionality. sl@0: //! @SYMTestActions 0) Create a transaction that requires preamble support, and queue it for processing sl@0: //! sl@0: //! 1) If the test has been invoked for preamble testing, wait for the preamble-specific sl@0: //! TRequestStatus to be completed. sl@0: //! sl@0: //! 2) If the test has been invoked for multi-transaction testing, wait for the multi-transaction sl@0: //! -specific TRequestStatus to be completed. sl@0: //! sl@0: //! sl@0: //! @SYMTestExpectedResults 0) Kernel-side proxy client should return with KErrNone, exits otherwise. sl@0: //! 1) If waiting on the preamble-specific TRequestStatus, it should be set to KErrNone, exists otherwise. sl@0: //! 2) If waiting on the multi-transaction-specific TRequestStatus, it should be set to KErrNone, exists otherwise. sl@0: //! sl@0: //! @SYMTestPriority High sl@0: //! @SYMTestStatus Implemented sl@0: //---------------------------------------------------------------------------------------------- sl@0: LOCAL_C TInt MasterExtTests(TUint8 aFlags) sl@0: // sl@0: // Exercise the Master Channel API for Preamble functionality sl@0: // sl@0: sl@0: // For the multi-transaction test, a bus Master might not know sl@0: // how much data to write to a Slave until it performs a single read on it. sl@0: // However, specifying a read separately from the subsequent write sl@0: // introduces the risk of allowing another transaction to go ahead of the sl@0: // following write and thus invalidating it. The multi-transaction feature of IIC sl@0: // allows a callback to be called(in the context of the bus channel) after sl@0: // the transfers of a preliminary transaction have taken place sl@0: // (could be a single read), without completing the overall transaction, sl@0: // then extend the delayed transaction by inserting more transfers sl@0: // sl@0: { sl@0: gTest.Printf(_L("\n\nStarting MasterExtTests\n")); sl@0: sl@0: TInt r = KErrNone; sl@0: sl@0: // Create a transaction that requires preamble support sl@0: // To prove required operation has executed, make callback complete a TRequestStatus object sl@0: TRequestStatus preamblestatus; sl@0: TRequestStatus multitranscstatus; sl@0: sl@0: // Use the SPI bus sl@0: // SPI uses channel numbers 1,2,3 and 4 sl@0: TUint32 busIdSpi = 0; sl@0: SET_BUS_TYPE(busIdSpi, ESpi); sl@0: SET_CHAN_NUM(busIdSpi, 1); sl@0: TConfigSpiBufV01* spiBuf = NULL; sl@0: // aDeviceId=1 ... 100kHz ... aTimeoutPeriod=100 ... aTransactionWaitCycles=10 - arbitrary paarmeters. sl@0: r = CreateSpiBuf(spiBuf, ESpiWordWidth_8, 100000, sl@0: ESpiPolarityLowRisingEdge, 100, ELittleEndian, EMsbFirst, 10, sl@0: ESpiCSPinActiveLow); sl@0: if (r != KErrNone) sl@0: return r; sl@0: sl@0: // Use a single transfer sl@0: _LIT(extText, "Ext Text"); sl@0: TBuf8<14> extBuf_8; sl@0: extBuf_8.Copy(extText); sl@0: TUsideTferDesc* tfer = NULL; sl@0: r = CreateSingleUserSideTransfer(tfer, EMasterRead, 8, &extBuf_8, NULL); sl@0: if (r != KErrNone) sl@0: { sl@0: delete spiBuf; sl@0: return r; sl@0: } sl@0: sl@0: // Create the transaction object sl@0: TUsideTracnDesc* tracn = NULL; sl@0: r = CreateSingleUserSideTransaction(tracn, ESpi, spiBuf, tfer, NULL, sl@0: aFlags, (TAny*) &preamblestatus, (TAny*) &multitranscstatus); sl@0: sl@0: if (r != KErrNone) sl@0: { sl@0: delete spiBuf; sl@0: delete tfer; sl@0: return r; sl@0: } sl@0: sl@0: // Send the transaction to the kernel-side proxy sl@0: // inline TInt QueueTransaction(TInt aBusId, TUsideTracnDesc* aTransaction) sl@0: gTest.Printf(_L("\nInvoke synchronous QueueTransaction for preamble test %x\n"), tracn); sl@0: sl@0: r = gChanMasterSpi.QueueTransaction(busIdSpi, tracn); sl@0: gTest.Printf(_L("synchronous QueueTransaction returned = %d\n"), r); sl@0: sl@0: if (r == KErrNone) sl@0: { sl@0: // ... and wait for the TRequestStatus object to be completed sl@0: if (aFlags & KTransactionWithPreamble) sl@0: { sl@0: User::WaitForRequest(preamblestatus); sl@0: r = preamblestatus.Int(); sl@0: if (r != KErrNone) sl@0: { sl@0: gTest.Printf(_L("MasterPreambleTests: TRequestStatus completed with = %d\n"), r); sl@0: } sl@0: } sl@0: sl@0: sl@0: if (aFlags & KTransactionWithMultiTransc) sl@0: { sl@0: User::WaitForRequest(multitranscstatus); sl@0: if (r != KErrNone) sl@0: { sl@0: gTest.Printf(_L("MasterMultiTranscTests: TRequestStatus completed with = %d\n"), r); sl@0: } sl@0: } sl@0: } sl@0: sl@0: delete spiBuf; sl@0: delete tfer; sl@0: delete tracn; sl@0: sl@0: return r; sl@0: } sl@0: sl@0: #ifdef SLAVE_MODE sl@0: LOCAL_C TInt CreateSlaveChanI2cConfig(TConfigI2cBufV01*& aI2cBuf, TUint32& aBusIdI2c, TUint8 aChanNum) sl@0: { sl@0: // Initialise TConfigI2cBufV01 and the Bus Realisation Config for gChanSlaveI2c. sl@0: // Customised: sl@0: // - token containing the bus realisation variability. sl@0: // - pointer to a descriptor containing the device specific configuration option applicable to all transactions. sl@0: // - reference to variable to hold a platform-specific cookie that uniquely identifies the channel instance to be sl@0: // used by this client sl@0: aBusIdI2c = 0; sl@0: SET_BUS_TYPE(aBusIdI2c,EI2c); sl@0: SET_CHAN_NUM(aBusIdI2c,aChanNum); sl@0: // sl@0: // clock speed=36Hz, aTimeoutPeriod=100 - arbitrary parameter sl@0: TInt r=CreateI2cBuf(aI2cBuf, EI2cAddr7Bit, 36, ELittleEndian, 100); sl@0: return r; sl@0: } sl@0: sl@0: LOCAL_C TInt SyncCaptureGChanSlaveI2c(TInt& aChanId, TConfigI2cBufV01* aI2cBuf, TUint32 aBusIdI2c) sl@0: { sl@0: // Synchronous capture of a Slave channel. Need to provide: sl@0: // - token containing the bus realisation variability. sl@0: // - pointer to a descriptor containing the device specific configuration option applicable to all transactions. sl@0: // - reference to variable to hold a platform-specific cookie that uniquely identifies the channel instance to be used by this client sl@0: gTest.Printf(_L("\n\nStarting synchronous CaptureChannel \n")); sl@0: TInt r = gChanSlaveI2c.CaptureChannel(aBusIdI2c, aI2cBuf, aChanId ); sl@0: gTest.Printf(_L("Synchronous CaptureChannel returned = %d, aChanId=0x%x\n"),r,aChanId); sl@0: return r; sl@0: } sl@0: sl@0: sl@0: LOCAL_C TInt AsyncCaptureGChanSlaveI2c(TInt& aChanId, TConfigI2cBufV01* aI2cBuf, TUint32 aBusIdI2c) sl@0: { sl@0: // Asynchronous capture of a Slave channel. Need to provide: sl@0: // - token containing the bus realisation variability. sl@0: // - pointer to a descriptor containing the device specific configuration option applicable to all transactions. sl@0: // - reference to variable to hold a platform-specific cookie that uniquely identifies the channel instance to be used by this client sl@0: // - pointer to TRequestStatus used to indicate operation completion sl@0: gTest.Printf(_L("\n\nStarting asynchronous CaptureChannel \n")); sl@0: TRequestStatus status; sl@0: TInt r = gChanSlaveI2c.CaptureChannel(aBusIdI2c, aI2cBuf, aChanId, status ); sl@0: gTest(r==KErrNone); sl@0: User::WaitForRequest(status); sl@0: r=status.Int(); sl@0: if(r != KErrCompletion) sl@0: { sl@0: gTest.Printf(_L("TRequestStatus value after CaptureChannel = %d\n"),r); sl@0: gTest(r==KErrCompletion); sl@0: } sl@0: gTest.Printf(_L("Asynchronous CaptureChannel gave aChanId=0x%x\n"),aChanId); sl@0: return KErrNone; sl@0: } sl@0: #endif sl@0: //---------------------------------------------------------------------------------------------- sl@0: //! @SYMTestCaseID KBASE-T_IIC-2399 sl@0: //! @SYMTestType UT sl@0: //! @SYMPREQ PREQ2128,2129 sl@0: //! @SYMTestCaseDesc This test case tests Slave channel capture and release APIs. sl@0: //! @SYMTestActions 0) Perform synchronous capture of a channel sl@0: //! sl@0: //! 1) Release the channel sl@0: //! sl@0: //! 2) Perform asynchronous capture of a channel sl@0: //! sl@0: //! 3) Attempt synchronous capture of a channel that is already captured sl@0: //! sl@0: //! 4) Attempt asynchronous capture of a channel that is already captured sl@0: //! sl@0: //! 5) Release the channel sl@0: //! sl@0: //! @SYMTestExpectedResults 0) Kernel-side proxy client should return with KErrCompletion, exits otherwise. sl@0: //! 1) Kernel-side proxy client should return with KErrNone, exits otherwise. sl@0: //! 2) Kernel-side proxy client should return with KErrNone, exits otherwise. sl@0: //! 3) Kernel-side proxy client should return with KErrInUse, exits otherwise. sl@0: //! 4) Kernel-side proxy client should return with KErrNone, exits otherwise. The associated sl@0: //! TRequestStatus should be set to KErrInUse, exits otherwise. sl@0: //! 5) Kernel-side proxy client should return with KErrNone, exits otherwise. sl@0: //! sl@0: //! @SYMTestPriority High sl@0: //! @SYMTestStatus Implemented sl@0: //---------------------------------------------------------------------------------------------- sl@0: LOCAL_C TInt SlaveChannelCaptureReleaseTests() sl@0: // sl@0: // Exercise the Slave Channel API for channel capture and release sl@0: // sl@0: { sl@0: gTest.Printf(_L("\n\nStarting SlaveChannelCaptureReleaseTests\n")); sl@0: TInt r=KErrNone; sl@0: #ifdef SLAVE_MODE sl@0: sl@0: // Create a I2C configuration buffer and the configuration data for use in capturing gChanSlaveI2c sl@0: TUint32 busIdI2c = 0; sl@0: TConfigI2cBufV01* i2cBuf=NULL; sl@0: r=CreateSlaveChanI2cConfig(i2cBuf, busIdI2c, 11); // 11 is the Slave channel number sl@0: gTest(r==KErrNone); sl@0: sl@0: // Synchronous capture of a Slave channel. sl@0: TInt chanId = 0; // Initialise to zero to silence compiler ... sl@0: r=SyncCaptureGChanSlaveI2c(chanId, i2cBuf, busIdI2c); sl@0: gTest(r==KErrNone); sl@0: // sl@0: // Release the channel sl@0: gTest.Printf(_L("\n\nInvoke ReleaseChannel for chanId=0x%x \n"),chanId); sl@0: r = gChanSlaveI2c.ReleaseChannel( chanId ); sl@0: gTest.Printf(_L("ReleaseChannel returned = %d\n"),r); sl@0: gTest(r==KErrNone); sl@0: // sl@0: // Asynchronous capture of a Slave channel. sl@0: chanId = 0; // Re-initialise to zero to silence compiler ... sl@0: r=AsyncCaptureGChanSlaveI2c(chanId, i2cBuf, busIdI2c); sl@0: gTest(r==KErrNone); sl@0: sl@0: // Try capturing a slave channel that is already captured sl@0: // sl@0: // Create another instance of a client, and use to attempt duplicated capture sl@0: TInt dumChanId = 0; // Initialise to zero to silence compiler ... sl@0: RBusDevIicClient tempChanSlaveI2c; sl@0: TBufC<24> proxySlaveName; sl@0: if(aStandAloneChan == 0) sl@0: proxySlaveName = KIicProxySlaveFileNameRoot; sl@0: else sl@0: proxySlaveName = KIicProxySlaveFileNameRootCtrlLess; sl@0: r = tempChanSlaveI2c.Open(proxySlaveName); sl@0: gTest(r==KErrNone); sl@0: r = tempChanSlaveI2c.InitSlaveClient(); sl@0: gTest(r==KErrNone); sl@0: // sl@0: // Synchronous capture sl@0: gTest.Printf(_L("\n\nStarting attempted synchronous CaptureChannel of previously-captured channel\n")); sl@0: r = tempChanSlaveI2c.CaptureChannel(busIdI2c, i2cBuf, dumChanId ); sl@0: gTest.Printf(_L("Synchronous CaptureChannel returned = %d, dumChanId=0x%x\n"),r,dumChanId); sl@0: gTest(r==KErrInUse); sl@0: // sl@0: // Asynchronous capture sl@0: dumChanId = 0; sl@0: gTest.Printf(_L("\n\nStarting attempted asynchronous CaptureChannel of previously-captured channel\n")); sl@0: TRequestStatus status; sl@0: r = tempChanSlaveI2c.CaptureChannel(busIdI2c, i2cBuf, dumChanId, status ); sl@0: gTest(r==KErrNone); sl@0: User::WaitForRequest(status); sl@0: r=status.Int(); sl@0: if(r != KErrInUse) sl@0: { sl@0: gTest.Printf(_L("TRequestStatus value after attempted CaptureChannel of previously-captured channel = %d\n"),r); sl@0: gTest(r==KErrInUse); sl@0: } sl@0: gTest.Printf(_L("Asynchronous CaptureChannel gave dumChanId=0x%x\n"),dumChanId); sl@0: sl@0: tempChanSlaveI2c.Close(); sl@0: // sl@0: // Clean up, release the channel sl@0: r = gChanSlaveI2c.ReleaseChannel( chanId ); sl@0: gTest.Printf(_L("ReleaseChannel returned = %d\n"),r); sl@0: gTest(r==KErrNone); sl@0: sl@0: delete i2cBuf; sl@0: #else sl@0: gTest.Printf(_L("\nSlaveChannelCaptureReleaseTests only supported when SLAVE_MODE is defined\n")); sl@0: #endif sl@0: return r; sl@0: } sl@0: sl@0: //---------------------------------------------------------------------------------------------- sl@0: //! @SYMTestCaseID KBASE-T_IIC-2400 sl@0: //! @SYMTestType UT sl@0: //! @SYMPREQ PREQ2128,2129 sl@0: //! @SYMTestCaseDesc This test case tests Slave channel capture operation for receive and transmit of data sl@0: //! @SYMTestActions 0) Check that the timeout threshold values can be updated sl@0: //! sl@0: //! 1) Check that an Rx Buffer can be registered, and that a replacement buffer can be registered in its place sl@0: //! if a notification has not been requested. sl@0: //! sl@0: //! 2) Specify a notification trigger for Rx events sl@0: //! sl@0: //! 3) Attempt to register a replacement Rx buffer sl@0: //! sl@0: //! 4) Use controlIO to instruct the simulated bus to indicate that it has received the required number of words sl@0: //! and wait for the TRequestStatus to be completed. sl@0: //! sl@0: //! 5) Specify a notification trigger for Rx events, use controlIO to instruct the simulated bus to indicate that sl@0: //! it has received less than the required number of words and wait for the TRequestStatus to be completed. sl@0: //! sl@0: //! 6) Specify a notification trigger for Rx events, use controlIO to instruct the simulated bus to indicate that sl@0: //! it has received more than the required number of words and wait for the TRequestStatus to be completed. sl@0: //! sl@0: //! 7) Repeat steps 1-6, but for Tx sl@0: //! sl@0: //! 8) Specify a notification trigger for Rx and Tx events. Use controlIO to instruct the simulated bus to indicate that sl@0: //! it has received the required number of words, then that it has transmitted the required number of words, and wait sl@0: //! for the TRequestStatus to be completed. sl@0: //! sl@0: //! 9) Repeat step 8, but simulate Tx, then Rx. sl@0: //! sl@0: //! 10) Specify a notification trigger for bus error events. Use controlIO to instruct the simulated bus to indicate that sl@0: //! it has encountered a bus error, and wait for the TRequestStatus to be completed. sl@0: //! sl@0: //! 11) Use controlIO to instruct the simulated bus to block Master response. Specify a notification trigger for bus error sl@0: //! events. Use controlIO to instruct the simulated bus to indicate that it has received more than the required number sl@0: //! of words. Wait for the TRequestStatus to be completed (with KErrNone). Specify a notification trigger for Tx and sl@0: //! Tx Overrun, then use controlIO to instruct the simulated bus to unblock Master responses.Wait for the TRequestStatus sl@0: //! to be completed. sl@0: //! sl@0: //! @SYMTestExpectedResults 0) Kernel-side proxy client should return with KErrNone, exits otherwise. sl@0: //! 1) Kernel-side proxy client should return with KErrNone, exits otherwise. sl@0: //! 2) Kernel-side proxy client should return with KErrNone, exits otherwise. sl@0: //! 3) Kernel-side proxy client should return with KErrAlreadyExists, exits otherwise. sl@0: //! 4) Kernel-side proxy client should return with KErrNone, exits otherwise. The associated sl@0: //! TRequestStatus should be set to KErrNone, exits otherwise. sl@0: //! 5) Kernel-side proxy client should return with KErrNone for both API calls, exits otherwise. The associated sl@0: //! TRequestStatus should be set to KErrNone, exits otherwise. sl@0: //! 6) Kernel-side proxy client should return with KErrNone for both API calls, exits otherwise. The associated sl@0: //! TRequestStatus should be set to KErrNone, exits otherwise. sl@0: //! 7) Results should be the same as for steps 1-6. sl@0: //! 8) Kernel-side proxy client should return with KErrNone for each API call, exits otherwise. The associated sl@0: //! TRequestStatus should be set to KErrNone, exits otherwise. sl@0: //! 9) Kernel-side proxy client should return with KErrNone for each API call, exits otherwise. The associated sl@0: //! TRequestStatus should be set to KErrNone, exits otherwise. sl@0: //! 10) Kernel-side proxy client should return with KErrNone for each API call, exits otherwise. The associated sl@0: //! TRequestStatus should be set to KErrNone, exits otherwise. sl@0: //! 11) Kernel-side proxy client should return with KErrNone for each API call, exits otherwise. The associated sl@0: //! TRequestStatus should be set to KErrNone in both cases, exits otherwise. sl@0: //! sl@0: //! @SYMTestPriority High sl@0: //! @SYMTestStatus Implemented sl@0: //---------------------------------------------------------------------------------------------- sl@0: sl@0: LOCAL_C TInt SlaveRxTxNotificationTests() sl@0: // sl@0: // Exercise the Slave channel operation for receive and transmit of data sl@0: // sl@0: sl@0: // The means to supply a buffer to be filled with data received from the Master, and the number of words expected. sl@0: // It is only after the reception of the number of words specified that the notification should be issued sl@0: // (or on under-run/overrun/timeout/bus specific error). sl@0: // sl@0: // The means to supply a buffer with data to be transmitted to the Master, and the number of words to transmit. sl@0: // It is only after the transmission of the number of words specified that the notification should be issued sl@0: // (or under-run/overrun/timeout/bus specific error). sl@0: // sl@0: // The means to enable and disable the events which will trigger the notification callback. These events are: sl@0: // 1) the complete reception of the number of words specified, sl@0: // 2) the complete transmission of the number of words specified, sl@0: // 3) errors: receive buffer under-run (the Master terminates the transaction or reverts the direction of sl@0: // transfer before all expected data has been received), receive buffer overrun sl@0: // (Master attempts to write more data than this channel expected to receive), transmit buffer overrun sl@0: // (Master attempts to read more data than supplied by client), transmit buffer under-run sl@0: // (the Master terminates the transaction or reverts the direction of transfer before all expected data sl@0: // has been transmitted to it), access timeout(1) error, or bus specific error (e.g. collision, framing). sl@0: { sl@0: gTest.Printf(_L("\n\nStarting SlaveRxTxNotificationTests\n")); sl@0: TInt r=KErrNone; sl@0: #ifdef SLAVE_MODE sl@0: sl@0: //Configure and capture a channel sl@0: gTest.Printf(_L("Create and capture channel\n")); sl@0: TUint32 busIdI2c; sl@0: TConfigI2cBufV01* i2cBuf=NULL; sl@0: r=CreateSlaveChanI2cConfig(i2cBuf, busIdI2c, 11); // 11 is the Slave channel number sl@0: gTest(r==KErrNone); sl@0: sl@0: TInt chanId = 0; // Initialise to zero to silence compiler ... sl@0: r=SyncCaptureGChanSlaveI2c(chanId, i2cBuf, busIdI2c); sl@0: gTest(r==KErrNone); sl@0: sl@0: // Update wait times for Master and Client sl@0: // Delegate the operation of this test to the proxy client (iic_client). The proxy will read, modify, and reinstate sl@0: // the timeout values. sl@0: gTest.Printf(_L("Starting UpdateTimeoutValues\n")); sl@0: r=gChanSlaveI2c.UpdateTimeoutValues(busIdI2c, chanId); sl@0: gTest(r==KErrNone); sl@0: sl@0: sl@0: // Receive and transmit buffers must be created by the client in Kernel heap and remain in their ownership throughout. sl@0: // Therefore, the kernel-side proxy will provide the buffer sl@0: // The buffers are of size KRxBufSizeInBytes and KRxBufSizeInBytes (currently 64) sl@0: sl@0: // sl@0: // Rx tests sl@0: // sl@0: sl@0: // For Rx, specify buffer granularity=4 (32-bit words), 8 words to receive, offset of 16 bytes sl@0: // 64 bytes as 16 words: words 0-3 offset, words 4-11 data, words 12-15 unused sl@0: gTest.Printf(_L("Starting RegisterRxBuffer\n")); sl@0: r=gChanSlaveI2c.RegisterRxBuffer(chanId, 4, 8, 16); sl@0: gTest(r==KErrNone); sl@0: // sl@0: // If a buffer is already registered but a notification has not yet been requested the API should return KErrNone sl@0: gTest.Printf(_L("Starting (repeated) RegisterRxBuffer\n")); sl@0: r=gChanSlaveI2c.RegisterRxBuffer(chanId, 4, 8, 16); sl@0: gTest(r==KErrNone); sl@0: // sl@0: // Now set the notification trigger sl@0: TRequestStatus status; sl@0: TInt triggerMask=ERxAllBytes; sl@0: gTest.Printf(_L("Starting SetNotificationTrigger with ERxAllBytes\n")); sl@0: r=gChanSlaveI2c.SetNotificationTrigger(chanId,triggerMask,&status); sl@0: gTest(r==KErrNone); sl@0: // sl@0: // If a buffer is registered and a notification has been requested the API should return KErrAlreadyExists sl@0: gTest.Printf(_L("Starting RegisterRxBuffer (to be rejected)\n")); sl@0: r=gChanSlaveI2c.RegisterRxBuffer(chanId, 4, 8, 16); sl@0: gTest(r==KErrAlreadyExists); sl@0: // sl@0: // Now instruct the bus implementation to represent receipt of the required number of words from the bus master. sl@0: gTest.Printf(_L("Starting SimulateRxNWords\n")); sl@0: r=gChanSlaveI2c.SimulateRxNWords(busIdI2c, chanId, 8); sl@0: gTest(r==KErrNone); sl@0: // sl@0: // Wait for the notification sl@0: User::WaitForRequest(status); sl@0: r=status.Int(); sl@0: if(r != KErrNone) sl@0: { sl@0: gTest.Printf(_L("TRequestStatus value after receiving data = %d\n"),r); sl@0: gTest(r==KErrNone); sl@0: } sl@0: gTest.Printf(_L("Starting Rx test completed OK\n")); sl@0: // sl@0: // Repeat for each error condition. Re-use the buffer previously registered. sl@0: // sl@0: // sl@0: triggerMask=ERxAllBytes|ERxUnderrun; sl@0: gTest.Printf(_L("Starting SetNotificationTrigger with ERxAllBytes\n")); sl@0: r=gChanSlaveI2c.SetNotificationTrigger(chanId,triggerMask,&status); sl@0: gTest(r==KErrNone); sl@0: // Now instruct the bus implementation to represent the bus master transmitting less words than anticipated (Rx Underrun) sl@0: gTest.Printf(_L("Starting SimulateRxNWords for Underrun\n")); sl@0: r=gChanSlaveI2c.SimulateRxNWords(busIdI2c, chanId, 6); sl@0: gTest(r==KErrNone); sl@0: // sl@0: // Wait for the notification sl@0: User::WaitForRequest(status); sl@0: r=status.Int(); sl@0: if(r != KErrNone) sl@0: { sl@0: gTest.Printf(_L("TRequestStatus value after receiving data = %d\n"),r); sl@0: gTest(r==KErrNone); sl@0: } sl@0: gTest.Printf(_L("Rx Underrun test completed OK\n")); sl@0: // Re-set the notification trigger sl@0: triggerMask=ERxAllBytes|ERxOverrun; sl@0: gTest.Printf(_L("Starting SetNotificationTrigger\n")); sl@0: r=gChanSlaveI2c.SetNotificationTrigger(chanId,triggerMask,&status); sl@0: gTest(r==KErrNone); sl@0: // Now instruct the bus implementation to represent the bus master attempting to transmit more words than sl@0: // anticipated (Rx Overrun) sl@0: gTest.Printf(_L("Starting SimulateRxNWords for Overrun\n")); sl@0: r=gChanSlaveI2c.SimulateRxNWords(busIdI2c, chanId, 10); sl@0: gTest(r==KErrNone); sl@0: // sl@0: // Wait for the notification sl@0: User::WaitForRequest(status); sl@0: r=status.Int(); sl@0: if(r != KErrNone) sl@0: { sl@0: gTest.Printf(_L("TRequestStatus value after receiving data = %d\n"),r); sl@0: gTest(r==KErrNone); sl@0: } sl@0: gTest.Printf(_L("Rx Overrun test completed OK\n")); sl@0: sl@0: // sl@0: // Tx tests sl@0: // sl@0: sl@0: // For Tx, specify buffer granularity=4 (32-bit words), 12 words to transmit, offset of 8 bytes sl@0: // 64 bytes as 16 words: words 0-1 offset, words 2-13 data, words 14-15 unused sl@0: gTest.Printf(_L("\nStarting RegisterTxBuffer\n")); sl@0: r=gChanSlaveI2c.RegisterTxBuffer(chanId, 4, 12, 8); sl@0: gTest(r==KErrNone); sl@0: // sl@0: // If a buffer is already registered but a notification has not yet been requested the API should return KErrNone sl@0: gTest.Printf(_L("Starting (repeated) RegisterTxBuffer\n")); sl@0: r=gChanSlaveI2c.RegisterTxBuffer(chanId, 4, 12, 8); sl@0: gTest(r==KErrNone); sl@0: // sl@0: sl@0: // Re-set the notification trigger sl@0: // Now set the notification trigger sl@0: gTest.Printf(_L("Starting SetNotificationTrigger\n")); sl@0: triggerMask=ETxAllBytes; sl@0: r=gChanSlaveI2c.SetNotificationTrigger(chanId,triggerMask,&status); sl@0: gTest(r==KErrNone); sl@0: // sl@0: // If a buffer is already registered, a subsequent request to do the same should return KErrAlreadyExists sl@0: gTest.Printf(_L("Starting RegisterTxBuffer (to be rejected)\n")); sl@0: r=gChanSlaveI2c.RegisterTxBuffer(chanId, 4, 12, 8); sl@0: gTest(r==KErrAlreadyExists); sl@0: // sl@0: // Now instruct the bus implementation to represent transmission of the required number of words to the bus master. sl@0: gTest.Printf(_L("Starting SimulateTxNWords (to be rejected)\n")); sl@0: r=gChanSlaveI2c.SimulateTxNWords(busIdI2c, chanId, 12); sl@0: gTest(r==KErrNone); sl@0: // sl@0: // Wait for the notification sl@0: User::WaitForRequest(status); sl@0: r=status.Int(); sl@0: if(r != KErrNone) sl@0: { sl@0: gTest.Printf(_L("TRequestStatus value after transmitting data = %d\n"),r); sl@0: gTest(r==KErrNone); sl@0: } sl@0: gTest.Printf(_L("Tx test completed OK\n")); sl@0: // sl@0: // Repeat for each error condition. Re-use the buffer previously registered sl@0: // sl@0: // Re-set the notification trigger sl@0: gTest.Printf(_L("Starting SetNotificationTrigger\n")); sl@0: triggerMask=ETxAllBytes|ETxOverrun; sl@0: r=gChanSlaveI2c.SetNotificationTrigger(chanId,triggerMask,&status); sl@0: gTest(r==KErrNone); sl@0: // Now instruct the bus implementation to represent transmission of less than the required number of words sl@0: // to the bus master (Tx Overrun) sl@0: gTest.Printf(_L("Starting SimulateTxNWords for Tx Overrun\n")); sl@0: r=gChanSlaveI2c.SimulateTxNWords(busIdI2c, chanId, 10); sl@0: gTest(r==KErrNone); sl@0: // sl@0: // Wait for the notification sl@0: User::WaitForRequest(status); sl@0: r=status.Int(); sl@0: if(r != KErrNone) sl@0: { sl@0: gTest.Printf(_L("TRequestStatus value after transmitting data = %d\n"),r); sl@0: gTest(r==KErrNone); sl@0: } sl@0: gTest.Printf(_L("Tx Overrun test completed OK\n")); sl@0: // Re-set the notification trigger sl@0: triggerMask=ETxAllBytes|ETxUnderrun; sl@0: gTest.Printf(_L("Starting SetNotificationTrigger\n")); sl@0: r=gChanSlaveI2c.SetNotificationTrigger(chanId,triggerMask,&status); sl@0: gTest(r==KErrNone); sl@0: // Now instruct the bus implementation to represent the bus master attempting to read more words than sl@0: // anticipated (Tx Underrun) sl@0: gTest.Printf(_L("Starting SimulateTxNWords for Tx Underrun\n")); sl@0: r=gChanSlaveI2c.SimulateTxNWords(busIdI2c, chanId, 14); sl@0: gTest(r==KErrNone); sl@0: // sl@0: // Wait for the notification sl@0: User::WaitForRequest(status); sl@0: r=status.Int(); sl@0: if(r != KErrNone) sl@0: { sl@0: gTest.Printf(_L("TRequestStatus value after transmitting data = %d\n"),r); sl@0: gTest(r==KErrNone); sl@0: } sl@0: gTest.Printf(_L("Tx Underrun test completed OK\n")); sl@0: sl@0: // sl@0: // Simultaneous Rx,Tx tests sl@0: // sl@0: // For these tests, the proxy client (iic_slaveclient) will check that the expected results are witnessed sl@0: // in the required order, and will complete the TRequestStatus when the sequence is complete (or error occurs). sl@0: // sl@0: // Set the notification trigger for both Rx and Tx sl@0: triggerMask=ERxAllBytes|ETxAllBytes; sl@0: gTest.Printf(_L("\nStarting SetNotificationTrigger with ERxAllBytes|ETxAllBytes\n")); sl@0: r=gChanSlaveI2c.SetNotificationTrigger(chanId,triggerMask,&status); sl@0: gTest(r==KErrNone); sl@0: // Now instruct the bus implementation to represent receipt of the required number of words from the bus master. sl@0: gTest.Printf(_L("Starting SimulateRxNWords\n")); sl@0: r=gChanSlaveI2c.SimulateRxNWords(busIdI2c, chanId, 8); sl@0: gTest(r==KErrNone); sl@0: // Now instruct the bus implementation to represent transmission of the required number of words to the bus master. sl@0: gTest.Printf(_L("Starting SimulateTxNWords\n")); sl@0: r=gChanSlaveI2c.SimulateTxNWords(busIdI2c, chanId, 12); sl@0: gTest(r==KErrNone); sl@0: // sl@0: // Wait for the notification sl@0: User::WaitForRequest(status); sl@0: r=status.Int(); sl@0: if(r != KErrNone) sl@0: { sl@0: gTest.Printf(_L("TRequestStatus value after receiving and transmitting data = %d\n"),r); sl@0: gTest(r==KErrNone); sl@0: } sl@0: gTest.Printf(_L("Rx, Tx test completed OK\n")); sl@0: // sl@0: // Set the notification trigger for both Rx and Tx sl@0: gTest.Printf(_L("Starting SetNotificationTrigger with ERxAllBytes|ETxAllBytes\n")); sl@0: triggerMask=ERxAllBytes|ETxAllBytes; sl@0: r=gChanSlaveI2c.SetNotificationTrigger(chanId,triggerMask,&status); sl@0: gTest(r==KErrNone); sl@0: // Now instruct the bus implementation to represent transmission of the required number of words to the bus master. sl@0: gTest.Printf(_L("Starting SimulateTxNWords\n")); sl@0: r=gChanSlaveI2c.SimulateTxNWords(busIdI2c, chanId, 12); sl@0: gTest(r==KErrNone); sl@0: // Now instruct the bus implementation to represent receipt of the required number of words from the bus master. sl@0: gTest.Printf(_L("Starting SimulateRxNWords\n")); sl@0: r=gChanSlaveI2c.SimulateRxNWords(busIdI2c, chanId, 8); sl@0: gTest(r==KErrNone); sl@0: // sl@0: // Wait for the notification sl@0: User::WaitForRequest(status); sl@0: r=status.Int(); sl@0: if(r != KErrNone) sl@0: { sl@0: gTest.Printf(_L("TRequestStatus value after receiving and transmitting data = %d\n"),r); sl@0: gTest(r==KErrNone); sl@0: } sl@0: gTest.Printf(_L("Tx, Rx test completed OK\n")); sl@0: // sl@0: // Set the notification trigger for both Rx and Tx sl@0: gTest.Printf(_L("Starting SetNotificationTrigger with ERxAllBytes|ETxAllBytes\n")); sl@0: triggerMask=ERxAllBytes|ETxAllBytes; sl@0: r=gChanSlaveI2c.SetNotificationTrigger(chanId,triggerMask,&status); sl@0: gTest(r==KErrNone); sl@0: // Now instruct the bus implementation to represent simultaneous transmission of the required number of words (12) sl@0: // to the bus master and receipt of the required number of words (8) from the bus master sl@0: gTest.Printf(_L("Starting SimulateRxTxNWords\n")); sl@0: r=gChanSlaveI2c.SimulateRxTxNWords(busIdI2c, chanId, 8, 12); sl@0: gTest(r==KErrNone); sl@0: // sl@0: // Wait for the notification sl@0: User::WaitForRequest(status); sl@0: r=status.Int(); sl@0: if(r != KErrNone) sl@0: { sl@0: gTest.Printf(_L("TRequestStatus value after receiving and transmitting data = %d\n"),r); sl@0: gTest(r==KErrNone); sl@0: } sl@0: gTest.Printf(_L("Tx with Rx test completed OK\n")); sl@0: sl@0: // Clear the trigger mask - this is just invoking SetNotificationTrigger with a zero trigger sl@0: // so that no subsequent triggers are expected (and so no TRequestStatus is provided) sl@0: gTest.Printf(_L("Starting SetNotificationTrigger with 0\n")); sl@0: triggerMask=0; sl@0: r=gChanSlaveI2c.SetNotifNoTrigger(chanId,triggerMask); sl@0: gTest(r==KErrNone); sl@0: sl@0: // sl@0: // Rx Overrun and Tx Underrun when both Rx and Tx notifications are requested sl@0: // sl@0: gTest.Printf(_L("Starting RxOverrun-TxUnderrun with simultaneous Rx,Tx notification requests\n")); sl@0: gChanSlaveI2c.TestOverrunUnderrun(busIdI2c,chanId,status); sl@0: // sl@0: // Wait for the notification sl@0: User::WaitForRequest(status); sl@0: r=status.Int(); sl@0: if(r != KErrNone) sl@0: { sl@0: gTest.Printf(_L("TRequestStatus value after RxOverrun-TxUnderrun with simultaneous Rx,Tx notification requests= %d\n"),r); sl@0: gTest(r==KErrNone); sl@0: } sl@0: gTest.Printf(_L("RxOverrun-TxUnderrun with simultaneous Rx,Tx notification requests test completed OK\n")); sl@0: sl@0: sl@0: // sl@0: // Bus Error tests sl@0: // sl@0: sl@0: // Simulate a bus error sl@0: // A bus error will cause all pending bus activity to be aborted. sl@0: // Request a notification, then simulate a bus error sl@0: triggerMask=ERxAllBytes|ETxAllBytes; sl@0: r=gChanSlaveI2c.SetNotificationTrigger(chanId,triggerMask,&status); sl@0: gTest(r==KErrNone); sl@0: gTest.Printf(_L("Starting SimulateBusErr\n")); sl@0: r = gChanSlaveI2c.SimulateBusErr(busIdI2c,chanId); sl@0: gTest(r==KErrNone); sl@0: // sl@0: // Wait for the notification sl@0: User::WaitForRequest(status); sl@0: r=status.Int(); sl@0: if(r != KErrNone) sl@0: { sl@0: gTest.Printf(_L("TRequestStatus value after receiving data = %d\n"),r); sl@0: gTest(r==KErrNone); sl@0: } sl@0: gTest.Printf(_L("Bus error test completed OK\n")); sl@0: sl@0: // Clear the trigger mask and prepare for the next test sl@0: // This is unnecessary if the SetNotificationTrigger for the following test sl@0: // is called within the timeout period applied for Client responses ... sl@0: // but it represents a Client ending a transaction cleanly, and so is sl@0: // left here as an example sl@0: gTest.Printf(_L("\nStarting SetNotificationTrigger with 0\n")); sl@0: triggerMask=0; sl@0: r=gChanSlaveI2c.SetNotificationTrigger(chanId,triggerMask,&status); sl@0: gTest(r==KErrNone); sl@0: sl@0: // Simulate Master timeout sl@0: // Do this by: sl@0: // - Requesting a trigger for Tx sl@0: // - simulating the Master performing a read (ie the PSL indicates a Tx event) to start the transaction sl@0: // - provide a buffer for Tx, and request notification of Tx events, ie wait for Master response sl@0: // - block the PSL Tx notification to the PIL, so that the PIL timeout timer expires when a simulated Tx event sl@0: // is next requested sl@0: // sl@0: // Indicate the test to be performed sl@0: gTest.Printf(_L("\nStarting BlockNotification\n")); sl@0: // Register a buffer for Tx, then set the notification trigger sl@0: gTest.Printf(_L("RegisterTxBuffer - for Master to start the transaction\n")); sl@0: r=gChanSlaveI2c.RegisterTxBuffer(chanId, 4, 12, 8); sl@0: gTest(r==KErrNone); sl@0: gTest.Printf(_L("SetNotificationTrigger - for Master to start the transaction\n")); sl@0: triggerMask=ETxAllBytes; sl@0: r=gChanSlaveI2c.SetNotificationTrigger(chanId,triggerMask,&status); sl@0: gTest(r==KErrNone); sl@0: // Now instruct the bus implementation to simulate the Master reading the expected number of words sl@0: gTest.Printf(_L("Starting SimulateTxNWords\n")); sl@0: r=gChanSlaveI2c.SimulateTxNWords(busIdI2c, chanId, 12); sl@0: gTest(r==KErrNone); sl@0: // Wait for the notification sl@0: User::WaitForRequest(status); sl@0: gTest.Printf(_L("Status request completed\n")); sl@0: r=status.Int(); sl@0: if(r != KErrNone) sl@0: { sl@0: gTest.Printf(_L("TRequestStatus value after receiving data = %d\n"),r); sl@0: gTest(r==KErrNone); sl@0: } sl@0: // Client is now expected to perform its part of the transaction - so pretend we need another Tx sl@0: // - but block completion of the Tx so that we generate a bus error sl@0: gTest.Printf(_L("SetNotificationTrigger - for second part of the transaction\n")); sl@0: triggerMask=ETxAllBytes; sl@0: r=gChanSlaveI2c.SetNotificationTrigger(chanId,triggerMask,&status); sl@0: gTest(r==KErrNone); sl@0: gTest.Printf(_L("BlockNotification\n")); sl@0: r=gChanSlaveI2c.BlockNotification(busIdI2c, chanId); sl@0: gTest(r==KErrNone); sl@0: // Now instruct the bus implementation to represent the bus master attempting to read the required number of words sl@0: gTest.Printf(_L("\nStarting SimulateTxNWords\n")); sl@0: r=gChanSlaveI2c.SimulateTxNWords(busIdI2c, chanId, 12); sl@0: gTest(r==KErrNone); sl@0: // sl@0: // Wait for the notification sl@0: User::WaitForRequest(status); sl@0: r=status.Int(); sl@0: if(r != KErrNone) sl@0: { sl@0: gTest.Printf(_L("TRequestStatus value after receiving data = %d\n"),r); sl@0: gTest(r==KErrNone); sl@0: } sl@0: gTest.Printf(_L("Blocked notification test completed OK\n")); sl@0: // Re-set the notification trigger - for the 'blocked' Tx sl@0: // This is required because, in the event of a bus error, the set of requested Rx,Tx sl@0: // flags are cleared sl@0: gTest.Printf(_L("Starting SetNotificationTrigger with ETxAllBytes\n")); sl@0: triggerMask=ETxAllBytes; sl@0: r=gChanSlaveI2c.SetNotificationTrigger(chanId,triggerMask,&status); sl@0: gTest(r==KErrNone); sl@0: // Remove the block sl@0: gTest.Printf(_L("Starting UnblockNotification\n")); sl@0: r=gChanSlaveI2c.UnblockNotification(busIdI2c, chanId); sl@0: gTest(r==KErrNone); sl@0: // sl@0: // Wait for the notification sl@0: User::WaitForRequest(status); sl@0: r=status.Int(); sl@0: if(r != KErrNone) sl@0: { sl@0: gTest.Printf(_L("TRequestStatus value after receiving data = %d\n"),r); sl@0: gTest(r==KErrNone); sl@0: } sl@0: gTest.Printf(_L("UnBlocked notification test completed OK\n")); sl@0: // Clear the trigger mask sl@0: gTest.Printf(_L("Starting SetNotificationTrigger with 0\n")); sl@0: triggerMask=0; sl@0: r=gChanSlaveI2c.SetNotificationTrigger(chanId,triggerMask,&status); sl@0: gTest(r==KErrNone); sl@0: sl@0: // Release the channel sl@0: r = gChanSlaveI2c.ReleaseChannel( chanId ); sl@0: gTest(r==KErrNone); sl@0: sl@0: delete i2cBuf; sl@0: #else sl@0: gTest.Printf(_L("\nSlaveRxTxNotificationTests only supported when SLAVE_MODE is defined\n")); sl@0: #endif sl@0: sl@0: return r; sl@0: } sl@0: sl@0: //---------------------------------------------------------------------------------------------- sl@0: //! @SYMTestCaseID KBASE-T_IIC-2404 sl@0: //! @SYMTestType UT sl@0: //! @SYMPREQ PREQ2128,2129 sl@0: //! @SYMTestCaseDesc This test case tests that MasterSlave channels can only be used in one mode at a time, and that sl@0: //! if captured for Slave operation or with transactions queued for Master operation the channel can sl@0: //! not be de-registered. sl@0: //! @SYMTestActions 0) Capture the channel for Slave operation. Attempt to synchronously queue a transaction sl@0: //! on the channel. Attempt to asynchronously queue a transaction on the channel. Attempt sl@0: //! to de-register the channel.Release the Slave channel sl@0: //! sl@0: //! 1) Use controlio to block completion of queued transactions. Request asynchronous queue sl@0: //! transaction. Attempt to capture the channel for Slave operation. Attempt to de-register sl@0: //! the channel. Unblock completion of transactions and wait for the TRequestStatus for the sl@0: //! transaction to be completed. sl@0: //! sl@0: //! @SYMTestExpectedResults 0) Once captured for Slave operation, attempts to queue a transaction or de-register the channel sl@0: //! return KErrInUse, exits otherwise. sl@0: //! 1) With a transaction queued, attempt to capture the channel returns KErrInUse, exits otherwise. sl@0: //! Attempt to de-register channel returns KErrInUse, exits otherwise. The TRequestStatus should sl@0: //! be set to KErrTimedOut, exits otherwise. sl@0: //! sl@0: //! sl@0: //! @SYMTestPriority High sl@0: //! @SYMTestStatus Implemented sl@0: //---------------------------------------------------------------------------------------------- sl@0: LOCAL_C TInt MasterSlaveAcquisitionTests() sl@0: // sl@0: // Test to check that: sl@0: // (1) A Master-Slave channel that has been captured for use in Slave mode will not allow requests for sl@0: // queing transactions to be accepted sl@0: // (2) A Master-Slave channel that has been captured for use in Slave mode can not be de-registered sl@0: // (3) A Master-Slave channel that has one or more transactions queued in its Master channel transaction queue sl@0: // can not be captured for use in Slave Made sl@0: // (4) A Master-Slave channel that has one or more transactions queued in its Master channel transaction queue sl@0: // can not be de-registered sl@0: // sl@0: { sl@0: gTest.Printf(_L("\n\nStarting MasterSlaveAcquisitionTests\n")); sl@0: TInt r=KErrNone; sl@0: sl@0: #if defined(MASTER_MODE) && defined(SLAVE_MODE) sl@0: // Create a Master-Slave channel sl@0: RBusDevIicClient chanMasterSlaveI2c; sl@0: TBufC<18> proxyName; sl@0: if(!aStandAloneChan) sl@0: proxyName = KIicProxyFileNameRoot; sl@0: else sl@0: proxyName = KIicProxyFileNameRootCtrlLess; sl@0: r = chanMasterSlaveI2c.Open(proxyName); sl@0: gTest(r==KErrNone); sl@0: r = chanMasterSlaveI2c.InitSlaveClient(); // Initialise callback used for Slave processing sl@0: gTest(r==KErrNone); sl@0: // sl@0: // Capture the channel for Slave operation sl@0: // Attempt to synchronously queue a transaction on the channel - expect KErrInUse as a response sl@0: // Attempt to asynchronously queue a transaction on the channel - expect KErrInUse as a response sl@0: // Attempt to de-register the channel - expect KErrInUse as a response sl@0: // Release the Slave channel sl@0: // sl@0: // Create a I2C configuration buffer and the configuration data for use in capturing gChanSlaveI2c sl@0: TUint32 busIdI2c = 0; sl@0: TConfigI2cBufV01* i2cBuf=NULL; sl@0: r=CreateSlaveChanI2cConfig(i2cBuf, busIdI2c, 12); // 12 is the MasterSlave channel number sl@0: gTest(r==KErrNone); sl@0: TInt chanId; sl@0: sl@0: gTest.Printf(_L("\nStarting synchronous CaptureChannel \n")); sl@0: r = chanMasterSlaveI2c.CaptureChannel(busIdI2c, i2cBuf, chanId ); sl@0: gTest.Printf(_L("Synchronous CaptureChannel returned = %d, chanId=0x%x\n"),r,chanId); sl@0: gTest(r==KErrNone); sl@0: // sl@0: _LIT(halfDuplexText,"Half Duplex Text"); sl@0: TBuf8<17> halfDuplexBuf_8; sl@0: halfDuplexBuf_8.Copy(halfDuplexText); sl@0: TUsideTferDesc* tfer = NULL; sl@0: r=CreateSingleUserSideTransfer(tfer, EMasterWrite, 8, &halfDuplexBuf_8, NULL); sl@0: if(r!=KErrNone) sl@0: return r; sl@0: if(tfer==NULL) sl@0: return KErrGeneral; sl@0: // sl@0: TUsideTracnDesc* tracn = NULL; sl@0: r = CreateSingleUserSideTransaction(tracn, EI2c, i2cBuf, tfer, NULL, 0, NULL, NULL); sl@0: if(r!=KErrNone) sl@0: return r; sl@0: if(tracn==NULL) sl@0: return KErrGeneral; sl@0: sl@0: sl@0: gTest.Printf(_L("\nStarting synchronous QueueTransaction \n")); sl@0: r = chanMasterSlaveI2c.QueueTransaction(busIdI2c, tracn); sl@0: gTest.Printf(_L("Synchronous QueueTransaction returned = %d\n"),r); sl@0: gTest(r==KErrInUse); sl@0: gTest.Printf(_L("\nStarting asynchronous QueueTransaction \n")); sl@0: TRequestStatus status; sl@0: chanMasterSlaveI2c.QueueTransaction(status, busIdI2c, tracn); sl@0: User::WaitForRequest(status); sl@0: if(status != KErrInUse) sl@0: { sl@0: gTest.Printf(_L("TRequestStatus value after queue = %d\n"),status.Int()); sl@0: gTest(r==KErrInUse); sl@0: } sl@0: // sl@0: // // If it is stand-alone channel, the client is responsible for channel creation. sl@0: // // So the RegisterChan and DeRegisterChan are not needed. sl@0: if(aStandAloneChan == 0) sl@0: { sl@0: gTest.Printf(_L("\nStarting deregistration of captured channel\n")); sl@0: r = chanMasterSlaveI2c.DeRegisterChan(busIdI2c); sl@0: gTest.Printf(_L("DeRegisterChan returned = %d\n"),r); sl@0: gTest(r==KErrInUse); sl@0: } sl@0: sl@0: gTest.Printf(_L("\nInvoke ReleaseChannel for chanId=0x%x \n"),chanId); sl@0: r = chanMasterSlaveI2c.ReleaseChannel( chanId ); sl@0: gTest.Printf(_L("ReleaseChannel returned = %d\n"),r); sl@0: gTest(r==KErrNone); sl@0: sl@0: // sl@0: // Use ControlIO/StaticExtension to block transactions on the Master Channel sl@0: // Queue an asynchronous transaction on the channel sl@0: // Attempt to capture the channel for Slave operation - expect KErrInUse as a response sl@0: // Attempt to de-register the channel - expect KErrInUse as a response sl@0: // Unblock the channel sl@0: // Check for (timed out) completion of the transaction sl@0: // sl@0: gTest.Printf(_L("Invoking BlockReqCompletion\n")); sl@0: r = chanMasterSlaveI2c.BlockReqCompletion(busIdI2c); sl@0: gTest.Printf(_L("BlockReqCompletion returned = %d\n"),r); sl@0: // sl@0: gTest.Printf(_L("Queueing first transaction \n")); sl@0: chanMasterSlaveI2c.QueueTransaction(status, busIdI2c, tracn); sl@0: // sl@0: User::After(50000); sl@0: // sl@0: gTest.Printf(_L("\nStarting synchronous CaptureChannel \n")); sl@0: r = chanMasterSlaveI2c.CaptureChannel(busIdI2c, i2cBuf, chanId ); sl@0: gTest.Printf(_L("Synchronous CaptureChannel returned = %d, chanId=0x%x\n"),r,chanId); sl@0: gTest(r==KErrInUse); sl@0: sl@0: // If it is stand-alone channel, the client is responsible for channel creation. sl@0: // So the RegisterChan and DeRegisterChan are not needed. sl@0: if(aStandAloneChan == 0) sl@0: { sl@0: gTest.Printf(_L("\nStarting deregistration of channel\n")); sl@0: r = chanMasterSlaveI2c.DeRegisterChan(busIdI2c); sl@0: gTest.Printf(_L("DeRegisterChan returned = %d\n"),r); sl@0: gTest(r==KErrInUse); sl@0: } sl@0: gTest.Printf(_L("Invoking UnlockReqCompletion\n")); sl@0: r = chanMasterSlaveI2c.UnblockReqCompletion(busIdI2c); sl@0: gTest.Printf(_L("UnblockReqCompletion returned = %d\n"),r); sl@0: // sl@0: User::After(50000); sl@0: // sl@0: User::WaitForRequest(status); sl@0: r=status.Int(); sl@0: if(r != KErrTimedOut) sl@0: { sl@0: gTest.Printf(_L("TRequestStatus value after queue = %d\n"),r); sl@0: gTest(r==KErrTimedOut); sl@0: } sl@0: r=KErrNone; // Ensure error code is not propagated sl@0: sl@0: delete i2cBuf; sl@0: delete tfer; sl@0: delete tracn; sl@0: chanMasterSlaveI2c.Close(); sl@0: #else sl@0: gTest.Printf(_L("\nMasterSlaveAcquisitionTests only supported when both MASTER_MODE and SLAVE_MODE are defined\n")); sl@0: #endif sl@0: sl@0: return r; sl@0: } sl@0: sl@0: //---------------------------------------------------------------------------------------------- sl@0: //! @SYMTestCaseID KBASE-T_IIC-2404 sl@0: //! @SYMTestType UT sl@0: //! @SYMDEF DEF141732 sl@0: //! @SYMTestCaseDesc This test case tests the inline functions of DIicBusChannel interface. sl@0: //! @SYMTestActions Call Kernel-side proxy client function to perform interface tests. sl@0: //! @SYMTestExpectedResults Kernel-side proxy client should return with KErrNone. sl@0: //! @SYMTestPriority Medium sl@0: //! @SYMTestStatus Implemented sl@0: //---------------------------------------------------------------------------------------------- sl@0: LOCAL_C TInt IicInterfaceInlineTests() sl@0: { sl@0: if(aStandAloneChan == 1) sl@0: { sl@0: gTest.Printf(_L("\n\nStarting IicInterfaceInlineTests\n")); sl@0: TInt r=KErrNone; sl@0: r = gChanMasterSpi.TestIiicChannelInlineFunc(); sl@0: return r; sl@0: } sl@0: else sl@0: { sl@0: gTest.Printf(_L("\nIicInterfaceInlineTests can only be run in Standalone mode\n")); sl@0: return KErrNone; sl@0: } sl@0: } sl@0: sl@0: LOCAL_C TInt RunTests() sl@0: // sl@0: // Utility method to invoke the separate tests sl@0: // sl@0: { sl@0: TInt r =KErrNone; sl@0: r = IicInterfaceInlineTests(); sl@0: if(r!=KErrNone) sl@0: return r; sl@0: sl@0: r = MasterBasicTests(); sl@0: if(r!=KErrNone) sl@0: return r; sl@0: sl@0: r = SlaveRxTxNotificationTests(); sl@0: if(r!=KErrNone) sl@0: return r; sl@0: sl@0: r = SlaveChannelCaptureReleaseTests(); sl@0: if(r!=KErrNone) sl@0: return r; sl@0: sl@0: r = MasterExtTests(KTransactionWithPreamble); sl@0: if(r!=KErrNone) sl@0: return r; sl@0: sl@0: r = MasterExtTests(KTransactionWithMultiTransc); sl@0: if(r!=KErrNone) sl@0: return r; sl@0: sl@0: r = MasterExtTests(KTransactionWithMultiTransc|KTransactionWithPreamble); sl@0: if(r!=KErrNone) sl@0: return r; sl@0: sl@0: r = MasterTransactionTests(); sl@0: if(r!=KErrNone) sl@0: return r; sl@0: sl@0: r = MasterSlaveAcquisitionTests(); sl@0: if(r!=KErrNone) sl@0: return r; sl@0: sl@0: return KErrNone; sl@0: } sl@0: sl@0: GLDEF_C TInt E32Main() sl@0: // sl@0: // Main sl@0: // sl@0: { sl@0: gTest.Title(); sl@0: gTest.Start(_L("Test IIC API\n")); sl@0: sl@0: TInt r = KErrNone; sl@0: sl@0: // Turn off lazy dll unloading sl@0: RLoader l; sl@0: gTest(l.Connect()==KErrNone); sl@0: gTest(l.CancelLazyDllUnload()==KErrNone); sl@0: l.Close(); sl@0: sl@0: #ifdef IIC_SIMULATED_PSL sl@0: gTest.Next(_L("Start the IIC with controller test\n")); sl@0: aStandAloneChan = 0; sl@0: gTest.Next(_L("Load Simulated IIC PSL bus driver")); sl@0: r = User::LoadPhysicalDevice(KIicPslFileName); sl@0: gTest.Printf(_L("return value r=%d"),r); sl@0: gTest(r==KErrNone || r==KErrAlreadyExists); sl@0: sl@0: gTest.Next(_L("Load Simulated PSL SPI bus driver")); sl@0: r = User::LoadPhysicalDevice(KSpiFileName); sl@0: gTest.Printf(_L("return value r=%d"),r); sl@0: gTest(r==KErrNone || r==KErrAlreadyExists); sl@0: sl@0: gTest.Next(_L("Load Simulated PSL I2C bus driver")); sl@0: r = User::LoadPhysicalDevice(KI2cFileName); sl@0: gTest.Printf(_L("return value r=%d"),r); sl@0: gTest(r==KErrNone || r==KErrAlreadyExists); sl@0: sl@0: gTest.Next(_L("Load kernel-side proxy IIC client")); sl@0: r = User::LoadLogicalDevice(KIicProxyFileName); sl@0: gTest(r==KErrNone || r==KErrAlreadyExists); sl@0: sl@0: gTest.Next(_L("Load kernel-side proxy IIC slave client")); sl@0: r = User::LoadLogicalDevice(KIicProxySlaveFileName); sl@0: gTest(r==KErrNone || r==KErrAlreadyExists); sl@0: sl@0: __KHEAP_MARK; sl@0: // First ascertain what bus options are available. sl@0: sl@0: // SPI has Master channel numbers 1,2 and 4, Slave channel number 3 sl@0: // Open a Master SPI channel to the kernel side proxy sl@0: TBufC<30> proxyName(KIicProxyFileNameRoot); sl@0: r = gChanMasterSpi.Open(proxyName); sl@0: gTest(r==KErrNone); sl@0: sl@0: // I2C has Master channel numbers 10 and 11, if built with MASTER_MODE, only sl@0: // I2C has Slave channel numbers 12 and 13, if built with SLAVE_MODE, only sl@0: // I2C has Master channel number 10 and Slave channel numer 11 if built with both MASTER_MODE and SLAVE_MODE sl@0: // Open a Master I2C channel to the kernel side proxy sl@0: r = gChanMasterI2c.Open(proxyName); sl@0: gTest(r==KErrNone); sl@0: TBufC<15> proxySlaveName(KIicProxySlaveFileNameRoot); sl@0: r = gChanSlaveI2c.Open(proxySlaveName); sl@0: gTest(r==KErrNone); sl@0: r = gChanSlaveI2c.InitSlaveClient(); sl@0: gTest(r==KErrNone); sl@0: sl@0: // Instigate tests sl@0: r = RunTests(); sl@0: gTest(r==KErrNone); sl@0: sl@0: gTest.Printf(_L("Tests completed OK, about to close channel\n")); sl@0: sl@0: gChanMasterSpi.Close(); sl@0: gChanMasterI2c.Close(); sl@0: gChanSlaveI2c.Close(); sl@0: sl@0: UserSvr::HalFunction(EHalGroupKernel, EKernelHalSupervisorBarrier, 0, 0); sl@0: __KHEAP_MARKEND; sl@0: sl@0: gTest.Next(_L("Free kernel-side proxy IIC client")); sl@0: TInt err = User::FreeLogicalDevice(KIicProxyFileNameRoot); sl@0: gTest(err==KErrNone || err==KErrAlreadyExists); sl@0: sl@0: gTest.Next(_L("Free kernel-side proxy IIC slave client")); sl@0: err = User::FreeLogicalDevice(KIicProxySlaveFileNameRoot); sl@0: gTest(err==KErrNone || err==KErrAlreadyExists); sl@0: sl@0: gTest.Next(_L("Free Simulated PSL I2C bus driver")); sl@0: err = User::FreePhysicalDevice(KI2cFileName); sl@0: gTest(err==KErrNone); sl@0: sl@0: gTest.Next(_L("Free Simulated PSL SPI bus driver")); sl@0: err = User::FreePhysicalDevice(KSpiFileName); sl@0: gTest(err==KErrNone); sl@0: sl@0: gTest.Next(_L("Free Simulated IIC PSL bus driver")); sl@0: err = User::FreePhysicalDevice(KIicPslFileNameRoot); sl@0: gTest(err==KErrNone); sl@0: sl@0: gTest.Next(_L("Start the controller-less IIC test\n")); sl@0: aStandAloneChan = 1; sl@0: sl@0: gTest.Next(_L("Load Simulated PSL SPI bus driver")); sl@0: r = User::LoadPhysicalDevice(KSpiFileNameCtrlLess); sl@0: gTest.Printf(_L("return value r=%d"),r); sl@0: gTest(r==KErrNone || r==KErrAlreadyExists); sl@0: sl@0: gTest.Next(_L("Load Simulated PSL I2C bus driver")); sl@0: r = User::LoadPhysicalDevice(KI2cFileNameCtrlLess); sl@0: gTest.Printf(_L("return value r=%d"),r); sl@0: gTest(r==KErrNone || r==KErrAlreadyExists); sl@0: sl@0: gTest.Next(_L("Load kernel-side proxy IIC client")); sl@0: r = User::LoadLogicalDevice(KIicProxyFileNameCtrlLess); sl@0: gTest(r==KErrNone || r==KErrAlreadyExists); sl@0: sl@0: gTest.Next(_L("Load kernel-side proxy IIC slave client")); sl@0: r = User::LoadLogicalDevice(KIicProxySlaveFileNameCtrlLess); sl@0: gTest(r==KErrNone || r==KErrAlreadyExists); sl@0: sl@0: // First ascertain what bus options are available. sl@0: __KHEAP_MARK; sl@0: // SPI has Master channel numbers 1,2 and 4, Slave channel number 3 sl@0: // Open a Master SPI channel to the kernel side proxy sl@0: TBufC<30> proxyNameCtrlLess(KIicProxyFileNameRootCtrlLess); sl@0: r = gChanMasterSpi.Open(proxyNameCtrlLess); sl@0: gTest(r==KErrNone); sl@0: sl@0: // I2C has Master channel numbers 10 and 11, if built with MASTER_MODE, only sl@0: // I2C has Slave channel numbers 12 and 13, if built with SLAVE_MODE, only sl@0: // I2C has Master channel number 10 and Slave channel numer 11 if built with both MASTER_MODE and SLAVE_MODE sl@0: // Open a Master I2C channel to the kernel side proxy sl@0: r = gChanMasterI2c.Open(proxyNameCtrlLess); sl@0: sl@0: gTest(r==KErrNone); sl@0: TBufC<35> proxySlaveNameCtrlLess(KIicProxySlaveFileNameRootCtrlLess); sl@0: sl@0: r = gChanSlaveI2c.Open(proxySlaveNameCtrlLess); sl@0: gTest(r==KErrNone); sl@0: r = gChanSlaveI2c.InitSlaveClient(); sl@0: gTest(r==KErrNone); sl@0: sl@0: // Instigate tests sl@0: r = RunTests(); sl@0: gTest(r==KErrNone); sl@0: sl@0: gTest.Printf(_L("Tests completed OK, about to close channel\n")); sl@0: sl@0: gChanMasterSpi.Close(); sl@0: gChanMasterI2c.Close(); sl@0: gChanSlaveI2c.Close(); sl@0: sl@0: UserSvr::HalFunction(EHalGroupKernel, EKernelHalSupervisorBarrier, 0, 0); sl@0: __KHEAP_MARKEND; sl@0: sl@0: gTest.Next(_L("Free kernel-side proxy IIC client")); sl@0: sl@0: err = User::FreeLogicalDevice(KIicProxyFileNameRootCtrlLess); sl@0: gTest(err==KErrNone || err==KErrAlreadyExists); sl@0: gTest.Next(_L("Free kernel-side proxy IIC slave client")); sl@0: err = User::FreeLogicalDevice(KIicProxySlaveFileNameRootCtrlLess); sl@0: gTest(err==KErrNone || err==KErrAlreadyExists); sl@0: sl@0: gTest.Next(_L("Free Simulated PSL I2C bus driver")); sl@0: err = User::FreePhysicalDevice(KI2cFileNameCtrlLess); sl@0: gTest(err==KErrNone); sl@0: sl@0: gTest.Next(_L("Free Simulated PSL SPI bus driver")); sl@0: err = User::FreePhysicalDevice(KSpiFileNameCtrlLess); sl@0: gTest(err==KErrNone); sl@0: #else sl@0: gTest.Printf(_L("Don't do the test if it is not IIC_SIMULATED_PSL")); sl@0: #endif sl@0: gTest.End(); sl@0: return r; sl@0: } sl@0: