sl@0
|
1 |
// Copyright (c) 2000-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/usb/t_usb_device/src/activestatenotifier.cpp
|
sl@0
|
15 |
// USB Test Program T_USB_DEVICE, functional part.
|
sl@0
|
16 |
// Device-side part, to work against T_USB_HOST running on the host.
|
sl@0
|
17 |
//
|
sl@0
|
18 |
//
|
sl@0
|
19 |
|
sl@0
|
20 |
#include "general.h"
|
sl@0
|
21 |
#include "activerw.h" // CActiveRW
|
sl@0
|
22 |
#include "config.h"
|
sl@0
|
23 |
#include "activeControl.h"
|
sl@0
|
24 |
#include "activedevicestatenotifier.h"
|
sl@0
|
25 |
|
sl@0
|
26 |
extern CActiveControl* gActiveControl;
|
sl@0
|
27 |
extern RTest test;
|
sl@0
|
28 |
extern TBool gVerbose;
|
sl@0
|
29 |
extern TBool gSkip;
|
sl@0
|
30 |
extern TBool gStopOnFail;
|
sl@0
|
31 |
extern TBool gAltSettingOnNotify;
|
sl@0
|
32 |
extern TInt gSoakCount;
|
sl@0
|
33 |
extern CActiveRW* gRW[KMaxConcurrentTests]; // the USB read/write active object
|
sl@0
|
34 |
extern IFConfigPtr gInterfaceConfig [128] [KMaxInterfaceSettings];
|
sl@0
|
35 |
|
sl@0
|
36 |
//
|
sl@0
|
37 |
// --- class CActiveDeviceStateNotifier ---------------------------------------------------------
|
sl@0
|
38 |
//
|
sl@0
|
39 |
|
sl@0
|
40 |
CActiveDeviceStateNotifier::CActiveDeviceStateNotifier(CConsoleBase* aConsole, RDEVCLIENT* aPort, TUint aPortNumber)
|
sl@0
|
41 |
: CActive(EPriorityNormal),
|
sl@0
|
42 |
iConsole(aConsole),
|
sl@0
|
43 |
iPort(aPort),
|
sl@0
|
44 |
iDeviceState(0),
|
sl@0
|
45 |
iPortNumber(aPortNumber)
|
sl@0
|
46 |
{
|
sl@0
|
47 |
CActiveScheduler::Add(this);
|
sl@0
|
48 |
}
|
sl@0
|
49 |
|
sl@0
|
50 |
CActiveDeviceStateNotifier* CActiveDeviceStateNotifier::NewL(CConsoleBase* aConsole, RDEVCLIENT* aPort, TUint aPortNumber)
|
sl@0
|
51 |
{
|
sl@0
|
52 |
CActiveDeviceStateNotifier* self = new (ELeave) CActiveDeviceStateNotifier(aConsole, aPort, aPortNumber);
|
sl@0
|
53 |
CleanupStack::PushL(self);
|
sl@0
|
54 |
self->ConstructL();
|
sl@0
|
55 |
CleanupStack::Pop(); // self
|
sl@0
|
56 |
return self;
|
sl@0
|
57 |
}
|
sl@0
|
58 |
|
sl@0
|
59 |
|
sl@0
|
60 |
void CActiveDeviceStateNotifier::ConstructL()
|
sl@0
|
61 |
{}
|
sl@0
|
62 |
|
sl@0
|
63 |
|
sl@0
|
64 |
CActiveDeviceStateNotifier::~CActiveDeviceStateNotifier()
|
sl@0
|
65 |
{
|
sl@0
|
66 |
TUSB_VERBOSE_PRINT("CActiveDeviceStateNotifier::~CActiveDeviceStateNotifier()");
|
sl@0
|
67 |
Cancel(); // base class
|
sl@0
|
68 |
}
|
sl@0
|
69 |
|
sl@0
|
70 |
|
sl@0
|
71 |
void CActiveDeviceStateNotifier::DoCancel()
|
sl@0
|
72 |
{
|
sl@0
|
73 |
TUSB_VERBOSE_PRINT("CActiveDeviceStateNotifier::DoCancel()");
|
sl@0
|
74 |
iPort->AlternateDeviceStatusNotifyCancel();
|
sl@0
|
75 |
}
|
sl@0
|
76 |
|
sl@0
|
77 |
|
sl@0
|
78 |
void CActiveDeviceStateNotifier::RunL()
|
sl@0
|
79 |
{
|
sl@0
|
80 |
// This displays the device state.
|
sl@0
|
81 |
// In a real world program, the user could take here appropriate action (cancel a
|
sl@0
|
82 |
// transfer request or whatever).
|
sl@0
|
83 |
if (!(iDeviceState & KUsbAlternateSetting) && gVerbose)
|
sl@0
|
84 |
{
|
sl@0
|
85 |
switch (iDeviceState)
|
sl@0
|
86 |
{
|
sl@0
|
87 |
case EUsbcDeviceStateUndefined:
|
sl@0
|
88 |
TUSB_PRINT("Device State notifier: Undefined");
|
sl@0
|
89 |
break;
|
sl@0
|
90 |
case EUsbcDeviceStateAttached:
|
sl@0
|
91 |
TUSB_PRINT("Device State notifier: Attached");
|
sl@0
|
92 |
break;
|
sl@0
|
93 |
case EUsbcDeviceStatePowered:
|
sl@0
|
94 |
TUSB_PRINT("Device State notifier: Powered");
|
sl@0
|
95 |
break;
|
sl@0
|
96 |
case EUsbcDeviceStateDefault:
|
sl@0
|
97 |
TUSB_PRINT("Device State notifier: Default");
|
sl@0
|
98 |
break;
|
sl@0
|
99 |
case EUsbcDeviceStateAddress:
|
sl@0
|
100 |
TUSB_PRINT("Device State notifier: Address");
|
sl@0
|
101 |
break;
|
sl@0
|
102 |
case EUsbcDeviceStateConfigured:
|
sl@0
|
103 |
TUSB_PRINT("Device State notifier: Configured");
|
sl@0
|
104 |
break;
|
sl@0
|
105 |
case EUsbcDeviceStateSuspended:
|
sl@0
|
106 |
TUSB_PRINT("Device State notifier: Suspended");
|
sl@0
|
107 |
break;
|
sl@0
|
108 |
default:
|
sl@0
|
109 |
TUSB_PRINT("Device State notifier: ***BAD***");
|
sl@0
|
110 |
}
|
sl@0
|
111 |
}
|
sl@0
|
112 |
else if (iDeviceState & KUsbAlternateSetting)
|
sl@0
|
113 |
{
|
sl@0
|
114 |
TUint8 altSetting = iDeviceState & ~KUsbAlternateSetting;
|
sl@0
|
115 |
TUSB_PRINT2("Device State notifier: Alternate interface %d setting has changed: now %d",
|
sl@0
|
116 |
iPortNumber, altSetting);
|
sl@0
|
117 |
|
sl@0
|
118 |
// allocate endpoint DMA and double buffering for all endpoints on interface
|
sl@0
|
119 |
for (TUint8 ifNumber = 0; ifNumber < 128; ifNumber++)
|
sl@0
|
120 |
{
|
sl@0
|
121 |
IFConfigPtr newIfPtr = gInterfaceConfig[ifNumber][altSetting];
|
sl@0
|
122 |
if (newIfPtr)
|
sl@0
|
123 |
{
|
sl@0
|
124 |
if (newIfPtr->iPortNumber == iPortNumber)
|
sl@0
|
125 |
{
|
sl@0
|
126 |
// allocate endpoint DMA and double buffering for all endpoints on default interface
|
sl@0
|
127 |
for (TUint8 i = 1; i <= newIfPtr->iInfoPtr->iTotalEndpointsUsed; i++)
|
sl@0
|
128 |
{
|
sl@0
|
129 |
newIfPtr->iEpDMA[i-1] ? gActiveControl->AllocateEndpointDMA(iPort,(TENDPOINTNUMBER)i) : gActiveControl->DeAllocateEndpointDMA(iPort,(TENDPOINTNUMBER)i);
|
sl@0
|
130 |
#ifndef USB_SC
|
sl@0
|
131 |
newIfPtr->iEpDoubleBuff[i-1] ? gActiveControl->AllocateDoubleBuffering(iPort,(TENDPOINTNUMBER)i) : gActiveControl->DeAllocateDoubleBuffering(iPort,(TENDPOINTNUMBER)i);
|
sl@0
|
132 |
#endif
|
sl@0
|
133 |
}
|
sl@0
|
134 |
break;
|
sl@0
|
135 |
}
|
sl@0
|
136 |
}
|
sl@0
|
137 |
}
|
sl@0
|
138 |
|
sl@0
|
139 |
if (gAltSettingOnNotify)
|
sl@0
|
140 |
{
|
sl@0
|
141 |
for (TUint16 i =0; i < KMaxConcurrentTests; i++)
|
sl@0
|
142 |
{
|
sl@0
|
143 |
if (gRW[i])
|
sl@0
|
144 |
{
|
sl@0
|
145 |
TUSB_VERBOSE_PRINT1("Resuming alternate Setting - activeRW index %d",i);
|
sl@0
|
146 |
gRW[i]->ResumeAltSetting(altSetting);
|
sl@0
|
147 |
}
|
sl@0
|
148 |
}
|
sl@0
|
149 |
}
|
sl@0
|
150 |
}
|
sl@0
|
151 |
Activate();
|
sl@0
|
152 |
}
|
sl@0
|
153 |
|
sl@0
|
154 |
|
sl@0
|
155 |
void CActiveDeviceStateNotifier::Activate()
|
sl@0
|
156 |
{
|
sl@0
|
157 |
__ASSERT_ALWAYS(!IsActive(), User::Panic(KActivePanic, 661));
|
sl@0
|
158 |
iPort->AlternateDeviceStatusNotify(iStatus, iDeviceState);
|
sl@0
|
159 |
SetActive();
|
sl@0
|
160 |
}
|
sl@0
|
161 |
|
sl@0
|
162 |
|
sl@0
|
163 |
// -eof-
|