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

📄 myusb_drv.asm

📁 实现2个ps/2接口转到1个USB接口功能
💻 ASM
📖 第 1 页 / 共 3 页
字号:

    TD_INDEX_TO_OFFSET myUSB_t2 ; Convert the index

    SWAP    A, X
    ADD     A, [myUSB_t2]
    SWAP    A, X
    ADC     A, 0                       ; A:X now points to the descriptor table entry we want

; Flow here to load the Transfer Descriptor (TD_ENTRY)
    MOV     [myUSB_t2], myUSB_CurrentTD  ; Use Temp as MVI pointer
    CALL     myUSB_GETBYTE             ; Get the descriptor data source
    CALL     myUSB_GETWORD             ; Get the descriptor size
    CALL     myUSB_GETWORD             ; Get the descriptor address
    CALL     myUSB_GETWORD             ; Get the Status Pointer
; Dispatch to InitControlRead or InitControlWrite based on d2h/h2d in the request
    MOV    A, REG[myUSB_EP0DATA+bmRequestType] ; Get bmRequestType
    AND     A,0x80                          ; Control Read or Write
    JZ      .control_write

    JMP     myUSB_InitControlRead

.control_write:
    JMP     myUSB_InitControlWrite

;-----------------------------------------------------------------------------
;  FUNCTION NAME: myUSB_LOOKUP
;
;  DESCRIPTION:    Returns the address of an entry in a lookup table (LT_ENTRY)
;
;-----------------------------------------------------------------------------
;
;  ARGUMENTS:    A:X Point to the lookup table
;                myUSB_t2 contain the table index
;
;  RETURNS:      Address of the LT_ENTRY in A:X
;
;  SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
;  THEORY of OPERATION or PROCEDURE:
;
;-----------------------------------------------------------------------------
EXPORT myUSB_LOOKUP
myUSB_LOOKUP:
    INC     X                          ; Point to the first table entry
    ADC     A, 0                       ;

    LT_INDEX_TO_OFFSET myUSB_t2        ; Convert the index
    SWAP    A, X
    ADD     A, [myUSB_t2]              ;
    SWAP    A, X
    ADC     A, 0
    RET
;-----------------------------------------------------------------------------
;  FUNCTION NAME: myUSB_GETWORD/myUSB_GETBYTE
;
;  DESCRIPTION:    Get a word value from ROM
;
;-----------------------------------------------------------------------------
;
;  ARGUMENTS:    A:X is the ROM Address
;                myUSB_t2 is the destination address
;
;  RETURNS:      myUSB_t1
;
;  SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;                USES myUSB_t2
;                A:X points to the subsequent locaction ROM location
;  THEORY of OPERATION or PROCEDURE:
;
;-----------------------------------------------------------------------------
EXPORT myUSB_GETWORD
myUSB_GETWORD:

    PUSH    A                          ; Don't loose the pointer MSB
    ROMX                               ; Data source flag
    MVI     [myUSB_t2], A              ; Save the data source
    POP     A                          ; Get the MSB back
    INC     X                          ; Point to the next  entry
    ADC     A, 0                       ;

EXPORT myUSB_GETBYTE
myUSB_GETBYTE:

    PUSH    A                          ; Don't loose the pointer MSB
    ROMX                               ; Data source flag
    MVI     [myUSB_t2], A              ; Save the data source
    POP     A                          ; Get the MSB back
    INC     X                          ; Point to the next  entry
    ADC     A, 0                       ;
    RET
;-----------------------------------------------------------------------------
;  FUNCTION NAME: myUSB_GET_DEVICE_TABLE_ENTRY
;
;  DESCRIPTION:    Get the address of the current DEVICE_TABLE entry
;                  Not intended for use by C fucntions 
;
;-----------------------------------------------------------------------------
;
;  ARGUMENTS:
;
;  RETURNS:        A:X points the the current DEVICE_TABLE entry
;                  Carry flag is set if the current device index is out of range
;
;  SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
;  THEORY of OPERATION or PROCEDURE:
;
;-----------------------------------------------------------------------------
EXPORT myUSB_GET_DEVICE_TABLE_ENTRY
myUSB_GET_DEVICE_TABLE_ENTRY:
    MOV     [myUSB_t2], [myUSB_bCurrentDevice]  ; Use the UM temp var--Selector

    MOV     A,>myUSB_DEVICE_LOOKUP     ; Get the ROM Address MSB
    MOV     X,<myUSB_DEVICE_LOOKUP     ; Get the ROM Address LSB
    ROMX                               ; First entry is the table size (only a byte)
    CMP     A, [myUSB_t2]              ; Range check
    MOV     A,>myUSB_DEVICE_LOOKUP     ; Get the ROM Address MSB
    JC      .exit
