0
|
1 |
// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
|
5 |
// which accompanies this distribution, and is available
|
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
// e32test\device\t_commsk.cpp
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
#include <e32base.h>
|
|
19 |
#include <e32base_private.h>
|
|
20 |
#include <e32test.h>
|
|
21 |
#include <e32cons.h>
|
|
22 |
#include <e32svr.h>
|
|
23 |
#include <e32hal.h>
|
|
24 |
#include <d32comm.h>
|
|
25 |
#include <e32uid.h>
|
|
26 |
#include <hal.h>
|
|
27 |
|
|
28 |
#if defined (__WINS__)
|
|
29 |
#define PDD_NAME _L("ECDRV.PDD")
|
|
30 |
#define LDD_NAME _L("ECOMM.LDD")
|
|
31 |
#else
|
|
32 |
#define PDD_NAME _L("EUARTn")
|
|
33 |
#define LDD_NAME _L("ECOMM")
|
|
34 |
#endif
|
|
35 |
|
|
36 |
// Our own comms object with synchronous writes
|
|
37 |
class RComm : public RBusDevComm
|
|
38 |
{
|
|
39 |
public:
|
|
40 |
TInt WriteS(const TDesC8& aDes);
|
|
41 |
TInt WriteS(const TDesC8& aDes,TInt aLength);
|
|
42 |
TInt WriteSE(const TDes8& Entered, TInt aLength);
|
|
43 |
};
|
|
44 |
|
|
45 |
LOCAL_D RTest test(_L("T_COMMSK"));
|
|
46 |
RComm* theSerialPort;
|
|
47 |
TCommCaps theCaps1Buf;
|
|
48 |
TCommCapsV01& theCaps1=theCaps1Buf();
|
|
49 |
TBool MediaChangeTestingEnabled;
|
|
50 |
|
|
51 |
|
|
52 |
class TResult
|
|
53 |
{
|
|
54 |
public:
|
|
55 |
enum TResTest {ETestPower,ESimpleWriting};
|
|
56 |
TResult();
|
|
57 |
void Display(CConsoleBase *aConsole,TInt aCycles);
|
|
58 |
void Add(TResTest aTst,TInt anErr);
|
|
59 |
inline TInt SetFreeMem(TInt aVal)
|
|
60 |
{return(iFreeMem=aVal);}
|
|
61 |
private:
|
|
62 |
TInt iFreeMem;
|
|
63 |
TInt iTestPowerFails;
|
|
64 |
TInt iWriteFails;
|
|
65 |
};
|
|
66 |
|
|
67 |
class TSpeedAndName
|
|
68 |
{
|
|
69 |
public:
|
|
70 |
TUint iMask;
|
|
71 |
TBps iSpeed;
|
|
72 |
const TText* iName;
|
|
73 |
};
|
|
74 |
|
121
|
75 |
/*
|
0
|
76 |
const TSpeedAndName KSpeeds[]=
|
|
77 |
{
|
|
78 |
{KCapsBps50,EBps50,_S("50")},
|
|
79 |
{KCapsBps2400,EBps2400,_S("2400")},
|
|
80 |
{KCapsBps9600,EBps9600,_S("9600")},
|
|
81 |
{KCapsBps19200,EBps19200,_S("19200")},
|
|
82 |
{KCapsBps57600,EBps57600,_S("57600")},
|
|
83 |
{KCapsBps115200,EBps115200,_S("115200")},
|
121
|
84 |
};*/
|
0
|
85 |
class TFrameAndName
|
|
86 |
{
|
|
87 |
public:
|
|
88 |
TDataBits iData;
|
|
89 |
TStopBits iStop;
|
|
90 |
TParity iParity;
|
|
91 |
const TText* iName;
|
|
92 |
};
|
121
|
93 |
/*
|
0
|
94 |
const TFrameAndName KFrameTypes[]=
|
|
95 |
{
|
|
96 |
{EData8,EStop1,EParityNone,_S("8,N,1")},
|
|
97 |
{EData8,EStop1,EParityEven,_S("8,E,1")},
|
|
98 |
{EData8,EStop1,EParityOdd,_S("8,O,1")},
|
|
99 |
|
|
100 |
{EData8,EStop2,EParityNone,_S("8,N,2")},
|
|
101 |
{EData8,EStop2,EParityEven,_S("8,E,2")},
|
|
102 |
{EData8,EStop2,EParityOdd,_S("8,O,2")},
|
|
103 |
|
|
104 |
{EData7,EStop2,EParityNone,_S("7,N,2")},
|
|
105 |
{EData7,EStop2,EParityEven,_S("7,E,2")},
|
|
106 |
{EData7,EStop2,EParityOdd,_S("7,O,2")},
|
|
107 |
|
|
108 |
{EData7,EStop1,EParityNone,_S("7,N,1")},
|
|
109 |
{EData7,EStop1,EParityEven,_S("7,E,1")},
|
|
110 |
{EData7,EStop1,EParityOdd,_S("7,O,1")},
|
121
|
111 |
};*/
|
0
|
112 |
|
|
113 |
class THandShakeAndName
|
|
114 |
{
|
|
115 |
public:
|
|
116 |
TUint iHandshake;
|
|
117 |
const TText* iName;
|
|
118 |
};
|
|
119 |
|
|
120 |
THandShakeAndName KHandshakes[]=
|
|
121 |
{
|
|
122 |
{KConfigObeyDSR,_S("DSR/DTR")},
|
|
123 |
{KConfigObeyCTS,_S("CTS/RTS")},
|
|
124 |
};
|
|
125 |
|
|
126 |
enum TSerialTestFault {EBadArg,EUnknownSignal};
|
|
127 |
|
|
128 |
TInt RComm::WriteS(const TDesC8& aDes)
|
|
129 |
|
|
130 |
// Syncronous write
|
|
131 |
|
|
132 |
{
|
|
133 |
return(WriteS(aDes,aDes.Length()));
|
|
134 |
}
|
|
135 |
|
|
136 |
TInt RComm::WriteS(const TDesC8& aDes,TInt aLength)
|
|
137 |
//
|
|
138 |
// Syncronous write
|
|
139 |
//
|
|
140 |
{
|
|
141 |
|
|
142 |
TRequestStatus s;
|
|
143 |
Write(s,aDes,aLength);
|
|
144 |
User::WaitForRequest(s);
|
|
145 |
return(s.Int());
|
|
146 |
}
|
|
147 |
|
|
148 |
TResult::TResult()
|
|
149 |
{
|
|
150 |
|
|
151 |
iTestPowerFails=0;
|
|
152 |
iFreeMem=0;
|
|
153 |
iWriteFails=0;
|
|
154 |
}
|
|
155 |
|
|
156 |
void TResult::Display(CConsoleBase *aConsole,TInt aCycles)
|
|
157 |
//
|
|
158 |
// Display test results:
|
|
159 |
//
|
|
160 |
{
|
|
161 |
|
|
162 |
test.Console()->ClearScreen();
|
|
163 |
TInt xStartPos=0;
|
|
164 |
TInt yStartPos=2;
|
|
165 |
|
|
166 |
aConsole->SetPos(xStartPos,yStartPos);
|
|
167 |
test.Printf(_L("Total cycles : %d"),aCycles);
|
|
168 |
|
|
169 |
// Display results of Power Down/Up followed by a simple write/read to the Serial Port
|
|
170 |
aConsole->SetPos(xStartPos,yStartPos+2);
|
|
171 |
if (MediaChangeTestingEnabled)
|
|
172 |
test.Printf(_L("Media Change failures: %d\n"),iTestPowerFails);
|
|
173 |
else
|
|
174 |
test.Printf(_L("Power test failures : %d\n"),iTestPowerFails);
|
|
175 |
aConsole->SetPos(xStartPos,yStartPos+3);
|
|
176 |
test.Printf(_L("Serial test failures : %d\n"),iWriteFails);
|
|
177 |
|
|
178 |
aConsole->SetPos(xStartPos,yStartPos+5);
|
|
179 |
test.Printf(_L("Free mem (in bytes) : %d"),iFreeMem);
|
|
180 |
}
|
|
181 |
|
|
182 |
void TResult::Add(TResTest aTst,TInt anErr)
|
|
183 |
//
|
|
184 |
// Increment the corresponding variable if test fails
|
|
185 |
//
|
|
186 |
{
|
|
187 |
|
|
188 |
if (anErr!=KErrNone)
|
|
189 |
{
|
|
190 |
switch (aTst)
|
|
191 |
{
|
|
192 |
case ETestPower:
|
|
193 |
if (anErr!=KErrNone)
|
|
194 |
++iTestPowerFails;
|
|
195 |
break;
|
|
196 |
case ESimpleWriting:
|
|
197 |
if (anErr!=KErrNone)
|
|
198 |
++iWriteFails;
|
|
199 |
break;
|
|
200 |
default:
|
|
201 |
iTestPowerFails=0;
|
|
202 |
break;
|
|
203 |
}
|
|
204 |
}
|
|
205 |
}
|
|
206 |
|
|
207 |
#ifdef _DEBUG_DEVCOMM
|
|
208 |
LOCAL_C void CommDebug(RBusDevComm& aComm)
|
|
209 |
{
|
|
210 |
TCommDebugInfoPckg infopckg;
|
|
211 |
TCommDebugInfo& info = infopckg();
|
|
212 |
aComm.DebugInfo(infopckg);
|
|
213 |
|
|
214 |
test.Printf(_L(" LDD State : TX RX \r\n"));
|
|
215 |
test.Printf(_L(" Busy : %10d %10d\r\n"), info.iTxBusy, info.iRxBusy);
|
|
216 |
test.Printf(_L(" Held : %10d %10d\r\n"), info.iTxHeld, info.iRxHeld);
|
|
217 |
test.Printf(_L(" Length : %10d %10d\r\n"), info.iTxLength, info.iRxLength);
|
|
218 |
test.Printf(_L(" Offset : %10d %10d\r\n"), info.iTxOffset, info.iRxOffset);
|
|
219 |
test.Printf(_L(" Int Count : %10d %10d\r\n"), info.iTxIntCount, info.iRxIntCount);
|
|
220 |
test.Printf(_L(" Err Count : %10d %10d\r\n"), info.iTxErrCount, info.iRxErrCount);
|
|
221 |
test.Printf(_L(" Buf Count : %10d %10d\r\n"), info.iTxBufCount, info.iRxBufCount);
|
|
222 |
test.Printf(_L(" Fill/Drain : %10d %10d\r\n"), info.iFillingTxBuf, info.iFillingTxBuf);
|
|
223 |
test.Printf(_L(" XON : %10d %10d\r\n"), info.iTxXon, info.iRxXon);
|
|
224 |
test.Printf(_L(" XOFF : %10d %10d\r\n"), info.iTxXoff, info.iRxXoff);
|
|
225 |
test.Printf(_L(" Chars : %10d %10d\r\n"), info.iTxChars, info.iRxChars);
|
|
226 |
}
|
|
227 |
#else
|
|
228 |
void CommDebug(RBusDevComm& /*aComm*/)
|
|
229 |
{
|
|
230 |
test.Printf(_L("Debug Dump not available\r\n"));
|
|
231 |
}
|
|
232 |
#endif
|
|
233 |
|
|
234 |
LOCAL_C void Panic(TSerialTestFault const& aFault)
|
|
235 |
//
|
|
236 |
// Panic the test code
|
|
237 |
//
|
|
238 |
{
|
|
239 |
User::Panic(_L("Comm Test"),aFault);
|
|
240 |
}
|
|
241 |
|
|
242 |
LOCAL_C void StripeMem(TDes8& aBuf,TUint aStartChar,TUint anEndChar)
|
|
243 |
//
|
|
244 |
// Mark a buffer with repeating byte pattern
|
|
245 |
//
|
|
246 |
{
|
|
247 |
|
|
248 |
__ASSERT_ALWAYS(aStartChar<=anEndChar,Panic(EBadArg));
|
|
249 |
if (aStartChar==anEndChar)
|
|
250 |
{
|
|
251 |
aBuf.Fill(aStartChar);
|
|
252 |
return;
|
|
253 |
}
|
|
254 |
|
|
255 |
TUint character=aStartChar;
|
|
256 |
for (TInt i=0;i<aBuf.Length();i++)
|
|
257 |
{
|
|
258 |
aBuf[i]=(TText8)character;
|
|
259 |
if(++character>anEndChar)
|
|
260 |
character=aStartChar;
|
|
261 |
}
|
|
262 |
}
|
|
263 |
|
|
264 |
LOCAL_C TInt TestSimpleWriting()
|
|
265 |
{
|
|
266 |
|
|
267 |
const TInt KBufSize=100;
|
|
268 |
TUint8* inBuf=new TUint8[KBufSize];
|
|
269 |
TUint8* outBuf=new TUint8[KBufSize];
|
|
270 |
TPtr8 outDes(outBuf,KBufSize,KBufSize);
|
|
271 |
TPtr8 inDes(inBuf,KBufSize,KBufSize);
|
|
272 |
StripeMem(outDes,'A','Z');
|
|
273 |
inDes.FillZ();
|
|
274 |
inDes.SetLength(1);
|
|
275 |
|
|
276 |
TRequestStatus readStatus;
|
|
277 |
TRequestStatus timeStatus;
|
|
278 |
|
|
279 |
theSerialPort->WriteS(outDes,KBufSize);
|
|
280 |
theSerialPort->Read(readStatus,inDes);
|
|
281 |
|
|
282 |
RTimer tim;
|
|
283 |
test(tim.CreateLocal()==KErrNone);
|
|
284 |
tim.After(timeStatus,2000000); // Async. timer request - 2Secs
|
|
285 |
|
|
286 |
|
|
287 |
User::WaitForRequest(timeStatus,readStatus);
|
|
288 |
|
|
289 |
if (readStatus!=KRequestPending)
|
|
290 |
{
|
|
291 |
// Serial request is complete - cancel timer
|
|
292 |
tim.Cancel();
|
|
293 |
User::WaitForRequest(timeStatus);
|
|
294 |
if (readStatus==KErrNone)
|
|
295 |
{
|
|
296 |
test(inDes.Length()==inDes.MaxLength());
|
|
297 |
test(inDes.Length()==KBufSize);
|
|
298 |
outDes.SetLength(inDes.Length());
|
|
299 |
return((inDes.Compare(outDes)==0)?KErrNone:KErrGeneral);
|
|
300 |
}
|
|
301 |
else
|
|
302 |
return KErrGeneral;
|
|
303 |
}
|
|
304 |
|
|
305 |
else if (timeStatus!=KRequestPending)
|
|
306 |
{
|
|
307 |
// Timed out before Serial test completed
|
|
308 |
theSerialPort->ReadCancel(); // Cancel serial read
|
|
309 |
User::WaitForRequest(readStatus);
|
|
310 |
return KErrTimedOut;
|
|
311 |
}
|
|
312 |
else
|
|
313 |
Panic(EUnknownSignal);
|
|
314 |
return(KErrNone); // Never gets here
|
|
315 |
}
|
|
316 |
|
|
317 |
LOCAL_C TInt SetUp()
|
|
318 |
//
|
|
319 |
// Set up the serial port
|
|
320 |
//
|
|
321 |
{
|
|
322 |
|
|
323 |
theSerialPort->QueryReceiveBuffer();
|
|
324 |
|
|
325 |
TCommConfig cBuf;
|
|
326 |
TCommConfigV01& c=cBuf();
|
|
327 |
theSerialPort->Config(cBuf);
|
|
328 |
|
|
329 |
c.iFifo=EFifoEnable;
|
|
330 |
c.iDataBits=EData8;
|
|
331 |
c.iStopBits=EStop1;
|
|
332 |
c.iParity=EParityNone;
|
|
333 |
c.iRate=EBps115200;
|
|
334 |
c.iHandshake=0;
|
|
335 |
|
|
336 |
TInt r=theSerialPort->SetConfig(cBuf);
|
|
337 |
return (r);
|
|
338 |
}
|
|
339 |
|
|
340 |
LOCAL_C TInt TestPower()
|
|
341 |
{
|
|
342 |
|
|
343 |
User::After(1000000); // Allow 1 second before power down
|
|
344 |
RTimer timer;
|
|
345 |
TRequestStatus done;
|
|
346 |
timer.CreateLocal();
|
|
347 |
TTime wakeup;
|
|
348 |
wakeup.HomeTime();
|
|
349 |
wakeup+=TTimeIntervalSeconds(10);
|
|
350 |
timer.At(done,wakeup);
|
|
351 |
UserHal::SwitchOff();
|
|
352 |
User::WaitForRequest(done);
|
|
353 |
return (done.Int());
|
|
354 |
}
|
|
355 |
|
|
356 |
GLDEF_C TInt E32Main()
|
|
357 |
{
|
|
358 |
|
|
359 |
// test.SetLogged(EFalse); // Turn off serial port debugging!
|
|
360 |
|
|
361 |
test.Title();
|
|
362 |
test.Start(_L("Comms Soak Test"));
|
|
363 |
|
|
364 |
TBuf <0x100> cmd;
|
|
365 |
User::CommandLine(cmd);
|
|
366 |
TInt port=0;
|
|
367 |
if ((cmd.Length()>0) && (cmd[0]>='1' && cmd[0]<='4'))
|
|
368 |
port=(TInt)(cmd[0]-'0');
|
|
369 |
|
|
370 |
test.Next(_L("Load Ldd/Pdd"));
|
|
371 |
TInt r;
|
|
372 |
TBuf<10> pddName=PDD_NAME;
|
|
373 |
#if !defined (__WINS__)
|
|
374 |
pddName[5]=(TText)('1'+port);
|
|
375 |
TInt muid=0;
|
|
376 |
if (HAL::Get(HAL::EMachineUid, muid)==KErrNone)
|
|
377 |
{
|
|
378 |
// Brutus uses EUART4 for both COM3 and COM4
|
|
379 |
if (muid==HAL::EMachineUid_Brutus && port==4)
|
|
380 |
pddName[5]=(TText)'4';
|
|
381 |
}
|
|
382 |
#endif
|
|
383 |
r=User::LoadPhysicalDevice(pddName);
|
|
384 |
test.Printf(_L("Load %S returned %d\n\r"),&pddName,r);
|
|
385 |
test(r==KErrNone || r==KErrAlreadyExists);
|
|
386 |
|
|
387 |
r=User::LoadLogicalDevice(LDD_NAME);
|
|
388 |
test.Printf(_L("Load LDD returned %d\n\r"),r);
|
|
389 |
test(r==KErrNone || r==KErrAlreadyExists);
|
|
390 |
|
|
391 |
theSerialPort=new RComm;
|
|
392 |
test(theSerialPort!=NULL);
|
|
393 |
|
|
394 |
// Set up the serial port
|
|
395 |
theSerialPort->Open(port);
|
|
396 |
r=SetUp();
|
|
397 |
test(r==KErrNone);
|
|
398 |
|
|
399 |
MediaChangeTestingEnabled=EFalse;
|
|
400 |
test.Printf(_L("\r\nThis test requires a loopback conector on the Serial Port\r\n"));
|
|
401 |
test.Printf(_L("<<Hit M for media change testing>>\r\n"));
|
|
402 |
test.Printf(_L("<<Any other key for power testing>>\r\n"));
|
|
403 |
TChar c=(TUint)test.Getch();
|
|
404 |
c.UpperCase();
|
|
405 |
if (c=='M')
|
|
406 |
MediaChangeTestingEnabled=ETrue;
|
|
407 |
|
|
408 |
// Continuous Test
|
|
409 |
TInt cycles=0;
|
|
410 |
TResult results;
|
|
411 |
|
|
412 |
TRequestStatus stat;
|
|
413 |
test.Console()->Read(stat);
|
|
414 |
|
|
415 |
while (stat==KRequestPending)
|
|
416 |
{
|
|
417 |
// Calculate the amount of free memory
|
|
418 |
TMemoryInfoV1Buf membuf;
|
|
419 |
UserHal::MemoryInfo(membuf);
|
|
420 |
TMemoryInfoV1 &memoryInfo=membuf();
|
|
421 |
results.SetFreeMem(memoryInfo.iFreeRamInBytes);
|
|
422 |
|
|
423 |
if (MediaChangeTestingEnabled)
|
|
424 |
{
|
|
425 |
// Media Change Test (if enabled) then SetUp Serial Port and test we can still read/write
|
|
426 |
// UserSvr::ForceRemountMedia(ERemovableMedia0); // Generate media change
|
|
427 |
// User::After(1000000); // Allow 1 second after power down
|
|
428 |
}
|
|
429 |
else
|
|
430 |
{
|
|
431 |
// Power Down then test we can still read/write
|
|
432 |
r=TestPower();
|
|
433 |
results.Add(TResult::ETestPower,r);
|
|
434 |
}
|
|
435 |
r=TestSimpleWriting();
|
|
436 |
results.Add(TResult::ESimpleWriting,r);
|
|
437 |
|
|
438 |
// Display the results of the test cycle
|
|
439 |
cycles++;
|
|
440 |
results.Display(test.Console(),cycles);
|
|
441 |
}
|
|
442 |
|
|
443 |
User::WaitForRequest(stat);
|
|
444 |
theSerialPort->Close();
|
|
445 |
test.End();
|
|
446 |
|
|
447 |
return(KErrNone);
|
|
448 |
}
|