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

📄 usb_1_drv.asm

📁 详细的无线键盘,鼠标,无线桥 开发文档.包含电路原理图,电路板光汇文件.FIREWALL, 驱动程序等.有此文档,就可以完全直接生产出来无线键盘,鼠标,无线桥.整个一套完整的解决方案.
💻 ASM
📖 第 1 页 / 共 3 页
字号:

    OR     [USB_1_EP0DataToggle], 1 ; setup EP0 data toggle
    JMP    USB_1_LoadEndpoint          ;
;-----------------------------------------------------------------------------
;  FUNCTION NAME: USB_1_ControlReadDataStage
;
;  DESCRIPTION:   This routine processes the data stage of a control read.  It
;                 must be JUMPed to, not called.  It assumes a tranfer descriptor
;                 has been loaded into the driver USB_1_CurrentTD
;                 data structure.
;
;-----------------------------------------------------------------------------
 USB_1_ControlReadDataStage:
    JMP     USB_1_LoadEndpoint

;-----------------------------------------------------------------------------
;  FUNCTION NAME: USB_1_ControlReadStatusStage
;
;  DESCRIPTION:   This routine processes the status stage of a control read.  It
;                 must be JUMPed to, not called.  It handles short or 0 packet
;                 It assumes a tranfer descriptor has been loaded into the
;                 driver USB_1_CurrentTD data structure.
;
;-----------------------------------------------------------------------------
 USB_1_ControlReadStatusStage:
    MOV    A, [USB_1_LastSize]         ; Get the number of bytes from the last transfer
    ADD    [USB_1_TransferByteCount + 1], A ; Update the transfer byte count
    ADC    [USB_1_TransferByteCount], 0;
    MOV    A, USB_XFER_STATUS_ACK      ; Return a Status ACK Completion
    CALL   USB_1_UpdateStatusBlock
    MOV    [USB_1_TransferType], USB_TRANS_STATE_IDLE
    MOV    A, 0                        ; Count Register
    MOV    X, USB_MODE_STALL_IN_OUT
    JMP    USB_1_EP0_UPD_MODE_EXIT
;-----------------------------------------------------------------------------
;  FUNCTION NAME: USB_1_NoDataStageControlTransfer
;                 USB_1_InitNoDataStageControlTransfer
;
;  DESCRIPTION:   This routine processes the status stage of a no data control
;                 write.  It must be JUMPed to, not called.
;
;-----------------------------------------------------------------------------
 USB_1_NoDataStageControlTransfer:
 USB_1_InitNoDataStageControlTransfer:
    CALL    USB_1_InitializeStatusBlock

    MOV    [USB_1_TransferType], USB_TRANS_STATE_NO_DATA_CONTROL

    MOV    A, 0                        ; Count Register
    MOV    X, USB_MODE_STATUS_IN_ONLY
    JMP    USB_1_EP0_UPD_MODE_EXIT
;-----------------------------------------------------------------------------
;  FUNCTION NAME: USB_1_InitControlWrite
;
;  DESCRIPTION:   This routine initializes control write.  It must be JUMPed
;                 to, not called.  It assumes a tranfer descriptor has been loaded
;                 into the driver USB_1_CurrentTD data structure.
;
;-----------------------------------------------------------------------------
 USB_1_InitControlWrite:
    MOV     A, [USB_1_DataSource]      ; Need to make sure the destination is not ROM
    CMP     A, USB_DS_ROM
    JZ      USB_1_Not_Supported_Local_Drv

    CALL    USB_1_InitializeStatusBlock

    MOV    [USB_1_TransferType], USB_TRANS_STATE_CONTROL_WRITE

    OR     [USB_1_EP0DataToggle], 1 ; setup EP0 data toggle

    MOV    A, 0                        ; Count Register
    MOV    X, USB_MODE_ACK_OUT_STATUS_IN
    JMP    USB_1_EP0_UPD_MODE_EXIT
;-----------------------------------------------------------------------------
;  FUNCTION NAME: USB_1_ControlWriteDataStage
;
;  DESCRIPTION:   This routine processes the data stage of a control
;                 write.  It must be JUMPed to, not called.  It assumes a
;                 tranfer descriptor has been loaded into the driver
;                 USB_1_CurrentTD data structure.
;
;-----------------------------------------------------------------------------
 USB_1_ControlWriteDataStage:
    XOR    [USB_1_EP0DataToggle], 1    ; Update data toggle

    MOV    A,REG[USB_1_EP0CNT]         ; Get the count

    AND     A, 0x0F
    SUB     A, 2                       ; Count include the two byte checksum

    MOV     [USB_1_t2], A              ; Assume we have room to receive the whole packet

    MOV     A, 0
    CMP     A, [USB_1_TransferSize]    ; If the MSB has anything just use the count
    JNZ     .L1

    MOV     A, [USB_1_t2]
    CMP     A, [USB_1_TransferSize+1]  ;
    JZ      .L6
.L1:
    JC      .L6
    MOV     [USB_1_t2], [USB_1_TransferSize+1]

.L6:
    MOV     A, [USB_1_t2]
    SUB     [USB_1_TransferSize+1],A   ; Update the bytes remaining
    SBB     [USB_1_TransferSize], 0    ;

    ADD     [USB_1_TransferByteCount + 1], A ; Update the transfer byte count
    ADC     [USB_1_TransferByteCount], 0 ;

    MOV     X,0                        ; Start the index at 0

.RAM_COPY:
    MOV     A, REG[X+USB_1_EP0DATA]    ; Get the data
    MVI     [USB_1_DataPtr+1], A       ; Store the data, bump the destination

    INC     X                          ; Bump the destination offset
    MOV     A,X                        ; Are we done?
    CMP     A, [USB_1_t2]
    JC      .RAM_COPY                  ; Not done

    MOV    A, 0                        ; Count Register
    MOV    X, USB_MODE_ACK_OUT_STATUS_IN
    JMP    USB_1_EP0_UPD_MODE_EXIT

; Jump here on data toggle error
.error:
    MOV    [USB_1_TransferType], USB_TRANS_STATE_IDLE  ; This simply aborts the transfer
    MOV    A, 0                        ; Count Register
    MOV    X, USB_MODE_STALL_IN_OUT
    JMP    USB_1_EP0_UPD_MODE_EXIT
;-----------------------------------------------------------------------------
;  FUNCTION NAME: USB_1_ControlWriteStatusStage
;
;  DESCRIPTION:   This routine processes the status stage of a control
;                 write.  It must be JUMPed to, not called.  It assumes a
;                 tranfer descriptor has been loaded into the driver
;                 USB_1_CurrentTD data structure.
;
;-----------------------------------------------------------------------------
 USB_1_ControlWriteStatusStage:

    CMP    [set_output_report_flags], 1         ; This flag is set to 1 if we received the Set_Report(OUTPUT) for the LEDs.
    JNZ    .Done_Set_Report
    
.Output_Report:
    MOV    A, [USB_1_INTERFACE_0_OUT_RPT_DATA]  ; First byte in the output buffer has the LED status
    AND    A, 1Fh                               ; Support 5 LEDs        
    MOV     [_back_channel_buffer], A           ; Update the buffer with the LED status
    
    MOV    [set_output_report_flags], 0         ; Done with Set_Report (OUTPUT), clear flag
    JMP    .Done_Set_Report                     ; This flag may be used for the main apps to unload [back_channel_buffer] 
    
.Done_Set_Report:    

    MOV    A, USB_XFER_STATUS_ACK      ; Return a Status ACK Completion
    CALL   USB_1_UpdateStatusBlock
    MOV    [USB_1_TransferType], USB_TRANS_STATE_IDLE  ; The packet is done
    MOV    A, 0                        ; Count Register
    MOV    X, USB_MODE_STALL_IN_OUT
    JMP    USB_1_EP0_UPD_MODE_EXIT
;-----------------------------------------------------------------------------
;  FUNCTION NAME: USB_1_NoDataControlStatusStage
;
;  DESCRIPTION:   This routine processes the status stage of a control
;                 write.  It must be JUMPed to, not called.  It assumes a
;                 tranfer descriptor has been loaded into the driver
;                 USB_1_CurrentTD data structure.
;
;                 USB Device Addressing happens here because we can't change
;                 the SIE Address before the Status IN is received.
;
;-----------------------------------------------------------------------------
 USB_1_NoDataControlStatusStage:
    MOV     A, USB_XFER_STATUS_ACK     ; Return a Status ACK Completion
    CALL    USB_1_UpdateStatusBlock
    ; Dispatch to the proper handler
    CMP     [USB_1_fDataPending], USB_ADDRESS_CHANGE_PENDING
    JNZ     .L1

    ; USB ADDRESS CHANGE
    MOV     A, [USB_1_TransferBuffer]  ; Get the pending data

    OR      A, USB_ADDR_ENABLE         ; Set the enable bit
    MOV     REG[USB_1_ADDR], A         ; Update the SIE address
    JMP     .EXIT
.L1:

.EXIT:
    MOV     [USB_1_fDataPending], 0    ; Clear data pending

    MOV    A, 0                        ; Count Register
    MOV    X, USB_MODE_STATUS_IN_ONLY  ; Wait for the next SETUP
    JMP    USB_1_EP0_UPD_MODE_EXIT
