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

📄 usb_drv.asm

📁 利用psoc进行usb及capsense的程序编写
💻 ASM
📖 第 1 页 / 共 3 页
字号:
    jnz   .L1

    cmp   [USB_TransferSize+1], 8      ; Check the LSB
    jnc   .L1

    mov   A,[USB_TransferSize+1]       ; Transfer all the remaing data
    jmp   .L3
    
.L1:
    mov   A, 8                         ; Just transfer the next 8 bytes

.L3:
 
    sub   [USB_TransferSize+1],A       ; Update the bytes remaining
    sbb   [USB_TransferSize],0 

    mov   [USB_t2],A                   ; Save the count             
    mov   X,0
    
    cmp   [USB_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_DataPtr]              ; Get the transfer source MSB
    mov   X,[USB_DataPtr+1]            ; Set the transfer source LSB
    inc   [USB_DataPtr+1]              ; Increment the data pointer
    adc   [USB_DataPtr], 0             ;   MSB if necessary

    romx                               ; Get the data byte

    pop   X                            ; Get the destination offset
    mov   REG[X + USB_EP0DATA], A      ; Load the data
    inc   X                            ; Bump the destination offset
    mov   A,X                          ; Are we done?
    cmp   A, [USB_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_DataPtr+1]           ; Get the data, bump the source

    mov   REG[X +USB_EP0DATA], A       ; Load the data
    inc   X                            ; Bump the destination offset
    mov   A,X                          ; Are we done?
    cmp   A, [USB_t2]
    jc    .RAM_COPY                    ; Not done

;; Set up the IN transfer count/mode/etc
;    A contains the byte count
.START_TRANSFER:
    mov   [USB_LastSize], A            ; Save the packet size?
    or    A,[USB_EP0DataToggle]        ; Or in the data toggle
    xor   [USB_EP0DataToggle], USB_CNT_TOGGLE    ; Update the data toggle for next time
    mov   REG[USB_EP0CNT], A           ; Set the count register
    mov   [USB_TempMode],USB_MODE_ACK_IN_STATUS_OUT  ; Set the mode register

    ret
