⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 js50.asm

📁 USB大全电子版全部资料3~包含源码、协议等
💻 ASM
📖 第 1 页 / 共 4 页
字号:
;***********************************************************************

;				Cypress Semiconductor

; 			Joystick Demonstration Design Kit Firmware 

;

; Features :

; Four Fire Buttons

; Four Hat Buttons

; X, Y, Z movement

; Throttle

; Passes Chapter 9 and Hidview Tests 

; Includes Suspend/Resume Feature

;

; This firmware file is for demonstration purposes only.  

; Cypress Semiconductor will not assume any liability for its use.

; 

;=======================================================================

; 1/20/98	wmh	v5.0 Minor changes in One_msec_ISR

;=======================================================================

; 12/10/97	wmh	v4.9 Minor changes in One_msec_ISR, main and Reset
; Watchdog timer reset in main.

;=======================================================================

; 10/27/97	wmh	v4.8	Change in One_msec_ISR

; Code Naks whenever the joystick is not moved.

; Code also Naks after enumeration for a period approx. 230msec

; This solves blue screen problem when the power is turned off then on

;=======================================================================

; 10/13/97	wmh	v4.6	Change in USB_EP0_ISR

; SetConfiguration request was changed so as to enable endpoint 1

; GetReport is stalled

; GetReportDescriptor sends HID Report Descriptor

;=======================================================================

; 9/8/97	wmh 	v4.5 	Joystick Jitter Solved

; Jitter Solution added to GPIO_ISR 

;=======================================================================

; 8/13/97	wmh 	v4.3 	Report Descriptor Change

; Solves unusual jump in joystick movement

;=======================================================================

; 8/11/97	wmh 	v4.2	ipret change

; changed ret to ipret whenever needed in all subroutines

;=======================================================================

; 8/8/97	wmh	v4.0	One_msec and GPIO ISR changes

; Changes to prevent Endpoint_1 from interrupting capacitor charging

; to prevent jitter effect

;========================================================================

; 8/8/97	wmh 	v3.9	change in Report Descriptor

; Logical and Physical Min and Max have been changed to 3 bytes if > 127

; Other changes were also done

;========================================================================

; 7/3/97	wmh	v3.7 add features

; Suspend/Resume features have been added

; Main work done in the One_mSec_ISR

;========================================================================

; 6/30/97	wmh	v3.6 add features

; changes to allow the code to pass chapter 9 and hidview tests have been

; done.  That meant major rework of the endpoint zero interrupt service

; routine (USB_EP0_ISR).

;=======================================================

; rev 3.5	4/17/97 gwg

; Changed the interrupt mask from a constant to a variable.

; This allows us to enable only the one msec timer and

; EP0 during enumeration.

;

; Tim Williams found a problem with the hat buttons.  I

; forgot the buttons were in the upper nibble.

;=======================================================

; rev 3.4	4/15/97 gwg	664 bytes

; 1. The endpoint one ISR only toggles the Data 0/1 bit

;    now.

; 2. Every four msec, the one msec ISR writes to the

;    USB_EP1_TX_Config register to enable response to IN

;    packets from the host.

; 3. Write measured data directly into the endpoint one 

;    dma buffer.

; 4. Code compatible with revision 2 and 3 silicon.

;=======================================================

; rev 3.3       4/11/97 gwg

; modified for IPRET instruction in an effort to improve

; the runtime.

;=======================================================

; rev 3.2       4/11/97 gwg

; Tim Williams found a bug in the GPIO_ISR that prevented

; the code from working in the chip.  There was not enough

; time allowed to discharge the timing capacitors before

; interrupts were enabled.

;=======================================================

; rev 3.1       4/8/97  gwg

; Replaced Send_Buffer macro with a subroutine.

;=======================================================

; rev 3.0       4/8/97  gwg

; reworked the code to support the hat buttons and up to

; four analog channels.  The analog channels are sampled

; one per msec.  With a channel sample rate of 250 hz, 

; each channel should have a bandwidth of 125 hz - good.

; 

; The buttons are sampled in the main loop at a much

; higher rate.  

;

; The Send_Buffer macro remains a code size problem as

; the result to date is 40 bytes over 2 kilobytes.

;=======================================================

; rev 2.1       3/29/97 gwg

; reworked the code to eliminate string indices in the

; descriptors.  We don't have any strings.  Also fixed

; an error in the HID length (114 => 116 bytes)

;=======================================================

; drastic rework of js63fa.asm on 3/25 by gwg

;*******************************************************

;  This version of code supports the joystick function

;  and four buttons.

;*******************************************************

; 1. Eliminated the "scaling" feature that tried to 

;    ensure the joystick returned full-range readings.

; 2. Converted the analog measurement sections into two

;    subroutines.

; 3. Fixed several interrupt enable and stack problems

;    with the USB interrupt service routines.

; 4. Initialized the part to work correctly in a joystick:

;       - program pullup registers

;       - program Isink registers

; 5. Enabled the one msec interrupt handler to clear the

;    watchdog.

; 6. Patched the USB EP0 ISR to set the BadOuts bit to

;    accomodate changes in the chip definition.

; 7. Rewrote the USB interrupt handlers for better flow

;    and to remove redundant load instructions.

; 8. Commented the code to describe how it works. 

;*******************************************************

;               Suggested Changes

;-------------------------------------------------------

; 1. Convert the Send_Buffer macro to a subroutine to

;    reduce the code size.  The current version is 2 KB

;    plus 22 bytes.

; 2. Add hat support as either:

;       - third analog channel (software only)

