author | hgs |
Tue, 24 Aug 2010 14:49:21 +0100 | |
changeset 253 | d37db4dcc88d |
parent 189 | a5496987b1da |
permissions | -rw-r--r-- |
189 | 1 |
// Copyright (c) 2000-2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 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/usb/t_usb_device/src/activestatenotifier.cpp |
|
15 |
// USB Test Program T_USB_DEVICE, functional part. |
|
16 |
// Device-side part, to work against T_USB_HOST running on the host. |
|
253 | 17 |
// |
0 | 18 |
// |
19 |
||
20 |
#include "general.h" |
|
21 |
#include "activerw.h" // CActiveRW |
|
22 |
#include "config.h" |
|
23 |
#include "activeControl.h" |
|
253 | 24 |
#include "OstTraceDefinitions.h" |
25 |
#ifdef OST_TRACE_COMPILER_IN_USE |
|
26 |
#include "activedevicestatenotifierTraces.h" |
|
27 |
#endif |
|
0 | 28 |
#include "activedevicestatenotifier.h" |
29 |
||
30 |
extern CActiveControl* gActiveControl; |
|
31 |
extern RTest test; |
|
32 |
extern TBool gVerbose; |
|
33 |
extern TBool gSkip; |
|
34 |
extern TBool gStopOnFail; |
|
35 |
extern TBool gAltSettingOnNotify; |
|
36 |
extern TInt gSoakCount; |
|
37 |
extern CActiveRW* gRW[KMaxConcurrentTests]; // the USB read/write active object |
|
38 |
extern IFConfigPtr gInterfaceConfig [128] [KMaxInterfaceSettings]; |
|
39 |
||
40 |
// |
|
41 |
// --- class CActiveDeviceStateNotifier --------------------------------------------------------- |
|
42 |
// |
|
43 |
||
44 |
CActiveDeviceStateNotifier::CActiveDeviceStateNotifier(CConsoleBase* aConsole, RDEVCLIENT* aPort, TUint aPortNumber) |
|
45 |
: CActive(EPriorityNormal), |
|
46 |
iConsole(aConsole), |
|
47 |
iPort(aPort), |
|
48 |
iDeviceState(0), |
|
49 |
iPortNumber(aPortNumber) |
|
50 |
{ |
|
51 |
CActiveScheduler::Add(this); |
|
52 |
} |
|
53 |
||
54 |
CActiveDeviceStateNotifier* CActiveDeviceStateNotifier::NewL(CConsoleBase* aConsole, RDEVCLIENT* aPort, TUint aPortNumber) |
|
55 |
{ |
|
56 |
CActiveDeviceStateNotifier* self = new (ELeave) CActiveDeviceStateNotifier(aConsole, aPort, aPortNumber); |
|
57 |
CleanupStack::PushL(self); |
|
58 |
self->ConstructL(); |
|
59 |
CleanupStack::Pop(); // self |
|
60 |
return self; |
|
61 |
} |
|
62 |
||
63 |
||
64 |
void CActiveDeviceStateNotifier::ConstructL() |
|
65 |
{} |
|
66 |
||
67 |
||
68 |
CActiveDeviceStateNotifier::~CActiveDeviceStateNotifier() |
|
69 |
{ |
|
70 |
TUSB_VERBOSE_PRINT("CActiveDeviceStateNotifier::~CActiveDeviceStateNotifier()"); |
|
253 | 71 |
if(gVerbose) |
72 |
{ |
|
73 |
OstTrace0(TRACE_VERBOSE, CACTIVEDEVICESTATENOTIFIER_DCACTIVEDEVICESTATENOTIFIER, "CActiveDeviceStateNotifier::~CActiveDeviceStateNotifier()"); |
|
74 |
} |
|
0 | 75 |
Cancel(); // base class |
76 |
} |
|
77 |
||
78 |
||
79 |
void CActiveDeviceStateNotifier::DoCancel() |
|
80 |
{ |
|
81 |
TUSB_VERBOSE_PRINT("CActiveDeviceStateNotifier::DoCancel()"); |
|
253 | 82 |
if(gVerbose) |
83 |
{ |
|
84 |
OstTrace0(TRACE_VERBOSE, CACTIVEDEVICESTATENOTIFIER_DOCANCEL, "CActiveDeviceStateNotifier::DoCancel()"); |
|
85 |
} |
|
0 | 86 |
iPort->AlternateDeviceStatusNotifyCancel(); |
87 |
} |
|
88 |
||
89 |
||
90 |
void CActiveDeviceStateNotifier::RunL() |
|
91 |
{ |
|
92 |
// This displays the device state. |
|
93 |
// In a real world program, the user could take here appropriate action (cancel a |
|
94 |
// transfer request or whatever). |
|
95 |
if (!(iDeviceState & KUsbAlternateSetting) && gVerbose) |
|
96 |
{ |
|
97 |
switch (iDeviceState) |
|
98 |
{ |
|
99 |
case EUsbcDeviceStateUndefined: |
|
189 | 100 |
#ifdef USB_SC |
101 |
TUSB_PRINT("Device State notifier: Undefined0"); |
|
253 | 102 |
OstTrace0(TRACE_NORMAL, CACTIVEDEVICESTATENOTIFIER_RUNL, "Device State notifier: Undefined0"); |
189 | 103 |
for (TUint16 i =0; i < KMaxConcurrentTests; i++) |
104 |
{ |
|
105 |
if (gRW[i]) |
|
106 |
{ |
|
107 |
TUSB_VERBOSE_PRINT2("ResetAltSetting index %d, LDD %x",i, gRW[i]->Ldd()); |
|
253 | 108 |
if(gVerbose) |
109 |
{ |
|
110 |
OstTraceExt2(TRACE_VERBOSE, CACTIVEDEVICESTATENOTIFIER_RUNL_DUP01, "ResetAltSetting index %u, LDD %x",(TUint32)i, (TUint32)gRW[i]->Ldd()); |
|
111 |
} |
|
112 |
gRW[i]->Ldd()->ResetAltSetting(); |
|
189 | 113 |
} |
114 |
} |
|
115 |
#endif |
|
0 | 116 |
TUSB_PRINT("Device State notifier: Undefined"); |
253 | 117 |
OstTrace0(TRACE_NORMAL, CACTIVEDEVICESTATENOTIFIER_RUNL_DUP02, "Device State notifier: Undefined"); |
0 | 118 |
break; |
119 |
case EUsbcDeviceStateAttached: |
|
120 |
TUSB_PRINT("Device State notifier: Attached"); |
|
253 | 121 |
OstTrace0(TRACE_NORMAL, CACTIVEDEVICESTATENOTIFIER_RUNL_DUP03, "Device State notifier: Attached"); |
0 | 122 |
break; |
123 |
case EUsbcDeviceStatePowered: |
|
124 |
TUSB_PRINT("Device State notifier: Powered"); |
|
253 | 125 |
OstTrace0(TRACE_NORMAL, CACTIVEDEVICESTATENOTIFIER_RUNL_DUP04, "Device State notifier: Powered"); |
0 | 126 |
break; |
127 |
case EUsbcDeviceStateDefault: |
|
128 |
TUSB_PRINT("Device State notifier: Default"); |
|
253 | 129 |
OstTrace0(TRACE_NORMAL, CACTIVEDEVICESTATENOTIFIER_RUNL_DUP05, "Device State notifier: Default"); |
0 | 130 |
break; |
131 |
case EUsbcDeviceStateAddress: |
|
132 |
TUSB_PRINT("Device State notifier: Address"); |
|
253 | 133 |
OstTrace0(TRACE_NORMAL, CACTIVEDEVICESTATENOTIFIER_RUNL_DUP06, "Device State notifier: Address"); |
0 | 134 |
break; |
135 |
case EUsbcDeviceStateConfigured: |
|
136 |
TUSB_PRINT("Device State notifier: Configured"); |
|
253 | 137 |
OstTrace0(TRACE_NORMAL, CACTIVEDEVICESTATENOTIFIER_RUNL_DUP07, "Device State notifier: Configured"); |
0 | 138 |
break; |
139 |
case EUsbcDeviceStateSuspended: |
|
140 |
TUSB_PRINT("Device State notifier: Suspended"); |
|
253 | 141 |
OstTrace0(TRACE_NORMAL, CACTIVEDEVICESTATENOTIFIER_RUNL_DUP08, "Device State notifier: Suspended"); |
0 | 142 |
break; |
143 |
default: |
|
144 |
TUSB_PRINT("Device State notifier: ***BAD***"); |
|
253 | 145 |
OstTrace0(TRACE_NORMAL, CACTIVEDEVICESTATENOTIFIER_RUNL_DUP09, "Device State notifier: ***BAD***"); |
0 | 146 |
} |
147 |
} |
|
148 |
else if (iDeviceState & KUsbAlternateSetting) |
|
149 |
{ |
|
150 |
TUint8 altSetting = iDeviceState & ~KUsbAlternateSetting; |
|
151 |
TUSB_PRINT2("Device State notifier: Alternate interface %d setting has changed: now %d", |
|
152 |
iPortNumber, altSetting); |
|
253 | 153 |
OstTraceExt2(TRACE_NORMAL, CACTIVEDEVICESTATENOTIFIER_RUNL_DUP10, "Device State notifier: Alternate interface %u setting has changed: now %u", |
154 |
(TUint32)iPortNumber, (TUint32)altSetting); |
|
155 |
||
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
156 |
TUsbDeviceCaps dCaps; |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
157 |
iPort->DeviceCaps(dCaps); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
158 |
TBool isResourceAllocationV2 = ((dCaps().iFeatureWord1 & KUsbDevCapsFeatureWord1_EndpointResourceAllocV2) != 0); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
159 |
if (!isResourceAllocationV2) |
0 | 160 |
{ |
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
161 |
// allocate endpoint DMA and double buffering for all endpoints on interface for resource allocation v1 |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
162 |
// if resource allocation v2, refer to CActiveControl::ConstructL and CActiveControl::PopulateInterfaceResourceAllocation |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
163 |
for (TUint8 ifNumber = 0; ifNumber < 128; ifNumber++) |
0 | 164 |
{ |
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
165 |
IFConfigPtr newIfPtr = gInterfaceConfig[ifNumber][altSetting]; |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
166 |
if (newIfPtr) |
0 | 167 |
{ |
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
168 |
if (newIfPtr->iPortNumber == iPortNumber) |
0 | 169 |
{ |
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
170 |
// allocate endpoint DMA and double buffering for all endpoints on default interface |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
171 |
for (TUint8 i = 1; i <= newIfPtr->iInfoPtr->iTotalEndpointsUsed; i++) |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
172 |
{ |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
173 |
newIfPtr->iEpDMA[i-1] ? gActiveControl->AllocateEndpointDMA(iPort,(TENDPOINTNUMBER)i) : gActiveControl->DeAllocateEndpointDMA(iPort,(TENDPOINTNUMBER)i); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
174 |
#ifndef USB_SC |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
175 |
newIfPtr->iEpDoubleBuff[i-1] ? gActiveControl->AllocateDoubleBuffering(iPort,(TENDPOINTNUMBER)i) : gActiveControl->DeAllocateDoubleBuffering(iPort,(TENDPOINTNUMBER)i); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
176 |
#endif |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
177 |
} |
253 | 178 |
break; |
0 | 179 |
} |
180 |
} |
|
181 |
} |
|
253 | 182 |
} |
183 |
||
0 | 184 |
if (gAltSettingOnNotify) |
185 |
{ |
|
186 |
for (TUint16 i =0; i < KMaxConcurrentTests; i++) |
|
187 |
{ |
|
188 |
if (gRW[i]) |
|
189 |
{ |
|
190 |
TUSB_VERBOSE_PRINT1("Resuming alternate Setting - activeRW index %d",i); |
|
253 | 191 |
if(gVerbose) |
192 |
{ |
|
193 |
OstTrace1(TRACE_VERBOSE, CACTIVEDEVICESTATENOTIFIER_RUNL_DUP11, "Resuming alternate Setting - activeRW index %d",i); |
|
194 |
} |
|
195 |
gRW[i]->ResumeAltSetting(altSetting); |
|
0 | 196 |
} |
197 |
} |
|
198 |
} |
|
199 |
} |
|
200 |
Activate(); |
|
201 |
} |
|
202 |
||
203 |
||
204 |
void CActiveDeviceStateNotifier::Activate() |
|
205 |
{ |
|
206 |
__ASSERT_ALWAYS(!IsActive(), User::Panic(KActivePanic, 661)); |
|
207 |
iPort->AlternateDeviceStatusNotify(iStatus, iDeviceState); |
|
208 |
SetActive(); |
|
209 |
} |
|
210 |
||
211 |
||
212 |
// -eof- |