0
|
1 |
// Copyright (c) 1998-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_dtenot.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("EUART")
|
|
33 |
#define LDD_NAME _L("ECOMM")
|
|
34 |
#endif
|
|
35 |
|
|
36 |
#define CHECK(r,v) {if ((r)!=(v)) {test.Printf(_L("Line %d Expected %08x Got %08x\n"),__LINE__,(v),(r)); test(0);}}
|
|
37 |
|
|
38 |
// Our own comms object with synchronous writes
|
|
39 |
class RComm : public RBusDevComm
|
|
40 |
{
|
|
41 |
public:
|
|
42 |
TInt WriteS(const TDesC8& aDes);
|
|
43 |
TInt WriteS(const TDesC8& aDes,TInt aLength);
|
|
44 |
};
|
|
45 |
|
|
46 |
LOCAL_D RTest test(_L("T_DTENOT"));
|
|
47 |
|
|
48 |
RComm* theSerialPort;
|
|
49 |
TCommCaps2 theCapsBuf;
|
|
50 |
TCommCapsV02& theCaps=theCapsBuf();
|
|
51 |
|
|
52 |
TInt RComm::WriteS(const TDesC8& aDes)
|
|
53 |
|
|
54 |
// Syncronous write
|
|
55 |
|
|
56 |
{
|
|
57 |
return(WriteS(aDes,aDes.Length()));
|
|
58 |
}
|
|
59 |
|
|
60 |
TInt RComm::WriteS(const TDesC8& aDes,TInt aLength)
|
|
61 |
|
|
62 |
// Syncronous write
|
|
63 |
|
|
64 |
{
|
|
65 |
|
|
66 |
TRequestStatus s;
|
|
67 |
Write(s,aDes,aLength);
|
|
68 |
User::WaitForRequest(s);
|
|
69 |
return(s.Int());
|
|
70 |
}
|
|
71 |
|
|
72 |
enum TSetClearOutSignal {ESetOutSignal,EClearOutSignal};
|
|
73 |
enum TOutcomeExpected {EExpectNotify,EExpectTimeout};
|
|
74 |
enum TSigChngNotifyType {ENotifyOnInSigOnly,ENotifyOnAnyChange};
|
|
75 |
LOCAL_C void TestNotifySignalChange(TUint anOutSig,TSetClearOutSignal aSetClr,TUint anInSig,TOutcomeExpected anExpect,TSigChngNotifyType aType)
|
|
76 |
//
|
|
77 |
// Change the state of the specified output signal and wait up to 2 seconds for
|
|
78 |
// this to trigger a change notification.
|
|
79 |
//
|
|
80 |
{
|
|
81 |
RTimer tim;
|
|
82 |
tim.CreateLocal();
|
|
83 |
TRequestStatus notifStatus;
|
|
84 |
TRequestStatus timeStatus;
|
|
85 |
|
|
86 |
TUint signals=0;
|
|
87 |
if (aType==ENotifyOnAnyChange)
|
|
88 |
theSerialPort->NotifySignalChange(notifStatus,signals);
|
|
89 |
else
|
|
90 |
theSerialPort->NotifySignalChange(notifStatus,signals,anInSig);
|
|
91 |
// CHECK(notifStatus.Int(),KRequestPending);
|
|
92 |
const TUint KTimeOut=2000000;
|
|
93 |
tim.After(timeStatus,KTimeOut);
|
|
94 |
CHECK(timeStatus.Int(),KRequestPending);
|
|
95 |
if (aSetClr==ESetOutSignal)
|
|
96 |
theSerialPort->SetSignals(anOutSig,0); // Set Out signal
|
|
97 |
else
|
|
98 |
theSerialPort->SetSignals(0,anOutSig); // Clear Out signal
|
|
99 |
User::WaitForRequest(notifStatus,timeStatus);
|
|
100 |
if (notifStatus!=KRequestPending)
|
|
101 |
{
|
|
102 |
test.Printf(_L("notifStatus=%08x\n"),notifStatus.Int());
|
|
103 |
tim.Cancel();
|
|
104 |
User::WaitForRequest(timeStatus);
|
|
105 |
if (anExpect==EExpectNotify)
|
|
106 |
{
|
|
107 |
// Got a notification as expected - but was it the correct notification?
|
|
108 |
TUint sigmask=(anInSig*KSignalChanged);
|
|
109 |
if (aSetClr==ESetOutSignal)
|
|
110 |
sigmask|=anInSig;
|
|
111 |
if (aType==ENotifyOnAnyChange)
|
|
112 |
{CHECK((signals&sigmask),sigmask);}
|
|
113 |
else
|
|
114 |
{CHECK(signals,sigmask);}
|
|
115 |
}
|
|
116 |
else
|
|
117 |
{
|
|
118 |
test.Printf(_L("Spurious notify %d %08x\n"),notifStatus.Int(),signals);
|
|
119 |
test(FALSE); // Unexpectedly got notification
|
|
120 |
}
|
|
121 |
}
|
|
122 |
else
|
|
123 |
{
|
|
124 |
test.Printf(_L("timeStatus=%08x\n"),timeStatus.Int());
|
|
125 |
theSerialPort->NotifySignalChangeCancel();
|
|
126 |
User::WaitForRequest(notifStatus);
|
|
127 |
if (anExpect==EExpectNotify)
|
|
128 |
{
|
|
129 |
test.Printf(_L("Timed Out!\n\r"));
|
|
130 |
test(FALSE);
|
|
131 |
}
|
|
132 |
else
|
|
133 |
test(timeStatus==KErrNone); // Success
|
|
134 |
}
|
|
135 |
}
|
|
136 |
|
|
137 |
GLDEF_C TInt E32Main()
|
|
138 |
//
|
|
139 |
// Test DTE serial driver change notification
|
|
140 |
//
|
|
141 |
{
|
|
142 |
test.SetLogged(EFalse); // Turn off serial port debugging!
|
|
143 |
|
|
144 |
test.Title();
|
|
145 |
test.Start(_L("Check loopback connector"));
|
|
146 |
|
|
147 |
TBuf <0x100> cmd;
|
|
148 |
User::CommandLine(cmd);
|
|
149 |
TInt port=0;
|
|
150 |
if ((cmd.Length()>0) && (cmd[0]>='0' && cmd[0]<='9'))
|
|
151 |
port=(TInt)(cmd[0]-'0');
|
|
152 |
|
|
153 |
// Read machine name to determine handshake options required
|
|
154 |
TInt mid;
|
|
155 |
TInt r=HAL::Get(HAL::EMachineUid,mid);
|
|
156 |
test(r==KErrNone);
|
|
157 |
|
|
158 |
TUint handshake=(KConfigFreeRTS|KConfigFreeDTR); // So we can control them ourselves
|
|
159 |
if (mid==HAL::EMachineUid_Brutus && port<3)
|
|
160 |
handshake=0; // Brutus can't support these option on ports 0-2
|
|
161 |
|
|
162 |
test.Printf(_L("\r\nThis test requires a loopback conector.\r\n"));
|
|
163 |
test.Printf(_L("<<Hit a key to continue>>\r\n"));
|
|
164 |
test.Getch();
|
|
165 |
|
|
166 |
TInt muid=0;
|
|
167 |
test(HAL::Get(HAL::EMachineUid, muid)==KErrNone);
|
|
168 |
TBool isAssabet=(muid==HAL::EMachineUid_Assabet);
|
|
169 |
|
|
170 |
// Load Device Drivers
|
|
171 |
TBuf<10> pddName=PDD_NAME;
|
|
172 |
test.Next(_L("Load PDDs"));
|
|
173 |
#ifdef __WINS__
|
|
174 |
const TInt KMaxPdds=0;
|
|
175 |
#else
|
|
176 |
const TInt KMaxPdds=10;
|
|
177 |
#endif
|
|
178 |
TInt i;
|
|
179 |
for (i=-1; i<KMaxPdds; ++i)
|
|
180 |
{
|
|
181 |
if (i==0)
|
|
182 |
pddName.Append(TChar('0'));
|
|
183 |
else if (i>0)
|
|
184 |
pddName[pddName.Length()-1]=TText('0'+i);
|
|
185 |
r=User::LoadPhysicalDevice(pddName);
|
|
186 |
if (r==KErrNone || r==KErrAlreadyExists)
|
|
187 |
test.Printf(_L("PDD %S loaded\n"),&pddName);
|
|
188 |
}
|
|
189 |
|
|
190 |
test.Next(_L("Load LDD"));
|
|
191 |
r=User::LoadLogicalDevice(LDD_NAME);
|
|
192 |
test.Printf(_L("Load LDD Return %d\n\r"),r);
|
|
193 |
|
|
194 |
test.Next(_L("Create RComm object"));
|
|
195 |
theSerialPort=new RComm;
|
|
196 |
test(theSerialPort!=NULL);
|
|
197 |
//
|
|
198 |
test.Next(_L("Open:"));
|
|
199 |
r=theSerialPort->Open(port);
|
|
200 |
test.Printf(_L("Open(%d)=%d\n\r"),port,r);
|
|
201 |
test(r==KErrNone);
|
|
202 |
|
|
203 |
test.Next(_L("Get caps and configure port"));
|
|
204 |
theSerialPort->Caps(theCapsBuf);
|
|
205 |
CHECK(r,KErrNone);
|
|
206 |
test.Printf(_L("Signals(DTR-RTS-RI-DCD-DSR-CTS) %x\n\r"),theCaps.iSignals);
|
|
207 |
test.Printf(_L("Notifications %x\n\r"),theCaps.iNotificationCaps);
|
|
208 |
|
|
209 |
TCommConfig cBuf;
|
|
210 |
TCommConfigV01& c=cBuf();
|
|
211 |
theSerialPort->Config(cBuf);
|
|
212 |
c.iHandshake=handshake;
|
|
213 |
c.iDataBits=EData8;
|
|
214 |
c.iStopBits=EStop1;
|
|
215 |
c.iParity=EParityNone;
|
|
216 |
c.iRate=EBps9600;
|
|
217 |
r=theSerialPort->SetConfig(cBuf);
|
|
218 |
CHECK(r,KErrNone);
|
|
219 |
|
|
220 |
RTimer tim;
|
|
221 |
tim.CreateLocal();
|
|
222 |
TRequestStatus notifStatus;
|
|
223 |
TRequestStatus timeStatus;
|
|
224 |
|
|
225 |
test.Next(_L("Testing NotifySignalChange()"));
|
|
226 |
if (!(theCaps.iNotificationCaps & KNotifySignalsChangeSupported))
|
|
227 |
test.Printf(_L("WARNING - Signal change notification not supported on this platform\r\n"));
|
|
228 |
else
|
|
229 |
{
|
|
230 |
if ((theCaps.iSignals&(KCapsSignalCTSSupported|KCapsSignalRTSSupported))!=(KCapsSignalCTSSupported|KCapsSignalRTSSupported))
|
|
231 |
test.Printf(_L("WARNING - RTS/CTS not supported on this platform\r\n"));
|
|
232 |
else
|
|
233 |
{
|
|
234 |
#ifndef __WINS__
|
|
235 |
TUint signals=0xffffffff;
|
|
236 |
theSerialPort->SetSignals(0,KSignalRTS); // Clear RTS
|
|
237 |
User::After(100000);
|
|
238 |
test.Next(_L("Initial notifier"));
|
|
239 |
theSerialPort->NotifySignalChange(notifStatus,signals);
|
|
240 |
User::WaitForRequest(notifStatus);
|
|
241 |
test(notifStatus==KErrNone); // goes off immediately the first time
|
|
242 |
test.Printf(_L("Signals %08x\n"),signals);
|
|
243 |
test((signals&(KSignalRTS|KSignalCTS))==0);
|
|
244 |
#endif
|
|
245 |
// Test with no signal mask set
|
|
246 |
|
|
247 |
isAssabet=0;
|
|
248 |
if (isAssabet)
|
|
249 |
{
|
|
250 |
// test.Next(_L(" CTS(set) notify without mask set"));
|
|
251 |
// TestNotifySignalChange(KSignalRTS,ESetOutSignal,KSignalCTS,EExpectNotify,ENotifyOnAnyChange);
|
|
252 |
// (CF) Note: This test presents some problems: we specify notification on any signal but the test only
|
|
253 |
// passes if the input signal specified (CTS) has changed. The test code makes a request for
|
|
254 |
// notification on any signal (iSignalMask=0x3f) and THEN changes an output signal (RTS) that's
|
|
255 |
// wired to the input signal specified (CTS). But changing an output signal launches the DFC
|
|
256 |
// to complete the notification request reporting a change on the output signal NOT the input
|
|
257 |
// signal. The only reason most platforms pass this test is because, on them, input signal changes
|
|
258 |
// trigger interrupts: due to the loopback between output and input signals, when the output
|
|
259 |
// signal changes so does the input signal and that triggers an interrupt which also launches
|
|
260 |
// a DFC to complete the notification request reporting a change on the input signal.
|
|
261 |
// The interrupt is serviced before the output signal notification DFC is scheduled and
|
|
262 |
// the notification request is completed with the input signal change.
|
|
263 |
// On Assabet Modem control signals are polled instead of generating interrupts (Intel's design
|
|
264 |
// flaw) and therefore the output signal change will complete the notification (in error) before
|
|
265 |
// the input signal change is notified.
|
|
266 |
//
|
|
267 |
test.Next(_L(" RTS(set) notify without mask set"));
|
|
268 |
TestNotifySignalChange(KSignalRTS,ESetOutSignal,KSignalRTS,EExpectNotify,ENotifyOnAnyChange);
|
|
269 |
test.Next(_L(" RTS(clear) notify without mask set"));
|
|
270 |
TestNotifySignalChange(KSignalRTS,EClearOutSignal,KSignalRTS,EExpectNotify,ENotifyOnAnyChange);
|
|
271 |
}
|
|
272 |
else
|
|
273 |
{
|
|
274 |
test.Next(_L(" CTS(set) notify without mask set"));
|
|
275 |
TestNotifySignalChange(KSignalRTS,ESetOutSignal,KSignalCTS,EExpectNotify,ENotifyOnAnyChange);
|
|
276 |
test.Next(_L(" CTS(clear) notify without mask set"));
|
|
277 |
TestNotifySignalChange(KSignalRTS,EClearOutSignal,KSignalCTS,EExpectNotify,ENotifyOnAnyChange);
|
|
278 |
}
|
|
279 |
|
|
280 |
// Test notification doesn't happen with signal mask set to some other signal
|
|
281 |
test.Next(_L(" No CTS(set) notify with mask set to other signal"));
|
|
282 |
TestNotifySignalChange(KSignalRTS,ESetOutSignal,KSignalDSR,EExpectTimeout,ENotifyOnInSigOnly);
|
|
283 |
TestNotifySignalChange(KSignalRTS,ESetOutSignal,KSignalCTS,EExpectNotify,ENotifyOnInSigOnly);
|
|
284 |
|
|
285 |
// Test notification happens with mask set to this signal
|
|
286 |
test.Next(_L(" CTS(clear) notify with mask set"));
|
|
287 |
TestNotifySignalChange(KSignalRTS,EClearOutSignal,KSignalCTS,EExpectNotify,ENotifyOnInSigOnly);
|
|
288 |
test.Next(_L(" CTS(set) notify with mask set"));
|
|
289 |
TestNotifySignalChange(KSignalRTS,ESetOutSignal,KSignalCTS,EExpectNotify,ENotifyOnInSigOnly);
|
|
290 |
}
|
|
291 |
|
|
292 |
if ((theCaps.iSignals&(KCapsSignalDSRSupported|KCapsSignalDTRSupported))!=(KCapsSignalDSRSupported|KCapsSignalDTRSupported))
|
|
293 |
test.Printf(_L("WARNING - DTR/DSR not supported on this platform\r\n"));
|
|
294 |
else
|
|
295 |
{
|
|
296 |
theSerialPort->SetSignals(0,KSignalDTR); // Clear DTR
|
|
297 |
User::After(100000);
|
|
298 |
|
|
299 |
// Test with no signal mask set
|
|
300 |
|
|
301 |
if (isAssabet)
|
|
302 |
{
|
|
303 |
// (CF) See note above
|
|
304 |
test.Next(_L(" DTR(set) notify without mask set"));
|
|
305 |
TestNotifySignalChange(KSignalDTR,ESetOutSignal,KSignalDTR,EExpectNotify,ENotifyOnAnyChange);
|
|
306 |
test.Next(_L(" DTR(clear) notify without mask set"));
|
|
307 |
TestNotifySignalChange(KSignalDTR,EClearOutSignal,KSignalDTR,EExpectNotify,ENotifyOnAnyChange);
|
|
308 |
}
|
|
309 |
else
|
|
310 |
{
|
|
311 |
test.Next(_L(" DSR(set) notify without mask set"));
|
|
312 |
TestNotifySignalChange(KSignalDTR,ESetOutSignal,KSignalDSR,EExpectNotify,ENotifyOnAnyChange);
|
|
313 |
test.Next(_L(" DSR(clear) notify without mask set"));
|
|
314 |
TestNotifySignalChange(KSignalDTR,EClearOutSignal,KSignalDSR,EExpectNotify,ENotifyOnAnyChange);
|
|
315 |
}
|
|
316 |
|
|
317 |
// Test notification happens with mask set to this signal
|
|
318 |
test.Next(_L(" DSR(set) notify with mask set"));
|
|
319 |
TestNotifySignalChange(KSignalDTR,ESetOutSignal,KSignalDSR,EExpectNotify,ENotifyOnInSigOnly);
|
|
320 |
test.Next(_L(" DSR(clear) notify with mask set"));
|
|
321 |
TestNotifySignalChange(KSignalDTR,EClearOutSignal,KSignalDSR,EExpectNotify,ENotifyOnInSigOnly);
|
|
322 |
}
|
|
323 |
|
|
324 |
if (mid==HAL::EMachineUid_Series5mx ||
|
|
325 |
(theCaps.iSignals&(KCapsSignalDCDSupported|KCapsSignalDTRSupported))!=(KCapsSignalDCDSupported|KCapsSignalDTRSupported))
|
|
326 |
test.Printf(_L("WARNING - DTR/DCD not supported on this platform\r\n"));
|
|
327 |
else
|
|
328 |
{
|
|
329 |
// Test with no signal mask set
|
|
330 |
|
|
331 |
if (isAssabet)
|
|
332 |
{
|
|
333 |
// (CF) See note above
|
|
334 |
test.Next(_L(" DTR(set) notify without mask set"));
|
|
335 |
TestNotifySignalChange(KSignalDTR,ESetOutSignal,KSignalDTR,EExpectNotify,ENotifyOnAnyChange);
|
|
336 |
test.Next(_L(" DTR(clear) notify without mask set"));
|
|
337 |
TestNotifySignalChange(KSignalDTR,EClearOutSignal,KSignalDTR,EExpectNotify,ENotifyOnAnyChange);
|
|
338 |
}
|
|
339 |
else
|
|
340 |
{
|
|
341 |
test.Next(_L(" DCD(set) notify without mask set"));
|
|
342 |
TestNotifySignalChange(KSignalDTR,ESetOutSignal,KSignalDCD,EExpectNotify,ENotifyOnAnyChange);
|
|
343 |
test.Next(_L(" DCD(clear) notify without mask set"));
|
|
344 |
TestNotifySignalChange(KSignalDTR,EClearOutSignal,KSignalDCD,EExpectNotify,ENotifyOnAnyChange);
|
|
345 |
}
|
|
346 |
|
|
347 |
|
|
348 |
// Test notification happens with mask set to this signal
|
|
349 |
test.Next(_L(" DCD(set) notify with mask set"));
|
|
350 |
TestNotifySignalChange(KSignalDTR,ESetOutSignal,KSignalDCD,EExpectNotify,ENotifyOnInSigOnly);
|
|
351 |
test.Next(_L(" DCD(clear) notify with mask set"));
|
|
352 |
TestNotifySignalChange(KSignalDTR,EClearOutSignal,KSignalDCD,EExpectNotify,ENotifyOnInSigOnly);
|
|
353 |
}
|
|
354 |
}
|
|
355 |
|
|
356 |
test.Next(_L("Testing NotifyReceiveDataAvailable()"));
|
|
357 |
if (!(theCaps.iNotificationCaps & KNotifyDataAvailableSupported))
|
|
358 |
test.Printf(_L("Data available notification not supported on this platform\r\n"));
|
|
359 |
else
|
|
360 |
{
|
|
361 |
TBuf8<0x10> buf1(0x10), buf2(0x10);
|
|
362 |
for (TInt i=0;i<0x10;i++) buf1[i]=(TUint8)i;
|
|
363 |
|
|
364 |
theSerialPort->ResetBuffers();
|
|
365 |
theSerialPort->NotifyReceiveDataAvailable(notifStatus);
|
|
366 |
CHECK(notifStatus.Int(),KRequestPending);
|
|
367 |
const TUint KTimeOut=2000000;
|
|
368 |
tim.After(timeStatus,KTimeOut);
|
|
369 |
CHECK(timeStatus.Int(),KRequestPending);
|
|
370 |
theSerialPort->WriteS(buf1);
|
|
371 |
User::WaitForRequest(notifStatus,timeStatus);
|
|
372 |
if (notifStatus==KErrNone)
|
|
373 |
{
|
|
374 |
tim.Cancel();
|
|
375 |
CHECK(notifStatus.Int(),KErrNone);
|
|
376 |
}
|
|
377 |
else
|
|
378 |
{
|
|
379 |
test.Printf(_L("Timed Out!\n\r"));
|
|
380 |
theSerialPort->NotifyReceiveDataAvailableCancel();
|
|
381 |
test(FALSE);
|
|
382 |
}
|
|
383 |
User::After(500000);
|
|
384 |
CHECK(theSerialPort->QueryReceiveBuffer(),0x10);
|
|
385 |
buf2.FillZ();
|
|
386 |
theSerialPort->Read(notifStatus,buf2,0x10);
|
|
387 |
User::WaitForRequest(notifStatus);
|
|
388 |
test(buf1.Compare(buf2)==0);
|
|
389 |
}
|
|
390 |
|
|
391 |
theSerialPort->Close();
|
|
392 |
test.Printf(_L("<<Hit a key to end>>\r\n"));
|
|
393 |
test.Getch();
|
|
394 |
test.End();
|
|
395 |
return(KErrNone);
|
|
396 |
}
|
|
397 |
|
|
398 |
|