1. USB

USB Device
USB v1.5

Copyright © 2004, 2005 Cypress Semiconductor Inc. All Rights Reserved.

CY7C639/638/633XX User Module Data Sheet

Resources
Required
Optional
Memory
1499 Flash / 41 RAM
461 Flash / 27 RAM
HID Class Driver
~40 Flash/ 0 RAM + 9 Flash overhead for each String Descriptor
String Descriptor
User Developed Class Driver
Pins
2 (D+/D-)
Other Modules
PS/2 Device (USB-PS/2 Combi)
MSTIMER (for Suspend, HID Report Idle Timers)

Features and Overview

USB Device Interface Driver

Support for Interrupt and Control Transfer Types

Setup Wizard for easy and accurate descriptor generation

Runtime support for descriptor set selection

Optional USB String Descriptors

Optional HID Class support

USB Device Block Diagrams

Functional Description

The USB Device User Module provides a USB Chapter 9 compliant device framework. The user module provides a low level driver for the control endpoint that decodes and dispacthes requests from the USB Host. The user module supports the HID Class. USB descriptors can be configured with the USB Setup Wizard.

Timing

The USB Device User Module support USB 2.0 Low Speed operation on the enCoRe II device family.

Parameters and Resources

The USB Device User Module doe not use the PSoC Designer User Module Parameter Grid Display for personalization. Instead, it uses form driven USB Setup Wizard to define the USB descriptors for the application. From the descriptors, the Wizard personalizes the User Module.

Application Programming Interface

The Application Programming Interface routines in this section allow programmatic control of the USB User Module. The following sections describe descriptor generation and integration intolist the basic and device specific API functions. It is assumed that the developer has a basic understanding of the USB protocol and is familiar with the USB 2.0 specification, especially Chapter 9, USB Device Framework.

In the following API descriptions, parameter references for bDevice, bInterface, and bEP refer to the device index, interface index and endpoint number. The values are derived implicitly from the USB Setup Wizard.

bDevice ranges from 0 to the number of device descriptors defined in the USB Setup Wizard and are positionally dependent to the order in the USB Setup Wizard (bDevice = 0 is the top entry, bDevice = 1 for the second entry and so on).

bInterface ranges from 0 to the number of interfaces defined for a configuration and is positionally dependent to the order in the USB Setup Wizard.

bEP is the endpoint number specified in the Endpoint Descriptor.

Note The API routines for the USB user modules are not reentrant. Because they depend on internal global variables in RAM, executing these routines from an interrupt is not supported by the API support supplied with this user module. If this is a requirement for a design, contact the local Cypress Field Application Engineer.

