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

📄 usbhost.h

📁 printer usb
💻 H
字号:
/*
 *  Start of Zoran Standard Header
 *  Copyright (c) 2003 - 2004 Zoran Corporation.
 *  
 *  
 *  All rights reserved.  Proprietary and confidential.
 *  
 *  DESCRIPTION for usbhost.h
 *  	Include for usbhost.c
 *  
 *  NEW HISTORY COMMENT (description must be followed by a blank line)
 *  <Enter change description here>

 *  ===== HISTORY of changes in //depot/misc/projects/tps/usb/usbhost.h
 *  
 *  1/Apr/04 #3 lee Change type to non-executable.
 *  11/Dec/03 #2 lee Funai board doesn't need V-USB turned on.
 *  26/Nov/03 #1 lee Created.
 *  
 *  End of Zoran Standard Header
 */
#ifndef USBHOST_INCLUDED
#define USBHOST_INCLUDED

#ifndef FALSE
#define FALSE ((Boolean)0)
#endif
#ifndef TRUE
#define TRUE ((Boolean)1)
#endif
#ifdef  NULL
#undef  NULL
#endif
#define NULL ((void *)0)

#ifndef MIN
#define MIN(a,b) ((a) < (b) ? (a) : (b))      
#endif

#ifdef DEBUG
#define USB_ASSERT(_XX_) ASSERT(_XX_)
#else
#define USB_ASSERT(_XX_)
#endif

#ifndef ASSERT
#define ASSERT(_XX_) { if (!(_XX_)) while (1) ; }
#endif

/* Interrupt bit position in MECRA, EXCLRA registers, (i.e., 1 << 1) */
#define USB1_INTERRUPT_BIT 0

/* register/memory access */
#define READ_BYTE(p)    (*(Uint8 *)(p))
#define WRITE_BYTE(p)   (*(Uint8 *)(p))


#define BDT_IN_BIT         (0x0)
#define BDT_OUT_BIT        (0x8)
#define BDT_ODD_EVEN_BIT   (0x4)

#define USB_SETUP_DEV2HOST (0x80)

/* Interrupt Status Register Bit Masks */
#define INTR_STALL      (0x80)
#define INTR_ATTACH     (0x40)
#define INTR_RSVD       (0x20)
#define INTR_SLEEP      (0x10)
#define INTR_TOK_DNE    (0x08)
#define INTR_SOF_TOK    (0x04)
#define INTR_ERROR      (0x02)
#define INTR_USB_RST    (0x01)

/* Control Register Bit Masks */
#define CTRL_USB_EN            (0x01)
#define CTRL_ODD_RST           (0x02)
#define CTRL_RESUME            (0x04)
#define CTRL_HOST_NO_SOF       (0x08)
#define CTRL_HOST_SOF          (0x09)  /*  HOST ENABLE | USB ENABLE */
#define CTRL_RESET             (0x10)
#define CTRL_TOKEN_BUSY        (0x20)
#define CTRL_TXD_SUSPEND       (0x20)
#define CTRL_SINGLE_END0       (0x40)
#define CTRL_JSTATE            (0x80)


/* Low Speed bit */
#define VUSB_ADDR_LS_EN             (0x80)

#define BDT_PID_MASKS           (0x3C)
#define BDT_INVALID_PID1        (0x18)
#define BDT_NAK_PID             (0x28)
#define BDT_STALL_PID           (0x38)
#define BDT_PID_OWN             (0x80)
#define BDT_PID_DATA01          (0x40)

/* Also define some useful bit combinations */
#define ENDPT_DISABLE           (0x00)
#define ENDPT_CNTL_0            (0x0d) /* retry disable|CtRxTx|Handshake */
#define ENDPT_BULK_RX           (0x49) /* retry disable|  Rx  |Handshake */
#define ENDPT_BULK_TX           (0x45) /* retry disable|    Tx|Handshake */
#define ENDPT_INT_RX            (0x49) /* retry disable|  Rx  |Handshake */
#define ENDPT_INT_TX            (0x45) /* not currently used */
#define ENDPT_INT_BIDIR         (0x4d) /* not currently used */
#define ENDPT_HOST_RETRY_DIS    (0x40) /* not currently used */
#define ENDPT_HOST_WO_HUB       (0x80) /* not currently used */

/* BYTE USB REGISTERS - base address: 0xE0480000 */
#define regINT_STAT ((volatile Uint8 *)USB10INTSTAT)  /* 00 Interrupt status  */
#define regINT_ENB  ((volatile Uint8 *)USB10INTENB)   /* 01 Interrupt enable  */
#define regERR_STAT ((volatile Uint8 *)USB10ERRSTAT)  /* 02 Error Int status  */
#define regERR_ENB  ((volatile Uint8 *)USB10ERRENB)   /* 03 Error int enable  */
#define regSTATUS   ((volatile Uint8 *)USB10STAT)     /* 04 Status            */
#define regCTL      ((volatile Uint8 *)USB10CTL)      /* 05 Control           */
#define regADDR     ((volatile Uint8 *)USB10ADDR)     /* 06 USB address       */
#define regFRM_NUML ((volatile Uint8 *)USB10FRMNUML)  /* 08 Frame no. - low   */
#define regFRM_NUMH ((volatile Uint8 *)USB10FRMNUMH)  /* 09 Frame no. - high  */
#define regTOKEN    ((volatile Uint8 *)USB10TOKEN)    /* 0A Token             */
#define regSOF_THLD ((volatile Uint8 *)USB10SOFTHLD)  /* 0B SOF threshold     */
#define regEP0CTL   ((volatile Uint8 *)USB10EP0CTL)   /* 10 EndPoint 0 cntrl  */
#define regBUFBASEL ((volatile Uint8 *)USB10BUFBASEL) /* 20 Buff base (23:16) */
#define regBUFBASEH ((volatile Uint8 *)(USB10BUFBASEL+1)) /* 21 Buff base (31:24) */

#if CONTROLLER_BOARD == FIRE4_REFERENCE_CONTROLLER
/* BOARD CONTROL REGISTER - Firestarter base address: 0xEE001002 */
#define regBCTRL_W  ((volatile Uint8 *)0xEE001002)
#define ENABLE_USB_PWR   *regBCTRL_W = *regBCTRL_W | 0x40;

#else

/* Funai boards don't need power turned on explicitly */
#define ENABLE_USB_PWR
#endif

/* USB CHAPTER 9 */

/* SETUP offsets */
#define bmRequestType   0
#define bRequest        1
#define wValue_low      2
#define wValue_high     3
#define wIndex_low      4
#define wIndex_high     5
#define wLength_low     6
#define wLength_high    7

/* bmRequestType */
#define DEVICE_TO_HOST        0x80
#define DEVICE_TO_HOST_IFACE  0x81
#define DEVICE_TO_HOST_EP     0x82

#define HOST_TO_DEVICE           0
#define HOST_TO_DEVICE_IFACE     1
#define HOST_TO_DEVICE_EP        2

/* bRequest types                 ReqType  wValue  wIndex  wLength   Data   */
#define GET_STATUS          0   /* dv/ep      0    0/if/ep    2      2bytes */
#define CLEAR_FEATURE       1   /* 02-ep   0-HALT     0       0      none   */
#define SET_FEATURE         3   /* 02-ep   feature 0/if/ep    0      none   */
#define SET_ADDRESS         5   /* 00        addr     0       0      none   */
#define GET_DESCRIPTOR      6   /* 80      type-inx langID   len     desc   */
#define SET_DESCRIPTOR      7   /* 00      type-inx langID   len     desc   */
#define GET_CONFIGURATION   8   /* 80         0       0       0      cnfg#  */
#define SET_CONFIGURATION   9   /* 00       cnfg#     0       0      none   */
#define GET_INTERFACE      10   /* 81         0      iface    1      altset */
#define SET_INTERFACE      11   /* 01       altset   iface    0      none   */

/* Descriptor types */
#define DEVICE_TYPE         1
#define CONFIGURATION_TYPE  2
#define STRING_TYPE         3
#define INTERFACE_TYPE      4
#define ENDPOINT_TYPE       5
#define HID_TYPE           33


/* Standard Device decriptors */

/* Device Descriptor */
typedef struct {
    Uint8 bLength;
    Uint8 bDescriptorType;
    Uint8 bcdUSB_low;
    Uint8 bcdUSB_high;
    Uint8 bDeviceClass;
    Uint8 bDeviceSubclass;
    Uint8 bDeviceProtocol;
    Uint8 bMaxPacketSize0;
    Uint8 idVendor_low;
    Uint8 idVendor_high;
    Uint8 idProduct_low;
    Uint8 idProduct_high;
    Uint8 bcdDevice_low;
    Uint8 bcdDevice_high;
    Uint8 bManufacturer;
    Uint8 bProduct;
    Uint8 iSerialNumber;
    Uint8 bNumConfigurations;
} DEVICE_DESC;

/* Configuration Descriptor */
typedef struct {
    Uint8 bLength;
    Uint8 bDescriptorType;
    Uint8 wTotalLength_low;
    Uint8 wTotalLength_high;
    Uint8 bNumInterfaces;
    Uint8 bConfigurationValue;
    Uint8 iConfiguration;
    Uint8 bmAttributes;
    Uint8 bMaxPower;
} CONFIG_DESC;

/* Interface Descriptor */
typedef struct {
    Uint8 bLength;
    Uint8 bDescriptorType;
    Uint8 bInterfaceNumber;
    Uint8 bAlternateSetting;
    Uint8 bNumEndpoints;
    Uint8 bInterfaceClass;
    Uint8 bInterfaceSubClass;
    Uint8 bInterfaceProtocol;
    Uint8 iInterface;
} INTERFACE_DESC;

/* Endpoint Descriptor */
typedef struct {
    Uint8 bLength;
    Uint8 bDescriptorType;
    Uint8 bEPAddress;
    Uint8 bmAttributes;
    Uint8 wMaxPacketSize_low;
    Uint8 wMaxPacketSize_high;
    Uint8 bInterval;
} ENDPOINT_DESC;

/* String[0] offsets */
#define BLENGTH             0
#define BDESCRIPTORTYPE     1
#define WLANGID0_LOW        2
#define WLANGID0_HIGH       3

/* UNICODE String offsets */
#define BLENGTH             0
#define BDESCRIPTORTYPE     1
#define BSTRING             2

#endif /* USBHOST_INCLUDED*/

⌨️ 快捷键说明

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