kerneltest/e32test/usbho/t_usbdi/src/hostisochronoustransfers.cpp
branchRCL_3
changeset 44 3e88ff8f41d5
parent 43 c1f20ce4abcf
equal deleted inserted replaced
43:c1f20ce4abcf 44:3e88ff8f41d5
     1 // Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Eclipse Public License v1.0"
     4 // under the terms of the License "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    15 // @internalComponent
    15 // @internalComponent
    16 // 
    16 // 
    17 //
    17 //
    18 
    18 
    19 #include "hosttransfers.h"
    19 #include "hosttransfers.h"
    20 #include "OstTraceDefinitions.h"
       
    21 #ifdef OST_TRACE_COMPILER_IN_USE
       
    22 #include "hostisochronoustransfersTraces.h"
       
    23 #endif
       
    24 #include <e32debug.h>
    20 #include <e32debug.h>
    25 #include <e32test.h>
    21 #include <e32test.h>
    26 
    22 
    27 extern RTest gtest;
    23 extern RTest gtest;
    28 
    24 
    33 							   TInt aMaxNumPackets,MTransferObserver& aObserver,TInt aTransferId)
    29 							   TInt aMaxNumPackets,MTransferObserver& aObserver,TInt aTransferId)
    34 :	CBaseTransfer(aPipe,aInterface,aObserver,aTransferId),
    30 :	CBaseTransfer(aPipe,aInterface,aObserver,aTransferId),
    35 	iTransferDescriptor(aMaxPacketSize,aMaxNumPackets),
    31 	iTransferDescriptor(aMaxPacketSize,aMaxNumPackets),
    36 	iMaxPacketSize(aMaxPacketSize)
    32 	iMaxPacketSize(aMaxPacketSize)
    37 	{
    33 	{
    38 	OstTraceFunctionEntryExt( CISOCHTRANSFER_CISOCHTRANSFER_ENTRY, this );
    34 	RDebug::Printf("aMaxPacketSize = %d, aMaxNumPackets = %d",aMaxPacketSize, aMaxNumPackets);
    39 	OstTraceExt2(TRACE_NORMAL, CISOCHTRANSFER_CISOCHTRANSFER, "aMaxPacketSize = %d, aMaxNumPackets = %d",aMaxPacketSize, aMaxNumPackets);
       
    40 	OstTraceFunctionExit1( CISOCHTRANSFER_CISOCHTRANSFER_EXIT, this );
       
    41 	}
    35 	}
    42 	
    36 	
    43 CIsochTransfer::~CIsochTransfer()
    37 CIsochTransfer::~CIsochTransfer()
    44 	{
    38 	{
    45 	OstTraceFunctionEntry1( CISOCHTRANSFER_CISOCHTRANSFER_ENTRY_DUP01, this );
    39 	LOG_FUNC
    46 	
    40 	
    47 	// Cancel the transfer
    41 	// Cancel the transfer
    48 
    42 
    49 	Cancel();
    43 	Cancel();
    50 	OstTraceFunctionExit1( CISOCHTRANSFER_CISOCHTRANSFER_EXIT_DUP01, this );
       
    51 	}	
    44 	}	
    52 	
    45 	
    53 TBool CIsochTransfer::DataPolled(TUint aPacketsToBeRead, RBuf8& aDataPolled) 
    46 TBool CIsochTransfer::DataPolled(TUint aPacketsToBeRead, RBuf8& aDataPolled) 
    54 	{
    47 	{
    55 	OstTraceFunctionEntryExt( CISOCHTRANSFER_DATAPOLLED_ENTRY, this );
    48 	LOG_FUNC
    56 	TInt numOfPacketsReturned = 0;	
    49 	TInt numOfPacketsReturned = 0;	
    57 	
    50 	
    58 	TInt firstPacketIndex = 0;
    51 	TInt firstPacketIndex = 0;
    59 	TInt totalPacketsRead = 0;
    52 	TInt totalPacketsRead = 0;
    60 	TInt packetsToBeRead = aPacketsToBeRead;
    53 	TInt packetsToBeRead = aPacketsToBeRead;
    62 	TUint dataPolledBufSize = iMaxPacketSize*aPacketsToBeRead;
    55 	TUint dataPolledBufSize = iMaxPacketSize*aPacketsToBeRead;
    63 	aDataPolled.CreateL(dataPolledBufSize);
    56 	aDataPolled.CreateL(dataPolledBufSize);
    64 		
    57 		
    65 	do {						
    58 	do {						
    66 		TPtrC8 ptrRet = iTransferDescriptor.Packets(firstPacketIndex, packetsToBeRead, numOfPacketsReturned); 
    59 		TPtrC8 ptrRet = iTransferDescriptor.Packets(firstPacketIndex, packetsToBeRead, numOfPacketsReturned); 
    67 		OstTrace1(TRACE_NORMAL, CISOCHTRANSFER_DATAPOLLED, "numOfPacketsReturned = %d", numOfPacketsReturned);
    60 		RDebug::Printf("numOfPacketsReturned = %d", numOfPacketsReturned);
    68 		OstTrace1(TRACE_NORMAL, CISOCHTRANSFER_DATAPOLLED_DUP01, "ptrRet.Length() = %d", ptrRet.Length());
    61 		RDebug::Printf("ptrRet.Length() = %d", ptrRet.Length());
    69 		firstPacketIndex = numOfPacketsReturned;
    62 		firstPacketIndex = numOfPacketsReturned;
    70 		totalPacketsRead += numOfPacketsReturned;
    63 		totalPacketsRead += numOfPacketsReturned;
    71 		packetsToBeRead = packetsToBeRead - numOfPacketsReturned;
    64 		packetsToBeRead = packetsToBeRead - numOfPacketsReturned;
    72 		OstTrace1(TRACE_NORMAL, CISOCHTRANSFER_DATAPOLLED_DUP02, "totalPacketsRead = %d", totalPacketsRead);	
    65 		RDebug::Printf("totalPacketsRead = %d", totalPacketsRead);	
    73 		OstTrace1(TRACE_NORMAL, CISOCHTRANSFER_DATAPOLLED_DUP03, "packetsToBeRead = %d", packetsToBeRead);	
    66 		RDebug::Printf("packetsToBeRead = %d", packetsToBeRead);	
    74 		aDataPolled.Append(ptrRet);		
    67 		aDataPolled.Append(ptrRet);		
    75 		}	while(totalPacketsRead != aPacketsToBeRead); 	
    68 		}	while(totalPacketsRead != aPacketsToBeRead); 	
    76 		
    69 		
    77 	OstTraceFunctionExitExt( CISOCHTRANSFER_DATAPOLLED_EXIT, this, ETrue );
       
    78 	return ETrue; 
    70 	return ETrue; 
    79 	}
    71 	}
    80 	
    72 	
    81 	
    73 	
    82 TInt CIsochTransfer::TransferInL(TInt aPacketsExpected)
    74 TInt CIsochTransfer::TransferInL(TInt aPacketsExpected)
    83 	{
    75 	{
    84 	OstTraceFunctionEntryExt( CISOCHTRANSFER_TRANSFERINL_ENTRY, this );
    76 	LOG_FUNC
    85 	
    77 	
    86 	// Activate the asynchronous transfer 	
    78 	// Activate the asynchronous transfer 	
    87 	OstTrace0(TRACE_NORMAL, CISOCHTRANSFER_TRANSFERINL, "Activating isoch. in transfer");
    79 	RDebug::Printf("Activating isoch. in transfer");
    88 	
    80 	
    89 	iTransferDescriptor.Reset();
    81 	iTransferDescriptor.Reset();
    90 	TPacketLengths fullLengths = iTransferDescriptor.Lengths();
    82 	TPacketLengths fullLengths = iTransferDescriptor.Lengths();
    91 	
    83 	
    92 	for(TInt packet = 0; packet < fullLengths.MaxNumPackets(); packet++)
    84 	for(TInt packet = 0; packet < fullLengths.MaxNumPackets(); packet++)
    93 		{
    85 		{
    94 		fullLengths[packet] = iMaxPacketSize;
    86 		fullLengths[packet] = iMaxPacketSize;
    95 		}	
    87 		}	
    96 
    88 
    97 	OstTrace1(TRACE_NORMAL, CISOCHTRANSFER_TRANSFERINL_DUP01, "fullLengths.MaxNumPackets() == %d",fullLengths.MaxNumPackets());
    89 	RDebug::Printf("fullLengths.MaxNumPackets() == %d",fullLengths.MaxNumPackets());
    98 	iTransferDescriptor.ReceivePackets(aPacketsExpected);
    90 	iTransferDescriptor.ReceivePackets(aPacketsExpected);
    99 		
    91 		
   100 	Pipe().Transfer(iTransferDescriptor,iStatus);
    92 	Pipe().Transfer(iTransferDescriptor,iStatus);
   101 	SetActive();
    93 	SetActive();
   102 	OstTraceFunctionExitExt( CISOCHTRANSFER_TRANSFERINL_EXIT, this, KErrNone );
       
   103 	return KErrNone;																
    94 	return KErrNone;																
   104 	}
    95 	}
   105 		
    96 		
   106 TInt CIsochTransfer::RegisterTransferDescriptor()
    97 TInt CIsochTransfer::RegisterTransferDescriptor()
   107 	{
    98 	{
   108 	OstTraceFunctionEntry1( CISOCHTRANSFER_REGISTERTRANSFERDESCRIPTOR_ENTRY, this );
    99 	LOG_FUNC
   109 	
   100 	
   110 	// Register the transfer descriptor with the interface	
   101 	// Register the transfer descriptor with the interface	
   111 	TInt err(Interface().RegisterTransferDescriptor(iTransferDescriptor));
   102 	TInt err(Interface().RegisterTransferDescriptor(iTransferDescriptor));
   112 	if(err != KErrNone)
   103 	if(err != KErrNone)
   113 		{
   104 		{
   114 		OstTrace1(TRACE_NORMAL, CISOCHTRANSFER_REGISTERTRANSFERDESCRIPTOR, "<Error %d> Unable to register transfer descriptor",err);
   105 		RDebug::Printf("<Error %d> Unable to register transfer descriptor",err);
   115 		}
   106 		}
   116 	OstTraceFunctionExitExt( CISOCHTRANSFER_REGISTERTRANSFERDESCRIPTOR_EXIT, this, err );
       
   117 	return err;	
   107 	return err;	
   118 	}
   108 	}
   119 	
   109 	
   120 TInt CIsochTransfer::PrepareTransfer(const TDesC8& aIsochData)
   110 TInt CIsochTransfer::PrepareTransfer(const TDesC8& aIsochData)
   121 	{
   111 	{
   122 OstTraceFunctionEntryExt( CISOCHTRANSFER_PREPARETRANSFER_ENTRY, this );
   112 	LOG_FUNC
   123 
   113 
   124 	//	
   114 	//	
   125 	iTransferDescriptor.Reset();
   115 	iTransferDescriptor.Reset();
   126 	TPacketLengths fullLengths = iTransferDescriptor.Lengths();
   116 	TPacketLengths fullLengths = iTransferDescriptor.Lengths();
   127 
   117 
   128 	OstTrace1(TRACE_NORMAL, CISOCHTRANSFER_PREPARETRANSFER, "fullLengths.MaxNumPackets() == %d",fullLengths.MaxNumPackets());
   118 	RDebug::Printf("fullLengths.MaxNumPackets() == %d",fullLengths.MaxNumPackets());
   129 	
   119 	
   130 	//	
   120 	//	
   131 	TInt bytesRemaining(aIsochData.Size());
   121 	TInt bytesRemaining(aIsochData.Size());
   132 	TInt maxAvailablePacketSlots;
   122 	TInt maxAvailablePacketSlots;
   133 	TInt startOffset(0);
   123 	TInt startOffset(0);
   134 	TInt startPacket(0); 
   124 	TInt startPacket(0); 
   135 	
   125 	
   136 	OstTrace1(TRACE_NORMAL, CISOCHTRANSFER_PREPARETRANSFER_DUP01, "Audio data is %d bytes",bytesRemaining);
   126 	RDebug::Printf("Audio data is %d bytes",bytesRemaining);
   137 	
   127 	
   138 	// Keep saving the isoch data to transfer in each packet buffer supplied 
   128 	// Keep saving the isoch data to transfer in each packet buffer supplied 
   139 	// by the transfer descriptor
   129 	// by the transfer descriptor
   140 
   130 
   141 	while(bytesRemaining)
   131 	while(bytesRemaining)
   144 		TPtr8 packetBuffer = iTransferDescriptor.WritablePackets(bytesRemaining/iMaxPacketSize,maxAvailablePacketSlots);
   134 		TPtr8 packetBuffer = iTransferDescriptor.WritablePackets(bytesRemaining/iMaxPacketSize,maxAvailablePacketSlots);
   145 		TInt dataToWrite = Min(bytesRemaining,packetBuffer.MaxSize());		
   135 		TInt dataToWrite = Min(bytesRemaining,packetBuffer.MaxSize());		
   146 		
   136 		
   147 		if(dataToWrite == 0)
   137 		if(dataToWrite == 0)
   148 			{
   138 			{
   149 			OstTrace0(TRACE_NORMAL, CISOCHTRANSFER_PREPARETRANSFER_DUP02, "<Warning> dropping the rest of the isoch data");
   139 			RDebug::Printf("<Warning> dropping the rest of the isoch data");
   150 			break;
   140 			break;
   151 			}
   141 			}
   152 		
   142 		
   153 		// Validate entire buffer as it is going to be filled
   143 		// Validate entire buffer as it is going to be filled
   154 		
   144 		
   165 		iTransferDescriptor.SaveMultiple(maxPacket);
   155 		iTransferDescriptor.SaveMultiple(maxPacket);
   166 		bytesRemaining -= maxPacket * iMaxPacketSize;
   156 		bytesRemaining -= maxPacket * iMaxPacketSize;
   167 		startOffset += maxPacket * iMaxPacketSize;
   157 		startOffset += maxPacket * iMaxPacketSize;
   168 		startPacket += maxPacket;
   158 		startPacket += maxPacket;
   169 		}	
   159 		}	
   170 	OstTraceFunctionExitExt( CISOCHTRANSFER_PREPARETRANSFER_EXIT, this, KErrNone );
       
   171 	return KErrNone;
   160 	return KErrNone;
   172 	}
   161 	}
   173 
   162 
   174 TInt CIsochTransfer::TransferOut()
   163 TInt CIsochTransfer::TransferOut()
   175 	{	
   164 	{	
   176 	OstTraceFunctionEntry1( CISOCHTRANSFER_TRANSFEROUT_ENTRY, this );
       
   177 	// Transfer the iscohronous data	
   165 	// Transfer the iscohronous data	
   178 	OstTrace0(TRACE_NORMAL, CISOCHTRANSFER_TRANSFEROUT, "Activating isochronous out transfer");
   166 	RDebug::Printf("Activating isochronous out transfer");
   179 	Pipe().Transfer(iTransferDescriptor,iStatus);
   167 	Pipe().Transfer(iTransferDescriptor,iStatus);
   180 	SetActive();
   168 	SetActive();
   181 	OstTraceFunctionExitExt( CISOCHTRANSFER_TRANSFEROUT_EXIT, this, KErrNone );
       
   182 	return KErrNone;
   169 	return KErrNone;
   183 	}
   170 	}
   184 	
   171 	
   185 		
   172 		
   186 	}
   173 	}