?? ups17b.asm
字號:
mov X, [txBufPtr] ; Set the index.
mov A, [X + txBuf] ; Load Command Byte Zero.
mov [txData], A ; Put it in the transmit register.
inc [txBufPtr] ; Point to the next byte.
iowr Watchdog ; Ping the watch dog timer.
call txRoutine ; Go transmit the byte.
iowr Watchdog ; Ping the watch dog timer.
call delay1 ; Give the serial device some time.
; iowr Watchdog ; clear watchdog timer
mov X, [txBufPtr] ; Set the index.
mov A, [X + txBuf] ; Load Command Byte One
mov [txData], A ; Put it in the transmit register.
inc [txBufPtr] ; Point to the next byte.
iowr Watchdog ; clear watchdog timer
call txRoutine ; Go transmit the byte.
iowr Watchdog ; clear watchdog timer
call delay1 ; Give the serial device some time.
; iowr Watchdog ; clear watchdog timer
mov X, [txBufPtr] ; Set the index.
mov A, [X + txBuf] ; Load Command Byte Two
mov [txData], A ; Put it in the transmit register.
inc [txBufPtr] ; Point to the next byte.
; iowr Watchdog ; clear watchdog timer
call txRoutine ; Go transmit the byte.
iowr Watchdog ; clear watchdog timer
; call delay1 ; Give the serial device some time.
; iowr Watchdog ; clear watchdog timer
mov X, [txBufPtr] ; Set the index.
mov A, [X + txBuf] ; Load Command Byte Three
mov [txData], A ; Put it in the transmit register.
inc [txBufPtr] ; Point to the next byte.
; iowr Watchdog ; clear watchdog timer
call txRoutine ; Go transmit the byte.
mov A, 80h ; Enable the Port 0 Bit 7
iowr Port0_Interrupt ; GPIO interrupt.
iowr Watchdog ; clear watchdog timer
ret ; Return to sender.
;
;************************************************************************
; This routine changes from ASCII to BCD
;************************************************************************
ASCII_to_BCD:
;
push A
push X
mov A, 0h
mov [rxBufPtr], A
mov A, 02h
mov [temp2], A
next_char:
mov X, [rxBufPtr]
mov A, [X + rxBuf]
cmp A, Car_Ret
jz end_of_data
and A, 0fh
mov [X + rxBuf], A
inc [rxBufPtr]
jmp next_char
end_of_data:
dec [rxBufPtr]
jc end_conversion
mov X, [rxBufPtr]
mov A, [X + rxBuf]
mov X, [temp2]
mov [X + endpoint_1], A
dec [rxBufPtr]
jc end_conversion
mov X, [rxBufPtr]
mov A, [X + rxBuf]
asl A
asl A
asl A
asl A
mov X, [temp2]
or A, [X + endpoint_1]
mov [X + endpoint_1], A
dec [temp2]
jmp end_of_data
end_conversion:
pop X
pop A
ret
;************************************************************************
;
; Interrupt handler: endpoint_zero
; Purpose: This interrupt routine handles the specially
; reserved control endpoint 0 and parses setup
; packets. If a IN or OUT is received, this
; handler returns to the control_read
; or no_data_control routines to send more data.
;
;************************************************************************
; The endpoint zero interrupt service routine supports the control
; endpoint. This firmware enumerates and configures the hardware.
;************************************************************************
USB_EP0_ISR:
push A ; save accumulator on stack
iord USB_EP0_RX_Status ; load status register into accumulator
and A, 01h ; check if SETUP packet received
jz ep0_continue ; ignore unless SETUP packet
mov A,[interrupt_mask] ; disable endpoint zero interrupts
and A, 0F7h
mov [interrupt_mask], A
iowr Global_Interrupt
call StageOne ; parse SETUP packet
mov A, [interrupt_mask] ; enable endpoint zero interrupts
or A, 08h
mov [interrupt_mask], A
ep0_continue:
mov A, [interrupt_mask] ; enable the interrupts
ipret Global_Interrupt
;========================================================================
; stage one ... test bmRequestType
;========================================================================
StageOne:
;------------------------------------------------------------------------
; Parse standard device requests as per Table 9.2 in USB Spec.
;------------------------------------------------------------------------
mov A, 00h ; clear the setup flag to write DMA
iowr USB_EP0_RX_Status
mov A, 8 ; set BadOut bit
iowr USB_Status_Control
mov A, [bmRequestType] ; load bmRequestType
; host to device
cmp A, 00h
jz RequestType00 ; bmRequestType = 00000000 device
; cmp A, 01h *** not required ***
; jz RequestType01 ; bmRequestType = 00000001 interface
cmp A, 02h
jz RequestType02 ; bmRequestType = 00000010 endpoint
cmp A, 80h
; device to host
jz RequestType80 ; bmRequestType = 10000000 device
cmp A, 81h
jz RequestType81 ; bmRequestType = 10000001 interface
cmp A, 82h
jz RequestType82 ; bmRequestType = 10000010 endpoint
;-----------------------------------------------------------------------
; Parse HID class device requests as per HID version 1.0 Draft #4
;-----------------------------------------------------------------------
; host to device
cmp A, 21h
jz RequestType21 ; bmRequestType = 00100001 interface
cmp A, 22h ; *** not in HID spec ***
jz RequestType22 ; bmRequestType = 00100010 endpoint
; device to host
cmp A, A1h
jz RequestTypeA1 ; bmRequestType = 10100001 interface
;-----------------------------------------------------------------------
; Stall unsupported functions
;-----------------------------------------------------------------------
SendStall: ; stall unsupported functions
mov A, A0h ; send a stall to indicate the requested
iowr USB_EP0_TX_Config ; function is not supported
ret ; return
;========================================================================
; stage two ... test bRequest
;========================================================================
; host to device with device as recipient
RequestType00:
mov A, [bRequest] ; load bRequest
;------------------------------------------------------------------------
; The only standard feature defined for a "device" recipient is
; device_remote_wakeup. Remote wakeup is the ability to "wakeup" a
; system from power down mode by pressing a key or moving a button.
; The default condition at reset is remote wakeup disabled.
;------------------------------------------------------------------------
; Clear Feature bRequest = 1
cmp A, clear_feature
jz ClearRemoteWakeup
; Set Feature bRequest = 3
cmp A, set_feature
jz SetRemoteWakeup
;------------------------------------------------------------------------
; Set the device address to a non-zero value.
; Set Address bRequest = 5
cmp A, set_address
jz SetAddress
;------------------------------------------------------------------------
; This request is optional. If a device supports this request, existing
; device descriptors may be updated or new descriptors may be added.
; Set Descriptor bRequest = 7 *** not supported ***
;------------------------------------------------------------------------
; If wValue is zero, the device is unconfigured. The only other legal
; configuration for this version of firmware is one.
; Set Configuration bRequest = 9
cmp A, set_configuration
jz SetConfiguration
jmp SendStall ; stall unsupported function calls
;========================================================================
; host to device with interface as recipient *** not required ***
; RequestType01:
; mov A, [bRequest] ; load bRequest
;------------------------------------------------------------------------
; There are no interface features defined in the spec.
; Clear Feature bRequest = 1 *** not supported ***
; Set Feature bRequest = 3 *** not supported ***
;------------------------------------------------------------------------
; This request allows the host to select an alternate setting for the
; specified interface. As only one interface setting is being used,
; this request is not supported.
; Set Interface bRequest = 11 *** not supported ***
; jmp SendStall ; stall unsupported functions
;========================================================================
; host to device with endpoint as recipient
RequestType02:
mov A, [bRequest] ; load bRequest
;------------------------------------------------------------------------
; The only standard feature defined for an endpoint is endpoint_stalled.
; Clear Feature bRequest = 1
cmp A, clear_feature
jz ClearEndpointStall
; Set Feature bRequest = 3
cmp A, set_feature
jz SetEndpointStall
jmp SendStall ; stall unsupported functions
;=======================================================================
; device to host with device as recipient
RequestType80:
mov A, [bRequest] ; load bRequest
; Get Status bRequest = 0
cmp A, get_status
jz GetDeviceStatus
; Get Descriptor bRequest = 6
cmp A, get_descriptor
jz GetDescriptor
; Get Configuration bRequest = 8
cmp A, get_configuration
jz GetConfiguration
jmp SendStall ; stall unsuported functions
;=======================================================================
; device to host with interface as recipient
RequestType81:
mov A, [bRequest] ; load bRequest
; Get Status bRequest = 0
cmp A, get_status
jz GetInterfaceStatus
;------------------------------------------------------------------------
; This request returns the selected alternate setting for the specified
; interface. There are no alternate settings for the in this UPS.
; Get Interface bRequest = 10 *** not supported ***
;------------------------------------------------------------------------
; HID class defines one more request for bmRequestType=10000001
; Get Descriptor bRequest = 6
cmp A, get_descriptor
jz GetDescriptor
jmp SendStall ; stall unsupported functions
;=======================================================================
; device to host with endpoint as recipient
RequestType82:
mov A, [bRequest] ; load bRequest
; Get Status bRequest = 0
cmp A, get_status
jz GetEndpointStatus
;------------------------------------------------------------------------
; Not defined in the spec, but it must be decoded for the enumeration to
; complete under Memphis.
; Get Descriptor bRequest = 6
cmp A, get_descriptor
jz GetDescriptor
; Sync Frame bRequest = 12 *** not supported ***
jmp SendStall ; stall unsupported functions
;========================================================================
; Now parse HID class Descriptor Types
;========================================================================
; host to device with endpoint as recipient
RequestType21:
mov A, [bRequest] ; load bRequest
; Set Report bRequest = 9
cmp A, set_report
jz SetReport
; Set Idle bRequest = 10
cmp A, set_idle
jz SetIdle
; Set Protocol bRequest = 11
cmp A, set_protocol
jz SetProtocol
jmp SendStall ; stall unsupported functions
;=======================================================================
; This one is not in the spec, but has been captured with CATC while
; Memphis beta testing.
RequestType22:
mov A, [bRequest] ; load bRequest
; Set Report bRequest = 9
cmp A, set_report
jz SetReport
jmp SendStall ; stall unsupported functions
;=======================================================================
; device to host with endpoint as recipient
RequestTypeA1:
mov A, [bRequest] ; load bRequest
; Get Report bRequest = 1
cmp A, get_report
jz GetReport
; Get Idle bRequest = 2
cmp A, get_idle
jz GetIdle
; Get Protocol bRequest = 3
cmp A, get_protocol
jz GetProtocol
jmp SendStall ; stall unsupported functions
;========================================================================
; stage three ... process the request
;========================================================================
; Remote wakeup is the ability to wakeup a system from power down mode.
; These routines allow the host to enable/disable the ability to request
; remote wakeup.
;
; Disable the remote wakeup capability.
ClearRemoteWakeup:
mov A, [wValue] ; load wValue
cmp A, device_remote_wakeup ; test for valid feature
jnz SendStall ; stall unsupported features
call no_data_control ; handshake with host
mov A, DISABLE_REMOTE_WAKEUP ; disable remote wakeup
mov [remote_wakeup_status], A
ret ; return
; Enable the remote wakeup capability.
SetRemoteWakeup:
mov A, [wValue] ; load wValue
cmp A, device_remote_wakeup ; test for valid feature
jnz SendStall ; stall unsupported features
call no_data_control ; handshake with host
mov A, ENABLE_REMOTE_WAKEUP ; enable remote wakeup
mov [remote_wakeup_status], A
ret ; return
; Set the device address to the wValue in the SETUP packet at
; the completion of the current transaction.
SetAddress:
call no_data_control ; handshake with host
mov A, [wValue] ; load wValue
iowr USB_Device_Address ; write new USB device address
ret ; return
; Set the configuration of the device to either unconfigured (0) or
; configured (1) based on wValue in the SETUP packet. According to
; the USB spec (page 178), a Set Configuration also clears the endpoint
; stall condition and re-initializes endpoints using data 0/1 toggle to
; Data0.
SetConfiguration:
call no_data_control
mov A, [wValue] ; load wValue lsb
mov [configuration_status], A ; store configuration byte
mov A, 0
mov [endpoint_stall], A ; not stalled
iord USB_EP1_TX_Config ; clear data 0/1 bit
and A, ~DataToggle
iowr USB_EP1_TX_Config
mov A, [configuration_status]
cmp A, 0
jnz device_configured
; device is unconfigured
iord USB_EP1_TX_Config
and A, EFh ; disable endpoint 1
iowr USB_EP1_TX_Config
mov A, [interrupt_mask] ; disable endpoint one interrupts
and A, EFh
mov [interrupt_mask], A
jmp done_configuration
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -