www.pudn.com > hf44b0_TEST.rar > usb.H


#ifndef _USB_H_ 
#define _USB_H_ 
 
#define Usb_Base_Address 0x2000000 
#define Usb_Data_Address 0x0000000 
#define Usb_Command_Address 0x0000001 
//**************************************************************************** 
// 
// USB.H - Defines for the USB specification and the Philips PDIUSBD12 USB 
//         controller. 
// 
// Copyright (c) 1999 Cirrus Logic, Inc. 
// 
//**************************************************************************** 
//**************************************************************************** 
// 
// The following defines are specific the USB standard version 1.1. 
// 
//**************************************************************************** 
 
// 
// Definitions of the bit fields in the bmRequestType field of a setup packet. 
// 
#define USB_RT_DEVICE_TO_HOST                   0x80 
#define USB_RT_TYPE_MASK                        0x60 
#define USB_RT_TYPE_STANDARD                    0x00 
#define USB_RT_TYPE_CLASS                       0x20 
#define USB_RT_TYPE_VENDOR                      0x40 
#define USB_RT_RECIPIENT_MASK                   0x1F 
#define USB_RT_RECIPIENT_DEVICE                 0x00 
#define USB_RT_RECIPIENT_INTERFACE              0x01 
#define USB_RT_RECIPIENT_ENDPOINT               0x02 
 
// 
// Definitions of the bit fields in the wIndex field of setup packets where the 
// wIndex field is used to specify a endpoint (i.e. Clear_Feature, Get_Status, 
// and Set_Feature). 
// 
#define USB_ENDPOINT_DIRECTION_MASK             0x0080 
#define USB_ENDPOINT_ADDRESS_MASK               0x000F 
 
// 
// Definitions of the features that can be specified in the wValue field of a 
// Clear_Feature or Set_Feature setup packet. 
// 
#define USB_FEATURE_ENDPOINT_STALL              0x0000 
#define USB_FEATURE_REMOTE_WAKEUP               0x0001 
#define USB_FEATURE_POWER_D0                    0x0002 
#define USB_FEATURE_POWER_D1                    0x0003 
#define USB_FEATURE_POWER_D2                    0x0004 
#define USB_FEATURE_POWER_D3                    0x0005 
 
// 
// Definitions of the wValue field for a Get_Descriptor setup packet. 
// 
#define USB_DESCRIPTOR_TYPE_MASK                0xFF00 
#define USB_DESCRIPTOR_DEVICE                   0x0100 
#define USB_DESCRIPTOR_CONFIGURATION            0x0200 
#define USB_DESCRIPTOR_STRING                   0x0300 
#define USB_DESCRIPTOR_INTERFACE                0x0400 
#define USB_DESCRIPTOR_ENDPOINT                 0x0500 
#define USB_DESCRIPTOR_INDEX_MASK               0x00FF 
 
// 
// Definitions of the device status returned for a Get_Status setup packet. 
// 
#define USB_DEVICE_STATUS_SELF_POWERED          0x01 
#define USB_DEVICE_STATUS_REMOTE_WAKEUP         0x02 
 
// 
// Definitions of the endpoint status returned for a Get_Status setup packet. 
// 
#define USB_ENDPOINT_STATUS_STALLED             0x01 
 
//**************************************************************************** 
// 
// The following defines are specific the the Philips PDIUSBD12 USB 
// controller. 
// 
//**************************************************************************** 
 
// 
// The offsets to the individual registers in the PDIUSBD12 USB controller. 
// 
#define HwUSBData                               0x00000000 
#define HwUSBCommand                            0x00000001 
 
// 
// Definitions of the supported endpoints. 
// 
#define USB_ENDPOINT_CONTROL_OUT                0x00 
#define USB_ENDPOINT_CONTROL_IN                 0x01 
#define USB_ENDPOINT_COMMAND_OUT		0x02 
#define USB_ENDPOINT_ACK_IN                     0x03 
#define USB_ENDPOINT_BULK_OUT                   0x04 
#define USB_ENDPOINT_BULK_IN                    0x05 
 
// 
// Definitions of the commands that can be sent to the PDIUSBD12. 
// 
#define USB_COMMAND_SELECT_ENDPOINT             0x00 
#define USB_COMMAND_READ_LAST_XACTION_STATUS    0x40 
#define USB_COMMAND_SET_ENDPOINT_STATUS         0x40 
#define USB_COMMAND_SET_ADDRESS_ENABLE          0xD0 
#define USB_COMMAND_SET_ENDPOINT_ENABLE         0xD8 
#define USB_COMMAND_READ_BUFFER                 0xF0 
#define USB_COMMAND_WRITE_BUFFER                0xF0 
#define USB_COMMAND_ACKNOWLEDGE_ENDPOINT        0xF1 
#define USB_COMMAND_CLEAR_BUFFER                0xF2 
#define USB_COMMAND_SET_MODE                    0xF3 
#define USB_COMMAND_READ_INTERRUPT              0xF4 
#define USB_COMMAND_VALIDATE_BUFFER             0xFA 
#define USB_COMMAND_SET_DMA                     0xFB 
 
#define USB_COMMAND_SEND_RESUME                 0xF6 
// 
// Definitions of the bit fields in the first byte of the configuration 
// register. 
// 
#define USB_CONFIG1_NO_LAZY_CLOCK               0x02 
#define USB_CONFIG1_CLOCK_RUNNING               0x04 
#define USB_CONFIG1_INTERRUPT_MODE              0x08 
#define USB_CONFIG1_SOFT_CONNECT                0x10 
#define USB_CONFIG1_NONISO_MODE                 0x00 
#define USB_CONFIG1_ISOOUT_MODE                 0x40 
#define USB_CONFIG1_ISOIN_MODE                  0x80 
#define USB_CONFIG1_ISOIO_MODE                  0xC0 
 
// 
// Definitions of the bit fields in the second byte of the configuration 
// register. 
// 
#define USB_CONFIG2_CLOCK_12M                   0x03 
#define USB_CONFIG2_CLOCK_4M                    0x0B 
#define USB_CONFIG2_SET_TO_ONE                  0x40 
#define USB_CONFIG2_SOF_ONLY                    0x80 
 
// 
// Definitions of the bit fields in the DMA configuration register. 
// 
#define USB_DMA_SINGLE                          0x00 
#define USB_DMA_BURST_4                         0x01 
#define USB_DMA_BURST_8                         0x02 
#define USB_DMA_BURST_16                        0x03 
#define USB_DMA_ENABLE                          0x04 
#define USB_DMA_DIRECTION                       0x08 
#define USB_DMA_AUTO_RELOAD                     0x10 
#define USB_DMA_INTPINMODE                      0x20 
#define USB_DMA_ENDP4_INT_ENABLE                0x40 
#define USB_DMA_ENDP5_INT_ENABLE                0x80 
 
// 
// Definitions of the bit fields in the first byte of the interrupt register. 
// 
#define USB_INT1_CONTROL_OUT                    0x01 
#define USB_INT1_CONTROL_IN                     0x02 
#define USB_INT1_ENDPOINT1_OUT                  0x04 
#define USB_INT1_ENDPOINT1_IN                   0x08 
#define USB_INT1_ENDPOINT2_OUT                  0x10 
#define USB_INT1_ENDPOINT2_IN                   0x20 
#define USB_INT1_BUS_RESET                      0x40 
#define USB_INT1_SUSPEND_CHANGE                 0x80 
 
// 
// Definitions of the bit fields in the second byte of the interrupt register. 
// 
#define USB_INT2_EOT                            0x01 
 
// 
// Definitions of the bit fields in the last transaction status register. 
// 
#define USB_XACTION_STATUS_DATA_RX_TX_SUCCESS   0x01 
#define USB_XACTION_STATUS_SETUP_PACKET         0x20 
#define USB_XACTION_STATUS_PREPACKET		0X80 
 
// 
// Definitions of the bit fields in the endpoint status register. 
// 
#define USB_ENDPOINT_STATUS_FULL_EMPTY          0x01 
#define USB_ENDPOINT_STALL                      0x02 
 
#define SIZE_USBCOMM_HISR		4000 
#define SIZE_USBCOMM_TASK 		40000 
 
#define USB_EVENT_LOADLIST		0x00000001 
#define USB_EVENT_DELFILE		0x00000002 
#define USB_EVENT_RECEFILE		0x00000004 
#define USB_EVENT_FORMAT		0x00000008 
#define USB_EVENT				(USB_EVENT_LOADLIST|USB_EVENT_DELFILE|USB_EVENT_RECEFILE|USB_EVENT_FORMAT) 
 
//from usb.c 
void USBON(void); 
void USBEnable(void); 
void USBWriteData(unsigned char datavalue); 
void USBWriteCommand(unsigned char commandvalue); 
unsigned char USBReadData(void); 
unsigned long USBReadEndpoint(unsigned long ulEndpoint, unsigned char **ppucData, 
                unsigned long *pulLength); 
void USBReserved(void); 
unsigned long USBSendACK(const unsigned char *pucData, unsigned long ulLength); 
void USBStallEndpoint(unsigned long ulEndpoint, unsigned long bStall); 
void USBWriteEndpoint(unsigned long ulEndpoint, const unsigned char **ppucData, 
                 unsigned long *pulLength); 
void USBGetStatus(void); 
unsigned long USBSendControl(const unsigned char *pucData, unsigned long ulLength); 
void USBClearFeature(void); 
void USBSetAddress(void); 
void USBSetFeature(void); 
void USBGetDescriptor(void); 
void USBGetConfiguration(void); 
void USBSetConfiguration(void); 
void USBGetInterface(void); 
void USBSetInterface(void); 
void __irq USBISR(void); 
void USBOFF(void); 
unsigned long USBReceiveBulk(unsigned char *pucData, unsigned long ulLength); 
unsigned long USBReceiveBulkDone(void); 
unsigned long USBReceiveCommand(unsigned char *pucData, unsigned long ulLength); 
unsigned long USBReceiveCommandDone(void); 
unsigned long USBSendACKDone(void); 
unsigned long USBSendBulk(const unsigned char *pucData, unsigned long ulLength); 
unsigned long USBSendBulkDone(void); 
unsigned long USBSendControlDone(void); 
void USBIrqDisable(void); 
void USBIrqEnable(void); 
 
#endif