⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usb_drv.h

📁 用AT89C5131A开发USB的框架很好用
💻 H
📖 第 1 页 / 共 2 页
字号:
//! @file usb_drv.h
//!
//! Copyright (c) 2004
//!
//! Use of this program is subject to Atmel's End User License Agreement.
//! Please read file license.txt for copyright notice.
//!
//! @brief This file contains the USB low level driver definition 
//!
//! @version 1.19.2.1 (c5131-usb-generic-1_2_0)
//!
//! @todo
//! @bug

#ifndef _USB_DRV_H_
#define _USB_DRV_H_

//_____ I N C L U D E S ____________________________________________________
#include "conf\conf_usb.h"

typedef enum endpoint_parameter{ep_num, ep_type, ep_direction, ep_size, ep_bank, nyet_status} t_endpoint_parameter;

#ifndef NO_SUPPORT_USB_PING_PONG
   extern  bdata bit   rx_bank;
#endif

//_____ M A C R O S ________________________________________________________

#define EP_CONTROL            0
#define EP_1                  1
#define EP_2                  2
#define EP_3                  3
#define EP_4                  4
#define EP_5                  5
#define EP_6                  6
#define EP_7                  7

#define MSK_EP_DIR            0x7F

//! Parameters for endpoint configuration
//! These define are the values used to enable and configure an endpoint.
#define TYPE_CONTROL             0
#define TYPE_ISOCHRONOUS         1
#define TYPE_BULK                2
#define TYPE_INTERRUPT           3

#define DIRECTION_OUT            0
#define DIRECTION_IN             1

#define SIZE_8                   0
#define SIZE_16                  1
#define SIZE_32                  2
#define SIZE_64                  3
#define SIZE_128                 4
#define SIZE_256                 5
#define SIZE_512                 6
#define SIZE_1024                7

#define ONE_BANK                 0
#define TWO_BANKS                1

#define NYET_ENABLED             0
#define NYET_DISABLED            1

#define Usb_build_ep_config0(type, dir, nyet)  ((type<<6) | (nyet<<1) | (dir))
#define Usb_build_ep_config1(size, bank     )  ((size<<4) | (bank<<2)        )
#define usb_configure_endpoint(num, type, dir, size, bank, nyet)             \
                                    ( Usb_select_endpoint(num),              \
                                      usb_config_ep(Usb_build_ep_config0(type, dir, nyet),\
                                                    Usb_build_ep_config1(size, bank)    ))


//! General USB management 
//! These macros manage the USB controller.

#define Usb_enable()                  (USBCON |= MSK_USBE)
#define Usb_disable()                 (USBCON &= ~MSK_USBE)
#define Usb_select_device()           // compatibility
#define Usb_select_host()             // compatibility
#define Usb_freeze_clock()            (USBCON  |=  MSK_SUSPCLK)
#define Usb_unfreeze_clock()          (USBCON  &= ~MSK_SUSPCLK)
#define Usb_enable_id_interrupt()     // compatibility
#define Usb_disable_id_interrupt()    // compatibility
#define Usb_enable_vbus_interrupt()   // compatibility
#define Usb_disable_vbus_interrupt()  // compatibility
#define Is_usb_enabled()              (USBCON & MSK_USBE == MSK_USBE)
#define Is_usb_host_enabled()         (FALSE)// compatibility
#define Is_usb_clock_freezed()        (USBCON & MSK_SUSPCLK == MSK_SUSPCLK)

#define Is_usb_vbus_high()            (TRUE)// compatibility
#define Is_usb_high_speed()           (FALSE)// compatibility
#define Is_usb_id_device()            (TRUE)// compatibility

#define Usb_ack_id_transition()       // compatibility
#define Usb_ack_vbus_transition()     // compatibility
#define Is_usb_id_transition()        (FALSE) // compatibility
#define Is_usb_vbus_transition()      (FALSE) // compatibility

#define Usb_enter_dpram_mode()        // compatibility
#define Usb_exit_dpram_mode()         // compatibility
#define Usb_set_dpram_address(addr)   // compatibility

#define Usb_enable_vbus()             // compatibility
#define Usb_disable_vbus()            // compatibility
#define Usb_device_initiate_hnp()     // compatibility
#define Usb_host_accept_hnp()         // compatibility
#define Usb_host_reject_hnp()         // compatibility
#define Usb_device_initiate_srp()     // compatibility
#define Usb_select_vbus_srp_method()  // compatibility
#define Usb_select_data_srp_method()  // compatibility
#define Usb_enable_vbus_hw_control()  // compatibility
#define Usb_disable_vbus_hw_control() // compatibility
#define Is_usb_vbus_enabled()         (TRUE)  // compatibility
#define Is_usb_hnp()                  (FALSE) // compatibility
#define Is_usb_device_srp()           (FALSE) // compatibility

#define Usb_enable_suspend_time_out_interrupt()   // compatibility
#define Usb_enable_hnp_error_interrupt()          // compatibility
#define Usb_enable_role_exchange_interrupt()      // compatibility
#define Usb_enable_bconnection_error_interrupt()  // compatibility
#define Usb_enable_vbus_error_interrupt()         // compatibility
#define Usb_enable_srp_interrupt()                // compatibility
#define Usb_disable_suspend_time_out_interrupt()  // compatibility
#define Usb_disable_hnp_error_interrupt()         // compatibility
#define Usb_disable_role_exchange_interrupt()     // compatibility
#define Usb_disable_bconnection_error_interrupt() // compatibility
#define Usb_disable_vbus_error_interrupt()        // compatibility
#define Usb_disable_srp_interrupt()               // compatibility

#define Usb_ack_suspend_time_out_interrupt()      // compatibility
#define Usb_ack_hnp_error_interrupt()             // compatibility
#define Usb_ack_role_exchange_interrupt()         // compatibility
#define Usb_ack_bconnection_error_interrupt()     // compatibility
#define Usb_ack_vbus_error_interrupt()            // compatibility
#define Usb_ack_srp_interrupt()                   // compatibility
#define Is_usb_suspend_time_out_interrupt()       (FALSE) // compatibility
#define Is_usb_hnp_error_interrupt()              (FALSE) // compatibility
#define Is_usb_role_exchange_interrupt()          (FALSE) // compatibility
#define Is_usb_bconnection_error_interrupt()      (FALSE) // compatibility
#define Is_usb_vbus_error_interrupt()             (FALSE) // compatibility
#define Is_usb_srp_interrupt()                    (FALSE) // compatibility


//! USB Device management
//! These macros manage the USB Device controller.
//!

#define Usb_initiate_remote_wake_up()             (USBCON   |=  MSK_SDRMWKUP)
#define Usb_detach()                              (USBCON   |=  MSK_DETACH)
#define Usb_attach()                              (USBCON   &= ~MSK_DETACH)
#define Is_usb_pending_remote_wake_up()           (USBCON & MSK_UPRSM == MSK_UPRSM)
#define Is_usb_detached()                         (USBCON & MSK_DETACH == MSK_DETACH)

#define Usb_ack_remote_wake_up_start()            (USBCON &= ~MSK_SDRMWUP)
#define Usb_ack_resume()                          (USBINT &= ~MSK_WUPCPU)
#define Usb_ack_wake_up()                         (USBINT &= ~MSK_WUPCPU)
#define Usb_ack_reset()                           (USBINT &= ~MSK_EORINT)
#define Usb_ack_sof()                             (USBINT &= ~MSK_SOFINT)
#define Usb_ack_micro_sof()                       // compatibility
#define Usb_ack_suspend()                         (USBINT &= ~MSK_SPINT)
#define Is_usb_remote_wake_up_start()             (USBCON & MSK_SDRMWUP)
#define Is_usb_resume()                           (USBINT & MSK_WUPCPU)
#define Is_usb_wake_up()                          (USBINT & MSK_WUPCPU)
#define Is_usb_reset()                            (USBINT & MSK_EORINT)
#define Is_usb_sof()                              (USBINT & MSK_SOFINT)
#define Is_usb_micro_sof()                        (FALSE) // compatibiliy
#define Is_usb_suspend()                          (USBINT & MSK_SPINT == MSK_SPINT)

#define Usb_enable_remote_wake_up_interrupt()     // compatibility
#define Usb_enable_resume_interrupt()             (USBIEN  |=  MSK_EWUPCPU)
#define Usb_enable_wake_up_interrupt()            (USBIEN  |=  MSK_EWUPCPU)
#define Usb_enable_reset_interrupt()              (USBIEN  |=  MSK_EEORINT)
#define Usb_enable_sof_interrupt()                (USBIEN  |=  MSK_ESOFINT)
#define Usb_enable_micro_sof_interrupt()          // compatibility
#define Usb_enable_suspend_interrupt()            (USBIEN  |=  MSK_ESPINT)
#define Usb_disable_remote_wake_up_interrupt()    // compatibility
#define Usb_disable_resume_interrupt()            (USBIEN  &= ~MSK_EWUPCPU)
#define Usb_disable_wake_up_interrupt()           (USBIEN  &= ~MSK_EWUPCPU)
#define Usb_disable_reset_interrupt()             (USBIEN  &= ~MSK_EEORINT)
#define Usb_disable_sof_interrupt()               (USBIEN  &= ~MSK_ESOFINT)
#define Usb_disable_micro_sof_interrupt()         // compatibility
#define Usb_disable_suspend_interrupt()           (USBIEN  &= ~MSK_ESPINT)

#define Usb_enable_address()                      (USBADDR  |=  MSK_FEN)
#define Usb_disable_address()                     (USBADDR  &= ~MSK_FEN)
#define Usb_configure_address(addr)               (Usb_disable_address(), USBADDR  = (U8)addr)

#define Usb_frame_number()                        ((U16)((((U16)UFNUMH & 0x07) << 8) | ((U16)UDNUML)))
#define Usb_micro_frame_number()                  (0) // compatibility
#define Is_usb_frame_number_crc_error()           (UFNUMH & MSK_CRCERR == MSK_CRCERR)

#define Usb_enter_test_packet_mode()              // compatibility
#define Usb_enter_test_k_mode()                   // compatibility

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -