sl@0: // Copyright (c) 1998-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\misc\t_lbk.cpp sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: sl@0: RTest test(_L("LoopBack")); sl@0: sl@0: #define TEST(c) ((void)((c)||(test.Printf(_L("Failed at line %d\n"),__LINE__),test.Getch(),test(0),0))) sl@0: sl@0: const TInt KBufferSize=4096; sl@0: sl@0: _LIT(KLddName,"ECOMM"); sl@0: _LIT(KPddName,"EUART"); sl@0: sl@0: TUint8 Buffer[2*KBufferSize]; sl@0: sl@0: void LoadCommDrivers() sl@0: { sl@0: test.Printf(_L("Load LDD\n")); sl@0: TInt r=User::LoadLogicalDevice(KLddName); sl@0: TEST(r==KErrNone || r==KErrAlreadyExists); sl@0: sl@0: TInt i; sl@0: TInt n=0; sl@0: for (i=-1; i<10; ++i) sl@0: { sl@0: TBuf<16> pddName=KPddName(); sl@0: if (i>=0) sl@0: pddName.Append('0'+i); sl@0: TInt r=User::LoadPhysicalDevice(pddName); sl@0: if (r==KErrNone || r==KErrAlreadyExists) sl@0: { sl@0: ++n; sl@0: test.Printf(_L("%S found\n"),&pddName); sl@0: } sl@0: } sl@0: TEST(n!=0); sl@0: } sl@0: sl@0: GLDEF_C TInt E32Main() sl@0: { sl@0: RThread().SetPriority(EPriorityAbsoluteForeground); sl@0: test.SetLogged(EFalse); sl@0: test.Title(); sl@0: sl@0: TBuf<256> cmd; sl@0: User::CommandLine(cmd); sl@0: TInt port=0; sl@0: if (cmd.Length()!=0) sl@0: { sl@0: TUint8 c=(TUint8)cmd[0]; sl@0: if (c>='0' && c<='9') sl@0: { sl@0: port=c-'0'; sl@0: } sl@0: } sl@0: sl@0: TInt r=KErrNone; sl@0: LoadCommDrivers(); sl@0: sl@0: RBusDevComm comm; sl@0: r=comm.Open(port); sl@0: test(r==KErrNone); sl@0: TCommConfig cfg; sl@0: TCommConfigV01& c=cfg(); sl@0: comm.Config(cfg); sl@0: c.iRate=EBps115200; sl@0: c.iDataBits=EData8; sl@0: c.iStopBits=EStop1; sl@0: c.iParity=EParityNone; sl@0: c.iHandshake=0; sl@0: c.iFifo=EFifoEnable; sl@0: c.iTerminatorCount=0; sl@0: r=comm.SetConfig(cfg); sl@0: test(r==KErrNone); sl@0: sl@0: TRequestStatus rxs, txs; sl@0: TRequestStatus* pS=&txs; sl@0: User::RequestComplete(pS,0); sl@0: sl@0: TInt pos=0; sl@0: FOREVER sl@0: { sl@0: TPtr8 dptr(Buffer+pos,0,KBufferSize); sl@0: comm.ReadOneOrMore(rxs,dptr); sl@0: User::WaitForRequest(rxs); sl@0: if (rxs!=KErrNone) sl@0: test.Printf(_L("RX error %d\n"),rxs.Int()); sl@0: User::WaitForRequest(txs); sl@0: if (txs!=KErrNone) sl@0: test.Printf(_L("TX error %d\n"),txs.Int()); sl@0: comm.Write(txs,dptr); sl@0: if (pos) sl@0: pos=0; sl@0: else sl@0: pos=KBufferSize; sl@0: } sl@0: }