📄 ups17b.asm
字号:
; 2.) Ident: Product: "I O C_R L_F"
; 3.) Ident: Serial Nunber: "I Z C_R L_F"
;************************************************************************
put_iManufacturer_String:
push A ; Save the accumulator.
push X ; Save the index register.
call initialize_req
mov A, Asc_I ; Load ASCII 'I' into accumulator
mov [X + txBuf], A ; Write into the buffer.
inc [txBufPtr] ; Increment tx buffer pointer
mov X, [txBufPtr] ; Load the new index.
mov A, Asc_M ; Load ASCII 'M' into accumulator
call end_req
pop X ; Restore the index.
pop A ; Restore the accumulator.
ret ; Return to caller.
;************************************************************************
put_iProduct_String:
push A ; Save the accumulator.
push X ; Save the index register.
call initialize_req
mov A, Asc_I ; Load ASCII 'I' into accumulator.
mov [X + txBuf], A ; Write into the buffer.
inc [txBufPtr] ; Increment tx buffer pointer.
mov X, [txBufPtr] ; Load the new index.
mov A, Asc_O ; Load ASCII 'O' into accumulator.
call end_req
pop X ; Restore the index register.
pop A ; Restore the accumulator.
ret ; Return to caller.
;************************************************************************
put_iSerialNumber_String:
push A ; Save the accumulator.
push X ; Save the index register.
call initialize_req
mov A, Asc_I ; Load ASCII 'I' into accumulator
mov [X + txBuf], A ; Write into the buffer.
inc [txBufPtr] ; Increment tx buffer pointer
mov X, [txBufPtr] ; Load the new index.
mov A, Asc_Z ; Load ASCII 'Z' into accumulator
call end_req
pop X ; Restore the index register.
pop A ; Restore the accumulator.
ret ; Return to caller.
;************************************************************************
; This routine sends the strings
;************************************************************************
send_string:
push X ; save X on stack
mov A, 00h ; clear data 0/1 bit
mov [endp0_data_toggle], A
mov [rxBufPtr], A
mov X, 0h
iowr USB_EP0_RX_Status ; clear setup bit
; Fixing a bug seen by NEC hosts
iord USB_EP0_RX_Status ; check setup bit
and A, 01h ; if not cleared, another setup
jnz send_string_end ; has arrived. Exit ISR
mov A, 08h ; set BADOUTS BIT
iowr USB_Status_Control
mov A, 03h
mov [endpoint_0 + 1], A
mov A, [data_count]
cmp A, [temp2]
jz right_length
; mov A, 03h
; mov [endpoint_0 + 1], A
mov A, [temp2]
mov [endpoint_0], A
mov A, 01h
mov [loop_counter], A
dec [data_count]
jz send_packet
inc [loop_counter]
dec [data_count]
jz send_packet
; mov A, [data_count]
; asr A
; mov [data_count], A
jmp sending_loop
right_length:
mov A, [data_count]
cmp A, 00h
jz send_empty
first_byte:
mov [endpoint_0], A
; mov A, 03h
; mov [endpoint_0 + 1], A
mov A, 01h
mov [loop_counter], A
dec [data_count]
mov A, [data_count]
cmp A, 00h
jz send_packet
dec [data_count]
inc [loop_counter]
mov A, [data_count]
cmp A, 00h
jz send_packet
sending_loop: ; loop to load data into the data buffer
mov X, [rxBufPtr]
mov A, [X + rxBuf]
mov X, [loop_counter]
mov [X + endpoint_0], A
inc [rxBufPtr]
inc [loop_counter]
dec [data_count]
cmp A, 0h
jz send_packet
mov A, 00h
mov X, [loop_counter]
mov [X + endpoint_0], A
inc [loop_counter]
dec [data_count]
mov A, [data_count]
cmp A, 0h
jz send_packet
mov A, [loop_counter]
cmp A, 08h
jnz sending_loop
send_packet:
iord USB_EP0_RX_Status ; check setup bit
and A, 01h ; if not cleared, another setup
jnz send_string_end ; has arrived. Exit ISR
mov A, [endp0_data_toggle]
xor A, 40h
mov [endp0_data_toggle], A
or A, 80h
or A, [loop_counter]
iowr USB_EP0_TX_Config
mov A, [interrupt_mask]
iowr Global_Interrupt
send_wait:
iord USB_EP0_TX_Config ; wait for the data to be
and A, 80h ; transfered
jz next_packet
iord USB_EP0_RX_Status
and A, 02h ; check if out was sent by host
jz send_wait
jmp send_empty
next_packet:
mov A, 0h
mov [loop_counter], A
iowr USB_EP0_RX_Status ; clear setup bit
; Fixing a bug seen by NEC hosts
iord USB_EP0_RX_Status ; check setup bit
and A, 01h ; if not cleared, another setup
jnz send_string_end ; has arrived. Exit ISR
mov A, 08h ; set BADOUTS BIT
iowr USB_Status_Control
mov A, [data_count]
cmp A, 00h
jnz sending_loop
send_empty:
mov A, [endp0_data_toggle]
xor A, 40h
mov [endp0_data_toggle], A
or A, 80h
and A, 0f0h
iowr USB_EP0_TX_Config
mov A, [interrupt_mask]
iowr Global_Interrupt
send_string_end: ; OUT at end of data transfer
pop X ; restore X from stack
mov A, [interrupt_mask]
iowr Global_Interrupt
ret
;************************************************************************
; This routine arranges the strings and adds 00 byte after each ascii byte
; the length is also calculated and the strings are sent(calls send_string)
;************************************************************************
arrange_strings:
mov A, 02h
mov [data_count], A
mov A, 03h
mov [data_send + 1], A ; Report type
; Check if an error has occured during communication with the UPS
mov A, [rxFrameFlag]
cmp A, 01h
jz bad_string
; NO error in the UPS communication
call unsupported_check ; check if the request unsupported
; mov A, [temp2]
cmp A, 01h
jz bad_string
; Request is supported and no errors occured
; Count the bytes and send
mov A, 0h
mov [rxBufPtr], A
mov [data_count], A
next_string:
mov X, [rxBufPtr]
mov A, [X + rxBuf]
cmp A, Car_Ret
jz end_of_string
inc [data_count]
mov A, [data_count]
cmp A, 10h ; check if 16 bytes
jz end_of_string
inc [rxBufPtr]
jmp next_string
end_of_string:
mov A, [data_count]
asl A
add A, 02h
mov [data_count], A
mov [temp2], A
call get_descriptor_length
call send_string
jmp arrange_strings_end
bad_string:
inc [data_count]
mov A, [data_count]
mov [data_send], A ; Report type
mov A, 0ffh
mov [data_send + 2], A
call get_descriptor_length
call control_send
arrange_strings_end:
ret
;********************************************************************************
; This routine initializes the sending of requests to the UPS
;********************************************************************************
initialize_req:
call delay
call Clear_rxBuf
mov A, 00h ;
mov [rxBufPtr], A ; Reset the receive buffer pointer.
mov [txBufPtr], A ;
mov X, [txBufPtr] ;
ret
;********************************************************************************
; This routine checks if 15,0D (unsupported request) has been returned from the UPS
; If a request is unsupported FFh is returned over the USB bus to the host
;********************************************************************************
unsupported_check:
mov A, [rxBuf] ; Is the first byte 15h
cmp A, 15h
jnz supported
mov A, [rxBuf + 1] ; Is the 2nd byte 0Dh
cmp A, Car_Ret
jnz supported
mov A, 1h ; unsupported command
mov [temp2], A
jmp end_unsupported
supported: ; supported command
mov A, 0h
mov [temp2], A
end_unsupported:
ret
;********************************************************************************
; This routine ends the transmission loading part, transmits the commands
; and receives the result from the UPS
;********************************************************************************
end_req:
mov [X + txBuf], A ;
inc [txBufPtr] ; Increment tx buffer pointer
mov X, [txBufPtr] ;
mov A, Car_Ret ; Load carriage return into accumulator
mov [X + txBuf], A ;
inc [txBufPtr] ; Increment tx buffer pointer
mov X, [txBufPtr] ;
mov A, Ln_Fd ; Load line feed into accumulator
mov [X + txBuf], A ;
call putCommand ; Send command to UPS
call getSerial ; Receive result from UPS
ret
;********************************************************************************
; This routine checks for error and loads two bytes to be sent
;********************************************************************************
get_two_bytes:
call end_req ;send and receive the data from UPS
; Check if an error has occured during communication with the UPS
mov A, [rxFrameFlag]
cmp A, 01h
jz bad_value
; NO error in the UPS communication
call unsupported_check ; check if the request unsupported
; mov A, [temp2]
cmp A, 01h
jz bad_value
; Request is supported and no errors occured
call ASCII_to_BCD ; change from ASCII to BCD
mov A, [endpoint_1 + 2]
mov X, [send_ptr]
mov [X + data_send], A
inc X
inc [send_ptr]
mov A, [endpoint_1 + 1]
mov [X + data_send], A
jmp next
bad_value:
; An error occured or an unsupported request
; fill sent back bytes with ffh
mov A, 0ffh
mov X, [send_ptr]
mov [X + data_send], A
inc X
inc [send_ptr]
mov [X + data_send], A
next:
inc [send_ptr]
call initialize_req ; initialize for next request
ret
;********************************************************************************
; This routine checks for error and loads three bytes to be sent
;********************************************************************************
get_three_bytes:
call end_req ;send and receive the data from UPS
; Check if an error has occured during communication with the UPS
mov A, [rxFrameFlag]
cmp A, 01h
jz bad_value2
; NO error in the UPS communication
call unsupported_check ; check if the request unsupported
; mov A, [temp2]
cmp A, 01h
jz bad_value2
; Request is supported and no errors occured
call ASCII_to_BCD ; change from ASCII to BCD
mov A, [endpoint_1 + 2]
mov X, [send_ptr]
mov [X + data_send], A
inc X
inc [send_ptr]
mov A, [endpoint_1 + 1]
mov [X + data_send], A
inc X
inc [send_ptr]
mov A, [endpoint_1]
mov [X + data_send], A
jmp next2
bad_value2:
; An error occured or an unsupported request
; fill sent back bytes with ffh
mov A, 0ffh
mov X, [send_ptr]
mov [X + data_send], A
inc X
inc [send_ptr]
mov [X + data_send], A
inc X
inc [send_ptr]
mov [X + data_send], A
next2:
inc [send_ptr]
call initialize_req ; initialize for next request
ret
;********************************************************************************
; Report ID 1
;********************************************************************************
get_reportID1:
push A ;
push X ;
mov A, 02h
mov [send_ptr], A
call initialize_req
;put_Main_ConfigVoltage_String:
mov A, Asc_F ; Load ASCII 'F' into accumulator
mov [X + txBuf], A ;
inc [txBufPtr] ; Increment tx buffer pointer
mov X, [txBufPtr] ;
mov A, Asc_V ; Load ASCII 'V' into accumulator
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -