#include "xusb_l.h"
#include "xstatus.h"
Classes | |
struct | XUsb_EpConfig |
struct | XUsb_DeviceConfig |
struct | XUsb_Config |
struct | XUsb |
Defines | |
Endpoint Direction | |
#define | XUSB_EP_DIRECTION_IN 1 |
#define | XUSB_EP_DIRECTION_OUT 0 |
Speed | |
#define | XUSB_EP_HIGH_SPEED 1 |
#define | XUSB_EP_FULL_SPEED 0 |
USB device specific global configuration constants. | |
#define | XUSB_MAX_ENDPOINTS 8 |
#define | XUSB_EP_NUMBER_ZERO 0 |
#define | XUSB_DEVICEADDR_MAX 127 |
USB device disconnect state | |
#define | XUSB_DISCONNECTED 0x1 |
#define | XUSB_RESET 0x0 |
Test Modes (Set Feature) | |
#define | TEST_J 1 |
#define | TEST_K 2 |
#define | TEST_SE0_NAK 3 |
#define | TEST_PKT 4 |
Typedefs | |
typedef void(* | XUsb_EpHandlerFunc )(void *CallBackRef, u8 EpNum, u32 EventType) |
typedef void(* | XUsb_IntrHandlerFunc )(void *CallBackRef, u32 InterruptType) |
Functions | |
int | XUsb_CfgInitialize (XUsb *InstancePtr, XUsb_Config *ConfigPtr, u32 EffectiveAddr) |
int | XUsb_ConfigureDevice (XUsb *InstancePtr, XUsb_DeviceConfig *CfgPtr) |
void | XUsb_Start (XUsb *InstancePtr) |
void | XUsb_Stop (XUsb *InstancePtr) |
u32 | XUsb_GetFrameNum (const XUsb *InstancePtr) |
int | XUsb_SetDeviceAddress (XUsb *InstancePtr, u8 Address) |
void | XUsb_SetTestMode (XUsb *InstancePtr, u8 TestMode, u8 *BufPtr) |
void | XUsb_DmaReset (XUsb *InstancePtr) |
void | XUsb_DmaTransfer (XUsb *InstancePtr, u32 *SrcAddr, u32 *DstAddr, u16 Length) |
void | XUsb_ReadErrorCounters (XUsb *InstancePtr, u8 *BitStuffErrors, u8 *PidErrors, u8 *CrcErrors) |
u8 | XUsb_UlpiPhyReadRegister (XUsb *InstancePtr, u8 RegAddr) |
int | XUsb_UlpiPhyWriteRegister (XUsb *InstancePtr, u8 RegAddr, u8 UlpiPhyRegData) |
void | XUsb_SieReset (XUsb *InstancePtr) |
void | XUsb_EpEnable (const XUsb *InstancePtr, u8 EpNum) |
void | XUsb_EpDisable (const XUsb *InstancePtr, u8 EpNum) |
void | XUsb_EpConfigure (XUsb *InstancePtr, u8 EpNum, XUsb_EpConfig *EpCfgPtr) |
int | XUsb_EpDataSend (XUsb *InstancePtr, u8 EpNum, u8 *BufferPtr, u32 BufferLen) |
int | XUsb_EpDataRecv (XUsb *InstancePtr, u8 EpNum, u8 *BufferPtr, u32 BufferLen) |
void | XUsb_EpStall (const XUsb *InstancePtr, u8 EpNum) |
void | XUsb_EpUnstall (const XUsb *InstancePtr, u8 EpNum) |
void | XUsb_EpIsoTransferConfigure (XUsb *InstancePtr, u8 EpNum, u8 NoOfTransfers) |
void | XUsb_IntrEnable (XUsb *InstancePtr, u32 IntrMask) |
void | XUsb_IntrDisable (XUsb *InstancePtr, u32 IntrMask) |
void | XUsb_IntrHandler (void *InstancePtr) |
void | XUsb_IntrSetHandler (XUsb *InstancePtr, void *CallBackFunc, void *CallBackRef) |
void | XUsb_EpSetHandler (XUsb *InstancePtr, u8 EpNum, XUsb_EpHandlerFunc *CallBackFunc, void *CallBackRef) |
void | XUsb_ErrIntrSetHandler (XUsb *InstancePtr, void *CallBackFunc, void *CallBackRef) |
void | XUsb_DmaIntrSetHandler (XUsb *InstancePtr, void *CallBackFunc, void *CallBackRef) |
void | XUsb_UlpiIntrSetHandler (XUsb *InstancePtr, void *CallBackFunc, void *CallBackRef) |
XUsb_Config * | XUsb_LookupConfig (u16 DeviceId) |
#define TEST_J 1 |
Chirp J Test
#define TEST_K 2 |
Chirp K Test
#define TEST_PKT 4 |
Packet Test
#define TEST_SE0_NAK 3 |
Chirp SE0 Test
#define XUSB_DEVICEADDR_MAX 127 |
Max device address
#define XUSB_DISCONNECTED 0x1 |
Disconnected state
#define XUSB_EP_DIRECTION_IN 1 |
Endpoint direction IN.
#define XUSB_EP_DIRECTION_OUT 0 |
Endpoint direction OUT.
#define XUSB_EP_FULL_SPEED 0 |
Full Speed
#define XUSB_EP_HIGH_SPEED 1 |
High Speed
#define XUSB_EP_NUMBER_ZERO 0 |
End point Zero
#define XUSB_MAX_ENDPOINTS 8 |
Maximum End Points
#define XUSB_RESET 0x0 |
Reset State
typedef void(* XUsb_EpHandlerFunc)(void *CallBackRef, u8 EpNum, u32 EventType) |
This data type defines the callback function to be used for Endpoint handlers.
CallBackRef | is the Callback reference passed in by the upper layer when setting the handler, and is passed back to the upper layer when the handler is called. | |
EpNum | is the endpoint that caused the event. | |
EventType | is the type of the event that occurred on that endpoint. |
typedef void(* XUsb_IntrHandlerFunc)(void *CallBackRef, u32 InterruptType) |
This data type defines the callback function to be used for the general interrupt handler.
CallBackRef | is the Callback reference passed in by the upper layer when setting the handler, and is passed back to the upper layer when the handler is called. | |
InterruptType | is the type of the event that caused the interrupt. |
int XUsb_CfgInitialize | ( | XUsb * | InstancePtr, | |
XUsb_Config * | ConfigPtr, | |||
u32 | EffectiveAddr | |||
) |
Setup / Initialize and DMA functions
Implemented in the file xusb.c
This function initializes a XUsb instance/driver.
The initialization entails:
InstancePtr | is a pointer to the XUsb instance of the USB device. | |
ConfigPtr | is a pointer to a XUsb_Config configuration structure. This structure will contain the requested configuration for the device. Typically, this is a local structure and the content of which will be copied into the configuration structure within XUsb. | |
EffectiveAddr | is the device base address in the virtual memory address space. If the address translation is not used then the physical address is passed. Unexpected errors may occur if the address mapping is changed after this function is invoked. |
int XUsb_ConfigureDevice | ( | XUsb * | InstancePtr, | |
XUsb_DeviceConfig * | CfgPtr | |||
) |
This function initializes USB End points.
InstancePtr | is a pointer to the XUsb instance. | |
CfgPtr | is pointer to a XUsb_Config configuration structure. This structure will contain the requested configuration for the device. Typically, this is a local structure and the content of which will be copied into the configuration structure within XUsb. |
void XUsb_DmaIntrSetHandler | ( | XUsb * | InstancePtr, | |
void * | CallBackFunc, | |||
void * | CallBackRef | |||
) |
This function installs an asynchronous callback function for the DMA events.
InstancePtr | is a pointer to the XUsb instance. | |
CallBackFunc | is the address of the callback function. | |
CallBackRef | is a user data item that will be passed to the callback function when it is invoked. |
void XUsb_DmaReset | ( | XUsb * | InstancePtr | ) |
This function resets the DMA module of the USB device
InstancePtr | is a pointer to the XUsb instance. |
void XUsb_DmaTransfer | ( | XUsb * | InstancePtr, | |
u32 * | SrcAddr, | |||
u32 * | DstAddr, | |||
u16 | Length | |||
) |
This function sets the DMA registers with the given values to initiate a DMA data transfer. This function is called by the XUsb_EpDataSend and XUsb_EpDataRecv functions.
InstancePtr | is a pointer to the XUsb instance. | |
SrcAddr | is the source address from where the data is to be read. | |
DstAddr | is the destination address to where the data is to be written. | |
Length | is the amount of data that can be transferred. The maximum data transfer can be 1024. |
void XUsb_EpConfigure | ( | XUsb * | InstancePtr, | |
u8 | EpNum, | |||
XUsb_EpConfig * | EpCfgPtr | |||
) |
This function configures a specific end point with the given configuration data.
InstancePtr | is a pointer to the XUsb instance. | |
EpNum | is the endpoint number which has to be configured. | |
EpCfgPtr | is a pointer to the endpoint configuration structure. |
int XUsb_EpDataRecv | ( | XUsb * | InstancePtr, | |
u8 | EpNum, | |||
u8 * | BufferPtr, | |||
u32 | BufferLen | |||
) |
This function copies the received data from end point buffer to the buffer passed and then makes the device ready for receiving data again into the same end point buffer.
InstancePtr | is a pointer to the XUsb instance. | |
EpNum | is the endpoint number. | |
BufferPtr | is a pointer to buffer where data is to be copied. | |
BufferLen | is the number of data bytes to be received. |
int XUsb_EpDataSend | ( | XUsb * | InstancePtr, | |
u8 | EpNum, | |||
u8 * | BufferPtr, | |||
u32 | BufferLen | |||
) |
This function copies the transmit data to the end point buffer and enables the buffer for transmission.
InstancePtr | is a pointer to the XUsb instance. | |
EpNum | is the endpoint number. | |
BufferPtr | is a pointer to buffer containing the data to be sent. | |
BufferLen | is the number of data bytes to be sent. |
void XUsb_EpDisable | ( | const XUsb * | InstancePtr, | |
u8 | EpNum | |||
) |
This function disables the specified endpoint for all operations.
InstancePtr | is a pointer to the XUsb instance. | |
EpNum | is the endpoint number which has to be disabled for operations. |
void XUsb_EpEnable | ( | const XUsb * | InstancePtr, | |
u8 | EpNum | |||
) |
This function enables the specified endpoint for all operations.
InstancePtr | is a pointer to the XUsb instance. | |
EpNum | is the endpoint number which has to be enabled for operations. |
void XUsb_EpIsoTransferConfigure | ( | XUsb * | InstancePtr, | |
u8 | EpNum, | |||
u8 | NoOfTransfers | |||
) |
This function sets the number of isochronous transfers in a microframe for a given endpoint.
InstancePtr | is a pointer to the XUsb instance. | |
EpNum | is the endpoint number. | |
NoOfTransfers | is the number of transfers in a microframe. |
void XUsb_EpSetHandler | ( | XUsb * | InstancePtr, | |
u8 | EpNum, | |||
XUsb_EpHandlerFunc * | CallBackFunc, | |||
void * | CallBackRef | |||
) |
This function sets the handler for endpoint events.
InstancePtr | is a Pointer to the XUsb instance. | |
EpNum | is the Number of the endpoint. | |
CallBackFunc | is the address of the callback function. It can be NULL if the user wants to disable the handler entry. | |
CallBackRef | is a user data item that will be passed to the callback function when it is invoked. This can be NULL. |
void XUsb_EpStall | ( | const XUsb * | InstancePtr, | |
u8 | EpNum | |||
) |
This function stalls operations for the specified endpoint.
InstancePtr | is a pointer to the XUsb instance. | |
EpNum | is the endpoint number which has to be stalled for operations. |
void XUsb_EpUnstall | ( | const XUsb * | InstancePtr, | |
u8 | EpNum | |||
) |
This function unstalls operations for the specified endpoint.
InstancePtr | is a pointer to the XUsb instance. | |
EpNum | is the endpoint number for which the unstall operations are to be carried out. |
void XUsb_ErrIntrSetHandler | ( | XUsb * | InstancePtr, | |
void * | CallBackFunc, | |||
void * | CallBackRef | |||
) |
This function installs an asynchronous callback function for the error events.
InstancePtr | is a pointer to the XUsb instance. | |
CallBackFunc | is the address of the callback function. | |
CallBackRef | is a user data item that will be passed to the callback function when it is invoked. |
u32 XUsb_GetFrameNum | ( | const XUsb * | InstancePtr | ) |
This function returns the current frame number.
InstancePtr | is a pointer to the XUsb instance. |
void XUsb_IntrDisable | ( | XUsb * | InstancePtr, | |
u32 | Mask | |||
) |
This function disables the specified interrupts.
InstancePtr | is a pointer to the XUsb instance. | |
Mask | is the bit-mask of the interrupts to be disabled. Bit positions of 1 will be enabled. Bit positions of 0 will keep the previous setting. This mask is formed by OR'ing XUSB_STATUS_*_MASK bits defined in xusb_l.h. |
void XUsb_IntrEnable | ( | XUsb * | InstancePtr, | |
u32 | Mask | |||
) |
This function enables the specified interrupts.
InstancePtr | is a pointer to the XUsb instance. | |
Mask | is the bit-mask of the interrupts to be enabled. Bit positions of 1 will be enabled. Bit positions of 0 will keep the previous setting. This mask is formed by OR'ing XUSB_STATUS_*_MASK bits defined in xusb_l.h. |
void XUsb_IntrHandler | ( | void * | InstancePtr | ) |
This function is the interrupt handler for the USB driver. This function is the first-level interrupt handler for the USB core. All USB interrupts will be handled here. Depending on the type of the interrupt, second level interrupt handler may be called. Second level interrupt handlers will be registered by the user using the XUsb_IntrSetHandler() and/or XUsb_EpSetHandler() functions.
This handler reads the interrupt status from the Interrupt Status Register, determines the source of the interrupts, calls the corresponding callbacks and finally clears the interrupts.
The interrupt from the USB driver has to be connected to the interrupt controller and the handler has to be registered with the interrupt system.
Applications using this driver are responsible for providing the callbacks to handle interrupts and installing the callbacks using XUsb_SetHandler() during the initialization phase.
InstancePtr | is a pointer to the XUsb instance that just interrupted. |
void XUsb_IntrSetHandler | ( | XUsb * | InstancePtr, | |
void * | CallBackFunc, | |||
void * | CallBackRef | |||
) |
This function installs an asynchronous callback function for the general interrupt (interrupts other than the endpoint and error interrupts).
InstancePtr | is a pointer to the XUsb instance. | |
CallBackFunc | is the address of the callback function. | |
CallBackRef | is a user data item that will be passed to the callback function when it is invoked. |
XUsb_Config* XUsb_LookupConfig | ( | u16 | DeviceId | ) |
Looks up the device configuration based on the unique device ID. A table contains the configuration info for each device in the system.
DeviceId | contains the ID of the device for which the device configuration pointer is to be returned. |
void XUsb_ReadErrorCounters | ( | XUsb * | InstancePtr, | |
u8 * | BitStuffErrors, | |||
u8 * | PidErrors, | |||
u8 * | CrcErrors | |||
) |
This function reads the USB error counter regsiter and returns the error counters information.
InstancePtr | is a pointer to the XUsb instance. | |
BitStuffErrors | is a pointer to the 8 bit bitstuff error counter. | |
PidErrors | is a pointer to the 8 bit pid error counter. | |
CrcErrors | is a pointer to the 8 bit crc error counter. |
int XUsb_SetDeviceAddress | ( | XUsb * | InstancePtr, | |
u8 | Address | |||
) |
This function sets the USB device address.
InstancePtr | is a pointer to the XUsb instance. | |
Address | is the device address to be set. |
void XUsb_SetTestMode | ( | XUsb * | InstancePtr, | |
u8 | TestMode, | |||
u8 * | BufPtr | |||
) |
This function sets the USB device into a given test mode.
InstancePtr | is a pointer to the XUsb instance. | |
TestMode | is the type of test to be performed. | |
BufPtr | is a pointer to the buffer containing the test packet. |
void XUsb_SieReset | ( | XUsb * | InstancePtr | ) |
This function resets the Serial Interface Engine
InstancePtr | is a pointer to the XUsb instance. |
void XUsb_Start | ( | XUsb * | InstancePtr | ) |
This function starts the USB Device.
InstancePtr | is a pointer to the XUsb instance. |
void XUsb_Stop | ( | XUsb * | InstancePtr | ) |
This function stops the USB device.
InstancePtr | is a pointer to the XUsb instance. |
void XUsb_UlpiIntrSetHandler | ( | XUsb * | InstancePtr, | |
void * | CallBackFunc, | |||
void * | CallBackRef | |||
) |
This function installs an asynchronous callback function for the ULPI PHY events.
InstancePtr | is a pointer to the XUsb instance. | |
CallBackFunc | is the address of the callback function. | |
CallBackRef | is a user data item that will be passed to the callback function when it is invoked. |
u8 XUsb_UlpiPhyReadRegister | ( | XUsb * | InstancePtr, | |
u8 | RegAddr | |||
) |
This function initiates the USB ULPI PHY regsiter read transaction. This function returns the busy status if the earlier transaction is still in progress and returns the PHY register data upon successful read transaction.
InstancePtr | is a pointer to the XUsb instance. | |
RegAddr | is the address of the PHY register. |
int XUsb_UlpiPhyWriteRegister | ( | XUsb * | InstancePtr, | |
u8 | RegAddr, | |||
u8 | UlpiPhyRegData | |||
) |
This function initiates the USB ULPI PHY regsiter write transaction. This function returns the busy status if the earlier transaction is still in progress and returns a success upon successful write transaction initiation.
InstancePtr | is a pointer to the XUsb instance. | |
RegAddr | is the address of the PHY register. counter. | |
UlpiPhyRegData | is the data to be written to PHY register. |
Copyright © 1995-2014 Xilinx, Inc. All rights reserved.