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