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

📄 ax_firm.asm

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



DoSuspend:
         mov   A, P1
         anl   A, #0F0h
         orl   A, #06h
         mov   P1,A

;         setb  IDL
         setb  PD                       ; Set PD - Enter Suspend Mode.
         nop
         nop
         NOP
         NOP
         NOP

                                            ; Code execution stops here after PD.
RESUME_CODE:
         jb     GSUS, SUSPEND_LOOP       ;   If still suspended, (RWU Event) then goto top.
         clr    GRSM                     ; CLear Resume Flag
         clr    GSUS                     ; CLear GSUS Flag

ExitSuspendISR:
         pop   WR2
         pop   ACC
         pop   PSW1
         pop   PSW
         reti

;----------------------------------------------------------------
;FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
;FF                 FUNCTION ISR
;FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
;----------------------------------------------------------------
;COMMENT *------------------------------------------------------------
;Function name     : FUNCTION_ISR
;Brief Description : Service the FUNCTION_ISR Interrupt
;                  : This routine scans the interrupt pending bits in order
;                  : and branches to any routines that have pending interrupts.
;                  : After finishing the routine jumps back to the top of
;                  : the scanning loop to preserve interrupt priority.
;                  :
;                  : NOTE: The order of precidence is set by the order in which the
;                  : user places the checks.
;                  :
;Regs preserved    : Reg. A, B  & EPINDEX are saved
;--------------------------------------------------------------------*


FUNCTION_ISR:
         push   PSW
         push   PSW1
         push   ACC
         push   B
         push   EPINDEX


ProcessFunctionEndpoints:

;----------------------------------------------------------------
;-- NOTE: Priority of the check sequence determines priority.  --
;----------------------------------------------------------------

F_EP0:

        mov     A,   FIFLG                  ; First check to see if this is EP0 Command
        anl     A,   #03h                   ; As they require extra overhead. Mask off all but EP0 Interrupts
        jz      NonEp0ISR

                                            ;----------------------------------------------------------------
                                            ;-- Process the EP0 COmmand in the correct order
                                            ;----------------------------------------------------------------

                                            ; If this an EP0 command then we need to process TX & RX
                                            ; ISRs in the correct order if, for whatever reason they occurred
                                            ; back to back.  This happens in OHCI systems.
        mov     A, gbSetupSeqTX
        cjne    A, #SETUP_PHASE, CheckDataStatusStage
        sjmp    DoRxFirst                   ; If the current stage is Setup then check the RX First.
                                            ; as we are expecting a setup packet.
CheckDataStatusStage:
                                            ; Now check to see what stage the TX is in.
                                            ; If it is in the data stage then check it first.
                                            ; If it's in the status stage then check the RX first.

        cjne    A, #DATA_PHASE, DoRxFirst   ; If current TX stage a data stage->a control read
                                            ; and we should process TX before RX ISR

                                            ;----------------------------------------------------------------
                                            ;-- Process the TX FIFO first
                                            ;----------------------------------------------------------------

DoTxFirst:
F_EP0_TXA:
        jnb     FTXD0,  F_EP0_RXA
        mov     EPINDEX,#00
        lCall   ProcessInToken              ; 82930 has sent a packet to HC
        ljmp    ProcessFunctionEndpoints    ; Look at all Interrupt flags again

F_EP0_RXA:
        jnb     FRXD0,  NonEp0ISR
        mov     EPINDEX,#00
        lCall   ProcessOutToken             ; 82930 has received a packet from HC
        ljmp    ProcessFunctionEndpoints    ; Look at all Interrupt flags again

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

DoRxFirst:
                                            ;----------------------------------------------------------------
                                            ;-- Process the RX FIFO first
                                            ;----------------------------------------------------------------
F_EP0_RXB:
        jnb     FRXD0,  F_EP0_TXB
        mov     EPINDEX,#00
        lCall   ProcessOutToken             ; 82930 has received a packet from HC
        ljmp    ProcessFunctionEndpoints    ; Look at all Interrupt flags again

F_EP0_TXB:
        jnb     FTXD0,  NonEp0ISR
        mov     EPINDEX,#00
        lCall   ProcessInToken              ; 82930 has sent a packet to HC
        ljmp    ProcessFunctionEndpoints    ; Look at all Interrupt flags again


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

                                            ;----------------------------------------------------------------
                                            ;-- Process the Other EPs next
                                            ;----------------------------------------------------------------

NonEp0ISR:
F_EP1_TX:

        jnb     FTXD1,  F_EP1_RX
        mov     EPINDEX,#01

        lcall   Ep1TxLoopBack
        jb      RXFIF0, GetEp1RxData        ; If data is pending in the FIFOs go get it.
        jb      RXFIF1, GetEp1RxData        ; This is quicker than calling the routines.
        ljmp    F_EP1_RX                    ; Check the next one so we don't starve anything.
GetEp1RxData:
        lCall   Ep1RxLoopBack               ; 82930 has received a packet from HC

F_EP1_RX:
        jnb     FRXD1,  F_EP2_TX
        mov     EPINDEX,#01
        lCall   Ep1RxLoopBack               ; 82930 has received a packet from HC
        lcall   Ep1TxLoopBack


