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