USBFm.LST
Upload User: wang202020
Upload Date: 2021-02-07
Package Size: 182k
Code Size: 427k
Category:

SCM

Development Platform:

HTML/CSS

  1.                       00556 ; *                  usb9.h and its function is to specifically service this
  2.                       00557 ; *                  event.
  3.                       00558 ; *****************************************************************************/
  4. 00050E                00559 USBCtrlTrfInHandler
  5.                       00560 ;       movlb   high 0x400              ; Point to proper bank
  6. 00050E 0E04           00561         movlw   ADR_PENDING_STATE       ; Must check if in ADR_PENDING_STATE
  7. 000510 631A           00562         cpfseq  usb_device_state
  8. 000512 D006           00563         bra     USBCtrlTrfInHandler1
  9. 000514 5120           00564         movf    SetupPkt + bDevADR, W
  10. 000516 6E6E           00565         movwf   UADDR
  11. 000518 0E05           00566         movlw   ADDRESS_STATE           ; If UADDR > 0
  12. 00051A B4D8           00567         btfsc   STATUS, Z
  13. 00051C 0E03           00568         movlw   DEFAULT_STATE
  14. 00051E 6F1A           00569         movwf   usb_device_state
  15. 000520                00570 USBCtrlTrfInHandler1
  16. 000520 0E01           00571         movlw   CTRL_TRF_TX
  17. 000522 6316           00572         cpfseq  ctrl_trf_state
  18. 000524 D09D           00573         bra     USBPrepareForNextSetupTrf
  19. 000526 D805           00574         rcall   USBCtrlTrfTxService
  20. 000528 0EC8           00575         movlw   _USIE|_DAT1|_DTSEN
  21. 00052A BD04           00576         btfsc   ep0Bi + Stat, DTS
  22. 00052C 0E88           00577         movlw   _USIE|_DAT0|_DTSEN
  23. 00052E 6F04           00578         movwf   ep0Bi + Stat
  24. 000530 0012           00579         return
  25.                       00580 
  26.                       00581 
  27.                       00582 ; From usbctrltrf.c line 260
  28.                       00583 ;/******************************************************************************
  29.                       00584 ; * Function:        void USBCtrlTrfTxService(void)
  30.                       00585 ; *
  31.                       00586 ; * PreCondition:    pSrc, wCount, and usb_stat.ctrl_trf_mem are setup properly.
  32. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE 37
  33. LOC  OBJECT CODE     LINE SOURCE TEXT
  34.   VALUE
  35.                       00587 ; *
  36.                       00588 ; * Input:           None
  37.                       00589 ; *
  38.                       00590 ; * Output:          None
  39.                       00591 ; *
  40.                       00592 ; * Side Effects:    None
  41.                       00593 ; *
  42.                       00594 ; * Overview:        This routine should be called from only two places.
  43.                       00595 ; *                  One from USBCtrlEPServiceComplete() and one from
  44.                       00596 ; *                  USBCtrlTrfInHandler(). It takes care of managing a
  45.                       00597 ; *                  transfer over multiple USB transactions.
  46.                       00598 ; *
  47.                       00599 ; * Note:            Copies one packet-ful of data pSrc (either ROM or RAM) to
  48.                       00600 ; *                  EP0 IN buffer. It then updates pSrc to be ready for next
  49.                       00601 ; *                  piece.
  50.                       00602 ; *                  This routine works with isochronous endpoint larger than
  51.                       00603 ; *                  256 bytes and is shown here as an example of how to deal
  52.                       00604 ; *                  with BC9 and BC8. In reality, a control endpoint can never
  53.                       00605 ; *                  be larger than 64 bytes.
  54.                       00606 ; *****************************************************************************/
  55. 000532                00607 USBCtrlTrfTxService
  56.                       00608 ;       movlb   high 0x400              ; Point to proper bank
  57. 000532 5118           00609         movf    wCount, W               ; Preset wCount bytes to send
  58. 000534 6F10           00610         movwf   usb_temp
  59. 000536 5119           00611         movf    wCount + 1, W
  60. 000538 6F11           00612         movwf   usb_temp + 1
  61. 00053A 0800           00613         sublw   high EP0_BUFF_SIZE      ; Make sure count does not exceed maximium length
  62. 00053C E304           00614         bnc     USBCtrlTrfTxServiceCopy
  63. 00053E E107           00615         bnz     USBCtrlTrfTxServiceSub
  64. 000540 5118           00616         movf    wCount, W
  65. 000542 0840           00617         sublw   low EP0_BUFF_SIZE
  66. 000544 E204           00618         bc      USBCtrlTrfTxServiceSub
  67. 000546                00619 USBCtrlTrfTxServiceCopy
  68. 000546 0E40           00620         movlw   low EP0_BUFF_SIZE       ; Send buffer full of bytes
  69. 000548 6F10           00621         movwf   usb_temp
  70. 00054A 0E00           00622         movlw   high EP0_BUFF_SIZE
  71. 00054C 6F11           00623         movwf   usb_temp + 1
  72. 00054E                00624 USBCtrlTrfTxServiceSub
  73. 00054E 5110           00625         movf    usb_temp, W             ; Subtract actual bytes to be sent from the buffer
  74. 000550 6F05           00626         movwf   ep0Bi + Cnt             ; Save low number of bytes to send while we're here
  75. 000552 5F18           00627         subwf   wCount, F
  76. 000554 5111           00628         movf    usb_temp + 1, W
  77. 000556 5B19           00629         subwfb  wCount + 1, F
  78. 000558 5104           00630         movf    ep0Bi + Stat, W         ; Get full Stat byte
  79. 00055A 0BFC           00631         andlw   0xfc                    ; Clear bottom bits
  80. 00055C 1111           00632         iorwf   usb_temp + 1, W         ; Put in high bits of bytes to send
  81. 00055E 6F04           00633         movwf   ep0Bi + Stat            ; Save it out
  82. 000560 EE24 F05E      00634         lfsr    2, CtrlTrfData          ; Set destination pointer
  83. 000564 5111           00635         movf    usb_temp + 1, W         ; Check high byte for 0
  84. 000566 E102           00636         bnz     USBCtrlTrfTxServiceRomRam       ; High byte not 0, must have something to do
  85. 000568 5110           00637         movf    usb_temp, W             ; Check low byte for 0
  86. 00056A E022           00638         bz      USBCtrlTrfTxServiceExit ; If both 0 then nothing to send this time
  87. 00056C                00639 USBCtrlTrfTxServiceRomRam
  88. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE 38
  89. LOC  OBJECT CODE     LINE SOURCE TEXT
  90.   VALUE
  91. 00056C A31D           00640         btfss   usb_stat, ctrl_trf_mem  ; ROM or RAM?
  92. 00056E D012           00641         bra     USBCtrlTrfTxServiceRam  ; RAM
  93. 000570 C412 FFF6      00642         movff   pSrc, TBLPTRL           ; Move source pointer to TBLPTR
  94. 000574 C413 FFF7      00643         movff   pSrc + 1, TBLPTRH
  95. 000578 6AF8           00644         clrf    TBLPTRU
  96. 00057A                00645 USBCtrlTrfTxServiceRomLoop
  97. 00057A 0009           00646         tblrd   *+
  98. 00057C CFF5 FFDE      00647         movff   TABLAT, POSTINC2        ; Copy one buffer to the other
  99. 000580 0009           00648         tblrd   *+                      ; Skip high location
  100. 000582 0710           00649         decf    usb_temp, F             ; Count down number of bytes
  101. 000584 E1FA           00650         bnz     USBCtrlTrfTxServiceRomLoop
  102. 000586 0711           00651         decf    usb_temp + 1, F
  103. 000588 E2F8           00652         bc      USBCtrlTrfTxServiceRomLoop
  104. 00058A CFF6 F412      00653         movff   TBLPTRL, pSrc           ; Update source pointer
  105. 00058E CFF7 F413      00654         movff   TBLPTRH, pSrc + 1
  106. 000592 0012           00655         return
  107. 000594                00656 USBCtrlTrfTxServiceRam
  108. 000594 C412 FFE1      00657         movff   pSrc, FSR1L             ; Move source pointer to FSR1
  109. 000598 C413 FFE2      00658         movff   pSrc + 1, FSR1H
  110. 00059C                00659 USBCtrlTrfTxServiceRamLoop
  111. 00059C CFE6 FFDE      00660         movff   POSTINC1, POSTINC2      ; Copy one buffer to the other
  112. 0005A0 0710           00661         decf    usb_temp, F             ; Count down number of bytes
  113. 0005A2 E1FC           00662         bnz     USBCtrlTrfTxServiceRamLoop
  114. 0005A4 0711           00663         decf    usb_temp + 1, F
  115. 0005A6 E2FA           00664         bc      USBCtrlTrfTxServiceRamLoop
  116. 0005A8 CFE1 F412      00665         movff   FSR1L, pSrc             ; Update source pointer
  117. 0005AC CFE2 F413      00666         movff   FSR1H, pSrc + 1
  118. 0005B0                00667 USBCtrlTrfTxServiceExit
  119. 0005B0 0012           00668         return
  120.                       00669         
  121.                       00670 
  122.                       00671 ; From usbctrltrf.c line 330
  123.                       00672 ;/******************************************************************************
  124.                       00673 ; * Function:        void USBCtrlTrfRxService(void)
  125.                       00674 ; *
  126.                       00675 ; * PreCondition:    pDst and wCount are setup properly.
  127.                       00676 ; *                  pSrc is always &CtrlTrfData
  128.                       00677 ; *                  usb_stat.ctrl_trf_mem is always _RAM.
  129.                       00678 ; *                  wCount should be set to 0 at the start of each control
  130.                       00679 ; *                  transfer.
  131.                       00680 ; *
  132.                       00681 ; * Input:           None
  133.                       00682 ; *
  134.                       00683 ; * Output:          None
  135.                       00684 ; *
  136.                       00685 ; * Side Effects:    None
  137.                       00686 ; *
  138.                       00687 ; * Overview:        Transfers bytes received, at EP0 OUT buffer CtrlTrfData,
  139.                       00688 ; *                  to user's buffer pointed by pDst.
  140.                       00689 ; *                  This routine only knows how to handle raw byte data.
  141.                       00690 ; *                  HIDmaker handles transferring and unpacking by a callback
  142.                       00691 ; *                  function in the generated main program, called from here.
  143.                       00692 ; *
  144. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE 39
  145. LOC  OBJECT CODE     LINE SOURCE TEXT
  146.   VALUE
  147.                       00693 ; * Note:            None
  148.                       00694 ; *****************************************************************************/
  149. 0005B2                00695 USBCtrlTrfRxService
  150.                       00696 ;       movlb   high 0x400              ; Point to proper bank
  151. 0005B2 5101           00697         movf    ep0Bo + Cnt, W          ; Get low number of bytes to read
  152. 0005B4 6F10           00698         movwf   usb_temp                ; usb_temp & usb_temp + 1 are bytes to read
  153. 0005B6 2718           00699         addwf   wCount, F               ; Accumulate total number of bytes read
  154. 0005B8 5100           00700         movf    ep0Bo + Stat, W         ; Get high bits to read
  155. 0005BA 0B03           00701         andlw   0x03                    ; Mask to the count
  156. 0005BC 6F11           00702         movwf   usb_temp + 1            ; Save to high byte of bytes to read
  157. 0005BE 2319           00703         addwfc  wCount + 1, F           ; Add overflow from low byte (C) and high byte to total number
  158. 0005C0 EE14 F05E      00704         lfsr    1, CtrlTrfData          ; Point FSR1 to source
  159. 0005C4 C414 FFD9      00705         movff   pDst, FSR2L             ; Move destination pointer to FSR2
  160. 0005C8 C415 FFDA      00706         movff   pDst + 1, FSR2H
  161. 0005CC 5111           00707         movf    usb_temp + 1, W         ; Check high byte for 0
  162. 0005CE E102           00708         bnz     USBCtrlTrfRxServiceLoop ; High byte not 0, must have something to do
  163. 0005D0 5110           00709         movf    usb_temp, W             ; Check low byte for 0
  164. 0005D2 E00A           00710         bz      USBCtrlTrfRxServiceExit ; If both 0 then nothing to send this time
  165. 0005D4                00711 USBCtrlTrfRxServiceLoop
  166. 0005D4 CFE6 FFDE      00712         movff   POSTINC1, POSTINC2      ; Copy one buffer to the other
  167. 0005D8 0710           00713         decf    usb_temp, F             ; Count down number of bytes
  168. 0005DA E1FC           00714         bnz     USBCtrlTrfRxServiceLoop
  169. 0005DC 0711           00715         decf    usb_temp + 1, F
  170. 0005DE E2FA           00716         bc      USBCtrlTrfRxServiceLoop
  171. 0005E0 CFD9 F414      00717         movff   FSR2L, pDst             ; Update destination pointer
  172. 0005E4 CFDA F415      00718         movff   FSR2H, pDst + 1
  173. 0005E8                00719 USBCtrlTrfRxServiceExit
  174. 0005E8 0012           00720         return
  175.                       00721 
  176.                       00722 
  177.                       00723 ; From usbctrltrf.c line 382
  178.                       00724 ;/******************************************************************************
  179.                       00725 ; * Function:        void USBCtrlEPServiceComplete(void)
  180.                       00726 ; *
  181.                       00727 ; * PreCondition:    None
  182.                       00728 ; *
  183.                       00729 ; * Input:           None
  184.                       00730 ; *
  185.                       00731 ; * Output:          None
  186.                       00732 ; *
  187.                       00733 ; * Side Effects:    None
  188.                       00734 ; *
  189.                       00735 ; * Overview:        This routine wrap up the ramaining tasks in servicing
  190.                       00736 ; *                  a Setup Request. Its main task is to set the endpoint
  191.                       00737 ; *                  controls appropriately for a given situation. See code
  192.                       00738 ; *                  below.
  193.                       00739 ; *                  There are three main scenarios:
  194.                       00740 ; *                  a) There was no handler for the Request, in this case
  195.                       00741 ; *                     a STALL should be sent out.
  196.                       00742 ; *                  b) The host has requested a read control transfer,
  197.                       00743 ; *                     endpoints are required to be setup in a specific way.
  198.                       00744 ; *                  c) The host has requested a write control transfer, or
  199.                       00745 ; *                     a control data stage is not required, endpoints are
  200. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE 40
  201. LOC  OBJECT CODE     LINE SOURCE TEXT
  202.   VALUE
  203.                       00746 ; *                     required to be setup in a specific way.
  204.                       00747 ; *
  205.                       00748 ; *                  Packet processing is resumed by clearing PKTDIS bit.
  206.                       00749 ; *
  207.                       00750 ; * Note:            None
  208.                       00751 ; *****************************************************************************/
  209. 0005EA                00752 USBCtrlEPServiceComplete
  210.                       00753 ;       movlb   high 0x400              ; Point to proper bank
  211. 0005EA 0E00           00754         movlw   MUID_NULL
  212. 0005EC 6317           00755         cpfseq  ctrl_trf_session_owner
  213. 0005EE D00A           00756         bra     USBCtrlEPServiceComplete1
  214.                       00757 ;
  215.                       00758 ; No handlers claimed ownership of this Setup packet.
  216.                       00759 ; If no one knows how to service this request then stall.
  217.                       00760 ; Must also prepare EP0 to receive the next SETUP transaction.
  218. 0005F0 0E40           00761         movlw   EP0_BUFF_SIZE
  219. 0005F2 6F01           00762         movwf   ep0Bo + Cnt
  220. 0005F4 0E1E           00763         movlw   low SetupPkt
  221. 0005F6 6F02           00764         movwf   ep0Bo + ADRL
  222. 0005F8 0E04           00765         movlw   high SetupPkt
  223. 0005FA 6F03           00766         movwf   ep0Bo + ADRH
  224. 0005FC 0E84           00767         movlw   _USIE|_BSTALL
  225. 0005FE 6F00           00768         movwf   ep0Bo + Stat
  226.                       00769 ;       movlw   _USIE|_BSTALL
  227. 000600 6F04           00770         movwf   ep0Bi + Stat
  228. 000602 D02C           00771         bra     USBCtrlEPServiceCompleteExit
  229.                       00772 ;
  230.                       00773 ; A module has claimed ownership of the control transfer session.
  231. 000604                00774 USBCtrlEPServiceComplete1
  232. 000604 AF1E           00775         btfss   SetupPkt, DataDir
  233. 000606 D01D           00776         bra     USBCtrlEPServiceComplete2
  234. 000608 5119           00777         movf    wCount + 1, W           ; Make sure count does not exceed max length requested by Host
  235. 00060A 5D25           00778         subwf   SetupPkt + wLength + 1, W
  236. 00060C E304           00779         bnc     USBCtrlEPServiceCompleteCopy
  237. 00060E E107           00780         bnz     USBCtrlEPServiceComplete11
  238. 000610 5118           00781         movf    wCount, W
  239. 000612 5D24           00782         subwf   SetupPkt + wLength, W
  240. 000614 E204           00783         bc      USBCtrlEPServiceComplete11
  241. 000616                00784 USBCtrlEPServiceCompleteCopy
  242. 000616 C424 F418      00785         movff   SetupPkt + wLength, wCount      ; Set count to maximum
  243. 00061A C425 F419      00786         movff   SetupPkt + wLength + 1, wCount + 1
  244.                       00787 ;
  245.                       00788 ; Setup packet's data direction is "Device to Host"
  246. 00061E                00789 USBCtrlEPServiceComplete11
  247. 00061E DF89           00790         rcall   USBCtrlTrfTxService    ; Actually copy the data to EP0 IN buffer
  248. 000620 0E01           00791         movlw   CTRL_TRF_TX
  249. 000622 6F16           00792         movwf   ctrl_trf_state
  250.                       00793 ; Control Read:
  251.                       00794 ; <SETUP[0]><IN[1]><IN[0]>...<OUT[1]> | <SETUP[0]>
  252.                       00795 ; 1. Prepare OUT EP to respond to early termination
  253.                       00796 ;
  254.                       00797 ; NOTE:
  255.                       00798 ; If something went wrong during the control transfer,
  256. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE 41
  257. LOC  OBJECT CODE     LINE SOURCE TEXT
  258.   VALUE
  259.                       00799 ; the last status stage may not be sent by the host.
  260.                       00800 ; When this happens, two different things could happen
  261.                       00801 ; depending on the host.
  262.                       00802 ; a) The host could send out a RESET.
  263.                       00803 ; b) The host could send out a new SETUP transaction
  264.                       00804 ;    without sending a RESET first.
  265.                       00805 ; To properly handle case (b), the OUT EP must be setup
  266.                       00806 ; to receive either a zero length OUT transaction, or a
  267.                       00807 ; new SETUP transaction.
  268.                       00808 ;
  269.                       00809 ; Since the SETUP transaction requires the DTS bit to be
  270.                       00810 ; DAT0 while the zero length OUT status requires the DTS
  271.                       00811 ; bit to be DAT1, the DTS bit check by the hardware should
  272.                       00812 ; be disabled. This way the SIE could accept either of
  273.                       00813 ; the two transactions.
  274.                       00814 ;
  275.                       00815 ; Furthermore, the Cnt byte should be set to prepare for
  276.                       00816 ; the SETUP data (8-byte or more), and the buffer address
  277.                       00817 ; should be pointed to SetupPkt.
  278. 000624 0E40           00818         movlw   EP0_BUFF_SIZE
  279. 000626 6F01           00819         movwf   ep0Bo + Cnt
  280. 000628 0E1E           00820         movlw   low SetupPkt
  281. 00062A 6F02           00821         movwf   ep0Bo + ADRL
  282. 00062C 0E04           00822         movlw   high SetupPkt
  283. 00062E 6F03           00823         movwf   ep0Bo + ADRH
  284. 000630 0E80           00824         movlw   _USIE                   ; Note: DTSEN is 0!
  285. 000632 6F00           00825         movwf   ep0Bo + Stat
  286.                       00826 ; 2. Prepare IN EP to transfer data, Cnt should have
  287.                       00827 ;    been initialized by responsible request owner.
  288. 000634 0E5E           00828         movlw   low CtrlTrfData
  289. 000636 6F06           00829         movwf   ep0Bi + ADRL
  290. 000638 0E04           00830         movlw   high CtrlTrfData
  291. 00063A 6F07           00831         movwf   ep0Bi + ADRH
  292. 00063C 0EC8           00832         movlw   _USIE|_DAT1|_DTSEN
  293. 00063E 6F04           00833         movwf   ep0Bi + Stat
  294. 000640 D00D           00834         bra     USBCtrlEPServiceCompleteExit
  295.                       00835 ;
  296.                       00836 ; Setup packet's data direction is "Host to Device"
  297. 000642                00837 USBCtrlEPServiceComplete2
  298. 000642 0E02           00838         movlw   CTRL_TRF_RX
  299. 000644 6F16           00839         movwf   ctrl_trf_state
  300.                       00840 ; Control Write:
  301.                       00841 ; <SETUP[0]><OUT[1]><OUT[0]>...<IN[1]> | <SETUP[0]>
  302.                       00842 ;
  303.                       00843 ; 1. Prepare IN EP to respond to early termination
  304.                       00844 ;
  305.                       00845 ;    This is the same as a Zero Length Packet Response
  306.                       00846 ;    for control transfer without a data stage
  307. 000646 6B05           00847         clrf    ep0Bi + Cnt
  308. 000648 0EC8           00848         movlw   _USIE|_DAT1|_DTSEN
  309. 00064A 6F04           00849         movwf   ep0Bi + Stat
  310.                       00850 ; 2. Prepare OUT EP to receive data.
  311. 00064C 0E40           00851         movlw   EP0_BUFF_SIZE
  312. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE 42
  313. LOC  OBJECT CODE     LINE SOURCE TEXT
  314.   VALUE
  315. 00064E 6F01           00852         movwf   ep0Bo + Cnt
  316. 000650 0E5E           00853         movlw   low CtrlTrfData
  317. 000652 6F02           00854         movwf   ep0Bo + ADRL
  318. 000654 0E04           00855         movlw   high CtrlTrfData
  319. 000656 6F03           00856         movwf   ep0Bo + ADRH
  320. 000658 0EC8           00857         movlw   _USIE|_DAT1|_DTSEN
  321. 00065A 6F00           00858         movwf   ep0Bo + Stat
  322.                       00859 ;
  323. 00065C                00860 USBCtrlEPServiceCompleteExit
  324.                       00861 ; PKTDIS bit is set when a Setup Transaction is received.
  325.                       00862 ; Clear to resume packet processing.
  326. 00065C 986D           00863         bcf     UCON, PKTDIS
  327. 00065E 0012           00864         return
  328.                       00865 
  329.                       00866 
  330.                       00867 ; From usbctrltrf.c line 490
  331.                       00868 ;/******************************************************************************
  332.                       00869 ; * Function:        void USBPrepareForNextSetupTrf(void)
  333.                       00870 ; *
  334.                       00871 ; * PreCondition:    None
  335.                       00872 ; *
  336.                       00873 ; * Input:           None
  337.                       00874 ; *
  338.                       00875 ; * Output:          None
  339.                       00876 ; *
  340.                       00877 ; * Side Effects:    None
  341.                       00878 ; *
  342.                       00879 ; * Overview:        The routine forces EP0 OUT to be ready for a new Setup
  343.                       00880 ; *                  transaction, and forces EP0 IN to be owned by CPU.
  344.                       00881 ; *
  345.                       00882 ; * Note:            None
  346.                       00883 ; *****************************************************************************/
  347. 000660                00884 USBPrepareForNextSetupTrf
  348.                       00885 ;       movlb   high 0x400              ; Point to proper bank
  349. 000660 0E00           00886         movlw   WAIT_SETUP
  350. 000662 6F16           00887         movwf   ctrl_trf_state
  351. 000664 0E40           00888         movlw   EP0_BUFF_SIZE
  352. 000666 6F01           00889         movwf   ep0Bo + Cnt
  353. 000668 0E1E           00890         movlw   low SetupPkt
  354. 00066A 6F02           00891         movwf   ep0Bo + ADRL
  355. 00066C 0E04           00892         movlw   high SetupPkt
  356. 00066E 6F03           00893         movwf   ep0Bo + ADRH
  357. 000670 0E88           00894         movlw   _USIE|_DAT0|_DTSEN      ; EP0 buff dsc init
  358. 000672 6F00           00895         movwf   ep0Bo + Stat
  359. 000674 0E00           00896         movlw   _UCPU                   ; EP0 IN buffer initialization
  360. 000676 6F04           00897         movwf   ep0Bi + Stat
  361. 000678 0012           00898         return
  362.                       00899 
  363.                       00900 
  364.                       00901 
  365.                       00902 ; From usbdrv.c line ???
  366.                       00903 ;/******************************************************************************
  367.                       00904 ; * Function:        void InitializeUSBDriver(void)
  368. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE 43
  369. LOC  OBJECT CODE     LINE SOURCE TEXT
  370.   VALUE
  371.                       00905 ; *
  372.                       00906 ; * PreCondition:    None
  373.                       00907 ; *
  374.                       00908 ; * Input:           None
  375.                       00909 ; *
  376.                       00910 ; * Output:          None
  377.                       00911 ; *
  378.                       00912 ; * Side Effects:    None
  379.                       00913 ; *
  380.                       00914 ; * Overview:        This routine initializes variables used by the USB library
  381.                       00915 ; *                  routines.
  382.                       00916 ; *
  383.                       00917 ; * Note:            None
  384.                       00918 ; *****************************************************************************/
  385. 00067A                00919 InitializeUSBDriver
  386. 00067A 0104           00920         movlb   high 0x400              ; Point to proper bank
  387. 00067C 0E14           00921         movlw   UCFG_VAL
  388. 00067E 6E6F           00922         movwf   UCFG
  389. 000680 0E00           00923         movlw   DETACHED_STATE
  390. 000682 6F1A           00924         movwf   usb_device_state
  391. 000684 6B1D           00925         clrf    usb_stat
  392. 000686 6B1B           00926         clrf    usb_active_cfg
  393.                       00927 #ifdef USB_USE_HID
  394. 000688 D8D9           00928         rcall   HIDInitEP
  395.                       00929 #endif
  396.                       00930 #ifdef USB_USE_CDC
  397.                       00931         rcall   CDCInitEP
  398.                       00932 #endif
  399. 00068A 0012           00933         return
  400.                       00934 
  401.                       00935         
  402.                       00936 ; From usbdrv.c line 76
  403.                       00937 ;/******************************************************************************
  404.                       00938 ; * Function:        void USBCheckBusStatus(void)
  405.                       00939 ; *
  406.                       00940 ; * PreCondition:    None
  407.                       00941 ; *
  408.                       00942 ; * Input:           None
  409.                       00943 ; *
  410.                       00944 ; * Output:          None
  411.                       00945 ; *
  412.                       00946 ; * Side Effects:    None
  413.                       00947 ; *
  414.                       00948 ; * Overview:        This routine enables/disables the USB module by monitoring
  415.                       00949 ; *                  the USB power signal.
  416.                       00950 ; *
  417.                       00951 ; * Note:            None
  418.                       00952 ; *****************************************************************************/
  419. 00068C                00953 USBCheckBusStatus
  420. 00068C 0104           00954         movlb   high 0x400              ; Point to proper bank
  421.                       00955 ; Bus Attachment & Detachment Detection
  422.                       00956 ; usb_bus_sense is an i/o pin defined in io_cfg.h
  423.                       00957 #ifdef USE_USB_BUS_SENSE_IO
  424. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE 44
  425. LOC  OBJECT CODE     LINE SOURCE TEXT
  426.   VALUE
  427.                       00958         btfss   usb_bus_sense           ; Is USB bus attached?
  428.                       00959         bra     USBCheckBusStatusDetached       ; No
  429.                       00960 #endif
  430. 00068E A66D           00961         btfss   UCON, USBEN             ; Is the module off?
  431. 000690 D80C           00962         rcall   USBModuleEnable         ; Is off, enable it
  432.                       00963 #ifdef USE_USB_BUS_SENSE_IO
  433.                       00964         bra     USBCheckBusStatus1
  434.                       00965 USBCheckBusStatusDetached
  435.                       00966         btfsc   UCON, USBEN             ; Is the module on?
  436.                       00967         rcall   USBModuleDisable        ; Is on, disable it
  437.                       00968 #endif
  438.                       00969 ;
  439.                       00970 ; After enabling the USB module, it takes some time for the voltage
  440.                       00971 ; on the D+ or D- line to rise high enough to get out of the SE0 condition.
  441.                       00972 ; The USB Reset interrupt should not be unmasked until the SE0 condition is
  442.                       00973 ; cleared. This helps preventing the firmware from misinterpreting this
  443.                       00974 ; unique event as a USB bus reset from the USB host.
  444. 000692                00975 USBCheckBusStatus1
  445. 000692 0E01           00976         movlw   ATTACHED_STATE
  446. 000694 631A           00977         cpfseq  usb_device_state
  447. 000696 0012           00978         return
  448. 000698 BA6D           00979         btfsc   UCON, SE0
  449. 00069A 0012           00980         return
  450. 00069C 6A68           00981         clrf    UIR                     ; Clear all USB interrupts
  451. 00069E 6A69           00982         clrf    UIE                     ; Mask all USB interrupts
  452. 0006A0 8069           00983         bsf     UIE, URSTIE             ; Unmask RESET interrupt
  453. 0006A2 8869           00984         bsf     UIE, IDLEIE             ; Unmask IDLE interrupt
  454. 0006A4 0E02           00985         movlw   POWERED_STATE
  455. 0006A6 6F1A           00986         movwf   usb_device_state
  456. 0006A8 0012           00987         return
  457.                       00988 
  458.                       00989 
  459.                       00990 ; From usbdrv.c line 135
  460. 0006AA                00991 USBModuleEnable
  461.                       00992 ;       movlb   high 0x400              ; Point to proper bank
  462. 0006AA 6A6D           00993         clrf    UCON
  463. 0006AC 6A69           00994         clrf    UIE                     ; Mask all USB interrupts
  464. 0006AE 866D           00995         bsf     UCON, USBEN             ; Enable module & attach to bus
  465. 0006B0 0E01           00996         movlw   ATTACHED_STATE
  466. 0006B2 6F1A           00997         movwf   usb_device_state
  467. 0006B4 0012           00998         return
  468.                       00999 
  469.                       01000 
  470.                       01001 ; From usbdrv.c line 192
  471. 0006B6                01002 USBSoftDetach
  472.                       01003 ; From usbdrv.c line 161
  473. 0006B6                01004 USBModuleDisable
  474. 0006B6 0104           01005         movlb   high 0x400              ; Point to proper bank
  475. 0006B8 6A6D           01006         clrf    UCON                    ; Disable module & detach from bus
  476. 0006BA 6A69           01007         clrf    UIE                     ; Mask all USB interrupts
  477. 0006BC 0E00           01008         movlw   DETACHED_STATE
  478. 0006BE 6F1A           01009         movwf   usb_device_state
  479. 0006C0 0012           01010         return
  480. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE 45
  481. LOC  OBJECT CODE     LINE SOURCE TEXT
  482.   VALUE
  483.                       01011 
  484.                       01012 
  485.                       01013 ; From usbdrv.c line 215
  486.                       01014 ;/******************************************************************************
  487.                       01015 ; * Function:        void USBDriverService(void)
  488.                       01016 ; *
  489.                       01017 ; * PreCondition:    None
  490.                       01018 ; *
  491.                       01019 ; * Input:           None
  492.                       01020 ; *
  493.                       01021 ; * Output:          None
  494.                       01022 ; *
  495.                       01023 ; * Side Effects:    None
  496.                       01024 ; *
  497.                       01025 ; * Overview:        This routine is the heart of this firmware. It manages
  498.                       01026 ; *                  all USB interrupts.
  499.                       01027 ; *
  500.                       01028 ; * Note:            Device state transitions through the following stages:
  501.                       01029 ; *                  DETACHED -> ATTACHED -> POWERED -> DEFAULT ->
  502.                       01030 ; *                  ADDRESS_PENDING -> ADDRESSED -> CONFIGURED -> READY
  503.                       01031 ; *****************************************************************************/
  504. 0006C2                01032 USBDriverService
  505. 0006C2 0104           01033         movlb   high 0x400              ; Point to proper bank
  506. 0006C4 0E00           01034         movlw   DETACHED_STATE
  507. 0006C6 5D1A           01035         subwf   usb_device_state, W
  508. 0006C8 E023           01036         bz      USBDriverServiceExit    ; Pointless to continue servicing
  509.                       01037                                         ; if USB cable is not even attached.
  510.                       01038 ;
  511.                       01039 ; Task A: Service USB Activity Interrupt
  512. 0006CA A468           01040         btfss   UIR, ACTVIF
  513. 0006CC D002           01041         bra     USBDriverService1
  514. 0006CE B469           01042         btfsc   UIE, ACTVIE
  515. 0006D0 D824           01043         rcall   USBWakeFromSuspend
  516.                       01044 ;
  517. 0006D2                01045 USBDriverService1
  518. 0006D2 B26D           01046         btfsc   UCON, SUSPND            ; Are we suspended?
  519. 0006D4 0012           01047         return                          ; Pointless to continue servicing if the device is in suspend mo
  520.                             de.
  521.                       01048 ;
  522.                       01049 ; Task B: Service USB Bus Reset Interrupt.
  523.                       01050 ; When bus reset is received during suspend, ACTVIF will be set first,
  524.                       01051 ; once the UCONbits.SUSPND is clear, then the URSTIF bit will be asserted.
  525.                       01052 ; This is why URSTIF is checked after ACTVIF.
  526.                       01053 ;
  527.                       01054 ; The USB reset flag is masked when the USB state is in
  528.                       01055 ; DETACHED_STATE or ATTACHED_STATE, and therefore cannot
  529.                       01056 ; cause a USB reset event during these two states.
  530. 0006D6 A068           01057         btfss   UIR, URSTIF        ; USB Bus Reset Interrupt?
  531. 0006D8 D002           01058         bra     USBDriverService2
  532. 0006DA B069           01059         btfsc   UIE, URSTIE
  533. 0006DC D839           01060         rcall   USBProtocolResetHandler
  534.                       01061 ;
  535.                       01062 ; Task C: Check & service other USB interrupts
  536. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE 46
  537. LOC  OBJECT CODE     LINE SOURCE TEXT
  538.   VALUE
  539. 0006DE                01063 USBDriverService2
  540. 0006DE A868           01064         btfss   UIR, IDLEIF
  541. 0006E0 D002           01065         bra     USBDriverService3
  542. 0006E2 B869           01066         btfsc   UIE, IDLEIE
  543. 0006E4 D816           01067         rcall   USBSuspend
  544. 0006E6                01068 USBDriverService3
  545. 0006E6 AC68           01069         btfss   UIR, SOFIF
  546. 0006E8 D002           01070         bra     USBDriverService4
  547. 0006EA BC69           01071         btfsc   UIE, SOFIE
  548. 0006EC D828           01072         rcall   USB_SOF_Handler
  549. 0006EE                01073 USBDriverService4
  550. 0006EE AA68           01074         btfss   UIR, STALLIF
  551. 0006F0 D002           01075         bra     USBDriverService5
  552. 0006F2 BA69           01076         btfsc   UIE, STALLIE
  553. 0006F4 D826           01077         rcall   USBStallHandler
  554. 0006F6                01078 USBDriverService5
  555. 0006F6 A268           01079         btfss   UIR, UERRIF
  556. 0006F8 D002           01080         bra     USBDriverService6
  557. 0006FA B269           01081         btfsc   UIE, UERRIE
  558. 0006FC D827           01082         rcall   USBErrorHandler
  559.                       01083 ;
  560.                       01084 ; Pointless to continue servicing if the host has not sent a bus reset.
  561.                       01085 ; Once bus reset is received, the device transitions into the DEFAULT
  562.                       01086 ;     * state and is ready for communication.
  563. 0006FE                01087 USBDriverService6
  564. 0006FE 0E03           01088         movlw   DEFAULT_STATE
  565. 000700 5D1A           01089         subwf   usb_device_state, W
  566. 000702 E306           01090         bnc     USBDriverServiceExit
  567.                       01091 ;
  568.                       01092 ; Task D: Servicing USB Transaction Complete Interrupt
  569. 000704 A668           01093         btfss   UIR, TRNIF
  570. 000706 D004           01094         bra     USBDriverServiceExit
  571. 000708 A669           01095         btfss   UIE, TRNIE
  572. 00070A D002           01096         bra     USBDriverServiceExit
  573.                       01097 ;
  574.                       01098 ; USBCtrlEPService only services transactions over EP0.
  575.                       01099 ; It ignores all other EP transactions.
  576. 00070C DEDF           01100         rcall   USBCtrlEPService
  577.                       01101 ; Other EPs can be serviced later by responsible device class firmware.
  578.                       01102 ; Each device driver knows when an OUT or IN transaction is ready by
  579.                       01103 ; checking the buffer ownership bit.
  580.                       01104 ; An OUT EP should always be owned by SIE until the data is ready.
  581.                       01105 ; An IN EP should always be owned by CPU until the data is ready.
  582.                       01106 ;
  583.                       01107 ; Because of this logic, it is not necessary to save the USTAT value
  584.                       01108 ; of non-EP0 transactions.
  585. 00070E 9668           01109         bcf     UIR, TRNIF
  586. 000710                01110 USBDriverServiceExit
  587. 000710 0012           01111         return
  588.                       01112 
  589.                       01113         
  590.                       01114 ; From usbdrv.c line 301
  591.                       01115 ;/******************************************************************************
  592. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE 47
  593. LOC  OBJECT CODE     LINE SOURCE TEXT
  594.   VALUE
  595.                       01116 ; * Function:        void USBSuspend(void)
  596.                       01117 ; *
  597.                       01118 ; * PreCondition:    None
  598.                       01119 ; *
  599.                       01120 ; * Input:           None
  600.                       01121 ; *
  601.                       01122 ; * Output:          None
  602.                       01123 ; *
  603.                       01124 ; * Side Effects:    None
  604.                       01125 ; *
  605.                       01126 ; * Overview:
  606.                       01127 ; *
  607.                       01128 ; * Note:            None
  608.                       01129 ; *****************************************************************************/
  609. 000712                01130 USBSuspend
  610.                       01131 ; NOTE: Do not clear UIRbits.ACTVIF here!
  611.                       01132 ; Reason:
  612.                       01133 ; ACTVIF is only generated once an IDLEIF has been generated.
  613.                       01134 ; This is a 1:1 ratio interrupt generation.
  614.                       01135 ; For every IDLEIF, there will be only one ACTVIF regardless of
  615.                       01136 ; the number of subsequent bus transitions.
  616.                       01137 ;
  617.                       01138 ; If the ACTIF is cleared here, a problem could occur when:
  618.                       01139 ; [       IDLE       ][bus activity ->
  619.                       01140 ; <--- 3 ms ----->     ^
  620.                       01141 ;                ^     ACTVIF=1
  621.                       01142 ;                IDLEIF=1
  622.                       01143 ;  #           #           #           #   (#=Program polling flags)
  623.                       01144 ;                          ^
  624.                       01145 ;                          This polling loop will see both
  625.                       01146 ;                          IDLEIF=1 and ACTVIF=1.
  626.                       01147 ;                          However, the program services IDLEIF first
  627.                       01148 ;                          because ACTIVIE=0.
  628.                       01149 ;                          If this routine clears the only ACTIVIF,
  629.                       01150 ;                          then it can never get out of the suspend
  630.                       01151 ;                          mode.
  631. 000712 8469           01152         bsf     UIE, ACTVIE             ; Enable bus activity interrupt
  632. 000714 9868           01153         bcf     UIR, IDLEIF
  633. 000716 826D           01154         bsf     UCON, SUSPND            ; Put USB module in power conserve
  634.                       01155 ; At this point the PIC can go into sleep,idle, or
  635.                       01156 ; switch to a slower clock, etc.
  636. 000718 0012           01157         return
  637.                       01158 
  638.                       01159 
  639.                       01160 ; From usbdrv.c line 353
  640.                       01161 ;/******************************************************************************
  641.                       01162 ; * Function:        void USBWakeFromSuspend(void)
  642.                       01163 ; *
  643.                       01164 ; * PreCondition:    None
  644.                       01165 ; *
  645.                       01166 ; * Input:           None
  646.                       01167 ; *
  647.                       01168 ; * Output:          None
  648. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE 48
  649. LOC  OBJECT CODE     LINE SOURCE TEXT
  650.   VALUE
  651.                       01169 ; *
  652.                       01170 ; * Side Effects:    None
  653.                       01171 ; *
  654.                       01172 ; * Overview:
  655.                       01173 ; *
  656.                       01174 ; * Note:            None
  657.                       01175 ; *****************************************************************************/
  658. 00071A                01176 USBWakeFromSuspend
  659.                       01177 ; If using clock switching, this is the place to restore the
  660.                       01178 ; original clock frequency.
  661. 00071A 926D           01179         bcf     UCON, SUSPND
  662. 00071C 9469           01180         bcf     UIE, ACTVIE
  663. 00071E 9468           01181         bcf     UIR, ACTVIF
  664. 000720 0012           01182         return
  665.                       01183 
  666.                       01184 
  667.                       01185 ; From usbdrv.c line 402
  668.                       01186 ;/******************************************************************************
  669.                       01187 ; * Function:        void USBRemoteWakeup(void)
  670.                       01188 ; *
  671.                       01189 ; * PreCondition:    None
  672.                       01190 ; *
  673.                       01191 ; * Input:           None
  674.                       01192 ; *
  675.                       01193 ; * Output:          None
  676.                       01194 ; *
  677.                       01195 ; * Side Effects:    None
  678.                       01196 ; *
  679.                       01197 ; * Overview:        This function should be called by user when the device
  680.                       01198 ; *                  is waken up by an external stimulus other than ACTIVIF.
  681.                       01199 ; *                  Please read the note below to understand the limitations.
  682.                       01200 ; *
  683.                       01201 ; * Note:            The modifiable section in this routine should be changed
  684.                       01202 ; *                  to meet the application needs. Current implementation
  685.                       01203 ; *                  temporary blocks other functions from executing for a
  686.                       01204 ; *                  period of 1-13 ms depending on the core frequency.
  687.                       01205 ; *
  688.                       01206 ; *                  According to USB 2.0 specification section 7.1.7.7,
  689.                       01207 ; *                  "The remote wakeup device must hold the resume signaling
  690.                       01208 ; *                  for at lest 1 ms but for no more than 15 ms."
  691.                       01209 ; *                  The idea here is to use a delay counter loop, using a
  692.                       01210 ; *                  common value that would work over a wide range of core
  693.                       01211 ; *                  frequencies.
  694.                       01212 ; *                  That value selected is 1800. See table below:
  695.                       01213 ; *                  ==========================================================
  696.                       01214 ; *                  Core Freq(MHz)      MIP         RESUME Signal Period (ms)
  697.                       01215 ; *                  ==========================================================
  698.                       01216 ; *                      48              12          1.05
  699.                       01217 ; *                       4              1           12.6
  700.                       01218 ; *                  ==========================================================
  701.                       01219 ; *                  * These timing could be incorrect when using code
  702.                       01220 ; *                    optimization or extended instruction mode,
  703.                       01221 ; *                    or when having other interrupts enabled.
  704. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE 49
  705. LOC  OBJECT CODE     LINE SOURCE TEXT
  706.   VALUE
  707.                       01222 ; *                    Make sure to verify using the MPLAB SIM's Stopwatch
  708.                       01223 ; *****************************************************************************/
  709. 000722                01224 USBRemoteWakeup
  710. 000722 0104           01225         movlb   high 0x400              ; Point to proper bank
  711. 000724 A11D           01226         btfss   usb_stat, RemoteWakeup  ; Check if RemoteWakeup function has been enabled by the host.
  712. 000726 0012           01227         return                          ; No
  713. 000728 DFF8           01228         rcall   USBWakeFromSuspend      ; Unsuspend USB modue
  714. 00072A 846D           01229         bsf     UCON, RESUME            ; Start RESUME signaling
  715. 00072C 0E10           01230         movlw   0x10                    ; Set RESUME line for 1-13 ms
  716. 00072E 6EDA           01231         movwf   FSR2H                   ; Using FSR2 as temp
  717. 000730 6AD9           01232         clrf    FSR2L
  718. 000732                01233 USBRemoteWakeupLoop
  719. 000732 2ED9           01234         decfsz  FSR2L, F
  720. 000734 D7FE           01235         bra     USBRemoteWakeupLoop
  721. 000736 2EDA           01236         decfsz  FSR2H, F
  722. 000738 D7FC           01237         bra     USBRemoteWakeupLoop
  723. 00073A 946D           01238         bcf     UCON, RESUME
  724. 00073C 0012           01239         return
  725.                       01240 
  726.                       01241 
  727.                       01242 ; From usbdrv.c line 443
  728.                       01243 ;/******************************************************************************
  729.                       01244 ; * Function:        void USB_SOF_Handler(void)
  730.                       01245 ; *
  731.                       01246 ; * PreCondition:    None
  732.                       01247 ; *
  733.                       01248 ; * Input:           None
  734.                       01249 ; *
  735.                       01250 ; * Output:          None
  736.                       01251 ; *
  737.                       01252 ; * Side Effects:    None
  738.                       01253 ; *
  739.                       01254 ; * Overview:        The USB host sends out a SOF packet to full-speed devices
  740.                       01255 ; *                  every 1 ms. This interrupt may be useful for isochronous
  741.                       01256 ; *                  pipes. End designers should implement callback routine
  742.                       01257 ; *                  as necessary.
  743.                       01258 ; *
  744.                       01259 ; * Note:            None
  745.                       01260 ; *****************************************************************************/
  746. 00073E                01261 USB_SOF_Handler
  747.                       01262 ; Callback routine here
  748. 00073E 9C68           01263         bcf UIR, SOFIF
  749. 000740 0012           01264         return
  750.                       01265 
  751.                       01266 
  752.                       01267 ; From usbdrv.c line 486
  753.                       01268 ;/******************************************************************************
  754.                       01269 ; * Function:        void USBStallHandler(void)
  755.                       01270 ; *
  756.                       01271 ; * PreCondition:    A STALL packet is sent to the host by the SIE.
  757.                       01272 ; *
  758.                       01273 ; * Input:           None
  759.                       01274 ; *
  760. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE 50
  761. LOC  OBJECT CODE     LINE SOURCE TEXT
  762.   VALUE
  763.                       01275 ; * Output:          None
  764.                       01276 ; *
  765.                       01277 ; * Side Effects:    None
  766.                       01278 ; *
  767.                       01279 ; * Overview:        The STALLIF is set anytime the SIE sends out a STALL
  768.                       01280 ; *                  packet regardless of which endpoint causes it.
  769.                       01281 ; *                  A Setup transaction overrides the STALL function. A stalled
  770.                       01282 ; *                  endpoint stops stalling once it receives a setup packet.
  771.                       01283 ; *                  In this case, the SIE will accepts the Setup packet and
  772.                       01284 ; *                  set the TRNIF flag to notify the firmware. STALL function
  773.                       01285 ; *                  for that particular endpoint pipe will be automatically
  774.                       01286 ; *                  disabled (direction specific).
  775.                       01287 ; *
  776.                       01288 ; *                  There are a few reasons for an endpoint to be stalled.
  777.                       01289 ; *                  1. When a non-supported USB request is received.
  778.                       01290 ; *                     Example: GET_DESCRIPTOR(DEVICE_QUALIFIER)
  779.                       01291 ; *                  2. When an endpoint is currently halted.
  780.                       01292 ; *                  3. When the device class specifies that an endpoint must
  781.                       01293 ; *                     stall in response to a specific event.
  782.                       01294 ; *                     Example: Mass Storage Device Class
  783.                       01295 ; *                              If the CBW is not valid, the device shall
  784.                       01296 ; *                              STALL the Bulk-In pipe.
  785.                       01297 ; *                              See USB Mass Storage Class Bulk-only Transport
  786.                       01298 ; *                              Specification for more details.
  787.                       01299 ; *
  788.                       01300 ; * Note:            UEPn.EPSTALL can be scanned to see which endpoint causes
  789.                       01301 ; *                  the stall event.
  790.                       01302 ; *                  If
  791.                       01303 ; *****************************************************************************/
  792. 000742                01304 USBStallHandler
  793.                       01305 ; Does not really have to do anything here,
  794.                       01306 ; even for the control endpoint.
  795.                       01307 ; All BDs of Endpoint 0 are owned by SIE right now,
  796.                       01308 ; but once a Setup Transaction is received, the ownership
  797.                       01309 ; for EP0_OUT will be returned to CPU.
  798.                       01310 ; When the Setup Transaction is serviced, the ownership
  799.                       01311 ; for EP0_IN will then be forced back to CPU by firmware.
  800.                       01312 ;
  801.                       01313 ; NOTE: Above description is not quite true at this point.
  802.                       01314 ;       It seems the SIE never returns the UOWN bit to CPU,
  803.                       01315 ;       and a TRNIF is never generated upon successful
  804.                       01316 ;       reception of a SETUP transaction.
  805.                       01317 ;       Firmware work-around is implemented below.
  806.                       01318 ;
  807. 000742 B070           01319         btfsc   UEP0, EPSTALL
  808. 000744 DF8D           01320         rcall   USBPrepareForNextSetupTrf       ; Firmware Work-Around
  809. 000746 9070           01321         bcf     UEP0, EPSTALL
  810. 000748 9A68           01322         bcf     UIR, STALLIF
  811. 00074A 0012           01323         return
  812.                       01324 
  813.                       01325 ; From usbdrv.c line 528
  814.                       01326 ;/******************************************************************************
  815.                       01327 ; * Function:        void USBErrorHandler(void)
  816. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE 51
  817. LOC  OBJECT CODE     LINE SOURCE TEXT
  818.   VALUE
  819.                       01328 ; *
  820.                       01329 ; * PreCondition:    None
  821.                       01330 ; *
  822.                       01331 ; * Input:           None
  823.                       01332 ; *
  824.                       01333 ; * Output:          None
  825.                       01334 ; *
  826.                       01335 ; * Side Effects:    None
  827.                       01336 ; *
  828.                       01337 ; * Overview:        The purpose of this interrupt is mainly for debugging
  829.                       01338 ; *                  during development. Check UEIR to see which error causes
  830.                       01339 ; *                  the interrupt.
  831.                       01340 ; *
  832.                       01341 ; * Note:            None
  833.                       01342 ; *****************************************************************************/
  834. 00074C                01343 USBErrorHandler
  835. 00074C 9268           01344         bcf     UIR, UERRIF
  836. 00074E 0012           01345         return
  837.                       01346 
  838.                       01347 
  839.                       01348 ; From usbdrv.c line 555
  840.                       01349 ;/******************************************************************************
  841.                       01350 ; * Function:        void USBProtocolResetHandler(void)
  842.                       01351 ; *
  843.                       01352 ; * PreCondition:    A USB bus reset is received from the host.
  844.                       01353 ; *
  845.                       01354 ; * Input:           None
  846.                       01355 ; *
  847.                       01356 ; * Output:          None
  848.                       01357 ; *
  849.                       01358 ; * Side Effects:    Currently, this routine flushes any pending USB
  850.                       01359 ; *                  transactions. It empties out the USTAT FIFO. This action
  851.                       01360 ; *                  might not be desirable in some applications.
  852.                       01361 ; *
  853.                       01362 ; * Overview:        Once a USB bus reset is received from the host, this
  854.                       01363 ; *                  routine should be called. It resets the device address to
  855.                       01364 ; *                  zero, disables all non-EP0 endpoints, initializes EP0 to
  856.                       01365 ; *                  be ready for default communication, clears all USB
  857.                       01366 ; *                  interrupt flags, unmasks applicable USB interrupts, and
  858.                       01367 ; *                  reinitializes internal state-machine variables.
  859.                       01368 ; *
  860.                       01369 ; * Note:            None
  861.                       01370 ; *****************************************************************************/
  862. 000750                01371 USBProtocolResetHandler
  863.                       01372 ;       movlb   high 0x400              ; Point to proper bank
  864. 000750 6A6A           01373         clrf    UEIR                    ; Clear all USB error flags
  865. 000752 6A68           01374         clrf    UIR                     ; Clears all USB interrupts
  866. 000754 0E9F           01375         movlw   0x9f                    ; Unmask all USB error interrupts
  867. 000756 6E6B           01376         movwf   UEIE
  868. 000758 0E7B           01377         movlw   0x7b                    ; Enable all interrupts except ACTVIE
  869. 00075A 6E69           01378         movwf   UIE
  870. 00075C 6A6E           01379         clrf    UADDR                   ; Reset to default address
  871. 00075E EE2F F071      01380         lfsr    2, UEP1                 ; Reset all non-EP0 UEPn registers
  872. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE 52
  873. LOC  OBJECT CODE     LINE SOURCE TEXT
  874.   VALUE
  875. 000762 0E0F           01381         movlw   15
  876. 000764                01382 USBProtocolResetHandlerClearLoop
  877. 000764 6ADE           01383         clrf    POSTINC2
  878. 000766 2EE8           01384         decfsz  WREG, F
  879. 000768 D7FD           01385         bra     USBProtocolResetHandlerClearLoop
  880. 00076A 0E16           01386         movlw   EP_CTRL|HSHK_EN         ; Init EP0 as a Ctrl EP
  881. 00076C 6E70           01387         movwf   UEP0
  882. 00076E B668           01388         btfsc   UIR, TRNIF              ; Flush any pending transactions
  883. 000770                01389 USBProtocolResetHandlerFlushLoop
  884. 000770 9668           01390         bcf     UIR, TRNIF
  885. 000772 B668           01391         btfsc   UIR, TRNIF
  886. 000774 D7FD           01392         bra     USBProtocolResetHandlerFlushLoop
  887. 000776 986D           01393         bcf     UCON, PKTDIS            ; Make sure packet processing is enabled
  888. 000778 DF73           01394         rcall   USBPrepareForNextSetupTrf
  889. 00077A 911D           01395         bcf     usb_stat, RemoteWakeup  ; Default status flag to disable
  890. 00077C 6B1B           01396         clrf    usb_active_cfg          ; Clear active configuration
  891. 00077E 0E03           01397         movlw   DEFAULT_STATE
  892. 000780 6F1A           01398         movwf   usb_device_state
  893. 000782 0012           01399         return
  894.                       01400 
  895.                       01401 
  896.                       01402 
  897.                       01403 #ifdef USB_USE_HID
  898.                       01404 
  899.                       01405 ; From hid.c  line 72
  900.                       01406 ;/******************************************************************************
  901.                       01407 ; * Function:        void USBCheckHIDRequest(void)
  902.                       01408 ; *
  903.                       01409 ; * PreCondition:    None
  904.                       01410 ; *
  905.                       01411 ; * Input:           None
  906.                       01412 ; *
  907.                       01413 ; * Output:          None
  908.                       01414 ; *
  909.                       01415 ; * Side Effects:    None
  910.                       01416 ; *
  911.                       01417 ; * Overview:        This routine checks the setup data packet to see if it
  912.                       01418 ; *                  knows how to handle it
  913.                       01419 ; *
  914.                       01420 ; * Note:            None
  915.                       01421 ; *****************************************************************************/
  916. 000784                01422 USBCheckHIDRequest
  917. 000784 0104           01423         movlb   high 0x400              ; Point to proper bank
  918. 000786 511E           01424         movf    SetupPkt, W             ; Recipient = RCPT_INTF?
  919. 000788 0B1F           01425         andlw   0x1f                    ; Mask to lower 5 bits
  920. 00078A 0801           01426         sublw   RCPT_INTF
  921. 00078C E102           01427         bnz     USBCheckHIDRequestExit  ; No
  922. 00078E 0E00           01428         movlw   HID_INTF_ID             ; IntfID = HID_INTF_ID?
  923. 000790 6322           01429         cpfseq  SetupPkt + bIntfID
  924. 000792                01430 USBCheckHIDRequestExit
  925. 000792 0012           01431         return                          ; No
  926.                       01432 ;
  927.                       01433 ; There are two standard requests that hid.c may support.
  928. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE 53
  929. LOC  OBJECT CODE     LINE SOURCE TEXT
  930.   VALUE
  931.                       01434 ; 1. GET_DSC(DSC_HID,DSC_RPT,DSC_PHY);
  932.                       01435 ; 2. SET_DSC(DSC_HID,DSC_RPT,DSC_PHY);
  933.                       01436 ;
  934. 000794 0E06           01437         movlw   GET_DSC                 ; Request = GET_DSC?
  935. 000796 631F           01438         cpfseq  SetupPkt + bRequest
  936. 000798 D027           01439         bra     USBCheckHIDRequestClass ; No
  937. 00079A 0E21           01440         movlw   DSC_HID                 ; DscType = DSC_HID?
  938. 00079C 6321           01441         cpfseq  SetupPkt + bDscType
  939. 00079E D00F           01442         bra     USBCheckHIDRequest1     ; No
  940.                       01443         mSetSourcePointer HIDDescriptor1
  941. 0007A0 0EFE               M         movlw   low (HIDDescriptor1)
  942. 0007A2 6F12               M         movwf   pSrc
  943. 0007A4 0E01               M         movlw   high (HIDDescriptor1)
  944. 0007A6 6F13               M         movwf   pSrc + 1
  945.                       01444         mGetRomTableCount               ; Set wCount
  946. 0007A8 C412 FFF6          M         movff   pSrc, TBLPTRL           ; Set source address
  947. 0007AC C413 FFF7          M         movff   pSrc + 1, TBLPTRH
  948. 0007B0 6AF8               M         clrf    TBLPTRU
  949. 0007B2 0008               M         tblrd   *                       ; Read count
  950. 0007B4 CFF5 F418          M         movff   TABLAT, wCount
  951. 0007B8 6B19               M         clrf    wCount + 1
  952. 0007BA 831D           01445         bsf     usb_stat, ctrl_trf_mem  ; Indicate ROM
  953. 0007BC D03C           01446         bra     USBHIDSetSessionOwner
  954. 0007BE                01447 USBCheckHIDRequest1
  955. 0007BE 0E22           01448         movlw   DSC_RPT                 ; DscType = DSC_RPT?
  956. 0007C0 6321           01449         cpfseq  SetupPkt + bDscType
  957. 0007C2 D012           01450         bra     USBCheckHIDRequest2     ; No
  958.                       01451         mSetSourcePointer ReportDescriptor1
  959. 0007C4 0E2C               M         movlw   low (ReportDescriptor1)
  960. 0007C6 6F12               M         movwf   pSrc
  961. 0007C8 0E02               M         movlw   high (ReportDescriptor1)
  962. 0007CA 6F13               M         movwf   pSrc + 1
  963. 0007CC 0E0C           01452         movlw   low (ReportDescriptor1Len)      ; Set wCount
  964. 0007CE 6EF6           01453         movwf   TBLPTRL
  965. 0007D0 0E02           01454         movlw   high (ReportDescriptor1Len)
  966. 0007D2 6EF7           01455         movwf   TBLPTRH
  967. 0007D4 6AF8           01456         clrf    TBLPTRU
  968. 0007D6 0009           01457         tblrd   *+                      ; Read count low
  969. 0007D8 CFF5 F418      01458         movff   TABLAT, wCount
  970. 0007DC 0009           01459         tblrd   *+                      ; Skip next
  971. 0007DE 0008           01460         tblrd   *                       ; Read count high
  972. 0007E0 CFF5 F419      01461         movff   TABLAT, wCount + 1
  973. 0007E4 831D           01462         bsf     usb_stat, ctrl_trf_mem  ; Indicate ROM
  974. 0007E6 D027           01463         bra     USBHIDSetSessionOwner
  975. 0007E8                01464 USBCheckHIDRequest2
  976.                       01465 ;       movlw   DSC_PHY                 ; DscType = DSC_PHY?
  977.                       01466 ;       cpfseq  SetupPkt + bDscType
  978.                       01467 ;       return                          ; No
  979. 0007E8                01468 USBCheckHIDRequestClass
  980. 0007E8 511E           01469         movf    SetupPkt, W             ; RequestType = CLASS?
  981. 0007EA 0B60           01470         andlw   0x60                    ; Mask to proper bits
  982. 0007EC 0820           01471         sublw   (CLASS) << 5
  983. 0007EE E1D1           01472         bnz     USBCheckHIDRequestExit  ; No
  984. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE 54
  985. LOC  OBJECT CODE     LINE SOURCE TEXT
  986.   VALUE
  987.                       01473 ;       movlw   GET_REPORT              ; Request = GET_REPORT?
  988.                       01474 ;       subwf   SetupPkt + bRequest, W
  989.                       01475 ;       bz      HIDGetReportHandler     ; Yes
  990.                       01476 ;       movlw   SET_REPORT              ; Request = SET_REPORT?
  991.                       01477 ;       subwf   SetupPkt + bRequest, W
  992.                       01478 ;       bz      HIDSetReportHandler     ; Yes
  993. 0007F0 0E02           01479         movlw   GET_IDLE                ; Request = GET_IDLE?
  994. 0007F2 631F           01480         cpfseq  SetupPkt + bRequest
  995. 0007F4 D009           01481         bra     USBCheckHIDRequestClass1        ; No
  996.                       01482         mSetSourcePointer idle_rate
  997. 0007F6 0E9E               M         movlw   low (idle_rate)
  998. 0007F8 6F12               M         movwf   pSrc
  999. 0007FA 0E04               M         movlw   high (idle_rate)
  1000. 0007FC 6F13               M         movwf   pSrc + 1
  1001. 0007FE 0E01           01483         movlw   1
  1002. 000800 6F18           01484         movwf   wCount
  1003. 000802 6B19           01485         clrf    wCount + 1
  1004. 000804 931D           01486         bcf     usb_stat, ctrl_trf_mem  ; Indicate RAM
  1005. 000806 D017           01487         bra     USBHIDSetSessionOwner
  1006. 000808                01488 USBCheckHIDRequestClass1
  1007. 000808 0E0A           01489         movlw   SET_IDLE                ; Request = SET_IDLE?
  1008. 00080A 631F           01490         cpfseq  SetupPkt + bRequest
  1009. 00080C D003           01491         bra     USBCheckHIDRequestClass2        ; No
  1010. 00080E C421 F49E      01492         movff   SetupPkt + wValue + 1, idle_rate
  1011. 000812 D011           01493         bra     USBHIDSetSessionOwner
  1012. 000814                01494 USBCheckHIDRequestClass2
  1013. 000814 0E03           01495         movlw   GET_PROTOCOL            ; Request = GET_PROTOCOL?
  1014. 000816 631F           01496         cpfseq  SetupPkt + bRequest
  1015. 000818 D009           01497         bra     USBCheckHIDRequestClass3        ; No
  1016.                       01498         mSetSourcePointer active_protocol
  1017. 00081A 0E9F               M         movlw   low (active_protocol)
  1018. 00081C 6F12               M         movwf   pSrc
  1019. 00081E 0E04               M         movlw   high (active_protocol)
  1020. 000820 6F13               M         movwf   pSrc + 1
  1021. 000822 0E01           01499         movlw   1
  1022. 000824 6F18           01500         movwf   wCount
  1023. 000826 6B19           01501         clrf    wCount + 1
  1024. 000828 931D           01502         bcf     usb_stat, ctrl_trf_mem  ; Indicate RAM
  1025. 00082A D005           01503         bra     USBHIDSetSessionOwner
  1026. 00082C                01504 USBCheckHIDRequestClass3
  1027. 00082C 0E0B           01505         movlw   SET_PROTOCOL            ; Request = SET_PROTOCOL?
  1028. 00082E 631F           01506         cpfseq  SetupPkt + bRequest
  1029. 000830 0012           01507         return                          ; No
  1030. 000832 C420 F49F      01508         movff   SetupPkt + wValue, active_protocol
  1031. 000836                01509 USBHIDSetSessionOwner
  1032. 000836 0E02           01510         movlw   MUID_HID
  1033. 000838 6F17           01511         movwf   ctrl_trf_session_owner
  1034. 00083A 0012           01512         return
  1035.                       01513 
  1036.                       01514 
  1037.                       01515 ; From hid.c  line 158
  1038.                       01516 ;/******************************************************************************
  1039.                       01517 ; * Function:        void HIDInitEP(void)
  1040. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE 55
  1041. LOC  OBJECT CODE     LINE SOURCE TEXT
  1042.   VALUE
  1043.                       01518 ; *
  1044.                       01519 ; * PreCondition:    None
  1045.                       01520 ; *
  1046.                       01521 ; * Input:           None
  1047.                       01522 ; *
  1048.                       01523 ; * Output:          None
  1049.                       01524 ; *
  1050.                       01525 ; * Side Effects:    None
  1051.                       01526 ; *
  1052.                       01527 ; * Overview:        HIDInitEP initializes HID endpoints, buffer descriptors,
  1053.                       01528 ; *                  internal state-machine, and variables.
  1054.                       01529 ; *                  It should be called after the USB host has sent out a
  1055.                       01530 ; *                  SET_CONFIGURATION request.
  1056.                       01531 ; *                  See USBStdSetCfgHandler() in usb9.c for examples.
  1057.                       01532 ; *
  1058.                       01533 ; * Note:            None
  1059.                       01534 ; *****************************************************************************/
  1060. 00083C                01535 HIDInitEP
  1061. 00083C 0E01           01536         movlw   1                       ; Endpoint 1 Out
  1062. 00083E 6EE9           01537         movwf   FSR0L
  1063. 000840 EE14 F0A0      01538         lfsr    1, hid_report_out       ; FSR1 = endpoint buffer address
  1064. 000844 0E40           01539         movlw   HID_INT_OUT_EP_SIZE     ; W = endpoint size
  1065. 000846 D81C           01540         rcall   InitEPOut               ; Inititalize the endpoint
  1066.                       01541 
  1067. 000848 0E01           01542         movlw   1                       ; Endpoint 1 In
  1068. 00084A 6EE9           01543         movwf   FSR0L
  1069. 00084C EE14 F0E1      01544         lfsr    1, hid_report_in        ; FSR1 = endpoint buffer address
  1070. 000850 0E40           01545         movlw   HID_INT_IN_EP_SIZE      ; W = endpoint size
  1071. 000852 D000           01546         bra     InitEPIn                ; Inititalize the endpoint
  1072.                       01547 
  1073.                       01548 #endif  ; USB_USE_HID
  1074.                       01549 
  1075.                       01550 
  1076.                       01551 
  1077.                       01552 #ifdef USB_USE_CDC
  1078.                       01553 
  1079.                       01554 ;/******************************************************************************
  1080.                       01555 ; * Function:        void USBCheckCDCRequest(void)
  1081.                       01556 ; *
  1082.                       01557 ; * PreCondition:    None
  1083.                       01558 ; *
  1084.                       01559 ; * Input:           None
  1085.                       01560 ; *
  1086.                       01561 ; * Output:          None
  1087.                       01562 ; *
  1088.                       01563 ; * Side Effects:    None
  1089.                       01564 ; *
  1090.                       01565 ; * Overview:        This routine checks the setup data packet to see if it
  1091.                       01566 ; *                  knows how to handle it
  1092.                       01567 ; *
  1093.                       01568 ; * Note:            None
  1094.                       01569 ; *****************************************************************************/
  1095.                       01570 USBCheckCDCRequest
  1096. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE 56
  1097. LOC  OBJECT CODE     LINE SOURCE TEXT
  1098.   VALUE
  1099.                       01571 ;    /*
  1100.                       01572 ;     * If request recipient is not an interface then return
  1101.                       01573 ;     */
  1102.                       01574         movlb   high 0x400              ; Point to proper bank
  1103.                       01575         movf    SetupPkt, W             ; Recipient = RCPT_INTF?
  1104.                       01576         andlw   0x1f                    ; Mask to lower 5 bits
  1105.                       01577         sublw   RCPT_INTF
  1106.                       01578         bnz     USBCheckCDCRequestExit  ; No
  1107.                       01579 
  1108.                       01580 ;    /*
  1109.                       01581 ;     * If request type is not class-specific then return
  1110.                       01582 ;     */
  1111.                       01583         movf    SetupPkt, W             ; RequestType = CLASS?
  1112.                       01584         andlw   0x60                    ; Mask to proper bits
  1113.                       01585         sublw   (CLASS) << 5
  1114.                       01586         bnz     USBCheckCDCRequestExit  ; No
  1115.                       01587 
  1116.                       01588 ;    /*
  1117.                       01589 ;     * Interface ID must match interface numbers associated with
  1118.                       01590 ;     * CDC class, else return
  1119.                       01591 ;     */
  1120.                       01592         movlw   CDC_COMM_INTF_ID        ; IntfID = CDC_COMM_INTF_ID?
  1121.                       01593         subwf   SetupPkt + bIntfID, W
  1122.                       01594         bz      USBCheckCDCRequest1     ; Yes
  1123.                       01595         movlw   CDC_DATA_INTF_ID        ; IntfID = CDC_DATA_INTF_ID?
  1124.                       01596         cpfseq  SetupPkt + bIntfID
  1125.                       01597 USBCheckCDCRequestExit
  1126.                       01598         return                          ; No
  1127.                       01599     
  1128.                       01600 USBCheckCDCRequest1
  1129.                       01601         movlw   SEND_ENCAPSULATED_COMMAND       ; Request = SEND_ENCAPSULATED_COMMAND?
  1130.                       01602         cpfseq  SetupPkt + bRequest
  1131.                       01603         bra     USBCheckCDCRequest2     ; No
  1132.                       01604         mSetSourcePointer dummy_encapsulated_cmd_response
  1133.                       01605         bcf     usb_stat, ctrl_trf_mem  ; Indicate RAM
  1134.                       01606         movlw   dummy_length
  1135.                       01607         movwf   wCount
  1136.                       01608         clrf    wCount + 1
  1137.                       01609         bra     USBCDCSetSessionOwner
  1138.                       01610 USBCheckCDCRequest2
  1139.                       01611         movlw   GET_ENCAPSULATED_RESPONSE       ; Request = GET_ENCAPSULATED_RESPONSE?
  1140.                       01612         cpfseq  SetupPkt + bRequest
  1141.                       01613         bra     USBCheckCDCRequest3     ; No
  1142.                       01614 ;       // Populate dummy_encapsulated_cmd_response first.
  1143.                       01615         mSetDestinationPointer dummy_encapsulated_cmd_response
  1144.                       01616         bra     USBCDCSetSessionOwner
  1145.                       01617 USBCheckCDCRequest3
  1146.                       01618         movlw   SET_COMM_FEATURE        ; Request = SET_COMM_FEATURE?
  1147.                       01619         cpfseq  SetupPkt + bRequest
  1148.                       01620         bra     USBCheckCDCRequest4     ; No
  1149.                       01621         return                          ; Optional
  1150.                       01622 USBCheckCDCRequest4
  1151.                       01623         movlw   GET_COMM_FEATURE        ; Request = GET_COMM_FEATURE?
  1152. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE 57
  1153. LOC  OBJECT CODE     LINE SOURCE TEXT
  1154.   VALUE
  1155.                       01624         cpfseq  SetupPkt + bRequest
  1156.                       01625         bra     USBCheckCDCRequest5     ; No
  1157.                       01626         return                          ; Optional
  1158.                       01627 USBCheckCDCRequest5
  1159.                       01628         movlw   CLEAR_COMM_FEATURE      ; Request = CLEAR_COMM_FEATURE?
  1160.                       01629         cpfseq  SetupPkt + bRequest
  1161.                       01630         bra     USBCheckCDCRequest6     ; No
  1162.                       01631         return                          ; Optional
  1163.                       01632 USBCheckCDCRequest6
  1164.                       01633         movlw   SET_LINE_CODING         ; Request = SET_LINE_CODING?
  1165.                       01634         cpfseq  SetupPkt + bRequest
  1166.                       01635         bra     USBCheckCDCRequest7     ; No
  1167.                       01636         mSetDestinationPointer line_coding
  1168.                       01637         bra     USBCDCSetSessionOwner
  1169.                       01638 USBCheckCDCRequest7
  1170.                       01639         movlw   GET_LINE_CODING         ; Request = GET_LINE_CODING?
  1171.                       01640         cpfseq  SetupPkt + bRequest
  1172.                       01641         bra     USBCheckCDCRequest8     ; No
  1173.                       01642         ; Abstract line coding information
  1174.                       01643         movlw   low 115200              ; baud rate
  1175.                       01644         movwf   line_coding + dwDTERate
  1176.                       01645         movlw   high 115200
  1177.                       01646         movwf   line_coding + dwDTERate + 1
  1178.                       01647         movlw   upper 115200
  1179.                       01648         movwf   line_coding + dwDTERate + 2
  1180.                       01649         clrf    line_coding + dwDTERate + 3
  1181.                       01650         clrf    line_coding + bCharFormat       ; 1 stop bit
  1182.                       01651         clrf    line_coding + bParityType       ; None
  1183.                       01652         movlw   8
  1184.                       01653         movwf   line_coding + bDataBits ; 5,6,7,8, or 16
  1185.                       01654         mSetSourcePointer line_coding
  1186.                       01655         bcf     usb_stat, ctrl_trf_mem  ; Indicate RAM
  1187.                       01656         movlw   LINE_CODING_LENGTH
  1188.                       01657         movwf   wCount
  1189.                       01658         clrf    wCount + 1
  1190.                       01659         bra     USBCDCSetSessionOwner
  1191.                       01660 USBCheckCDCRequest8
  1192.                       01661         movlw   SET_CONTROL_LINE_STATE  ; Request = SET_CONTROL_LINE_STATE?
  1193.                       01662         cpfseq  SetupPkt + bRequest
  1194.                       01663         bra     USBCheckCDCRequest9     ; No
  1195.                       01664         movff   SetupPkt + wValue, control_signal_bitmap
  1196.                       01665         bra     USBCDCSetSessionOwner
  1197.                       01666 USBCheckCDCRequest9
  1198.                       01667         movlw   SEND_BREAK              ; Request = SEND_BREAK?
  1199.                       01668         cpfseq  SetupPkt + bRequest
  1200.                       01669         bra     USBCheckCDCRequest10    ; No
  1201.                       01670         return                          ; Optional
  1202.                       01671 USBCheckCDCRequest10
  1203.                       01672         return                          ; Default
  1204.                       01673 USBCDCSetSessionOwner
  1205.                       01674         movlw   MUID_CDC
  1206.                       01675         movwf   ctrl_trf_session_owner
  1207.                       01676         return
  1208. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE 58
  1209. LOC  OBJECT CODE     LINE SOURCE TEXT
  1210.   VALUE
  1211.                       01677 
  1212.                       01678 
  1213.                       01679 ;/******************************************************************************
  1214.                       01680 ; * Function:        void CDCInitEP(void)
  1215.                       01681 ; *
  1216.                       01682 ; * PreCondition:    None
  1217.                       01683 ; *
  1218.                       01684 ; * Input:           None
  1219.                       01685 ; *
  1220.                       01686 ; * Output:          None
  1221.                       01687 ; *
  1222.                       01688 ; * Side Effects:    None
  1223.                       01689 ; *
  1224.                       01690 ; * Overview:        CDCInitEP initializes CDC endpoints, buffer descriptors,
  1225.                       01691 ; *                  internal state-machine, and variables.
  1226.                       01692 ; *                  It should be called after the USB host has sent out a
  1227.                       01693 ; *                  SET_CONFIGURATION request.
  1228.                       01694 ; *                  See USBStdSetCfgHandler() in usb9.c for examples.
  1229.                       01695 ; *
  1230.                       01696 ; * Note:            None
  1231.                       01697 ; *****************************************************************************/
  1232.                       01698 CDCInitEP
  1233.                       01699         movlw   2                       ; Endpoint 2 In
  1234.                       01700         movwf   FSR0L
  1235.                       01701         lfsr    1, cdc_notice           ; FSR1 = endpoint buffer address
  1236.                       01702         movlw   CDC_INT_EP_SIZE         ; W = endpoint size
  1237.                       01703         rcall   InitEPIn                ; Inititalize the endpoint
  1238.                       01704 
  1239.                       01705         movlw   3                       ; Endpoint 3
  1240.                       01706         movwf   FSR0L
  1241.                       01707         lfsr    1, cdc_data_rx          ; FSR1 = endpoint buffer address
  1242.                       01708         movlw   CDC_BULK_OUT_EP_SIZE    ; W = endpoint size
  1243.                       01709         rcall   InitEPOut               ; Inititalize the endpoint
  1244.                       01710 
  1245.                       01711         movlw   3                       ; Endpoint 3 In
  1246.                       01712         movwf   FSR0L
  1247.                       01713         lfsr    1, cdc_data_tx          ; FSR1 = endpoint buffer address
  1248.                       01714         movlw   CDC_BULK_IN_EP_SIZE     ; W = endpoint size
  1249.                       01715         bra     InitEPIn                ; Inititalize the endpoint
  1250.                       01716 
  1251.                       01717 #endif  ; USB_USE_CDC
  1252.                       01718 
  1253.                       01719 
  1254.                       01720 ; Generic code for use by all the classes
  1255.                       01721 
  1256.                       01722 ; InitEPIn
  1257.                       01723 ;  Generic initialize In endpoint
  1258.                       01724 ; Input:
  1259.                       01725 ;  FSR0L is endpoint number
  1260.                       01726 ;  FSR1 is endpoint buffer address
  1261.                       01727 ;  W is endpoint buffer size
  1262.                       01728 ; Returns:
  1263.                       01729 ;  Nada
  1264. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE 59
  1265. LOC  OBJECT CODE     LINE SOURCE TEXT
  1266.   VALUE
  1267.                       01730 ; Uses
  1268.                       01731 ;  FSR0 is BDT pointer
  1269.                       01732 ;  FSR1 is endpoint buffer pointer
  1270.                       01733 ;  FSR2 is endpoint table pointer
  1271.                       01734 
  1272. 000854                01735 InitEPIn
  1273.                       01736 ; Save maximum count at front of endpoint buffer and move buffer pointer up (no need to put in Cnt for I
  1274.                             n)
  1275. 000854 6EE6           01737         movwf   POSTINC1                ; Store maximum count at front of endpoint buffer and move up po
  1276.                             inter
  1277.                       01738 
  1278.                       01739 ; Point FSR2 to endpoint table
  1279. 000856 EE2F F070      01740         lfsr    2, UEP0
  1280. 00085A 50E9           01741         movf    FSR0L, W                ; Add in endpoint number
  1281. 00085C 26D9           01742         addwf   FSR2L, F
  1282.                       01743 
  1283.                       01744 ; Enable In endpoint
  1284. 00085E 0E1A           01745         movlw   EP_IN|HSHK_EN           ; Enable In pipe
  1285. 000860 12DF           01746         iorwf   INDF2, F
  1286.                       01747 
  1287.                       01748 ; Point FSR0 to endpoint BDT
  1288. 000862 44E9           01749         rlncf   FSR0L, W                ; Endpoint number * 8
  1289. 000864 46E8           01750         rlncf   WREG, F
  1290. 000866 46E8           01751         rlncf   WREG, F
  1291. 000868 EE04 F004      01752         lfsr    0, ep0Bi                ; Point FSR0 to beginning of BDT area
  1292. 00086C 26E9           01753         addwf   FSR0L, F                ; Add endpoint offset to FSR0 (can't overflow to FSR0H)
  1293.                       01754 
  1294.                       01755 ; Set endpoint buffer address from FSR1
  1295. 00086E 0E02           01756         movlw   ADRL                    ; Point to ADRL
  1296. 000870 CFE1 FFEB      01757         movff   FSR1L, PLUSW0
  1297. 000874 0E03           01758         movlw   ADRH                    ; Point to ADRH
  1298. 000876 CFE2 FFEB      01759         movff   FSR1H, PLUSW0
  1299.                       01760 
  1300.                       01761 ; Set endpoint status
  1301. 00087A 0E40           01762         movlw   _UCPU|_DAT1             ; Set transmit status
  1302. 00087C 6EEF           01763         movwf   INDF0                   ; Set Stat
  1303. 00087E 0012           01764         return
  1304.                       01765 
  1305.                       01766 
  1306.                       01767 ; InitEPOut
  1307.                       01768 ;  Generic initialize Out endpoint
  1308.                       01769 ; Input:
  1309.                       01770 ;  FSR0L is endpoint number
  1310.                       01771 ;  FSR1 is endpoint buffer address
  1311.                       01772 ;  W is endpoint buffer size
  1312.                       01773 ; Returns:
  1313.                       01774 ;  Nada
  1314.                       01775 ; Uses
  1315.                       01776 ;  FSR0 is BDT pointer
  1316.                       01777 ;  FSR1 is endpoint buffer pointer
  1317.                       01778 ;  FSR2 is endpoint table pointer
  1318.                       01779 
  1319. 000880                01780 InitEPOut
  1320. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE 60
  1321. LOC  OBJECT CODE     LINE SOURCE TEXT
  1322.   VALUE
  1323.                       01781 ; Save maximum count at front of endpoint buffer and move buffer pointer up
  1324. 000880 6EE6           01782         movwf   POSTINC1                ; Store maximum count at front of endpoint buffer and move up po
  1325.                             inter
  1326.                       01783 
  1327.                       01784 ; Point FSR2 to endpoint table
  1328. 000882 EE2F F070      01785         lfsr    2, UEP0
  1329. 000886 50E9           01786         movf    FSR0L, W                ; Add in endpoint number
  1330. 000888 26D9           01787         addwf   FSR2L, F
  1331.                       01788 
  1332.                       01789 ; Enable Out endpoint
  1333. 00088A 0E1C           01790         movlw   EP_OUT|HSHK_EN          ; Enable Out pipe
  1334. 00088C 12DF           01791         iorwf   INDF2, F
  1335.                       01792 
  1336.                       01793 ; Point FSR0 to endpoint BDT
  1337. 00088E 44E9           01794         rlncf   FSR0L, W                ; Endpoint number * 8
  1338. 000890 46E8           01795         rlncf   WREG, F
  1339. 000892 46E8           01796         rlncf   WREG, F
  1340. 000894 EE04 F000      01797         lfsr    0, ep0Bo                ; Point FSR0 to beginning of BDT area
  1341. 000898 26E9           01798         addwf   FSR0L, F                ; Add endpoint offset to FSR0 (can't overflow to FSR0H)
  1342.                       01799 
  1343.                       01800 ; Set endpoint buffer address from FSR1 + 1
  1344. 00089A 0E02           01801         movlw   ADRL                    ; Point to ADRL
  1345. 00089C CFE1 FFEB      01802         movff   FSR1L, PLUSW0
  1346. 0008A0 0E03           01803         movlw   ADRH                    ; Point to ADRH
  1347. 0008A2 CFE2 FFEB      01804         movff   FSR1H, PLUSW0
  1348.                       01805 
  1349.                       01806 ; Set Cnt to maximum count
  1350. 0008A6 50E5           01807         movf    POSTDEC1, W             ; Back up endpoint buffer pointer (no PREDEC1!)
  1351. 0008A8 2AE9           01808         incf    FSR0L, F                ; Point to Cnt
  1352. 0008AA CFE7 FFED      01809         movff   INDF1, POSTDEC0         ; Set maximum count and point back to Stat
  1353.                       01810 
  1354.                       01811 ; Set endpoint status
  1355. 0008AE 0E88           01812         movlw   _USIE|_DAT0|_DTSEN      ; Set receive status
  1356. 0008B0 6EEF           01813         movwf   INDF0                   ; Set Stat
  1357. 0008B2 0012           01814         return
  1358.                       01815 
  1359.                       01816 
  1360.                       01817 ; PutUSB
  1361.                       01818 ;  Generic fill In endpoint for TX
  1362.                       01819 ; Input:
  1363.                       01820 ;  FSR0L is endpoint number
  1364.                       01821 ;  FSR1 is source buffer pointer
  1365.                       01822 ;  W is count
  1366.                       01823 ; Returns:
  1367.                       01824 ;  FSR1 is updated source buffer pointer
  1368.                       01825 ;  W returns number sent
  1369.                       01826 ;  Carry is clear for buffer not available
  1370.                       01827 ; Uses:
  1371.                       01828 ;  FSR0 is BDT pointer
  1372.                       01829 ;  FSR1 is source buffer pointer
  1373.                       01830 ;  FSR2 is endpoint buffer pointer
  1374.                       01831 ;  R0 in BANKA is temporary length storage
  1375.                       01832 
  1376. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE 61
  1377. LOC  OBJECT CODE     LINE SOURCE TEXT
  1378.   VALUE
  1379. 0008B4                01833 PutUSB
  1380. 0008B4 6E01           01834         movwf   R0                      ; Save count
  1381.                       01835 
  1382.                       01836 ; Check to see if we're configured
  1383. 0008B6 0104           01837         movlb   high 0x400              ; Point to proper bank
  1384. 0008B8 0E06           01838         movlw   CONFIGURED_STATE        ; We might not be configured yet
  1385. 0008BA 5D1A           01839         subwf   usb_device_state, W
  1386. 0008BC 0E00           01840         movlw   0                       ; 0 characters sent, so far
  1387. 0008BE 90D8           01841         bcf     STATUS, C               ; Clear Carry for possible error return
  1388. 0008C0 E109           01842         bnz     PutUSBNotReady          ; We're not configured
  1389.                       01843 
  1390.                       01844 ; Point FSR0 to requested endpoint In BDT
  1391. 0008C2 44E9           01845         rlncf   FSR0L, W                ; Endpoint number * 8
  1392. 0008C4 46E8           01846         rlncf   WREG, F
  1393. 0008C6 46E8           01847         rlncf   WREG, F
  1394. 0008C8 EE04 F004      01848         lfsr    0, ep0Bi                ; Point FSR0 to beginning of BDT area
  1395. 0008CC 26E9           01849         addwf   FSR0L, F                ; Add endpoint offset to FSR0 (can't overflow to FSR0H)
  1396.                       01850 
  1397. 0008CE 0E00           01851         movlw   0                       ; 0 characters sent, so far
  1398. 0008D0 90D8           01852         bcf     STATUS, C               ; Clear Carry for possible error return
  1399. 0008D2 BEEF           01853         btfsc   INDF0, UOWN             ; Who owns the buffer (Stat, UOWN)?
  1400. 0008D4                01854 PutUSBNotReady
  1401. 0008D4 0012           01855         return                          ; Busy (we don't)
  1402.                       01856 
  1403.                       01857 ; Get endpoint buffer address to FSR2
  1404. 0008D6 0E02           01858         movlw   ADRL                    ; Point to ADRL
  1405. 0008D8 CFEB FFD9      01859         movff   PLUSW0, FSR2L
  1406. 0008DC 0E03           01860         movlw   ADRH                    ; Point to ADRH
  1407. 0008DE CFEB FFDA      01861         movff   PLUSW0, FSR2H
  1408.                       01862 
  1409. 0008E2 0EFF           01863         movlw   -1
  1410. 0008E4 50DB           01864         movf    PLUSW2, W               ; Get maximum length from in front of endpoint buffer
  1411.                       01865 
  1412. 0008E6 6001           01866         cpfslt  R0                      ; Find number of bytes to send this time
  1413. 0008E8 6E01           01867         movwf   R0                      ; Too big - send maximum allowed length
  1414.                       01868 
  1415. 0008EA 2AE9           01869         incf    FSR0L, F                ; Point to Cnt
  1416. 0008EC 5001           01870         movf    R0, W                   ; Get number to send
  1417. 0008EE 6EED           01871         movwf   POSTDEC0                ; Put length into Cnt and point back to Stat
  1418. 0008F0 E004           01872         bz      PutUSBZero              ; Zero to send
  1419.                       01873 
  1420. 0008F2                01874 PutUSBRamLoop
  1421. 0008F2 CFE6 FFDE      01875         movff   POSTINC1, POSTINC2      ; Copy source buffer to endpoint buffer
  1422. 0008F6 2EE8           01876         decfsz  WREG, F                 ; Count down number of bytes to transfer
  1423. 0008F8 D7FC           01877         bra     PutUSBRamLoop
  1424.                       01878 
  1425. 0008FA                01879 PutUSBZero
  1426. 0008FA 0E40           01880         movlw   _DTSMASK                ; Save only DTS bit
  1427. 0008FC 16EF           01881         andwf   INDF0, F
  1428. 0008FE 7CEF           01882         btg     INDF0, DTS              ; Toggle DTS bit
  1429. 000900 0E88           01883         movlw   _USIE|_DTSEN            ; Turn ownership to SIE
  1430. 000902 12EF           01884         iorwf   INDF0, F
  1431. 000904 5001           01885         movf    R0, W                   ; Return number of bytes sent
  1432. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE 62
  1433. LOC  OBJECT CODE     LINE SOURCE TEXT
  1434.   VALUE
  1435. 000906 80D8           01886         bsf     STATUS, C               ; Set Carry for non-error return
  1436. 000908 0012           01887         return
  1437.                       01888 
  1438.                       01889 
  1439.                       01890 ; GetUSB
  1440.                       01891 ;  Generic get from Out endpoint for RX
  1441.                       01892 ; Input:
  1442.                       01893 ;  FSR0L is endpoint number
  1443.                       01894 ;  FSR1 is destination buffer pointer
  1444.                       01895 ;  W is max buffer length
  1445.                       01896 ; Returns:
  1446.                       01897 ;  FSR1 is updated destination buffer pointer
  1447.                       01898 ;  W returns number received
  1448.                       01899 ;  Carry is clear for buffer not available
  1449.                       01900 ; Uses
  1450.                       01901 ;  FSR0 is BDT pointer
  1451.                       01902 ;  FSR1 is destination buffer pointer
  1452.                       01903 ;  FSR2 is endpoint buffer pointer
  1453.                       01904 ;  R0 in BANKA is temporary length storage
  1454.                       01905 
  1455. 00090A                01906 GetUSB
  1456. 00090A 6E01           01907         movwf   R0                      ; Save max buffer length
  1457.                       01908 
  1458.                       01909 ; Check to see if we're configured
  1459. 00090C 0104           01910         movlb   high 0x400              ; Point to proper bank
  1460. 00090E 0E06           01911         movlw   CONFIGURED_STATE        ; We might not be configured yet
  1461. 000910 5D1A           01912         subwf   usb_device_state, W
  1462. 000912 0E00           01913         movlw   0                       ; 0 characters received, so far
  1463. 000914 90D8           01914         bcf     STATUS, C               ; Clear Carry for possible error return
  1464. 000916 E109           01915         bnz     GetUSBNotReady          ; We're not configured
  1465.                       01916 
  1466.                       01917 ; Point FSR0 to requested endpoint Out BDT
  1467. 000918 44E9           01918         rlncf   FSR0L, W                ; Endpoint number * 8
  1468. 00091A 46E8           01919         rlncf   WREG, F
  1469. 00091C 46E8           01920         rlncf   WREG, F
  1470. 00091E EE04 F000      01921         lfsr    0, ep0Bo                ; Point FSR0 to beginning of BDT area
  1471. 000922 26E9           01922         addwf   FSR0L, F                ; Add endpoint offset to FSR0 (can't overflow to FSR0H)
  1472.                       01923 
  1473. 000924 0E00           01924         movlw   0                       ; 0 characters received, so far
  1474. 000926 90D8           01925         bcf     STATUS, C               ; Clear Carry for possible error return
  1475. 000928 BEEF           01926         btfsc   INDF0, UOWN             ; Who owns the buffer (Stat, UOWN)?
  1476. 00092A                01927 GetUSBNotReady
  1477. 00092A 0012           01928         return                          ; Busy (we don't)
  1478.                       01929 
  1479.                       01930 ; Get endpoint buffer address to FSR2
  1480. 00092C 0E02           01931         movlw   ADRL                    ; Point to ADRL
  1481. 00092E CFEB FFD9      01932         movff   PLUSW0, FSR2L
  1482. 000932 0E03           01933         movlw   ADRH                    ; Point to ADRH
  1483. 000934 CFEB FFDA      01934         movff   PLUSW0, FSR2H
  1484.                       01935 
  1485. 000938 50EC           01936         movf    PREINC0, W              ; Get Cnt
  1486. 00093A 6001           01937         cpfslt  R0                      ; Make sure it's not longer than the buffer
  1487. 00093C 6E01           01938         movwf   R0                      ; It's OK, save returned length
  1488. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE 63
  1489. LOC  OBJECT CODE     LINE SOURCE TEXT
  1490.   VALUE
  1491.                       01939 
  1492. 00093E 0EFF           01940         movlw   -1
  1493. 000940 50DB           01941         movf    PLUSW2, W               ; Get maximum length from in front of endpoint buffer
  1494. 000942 6EED           01942         movwf   POSTDEC0                ; Reset max length and point back to Stat
  1495.                       01943 
  1496. 000944 5001           01944         movf    R0, W                   ; Get count to W
  1497. 000946 E004           01945         bz      GetUSBZero              ; Nothing received
  1498.                       01946 
  1499. 000948                01947 GetUSBRamLoop
  1500. 000948 CFDE FFE6      01948         movff   POSTINC2, POSTINC1      ; Copy endpoint buffer to destination buffer
  1501. 00094C 2EE8           01949         decfsz  WREG, F                 ; Count down number of bytes
  1502. 00094E D7FC           01950         bra     GetUSBRamLoop
  1503.                       01951 
  1504. 000950                01952 GetUSBZero
  1505. 000950 0E40           01953         movlw   _DTSMASK                ; Save only DTS bit
  1506. 000952 16EF           01954         andwf   INDF0, F
  1507. 000954 7CEF           01955         btg     INDF0, DTS              ; Toggle DTS bit
  1508. 000956 0E88           01956         movlw   _USIE|_DTSEN            ; Turn ownership to SIE
  1509. 000958 12EF           01957         iorwf   INDF0, F
  1510. 00095A 5001           01958         movf    R0, W                   ; Return number of bytes received
  1511. 00095C 80D8           01959         bsf     STATUS, C               ; Set Carry for non-error return
  1512. 00095E 0012           01960         return
  1513.                       00017 
  1514. 000960                00018 MAINPROG
  1515.                       00082 
  1516.                       00083         MOVE?CB 000h, TRISA
  1517.                           M         CHK?RP  TRISA
  1518.                           M     if (((TRISA) > BANKA_END) & ((TRISA) < (0f01h + BANKA_END)))
  1519.                           M       if (((TRISA) & 0f00h) != (PREV_BANK << 8))
  1520.                           M         movlb   high (TRISA)
  1521.                           M PREV_BANK = high (TRISA)
  1522.                           M       endif
  1523.                           M     endif
  1524.                           M     if (low (000h) == 0)
  1525. 000960 6A92               M         clrf    TRISA
  1526.                           M     else
  1527.                           M         movlw   low (000h)
  1528.                           M         movwf   TRISA
  1529.                           M     endif
  1530.                       00084         MOVE?CB 000h, TRISB
  1531.                           M         CHK?RP  TRISB
  1532.                           M     if (((TRISB) > BANKA_END) & ((TRISB) < (0f01h + BANKA_END)))
  1533.                           M       if (((TRISB) & 0f00h) != (PREV_BANK << 8))
  1534.                           M         movlb   high (TRISB)
  1535.                           M PREV_BANK = high (TRISB)
  1536.                           M       endif
  1537.                           M     endif
  1538.                           M     if (low (000h) == 0)
  1539. 000962 6A93               M         clrf    TRISB
  1540.                           M     else
  1541.                           M         movlw   low (000h)
  1542.                           M         movwf   TRISB
  1543.                           M     endif
  1544. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE 64
  1545. LOC  OBJECT CODE     LINE SOURCE TEXT
  1546.   VALUE
  1547.                       00085         MOVE?CT 001h, _TRISC??0
  1548.                           M         CHK?RP  TRISC
  1549.                           M     if (((TRISC) > BANKA_END) & ((TRISC) < (0f01h + BANKA_END)))
  1550.                           M       if (((TRISC) & 0f00h) != (PREV_BANK << 8))
  1551.                           M         movlb   high (TRISC)
  1552.                           M PREV_BANK = high (TRISC)
  1553.                           M       endif
  1554.                           M     endif
  1555.                           M     if (((001h) & 1) == 1)
  1556. 000964 8094               M         bsf     TRISC,  000h
  1557.                           M     else
  1558.                           M         bcf     TRISC,  000h
  1559.                           M     endif
  1560.                       00086         MOVE?CT 001h, _TRISC??1
  1561.                           M         CHK?RP  TRISC
  1562.                           M     if (((TRISC) > BANKA_END) & ((TRISC) < (0f01h + BANKA_END)))
  1563.                           M       if (((TRISC) & 0f00h) != (PREV_BANK << 8))
  1564.                           M         movlb   high (TRISC)
  1565.                           M PREV_BANK = high (TRISC)
  1566.                           M       endif
  1567.                           M     endif
  1568.                           M     if (((001h) & 1) == 1)
  1569. 000966 8294               M         bsf     TRISC,  001h
  1570.                           M     else
  1571.                           M         bcf     TRISC,  001h
  1572.                           M     endif
  1573.                       00087         MOVE?CT 000h, _TRISC??2
  1574.                           M         CHK?RP  TRISC
  1575.                           M     if (((TRISC) > BANKA_END) & ((TRISC) < (0f01h + BANKA_END)))
  1576.                           M       if (((TRISC) & 0f00h) != (PREV_BANK << 8))
  1577.                           M         movlb   high (TRISC)
  1578.                           M PREV_BANK = high (TRISC)
  1579.                           M       endif
  1580.                           M     endif
  1581.                           M     if (((000h) & 1) == 1)
  1582.                           M         bsf     TRISC,  002h
  1583.                           M     else
  1584. 000968 9494               M         bcf     TRISC,  002h
  1585.                           M     endif
  1586.                       00088         MOVE?CB _FreqMin, _Frecuencia
  1587.                           M         CHK?RP  _Frecuencia
  1588.                           M     if (((_Frecuencia) > BANKA_END) & ((_Frecuencia) < (0f01h + BANKA_END)))
  1589.                           M       if (((_Frecuencia) & 0f00h) != (PREV_BANK << 8))
  1590.                           M         movlb   high (_Frecuencia)
  1591.                           M PREV_BANK = high (_Frecuencia)
  1592.                           M       endif
  1593.                           M     endif
  1594.                           M     if (low (_FreqMin) == 0)
  1595.                           M         clrf    _Frecuencia
  1596.                           M     else
  1597. 00096A 0E0A               M         movlw   low (_FreqMin)
  1598. 00096C 6E1E               M         movwf   _Frecuencia
  1599.                           M     endif
  1600. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE 65
  1601. LOC  OBJECT CODE     LINE SOURCE TEXT
  1602.   VALUE
  1603.                       00089         MOVE?BB _Frecuencia, PORTB
  1604. 00096E C01E FF81          M         movff   _Frecuencia, PORTB
  1605.                       00090         MOVE?CB 000h, PORTA
  1606.                           M         CHK?RP  PORTA
  1607.                           M     if (((PORTA) > BANKA_END) & ((PORTA) < (0f01h + BANKA_END)))
  1608.                           M       if (((PORTA) & 0f00h) != (PREV_BANK << 8))
  1609.                           M         movlb   high (PORTA)
  1610.                           M PREV_BANK = high (PORTA)
  1611.                           M       endif
  1612.                           M     endif
  1613.                           M     if (low (000h) == 0)
  1614. 000972 6A80               M         clrf    PORTA
  1615.                           M     else
  1616.                           M         movlw   low (000h)
  1617.                           M         movwf   PORTA
  1618.                           M     endif
  1619.                       00091         MOVE?CB 000h, PORTC
  1620.                           M         CHK?RP  PORTC
  1621.                           M     if (((PORTC) > BANKA_END) & ((PORTC) < (0f01h + BANKA_END)))
  1622.                           M       if (((PORTC) & 0f00h) != (PREV_BANK << 8))
  1623.                           M         movlb   high (PORTC)
  1624.                           M PREV_BANK = high (PORTC)
  1625.                           M       endif
  1626.                           M     endif
  1627.                           M     if (low (000h) == 0)
  1628. 000974 6A82               M         clrf    PORTC
  1629.                           M     else
  1630.                           M         movlw   low (000h)
  1631.                           M         movwf   PORTC
  1632.                           M     endif
  1633.                       00092         MOVE?CB 007h, ADCON1
  1634.                           M         CHK?RP  ADCON1
  1635.                           M     if (((ADCON1) > BANKA_END) & ((ADCON1) < (0f01h + BANKA_END)))
  1636.                           M       if (((ADCON1) & 0f00h) != (PREV_BANK << 8))
  1637.                           M         movlb   high (ADCON1)
  1638.                           M PREV_BANK = high (ADCON1)
  1639.                           M       endif
  1640.                           M     endif
  1641.                           M     if (low (007h) == 0)
  1642.                           M         clrf    ADCON1
  1643.                           M     else
  1644. 000976 0E07               M         movlw   low (007h)
  1645. 000978 6EC1               M         movwf   ADCON1
  1646.                           M     endif
  1647.                       00093         MOVE?CB 007h, CMCON
  1648.                           M         CHK?RP  CMCON
  1649.                           M     if (((CMCON) > BANKA_END) & ((CMCON) < (0f01h + BANKA_END)))
  1650.                           M       if (((CMCON) & 0f00h) != (PREV_BANK << 8))
  1651.                           M         movlb   high (CMCON)
  1652.                           M PREV_BANK = high (CMCON)
  1653.                           M       endif
  1654.                           M     endif
  1655.                           M     if (low (007h) == 0)
  1656. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE 66
  1657. LOC  OBJECT CODE     LINE SOURCE TEXT
  1658.   VALUE
  1659.                           M         clrf    CMCON
  1660.                           M     else
  1661. 00097A 0E07               M         movlw   low (007h)
  1662. 00097C 6EB4               M         movwf   CMCON
  1663.                           M     endif
  1664.                       00094         USBINIT?        
  1665.                           M   ifdef USE_USB_BUS_SENSE_IO
  1666.                           M         tris_usb_bus_sense = 1  ; Set to input
  1667.                           M   endif
  1668.                           M   ifdef USE_SELF_POWER_SENSE_IO
  1669.                           M         tris_self_power = 1     ; Set to input
  1670.                           M   endif
  1671.                           M         L?CALL  InitializeUSBDriver     ; Finish initialization
  1672.                           M         RST?RP
  1673.                           M     if (PREV_BANK != 0)
  1674.                           M         movlb   0
  1675.                           M PREV_BANK = 0
  1676.                           M     endif
  1677.                           M 
  1678.                           M     ifdef USE_LINKER
  1679.                           M         call    InitializeUSBDriver
  1680.                           M     else
  1681.                           M       if ((InitializeUSBDriver) < 1)
  1682.                           M         call    InitializeUSBDriver
  1683.                           M       else
  1684.                           M         if ((InitializeUSBDriver) > $)
  1685.                           M         call    InitializeUSBDriver
  1686.                           M         else
  1687.                           M           if ((InitializeUSBDriver) < ($ - 3ffh))
  1688.                           M         call    InitializeUSBDriver
  1689.                           M           else
  1690. 00097E DE7D               M         rcall   InitializeUSBDriver
  1691.                           M           endif
  1692.                           M         endif
  1693.                           M       endif
  1694.                           M     endif
  1695.                           M         L?CALL  DUNN            ; Do our cleanup
  1696.                           M         RST?RP
  1697.                           M     if (PREV_BANK != 0)
  1698.                           M         movlb   0
  1699.                           M PREV_BANK = 0
  1700.                           M     endif
  1701.                           M 
  1702.                           M     ifdef USE_LINKER
  1703.                           M         call    DUNN
  1704.                           M     else
  1705.                           M       if ((DUNN)  < 1)
  1706.                           M         call    DUNN
  1707.                           M       else
  1708.                           M         if ((DUNN)  > $)
  1709.                           M         call    DUNN
  1710.                           M         else
  1711.                           M           if ((DUNN)  < ($ - 3ffh))
  1712. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE 67
  1713. LOC  OBJECT CODE     LINE SOURCE TEXT
  1714.   VALUE
  1715. 000980 ECD4 F000          M         call    DUNN
  1716.                           M           else
  1717.                           M         rcall   DUNN
  1718.                           M           endif
  1719.                           M         endif
  1720.                           M       endif
  1721.                           M     endif
  1722.                       00095         LCDOUT?C        0FEh
  1723.                           M         MOVE?CA 0FEh
  1724. 000984 0EFE               M         movlw   low (0FEh)
  1725.                           M         L?CALL  LCDOUT
  1726.                           M         RST?RP
  1727.                           M     if (PREV_BANK != 0)
  1728.                           M         movlb   0
  1729.                           M PREV_BANK = 0
  1730.                           M     endif
  1731.                           M 
  1732.                           M     ifdef USE_LINKER
  1733.                           M         call    LCDOUT
  1734.                           M     else
  1735.                           M       if ((LCDOUT) < 1)
  1736.                           M         call    LCDOUT
  1737.                           M       else
  1738.                           M         if ((LCDOUT) > $)
  1739.                           M         call    LCDOUT
  1740.                           M         else
  1741.                           M           if ((LCDOUT) < ($ - 3ffh))
  1742. 000986 EC23 F000          M         call    LCDOUT
  1743.                           M           else
  1744.                           M         rcall   LCDOUT
  1745.                           M           endif
  1746.                           M         endif
  1747.                           M       endif
  1748.                           M     endif
  1749.                       00096         LCDOUT?C        001h
  1750.                           M         MOVE?CA 001h
  1751. 00098A 0E01               M         movlw   low (001h)
  1752.                           M         L?CALL  LCDOUT
  1753.                           M         RST?RP
  1754.                           M     if (PREV_BANK != 0)
  1755.                           M         movlb   0
  1756.                           M PREV_BANK = 0
  1757.                           M     endif
  1758.                           M 
  1759.                           M     ifdef USE_LINKER
  1760.                           M         call    LCDOUT
  1761.                           M     else
  1762.                           M       if ((LCDOUT) < 1)
  1763.                           M         call    LCDOUT
  1764.                           M       else
  1765.                           M         if ((LCDOUT) > $)
  1766.                           M         call    LCDOUT
  1767.                           M         else
  1768. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE 68
  1769. LOC  OBJECT CODE     LINE SOURCE TEXT
  1770.   VALUE
  1771.                           M           if ((LCDOUT) < ($ - 3ffh))
  1772. 00098C EC23 F000          M         call    LCDOUT
  1773.                           M           else
  1774.                           M         rcall   LCDOUT
  1775.                           M           endif
  1776.                           M         endif
  1777.                           M       endif
  1778.                           M     endif
  1779.                       00097         LCDOUT?C        04Dh
  1780.                           M         MOVE?CA 04Dh
  1781. 000990 0E4D               M         movlw   low (04Dh)
  1782.                           M         L?CALL  LCDOUT
  1783.                           M         RST?RP
  1784.                           M     if (PREV_BANK != 0)
  1785.                           M         movlb   0
  1786.                           M PREV_BANK = 0
  1787.                           M     endif
  1788.                           M 
  1789.                           M     ifdef USE_LINKER
  1790.                           M         call    LCDOUT
  1791.                           M     else
  1792.                           M       if ((LCDOUT) < 1)
  1793.                           M         call    LCDOUT
  1794.                           M       else
  1795.                           M         if ((LCDOUT) > $)
  1796.                           M         call    LCDOUT
  1797.                           M         else
  1798.                           M           if ((LCDOUT) < ($ - 3ffh))
  1799. 000992 EC23 F000          M         call    LCDOUT
  1800.                           M           else
  1801.                           M         rcall   LCDOUT
  1802.                           M           endif
  1803.                           M         endif
  1804.                           M       endif
  1805.                           M     endif
  1806.                       00098         LCDOUT?C        06Fh
  1807.                           M         MOVE?CA 06Fh
  1808. 000996 0E6F               M         movlw   low (06Fh)
  1809.                           M         L?CALL  LCDOUT
  1810.                           M         RST?RP
  1811.                           M     if (PREV_BANK != 0)
  1812.                           M         movlb   0
  1813.                           M PREV_BANK = 0
  1814.                           M     endif
  1815.                           M 
  1816.                           M     ifdef USE_LINKER
  1817.                           M         call    LCDOUT
  1818.                           M     else
  1819.                           M       if ((LCDOUT) < 1)
  1820.                           M         call    LCDOUT
  1821.                           M       else
  1822.                           M         if ((LCDOUT) > $)
  1823.                           M         call    LCDOUT
  1824. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE 69
  1825. LOC  OBJECT CODE     LINE SOURCE TEXT
  1826.   VALUE
  1827.                           M         else
  1828.                           M           if ((LCDOUT) < ($ - 3ffh))
  1829. 000998 EC23 F000          M         call    LCDOUT
  1830.                           M           else
  1831.                           M         rcall   LCDOUT
  1832.                           M           endif
  1833.                           M         endif
  1834.                           M       endif
  1835.                           M     endif
  1836.                       00099         LCDOUT?C        064h
  1837.                           M         MOVE?CA 064h
  1838. 00099C 0E64               M         movlw   low (064h)
  1839.                           M         L?CALL  LCDOUT
  1840.                           M         RST?RP
  1841.                           M     if (PREV_BANK != 0)
  1842.                           M         movlb   0
  1843.                           M PREV_BANK = 0
  1844.                           M     endif
  1845.                           M 
  1846.                           M     ifdef USE_LINKER
  1847.                           M         call    LCDOUT
  1848.                           M     else
  1849.                           M       if ((LCDOUT) < 1)
  1850.                           M         call    LCDOUT
  1851.                           M       else
  1852.                           M         if ((LCDOUT) > $)
  1853.                           M         call    LCDOUT
  1854.                           M         else
  1855.                           M           if ((LCDOUT) < ($ - 3ffh))
  1856. 00099E EC23 F000          M         call    LCDOUT
  1857.                           M           else
  1858.                           M         rcall   LCDOUT
  1859.                           M           endif
  1860.                           M         endif
  1861.                           M       endif
  1862.                           M     endif
  1863.                       00100         LCDOUT?C        075h
  1864.                           M         MOVE?CA 075h
  1865. 0009A2 0E75               M         movlw   low (075h)
  1866.                           M         L?CALL  LCDOUT
  1867.                           M         RST?RP
  1868.                           M     if (PREV_BANK != 0)
  1869.                           M         movlb   0
  1870.                           M PREV_BANK = 0
  1871.                           M     endif
  1872.                           M 
  1873.                           M     ifdef USE_LINKER
  1874.                           M         call    LCDOUT
  1875.                           M     else
  1876.                           M       if ((LCDOUT) < 1)
  1877.                           M         call    LCDOUT
  1878.                           M       else
  1879.                           M         if ((LCDOUT) > $)
  1880. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE 70
  1881. LOC  OBJECT CODE     LINE SOURCE TEXT
  1882.   VALUE
  1883.                           M         call    LCDOUT
  1884.                           M         else
  1885.                           M           if ((LCDOUT) < ($ - 3ffh))
  1886. 0009A4 EC23 F000          M         call    LCDOUT
  1887.                           M           else
  1888.                           M         rcall   LCDOUT
  1889.                           M           endif
  1890.                           M         endif
  1891.                           M       endif
  1892.                           M     endif
  1893.                       00101         LCDOUT?C        06Ch
  1894.                           M         MOVE?CA 06Ch
  1895. 0009A8 0E6C               M         movlw   low (06Ch)
  1896.                           M         L?CALL  LCDOUT
  1897.                           M         RST?RP
  1898.                           M     if (PREV_BANK != 0)
  1899.                           M         movlb   0
  1900.                           M PREV_BANK = 0
  1901.                           M     endif
  1902.                           M 
  1903.                           M     ifdef USE_LINKER
  1904.                           M         call    LCDOUT
  1905.                           M     else
  1906.                           M       if ((LCDOUT) < 1)
  1907.                           M         call    LCDOUT
  1908.                           M       else
  1909.                           M         if ((LCDOUT) > $)
  1910.                           M         call    LCDOUT
  1911.                           M         else
  1912.                           M           if ((LCDOUT) < ($ - 3ffh))
  1913. 0009AA EC23 F000          M         call    LCDOUT
  1914.                           M           else
  1915.                           M         rcall   LCDOUT
  1916.                           M           endif
  1917.                           M         endif
  1918.                           M       endif
  1919.                           M     endif
  1920.                       00102         LCDOUT?C        061h
  1921.                           M         MOVE?CA 061h
  1922. 0009AE 0E61               M         movlw   low (061h)
  1923.                           M         L?CALL  LCDOUT
  1924.                           M         RST?RP
  1925.                           M     if (PREV_BANK != 0)
  1926.                           M         movlb   0
  1927.                           M PREV_BANK = 0
  1928.                           M     endif
  1929.                           M 
  1930.                           M     ifdef USE_LINKER
  1931.                           M         call    LCDOUT
  1932.                           M     else
  1933.                           M       if ((LCDOUT) < 1)
  1934.                           M         call    LCDOUT
  1935.                           M       else
  1936. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE 71
  1937. LOC  OBJECT CODE     LINE SOURCE TEXT
  1938.   VALUE
  1939.                           M         if ((LCDOUT) > $)
  1940.                           M         call    LCDOUT
  1941.                           M         else
  1942.                           M           if ((LCDOUT) < ($ - 3ffh))
  1943. 0009B0 EC23 F000          M         call    LCDOUT
  1944.                           M           else
  1945.                           M         rcall   LCDOUT
  1946.                           M           endif
  1947.                           M         endif
  1948.                           M       endif
  1949.                           M     endif
  1950.                       00103         LCDOUT?C        064h
  1951.                           M         MOVE?CA 064h
  1952. 0009B4 0E64               M         movlw   low (064h)
  1953.                           M         L?CALL  LCDOUT
  1954.                           M         RST?RP
  1955.                           M     if (PREV_BANK != 0)
  1956.                           M         movlb   0
  1957.                           M PREV_BANK = 0
  1958.                           M     endif
  1959.                           M 
  1960.                           M     ifdef USE_LINKER
  1961.                           M         call    LCDOUT
  1962.                           M     else
  1963.                           M       if ((LCDOUT) < 1)
  1964.                           M         call    LCDOUT
  1965.                           M       else
  1966.                           M         if ((LCDOUT) > $)
  1967.                           M         call    LCDOUT
  1968.                           M         else
  1969.                           M           if ((LCDOUT) < ($ - 3ffh))
  1970. 0009B6 EC23 F000          M         call    LCDOUT
  1971.                           M           else
  1972.                           M         rcall   LCDOUT
  1973.                           M           endif
  1974.                           M         endif
  1975.                           M       endif
  1976.                           M     endif
  1977.                       00104         LCDOUT?C        06Fh
  1978.                           M         MOVE?CA 06Fh
  1979. 0009BA 0E6F               M         movlw   low (06Fh)
  1980.                           M         L?CALL  LCDOUT
  1981.                           M         RST?RP
  1982.                           M     if (PREV_BANK != 0)
  1983.                           M         movlb   0
  1984.                           M PREV_BANK = 0
  1985.                           M     endif
  1986.                           M 
  1987.                           M     ifdef USE_LINKER
  1988.                           M         call    LCDOUT