;       - four buttons (rework hardware)

; 3. Add throttle support as another analog channel.

;    Consolidate the measure subroutines into one routine

;    that can process a selectable channel.

;*******************************************************

;               Suggestions for the Assembler

;-------------------------------------------------------

; 1. The assembler should be able to assign variable

;    addresses automatically.  One method is the concept

;    of segments: "data" and "code".  An ORG directive

;    would include a parameter to indicate which type of

;    segment was intended.  Then DB, DW, etc. would

;    allocate variable space and automatically assign 

;    the addresses.

; 2. We need a linker that allows us to write modular

;    code and link modules together.   

; 3. Conditional assembly directives would be useful to

;    write common code to support multiple parts.

;*******************************************************



;**************** assembler directives ***************** 



label:          XPAGEON



; I/O ports

Port0_Data:            equ     00h      ; GPIO data port 0

Port1_Data:            equ     01h      ; GPIO data port 1

Port0_Interrupt:       equ     04h      ; Interrupt enable for port 0

Port1_Interrupt:       equ     05h      ; Interrupt enable for port 1

Port0_Pullup:          equ     08h      ; Pullup resistor control for port 0

Port1_Pullup:          equ     09h      ; Pullup resistor control for port 1



; 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

Timer:                  equ     23h     ; free-running Timer



; GPIO Isink registers

Port0_Isink:            equ     30h

Port0_Isink0:           equ     30h

Port0_Isink1:           equ     31h

Port0_Isink2:           equ     32h

Port0_Isink3:           equ     33h

Port0_Isink4:           equ     34h

Port0_Isink5:           equ     35h

Port0_Isink6:           equ     36h

Port0_Isink7:           equ     37h



Port1_Isink:            equ     38h

Port1_Isink0:           equ     38h

Port1_Isink1:           equ     39h

Port1_Isink2:           equ     3Ah

Port1_Isink3:           equ     3Bh



; control port

Status_Control:         equ     FFh



; constants - gwg

BUTTON_MASK:            equ     0Fh     ; button bits

HAT_MASK:               equ     F0h     ; hat bits

FORWARD:                equ     1       ; hat forward

RIGHT:                  equ     3       ; hat right

BACK:                   equ     5       ; hat back

LEFT:                   equ     7       ; hat left

;**********  Register constants  ************************************

; Processor Status and Control

RunBit:			equ	 1h	; CPU Run bit

USBReset:			equ	20h	; USB Bus Reset bit

WatchDogReset:		equ	40h	; Watchdog Reset bit



; interrupt masks

TIMER_ONLY:			equ	 4h	; one msec timer



ENUMERATE_MASK:		equ	0Ch	; one msec timer 	

						; USB EP0 interrupt



RUNTIME_MASK:		equ     5Ch     	; one msec timer

							; USB EP0 interrupt

							; USB EP1 interrupt

							; GPIO 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



;========================================================================

; 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

 



; data memory variables

;------------------------------------------------------------------------

; To support the USB specification.

remote_wakeup_status:   equ  30h       	; remote wakeup request

							; zero is disabled

							; two is enabled

configuration_status:   equ  31h        	; configuration status

							; zero is unconfigured

							; one is configured

;idle_status:           equ  33h        	; support SetIdle and GetIdle

protocol_status:      	equ  34h        	; zero is boot protocol

							; one is report protocol

suspend_counter:		equ 35h		; contains number of idle bus msecs 

jitter_temp:		equ 36h	

loop_temp:			equ 37h

start_send:			equ 38h

X_Value_old:                equ  39h        

Y_Value_old:                equ  40h        

Z_Value_old:                equ  41h        

hat_bits_old:               equ  42h        

button_bits_old:            equ  43h        

Throttle_old:               equ  44h        



	

;------------------------------------------------------------------------



; variable allocations

temp:                   equ  25h

start_time:             equ  21h

testbit:                equ  22h

interrupt_mask:		equ  20h

endp0_data_toggle: 	equ  23h

loop_counter:		equ  24h

data_start:			equ  27h

data_count:			equ  28h

endpoint_stall:		equ  29h



; interrupt endpoint 1 fifo

endpoint_1:             equ  78h

X_Value:                equ  78h        ; Port 1 bit 0

Y_Value:                equ  79h        ; Port 1 bit 1

Z_Value:                equ  7Ah        ; Port 1 bit 3

hat_bits:               equ  7Bh        ; Port 0 bits 7:4

button_bits:            equ  7Ch        ; Port 0 bits 3:0

Throttle:               equ  7Dh        ; Port 1 bit 2



;*************** interrupt vector table ****************

; begin execution here after a reset

org  00h                ; Reset vector

jmp  Reset



org  02h                ; 128us interrupt

jmp  DoNothing_ISR



org  04h                ; 1024ms interrupt 

jmp  One_mSec_ISR



org  06h                ; endpoint 0 interrupt 

jmp  USB_EP0_ISR



org  08h                ; endpoint 1 interrupt 

jmp  USB_EP1_ISR



org  0Ah                ; reserved interrupt 

jmp  Reset



org  0Ch                ; general purpose I/O interrupt 

jmp  GPIO_ISR           ; not used



org  0Eh                ; Wakeup_ISR or resume interrupt 

jmp  DoNothing_ISR      ; not used





ORG  10h

;************************************************************************

; The 128 uSec, Cext, is not used by the joystick
 code.
; If this interrupt occurs, the software should do nothing

; except re-enable the interrupts.

DoNothing_ISR:

	push A                  ; save accumulator on stack

	mov A,[interrupt_mask]

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -