Software Drivers

xusb.c File Reference

#include "xusb.h"

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)

Detailed Description

The XUsb driver. Functions in this file are the minimum required functions for this driver. See xusb.h for a detailed description of the driver.

Note:
None.
 MODIFICATION HISTORY:
 Ver   Who  Date     Changes
 ----- ---- -----------------------------------------------------------------
 1.00a hvm  2/22/07 First release
 2.00a hvm  10/22/08 Added DMA APIs.
 3.00a hvm  12/3/09 Added XUsb_ReadErrorCounters API to return USB error
                     counters data. Updated to use HAL processor APIs.
		       XUsb_mReadReg is renamed to XUsb_ReadReg and
		       XUsb_mWriteReg is renamed to XUsb_WriteReg.
 3.02a hvm  7/15/10  Added Device ID initialization in XUsb_CfgInitialize
		       function (CR555996).
 4.00a hvm  10/21/10 Added ULPI PHY Read/Write APIs.
 			Added DMA handler initialization in XUsb_CfgInitialize
			function
 4.03a bss  06/20/10 Added SIE Reset API (XUsb_SieReset) to reset the SIE
 			state machine (CR 660602)
 

Function Documentation

int XUsb_CfgInitialize ( XUsb InstancePtr,
XUsb_Config ConfigPtr,
u32  EffectiveAddr 
)

This function initializes a XUsb instance/driver.

The initialization entails:

  • Initialize all members of the XUsb structure.
Parameters:
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.
Returns:
  • XST_SUCCESS no errors occurred.
  • XST_FAILURE an error occurred during initialization.
Note:
After calling XUsb_CfgInitialize() the USB device IS NOT READY for use. Before the USB device can be used its parameters must be configured. See xusb.h for details.
int XUsb_ConfigureDevice ( XUsb InstancePtr,
XUsb_DeviceConfig CfgPtr 
)

This function initializes USB End points.

Parameters:
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.
Returns:
  • XST_SUCCESS no errors occurred.
  • XST_FAILURE an error occurred during initialization.
Note:
None.
void XUsb_DmaReset ( XUsb InstancePtr  ) 

This function resets the DMA module of the USB device

Parameters:
InstancePtr is a pointer to the XUsb instance.
Returns:
None.
Note:
After the DMA reset, only the DMA related logic part of the USB device will be reset and all the DMA related registers will be reset to the default values. Upon DMA Reset, any DMA transfer in progress will be stopped.
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.

Parameters:
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.
Returns:
None.
Note:
This function doesn't guarantee that the transfer is done successfully. This function only initiates the DMA transfer.
u32 XUsb_GetFrameNum ( const XUsb InstancePtr  ) 

This function returns the current frame number.

Parameters:
InstancePtr is a pointer to the XUsb instance.
Returns:
The current frame number..
Note:
None.
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.

Parameters:
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.
Returns:
None.
Note:
None.
int XUsb_SetDeviceAddress ( XUsb InstancePtr,
u8  Address 
)

This function sets the USB device address.

Parameters:
InstancePtr is a pointer to the XUsb instance.
Address is the device address to be set.
Returns:
  • XST_SUCCESS: Address set successfully.
  • XST_INVALID_PARAM: Invalid parameter passed.
Note:
None.
void XUsb_SetTestMode ( XUsb InstancePtr,
u8  TestMode,
u8 *  BufPtr 
)

This function sets the USB device into a given test mode.

Parameters:
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.
Returns:
None.
Note:
If the test mode is Test packet(TEST_PKT), then user needs to pass the address of the buffer containing the test packet. In other cases, the BufPtr parameter is not used and the user can send a NULL or any value. BufPtr parameter should be 32 bit aligned.
void XUsb_SieReset ( XUsb InstancePtr  ) 

This function resets the Serial Interface Engine

Parameters:
InstancePtr is a pointer to the XUsb instance.
Returns:
None.
Note:
After the SIE reset, only the SIE state machine logic part of the USB device will be reset and starts from Init state.
void XUsb_Start ( XUsb InstancePtr  ) 

This function starts the USB Device.

Parameters:
InstancePtr is a pointer to the XUsb instance.
Returns:
None.
Note:
None.
void XUsb_Stop ( XUsb InstancePtr  ) 

This function stops the USB device.

Parameters:
InstancePtr is a pointer to the XUsb instance.
Returns:
None.
Note:
None.
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.

Parameters:
InstancePtr is a pointer to the XUsb instance.
RegAddr is the address of the PHY register.
Returns:
  • Register data
  • XST_DEVICE_BUSY: The previous PHY transaction is still in progress.
Note:
This function waits till the BUSY bit is cleared in the ULPI PHY resgiter and then reads the register. The user of this API should note that the PHY interrupt should be ignored during read operation.
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.

Parameters:
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.
Returns:
  • XST_SUCCESS: Read transaction initiated successfully.
  • XST_DEVICE_BUSY: The previous PHY transaction is still in progress.
Note:
None.