36 iNewAltSetting = 0; |
39 iNewAltSetting = 0; |
37 iAltSettingSeq = 0; |
40 iAltSettingSeq = 0; |
38 return r; |
41 return r; |
39 } |
42 } |
40 |
43 |
|
44 // empty a endpoint buffer, this is called when device state enter undefined |
|
45 TInt RDevUsbcScClient::Empty(TUint aBufferOffset) |
|
46 { |
|
47 TUint8* base = iSharedChunk.Base(); |
|
48 SUsbcScBufferHeader* endpointHdr = (SUsbcScBufferHeader*) (aBufferOffset + base); |
|
49 TUint localTail = endpointHdr->iBilTail; |
|
50 TUsbcScTransferHeader* currentTransfer; |
|
51 TInt err=KErrNone; |
|
52 |
|
53 while (ETrue) |
|
54 { |
|
55 if (localTail == (TUint) endpointHdr->iHead) |
|
56 { |
|
57 err = KErrNone; |
|
58 break; |
|
59 } |
|
60 currentTransfer = (TUsbcScTransferHeader*) (base + localTail); |
|
61 localTail = currentTransfer->iNext; |
|
62 } // end while |
|
63 endpointHdr->iBilTail = localTail; |
|
64 endpointHdr->iTail = localTail; |
|
65 return err; |
|
66 } |
|
67 |
|
68 |
41 |
69 |
42 EXPORT_C TInt RDevUsbcScClient::FinalizeInterface(RChunk*& aChunk) |
70 EXPORT_C TInt RDevUsbcScClient::FinalizeInterface(RChunk*& aChunk) |
43 { |
71 { |
44 TInt errorOrhandle = DoControl(EControlRealizeInterface); |
72 TInt errorOrhandle = DoControl(EControlRealizeInterface); |
45 iSharedChunk.SetReturnedHandle(errorOrhandle); |
73 iSharedChunk.SetReturnedHandle(errorOrhandle); |
46 iEndpointStatus = 0x00; //all endpoints are closed at the moment |
74 iEndpointStatus = 0x00; //all endpoints are closed at the moment |
47 iAlternateSetting = 0; |
75 iAlternateSetting = 0; |
48 return aChunk->SetReturnedHandle(errorOrhandle); |
76 return aChunk->SetReturnedHandle(errorOrhandle); |
|
77 } |
|
78 |
|
79 |
|
80 EXPORT_C void RDevUsbcScClient::ResetAltSetting() |
|
81 { |
|
82 if (iAlternateSetting == 0) |
|
83 return; |
|
84 TUsbcScChunkHeader chunkHeader(iSharedChunk); |
|
85 |
|
86 TInt ep; |
|
87 TInt noEp; |
|
88 TUint bufOff; |
|
89 TUsbcScHdrEndpointRecord* endpointInf = NULL; |
|
90 |
|
91 // check if alternate setting contains all IN endpoints |
|
92 noEp = chunkHeader.GetNumberOfEndpoints(iAlternateSetting); |
|
93 |
|
94 // for each used buffer. |
|
95 for (ep=1;ep<=noEp;ep++) |
|
96 { |
|
97 bufOff = chunkHeader.GetBuffer(iAlternateSetting,ep,endpointInf)->Offset(); |
|
98 |
|
99 if (endpointInf->Direction() & KUsbScHdrEpDirectionOut) |
|
100 { |
|
101 Empty(bufOff); // we need to remove anythng in the way, and get it ready for reading. |
|
102 } |
|
103 } |
|
104 |
|
105 iAlternateSetting = 0; |
49 } |
106 } |
50 |
107 |
51 |
108 |
52 EXPORT_C TInt RDevUsbcScClient::OpenEndpoint(TEndpointBuffer& aEpB, TInt aEpI) |
109 EXPORT_C TInt RDevUsbcScClient::OpenEndpoint(TEndpointBuffer& aEpB, TInt aEpI) |
53 { |
110 { |
116 //This drains any old data from an OUT buffer, and gets it ready for reading an ep. |
173 //This drains any old data from an OUT buffer, and gets it ready for reading an ep. |
117 //aBufferOffset - The offset, into the chunk, that the buffer in question, may be found. |
174 //aBufferOffset - The offset, into the chunk, that the buffer in question, may be found. |
118 |
175 |
119 TInt RDevUsbcScClient::Drain(TUint aBufferOffset) |
176 TInt RDevUsbcScClient::Drain(TUint aBufferOffset) |
120 { |
177 { |
|
178 |
121 TUint8* base = iSharedChunk.Base(); |
179 TUint8* base = iSharedChunk.Base(); |
122 SUsbcScBufferHeader* endpointHdr = (SUsbcScBufferHeader*) (aBufferOffset+base); |
180 SUsbcScBufferHeader* endpointHdr = (SUsbcScBufferHeader*) (aBufferOffset+base); |
123 TUint localTail = endpointHdr->iBilTail; |
181 TUint localTail = endpointHdr->iBilTail; |
124 TUsbcScTransferHeader* currentTransfer; |
182 TUsbcScTransferHeader* currentTransfer; |
125 TUint16 next = (iAltSettingSeq+1)&0xFFFF; |
183 TUint16 next = (iAltSettingSeq+1)&0xFFFF; |
126 TInt err=KErrNone; |
184 TInt err=KErrNone; |
|
185 TBool aZLP; |
127 |
186 |
128 while (ETrue) |
187 while (ETrue) |
129 { |
188 { |
130 if (localTail == (TUint) endpointHdr->iHead) |
189 if (localTail == (TUint) endpointHdr->iHead) |
131 { |
190 { |
403 if (iOutState) |
467 if (iOutState) |
404 return iOutState; |
468 return iOutState; |
405 |
469 |
406 TUsbcScTransferHeader* currentTransfer; |
470 TUsbcScTransferHeader* currentTransfer; |
407 TInt r; |
471 TInt r; |
|
472 TInt aBilTail; |
408 do // until we have a transfer with data. |
473 do // until we have a transfer with data. |
409 { |
474 { |
410 iEndpointHdr->iTail = iEndpointHdr->iBilTail; |
475 iEndpointHdr->iTail = iEndpointHdr->iBilTail; |
411 if(iEndpointHdr->iBilTail == iEndpointHdr->iHead) //If no new data, create request |
476 if(iEndpointHdr->iBilTail == iEndpointHdr->iHead) //If no new data, create request |
412 { |
477 { |
413 r = iClient->ReadDataNotify(iBufferNum,aStatus); |
478 r = iClient->ReadDataNotify(iBufferNum,aStatus); |
414 if (r!=KErrCompletion) // Data could arrive since we checked. |
479 if (r!=KErrCompletion) // Data could arrive since we checked. |
415 return r; |
480 return r; |
416 } |
481 } |
417 currentTransfer = (TUsbcScTransferHeader*) (iBaseAddr + iEndpointHdr->iBilTail); |
482 currentTransfer = (TUsbcScTransferHeader*) (iBaseAddr + iEndpointHdr->iBilTail); |
418 |
483 aBilTail = iEndpointHdr->iBilTail; |
419 iEndpointHdr->iBilTail = currentTransfer->iNext; |
484 iEndpointHdr->iBilTail = currentTransfer->iNext; |
420 aZLP = (currentTransfer->iFlags & KUsbcScShortPacket)!=EFalse; |
485 aZLP = (currentTransfer->iFlags & KUsbcScShortPacket)!=EFalse; |
|
486 |
|
487 if(currentTransfer->iAltSettingSeq != (iClient->iAltSettingSeq)) // if alternate setting has changed |
|
488 { |
|
489 if (currentTransfer->iAltSettingSeq == (iClient->iAltSettingSeq+1)) //Note- KIS ATM, if multiple alternate setting changes happen |
|
490 { |
|
491 iClient->iNewAltSetting = currentTransfer->iAltSetting; //before StartNextOutAlternateSetting is called, |
|
492 //this variable will reflect the latest requested AlternateSetting |
|
493 } |
|
494 |
|
495 |
|
496 if (iEndpointNumber != KEp0Number) |
|
497 { |
|
498 iEndpointHdr->iBilTail = aBilTail; |
|
499 // iOutState = EEOF; |
|
500 return KErrEof; |
|
501 } |
|
502 else if ((currentTransfer->iBytes==0) && (!aZLP)) |
|
503 { |
|
504 return KErrAlternateSettingChanged; |
|
505 } |
|
506 } |
|
507 |
|
508 } |
|
509 while ((currentTransfer->iBytes==0) && (!aZLP)); // ignore empty transfers |
|
510 |
|
511 aBuffer = currentTransfer->iData.i; |
|
512 aSize = currentTransfer->iBytes; |
|
513 return (currentTransfer->iFlags & KUsbcScStateChange)?KStateChange:KErrCompletion; |
|
514 } |
|
515 |
|
516 EXPORT_C TInt TEndpointBuffer::TakeBuffer(TAny*& aBuffer,TUint& aSize,TBool& aZLP,TRequestStatus& aStatus,TUint aLength) |
|
517 { |
|
518 if (iOutState) |
|
519 return iOutState; |
|
520 |
|
521 |
|
522 TUsbcScTransferHeader* currentTransfer; |
|
523 TInt r; |
|
524 TInt aBilTail; |
|
525 do // until we have a transfer with data. |
|
526 { |
|
527 if(iEndpointHdr->iBilTail == iEndpointHdr->iHead) //If no new data, create request |
|
528 { |
|
529 r = iClient->ReadDataNotify(iBufferNum,aStatus); |
|
530 if (r!=KErrCompletion) // Data could arrive since we checked. |
|
531 { |
|
532 return r; |
|
533 } |
|
534 } |
|
535 |
|
536 currentTransfer = (TUsbcScTransferHeader*) (iBaseAddr + iEndpointHdr->iBilTail); |
|
537 aBilTail = iEndpointHdr->iBilTail; |
|
538 iEndpointHdr->iBilTail = currentTransfer->iNext; |
|
539 aZLP = (currentTransfer->iFlags & KUsbcScShortPacket)!=EFalse; // True if short packet else false |
421 |
540 |
422 if(currentTransfer->iAltSettingSeq != (iClient->iAltSettingSeq)) // if alternate setting has changed |
541 if(currentTransfer->iAltSettingSeq != (iClient->iAltSettingSeq)) // if alternate setting has changed |
423 { |
542 { |
424 if (currentTransfer->iAltSettingSeq == (iClient->iAltSettingSeq+1)) //Note- KIS ATM, if multiple alternate setting changes happen |
543 if (currentTransfer->iAltSettingSeq == (iClient->iAltSettingSeq+1)) //Note- KIS ATM, if multiple alternate setting changes happen |
425 iClient->iNewAltSetting = currentTransfer->iAltSetting; //before StartNextOutAlternateSetting is called, |
544 iClient->iNewAltSetting = currentTransfer->iAltSetting; //before StartNextOutAlternateSetting is called, |
426 //this variable will reflect the latest requested AlternateSetting |
545 //this variable will reflect the latest requested AlternateSetting |
427 |
546 |
428 |
|
429 if (iEndpointNumber != KEp0Number) |
547 if (iEndpointNumber != KEp0Number) |
430 { |
548 { |
431 // iOutState = EEOF; |
549 iEndpointHdr->iBilTail = aBilTail; |
432 return KErrEof; |
|
433 } |
|
434 else if ((currentTransfer->iBytes==0) && (!aZLP)) |
|
435 { |
|
436 return KErrAlternateSettingChanged; |
|
437 } |
|
438 } |
|
439 |
|
440 } |
|
441 while ((currentTransfer->iBytes==0) && (!aZLP)); // ignore empty transfers |
|
442 |
|
443 aBuffer = currentTransfer->iData.i; |
|
444 aSize = currentTransfer->iBytes; |
|
445 return (currentTransfer->iFlags & KUsbcScStateChange)?KStateChange:KErrCompletion; |
|
446 } |
|
447 |
|
448 EXPORT_C TInt TEndpointBuffer::TakeBuffer(TAny*& aBuffer,TUint& aSize,TBool& aZLP,TRequestStatus& aStatus,TUint aLength) |
|
449 { |
|
450 if (iOutState) |
|
451 return iOutState; |
|
452 |
|
453 TUsbcScTransferHeader* currentTransfer; |
|
454 TInt r; |
|
455 do // until we have a transfer with data. |
|
456 { |
|
457 if(iEndpointHdr->iBilTail == iEndpointHdr->iHead) //If no new data, create request |
|
458 { |
|
459 r = iClient->ReadDataNotify(iBufferNum,aStatus); |
|
460 if (r!=KErrCompletion) // Data could arrive since we checked. |
|
461 { |
|
462 return r; |
|
463 } |
|
464 } |
|
465 |
|
466 currentTransfer = (TUsbcScTransferHeader*) (iBaseAddr + iEndpointHdr->iBilTail); |
|
467 iEndpointHdr->iBilTail = currentTransfer->iNext; |
|
468 aZLP = (currentTransfer->iFlags & KUsbcScShortPacket)!=EFalse; // True if short packet else false |
|
469 |
|
470 if(currentTransfer->iAltSettingSeq != (iClient->iAltSettingSeq)) // if alternate setting has changed |
|
471 { |
|
472 if (currentTransfer->iAltSettingSeq == (iClient->iAltSettingSeq+1)) //Note- KIS ATM, if multiple alternate setting changes happen |
|
473 iClient->iNewAltSetting = currentTransfer->iAltSetting; //before StartNextOutAlternateSetting is called, |
|
474 //this variable will reflect the latest requested AlternateSetting |
|
475 Expire(currentTransfer->iData.i); |
|
476 if (iEndpointNumber != KEp0Number) |
|
477 { |
|
478 // iOutState = EEOF; |
550 // iOutState = EEOF; |
479 return KErrEof; |
551 return KErrEof; |
480 } |
552 } |
481 else if ((currentTransfer->iBytes==0) && (!aZLP)) |
553 else if ((currentTransfer->iBytes==0) && (!aZLP)) |
482 { |
554 { |
|
555 Expire(currentTransfer->iData.i); |
483 return KErrAlternateSettingChanged; |
556 return KErrAlternateSettingChanged; |
484 } |
557 } |
|
558 Expire(currentTransfer->iData.i); |
485 |
559 |
486 } |
560 } |
487 |
561 |
488 if ((currentTransfer->iBytes==0) && (!aZLP)) // here , if empty transfer with alt setting information, Call expire |
562 if ((currentTransfer->iBytes==0) && (!aZLP)) // here , if empty transfer with alt setting information, Call expire |
489 { |
563 { |
625 |
700 |
626 /* Debug functions */ |
701 /* Debug functions */ |
627 |
702 |
628 EXPORT_C void TEndpointBuffer::Dump() |
703 EXPORT_C void TEndpointBuffer::Dump() |
629 { |
704 { |
630 RDebug::Printf("TEndpointBuffer::Dump iBufferStart: 0x%x, iSize: 0x%x, iEndpointNumber: 0x%x, iBufferNum: %d, iInState: 0x%x iOutState: 0x%x\n", |
705 OstTraceDefExt5(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TENDPOINTBUFFER_DUMP, "TEndpointBuffer::Dump iBufferStart: 0x%x, iSize: 0x%x, iEndpointNumber: 0x%x, iBufferNum: %d, iInState: 0x%x", |
631 iBufferStartAddr,iSize,iEndpointNumber,iBufferNum,iInState,iOutState); |
706 (TUint)iBufferStartAddr,iSize,iEndpointNumber,iBufferNum, (TUint)iInState); |
632 } |
707 |
633 |
708 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TENDPOINTBUFFER_DUMP_DUP1, " iOutState: 0x%x\n", iOutState); |
|
709 } |
|
710 |