![FTDI FT51A Application Note Download Page 139](http://html1.mh-extra.com/html/ftdi/ft51a/ft51a_application-note_2341158139.webp)
Application Note
AN_289 FT51A Programming Guide
Version 1.0
Document Reference No.: FT_000962 Clearance No.: FTDI# 483
138
Copyright © 2015 Future Technology Devices International Limited
3.1.1.3
get_system_clock()
File: ft51_general_config_get_system_clock.c
The function returns an enumerated value allowing the current frequency of the FT51A clock to be
determined.
3.1.1.4
set_system_clock()
File: ft51_general_config_set_system_clock.c
The system clock frequency can be adjusted by changing the SYSTEM_CLOCK_DIVIDER register.
This function abstracts the process using one of the enumerated clock frequency values.
3.1.2
USB Library
The USB library is designed to manage the interface from the FT51A device to the host. The library
invokes call-back functions in the application code when certain events happen, such as the host
issuing a standard request, or resetting the bus.
There are 2 control endpoints, IN and OUT; in default mode there are 2 other pairs of endpoints;
in extended mode there are 6 other pairs of endpoints. The control endpoints are always enabled;
however, other endpoints must be enabled by code when required.
Call-backs are nominated using the USB_initialise() function call. This function will also setup an
interrupt handler for USB interrupts and create the control endpoints that are always required in a
USB device.
The USB_process() function is called during the application’s main loop to perform required USB
operations via the call-back functions. This allows the call-backs to be run by the application and
not at interrupt level.
Non-control endpoints must be created by a call to USB_create_endpoint() before being used. An
endpoint is described in this library by both the endpoint number and its direction. Once created,
an endpoint can be removed with USB_free_endpoint().
The application will use the USB_transfer() function to send information to the host via IN
endpoints. The same function called on an OUT endpoint will receive any data pending from the
host.
There is a memory structure associated with an endpoint and code to process interrupts. Therefore
the number of endpoints to be used can be defined in the application as a build definition. When
building the USB library files add the following macro to the SDCC compiler command line (where
x is the number of endpoints):
–
D USB_MAX_ENDPOINT_COUNT=x
Additional parameters checking for endpoint functions can be enabled by setting the following
macro:
–
D USB_ENDPOINT_CHECKS=1
This is normally disabled to save code space.
Source Folder: usb
3.1.2.1
USB_initialise
File: ft51_usb_initialise.c
Requires: ft51_usb_remote_wakeup_feature.c, ft51_usb_endpoint.c, ft51_interrupts.c
This is called to initialise the USB library with call-back functions, configure the hub device and set
the initial size for the control endpoints. It will also enable and configure the USB peripheral device
to a state where it can receive and respond to SETUP packets from the host.
The call-back functions passed to this function will allow the USB device to be enumerated by the
host and respond to all required SETUP requests from the host device driver.