USBLibAPIGuide  1.00.00.01
Macros | Typedefs | Enumerations | Functions | Variables
General_usblib_api

Macros

#define USB_DESC_ANY   0xFFFFFFFF
 
#define USBERR_HOST_IN_PID_ERROR   0x01000000
 The host received an invalid PID in a transaction. More...
 
#define USBERR_HOST_IN_NOT_COMP   0x00100000
 The host did not receive a response from a device. More...
 
#define USBERR_HOST_IN_STALL   0x00400000
 The host received a stall on an IN endpoint. More...
 
#define USBERR_HOST_IN_DATA_ERROR   0x00080000
 The host detected a CRC or bit-stuffing error (isochronous mode). More...
 
#define USBERR_HOST_IN_NAK_TO   0x00080000
 
#define USBERR_HOST_IN_ERROR   0x00040000
 The host failed to communicate with a device via an IN endpoint. More...
 
#define USBERR_HOST_IN_FIFO_FULL   0x00020000
 The host receive FIFO is full. More...
 
#define USBERR_HOST_OUT_NAK_TO   0x00000080
 
#define USBERR_HOST_OUT_NOT_COMP   0x00000080
 The host did not receive a response from a device (isochronous mode). More...
 
#define USBERR_HOST_OUT_STALL   0x00000020
 The host received a stall on an OUT endpoint. More...
 
#define USBERR_HOST_OUT_ERROR   0x00000004
 The host failed to communicate with a device via an OUT endpoint. More...
 
#define USBERR_HOST_EP0_NAK_TO   0x00000080
 
#define USBERR_HOST_EP0_ERROR   0x00000010
 The host failed to communicate with a device via an endpoint zero. More...
 
#define USBERR_DEV_RX_DATA_ERROR   0x00080000
 The device detected a CRC error in received data. More...
 
#define USBERR_DEV_RX_OVERRUN   0x00040000
 
#define USBERR_DEV_RX_FIFO_FULL   0x00020000
 The device receive FIFO is full. More...
 
#define USB_HOST_INTS   (USB_INTCTRL_VBUS_ERR)
 

Typedefs

typedef struct tUSBDMAInstance tUSBDMAInstance
 
typedef void(* tUSBModeCallback) (uint32_t ui32Index, tUSBMode iMode)
 
typedef uint32_t(* tUSBCallback) (void *pvCBData, uint32_t ui32Event, uint32_t ui32MsgParam, void *pvMsgData)
 

Enumerations

enum  tUSBMode {
  eUSBModeDevice = 0, eUSBModeHost, eUSBModeOTG, eUSBModeNone,
  eUSBModeForceHost, eUSBModeForceDevice
}
 
enum  tUSBOTGState {
  eUSBOTGModeIdle, eUSBOTGModeWaitID, eUSBOTGModeWait, eUSBOTGModeBWaitCon,
  eUSBOTGModeBDevice, eUSBOTGModeAHost
}
 

Functions

uint32_t USBDescGetNum (tDescriptorHeader *psDesc, uint32_t ui32Size, uint32_t ui32Type)
 
tDescriptorHeader * USBDescGet (tDescriptorHeader *psDesc, uint32_t ui32Size, uint32_t ui32Type, uint32_t ui32Index)
 
uint32_t USBDescGetNumAlternateInterfaces (tConfigDescriptor *psConfig, uint8_t ui8InterfaceNumber)
 
tInterfaceDescriptor * USBDescGetInterface (tConfigDescriptor *psConfig, uint32_t ui32Index, uint32_t ui32Alt)
 
tEndpointDescriptor * USBDescGetInterfaceEndpoint (tInterfaceDescriptor *psInterface, uint32_t ui32Index, uint32_t ui32Size)
 
void USBStackModeSet (uint32_t ui32Index, tUSBMode iUSBMode, tUSBModeCallback pfnCallback)
 
void USB0DualModeIntHandler (void)
 
void InternalUSBTickInit (void)
 
void InternalUSBTickReset (void)
 
int32_t InternalUSBRegisterTickHandler (tUSBTickHandler pfHandler, void *pvInstance)
 
void InternalUSBStartOfFrameTick (uint32_t ui32TicksmS)
 

Variables

volatile tUSBMode g_iUSBMode = eUSBModeNone
 
volatile uint32_t g_ui32PollRate
 
volatile uint32_t g_ui32WaitTicks = 0
 
volatile tUSBOTGState g_eOTGModeState
 
tUSBTickHandler g_pfnTickHandlers [MAX_USB_TICK_HANDLERS]
 
void * g_pvTickInstance [MAX_USB_TICK_HANDLERS]
 
bool g_bUSBTimerInitialized = false
 
uint32_t g_ui32CurrentUSBTick = 0
 
uint32_t g_ui32USBSOFCount = 0
 

Detailed Description

Macro Definition Documentation

§ USB_DESC_ANY

#define USB_DESC_ANY   0xFFFFFFFF

The USB_DESC_ANY label is used as a wild card in several of the descriptor parsing APIs to determine whether or not particular search criteria should be ignored.

Referenced by USBDCDConfigGetInterface(), USBDescGet(), USBDescGetInterface(), USBDescGetNum(), USBDeviceConfig(), and USBDeviceConfigAlternate().

§ USBERR_HOST_IN_PID_ERROR

#define USBERR_HOST_IN_PID_ERROR   0x01000000

The host received an invalid PID in a transaction.

§ USBERR_HOST_IN_NOT_COMP

#define USBERR_HOST_IN_NOT_COMP   0x00100000

The host did not receive a response from a device.

§ USBERR_HOST_IN_STALL

#define USBERR_HOST_IN_STALL   0x00400000

The host received a stall on an IN endpoint.

§ USBERR_HOST_IN_DATA_ERROR

#define USBERR_HOST_IN_DATA_ERROR   0x00080000

The host detected a CRC or bit-stuffing error (isochronous mode).

§ USBERR_HOST_IN_NAK_TO

#define USBERR_HOST_IN_NAK_TO   0x00080000

The host received NAK on an IN endpoint for longer than the specified timeout period (interrupt, bulk and control modes).

§ USBERR_HOST_IN_ERROR

#define USBERR_HOST_IN_ERROR   0x00040000

The host failed to communicate with a device via an IN endpoint.

§ USBERR_HOST_IN_FIFO_FULL

#define USBERR_HOST_IN_FIFO_FULL   0x00020000

The host receive FIFO is full.

§ USBERR_HOST_OUT_NAK_TO

#define USBERR_HOST_OUT_NAK_TO   0x00000080

The host received NAK on an OUT endpoint for longer than the specified timeout period (bulk, interrupt and control modes).

§ USBERR_HOST_OUT_NOT_COMP

#define USBERR_HOST_OUT_NOT_COMP   0x00000080

The host did not receive a response from a device (isochronous mode).

§ USBERR_HOST_OUT_STALL

#define USBERR_HOST_OUT_STALL   0x00000020

The host received a stall on an OUT endpoint.

§ USBERR_HOST_OUT_ERROR

#define USBERR_HOST_OUT_ERROR   0x00000004

The host failed to communicate with a device via an OUT endpoint.

§ USBERR_HOST_EP0_NAK_TO

#define USBERR_HOST_EP0_NAK_TO   0x00000080

The host received NAK on endpoint 0 for longer than the configured timeout.

§ USBERR_HOST_EP0_ERROR

#define USBERR_HOST_EP0_ERROR   0x00000010

The host failed to communicate with a device via an endpoint zero.

§ USBERR_DEV_RX_DATA_ERROR

#define USBERR_DEV_RX_DATA_ERROR   0x00080000

The device detected a CRC error in received data.

§ USBERR_DEV_RX_OVERRUN

#define USBERR_DEV_RX_OVERRUN   0x00040000

The device was unable to receive a packet from the host since the receive FIFO is full.

§ USBERR_DEV_RX_FIFO_FULL

#define USBERR_DEV_RX_FIFO_FULL   0x00020000

The device receive FIFO is full.

§ USB_HOST_INTS

#define USB_HOST_INTS   (USB_INTCTRL_VBUS_ERR)

Referenced by USB0DualModeIntHandler().

Typedef Documentation

§ tUSBDMAInstance

§ tUSBModeCallback

typedef void(* tUSBModeCallback) (uint32_t ui32Index, tUSBMode iMode)

§ tUSBCallback

typedef uint32_t(* tUSBCallback) (void *pvCBData, uint32_t ui32Event, uint32_t ui32MsgParam, void *pvMsgData)

USB callback function.

Parameters
pvCBDatais the callback pointer associated with the instance generating the callback. This is a value provided by the client during initialization of the instance making the callback.
ui32Eventis the identifier of the asynchronous event which is being notified to the client.
ui32MsgParamis an event-specific parameter.
pvMsgDatais an event-specific data pointer.

A function pointer provided to the USB layer by the application which will be called to notify it of all asynchronous events relating to data transmission or reception. This callback is used by device class drivers and host pipe functions.

Returns
Returns an event-dependent value.

Enumeration Type Documentation

§ tUSBMode

enum tUSBMode

The operating mode required by the USB library client. This type is used by applications which wish to be able to switch between host and device modes by calling the USBStackModeSet() API.

Enumerator
eUSBModeDevice 

Operate in USB device mode with active monitoring of VBUS and the ID pin must be pulled to a logic high value.

eUSBModeHost 

Operate in USB host mode with active monitoring of VBUS and the ID pin must be pulled to a logic low value.

eUSBModeOTG 

Operate as an On-The-Go device which requires both VBUS and ID to be connected directly to the USB controller from the USB connector.

eUSBModeNone 

A marker indicating that no USB mode has yet been set by the application.

eUSBModeForceHost 

Force host mode so that the VBUS and ID pins are not used or monitored by the USB controller.

eUSBModeForceDevice 

Forcing device mode so that the VBUS and ID pins are not used or monitored by the USB controller.

§ tUSBOTGState

Enumerator
eUSBOTGModeIdle 
eUSBOTGModeWaitID 
eUSBOTGModeWait 
eUSBOTGModeBWaitCon 
eUSBOTGModeBDevice 
eUSBOTGModeAHost 

Function Documentation

§ USBDescGetNum()

uint32_t USBDescGetNum ( tDescriptorHeader *  psDesc,
uint32_t  ui32Size,
uint32_t  ui32Type 
)

Determines the number of individual descriptors of a particular type within a supplied buffer.

Parameters
psDescpoints to the first byte of a block of standard USB descriptors.
ui32Sizeis the number of bytes of descriptor data found at pointer psDesc.
ui32Typeidentifies the type of descriptor that is to be counted. If the value is USB_DESC_ANY, the function returns the total number of descriptors regardless of type.

This function can be used to count the number of descriptors of a particular type within a block of descriptors. The caller can provide a specific type value which the function matches against the second byte of each descriptor or, alternatively, can specify USB_DESC_ANY to have the function count all descriptors regardless of their type.

Returns
Returns the number of descriptors found in the supplied block of data.

References NEXT_USB_DESCRIPTOR, and USB_DESC_ANY.

Referenced by USBDCDConfigDescGet(), and USBDCDConfigDescGetNum().

§ USBDescGet()

tDescriptorHeader * USBDescGet ( tDescriptorHeader *  psDesc,
uint32_t  ui32Size,
uint32_t  ui32Type,
uint32_t  ui32Index 
)

Determines the number of individual descriptors of a particular type within a supplied buffer.

Parameters
psDescpoints to the first byte of a block of standard USB descriptors.
ui32Sizeis the number of bytes of descriptor data found at pointer psDesc.
ui32Typeidentifies the type of descriptor that is to be found. If the value is USB_DESC_ANY, the function returns a pointer to the n-th descriptor regardless of type.
ui32Indexis the zero based index of the descriptor whose pointer is to be returned. For example, passing value 1 in ui32Index returns the second matching descriptor.

Return a pointer to the n-th descriptor of a particular type found in the block of ui32Size bytes starting at psDesc.

Returns
Returns a pointer to the header of the required descriptor if found or NULL otherwise.

References NEXT_USB_DESCRIPTOR, and USB_DESC_ANY.

Referenced by USBDCDConfigDescGet(), USBDescGetInterface(), and USBDescGetInterfaceEndpoint().

§ USBDescGetNumAlternateInterfaces()

uint32_t USBDescGetNumAlternateInterfaces ( tConfigDescriptor *  psConfig,
uint8_t  ui8InterfaceNumber 
)

Determines the number of different alternate configurations for a given interface within a configuration descriptor.

Parameters
psConfigpoints to the first byte of a standard USB configuration descriptor.
ui8InterfaceNumberis the interface number for which the number of alternate configurations is to be counted.

This function can be used to count the number of alternate settings for a specific interface within a configuration.

Returns
Returns the number of alternate versions of the specified interface or 0 if the interface number supplied cannot be found in the config descriptor.

References NEXT_USB_DESCRIPTOR, and USB_DTYPE_INTERFACE.

§ USBDescGetInterface()

tInterfaceDescriptor * USBDescGetInterface ( tConfigDescriptor *  psConfig,
uint32_t  ui32Index,
uint32_t  ui32Alt 
)

Returns a pointer to the n-th interface descriptor in a configuration descriptor that applies to the supplied alternate setting number.

Parameters
psConfigpoints to the first byte of a standard USB configuration descriptor.
ui32Indexis the zero based index of the interface that is to be found. If ui32Alt is set to a value other than USB_DESC_ANY, this will be equivalent to the interface number being searched for.
ui32Altis the alternate setting number which is to be searched for. If this value is USB_DESC_ANY, the alternate setting is ignored and all interface descriptors are considered in the search.

Return a pointer to the n-th interface descriptor found in the supplied configuration descriptor. If ui32Alt is not USB_DESC_ANY, only interface descriptors which are part of the supplied alternate setting are considered in the search otherwise all interface descriptors are considered.

Note that, although alternate settings can be applied on an interface-by- interface basis, the number of interfaces offered is fixed for a given config descriptor. Hence, this function will correctly find the unique interface descriptor for that interface's alternate setting number ui32Alt if ui32Index is set to the required interface number and ui32Alt is set to a valid alternate setting number for that interface.

Returns
Returns a pointer to the required interface descriptor if found or NULL otherwise.

References USB_DESC_ANY, USB_DTYPE_INTERFACE, and USBDescGet().

§ USBDescGetInterfaceEndpoint()

tEndpointDescriptor * USBDescGetInterfaceEndpoint ( tInterfaceDescriptor *  psInterface,
uint32_t  ui32Index,
uint32_t  ui32Size 
)

Return a pointer to the n-th endpoint descriptor in the supplied interface descriptor.

Parameters
psInterfacepoints to the first byte of a standard USB interface descriptor.
ui32Indexis the zero based index of the endpoint that is to be found.
ui32Sizecontains the maximum number of bytes that the function may search beyond psInterface while looking for the requested endpoint descriptor.

Return a pointer to the n-th endpoint descriptor found in the supplied interface descriptor. If the ui32Index parameter is invalid (greater than or equal to the bNumEndpoints field of the interface descriptor) or the endpoint cannot be found within ui32Size bytes of the interface descriptor pointer, the function will return NULL.

Note that, although the USB 2.0 specification states that endpoint descriptors must follow the interface descriptor that they relate to, it also states that device specific descriptors should follow any standard descriptor that they relate to. As a result, we cannot assume that each interface descriptor will be followed by nothing but an ordered list of its own endpoints and, hence, the function needs to be provided ui32Size to limit the search range.

Returns
Returns a pointer to the requested endpoint descriptor if found or NULL otherwise.

References USB_DTYPE_ENDPOINT, and USBDescGet().

§ USBStackModeSet()

void USBStackModeSet ( uint32_t  ui32Index,
tUSBMode  iUSBMode,
tUSBModeCallback  pfnCallback 
)

Allows dual mode application to switch between USB device and host modes and provides a method to force the controller into the desired mode.

Parameters
ui32Indexspecifies the USB controller whose mode of operation is to be set. This parameter must be set to 0.
iUSBModeindicates the mode that the application wishes to operate in. Valid values are eUSBModeDevice to operate as a USB device and eUSBModeHost to operate as a USB host.
pfnCallbackis a pointer to a function which the USB library will call each time the mode is changed to indicate the new operating mode. In cases where iUSBMode is set to either eUSBModeDevice or eUSBModeHost, the callback will be made immediately to allow the application to perform any host or device specific initialization.

This function allows a USB application that can operate in host or device mode to indicate to the USB stack the mode that it wishes to use. The caller is responsible for cleaning up the interface and removing itself from the bus prior to making this call and reconfiguring afterwards. The pfnCallback function can be a NULL(0) value to indicate that no notification is required.

For successful dual mode mode operation, an application must register USB0DualModeIntHandler() as the interrupt handler for the USB0 interrupt. This handler is responsible for steering interrupts to the device or host stack depending upon the chosen mode. Devices which do not require dual mode capability should register either USB0_IRQDeviceHandler() or USB0_IRQHostHandler() instead. Registering USB0DualModeIntHandler() for a single mode application will result in an application binary larger than required since library functions for both USB operating modes will be included even though only one mode is required.

Single mode applications (those offering exclusively USB device or USB host functionality) are only required to call this function if they need to force the mode of the controller to Host or Device mode. This is usually in the event that the application needs to reused the USBVBUS and/or USBID pins as GPIOs.

Returns
None.

References g_iUSBMode.

§ USB0DualModeIntHandler()

void USB0DualModeIntHandler ( void  )

Steers USB interrupts from controller to the correct handler in the USB stack.

This interrupt handler is used in applications which require to operate in both host and device mode. It steers the USB hardware interrupt to the correct handler in the USB stack depending upon the current operating mode of the application, USB device or host.

For successful dual mode operation, an application must register USB0DualModeIntHandler() in the CPU vector table as the interrupt handler for the USB0 interrupt. This handler is responsible for steering interrupts to the device or host stack depending upon the chosen mode.

Note
Devices which do not require dual mode capability should register either USB0_IRQDeviceHandler() or USB0_IRQHostHandler() instead. Registering USB0DualModeIntHandler() for a single mode application will result in an application binary larger than required since library functions for both USB operating modes will be included even though only one mode is actually required.
Returns
None.

References eUSBModeDevice, eUSBModeHost, eUSBModeNone, g_iUSBMode, USB_HOST_INTS, USBDeviceIntHandlerInternal(), and USBHostIntHandlerInternal().

§ InternalUSBTickInit()

void InternalUSBTickInit ( void  )

§ InternalUSBTickReset()

void InternalUSBTickReset ( void  )

References g_bUSBTimerInitialized.

Referenced by USBDCDTerm().

§ InternalUSBRegisterTickHandler()

int32_t InternalUSBRegisterTickHandler ( tUSBTickHandler  pfHandler,
void *  pvInstance 
)

§ InternalUSBStartOfFrameTick()

void InternalUSBStartOfFrameTick ( uint32_t  ui32TicksmS)

Variable Documentation

§ g_iUSBMode

volatile tUSBMode g_iUSBMode = eUSBModeNone

§ g_ui32PollRate

volatile uint32_t g_ui32PollRate

Referenced by USBOTGMain(), and USBOTGPollRate().

§ g_ui32WaitTicks

volatile uint32_t g_ui32WaitTicks = 0

Referenced by USBOTGMain().

§ g_eOTGModeState

volatile tUSBOTGState g_eOTGModeState

§ g_pfnTickHandlers

§ g_pvTickInstance

void* g_pvTickInstance[MAX_USB_TICK_HANDLERS]

§ g_bUSBTimerInitialized

bool g_bUSBTimerInitialized = false

§ g_ui32CurrentUSBTick

uint32_t g_ui32CurrentUSBTick = 0

§ g_ui32USBSOFCount

uint32_t g_ui32USBSOFCount = 0
© Copyright 1995-2020, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale