author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Wed, 18 Aug 2010 11:08:29 +0300 | |
changeset 247 | d8d70de2bd36 |
parent 90 | 947f0dc9f7a8 |
child 253 | d37db4dcc88d |
permissions | -rw-r--r-- |
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
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. |
|
17 |
// |
|
18 |
// |
|
19 |
||
20 |
#include "general.h" |
|
21 |
#include "activerw.h" // CActiveRW |
|
22 |
#include "config.h" |
|
23 |
#include "activeControl.h" |
|
24 |
#include "activedevicestatenotifier.h" |
|
25 |
||
26 |
extern CActiveControl* gActiveControl; |
|
27 |
extern RTest test; |
|
28 |
extern TBool gVerbose; |
|
29 |
extern TBool gSkip; |
|
30 |
extern TBool gStopOnFail; |
|
31 |
extern TBool gAltSettingOnNotify; |
|
32 |
extern TInt gSoakCount; |
|
33 |
extern CActiveRW* gRW[KMaxConcurrentTests]; // the USB read/write active object |
|
34 |
extern IFConfigPtr gInterfaceConfig [128] [KMaxInterfaceSettings]; |
|
35 |
||
36 |
// |
|
37 |
// --- class CActiveDeviceStateNotifier --------------------------------------------------------- |
|
38 |
// |
|
39 |
||
40 |
CActiveDeviceStateNotifier::CActiveDeviceStateNotifier(CConsoleBase* aConsole, RDEVCLIENT* aPort, TUint aPortNumber) |
|
41 |
: CActive(EPriorityNormal), |
|
42 |
iConsole(aConsole), |
|
43 |
iPort(aPort), |
|
44 |
iDeviceState(0), |
|
45 |
iPortNumber(aPortNumber) |
|
46 |
{ |
|
47 |
CActiveScheduler::Add(this); |
|
48 |
} |
|
49 |
||
50 |
CActiveDeviceStateNotifier* CActiveDeviceStateNotifier::NewL(CConsoleBase* aConsole, RDEVCLIENT* aPort, TUint aPortNumber) |
|
51 |
{ |
|
52 |
CActiveDeviceStateNotifier* self = new (ELeave) CActiveDeviceStateNotifier(aConsole, aPort, aPortNumber); |
|
53 |
CleanupStack::PushL(self); |
|
54 |
self->ConstructL(); |
|
55 |
CleanupStack::Pop(); // self |
|
56 |
return self; |
|
57 |
} |
|
58 |
||
59 |
||
60 |
void CActiveDeviceStateNotifier::ConstructL() |
|
61 |
{} |
|
62 |
||
63 |
||
64 |
CActiveDeviceStateNotifier::~CActiveDeviceStateNotifier() |
|
65 |
{ |
|
66 |
TUSB_VERBOSE_PRINT("CActiveDeviceStateNotifier::~CActiveDeviceStateNotifier()"); |
|
67 |
Cancel(); // base class |
|
68 |
} |
|
69 |
||
70 |
||
71 |
void CActiveDeviceStateNotifier::DoCancel() |
|
72 |
{ |
|
73 |
TUSB_VERBOSE_PRINT("CActiveDeviceStateNotifier::DoCancel()"); |
|
74 |
iPort->AlternateDeviceStatusNotifyCancel(); |
|
75 |
} |
|
76 |
||
77 |
||
78 |
void CActiveDeviceStateNotifier::RunL() |
|
79 |
{ |
|
80 |
// This displays the device state. |
|
81 |
// In a real world program, the user could take here appropriate action (cancel a |
|
82 |
// transfer request or whatever). |
|
83 |
if (!(iDeviceState & KUsbAlternateSetting) && gVerbose) |
|
84 |
{ |
|
85 |
switch (iDeviceState) |
|
86 |
{ |
|
87 |
case EUsbcDeviceStateUndefined: |
|
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
88 |
#ifdef USB_SC |
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
89 |
TUSB_PRINT("Device State notifier: Undefined0"); |
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
90 |
for (TUint16 i =0; i < KMaxConcurrentTests; i++) |
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
91 |
{ |
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
92 |
if (gRW[i]) |
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
93 |
{ |
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
94 |
TUSB_VERBOSE_PRINT2("ResetAltSetting index %d, LDD %x",i, gRW[i]->Ldd()); |
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
95 |
gRW[i]->Ldd()->ResetAltSetting(); |
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
96 |
} |
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
97 |
} |
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
98 |
#endif |
0 | 99 |
TUSB_PRINT("Device State notifier: Undefined"); |
100 |
break; |
|
101 |
case EUsbcDeviceStateAttached: |
|
102 |
TUSB_PRINT("Device State notifier: Attached"); |
|
103 |
break; |
|
104 |
case EUsbcDeviceStatePowered: |
|
105 |
TUSB_PRINT("Device State notifier: Powered"); |
|
106 |
break; |
|
107 |
case EUsbcDeviceStateDefault: |
|
108 |
TUSB_PRINT("Device State notifier: Default"); |
|
109 |
break; |
|
110 |
case EUsbcDeviceStateAddress: |
|
111 |
TUSB_PRINT("Device State notifier: Address"); |
|
112 |
break; |
|
113 |
case EUsbcDeviceStateConfigured: |
|
114 |
TUSB_PRINT("Device State notifier: Configured"); |
|
115 |
break; |
|
116 |
case EUsbcDeviceStateSuspended: |
|
117 |
TUSB_PRINT("Device State notifier: Suspended"); |
|
118 |
break; |
|
119 |
default: |
|
120 |
TUSB_PRINT("Device State notifier: ***BAD***"); |
|
121 |
} |
|
122 |
} |
|
123 |
else if (iDeviceState & KUsbAlternateSetting) |
|
124 |
{ |
|
125 |
TUint8 altSetting = iDeviceState & ~KUsbAlternateSetting; |
|
126 |
TUSB_PRINT2("Device State notifier: Alternate interface %d setting has changed: now %d", |
|
127 |
iPortNumber, altSetting); |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
128 |
|
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
129 |
TUsbDeviceCaps dCaps; |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
130 |
iPort->DeviceCaps(dCaps); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
131 |
TBool isResourceAllocationV2 = ((dCaps().iFeatureWord1 & KUsbDevCapsFeatureWord1_EndpointResourceAllocV2) != 0); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
132 |
if (!isResourceAllocationV2) |
0 | 133 |
{ |
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
134 |
// 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
|
135 |
// 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
|
136 |
for (TUint8 ifNumber = 0; ifNumber < 128; ifNumber++) |
0 | 137 |
{ |
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
138 |
IFConfigPtr newIfPtr = gInterfaceConfig[ifNumber][altSetting]; |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
139 |
if (newIfPtr) |
0 | 140 |
{ |
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
141 |
if (newIfPtr->iPortNumber == iPortNumber) |
0 | 142 |
{ |
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
143 |
// 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
|
144 |
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
|
145 |
{ |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
146 |
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
|
147 |
#ifndef USB_SC |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
148 |
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
|
149 |
#endif |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
150 |
} |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
151 |
break; |
0 | 152 |
} |
153 |
} |
|
154 |
} |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
155 |
} |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
156 |
|
0 | 157 |
if (gAltSettingOnNotify) |
158 |
{ |
|
159 |
for (TUint16 i =0; i < KMaxConcurrentTests; i++) |
|
160 |
{ |
|
161 |
if (gRW[i]) |
|
162 |
{ |
|
163 |
TUSB_VERBOSE_PRINT1("Resuming alternate Setting - activeRW index %d",i); |
|
164 |
gRW[i]->ResumeAltSetting(altSetting); |
|
165 |
} |
|
166 |
} |
|
167 |
} |
|
168 |
} |
|
169 |
Activate(); |
|
170 |
} |
|
171 |
||
172 |
||
173 |
void CActiveDeviceStateNotifier::Activate() |
|
174 |
{ |
|
175 |
__ASSERT_ALWAYS(!IsActive(), User::Panic(KActivePanic, 661)); |
|
176 |
iPort->AlternateDeviceStatusNotify(iStatus, iDeviceState); |
|
177 |
SetActive(); |
|
178 |
} |
|
179 |
||
180 |
||
181 |
// -eof- |