AN232B-03 Optimising D2XX Data Throughput

Future Technology Devices
International Ltd.
AN232B-03 Optimizing D2XX Data
Throughput
Copyright © 2006 Future Technology Devices International Ltd.
I
AN232B-03 Optimising D2XX Data Throughput
Table of Contents
Part I D2XX Applications - Optimizing
Data Throughput Over USB
2
1 Introduction
................................................................................................................................... 2
2 Transfer Sizes
................................................................................................................................... 3
3 Driver Operation
................................................................................................................................... 4
4 Optimizing...................................................................................................................................
Performance
5
Part II Revision History, Disclaimer, and
Contact Information
6
1 Document...................................................................................................................................
Revision History
6
2 Disclaimer................................................................................................................................... 7
3 Contact Information
................................................................................................................................... 8
9
Index
Copyright © 2006 Future Technology Devices International Ltd.
D2XX Applications - Optimizing Data Throughput Over USB
1
D2XX Applications - Optimizing Data Throughput Over
USB
1.1
Introduction
2
This application note provides guidelines for achieving optimal performance over USB from D2XX
applications.
Copyright © 2006 Future Technology Devices International Ltd.
3
1.2
AN232B-03 Optimising D2XX Data Throughput
Transfer Sizes
The maximum transfer size over USB is setup once and for all when a device is initialized. An
application can change the current USB transfer size to a value not exceeding the maximum USB
transfer size. The best transfer size for an application depends on its type. For example, an
application that handles streaming data will run more efficiently with a large transfer size, whereas
a smaller transfer size may be more suited to an application that handles small amounts of data.
Copyright © 2006 Future Technology Devices International Ltd.
D2XX Applications - Optimizing Data Throughput Over USB
1.3
4
Driver Operation
In the D2XX device driver, the maximum USB transfer size is set at 64Kbytes. This is necessary in
order to support USB2.0 controllers: on USB2.0, we have found that transfer sizes greater than
64K fail catastrophically.
Current USB transfer size can be changed using the function FT_SetUSBParameters. The change
comes into effect immediately, and any data that was held in the driver at the time of the change is
lost.
Note that, currently, FT_SetUSBParameters supports transfer size changes for the IN endpoint
only, and the remainder of this note is restricted to consideration of read requests.
When a device is opened, the driver allocates two buffers: a USB transfer buffer of maximum USB
transfer size bytes and a read buffer whose size is based on, but not the same as, the maximum
USB transfer size. The current USB transfer size is set by default to 4Kbytes, but an application
may setup the current USB transfer size anytime after a device has been opened. The driver
performs USB requests of any size up to the current USB transfer size, then copies the data to the
read buffer. The actual USB request size is determined by the space that is currently available in
the read buffer. If the read buffer becomes full (i.e. there is not enough space in the read buffer to
hold data returned from a USB request), the driver will stop issuing USB requests until space
becomes available.
Data is removed from the read buffer when the application performs a read request. So the rate at
which the application issues read requests has a direct bearing on the driver's ability to keep
issuing USB requests. USB requests will continue to be issued as long as the application performs
enough read requests to ensure that the read buffer does not become full.
Copyright © 2006 Future Technology Devices International Ltd.
5
1.4
AN232B-03 Optimising D2XX Data Throughput
Optimizing Performance
The question of how to setup an application for optimized data throughput is complicated by the
format of the data that is transferred over USB. Data is transferred over USB in a series of 64 byte
packets. Each packets contains two bytes that are reserved by FTDI and 62 bytes of actual data.
So a 4Kbyte USB transaction contains 3968 bytes of actual data, and a 64Kbyte transaction
contains 63488 bytes. In general, an x byte USB transaction yields x - ((x/64)*2) bytes of actual
data.
Optimized throughput occurs when the maximum amount of data is transferred in the least
possible number of USB transactions. The necessary condition is that the application's request
size must be matched to the current USB request size. More precisely, optimal throughput is
achieved when the application request size is a multiple of the number of actual data bytes
contained in the current USB transfer size. For example, using a current USB transfer size of
4Kbytes, optimal throughput is achieved with application request sizes that are multiples of 3968
bytes.
Maximum throughput is achieved using a current USB transfer size of 64K bytes, and application
requests that are multiples of 63448 bytes.
Copyright © 2006 Future Technology Devices International Ltd.
Revision History, Disclaimer, and Contact Information
2
Revision History, Disclaimer, and Contact Information
2.1
Document Revision History
Version
Release Date
Comments
1.0
March 2004
Initial release.
1.1
February 2006
Format and contact information updated.
Copyright © 2006 Future Technology Devices International Ltd.
6
7
2.2
AN232B-03 Optimising D2XX Data Throughput
Disclaimer
Copyright © 2006 Future Technology Devices International Ltd.
Neither the whole nor any part of the information contained in, or the product described in this
manual, may be adapted or reproduced in any material or electronic form without the prior written
consent of the copyright holder.
This product and its documentation are supplied on an as-is basis and no warranty as to their
suitability for any particular purpose is either made or implied.
Future Technology Devices International Ltd. will not accept any claim for damages howsoever
arising as a result of use or failure of this product. Your statutory rights are not affected.
This product or any variant of it is not intended for use in any medical appliance, device or system
in which the failure of the product might reasonably be expected to result in personal injury.
This document provides preliminary information that may be subject to change without notice.
Copyright © 2006 Future Technology Devices International Ltd.
Revision History, Disclaimer, and Contact Information
2.3
Contact Information
Head Office - Glasgow, UK
Future Technology Devices International Limited
373 Scotland Street
Glasgow
G5 8QB
United Kingdom
Tel: +44 (0) 141 429 2777
Fax: +44 (0) 141 429 2758
E-Mail (Sales): [email protected]
E-Mail (Support): [email protected]
E-Mail (General Enquiries): [email protected]
Web Site URL: http://www.ftdichip.com
Web Shop URL: http://apple.clickandbuild.com/cnb/shop/ftdichip
Branch Office - Taiwan
Future Technology Devices International Limited (Taiwan)
4F, No 16-1, Sec. 6 Mincyuan East Road
Neihu District
Taipei 114
Taiwan
ROC
Tel: +886 2 8791 3570
Fax: +886 2 8791 3576
E-Mail (Sales): [email protected]
E-Mail (Support): [email protected]
E-Mail (General Enquiries): [email protected]
Web Site URL: http://www.ftdichip.com
Branch Office - Hillsboro, Oregon, USA
Future Technology Devices International Limited (USA)
5285 NE Elam Young Parkway
Suite B800
Hillsboro, OR 97124-6499
USA
Tel: +1 (503) 547-0988
Fax: +1 (503) 547-0987
E-Mail (Sales): [email protected]
E-Mail (Support): [email protected]
E-Mail (General Enquiries): [email protected]
Web Site URL: http://www.ftdichip.com
Agents and Sales Representatives
Please visit the Sales Network page of the FTDI Web site for the contact details of our
distributor(s) in your country.
Copyright © 2006 Future Technology Devices International Ltd.
8
AN232B-03 Optimising D2XX Data Throughput
9
Index
-BBuffers
4
-DD2XX 2, 4
Data Format
5
-FFT_SetUSBParameters
4
-IIN Endpoint
4
-MMaximum Transfer Size 3
Maximum USB Transfer Size
4
-PPackets
5
-RRead Buffer 4
Read Requests 4
-UUSB 2.0 Controllers 4
USB Request 4
USB Request Size 5
USB Transactions 5
USB transfer Buffer 4
USB Transfer Size 3, 4
Copyright © 2006 Future Technology Devices International Ltd.