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

📄 counter.asm

📁 驱动程序开发基础教程
💻 ASM
📖 第 1 页 / 共 3 页
字号:
  USBEventEP0SetupTargetEndpointOUT:
    cmp  a,USBRqstTargetEndPoint
    jz   USBEventEP0Stall               ; Yes

  USBEventEP0SetupTargetDeviceIN:
    cmp  a,USBRqstTargetDevice | USBRqstTypeDirection
    jz   USBEventEP0SetupGetDescriptor  ; Yes

  USBEventEP0SetupTargetInterfaceIN:
    cmp  a,USBRqstTargetInterface | USBRqstTypeDirection
    jz   USBEventEP0Stall               ; Yes Oops! We don't have an interface.

  USBEventEP0SetupTargetEndpointIN:
    cmp  a,USBRqstTargetEndPoint | USBRqstTypeDirection
    jz   USBEventEP0Stall               ; Yes

    ; Vendor specific commands
  USBEventEP0SetupTargetVendorIN_OUT:
    ; Check request (IN packet OK, OUT packet ERR)
    mov  a,[USBEndP0FIFO_0]
    and  a,USBRqstTypeVendor | USBRqstTargetEndPoint | USBRqstTypeDirection
    cmp  a,USBRqstTypeVendor | USBRqstTargetEndPoint | USBRqstTypeDirection
    jz   USBEventEP0VendorRqst

    ; Unsupported request !!!
    jmp  USBEventEP0Stall               ; Oops! We don't support whatever
                                        ;   request was made.

;//$PAGE
;********************************************************
; USBEventEP0SetupIsSet()
; @func End point event SETUP to set address.
; @devnote Runs in interrupt enabled context.
;********************************************************
USBEventEP0SetupIsSetAddress:

    ; Set device address?
    mov  a,[USBRqstMessage]
    cmp  a,USBRqstSetAddress
    jz   USBEventEP0SetupSetAddress         ; Yes

    ; Set device configuration?
    mov  a,[USBRqstMessage]
    cmp  a,USBRqstSetConfiguration
    jz   USBEventEP0SetupSetConfig          ; Yes

    ; Unsupported set request !!!
    jmp  USBEventEP0Stall                   ; No. Stall

;********************************************************
; USBEventEP0SetupSetAddress()
; @func End point zero event SETUP to set address.
; @devnote Runs in interrupt enabled context.
; @comm
; The status token of the SetAddress is an IN. So, we send status manually.
;********************************************************
USBEventEP0SetupSetAddress:

    ; Send ACK
    call USBSendACK
    ; Now that we have been acknowleged, we actually set the address.
    ; This is different from all other commands which execute first
    ;   and then acknowlege (_________________)

    ; Set Address
    mov  a,[USBRqstWordValueLo]
    iowr USBDeviceAddress

    ; Done
    jmp  USBEventEP0End

;********************************************************
; USBEventEP0SetupSetConfig()
; @func End point zero event SETUP to Set Configuration.
; @devnote Runs in interrupt enabled context.
; 1
;  set enumerated (gbSysEnumerated) state, 
;  enable GPIO (and EP1, if appropriate)
;  Enable P0 and P1
; 0
;  Reset enumerated (gbSysEnumerated) state, 
;  Turn off LED
;  Reset variables
;  Disable GPIO and EP1
;  Disable dallas chip and P0 and P1
;********************************************************
USBEventEP0SetupSetConfig:

    ; Enumerated !
    ; Write a 0 to the LED on P13 to turn it on
    mov a,~(LED_ON)
    iowr SysPort1

    mov  a,10h
    iowr USBEndP1TxConfig;NAK

    ; enable all appropriate irq's
    mov  a,SysIntTimer1024us | SysIntGPIO | SysIntUSBEndP0 | SysIntUSBEndP1
    mov  [gbSysInterruptMask],a

    ; Send ACK
    call USBSendACK
    jmp  USBEventEP0End

;//$PAGE
;********************************************************
; USBEventEP0SetupGetDescriptor()
; @func End point zero event SETUP to Get Descriptor.
; @devnote Runs in interrupt enabled context.
;********************************************************
USBEventEP0SetupGetDescriptor:

    ; Get descriptor type
    mov  a,[USBRqstWordValueHi]

  USBEventEP0SetupGetDescriptorDevice:
    ; Device Descriptor?
    cmp  a,USBDescriptorTypeDevice
    jnz  USBEventEP0SetupGetDescriptorConfig    ; No

    ;*********************************************
    ; Get Device Descriptor Event
    ;*********************************************
    ; Descriptor pointer
    mov  a,(USBDeviceDescription -USBSendROMBufferBase)
    mov  [gbUSBSendBuffer],a

    ; Descriptor size
    mov  a,12h                  ;[USBDeviceDescription]
    mov  [gbUSBSendBytes],a

    ; Check request size field
    call USBSendDescriptorCheckLength

    ; Send buffer
    call USBSendROMBuffer
    jmp  USBEventEP0End

  USBEventEP0SetupGetDescriptorConfig:
    ; Configuration Descriptor?
    cmp  a,USBDescriptorTypeConfig
    jnz  USBEventEP0SetupGetDescriptorString    ; No

    ;*********************************************
    ; Get Configuration Descriptor Event
    ;*********************************************
    ; Descriptor pointer
    mov  a,(USBConfigurationDescription -USBSendROMBufferBase)
    mov  [gbUSBSendBuffer],a

    ; Descriptor size
    mov  a,09h                  ;[USBConfigurationDescription]
    add  a,09h                  ;[USBInterfaceDescription]
    add  a,07h                  ;[USBEndPointDescriptionInt]
    mov  [gbUSBSendBytes],a

    ; Check request size field
    call USBSendDescriptorCheckLength

    ; Send buffer
    call USBSendROMBuffer
    jmp  USBEventEP0End

  USBEventEP0SetupGetDescriptorString:
    ; Get String Descriptor?
    cmp  a,USBDescriptorTypeString
    jnz  USBEventEP0SetupGetDescriptorEnd       ; No

    ;*********************************************
    ; Get String Descriptor Event
    ;*********************************************

    ; Get string descriptor index
    mov  a,[USBRqstWordValueLo]

  USBEventEP0SetupGetDescriptorString0:
    cmp  a,0h
    jnz  USBEventEP0SetupGetDescriptorString1   ; No

    ;*********************************************
    ; Get String Language(s) Descriptor Event
    ;*********************************************
    ; Descriptor pointer
    mov  a,(USBStringLanguageDescription -USBSendROMBufferBase)
    mov  [gbUSBSendBuffer],a

    ; Descriptor size
    mov  a,4h                   ;[USBStringLanguageDescription]
    mov  [gbUSBSendBytes],a

    ; Check request size field
    call USBSendDescriptorCheckLength

    ; Send buffer
    call USBSendROMBuffer
    jmp  USBEventEP0End

  USBEventEP0SetupGetDescriptorString1:
    cmp  a,1
    jnz  USBEventEP0SetupGetDescriptorString2   ; No

    ;*********************************************
    ; Get String 1 Descriptor Event
    ;*********************************************
    ; Descriptor pointer
    mov  a,(USBStringDescription1 -USBSendROMBufferBase)
    mov  [gbUSBSendBuffer],a

    ; Descriptor size
    mov  a,10h                  ;[USBStringDescription1]
    mov  [gbUSBSendBytes],a

    ; Check request size field
    call USBSendDescriptorCheckLength

    ; Send buffer
    call USBSendROMBuffer
    jmp  USBEventEP0End

  USBEventEP0SetupGetDescriptorString2:
    cmp  a,2
    jnz  USBEventEP0SetupGetDescriptorString3   ; No

    ;*********************************************
    ; Get String 2 Descriptor Event
    ;*********************************************
    ; Descriptor pointer
    mov  a,(USBStringDescription2 -USBSendROMBufferBase)
    mov  [gbUSBSendBuffer],a

    ; Descriptor size
    mov  a,10h                  ;[USBStringDescription2]
    mov  [gbUSBSendBytes],a

    ; Check request size field
    call USBSendDescriptorCheckLength

    ; Send buffer
    call USBSendROMBuffer
    jmp  USBEventEP0End

  USBEventEP0SetupGetDescriptorString3:
    cmp  a,3
    jnz  USBEventEP0SetupGetDescriptorString4   ; No

    ;*********************************************
    ; Get String 3 Descriptor Event
    ;*********************************************
    ; Descriptor pointer
    mov  a,(USBStringDescription3 -USBSendROMBufferBase)
    mov  [gbUSBSendBuffer],a

    ; Descriptor size
    mov  a,0Ah                  ;[USBStringDescription3]
    mov  [gbUSBSendBytes],a

    ; Check request size field
    call USBSendDescriptorCheckLength

    ; Send buffer
    call USBSendROMBuffer
    jmp  USBEventEP0End

  USBEventEP0SetupGetDescriptorString4:
    cmp  a,4
    jnz  USBEventEP0SetupGetDescriptorString5   ; No

    ;*********************************************
    ; Get String 4 Descriptor Event
    ;*********************************************
    ; Descriptor pointer
    mov  a,(USBStringDescription4 -USBSendROMBufferBase)
    mov  [gbUSBSendBuffer],a

    ; Descriptor size
    mov  a,28h                  ;[USBStringDescription4]
    mov  [gbUSBSendBytes],a

    ; Check request size field
    call USBSendDescriptorCheckLength

    ; Send buffer
    call USBSendROMBuffer
    jmp  USBEventEP0End

  USBEventEP0SetupGetDescriptorString5:
    cmp  a,5
    jnz  USBEventEP0SetupGetDescriptorEnd       ; No

    ;*********************************************
    ; Get String 5 Descriptor Event
    ;*********************************************
    ; Descriptor pointer
    mov  a,(USBStringDescription5 -USBSendROMBufferBase)
    mov  [gbUSBSendBuffer],a

    ; Descriptor size
    mov  a,3Eh                  ;[USBStringDescription5]
    mov  [gbUSBSendBytes],a

    ; Check request size field
    call USBSendDescriptorCheckLength

    ; Send buffer
    call USBSendROMBuffer
    jmp  USBEventEP0End

  USBEventEP0SetupGetDescriptorEnd:
    ; Unsupported Get request !!!
    jmp  USBEventEP0Stall

;//$PAGE
;********************************************************
; USBSendDescriptorCheckLength()
; @func Check and update send length for Get Descriptor
;       requests on end point 0.
; @parm BYTE | gbUSBSendBytes | Number of bytes to send.
;********************************************************
USBSendDescriptorCheckLength:

    ; High byte set? (Assume <255 bytes)
    mov  a,[USBEndP0FIFO_7]
    cmp  a,0
    jnz  USBSendDescriptorCheckLengthEnd    ; Yes

    ; Check size
    mov  a,[USBEndP0FIFO_6]
    cmp  a,[gbUSBSendBytes]
    jz   USBSendDescriptorCheckLengthEnd    ; equal
    jnc  USBSendDescriptorCheckLengthEnd    ; greater than

⌨️ 快捷键说明

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