📄 usb_to_serial.asm
字号:
;****************************************************************
; FILE: USB_TO_SERIAL.ASM
;****************************************************************
XPAGEON
;****************************************************************
; BUILD OPTIONS
;****************************************************************
; Uncomment one of the two following statements to
; select the target processor platform.
INCLUDE "7C64013.INC"
;INCLUDE "7C63743.INC"
INCLUDE "MACROS.INC"
SIZEOF_INPUT_REPORT: equ SIZEOF_EP1_FIFO ;
SIZEOF_OUTPUT_REPORT: equ SIZEOF_EP2_FIFO ;
SIZEOF_RX_BUFFER: equ 20h ;
DEFINE HW_FLOW_CONTROL
;****************************************************************
; CONSTANTS
;****************************************************************
;****************************************************************
; RAM ALLOCATION
;****************************************************************
; NOTE: Variables need to be grouped into a cohesive block and
; this constant needs to be set to the size of the variable
; block. This block of data is cleared when a Reset Serial
; operation occurs.
SIZEOF_VARIABLE_BLOCK: equ 10h ;
;PSP_BEGIN: equ 00h
;PSP_END: equ 0Fh
VARS_BEGIN: equ 10h
;DSP_END: equ A5h
DSP_BEGIN: equ (TOP_OF_RAM + 1)
;****************************************************************
; GLOBAL CONSTANTS
;****************************************************************
FALSE: equ 00h ;
TRUE: equ ~FALSE ;
;****************************************************************
; VARIABLES
;****************************************************************
;----------------------------------------------------------------
; USB_TO_SERIAL VARIABLES
;----------------------------------------------------------------
RX_TX_VARS: equ VARS_BEGIN ;
control_report: equ (RX_TX_VARS + 0) ; this hold the 5 bytes of config data
setup_serial: equ (RX_TX_VARS + 5) ; flag that indicates if a feature report has come in
load_ep1: equ (RX_TX_VARS + 6) ;
tx_pending: equ (RX_TX_VARS + 7) ; flag to indicate a TX transfer is pending
serial_configured: equ (RX_TX_VARS + 8) ; set when we get configured
bit_rate: equ (RX_TX_VARS + 9) ; set by host, this is the rate of transfers
data_bit_count: equ (RX_TX_VARS + 10) ;
parity_on: equ (RX_TX_VARS + 11) ;
parity_type: equ (RX_TX_VARS + 12) ; set by host, this is the parity type we are using
stop_bit_count: equ (RX_TX_VARS + 13) ;
parity: equ (RX_TX_VARS + 14) ; the parity being generated or checked
loop_counter: equ (RX_TX_VARS + 15) ; used for bit rate control
p1_shadow: equ (RX_TX_VARS + 16) ;
temp: equ (RX_TX_VARS + 17) ;
temp2: equ (RX_TX_VARS + 18) ;
RX_TX_VARS_END: equ temp2 ;
;----------------------------------------------------------------
; Variables for RX
;----------------------------------------------------------------
RX_VARS: equ (RX_TX_VARS_END + 1) ;
rts_shadow: equ (RX_VARS + 0) ;
error_location: equ (RX_VARS + 1) ;
rx_buffer_in: equ (RX_VARS + 2) ;
rx_buffer_out: equ (RX_VARS + 3) ;
rx_buffer: equ (RX_VARS + 4) ;
RX_VARS_END: equ (rx_buffer + SIZEOF_RX_BUFFER) ;
;----------------------------------------------------------------
; Variables for TX
;----------------------------------------------------------------
TX_VARS: equ (RX_VARS_END + 1) ;
tx_byte_count: equ (TX_VARS + 0) ; number of bytes in the OUT packet
tx_byte_counter: equ (TX_VARS + 1) ; # of bytes that have been transmitted
tx_data: equ (TX_VARS + 2) ; current data being transmitted
TX_VARS_END: equ tx_data
;----------------------------------------------------------------
; Variables for EP0 and enumeration
;----------------------------------------------------------------
EP0_VARS: equ (TX_VARS_END + 1) ; EP0 variables will be based here
ep0_mode_shadow: equ (EP0_VARS + 0) ; the ep0 mode register shadow
ep0_next_mode: equ (EP0_VARS + 1) ; holds the mode that ep0 will go to next
ep0_data_toggle: equ (EP0_VARS + 2) ; keeps track of the toggle bit
configuration: equ (EP0_VARS + 3) ; holds the current status of configuration
device_status: equ (EP0_VARS + 4) ; holds the current status of remote_wakeup (2 bytes)
zero_register: equ (EP0_VARS + 6) ; two bytes of 0
ep1_status: equ (EP0_VARS + 8) ; holds the current status of ep1_stall (2 bytes)
ep2_status: equ (EP0_VARS + 10) ; holds the current status of ep2_stall (2 bytes)
protocol: equ (EP0_VARS + 12) ; holds the current status of protocol
ram_or_rom: equ (EP0_VARS + 13) ; flag to pick whether we should get data from ram or rom
data_count: equ (EP0_VARS + 14) ; the total number of bytes being sent
data_start: equ (EP0_VARS + 15) ; location of data to be sent
load_loop_counter: equ (EP0_VARS + 16) ; counts the load loops
control_read_counter: equ (EP0_VARS + 17) ; for get descriptor command
suspend_count: equ (EP0_VARS + 18) ;
idle: equ (EP0_VARS + 19) ;
EP0_VARS_END: equ idle ;
;----------------------------------------------------------------
; Aliased Variables
;----------------------------------------------------------------
byte_counter: equ temp2 ;
; Definitions for SETUP packets
request_type: equ (ep0_fifo + 0) ;
request: equ (ep0_fifo + 1) ;
value: equ (ep0_fifo + 2) ;
value_hi: equ (ep0_fifo + 3) ;
index: equ (ep0_fifo + 4) ;
index_hi: equ (ep0_fifo + 5) ;
length: equ (ep0_fifo + 6) ;
length_hi: equ (ep0_fifo + 7) ;
;****************************************************************
; CONTROL REPORT
;****************************************************************
; The control report is a five-byte report that includes
; configuration settings. These settings include baud rate, reset,
; even/odd parity, parity enable, number of stop bits and data
; length.
;****************************************************************
SIZEOF_CONTROL_REPORT: equ 5 ;
; Definitions for Control Report
baud_rate_byte_0: equ (control_report + 0) ;
baud_rate_byte_1: equ (control_report + 1) ;
baud_rate_byte_2: equ (control_report + 2) ;
baud_rate_byte_3: equ (control_report + 3) ;
config: equ (control_report + 4) ;
;----------------------------------------------------------------
; config FIELDS
;----------------------------------------------------------------
RESET: equ 80h ; 1: Reset
PARITY_TYPE: equ 20h ; 1: Even, 0: Odd
PARITY_ON: equ 10h ; 1: Enable parity, 0: Disable parity
STOP_BITS: equ 08h ; 1: Two stop bits, 0: One stop bit
BIT_COUNT: equ 03h ; Data length - 5
;****************************************************************
; OUTPUT REPORT
;****************************************************************
; Definitions for Output Report
output_report: equ ep2_fifo ;
output_control: equ (output_report + 0) ;
IF ((SIZEOF_OUTPUT_REPORT - 1) & ~7)
OUTPUT_COUNT: equ 1Fh ;
output_count: equ (output_report + 1) ;
output_data: equ (output_report + 2) ;
ELSE
OUTPUT_COUNT: equ 07h ;
output_count: equ (output_report + 0) ;
output_data: equ (output_report + 1) ;
ENDIF
SIZEOF_OUTPUT_HEADER: equ (output_data - output_report) ;
;----------------------------------------------------------------
; OUTPUT REPORT BYTE 0 FIELDS
;----------------------------------------------------------------
OUTPUT_DTR: equ 20h ;
OUTPUT_RTS: equ 10h ;
OUTPUT_RESET: equ 08h ;
;****************************************************************
; INPUT REPORT
;****************************************************************
; Definitions for Input Report
input_report: equ ep1_fifo ;
input_status: equ (input_report + 0) ;
IF ((SIZEOF_INPUT_REPORT - 1) & ~7)
INPUT_COUNT: equ 1Fh ;
input_count: equ (input_report + 1) ;
input_data: equ (input_report + 2) ;
ELSE
INPUT_COUNT: equ 07h ;
input_count: equ (input_report + 0) ;
input_data: equ (input_report + 1) ;
ENDIF
SIZEOF_INPUT_HEADER: equ (input_data - input_report) ;
;----------------------------------------------------------------
; INPUT REPORT BYTE 0 FIELDS
;----------------------------------------------------------------
INPUT_RI: equ 80h ;
INPUT_CD: equ 40h ;
INPUT_DSR: equ 20h ;
INPUT_CTS: equ 10h ;
INPUT_ERROR: equ 08h ;
;****************************************************************
; INPUT AND OUTPUT PORT DEFINITIONS
;****************************************************************
; The use of "input" and "output" here refers to electrical
; signals that are input to and output from the processor. There
; is no relationship between the reference of input/output here
; and the reference to input/output reports to/from the host.
;****************************************************************
;----------------------------------------------------------------
; PORT 0 PIN ALLOCATION
;----------------------------------------------------------------
INPUT_PORT: equ P0_DATA ;
RXD: equ 80h ;
RI: equ 10h ;
CD: equ 08h ;
DSR: equ 04h ;
CTS: equ 02h ;
;----------------------------------------------------------------
; PORT 1 PIN ALLOCATION
;----------------------------------------------------------------
OUTPUT_PORT: equ P1_DATA ;
output_port_shadow: equ p1_shadow ;
DTR: equ 04h ;
RTS: equ 02h ;
TXD: equ 01h ;
OUTPUT_PORT_MASK: equ (DTR | RTS | TXD) ;
;****************************************************************
; MISCELLANEOUS CONSTANTS
;****************************************************************
ERROR_FLAG: equ 80h ;
RAM: equ 00h ;
ROM: equ 01h ;
EVEN_PARITY: equ FALSE ;
ODD_PARITY: equ TRUE ;
RTS_LAG: equ 06h ;
BAUD_115200: equ C2h ;
BAUD_57600: equ E1h ;
BAUD_38400: equ 96h ;
BAUD_19200: equ 4Bh ;
BAUD_9600: equ 25h ;
BAUD_4800: equ 12h ;
BAUD_2400: equ 09h ;
BAUD_1200: equ 04h ;
BAUD_600: equ 02h ;
;****************************************************************
; USB CONSTANTS
;****************************************************************
; Standard Requests
GET_STATUS: equ 0 ;
CLEAR_FEATURE: equ 1 ;
SET_FEATURE: equ 3 ;
SET_ADDRESS: equ 5 ;
GET_DESCRIPTOR: equ 6 ;
SET_DESCRIPTOR: equ 7 ;
GET_CONFIGURATION: equ 8 ;
SET_CONFIGURATION: equ 9 ;
GET_INTERFACE: equ 10 ;
SET_INTERFACE: equ 11 ;
SYNCH_FRAME: equ 12 ;
; Standard Descriptor Types
DEVICE: equ 1 ;
CONFIGURATION: equ 2 ;
STRING: equ 3 ;
INTERFACE: equ 4 ;
ENDPOINT: equ 5 ;
; Standard Feature Selectors
ENDPOINT_STALL: equ 0 ; Endpoint recipient
DEVICE_REMOTE_WAKEUP: equ 1 ; Device recipient
;****************************************************************
; HID CONSTANTS
;****************************************************************
; from HID Class v1.0 Draft #4
;****************************************************************
; Class specific descriptor types from section
; 7.1 Standard Requests
HID: equ 21h ;
REPORT: equ 22h ;
PHYSICAL: equ 23h ;
; Class specific request codes from section 7.2
; Class Specific Requests
GET_REPORT: equ 1 ;
GET_IDLE: equ 2 ;
GET_PROTOCOL: equ 3 ;
SET_REPORT: equ 9 ;
SET_IDLE: equ 10 ;
SET_PROTOCOL: equ 11 ;
CONFIGURED: equ 1 ; configuration status values
UNCONFIGURED: equ 0 ;
BOOT_PROTOCOL: equ 0 ; protocol status values
REPORT_PROTOCOL: equ 1
DISABLE_REMOTE_WAKEUP: equ 0 ; bit[1] = 0
ENABLE_REMOTE_WAKEUP: equ 2 ; bit[1] = 1
;****************************************************************
; CODE STARTS HERE
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -