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

📄 lite_frm.asm

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

CheckSetIdleRequest:
     mov   A, bRequest
     cjne  A, #00Ah, CheckSetProtocolRequest   ;0A = Set Idle Request
SetIdleRequest:
     mov   A, wIndex+1                          ; Endpoint 2 check. Mouse
     cjne  A, #002, ExitClassSetEndpointCommand ; (EP3) needs no IDLE.
                                                ; It already acts like in
                                                ; IDLE mode
     mov   A, wValue+1                          ; Report ID check.
     cjne  A, #001, ExitClassSetEndpointCommand ; 01 = KBD

     mov   R0, wValue
     cjne  R0, #0, SET_TIMED_IDLE

INDEFINITE_IDLE:
     clr   SBIE.4                         ; Disable TXD2 interrupt
                                          ; FIFO now filled only by data events or timer
     setb  TXCON2.7                       ; flush FIFO for TIMED & INDEF

     mov   IDLE_MODE, #1                  ; Set for check in kbdisr.asm
                                          ; 1=INDEF; 2=TIMED
     jmp   ExitClassSetEndpointCommand

SET_TIMED_IDLE:
     cmp   R0, gEP2_bInterval             ; exit if Duration <= Poll Rate
     jg    SET_UP_DELAY
     setb  SBIE.4                         ; Reenables TXD2 int so it can
                                          ; control FIFO writes again
     jmp   ExitClassSetEndpointCommand

SET_UP_DELAY:
     clr   SBIE.4                         ; Disable TXD2 interrupt
                                          ; FIFO now filled only by data events or timer
     setb  TXCON2.7                       ; flush FIFO for TIMED & INDEF

     mov   IDLE_MODE, #2                  ; Set for check in kbdisr.asm
     mov   IDLE_RATE, wValue

     clr   TMOD.3                         ; Sets timer 0 to be 16-bit
     clr   TMOD.2
     clr   TMOD.1
     setb  TMOD.0

     mov   TH0, #0E0h                     ; E0BF provides an OVFL int
     mov   TL0, #0BFh                     ; every 4ms.
     setb  TCON.4                         ; Starts timer 0
     setb  IE0.1                          ; Enables OVFL interrupt

     jmp   ExitClassSetEndpointCommand

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

CheckSetProtocolRequest:
     mov   A, bRequest
     cjne  A, #00Bh, ExitClassSetEndpointCommand  ; 0B = Set Protocol Request
SetProtocolRequest:
     mov   USB_PROTOCOL, wValue+1                 ; 00=Boot; 01=Item
     jmp   ExitClassSetEndpointCommand

ExitClassSetEndpointCommand:
      ret
;-------------------------------------------------------------
; We now have the data and can actually do stuff with it.
; When in data phase, it will automatically come to here.
; This code will then validate the contents of the SETUP Packet
; and read the data out of the FIFO and
; process the data.

SetReportRequestWithData:
     mov   A, wValue
     cjne  A, #002h, EXIT_SET_REPORT       ; If it is not an "output"
                                           ; report then exit
     mov   A, wValue+1
     cjne  A, #001h, EXIT_SET_REPORT       ; If not a "01" report ID (for kbd)
                                           ; then exit
     mov   A, wIndex+1
     cjne  A, #003h, EXIT_SET_REPORT       ; If not for EP2 then exit

     mov   A, wLength+1
     cjne  A, #001h, EXIT_SET_REPORT       ; If not 1 Byte only then exit


     jb   RXFLG0.6, GetReportData
     jb   RXFLG0.7, GetReportData
                             ; No data, bad...VEry Badddd


GetReportData:
     mov   A, RXCNT0
;     cjne  ACC, #01,  Wrong_size

     mov   A, RXDAT0
     rl    A                 ; Need to change LED bits for kbd
                             ; USB: b2=ScrollLock;b1=CapsLock;b0=NumLock
                             ; KBD: b2=CapsLock;  b1=Num Lock;b0=ScrollLock
     jb    ACC.3, SET_SCROLL_LOCK
     anl   A, #006h
     mov   LED_STATUS, A
     lcall SET_LED_STATUS
     jmp   EXIT_SET_REPORT

SET_SCROLL_LOCK:
     setb  ACC.0
     anl   A, #007h
     mov   LED_STATUS, A
     lcall SET_LED_STATUS
     jmp   EXIT_SET_REPORT

EXIT_SET_REPORT:
     setb  RXCON0.4
     jmp   ExitClassSetEndpointCommand

COMMENT *------------------------------------------------------------
Function name     : ClassGetEndpointCommand:
Brief Description : Handles the three main class "get" requests:
                         - Get Report Request
                         - Get Idle Request
                         - Get Protocol Request
