os/kernelhwsrv/kerneltest/e32test/device/t_usb.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     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;
    89 	TBool iDoubleBufferingChosen;
    90 	TUint32 iBandwidthPriority;
    91 	TBool iSoftwareConnect;
    92 	TBool iHighSpeed;
    93 	TBool iOtg;
    94 	TBool iVerbose;
    95 	};
    96 
    97 
    98 class CActiveTimer;
    99 
   100 class CActiveRW : public CActive
   101 	{
   102 public:
   103 	enum TXferType
   104 		{
   105 		ENone,
   106 		EPreamble,
   107 		EReadXfer,
   108 		EWriteXfer
   109 		};
   110 	static CActiveRW* NewL(CConsoleBase* aConsole, RDevUsbcClient* aPort, TBool aVerboseOutput);
   111 	~CActiveRW();
   112 	TInt ExchangeVersions();
   113 	void SendPreamble();
   114 	void SendData();
   115 	void ReadData();
   116 	void Stop();
   117 	void SetMaxBufSize(TInt aBufSz);
   118 	void SetMaxPacketSize(TInt aPktSz);
   119 	TInt MaxBufSize() const;
   120 	void SetTransferMode(TXferMode aMode);
   121 	TInt WriteToDisk(TBool aEnable);
   122 	TInt ReadFromDisk(TBool aEnable);
   123 
   124 private:
   125 	CActiveRW(CConsoleBase* aConsole, RDevUsbcClient* aPort, TBool aVerboseOutput);
   126 	void ConstructL();
   127 	virtual void RunL();
   128 	virtual void DoCancel();
   129 	TInt SendVersion();
   130 	TInt ReceiveVersion();
   131 	TBool CompareBuffers(TInt aLen);
   132 	TInt SelectDrive();
   133 	void WriteBufferToDisk(TDes8& aBuffer, TInt aLen);
   134 	void ReadBufferFromDisk(TDes8& aBuffer, TInt aLen);
   135 
   136 private:
   137 	TBuf8<KPreambleLength> iPreambleBuf;				// 2 bytes transfer length + stuffing
   138 	TBuf8<KMaxBufSize> iWriteBuf;
   139 	TBuf8<KMaxBufSize> iReadBuf;
   140 	CConsoleBase* iConsole;
   141 	RDevUsbcClient* iPort;
   142 	CActiveTimer* iTimeoutTimer;
   143 	TInt iBufSz;
   144 	TInt iMaxBufSz;
   145 	TInt iMaxPktSz;
   146 	TXferType iCurrentXfer;
   147 	TXferMode iXferMode;
   148 	TBool iDoStop;
   149 	TUint32 iPktNum;
   150 	TBool iVerbose;
   151 	TBool iDiskAccessEnabled;
   152 	RFs iFs;
   153 	RFile iFile;
   154 	TFileName iFileName;
   155 	TInt iFileOffset;
   156 	};
   157 
   158 
   159 class CActiveStallNotifier : public CActive
   160 	{
   161 public:
   162 	static CActiveStallNotifier* NewL(CConsoleBase* aConsole, RDevUsbcClient* aPort, TBool aVerboseOutput);
   163 	~CActiveStallNotifier();
   164 	void Activate();
   165 
   166 private:
   167 	CActiveStallNotifier(CConsoleBase* aConsole, RDevUsbcClient* aPort, TBool aVerboseOutput);
   168 	void ConstructL();
   169 	virtual void DoCancel();
   170 	virtual void RunL();
   171 
   172 private:
   173 	CConsoleBase* iConsole;
   174 	RDevUsbcClient* iPort;
   175 	TUint iEndpointState;
   176 	TBool iVerbose;
   177 	};
   178 
   179 
   180 class CActiveDeviceStateNotifier : public CActive
   181 	{
   182 public:
   183 	static CActiveDeviceStateNotifier* NewL(CConsoleBase* aConsole, RDevUsbcClient* aPort, TBool aVerboseOutput);
   184 	~CActiveDeviceStateNotifier();
   185 	void Activate();
   186 
   187 private:
   188 	CActiveDeviceStateNotifier(CConsoleBase* aConsole, RDevUsbcClient* aPort, TBool aVerboseOutput);
   189 	void ConstructL();
   190 	virtual void DoCancel();
   191 	virtual void RunL();
   192 
   193 private:
   194 	CConsoleBase* iConsole;
   195 	RDevUsbcClient* iPort;
   196 	TUint iDeviceState;
   197 	TBool iVerbose;
   198 	};
   199 
   200 
   201 class CActiveTimer : public CActive
   202 	{
   203 public:
   204 	static CActiveTimer* NewL(CConsoleBase* aConsole, RDevUsbcClient* aPort, TBool aVerboseOutput);
   205 	~CActiveTimer();
   206 	void Activate(TTimeIntervalMicroSeconds32 aDelay);
   207 
   208 private:
   209 	CActiveTimer(CConsoleBase* aConsole, RDevUsbcClient* aPort, TBool aVerboseOutput);
   210 	void ConstructL();
   211 	virtual void DoCancel();
   212 	virtual void RunL();
   213 
   214 private:
   215 	CConsoleBase* iConsole;
   216 	RDevUsbcClient* iPort;
   217 	RTimer iTimer;
   218 	TBool iVerbose;
   219 	};
   220 
   221 
   222 //
   223 // Helpful Defines
   224 //
   225 
   226 #define TUSB_PRINT(string) \
   227 		do { \
   228 		iConsole->Printf(_L(string)); \
   229 		iConsole->Printf(_L("\n")); \
   230 		RDebug::Print(_L(string)); \
   231 		} while (0)
   232 
   233 #define TUSB_PRINT1(string, a) \
   234 		do { \
   235 		iConsole->Printf(_L(string), (a)); \
   236 		iConsole->Printf(_L("\n")); \
   237 		RDebug::Print(_L(string), (a)); \
   238 		} while (0)
   239 
   240 #define TUSB_PRINT2(string, a, b) \
   241 		do { \
   242 		iConsole->Printf(_L(string), (a), (b)); \
   243 		iConsole->Printf(_L("\n")); \
   244 		RDebug::Print(_L(string), (a), (b)); \
   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 		RDebug::Print(_L(string), (a), (b), (c)); \
   252 		} while (0)
   253 
   254 #define TUSB_PRINT5(string, a, b, c, d, e) \
   255 		do { \
   256 		iConsole->Printf(_L(string), (a), (b), (c), (d), (e)); \
   257 		iConsole->Printf(_L("\n")); \
   258 		RDebug::Print(_L(string), (a), (b), (c), (d), (e)); \
   259 		} while (0)
   260 
   261 #define TUSB_PRINT6(string, a, b, c, d, e, f) \
   262 		do { \
   263 		iConsole->Printf(_L(string), (a), (b), (c), (d), (e), (f)); \
   264 		iConsole->Printf(_L("\n")); \
   265 		RDebug::Print(_L(string), (a), (b), (c), (d), (e), (f)); \
   266 		} while (0)
   267 
   268 #define TUSB_VERBOSE_PRINT(string) \
   269 		do { \
   270 		if (iVerbose) \
   271 			{ \
   272 			TUSB_PRINT(string); \
   273 			} \
   274 		} while (0)
   275 
   276 #define TUSB_VERBOSE_PRINT1(string, a) \
   277 		do { \
   278 		if (iVerbose) \
   279 			{ \
   280 			TUSB_PRINT1(string, a); \
   281 			} \
   282 		} while (0)
   283 
   284 #define TUSB_VERBOSE_PRINT2(string, a, b) \
   285 		do { \
   286 		if (iVerbose) \
   287 			{ \
   288 			TUSB_PRINT2(string, a, b); \
   289 			} \
   290 		} while (0)
   291 
   292 
   293 #endif	// __T_USB_H__