sl@0: // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0: // All rights reserved.
sl@0: // This component and the accompanying materials are made available
sl@0: // under the terms of the License "Eclipse Public License v1.0"
sl@0: // which accompanies this distribution, and is available
sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0: //
sl@0: // Initial Contributors:
sl@0: // Nokia Corporation - initial contribution.
sl@0: //
sl@0: // Contributors:
sl@0: //
sl@0: // Description:
sl@0: //
sl@0: 
sl@0: #ifndef __D32USBTRANSFERS_H
sl@0: #define __D32USBTRANSFERS_H
sl@0: 
sl@0: #ifdef __KERNEL_MODE__
sl@0: #include <kernel/klib.h>
sl@0: #else
sl@0: #include <e32base.h>
sl@0: #endif
sl@0: #include <d32usbdi.h>
sl@0: 
sl@0: 
sl@0: class RUsbTransferStrategy;
sl@0: 
sl@0: /**
sl@0: Base class for all transfer descriptors.
sl@0: 
sl@0: @publishedPartner Intended to be available to 3rd parties later
sl@0: @prototype
sl@0: */
sl@0: NONSHARABLE_CLASS(RUsbTransferDescriptor)
sl@0: 	{
sl@0: public:
sl@0: 	enum TTransferType
sl@0: 		{
sl@0: 		EBulk,
sl@0: 		EIsochronous,
sl@0: 		EInterrupt
sl@0: 		};
sl@0: 
sl@0: 	enum TZlpStatus
sl@0: 		{
sl@0: 		ESuppressZlp,
sl@0: 		ESendZlpIfRequired, // Default
sl@0: 		EAlwaysSendZlp
sl@0: 		};
sl@0: 
sl@0: #ifndef __KERNEL_MODE__
sl@0: friend class RUsbPipe;
sl@0: friend class RUsbTransferStrategy;
sl@0: 
sl@0: public:
sl@0: 	virtual void Close();
sl@0: 
sl@0: protected:
sl@0: 	RUsbTransferDescriptor(TTransferType aType, TInt aMaxSize, TInt aMaxNumPackets);
sl@0: 	
sl@0: protected:
sl@0: 	static const TInt KInvalidHandle = -1;
sl@0: 
sl@0: protected:
sl@0: 	/**
sl@0: 	A pointer to the transfer strategy the descriptor is registered in.
sl@0: 	*/
sl@0: 	RUsbTransferStrategy* iTransferStrategy;
sl@0: 
sl@0: 	/**
sl@0: 	Handle into the transfer strategy for the descriptor.
sl@0: 	*/
sl@0: 	TInt iHandle;
sl@0: 
sl@0: public:
sl@0: 	/**
sl@0: 	The type of transfer descriptor this instance represents.
sl@0: 	*/
sl@0: 	const TTransferType iType;
sl@0: 
sl@0: 	/**
sl@0: 	For isochronous transfers this refers to the maximum packet size packets
sl@0: 	in this descriptor may be.
sl@0: 	For other transfers this refers to the maximum size of the transfer.
sl@0: 	*/
sl@0: 	const TInt iMaxSize;
sl@0: 
sl@0: 	/**
sl@0: 	Used to specify the maximum number of packets the descriptor will hold.
sl@0: 	*/
sl@0: 	const TInt iMaxNumPackets;
sl@0: #endif // __KERNEL_MODE__
sl@0: 	};
sl@0: 
sl@0: 
sl@0: #ifndef __KERNEL_MODE__
sl@0: 
sl@0: /**
sl@0: A class that refers to the list of packet lengths for a isochronous transfer
sl@0: descriptor.
sl@0: 
sl@0: @publishedPartner
sl@0: @prototype
sl@0: */
sl@0: NONSHARABLE_CLASS(TPacketLengths)
sl@0: 	{
sl@0: public:
sl@0: 	NONSHARABLE_CLASS(TLength)
sl@0: 		{
sl@0: 	public:
sl@0: 		IMPORT_C TUint16 operator=(TUint16 aValue);
sl@0: 		IMPORT_C operator TUint16() const;
sl@0: 	public:
sl@0: 		TLength(TUint16& aRecv, TUint16& aReq);
sl@0: 	private:
sl@0: 		TUint16& iRecv;
sl@0: 		TUint16& iReq;
sl@0: 		};
sl@0: public:
sl@0: 	IMPORT_C TLength At(TInt aIndex);
sl@0: 	IMPORT_C const TLength At(TInt aIndex) const;
sl@0: 	IMPORT_C TLength operator[](TInt aIndex);
sl@0: 	IMPORT_C const TLength operator[](TInt aIndex) const;
sl@0: 	IMPORT_C TInt MaxNumPackets();
sl@0: 
sl@0: public:
sl@0: 	TPacketLengths(TUint16* aRecvPtr, TUint16* aReqPtr, TInt& aMaxNumPackets);
sl@0: 
sl@0: private:
sl@0: 	TUint16* iRecvPtr;
sl@0: 	TUint16* iReqPtr;
sl@0: 	TInt& iMaxNumPackets;
sl@0: 	};
sl@0: 
sl@0: /**
sl@0: A class that refers to the list of packet results for a isochronous transfer
sl@0: descriptor.
sl@0: 
sl@0: @publishedPartner
sl@0: @prototype
sl@0: */
sl@0: NONSHARABLE_CLASS(TPacketResults)
sl@0: 	{
sl@0: public:
sl@0: 	IMPORT_C TInt At(TInt aIndex) const;
sl@0: 	IMPORT_C TInt operator[](TInt aIndex) const;
sl@0: 	IMPORT_C TInt MaxNumPackets();
sl@0: 
sl@0: public:
sl@0: 	TPacketResults(TInt* aResPtr, TInt& aMaxNumPackets);
sl@0: 	
sl@0: private:
sl@0: 	TInt* iResPtr;
sl@0: 	TInt& iMaxNumPackets;
sl@0: 	};
sl@0: 
sl@0: 
sl@0: /**
sl@0: Provides *SEQUENTIAL* access to the packet slots in an isochronous transfer descriptor.
sl@0: As some HCs may pack the buffer space tightly, with one packet starting immediately after the preceeding one,
sl@0: random access is not possible -- in this implementation, even replacing the content of a slot with another packet
sl@0: of the same size is not 'intentionally' possible.
sl@0: Note that reading data is possible in a random access manner -- the sequential constraint only applies to writing.
sl@0: @publishedPartner Intended to be available to 3rd parties later
sl@0: @prototype
sl@0: */
sl@0: NONSHARABLE_CLASS(RUsbIsocTransferDescriptor) : public RUsbTransferDescriptor
sl@0: 	{
sl@0: friend class RUsbTransferStrategy;
sl@0: 
sl@0: public:
sl@0:     IMPORT_C RUsbIsocTransferDescriptor(TInt aMaxPacketSize, TInt aMaxNumPackets);
sl@0: 
sl@0: public:
sl@0: 	IMPORT_C void Reset();
sl@0: 	IMPORT_C TPacketLengths Lengths();
sl@0: 	IMPORT_C TPacketResults Results();
sl@0: 	IMPORT_C TInt MaxPacketSize();
sl@0: 
sl@0: public:		// Sending
sl@0: 	IMPORT_C TPtr8 WritablePackets(TInt aNumPacketsRequested, TInt& aMaxNumOfPacketsAbleToWrite);
sl@0: 	IMPORT_C void SaveMultiple(TInt aNumOfPackets);
sl@0: 
sl@0: public:		// Receiving
sl@0: 	IMPORT_C TPtrC8 Packets(TInt aFirstPacketIndex, TInt aNumPacketsRequested, TInt& aNumOfPacketsReturned) const;
sl@0: 	IMPORT_C void ReceivePackets(TInt aNumOfPackets);
sl@0: 
sl@0: private:
sl@0: 	/**
sl@0: 	The handle to represent the current point in writing an isoc. transfer.
sl@0: 	*/
sl@0: 	TInt iWriteHandle;
sl@0: 	};
sl@0: 
sl@0: 
sl@0: /**
sl@0: Provides buffer management for Bulk transfers
sl@0: @publishedPartner Intended to be available to 3rd parties later
sl@0: @prototype
sl@0: */
sl@0: NONSHARABLE_CLASS(RUsbBulkTransferDescriptor) : public RUsbTransferDescriptor
sl@0: 	{
sl@0: public:
sl@0: 	IMPORT_C RUsbBulkTransferDescriptor(TInt aMaxSize);
sl@0: 
sl@0: public:		// Setters
sl@0: 	IMPORT_C TPtr8 WritableBuffer();
sl@0: 	IMPORT_C void SaveData(TInt aLength);
sl@0: 	IMPORT_C void SetZlpStatus(TZlpStatus aZlpStatus);
sl@0: 
sl@0: public:		// Getters
sl@0: 	IMPORT_C TPtrC8 Buffer() const;
sl@0: 	};
sl@0: 
sl@0: 
sl@0: 
sl@0: /**
sl@0: Provides buffer management for Interrupt transfers
sl@0: @publishedPartner Intended to be available to 3rd parties later
sl@0: @prototype
sl@0: */
sl@0: NONSHARABLE_CLASS(RUsbIntrTransferDescriptor) : public RUsbTransferDescriptor
sl@0: 	{
sl@0: public:
sl@0: 	IMPORT_C RUsbIntrTransferDescriptor(TInt aMaxSize);
sl@0: 
sl@0: public:		// Setters
sl@0: 	IMPORT_C TPtr8 WritableBuffer();
sl@0: 	IMPORT_C void SaveData(TInt aLength);
sl@0: 	IMPORT_C void SetZlpStatus(TZlpStatus aZlpStatus);
sl@0: 
sl@0: public:		// Getters
sl@0: 	IMPORT_C TPtrC8 Buffer() const;
sl@0: 	};
sl@0: 
sl@0: #endif // __KERNEL_MODE__
sl@0: 
sl@0: #endif	// __D32USBTRANSFERS_H