Regs preserved    : No reg. is saved
--------------------------------------------------------------------*
SCOPE
ClassGetEndpointCommand:
     mov   A, bRequest
     cjne  A, #001h, CheckGetIdleRequest          ;01 = Get Report Request
GetReportRequest:
     mov   A, wValue
     cjne  A, #001h, ExitClassGetEndpointCommand  ; If it is not an "input"
                                                  ; report then exit

                   ; Do I need to check the current protocol here?
                   ; ie- can the system request a report when in boot
                   ;     mode?

     mov   A, wValue+1
     cjne  A, #001h, ExitClassGetEndpointCommand  ; If not a "01" report ID (for kbd)
     mov   REPORT_ID, #1                          ; then exit

     mov   A, wIndex+1
     cjne  A, #002h, ExitClassGetEndpointCommand  ; If not for EP2 then exit

     mov   A, wLength+1
     cjne  A, #008h, ExitClassGetEndpointCommand  ; If not 8 Bytes only then exit

     setb  EPCON0.1

     lcall SEND_KBD_REPORT_EP0
     jmp   ExitClassGetEndpointCommand

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

CheckGetIdleRequest:
     mov   A, bRequest
     cjne  A, #002h, CheckGetProtocolRequest   ;02 = Get Idle Request

GetIdleRequest:
     mov   A, wValue+1                    ; Check Report ID first (01=KBD)
     cjne  A, #001h, ExitClassGetEndpointCommand

     mov   A, wIndex+1                    ; Check Endpoint
     cjne  A, #002h, ExitClassGetEndpointCommand

     mov   A, wLength+1                   ; Check size (should be 1)
     cjne  A, #001h, ExitClassGetEndpointCommand

     setb  EPCON0.1

     setb  TXCON0.7                       ; Flushes TXFIFO0
     mov   R0, IDLE_RATE                  ; Write value to TXFIFO0
     mov   TXDAT0, R0
     mov   TXCNT0, #01h

     jmp   ExitClassGetEndpointCommand

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

CheckGetProtocolRequest:
     mov   A, bRequest
     cjne  A, #003h, ExitClassGetEndpointCommand  ;03 = Get Protocol Request
GetProtocolRequest:
     mov   A, wValue+1
     cjne  A, #0, ExitClassGetEndpointCommand     ; Exit if not 0

     mov   A, wIndex+1
     cjne  A, #002h, ExitClassGetEndpointCommand  ; Exit if not for EP2

     mov   A, wLength+1
     cjne  A, #001h, ExitClassGetEndpointCommand  ; Exit if not 1 byte only

     setb  EPCON0.1

     setb  TXCON0.7                               ; Flushes TXFIFO0
     mov   R0, USB_PROTOCOL                       ; Write value to TXFIFO0
     mov   TXDAT0, R0
     mov   TXCNT0, #01h

     jmp   ExitClassGetEndpointCommand

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

ExitClassGetEndpointCommand:
     ret

;-------------------------------------------------------------------
;(SPR)


VendorSetDeviceCommand:
VendorGetDeviceCommand:
VendorSetInterfaceCommand:
VendorGetInterfaceCommand:
VendorSetEndpointCommand:
VendorGetEndpointCommand:
VendorSetOtherCommand:
VendorGetOtherCommand:



COMMENT *------------------------------------------------------------
Function name     : LoadControlTXFifo
Brief Description : Copy data from the location pointed to by
                  : the three byte value gbFControlBufferLocation.
                  : The number of bytes left to transmit are stored in
                  : gbFControlBufferBytesLeft.  If zero bytes are left then
                  : a Null packet is loaded even if the null/short packet is
                  : not needed.
Regs preserved    : No reg. is saved
--------------------------------------------------------------------*
SCOPE
LoadControlTXFifo:
        push    R0                                  ; Need to save this register
        push    DPX
        mov     DPXL,   gbFControlBufferLocation    ; Get location of data to send.
        mov     DPH,    gbFControlBufferLocation+1
        mov     DPL,    gbFControlBufferLocation+2


        mov     A,      wLength                     ; First check to see if any data is availble
        orl     A,      wLength+1                   ; to send.
        jnz     CntlDataAvail

        mov     R0,     #0                          ; if there is data do normal flow
        ljmp    ControlArmTx                       ; if none, do null packet

CntlDataAvail
        mov     R0,     #0                          ; Number of bytes in FIFO- Awlays <=16
        mov     A,      DPXL
        JZ      DataInRAM

;-----------------------------------------------
; Data is in ROM, use instrcutions to pull from ROM.
;-----------------------------------------------
DataInROM:
        mov     A,      #00h
        movc    A,      @A+DPTR                     ; Get Data to transmit
        mov     TXDAT0, A
        inc     DPTR
        inc     R0                                  ; Increment the number of bytes in FIFO
        djnz    wLength+1, ROMCheckMaxPacket        ; If not zero, the continue.