; Flow here if the index is valid
    CALL    myUSB_LOOKUP               ; Look up the configuration
; Jump or flow here on exit
.exit:
    RET
;-----------------------------------------------------------------------------
;  FUNCTION NAME: myUSB_GET_CONFIG_TABLE_ENTRY
;
;  DESCRIPTION:    Get the address of the current DEVICE_TABLE entry
;                  Not intended for use by C fucntions
;                  Does not do range checking on  
;
;-----------------------------------------------------------------------------
;
;  ARGUMENTS:
;
;  RETURNS:        A:X points the the current CONFIG_TABLE entry
;                  Carry flag is set if the current device index is out of range
;
;  SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
;  THEORY of OPERATION or PROCEDURE:
;
;-----------------------------------------------------------------------------
EXPORT myUSB_GET_CONFIG_TABLE_ENTRY
myUSB_GET_CONFIG_TABLE_ENTRY:
    CALL    myUSB_GET_DEVICE_TABLE_ENTRY  ; Get the selected device
    MOV     [myUSB_t2],myUSB_t1        ; Set the GETWORD destination 
    CALL    myUSB_GETWORD              ; Get the pointer to the CONFIG_LOOKUP table
                                       ; ITempW has the address
    MOV     A, REG[myUSB_EP0DATA+wValueLo]  ; Get the configuration number
    MOV     [myUSB_t2],A               ; Save it 
    MOV     A, [myUSB_t1]              ; Get the CONFIG_LOOKUP ROM Address MSB
    MOV     X, [myUSB_t1+1]            ; Get the CONFIG_LOOKUP ROM Address LSB

; A:X Points to the CONFIG_LOOKUP, so get the current entry        
    MOV     [myUSB_t2], [myUSB_Configuration] ; Get the configuration number
    DEC     [myUSB_t2]                 ; We don't populate the 0th entry
    CALL    myUSB_LOOKUP               ; Look up the configuration
    RET
;-----------------------------------------------------------------------------
;  FUNCTION NAME: myUSB_UpdateStatusBlock
;
;  DESCRIPTION:    Update the Completion Status Block for a Request.  The
;                  block is updated with the completion code from the
;                  argument (A) and the _TransferByteCount.
;                  
;                  The StatusBlock Pointer (_StatusBlockPtr) is set to NULL (0)
;                  to make sure no other updates are made to the StatusBlock by
;                  the USB User Module.
;
;-----------------------------------------------------------------------------
;
;  ARGUMENTS:      A contains the Completion Status Code
;
;  RETURNS:        None
;
;  SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
;  THEORY of OPERATION or PROCEDURE:
;
;-----------------------------------------------------------------------------
myUSB_UpdateStatusBlock:
    MOV     X, [myUSB_StatusBlockPtr + 1] ;
    SWAP    A, X                       ; Don't loose the completion code
    CMP     A, 0                       ; NULL?
    JZ      .done                      ; No update on NULL
; Flow here to update the VSR Completion Status Block
    SWAP    A, X                       ; Completion code A, Pointer in X
    MOV     [X + 0], A                 ; Update the completion Code 
    MOV     A, [myUSB_TransferByteCount] ; Actual Byte Count MSB
    MOV     [X + 1], A
    MOV     A, [myUSB_TransferByteCount + 1] ; Actual Byte Count LSB
    MOV     [X + 2], A
    MOV     [myUSB_StatusBlockPtr + 1], 0 ; Clear the Block Pointer    
.done:
    RET                                ; All done
;-----------------------------------------------------------------------------
;  FUNCTION NAME: myUSB_InitializeStatusBlock
;
;  DESCRIPTION:    Initialize the Completion Status Block for a Request.
;                  The completion code is set to USB_XFER_IDLE.
;                  
;-----------------------------------------------------------------------------
;
;  ARGUMENTS:      None
;
;  RETURNS:        None
;
;  SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
;  THEORY of OPERATION or PROCEDURE:
;
;-----------------------------------------------------------------------------
myUSB_InitializeStatusBlock:
    MOV     A, [myUSB_StatusBlockPtr + 1] ;
    CMP     A, 0                       ; NULL?
    JZ      .done                      ; No update on NULL
; Flow here to initialize the Completion Status Block
    SWAP    A, X                       ; Pointer in X
    MOV     [X + 0], USB_XFER_IDLE     ; Initialize the completion code (0) 
    MOV     [myUSB_TransferByteCount], 0 ; Clear the byte count 
    MOV     [myUSB_TransferByteCount + 1], 0 ; 
.done:
    RET                                ; All done
;-----------------------------------------------------------------------------
;  FUNCTION NAME: ;  USB 1st Tier Dispactch Jump Table (based on bmRequestType)
;
;  DESCRIPTION:
;
;-----------------------------------------------------------------------------
;
;  ARGUMENTS:
;
;  RETURNS:
;
;  SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
;  THEORY of OPERATION or PROCEDURE:
;
;-----------------------------------------------------------------------------
MACRO BMREQUEST_DISPATCH
IF (USB_CB_@0_@1_@2 & 1)
    jmp     myUSB_DT_@0_@1_@2_Dispatch
ELSE
    jmp     myUSB_Not_Supported_Local_Drv
ENDIF
ENDM
myUSB_DT_bmRequestType::
    BMREQUEST_DISPATCH    h2d,std,dev
    BMREQUEST_DISPATCH    h2d,std,ifc
    BMREQUEST_DISPATCH    h2d,std,ep
    BMREQUEST_DISPATCH    h2d,std,oth
    BMREQUEST_DISPATCH    h2d,cls,dev
    BMREQUEST_DISPATCH    h2d,cls,ifc
    BMREQUEST_DISPATCH    h2d,cls,ep
    BMREQUEST_DISPATCH    h2d,cls,oth
    BMREQUEST_DISPATCH    h2d,vnd,dev
    BMREQUEST_DISPATCH    h2d,vnd,ifc
    BMREQUEST_DISPATCH    h2d,vnd,ep
    BMREQUEST_DISPATCH    h2d,vnd,oth
    BMREQUEST_DISPATCH    h2d,rsv,dev
    BMREQUEST_DISPATCH    h2d,rsv,ifc
    BMREQUEST_DISPATCH    h2d,rsv,ep
    BMREQUEST_DISPATCH    h2d,rsv,oth
    BMREQUEST_DISPATCH    d2h,std,dev
    BMREQUEST_DISPATCH    d2h,std,ifc
    BMREQUEST_DISPATCH    d2h,std,ep
    BMREQUEST_DISPATCH    d2h,std,oth
    BMREQUEST_DISPATCH    d2h,cls,dev
    BMREQUEST_DISPATCH    d2h,cls,ifc
    BMREQUEST_DISPATCH    d2h,cls,ep
    BMREQUEST_DISPATCH    d2h,cls,oth
    BMREQUEST_DISPATCH    d2h,vnd,dev
    BMREQUEST_DISPATCH    d2h,vnd,ifc
    BMREQUEST_DISPATCH    d2h,vnd,ep
    BMREQUEST_DISPATCH    d2h,vnd,oth
    BMREQUEST_DISPATCH    d2h,rsv,dev
    BMREQUEST_DISPATCH    d2h,rsv,ifc
    BMREQUEST_DISPATCH    d2h,rsv,ep
    BMREQUEST_DISPATCH    d2h,rsv,oth
myUSB_DT_End:
myUSB_DT_Size: equ (myUSB_DT_End-myUSB_DT_bmRequestType) / 2
myUSB_bmRequestType_Dispatch::
    DISPATCHER myUSB_DT_bmRequestType, myUSB_DT_Size, myUSB_Not_Supported_Local_Drv 

myUSB_Not_Supported_Local_Drv:
        LJMP     myUSB_Not_Supported


;-----------------------------------------------
; Add custom application code for routines 
;-----------------------------------------------

   ;@PSoC_UserCode_BODY_1@ (Do not change this line.)
   ;---------------------------------------------------
   ; Insert your custom code below this banner
   ;---------------------------------------------------

   ;---------------------------------------------------
   ; Insert your custom code above this banner
   ;---------------------------------------------------
   ;@PSoC_UserCode_END@ (Do not change this line.)

; End of File myUSB_drv.asm

⌨️ 快捷键说明

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