189
|
1 |
// Copyright (c) 2000-2010 Nokia Corporation and/or its subsidiary(-ies).
|
0
|
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/usb/t_usb_device/src/activerw.cpp
|
|
15 |
// USB Test Program T_USB_DEVICE, functional part.
|
|
16 |
// Device-side part, to work against T_USB_HOST running on the host.
|
253
|
17 |
//
|
0
|
18 |
//
|
|
19 |
|
|
20 |
#include "general.h" // CActiveControl, CActiveRW
|
|
21 |
#include "config.h"
|
|
22 |
#include "activerw.h"
|
253
|
23 |
#include "activetimer.h"
|
0
|
24 |
#include "usblib.h" // Helpers
|
253
|
25 |
#include "OstTraceDefinitions.h"
|
|
26 |
#ifdef OST_TRACE_COMPILER_IN_USE
|
|
27 |
#include "activerwTraces.h"
|
|
28 |
#endif
|
|
29 |
|
0
|
30 |
|
|
31 |
_LIT(KFileName, "\\T_USBFILE.BIN");
|
|
32 |
|
|
33 |
extern RTest test;
|
|
34 |
extern TBool gVerbose;
|
|
35 |
extern TBool gSkip;
|
|
36 |
extern TBool gStopOnFail;
|
|
37 |
extern TBool gAltSettingOnNotify;
|
|
38 |
extern TInt8 gSettingNumber [128];
|
|
39 |
extern TInt gSoakCount;
|
|
40 |
extern CActiveRW* gRW[KMaxConcurrentTests]; // the USB read/write active object
|
|
41 |
extern IFConfigPtr gInterfaceConfig [128] [KMaxInterfaceSettings];
|
|
42 |
extern TInt gActiveTestCount;
|
|
43 |
|
|
44 |
static TInt gYieldRepeat = 0;
|
|
45 |
static const TInt KYieldRepeat = 100;
|
|
46 |
|
|
47 |
//
|
|
48 |
// --- class CActiveRW ---------------------------------------------------------
|
|
49 |
//
|
|
50 |
|
|
51 |
CActiveRW::CActiveRW(CConsoleBase* aConsole, RDEVCLIENT* aPort, RFs aFs, TUint16 aIndex, TBool aLastSetting)
|
|
52 |
: CActive(EPriorityNormal),
|
|
53 |
#ifndef USB_SC
|
|
54 |
iWriteBuf((TUint8 *)NULL,0,0), // temporary initialisation
|
253
|
55 |
iReadBuf((TUint8 *)NULL,0,0), // temporary initialisation
|
0
|
56 |
#endif
|
|
57 |
iConsole(aConsole),
|
|
58 |
iPort(aPort),
|
|
59 |
iBufSz(0),
|
|
60 |
iMaxPktSz(0),
|
|
61 |
iCurrentXfer(ETxferNone),
|
|
62 |
iXferMode(::ENone),
|
|
63 |
iDoStop(EFalse),
|
|
64 |
iPktNum(0),
|
|
65 |
iFs(aFs),
|
|
66 |
iRepeat(0),
|
|
67 |
iComplete(EFalse),
|
|
68 |
iResult(EFalse),
|
|
69 |
iIndex (aIndex),
|
|
70 |
iLastSetting (aLastSetting)
|
|
71 |
{
|
|
72 |
gActiveTestCount++;
|
|
73 |
TUSB_VERBOSE_PRINT("CActiveRW::CActiveRW()");
|
253
|
74 |
if(gVerbose)
|
|
75 |
{
|
|
76 |
OstTrace0(TRACE_VERBOSE, CACTIVERW_CACTIVERW, "CActiveRW::CActiveRW()");
|
|
77 |
}
|
0
|
78 |
}
|
|
79 |
|
|
80 |
|
|
81 |
CActiveRW* CActiveRW::NewL(CConsoleBase* aConsole, RDEVCLIENT* aPort, RFs aFs, TUint16 aIndex, TBool aLastSetting)
|
|
82 |
{
|
253
|
83 |
//TUSB_VERBOSE_APRINT("CActiveRW::NewL()");
|
|
84 |
//OstTrace0(TRACE_NORMAL, CACTIVERW_NEWL, "CActiveRW::NewL()");
|
0
|
85 |
|
|
86 |
CActiveRW* self = new (ELeave) CActiveRW(aConsole, aPort, aFs, aIndex, aLastSetting);
|
|
87 |
CleanupStack::PushL(self);
|
|
88 |
self->ConstructL();
|
|
89 |
CActiveScheduler::Add(self);
|
|
90 |
CleanupStack::Pop(); // self
|
|
91 |
return self;
|
|
92 |
}
|
|
93 |
|
|
94 |
|
|
95 |
void CActiveRW::ConstructL()
|
|
96 |
{
|
|
97 |
TUSB_VERBOSE_PRINT("CActiveRW::ConstructL()");
|
253
|
98 |
if(gVerbose)
|
|
99 |
{
|
|
100 |
OstTrace0(TRACE_VERBOSE, CACTIVERW_CONSTRUCTL, "CActiveRW::ConstructL()");
|
|
101 |
}
|
0
|
102 |
|
|
103 |
// Create read timeout timer active object (but don't activate it yet)
|
|
104 |
iTimeoutTimer = CActiveTimer::NewL(iConsole, iPort);
|
|
105 |
if (!iTimeoutTimer)
|
|
106 |
{
|
|
107 |
TUSB_PRINT("Failed to create timeout timer");
|
253
|
108 |
OstTrace0(TRACE_NORMAL, CACTIVERW_CONSTRUCTL_DUP01, "Failed to create timeout timer");
|
0
|
109 |
}
|
|
110 |
}
|
|
111 |
|
|
112 |
|
|
113 |
CActiveRW::~CActiveRW()
|
|
114 |
{
|
|
115 |
TUSB_VERBOSE_PRINT("CActiveRW::~CActiveRW()");
|
253
|
116 |
if(gVerbose)
|
|
117 |
{
|
|
118 |
OstTrace0(TRACE_VERBOSE, CACTIVERW_DCACTIVERW, "CActiveRW::~CActiveRW()");
|
|
119 |
}
|
0
|
120 |
Cancel(); // base class
|
|
121 |
delete iTimeoutTimer;
|
|
122 |
#ifdef USB_SC
|
|
123 |
if ((TENDPOINTNUMBER)iTestParams.outPipe <= KMaxEndpointsPerClient)
|
|
124 |
{
|
|
125 |
iSCReadBuf.Close();
|
|
126 |
}
|
|
127 |
if ((TENDPOINTNUMBER)iTestParams.inPipe <= KMaxEndpointsPerClient)
|
|
128 |
{
|
|
129 |
iSCWriteBuf.Close();
|
|
130 |
}
|
|
131 |
#else
|
|
132 |
User::Free((TAny *)iReadBuf.Ptr());
|
|
133 |
User::Free((TAny *)iWriteBuf.Ptr());
|
|
134 |
#endif
|
|
135 |
iFile.Close();
|
|
136 |
gRW[iIndex] = NULL;
|
|
137 |
gActiveTestCount--;
|
|
138 |
}
|
|
139 |
|
|
140 |
|
|
141 |
void CActiveRW::SetTestParams(TestParamPtr aTpPtr)
|
|
142 |
{
|
|
143 |
iBufSz = aTpPtr->minSize;
|
|
144 |
iPktNum = aTpPtr->packetNumber;
|
253
|
145 |
|
0
|
146 |
iTestParams = *aTpPtr;
|
|
147 |
|
|
148 |
gYieldRepeat = ((iTestParams.settingRepeat != 0) || (iIndex == 0))? 0 : KYieldRepeat;
|
|
149 |
|
|
150 |
if ((TENDPOINTNUMBER)iTestParams.outPipe <= KMaxEndpointsPerClient)
|
|
151 |
{
|
|
152 |
#ifndef USB_SC
|
|
153 |
TAny * newBuffer = User::Alloc(aTpPtr->maxSize);
|
|
154 |
if (newBuffer == NULL)
|
|
155 |
{
|
|
156 |
TUSB_PRINT ("Failure to allocate heap memory");
|
253
|
157 |
OstTrace0 (TRACE_ERROR, CACTIVERW_SETTESTPARAMS, "Failure to allocate heap memory");
|
0
|
158 |
test(EFalse);
|
|
159 |
}
|
|
160 |
iReadBuf.Set((TUint8 *)newBuffer,0,(TInt)aTpPtr->maxSize);
|
|
161 |
#endif
|
|
162 |
TBuf8<KUsbDescSize_Endpoint> descriptor;
|
|
163 |
TUSB_VERBOSE_PRINT2 ("GetEndpointDescriptor Alt Setting %d Endpoint %d",iTestParams.alternateSetting, iTestParams.outPipe);
|
253
|
164 |
if(gVerbose)
|
|
165 |
{
|
|
166 |
OstTraceExt2 (TRACE_VERBOSE, CACTIVERW_SETTESTPARAMS_DUP01, "GetEndpointDescriptor Alt Setting %d Endpoint %d",iTestParams.alternateSetting, iTestParams.outPipe);
|
|
167 |
}
|
0
|
168 |
TInt r = iPort->GetEndpointDescriptor(iTestParams.alternateSetting, (TENDPOINTNUMBER)iTestParams.outPipe, descriptor);
|
|
169 |
if ((TUint)r != iReadSize)
|
|
170 |
{
|
|
171 |
TUSB_PRINT("Failed to get endpoint descriptor");
|
253
|
172 |
OstTrace0(TRACE_ERROR, CACTIVERW_SETTESTPARAMS_DUP02, "Failed to get endpoint descriptor");
|
0
|
173 |
test(EFalse);
|
|
174 |
return;
|
|
175 |
}
|
|
176 |
|
253
|
177 |
iMaxPktSz = EpSize(descriptor[KEpDesc_PacketSizeOffset],descriptor[KEpDesc_PacketSizeOffset+1]);
|
0
|
178 |
TUSB_VERBOSE_PRINT5 ("Out Endpoint 0x%x attributes 0x%x interface %d setting %d max packet size %d",
|
|
179 |
descriptor[KEpDesc_AddressOffset],descriptor[KEpDesc_AttributesOffset],iTestParams.interfaceNumber,iTestParams.alternateSetting,iMaxPktSz);
|
253
|
180 |
if(gVerbose)
|
|
181 |
{
|
|
182 |
OstTraceExt5 (TRACE_VERBOSE, CACTIVERW_SETTESTPARAMS_DUP03, "Out Endpoint 0x%x attributes 0x%x interface %d setting %d max packet size %d",
|
|
183 |
(TUint)descriptor[KEpDesc_AddressOffset],(TUint)descriptor[KEpDesc_AttributesOffset],(TUint)iTestParams.interfaceNumber,(TUint)iTestParams.alternateSetting,(TUint)iMaxPktSz);
|
|
184 |
}
|
0
|
185 |
if (!gSkip && iMaxPktSz != (TUint)gInterfaceConfig[iTestParams.interfaceNumber][iTestParams.alternateSetting]->iInfoPtr->iEndpointData[iTestParams.outPipe-1].iSize)
|
|
186 |
{
|
|
187 |
TUSB_PRINT4("Error - Interface %d Setting %d Endpoint %d Max Packet Size %d",iTestParams.interfaceNumber,iTestParams.alternateSetting,iTestParams.outPipe,iMaxPktSz);
|
253
|
188 |
OstTraceExt4(TRACE_ERROR, CACTIVERW_SETTESTPARAMS_DUP04, "Error - Interface %d Setting %d Endpoint %d Max Packet Size %d",iTestParams.interfaceNumber,iTestParams.alternateSetting,iTestParams.outPipe,iMaxPktSz);
|
0
|
189 |
test(EFalse);
|
|
190 |
return;
|
|
191 |
}
|
|
192 |
}
|
|
193 |
if ((TENDPOINTNUMBER)iTestParams.inPipe <= KMaxEndpointsPerClient)
|
|
194 |
{
|
|
195 |
#ifndef USB_SC
|
|
196 |
TAny * newBuffer = User::Alloc(aTpPtr->maxSize);
|
|
197 |
if (newBuffer == NULL)
|
|
198 |
{
|
|
199 |
TUSB_PRINT ("Failure to allocate heap memory");
|
253
|
200 |
OstTrace0 (TRACE_ERROR, CACTIVERW_SETTESTPARAMS_DUP05, "Failure to allocate heap memory");
|
0
|
201 |
test(EFalse);
|
|
202 |
}
|
|
203 |
iWriteBuf.Set((TUint8 *)newBuffer,0,(TInt)aTpPtr->maxSize);
|
|
204 |
#endif
|
|
205 |
TBuf8<KUsbDescSize_Endpoint> descriptor;
|
|
206 |
TUSB_VERBOSE_PRINT2 ("GetEndpointDescriptor Alt Setting %d Endpoint %d",iTestParams.alternateSetting, iTestParams.inPipe);
|
253
|
207 |
if(gVerbose)
|
|
208 |
{
|
|
209 |
OstTraceExt2 (TRACE_VERBOSE, CACTIVERW_SETTESTPARAMS_DUP06, "GetEndpointDescriptor Alt Setting %d Endpoint %d",iTestParams.alternateSetting, iTestParams.inPipe);
|
|
210 |
}
|
0
|
211 |
TInt r = iPort->GetEndpointDescriptor(iTestParams.alternateSetting, (TENDPOINTNUMBER)iTestParams.inPipe, descriptor);
|
|
212 |
if (r != KErrNone)
|
|
213 |
{
|
|
214 |
TUSB_PRINT("Failed to get endpoint descriptor");
|
253
|
215 |
OstTrace0(TRACE_ERROR, CACTIVERW_SETTESTPARAMS_DUP07, "Failed to get endpoint descriptor");
|
0
|
216 |
test(EFalse);
|
|
217 |
return;
|
|
218 |
}
|
|
219 |
|
253
|
220 |
TInt maxPktSz = EpSize(descriptor[KEpDesc_PacketSizeOffset],descriptor[KEpDesc_PacketSizeOffset+1]);
|
0
|
221 |
TUSB_VERBOSE_PRINT5 ("In Endpoint 0x%x attributes 0x%x interface %d setting %d max packet size %d",
|
|
222 |
descriptor[KEpDesc_AddressOffset],descriptor[KEpDesc_AttributesOffset],iTestParams.interfaceNumber,iTestParams.alternateSetting,maxPktSz);
|
253
|
223 |
if(gVerbose)
|
|
224 |
{
|
|
225 |
OstTraceExt5 (TRACE_VERBOSE, CACTIVERW_SETTESTPARAMS_DUP08, "In Endpoint 0x%x attributes 0x%x interface %d setting %d max packet size %d",
|
|
226 |
descriptor[KEpDesc_AddressOffset],descriptor[KEpDesc_AttributesOffset],iTestParams.interfaceNumber,iTestParams.alternateSetting,maxPktSz);
|
|
227 |
}
|
0
|
228 |
if (!gSkip && maxPktSz != gInterfaceConfig[iTestParams.interfaceNumber][iTestParams.alternateSetting]->iInfoPtr->iEndpointData[iTestParams.inPipe-1].iSize)
|
|
229 |
{
|
|
230 |
TUSB_PRINT4("Error - Interface %d Setting %d Endpoint %d Max Packet Size %d",iTestParams.interfaceNumber,iTestParams.alternateSetting,iTestParams.inPipe,maxPktSz);
|
253
|
231 |
OstTraceExt4(TRACE_ERROR, CACTIVERW_SETTESTPARAMS_DUP09, "Error - Interface %d Setting %d Endpoint %d Max Packet Size %d",iTestParams.interfaceNumber,iTestParams.alternateSetting,iTestParams.inPipe,maxPktSz);
|
0
|
232 |
test(EFalse);
|
|
233 |
return;
|
|
234 |
}
|
|
235 |
}
|
253
|
236 |
|
0
|
237 |
}
|
|
238 |
|
|
239 |
|
|
240 |
void CActiveRW::SetTransferMode(TXferMode aMode)
|
|
241 |
{
|
|
242 |
iXferMode = aMode;
|
|
243 |
if (aMode == EReceiveOnly || aMode == ETransmitOnly)
|
|
244 |
{
|
|
245 |
// For streaming transfers we do this only once.
|
|
246 |
iBufSz = iTestParams.maxSize;
|
|
247 |
}
|
|
248 |
}
|
|
249 |
|
|
250 |
void CActiveRW::Suspend(TXferType aType)
|
|
251 |
{
|
|
252 |
if (aType == ESuspend)
|
|
253 |
TUSB_VERBOSE_PRINT1("Index %d Suspend",iIndex);
|
253
|
254 |
if(gVerbose)
|
|
255 |
{
|
|
256 |
OstTrace1(TRACE_VERBOSE, CACTIVERW_SUSPEND, "Index %d Suspend",iIndex);
|
|
257 |
}
|
0
|
258 |
if (aType == EAltSetting)
|
253
|
259 |
TUSB_VERBOSE_PRINT3("Index %d Suspend for Alternate Setting - interface %d setting %d",iIndex,iTestParams.interfaceNumber,iTestParams.alternateSetting);
|
|
260 |
if(gVerbose)
|
|
261 |
{
|
|
262 |
OstTraceExt3(TRACE_VERBOSE, CACTIVERW_SUSPEND_DUP01, "Index %d Suspend for Alternate Setting - interface %d setting %d",iIndex,iTestParams.interfaceNumber,iTestParams.alternateSetting);
|
|
263 |
}
|
0
|
264 |
iStatus = KRequestPending;
|
|
265 |
iCurrentXfer = aType;
|
|
266 |
if (!IsActive())
|
|
267 |
{
|
|
268 |
SetActive();
|
|
269 |
}
|
|
270 |
}
|
|
271 |
|
|
272 |
void CActiveRW::Resume()
|
253
|
273 |
{
|
0
|
274 |
TUSB_VERBOSE_PRINT3("Index %d Resume interface %d setting %d",iIndex,iTestParams.interfaceNumber,iTestParams.alternateSetting);
|
253
|
275 |
if(gVerbose)
|
|
276 |
{
|
|
277 |
OstTraceExt3(TRACE_VERBOSE, CACTIVERW_RESUME, "Index %d Resume interface %d setting %d",iIndex,iTestParams.interfaceNumber,iTestParams.alternateSetting);
|
|
278 |
}
|
0
|
279 |
TRequestStatus* status = &iStatus;
|
|
280 |
User::RequestComplete(status,KErrNone);
|
|
281 |
if (!IsActive())
|
|
282 |
{
|
|
283 |
SetActive();
|
|
284 |
}
|
|
285 |
}
|
|
286 |
|
|
287 |
void CActiveRW::Yield()
|
|
288 |
{
|
|
289 |
TUSB_VERBOSE_PRINT1("Index %d Scheduler Yield",iIndex);
|
253
|
290 |
if(gVerbose)
|
|
291 |
{
|
|
292 |
OstTrace1(TRACE_VERBOSE, CACTIVERW_YIELD, "Index %d Scheduler Yield",iIndex);
|
|
293 |
}
|
0
|
294 |
// removes the active object from the scheduler queue then adds it back in again
|
253
|
295 |
Deque();
|
0
|
296 |
CActiveScheduler::Add(this);
|
|
297 |
}
|
|
298 |
|
|
299 |
void CActiveRW::ResumeAltSetting(TUint aAltSetting)
|
|
300 |
{
|
|
301 |
if (iCurrentXfer == EAltSetting && iTestParams.alternateSetting == aAltSetting)
|
|
302 |
{
|
|
303 |
Resume();
|
|
304 |
}
|
|
305 |
}
|
|
306 |
|
|
307 |
void CActiveRW::StartOrSuspend()
|
|
308 |
{
|
|
309 |
TInt altSetting;
|
253
|
310 |
|
0
|
311 |
iPort->GetAlternateSetting (altSetting);
|
|
312 |
if (iTestParams.alternateSetting != altSetting)
|
|
313 |
{
|
|
314 |
Suspend(EAltSetting);
|
|
315 |
}
|
|
316 |
else
|
|
317 |
{
|
|
318 |
#ifdef USB_SC
|
|
319 |
TInt r;
|
|
320 |
if (iTestParams.alternateSetting != gSettingNumber[iTestParams.interfaceNumber])
|
|
321 |
{
|
|
322 |
gSettingNumber[iTestParams.interfaceNumber] = iTestParams.alternateSetting;
|
|
323 |
r = iPort->StartNextOutAlternateSetting(ETrue);
|
|
324 |
TUSB_VERBOSE_PRINT1("StartNextOutAlternateSetting retValue %d",r);
|
253
|
325 |
if(gVerbose)
|
|
326 |
{
|
|
327 |
OstTrace1(TRACE_VERBOSE, CACTIVERW_STARTORSUSPEND, "StartNextOutAlternateSetting retValue %d",r);
|
|
328 |
}
|
0
|
329 |
test_Value(r, (r >= KErrNone) || (r == KErrNotReady) || (r == KErrGeneral));
|
|
330 |
}
|
|
331 |
TUSB_VERBOSE_PRINT4 ("CActiveRW::StartOrSuspend() interface %d setting %d Out %d In %d",iTestParams.interfaceNumber,iTestParams.alternateSetting,iTestParams.outPipe,iTestParams.inPipe);
|
253
|
332 |
if(gVerbose)
|
|
333 |
{
|
|
334 |
OstTraceExt4 (TRACE_VERBOSE, CACTIVERW_STARTORSUSPEND_DUP01, "CActiveRW::StartOrSuspend() interface %d setting %d Out %d In %d",iTestParams.interfaceNumber,iTestParams.alternateSetting,iTestParams.outPipe,iTestParams.inPipe);
|
|
335 |
}
|
0
|
336 |
if ((TENDPOINTNUMBER)iTestParams.outPipe <= KMaxEndpointsPerClient)
|
|
337 |
{
|
|
338 |
r = iPort->OpenEndpoint(iSCReadBuf,iTestParams.outPipe);
|
|
339 |
test_KErrNone(r);
|
|
340 |
}
|
|
341 |
if ((TENDPOINTNUMBER)iTestParams.inPipe <= KMaxEndpointsPerClient)
|
|
342 |
{
|
|
343 |
r = iPort->OpenEndpoint(iSCWriteBuf,iTestParams.inPipe);
|
|
344 |
test_KErrNone(r);
|
|
345 |
}
|
|
346 |
#endif
|
|
347 |
if (iXferMode == EReceiveOnly)
|
|
348 |
{
|
|
349 |
// read data and process any available
|
|
350 |
iReadSize = ReadData();
|
|
351 |
if (iReadSize != 0)
|
|
352 |
{
|
|
353 |
ProcessReadXfer();
|
|
354 |
}
|
|
355 |
}
|
|
356 |
else
|
|
357 |
{
|
|
358 |
SendData(); // or we send data
|
|
359 |
if (iXferMode == ETransmitOnly)
|
|
360 |
{
|
253
|
361 |
iPktNum++;
|
|
362 |
iRepeat++;
|
0
|
363 |
}
|
253
|
364 |
}
|
0
|
365 |
}
|
|
366 |
}
|
|
367 |
|
|
368 |
void CActiveRW::RunL()
|
|
369 |
{
|
|
370 |
#ifdef USB_SC
|
|
371 |
TInt r = 0;
|
|
372 |
#else
|
253
|
373 |
TInt altSetting;
|
0
|
374 |
#endif
|
253
|
375 |
|
0
|
376 |
TUSB_VERBOSE_PRINT("CActiveRW::RunL()");
|
253
|
377 |
if(gVerbose)
|
|
378 |
{
|
|
379 |
OstTrace0(TRACE_VERBOSE, CACTIVERW_RUNL, "CActiveRW::RunL()");
|
|
380 |
}
|
0
|
381 |
|
|
382 |
if ((iStatus != KErrNone) && (iStatus != KErrEof))
|
|
383 |
{
|
|
384 |
TUSB_PRINT1("Error %d in RunL", iStatus.Int());
|
253
|
385 |
OstTrace1(TRACE_NORMAL, CACTIVERW_RUNL_DUP01, "Error %d in RunL", iStatus.Int());
|
0
|
386 |
}
|
|
387 |
if (iDoStop)
|
|
388 |
{
|
|
389 |
TUSB_PRINT("Stopped");
|
253
|
390 |
OstTrace0(TRACE_NORMAL, CACTIVERW_RUNL_DUP02, "Stopped");
|
0
|
391 |
iDoStop = EFalse;
|
|
392 |
return;
|
|
393 |
}
|
|
394 |
switch (iCurrentXfer)
|
|
395 |
{
|
|
396 |
case EWaitSetting:
|
|
397 |
#ifdef USB_SC
|
|
398 |
if ((TENDPOINTNUMBER)iTestParams.outPipe <= KMaxEndpointsPerClient)
|
|
399 |
{
|
|
400 |
r = iSCReadBuf.Close();
|
|
401 |
test_KErrNone(r);
|
|
402 |
}
|
|
403 |
if ((TENDPOINTNUMBER)iTestParams.inPipe <= KMaxEndpointsPerClient)
|
|
404 |
{
|
|
405 |
r = iSCWriteBuf.Close();
|
|
406 |
test_KErrNone(r);
|
|
407 |
}
|
|
408 |
#endif
|
|
409 |
if (iTestParams.settingRepeat && ((iRepeat < iTestParams.repeat) || !iLastSetting))
|
|
410 |
{
|
253
|
411 |
gRW[iTestParams.afterIndex]->Resume();
|
0
|
412 |
}
|
253
|
413 |
Suspend(ESuspend);
|
0
|
414 |
break;
|
253
|
415 |
|
0
|
416 |
case ESuspend:
|
|
417 |
#ifdef USB_SC
|
253
|
418 |
TUSB_VERBOSE_PRINT3("Index %d Resumed interface %d setting test=%d",iIndex,iTestParams.interfaceNumber,iTestParams.alternateSetting);
|
|
419 |
if(gVerbose)
|
|
420 |
{
|
|
421 |
OstTraceExt3(TRACE_VERBOSE, CACTIVERW_RUNL_DUP03, "Index %d Resumed interface %d setting test=%d",iIndex,iTestParams.interfaceNumber,iTestParams.alternateSetting);
|
|
422 |
}
|
0
|
423 |
if (iTestParams.alternateSetting != gSettingNumber[iTestParams.interfaceNumber])
|
|
424 |
{
|
|
425 |
r = iPort->StartNextOutAlternateSetting(ETrue);
|
|
426 |
TUSB_VERBOSE_PRINT1("StartNextOutAlternateSetting retValue %d",r);
|
253
|
427 |
if(gVerbose)
|
|
428 |
{
|
|
429 |
OstTrace1(TRACE_VERBOSE, CACTIVERW_RUNL_DUP04, "StartNextOutAlternateSetting retValue %d",r);
|
|
430 |
}
|
0
|
431 |
test_Value(r, (r >= KErrNone) || (r == KErrNotReady) || (r == KErrGeneral));
|
|
432 |
if (r != KErrNotReady)
|
|
433 |
{
|
|
434 |
gSettingNumber[iTestParams.interfaceNumber] = r;
|
|
435 |
}
|
|
436 |
if (iTestParams.alternateSetting != gSettingNumber[iTestParams.interfaceNumber])
|
|
437 |
{
|
|
438 |
Suspend(EAltSetting);
|
|
439 |
break;
|
|
440 |
}
|
|
441 |
}
|
|
442 |
#else
|
|
443 |
iPort->GetAlternateSetting (altSetting);
|
253
|
444 |
TUSB_VERBOSE_PRINT4("Index %d Resumed interface %d setting test=%d actual=%d",iIndex,iTestParams.interfaceNumber,iTestParams.alternateSetting,altSetting);
|
|
445 |
if(gVerbose)
|
|
446 |
{
|
|
447 |
OstTraceExt4(TRACE_VERBOSE, CACTIVERW_RUNL_DUP05, "Index %d Resumed interface %d setting test=%d actual=%d",iIndex,iTestParams.interfaceNumber,iTestParams.alternateSetting,altSetting);
|
|
448 |
}
|
0
|
449 |
if (gAltSettingOnNotify)
|
|
450 |
{
|
|
451 |
if (iTestParams.alternateSetting != altSetting)
|
|
452 |
{
|
|
453 |
Suspend(EAltSetting);
|
|
454 |
break;
|
|
455 |
}
|
|
456 |
}
|
|
457 |
#endif
|
253
|
458 |
|
0
|
459 |
// If alternate setting is ok drops through to EAltSetting to start next read or write
|
|
460 |
iCurrentXfer = EAltSetting;
|
253
|
461 |
|
0
|
462 |
case EAltSetting:
|
|
463 |
#ifdef USB_SC
|
|
464 |
if (iTestParams.alternateSetting != gSettingNumber[iTestParams.interfaceNumber])
|
|
465 |
{
|
|
466 |
r = iPort->StartNextOutAlternateSetting(ETrue);
|
|
467 |
TUSB_VERBOSE_PRINT1("StartNextOutAlternateSetting retValue %d",r);
|
253
|
468 |
if(gVerbose)
|
|
469 |
{
|
|
470 |
OstTrace1(TRACE_VERBOSE, CACTIVERW_RUNL_DUP06, "StartNextOutAlternateSetting retValue %d",r);
|
|
471 |
}
|
0
|
472 |
test_Value(r, (r >= KErrNone) || (r == KErrNotReady) || (r == KErrGeneral));
|
|
473 |
if (r != KErrNotReady)
|
|
474 |
{
|
|
475 |
gSettingNumber[iTestParams.interfaceNumber] = r;
|
|
476 |
}
|
|
477 |
if (iTestParams.alternateSetting != gSettingNumber[iTestParams.interfaceNumber])
|
|
478 |
{
|
|
479 |
Suspend(EAltSetting);
|
|
480 |
break;
|
|
481 |
}
|
|
482 |
}
|
|
483 |
TUSB_VERBOSE_PRINT4 ("CActiveRW::Runl() EAltSetting interface %d setting %d Out %d In %d",iTestParams.interfaceNumber,iTestParams.alternateSetting,iTestParams.outPipe,iTestParams.inPipe);
|
253
|
484 |
if(gVerbose)
|
|
485 |
{
|
|
486 |
OstTraceExt4 (TRACE_VERBOSE, CACTIVERW_RUNL_DUP07, "CActiveRW::Runl() EAltSetting interface %d setting %d Out %d In %d",iTestParams.interfaceNumber,iTestParams.alternateSetting,iTestParams.outPipe,iTestParams.inPipe);
|
|
487 |
}
|
0
|
488 |
if ((TENDPOINTNUMBER)iTestParams.outPipe <= KMaxEndpointsPerClient)
|
|
489 |
{
|
|
490 |
r = iPort->OpenEndpoint(iSCReadBuf,iTestParams.outPipe);
|
|
491 |
test_KErrNone(r);
|
|
492 |
}
|
|
493 |
if ((TENDPOINTNUMBER)iTestParams.inPipe <= KMaxEndpointsPerClient)
|
|
494 |
{
|
|
495 |
r = iPort->OpenEndpoint(iSCWriteBuf,iTestParams.inPipe);
|
|
496 |
test_KErrNone(r);
|
|
497 |
}
|
|
498 |
#endif
|
|
499 |
if (iXferMode == EReceiveOnly)
|
|
500 |
{
|
|
501 |
// read data and process any available
|
|
502 |
iReadSize = ReadData();
|
|
503 |
if (iReadSize != 0)
|
|
504 |
{
|
|
505 |
ProcessReadXfer();
|
253
|
506 |
}
|
0
|
507 |
}
|
|
508 |
else
|
|
509 |
{
|
|
510 |
SendData(); // or we send data
|
|
511 |
if (iXferMode == ETransmitOnly)
|
|
512 |
{
|
253
|
513 |
iPktNum++;
|
|
514 |
iRepeat++;
|
0
|
515 |
}
|
|
516 |
}
|
|
517 |
break;
|
|
518 |
|
|
519 |
case EWriteXfer:
|
|
520 |
ProcessWriteXfer();
|
|
521 |
break;
|
253
|
522 |
|
0
|
523 |
case EReadXfer:
|
|
524 |
#ifdef USB_SC
|
|
525 |
iReadSize = ReadData();
|
|
526 |
if (iReadSize != 0)
|
|
527 |
{
|
|
528 |
ProcessReadXfer();
|
|
529 |
}
|
|
530 |
#else
|
|
531 |
iReadSize = iReadBuf.Length();
|
|
532 |
ProcessReadXfer();
|
|
533 |
#endif
|
|
534 |
break;
|
253
|
535 |
|
0
|
536 |
default:
|
|
537 |
TUSB_PRINT("Oops. (Shouldn't end up here...)");
|
253
|
538 |
OstTrace0(TRACE_NORMAL, CACTIVERW_RUNL_DUP08, "Oops. (Shouldn't end up here...)");
|
0
|
539 |
break;
|
|
540 |
}
|
|
541 |
return;
|
|
542 |
}
|
|
543 |
|
|
544 |
void CActiveRW::ProcessWriteXfer()
|
|
545 |
{
|
|
546 |
if (iXferMode == ETransmitOnly)
|
|
547 |
{
|
|
548 |
if (iTestParams.settingRepeat && iRepeat)
|
253
|
549 |
{
|
0
|
550 |
if (((iRepeat % iTestParams.settingRepeat) == 0) || (iRepeat >= iTestParams.repeat))
|
|
551 |
{
|
|
552 |
if ((iRepeat < iTestParams.repeat) || !iLastSetting)
|
|
553 |
{
|
|
554 |
#ifdef USB_SC
|
|
555 |
if ((TENDPOINTNUMBER)iTestParams.inPipe <= KMaxEndpointsPerClient)
|
|
556 |
{
|
|
557 |
test_KErrNone(iSCWriteBuf.Close());
|
|
558 |
}
|
|
559 |
#endif
|
253
|
560 |
gRW[iTestParams.afterIndex]->Resume();
|
0
|
561 |
}
|
|
562 |
if (iRepeat < iTestParams.repeat)
|
|
563 |
{
|
253
|
564 |
Suspend(ESuspend);
|
|
565 |
return;
|
0
|
566 |
}
|
|
567 |
}
|
|
568 |
}
|
|
569 |
|
|
570 |
if ((iTestParams.repeat == 0) || (iRepeat < iTestParams.repeat))
|
|
571 |
{
|
|
572 |
// Yield the scheduler to ensure other activeObjects can run
|
|
573 |
if (iRepeat && gYieldRepeat)
|
|
574 |
{
|
|
575 |
if ((iRepeat % gYieldRepeat) == 0)
|
|
576 |
{
|
|
577 |
Yield();
|
|
578 |
}
|
|
579 |
}
|
253
|
580 |
SendData(); // next we send data
|
|
581 |
iPktNum++;
|
0
|
582 |
iRepeat++;
|
|
583 |
}
|
|
584 |
else
|
|
585 |
{
|
|
586 |
TestComplete(ETrue);
|
|
587 |
}
|
|
588 |
}
|
|
589 |
else
|
|
590 |
{
|
|
591 |
// read data and process any available
|
|
592 |
iReadSize = ReadData();
|
|
593 |
if (iReadSize != 0)
|
|
594 |
{
|
|
595 |
ProcessReadXfer();
|
|
596 |
}
|
|
597 |
}
|
|
598 |
|
|
599 |
return;
|
|
600 |
}
|
|
601 |
|
|
602 |
void CActiveRW::ProcessReadXfer()
|
|
603 |
{
|
|
604 |
if ((iReadOffset + iReadSize) > iBufSz)
|
|
605 |
{
|
|
606 |
TUSB_PRINT2("*** rcv'd too much data: 0x%x (expected: 0x%x)", iReadOffset + iReadSize, iBufSz);
|
253
|
607 |
OstTraceExt2(TRACE_NORMAL, CACTIVERW_PROCESSREADXFER, "*** rcv'd too much data: 0x%x (expected: 0x%x)", iReadOffset + iReadSize, iBufSz);
|
0
|
608 |
test(EFalse);
|
|
609 |
}
|
|
610 |
|
|
611 |
if (iXferMode == EReceiveOnly)
|
|
612 |
{
|
|
613 |
if (iReadOffset == 0)
|
|
614 |
{
|
|
615 |
#ifdef USB_SC
|
|
616 |
const TUint32 num = *reinterpret_cast<const TUint32*>(iSCReadData);
|
|
617 |
#else
|
|
618 |
const TUint32 num = *reinterpret_cast<const TUint32*>(iReadBuf.Ptr());
|
253
|
619 |
#endif
|
0
|
620 |
if (num != iPktNum)
|
|
621 |
{
|
|
622 |
TUSB_PRINT3("*** Repeat %d rcv'd wrong pkt number: 0x%x (expected: 0x%x)", iRepeat, num, iPktNum);
|
253
|
623 |
OstTraceExt3(TRACE_NORMAL, CACTIVERW_PROCESSREADXFER_DUP01, "*** Repeat %d rcv'd wrong pkt number: 0x%x (expected: 0x%x)", (TInt32)iRepeat, (TInt32)num, (TInt32)iPktNum);
|
0
|
624 |
iPktNum = num;
|
|
625 |
test(EFalse);
|
|
626 |
}
|
|
627 |
}
|
|
628 |
if (iDiskAccessEnabled)
|
|
629 |
{
|
|
630 |
// Write out to disk previous completed Read
|
|
631 |
#ifdef USB_SC
|
|
632 |
TPtr8 readBuf((TUint8 *)iSCReadData,iReadSize,iReadSize);
|
|
633 |
WriteBufferToDisk(readBuf, iReadSize);
|
253
|
634 |
#else
|
0
|
635 |
TUSB_VERBOSE_PRINT2("Max Buffer Size = %d (iReadBuf.Size(): %d)", iTestParams.maxSize, iReadBuf.Size());
|
253
|
636 |
if(gVerbose)
|
|
637 |
{
|
|
638 |
OstTraceExt2(TRACE_VERBOSE, CACTIVERW_PROCESSREADXFER_DUP02, "Max Buffer Size = %u (iReadBuf.Size(): %d)", (TUint32)iTestParams.maxSize, (TUint32)iReadBuf.Size());
|
|
639 |
}
|
0
|
640 |
WriteBufferToDisk(iReadBuf, iTestParams.maxSize);
|
|
641 |
#endif
|
253
|
642 |
}
|
0
|
643 |
iReadOffset += iReadSize;
|
|
644 |
if (iReadOffset >= iBufSz)
|
|
645 |
{
|
253
|
646 |
iReadOffset = 0;
|
0
|
647 |
}
|
|
648 |
else
|
|
649 |
{
|
|
650 |
#ifdef USB_SC
|
|
651 |
iReadSize = ReadData();
|
|
652 |
if (iReadSize)
|
|
653 |
{
|
|
654 |
ProcessReadXfer();
|
|
655 |
}
|
|
656 |
#endif
|
|
657 |
return;
|
|
658 |
}
|
|
659 |
iPktNum++;
|
|
660 |
iRepeat++;
|
|
661 |
iReadSize = 0;
|
|
662 |
if (iTestParams.settingRepeat)
|
253
|
663 |
{
|
0
|
664 |
if (((iRepeat % iTestParams.settingRepeat) == 0) || (iRepeat >= iTestParams.repeat))
|
|
665 |
{
|
|
666 |
#ifdef USB_SC
|
|
667 |
if ((TENDPOINTNUMBER)iTestParams.outPipe <= KMaxEndpointsPerClient)
|
|
668 |
{
|
|
669 |
test_KErrNone(iSCReadBuf.Close());
|
|
670 |
}
|
|
671 |
#endif
|
|
672 |
if ((iRepeat < iTestParams.repeat) || !iLastSetting)
|
|
673 |
{
|
253
|
674 |
gRW[iTestParams.afterIndex]->Resume();
|
0
|
675 |
}
|
|
676 |
if (iRepeat < iTestParams.repeat)
|
|
677 |
{
|
253
|
678 |
Suspend(ESuspend);
|
|
679 |
return;
|
0
|
680 |
}
|
|
681 |
}
|
|
682 |
}
|
|
683 |
if ((iTestParams.repeat == 0) || (iRepeat < iTestParams.repeat))
|
|
684 |
{
|
|
685 |
// Yield the scheduler to ensure other activeObjects can run
|
|
686 |
if (iRepeat && gYieldRepeat)
|
|
687 |
{
|
|
688 |
if ((iRepeat % gYieldRepeat) == 0)
|
|
689 |
{
|
|
690 |
Yield();
|
|
691 |
}
|
|
692 |
}
|
|
693 |
#ifdef USB_SC
|
|
694 |
TRequestStatus* status = &iStatus;
|
|
695 |
User::RequestComplete(status,KErrNone);
|
|
696 |
if (!IsActive())
|
|
697 |
{
|
|
698 |
SetActive();
|
253
|
699 |
}
|
0
|
700 |
#else
|
253
|
701 |
iReadSize = ReadData();
|
0
|
702 |
#endif
|
|
703 |
}
|
|
704 |
else
|
|
705 |
{
|
|
706 |
TestComplete(ETrue);
|
|
707 |
}
|
|
708 |
}
|
|
709 |
else
|
|
710 |
{
|
|
711 |
if (iXferMode == ELoopComp)
|
|
712 |
{
|
|
713 |
test(CompareBuffers());
|
|
714 |
}
|
|
715 |
else if (iBufSz > 3)
|
|
716 |
{
|
|
717 |
if (iReadOffset == 0)
|
|
718 |
{
|
|
719 |
#ifdef USB_SC
|
|
720 |
const TUint32 num = *reinterpret_cast<const TUint32*>(iSCReadData);
|
|
721 |
#else
|
|
722 |
const TUint32 num = *reinterpret_cast<const TUint32*>(iReadBuf.Ptr());
|
|
723 |
#endif
|
|
724 |
if (num != iPktNum)
|
|
725 |
{
|
|
726 |
TUSB_PRINT2("*** rcv'd wrong pkt number: 0x%x (expected: 0x%x)", num, iPktNum);
|
253
|
727 |
OstTraceExt2(TRACE_NORMAL, CACTIVERW_PROCESSREADXFER_DUP03, "*** rcv'd wrong pkt number: 0x%x (expected: 0x%x)", num, iPktNum);
|
0
|
728 |
}
|
|
729 |
}
|
|
730 |
}
|
|
731 |
iReadOffset += iReadSize;
|
|
732 |
if (iReadOffset >= iBufSz)
|
|
733 |
{
|
253
|
734 |
iReadOffset = 0;
|
0
|
735 |
}
|
|
736 |
else
|
|
737 |
{
|
|
738 |
iReadSize = ReadData();
|
|
739 |
if (iReadSize)
|
|
740 |
{
|
|
741 |
ProcessReadXfer();
|
|
742 |
}
|
|
743 |
return;
|
|
744 |
}
|
|
745 |
if ((TUint)iBufSz == iTestParams.maxSize)
|
|
746 |
{
|
|
747 |
iBufSz = iTestParams.minSize;
|
|
748 |
}
|
|
749 |
else
|
|
750 |
{
|
|
751 |
iBufSz++;
|
|
752 |
}
|
|
753 |
iPktNum++;
|
|
754 |
iRepeat++;
|
|
755 |
iReadSize = 0;
|
|
756 |
if (iTestParams.settingRepeat)
|
253
|
757 |
{
|
0
|
758 |
if (((iRepeat % iTestParams.settingRepeat) == 0) || (iRepeat >= iTestParams.repeat))
|
|
759 |
{
|
|
760 |
if (iRepeat < iTestParams.repeat)
|
|
761 |
{
|
|
762 |
SendWaitSetting();
|
253
|
763 |
return;
|
0
|
764 |
}
|
|
765 |
else
|
|
766 |
{
|
|
767 |
#ifdef USB_SC
|
|
768 |
if ((TENDPOINTNUMBER)iTestParams.outPipe <= KMaxEndpointsPerClient)
|
|
769 |
{
|
|
770 |
test_KErrNone(iSCReadBuf.Close());
|
|
771 |
}
|
|
772 |
if ((TENDPOINTNUMBER)iTestParams.inPipe <= KMaxEndpointsPerClient)
|
|
773 |
{
|
|
774 |
test_KErrNone(iSCWriteBuf.Close());
|
|
775 |
}
|
253
|
776 |
#endif
|
0
|
777 |
if (!iLastSetting)
|
|
778 |
{
|
253
|
779 |
gRW[iTestParams.afterIndex]->Resume();
|
0
|
780 |
}
|
|
781 |
}
|
|
782 |
}
|
|
783 |
}
|
253
|
784 |
|
0
|
785 |
if ((iTestParams.repeat == 0) || (iRepeat < iTestParams.repeat))
|
|
786 |
{
|
|
787 |
// Yield the scheduler to ensure other activeObjects can run
|
|
788 |
if (iRepeat && gYieldRepeat)
|
|
789 |
{
|
|
790 |
if ((iRepeat % gYieldRepeat) == 0)
|
|
791 |
{
|
|
792 |
Yield();
|
|
793 |
}
|
|
794 |
}
|
253
|
795 |
SendData();
|
0
|
796 |
}
|
|
797 |
else
|
|
798 |
{
|
|
799 |
TestComplete(ETrue);
|
253
|
800 |
}
|
0
|
801 |
}
|
|
802 |
|
|
803 |
return;
|
|
804 |
}
|
|
805 |
|
|
806 |
void CActiveRW::SendWaitSetting()
|
|
807 |
{
|
|
808 |
__ASSERT_ALWAYS(!IsActive(), User::Panic(KActivePanic, 662));
|
|
809 |
#ifdef USB_SC
|
|
810 |
TAny* inBuffer;
|
|
811 |
TUint inBufLength;
|
|
812 |
test_KErrNone(iSCWriteBuf.GetInBufferRange(inBuffer, inBufLength));
|
|
813 |
test_KErrNone(iSCWriteBuf.WriteBuffer(inBuffer,KWaitSettingSize,FALSE,iStatus));
|
|
814 |
#else
|
|
815 |
iWriteBuf.SetLength(KWaitSettingSize);
|
|
816 |
iPort->Write(iStatus, (TENDPOINTNUMBER)iTestParams.inPipe, iWriteBuf, KWaitSettingSize);
|
|
817 |
#endif
|
|
818 |
iCurrentXfer = EWaitSetting;
|
|
819 |
if (!IsActive())
|
|
820 |
{
|
|
821 |
SetActive();
|
|
822 |
}
|
|
823 |
}
|
|
824 |
|
253
|
825 |
|
0
|
826 |
void CActiveRW::SendData()
|
|
827 |
{
|
|
828 |
__ASSERT_ALWAYS(!IsActive(), User::Panic(KActivePanic, 663));
|
|
829 |
#ifdef USB_SC
|
|
830 |
TUint8* inBuffer;
|
|
831 |
TUint inBufLength;
|
|
832 |
test_KErrNone(iSCWriteBuf.GetInBufferRange((TAny*&)inBuffer, inBufLength));
|
|
833 |
if (iDiskAccessEnabled)
|
|
834 |
{
|
|
835 |
TPtr8 writeBuf((TUint8 *)inBuffer,iBufSz,iBufSz);
|
|
836 |
ReadBufferFromDisk(writeBuf, iBufSz);
|
|
837 |
}
|
|
838 |
if (iBufSz > 3)
|
|
839 |
*reinterpret_cast<TUint32*>(inBuffer) = iPktNum;
|
253
|
840 |
|
0
|
841 |
if (iXferMode == ELoopComp)
|
|
842 |
{
|
|
843 |
for (TUint i = 4; i < iBufSz; i++)
|
|
844 |
{
|
|
845 |
*(inBuffer+i) = static_cast<TUint8>((iPktNum+i) & 0x000000ff);
|
|
846 |
}
|
|
847 |
}
|
|
848 |
TUSB_VERBOSE_PRINT3("SendData interface %d setting %d endpoint %d",iTestParams.interfaceNumber,iTestParams.alternateSetting,iTestParams.inPipe);
|
253
|
849 |
if(gVerbose)
|
|
850 |
{
|
|
851 |
OstTraceExt3(TRACE_VERBOSE, CACTIVERW_SENDDATA, "SendData interface %d setting %d endpoint %d",iTestParams.interfaceNumber,iTestParams.alternateSetting,iTestParams.inPipe);
|
|
852 |
}
|
0
|
853 |
iCurrentXfer = EWriteXfer;
|
|
854 |
TInt r = iSCWriteBuf.WriteBuffer(inBuffer, iBufSz, FALSE, iStatus);
|
|
855 |
test_KErrNone(r);
|
|
856 |
#else
|
|
857 |
if (iDiskAccessEnabled)
|
|
858 |
{
|
|
859 |
ReadBufferFromDisk(iWriteBuf, iBufSz);
|
|
860 |
}
|
|
861 |
iWriteBuf.SetLength(iBufSz);
|
|
862 |
if (iBufSz > 3)
|
|
863 |
*reinterpret_cast<TUint32*>(const_cast<TUint8*>(iWriteBuf.Ptr())) = iPktNum;
|
|
864 |
if (iXferMode == ELoopComp)
|
|
865 |
{
|
|
866 |
for (TUint i = 4; i < iBufSz; i++)
|
|
867 |
{
|
|
868 |
iWriteBuf[i] = static_cast<TUint8>((iPktNum+i) & 0x000000ff);
|
|
869 |
}
|
|
870 |
}
|
|
871 |
|
|
872 |
TUSB_VERBOSE_PRINT3("SendData interface %d setting %d endpoint %d",iTestParams.interfaceNumber,iTestParams.alternateSetting,iTestParams.inPipe);
|
253
|
873 |
if(gVerbose)
|
|
874 |
{
|
|
875 |
OstTraceExt3(TRACE_VERBOSE, CACTIVERW_SENDDATA_DUP01, "SendData interface %d setting %d endpoint %d",iTestParams.interfaceNumber,iTestParams.alternateSetting,iTestParams.inPipe);
|
|
876 |
}
|
0
|
877 |
iCurrentXfer = EWriteXfer;
|
|
878 |
iPort->Write(iStatus, (TENDPOINTNUMBER)iTestParams.inPipe, iWriteBuf, iBufSz);
|
|
879 |
#endif
|
|
880 |
if (!IsActive())
|
|
881 |
{
|
|
882 |
SetActive();
|
|
883 |
}
|
|
884 |
}
|
|
885 |
|
|
886 |
TInt CActiveRW::WriteToDisk(TChar aDriveLetter)
|
|
887 |
{
|
|
888 |
iDiskAccessEnabled = ETrue;
|
|
889 |
TInt r = KErrNone;
|
|
890 |
|
|
891 |
iFileName.Format(_L("%c:"), aDriveLetter.operator TUint());
|
|
892 |
iFileName.Append(KFileName);
|
|
893 |
TUSB_PRINT1("\nFilename = %S", &iFileName);
|
253
|
894 |
OstTraceExt1(TRACE_NORMAL, CACTIVERW_WRITETODISK, "\nFilename = %S", iFileName);
|
0
|
895 |
|
|
896 |
// open the record file
|
|
897 |
r = iFile.Replace(iFs, iFileName, EFileWrite);
|
|
898 |
iFileOffset = 0;
|
|
899 |
if (r != KErrNone)
|
|
900 |
{
|
|
901 |
TUSB_PRINT1("RFile::Replace() returned %d", r);
|
253
|
902 |
OstTrace1(TRACE_ERROR, CACTIVERW_WRITETODISK_DUP01, "RFile::Replace() returned %d", r);
|
0
|
903 |
iDiskAccessEnabled = EFalse;
|
|
904 |
return r;
|
|
905 |
}
|
253
|
906 |
|
0
|
907 |
return r;
|
|
908 |
}
|
|
909 |
|
|
910 |
|
|
911 |
TInt CActiveRW::ReadFromDisk(TChar aDriveLetter, TInt aMaxFileSize)
|
|
912 |
{
|
|
913 |
iDiskAccessEnabled = ETrue;
|
|
914 |
TInt r = KErrNone;
|
|
915 |
|
|
916 |
iFileName.Format(_L("%c:"), aDriveLetter.operator TUint());
|
|
917 |
iFileName.Append(KFileName);
|
|
918 |
TUSB_PRINT1("\nFilename = %S", &iFileName);
|
253
|
919 |
OstTraceExt1(TRACE_NORMAL, CACTIVERW_READFROMDISK, "\nFilename = %S", iFileName);
|
0
|
920 |
TUSB_PRINT1("File size: %d", aMaxFileSize);
|
253
|
921 |
OstTrace1(TRACE_NORMAL, CACTIVERW_READFROMDISK_DUP01, "File size: %d", aMaxFileSize);
|
0
|
922 |
|
|
923 |
// First create the file & fill it
|
|
924 |
r = iFile.Replace(iFs, iFileName, EFileWrite);
|
|
925 |
if (r != KErrNone)
|
|
926 |
{
|
|
927 |
TUSB_PRINT1("RFile::Replace() returned %d", r);
|
253
|
928 |
OstTrace1(TRACE_ERROR, CACTIVERW_READFROMDISK_DUP02, "RFile::Replace() returned %d", r);
|
0
|
929 |
iDiskAccessEnabled = EFalse;
|
|
930 |
return r;
|
|
931 |
}
|
|
932 |
const TInt KBufferSize = 4 * 1024;
|
|
933 |
TBuf8<KBufferSize> buffer;
|
|
934 |
buffer.SetLength(KBufferSize);
|
|
935 |
for (TInt n = 0; n < KBufferSize; n++)
|
|
936 |
{
|
|
937 |
buffer[n] = static_cast<TUint8>(n & 0x000000ff);
|
|
938 |
}
|
|
939 |
TUSB_PRINT("Writing data to file (this may take some minutes...)");
|
253
|
940 |
OstTrace0(TRACE_NORMAL, CACTIVERW_READFROMDISK_DUP03, "Writing data to file (this may take some minutes...)");
|
0
|
941 |
for (TInt n = 0; n < aMaxFileSize; n += KBufferSize)
|
|
942 |
{
|
|
943 |
r = iFile.Write(buffer, KBufferSize);
|
|
944 |
if (r != KErrNone)
|
|
945 |
{
|
|
946 |
TUSB_PRINT1("RFile::Write() returned %d (disk full?)", r);
|
253
|
947 |
OstTrace1(TRACE_ERROR, CACTIVERW_READFROMDISK_DUP04, "RFile::Write() returned %d (disk full?)", r);
|
0
|
948 |
iFile.Close();
|
|
949 |
iDiskAccessEnabled = EFalse;
|
|
950 |
return r;
|
|
951 |
}
|
|
952 |
}
|
|
953 |
TUSB_PRINT("Done.");
|
253
|
954 |
OstTrace0(TRACE_NORMAL, CACTIVERW_READFROMDISK_DUP05, "Done.");
|
0
|
955 |
iFile.Close();
|
|
956 |
// Now open the file for reading
|
|
957 |
r = iFile.Open(iFs, iFileName, EFileRead);
|
|
958 |
if (r != KErrNone)
|
|
959 |
{
|
|
960 |
TUSB_PRINT1("RFile::Open() returned %d", r);
|
253
|
961 |
OstTrace1(TRACE_ERROR, CACTIVERW_READFROMDISK_DUP06, "RFile::Open() returned %d", r);
|
0
|
962 |
iDiskAccessEnabled = EFalse;
|
|
963 |
return r;
|
|
964 |
}
|
|
965 |
iFileOffset = 0;
|
|
966 |
|
|
967 |
return r;
|
|
968 |
}
|
|
969 |
|
|
970 |
|
|
971 |
void CActiveRW::WriteBufferToDisk(TDes8& aBuffer, TInt aLen)
|
|
972 |
{
|
|
973 |
TUSB_VERBOSE_PRINT1("CActiveRW::WriteBufferToDisk(), len = %d", aLen);
|
253
|
974 |
if(gVerbose)
|
|
975 |
{
|
|
976 |
OstTrace1(TRACE_VERBOSE, CACTIVERW_WRITEBUFFERTODISK, "CActiveRW::WriteBufferToDisk(), len = %d", aLen);
|
|
977 |
}
|
0
|
978 |
TInt r = iFile.Write(aBuffer, aLen);
|
|
979 |
if (r != KErrNone)
|
|
980 |
{
|
|
981 |
TUSB_PRINT2("Error writing to %S (%d)", &iFileName, r);
|
253
|
982 |
OstTraceExt2(TRACE_ERROR, CACTIVERW_WRITEBUFFERTODISK_DUP01, "Error writing to %S (%d)", iFileName, r);
|
0
|
983 |
iDiskAccessEnabled = EFalse;
|
|
984 |
return;
|
|
985 |
}
|
|
986 |
iFileOffset += aLen;
|
|
987 |
}
|
|
988 |
|
|
989 |
|
|
990 |
void CActiveRW::ReadBufferFromDisk(TDes8& aBuffer, TInt aLen)
|
|
991 |
{
|
|
992 |
const TInt r = iFile.Read(aBuffer, aLen);
|
|
993 |
if (r != KErrNone)
|
|
994 |
{
|
|
995 |
TUSB_PRINT2("Error reading from %S (%d)", &iFileName, r);
|
253
|
996 |
OstTraceExt2(TRACE_ERROR, CACTIVERW_READBUFFERFROMDISK, "Error reading from %S (%d)", iFileName, r);
|
0
|
997 |
iDiskAccessEnabled = EFalse;
|
|
998 |
return;
|
|
999 |
}
|
|
1000 |
TInt readLen = aBuffer.Length();
|
|
1001 |
TUSB_VERBOSE_PRINT1("CActiveRW::ReadBufferFromDisk(), len = %d\n", readLen);
|
253
|
1002 |
if(gVerbose)
|
|
1003 |
{
|
|
1004 |
OstTrace1(TRACE_VERBOSE, CACTIVERW_READBUFFERFROMDISK_DUP01, "CActiveRW::ReadBufferFromDisk(), len = %d\n", readLen);
|
|
1005 |
}
|
0
|
1006 |
if (readLen < aLen)
|
|
1007 |
{
|
|
1008 |
TUSB_PRINT3("Only %d bytes of %d read from file %S)",
|
|
1009 |
readLen, aLen, &iFileName);
|
253
|
1010 |
OstTraceExt3(TRACE_NORMAL, CACTIVERW_READBUFFERFROMDISK_DUP02, "Only %d bytes of %d read from file %S)",
|
|
1011 |
readLen, aLen, iFileName);
|
0
|
1012 |
iDiskAccessEnabled = EFalse;
|
|
1013 |
return;
|
|
1014 |
}
|
|
1015 |
iFileOffset += aLen;
|
|
1016 |
}
|
|
1017 |
|
|
1018 |
|
|
1019 |
TUint CActiveRW::ReadData()
|
|
1020 |
{
|
|
1021 |
__ASSERT_ALWAYS(!IsActive(), User::Panic(KActivePanic, 664));
|
|
1022 |
iCurrentXfer = EReadXfer;
|
|
1023 |
#ifdef USB_SC
|
253
|
1024 |
TUint readSize = 0; // note that this returns zero when asynchronous read is pending
|
0
|
1025 |
TInt r = 0;
|
|
1026 |
do
|
|
1027 |
{
|
|
1028 |
r = iSCReadBuf.GetBuffer (iSCReadData,readSize,iReadZlp,iStatus);
|
|
1029 |
test_Value(r, (r == KErrNone) || (r == KErrCompletion) || (r == KErrEof));
|
253
|
1030 |
TUSB_VERBOSE_PRINT4("Get Buffer Return code %d Status %d DataPtr 0x%x Size %d", r, iStatus.Int(),iSCReadData,readSize);
|
|
1031 |
if(gVerbose)
|
|
1032 |
{
|
|
1033 |
OstTraceExt4(TRACE_VERBOSE, CACTIVERW_READDATA, "Get Buffer Return code %d Status %d DataPtr 0x%x Size %d", r, iStatus.Int(),(TInt)iSCReadData,readSize);
|
|
1034 |
}
|
0
|
1035 |
}
|
|
1036 |
while ((r == KErrCompletion && readSize == 0) || (r == KErrEof));
|
|
1037 |
if (r == KErrCompletion)
|
|
1038 |
{
|
|
1039 |
return readSize;
|
|
1040 |
}
|
|
1041 |
else
|
|
1042 |
{
|
|
1043 |
if (!IsActive())
|
|
1044 |
{
|
|
1045 |
SetActive();
|
|
1046 |
}
|
|
1047 |
return 0;
|
|
1048 |
}
|
|
1049 |
#else
|
|
1050 |
iReadBuf.SetLength (0);
|
|
1051 |
if (iBufSz <= iMaxPktSz)
|
|
1052 |
{
|
|
1053 |
// Testing the packet version of Read()
|
|
1054 |
TUSB_VERBOSE_PRINT3("ReadData (single packet) interface %d setting %d endpoint %d",iTestParams.interfaceNumber,iTestParams.alternateSetting,iTestParams.outPipe);
|
253
|
1055 |
if(gVerbose)
|
|
1056 |
{
|
|
1057 |
OstTraceExt3(TRACE_VERBOSE, CACTIVERW_READDATA_DUP01, "ReadData (single packet) interface %d setting %d endpoint %d",iTestParams.interfaceNumber,iTestParams.alternateSetting,iTestParams.outPipe);
|
|
1058 |
}
|
0
|
1059 |
iPort->ReadPacket(iStatus, (TENDPOINTNUMBER)iTestParams.outPipe, iReadBuf, iBufSz);
|
|
1060 |
}
|
|
1061 |
else if ((TUint)iBufSz == iTestParams.maxSize)
|
|
1062 |
{
|
|
1063 |
// Testing the two-parameter version
|
|
1064 |
TUSB_VERBOSE_PRINT3("ReadData (w/o length) interface %d setting %d endpoint %d",iTestParams.interfaceNumber,iTestParams.alternateSetting,iTestParams.outPipe);
|
253
|
1065 |
if(gVerbose)
|
|
1066 |
{
|
|
1067 |
OstTraceExt3(TRACE_VERBOSE, CACTIVERW_READDATA_DUP02, "ReadData (w/o length) interface %d setting %d endpoint %d",iTestParams.interfaceNumber,iTestParams.alternateSetting,iTestParams.outPipe);
|
|
1068 |
}
|
0
|
1069 |
iPort->Read(iStatus, (TENDPOINTNUMBER)iTestParams.outPipe, iReadBuf);
|
|
1070 |
}
|
|
1071 |
else
|
|
1072 |
{
|
|
1073 |
// otherwise, we use the universal default version
|
|
1074 |
// Testing the three-parameter version
|
|
1075 |
TUSB_VERBOSE_PRINT3("ReadData (normal) interface %d setting %d endpoint %d",iTestParams.interfaceNumber,iTestParams.alternateSetting,iTestParams.outPipe);
|
253
|
1076 |
if(gVerbose)
|
|
1077 |
{
|
|
1078 |
OstTraceExt3(TRACE_VERBOSE, CACTIVERW_READDATA_DUP03, "ReadData (normal) interface %d setting %d endpoint %d",iTestParams.interfaceNumber,iTestParams.alternateSetting,iTestParams.outPipe);
|
|
1079 |
}
|
0
|
1080 |
iPort->Read(iStatus, (TENDPOINTNUMBER)iTestParams.outPipe, iReadBuf, iBufSz);
|
|
1081 |
}
|
|
1082 |
if (!IsActive())
|
|
1083 |
{
|
|
1084 |
SetActive();
|
|
1085 |
}
|
|
1086 |
return 0;
|
|
1087 |
#endif
|
|
1088 |
}
|
|
1089 |
|
|
1090 |
|
|
1091 |
void CActiveRW::Stop()
|
|
1092 |
{
|
|
1093 |
if (!IsActive())
|
|
1094 |
{
|
|
1095 |
TUSB_PRINT("CActiveRW::Stop(): Not active");
|
253
|
1096 |
OstTrace0(TRACE_NORMAL, CACTIVERW_STOP, "CActiveRW::Stop(): Not active");
|
0
|
1097 |
return;
|
|
1098 |
}
|
|
1099 |
TUSB_PRINT("Cancelling outstanding transfer requests\n");
|
253
|
1100 |
OstTrace0(TRACE_NORMAL, CACTIVERW_STOP_DUP01, "Cancelling outstanding transfer requests\n");
|
0
|
1101 |
iBufSz = 0;
|
|
1102 |
iPktNum = 0;
|
|
1103 |
iDoStop = ETrue;
|
|
1104 |
iCurrentXfer = ETxferNone;
|
|
1105 |
Cancel();
|
|
1106 |
}
|
|
1107 |
|
|
1108 |
|
|
1109 |
void CActiveRW::DoCancel()
|
|
1110 |
{
|
|
1111 |
TUSB_VERBOSE_PRINT("CActiveRW::DoCancel()");
|
253
|
1112 |
if(gVerbose)
|
|
1113 |
{
|
|
1114 |
OstTrace0(TRACE_VERBOSE, CACTIVERW_DOCANCEL, "CActiveRW::DoCancel()");
|
|
1115 |
}
|
0
|
1116 |
// Canceling the transfer requests can be done explicitly
|
|
1117 |
// for every transfer...
|
|
1118 |
iPort->WriteCancel((TENDPOINTNUMBER)iTestParams.inPipe);
|
|
1119 |
iPort->ReadCancel((TENDPOINTNUMBER)iTestParams.outPipe);
|
|
1120 |
// or like this:
|
253
|
1121 |
// iPort->EndpointTransferCancel(~0);
|
0
|
1122 |
}
|
|
1123 |
|
|
1124 |
|
|
1125 |
TBool CActiveRW::CompareBuffers()
|
|
1126 |
{
|
|
1127 |
TUSB_VERBOSE_PRINT2("CActiveRW::CompareBuffers() ReadOffset %d ReadSize %d",iReadOffset,iReadSize);
|
253
|
1128 |
if(gVerbose)
|
|
1129 |
{
|
|
1130 |
OstTraceExt2(TRACE_VERBOSE, CACTIVERW_COMPAREBUFFERS, "CActiveRW::CompareBuffers() ReadOffset %d ReadSize %d",iReadOffset,iReadSize);
|
|
1131 |
}
|
0
|
1132 |
#ifdef USB_SC
|
|
1133 |
TUint8 *readPtr = reinterpret_cast<TUint8*>(iSCReadData);
|
|
1134 |
TUint8* writePtr;
|
|
1135 |
TUint inBufLength;
|
|
1136 |
test_KErrNone(iSCWriteBuf.GetInBufferRange((TAny*&)writePtr, inBufLength));
|
|
1137 |
writePtr += iReadOffset;
|
|
1138 |
#endif
|
|
1139 |
for (TUint i = 0; i < iReadSize; i++)
|
|
1140 |
{
|
|
1141 |
#ifdef USB_SC
|
|
1142 |
if (*readPtr != *writePtr)
|
|
1143 |
{
|
253
|
1144 |
TUSB_PRINT3 ("*** Error while comparing tx & rx buffers packet 0x%x length %d index %d",iPktNum, iReadSize,i + iReadOffset);
|
|
1145 |
OstTraceExt3 (TRACE_NORMAL, CACTIVERW_COMPAREBUFFERS_DUP01, "*** Error while comparing tx & rx buffers packet 0x%x length %u index %u",iPktNum, (TUint32)iReadSize,(TUint32)(i + iReadOffset));
|
|
1146 |
TUSB_PRINT2 ("*** Read byte 0x%x Write byte 0x%x",*readPtr,*writePtr);
|
|
1147 |
OstTraceExt2 (TRACE_NORMAL, CACTIVERW_COMPAREBUFFERS_DUP02, "*** Read byte 0x%x Write byte 0x%x",*readPtr,*writePtr);
|
0
|
1148 |
return EFalse;
|
|
1149 |
}
|
|
1150 |
readPtr++;
|
|
1151 |
writePtr++;
|
|
1152 |
#else
|
|
1153 |
if (iReadBuf[i] != iWriteBuf[i + iReadOffset])
|
|
1154 |
{
|
253
|
1155 |
TUSB_PRINT3 ("*** Error while comparing tx & rx buffers packet 0x%x length %d index %d",iPktNum, iReadSize,i + iReadOffset);
|
|
1156 |
OstTraceExt3 (TRACE_NORMAL, CACTIVERW_COMPAREBUFFERS_DUP03, "*** Error while comparing tx & rx buffers packet 0x%x length %u index %u",(TUint32)iPktNum, (TUint32)iReadSize,(TUint32)(i + iReadOffset));
|
0
|
1157 |
TUSB_PRINT5 ("WriteBuf Start 0x%x 0x%x 0x%x 0x%x 0x%x",
|
253
|
1158 |
iWriteBuf[i], iWriteBuf[i+1], iWriteBuf[i+2], iWriteBuf[i+3], iWriteBuf[i+4]);
|
|
1159 |
OstTraceExt5 (TRACE_NORMAL, CACTIVERW_COMPAREBUFFERS_DUP04, "WriteBuf Start 0x%x 0x%x 0x%x 0x%x 0x%x",
|
|
1160 |
iWriteBuf[i], iWriteBuf[i+1], iWriteBuf[i+2], iWriteBuf[i+3], iWriteBuf[i+4]);
|
0
|
1161 |
TUSB_PRINT5 ("ReadBuf Start 0x%x 0x%x 0x%x 0x%x 0x%x",
|
|
1162 |
iReadBuf[i], iReadBuf[i+1], iReadBuf[i+2], iReadBuf[i+3], iReadBuf[i+4]);
|
253
|
1163 |
OstTraceExt5 (TRACE_NORMAL, CACTIVERW_COMPAREBUFFERS_DUP05, "ReadBuf Start 0x%x 0x%x 0x%x 0x%x 0x%x",
|
|
1164 |
iReadBuf[i], iReadBuf[i+1], iReadBuf[i+2], iReadBuf[i+3], iReadBuf[i+4]);
|
0
|
1165 |
if (iReadSize >= 10)
|
|
1166 |
{
|
|
1167 |
TUSB_PRINT5 ("WriteBuf End 0x%x 0x%x 0x%x 0x%x 0x%x",
|
253
|
1168 |
iWriteBuf[iReadSize-5], iWriteBuf[iReadSize-4], iWriteBuf[iReadSize-3], iWriteBuf[iReadSize-2], iWriteBuf[iReadSize-1]);
|
|
1169 |
OstTraceExt5 (TRACE_NORMAL, CACTIVERW_COMPAREBUFFERS_DUP06, "WriteBuf End 0x%x 0x%x 0x%x 0x%x 0x%x",
|
|
1170 |
iWriteBuf[iReadSize-5], iWriteBuf[iReadSize-4], iWriteBuf[iReadSize-3], iWriteBuf[iReadSize-2], iWriteBuf[iReadSize-1]);
|
0
|
1171 |
TUSB_PRINT5 ("ReadBuf End 0x%x 0x%x 0x%x 0x%x 0x%x",
|
253
|
1172 |
iReadBuf[iReadSize-5], iReadBuf[iReadSize-4], iReadBuf[iReadSize-3], iReadBuf[iReadSize-2], iReadBuf[iReadSize-1]);
|
|
1173 |
OstTraceExt5 (TRACE_NORMAL, CACTIVERW_COMPAREBUFFERS_DUP07, "ReadBuf End 0x%x 0x%x 0x%x 0x%x 0x%x",
|
|
1174 |
iReadBuf[iReadSize-5], iReadBuf[iReadSize-4], iReadBuf[iReadSize-3], iReadBuf[iReadSize-2], iReadBuf[iReadSize-1]);
|
0
|
1175 |
}
|
|
1176 |
return EFalse;
|
|
1177 |
}
|
|
1178 |
#endif
|
|
1179 |
}
|
|
1180 |
return ETrue;
|
|
1181 |
}
|
|
1182 |
|
|
1183 |
void CActiveRW::TestComplete(TBool aResult)
|
|
1184 |
{
|
|
1185 |
TUSB_VERBOSE_PRINT("CActiveRW::TestComplete()");
|
253
|
1186 |
if(gVerbose)
|
|
1187 |
{
|
|
1188 |
OstTrace0(TRACE_VERBOSE, CACTIVERW_TESTCOMPLETE, "CActiveRW::TestComplete()");
|
|
1189 |
}
|
0
|
1190 |
|
|
1191 |
iResult = aResult;
|
253
|
1192 |
|
0
|
1193 |
if (iComplete || !iResult || iTestParams.repeat == 0)
|
|
1194 |
{
|
|
1195 |
test(iResult);
|
|
1196 |
test.End();
|
|
1197 |
gRW[iIndex] = NULL;
|
|
1198 |
delete this;
|
|
1199 |
}
|
|
1200 |
else
|
|
1201 |
{
|
|
1202 |
iComplete = ETrue;
|
|
1203 |
}
|
|
1204 |
}
|
|
1205 |
|
|
1206 |
// -eof-
|