Rev. 0.2 1/04 Copyright © 2004 by Silicon Laboratories AN167
Introduction
This application note covers the implementation of a simple USB application using the interrupt transfer type. This
includes support for device enumeration, control and interrupt transactions, and definitions of descriptor data. The
purpose of this software is to give a simple working example of an interrupt transfer application; it does not include
support for multiple configurations, or other transfer types.
Overview by File Name
The firmware includes three header files and four source files. USB_MAIN.h consists of program constants,
definitions, and function prototypes. The firmware can run in either low or full-speed, depending on whether
_USB_LOW_SPEED_ is defined in this header file. USB_DESCRIPTOR.h contains the various structures used for
the different types of descriptors. USB_REGISTER.h contains addresses for the USB core registers, and register
access macros used throughout the software.
USB_MAIN.c - This file contains the main routine and some initialization subroutines. The main routine calls all
initialization routines, then starts an infinite loop of updating the OUT packet with information received from the
host, and the IN packet with information from the development boards peripherals. This file contains two interrupt
service routines (ISR). The first ISR is called when timer two overflows and checks to see if a switch has been
pressed or released. The second ISR is called when the analog to digital converter (ADC) finishes a conversion.
This ISR switches the ADC connection between the potentiometer wheel and the temperature sensor, allowing for
each to updated on every second conversion.
USB_DESCRIPTOR.c - This file contains the definitions of the actual descriptors used by the application. This
includes a single device descriptor, configuration descriptor and interface descriptor. Since this firmware uses
different endpoints for input and output transactions, there are two endpoint descriptors defined, one for each
direction. There are also three string descriptors defining the string language, manufacturer, and product type
respectively.
USB_ISR.c - The top-level USB ISR is located here. This is called when any USB type event occurs, and calls the
appropriate event handler between reset (USBReset), incoming setup packet (HandleSetup), incoming data packet
(HandleIN1), and out packet sent (HandleOUT2). The last three routines are responsible for actually reading and
writing from the different endpoints. The USB_State variable used in this file contains the current USB state of the
device, and the EpStatus array contains the current state of the 3 endpoints used.
USB_STD_REQ.c - All USB device requests, as defined in chapter 9 of USB specification, are handled by routines
in this file. All of these have been made as simple as possible, and return responses specifically for this software
implementation and which uses only one interface and one configuration. These routines all begin by checking the
setup packet and verifying the instruction matches exactly as specified by the USB specification, otherwise the
software returns a stall packet to the host.
Relevant Devices
This application note applies to the following devices:
C8051F320, C8051F321.
AN167
USB INTERRUPT EXAMPLE FIRMWARE- REFERENCE MANUAL