F_EP2_TX:

        jnb     FTXD2,  F_EP2_RX
        mov     EPINDEX,#02

        lcall   Ep2TxLoopBack
        jb      RXFIF0, GetEp2RxData        ; If data is pending in the FIFOs go get it.
        jb      RXFIF1, GetEp2RxData        ; This is quicker than calling the routines.
        ljmp    F_EP2_RX                    ; Look at all Interrupt flags again
GetEp2RxData:
        lCall   Ep2RxLoopBack               ; 82930 has received a packet from HC


F_EP2_RX:
        jnb     FRXD2,  F_EP3_TX
        mov     EPINDEX,#02
        lCall   Ep2RxLoopBack               ; 82930 has received a packet from HC
        lcall   Ep2TxLoopBack

F_EP3_TX:
        jnb     FTXD3,  F_EP3_RX
        mov     EPINDEX,#03

        lcall   Ep3TxLoopBack
        jb      RXFIF0, GetEp3RxData        ; If data is pending in the FIFOs go get it.
        jb      RXFIF1, GetEp3RxData        ; This is quicker than calling the routines.
        ljmp    F_EP3_RX                    ; Look at all Interrupt flags again
GetEp3RxData:
        lCall   Ep3RxLoopBack               ; 82930 has received a packet from HC

F_EP3_RX:
        jnb     FRXD3,  EXIT_FUNCTION_ISR
        mov     EPINDEX,#03
        lCall   Ep3RxLoopBack               ; 82930 has received a packet from HC
        lcall   Ep3TxLoopBack

        mov     A, FIFLG                    ; Check to see if any other Interrupts are pending.
        jz      EXIT_FUNCTION_ISR
        ljmp    ProcessFunctionEndpoints    ; Look at all Interrupt flags again


EXIT_FUNCTION_ISR:
        pop     EPINDEX
        pop     B
        pop     ACC
        pop     PSW1
        pop     PSW
        reti

;----------------------------------------------------------------
;SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
;SS                 SOF ISR
;SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
;----------------------------------------------------------------
;COMMENT *------------------------------------------------------------
;Function name     : SOF_ISR
;Brief Description : Service the SOF_ISR Interrupt
;                  : This routine simply displays the upper three bytes of the
;                  : SOF in the lower three bits of the LEDs on P1.
;                  : It does not affect the other LEDS.  Very usefull
;                  : in determining when the function is receiveing SOFs
;Regs preserved    : Reg. A is saved
;--------------------------------------------------------------------*


SOF_ISR:
SOF_ISR1:
         push   PSW
         push   PSW1
         push    ACC
         jnb     ASOF,   ExitSofIsr         ; If this ASOF bit not set, the ISR could be a HUB.  Go Check.

SofIsocIsr:
                                            ;-----------------------------------------------------
                                            ; Update LEDs for the Heartbeat
                                            ;-----------------------------------------------------
        clr     ASOF


        mov     A,      P1                  ; Mask off lower three bits
        anl     A,      #0f8h
        mov     P1,     A

        mov     A,      SOFH                ; Put upper 3 bits of SOF in low 3 bits of P1
        anl     A,      #07h
        orl     P1,     A

ExitSofIsr:
        pop     ACC
        pop     PSW1
        pop     PSW

        reti






;COMMENT *------------------------------------------------------------
;Function name     : ProcessOutToken
;Brief Description : Services all OUTs on EP0.
;                  : This routine checks to see if this is an OUT token oor
;                  : SETUP token.  If a SETUP token then the Control COmmand
;                  : State machine is initilized to SETUP STAGE
;Regs preserved    : No reg. is saved
;--------------------------------------------------------------------*

ProcessOutToken:

        anl     FIFLG,   #EP0_RX_CLR        ; Clear the interrupt bit.
;        jmp     ProcCommand

ProcCommand:
        mov     A,     RXSTAT
        jnb     ACC.6, CheckOutStatusPhase  ; Is this a setup packet??



                                            ; Now Check for Data still in FIFO.
                                            ; If this is true then the function
                                            ; did not see the ACK form the host.
        mov     A,      TXFLG
        anl     A,      #0C0h
        jZ      NoEP0Error

        setb    TXCLR                       ; Flush the Transmit FIFOS in case
                                            ; a null packet is still left.

NoEP0Error:
                                            ; Check to see if the stall bit is set.
        mov     A, EPCON
        anl     A, #0C0h
        jz      NoEp0Stall
        anl     EPCON, #03Fh                ; Clear the stalls
        orl     TXSTAT, #88h                ; Set data toggle on TX ep0.
NoEp0Stall:
        lCall   SetupReceived


        sjmp    ReturnProcessOutToken

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

        setb    RXFFRC                      ; Update receive FIFO state
        mov     A,     #SETUP_PHASE         ; Update the state machine to
                                            ; expect a setup packet
        mov     gbSetupSeqRX, A
        mov     gbSetupSeqTX, A
        sjmp    ReturnProcessOutToken

            ;---------------------------------------------------------------
            ; -   Control Write Data Stage
            ;---------------------------------------------------------------

                ; If this is a control write command with a datastage then this
                ; routine will be called on all data stages of the control write.
                ; When all the data has been collected(Bytes received=wLength)
                ; the actual routine is called.  The size of data is limited to this
                ; buffer length.
                ; THE CALLING CODE MUST THEN CALL SetUpControlWriteStatusStage to allow
                ; the status stage to continue.  The user must NOT do this themselves.
                ; Later in the life of this code, other features will be added here.

⌨️ 快捷键说明

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