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

📄 lite_frm.asm

📁 mcs51,2051,x86系列MCU
💻 ASM
📖 第 1 页 / 共 4 页
字号:
 File: lite_frm.asm

;   Universal Serial Bus 930 Test firmware
;   Lite Version

;        The Software is provided "AS IS."
;
;        LIMITATION OF LIABILITY:    NEITHER INTEL NOR ITS VENDORS OR AGENTS
;        SHALL BE LIABLE FOR ANY LOSS OF PROFITS, LOSS OF USE, LOSS OF DATA,
;        INTERRUPTION OF BUSINESS, NOR FOR INDIRECT, SPECIAL, INCIDENTAL OR
;        CONSEQUENTIAL DAMAGES OF ANY KIND WHETHER UNDER THIS AGREEMENT OR
;        OTHERWISE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
;
;        While we have made every attempt to completely test this code, we request that
;        you personally test it completely prior to actual inclusion in your own projects.
;        This code requires conversion for use with the 82930AX Microcontroller.

INCLUDE "82930.inc"
INCLUDE "defs.inc"
INCLUDE "ONE_OH.INC"


USE_RISM        equ     1h
FIFO_SIZE       equ     008h
GET_COMMAND     equ     080h

SETUP_PHASE     equ     000h
DATA_PHASE      equ     001h
STATUS_PHASE    equ     002h

EP0_MAX_PACKET_SIZE     equ      08h
NULL_DATA_PACKET        equ     000h

EPINDEX  equ 77h

extern GetClassDeviceCommand:CODE
extern GetClassOtherCommand:CODE
extern SetClassDeviceCommand:CODE
extern SetClassOtherCommand:CODE

;(SPR)
extern SEND_KBD_REPORT_EP0:CODE
extern SEND_KBD_REPORT_EP2:CODE
extern SEND_MOUSE_REPORT:CODE
extern DONGLE_INITIALIZATION:CODE
extern SET_LED_STATUS:CODE

INCLUDE externs.inc
;(SPR)

;xdef bRequest
;xdef wValue
;xdef wIndex

;DEFINE CCB_SEGMENT, SPACE=CODE, ORG=FFfff8H
DEFINE CCB_SEGMENT, SPACE=CODE, ORG=FF7ff8H
SEGMENT CCB_SEGMENT
       db 0D0h       ;Original Binary Mode-Paged Mode
       db 097h

;----------------------------------------------------
;- Reset Segment is ORGed at 00, but the linker will
;- Place the rest of the signigiant figures
;----------------------------------------------------

IF USE_RISM == 1
DEFINE RESET_SEGMENT, SPACE=CODE, ORG=004000H
SEGMENT RESET_SEGMENT
        ljmp    main

DEFINE EP0_SEGMENT, SPACE=CODE, ORG=004043H
SEGMENT EP0_SEGMENT
        ljmp    FUNCTION_ISR

DEFINE EP1_SEGMENT, SPACE=CODE, ORG=00404BH
SEGMENT EP1_SEGMENT
        ljmp    FUNCTION_ISR

DEFINE EP2_SEGMENT, SPACE=CODE, ORG=004053H
SEGMENT EP2_SEGMENT
        ljmp    FUNCTION_ISR

DEFINE EP3_SEGMENT, SPACE=CODE, ORG=00405BH
SEGMENT EP3_SEGMENT
        ljmp    FUNCTION_ISR

ELSE

DEFINE RESET_SEGMENT, SPACE=CODE, ORG=FF0000H
SEGMENT RESET_SEGMENT

        ljmp    main

DEFINE EP0_SEGMENT, SPACE=CODE, ORG=FF0043H
SEGMENT EP0_SEGMENT
        ljmp    FUNCTION_ISR

DEFINE EP1_SEGMENT, SPACE=CODE, ORG=FF004BH
SEGMENT EP1_SEGMENT
        ljmp    FUNCTION_ISR

DEFINE EP2_SEGMENT, SPACE=CODE, ORG=FF0053H
SEGMENT EP2_SEGMENT
        ljmp    FUNCTION_ISR

DEFINE EP3_SEGMENT, SPACE=CODE, ORG=FF005BH
SEGMENT EP3_SEGMENT
        ljmp    FUNCTION_ISR

ENDIF


;----------------------------------------------------
;- Main Segment is ORGed at 100, but the linker will
;- Place the rest of the signigiant figures
;----------------------------------------------------
DEFINE CODE_SEGMENT, SPACE=CODE, ORG=004080H
;DEFINE CODE_SEGMENT, SPACE=CODE, ORG=FF0080H
SEGMENT CODE_SEGMENT

main:

;        mov     IE0, #00h
        mov     IE_USB, #00h               ; Disable Endpoint interrupts
        mov     SBIE,   #00h               ; IE_USB = IE1

        mov     SP,     #00h
        mov     SPH,    #05h               ; Set the stack to start @ 00:0500h

        mov     P1,     #025h
;       mov     DPXL,   #0ffh              ; Set DPXL to point at the FLASH device
                                           ; to access constants

        lCall   INIT_VARIABLES             ; Initialize the RAM space as required
        lCall   INIT_USB                   ; Initialize the USB subsystem

        orl     SBIE,   #03h               ; IE_USB = IE1
        orl     IE_USB, #01h               ; Enable EP0 interrupts
;(SPR)
        lcall   DONGLE_INITIALIZATION
;(SPR)

        ljmp    ActiveLoop                 ; Jump over the ISR stubs to the main loop.


COMMENT *------------------------------------------------------------
ISR Registers
IF the user makes this into an ISR, they will need to save certain registers
upon entry into this code.  The firmware has been written such that the
only registers which are modified in this code are A, R0, R1 & EPINDEX.
While DPX is used within the code, it is saved locally only when needed.
This will allow the ISR to run slightly faster.
--------------------------------------------------------------------*

COMMENT *------------------------------------------------------------
Function name     : ActiveLoop
Brief Description : Monitors RX and TX on all EPs. Additionally checks
                  : whether any mouse data is available and if the same
                  : can be sent back to the host.
Regs preserved    : No reg. is saved
--------------------------------------------------------------------*
SCOPE

ActiveLoop:

;------------------------------------------------------------------
;-- Heart Beat
;------------------------------------------------------------------
        mov     A,      SOFH
        anl     A,      #07h
        mov     P1,     A

        mov     WR0,    Heart1
        inc     WR0,    #1
        mov     Heart1, WR0

        cmp     WR0,    #7FFFh
        jl      ClearBit
        setb    P1.3
        jmp     EndofHeart
ClearBit:
        clr     P1.3
EndofHeart:
        jmp     ActiveLoop
;----------------------------------------------------------------
;-- FUNCTION ISR ROUTINE
;----------------------------------------------------------------

FUNCTION_ISR:
         push   ACC
         push   B

ProcessEndpoints:

;----------------------------------------------------------------
;-- Check the function endpoints first.
;----------------------------------------------------------------
F_EP0_RX:
        jnb     FRXD0,  F_EP0_TX

        lCall   ProcessOutToken            ; 82930 has received a packet from HC

F_EP0_TX:
        jnb     FTXD0, F_EP2_TX
        lCall   ProcessInToken             ; 82930 has sent a packet to HC


;(SPR)
F_EP2_TX:
        jnb     FTXD2, F_EP3_TX
        lcall   SEND_KBD_REPORT_EP2

F_EP3_TX:
        jnb     FTXD3, H_EP0_RX
        lcall   SEND_MOUSE_REPORT
;(SPR)


H_EP0_RX:

H_EP0_TX:

        pop     B
        pop     ACC

;----------------------------------------------------------------
; IF THIS IS INTERRUPT DRIVEN, UN-COMMENT THE RETI command below.
;----------------------------------------------------------------
        reti

        ljmp    ActiveLoop


COMMENT *------------------------------------------------------------
Function name     : ProcessOutToken
Brief Description : Services all OUTs on EP0.
Regs preserved    : No reg. is saved
--------------------------------------------------------------------*
SCOPE
ProcessOutToken:
        anl     SBI,   #EP0_RX_CLR                      ; Clear the interrupt bit.

        mov     A,     gbSetupSeqRX                     ; Get the State we are in
        cjne    A,     #SETUP_PHASE, CheckOutStatusPhase  ; Is this a setup phase??

        lCall   SetupReceived
        orl     RXCON0, #10h
;        setb    RXFFRC0                                  ; Update receive FIFO state

        clr     RXSETUP0

        jmp     ReturnProcessOutToken

CheckOutStatusPhase:
        cjne    A,     #STATUS_PHASE, CheckDataPhase   ; Is this the status phase of a "GET"
                                                         ; command?


        setb    RXFFRC0                                  ; Update receive FIFO state
        setb    TXCLR0                                   ; Flush the Transmit FIFOS in case
                                                         ; a null packet is still left.

        mov     A,      #SETUP_PHASE                     ; Update the state machine-Expect
                                                         ; a setup packet
        mov     gbSetupSeqRX, A
        mov     gbSetupSeqTX, A
        jmp     ReturnProcessOutToken

CheckDataPhase:
        cjne    A,     #DATA_PHASE, ReturnProcessOutToken ; Are we processing a Control Write,
                                                         ; i.e. Set Descr...
;  Code that reached here is part of a datastage.
;  The user needs to call a routine that reads the data out of the FIFO
;  does what they want with it and then returns here.
;  If this was the only/last packet of the data stage then the
;  user needs to write a null packet to the TX FIFO to arm the status
;  stage.

        CALL   SetReportRequestWithData  ; This is the only time we have a data
                                         ; stage.  If more than one command used
                                         ; we will need to compare the command here.
        mov    TXCNT0, #0                ; Status stage.
        setb   EPCON0.1


