Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
USBFm.LST
Package: USBFM.zip [view]
Upload User: wang202020
Upload Date: 2021-02-07
Package Size: 182k
Code Size: 427k
Category:
SCM
Development Platform:
HTML/CSS
- 00556 ; * usb9.h and its function is to specifically service this
- 00557 ; * event.
- 00558 ; *****************************************************************************/
- 00050E 00559 USBCtrlTrfInHandler
- 00560 ; movlb high 0x400 ; Point to proper bank
- 00050E 0E04 00561 movlw ADR_PENDING_STATE ; Must check if in ADR_PENDING_STATE
- 000510 631A 00562 cpfseq usb_device_state
- 000512 D006 00563 bra USBCtrlTrfInHandler1
- 000514 5120 00564 movf SetupPkt + bDevADR, W
- 000516 6E6E 00565 movwf UADDR
- 000518 0E05 00566 movlw ADDRESS_STATE ; If UADDR > 0
- 00051A B4D8 00567 btfsc STATUS, Z
- 00051C 0E03 00568 movlw DEFAULT_STATE
- 00051E 6F1A 00569 movwf usb_device_state
- 000520 00570 USBCtrlTrfInHandler1
- 000520 0E01 00571 movlw CTRL_TRF_TX
- 000522 6316 00572 cpfseq ctrl_trf_state
- 000524 D09D 00573 bra USBPrepareForNextSetupTrf
- 000526 D805 00574 rcall USBCtrlTrfTxService
- 000528 0EC8 00575 movlw _USIE|_DAT1|_DTSEN
- 00052A BD04 00576 btfsc ep0Bi + Stat, DTS
- 00052C 0E88 00577 movlw _USIE|_DAT0|_DTSEN
- 00052E 6F04 00578 movwf ep0Bi + Stat
- 000530 0012 00579 return
- 00580
- 00581
- 00582 ; From usbctrltrf.c line 260
- 00583 ;/******************************************************************************
- 00584 ; * Function: void USBCtrlTrfTxService(void)
- 00585 ; *
- 00586 ; * PreCondition: pSrc, wCount, and usb_stat.ctrl_trf_mem are setup properly.
- MPASM 5.22 USBFM.ASM 1-25-2010 15:59:32 PAGE 37
- LOC OBJECT CODE LINE SOURCE TEXT
- VALUE
- 00587 ; *
- 00588 ; * Input: None
- 00589 ; *
- 00590 ; * Output: None
- 00591 ; *
- 00592 ; * Side Effects: None
- 00593 ; *
- 00594 ; * Overview: This routine should be called from only two places.
- 00595 ; * One from USBCtrlEPServiceComplete() and one from
- 00596 ; * USBCtrlTrfInHandler(). It takes care of managing a
- 00597 ; * transfer over multiple USB transactions.
- 00598 ; *
- 00599 ; * Note: Copies one packet-ful of data pSrc (either ROM or RAM) to
- 00600 ; * EP0 IN buffer. It then updates pSrc to be ready for next
- 00601 ; * piece.
- 00602 ; * This routine works with isochronous endpoint larger than
- 00603 ; * 256 bytes and is shown here as an example of how to deal
- 00604 ; * with BC9 and BC8. In reality, a control endpoint can never
- 00605 ; * be larger than 64 bytes.
- 00606 ; *****************************************************************************/
- 000532 00607 USBCtrlTrfTxService
- 00608 ; movlb high 0x400 ; Point to proper bank
- 000532 5118 00609 movf wCount, W ; Preset wCount bytes to send
- 000534 6F10 00610 movwf usb_temp
- 000536 5119 00611 movf wCount + 1, W
- 000538 6F11 00612 movwf usb_temp + 1
- 00053A 0800 00613 sublw high EP0_BUFF_SIZE ; Make sure count does not exceed maximium length
- 00053C E304 00614 bnc USBCtrlTrfTxServiceCopy
- 00053E E107 00615 bnz USBCtrlTrfTxServiceSub
- 000540 5118 00616 movf wCount, W
- 000542 0840 00617 sublw low EP0_BUFF_SIZE
- 000544 E204 00618 bc USBCtrlTrfTxServiceSub
- 000546 00619 USBCtrlTrfTxServiceCopy
- 000546 0E40 00620 movlw low EP0_BUFF_SIZE ; Send buffer full of bytes
- 000548 6F10 00621 movwf usb_temp
- 00054A 0E00 00622 movlw high EP0_BUFF_SIZE
- 00054C 6F11 00623 movwf usb_temp + 1
- 00054E 00624 USBCtrlTrfTxServiceSub
- 00054E 5110 00625 movf usb_temp, W ; Subtract actual bytes to be sent from the buffer
- 000550 6F05 00626 movwf ep0Bi + Cnt ; Save low number of bytes to send while we're here
- 000552 5F18 00627 subwf wCount, F
- 000554 5111 00628 movf usb_temp + 1, W
- 000556 5B19 00629 subwfb wCount + 1, F
- 000558 5104 00630 movf ep0Bi + Stat, W ; Get full Stat byte
- 00055A 0BFC 00631 andlw 0xfc ; Clear bottom bits
- 00055C 1111 00632 iorwf usb_temp + 1, W ; Put in high bits of bytes to send
- 00055E 6F04 00633 movwf ep0Bi + Stat ; Save it out
- 000560 EE24 F05E 00634 lfsr 2, CtrlTrfData ; Set destination pointer
- 000564 5111 00635 movf usb_temp + 1, W ; Check high byte for 0
- 000566 E102 00636 bnz USBCtrlTrfTxServiceRomRam ; High byte not 0, must have something to do
- 000568 5110 00637 movf usb_temp, W ; Check low byte for 0
- 00056A E022 00638 bz USBCtrlTrfTxServiceExit ; If both 0 then nothing to send this time
- 00056C 00639 USBCtrlTrfTxServiceRomRam
- MPASM 5.22 USBFM.ASM 1-25-2010 15:59:32 PAGE 38
- LOC OBJECT CODE LINE SOURCE TEXT
- VALUE
- 00056C A31D 00640 btfss usb_stat, ctrl_trf_mem ; ROM or RAM?
- 00056E D012 00641 bra USBCtrlTrfTxServiceRam ; RAM
- 000570 C412 FFF6 00642 movff pSrc, TBLPTRL ; Move source pointer to TBLPTR
- 000574 C413 FFF7 00643 movff pSrc + 1, TBLPTRH
- 000578 6AF8 00644 clrf TBLPTRU
- 00057A 00645 USBCtrlTrfTxServiceRomLoop
- 00057A 0009 00646 tblrd *+
- 00057C CFF5 FFDE 00647 movff TABLAT, POSTINC2 ; Copy one buffer to the other
- 000580 0009 00648 tblrd *+ ; Skip high location
- 000582 0710 00649 decf usb_temp, F ; Count down number of bytes
- 000584 E1FA 00650 bnz USBCtrlTrfTxServiceRomLoop
- 000586 0711 00651 decf usb_temp + 1, F
- 000588 E2F8 00652 bc USBCtrlTrfTxServiceRomLoop
- 00058A CFF6 F412 00653 movff TBLPTRL, pSrc ; Update source pointer
- 00058E CFF7 F413 00654 movff TBLPTRH, pSrc + 1
- 000592 0012 00655 return
- 000594 00656 USBCtrlTrfTxServiceRam
- 000594 C412 FFE1 00657 movff pSrc, FSR1L ; Move source pointer to FSR1
- 000598 C413 FFE2 00658 movff pSrc + 1, FSR1H
- 00059C 00659 USBCtrlTrfTxServiceRamLoop
- 00059C CFE6 FFDE 00660 movff POSTINC1, POSTINC2 ; Copy one buffer to the other
- 0005A0 0710 00661 decf usb_temp, F ; Count down number of bytes
- 0005A2 E1FC 00662 bnz USBCtrlTrfTxServiceRamLoop
- 0005A4 0711 00663 decf usb_temp + 1, F
- 0005A6 E2FA 00664 bc USBCtrlTrfTxServiceRamLoop
- 0005A8 CFE1 F412 00665 movff FSR1L, pSrc ; Update source pointer
- 0005AC CFE2 F413 00666 movff FSR1H, pSrc + 1
- 0005B0 00667 USBCtrlTrfTxServiceExit
- 0005B0 0012 00668 return
- 00669
- 00670
- 00671 ; From usbctrltrf.c line 330
- 00672 ;/******************************************************************************
- 00673 ; * Function: void USBCtrlTrfRxService(void)
- 00674 ; *
- 00675 ; * PreCondition: pDst and wCount are setup properly.
- 00676 ; * pSrc is always &CtrlTrfData
- 00677 ; * usb_stat.ctrl_trf_mem is always _RAM.
- 00678 ; * wCount should be set to 0 at the start of each control
- 00679 ; * transfer.
- 00680 ; *
- 00681 ; * Input: None
- 00682 ; *
- 00683 ; * Output: None
- 00684 ; *
- 00685 ; * Side Effects: None
- 00686 ; *
- 00687 ; * Overview: Transfers bytes received, at EP0 OUT buffer CtrlTrfData,
- 00688 ; * to user's buffer pointed by pDst.
- 00689 ; * This routine only knows how to handle raw byte data.
- 00690 ; * HIDmaker handles transferring and unpacking by a callback
- 00691 ; * function in the generated main program, called from here.
- 00692 ; *
- MPASM 5.22 USBFM.ASM 1-25-2010 15:59:32 PAGE 39
- LOC OBJECT CODE LINE SOURCE TEXT
- VALUE
- 00693 ; * Note: None
- 00694 ; *****************************************************************************/
- 0005B2 00695 USBCtrlTrfRxService
- 00696 ; movlb high 0x400 ; Point to proper bank
- 0005B2 5101 00697 movf ep0Bo + Cnt, W ; Get low number of bytes to read
- 0005B4 6F10 00698 movwf usb_temp ; usb_temp & usb_temp + 1 are bytes to read
- 0005B6 2718 00699 addwf wCount, F ; Accumulate total number of bytes read
- 0005B8 5100 00700 movf ep0Bo + Stat, W ; Get high bits to read
- 0005BA 0B03 00701 andlw 0x03 ; Mask to the count
- 0005BC 6F11 00702 movwf usb_temp + 1 ; Save to high byte of bytes to read
- 0005BE 2319 00703 addwfc wCount + 1, F ; Add overflow from low byte (C) and high byte to total number
- 0005C0 EE14 F05E 00704 lfsr 1, CtrlTrfData ; Point FSR1 to source
- 0005C4 C414 FFD9 00705 movff pDst, FSR2L ; Move destination pointer to FSR2
- 0005C8 C415 FFDA 00706 movff pDst + 1, FSR2H
- 0005CC 5111 00707 movf usb_temp + 1, W ; Check high byte for 0
- 0005CE E102 00708 bnz USBCtrlTrfRxServiceLoop ; High byte not 0, must have something to do
- 0005D0 5110 00709 movf usb_temp, W ; Check low byte for 0
- 0005D2 E00A 00710 bz USBCtrlTrfRxServiceExit ; If both 0 then nothing to send this time
- 0005D4 00711 USBCtrlTrfRxServiceLoop
- 0005D4 CFE6 FFDE 00712 movff POSTINC1, POSTINC2 ; Copy one buffer to the other
- 0005D8 0710 00713 decf usb_temp, F ; Count down number of bytes
- 0005DA E1FC 00714 bnz USBCtrlTrfRxServiceLoop
- 0005DC 0711 00715 decf usb_temp + 1, F
- 0005DE E2FA 00716 bc USBCtrlTrfRxServiceLoop
- 0005E0 CFD9 F414 00717 movff FSR2L, pDst ; Update destination pointer
- 0005E4 CFDA F415 00718 movff FSR2H, pDst + 1
- 0005E8 00719 USBCtrlTrfRxServiceExit
- 0005E8 0012 00720 return
- 00721
- 00722
- 00723 ; From usbctrltrf.c line 382
- 00724 ;/******************************************************************************
- 00725 ; * Function: void USBCtrlEPServiceComplete(void)
- 00726 ; *
- 00727 ; * PreCondition: None
- 00728 ; *
- 00729 ; * Input: None
- 00730 ; *
- 00731 ; * Output: None
- 00732 ; *
- 00733 ; * Side Effects: None
- 00734 ; *
- 00735 ; * Overview: This routine wrap up the ramaining tasks in servicing
- 00736 ; * a Setup Request. Its main task is to set the endpoint
- 00737 ; * controls appropriately for a given situation. See code
- 00738 ; * below.
- 00739 ; * There are three main scenarios:
- 00740 ; * a) There was no handler for the Request, in this case
- 00741 ; * a STALL should be sent out.
- 00742 ; * b) The host has requested a read control transfer,
- 00743 ; * endpoints are required to be setup in a specific way.
- 00744 ; * c) The host has requested a write control transfer, or
- 00745 ; * a control data stage is not required, endpoints are
- MPASM 5.22 USBFM.ASM 1-25-2010 15:59:32 PAGE 40
- LOC OBJECT CODE LINE SOURCE TEXT
- VALUE
- 00746 ; * required to be setup in a specific way.
- 00747 ; *
- 00748 ; * Packet processing is resumed by clearing PKTDIS bit.
- 00749 ; *
- 00750 ; * Note: None
- 00751 ; *****************************************************************************/
- 0005EA 00752 USBCtrlEPServiceComplete
- 00753 ; movlb high 0x400 ; Point to proper bank
- 0005EA 0E00 00754 movlw MUID_NULL
- 0005EC 6317 00755 cpfseq ctrl_trf_session_owner
- 0005EE D00A 00756 bra USBCtrlEPServiceComplete1
- 00757 ;
- 00758 ; No handlers claimed ownership of this Setup packet.
- 00759 ; If no one knows how to service this request then stall.
- 00760 ; Must also prepare EP0 to receive the next SETUP transaction.
- 0005F0 0E40 00761 movlw EP0_BUFF_SIZE
- 0005F2 6F01 00762 movwf ep0Bo + Cnt
- 0005F4 0E1E 00763 movlw low SetupPkt
- 0005F6 6F02 00764 movwf ep0Bo + ADRL
- 0005F8 0E04 00765 movlw high SetupPkt
- 0005FA 6F03 00766 movwf ep0Bo + ADRH
- 0005FC 0E84 00767 movlw _USIE|_BSTALL
- 0005FE 6F00 00768 movwf ep0Bo + Stat
- 00769 ; movlw _USIE|_BSTALL
- 000600 6F04 00770 movwf ep0Bi + Stat
- 000602 D02C 00771 bra USBCtrlEPServiceCompleteExit
- 00772 ;
- 00773 ; A module has claimed ownership of the control transfer session.
- 000604 00774 USBCtrlEPServiceComplete1
- 000604 AF1E 00775 btfss SetupPkt, DataDir
- 000606 D01D 00776 bra USBCtrlEPServiceComplete2
- 000608 5119 00777 movf wCount + 1, W ; Make sure count does not exceed max length requested by Host
- 00060A 5D25 00778 subwf SetupPkt + wLength + 1, W
- 00060C E304 00779 bnc USBCtrlEPServiceCompleteCopy
- 00060E E107 00780 bnz USBCtrlEPServiceComplete11
- 000610 5118 00781 movf wCount, W
- 000612 5D24 00782 subwf SetupPkt + wLength, W
- 000614 E204 00783 bc USBCtrlEPServiceComplete11
- 000616 00784 USBCtrlEPServiceCompleteCopy
- 000616 C424 F418 00785 movff SetupPkt + wLength, wCount ; Set count to maximum
- 00061A C425 F419 00786 movff SetupPkt + wLength + 1, wCount + 1
- 00787 ;
- 00788 ; Setup packet's data direction is "Device to Host"
- 00061E 00789 USBCtrlEPServiceComplete11
- 00061E DF89 00790 rcall USBCtrlTrfTxService ; Actually copy the data to EP0 IN buffer
- 000620 0E01 00791 movlw CTRL_TRF_TX
- 000622 6F16 00792 movwf ctrl_trf_state
- 00793 ; Control Read:
- 00794 ; <SETUP[0]><IN[1]><IN[0]>...<OUT[1]> | <SETUP[0]>
- 00795 ; 1. Prepare OUT EP to respond to early termination
- 00796 ;
- 00797 ; NOTE:
- 00798 ; If something went wrong during the control transfer,
- MPASM 5.22 USBFM.ASM 1-25-2010 15:59:32 PAGE 41
- LOC OBJECT CODE LINE SOURCE TEXT
- VALUE
- 00799 ; the last status stage may not be sent by the host.
- 00800 ; When this happens, two different things could happen
- 00801 ; depending on the host.
- 00802 ; a) The host could send out a RESET.
- 00803 ; b) The host could send out a new SETUP transaction
- 00804 ; without sending a RESET first.
- 00805 ; To properly handle case (b), the OUT EP must be setup
- 00806 ; to receive either a zero length OUT transaction, or a
- 00807 ; new SETUP transaction.
- 00808 ;
- 00809 ; Since the SETUP transaction requires the DTS bit to be
- 00810 ; DAT0 while the zero length OUT status requires the DTS
- 00811 ; bit to be DAT1, the DTS bit check by the hardware should
- 00812 ; be disabled. This way the SIE could accept either of
- 00813 ; the two transactions.
- 00814 ;
- 00815 ; Furthermore, the Cnt byte should be set to prepare for
- 00816 ; the SETUP data (8-byte or more), and the buffer address
- 00817 ; should be pointed to SetupPkt.
- 000624 0E40 00818 movlw EP0_BUFF_SIZE
- 000626 6F01 00819 movwf ep0Bo + Cnt
- 000628 0E1E 00820 movlw low SetupPkt
- 00062A 6F02 00821 movwf ep0Bo + ADRL
- 00062C 0E04 00822 movlw high SetupPkt
- 00062E 6F03 00823 movwf ep0Bo + ADRH
- 000630 0E80 00824 movlw _USIE ; Note: DTSEN is 0!
- 000632 6F00 00825 movwf ep0Bo + Stat
- 00826 ; 2. Prepare IN EP to transfer data, Cnt should have
- 00827 ; been initialized by responsible request owner.
- 000634 0E5E 00828 movlw low CtrlTrfData
- 000636 6F06 00829 movwf ep0Bi + ADRL
- 000638 0E04 00830 movlw high CtrlTrfData
- 00063A 6F07 00831 movwf ep0Bi + ADRH
- 00063C 0EC8 00832 movlw _USIE|_DAT1|_DTSEN
- 00063E 6F04 00833 movwf ep0Bi + Stat
- 000640 D00D 00834 bra USBCtrlEPServiceCompleteExit
- 00835 ;
- 00836 ; Setup packet's data direction is "Host to Device"
- 000642 00837 USBCtrlEPServiceComplete2
- 000642 0E02 00838 movlw CTRL_TRF_RX
- 000644 6F16 00839 movwf ctrl_trf_state
- 00840 ; Control Write:
- 00841 ; <SETUP[0]><OUT[1]><OUT[0]>...<IN[1]> | <SETUP[0]>
- 00842 ;
- 00843 ; 1. Prepare IN EP to respond to early termination
- 00844 ;
- 00845 ; This is the same as a Zero Length Packet Response
- 00846 ; for control transfer without a data stage
- 000646 6B05 00847 clrf ep0Bi + Cnt
- 000648 0EC8 00848 movlw _USIE|_DAT1|_DTSEN
- 00064A 6F04 00849 movwf ep0Bi + Stat
- 00850 ; 2. Prepare OUT EP to receive data.
- 00064C 0E40 00851 movlw EP0_BUFF_SIZE
- MPASM 5.22 USBFM.ASM 1-25-2010 15:59:32 PAGE 42
- LOC OBJECT CODE LINE SOURCE TEXT
- VALUE
- 00064E 6F01 00852 movwf ep0Bo + Cnt
- 000650 0E5E 00853 movlw low CtrlTrfData
- 000652 6F02 00854 movwf ep0Bo + ADRL
- 000654 0E04 00855 movlw high CtrlTrfData
- 000656 6F03 00856 movwf ep0Bo + ADRH
- 000658 0EC8 00857 movlw _USIE|_DAT1|_DTSEN
- 00065A 6F00 00858 movwf ep0Bo + Stat
- 00859 ;
- 00065C 00860 USBCtrlEPServiceCompleteExit
- 00861 ; PKTDIS bit is set when a Setup Transaction is received.
- 00862 ; Clear to resume packet processing.
- 00065C 986D 00863 bcf UCON, PKTDIS
- 00065E 0012 00864 return
- 00865
- 00866
- 00867 ; From usbctrltrf.c line 490
- 00868 ;/******************************************************************************
- 00869 ; * Function: void USBPrepareForNextSetupTrf(void)
- 00870 ; *
- 00871 ; * PreCondition: None
- 00872 ; *
- 00873 ; * Input: None
- 00874 ; *
- 00875 ; * Output: None
- 00876 ; *
- 00877 ; * Side Effects: None
- 00878 ; *
- 00879 ; * Overview: The routine forces EP0 OUT to be ready for a new Setup
- 00880 ; * transaction, and forces EP0 IN to be owned by CPU.
- 00881 ; *
- 00882 ; * Note: None
- 00883 ; *****************************************************************************/
- 000660 00884 USBPrepareForNextSetupTrf
- 00885 ; movlb high 0x400 ; Point to proper bank
- 000660 0E00 00886 movlw WAIT_SETUP
- 000662 6F16 00887 movwf ctrl_trf_state
- 000664 0E40 00888 movlw EP0_BUFF_SIZE
- 000666 6F01 00889 movwf ep0Bo + Cnt
- 000668 0E1E 00890 movlw low SetupPkt
- 00066A 6F02 00891 movwf ep0Bo + ADRL
- 00066C 0E04 00892 movlw high SetupPkt
- 00066E 6F03 00893 movwf ep0Bo + ADRH
- 000670 0E88 00894 movlw _USIE|_DAT0|_DTSEN ; EP0 buff dsc init
- 000672 6F00 00895 movwf ep0Bo + Stat
- 000674 0E00 00896 movlw _UCPU ; EP0 IN buffer initialization
- 000676 6F04 00897 movwf ep0Bi + Stat
- 000678 0012 00898 return
- 00899
- 00900
- 00901
- 00902 ; From usbdrv.c line ???
- 00903 ;/******************************************************************************
- 00904 ; * Function: void InitializeUSBDriver(void)
- MPASM 5.22 USBFM.ASM 1-25-2010 15:59:32 PAGE 43
- LOC OBJECT CODE LINE SOURCE TEXT
- VALUE
- 00905 ; *
- 00906 ; * PreCondition: None
- 00907 ; *
- 00908 ; * Input: None
- 00909 ; *
- 00910 ; * Output: None
- 00911 ; *
- 00912 ; * Side Effects: None
- 00913 ; *
- 00914 ; * Overview: This routine initializes variables used by the USB library
- 00915 ; * routines.
- 00916 ; *
- 00917 ; * Note: None
- 00918 ; *****************************************************************************/
- 00067A 00919 InitializeUSBDriver
- 00067A 0104 00920 movlb high 0x400 ; Point to proper bank
- 00067C 0E14 00921 movlw UCFG_VAL
- 00067E 6E6F 00922 movwf UCFG
- 000680 0E00 00923 movlw DETACHED_STATE
- 000682 6F1A 00924 movwf usb_device_state
- 000684 6B1D 00925 clrf usb_stat
- 000686 6B1B 00926 clrf usb_active_cfg
- 00927 #ifdef USB_USE_HID
- 000688 D8D9 00928 rcall HIDInitEP
- 00929 #endif
- 00930 #ifdef USB_USE_CDC
- 00931 rcall CDCInitEP
- 00932 #endif
- 00068A 0012 00933 return
- 00934
- 00935
- 00936 ; From usbdrv.c line 76
- 00937 ;/******************************************************************************
- 00938 ; * Function: void USBCheckBusStatus(void)
- 00939 ; *
- 00940 ; * PreCondition: None
- 00941 ; *
- 00942 ; * Input: None
- 00943 ; *
- 00944 ; * Output: None
- 00945 ; *
- 00946 ; * Side Effects: None
- 00947 ; *
- 00948 ; * Overview: This routine enables/disables the USB module by monitoring
- 00949 ; * the USB power signal.
- 00950 ; *
- 00951 ; * Note: None
- 00952 ; *****************************************************************************/
- 00068C 00953 USBCheckBusStatus
- 00068C 0104 00954 movlb high 0x400 ; Point to proper bank
- 00955 ; Bus Attachment & Detachment Detection
- 00956 ; usb_bus_sense is an i/o pin defined in io_cfg.h
- 00957 #ifdef USE_USB_BUS_SENSE_IO
- MPASM 5.22 USBFM.ASM 1-25-2010 15:59:32 PAGE 44
- LOC OBJECT CODE LINE SOURCE TEXT
- VALUE
- 00958 btfss usb_bus_sense ; Is USB bus attached?
- 00959 bra USBCheckBusStatusDetached ; No
- 00960 #endif
- 00068E A66D 00961 btfss UCON, USBEN ; Is the module off?
- 000690 D80C 00962 rcall USBModuleEnable ; Is off, enable it
- 00963 #ifdef USE_USB_BUS_SENSE_IO
- 00964 bra USBCheckBusStatus1
- 00965 USBCheckBusStatusDetached
- 00966 btfsc UCON, USBEN ; Is the module on?
- 00967 rcall USBModuleDisable ; Is on, disable it
- 00968 #endif
- 00969 ;
- 00970 ; After enabling the USB module, it takes some time for the voltage
- 00971 ; on the D+ or D- line to rise high enough to get out of the SE0 condition.
- 00972 ; The USB Reset interrupt should not be unmasked until the SE0 condition is
- 00973 ; cleared. This helps preventing the firmware from misinterpreting this
- 00974 ; unique event as a USB bus reset from the USB host.
- 000692 00975 USBCheckBusStatus1
- 000692 0E01 00976 movlw ATTACHED_STATE
- 000694 631A 00977 cpfseq usb_device_state
- 000696 0012 00978 return
- 000698 BA6D 00979 btfsc UCON, SE0
- 00069A 0012 00980 return
- 00069C 6A68 00981 clrf UIR ; Clear all USB interrupts
- 00069E 6A69 00982 clrf UIE ; Mask all USB interrupts
- 0006A0 8069 00983 bsf UIE, URSTIE ; Unmask RESET interrupt
- 0006A2 8869 00984 bsf UIE, IDLEIE ; Unmask IDLE interrupt
- 0006A4 0E02 00985 movlw POWERED_STATE
- 0006A6 6F1A 00986 movwf usb_device_state
- 0006A8 0012 00987 return
- 00988
- 00989
- 00990 ; From usbdrv.c line 135
- 0006AA 00991 USBModuleEnable
- 00992 ; movlb high 0x400 ; Point to proper bank
- 0006AA 6A6D 00993 clrf UCON
- 0006AC 6A69 00994 clrf UIE ; Mask all USB interrupts
- 0006AE 866D 00995 bsf UCON, USBEN ; Enable module & attach to bus
- 0006B0 0E01 00996 movlw ATTACHED_STATE
- 0006B2 6F1A 00997 movwf usb_device_state
- 0006B4 0012 00998 return
- 00999
- 01000
- 01001 ; From usbdrv.c line 192
- 0006B6 01002 USBSoftDetach
- 01003 ; From usbdrv.c line 161
- 0006B6 01004 USBModuleDisable
- 0006B6 0104 01005 movlb high 0x400 ; Point to proper bank
- 0006B8 6A6D 01006 clrf UCON ; Disable module & detach from bus
- 0006BA 6A69 01007 clrf UIE ; Mask all USB interrupts
- 0006BC 0E00 01008 movlw DETACHED_STATE
- 0006BE 6F1A 01009 movwf usb_device_state
- 0006C0 0012 01010 return
- MPASM 5.22 USBFM.ASM 1-25-2010 15:59:32 PAGE 45
- LOC OBJECT CODE LINE SOURCE TEXT
- VALUE
- 01011
- 01012
- 01013 ; From usbdrv.c line 215
- 01014 ;/******************************************************************************
- 01015 ; * Function: void USBDriverService(void)
- 01016 ; *
- 01017 ; * PreCondition: None
- 01018 ; *
- 01019 ; * Input: None
- 01020 ; *
- 01021 ; * Output: None
- 01022 ; *
- 01023 ; * Side Effects: None
- 01024 ; *
- 01025 ; * Overview: This routine is the heart of this firmware. It manages
- 01026 ; * all USB interrupts.
- 01027 ; *
- 01028 ; * Note: Device state transitions through the following stages:
- 01029 ; * DETACHED -> ATTACHED -> POWERED -> DEFAULT ->
- 01030 ; * ADDRESS_PENDING -> ADDRESSED -> CONFIGURED -> READY
- 01031 ; *****************************************************************************/
- 0006C2 01032 USBDriverService
- 0006C2 0104 01033 movlb high 0x400 ; Point to proper bank
- 0006C4 0E00 01034 movlw DETACHED_STATE
- 0006C6 5D1A 01035 subwf usb_device_state, W
- 0006C8 E023 01036 bz USBDriverServiceExit ; Pointless to continue servicing
- 01037 ; if USB cable is not even attached.
- 01038 ;
- 01039 ; Task A: Service USB Activity Interrupt
- 0006CA A468 01040 btfss UIR, ACTVIF
- 0006CC D002 01041 bra USBDriverService1
- 0006CE B469 01042 btfsc UIE, ACTVIE
- 0006D0 D824 01043 rcall USBWakeFromSuspend
- 01044 ;
- 0006D2 01045 USBDriverService1
- 0006D2 B26D 01046 btfsc UCON, SUSPND ; Are we suspended?
- 0006D4 0012 01047 return ; Pointless to continue servicing if the device is in suspend mo
- de.
- 01048 ;
- 01049 ; Task B: Service USB Bus Reset Interrupt.
- 01050 ; When bus reset is received during suspend, ACTVIF will be set first,
- 01051 ; once the UCONbits.SUSPND is clear, then the URSTIF bit will be asserted.
- 01052 ; This is why URSTIF is checked after ACTVIF.
- 01053 ;
- 01054 ; The USB reset flag is masked when the USB state is in
- 01055 ; DETACHED_STATE or ATTACHED_STATE, and therefore cannot
- 01056 ; cause a USB reset event during these two states.
- 0006D6 A068 01057 btfss UIR, URSTIF ; USB Bus Reset Interrupt?
- 0006D8 D002 01058 bra USBDriverService2
- 0006DA B069 01059 btfsc UIE, URSTIE
- 0006DC D839 01060 rcall USBProtocolResetHandler
- 01061 ;
- 01062 ; Task C: Check & service other USB interrupts
- MPASM 5.22 USBFM.ASM 1-25-2010 15:59:32 PAGE 46
- LOC OBJECT CODE LINE SOURCE TEXT
- VALUE
- 0006DE 01063 USBDriverService2
- 0006DE A868 01064 btfss UIR, IDLEIF
- 0006E0 D002 01065 bra USBDriverService3
- 0006E2 B869 01066 btfsc UIE, IDLEIE
- 0006E4 D816 01067 rcall USBSuspend
- 0006E6 01068 USBDriverService3
- 0006E6 AC68 01069 btfss UIR, SOFIF
- 0006E8 D002 01070 bra USBDriverService4
- 0006EA BC69 01071 btfsc UIE, SOFIE
- 0006EC D828 01072 rcall USB_SOF_Handler
- 0006EE 01073 USBDriverService4
- 0006EE AA68 01074 btfss UIR, STALLIF
- 0006F0 D002 01075 bra USBDriverService5
- 0006F2 BA69 01076 btfsc UIE, STALLIE
- 0006F4 D826 01077 rcall USBStallHandler
- 0006F6 01078 USBDriverService5
- 0006F6 A268 01079 btfss UIR, UERRIF
- 0006F8 D002 01080 bra USBDriverService6
- 0006FA B269 01081 btfsc UIE, UERRIE
- 0006FC D827 01082 rcall USBErrorHandler
- 01083 ;
- 01084 ; Pointless to continue servicing if the host has not sent a bus reset.
- 01085 ; Once bus reset is received, the device transitions into the DEFAULT
- 01086 ; * state and is ready for communication.
- 0006FE 01087 USBDriverService6
- 0006FE 0E03 01088 movlw DEFAULT_STATE
- 000700 5D1A 01089 subwf usb_device_state, W
- 000702 E306 01090 bnc USBDriverServiceExit
- 01091 ;
- 01092 ; Task D: Servicing USB Transaction Complete Interrupt
- 000704 A668 01093 btfss UIR, TRNIF
- 000706 D004 01094 bra USBDriverServiceExit
- 000708 A669 01095 btfss UIE, TRNIE
- 00070A D002 01096 bra USBDriverServiceExit
- 01097 ;
- 01098 ; USBCtrlEPService only services transactions over EP0.
- 01099 ; It ignores all other EP transactions.
- 00070C DEDF 01100 rcall USBCtrlEPService
- 01101 ; Other EPs can be serviced later by responsible device class firmware.
- 01102 ; Each device driver knows when an OUT or IN transaction is ready by
- 01103 ; checking the buffer ownership bit.
- 01104 ; An OUT EP should always be owned by SIE until the data is ready.
- 01105 ; An IN EP should always be owned by CPU until the data is ready.
- 01106 ;
- 01107 ; Because of this logic, it is not necessary to save the USTAT value
- 01108 ; of non-EP0 transactions.
- 00070E 9668 01109 bcf UIR, TRNIF
- 000710 01110 USBDriverServiceExit
- 000710 0012 01111 return
- 01112
- 01113
- 01114 ; From usbdrv.c line 301
- 01115 ;/******************************************************************************
- MPASM 5.22 USBFM.ASM 1-25-2010 15:59:32 PAGE 47
- LOC OBJECT CODE LINE SOURCE TEXT
- VALUE
- 01116 ; * Function: void USBSuspend(void)
- 01117 ; *
- 01118 ; * PreCondition: None
- 01119 ; *
- 01120 ; * Input: None
- 01121 ; *
- 01122 ; * Output: None
- 01123 ; *
- 01124 ; * Side Effects: None
- 01125 ; *
- 01126 ; * Overview:
- 01127 ; *
- 01128 ; * Note: None
- 01129 ; *****************************************************************************/
- 000712 01130 USBSuspend
- 01131 ; NOTE: Do not clear UIRbits.ACTVIF here!
- 01132 ; Reason:
- 01133 ; ACTVIF is only generated once an IDLEIF has been generated.
- 01134 ; This is a 1:1 ratio interrupt generation.
- 01135 ; For every IDLEIF, there will be only one ACTVIF regardless of
- 01136 ; the number of subsequent bus transitions.
- 01137 ;
- 01138 ; If the ACTIF is cleared here, a problem could occur when:
- 01139 ; [ IDLE ][bus activity ->
- 01140 ; <--- 3 ms -----> ^
- 01141 ; ^ ACTVIF=1
- 01142 ; IDLEIF=1
- 01143 ; # # # # (#=Program polling flags)
- 01144 ; ^
- 01145 ; This polling loop will see both
- 01146 ; IDLEIF=1 and ACTVIF=1.
- 01147 ; However, the program services IDLEIF first
- 01148 ; because ACTIVIE=0.
- 01149 ; If this routine clears the only ACTIVIF,
- 01150 ; then it can never get out of the suspend
- 01151 ; mode.
- 000712 8469 01152 bsf UIE, ACTVIE ; Enable bus activity interrupt
- 000714 9868 01153 bcf UIR, IDLEIF
- 000716 826D 01154 bsf UCON, SUSPND ; Put USB module in power conserve
- 01155 ; At this point the PIC can go into sleep,idle, or
- 01156 ; switch to a slower clock, etc.
- 000718 0012 01157 return
- 01158
- 01159
- 01160 ; From usbdrv.c line 353
- 01161 ;/******************************************************************************
- 01162 ; * Function: void USBWakeFromSuspend(void)
- 01163 ; *
- 01164 ; * PreCondition: None
- 01165 ; *
- 01166 ; * Input: None
- 01167 ; *
- 01168 ; * Output: None
- MPASM 5.22 USBFM.ASM 1-25-2010 15:59:32 PAGE 48
- LOC OBJECT CODE LINE SOURCE TEXT
- VALUE
- 01169 ; *
- 01170 ; * Side Effects: None
- 01171 ; *
- 01172 ; * Overview:
- 01173 ; *
- 01174 ; * Note: None
- 01175 ; *****************************************************************************/
- 00071A 01176 USBWakeFromSuspend
- 01177 ; If using clock switching, this is the place to restore the
- 01178 ; original clock frequency.
- 00071A 926D 01179 bcf UCON, SUSPND
- 00071C 9469 01180 bcf UIE, ACTVIE
- 00071E 9468 01181 bcf UIR, ACTVIF
- 000720 0012 01182 return
- 01183
- 01184
- 01185 ; From usbdrv.c line 402
- 01186 ;/******************************************************************************
- 01187 ; * Function: void USBRemoteWakeup(void)
- 01188 ; *
- 01189 ; * PreCondition: None
- 01190 ; *
- 01191 ; * Input: None
- 01192 ; *
- 01193 ; * Output: None
- 01194 ; *
- 01195 ; * Side Effects: None
- 01196 ; *
- 01197 ; * Overview: This function should be called by user when the device
- 01198 ; * is waken up by an external stimulus other than ACTIVIF.
- 01199 ; * Please read the note below to understand the limitations.
- 01200 ; *
- 01201 ; * Note: The modifiable section in this routine should be changed
- 01202 ; * to meet the application needs. Current implementation
- 01203 ; * temporary blocks other functions from executing for a
- 01204 ; * period of 1-13 ms depending on the core frequency.
- 01205 ; *
- 01206 ; * According to USB 2.0 specification section 7.1.7.7,
- 01207 ; * "The remote wakeup device must hold the resume signaling
- 01208 ; * for at lest 1 ms but for no more than 15 ms."
- 01209 ; * The idea here is to use a delay counter loop, using a
- 01210 ; * common value that would work over a wide range of core
- 01211 ; * frequencies.
- 01212 ; * That value selected is 1800. See table below:
- 01213 ; * ==========================================================
- 01214 ; * Core Freq(MHz) MIP RESUME Signal Period (ms)
- 01215 ; * ==========================================================
- 01216 ; * 48 12 1.05
- 01217 ; * 4 1 12.6
- 01218 ; * ==========================================================
- 01219 ; * * These timing could be incorrect when using code
- 01220 ; * optimization or extended instruction mode,
- 01221 ; * or when having other interrupts enabled.
- MPASM 5.22 USBFM.ASM 1-25-2010 15:59:32 PAGE 49
- LOC OBJECT CODE LINE SOURCE TEXT
- VALUE
- 01222 ; * Make sure to verify using the MPLAB SIM's Stopwatch
- 01223 ; *****************************************************************************/
- 000722 01224 USBRemoteWakeup
- 000722 0104 01225 movlb high 0x400 ; Point to proper bank
- 000724 A11D 01226 btfss usb_stat, RemoteWakeup ; Check if RemoteWakeup function has been enabled by the host.
- 000726 0012 01227 return ; No
- 000728 DFF8 01228 rcall USBWakeFromSuspend ; Unsuspend USB modue
- 00072A 846D 01229 bsf UCON, RESUME ; Start RESUME signaling
- 00072C 0E10 01230 movlw 0x10 ; Set RESUME line for 1-13 ms
- 00072E 6EDA 01231 movwf FSR2H ; Using FSR2 as temp
- 000730 6AD9 01232 clrf FSR2L
- 000732 01233 USBRemoteWakeupLoop
- 000732 2ED9 01234 decfsz FSR2L, F
- 000734 D7FE 01235 bra USBRemoteWakeupLoop
- 000736 2EDA 01236 decfsz FSR2H, F
- 000738 D7FC 01237 bra USBRemoteWakeupLoop
- 00073A 946D 01238 bcf UCON, RESUME
- 00073C 0012 01239 return
- 01240
- 01241
- 01242 ; From usbdrv.c line 443
- 01243 ;/******************************************************************************
- 01244 ; * Function: void USB_SOF_Handler(void)
- 01245 ; *
- 01246 ; * PreCondition: None
- 01247 ; *
- 01248 ; * Input: None
- 01249 ; *
- 01250 ; * Output: None
- 01251 ; *
- 01252 ; * Side Effects: None
- 01253 ; *
- 01254 ; * Overview: The USB host sends out a SOF packet to full-speed devices
- 01255 ; * every 1 ms. This interrupt may be useful for isochronous
- 01256 ; * pipes. End designers should implement callback routine
- 01257 ; * as necessary.
- 01258 ; *
- 01259 ; * Note: None
- 01260 ; *****************************************************************************/
- 00073E 01261 USB_SOF_Handler
- 01262 ; Callback routine here
- 00073E 9C68 01263 bcf UIR, SOFIF
- 000740 0012 01264 return
- 01265
- 01266
- 01267 ; From usbdrv.c line 486
- 01268 ;/******************************************************************************
- 01269 ; * Function: void USBStallHandler(void)
- 01270 ; *
- 01271 ; * PreCondition: A STALL packet is sent to the host by the SIE.
- 01272 ; *
- 01273 ; * Input: None
- 01274 ; *
- MPASM 5.22 USBFM.ASM 1-25-2010 15:59:32 PAGE 50
- LOC OBJECT CODE LINE SOURCE TEXT
- VALUE
- 01275 ; * Output: None
- 01276 ; *
- 01277 ; * Side Effects: None
- 01278 ; *
- 01279 ; * Overview: The STALLIF is set anytime the SIE sends out a STALL
- 01280 ; * packet regardless of which endpoint causes it.
- 01281 ; * A Setup transaction overrides the STALL function. A stalled
- 01282 ; * endpoint stops stalling once it receives a setup packet.
- 01283 ; * In this case, the SIE will accepts the Setup packet and
- 01284 ; * set the TRNIF flag to notify the firmware. STALL function
- 01285 ; * for that particular endpoint pipe will be automatically
- 01286 ; * disabled (direction specific).
- 01287 ; *
- 01288 ; * There are a few reasons for an endpoint to be stalled.
- 01289 ; * 1. When a non-supported USB request is received.
- 01290 ; * Example: GET_DESCRIPTOR(DEVICE_QUALIFIER)
- 01291 ; * 2. When an endpoint is currently halted.
- 01292 ; * 3. When the device class specifies that an endpoint must
- 01293 ; * stall in response to a specific event.
- 01294 ; * Example: Mass Storage Device Class
- 01295 ; * If the CBW is not valid, the device shall
- 01296 ; * STALL the Bulk-In pipe.
- 01297 ; * See USB Mass Storage Class Bulk-only Transport
- 01298 ; * Specification for more details.
- 01299 ; *
- 01300 ; * Note: UEPn.EPSTALL can be scanned to see which endpoint causes
- 01301 ; * the stall event.
- 01302 ; * If
- 01303 ; *****************************************************************************/
- 000742 01304 USBStallHandler
- 01305 ; Does not really have to do anything here,
- 01306 ; even for the control endpoint.
- 01307 ; All BDs of Endpoint 0 are owned by SIE right now,
- 01308 ; but once a Setup Transaction is received, the ownership
- 01309 ; for EP0_OUT will be returned to CPU.
- 01310 ; When the Setup Transaction is serviced, the ownership
- 01311 ; for EP0_IN will then be forced back to CPU by firmware.
- 01312 ;
- 01313 ; NOTE: Above description is not quite true at this point.
- 01314 ; It seems the SIE never returns the UOWN bit to CPU,
- 01315 ; and a TRNIF is never generated upon successful
- 01316 ; reception of a SETUP transaction.
- 01317 ; Firmware work-around is implemented below.
- 01318 ;
- 000742 B070 01319 btfsc UEP0, EPSTALL
- 000744 DF8D 01320 rcall USBPrepareForNextSetupTrf ; Firmware Work-Around
- 000746 9070 01321 bcf UEP0, EPSTALL
- 000748 9A68 01322 bcf UIR, STALLIF
- 00074A 0012 01323 return
- 01324
- 01325 ; From usbdrv.c line 528
- 01326 ;/******************************************************************************
- 01327 ; * Function: void USBErrorHandler(void)
- MPASM 5.22 USBFM.ASM 1-25-2010 15:59:32 PAGE 51
- LOC OBJECT CODE LINE SOURCE TEXT
- VALUE
- 01328 ; *
- 01329 ; * PreCondition: None
- 01330 ; *
- 01331 ; * Input: None
- 01332 ; *
- 01333 ; * Output: None
- 01334 ; *
- 01335 ; * Side Effects: None
- 01336 ; *
- 01337 ; * Overview: The purpose of this interrupt is mainly for debugging
- 01338 ; * during development. Check UEIR to see which error causes
- 01339 ; * the interrupt.
- 01340 ; *
- 01341 ; * Note: None
- 01342 ; *****************************************************************************/
- 00074C 01343 USBErrorHandler
- 00074C 9268 01344 bcf UIR, UERRIF
- 00074E 0012 01345 return
- 01346
- 01347
- 01348 ; From usbdrv.c line 555
- 01349 ;/******************************************************************************
- 01350 ; * Function: void USBProtocolResetHandler(void)
- 01351 ; *
- 01352 ; * PreCondition: A USB bus reset is received from the host.
- 01353 ; *
- 01354 ; * Input: None
- 01355 ; *
- 01356 ; * Output: None
- 01357 ; *
- 01358 ; * Side Effects: Currently, this routine flushes any pending USB
- 01359 ; * transactions. It empties out the USTAT FIFO. This action
- 01360 ; * might not be desirable in some applications.
- 01361 ; *
- 01362 ; * Overview: Once a USB bus reset is received from the host, this
- 01363 ; * routine should be called. It resets the device address to
- 01364 ; * zero, disables all non-EP0 endpoints, initializes EP0 to
- 01365 ; * be ready for default communication, clears all USB
- 01366 ; * interrupt flags, unmasks applicable USB interrupts, and
- 01367 ; * reinitializes internal state-machine variables.
- 01368 ; *
- 01369 ; * Note: None
- 01370 ; *****************************************************************************/
- 000750 01371 USBProtocolResetHandler
- 01372 ; movlb high 0x400 ; Point to proper bank
- 000750 6A6A 01373 clrf UEIR ; Clear all USB error flags
- 000752 6A68 01374 clrf UIR ; Clears all USB interrupts
- 000754 0E9F 01375 movlw 0x9f ; Unmask all USB error interrupts
- 000756 6E6B 01376 movwf UEIE
- 000758 0E7B 01377 movlw 0x7b ; Enable all interrupts except ACTVIE
- 00075A 6E69 01378 movwf UIE
- 00075C 6A6E 01379 clrf UADDR ; Reset to default address
- 00075E EE2F F071 01380 lfsr 2, UEP1 ; Reset all non-EP0 UEPn registers
- MPASM 5.22 USBFM.ASM 1-25-2010 15:59:32 PAGE 52
- LOC OBJECT CODE LINE SOURCE TEXT
- VALUE
- 000762 0E0F 01381 movlw 15
- 000764 01382 USBProtocolResetHandlerClearLoop
- 000764 6ADE 01383 clrf POSTINC2
- 000766 2EE8 01384 decfsz WREG, F
- 000768 D7FD 01385 bra USBProtocolResetHandlerClearLoop
- 00076A 0E16 01386 movlw EP_CTRL|HSHK_EN ; Init EP0 as a Ctrl EP
- 00076C 6E70 01387 movwf UEP0
- 00076E B668 01388 btfsc UIR, TRNIF ; Flush any pending transactions
- 000770 01389 USBProtocolResetHandlerFlushLoop
- 000770 9668 01390 bcf UIR, TRNIF
- 000772 B668 01391 btfsc UIR, TRNIF
- 000774 D7FD 01392 bra USBProtocolResetHandlerFlushLoop
- 000776 986D 01393 bcf UCON, PKTDIS ; Make sure packet processing is enabled
- 000778 DF73 01394 rcall USBPrepareForNextSetupTrf
- 00077A 911D 01395 bcf usb_stat, RemoteWakeup ; Default status flag to disable
- 00077C 6B1B 01396 clrf usb_active_cfg ; Clear active configuration
- 00077E 0E03 01397 movlw DEFAULT_STATE
- 000780 6F1A 01398 movwf usb_device_state
- 000782 0012 01399 return
- 01400
- 01401
- 01402
- 01403 #ifdef USB_USE_HID
- 01404
- 01405 ; From hid.c line 72
- 01406 ;/******************************************************************************
- 01407 ; * Function: void USBCheckHIDRequest(void)
- 01408 ; *
- 01409 ; * PreCondition: None
- 01410 ; *
- 01411 ; * Input: None
- 01412 ; *
- 01413 ; * Output: None
- 01414 ; *
- 01415 ; * Side Effects: None
- 01416 ; *
- 01417 ; * Overview: This routine checks the setup data packet to see if it
- 01418 ; * knows how to handle it
- 01419 ; *
- 01420 ; * Note: None
- 01421 ; *****************************************************************************/
- 000784 01422 USBCheckHIDRequest
- 000784 0104 01423 movlb high 0x400 ; Point to proper bank
- 000786 511E 01424 movf SetupPkt, W ; Recipient = RCPT_INTF?
- 000788 0B1F 01425 andlw 0x1f ; Mask to lower 5 bits
- 00078A 0801 01426 sublw RCPT_INTF
- 00078C E102 01427 bnz USBCheckHIDRequestExit ; No
- 00078E 0E00 01428 movlw HID_INTF_ID ; IntfID = HID_INTF_ID?
- 000790 6322 01429 cpfseq SetupPkt + bIntfID
- 000792 01430 USBCheckHIDRequestExit
- 000792 0012 01431 return ; No
- 01432 ;
- 01433 ; There are two standard requests that hid.c may support.
- MPASM 5.22 USBFM.ASM 1-25-2010 15:59:32 PAGE 53
- LOC OBJECT CODE LINE SOURCE TEXT
- VALUE
- 01434 ; 1. GET_DSC(DSC_HID,DSC_RPT,DSC_PHY);
- 01435 ; 2. SET_DSC(DSC_HID,DSC_RPT,DSC_PHY);
- 01436 ;
- 000794 0E06 01437 movlw GET_DSC ; Request = GET_DSC?
- 000796 631F 01438 cpfseq SetupPkt + bRequest
- 000798 D027 01439 bra USBCheckHIDRequestClass ; No
- 00079A 0E21 01440 movlw DSC_HID ; DscType = DSC_HID?
- 00079C 6321 01441 cpfseq SetupPkt + bDscType
- 00079E D00F 01442 bra USBCheckHIDRequest1 ; No
- 01443 mSetSourcePointer HIDDescriptor1
- 0007A0 0EFE M movlw low (HIDDescriptor1)
- 0007A2 6F12 M movwf pSrc
- 0007A4 0E01 M movlw high (HIDDescriptor1)
- 0007A6 6F13 M movwf pSrc + 1
- 01444 mGetRomTableCount ; Set wCount
- 0007A8 C412 FFF6 M movff pSrc, TBLPTRL ; Set source address
- 0007AC C413 FFF7 M movff pSrc + 1, TBLPTRH
- 0007B0 6AF8 M clrf TBLPTRU
- 0007B2 0008 M tblrd * ; Read count
- 0007B4 CFF5 F418 M movff TABLAT, wCount
- 0007B8 6B19 M clrf wCount + 1
- 0007BA 831D 01445 bsf usb_stat, ctrl_trf_mem ; Indicate ROM
- 0007BC D03C 01446 bra USBHIDSetSessionOwner
- 0007BE 01447 USBCheckHIDRequest1
- 0007BE 0E22 01448 movlw DSC_RPT ; DscType = DSC_RPT?
- 0007C0 6321 01449 cpfseq SetupPkt + bDscType
- 0007C2 D012 01450 bra USBCheckHIDRequest2 ; No
- 01451 mSetSourcePointer ReportDescriptor1
- 0007C4 0E2C M movlw low (ReportDescriptor1)
- 0007C6 6F12 M movwf pSrc
- 0007C8 0E02 M movlw high (ReportDescriptor1)
- 0007CA 6F13 M movwf pSrc + 1
- 0007CC 0E0C 01452 movlw low (ReportDescriptor1Len) ; Set wCount
- 0007CE 6EF6 01453 movwf TBLPTRL
- 0007D0 0E02 01454 movlw high (ReportDescriptor1Len)
- 0007D2 6EF7 01455 movwf TBLPTRH
- 0007D4 6AF8 01456 clrf TBLPTRU
- 0007D6 0009 01457 tblrd *+ ; Read count low
- 0007D8 CFF5 F418 01458 movff TABLAT, wCount
- 0007DC 0009 01459 tblrd *+ ; Skip next
- 0007DE 0008 01460 tblrd * ; Read count high
- 0007E0 CFF5 F419 01461 movff TABLAT, wCount + 1
- 0007E4 831D 01462 bsf usb_stat, ctrl_trf_mem ; Indicate ROM
- 0007E6 D027 01463 bra USBHIDSetSessionOwner
- 0007E8 01464 USBCheckHIDRequest2
- 01465 ; movlw DSC_PHY ; DscType = DSC_PHY?
- 01466 ; cpfseq SetupPkt + bDscType
- 01467 ; return ; No
- 0007E8 01468 USBCheckHIDRequestClass
- 0007E8 511E 01469 movf SetupPkt, W ; RequestType = CLASS?
- 0007EA 0B60 01470 andlw 0x60 ; Mask to proper bits
- 0007EC 0820 01471 sublw (CLASS) << 5
- 0007EE E1D1 01472 bnz USBCheckHIDRequestExit ; No
- MPASM 5.22 USBFM.ASM 1-25-2010 15:59:32 PAGE 54
- LOC OBJECT CODE LINE SOURCE TEXT
- VALUE
- 01473 ; movlw GET_REPORT ; Request = GET_REPORT?
- 01474 ; subwf SetupPkt + bRequest, W
- 01475 ; bz HIDGetReportHandler ; Yes
- 01476 ; movlw SET_REPORT ; Request = SET_REPORT?
- 01477 ; subwf SetupPkt + bRequest, W
- 01478 ; bz HIDSetReportHandler ; Yes
- 0007F0 0E02 01479 movlw GET_IDLE ; Request = GET_IDLE?
- 0007F2 631F 01480 cpfseq SetupPkt + bRequest
- 0007F4 D009 01481 bra USBCheckHIDRequestClass1 ; No
- 01482 mSetSourcePointer idle_rate
- 0007F6 0E9E M movlw low (idle_rate)
- 0007F8 6F12 M movwf pSrc
- 0007FA 0E04 M movlw high (idle_rate)
- 0007FC 6F13 M movwf pSrc + 1
- 0007FE 0E01 01483 movlw 1
- 000800 6F18 01484 movwf wCount
- 000802 6B19 01485 clrf wCount + 1
- 000804 931D 01486 bcf usb_stat, ctrl_trf_mem ; Indicate RAM
- 000806 D017 01487 bra USBHIDSetSessionOwner
- 000808 01488 USBCheckHIDRequestClass1
- 000808 0E0A 01489 movlw SET_IDLE ; Request = SET_IDLE?
- 00080A 631F 01490 cpfseq SetupPkt + bRequest
- 00080C D003 01491 bra USBCheckHIDRequestClass2 ; No
- 00080E C421 F49E 01492 movff SetupPkt + wValue + 1, idle_rate
- 000812 D011 01493 bra USBHIDSetSessionOwner
- 000814 01494 USBCheckHIDRequestClass2
- 000814 0E03 01495 movlw GET_PROTOCOL ; Request = GET_PROTOCOL?
- 000816 631F 01496 cpfseq SetupPkt + bRequest
- 000818 D009 01497 bra USBCheckHIDRequestClass3 ; No
- 01498 mSetSourcePointer active_protocol
- 00081A 0E9F M movlw low (active_protocol)
- 00081C 6F12 M movwf pSrc
- 00081E 0E04 M movlw high (active_protocol)
- 000820 6F13 M movwf pSrc + 1
- 000822 0E01 01499 movlw 1
- 000824 6F18 01500 movwf wCount
- 000826 6B19 01501 clrf wCount + 1
- 000828 931D 01502 bcf usb_stat, ctrl_trf_mem ; Indicate RAM
- 00082A D005 01503 bra USBHIDSetSessionOwner
- 00082C 01504 USBCheckHIDRequestClass3
- 00082C 0E0B 01505 movlw SET_PROTOCOL ; Request = SET_PROTOCOL?
- 00082E 631F 01506 cpfseq SetupPkt + bRequest
- 000830 0012 01507 return ; No
- 000832 C420 F49F 01508 movff SetupPkt + wValue, active_protocol
- 000836 01509 USBHIDSetSessionOwner
- 000836 0E02 01510 movlw MUID_HID
- 000838 6F17 01511 movwf ctrl_trf_session_owner
- 00083A 0012 01512 return
- 01513
- 01514
- 01515 ; From hid.c line 158
- 01516 ;/******************************************************************************
- 01517 ; * Function: void HIDInitEP(void)
- MPASM 5.22 USBFM.ASM 1-25-2010 15:59:32 PAGE 55
- LOC OBJECT CODE LINE SOURCE TEXT
- VALUE
- 01518 ; *
- 01519 ; * PreCondition: None
- 01520 ; *
- 01521 ; * Input: None
- 01522 ; *
- 01523 ; * Output: None
- 01524 ; *
- 01525 ; * Side Effects: None
- 01526 ; *
- 01527 ; * Overview: HIDInitEP initializes HID endpoints, buffer descriptors,
- 01528 ; * internal state-machine, and variables.
- 01529 ; * It should be called after the USB host has sent out a
- 01530 ; * SET_CONFIGURATION request.
- 01531 ; * See USBStdSetCfgHandler() in usb9.c for examples.
- 01532 ; *
- 01533 ; * Note: None
- 01534 ; *****************************************************************************/
- 00083C 01535 HIDInitEP
- 00083C 0E01 01536 movlw 1 ; Endpoint 1 Out
- 00083E 6EE9 01537 movwf FSR0L
- 000840 EE14 F0A0 01538 lfsr 1, hid_report_out ; FSR1 = endpoint buffer address
- 000844 0E40 01539 movlw HID_INT_OUT_EP_SIZE ; W = endpoint size
- 000846 D81C 01540 rcall InitEPOut ; Inititalize the endpoint
- 01541
- 000848 0E01 01542 movlw 1 ; Endpoint 1 In
- 00084A 6EE9 01543 movwf FSR0L
- 00084C EE14 F0E1 01544 lfsr 1, hid_report_in ; FSR1 = endpoint buffer address
- 000850 0E40 01545 movlw HID_INT_IN_EP_SIZE ; W = endpoint size
- 000852 D000 01546 bra InitEPIn ; Inititalize the endpoint
- 01547
- 01548 #endif ; USB_USE_HID
- 01549
- 01550
- 01551
- 01552 #ifdef USB_USE_CDC
- 01553
- 01554 ;/******************************************************************************
- 01555 ; * Function: void USBCheckCDCRequest(void)
- 01556 ; *
- 01557 ; * PreCondition: None
- 01558 ; *
- 01559 ; * Input: None
- 01560 ; *
- 01561 ; * Output: None
- 01562 ; *
- 01563 ; * Side Effects: None
- 01564 ; *
- 01565 ; * Overview: This routine checks the setup data packet to see if it
- 01566 ; * knows how to handle it
- 01567 ; *
- 01568 ; * Note: None
- 01569 ; *****************************************************************************/
- 01570 USBCheckCDCRequest
- MPASM 5.22 USBFM.ASM 1-25-2010 15:59:32 PAGE 56
- LOC OBJECT CODE LINE SOURCE TEXT
- VALUE
- 01571 ; /*
- 01572 ; * If request recipient is not an interface then return
- 01573 ; */
- 01574 movlb high 0x400 ; Point to proper bank
- 01575 movf SetupPkt, W ; Recipient = RCPT_INTF?
- 01576 andlw 0x1f ; Mask to lower 5 bits
- 01577 sublw RCPT_INTF
- 01578 bnz USBCheckCDCRequestExit ; No
- 01579
- 01580 ; /*
- 01581 ; * If request type is not class-specific then return
- 01582 ; */
- 01583 movf SetupPkt, W ; RequestType = CLASS?
- 01584 andlw 0x60 ; Mask to proper bits
- 01585 sublw (CLASS) << 5
- 01586 bnz USBCheckCDCRequestExit ; No
- 01587
- 01588 ; /*
- 01589 ; * Interface ID must match interface numbers associated with
- 01590 ; * CDC class, else return
- 01591 ; */
- 01592 movlw CDC_COMM_INTF_ID ; IntfID = CDC_COMM_INTF_ID?
- 01593 subwf SetupPkt + bIntfID, W
- 01594 bz USBCheckCDCRequest1 ; Yes
- 01595 movlw CDC_DATA_INTF_ID ; IntfID = CDC_DATA_INTF_ID?
- 01596 cpfseq SetupPkt + bIntfID
- 01597 USBCheckCDCRequestExit
- 01598 return ; No
- 01599
- 01600 USBCheckCDCRequest1
- 01601 movlw SEND_ENCAPSULATED_COMMAND ; Request = SEND_ENCAPSULATED_COMMAND?
- 01602 cpfseq SetupPkt + bRequest
- 01603 bra USBCheckCDCRequest2 ; No
- 01604 mSetSourcePointer dummy_encapsulated_cmd_response
- 01605 bcf usb_stat, ctrl_trf_mem ; Indicate RAM
- 01606 movlw dummy_length
- 01607 movwf wCount
- 01608 clrf wCount + 1
- 01609 bra USBCDCSetSessionOwner
- 01610 USBCheckCDCRequest2
- 01611 movlw GET_ENCAPSULATED_RESPONSE ; Request = GET_ENCAPSULATED_RESPONSE?
- 01612 cpfseq SetupPkt + bRequest
- 01613 bra USBCheckCDCRequest3 ; No
- 01614 ; // Populate dummy_encapsulated_cmd_response first.
- 01615 mSetDestinationPointer dummy_encapsulated_cmd_response
- 01616 bra USBCDCSetSessionOwner
- 01617 USBCheckCDCRequest3
- 01618 movlw SET_COMM_FEATURE ; Request = SET_COMM_FEATURE?
- 01619 cpfseq SetupPkt + bRequest
- 01620 bra USBCheckCDCRequest4 ; No
- 01621 return ; Optional
- 01622 USBCheckCDCRequest4
- 01623 movlw GET_COMM_FEATURE ; Request = GET_COMM_FEATURE?
- MPASM 5.22 USBFM.ASM 1-25-2010 15:59:32 PAGE 57
- LOC OBJECT CODE LINE SOURCE TEXT
- VALUE
- 01624 cpfseq SetupPkt + bRequest
- 01625 bra USBCheckCDCRequest5 ; No
- 01626 return ; Optional
- 01627 USBCheckCDCRequest5
- 01628 movlw CLEAR_COMM_FEATURE ; Request = CLEAR_COMM_FEATURE?
- 01629 cpfseq SetupPkt + bRequest
- 01630 bra USBCheckCDCRequest6 ; No
- 01631 return ; Optional
- 01632 USBCheckCDCRequest6
- 01633 movlw SET_LINE_CODING ; Request = SET_LINE_CODING?
- 01634 cpfseq SetupPkt + bRequest
- 01635 bra USBCheckCDCRequest7 ; No
- 01636 mSetDestinationPointer line_coding
- 01637 bra USBCDCSetSessionOwner
- 01638 USBCheckCDCRequest7
- 01639 movlw GET_LINE_CODING ; Request = GET_LINE_CODING?
- 01640 cpfseq SetupPkt + bRequest
- 01641 bra USBCheckCDCRequest8 ; No
- 01642 ; Abstract line coding information
- 01643 movlw low 115200 ; baud rate
- 01644 movwf line_coding + dwDTERate
- 01645 movlw high 115200
- 01646 movwf line_coding + dwDTERate + 1
- 01647 movlw upper 115200
- 01648 movwf line_coding + dwDTERate + 2
- 01649 clrf line_coding + dwDTERate + 3
- 01650 clrf line_coding + bCharFormat ; 1 stop bit
- 01651 clrf line_coding + bParityType ; None
- 01652 movlw 8
- 01653 movwf line_coding + bDataBits ; 5,6,7,8, or 16
- 01654 mSetSourcePointer line_coding
- 01655 bcf usb_stat, ctrl_trf_mem ; Indicate RAM
- 01656 movlw LINE_CODING_LENGTH
- 01657 movwf wCount
- 01658 clrf wCount + 1
- 01659 bra USBCDCSetSessionOwner
- 01660 USBCheckCDCRequest8
- 01661 movlw SET_CONTROL_LINE_STATE ; Request = SET_CONTROL_LINE_STATE?
- 01662 cpfseq SetupPkt + bRequest
- 01663 bra USBCheckCDCRequest9 ; No
- 01664 movff SetupPkt + wValue, control_signal_bitmap
- 01665 bra USBCDCSetSessionOwner
- 01666 USBCheckCDCRequest9
- 01667 movlw SEND_BREAK ; Request = SEND_BREAK?
- 01668 cpfseq SetupPkt + bRequest
- 01669 bra USBCheckCDCRequest10 ; No
- 01670 return ; Optional
- 01671 USBCheckCDCRequest10
- 01672 return ; Default
- 01673 USBCDCSetSessionOwner
- 01674 movlw MUID_CDC
- 01675 movwf ctrl_trf_session_owner
- 01676 return
- MPASM 5.22 USBFM.ASM 1-25-2010 15:59:32 PAGE 58
- LOC OBJECT CODE LINE SOURCE TEXT
- VALUE
- 01677
- 01678
- 01679 ;/******************************************************************************
- 01680 ; * Function: void CDCInitEP(void)
- 01681 ; *
- 01682 ; * PreCondition: None
- 01683 ; *
- 01684 ; * Input: None
- 01685 ; *
- 01686 ; * Output: None
- 01687 ; *
- 01688 ; * Side Effects: None
- 01689 ; *
- 01690 ; * Overview: CDCInitEP initializes CDC endpoints, buffer descriptors,
- 01691 ; * internal state-machine, and variables.
- 01692 ; * It should be called after the USB host has sent out a
- 01693 ; * SET_CONFIGURATION request.
- 01694 ; * See USBStdSetCfgHandler() in usb9.c for examples.
- 01695 ; *
- 01696 ; * Note: None
- 01697 ; *****************************************************************************/
- 01698 CDCInitEP
- 01699 movlw 2 ; Endpoint 2 In
- 01700 movwf FSR0L
- 01701 lfsr 1, cdc_notice ; FSR1 = endpoint buffer address
- 01702 movlw CDC_INT_EP_SIZE ; W = endpoint size
- 01703 rcall InitEPIn ; Inititalize the endpoint
- 01704
- 01705 movlw 3 ; Endpoint 3
- 01706 movwf FSR0L
- 01707 lfsr 1, cdc_data_rx ; FSR1 = endpoint buffer address
- 01708 movlw CDC_BULK_OUT_EP_SIZE ; W = endpoint size
- 01709 rcall InitEPOut ; Inititalize the endpoint
- 01710
- 01711 movlw 3 ; Endpoint 3 In
- 01712 movwf FSR0L
- 01713 lfsr 1, cdc_data_tx ; FSR1 = endpoint buffer address
- 01714 movlw CDC_BULK_IN_EP_SIZE ; W = endpoint size
- 01715 bra InitEPIn ; Inititalize the endpoint
- 01716
- 01717 #endif ; USB_USE_CDC
- 01718
- 01719
- 01720 ; Generic code for use by all the classes
- 01721
- 01722 ; InitEPIn
- 01723 ; Generic initialize In endpoint
- 01724 ; Input:
- 01725 ; FSR0L is endpoint number
- 01726 ; FSR1 is endpoint buffer address
- 01727 ; W is endpoint buffer size
- 01728 ; Returns:
- 01729 ; Nada
- MPASM 5.22 USBFM.ASM 1-25-2010 15:59:32 PAGE 59
- LOC OBJECT CODE LINE SOURCE TEXT
- VALUE
- 01730 ; Uses
- 01731 ; FSR0 is BDT pointer
- 01732 ; FSR1 is endpoint buffer pointer
- 01733 ; FSR2 is endpoint table pointer
- 01734
- 000854 01735 InitEPIn
- 01736 ; Save maximum count at front of endpoint buffer and move buffer pointer up (no need to put in Cnt for I
- n)
- 000854 6EE6 01737 movwf POSTINC1 ; Store maximum count at front of endpoint buffer and move up po
- inter
- 01738
- 01739 ; Point FSR2 to endpoint table
- 000856 EE2F F070 01740 lfsr 2, UEP0
- 00085A 50E9 01741 movf FSR0L, W ; Add in endpoint number
- 00085C 26D9 01742 addwf FSR2L, F
- 01743
- 01744 ; Enable In endpoint
- 00085E 0E1A 01745 movlw EP_IN|HSHK_EN ; Enable In pipe
- 000860 12DF 01746 iorwf INDF2, F
- 01747
- 01748 ; Point FSR0 to endpoint BDT
- 000862 44E9 01749 rlncf FSR0L, W ; Endpoint number * 8
- 000864 46E8 01750 rlncf WREG, F
- 000866 46E8 01751 rlncf WREG, F
- 000868 EE04 F004 01752 lfsr 0, ep0Bi ; Point FSR0 to beginning of BDT area
- 00086C 26E9 01753 addwf FSR0L, F ; Add endpoint offset to FSR0 (can't overflow to FSR0H)
- 01754
- 01755 ; Set endpoint buffer address from FSR1
- 00086E 0E02 01756 movlw ADRL ; Point to ADRL
- 000870 CFE1 FFEB 01757 movff FSR1L, PLUSW0
- 000874 0E03 01758 movlw ADRH ; Point to ADRH
- 000876 CFE2 FFEB 01759 movff FSR1H, PLUSW0
- 01760
- 01761 ; Set endpoint status
- 00087A 0E40 01762 movlw _UCPU|_DAT1 ; Set transmit status
- 00087C 6EEF 01763 movwf INDF0 ; Set Stat
- 00087E 0012 01764 return
- 01765
- 01766
- 01767 ; InitEPOut
- 01768 ; Generic initialize Out endpoint
- 01769 ; Input:
- 01770 ; FSR0L is endpoint number
- 01771 ; FSR1 is endpoint buffer address
- 01772 ; W is endpoint buffer size
- 01773 ; Returns:
- 01774 ; Nada
- 01775 ; Uses
- 01776 ; FSR0 is BDT pointer
- 01777 ; FSR1 is endpoint buffer pointer
- 01778 ; FSR2 is endpoint table pointer
- 01779
- 000880 01780 InitEPOut
- MPASM 5.22 USBFM.ASM 1-25-2010 15:59:32 PAGE 60
- LOC OBJECT CODE LINE SOURCE TEXT
- VALUE
- 01781 ; Save maximum count at front of endpoint buffer and move buffer pointer up
- 000880 6EE6 01782 movwf POSTINC1 ; Store maximum count at front of endpoint buffer and move up po
- inter
- 01783
- 01784 ; Point FSR2 to endpoint table
- 000882 EE2F F070 01785 lfsr 2, UEP0
- 000886 50E9 01786 movf FSR0L, W ; Add in endpoint number
- 000888 26D9 01787 addwf FSR2L, F
- 01788
- 01789 ; Enable Out endpoint
- 00088A 0E1C 01790 movlw EP_OUT|HSHK_EN ; Enable Out pipe
- 00088C 12DF 01791 iorwf INDF2, F
- 01792
- 01793 ; Point FSR0 to endpoint BDT
- 00088E 44E9 01794 rlncf FSR0L, W ; Endpoint number * 8
- 000890 46E8 01795 rlncf WREG, F
- 000892 46E8 01796 rlncf WREG, F
- 000894 EE04 F000 01797 lfsr 0, ep0Bo ; Point FSR0 to beginning of BDT area
- 000898 26E9 01798 addwf FSR0L, F ; Add endpoint offset to FSR0 (can't overflow to FSR0H)
- 01799
- 01800 ; Set endpoint buffer address from FSR1 + 1
- 00089A 0E02 01801 movlw ADRL ; Point to ADRL
- 00089C CFE1 FFEB 01802 movff FSR1L, PLUSW0
- 0008A0 0E03 01803 movlw ADRH ; Point to ADRH
- 0008A2 CFE2 FFEB 01804 movff FSR1H, PLUSW0
- 01805
- 01806 ; Set Cnt to maximum count
- 0008A6 50E5 01807 movf POSTDEC1, W ; Back up endpoint buffer pointer (no PREDEC1!)
- 0008A8 2AE9 01808 incf FSR0L, F ; Point to Cnt
- 0008AA CFE7 FFED 01809 movff INDF1, POSTDEC0 ; Set maximum count and point back to Stat
- 01810
- 01811 ; Set endpoint status
- 0008AE 0E88 01812 movlw _USIE|_DAT0|_DTSEN ; Set receive status
- 0008B0 6EEF 01813 movwf INDF0 ; Set Stat
- 0008B2 0012 01814 return
- 01815
- 01816
- 01817 ; PutUSB
- 01818 ; Generic fill In endpoint for TX
- 01819 ; Input:
- 01820 ; FSR0L is endpoint number
- 01821 ; FSR1 is source buffer pointer
- 01822 ; W is count
- 01823 ; Returns:
- 01824 ; FSR1 is updated source buffer pointer
- 01825 ; W returns number sent
- 01826 ; Carry is clear for buffer not available
- 01827 ; Uses:
- 01828 ; FSR0 is BDT pointer
- 01829 ; FSR1 is source buffer pointer
- 01830 ; FSR2 is endpoint buffer pointer
- 01831 ; R0 in BANKA is temporary length storage
- 01832
- MPASM 5.22 USBFM.ASM 1-25-2010 15:59:32 PAGE 61
- LOC OBJECT CODE LINE SOURCE TEXT
- VALUE
- 0008B4 01833 PutUSB
- 0008B4 6E01 01834 movwf R0 ; Save count
- 01835
- 01836 ; Check to see if we're configured
- 0008B6 0104 01837 movlb high 0x400 ; Point to proper bank
- 0008B8 0E06 01838 movlw CONFIGURED_STATE ; We might not be configured yet
- 0008BA 5D1A 01839 subwf usb_device_state, W
- 0008BC 0E00 01840 movlw 0 ; 0 characters sent, so far
- 0008BE 90D8 01841 bcf STATUS, C ; Clear Carry for possible error return
- 0008C0 E109 01842 bnz PutUSBNotReady ; We're not configured
- 01843
- 01844 ; Point FSR0 to requested endpoint In BDT
- 0008C2 44E9 01845 rlncf FSR0L, W ; Endpoint number * 8
- 0008C4 46E8 01846 rlncf WREG, F
- 0008C6 46E8 01847 rlncf WREG, F
- 0008C8 EE04 F004 01848 lfsr 0, ep0Bi ; Point FSR0 to beginning of BDT area
- 0008CC 26E9 01849 addwf FSR0L, F ; Add endpoint offset to FSR0 (can't overflow to FSR0H)
- 01850
- 0008CE 0E00 01851 movlw 0 ; 0 characters sent, so far
- 0008D0 90D8 01852 bcf STATUS, C ; Clear Carry for possible error return
- 0008D2 BEEF 01853 btfsc INDF0, UOWN ; Who owns the buffer (Stat, UOWN)?
- 0008D4 01854 PutUSBNotReady
- 0008D4 0012 01855 return ; Busy (we don't)
- 01856
- 01857 ; Get endpoint buffer address to FSR2
- 0008D6 0E02 01858 movlw ADRL ; Point to ADRL
- 0008D8 CFEB FFD9 01859 movff PLUSW0, FSR2L
- 0008DC 0E03 01860 movlw ADRH ; Point to ADRH
- 0008DE CFEB FFDA 01861 movff PLUSW0, FSR2H
- 01862
- 0008E2 0EFF 01863 movlw -1
- 0008E4 50DB 01864 movf PLUSW2, W ; Get maximum length from in front of endpoint buffer
- 01865
- 0008E6 6001 01866 cpfslt R0 ; Find number of bytes to send this time
- 0008E8 6E01 01867 movwf R0 ; Too big - send maximum allowed length
- 01868
- 0008EA 2AE9 01869 incf FSR0L, F ; Point to Cnt
- 0008EC 5001 01870 movf R0, W ; Get number to send
- 0008EE 6EED 01871 movwf POSTDEC0 ; Put length into Cnt and point back to Stat
- 0008F0 E004 01872 bz PutUSBZero ; Zero to send
- 01873
- 0008F2 01874 PutUSBRamLoop
- 0008F2 CFE6 FFDE 01875 movff POSTINC1, POSTINC2 ; Copy source buffer to endpoint buffer
- 0008F6 2EE8 01876 decfsz WREG, F ; Count down number of bytes to transfer
- 0008F8 D7FC 01877 bra PutUSBRamLoop
- 01878
- 0008FA 01879 PutUSBZero
- 0008FA 0E40 01880 movlw _DTSMASK ; Save only DTS bit
- 0008FC 16EF 01881 andwf INDF0, F
- 0008FE 7CEF 01882 btg INDF0, DTS ; Toggle DTS bit
- 000900 0E88 01883 movlw _USIE|_DTSEN ; Turn ownership to SIE
- 000902 12EF 01884 iorwf INDF0, F
- 000904 5001 01885 movf R0, W ; Return number of bytes sent
- MPASM 5.22 USBFM.ASM 1-25-2010 15:59:32 PAGE 62
- LOC OBJECT CODE LINE SOURCE TEXT
- VALUE
- 000906 80D8 01886 bsf STATUS, C ; Set Carry for non-error return
- 000908 0012 01887 return
- 01888
- 01889
- 01890 ; GetUSB
- 01891 ; Generic get from Out endpoint for RX
- 01892 ; Input:
- 01893 ; FSR0L is endpoint number
- 01894 ; FSR1 is destination buffer pointer
- 01895 ; W is max buffer length
- 01896 ; Returns:
- 01897 ; FSR1 is updated destination buffer pointer
- 01898 ; W returns number received
- 01899 ; Carry is clear for buffer not available
- 01900 ; Uses
- 01901 ; FSR0 is BDT pointer
- 01902 ; FSR1 is destination buffer pointer
- 01903 ; FSR2 is endpoint buffer pointer
- 01904 ; R0 in BANKA is temporary length storage
- 01905
- 00090A 01906 GetUSB
- 00090A 6E01 01907 movwf R0 ; Save max buffer length
- 01908
- 01909 ; Check to see if we're configured
- 00090C 0104 01910 movlb high 0x400 ; Point to proper bank
- 00090E 0E06 01911 movlw CONFIGURED_STATE ; We might not be configured yet
- 000910 5D1A 01912 subwf usb_device_state, W
- 000912 0E00 01913 movlw 0 ; 0 characters received, so far
- 000914 90D8 01914 bcf STATUS, C ; Clear Carry for possible error return
- 000916 E109 01915 bnz GetUSBNotReady ; We're not configured
- 01916
- 01917 ; Point FSR0 to requested endpoint Out BDT
- 000918 44E9 01918 rlncf FSR0L, W ; Endpoint number * 8
- 00091A 46E8 01919 rlncf WREG, F
- 00091C 46E8 01920 rlncf WREG, F
- 00091E EE04 F000 01921 lfsr 0, ep0Bo ; Point FSR0 to beginning of BDT area
- 000922 26E9 01922 addwf FSR0L, F ; Add endpoint offset to FSR0 (can't overflow to FSR0H)
- 01923
- 000924 0E00 01924 movlw 0 ; 0 characters received, so far
- 000926 90D8 01925 bcf STATUS, C ; Clear Carry for possible error return
- 000928 BEEF 01926 btfsc INDF0, UOWN ; Who owns the buffer (Stat, UOWN)?
- 00092A 01927 GetUSBNotReady
- 00092A 0012 01928 return ; Busy (we don't)
- 01929
- 01930 ; Get endpoint buffer address to FSR2
- 00092C 0E02 01931 movlw ADRL ; Point to ADRL
- 00092E CFEB FFD9 01932 movff PLUSW0, FSR2L
- 000932 0E03 01933 movlw ADRH ; Point to ADRH
- 000934 CFEB FFDA 01934 movff PLUSW0, FSR2H
- 01935
- 000938 50EC 01936 movf PREINC0, W ; Get Cnt
- 00093A 6001 01937 cpfslt R0 ; Make sure it's not longer than the buffer
- 00093C 6E01 01938 movwf R0 ; It's OK, save returned length
- MPASM 5.22 USBFM.ASM 1-25-2010 15:59:32 PAGE 63
- LOC OBJECT CODE LINE SOURCE TEXT
- VALUE
- 01939
- 00093E 0EFF 01940 movlw -1
- 000940 50DB 01941 movf PLUSW2, W ; Get maximum length from in front of endpoint buffer
- 000942 6EED 01942 movwf POSTDEC0 ; Reset max length and point back to Stat
- 01943
- 000944 5001 01944 movf R0, W ; Get count to W
- 000946 E004 01945 bz GetUSBZero ; Nothing received
- 01946
- 000948 01947 GetUSBRamLoop
- 000948 CFDE FFE6 01948 movff POSTINC2, POSTINC1 ; Copy endpoint buffer to destination buffer
- 00094C 2EE8 01949 decfsz WREG, F ; Count down number of bytes
- 00094E D7FC 01950 bra GetUSBRamLoop
- 01951
- 000950 01952 GetUSBZero
- 000950 0E40 01953 movlw _DTSMASK ; Save only DTS bit
- 000952 16EF 01954 andwf INDF0, F
- 000954 7CEF 01955 btg INDF0, DTS ; Toggle DTS bit
- 000956 0E88 01956 movlw _USIE|_DTSEN ; Turn ownership to SIE
- 000958 12EF 01957 iorwf INDF0, F
- 00095A 5001 01958 movf R0, W ; Return number of bytes received
- 00095C 80D8 01959 bsf STATUS, C ; Set Carry for non-error return
- 00095E 0012 01960 return
- 00017
- 000960 00018 MAINPROG
- 00082
- 00083 MOVE?CB 000h, TRISA
- M CHK?RP TRISA
- M if (((TRISA) > BANKA_END) & ((TRISA) < (0f01h + BANKA_END)))
- M if (((TRISA) & 0f00h) != (PREV_BANK << 8))
- M movlb high (TRISA)
- M PREV_BANK = high (TRISA)
- M endif
- M endif
- M if (low (000h) == 0)
- 000960 6A92 M clrf TRISA
- M else
- M movlw low (000h)
- M movwf TRISA
- M endif
- 00084 MOVE?CB 000h, TRISB
- M CHK?RP TRISB
- M if (((TRISB) > BANKA_END) & ((TRISB) < (0f01h + BANKA_END)))
- M if (((TRISB) & 0f00h) != (PREV_BANK << 8))
- M movlb high (TRISB)
- M PREV_BANK = high (TRISB)
- M endif
- M endif
- M if (low (000h) == 0)
- 000962 6A93 M clrf TRISB
- M else
- M movlw low (000h)
- M movwf TRISB
- M endif
- MPASM 5.22 USBFM.ASM 1-25-2010 15:59:32 PAGE 64
- LOC OBJECT CODE LINE SOURCE TEXT
- VALUE
- 00085 MOVE?CT 001h, _TRISC??0
- M CHK?RP TRISC
- M if (((TRISC) > BANKA_END) & ((TRISC) < (0f01h + BANKA_END)))
- M if (((TRISC) & 0f00h) != (PREV_BANK << 8))
- M movlb high (TRISC)
- M PREV_BANK = high (TRISC)
- M endif
- M endif
- M if (((001h) & 1) == 1)
- 000964 8094 M bsf TRISC, 000h
- M else
- M bcf TRISC, 000h
- M endif
- 00086 MOVE?CT 001h, _TRISC??1
- M CHK?RP TRISC
- M if (((TRISC) > BANKA_END) & ((TRISC) < (0f01h + BANKA_END)))
- M if (((TRISC) & 0f00h) != (PREV_BANK << 8))
- M movlb high (TRISC)
- M PREV_BANK = high (TRISC)
- M endif
- M endif
- M if (((001h) & 1) == 1)
- 000966 8294 M bsf TRISC, 001h
- M else
- M bcf TRISC, 001h
- M endif
- 00087 MOVE?CT 000h, _TRISC??2
- M CHK?RP TRISC
- M if (((TRISC) > BANKA_END) & ((TRISC) < (0f01h + BANKA_END)))
- M if (((TRISC) & 0f00h) != (PREV_BANK << 8))
- M movlb high (TRISC)
- M PREV_BANK = high (TRISC)
- M endif
- M endif
- M if (((000h) & 1) == 1)
- M bsf TRISC, 002h
- M else
- 000968 9494 M bcf TRISC, 002h
- M endif
- 00088 MOVE?CB _FreqMin, _Frecuencia
- M CHK?RP _Frecuencia
- M if (((_Frecuencia) > BANKA_END) & ((_Frecuencia) < (0f01h + BANKA_END)))
- M if (((_Frecuencia) & 0f00h) != (PREV_BANK << 8))
- M movlb high (_Frecuencia)
- M PREV_BANK = high (_Frecuencia)
- M endif
- M endif
- M if (low (_FreqMin) == 0)
- M clrf _Frecuencia
- M else
- 00096A 0E0A M movlw low (_FreqMin)
- 00096C 6E1E M movwf _Frecuencia
- M endif
- MPASM 5.22 USBFM.ASM 1-25-2010 15:59:32 PAGE 65
- LOC OBJECT CODE LINE SOURCE TEXT
- VALUE
- 00089 MOVE?BB _Frecuencia, PORTB
- 00096E C01E FF81 M movff _Frecuencia, PORTB
- 00090 MOVE?CB 000h, PORTA
- M CHK?RP PORTA
- M if (((PORTA) > BANKA_END) & ((PORTA) < (0f01h + BANKA_END)))
- M if (((PORTA) & 0f00h) != (PREV_BANK << 8))
- M movlb high (PORTA)
- M PREV_BANK = high (PORTA)
- M endif
- M endif
- M if (low (000h) == 0)
- 000972 6A80 M clrf PORTA
- M else
- M movlw low (000h)
- M movwf PORTA
- M endif
- 00091 MOVE?CB 000h, PORTC
- M CHK?RP PORTC
- M if (((PORTC) > BANKA_END) & ((PORTC) < (0f01h + BANKA_END)))
- M if (((PORTC) & 0f00h) != (PREV_BANK << 8))
- M movlb high (PORTC)
- M PREV_BANK = high (PORTC)
- M endif
- M endif
- M if (low (000h) == 0)
- 000974 6A82 M clrf PORTC
- M else
- M movlw low (000h)
- M movwf PORTC
- M endif
- 00092 MOVE?CB 007h, ADCON1
- M CHK?RP ADCON1
- M if (((ADCON1) > BANKA_END) & ((ADCON1) < (0f01h + BANKA_END)))
- M if (((ADCON1) & 0f00h) != (PREV_BANK << 8))
- M movlb high (ADCON1)
- M PREV_BANK = high (ADCON1)
- M endif
- M endif
- M if (low (007h) == 0)
- M clrf ADCON1
- M else
- 000976 0E07 M movlw low (007h)
- 000978 6EC1 M movwf ADCON1
- M endif
- 00093 MOVE?CB 007h, CMCON
- M CHK?RP CMCON
- M if (((CMCON) > BANKA_END) & ((CMCON) < (0f01h + BANKA_END)))
- M if (((CMCON) & 0f00h) != (PREV_BANK << 8))
- M movlb high (CMCON)
- M PREV_BANK = high (CMCON)
- M endif
- M endif
- M if (low (007h) == 0)
- MPASM 5.22 USBFM.ASM 1-25-2010 15:59:32 PAGE 66
- LOC OBJECT CODE LINE SOURCE TEXT
- VALUE
- M clrf CMCON
- M else
- 00097A 0E07 M movlw low (007h)
- 00097C 6EB4 M movwf CMCON
- M endif
- 00094 USBINIT?
- M ifdef USE_USB_BUS_SENSE_IO
- M tris_usb_bus_sense = 1 ; Set to input
- M endif
- M ifdef USE_SELF_POWER_SENSE_IO
- M tris_self_power = 1 ; Set to input
- M endif
- M L?CALL InitializeUSBDriver ; Finish initialization
- M RST?RP
- M if (PREV_BANK != 0)
- M movlb 0
- M PREV_BANK = 0
- M endif
- M
- M ifdef USE_LINKER
- M call InitializeUSBDriver
- M else
- M if ((InitializeUSBDriver) < 1)
- M call InitializeUSBDriver
- M else
- M if ((InitializeUSBDriver) > $)
- M call InitializeUSBDriver
- M else
- M if ((InitializeUSBDriver) < ($ - 3ffh))
- M call InitializeUSBDriver
- M else
- 00097E DE7D M rcall InitializeUSBDriver
- M endif
- M endif
- M endif
- M endif
- M L?CALL DUNN ; Do our cleanup
- M RST?RP
- M if (PREV_BANK != 0)
- M movlb 0
- M PREV_BANK = 0
- M endif
- M
- M ifdef USE_LINKER
- M call DUNN
- M else
- M if ((DUNN) < 1)
- M call DUNN
- M else
- M if ((DUNN) > $)
- M call DUNN
- M else
- M if ((DUNN) < ($ - 3ffh))
- MPASM 5.22 USBFM.ASM 1-25-2010 15:59:32 PAGE 67
- LOC OBJECT CODE LINE SOURCE TEXT
- VALUE
- 000980 ECD4 F000 M call DUNN
- M else
- M rcall DUNN
- M endif
- M endif
- M endif
- M endif
- 00095 LCDOUT?C 0FEh
- M MOVE?CA 0FEh
- 000984 0EFE M movlw low (0FEh)
- M L?CALL LCDOUT
- M RST?RP
- M if (PREV_BANK != 0)
- M movlb 0
- M PREV_BANK = 0
- M endif
- M
- M ifdef USE_LINKER
- M call LCDOUT
- M else
- M if ((LCDOUT) < 1)
- M call LCDOUT
- M else
- M if ((LCDOUT) > $)
- M call LCDOUT
- M else
- M if ((LCDOUT) < ($ - 3ffh))
- 000986 EC23 F000 M call LCDOUT
- M else
- M rcall LCDOUT
- M endif
- M endif
- M endif
- M endif
- 00096 LCDOUT?C 001h
- M MOVE?CA 001h
- 00098A 0E01 M movlw low (001h)
- M L?CALL LCDOUT
- M RST?RP
- M if (PREV_BANK != 0)
- M movlb 0
- M PREV_BANK = 0
- M endif
- M
- M ifdef USE_LINKER
- M call LCDOUT
- M else
- M if ((LCDOUT) < 1)
- M call LCDOUT
- M else
- M if ((LCDOUT) > $)
- M call LCDOUT
- M else
- MPASM 5.22 USBFM.ASM 1-25-2010 15:59:32 PAGE 68
- LOC OBJECT CODE LINE SOURCE TEXT
- VALUE
- M if ((LCDOUT) < ($ - 3ffh))
- 00098C EC23 F000 M call LCDOUT
- M else
- M rcall LCDOUT
- M endif
- M endif
- M endif
- M endif
- 00097 LCDOUT?C 04Dh
- M MOVE?CA 04Dh
- 000990 0E4D M movlw low (04Dh)
- M L?CALL LCDOUT
- M RST?RP
- M if (PREV_BANK != 0)
- M movlb 0
- M PREV_BANK = 0
- M endif
- M
- M ifdef USE_LINKER
- M call LCDOUT
- M else
- M if ((LCDOUT) < 1)
- M call LCDOUT
- M else
- M if ((LCDOUT) > $)
- M call LCDOUT
- M else
- M if ((LCDOUT) < ($ - 3ffh))
- 000992 EC23 F000 M call LCDOUT
- M else
- M rcall LCDOUT
- M endif
- M endif
- M endif
- M endif
- 00098 LCDOUT?C 06Fh
- M MOVE?CA 06Fh
- 000996 0E6F M movlw low (06Fh)
- M L?CALL LCDOUT
- M RST?RP
- M if (PREV_BANK != 0)
- M movlb 0
- M PREV_BANK = 0
- M endif
- M
- M ifdef USE_LINKER
- M call LCDOUT
- M else
- M if ((LCDOUT) < 1)
- M call LCDOUT
- M else
- M if ((LCDOUT) > $)
- M call LCDOUT
- MPASM 5.22 USBFM.ASM 1-25-2010 15:59:32 PAGE 69
- LOC OBJECT CODE LINE SOURCE TEXT
- VALUE
- M else
- M if ((LCDOUT) < ($ - 3ffh))
- 000998 EC23 F000 M call LCDOUT
- M else
- M rcall LCDOUT
- M endif
- M endif
- M endif
- M endif
- 00099 LCDOUT?C 064h
- M MOVE?CA 064h
- 00099C 0E64 M movlw low (064h)
- M L?CALL LCDOUT
- M RST?RP
- M if (PREV_BANK != 0)
- M movlb 0
- M PREV_BANK = 0
- M endif
- M
- M ifdef USE_LINKER
- M call LCDOUT
- M else
- M if ((LCDOUT) < 1)
- M call LCDOUT
- M else
- M if ((LCDOUT) > $)
- M call LCDOUT
- M else
- M if ((LCDOUT) < ($ - 3ffh))
- 00099E EC23 F000 M call LCDOUT
- M else
- M rcall LCDOUT
- M endif
- M endif
- M endif
- M endif
- 00100 LCDOUT?C 075h
- M MOVE?CA 075h
- 0009A2 0E75 M movlw low (075h)
- M L?CALL LCDOUT
- M RST?RP
- M if (PREV_BANK != 0)
- M movlb 0
- M PREV_BANK = 0
- M endif
- M
- M ifdef USE_LINKER
- M call LCDOUT
- M else
- M if ((LCDOUT) < 1)
- M call LCDOUT
- M else
- M if ((LCDOUT) > $)
- MPASM 5.22 USBFM.ASM 1-25-2010 15:59:32 PAGE 70
- LOC OBJECT CODE LINE SOURCE TEXT
- VALUE
- M call LCDOUT
- M else
- M if ((LCDOUT) < ($ - 3ffh))
- 0009A4 EC23 F000 M call LCDOUT
- M else
- M rcall LCDOUT
- M endif
- M endif
- M endif
- M endif
- 00101 LCDOUT?C 06Ch
- M MOVE?CA 06Ch
- 0009A8 0E6C M movlw low (06Ch)
- M L?CALL LCDOUT
- M RST?RP
- M if (PREV_BANK != 0)
- M movlb 0
- M PREV_BANK = 0
- M endif
- M
- M ifdef USE_LINKER
- M call LCDOUT
- M else
- M if ((LCDOUT) < 1)
- M call LCDOUT
- M else
- M if ((LCDOUT) > $)
- M call LCDOUT
- M else
- M if ((LCDOUT) < ($ - 3ffh))
- 0009AA EC23 F000 M call LCDOUT
- M else
- M rcall LCDOUT
- M endif
- M endif
- M endif
- M endif
- 00102 LCDOUT?C 061h
- M MOVE?CA 061h
- 0009AE 0E61 M movlw low (061h)
- M L?CALL LCDOUT
- M RST?RP
- M if (PREV_BANK != 0)
- M movlb 0
- M PREV_BANK = 0
- M endif
- M
- M ifdef USE_LINKER
- M call LCDOUT
- M else
- M if ((LCDOUT) < 1)
- M call LCDOUT
- M else
- MPASM 5.22 USBFM.ASM 1-25-2010 15:59:32 PAGE 71
- LOC OBJECT CODE LINE SOURCE TEXT
- VALUE
- M if ((LCDOUT) > $)
- M call LCDOUT
- M else
- M if ((LCDOUT) < ($ - 3ffh))
- 0009B0 EC23 F000 M call LCDOUT
- M else
- M rcall LCDOUT
- M endif
- M endif
- M endif
- M endif
- 00103 LCDOUT?C 064h
- M MOVE?CA 064h
- 0009B4 0E64 M movlw low (064h)
- M L?CALL LCDOUT
- M RST?RP
- M if (PREV_BANK != 0)
- M movlb 0
- M PREV_BANK = 0
- M endif
- M
- M ifdef USE_LINKER
- M call LCDOUT
- M else
- M if ((LCDOUT) < 1)
- M call LCDOUT
- M else
- M if ((LCDOUT) > $)
- M call LCDOUT
- M else
- M if ((LCDOUT) < ($ - 3ffh))
- 0009B6 EC23 F000 M call LCDOUT
- M else
- M rcall LCDOUT
- M endif
- M endif
- M endif
- M endif
- 00104 LCDOUT?C 06Fh
- M MOVE?CA 06Fh
- 0009BA 0E6F M movlw low (06Fh)
- M L?CALL LCDOUT
- M RST?RP
- M if (PREV_BANK != 0)
- M movlb 0
- M PREV_BANK = 0
- M endif
- M
- M ifdef USE_LINKER
- M call LCDOUT