基于AT89C51SND1的MP3的程序设计(包括播放mp3和录音功能)

源代码在线查看: usb_drv.h

软件大小: 1052 K
上传用户: shkk21
关键词: SND1 89C C51 SND
下载地址: 免注册下载 普通下载 VIP

相关代码

				/*H**************************************************************************
				* NAME:         usb_drv.h         
				*----------------------------------------------------------------------------
				* Copyright (c) 2003 Atmel.
				*----------------------------------------------------------------------------
				* RELEASE:      snd1c-refd-nf-4_0_3      
				* REVISION:     1.11     
				*----------------------------------------------------------------------------
				* PURPOSE:
				* This file contains the USB driver definition
				*****************************************************************************/
				
				#ifndef _USB_DRV_H_
				#define _USB_DRV_H_
				
				/*_____ I N C L U D E S ____________________________________________________*/
				
				
				/*_____ M A C R O S ________________________________________________________*/
				
				#define CONTROL               0x80
				#define BULK_IN               0x86
				#define BULK_OUT              0x82
				#define INTERRUPT_IN          0x87
				#define INTERRUPT_OUT         0x83
				#define ISOCHRONOUS_IN        0x85
				#define ISOCHRONOUS_OUT       0x81
				#define BULK_MAX_SIZE         ((Byte)64)
				
				#define GET_DEVICE_DESCRIPTOR           1
				#define GET_CONFIGURATION_DESCRIPTOR    4
				
				
				/*_____ S T A N D A R D    R E Q U E S T S __________________________________*/
				
				#define GET_STATUS            0x00
				#define GET_DEVICE            0x01
				#define CLEAR_FEATURE         0x01        /* see FEATURES below */
				#define GET_STRING            0x03
				#define SET_FEATURE           0x03        /* see FEATURES below */
				#define SET_ADDRESS           0x05
				#define GET_DESCRIPTOR        0x06
				#define SET_DESCRIPTOR        0x07
				#define GET_CONFIGURATION     0x08
				#define SET_CONFIGURATION     0x09
				#define GET_INTERFACE         0x0A
				#define SET_INTERFACE         0x0B
				#define SYNC_FRAME            0x0C
				#define GET_MAX_LUN           0xFE
				#define MASS_STORAGE_RESET    0xFF
				
				
				/*_____ D E S C R I P T O R    T Y P E S ____________________________________*/
				
				#define DEVICE                0x01
				#define CONFIGURATION         0x02
				#define STRING                0x03
				#define INTERFACE             0x04
				#define ENDPOINT              0x05
				
				#define LANG_ID               0x00
				#define MAN_INDEX             0x01
				#define PROD_INDEX            0x02
				#define SN_INDEX              0x03
				
				
				/*_____ S T A N D A R D    F E A T U R E S __________________________________*/
				
				#define DEVICE_REMOTE_WAKEUP_FEATURE     0x01
				#define ENDPOINT_HALT_FEATURE            0x00
				
				/*_____ D E V I C E   S T A T U S ___________________________________________*/
				
				#define SELF_POWERED       1
				
				/*_____ D E V I C E   S T A T E _____________________________________________*/
				
				#define ATTACHED                  0
				#define POWERED                   1
				#define DEFAULT                   2
				#define ADDRESSED                 3
				#define CONFIGURED                4
				#define SUSPENDED                 5
				
				#define USB_CONFIG_BUSPOWERED     0x80
				#define USB_CONFIG_SELFPOWERED    0x40
				#define USB_CONFIG_REMOTEWAKEUP   0x20
				
				/*_____ M A S S   S T O R A G E   E N D P O I N T S _________________________*/
				
				#define EP_CONTROL                0x00
				#define EP_IN                     0x01
				#define EP_OUT                    0x02
				#define EP_CONTROL_LENGTH         8
				#define EP_IN_LENGTH              64
				#define EP_OUT_LENGTH             64
				
				/*_________________________________________________________ S T R U C T _____*/
				/*_____ U S B   D E V I C E   R E Q U E S T _________________________________*/
				struct Endpoint_information_st
				 {
				  Uint16  fifo_size ;             /* size of the endpoint FIFO */
				  Uint16  fifo_left ;
				 };
				
				struct USB_request_st
				  {
				    Byte    bmRequestType;        /* Characteristics of the request */
				    Byte    bRequest;             /* Specific request */
				    Uint16  wValue;               /* field that varies according to request */
				    Uint16  wIndex;               /* field that varies according to request */
				    Uint16  wLength;              /* Number of bytes to transfer if Data */
				  };
				
				
				/*_____ U S B   D E V I C E   D E S C R I P T O R ___________________________*/
				
				struct usb_st_device_descriptor
				  {
				    Byte   bLength;               /* Size of this descriptor in bytes */
				    Byte   bDescriptorType;       /* DEVICE descriptor type */
				    Uint16 bscUSB;                /* Binay Coded Decimal Spec. release */
				    Byte   bDeviceClass;          /* Class code assigned by the USB */
				    Byte   bDeviceSubClass;       /* Sub-class code assigned by the USB */
				    Byte   bDeviceProtocol;       /* Protocol code assigned by the USB */
				    Byte   bMaxPacketSize0;       /* Max packet size for EP0 */
				    Uint16 idVendor;              /* Vendor ID. ATMEL = 0x03EB */
				    Uint16 idProduct;             /* Product ID assigned by the manufacturer */
				    Uint16 bcdDevice;             /* Device release number */
				    Byte   iManufacturer;         /* Index of manu. string descriptor */
				    Byte   iProduct;              /* Index of prod. string descriptor */
				    Byte   iSerialNumber;         /* Index of S.N.  string descriptor */
				    Byte   bNumConfigurations;    /* Number of possible configurations */
				  };
				
				
				/*_____ U S B   C O N F I G U R A T I O N   D E S C R I P T O R _____________*/
				
				struct usb_st_configuration_descriptor
				  {
				    Byte   bLength;               /* size of this descriptor in bytes */
				    Byte   bDescriptorType;       /* CONFIGURATION descriptor type */
				    Uint16 wTotalLength;          /* total length of data returned */
				    Byte   bNumInterfaces;        /* number of interfaces for this conf. */
				    Byte   bConfigurationValue;   /* value for SetConfiguration resquest */
				    Byte   iConfiguration;        /* index of string descriptor */
				    Byte   bmAttibutes;           /* Configuration characteristics */
				    Byte   MaxPower;              /* maximum power consumption */
				  };
				
				
				/*_____ U S B   M A N U F A C T U R E R   D E S C R I P T O R _______________*/
				
				struct usb_st_manufacturer
				  {
				    Byte   bLength;               /* size of this descriptor in bytes */
				    Byte   bDescriptorType;       /* STRING descriptor type */
				    Uint16 wstring[USB_MN_LENGTH];/* unicode characters */
				  };
				
				
				/*_____ U S B   P R O D U C T   D E S C R I P T O R _________________________*/
				
				struct usb_st_product
				  {
				    Byte   bLength;               /* size of this descriptor in bytes */
				    Byte   bDescriptorType;       /* STRING descriptor type */
				    Uint16 wstring[USB_PN_LENGTH];/* unicode characters */
				  };
				
				
				/*_____ U S B   S E R I A L   N U M B E R   D E S C R I P T O R _____________*/
				
				struct usb_st_serial_number
				  {
				    Byte   bLength;               /* size of this descriptor in bytes */
				    Byte   bDescriptorType;       /* STRING descriptor type */
				    Uint16 wstring[USB_SN_LENGTH];/* unicode characters */
				  };
				
				
				/*_____ U S B   L A N G U A G E    D E S C R I P T O R ______________________*/
				
				struct usb_st_language_descriptor
				  {
				    Byte   bLength;               /* size of this descriptor in bytes */
				    Byte   bDescriptorType;       /* STRING descriptor type */
				    Uint16 wlangid;               /* language id */
				  };
				
				
				/*_____ U S B   I N T E R F A C E   D E S C R I P T O R _____________________*/
				
				struct usb_st_interface_descriptor
				  {
				    Byte  bLength;                /* size of this descriptor in bytes */
				    Byte  bDescriptorType;        /* INTERFACE descriptor type */
				    Byte  bInterfaceNumber;       /* Number of interface */
				    Byte  bAlternateSetting;      /* value to select alternate setting */
				    Byte  bNumEndpoints;          /* Number of EP except EP 0 */
				    Byte  bInterfaceClass;        /* Class code assigned by the USB */
				    Byte  bInterfaceSubClass;     /* Sub-class code assigned by the USB */
				    Byte  bInterfaceProtocol;     /* Protocol code assigned by the USB */
				    Byte  iInterface;             /* Index of string descriptor */
				  };
				
				
				/*_____ U S B   E N D P O I N T   D E S C R I P T O R _______________________*/
				
				struct usb_st_endpoint_descriptor
				  {
				    Byte   bLength;               /* Size of this descriptor in bytes */
				    Byte   bDescriptorType;       /* ENDPOINT descriptor type */
				    Byte   bEndpointAddress;      /* Address of the endpoint */
				    Byte   bmAttributes;          /* Endpoint's attributes */
				    Uint16 wMaxPacketSize;        /* Maximum packet size for this EP */
				    Byte   bInterval;             /* Interval for polling EP in ms */
				  };
				
				
				
				/*_____ U S B   L I T T L E   E N D I A N    B I G   E N D I A N _________*/
				
				extern  bdata bit   bmCBWFlag7;
				extern  bdata bit   status_ready;
				extern  data  Byte  status;
				extern  bdata bit   rx_bank;
				
				
				/*_____ D E C L A R A T I O N ______________________________________________*/
				
				void    usb_init(void);
				void    usb_enumeration_process(void);
				                                      /* Standard define */
				#define Usb_enable()                  (USBCON |= MSK_USBE)
				#define Usb_disable()                 (USBCON &= ~MSK_USBE)
				#define Usb_enable_int()              (IEN1 |= MSK_EUSB)
				#define Usb_disable_int()             (IEN1 &= ~MSK_EUSB)
				#define Usb_set_clock(c)              (USBCLK = c)
				#define Usb_clear_EORINT()            (USBINT &= ~MSK_EORINT)
				#define Usb_clear_WUPCPU()            (USBINT &= ~MSK_WUPCPU)
				#define Usb_clear_SOFINT()            (USBINT &= ~MSK_SOFINT)
				#define Usb_clear_SPINT()             (USBINT &= ~MSK_SPINT)
				#define Usb_enable_SPINT()            (USBIEN |= MSK_SPINT)
				#define Usb_suspend()                 (USBINT & MSK_SPINT)
				#define Usb_resume()                  (USBINT & MSK_WUPCPU)
				#define Usb_reset()                   (USBINT & MSK_EORINT)
				#define Usb_clear_RXOUT()             (UEPSTAX &= ~MSK_RXOUT)
				#define Usb_clear_RXOUT_PP()          {if(rx_bank){UEPSTAX&=~MSK_RXOUTB1;}else{UEPSTAX&=(~MSK_RXOUTB0);}rx_bank=~rx_bank;}
				#define Usb_rx_complete()             (UEPSTAX & MSK_RXOUTB0B1)
				#define Usb_clear_RXSETUP()           (UEPSTAX &= ~MSK_RXSETUP)
				#define Usb_setup_received()          (UEPSTAX & MSK_RXSETUP)
				#define Usb_set_TXRDY()               (UEPSTAX |= MSK_TXRDY)
				#define Usb_clear_DIR()               (UEPSTAX &= ~MSK_DIR)
				#define Usb_set_DIR()                 (UEPSTAX |= MSK_DIR)
				#define Usb_clear_TXCMPL()            (UEPSTAX &= ~MSK_TXCMPL)
				#define Usb_tx_complete()             (UEPSTAX & MSK_TXCMPL)
				#define Usb_configure_address(x)      (USBADDR = (0x80 | x))
				#define Usb_set_CONFG()               (USBCON |= MSK_CONFG)
				#define Usb_clear_CONFG()             (USBCON &= ~MSK_CONFG)
				#define Usb_set_FADDEN()              (USBCON |= MSK_FADDEN)
				#define Usb_clear_FADDEN()            (USBCON &= ~MSK_FADDEN)
				#define Usb_select_ep(e)              (UEPNUM = e)
				
				#define Usb_clear_rx_bank()            (rx_bank = FALSE)
				
				#define MSK_EP_DIR                    0x7F
				#define REQUEST_DEVICE_STATUS         0x80
				#define REQUEST_INTERFACE_STATUS      0x81
				#define REQUEST_ENDPOINT_STATUS       0x82
				#define ENDPOINT_0                    0x00
				#define ENDPOINT_1                    0x81
				#define ENDPOINT_2                    0x02
				#define ZERO_TYPE                     0x00
				#define INTERFACE_TYPE                0x01
				#define ENDPOINT_TYPE                 0x02
				
				                                      /* mass storage define */
				#define FREE                          0x00
				#define Usb_set_STALLRQ()             (UEPSTAX |= MSK_STALLRQ)
				#define Usb_clear_STALLRQ()           (UEPSTAX &= ~MSK_STALLRQ)
				#define Usb_clear_STALLED()           (UEPSTAX &= ~MSK_STALLED)
				#define Usb_STALL_requested()         (UEPSTAX & MSK_STALLRQ)
				#define Usb_STALL_sent()              (UEPSTAX & MSK_STALLED)
				#define Usb_set_no_data_phase()       (no_data_phase = 1)
				#define Usb_clear_no_data_phase()     (no_data_phase = 0)
				
				#define Usb_read_byte()               (UEPDATX)
				#define Usb_write_byte(x)             (UEPDATX = x)
				
				#define Usb_set_no_data_phase()       (no_data_phase = 1)
				#define Usb_clear_no_data_phase()     (no_data_phase = 0)
				#define Usb_set_status_ready()        (status_ready = 1)
				#define Usb_clear_status_ready()      (status_ready = 0)
				#define Usb_set_status(x)             (status = x); (status_ready = 1) 
				#define Usb_CBWFlag_out()             (bmCBWFlag7 = 0)
				#define Usb_CBWFlag_in()              (bmCBWFlag7 = 1)
				#define Usb_get_CBWFlag()             (bmCBWFlag7)
				
				#define COMMAND_PASSED                0x00
				#define COMMAND_FAILED                0x01
				#define PHASE_ERROR                   0x02
				
				#ifndef USB_PU_CTRL
				  #error USB_PU_CTRL must be defined in config.h
				#else
				  #if USB_PU_CTRL == TRUE
				    #ifndef USB_PULL_UP_PORT
				      #error USB_PULL_UP_PORT must be defined in board definition header file
				    #else
				      #define Usb_enable_pull_up()    (USB_PULL_UP_PORT = 0)
				      #define Usb_disable_pull_up()   (USB_PULL_UP_PORT = 1)
				    #endif
				  #else
				    #define Usb_enable_pull_up()
				    #define Usb_disable_pull_up()
				  #endif
				#endif
				
				
				#endif  /* _USB_DRV_H_ */
							

相关资源