author | hgs |
Mon, 13 Sep 2010 15:16:07 +0100 | |
changeset 269 | d57b86b1867a |
parent 253 | d37db4dcc88d |
child 257 | 3e88ff8f41d5 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). |
2 |
// All rights reserved. |
|
3 |
// This component and the accompanying materials are made available |
|
4 |
// under the terms of the License "Eclipse Public License v1.0" |
|
5 |
// which accompanies this distribution, and is available |
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 |
// |
|
8 |
// Initial Contributors: |
|
9 |
// Nokia Corporation - initial contribution. |
|
10 |
// |
|
11 |
// Contributors: |
|
12 |
// |
|
13 |
// Description: |
|
14 |
// e32test\device\t_usb.h |
|
15 |
// |
|
16 |
// |
|
17 |
||
18 |
#ifndef __T_USB_H__ |
|
19 |
#define __T_USB_H__ |
|
20 |
||
21 |
#include <e32cons.h> |
|
22 |
#include <e32svr.h> |
|
23 |
#include <e32std.h> |
|
24 |
#include <f32file.h> |
|
25 |
||
26 |
#include <d32usbc.h> |
|
27 |
#include <d32otgdi.h> |
|
28 |
||
29 |
||
30 |
static const TInt KMaxBufSize = 1024 * 1024; // max data buffer size: 1MB |
|
31 |
static const TInt KPreambleLength = 8; // length of preamble data (bytes) |
|
32 |
||
33 |
||
34 |
enum TXferMode |
|
35 |
{ |
|
36 |
ENone, |
|
37 |
ELoop, |
|
38 |
ELoopComp, |
|
39 |
EReceiveOnly, |
|
40 |
ETransmitOnly |
|
41 |
}; |
|
42 |
||
43 |
||
44 |
class CActiveRW; |
|
45 |
class CActiveStallNotifier; |
|
46 |
class CActiveDeviceStateNotifier; |
|
47 |
||
48 |
class CActiveConsole : public CActive |
|
49 |
{ |
|
50 |
public: |
|
51 |
static CActiveConsole* NewLC(CConsoleBase* aConsole, TBool aVerboseOutput); |
|
52 |
static CActiveConsole* NewL(CConsoleBase* aConsole, TBool aVerboseOutput); |
|
53 |
void ConstructL(); |
|
54 |
~CActiveConsole(); |
|
55 |
TInt SetupInterface(); |
|
56 |
void RequestCharacter(); |
|
57 |
||
58 |
private: |
|
59 |
CActiveConsole(CConsoleBase* aConsole, TBool aVerboseOutput); |
|
60 |
// Defined as pure virtual by CActive; |
|
61 |
// implementation provided by this class. |
|
62 |
virtual void DoCancel(); |
|
63 |
// Defined as pure virtual by CActive; |
|
64 |
// implementation provided by this class, |
|
65 |
virtual void RunL(); |
|
66 |
void ProcessKeyPressL(TChar aChar); |
|
67 |
TInt QueryUsbClientL(); |
|
68 |
void AllocateEndpointDMA(TEndpointNumber aEndpoint); |
|
69 |
void AllocateDoubleBuffering(TEndpointNumber aEndpoint); |
|
70 |
void DeAllocateEndpointDMA(TEndpointNumber aEndpoint); |
|
71 |
void DeAllocateDoubleBuffering(TEndpointNumber aEndpoint); |
|
72 |
void QueryEndpointState(TEndpointNumber aEndpoint); |
|
73 |
#ifdef WITH_DUMP_OPTION |
|
74 |
void QueryRxBuffer(); |
|
75 |
#endif |
|
76 |
TInt SetupDescriptors(); |
|
77 |
TInt ReEnumerate(); |
|
78 |
||
79 |
private: |
|
80 |
CConsoleBase* iConsole; // a console to read from |
|
81 |
CActiveRW* iRW; // the USB read/write active object |
|
82 |
CActiveStallNotifier* iStallNotifier; |
|
83 |
CActiveDeviceStateNotifier* iDeviceStateNotifier; |
|
84 |
RDevUsbcClient iPort; |
|
85 |
RUsbOtgDriver iOtgPort; |
|
86 |
TBool iBufferSizeChosen; |
|
87 |
TBool iBandwidthPriorityChosen; |
|
88 |
TBool iDMAChosen; |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
89 |
TBool iAllocateDma; |
0 | 90 |
TBool iDoubleBufferingChosen; |
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
91 |
TBool iAllocateDoubleBuffering; |
0 | 92 |
TUint32 iBandwidthPriority; |
93 |
TBool iSoftwareConnect; |
|
94 |
TBool iHighSpeed; |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
95 |
TBool iResourceAllocationV2; |
0 | 96 |
TBool iOtg; |
97 |
TBool iVerbose; |
|
98 |
}; |
|
99 |
||
100 |
||
101 |
class CActiveTimer; |
|
102 |
||
103 |
class CActiveRW : public CActive |
|
104 |
{ |
|
105 |
public: |
|
106 |
enum TXferType |
|
107 |
{ |
|
108 |
ENone, |
|
109 |
EPreamble, |
|
110 |
EReadXfer, |
|
111 |
EWriteXfer |
|
112 |
}; |
|
113 |
static CActiveRW* NewL(CConsoleBase* aConsole, RDevUsbcClient* aPort, TBool aVerboseOutput); |
|
114 |
~CActiveRW(); |
|
115 |
TInt ExchangeVersions(); |
|
116 |
void SendPreamble(); |
|
117 |
void SendData(); |
|
118 |
void ReadData(); |
|
119 |
void Stop(); |
|
120 |
void SetMaxBufSize(TInt aBufSz); |
|
121 |
void SetMaxPacketSize(TInt aPktSz); |
|
122 |
TInt MaxBufSize() const; |
|
123 |
void SetTransferMode(TXferMode aMode); |
|
124 |
TInt WriteToDisk(TBool aEnable); |
|
125 |
TInt ReadFromDisk(TBool aEnable); |
|
126 |
||
127 |
private: |
|
128 |
CActiveRW(CConsoleBase* aConsole, RDevUsbcClient* aPort, TBool aVerboseOutput); |
|
129 |
void ConstructL(); |
|
130 |
virtual void RunL(); |
|
131 |
virtual void DoCancel(); |
|
132 |
TInt SendVersion(); |
|
133 |
TInt ReceiveVersion(); |
|
134 |
TBool CompareBuffers(TInt aLen); |
|
135 |
TInt SelectDrive(); |
|
136 |
void WriteBufferToDisk(TDes8& aBuffer, TInt aLen); |
|
137 |
void ReadBufferFromDisk(TDes8& aBuffer, TInt aLen); |
|
138 |
||
139 |
private: |
|
140 |
TBuf8<KPreambleLength> iPreambleBuf; // 2 bytes transfer length + stuffing |
|
141 |
TBuf8<KMaxBufSize> iWriteBuf; |
|
142 |
TBuf8<KMaxBufSize> iReadBuf; |
|
143 |
CConsoleBase* iConsole; |
|
144 |
RDevUsbcClient* iPort; |
|
145 |
CActiveTimer* iTimeoutTimer; |
|
146 |
TInt iBufSz; |
|
147 |
TInt iMaxBufSz; |
|
148 |
TInt iMaxPktSz; |
|
149 |
TXferType iCurrentXfer; |
|
150 |
TXferMode iXferMode; |
|
151 |
TBool iDoStop; |
|
152 |
TUint32 iPktNum; |
|
153 |
TBool iVerbose; |
|
154 |
TBool iDiskAccessEnabled; |
|
155 |
RFs iFs; |
|
156 |
RFile iFile; |
|
157 |
TFileName iFileName; |
|
158 |
TInt iFileOffset; |
|
159 |
}; |
|
160 |
||
161 |
||
162 |
class CActiveStallNotifier : public CActive |
|
163 |
{ |
|
164 |
public: |
|
165 |
static CActiveStallNotifier* NewL(CConsoleBase* aConsole, RDevUsbcClient* aPort, TBool aVerboseOutput); |
|
166 |
~CActiveStallNotifier(); |
|
167 |
void Activate(); |
|
168 |
||
169 |
private: |
|
170 |
CActiveStallNotifier(CConsoleBase* aConsole, RDevUsbcClient* aPort, TBool aVerboseOutput); |
|
171 |
void ConstructL(); |
|
172 |
virtual void DoCancel(); |
|
173 |
virtual void RunL(); |
|
174 |
||
175 |
private: |
|
176 |
CConsoleBase* iConsole; |
|
177 |
RDevUsbcClient* iPort; |
|
178 |
TUint iEndpointState; |
|
179 |
TBool iVerbose; |
|
180 |
}; |
|
181 |
||
182 |
||
183 |
class CActiveDeviceStateNotifier : public CActive |
|
184 |
{ |
|
185 |
public: |
|
186 |
static CActiveDeviceStateNotifier* NewL(CConsoleBase* aConsole, RDevUsbcClient* aPort, TBool aVerboseOutput); |
|
187 |
~CActiveDeviceStateNotifier(); |
|
188 |
void Activate(); |
|
189 |
||
190 |
private: |
|
191 |
CActiveDeviceStateNotifier(CConsoleBase* aConsole, RDevUsbcClient* aPort, TBool aVerboseOutput); |
|
192 |
void ConstructL(); |
|
193 |
virtual void DoCancel(); |
|
194 |
virtual void RunL(); |
|
195 |
||
196 |
private: |
|
197 |
CConsoleBase* iConsole; |
|
198 |
RDevUsbcClient* iPort; |
|
199 |
TUint iDeviceState; |
|
200 |
TBool iVerbose; |
|
201 |
}; |
|
202 |
||
203 |
||
204 |
class CActiveTimer : public CActive |
|
205 |
{ |
|
206 |
public: |
|
207 |
static CActiveTimer* NewL(CConsoleBase* aConsole, RDevUsbcClient* aPort, TBool aVerboseOutput); |
|
208 |
~CActiveTimer(); |
|
209 |
void Activate(TTimeIntervalMicroSeconds32 aDelay); |
|
210 |
||
211 |
private: |
|
212 |
CActiveTimer(CConsoleBase* aConsole, RDevUsbcClient* aPort, TBool aVerboseOutput); |
|
213 |
void ConstructL(); |
|
214 |
virtual void DoCancel(); |
|
215 |
virtual void RunL(); |
|
216 |
||
217 |
private: |
|
218 |
CConsoleBase* iConsole; |
|
219 |
RDevUsbcClient* iPort; |
|
220 |
RTimer iTimer; |
|
221 |
TBool iVerbose; |
|
222 |
}; |
|
223 |
||
224 |
||
225 |
// |
|
226 |
// Helpful Defines |
|
227 |
// |
|
228 |
||
229 |
#define TUSB_PRINT(string) \ |
|
230 |
do { \ |
|
231 |
iConsole->Printf(_L(string)); \ |
|
232 |
iConsole->Printf(_L("\n")); \ |
|
233 |
} while (0) |
|
234 |
||
235 |
#define TUSB_PRINT1(string, a) \ |
|
236 |
do { \ |
|
237 |
iConsole->Printf(_L(string), (a)); \ |
|
238 |
iConsole->Printf(_L("\n")); \ |
|
239 |
} while (0) |
|
240 |
||
241 |
#define TUSB_PRINT2(string, a, b) \ |
|
242 |
do { \ |
|
243 |
iConsole->Printf(_L(string), (a), (b)); \ |
|
244 |
iConsole->Printf(_L("\n")); \ |
|
245 |
} while (0) |
|
246 |
||
247 |
#define TUSB_PRINT3(string, a, b, c) \ |
|
248 |
do { \ |
|
249 |
iConsole->Printf(_L(string), (a), (b), (c)); \ |
|
250 |
iConsole->Printf(_L("\n")); \ |
|
251 |
} while (0) |
|
252 |
||
253 |
#define TUSB_PRINT5(string, a, b, c, d, e) \ |
|
254 |
do { \ |
|
255 |
iConsole->Printf(_L(string), (a), (b), (c), (d), (e)); \ |
|
256 |
iConsole->Printf(_L("\n")); \ |
|
257 |
} while (0) |
|
258 |
||
259 |
#define TUSB_PRINT6(string, a, b, c, d, e, f) \ |
|
260 |
do { \ |
|
261 |
iConsole->Printf(_L(string), (a), (b), (c), (d), (e), (f)); \ |
|
262 |
iConsole->Printf(_L("\n")); \ |
|
263 |
} while (0) |
|
264 |
||
265 |
#define TUSB_VERBOSE_PRINT(string) \ |
|
266 |
do { \ |
|
267 |
if (iVerbose) \ |
|
268 |
{ \ |
|
269 |
TUSB_PRINT(string); \ |
|
270 |
} \ |
|
271 |
} while (0) |
|
272 |
||
273 |
#define TUSB_VERBOSE_PRINT1(string, a) \ |
|
274 |
do { \ |
|
275 |
if (iVerbose) \ |
|
276 |
{ \ |
|
277 |
TUSB_PRINT1(string, a); \ |
|
278 |
} \ |
|
279 |
} while (0) |
|
280 |
||
281 |
#define TUSB_VERBOSE_PRINT2(string, a, b) \ |
|
282 |
do { \ |
|
283 |
if (iVerbose) \ |
|
284 |
{ \ |
|
285 |
TUSB_PRINT2(string, a, b); \ |
|
286 |
} \ |
|
287 |
} while (0) |
|
288 |
||
289 |
||
290 |
#endif // __T_USB_H__ |