author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 11 May 2010 17:28:22 +0300 | |
branch | RCL_3 |
changeset 26 | c734af59ce98 |
parent 19 | 4a8fed1c0ef6 |
child 43 | c1f20ce4abcf |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 2000-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_usbco2.cpp |
|
15 |
// USB Test Program T_USB, functional part. |
|
16 |
// Device-side part, to work against USBRFLCT running on the host. |
|
17 |
// |
|
18 |
// |
|
19 |
||
20 |
#include <e32hal.h> |
|
21 |
#include <e32uid.h> |
|
22 |
#include <hal.h> |
|
23 |
||
24 |
#include "t_usb.h" // CActiveConsole, CActiveRW |
|
25 |
#include "t_usblib.h" // Helpers |
|
26 |
||
27 |
||
28 |
_LIT(KUsbLddFilename, "eusbc"); // .ldd assumed - it's a filename |
|
29 |
_LIT(KOtgdiLddFilename, "otgdi"); |
|
30 |
_LIT(KUsbDeviceName, "Usbc"); |
|
31 |
_LIT(KFileName, "\\T_USBFILE.BIN"); |
|
32 |
_LIT(KActivePanic, "T_USB"); |
|
33 |
||
19
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
34 |
static const TUint32 KTusbVersion = 20091224; // just an edit date really |
0 | 35 |
static const TUint8 KUsbrflctVersionMajor = 1; // the version we're compatible with |
36 |
static const TUint8 KUsbrflctVersionMinor = 5; |
|
37 |
static const TUint8 KUsbrflctVersionMicro = 0; |
|
38 |
||
39 |
static const TInt KMaxFileSize = 100 * 1024 * 1024; // 100MB (requires at least 128MB card) |
|
40 |
static const TInt KInitialBufSz = 0; |
|
41 |
static const TInt stridx1 = 0xCC; |
|
42 |
static const TInt stridx2 = 0xEE; |
|
43 |
||
44 |
// |
|
45 |
// --- class CActiveConsole --------------------------------------------------------- |
|
46 |
// |
|
47 |
||
48 |
CActiveConsole::CActiveConsole(CConsoleBase* aConsole, TBool aVerboseOutput) |
|
49 |
: CActive(EPriorityNormal), |
|
50 |
iConsole(aConsole), |
|
51 |
iRW(NULL), |
|
52 |
iBufferSizeChosen(EFalse), |
|
53 |
iBandwidthPriorityChosen(EFalse), |
|
54 |
iDMAChosen(EFalse), |
|
19
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
55 |
iAllocateDma(EFalse), |
0 | 56 |
iDoubleBufferingChosen(EFalse), |
19
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
57 |
iAllocateDoubleBuffering(EFalse), |
0 | 58 |
iSoftwareConnect(EFalse), |
59 |
iHighSpeed(EFalse), |
|
19
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
60 |
iResourceAllocationV2(EFalse), |
0 | 61 |
iOtg(EFalse), |
62 |
iVerbose(aVerboseOutput) |
|
63 |
{} |
|
64 |
||
65 |
||
66 |
CActiveConsole* CActiveConsole::NewLC(CConsoleBase* aConsole, TBool aVerboseOutput) |
|
67 |
{ |
|
68 |
CActiveConsole* self = new (ELeave) CActiveConsole(aConsole, aVerboseOutput); |
|
69 |
CleanupStack::PushL(self); |
|
70 |
self->ConstructL(); |
|
71 |
return self; |
|
72 |
} |
|
73 |
||
74 |
||
75 |
CActiveConsole* CActiveConsole::NewL(CConsoleBase* aConsole, TBool aVerboseOutput) |
|
76 |
{ |
|
77 |
CActiveConsole* self = NewLC(aConsole, aVerboseOutput); |
|
78 |
CleanupStack::Pop(); |
|
79 |
return self; |
|
80 |
} |
|
81 |
||
82 |
||
83 |
void CActiveConsole::ConstructL() |
|
84 |
{ |
|
85 |
CActiveScheduler::Add(this); |
|
86 |
||
87 |
// Load logical driver (LDD) |
|
88 |
// (There's no physical driver (PDD) with USB: it's a kernel extension DLL which |
|
89 |
// was already loaded at boot time.) |
|
90 |
TInt r = User::LoadLogicalDevice(KUsbLddFilename); |
|
91 |
if (r != KErrNone && r != KErrAlreadyExists) |
|
92 |
{ |
|
93 |
TUSB_PRINT1("Error %d on loading USB LDD", r); |
|
94 |
User::Leave(-1); |
|
95 |
return; |
|
96 |
} |
|
97 |
TUSB_PRINT("Successfully loaded USB LDD"); |
|
98 |
||
99 |
// Open USB channel |
|
100 |
r = iPort.Open(0); |
|
101 |
if (r != KErrNone) |
|
102 |
{ |
|
103 |
TUSB_PRINT1("Error %d on opening USB port", r); |
|
104 |
User::Leave(-1); |
|
105 |
return; |
|
106 |
} |
|
107 |
TUSB_PRINT("Successfully opened USB port"); |
|
108 |
||
109 |
// Create Reader/Writer active object |
|
110 |
iRW = CActiveRW::NewL(iConsole, &iPort, iVerbose); |
|
111 |
if (!iRW) |
|
112 |
{ |
|
113 |
TUSB_PRINT("Failed to create reader/writer"); |
|
114 |
User::Leave(-1); |
|
115 |
return; |
|
116 |
} |
|
117 |
TUSB_PRINT("Created reader/writer"); |
|
19
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
118 |
|
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
119 |
// check for endpoint resource allocation v2 support |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
120 |
TUsbDeviceCaps d_caps; |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
121 |
r = iPort.DeviceCaps(d_caps); |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
122 |
if (r != KErrNone) |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
123 |
{ |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
124 |
TUSB_PRINT1("Error %d on querying device capabilities", r); |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
125 |
User::Leave(-1); |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
126 |
return; |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
127 |
} |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
128 |
iResourceAllocationV2 = ((d_caps().iFeatureWord1 & KUsbDevCapsFeatureWord1_EndpointResourceAllocV2) != 0); |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
129 |
|
0 | 130 |
// Check for OTG support |
131 |
TBuf8<KUsbDescSize_Otg> otg_desc; |
|
132 |
r = iPort.GetOtgDescriptor(otg_desc); |
|
133 |
if (!(r == KErrNotSupported || r == KErrNone)) |
|
134 |
{ |
|
135 |
TUSB_PRINT1("Error %d while fetching OTG descriptor", r); |
|
136 |
User::Leave(-1); |
|
137 |
return; |
|
138 |
} |
|
139 |
iOtg = (r != KErrNotSupported) ? ETrue : EFalse; |
|
140 |
||
141 |
// On an OTG device we have to start the OTG driver, otherwise the Client |
|
142 |
// stack will remain disabled forever. |
|
143 |
if (iOtg) |
|
144 |
{ |
|
145 |
TUSB_PRINT("Running on OTG device: loading OTG driver"); |
|
146 |
r = User::LoadLogicalDevice(KOtgdiLddFilename); |
|
147 |
if (r != KErrNone) |
|
148 |
{ |
|
149 |
TUSB_PRINT1("Error %d on loading OTG LDD", r); |
|
150 |
User::Leave(-1); |
|
151 |
return; |
|
152 |
} |
|
153 |
r = iOtgPort.Open(); |
|
154 |
if (r != KErrNone) |
|
155 |
{ |
|
156 |
TUSB_PRINT1("Error %d on opening OTG port", r); |
|
157 |
User::Leave(-1); |
|
158 |
return; |
|
159 |
} |
|
160 |
r = iOtgPort.StartStacks(); |
|
161 |
if (r != KErrNone) |
|
162 |
{ |
|
163 |
TUSB_PRINT1("Error %d on starting USB stack", r); |
|
164 |
User::Leave(-1); |
|
165 |
return; |
|
166 |
} |
|
167 |
} |
|
168 |
} |
|
169 |
||
170 |
||
171 |
TInt CActiveConsole::SetupInterface() |
|
172 |
{ |
|
173 |
// Query the USB device/Setup the USB interface |
|
174 |
TInt r = QueryUsbClientL(); |
|
175 |
if (r != KErrNone) |
|
176 |
{ |
|
177 |
TUSB_PRINT1("Interface setup failed", r); |
|
178 |
return r; |
|
179 |
} |
|
180 |
TUSB_PRINT("Interface successfully set up"); |
|
181 |
||
182 |
// Change some descriptors to contain suitable values |
|
183 |
r = SetupDescriptors(); |
|
184 |
if (r != KErrNone) |
|
185 |
{ |
|
186 |
TUSB_PRINT1("Descriptor setup failed", r); |
|
187 |
return r; |
|
188 |
} |
|
189 |
||
190 |
// Create device state active object |
|
191 |
iDeviceStateNotifier = CActiveDeviceStateNotifier::NewL(iConsole, &iPort, iVerbose); |
|
192 |
if (!iDeviceStateNotifier) |
|
193 |
{ |
|
194 |
TUSB_PRINT("Failed to create device state notifier"); |
|
195 |
return r; |
|
196 |
} |
|
197 |
iDeviceStateNotifier->Activate(); |
|
198 |
||
199 |
// Create endpoint stall status active object |
|
200 |
iStallNotifier = CActiveStallNotifier::NewL(iConsole, &iPort, iVerbose); |
|
201 |
if (!iStallNotifier) |
|
202 |
{ |
|
203 |
TUSB_PRINT("Failed to create stall notifier"); |
|
204 |
return r; |
|
205 |
} |
|
206 |
iStallNotifier->Activate(); |
|
207 |
||
208 |
return r; |
|
209 |
} |
|
210 |
||
211 |
||
212 |
CActiveConsole::~CActiveConsole() |
|
213 |
{ |
|
214 |
TUSB_VERBOSE_PRINT("CActiveConsole::~CActiveConsole()"); |
|
215 |
Cancel(); // base class cancel -> calls our DoCancel |
|
216 |
delete iRW; // destroy the reader/writer |
|
217 |
delete iDeviceStateNotifier; |
|
218 |
delete iStallNotifier; |
|
219 |
TInt r = iPort.RemoveStringDescriptor(stridx1); |
|
220 |
if (r != KErrNone) |
|
221 |
{ |
|
222 |
TUSB_PRINT1("Error %d on string removal", r); |
|
223 |
} |
|
224 |
r = iPort.RemoveStringDescriptor(stridx2); |
|
225 |
if (r != KErrNone) |
|
226 |
{ |
|
227 |
TUSB_PRINT1("Error %d on string removal", r); |
|
228 |
} |
|
229 |
if (iOtg) |
|
230 |
{ |
|
231 |
TUSB_PRINT("Running on OTG device: unloading OTG driver"); |
|
232 |
iOtgPort.StopStacks(); |
|
233 |
iOtgPort.Close(); |
|
234 |
r = User::FreeLogicalDevice(RUsbOtgDriver::Name()); |
|
235 |
if (r != KErrNone) |
|
236 |
{ |
|
237 |
TUSB_PRINT1("Error %d on freeing OTG LDD", r); |
|
238 |
} |
|
239 |
} |
|
240 |
iPort.Close(); // close USB channel |
|
241 |
r = User::FreeLogicalDevice(KUsbDeviceName); |
|
242 |
if (r != KErrNone) |
|
243 |
{ |
|
244 |
TUSB_PRINT1("Error %d during unloading USB LDD", r); |
|
245 |
User::Leave(-1); |
|
246 |
return; |
|
247 |
} |
|
248 |
TUSB_PRINT("Successfully unloaded USB LDD"); |
|
249 |
} |
|
250 |
||
251 |
||
252 |
void CActiveConsole::DoCancel() |
|
253 |
{ |
|
254 |
TUSB_VERBOSE_PRINT("CActiveConsole::DoCancel()"); |
|
255 |
iConsole->ReadCancel(); |
|
256 |
} |
|
257 |
||
258 |
||
259 |
void CActiveConsole::RunL() |
|
260 |
{ |
|
261 |
TUSB_VERBOSE_PRINT("CActiveConsole::RunL()"); |
|
262 |
ProcessKeyPressL(static_cast<TChar>(iConsole->KeyCode())); |
|
263 |
} |
|
264 |
||
265 |
||
266 |
void CActiveConsole::RequestCharacter() |
|
267 |
{ |
|
268 |
// A request is issued to the CConsoleBase to accept a character from the keyboard. |
|
269 |
__ASSERT_ALWAYS(!IsActive(), User::Panic(KActivePanic, 666)); |
|
270 |
if (!iBufferSizeChosen) |
|
271 |
{ |
|
272 |
iConsole->Printf(_L("\n")); |
|
273 |
iConsole->Printf(_L("++++ Choose max. Transfer Size ++++\n")); |
|
274 |
iConsole->Printf(_L(" '0' - Set up USB device for USBCV\n")); |
|
275 |
iConsole->Printf(_L(" '1' - 32 bytes\n")); |
|
276 |
iConsole->Printf(_L(" '2' - 1024 bytes\n")); |
|
277 |
iConsole->Printf(_L(" '3' - 64 kbytes\n")); |
|
278 |
iConsole->Printf(_L(" '4' - 1 Mbyte\n")); |
|
279 |
} |
|
280 |
else if (!iBandwidthPriorityChosen) |
|
281 |
{ |
|
282 |
iConsole->Printf(_L("\n")); |
|
283 |
iConsole->Printf(_L("++++ Choose Bandwidth Priority ++++\n")); |
|
284 |
iConsole->Printf(_L(" '1' - Economical buffering - default\n")); |
|
285 |
iConsole->Printf(_L(" '2' - More memory than default buffering - Plus1\n")); |
|
286 |
iConsole->Printf(_L(" '3' - More memory than Plus1 buffering - Plus2\n")); |
|
287 |
iConsole->Printf(_L(" '4' - Maximum buffering\n")); |
|
288 |
} |
|
289 |
else if (!iDMAChosen) |
|
290 |
{ |
|
291 |
iConsole->Printf(_L("\n")); |
|
292 |
iConsole->Printf(_L("++++ Choose Endpoint I/O Transfer Mode ++++\n")); |
|
293 |
iConsole->Printf(_L(" '1' - Interrupt Mode\n")); |
|
294 |
iConsole->Printf(_L(" '2' - DMA Mode (recommended)\n")); |
|
295 |
} |
|
296 |
else if (!iDoubleBufferingChosen) |
|
297 |
{ |
|
298 |
iConsole->Printf(_L("\n")); |
|
299 |
iConsole->Printf(_L("++++ Choose Endpoint FIFO Mode ++++\n")); |
|
300 |
iConsole->Printf(_L(" '1' - Normal Buffering Mode\n")); |
|
301 |
iConsole->Printf(_L(" '2' - Double Buffering Mode (recommended)\n")); |
|
302 |
} |
|
303 |
else |
|
304 |
{ |
|
305 |
iConsole->Printf(_L("\n")); |
|
306 |
iConsole->Printf(_L("++++ Select Program Option ++++\n")); |
|
307 |
iConsole->Printf(_L(" 'L'oop test\n")); |
|
308 |
iConsole->Printf(_L(" Loop test with data 'C'ompare\n")); |
|
309 |
iConsole->Printf(_L(" 'R'eceive-only test (we receive, host transmits)\n")); |
|
310 |
iConsole->Printf(_L(" 'T'ransmit-only test\n")); |
|
311 |
iConsole->Printf(_L(" Receive and 'P'ut (write) to File\n")); |
|
312 |
iConsole->Printf(_L(" Transmit and 'G'et (read) from File\n")); |
|
313 |
iConsole->Printf(_L(" Signal Remote-'W'akeup to the host\n")); |
|
314 |
iConsole->Printf(_L(" 'S'top current transfer\n")); |
|
315 |
#ifdef WITH_DUMP_OPTION |
|
316 |
iConsole->Printf(_L(" 'D'ump USB regs to debugout\n")); |
|
317 |
#endif |
|
318 |
iConsole->Printf(_L(" Re'E'numerate device\n")); |
|
319 |
iConsole->Printf(_L(" 'Q'uit this app\n")); |
|
320 |
} |
|
321 |
iConsole->Read(iStatus); |
|
322 |
SetActive(); |
|
323 |
} |
|
324 |
||
325 |
||
326 |
void CActiveConsole::ProcessKeyPressL(TChar aChar) |
|
327 |
{ |
|
328 |
if (aChar == EKeyEscape) |
|
329 |
{ |
|
330 |
RDebug::Print(_L("CActiveConsole: ESC key pressed -> stopping active scheduler...")); |
|
331 |
CActiveScheduler::Stop(); |
|
332 |
return; |
|
333 |
} |
|
334 |
if (!iBufferSizeChosen) |
|
335 |
{ |
|
336 |
// Set maximum buffer size from keypress |
|
337 |
switch (aChar) |
|
338 |
{ |
|
339 |
case '0': |
|
340 |
// This is for creating a USB device that just enumerates, |
|
341 |
// to be used for compliance testing with USBCV. |
|
342 |
iRW->SetMaxBufSize(0); |
|
343 |
break; |
|
344 |
case '1': |
|
345 |
iRW->SetMaxBufSize(32); |
|
346 |
break; |
|
347 |
case '2': |
|
348 |
iRW->SetMaxBufSize(1024); |
|
349 |
break; |
|
350 |
case '3': |
|
351 |
iRW->SetMaxBufSize(64 * 1024); |
|
352 |
break; |
|
353 |
case '4': |
|
354 |
iRW->SetMaxBufSize(KMaxBufSize); |
|
355 |
break; |
|
356 |
default: |
|
357 |
TUSB_PRINT1("Not a valid input character: %c", aChar.operator TUint()); |
|
358 |
goto request_char; |
|
359 |
} |
|
360 |
TUSB_PRINT1("Maximum buffer size set to %d bytes", iRW->MaxBufSize()); |
|
361 |
iBufferSizeChosen = ETrue; |
|
362 |
} |
|
363 |
else if (!iBandwidthPriorityChosen) |
|
364 |
{ |
|
365 |
// Set bandwidth priority from keypress |
|
366 |
switch (aChar) |
|
367 |
{ |
|
368 |
case '1': |
|
369 |
iBandwidthPriority = EUsbcBandwidthOUTDefault | EUsbcBandwidthINDefault; |
|
370 |
TUSB_PRINT("Bandwith priority set to default"); |
|
371 |
break; |
|
372 |
case '2': |
|
373 |
iBandwidthPriority = EUsbcBandwidthOUTPlus1 | EUsbcBandwidthINPlus1; |
|
374 |
TUSB_PRINT("Bandwith priority set to Plus1"); |
|
375 |
break; |
|
376 |
case '3': |
|
377 |
iBandwidthPriority = EUsbcBandwidthOUTPlus2 | EUsbcBandwidthINPlus2; |
|
378 |
TUSB_PRINT("Bandwith priority set to Plus2"); |
|
379 |
break; |
|
380 |
case '4': |
|
381 |
iBandwidthPriority = EUsbcBandwidthINMaximum | EUsbcBandwidthOUTMaximum; |
|
382 |
TUSB_PRINT("Bandwith priority set to maximum"); |
|
383 |
break; |
|
384 |
default: |
|
385 |
TUSB_PRINT1("Not a valid input character: %c", aChar.operator TUint()); |
|
386 |
goto request_char; |
|
387 |
} |
|
388 |
TUSB_PRINT1("(Set to 0x%08X)", iBandwidthPriority); |
|
389 |
iBandwidthPriorityChosen = ETrue; |
|
19
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
390 |
|
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
391 |
if (!iResourceAllocationV2) |
0 | 392 |
{ |
19
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
393 |
TUSB_PRINT("Configuring interface..."); |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
394 |
TInt r = SetupInterface(); |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
395 |
if (r != KErrNone) |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
396 |
{ |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
397 |
TUSB_PRINT1("Error: %d. Stopping active scheduler...", r); |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
398 |
CActiveScheduler::Stop(); |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
399 |
return; |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
400 |
} |
0 | 401 |
} |
402 |
} |
|
403 |
else if (!iDMAChosen) |
|
404 |
{ |
|
405 |
// Set DMA mode from keypress |
|
406 |
switch (aChar) |
|
407 |
{ |
|
408 |
case '1': |
|
19
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
409 |
{ |
0 | 410 |
TUSB_PRINT("- Trying to deallocate endpoint DMA:\n"); |
19
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
411 |
if (!iResourceAllocationV2) |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
412 |
{ |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
413 |
DeAllocateEndpointDMA(EEndpoint1); |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
414 |
DeAllocateEndpointDMA(EEndpoint2); |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
415 |
} |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
416 |
iAllocateDma = EFalse; |
0 | 417 |
break; |
19
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
418 |
} |
0 | 419 |
case '2': |
19
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
420 |
{ |
0 | 421 |
TUSB_PRINT("- Trying to allocate endpoint DMA:\n"); |
19
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
422 |
if (!iResourceAllocationV2) |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
423 |
{ |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
424 |
AllocateEndpointDMA(EEndpoint1); |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
425 |
AllocateEndpointDMA(EEndpoint2); |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
426 |
} |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
427 |
iAllocateDma = ETrue; |
0 | 428 |
break; |
19
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
429 |
} |
0 | 430 |
default: |
431 |
TUSB_PRINT1("Not a valid input character: %c", aChar.operator TUint()); |
|
432 |
goto request_char; |
|
433 |
} |
|
434 |
iDMAChosen = ETrue; |
|
435 |
} |
|
436 |
else if (!iDoubleBufferingChosen) |
|
437 |
{ |
|
438 |
// Set Double Buffering from keypress |
|
439 |
switch (aChar) |
|
440 |
{ |
|
441 |
case '1': |
|
19
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
442 |
{ |
0 | 443 |
TUSB_PRINT("- Trying to deallocate Double Buffering:\n"); |
19
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
444 |
if (!iResourceAllocationV2) |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
445 |
{ |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
446 |
DeAllocateDoubleBuffering(EEndpoint1); |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
447 |
DeAllocateDoubleBuffering(EEndpoint2); |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
448 |
} |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
449 |
iAllocateDoubleBuffering = EFalse; |
0 | 450 |
break; |
19
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
451 |
} |
0 | 452 |
case '2': |
19
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
453 |
{ |
0 | 454 |
TUSB_PRINT("- Trying to allocate Double Buffering:\n"); |
19
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
455 |
if (!iResourceAllocationV2) |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
456 |
{ |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
457 |
AllocateDoubleBuffering(EEndpoint1); |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
458 |
AllocateDoubleBuffering(EEndpoint2); |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
459 |
} |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
460 |
iAllocateDoubleBuffering = ETrue; |
0 | 461 |
break; |
19
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
462 |
} |
0 | 463 |
default: |
464 |
TUSB_PRINT1("Not a valid input character: %c", aChar.operator TUint()); |
|
465 |
goto request_char; |
|
466 |
} |
|
467 |
iDoubleBufferingChosen = ETrue; |
|
19
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
468 |
|
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
469 |
if (iResourceAllocationV2) |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
470 |
{ |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
471 |
TUSB_PRINT("Configuring interface..."); |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
472 |
TInt r = SetupInterface(); |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
473 |
if (r != KErrNone) |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
474 |
{ |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
475 |
TUSB_PRINT1("Error: %d. Stopping active scheduler...", r); |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
476 |
CActiveScheduler::Stop(); |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
477 |
return; |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
478 |
} |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
479 |
} |
0 | 480 |
|
481 |
// Everything chosen, so let's re-enumerate... |
|
482 |
TUSB_PRINT("Enumeration..."); |
|
483 |
TInt r = ReEnumerate(); |
|
484 |
if (r != KErrNone) |
|
485 |
{ |
|
486 |
TUSB_PRINT1("Error: %d. Stopping active scheduler...", r); |
|
487 |
CActiveScheduler::Stop(); |
|
488 |
return; |
|
489 |
} |
|
490 |
TUSB_PRINT("Device successfully re-enumerated\n"); |
|
491 |
||
492 |
// Make sure program versions match if testing against USBRFLCT |
|
493 |
if (iRW->MaxBufSize() != 0) |
|
494 |
{ |
|
495 |
r = iRW->ExchangeVersions(); |
|
496 |
if (r != KErrNone) |
|
497 |
{ |
|
498 |
TUSB_PRINT1("Error: %d. Stopping active scheduler...", r); |
|
499 |
CActiveScheduler::Stop(); |
|
500 |
return; |
|
501 |
} |
|
502 |
} |
|
503 |
} |
|
504 |
else |
|
505 |
{ |
|
506 |
// Execute one of the 'proper' program functions |
|
507 |
switch (aChar) |
|
508 |
{ |
|
509 |
case 'l': // start loop test |
|
510 |
case 'L': |
|
511 |
TUSB_PRINT("-> Loop test selected\n"); |
|
512 |
iRW->SetTransferMode(ELoop); |
|
513 |
iRW->SendPreamble(); |
|
514 |
break; |
|
515 |
case 'c': // start loop/compare test |
|
516 |
case 'C': |
|
517 |
TUSB_PRINT("-> Loop test with compare selected\n"); |
|
518 |
iRW->SetTransferMode(ELoopComp); |
|
519 |
iRW->SendPreamble(); |
|
520 |
break; |
|
521 |
case 'r': // start receive-only test |
|
522 |
case 'R': |
|
523 |
TUSB_PRINT("-> Receive-only test selected\n"); |
|
524 |
iRW->SetTransferMode(EReceiveOnly); |
|
525 |
iRW->SendPreamble(); |
|
526 |
break; |
|
527 |
case 't': // start transmit-only test |
|
528 |
case 'T': |
|
529 |
TUSB_PRINT("-> Transmit-only test selected\n"); |
|
530 |
iRW->SetTransferMode(ETransmitOnly); |
|
531 |
iRW->SendPreamble(); |
|
532 |
break; |
|
533 |
case 'g': // start transmit & get-from-file test |
|
534 |
case 'G': |
|
535 |
TUSB_PRINT("-> Transmit from file test selected\n"); |
|
536 |
iRW->SetTransferMode(ETransmitOnly); |
|
537 |
iRW->ReadFromDisk(ETrue); |
|
538 |
iRW->SendPreamble(); |
|
539 |
break; |
|
540 |
case 'p': // start receive & put-to-file test |
|
541 |
case 'P': |
|
542 |
TUSB_PRINT("-> Receive to file test selected\n"); |
|
543 |
iRW->SetTransferMode(EReceiveOnly); |
|
544 |
iRW->WriteToDisk(ETrue); |
|
545 |
iRW->SendPreamble(); |
|
546 |
break; |
|
547 |
case 'w': // remote-wakeup |
|
548 |
case 'W': |
|
549 |
TUSB_PRINT("-> Signal Remote-wakeup selected\n"); |
|
550 |
iPort.SignalRemoteWakeup(); |
|
551 |
break; |
|
552 |
case 's': // stop either |
|
553 |
case 'S': |
|
554 |
TUSB_PRINT("-> Stop transfer selected\n"); |
|
555 |
iRW->Stop(); |
|
556 |
break; |
|
557 |
#ifdef WITH_DUMP_OPTION |
|
558 |
case 'd': // dump controller registers |
|
559 |
case 'D': |
|
560 |
TUSB_PRINT("-> Dump option selected\n"); |
|
561 |
iPort.DumpRegisters(); |
|
562 |
QueryRxBuffer(); |
|
563 |
break; |
|
564 |
#endif |
|
565 |
case 'e': // ReEnumerate() |
|
566 |
case 'E': |
|
567 |
TUSB_PRINT("-> Re-enumerate device selected\n"); |
|
568 |
ReEnumerate(); |
|
569 |
break; |
|
570 |
case 'q': // quit |
|
571 |
case 'Q': |
|
572 |
TUSB_PRINT("-> Quit program selected\n"); |
|
573 |
TUSB_VERBOSE_PRINT("CActiveConsole: stopping active scheduler..."); |
|
574 |
CActiveScheduler::Stop(); |
|
575 |
return; |
|
576 |
default: |
|
577 |
TUSB_PRINT1("-> Not a valid input character: %c", aChar.operator TUint()); |
|
578 |
goto request_char; |
|
579 |
} |
|
580 |
} |
|
581 |
request_char: |
|
582 |
RequestCharacter(); |
|
583 |
return; |
|
584 |
} |
|
585 |
||
586 |
||
587 |
#ifdef WITH_DUMP_OPTION |
|
588 |
void CActiveConsole::QueryRxBuffer() |
|
589 |
{ |
|
590 |
// Let's look whether there's data in the rx buffer |
|
591 |
TInt bytes = 0; |
|
592 |
TInt r = iPort.QueryReceiveBuffer(EEndpoint2, bytes); |
|
593 |
if (r != KErrNone) |
|
594 |
{ |
|
595 |
RDebug::Print(_L(" Error %d on querying read buffer\n"), r); |
|
596 |
} |
|
597 |
else |
|
598 |
{ |
|
599 |
RDebug::Print(_L(" %d bytes in RX buffer\n"), bytes); |
|
600 |
} |
|
601 |
} |
|
602 |
#endif |
|
603 |
||
604 |
||
605 |
TInt CActiveConsole::QueryUsbClientL() |
|
606 |
{ |
|
607 |
// Not really just querying... but rather setting up the whole interface. |
|
608 |
// It's in fact a bit lengthy, but all these steps are required, once, |
|
609 |
// and in that order. |
|
610 |
||
611 |
// Get device/endpoint capabilities |
|
612 |
// |
|
613 |
// A TPckg, or TPckBuf was not used in the following, because |
|
614 |
// |
|
615 |
// TPckgBuf<TUsbcEndpointData[KUsbcMaxEndpoints]> databuf; |
|
616 |
// |
|
617 |
// doesn't work. Also, |
|
618 |
// |
|
619 |
// TUsbcEndpointData data[KUsbcMaxEndpoints]; |
|
620 |
// TPckgBuf<TUsbcEndpointData[KUsbcMaxEndpoints]> databuf(data); |
|
621 |
// |
|
622 |
// doesn't work. Also, |
|
623 |
// |
|
624 |
// TUsbcEndpointData data[KUsbcMaxEndpoints]; |
|
625 |
// TPckgBuf<TUsbcEndpointData[]> databuf(data); |
|
626 |
// |
|
627 |
// doesn't work. |
|
628 |
// So we seem to have to stick to the ugly cast below. |
|
629 |
// |
|
630 |
// TUsbcEndpointData data[KUsbcMaxEndpoints]; |
|
631 |
// TPtr8 databuf(reinterpret_cast<TUint8*>(data), sizeof(data), sizeof(data)); |
|
632 |
// |
|
633 |
||
634 |
// Device |
|
635 |
TUsbDeviceCaps d_caps; |
|
636 |
TInt r = iPort.DeviceCaps(d_caps); |
|
637 |
if (r != KErrNone) |
|
638 |
{ |
|
639 |
TUSB_PRINT1("Error %d on querying device capabilities", r); |
|
640 |
return KErrGeneral; |
|
641 |
} |
|
642 |
const TInt n = d_caps().iTotalEndpoints; |
|
643 |
||
644 |
TUSB_PRINT("### USB device capabilities:"); |
|
645 |
TUSB_PRINT1("Number of endpoints: %d", n); |
|
646 |
TUSB_PRINT1("Supports Software-Connect: %s", |
|
647 |
d_caps().iConnect ? _S("yes") : _S("no")); |
|
648 |
TUSB_PRINT1("Device is Self-Powered: %s", |
|
649 |
d_caps().iSelfPowered ? _S("yes") : _S("no")); |
|
650 |
TUSB_PRINT1("Supports Remote-Wakeup: %s", |
|
651 |
d_caps().iRemoteWakeup ? _S("yes") : _S("no")); |
|
652 |
TUSB_PRINT1("Supports High-speed: %s", |
|
653 |
d_caps().iHighSpeed ? _S("yes") : _S("no")); |
|
654 |
TUSB_PRINT1("Supports OTG: %s", |
|
655 |
iOtg ? _S("yes") : _S("no")); |
|
656 |
TUSB_PRINT1("Supports unpowered cable detection: %s", |
|
657 |
(d_caps().iFeatureWord1 & KUsbDevCapsFeatureWord1_CableDetectWithoutPower) ? |
|
658 |
_S("yes") : _S("no")); |
|
659 |
TUSB_PRINT1("Supports endpoint resource alloc scheme V2: %s\n", |
|
660 |
(d_caps().iFeatureWord1 & KUsbDevCapsFeatureWord1_EndpointResourceAllocV2) ? |
|
661 |
_S("yes") : _S("no")); |
|
662 |
TUSB_PRINT(""); |
|
663 |
||
664 |
iSoftwareConnect = d_caps().iConnect; // we need to remember this |
|
665 |
||
666 |
if (n < 2) |
|
667 |
{ |
|
668 |
TUSB_PRINT1("Error: only %d endpoints available on device", n); |
|
669 |
return KErrGeneral; |
|
670 |
} |
|
671 |
||
672 |
// Endpoints |
|
673 |
TUsbcEndpointData data[KUsbcMaxEndpoints]; |
|
674 |
TPtr8 dataptr(reinterpret_cast<TUint8*>(data), sizeof(data), sizeof(data)); |
|
675 |
r = iPort.EndpointCaps(dataptr); |
|
676 |
if (r != KErrNone) |
|
677 |
{ |
|
678 |
TUSB_PRINT1("Error %d on querying endpoint capabilities", r); |
|
679 |
return KErrGeneral; |
|
680 |
} |
|
681 |
TUSB_PRINT("### USB device endpoint capabilities:"); |
|
682 |
for (TInt i = 0; i < n; i++) |
|
683 |
{ |
|
684 |
const TUsbcEndpointCaps* caps = &data[i].iCaps; |
|
685 |
TUSB_PRINT2("Endpoint: SizeMask = 0x%08x TypeDirMask = 0x%08x", |
|
686 |
caps->iSizes, caps->iTypesAndDir); |
|
687 |
} |
|
688 |
TUSB_PRINT(""); |
|
689 |
||
690 |
// Set up the active interface |
|
691 |
TUsbcInterfaceInfoBuf ifc; |
|
692 |
TInt ep_found = 0; |
|
693 |
TBool foundBulkIN = EFalse; |
|
694 |
TBool foundBulkOUT = EFalse; |
|
695 |
for (TInt i = 0; i < n; i++) |
|
696 |
{ |
|
697 |
const TUsbcEndpointCaps* const caps = &data[i].iCaps; |
|
698 |
const TInt mps = caps->MaxPacketSize(); |
|
699 |
if (!foundBulkIN && |
|
700 |
(caps->iTypesAndDir & (KUsbEpTypeBulk | KUsbEpDirIn)) == |
|
701 |
(KUsbEpTypeBulk | KUsbEpDirIn)) |
|
702 |
{ |
|
703 |
if (!(mps == 64 || mps == 512)) |
|
704 |
{ |
|
705 |
TUSB_PRINT1("Funny Bulk IN MaxPacketSize: %d - T_USB will probably fail...", mps); |
|
706 |
} |
|
707 |
// EEndpoint1 is going to be our Tx (IN) endpoint |
|
708 |
ifc().iEndpointData[0].iType = KUsbEpTypeBulk; |
|
709 |
ifc().iEndpointData[0].iDir = KUsbEpDirIn; |
|
710 |
ifc().iEndpointData[0].iSize = mps; |
|
711 |
foundBulkIN = ETrue; |
|
712 |
if (++ep_found == 2) |
|
713 |
break; |
|
714 |
} |
|
715 |
else if (!foundBulkOUT && |
|
716 |
(caps->iTypesAndDir & (KUsbEpTypeBulk | KUsbEpDirOut)) == |
|
717 |
(KUsbEpTypeBulk | KUsbEpDirOut)) |
|
718 |
{ |
|
719 |
if (!(mps == 64 || mps == 512)) |
|
720 |
{ |
|
721 |
TUSB_PRINT1("Funny Bulk OUT MaxPacketSize: %d - T_USB will probably fail...", mps); |
|
722 |
} |
|
723 |
// EEndpoint2 is going to be our Rx (OUT) endpoint |
|
724 |
ifc().iEndpointData[1].iType = KUsbEpTypeBulk; |
|
725 |
ifc().iEndpointData[1].iDir = KUsbEpDirOut; |
|
726 |
ifc().iEndpointData[1].iSize = mps; |
|
727 |
foundBulkOUT = ETrue; |
|
728 |
if (++ep_found == 2) |
|
729 |
break; |
|
730 |
} |
|
731 |
} |
|
732 |
if (ep_found != 2) |
|
733 |
{ |
|
734 |
TUSB_PRINT1("No suitable endpoints found", r); |
|
735 |
return KErrGeneral; |
|
736 |
} |
|
737 |
||
19
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
738 |
if (iResourceAllocationV2) |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
739 |
{ |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
740 |
if (iAllocateDma) |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
741 |
{ |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
742 |
ifc().iEndpointData[0].iFeatureWord1 |= KUsbcEndpointInfoFeatureWord1_DMA; |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
743 |
ifc().iEndpointData[1].iFeatureWord1 |= KUsbcEndpointInfoFeatureWord1_DMA; |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
744 |
} |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
745 |
if (iAllocateDoubleBuffering) |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
746 |
{ |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
747 |
ifc().iEndpointData[0].iFeatureWord1 |= KUsbcEndpointInfoFeatureWord1_DoubleBuffering; |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
748 |
ifc().iEndpointData[1].iFeatureWord1 |= KUsbcEndpointInfoFeatureWord1_DoubleBuffering; |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
749 |
} |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
750 |
} |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
751 |
|
0 | 752 |
_LIT16(ifcname, "T_USB Test Interface (Default Setting 0)"); |
753 |
ifc().iString = const_cast<TDesC16*>(&ifcname); |
|
754 |
ifc().iTotalEndpointsUsed = 2; |
|
755 |
ifc().iClass.iClassNum = 0xff; // vendor-specific |
|
756 |
ifc().iClass.iSubClassNum = 0xff; // vendor-specific |
|
757 |
ifc().iClass.iProtocolNum = 0xff; // vendor-specific |
|
758 |
r = iPort.SetInterface(0, ifc, iBandwidthPriority); |
|
759 |
if (r != KErrNone) |
|
760 |
{ |
|
761 |
TUSB_PRINT1("Error %d on setting active interface", r); |
|
762 |
} |
|
763 |
||
764 |
// Find ep's for an alternate ifc setting. |
|
765 |
// We're not really going to use it, but it gives USBCV et al. more stuff to play with. |
|
766 |
if (!SupportsAlternateInterfaces()) |
|
767 |
{ |
|
768 |
TUSB_PRINT("Alternate Interfaces not supported - skipping alternate setting setup\n"); |
|
769 |
return KErrNone; |
|
770 |
} |
|
771 |
ep_found = 0; |
|
772 |
TBool foundIsoIN = EFalse; |
|
773 |
TBool foundIsoOUT = EFalse; |
|
774 |
||
775 |
// NB! We cannot assume that any specific device has any given set of |
|
776 |
// capabilities, so whilst we try and set an assortment of endpoint types |
|
777 |
// we may not get what we want. |
|
778 |
||
779 |
// Also, note that the endpoint[] array in the interface descriptor |
|
780 |
// must be filled from ep[0]...ep[n-1]. |
|
781 |
||
782 |
for (TInt i = 0; i < n; i++) |
|
783 |
{ |
|
784 |
const TUsbcEndpointCaps* const caps = &data[i].iCaps; |
|
785 |
const TInt mps = caps->MaxPacketSize(); |
|
786 |
if (!foundIsoIN && |
|
787 |
(caps->iTypesAndDir & (KUsbEpTypeIsochronous | KUsbEpDirIn)) == |
|
788 |
(KUsbEpTypeIsochronous | KUsbEpDirIn)) |
|
789 |
{ |
|
790 |
// This is going to be our Iso TX (IN) endpoint |
|
791 |
ifc().iEndpointData[ep_found].iType = KUsbEpTypeIsochronous; |
|
792 |
ifc().iEndpointData[ep_found].iDir = KUsbEpDirIn; |
|
793 |
ifc().iEndpointData[ep_found].iSize = mps; |
|
794 |
ifc().iEndpointData[ep_found].iInterval = 0x01; // 2^(bInterval-1)ms, bInterval must be [1..16] |
|
795 |
ifc().iEndpointData[ep_found].iInterval_Hs = 0x01; // same as for FS |
|
796 |
ifc().iEndpointData[ep_found].iExtra = 2; // 2 extra bytes for Audio Class EP descriptor |
|
797 |
foundIsoIN = ETrue; |
|
798 |
if (++ep_found == 2) |
|
799 |
break; |
|
800 |
} |
|
801 |
else if (!foundIsoOUT && |
|
802 |
(caps->iTypesAndDir & (KUsbEpTypeIsochronous | KUsbEpDirOut)) == |
|
803 |
(KUsbEpTypeIsochronous | KUsbEpDirOut)) |
|
804 |
{ |
|
805 |
// This is going to be our Iso RX (OUT) endpoint |
|
806 |
ifc().iEndpointData[ep_found].iType = KUsbEpTypeIsochronous; |
|
807 |
ifc().iEndpointData[ep_found].iDir = KUsbEpDirOut; |
|
808 |
ifc().iEndpointData[ep_found].iSize = mps; |
|
809 |
ifc().iEndpointData[ep_found].iInterval = 0x01; // 2^(bInterval-1)ms, bInterval must be [1..16] |
|
810 |
ifc().iEndpointData[ep_found].iExtra = 2; // 2 extra bytes for Audio Class EP descriptor |
|
811 |
foundIsoOUT = ETrue; |
|
812 |
if (++ep_found == 2) |
|
813 |
break; |
|
814 |
} |
|
815 |
} |
|
816 |
// Let's try to add Bulk endpoints up to the max # of 2. |
|
817 |
if (ep_found < 2) |
|
818 |
{ |
|
819 |
for (TInt i = 0; i < n; i++) |
|
820 |
{ |
|
821 |
const TUsbcEndpointCaps* const caps = &data[i].iCaps; |
|
822 |
const TUint mps = caps->MaxPacketSize(); |
|
823 |
if (caps->iTypesAndDir & KUsbEpTypeBulk) |
|
824 |
{ |
|
825 |
const TUint dir = (caps->iTypesAndDir & KUsbEpDirIn) ? KUsbEpDirIn : KUsbEpDirOut; |
|
826 |
ifc().iEndpointData[ep_found].iType = KUsbEpTypeBulk; |
|
827 |
ifc().iEndpointData[ep_found].iDir = dir; |
|
828 |
ifc().iEndpointData[ep_found].iSize = mps; |
|
829 |
if (++ep_found == 2) |
|
830 |
break; |
|
831 |
} |
|
832 |
} |
|
833 |
} |
|
834 |
if (ep_found == 0) |
|
835 |
{ |
|
836 |
TUSB_PRINT("Not enough suitable endpoints found for alt ifc"); |
|
837 |
// not a disaster though |
|
838 |
return KErrNone; |
|
839 |
} |
|
840 |
||
841 |
_LIT16(ifcname1, "T_USB Test Interface (Alternate Setting 1)"); |
|
842 |
ifc().iString = const_cast<TDesC16*>(&ifcname1); |
|
843 |
ifc().iTotalEndpointsUsed = ep_found; |
|
844 |
ifc().iClass.iClassNum = KUsbAudioInterfaceClassCode; |
|
845 |
ifc().iClass.iSubClassNum = KUsbAudioInterfaceSubclassCode_Audiostreaming; |
|
846 |
ifc().iClass.iProtocolNum = KUsbAudioInterfaceProtocolCode_Pr_Protocol_Undefined; |
|
847 |
// Tell the driver that this setting is not interested in Ep0 requests: |
|
848 |
ifc().iFeatureWord |= KUsbcInterfaceInfo_NoEp0RequestsPlease; |
|
849 |
r = iPort.SetInterface(1, ifc); |
|
850 |
if (r != KErrNone) |
|
851 |
{ |
|
852 |
TUSB_PRINT1("Error %d on setting alternate interface", r); |
|
853 |
} |
|
854 |
||
855 |
return r; |
|
856 |
} |
|
857 |
||
858 |
||
859 |
void CActiveConsole::AllocateEndpointDMA(TEndpointNumber aEndpoint) |
|
860 |
{ |
|
861 |
TInt r = iPort.AllocateEndpointResource(aEndpoint, EUsbcEndpointResourceDMA); |
|
862 |
if (r == KErrNone) |
|
863 |
RDebug::Print(_L("DMA allocation on endpoint %d: KErrNone"), aEndpoint); |
|
864 |
else if (r == KErrInUse) |
|
865 |
RDebug::Print(_L("DMA allocation on endpoint %d: KErrInUse"), aEndpoint); |
|
866 |
else if (r == KErrNotSupported) |
|
867 |
RDebug::Print(_L("DMA allocation on endpoint %d: KErrNotSupported"), aEndpoint); |
|
868 |
else |
|
869 |
RDebug::Print(_L("DMA allocation on endpoint %d: unexpected return value %d"), |
|
870 |
aEndpoint, r); |
|
871 |
TBool res = iPort.QueryEndpointResourceUse(aEndpoint, EUsbcEndpointResourceDMA); |
|
872 |
TUSB_PRINT2("DMA on endpoint %d %s\n", |
|
873 |
aEndpoint, res ? _S("allocated") : _S("not allocated")); |
|
874 |
||
875 |
if ((r == KErrNone) && !res) |
|
876 |
RDebug::Print(_L("(Allocation success but negative query result: contradiction!)\n")); |
|
877 |
else if ((r != KErrNone) && res) |
|
878 |
RDebug::Print(_L("(Allocation failure but positive query result: contradiction!)\n")); |
|
879 |
} |
|
880 |
||
881 |
||
882 |
void CActiveConsole::DeAllocateEndpointDMA(TEndpointNumber aEndpoint) |
|
883 |
{ |
|
884 |
TInt r = iPort.DeAllocateEndpointResource(aEndpoint, EUsbcEndpointResourceDMA); |
|
885 |
if (r == KErrNone) |
|
886 |
RDebug::Print(_L("DMA deallocation on endpoint %d: KErrNone"), aEndpoint); |
|
887 |
else if (r == KErrNotSupported) |
|
888 |
RDebug::Print(_L("DMA deallocation on endpoint %d: KErrNotSupported"), aEndpoint); |
|
889 |
else |
|
890 |
RDebug::Print(_L("DMA deallocation on endpoint %d: unexpected return value %d"), |
|
891 |
aEndpoint, r); |
|
892 |
TBool res = iPort.QueryEndpointResourceUse(aEndpoint, EUsbcEndpointResourceDMA); |
|
893 |
TUSB_PRINT2("DMA on endpoint %d %s\n", |
|
894 |
aEndpoint, res ? _S("allocated") : _S("not allocated")); |
|
895 |
} |
|
896 |
||
897 |
||
898 |
void CActiveConsole::AllocateDoubleBuffering(TEndpointNumber aEndpoint) |
|
899 |
{ |
|
900 |
TInt r = iPort.AllocateEndpointResource(aEndpoint, EUsbcEndpointResourceDoubleBuffering); |
|
901 |
if (r == KErrNone) |
|
902 |
RDebug::Print(_L("Double Buffering allocation on endpoint %d: KErrNone"), aEndpoint); |
|
903 |
else if (r == KErrInUse) |
|
904 |
RDebug::Print(_L("Double Buffering allocation on endpoint %d: KErrInUse"), aEndpoint); |
|
905 |
else if (r == KErrNotSupported) |
|
906 |
RDebug::Print(_L("Double Buffering allocation on endpoint %d: KErrNotSupported"), aEndpoint); |
|
907 |
else |
|
908 |
RDebug::Print(_L("Double Buffering allocation on endpoint %d: unexpected return value %d"), |
|
909 |
aEndpoint, r); |
|
910 |
TBool res = iPort.QueryEndpointResourceUse(aEndpoint, EUsbcEndpointResourceDoubleBuffering); |
|
911 |
TUSB_PRINT2("Double Buffering on endpoint %d %s\n", |
|
912 |
aEndpoint, res ? _S("allocated") : _S("not allocated")); |
|
913 |
||
914 |
if ((r == KErrNone) && !res) |
|
915 |
RDebug::Print(_L("(Allocation success but negative query result: contradiction!)\n")); |
|
916 |
else if ((r != KErrNone) && res) |
|
917 |
RDebug::Print(_L("(Allocation failure but positive query result: contradiction!)\n")); |
|
918 |
} |
|
919 |
||
920 |
||
921 |
void CActiveConsole::DeAllocateDoubleBuffering(TEndpointNumber aEndpoint) |
|
922 |
{ |
|
923 |
TInt r = iPort.DeAllocateEndpointResource(aEndpoint, EUsbcEndpointResourceDoubleBuffering); |
|
924 |
if (r == KErrNone) |
|
925 |
RDebug::Print(_L("Double Buffering deallocation on endpoint %d: KErrNone"), aEndpoint); |
|
926 |
else if (r == KErrNotSupported) |
|
927 |
RDebug::Print(_L("Double Buffering deallocation on endpoint %d: KErrNotSupported"), aEndpoint); |
|
928 |
else |
|
929 |
RDebug::Print(_L("Double Buffering deallocation on endpoint %d: unexpected return value %d"), |
|
930 |
aEndpoint, r); |
|
931 |
TBool res = iPort.QueryEndpointResourceUse(aEndpoint, EUsbcEndpointResourceDoubleBuffering); |
|
932 |
TUSB_PRINT2("Double Buffering on endpoint %d %s\n", |
|
933 |
aEndpoint, res ? _S("allocated") : _S("not allocated")); |
|
934 |
} |
|
935 |
||
936 |
||
937 |
TInt CActiveConsole::ReEnumerate() |
|
938 |
{ |
|
939 |
TRequestStatus enum_status; |
|
940 |
iPort.ReEnumerate(enum_status); |
|
941 |
if (!iSoftwareConnect) |
|
942 |
{ |
|
943 |
iConsole->Printf(_L("This device does not support software\n")); |
|
944 |
iConsole->Printf(_L("disconnect/reconnect\n")); |
|
945 |
iConsole->Printf(_L("Please physically unplug and replug\n")); |
|
946 |
iConsole->Printf(_L("the USB cable NOW... ")); |
|
947 |
} |
|
948 |
iConsole->Printf(_L("\n>>> START THE USBRFLCT PROGRAM ON THE HOST SIDE NOW <<<\n")); |
|
949 |
User::WaitForRequest(enum_status); |
|
950 |
if (enum_status != KErrNone) |
|
951 |
{ |
|
952 |
TUSB_PRINT1("Error: Re-enumeration status = %d", enum_status.Int()); |
|
953 |
return KErrGeneral; |
|
954 |
} |
|
955 |
TUsbcDeviceState device_state = EUsbcDeviceStateUndefined; |
|
956 |
TInt r = iPort.DeviceStatus(device_state); |
|
957 |
if (r != KErrNone) |
|
958 |
{ |
|
959 |
TUSB_PRINT1("Error %d on querying device state", r); |
|
960 |
} |
|
961 |
else |
|
962 |
{ |
|
963 |
TUSB_PRINT1("Current device state: %s", |
|
964 |
(device_state == EUsbcDeviceStateUndefined) ? _S("Undefined") : |
|
965 |
((device_state == EUsbcDeviceStateAttached) ? _S("Attached") : |
|
966 |
((device_state == EUsbcDeviceStatePowered) ? _S("Powered") : |
|
967 |
((device_state == EUsbcDeviceStateDefault) ? _S("Default") : |
|
968 |
((device_state == EUsbcDeviceStateAddress) ? _S("Address") : |
|
969 |
((device_state == EUsbcDeviceStateConfigured) ? _S("Configured") : |
|
970 |
((device_state == EUsbcDeviceStateSuspended) ? _S("Suspended") : |
|
971 |
_S("Unknown")))))))); |
|
972 |
} |
|
973 |
||
974 |
// Check the speed of the established physical USB connection |
|
975 |
iHighSpeed = iPort.CurrentlyUsingHighSpeed(); |
|
976 |
if (iHighSpeed) |
|
977 |
{ |
|
978 |
TUSB_PRINT("---> USB High-speed Testing\n"); |
|
979 |
// It can only be 512 bytes when using high-speed. |
|
980 |
iRW->SetMaxPacketSize(512); // iRW already exists at this point |
|
981 |
} |
|
982 |
else |
|
983 |
{ |
|
984 |
TUSB_PRINT("---> USB Full-speed Testing\n"); |
|
985 |
// We only support 64 bytes when using full-speed. |
|
986 |
iRW->SetMaxPacketSize(64); // iRW already exists at this point |
|
987 |
} |
|
988 |
||
989 |
return KErrNone; |
|
990 |
} |
|
991 |
||
992 |
||
993 |
#ifdef test |
|
994 |
#undef test |
|
995 |
#endif |
|
996 |
#define test(x) \ |
|
997 |
do { \ |
|
998 |
if (!(x)) \ |
|
999 |
{ \ |
|
1000 |
TUSB_PRINT1("Failure occurred! - on line %d", __LINE__); \ |
|
1001 |
return KErrGeneral; \ |
|
1002 |
} \ |
|
1003 |
} while (0) |
|
1004 |
||
1005 |
||
1006 |
TInt CActiveConsole::SetupDescriptors() |
|
1007 |
{ |
|
1008 |
// === Device Descriptor |
|
1009 |
||
1010 |
TInt deviceDescriptorSize = 0; |
|
1011 |
iPort.GetDeviceDescriptorSize(deviceDescriptorSize); |
|
1012 |
test(static_cast<TUint>(deviceDescriptorSize) == KUsbDescSize_Device); |
|
1013 |
||
1014 |
TBuf8<KUsbDescSize_Device> deviceDescriptor; |
|
1015 |
TInt r = iPort.GetDeviceDescriptor(deviceDescriptor); |
|
1016 |
test(r == KErrNone); |
|
1017 |
||
1018 |
const TInt KUsbSpecOffset = 2; |
|
1019 |
const TInt KUsbVendorIdOffset = 8; |
|
1020 |
const TInt KUsbProductIdOffset = 10; |
|
1021 |
const TInt KUsbDevReleaseOffset = 12; |
|
1022 |
// Change the USB spec number to 2.00 |
|
1023 |
deviceDescriptor[KUsbSpecOffset] = 0x00; |
|
1024 |
deviceDescriptor[KUsbSpecOffset+1] = 0x02; |
|
1025 |
// Change the device vendor ID (VID) to 0x0E22 (Symbian) |
|
1026 |
deviceDescriptor[KUsbVendorIdOffset] = 0x22; // little endian! |
|
1027 |
deviceDescriptor[KUsbVendorIdOffset+1] = 0x0E; |
|
1028 |
// Change the device product ID (PID) to 0x1111 |
|
1029 |
deviceDescriptor[KUsbProductIdOffset] = 0x11; |
|
1030 |
deviceDescriptor[KUsbProductIdOffset+1] = 0x11; |
|
1031 |
// Change the device release number to 3.05 |
|
1032 |
deviceDescriptor[KUsbDevReleaseOffset] = 0x05; |
|
1033 |
deviceDescriptor[KUsbDevReleaseOffset+1] = 0x03; |
|
1034 |
r = iPort.SetDeviceDescriptor(deviceDescriptor); |
|
1035 |
test(r == KErrNone); |
|
1036 |
||
1037 |
const TUint16 Vid = (((TUint16)deviceDescriptor[KUsbVendorIdOffset + 1] << 8) & 0xff00) | |
|
1038 |
deviceDescriptor[KUsbVendorIdOffset]; |
|
1039 |
const TUint16 Pid = (((TUint16)deviceDescriptor[KUsbProductIdOffset + 1] << 8) & 0xff00) | |
|
1040 |
deviceDescriptor[KUsbProductIdOffset]; |
|
1041 |
||
1042 |
TUSB_PRINT6("\nVID = 0x%04X / PID = 0x%04X / DevRel = %d%d.%d%d\n", Vid, Pid, |
|
1043 |
((deviceDescriptor[KUsbDevReleaseOffset + 1] >> 4) & 0x0f), |
|
1044 |
(deviceDescriptor[KUsbDevReleaseOffset + 1] & 0x0f), |
|
1045 |
((deviceDescriptor[KUsbDevReleaseOffset] >> 4) & 0x0f), |
|
1046 |
(deviceDescriptor[KUsbDevReleaseOffset] & 0x0f)); |
|
1047 |
||
1048 |
// === Configuration Descriptor |
|
1049 |
||
1050 |
TInt configDescriptorSize = 0; |
|
1051 |
iPort.GetConfigurationDescriptorSize(configDescriptorSize); |
|
1052 |
test(static_cast<TUint>(configDescriptorSize) == KUsbDescSize_Config); |
|
1053 |
||
1054 |
TBuf8<KUsbDescSize_Config> configDescriptor; |
|
1055 |
r = iPort.GetConfigurationDescriptor(configDescriptor); |
|
1056 |
test(r == KErrNone); |
|
1057 |
||
1058 |
// Change the reported max power to 100mA (= 2 * 0x32), |
|
1059 |
// which is the highest value allowed for a bus-powered device. |
|
1060 |
const TInt KUsbMaxPowerOffset = 8; |
|
1061 |
configDescriptor[KUsbMaxPowerOffset] = 0x32; |
|
1062 |
r = iPort.SetConfigurationDescriptor(configDescriptor); |
|
1063 |
test(r == KErrNone); |
|
1064 |
||
1065 |
// === String Descriptors |
|
1066 |
||
1067 |
// Set up two arbitrary string descriptors, which can be queried |
|
1068 |
// manually from the host side for testing purposes (for instance |
|
1069 |
// using 'usbcheck'). |
|
1070 |
||
1071 |
_LIT16(string_one, "Arbitrary String Descriptor Test String 1"); |
|
1072 |
TBuf16<KUsbStringDescStringMaxSize / 2> wr_str(string_one); |
|
1073 |
r = iPort.SetStringDescriptor(stridx1, wr_str); |
|
1074 |
test(r == KErrNone); |
|
1075 |
||
1076 |
_LIT16(string_two, "Another Arbitrary String Descriptor Test String"); |
|
1077 |
wr_str.FillZ(wr_str.MaxLength()); |
|
1078 |
wr_str = string_two; |
|
1079 |
r = iPort.SetStringDescriptor(stridx2, wr_str); |
|
1080 |
test(r == KErrNone); |
|
1081 |
||
1082 |
return KErrNone; |
|
1083 |
} |
|
1084 |
||
1085 |
||
1086 |
// |
|
1087 |
// --- class CActiveRW --------------------------------------------------------- |
|
1088 |
// |
|
1089 |
||
1090 |
CActiveRW::CActiveRW(CConsoleBase* aConsole, RDevUsbcClient* aPort, TBool aVerboseOutput) |
|
1091 |
: CActive(EPriorityNormal), |
|
1092 |
iConsole(aConsole), |
|
1093 |
iPort(aPort), |
|
1094 |
iBufSz(KInitialBufSz), |
|
1095 |
iMaxBufSz(KInitialBufSz), |
|
1096 |
iMaxPktSz(0), |
|
1097 |
iCurrentXfer(ENone), |
|
1098 |
iXferMode(::ENone), |
|
1099 |
iDoStop(EFalse), |
|
1100 |
iPktNum(~0), |
|
1101 |
iVerbose(aVerboseOutput) |
|
1102 |
{ |
|
1103 |
TUSB_VERBOSE_PRINT("CActiveRW::CActiveRW()"); |
|
1104 |
} |
|
1105 |
||
1106 |
||
1107 |
CActiveRW* CActiveRW::NewL(CConsoleBase* aConsole, RDevUsbcClient* aPort, TBool aVerboseOutput) |
|
1108 |
{ |
|
1109 |
CActiveRW* self = new (ELeave) CActiveRW(aConsole, aPort, aVerboseOutput); |
|
1110 |
CleanupStack::PushL(self); |
|
1111 |
self->ConstructL(); |
|
1112 |
CActiveScheduler::Add(self); |
|
1113 |
CleanupStack::Pop(); // self |
|
1114 |
return self; |
|
1115 |
} |
|
1116 |
||
1117 |
||
1118 |
void CActiveRW::ConstructL() |
|
1119 |
{ |
|
1120 |
TUSB_VERBOSE_PRINT("CActiveRW::ConstructL()"); |
|
1121 |
||
1122 |
User::LeaveIfError(iFs.Connect()); |
|
1123 |
||
1124 |
// Prepare Preamble buffer |
|
1125 |
iPreambleBuf.SetMax(); |
|
1126 |
iPreambleBuf.FillZ(); |
|
1127 |
||
1128 |
// Prepare IN data buffer |
|
1129 |
iWriteBuf.SetMax(); |
|
1130 |
for (TInt i = 0; i < iWriteBuf.MaxSize(); i++) |
|
1131 |
{ |
|
1132 |
iWriteBuf[i] = i; |
|
1133 |
} |
|
1134 |
||
1135 |
// Prepare OUT data buffer |
|
1136 |
iReadBuf.SetMax(); |
|
1137 |
||
1138 |
// Create read timeout timer active object (but don't activate it yet) |
|
1139 |
iTimeoutTimer = CActiveTimer::NewL(iConsole, iPort, iVerbose); |
|
1140 |
if (!iTimeoutTimer) |
|
1141 |
{ |
|
1142 |
TUSB_PRINT("Failed to create timeout timer"); |
|
1143 |
} |
|
1144 |
} |
|
1145 |
||
1146 |
||
1147 |
CActiveRW::~CActiveRW() |
|
1148 |
{ |
|
1149 |
TUSB_VERBOSE_PRINT("CActiveRW::~CActiveRW()"); |
|
1150 |
Cancel(); // base class |
|
1151 |
delete iTimeoutTimer; |
|
1152 |
iFile.Close(); |
|
1153 |
iFs.Close(); |
|
1154 |
} |
|
1155 |
||
1156 |
||
1157 |
void CActiveRW::SetMaxBufSize(TInt aBufSz) |
|
1158 |
{ |
|
1159 |
if (aBufSz > KMaxBufSize) |
|
1160 |
{ |
|
1161 |
TUSB_PRINT2("SetMaxBufSize(): too large: %d! (using %d)", aBufSz, KMaxBufSize); |
|
1162 |
aBufSz = KMaxBufSize; |
|
1163 |
} |
|
1164 |
iMaxBufSz = aBufSz; |
|
1165 |
} |
|
1166 |
||
1167 |
||
1168 |
void CActiveRW::SetMaxPacketSize(TInt aPktSz) |
|
1169 |
{ |
|
1170 |
iMaxPktSz = aPktSz; |
|
1171 |
} |
|
1172 |
||
1173 |
||
1174 |
TInt CActiveRW::MaxBufSize() const |
|
1175 |
{ |
|
1176 |
return iMaxBufSz; |
|
1177 |
} |
|
1178 |
||
1179 |
||
1180 |
void CActiveRW::SetTransferMode(TXferMode aMode) |
|
1181 |
{ |
|
1182 |
iXferMode = aMode; |
|
1183 |
if (aMode == EReceiveOnly || aMode == ETransmitOnly) |
|
1184 |
{ |
|
1185 |
// For streaming transfers we do this only once. |
|
1186 |
iBufSz = iMaxBufSz; |
|
1187 |
} |
|
1188 |
} |
|
1189 |
||
1190 |
||
1191 |
void CActiveRW::RunL() |
|
1192 |
{ |
|
1193 |
TUSB_VERBOSE_PRINT("CActiveRW::RunL()"); |
|
1194 |
if (iStatus != KErrNone) |
|
1195 |
{ |
|
1196 |
TUSB_PRINT1("Error %d in RunL", iStatus.Int()); |
|
1197 |
} |
|
1198 |
if (iDoStop) |
|
1199 |
{ |
|
1200 |
TUSB_PRINT("Stopped"); |
|
1201 |
iDoStop = EFalse; |
|
1202 |
return; |
|
1203 |
} |
|
1204 |
switch (iCurrentXfer) |
|
1205 |
{ |
|
1206 |
case EPreamble: |
|
1207 |
if (iXferMode != EReceiveOnly) |
|
1208 |
SendData(); // next we write data |
|
1209 |
else |
|
1210 |
ReadData(); // or we read data |
|
1211 |
break; |
|
1212 |
case EWriteXfer: |
|
1213 |
if (iXferMode == ETransmitOnly) |
|
1214 |
SendData(); // next we send data |
|
1215 |
else |
|
1216 |
ReadData(); // or we read data |
|
1217 |
break; |
|
1218 |
case EReadXfer: |
|
1219 |
if (iXferMode == EReceiveOnly) |
|
1220 |
{ |
|
1221 |
const TUint32 num = *reinterpret_cast<const TUint32*>(iReadBuf.Ptr()); |
|
1222 |
if (num != ++iPktNum) |
|
1223 |
{ |
|
1224 |
TUSB_PRINT2("*** rcv'd wrong pkt number: 0x%x (expected: 0x%x)", num, iPktNum); |
|
1225 |
// Update the packet number with the received number, so that |
|
1226 |
// if a single packet is duplicated or lost then a single error occurs |
|
1227 |
iPktNum = num; |
|
1228 |
} |
|
1229 |
if (iDiskAccessEnabled) |
|
1230 |
{ |
|
1231 |
// Write out to disk previous completed Read |
|
1232 |
TUSB_VERBOSE_PRINT2("iMaxBufSz = %d (iReadBuf.Size(): %d)", |
|
1233 |
iMaxBufSz, iReadBuf.Size()); |
|
1234 |
WriteBufferToDisk(iReadBuf, iMaxBufSz); |
|
1235 |
} |
|
1236 |
ReadData(); // next we read data |
|
1237 |
break; |
|
1238 |
} |
|
1239 |
if (iXferMode == ELoopComp) |
|
1240 |
{ |
|
1241 |
if (!CompareBuffers(iBufSz)) |
|
1242 |
{ |
|
1243 |
TUSB_PRINT1("Error while comparing tx & rx buffers for packet 0x%x", iPktNum); |
|
1244 |
} |
|
1245 |
} |
|
1246 |
else if (iBufSz > 3) |
|
1247 |
{ |
|
1248 |
const TUint32 num = *reinterpret_cast<const TUint32*>(iReadBuf.Ptr()); |
|
1249 |
if (num != iPktNum) |
|
1250 |
{ |
|
1251 |
TUSB_PRINT2("*** rcv'd wrong pkt number: 0x%x (expected: 0x%x)", num, iPktNum); |
|
1252 |
} |
|
1253 |
} |
|
1254 |
if (iBufSz == iMaxBufSz) |
|
1255 |
{ |
|
1256 |
iBufSz = KInitialBufSz; |
|
1257 |
} |
|
1258 |
else |
|
1259 |
{ |
|
1260 |
++iBufSz; |
|
1261 |
} |
|
1262 |
SendPreamble(); // next we send the length |
|
1263 |
break; |
|
1264 |
default: |
|
1265 |
TUSB_PRINT("Oops. (Shouldn't end up here...)"); |
|
1266 |
break; |
|
1267 |
} |
|
1268 |
return; |
|
1269 |
} |
|
1270 |
||
1271 |
||
1272 |
TInt CActiveRW::SendVersion() |
|
1273 |
{ |
|
1274 |
TUSB_VERBOSE_PRINT("CActiveRW::SendVersion()"); |
|
1275 |
if (iXferMode != ::ENone) |
|
1276 |
{ |
|
1277 |
TUSB_PRINT1("Error : wrong state: %d", iXferMode); |
|
1278 |
return KErrGeneral; |
|
1279 |
} |
|
1280 |
// Here we send our version packet to the host. |
|
1281 |
// (We can use the preamble buffer because we only need it |
|
1282 |
// once and that's also before the preamble uses.) |
|
1283 |
TUSB_PRINT1("Sending T_USB version: %d\n", KTusbVersion); |
|
1284 |
iPreambleBuf.FillZ(); |
|
1285 |
*reinterpret_cast<TUint32*>(&iPreambleBuf[0]) = SWAP_BYTES_32(KTusbVersion); |
|
1286 |
// A 'magic' string so that USBRFLCT doesn't interpret the first 4 bytes |
|
1287 |
// of a data preamble packet of an old T_USB as the version number. |
|
1288 |
iPreambleBuf[4] = 'V'; |
|
1289 |
iPreambleBuf[5] = 'e'; |
|
1290 |
iPreambleBuf[6] = 'r'; |
|
1291 |
iPreambleBuf[7] = 's'; |
|
1292 |
TRequestStatus send_status; |
|
1293 |
iPort->Write(send_status, EEndpoint1, iPreambleBuf, KPreambleLength); |
|
1294 |
TUSB_VERBOSE_PRINT("Waiting for write request to complete..."); |
|
1295 |
User::WaitForRequest(send_status); |
|
1296 |
TUSB_VERBOSE_PRINT("...done.\n"); |
|
1297 |
return send_status.Int(); |
|
1298 |
} |
|
1299 |
||
1300 |
||
1301 |
TInt CActiveRW::ReceiveVersion() |
|
1302 |
{ |
|
1303 |
TUSB_VERBOSE_PRINT("CActiveRW::ReceiveVersion()"); |
|
1304 |
if (iXferMode != ::ENone) |
|
1305 |
{ |
|
1306 |
TUSB_PRINT1("Error : wrong state: %d", iXferMode); |
|
1307 |
return KErrGeneral; |
|
1308 |
} |
|
1309 |
// Here we try to receive a version packet from the host. |
|
1310 |
// (We can use the preamble buffer because we only need it |
|
1311 |
// once and that's also before the preamble uses.) |
|
1312 |
TUSB_PRINT("Getting host program versions..."); |
|
1313 |
iPreambleBuf.FillZ(); |
|
1314 |
TRequestStatus receive_status; |
|
1315 |
iPort->Read(receive_status, EEndpoint2, iPreambleBuf, KPreambleLength); |
|
1316 |
TUSB_VERBOSE_PRINT("Waiting for read request to complete..."); |
|
1317 |
iTimeoutTimer->Activate(5000000); // Host gets 5s |
|
1318 |
User::WaitForRequest(receive_status, iTimeoutTimer->iStatus); |
|
1319 |
if (receive_status == KRequestPending) |
|
1320 |
{ |
|
1321 |
// Read() still pending... |
|
1322 |
TUSB_PRINT("Cancelling USB Read(): no response from host.\n"); |
|
1323 |
iPort->ReadCancel(EEndpoint2); |
|
1324 |
TUSB_PRINT("THIS COULD BE DUE TO AN OLD VERSION OF USBRFLCT ON THE PC:"); |
|
1325 |
TUSB_PRINT3("PLEASE CHECK THE VERSION THERE - WE NEED AT LEAST V%d.%d.%d!\n", |
|
1326 |
KUsbrflctVersionMajor, KUsbrflctVersionMinor, KUsbrflctVersionMicro); |
|
1327 |
TUSB_PRINT("When updating an existing USBRFLCT installation <= v1.3.1,\n" \ |
|
1328 |
L"the following three things will need to be done:\n"); |
|
1329 |
TUSB_PRINT("1. Connect the device to the PC & start T_USB (just as now),\n" \ |
|
1330 |
L"then find the USB device in the Windows Device Manager\n" \ |
|
1331 |
L"('Control Panel'->'System'->'Hardware'->'Device Manager').\n" \ |
|
1332 |
L"Right click on the device name and choose 'Uninstall...'.\n"); |
|
1333 |
TUSB_PRINT("2. In c:\\winnt\\inf\\, find (by searching for \"Symbian\") and\n" \ |
|
1334 |
L"delete the *.INF file that was used to install the existing\n" \ |
|
1335 |
L"version of USBRFLCT.SYS. Make sure to also delete the\n" \ |
|
1336 |
L"precompiled version of that file (<samename>.PNF).\n"); |
|
1337 |
TUSB_PRINT("3. In c:\\winnt\\system32\\drivers\\, delete the file USBRFLCT.SYS.\n"); |
|
1338 |
TUSB_PRINT("Then unplug & reconnect the USB device and, when prompted, install\n" \ |
|
1339 |
L"the new USBRFLCT.SYS driver using the .INF file from this distribution.\n" \ |
|
1340 |
L"(All files can be found under e32test\\win32\\usbrflct_distribution\\.)\n"); |
|
1341 |
TUSB_PRINT("Use the new USBRFLCT.EXE from this distribution.\n"); |
|
1342 |
} |
|
1343 |
else |
|
1344 |
{ |
|
1345 |
TUSB_VERBOSE_PRINT("...done."); |
|
1346 |
// Timeout not needed any longer |
|
1347 |
TUSB_VERBOSE_PRINT("Cancelling timeout timer: USB Read() completed.\n"); |
|
1348 |
iTimeoutTimer->Cancel(); |
|
1349 |
} |
|
1350 |
return receive_status.Int(); |
|
1351 |
} |
|
1352 |
||
1353 |
||
1354 |
TInt CActiveRW::ExchangeVersions() |
|
1355 |
{ |
|
1356 |
TUSB_VERBOSE_PRINT("CActiveRW::ExchangeVersions()"); |
|
1357 |
// First check the version of USBRFLCT that's running on the host |
|
1358 |
TInt r = ReceiveVersion(); |
|
1359 |
if (r != KErrNone) |
|
1360 |
{ |
|
1361 |
return KErrGeneral; |
|
1362 |
} |
|
1363 |
TUint8 usbrflct_ver_major = iPreambleBuf[0]; |
|
1364 |
TUint8 usbrflct_ver_minor = iPreambleBuf[1]; |
|
1365 |
TUint8 usbrflct_ver_micro = iPreambleBuf[2]; |
|
1366 |
TUint8 usbio_ver_major = iPreambleBuf[3]; |
|
1367 |
TUint8 usbio_ver_minor = iPreambleBuf[4]; |
|
1368 |
TUSB_PRINT5("Host-side: USBRFLCT v%d.%d.%d USBIO v%d.%d\n", |
|
1369 |
usbrflct_ver_major, usbrflct_ver_minor, usbrflct_ver_micro, |
|
1370 |
usbio_ver_major, usbio_ver_minor); |
|
1371 |
if (usbrflct_ver_major < KUsbrflctVersionMajor) |
|
1372 |
{ |
|
1373 |
TUSB_PRINT1("USBRFLCT version not sufficient (need at least v%d.x.x)\n", |
|
1374 |
KUsbrflctVersionMajor); |
|
1375 |
return KErrGeneral; |
|
1376 |
} |
|
1377 |
// Just using '<' instead of the seemingly absurd '<= && !==' doesn't work without |
|
1378 |
// GCC compiler warning because Kxxx can also be zero (in which case there's no '<'). |
|
1379 |
else if ((usbrflct_ver_minor <= KUsbrflctVersionMinor) && |
|
1380 |
!(usbrflct_ver_minor == KUsbrflctVersionMinor)) |
|
1381 |
{ |
|
1382 |
TUSB_PRINT2("USBRFLCT version not sufficient (need at least v%d.%d.x)\n", |
|
1383 |
KUsbrflctVersionMajor, KUsbrflctVersionMinor); |
|
1384 |
return KErrGeneral; |
|
1385 |
} |
|
1386 |
// Just using '<' instead of the seemingly absurd '<= && !==' doesn't work without |
|
1387 |
// GCC compiler warning because Kxxx can also be zero (in which case there's no '<'). |
|
1388 |
else if ((usbrflct_ver_micro <= KUsbrflctVersionMicro) && |
|
1389 |
!(usbrflct_ver_micro == KUsbrflctVersionMicro)) |
|
1390 |
{ |
|
1391 |
TUSB_PRINT3("USBRFLCT version not sufficient (need at least v%d.%d.%d)\n", |
|
1392 |
KUsbrflctVersionMajor, KUsbrflctVersionMinor, KUsbrflctVersionMicro); |
|
1393 |
return KErrGeneral; |
|
1394 |
} |
|
1395 |
// Now we send T_USB's version to the host |
|
1396 |
r = SendVersion(); |
|
1397 |
if (r != KErrNone) |
|
1398 |
{ |
|
1399 |
return KErrGeneral; |
|
1400 |
} |
|
1401 |
return KErrNone; |
|
1402 |
} |
|
1403 |
||
1404 |
||
1405 |
void CActiveRW::SendPreamble() |
|
1406 |
{ |
|
1407 |
TUSB_VERBOSE_PRINT("CActiveRW::SendPreamble()"); |
|
1408 |
__ASSERT_ALWAYS(!IsActive(), User::Panic(KActivePanic, 666)); |
|
1409 |
TUSB_VERBOSE_PRINT1("Sending data length: %d bytes", iBufSz); |
|
1410 |
*reinterpret_cast<TUint32*>(&iPreambleBuf[0]) = SWAP_BYTES_32(iBufSz); |
|
1411 |
iPort->Write(iStatus, EEndpoint1, iPreambleBuf, KPreambleLength); |
|
1412 |
iCurrentXfer = EPreamble; |
|
1413 |
SetActive(); |
|
1414 |
} |
|
1415 |
||
1416 |
||
1417 |
void CActiveRW::SendData() |
|
1418 |
{ |
|
1419 |
TUSB_VERBOSE_PRINT("CActiveRW::SendData()"); |
|
1420 |
__ASSERT_ALWAYS(!IsActive(), User::Panic(KActivePanic, 666)); |
|
1421 |
if (iDiskAccessEnabled) |
|
1422 |
{ |
|
1423 |
ReadBufferFromDisk(iWriteBuf, iBufSz); |
|
1424 |
} |
|
1425 |
++iPktNum; |
|
1426 |
if (iBufSz > 3) |
|
1427 |
{ |
|
1428 |
*reinterpret_cast<TUint32*>(const_cast<TUint8*>(iWriteBuf.Ptr())) = iPktNum; |
|
1429 |
} |
|
1430 |
if (iXferMode == ELoopComp) |
|
1431 |
{ |
|
1432 |
for (TInt i = 4; i < iBufSz; i++) |
|
1433 |
{ |
|
1434 |
iWriteBuf[i] = static_cast<TUint8>(iPktNum & 0x000000ff); |
|
1435 |
} |
|
1436 |
} |
|
1437 |
TUSB_VERBOSE_PRINT1("Sending data: %d bytes", iBufSz); |
|
1438 |
iPort->Write(iStatus, EEndpoint1, iWriteBuf, iBufSz); |
|
1439 |
iCurrentXfer = EWriteXfer; |
|
1440 |
SetActive(); |
|
1441 |
} |
|
1442 |
||
1443 |
||
1444 |
TInt CActiveRW::SelectDrive() |
|
1445 |
{ |
|
1446 |
TDriveList driveList; |
|
1447 |
TInt r = iFs.DriveList(driveList); |
|
1448 |
if (r != KErrNone) |
|
1449 |
{ |
|
1450 |
TUSB_PRINT1("RFs::DriveList() returned %d", r); |
|
1451 |
return r; |
|
1452 |
} |
|
1453 |
TUSB_PRINT("Available drives:"); |
|
1454 |
for (TInt n = 0; n < KMaxDrives; n++) |
|
1455 |
{ |
|
1456 |
if (driveList[n] != 0) |
|
1457 |
{ |
|
1458 |
TVolumeInfo volumeInfo; |
|
1459 |
r = iFs.Volume(volumeInfo, n); |
|
1460 |
if (r == KErrNone) |
|
1461 |
{ |
|
1462 |
TPtr name(volumeInfo.iName.Des()); |
|
1463 |
TUSB_PRINT2("Drive %c: %- 16S", 'A' + n, &name); |
|
1464 |
if (volumeInfo.iDrive.iMediaAtt & KMediaAttWriteProtected) |
|
1465 |
TUSB_PRINT(" (read-only)"); |
|
1466 |
TUSB_PRINT(""); |
|
1467 |
} |
|
1468 |
} |
|
1469 |
} |
|
1470 |
iConsole->Printf(_L("Please select a drive letter (or 'Q' to quit)...")); |
|
1471 |
TChar driveLetter; |
|
1472 |
TInt driveNumber; |
|
1473 |
TVolumeInfo volumeInfo; |
|
1474 |
do |
|
1475 |
{ |
|
1476 |
driveLetter = (TUint)iConsole->Getch(); |
|
1477 |
driveLetter.UpperCase(); |
|
1478 |
if (driveLetter == 'Q') |
|
1479 |
{ |
|
1480 |
return KErrCancel; |
|
1481 |
} |
|
1482 |
driveNumber = (TUint)driveLetter - 'A'; |
|
1483 |
r = iFs.Volume(volumeInfo, driveNumber); |
|
1484 |
} |
|
1485 |
while ((driveNumber < 0) || |
|
1486 |
(driveNumber >= KMaxDrives) || |
|
1487 |
(r) || |
|
1488 |
(driveList[driveNumber] == 0) || |
|
1489 |
(volumeInfo.iDrive.iMediaAtt & KMediaAttWriteProtected)); |
|
1490 |
||
1491 |
iFileName.Format(_L("%c:"), driveLetter.operator TUint()); |
|
1492 |
iFileName.Append(KFileName); |
|
1493 |
TUSB_PRINT1("\nFilename = %S", &iFileName); |
|
1494 |
TUSB_PRINT1("File size: %d", KMaxFileSize); |
|
1495 |
return r; |
|
1496 |
} |
|
1497 |
||
1498 |
||
1499 |
TInt CActiveRW::WriteToDisk(TBool aEnable) |
|
1500 |
{ |
|
1501 |
iDiskAccessEnabled = aEnable; |
|
1502 |
TInt r = KErrNone; |
|
1503 |
||
1504 |
if (iDiskAccessEnabled) |
|
1505 |
{ |
|
1506 |
r = SelectDrive(); |
|
1507 |
if (r != KErrNone) |
|
1508 |
{ |
|
1509 |
iDiskAccessEnabled = EFalse; |
|
1510 |
return r; |
|
1511 |
} |
|
1512 |
// open the record file |
|
1513 |
r = iFile.Replace(iFs, iFileName, EFileWrite); |
|
1514 |
iFileOffset = 0; |
|
1515 |
} |
|
1516 |
return r; |
|
1517 |
} |
|
1518 |
||
1519 |
||
1520 |
TInt CActiveRW::ReadFromDisk(TBool aEnable) |
|
1521 |
{ |
|
1522 |
iDiskAccessEnabled = aEnable; |
|
1523 |
TInt r = KErrNone; |
|
1524 |
||
1525 |
if (iDiskAccessEnabled) |
|
1526 |
{ |
|
1527 |
r = SelectDrive(); |
|
1528 |
if (r != KErrNone) |
|
1529 |
{ |
|
1530 |
iDiskAccessEnabled = EFalse; |
|
1531 |
return r; |
|
1532 |
} |
|
1533 |
// First create the file & fill it |
|
1534 |
r = iFile.Replace(iFs, iFileName, EFileWrite); |
|
1535 |
if (r != KErrNone) |
|
1536 |
{ |
|
1537 |
TUSB_PRINT1("RFile::Replace() returned %d", r); |
|
1538 |
iDiskAccessEnabled = EFalse; |
|
1539 |
return r; |
|
1540 |
} |
|
1541 |
const TInt KBufferSize = 4 * 1024; |
|
1542 |
TBuf8<KBufferSize> buffer; |
|
1543 |
buffer.SetLength(KBufferSize); |
|
1544 |
for (TInt n = 0; n < KBufferSize; n++) |
|
1545 |
{ |
|
1546 |
buffer[n] = static_cast<TUint8>(n & 0x000000ff); |
|
1547 |
} |
|
1548 |
TUSB_PRINT("Writing data to file (this may take some minutes...)"); |
|
1549 |
for (TInt n = 0; n < KMaxFileSize; n += KBufferSize) |
|
1550 |
{ |
|
1551 |
r = iFile.Write(buffer, KBufferSize); |
|
1552 |
if (r != KErrNone) |
|
1553 |
{ |
|
1554 |
TUSB_PRINT1("RFile::Write() returned %d (disk full?)", r); |
|
1555 |
iFile.Close(); |
|
1556 |
iDiskAccessEnabled = EFalse; |
|
1557 |
return r; |
|
1558 |
} |
|
1559 |
} |
|
1560 |
TUSB_PRINT("Done."); |
|
1561 |
iFile.Close(); |
|
1562 |
// Now open the file for reading |
|
1563 |
r = iFile.Open(iFs, iFileName, EFileRead); |
|
1564 |
if (r != KErrNone) |
|
1565 |
{ |
|
1566 |
TUSB_PRINT1("RFile::Open() returned %d", r); |
|
1567 |
iDiskAccessEnabled = EFalse; |
|
1568 |
return r; |
|
1569 |
} |
|
1570 |
iFileOffset = 0; |
|
1571 |
} |
|
1572 |
return r; |
|
1573 |
} |
|
1574 |
||
1575 |
||
1576 |
void CActiveRW::WriteBufferToDisk(TDes8& aBuffer, TInt aLen) |
|
1577 |
{ |
|
1578 |
TUSB_VERBOSE_PRINT1("CActiveRW::WriteBufferToDisk(), len = %d", aLen); |
|
1579 |
TInt r = iFile.Write(aBuffer, aLen); |
|
1580 |
if (r != KErrNone) |
|
1581 |
{ |
|
1582 |
TUSB_PRINT2("Error writing to %S (%d)", &iFileName, r); |
|
1583 |
iDiskAccessEnabled = EFalse; |
|
1584 |
return; |
|
1585 |
} |
|
1586 |
iFileOffset += aLen; |
|
1587 |
if (iFileOffset >= KMaxFileSize) |
|
1588 |
{ |
|
1589 |
iFileOffset = 0; |
|
1590 |
iFile.Seek(ESeekStart, iFileOffset); |
|
1591 |
} |
|
1592 |
} |
|
1593 |
||
1594 |
||
1595 |
void CActiveRW::ReadBufferFromDisk(TDes8& aBuffer, TInt aLen) |
|
1596 |
{ |
|
1597 |
if (iFileOffset + aLen >= KMaxFileSize) |
|
1598 |
{ |
|
1599 |
iFileOffset = 0; |
|
1600 |
iFile.Seek(ESeekStart, iFileOffset); |
|
1601 |
} |
|
1602 |
const TInt r = iFile.Read(aBuffer, aLen); |
|
1603 |
if (r != KErrNone) |
|
1604 |
{ |
|
1605 |
TUSB_PRINT2("Error reading from %S (%d)", &iFileName, r); |
|
1606 |
iDiskAccessEnabled = EFalse; |
|
1607 |
return; |
|
1608 |
} |
|
1609 |
TInt readLen = aBuffer.Length(); |
|
1610 |
TUSB_VERBOSE_PRINT1("CActiveRW::ReadBufferFromDisk(), len = %d\n", readLen); |
|
1611 |
if (readLen < aLen) |
|
1612 |
{ |
|
1613 |
TUSB_PRINT3("Only %d bytes of %d read from file %S)", |
|
1614 |
readLen, aLen, &iFileName); |
|
1615 |
iDiskAccessEnabled = EFalse; |
|
1616 |
return; |
|
1617 |
} |
|
1618 |
iFileOffset += aLen; |
|
1619 |
} |
|
1620 |
||
1621 |
||
1622 |
void CActiveRW::ReadData() |
|
1623 |
{ |
|
1624 |
TUSB_VERBOSE_PRINT("CActiveRW::ReadData()"); |
|
1625 |
__ASSERT_ALWAYS(!IsActive(), User::Panic(KActivePanic, 666)); |
|
1626 |
TUSB_VERBOSE_PRINT1("Reading data: %d bytes", iBufSz); |
|
1627 |
if (iXferMode == EReceiveOnly) |
|
1628 |
{ |
|
1629 |
TUSB_VERBOSE_PRINT(" (rx only)"); |
|
1630 |
iPort->Read(iStatus, EEndpoint2, iReadBuf, iBufSz); |
|
1631 |
} |
|
1632 |
else if (iBufSz == iMaxPktSz) |
|
1633 |
{ |
|
1634 |
// we also want to test the packet version of Read() |
|
1635 |
TUSB_VERBOSE_PRINT(" (a single packet)"); |
|
1636 |
iPort->ReadPacket(iStatus, EEndpoint2, iReadBuf, iBufSz); |
|
1637 |
} |
|
1638 |
else if (iBufSz == iReadBuf.MaxSize()) |
|
1639 |
{ |
|
1640 |
// or we could perhaps test the three-parameter version |
|
1641 |
TUSB_VERBOSE_PRINT(" (w/o length)"); |
|
1642 |
iPort->Read(iStatus, EEndpoint2, iReadBuf); |
|
1643 |
} |
|
1644 |
else |
|
1645 |
{ |
|
1646 |
// otherwise, we use the universal default version |
|
1647 |
TUSB_VERBOSE_PRINT(" (normal)"); |
|
1648 |
iPort->Read(iStatus, EEndpoint2, iReadBuf, iBufSz); |
|
1649 |
} |
|
1650 |
iCurrentXfer = EReadXfer; |
|
1651 |
SetActive(); |
|
1652 |
} |
|
1653 |
||
1654 |
||
1655 |
void CActiveRW::Stop() |
|
1656 |
{ |
|
1657 |
if (!IsActive()) |
|
1658 |
{ |
|
1659 |
TUSB_PRINT("CActiveRW::Stop(): Not active"); |
|
1660 |
return; |
|
1661 |
} |
|
1662 |
TUSB_PRINT("Cancelling outstanding transfer requests\n"); |
|
1663 |
iBufSz = KInitialBufSz; |
|
1664 |
iPktNum = ~0; |
|
1665 |
iDoStop = ETrue; |
|
1666 |
iCurrentXfer = ENone; |
|
1667 |
Cancel(); |
|
1668 |
} |
|
1669 |
||
1670 |
||
1671 |
void CActiveRW::DoCancel() |
|
1672 |
{ |
|
1673 |
TUSB_VERBOSE_PRINT("CActiveRW::DoCancel()"); |
|
1674 |
// Canceling the transfer requests can be done explicitly |
|
1675 |
// for every transfer... |
|
1676 |
iPort->WriteCancel(EEndpoint1); |
|
1677 |
iPort->ReadCancel(EEndpoint2); |
|
1678 |
// or like this: |
|
1679 |
iPort->EndpointTransferCancel(~0); |
|
1680 |
} |
|
1681 |
||
1682 |
||
1683 |
TBool CActiveRW::CompareBuffers(TInt aLen) |
|
1684 |
{ |
|
1685 |
TUSB_VERBOSE_PRINT1("CActiveRW::CompareBuffers(%d)", aLen); |
|
1686 |
for (TInt i = 0; i < aLen; i++) |
|
1687 |
{ |
|
1688 |
if (iReadBuf[i] != iWriteBuf[i]) |
|
1689 |
{ |
|
1690 |
TUSB_VERBOSE_PRINT1("Error: for i = %d:", i); |
|
1691 |
TUSB_VERBOSE_PRINT2("iReadBuf: %d != iWriteBuf: %d", |
|
1692 |
iReadBuf[i], iWriteBuf[i]); |
|
1693 |
return EFalse; |
|
1694 |
} |
|
1695 |
} |
|
1696 |
return ETrue; |
|
1697 |
} |
|
1698 |
||
1699 |
||
1700 |
// |
|
1701 |
// --- class CActiveStallNotifier --------------------------------------------------------- |
|
1702 |
// |
|
1703 |
||
1704 |
CActiveStallNotifier::CActiveStallNotifier(CConsoleBase* aConsole, RDevUsbcClient* aPort, |
|
1705 |
TBool aVerboseOutput) |
|
1706 |
: CActive(EPriorityNormal), |
|
1707 |
iConsole(aConsole), |
|
1708 |
iPort(aPort), |
|
1709 |
iEndpointState(0), |
|
1710 |
iVerbose(aVerboseOutput) |
|
1711 |
{ |
|
1712 |
CActiveScheduler::Add(this); |
|
1713 |
} |
|
1714 |
||
1715 |
CActiveStallNotifier* CActiveStallNotifier::NewL(CConsoleBase* aConsole, RDevUsbcClient* aPort, |
|
1716 |
TBool aVerboseOutput) |
|
1717 |
{ |
|
1718 |
CActiveStallNotifier* self = new (ELeave) CActiveStallNotifier(aConsole, aPort, aVerboseOutput); |
|
1719 |
CleanupStack::PushL(self); |
|
1720 |
self->ConstructL(); |
|
1721 |
CleanupStack::Pop(); // self |
|
1722 |
return self; |
|
1723 |
} |
|
1724 |
||
1725 |
||
1726 |
void CActiveStallNotifier::ConstructL() |
|
1727 |
{} |
|
1728 |
||
1729 |
||
1730 |
CActiveStallNotifier::~CActiveStallNotifier() |
|
1731 |
{ |
|
1732 |
TUSB_VERBOSE_PRINT("CActiveStallNotifier::~CActiveStallNotifier()"); |
|
1733 |
Cancel(); // base class |
|
1734 |
} |
|
1735 |
||
1736 |
||
1737 |
void CActiveStallNotifier::DoCancel() |
|
1738 |
{ |
|
1739 |
TUSB_VERBOSE_PRINT("CActiveStallNotifier::DoCancel()"); |
|
1740 |
iPort->EndpointStatusNotifyCancel(); |
|
1741 |
} |
|
1742 |
||
1743 |
||
1744 |
void CActiveStallNotifier::RunL() |
|
1745 |
{ |
|
1746 |
// This just displays the bitmap, showing which endpoints (if any) are now stalled. |
|
1747 |
// In a real world program, the user could take here appropriate action (cancel a |
|
1748 |
// transfer request or whatever). |
|
1749 |
TUSB_VERBOSE_PRINT1("StallNotifier: Endpointstate 0x%x\n", iEndpointState); |
|
1750 |
Activate(); |
|
1751 |
} |
|
1752 |
||
1753 |
||
1754 |
void CActiveStallNotifier::Activate() |
|
1755 |
{ |
|
1756 |
__ASSERT_ALWAYS(!IsActive(), User::Panic(KActivePanic, 666)); |
|
1757 |
iPort->EndpointStatusNotify(iStatus, iEndpointState); |
|
1758 |
SetActive(); |
|
1759 |
} |
|
1760 |
||
1761 |
||
1762 |
// |
|
1763 |
// --- class CActiveDeviceStateNotifier --------------------------------------------------------- |
|
1764 |
// |
|
1765 |
||
1766 |
CActiveDeviceStateNotifier::CActiveDeviceStateNotifier(CConsoleBase* aConsole, RDevUsbcClient* aPort, |
|
1767 |
TBool aVerboseOutput) |
|
1768 |
: CActive(EPriorityNormal), |
|
1769 |
iConsole(aConsole), |
|
1770 |
iPort(aPort), |
|
1771 |
iDeviceState(0), |
|
1772 |
iVerbose(aVerboseOutput) |
|
1773 |
{ |
|
1774 |
CActiveScheduler::Add(this); |
|
1775 |
} |
|
1776 |
||
1777 |
CActiveDeviceStateNotifier* CActiveDeviceStateNotifier::NewL(CConsoleBase* aConsole, RDevUsbcClient* aPort, |
|
1778 |
TBool aVerboseOutput) |
|
1779 |
{ |
|
1780 |
CActiveDeviceStateNotifier* self = new (ELeave) CActiveDeviceStateNotifier(aConsole, aPort, aVerboseOutput); |
|
1781 |
CleanupStack::PushL(self); |
|
1782 |
self->ConstructL(); |
|
1783 |
CleanupStack::Pop(); // self |
|
1784 |
return self; |
|
1785 |
} |
|
1786 |
||
1787 |
||
1788 |
void CActiveDeviceStateNotifier::ConstructL() |
|
1789 |
{} |
|
1790 |
||
1791 |
||
1792 |
CActiveDeviceStateNotifier::~CActiveDeviceStateNotifier() |
|
1793 |
{ |
|
1794 |
TUSB_VERBOSE_PRINT("CActiveDeviceStateNotifier::~CActiveDeviceStateNotifier()"); |
|
1795 |
Cancel(); // base class |
|
1796 |
} |
|
1797 |
||
1798 |
||
1799 |
void CActiveDeviceStateNotifier::DoCancel() |
|
1800 |
{ |
|
1801 |
TUSB_VERBOSE_PRINT("CActiveDeviceStateNotifier::DoCancel()"); |
|
1802 |
iPort->AlternateDeviceStatusNotifyCancel(); |
|
1803 |
} |
|
1804 |
||
1805 |
||
1806 |
void CActiveDeviceStateNotifier::RunL() |
|
1807 |
{ |
|
1808 |
// This displays the device state. |
|
1809 |
// In a real world program, the user could take here appropriate action (cancel a |
|
1810 |
// transfer request or whatever). |
|
1811 |
if (!(iDeviceState & KUsbAlternateSetting) && iVerbose) |
|
1812 |
{ |
|
1813 |
switch (iDeviceState) |
|
1814 |
{ |
|
1815 |
case EUsbcDeviceStateUndefined: |
|
1816 |
TUSB_PRINT("Device State notifier: Undefined"); |
|
1817 |
break; |
|
1818 |
case EUsbcDeviceStateAttached: |
|
1819 |
TUSB_PRINT("Device State notifier: Attached"); |
|
1820 |
break; |
|
1821 |
case EUsbcDeviceStatePowered: |
|
1822 |
TUSB_PRINT("Device State notifier: Powered"); |
|
1823 |
break; |
|
1824 |
case EUsbcDeviceStateDefault: |
|
1825 |
TUSB_PRINT("Device State notifier: Default"); |
|
1826 |
break; |
|
1827 |
case EUsbcDeviceStateAddress: |
|
1828 |
TUSB_PRINT("Device State notifier: Address"); |
|
1829 |
break; |
|
1830 |
case EUsbcDeviceStateConfigured: |
|
1831 |
TUSB_PRINT("Device State notifier: Configured"); |
|
1832 |
break; |
|
1833 |
case EUsbcDeviceStateSuspended: |
|
1834 |
TUSB_PRINT("Device State notifier: Suspended"); |
|
1835 |
break; |
|
1836 |
default: |
|
1837 |
TUSB_PRINT("Device State notifier: ***BAD***"); |
|
1838 |
} |
|
1839 |
} |
|
1840 |
else if (iDeviceState & KUsbAlternateSetting) |
|
1841 |
{ |
|
1842 |
TUSB_PRINT1("Device State notifier: Alternate interface setting has changed: now %d", |
|
1843 |
iDeviceState & ~KUsbAlternateSetting); |
|
1844 |
} |
|
19
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1845 |
|
0 | 1846 |
Activate(); |
1847 |
} |
|
1848 |
||
1849 |
||
1850 |
void CActiveDeviceStateNotifier::Activate() |
|
1851 |
{ |
|
1852 |
__ASSERT_ALWAYS(!IsActive(), User::Panic(KActivePanic, 666)); |
|
1853 |
iPort->AlternateDeviceStatusNotify(iStatus, iDeviceState); |
|
1854 |
SetActive(); |
|
1855 |
} |
|
1856 |
||
1857 |
||
1858 |
// |
|
1859 |
// --- class CActiveTimer --------------------------------------------------------- |
|
1860 |
// |
|
1861 |
||
1862 |
CActiveTimer::CActiveTimer(CConsoleBase* aConsole, RDevUsbcClient* aPort, |
|
1863 |
TBool aVerboseOutput) |
|
1864 |
: CActive(EPriorityNormal), |
|
1865 |
iConsole(aConsole), |
|
1866 |
iPort(aPort), |
|
1867 |
iVerbose(aVerboseOutput) |
|
1868 |
{ |
|
1869 |
CActiveScheduler::Add(this); |
|
1870 |
} |
|
1871 |
||
1872 |
||
1873 |
CActiveTimer* CActiveTimer::NewL(CConsoleBase* aConsole, RDevUsbcClient* aPort, |
|
1874 |
TBool aVerboseOutput) |
|
1875 |
{ |
|
1876 |
CActiveTimer* self = new (ELeave) CActiveTimer(aConsole, aPort, aVerboseOutput); |
|
1877 |
CleanupStack::PushL(self); |
|
1878 |
self->ConstructL(); |
|
1879 |
CleanupStack::Pop(); // self |
|
1880 |
return self; |
|
1881 |
} |
|
1882 |
||
1883 |
||
1884 |
void CActiveTimer::ConstructL() |
|
1885 |
{ |
|
1886 |
User::LeaveIfError(iTimer.CreateLocal()); |
|
1887 |
} |
|
1888 |
||
1889 |
||
1890 |
CActiveTimer::~CActiveTimer() |
|
1891 |
{ |
|
1892 |
TUSB_VERBOSE_PRINT("CActiveTimer::~CActiveTimer()"); |
|
1893 |
Cancel(); // base class |
|
1894 |
iTimer.Close(); |
|
1895 |
} |
|
1896 |
||
1897 |
||
1898 |
void CActiveTimer::DoCancel() |
|
1899 |
{ |
|
1900 |
TUSB_VERBOSE_PRINT("CActiveTimer::DoCancel()"); |
|
1901 |
iTimer.Cancel(); |
|
1902 |
} |
|
1903 |
||
1904 |
||
1905 |
void CActiveTimer::RunL() |
|
1906 |
{ |
|
1907 |
TUSB_VERBOSE_PRINT("CActiveTimer::RunL()"); |
|
1908 |
// Nothing to do here, as we call ReadCancel() after a manual WaitForRequest() |
|
1909 |
// (in CActiveRW::ReceiveVersion()). |
|
1910 |
} |
|
1911 |
||
1912 |
||
1913 |
void CActiveTimer::Activate(TTimeIntervalMicroSeconds32 aDelay) |
|
1914 |
{ |
|
1915 |
__ASSERT_ALWAYS(!IsActive(), User::Panic(KActivePanic, 666)); |
|
1916 |
iTimer.After(iStatus, aDelay); |
|
1917 |
SetActive(); |
|
1918 |
} |
|
1919 |
||
1920 |
||
1921 |
// -eof- |