📄 jb8-usb.asm
字号:
*****************************************************************************
* Copyright (c) Motorola 2000 *
* File Name: JB8-USB.ASM *
* *
* Description: USB PS/2 keyboard demo program for HC908JB8 *
* *
* *
* Assembler: CASM08Z (P&E Microcomputer Systems Inc) *
* Version: 3.16 *
* *
* Current Revision: 0.1 *
* Current Revision Release Date: 2000.05.02 by Derek Lau *
* *
* Updated History *
* Rev YYYY.MM.DD Author Description of Change *
* --- ----------- ------ --------------------- *
* 0.0 1999.07.15 Derek Lau orginal release *
* 0.1 2000.05.02 Derek Lau fixed stop/resume problem *
* fixed SETUP token not response *
*****************************************************************************
* This Program is a freeware to demonstrate the operation of Motorola *
* Microcontroller. Motorola reserves the right to make changes without *
* further notice to any product herein to improve reliability, function, or *
* design. Motorola does not assume any liability arising out of the *
* application or use of any product, circuit, or software described herein; *
* neither does it convey any license under its patent rights nor the rights *
* of others. Motorola products are not designed, intended, or authorized *
* for use as components in systems intended for surgical implant into the *
* body, or other applications intended to support life, or for any other *
* application in which the failure of the Motorola product could create a *
* situation where personal injury or death may occur. Should Buyer purchase *
* or use Motorola products for any such intended or unauthorized *
* application, Buyer shall indemnify and hold Motorola and its officers, *
* employees, subsidiaries, affiliates, and distributors harmless against *
* all claims, costs, damages, and expenses, and reasonable attorney fees *
* arising out of, directly or indirectly, any claim of personal injury or *
* death associated with such unintended or unauthorized use, even if such *
* claim alleges that Motorola was negligent regarding the design or *
* manufacture of the part. Motorola and the Motorola logo* are registered *
* trademarks of Motorola Inc *
*****************************************************************************
* Notes:
* - abbreviation
* i/p - input, o/p - output, i/o - input/output, o/d - open-drain o/p
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
;; (If use internal D- pullup SET USB_IPullup)
$SET USB_IPullup ; internal USB pullup resistor
;;$SETNOT USB_IPullup
* ------ Compile Options -------------------------------------------------
.CYCLE_ADDER_OFF
$BASE !10
* ------ USB Initialization --------------------------------------------
USB_Start:
SEI ; mask all interrupts.
*
* --- Initialize IRQ Interrupt ------------------------------------------
bset b_IMASK1,ISCR ; disable IRQ interrupt
MOV #%11100111,POC ; enable Port A/B/C/E pullup,
CLR VS_LED
; disabled spec s.9.4.5
clr V_EP1_UCR1
clr V_EP2_UCR2
$IF USB_IPullup
mov #%00000100,UCR3 ; enable USB pullup
$ENDIF
Not_USB_Rst:
*
*
* --- Initialize LONG_IDX routine ----------------------------------------
* where 16-bit offset V_Opd_H:L are RAM bytes
MOV #$D6,V_LDA ; Opcode of LDA(16-bit Index)
MOV #$B7,V_STA
MOV #$81,V_RTS
*
*
* fixed setup token not response problem
; cli
jsr Init_IO
jsr RIN_Reset
brclr b_RXSETUP,USR0,URIN_Exit ; skip setup handler if not SETUP
brset b_Power,V_Dev_State,URIN_Exit
jsr TRAN_SETUP ; serve first SETUP transact
bset b_RXD0FR,UIR2 ; ready for next OUT/SETUP
jsr USB_Handler ; handle SETUP stage
brset b_ISTALL0,UCR3,M_SETUP_EXIT
brset b_Dir,V_bmReqType,M_SETUP_EXIT ; [5] OUT or no Data stage ?
lda V_wLength_L ; [2]
bne M_SETUP_EXIT
jsr TSP_IN_STATUS ; [3] 0-byte Data stage ?
M_Setup_Exit:
jmp URIN_Exit
*
* --- USB Resume Entry Point ---------------------------------------------
RIN_SYS:
jsr RIN_Reset
URIN_EXIT:
* --- Enable Interrupt --------------------------------------------------
cli
*
*
Wait_USB_Rst:
lda V_Dev_State
and #{(1<b_Power)|(1<b_Default)}
bne Main_Suspend
* Device is now not in POWER or Default stage
*
* --- Enable USB Interrupt Endpoints 1 ---------------------
jsr EP1N2_Init
*
* --- Start Suspend & Idle Timeout Timers ----------------------
MOV #%01010000,TSC0 ; CH0: OC mode, disable TCH0 pin,
; interrupt enable
MOV #%01010000,TSC1 ; CH1: OC mode, disable TCH1 pin,
; interrupt enable
*
jsr REF_TCH0 ; Add 3ms to TCH0H:L
jsr REF_TCH1 ; Add 4ms to TCH1H:L
*
* --- Force 1st Keyboard Scan ----------------------------------
MOV #KC_40ms,VC_40ms ; re-init 40ms timeout counter
*
MOV #{1<b_T40MS},VS_TIMER ; clr T4MS, Tsus flags,
; set T40MS flag(force 1st key scan)
*
*
*
.PAGE
* ------ Main Loop -------------------------------------------------------
UMAIN:
*
*
* --- Handle Keyboard Report to EndPoint 1 -------------------------------
MAIN_EP1:
brclr b_NIRpt0,V_Dev_Status,MEnd_IN_EP1 ; ~new kbd report pending ?
brclr b_TX1E,UCR1,Send_EP1_Anyway ; USB Tx buffer full ?
*
M_Chk_TOut1:
lda VC_EP_T_Out ; Check time out
bne MEnd_IN_EP1
*
Send_EP1_Anyway:
sei
jsr EP1_IN_Transact
*
mov V_IF0_Idle,VC_IF0_Idle ; refresh kbd. idle timeout cntr
bclr b_NIRpt0,V_Dev_Status ; No new keyboard report
cli
*
* ------------------------------------------------------------------------
MEnd_IN_EP1:
*
;Main_OUT_EP1:
; brclr b_NORpt0,V_Dev_Status,MEnd_EP1
; bclr b_NORpt0,V_Dev_Status
; jsr Update_LED
*
MEND_EP1:
*
Main_EP2:
* --- Handle Keyboard Report to EndPoint 2 ---------------------
* --- Handle Keyboard Report for ACPI key ---------------------
M_ACPI:
brclr b_ACPI_NRpt,V_HK_Status,MEnd_ACPI ; ACPI report ?
brclr b_TX2E,UCR2,Send_EP2_Anyway2 ; EP2 Tx Buff full ?
M_Chk_Tout3:
lda VC_EP_T_OUT ; Check if packet waits for 120ms?
; beq SEND_EP2_ANYWAY2 ; Send out anyway if time out.
bne MEnd_ACPI
*
Send_EP2_Anyway2:
sei
mov #K_ACPI_Rpt_ID,V_IF1_Rpt_ID ; set the report ID
jsr EP2_IN_TRANSACT ; push ACPI report to Epnt 2
*
mov V_IF1R1_Idle,VC_IF1R1_Idle ; refresh ACPI idle timeout cntr
*
bclr b_ACPI_NRpt,V_HK_Status ; clear new ACPI report flag
cli
; bra MEND_ACPI
* ------------------------------------------------------------------------
MEnd_ACPI:
*
*
* --- Handle Keyboard Report for HOT KEYs -------------------------
M_HOTK:
brclr b_HK_NRpt,V_HK_Status,MEnd_HotK
brclr b_TX2E,UCR2,Send_EP2_Anyway3 ; EP2 Tx Buff full ?
; -----------------------------------------
M_Chk_TOut4:
lda VC_EP_T_OUT ; Check if packet waits for 120ms?
; beq SEND_EP2_ANYWAY3 ; Send out anyway if time out.
bne Send_EP2_Anyway3
SEND_EP2_ANYWAY3:
sei
mov #K_MMK_Rpt_ID,V_IF1_RPT_ID ; Set the Report ID
jsr EP2_IN_TRANSACT ; push kbd report to Epnt 2
*
mov V_IF1R2_Idle,VC_IF1R2_Idle ; refresh kbd. idle timeout cntr
*
bclr b_HK_NRPT,V_HK_Status ; clear new kbd report flag
cli
; bra MEnd_HotK
*
MEND_HotK:
*
*
*
*
*
* --- Handle 40ms Time Tick ----------------------------------------------
UM_40MS:
brclr b_T40ms,VS_TIMER,UMEND_40MS ; 40ms time tick detected ?
bclr b_T40ms,VS_TIMER
*
* --- Scan Key Matrix ------------------------------------------
jsr UScan_MTX ; scan key matrix
*
* --- Eliminate Ghost Keys -------------------------------------
jsr Ghost_Key ; detect ghost keys
*
* --- Handle New Key Matrix Scan -------------------------------
jsr UScan_Hdlr ; handle new key scan result
*
* ------------------------------------------------------------------------
UMEND_40MS:
*
*
* --- Handle Device Suspend/Resume ---------------------------------------
MAIN_SUSPEND:
brset b_Tsus,VS_TIMER,MAIN_SUSPEND1 ; suspend timeout ?
jmp MSus_Exit ; not suspend
MAIN_SUSPEND1:
*
* --- Prepare Remote Wakeup ------------------------------------
*
bset b_IMASKK,KBSCR ; disable kbd. interrupt
bset b_ACKK,KBSCR ; clear the keyboard int. flag
*
brclr b_RWakeup,V_Dev_Status,MSUS_DEVOFF ; remote wakeup disabled
MSUS_DEVON:
*
MOV #%00000100,KBSCR ; enable kbd. interrupt
*
* --- Bring USB Module to Suspend Mode -------------------------
MSUS_DEVOFF:
MOV #%00100010,TSC ; disable TOF int., stop TIM
MOV #%00010000,TSC0 ; disable CH0F int.
MOV #%00010000,TSC1 ; disable CH1F int.
*
*
MOV #%00011010,PTE ; force low Column 16,17
MOV #%00000111,DDRE ; force high unsed pins
*
MOV #%00000001,POC ; Disable PortA pullup
clr PTB ; force low Column 0-7
MOV #%11111111,DDRB
*
clr PTC ; force low Column 8-15
MOV #%11111111,DDRC
*
MOV #%11111111,PTD ; force high unsed pins
MOV #%11111111,DDRD ; turn off LEDs
*
*
*
*
* --- Bring MCU to STOP mode ------------------------------------
*
sei
bset b_RESUMFR,UIR2 ; reset resume flag
bset b_SUSPND,UIR0 ; set USB module to suspend mode
bstop:
nop
nop
nop
STOP
astop:
*
bclr b_Suspnd,UIR0
clra
dbnza $ ; wait for USB reset
sei
bset b_Suspnd,UIR0
nop ; ensure RSME interrupt is handled
*
*
Wait_End_Resume:
nop
lda UIR1
brset b_RESUMF,UIR1,MSUS_RESUME ; ~resume signal from HOST?
nop
lda V_Dev_State
and #{(1<b_Power)|(1<b_Default)}
bne MSUS_RESUME
; in power state
brclr b_RWakeup,V_Dev_Status,MSUS_RESUME ;
*
*
*
* --- Handle Remote Wakeup --------------------------------------
MSUS_RWAKEUP:
*
* --- Delay 5ms ---------------------------
* Check idle state for 5ms before sending resume signal to host
* "USB spec v1.1 s.7.1.7.5 Resume: para.3"
*
MSUS_D5MS:
MOV #%00000010,TSC ; TIM clk - CPU clk / 4,
; TOF interrupt disable
*
MOV #{K_N5ms/256},TMODH ; set TIM overflow interval
MOV #{K_N5ms%256},TMODL ; (must write high byte first)
*
bset b_TRST,TSC ; reset TIM counter
bclr b_TOF,TSC ; clear TOF flag
MSUS_WD5MS:
brset b_RESUMF,UIR1,MSUS_RESUME ; ~resume signal from HOST?
nop
brclr b_TOF,TSC,MSUS_WD5MS ; delay 5ms
*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -