|
1 // Copyright (c) 2007-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 // |
|
15 |
|
16 #include <d32usbtransfers.h> |
|
17 |
|
18 #include <d32usbdi_errors.h> |
|
19 #include "usbtransferstrategy.h" |
|
20 #include "usbdiutils.h" |
|
21 |
|
22 |
|
23 // ======================== |
|
24 // RUsbTransferDescriptor |
|
25 // ======================== |
|
26 |
|
27 /** |
|
28 Constructor protected to as this class is only intended as a base class. |
|
29 */ |
|
30 RUsbTransferDescriptor::RUsbTransferDescriptor(TTransferType aType, TInt aMaxSize, TInt aMaxNumPackets) |
|
31 : iHandle(KInvalidHandle) |
|
32 , iType(aType) |
|
33 , iMaxSize(aMaxSize) |
|
34 , iMaxNumPackets(aMaxNumPackets) |
|
35 { |
|
36 } |
|
37 |
|
38 /** |
|
39 Releases resources allocated to this transfer descriptor. |
|
40 */ |
|
41 EXPORT_C void RUsbTransferDescriptor::Close() |
|
42 { |
|
43 // Do nothing - the buffer is owned by the {R,D}UsbInterface. |
|
44 // This is provided in case the descriptor owns resources in future. |
|
45 } |
|
46 |
|
47 |
|
48 // ============================ |
|
49 // RUsbIsocTransferDescriptor |
|
50 // ============================ |
|
51 |
|
52 EXPORT_C RUsbIsocTransferDescriptor::RUsbIsocTransferDescriptor(TInt aMaxSize, TInt aMaxNumPackets) |
|
53 : RUsbTransferDescriptor(EIsochronous, aMaxSize, aMaxNumPackets) |
|
54 , iWriteHandle(KInvalidHandle) |
|
55 { |
|
56 } |
|
57 |
|
58 EXPORT_C void RUsbIsocTransferDescriptor::Reset() |
|
59 { |
|
60 __ASSERT_ALWAYS(iHandle != KInvalidHandle, UsbdiUtils::Panic(UsbdiPanics::EBadIsocTransferDescriptorHandle)); |
|
61 iWriteHandle = iHandle; |
|
62 iTransferStrategy->IsocReset(iHandle); |
|
63 } |
|
64 |
|
65 EXPORT_C TPacketLengths RUsbIsocTransferDescriptor::Lengths() |
|
66 { |
|
67 __ASSERT_ALWAYS(iHandle != KInvalidHandle, UsbdiUtils::Panic(UsbdiPanics::EBadIsocTransferDescriptorHandle)); |
|
68 return iTransferStrategy->IsocLengths(iHandle); |
|
69 } |
|
70 |
|
71 EXPORT_C TPacketResults RUsbIsocTransferDescriptor::Results() |
|
72 { |
|
73 __ASSERT_ALWAYS(iHandle != KInvalidHandle, UsbdiUtils::Panic(UsbdiPanics::EBadIsocTransferDescriptorHandle)); |
|
74 return iTransferStrategy->IsocResults(iHandle); |
|
75 } |
|
76 |
|
77 EXPORT_C TInt RUsbIsocTransferDescriptor::MaxPacketSize() |
|
78 { |
|
79 __ASSERT_ALWAYS(iHandle != KInvalidHandle, UsbdiUtils::Panic(UsbdiPanics::EBadIsocTransferDescriptorHandle)); |
|
80 return iTransferStrategy->IsocMaxPacketSize(iHandle); |
|
81 } |
|
82 |
|
83 EXPORT_C TPtr8 RUsbIsocTransferDescriptor::WritablePackets(TInt aNumPacketsRequested, TInt& aMaxNumOfPacketsAbleToWrite) |
|
84 { |
|
85 __ASSERT_ALWAYS(iHandle != KInvalidHandle, UsbdiUtils::Panic(UsbdiPanics::EBadIsocTransferDescriptorHandle)); |
|
86 if(iWriteHandle == KInvalidHandle) |
|
87 { |
|
88 return TPtr8(NULL, 0); |
|
89 } |
|
90 return iTransferStrategy->IsocWritablePackets(iHandle, iWriteHandle, aNumPacketsRequested, aMaxNumOfPacketsAbleToWrite); |
|
91 } |
|
92 |
|
93 EXPORT_C void RUsbIsocTransferDescriptor::SaveMultiple(TInt aNumOfPackets) |
|
94 { |
|
95 __ASSERT_ALWAYS(iHandle != KInvalidHandle, UsbdiUtils::Panic(UsbdiPanics::EBadIsocTransferDescriptorHandle)); |
|
96 __ASSERT_ALWAYS(iWriteHandle != KInvalidHandle, UsbdiUtils::Panic(UsbdiPanics::EBadIsocTransferDescriptorWriteHandle)); |
|
97 TInt writeHandle = iTransferStrategy->IsocSaveMultiple(iHandle, iWriteHandle, aNumOfPackets); |
|
98 iWriteHandle = (writeHandle < 0) ? KInvalidHandle : writeHandle; |
|
99 } |
|
100 |
|
101 EXPORT_C TPtrC8 RUsbIsocTransferDescriptor::Packets(TInt aFirstPacketIndex, TInt aNumPacketsRequested, TInt& aNumOfPacketsReturned) const |
|
102 { |
|
103 __ASSERT_ALWAYS(iHandle != KInvalidHandle, UsbdiUtils::Panic(UsbdiPanics::EBadIsocTransferDescriptorHandle)); |
|
104 return iTransferStrategy->IsocPackets(iHandle, aFirstPacketIndex, aNumPacketsRequested, aNumOfPacketsReturned); |
|
105 } |
|
106 |
|
107 EXPORT_C void RUsbIsocTransferDescriptor::ReceivePackets(TInt aNumOfPackets) |
|
108 { |
|
109 __ASSERT_ALWAYS(iHandle != KInvalidHandle, UsbdiUtils::Panic(UsbdiPanics::EBadIsocTransferDescriptorHandle)); |
|
110 iTransferStrategy->IsocReceivePackets(iHandle, aNumOfPackets); |
|
111 } |
|
112 |
|
113 |
|
114 // ============================ |
|
115 // RUsbBulkTransferDescriptor |
|
116 // ============================ |
|
117 |
|
118 EXPORT_C RUsbBulkTransferDescriptor::RUsbBulkTransferDescriptor(TInt aMaxSize) |
|
119 : RUsbTransferDescriptor(EBulk, aMaxSize, 0) |
|
120 { |
|
121 } |
|
122 |
|
123 /** |
|
124 @return A modifiable pointer to the entire data buffer. |
|
125 */ |
|
126 EXPORT_C TPtr8 RUsbBulkTransferDescriptor::WritableBuffer() |
|
127 { |
|
128 __ASSERT_ALWAYS(iHandle != KInvalidHandle, UsbdiUtils::Panic(UsbdiPanics::EBadBulkTransferDescriptorHandle)); |
|
129 return iTransferStrategy->BulkWritableBuffer(iHandle); |
|
130 } |
|
131 |
|
132 /** |
|
133 Update the transfer descriptor given the length of data supplied. |
|
134 @param[in] aLength Length of data to write or expect. |
|
135 */ |
|
136 EXPORT_C void RUsbBulkTransferDescriptor::SaveData(TInt aLength) |
|
137 { |
|
138 __ASSERT_ALWAYS(iHandle != KInvalidHandle, UsbdiUtils::Panic(UsbdiPanics::EBadBulkTransferDescriptorHandle)); |
|
139 iTransferStrategy->BulkSaveData(iHandle, aLength); |
|
140 } |
|
141 |
|
142 /** |
|
143 @return A non-modifiable pointer to the entire data buffer. |
|
144 */ |
|
145 EXPORT_C TPtrC8 RUsbBulkTransferDescriptor::Buffer() const |
|
146 { |
|
147 __ASSERT_ALWAYS(iHandle != KInvalidHandle, UsbdiUtils::Panic(UsbdiPanics::EBadBulkTransferDescriptorHandle)); |
|
148 return iTransferStrategy->BulkBuffer(iHandle); |
|
149 } |
|
150 |
|
151 /** |
|
152 @param aZlpStatus the ZLP type to use for the transfer |
|
153 */ |
|
154 EXPORT_C void RUsbBulkTransferDescriptor::SetZlpStatus(TZlpStatus aZlpStatus) |
|
155 { |
|
156 __ASSERT_ALWAYS(iHandle != KInvalidHandle, UsbdiUtils::Panic(UsbdiPanics::EBadBulkTransferDescriptorHandle)); |
|
157 iTransferStrategy->BulkSetZlpStatus(iHandle, aZlpStatus); |
|
158 } |
|
159 |
|
160 |
|
161 // ============================ |
|
162 // RUsbIntrTransferDescriptor |
|
163 // ============================ |
|
164 |
|
165 EXPORT_C RUsbIntrTransferDescriptor::RUsbIntrTransferDescriptor(TInt aMaxSize) |
|
166 : RUsbTransferDescriptor(EInterrupt, aMaxSize, 0) |
|
167 { |
|
168 } |
|
169 |
|
170 /** |
|
171 @return A modifiable pointer to the entire data buffer. |
|
172 */ |
|
173 EXPORT_C TPtr8 RUsbIntrTransferDescriptor::WritableBuffer() |
|
174 { |
|
175 __ASSERT_ALWAYS(iHandle != KInvalidHandle, UsbdiUtils::Panic(UsbdiPanics::EBadIntrTransferDescriptorHandle)); |
|
176 return iTransferStrategy->IntrWritableBuffer(iHandle); |
|
177 } |
|
178 |
|
179 /** |
|
180 Update the transfer descriptor given the length of data supplied. |
|
181 @param[in] aLength Length of data to write or expect. |
|
182 */ |
|
183 EXPORT_C void RUsbIntrTransferDescriptor::SaveData(TInt aLength) |
|
184 { |
|
185 __ASSERT_ALWAYS(iHandle != KInvalidHandle, UsbdiUtils::Panic(UsbdiPanics::EBadIntrTransferDescriptorHandle)); |
|
186 iTransferStrategy->IntrSaveData(iHandle, aLength); |
|
187 } |
|
188 |
|
189 /** |
|
190 @return A non-modifiable pointer to the entire data buffer. |
|
191 */ |
|
192 EXPORT_C TPtrC8 RUsbIntrTransferDescriptor::Buffer() const |
|
193 { |
|
194 __ASSERT_ALWAYS(iHandle != KInvalidHandle, UsbdiUtils::Panic(UsbdiPanics::EBadIntrTransferDescriptorHandle)); |
|
195 return iTransferStrategy->IntrBuffer(iHandle); |
|
196 } |
|
197 |
|
198 /** |
|
199 @param aZlpStatus the ZLP type to use for the transfer |
|
200 */ |
|
201 EXPORT_C void RUsbIntrTransferDescriptor::SetZlpStatus(TZlpStatus aZlpStatus) |
|
202 { |
|
203 __ASSERT_ALWAYS(iHandle != KInvalidHandle, UsbdiUtils::Panic(UsbdiPanics::EBadIntrTransferDescriptorHandle)); |
|
204 return iTransferStrategy->IntrSetZlpStatus(iHandle, aZlpStatus); |
|
205 } |