Basic USB Device API 
Function
Description
void USB_Start(BYTE bDevice)
Enable user module for the using the data Device
void USB_Stop(void)
Disable user module.
BYTE USB_bCheckActivity(void)
Checks and clears the USB Bus Activity Flag. Returns 1 if the USB was active since the last check, otherwise returns 0.
BYTE USB_bGetConfiguration(void)
Returns the currently assigned configuration. Returns 0 if the device is not configured.
BYTE USB_bGetEPState(BYTE bEP)
Returns the current state of the specified USB endpoint.
2 = NO_EVENT_ALLOWED
1 = EVENT_PENDING
0 = NO_EVENT_PENDING
When an IN endpoint is configured during USB enumeration, the endpoint mode is set to NAK IN tokens and the endpoint state is set to EVENT_PENDING. EVENT_PENDING is equated with IN_BUFFER_EMPTY indicating that the endpoint is ready to accept new data for transfer to the host. The application loads the endpoint when the endpoint state is IN_BUFFER_EMPTY. The USB_XLoadEP function updates the endpoint mode to ACK the next IN token and sets the endpoint state to IN_BUFFER_FULL. When an IN transfer is ACK'ed, the SIE automatically changes the endpoint mode to NAK subsequent transfers. The endpoint ISR updates the endpoint state to IN_BUFFER_EMPTY.
When an OUT endpoint is configured during USB enumeration, the endpoint mode is set to NAK OUT tokens and the endpoint state is set to NO_EVENT_PENDING. NO_EVENT_PENDING is equated with OUT_BUFFER_EMPTY indicating that the endpoint is ready to accept new data from the host. The application provides data flow control by enabling the OUT endpoint using the application must enable the OUT endpoint using the USB_EnableEP function. After the OUT transfer is complete, the endpoint ISR sets the endpoint state to OUT_BUFFER_EMPTY.
BYTE USB_bGetEPCount(BYTE bEP)
Returns the current byte count from the specified USB endpoint.
BYTE USB_bRWUEnabled(void)
Returns 1 if the REMOTE WAKEUP has been enabled by the host, otherwise returns 0.
void USB_XLoadEP(BYTE*pSrc)
Loads and enables the specified USB endpoint for an IN transfer. Note: USB_XLoadEP should not be call directly. Rather, the macro USB_LoadEP should be used.
C Macro
USB_LoadEP(BYTE bEP, BYTE *pSrc, BYTE count)
Loads and enables the specified USB endpoint for an IN transfer.
void USB_EnableEP(BYTE bEP)
Enables the specified USB endpoint. This functions is used for OUT endpoints to set the endpoint mode to ACK the next OUT transfer. It also sets the endpoint state to OUT_BUFFER_EMPTY.
void USB_DisableEP(BYTE bEP)
Disables the specified USB endpoint. This function is used for OUT endpoints to set the endpoint mode to NAK subsequent OUT transfers. It does not change the endpoint state.
void USB_Force(BYTE bState)
Forces a J, K, or SE0 State on the USB D+/D- pins. Normally used for remote wakeup.
bState Parameters are:
USB_FORCE_J 0x02
USB_FORCE_K 0x01
USB_FORCE_SE0 0x00
USB_FORCE_NONE 0xFF
Note: When using this API Function and GPIO pins from Port 1 (P1.2-P1.7), the application should use the Port_1_Data_SHADE shadow register to ensure consistent data handling. From assembly language, you can access the Port_1_Data_SHADE RAM location directly. From C language, you should include an extern reference:
extern BYTE Port_1_Data_SHADE;  
void USB_Suspend(void)
Puts the USB Transceiver into power-down mode, while maintaining the USB address assigned by the USB host. To restore the USB Transceiver to normal operation, the USB_Resume function should be called.
void USB_Resume(void)
Puts the USB Transceiver into normal operation, following a call to USB_Suspend. It retains the USB address that had been assigned by the USB host.

Human Interface Device (HID) Class Support API 
Function
Description
BYTE USB_UpdateHIDTimer(BYTE)
Updates the HID Report timer for the specified interface and returns 1 if the timer expired and 0 if not. If the timer expired, it reloads the timer.
BYTE USB_bGetProtocol(BYTE)
Returns the protocol for the specified interface

USB_Start

Description:

Performs all required initialization for USB Device User Module.

C Prototype:

void  USB_Start(BYTE bDevice)  

Assembly:

call  USB_Start  

Parameters:

Register A contains the device number from the desired Device Descriptor set that was entered with the USB Setup Wizard.

Return Value:

None

Side Effects:

The A and X registers may be altered by this function.

USB_Stop

Description:

Performs all necessary shutdown task required for the USB User Module.

C Prototype:

void  USB_Stop(void)  

Assembly:

call  USB_Stop  

Parameters:

None

Return Value:

None

Side Effects:

The A and X registers may be altered by this function.

USB_USB_bCheckActivity

Description:

Checks for USB Bus Activity.

C Prototype:

BYTE  USB_bCheckActivity(void)  

Assembly:

call  USB_bCheckActivity  

Parameters:

None

Return Value:

Returns 1 if the USB was active since the last check, otherwise returns 0.

Side Effects:

The A and X registers may be altered by this function.

USB_bGetConfiguration

Description:

C Prototype:

BYTE  USB_bGetConfiguration(void)  

Assembly:

call  USB_bGetConfiguration  

Parameters:

None

Return Value:

Returns the currently assigned configuration. Returns 0 if the device is not configured.

Side Effects:

The A and X registers may be altered by this function.

USB_bGetEPState

Description:

Gets the Endpoint state for the specified endpoint. The endpoint can have one of three states, two of the states mean different things for IN and OUT endpoints. The table below outlines the possible states and their meaning for IN and OUT endpoints.

C Prototype:

BYTE  USB_bGetEPState(BYTE bEP)  

Assembly:

MOV		A, 1						; Select endpoint 1  
call  USB_bGetEPState  

Parameters:

Register A contains the endpoint number

Return Value:

Returns the current state of the specified USB endpoint.

State
Value
Description
NO_EVENT_PENDING
0x00
Indicates that the endpoint is awaiting SIE action
EVENT_PENDING
0x01
Indicates that the endpoint is awaiting CPU action
NO_EVENT_ALLOWED
0x02
Indicates that the endpoint is locked from access
IN_BUFFER_FULL
0x00
The IN endpoint is loaded and the mode is set to ACK IN
IN_BUFFER_EMPTY
0x01
An IN transaction has occurred and more data can be loaded
OUT_BUFFER_EMPTY
0x00
The OUT endpoint is set to ACK OUT and is waiting for data
OUT_BUFFER_FULL
0x01
An OUT transaction has occurred and data can be read

Side Effects:

The A and X registers may be altered by this function.

USB_bRWUEnabled

Description:

This functions returns the value of the endpoint count register. The Serial Interface Engine (SIE) includes two bytes of checksum data in the count. This function subtracts two from the count before returning the value. This function should only be called for OUT endpoints, after a call to USB_bGetEPState returns EVENT_PENDING.

C Prototype:

BYTE  USB_bRWUEnabled(void)  

Assembly:

call  USB_bRWUEnabled  

Parameters:

None

Return Value:

Returns 1 if the USB host has enabled REMOTE WAKEUP, otherwise returns 0.

Side Effects:

The A and X registers may be altered by this function.

USB_bGetEPCount

Description:

This functions returns the value of the endpoint count register. The Serial Interface Enginer (SIE) includes two bytes of checksum data in the count. This function subtracts two from the count before returning the value. This function should only be called for OUT endpoints, after a call to USB_GetEPState returns EVENT_PENDING.

C Prototype:

BYTE  USB_bGetEPCount(BYTE)  

Assembly:

MOV		A, 1						; Select endpoint 1  
call  USB_bGetEPCount  

Parameters:

Register A contains the endpoint number

Return Value:

Returns the current byte count from the specified USB endpoint.

Side Effects:

The A and X registers may be altered by this function.

USB_XLoadEP

Description:

Loads and enables the specified USB endpoint for an IN transfer.

C Prototype:

void  USB_XLoadEP(BYTE*)  

Assembly:

call  USB_XLoadEP  

Parameters:

Register A contains the address of the RAM buffer containing the IN data

Return Value:

None

Side Effects:

The A and X registers may be altered by this function.

USB_EnableEP

Description:

Enables the specified USB OUT endpoint. This function should not be called for IN endpoints.

C Prototype:

void  USB_EnableEP(BYTE)  

Assembly:

MOV		A, 1  
call  USB_EnableEP  

Parameters:

Register A contains the endpoint number

Return Value:

None

Side Effects:

The A and X registers may be altered by this function.

USB_DisableEP

Description:

Disables the specified USB OUT endpoint. This function should not be called for IN endpoints.

C Prototype:

void  USB_DisableEP(BYTE)  

Assembly:

MOV		A, 1						; Select endpoint 1  
call  USB_DisableEP  

Parameters:

Register A contains the endpoint number

Return Value:

None

Side Effects:

The A and X registers may be altered by this function.

USB_Force

Description:

Forces a J, K, or SE0 state on the D+/D-. Used for signaling remote wakeup to the USB host.

C Prototype:

void  USB_Force(BYTE)  

Assembly:

MOV		A, USB_FORCE_K  
call  USB_Force  

Parameters:

Register A contains one of the following constants:.

State
Value
Description
USB_FORCE_SE0
0x00
Force a Single Ended 0 onto the D+/D- lines
USB_FORCE_J
0x02
Force a J State onto the D+/D- lines
USB_FORCE_K
0x01
Force a K State onto the D+/D- lines
USB_FORCE_NONE
0xFF
Return bus to SIE control

Return Value:

None

Side Effects:

The A and X registers may be altered by this function.

USB_Suspend

Description:

Puts the USB Transceiver into power-down mode, while maintaining the USB address assigned by the USB host. To restore the USB Transceiver to normal operation, the USB_Resume function should be called.

C Prototype:

void  USB_Suspend(void)  

Assembly:

call  USB_Suspend  

Parameters:

None

Return Value:

None

Side Effects:

The A and X registers may be altered by this function.

USB_Resume

Description:

Puts the USB Transceiver into normal operation, following a call to USB_Suspend. It retains the USB address that had been assigned by the USB host.

C Prototype:

void  USB_Resume(void)  

Assembly:

call  USB_Resume  

Parameters:

None

Return Value:

None

Side Effects:

The A and X registers may be altered by this function.

USB_UpdateHIDTimer

Description:

Updates the HID Report Idle timer and returns the expiry status. Reloads the timer if it expires.

C Prototype:

BYTE  USB_UpdateHIDTimer(BYTE bInterface)  

Assembly:

MOV		A, 1							; Select Interface 1  
call  USB_UpdateHIDTimer  

Parameters:

Register A contains the interface number

Return Value:

Register A contains:.

State
Value
Description
USB_IDLE_TIMER_EXPIRED
0x01
The timer has expired
USB_IDLE_TIMER_RUNNING
0x02
The timer is running
USB_IDLE_TIMER_INDEFINITE
0x00
The report should be sent upon a data/state change

Side Effects:

The A and X registers may be altered by this function.

USB_bGetProtocol

Description:

Returns the protocol value for the selected interface

C Prototype:

BYTE  USB_bGetProtocol(BYTE bInterface)  

Assembly:

MOV		A, 1							; Select Interface 1  
call  USB_bGetProtocol  

Parameters:

bInterface contains the desired interface number

Return Value:

Register A contains the protocol value

Side Effects:

The A and X registers may be altered by this function.

Sample Code

Sample code can be found in the PSoC Designer Examples directory.

USB Standard Device Requests

The following section describes the requests supported by the USB User Module. If a request is not supported the USB User Module normally responds with a STALL, indicating a Request Error.

Standard Device Request
USB User Module Support Description
USB 2.0 Spec Section
CLEAR_FEATURE
Device:
9.4.1
Interface: Not supported.
Endpoint
GET_CONFIGURATION
Returns the current device configuration value.
9.4.2
GET_DESCRIPTOR
Returns the specified descriptor.
9.4.3
GET_INTERFACE
Returns the selected alternate interface setting for the specified interface.
9.4.4
GET_STATUS
Device: Supported
9.4.5
Interface: Supported
Endpoint: Supported
SET_ADDRESS
Sets the device address for all future device accesses.
9.4.6
SET_CONFIGURATION
Sets the device configuration.
9.4.7
SET_DESCRIPTOR
This optional request is not supported.
9.4.8
SET_FEATURE
Device:
DEVICE_REMOTE_WAKEUP support is selected by the bRemoteWakeUp User Module Parameter.
TEST_MODE is not supported.
9.4.9
Interface: Not supported.
Endpoint: The specified Endpoint is halted.
SET_INTERFACE
Not supported.
9.4.10
SYNCH_FRAME
Since enCoRe II does not contain ISOC endpoints, this request is not supported.
9.4.11

HID Class Request

Class Request
USB User Module Support Description
Device Class Definition for HID - Section
GET_REPORT
Allows the host to receive a report by way of the Control pipe.
7.2.1
GET_IDLE
Reads the current idle rate for a particular Input report.
7.2.3
GET_PROTOCOL
Reads which protocol is currently active (either the boot or the report protocol).
7.2.5
SET_REPORT
Allows the host to send a report to the device, possibly setting the state of input, output, or feature controls.
7.2.2
SET_IDLE
Silences a particular report on the Interrupt In pipe until a new event occurs or the specified amount of time passes.
7.2.4
SET_PROTOCOL
Switches between the boot protocol and the report protocol (or vice versa).
7.2.6

USB Setup Wizard

This section details all of the USB descriptors provided by the USB User Module. The descriptions include the descriptor format and how User Module parameters map into the descriptor data.

The Setup Wizard is a tool provided by Cypress to assist engineers in the designing of USB devices. The Setup Wizard displays the Device Descriptor tree; when expanded the following folders that are part of the standard USB descriptor definitions appear:

Device Attributes

Configuration Descriptor

Interface Descriptor

HID Class Descriptor

Endpoint Descriptor

String/LANGID

Descriptor - HID

To access the Setup Wizard, right click over the USB Icon in the device editor and click the "USB Setup Wizard..." menu item.

When the Device Descriptor tree is fully expanded, all the Setup Wizard options can be seen. The left side displays the name of the Descriptor, the center displays the data, and the left displays the operation that may be performed for a particular Descriptor. In some instances, a Descriptor has a pull-down menu that presents options available for it.

Descriptor
Data
 
Operations
USB User Module Descriptor Root
"Device Name"
 
Add Device
Device Descriptor
DEVICE_1
 
Remove|Add Configuration
Device Attributes
     
Vendor ID
FFFF
   
Product ID
FFFF
   
Device Release (bcdDevice)
0000
   
Device Class
Undefined
pull-down
 
Subclass
No Subclass
pull-down
 
Protocol
None
pull-down
 
Manufacturer String
No String
pull-down
 
Product String
No String
pull-down
 
Serial Number String
No String
pull-down
 
Configuration Descriptor
CONFIG_NAME
 
Remove|Add Interface
Configuration Attributes
     
Configuration String
No String
pull-down
 
Max Power
100
   
Device Power
Bus Powered
pull-down
 
Remote Wakeup
Disabled
pull-down
 
Interface Descriptor
INTERFACE_NAME
 
Remove|Add Endpoint
Interface Attributes
     
Interface String
No String
pull-down
 
Class
Vendor Specific
pull-down
 
Subclass
No Subclass
pull-down
 
HID Class Descriptor
     
Descriptor Type
Report
pull-down
 
Country Code
Not Supported
pull-down
 
HID Report
None
pull-down
 
Endpoint Descriptor
ENDPOINT_NAME
 
Remove
Endpoint Attributes
     
Endpoint Number
0
   
Direction
IN
pull-down
 
Transfer Type
CNTRL
pull-down
 
Interval
10
   
Max Packet Size
8
   
String/LANGID
     
String Descriptors
"Device Name"
 
Add String
LANGID
 
pull-down
 
String
"Selected String Name"
 
Remove
Descriptor
     
HID Report Root
"Device Name"
 
Add HID Report

Understanding the Setup Wizard

The Setup Wizard window may be described as a table that presents three major areas for programming. The first area is the Descriptor USB User Module, the second is the String/LANGID, and the third is the Descriptor HID Report. Two buttons below the table may be used to perform a selected command.

The first section presents the Descriptor USB User Module -- this will be subsequently describe in greater details. The second section presents the String/LANGID; when a string ID is required, this area is used for input of that string. To add a string for a USB device, click on the Add String operation. The software adds a row and prompts you to "Edit your string here". Enter the new string then click the Save/Generate Descriptors button. Once the string is saved, it is available for use in the Descriptor USB User Module from the pull-down menus. If you close the Wizard window without saving, the string will be lost and not available for use.

The third area presents the Descriptor HID Report Root. From here you can request an HID Report for the device selected.

Descriptor USB User Module

The first column displays folders that may be expanded and collapsed. For the purpose of this discussion, the tree must be fully expanded so that all options are visible. The Setup Wizard permits the entering of data into the middle Data column; if there is a pull-down menu, it can be used to select a different option. If there is no pull-down menu, but there is "data", use the cursor to highlight and select the "data", then over-write that data with another value or text-option. All the values entered must meet the USB 2.0 Chapter 9 Specifications.

The first folder that is displayed at the top is the USB User Module Descriptor Root. It has the user module name in the Data column (this is the user-module name given to it by the software; right-clicking on the user module presents "Rename" as one of the options). This user module is the one that was placed in the Interconnect View. The Add Device operation on the right-hand column adds another USB device complete with all the different fields required for describing it. The new USB device will be listed at the bottom after the Endpoint Descriptor. Click the Save/Generate Descriptors button. If you do not save the newly added device, it will not be available for use.

Device Descriptor has DEVICE_NUMBER as the Data; it may be Removed or a Configuration may be added. All the information about a particular USB device may be entered by over-writing the existing data or by using a pull-down menu.

When the input of data is complete, either by using the pull-down menus or by filling in alpha-numeric text in the appropriate spots, select the Save/Generate Descriptors button; the data that will define your design can only be made permanent by the use of this button.

USB Suspend, Resume, and Remote Wakeup

The USB User Module support USB Suspend, Resume, and Remote Wakeup. Since these features must be tightly coupled into the user application, the USB User Module provides a set of API Functions.

USB Activity Monitoring

The USB_bCheckActivity API function provides a means to check if any USB Bus activity has occurred. The application uses the function to determine if the conditions to enter USB Suspend have been met.

USB Suspend

Once the conditions to enter USB Suspend have been met, the application should take appropriate steps to reduce current consumption to meet the suspend current requirements. To put the USB SIE and Transceiver into power-down mode, the application calls the USB_Suspend API function. This function disables the USB block, but maintains the current USB address (in the USBCR register). The device can use the Sleep feature of the enCoRe II to reduce current consumption.

USB Resume

While the device is suspended, it should periodically check to determine if the conditions to leave the suspended state have been met. One way check resume conditions is to use the Sleep Timer to periodically wake the device. If the resume conditions have been met, the application calls the USB_Resume API function. This function enables the USB SIE and Transceiver, bringing them out of power-down mode. It does not change the USB address field of the USBCR register, thus maintaining the USB address previously assigned by the host.

USB Remote Wakeup

If the device supports remote wakeup, the application can determine if the host has enabled remote wakeup with the USB_bRWUEnabled API function. When the device is suspended and it determines the conditions to initiate a remote wakeup have been met, the application can use the USB_Force API function to force the appropriate J and K states onto the USB Bus, thus signaling a remote wakeup.

Vendor Specific Requests

The USB User Module supports Vendor Specific Requests (VSR) by providing a SETUP request dispatcher, exposing the control endpoint initialization entry points for Control Read, Control Write and No Data control transfers and providing transfer completion notification. The USB User Module Endpoint 0 Interrupt Service Routine (ISR) transfers control to a handler provided by the application. The handler initializes specific user module data structures and transfers control back to the Endpoint 0 ISR. The user module handles the subsequent data and status stages of the transfer without any involvement of the user application. Upon completion of the transfer, the user module updates a completion status block. The status block can be monitored by the application to determine it the VSR has completed.

Vendor Specific Request Processing

All control transfers, including VSRs, have a SETUP stage, an optional data stage, and a status stage. The SETUP stage is unique for each request. During the SETUP stage, the handler must prepare the application to receive data for control writes and prepares data for transmission to the host for control reads. For no data control transfers, the handler may extract information from the SETUP packet itself.

The Endpoint 0 ISR processes the data and status stages exactly the same way for all requests. During the data stage, the ISR copies data to or from the control endpoint buffer (registers EP0DATA0-EP0DATA7) depending upon the direction of the transaction.

During the status stage, the Endpoint 0 ISR updates the completion status block. The ISR detects and reports premature completion.

Vendor Specific Request Dispatch Routines

Depending on the application requirements, the Endpoint 0 ISR can dispatch up to eight types of VSRs based on the bmRequestType field of the SETUP. Refer to section 9.3 of the USB 2.0 specification for a discussion of bmRequestType. The application must provide an assembly language dispatch routine

Vendor Specific Request Dispatch Routine Names
Direction
Recipient
Dispatch Routine Entry Point
Enable Flag
Host to Device

(Control Write)
Device
USB_DT_h2d_vnd_dev_Dispatch
USB_CB_h2d_vnd_dev
Interface
USB_DT_h2d_vnd_ifc_Dispatch
USB_CB_h2d_vnd_ifc
Endpoint
USB_DT_h2d_vnd_ep_Dispatch
USB_CB_h2d_vnd_ep
Other
USB_DT_h2d_vnd_oth_Dispatch
USB_CB_h2d_vnd_oth
Device to Host

(Control Read)
Device
USB_DT_d2h_vnd_dev_Dispatch
USB_CB_d2h_vnd_dev
Interface
USB_DT_d2h_vnd_ifc_Dispatch
USB_CB_d2h_vnd_ifc
Endpoint
USB_DT_d2h_vnd_ep_Dispatch
USB_CB_d2h_vnd_ep
Other
USB_DT_d2h_vnd_oth_Dispatch
USB_CB_d2h_vnd_oth

and expose it to by resetting the Enable Flag to 1 in the custom code block of the USB.inc file.

At a minimum, the dispatch routine must return control back to the Endpoint ISR by a LJMP to one of the Endpoint 0 ISR Return Points listed in the following table. The dispatch routine may destroy the A and X registers, but the Stack Pointer (SP) and any other relevant context must be restored prior to returning control to the ISR.

Endpoint 0 ISR Return Points
Return Entry Point
Required Data Items
Description
USB_Not_Supported
This return point should be used when the request is not supported. It STALLs the request.
 
Data Items: None
 
USB_InitControlRead
This return point is used to initiate a Control Read transfer.
 
USB_DataSource
The data source is RAM or ROM (USB_DS_RAM or USB_DS_ROM). This is necessary since different instructions must be used to move the data from the source ROMX or MOV.
 
USB_TransferSize (WORD)
The number of data bytes to be transferred
 
USB_DataPtr (WORD)
RAM or ROM address of the data
 
USB_StatusBlockPtr (WORD)
Address of a status block allocated with the USB_XFER_STATUS_BLOCK macro.
USB_InitControlWrite
This return point is used to initiate a Control Write transfer.
 
USB_DataSource
USB_DS_RAM (the destination for control writes must RAM).
 
USB_TransferSize (WORD)
Size of the application buffer to receive the data
 
USB_DataPtr (WORD)
RAM address of the application buffer to receive the data
 
USB_StatusBlockPtr (WORD)
Address of a status block allocated with the USB_XFER_STATUS_BLOCK macro.
USB_InitNoDataControlTransfer
This return point is used to initiate a No Data Control transfer.
 
USB_StatusBlockPtr (WORD)
Address of a status block allocated with the USB_XFER_STATUS_BLOCK macro.

The status completion block contains two data items, a one byte completion status code and a two byte transfer length. The "main" application can monitor the completion status to determine how to proceed. Completion status codes are found in the following table.

USB Transfer Completion Codes
Completion Code
Description
USB_XFER_IDLE
(0x00)
USB_XFER_IDLE indicates that the associated data buffer does not have valid data and the application should not use the buffer. The actual data transfer will take place while the completion code is USB_XFER_IDLE, although it does not indicate a transfer is in progress.
USB_XFER_STATUS_ACK
(0x01)
USB_XFER_STATUS_ACK indicates the control transfer status stage completed successfully. At this time, the application can use the associated data buffer and its contents.
USB_XFER_PREMATURE
(0x02)
USB_XFER_PREMATURE indicates that the control transfer was interrupted by the SETUP of a subsequent control transfer. For control writes, the contents of the associated data buffer will contain the data up to the premature completion.
USB_XFER_ERROR
(0x03)
USB_XFER_ERROR indicates that the expected status stage token was not received.

The transfer length is the actual number of data bytes tranfered.