📄 usb.h
字号:
/*
********************************************************
// Copyright (c)2004 Ark Pioneer Microelectronics Ltd.,
// All Rights Reserved
//
// Filename:usb.h
// Version:1.0
// Created:2004.01.12 By: Philip
********************************************************
*/
#ifndef _USB_H_
#define _USB_H_
#include "config.h"
extern WORD g_wDMACount;
extern BOOLEAN g_bDMA8Packet;
//for test
extern void ram_test(void);
extern void reg_space_test(void);
extern void test(void);
extern WORD DMATest(void);
// Macros
#define min(a,b) (((a)<(b))?(a):(b))
#define max(a,b) (((a)>(b))?(a):(b))
// 2004.09.06, philip add
// These 2 macros are for clock switch to use.
// We alawys use usb_48MHz_clock except cpu want to access to the
// usb endpoint2 buffers (IN2BUF, OUT2BUF).
// DMA use cpu clock(tclk) also.
#define USB_CLOCK() (*(PWORD)CLKSWITCH = 0) // 48Mhz clock, default
#define CPU_CLOCK() (*(PWORD)CLKSWITCH = 1) // tclk
// Convert End point ID (d0000eee) to EPIO offset
#define EPID(id) (((~id & 0x80) >> 4) + (id & 0x07))
#define EZUSB_STALL_EP0() (*(PWORD)EP0CS = bmEPSTALL)
#define WRITEDELAY() {BYTE writedelaydummy = 0;}
#define EZUSB_RESET_DATA_TOGGLE(ep) *(PWORD)TOGCTL = (((ep & 0x80) >> 3) + (ep & 0x07));\
WRITEDELAY();\
*(PWORD)TOGCTL |= 0x20
#define DR_BULK_RESET 0x21
#define DR_BULK_GETMAXLUN 0xA1
/*-----------------------------------------------------------------------------
Data which was in datarom before
-----------------------------------------------------------------------------*/
/*
#define DeviceDscrInDataRom 0x400
#define ConfigDscrInDataRom 0x412
#define StringDscr0InDataRom 0x432
#define SCSIInquiryDataInDataRom 0x46C
#define FormatCapacityInDataRom 0x490
#define SenseOkInDataRom 0x49C
#define SenseInvalidCDBInDataRom 0x4AE
#define SensesenseNoMediaInDataRom 0x4C0
#define SenseMediaChangedInDataRom 0x4D2
#define SenseWriteProtectInDataRom 0x4E4
#define SCSIInquiryData (PBYTE)SCSIInquiryDataInDataRom
#define SCSIInquiryDataSize 36
#define formatCapacity (PBYTE)FormatCapacityInDataRom
#define FormatCapacitySize 12
#define senseOk SenseOkInDataRom
#define SenseDataSize 18
#define senseInvalidFieldInCDB SenseInvalidCDBInDataRom
#define senseNoMedia SensesenseNoMediaInDataRom
#define senseMediaChanged SenseMediaChangedInDataRom
#define senseWriteProtectMedia SenseWriteProtectInDataRom
*/
#define SenseDataSize 18
#define FormatCapacitySize 12
#define SCSIInquiryDataSize 36
/*-----------------------------------------------------------------------------
Data Types
-----------------------------------------------------------------------------*/
#define INT0_VECT 0
#define TMR0_VECT 1
#define INT1_VECT 2
#define TMR1_VECT 3
#define COM0_VECT 4
#define TMR2_VECT 5
#define WKUP_VECT 6
#define COM1_VECT 7
#define USB_VECT 8
#define I2C_VECT 9
#define INT4_VECT 10
#define INT5_VECT 11
#define INT6_VECT 12
#define SUDAV_USBVECT (0 << 2)
#define SOF_USBVECT (1 << 2)
#define SUTOK_USBVECT (2 << 2)
#define SUSP_USBVECT (3 << 2)
#define URES_USBVECT (4 << 2)
#define SPARE_USBVECT (5 << 2)
#define IN0BUF_USBVECT (6 << 2)
#define OUT0BUF_USBVECT (7 << 2)
#define IN1BUF_USBVECT (8 << 2)
#define OUT1BUF_USBVECT (9 << 2)
#define IN2BUF_USBVECT (10 << 2)
#define OUT2BUF_USBVECT (11 << 2)
#define IN3BUF_USBVECT (12 << 2)
#define OUT3BUF_USBVECT (13 << 2)
#define IN4BUF_USBVECT (14 << 2)
#define OUT4BUF_USBVECT (15 << 2)
#define IN5BUF_USBVECT (16 << 2)
#define OUT5BUF_USBVECT (17 << 2)
#define IN6BUF_USBVECT (18 << 2)
#define OUT6BUF_USBVECT (19 << 2)
#define IN7BUF_USBVECT (20 << 2)
#define OUT7BUF_USBVECT (21 << 2)
/* End point control offsets */
enum
{
IN0BUF_ID = 0,
IN1BUF_ID,
IN2BUF_ID,
OUT0BUF_ID,
OUT1BUF_ID,
OUT2BUF_ID
};
typedef struct
{
BYTE length;
BYTE type;
}DSCR;
typedef struct // Device Descriptor
{
BYTE length; // Descriptor length ( = sizeof(DEVICEDSCR) )
BYTE type; // Decriptor type (Device = 1)
BYTE spec_ver_minor; // Specification Version (BCD) minor
BYTE spec_ver_major; // Specification Version (BCD) major
BYTE dev_class; // Device class
BYTE sub_class; // Device sub-class
BYTE protocol; // Device sub-sub-class
BYTE max_packet; // Maximum packet size
HWORD vendor_id; // Vendor ID
HWORD product_id; // Product ID
HWORD version_id; // Product version ID
BYTE mfg_str; // Manufacturer string index
BYTE prod_str; // Product string index
BYTE serialnum_str; // Serial number string index
BYTE configs; // Numder of configurations
}DEVICEDSCR;
typedef struct
{
BYTE length; // Configuration length ( = sizeof(CONFIGDSCR) )
BYTE type; // Descriptor type (Configuration = 2)
HWORD config_len; // Configuration + End Points length
BYTE interfaces; // Number of interfaces
BYTE index; // Configuration number
BYTE config_str; // Configuration string
BYTE attrib; // Attributes (b7 - buspwr, b6 - selfpwr, b5 - rwu
BYTE power; // Power requirement (div 2 ma)
}CONFIGDSCR;
typedef struct
{
BYTE length; // Interface descriptor length ( - sizeof(INTRFCDSCR) )
BYTE type; // Descriptor type (Interface = 4)
BYTE index; // Zero-based index of this interface
BYTE alt_setting; // Alternate setting
BYTE ep_cnt; // Number of end points
BYTE class; // Interface class
BYTE sub_class; // Interface sub class
BYTE protocol; // Interface sub sub class
BYTE interface_str; // Interface descriptor string index
}INTRFCDSCR;
typedef struct
{
BYTE length; // End point descriptor length ( = sizeof(ENDPNTDSCR) )
BYTE type; // Descriptor type (End point = 5)
BYTE addr; // End point address
BYTE ep_type; // End point type
BYTE mp_L; // Maximum packet size
BYTE mp_H;
BYTE interval; // Interrupt polling interval
}ENDPNTDSCR;
typedef struct
{
BYTE length; // String descriptor length
BYTE type; // Descriptor type
}STRINGDSCR;
typedef struct
{
BYTE cntrl; // End point control register
BYTE bytes; // End point buffer byte count
}EPIOC;
typedef struct
{
BYTE length;
BYTE *dat;
BYTE count;
BYTE status;
}I2CPCKT;
extern void SetupCommand(void);
extern BYTE DR_VendorCmnd(void);
extern STRINGDSCR * EZUSB_GetStringDscr(BYTE StrIdx);
/*-----------------------------------------------------------------------------
Setup Command
-----------------------------------------------------------------------------*/
#define SC_GET_STATUS 0x00 // Setup command: Get Status
#define SC_CLEAR_FEATURE 0x01 // Setup command: Clear Feature
#define SC_RESERVED 0x02 // Setup command: Reserved
#define SC_SET_FEATURE 0x03 // Setup command: Set Feature
#define SC_SET_ADDRESS 0x05 // Setup command: Set Address
#define SC_GET_DESCRIPTOR 0x06 // Setup command: Get Descriptor
#define SC_SET_DESCRIPTOR 0x07 // Setup command: Set Descriptor
#define SC_GET_CONFIGURATION 0x08 // Setup command: Get Configuration
#define SC_SET_CONFIGURATION 0x09 // Setup command: Set Configuration
#define SC_GET_INTERFACE 0x0a // Setup command: Get Interface
#define SC_SET_INTERFACE 0x0b // Setup command: Set Interface
#define SC_SYNC_FRAME 0x0c // Setup command: Sync Frame
#define SC_ANCHOR_LOAD 0xa0 // Setup command: Anchor load
#define GD_DEVICE 0x01 // Get device descriptor: Device
#define GD_CONFIGURATION 0x02 // Get device descriptor: Configuration
#define GD_STRING 0x03 // Get device descriptor: String
#define GD_HID 0x21 // Get descriptor: HID
#define GD_REPORT 0x22 // Get descriptor: Report
#define GS_DEVICE 0x80 // Get Status: Device
#define GS_INTERFACE 0x81 // Get Status: Interface
#define GS_ENDPOINT 0x82 // Get Status: End Point
#define FT_DEVICE 0x00 // Feature: Device
#define FT_ENDPOINT 0x02 // Feature: End Point
#define I2C_IDLE 0 // I2C Status: Idle mode
#define I2C_SENDING 1 // I2C Status: I2C is sending data
#define I2C_RECEIVING 2 // I2C Status: I2C is receiving data
#define I2C_PRIME 3 // I2C Status: I2C is receiving the first byte of a string
#define I2C_STOP 5 // I2C Status: I2C waiting for stop completion
#define I2C_BERROR 6 // I2C Status: I2C error; Bit Error
#define I2C_NACK 7 // I2C Status: I2C error; No Acknowledge
#define I2C_OK 8 // I2C positive return code
#define I2C_WAITSTOP 9 // I2C Status: Wait for STOP complete
#define DEVICE_DSCR 0x01 // Descriptor type: Device
#define CONFIG_DSCR 0x02 // Descriptor type: Configuration
#define STRING_DSCR 0x03 // Descriptor type: String
#define INTRFC_DSCR 0x04 // Descriptor type: Interface
#define ENDPNT_DSCR 0x05 // Descriptor type: End Point
#define bmBUSPWR bmBIT7 // Config. attribute: Bus powered
#define bmSELFPWR bmBIT6 // Config. attribute: Self powered
#define bmRWU bmBIT5 // Config. attribute: Remote Wakeup
#define bmEPOUT bmBIT7
#define bmEPIN 0x00
#define EP_CONTROL 0x00 // End Point type: Control
#define EP_ISO 0x01 // End Point type: Isochronous
#define EP_BULK 0x02 // End Point type: Bulk
#define EP_INT 0x03 // End Point type: Interrupt
#define SUD_SIZE 8 // Setup data packet size
/*-----------------------------------------------------------------------------
Bit Masks
-----------------------------------------------------------------------------*/
/* USB Control & Status Register */
#define bmRWAKEUP bmBIT7
#define bmDISCON bmBIT3
#define bmDISCOE bmBIT2
#define bmRENUM bmBIT1
#define bmSIGRESUME bmBIT0
/* End Point 0 Control & Status Register */
#define bmOUT bmBIT3
#define bmIN bmBIT2
#define bmHS bmBIT1
#define bmHSSTALL bmBIT0
/* End Point Control & Status Registers */
#define bmEPSTALL bmBIT0
#define bmEPBUSY bmBIT1
/* IN/OUT irq registers */
#define bmIN0IRQ bmBIT0
#define bmOUT0IRQ bmBIT0
#define bmIN1IRQ bmBIT1
#define bmOUT1IRQ bmBIT1
#define bmIN2IRQ bmBIT2
#define bmOUT2IRQ bmBIT2
#define bmEP2 bmBIT2
#define bmEP1 bmBIT1
#define bmEP0 bmBIT0
/* Global Interrupt Request & Enable Registers */
#define bmUSBIEN_TOTAL bmBIT7
#define bmIBN bmBIT5
#define bmURES bmBIT4
#define bmSUSP bmBIT3
#define bmSUTOK bmBIT2
#define bmSOF bmBIT1
#define bmSUDAV bmBIT0
#define INT2SFC bmBIT4
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -