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) 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; |
|
19
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
89 |
TBool iAllocateDma; |
0 | 90 |
TBool iDoubleBufferingChosen; |
19
4a8fed1c0ef6
Revision: 201007
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; |
|
19
4a8fed1c0ef6
Revision: 201007
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 |
RDebug::Print(_L(string)); \ |
|
234 |
} while (0) |
|
235 |
||
236 |
#define TUSB_PRINT1(string, a) \ |
|
237 |
do { \ |
|
238 |
iConsole->Printf(_L(string), (a)); \ |
|
239 |
iConsole->Printf(_L("\n")); \ |
|
240 |
RDebug::Print(_L(string), (a)); \ |
|
241 |
} while (0) |
|
242 |
||
243 |
#define TUSB_PRINT2(string, a, b) \ |
|
244 |
do { \ |
|
245 |
iConsole->Printf(_L(string), (a), (b)); \ |
|
246 |
iConsole->Printf(_L("\n")); \ |
|
247 |
RDebug::Print(_L(string), (a), (b)); \ |
|
248 |
} while (0) |
|
249 |
||
250 |
#define TUSB_PRINT3(string, a, b, c) \ |
|
251 |
do { \ |
|
252 |
iConsole->Printf(_L(string), (a), (b), (c)); \ |
|
253 |
iConsole->Printf(_L("\n")); \ |
|
254 |
RDebug::Print(_L(string), (a), (b), (c)); \ |
|
255 |
} while (0) |
|
256 |
||
257 |
#define TUSB_PRINT5(string, a, b, c, d, e) \ |
|
258 |
do { \ |
|
259 |
iConsole->Printf(_L(string), (a), (b), (c), (d), (e)); \ |
|
260 |
iConsole->Printf(_L("\n")); \ |
|
261 |
RDebug::Print(_L(string), (a), (b), (c), (d), (e)); \ |
|
262 |
} while (0) |
|
263 |
||
264 |
#define TUSB_PRINT6(string, a, b, c, d, e, f) \ |
|
265 |
do { \ |
|
266 |
iConsole->Printf(_L(string), (a), (b), (c), (d), (e), (f)); \ |
|
267 |
iConsole->Printf(_L("\n")); \ |
|
268 |
RDebug::Print(_L(string), (a), (b), (c), (d), (e), (f)); \ |
|
269 |
} while (0) |
|
270 |
||
271 |
#define TUSB_VERBOSE_PRINT(string) \ |
|
272 |
do { \ |
|
273 |
if (iVerbose) \ |
|
274 |
{ \ |
|
275 |
TUSB_PRINT(string); \ |
|
276 |
} \ |
|
277 |
} while (0) |
|
278 |
||
279 |
#define TUSB_VERBOSE_PRINT1(string, a) \ |
|
280 |
do { \ |
|
281 |
if (iVerbose) \ |
|
282 |
{ \ |
|
283 |
TUSB_PRINT1(string, a); \ |
|
284 |
} \ |
|
285 |
} while (0) |
|
286 |
||
287 |
#define TUSB_VERBOSE_PRINT2(string, a, b) \ |
|
288 |
do { \ |
|
289 |
if (iVerbose) \ |
|
290 |
{ \ |
|
291 |
TUSB_PRINT2(string, a, b); \ |
|
292 |
} \ |
|
293 |
} while (0) |
|
294 |
||
295 |
||
296 |
#endif // __T_USB_H__ |