1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/device/t_dceutl.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,670 @@
1.4 +// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// e32test\device\t_dceutl.cpp
1.18 +//
1.19 +//
1.20 +
1.21 +#include <e32base.h>
1.22 +#include <e32base_private.h>
1.23 +#include <e32test.h>
1.24 +#include <e32cons.h>
1.25 +#include <e32svr.h>
1.26 +#include <e32hal.h>
1.27 +#include <d32comm.h>
1.28 +#include <e32uid.h>
1.29 +#include <hal.h>
1.30 +
1.31 +const TInt KDisplayTitleY=0;
1.32 +const TInt KDisplayMainY=2;
1.33 +const TInt KDisplayTextY=17;
1.34 +const TInt KUnit0=0;
1.35 +const TInt KUnit1=1;
1.36 +const TInt KTestPatternSize=250;
1.37 +enum TPanic {ECreatingConsole,ELoadingPDD,ELoadingLDD,ECreatingRComm,EOpeningPort,ESettingPort,ECircBuf,EStraySignal};
1.38 +
1.39 +#if defined (__WINS__)
1.40 +#define PDD_NAME _L("ECDRV.PDD")
1.41 +#define LDD_NAME _L("ECOMM.LDD")
1.42 +#else
1.43 +#define PDD_NAME _L("EUARTn")
1.44 +#define LDD_NAME _L("ECOMM")
1.45 +#endif
1.46 +
1.47 +class RComm : public RBusDevComm
1.48 + {
1.49 +public:
1.50 + TInt WriteS(const TDesC8& aDes);
1.51 + };
1.52 +
1.53 +CConsoleBase *TheConsole;
1.54 +RComm *TheSerialPort;
1.55 +TCommConfig TheConfigBuf;
1.56 +TCommConfigV01& TheConfig=TheConfigBuf();
1.57 +TBool TheDtrState;
1.58 +TBool TheRtsState;
1.59 +TBuf8<KTestPatternSize> TheTestBuf;
1.60 +
1.61 +LOCAL_C void Panic(TPanic aPanic)
1.62 +//
1.63 +// Panic
1.64 +//
1.65 + {
1.66 +
1.67 + if (TheSerialPort)
1.68 + TheSerialPort->Close();
1.69 + delete TheSerialPort;
1.70 + delete TheConsole;
1.71 + User::Panic(_L("T_DCEUTL"),aPanic);
1.72 + }
1.73 +
1.74 +LOCAL_C TPtrC BaudrateText(TBps aBaudrate)
1.75 + {
1.76 + switch(aBaudrate)
1.77 + {
1.78 + case EBps50: return(_L("50"));
1.79 + case EBps75: return(_L("75"));
1.80 + case EBps110: return(_L("110"));
1.81 + case EBps134: return(_L("134"));
1.82 + case EBps150: return(_L("150"));
1.83 + case EBps300: return(_L("300"));
1.84 + case EBps600: return(_L("600"));
1.85 + case EBps1200: return(_L("1200"));
1.86 + case EBps1800: return(_L("1800"));
1.87 + case EBps2000: return(_L("2000"));
1.88 + case EBps2400: return(_L("2400"));
1.89 + case EBps3600: return(_L("3600"));
1.90 + case EBps4800: return(_L("4800"));
1.91 + case EBps7200: return(_L("7200"));
1.92 + case EBps9600: return(_L("9600"));
1.93 + case EBps19200: return(_L("19200"));
1.94 + case EBps38400: return(_L("38400"));
1.95 + case EBps57600: return(_L("57600"));
1.96 + case EBps115200: return(_L("115200"));
1.97 + case EBps230400: return(_L("230400"));
1.98 + case EBps460800: return(_L("460800"));
1.99 + case EBps576000: return(_L("576000"));
1.100 + case EBps1152000: return(_L("1152000"));
1.101 + case EBps4000000: return(_L("4000000"));
1.102 + case EBpsSpecial: return(_L("Special"));
1.103 + default: return(_L("Unknown"));
1.104 + }
1.105 + }
1.106 +
1.107 +LOCAL_C TPtrC DtrText(TBool aDtrState)
1.108 + {
1.109 + if (aDtrState)
1.110 + return(_L("ASSERTED"));
1.111 + else
1.112 + return(_L("NEGATED"));
1.113 + }
1.114 +
1.115 +LOCAL_C TPtrC RtsText(TBool aRtsState)
1.116 + {
1.117 + if (aRtsState)
1.118 + return(_L("ASSERTED"));
1.119 + else
1.120 + return(_L("NEGATED"));
1.121 + }
1.122 +
1.123 +TInt RComm::WriteS(const TDesC8& aDes)
1.124 +//
1.125 +// Syncronous write
1.126 +//
1.127 + {
1.128 +
1.129 + TRequestStatus s;
1.130 + Write(s,aDes,aDes.Length());
1.131 + User::WaitForRequest(s);
1.132 + return(s.Int());
1.133 + }
1.134 +
1.135 +LOCAL_C void CenteredPrintf(TInt aLine,TRefByValue<const TDesC> aFmt,...)
1.136 +//
1.137 +// Print centrally on specified line
1.138 +//
1.139 + {
1.140 + VA_LIST list;
1.141 + VA_START(list,aFmt);
1.142 + TBuf<0x100> aBuf;
1.143 + aBuf.AppendFormatList(aFmt,list);
1.144 + TInt xPos = ((TheConsole->ScreenSize().iWidth)-aBuf.Length())/2;
1.145 + if (xPos<0)
1.146 + xPos=0;
1.147 + TheConsole->SetPos(0,aLine);
1.148 + TheConsole->ClearToEndOfLine();
1.149 + TheConsole->SetPos(xPos,aLine);
1.150 + TheConsole->Write(aBuf);
1.151 + }
1.152 +
1.153 +LOCAL_C void Heading(TRefByValue<const TDesC> aFmt,...)
1.154 +//
1.155 +// Print a title
1.156 +//
1.157 + {
1.158 + VA_LIST list;
1.159 + VA_START(list,aFmt);
1.160 + TBuf<0x100> aBuf;
1.161 + aBuf.AppendFormatList(aFmt,list);
1.162 + CenteredPrintf(KDisplayTitleY,aBuf);
1.163 + }
1.164 +
1.165 +LOCAL_C void Instructions(TBool topLine,TRefByValue<const TDesC> aFmt,...)
1.166 +//
1.167 +// Print instructions (dont use top line with hex display).
1.168 +//
1.169 + {
1.170 + VA_LIST list;
1.171 + VA_START(list,aFmt);
1.172 + TBuf<0x100> aBuf;
1.173 + aBuf.AppendFormatList(aFmt,list);
1.174 + CenteredPrintf((topLine)?KDisplayTextY-1:KDisplayTextY,aBuf);
1.175 + }
1.176 +
1.177 +LOCAL_C void StripeMem(TDes8& aBuf,TUint aStartChar,TUint anEndChar)
1.178 +//
1.179 +// Mark a buffer with repeating byte pattern
1.180 +//
1.181 + {
1.182 +
1.183 + if (aStartChar==anEndChar)
1.184 + {
1.185 + aBuf.Fill(aStartChar);
1.186 + return;
1.187 + }
1.188 +
1.189 + TUint character=aStartChar;
1.190 + for (TInt i=0;i<aBuf.Length();i++)
1.191 + {
1.192 + aBuf[i]=(TText8)character;
1.193 + if(++character>anEndChar)
1.194 + character=aStartChar;
1.195 + }
1.196 + }
1.197 +
1.198 +#define COLUMN_HEADER _L(" RxBuf | Expected ")
1.199 +LOCAL_C void DumpDescriptors(TDes8 &aLeft,TDes8 &aRight)
1.200 +//
1.201 +//
1.202 +//
1.203 + {
1.204 +
1.205 + TBuf<80> b;
1.206 + CenteredPrintf(KDisplayMainY+2,_L("Compare failed:"));
1.207 + TInt minLen=Min(aLeft.Length(),aRight.Length());
1.208 + CenteredPrintf(KDisplayMainY+3,COLUMN_HEADER);
1.209 + TInt i=0;
1.210 + TInt j=0;
1.211 + TInt pos=KDisplayMainY+4;
1.212 + while (i<=minLen)
1.213 + {
1.214 + b.Format(_L("%02x: "),i);
1.215 + for (j=0;j<8;j++)
1.216 + {
1.217 + if ((i+j)<minLen)
1.218 + {
1.219 + TInt v=aLeft[i+j];
1.220 + b.AppendFormat(_L("%02x "),v);
1.221 + }
1.222 + else
1.223 + b.Append(_L(" "));
1.224 + }
1.225 + b.Append(_L(" | "));
1.226 + for (j=0;j<8;j++)
1.227 + {
1.228 + if ((i+j)<minLen)
1.229 + {
1.230 + TInt v=aRight[i+j];
1.231 + b.AppendFormat(_L("%02x "),v);
1.232 + }
1.233 + else
1.234 + b.Append(_L(" "));
1.235 + }
1.236 + CenteredPrintf(pos++,b);
1.237 + i+=8;
1.238 + if ((i%64)==0)
1.239 + {
1.240 + pos=KDisplayMainY+4;
1.241 + TheConsole->Getch();
1.242 + }
1.243 + }
1.244 + }
1.245 +
1.246 +LOCAL_C TInt ChangeBaudrate()
1.247 +//
1.248 +// Change baudrate
1.249 +//
1.250 + {
1.251 +
1.252 + CenteredPrintf(KDisplayMainY,_L("Select Baudrate:-"));
1.253 + CenteredPrintf(KDisplayMainY+1,_L("A - 4800 "));
1.254 + CenteredPrintf(KDisplayMainY+2,_L("B - 9600 "));
1.255 + CenteredPrintf(KDisplayMainY+3,_L("C - 19200 "));
1.256 + CenteredPrintf(KDisplayMainY+4,_L("D - 38400 "));
1.257 + CenteredPrintf(KDisplayMainY+5,_L("E - 57600 "));
1.258 + CenteredPrintf(KDisplayMainY+6,_L("F - 115200"));
1.259 + TChar c;
1.260 + do
1.261 + {
1.262 + c=(TUint)TheConsole->Getch();
1.263 + c.UpperCase();
1.264 + }
1.265 + while(c<'A' && c>'F');
1.266 +
1.267 + switch (c)
1.268 + {
1.269 + case 'A': TheConfig.iRate=EBps4800; break;
1.270 + case 'B': TheConfig.iRate=EBps9600; break;
1.271 + case 'C': TheConfig.iRate=EBps19200; break;
1.272 + case 'D': TheConfig.iRate=EBps38400; break;
1.273 + case 'E': TheConfig.iRate=EBps57600; break;
1.274 + case 'F': TheConfig.iRate=EBps115200; break;
1.275 + case 0x1b: return(KErrNone);
1.276 + }
1.277 + TInt r=TheSerialPort->SetConfig(TheConfigBuf);
1.278 + if (r!=KErrNone)
1.279 + {
1.280 + CenteredPrintf(KDisplayMainY+9,_L("Error (%d) changing baudrate"),r);
1.281 + TheConsole->Getch();
1.282 + }
1.283 +
1.284 + return(KErrNone);
1.285 + }
1.286 +
1.287 +LOCAL_C TInt SendHayesCommand()
1.288 +//
1.289 +// Send short hayes command
1.290 +//
1.291 + {
1.292 +
1.293 + TInt r=TheSerialPort->WriteS(_L8("AT&f\r"));
1.294 + if (r!=KErrNone)
1.295 + {
1.296 + CenteredPrintf(KDisplayMainY+1,_L("Error (%d) sending data"),r);
1.297 + TheConsole->Getch();
1.298 + }
1.299 + return(KErrNone);
1.300 + }
1.301 +
1.302 +LOCAL_C TInt SendLongHayesCommand()
1.303 +//
1.304 +// Send Long hayes command
1.305 +//
1.306 + {
1.307 +
1.308 + TInt r=TheSerialPort->WriteS(_L8("AT&f&f&f&f&f&f&f\r"));
1.309 + if (r!=KErrNone)
1.310 + {
1.311 + CenteredPrintf(KDisplayMainY+1,_L("Error (%d) sending data"),r);
1.312 + TheConsole->Getch();
1.313 + }
1.314 + return(KErrNone);
1.315 + }
1.316 +
1.317 +const TInt KBufSize=0x100;
1.318 +LOCAL_C TInt Loopback()
1.319 +//
1.320 +// Loopback data from Rx to Tx
1.321 +//
1.322 + {
1.323 +
1.324 + CenteredPrintf(KDisplayMainY,_L("Loopback mode"));
1.325 + CenteredPrintf(KDisplayMainY+5,_L("Hit a key abort"));
1.326 + TheSerialPort->ResetBuffers();
1.327 +
1.328 + CCirBuffer* cbufPtr=new CCirBuffer;
1.329 + __ASSERT_ALWAYS(cbufPtr!=NULL,Panic(ECircBuf));
1.330 + TRAPD(r,cbufPtr->SetLengthL(KBufSize));
1.331 + __ASSERT_ALWAYS(r==KErrNone,Panic(ECircBuf));
1.332 + TRequestStatus kStat,rStat,tStat = 0;
1.333 +
1.334 + TBool TxActive=EFalse;
1.335 + TInt TxCount=0;
1.336 + TUint8 txChar;
1.337 + TPtr8 txPtr(&txChar,1);
1.338 +
1.339 + TUint8 rxChar;
1.340 + TPtr8 rxPtr(&rxChar,1);
1.341 + TheSerialPort->Read(rStat,rxPtr,1);
1.342 +
1.343 + TheConsole->Read(kStat);
1.344 + FOREVER
1.345 + {
1.346 + User::WaitForAnyRequest();
1.347 + if (rStat!=KRequestPending)
1.348 + {
1.349 + if (rStat.Int()!=KErrNone)
1.350 + { // Rx error
1.351 + CenteredPrintf(KDisplayMainY+5,_L("Rx error(%d)"),rStat.Int());
1.352 + TheConsole->ReadCancel();
1.353 + User::WaitForRequest(kStat);
1.354 + goto LoopEnd;
1.355 + }
1.356 + cbufPtr->Put((TInt)rxChar);
1.357 + TheSerialPort->Read(rStat,rxPtr,1);
1.358 + if (!TxActive)
1.359 + {
1.360 + txChar=(TUint8)cbufPtr->Get();
1.361 + TheSerialPort->Write(tStat,txPtr,1);
1.362 + TxActive=ETrue;
1.363 + }
1.364 + }
1.365 + else if (TxActive && tStat!=KRequestPending)
1.366 + {
1.367 + if (tStat.Int()!=KErrNone)
1.368 + { // Tx error
1.369 + CenteredPrintf(KDisplayMainY+5,_L("Tx error(%d)"),tStat.Int());
1.370 + TheSerialPort->ReadCancel();
1.371 + User::WaitForRequest(rStat);
1.372 + TheConsole->ReadCancel();
1.373 + User::WaitForRequest(kStat);
1.374 + TxActive=EFalse;
1.375 + goto LoopEnd;
1.376 + }
1.377 + TxCount++;
1.378 + TInt t=cbufPtr->Get();
1.379 + if (t==KErrGeneral)
1.380 + TxActive=EFalse;
1.381 + else
1.382 + {
1.383 + txChar=(TUint8)t;
1.384 + TheSerialPort->Write(tStat,txPtr,1);
1.385 + }
1.386 + }
1.387 + else if (kStat!=KRequestPending)
1.388 + {
1.389 + CenteredPrintf(KDisplayMainY+5,_L("Tx count (%d) - Hit another key"),TxCount);
1.390 + TheSerialPort->ReadCancel();
1.391 + User::WaitForRequest(rStat);
1.392 +LoopEnd:
1.393 + if (TxActive)
1.394 + {
1.395 + TheSerialPort->WriteCancel();
1.396 + User::WaitForRequest(tStat);
1.397 + }
1.398 + delete cbufPtr;
1.399 + TheConsole->Getch();
1.400 + break;
1.401 + }
1.402 + else
1.403 + Panic(EStraySignal);
1.404 + }
1.405 + return(KErrNone);
1.406 + }
1.407 +
1.408 +LOCAL_C TInt ToggleDtr()
1.409 +//
1.410 +// Toggle state of DTR signal
1.411 +//
1.412 + {
1.413 +
1.414 + if (TheDtrState)
1.415 + {
1.416 + TheSerialPort->SetSignals(0,KSignalDTR); // Negate DTR
1.417 + TheDtrState=EFalse;
1.418 + }
1.419 + else
1.420 + {
1.421 + TheSerialPort->SetSignals(KSignalDTR,0); // Assert DTR
1.422 + TheDtrState=ETrue;
1.423 + }
1.424 + return(KErrNone);
1.425 + }
1.426 +
1.427 +LOCAL_C TInt ToggleRts()
1.428 +//
1.429 +// Toggle state of RTS signal
1.430 +//
1.431 + {
1.432 +
1.433 + if (TheRtsState)
1.434 + {
1.435 + TheSerialPort->SetSignals(0,KSignalRTS); // Negate RTS
1.436 + TheRtsState=EFalse;
1.437 + }
1.438 + else
1.439 + {
1.440 + TheSerialPort->SetSignals(KSignalRTS,0); // Assert RTS
1.441 + TheRtsState=ETrue;
1.442 + }
1.443 + return(KErrNone);
1.444 + }
1.445 +
1.446 +LOCAL_C TInt SendXoff()
1.447 +//
1.448 +// Send XOFF
1.449 +//
1.450 + {
1.451 +
1.452 + TInt r=TheSerialPort->WriteS(_L8("\x13"));
1.453 + if (r!=KErrNone)
1.454 + {
1.455 + CenteredPrintf(KDisplayMainY+1,_L("Error (%d) sending XOFF"),r);
1.456 + TheConsole->Getch();
1.457 + }
1.458 + return(KErrNone);
1.459 + }
1.460 +
1.461 +LOCAL_C TInt ReceiveBlock()
1.462 +//
1.463 +// Receive a block
1.464 +//
1.465 + {
1.466 +
1.467 + CenteredPrintf(KDisplayMainY,_L("Waiting to recieve a block. Hit a key to abort"));
1.468 + TheSerialPort->ResetBuffers();
1.469 + TRequestStatus kStat,rStat;
1.470 + TBuf8<KTestPatternSize> rdBuf(KTestPatternSize);
1.471 + TheSerialPort->Read(rStat,rdBuf);
1.472 + TheConsole->Read(kStat);
1.473 + User::WaitForRequest(kStat,rStat);
1.474 + if (rStat!=KRequestPending)
1.475 + {
1.476 + TheConsole->ReadCancel();
1.477 + User::WaitForRequest(kStat);
1.478 + if (rStat.Int()!=KErrNone)
1.479 + {
1.480 + CenteredPrintf(KDisplayMainY+5,_L("Rx error(%d)"),rStat.Int());
1.481 + TheConsole->Getch();
1.482 + }
1.483 + else if (rdBuf.Compare(TheTestBuf)!=0)
1.484 + DumpDescriptors(rdBuf,TheTestBuf);
1.485 + else
1.486 + {
1.487 + CenteredPrintf(KDisplayMainY+5,_L("Success"));
1.488 + TheConsole->Getch();
1.489 + }
1.490 + }
1.491 + else
1.492 + {
1.493 + TheSerialPort->ReadCancel();
1.494 + User::WaitForRequest(rStat);
1.495 + }
1.496 + return(KErrNone);
1.497 + }
1.498 +
1.499 +LOCAL_C TInt TransmitBlock()
1.500 +//
1.501 +// Transmit a block
1.502 +//
1.503 + {
1.504 +
1.505 + TInt r;
1.506 + CenteredPrintf(KDisplayMainY,_L("Hit a key to transmit a block"));
1.507 + while ((TUint)TheConsole->Getch()!=0x1b)
1.508 + {
1.509 + r=TheSerialPort->WriteS(TheTestBuf);
1.510 + if (r!=KErrNone)
1.511 + {
1.512 + CenteredPrintf(KDisplayMainY+1,_L("Error (%d) transmitting block"),r);
1.513 + TheConsole->Getch();
1.514 + }
1.515 + }
1.516 + return(KErrNone);
1.517 + }
1.518 +
1.519 +LOCAL_C TInt SendXon()
1.520 +//
1.521 +// Send XON
1.522 +//
1.523 + {
1.524 +
1.525 + TInt r=TheSerialPort->WriteS(_L8("\x11"));
1.526 + if (r!=KErrNone)
1.527 + {
1.528 + CenteredPrintf(KDisplayMainY+1,_L("Error (%d) sending XON"),r);
1.529 + TheConsole->Getch();
1.530 + }
1.531 + return(KErrNone);
1.532 + }
1.533 +
1.534 +LOCAL_C void DceUtil()
1.535 +//
1.536 +// DCE Serial Driver test utilities
1.537 +//
1.538 + {
1.539 + TBuf<20> b(_L("BDHLOQRSTXY\x1b"));
1.540 +
1.541 + FOREVER
1.542 + {
1.543 + TheConsole->ClearScreen();
1.544 + TPtrC br=BaudrateText(TheConfig.iRate);
1.545 + TPtrC dt=DtrText(TheDtrState);
1.546 + TPtrC rt=RtsText(TheRtsState);
1.547 + Heading(_L("T_DCEUTL 1.01 (Baudrate: %S DTR:%S RTS:%S)"),&br,&dt,&rt);
1.548 + Instructions(ETrue,_L("Change(B)aud Toggle(D)TR Send(H)ayes (L)oopBack Send X(O)FF"));
1.549 + Instructions(EFalse,_L("(Q)uit (R)xBlock Toggle RT(S) (T)xBlock Send(X)ON LongHayes(Y)?"));
1.550 + TChar c;
1.551 + do
1.552 + {
1.553 + c=(TUint)TheConsole->Getch();
1.554 + c.UpperCase();
1.555 + }
1.556 + while(b.Locate(c)==KErrNotFound);
1.557 +
1.558 + switch (c)
1.559 + {
1.560 + case 'B': // Change baudrate
1.561 + ChangeBaudrate();
1.562 + break;
1.563 + case 'D': // Toggle state of DTR signal
1.564 + ToggleDtr();
1.565 + break;
1.566 + case 'H': // Send short hayes command
1.567 + SendHayesCommand();
1.568 + break;
1.569 + case 'L': // Loopback data from Rx to Tx
1.570 + Loopback();
1.571 + break;
1.572 + case 'O': // Send XOFF
1.573 + SendXoff();
1.574 + break;
1.575 + case 'Q': case 0x1b: // Quit
1.576 + return;
1.577 + case 'R': // Receive a block
1.578 + ReceiveBlock();
1.579 + break;
1.580 + case 'S': // Toggle state of RTS signal
1.581 + ToggleRts();
1.582 + break;
1.583 + case 'T': // Transmit a block
1.584 + TransmitBlock();
1.585 + break;
1.586 + case 'X': // Send XON
1.587 + SendXon();
1.588 + break;
1.589 + case 'Y': // Send long hayes command
1.590 + SendLongHayesCommand();
1.591 + break;
1.592 + }
1.593 + }
1.594 + }
1.595 +
1.596 +GLDEF_C TInt E32Main()
1.597 + {
1.598 +
1.599 + // Create console
1.600 + TRAPD(r,TheConsole=Console::NewL(_L("T_DCEUTL"),TSize(KConsFullScreen,KConsFullScreen)))
1.601 + __ASSERT_ALWAYS(r==KErrNone,Panic(ECreatingConsole));
1.602 + TheTestBuf.SetLength(KTestPatternSize);
1.603 + StripeMem(TheTestBuf,'A','Z');
1.604 +
1.605 + TBuf <0x100> cmd;
1.606 + User::CommandLine(cmd);
1.607 + TInt port=0;
1.608 + if ((cmd.Length()>0) && (cmd[0]>='1' && cmd[0]<='4'))
1.609 + port=(TInt)(cmd[0]-'0');
1.610 +
1.611 + // Load Device Drivers
1.612 + TheConsole->Printf(_L("Load PDD\n\r"));
1.613 + TBuf<9> pddName=PDD_NAME;
1.614 +#if !defined (__WINS__)
1.615 + pddName[5]=(TText)('1'+port);
1.616 + TInt muid=0;
1.617 + if (HAL::Get(HAL::EMachineUid, muid)==KErrNone)
1.618 + {
1.619 + // Brutus uses EUART4 for both COM3 and COM4
1.620 + if (muid==HAL::EMachineUid_Brutus && port==4)
1.621 + pddName[5]=(TText)'4';
1.622 + }
1.623 +#endif
1.624 + r=User::LoadPhysicalDevice(pddName);
1.625 + __ASSERT_ALWAYS(r==KErrNone||r==KErrAlreadyExists,Panic(ELoadingPDD));
1.626 + TheConsole->Printf(_L("Load LDD\n\r"));
1.627 + r=User::LoadLogicalDevice(LDD_NAME);
1.628 + __ASSERT_ALWAYS(r==KErrNone||r==KErrAlreadyExists,Panic(ELoadingLDD));
1.629 +
1.630 + // Create RComm object
1.631 + TheConsole->Printf(_L("Create RComm object\n\r"));
1.632 + TheSerialPort=new RComm;
1.633 + __ASSERT_ALWAYS(TheSerialPort!=NULL,Panic(ECreatingRComm));
1.634 +
1.635 + // Open Serial Port
1.636 + TheConsole->Printf(_L("Open Serial Port (%d)\n\r"),port);
1.637 + r=TheSerialPort->Open(port);
1.638 + __ASSERT_ALWAYS(r==KErrNone,Panic(EOpeningPort));
1.639 +
1.640 + // Setup serial port
1.641 + TheConsole->Printf(_L("Setup serial port\n\r"));
1.642 + TheSerialPort->Config(TheConfigBuf);
1.643 + TheConfig.iRate=EBps9600;
1.644 + TheConfig.iDataBits=EData8;
1.645 + TheConfig.iStopBits=EStop1;
1.646 + TheConfig.iParity=EParityNone;
1.647 + TheConfig.iHandshake=(KConfigFreeRTS|KConfigFreeDTR); // So we can control them ourselves
1.648 + r=TheSerialPort->SetConfig(TheConfigBuf);
1.649 + __ASSERT_ALWAYS((r==KErrNone||r==KErrNotSupported),Panic(ESettingPort));
1.650 + if (r==KErrNotSupported)
1.651 + {
1.652 + // Port may not support the handshake settings
1.653 + TheConfig.iHandshake=0;
1.654 + r=TheSerialPort->SetConfig(TheConfigBuf);
1.655 + __ASSERT_ALWAYS(r==KErrNone,Panic(ESettingPort));
1.656 + }
1.657 +
1.658 + // Assert DTR signal
1.659 + TheSerialPort->SetSignals(KSignalDTR,0); // Assert DTR
1.660 + TheDtrState=ETrue;
1.661 + // Assert RTS signal
1.662 + TheSerialPort->SetSignals(KSignalRTS,0); // Assert RTS
1.663 + TheRtsState=ETrue;
1.664 +
1.665 + DceUtil();
1.666 +
1.667 + TheSerialPort->Close();
1.668 + delete TheSerialPort;
1.669 + delete TheConsole;
1.670 + return(KErrNone);
1.671 + }
1.672 +
1.673 +