?? ups17b.asm
字號:
;======================================================================
; copyright 1997 Cypress Semiconductor Corporation
;======================================================================
; USB UPS Reference Firmware
;======================================================================
; Part Number: CY7C63001
;======================================================================
;
; This code implements the USB interface for an Uninterruptable
; Power Supply. The interface between the CY7C63001 and the UPS
; is done through RS-232. The code has been divided into two
; portions a general RS-232 part which is in the serial.asm file
; and the USB UPS part which is in this file.
;
; UPS Features include:
; 5 Reports that are used to represent :
; - MAIN AC FLOW PHYSICAL COLLECTION
; - OUTPUT AC FLOW PHYSICAL COLLECTION
; - BATTERY SYSTEM PHYSICAL COLLECTION
; - POWER CONVERTER PHYSICAL COLLECTION
; - AC INPUT PHYSICAL COLLECTION
; - AC OUTPUT PHYSICAL COLLECTION
;
;======================================================================
; History:
; 3/3/98 wmh v1.7
; Minor changes and addition of more comments
;======================================================================
; 12/13/97 wmh v1.6
; All set/get reports added, conversions and strings added
;======================================================================
; 11/24/97 wmh v0.9
; Change in control_read_16 routine to allow program to send more
; than 255 bytes of the report descriptor
;======================================================================
; 11/4/97 wmh v0.8
; Change in GetReportDescriptor subroutine
;======================================================================
; 10/28/97 wmh v0.7
; Control Send added and get/set report requests added
; Control Send is used to send the data of a get report
;======================================================================
; 10/26/97 wmh v0.6
; Control Read 16 added. This allows for a larger than 256 byte
; report descriptor
;======================================================================
; 10/19/97 wmh v0.4
; String Descriptors added (in ROM)
;======================================================================
; 10/16/97 wmh v0.3 USB Enumeration added
; Hid Report id 1 is the only report currently supported
;======================================================================
; 9/27/97 : jb v0.1
; Initial code for generic UPS Serial Interface.
;======================================================================
;
;======================== assembler directives ========================
;
label: XPAGEON
;
; USB ports
USB_EP0_TX_Config: equ 10h ; USB EP0 transmit configuration
USB_EP1_TX_Config: equ 11h ; USB EP1 transmit configuration
USB_Device_Address: equ 12h ; USB device address assigned by host
USB_Status_Control: equ 13h ; USB status and control register
USB_EP0_RX_Status: equ 14h ; USB EP0 receive status
; control ports
Global_Interrupt: equ 20h ; Global interrupt enable
Watchdog: equ 21h ; Clear watchdog Timer
CExt: equ 22h ; Extenal timeout
Timer: equ 23h ; free-running Timer
;
; control port
Status_Control: equ FFh ;
RAMStart: equ 00h ;
RAMEnd: equ 80h ; End of RAM + 1
;********** Register constants ************************************
; Processor Status and Control
RunBit: equ 1h ; CPU Run bit
SuspendBits: equ 9h ; Run and suspend bits set
PowerOnReset: equ 10h ; Power on reset bit
USBReset: equ 20h ; USB Bus Reset bit
WatchDogReset: equ 40h ; Watchdog Reset bit
; USB Status and Control
BusActivity: equ 1h ; USB bus activity bit
; interrupt masks
TIMER_ONLY: equ 4h ; one msec timer
ENUMERATE_MASK: equ 0Ch ; one msec timer
; USB EP0 interrupt
RUNTIME_MASK: equ 1Ch ; one msec timer
; USB EP0 interrupt
; USB EP1 interrupt
; USB EP1 transmit configuration
DataToggle: equ 40h ; Data 0/1 bit
;========================================================================
; constant declarations
;========================================================================
; from USB Spec v1.0 from page 175
;------------------------------------------------------------------------
; standard request codes
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_stalled: equ 0 ; recipient endpoint
device_remote_wakeup: equ 1 ; recipient device
;========================================================================
; 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
;========================================================================
; USB packet constants (debug purposes)
;------------------------------------------------------------------------
;setup: equ B4h
;in: equ 96h
;out: equ 87h
;data0: equ C3h
;data1: equ D2h
;ack: equ 4Bh
;nak: equ 5Ah
DISABLE_REMOTE_WAKEUP: equ 0 ; bit[1] = 0
ENABLE_REMOTE_WAKEUP: equ 2 ; bit[1] = 1
DISABLE_PROTOCOL: equ 0 ; bit[0] = 0
ENABLE_PROTOCOL: equ 1 ; bit[0] = 1
;========================================================================
; data variable assignments
;========================================================================
; control endpoint 0 fifo
endpoint_0: equ 70h ; control endpoint
; definitions for SETUP packets
bmRequestType: equ 70h
bRequest: equ 71h
wValue: equ 72h ; default wValue (8-bits)
wValueHi: equ 73h
wIndex: equ 74h ; default wIndex (8-bits)
wIndexHi: equ 75h
wLength: equ 76h ; default wLength (8-bits)
wLengthHi: equ 77h
; interrupt endpoint 1 fifo
endpoint_1: equ 78h
;*************************************
;
; variable allocations
;*************************************
interrupt_mask: equ 20h ;
;************************************************
;USB Variables
;************************************************
endp0_data_toggle: equ 21h
loop_counter: equ 22h
data_start: equ 23h
data_count: equ 24h
endpoint_stall: equ 25h
remote_wakeup_status: equ 26h ; remote wakeup request
; zero is disabled
; two is enabled
configuration_status: equ 27h ; configuration status
; zero is unconfigured
; one is configured
;idle_status: equ 64h ; support SetIdle and GetIdle
protocol_status: equ 65h ; zero is boot protocol
; one is report protocol
data_send: equ 28h ; start of data to be sent
; next 16 bytes (28-39) are
; send buffer
hi_data_count: equ 60h ; high byte of data count
low_data_count: equ 61h ; low byte of data count
loop_num: equ 62h ; loop number (USB sending)
temp2: equ 63h ; temporary variable
send_ptr: equ 7Dh ; Send buffer ptr
;======================================================================
;
;*************** interrupt vector table ****************
; begin execution here after a reset
org 00h
;
; Interrupt Vector Number 0 : Reset vector
jmp Reset
;
; Interrupt Vector Number 1 : 128us interrupt
jmp Serial_ISR
; Used to implement serial receive/transmit
; bit timing loops.
;
; Interrupt Vector Number 2 : 1024ms interrupt
jmp One_mSec_ISR
; Used for Watchdog timer.
;
; Interrupt Vector Number 3 : endpoint 0 interrupt
jmp USB_EP0_ISR
;
; Interrupt Vector Number 4 : endpoint 1 interrupt
jmp DoNothing_ISR
;
; Interrupt Vector Number 5 : reserved interrupt
jmp Reset
; Runs initialization at reset.
;
; Interrupt Vector Number 6 : general purpose I/O interrupt
jmp GPIO_ISR
; Used to detect receive data start bit.
; Falling edge of Port 0 Bit 7 detected.
;
; Interrupt Vector Number 7 : Wakeup_ISR or resume interrupt
jmp DoNothing_ISR
; Not used
;
;************************************************************************
;
ORG 10h
;************************************************************************
; The Cext, and and most GPIO interrupts are not used by the ups
; code. If any of these interrupts occur, the software should do nothing
; except re-enable the interrupts.
DoNothing_ISR:
push A ; save accumulator on stack
mov A, [interrupt_mask]
ipret Global_Interrupt
;************************************************************************
; The 1 msec interrupt is used to clear the watchdog timer.
; If the watchdog is not cleared for 8 msec, then a watchdog reset will
; occur.
One_mSec_ISR:
push A ; save accumulator on stack
iowr Watchdog ; clear watchdog timer
;
; Finish the interrupt handling
mov A,[interrupt_mask] ;
ipret Global_Interrupt ;
;
;************************************************************************
; The Serial_ISR routine resides in Serial2.asm
;************************************************************************
; The GPIO_ISR routine resides in Serial2.asm
;************************************************************************
include "serial.asm" ;
;************************************************************************
; reset processing
; The idea is to put the microcontroller in a known state. As this
; is the entry point for the "reserved" interrupt vector, we may not
; assume the processor has actually been reset and must write to all
; of the I/O ports.
Reset:
mov A, endpoint_0 ; move data stack pointer
swap A, dsp ; so it does not write over USB FIFOs
mov A,00h ;
mov X,00h ;
ClrRAMLoop:
swap A,X ;
mov [X+RAMStart],A ;
inc X ;
swap A,X ;
cmp A,RAMEnd ;
jnz ClrRAMLoop ;
;
;************************************************************************
; During serial transfers data bit 0 is transmitted first.
; We will use Port 0 Bit 7 for receive and Bit 0 for transmit.
; Data will always be right shifted for either transmit or receive.
; Port 0 Bit 7 will be a falling edge sensitive GPIO_ISR input.
; Port 0 bits 6-0 and Port 1 bits 3-0 will be outputs.
;
call SerialInitialize ;
;*****************************************
;USB initialization
;*****************************************
mov A, 0h
mov [endpoint_stall], A
mov [remote_wakeup_status], A
mov [configuration_status], A
mov A, ENABLE_PROTOCOL
mov [protocol_status], A
;
; test what kind of reset occurred
;
iord Status_Control
and A, USBReset ; test for USB Bus Reset
jnz BusReset
iord Status_Control
and A, WatchDogReset ; test for Watch Dog Reset
jz suspendReset
;
; Process a watchdog reset. Wait for a Bus Reset to bring the system
; alive again.
mov A, TIMER_ONLY ; enable one msec timer interrupt
mov [interrupt_mask],A
iowr Global_Interrupt
WatchdogHandler: ; wait for USB Bus Reset
jmp WatchdogHandler
suspendReset:
mov A, 09h
iowr Status_Control ; go back to suspend
nop
jmp suspendReset ; wait until real bus reset
;
; Either a bus reset or a normal reset has occurred
;
BusReset:
mov A, RunBit ; clear all reset bits
iowr Status_Control
; setup for enumeration
mov A, ENUMERATE_MASK
mov [interrupt_mask],A
iowr Global_Interrupt
wait: ; wait until configured
iord USB_EP1_TX_Config
cmp A, 0
jz wait
;************************************************************************
; This is the main loop that is entered after reset processing
;************************************************************************
;
main:
; iowr Watchdog ; clear watchdog timer
jmp main
;************************************************************************
; Command string transmit processing:
; These 3 routines will transmit four bytes of data for each command.
; 1.) Ident: Manufacturer: "I M C_R L_F"
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -