📄 usbasm.txt
字号:
mov X, 00h
; mov X, 1fh
; mov A, 00h
send_EP1_buffer: ; send data from EP1
mov A, [X + send_data0] ; fill EP1 buffers
mov [X + EP1_buffer0], A
;---------- mod at July,26,2001---------------
mov A, X
inc A
; dec A
mov X, A
cmp A, 20h
jnz send_EP1_buffer
;---------- mod end at July,26,2001---------------
mov A, in_ack ; set ACK-IN mode
iowr EP1_mode
mov A, 20h ; data length
or A, [EP1_data_toggle]
iowr EP1_counter
wait_data_sent:
iord USB_address ; if address = 0 a bus reset has occured
cmp A, 80h ; jump to wait loop
jz ep1_sent_over
; wait for data to be sent
iord EP1_mode ; before loading registers
and A, 10h ; again
jnz wait_data_sent
mov A, in_nak ; set NAK-IN mode
iowr EP1_mode
ep1_sent_over:
pop X
pop A
ret
;*******************************************************
; Interrupt handler: endpoint_two ( mod at July,26,2001)
; Purpose: This interrupt routine handles the specially
; reserved data endpoint 2.
; This interrupt happens every time a host sends an
; OUT on endpoint 2. this routine receive the data
; from the FIFO dma buffers
;*******************************************************
endpoint_two:
push A
push X
iord EP2_mode
and A, 10h ; check ACK bit[4]
jz ep2_receive_over
iord EP2_counter
and A, 40h ; check data_valid bit[6],[0100,0000]
jz ep2_receive_over
;------ mod at July,26,2001 -------------
iord EP2_counter
and A, 3fh ; check data_length bit[0:5], [0011,1111]
dec A ; -2
dec A
mov [rcvdata_length], A
jz ep2_packet_empty
; iord EP2_counter ; check EP2_data_toggle
; and A, [EP2_data_toggle]
; cmp A, [EP2_data_toggle]
; jnz ep2_receive_over
; mov A, [EP2_data_toggle] ; change endpoint2
; xor A, 80h ; data toggle
; and A, 80h
; mov [EP2_data_toggle], A
mov X, 00h ; receive 32 bytes
receive_loop:
mov A, [X+ EP2_buffer0] ; get data from buffers
mov [X + recvpc_data0], A
mov A, X
inc A
mov X, A
cmp A, [rcvdata_length] ;20h
jnz receive_loop
mov A, 01h ; set flag
mov [recvpc_data_ok], A
;--------- mod at Aug,09 2001 ----------------------
mov A, out_nak ; will be set ep2 ACK-OUT mode in HAPI_int
iowr EP2_mode
iord EP_int ; disable EP2 interrupt x[1111,1011]
and A, 0f9h
iowr EP_int
jmp ep2_receive_over
ep2_packet_empty:
mov A, out_ack
iowr EP2_mode
;--------- mod end at Aug,09 2001 ----------------------
ep2_receive_over:
pop X
pop A
reti
;*******************************************************
; Function: Trans_data
; Purpose: Data format conversion tools
;*******************************************************
;trans_data:
; ret
;*******************************************************
; Function: Trans_printer_data
; Purpose: Change printer data format
;*******************************************************
;trans_printer_data:
; mov A, 21h
; mov X, 00h
;trans_again:
; mov [X + recvpc_data0], A
; inc X
; inc A
; mov [temp_1], A
; mov A, X
; cmp A, 20h
; jz trans_data_done
; mov A, [temp_1]
; jmp trans_again
;trans_data_done:
; ret
;*******************************************************
; Function: Print_data
; Purpose: Send data to printer
; data was sent by HC12, and was loaded
; at Port0.
;*******************************************************
;print_data:
; push A
; mov X, 00h
; mov A, 00h
; mov [recvpc_data_ok], A
; call init_printer
;print_next:
; mov A, [X + recvpc_data0]
; iord Port0
; mov [temp_print_data], A
; call check_printer
; call send_to_printer
; mov A, X
; cmp A, 1fh ; total 32 bytes
; jz print_data_end
; inc X
; jmp print_next
;print_data_end:
; mov A, 0ch
; mov [temp_print_data], A
; call send_to_printer
; pop A
; ret
;*******************************************************
; The Following Subroutine is for Printer
;*******************************************************
; Function: Delay
; Purpose: Delay sometime
; Use for send STB signal to printer only
;*******************************************************
delay:
push A
mov A, [delay_time]
delay1:
dec A
jz done
iowr WDT
jmp delay1
done: pop A
ret
;*******************************************************
; Function: send_to_printer
; Purpose: Send data to printer data port
; data should be loaded at [temp_printer_data]
; before calling this subroutine.
;*******************************************************
send_to_printer:
mov A, [temp_print_data] ; Print data from [temp_print_data]
iowr Port3
mov A, 04h
mov [delay_time], A
call delay
iord Port2 ; clear STROBE
and A, 7fh
iowr Port2
mov A, 04h
mov [delay_time], A
call delay
iord Port2 ; set STROBE
or A, 80h
iowr Port2
mov A, 0ffh
mov [delay_time], A
call delay
done_send_to_printer:
ret
;------------------------------------------------------
; End of Subroutines for Printer
;------------------------------------------------------
;******************************************************
; USB library main routines
;******************************************************
; Function: Control_read
; Purpose: Performs the control read operation
; as defined by the USB specification
; SETUP-IN-IN-IN...OUT
;
; data_start: must be set to the descriptors info
; as an offset from the beginning of the
; control_read_table
; data_count: must be set to the size of the
; descriptor
;******************************************************
control_read:
mov X, 00h
mov A, 00h
mov [EP0_data_toggle], A
cr_wr:
mov A, nak ; clear PID bits
iowr EP0_mode ; leave in NAK IN/OUT mode (01h)
iord EP0_mode
cmp A, nak
jnz cr_wr
send_buffer:
mov X, 00h
mov A, 00h
mov [loop_counter], A
crds_wr:
mov A, con_rd_nak ; clear PID bits
iowr EP0_mode ; leave in NAK IN STATUS OUT mode (0eh)
iord EP0_mode
cmp A, con_rd_nak
jnz crds_wr
;-------------------------------------------------------
; code added to modifiy mutiple 8 bytes packets problem
;-------------------------------------------------------
mov A, [data_count] ; check if data_count= 8
cmp A, 08h
jnz check_data_count0 ; not equ 8
mov A, 01h ; equ 8, set bit [data_count_8]
mov [data_count_8], A
jmp dma_load_loop
;---------------------------------------------------------
; added code end
;---------------------------------------------------------
check_data_count0:
mov A, [data_count] ; if data_count=0 no data need to be sent
cmp A, 00h
jz control_read_over
dma_load_loop: ; loop to load data into the data buffer
; mov A, [port_status] ; check if the caller is get_portstat
; cmp A, 01h
; jnz index
; mov A, [printer_status]
; jmp nonindex
;index:
mov A, [data_start]
index control_read_table
nonindex:
mov [X + EP0_buffer0], A ; load dma buffer
inc [data_start]
inc X
inc [loop_counter]
dec [data_count] ; exit if descriptor
jz dma_load_done ; is done
mov A, [loop_counter] ; or 8 bytes sent
cmp A, 08h
jnz dma_load_loop
dma_load_done:
iord EP0_counter ; set data_toggle
mov A, [EP0_data_toggle]
xor A, 80h
mov [EP0_data_toggle], A
or A, [loop_counter] ; set data length
iowr EP0_counter
cr_wr_ack:
mov A, con_rd_ack ; leave in ACK IN STATUS OUT mode (0fh)
iowr EP0_mode
iord EP0_mode
and A, 0Fh
cmp A, con_rd_ack
jnz cr_wr_ack
wait_control_read:
iord EP0_mode ; wait for the data to be
and A, 01h ; transfered
; jz send_buffer
jnz check_setup_out
;-------------------------------------------------------
; code added to modifiy mutiple 8 bytes packets problem
;-------------------------------------------------------
mov A, [data_count_8]
cmp A, 01h
jnz send_buffer
mov A, 00h
mov [data_count_8], A
mov [loop_counter], A
jmp dma_load_done
;---------------------------------------------------------
; added code end
;---------------------------------------------------------
check_setup_out:
iord EP0_mode
and A, 0A0h ; check if out/setup was sent by host
jnz control_read_over ; received SETUP or OUT bit [7,5]
jmp wait_control_read ; still wait
; jmp send_buffer
;--------------------------------
; old end
;--------------------------------
control_read_over: ; OUT at end of data transfer
ret
;******************************************************
; Function: control_write
; Purpose: performs the control write operaion
; as defined by the USB specification
; SETUP-OUT-OUT-OUT...IN
;******************************************************
control_write:
; not implemented for this device, but may be needed for
; other devices
ret
;******************************************************
; Function: no_data_control
; Purpose: performs the no-data control operation
; as defined by the USB specification
; SETUP-IN
;******************************************************
no_data_control:
; iord EP_int
mov A, con_wr_stall
iowr EP0_mode
iord EP0_mode
cmp A, con_wr_stall
jnz no_data_control
wait_nodata_sent:
iord EP0_mode
and A, 40h
jz wait_nodata_sent
ret
;*********************************************************
; RAM Table
;*********************************************************
XPAGEOFF
;*********************************************************
; USB Enumeration Tables
;*********************************************************
control_read_table:
device_desc_table:
db 12h ; size of descriptor (18 bytes)
db 01h ; descriptor type (device descriptor)
db 00h, 01h ; USB spec release (ver 1.0)
db 0ffh ;07h ; class code (each interface specifies class information)
db 00h ;01h ; device sub-class (must be set to 0 if class code is 0)
db 0ffh ;02h ; device protocol (no class specific protocol)
db 08h ; maximum packet size for endpoint0 (8 bytes) (only for 64113)
db b4h, 04h ; b8h, 04h ; vendor ID (Epson) (XXXXX need a new vendor ID)
db 01h, 64h ; product ID (Epson printer product ID)
db 00h, 01h ; device release number
db 01h ; index of manufacturer string (1)
db 02h ; index of product string (2)
db 00h ; index of serial number string (not supported)
db 01h ; number of configurations (1)
config_desc_table:
db 09h ; length of descriptor (9 bytes)
db 02h ; descriptor type (CONFIGURATION)
db 20h, 00h ; total length of descriptor (19h=25 bytes,20h=32 bytes)
db 01h ; number of interfaces to configure (1)
db 01h ; configuration value (1)
db 00h ; configuration string index (not supported)
db 40h ; configuration attributes (self powered...or will be in future
db 01h ; maximum power (2mA)
interface_desc_table:
db 09h ; length of descriptor (9 bytes)
db 04h ; descriptor type (INTERFACE)
db 00h ; interface number (0)
db 00h ; alternate setting (0)
db 02h ; number of endpoints (01h/02h, 1/2)
db 0ffh ;07h ; interface class (3..defined by USB spec)
db 00h ;01h ; interface sub-class (1..defined by USB spec)
db 0ffh ;02h ; interface protocol (2..defined by USB spec)
db 00h ; interface string index (not supported)
endpoint1_desc_table:
db 07h ; descriptor length (7 bytes)
db 05h ; descriptor type (ENDPOINT)
db 81h ;01h ; endpoint address (IN endpoint, endpoint1)
db 02h ; endpoint attributes (03-interrupt,02-bulk)
db 20h, 00h ; maximum packet size (32 bytes)
db 00h ; polling interval (0a-10ms)
endpoint2_desc_table:
db 07h ; descriptor length (7 bytes)
db 05h ; descriptor type (ENDPOINT)
db 02h ;82h ; endpoint address ( OUT endpoint, endpoint2)
db 02h ; endpoint attributes (03-interrupt,02-bulk)
db 20h, 00h ; maximum packet size (32 bytes)
db 00h ; polling interval (0a-10ms)
get_dev_status_table:
db 00h, 00h ; bus powered, no remote wakeup
get_config_table:
db 00h ; configuration 0
db 01h ; configuration 1
get_interface_table:
db 00h ; interface 0
get_endp_status_table:
db 00h, 00h ; endpoint not stalled
get_endp_stalled_status_table:
db 01h, 00h ; endpoint stalled
string_desc_table:
USB_string_language_desc_table: ; string 0
db 04h ; descriptor length (4 bytes)
db 03h ; descriptor type (string)
db 09h ; language: English
db 04h ; sub-language: US
USB_string_desc_1: ; string 1
db 0ch ; descriptor length (12 bytes)
db 03h ; descriptor type (string)
dsu "XXXXX" ; dsu "XXXXX"
USB_string_desc_2: ; string 2
db 22h ;18h ; descriptor length (34 bytes)
db 03h ; descriptor type (string)
dsu "Battery Analyzer" ; dsu "Battery Analyzer"
;*********************************************************
; END
;*********************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -