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 |
#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().
#define USBERR_HOST_IN_PID_ERROR 0x01000000 |
The host received an invalid PID in a transaction.
#define USBERR_HOST_IN_NOT_COMP 0x00100000 |
The host did not receive a response from a device.
#define USBERR_HOST_IN_STALL 0x00400000 |
The host received a stall on an IN endpoint.
#define USBERR_HOST_IN_DATA_ERROR 0x00080000 |
The host detected a CRC or bit-stuffing error (isochronous mode).
#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).
#define USBERR_HOST_IN_ERROR 0x00040000 |
The host failed to communicate with a device via an IN endpoint.
#define USBERR_HOST_IN_FIFO_FULL 0x00020000 |
The host receive FIFO is full.
#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).
#define USBERR_HOST_OUT_NOT_COMP 0x00000080 |
The host did not receive a response from a device (isochronous mode).
#define USBERR_HOST_OUT_STALL 0x00000020 |
The host received a stall on an OUT endpoint.
#define USBERR_HOST_OUT_ERROR 0x00000004 |
The host failed to communicate with a device via an OUT endpoint.
#define USBERR_HOST_EP0_NAK_TO 0x00000080 |
The host received NAK on endpoint 0 for longer than the configured timeout.
#define USBERR_HOST_EP0_ERROR 0x00000010 |
The host failed to communicate with a device via an endpoint zero.
#define USBERR_DEV_RX_DATA_ERROR 0x00080000 |
The device detected a CRC error in received data.
#define USBERR_DEV_RX_OVERRUN 0x00040000 |
The device was unable to receive a packet from the host since the receive FIFO is full.
#define USBERR_DEV_RX_FIFO_FULL 0x00020000 |
The device receive FIFO is full.
#define USB_HOST_INTS (USB_INTCTRL_VBUS_ERR) |
Referenced by USB0DualModeIntHandler().
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) |
USB callback function.
pvCBData | is 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. |
ui32Event | is the identifier of the asynchronous event which is being notified to the client. |
ui32MsgParam | is an event-specific parameter. |
pvMsgData | is 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.
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.
enum tUSBOTGState |
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.
psDesc | points to the first byte of a block of standard USB descriptors. |
ui32Size | is the number of bytes of descriptor data found at pointer psDesc. |
ui32Type | identifies 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.
References NEXT_USB_DESCRIPTOR, and USB_DESC_ANY.
Referenced by USBDCDConfigDescGet(), and USBDCDConfigDescGetNum().
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.
psDesc | points to the first byte of a block of standard USB descriptors. |
ui32Size | is the number of bytes of descriptor data found at pointer psDesc. |
ui32Type | identifies 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. |
ui32Index | is 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.
References NEXT_USB_DESCRIPTOR, and USB_DESC_ANY.
Referenced by USBDCDConfigDescGet(), USBDescGetInterface(), and USBDescGetInterfaceEndpoint().
uint32_t USBDescGetNumAlternateInterfaces | ( | tConfigDescriptor * | psConfig, |
uint8_t | ui8InterfaceNumber | ||
) |
Determines the number of different alternate configurations for a given interface within a configuration descriptor.
psConfig | points to the first byte of a standard USB configuration descriptor. |
ui8InterfaceNumber | is 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.
References NEXT_USB_DESCRIPTOR, and USB_DTYPE_INTERFACE.
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.
psConfig | points to the first byte of a standard USB configuration descriptor. |
ui32Index | is 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. |
ui32Alt | is 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.
References USB_DESC_ANY, USB_DTYPE_INTERFACE, and USBDescGet().
tEndpointDescriptor * USBDescGetInterfaceEndpoint | ( | tInterfaceDescriptor * | psInterface, |
uint32_t | ui32Index, | ||
uint32_t | ui32Size | ||
) |
Return a pointer to the n-th endpoint descriptor in the supplied interface descriptor.
psInterface | points to the first byte of a standard USB interface descriptor. |
ui32Index | is the zero based index of the endpoint that is to be found. |
ui32Size | contains 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.
References USB_DTYPE_ENDPOINT, and USBDescGet().
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.
ui32Index | specifies the USB controller whose mode of operation is to be set. This parameter must be set to 0. |
iUSBMode | indicates 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. |
pfnCallback | is 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.
References g_iUSBMode.
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.
References eUSBModeDevice, eUSBModeHost, eUSBModeNone, g_iUSBMode, USB_HOST_INTS, USBDeviceIntHandlerInternal(), and USBHostIntHandlerInternal().
void InternalUSBTickInit | ( | void | ) |
References g_bUSBTimerInitialized, g_pfnTickHandlers, g_pvTickInstance, and MAX_USB_TICK_HANDLERS.
Referenced by USBDualModeInit().
void InternalUSBTickReset | ( | void | ) |
References g_bUSBTimerInitialized.
Referenced by USBDCDTerm().
int32_t InternalUSBRegisterTickHandler | ( | tUSBTickHandler | pfHandler, |
void * | pvInstance | ||
) |
References g_pfnTickHandlers, g_pvTickInstance, and MAX_USB_TICK_HANDLERS.
void InternalUSBStartOfFrameTick | ( | uint32_t | ui32TicksmS | ) |
References g_pfnTickHandlers, g_pvTickInstance, g_ui32CurrentUSBTick, and MAX_USB_TICK_HANDLERS.
Referenced by USBDeviceIntHandlerInternal().
volatile tUSBMode g_iUSBMode = eUSBModeNone |
Referenced by USB0DualModeIntHandler(), USBDCDInit(), USBHCDInit(), USBOTGModeInit(), and USBStackModeSet().
volatile uint32_t g_ui32PollRate |
Referenced by USBOTGMain(), and USBOTGPollRate().
volatile uint32_t g_ui32WaitTicks = 0 |
Referenced by USBOTGMain().
volatile tUSBOTGState g_eOTGModeState |
Referenced by OTGDeviceDisconnect(), USB0_IRQOTGModeHandler(), and USBOTGMain().
tUSBTickHandler g_pfnTickHandlers[MAX_USB_TICK_HANDLERS] |
Referenced by InternalUSBRegisterTickHandler(), InternalUSBStartOfFrameTick(), and InternalUSBTickInit().
void* g_pvTickInstance[MAX_USB_TICK_HANDLERS] |
Referenced by InternalUSBRegisterTickHandler(), InternalUSBStartOfFrameTick(), and InternalUSBTickInit().
bool g_bUSBTimerInitialized = false |
Referenced by InternalUSBTickInit(), and InternalUSBTickReset().
uint32_t g_ui32CurrentUSBTick = 0 |
Referenced by InternalUSBStartOfFrameTick().
uint32_t g_ui32USBSOFCount = 0 |
Referenced by USBDeviceIntHandlerInternal().