1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/device/t_usb.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,293 @@
1.4 +// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// e32test\device\t_usb.h
1.18 +//
1.19 +//
1.20 +
1.21 +#ifndef __T_USB_H__
1.22 +#define __T_USB_H__
1.23 +
1.24 +#include <e32cons.h>
1.25 +#include <e32svr.h>
1.26 +#include <e32std.h>
1.27 +#include <f32file.h>
1.28 +
1.29 +#include <d32usbc.h>
1.30 +#include <d32otgdi.h>
1.31 +
1.32 +
1.33 +static const TInt KMaxBufSize = 1024 * 1024; // max data buffer size: 1MB
1.34 +static const TInt KPreambleLength = 8; // length of preamble data (bytes)
1.35 +
1.36 +
1.37 +enum TXferMode
1.38 + {
1.39 + ENone,
1.40 + ELoop,
1.41 + ELoopComp,
1.42 + EReceiveOnly,
1.43 + ETransmitOnly
1.44 + };
1.45 +
1.46 +
1.47 +class CActiveRW;
1.48 +class CActiveStallNotifier;
1.49 +class CActiveDeviceStateNotifier;
1.50 +
1.51 +class CActiveConsole : public CActive
1.52 + {
1.53 +public:
1.54 + static CActiveConsole* NewLC(CConsoleBase* aConsole, TBool aVerboseOutput);
1.55 + static CActiveConsole* NewL(CConsoleBase* aConsole, TBool aVerboseOutput);
1.56 + void ConstructL();
1.57 + ~CActiveConsole();
1.58 + TInt SetupInterface();
1.59 + void RequestCharacter();
1.60 +
1.61 +private:
1.62 + CActiveConsole(CConsoleBase* aConsole, TBool aVerboseOutput);
1.63 + // Defined as pure virtual by CActive;
1.64 + // implementation provided by this class.
1.65 + virtual void DoCancel();
1.66 + // Defined as pure virtual by CActive;
1.67 + // implementation provided by this class,
1.68 + virtual void RunL();
1.69 + void ProcessKeyPressL(TChar aChar);
1.70 + TInt QueryUsbClientL();
1.71 + void AllocateEndpointDMA(TEndpointNumber aEndpoint);
1.72 + void AllocateDoubleBuffering(TEndpointNumber aEndpoint);
1.73 + void DeAllocateEndpointDMA(TEndpointNumber aEndpoint);
1.74 + void DeAllocateDoubleBuffering(TEndpointNumber aEndpoint);
1.75 + void QueryEndpointState(TEndpointNumber aEndpoint);
1.76 +#ifdef WITH_DUMP_OPTION
1.77 + void QueryRxBuffer();
1.78 +#endif
1.79 + TInt SetupDescriptors();
1.80 + TInt ReEnumerate();
1.81 +
1.82 +private:
1.83 + CConsoleBase* iConsole; // a console to read from
1.84 + CActiveRW* iRW; // the USB read/write active object
1.85 + CActiveStallNotifier* iStallNotifier;
1.86 + CActiveDeviceStateNotifier* iDeviceStateNotifier;
1.87 + RDevUsbcClient iPort;
1.88 + RUsbOtgDriver iOtgPort;
1.89 + TBool iBufferSizeChosen;
1.90 + TBool iBandwidthPriorityChosen;
1.91 + TBool iDMAChosen;
1.92 + TBool iDoubleBufferingChosen;
1.93 + TUint32 iBandwidthPriority;
1.94 + TBool iSoftwareConnect;
1.95 + TBool iHighSpeed;
1.96 + TBool iOtg;
1.97 + TBool iVerbose;
1.98 + };
1.99 +
1.100 +
1.101 +class CActiveTimer;
1.102 +
1.103 +class CActiveRW : public CActive
1.104 + {
1.105 +public:
1.106 + enum TXferType
1.107 + {
1.108 + ENone,
1.109 + EPreamble,
1.110 + EReadXfer,
1.111 + EWriteXfer
1.112 + };
1.113 + static CActiveRW* NewL(CConsoleBase* aConsole, RDevUsbcClient* aPort, TBool aVerboseOutput);
1.114 + ~CActiveRW();
1.115 + TInt ExchangeVersions();
1.116 + void SendPreamble();
1.117 + void SendData();
1.118 + void ReadData();
1.119 + void Stop();
1.120 + void SetMaxBufSize(TInt aBufSz);
1.121 + void SetMaxPacketSize(TInt aPktSz);
1.122 + TInt MaxBufSize() const;
1.123 + void SetTransferMode(TXferMode aMode);
1.124 + TInt WriteToDisk(TBool aEnable);
1.125 + TInt ReadFromDisk(TBool aEnable);
1.126 +
1.127 +private:
1.128 + CActiveRW(CConsoleBase* aConsole, RDevUsbcClient* aPort, TBool aVerboseOutput);
1.129 + void ConstructL();
1.130 + virtual void RunL();
1.131 + virtual void DoCancel();
1.132 + TInt SendVersion();
1.133 + TInt ReceiveVersion();
1.134 + TBool CompareBuffers(TInt aLen);
1.135 + TInt SelectDrive();
1.136 + void WriteBufferToDisk(TDes8& aBuffer, TInt aLen);
1.137 + void ReadBufferFromDisk(TDes8& aBuffer, TInt aLen);
1.138 +
1.139 +private:
1.140 + TBuf8<KPreambleLength> iPreambleBuf; // 2 bytes transfer length + stuffing
1.141 + TBuf8<KMaxBufSize> iWriteBuf;
1.142 + TBuf8<KMaxBufSize> iReadBuf;
1.143 + CConsoleBase* iConsole;
1.144 + RDevUsbcClient* iPort;
1.145 + CActiveTimer* iTimeoutTimer;
1.146 + TInt iBufSz;
1.147 + TInt iMaxBufSz;
1.148 + TInt iMaxPktSz;
1.149 + TXferType iCurrentXfer;
1.150 + TXferMode iXferMode;
1.151 + TBool iDoStop;
1.152 + TUint32 iPktNum;
1.153 + TBool iVerbose;
1.154 + TBool iDiskAccessEnabled;
1.155 + RFs iFs;
1.156 + RFile iFile;
1.157 + TFileName iFileName;
1.158 + TInt iFileOffset;
1.159 + };
1.160 +
1.161 +
1.162 +class CActiveStallNotifier : public CActive
1.163 + {
1.164 +public:
1.165 + static CActiveStallNotifier* NewL(CConsoleBase* aConsole, RDevUsbcClient* aPort, TBool aVerboseOutput);
1.166 + ~CActiveStallNotifier();
1.167 + void Activate();
1.168 +
1.169 +private:
1.170 + CActiveStallNotifier(CConsoleBase* aConsole, RDevUsbcClient* aPort, TBool aVerboseOutput);
1.171 + void ConstructL();
1.172 + virtual void DoCancel();
1.173 + virtual void RunL();
1.174 +
1.175 +private:
1.176 + CConsoleBase* iConsole;
1.177 + RDevUsbcClient* iPort;
1.178 + TUint iEndpointState;
1.179 + TBool iVerbose;
1.180 + };
1.181 +
1.182 +
1.183 +class CActiveDeviceStateNotifier : public CActive
1.184 + {
1.185 +public:
1.186 + static CActiveDeviceStateNotifier* NewL(CConsoleBase* aConsole, RDevUsbcClient* aPort, TBool aVerboseOutput);
1.187 + ~CActiveDeviceStateNotifier();
1.188 + void Activate();
1.189 +
1.190 +private:
1.191 + CActiveDeviceStateNotifier(CConsoleBase* aConsole, RDevUsbcClient* aPort, TBool aVerboseOutput);
1.192 + void ConstructL();
1.193 + virtual void DoCancel();
1.194 + virtual void RunL();
1.195 +
1.196 +private:
1.197 + CConsoleBase* iConsole;
1.198 + RDevUsbcClient* iPort;
1.199 + TUint iDeviceState;
1.200 + TBool iVerbose;
1.201 + };
1.202 +
1.203 +
1.204 +class CActiveTimer : public CActive
1.205 + {
1.206 +public:
1.207 + static CActiveTimer* NewL(CConsoleBase* aConsole, RDevUsbcClient* aPort, TBool aVerboseOutput);
1.208 + ~CActiveTimer();
1.209 + void Activate(TTimeIntervalMicroSeconds32 aDelay);
1.210 +
1.211 +private:
1.212 + CActiveTimer(CConsoleBase* aConsole, RDevUsbcClient* aPort, TBool aVerboseOutput);
1.213 + void ConstructL();
1.214 + virtual void DoCancel();
1.215 + virtual void RunL();
1.216 +
1.217 +private:
1.218 + CConsoleBase* iConsole;
1.219 + RDevUsbcClient* iPort;
1.220 + RTimer iTimer;
1.221 + TBool iVerbose;
1.222 + };
1.223 +
1.224 +
1.225 +//
1.226 +// Helpful Defines
1.227 +//
1.228 +
1.229 +#define TUSB_PRINT(string) \
1.230 + do { \
1.231 + iConsole->Printf(_L(string)); \
1.232 + iConsole->Printf(_L("\n")); \
1.233 + RDebug::Print(_L(string)); \
1.234 + } while (0)
1.235 +
1.236 +#define TUSB_PRINT1(string, a) \
1.237 + do { \
1.238 + iConsole->Printf(_L(string), (a)); \
1.239 + iConsole->Printf(_L("\n")); \
1.240 + RDebug::Print(_L(string), (a)); \
1.241 + } while (0)
1.242 +
1.243 +#define TUSB_PRINT2(string, a, b) \
1.244 + do { \
1.245 + iConsole->Printf(_L(string), (a), (b)); \
1.246 + iConsole->Printf(_L("\n")); \
1.247 + RDebug::Print(_L(string), (a), (b)); \
1.248 + } while (0)
1.249 +
1.250 +#define TUSB_PRINT3(string, a, b, c) \
1.251 + do { \
1.252 + iConsole->Printf(_L(string), (a), (b), (c)); \
1.253 + iConsole->Printf(_L("\n")); \
1.254 + RDebug::Print(_L(string), (a), (b), (c)); \
1.255 + } while (0)
1.256 +
1.257 +#define TUSB_PRINT5(string, a, b, c, d, e) \
1.258 + do { \
1.259 + iConsole->Printf(_L(string), (a), (b), (c), (d), (e)); \
1.260 + iConsole->Printf(_L("\n")); \
1.261 + RDebug::Print(_L(string), (a), (b), (c), (d), (e)); \
1.262 + } while (0)
1.263 +
1.264 +#define TUSB_PRINT6(string, a, b, c, d, e, f) \
1.265 + do { \
1.266 + iConsole->Printf(_L(string), (a), (b), (c), (d), (e), (f)); \
1.267 + iConsole->Printf(_L("\n")); \
1.268 + RDebug::Print(_L(string), (a), (b), (c), (d), (e), (f)); \
1.269 + } while (0)
1.270 +
1.271 +#define TUSB_VERBOSE_PRINT(string) \
1.272 + do { \
1.273 + if (iVerbose) \
1.274 + { \
1.275 + TUSB_PRINT(string); \
1.276 + } \
1.277 + } while (0)
1.278 +
1.279 +#define TUSB_VERBOSE_PRINT1(string, a) \
1.280 + do { \
1.281 + if (iVerbose) \
1.282 + { \
1.283 + TUSB_PRINT1(string, a); \
1.284 + } \
1.285 + } while (0)
1.286 +
1.287 +#define TUSB_VERBOSE_PRINT2(string, a, b) \
1.288 + do { \
1.289 + if (iVerbose) \
1.290 + { \
1.291 + TUSB_PRINT2(string, a, b); \
1.292 + } \
1.293 + } while (0)
1.294 +
1.295 +
1.296 +#endif // __T_USB_H__