|
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 /** |
|
17 @file |
|
18 @internalComponent |
|
19 */ |
|
20 |
|
21 #ifndef ZEROCOPYTRANSFERSTRATEGY_H |
|
22 #define ZEROCOPYTRANSFERSTRATEGY_H |
|
23 |
|
24 #include "usbtransferstrategy.h" |
|
25 |
|
26 |
|
27 NONSHARABLE_CLASS(RUsbZeroCopyTransferStrategy) : public RUsbTransferStrategy |
|
28 { |
|
29 public: |
|
30 RUsbZeroCopyTransferStrategy(); |
|
31 virtual TInt RegisterTransferDescriptor(RUsbTransferDescriptor& aTransferDesc, TInt aRequiredSize, TUint aStartAlignment, TInt aRequiredMaxPackets); |
|
32 virtual void ResetTransferDescriptors(); |
|
33 virtual TInt InitialiseTransferDescriptors(RUsbInterface& aInterface); |
|
34 |
|
35 virtual void Close(); |
|
36 |
|
37 public: // Interrupt transfer descriptor methods |
|
38 virtual TPtr8 IntrWritableBuffer(TInt aHandle); |
|
39 virtual void IntrSaveData(TInt aHandle, TInt aLength); |
|
40 virtual void IntrSetZlpStatus(TInt aHandle, RUsbTransferDescriptor::TZlpStatus aZlpStatus); |
|
41 virtual TPtrC8 IntrBuffer(TInt aHandle) const; |
|
42 public: // Bulk transfer descriptor methods |
|
43 virtual TPtr8 BulkWritableBuffer(TInt aHandle); |
|
44 virtual void BulkSaveData(TInt aHandle, TInt aLength); |
|
45 virtual void BulkSetZlpStatus(TInt aHandle, RUsbTransferDescriptor::TZlpStatus aZlpStatus); |
|
46 virtual TPtrC8 BulkBuffer(TInt aHandle) const; |
|
47 public: // Isochronous transfer descriptor methods |
|
48 virtual void IsocReset(TInt aHandle); |
|
49 virtual TPacketLengths IsocLengths(TInt aHandle); |
|
50 virtual TPacketResults IsocResults(TInt aHandle); |
|
51 virtual TInt IsocMaxPacketSize(TInt aHandle); |
|
52 virtual TPtr8 IsocWritablePackets(TInt aHandle, TInt aWriteHandle, TInt aNumPacketsRequested, TInt& aMaxNumPacketsAbleToWrite); |
|
53 virtual TInt IsocSaveMultiple(TInt aHandle, TInt aWriteHandle, TInt aNumOfPackets); |
|
54 virtual TPtrC8 IsocPackets(TInt aHandle, TInt aFirstPacketIndex, TInt aNumPacketsRequested, TInt& aNumPacketsReturned) const; |
|
55 virtual void IsocReceivePackets(TInt aHandle, TInt aNumOfPackets); |
|
56 |
|
57 |
|
58 private: // Standard (Bulk, Ctrl and Intr) Buffer methods |
|
59 TPtr8 WritableBuffer(TInt aHandle); |
|
60 void SaveData(TInt aHandle, TInt aLength); |
|
61 void SetZlpStatus(TInt aHandle, RUsbTransferDescriptor::TZlpStatus aZlpStatus); |
|
62 TPtrC8 Buffer(TInt aHandle) const; |
|
63 |
|
64 private: // Isoc Buffer methods |
|
65 void Reset(TInt aHandle); |
|
66 TPacketLengths Lengths(TInt aHandle); |
|
67 TPacketResults Results(TInt aHandle); |
|
68 TInt MaxPacketSize(TInt aHandle); |
|
69 TPtr8 WritablePackets(TInt aHandle, TInt aWriteHandle, TInt aNumPacketsRequested, TInt& aMaxNumPacketsAbleToWrite); |
|
70 TInt SaveMultiple(TInt aHandle, TInt aWriteHandle, TInt aNumOfPackets); |
|
71 TPtrC8 Packets(TInt aHandle, TInt aFirstPacketIndex, TInt aNumPacketsRequested, TInt& aNumPacketsReturned) const; |
|
72 void ReceivePackets(TInt aHandle, TInt aNumOfPackets); |
|
73 |
|
74 private: |
|
75 NONSHARABLE_STRUCT(TUsbTransferDescriptorDetails) |
|
76 { |
|
77 TUsbTransferDescriptorDetails(RUsbTransferDescriptor&, TInt, TUint, TInt); |
|
78 RUsbTransferDescriptor& iTransferDesc; |
|
79 const TInt iRequiredSize; |
|
80 TUint iRequiredAlignment; |
|
81 const TInt iRequiredMaxPackets; |
|
82 // Members to aid internal logic |
|
83 TInt iAssignedOffset; |
|
84 TInt iLengthsOffset; // Only applicable to isoc |
|
85 TInt iReqLenOffset; // Only applicable to isoc |
|
86 TInt iResultsOffset; // Only applicable to isoc |
|
87 TInt iNumElements; // Only applicable to isoc |
|
88 }; |
|
89 |
|
90 private: |
|
91 TInt CalculateDataLayout(TInt& aCurrentOffset, TInt& aNumStandardTransfers, TInt& aNumIsocTransfers, TInt& aNumIsocElements); |
|
92 void CalculateMetaDataLayout(TInt& aCurrentOffset, TInt& aMetaDataStart, TInt aNumStandardTransfers, TInt aNumIsocTransfers, TInt aNumIsocElements); |
|
93 void InitialiseMetaData(TInt aMetaDataOffset, TInt aNumStandardTransfers, TInt aNumIsocTransfers, TInt aNumIsocElements); |
|
94 TInt UsedPackets(TInt aHeaderOffset); |
|
95 TBool IsPowerOfTwo(TUint aNumber); |
|
96 TInt IncNeededToAlign(TInt aOffset, TUint aAlignment); |
|
97 static TBool CompareTransferDescriptor(const RUsbTransferDescriptor* aTransferDesc, const TUsbTransferDescriptorDetails& aDetails); |
|
98 |
|
99 private: //Calculate additional alignment related methods |
|
100 TInt GetMaximumMaxPacketSize(TInt& aMaxMaxBulk, TInt& aMaxMaxInterrupt); |
|
101 TInt CaculateAdditionalAlignment(TInt aCurrentOffset, TInt aMaxMaxBulk, TInt aMaxMaxInterrupt, TUsbTransferDescriptorDetails& aTransferDetails); |
|
102 private: |
|
103 RArray<TUsbTransferDescriptorDetails> iRegisteredTransfers; |
|
104 |
|
105 private: |
|
106 RUsbInterface* iInterfaceHandle; |
|
107 RChunk iChunk; |
|
108 TInt iBaseOffset; |
|
109 TInt iPageSize; |
|
110 }; |
|
111 |
|
112 #endif // ZEROCOPYTRANSFERSTRATEGY_H |