ROMCheckUpper1:
        mov     A,       wLength                    ; If upper byte of wLength is also zero, buffer is empty.
        jz      ControlTxUpd                       ; Are we done with the buffer
        dec     A                                   ; If it's not zero dec. the upper byte as well.
        mov     wLength, A                          ; And store it.

ROMCheckMaxPacket:
        cjne    R0,      #EP0_MAX_PACKET_SIZE, DataInROM    ; Loop until FIFO is Full
        jmp     ControlTxUpd                       ; Done with this FIFO.


;-----------------------------------------------
; Data is in RAM, use instrcutions to pull from RAM.
;-----------------------------------------------

DataInRAM:


        movx    A,      @DPTR                       ; Get Data to transmit
        mov     TXDAT0, A
        inc     DPTR
        inc     R0                                  ; Increment the number of bytes in FIFO
        djnz    wLength+1, RAMCheckMaxPacket        ; If not zero, the continue.

RAMCheckUpper1:
        mov     A,       wLength                    ; If upper byte of wLength is also zero, buffer is empty.
        jz      ControlTxUpd                       ; Are we done with the buffer
        dec     A                                   ; If it's not zero dec. the upper byte as well.
        mov     wLength, A                          ; And store it.

RAMCheckMaxPacket:
        cjne    R0,      #EP0_MAX_PACKET_SIZE, DataInRAM    ; Loop until FIFO is Full


ControlTxUpd
        mov     gbFControlBufferLocation+1, DPH      ; Update read pointers.
        mov     gbFControlBufferLocation+2, DPL

ControlArmTx:
        mov     TXCNT0, R0                          ; Write count into TXCNT register
        setb    TXOE0                               ; Enable data transmit
ReturnLoadCntl:
        pop     DPX
        pop     R0
        Ret

COMMENT *------------------------------------------------------------
Function name     : ProcessInToken
Brief Description : Services all INs on EP0.
Regs preserved    : No reg. is saved
--------------------------------------------------------------------*
SCOPE
ProcessInToken:
        anl     SBI,    #EP0_TX_CLR                 ; clear the interrupt bit
        mov     A,      gbSetupSeqTX                ; read state variable

CheckInStatusPhase:
        cjne    A,      #STATUS_PHASE,SendDataBack ; Should this be the end to
                                                    ; a setup sequence


StatusPhaseDone:
        lCall   CompleteSetCommand

        clr     TXOE0                               ; Status phase completed. NAK any more INs.

        mov     gbSetupSeqTX, #SETUP_PHASE          ; Set state var. to expect setup.
        mov     gbSetupSeqRX, #SETUP_PHASE

        jmp     ReturnProcessIn

SendDataBack:
        cjne    A,      #DATA_PHASE, ReturnProcessIn
        call    LoadControlTXFifo

ReturnProcessIn:
        Ret

COMMENT *------------------------------------------------------------
Function name     : CompleteSetCommand
Brief Description : Called after the status phase of a set command has
                  : completed.  This is called everytime there is a
                  : xmit status stage.
Regs preserved    : No reg. is saved
--------------------------------------------------------------------*
SCOPE
CompleteSetCommand:
        mov     A,      bRequest                    ; If this was not a Std. Set
                                                    ; command then return.

        cjne    A,      #SET_ADDRESS, CheckNextCommand
   ;------------------------------------------------
   ;- SET ADDRESS
   ;------------------------------------------------
DoSetAddress:
        mov     FADDR,  wValue+1                    ; Set to new address
        jmp     ReturnCompleteSet

CheckNextCommand:
ReturnCompleteSet:
        ret

COMMENT *------------------------------------------------------------
Function name     : SetConfiguration
Brief Description : Enables endpoint 1, Initializes the UARt.
Regs preserved    : No reg. is saved
--------------------------------------------------------------------*
SCOPE
;SetConfiguration:
;(SPR)  - Took out all timer2 baud stuff & serial port init
;         (done already in "main" section)

;ReturnSetConfig:
;        Ret


COMMENT *------------------------------------------------------------
Function name     : ProcessClassGetCommand
Brief Description : Process Set commands recd. from the HOST
Regs preserved    : No reg. is saved
--------------------------------------------------------------------*
SCOPE
ProcessClassGetCommand:
         mov    A, wLength                         ; Find out if this
         clr    CY
         subb   A, #04
         call   GetFunctionClassCommand
         ret


GetFunctionClassCommand:
         ret
COMMENT *------------------------------------------------------------
Function name     : GetOUTData
Brief Description : takes data from the FIFO, Puts it in memory and
                  : then updates writes it to the fifo.
Regs preserved    : No reg. is saved
--------------------------------------------------------------------*
;SCOPE
;GetOUTData:

⌨️ 快捷键说明

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