;-----------------------------------------------------------------------------
;  FUNCTION NAME: USB_1_NoDataControlError
;
;  DESCRIPTION:   This routine handles the condition when we expected a
;                 status IN, but receive an OUT
;
;-----------------------------------------------------------------------------
 USB_1_NoDataControlError:
    MOV    A, USB_XFER_ERROR           ; Return Transaction Error
    CALL   USB_1_UpdateStatusBlock
    MOV    A, 0                        ; Count Register
    MOV    X, USB_MODE_STALL_IN_OUT    ; Set the mode register
    JMP    USB_1_EP0_UPD_MODE_EXIT
;-----------------------------------------------------------------------------
;  FUNCTION NAME: USB_1_LoadEndpoint
;
;  DESCRIPTION:  Load the endpoint buffer with the next data for the control
;                transfer.  It assumes a tranfer descriptor has been loaded
;                into the driver USB_1_CurrentTD data structure.
;
;-----------------------------------------------------------------------------
USB_1_LoadEndpoint:
    MOV     A, [USB_1_LastSize]        ; Get the number of bytes from the last transfer
    ADD     [USB_1_TransferByteCount + 1], A ; Update the transfer byte count
    ADC     [USB_1_TransferByteCount], 0 ;
    MOV     A,  [USB_1_TransferSize]   ; Check to see if we have any
    OR      A,  [USB_1_TransferSize+1] ;  more data to send
    JNZ     .cont                      ; Jump if we have to send more data

; Flow here if there is no more data to send
    CMP     [USB_1_LastSize], 8        ; Was it a full packet?
    JZ      .START_TRANSFER            ; Jump if it was full (need to send a zero length)

; Flow here if we are entering the status stage
    MOV    A, 0                        ; Count Register
    MOV    [USB_1_LastSize], A         ; Clear the byte count
    MOV    X, USB_MODE_STATUS_OUT_ONLY ; Only ACK the Status Out
    JMP    USB_1_EP0_UPD_MODE_EXIT

; Jump here to determine how many bytes should we transfer
.cont:
    CMP     [USB_1_TransferSize], 0    ; Check the MSB
    JNZ     .L1

    CMP     [USB_1_TransferSize+1], 8  ; Check the LSB
    JNC     .L1

    MOV     A,[USB_1_TransferSize+1]   ; Transfer all the remaing data
    JMP     .L3

.L1:
    MOV     A, 8                       ; Just transfer the next 8 bytes

.L3:

    SUB     [USB_1_TransferSize+1],A   ; Update the bytes remaining
    SBB     [USB_1_TransferSize],0

    MOV     [USB_1_t2],A               ; Save the count
    MOV     X,0

    CMP     [USB_1_DataSource],USB_DS_ROM  ; RAM or ROM copy?
    JNZ     .RAM_COPY

; Copy data from a ROM source
.ROM_COPY:
    PUSH    X                          ; Save the destination offset
    MOV     A,[USB_1_DataPtr]          ; Get the transfer source MSB
    MOV     X,[USB_1_DataPtr+1]        ; Set the transfer source LSB
    INC     [USB_1_DataPtr+1]          ; Increment the data pointer
    ADC     [USB_1_DataPtr], 0         ;   MSB if necessary

    ROMX                               ; Get the data byte

    POP     X                          ; Get the destination offset
    MOV     REG[X + USB_1_EP0DATA], A  ; Load the data
    INC     X                          ; Bump the destination offset
    MOV     A,X                        ; Are we done?
    CMP     A, [USB_1_t2]
    JC      .ROM_COPY                  ; Not done
    JMP     .START_TRANSFER            ; Otherwise go start the transfer

; Copy data from a RAM source
.RAM_COPY:
    MVI     A, [USB_1_DataPtr+1]       ; Get the data, bump the source

    MOV     REG[X +USB_1_EP0DATA], A   ; Load the data
    INC     X                          ; Bump the destination offset
    MOV     A,X                        ; Are we done?
    CMP     A, [USB_1_t2]
    JC      .RAM_COPY                  ; Not done

;; Set up the IN transfer count/mode/etc
;    A contains the byte count
.START_TRANSFER:
    MOV     [USB_1_LastSize], A        ; Save the packet size

    MOV     A, 1
    AND     A, [USB_1_EP0DataToggle]
    JZ      .BYPASS_T1
    MOV     A, USB_CNT_TOGGLE          ; Or T1 in the data toggle

.BYPASS_T1:
    OR      A, [USB_1_LastSize]
    XOR     [USB_1_EP0DataToggle], 1   ; Update the data toggle for next time

    MOV    X, USB_MODE_ACK_IN_STATUS_OUT  ; Set the mode register
    JMP    USB_1_EP0_UPD_MODE_EXIT
;-----------------------------------------------------------------------------
;  FUNCTION NAME: USB_1_GetTableEntry
;
;  DESCRIPTION:   Copies a TD to the USB_1_CurrentTD data structure.
;
;-----------------------------------------------------------------------------
EXPORT USB_1_GetTableEntry

⌨️ 快捷键说明

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