ReturnProcessOutToken:
        Ret

COMMENT *------------------------------------------------------------
Function name     : SetupReceived
Brief Description : Service all Setup Tokens recd. on EP0
Regs preserved    : No reg. is saved
--------------------------------------------------------------------*
SCOPE
SetupReceived:
        mov     A,     RXCNT0                   ; Get the no. of bytes
        clr     CY
        subb    A,     #SETUP_PACKET_LENGTH
        JNZ     ReturnSetup                      ; If less than 8 bytes recd.
                                                 ; Return

                                                 ; Since buffer will reside within the
                                                 ; the first 255 bytes, I can use
                                                 ; register indirect addressing
       ; Move FIFO to command buffer.
       ; Notice byte swapping of word fields
       ; For Word Fields make USB Little Endian words->'251 Big Endian words

       mov      COMMAND_BUFFER,   RXDAT0         ; bmRequestType
       mov      COMMAND_BUFFER+1, RXDAT0         ; bRequest
       mov      COMMAND_BUFFER+3, RXDAT0         ; wValue LSB
       mov      COMMAND_BUFFER+2, RXDAT0         ; wValue MSB
       mov      COMMAND_BUFFER+5, RXDAT0         ; wIndex LSB
       mov      COMMAND_BUFFER+4, RXDAT0         ; wIndex MSB
       mov      COMMAND_BUFFER+7, RXDAT0         ; wLength LSB
       mov      COMMAND_BUFFER+6, RXDAT0         ; wLength MSB

       push     DPX                              ; Processing the jump table will
                                                 ; corrupt DPX.  Save it here
       lCall    ProcessSetup
       pop      DPX                              ; Restore DPX
ReturnSetup:
        Ret

COMMENT *------------------------------------------------------------
Function name     : ProcessSetup
Brief Description : Process a Setup token recd. on EP0. The following
                  : code compresses the 8 byte bmRequestValue in 4 1/2
                  : bits by removing bits 2,3 & 4.
                  : THIS FIRMWARE IS ASSUMES BITS 2,3 & 4 are zero!!!!
                  : By compressing the byte down, we limit the size
                  : of the jump table.
Regs preserved    : No reg. is saved
--------------------------------------------------------------------*
SCOPE
ProcessSetup:

        ; Place bmRequestType in the following order and then do jump table
        ; on it.
        ; xx65107x
        ; if bits 65 == 11, Reserved = Error
        ; Unless you have time, don't spend a lot of time tracing the algorythm
        ; It's not fancy but it works.  If you don't understand it go ask someone for a
        ; a quarter.

        mov     A,      bmRequestType
        anl     A,      #0E3h                    ; Clear out bits 2,3,4 since
                                                 ; we don't need these
        RL      A                                ; Put bits 1,0,& 7 in place
        RL      A

CheckBit6:                                      ; 6 is in bit 0 position,
        jnb     ACC.0,  CheckBit5               ; Convert it to bit 5 position
        setb    ACC.5
CheckBit5:                                      ; Bit 5 is currently at 7 position
        jnb     ACC.7,  CheckValidType          ; Convert it to bit 4 position
        setb    ACC.4

CheckValidType:
        jnb     ACC.5,  GoodCommand             ; If this bit (6) is clear we know
                                                 ; it's a valid value
        jb      ACC.4,  ReservedCommand         ; Bit (6) was set, if bit 5 is set it's
                                                 ; a reserved command.
        jmp     GoodCommand

ReservedCommand:
        orl     EPCON0, #0C0h                     ; Stall EP0.
        ret



GoodCommand:
        anl     A, #1Fh
        mov     DPTR,   #bmRequestJumpTable
        mov     DPXL,   #LOW HIGH16(GoodCommand)    ; Get Page of Jump Table
        jmp     @A+DPTR                             ; Used because I use RISM sometimes
                                                    ; which places code in RAM

bmRequestJumpTable:
        AJMP    StandardSetDeviceCommand
        AJMP    StandardGetDeviceCommand
        AJMP    StandardSetInterfaceCommand
        AJMP    StandardGetInterfaceCommand
        AJMP    StandardSetEndpointCommand
        AJMP    StandardGetEndpointCommand
        AJMP    StandardSetOtherCommand
        AJMP    StandardGetOtherCommand

        AJMP    ClassSetDeviceCommand
        AJMP    ClassGetDeviceCommand
        AJMP    ClassSetInterfaceCommand
        AJMP    ClassGetInterfaceCommand
        AJMP    ClassSetEndpointCommand
        AJMP    ClassGetEndpointCommand
        AJMP    ClassSetOtherCommand
        AJMP    ClassGetOtherCommand

        AJMP    VendorSetDeviceCommand
        AJMP    VendorGetDeviceCommand
        AJMP    VendorSetInterfaceCommand

⌨️ 快捷键说明

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