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

SCM

Development Platform:

HTML/CSS

  1. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE  1
  2. LOC  OBJECT CODE     LINE SOURCE TEXT
  3.   VALUE
  4.                       00001 
  5.                       00002 ; PICBASIC PRO(TM) Compiler 2.47, (c) 1998, 2006 microEngineering Labs, Inc. All Rights Reserved.  
  6.   00000001            00003 _USED                   EQU     1
  7.                       00004 
  8.                       00005         INCLUDE "D:PBP18F2550.INC"
  9.                       00001 ;****************************************************************
  10.                       00002 ;*  18F2550.INC                                                 *
  11.                       00003 ;*                                                              *
  12.                       00004 ;*  By        : Leonard Zerman, Jeff Schmoyer                   *
  13.                       00005 ;*  Notice    : Copyright (c) 2006 microEngineering Labs, Inc.  *
  14.                       00006 ;*              All Rights Reserved                             *
  15.                       00007 ;*  Date      : 06/05/06                                        *
  16.                       00008 ;*  Version   : 2.47                                            *
  17.                       00009 ;*  Notes     :                                                 *
  18.                       00010 ;****************************************************************
  19.                       00017         LIST
  20.                       00018         LIST p = 18F2550, r = dec, w = -311, w = -230, f = inhx32
  21.                       00019         INCLUDE "P18F2550.INC"  ; MPASM  Header
  22.                       00001         LIST
  23.                       00002 
  24.                       00003 ;==========================================================================
  25.                       00004 ;  MPASM PIC18F2550 processor include
  26.                       00005 ; 
  27.                       00006 ;  (c) Copyright 1999-2007 Microchip Technology, All rights reserved
  28.                       00007 ;==========================================================================
  29.                       00008 
  30.                       01486         LIST
  31.                       00020         __CONFIG    _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
  32. 300000 FEE4           00021         __CONFIG    _CONFIG1H, _FOSC_HSPLL_HS_1H
  33. 300002 F3FF           00022         __CONFIG    _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
  34. 300004 FDFF           00023         __CONFIG    _CONFIG3H, _PBADEN_OFF_3H
  35. 300006 FFBB           00024         __CONFIG    _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L
  36.                       00027         LIST
  37.   00F00000            00028 EEPROM_START    EQU     0F00000h
  38.   00000020            00029 BLOCK_SIZE      EQU     32
  39.                       00006 
  40.                       00007 
  41.                       00008 ; Define statements.
  42.                       00009 #define         OSC              48          
  43.                       00010 #define         LOADER_USED              1
  44.                       00011 #define         LCD_DREG                 PORTA       
  45.                       00012 #define         LCD_DBIT                 0           
  46.                       00013 #define         LCD_RSREG                PORTA      
  47.                       00014 #define         LCD_RSBIT                4          
  48.                       00015 #define         LCD_EREG                 PORTC       
  49.                       00016 #define         LCD_EBIT                 2           
  50.                       00017 #define         LCD_BITS                 4           
  51.                       00018 #define         LCD_LINES                2          
  52.                       00019 #define         LCD_COMMANDUS            2000   
  53.                       00020 #define         LCD_DATAUS               50        
  54.                       00021 
  55.   00000000            00022 RAM_START                       EQU     00000h
  56.   000003FF            00023 RAM_END                         EQU     003FFh
  57. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE  2
  58. LOC  OBJECT CODE     LINE SOURCE TEXT
  59.   VALUE
  60.   00000004            00024 RAM_BANKS                       EQU     00004h
  61.   00000060            00025 BANK0_START                     EQU     00060h
  62.   000000FF            00026 BANK0_END                       EQU     000FFh
  63.   00000100            00027 BANK1_START                     EQU     00100h
  64.   000001FF            00028 BANK1_END                       EQU     001FFh
  65.   00000200            00029 BANK2_START                     EQU     00200h
  66.   000002FF            00030 BANK2_END                       EQU     002FFh
  67.   00000300            00031 BANK3_START                     EQU     00300h
  68.   000003FF            00032 BANK3_END                       EQU     003FFh
  69.   00000000            00033 BANKA_START                     EQU     00000h
  70.   0000005F            00034 BANKA_END                       EQU     0005Fh
  71.                       00035 
  72.   00000000            00036 FLAGS                           EQU     RAM_START + 000h
  73.   00000001            00037 R0                              EQU     RAM_START + 001h
  74.   00000003            00038 R1                              EQU     RAM_START + 003h
  75.   00000005            00039 R2                              EQU     RAM_START + 005h
  76.   00000007            00040 R3                              EQU     RAM_START + 007h
  77.   00000009            00041 R4                              EQU     RAM_START + 009h
  78.   0000000B            00042 R5                              EQU     RAM_START + 00Bh
  79.   0000000D            00043 R6                              EQU     RAM_START + 00Dh
  80.   0000000F            00044 R7                              EQU     RAM_START + 00Fh
  81.   00000011            00045 R8                              EQU     RAM_START + 011h
  82.   00000013            00046 T1                              EQU     RAM_START + 013h
  83.   00000015            00047 GOP                             EQU     RAM_START + 015h
  84.   00000016            00048 RM1                             EQU     RAM_START + 016h
  85.   00000017            00049 RM2                             EQU     RAM_START + 017h
  86.   00000018            00050 RR1                             EQU     RAM_START + 018h
  87.   00000019            00051 RR2                             EQU     RAM_START + 019h
  88.   0000001A            00052 RS1                             EQU     RAM_START + 01Ah
  89.   0000001B            00053 RS2                             EQU     RAM_START + 01Bh
  90.   0000001C            00054 _Modulante                      EQU     RAM_START + 01Ch
  91.   0000001E            00055 _Frecuencia                     EQU     RAM_START + 01Eh
  92.   0000001F            00056 _Residuo                        EQU     RAM_START + 01Fh
  93.   00000020            00057 _USBBufferCount                 EQU     RAM_START + 020h
  94.   00000021            00058 _USBBuffer                      EQU     RAM_START + 021h
  95.   00000F81            00059 _PORTL                          EQU      PORTB
  96.   00000F82            00060 _PORTH                          EQU      PORTC
  97.   00000F93            00061 _TRISL                          EQU      TRISB
  98.   00000F94            00062 _TRISH                          EQU      TRISC
  99.                       00063 #define _incr                   _PORTC??0
  100.                       00064 #define _decr                   _PORTC??1
  101.                       00065 #define _PORTC??0                PORTC, 000h
  102.                       00066 #define _PORTC??1                PORTC, 001h
  103.                       00067 #define _TRISC??0                TRISC, 000h
  104.                       00068 #define _TRISC??1                TRISC, 001h
  105.                       00069 #define _TRISC??2                TRISC, 002h
  106.                       00070 
  107.                       00071 ; Constants.
  108.   00000010            00072 _USBBufferSizeMax               EQU     00010h
  109.   00000010            00073 _USBBufferSizeTX                EQU     00010h
  110.   00000010            00074 _USBBufferSizeRX                EQU     00010h
  111.   0000000A            00075 _FreqMin                        EQU     0000Ah
  112.                       00076 
  113. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE  3
  114. LOC  OBJECT CODE     LINE SOURCE TEXT
  115.   VALUE
  116.                       00077 ; EEPROM data.
  117.                       00078 
  118.                       00079 
  119.                       00080         INCLUDE "USBFM.MAC"
  120.                       00001 
  121.                       00273         LIST
  122.                       00081         INCLUDE "D:PBPPBPUSB18.LIB"
  123.                       00001 ;****************************************************************
  124.                       00002 ;*  PBPUSB18.LIB                                                *
  125.                       00003 ;*                                                              *
  126.                       00004 ;*  Notice    : Copyright (c) 2004 microEngineering Labs, Inc.  *
  127.                       00005 ;*              All Rights Reserved                             *
  128.                       00006 ;*  Date      : 12/31/04                                        *
  129.                       00007 ;*  Version   : 2.46                                            *
  130.                       00008 ;*  Notes     : PIC18 USB library                               *
  131.                       00009 ;****************************************************************
  132.                       00010 
  133.                       00011         include "PBPPBPPIC18.LIB"
  134.                       00001 ;******************************************************************
  135.                       00002 ;*  PBPPIC18.LIB                                                  *
  136.                       00003 ;*                                                                *
  137.                       00004 ;*  By        : Leonard Zerman, Jeff Schmoyer                     *
  138.                       00005 ;*  Notice    : Copyright (c) 2006 microEngineering Labs, Inc.    *
  139.                       00006 ;*              All Rights Reserved                               *
  140.                       00007 ;*  Date      : 06/05/06                                          *
  141.                       00008 ;*  Version   : 2.47                                              *
  142.                       00009 ;*  Notes     :                                                   *
  143.                       00010 ;******************************************************************
  144.                       00129   LIST
  145.                       00130 ; Oscillator is 48MHz
  146.                       01147   LIST
  147. 000000                01148     ORG RESET_ORG               ; Reset vector at 0
  148.                       01152   LIST
  149. 000000 6A00           01153         clrf    FLAGS           ; Clear all flags on reset
  150.                       01157   LIST
  151. 000002 EFD7 F000      01158         goto    INIT            ; Finish initialization
  152.                       01162   LIST
  153. 000008                01163     ORG RESET_ORG + 8           ; Make sure no library code in first 4 locs
  154.                       02853   LIST
  155. 000008 6A06           02854 LCDOUTDEC clrf  R2 + 1          ; Zero high value
  156.                       02860   LIST
  157. 00000A 6E05           02861 LCDOUTDECL movwf R2             ; Save low value
  158. 00000C 8E15           02862         bsf     GOP, 7          ; Set blanking on
  159. 00000E 0E27           02863         movlw   high 10000      ; Find 10,000s
  160. 000010 6E04           02864         movwf   R1 + 1
  161. 000012 0E10           02865         movlw   low 10000
  162. 000014 D80C           02866         rcall   lcdoutdig       ; Do the work
  163. 000016 0E03           02867         movlw   high 1000       ; Find 1,000s
  164. 000018 6E04           02868         movwf   R1 + 1
  165. 00001A 0EE8           02869         movlw   low 1000
  166. 00001C D808           02870         rcall   lcdoutdig       ; Do the work
  167. 00001E 6A04           02871         clrf    R1 + 1          ; Find 100s
  168. 000020 0E64           02872         movlw   100
  169. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE  4
  170. LOC  OBJECT CODE     LINE SOURCE TEXT
  171.   VALUE
  172. 000022 D805           02873         rcall   lcdoutdig       ; Do the work
  173. 000024 6A04           02874         clrf    R1 + 1          ; Find 10s
  174. 000026 0E0A           02875         movlw   10
  175. 000028 D802           02876         rcall   lcdoutdig       ; Do the work
  176. 00002A 5005           02877         movf    R2, W           ; Get the 1s
  177. 00002C D00B           02878         bra     lcdouta         ; Send the 1s
  178.                       02879 
  179. 00002E 6E03           02880 lcdoutdig movwf R1              ; Save last piece
  180. 000030 5006           02881         movf    R2 + 1, W       ; Move remainder to dividend
  181. 000032 6E02           02882         movwf   R0 + 1
  182. 000034 5005           02883         movf    R2, W
  183. 000036 6E01           02884         movwf   R0
  184. 000038 EC9D F000      02885         call    DIV             ; Do the math
  185. 00003C 6601           02886         tstfsz  R0              ; If zero, goto blank check
  186. 00003E 9E15           02887         bcf     GOP, 7          ; Not zero so clear blank
  187. 000040 BE15           02888         btfsc   GOP, 7          ; If blanking on, don't send
  188. 000042 0012           02889         return
  189. 000044 0F30           02890 lcdouta addlw   '0'             ; Add ASCII offset
  190.                       02918   LIST
  191. 000046 6E08           02919 LCDOUT  movwf   R3 + 1          ; Save char
  192.                       02920 
  193. 000048 9482           02921         bcf     LCD_EREG, LCD_EBIT      ; Set E low
  194. 00004A 9880           02922         bcf     LCD_RSREG, LCD_RSBIT    ; Set command register select
  195. 00004C 9880           02923         bcf     LCD_RWREG, LCD_RWBIT    ; Set RW low (write)
  196.                       02924 
  197. 00004E 9494           02925         bcf     (LCD_EREG) + 12h, LCD_EBIT      ; Set E to output
  198. 000050 9892           02926         bcf     (LCD_RSREG) + 12h, LCD_RSBIT    ; Set RS to output
  199. 000052 9892           02927         bcf     (LCD_RWREG) + 12h, LCD_RWBIT    ; Set RW to output
  200.                       02928     if (LCD_BITS == 8)
  201.                       02929         clrf    (LCD_DREG) + 12h        ; Set port to all output
  202.                       02930     else
  203.                       02931       if (LCD_DBIT == 0)
  204. 000054 0EF0           02932         movlw   0f0h
  205.                       02933       else
  206.                       02934         movlw   0fh
  207.                       02935       endif
  208. 000056 1692           02936         andwf   (LCD_DREG) + 12h, F     ; Set proper half of port to output
  209. 000058 5008           02937         movf    R3 + 1, W       ; Get back char
  210.                       02938     endif
  211.                       02939 
  212. 00005A B200           02940         btfsc   LCDINITFLAG     ; Has lcd been inititalized?
  213. 00005C D022           02941         bra     lcdout1         ; Yes
  214.                       02942 
  215. 00005E 0E3A           02943         movlw   high 15000      ; Wait at least 15ms
  216. 000060 6E02           02944         movwf   R0 + 1
  217. 000062 0E98           02945         movlw   low 15000
  218. 000064 EC8F F000      02946         call    PAUSEUSL
  219.                       02947 
  220. 000068 0E33           02948         movlw   33h             ; Init lcd
  221. 00006A 6E07           02949         movwf   R3              ; Save char
  222. 00006C D830           02950         rcall   lcdloop         ; Send init
  223.                       02951 
  224. 00006E 0E13           02952         movlw   high 5000       ; Wait at least 5ms
  225. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE  5
  226. LOC  OBJECT CODE     LINE SOURCE TEXT
  227.   VALUE
  228. 000070 6E02           02953         movwf   R0 + 1
  229. 000072 0E88           02954         movlw   low 5000
  230. 000074 EC8F F000      02955         call    PAUSEUSL
  231.                       02956 
  232. 000078 D82A           02957         rcall   lcdloop         ; Send init again
  233.                       02958 
  234. 00007A 0E64           02959         movlw   100             ; Wait at least 100us
  235. 00007C EC8E F000      02960         call    PAUSEUS
  236.                       02961 
  237. 000080 D826           02962         rcall   lcdloop         ; Send init more time
  238.                       02963 
  239. 000082 0E64           02964         movlw   100             ; Wait at least 100us
  240. 000084 EC8E F000      02965         call    PAUSEUS
  241.                       02966 
  242.                       02967     if (LCD_BITS != 8)
  243. 000088 0E22           02968         movlw   22h             ; Set 4-bit mode
  244. 00008A 6E07           02969         movwf   R3              ; Save character
  245. 00008C D820           02970         rcall   lcdloop         ; Set interface to 4-bit mode
  246.                       02971     endif
  247.                       02972 
  248.                       02973     if (LCD_BITS == 8)
  249.                       02974       if (LCD_LINES == 1)
  250.                       02975         movlw   30h             ; 8-bit mode, 1 line, 5x7 font
  251.                       02976       else
  252.                       02977         movlw   38h             ; 8-bit mode, 2+ lines, 5x7 font
  253.                       02978       endif
  254.                       02979     else
  255.                       02980       if (LCD_LINES == 1)
  256.                       02981         movlw   20h             ; 4-bit mode, 1 line, 5x7 font
  257.                       02982       else
  258. 00008E 0E28           02983         movlw   28h             ; 4-bit mode, 2+ lines, 5x7 font
  259.                       02984       endif
  260.                       02985     endif
  261. 000090 D807           02986         rcall   lcdoutcom       ; Send function set
  262.                       02987 
  263. 000092 0E0C           02988         movlw   0ch             ; Display on, no cursor, no blink
  264. 000094 D805           02989         rcall   lcdoutcom
  265.                       02990 
  266. 000096 0E06           02991         movlw   06h             ; Lcd entry mode set, increment, no shift
  267. 000098 D803           02992         rcall   lcdoutcom
  268.                       02993 
  269. 00009A 8200           02994         bsf     LCDINITFLAG     ; Set to initialized
  270.                       02995 
  271. 00009C 5008           02996         movf    R3 + 1, W       ; Get saved char back
  272. 00009E D001           02997         bra     lcdout1
  273.                       02998 
  274. 0000A0 8000           02999 lcdoutcom bsf   LCDCDFLAG       ; Set command
  275.                       03000 
  276. 0000A2 6E07           03001 lcdout1 movwf   R3              ; Save char if 4 bit
  277. 0000A4 A000           03002         btfss   LCDCDFLAG       ; Command this time?
  278. 0000A6 D00B           03003         bra     lcdchkcd        ; No
  279.                       03004 
  280. 0000A8 9880           03005         bcf     LCD_RSREG, LCD_RSBIT    ; Set command register select
  281. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE  6
  282. LOC  OBJECT CODE     LINE SOURCE TEXT
  283.   VALUE
  284. 0000AA 0803           03006         sublw   3
  285. 0000AC E30E           03007         bnc     lcdsend         ; Short delay
  286.                       03008 
  287. 0000AE D80D           03009         rcall   lcdsend         ; Long delay
  288. 0000B0 0E07           03010         movlw   high LCD_COMMANDUS      ; Wait for command to complete
  289. 0000B2 6E02           03011         movwf   R0 + 1
  290. 0000B4 0ED0           03012         movlw   low LCD_COMMANDUS
  291. 0000B6 EC8F F000      03013         call    PAUSEUSL
  292. 0000BA 80D8           03014         bsf     STATUS, C       ; Set no timeout for Serout2mod
  293. 0000BC 0012           03015         return
  294.                       03016 
  295. 0000BE 8000           03017 lcdchkcd bsf    LCDCDFLAG       ; Indicate first nibble (or command next time)
  296. 0000C0 08FE           03018         sublw   0feh            ; Command next time? (char still in W)
  297. 0000C2 B4D8           03019         btfsc   STATUS, Z
  298. 0000C4 EFD4 F000      03020         goto    DUNN            ; Yes - nothing to do this time (C set)
  299.                       03021 
  300. 0000C8 8880           03022         bsf     LCD_RSREG, LCD_RSBIT    ; Set data register select
  301.                       03023 
  302. 0000CA                03024 lcdsend
  303.                       03025     if (LCD_BITS == 8)
  304.                       03026 lcdloop bsf     LCD_EREG, LCD_EBIT      ; Enabled
  305.                       03027         movf    R3, W           ; Get char back
  306.                       03028         movwf   LCD_DREG        ; Write char to the port
  307.                       03029       if (OSC > 16)
  308.                       03030         nop                     ; Minimum 1us enable time
  309.                       03031       endif
  310.                       03032       if (OSC > 20)
  311.                       03033         bra     $ + 2
  312.                       03034       endif
  313.                       03035       if (OSC > 25)
  314.                       03036         bra     $ + 2
  315.                       03037       endif
  316.                       03038       if (OSC > 33)
  317.                       03039         nop
  318.                       03040       endif
  319.                       03041       if (OSC > 40)
  320.                       03042         bra     $ + 2
  321.                       03043       endif
  322.                       03044         bcf     LCDCDFLAG       ; Indicate data next time
  323.                       03045         bcf     LCD_EREG, LCD_EBIT      ; Not enabled
  324.                       03046     else
  325.                       03047 
  326.                       03048       if (LCD_DBIT == 0)
  327. 0000CA 3A07           03049         swapf   R3, F           ; Swap top and bottom nibbles
  328.                       03050       endif
  329.                       03051 
  330. 0000CC A000           03052         btfss   LCDCDFLAG       ; First time through only
  331. 0000CE 9000           03053 lcdloop bcf     LCDCDFLAG       ; Indicate second nibble (and data next time)
  332.                       03054 
  333. 0000D0 8482           03055         bsf     LCD_EREG, LCD_EBIT      ; Enabled
  334.                       03056 
  335.                       03057       if (LCD_DBIT == 0)
  336. 0000D2 0EF0           03058         movlw   0f0h            ; Clear lcd data port
  337. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE  7
  338. LOC  OBJECT CODE     LINE SOURCE TEXT
  339.   VALUE
  340.                       03059       else
  341.                       03060         movlw   0fh             ; Clear lcd data port
  342.                       03061       endif
  343. 0000D4 1680           03062         andwf   LCD_DREG, F
  344.                       03063 
  345. 0000D6 5007           03064         movf    R3, W           ; Isolate proper nibble of char
  346.                       03065       if (LCD_DBIT == 0)
  347. 0000D8 0B0F           03066         andlw   0fh
  348.                       03067       else
  349.                       03068         andlw   0f0h
  350.                       03069       endif
  351. 0000DA 1280           03070         iorwf   LCD_DREG, F     ; Write char to port
  352.                       03071 
  353.                       03072       if (OSC > 20)
  354. 0000DC 0000           03073         nop                     ; Minimum 1us enable time
  355.                       03074       endif
  356.                       03075       if (OSC > 25)
  357. 0000DE D000           03076         bra     $ + 2
  358.                       03077       endif
  359.                       03078       if (OSC > 33)
  360. 0000E0 0000           03079         nop
  361.                       03080       endif
  362.                       03081       if (OSC > 40)
  363. 0000E2 D000           03082         bra     $ + 2
  364.                       03083       endif
  365.                       03084 
  366. 0000E4 9482           03085         bcf     LCD_EREG, LCD_EBIT      ; Not enabled - that's four
  367. 0000E6 3A07           03086         swapf   R3, F           ; Get to other nibble
  368.                       03087 
  369.                       03088       if (OSC > 20)
  370. 0000E8 0000           03089         nop                     ; Minimum 1us not-enabled time
  371.                       03090       endif
  372.                       03091       if (OSC > 25)
  373. 0000EA D000           03092         bra     $ + 2
  374.                       03093       endif
  375.                       03094       if (OSC > 33)
  376. 0000EC 0000           03095         nop
  377.                       03096       endif
  378.                       03097       if (OSC > 40)
  379. 0000EE D000           03098         bra     $ + 2
  380.                       03099       endif
  381.                       03100 
  382. 0000F0 B000           03101         btfsc   LCDCDFLAG
  383. 0000F2 D7ED           03102         bra     lcdloop         ; Send lower 4 to lcd
  384.                       03103     endif
  385.                       03104 
  386. 0000F4 0E32           03105         movlw   LCD_DATAUS      ; Wait for data operation to complete
  387. 0000F6 EC8E F000      03106         call    PAUSEUS
  388. 0000FA 80D8           03107         bsf     STATUS, C       ; Set no timeout for Serout2mod
  389. 0000FC EFD4 F000      03108         goto    DUNN
  390.                       06227   LIST
  391. 000100 6A04           06228 PAUSE   clrf    R1 + 1
  392. 000102 6E03           06229 PAUSEL  movwf   R1
  393. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE  8
  394. LOC  OBJECT CODE     LINE SOURCE TEXT
  395.   VALUE
  396. 000104 0EFF           06230 pauseloop movlw -1              ; 1 (9)
  397. 000106 2603           06231         addwf   R1, F           ; 1
  398. 000108 A0D8           06232         btfss   STATUS, C       ; 1 / 2
  399. 00010A 2604           06233         addwf   R1 + 1, F       ; 1 / 0
  400. 00010C A0D8           06234         btfss   STATUS, C       ; 2
  401. 00010E EFD4 F000      06235         goto    DUNN
  402. 000112 0E03           06236         movlw   (PAUSE_DELAY) >> 8      ; 1
  403. 000114 6E02           06237         movwf   R0 + 1          ; 1
  404. 000116 0EE7           06238         movlw   low (PAUSE_DELAY)       ; 1
  405. 000118 D802           06239         rcall   PAUSEUSL        ; -2 (PAUSEUSL gives you 2 less than you ask for)
  406. 00011A D7F4           06240         bra     pauseloop       ; 2
  407.                       06661   LIST
  408. 00011C 6A02           06662 PAUSEUS clrf    R0 + 1          ; 1
  409. 00011E 0FFD           06663 PAUSEUSL addlw  -3              ; 1 Subtract overhead
  410. 000120 6E01           06664         movwf   R0              ; 1
  411. 000122 0EFF           06665         movlw   -1              ; 1
  412. 000124 D000           06666         bra     $ + 2           ; 2
  413. 000126 D001           06667         bra     pauseush        ; 2
  414. 000128 2601           06668 pauseusloop addwf R0, F         ; 1
  415.                       06669 pauseush CLRWDT?NOP             ; 1
  416.                           M     ifndef NO_CLRWDT
  417. 00012A 0004               M         clrwdt
  418.                           M     else
  419.                           M         nop
  420.                           M     endif
  421. 00012C D000           06670         bra     $ + 2           ; 2
  422. 00012E D000           06671         bra     $ + 2           ; 2
  423. 000130 A0D8           06672         btfss   STATUS, C       ; 1 / 2
  424. 000132 2602           06673         addwf   R0 + 1, F       ; 1 / 0
  425. 000134 A0D8           06674         btfss   STATUS, C       ; 1 / 2
  426. 000136 0012           06675         return                  ; 2 + 3 (call + setup)
  427. 000138 D7F7           06676         bra     pauseusloop     ; 2
  428.                       07496   LIST
  429. 00013A 6A06           07497 DIV     clrf    R2 + 1
  430. 00013C 6A05           07498         clrf    R2
  431.                       07499 
  432. 00013E 0E10           07500 DIV32DIV movlw   16
  433. 000140 6E07           07501         movwf   R3
  434.                       07502 
  435. 000142 3402           07503 divloop rlcf    R0 + 1, W
  436. 000144 3605           07504         rlcf    R2, F
  437. 000146 3606           07505         rlcf    R2 + 1, F
  438. 000148 5003           07506         movf    R1, W
  439. 00014A 5E05           07507         subwf   R2, F
  440. 00014C 5004           07508         movf    R1 + 1, W
  441. 00014E 5A06           07509         subwfb  R2 + 1, F
  442.                       07510 
  443. 000150 E205           07511         bc      divok
  444. 000152 5003           07512         movf    R1, W
  445. 000154 2605           07513         addwf   R2, F
  446. 000156 5004           07514         movf    R1 + 1, W
  447. 000158 2206           07515         addwfc  R2 + 1, F
  448.                       07516 
  449. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE  9
  450. LOC  OBJECT CODE     LINE SOURCE TEXT
  451.   VALUE
  452. 00015A 90D8           07517         bcf     STATUS, C
  453.                       07518 
  454. 00015C 3601           07519 divok   rlcf    R0, F
  455. 00015E 3602           07520         rlcf    R0 + 1, F
  456.                       07521 
  457. 000160 2E07           07522         decfsz  R3, F
  458. 000162 D7EF           07523         bra     divloop
  459. 000164 5001           07524         movf    R0, W           ; Get low byte to W
  460. 000166 EFD4 F000      07525         goto    DUNN
  461.                       07542   LIST
  462. 00016A 5003           07543 MUL     movf    R1, W
  463. 00016C 0207           07544         mulwf   R3              ; R1 * R3 = PRODHL
  464.                       07545 
  465. 00016E CFF4 F006      07546         movff   PRODH, R2 + 1
  466. 000172 CFF3 F005      07547         movff   PRODL, R2
  467.                       07548 
  468. 000176 5004           07549         movf    R1 + 1, W
  469. 000178 0208           07550         mulwf   R3 + 1          ; R1 + 1 * R3 + 1 = PRODHL
  470.                       07551 
  471. 00017A CFF4 F002      07552         movff   PRODH, R0 + 1
  472. 00017E CFF3 F001      07553         movff   PRODL, R0
  473.                       07554 
  474. 000182 5003           07555         movf    R1, W
  475. 000184 0208           07556         mulwf   R3 + 1          ; R1 * R3 + 1 = PRODHL
  476.                       07557 
  477. 000186 50F3           07558         movf    PRODL, W        ; Add cross products
  478. 000188 2606           07559         addwf   R2 + 1, F
  479. 00018A 50F4           07560         movf    PRODH, W
  480. 00018C 2201           07561         addwfc  R0, F
  481. 00018E 6AE8           07562         clrf    WREG
  482. 000190 2202           07563         addwfc  R0 + 1, F
  483.                       07564 
  484. 000192 5004           07565         movf    R1 + 1, W
  485. 000194 0207           07566         mulwf   R3              ; R1 + 1 * R3 = PRODHL
  486.                       07567 
  487. 000196 50F3           07568         movf    PRODL, W        ; Add cross products
  488. 000198 2606           07569         addwf   R2 + 1, F
  489. 00019A 50F4           07570         movf    PRODH, W
  490. 00019C 2201           07571         addwfc  R0, F
  491. 00019E 6AE8           07572         clrf    WREG
  492. 0001A0 2202           07573         addwfc  R0 + 1, F
  493.                       07574 
  494. 0001A2 5005           07575         movf    R2, W           ; Get low byte to W
  495. 0001A4 EFD4 F000      07576         goto    DUNN
  496.                       07647   LIST
  497. 0001A8 0100           07648 DUNN    movlb   0               ; 1 Reset banks to 0
  498.                       07649 DUNN3   CLRWDT?NOP              ; 1 Hit Watchdog timer
  499.                           M     ifndef NO_CLRWDT
  500. 0001AA 0004               M         clrwdt
  501.                           M     else
  502.                           M         nop
  503.                           M     endif
  504. 0001AC 0012           07650 DUNNRET return                  ; 2 Done
  505. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE 10
  506. LOC  OBJECT CODE     LINE SOURCE TEXT
  507.   VALUE
  508.                       07663   LIST
  509. 0001AE                07664 INIT
  510.                       07708   LIST
  511. 0001AE                07709 main
  512. 0001AE EFB0 F004      00012         goto MAINPROG
  513.                       00013         include "USB18.INC"
  514.                       00001 ; MUID = Microchip USB Class ID
  515.                       00002 ; Used to identify which of the USB classes owns the current
  516.                       00003 ; session of control transfer over EP0
  517.                       00004 #define MUID_NULL               0
  518.                       00005 #define MUID_USB9               1
  519.                       00006 #define MUID_HID                2
  520.                       00007 #define MUID_CDC                3
  521.                       00008 #define MUID_MSD                4
  522.                       00009 
  523.                       00010 ; Buffer Descriptor Status Register Initialization Parameters
  524.                       00011 #define _BSTALL                 0x04    ; Buffer Stall enable
  525.                       00012 #define _DTSEN                  0x08    ; Data Toggle Synch enable
  526.                       00013 #define _INCDIS                 0x10    ; Address increment disable
  527.                       00014 #define _KEN                    0x20    ; SIE keeps buff descriptors enable
  528.                       00015 #define _DAT0                   0x00    ; DATA0 packet expected next
  529.                       00016 #define _DAT1                   0x40    ; DATA1 packet expected next
  530.                       00017 #define _DTSMASK                0x40    ; DTS Mask
  531.                       00018 #define _USIE                   0x80    ; SIE owns buffer
  532.                       00019 #define _UCPU                   0x00    ; CPU owns buffer
  533.                       00020 
  534.                       00021 ; USB Device States - To be used with [byte usb_device_state]
  535.                       00022 #define DETACHED_STATE          0
  536.                       00023 #define ATTACHED_STATE          1
  537.                       00024 #define POWERED_STATE           2
  538.                       00025 #define DEFAULT_STATE           3
  539.                       00026 #define ADR_PENDING_STATE       4
  540.                       00027 #define ADDRESS_STATE           5
  541.                       00028 #define CONFIGURED_STATE        6
  542.                       00029 
  543.                       00030 ; Memory Types for Control Transfer - used in USB_DEVICE_STATUS
  544.                       00031 ;#define        _RAM                    0
  545.                       00032 ;#define        _ROM                    1
  546.                       00033 
  547.                       00034 
  548.                       00035 ; From usbdefs_std_dsc.h
  549.                       00036 ; Descriptor Types
  550.                       00037 #define DSC_DEV     0x01
  551.                       00038 #define DSC_CFG     0x02
  552.                       00039 #define DSC_STR     0x03
  553.                       00040 #define DSC_INTF    0x04
  554.                       00041 #define DSC_EP      0x05
  555.                       00042 
  556.                       00043 ; USB Endpoint Definitions
  557.                       00044 #define _EP01_OUT   0x01
  558.                       00045 #define _EP01_IN    0x81
  559.                       00046 #define _EP02_OUT   0x02
  560.                       00047 #define _EP02_IN    0x82
  561. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE 11
  562. LOC  OBJECT CODE     LINE SOURCE TEXT
  563.   VALUE
  564.                       00048 #define _EP03_OUT   0x03
  565.                       00049 #define _EP03_IN    0x83
  566.                       00050 #define _EP04_OUT   0x04
  567.                       00051 #define _EP04_IN    0x84
  568.                       00052 #define _EP05_OUT   0x05
  569.                       00053 #define _EP05_IN    0x85
  570.                       00054 #define _EP06_OUT   0x06
  571.                       00055 #define _EP06_IN    0x86
  572.                       00056 #define _EP07_OUT   0x07
  573.                       00057 #define _EP07_IN    0x87
  574.                       00058 #define _EP08_OUT   0x08
  575.                       00059 #define _EP08_IN    0x88
  576.                       00060 #define _EP09_OUT   0x09
  577.                       00061 #define _EP09_IN    0x89
  578.                       00062 #define _EP10_OUT   0x0A
  579.                       00063 #define _EP10_IN    0x8A
  580.                       00064 #define _EP11_OUT   0x0B
  581.                       00065 #define _EP11_IN    0x8B
  582.                       00066 #define _EP12_OUT   0x0C
  583.                       00067 #define _EP12_IN    0x8C
  584.                       00068 #define _EP13_OUT   0x0D
  585.                       00069 #define _EP13_IN    0x8D
  586.                       00070 #define _EP14_OUT   0x0E
  587.                       00071 #define _EP14_IN    0x8E
  588.                       00072 #define _EP15_OUT   0x0F
  589.                       00073 #define _EP15_IN    0x8F
  590.                       00074 
  591.                       00075 ; Configuration Attributes
  592.                       00076 ;#define        _DEFAULT        0x01<<7         ; Default Value (Bit 7 is set)
  593.                       00077 ;#define        _SELF           0x01<<6         ; Self-powered (Supports if set)
  594.                       00078 ;#define        _RWU            0x01<<5         ; Remote Wakeup (Supports if set)
  595.                       00079 
  596.                       00080 ; Endpoint Transfer Type
  597.                       00081 ;#define        _CTRL           0x00            ; Control Transfer
  598.                       00082 ;#define        _ISO            0x01            ; Isochronous Transfer
  599.                       00083 ;#define        _BULK           0x02            ; Bulk Transfer
  600.                       00084 ;#define        _INT            0x03            ; Interrupt Transfer
  601.                       00085 
  602.                       00086 ; Isochronous Endpoint Synchronization Type
  603.                       00087 ;#define        _NS             0x00<<2         ; No Synchronization
  604.                       00088 ;#define        _AS             0x01<<2         ; Asynchronous
  605.                       00089 ;#define        _AD             0x02<<2         ; Adaptive
  606.                       00090 ;#define        _SY             0x03<<2         ; Synchronous
  607.                       00091 
  608.                       00092 ; Isochronous Endpoint Usage Type
  609.                       00093 ;#define        _DE             0x00<<4         ; Data endpoint
  610.                       00094 ;#define        _FE             0x01<<4         ; Feedback endpoint
  611.                       00095 ;#define        _IE             0x02<<4         ; Implicit feedback Data endpoint
  612.                       00096 
  613.                       00097 
  614.                       00098 ; From usb9.h
  615.                       00099 ; Standard Request Codes
  616.                       00100 ; USB 2.0 Spec Ref Table 9-4
  617. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE 12
  618. LOC  OBJECT CODE     LINE SOURCE TEXT
  619.   VALUE
  620.                       00101 #define GET_STATUS              0
  621.                       00102 #define CLR_FEATURE             1
  622.                       00103 #define SET_FEATURE             3
  623.                       00104 #define SET_ADR                 5
  624.                       00105 #define GET_DSC                 6
  625.                       00106 #define SET_DSC                 7
  626.                       00107 #define GET_CFG                 8
  627.                       00108 #define SET_CFG                 9
  628.                       00109 #define GET_INTF                10
  629.                       00110 #define SET_INTF                11
  630.                       00111 #define SYNCH_FRAME             12
  631.                       00112 
  632.                       00113 ; Standard Feature Selectors
  633.                       00114 #define DEVICE_REMOTE_WAKEUP    0x01
  634.                       00115 #define ENDPOINT_HALT           0x00
  635.                       00116 
  636.                       00117 
  637.                       00118 ; From hid.h
  638.                       00119 ; Class-Specific Requests
  639.                       00120 #define GET_REPORT              0x01
  640.                       00121 #define GET_IDLE                0x02
  641.                       00122 #define GET_PROTOCOL            0x03
  642.                       00123 #define SET_REPORT              0x09
  643.                       00124 #define SET_IDLE                0x0A
  644.                       00125 #define SET_PROTOCOL            0x0B
  645.                       00126 
  646.                       00127 ; Class Descriptor Types
  647.                       00128 #define DSC_HID                 0x21
  648.                       00129 #define DSC_RPT                 0x22
  649.                       00130 #define DSC_PHY                 0x23
  650.                       00131 
  651.                       00132 ; Protocol Selection
  652.                       00133 #define BOOT_PROTOCOL           0x00
  653.                       00134 #define RPT_PROTOCOL            0x01
  654.                       00135 
  655.                       00136 ; HID Interface Class Code
  656.                       00137 #define HID_INTF                0x03
  657.                       00138 
  658.                       00139 ; HID Interface Class SubClass Codes
  659.                       00140 #define BOOT_INTF_SUBCLASS      0x01
  660.                       00141 
  661.                       00142 ; HID Interface Class Protocol Codes
  662.                       00143 #define HID_PROTOCOL_NONE       0x00
  663.                       00144 #define HID_PROTOCOL_KEYBOAD    0x01
  664.                       00145 #define HID_PROTOCOL_MOUSE      0x02
  665.                       00146 
  666.                       00147 ; HID Report codes used in GET_REPORT and SET_REPORT requests
  667.                       00148 #define HID_INPUT_REPORT        1
  668.                       00149 #define HID_OUTPUT_REPORT       2
  669.                       00150 #define HID_FEATURE_REPORT      3
  670.                       00151 
  671.                       00152 
  672.                       00153 ; From cdc.h
  673. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE 13
  674. LOC  OBJECT CODE     LINE SOURCE TEXT
  675.   VALUE
  676.                       00154 ; Class-Specific Requests
  677.                       00155 #define SEND_ENCAPSULATED_COMMAND 0x00
  678.                       00156 #define GET_ENCAPSULATED_RESPONSE 0x01
  679.                       00157 #define SET_COMM_FEATURE        0x02
  680.                       00158 #define GET_COMM_FEATURE        0x03
  681.                       00159 #define CLEAR_COMM_FEATURE      0x04
  682.                       00160 #define SET_LINE_CODING         0x20
  683.                       00161 #define GET_LINE_CODING         0x21
  684.                       00162 #define SET_CONTROL_LINE_STATE  0x22
  685.                       00163 #define SEND_BREAK              0x23
  686.                       00164 
  687.                       00165 ; Notifications
  688.                       00166 ;  Note: Notifications are polled over
  689.                       00167 ;  Communication Interface (Interrupt Endpoint)
  690.                       00168 #define NETWORK_CONNECTION      0x00
  691.                       00169 #define RESPONSE_AVAILABLE      0x01
  692.                       00170 #define SERIAL_STATE            0x20
  693.                       00171 
  694.                       00172 ; Device Class Code
  695.                       00173 #define CDC_DEVICE              0x02
  696.                       00174 
  697.                       00175 ; Communication Interface Class Code
  698.                       00176 #define COMM_INTF               0x02
  699.                       00177 
  700.                       00178 ; Communication Interface Class SubClass Codes
  701.                       00179 #define ABSTRACT_CONTROL_MODEL  0x02
  702.                       00180 
  703.                       00181 ; Communication Interface Class Control Protocol Codes
  704.                       00182 #define V25TER                  0x01    ; Common AT commands ("Hayes(TM)")
  705.                       00183 
  706.                       00184 ; Data Interface Class Codes
  707.                       00185 #define DATA_INTF               0x0A
  708.                       00186 
  709.                       00187 ; Data Interface Class Protocol Codes
  710.                       00188 #define NO_PROTOCOL             0x00    ; No class specific protocol required
  711.                       00189 
  712.                       00190 ; Communication Feature Selector Codes
  713.                       00191 #define ABSTRACT_STATE          0x01
  714.                       00192 #define COUNTRY_SETTING         0x02
  715.                       00193 
  716.                       00194 ; Functional Descriptors
  717.                       00195 ; Type Values for the bDscType Field
  718.                       00196 #define CS_INTERFACE            0x24
  719.                       00197 #define CS_ENDPOINT             0x25
  720.                       00198 
  721.                       00199 ; bDscSubType in Functional Descriptors
  722.                       00200 #define DSC_FN_HEADER           0x00
  723.                       00201 #define DSC_FN_CALL_MGT         0x01
  724.                       00202 #define DSC_FN_ACM              0x02    ; ACM - Abstract Control Management
  725.                       00203 #define DSC_FN_DLM              0x03    ; DLM - Direct Line Managment
  726.                       00204 #define DSC_FN_TELEPHONE_RINGER 0x04
  727.                       00205 #define DSC_FN_RPT_CAPABILITIES 0x05
  728.                       00206 #define DSC_FN_UNION            0x06
  729. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE 14
  730. LOC  OBJECT CODE     LINE SOURCE TEXT
  731.   VALUE
  732.                       00207 #define DSC_FN_COUNTRY_SELECTION 0x07
  733.                       00208 #define DSC_FN_TEL_OP_MODES     0x08
  734.                       00209 #define DSC_FN_USB_TERMINAL     0x09
  735.                       00210 ; more.... see Table 25 in USB CDC Specification 1.1
  736.                       00211 
  737.                       00212 ; CDC Bulk IN transfer states
  738.                       00213 #define CDC_TX_READY            0
  739.                       00214 #define CDC_TX_BUSY             1
  740.                       00215 #define CDC_TX_BUSY_ZLP         2       ; ZLP: Zero Length Packet
  741.                       00216 #define CDC_TX_COMPLETING       3
  742.                       00217 
  743.                       00218 #define LINE_CODING_LENGTH      0x07
  744.                       00219 #define dummy_length            0x08
  745.                       00220 
  746.                       00221 
  747.                       00222 ; From usbctrltrf.h
  748.                       00223 ; Control Transfer States
  749.                       00224 #define WAIT_SETUP              0
  750.                       00225 #define CTRL_TRF_TX             1
  751.                       00226 #define CTRL_TRF_RX             2
  752.                       00227 
  753.                       00228 ; USB PID: Token Types - See chapter 8 in the USB specification
  754.                       00229 #define SETUP_TOKEN             0x0d
  755.                       00230 #define OUT_TOKEN               0x01
  756.                       00231 #define IN_TOKEN                0x09
  757.                       00232 
  758.                       00233 ; bmRequestType Definitions
  759.                       00234 #define HOST_TO_DEV             0
  760.                       00235 #define DEV_TO_HOST             1
  761.                       00236 
  762.                       00237 #define STANDARD                0x00
  763.                       00238 #define CLASS                   0x01
  764.                       00239 #define VENDOR                  0x02
  765.                       00240 
  766.                       00241 #define RCPT_DEV                0
  767.                       00242 #define RCPT_INTF               1
  768.                       00243 #define RCPT_EP                 2
  769.                       00244 #define RCPT_OTH                3
  770.                       00245 
  771.                       00246 
  772.                       00247 ; From usbdrv.h
  773.                       00248 ; UCFG Initialization Parameters
  774.                       00249 #define _PPBM0                  0x00    ; Pingpong Buffer Mode 0
  775.                       00250 #define _PPBM1                  0x01    ; Pingpong Buffer Mode 1
  776.                       00251 #define _PPBM2                  0x02    ; Pingpong Buffer Mode 2
  777.                       00252 #define _LS                     0x00    ; Use Low-Speed USB Mode
  778.                       00253 #define _FS                     0x04    ; Use Full-Speed USB Mode
  779.                       00254 #define _TRINT                  0x00    ; Use internal transceiver
  780.                       00255 #define _TREXT                  0x08    ; Use external transceiver
  781.                       00256 #define _PUEN                   0x10    ; Use internal pull-up resistor
  782.                       00257 #define _OEMON                  0x40    ; Use SIE output indicator
  783.                       00258 #define _UTEYE                  0x80    ; Use Eye-Pattern test
  784.                       00259 
  785. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE 15
  786. LOC  OBJECT CODE     LINE SOURCE TEXT
  787.   VALUE
  788.                       00260 ; UEPn Initialization Parameters
  789.                       00261 #define EP_CTRL                 0x06    ; Cfg Control pipe for this ep
  790.                       00262 #define EP_OUT                  0x0C    ; Cfg OUT only pipe for this ep
  791.                       00263 #define EP_IN                   0x0A    ; Cfg IN only pipe for this ep
  792.                       00264 #define EP_OUT_IN               0x0E    ; Cfg both OUT & IN pipes for this ep
  793.                       00265 #define HSHK_EN                 0x10    ; Enable handshake packet
  794.                       00266 
  795.                       00267 #define OUT             0
  796.                       00268 #define IN              1
  797.                       00269 
  798.                       00270 #define PIC_EP_NUM_MASK 0b01111000
  799.                       00271 #define PIC_EP_DIR_MASK 0b00000100
  800.                       00272 
  801.                       00273 #define EP00_OUT        ((0x00<<3)|(OUT<<2))
  802.                       00274 #define EP00_IN         ((0x00<<3)|(IN<<2))
  803.                       00275 #define EP01_OUT        ((0x01<<3)|(OUT<<2))
  804.                       00276 #define EP01_IN         ((0x01<<3)|(IN<<2))
  805.                       00277 #define EP02_OUT        ((0x02<<3)|(OUT<<2))
  806.                       00278 #define EP02_IN         ((0x02<<3)|(IN<<2))
  807.                       00279 #define EP03_OUT        ((0x03<<3)|(OUT<<2))
  808.                       00280 #define EP03_IN         ((0x03<<3)|(IN<<2))
  809.                       00281 #define EP04_OUT        ((0x04<<3)|(OUT<<2))
  810.                       00282 #define EP04_IN         ((0x04<<3)|(IN<<2))
  811.                       00283 #define EP05_OUT        ((0x05<<3)|(OUT<<2))
  812.                       00284 #define EP05_IN         ((0x05<<3)|(IN<<2))
  813.                       00285 #define EP06_OUT        ((0x06<<3)|(OUT<<2))
  814.                       00286 #define EP06_IN         ((0x06<<3)|(IN<<2))
  815.                       00287 #define EP07_OUT        ((0x07<<3)|(OUT<<2))
  816.                       00288 #define EP07_IN         ((0x07<<3)|(IN<<2))
  817.                       00289 #define EP08_OUT        ((0x08<<3)|(OUT<<2))
  818.                       00290 #define EP08_IN         ((0x08<<3)|(IN<<2))
  819.                       00291 #define EP09_OUT        ((0x09<<3)|(OUT<<2))
  820.                       00292 #define EP09_IN         ((0x09<<3)|(IN<<2))
  821.                       00293 #define EP10_OUT        ((0x0A<<3)|(OUT<<2))
  822.                       00294 #define EP10_IN         ((0x0A<<3)|(IN<<2))
  823.                       00295 #define EP11_OUT        ((0x0B<<3)|(OUT<<2))
  824.                       00296 #define EP11_IN         ((0x0B<<3)|(IN<<2))
  825.                       00297 #define EP12_OUT        ((0x0C<<3)|(OUT<<2))
  826.                       00298 #define EP12_IN         ((0x0C<<3)|(IN<<2))
  827.                       00299 #define EP13_OUT        ((0x0D<<3)|(OUT<<2))
  828.                       00300 #define EP13_IN         ((0x0D<<3)|(IN<<2))
  829.                       00301 #define EP14_OUT        ((0x0E<<3)|(OUT<<2))
  830.                       00302 #define EP14_IN         ((0x0E<<3)|(IN<<2))
  831.                       00303 #define EP15_OUT        ((0x0F<<3)|(OUT<<2))
  832.                       00304 #define EP15_IN         ((0x0F<<3)|(IN<<2))
  833.                       00014         include "USBDESC.ASM"   ; Application specific descriptors
  834.                       00001 ; This file contains an include for the application specific
  835.                       00002 ; USB descriptors.  Include only ONE of the following or add
  836.                       00003 ; your own for your own project.
  837.                       00004 
  838.                       00005         include "DESCUSBFm.ASM" ; USB descriptors
  839.                       00001 
  840.                       00002 
  841. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE 16
  842. LOC  OBJECT CODE     LINE SOURCE TEXT
  843.   VALUE
  844.                       00003 #define EP0_BUFF_SIZE           64      ; 8, 16, 32, or 64
  845.                       00004 #define MAX_NUM_INT             1       ; For tracking Alternate Setting
  846.                       00005 #define MAX_EP_NUMBER           1       ; UEP1
  847.                       00006 #define NUM_CONFIGURATIONS      1
  848.                       00007 #define NUM_INTERFACES          1
  849.                       00008 
  850.                       00009 #define MODE_PP                     _PPBM0
  851.                       00010 #define UCFG_VAL                    _PUEN|_TRINT|_FS|MODE_PP    ; Full-speed
  852.                       00011 
  853.                       00012 ; DEVICE CLASS USAGE
  854.                       00013 #define USB_USE_HID
  855.                       00014 
  856.                       00015 ; HID
  857.                       00016 ; Endpoints Allocation
  858.                       00017 #define HID_INTF_ID               0x00
  859.                       00018 #define HID_UEP                   UEP1
  860.                       00019 #define HID_BD_OUT                ep1Bo
  861.                       00020 #define HID_INT_OUT_EP_SIZE       64
  862.                       00021 #define HID_BD_IN                 ep1Bi
  863.                       00022 #define HID_INT_IN_EP_SIZE        64
  864.                       00023 #define HID_NUM_OF_DSC            1
  865.                       00024 
  866.                       00025 ; ******************************************************************
  867.                       00026 ; This table is polled by the host immediately after USB Reset has been released.
  868.                       00027 ; This table defines the maximum packet size EP0 can take.
  869.                       00028 ; See section 9.6.1 of the Rev 1.0 USB specification.
  870.                       00029 ; These fields are application DEPENDENT. Modify these to meet
  871.                       00030 ; your specifications.
  872.                       00031 ; ******************************************************************
  873. 0001B2                00032 DeviceDescriptor
  874. 0001B2 0C12           00033         retlw   (EndDeviceDescriptor-DeviceDescriptor)/2        ; bLength Length of this descriptor
  875. 0001B4 0C01           00034         retlw   DSC_DEV         ; bDescType This is a DEVICE descriptor
  876. 0001B6 0C10           00035         retlw   0x10            ; bcdUSBUSB Revision 1.10 (low byte)
  877. 0001B8 0C01           00036         retlw   0x01            ; high byte
  878. 0001BA 0C00           00037         retlw   0x00            ; bDeviceClass zero means each interface operates independently
  879. 0001BC 0C00           00038         retlw   0x00            ; bDeviceSubClass
  880. 0001BE 0C00           00039         retlw   0x00            ; bDeviceProtocol
  881. 0001C0 0C40           00040         retlw   EP0_BUFF_SIZE   ; bMaxPacketSize for EP0
  882.                       00041 
  883.                       00042         ; idVendor (low byte, high byte)
  884. 0001C2 0C83           00043         retlw   0x83
  885. 0001C4 0C17           00044         retlw   0x17
  886.                       00045 
  887.                       00046         ; idProduct (low byte, high byte)
  888. 0001C6 0CD9           00047         retlw   0xD9
  889. 0001C8 0C07           00048         retlw   0x07
  890.                       00049 
  891. 0001CA 0C00           00050         retlw   0x00            ; bcdDevice (low byte)
  892. 0001CC 0C00           00051         retlw   0x00            ; (high byte)
  893. 0001CE 0C01           00052         retlw   0x01            ; iManufacturer (string index)
  894. 0001D0 0C02           00053         retlw   0x02            ; iProduct      (string index)
  895.                       00054 
  896.                       00055         ; iSerialNumber (string index)
  897. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE 17
  898. LOC  OBJECT CODE     LINE SOURCE TEXT
  899.   VALUE
  900. 0001D2 0C00           00056         retlw   0x00
  901. 0001D4 0C01           00057         retlw   NUM_CONFIGURATIONS ; bNumConfigurations
  902. 0001D6                00058 EndDeviceDescriptor
  903.                       00059 
  904.                       00060 ; ******************************************************************
  905.                       00061 ; This table is retrieved by the host after the address has been set.
  906.                       00062 ; This table defines the configurations available for the device.
  907.                       00063 ; See section 9.6.2 of the Rev 1.0 USB specification (page 184).
  908.                       00064 ; These fields are application DEPENDENT. 
  909.                       00065 ; Modify these to meet your specifications.
  910.                       00066 ; ******************************************************************
  911.                       00067 ; Configuration pointer table
  912. 0001D6                00068 USB_CD_Ptr
  913. 0001D6                00069 Configs
  914. 0001D6 01DA           00070         db      low Config1, high Config1
  915. 0001D8 01DA           00071         db      low Config1, high Config1
  916.                       00072 
  917.                       00073 ; Configuration Descriptor
  918. 0001DA                00074 Config1
  919. 0001DA 0C09           00075         retlw   (Interface1-Config1)/2  ; bLength Length of this descriptor
  920. 0001DC 0C02           00076         retlw   DSC_CFG         ; bDescType 2=CONFIGURATION
  921. 0001DE                00077 Config1Len
  922. 0001DE 0C29           00078         retlw   low ((EndConfig1 - Config1)/2)  ; Length of this configuration
  923. 0001E0 0C00           00079         retlw   high ((EndConfig1 - Config1)/2)
  924. 0001E2 0C01           00080         retlw   0x01            ; bNumInterfaces Number of interfaces
  925. 0001E4 0C01           00081         retlw   0x01            ; bConfigValue Configuration Value
  926. 0001E6 0C00           00082         retlw   0x00            ; iConfig (string index)
  927. 0001E8 0CA0           00083         retlw   0xA0            ; bmAttributes attributes - bus powered
  928.                       00084 
  929.                       00085         ; Max power consumption (2X mA)
  930. 0001EA 0C32           00086         retlw   0x32
  931. 0001EC                00087 Interface1
  932. 0001EC 0C09           00088         retlw   (HIDDescriptor1-Interface1)/2   ; length of descriptor
  933. 0001EE 0C04           00089         retlw   DSC_INTF
  934. 0001F0 0C00           00090         retlw   0x00            ; number of interface, 0 based array
  935. 0001F2 0C00           00091         retlw   0x00            ; alternate setting
  936. 0001F4 0C02           00092         retlw   0x02            ; number of endpoints used in this interface
  937. 0001F6 0C03           00093         retlw   0x03            ; interface class - assigned by the USB
  938. 0001F8 0C00           00094         retlw   0x00            ; boot device
  939. 0001FA 0C00           00095         retlw   0x00            ; interface protocol - mouse
  940. 0001FC 0C00           00096         retlw   0x00            ; index to string descriptor that describes this interface
  941. 0001FE                00097 HIDDescriptor1
  942. 0001FE 0C09           00098         retlw   (Endpoint1In-HIDDescriptor1)/2  ; descriptor size (9 bytes)
  943. 000200 0C21           00099         retlw   0x21            ; descriptor type (HID)
  944. 000202 0C00           00100         retlw   0x00            ; HID class release number (1.00)
  945. 000204 0C01           00101         retlw   0x01
  946. 000206 0C00           00102         retlw   0x00            ; Localized country code (none)
  947. 000208 0C01           00103         retlw   0x01            ; # of HID class descriptor to follow (1)
  948. 00020A 0C22           00104         retlw   0x22            ; Report descriptor type (HID)
  949. 00020C                00105 ReportDescriptor1Len
  950. 00020C 0C28           00106         retlw   low ((EndReportDescriptor1-ReportDescriptor1)/2)
  951. 00020E 0C00           00107         retlw   high ((EndReportDescriptor1-ReportDescriptor1)/2)
  952. 000210                00108 Endpoint1In
  953. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE 18
  954. LOC  OBJECT CODE     LINE SOURCE TEXT
  955.   VALUE
  956. 000210 0C07           00109         retlw   (EndPoint1Out-Endpoint1In)/2    ; length of descriptor
  957. 000212 0C05           00110         retlw   DSC_EP
  958. 000214 0C81           00111         retlw   0x81            ; EP1, In
  959. 000216 0C03           00112         retlw   0x03            ; Interrupt
  960. 000218 0C40           00113         retlw   0x40            ; This should be the size of the endpoint buffer
  961. 00021A 0C00           00114         retlw   0x00
  962. 00021C 0C0A           00115         retlw   0x0A                        ; Polling interval
  963. 00021E                00116 EndPoint1Out
  964. 00021E 0C07           00117         retlw   (EndConfig1-EndPoint1Out)/2     ; Length of this Endpoint Descriptor
  965. 000220 0C05           00118         retlw   DSC_EP          ; bDescriptorType = 5 for Endpoint Descriptor
  966. 000222 0C01           00119         retlw   0x01            ; Endpoint number & direction
  967. 000224 0C03           00120         retlw   0x03            ; Transfer type supported by this Endpoint
  968. 000226 0C40           00121         retlw   0x40            ; This should be the size of the endpoint buffer
  969. 000228 0C00           00122         retlw   0x00
  970. 00022A 0C0A           00123         retlw   0x0A                        ; Polling interval
  971. 00022C                00124 EndConfig1
  972.                       00125 
  973. 00022C                00126 ReportDescriptor1
  974.                       00127     ; vendor defined usage page
  975. 00022C 0C06           00128     retlw       0x06            
  976. 00022E 0C00           00129     retlw       0x00
  977. 000230 0CFF           00130     retlw       0xFF
  978.                       00131 
  979.                       00132     ; vendor defined usage
  980. 000232 0C09           00133     retlw       0x09
  981. 000234 0C00           00134     retlw       0x00
  982.                       00135 
  983.                       00136     ; collection(application)
  984. 000236 0CA1           00137     retlw       0xA1
  985. 000238 0C01           00138     retlw       0x01
  986.                       00139 
  987.                       00140     ; *** INPUT REPORT ***
  988.                       00141 
  989.                       00142     ; vendor defined usage
  990. 00023A 0C09           00143     retlw       0x09
  991. 00023C 0C01           00144     retlw       0x01
  992.                       00145 
  993. 00023E 0C15           00146     retlw       0x15    ; logical minimum (-128)
  994. 000240 0C80           00147     retlw       0x80    ;
  995. 000242 0C25           00148     retlw       0x25    ; logical maximum (127)
  996. 000244 0C7F           00149     retlw       0x7F    ;
  997. 000246 0C35           00150     retlw       0x35    ; Physical Minimum (0)
  998. 000248 0C00           00151     retlw       0x00    ;
  999. 00024A 0C45           00152     retlw       0x45    ; Physical Maximum (255)
  1000. 00024C 0CFF           00153     retlw       0xFF    ;
  1001.                       00154 
  1002.                       00155     ; report size in bits
  1003. 00024E 0C75           00156     retlw       0x75
  1004. 000250 0C08           00157     retlw       0x08
  1005.                       00158 
  1006.                       00159     ; report count (number of fields)
  1007. 000252 0C95           00160     retlw       0x95
  1008. 000254 0C10           00161     retlw       0x10
  1009. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE 19
  1010. LOC  OBJECT CODE     LINE SOURCE TEXT
  1011.   VALUE
  1012.                       00162 
  1013.                       00163     ; Input (Data, Variable, Absolute)
  1014. 000256 0C81           00164     retlw       0x81
  1015. 000258 0C02           00165     retlw       0x02
  1016.                       00166 
  1017.                       00167     ; *** OUTPUT REPORT ***
  1018.                       00168 
  1019.                       00169     ; vendor defined usage
  1020. 00025A 0C09           00170     retlw       0x09        ; usage (Vendor Defined)
  1021. 00025C 0C02           00171     retlw       0x02        ;
  1022.                       00172 
  1023. 00025E 0C15           00173     retlw       0x15        ; logical minimum (-128)
  1024. 000260 0C80           00174     retlw       0x80        ;
  1025. 000262 0C25           00175     retlw       0x25        ; logical maximum (127)
  1026. 000264 0C7F           00176     retlw       0x7F        ;
  1027. 000266 0C35           00177     retlw       0x35        ; Physical Minimum (0)
  1028. 000268 0C00           00178     retlw       0x00        ;
  1029. 00026A 0C45           00179     retlw       0x45        ; Physical Maximum (255)
  1030. 00026C 0CFF           00180     retlw       0xFF        ;
  1031.                       00181 
  1032.                       00182     ; report size in bits
  1033. 00026E 0C75           00183     retlw       0x75
  1034. 000270 0C08           00184     retlw       0x08
  1035.                       00185 
  1036.                       00186     ; report count (number of fields)
  1037. 000272 0C95           00187     retlw       0x95
  1038. 000274 0C10           00188     retlw       0x10
  1039.                       00189 
  1040.                       00190     ; Output (Data, Variable, Absolute)
  1041. 000276 0C91           00191     retlw       0x91
  1042. 000278 0C02           00192     retlw       0x02
  1043.                       00193 
  1044. 00027A 0CC0           00194     retlw   0xC0           ; end collection
  1045.                       00195 
  1046. 00027C                00196 EndReportDescriptor1
  1047.                       00197 
  1048.                       00198 ; String pointer table
  1049. 00027C                00199 USB_SD_Ptr
  1050. 00027C                00200 Strings
  1051. 00027C 0284           00201         db      low String0, high String0
  1052. 00027E 028C           00202         db      low String1, high String1
  1053. 000280 02B8           00203         db      low String2, high String2
  1054. 000282 02E8           00204         db      low String3, high String3
  1055.                       00205 
  1056. 000284                00206 String0
  1057. 000284 0C04           00207         retlw   (String1-String0)/2     ; Length of string
  1058. 000286 0C03           00208         retlw   DSC_STR                 ; Descriptor type 3
  1059. 000288 0C09           00209         retlw   0x09                    ; Language ID (as defined by MS 0x0409)
  1060. 00028A 0C04           00210         retlw   0x04
  1061.                       00211 
  1062.                       00212 ; company name
  1063. 00028C                00213 String1
  1064. 00028C 0C16           00214         retlw   (String2-String1)/2
  1065. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE 20
  1066. LOC  OBJECT CODE     LINE SOURCE TEXT
  1067.   VALUE
  1068. 00028E 0C03           00215         retlw   DSC_STR
  1069.                       00216         
  1070. 000290 0C54           00217         retlw   'T'
  1071. 000292 0C00           00218         retlw   0x00
  1072. 000294 0C72           00219         retlw   'r'
  1073. 000296 0C00           00220         retlw   0x00
  1074. 000298 0C61           00221         retlw   'a'
  1075. 00029A 0C00           00222         retlw   0x00
  1076. 00029C 0C6E           00223         retlw   'n'
  1077. 00029E 0C00           00224         retlw   0x00
  1078. 0002A0 0C73           00225         retlw   's'
  1079. 0002A2 0C00           00226         retlw   0x00
  1080. 0002A4 0C6D           00227         retlw   'm'
  1081. 0002A6 0C00           00228         retlw   0x00
  1082. 0002A8 0C69           00229         retlw   'i'
  1083. 0002AA 0C00           00230         retlw   0x00
  1084. 0002AC 0C73           00231         retlw   's'
  1085. 0002AE 0C00           00232         retlw   0x00
  1086. 0002B0 0C6F           00233         retlw   'o'
  1087. 0002B2 0C00           00234         retlw   0x00
  1088. 0002B4 0C72           00235         retlw   'r'
  1089. 0002B6 0C00           00236         retlw   0x00
  1090.                       00237 
  1091.                       00238         
  1092.                       00239 ; product name  
  1093. 0002B8                00240 String2
  1094. 0002B8 0C18           00241         retlw   (String3-String2)/2
  1095. 0002BA 0C03           00242         retlw   DSC_STR
  1096.                       00243         
  1097. 0002BC 0C46           00244         retlw   'F'
  1098. 0002BE 0C00           00245         retlw   0x00
  1099. 0002C0 0C6D           00246         retlw   'm'
  1100. 0002C2 0C00           00247         retlw   0x00
  1101. 0002C4 0C4D           00248         retlw   'M'
  1102. 0002C6 0C00           00249         retlw   0x00
  1103. 0002C8 0C6F           00250         retlw   'o'
  1104. 0002CA 0C00           00251         retlw   0x00
  1105. 0002CC 0C64           00252         retlw   'd'
  1106. 0002CE 0C00           00253         retlw   0x00
  1107. 0002D0 0C75           00254         retlw   'u'
  1108. 0002D2 0C00           00255         retlw   0x00
  1109. 0002D4 0C6C           00256         retlw   'l'
  1110. 0002D6 0C00           00257         retlw   0x00
  1111. 0002D8 0C61           00258         retlw   'a'
  1112. 0002DA 0C00           00259         retlw   0x00
  1113. 0002DC 0C74           00260         retlw   't'
  1114. 0002DE 0C00           00261         retlw   0x00
  1115. 0002E0 0C6F           00262         retlw   'o'
  1116. 0002E2 0C00           00263         retlw   0x00
  1117. 0002E4 0C72           00264         retlw   'r'
  1118. 0002E6 0C00           00265         retlw   0x00
  1119.                       00266 
  1120.                       00267 ; serial number
  1121. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE 21
  1122. LOC  OBJECT CODE     LINE SOURCE TEXT
  1123.   VALUE
  1124. 0002E8                00268 String3
  1125. 0002E8 0C02           00269         retlw   (String4-String3)/2
  1126. 0002EA 0C03           00270         retlw   DSC_STR
  1127.                       00271         
  1128.                       00272 
  1129. 0002EC                00273 String4
  1130.                       00274  
  1131.                       00275  
  1132.                       00015         include "USB18MEM.ASM"
  1133.                       00001 ; Buffer Descriptor Byte Aliases
  1134.                       00002 #define Stat            0               ; Buffer Descriptor Status Register
  1135.                       00003 #define Cnt             1               ; Buffer Count
  1136.                       00004 ;#define ADR            2               ; Buffer Address
  1137.                       00005 #define ADRL            2               ; Buffer Address Low
  1138.                       00006 #define ADRH            3               ; Buffer Address High
  1139.                       00007 
  1140.                       00008 ; Stat Bit Aliases
  1141.                       00009 #define BC8             0               ; Upper Count Bit
  1142.                       00010 #define BC9             1               ; Upper Count Bit
  1143.                       00011 #define BSTALL          2               ; Buffer Stall Enable
  1144.                       00012 #define DTSEN           3               ; Data Toggle Synch Enable
  1145.                       00013 #define INCDIS          4               ; Address Increment Disable
  1146.                       00014 #define KEN             5               ; BD Keep Enable
  1147.                       00015 #define DTS             6               ; Data Toggle Synch Value
  1148.                       00016 #define UOWN            7               ; USB Ownership
  1149.                       00017 #define PID             2               ; Packet Identifier (4 bits)
  1150.                       00018 ;#define PID0           2
  1151.                       00019 ;#define PID1           3
  1152.                       00020 ;#define PID2           4
  1153.                       00021 ;#define PID3           5
  1154.                       00022 
  1155.                       00023 
  1156.   000002EC            00024 SavedOrg equ    $                       ; Save current org
  1157. 000400                00025         org     0x400                   ; Bank 4
  1158.                       00026 
  1159.                       00027 ; Buffer Descriptor Table (BDT) RAM
  1160.                       00028 
  1161.                       00029 #if(0 <= MAX_EP_NUMBER)                 ; (See usbmmap.c & usbmmap.h)
  1162. 000400                00030 ep0Bo           res     4               ; Endpoint #0 BD Out
  1163. 000404                00031 ep0Bi           res     4               ; Endpoint #0 BD In
  1164.                       00032 #endif
  1165.                       00033 
  1166.                       00034 #if(1 <= MAX_EP_NUMBER)
  1167. 000408                00035 ep1Bo           res     4               ; Endpoint #1 BD Out
  1168. 00040C                00036 ep1Bi           res     4               ; Endpoint #1 BD In
  1169.                       00037 #endif
  1170.                       00038 
  1171.                       00039 #if(2 <= MAX_EP_NUMBER)
  1172.                       00040 ep2Bo           res     4               ; Endpoint #2 BD Out
  1173.                       00041 ep2Bi           res     4               ; Endpoint #2 BD In
  1174.                       00042 #endif
  1175.                       00043 
  1176.                       00044 #if(3 <= MAX_EP_NUMBER)
  1177. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE 22
  1178. LOC  OBJECT CODE     LINE SOURCE TEXT
  1179.   VALUE
  1180.                       00045 ep3Bo           res     4               ; Endpoint #3 BD Out
  1181.                       00046 ep3Bi           res     4               ; Endpoint #3 BD In
  1182.                       00047 #endif
  1183.                       00048 
  1184.                       00049 #if(4 <= MAX_EP_NUMBER)
  1185.                       00050 ep4Bo           res     4               ; Endpoint #4 BD Out
  1186.                       00051 ep4Bi           res     4               ; Endpoint #4 BD In
  1187.                       00052 #endif
  1188.                       00053 
  1189.                       00054 #if(5 <= MAX_EP_NUMBER)
  1190.                       00055 ep5Bo           res     4               ; Endpoint #5 BD Out
  1191.                       00056 ep5Bi           res     4               ; Endpoint #5 BD In
  1192.                       00057 #endif
  1193.                       00058 
  1194.                       00059 #if(6 <= MAX_EP_NUMBER)
  1195.                       00060 ep6Bo           res     4               ; Endpoint #6 BD Out
  1196.                       00061 ep6Bi           res     4               ; Endpoint #6 BD In
  1197.                       00062 #endif
  1198.                       00063 
  1199.                       00064 #if(7 <= MAX_EP_NUMBER)
  1200.                       00065 ep7Bo           res     4               ; Endpoint #7 BD Out
  1201.                       00066 ep7Bi           res     4               ; Endpoint #7 BD In
  1202.                       00067 #endif
  1203.                       00068 
  1204.                       00069 #if(8 <= MAX_EP_NUMBER)
  1205.                       00070 ep8Bo           res     4               ; Endpoint #8 BD Out
  1206.                       00071 ep8Bi           res     4               ; Endpoint #8 BD In
  1207.                       00072 #endif
  1208.                       00073 
  1209.                       00074 #if(9 <= MAX_EP_NUMBER)
  1210.                       00075 ep9Bo           res     4               ; Endpoint #9 BD Out
  1211.                       00076 ep9Bi           res     4               ; Endpoint #9 BD In
  1212.                       00077 #endif
  1213.                       00078 
  1214.                       00079 #if(10 <= MAX_EP_NUMBER)
  1215.                       00080 ep10Bo          res     4               ; Endpoint #10 BD Out
  1216.                       00081 ep10Bi          res     4               ; Endpoint #10 BD In
  1217.                       00082 #endif
  1218.                       00083 
  1219.                       00084 #if(11 <= MAX_EP_NUMBER)
  1220.                       00085 ep11Bo          res     4               ; Endpoint #11 BD Out
  1221.                       00086 ep11Bi          res     4               ; Endpoint #11 BD In
  1222.                       00087 #endif
  1223.                       00088 
  1224.                       00089 #if(12 <= MAX_EP_NUMBER)
  1225.                       00090 ep12Bo          res     4               ; Endpoint #12 BD Out
  1226.                       00091 ep12Bi          res     4               ; Endpoint #12 BD In
  1227.                       00092 #endif
  1228.                       00093 
  1229.                       00094 #if(13 <= MAX_EP_NUMBER)
  1230.                       00095 ep13Bo          res     4               ; Endpoint #13 BD Out
  1231.                       00096 ep13Bi          res     4               ; Endpoint #13 BD In
  1232.                       00097 #endif
  1233. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE 23
  1234. LOC  OBJECT CODE     LINE SOURCE TEXT
  1235.   VALUE
  1236.                       00098 
  1237.                       00099 #if(14 <= MAX_EP_NUMBER)
  1238.                       00100 ep14Bo          res     4               ; Endpoint #14 BD Out
  1239.                       00101 ep14Bi          res     4               ; Endpoint #14 BD In
  1240.                       00102 #endif
  1241.                       00103 
  1242.                       00104 #if(15 <= MAX_EP_NUMBER)
  1243.                       00105 ep15Bo          res     4               ; Endpoint #15 BD Out
  1244.                       00106 ep15Bi          res     4               ; Endpoint #15 BD In
  1245.                       00107 #endif
  1246.                       00108 
  1247.                       00109 
  1248.                       00110 ; General RAM (in bank 4)
  1249. 000410                00111 usb_temp        res     2               ; Temporary storage
  1250. 000412                00112 pSrc            res     2               ; Source pointer
  1251. 000414                00113 pDst            res     2               ; Destination pointer
  1252.                       00114 
  1253.                       00115 ; (See usbctrltrf.c)
  1254. 000416                00116 ctrl_trf_state  res     1               ; Control Transfer State
  1255. 000417                00117 ctrl_trf_session_owner res 1            ; Current transfer session owner
  1256. 000418                00118 wCount          res     2               ; Data counter
  1257.                       00119 
  1258.                       00120 ; (See usbmmap.c)
  1259. 00041A                00121 usb_device_state res    1               ; Device States: DETACHED, ATTACHED, ...
  1260. 00041B                00122 usb_active_cfg  res     1               ; Value of current configuration
  1261. 00041C                00123 usb_alt_intf    res     MAX_NUM_INT     ; Array to keep track of the current alternate setting for each 
  1262.                             interface ID
  1263. 00041D                00124 usb_stat        res     1
  1264.                       00125 
  1265.                       00126 ; usb_stat bit aliases
  1266.                       00127 #define RemoteWakeup    0               ; [0]Disabled [1]Enabled
  1267.                       00128 #define ctrl_trf_mem    1               ; [0]RAM      [1]ROM
  1268.                       00129 #define cdc_mem_type    2               ; [0]RAM      [1]ROM
  1269.                       00130 
  1270.                       00131 ; Endpoint 0 buffers
  1271. 00041E                00132 SetupPkt        res     EP0_BUFF_SIZE   ; (See usbmmap.c & usbdefs_ep0_buff.h - CTRL_TRF_SETUP)
  1272. 00045E                00133 CtrlTrfData     res     EP0_BUFF_SIZE   ; (See usbmmap.c & usbdefs_ep0_buff.h - CTRL_TRF_DATA)
  1273.                       00134 
  1274.                       00135 ; SetupPkt Byte and Bit Aliases
  1275.                       00136 #define bmRequestType   0
  1276.                       00137 #define bRequest        1
  1277.                       00138 #define wValue          2
  1278.                       00139 #define wIndex          4
  1279.                       00140 #define wLength         6
  1280.                       00141 
  1281.                       00142 #define Recipient       0               ; Device,Interface,Endpoint,Other (5 bits)
  1282.                       00143 #define RequestType     5               ; Standard,Class,Vendor,Reserved (2 bits)
  1283.                       00144 #define DataDir         7               ; Host-to-device,Device-to-host
  1284.                       00145 #define bFeature        2               ; DEVICE_REMOTE_WAKEUP,ENDPOINT_HALT
  1285.                       00146 
  1286.                       00147 #define bReportID       2               ; In a SET_REPORT or GET_REPORT request
  1287.                       00148 #define bReportType     3               ; In a SET_REPORT or GET_REPORT request
  1288.                       00149 
  1289. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE 24
  1290. LOC  OBJECT CODE     LINE SOURCE TEXT
  1291.   VALUE
  1292.                       00150 #define bDscIndex       2               ; For Configuration and String DSC Only
  1293.                       00151 #define bDscType        3               ; Device,Configuration,String
  1294.                       00152 #define wLangID         4               ; Language ID
  1295.                       00153 
  1296.                       00154 #define bDevADR         2               ; Device Address 0-127
  1297.                       00155 #define bDevADRH        3               ; Must equal zero
  1298.                       00156 
  1299.                       00157 #define bCfgValue       2               ; Configuration Value 0-255
  1300.                       00158 #define bCfgRSD         3               ; Must equal zero (Reserved)
  1301.                       00159 
  1302.                       00160 #define bAltID          2               ; Alternate Setting Value 0-255
  1303.                       00161 #define bAltID_H        3               ; Must equal zero (Reserved)
  1304.                       00162 #define bIntfID         4               ; Interface Number Value 0-255
  1305.                       00163 #define bIntfID_H       5               ; Must equal zero
  1306.                       00164 
  1307.                       00165 #define bEPID           4               ; Endpoint ID (Number & Direction)
  1308.                       00166 #define bEPID_H         5               ; Must equal zero
  1309.                       00167 
  1310.                       00168 #define EPNum           0               ; Endpoint Number 0-15 (4 bits)
  1311.                       00169 #define EPDir           7               ; Endpoint Direction: 0-OUT, 1-IN
  1312.                       00170 
  1313.                       00171 
  1314.                       00172 ; HID RAM (in bank 4)
  1315.                       00173 
  1316.                       00174 #ifdef USB_USE_HID
  1317. 00049E                00175 idle_rate       res     1
  1318. 00049F                00176 active_protocol res     1               ; [0] Boot Protocol [1] Report Protocol
  1319.                       00177 #endif
  1320.                       00178 
  1321.                       00179 
  1322.                       00180 ; CDC RAM (in bank 4)
  1323.                       00181 
  1324.                       00182 #ifdef USB_USE_CDC                      ; (See usbmmap.c & usbmmap.h)
  1325.                       00183 line_coding     res     LINE_CODING_LENGTH
  1326.                       00184 control_signal_bitmap res 1
  1327.                       00185 dummy_encapsulated_cmd_response res dummy_length
  1328.                       00186 
  1329.                       00187 ; line_coding Byte and Bit Aliases
  1330.                       00188 #define dwDTERate       0               ; Complex data structure
  1331.                       00189 #define bCharFormat     4
  1332.                       00190 #define bParityType     5
  1333.                       00191 #define bDataBits       6
  1334.                       00192 
  1335.                       00193 ; control_signal_bitmap Byte and Bit Aliases
  1336.                       00194 #define DTE_PRESENT     0               ; [0] Not Present  [1] Present
  1337.                       00195 #define CARRIER_CONTROL 1               ; [0] Deactivate   [1] Activate
  1338.                       00196 #endif
  1339.                       00197 
  1340.                       00198 
  1341.                       00199 ; All previous RAM must be in bank 4
  1342.                       00200 ; The following buffers may be in any dual-port RAM bank
  1343.                       00201 
  1344.                       00202 ; HID Buffer RAM
  1345. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE 25
  1346. LOC  OBJECT CODE     LINE SOURCE TEXT
  1347.   VALUE
  1348.                       00203 
  1349.                       00204 #ifdef USB_USE_HID
  1350. 0004A0                00205 hid_report_out  res     HID_INT_OUT_EP_SIZE + 1 ; (See usbmmap.c & usbmmap.h)
  1351. 0004E1                00206 hid_report_in   res     HID_INT_IN_EP_SIZE + 1  ; +1 for size at front
  1352.                       00207 #endif
  1353.                       00208 
  1354.                       00209 
  1355.                       00210 ; CDC Buffer RAM
  1356.                       00211         
  1357.                       00212 #ifdef USB_USE_CDC                      ; (See usbmmap.c & usbmmap.h)
  1358.                       00213 cdc_notice      res     CDC_INT_EP_SIZE + 1     ; +1 for size at front
  1359.                       00214 cdc_data_rx     res     CDC_BULK_OUT_EP_SIZE + 1        ; +1 for size at front
  1360.                       00215 cdc_data_tx     res     CDC_BULK_IN_EP_SIZE + 1 ; +1 for size at front
  1361.                       00216 #endif
  1362.                       00217 
  1363.                       00218 
  1364. 0002EC                00219         org     SavedOrg                ; Restore previous org
  1365.                       00016         include "USB18.ASM"
  1366.                       00001 ; USB18.ASM
  1367.                       00002 
  1368.                       00003 ; Put Address into source pointer
  1369.                       00004 mSetSourcePointer macro Address
  1370.                       00005         movlw   low (Address)
  1371.                       00006         movwf   pSrc
  1372.                       00007         movlw   high (Address)
  1373.                       00008         movwf   pSrc + 1
  1374.                       00009         endm
  1375.                       00010 
  1376.                       00011 ; Put Address into destination pointer
  1377.                       00012 mSetDestinationPointer macro Address
  1378.                       00013         movlw   low (Address)
  1379.                       00014         movwf   pDst
  1380.                       00015         movlw   high (Address)
  1381.                       00016         movwf   pDst + 1
  1382.                       00017         endm
  1383.                       00018 
  1384.                       00019 ; Get count from first location of ROM table pointed to by pSrc
  1385.                       00020 mGetRomTableCount macro
  1386.                       00021         movff   pSrc, TBLPTRL           ; Set source address
  1387.                       00022         movff   pSrc + 1, TBLPTRH
  1388.                       00023         clrf    TBLPTRU
  1389.                       00024         tblrd   *                       ; Read count
  1390.                       00025         movff   TABLAT, wCount
  1391.                       00026         clrf    wCount + 1
  1392.                       00027         endm
  1393.                       00028 
  1394.                       00029 
  1395.                       00030 ; From usb9.c  line 70
  1396.                       00031 ;/******************************************************************************
  1397.                       00032 ; * Function:        void USBCheckStdRequest(void)
  1398.                       00033 ; *
  1399.                       00034 ; * PreCondition:    None
  1400.                       00035 ; *
  1401. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE 26
  1402. LOC  OBJECT CODE     LINE SOURCE TEXT
  1403.   VALUE
  1404.                       00036 ; * Input:           None
  1405.                       00037 ; *
  1406.                       00038 ; * Output:          None
  1407.                       00039 ; *
  1408.                       00040 ; * Side Effects:    None
  1409.                       00041 ; *
  1410.                       00042 ; * Overview:        This routine checks the setup data packet to see if it
  1411.                       00043 ; *                  knows how to handle it
  1412.                       00044 ; *
  1413.                       00045 ; * Note:            None
  1414.                       00046 ; *****************************************************************************/
  1415. 0002EC                00047 USBCheckStdRequest
  1416. 0002EC 0104           00048         movlb   high 0x400              ; Point to proper bank
  1417. 0002EE 511E           00049         movf    SetupPkt, W             ; RequestType = STANDARD?
  1418. 0002F0 0B60           00050         andlw   0x60                    ; Mask to proper bits
  1419. 0002F2 0800           00051         sublw   (STANDARD) << 5
  1420. 0002F4 E13E           00052         bnz     USBCheckStdRequestExit  ; No
  1421. 0002F6 0E05           00053         movlw   SET_ADR                 ; Handle request
  1422. 0002F8 631F           00054         cpfseq  SetupPkt + bRequest
  1423. 0002FA D003           00055         bra     USBCheckStdRequest1
  1424. 0002FC 0E04           00056         movlw   ADR_PENDING_STATE
  1425. 0002FE 6F1A           00057         movwf   usb_device_state
  1426. 000300 D036           00058         bra     USBStdSetSessionOwnerUSB9
  1427.                       00059 
  1428.                       00060 ; GET_DESCRIPTOR request?
  1429. 000302                00061 USBCheckStdRequest1
  1430. 000302 0E06           00062         movlw   GET_DSC
  1431. 000304 631F           00063         cpfseq  SetupPkt + bRequest
  1432. 000306 D001           00064         bra     USBCheckStdRequest2
  1433. 000308 D035           00065         bra     USBStdGetDscHandler
  1434.                       00066 
  1435.                       00067 ; GET_CONFIGURATION request?
  1436. 00030A                00068 USBCheckStdRequest2
  1437. 00030A 0E08           00069         movlw   GET_CFG
  1438. 00030C 631F           00070         cpfseq  SetupPkt + bRequest
  1439. 00030E D009           00071         bra     USBCheckStdRequest3
  1440.                       00072         mSetSourcePointer usb_active_cfg
  1441. 000310 0E1B               M         movlw   low (usb_active_cfg)
  1442. 000312 6F12               M         movwf   pSrc
  1443. 000314 0E04               M         movlw   high (usb_active_cfg)
  1444. 000316 6F13               M         movwf   pSrc + 1
  1445. 000318 0E01           00073         movlw   1
  1446. 00031A 6F18           00074         movwf   wCount
  1447. 00031C 6B19           00075         clrf    wCount + 1
  1448. 00031E 931D           00076         bcf     usb_stat, ctrl_trf_mem  ; Indicate RAM
  1449. 000320 D026           00077         bra     USBStdSetSessionOwnerUSB9
  1450.                       00078 
  1451.                       00079 ; SET_CONFIGURATION request?
  1452. 000322                00080 USBCheckStdRequest3
  1453. 000322 0E09           00081         movlw   SET_CFG
  1454. 000324 631F           00082         cpfseq  SetupPkt + bRequest
  1455. 000326 D001           00083         bra     USBCheckStdRequest4
  1456. 000328 D06A           00084         bra     USBStdSetCfgHandler
  1457. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE 27
  1458. LOC  OBJECT CODE     LINE SOURCE TEXT
  1459.   VALUE
  1460.                       00085 
  1461.                       00086 ; GET_STATUS request?
  1462. 00032A                00087 USBCheckStdRequest4
  1463. 00032A 0E00           00088         movlw   GET_STATUS
  1464. 00032C 631F           00089         cpfseq  SetupPkt + bRequest
  1465. 00032E D001           00090         bra     USBCheckStdRequest5
  1466. 000330 D07E           00091         bra     USBStdGetStatusHandler
  1467.                       00092 
  1468.                       00093 ; CLEAR_FEATURE request?
  1469. 000332                00094 USBCheckStdRequest5
  1470. 000332 0E01           00095         movlw   CLR_FEATURE
  1471. 000334 631F           00096         cpfseq  SetupPkt + bRequest
  1472. 000336 D001           00097         bra     USBCheckStdRequest6
  1473. 000338 D09F           00098         bra     USBStdFeatureReqHandler
  1474.                       00099 
  1475.                       00100 ; SET_FEATURE request?
  1476. 00033A                00101 USBCheckStdRequest6
  1477. 00033A 0E03           00102         movlw   SET_FEATURE
  1478. 00033C 631F           00103         cpfseq  SetupPkt + bRequest
  1479. 00033E D001           00104         bra     USBCheckStdRequest7
  1480. 000340 D09B           00105         bra     USBStdFeatureReqHandler
  1481.                       00106 
  1482.                       00107 ; GET_INTERFACE request?
  1483. 000342                00108 USBCheckStdRequest7
  1484. 000342 0E0A           00109         movlw   GET_INTF
  1485. 000344 631F           00110         cpfseq  SetupPkt + bRequest
  1486. 000346 D00B           00111         bra     USBCheckStdRequest8
  1487.                       00112         mSetSourcePointer usb_alt_intf
  1488. 000348 0E1C               M         movlw   low (usb_alt_intf)
  1489. 00034A 6F12               M         movwf   pSrc
  1490. 00034C 0E04               M         movlw   high (usb_alt_intf)
  1491. 00034E 6F13               M         movwf   pSrc + 1
  1492. 000350 5122           00113         movf    SetupPkt + bIntfID, W
  1493. 000352 2712           00114         addwf   pSrc, F
  1494. 000354 0E01           00115         movlw   1
  1495. 000356 6F18           00116         movwf   wCount
  1496. 000358 6B19           00117         clrf    wCount + 1
  1497. 00035A 931D           00118         bcf     usb_stat, ctrl_trf_mem  ; Indicate RAM
  1498. 00035C D008           00119         bra     USBStdSetSessionOwnerUSB9
  1499.                       00120 
  1500.                       00121 ; SET_INTERFACE request?
  1501. 00035E                00122 USBCheckStdRequest8
  1502. 00035E 0E0B           00123         movlw   SET_INTF
  1503. 000360 631F           00124         cpfseq  SetupPkt + bRequest
  1504. 000362 0012           00125         return
  1505. 000364 EE24 F01C      00126         lfsr    2, usb_alt_intf
  1506. 000368 5122           00127         movf    SetupPkt + bIntfID, W
  1507. 00036A C420 FFDB      00128         movff   SetupPkt + bAltID, PLUSW2
  1508.                       00129 ; Branch here after decoding one of the above USB standard requests.
  1509.                       00130 ; Assign a value to ctrl_trf_session_owner, to prevent stalling
  1510. 00036E                00131 USBStdSetSessionOwnerUSB9
  1511. 00036E 0E01           00132         movlw   MUID_USB9
  1512. 000370 6F17           00133         movwf   ctrl_trf_session_owner
  1513. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE 28
  1514. LOC  OBJECT CODE     LINE SOURCE TEXT
  1515.   VALUE
  1516. 000372                00134 USBCheckStdRequestExit
  1517. 000372 0012           00135         return
  1518.                       00136 
  1519.                       00137 ; From usb9.c  line 136
  1520.                       00138 ;/******************************************************************************
  1521.                       00139 ; * Function:        void USBStdGetDscHandler(void)
  1522.                       00140 ; *
  1523.                       00141 ; * PreCondition:    None
  1524.                       00142 ; *
  1525.                       00143 ; * Input:           None
  1526.                       00144 ; *
  1527.                       00145 ; * Output:          None
  1528.                       00146 ; *
  1529.                       00147 ; * Side Effects:    None
  1530.                       00148 ; *
  1531.                       00149 ; * Overview:        This routine handles the standard GET_DESCRIPTOR request.
  1532.                       00150 ; *                  It utilizes tables dynamically looks up descriptor size.
  1533.                       00151 ; *                  This routine should never have to be modified if the tables
  1534.                       00152 ; *                  in usbdsc.c are declared correctly.
  1535.                       00153 ; *
  1536.                       00154 ; * Note:            None
  1537.                       00155 ; *****************************************************************************/
  1538. 000374                00156 USBStdGetDscHandler
  1539.                       00157 ;       movlb   high 0x400              ; Point to proper bank
  1540. 000374 0E80           00158         movlw   0x80
  1541. 000376 631E           00159         cpfseq  SetupPkt + bmRequestType
  1542. 000378 0012           00160         return
  1543. 00037A 0E01           00161         movlw   DSC_DEV
  1544. 00037C 6321           00162         cpfseq  SetupPkt + bDscType
  1545. 00037E D00F           00163         bra     USBStdGetDscHandler1
  1546.                       00164         mSetSourcePointer DeviceDescriptor
  1547. 000380 0EB2               M         movlw   low (DeviceDescriptor)
  1548. 000382 6F12               M         movwf   pSrc
  1549. 000384 0E01               M         movlw   high (DeviceDescriptor)
  1550. 000386 6F13               M         movwf   pSrc + 1
  1551.                       00165         mGetRomTableCount               ; Set wCount
  1552. 000388 C412 FFF6          M         movff   pSrc, TBLPTRL           ; Set source address
  1553. 00038C C413 FFF7          M         movff   pSrc + 1, TBLPTRH
  1554. 000390 6AF8               M         clrf    TBLPTRU
  1555. 000392 0008               M         tblrd   *                       ; Read count
  1556. 000394 CFF5 F418          M         movff   TABLAT, wCount
  1557. 000398 6B19               M         clrf    wCount + 1
  1558. 00039A 831D           00166         bsf     usb_stat, ctrl_trf_mem  ; Indicate ROM
  1559. 00039C D7E8           00167         bra     USBStdSetSessionOwnerUSB9
  1560. 00039E                00168 USBStdGetDscHandler1
  1561. 00039E 0E02           00169         movlw   DSC_CFG
  1562. 0003A0 6321           00170         cpfseq  SetupPkt + bDscType
  1563. 0003A2 D012           00171         bra     USBStdGetDscHandler2
  1564.                       00172         mSetSourcePointer Config1
  1565. 0003A4 0EDA               M         movlw   low (Config1)
  1566. 0003A6 6F12               M         movwf   pSrc
  1567. 0003A8 0E01               M         movlw   high (Config1)
  1568. 0003AA 6F13               M         movwf   pSrc + 1
  1569. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE 29
  1570. LOC  OBJECT CODE     LINE SOURCE TEXT
  1571.   VALUE
  1572. 0003AC 0EDE           00173         movlw   low Config1Len          ; Set wCount to total length
  1573. 0003AE 6EF6           00174         movwf   TBLPTRL
  1574. 0003B0 0E01           00175         movlw   high Config1Len
  1575. 0003B2 6EF7           00176         movwf   TBLPTRH
  1576. 0003B4 6AF8           00177         clrf    TBLPTRU
  1577. 0003B6 0009           00178         tblrd   *+                      ; Read count low
  1578. 0003B8 CFF5 F418      00179         movff   TABLAT, wCount
  1579. 0003BC 0009           00180         tblrd   *+                      ; Ignore RETLW opcode
  1580. 0003BE 0009           00181         tblrd   *+                      ; Read count high
  1581. 0003C0 CFF5 F419      00182         movff   TABLAT, wCount + 1
  1582. 0003C4 831D           00183         bsf     usb_stat, ctrl_trf_mem  ; Indicate ROM
  1583. 0003C6 D7D3           00184         bra     USBStdSetSessionOwnerUSB9
  1584. 0003C8                00185 USBStdGetDscHandler2
  1585. 0003C8 0E03           00186         movlw   DSC_STR
  1586. 0003CA 6321           00187         cpfseq  SetupPkt + bDscType
  1587. 0003CC 0012           00188         return
  1588. 0003CE 6AF8           00189         clrf    TBLPTRU
  1589. 0003D0 6AF7           00190         clrf    TBLPTRH
  1590. 0003D2 4520           00191         rlncf   SetupPkt + bDscIndex, W ; Index * 2
  1591. 0003D4 0F7C           00192         addlw   low (USB_SD_Ptr)        ; Add element offset to low address
  1592. 0003D6 6EF6           00193         movwf   TBLPTRL
  1593. 0003D8 0E02           00194         movlw   high (USB_SD_Ptr)
  1594. 0003DA 22F7           00195         addwfc  TBLPTRH, F
  1595. 0003DC 0009           00196         tblrd   *+                      ; Get the data to TABLAT and move pointer forward
  1596. 0003DE CFF5 F412      00197         movff   TABLAT, pSrc            ; Get low source address
  1597. 0003E2 0008           00198         tblrd   *
  1598. 0003E4 CFF5 F413      00199         movff   TABLAT, pSrc + 1        ; Get high source address
  1599.                       00200         mGetRomTableCount               ; Set wCount
  1600. 0003E8 C412 FFF6          M         movff   pSrc, TBLPTRL           ; Set source address
  1601. 0003EC C413 FFF7          M         movff   pSrc + 1, TBLPTRH
  1602. 0003F0 6AF8               M         clrf    TBLPTRU
  1603. 0003F2 0008               M         tblrd   *                       ; Read count
  1604. 0003F4 CFF5 F418          M         movff   TABLAT, wCount
  1605. 0003F8 6B19               M         clrf    wCount + 1
  1606. 0003FA 831D           00201         bsf     usb_stat, ctrl_trf_mem  ; Indicate ROM
  1607. 0003FC D7B8           00202         bra     USBStdSetSessionOwnerUSB9
  1608.                       00203 
  1609.                       00204 
  1610.                       00205 ; From usb9.c  line 180
  1611.                       00206 ;/******************************************************************************
  1612.                       00207 ; * Function:        void USBStdSetCfgHandler(void)
  1613.                       00208 ; *
  1614.                       00209 ; * PreCondition:    None
  1615.                       00210 ; *
  1616.                       00211 ; * Input:           None
  1617.                       00212 ; *
  1618.                       00213 ; * Output:          None
  1619.                       00214 ; *
  1620.                       00215 ; * Side Effects:    None
  1621.                       00216 ; *
  1622.                       00217 ; * Overview:        This routine first disables all endpoints by clearing
  1623.                       00218 ; *                  UEP registers. It then configures (initializes) endpoints
  1624.                       00219 ; *                  specified in the modifiable section.
  1625. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE 30
  1626. LOC  OBJECT CODE     LINE SOURCE TEXT
  1627.   VALUE
  1628.                       00220 ; *
  1629.                       00221 ; * Note:            None
  1630.                       00222 ; *****************************************************************************/
  1631. 0003FE                00223 USBStdSetCfgHandler
  1632.                       00224 ;       movlb   high 0x400              ; Point to proper bank
  1633. 0003FE 0E01           00225         movlw   MUID_USB9
  1634. 000400 6F17           00226         movwf   ctrl_trf_session_owner
  1635. 000402 EE2F F071      00227         lfsr    2, UEP1                 ; Reset all non-EP0 UEPn registers
  1636. 000406 0E0F           00228         movlw   15
  1637. 000408                00229 USBStdSetCfgHandlerClearEPLoop
  1638. 000408 6ADE           00230         clrf    POSTINC2
  1639. 00040A 2EE8           00231         decfsz  WREG, F
  1640. 00040C D7FD           00232         bra     USBStdSetCfgHandlerClearEPLoop
  1641. 00040E EE24 F01C      00233         lfsr    2, usb_alt_intf         ; Clear usb_alt_intf array
  1642. 000412 0E01           00234         movlw   MAX_NUM_INT
  1643. 000414                00235 USBStdSetCfgHandlerClearAltLoop
  1644. 000414 6ADE           00236         clrf    POSTINC2
  1645. 000416 2EE8           00237         decfsz  WREG, F
  1646. 000418 D7FD           00238         bra     USBStdSetCfgHandlerClearAltLoop
  1647. 00041A 5120           00239         movf    SetupPkt + bCfgValue, W
  1648. 00041C 6F1B           00240         movwf   usb_active_cfg
  1649. 00041E E103           00241         bnz     USBStdSetCfgHandler1
  1650. 000420 0E05           00242         movlw   ADDRESS_STATE           ; SetupPkt + bCfgValue = 0
  1651. 000422 6F1A           00243         movwf   usb_device_state
  1652. 000424 0012           00244         return
  1653. 000426                00245 USBStdSetCfgHandler1
  1654. 000426 0E06           00246         movlw   CONFIGURED_STATE
  1655. 000428 6F1A           00247         movwf   usb_device_state
  1656.                       00248 #ifdef USB_USE_HID
  1657. 00042A DA08           00249         rcall   HIDInitEP
  1658.                       00250 #endif
  1659.                       00251 #ifdef USB_USE_CDC
  1660.                       00252         rcall   CDCInitEP
  1661.                       00253 #endif
  1662. 00042C 0012           00254         return
  1663.                       00255 
  1664.                       00256 
  1665.                       00257 ; From usb9.c  line 224
  1666.                       00258 ;/******************************************************************************
  1667.                       00259 ; * Function:        void USBStdGetStatusHandler(void)
  1668.                       00260 ; *
  1669.                       00261 ; * PreCondition:    None
  1670.                       00262 ; *
  1671.                       00263 ; * Input:           None
  1672.                       00264 ; *
  1673.                       00265 ; * Output:          None
  1674.                       00266 ; *
  1675.                       00267 ; * Side Effects:    None
  1676.                       00268 ; *
  1677.                       00269 ; * Overview:        This routine handles the standard GET_STATUS request
  1678.                       00270 ; *
  1679.                       00271 ; * Note:            None
  1680.                       00272 ; *****************************************************************************/
  1681. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE 31
  1682. LOC  OBJECT CODE     LINE SOURCE TEXT
  1683.   VALUE
  1684. 00042E                00273 USBStdGetStatusHandler
  1685.                       00274 ;       movlb   high 0x400              ; Point to proper bank
  1686. 00042E 6B5E           00275         clrf    CtrlTrfData             ; Initialize content
  1687. 000430 6B5F           00276         clrf    CtrlTrfData + 1
  1688. 000432 511E           00277         movf    SetupPkt, W             ; Recipient = RCPT_DEV?
  1689. 000434 0B1F           00278         andlw   0x1f                    ; Mask to lower 5 bits
  1690. 000436 0800           00279         sublw   RCPT_DEV
  1691. 000438 E103           00280         bnz     USBStdGetStatusHandler1 ; No
  1692.                       00281 ;
  1693.                       00282 ; Recipient of this Setup packet was "Device": set bits to indicate power & remote wakeup
  1694.                       00283 ; Decoding of "Self-powered" & "Remote Wakeup"
  1695.                       00284 ; _byte0: bit0: Self-Powered Status [0] Bus-Powered [1] Self-Powered
  1696.                       00285 ;         bit1: RemoteWakeup        [0] Disabled    [1] Enabled
  1697.                       00286 ;
  1698.                       00287 #ifdef USB_SELF_POWER
  1699.                       00288         bsf     CtrlTrfData, 0
  1700.                       00289 #endif
  1701. 00043A B11D           00290         btfsc   usb_stat, RemoteWakeup
  1702. 00043C 835E           00291         bsf     CtrlTrfData, 1
  1703. 00043E D00E           00292         bra     USBStdGetStatusSetSessionOwner
  1704.                       00293 ;
  1705. 000440                00294 USBStdGetStatusHandler1
  1706. 000440 511E           00295         movf    SetupPkt, W             ; Recipient = RCPT_INTF?
  1707. 000442 0B1F           00296         andlw   0x1f                    ; Mask to lower 5 bits
  1708. 000444 0801           00297         sublw   RCPT_INTF
  1709. 000446 E101           00298         bnz     USBStdGetStatusHandler2 ; No
  1710.                       00299 ;
  1711.                       00300 ; Recipient of this Setup packet was "Interface": No data to update
  1712. 000448 D009           00301         bra     USBStdGetStatusSetSessionOwner
  1713.                       00302 ;
  1714. 00044A                00303 USBStdGetStatusHandler2
  1715. 00044A 511E           00304         movf    SetupPkt, W             ; Recipient = RCPT_EP?
  1716. 00044C 0B1F           00305         andlw   0x1f                    ; Mask to lower 5 bits
  1717. 00044E 0802           00306         sublw   RCPT_EP
  1718. 000450 E107           00307         bnz     USBStdGetStatusHandler3 ; No
  1719.                       00308 ;
  1720.                       00309 ; Recipient of this Setup packet was "Endpoint"
  1721. 000452 D834           00310         rcall   USBCalcEPAddress        ; Put endpoint buffer address in FSR2
  1722. 000454 50DF           00311         movf    INDF2, W
  1723. 000456 0B04           00312         andlw   _BSTALL
  1724. 000458 E001           00313         bz      USBStdGetStatusSetSessionOwner
  1725. 00045A 815E           00314         bsf     CtrlTrfData, 0
  1726. 00045C                00315 USBStdGetStatusSetSessionOwner
  1727. 00045C 0E01           00316         movlw   MUID_USB9
  1728. 00045E 6F17           00317         movwf   ctrl_trf_session_owner
  1729. 000460                00318 USBStdGetStatusHandler3
  1730. 000460 0E01           00319         movlw   MUID_USB9
  1731. 000462 6317           00320         cpfseq  ctrl_trf_session_owner
  1732. 000464 0012           00321         return
  1733.                       00322         mSetSourcePointer CtrlTrfData
  1734. 000466 0E5E               M         movlw   low (CtrlTrfData)
  1735. 000468 6F12               M         movwf   pSrc
  1736. 00046A 0E04               M         movlw   high (CtrlTrfData)
  1737. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE 32
  1738. LOC  OBJECT CODE     LINE SOURCE TEXT
  1739.   VALUE
  1740. 00046C 6F13               M         movwf   pSrc + 1
  1741. 00046E 0E02           00323         movlw   2                       ; Set count
  1742. 000470 6F18           00324         movwf   wCount
  1743. 000472 6B19           00325         clrf    wCount + 1
  1744. 000474 931D           00326         bcf     usb_stat, ctrl_trf_mem  ; Indicate RAM
  1745. 000476 0012           00327         return
  1746.                       00328 
  1747.                       00329 ; From usb9.c  line 281
  1748.                       00330 ;/******************************************************************************
  1749.                       00331 ; * Function:        void USBStdFeatureReqHandler(void)
  1750.                       00332 ; *
  1751.                       00333 ; * PreCondition:    None
  1752.                       00334 ; *
  1753.                       00335 ; * Input:           None
  1754.                       00336 ; *
  1755.                       00337 ; * Output:          None
  1756.                       00338 ; *
  1757.                       00339 ; * Side Effects:    None
  1758.                       00340 ; *
  1759.                       00341 ; * Overview:        This routine handles the standard SET & CLEAR FEATURES
  1760.                       00342 ; *                  requests
  1761.                       00343 ; *
  1762.                       00344 ; * Note:            None
  1763.                       00345 ; *****************************************************************************/
  1764. 000478                00346 USBStdFeatureReqHandler
  1765.                       00347 ;       movlb   high 0x400              ; Point to proper bank
  1766. 000478 0E01           00348         movlw   DEVICE_REMOTE_WAKEUP    ; If Feature = DEVICE_REMOTE_WAKEUP &
  1767. 00047A 6320           00349         cpfseq  SetupPkt + bFeature
  1768. 00047C D009           00350         bra     USBStdFeatureReqHandler1
  1769. 00047E 511E           00351         movf    SetupPkt, W     ; Recipient = RCPT_DEV?
  1770. 000480 0B1F           00352         andlw   0x1f                    ; Mask to lower 5 bits
  1771. 000482 0800           00353         sublw   RCPT_DEV
  1772. 000484 E105           00354         bnz     USBStdFeatureReqHandler1        ; No
  1773. 000486 811D           00355         bsf     usb_stat, RemoteWakeup  ; Preset RemoteWakeup to 1
  1774. 000488 0E03           00356         movlw   SET_FEATURE             ; Request = SET_FEATURE?
  1775. 00048A 631F           00357         cpfseq  SetupPkt + bRequest
  1776. 00048C 911D           00358         bcf     usb_stat, RemoteWakeup  ; No, RemoteWakeup = 0
  1777. 00048E D76F           00359         bra     USBStdSetSessionOwnerUSB9
  1778. 000490                00360 USBStdFeatureReqHandler1
  1779. 000490 0E00           00361         movlw   ENDPOINT_HALT           ; If Feature = ENDPOINT_HALT &
  1780. 000492 6320           00362         cpfseq  SetupPkt + bFeature
  1781. 000494                00363 USBStdFeatureReqHandlerExit
  1782. 000494 0012           00364         return
  1783. 000496 511E           00365         movf    SetupPkt, W     ; Recepient = RCPT_EP &
  1784. 000498 0B1F           00366         andlw   0x1f                    ; Mask to lower 5 bits
  1785. 00049A 0802           00367         sublw   RCPT_EP
  1786. 00049C E1FB           00368         bnz     USBStdFeatureReqHandlerExit
  1787. 00049E 5122           00369         movf    SetupPkt + bEPID, W     ; EPNum != 0
  1788. 0004A0 0B0F           00370         andlw   0x0f                    ; Mask to EPNum
  1789. 0004A2 E0F8           00371         bz      USBStdFeatureReqHandlerExit
  1790. 0004A4 D80B           00372         rcall   USBCalcEPAddress        ; Put endpoint buffer address in FSR2
  1791. 0004A6 0E03           00373         movlw   SET_FEATURE             ; Request = SET_FEATURE?
  1792. 0004A8 631F           00374         cpfseq  SetupPkt + bRequest
  1793. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE 33
  1794. LOC  OBJECT CODE     LINE SOURCE TEXT
  1795.   VALUE
  1796. 0004AA D003           00375         bra     USBStdFeatureReqHandler2        ; No
  1797. 0004AC 0E84           00376         movlw   _USIE|_BSTALL
  1798. 0004AE 6EDF           00377         movwf   INDF2                   ; Put in endpoint buffer
  1799. 0004B0 D75E           00378         bra     USBStdSetSessionOwnerUSB9
  1800. 0004B2                00379 USBStdFeatureReqHandler2
  1801. 0004B2 0E00           00380         movlw   _UCPU                   ; IN
  1802. 0004B4 AF22           00381         btfss   SetupPkt + bEPID, EPDir ; EPDir = 1 (IN)?
  1803. 0004B6 0E88           00382         movlw   _USIE|_DAT0|_DTSEN      ; No - OUT
  1804. 0004B8 6EDF           00383         movwf   INDF2                   ; Put in endpoint buffer
  1805. 0004BA D759           00384         bra     USBStdSetSessionOwnerUSB9
  1806.                       00385 
  1807.                       00386 
  1808.                       00387 ; Put endpoint buffer address in FSR2 (ep0Bo+(EPNum*8)+(EPDir*4))
  1809. 0004BC                00388 USBCalcEPAddress
  1810. 0004BC EE24 F000      00389         lfsr    2, ep0Bo                ; Point FSR2 to beginning of buffer area
  1811. 0004C0 4522           00390         rlncf   SetupPkt + bEPID, W     ; Move endpoint direction to C
  1812. 0004C2 3522           00391         rlcf    SetupPkt + bEPID, W     ; Endpoint number * 8 (roll in ep direction)
  1813. 0004C4 46E8           00392         rlncf   WREG, F
  1814. 0004C6 46E8           00393         rlncf   WREG, F
  1815. 0004C8 26D9           00394         addwf   FSR2L, F                ; Add to FSR2 (can't overflow to FSR2H)
  1816. 0004CA 0012           00395         return
  1817.                       00396 
  1818.                       00397 
  1819.                       00398 
  1820.                       00399 ; From usbctrltrf.c line 78
  1821.                       00400 ;/******************************************************************************
  1822.                       00401 ; * Function:        void USBCtrlEPService(void)
  1823.                       00402 ; *
  1824.                       00403 ; * PreCondition:    USTAT is loaded with a valid endpoint address.
  1825.                       00404 ; *
  1826.                       00405 ; * Input:           None
  1827.                       00406 ; *
  1828.                       00407 ; * Output:          None
  1829.                       00408 ; *
  1830.                       00409 ; * Side Effects:    None
  1831.                       00410 ; *
  1832.                       00411 ; * Overview:        USBCtrlEPService checks for three transaction types that
  1833.                       00412 ; *                  it knows how to service and services them:
  1834.                       00413 ; *                  1. EP0 SETUP
  1835.                       00414 ; *                  2. EP0 OUT
  1836.                       00415 ; *                  3. EP0 IN
  1837.                       00416 ; *                  It ignores all other types (i.e. EP1, EP2, etc.)
  1838.                       00417 ; *
  1839.                       00418 ; * Note:            None
  1840.                       00419 ; *****************************************************************************/
  1841. 0004CC                00420 USBCtrlEPService
  1842.                       00421 ;       movlb   high 0x400              ; Point to proper bank
  1843. 0004CC 0E00           00422         movlw   EP00_OUT
  1844. 0004CE 626C           00423         cpfseq  USTAT
  1845. 0004D0 D005           00424         bra     USBCtrlEPService1
  1846. 0004D2 5100           00425         movf    ep0Bo + Stat, W
  1847. 0004D4 0B3C           00426         andlw   0x3c                    ; Mask to PID
  1848. 0004D6 0834           00427         sublw   (SETUP_TOKEN) << 2
  1849. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE 34
  1850. LOC  OBJECT CODE     LINE SOURCE TEXT
  1851.   VALUE
  1852. 0004D8 E005           00428         bz      USBCtrlTrfSetupHandler
  1853. 0004DA D010           00429         bra     USBCtrlTrfOutHandler
  1854. 0004DC                00430 USBCtrlEPService1
  1855. 0004DC 0E04           00431         movlw   EP00_IN
  1856. 0004DE 626C           00432         cpfseq  USTAT
  1857. 0004E0 0012           00433         return
  1858. 0004E2 D015           00434         bra     USBCtrlTrfInHandler
  1859.                       00435 
  1860.                       00436 
  1861.                       00437 ; From usbctrltrf.c line 133
  1862.                       00438 ;/******************************************************************************
  1863.                       00439 ; * Function:        void USBCtrlTrfSetupHandler(void)
  1864.                       00440 ; *
  1865.                       00441 ; * PreCondition:    SetupPkt buffer is loaded with valid USB Setup Data
  1866.                       00442 ; *
  1867.                       00443 ; * Input:           None
  1868.                       00444 ; *
  1869.                       00445 ; * Output:          None
  1870.                       00446 ; *
  1871.                       00447 ; * Side Effects:    None
  1872.                       00448 ; *
  1873.                       00449 ; * Overview:        This routine is a task dispatcher and has 3 stages.
  1874.                       00450 ; *                  1. It initializes the control transfer state machine.
  1875.                       00451 ; *                  2. It calls on each of the module that may know how to
  1876.                       00452 ; *                     service the Setup Request from the host.
  1877.                       00453 ; *                     Module Example: USB9, HID, CDC, MSD, ...
  1878.                       00454 ; *                     As new classes are added, ClassReqHandler table in
  1879.                       00455 ; *                     usbdsc.c should be updated to call all available
  1880.                       00456 ; *                     class handlers.
  1881.                       00457 ; *                  3. Once each of the modules has had a chance to check if
  1882.                       00458 ; *                     it is responsible for servicing the request, stage 3
  1883.                       00459 ; *                     then checks direction of the transfer to determine how
  1884.                       00460 ; *                     to prepare EP0 for the control transfer.
  1885.                       00461 ; *                     Refer to USBCtrlEPServiceComplete() for more details.
  1886.                       00462 ; *
  1887.                       00463 ; * Note:            Microchip USB Firmware has three different states for
  1888.                       00464 ; *                  the control transfer state machine:
  1889.                       00465 ; *                  1. WAIT_SETUP
  1890.                       00466 ; *                  2. CTRL_TRF_TX
  1891.                       00467 ; *                  3. CTRL_TRF_RX
  1892.                       00468 ; *                  Refer to firmware manual to find out how one state
  1893.                       00469 ; *                  is transitioned to another.
  1894.                       00470 ; *
  1895.                       00471 ; *                  A Control Transfer is composed of many USB transactions.
  1896.                       00472 ; *                  When transferring data over multiple transactions,
  1897.                       00473 ; *                  it is important to keep track of data source, data
  1898.                       00474 ; *                  destination, and data count. These three parameters are
  1899.                       00475 ; *                  stored in pSrc,pDst, and wCount. A flag is used to
  1900.                       00476 ; *                  note if the data source is from ROM or RAM.
  1901.                       00477 ; *
  1902.                       00478 ; *****************************************************************************/
  1903. 0004E4                00479 USBCtrlTrfSetupHandler
  1904.                       00480 ;       movlb   high 0x400              ; Point to proper bank
  1905. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE 35
  1906. LOC  OBJECT CODE     LINE SOURCE TEXT
  1907.   VALUE
  1908. 0004E4 0E00           00481         movlw   WAIT_SETUP
  1909. 0004E6 6F16           00482         movwf   ctrl_trf_state
  1910. 0004E8 0E00           00483         movlw   MUID_NULL               ; Set owner to NULL
  1911. 0004EA 6F17           00484         movwf   ctrl_trf_session_owner
  1912. 0004EC 6B18           00485         clrf    wCount
  1913. 0004EE 6B19           00486         clrf    wCount + 1
  1914. 0004F0 DEFD           00487         rcall   USBCheckStdRequest
  1915. 0004F2 0E00           00488         movlw   MUID_NULL
  1916. 0004F4 6317           00489         cpfseq  ctrl_trf_session_owner
  1917. 0004F6 D079           00490         bra     USBCtrlEPServiceComplete
  1918.                       00491 #ifdef USB_USE_HID
  1919. 0004F8 D945           00492         rcall   USBCheckHIDRequest
  1920.                       00493 #endif ; USB_USE_HID
  1921.                       00494 #ifdef USB_USE_CDC
  1922.                       00495         rcall   USBCheckCDCRequest
  1923.                       00496 #endif ; USB_USE_CDC
  1924. 0004FA D077           00497         bra     USBCtrlEPServiceComplete
  1925.                       00498 
  1926.                       00499 
  1927.                       00500 ; From usbctrltrf.c line 176
  1928.                       00501 ;/******************************************************************************
  1929.                       00502 ; * Function:        void USBCtrlTrfOutHandler(void)
  1930.                       00503 ; *
  1931.                       00504 ; * PreCondition:    None
  1932.                       00505 ; *
  1933.                       00506 ; * Input:           None
  1934.                       00507 ; *
  1935.                       00508 ; * Output:          None
  1936.                       00509 ; *
  1937.                       00510 ; * Side Effects:    None
  1938.                       00511 ; *
  1939.                       00512 ; * Overview:        This routine handles an OUT transaction according to
  1940.                       00513 ; *                  which control transfer state is currently active.
  1941.                       00514 ; *
  1942.                       00515 ; * Note:            Note that if the the control transfer was from
  1943.                       00516 ; *                  host to device, the session owner should be notified
  1944.                       00517 ; *                  at the end of each OUT transaction to service the
  1945.                       00518 ; *                  received data.
  1946.                       00519 ; *
  1947.                       00520 ; *****************************************************************************/
  1948. 0004FC                00521 USBCtrlTrfOutHandler
  1949.                       00522 ;       movlb   high 0x400              ; Point to proper bank
  1950. 0004FC 0E02           00523         movlw   CTRL_TRF_RX
  1951. 0004FE 6316           00524         cpfseq  ctrl_trf_state
  1952. 000500 D0AF           00525         bra     USBPrepareForNextSetupTrf
  1953. 000502 D857           00526         rcall   USBCtrlTrfRxService
  1954. 000504 0EC8           00527         movlw   _USIE|_DAT1|_DTSEN
  1955. 000506 BD00           00528         btfsc   ep0Bo + Stat, DTS
  1956. 000508 0E88           00529         movlw   _USIE|_DAT0|_DTSEN
  1957. 00050A 6F00           00530         movwf   ep0Bo + Stat
  1958. 00050C 0012           00531         return
  1959.                       00532 
  1960.                       00533 
  1961. MPASM  5.22                         USBFM.ASM   1-25-2010  15:59:32         PAGE 36
  1962. LOC  OBJECT CODE     LINE SOURCE TEXT
  1963.   VALUE
  1964.                       00534 ; From usbctrltrf.c line 221
  1965.                       00535 ;/******************************************************************************
  1966.                       00536 ; * Function:        void USBCtrlTrfInHandler(void)
  1967.                       00537 ; *
  1968.                       00538 ; * PreCondition:    None
  1969.                       00539 ; *
  1970.                       00540 ; * Input:           None
  1971.                       00541 ; *
  1972.                       00542 ; * Output:          None
  1973.                       00543 ; *
  1974.                       00544 ; * Side Effects:    None
  1975.                       00545 ; *
  1976.                       00546 ; * Overview:        This routine handles an IN transaction according to
  1977.                       00547 ; *                  which control transfer state is currently active.
  1978.                       00548 ; *
  1979.                       00549 ; *
  1980.                       00550 ; * Note:            A Set Address Request must not change the acutal address
  1981.                       00551 ; *                  of the device until the completion of the control
  1982.                       00552 ; *                  transfer. The end of the control transfer for Set Address
  1983.                       00553 ; *                  Request is an IN transaction. Therefore it is necessary
  1984.                       00554 ; *                  to service this unique situation when the condition is
  1985.                       00555 ; *                  right. Macro mUSBCheckAdrPendingState is defined in