--- a/kernel/eka/drivers/usbcsc/usbcsc_bil.cpp Thu Aug 19 11:14:22 2010 +0300
+++ b/kernel/eka/drivers/usbcsc/usbcsc_bil.cpp Tue Aug 31 16:34:26 2010 +0300
@@ -1,4 +1,4 @@
-// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
+// Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
// All rights reserved.
// This component and the accompanying materials are made available
// under the terms of the License "Eclipse Public License v1.0"
@@ -19,7 +19,10 @@
#include <e32std_private.h>
#include <d32usbcsc.h>
#include <e32debug.h>
-
+#include "OstTraceDefinitions.h"
+#ifdef OST_TRACE_COMPILER_IN_USE
+#include "usbcsc_bilTraces.h"
+#endif
/** @file usbcsc_bil.cpp
Buffer Interface Layer for USB Client Device driver stack, using shared chunks.
@@ -38,6 +41,31 @@
return r;
}
+// empty a endpoint buffer, this is called when device state enter undefined
+TInt RDevUsbcScClient::Empty(TUint aBufferOffset)
+{
+ TUint8* base = iSharedChunk.Base();
+ SUsbcScBufferHeader* endpointHdr = (SUsbcScBufferHeader*) (aBufferOffset + base);
+ TUint localTail = endpointHdr->iBilTail;
+ TUsbcScTransferHeader* currentTransfer;
+ TInt err=KErrNone;
+
+ while (ETrue)
+ {
+ if (localTail == (TUint) endpointHdr->iHead)
+ {
+ err = KErrNone;
+ break;
+ }
+ currentTransfer = (TUsbcScTransferHeader*) (base + localTail);
+ localTail = currentTransfer->iNext;
+ } // end while
+ endpointHdr->iBilTail = localTail;
+ endpointHdr->iTail = localTail;
+ return err;
+}
+
+
EXPORT_C TInt RDevUsbcScClient::FinalizeInterface(RChunk*& aChunk)
{
@@ -49,6 +77,35 @@
}
+EXPORT_C void RDevUsbcScClient::ResetAltSetting()
+ {
+ if (iAlternateSetting == 0)
+ return;
+ TUsbcScChunkHeader chunkHeader(iSharedChunk);
+
+ TInt ep;
+ TInt noEp;
+ TUint bufOff;
+ TUsbcScHdrEndpointRecord* endpointInf = NULL;
+
+ // check if alternate setting contains all IN endpoints
+ noEp = chunkHeader.GetNumberOfEndpoints(iAlternateSetting);
+
+ // for each used buffer.
+ for (ep=1;ep<=noEp;ep++)
+ {
+ bufOff = chunkHeader.GetBuffer(iAlternateSetting,ep,endpointInf)->Offset();
+
+ if (endpointInf->Direction() & KUsbScHdrEpDirectionOut)
+ {
+ Empty(bufOff); // we need to remove anythng in the way, and get it ready for reading.
+ }
+ }
+
+ iAlternateSetting = 0;
+ }
+
+
EXPORT_C TInt RDevUsbcScClient::OpenEndpoint(TEndpointBuffer& aEpB, TInt aEpI)
{
TUsbcScHdrEndpointRecord* endpointInf = NULL;
@@ -106,7 +163,7 @@
#ifdef _DEBUG
aEpB.Dump();
- RDebug::Printf("iEndpointStatus: %x \n",iEndpointStatus);
+ OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, RDEVUSBCSCCLIENT_OPENENDPOINT, "iEndpointStatus: %x \n",iEndpointStatus );
#endif
return KErrNone;
}
@@ -118,12 +175,14 @@
TInt RDevUsbcScClient::Drain(TUint aBufferOffset)
{
+
TUint8* base = iSharedChunk.Base();
SUsbcScBufferHeader* endpointHdr = (SUsbcScBufferHeader*) (aBufferOffset+base);
TUint localTail = endpointHdr->iBilTail;
TUsbcScTransferHeader* currentTransfer;
TUint16 next = (iAltSettingSeq+1)&0xFFFF;
TInt err=KErrNone;
+ TBool aZLP;
while (ETrue)
{
@@ -135,8 +194,13 @@
currentTransfer = (TUsbcScTransferHeader*) (base + localTail);
if (currentTransfer->iAltSettingSeq == next)
- {
+ {
iNewAltSetting=currentTransfer->iAltSetting; // record new alt setting
+ aZLP = (currentTransfer->iFlags & KUsbcScShortPacket)!=EFalse;
+ if ((currentTransfer->iBytes==0) && (!aZLP)) // take empty packet which is for alternate setting change
+ {
+ localTail = currentTransfer->iNext;
+ }
break;
}
else
@@ -164,7 +228,7 @@
// if alternate setting has not changed
return KErrNotReady;
else
- {
+ {
iNewAltSetting=currentTransfer->iAltSetting;
return KErrNone;
}
@@ -405,6 +469,7 @@
TUsbcScTransferHeader* currentTransfer;
TInt r;
+ TInt aBilTail;
do // until we have a transfer with data.
{
iEndpointHdr->iTail = iEndpointHdr->iBilTail;
@@ -415,19 +480,22 @@
return r;
}
currentTransfer = (TUsbcScTransferHeader*) (iBaseAddr + iEndpointHdr->iBilTail);
-
+ aBilTail = iEndpointHdr->iBilTail;
iEndpointHdr->iBilTail = currentTransfer->iNext;
aZLP = (currentTransfer->iFlags & KUsbcScShortPacket)!=EFalse;
if(currentTransfer->iAltSettingSeq != (iClient->iAltSettingSeq)) // if alternate setting has changed
{
if (currentTransfer->iAltSettingSeq == (iClient->iAltSettingSeq+1)) //Note- KIS ATM, if multiple alternate setting changes happen
+ {
iClient->iNewAltSetting = currentTransfer->iAltSetting; //before StartNextOutAlternateSetting is called,
- //this variable will reflect the latest requested AlternateSetting
+ //this variable will reflect the latest requested AlternateSetting
+ }
if (iEndpointNumber != KEp0Number)
{
+ iEndpointHdr->iBilTail = aBilTail;
// iOutState = EEOF;
return KErrEof;
}
@@ -450,8 +518,10 @@
if (iOutState)
return iOutState;
+
TUsbcScTransferHeader* currentTransfer;
TInt r;
+ TInt aBilTail;
do // until we have a transfer with data.
{
if(iEndpointHdr->iBilTail == iEndpointHdr->iHead) //If no new data, create request
@@ -464,6 +534,7 @@
}
currentTransfer = (TUsbcScTransferHeader*) (iBaseAddr + iEndpointHdr->iBilTail);
+ aBilTail = iEndpointHdr->iBilTail;
iEndpointHdr->iBilTail = currentTransfer->iNext;
aZLP = (currentTransfer->iFlags & KUsbcScShortPacket)!=EFalse; // True if short packet else false
@@ -472,16 +543,19 @@
if (currentTransfer->iAltSettingSeq == (iClient->iAltSettingSeq+1)) //Note- KIS ATM, if multiple alternate setting changes happen
iClient->iNewAltSetting = currentTransfer->iAltSetting; //before StartNextOutAlternateSetting is called,
//this variable will reflect the latest requested AlternateSetting
- Expire(currentTransfer->iData.i);
+
if (iEndpointNumber != KEp0Number)
{
+ iEndpointHdr->iBilTail = aBilTail;
// iOutState = EEOF;
return KErrEof;
}
else if ((currentTransfer->iBytes==0) && (!aZLP))
{
+ Expire(currentTransfer->iData.i);
return KErrAlternateSettingChanged;
}
+ Expire(currentTransfer->iData.i);
}
@@ -523,11 +597,12 @@
TInt prevTail = NULL;
TBool found = EFalse;
+
while (currentTail != iEndpointHdr->iBilTail)
- {
+ {
TUsbcScTransferHeader* currentTransfer = (TUsbcScTransferHeader*) (iBaseAddr + currentTail);
if (currentTail == offsetToExpire) // found which to expire
- {
+ {
found = ETrue;
// This offset is to be expired
if (prevTail == NULL)
@@ -547,7 +622,7 @@
}
prevTail = currentTail;
currentTail = currentTransfer->iNext;
- }
+ }
return found ? KErrNone : KErrNotFound;
}
@@ -627,7 +702,9 @@
EXPORT_C void TEndpointBuffer::Dump()
{
- RDebug::Printf("TEndpointBuffer::Dump iBufferStart: 0x%x, iSize: 0x%x, iEndpointNumber: 0x%x, iBufferNum: %d, iInState: 0x%x iOutState: 0x%x\n",
- iBufferStartAddr,iSize,iEndpointNumber,iBufferNum,iInState,iOutState);
+ 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",
+ (TUint)iBufferStartAddr,iSize,iEndpointNumber,iBufferNum, (TUint)iInState);
+
+ OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TENDPOINTBUFFER_DUMP_DUP1, " iOutState: 0x%x\n", iOutState);
}