;-----------------------------------------------------------------------------
;  FUNCTION NAME: USB_GetTableEntry
;
;  DESCRIPTION: This function figures out based on the various bytes in the
;               setup packet where to get the data from or put the data to.
;               Transfer Data structures are defined each of the supported
;               control transfers, this function finds the right one and 
;               saves it in the CurrentTD structure in RAM.  It then 
;               calles InitControlRead or InitControlWrite to being the 
;               transaction.
;
EXPORT USB_GetTableEntry
USB_GetTableEntry:

    inc   X                            ; Point to the first table entry
    adc   A, 0                         ;

    TD_INDEX_TO_OFFSET USB_t2 ; Convert the index

    swap  A, X
    add   A, [USB_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  [USB_t2], USB_CurrentTD       ; Use Temp as MVI pointer
    call USB_GETBYTE                   ; Get the descriptor data source
    call USB_GETWORD                   ; Get the descriptor size
    call USB_GETWORD                   ; Get the descriptor address
; Dispatch to InitControlRead or InitControlWrite based on d2h/h2d in the request
    mov  A, REG[USB_EP0DATA+bmRequestType]  ; Get bmRequestType

    and  A,0x80                             ; Control Read or Write
    jz   .control_write

    jmp  USB_InitControlRead

.control_write:
    jmp  USB_InitControlWrite

;-----------------------------------------------------------------------------
;  FUNCTION NAME: USB_LOOKUP
;
;  DESCRIPTION:    Returns the address of an entry in a lookup table (LT_ENTRY)
;
;-----------------------------------------------------------------------------
;
;  ARGUMENTS:    A:X Point to the lookup table
;                USB_t2 contain the table index
;
EXPORT USB_LOOKUP
USB_LOOKUP:
    inc  X                             ; Point to the first table entry
    adc  A, 0                          ;

    LT_INDEX_TO_OFFSET USB_t2          ; Convert the index
    swap  A, X
    add   A, [USB_t2]                  ;
    swap  A, X
    adc   A, 0
    ret
;-----------------------------------------------------------------------------
;  FUNCTION NAME: USB_GETWORD/USB_GETBYTE
;
;  DESCRIPTION:    Get a word value from ROM
;
;-----------------------------------------------------------------------------
;
;  ARGUMENTS:    A:X is the ROM Address
;                USB_t2 is the destination address
;
;  RETURNS:      USB_t1
;
EXPORT USB_GETWORD
USB_GETWORD:

    push A                             ; Don't loose the pointer MSB
    romx                               ; Data source flag
    mvi  [USB_t2], A                   ; Save the data source
    pop  A                             ; Get the MSB back
    inc  X                             ; Point to the next  entry
    adc  A, 0                          ;

EXPORT USB_GETBYTE
USB_GETBYTE:

    push A                             ; Don't loose the pointer MSB
    romx                               ; Data source flag
    mvi  [USB_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: USB_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
;
EXPORT USB_GET_DEVICE_TABLE_ENTRY
USB_GET_DEVICE_TABLE_ENTRY:
    mov  [USB_t2], [USB_bCurrentDevice]  ; Use the UM temp var--Selector

    mov  A,>USB_DEVICE_LOOKUP          ; Get the ROM Address MSB
    mov  X,<USB_DEVICE_LOOKUP          ; Get the ROM Address LSB
    romx                               ; First entry is the table size (only a byte)
    cmp  A, [USB_t2]                   ; Range check
    mov  A,>USB_DEVICE_LOOKUP          ; Get the ROM Address MSB
    jc   .exit
; Flow here if the index is valid
    call USB_LOOKUP                    ; Look up the configuration
; Jump or flow here on exit
.exit:
    ret
;-----------------------------------------------------------------------------
;  FUNCTION NAME: USB_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
;
EXPORT USB_GET_CONFIG_TABLE_ENTRY
USB_GET_CONFIG_TABLE_ENTRY:
    call USB_GET_DEVICE_TABLE_ENTRY    ; Get the selected device
    mov  [USB_t2],USB_t1               ; Set the GETWORD destination 
    call USB_GETWORD                   ; Get the pointer to the CONFIG_LOOKUP table
                                       ; ITempW has the address
    mov  A, REG[USB_EP0DATA+wValueLo]  ; Get the configuration number
    mov  [USB_t2],A                    ; Save it 
    mov  A, [USB_t1]                   ; Get the CONFIG_LOOKUP ROM Address MSB
    mov  X, [USB_t1+1]                 ; Get the CONFIG_LOOKUP ROM Address LSB

; A:X Points to the CONFIG_LOOKUP, so get the current entry        
    mov   [USB_t2], [USB_Configuration]; Get the configuration number
    dec   [USB_t2]                     ; We don't populate the 0th entry
    call  USB_LOOKUP                   ; Look up the configuration
    ret
;-----------------------------------------------------------------------------
;  FUNCTION NAME: ;  USB 1st Tier Dispactch Jump Table (based on bmRequestType)
;
;  DESCRIPTION:
;
MACRO BMREQUEST_DISPATCH
IF (USB_CB_@0_@1_@2 & 1)
    jmp     USB_DT_@0_@1_@2_Dispatch
ELSE
    jmp     USB_Not_Supported_Local2
ENDIF
ENDM

USB_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
USB_DT_End:
USB_DT_Size: equ (USB_DT_End-USB_DT_bmRequestType) / 2
USB_bmRequestType_Dispatch::

    DISPATCHER USB_DT_bmRequestType, USB_DT_Size, USB_Not_Supported_Local2 

USB_Not_Supported_Local2:
   nop
   ljmp USB_Not_Supported
; End of File USB_drv.asm

⌨️ 快捷键说明

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