📄 ezusb.h
字号:
/*************************************************************************** ezusb.h - description ------------------- begin : Sat Sep 2 2000 copyright : (C) 2000 by William Rachelson email : gurufool@cc.gatech.edu ezusb.h is intended for use with SDCC and Anchorchips' EZ-USB. It is based on Anchor's ezusb.h file that was intended for the Keil compiler, and also on the standard 8051.h templates for SDCC. ***************************************************************************//*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************//*! \file * * This is the EzUSB microcontroller integrated peripherical * definition from the SDCC distribution * * \author Julien Pilet <julien.pilet@epfl.ch> * \author Stephane Magnenat <stephane.magnenat@epfl.ch> */#ifndef EZUSB_H#define EZUSB_H//-----------------------------------------------------------------------------// Constants//-----------------------------------------------------------------------------#define TRUE 1#define FALSE 0#define bmBIT0 0x01#define bmBIT1 0x02#define bmBIT2 0x04#define bmBIT3 0x08#define bmBIT4 0x10#define bmBIT5 0x20#define bmBIT6 0x40#define bmBIT7 0x80#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#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 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/*----------------------------------------------------------------------------- Macros-----------------------------------------------------------------------------*/#define MSB(word) (BYTE)(((WORD)word >> 8) & 0xff)#define LSB(word) (BYTE)((WORD)word & 0xff)#define SWAP_ENDIAN(word) ((BYTE*)&word)[0] ^= ((BYTE*)&word)[1];\ ((BYTE*)&word)[1] ^= ((BYTE*)&word)[0];\ ((BYTE*)&word)[0] ^= ((BYTE*)&word)[1]#define EZUSB_IRQ_ENABLE() EUSB = 1#define EZUSB_IRQ_DISABLE() EUSB = 0#ifndef CHIPREV_B#define EZUSB_IRQ_CLEAR() EXIF &= ~0x10 // IE2_#endif#define EZUSB_STALL_EP0() EP0CS |= bmEPSTALL#define EZUSB_STALL_EP(ep_id) EPIO[ep_id].cntrl = bmEPSTALL#define EZUSB_UNSTALL_EP(ep_id) EPIO[ep_id].cntrl = 0#define EZUSB_GET_EP_STATUS(ep_id) EPIO[ep_id].cntrl#define EZUSB_SET_EP_BYTES(ep_id,count) EPIO[ep_id].bytes = count#define EZUSB_RESET_DATA_TOGGLE(ep) TOGCTL = (((ep & 0x80) >> 3) + (ep & 0x07));\ TOGCTL |= 0x20#define EZUSB_ENABLE_RSMIRQ() (EICON |= 0x20) // Enable Resume Interrupt (EPFI_)#define EZUSB_DISABLE_RSMIRQ() (EICON &= ~0x20) // Disable Resume Interrupt (EPFI_)#define EZUSB_CLEAR_RSMIRQ() (EICON &= ~0x10) // Clear Resume Interrupt Flag (PFI_)#define EZUSB_GETI2CSTATUS() (I2CPckt.status)#define EZUSB_CLEARI2CSTATUS() if((I2CPckt.status == I2C_BERROR) || (I2CPckt.status == I2C_NACK))\ I2CPckt.status = I2C_IDLE;#define EZUSB_ENABLEBP() (USBBAV |= bmBPEN)#define EZUSB_DISABLEBP() (USBBAV &= ~bmBPEN)#define EZUSB_CLEARBP() (USBBAV |= bmBREAK)#define EZUSB_BP(addr) BPADDR = (WORD)addr#define EZUSB_EXTWAKEUP() (USBCS & bmRWAKEUP)/* Convert End point ID (d0000eee) to EPIO offset */#define EPID(id) (((~id & 0x80) >> 4) + (id & 0x07))//-----------------------------------------------------------------------------// Datatypes//-----------------------------------------------------------------------------typedef unsigned char BYTE;typedef unsigned short WORD;typedef unsigned long DWORD;typedef bit BOOL;#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)//! EzUSB Generic Descriptortypedef struct{ BYTE length; BYTE type;}DSCR;//! EzUSB Device Descriptortypedef 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 WORD vendor_id; // Vendor ID WORD product_id; // Product ID WORD 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;//! EzUSB Configuration Descriptortypedef struct{ BYTE length; // Configuration length ( = sizeof(CONFIGDSCR) ) BYTE type; // Descriptor type (Configuration = 2) WORD 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;//! EzUSB Interface Descriptortypedef 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;//! EzUSB Endpoint Descriptortypedef 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;//! EzUSB String Descriptortypedef struct{ BYTE length; // String descriptor length BYTE type; // Descriptor type}STRINGDSCR;//! EzUSB Endpoint Descriptortypedef struct{ BYTE cntrl; // End point control register BYTE bytes; // End point buffer byte count}EPIOC;//! EzUSB I2C Descriptortypedef struct{ BYTE length; BYTE *dat; BYTE count; BYTE status;}I2CPCKT;/*----------------------------------------------------------------------------- Global Variables The Ez-USB registers are defined here.-----------------------------------------------------------------------------*/xdata volatile BYTE at 0x7B40 OUT7BUF[64] ;xdata volatile BYTE at 0x7B80 IN7BUF[64] ;xdata volatile BYTE at 0x7BC0 OUT6BUF[64] ;xdata volatile BYTE at 0x7C00 IN6BUF[64] ;xdata volatile BYTE at 0x7C40 OUT5BUF[64] ;xdata volatile BYTE at 0x7C80 IN5BUF[64] ;xdata volatile BYTE at 0x7CC0 OUT4BUF[64] ;xdata volatile BYTE at 0x7D00 IN4BUF[64] ;xdata volatile BYTE at 0x7D40 OUT3BUF[64] ;xdata volatile BYTE at 0x7D80 IN3BUF[64] ;xdata volatile BYTE at 0x7DC0 OUT2BUF[64] ;xdata volatile BYTE at 0x7E00 IN2BUF[64] ;xdata volatile BYTE at 0x7E40 OUT1BUF[64] ;xdata volatile BYTE at 0x7E80 IN1BUF[64] ;xdata volatile BYTE at 0x7EC0 OUT0BUF[64] ;xdata volatile BYTE at 0x7F00 IN0BUF[64] ;xdata volatile BYTE at 0x7F60 OUT8DATA ;xdata volatile BYTE at 0x7F61 OUT9DATA ;xdata volatile BYTE at 0x7F62 OUT10DATA ;xdata volatile BYTE at 0x7F63 OUT11DATA ;xdata volatile BYTE at 0x7F64 OUT12DATA ;xdata volatile BYTE at 0x7F65 OUT13DATA ;xdata volatile BYTE at 0x7F66 OUT14DATA ;xdata volatile BYTE at 0x7F67 OUT15DATA ;xdata volatile BYTE at 0x7F68 IN8DATA ;xdata volatile BYTE at 0x7F69 IN9DATA ;xdata volatile BYTE at 0x7F6A IN10DATA ;xdata volatile BYTE at 0x7F6B IN11DATA ;xdata volatile BYTE at 0x7F6C IN12DATA ;xdata volatile BYTE at 0x7F6D IN13DATA ;xdata volatile BYTE at 0x7F6E IN14DATA ;xdata volatile BYTE at 0x7F6F IN15DATA ;xdata volatile BYTE at 0x7F70 OUT8BCH ;xdata volatile BYTE at 0x7F71 OUT8BCL ;xdata volatile BYTE at 0x7F72 OUT9BCH ;xdata volatile BYTE at 0x7F73 OUT9BCL ;xdata volatile BYTE at 0x7F74 OUT10BCH ;xdata volatile BYTE at 0x7F75 OUT10BCL ;xdata volatile BYTE at 0x7F76 OUT11BCH ;xdata volatile BYTE at 0x7F77 OUT11BCL ;xdata volatile BYTE at 0x7F78 OUT12BCH ;xdata volatile BYTE at 0x7F79 OUT12BCL ;xdata volatile BYTE at 0x7F7A OUT13BCH ;xdata volatile BYTE at 0x7F7B OUT13BCL ;xdata volatile BYTE at 0x7F7C OUT14BCH ;xdata volatile BYTE at 0x7F7D OUT14BCL ;xdata volatile BYTE at 0x7F7E OUT15BCH ;xdata volatile BYTE at 0x7F7F OUT15BCL ;xdata volatile BYTE at 0x7F90 SPARE1 ;xdata volatile BYTE at 0x7F91 SPARE2 ;xdata volatile BYTE at 0x7F92 CPUCS ;xdata volatile BYTE at 0x7F93 PORTACFG ;xdata volatile BYTE at 0x7F94 PORTBCFG ;xdata volatile BYTE at 0x7F95 PORTCCFG ;xdata volatile BYTE at 0x7F96 OUTA ;xdata volatile BYTE at 0x7F97 OUTB ;xdata volatile BYTE at 0x7F98 OUTC ;xdata volatile BYTE at 0x7F99 PINSA ;xdata volatile BYTE at 0x7F9A PINSB ;xdata volatile BYTE at 0x7F9B PINSC ;xdata volatile BYTE at 0x7F9C OEA ;xdata volatile BYTE at 0x7F9D OEB ;xdata volatile BYTE at 0x7F9E OEC ;xdata volatile BYTE at 0x7F9F SPARE3 ;xdata volatile BYTE at 0x7FA0 ISOERR ;xdata volatile BYTE at 0x7FA1 ISOCTL ;xdata volatile BYTE at 0x7FA2 ZBCOUT ;xdata volatile BYTE at 0x7FA3 ZBCIN ;xdata volatile BYTE at 0x7FA4 SPARE4 ;xdata volatile BYTE at 0x7FA5 I2CS ;xdata volatile BYTE at 0x7FA6 I2DAT ;xdata volatile BYTE at 0x7FA7 SPARE5 ;xdata volatile BYTE at 0x7FA8 IVEC ;xdata volatile BYTE at 0x7FA9 IN07IRQ ;xdata volatile BYTE at 0x7FAA OUT07IRQ ;xdata volatile BYTE at 0x7FAB USBIRQ ;xdata volatile BYTE at 0x7FAC IN07IEN ;xdata volatile BYTE at 0x7FAD OUT07IEN ;xdata volatile BYTE at 0x7FAE USBIEN ;xdata volatile BYTE at 0x7FAF USBBAV ;xdata volatile WORD at 0x7FB0 AVADDR ;xdata volatile WORD at 0x7FB2 BPADDR ;xdata volatile BYTE at 0x7FB3 BPADDRL ;xdata volatile EPIOC at 0x7FB4 EPIO[16] ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -