|
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 #ifndef __D32USBTRANSFERS_H |
|
17 #define __D32USBTRANSFERS_H |
|
18 |
|
19 #ifdef __KERNEL_MODE__ |
|
20 #include <kernel/klib.h> |
|
21 #else |
|
22 #include <e32base.h> |
|
23 #endif |
|
24 #include <d32usbdi.h> |
|
25 |
|
26 |
|
27 class RUsbTransferStrategy; |
|
28 |
|
29 /** |
|
30 Base class for all transfer descriptors. |
|
31 |
|
32 @publishedPartner Intended to be available to 3rd parties later |
|
33 @prototype |
|
34 */ |
|
35 NONSHARABLE_CLASS(RUsbTransferDescriptor) |
|
36 { |
|
37 public: |
|
38 enum TTransferType |
|
39 { |
|
40 EBulk, |
|
41 EIsochronous, |
|
42 EInterrupt |
|
43 }; |
|
44 |
|
45 enum TZlpStatus |
|
46 { |
|
47 ESuppressZlp, |
|
48 ESendZlpIfRequired, // Default |
|
49 EAlwaysSendZlp |
|
50 }; |
|
51 |
|
52 #ifndef __KERNEL_MODE__ |
|
53 friend class RUsbPipe; |
|
54 friend class RUsbTransferStrategy; |
|
55 |
|
56 public: |
|
57 virtual void Close(); |
|
58 |
|
59 protected: |
|
60 RUsbTransferDescriptor(TTransferType aType, TInt aMaxSize, TInt aMaxNumPackets); |
|
61 |
|
62 protected: |
|
63 static const TInt KInvalidHandle = -1; |
|
64 |
|
65 protected: |
|
66 /** |
|
67 A pointer to the transfer strategy the descriptor is registered in. |
|
68 */ |
|
69 RUsbTransferStrategy* iTransferStrategy; |
|
70 |
|
71 /** |
|
72 Handle into the transfer strategy for the descriptor. |
|
73 */ |
|
74 TInt iHandle; |
|
75 |
|
76 public: |
|
77 /** |
|
78 The type of transfer descriptor this instance represents. |
|
79 */ |
|
80 const TTransferType iType; |
|
81 |
|
82 /** |
|
83 For isochronous transfers this refers to the maximum packet size packets |
|
84 in this descriptor may be. |
|
85 For other transfers this refers to the maximum size of the transfer. |
|
86 */ |
|
87 const TInt iMaxSize; |
|
88 |
|
89 /** |
|
90 Used to specify the maximum number of packets the descriptor will hold. |
|
91 */ |
|
92 const TInt iMaxNumPackets; |
|
93 #endif // __KERNEL_MODE__ |
|
94 }; |
|
95 |
|
96 |
|
97 #ifndef __KERNEL_MODE__ |
|
98 |
|
99 /** |
|
100 A class that refers to the list of packet lengths for a isochronous transfer |
|
101 descriptor. |
|
102 |
|
103 @publishedPartner |
|
104 @prototype |
|
105 */ |
|
106 NONSHARABLE_CLASS(TPacketLengths) |
|
107 { |
|
108 public: |
|
109 NONSHARABLE_CLASS(TLength) |
|
110 { |
|
111 public: |
|
112 IMPORT_C TUint16 operator=(TUint16 aValue); |
|
113 IMPORT_C operator TUint16() const; |
|
114 public: |
|
115 TLength(TUint16& aRecv, TUint16& aReq); |
|
116 private: |
|
117 TUint16& iRecv; |
|
118 TUint16& iReq; |
|
119 }; |
|
120 public: |
|
121 IMPORT_C TLength At(TInt aIndex); |
|
122 IMPORT_C const TLength At(TInt aIndex) const; |
|
123 IMPORT_C TLength operator[](TInt aIndex); |
|
124 IMPORT_C const TLength operator[](TInt aIndex) const; |
|
125 IMPORT_C TInt MaxNumPackets(); |
|
126 |
|
127 public: |
|
128 TPacketLengths(TUint16* aRecvPtr, TUint16* aReqPtr, TInt& aMaxNumPackets); |
|
129 |
|
130 private: |
|
131 TUint16* iRecvPtr; |
|
132 TUint16* iReqPtr; |
|
133 TInt& iMaxNumPackets; |
|
134 }; |
|
135 |
|
136 /** |
|
137 A class that refers to the list of packet results for a isochronous transfer |
|
138 descriptor. |
|
139 |
|
140 @publishedPartner |
|
141 @prototype |
|
142 */ |
|
143 NONSHARABLE_CLASS(TPacketResults) |
|
144 { |
|
145 public: |
|
146 IMPORT_C TInt At(TInt aIndex) const; |
|
147 IMPORT_C TInt operator[](TInt aIndex) const; |
|
148 IMPORT_C TInt MaxNumPackets(); |
|
149 |
|
150 public: |
|
151 TPacketResults(TInt* aResPtr, TInt& aMaxNumPackets); |
|
152 |
|
153 private: |
|
154 TInt* iResPtr; |
|
155 TInt& iMaxNumPackets; |
|
156 }; |
|
157 |
|
158 |
|
159 /** |
|
160 Provides *SEQUENTIAL* access to the packet slots in an isochronous transfer descriptor. |
|
161 As some HCs may pack the buffer space tightly, with one packet starting immediately after the preceeding one, |
|
162 random access is not possible -- in this implementation, even replacing the content of a slot with another packet |
|
163 of the same size is not 'intentionally' possible. |
|
164 Note that reading data is possible in a random access manner -- the sequential constraint only applies to writing. |
|
165 @publishedPartner Intended to be available to 3rd parties later |
|
166 @prototype |
|
167 */ |
|
168 NONSHARABLE_CLASS(RUsbIsocTransferDescriptor) : public RUsbTransferDescriptor |
|
169 { |
|
170 friend class RUsbTransferStrategy; |
|
171 |
|
172 public: |
|
173 IMPORT_C RUsbIsocTransferDescriptor(TInt aMaxPacketSize, TInt aMaxNumPackets); |
|
174 |
|
175 public: |
|
176 IMPORT_C void Reset(); |
|
177 IMPORT_C TPacketLengths Lengths(); |
|
178 IMPORT_C TPacketResults Results(); |
|
179 IMPORT_C TInt MaxPacketSize(); |
|
180 |
|
181 public: // Sending |
|
182 IMPORT_C TPtr8 WritablePackets(TInt aNumPacketsRequested, TInt& aMaxNumOfPacketsAbleToWrite); |
|
183 IMPORT_C void SaveMultiple(TInt aNumOfPackets); |
|
184 |
|
185 public: // Receiving |
|
186 IMPORT_C TPtrC8 Packets(TInt aFirstPacketIndex, TInt aNumPacketsRequested, TInt& aNumOfPacketsReturned) const; |
|
187 IMPORT_C void ReceivePackets(TInt aNumOfPackets); |
|
188 |
|
189 private: |
|
190 /** |
|
191 The handle to represent the current point in writing an isoc. transfer. |
|
192 */ |
|
193 TInt iWriteHandle; |
|
194 }; |
|
195 |
|
196 |
|
197 /** |
|
198 Provides buffer management for Bulk transfers |
|
199 @publishedPartner Intended to be available to 3rd parties later |
|
200 @prototype |
|
201 */ |
|
202 NONSHARABLE_CLASS(RUsbBulkTransferDescriptor) : public RUsbTransferDescriptor |
|
203 { |
|
204 public: |
|
205 IMPORT_C RUsbBulkTransferDescriptor(TInt aMaxSize); |
|
206 |
|
207 public: // Setters |
|
208 IMPORT_C TPtr8 WritableBuffer(); |
|
209 IMPORT_C void SaveData(TInt aLength); |
|
210 IMPORT_C void SetZlpStatus(TZlpStatus aZlpStatus); |
|
211 |
|
212 public: // Getters |
|
213 IMPORT_C TPtrC8 Buffer() const; |
|
214 }; |
|
215 |
|
216 |
|
217 |
|
218 /** |
|
219 Provides buffer management for Interrupt transfers |
|
220 @publishedPartner Intended to be available to 3rd parties later |
|
221 @prototype |
|
222 */ |
|
223 NONSHARABLE_CLASS(RUsbIntrTransferDescriptor) : public RUsbTransferDescriptor |
|
224 { |
|
225 public: |
|
226 IMPORT_C RUsbIntrTransferDescriptor(TInt aMaxSize); |
|
227 |
|
228 public: // Setters |
|
229 IMPORT_C TPtr8 WritableBuffer(); |
|
230 IMPORT_C void SaveData(TInt aLength); |
|
231 IMPORT_C void SetZlpStatus(TZlpStatus aZlpStatus); |
|
232 |
|
233 public: // Getters |
|
234 IMPORT_C TPtrC8 Buffer() const; |
|
235 }; |
|
236 |
|
237 #endif // __KERNEL_MODE__ |
|
238 |
|
239 #endif // __D32USBTRANSFERS_H |