1 // Copyright (c) 2000-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 // e32\include\drivers\usbcshared.inl |
|
15 // Kernel side definitions for the USB Device driver stack (PIL + LDD). |
|
16 // |
|
17 // |
|
18 |
|
19 /** |
|
20 @file usbcshared.inl |
|
21 @internalTechnology |
|
22 */ |
|
23 |
|
24 #ifndef __USBCSHARED_INL__ |
|
25 #define __USBCSHARED_INL__ |
|
26 |
|
27 // |
|
28 // --- DUsbClientController (USB PDD) --- |
|
29 // |
|
30 |
|
31 // --- Private member functions, used by controller itself --- |
|
32 |
|
33 const DBase* DUsbClientController::PEndpoint2ClientId(TInt aRealEndpoint) const |
|
34 { |
|
35 if (iRealEndpoints[aRealEndpoint].iLEndpoint) |
|
36 return iRealEndpoints[aRealEndpoint].iLEndpoint->iInterface->iInterfaceSet->iClientId; |
|
37 else |
|
38 return NULL; |
|
39 } |
|
40 |
|
41 |
|
42 TInt DUsbClientController::PEndpoint2LEndpoint(TInt aRealEndpoint) const |
|
43 { |
|
44 if (iRealEndpoints[aRealEndpoint].iLEndpoint) |
|
45 return iRealEndpoints[aRealEndpoint].iLEndpoint->iLEndpointNum; |
|
46 else |
|
47 return -1; |
|
48 } |
|
49 |
|
50 |
|
51 const TUsbcConfiguration* DUsbClientController::CurrentConfig() const |
|
52 { |
|
53 return (iCurrentConfig ? iConfigs[iCurrentConfig - 1] : NULL); |
|
54 } |
|
55 |
|
56 |
|
57 TUsbcConfiguration* DUsbClientController::CurrentConfig() |
|
58 { |
|
59 return (iCurrentConfig ? iConfigs[iCurrentConfig - 1] : NULL); |
|
60 } |
|
61 |
|
62 |
|
63 TBool DUsbClientController::InterfaceExists(TInt aNumber) const |
|
64 { |
|
65 const TInt num_ifcsets = iConfigs[0]->iInterfaceSets.Count(); |
|
66 RPointerArray<TUsbcInterfaceSet>& ifcsets = iConfigs[0]->iInterfaceSets; |
|
67 for (TInt i = 0; i < num_ifcsets; i++) |
|
68 { |
|
69 if (ifcsets[i]->iInterfaceNumber == aNumber) |
|
70 { |
|
71 return ETrue; |
|
72 } |
|
73 } |
|
74 return EFalse; |
|
75 } |
|
76 |
|
77 |
|
78 TBool DUsbClientController::EndpointExists(TUint aAddress) const |
|
79 { |
|
80 // Ep0 doesn't have a "logical ep" pointer (there's no virtual endpoint zero); |
|
81 // that's why this pointer being non-NULL is not a sufficient criterion for |
|
82 // endpoint-existence. (Apart from that, ep0 always exists.) |
|
83 const TInt idx = EpAddr2Idx(aAddress); |
|
84 return ((idx < iDeviceTotalEndpoints) && |
|
85 ((iRealEndpoints[idx].iLEndpoint != NULL) || |
|
86 ((aAddress & KUsbEpAddress_Portmask) == 0))); |
|
87 } |
|
88 |
|
89 TUint DUsbClientController::EpIdx2Addr(TUint aRealEndpoint) const |
|
90 { |
|
91 return ((aRealEndpoint << 7) & 0x80) | ((aRealEndpoint >> 1) & 0x0f); |
|
92 } |
|
93 |
|
94 |
|
95 TUint DUsbClientController::EpAddr2Idx(TUint aAddress) const |
|
96 { |
|
97 return ((aAddress & 0x80) >> 7) | ((aAddress & 0x0f) << 1); |
|
98 } |
|
99 |
|
100 |
|
101 void DUsbClientController::SetEp0DataOutVars(const DBase* aClientId) |
|
102 { |
|
103 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::SetEp0DataOutVars()")); |
|
104 //iSetup = aPacket; |
|
105 iEp0DataReceived = 0; |
|
106 iEp0ClientId = aClientId; |
|
107 } |
|
108 |
|
109 |
|
110 void DUsbClientController::ResetEp0DataOutVars() |
|
111 { |
|
112 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ResetEp0DataOutVars()")); |
|
113 iEp0DataReceived = 0; |
|
114 iEp0ClientId = NULL; |
|
115 } |
|
116 |
|
117 |
|
118 TBool DUsbClientController::IsInTheRequestList(const TUsbcRequestCallback& aCallback) |
|
119 { |
|
120 const TInt irq = __SPIN_LOCK_IRQSAVE(iUsbLock); |
|
121 TSglQueIter<TUsbcRequestCallback> iter(iEp0ReadRequestCallbacks); |
|
122 TUsbcRequestCallback* p; |
|
123 while ((p = iter++) != NULL) |
|
124 { |
|
125 if (p == &aCallback) |
|
126 { |
|
127 __SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq); |
|
128 return ETrue; |
|
129 } |
|
130 } |
|
131 __SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq); |
|
132 return EFalse; |
|
133 } |
|
134 |
|
135 |
|
136 TBool DUsbClientController::IsInTheStatusList(const TUsbcStatusCallback& aCallback) |
|
137 { |
|
138 const TInt irq = __SPIN_LOCK_IRQSAVE(iUsbLock); |
|
139 TSglQueIter<TUsbcStatusCallback> iter(iStatusCallbacks); |
|
140 TUsbcStatusCallback* p; |
|
141 while ((p = iter++) != NULL) |
|
142 { |
|
143 if (p == &aCallback) |
|
144 { |
|
145 __SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq); |
|
146 return ETrue; |
|
147 } |
|
148 } |
|
149 __SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq); |
|
150 return EFalse; |
|
151 } |
|
152 |
|
153 |
|
154 TBool DUsbClientController::IsInTheEpStatusList(const TUsbcEndpointStatusCallback& aCallback) |
|
155 { |
|
156 const TInt irq = __SPIN_LOCK_IRQSAVE(iUsbLock); |
|
157 TSglQueIter<TUsbcEndpointStatusCallback> iter(iEpStatusCallbacks); |
|
158 TUsbcEndpointStatusCallback* p; |
|
159 while ((p = iter++) != NULL) |
|
160 { |
|
161 if (p == &aCallback) |
|
162 { |
|
163 __SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq); |
|
164 return ETrue; |
|
165 } |
|
166 } |
|
167 __SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq); |
|
168 return EFalse; |
|
169 } |
|
170 |
|
171 |
|
172 TBool DUsbClientController::IsInTheOtgFeatureList(const TUsbcOtgFeatureCallback& aCallback) |
|
173 { |
|
174 const TInt irq = __SPIN_LOCK_IRQSAVE(iUsbLock); |
|
175 TSglQueIter<TUsbcOtgFeatureCallback> iter(iOtgCallbacks); |
|
176 TUsbcOtgFeatureCallback* p; |
|
177 while ((p = iter++) != NULL) |
|
178 { |
|
179 if (p == &aCallback) |
|
180 { |
|
181 __SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq); |
|
182 return ETrue; |
|
183 } |
|
184 } |
|
185 __SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq); |
|
186 return EFalse; |
|
187 } |
|
188 |
|
189 // |
|
190 // --- Misc classes --- |
|
191 // |
|
192 |
|
193 // --- TUsbcClientCallback |
|
194 |
|
195 /** Constructor. |
|
196 */ |
|
197 TUsbcClientCallback::TUsbcClientCallback(DBase* aOwner, TDfcFn aCallback, TInt aPriority) |
|
198 : iOwner(aOwner), |
|
199 iDfc(aCallback, aOwner, aPriority) |
|
200 {} |
|
201 |
|
202 |
|
203 /** Returns a pointer to the owner of this request. |
|
204 |
|
205 @return A pointer to the owner of this request. |
|
206 */ |
|
207 DBase* TUsbcClientCallback::Owner() const |
|
208 { |
|
209 return iOwner; |
|
210 } |
|
211 |
|
212 |
|
213 /** Executes the callback function set by the owner of this request. |
|
214 |
|
215 @return KErrNone. |
|
216 */ |
|
217 TInt TUsbcClientCallback::DoCallback() |
|
218 { |
|
219 __ASSERT_DEBUG((NKern::CurrentContext() == EThread), Kern::Fault(KUsbPILPanicCat, __LINE__)); |
|
220 iDfc.Enque(); |
|
221 return KErrNone; |
|
222 } |
|
223 |
|
224 |
|
225 /** Cancels the callback function set by the owner of this request. |
|
226 */ |
|
227 void TUsbcClientCallback::Cancel() |
|
228 { |
|
229 iDfc.Cancel(); |
|
230 } |
|
231 |
|
232 |
|
233 /** Sets the DFC queue used by the callback function. |
|
234 @param aDfcQ DFC queue to be set |
|
235 */ |
|
236 void TUsbcClientCallback::SetDfcQ(TDfcQue* aDfcQ) |
|
237 { |
|
238 iDfc.SetDfcQ(aDfcQ); |
|
239 } |
|
240 |
|
241 |
|
242 // --- TUsbcEndpointStatusCallback |
|
243 |
|
244 /** Constructor. |
|
245 */ |
|
246 TUsbcEndpointStatusCallback::TUsbcEndpointStatusCallback(DBase* aOwner, TDfcFn aCallback, |
|
247 TInt aPriority) |
|
248 : iOwner(aOwner), |
|
249 iDfc(aCallback, aOwner, aPriority), |
|
250 iState(0) |
|
251 {} |
|
252 |
|
253 |
|
254 /** Sets the state of this request to aState. |
|
255 |
|
256 @param aState The new state to be set. |
|
257 */ |
|
258 void TUsbcEndpointStatusCallback::SetState(TUint aState) |
|
259 { |
|
260 iState = aState; |
|
261 } |
|
262 |
|
263 |
|
264 /** Returns the state value of this request. |
|
265 |
|
266 @return The state value of this request. |
|
267 */ |
|
268 TUint TUsbcEndpointStatusCallback::State() const |
|
269 { |
|
270 return iState; |
|
271 } |
|
272 |
|
273 |
|
274 /** Returns a pointer to the owner of this request. |
|
275 |
|
276 @return A pointer to the owner of this request. |
|
277 */ |
|
278 DBase* TUsbcEndpointStatusCallback::Owner() const |
|
279 { |
|
280 return iOwner; |
|
281 } |
|
282 |
|
283 |
|
284 /** Executes the callback function set by the owner of this request. |
|
285 |
|
286 @return KErrNone. |
|
287 */ |
|
288 TInt TUsbcEndpointStatusCallback::DoCallback() |
|
289 { |
|
290 if (NKern::CurrentContext() == EThread) |
|
291 iDfc.Enque(); |
|
292 else |
|
293 iDfc.Add(); |
|
294 return KErrNone; |
|
295 } |
|
296 |
|
297 |
|
298 /** Cancels the callback function set by the owner of this request. |
|
299 */ |
|
300 void TUsbcEndpointStatusCallback::Cancel() |
|
301 { |
|
302 iDfc.Cancel(); |
|
303 } |
|
304 |
|
305 |
|
306 /** Sets the DFC queue used by the callback function. |
|
307 */ |
|
308 void TUsbcEndpointStatusCallback::SetDfcQ(TDfcQue* aDfcQ) |
|
309 { |
|
310 iDfc.SetDfcQ(aDfcQ); |
|
311 } |
|
312 |
|
313 |
|
314 // --- TUsbcStatusCallback |
|
315 |
|
316 /** Constructor. |
|
317 */ |
|
318 TUsbcStatusCallback::TUsbcStatusCallback(DBase* aOwner, TDfcFn aCallback, TInt aPriority) |
|
319 : iOwner(aOwner), |
|
320 iDfc(aCallback, aOwner, aPriority) |
|
321 { |
|
322 ResetState(); |
|
323 } |
|
324 |
|
325 |
|
326 /** Sets the state of this request to aState (at the first available position |
|
327 in the state value array). |
|
328 |
|
329 @param aState The new state to be set. |
|
330 */ |
|
331 void TUsbcStatusCallback::SetState(UsbShai::TUsbPeripheralState aState) |
|
332 { |
|
333 for (TInt i = 0; i < KUsbcDeviceStateRequests; i++) |
|
334 { |
|
335 if (iState[i] == UsbShai::EUsbPeripheralNoState) |
|
336 { |
|
337 iState[i] = aState; |
|
338 return; |
|
339 } |
|
340 } |
|
341 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: KUsbcDeviceStateRequests too small (%d)!", |
|
342 KUsbcDeviceStateRequests)); |
|
343 } |
|
344 |
|
345 |
|
346 /** Returns the state value of this request at a certain index. |
|
347 |
|
348 @param aIndex The index to be used for referencing the state array. |
|
349 |
|
350 @return The state value of this request at aIndex. |
|
351 */ |
|
352 UsbShai::TUsbPeripheralState TUsbcStatusCallback::State(TInt aIndex) const |
|
353 { |
|
354 if (aIndex >= 0 && aIndex < KUsbcDeviceStateRequests) |
|
355 { |
|
356 return iState[aIndex]; |
|
357 } |
|
358 else |
|
359 { |
|
360 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: aIndex too large (%d)!", aIndex)); |
|
361 return UsbShai::EUsbPeripheralNoState; |
|
362 } |
|
363 } |
|
364 |
|
365 |
|
366 /** Resets the entire state value array of this request. |
|
367 */ |
|
368 void TUsbcStatusCallback::ResetState() |
|
369 { |
|
370 for (TInt i = 0; i < KUsbcDeviceStateRequests; ++i) |
|
371 { |
|
372 iState[i] = UsbShai::EUsbPeripheralNoState; |
|
373 } |
|
374 } |
|
375 |
|
376 |
|
377 /** Returns a pointer to the owner of this request. |
|
378 |
|
379 @return A pointer to the owner of this request. |
|
380 */ |
|
381 DBase* TUsbcStatusCallback::Owner() const |
|
382 { |
|
383 return iOwner; |
|
384 } |
|
385 |
|
386 |
|
387 /** Executes the callback function set by the owner of this request. |
|
388 |
|
389 @return KErrNone. |
|
390 */ |
|
391 TInt TUsbcStatusCallback::DoCallback() |
|
392 { |
|
393 if (NKern::CurrentContext() == EThread) |
|
394 iDfc.Enque(); |
|
395 else |
|
396 iDfc.Add(); |
|
397 return KErrNone; |
|
398 } |
|
399 |
|
400 |
|
401 /** Cancels the callback function set by the owner of this request. |
|
402 */ |
|
403 void TUsbcStatusCallback::Cancel() |
|
404 { |
|
405 iDfc.Cancel(); |
|
406 } |
|
407 |
|
408 |
|
409 /** Sets the DFC queue used by the callback function. |
|
410 */ |
|
411 void TUsbcStatusCallback::SetDfcQ(TDfcQue* aDfcQ) |
|
412 { |
|
413 iDfc.SetDfcQ(aDfcQ); |
|
414 } |
|
415 |
|
416 // --- TUsbcRequestCallback |
|
417 |
|
418 /** Constructor. |
|
419 */ |
|
420 TUsbcRequestCallback::TUsbcRequestCallback(const DBase* aOwner, TInt aEndpointNum, TDfcFn aDfcFunc, |
|
421 TAny* aEndpoint, TDfcQue* aDfcQ, TInt aPriority) |
|
422 : TUsbPeripheralRequest(-1), |
|
423 iEndpointNum(aEndpointNum), |
|
424 iOwner(aOwner), |
|
425 iDfc(aDfcFunc, aEndpoint, aDfcQ, aPriority) |
|
426 { |
|
427 } |
|
428 |
|
429 |
|
430 /** Destructor. |
|
431 */ |
|
432 TUsbcRequestCallback::~TUsbcRequestCallback() |
|
433 { |
|
434 __KTRACE_OPT(KUSB, Kern::Printf("TUsbcRequestCallback::~TUsbcRequestCallback()")); |
|
435 iDfc.Cancel(); |
|
436 } |
|
437 |
|
438 /** Sets the transfer direction for this request. |
|
439 |
|
440 @param aTransferDir The new transfer direction. |
|
441 */ |
|
442 void TUsbcRequestCallback::SetTransferDirection(UsbShai::TTransferDirection aTransferDir) |
|
443 { |
|
444 iTransferDir = aTransferDir; |
|
445 } |
|
446 |
|
447 |
|
448 /** Returns a pointer to the owner of this request. |
|
449 |
|
450 @return A pointer to the owner of this request. |
|
451 */ |
|
452 const DBase* TUsbcRequestCallback::Owner() const |
|
453 { |
|
454 return iOwner; |
|
455 } |
|
456 |
|
457 |
|
458 /** Executes the callback function set by the owner of this request. |
|
459 |
|
460 @return KErrNone. |
|
461 */ |
|
462 TInt TUsbcRequestCallback::DoCallback() |
|
463 { |
|
464 if (NKern::CurrentContext() == NKern::EThread) |
|
465 iDfc.Enque(); |
|
466 else |
|
467 iDfc.Add(); |
|
468 return KErrNone; |
|
469 } |
|
470 |
|
471 |
|
472 /** Cancels the callback function set by the owner of this request. |
|
473 */ |
|
474 void TUsbcRequestCallback::Cancel() |
|
475 { |
|
476 iDfc.Cancel(); |
|
477 } |
|
478 |
|
479 // --- TUsbcOtgFeatureCallback |
|
480 |
|
481 /** Constructor. |
|
482 */ |
|
483 TUsbcOtgFeatureCallback::TUsbcOtgFeatureCallback(DBase* aOwner, TDfcFn aCallback, |
|
484 TInt aPriority) |
|
485 : iOwner(aOwner), |
|
486 iDfc(aCallback, aOwner, aPriority), |
|
487 iValue(0) |
|
488 {} |
|
489 |
|
490 |
|
491 /** Returns a pointer to the owner of this request. |
|
492 @return A pointer to the owner of this request. |
|
493 */ |
|
494 DBase* TUsbcOtgFeatureCallback::Owner() const |
|
495 { |
|
496 return iOwner; |
|
497 } |
|
498 |
|
499 |
|
500 /** Set feature value which is to be notified to client. |
|
501 @param OTG feature value to be set |
|
502 */ |
|
503 void TUsbcOtgFeatureCallback::SetFeatures(TUint8 aFeatures) |
|
504 { |
|
505 iValue = aFeatures; |
|
506 } |
|
507 |
|
508 |
|
509 /** Set feature value which is to be notified to client. |
|
510 @return Value of OTG features |
|
511 */ |
|
512 TUint8 TUsbcOtgFeatureCallback::Features() const |
|
513 { |
|
514 return iValue; |
|
515 } |
|
516 |
|
517 |
|
518 /** Set DFC queue. |
|
519 @param aDfcQ DFC queue to be set |
|
520 */ |
|
521 void TUsbcOtgFeatureCallback::SetDfcQ(TDfcQue* aDfcQ) |
|
522 { |
|
523 iDfc.SetDfcQ(aDfcQ); |
|
524 } |
|
525 |
|
526 |
|
527 /** Executes the callback function set by the owner of this request. |
|
528 @return KErrNone. |
|
529 */ |
|
530 TInt TUsbcOtgFeatureCallback::DoCallback() |
|
531 { |
|
532 if (NKern::CurrentContext() == EThread) |
|
533 iDfc.Enque(); |
|
534 else |
|
535 iDfc.Add(); |
|
536 return KErrNone; |
|
537 } |
|
538 |
|
539 |
|
540 /** Cancels the callback function set by the owner of this request. |
|
541 */ |
|
542 void TUsbcOtgFeatureCallback::Cancel() |
|
543 { |
|
544 iDfc.Cancel(); |
|
545 } |
|
546 |
|
547 |
|
548 /** Returns a pointer to the currently selected (active) setting of this interface. |
|
549 |
|
550 @return A pointer to the currently selected (active) setting of this interface. |
|
551 */ |
|
552 const TUsbcInterface* TUsbcInterfaceSet::CurrentInterface() const |
|
553 { |
|
554 return iInterfaces[iCurrentInterface]; |
|
555 } |
|
556 |
|
557 |
|
558 /** Returns a pointer to the currently selected (active) setting of this interface. |
|
559 |
|
560 @return A pointer to the currently selected (active) setting of this interface. |
|
561 */ |
|
562 |
|
563 TUsbcInterface* TUsbcInterfaceSet::CurrentInterface() |
|
564 { |
|
565 return iInterfaces[iCurrentInterface]; |
|
566 } |
|
567 |
|
568 #endif // __USBCSHARED_INL__ |
|
569 |
|
570 |
|
571 |
|