Rev 1504 Rev 1858
1 CCS PCH C Compiler, Version 4.090, 47914 28-V-10 17:50 1 CCS PCH C Compiler, Version 4.090, 47914 28-V-10 17:50
2   2  
3 Filename: D:\MLAB\Designs\galileo_experiment\SW\main.lst 3 Filename: D:\MLAB\Designs\galileo_experiment\SW\main.lst
4   4  
5 ROM used: 9692 bytes (30%) 5 ROM used: 9692 bytes (30%)
6 Largest free fragment is 23072 6 Largest free fragment is 23072
7 RAM used: 1650 (81%) at main() level 7 RAM used: 1650 (81%) at main() level
8 1869 (91%) worst case 8 1869 (91%) worst case
9 Stack: 17 worst case (8 in main + 9 for interrupts) 9 Stack: 17 worst case (8 in main + 9 for interrupts)
10   10  
11 * 11 *
12 0000: GOTO 1F62 12 0000: GOTO 1F62
13 * 13 *
14 0008: MOVWF 05 14 0008: MOVWF 05
15 000A: MOVFF FD8,06 15 000A: MOVFF FD8,06
16 000E: MOVFF FE0,07 16 000E: MOVFF FE0,07
17 0012: MOVLB 0 17 0012: MOVLB 0
18 0014: MOVFF FE9,0D 18 0014: MOVFF FE9,0D
19 0018: MOVFF FEA,08 19 0018: MOVFF FEA,08
20 001C: MOVFF FE1,09 20 001C: MOVFF FE1,09
21 0020: MOVFF FE2,0A 21 0020: MOVFF FE2,0A
22 0024: MOVFF FD9,0B 22 0024: MOVFF FD9,0B
23 0028: MOVFF FDA,0C 23 0028: MOVFF FDA,0C
24 002C: MOVFF FF3,14 24 002C: MOVFF FF3,14
25 0030: MOVFF FF4,15 25 0030: MOVFF FF4,15
26 0034: MOVFF FFA,16 26 0034: MOVFF FFA,16
27 0038: MOVFF 00,0F 27 0038: MOVFF 00,0F
28 003C: MOVFF 01,10 28 003C: MOVFF 01,10
29 0040: MOVFF 02,11 29 0040: MOVFF 02,11
30 0044: MOVFF 03,12 30 0044: MOVFF 03,12
31 0048: MOVFF 04,13 31 0048: MOVFF 04,13
32 004C: BTFSS FF2.5 32 004C: BTFSS FF2.5
33 004E: GOTO 0058 33 004E: GOTO 0058
34 0052: BTFSC FF2.2 34 0052: BTFSC FF2.2
35 0054: GOTO 025E 35 0054: GOTO 025E
36 0058: BTFSS FA0.5 36 0058: BTFSS FA0.5
37 005A: GOTO 0064 37 005A: GOTO 0064
38 005E: BTFSC FA1.5 38 005E: BTFSC FA1.5
39 0060: GOTO 1274 39 0060: GOTO 1274
40 0064: MOVFF 0F,00 40 0064: MOVFF 0F,00
41 0068: MOVFF 10,01 41 0068: MOVFF 10,01
42 006C: MOVFF 11,02 42 006C: MOVFF 11,02
43 0070: MOVFF 12,03 43 0070: MOVFF 12,03
44 0074: MOVFF 13,04 44 0074: MOVFF 13,04
45 0078: MOVFF 0D,FE9 45 0078: MOVFF 0D,FE9
46 007C: MOVFF 08,FEA 46 007C: MOVFF 08,FEA
47 0080: BSF 08.7 47 0080: BSF 08.7
48 0082: MOVFF 09,FE1 48 0082: MOVFF 09,FE1
49 0086: MOVFF 0A,FE2 49 0086: MOVFF 0A,FE2
50 008A: MOVFF 0B,FD9 50 008A: MOVFF 0B,FD9
51 008E: MOVFF 0C,FDA 51 008E: MOVFF 0C,FDA
52 0092: MOVFF 14,FF3 52 0092: MOVFF 14,FF3
53 0096: MOVFF 15,FF4 53 0096: MOVFF 15,FF4
54 009A: MOVFF 16,FFA 54 009A: MOVFF 16,FFA
55 009E: MOVF 05,W 55 009E: MOVF 05,W
56 00A0: MOVFF 07,FE0 56 00A0: MOVFF 07,FE0
57 00A4: MOVFF 06,FD8 57 00A4: MOVFF 06,FD8
58 00A8: RETFIE 0 58 00A8: RETFIE 0
59 .................... #include "main.h" 59 .................... #include "main.h"
60 .................... #include <18F4550.h> 60 .................... #include <18F4550.h>
61 .................... //////// Standard Header file for the PIC18F4550 device //////////////// 61 .................... //////// Standard Header file for the PIC18F4550 device ////////////////
62 .................... #device PIC18F4550 62 .................... #device PIC18F4550
63 .................... #list 63 .................... #list
64 .................... 64 ....................
65 .................... #device adc=10 65 .................... #device adc=10
66 .................... 66 ....................
67 .................... #FUSES NOWDT //No Watch Dog Timer 67 .................... #FUSES NOWDT //No Watch Dog Timer
68 .................... #FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale 68 .................... #FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
69 .................... #FUSES HSPLL //Crystal/Resonator with PLL enabled 69 .................... #FUSES HSPLL //Crystal/Resonator with PLL enabled
70 .................... #FUSES NOPROTECT //Code not protected from reading 70 .................... #FUSES NOPROTECT //Code not protected from reading
71 .................... #FUSES NOBROWNOUT //No brownout reset 71 .................... #FUSES NOBROWNOUT //No brownout reset
72 .................... #FUSES BORV20 //Brownout reset at 2.0V 72 .................... #FUSES BORV20 //Brownout reset at 2.0V
73 .................... #FUSES NOPUT //No Power Up Timer 73 .................... #FUSES NOPUT //No Power Up Timer
74 .................... #FUSES NOCPD //No EE protection 74 .................... #FUSES NOCPD //No EE protection
75 .................... #FUSES STVREN //Stack full/underflow will cause reset 75 .................... #FUSES STVREN //Stack full/underflow will cause reset
76 .................... #FUSES NODEBUG //No Debug mode for ICD 76 .................... #FUSES NODEBUG //No Debug mode for ICD
77 .................... #FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O 77 .................... #FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
78 .................... #FUSES NOWRT //Program memory not write protected 78 .................... #FUSES NOWRT //Program memory not write protected
79 .................... #FUSES NOWRTD //Data EEPROM not write protected 79 .................... #FUSES NOWRTD //Data EEPROM not write protected
80 .................... #FUSES IESO //Internal External Switch Over mode enabled 80 .................... #FUSES IESO //Internal External Switch Over mode enabled
81 .................... #FUSES FCMEN //Fail-safe clock monitor enabled 81 .................... #FUSES FCMEN //Fail-safe clock monitor enabled
82 .................... #FUSES PBADEN //PORTB pins are configured as analog input channels on RESET 82 .................... #FUSES PBADEN //PORTB pins are configured as analog input channels on RESET
83 .................... #FUSES NOWRTC //configuration not registers write protected 83 .................... #FUSES NOWRTC //configuration not registers write protected
84 .................... #FUSES NOWRTB //Boot block not write protected 84 .................... #FUSES NOWRTB //Boot block not write protected
85 .................... #FUSES NOEBTR //Memory not protected from table reads 85 .................... #FUSES NOEBTR //Memory not protected from table reads
86 .................... #FUSES NOEBTRB //Boot block not protected from table reads 86 .................... #FUSES NOEBTRB //Boot block not protected from table reads
87 .................... #FUSES NOCPB //No Boot Block code protection 87 .................... #FUSES NOCPB //No Boot Block code protection
88 .................... #FUSES MCLR //Master Clear pin enabled 88 .................... #FUSES MCLR //Master Clear pin enabled
89 .................... #FUSES LPT1OSC //Timer1 configured for low-power operation 89 .................... #FUSES LPT1OSC //Timer1 configured for low-power operation
90 .................... #FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode) 90 .................... #FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
91 .................... #FUSES PLL5 //Divide By 5(20MHz oscillator input) 91 .................... #FUSES PLL5 //Divide By 5(20MHz oscillator input)
92 .................... #FUSES CPUDIV4 //System Clock by 4 92 .................... #FUSES CPUDIV4 //System Clock by 4
93 .................... #FUSES USBDIV //USB clock source comes from PLL divide by 2 93 .................... #FUSES USBDIV //USB clock source comes from PLL divide by 2
94 .................... #FUSES VREGEN //USB voltage regulator enabled 94 .................... #FUSES VREGEN //USB voltage regulator enabled
95 .................... #FUSES ICPRT //ICPRT enabled 95 .................... #FUSES ICPRT //ICPRT enabled
96 .................... 96 ....................
97 .................... #use delay(clock=24000000) 97 .................... #use delay(clock=24000000)
98 .................... 98 ....................
99 .................... 99 ....................
100 .................... 100 ....................
101 .................... #define REV "$Rev$" 101 .................... #define REV "$Rev$"
102 .................... 102 ....................
103 .................... unsigned int32 time; // pocitadlo preteceni casovace 103 .................... unsigned int32 time; // pocitadlo preteceni casovace
104 .................... 104 ....................
105 .................... #define BUFLEN 100 105 .................... #define BUFLEN 100
106 .................... 106 ....................
107 .................... #int_RTCC 107 .................... #int_RTCC
108 .................... void RTCC_isr(void) // preruseni od pretekleho casovace 108 .................... void RTCC_isr(void) // preruseni od pretekleho casovace
109 .................... { 109 .................... {
110 .................... time++; 110 .................... time++;
111 * 111 *
112 025E: MOVLW 01 112 025E: MOVLW 01
113 0260: ADDWF 19,F 113 0260: ADDWF 19,F
114 0262: BTFSC FD8.0 114 0262: BTFSC FD8.0
115 0264: INCF 1A,F 115 0264: INCF 1A,F
116 0266: BTFSC FD8.2 116 0266: BTFSC FD8.2
117 0268: INCF 1B,F 117 0268: INCF 1B,F
118 026A: BTFSC FD8.2 118 026A: BTFSC FD8.2
119 026C: INCF 1C,F 119 026C: INCF 1C,F
120 .................... } 120 .................... }
121 .................... 121 ....................
122 .................... // Includes all USB code and interrupts, as well as the CDC API 122 .................... // Includes all USB code and interrupts, as well as the CDC API
123 .................... #include <usb_cdc.h> 123 .................... #include <usb_cdc.h>
124 .................... ///////////////////////////////////////////////////////////////////////// 124 .................... /////////////////////////////////////////////////////////////////////////
125 .................... //// //// 125 .................... //// ////
126 .................... //// usb_cdc.h //// 126 .................... //// usb_cdc.h ////
127 .................... //// //// 127 .................... //// ////
128 .................... //// Library for adding a virtual COM port on your PC over USB using //// 128 .................... //// Library for adding a virtual COM port on your PC over USB using ////
129 .................... //// the standard Communication Device Class (CDC) specification. //// 129 .................... //// the standard Communication Device Class (CDC) specification. ////
130 .................... //// Including this file in your code will add all USB code, //// 130 .................... //// Including this file in your code will add all USB code, ////
131 .................... //// interrupts, descriptors and handlers required. No other //// 131 .................... //// interrupts, descriptors and handlers required. No other ////
132 .................... //// modifications need to be made. //// 132 .................... //// modifications need to be made. ////
133 .................... //// //// 133 .................... //// ////
134 .................... //// This library creates a virtual RS232 link between the PC and //// 134 .................... //// This library creates a virtual RS232 link between the PC and ////
135 .................... //// the PIC, therefore the library provided will be familiar to //// 135 .................... //// the PIC, therefore the library provided will be familiar to ////
136 .................... //// anyone with standard UART stream I/O: //// 136 .................... //// anyone with standard UART stream I/O: ////
137 .................... //// //// 137 .................... //// ////
138 .................... //// usb_cdc_kbhit() - Returns TRUE if there is one or more //// 138 .................... //// usb_cdc_kbhit() - Returns TRUE if there is one or more ////
139 .................... //// character received and waiting in the receive buffer. //// 139 .................... //// character received and waiting in the receive buffer. ////
140 .................... //// //// 140 .................... //// ////
141 .................... //// usb_cdc_getc() - Gets a character from the receive buffer. If //// 141 .................... //// usb_cdc_getc() - Gets a character from the receive buffer. If ////
142 .................... //// there is no data in the receive buffer it will wait until //// 142 .................... //// there is no data in the receive buffer it will wait until ////
143 .................... //// there is data in the receive buffer. If you do not want //// 143 .................... //// there is data in the receive buffer. If you do not want ////
144 .................... //// to wait in an infinit loop, use usb_cdc_kbhit() first to //// 144 .................... //// to wait in an infinit loop, use usb_cdc_kbhit() first to ////
145 .................... //// check if there is data before calling usb_cdc_getc(). //// 145 .................... //// check if there is data before calling usb_cdc_getc(). ////
146 .................... //// //// 146 .................... //// ////
147 .................... //// usb_cdc_putc(char c) - Puts a character into the transmit //// 147 .................... //// usb_cdc_putc(char c) - Puts a character into the transmit ////
148 .................... //// buffer. If the transmit buffer is full it will wait until //// 148 .................... //// buffer. If the transmit buffer is full it will wait until ////
149 .................... //// the transmit buffer is not full before putting the char //// 149 .................... //// the transmit buffer is not full before putting the char ////
150 .................... //// into the transmit buffer. The transmit buffer is read by //// 150 .................... //// into the transmit buffer. The transmit buffer is read by ////
151 .................... //// the PC very quickly, and therefore the buffer should only //// 151 .................... //// the PC very quickly, and therefore the buffer should only ////
152 .................... //// be full for a few milli-seconds. If you are concerned //// 152 .................... //// be full for a few milli-seconds. If you are concerned ////
153 .................... //// and don't want to be stuck in a long or infinite loop, //// 153 .................... //// and don't want to be stuck in a long or infinite loop, ////
154 .................... //// use usb_cdc_putready() to see if there is space in the //// 154 .................... //// use usb_cdc_putready() to see if there is space in the ////
155 .................... //// transmit buffer before putting data into the transmit //// 155 .................... //// transmit buffer before putting data into the transmit ////
156 .................... //// buffer. //// 156 .................... //// buffer. ////
157 .................... //// //// 157 .................... //// ////
158 .................... //// usb_cdc_putready() - Returns TRUE if there is room left in the //// 158 .................... //// usb_cdc_putready() - Returns TRUE if there is room left in the ////
159 .................... //// transmit buffer for another character. //// 159 .................... //// transmit buffer for another character. ////
160 .................... //// //// 160 .................... //// ////
161 .................... //// usb_cdc_connected() - Returns TRUE if we received a //// 161 .................... //// usb_cdc_connected() - Returns TRUE if we received a ////
162 .................... //// Set_Line_Coding. On most serial terminal programs (such //// 162 .................... //// Set_Line_Coding. On most serial terminal programs (such ////
163 .................... //// as Hyperterminal), they will send a Set_Line_Coding //// 163 .................... //// as Hyperterminal), they will send a Set_Line_Coding ////
164 .................... //// message when the program starts and it opens the virtual //// 164 .................... //// message when the program starts and it opens the virtual ////
165 .................... //// COM port. This is a simple way to determine if the PC //// 165 .................... //// COM port. This is a simple way to determine if the PC ////
166 .................... //// is ready to display data on a serial terminal program, //// 166 .................... //// is ready to display data on a serial terminal program, ////
167 .................... //// but is not garaunteed to work all the time or on other //// 167 .................... //// but is not garaunteed to work all the time or on other ////
168 .................... //// terminal programs. //// 168 .................... //// terminal programs. ////
169 .................... //// //// 169 .................... //// ////
170 .................... //// usb_cdc_putc_fast(char c) - Similar to usb_cdc_putc(), except //// 170 .................... //// usb_cdc_putc_fast(char c) - Similar to usb_cdc_putc(), except ////
171 .................... //// if the transmit buffer is full it will skip the char. //// 171 .................... //// if the transmit buffer is full it will skip the char. ////
172 .................... //// //// 172 .................... //// ////
173 .................... //// usb_cdc_line_coding - A structure used for Set_Line_Coding and //// 173 .................... //// usb_cdc_line_coding - A structure used for Set_Line_Coding and ////
174 .................... //// Get_Line_Coding. Most of the time you can ignore this. //// 174 .................... //// Get_Line_Coding. Most of the time you can ignore this. ////
175 .................... //// //// 175 .................... //// ////
176 .................... //// usb_cdc_break - If the PC has sent a break command, this will //// 176 .................... //// usb_cdc_break - If the PC has sent a break command, this will ////
177 .................... //// hold the break time (in milli-seconds). If the PC sends //// 177 .................... //// hold the break time (in milli-seconds). If the PC sends ////
178 .................... //// a value of 0xFFFF the device is supposed to hold the //// 178 .................... //// a value of 0xFFFF the device is supposed to hold the ////
179 .................... //// break until it sends a value of 0 //// 179 .................... //// break until it sends a value of 0 ////
180 .................... //// //// 180 .................... //// ////
181 .................... //// usb_cdc_carrier - Where Set_Control_Line_State value is stored. //// 181 .................... //// usb_cdc_carrier - Where Set_Control_Line_State value is stored. ////
182 .................... //// Of most relevance is the field dte_present, which is the //// 182 .................... //// Of most relevance is the field dte_present, which is the ////
183 .................... //// DTR setting. //// 183 .................... //// DTR setting. ////
184 .................... //// //// 184 .................... //// ////
185 .................... //// The following functions are also provided, and are ports of the //// 185 .................... //// The following functions are also provided, and are ports of the ////
186 .................... //// I/O functions in input.c. See input.c and the CCS manual for //// 186 .................... //// I/O functions in input.c. See input.c and the CCS manual for ////
187 .................... //// documentation: //// 187 .................... //// documentation: ////
188 .................... //// get_float_usb() - Read a float number from the user //// 188 .................... //// get_float_usb() - Read a float number from the user ////
189 .................... //// get_long_usb() - Read a long number from the user //// 189 .................... //// get_long_usb() - Read a long number from the user ////
190 .................... //// get_int_usb() - Read an integer number from the user //// 190 .................... //// get_int_usb() - Read an integer number from the user ////
191 .................... //// get_string_usb(char *s, int max) - Read a string from the user. //// 191 .................... //// get_string_usb(char *s, int max) - Read a string from the user. ////
192 .................... //// gethex_usb() - Read a byte, in HEX, from the user //// 192 .................... //// gethex_usb() - Read a byte, in HEX, from the user ////
193 .................... //// gethex1_usb() - Read a HEX character //// 193 .................... //// gethex1_usb() - Read a HEX character ////
194 .................... //// //// 194 .................... //// ////
195 .................... //// This driver will load all the rest of the USB code, and a set //// 195 .................... //// This driver will load all the rest of the USB code, and a set ////
196 .................... //// of descriptors that will properly describe a CDC device for a //// 196 .................... //// of descriptors that will properly describe a CDC device for a ////
197 .................... //// virtual COM port (usb_desc_cdc.h) //// 197 .................... //// virtual COM port (usb_desc_cdc.h) ////
198 .................... //// //// 198 .................... //// ////
199 .................... //// An .INF file is provided (cdc_NTXP.inf) that will load the //// 199 .................... //// An .INF file is provided (cdc_NTXP.inf) that will load the ////
200 .................... //// standard CDC drivers for a virtual COM port in Windows //// 200 .................... //// standard CDC drivers for a virtual COM port in Windows ////
201 .................... //// NT/2000/XP and above. //// 201 .................... //// NT/2000/XP and above. ////
202 .................... //// //// 202 .................... //// ////
203 .................... ///////////////////////////////////////////////////////////////////////// 203 .................... /////////////////////////////////////////////////////////////////////////
204 .................... //// //// 204 .................... //// ////
205 .................... //// VERSION HISTORY //// 205 .................... //// VERSION HISTORY ////
206 .................... //// //// 206 .................... //// ////
207 .................... //// March 5th, 2009: //// 207 .................... //// March 5th, 2009: ////
208 .................... //// Cleanup for Wizard. //// 208 .................... //// Cleanup for Wizard. ////
209 .................... //// PIC24 Initial release. //// 209 .................... //// PIC24 Initial release. ////
210 .................... //// //// 210 .................... //// ////
211 .................... //// Nov 26th, 2007: //// 211 .................... //// Nov 26th, 2007: ////
212 .................... //// usb_cdc_put_buffer_free() should be more stable. //// 212 .................... //// usb_cdc_put_buffer_free() should be more stable. ////
213 .................... //// Fixed a hang-up that would happen if you sent //// 213 .................... //// Fixed a hang-up that would happen if you sent ////
214 .................... //// exactly 64 bytes. //// 214 .................... //// exactly 64 bytes. ////
215 .................... //// //// 215 .................... //// ////
216 .................... //// Nov 6th, 2007: //// 216 .................... //// Nov 6th, 2007: ////
217 .................... //// Compatabible with latest pic18_usb.h, which //// 217 .................... //// Compatabible with latest pic18_usb.h, which ////
218 .................... //// reduces RAM footprint of USB driver. //// 218 .................... //// reduces RAM footprint of USB driver. ////
219 .................... //// This driver now fits on 18F4450/2450 PICs. //// 219 .................... //// This driver now fits on 18F4450/2450 PICs. ////
220 .................... //// //// 220 .................... //// ////
221 .................... //// October 27th, 2005: Changed the way incoming packets are //// 221 .................... //// October 27th, 2005: Changed the way incoming packets are ////
222 .................... //// handled in that CDC driver will not flush //// 222 .................... //// handled in that CDC driver will not flush ////
223 .................... //// endpoint until user has handled all data. This //// 223 .................... //// endpoint until user has handled all data. This ////
224 .................... //// will prevent overflows as the USB will NAK //// 224 .................... //// will prevent overflows as the USB will NAK ////
225 .................... //// incoming packets until it is ready to receive //// 225 .................... //// incoming packets until it is ready to receive ////
226 .................... //// more. //// 226 .................... //// more. ////
227 .................... //// When using 18F4550 family, the RX buffer is //// 227 .................... //// When using 18F4550 family, the RX buffer is ////
228 .................... //// mapped directly to the endpoint buffer - this //// 228 .................... //// mapped directly to the endpoint buffer - this ////
229 .................... //// saves a chunk of RAM. //// 229 .................... //// saves a chunk of RAM. ////
230 .................... //// When using the 18F4550 family, you can increase //// 230 .................... //// When using the 18F4550 family, you can increase ////
231 .................... //// the TX and RX size over 64 bytes. //// 231 .................... //// the TX and RX size over 64 bytes. ////
232 .................... //// No longer send 0len packets in the TBE interrupt. //// 232 .................... //// No longer send 0len packets in the TBE interrupt. ////
233 .................... //// Hopefully fixed bugs that caused random crashes //// 233 .................... //// Hopefully fixed bugs that caused random crashes ////
234 .................... //// if you tried sending more than 64 bytes. //// 234 .................... //// if you tried sending more than 64 bytes. ////
235 .................... //// //// 235 .................... //// ////
236 .................... //// July 6th, 2005: Global interrupts disabled when writing to TX //// 236 .................... //// July 6th, 2005: Global interrupts disabled when writing to TX ////
237 .................... //// buffer. //// 237 .................... //// buffer. ////
238 .................... //// //// 238 .................... //// ////
239 .................... //// July 1st, 2005: Initial Release. //// 239 .................... //// July 1st, 2005: Initial Release. ////
240 .................... //// //// 240 .................... //// ////
241 .................... ///////////////////////////////////////////////////////////////////////// 241 .................... /////////////////////////////////////////////////////////////////////////
242 .................... //// (C) Copyright 1996,2005 Custom Computer Services //// 242 .................... //// (C) Copyright 1996,2005 Custom Computer Services ////
243 .................... //// This source code may only be used by licensed users of the CCS //// 243 .................... //// This source code may only be used by licensed users of the CCS ////
244 .................... //// C compiler. This source code may only be distributed to other //// 244 .................... //// C compiler. This source code may only be distributed to other ////
245 .................... //// licensed users of the CCS C compiler. No other use, //// 245 .................... //// licensed users of the CCS C compiler. No other use, ////
246 .................... //// reproduction or distribution is permitted without written //// 246 .................... //// reproduction or distribution is permitted without written ////
247 .................... //// permission. Derivative programs created using this software //// 247 .................... //// permission. Derivative programs created using this software ////
248 .................... //// in object code form are not restricted in any way. //// 248 .................... //// in object code form are not restricted in any way. ////
249 .................... ///////////////////////////////////////////////////////////////////////// 249 .................... /////////////////////////////////////////////////////////////////////////
250 .................... 250 ....................
251 .................... 251 ....................
252 .................... //api for the user: 252 .................... //api for the user:
253 .................... #define usb_cdc_kbhit() (usb_cdc_get_buffer_status.got) 253 .................... #define usb_cdc_kbhit() (usb_cdc_get_buffer_status.got)
254 .................... #define usb_cdc_putready() (usb_cdc_put_buffer_nextin<USB_CDC_DATA_IN_SIZE) 254 .................... #define usb_cdc_putready() (usb_cdc_put_buffer_nextin<USB_CDC_DATA_IN_SIZE)
255 .................... #define usb_cdc_connected() (usb_cdc_got_set_line_coding) 255 .................... #define usb_cdc_connected() (usb_cdc_got_set_line_coding)
256 026E: BCF FF2.2 256 026E: BCF FF2.2
257 0270: GOTO 0064 257 0270: GOTO 0064
258 .................... void usb_cdc_putc_fast(char c); 258 .................... void usb_cdc_putc_fast(char c);
259 .................... char usb_cdc_getc(void); 259 .................... char usb_cdc_getc(void);
260 .................... void usb_cdc_putc(char c); 260 .................... void usb_cdc_putc(char c);
261 .................... 261 ....................
262 .................... //input.c ported to use CDC: 262 .................... //input.c ported to use CDC:
263 .................... float get_float_usb(); 263 .................... float get_float_usb();
264 .................... signed long get_long_usb(); 264 .................... signed long get_long_usb();
265 .................... signed int get_int_usb(); 265 .................... signed int get_int_usb();
266 .................... void get_string_usb(char* s, unsigned int max); 266 .................... void get_string_usb(char* s, unsigned int max);
267 .................... BYTE gethex_usb(); 267 .................... BYTE gethex_usb();
268 .................... BYTE gethex1_usb(); 268 .................... BYTE gethex1_usb();
269 .................... 269 ....................
270 .................... //functions automatically called by USB handler code 270 .................... //functions automatically called by USB handler code
271 .................... void usb_isr_tkn_cdc(void); 271 .................... void usb_isr_tkn_cdc(void);
272 .................... void usb_cdc_init(void); 272 .................... void usb_cdc_init(void);
273 .................... void usb_isr_tok_out_cdc_control_dne(void); 273 .................... void usb_isr_tok_out_cdc_control_dne(void);
274 .................... void usb_isr_tok_in_cdc_data_dne(void); 274 .................... void usb_isr_tok_in_cdc_data_dne(void);
275 .................... void usb_isr_tok_out_cdc_data_dne(void); 275 .................... void usb_isr_tok_out_cdc_data_dne(void);
276 .................... 276 ....................
277 .................... void usb_cdc_flush_out_buffer(void); 277 .................... void usb_cdc_flush_out_buffer(void);
278 .................... 278 ....................
279 .................... ///////////////////////////////////////////////////////////////////////////// 279 .................... /////////////////////////////////////////////////////////////////////////////
280 .................... // 280 .................... //
281 .................... // Include the CCS USB Libraries. See the comments at the top of these 281 .................... // Include the CCS USB Libraries. See the comments at the top of these
282 .................... // files for more information 282 .................... // files for more information
283 .................... // 283 .................... //
284 .................... ///////////////////////////////////////////////////////////////////////////// 284 .................... /////////////////////////////////////////////////////////////////////////////
285 .................... #ifndef __USB_PIC_PERIF__ 285 .................... #ifndef __USB_PIC_PERIF__
286 .................... #define __USB_PIC_PERIF__ 1 286 .................... #define __USB_PIC_PERIF__ 1
287 .................... #endif 287 .................... #endif
288 .................... 288 ....................
289 .................... #if __USB_PIC_PERIF__ 289 .................... #if __USB_PIC_PERIF__
290 .................... #if defined(__PCH__) 290 .................... #if defined(__PCH__)
291 .................... #include <pic18_usb.h> //Microchip 18Fxx5x hardware layer for usb.c 291 .................... #include <pic18_usb.h> //Microchip 18Fxx5x hardware layer for usb.c
292 .................... ///////////////////////////////////////////////////////////////////////// 292 .................... /////////////////////////////////////////////////////////////////////////
293 .................... //// pic18_usb.h //// 293 .................... //// pic18_usb.h ////
294 .................... //// //// 294 .................... //// ////
295 .................... //// Hardware layer for CCS's USB library. This hardware layer //// 295 .................... //// Hardware layer for CCS's USB library. This hardware layer ////
296 .................... //// supports the USB peripheral on the PIC18 family chips. Current //// 296 .................... //// supports the USB peripheral on the PIC18 family chips. Current ////
297 .................... //// supported families are: //// 297 .................... //// supported families are: ////
298 .................... //// PIC18F2455/2550/4455/4550 //// 298 .................... //// PIC18F2455/2550/4455/4550 ////
299 .................... //// PIC18F2450/4450 //// 299 .................... //// PIC18F2450/4450 ////
300 .................... //// PIC18F2458/2553/4458/4553 //// 300 .................... //// PIC18F2458/2553/4458/4553 ////
301 .................... //// PIC18F13K50/14K50 //// 301 .................... //// PIC18F13K50/14K50 ////
302 .................... //// PIC18F65J50/66J50/66J55/67J50/85J50/86J50/86J55/87J50 //// 302 .................... //// PIC18F65J50/66J50/66J55/67J50/85J50/86J50/86J55/87J50 ////
303 .................... //// //// 303 .................... //// ////
304 .................... //// This file is part of CCS's PIC USB driver code. See USB.H //// 304 .................... //// This file is part of CCS's PIC USB driver code. See USB.H ////
305 .................... //// for more documentation and a list of examples. //// 305 .................... //// for more documentation and a list of examples. ////
306 .................... //// //// 306 .................... //// ////
307 .................... //// See the section labeled EXTRA USER FUNCTIONS for functions //// 307 .................... //// See the section labeled EXTRA USER FUNCTIONS for functions ////
308 .................... //// that are specific to only this HW peripheral that you may //// 308 .................... //// that are specific to only this HW peripheral that you may ////
309 .................... //// find useful to use in your application. //// 309 .................... //// find useful to use in your application. ////
310 .................... //// //// 310 .................... //// ////
311 .................... //// *********** NOTE ABOUT 18F2450/4450 LIMITATIONS ********** //// 311 .................... //// *********** NOTE ABOUT 18F2450/4450 LIMITATIONS ********** ////
312 .................... //// Due to the limited USB RAM of this family, a limitation of //// 312 .................... //// Due to the limited USB RAM of this family, a limitation of ////
313 .................... //// this driver is that there are only 3 endpoints (0, 1 and 2). //// 313 .................... //// this driver is that there are only 3 endpoints (0, 1 and 2). ////
314 .................... //// The HW actually supports more endpoints, but to simplify //// 314 .................... //// The HW actually supports more endpoints, but to simplify ////
315 .................... //// driver development this driver will only support the first 3 //// 315 .................... //// driver development this driver will only support the first 3 ////
316 .................... //// so there is an easier memory block to work with. //// 316 .................... //// so there is an easier memory block to work with. ////
317 .................... //// //// 317 .................... //// ////
318 .................... //// USB_MAX_EP0_PACKET_LENGTH will also be set to 8 regardless //// 318 .................... //// USB_MAX_EP0_PACKET_LENGTH will also be set to 8 regardless ////
319 .................... //// of USB speed, to save RAM. //// 319 .................... //// of USB speed, to save RAM. ////
320 .................... //// //// 320 .................... //// ////
321 .................... //// ************** NOTE ABOUT HW REQUIREMENTS **************** //// 321 .................... //// ************** NOTE ABOUT HW REQUIREMENTS **************** ////
322 .................... //// If you are not using internal pullups, you will need to put //// 322 .................... //// If you are not using internal pullups, you will need to put ////
323 .................... //// an internal pullup resistor on D+ or D+ depending on if you //// 323 .................... //// an internal pullup resistor on D+ or D+ depending on if you ////
324 .................... //// want to use slow speed or full speed. This code configures //// 324 .................... //// want to use slow speed or full speed. This code configures ////
325 .................... //// the device to use internal pullups, see usb_init() if you //// 325 .................... //// the device to use internal pullups, see usb_init() if you ////
326 .................... //// want to change that. //// 326 .................... //// want to change that. ////
327 .................... //// //// 327 .................... //// ////
328 .................... //// You need approximately 470nF cap on Vusb, even if you are //// 328 .................... //// You need approximately 470nF cap on Vusb, even if you are ////
329 .................... //// using the internal 3.3V USB regulator. //// 329 .................... //// using the internal 3.3V USB regulator. ////
330 .................... //// //// 330 .................... //// ////
331 .................... //// To run at full speed, you must use the oscillator //// 331 .................... //// To run at full speed, you must use the oscillator ////
332 .................... //// configuration (PLLx) to set the PLL divide to 4MHz. You can //// 332 .................... //// configuration (PLLx) to set the PLL divide to 4MHz. You can ////
333 .................... //// configure the MCU clock to any speed (up to 48MHz) but the //// 333 .................... //// configure the MCU clock to any speed (up to 48MHz) but the ////
334 .................... //// PLL must run at 4Mhz to provide the USB peripheral with a //// 334 .................... //// PLL must run at 4Mhz to provide the USB peripheral with a ////
335 .................... //// 96MHz clock. See the datasheet for details. //// 335 .................... //// 96MHz clock. See the datasheet for details. ////
336 .................... //// //// 336 .................... //// ////
337 .................... //// To run at slow speed you must configure your MCU to run at //// 337 .................... //// To run at slow speed you must configure your MCU to run at ////
338 .................... //// 24Mhz. See the datasheet for details. //// 338 .................... //// 24Mhz. See the datasheet for details. ////
339 .................... //// //// 339 .................... //// ////
340 .................... //// **************** NOTE ABOUT INTERRUPTS ****************** //// 340 .................... //// **************** NOTE ABOUT INTERRUPTS ****************** ////
341 .................... //// This driver uses INT_USB. It requires INT_USB to interrupt the //// 341 .................... //// This driver uses INT_USB. It requires INT_USB to interrupt the ////
342 .................... //// PIC when an event has happened on the USB Bus. Therfore //// 342 .................... //// PIC when an event has happened on the USB Bus. Therfore ////
343 .................... //// this code enables interrupts. A user modification can be made //// 343 .................... //// this code enables interrupts. A user modification can be made ////
344 .................... //// to poll the USB interrupt flag instead of relying on an //// 344 .................... //// to poll the USB interrupt flag instead of relying on an ////
345 .................... //// interrupt. //// 345 .................... //// interrupt. ////
346 .................... //// //// 346 .................... //// ////
347 .................... ///////////////////////////////////////////////////////////////////////// 347 .................... /////////////////////////////////////////////////////////////////////////
348 .................... //// //// 348 .................... //// ////
349 .................... //// Version History: //// 349 .................... //// Version History: ////
350 .................... //// //// 350 .................... //// ////
351 .................... //// March 5th, 2009: //// 351 .................... //// March 5th, 2009: ////
352 .................... //// 18F14K50 family added. //// 352 .................... //// 18F14K50 family added. ////
353 .................... //// Cleanup for Wizard. //// 353 .................... //// Cleanup for Wizard. ////
354 .................... //// PIC24 Initial release. //// 354 .................... //// PIC24 Initial release. ////
355 .................... //// //// 355 .................... //// ////
356 .................... //// Nov 3rd, 2008: //// 356 .................... //// Nov 3rd, 2008: ////
357 .................... //// * 4553 family added. //// 357 .................... //// * 4553 family added. ////
358 .................... //// //// 358 .................... //// ////
359 .................... //// Dec 18, 2007: //// 359 .................... //// Dec 18, 2007: ////
360 .................... //// * usb_kbhit() moved to device driver. //// 360 .................... //// * usb_kbhit() moved to device driver. ////
361 .................... //// * USB Token handler changed to workaround a flaw in the USB //// 361 .................... //// * USB Token handler changed to workaround a flaw in the USB ////
362 .................... //// peripheral to prevent the USB peripheral from //// 362 .................... //// peripheral to prevent the USB peripheral from ////
363 .................... //// inadvertantly STALLing the endpoint. Happened most often //// 363 .................... //// inadvertantly STALLing the endpoint. Happened most often ////
364 .................... //// in bulk demo applications, especially CDC. //// 364 .................... //// in bulk demo applications, especially CDC. ////
365 .................... //// //// 365 .................... //// ////
366 .................... //// 11-6-07: Fixed a bug where usb_data_buffer[] was reserving //// 366 .................... //// 11-6-07: Fixed a bug where usb_data_buffer[] was reserving ////
367 .................... //// too much RAM. //// 367 .................... //// too much RAM. ////
368 .................... //// USB_MAX_EP0_PACKET_LENGTH value can be overwritten. //// 368 .................... //// USB_MAX_EP0_PACKET_LENGTH value can be overwritten. ////
369 .................... //// For the 18F4450/2450 family this should be 8 //// 369 .................... //// For the 18F4450/2450 family this should be 8 ////
370 .................... //// because of limited RAM. Reducing this value //// 370 .................... //// because of limited RAM. Reducing this value ////
371 .................... //// frees RAM for application. //// 371 .................... //// frees RAM for application. ////
372 .................... //// Based upon which endpoints have been configured for //// 372 .................... //// Based upon which endpoints have been configured for ////
373 .................... //// use, will free up unused USB data RAM for //// 373 .................... //// use, will free up unused USB data RAM for ////
374 .................... //// application dynamically. This should free up //// 374 .................... //// application dynamically. This should free up ////
375 .................... //// at least 128 bytes of RAM. //// 375 .................... //// at least 128 bytes of RAM. ////
376 .................... //// CDC now fits on a 18F4450/2450 //// 376 .................... //// CDC now fits on a 18F4450/2450 ////
377 .................... //// //// 377 .................... //// ////
378 .................... //// 09-19-07: Fixed problems with 18F4450 family. //// 378 .................... //// 09-19-07: Fixed problems with 18F4450 family. ////
379 .................... //// //// 379 .................... //// ////
380 .................... //// 07-17-07: Added 18F4450,2450 support //// 380 .................... //// 07-17-07: Added 18F4450,2450 support ////
381 .................... //// //// 381 .................... //// ////
382 .................... //// 07-13-07: Added 87J50 family support //// 382 .................... //// 07-13-07: Added 87J50 family support ////
383 .................... //// //// 383 .................... //// ////
384 .................... //// 11-01-05: usb_detach(), usb_attach() and usb_init_cs() //// 384 .................... //// 11-01-05: usb_detach(), usb_attach() and usb_init_cs() ////
385 .................... //// changed for the better. //// 385 .................... //// changed for the better. ////
386 .................... //// //// 386 .................... //// ////
387 .................... //// 10-28-05: Added usb_rx_packet_size() //// 387 .................... //// 10-28-05: Added usb_rx_packet_size() ////
388 .................... //// //// 388 .................... //// ////
389 .................... //// 07-13-05: usb_put_packet() changed for 16bit packet sizes //// 389 .................... //// 07-13-05: usb_put_packet() changed for 16bit packet sizes ////
390 .................... //// usb_flush_in() changed for 16bit packet sizes //// 390 .................... //// usb_flush_in() changed for 16bit packet sizes ////
391 .................... //// usb_get_packet() changed for 16bit packet sizes //// 391 .................... //// usb_get_packet() changed for 16bit packet sizes ////
392 .................... //// usb_flush_out() changed for 16bit packet sizes //// 392 .................... //// usb_flush_out() changed for 16bit packet sizes ////
393 .................... //// usb_set_configured() changed for 16bit packet sizes //// 393 .................... //// usb_set_configured() changed for 16bit packet sizes ////
394 .................... //// //// 394 .................... //// ////
395 .................... //// 06-30-05: usb_tbe() added //// 395 .................... //// 06-30-05: usb_tbe() added ////
396 .................... //// The way endpoint 0 DTS is set has been changed. //// 396 .................... //// The way endpoint 0 DTS is set has been changed. ////
397 .................... //// //// 397 .................... //// ////
398 .................... //// 06-20-05: Initial Release //// 398 .................... //// 06-20-05: Initial Release ////
399 .................... //// //// 399 .................... //// ////
400 .................... //// 05-13-05: Beta Release (Full Speed works) //// 400 .................... //// 05-13-05: Beta Release (Full Speed works) ////
401 .................... //// //// 401 .................... //// ////
402 .................... //// 03-21-05: Initial Alpha Release //// 402 .................... //// 03-21-05: Initial Alpha Release ////
403 .................... //// //// 403 .................... //// ////
404 .................... ///////////////////////////////////////////////////////////////////////// 404 .................... /////////////////////////////////////////////////////////////////////////
405 .................... //// (C) Copyright 1996,2005 Custom Computer Services //// 405 .................... //// (C) Copyright 1996,2005 Custom Computer Services ////
406 .................... //// This source code may only be used by licensed users of the CCS //// 406 .................... //// This source code may only be used by licensed users of the CCS ////
407 .................... //// C compiler. This source code may only be distributed to other //// 407 .................... //// C compiler. This source code may only be distributed to other ////
408 .................... //// licensed users of the CCS C compiler. No other use, //// 408 .................... //// licensed users of the CCS C compiler. No other use, ////
409 .................... //// reproduction or distribution is permitted without written //// 409 .................... //// reproduction or distribution is permitted without written ////
410 .................... //// permission. Derivative programs created using this software //// 410 .................... //// permission. Derivative programs created using this software ////
411 .................... //// in object code form are not restricted in any way. //// 411 .................... //// in object code form are not restricted in any way. ////
412 .................... ///////////////////////////////////////////////////////////////////////// 412 .................... /////////////////////////////////////////////////////////////////////////
413 .................... 413 ....................
414 .................... #IFNDEF __PIC18_USB_H__ 414 .................... #IFNDEF __PIC18_USB_H__
415 .................... #DEFINE __PIC18_USB_H__ 415 .................... #DEFINE __PIC18_USB_H__
416 .................... 416 ....................
417 .................... #DEFINE __USB_HARDWARE__ 417 .................... #DEFINE __USB_HARDWARE__
418 .................... 418 ....................
419 .................... //let the USB Stack know that we are using a PIC with internal USB peripheral 419 .................... //let the USB Stack know that we are using a PIC with internal USB peripheral
420 .................... #DEFINE __PIC__ 1 420 .................... #DEFINE __PIC__ 1
421 .................... 421 ....................
422 .................... #ifndef USB_USE_FULL_SPEED 422 .................... #ifndef USB_USE_FULL_SPEED
423 .................... #define USB_USE_FULL_SPEED TRUE 423 .................... #define USB_USE_FULL_SPEED TRUE
424 .................... #endif 424 .................... #endif
425 .................... 425 ....................
426 .................... #ifndef USB_MAX_EP0_PACKET_LENGTH 426 .................... #ifndef USB_MAX_EP0_PACKET_LENGTH
427 .................... #if ((getenv("DEVICE")=="PIC18F2450") || (getenv("DEVICE")=="PIC18F4450")) 427 .................... #if ((getenv("DEVICE")=="PIC18F2450") || (getenv("DEVICE")=="PIC18F4450"))
428 .................... //due to limited ram, force max packet length to 8 for this chip 428 .................... //due to limited ram, force max packet length to 8 for this chip
429 .................... #define USB_MAX_EP0_PACKET_LENGTH 8 429 .................... #define USB_MAX_EP0_PACKET_LENGTH 8
430 .................... #else 430 .................... #else
431 .................... #if USB_USE_FULL_SPEED==FALSE 431 .................... #if USB_USE_FULL_SPEED==FALSE
432 .................... //slow speed requires 8byte max packet size for endpoint 0 432 .................... //slow speed requires 8byte max packet size for endpoint 0
433 .................... #DEFINE USB_MAX_EP0_PACKET_LENGTH 8 433 .................... #DEFINE USB_MAX_EP0_PACKET_LENGTH 8
434 .................... #else 434 .................... #else
435 .................... //for full speed you can still use 8bytes, but 64 will be faster 435 .................... //for full speed you can still use 8bytes, but 64 will be faster
436 .................... #DEFINE USB_MAX_EP0_PACKET_LENGTH 64 436 .................... #DEFINE USB_MAX_EP0_PACKET_LENGTH 64
437 .................... #endif 437 .................... #endif
438 .................... #endif 438 .................... #endif
439 .................... #endif 439 .................... #endif
440 .................... 440 ....................
441 .................... #if (!USB_USE_FULL_SPEED && (USB_MAX_EP0_PACKET_LENGTH!=8)) 441 .................... #if (!USB_USE_FULL_SPEED && (USB_MAX_EP0_PACKET_LENGTH!=8))
442 .................... #error Slow speed devices must use a max packet size of 8 for endpoint 0! 442 .................... #error Slow speed devices must use a max packet size of 8 for endpoint 0!
443 .................... #endif 443 .................... #endif
444 .................... 444 ....................
445 .................... #if USB_MAX_EP0_PACKET_LENGTH < 8 445 .................... #if USB_MAX_EP0_PACKET_LENGTH < 8
446 .................... #error Max Endpoint 0 length can't be less than 8! 446 .................... #error Max Endpoint 0 length can't be less than 8!
447 .................... #endif 447 .................... #endif
448 .................... 448 ....................
449 .................... #if USB_MAX_EP0_PACKET_LENGTH > 64 449 .................... #if USB_MAX_EP0_PACKET_LENGTH > 64
450 .................... #error Max Endpoint 0 length can't be greater than 64! 450 .................... #error Max Endpoint 0 length can't be greater than 64!
451 .................... #endif 451 .................... #endif
452 .................... 452 ....................
453 .................... #include <usb_hw_layer.h> 453 .................... #include <usb_hw_layer.h>
454 .................... /////////////////////////////////////////////////////////////////////////// 454 .................... ///////////////////////////////////////////////////////////////////////////
455 .................... //// usb_hw_layer.h //// 455 .................... //// usb_hw_layer.h ////
456 .................... //// //// 456 .................... //// ////
457 .................... //// HW Layer for the USB Stack. //// 457 .................... //// HW Layer for the USB Stack. ////
458 .................... //// //// 458 .................... //// ////
459 .................... //// HW drivers for the USB stack must support this API. //// 459 .................... //// HW drivers for the USB stack must support this API. ////
460 .................... //// //// 460 .................... //// ////
461 .................... //// The HW driver must also have a token handler that will call //// 461 .................... //// The HW driver must also have a token handler that will call ////
462 .................... //// usb_token_reset() when the device is init/reset, will call //// 462 .................... //// usb_token_reset() when the device is init/reset, will call ////
463 .................... //// usb_isr_tok_setup_dne() when it receives a setup packet, //// 463 .................... //// usb_isr_tok_setup_dne() when it receives a setup packet, ////
464 .................... //// will call usb_isr_tok_out_dne() when a new packet is received, //// 464 .................... //// will call usb_isr_tok_out_dne() when a new packet is received, ////
465 .................... //// and will call usb_isr_tok_in_dne() when a new packet is sent. //// 465 .................... //// and will call usb_isr_tok_in_dne() when a new packet is sent. ////
466 .................... //// See usb.h for documentation of these functions. //// 466 .................... //// See usb.h for documentation of these functions. ////
467 .................... //// //// 467 .................... //// ////
468 .................... /////////////////////////////////////////////////////////////////////////// 468 .................... ///////////////////////////////////////////////////////////////////////////
469 .................... //// //// 469 .................... //// ////
470 .................... //// Version History: //// 470 .................... //// Version History: ////
471 .................... //// //// 471 .................... //// ////
472 .................... //// March 5th, 2009: //// 472 .................... //// March 5th, 2009: ////
473 .................... //// Cleanup for Wizard. //// 473 .................... //// Cleanup for Wizard. ////
474 .................... //// PIC24 Initial release. //// 474 .................... //// PIC24 Initial release. ////
475 .................... //// //// 475 .................... //// ////
476 .................... /////////////////////////////////////////////////////////////////////////// 476 .................... ///////////////////////////////////////////////////////////////////////////
477 .................... //// (C) Copyright 1996,2009 Custom Computer Services //// 477 .................... //// (C) Copyright 1996,2009 Custom Computer Services ////
478 .................... //// This source code may only be used by licensed users of the CCS //// 478 .................... //// This source code may only be used by licensed users of the CCS ////
479 .................... //// C compiler. This source code may only be distributed to other //// 479 .................... //// C compiler. This source code may only be distributed to other ////
480 .................... //// licensed users of the CCS C compiler. No other use, //// 480 .................... //// licensed users of the CCS C compiler. No other use, ////
481 .................... //// reproduction or distribution is permitted without written //// 481 .................... //// reproduction or distribution is permitted without written ////
482 .................... //// permission. Derivative programs created using this software //// 482 .................... //// permission. Derivative programs created using this software ////
483 .................... //// in object code form are not restricted in any way. //// 483 .................... //// in object code form are not restricted in any way. ////
484 .................... /////////////////////////////////////////////////////////////////////////// 484 .................... ///////////////////////////////////////////////////////////////////////////
485 .................... 485 ....................
486 .................... #ifndef __USB_HW_LAYER_H__ 486 .................... #ifndef __USB_HW_LAYER_H__
487 .................... #define __USB_HW_LAYER_H__ 487 .................... #define __USB_HW_LAYER_H__
488 .................... 488 ....................
489 .................... enum USB_DTS_BIT {USB_DTS_DATA1=1, USB_DTS_TOGGLE=2, USB_DTS_DATA0=0, 489 .................... enum USB_DTS_BIT {USB_DTS_DATA1=1, USB_DTS_TOGGLE=2, USB_DTS_DATA0=0,
490 .................... USB_DTS_STALL=3, USB_DTS_USERX=4}; 490 .................... USB_DTS_STALL=3, USB_DTS_USERX=4};
491 .................... 491 ....................
492 .................... 492 ....................
493 .................... // USER LEVEL FUNCTIONS: 493 .................... // USER LEVEL FUNCTIONS:
494 .................... 494 ....................
495 .................... /***************************************************************************** 495 .................... /*****************************************************************************
496 .................... /* usb_init() 496 .................... /* usb_init()
497 .................... /* 497 .................... /*
498 .................... /* Summary: See API section of USB.H for documentation. 498 .................... /* Summary: See API section of USB.H for documentation.
499 .................... /* 499 .................... /*
500 .................... /*****************************************************************************/ 500 .................... /*****************************************************************************/
501 .................... void usb_init(void); 501 .................... void usb_init(void);
502 .................... 502 ....................
503 .................... /***************************************************************************** 503 .................... /*****************************************************************************
504 .................... /* usb_init_cs() 504 .................... /* usb_init_cs()
505 .................... /* 505 .................... /*
506 .................... /* Summary: See API section of USB.H for documentation. 506 .................... /* Summary: See API section of USB.H for documentation.
507 .................... /* 507 .................... /*
508 .................... /*****************************************************************************/ 508 .................... /*****************************************************************************/
509 .................... void usb_init_cs(void); 509 .................... void usb_init_cs(void);
510 .................... 510 ....................
511 .................... /***************************************************************************** 511 .................... /*****************************************************************************
512 .................... /* usb_task() 512 .................... /* usb_task()
513 .................... /* 513 .................... /*
514 .................... /* Summary: See API section of USB.H for documentation. 514 .................... /* Summary: See API section of USB.H for documentation.
515 .................... /* 515 .................... /*
516 .................... /*****************************************************************************/ 516 .................... /*****************************************************************************/
517 .................... void usb_task(void); 517 .................... void usb_task(void);
518 .................... 518 ....................
519 .................... /****************************************************************************** 519 .................... /******************************************************************************
520 .................... /* usb_attach() 520 .................... /* usb_attach()
521 .................... /* 521 .................... /*
522 .................... /* Summary: Attach the D+/D- lines to the USB bus. Enable the USB peripheral. 522 .................... /* Summary: Attach the D+/D- lines to the USB bus. Enable the USB peripheral.
523 .................... /* 523 .................... /*
524 .................... /* You should wait until UCON_SE0 is clear before enabling reset/idle interrupt. 524 .................... /* You should wait until UCON_SE0 is clear before enabling reset/idle interrupt.
525 .................... /* 525 .................... /*
526 .................... /* Shouldn't be called by user, let usb_task() handle this. 526 .................... /* Shouldn't be called by user, let usb_task() handle this.
527 .................... /* 527 .................... /*
528 .................... /* NOTE: If you are writing a new HW driver, this routine should call 528 .................... /* NOTE: If you are writing a new HW driver, this routine should call
529 .................... /* usb_token_reset() to reset the CH9 stack. 529 .................... /* usb_token_reset() to reset the CH9 stack.
530 .................... /* 530 .................... /*
531 .................... /*****************************************************************************/ 531 .................... /*****************************************************************************/
532 .................... void usb_attach(void); 532 .................... void usb_attach(void);
533 .................... 533 ....................
534 .................... /****************************************************************************** 534 .................... /******************************************************************************
535 .................... /* usb_detach() 535 .................... /* usb_detach()
536 .................... /* 536 .................... /*
537 .................... /* Summary: Remove the D+/D- lines from the USB bus. Basically, disable USB. 537 .................... /* Summary: Remove the D+/D- lines from the USB bus. Basically, disable USB.
538 .................... /* 538 .................... /*
539 .................... /* Shouldn't be called by user, let usb_task() handle this. 539 .................... /* Shouldn't be called by user, let usb_task() handle this.
540 .................... /* 540 .................... /*
541 .................... /* If the user does call this function while USB is connected, the USB 541 .................... /* If the user does call this function while USB is connected, the USB
542 .................... /* peripheral will be disabled only momentarily because usb_task() will 542 .................... /* peripheral will be disabled only momentarily because usb_task() will
543 .................... /* reconnect. But this is a great way to cause the PC/HOST to cause a USB 543 .................... /* reconnect. But this is a great way to cause the PC/HOST to cause a USB
544 .................... /* reset of the device. 544 .................... /* reset of the device.
545 .................... /* 545 .................... /*
546 .................... /* NOTE: If you are writing a new HW driver, this routine should call 546 .................... /* NOTE: If you are writing a new HW driver, this routine should call
547 .................... /* usb_token_reset() to reset the CH9 stack. 547 .................... /* usb_token_reset() to reset the CH9 stack.
548 .................... /* 548 .................... /*
549 .................... /*****************************************************************************/ 549 .................... /*****************************************************************************/
550 .................... void usb_detach(void); 550 .................... void usb_detach(void);
551 .................... 551 ....................
552 .................... /****************************************************************************** 552 .................... /******************************************************************************
553 .................... /* usb_put_packet() 553 .................... /* usb_put_packet()
554 .................... /* 554 .................... /*
555 .................... /* Input: endpoint - endpoint to send packet to (0..15). 555 .................... /* Input: endpoint - endpoint to send packet to (0..15).
556 .................... /* ptr - points to data to send. 556 .................... /* ptr - points to data to send.
557 .................... /* len - amount of data to send. 557 .................... /* len - amount of data to send.
558 .................... /* toggle - whether to send data with a DATA0 pid, a DATA1 pid, 558 .................... /* toggle - whether to send data with a DATA0 pid, a DATA1 pid,
559 .................... /* or toggle from the last DATAx pid. 559 .................... /* or toggle from the last DATAx pid.
560 .................... /* 560 .................... /*
561 .................... /* Output: TRUE if data was sent correctly, FALSE if it was not. The only 561 .................... /* Output: TRUE if data was sent correctly, FALSE if it was not. The only
562 .................... /* reason it will return FALSE is if because the TX buffer is still full 562 .................... /* reason it will return FALSE is if because the TX buffer is still full
563 .................... /* from the last time it tried to send a packet. 563 .................... /* from the last time it tried to send a packet.
564 .................... /* 564 .................... /*
565 .................... /* Summary: Sends one packet out the EP to the host. Notice that there is a 565 .................... /* Summary: Sends one packet out the EP to the host. Notice that there is a
566 .................... /* difference between a packet and a message. If you wanted to send a 566 .................... /* difference between a packet and a message. If you wanted to send a
567 .................... /* 512 byte message on an endpoint that only supported 64 byte packets, 567 .................... /* 512 byte message on an endpoint that only supported 64 byte packets,
568 .................... /* this would be accomplished this by sending 8 64-byte packets, 568 .................... /* this would be accomplished this by sending 8 64-byte packets,
569 .................... /* followed by a 0 length packet. If the last (or only packet) being 569 .................... /* followed by a 0 length packet. If the last (or only packet) being
570 .................... /* sent is less than the max packet size defined in your descriptor 570 .................... /* sent is less than the max packet size defined in your descriptor
571 .................... /* then you do not need to send a 0 length packet to identify 571 .................... /* then you do not need to send a 0 length packet to identify
572 .................... /* an end of message. 572 .................... /* an end of message.
573 .................... /* 573 .................... /*
574 .................... /* usb_puts() (provided in usb.c) will send a multi-packet message 574 .................... /* usb_puts() (provided in usb.c) will send a multi-packet message
575 .................... /* correctly and know if a 0 lenght packet needs to be sent. 575 .................... /* correctly and know if a 0 lenght packet needs to be sent.
576 .................... /* 576 .................... /*
577 .................... /* The result will be invalid if the specified input has not been configured for 577 .................... /* The result will be invalid if the specified input has not been configured for
578 .................... /* use by the API with USB_EPx_TX_SIZE 578 .................... /* use by the API with USB_EPx_TX_SIZE
579 .................... /* 579 .................... /*
580 .................... /*****************************************************************************/ 580 .................... /*****************************************************************************/
581 .................... int1 usb_put_packet(int8 endpoint, int8 * ptr, unsigned int16 len, USB_DTS_BIT tgl); 581 .................... int1 usb_put_packet(int8 endpoint, int8 * ptr, unsigned int16 len, USB_DTS_BIT tgl);
582 .................... 582 ....................
583 .................... /******************************************************************************* 583 .................... /*******************************************************************************
584 .................... /* usb_get_packet(endpoint, *ptr, max) 584 .................... /* usb_get_packet(endpoint, *ptr, max)
585 .................... /* 585 .................... /*
586 .................... /* Input: endpoint - endpoint to get data from 586 .................... /* Input: endpoint - endpoint to get data from
587 .................... /* ptr - where to save data to local PIC RAM 587 .................... /* ptr - where to save data to local PIC RAM
588 .................... /* max - max amount of data to receive from buffer 588 .................... /* max - max amount of data to receive from buffer
589 .................... /* 589 .................... /*
590 .................... /* Output: the amount of data taken from the buffer and saved to ptr. 590 .................... /* Output: the amount of data taken from the buffer and saved to ptr.
591 .................... /* 591 .................... /*
592 .................... /* NOTE - IF THERE IS NO PACKET TO GET YOU WILL GET INVALID RESULTS! 592 .................... /* NOTE - IF THERE IS NO PACKET TO GET YOU WILL GET INVALID RESULTS!
593 .................... /* VERIFY WITH USB_KBHIT() BEFORE YOU CALL USB_GET_PACKET()! 593 .................... /* VERIFY WITH USB_KBHIT() BEFORE YOU CALL USB_GET_PACKET()!
594 .................... /* 594 .................... /*
595 .................... /* Summary: Gets a packet of data from the USB endpoint buffer. 595 .................... /* Summary: Gets a packet of data from the USB endpoint buffer.
596 .................... /* Until this is called, if there is data in the receive buffer the 596 .................... /* Until this is called, if there is data in the receive buffer the
597 .................... /* PC/HOST will be prevented from sending more data. Upon completion 597 .................... /* PC/HOST will be prevented from sending more data. Upon completion
598 .................... /* of this call, the endpoint will be freed and the PC/HOST will be 598 .................... /* of this call, the endpoint will be freed and the PC/HOST will be
599 .................... /* allowed to send a new packet. Only receives one packet, if you need 599 .................... /* allowed to send a new packet. Only receives one packet, if you need
600 .................... /* to receive multiple packets or handle 0-length terminator packets, 600 .................... /* to receive multiple packets or handle 0-length terminator packets,
601 .................... /* then use usb_gets(). 601 .................... /* then use usb_gets().
602 .................... /* 602 .................... /*
603 .................... /* The result will be invalid if the specified input has not been configured for 603 .................... /* The result will be invalid if the specified input has not been configured for
604 .................... /* use by the API with USB_EPx_RX_SIZE 604 .................... /* use by the API with USB_EPx_RX_SIZE
605 .................... /* 605 .................... /*
606 .................... /********************************************************************************/ 606 .................... /********************************************************************************/
607 .................... unsigned int16 usb_get_packet(int8 endpoint, int8 * ptr, unsigned int16 max); 607 .................... unsigned int16 usb_get_packet(int8 endpoint, int8 * ptr, unsigned int16 max);
608 .................... 608 ....................
609 .................... /**************************************************************************** 609 .................... /****************************************************************************
610 .................... /* usb_kbhit(endpoint) 610 .................... /* usb_kbhit(endpoint)
611 .................... /* 611 .................... /*
612 .................... /* Input: endpoint - endpoint to check (0..15) 612 .................... /* Input: endpoint - endpoint to check (0..15)
613 .................... /* 613 .................... /*
614 .................... /* Output: TRUE if there is new data in RX buffer, FALSE if there is not. 614 .................... /* Output: TRUE if there is new data in RX buffer, FALSE if there is not.
615 .................... /* 615 .................... /*
616 .................... /* Summary: Similar to kbhit(), sees if there is new data in the RX USB buffers. 616 .................... /* Summary: Similar to kbhit(), sees if there is new data in the RX USB buffers.
617 .................... /* See API section of USB.H for more information. 617 .................... /* See API section of USB.H for more information.
618 .................... /* 618 .................... /*
619 .................... /* The result will be invalid if the specified input has not been configured for 619 .................... /* The result will be invalid if the specified input has not been configured for
620 .................... /* use by the API with USB_EPx_RX_SIZE 620 .................... /* use by the API with USB_EPx_RX_SIZE
621 .................... /* 621 .................... /*
622 .................... /*****************************************************************************/ 622 .................... /*****************************************************************************/
623 .................... int1 usb_kbhit(int8 en); 623 .................... int1 usb_kbhit(int8 en);
624 .................... 624 ....................
625 .................... /****************************************************************************** 625 .................... /******************************************************************************
626 .................... /* usb_tbe(endpoint) 626 .................... /* usb_tbe(endpoint)
627 .................... /* 627 .................... /*
628 .................... /* Input: endpoint - endpoint to check 628 .................... /* Input: endpoint - endpoint to check
629 .................... /* ptr - where to save data to local PIC RAM 629 .................... /* ptr - where to save data to local PIC RAM
630 .................... /* max - max amount of data to receive from buffer 630 .................... /* max - max amount of data to receive from buffer
631 .................... /* 631 .................... /*
632 .................... /* Output: returns TRUE if this endpoint's IN buffer (PIC-PC) is empty and ready 632 .................... /* Output: returns TRUE if this endpoint's IN buffer (PIC-PC) is empty and ready
633 .................... /* returns FALSE if this endpoint's IN buffer is still processing the last 633 .................... /* returns FALSE if this endpoint's IN buffer is still processing the last
634 .................... /* transmit or if this endpoint is invalid. 634 .................... /* transmit or if this endpoint is invalid.
635 .................... /* 635 .................... /*
636 .................... /* The result will be invalid if the specified input has not been configured for 636 .................... /* The result will be invalid if the specified input has not been configured for
637 .................... /* use by the API with USB_EPx_TX_SIZE 637 .................... /* use by the API with USB_EPx_TX_SIZE
638 .................... /* 638 .................... /*
639 .................... /*****************************************************************************/ 639 .................... /*****************************************************************************/
640 .................... int1 usb_tbe(int8 en); 640 .................... int1 usb_tbe(int8 en);
641 .................... 641 ....................
642 .................... //////////////// END USER LEVEL FUNCTIONS ///////////////////////////////////// 642 .................... //////////////// END USER LEVEL FUNCTIONS /////////////////////////////////////
643 .................... 643 ....................
644 .................... 644 ....................
645 .................... /// 645 .................... ///
646 .................... /// BEGIN STACK LEVEL FUNCTIONS: These functions are meant to be called by 646 .................... /// BEGIN STACK LEVEL FUNCTIONS: These functions are meant to be called by
647 .................... /// the USB stack, and are not meant to be called by the 647 .................... /// the USB stack, and are not meant to be called by the
648 .................... /// user/application. 648 .................... /// user/application.
649 .................... /// 649 .................... ///
650 .................... 650 ....................
651 .................... /***************************************************************************** 651 .................... /*****************************************************************************
652 .................... /* usb_stall_ep() 652 .................... /* usb_stall_ep()
653 .................... /* 653 .................... /*
654 .................... /* Input: endpoint - endpoint to stall. 654 .................... /* Input: endpoint - endpoint to stall.
655 .................... /* top most bit indicates direction (set is IN, clear is OUT) 655 .................... /* top most bit indicates direction (set is IN, clear is OUT)
656 .................... /* 656 .................... /*
657 .................... /* Summary: Stalls specified endpoint. If endpoint is stalled it will 657 .................... /* Summary: Stalls specified endpoint. If endpoint is stalled it will
658 .................... /* send STALL packet if the host tries to access this endpoint's 658 .................... /* send STALL packet if the host tries to access this endpoint's
659 .................... /* buffer. 659 .................... /* buffer.
660 .................... /* 660 .................... /*
661 .................... /* NOTE: WE ASSUME ENDPOINT IS VALID. USB.C SHOULD CHECK IF VALID BEFORE 661 .................... /* NOTE: WE ASSUME ENDPOINT IS VALID. USB.C SHOULD CHECK IF VALID BEFORE
662 .................... /* CALLING THIS ROUTINE. 662 .................... /* CALLING THIS ROUTINE.
663 .................... /* 663 .................... /*
664 .................... /*****************************************************************************/ 664 .................... /*****************************************************************************/
665 .................... void usb_stall_ep(int8 endpoint); 665 .................... void usb_stall_ep(int8 endpoint);
666 .................... 666 ....................
667 .................... 667 ....................
668 .................... /***************************************************************************** 668 .................... /*****************************************************************************
669 .................... /* usb_unstall_ep(endpoint, direction) 669 .................... /* usb_unstall_ep(endpoint, direction)
670 .................... /* 670 .................... /*
671 .................... /* Input: endpoint - endpoint to un-stall. 671 .................... /* Input: endpoint - endpoint to un-stall.
672 .................... /* top most bit indicates direction (set is IN, clear is OUT) 672 .................... /* top most bit indicates direction (set is IN, clear is OUT)
673 .................... /* 673 .................... /*
674 .................... /* Summary: Un-stalls endpoint. 674 .................... /* Summary: Un-stalls endpoint.
675 .................... /* 675 .................... /*
676 .................... /* NOTE: WE ASSUME ENDPOINT IS VALID. USB.C SHOULD CHECK IF VALID BEFORE 676 .................... /* NOTE: WE ASSUME ENDPOINT IS VALID. USB.C SHOULD CHECK IF VALID BEFORE
677 .................... /* CALLING THIS ROUTINE. 677 .................... /* CALLING THIS ROUTINE.
678 .................... /* 678 .................... /*
679 .................... /*****************************************************************************/ 679 .................... /*****************************************************************************/
680 .................... void usb_unstall_ep(int8 endpoint); 680 .................... void usb_unstall_ep(int8 endpoint);
681 .................... 681 ....................
682 .................... /***************************************************************************** 682 .................... /*****************************************************************************
683 .................... /* usb_endpoint_stalled() 683 .................... /* usb_endpoint_stalled()
684 .................... /* 684 .................... /*
685 .................... /* Input: endpoint - endpoint to check 685 .................... /* Input: endpoint - endpoint to check
686 .................... /* top most bit indicates direction (set is IN, clear is OUT) 686 .................... /* top most bit indicates direction (set is IN, clear is OUT)
687 .................... /* 687 .................... /*
688 .................... /* Output: returns a TRUE if endpoint is stalled, FALSE if it is not. 688 .................... /* Output: returns a TRUE if endpoint is stalled, FALSE if it is not.
689 .................... /* 689 .................... /*
690 .................... /* Summary: Looks to see if an endpoint is stalled, or not. Does not look to 690 .................... /* Summary: Looks to see if an endpoint is stalled, or not. Does not look to
691 .................... /* see if endpoint has been issued a STALL, just whether or not it is 691 .................... /* see if endpoint has been issued a STALL, just whether or not it is
692 .................... /* configured to STALL on the next packet. See Set_Feature and 692 .................... /* configured to STALL on the next packet. See Set_Feature and
693 .................... /* Clear_Feature Chapter 9 requests. 693 .................... /* Clear_Feature Chapter 9 requests.
694 .................... /* 694 .................... /*
695 .................... /* NOTE: WE ASSUME ENDPOINT IS VALID. USB.C SHOULD CHECK IF VALID BEFORE 695 .................... /* NOTE: WE ASSUME ENDPOINT IS VALID. USB.C SHOULD CHECK IF VALID BEFORE
696 .................... /* CALLING THIS ROUTINE. 696 .................... /* CALLING THIS ROUTINE.
697 .................... /* 697 .................... /*
698 .................... /*****************************************************************************/ 698 .................... /*****************************************************************************/
699 .................... int1 usb_endpoint_stalled(int8 endpoint); 699 .................... int1 usb_endpoint_stalled(int8 endpoint);
700 .................... 700 ....................
701 .................... /***************************************************************************** 701 .................... /*****************************************************************************
702 .................... /* usb_set_address(address) 702 .................... /* usb_set_address(address)
703 .................... /* 703 .................... /*
704 .................... /* Input: address - address the host specified that we use 704 .................... /* Input: address - address the host specified that we use
705 .................... /* 705 .................... /*
706 .................... /* Summary: Configures the USB Peripheral for the specified device address. 706 .................... /* Summary: Configures the USB Peripheral for the specified device address.
707 .................... /* The host will now talk to use with the following address. 707 .................... /* The host will now talk to use with the following address.
708 .................... /* 708 .................... /*
709 .................... /*****************************************************************************/ 709 .................... /*****************************************************************************/
710 .................... void usb_set_address(int8 address); 710 .................... void usb_set_address(int8 address);
711 .................... 711 ....................
712 .................... /****************************************************************************** 712 .................... /******************************************************************************
713 .................... /* usb_set_configured() 713 .................... /* usb_set_configured()
714 .................... /* 714 .................... /*
715 .................... /* Input: config - Configuration to use. 0 to uncofigure device. 715 .................... /* Input: config - Configuration to use. 0 to uncofigure device.
716 .................... /* 716 .................... /*
717 .................... /* Summary: Configures or unconfigures device. If configuring device it will 717 .................... /* Summary: Configures or unconfigures device. If configuring device it will
718 .................... /* enable all the endpoints the user specified for this configuration. 718 .................... /* enable all the endpoints the user specified for this configuration.
719 .................... /* If un-configuring device it will disable all endpoints. 719 .................... /* If un-configuring device it will disable all endpoints.
720 .................... /* 720 .................... /*
721 .................... /* NOTE: CCS only provides code to handle 1 configuration. 721 .................... /* NOTE: CCS only provides code to handle 1 configuration.
722 .................... /* 722 .................... /*
723 .................... /*****************************************************************************/ 723 .................... /*****************************************************************************/
724 .................... void usb_set_configured(int8 config); 724 .................... void usb_set_configured(int8 config);
725 .................... 725 ....................
726 .................... /****************************************************************************** 726 .................... /******************************************************************************
727 .................... /* usb_disable_endpoints() 727 .................... /* usb_disable_endpoints()
728 .................... /* 728 .................... /*
729 .................... /* Summary: Disables endpoints (all endpoints but 0) 729 .................... /* Summary: Disables endpoints (all endpoints but 0)
730 .................... /* 730 .................... /*
731 .................... /*****************************************************************************/ 731 .................... /*****************************************************************************/
732 .................... void usb_disable_endpoints(void); 732 .................... void usb_disable_endpoints(void);
733 .................... 733 ....................
734 .................... 734 ....................
735 .................... /******************************************************************************* 735 .................... /*******************************************************************************
736 .................... /* usb_disable_endpoint() 736 .................... /* usb_disable_endpoint()
737 .................... /* 737 .................... /*
738 .................... /* Input: Endpoint to disable (0..15) 738 .................... /* Input: Endpoint to disable (0..15)
739 .................... /* 739 .................... /*
740 .................... /* Summary: Disables specified endpoint 740 .................... /* Summary: Disables specified endpoint
741 .................... /* 741 .................... /*
742 .................... /********************************************************************************/ 742 .................... /********************************************************************************/
743 .................... void usb_disable_endpoint(int8 en); 743 .................... void usb_disable_endpoint(int8 en);
744 .................... 744 ....................
745 .................... /************************************************************** 745 .................... /**************************************************************
746 .................... /* usb_request_send_response(len) 746 .................... /* usb_request_send_response(len)
747 .................... /* usb_request_get_data() 747 .................... /* usb_request_get_data()
748 .................... /* usb_request_stall() 748 .................... /* usb_request_stall()
749 .................... /* 749 .................... /*
750 .................... /* Input: len - size of packet to send 750 .................... /* Input: len - size of packet to send
751 .................... /* 751 .................... /*
752 .................... /* Summary: One of these 3 functions will be called by the USB stack after 752 .................... /* Summary: One of these 3 functions will be called by the USB stack after
753 .................... /* handling a SETUP packet. 753 .................... /* handling a SETUP packet.
754 .................... /* 754 .................... /*
755 .................... /* After we process a SETUP request, we have 1 of three responses: 755 .................... /* After we process a SETUP request, we have 1 of three responses:
756 .................... /* 1.) send a response IN packet 756 .................... /* 1.) send a response IN packet
757 .................... /* 2.) wait for followup OUT packet(s) with data 757 .................... /* 2.) wait for followup OUT packet(s) with data
758 .................... /* 3.) stall because we don't support that SETUP request 758 .................... /* 3.) stall because we don't support that SETUP request
759 .................... /* 759 .................... /*
760 .................... /* If we are sending data, the array usb_ep0_tx_buffer[] will hold 760 .................... /* If we are sending data, the array usb_ep0_tx_buffer[] will hold
761 .................... /* the response and the USB Request handler code will call 761 .................... /* the response and the USB Request handler code will call
762 .................... /* usb_request_send_response() to let us know how big the packet is. 762 .................... /* usb_request_send_response() to let us know how big the packet is.
763 .................... /* 763 .................... /*
764 .................... /* If we are waiting for more data, usb_request_get_data() will 764 .................... /* If we are waiting for more data, usb_request_get_data() will
765 .................... /* be called by the USB request handler code to configure the EP0 OUT 765 .................... /* be called by the USB request handler code to configure the EP0 OUT
766 .................... /* endpoint to be ready for more data 766 .................... /* endpoint to be ready for more data
767 .................... /* 767 .................... /*
768 .................... /* If we don't support a request, usb_request_stall() will be called 768 .................... /* If we don't support a request, usb_request_stall() will be called
769 .................... /* by the USB request handler code to stall the endpoint 0. 769 .................... /* by the USB request handler code to stall the endpoint 0.
770 .................... /* 770 .................... /*
771 .................... /* The operation of these functions depends on how SETUP packets 771 .................... /* The operation of these functions depends on how SETUP packets
772 .................... /* are handled in the hardware layer. 772 .................... /* are handled in the hardware layer.
773 .................... /* 773 .................... /*
774 .................... /***************************************************************/ 774 .................... /***************************************************************/
775 .................... void usb_request_send_response(unsigned int8 len); 775 .................... void usb_request_send_response(unsigned int8 len);
776 .................... void usb_request_get_data(void); 776 .................... void usb_request_get_data(void);
777 .................... void usb_request_stall(void); 777 .................... void usb_request_stall(void);
778 .................... 778 ....................
779 .................... 779 ....................
780 .................... #endif 780 .................... #endif
781 .................... 781 ....................
782 .................... 782 ....................
783 .................... //////////////////////// EXTRA USER FUNCTIONS ///////////////////////////////// 783 .................... //////////////////////// EXTRA USER FUNCTIONS /////////////////////////////////
784 .................... 784 ....................
785 .................... /************************************************************** 785 .................... /**************************************************************
786 .................... /* usb_flush_in() 786 .................... /* usb_flush_in()
787 .................... /* 787 .................... /*
788 .................... /* Input: endpoint - which endpoint to mark for transfer 788 .................... /* Input: endpoint - which endpoint to mark for transfer
789 .................... /* len - length of data that is being tramsferred 789 .................... /* len - length of data that is being tramsferred
790 .................... /* tgl - Data toggle synchronization for this packet 790 .................... /* tgl - Data toggle synchronization for this packet
791 .................... /* 791 .................... /*
792 .................... /* Output: TRUE if success, FALSE if error (we don't control the endpoint) 792 .................... /* Output: TRUE if success, FALSE if error (we don't control the endpoint)
793 .................... /* 793 .................... /*
794 .................... /* Summary: Marks the endpoint ready for transmission. You must 794 .................... /* Summary: Marks the endpoint ready for transmission. You must
795 .................... /* have already loaded the endpoint buffer with data. 795 .................... /* have already loaded the endpoint buffer with data.
796 .................... /* (IN is PIC -> PC). 796 .................... /* (IN is PIC -> PC).
797 .................... /* This routine is useful if you want to setup an endpoint by 797 .................... /* This routine is useful if you want to setup an endpoint by
798 .................... /* writing to the buffer directly. 798 .................... /* writing to the buffer directly.
799 .................... /* This routine is not necessary if you use usb_put_packet(). 799 .................... /* This routine is not necessary if you use usb_put_packet().
800 .................... /***************************************************************/ 800 .................... /***************************************************************/
801 .................... int1 usb_flush_in(int8 endpoint, int16 len, USB_DTS_BIT tgl); 801 .................... int1 usb_flush_in(int8 endpoint, int16 len, USB_DTS_BIT tgl);
802 .................... 802 ....................
803 .................... /************************************************************** 803 .................... /**************************************************************
804 .................... /* usb_flush_out() 804 .................... /* usb_flush_out()
805 .................... /* 805 .................... /*
806 .................... /* Input: endpoint - which endpoint to mark for release 806 .................... /* Input: endpoint - which endpoint to mark for release
807 .................... /* tgl - Data toggle synchronization to expect in the next packet 807 .................... /* tgl - Data toggle synchronization to expect in the next packet
808 .................... /* 808 .................... /*
809 .................... /* Output: NONE 809 .................... /* Output: NONE
810 .................... /* 810 .................... /*
811 .................... /* Summary: Clears the previously received packet, and then marks this 811 .................... /* Summary: Clears the previously received packet, and then marks this
812 .................... /* endpoint's receive buffer as ready for more data. 812 .................... /* endpoint's receive buffer as ready for more data.
813 .................... /* (OUT is PC -> PIC). This routine is useful if you do not 813 .................... /* (OUT is PC -> PIC). This routine is useful if you do not
814 .................... /* want to use usb_get_packet(), instead you want to handle with 814 .................... /* want to use usb_get_packet(), instead you want to handle with
815 .................... /* the endpoint buffer directly. Also see usb_rx_packet_size(). 815 .................... /* the endpoint buffer directly. Also see usb_rx_packet_size().
816 .................... /* This routine is not necessary if you use usb_get_packet(). 816 .................... /* This routine is not necessary if you use usb_get_packet().
817 .................... /***************************************************************/ 817 .................... /***************************************************************/
818 .................... void usb_flush_out(int8 endpoint, USB_DTS_BIT tgl); 818 .................... void usb_flush_out(int8 endpoint, USB_DTS_BIT tgl);
819 .................... 819 ....................
820 .................... /************************************************************** 820 .................... /**************************************************************
821 .................... /* usb_rx_packet_size() 821 .................... /* usb_rx_packet_size()
822 .................... /* 822 .................... /*
823 .................... /* Input: endpoint - which endpoint to mark to check 823 .................... /* Input: endpoint - which endpoint to mark to check
824 .................... /* 824 .................... /*
825 .................... /* Output: Returns the number of bytes in the endpoint's receive buffer. 825 .................... /* Output: Returns the number of bytes in the endpoint's receive buffer.
826 .................... /* 826 .................... /*
827 .................... /* Summary: Read the number of data stored in the receive buffer. When you 827 .................... /* Summary: Read the number of data stored in the receive buffer. When you
828 .................... /* have handled the data, use usb_flush_out() to clear the buffer. The 828 .................... /* have handled the data, use usb_flush_out() to clear the buffer. The
829 .................... /* result may be invalid if usb_kbhit() returns false for this endpoint. 829 .................... /* result may be invalid if usb_kbhit() returns false for this endpoint.
830 .................... /* This routine is not necessary if you use usb_get_packet(). 830 .................... /* This routine is not necessary if you use usb_get_packet().
831 .................... /***************************************************************/ 831 .................... /***************************************************************/
832 .................... int16 usb_rx_packet_size(int8 endpoint); 832 .................... int16 usb_rx_packet_size(int8 endpoint);
833 .................... 833 ....................
834 .................... #ENDIF 834 .................... #ENDIF
835 .................... 835 ....................
836 .................... #else 836 .................... #else
837 .................... #include <pic24_usb.h> //Microchip 18Fxx5x hardware layer for usb.c 837 .................... #include <pic24_usb.h> //Microchip 18Fxx5x hardware layer for usb.c
838 .................... #endif 838 .................... #endif
839 .................... #else 839 .................... #else
840 .................... #include <usbn960x.h> 840 .................... #include <usbn960x.h>
841 .................... #endif 841 .................... #endif
842 .................... #include <usb_desc_cdc.h> //USB Configuration and Device descriptors for this UBS device 842 .................... #include <usb_desc_cdc.h> //USB Configuration and Device descriptors for this UBS device
843 .................... /////////////////////////////////////////////////////////////////////////// 843 .................... ///////////////////////////////////////////////////////////////////////////
844 .................... //// usb_desc_cdc.h //// 844 .................... //// usb_desc_cdc.h ////
845 .................... //// //// 845 .................... //// ////
846 .................... //// An example set of device / configuration descriptors for use with //// 846 .................... //// An example set of device / configuration descriptors for use with ////
847 .................... //// CCS's CDC Virtual COM Port driver (see usb_cdc.h) //// 847 .................... //// CCS's CDC Virtual COM Port driver (see usb_cdc.h) ////
848 .................... //// //// 848 .................... //// ////
849 .................... //// This file is part of CCS's PIC USB driver code. See USB.H //// 849 .................... //// This file is part of CCS's PIC USB driver code. See USB.H ////
850 .................... //// for more documentation and a list of examples. //// 850 .................... //// for more documentation and a list of examples. ////
851 .................... //// //// 851 .................... //// ////
852 .................... /////////////////////////////////////////////////////////////////////////// 852 .................... ///////////////////////////////////////////////////////////////////////////
853 .................... //// //// 853 .................... //// ////
854 .................... //// Version History: //// 854 .................... //// Version History: ////
855 .................... //// //// 855 .................... //// ////
856 .................... //// March 5th, 2009: //// 856 .................... //// March 5th, 2009: ////
857 .................... //// Cleanup for Wizard. //// 857 .................... //// Cleanup for Wizard. ////
858 .................... //// PIC24 Initial release. //// 858 .................... //// PIC24 Initial release. ////
859 .................... //// //// 859 .................... //// ////
860 .................... //// 10/28/05: //// 860 .................... //// 10/28/05: ////
861 .................... //// Bulk endpoint sizes updated to allow more than 255 byte //// 861 .................... //// Bulk endpoint sizes updated to allow more than 255 byte ////
862 .................... //// packets. //// 862 .................... //// packets. ////
863 .................... //// Changed device to USB 1.10 //// 863 .................... //// Changed device to USB 1.10 ////
864 .................... //// //// 864 .................... //// ////
865 .................... /////////////////////////////////////////////////////////////////////////// 865 .................... ///////////////////////////////////////////////////////////////////////////
866 .................... //// (C) Copyright 1996,2005 Custom Computer Services //// 866 .................... //// (C) Copyright 1996,2005 Custom Computer Services ////
867 .................... //// This source code may only be used by licensed users of the CCS //// 867 .................... //// This source code may only be used by licensed users of the CCS ////
868 .................... //// C compiler. This source code may only be distributed to other //// 868 .................... //// C compiler. This source code may only be distributed to other ////
869 .................... //// licensed users of the CCS C compiler. No other use, //// 869 .................... //// licensed users of the CCS C compiler. No other use, ////
870 .................... //// reproduction or distribution is permitted without written //// 870 .................... //// reproduction or distribution is permitted without written ////
871 .................... //// permission. Derivative programs created using this software //// 871 .................... //// permission. Derivative programs created using this software ////
872 .................... //// in object code form are not restricted in any way. //// 872 .................... //// in object code form are not restricted in any way. ////
873 .................... /////////////////////////////////////////////////////////////////////////// 873 .................... ///////////////////////////////////////////////////////////////////////////
874 .................... 874 ....................
875 .................... #IFNDEF __USB_DESCRIPTORS__ 875 .................... #IFNDEF __USB_DESCRIPTORS__
876 .................... #DEFINE __USB_DESCRIPTORS__ 876 .................... #DEFINE __USB_DESCRIPTORS__
877 .................... 877 ....................
878 .................... ///////// config options, although it's best to leave alone for this demo ///// 878 .................... ///////// config options, although it's best to leave alone for this demo /////
879 .................... #define USB_CONFIG_PID 0x0033 879 .................... #define USB_CONFIG_PID 0x0033
880 .................... #define USB_CONFIG_VID 0x0461 880 .................... #define USB_CONFIG_VID 0x0461
881 .................... #define USB_CONFIG_BUS_POWER 100 //100mA (range is 0..500) 881 .................... #define USB_CONFIG_BUS_POWER 100 //100mA (range is 0..500)
882 .................... #define USB_CONFIG_VERSION 0x0100 //01.00 //range is 00.00 to 99.99 882 .................... #define USB_CONFIG_VERSION 0x0100 //01.00 //range is 00.00 to 99.99
883 .................... //////// end config /////////////////////////////////////////////////////////// 883 .................... //////// end config ///////////////////////////////////////////////////////////
884 .................... 884 ....................
885 .................... #DEFINE USB_HID_DEVICE FALSE 885 .................... #DEFINE USB_HID_DEVICE FALSE
886 .................... #DEFINE USB_CDC_DEVICE TRUE 886 .................... #DEFINE USB_CDC_DEVICE TRUE
887 .................... 887 ....................
888 .................... #define USB_CDC_COMM_IN_ENDPOINT 1 888 .................... #define USB_CDC_COMM_IN_ENDPOINT 1
889 .................... #define USB_CDC_COMM_IN_SIZE 8 889 .................... #define USB_CDC_COMM_IN_SIZE 8
890 .................... #define USB_EP1_TX_ENABLE USB_ENABLE_INTERRUPT 890 .................... #define USB_EP1_TX_ENABLE USB_ENABLE_INTERRUPT
891 .................... #define USB_EP1_TX_SIZE USB_CDC_COMM_IN_SIZE 891 .................... #define USB_EP1_TX_SIZE USB_CDC_COMM_IN_SIZE
892 .................... 892 ....................
893 .................... //pic to pc endpoint config 893 .................... //pic to pc endpoint config
894 .................... #define USB_CDC_DATA_IN_ENDPOINT 2 894 .................... #define USB_CDC_DATA_IN_ENDPOINT 2
895 .................... #define USB_CDC_DATA_IN_SIZE 64 895 .................... #define USB_CDC_DATA_IN_SIZE 64
896 .................... #define USB_EP2_TX_ENABLE USB_ENABLE_BULK 896 .................... #define USB_EP2_TX_ENABLE USB_ENABLE_BULK
897 .................... #define USB_EP2_TX_SIZE USB_CDC_DATA_IN_SIZE 897 .................... #define USB_EP2_TX_SIZE USB_CDC_DATA_IN_SIZE
898 .................... 898 ....................
899 .................... //pc to pic endpoint config 899 .................... //pc to pic endpoint config
900 .................... #define USB_CDC_DATA_OUT_ENDPOINT 2 900 .................... #define USB_CDC_DATA_OUT_ENDPOINT 2
901 .................... #define USB_CDC_DATA_OUT_SIZE 64 901 .................... #define USB_CDC_DATA_OUT_SIZE 64
902 .................... #define USB_EP2_RX_ENABLE USB_ENABLE_BULK 902 .................... #define USB_EP2_RX_ENABLE USB_ENABLE_BULK
903 .................... #define USB_EP2_RX_SIZE USB_CDC_DATA_OUT_SIZE 903 .................... #define USB_EP2_RX_SIZE USB_CDC_DATA_OUT_SIZE
904 .................... 904 ....................
905 .................... #include <usb.h> 905 .................... #include <usb.h>
906 .................... /////////////////////////////////////////////////////////////////////////// 906 .................... ///////////////////////////////////////////////////////////////////////////
907 .................... //// usb.h //// 907 .................... //// usb.h ////
908 .................... //// //// 908 .................... //// ////
909 .................... //// Function protypes, defintions and globals used by CCS USB driver //// 909 .................... //// Function protypes, defintions and globals used by CCS USB driver ////
910 .................... //// //// 910 .................... //// ////
911 .................... //// This file is part of CCS's USB driver code //// 911 .................... //// This file is part of CCS's USB driver code ////
912 .................... //// //// 912 .................... //// ////
913 .................... //// The following USB examples are provided by CCS: //// 913 .................... //// The following USB examples are provided by CCS: ////
914 .................... //// ex_usb_mouse.c - A HID Mouse. //// 914 .................... //// ex_usb_mouse.c - A HID Mouse. ////
915 .................... //// ex_usb_hid.c - A custom application using HID protocol. //// 915 .................... //// ex_usb_hid.c - A custom application using HID protocol. ////
916 .................... //// ex_usb_kbmouse.c - A HID Mouse/Keyboard combo using multiple //// 916 .................... //// ex_usb_kbmouse.c - A HID Mouse/Keyboard combo using multiple ////
917 .................... //// interfaces. //// 917 .................... //// interfaces. ////
918 .................... //// ex_usb_kbmouse2.c - A HID Mouse/Keyboard combo using multiple //// 918 .................... //// ex_usb_kbmouse2.c - A HID Mouse/Keyboard combo using multiple ////
919 .................... //// HID Reports. //// 919 .................... //// HID Reports. ////
920 .................... //// ex_usb_scope.c - A digital oscilloscope using a custom //// 920 .................... //// ex_usb_scope.c - A digital oscilloscope using a custom ////
921 .................... //// protocol requiring custom Windows drivers. //// 921 .................... //// protocol requiring custom Windows drivers. ////
922 .................... //// ex_usb_serial.c - //// 922 .................... //// ex_usb_serial.c - ////
923 .................... //// ex_usb_serial2.c - Two examples of using the CDC driver for //// 923 .................... //// ex_usb_serial2.c - Two examples of using the CDC driver for ////
924 .................... //// a virtual COM port. //// 924 .................... //// a virtual COM port. ////
925 .................... //// ex_usb_bootloader.c - CDC/Virtual COM port bootloader. //// 925 .................... //// ex_usb_bootloader.c - CDC/Virtual COM port bootloader. ////
926 .................... //// ex_usb_loadmouse.c - A conversion of ex_usb_mouse.c that is //// 926 .................... //// ex_usb_loadmouse.c - A conversion of ex_usb_mouse.c that is ////
927 .................... //// compatible with ex_usb_mouse.c. //// 927 .................... //// compatible with ex_usb_mouse.c. ////
928 .................... //// //// 928 .................... //// ////
929 .................... //// ********************** API ********************* //// 929 .................... //// ********************** API ********************* ////
930 .................... //// //// 930 .................... //// ////
931 .................... //// These are the functions that are meant to be called by the user: //// 931 .................... //// These are the functions that are meant to be called by the user: ////
932 .................... //// //// 932 .................... //// ////
933 .................... //// usb_init() - Initializes the USB stack, the USB peripheral and //// 933 .................... //// usb_init() - Initializes the USB stack, the USB peripheral and ////
934 .................... //// attaches the unit to the usb bus. Enables //// 934 .................... //// attaches the unit to the usb bus. Enables ////
935 .................... //// interrupts. Will wait in an infinite loop until //// 935 .................... //// interrupts. Will wait in an infinite loop until ////
936 .................... //// the device enumerates - if you are using //// 936 .................... //// the device enumerates - if you are using ////
937 .................... //// connection sense or if the processor should run //// 937 .................... //// connection sense or if the processor should run ////
938 .................... //// even if it's not connected to USB then use //// 938 .................... //// even if it's not connected to USB then use ////
939 .................... //// usb_init_cs() instead. //// 939 .................... //// usb_init_cs() instead. ////
940 .................... //// //// 940 .................... //// ////
941 .................... //// usb_init_cs() - A smaller usb_init(), does not attach unit //// 941 .................... //// usb_init_cs() - A smaller usb_init(), does not attach unit ////
942 .................... //// to usb bus or enable interrupts. Since this does //// 942 .................... //// to usb bus or enable interrupts. Since this does ////
943 .................... //// not attach to the USB, you must periodically call //// 943 .................... //// not attach to the USB, you must periodically call ////
944 .................... //// usb_task(). See usb_task() for more information. //// 944 .................... //// usb_task(). See usb_task() for more information. ////
945 .................... //// //// 945 .................... //// ////
946 .................... //// usb_task() - If usb_init_cs() was used to initiate the USB //// 946 .................... //// usb_task() - If usb_init_cs() was used to initiate the USB ////
947 .................... //// peripheral, usb_task() should then be called periodically //// 947 .................... //// peripheral, usb_task() should then be called periodically ////
948 .................... //// to check the connection sense pin. If the connection //// 948 .................... //// to check the connection sense pin. If the connection ////
949 .................... //// sense pin denotes USB is connected and the USB peripheral //// 949 .................... //// sense pin denotes USB is connected and the USB peripheral ////
950 .................... //// is not attached, this will attach the USB peripheral //// 950 .................... //// is not attached, this will attach the USB peripheral ////
951 .................... //// so the PC can start the enumeration process (and it //// 951 .................... //// so the PC can start the enumeration process (and it ////
952 .................... //// will enable interrupts). If the connection sense pin //// 952 .................... //// will enable interrupts). If the connection sense pin ////
953 .................... //// denotes USB is not attached and the USB peripheral is //// 953 .................... //// denotes USB is not attached and the USB peripheral is ////
954 .................... //// running, this will reset the USB peripheral and wait //// 954 .................... //// running, this will reset the USB peripheral and wait ////
955 .................... //// for USB to reconnect (and usb_enumerated() will start //// 955 .................... //// for USB to reconnect (and usb_enumerated() will start ////
956 .................... //// returning FALSE). If connection sense (USB_CON_SENSE_PIN) //// 956 .................... //// returning FALSE). If connection sense (USB_CON_SENSE_PIN) ////
957 .................... //// is not defined the usb_task() assumes that USB is always //// 957 .................... //// is not defined the usb_task() assumes that USB is always ////
958 .................... //// connected. //// 958 .................... //// connected. ////
959 .................... //// //// 959 .................... //// ////
960 .................... //// usb_attached() - Returns TRUE if the device is attached to a //// 960 .................... //// usb_attached() - Returns TRUE if the device is attached to a ////
961 .................... //// USB cable. A macro that looks at the defined //// 961 .................... //// USB cable. A macro that looks at the defined ////
962 .................... //// connection sense pin. If this returns TRUE //// 962 .................... //// connection sense pin. If this returns TRUE ////
963 .................... //// it does not mean the PC has connected to it, //// 963 .................... //// it does not mean the PC has connected to it, ////
964 .................... //// you need to use usb_enumerated() to check this. //// 964 .................... //// you need to use usb_enumerated() to check this. ////
965 .................... //// //// 965 .................... //// ////
966 .................... //// usb_enumerated() - Returns TRUE if device has been enumerated //// 966 .................... //// usb_enumerated() - Returns TRUE if device has been enumerated ////
967 .................... //// (configured) by host, FALSE if it has not. //// 967 .................... //// (configured) by host, FALSE if it has not. ////
968 .................... //// Do not try to use the USB peripheral for //// 968 .................... //// Do not try to use the USB peripheral for ////
969 .................... //// sending and receiving packets until you //// 969 .................... //// sending and receiving packets until you ////
970 .................... //// are enumerated. //// 970 .................... //// are enumerated. ////
971 .................... //// //// 971 .................... //// ////
972 .................... //// usb_wait_for_enumeration() - Sits in an infinte loop until device //// 972 .................... //// usb_wait_for_enumeration() - Sits in an infinte loop until device ////
973 .................... //// is enumerated. //// 973 .................... //// is enumerated. ////
974 .................... //// //// 974 .................... //// ////
975 .................... //// usb_tbe(endpoint) - Returns TRUE if the endpoint transmit buffer //// 975 .................... //// usb_tbe(endpoint) - Returns TRUE if the endpoint transmit buffer ////
976 .................... //// is free and ready to accept a new packet for transmission. //// 976 .................... //// is free and ready to accept a new packet for transmission. ////
977 .................... //// //// 977 .................... //// ////
978 .................... //// usb_put_packet(endpoint, ptr, len, tgl) - Sends one packet to the //// 978 .................... //// usb_put_packet(endpoint, ptr, len, tgl) - Sends one packet to the ////
979 .................... //// host. If you need to send a message that //// 979 .................... //// host. If you need to send a message that ////
980 .................... //// spans more than one packet then use //// 980 .................... //// spans more than one packet then use ////
981 .................... //// usb_puts(). Fore more detailed documentation //// 981 .................... //// usb_puts(). Fore more detailed documentation ////
982 .................... //// see usb_hw_layer.h //// 982 .................... //// see usb_hw_layer.h ////
983 .................... //// //// 983 .................... //// ////
984 .................... //// usb_puts(endpoint, ptr, len, timeout) - Sends a multiple packet //// 984 .................... //// usb_puts(endpoint, ptr, len, timeout) - Sends a multiple packet ////
985 .................... //// message to the host. If you only need to send one packet, //// 985 .................... //// message to the host. If you only need to send one packet, ////
986 .................... //// it is more effecient to use usb_put_packet(). This is //// 986 .................... //// it is more effecient to use usb_put_packet(). This is ////
987 .................... //// documented in more detail above the prototype in USB.H. //// 987 .................... //// documented in more detail above the prototype in USB.H. ////
988 .................... //// //// 988 .................... //// ////
989 .................... //// usb_kbhit(endpoint) - Returns true if OUT endpoint contains data //// 989 .................... //// usb_kbhit(endpoint) - Returns true if OUT endpoint contains data ////
990 .................... //// from host. This will remain TRUE until //// 990 .................... //// from host. This will remain TRUE until ////
991 .................... //// usb_put_packet() or usb_flush_out() used. //// 991 .................... //// usb_put_packet() or usb_flush_out() used. ////
992 .................... //// This function will return an invalid response //// 992 .................... //// This function will return an invalid response ////
993 .................... //// if specified endpoint is not enabled for //// 993 .................... //// if specified endpoint is not enabled for ////
994 .................... //// receiving data. //// 994 .................... //// receiving data. ////
995 .................... //// //// 995 .................... //// ////
996 .................... //// len = usb_get_packet(endpoint, ptr, max) - Gets one packet that //// 996 .................... //// len = usb_get_packet(endpoint, ptr, max) - Gets one packet that ////
997 .................... //// from the host/PC. usb_kbhit() must return TRUE before you //// 997 .................... //// from the host/PC. usb_kbhit() must return TRUE before you ////
998 .................... //// call this routine or your data may not be valid. This //// 998 .................... //// call this routine or your data may not be valid. This ////
999 .................... //// only receives one packet, if you are trying to receive a //// 999 .................... //// only receives one packet, if you are trying to receive a ////
1000 .................... //// multi-packet message use usb_gets(). For more detailed //// 1000 .................... //// multi-packet message use usb_gets(). For more detailed ////
1001 .................... //// documentation see usb_hw_layer.h. //// 1001 .................... //// documentation see usb_hw_layer.h. ////
1002 .................... //// //// 1002 .................... //// ////
1003 .................... //// len = usb_gets(endpoint, ptr, max, timeout) - Gets multiple //// 1003 .................... //// len = usb_gets(endpoint, ptr, max, timeout) - Gets multiple ////
1004 .................... //// packets from the host, you would use this instead //// 1004 .................... //// packets from the host, you would use this instead ////
1005 .................... //// of usb_get_packet() if you wanted to handle multi-packet //// 1005 .................... //// of usb_get_packet() if you wanted to handle multi-packet ////
1006 .................... //// messages. This is documented in more detail above the //// 1006 .................... //// messages. This is documented in more detail above the ////
1007 .................... //// prototype in USB.H. //// 1007 .................... //// prototype in USB.H. ////
1008 .................... //// //// 1008 .................... //// ////
1009 .................... //// //// 1009 .................... //// ////
1010 .................... //// ********* DEFINITIONS / CONFIGURATION ********** //// 1010 .................... //// ********* DEFINITIONS / CONFIGURATION ********** ////
1011 .................... //// //// 1011 .................... //// ////
1012 .................... //// The following definitions are declared here, but can be //// 1012 .................... //// The following definitions are declared here, but can be ////
1013 .................... //// overwritten in your code. Unless needed otherwise, leave //// 1013 .................... //// overwritten in your code. Unless needed otherwise, leave ////
1014 .................... //// to default value. If confused about a definition read the //// 1014 .................... //// to default value. If confused about a definition read the ////
1015 .................... //// comments at each defintion //// 1015 .................... //// comments at each defintion ////
1016 .................... //// //// 1016 .................... //// ////
1017 .................... //// USB_HID_IDLE (TRUE) - Set to TRUE if your device supports //// 1017 .................... //// USB_HID_IDLE (TRUE) - Set to TRUE if your device supports ////
1018 .................... //// Set_Idle HID class request. Set to //// 1018 .................... //// Set_Idle HID class request. Set to ////
1019 .................... //// False if you do not (device will //// 1019 .................... //// False if you do not (device will ////
1020 .................... //// send a Wrong-state if computer //// 1020 .................... //// send a Wrong-state if computer ////
1021 .................... //// sends a Set_Idle / Get_Idle command) //// 1021 .................... //// sends a Set_Idle / Get_Idle command) ////
1022 .................... //// NOTE: If you set to TRUE you must //// 1022 .................... //// NOTE: If you set to TRUE you must ////
1023 .................... //// provide your own code. See //// 1023 .................... //// provide your own code. See ////
1024 .................... //// usb_isr_tkn_setup_ClassInterface() in //// 1024 .................... //// usb_isr_tkn_setup_ClassInterface() in ////
1025 .................... //// usb.c //// 1025 .................... //// usb.c ////
1026 .................... //// //// 1026 .................... //// ////
1027 .................... //// USB_HID_BOOT_PROTOCOL (FALSE) - Set to TRUE if your device supports //// 1027 .................... //// USB_HID_BOOT_PROTOCOL (FALSE) - Set to TRUE if your device supports ////
1028 .................... //// Set_Protocl HID class request. Set to //// 1028 .................... //// Set_Protocl HID class request. Set to ////
1029 .................... //// False if you do not (device will //// 1029 .................... //// False if you do not (device will ////
1030 .................... //// send a Wrong-state if computer //// 1030 .................... //// send a Wrong-state if computer ////
1031 .................... //// sends a Set_Protocl / Get_Protocol //// 1031 .................... //// sends a Set_Protocl / Get_Protocol ////
1032 .................... //// command). //// 1032 .................... //// command). ////
1033 .................... //// NOTE: If you set to TRUE you must //// 1033 .................... //// NOTE: If you set to TRUE you must ////
1034 .................... //// provide your own code in the //// 1034 .................... //// provide your own code in the ////
1035 .................... //// application that properly send boot //// 1035 .................... //// application that properly send boot ////
1036 .................... //// or HID packets. //// 1036 .................... //// or HID packets. ////
1037 .................... //// //// 1037 .................... //// ////
1038 .................... //// USB_MAX_EP0_PACKET_LENGTH (8) - Max Packet size for Endpoint 0. //// 1038 .................... //// USB_MAX_EP0_PACKET_LENGTH (8) - Max Packet size for Endpoint 0. ////
1039 .................... //// The hardware level driver (ex //// 1039 .................... //// The hardware level driver (ex ////
1040 .................... //// pic18_usb.h will define this value if //// 1040 .................... //// pic18_usb.h will define this value if ////
1041 .................... //// not already overwritten). Increasing //// 1041 .................... //// not already overwritten). Increasing ////
1042 .................... //// this size will speed up the //// 1042 .................... //// this size will speed up the ////
1043 .................... //// enumeration process. //// 1043 .................... //// enumeration process. ////
1044 .................... //// //// 1044 .................... //// ////
1045 .................... //// USB_EPx_RX_ENABLE (USB_ENABLE_DISABLED) - Where x is the //// 1045 .................... //// USB_EPx_RX_ENABLE (USB_ENABLE_DISABLED) - Where x is the ////
1046 .................... //// endpoint number. Change this define //// 1046 .................... //// endpoint number. Change this define ////
1047 .................... //// to specify what kind of transfer method //// 1047 .................... //// to specify what kind of transfer method ////
1048 .................... //// this RX (PC to device) endpoint uses. //// 1048 .................... //// this RX (PC to device) endpoint uses. ////
1049 .................... //// Here is the list of valid transfer methods: //// 1049 .................... //// Here is the list of valid transfer methods: ////
1050 .................... //// USB_ENABLE_CONTROL //// 1050 .................... //// USB_ENABLE_CONTROL ////
1051 .................... //// USB_ENABLE_ISOCHRONOUS //// 1051 .................... //// USB_ENABLE_ISOCHRONOUS ////
1052 .................... //// USB_ENABLE_BULK //// 1052 .................... //// USB_ENABLE_BULK ////
1053 .................... //// USB_ENABLE_INTERRUPT //// 1053 .................... //// USB_ENABLE_INTERRUPT ////
1054 .................... //// USB_ENABLE_DISABLED //// 1054 .................... //// USB_ENABLE_DISABLED ////
1055 .................... //// Don't forget that you must specify the //// 1055 .................... //// Don't forget that you must specify the ////
1056 .................... //// transfer method properly in your endpoint //// 1056 .................... //// transfer method properly in your endpoint ////
1057 .................... //// descriptor, too. //// 1057 .................... //// descriptor, too. ////
1058 .................... //// //// 1058 .................... //// ////
1059 .................... //// USB_EPx_RX_SIZE (0) - For some hardware it is important to know //// 1059 .................... //// USB_EPx_RX_SIZE (0) - For some hardware it is important to know ////
1060 .................... //// how much memory to reserve for receiving //// 1060 .................... //// how much memory to reserve for receiving ////
1061 .................... //// packets. //// 1061 .................... //// packets. ////
1062 .................... //// //// 1062 .................... //// ////
1063 .................... //// *** NOTE *** You must have both USB_EPx_RX_ENABLE defined and //// 1063 .................... //// *** NOTE *** You must have both USB_EPx_RX_ENABLE defined and ////
1064 .................... //// USB_EPx_RX_SIZE defined (non 0) to enable a RX //// 1064 .................... //// USB_EPx_RX_SIZE defined (non 0) to enable a RX ////
1065 .................... //// endpoint. //// 1065 .................... //// endpoint. ////
1066 .................... //// *** NOTE *** Endpoint 0 is always enabled. //// 1066 .................... //// *** NOTE *** Endpoint 0 is always enabled. ////
1067 .................... //// //// 1067 .................... //// ////
1068 .................... //// USB_EPx_TX_ENABLE (USB_ENABLE_DISABLED) - Where x is the //// 1068 .................... //// USB_EPx_TX_ENABLE (USB_ENABLE_DISABLED) - Where x is the ////
1069 .................... //// endpoint number. Change this define //// 1069 .................... //// endpoint number. Change this define ////
1070 .................... //// to specify what kind of transfer method //// 1070 .................... //// to specify what kind of transfer method ////
1071 .................... //// this TX (device to PC) endpoint uses. //// 1071 .................... //// this TX (device to PC) endpoint uses. ////
1072 .................... //// Here is the list of valid transfer methods: //// 1072 .................... //// Here is the list of valid transfer methods: ////
1073 .................... //// USB_ENABLE_CONTROL //// 1073 .................... //// USB_ENABLE_CONTROL ////
1074 .................... //// USB_ENABLE_ISOCHRONOUS //// 1074 .................... //// USB_ENABLE_ISOCHRONOUS ////
1075 .................... //// USB_ENABLE_BULK //// 1075 .................... //// USB_ENABLE_BULK ////
1076 .................... //// USB_ENABLE_INTERRUPT //// 1076 .................... //// USB_ENABLE_INTERRUPT ////
1077 .................... //// USB_ENABLE_DISABLED //// 1077 .................... //// USB_ENABLE_DISABLED ////
1078 .................... //// Don't forget that you must specify the //// 1078 .................... //// Don't forget that you must specify the ////
1079 .................... //// transfer method properly in your endpoint //// 1079 .................... //// transfer method properly in your endpoint ////
1080 .................... //// descriptor, too. //// 1080 .................... //// descriptor, too. ////
1081 .................... //// //// 1081 .................... //// ////
1082 .................... //// USB_EPx_TX_SIZE (0) - For some hardware it is important to know //// 1082 .................... //// USB_EPx_TX_SIZE (0) - For some hardware it is important to know ////
1083 .................... //// how much memory to reserve for transmitting //// 1083 .................... //// how much memory to reserve for transmitting ////
1084 .................... //// packets. //// 1084 .................... //// packets. ////
1085 .................... //// //// 1085 .................... //// ////
1086 .................... //// *** NOTE *** You must have both USB_EPx_TX_ENABLE defined and //// 1086 .................... //// *** NOTE *** You must have both USB_EPx_TX_ENABLE defined and ////
1087 .................... //// USB_EPx_TX_SIZE defined (non 0) to enable a TX //// 1087 .................... //// USB_EPx_TX_SIZE defined (non 0) to enable a TX ////
1088 .................... //// endpoint. //// 1088 .................... //// endpoint. ////
1089 .................... //// //// 1089 .................... //// ////
1090 .................... //// //// 1090 .................... //// ////
1091 .................... //// USB_HID_DEVICE (TRUE) - HID devices require extra code to handle //// 1091 .................... //// USB_HID_DEVICE (TRUE) - HID devices require extra code to handle ////
1092 .................... //// HID requests. You can disable to save //// 1092 .................... //// HID requests. You can disable to save ////
1093 .................... //// ROM space if you are not using a HID //// 1093 .................... //// ROM space if you are not using a HID ////
1094 .................... //// device. If you are not using a HID //// 1094 .................... //// device. If you are not using a HID ////
1095 .................... //// device you must provide your own O/S //// 1095 .................... //// device you must provide your own O/S ////
1096 .................... //// (Windows) driver. //// 1096 .................... //// (Windows) driver. ////
1097 .................... //// //// 1097 .................... //// ////
1098 .................... //// The other definitions should not be changed. //// 1098 .................... //// The other definitions should not be changed. ////
1099 .................... //// //// 1099 .................... //// ////
1100 .................... /////////////////////////////////////////////////////////////////////////// 1100 .................... ///////////////////////////////////////////////////////////////////////////
1101 .................... //// //// 1101 .................... //// ////
1102 .................... //// Version History: //// 1102 .................... //// Version History: ////
1103 .................... //// //// 1103 .................... //// ////
1104 .................... //// March 5th, 2009: //// 1104 .................... //// March 5th, 2009: ////
1105 .................... //// Cleanup for Wizard. //// 1105 .................... //// Cleanup for Wizard. ////
1106 .................... //// PIC24 Initial release. //// 1106 .................... //// PIC24 Initial release. ////
1107 .................... //// //// 1107 .................... //// ////
1108 .................... //// July 13th, 2005: //// 1108 .................... //// July 13th, 2005: ////
1109 .................... //// usb_ep_tx_size[] and usb_ep_rx_size[] changed to 16bits //// 1109 .................... //// usb_ep_tx_size[] and usb_ep_rx_size[] changed to 16bits ////
1110 .................... //// //// 1110 .................... //// ////
1111 .................... //// June 20th, 2005: //// 1111 .................... //// June 20th, 2005: ////
1112 .................... //// Initial 18fxx5x release //// 1112 .................... //// Initial 18fxx5x release ////
1113 .................... //// //// 1113 .................... //// ////
1114 .................... //// May 13th, 2005: //// 1114 .................... //// May 13th, 2005: ////
1115 .................... //// Beta release, only works with 18Fxx5x hardware layer. //// 1115 .................... //// Beta release, only works with 18Fxx5x hardware layer. ////
1116 .................... //// Now supports multiple interfaces (many defines in descriptors //// 1116 .................... //// Now supports multiple interfaces (many defines in descriptors ////
1117 .................... //// will have to be changed, see examples) //// 1117 .................... //// will have to be changed, see examples) ////
1118 .................... //// //// 1118 .................... //// ////
1119 .................... //// Mar 21st, 2005: //// 1119 .................... //// Mar 21st, 2005: ////
1120 .................... //// Initial Alpha Release with PIC18Fxx5x support. (ONLY TESTED //// 1120 .................... //// Initial Alpha Release with PIC18Fxx5x support. (ONLY TESTED ////
1121 .................... //// WITH 18F4550) //// 1121 .................... //// WITH 18F4550) ////
1122 .................... //// usb_gets() and usb_puts() changed (see usb.c) //// 1122 .................... //// usb_gets() and usb_puts() changed (see usb.c) ////
1123 .................... //// //// 1123 .................... //// ////
1124 .................... //// June 24th, 2004: //// 1124 .................... //// June 24th, 2004: ////
1125 .................... //// Optimization and cleanup. //// 1125 .................... //// Optimization and cleanup. ////
1126 .................... //// The following definitions changed: //// 1126 .................... //// The following definitions changed: ////
1127 .................... //// USB_EPx_TX_ENABLE and USB_EPx_RX_ENABLE have changed. See usb.h //// 1127 .................... //// USB_EPx_TX_ENABLE and USB_EPx_RX_ENABLE have changed. See usb.h ////
1128 .................... //// USB_CONFIG_DESCRIPTORS[] removed //// 1128 .................... //// USB_CONFIG_DESCRIPTORS[] removed ////
1129 .................... //// USB_CONFIG_DESC_LEN changed to USB_DESC_CONFIG_LEN //// 1129 .................... //// USB_CONFIG_DESC_LEN changed to USB_DESC_CONFIG_LEN ////
1130 .................... //// USB_INTERFACE_DESC_LEN changed to USB_DESC_INTERFACE_LEN //// 1130 .................... //// USB_INTERFACE_DESC_LEN changed to USB_DESC_INTERFACE_LEN ////
1131 .................... //// USB_CLASS_DESC_LEN changed to USB_DESC_CLASS_LEN //// 1131 .................... //// USB_CLASS_DESC_LEN changed to USB_DESC_CLASS_LEN ////
1132 .................... //// USB_ENDPOINT_DESC_LEN changed to USB_DESC_ENDPOINT_LEN //// 1132 .................... //// USB_ENDPOINT_DESC_LEN changed to USB_DESC_ENDPOINT_LEN ////
1133 .................... //// USB_CONFIG_DESC_KEY changed to USB_DESC_CONFIG_TYPE //// 1133 .................... //// USB_CONFIG_DESC_KEY changed to USB_DESC_CONFIG_TYPE ////
1134 .................... //// USB_INTERFACE_DESC_KEY changed to USB_DESC_INTERFACE_TYPE //// 1134 .................... //// USB_INTERFACE_DESC_KEY changed to USB_DESC_INTERFACE_TYPE ////
1135 .................... //// USB_CLASS_DESC_KEY changed to USB_DESC_CLASS_TYPE //// 1135 .................... //// USB_CLASS_DESC_KEY changed to USB_DESC_CLASS_TYPE ////
1136 .................... //// USB_ENDPOINT_DESC_KEY changed to USB_DESC_ENDPOINT_TYPE //// 1136 .................... //// USB_ENDPOINT_DESC_KEY changed to USB_DESC_ENDPOINT_TYPE ////
1137 .................... //// USB_STRING_X[] arrays removed, see USB_STRING_DESC[] and //// 1137 .................... //// USB_STRING_X[] arrays removed, see USB_STRING_DESC[] and ////
1138 .................... //// USB_STRING_DESC_OFFSET[] //// 1138 .................... //// USB_STRING_DESC_OFFSET[] ////
1139 .................... //// dev_req, curr_config, status_device and getdesc_type global //// 1139 .................... //// dev_req, curr_config, status_device and getdesc_type global ////
1140 .................... //// variables moved into struct USB_stack_status //// 1140 .................... //// variables moved into struct USB_stack_status ////
1141 .................... //// //// 1141 .................... //// ////
1142 .................... //// October 15th, 2003: Support for boot protocol added. //// 1142 .................... //// October 15th, 2003: Support for boot protocol added. ////
1143 .................... //// Set USB_HID_BOOT_PROTOCOL to TRUE to support this. //// 1143 .................... //// Set USB_HID_BOOT_PROTOCOL to TRUE to support this. ////
1144 .................... //// The array hid_protocol[] saves which protocol mode each //// 1144 .................... //// The array hid_protocol[] saves which protocol mode each ////
1145 .................... //// interface is in. It is your applications job to send //// 1145 .................... //// interface is in. It is your applications job to send ////
1146 .................... //// data that either fit the boot protocol or HID protocol. //// 1146 .................... //// data that either fit the boot protocol or HID protocol. ////
1147 .................... //// //// 1147 .................... //// ////
1148 .................... //// May 6th, 2003: Fixed a potential stack overflow using PCM //// 1148 .................... //// May 6th, 2003: Fixed a potential stack overflow using PCM ////
1149 .................... //// //// 1149 .................... //// ////
1150 .................... //// October 29th, 2002: New definition added to USB_STATES //// 1150 .................... //// October 29th, 2002: New definition added to USB_STATES ////
1151 .................... //// //// 1151 .................... //// ////
1152 .................... //// August 2nd, 2002: Initial Public Release //// 1152 .................... //// August 2nd, 2002: Initial Public Release ////
1153 .................... //// //// 1153 .................... //// ////
1154 .................... /////////////////////////////////////////////////////////////////////////// 1154 .................... ///////////////////////////////////////////////////////////////////////////
1155 .................... //// (C) Copyright 1996,2009 Custom Computer Services //// 1155 .................... //// (C) Copyright 1996,2009 Custom Computer Services ////
1156 .................... //// This source code may only be used by licensed users of the CCS //// 1156 .................... //// This source code may only be used by licensed users of the CCS ////
1157 .................... //// C compiler. This source code may only be distributed to other //// 1157 .................... //// C compiler. This source code may only be distributed to other ////
1158 .................... //// licensed users of the CCS C compiler. No other use, //// 1158 .................... //// licensed users of the CCS C compiler. No other use, ////
1159 .................... //// reproduction or distribution is permitted without written //// 1159 .................... //// reproduction or distribution is permitted without written ////
1160 .................... //// permission. Derivative programs created using this software //// 1160 .................... //// permission. Derivative programs created using this software ////
1161 .................... //// in object code form are not restricted in any way. //// 1161 .................... //// in object code form are not restricted in any way. ////
1162 .................... /////////////////////////////////////////////////////////////////////////// 1162 .................... ///////////////////////////////////////////////////////////////////////////
1163 .................... 1163 ....................
1164 .................... #IFNDEF __USB_PROTOTYPES__ 1164 .................... #IFNDEF __USB_PROTOTYPES__
1165 .................... #DEFINE __USB_PROTOTYPES__ 1165 .................... #DEFINE __USB_PROTOTYPES__
1166 .................... 1166 ....................
1167 .................... //// CONFIGURATION //////////////////////////////////////////////////////////// 1167 .................... //// CONFIGURATION ////////////////////////////////////////////////////////////
1168 .................... 1168 ....................
1169 .................... #ifndef USB_CON_SENSE_PIN 1169 .................... #ifndef USB_CON_SENSE_PIN
1170 .................... #define USB_CON_SENSE_PIN 0 1170 .................... #define USB_CON_SENSE_PIN 0
1171 .................... #endif 1171 .................... #endif
1172 .................... 1172 ....................
1173 .................... #IFNDEF USB_HID_BOOT_PROTOCOL 1173 .................... #IFNDEF USB_HID_BOOT_PROTOCOL
1174 .................... #DEFINE USB_HID_BOOT_PROTOCOL FALSE 1174 .................... #DEFINE USB_HID_BOOT_PROTOCOL FALSE
1175 .................... #ENDIF 1175 .................... #ENDIF
1176 .................... 1176 ....................
1177 .................... #IFNDEF USB_HID_IDLE 1177 .................... #IFNDEF USB_HID_IDLE
1178 .................... #DEFINE USB_HID_IDLE FALSE 1178 .................... #DEFINE USB_HID_IDLE FALSE
1179 .................... #ENDIF 1179 .................... #ENDIF
1180 .................... 1180 ....................
1181 .................... //should the compiler add the extra HID handler code? Defaults to yes. 1181 .................... //should the compiler add the extra HID handler code? Defaults to yes.
1182 .................... #IFNDEF USB_HID_DEVICE 1182 .................... #IFNDEF USB_HID_DEVICE
1183 .................... #DEFINE USB_HID_DEVICE TRUE 1183 .................... #DEFINE USB_HID_DEVICE TRUE
1184 .................... #ENDIF 1184 .................... #ENDIF
1185 .................... 1185 ....................
1186 .................... #IFNDEF USB_CDC_DEVICE 1186 .................... #IFNDEF USB_CDC_DEVICE
1187 .................... #DEFINE USB_CDC_DEVICE FALSE 1187 .................... #DEFINE USB_CDC_DEVICE FALSE
1188 .................... #ENDIF 1188 .................... #ENDIF
1189 .................... 1189 ....................
1190 .................... //set to false to opt for less RAM, true to opt for less ROM 1190 .................... //set to false to opt for less RAM, true to opt for less ROM
1191 .................... #ifndef USB_OPT_FOR_ROM 1191 .................... #ifndef USB_OPT_FOR_ROM
1192 .................... #define USB_OPT_FOR_ROM TRUE 1192 .................... #define USB_OPT_FOR_ROM TRUE
1193 .................... #endif 1193 .................... #endif
1194 .................... 1194 ....................
1195 .................... #IFNDEF USB_MAX_EP0_PACKET_LENGTH 1195 .................... #IFNDEF USB_MAX_EP0_PACKET_LENGTH
1196 .................... #DEFINE USB_MAX_EP0_PACKET_LENGTH 8 1196 .................... #DEFINE USB_MAX_EP0_PACKET_LENGTH 8
1197 .................... #ENDIF 1197 .................... #ENDIF
1198 .................... 1198 ....................
1199 .................... 1199 ....................
1200 .................... ////// USER-LEVEL API ///////////////////////////////////////////////////////// 1200 .................... ////// USER-LEVEL API /////////////////////////////////////////////////////////
1201 .................... 1201 ....................
1202 .................... /************************************************************** 1202 .................... /**************************************************************
1203 .................... /* usb_enumerated() 1203 .................... /* usb_enumerated()
1204 .................... /* 1204 .................... /*
1205 .................... /* Input: Global variable USB_Curr_Config 1205 .................... /* Input: Global variable USB_Curr_Config
1206 .................... /* Returns: Returns a 1 if device is configured / enumerated, 1206 .................... /* Returns: Returns a 1 if device is configured / enumerated,
1207 .................... /* Returns a 0 if device is un-configured / not enumerated. 1207 .................... /* Returns a 0 if device is un-configured / not enumerated.
1208 .................... /* 1208 .................... /*
1209 .................... /* Summary: See API section of USB.H for more documentation. 1209 .................... /* Summary: See API section of USB.H for more documentation.
1210 .................... /***************************************************************/ 1210 .................... /***************************************************************/
1211 .................... int1 usb_enumerated(void); 1211 .................... int1 usb_enumerated(void);
1212 .................... 1212 ....................
1213 .................... /************************************************************** 1213 .................... /**************************************************************
1214 .................... /* usb_wait_for_enumeration() 1214 .................... /* usb_wait_for_enumeration()
1215 .................... /* 1215 .................... /*
1216 .................... /* Input: Global variable USB_Curr_Config 1216 .................... /* Input: Global variable USB_Curr_Config
1217 .................... /* 1217 .................... /*
1218 .................... /* Summary: Waits in-definately until device is configured / enumerated. 1218 .................... /* Summary: Waits in-definately until device is configured / enumerated.
1219 .................... /* See API section of USB.H for more information. 1219 .................... /* See API section of USB.H for more information.
1220 .................... /***************************************************************/ 1220 .................... /***************************************************************/
1221 .................... void usb_wait_for_enumeration(void); 1221 .................... void usb_wait_for_enumeration(void);
1222 .................... 1222 ....................
1223 .................... /**************************************************************************** 1223 .................... /****************************************************************************
1224 .................... /* usb_gets(endpoint, ptr, max, timeout) 1224 .................... /* usb_gets(endpoint, ptr, max, timeout)
1225 .................... /* 1225 .................... /*
1226 .................... /* Input: endpoint - endpoint to get data from 1226 .................... /* Input: endpoint - endpoint to get data from
1227 .................... /* ptr - place / array to store data to 1227 .................... /* ptr - place / array to store data to
1228 .................... /* max - max amount of data to get from USB and store into ptr 1228 .................... /* max - max amount of data to get from USB and store into ptr
1229 .................... /* timeout - time in milliseconds, for each packet, to wait before 1229 .................... /* timeout - time in milliseconds, for each packet, to wait before
1230 .................... /* timeout. set to 0 for no timeout. 1230 .................... /* timeout. set to 0 for no timeout.
1231 .................... /* 1231 .................... /*
1232 .................... /* Output: Amount of data returned. It may be less than max. 1232 .................... /* Output: Amount of data returned. It may be less than max.
1233 .................... /* 1233 .................... /*
1234 .................... /* Summary: Gets data from the host. Will get multiple-packet messages 1234 .................... /* Summary: Gets data from the host. Will get multiple-packet messages
1235 .................... /* and finish when either it receives a 0-len packet or a packet 1235 .................... /* and finish when either it receives a 0-len packet or a packet
1236 .................... /* of less size than maximum. 1236 .................... /* of less size than maximum.
1237 .................... /* 1237 .................... /*
1238 .................... /*****************************************************************************/ 1238 .................... /*****************************************************************************/
1239 .................... unsigned int16 usb_gets(int8 endpoint, int8 * ptr, unsigned int16 max, unsigned int16 timeout); 1239 .................... unsigned int16 usb_gets(int8 endpoint, int8 * ptr, unsigned int16 max, unsigned int16 timeout);
1240 .................... 1240 ....................
1241 .................... /**************************************************************************** 1241 .................... /****************************************************************************
1242 .................... /* usb_puts() 1242 .................... /* usb_puts()
1243 .................... /* 1243 .................... /*
1244 .................... /* Inputs: endpoint - endpoint to send data out 1244 .................... /* Inputs: endpoint - endpoint to send data out
1245 .................... /* ptr - points to array of data to send 1245 .................... /* ptr - points to array of data to send
1246 .................... /* len - amount of data to send 1246 .................... /* len - amount of data to send
1247 .................... /* timeout - time in milli-seconds, for each packet, to wait before 1247 .................... /* timeout - time in milli-seconds, for each packet, to wait before
1248 .................... /* timeout. set to 0 for no timeout. 1248 .................... /* timeout. set to 0 for no timeout.
1249 .................... /* 1249 .................... /*
1250 .................... /* Outputs: Returns TRUE if message sent succesfully, FALSE if it was not 1250 .................... /* Outputs: Returns TRUE if message sent succesfully, FALSE if it was not
1251 .................... /* sent before timeout period expired. 1251 .................... /* sent before timeout period expired.
1252 .................... /* 1252 .................... /*
1253 .................... /* Summary: Used for sending multiple packets of data as one message. This 1253 .................... /* Summary: Used for sending multiple packets of data as one message. This
1254 .................... /* function can still be used to send messages consiting of only one 1254 .................... /* function can still be used to send messages consiting of only one
1255 .................... /* packet. See usb_put_packet() documentation for the rules about when 1255 .................... /* packet. See usb_put_packet() documentation for the rules about when
1256 .................... /* multiple packet messages or 0-lenght packets are needed. 1256 .................... /* multiple packet messages or 0-lenght packets are needed.
1257 .................... /* 1257 .................... /*
1258 .................... /*****************************************************************************/ 1258 .................... /*****************************************************************************/
1259 .................... int1 usb_puts(int8 endpoint, int8 * ptr, unsigned int16 len, unsigned int8 timeout); 1259 .................... int1 usb_puts(int8 endpoint, int8 * ptr, unsigned int16 len, unsigned int8 timeout);
1260 .................... 1260 ....................
1261 .................... /****************************************************************************** 1261 .................... /******************************************************************************
1262 .................... /* usb_attached() 1262 .................... /* usb_attached()
1263 .................... /* 1263 .................... /*
1264 .................... /* Summary: Returns TRUE if the device is attached to a USB cable. 1264 .................... /* Summary: Returns TRUE if the device is attached to a USB cable.
1265 .................... /* See the API section of USB.H for more documentation. 1265 .................... /* See the API section of USB.H for more documentation.
1266 .................... /* 1266 .................... /*
1267 .................... /*****************************************************************************/ 1267 .................... /*****************************************************************************/
1268 .................... #if USB_CON_SENSE_PIN 1268 .................... #if USB_CON_SENSE_PIN
1269 .................... #define usb_attached() input(USB_CON_SENSE_PIN) 1269 .................... #define usb_attached() input(USB_CON_SENSE_PIN)
1270 .................... #else 1270 .................... #else
1271 .................... #define usb_attached() TRUE 1271 .................... #define usb_attached() TRUE
1272 .................... #endif 1272 .................... #endif
1273 .................... 1273 ....................
1274 .................... ////// END USER-LEVEL API ///////////////////////////////////////////////////// 1274 .................... ////// END USER-LEVEL API /////////////////////////////////////////////////////
1275 .................... 1275 ....................
1276 .................... 1276 ....................
1277 .................... ////// STACK-LEVEL API USED BY HW DRIVERS //////////////////////////////////// 1277 .................... ////// STACK-LEVEL API USED BY HW DRIVERS ////////////////////////////////////
1278 .................... 1278 ....................
1279 .................... enum USB_STATES {GET_DESCRIPTOR=1,SET_ADDRESS=2,NONE=0}; 1279 .................... enum USB_STATES {GET_DESCRIPTOR=1,SET_ADDRESS=2,NONE=0};
1280 .................... 1280 ....................
1281 .................... enum USB_GETDESC_TYPES {USB_GETDESC_CONFIG_TYPE=0,USB_GETDESC_HIDREPORT_TYPE=1,USB_GETDESC_STRING_TYPE=2,USB_GETDESC_DEVICE_TYPE=3}; 1281 .................... enum USB_GETDESC_TYPES {USB_GETDESC_CONFIG_TYPE=0,USB_GETDESC_HIDREPORT_TYPE=1,USB_GETDESC_STRING_TYPE=2,USB_GETDESC_DEVICE_TYPE=3};
1282 .................... 1282 ....................
1283 .................... #if USB_OPT_FOR_ROM 1283 .................... #if USB_OPT_FOR_ROM
1284 .................... typedef struct { 1284 .................... typedef struct {
1285 .................... USB_STATES dev_req; //what did the last setup token set us up to do?. init at none 1285 .................... USB_STATES dev_req; //what did the last setup token set us up to do?. init at none
1286 .................... int curr_config; //our current config. start at none/powered (NOT THAT THIS LIMITS US TO 3 CONFIGURATIONS) 1286 .................... int curr_config; //our current config. start at none/powered (NOT THAT THIS LIMITS US TO 3 CONFIGURATIONS)
1287 .................... int status_device; //Holds our state for Set_Feature and Clear_Feature 1287 .................... int status_device; //Holds our state for Set_Feature and Clear_Feature
1288 .................... USB_GETDESC_TYPES getdesc_type; //which get_descriptor() we are handling 1288 .................... USB_GETDESC_TYPES getdesc_type; //which get_descriptor() we are handling
1289 .................... } TYPE_USB_STACK_STATUS; 1289 .................... } TYPE_USB_STACK_STATUS;
1290 .................... #else 1290 .................... #else
1291 .................... typedef struct { 1291 .................... typedef struct {
1292 .................... USB_STATES dev_req:2; //what did the last setup token set us up to do?. init at none 1292 .................... USB_STATES dev_req:2; //what did the last setup token set us up to do?. init at none
1293 .................... int Curr_config:2; //our current config. start at none/powered (NOT THAT THIS LIMITS US TO 3 CONFIGURATIONS) 1293 .................... int Curr_config:2; //our current config. start at none/powered (NOT THAT THIS LIMITS US TO 3 CONFIGURATIONS)
1294 .................... int status_device:2; //Holds our state for Set_Feature and Clear_Feature 1294 .................... int status_device:2; //Holds our state for Set_Feature and Clear_Feature
1295 .................... USB_GETDESC_TYPES getdesc_type:2; //which get_descriptor() we are handling 1295 .................... USB_GETDESC_TYPES getdesc_type:2; //which get_descriptor() we are handling
1296 .................... } TYPE_USB_STACK_STATUS; 1296 .................... } TYPE_USB_STACK_STATUS;
1297 .................... #endif 1297 .................... #endif
1298 .................... 1298 ....................
1299 .................... extern TYPE_USB_STACK_STATUS USB_stack_status; 1299 .................... extern TYPE_USB_STACK_STATUS USB_stack_status;
1300 .................... 1300 ....................
1301 .................... /************************************************************** 1301 .................... /**************************************************************
1302 .................... /* usb_token_reset() 1302 .................... /* usb_token_reset()
1303 .................... /* 1303 .................... /*
1304 .................... /* Output: No output (but many global registers are modified) 1304 .................... /* Output: No output (but many global registers are modified)
1305 .................... /* 1305 .................... /*
1306 .................... /* Summary: Resets the token handler to initial (unconfigured) state. 1306 .................... /* Summary: Resets the token handler to initial (unconfigured) state.
1307 .................... /***************************************************************/ 1307 .................... /***************************************************************/
1308 .................... void usb_token_reset(void); 1308 .................... void usb_token_reset(void);
1309 .................... 1309 ....................
1310 .................... /************************************************************** 1310 .................... /**************************************************************
1311 .................... /* usb_isr_tok_setup_dne() 1311 .................... /* usb_isr_tok_setup_dne()
1312 .................... /* 1312 .................... /*
1313 .................... /* Input: usb_ep0_rx_buffer[] contains the the setup packet. 1313 .................... /* Input: usb_ep0_rx_buffer[] contains the the setup packet.
1314 .................... /* 1314 .................... /*
1315 .................... /* Output: None (many globals are changed) 1315 .................... /* Output: None (many globals are changed)
1316 .................... /* 1316 .................... /*
1317 .................... /* Summary: This function is that handles the setup token. 1317 .................... /* Summary: This function is that handles the setup token.
1318 .................... /* We must handle all relevant requests, such as Set_Configuration, 1318 .................... /* We must handle all relevant requests, such as Set_Configuration,
1319 .................... /* Get_Descriptor, etc. 1319 .................... /* Get_Descriptor, etc.
1320 .................... /* 1320 .................... /*
1321 .................... /* usb_ep0_rx_buffer[] contains setup data packet, which has the 1321 .................... /* usb_ep0_rx_buffer[] contains setup data packet, which has the
1322 .................... /* following records: 1322 .................... /* following records:
1323 .................... /* ------------------------------------------------------------------------------------------- 1323 .................... /* -------------------------------------------------------------------------------------------
1324 .................... /* usb_ep0_rx_buffer[ 0 ]=bmRequestType; Where the setup packet goes 1324 .................... /* usb_ep0_rx_buffer[ 0 ]=bmRequestType; Where the setup packet goes
1325 .................... /* bit7 (0) host-to-device 1325 .................... /* bit7 (0) host-to-device
1326 .................... /* (1) device-to-host 1326 .................... /* (1) device-to-host
1327 .................... /* bit6-5 (00) usb standard request; 1327 .................... /* bit6-5 (00) usb standard request;
1328 .................... /* (01) class request; 1328 .................... /* (01) class request;
1329 .................... /* (10) vendor request 1329 .................... /* (10) vendor request
1330 .................... /* (11) reserved 1330 .................... /* (11) reserved
1331 .................... /* bit4-0 (0000) device 1331 .................... /* bit4-0 (0000) device
1332 .................... /* (0001) interface 1332 .................... /* (0001) interface
1333 .................... /* (0010) endpoint 1333 .................... /* (0010) endpoint
1334 .................... /* (0011) other element 1334 .................... /* (0011) other element
1335 .................... /* (0100) to (1111) reserved 1335 .................... /* (0100) to (1111) reserved
1336 .................... /* usb_ep0_rx_buffer[ 1 ]=bRequest ; the request 1336 .................... /* usb_ep0_rx_buffer[ 1 ]=bRequest ; the request
1337 .................... /* usb_ep0_rx_buffer[2,3]=wValue ; a value which corresponds to request 1337 .................... /* usb_ep0_rx_buffer[2,3]=wValue ; a value which corresponds to request
1338 .................... /* usb_ep0_rx_buffer[4,5]=wIndex ; could correspond to interface or endpoint... 1338 .................... /* usb_ep0_rx_buffer[4,5]=wIndex ; could correspond to interface or endpoint...
1339 .................... /* usb_ep0_rx_buffer[6,7]=wLength ; number of bytes in next data packet; 1339 .................... /* usb_ep0_rx_buffer[6,7]=wLength ; number of bytes in next data packet;
1340 .................... /* for host-to-device, this exactly how many bytes in data packet. 1340 .................... /* for host-to-device, this exactly how many bytes in data packet.
1341 .................... /* for device-to-host, this is the maximum bytes that can fit one packet. 1341 .................... /* for device-to-host, this is the maximum bytes that can fit one packet.
1342 .................... /***************************************************************/ 1342 .................... /***************************************************************/
1343 .................... void usb_isr_tok_setup_dne(void); 1343 .................... void usb_isr_tok_setup_dne(void);
1344 .................... 1344 ....................
1345 .................... /************************************************************** 1345 .................... /**************************************************************
1346 .................... /* usb_isr_tok_out_dne() 1346 .................... /* usb_isr_tok_out_dne()
1347 .................... /* 1347 .................... /*
1348 .................... /* Input: endpoint contains which endpoint we are receiving data (0..15) 1348 .................... /* Input: endpoint contains which endpoint we are receiving data (0..15)
1349 .................... /* 1349 .................... /*
1350 .................... /* Summary: Processes out tokens (out is respective of the host, so actualy 1350 .................... /* Summary: Processes out tokens (out is respective of the host, so actualy
1351 .................... /* incoming to the pic), but not out setup tokens. Normally when 1351 .................... /* incoming to the pic), but not out setup tokens. Normally when
1352 .................... /* data is received it is left in the buffer (user would use 1352 .................... /* data is received it is left in the buffer (user would use
1353 .................... /* usb_kbhit() and usb_get_packet() to receive data), but certain 1353 .................... /* usb_kbhit() and usb_get_packet() to receive data), but certain
1354 .................... /* libraries (like CDC) have to answer setup packets. 1354 .................... /* libraries (like CDC) have to answer setup packets.
1355 .................... /* 1355 .................... /*
1356 .................... /***************************************************************/ 1356 .................... /***************************************************************/
1357 .................... void usb_isr_tok_out_dne(int8 endpoint); 1357 .................... void usb_isr_tok_out_dne(int8 endpoint);
1358 .................... 1358 ....................
1359 .................... /************************************************************** 1359 .................... /**************************************************************
1360 .................... /* usb_isr_tok_in_dne(endpoint) 1360 .................... /* usb_isr_tok_in_dne(endpoint)
1361 .................... /* 1361 .................... /*
1362 .................... /* Input: endpoint - which endpoint we are processing a setup token. 1362 .................... /* Input: endpoint - which endpoint we are processing a setup token.
1363 .................... /* 1363 .................... /*
1364 .................... /* Summary: This handles an IN packet (HOST <- PIC). For endpoint 0, this 1364 .................... /* Summary: This handles an IN packet (HOST <- PIC). For endpoint 0, this
1365 .................... /* is usually to setup a response packet to a setup packet. Endpoints 1..15 1365 .................... /* is usually to setup a response packet to a setup packet. Endpoints 1..15
1366 .................... /* are generally ignored, and the user has to use usb_tbe() to determine if 1366 .................... /* are generally ignored, and the user has to use usb_tbe() to determine if
1367 .................... /* if the buffer is ready for a new transmit packet (there are special cases, 1367 .................... /* if the buffer is ready for a new transmit packet (there are special cases,
1368 .................... /* like CDC which handles the CDC protocl). 1368 .................... /* like CDC which handles the CDC protocl).
1369 .................... /* 1369 .................... /*
1370 .................... /***************************************************************/ 1370 .................... /***************************************************************/
1371 .................... void usb_isr_tok_in_dne(int8 endpoint); 1371 .................... void usb_isr_tok_in_dne(int8 endpoint);
1372 .................... 1372 ....................
1373 .................... ////// END STACK-LEVEL API USED BY HW DRIVERS ///////////////////////////////// 1373 .................... ////// END STACK-LEVEL API USED BY HW DRIVERS /////////////////////////////////
1374 .................... 1374 ....................
1375 .................... 1375 ....................
1376 .................... //CCS only supports one configuration at this time 1376 .................... //CCS only supports one configuration at this time
1377 .................... #DEFINE USB_NUM_CONFIGURATIONS 1 //DO NOT CHANGE 1377 .................... #DEFINE USB_NUM_CONFIGURATIONS 1 //DO NOT CHANGE
1378 .................... 1378 ....................
1379 .................... //PID values for tokens (see page 48 of USB Complete ed.1) 1379 .................... //PID values for tokens (see page 48 of USB Complete ed.1)
1380 .................... #define PID_IN 0x09 //device to host transactions 1380 .................... #define PID_IN 0x09 //device to host transactions
1381 .................... #define PID_OUT 0x01 //host to device transactions 1381 .................... #define PID_OUT 0x01 //host to device transactions
1382 .................... #define PID_SETUP 0x0D //host to device setup transaction 1382 .................... #define PID_SETUP 0x0D //host to device setup transaction
1383 .................... #define PID_ACK 0x02 //receiver accepts error-free data packet 1383 .................... #define PID_ACK 0x02 //receiver accepts error-free data packet
1384 .................... #define PID_DATA0 0x03 //data packet with even sync bit 1384 .................... #define PID_DATA0 0x03 //data packet with even sync bit
1385 .................... #define PID_SOF 0x05 //start of framer marker and frame number 1385 .................... #define PID_SOF 0x05 //start of framer marker and frame number
1386 .................... #define PID_NAK 0x0A //receiver can't accept data or sender cant send data or has no data to transmit 1386 .................... #define PID_NAK 0x0A //receiver can't accept data or sender cant send data or has no data to transmit
1387 .................... #define PID_DATA1 0x0B //data packet with odd sync bit 1387 .................... #define PID_DATA1 0x0B //data packet with odd sync bit
1388 .................... #define PID_PRE 0x0C //preamble issued by host. enables downstream traffic to low-speed device 1388 .................... #define PID_PRE 0x0C //preamble issued by host. enables downstream traffic to low-speed device
1389 .................... #define PID_STALL 0x0E //a control request isnt supported or the endpoint is halted 1389 .................... #define PID_STALL 0x0E //a control request isnt supported or the endpoint is halted
1390 .................... 1390 ....................
1391 .................... //Key which identifies descritpors 1391 .................... //Key which identifies descritpors
1392 .................... #DEFINE USB_DESC_DEVICE_TYPE 0x01 //#DEFINE USB_DEVICE_DESC_KEY 0x01 1392 .................... #DEFINE USB_DESC_DEVICE_TYPE 0x01 //#DEFINE USB_DEVICE_DESC_KEY 0x01
1393 .................... #DEFINE USB_DESC_CONFIG_TYPE 0x02 //#DEFINE USB_CONFIG_DESC_KEY 0x02 1393 .................... #DEFINE USB_DESC_CONFIG_TYPE 0x02 //#DEFINE USB_CONFIG_DESC_KEY 0x02
1394 .................... #DEFINE USB_DESC_STRING_TYPE 0x03 //#DEFINE USB_STRING_DESC_KEY 0x03 1394 .................... #DEFINE USB_DESC_STRING_TYPE 0x03 //#DEFINE USB_STRING_DESC_KEY 0x03
1395 .................... #DEFINE USB_DESC_INTERFACE_TYPE 0x04 //#DEFINE USB_INTERFACE_DESC_KEY 0x04 1395 .................... #DEFINE USB_DESC_INTERFACE_TYPE 0x04 //#DEFINE USB_INTERFACE_DESC_KEY 0x04
1396 .................... #DEFINE USB_DESC_ENDPOINT_TYPE 0x05 //#DEFINE USB_ENDPOINT_DESC_KEY 0x05 1396 .................... #DEFINE USB_DESC_ENDPOINT_TYPE 0x05 //#DEFINE USB_ENDPOINT_DESC_KEY 0x05
1397 .................... #DEFINE USB_DESC_CLASS_TYPE 0x21 //#DEFINE USB_CLASS_DESC_KEY 0x21 1397 .................... #DEFINE USB_DESC_CLASS_TYPE 0x21 //#DEFINE USB_CLASS_DESC_KEY 0x21
1398 .................... #DEFINE USB_DESC_HIDREPORT_TYPE 0x22 1398 .................... #DEFINE USB_DESC_HIDREPORT_TYPE 0x22
1399 .................... 1399 ....................
1400 .................... //The length of each descriptor 1400 .................... //The length of each descriptor
1401 .................... #DEFINE USB_DESC_DEVICE_LEN 18 //#DEFINE USB_DEVICE_DESC_LEN 18 1401 .................... #DEFINE USB_DESC_DEVICE_LEN 18 //#DEFINE USB_DEVICE_DESC_LEN 18
1402 .................... #DEFINE USB_DESC_CONFIG_LEN 9 //#DEFINE USB_CONFIG_DESC_LEN 9 1402 .................... #DEFINE USB_DESC_CONFIG_LEN 9 //#DEFINE USB_CONFIG_DESC_LEN 9
1403 .................... #DEFINE USB_DESC_INTERFACE_LEN 9 //#DEFINE USB_INTERFACE_DESC_LEN 9 1403 .................... #DEFINE USB_DESC_INTERFACE_LEN 9 //#DEFINE USB_INTERFACE_DESC_LEN 9
1404 .................... #DEFINE USB_DESC_CLASS_LEN 9 //#DEFINE USB_CLASS_DESC_LEN 9 1404 .................... #DEFINE USB_DESC_CLASS_LEN 9 //#DEFINE USB_CLASS_DESC_LEN 9
1405 .................... #DEFINE USB_DESC_ENDPOINT_LEN 7 //#DEFINE USB_ENDPOINT_DESC_LEN 7 1405 .................... #DEFINE USB_DESC_ENDPOINT_LEN 7 //#DEFINE USB_ENDPOINT_DESC_LEN 7
1406 .................... 1406 ....................
1407 .................... //Standard USB Setup bRequest Codes 1407 .................... //Standard USB Setup bRequest Codes
1408 .................... #define USB_STANDARD_REQUEST_GET_STATUS 0x00 1408 .................... #define USB_STANDARD_REQUEST_GET_STATUS 0x00
1409 .................... #define USB_STANDARD_REQUEST_CLEAR_FEATURE 0x01 1409 .................... #define USB_STANDARD_REQUEST_CLEAR_FEATURE 0x01
1410 .................... #define USB_STANDARD_REQUEST_SET_FEATURE 0x03 1410 .................... #define USB_STANDARD_REQUEST_SET_FEATURE 0x03
1411 .................... #define USB_STANDARD_REQUEST_SET_ADDRESS 0x05 1411 .................... #define USB_STANDARD_REQUEST_SET_ADDRESS 0x05
1412 .................... #define USB_STANDARD_REQUEST_GET_DESCRIPTOR 0x06 1412 .................... #define USB_STANDARD_REQUEST_GET_DESCRIPTOR 0x06
1413 .................... #define USB_STANDARD_REQUEST_SET_DESCRIPTOR 0x07 1413 .................... #define USB_STANDARD_REQUEST_SET_DESCRIPTOR 0x07
1414 .................... #define USB_STANDARD_REQUEST_GET_CONFIGURATION 0x08 1414 .................... #define USB_STANDARD_REQUEST_GET_CONFIGURATION 0x08
1415 .................... #define USB_STANDARD_REQUEST_SET_CONFIGURATION 0x09 1415 .................... #define USB_STANDARD_REQUEST_SET_CONFIGURATION 0x09
1416 .................... #define USB_STANDARD_REQUEST_GET_INTERFACE 0x0A 1416 .................... #define USB_STANDARD_REQUEST_GET_INTERFACE 0x0A
1417 .................... #define USB_STANDARD_REQUEST_SET_INTERFACE 0x0B 1417 .................... #define USB_STANDARD_REQUEST_SET_INTERFACE 0x0B
1418 .................... #define USB_STANDARD_REQUEST_SYNCH_FRAME 0x0C 1418 .................... #define USB_STANDARD_REQUEST_SYNCH_FRAME 0x0C
1419 .................... 1419 ....................
1420 .................... //HID Class Setup bRequest Codes 1420 .................... //HID Class Setup bRequest Codes
1421 .................... #define USB_HID_REQUEST_GET_REPORT 0x01 1421 .................... #define USB_HID_REQUEST_GET_REPORT 0x01
1422 .................... #define USB_HID_REQUEST_GET_IDLE 0x02 1422 .................... #define USB_HID_REQUEST_GET_IDLE 0x02
1423 .................... #define USB_HID_REQUEST_GET_PROTOCOL 0x03 1423 .................... #define USB_HID_REQUEST_GET_PROTOCOL 0x03
1424 .................... #define USB_HID_REQUEST_SET_REPORT 0x09 1424 .................... #define USB_HID_REQUEST_SET_REPORT 0x09
1425 .................... #define USB_HID_REQUEST_SET_IDLE 0x0A 1425 .................... #define USB_HID_REQUEST_SET_IDLE 0x0A
1426 .................... #define USB_HID_REQUEST_SET_PROTOCOL 0x0B 1426 .................... #define USB_HID_REQUEST_SET_PROTOCOL 0x0B
1427 .................... 1427 ....................
1428 .................... //types of endpoints as defined in the descriptor 1428 .................... //types of endpoints as defined in the descriptor
1429 .................... #define USB_ENDPOINT_TYPE_CONTROL 0x00 1429 .................... #define USB_ENDPOINT_TYPE_CONTROL 0x00
1430 .................... #define USB_ENDPOINT_TYPE_ISOCHRONOUS 0x01 1430 .................... #define USB_ENDPOINT_TYPE_ISOCHRONOUS 0x01
1431 .................... #define USB_ENDPOINT_TYPE_BULK 0x02 1431 .................... #define USB_ENDPOINT_TYPE_BULK 0x02
1432 .................... #define USB_ENDPOINT_TYPE_INTERRUPT 0x03 1432 .................... #define USB_ENDPOINT_TYPE_INTERRUPT 0x03
1433 .................... 1433 ....................
1434 .................... //types of endpoints used internally in this api 1434 .................... //types of endpoints used internally in this api
1435 .................... #define USB_ENABLE_DISABLED -1 1435 .................... #define USB_ENABLE_DISABLED -1
1436 .................... #define USB_ENABLE_BULK USB_ENDPOINT_TYPE_BULK 1436 .................... #define USB_ENABLE_BULK USB_ENDPOINT_TYPE_BULK
1437 .................... #define USB_ENABLE_ISOCHRONOUS USB_ENDPOINT_TYPE_ISOCHRONOUS 1437 .................... #define USB_ENABLE_ISOCHRONOUS USB_ENDPOINT_TYPE_ISOCHRONOUS
1438 .................... #define USB_ENABLE_INTERRUPT USB_ENDPOINT_TYPE_INTERRUPT 1438 .................... #define USB_ENABLE_INTERRUPT USB_ENDPOINT_TYPE_INTERRUPT
1439 .................... #define USB_ENABLE_CONTROL USB_ENDPOINT_TYPE_CONTROL 1439 .................... #define USB_ENABLE_CONTROL USB_ENDPOINT_TYPE_CONTROL
1440 .................... 1440 ....................
1441 .................... 1441 ....................
1442 .................... //*** ENABLE RX ENDPOINTS AND BUFFERS 1442 .................... //*** ENABLE RX ENDPOINTS AND BUFFERS
1443 .................... 1443 ....................
1444 .................... //--------- endpoint 0 defines ---------- 1444 .................... //--------- endpoint 0 defines ----------
1445 .................... #define USB_EP0_TX_ENABLE USB_ENABLE_CONTROL 1445 .................... #define USB_EP0_TX_ENABLE USB_ENABLE_CONTROL
1446 .................... #define USB_EP0_RX_ENABLE USB_ENABLE_CONTROL 1446 .................... #define USB_EP0_RX_ENABLE USB_ENABLE_CONTROL
1447 .................... #define USB_EP0_RX_SIZE USB_MAX_EP0_PACKET_LENGTH //endpoint 0 is setup, and should always be the MAX_PACKET_LENGTH. Slow speed specifies 8 1447 .................... #define USB_EP0_RX_SIZE USB_MAX_EP0_PACKET_LENGTH //endpoint 0 is setup, and should always be the MAX_PACKET_LENGTH. Slow speed specifies 8
1448 .................... #define USB_EP0_TX_SIZE USB_MAX_EP0_PACKET_LENGTH //endpoint 0 is setup, and should always be the MAX_PACKET_LENGTH. Slow speed specifies 8 1448 .................... #define USB_EP0_TX_SIZE USB_MAX_EP0_PACKET_LENGTH //endpoint 0 is setup, and should always be the MAX_PACKET_LENGTH. Slow speed specifies 8
1449 .................... 1449 ....................
1450 .................... //--------- endpoint 1 defines ---------- 1450 .................... //--------- endpoint 1 defines ----------
1451 .................... #ifndef USB_EP1_TX_ENABLE 1451 .................... #ifndef USB_EP1_TX_ENABLE
1452 .................... #define USB_EP1_TX_ENABLE USB_ENABLE_DISABLED 1452 .................... #define USB_EP1_TX_ENABLE USB_ENABLE_DISABLED
1453 .................... #endif 1453 .................... #endif
1454 .................... #ifndef USB_EP1_RX_ENABLE 1454 .................... #ifndef USB_EP1_RX_ENABLE
1455 .................... #define USB_EP1_RX_ENABLE USB_ENABLE_DISABLED 1455 .................... #define USB_EP1_RX_ENABLE USB_ENABLE_DISABLED
1456 .................... #endif 1456 .................... #endif
1457 .................... 1457 ....................
1458 .................... #if USB_EP1_RX_ENABLE==USB_ENABLE_DISABLED 1458 .................... #if USB_EP1_RX_ENABLE==USB_ENABLE_DISABLED
1459 .................... #ifdef USB_EP1_RX_SIZE 1459 .................... #ifdef USB_EP1_RX_SIZE
1460 .................... #undef USB_EP1_RX_SIZE 1460 .................... #undef USB_EP1_RX_SIZE
1461 .................... #endif 1461 .................... #endif
1462 .................... #define USB_EP1_RX_SIZE 0 1462 .................... #define USB_EP1_RX_SIZE 0
1463 .................... #else 1463 .................... #else
1464 .................... #ifndef USB_EP1_RX_SIZE 1464 .................... #ifndef USB_EP1_RX_SIZE
1465 .................... #error You enabled EP1 for RX but didn't specify endpoint size 1465 .................... #error You enabled EP1 for RX but didn't specify endpoint size
1466 .................... #endif 1466 .................... #endif
1467 .................... #endif 1467 .................... #endif
1468 .................... 1468 ....................
1469 .................... #if USB_EP1_TX_ENABLE==USB_ENABLE_DISABLED 1469 .................... #if USB_EP1_TX_ENABLE==USB_ENABLE_DISABLED
1470 .................... #ifdef USB_EP1_TX_SIZE 1470 .................... #ifdef USB_EP1_TX_SIZE
1471 .................... #undef USB_EP1_TX_SIZE 1471 .................... #undef USB_EP1_TX_SIZE
1472 .................... #endif 1472 .................... #endif
1473 .................... #define USB_EP1_TX_SIZE 0 1473 .................... #define USB_EP1_TX_SIZE 0
1474 .................... #else 1474 .................... #else
1475 .................... #ifndef USB_EP1_TX_SIZE 1475 .................... #ifndef USB_EP1_TX_SIZE
1476 .................... #error You enabled EP1 for TX but didn't specify endpoint size 1476 .................... #error You enabled EP1 for TX but didn't specify endpoint size
1477 .................... #endif 1477 .................... #endif
1478 .................... #endif 1478 .................... #endif
1479 .................... 1479 ....................
1480 .................... 1480 ....................
1481 .................... //--------- endpoint 2 defines ---------- 1481 .................... //--------- endpoint 2 defines ----------
1482 .................... #ifndef USB_EP2_TX_ENABLE 1482 .................... #ifndef USB_EP2_TX_ENABLE
1483 .................... #define USB_EP2_TX_ENABLE USB_ENABLE_DISABLED 1483 .................... #define USB_EP2_TX_ENABLE USB_ENABLE_DISABLED
1484 .................... #endif 1484 .................... #endif
1485 .................... #ifndef USB_EP2_RX_ENABLE 1485 .................... #ifndef USB_EP2_RX_ENABLE
1486 .................... #define USB_EP2_RX_ENABLE USB_ENABLE_DISABLED 1486 .................... #define USB_EP2_RX_ENABLE USB_ENABLE_DISABLED
1487 .................... #endif 1487 .................... #endif
1488 .................... 1488 ....................
1489 .................... #if USB_EP2_RX_ENABLE==USB_ENABLE_DISABLED 1489 .................... #if USB_EP2_RX_ENABLE==USB_ENABLE_DISABLED
1490 .................... #ifdef USB_EP2_RX_SIZE 1490 .................... #ifdef USB_EP2_RX_SIZE
1491 .................... #undef USB_EP2_RX_SIZE 1491 .................... #undef USB_EP2_RX_SIZE
1492 .................... #endif 1492 .................... #endif
1493 .................... #define USB_EP2_RX_SIZE 0 1493 .................... #define USB_EP2_RX_SIZE 0
1494 .................... #else 1494 .................... #else
1495 .................... #ifndef USB_EP2_RX_SIZE 1495 .................... #ifndef USB_EP2_RX_SIZE
1496 .................... #error You enabled EP2 for RX but didn't specify endpoint size 1496 .................... #error You enabled EP2 for RX but didn't specify endpoint size
1497 .................... #endif 1497 .................... #endif
1498 .................... #endif 1498 .................... #endif
1499 .................... 1499 ....................
1500 .................... #if USB_EP2_TX_ENABLE==USB_ENABLE_DISABLED 1500 .................... #if USB_EP2_TX_ENABLE==USB_ENABLE_DISABLED
1501 .................... #ifdef USB_EP2_TX_SIZE 1501 .................... #ifdef USB_EP2_TX_SIZE
1502 .................... #undef USB_EP2_TX_SIZE 1502 .................... #undef USB_EP2_TX_SIZE
1503 .................... #endif 1503 .................... #endif
1504 .................... #define USB_EP2_TX_SIZE 0 1504 .................... #define USB_EP2_TX_SIZE 0
1505 .................... #else 1505 .................... #else
1506 .................... #ifndef USB_EP2_TX_SIZE 1506 .................... #ifndef USB_EP2_TX_SIZE
1507 .................... #error You enabled EP2 for TX but didn't specify endpoint size 1507 .................... #error You enabled EP2 for TX but didn't specify endpoint size
1508 .................... #endif 1508 .................... #endif
1509 .................... #endif 1509 .................... #endif
1510 .................... 1510 ....................
1511 .................... 1511 ....................
1512 .................... //--------- endpoint 3 defines ---------- 1512 .................... //--------- endpoint 3 defines ----------
1513 .................... #ifndef USB_EP3_TX_ENABLE 1513 .................... #ifndef USB_EP3_TX_ENABLE
1514 .................... #define USB_EP3_TX_ENABLE USB_ENABLE_DISABLED 1514 .................... #define USB_EP3_TX_ENABLE USB_ENABLE_DISABLED
1515 .................... #endif 1515 .................... #endif
1516 .................... #ifndef USB_EP3_RX_ENABLE 1516 .................... #ifndef USB_EP3_RX_ENABLE
1517 .................... #define USB_EP3_RX_ENABLE USB_ENABLE_DISABLED 1517 .................... #define USB_EP3_RX_ENABLE USB_ENABLE_DISABLED
1518 .................... #endif 1518 .................... #endif
1519 .................... 1519 ....................
1520 .................... #if USB_EP3_RX_ENABLE==USB_ENABLE_DISABLED 1520 .................... #if USB_EP3_RX_ENABLE==USB_ENABLE_DISABLED
1521 .................... #ifdef USB_EP3_RX_SIZE 1521 .................... #ifdef USB_EP3_RX_SIZE
1522 .................... #undef USB_EP3_RX_SIZE 1522 .................... #undef USB_EP3_RX_SIZE
1523 .................... #endif 1523 .................... #endif
1524 .................... #define USB_EP3_RX_SIZE 0 1524 .................... #define USB_EP3_RX_SIZE 0
1525 .................... #else 1525 .................... #else
1526 .................... #ifndef USB_EP3_RX_SIZE 1526 .................... #ifndef USB_EP3_RX_SIZE
1527 .................... #error You enabled EP3 for RX but didn't specify endpoint size 1527 .................... #error You enabled EP3 for RX but didn't specify endpoint size
1528 .................... #endif 1528 .................... #endif
1529 .................... #endif 1529 .................... #endif
1530 .................... 1530 ....................
1531 .................... #if USB_EP3_TX_ENABLE==USB_ENABLE_DISABLED 1531 .................... #if USB_EP3_TX_ENABLE==USB_ENABLE_DISABLED
1532 .................... #ifdef USB_EP3_TX_SIZE 1532 .................... #ifdef USB_EP3_TX_SIZE
1533 .................... #undef USB_EP3_TX_SIZE 1533 .................... #undef USB_EP3_TX_SIZE
1534 .................... #endif 1534 .................... #endif
1535 .................... #define USB_EP3_TX_SIZE 0 1535 .................... #define USB_EP3_TX_SIZE 0
1536 .................... #else 1536 .................... #else
1537 .................... #ifndef USB_EP3_TX_SIZE 1537 .................... #ifndef USB_EP3_TX_SIZE
1538 .................... #error You enabled EP3 for TX but didn't specify endpoint size 1538 .................... #error You enabled EP3 for TX but didn't specify endpoint size
1539 .................... #endif 1539 .................... #endif
1540 .................... #endif 1540 .................... #endif
1541 .................... 1541 ....................
1542 .................... 1542 ....................
1543 .................... //--------- endpoint 4 defines ---------- 1543 .................... //--------- endpoint 4 defines ----------
1544 .................... #ifndef USB_EP4_TX_ENABLE 1544 .................... #ifndef USB_EP4_TX_ENABLE
1545 .................... #define USB_EP4_TX_ENABLE USB_ENABLE_DISABLED 1545 .................... #define USB_EP4_TX_ENABLE USB_ENABLE_DISABLED
1546 .................... #endif 1546 .................... #endif
1547 .................... #ifndef USB_EP4_RX_ENABLE 1547 .................... #ifndef USB_EP4_RX_ENABLE
1548 .................... #define USB_EP4_RX_ENABLE USB_ENABLE_DISABLED 1548 .................... #define USB_EP4_RX_ENABLE USB_ENABLE_DISABLED
1549 .................... #endif 1549 .................... #endif
1550 .................... 1550 ....................
1551 .................... #if USB_EP4_RX_ENABLE==USB_ENABLE_DISABLED 1551 .................... #if USB_EP4_RX_ENABLE==USB_ENABLE_DISABLED
1552 .................... #ifdef USB_EP4_RX_SIZE 1552 .................... #ifdef USB_EP4_RX_SIZE
1553 .................... #undef USB_EP4_RX_SIZE 1553 .................... #undef USB_EP4_RX_SIZE
1554 .................... #endif 1554 .................... #endif
1555 .................... #define USB_EP4_RX_SIZE 0 1555 .................... #define USB_EP4_RX_SIZE 0
1556 .................... #else 1556 .................... #else
1557 .................... #ifndef USB_EP4_RX_SIZE 1557 .................... #ifndef USB_EP4_RX_SIZE
1558 .................... #error You enabled EP4 for RX but didn't specify endpoint size 1558 .................... #error You enabled EP4 for RX but didn't specify endpoint size
1559 .................... #endif 1559 .................... #endif
1560 .................... #endif 1560 .................... #endif
1561 .................... 1561 ....................
1562 .................... #if USB_EP4_TX_ENABLE==USB_ENABLE_DISABLED 1562 .................... #if USB_EP4_TX_ENABLE==USB_ENABLE_DISABLED
1563 .................... #ifdef USB_EP4_TX_SIZE 1563 .................... #ifdef USB_EP4_TX_SIZE
1564 .................... #undef USB_EP4_TX_SIZE 1564 .................... #undef USB_EP4_TX_SIZE
1565 .................... #endif 1565 .................... #endif
1566 .................... #define USB_EP4_TX_SIZE 0 1566 .................... #define USB_EP4_TX_SIZE 0
1567 .................... #else 1567 .................... #else
1568 .................... #ifndef USB_EP4_TX_SIZE 1568 .................... #ifndef USB_EP4_TX_SIZE
1569 .................... #error You enabled EP4 for TX but didn't specify endpoint size 1569 .................... #error You enabled EP4 for TX but didn't specify endpoint size
1570 .................... #endif 1570 .................... #endif
1571 .................... #endif 1571 .................... #endif
1572 .................... 1572 ....................
1573 .................... 1573 ....................
1574 .................... //--------- endpoint 5 defines ---------- 1574 .................... //--------- endpoint 5 defines ----------
1575 .................... #ifndef USB_EP5_TX_ENABLE 1575 .................... #ifndef USB_EP5_TX_ENABLE
1576 .................... #define USB_EP5_TX_ENABLE USB_ENABLE_DISABLED 1576 .................... #define USB_EP5_TX_ENABLE USB_ENABLE_DISABLED
1577 .................... #endif 1577 .................... #endif
1578 .................... #ifndef USB_EP5_RX_ENABLE 1578 .................... #ifndef USB_EP5_RX_ENABLE
1579 .................... #define USB_EP5_RX_ENABLE USB_ENABLE_DISABLED 1579 .................... #define USB_EP5_RX_ENABLE USB_ENABLE_DISABLED
1580 .................... #endif 1580 .................... #endif
1581 .................... 1581 ....................
1582 .................... #if USB_EP5_RX_ENABLE==USB_ENABLE_DISABLED 1582 .................... #if USB_EP5_RX_ENABLE==USB_ENABLE_DISABLED
1583 .................... #ifdef USB_EP5_RX_SIZE 1583 .................... #ifdef USB_EP5_RX_SIZE
1584 .................... #undef USB_EP5_RX_SIZE 1584 .................... #undef USB_EP5_RX_SIZE
1585 .................... #endif 1585 .................... #endif
1586 .................... #define USB_EP5_RX_SIZE 0 1586 .................... #define USB_EP5_RX_SIZE 0
1587 .................... #else 1587 .................... #else
1588 .................... #ifndef USB_EP5_RX_SIZE 1588 .................... #ifndef USB_EP5_RX_SIZE
1589 .................... #error You enabled EP5 for RX but didn't specify endpoint size 1589 .................... #error You enabled EP5 for RX but didn't specify endpoint size
1590 .................... #endif 1590 .................... #endif
1591 .................... #endif 1591 .................... #endif
1592 .................... 1592 ....................
1593 .................... #if USB_EP5_TX_ENABLE==USB_ENABLE_DISABLED 1593 .................... #if USB_EP5_TX_ENABLE==USB_ENABLE_DISABLED
1594 .................... #ifdef USB_EP5_TX_SIZE 1594 .................... #ifdef USB_EP5_TX_SIZE
1595 .................... #undef USB_EP5_TX_SIZE 1595 .................... #undef USB_EP5_TX_SIZE
1596 .................... #endif 1596 .................... #endif
1597 .................... #define USB_EP5_TX_SIZE 0 1597 .................... #define USB_EP5_TX_SIZE 0
1598 .................... #else 1598 .................... #else
1599 .................... #ifndef USB_EP5_TX_SIZE 1599 .................... #ifndef USB_EP5_TX_SIZE
1600 .................... #error You enabled EP5 for TX but didn't specify endpoint size 1600 .................... #error You enabled EP5 for TX but didn't specify endpoint size
1601 .................... #endif 1601 .................... #endif
1602 .................... #endif 1602 .................... #endif
1603 .................... 1603 ....................
1604 .................... 1604 ....................
1605 .................... //--------- endpoint 6 defines ---------- 1605 .................... //--------- endpoint 6 defines ----------
1606 .................... #ifndef USB_EP6_TX_ENABLE 1606 .................... #ifndef USB_EP6_TX_ENABLE
1607 .................... #define USB_EP6_TX_ENABLE USB_ENABLE_DISABLED 1607 .................... #define USB_EP6_TX_ENABLE USB_ENABLE_DISABLED
1608 .................... #endif 1608 .................... #endif
1609 .................... #ifndef USB_EP6_RX_ENABLE 1609 .................... #ifndef USB_EP6_RX_ENABLE
1610 .................... #define USB_EP6_RX_ENABLE USB_ENABLE_DISABLED 1610 .................... #define USB_EP6_RX_ENABLE USB_ENABLE_DISABLED
1611 .................... #endif 1611 .................... #endif
1612 .................... 1612 ....................
1613 .................... #if USB_EP6_RX_ENABLE==USB_ENABLE_DISABLED 1613 .................... #if USB_EP6_RX_ENABLE==USB_ENABLE_DISABLED
1614 .................... #ifdef USB_EP6_RX_SIZE 1614 .................... #ifdef USB_EP6_RX_SIZE
1615 .................... #undef USB_EP6_RX_SIZE 1615 .................... #undef USB_EP6_RX_SIZE
1616 .................... #endif 1616 .................... #endif
1617 .................... #define USB_EP6_RX_SIZE 0 1617 .................... #define USB_EP6_RX_SIZE 0
1618 .................... #else 1618 .................... #else
1619 .................... #ifndef USB_EP6_RX_SIZE 1619 .................... #ifndef USB_EP6_RX_SIZE
1620 .................... #error You enabled EP6 for RX but didn't specify endpoint size 1620 .................... #error You enabled EP6 for RX but didn't specify endpoint size
1621 .................... #endif 1621 .................... #endif
1622 .................... #endif 1622 .................... #endif
1623 .................... 1623 ....................
1624 .................... #if USB_EP6_TX_ENABLE==USB_ENABLE_DISABLED 1624 .................... #if USB_EP6_TX_ENABLE==USB_ENABLE_DISABLED
1625 .................... #ifdef USB_EP6_TX_SIZE 1625 .................... #ifdef USB_EP6_TX_SIZE
1626 .................... #undef USB_EP6_TX_SIZE 1626 .................... #undef USB_EP6_TX_SIZE
1627 .................... #endif 1627 .................... #endif
1628 .................... #define USB_EP6_TX_SIZE 0 1628 .................... #define USB_EP6_TX_SIZE 0
1629 .................... #else 1629 .................... #else
1630 .................... #ifndef USB_EP6_TX_SIZE 1630 .................... #ifndef USB_EP6_TX_SIZE
1631 .................... #error You enabled EP6 for TX but didn't specify endpoint size 1631 .................... #error You enabled EP6 for TX but didn't specify endpoint size
1632 .................... #endif 1632 .................... #endif
1633 .................... #endif 1633 .................... #endif
1634 .................... 1634 ....................
1635 .................... 1635 ....................
1636 .................... //--------- endpoint 7 defines ---------- 1636 .................... //--------- endpoint 7 defines ----------
1637 .................... #ifndef USB_EP7_TX_ENABLE 1637 .................... #ifndef USB_EP7_TX_ENABLE
1638 .................... #define USB_EP7_TX_ENABLE USB_ENABLE_DISABLED 1638 .................... #define USB_EP7_TX_ENABLE USB_ENABLE_DISABLED
1639 .................... #endif 1639 .................... #endif
1640 .................... #ifndef USB_EP7_RX_ENABLE 1640 .................... #ifndef USB_EP7_RX_ENABLE
1641 .................... #define USB_EP7_RX_ENABLE USB_ENABLE_DISABLED 1641 .................... #define USB_EP7_RX_ENABLE USB_ENABLE_DISABLED
1642 .................... #endif 1642 .................... #endif
1643 .................... 1643 ....................
1644 .................... #if USB_EP7_RX_ENABLE==USB_ENABLE_DISABLED 1644 .................... #if USB_EP7_RX_ENABLE==USB_ENABLE_DISABLED
1645 .................... #ifdef USB_EP7_RX_SIZE 1645 .................... #ifdef USB_EP7_RX_SIZE
1646 .................... #undef USB_EP7_RX_SIZE 1646 .................... #undef USB_EP7_RX_SIZE
1647 .................... #endif 1647 .................... #endif
1648 .................... #define USB_EP7_RX_SIZE 0 1648 .................... #define USB_EP7_RX_SIZE 0
1649 .................... #else 1649 .................... #else
1650 .................... #ifndef USB_EP7_RX_SIZE 1650 .................... #ifndef USB_EP7_RX_SIZE
1651 .................... #error You enabled EP7 for RX but didn't specify endpoint size 1651 .................... #error You enabled EP7 for RX but didn't specify endpoint size
1652 .................... #endif 1652 .................... #endif
1653 .................... #endif 1653 .................... #endif
1654 .................... 1654 ....................
1655 .................... #if USB_EP7_TX_ENABLE==USB_ENABLE_DISABLED 1655 .................... #if USB_EP7_TX_ENABLE==USB_ENABLE_DISABLED
1656 .................... #ifdef USB_EP7_TX_SIZE 1656 .................... #ifdef USB_EP7_TX_SIZE
1657 .................... #undef USB_EP7_TX_SIZE 1657 .................... #undef USB_EP7_TX_SIZE
1658 .................... #endif 1658 .................... #endif
1659 .................... #define USB_EP7_TX_SIZE 0 1659 .................... #define USB_EP7_TX_SIZE 0
1660 .................... #else 1660 .................... #else
1661 .................... #ifndef USB_EP7_TX_SIZE 1661 .................... #ifndef USB_EP7_TX_SIZE
1662 .................... #error You enabled EP7 for TX but didn't specify endpoint size 1662 .................... #error You enabled EP7 for TX but didn't specify endpoint size
1663 .................... #endif 1663 .................... #endif
1664 .................... #endif 1664 .................... #endif
1665 .................... 1665 ....................
1666 .................... 1666 ....................
1667 .................... //--------- endpoint 8 defines ---------- 1667 .................... //--------- endpoint 8 defines ----------
1668 .................... #ifndef USB_EP8_TX_ENABLE 1668 .................... #ifndef USB_EP8_TX_ENABLE
1669 .................... #define USB_EP8_TX_ENABLE USB_ENABLE_DISABLED 1669 .................... #define USB_EP8_TX_ENABLE USB_ENABLE_DISABLED
1670 .................... #endif 1670 .................... #endif
1671 .................... #ifndef USB_EP8_RX_ENABLE 1671 .................... #ifndef USB_EP8_RX_ENABLE
1672 .................... #define USB_EP8_RX_ENABLE USB_ENABLE_DISABLED 1672 .................... #define USB_EP8_RX_ENABLE USB_ENABLE_DISABLED
1673 .................... #endif 1673 .................... #endif
1674 .................... 1674 ....................
1675 .................... #if USB_EP8_RX_ENABLE==USB_ENABLE_DISABLED 1675 .................... #if USB_EP8_RX_ENABLE==USB_ENABLE_DISABLED
1676 .................... #ifdef USB_EP8_RX_SIZE 1676 .................... #ifdef USB_EP8_RX_SIZE
1677 .................... #undef USB_EP8_RX_SIZE 1677 .................... #undef USB_EP8_RX_SIZE
1678 .................... #endif 1678 .................... #endif
1679 .................... #define USB_EP8_RX_SIZE 0 1679 .................... #define USB_EP8_RX_SIZE 0
1680 .................... #else 1680 .................... #else
1681 .................... #ifndef USB_EP8_RX_SIZE 1681 .................... #ifndef USB_EP8_RX_SIZE
1682 .................... #error You enabled EP8 for RX but didn't specify endpoint size 1682 .................... #error You enabled EP8 for RX but didn't specify endpoint size
1683 .................... #endif 1683 .................... #endif
1684 .................... #endif 1684 .................... #endif
1685 .................... 1685 ....................
1686 .................... #if USB_EP8_TX_ENABLE==USB_ENABLE_DISABLED 1686 .................... #if USB_EP8_TX_ENABLE==USB_ENABLE_DISABLED
1687 .................... #ifdef USB_EP8_TX_SIZE 1687 .................... #ifdef USB_EP8_TX_SIZE
1688 .................... #undef USB_EP8_TX_SIZE 1688 .................... #undef USB_EP8_TX_SIZE
1689 .................... #endif 1689 .................... #endif
1690 .................... #define USB_EP8_TX_SIZE 0 1690 .................... #define USB_EP8_TX_SIZE 0
1691 .................... #else 1691 .................... #else
1692 .................... #ifndef USB_EP8_TX_SIZE 1692 .................... #ifndef USB_EP8_TX_SIZE
1693 .................... #error You enabled EP8 for TX but didn't specify endpoint size 1693 .................... #error You enabled EP8 for TX but didn't specify endpoint size
1694 .................... #endif 1694 .................... #endif
1695 .................... #endif 1695 .................... #endif
1696 .................... 1696 ....................
1697 .................... 1697 ....................
1698 .................... //--------- endpoint 9 defines ---------- 1698 .................... //--------- endpoint 9 defines ----------
1699 .................... #ifndef USB_EP9_TX_ENABLE 1699 .................... #ifndef USB_EP9_TX_ENABLE
1700 .................... #define USB_EP9_TX_ENABLE USB_ENABLE_DISABLED 1700 .................... #define USB_EP9_TX_ENABLE USB_ENABLE_DISABLED
1701 .................... #endif 1701 .................... #endif
1702 .................... #ifndef USB_EP9_RX_ENABLE 1702 .................... #ifndef USB_EP9_RX_ENABLE
1703 .................... #define USB_EP9_RX_ENABLE USB_ENABLE_DISABLED 1703 .................... #define USB_EP9_RX_ENABLE USB_ENABLE_DISABLED
1704 .................... #endif 1704 .................... #endif
1705 .................... 1705 ....................
1706 .................... #if USB_EP9_RX_ENABLE==USB_ENABLE_DISABLED 1706 .................... #if USB_EP9_RX_ENABLE==USB_ENABLE_DISABLED
1707 .................... #ifdef USB_EP9_RX_SIZE 1707 .................... #ifdef USB_EP9_RX_SIZE
1708 .................... #undef USB_EP9_RX_SIZE 1708 .................... #undef USB_EP9_RX_SIZE
1709 .................... #endif 1709 .................... #endif
1710 .................... #define USB_EP9_RX_SIZE 0 1710 .................... #define USB_EP9_RX_SIZE 0
1711 .................... #else 1711 .................... #else
1712 .................... #ifndef USB_EP9_RX_SIZE 1712 .................... #ifndef USB_EP9_RX_SIZE
1713 .................... #error You enabled EP9 for RX but didn't specify endpoint size 1713 .................... #error You enabled EP9 for RX but didn't specify endpoint size
1714 .................... #endif 1714 .................... #endif
1715 .................... #endif 1715 .................... #endif
1716 .................... 1716 ....................
1717 .................... #if USB_EP9_TX_ENABLE==USB_ENABLE_DISABLED 1717 .................... #if USB_EP9_TX_ENABLE==USB_ENABLE_DISABLED
1718 .................... #ifdef USB_EP9_TX_SIZE 1718 .................... #ifdef USB_EP9_TX_SIZE
1719 .................... #undef USB_EP9_TX_SIZE 1719 .................... #undef USB_EP9_TX_SIZE
1720 .................... #endif 1720 .................... #endif
1721 .................... #define USB_EP9_TX_SIZE 0 1721 .................... #define USB_EP9_TX_SIZE 0
1722 .................... #else 1722 .................... #else
1723 .................... #ifndef USB_EP9_TX_SIZE 1723 .................... #ifndef USB_EP9_TX_SIZE
1724 .................... #error You enabled EP9 for TX but didn't specify endpoint size 1724 .................... #error You enabled EP9 for TX but didn't specify endpoint size
1725 .................... #endif 1725 .................... #endif
1726 .................... #endif 1726 .................... #endif
1727 .................... 1727 ....................
1728 .................... 1728 ....................
1729 .................... //--------- endpoint 10 defines ---------- 1729 .................... //--------- endpoint 10 defines ----------
1730 .................... #ifndef USB_EP10_TX_ENABLE 1730 .................... #ifndef USB_EP10_TX_ENABLE
1731 .................... #define USB_EP10_TX_ENABLE USB_ENABLE_DISABLED 1731 .................... #define USB_EP10_TX_ENABLE USB_ENABLE_DISABLED
1732 .................... #endif 1732 .................... #endif
1733 .................... #ifndef USB_EP10_RX_ENABLE 1733 .................... #ifndef USB_EP10_RX_ENABLE
1734 .................... #define USB_EP10_RX_ENABLE USB_ENABLE_DISABLED 1734 .................... #define USB_EP10_RX_ENABLE USB_ENABLE_DISABLED
1735 .................... #endif 1735 .................... #endif
1736 .................... 1736 ....................
1737 .................... #if USB_EP10_RX_ENABLE==USB_ENABLE_DISABLED 1737 .................... #if USB_EP10_RX_ENABLE==USB_ENABLE_DISABLED
1738 .................... #ifdef USB_EP10_RX_SIZE 1738 .................... #ifdef USB_EP10_RX_SIZE
1739 .................... #undef USB_EP10_RX_SIZE 1739 .................... #undef USB_EP10_RX_SIZE
1740 .................... #endif 1740 .................... #endif
1741 .................... #define USB_EP10_RX_SIZE 0 1741 .................... #define USB_EP10_RX_SIZE 0
1742 .................... #else 1742 .................... #else
1743 .................... #ifndef USB_EP10_RX_SIZE 1743 .................... #ifndef USB_EP10_RX_SIZE
1744 .................... #error You enabled EP10 for RX but didn't specify endpoint size 1744 .................... #error You enabled EP10 for RX but didn't specify endpoint size
1745 .................... #endif 1745 .................... #endif
1746 .................... #endif 1746 .................... #endif
1747 .................... 1747 ....................
1748 .................... #if USB_EP10_TX_ENABLE==USB_ENABLE_DISABLED 1748 .................... #if USB_EP10_TX_ENABLE==USB_ENABLE_DISABLED
1749 .................... #ifdef USB_EP10_TX_SIZE 1749 .................... #ifdef USB_EP10_TX_SIZE
1750 .................... #undef USB_EP10_TX_SIZE 1750 .................... #undef USB_EP10_TX_SIZE
1751 .................... #endif 1751 .................... #endif
1752 .................... #define USB_EP10_TX_SIZE 0 1752 .................... #define USB_EP10_TX_SIZE 0
1753 .................... #else 1753 .................... #else
1754 .................... #ifndef USB_EP10_TX_SIZE 1754 .................... #ifndef USB_EP10_TX_SIZE
1755 .................... #error You enabled EP10 for TX but didn't specify endpoint size 1755 .................... #error You enabled EP10 for TX but didn't specify endpoint size
1756 .................... #endif 1756 .................... #endif
1757 .................... #endif 1757 .................... #endif
1758 .................... 1758 ....................
1759 .................... 1759 ....................
1760 .................... //--------- endpoint 11 defines ---------- 1760 .................... //--------- endpoint 11 defines ----------
1761 .................... #ifndef USB_EP11_TX_ENABLE 1761 .................... #ifndef USB_EP11_TX_ENABLE
1762 .................... #define USB_EP11_TX_ENABLE USB_ENABLE_DISABLED 1762 .................... #define USB_EP11_TX_ENABLE USB_ENABLE_DISABLED
1763 .................... #endif 1763 .................... #endif
1764 .................... #ifndef USB_EP11_RX_ENABLE 1764 .................... #ifndef USB_EP11_RX_ENABLE
1765 .................... #define USB_EP11_RX_ENABLE USB_ENABLE_DISABLED 1765 .................... #define USB_EP11_RX_ENABLE USB_ENABLE_DISABLED
1766 .................... #endif 1766 .................... #endif
1767 .................... 1767 ....................
1768 .................... #if USB_EP11_RX_ENABLE==USB_ENABLE_DISABLED 1768 .................... #if USB_EP11_RX_ENABLE==USB_ENABLE_DISABLED
1769 .................... #ifdef USB_EP11_RX_SIZE 1769 .................... #ifdef USB_EP11_RX_SIZE
1770 .................... #undef USB_EP11_RX_SIZE 1770 .................... #undef USB_EP11_RX_SIZE
1771 .................... #endif 1771 .................... #endif
1772 .................... #define USB_EP11_RX_SIZE 0 1772 .................... #define USB_EP11_RX_SIZE 0
1773 .................... #else 1773 .................... #else
1774 .................... #ifndef USB_EP11_RX_SIZE 1774 .................... #ifndef USB_EP11_RX_SIZE
1775 .................... #error You enabled EP11 for RX but didn't specify endpoint size 1775 .................... #error You enabled EP11 for RX but didn't specify endpoint size
1776 .................... #endif 1776 .................... #endif
1777 .................... #endif 1777 .................... #endif
1778 .................... 1778 ....................
1779 .................... #if USB_EP11_TX_ENABLE==USB_ENABLE_DISABLED 1779 .................... #if USB_EP11_TX_ENABLE==USB_ENABLE_DISABLED
1780 .................... #ifdef USB_EP11_TX_SIZE 1780 .................... #ifdef USB_EP11_TX_SIZE
1781 .................... #undef USB_EP11_TX_SIZE 1781 .................... #undef USB_EP11_TX_SIZE
1782 .................... #endif 1782 .................... #endif
1783 .................... #define USB_EP11_TX_SIZE 0 1783 .................... #define USB_EP11_TX_SIZE 0
1784 .................... #else 1784 .................... #else
1785 .................... #ifndef USB_EP11_TX_SIZE 1785 .................... #ifndef USB_EP11_TX_SIZE
1786 .................... #error You enabled EP11 for TX but didn't specify endpoint size 1786 .................... #error You enabled EP11 for TX but didn't specify endpoint size
1787 .................... #endif 1787 .................... #endif
1788 .................... #endif 1788 .................... #endif
1789 .................... 1789 ....................
1790 .................... 1790 ....................
1791 .................... //--------- endpoint 12 defines ---------- 1791 .................... //--------- endpoint 12 defines ----------
1792 .................... #ifndef USB_EP12_TX_ENABLE 1792 .................... #ifndef USB_EP12_TX_ENABLE
1793 .................... #define USB_EP12_TX_ENABLE USB_ENABLE_DISABLED 1793 .................... #define USB_EP12_TX_ENABLE USB_ENABLE_DISABLED
1794 .................... #endif 1794 .................... #endif
1795 .................... #ifndef USB_EP12_RX_ENABLE 1795 .................... #ifndef USB_EP12_RX_ENABLE
1796 .................... #define USB_EP12_RX_ENABLE USB_ENABLE_DISABLED 1796 .................... #define USB_EP12_RX_ENABLE USB_ENABLE_DISABLED
1797 .................... #endif 1797 .................... #endif
1798 .................... 1798 ....................
1799 .................... #if USB_EP12_RX_ENABLE==USB_ENABLE_DISABLED 1799 .................... #if USB_EP12_RX_ENABLE==USB_ENABLE_DISABLED
1800 .................... #ifdef USB_EP12_RX_SIZE 1800 .................... #ifdef USB_EP12_RX_SIZE
1801 .................... #undef USB_EP12_RX_SIZE 1801 .................... #undef USB_EP12_RX_SIZE
1802 .................... #endif 1802 .................... #endif
1803 .................... #define USB_EP12_RX_SIZE 0 1803 .................... #define USB_EP12_RX_SIZE 0
1804 .................... #else 1804 .................... #else
1805 .................... #ifndef USB_EP12_RX_SIZE 1805 .................... #ifndef USB_EP12_RX_SIZE
1806 .................... #error You enabled EP12 for RX but didn't specify endpoint size 1806 .................... #error You enabled EP12 for RX but didn't specify endpoint size
1807 .................... #endif 1807 .................... #endif
1808 .................... #endif 1808 .................... #endif
1809 .................... 1809 ....................
1810 .................... #if USB_EP12_TX_ENABLE==USB_ENABLE_DISABLED 1810 .................... #if USB_EP12_TX_ENABLE==USB_ENABLE_DISABLED
1811 .................... #ifdef USB_EP12_TX_SIZE 1811 .................... #ifdef USB_EP12_TX_SIZE
1812 .................... #undef USB_EP12_TX_SIZE 1812 .................... #undef USB_EP12_TX_SIZE
1813 .................... #endif 1813 .................... #endif
1814 .................... #define USB_EP12_TX_SIZE 0 1814 .................... #define USB_EP12_TX_SIZE 0
1815 .................... #else 1815 .................... #else
1816 .................... #ifndef USB_EP12_TX_SIZE 1816 .................... #ifndef USB_EP12_TX_SIZE
1817 .................... #error You enabled EP12 for TX but didn't specify endpoint size 1817 .................... #error You enabled EP12 for TX but didn't specify endpoint size
1818 .................... #endif 1818 .................... #endif
1819 .................... #endif 1819 .................... #endif
1820 .................... 1820 ....................
1821 .................... 1821 ....................
1822 .................... //--------- endpoint 13 defines ---------- 1822 .................... //--------- endpoint 13 defines ----------
1823 .................... #ifndef USB_EP13_TX_ENABLE 1823 .................... #ifndef USB_EP13_TX_ENABLE
1824 .................... #define USB_EP13_TX_ENABLE USB_ENABLE_DISABLED 1824 .................... #define USB_EP13_TX_ENABLE USB_ENABLE_DISABLED
1825 .................... #endif 1825 .................... #endif
1826 .................... #ifndef USB_EP13_RX_ENABLE 1826 .................... #ifndef USB_EP13_RX_ENABLE
1827 .................... #define USB_EP13_RX_ENABLE USB_ENABLE_DISABLED 1827 .................... #define USB_EP13_RX_ENABLE USB_ENABLE_DISABLED
1828 .................... #endif 1828 .................... #endif
1829 .................... 1829 ....................
1830 .................... #if USB_EP13_RX_ENABLE==USB_ENABLE_DISABLED 1830 .................... #if USB_EP13_RX_ENABLE==USB_ENABLE_DISABLED
1831 .................... #ifdef USB_EP13_RX_SIZE 1831 .................... #ifdef USB_EP13_RX_SIZE
1832 .................... #undef USB_EP13_RX_SIZE 1832 .................... #undef USB_EP13_RX_SIZE
1833 .................... #endif 1833 .................... #endif
1834 .................... #define USB_EP13_RX_SIZE 0 1834 .................... #define USB_EP13_RX_SIZE 0
1835 .................... #else 1835 .................... #else
1836 .................... #ifndef USB_EP13_RX_SIZE 1836 .................... #ifndef USB_EP13_RX_SIZE
1837 .................... #error You enabled EP13 for RX but didn't specify endpoint size 1837 .................... #error You enabled EP13 for RX but didn't specify endpoint size
1838 .................... #endif 1838 .................... #endif
1839 .................... #endif 1839 .................... #endif
1840 .................... 1840 ....................
1841 .................... #if USB_EP13_TX_ENABLE==USB_ENABLE_DISABLED 1841 .................... #if USB_EP13_TX_ENABLE==USB_ENABLE_DISABLED
1842 .................... #ifdef USB_EP13_TX_SIZE 1842 .................... #ifdef USB_EP13_TX_SIZE
1843 .................... #undef USB_EP13_TX_SIZE 1843 .................... #undef USB_EP13_TX_SIZE
1844 .................... #endif 1844 .................... #endif
1845 .................... #define USB_EP13_TX_SIZE 0 1845 .................... #define USB_EP13_TX_SIZE 0
1846 .................... #else 1846 .................... #else
1847 .................... #ifndef USB_EP13_TX_SIZE 1847 .................... #ifndef USB_EP13_TX_SIZE
1848 .................... #error You enabled EP13 for TX but didn't specify endpoint size 1848 .................... #error You enabled EP13 for TX but didn't specify endpoint size
1849 .................... #endif 1849 .................... #endif
1850 .................... #endif 1850 .................... #endif
1851 .................... 1851 ....................
1852 .................... 1852 ....................
1853 .................... //--------- endpoint 14 defines ---------- 1853 .................... //--------- endpoint 14 defines ----------
1854 .................... #ifndef USB_EP14_TX_ENABLE 1854 .................... #ifndef USB_EP14_TX_ENABLE
1855 .................... #define USB_EP14_TX_ENABLE USB_ENABLE_DISABLED 1855 .................... #define USB_EP14_TX_ENABLE USB_ENABLE_DISABLED
1856 .................... #endif 1856 .................... #endif
1857 .................... #ifndef USB_EP14_RX_ENABLE 1857 .................... #ifndef USB_EP14_RX_ENABLE
1858 .................... #define USB_EP14_RX_ENABLE USB_ENABLE_DISABLED 1858 .................... #define USB_EP14_RX_ENABLE USB_ENABLE_DISABLED
1859 .................... #endif 1859 .................... #endif
1860 .................... 1860 ....................
1861 .................... #if USB_EP14_RX_ENABLE==USB_ENABLE_DISABLED 1861 .................... #if USB_EP14_RX_ENABLE==USB_ENABLE_DISABLED
1862 .................... #ifdef USB_EP14_RX_SIZE 1862 .................... #ifdef USB_EP14_RX_SIZE
1863 .................... #undef USB_EP14_RX_SIZE 1863 .................... #undef USB_EP14_RX_SIZE
1864 .................... #endif 1864 .................... #endif
1865 .................... #define USB_EP14_RX_SIZE 0 1865 .................... #define USB_EP14_RX_SIZE 0
1866 .................... #else 1866 .................... #else
1867 .................... #ifndef USB_EP14_RX_SIZE 1867 .................... #ifndef USB_EP14_RX_SIZE
1868 .................... #error You enabled EP14 for RX but didn't specify endpoint size 1868 .................... #error You enabled EP14 for RX but didn't specify endpoint size
1869 .................... #endif 1869 .................... #endif
1870 .................... #endif 1870 .................... #endif
1871 .................... 1871 ....................
1872 .................... #if USB_EP14_TX_ENABLE==USB_ENABLE_DISABLED 1872 .................... #if USB_EP14_TX_ENABLE==USB_ENABLE_DISABLED
1873 .................... #ifdef USB_EP14_TX_SIZE 1873 .................... #ifdef USB_EP14_TX_SIZE
1874 .................... #undef USB_EP14_TX_SIZE 1874 .................... #undef USB_EP14_TX_SIZE
1875 .................... #endif 1875 .................... #endif
1876 .................... #define USB_EP14_TX_SIZE 0 1876 .................... #define USB_EP14_TX_SIZE 0
1877 .................... #else 1877 .................... #else
1878 .................... #ifndef USB_EP14_TX_SIZE 1878 .................... #ifndef USB_EP14_TX_SIZE
1879 .................... #error You enabled EP14 for TX but didn't specify endpoint size 1879 .................... #error You enabled EP14 for TX but didn't specify endpoint size
1880 .................... #endif 1880 .................... #endif
1881 .................... #endif 1881 .................... #endif
1882 .................... 1882 ....................
1883 .................... 1883 ....................
1884 .................... //--------- endpoint 15 defines ---------- 1884 .................... //--------- endpoint 15 defines ----------
1885 .................... #ifndef USB_EP15_TX_ENABLE 1885 .................... #ifndef USB_EP15_TX_ENABLE
1886 .................... #define USB_EP15_TX_ENABLE USB_ENABLE_DISABLED 1886 .................... #define USB_EP15_TX_ENABLE USB_ENABLE_DISABLED
1887 .................... #endif 1887 .................... #endif
1888 .................... #ifndef USB_EP15_RX_ENABLE 1888 .................... #ifndef USB_EP15_RX_ENABLE
1889 .................... #define USB_EP15_RX_ENABLE USB_ENABLE_DISABLED 1889 .................... #define USB_EP15_RX_ENABLE USB_ENABLE_DISABLED
1890 .................... #endif 1890 .................... #endif
1891 .................... 1891 ....................
1892 .................... #if USB_EP15_RX_ENABLE==USB_ENABLE_DISABLED 1892 .................... #if USB_EP15_RX_ENABLE==USB_ENABLE_DISABLED
1893 .................... #ifdef USB_EP15_RX_SIZE 1893 .................... #ifdef USB_EP15_RX_SIZE
1894 .................... #undef USB_EP15_RX_SIZE 1894 .................... #undef USB_EP15_RX_SIZE
1895 .................... #endif 1895 .................... #endif
1896 .................... #define USB_EP15_RX_SIZE 0 1896 .................... #define USB_EP15_RX_SIZE 0
1897 .................... #else 1897 .................... #else
1898 .................... #ifndef USB_EP15_RX_SIZE 1898 .................... #ifndef USB_EP15_RX_SIZE
1899 .................... #error You enabled EP15 for RX but didn't specify endpoint size 1899 .................... #error You enabled EP15 for RX but didn't specify endpoint size
1900 .................... #endif 1900 .................... #endif
1901 .................... #endif 1901 .................... #endif
1902 .................... 1902 ....................
1903 .................... #if USB_EP15_TX_ENABLE==USB_ENABLE_DISABLED 1903 .................... #if USB_EP15_TX_ENABLE==USB_ENABLE_DISABLED
1904 .................... #ifdef USB_EP15_TX_SIZE 1904 .................... #ifdef USB_EP15_TX_SIZE
1905 .................... #undef USB_EP15_TX_SIZE 1905 .................... #undef USB_EP15_TX_SIZE
1906 .................... #endif 1906 .................... #endif
1907 .................... #define USB_EP15_TX_SIZE 0 1907 .................... #define USB_EP15_TX_SIZE 0
1908 .................... #else 1908 .................... #else
1909 .................... #ifndef USB_EP15_TX_SIZE 1909 .................... #ifndef USB_EP15_TX_SIZE
1910 .................... #error You enabled EP15 for TX but didn't specify endpoint size 1910 .................... #error You enabled EP15 for TX but didn't specify endpoint size
1911 .................... #endif 1911 .................... #endif
1912 .................... #endif 1912 .................... #endif
1913 .................... 1913 ....................
1914 .................... const int8 usb_ep_tx_type[16]={ 1914 .................... const int8 usb_ep_tx_type[16]={
1915 .................... USB_EP0_TX_ENABLE, USB_EP1_TX_ENABLE, USB_EP2_TX_ENABLE, 1915 .................... USB_EP0_TX_ENABLE, USB_EP1_TX_ENABLE, USB_EP2_TX_ENABLE,
1916 .................... USB_EP3_TX_ENABLE, USB_EP4_TX_ENABLE, USB_EP5_TX_ENABLE, 1916 .................... USB_EP3_TX_ENABLE, USB_EP4_TX_ENABLE, USB_EP5_TX_ENABLE,
1917 .................... USB_EP6_TX_ENABLE, USB_EP7_TX_ENABLE, USB_EP8_TX_ENABLE, 1917 .................... USB_EP6_TX_ENABLE, USB_EP7_TX_ENABLE, USB_EP8_TX_ENABLE,
1918 .................... USB_EP9_TX_ENABLE, USB_EP10_TX_ENABLE, USB_EP11_TX_ENABLE, 1918 .................... USB_EP9_TX_ENABLE, USB_EP10_TX_ENABLE, USB_EP11_TX_ENABLE,
1919 .................... USB_EP12_TX_ENABLE, USB_EP13_TX_ENABLE, USB_EP14_TX_ENABLE, 1919 .................... USB_EP12_TX_ENABLE, USB_EP13_TX_ENABLE, USB_EP14_TX_ENABLE,
1920 .................... USB_EP15_TX_ENABLE 1920 .................... USB_EP15_TX_ENABLE
1921 .................... }; 1921 .................... };
1922 .................... 1922 ....................
1923 .................... const int8 usb_ep_rx_type[16]={ 1923 .................... const int8 usb_ep_rx_type[16]={
1924 .................... USB_EP0_RX_ENABLE, USB_EP1_RX_ENABLE, USB_EP2_RX_ENABLE, 1924 .................... USB_EP0_RX_ENABLE, USB_EP1_RX_ENABLE, USB_EP2_RX_ENABLE,
1925 .................... USB_EP3_RX_ENABLE, USB_EP4_RX_ENABLE, USB_EP5_RX_ENABLE, 1925 .................... USB_EP3_RX_ENABLE, USB_EP4_RX_ENABLE, USB_EP5_RX_ENABLE,
1926 .................... USB_EP6_RX_ENABLE, USB_EP7_RX_ENABLE, USB_EP8_RX_ENABLE, 1926 .................... USB_EP6_RX_ENABLE, USB_EP7_RX_ENABLE, USB_EP8_RX_ENABLE,
1927 .................... USB_EP9_RX_ENABLE, USB_EP10_RX_ENABLE, USB_EP11_RX_ENABLE, 1927 .................... USB_EP9_RX_ENABLE, USB_EP10_RX_ENABLE, USB_EP11_RX_ENABLE,
1928 .................... USB_EP12_RX_ENABLE, USB_EP13_RX_ENABLE, USB_EP14_RX_ENABLE, 1928 .................... USB_EP12_RX_ENABLE, USB_EP13_RX_ENABLE, USB_EP14_RX_ENABLE,
1929 .................... USB_EP15_RX_ENABLE 1929 .................... USB_EP15_RX_ENABLE
1930 .................... }; 1930 .................... };
1931 .................... 1931 ....................
1932 .................... const unsigned int16 usb_ep_tx_size[16]={ 1932 .................... const unsigned int16 usb_ep_tx_size[16]={
1933 .................... USB_EP0_TX_SIZE, USB_EP1_TX_SIZE, USB_EP2_TX_SIZE, 1933 .................... USB_EP0_TX_SIZE, USB_EP1_TX_SIZE, USB_EP2_TX_SIZE,
1934 .................... USB_EP3_TX_SIZE, USB_EP4_TX_SIZE, USB_EP5_TX_SIZE, 1934 .................... USB_EP3_TX_SIZE, USB_EP4_TX_SIZE, USB_EP5_TX_SIZE,
1935 .................... USB_EP6_TX_SIZE, USB_EP7_TX_SIZE, USB_EP8_TX_SIZE, 1935 .................... USB_EP6_TX_SIZE, USB_EP7_TX_SIZE, USB_EP8_TX_SIZE,
1936 .................... USB_EP9_TX_SIZE, USB_EP10_TX_SIZE, USB_EP11_TX_SIZE, 1936 .................... USB_EP9_TX_SIZE, USB_EP10_TX_SIZE, USB_EP11_TX_SIZE,
1937 .................... USB_EP12_TX_SIZE, USB_EP13_TX_SIZE, USB_EP14_TX_SIZE, 1937 .................... USB_EP12_TX_SIZE, USB_EP13_TX_SIZE, USB_EP14_TX_SIZE,
1938 .................... USB_EP15_TX_SIZE 1938 .................... USB_EP15_TX_SIZE
1939 .................... }; 1939 .................... };
1940 .................... 1940 ....................
1941 .................... const unsigned int16 usb_ep_rx_size[16]={ 1941 .................... const unsigned int16 usb_ep_rx_size[16]={
1942 .................... USB_EP0_RX_SIZE, USB_EP1_RX_SIZE, USB_EP2_RX_SIZE, 1942 .................... USB_EP0_RX_SIZE, USB_EP1_RX_SIZE, USB_EP2_RX_SIZE,
1943 .................... USB_EP3_RX_SIZE, USB_EP4_RX_SIZE, USB_EP5_RX_SIZE, 1943 .................... USB_EP3_RX_SIZE, USB_EP4_RX_SIZE, USB_EP5_RX_SIZE,
1944 .................... USB_EP6_RX_SIZE, USB_EP7_RX_SIZE, USB_EP8_RX_SIZE, 1944 .................... USB_EP6_RX_SIZE, USB_EP7_RX_SIZE, USB_EP8_RX_SIZE,
1945 .................... USB_EP9_RX_SIZE, USB_EP10_RX_SIZE, USB_EP11_RX_SIZE, 1945 .................... USB_EP9_RX_SIZE, USB_EP10_RX_SIZE, USB_EP11_RX_SIZE,
1946 .................... USB_EP12_RX_SIZE, USB_EP13_RX_SIZE, USB_EP14_RX_SIZE, 1946 .................... USB_EP12_RX_SIZE, USB_EP13_RX_SIZE, USB_EP14_RX_SIZE,
1947 .................... USB_EP15_RX_SIZE 1947 .................... USB_EP15_RX_SIZE
1948 .................... }; 1948 .................... };
1949 .................... 1949 ....................
1950 .................... #ENDIF 1950 .................... #ENDIF
1951 .................... 1951 ....................
1952 .................... 1952 ....................
1953 .................... ////////////////////////////////////////////////////////////////// 1953 .................... //////////////////////////////////////////////////////////////////
1954 .................... /// 1954 .................... ///
1955 .................... /// start config descriptor 1955 .................... /// start config descriptor
1956 .................... /// right now we only support one configuration descriptor. 1956 .................... /// right now we only support one configuration descriptor.
1957 .................... /// the config, interface, class, and endpoint goes into this array. 1957 .................... /// the config, interface, class, and endpoint goes into this array.
1958 .................... /// 1958 .................... ///
1959 .................... ////////////////////////////////////////////////////////////////// 1959 .................... //////////////////////////////////////////////////////////////////
1960 .................... 1960 ....................
1961 .................... #DEFINE USB_TOTAL_CONFIG_LEN 67 //config+interface+class+endpoint+endpoint (2 endpoints) 1961 .................... #DEFINE USB_TOTAL_CONFIG_LEN 67 //config+interface+class+endpoint+endpoint (2 endpoints)
1962 .................... 1962 ....................
1963 .................... const char USB_CONFIG_DESC[] = { 1963 .................... const char USB_CONFIG_DESC[] = {
1964 .................... //IN ORDER TO COMPLY WITH WINDOWS HOSTS, THE ORDER OF THIS ARRAY MUST BE: 1964 .................... //IN ORDER TO COMPLY WITH WINDOWS HOSTS, THE ORDER OF THIS ARRAY MUST BE:
1965 .................... // config(s) 1965 .................... // config(s)
1966 .................... // interface(s) 1966 .................... // interface(s)
1967 .................... // class(es) 1967 .................... // class(es)
1968 .................... // endpoint(s) 1968 .................... // endpoint(s)
1969 .................... 1969 ....................
1970 .................... //config_descriptor for config index 1 1970 .................... //config_descriptor for config index 1
1971 .................... USB_DESC_CONFIG_LEN, //length of descriptor size ==0 1971 .................... USB_DESC_CONFIG_LEN, //length of descriptor size ==0
1972 .................... USB_DESC_CONFIG_TYPE, //constant CONFIGURATION (CONFIGURATION 0x02) ==1 1972 .................... USB_DESC_CONFIG_TYPE, //constant CONFIGURATION (CONFIGURATION 0x02) ==1
1973 .................... USB_TOTAL_CONFIG_LEN,0, //size of all data returned for this config ==2,3 1973 .................... USB_TOTAL_CONFIG_LEN,0, //size of all data returned for this config ==2,3
1974 .................... 2, //number of interfaces this device supports ==4 1974 .................... 2, //number of interfaces this device supports ==4
1975 .................... 0x01, //identifier for this configuration. (IF we had more than one configurations) ==5 1975 .................... 0x01, //identifier for this configuration. (IF we had more than one configurations) ==5
1976 .................... 0x00, //index of string descriptor for this configuration ==6 1976 .................... 0x00, //index of string descriptor for this configuration ==6
1977 .................... #if USB_CONFIG_BUS_POWER 1977 .................... #if USB_CONFIG_BUS_POWER
1978 .................... 0x80, //bit 6=1 if self powered, bit 5=1 if supports remote wakeup (we don't), bits 0-4 unused and bit7=1 ==7 1978 .................... 0x80, //bit 6=1 if self powered, bit 5=1 if supports remote wakeup (we don't), bits 0-4 unused and bit7=1 ==7
1979 .................... #else 1979 .................... #else
1980 .................... 0xC0, //bit 6=1 if self powered, bit 5=1 if supports remote wakeup (we don't), bits 0-4 unused and bit7=1 ==7 1980 .................... 0xC0, //bit 6=1 if self powered, bit 5=1 if supports remote wakeup (we don't), bits 0-4 unused and bit7=1 ==7
1981 .................... #endif 1981 .................... #endif
1982 .................... USB_CONFIG_BUS_POWER/2, //maximum bus power required (maximum milliamperes/2) (0x32 = 100mA) ==8 1982 .................... USB_CONFIG_BUS_POWER/2, //maximum bus power required (maximum milliamperes/2) (0x32 = 100mA) ==8
1983 .................... 1983 ....................
1984 .................... 1984 ....................
1985 .................... //interface descriptor 0 (comm class interface) 1985 .................... //interface descriptor 0 (comm class interface)
1986 .................... USB_DESC_INTERFACE_LEN, //length of descriptor =9 1986 .................... USB_DESC_INTERFACE_LEN, //length of descriptor =9
1987 .................... USB_DESC_INTERFACE_TYPE, //constant INTERFACE (INTERFACE 0x04) =10 1987 .................... USB_DESC_INTERFACE_TYPE, //constant INTERFACE (INTERFACE 0x04) =10
1988 .................... 0x00, //number defining this interface (IF we had more than one interface) ==11 1988 .................... 0x00, //number defining this interface (IF we had more than one interface) ==11
1989 .................... 0x00, //alternate setting ==12 1989 .................... 0x00, //alternate setting ==12
1990 .................... 1, //number of endpoints ==13 1990 .................... 1, //number of endpoints ==13
1991 .................... 0x02, //class code, 02 = Comm Interface Class ==14 1991 .................... 0x02, //class code, 02 = Comm Interface Class ==14
1992 .................... 0x02, //subclass code, 2 = Abstract ==15 1992 .................... 0x02, //subclass code, 2 = Abstract ==15
1993 .................... 0x01, //protocol code, 1 = v.25ter ==16 1993 .................... 0x01, //protocol code, 1 = v.25ter ==16
1994 .................... 0x00, //index of string descriptor for interface ==17 1994 .................... 0x00, //index of string descriptor for interface ==17
1995 .................... 1995 ....................
1996 .................... //class descriptor [functional header] 1996 .................... //class descriptor [functional header]
1997 .................... 5, //length of descriptor ==18 1997 .................... 5, //length of descriptor ==18
1998 .................... 0x24, //dscriptor type (0x24 == ) ==19 1998 .................... 0x24, //dscriptor type (0x24 == ) ==19
1999 .................... 0, //sub type (0=functional header) ==20 1999 .................... 0, //sub type (0=functional header) ==20
2000 .................... 0x10,0x01, // ==21,22 //cdc version 2000 .................... 0x10,0x01, // ==21,22 //cdc version
2001 .................... 2001 ....................
2002 .................... //class descriptor [acm header] 2002 .................... //class descriptor [acm header]
2003 .................... 4, //length of descriptor ==23 2003 .................... 4, //length of descriptor ==23
2004 .................... 0x24, //dscriptor type (0x24 == ) ==24 2004 .................... 0x24, //dscriptor type (0x24 == ) ==24
2005 .................... 2, //sub type (2=ACM) ==25 2005 .................... 2, //sub type (2=ACM) ==25
2006 .................... 2, //capabilities ==26 //we support Set_Line_Coding, Set_Control_Line_State, Get_Line_Coding, and the notification Serial_State. 2006 .................... 2, //capabilities ==26 //we support Set_Line_Coding, Set_Control_Line_State, Get_Line_Coding, and the notification Serial_State.
2007 .................... 2007 ....................
2008 .................... //class descriptor [union header] 2008 .................... //class descriptor [union header]
2009 .................... 5, //length of descriptor ==27 2009 .................... 5, //length of descriptor ==27
2010 .................... 0x24, //dscriptor type (0x24 == ) ==28 2010 .................... 0x24, //dscriptor type (0x24 == ) ==28
2011 .................... 6, //sub type (6=union) ==29 2011 .................... 6, //sub type (6=union) ==29
2012 .................... 0, //master intf ==30 //The interface number of the Communication or Dat a Cl ass interface, designated as the masteror controlling interface for the union. 2012 .................... 0, //master intf ==30 //The interface number of the Communication or Dat a Cl ass interface, designated as the masteror controlling interface for the union.
2013 .................... 1, //save intf0 ==31 //Interface number of first slave or associated interface in the union. * 2013 .................... 1, //save intf0 ==31 //Interface number of first slave or associated interface in the union. *
2014 .................... 2014 ....................
2015 .................... //class descriptor [call mgmt header] 2015 .................... //class descriptor [call mgmt header]
2016 .................... 5, //length of descriptor ==32 2016 .................... 5, //length of descriptor ==32
2017 .................... 0x24, //dscriptor type (0x24 == ) ==33 2017 .................... 0x24, //dscriptor type (0x24 == ) ==33
2018 .................... 1, //sub type (1=call mgmt) ==34 2018 .................... 1, //sub type (1=call mgmt) ==34
2019 .................... 0, //capabilities ==35 //device does not handle call management itself 2019 .................... 0, //capabilities ==35 //device does not handle call management itself
2020 .................... 1, //data interface ==36 //interface number of data class interface 2020 .................... 1, //data interface ==36 //interface number of data class interface
2021 .................... 2021 ....................
2022 .................... //endpoint descriptor 2022 .................... //endpoint descriptor
2023 .................... USB_DESC_ENDPOINT_LEN, //length of descriptor ==37 2023 .................... USB_DESC_ENDPOINT_LEN, //length of descriptor ==37
2024 .................... USB_DESC_ENDPOINT_TYPE, //constant ENDPOINT (ENDPOINT 0x05) ==38 2024 .................... USB_DESC_ENDPOINT_TYPE, //constant ENDPOINT (ENDPOINT 0x05) ==38
2025 .................... USB_CDC_COMM_IN_ENDPOINT | 0x80, //endpoint number and direction 2025 .................... USB_CDC_COMM_IN_ENDPOINT | 0x80, //endpoint number and direction
2026 .................... 0x03, //transfer type supported (0x03 is interrupt) ==40 2026 .................... 0x03, //transfer type supported (0x03 is interrupt) ==40
2027 .................... USB_CDC_COMM_IN_SIZE,0x00, //maximum packet size supported ==41,42 2027 .................... USB_CDC_COMM_IN_SIZE,0x00, //maximum packet size supported ==41,42
2028 .................... 250, //polling interval, in ms. (interrupt endpoint cant be smaller than 10 for slow speed devices) ==43 2028 .................... 250, //polling interval, in ms. (interrupt endpoint cant be smaller than 10 for slow speed devices) ==43
2029 .................... 2029 ....................
2030 .................... //interface descriptor 1 (data class interface) 2030 .................... //interface descriptor 1 (data class interface)
2031 .................... USB_DESC_INTERFACE_LEN, //length of descriptor =44 2031 .................... USB_DESC_INTERFACE_LEN, //length of descriptor =44
2032 .................... USB_DESC_INTERFACE_TYPE, //constant INTERFACE (INTERFACE 0x04) =45 2032 .................... USB_DESC_INTERFACE_TYPE, //constant INTERFACE (INTERFACE 0x04) =45
2033 .................... 0x01, //number defining this interface (IF we had more than one interface) ==46 2033 .................... 0x01, //number defining this interface (IF we had more than one interface) ==46
2034 .................... 0x00, //alternate setting ==47 2034 .................... 0x00, //alternate setting ==47
2035 .................... 2, //number of endpoints ==48 2035 .................... 2, //number of endpoints ==48
2036 .................... 0x0A, //class code, 0A = Data Interface Class ==49 2036 .................... 0x0A, //class code, 0A = Data Interface Class ==49
2037 .................... 0x00, //subclass code ==50 2037 .................... 0x00, //subclass code ==50
2038 .................... 0x00, //protocol code ==51 2038 .................... 0x00, //protocol code ==51
2039 .................... 0x00, //index of string descriptor for interface ==52 2039 .................... 0x00, //index of string descriptor for interface ==52
2040 .................... 2040 ....................
2041 .................... //endpoint descriptor 2041 .................... //endpoint descriptor
2042 .................... USB_DESC_ENDPOINT_LEN, //length of descriptor ==53 2042 .................... USB_DESC_ENDPOINT_LEN, //length of descriptor ==53
2043 .................... USB_DESC_ENDPOINT_TYPE, //constant ENDPOINT (ENDPOINT 0x05) ==54 2043 .................... USB_DESC_ENDPOINT_TYPE, //constant ENDPOINT (ENDPOINT 0x05) ==54
2044 .................... USB_CDC_DATA_OUT_ENDPOINT, //endpoint number and direction (0x02 = EP2 OUT) ==55 2044 .................... USB_CDC_DATA_OUT_ENDPOINT, //endpoint number and direction (0x02 = EP2 OUT) ==55
2045 .................... 0x02, //transfer type supported (0x02 is bulk) ==56 2045 .................... 0x02, //transfer type supported (0x02 is bulk) ==56
2046 .................... (USB_CDC_DATA_OUT_SIZE+1) & 0xFF, ((USB_CDC_DATA_OUT_SIZE+1) >> 8) & 0xFF, //maximum packet size supported ==57, 58 2046 .................... (USB_CDC_DATA_OUT_SIZE+1) & 0xFF, ((USB_CDC_DATA_OUT_SIZE+1) >> 8) & 0xFF, //maximum packet size supported ==57, 58
2047 .................... 1, //polling interval, in ms. ==59 2047 .................... 1, //polling interval, in ms. ==59
2048 .................... 2048 ....................
2049 .................... //endpoint descriptor 2049 .................... //endpoint descriptor
2050 .................... USB_DESC_ENDPOINT_LEN, //length of descriptor ==60 2050 .................... USB_DESC_ENDPOINT_LEN, //length of descriptor ==60
2051 .................... USB_DESC_ENDPOINT_TYPE, //constant ENDPOINT (ENDPOINT 0x05) ==61 2051 .................... USB_DESC_ENDPOINT_TYPE, //constant ENDPOINT (ENDPOINT 0x05) ==61
2052 .................... USB_CDC_DATA_IN_ENDPOINT | 0x80, //endpoint number and direction (0x82 = EP2 IN) ==62 2052 .................... USB_CDC_DATA_IN_ENDPOINT | 0x80, //endpoint number and direction (0x82 = EP2 IN) ==62
2053 .................... 0x02, //transfer type supported (0x02 is bulk) ==63 2053 .................... 0x02, //transfer type supported (0x02 is bulk) ==63
2054 .................... (USB_CDC_DATA_IN_SIZE+1) & 0xFF, ((USB_CDC_DATA_IN_SIZE+1) >> 8) & 0xFF, //maximum packet size supported ==66, 67 2054 .................... (USB_CDC_DATA_IN_SIZE+1) & 0xFF, ((USB_CDC_DATA_IN_SIZE+1) >> 8) & 0xFF, //maximum packet size supported ==66, 67
2055 .................... 1, //polling interval, in ms. ==68 2055 .................... 1, //polling interval, in ms. ==68
2056 .................... }; 2056 .................... };
2057 .................... 2057 ....................
2058 .................... //****** BEGIN CONFIG DESCRIPTOR LOOKUP TABLES ******** 2058 .................... //****** BEGIN CONFIG DESCRIPTOR LOOKUP TABLES ********
2059 .................... //since we can't make pointers to constants in certain pic16s, this is an offset table to find 2059 .................... //since we can't make pointers to constants in certain pic16s, this is an offset table to find
2060 .................... // a specific descriptor in the above table. 2060 .................... // a specific descriptor in the above table.
2061 .................... 2061 ....................
2062 .................... //the maximum number of interfaces seen on any config 2062 .................... //the maximum number of interfaces seen on any config
2063 .................... //for example, if config 1 has 1 interface and config 2 has 2 interfaces you must define this as 2 2063 .................... //for example, if config 1 has 1 interface and config 2 has 2 interfaces you must define this as 2
2064 .................... #define USB_MAX_NUM_INTERFACES 2 2064 .................... #define USB_MAX_NUM_INTERFACES 2
2065 .................... 2065 ....................
2066 .................... //define how many interfaces there are per config. [0] is the first config, etc. 2066 .................... //define how many interfaces there are per config. [0] is the first config, etc.
2067 .................... const char USB_NUM_INTERFACES[USB_NUM_CONFIGURATIONS]={2}; 2067 .................... const char USB_NUM_INTERFACES[USB_NUM_CONFIGURATIONS]={2};
2068 .................... 2068 ....................
2069 .................... //define where to find class descriptors 2069 .................... //define where to find class descriptors
2070 .................... //first dimension is the config number 2070 .................... //first dimension is the config number
2071 .................... //second dimension specifies which interface 2071 .................... //second dimension specifies which interface
2072 .................... //last dimension specifies which class in this interface to get, but most will only have 1 class per interface 2072 .................... //last dimension specifies which class in this interface to get, but most will only have 1 class per interface
2073 .................... //if a class descriptor is not valid, set the value to 0xFFFF 2073 .................... //if a class descriptor is not valid, set the value to 0xFFFF
2074 .................... const int8 USB_CLASS_DESCRIPTORS[USB_NUM_CONFIGURATIONS][USB_MAX_NUM_INTERFACES][4]= 2074 .................... const int8 USB_CLASS_DESCRIPTORS[USB_NUM_CONFIGURATIONS][USB_MAX_NUM_INTERFACES][4]=
2075 .................... { 2075 .................... {
2076 .................... //config 1 2076 .................... //config 1
2077 .................... //interface 0 2077 .................... //interface 0
2078 .................... //class 1-4 2078 .................... //class 1-4
2079 .................... 18,23,27,32, 2079 .................... 18,23,27,32,
2080 .................... //interface 1 2080 .................... //interface 1
2081 .................... //no classes for this interface 2081 .................... //no classes for this interface
2082 .................... 0xFF,0xFF,0xFF,0xFF 2082 .................... 0xFF,0xFF,0xFF,0xFF
2083 .................... }; 2083 .................... };
2084 .................... 2084 ....................
2085 .................... #if (sizeof(USB_CONFIG_DESC) != USB_TOTAL_CONFIG_LEN) 2085 .................... #if (sizeof(USB_CONFIG_DESC) != USB_TOTAL_CONFIG_LEN)
2086 .................... #error USB_TOTAL_CONFIG_LEN not defined correctly 2086 .................... #error USB_TOTAL_CONFIG_LEN not defined correctly
2087 .................... #endif 2087 .................... #endif
2088 .................... 2088 ....................
2089 .................... 2089 ....................
2090 .................... ////////////////////////////////////////////////////////////////// 2090 .................... //////////////////////////////////////////////////////////////////
2091 .................... /// 2091 .................... ///
2092 .................... /// start device descriptors 2092 .................... /// start device descriptors
2093 .................... /// 2093 .................... ///
2094 .................... ////////////////////////////////////////////////////////////////// 2094 .................... //////////////////////////////////////////////////////////////////
2095 .................... 2095 ....................
2096 .................... const char USB_DEVICE_DESC[USB_DESC_DEVICE_LEN] ={ 2096 .................... const char USB_DEVICE_DESC[USB_DESC_DEVICE_LEN] ={
2097 .................... //starts of with device configuration. only one possible 2097 .................... //starts of with device configuration. only one possible
2098 .................... USB_DESC_DEVICE_LEN, //the length of this report ==0 2098 .................... USB_DESC_DEVICE_LEN, //the length of this report ==0
2099 .................... 0x01, //the constant DEVICE (DEVICE 0x01) ==1 2099 .................... 0x01, //the constant DEVICE (DEVICE 0x01) ==1
2100 .................... 0x10,0x01, //usb version in bcd ==2,3 2100 .................... 0x10,0x01, //usb version in bcd ==2,3
2101 .................... 0x02, //class code. 0x02=Communication Device Class ==4 2101 .................... 0x02, //class code. 0x02=Communication Device Class ==4
2102 .................... 0x00, //subclass code ==5 2102 .................... 0x00, //subclass code ==5
2103 .................... 0x00, //protocol code ==6 2103 .................... 0x00, //protocol code ==6
2104 .................... USB_MAX_EP0_PACKET_LENGTH, //max packet size for endpoint 0. (SLOW SPEED SPECIFIES 8) ==7 2104 .................... USB_MAX_EP0_PACKET_LENGTH, //max packet size for endpoint 0. (SLOW SPEED SPECIFIES 8) ==7
2105 .................... USB_CONFIG_VID & 0xFF, ((USB_CONFIG_VID >> 8) & 0xFF), //vendor id ==9, 10 2105 .................... USB_CONFIG_VID & 0xFF, ((USB_CONFIG_VID >> 8) & 0xFF), //vendor id ==9, 10
2106 .................... USB_CONFIG_PID & 0xFF, ((USB_CONFIG_PID >> 8) & 0xFF), //product id, don't use 0xffff ==11, 12 2106 .................... USB_CONFIG_PID & 0xFF, ((USB_CONFIG_PID >> 8) & 0xFF), //product id, don't use 0xffff ==11, 12
2107 .................... USB_CONFIG_VERSION & 0xFF, ((USB_CONFIG_VERSION >> 8) & 0xFF), //device release number ==13,14 2107 .................... USB_CONFIG_VERSION & 0xFF, ((USB_CONFIG_VERSION >> 8) & 0xFF), //device release number ==13,14
2108 .................... 0x01, //index of string description of manufacturer. therefore we point to string_1 array (see below) ==14 2108 .................... 0x01, //index of string description of manufacturer. therefore we point to string_1 array (see below) ==14
2109 .................... 0x02, //index of string descriptor of the product ==15 2109 .................... 0x02, //index of string descriptor of the product ==15
2110 .................... 0x00, //index of string descriptor of serial number ==16 2110 .................... 0x00, //index of string descriptor of serial number ==16
2111 .................... USB_NUM_CONFIGURATIONS //number of possible configurations ==17 2111 .................... USB_NUM_CONFIGURATIONS //number of possible configurations ==17
2112 .................... }; 2112 .................... };
2113 .................... 2113 ....................
2114 .................... 2114 ....................
2115 .................... ////////////////////////////////////////////////////////////////// 2115 .................... //////////////////////////////////////////////////////////////////
2116 .................... /// 2116 .................... ///
2117 .................... /// start string descriptors 2117 .................... /// start string descriptors
2118 .................... /// String 0 is a special language string, and must be defined. People in U.S.A. can leave this alone. 2118 .................... /// String 0 is a special language string, and must be defined. People in U.S.A. can leave this alone.
2119 .................... /// 2119 .................... ///
2120 .................... /// You must define the length else get_next_string_character() will not see the string 2120 .................... /// You must define the length else get_next_string_character() will not see the string
2121 .................... /// Current code only supports 10 strings (0 thru 9) 2121 .................... /// Current code only supports 10 strings (0 thru 9)
2122 .................... /// 2122 .................... ///
2123 .................... ////////////////////////////////////////////////////////////////// 2123 .................... //////////////////////////////////////////////////////////////////
2124 .................... 2124 ....................
2125 .................... #if !defined(USB_STRINGS_OVERWRITTEN) 2125 .................... #if !defined(USB_STRINGS_OVERWRITTEN)
2126 .................... //the offset of the starting location of each string. offset[0] is the start of string 0, offset[1] is the start of string 1, etc. 2126 .................... //the offset of the starting location of each string. offset[0] is the start of string 0, offset[1] is the start of string 1, etc.
2127 .................... char USB_STRING_DESC_OFFSET[]={0,4,12}; 2127 .................... char USB_STRING_DESC_OFFSET[]={0,4,12};
2128 .................... 2128 ....................
2129 .................... // Here is where the "CCS" Manufacturer string and "SERIAL DEMO" are stored. 2129 .................... // Here is where the "CCS" Manufacturer string and "SERIAL DEMO" are stored.
2130 .................... // Strings are saved as unicode. 2130 .................... // Strings are saved as unicode.
2131 .................... // These strings are mostly only displayed during the add hardware wizard. 2131 .................... // These strings are mostly only displayed during the add hardware wizard.
2132 .................... // Once the operating system drivers have been installed it will usually display 2132 .................... // Once the operating system drivers have been installed it will usually display
2133 .................... // the name from the drivers .INF. 2133 .................... // the name from the drivers .INF.
2134 .................... char const USB_STRING_DESC[]={ 2134 .................... char const USB_STRING_DESC[]={
2135 .................... //string 0 2135 .................... //string 0
2136 .................... 4, //length of string index 2136 .................... 4, //length of string index
2137 .................... USB_DESC_STRING_TYPE, //descriptor type 0x03 (STRING) 2137 .................... USB_DESC_STRING_TYPE, //descriptor type 0x03 (STRING)
2138 .................... 0x09,0x04, //Microsoft Defined for US-English 2138 .................... 0x09,0x04, //Microsoft Defined for US-English
2139 .................... //string 1 - manufacturer 2139 .................... //string 1 - manufacturer
2140 .................... 8, //length of string index 2140 .................... 8, //length of string index
2141 .................... USB_DESC_STRING_TYPE, //descriptor type 0x03 (STRING) 2141 .................... USB_DESC_STRING_TYPE, //descriptor type 0x03 (STRING)
2142 .................... 'C',0, 2142 .................... 'C',0,
2143 .................... 'C',0, 2143 .................... 'C',0,
2144 .................... 'S',0, 2144 .................... 'S',0,
2145 .................... //string 2 - product 2145 .................... //string 2 - product
2146 .................... 24, //length of string index 2146 .................... 24, //length of string index
2147 .................... USB_DESC_STRING_TYPE, //descriptor type 0x03 (STRING) 2147 .................... USB_DESC_STRING_TYPE, //descriptor type 0x03 (STRING)
2148 .................... 'S',0, 2148 .................... 'S',0,
2149 .................... 'E',0, 2149 .................... 'E',0,
2150 .................... 'R',0, 2150 .................... 'R',0,
2151 .................... 'I',0, 2151 .................... 'I',0,
2152 .................... 'A',0, 2152 .................... 'A',0,
2153 .................... 'L',0, 2153 .................... 'L',0,
2154 .................... ' ',0, 2154 .................... ' ',0,
2155 .................... 'D',0, 2155 .................... 'D',0,
2156 .................... 'E',0, 2156 .................... 'E',0,
2157 .................... 'M',0, 2157 .................... 'M',0,
2158 .................... 'O',0 2158 .................... 'O',0
2159 .................... }; 2159 .................... };
2160 .................... #endif //!defined(USB_STRINGS_OVERWRITTEN) 2160 .................... #endif //!defined(USB_STRINGS_OVERWRITTEN)
2161 .................... 2161 ....................
2162 .................... #ENDIF 2162 .................... #ENDIF
2163 .................... 2163 ....................
2164 .................... #include <usb.c> //handles usb setup tokens and get descriptor reports 2164 .................... #include <usb.c> //handles usb setup tokens and get descriptor reports
2165 .................... /////////////////////////////////////////////////////////////////////////// 2165 .................... ///////////////////////////////////////////////////////////////////////////
2166 .................... //// usb.c //// 2166 .................... //// usb.c ////
2167 .................... //// //// 2167 .................... //// ////
2168 .................... //// Standard USB request and token handler code. //// 2168 .................... //// Standard USB request and token handler code. ////
2169 .................... //// //// 2169 .................... //// ////
2170 .................... //// This file is part of CCS's PIC USB driver code. See USB.H //// 2170 .................... //// This file is part of CCS's PIC USB driver code. See USB.H ////
2171 .................... //// for more documentation and a list of examples. //// 2171 .................... //// for more documentation and a list of examples. ////
2172 .................... //// //// 2172 .................... //// ////
2173 .................... //// The majority of this code is called and used by the interrupt //// 2173 .................... //// The majority of this code is called and used by the interrupt ////
2174 .................... //// generated by the hardware level, and therefore it is not meant //// 2174 .................... //// generated by the hardware level, and therefore it is not meant ////
2175 .................... //// to be called by the user. The functions that are meant to be //// 2175 .................... //// to be called by the user. The functions that are meant to be ////
2176 .................... //// called by the user (init, put packet, get packet, etc) are //// 2176 .................... //// called by the user (init, put packet, get packet, etc) are ////
2177 .................... //// documented in USB.H. //// 2177 .................... //// documented in USB.H. ////
2178 .................... //// //// 2178 .................... //// ////
2179 .................... //// ************************* NOTE ************************** //// 2179 .................... //// ************************* NOTE ************************** ////
2180 .................... //// This code will not create a multiple configuration device. //// 2180 .................... //// This code will not create a multiple configuration device. ////
2181 .................... //// If you wish to create a multiple configuration device then you //// 2181 .................... //// If you wish to create a multiple configuration device then you ////
2182 .................... //// will have to modify these drivers. //// 2182 .................... //// will have to modify these drivers. ////
2183 .................... //// //// 2183 .................... //// ////
2184 .................... //// ************************* NOTE ************************** //// 2184 .................... //// ************************* NOTE ************************** ////
2185 .................... //// This code does not support Get_Idle or Set_Idle HID-specific //// 2185 .................... //// This code does not support Get_Idle or Set_Idle HID-specific ////
2186 .................... //// requests. These requests are optional. If you want to support //// 2186 .................... //// requests. These requests are optional. If you want to support ////
2187 .................... //// these requests you must provide the code yourself. See //// 2187 .................... //// these requests you must provide the code yourself. See ////
2188 .................... //// usb_isr_tkn_setup_ClassInterface() if you wish to add this //// 2188 .................... //// usb_isr_tkn_setup_ClassInterface() if you wish to add this ////
2189 .................... //// support. //// 2189 .................... //// support. ////
2190 .................... //// //// 2190 .................... //// ////
2191 .................... /////////////////////////////////////////////////////////////////////////// 2191 .................... ///////////////////////////////////////////////////////////////////////////
2192 .................... //// //// 2192 .................... //// ////
2193 .................... //// If you wish to provide your own USB peripheral hardware layer, it //// 2193 .................... //// If you wish to provide your own USB peripheral hardware layer, it ////
2194 .................... //// must must provide the API as described in usb_hw_layer.h. //// 2194 .................... //// must must provide the API as described in usb_hw_layer.h. ////
2195 .................... //// //// 2195 .................... //// ////
2196 .................... /////////////////////////////////////////////////////////////////////////// 2196 .................... ///////////////////////////////////////////////////////////////////////////
2197 .................... //// //// 2197 .................... //// ////
2198 .................... //// Version History: //// 2198 .................... //// Version History: ////
2199 .................... //// //// 2199 .................... //// ////
2200 .................... //// March 5th, 2009: //// 2200 .................... //// March 5th, 2009: ////
2201 .................... //// Cleanup for Wizard. //// 2201 .................... //// Cleanup for Wizard. ////
2202 .................... //// PIC24 Initial release. //// 2202 .................... //// PIC24 Initial release. ////
2203 .................... //// //// 2203 .................... //// ////
2204 .................... //// Dec 14, 2007: //// 2204 .................... //// Dec 14, 2007: ////
2205 .................... //// usb_kbhit() moved to device driver. //// 2205 .................... //// usb_kbhit() moved to device driver. ////
2206 .................... //// //// 2206 .................... //// ////
2207 .................... //// July 13th, 2005: //// 2207 .................... //// July 13th, 2005: ////
2208 .................... //// usb_puts() packet_size and this_packet_len changed to 16bits. //// 2208 .................... //// usb_puts() packet_size and this_packet_len changed to 16bits. ////
2209 .................... //// usb_gets() len, packet_size and this_packet_len to 16bits. //// 2209 .................... //// usb_gets() len, packet_size and this_packet_len to 16bits. ////
2210 .................... //// //// 2210 .................... //// ////
2211 .................... //// June 20th, 2005: //// 2211 .................... //// June 20th, 2005: ////
2212 .................... //// Initial 18fxx5x release. //// 2212 .................... //// Initial 18fxx5x release. ////
2213 .................... //// usb_kbhit() removed, usb_kbhit() now implemented in hardware //// 2213 .................... //// usb_kbhit() removed, usb_kbhit() now implemented in hardware ////
2214 .................... //// layer. //// 2214 .................... //// layer. ////
2215 .................... //// //// 2215 .................... //// ////
2216 .................... //// May 13th, 2005: //// 2216 .................... //// May 13th, 2005: ////
2217 .................... //// Beta release, only works with 18Fxx5x hardware layer. //// 2217 .................... //// Beta release, only works with 18Fxx5x hardware layer. ////
2218 .................... //// Now supports multiple interfaces (many defines in descriptors //// 2218 .................... //// Now supports multiple interfaces (many defines in descriptors ////
2219 .................... //// will have to be changed, see examples) //// 2219 .................... //// will have to be changed, see examples) ////
2220 .................... //// TODO: alot of indexing and length handling for descriptors is //// 2220 .................... //// TODO: alot of indexing and length handling for descriptors is ////
2221 .................... //// only 8bit, so make sure all descriptor tables are less than //// 2221 .................... //// only 8bit, so make sure all descriptor tables are less than ////
2222 .................... //// 256 bytes long. //// 2222 .................... //// 256 bytes long. ////
2223 .................... //// //// 2223 .................... //// ////
2224 .................... //// Apr 21st, 2005: //// 2224 .................... //// Apr 21st, 2005: ////
2225 .................... //// Initial Alpha Release with PIC18Fxx5x support. (ONLY TESTED //// 2225 .................... //// Initial Alpha Release with PIC18Fxx5x support. (ONLY TESTED ////
2226 .................... //// WITH 18F4550) //// 2226 .................... //// WITH 18F4550) ////
2227 .................... //// usb_puts() doesn't need max packet size as a paremeter, uses //// 2227 .................... //// usb_puts() doesn't need max packet size as a paremeter, uses ////
2228 .................... //// usb_ep_tx_size[] defined in usb.h //// 2228 .................... //// usb_ep_tx_size[] defined in usb.h ////
2229 .................... //// usb_puts() timeout parameter now in ms, not seconds. //// 2229 .................... //// usb_puts() timeout parameter now in ms, not seconds. ////
2230 .................... //// USB Stack no longer buffers incoming data. If there is data to //// 2230 .................... //// USB Stack no longer buffers incoming data. If there is data to ////
2231 .................... //// get usb_kbhit(en) will return TRUE and the data will sit in //// 2231 .................... //// get usb_kbhit(en) will return TRUE and the data will sit in ////
2232 .................... //// the endpoint buffer until you usb_get_packet(), which will //// 2232 .................... //// the endpoint buffer until you usb_get_packet(), which will ////
2233 .................... //// then free the endpoint buffer for more data. This affects //// 2233 .................... //// then free the endpoint buffer for more data. This affects ////
2234 .................... //// routines such as usb_gets() and usb_kbhit(). //// 2234 .................... //// routines such as usb_gets() and usb_kbhit(). ////
2235 .................... //// usb_gets() no longer reads buffered data (see above note), //// 2235 .................... //// usb_gets() no longer reads buffered data (see above note), ////
2236 .................... //// now it reads multiple packets in the same way usb_puts() //// 2236 .................... //// now it reads multiple packets in the same way usb_puts() ////
2237 .................... //// writes multiple packets //// 2237 .................... //// writes multiple packets ////
2238 .................... //// usb_kbhit() is hardware specific, so has been moved to hardware //// 2238 .................... //// usb_kbhit() is hardware specific, so has been moved to hardware ////
2239 .................... //// layer. //// 2239 .................... //// layer. ////
2240 .................... //// //// 2240 .................... //// ////
2241 .................... //// Nov 11th, 2004: //// 2241 .................... //// Nov 11th, 2004: ////
2242 .................... //// No longer includes wrong descriptor header. //// 2242 .................... //// No longer includes wrong descriptor header. ////
2243 .................... //// //// 2243 .................... //// ////
2244 .................... //// June 24th, 2004: //// 2244 .................... //// June 24th, 2004: ////
2245 .................... //// Optimization and cleanup. //// 2245 .................... //// Optimization and cleanup. ////
2246 .................... //// The following definitions changed: //// 2246 .................... //// The following definitions changed: ////
2247 .................... //// USB_EPx_TX_ENABLE and USB_EPx_RX_ENABLE have changed. See usb.h //// 2247 .................... //// USB_EPx_TX_ENABLE and USB_EPx_RX_ENABLE have changed. See usb.h ////
2248 .................... //// USB_CONFIG_DESCRIPTORS[] removed //// 2248 .................... //// USB_CONFIG_DESCRIPTORS[] removed ////
2249 .................... //// USB_CONFIG_DESC_LEN changed to USB_DESC_CONFIG_LEN //// 2249 .................... //// USB_CONFIG_DESC_LEN changed to USB_DESC_CONFIG_LEN ////
2250 .................... //// USB_INTERFACE_DESC_LEN changed to USB_DESC_INTERFACE_LEN //// 2250 .................... //// USB_INTERFACE_DESC_LEN changed to USB_DESC_INTERFACE_LEN ////
2251 .................... //// USB_CLASS_DESC_LEN changed to USB_DESC_CLASS_LEN //// 2251 .................... //// USB_CLASS_DESC_LEN changed to USB_DESC_CLASS_LEN ////
2252 .................... //// USB_ENDPOINT_DESC_LEN changed to USB_DESC_ENDPOINT_LEN //// 2252 .................... //// USB_ENDPOINT_DESC_LEN changed to USB_DESC_ENDPOINT_LEN ////
2253 .................... //// USB_CONFIG_DESC_KEY changed to USB_DESC_CONFIG_TYPE //// 2253 .................... //// USB_CONFIG_DESC_KEY changed to USB_DESC_CONFIG_TYPE ////
2254 .................... //// USB_INTERFACE_DESC_KEY changed to USB_DESC_INTERFACE_TYPE //// 2254 .................... //// USB_INTERFACE_DESC_KEY changed to USB_DESC_INTERFACE_TYPE ////
2255 .................... //// USB_CLASS_DESC_KEY changed to USB_DESC_CLASS_TYPE //// 2255 .................... //// USB_CLASS_DESC_KEY changed to USB_DESC_CLASS_TYPE ////
2256 .................... //// USB_ENDPOINT_DESC_KEY changed to USB_DESC_ENDPOINT_TYPE //// 2256 .................... //// USB_ENDPOINT_DESC_KEY changed to USB_DESC_ENDPOINT_TYPE ////
2257 .................... //// USB_STRING_X[] arrays removed, see USB_STRING_DESC[] and //// 2257 .................... //// USB_STRING_X[] arrays removed, see USB_STRING_DESC[] and ////
2258 .................... //// USB_STRING_DESC_OFFSET[] //// 2258 .................... //// USB_STRING_DESC_OFFSET[] ////
2259 .................... //// dev_req, curr_config, status_device and getdesc_type global //// 2259 .................... //// dev_req, curr_config, status_device and getdesc_type global ////
2260 .................... //// variables moved into struct USB_stack_status //// 2260 .................... //// variables moved into struct USB_stack_status ////
2261 .................... //// //// 2261 .................... //// ////
2262 .................... //// December 5th, 2003: Fixed a potential bug where descriptors are //// 2262 .................... //// December 5th, 2003: Fixed a potential bug where descriptors are ////
2263 .................... //// evenly dividable by 8 (MAX_EP0_PACKET_SIZE) //// 2263 .................... //// evenly dividable by 8 (MAX_EP0_PACKET_SIZE) ////
2264 .................... //// //// 2264 .................... //// ////
2265 .................... //// October 15th, 2003: Support for boot protocol added. //// 2265 .................... //// October 15th, 2003: Support for boot protocol added. ////
2266 .................... //// Set USB_HID_BOOT_PROTOCOL to TRUE to support this. //// 2266 .................... //// Set USB_HID_BOOT_PROTOCOL to TRUE to support this. ////
2267 .................... //// The array hid_protocol[] saves which protocol mode each //// 2267 .................... //// The array hid_protocol[] saves which protocol mode each ////
2268 .................... //// interface is in. It is your applications job to send //// 2268 .................... //// interface is in. It is your applications job to send ////
2269 .................... //// data that either fit the boot protocol or HID protocol. //// 2269 .................... //// data that either fit the boot protocol or HID protocol. ////
2270 .................... //// //// 2270 .................... //// ////
2271 .................... //// May 6th, 2003: Fixed a potential stack overflow using PCM //// 2271 .................... //// May 6th, 2003: Fixed a potential stack overflow using PCM ////
2272 .................... //// //// 2272 .................... //// ////
2273 .................... //// October 28th, 2002: Problem with usb_puts and timeout fixed. //// 2273 .................... //// October 28th, 2002: Problem with usb_puts and timeout fixed. ////
2274 .................... //// //// 2274 .................... //// ////
2275 .................... //// October 28th, 2002: Typo fixed in get_next_string_character(), //// 2275 .................... //// October 28th, 2002: Typo fixed in get_next_string_character(), ////
2276 .................... //// although it didn't cause any serious problems //// 2276 .................... //// although it didn't cause any serious problems ////
2277 .................... //// //// 2277 .................... //// ////
2278 .................... //// October 25th, 2002: Another change to usb_puts() was made to fix //// 2278 .................... //// October 25th, 2002: Another change to usb_puts() was made to fix ////
2279 .................... //// problems with multiple packet messages //// 2279 .................... //// problems with multiple packet messages ////
2280 .................... //// October 29th, 2002: Fixed a problem with multiple packet string //// 2280 .................... //// October 29th, 2002: Fixed a problem with multiple packet string ////
2281 .................... //// descriptors that require a 0 len packet to //// 2281 .................... //// descriptors that require a 0 len packet to ////
2282 .................... //// end message. //// 2282 .................... //// end message. ////
2283 .................... //// //// 2283 .................... //// ////
2284 .................... //// October 23rd, 2002: usb_puts() will bomb out of error quicker //// 2284 .................... //// October 23rd, 2002: usb_puts() will bomb out of error quicker ////
2285 .................... //// //// 2285 .................... //// ////
2286 .................... //// August 2nd, 2002: Initial Public Release //// 2286 .................... //// August 2nd, 2002: Initial Public Release ////
2287 .................... //// //// 2287 .................... //// ////
2288 .................... /////////////////////////////////////////////////////////////////////////// 2288 .................... ///////////////////////////////////////////////////////////////////////////
2289 .................... //// (C) Copyright 1996,2005 Custom Computer Services //// 2289 .................... //// (C) Copyright 1996,2005 Custom Computer Services ////
2290 .................... //// This source code may only be used by licensed users of the CCS //// 2290 .................... //// This source code may only be used by licensed users of the CCS ////
2291 .................... //// C compiler. This source code may only be distributed to other //// 2291 .................... //// C compiler. This source code may only be distributed to other ////
2292 .................... //// licensed users of the CCS C compiler. No other use, //// 2292 .................... //// licensed users of the CCS C compiler. No other use, ////
2293 .................... //// reproduction or distribution is permitted without written //// 2293 .................... //// reproduction or distribution is permitted without written ////
2294 .................... //// permission. Derivative programs created using this software //// 2294 .................... //// permission. Derivative programs created using this software ////
2295 .................... //// in object code form are not restricted in any way. //// 2295 .................... //// in object code form are not restricted in any way. ////
2296 .................... /////////////////////////////////////////////////////////////////////////// 2296 .................... ///////////////////////////////////////////////////////////////////////////
2297 .................... 2297 ....................
2298 .................... #IFNDEF __USB_DRIVER__ 2298 .................... #IFNDEF __USB_DRIVER__
2299 .................... #DEFINE __USB_DRIVER__ 2299 .................... #DEFINE __USB_DRIVER__
2300 .................... 2300 ....................
2301 .................... #include <usb.h> 2301 .................... #include <usb.h>
2302 .................... /////////////////////////////////////////////////////////////////////////// 2302 .................... ///////////////////////////////////////////////////////////////////////////
2303 .................... //// usb.h //// 2303 .................... //// usb.h ////
2304 .................... //// //// 2304 .................... //// ////
2305 .................... //// Function protypes, defintions and globals used by CCS USB driver //// 2305 .................... //// Function protypes, defintions and globals used by CCS USB driver ////
2306 .................... //// //// 2306 .................... //// ////
2307 .................... //// This file is part of CCS's USB driver code //// 2307 .................... //// This file is part of CCS's USB driver code ////
2308 .................... //// //// 2308 .................... //// ////
2309 .................... //// The following USB examples are provided by CCS: //// 2309 .................... //// The following USB examples are provided by CCS: ////
2310 .................... //// ex_usb_mouse.c - A HID Mouse. //// 2310 .................... //// ex_usb_mouse.c - A HID Mouse. ////
2311 .................... //// ex_usb_hid.c - A custom application using HID protocol. //// 2311 .................... //// ex_usb_hid.c - A custom application using HID protocol. ////
2312 .................... //// ex_usb_kbmouse.c - A HID Mouse/Keyboard combo using multiple //// 2312 .................... //// ex_usb_kbmouse.c - A HID Mouse/Keyboard combo using multiple ////
2313 .................... //// interfaces. //// 2313 .................... //// interfaces. ////
2314 .................... //// ex_usb_kbmouse2.c - A HID Mouse/Keyboard combo using multiple //// 2314 .................... //// ex_usb_kbmouse2.c - A HID Mouse/Keyboard combo using multiple ////
2315 .................... //// HID Reports. //// 2315 .................... //// HID Reports. ////
2316 .................... //// ex_usb_scope.c - A digital oscilloscope using a custom //// 2316 .................... //// ex_usb_scope.c - A digital oscilloscope using a custom ////
2317 .................... //// protocol requiring custom Windows drivers. //// 2317 .................... //// protocol requiring custom Windows drivers. ////
2318 .................... //// ex_usb_serial.c - //// 2318 .................... //// ex_usb_serial.c - ////
2319 .................... //// ex_usb_serial2.c - Two examples of using the CDC driver for //// 2319 .................... //// ex_usb_serial2.c - Two examples of using the CDC driver for ////
2320 .................... //// a virtual COM port. //// 2320 .................... //// a virtual COM port. ////
2321 .................... //// ex_usb_bootloader.c - CDC/Virtual COM port bootloader. //// 2321 .................... //// ex_usb_bootloader.c - CDC/Virtual COM port bootloader. ////
2322 .................... //// ex_usb_loadmouse.c - A conversion of ex_usb_mouse.c that is //// 2322 .................... //// ex_usb_loadmouse.c - A conversion of ex_usb_mouse.c that is ////
2323 .................... //// compatible with ex_usb_mouse.c. //// 2323 .................... //// compatible with ex_usb_mouse.c. ////
2324 .................... //// //// 2324 .................... //// ////
2325 .................... //// ********************** API ********************* //// 2325 .................... //// ********************** API ********************* ////
2326 .................... //// //// 2326 .................... //// ////
2327 .................... //// These are the functions that are meant to be called by the user: //// 2327 .................... //// These are the functions that are meant to be called by the user: ////
2328 .................... //// //// 2328 .................... //// ////
2329 .................... //// usb_init() - Initializes the USB stack, the USB peripheral and //// 2329 .................... //// usb_init() - Initializes the USB stack, the USB peripheral and ////
2330 .................... //// attaches the unit to the usb bus. Enables //// 2330 .................... //// attaches the unit to the usb bus. Enables ////
2331 .................... //// interrupts. Will wait in an infinite loop until //// 2331 .................... //// interrupts. Will wait in an infinite loop until ////
2332 .................... //// the device enumerates - if you are using //// 2332 .................... //// the device enumerates - if you are using ////
2333 .................... //// connection sense or if the processor should run //// 2333 .................... //// connection sense or if the processor should run ////
2334 .................... //// even if it's not connected to USB then use //// 2334 .................... //// even if it's not connected to USB then use ////
2335 .................... //// usb_init_cs() instead. //// 2335 .................... //// usb_init_cs() instead. ////
2336 .................... //// //// 2336 .................... //// ////
2337 .................... //// usb_init_cs() - A smaller usb_init(), does not attach unit //// 2337 .................... //// usb_init_cs() - A smaller usb_init(), does not attach unit ////
2338 .................... //// to usb bus or enable interrupts. Since this does //// 2338 .................... //// to usb bus or enable interrupts. Since this does ////
2339 .................... //// not attach to the USB, you must periodically call //// 2339 .................... //// not attach to the USB, you must periodically call ////
2340 .................... //// usb_task(). See usb_task() for more information. //// 2340 .................... //// usb_task(). See usb_task() for more information. ////
2341 .................... //// //// 2341 .................... //// ////
2342 .................... //// usb_task() - If usb_init_cs() was used to initiate the USB //// 2342 .................... //// usb_task() - If usb_init_cs() was used to initiate the USB ////
2343 .................... //// peripheral, usb_task() should then be called periodically //// 2343 .................... //// peripheral, usb_task() should then be called periodically ////
2344 .................... //// to check the connection sense pin. If the connection //// 2344 .................... //// to check the connection sense pin. If the connection ////
2345 .................... //// sense pin denotes USB is connected and the USB peripheral //// 2345 .................... //// sense pin denotes USB is connected and the USB peripheral ////
2346 .................... //// is not attached, this will attach the USB peripheral //// 2346 .................... //// is not attached, this will attach the USB peripheral ////
2347 .................... //// so the PC can start the enumeration process (and it //// 2347 .................... //// so the PC can start the enumeration process (and it ////
2348 .................... //// will enable interrupts). If the connection sense pin //// 2348 .................... //// will enable interrupts). If the connection sense pin ////
2349 .................... //// denotes USB is not attached and the USB peripheral is //// 2349 .................... //// denotes USB is not attached and the USB peripheral is ////
2350 .................... //// running, this will reset the USB peripheral and wait //// 2350 .................... //// running, this will reset the USB peripheral and wait ////
2351 .................... //// for USB to reconnect (and usb_enumerated() will start //// 2351 .................... //// for USB to reconnect (and usb_enumerated() will start ////
2352 .................... //// returning FALSE). If connection sense (USB_CON_SENSE_PIN) //// 2352 .................... //// returning FALSE). If connection sense (USB_CON_SENSE_PIN) ////
2353 .................... //// is not defined the usb_task() assumes that USB is always //// 2353 .................... //// is not defined the usb_task() assumes that USB is always ////
2354 .................... //// connected. //// 2354 .................... //// connected. ////
2355 .................... //// //// 2355 .................... //// ////
2356 .................... //// usb_attached() - Returns TRUE if the device is attached to a //// 2356 .................... //// usb_attached() - Returns TRUE if the device is attached to a ////
2357 .................... //// USB cable. A macro that looks at the defined //// 2357 .................... //// USB cable. A macro that looks at the defined ////
2358 .................... //// connection sense pin. If this returns TRUE //// 2358 .................... //// connection sense pin. If this returns TRUE ////
2359 .................... //// it does not mean the PC has connected to it, //// 2359 .................... //// it does not mean the PC has connected to it, ////
2360 .................... //// you need to use usb_enumerated() to check this. //// 2360 .................... //// you need to use usb_enumerated() to check this. ////
2361 .................... //// //// 2361 .................... //// ////
2362 .................... //// usb_enumerated() - Returns TRUE if device has been enumerated //// 2362 .................... //// usb_enumerated() - Returns TRUE if device has been enumerated ////
2363 .................... //// (configured) by host, FALSE if it has not. //// 2363 .................... //// (configured) by host, FALSE if it has not. ////
2364 .................... //// Do not try to use the USB peripheral for //// 2364 .................... //// Do not try to use the USB peripheral for ////
2365 .................... //// sending and receiving packets until you //// 2365 .................... //// sending and receiving packets until you ////
2366 .................... //// are enumerated. //// 2366 .................... //// are enumerated. ////
2367 .................... //// //// 2367 .................... //// ////
2368 .................... //// usb_wait_for_enumeration() - Sits in an infinte loop until device //// 2368 .................... //// usb_wait_for_enumeration() - Sits in an infinte loop until device ////
2369 .................... //// is enumerated. //// 2369 .................... //// is enumerated. ////
2370 .................... //// //// 2370 .................... //// ////
2371 .................... //// usb_tbe(endpoint) - Returns TRUE if the endpoint transmit buffer //// 2371 .................... //// usb_tbe(endpoint) - Returns TRUE if the endpoint transmit buffer ////
2372 .................... //// is free and ready to accept a new packet for transmission. //// 2372 .................... //// is free and ready to accept a new packet for transmission. ////
2373 .................... //// //// 2373 .................... //// ////
2374 .................... //// usb_put_packet(endpoint, ptr, len, tgl) - Sends one packet to the //// 2374 .................... //// usb_put_packet(endpoint, ptr, len, tgl) - Sends one packet to the ////
2375 .................... //// host. If you need to send a message that //// 2375 .................... //// host. If you need to send a message that ////
2376 .................... //// spans more than one packet then use //// 2376 .................... //// spans more than one packet then use ////
2377 .................... //// usb_puts(). Fore more detailed documentation //// 2377 .................... //// usb_puts(). Fore more detailed documentation ////
2378 .................... //// see usb_hw_layer.h //// 2378 .................... //// see usb_hw_layer.h ////
2379 .................... //// //// 2379 .................... //// ////
2380 .................... //// usb_puts(endpoint, ptr, len, timeout) - Sends a multiple packet //// 2380 .................... //// usb_puts(endpoint, ptr, len, timeout) - Sends a multiple packet ////
2381 .................... //// message to the host. If you only need to send one packet, //// 2381 .................... //// message to the host. If you only need to send one packet, ////
2382 .................... //// it is more effecient to use usb_put_packet(). This is //// 2382 .................... //// it is more effecient to use usb_put_packet(). This is ////
2383 .................... //// documented in more detail above the prototype in USB.H. //// 2383 .................... //// documented in more detail above the prototype in USB.H. ////
2384 .................... //// //// 2384 .................... //// ////
2385 .................... //// usb_kbhit(endpoint) - Returns true if OUT endpoint contains data //// 2385 .................... //// usb_kbhit(endpoint) - Returns true if OUT endpoint contains data ////
2386 .................... //// from host. This will remain TRUE until //// 2386 .................... //// from host. This will remain TRUE until ////
2387 .................... //// usb_put_packet() or usb_flush_out() used. //// 2387 .................... //// usb_put_packet() or usb_flush_out() used. ////
2388 .................... //// This function will return an invalid response //// 2388 .................... //// This function will return an invalid response ////
2389 .................... //// if specified endpoint is not enabled for //// 2389 .................... //// if specified endpoint is not enabled for ////
2390 .................... //// receiving data. //// 2390 .................... //// receiving data. ////
2391 .................... //// //// 2391 .................... //// ////
2392 .................... //// len = usb_get_packet(endpoint, ptr, max) - Gets one packet that //// 2392 .................... //// len = usb_get_packet(endpoint, ptr, max) - Gets one packet that ////
2393 .................... //// from the host/PC. usb_kbhit() must return TRUE before you //// 2393 .................... //// from the host/PC. usb_kbhit() must return TRUE before you ////
2394 .................... //// call this routine or your data may not be valid. This //// 2394 .................... //// call this routine or your data may not be valid. This ////
2395 .................... //// only receives one packet, if you are trying to receive a //// 2395 .................... //// only receives one packet, if you are trying to receive a ////
2396 .................... //// multi-packet message use usb_gets(). For more detailed //// 2396 .................... //// multi-packet message use usb_gets(). For more detailed ////
2397 .................... //// documentation see usb_hw_layer.h. //// 2397 .................... //// documentation see usb_hw_layer.h. ////
2398 .................... //// //// 2398 .................... //// ////
2399 .................... //// len = usb_gets(endpoint, ptr, max, timeout) - Gets multiple //// 2399 .................... //// len = usb_gets(endpoint, ptr, max, timeout) - Gets multiple ////
2400 .................... //// packets from the host, you would use this instead //// 2400 .................... //// packets from the host, you would use this instead ////
2401 .................... //// of usb_get_packet() if you wanted to handle multi-packet //// 2401 .................... //// of usb_get_packet() if you wanted to handle multi-packet ////
2402 .................... //// messages. This is documented in more detail above the //// 2402 .................... //// messages. This is documented in more detail above the ////
2403 .................... //// prototype in USB.H. //// 2403 .................... //// prototype in USB.H. ////
2404 .................... //// //// 2404 .................... //// ////
2405 .................... //// //// 2405 .................... //// ////
2406 .................... //// ********* DEFINITIONS / CONFIGURATION ********** //// 2406 .................... //// ********* DEFINITIONS / CONFIGURATION ********** ////
2407 .................... //// //// 2407 .................... //// ////
2408 .................... //// The following definitions are declared here, but can be //// 2408 .................... //// The following definitions are declared here, but can be ////
2409 .................... //// overwritten in your code. Unless needed otherwise, leave //// 2409 .................... //// overwritten in your code. Unless needed otherwise, leave ////
2410 .................... //// to default value. If confused about a definition read the //// 2410 .................... //// to default value. If confused about a definition read the ////
2411 .................... //// comments at each defintion //// 2411 .................... //// comments at each defintion ////
2412 .................... //// //// 2412 .................... //// ////
2413 .................... //// USB_HID_IDLE (TRUE) - Set to TRUE if your device supports //// 2413 .................... //// USB_HID_IDLE (TRUE) - Set to TRUE if your device supports ////
2414 .................... //// Set_Idle HID class request. Set to //// 2414 .................... //// Set_Idle HID class request. Set to ////
2415 .................... //// False if you do not (device will //// 2415 .................... //// False if you do not (device will ////
2416 .................... //// send a Wrong-state if computer //// 2416 .................... //// send a Wrong-state if computer ////
2417 .................... //// sends a Set_Idle / Get_Idle command) //// 2417 .................... //// sends a Set_Idle / Get_Idle command) ////
2418 .................... //// NOTE: If you set to TRUE you must //// 2418 .................... //// NOTE: If you set to TRUE you must ////
2419 .................... //// provide your own code. See //// 2419 .................... //// provide your own code. See ////
2420 .................... //// usb_isr_tkn_setup_ClassInterface() in //// 2420 .................... //// usb_isr_tkn_setup_ClassInterface() in ////
2421 .................... //// usb.c //// 2421 .................... //// usb.c ////
2422 .................... //// //// 2422 .................... //// ////
2423 .................... //// USB_HID_BOOT_PROTOCOL (FALSE) - Set to TRUE if your device supports //// 2423 .................... //// USB_HID_BOOT_PROTOCOL (FALSE) - Set to TRUE if your device supports ////
2424 .................... //// Set_Protocl HID class request. Set to //// 2424 .................... //// Set_Protocl HID class request. Set to ////
2425 .................... //// False if you do not (device will //// 2425 .................... //// False if you do not (device will ////
2426 .................... //// send a Wrong-state if computer //// 2426 .................... //// send a Wrong-state if computer ////
2427 .................... //// sends a Set_Protocl / Get_Protocol //// 2427 .................... //// sends a Set_Protocl / Get_Protocol ////
2428 .................... //// command). //// 2428 .................... //// command). ////
2429 .................... //// NOTE: If you set to TRUE you must //// 2429 .................... //// NOTE: If you set to TRUE you must ////
2430 .................... //// provide your own code in the //// 2430 .................... //// provide your own code in the ////
2431 .................... //// application that properly send boot //// 2431 .................... //// application that properly send boot ////
2432 .................... //// or HID packets. //// 2432 .................... //// or HID packets. ////
2433 .................... //// //// 2433 .................... //// ////
2434 .................... //// USB_MAX_EP0_PACKET_LENGTH (8) - Max Packet size for Endpoint 0. //// 2434 .................... //// USB_MAX_EP0_PACKET_LENGTH (8) - Max Packet size for Endpoint 0. ////
2435 .................... //// The hardware level driver (ex //// 2435 .................... //// The hardware level driver (ex ////
2436 .................... //// pic18_usb.h will define this value if //// 2436 .................... //// pic18_usb.h will define this value if ////
2437 .................... //// not already overwritten). Increasing //// 2437 .................... //// not already overwritten). Increasing ////
2438 .................... //// this size will speed up the //// 2438 .................... //// this size will speed up the ////
2439 .................... //// enumeration process. //// 2439 .................... //// enumeration process. ////
2440 .................... //// //// 2440 .................... //// ////
2441 .................... //// USB_EPx_RX_ENABLE (USB_ENABLE_DISABLED) - Where x is the //// 2441 .................... //// USB_EPx_RX_ENABLE (USB_ENABLE_DISABLED) - Where x is the ////
2442 .................... //// endpoint number. Change this define //// 2442 .................... //// endpoint number. Change this define ////
2443 .................... //// to specify what kind of transfer method //// 2443 .................... //// to specify what kind of transfer method ////
2444 .................... //// this RX (PC to device) endpoint uses. //// 2444 .................... //// this RX (PC to device) endpoint uses. ////
2445 .................... //// Here is the list of valid transfer methods: //// 2445 .................... //// Here is the list of valid transfer methods: ////
2446 .................... //// USB_ENABLE_CONTROL //// 2446 .................... //// USB_ENABLE_CONTROL ////
2447 .................... //// USB_ENABLE_ISOCHRONOUS //// 2447 .................... //// USB_ENABLE_ISOCHRONOUS ////
2448 .................... //// USB_ENABLE_BULK //// 2448 .................... //// USB_ENABLE_BULK ////
2449 .................... //// USB_ENABLE_INTERRUPT //// 2449 .................... //// USB_ENABLE_INTERRUPT ////
2450 .................... //// USB_ENABLE_DISABLED //// 2450 .................... //// USB_ENABLE_DISABLED ////
2451 .................... //// Don't forget that you must specify the //// 2451 .................... //// Don't forget that you must specify the ////
2452 .................... //// transfer method properly in your endpoint //// 2452 .................... //// transfer method properly in your endpoint ////
2453 .................... //// descriptor, too. //// 2453 .................... //// descriptor, too. ////
2454 .................... //// //// 2454 .................... //// ////
2455 .................... //// USB_EPx_RX_SIZE (0) - For some hardware it is important to know //// 2455 .................... //// USB_EPx_RX_SIZE (0) - For some hardware it is important to know ////
2456 .................... //// how much memory to reserve for receiving //// 2456 .................... //// how much memory to reserve for receiving ////
2457 .................... //// packets. //// 2457 .................... //// packets. ////
2458 .................... //// //// 2458 .................... //// ////
2459 .................... //// *** NOTE *** You must have both USB_EPx_RX_ENABLE defined and //// 2459 .................... //// *** NOTE *** You must have both USB_EPx_RX_ENABLE defined and ////
2460 .................... //// USB_EPx_RX_SIZE defined (non 0) to enable a RX //// 2460 .................... //// USB_EPx_RX_SIZE defined (non 0) to enable a RX ////
2461 .................... //// endpoint. //// 2461 .................... //// endpoint. ////
2462 .................... //// *** NOTE *** Endpoint 0 is always enabled. //// 2462 .................... //// *** NOTE *** Endpoint 0 is always enabled. ////
2463 .................... //// //// 2463 .................... //// ////
2464 .................... //// USB_EPx_TX_ENABLE (USB_ENABLE_DISABLED) - Where x is the //// 2464 .................... //// USB_EPx_TX_ENABLE (USB_ENABLE_DISABLED) - Where x is the ////
2465 .................... //// endpoint number. Change this define //// 2465 .................... //// endpoint number. Change this define ////
2466 .................... //// to specify what kind of transfer method //// 2466 .................... //// to specify what kind of transfer method ////
2467 .................... //// this TX (device to PC) endpoint uses. //// 2467 .................... //// this TX (device to PC) endpoint uses. ////
2468 .................... //// Here is the list of valid transfer methods: //// 2468 .................... //// Here is the list of valid transfer methods: ////
2469 .................... //// USB_ENABLE_CONTROL //// 2469 .................... //// USB_ENABLE_CONTROL ////
2470 .................... //// USB_ENABLE_ISOCHRONOUS //// 2470 .................... //// USB_ENABLE_ISOCHRONOUS ////
2471 .................... //// USB_ENABLE_BULK //// 2471 .................... //// USB_ENABLE_BULK ////
2472 .................... //// USB_ENABLE_INTERRUPT //// 2472 .................... //// USB_ENABLE_INTERRUPT ////
2473 .................... //// USB_ENABLE_DISABLED //// 2473 .................... //// USB_ENABLE_DISABLED ////
2474 .................... //// Don't forget that you must specify the //// 2474 .................... //// Don't forget that you must specify the ////
2475 .................... //// transfer method properly in your endpoint //// 2475 .................... //// transfer method properly in your endpoint ////
2476 .................... //// descriptor, too. //// 2476 .................... //// descriptor, too. ////
2477 .................... //// //// 2477 .................... //// ////
2478 .................... //// USB_EPx_TX_SIZE (0) - For some hardware it is important to know //// 2478 .................... //// USB_EPx_TX_SIZE (0) - For some hardware it is important to know ////
2479 .................... //// how much memory to reserve for transmitting //// 2479 .................... //// how much memory to reserve for transmitting ////
2480 .................... //// packets. //// 2480 .................... //// packets. ////
2481 .................... //// //// 2481 .................... //// ////
2482 .................... //// *** NOTE *** You must have both USB_EPx_TX_ENABLE defined and //// 2482 .................... //// *** NOTE *** You must have both USB_EPx_TX_ENABLE defined and ////
2483 .................... //// USB_EPx_TX_SIZE defined (non 0) to enable a TX //// 2483 .................... //// USB_EPx_TX_SIZE defined (non 0) to enable a TX ////
2484 .................... //// endpoint. //// 2484 .................... //// endpoint. ////
2485 .................... //// //// 2485 .................... //// ////
2486 .................... //// //// 2486 .................... //// ////
2487 .................... //// USB_HID_DEVICE (TRUE) - HID devices require extra code to handle //// 2487 .................... //// USB_HID_DEVICE (TRUE) - HID devices require extra code to handle ////
2488 .................... //// HID requests. You can disable to save //// 2488 .................... //// HID requests. You can disable to save ////
2489 .................... //// ROM space if you are not using a HID //// 2489 .................... //// ROM space if you are not using a HID ////
2490 .................... //// device. If you are not using a HID //// 2490 .................... //// device. If you are not using a HID ////
2491 .................... //// device you must provide your own O/S //// 2491 .................... //// device you must provide your own O/S ////
2492 .................... //// (Windows) driver. //// 2492 .................... //// (Windows) driver. ////
2493 .................... //// //// 2493 .................... //// ////
2494 .................... //// The other definitions should not be changed. //// 2494 .................... //// The other definitions should not be changed. ////
2495 .................... //// //// 2495 .................... //// ////
2496 .................... /////////////////////////////////////////////////////////////////////////// 2496 .................... ///////////////////////////////////////////////////////////////////////////
2497 .................... //// //// 2497 .................... //// ////
2498 .................... //// Version History: //// 2498 .................... //// Version History: ////
2499 .................... //// //// 2499 .................... //// ////
2500 .................... //// March 5th, 2009: //// 2500 .................... //// March 5th, 2009: ////
2501 .................... //// Cleanup for Wizard. //// 2501 .................... //// Cleanup for Wizard. ////
2502 .................... //// PIC24 Initial release. //// 2502 .................... //// PIC24 Initial release. ////
2503 .................... //// //// 2503 .................... //// ////
2504 .................... //// July 13th, 2005: //// 2504 .................... //// July 13th, 2005: ////
2505 .................... //// usb_ep_tx_size[] and usb_ep_rx_size[] changed to 16bits //// 2505 .................... //// usb_ep_tx_size[] and usb_ep_rx_size[] changed to 16bits ////
2506 .................... //// //// 2506 .................... //// ////
2507 .................... //// June 20th, 2005: //// 2507 .................... //// June 20th, 2005: ////
2508 .................... //// Initial 18fxx5x release //// 2508 .................... //// Initial 18fxx5x release ////
2509 .................... //// //// 2509 .................... //// ////
2510 .................... //// May 13th, 2005: //// 2510 .................... //// May 13th, 2005: ////
2511 .................... //// Beta release, only works with 18Fxx5x hardware layer. //// 2511 .................... //// Beta release, only works with 18Fxx5x hardware layer. ////
2512 .................... //// Now supports multiple interfaces (many defines in descriptors //// 2512 .................... //// Now supports multiple interfaces (many defines in descriptors ////
2513 .................... //// will have to be changed, see examples) //// 2513 .................... //// will have to be changed, see examples) ////
2514 .................... //// //// 2514 .................... //// ////
2515 .................... //// Mar 21st, 2005: //// 2515 .................... //// Mar 21st, 2005: ////
2516 .................... //// Initial Alpha Release with PIC18Fxx5x support. (ONLY TESTED //// 2516 .................... //// Initial Alpha Release with PIC18Fxx5x support. (ONLY TESTED ////
2517 .................... //// WITH 18F4550) //// 2517 .................... //// WITH 18F4550) ////
2518 .................... //// usb_gets() and usb_puts() changed (see usb.c) //// 2518 .................... //// usb_gets() and usb_puts() changed (see usb.c) ////
2519 .................... //// //// 2519 .................... //// ////
2520 .................... //// June 24th, 2004: //// 2520 .................... //// June 24th, 2004: ////
2521 .................... //// Optimization and cleanup. //// 2521 .................... //// Optimization and cleanup. ////
2522 .................... //// The following definitions changed: //// 2522 .................... //// The following definitions changed: ////
2523 .................... //// USB_EPx_TX_ENABLE and USB_EPx_RX_ENABLE have changed. See usb.h //// 2523 .................... //// USB_EPx_TX_ENABLE and USB_EPx_RX_ENABLE have changed. See usb.h ////
2524 .................... //// USB_CONFIG_DESCRIPTORS[] removed //// 2524 .................... //// USB_CONFIG_DESCRIPTORS[] removed ////
2525 .................... //// USB_CONFIG_DESC_LEN changed to USB_DESC_CONFIG_LEN //// 2525 .................... //// USB_CONFIG_DESC_LEN changed to USB_DESC_CONFIG_LEN ////
2526 .................... //// USB_INTERFACE_DESC_LEN changed to USB_DESC_INTERFACE_LEN //// 2526 .................... //// USB_INTERFACE_DESC_LEN changed to USB_DESC_INTERFACE_LEN ////
2527 .................... //// USB_CLASS_DESC_LEN changed to USB_DESC_CLASS_LEN //// 2527 .................... //// USB_CLASS_DESC_LEN changed to USB_DESC_CLASS_LEN ////
2528 .................... //// USB_ENDPOINT_DESC_LEN changed to USB_DESC_ENDPOINT_LEN //// 2528 .................... //// USB_ENDPOINT_DESC_LEN changed to USB_DESC_ENDPOINT_LEN ////
2529 .................... //// USB_CONFIG_DESC_KEY changed to USB_DESC_CONFIG_TYPE //// 2529 .................... //// USB_CONFIG_DESC_KEY changed to USB_DESC_CONFIG_TYPE ////
2530 .................... //// USB_INTERFACE_DESC_KEY changed to USB_DESC_INTERFACE_TYPE //// 2530 .................... //// USB_INTERFACE_DESC_KEY changed to USB_DESC_INTERFACE_TYPE ////
2531 .................... //// USB_CLASS_DESC_KEY changed to USB_DESC_CLASS_TYPE //// 2531 .................... //// USB_CLASS_DESC_KEY changed to USB_DESC_CLASS_TYPE ////
2532 .................... //// USB_ENDPOINT_DESC_KEY changed to USB_DESC_ENDPOINT_TYPE //// 2532 .................... //// USB_ENDPOINT_DESC_KEY changed to USB_DESC_ENDPOINT_TYPE ////
2533 .................... //// USB_STRING_X[] arrays removed, see USB_STRING_DESC[] and //// 2533 .................... //// USB_STRING_X[] arrays removed, see USB_STRING_DESC[] and ////
2534 .................... //// USB_STRING_DESC_OFFSET[] //// 2534 .................... //// USB_STRING_DESC_OFFSET[] ////
2535 .................... //// dev_req, curr_config, status_device and getdesc_type global //// 2535 .................... //// dev_req, curr_config, status_device and getdesc_type global ////
2536 .................... //// variables moved into struct USB_stack_status //// 2536 .................... //// variables moved into struct USB_stack_status ////
2537 .................... //// //// 2537 .................... //// ////
2538 .................... //// October 15th, 2003: Support for boot protocol added. //// 2538 .................... //// October 15th, 2003: Support for boot protocol added. ////
2539 .................... //// Set USB_HID_BOOT_PROTOCOL to TRUE to support this. //// 2539 .................... //// Set USB_HID_BOOT_PROTOCOL to TRUE to support this. ////
2540 .................... //// The array hid_protocol[] saves which protocol mode each //// 2540 .................... //// The array hid_protocol[] saves which protocol mode each ////
2541 .................... //// interface is in. It is your applications job to send //// 2541 .................... //// interface is in. It is your applications job to send ////
2542 .................... //// data that either fit the boot protocol or HID protocol. //// 2542 .................... //// data that either fit the boot protocol or HID protocol. ////
2543 .................... //// //// 2543 .................... //// ////
2544 .................... //// May 6th, 2003: Fixed a potential stack overflow using PCM //// 2544 .................... //// May 6th, 2003: Fixed a potential stack overflow using PCM ////
2545 .................... //// //// 2545 .................... //// ////
2546 .................... //// October 29th, 2002: New definition added to USB_STATES //// 2546 .................... //// October 29th, 2002: New definition added to USB_STATES ////
2547 .................... //// //// 2547 .................... //// ////
2548 .................... //// August 2nd, 2002: Initial Public Release //// 2548 .................... //// August 2nd, 2002: Initial Public Release ////
2549 .................... //// //// 2549 .................... //// ////
2550 .................... /////////////////////////////////////////////////////////////////////////// 2550 .................... ///////////////////////////////////////////////////////////////////////////
2551 .................... //// (C) Copyright 1996,2009 Custom Computer Services //// 2551 .................... //// (C) Copyright 1996,2009 Custom Computer Services ////
2552 .................... //// This source code may only be used by licensed users of the CCS //// 2552 .................... //// This source code may only be used by licensed users of the CCS ////
2553 .................... //// C compiler. This source code may only be distributed to other //// 2553 .................... //// C compiler. This source code may only be distributed to other ////
2554 .................... //// licensed users of the CCS C compiler. No other use, //// 2554 .................... //// licensed users of the CCS C compiler. No other use, ////
2555 .................... //// reproduction or distribution is permitted without written //// 2555 .................... //// reproduction or distribution is permitted without written ////
2556 .................... //// permission. Derivative programs created using this software //// 2556 .................... //// permission. Derivative programs created using this software ////
2557 .................... //// in object code form are not restricted in any way. //// 2557 .................... //// in object code form are not restricted in any way. ////
2558 .................... /////////////////////////////////////////////////////////////////////////// 2558 .................... ///////////////////////////////////////////////////////////////////////////
2559 .................... 2559 ....................
2560 .................... #IFNDEF __USB_PROTOTYPES__ 2560 .................... #IFNDEF __USB_PROTOTYPES__
2561 .................... #DEFINE __USB_PROTOTYPES__ 2561 .................... #DEFINE __USB_PROTOTYPES__
2562 .................... 2562 ....................
2563 .................... //// CONFIGURATION //////////////////////////////////////////////////////////// 2563 .................... //// CONFIGURATION ////////////////////////////////////////////////////////////
2564 .................... 2564 ....................
2565 .................... #ifndef USB_CON_SENSE_PIN 2565 .................... #ifndef USB_CON_SENSE_PIN
2566 .................... #define USB_CON_SENSE_PIN 0 2566 .................... #define USB_CON_SENSE_PIN 0
2567 .................... #endif 2567 .................... #endif
2568 .................... 2568 ....................
2569 .................... #IFNDEF USB_HID_BOOT_PROTOCOL 2569 .................... #IFNDEF USB_HID_BOOT_PROTOCOL
2570 .................... #DEFINE USB_HID_BOOT_PROTOCOL FALSE 2570 .................... #DEFINE USB_HID_BOOT_PROTOCOL FALSE
2571 .................... #ENDIF 2571 .................... #ENDIF
2572 .................... 2572 ....................
2573 .................... #IFNDEF USB_HID_IDLE 2573 .................... #IFNDEF USB_HID_IDLE
2574 .................... #DEFINE USB_HID_IDLE FALSE 2574 .................... #DEFINE USB_HID_IDLE FALSE
2575 .................... #ENDIF 2575 .................... #ENDIF
2576 .................... 2576 ....................
2577 .................... //should the compiler add the extra HID handler code? Defaults to yes. 2577 .................... //should the compiler add the extra HID handler code? Defaults to yes.
2578 .................... #IFNDEF USB_HID_DEVICE 2578 .................... #IFNDEF USB_HID_DEVICE
2579 .................... #DEFINE USB_HID_DEVICE TRUE 2579 .................... #DEFINE USB_HID_DEVICE TRUE
2580 .................... #ENDIF 2580 .................... #ENDIF
2581 .................... 2581 ....................
2582 .................... #IFNDEF USB_CDC_DEVICE 2582 .................... #IFNDEF USB_CDC_DEVICE
2583 .................... #DEFINE USB_CDC_DEVICE FALSE 2583 .................... #DEFINE USB_CDC_DEVICE FALSE
2584 .................... #ENDIF 2584 .................... #ENDIF
2585 .................... 2585 ....................
2586 .................... //set to false to opt for less RAM, true to opt for less ROM 2586 .................... //set to false to opt for less RAM, true to opt for less ROM
2587 .................... #ifndef USB_OPT_FOR_ROM 2587 .................... #ifndef USB_OPT_FOR_ROM
2588 .................... #define USB_OPT_FOR_ROM TRUE 2588 .................... #define USB_OPT_FOR_ROM TRUE
2589 .................... #endif 2589 .................... #endif
2590 .................... 2590 ....................
2591 .................... #IFNDEF USB_MAX_EP0_PACKET_LENGTH 2591 .................... #IFNDEF USB_MAX_EP0_PACKET_LENGTH
2592 .................... #DEFINE USB_MAX_EP0_PACKET_LENGTH 8 2592 .................... #DEFINE USB_MAX_EP0_PACKET_LENGTH 8
2593 .................... #ENDIF 2593 .................... #ENDIF
2594 .................... 2594 ....................
2595 .................... 2595 ....................
2596 .................... ////// USER-LEVEL API ///////////////////////////////////////////////////////// 2596 .................... ////// USER-LEVEL API /////////////////////////////////////////////////////////
2597 .................... 2597 ....................
2598 .................... /************************************************************** 2598 .................... /**************************************************************
2599 .................... /* usb_enumerated() 2599 .................... /* usb_enumerated()
2600 .................... /* 2600 .................... /*
2601 .................... /* Input: Global variable USB_Curr_Config 2601 .................... /* Input: Global variable USB_Curr_Config
2602 .................... /* Returns: Returns a 1 if device is configured / enumerated, 2602 .................... /* Returns: Returns a 1 if device is configured / enumerated,
2603 .................... /* Returns a 0 if device is un-configured / not enumerated. 2603 .................... /* Returns a 0 if device is un-configured / not enumerated.
2604 .................... /* 2604 .................... /*
2605 .................... /* Summary: See API section of USB.H for more documentation. 2605 .................... /* Summary: See API section of USB.H for more documentation.
2606 .................... /***************************************************************/ 2606 .................... /***************************************************************/
2607 .................... int1 usb_enumerated(void); 2607 .................... int1 usb_enumerated(void);
2608 .................... 2608 ....................
2609 .................... /************************************************************** 2609 .................... /**************************************************************
2610 .................... /* usb_wait_for_enumeration() 2610 .................... /* usb_wait_for_enumeration()
2611 .................... /* 2611 .................... /*
2612 .................... /* Input: Global variable USB_Curr_Config 2612 .................... /* Input: Global variable USB_Curr_Config
2613 .................... /* 2613 .................... /*
2614 .................... /* Summary: Waits in-definately until device is configured / enumerated. 2614 .................... /* Summary: Waits in-definately until device is configured / enumerated.
2615 .................... /* See API section of USB.H for more information. 2615 .................... /* See API section of USB.H for more information.
2616 .................... /***************************************************************/ 2616 .................... /***************************************************************/
2617 .................... void usb_wait_for_enumeration(void); 2617 .................... void usb_wait_for_enumeration(void);
2618 .................... 2618 ....................
2619 .................... /**************************************************************************** 2619 .................... /****************************************************************************
2620 .................... /* usb_gets(endpoint, ptr, max, timeout) 2620 .................... /* usb_gets(endpoint, ptr, max, timeout)
2621 .................... /* 2621 .................... /*
2622 .................... /* Input: endpoint - endpoint to get data from 2622 .................... /* Input: endpoint - endpoint to get data from
2623 .................... /* ptr - place / array to store data to 2623 .................... /* ptr - place / array to store data to
2624 .................... /* max - max amount of data to get from USB and store into ptr 2624 .................... /* max - max amount of data to get from USB and store into ptr
2625 .................... /* timeout - time in milliseconds, for each packet, to wait before 2625 .................... /* timeout - time in milliseconds, for each packet, to wait before
2626 .................... /* timeout. set to 0 for no timeout. 2626 .................... /* timeout. set to 0 for no timeout.
2627 .................... /* 2627 .................... /*
2628 .................... /* Output: Amount of data returned. It may be less than max. 2628 .................... /* Output: Amount of data returned. It may be less than max.
2629 .................... /* 2629 .................... /*
2630 .................... /* Summary: Gets data from the host. Will get multiple-packet messages 2630 .................... /* Summary: Gets data from the host. Will get multiple-packet messages
2631 .................... /* and finish when either it receives a 0-len packet or a packet 2631 .................... /* and finish when either it receives a 0-len packet or a packet
2632 .................... /* of less size than maximum. 2632 .................... /* of less size than maximum.
2633 .................... /* 2633 .................... /*
2634 .................... /*****************************************************************************/ 2634 .................... /*****************************************************************************/
2635 .................... unsigned int16 usb_gets(int8 endpoint, int8 * ptr, unsigned int16 max, unsigned int16 timeout); 2635 .................... unsigned int16 usb_gets(int8 endpoint, int8 * ptr, unsigned int16 max, unsigned int16 timeout);
2636 .................... 2636 ....................
2637 .................... /**************************************************************************** 2637 .................... /****************************************************************************
2638 .................... /* usb_puts() 2638 .................... /* usb_puts()
2639 .................... /* 2639 .................... /*
2640 .................... /* Inputs: endpoint - endpoint to send data out 2640 .................... /* Inputs: endpoint - endpoint to send data out
2641 .................... /* ptr - points to array of data to send 2641 .................... /* ptr - points to array of data to send
2642 .................... /* len - amount of data to send 2642 .................... /* len - amount of data to send
2643 .................... /* timeout - time in milli-seconds, for each packet, to wait before 2643 .................... /* timeout - time in milli-seconds, for each packet, to wait before
2644 .................... /* timeout. set to 0 for no timeout. 2644 .................... /* timeout. set to 0 for no timeout.
2645 .................... /* 2645 .................... /*
2646 .................... /* Outputs: Returns TRUE if message sent succesfully, FALSE if it was not 2646 .................... /* Outputs: Returns TRUE if message sent succesfully, FALSE if it was not
2647 .................... /* sent before timeout period expired. 2647 .................... /* sent before timeout period expired.
2648 .................... /* 2648 .................... /*
2649 .................... /* Summary: Used for sending multiple packets of data as one message. This 2649 .................... /* Summary: Used for sending multiple packets of data as one message. This
2650 .................... /* function can still be used to send messages consiting of only one 2650 .................... /* function can still be used to send messages consiting of only one
2651 .................... /* packet. See usb_put_packet() documentation for the rules about when 2651 .................... /* packet. See usb_put_packet() documentation for the rules about when
2652 .................... /* multiple packet messages or 0-lenght packets are needed. 2652 .................... /* multiple packet messages or 0-lenght packets are needed.
2653 .................... /* 2653 .................... /*
2654 .................... /*****************************************************************************/ 2654 .................... /*****************************************************************************/
2655 .................... int1 usb_puts(int8 endpoint, int8 * ptr, unsigned int16 len, unsigned int8 timeout); 2655 .................... int1 usb_puts(int8 endpoint, int8 * ptr, unsigned int16 len, unsigned int8 timeout);
2656 .................... 2656 ....................
2657 .................... /****************************************************************************** 2657 .................... /******************************************************************************
2658 .................... /* usb_attached() 2658 .................... /* usb_attached()
2659 .................... /* 2659 .................... /*
2660 .................... /* Summary: Returns TRUE if the device is attached to a USB cable. 2660 .................... /* Summary: Returns TRUE if the device is attached to a USB cable.
2661 .................... /* See the API section of USB.H for more documentation. 2661 .................... /* See the API section of USB.H for more documentation.
2662 .................... /* 2662 .................... /*
2663 .................... /*****************************************************************************/ 2663 .................... /*****************************************************************************/
2664 .................... #if USB_CON_SENSE_PIN 2664 .................... #if USB_CON_SENSE_PIN
2665 .................... #define usb_attached() input(USB_CON_SENSE_PIN) 2665 .................... #define usb_attached() input(USB_CON_SENSE_PIN)
2666 .................... #else 2666 .................... #else
2667 .................... #define usb_attached() TRUE 2667 .................... #define usb_attached() TRUE
2668 .................... #endif 2668 .................... #endif
2669 .................... 2669 ....................
2670 .................... ////// END USER-LEVEL API ///////////////////////////////////////////////////// 2670 .................... ////// END USER-LEVEL API /////////////////////////////////////////////////////
2671 .................... 2671 ....................
2672 .................... 2672 ....................
2673 .................... ////// STACK-LEVEL API USED BY HW DRIVERS //////////////////////////////////// 2673 .................... ////// STACK-LEVEL API USED BY HW DRIVERS ////////////////////////////////////
2674 .................... 2674 ....................
2675 .................... enum USB_STATES {GET_DESCRIPTOR=1,SET_ADDRESS=2,NONE=0}; 2675 .................... enum USB_STATES {GET_DESCRIPTOR=1,SET_ADDRESS=2,NONE=0};
2676 .................... 2676 ....................
2677 .................... enum USB_GETDESC_TYPES {USB_GETDESC_CONFIG_TYPE=0,USB_GETDESC_HIDREPORT_TYPE=1,USB_GETDESC_STRING_TYPE=2,USB_GETDESC_DEVICE_TYPE=3}; 2677 .................... enum USB_GETDESC_TYPES {USB_GETDESC_CONFIG_TYPE=0,USB_GETDESC_HIDREPORT_TYPE=1,USB_GETDESC_STRING_TYPE=2,USB_GETDESC_DEVICE_TYPE=3};
2678 .................... 2678 ....................
2679 .................... #if USB_OPT_FOR_ROM 2679 .................... #if USB_OPT_FOR_ROM
2680 .................... typedef struct { 2680 .................... typedef struct {
2681 .................... USB_STATES dev_req; //what did the last setup token set us up to do?. init at none 2681 .................... USB_STATES dev_req; //what did the last setup token set us up to do?. init at none
2682 .................... int curr_config; //our current config. start at none/powered (NOT THAT THIS LIMITS US TO 3 CONFIGURATIONS) 2682 .................... int curr_config; //our current config. start at none/powered (NOT THAT THIS LIMITS US TO 3 CONFIGURATIONS)
2683 .................... int status_device; //Holds our state for Set_Feature and Clear_Feature 2683 .................... int status_device; //Holds our state for Set_Feature and Clear_Feature
2684 .................... USB_GETDESC_TYPES getdesc_type; //which get_descriptor() we are handling 2684 .................... USB_GETDESC_TYPES getdesc_type; //which get_descriptor() we are handling
2685 .................... } TYPE_USB_STACK_STATUS; 2685 .................... } TYPE_USB_STACK_STATUS;
2686 .................... #else 2686 .................... #else
2687 .................... typedef struct { 2687 .................... typedef struct {
2688 .................... USB_STATES dev_req:2; //what did the last setup token set us up to do?. init at none 2688 .................... USB_STATES dev_req:2; //what did the last setup token set us up to do?. init at none
2689 .................... int Curr_config:2; //our current config. start at none/powered (NOT THAT THIS LIMITS US TO 3 CONFIGURATIONS) 2689 .................... int Curr_config:2; //our current config. start at none/powered (NOT THAT THIS LIMITS US TO 3 CONFIGURATIONS)
2690 .................... int status_device:2; //Holds our state for Set_Feature and Clear_Feature 2690 .................... int status_device:2; //Holds our state for Set_Feature and Clear_Feature
2691 .................... USB_GETDESC_TYPES getdesc_type:2; //which get_descriptor() we are handling 2691 .................... USB_GETDESC_TYPES getdesc_type:2; //which get_descriptor() we are handling
2692 .................... } TYPE_USB_STACK_STATUS; 2692 .................... } TYPE_USB_STACK_STATUS;
2693 .................... #endif 2693 .................... #endif
2694 .................... 2694 ....................
2695 .................... extern TYPE_USB_STACK_STATUS USB_stack_status; 2695 .................... extern TYPE_USB_STACK_STATUS USB_stack_status;
2696 .................... 2696 ....................
2697 .................... /************************************************************** 2697 .................... /**************************************************************
2698 .................... /* usb_token_reset() 2698 .................... /* usb_token_reset()
2699 .................... /* 2699 .................... /*
2700 .................... /* Output: No output (but many global registers are modified) 2700 .................... /* Output: No output (but many global registers are modified)
2701 .................... /* 2701 .................... /*
2702 .................... /* Summary: Resets the token handler to initial (unconfigured) state. 2702 .................... /* Summary: Resets the token handler to initial (unconfigured) state.
2703 .................... /***************************************************************/ 2703 .................... /***************************************************************/
2704 .................... void usb_token_reset(void); 2704 .................... void usb_token_reset(void);
2705 .................... 2705 ....................
2706 .................... /************************************************************** 2706 .................... /**************************************************************
2707 .................... /* usb_isr_tok_setup_dne() 2707 .................... /* usb_isr_tok_setup_dne()
2708 .................... /* 2708 .................... /*
2709 .................... /* Input: usb_ep0_rx_buffer[] contains the the setup packet. 2709 .................... /* Input: usb_ep0_rx_buffer[] contains the the setup packet.
2710 .................... /* 2710 .................... /*
2711 .................... /* Output: None (many globals are changed) 2711 .................... /* Output: None (many globals are changed)
2712 .................... /* 2712 .................... /*
2713 .................... /* Summary: This function is that handles the setup token. 2713 .................... /* Summary: This function is that handles the setup token.
2714 .................... /* We must handle all relevant requests, such as Set_Configuration, 2714 .................... /* We must handle all relevant requests, such as Set_Configuration,
2715 .................... /* Get_Descriptor, etc. 2715 .................... /* Get_Descriptor, etc.
2716 .................... /* 2716 .................... /*
2717 .................... /* usb_ep0_rx_buffer[] contains setup data packet, which has the 2717 .................... /* usb_ep0_rx_buffer[] contains setup data packet, which has the
2718 .................... /* following records: 2718 .................... /* following records:
2719 .................... /* ------------------------------------------------------------------------------------------- 2719 .................... /* -------------------------------------------------------------------------------------------
2720 .................... /* usb_ep0_rx_buffer[ 0 ]=bmRequestType; Where the setup packet goes 2720 .................... /* usb_ep0_rx_buffer[ 0 ]=bmRequestType; Where the setup packet goes
2721 .................... /* bit7 (0) host-to-device 2721 .................... /* bit7 (0) host-to-device
2722 .................... /* (1) device-to-host 2722 .................... /* (1) device-to-host
2723 .................... /* bit6-5 (00) usb standard request; 2723 .................... /* bit6-5 (00) usb standard request;
2724 .................... /* (01) class request; 2724 .................... /* (01) class request;
2725 .................... /* (10) vendor request 2725 .................... /* (10) vendor request
2726 .................... /* (11) reserved 2726 .................... /* (11) reserved
2727 .................... /* bit4-0 (0000) device 2727 .................... /* bit4-0 (0000) device
2728 .................... /* (0001) interface 2728 .................... /* (0001) interface
2729 .................... /* (0010) endpoint 2729 .................... /* (0010) endpoint
2730 .................... /* (0011) other element 2730 .................... /* (0011) other element
2731 .................... /* (0100) to (1111) reserved 2731 .................... /* (0100) to (1111) reserved
2732 .................... /* usb_ep0_rx_buffer[ 1 ]=bRequest ; the request 2732 .................... /* usb_ep0_rx_buffer[ 1 ]=bRequest ; the request
2733 .................... /* usb_ep0_rx_buffer[2,3]=wValue ; a value which corresponds to request 2733 .................... /* usb_ep0_rx_buffer[2,3]=wValue ; a value which corresponds to request
2734 .................... /* usb_ep0_rx_buffer[4,5]=wIndex ; could correspond to interface or endpoint... 2734 .................... /* usb_ep0_rx_buffer[4,5]=wIndex ; could correspond to interface or endpoint...
2735 .................... /* usb_ep0_rx_buffer[6,7]=wLength ; number of bytes in next data packet; 2735 .................... /* usb_ep0_rx_buffer[6,7]=wLength ; number of bytes in next data packet;
2736 .................... /* for host-to-device, this exactly how many bytes in data packet. 2736 .................... /* for host-to-device, this exactly how many bytes in data packet.
2737 .................... /* for device-to-host, this is the maximum bytes that can fit one packet. 2737 .................... /* for device-to-host, this is the maximum bytes that can fit one packet.
2738 .................... /***************************************************************/ 2738 .................... /***************************************************************/
2739 .................... void usb_isr_tok_setup_dne(void); 2739 .................... void usb_isr_tok_setup_dne(void);
2740 .................... 2740 ....................
2741 .................... /************************************************************** 2741 .................... /**************************************************************
2742 .................... /* usb_isr_tok_out_dne() 2742 .................... /* usb_isr_tok_out_dne()
2743 .................... /* 2743 .................... /*
2744 .................... /* Input: endpoint contains which endpoint we are receiving data (0..15) 2744 .................... /* Input: endpoint contains which endpoint we are receiving data (0..15)
2745 .................... /* 2745 .................... /*
2746 .................... /* Summary: Processes out tokens (out is respective of the host, so actualy 2746 .................... /* Summary: Processes out tokens (out is respective of the host, so actualy
2747 .................... /* incoming to the pic), but not out setup tokens. Normally when 2747 .................... /* incoming to the pic), but not out setup tokens. Normally when
2748 .................... /* data is received it is left in the buffer (user would use 2748 .................... /* data is received it is left in the buffer (user would use
2749 .................... /* usb_kbhit() and usb_get_packet() to receive data), but certain 2749 .................... /* usb_kbhit() and usb_get_packet() to receive data), but certain
2750 .................... /* libraries (like CDC) have to answer setup packets. 2750 .................... /* libraries (like CDC) have to answer setup packets.
2751 .................... /* 2751 .................... /*
2752 .................... /***************************************************************/ 2752 .................... /***************************************************************/
2753 .................... void usb_isr_tok_out_dne(int8 endpoint); 2753 .................... void usb_isr_tok_out_dne(int8 endpoint);
2754 .................... 2754 ....................
2755 .................... /************************************************************** 2755 .................... /**************************************************************
2756 .................... /* usb_isr_tok_in_dne(endpoint) 2756 .................... /* usb_isr_tok_in_dne(endpoint)
2757 .................... /* 2757 .................... /*
2758 .................... /* Input: endpoint - which endpoint we are processing a setup token. 2758 .................... /* Input: endpoint - which endpoint we are processing a setup token.
2759 .................... /* 2759 .................... /*
2760 .................... /* Summary: This handles an IN packet (HOST <- PIC). For endpoint 0, this 2760 .................... /* Summary: This handles an IN packet (HOST <- PIC). For endpoint 0, this
2761 .................... /* is usually to setup a response packet to a setup packet. Endpoints 1..15 2761 .................... /* is usually to setup a response packet to a setup packet. Endpoints 1..15
2762 .................... /* are generally ignored, and the user has to use usb_tbe() to determine if 2762 .................... /* are generally ignored, and the user has to use usb_tbe() to determine if
2763 .................... /* if the buffer is ready for a new transmit packet (there are special cases, 2763 .................... /* if the buffer is ready for a new transmit packet (there are special cases,
2764 .................... /* like CDC which handles the CDC protocl). 2764 .................... /* like CDC which handles the CDC protocl).
2765 .................... /* 2765 .................... /*
2766 .................... /***************************************************************/ 2766 .................... /***************************************************************/
2767 .................... void usb_isr_tok_in_dne(int8 endpoint); 2767 .................... void usb_isr_tok_in_dne(int8 endpoint);
2768 .................... 2768 ....................
2769 .................... ////// END STACK-LEVEL API USED BY HW DRIVERS ///////////////////////////////// 2769 .................... ////// END STACK-LEVEL API USED BY HW DRIVERS /////////////////////////////////
2770 .................... 2770 ....................
2771 .................... 2771 ....................
2772 .................... //CCS only supports one configuration at this time 2772 .................... //CCS only supports one configuration at this time
2773 .................... #DEFINE USB_NUM_CONFIGURATIONS 1 //DO NOT CHANGE 2773 .................... #DEFINE USB_NUM_CONFIGURATIONS 1 //DO NOT CHANGE
2774 .................... 2774 ....................
2775 .................... //PID values for tokens (see page 48 of USB Complete ed.1) 2775 .................... //PID values for tokens (see page 48 of USB Complete ed.1)
2776 .................... #define PID_IN 0x09 //device to host transactions 2776 .................... #define PID_IN 0x09 //device to host transactions
2777 .................... #define PID_OUT 0x01 //host to device transactions 2777 .................... #define PID_OUT 0x01 //host to device transactions
2778 .................... #define PID_SETUP 0x0D //host to device setup transaction 2778 .................... #define PID_SETUP 0x0D //host to device setup transaction
2779 .................... #define PID_ACK 0x02 //receiver accepts error-free data packet 2779 .................... #define PID_ACK 0x02 //receiver accepts error-free data packet
2780 .................... #define PID_DATA0 0x03 //data packet with even sync bit 2780 .................... #define PID_DATA0 0x03 //data packet with even sync bit
2781 .................... #define PID_SOF 0x05 //start of framer marker and frame number 2781 .................... #define PID_SOF 0x05 //start of framer marker and frame number
2782 .................... #define PID_NAK 0x0A //receiver can't accept data or sender cant send data or has no data to transmit 2782 .................... #define PID_NAK 0x0A //receiver can't accept data or sender cant send data or has no data to transmit
2783 .................... #define PID_DATA1 0x0B //data packet with odd sync bit 2783 .................... #define PID_DATA1 0x0B //data packet with odd sync bit
2784 .................... #define PID_PRE 0x0C //preamble issued by host. enables downstream traffic to low-speed device 2784 .................... #define PID_PRE 0x0C //preamble issued by host. enables downstream traffic to low-speed device
2785 .................... #define PID_STALL 0x0E //a control request isnt supported or the endpoint is halted 2785 .................... #define PID_STALL 0x0E //a control request isnt supported or the endpoint is halted
2786 .................... 2786 ....................
2787 .................... //Key which identifies descritpors 2787 .................... //Key which identifies descritpors
2788 .................... #DEFINE USB_DESC_DEVICE_TYPE 0x01 //#DEFINE USB_DEVICE_DESC_KEY 0x01 2788 .................... #DEFINE USB_DESC_DEVICE_TYPE 0x01 //#DEFINE USB_DEVICE_DESC_KEY 0x01
2789 .................... #DEFINE USB_DESC_CONFIG_TYPE 0x02 //#DEFINE USB_CONFIG_DESC_KEY 0x02 2789 .................... #DEFINE USB_DESC_CONFIG_TYPE 0x02 //#DEFINE USB_CONFIG_DESC_KEY 0x02
2790 .................... #DEFINE USB_DESC_STRING_TYPE 0x03 //#DEFINE USB_STRING_DESC_KEY 0x03 2790 .................... #DEFINE USB_DESC_STRING_TYPE 0x03 //#DEFINE USB_STRING_DESC_KEY 0x03
2791 .................... #DEFINE USB_DESC_INTERFACE_TYPE 0x04 //#DEFINE USB_INTERFACE_DESC_KEY 0x04 2791 .................... #DEFINE USB_DESC_INTERFACE_TYPE 0x04 //#DEFINE USB_INTERFACE_DESC_KEY 0x04
2792 .................... #DEFINE USB_DESC_ENDPOINT_TYPE 0x05 //#DEFINE USB_ENDPOINT_DESC_KEY 0x05 2792 .................... #DEFINE USB_DESC_ENDPOINT_TYPE 0x05 //#DEFINE USB_ENDPOINT_DESC_KEY 0x05
2793 .................... #DEFINE USB_DESC_CLASS_TYPE 0x21 //#DEFINE USB_CLASS_DESC_KEY 0x21 2793 .................... #DEFINE USB_DESC_CLASS_TYPE 0x21 //#DEFINE USB_CLASS_DESC_KEY 0x21
2794 .................... #DEFINE USB_DESC_HIDREPORT_TYPE 0x22 2794 .................... #DEFINE USB_DESC_HIDREPORT_TYPE 0x22
2795 .................... 2795 ....................
2796 .................... //The length of each descriptor 2796 .................... //The length of each descriptor
2797 .................... #DEFINE USB_DESC_DEVICE_LEN 18 //#DEFINE USB_DEVICE_DESC_LEN 18 2797 .................... #DEFINE USB_DESC_DEVICE_LEN 18 //#DEFINE USB_DEVICE_DESC_LEN 18
2798 .................... #DEFINE USB_DESC_CONFIG_LEN 9 //#DEFINE USB_CONFIG_DESC_LEN 9 2798 .................... #DEFINE USB_DESC_CONFIG_LEN 9 //#DEFINE USB_CONFIG_DESC_LEN 9
2799 .................... #DEFINE USB_DESC_INTERFACE_LEN 9 //#DEFINE USB_INTERFACE_DESC_LEN 9 2799 .................... #DEFINE USB_DESC_INTERFACE_LEN 9 //#DEFINE USB_INTERFACE_DESC_LEN 9
2800 .................... #DEFINE USB_DESC_CLASS_LEN 9 //#DEFINE USB_CLASS_DESC_LEN 9 2800 .................... #DEFINE USB_DESC_CLASS_LEN 9 //#DEFINE USB_CLASS_DESC_LEN 9
2801 .................... #DEFINE USB_DESC_ENDPOINT_LEN 7 //#DEFINE USB_ENDPOINT_DESC_LEN 7 2801 .................... #DEFINE USB_DESC_ENDPOINT_LEN 7 //#DEFINE USB_ENDPOINT_DESC_LEN 7
2802 .................... 2802 ....................
2803 .................... //Standard USB Setup bRequest Codes 2803 .................... //Standard USB Setup bRequest Codes
2804 .................... #define USB_STANDARD_REQUEST_GET_STATUS 0x00 2804 .................... #define USB_STANDARD_REQUEST_GET_STATUS 0x00
2805 .................... #define USB_STANDARD_REQUEST_CLEAR_FEATURE 0x01 2805 .................... #define USB_STANDARD_REQUEST_CLEAR_FEATURE 0x01
2806 .................... #define USB_STANDARD_REQUEST_SET_FEATURE 0x03 2806 .................... #define USB_STANDARD_REQUEST_SET_FEATURE 0x03
2807 .................... #define USB_STANDARD_REQUEST_SET_ADDRESS 0x05 2807 .................... #define USB_STANDARD_REQUEST_SET_ADDRESS 0x05
2808 .................... #define USB_STANDARD_REQUEST_GET_DESCRIPTOR 0x06 2808 .................... #define USB_STANDARD_REQUEST_GET_DESCRIPTOR 0x06
2809 .................... #define USB_STANDARD_REQUEST_SET_DESCRIPTOR 0x07 2809 .................... #define USB_STANDARD_REQUEST_SET_DESCRIPTOR 0x07
2810 .................... #define USB_STANDARD_REQUEST_GET_CONFIGURATION 0x08 2810 .................... #define USB_STANDARD_REQUEST_GET_CONFIGURATION 0x08
2811 .................... #define USB_STANDARD_REQUEST_SET_CONFIGURATION 0x09 2811 .................... #define USB_STANDARD_REQUEST_SET_CONFIGURATION 0x09
2812 .................... #define USB_STANDARD_REQUEST_GET_INTERFACE 0x0A 2812 .................... #define USB_STANDARD_REQUEST_GET_INTERFACE 0x0A
2813 .................... #define USB_STANDARD_REQUEST_SET_INTERFACE 0x0B 2813 .................... #define USB_STANDARD_REQUEST_SET_INTERFACE 0x0B
2814 .................... #define USB_STANDARD_REQUEST_SYNCH_FRAME 0x0C 2814 .................... #define USB_STANDARD_REQUEST_SYNCH_FRAME 0x0C
2815 .................... 2815 ....................
2816 .................... //HID Class Setup bRequest Codes 2816 .................... //HID Class Setup bRequest Codes
2817 .................... #define USB_HID_REQUEST_GET_REPORT 0x01 2817 .................... #define USB_HID_REQUEST_GET_REPORT 0x01
2818 .................... #define USB_HID_REQUEST_GET_IDLE 0x02 2818 .................... #define USB_HID_REQUEST_GET_IDLE 0x02
2819 .................... #define USB_HID_REQUEST_GET_PROTOCOL 0x03 2819 .................... #define USB_HID_REQUEST_GET_PROTOCOL 0x03
2820 .................... #define USB_HID_REQUEST_SET_REPORT 0x09 2820 .................... #define USB_HID_REQUEST_SET_REPORT 0x09
2821 .................... #define USB_HID_REQUEST_SET_IDLE 0x0A 2821 .................... #define USB_HID_REQUEST_SET_IDLE 0x0A
2822 .................... #define USB_HID_REQUEST_SET_PROTOCOL 0x0B 2822 .................... #define USB_HID_REQUEST_SET_PROTOCOL 0x0B
2823 .................... 2823 ....................
2824 .................... //types of endpoints as defined in the descriptor 2824 .................... //types of endpoints as defined in the descriptor
2825 .................... #define USB_ENDPOINT_TYPE_CONTROL 0x00 2825 .................... #define USB_ENDPOINT_TYPE_CONTROL 0x00
2826 .................... #define USB_ENDPOINT_TYPE_ISOCHRONOUS 0x01 2826 .................... #define USB_ENDPOINT_TYPE_ISOCHRONOUS 0x01
2827 .................... #define USB_ENDPOINT_TYPE_BULK 0x02 2827 .................... #define USB_ENDPOINT_TYPE_BULK 0x02
2828 .................... #define USB_ENDPOINT_TYPE_INTERRUPT 0x03 2828 .................... #define USB_ENDPOINT_TYPE_INTERRUPT 0x03
2829 .................... 2829 ....................
2830 .................... //types of endpoints used internally in this api 2830 .................... //types of endpoints used internally in this api
2831 .................... #define USB_ENABLE_DISABLED -1 2831 .................... #define USB_ENABLE_DISABLED -1
2832 .................... #define USB_ENABLE_BULK USB_ENDPOINT_TYPE_BULK 2832 .................... #define USB_ENABLE_BULK USB_ENDPOINT_TYPE_BULK
2833 .................... #define USB_ENABLE_ISOCHRONOUS USB_ENDPOINT_TYPE_ISOCHRONOUS 2833 .................... #define USB_ENABLE_ISOCHRONOUS USB_ENDPOINT_TYPE_ISOCHRONOUS
2834 .................... #define USB_ENABLE_INTERRUPT USB_ENDPOINT_TYPE_INTERRUPT 2834 .................... #define USB_ENABLE_INTERRUPT USB_ENDPOINT_TYPE_INTERRUPT
2835 .................... #define USB_ENABLE_CONTROL USB_ENDPOINT_TYPE_CONTROL 2835 .................... #define USB_ENABLE_CONTROL USB_ENDPOINT_TYPE_CONTROL
2836 .................... 2836 ....................
2837 .................... 2837 ....................
2838 .................... //*** ENABLE RX ENDPOINTS AND BUFFERS 2838 .................... //*** ENABLE RX ENDPOINTS AND BUFFERS
2839 .................... 2839 ....................
2840 .................... //--------- endpoint 0 defines ---------- 2840 .................... //--------- endpoint 0 defines ----------
2841 .................... #define USB_EP0_TX_ENABLE USB_ENABLE_CONTROL 2841 .................... #define USB_EP0_TX_ENABLE USB_ENABLE_CONTROL
2842 .................... #define USB_EP0_RX_ENABLE USB_ENABLE_CONTROL 2842 .................... #define USB_EP0_RX_ENABLE USB_ENABLE_CONTROL
2843 .................... #define USB_EP0_RX_SIZE USB_MAX_EP0_PACKET_LENGTH //endpoint 0 is setup, and should always be the MAX_PACKET_LENGTH. Slow speed specifies 8 2843 .................... #define USB_EP0_RX_SIZE USB_MAX_EP0_PACKET_LENGTH //endpoint 0 is setup, and should always be the MAX_PACKET_LENGTH. Slow speed specifies 8
2844 .................... #define USB_EP0_TX_SIZE USB_MAX_EP0_PACKET_LENGTH //endpoint 0 is setup, and should always be the MAX_PACKET_LENGTH. Slow speed specifies 8 2844 .................... #define USB_EP0_TX_SIZE USB_MAX_EP0_PACKET_LENGTH //endpoint 0 is setup, and should always be the MAX_PACKET_LENGTH. Slow speed specifies 8
2845 .................... 2845 ....................
2846 .................... //--------- endpoint 1 defines ---------- 2846 .................... //--------- endpoint 1 defines ----------
2847 .................... #ifndef USB_EP1_TX_ENABLE 2847 .................... #ifndef USB_EP1_TX_ENABLE
2848 .................... #define USB_EP1_TX_ENABLE USB_ENABLE_DISABLED 2848 .................... #define USB_EP1_TX_ENABLE USB_ENABLE_DISABLED
2849 .................... #endif 2849 .................... #endif
2850 .................... #ifndef USB_EP1_RX_ENABLE 2850 .................... #ifndef USB_EP1_RX_ENABLE
2851 .................... #define USB_EP1_RX_ENABLE USB_ENABLE_DISABLED 2851 .................... #define USB_EP1_RX_ENABLE USB_ENABLE_DISABLED
2852 .................... #endif 2852 .................... #endif
2853 .................... 2853 ....................
2854 .................... #if USB_EP1_RX_ENABLE==USB_ENABLE_DISABLED 2854 .................... #if USB_EP1_RX_ENABLE==USB_ENABLE_DISABLED
2855 .................... #ifdef USB_EP1_RX_SIZE 2855 .................... #ifdef USB_EP1_RX_SIZE
2856 .................... #undef USB_EP1_RX_SIZE 2856 .................... #undef USB_EP1_RX_SIZE
2857 .................... #endif 2857 .................... #endif
2858 .................... #define USB_EP1_RX_SIZE 0 2858 .................... #define USB_EP1_RX_SIZE 0
2859 .................... #else 2859 .................... #else
2860 .................... #ifndef USB_EP1_RX_SIZE 2860 .................... #ifndef USB_EP1_RX_SIZE
2861 .................... #error You enabled EP1 for RX but didn't specify endpoint size 2861 .................... #error You enabled EP1 for RX but didn't specify endpoint size
2862 .................... #endif 2862 .................... #endif
2863 .................... #endif 2863 .................... #endif
2864 .................... 2864 ....................
2865 .................... #if USB_EP1_TX_ENABLE==USB_ENABLE_DISABLED 2865 .................... #if USB_EP1_TX_ENABLE==USB_ENABLE_DISABLED
2866 .................... #ifdef USB_EP1_TX_SIZE 2866 .................... #ifdef USB_EP1_TX_SIZE
2867 .................... #undef USB_EP1_TX_SIZE 2867 .................... #undef USB_EP1_TX_SIZE
2868 .................... #endif 2868 .................... #endif
2869 .................... #define USB_EP1_TX_SIZE 0 2869 .................... #define USB_EP1_TX_SIZE 0
2870 .................... #else 2870 .................... #else
2871 .................... #ifndef USB_EP1_TX_SIZE 2871 .................... #ifndef USB_EP1_TX_SIZE
2872 .................... #error You enabled EP1 for TX but didn't specify endpoint size 2872 .................... #error You enabled EP1 for TX but didn't specify endpoint size
2873 .................... #endif 2873 .................... #endif
2874 .................... #endif 2874 .................... #endif
2875 .................... 2875 ....................
2876 .................... 2876 ....................
2877 .................... //--------- endpoint 2 defines ---------- 2877 .................... //--------- endpoint 2 defines ----------
2878 .................... #ifndef USB_EP2_TX_ENABLE 2878 .................... #ifndef USB_EP2_TX_ENABLE
2879 .................... #define USB_EP2_TX_ENABLE USB_ENABLE_DISABLED 2879 .................... #define USB_EP2_TX_ENABLE USB_ENABLE_DISABLED
2880 .................... #endif 2880 .................... #endif
2881 .................... #ifndef USB_EP2_RX_ENABLE 2881 .................... #ifndef USB_EP2_RX_ENABLE
2882 .................... #define USB_EP2_RX_ENABLE USB_ENABLE_DISABLED 2882 .................... #define USB_EP2_RX_ENABLE USB_ENABLE_DISABLED
2883 .................... #endif 2883 .................... #endif
2884 .................... 2884 ....................
2885 .................... #if USB_EP2_RX_ENABLE==USB_ENABLE_DISABLED 2885 .................... #if USB_EP2_RX_ENABLE==USB_ENABLE_DISABLED
2886 .................... #ifdef USB_EP2_RX_SIZE 2886 .................... #ifdef USB_EP2_RX_SIZE
2887 .................... #undef USB_EP2_RX_SIZE 2887 .................... #undef USB_EP2_RX_SIZE
2888 .................... #endif 2888 .................... #endif
2889 .................... #define USB_EP2_RX_SIZE 0 2889 .................... #define USB_EP2_RX_SIZE 0
2890 .................... #else 2890 .................... #else
2891 .................... #ifndef USB_EP2_RX_SIZE 2891 .................... #ifndef USB_EP2_RX_SIZE
2892 .................... #error You enabled EP2 for RX but didn't specify endpoint size 2892 .................... #error You enabled EP2 for RX but didn't specify endpoint size
2893 .................... #endif 2893 .................... #endif
2894 .................... #endif 2894 .................... #endif
2895 .................... 2895 ....................
2896 .................... #if USB_EP2_TX_ENABLE==USB_ENABLE_DISABLED 2896 .................... #if USB_EP2_TX_ENABLE==USB_ENABLE_DISABLED
2897 .................... #ifdef USB_EP2_TX_SIZE 2897 .................... #ifdef USB_EP2_TX_SIZE
2898 .................... #undef USB_EP2_TX_SIZE 2898 .................... #undef USB_EP2_TX_SIZE
2899 .................... #endif 2899 .................... #endif
2900 .................... #define USB_EP2_TX_SIZE 0 2900 .................... #define USB_EP2_TX_SIZE 0
2901 .................... #else 2901 .................... #else
2902 .................... #ifndef USB_EP2_TX_SIZE 2902 .................... #ifndef USB_EP2_TX_SIZE
2903 .................... #error You enabled EP2 for TX but didn't specify endpoint size 2903 .................... #error You enabled EP2 for TX but didn't specify endpoint size
2904 .................... #endif 2904 .................... #endif
2905 .................... #endif 2905 .................... #endif
2906 .................... 2906 ....................
2907 .................... 2907 ....................
2908 .................... //--------- endpoint 3 defines ---------- 2908 .................... //--------- endpoint 3 defines ----------
2909 .................... #ifndef USB_EP3_TX_ENABLE 2909 .................... #ifndef USB_EP3_TX_ENABLE
2910 .................... #define USB_EP3_TX_ENABLE USB_ENABLE_DISABLED 2910 .................... #define USB_EP3_TX_ENABLE USB_ENABLE_DISABLED
2911 .................... #endif 2911 .................... #endif
2912 .................... #ifndef USB_EP3_RX_ENABLE 2912 .................... #ifndef USB_EP3_RX_ENABLE
2913 .................... #define USB_EP3_RX_ENABLE USB_ENABLE_DISABLED 2913 .................... #define USB_EP3_RX_ENABLE USB_ENABLE_DISABLED
2914 .................... #endif 2914 .................... #endif
2915 .................... 2915 ....................
2916 .................... #if USB_EP3_RX_ENABLE==USB_ENABLE_DISABLED 2916 .................... #if USB_EP3_RX_ENABLE==USB_ENABLE_DISABLED
2917 .................... #ifdef USB_EP3_RX_SIZE 2917 .................... #ifdef USB_EP3_RX_SIZE
2918 .................... #undef USB_EP3_RX_SIZE 2918 .................... #undef USB_EP3_RX_SIZE
2919 .................... #endif 2919 .................... #endif
2920 .................... #define USB_EP3_RX_SIZE 0 2920 .................... #define USB_EP3_RX_SIZE 0
2921 .................... #else 2921 .................... #else
2922 .................... #ifndef USB_EP3_RX_SIZE 2922 .................... #ifndef USB_EP3_RX_SIZE
2923 .................... #error You enabled EP3 for RX but didn't specify endpoint size 2923 .................... #error You enabled EP3 for RX but didn't specify endpoint size
2924 .................... #endif 2924 .................... #endif
2925 .................... #endif 2925 .................... #endif
2926 .................... 2926 ....................
2927 .................... #if USB_EP3_TX_ENABLE==USB_ENABLE_DISABLED 2927 .................... #if USB_EP3_TX_ENABLE==USB_ENABLE_DISABLED
2928 .................... #ifdef USB_EP3_TX_SIZE 2928 .................... #ifdef USB_EP3_TX_SIZE
2929 .................... #undef USB_EP3_TX_SIZE 2929 .................... #undef USB_EP3_TX_SIZE
2930 .................... #endif 2930 .................... #endif
2931 .................... #define USB_EP3_TX_SIZE 0 2931 .................... #define USB_EP3_TX_SIZE 0
2932 .................... #else 2932 .................... #else
2933 .................... #ifndef USB_EP3_TX_SIZE 2933 .................... #ifndef USB_EP3_TX_SIZE
2934 .................... #error You enabled EP3 for TX but didn't specify endpoint size 2934 .................... #error You enabled EP3 for TX but didn't specify endpoint size
2935 .................... #endif 2935 .................... #endif
2936 .................... #endif 2936 .................... #endif
2937 .................... 2937 ....................
2938 .................... 2938 ....................
2939 .................... //--------- endpoint 4 defines ---------- 2939 .................... //--------- endpoint 4 defines ----------
2940 .................... #ifndef USB_EP4_TX_ENABLE 2940 .................... #ifndef USB_EP4_TX_ENABLE
2941 .................... #define USB_EP4_TX_ENABLE USB_ENABLE_DISABLED 2941 .................... #define USB_EP4_TX_ENABLE USB_ENABLE_DISABLED
2942 .................... #endif 2942 .................... #endif
2943 .................... #ifndef USB_EP4_RX_ENABLE 2943 .................... #ifndef USB_EP4_RX_ENABLE
2944 .................... #define USB_EP4_RX_ENABLE USB_ENABLE_DISABLED 2944 .................... #define USB_EP4_RX_ENABLE USB_ENABLE_DISABLED
2945 .................... #endif 2945 .................... #endif
2946 .................... 2946 ....................
2947 .................... #if USB_EP4_RX_ENABLE==USB_ENABLE_DISABLED 2947 .................... #if USB_EP4_RX_ENABLE==USB_ENABLE_DISABLED
2948 .................... #ifdef USB_EP4_RX_SIZE 2948 .................... #ifdef USB_EP4_RX_SIZE
2949 .................... #undef USB_EP4_RX_SIZE 2949 .................... #undef USB_EP4_RX_SIZE
2950 .................... #endif 2950 .................... #endif
2951 .................... #define USB_EP4_RX_SIZE 0 2951 .................... #define USB_EP4_RX_SIZE 0
2952 .................... #else 2952 .................... #else
2953 .................... #ifndef USB_EP4_RX_SIZE 2953 .................... #ifndef USB_EP4_RX_SIZE
2954 .................... #error You enabled EP4 for RX but didn't specify endpoint size 2954 .................... #error You enabled EP4 for RX but didn't specify endpoint size
2955 .................... #endif 2955 .................... #endif
2956 .................... #endif 2956 .................... #endif
2957 .................... 2957 ....................
2958 .................... #if USB_EP4_TX_ENABLE==USB_ENABLE_DISABLED 2958 .................... #if USB_EP4_TX_ENABLE==USB_ENABLE_DISABLED
2959 .................... #ifdef USB_EP4_TX_SIZE 2959 .................... #ifdef USB_EP4_TX_SIZE
2960 .................... #undef USB_EP4_TX_SIZE 2960 .................... #undef USB_EP4_TX_SIZE
2961 .................... #endif 2961 .................... #endif
2962 .................... #define USB_EP4_TX_SIZE 0 2962 .................... #define USB_EP4_TX_SIZE 0
2963 .................... #else 2963 .................... #else
2964 .................... #ifndef USB_EP4_TX_SIZE 2964 .................... #ifndef USB_EP4_TX_SIZE
2965 .................... #error You enabled EP4 for TX but didn't specify endpoint size 2965 .................... #error You enabled EP4 for TX but didn't specify endpoint size
2966 .................... #endif 2966 .................... #endif
2967 .................... #endif 2967 .................... #endif
2968 .................... 2968 ....................
2969 .................... 2969 ....................
2970 .................... //--------- endpoint 5 defines ---------- 2970 .................... //--------- endpoint 5 defines ----------
2971 .................... #ifndef USB_EP5_TX_ENABLE 2971 .................... #ifndef USB_EP5_TX_ENABLE
2972 .................... #define USB_EP5_TX_ENABLE USB_ENABLE_DISABLED 2972 .................... #define USB_EP5_TX_ENABLE USB_ENABLE_DISABLED
2973 .................... #endif 2973 .................... #endif
2974 .................... #ifndef USB_EP5_RX_ENABLE 2974 .................... #ifndef USB_EP5_RX_ENABLE
2975 .................... #define USB_EP5_RX_ENABLE USB_ENABLE_DISABLED 2975 .................... #define USB_EP5_RX_ENABLE USB_ENABLE_DISABLED
2976 .................... #endif 2976 .................... #endif
2977 .................... 2977 ....................
2978 .................... #if USB_EP5_RX_ENABLE==USB_ENABLE_DISABLED 2978 .................... #if USB_EP5_RX_ENABLE==USB_ENABLE_DISABLED
2979 .................... #ifdef USB_EP5_RX_SIZE 2979 .................... #ifdef USB_EP5_RX_SIZE
2980 .................... #undef USB_EP5_RX_SIZE 2980 .................... #undef USB_EP5_RX_SIZE
2981 .................... #endif 2981 .................... #endif
2982 .................... #define USB_EP5_RX_SIZE 0 2982 .................... #define USB_EP5_RX_SIZE 0
2983 .................... #else 2983 .................... #else
2984 .................... #ifndef USB_EP5_RX_SIZE 2984 .................... #ifndef USB_EP5_RX_SIZE
2985 .................... #error You enabled EP5 for RX but didn't specify endpoint size 2985 .................... #error You enabled EP5 for RX but didn't specify endpoint size
2986 .................... #endif 2986 .................... #endif
2987 .................... #endif 2987 .................... #endif
2988 .................... 2988 ....................
2989 .................... #if USB_EP5_TX_ENABLE==USB_ENABLE_DISABLED 2989 .................... #if USB_EP5_TX_ENABLE==USB_ENABLE_DISABLED
2990 .................... #ifdef USB_EP5_TX_SIZE 2990 .................... #ifdef USB_EP5_TX_SIZE
2991 .................... #undef USB_EP5_TX_SIZE 2991 .................... #undef USB_EP5_TX_SIZE
2992 .................... #endif 2992 .................... #endif
2993 .................... #define USB_EP5_TX_SIZE 0 2993 .................... #define USB_EP5_TX_SIZE 0
2994 .................... #else 2994 .................... #else
2995 .................... #ifndef USB_EP5_TX_SIZE 2995 .................... #ifndef USB_EP5_TX_SIZE
2996 .................... #error You enabled EP5 for TX but didn't specify endpoint size 2996 .................... #error You enabled EP5 for TX but didn't specify endpoint size
2997 .................... #endif 2997 .................... #endif
2998 .................... #endif 2998 .................... #endif
2999 .................... 2999 ....................
3000 .................... 3000 ....................
3001 .................... //--------- endpoint 6 defines ---------- 3001 .................... //--------- endpoint 6 defines ----------
3002 .................... #ifndef USB_EP6_TX_ENABLE 3002 .................... #ifndef USB_EP6_TX_ENABLE
3003 .................... #define USB_EP6_TX_ENABLE USB_ENABLE_DISABLED 3003 .................... #define USB_EP6_TX_ENABLE USB_ENABLE_DISABLED
3004 .................... #endif 3004 .................... #endif
3005 .................... #ifndef USB_EP6_RX_ENABLE 3005 .................... #ifndef USB_EP6_RX_ENABLE
3006 .................... #define USB_EP6_RX_ENABLE USB_ENABLE_DISABLED 3006 .................... #define USB_EP6_RX_ENABLE USB_ENABLE_DISABLED
3007 .................... #endif 3007 .................... #endif
3008 .................... 3008 ....................
3009 .................... #if USB_EP6_RX_ENABLE==USB_ENABLE_DISABLED 3009 .................... #if USB_EP6_RX_ENABLE==USB_ENABLE_DISABLED
3010 .................... #ifdef USB_EP6_RX_SIZE 3010 .................... #ifdef USB_EP6_RX_SIZE
3011 .................... #undef USB_EP6_RX_SIZE 3011 .................... #undef USB_EP6_RX_SIZE
3012 .................... #endif 3012 .................... #endif
3013 .................... #define USB_EP6_RX_SIZE 0 3013 .................... #define USB_EP6_RX_SIZE 0
3014 .................... #else 3014 .................... #else
3015 .................... #ifndef USB_EP6_RX_SIZE 3015 .................... #ifndef USB_EP6_RX_SIZE
3016 .................... #error You enabled EP6 for RX but didn't specify endpoint size 3016 .................... #error You enabled EP6 for RX but didn't specify endpoint size
3017 .................... #endif 3017 .................... #endif
3018 .................... #endif 3018 .................... #endif
3019 .................... 3019 ....................
3020 .................... #if USB_EP6_TX_ENABLE==USB_ENABLE_DISABLED 3020 .................... #if USB_EP6_TX_ENABLE==USB_ENABLE_DISABLED
3021 .................... #ifdef USB_EP6_TX_SIZE 3021 .................... #ifdef USB_EP6_TX_SIZE
3022 .................... #undef USB_EP6_TX_SIZE 3022 .................... #undef USB_EP6_TX_SIZE
3023 .................... #endif 3023 .................... #endif
3024 .................... #define USB_EP6_TX_SIZE 0 3024 .................... #define USB_EP6_TX_SIZE 0
3025 .................... #else 3025 .................... #else
3026 .................... #ifndef USB_EP6_TX_SIZE 3026 .................... #ifndef USB_EP6_TX_SIZE
3027 .................... #error You enabled EP6 for TX but didn't specify endpoint size 3027 .................... #error You enabled EP6 for TX but didn't specify endpoint size
3028 .................... #endif 3028 .................... #endif
3029 .................... #endif 3029 .................... #endif
3030 .................... 3030 ....................
3031 .................... 3031 ....................
3032 .................... //--------- endpoint 7 defines ---------- 3032 .................... //--------- endpoint 7 defines ----------
3033 .................... #ifndef USB_EP7_TX_ENABLE 3033 .................... #ifndef USB_EP7_TX_ENABLE
3034 .................... #define USB_EP7_TX_ENABLE USB_ENABLE_DISABLED 3034 .................... #define USB_EP7_TX_ENABLE USB_ENABLE_DISABLED
3035 .................... #endif 3035 .................... #endif
3036 .................... #ifndef USB_EP7_RX_ENABLE 3036 .................... #ifndef USB_EP7_RX_ENABLE
3037 .................... #define USB_EP7_RX_ENABLE USB_ENABLE_DISABLED 3037 .................... #define USB_EP7_RX_ENABLE USB_ENABLE_DISABLED
3038 .................... #endif 3038 .................... #endif
3039 .................... 3039 ....................
3040 .................... #if USB_EP7_RX_ENABLE==USB_ENABLE_DISABLED 3040 .................... #if USB_EP7_RX_ENABLE==USB_ENABLE_DISABLED
3041 .................... #ifdef USB_EP7_RX_SIZE 3041 .................... #ifdef USB_EP7_RX_SIZE
3042 .................... #undef USB_EP7_RX_SIZE 3042 .................... #undef USB_EP7_RX_SIZE
3043 .................... #endif 3043 .................... #endif
3044 .................... #define USB_EP7_RX_SIZE 0 3044 .................... #define USB_EP7_RX_SIZE 0
3045 .................... #else 3045 .................... #else
3046 .................... #ifndef USB_EP7_RX_SIZE 3046 .................... #ifndef USB_EP7_RX_SIZE
3047 .................... #error You enabled EP7 for RX but didn't specify endpoint size 3047 .................... #error You enabled EP7 for RX but didn't specify endpoint size
3048 .................... #endif 3048 .................... #endif
3049 .................... #endif 3049 .................... #endif
3050 .................... 3050 ....................
3051 .................... #if USB_EP7_TX_ENABLE==USB_ENABLE_DISABLED 3051 .................... #if USB_EP7_TX_ENABLE==USB_ENABLE_DISABLED
3052 .................... #ifdef USB_EP7_TX_SIZE 3052 .................... #ifdef USB_EP7_TX_SIZE
3053 .................... #undef USB_EP7_TX_SIZE 3053 .................... #undef USB_EP7_TX_SIZE
3054 .................... #endif 3054 .................... #endif
3055 .................... #define USB_EP7_TX_SIZE 0 3055 .................... #define USB_EP7_TX_SIZE 0
3056 .................... #else 3056 .................... #else
3057 .................... #ifndef USB_EP7_TX_SIZE 3057 .................... #ifndef USB_EP7_TX_SIZE
3058 .................... #error You enabled EP7 for TX but didn't specify endpoint size 3058 .................... #error You enabled EP7 for TX but didn't specify endpoint size
3059 .................... #endif 3059 .................... #endif
3060 .................... #endif 3060 .................... #endif
3061 .................... 3061 ....................
3062 .................... 3062 ....................
3063 .................... //--------- endpoint 8 defines ---------- 3063 .................... //--------- endpoint 8 defines ----------
3064 .................... #ifndef USB_EP8_TX_ENABLE 3064 .................... #ifndef USB_EP8_TX_ENABLE
3065 .................... #define USB_EP8_TX_ENABLE USB_ENABLE_DISABLED 3065 .................... #define USB_EP8_TX_ENABLE USB_ENABLE_DISABLED
3066 .................... #endif 3066 .................... #endif
3067 .................... #ifndef USB_EP8_RX_ENABLE 3067 .................... #ifndef USB_EP8_RX_ENABLE
3068 .................... #define USB_EP8_RX_ENABLE USB_ENABLE_DISABLED 3068 .................... #define USB_EP8_RX_ENABLE USB_ENABLE_DISABLED
3069 .................... #endif 3069 .................... #endif
3070 .................... 3070 ....................
3071 .................... #if USB_EP8_RX_ENABLE==USB_ENABLE_DISABLED 3071 .................... #if USB_EP8_RX_ENABLE==USB_ENABLE_DISABLED
3072 .................... #ifdef USB_EP8_RX_SIZE 3072 .................... #ifdef USB_EP8_RX_SIZE
3073 .................... #undef USB_EP8_RX_SIZE 3073 .................... #undef USB_EP8_RX_SIZE
3074 .................... #endif 3074 .................... #endif
3075 .................... #define USB_EP8_RX_SIZE 0 3075 .................... #define USB_EP8_RX_SIZE 0
3076 .................... #else 3076 .................... #else
3077 .................... #ifndef USB_EP8_RX_SIZE 3077 .................... #ifndef USB_EP8_RX_SIZE
3078 .................... #error You enabled EP8 for RX but didn't specify endpoint size 3078 .................... #error You enabled EP8 for RX but didn't specify endpoint size
3079 .................... #endif 3079 .................... #endif
3080 .................... #endif 3080 .................... #endif
3081 .................... 3081 ....................
3082 .................... #if USB_EP8_TX_ENABLE==USB_ENABLE_DISABLED 3082 .................... #if USB_EP8_TX_ENABLE==USB_ENABLE_DISABLED
3083 .................... #ifdef USB_EP8_TX_SIZE 3083 .................... #ifdef USB_EP8_TX_SIZE
3084 .................... #undef USB_EP8_TX_SIZE 3084 .................... #undef USB_EP8_TX_SIZE
3085 .................... #endif 3085 .................... #endif
3086 .................... #define USB_EP8_TX_SIZE 0 3086 .................... #define USB_EP8_TX_SIZE 0
3087 .................... #else 3087 .................... #else
3088 .................... #ifndef USB_EP8_TX_SIZE 3088 .................... #ifndef USB_EP8_TX_SIZE
3089 .................... #error You enabled EP8 for TX but didn't specify endpoint size 3089 .................... #error You enabled EP8 for TX but didn't specify endpoint size
3090 .................... #endif 3090 .................... #endif
3091 .................... #endif 3091 .................... #endif
3092 .................... 3092 ....................
3093 .................... 3093 ....................
3094 .................... //--------- endpoint 9 defines ---------- 3094 .................... //--------- endpoint 9 defines ----------
3095 .................... #ifndef USB_EP9_TX_ENABLE 3095 .................... #ifndef USB_EP9_TX_ENABLE
3096 .................... #define USB_EP9_TX_ENABLE USB_ENABLE_DISABLED 3096 .................... #define USB_EP9_TX_ENABLE USB_ENABLE_DISABLED
3097 .................... #endif 3097 .................... #endif
3098 .................... #ifndef USB_EP9_RX_ENABLE 3098 .................... #ifndef USB_EP9_RX_ENABLE
3099 .................... #define USB_EP9_RX_ENABLE USB_ENABLE_DISABLED 3099 .................... #define USB_EP9_RX_ENABLE USB_ENABLE_DISABLED
3100 .................... #endif 3100 .................... #endif
3101 .................... 3101 ....................
3102 .................... #if USB_EP9_RX_ENABLE==USB_ENABLE_DISABLED 3102 .................... #if USB_EP9_RX_ENABLE==USB_ENABLE_DISABLED
3103 .................... #ifdef USB_EP9_RX_SIZE 3103 .................... #ifdef USB_EP9_RX_SIZE
3104 .................... #undef USB_EP9_RX_SIZE 3104 .................... #undef USB_EP9_RX_SIZE
3105 .................... #endif 3105 .................... #endif
3106 .................... #define USB_EP9_RX_SIZE 0 3106 .................... #define USB_EP9_RX_SIZE 0
3107 .................... #else 3107 .................... #else
3108 .................... #ifndef USB_EP9_RX_SIZE 3108 .................... #ifndef USB_EP9_RX_SIZE
3109 .................... #error You enabled EP9 for RX but didn't specify endpoint size 3109 .................... #error You enabled EP9 for RX but didn't specify endpoint size
3110 .................... #endif 3110 .................... #endif
3111 .................... #endif 3111 .................... #endif
3112 .................... 3112 ....................
3113 .................... #if USB_EP9_TX_ENABLE==USB_ENABLE_DISABLED 3113 .................... #if USB_EP9_TX_ENABLE==USB_ENABLE_DISABLED
3114 .................... #ifdef USB_EP9_TX_SIZE 3114 .................... #ifdef USB_EP9_TX_SIZE
3115 .................... #undef USB_EP9_TX_SIZE 3115 .................... #undef USB_EP9_TX_SIZE
3116 .................... #endif 3116 .................... #endif
3117 .................... #define USB_EP9_TX_SIZE 0 3117 .................... #define USB_EP9_TX_SIZE 0
3118 .................... #else 3118 .................... #else
3119 .................... #ifndef USB_EP9_TX_SIZE 3119 .................... #ifndef USB_EP9_TX_SIZE
3120 .................... #error You enabled EP9 for TX but didn't specify endpoint size 3120 .................... #error You enabled EP9 for TX but didn't specify endpoint size
3121 .................... #endif 3121 .................... #endif
3122 .................... #endif 3122 .................... #endif
3123 .................... 3123 ....................
3124 .................... 3124 ....................
3125 .................... //--------- endpoint 10 defines ---------- 3125 .................... //--------- endpoint 10 defines ----------
3126 .................... #ifndef USB_EP10_TX_ENABLE 3126 .................... #ifndef USB_EP10_TX_ENABLE
3127 .................... #define USB_EP10_TX_ENABLE USB_ENABLE_DISABLED 3127 .................... #define USB_EP10_TX_ENABLE USB_ENABLE_DISABLED
3128 .................... #endif 3128 .................... #endif
3129 .................... #ifndef USB_EP10_RX_ENABLE 3129 .................... #ifndef USB_EP10_RX_ENABLE
3130 .................... #define USB_EP10_RX_ENABLE USB_ENABLE_DISABLED 3130 .................... #define USB_EP10_RX_ENABLE USB_ENABLE_DISABLED
3131 .................... #endif 3131 .................... #endif
3132 .................... 3132 ....................
3133 .................... #if USB_EP10_RX_ENABLE==USB_ENABLE_DISABLED 3133 .................... #if USB_EP10_RX_ENABLE==USB_ENABLE_DISABLED
3134 .................... #ifdef USB_EP10_RX_SIZE 3134 .................... #ifdef USB_EP10_RX_SIZE
3135 .................... #undef USB_EP10_RX_SIZE 3135 .................... #undef USB_EP10_RX_SIZE
3136 .................... #endif 3136 .................... #endif
3137 .................... #define USB_EP10_RX_SIZE 0 3137 .................... #define USB_EP10_RX_SIZE 0
3138 .................... #else 3138 .................... #else
3139 .................... #ifndef USB_EP10_RX_SIZE 3139 .................... #ifndef USB_EP10_RX_SIZE
3140 .................... #error You enabled EP10 for RX but didn't specify endpoint size 3140 .................... #error You enabled EP10 for RX but didn't specify endpoint size
3141 .................... #endif 3141 .................... #endif
3142 .................... #endif 3142 .................... #endif
3143 .................... 3143 ....................
3144 .................... #if USB_EP10_TX_ENABLE==USB_ENABLE_DISABLED 3144 .................... #if USB_EP10_TX_ENABLE==USB_ENABLE_DISABLED
3145 .................... #ifdef USB_EP10_TX_SIZE 3145 .................... #ifdef USB_EP10_TX_SIZE
3146 .................... #undef USB_EP10_TX_SIZE 3146 .................... #undef USB_EP10_TX_SIZE
3147 .................... #endif 3147 .................... #endif
3148 .................... #define USB_EP10_TX_SIZE 0 3148 .................... #define USB_EP10_TX_SIZE 0
3149 .................... #else 3149 .................... #else
3150 .................... #ifndef USB_EP10_TX_SIZE 3150 .................... #ifndef USB_EP10_TX_SIZE
3151 .................... #error You enabled EP10 for TX but didn't specify endpoint size 3151 .................... #error You enabled EP10 for TX but didn't specify endpoint size
3152 .................... #endif 3152 .................... #endif
3153 .................... #endif 3153 .................... #endif
3154 .................... 3154 ....................
3155 .................... 3155 ....................
3156 .................... //--------- endpoint 11 defines ---------- 3156 .................... //--------- endpoint 11 defines ----------
3157 .................... #ifndef USB_EP11_TX_ENABLE 3157 .................... #ifndef USB_EP11_TX_ENABLE
3158 .................... #define USB_EP11_TX_ENABLE USB_ENABLE_DISABLED 3158 .................... #define USB_EP11_TX_ENABLE USB_ENABLE_DISABLED
3159 .................... #endif 3159 .................... #endif
3160 .................... #ifndef USB_EP11_RX_ENABLE 3160 .................... #ifndef USB_EP11_RX_ENABLE
3161 .................... #define USB_EP11_RX_ENABLE USB_ENABLE_DISABLED 3161 .................... #define USB_EP11_RX_ENABLE USB_ENABLE_DISABLED
3162 .................... #endif 3162 .................... #endif
3163 .................... 3163 ....................
3164 .................... #if USB_EP11_RX_ENABLE==USB_ENABLE_DISABLED 3164 .................... #if USB_EP11_RX_ENABLE==USB_ENABLE_DISABLED
3165 .................... #ifdef USB_EP11_RX_SIZE 3165 .................... #ifdef USB_EP11_RX_SIZE
3166 .................... #undef USB_EP11_RX_SIZE 3166 .................... #undef USB_EP11_RX_SIZE
3167 .................... #endif 3167 .................... #endif
3168 .................... #define USB_EP11_RX_SIZE 0 3168 .................... #define USB_EP11_RX_SIZE 0
3169 .................... #else 3169 .................... #else
3170 .................... #ifndef USB_EP11_RX_SIZE 3170 .................... #ifndef USB_EP11_RX_SIZE
3171 .................... #error You enabled EP11 for RX but didn't specify endpoint size 3171 .................... #error You enabled EP11 for RX but didn't specify endpoint size
3172 .................... #endif 3172 .................... #endif
3173 .................... #endif 3173 .................... #endif
3174 .................... 3174 ....................
3175 .................... #if USB_EP11_TX_ENABLE==USB_ENABLE_DISABLED 3175 .................... #if USB_EP11_TX_ENABLE==USB_ENABLE_DISABLED
3176 .................... #ifdef USB_EP11_TX_SIZE 3176 .................... #ifdef USB_EP11_TX_SIZE
3177 .................... #undef USB_EP11_TX_SIZE 3177 .................... #undef USB_EP11_TX_SIZE
3178 .................... #endif 3178 .................... #endif
3179 .................... #define USB_EP11_TX_SIZE 0 3179 .................... #define USB_EP11_TX_SIZE 0
3180 .................... #else 3180 .................... #else
3181 .................... #ifndef USB_EP11_TX_SIZE 3181 .................... #ifndef USB_EP11_TX_SIZE
3182 .................... #error You enabled EP11 for TX but didn't specify endpoint size 3182 .................... #error You enabled EP11 for TX but didn't specify endpoint size
3183 .................... #endif 3183 .................... #endif
3184 .................... #endif 3184 .................... #endif
3185 .................... 3185 ....................
3186 .................... 3186 ....................
3187 .................... //--------- endpoint 12 defines ---------- 3187 .................... //--------- endpoint 12 defines ----------
3188 .................... #ifndef USB_EP12_TX_ENABLE 3188 .................... #ifndef USB_EP12_TX_ENABLE
3189 .................... #define USB_EP12_TX_ENABLE USB_ENABLE_DISABLED 3189 .................... #define USB_EP12_TX_ENABLE USB_ENABLE_DISABLED
3190 .................... #endif 3190 .................... #endif
3191 .................... #ifndef USB_EP12_RX_ENABLE 3191 .................... #ifndef USB_EP12_RX_ENABLE
3192 .................... #define USB_EP12_RX_ENABLE USB_ENABLE_DISABLED 3192 .................... #define USB_EP12_RX_ENABLE USB_ENABLE_DISABLED
3193 .................... #endif 3193 .................... #endif
3194 .................... 3194 ....................
3195 .................... #if USB_EP12_RX_ENABLE==USB_ENABLE_DISABLED 3195 .................... #if USB_EP12_RX_ENABLE==USB_ENABLE_DISABLED
3196 .................... #ifdef USB_EP12_RX_SIZE 3196 .................... #ifdef USB_EP12_RX_SIZE
3197 .................... #undef USB_EP12_RX_SIZE 3197 .................... #undef USB_EP12_RX_SIZE
3198 .................... #endif 3198 .................... #endif
3199 .................... #define USB_EP12_RX_SIZE 0 3199 .................... #define USB_EP12_RX_SIZE 0
3200 .................... #else 3200 .................... #else
3201 .................... #ifndef USB_EP12_RX_SIZE 3201 .................... #ifndef USB_EP12_RX_SIZE
3202 .................... #error You enabled EP12 for RX but didn't specify endpoint size 3202 .................... #error You enabled EP12 for RX but didn't specify endpoint size
3203 .................... #endif 3203 .................... #endif
3204 .................... #endif 3204 .................... #endif
3205 .................... 3205 ....................
3206 .................... #if USB_EP12_TX_ENABLE==USB_ENABLE_DISABLED 3206 .................... #if USB_EP12_TX_ENABLE==USB_ENABLE_DISABLED
3207 .................... #ifdef USB_EP12_TX_SIZE 3207 .................... #ifdef USB_EP12_TX_SIZE
3208 .................... #undef USB_EP12_TX_SIZE 3208 .................... #undef USB_EP12_TX_SIZE
3209 .................... #endif 3209 .................... #endif
3210 .................... #define USB_EP12_TX_SIZE 0 3210 .................... #define USB_EP12_TX_SIZE 0
3211 .................... #else 3211 .................... #else
3212 .................... #ifndef USB_EP12_TX_SIZE 3212 .................... #ifndef USB_EP12_TX_SIZE
3213 .................... #error You enabled EP12 for TX but didn't specify endpoint size 3213 .................... #error You enabled EP12 for TX but didn't specify endpoint size
3214 .................... #endif 3214 .................... #endif
3215 .................... #endif 3215 .................... #endif
3216 .................... 3216 ....................
3217 .................... 3217 ....................
3218 .................... //--------- endpoint 13 defines ---------- 3218 .................... //--------- endpoint 13 defines ----------
3219 .................... #ifndef USB_EP13_TX_ENABLE 3219 .................... #ifndef USB_EP13_TX_ENABLE
3220 .................... #define USB_EP13_TX_ENABLE USB_ENABLE_DISABLED 3220 .................... #define USB_EP13_TX_ENABLE USB_ENABLE_DISABLED
3221 .................... #endif 3221 .................... #endif
3222 .................... #ifndef USB_EP13_RX_ENABLE 3222 .................... #ifndef USB_EP13_RX_ENABLE
3223 .................... #define USB_EP13_RX_ENABLE USB_ENABLE_DISABLED 3223 .................... #define USB_EP13_RX_ENABLE USB_ENABLE_DISABLED
3224 .................... #endif 3224 .................... #endif
3225 .................... 3225 ....................
3226 .................... #if USB_EP13_RX_ENABLE==USB_ENABLE_DISABLED 3226 .................... #if USB_EP13_RX_ENABLE==USB_ENABLE_DISABLED
3227 .................... #ifdef USB_EP13_RX_SIZE 3227 .................... #ifdef USB_EP13_RX_SIZE
3228 .................... #undef USB_EP13_RX_SIZE 3228 .................... #undef USB_EP13_RX_SIZE
3229 .................... #endif 3229 .................... #endif
3230 .................... #define USB_EP13_RX_SIZE 0 3230 .................... #define USB_EP13_RX_SIZE 0
3231 .................... #else 3231 .................... #else
3232 .................... #ifndef USB_EP13_RX_SIZE 3232 .................... #ifndef USB_EP13_RX_SIZE
3233 .................... #error You enabled EP13 for RX but didn't specify endpoint size 3233 .................... #error You enabled EP13 for RX but didn't specify endpoint size
3234 .................... #endif 3234 .................... #endif
3235 .................... #endif 3235 .................... #endif
3236 .................... 3236 ....................
3237 .................... #if USB_EP13_TX_ENABLE==USB_ENABLE_DISABLED 3237 .................... #if USB_EP13_TX_ENABLE==USB_ENABLE_DISABLED
3238 .................... #ifdef USB_EP13_TX_SIZE 3238 .................... #ifdef USB_EP13_TX_SIZE
3239 .................... #undef USB_EP13_TX_SIZE 3239 .................... #undef USB_EP13_TX_SIZE
3240 .................... #endif 3240 .................... #endif
3241 .................... #define USB_EP13_TX_SIZE 0 3241 .................... #define USB_EP13_TX_SIZE 0
3242 .................... #else 3242 .................... #else
3243 .................... #ifndef USB_EP13_TX_SIZE 3243 .................... #ifndef USB_EP13_TX_SIZE
3244 .................... #error You enabled EP13 for TX but didn't specify endpoint size 3244 .................... #error You enabled EP13 for TX but didn't specify endpoint size
3245 .................... #endif 3245 .................... #endif
3246 .................... #endif 3246 .................... #endif
3247 .................... 3247 ....................
3248 .................... 3248 ....................
3249 .................... //--------- endpoint 14 defines ---------- 3249 .................... //--------- endpoint 14 defines ----------
3250 .................... #ifndef USB_EP14_TX_ENABLE 3250 .................... #ifndef USB_EP14_TX_ENABLE
3251 .................... #define USB_EP14_TX_ENABLE USB_ENABLE_DISABLED 3251 .................... #define USB_EP14_TX_ENABLE USB_ENABLE_DISABLED
3252 .................... #endif 3252 .................... #endif
3253 .................... #ifndef USB_EP14_RX_ENABLE 3253 .................... #ifndef USB_EP14_RX_ENABLE
3254 .................... #define USB_EP14_RX_ENABLE USB_ENABLE_DISABLED 3254 .................... #define USB_EP14_RX_ENABLE USB_ENABLE_DISABLED
3255 .................... #endif 3255 .................... #endif
3256 .................... 3256 ....................
3257 .................... #if USB_EP14_RX_ENABLE==USB_ENABLE_DISABLED 3257 .................... #if USB_EP14_RX_ENABLE==USB_ENABLE_DISABLED
3258 .................... #ifdef USB_EP14_RX_SIZE 3258 .................... #ifdef USB_EP14_RX_SIZE
3259 .................... #undef USB_EP14_RX_SIZE 3259 .................... #undef USB_EP14_RX_SIZE
3260 .................... #endif 3260 .................... #endif
3261 .................... #define USB_EP14_RX_SIZE 0 3261 .................... #define USB_EP14_RX_SIZE 0
3262 .................... #else 3262 .................... #else
3263 .................... #ifndef USB_EP14_RX_SIZE 3263 .................... #ifndef USB_EP14_RX_SIZE
3264 .................... #error You enabled EP14 for RX but didn't specify endpoint size 3264 .................... #error You enabled EP14 for RX but didn't specify endpoint size
3265 .................... #endif 3265 .................... #endif
3266 .................... #endif 3266 .................... #endif
3267 .................... 3267 ....................
3268 .................... #if USB_EP14_TX_ENABLE==USB_ENABLE_DISABLED 3268 .................... #if USB_EP14_TX_ENABLE==USB_ENABLE_DISABLED
3269 .................... #ifdef USB_EP14_TX_SIZE 3269 .................... #ifdef USB_EP14_TX_SIZE
3270 .................... #undef USB_EP14_TX_SIZE 3270 .................... #undef USB_EP14_TX_SIZE
3271 .................... #endif 3271 .................... #endif
3272 .................... #define USB_EP14_TX_SIZE 0 3272 .................... #define USB_EP14_TX_SIZE 0
3273 .................... #else 3273 .................... #else
3274 .................... #ifndef USB_EP14_TX_SIZE 3274 .................... #ifndef USB_EP14_TX_SIZE
3275 .................... #error You enabled EP14 for TX but didn't specify endpoint size 3275 .................... #error You enabled EP14 for TX but didn't specify endpoint size
3276 .................... #endif 3276 .................... #endif
3277 .................... #endif 3277 .................... #endif
3278 .................... 3278 ....................
3279 .................... 3279 ....................
3280 .................... //--------- endpoint 15 defines ---------- 3280 .................... //--------- endpoint 15 defines ----------
3281 .................... #ifndef USB_EP15_TX_ENABLE 3281 .................... #ifndef USB_EP15_TX_ENABLE
3282 .................... #define USB_EP15_TX_ENABLE USB_ENABLE_DISABLED 3282 .................... #define USB_EP15_TX_ENABLE USB_ENABLE_DISABLED
3283 .................... #endif 3283 .................... #endif
3284 .................... #ifndef USB_EP15_RX_ENABLE 3284 .................... #ifndef USB_EP15_RX_ENABLE
3285 .................... #define USB_EP15_RX_ENABLE USB_ENABLE_DISABLED 3285 .................... #define USB_EP15_RX_ENABLE USB_ENABLE_DISABLED
3286 .................... #endif 3286 .................... #endif
3287 .................... 3287 ....................
3288 .................... #if USB_EP15_RX_ENABLE==USB_ENABLE_DISABLED 3288 .................... #if USB_EP15_RX_ENABLE==USB_ENABLE_DISABLED
3289 .................... #ifdef USB_EP15_RX_SIZE 3289 .................... #ifdef USB_EP15_RX_SIZE
3290 .................... #undef USB_EP15_RX_SIZE 3290 .................... #undef USB_EP15_RX_SIZE
3291 .................... #endif 3291 .................... #endif
3292 .................... #define USB_EP15_RX_SIZE 0 3292 .................... #define USB_EP15_RX_SIZE 0
3293 .................... #else 3293 .................... #else
3294 .................... #ifndef USB_EP15_RX_SIZE 3294 .................... #ifndef USB_EP15_RX_SIZE
3295 .................... #error You enabled EP15 for RX but didn't specify endpoint size 3295 .................... #error You enabled EP15 for RX but didn't specify endpoint size
3296 .................... #endif 3296 .................... #endif
3297 .................... #endif 3297 .................... #endif
3298 .................... 3298 ....................
3299 .................... #if USB_EP15_TX_ENABLE==USB_ENABLE_DISABLED 3299 .................... #if USB_EP15_TX_ENABLE==USB_ENABLE_DISABLED
3300 .................... #ifdef USB_EP15_TX_SIZE 3300 .................... #ifdef USB_EP15_TX_SIZE
3301 .................... #undef USB_EP15_TX_SIZE 3301 .................... #undef USB_EP15_TX_SIZE
3302 .................... #endif 3302 .................... #endif
3303 .................... #define USB_EP15_TX_SIZE 0 3303 .................... #define USB_EP15_TX_SIZE 0
3304 .................... #else 3304 .................... #else
3305 .................... #ifndef USB_EP15_TX_SIZE 3305 .................... #ifndef USB_EP15_TX_SIZE
3306 .................... #error You enabled EP15 for TX but didn't specify endpoint size 3306 .................... #error You enabled EP15 for TX but didn't specify endpoint size
3307 .................... #endif 3307 .................... #endif
3308 .................... #endif 3308 .................... #endif
3309 .................... 3309 ....................
3310 .................... const int8 usb_ep_tx_type[16]={ 3310 .................... const int8 usb_ep_tx_type[16]={
3311 .................... USB_EP0_TX_ENABLE, USB_EP1_TX_ENABLE, USB_EP2_TX_ENABLE, 3311 .................... USB_EP0_TX_ENABLE, USB_EP1_TX_ENABLE, USB_EP2_TX_ENABLE,
3312 .................... USB_EP3_TX_ENABLE, USB_EP4_TX_ENABLE, USB_EP5_TX_ENABLE, 3312 .................... USB_EP3_TX_ENABLE, USB_EP4_TX_ENABLE, USB_EP5_TX_ENABLE,
3313 .................... USB_EP6_TX_ENABLE, USB_EP7_TX_ENABLE, USB_EP8_TX_ENABLE, 3313 .................... USB_EP6_TX_ENABLE, USB_EP7_TX_ENABLE, USB_EP8_TX_ENABLE,
3314 .................... USB_EP9_TX_ENABLE, USB_EP10_TX_ENABLE, USB_EP11_TX_ENABLE, 3314 .................... USB_EP9_TX_ENABLE, USB_EP10_TX_ENABLE, USB_EP11_TX_ENABLE,
3315 .................... USB_EP12_TX_ENABLE, USB_EP13_TX_ENABLE, USB_EP14_TX_ENABLE, 3315 .................... USB_EP12_TX_ENABLE, USB_EP13_TX_ENABLE, USB_EP14_TX_ENABLE,
3316 .................... USB_EP15_TX_ENABLE 3316 .................... USB_EP15_TX_ENABLE
3317 .................... }; 3317 .................... };
3318 .................... 3318 ....................
3319 .................... const int8 usb_ep_rx_type[16]={ 3319 .................... const int8 usb_ep_rx_type[16]={
3320 .................... USB_EP0_RX_ENABLE, USB_EP1_RX_ENABLE, USB_EP2_RX_ENABLE, 3320 .................... USB_EP0_RX_ENABLE, USB_EP1_RX_ENABLE, USB_EP2_RX_ENABLE,
3321 .................... USB_EP3_RX_ENABLE, USB_EP4_RX_ENABLE, USB_EP5_RX_ENABLE, 3321 .................... USB_EP3_RX_ENABLE, USB_EP4_RX_ENABLE, USB_EP5_RX_ENABLE,
3322 .................... USB_EP6_RX_ENABLE, USB_EP7_RX_ENABLE, USB_EP8_RX_ENABLE, 3322 .................... USB_EP6_RX_ENABLE, USB_EP7_RX_ENABLE, USB_EP8_RX_ENABLE,
3323 .................... USB_EP9_RX_ENABLE, USB_EP10_RX_ENABLE, USB_EP11_RX_ENABLE, 3323 .................... USB_EP9_RX_ENABLE, USB_EP10_RX_ENABLE, USB_EP11_RX_ENABLE,
3324 .................... USB_EP12_RX_ENABLE, USB_EP13_RX_ENABLE, USB_EP14_RX_ENABLE, 3324 .................... USB_EP12_RX_ENABLE, USB_EP13_RX_ENABLE, USB_EP14_RX_ENABLE,
3325 .................... USB_EP15_RX_ENABLE 3325 .................... USB_EP15_RX_ENABLE
3326 .................... }; 3326 .................... };
3327 .................... 3327 ....................
3328 .................... const unsigned int16 usb_ep_tx_size[16]={ 3328 .................... const unsigned int16 usb_ep_tx_size[16]={
3329 .................... USB_EP0_TX_SIZE, USB_EP1_TX_SIZE, USB_EP2_TX_SIZE, 3329 .................... USB_EP0_TX_SIZE, USB_EP1_TX_SIZE, USB_EP2_TX_SIZE,
3330 .................... USB_EP3_TX_SIZE, USB_EP4_TX_SIZE, USB_EP5_TX_SIZE, 3330 .................... USB_EP3_TX_SIZE, USB_EP4_TX_SIZE, USB_EP5_TX_SIZE,
3331 .................... USB_EP6_TX_SIZE, USB_EP7_TX_SIZE, USB_EP8_TX_SIZE, 3331 .................... USB_EP6_TX_SIZE, USB_EP7_TX_SIZE, USB_EP8_TX_SIZE,
3332 .................... USB_EP9_TX_SIZE, USB_EP10_TX_SIZE, USB_EP11_TX_SIZE, 3332 .................... USB_EP9_TX_SIZE, USB_EP10_TX_SIZE, USB_EP11_TX_SIZE,
3333 .................... USB_EP12_TX_SIZE, USB_EP13_TX_SIZE, USB_EP14_TX_SIZE, 3333 .................... USB_EP12_TX_SIZE, USB_EP13_TX_SIZE, USB_EP14_TX_SIZE,
3334 .................... USB_EP15_TX_SIZE 3334 .................... USB_EP15_TX_SIZE
3335 .................... }; 3335 .................... };
3336 .................... 3336 ....................
3337 .................... const unsigned int16 usb_ep_rx_size[16]={ 3337 .................... const unsigned int16 usb_ep_rx_size[16]={
3338 .................... USB_EP0_RX_SIZE, USB_EP1_RX_SIZE, USB_EP2_RX_SIZE, 3338 .................... USB_EP0_RX_SIZE, USB_EP1_RX_SIZE, USB_EP2_RX_SIZE,
3339 .................... USB_EP3_RX_SIZE, USB_EP4_RX_SIZE, USB_EP5_RX_SIZE, 3339 .................... USB_EP3_RX_SIZE, USB_EP4_RX_SIZE, USB_EP5_RX_SIZE,
3340 .................... USB_EP6_RX_SIZE, USB_EP7_RX_SIZE, USB_EP8_RX_SIZE, 3340 .................... USB_EP6_RX_SIZE, USB_EP7_RX_SIZE, USB_EP8_RX_SIZE,
3341 .................... USB_EP9_RX_SIZE, USB_EP10_RX_SIZE, USB_EP11_RX_SIZE, 3341 .................... USB_EP9_RX_SIZE, USB_EP10_RX_SIZE, USB_EP11_RX_SIZE,
3342 .................... USB_EP12_RX_SIZE, USB_EP13_RX_SIZE, USB_EP14_RX_SIZE, 3342 .................... USB_EP12_RX_SIZE, USB_EP13_RX_SIZE, USB_EP14_RX_SIZE,
3343 .................... USB_EP15_RX_SIZE 3343 .................... USB_EP15_RX_SIZE
3344 .................... }; 3344 .................... };
3345 .................... 3345 ....................
3346 .................... #ENDIF 3346 .................... #ENDIF
3347 .................... 3347 ....................
3348 .................... 3348 ....................
3349 .................... #if defined(__PIC16_USB_H__) 3349 .................... #if defined(__PIC16_USB_H__)
3350 .................... #include <pic_usb.c> 3350 .................... #include <pic_usb.c>
3351 .................... #endif 3351 .................... #endif
3352 .................... 3352 ....................
3353 .................... #if defined(__PIC18_USB_H__) 3353 .................... #if defined(__PIC18_USB_H__)
3354 .................... #include <pic18_usb.c> 3354 .................... #include <pic18_usb.c>
3355 .................... ///////////////////////////////////////////////////////////////////////// 3355 .................... /////////////////////////////////////////////////////////////////////////
3356 .................... //// pic18_usb.c //// 3356 .................... //// pic18_usb.c ////
3357 .................... //// //// 3357 .................... //// ////
3358 .................... //// Hardware layer for CCS's USB library. See pic18_usb.h more //// 3358 .................... //// Hardware layer for CCS's USB library. See pic18_usb.h more ////
3359 .................... //// documentation about the PIC18 hardware layer. //// 3359 .................... //// documentation about the PIC18 hardware layer. ////
3360 .................... //// //// 3360 .................... //// ////
3361 .................... //// This file is part of CCS's PIC USB driver code. See USB.H //// 3361 .................... //// This file is part of CCS's PIC USB driver code. See USB.H ////
3362 .................... //// for more documentation and a list of examples. //// 3362 .................... //// for more documentation and a list of examples. ////
3363 .................... //// //// 3363 .................... //// ////
3364 .................... ///////////////////////////////////////////////////////////////////////// 3364 .................... /////////////////////////////////////////////////////////////////////////
3365 .................... //// //// 3365 .................... //// ////
3366 .................... //// Version History: //// 3366 .................... //// Version History: ////
3367 .................... //// //// 3367 .................... //// ////
3368 .................... //// March 5th, 2009: //// 3368 .................... //// March 5th, 2009: ////
3369 .................... //// 18F14K50 family added. //// 3369 .................... //// 18F14K50 family added. ////
3370 .................... //// Cleanup for Wizard. //// 3370 .................... //// Cleanup for Wizard. ////
3371 .................... //// PIC24 Initial release. //// 3371 .................... //// PIC24 Initial release. ////
3372 .................... //// //// 3372 .................... //// ////
3373 .................... //// Nov 3rd, 2008: //// 3373 .................... //// Nov 3rd, 2008: ////
3374 .................... //// * 4553 family added. //// 3374 .................... //// * 4553 family added. ////
3375 .................... //// //// 3375 .................... //// ////
3376 .................... //// Dec 18, 2007: //// 3376 .................... //// Dec 18, 2007: ////
3377 .................... //// * usb_kbhit() moved to device driver. //// 3377 .................... //// * usb_kbhit() moved to device driver. ////
3378 .................... //// * USB Token handler changed to workaround a flaw in the USB //// 3378 .................... //// * USB Token handler changed to workaround a flaw in the USB ////
3379 .................... //// peripheral to prevent the USB peripheral from //// 3379 .................... //// peripheral to prevent the USB peripheral from ////
3380 .................... //// inadvertantly STALLing the endpoint. Happened most often //// 3380 .................... //// inadvertantly STALLing the endpoint. Happened most often ////
3381 .................... //// in bulk demo applications, especially CDC. //// 3381 .................... //// in bulk demo applications, especially CDC. ////
3382 .................... //// //// 3382 .................... //// ////
3383 .................... //// 11-6-07: Fixed a bug where usb_data_buffer[] was reserving //// 3383 .................... //// 11-6-07: Fixed a bug where usb_data_buffer[] was reserving ////
3384 .................... //// too much RAM. //// 3384 .................... //// too much RAM. ////
3385 .................... //// USB_MAX_EP0_PACKET_LENGTH value can be overwritten. //// 3385 .................... //// USB_MAX_EP0_PACKET_LENGTH value can be overwritten. ////
3386 .................... //// For the 18F4450/2450 family this should be 8 //// 3386 .................... //// For the 18F4450/2450 family this should be 8 ////
3387 .................... //// because of limited RAM. Reducing this value //// 3387 .................... //// because of limited RAM. Reducing this value ////
3388 .................... //// frees RAM for application. //// 3388 .................... //// frees RAM for application. ////
3389 .................... //// Based upon which endpoints have been configured for //// 3389 .................... //// Based upon which endpoints have been configured for ////
3390 .................... //// use, will free up unused USB data RAM for //// 3390 .................... //// use, will free up unused USB data RAM for ////
3391 .................... //// application dynamically. This should free up //// 3391 .................... //// application dynamically. This should free up ////
3392 .................... //// at least 128 bytes of RAM. //// 3392 .................... //// at least 128 bytes of RAM. ////
3393 .................... //// CDC now fits on a 18F4450/2450 //// 3393 .................... //// CDC now fits on a 18F4450/2450 ////
3394 .................... //// //// 3394 .................... //// ////
3395 .................... //// 09-19-07: Fixed problems with 18F4450 family. //// 3395 .................... //// 09-19-07: Fixed problems with 18F4450 family. ////
3396 .................... //// //// 3396 .................... //// ////
3397 .................... //// 07-17-07: Added 18F4450,2450 support //// 3397 .................... //// 07-17-07: Added 18F4450,2450 support ////
3398 .................... //// //// 3398 .................... //// ////
3399 .................... //// 07-13-07: Added 87J50 family support //// 3399 .................... //// 07-13-07: Added 87J50 family support ////
3400 .................... //// //// 3400 .................... //// ////
3401 .................... //// 11-01-05: usb_detach(), usb_attach() and usb_init_cs() //// 3401 .................... //// 11-01-05: usb_detach(), usb_attach() and usb_init_cs() ////
3402 .................... //// changed for the better. //// 3402 .................... //// changed for the better. ////
3403 .................... //// //// 3403 .................... //// ////
3404 .................... //// 10-28-05: Added usb_rx_packet_size() //// 3404 .................... //// 10-28-05: Added usb_rx_packet_size() ////
3405 .................... //// //// 3405 .................... //// ////
3406 .................... //// 07-13-05: usb_put_packet() changed for 16bit packet sizes //// 3406 .................... //// 07-13-05: usb_put_packet() changed for 16bit packet sizes ////
3407 .................... //// usb_flush_in() changed for 16bit packet sizes //// 3407 .................... //// usb_flush_in() changed for 16bit packet sizes ////
3408 .................... //// usb_get_packet() changed for 16bit packet sizes //// 3408 .................... //// usb_get_packet() changed for 16bit packet sizes ////
3409 .................... //// usb_flush_out() changed for 16bit packet sizes //// 3409 .................... //// usb_flush_out() changed for 16bit packet sizes ////
3410 .................... //// usb_set_configured() changed for 16bit packet sizes //// 3410 .................... //// usb_set_configured() changed for 16bit packet sizes ////
3411 .................... //// //// 3411 .................... //// ////
3412 .................... //// 06-30-05: usb_tbe() added //// 3412 .................... //// 06-30-05: usb_tbe() added ////
3413 .................... //// The way endpoint 0 DTS is set has been changed. //// 3413 .................... //// The way endpoint 0 DTS is set has been changed. ////
3414 .................... //// //// 3414 .................... //// ////
3415 .................... //// 06-20-05: Initial Release //// 3415 .................... //// 06-20-05: Initial Release ////
3416 .................... //// //// 3416 .................... //// ////
3417 .................... //// 05-13-05: Beta Release (Full Speed works) //// 3417 .................... //// 05-13-05: Beta Release (Full Speed works) ////
3418 .................... //// //// 3418 .................... //// ////
3419 .................... //// 03-21-05: Initial Alpha Release //// 3419 .................... //// 03-21-05: Initial Alpha Release ////
3420 .................... //// //// 3420 .................... //// ////
3421 .................... ///////////////////////////////////////////////////////////////////////// 3421 .................... /////////////////////////////////////////////////////////////////////////
3422 .................... //// (C) Copyright 1996,2009 Custom Computer Services //// 3422 .................... //// (C) Copyright 1996,2009 Custom Computer Services ////
3423 .................... //// This source code may only be used by licensed users of the CCS //// 3423 .................... //// This source code may only be used by licensed users of the CCS ////
3424 .................... //// C compiler. This source code may only be distributed to other //// 3424 .................... //// C compiler. This source code may only be distributed to other ////
3425 .................... //// licensed users of the CCS C compiler. No other use, //// 3425 .................... //// licensed users of the CCS C compiler. No other use, ////
3426 .................... //// reproduction or distribution is permitted without written //// 3426 .................... //// reproduction or distribution is permitted without written ////
3427 .................... //// permission. Derivative programs created using this software //// 3427 .................... //// permission. Derivative programs created using this software ////
3428 .................... //// in object code form are not restricted in any way. //// 3428 .................... //// in object code form are not restricted in any way. ////
3429 .................... ///////////////////////////////////////////////////////////////////////// 3429 .................... /////////////////////////////////////////////////////////////////////////
3430 .................... 3430 ....................
3431 .................... #IFNDEF __PIC18_USB_C__ 3431 .................... #IFNDEF __PIC18_USB_C__
3432 .................... #DEFINE __PIC18_USB_C__ 3432 .................... #DEFINE __PIC18_USB_C__
3433 .................... 3433 ....................
3434 .................... #INCLUDE <usb.h> 3434 .................... #INCLUDE <usb.h>
3435 .................... /////////////////////////////////////////////////////////////////////////// 3435 .................... ///////////////////////////////////////////////////////////////////////////
3436 .................... //// usb.h //// 3436 .................... //// usb.h ////
3437 .................... //// //// 3437 .................... //// ////
3438 .................... //// Function protypes, defintions and globals used by CCS USB driver //// 3438 .................... //// Function protypes, defintions and globals used by CCS USB driver ////
3439 .................... //// //// 3439 .................... //// ////
3440 .................... //// This file is part of CCS's USB driver code //// 3440 .................... //// This file is part of CCS's USB driver code ////
3441 .................... //// //// 3441 .................... //// ////
3442 .................... //// The following USB examples are provided by CCS: //// 3442 .................... //// The following USB examples are provided by CCS: ////
3443 .................... //// ex_usb_mouse.c - A HID Mouse. //// 3443 .................... //// ex_usb_mouse.c - A HID Mouse. ////
3444 .................... //// ex_usb_hid.c - A custom application using HID protocol. //// 3444 .................... //// ex_usb_hid.c - A custom application using HID protocol. ////
3445 .................... //// ex_usb_kbmouse.c - A HID Mouse/Keyboard combo using multiple //// 3445 .................... //// ex_usb_kbmouse.c - A HID Mouse/Keyboard combo using multiple ////
3446 .................... //// interfaces. //// 3446 .................... //// interfaces. ////
3447 .................... //// ex_usb_kbmouse2.c - A HID Mouse/Keyboard combo using multiple //// 3447 .................... //// ex_usb_kbmouse2.c - A HID Mouse/Keyboard combo using multiple ////
3448 .................... //// HID Reports. //// 3448 .................... //// HID Reports. ////
3449 .................... //// ex_usb_scope.c - A digital oscilloscope using a custom //// 3449 .................... //// ex_usb_scope.c - A digital oscilloscope using a custom ////
3450 .................... //// protocol requiring custom Windows drivers. //// 3450 .................... //// protocol requiring custom Windows drivers. ////
3451 .................... //// ex_usb_serial.c - //// 3451 .................... //// ex_usb_serial.c - ////
3452 .................... //// ex_usb_serial2.c - Two examples of using the CDC driver for //// 3452 .................... //// ex_usb_serial2.c - Two examples of using the CDC driver for ////
3453 .................... //// a virtual COM port. //// 3453 .................... //// a virtual COM port. ////
3454 .................... //// ex_usb_bootloader.c - CDC/Virtual COM port bootloader. //// 3454 .................... //// ex_usb_bootloader.c - CDC/Virtual COM port bootloader. ////
3455 .................... //// ex_usb_loadmouse.c - A conversion of ex_usb_mouse.c that is //// 3455 .................... //// ex_usb_loadmouse.c - A conversion of ex_usb_mouse.c that is ////
3456 .................... //// compatible with ex_usb_mouse.c. //// 3456 .................... //// compatible with ex_usb_mouse.c. ////
3457 .................... //// //// 3457 .................... //// ////
3458 .................... //// ********************** API ********************* //// 3458 .................... //// ********************** API ********************* ////
3459 .................... //// //// 3459 .................... //// ////
3460 .................... //// These are the functions that are meant to be called by the user: //// 3460 .................... //// These are the functions that are meant to be called by the user: ////
3461 .................... //// //// 3461 .................... //// ////
3462 .................... //// usb_init() - Initializes the USB stack, the USB peripheral and //// 3462 .................... //// usb_init() - Initializes the USB stack, the USB peripheral and ////
3463 .................... //// attaches the unit to the usb bus. Enables //// 3463 .................... //// attaches the unit to the usb bus. Enables ////
3464 .................... //// interrupts. Will wait in an infinite loop until //// 3464 .................... //// interrupts. Will wait in an infinite loop until ////
3465 .................... //// the device enumerates - if you are using //// 3465 .................... //// the device enumerates - if you are using ////
3466 .................... //// connection sense or if the processor should run //// 3466 .................... //// connection sense or if the processor should run ////
3467 .................... //// even if it's not connected to USB then use //// 3467 .................... //// even if it's not connected to USB then use ////
3468 .................... //// usb_init_cs() instead. //// 3468 .................... //// usb_init_cs() instead. ////
3469 .................... //// //// 3469 .................... //// ////
3470 .................... //// usb_init_cs() - A smaller usb_init(), does not attach unit //// 3470 .................... //// usb_init_cs() - A smaller usb_init(), does not attach unit ////
3471 .................... //// to usb bus or enable interrupts. Since this does //// 3471 .................... //// to usb bus or enable interrupts. Since this does ////
3472 .................... //// not attach to the USB, you must periodically call //// 3472 .................... //// not attach to the USB, you must periodically call ////
3473 .................... //// usb_task(). See usb_task() for more information. //// 3473 .................... //// usb_task(). See usb_task() for more information. ////
3474 .................... //// //// 3474 .................... //// ////
3475 .................... //// usb_task() - If usb_init_cs() was used to initiate the USB //// 3475 .................... //// usb_task() - If usb_init_cs() was used to initiate the USB ////
3476 .................... //// peripheral, usb_task() should then be called periodically //// 3476 .................... //// peripheral, usb_task() should then be called periodically ////
3477 .................... //// to check the connection sense pin. If the connection //// 3477 .................... //// to check the connection sense pin. If the connection ////
3478 .................... //// sense pin denotes USB is connected and the USB peripheral //// 3478 .................... //// sense pin denotes USB is connected and the USB peripheral ////
3479 .................... //// is not attached, this will attach the USB peripheral //// 3479 .................... //// is not attached, this will attach the USB peripheral ////
3480 .................... //// so the PC can start the enumeration process (and it //// 3480 .................... //// so the PC can start the enumeration process (and it ////
3481 .................... //// will enable interrupts). If the connection sense pin //// 3481 .................... //// will enable interrupts). If the connection sense pin ////
3482 .................... //// denotes USB is not attached and the USB peripheral is //// 3482 .................... //// denotes USB is not attached and the USB peripheral is ////
3483 .................... //// running, this will reset the USB peripheral and wait //// 3483 .................... //// running, this will reset the USB peripheral and wait ////
3484 .................... //// for USB to reconnect (and usb_enumerated() will start //// 3484 .................... //// for USB to reconnect (and usb_enumerated() will start ////
3485 .................... //// returning FALSE). If connection sense (USB_CON_SENSE_PIN) //// 3485 .................... //// returning FALSE). If connection sense (USB_CON_SENSE_PIN) ////
3486 .................... //// is not defined the usb_task() assumes that USB is always //// 3486 .................... //// is not defined the usb_task() assumes that USB is always ////
3487 .................... //// connected. //// 3487 .................... //// connected. ////
3488 .................... //// //// 3488 .................... //// ////
3489 .................... //// usb_attached() - Returns TRUE if the device is attached to a //// 3489 .................... //// usb_attached() - Returns TRUE if the device is attached to a ////
3490 .................... //// USB cable. A macro that looks at the defined //// 3490 .................... //// USB cable. A macro that looks at the defined ////
3491 .................... //// connection sense pin. If this returns TRUE //// 3491 .................... //// connection sense pin. If this returns TRUE ////
3492 .................... //// it does not mean the PC has connected to it, //// 3492 .................... //// it does not mean the PC has connected to it, ////
3493 .................... //// you need to use usb_enumerated() to check this. //// 3493 .................... //// you need to use usb_enumerated() to check this. ////
3494 .................... //// //// 3494 .................... //// ////
3495 .................... //// usb_enumerated() - Returns TRUE if device has been enumerated //// 3495 .................... //// usb_enumerated() - Returns TRUE if device has been enumerated ////
3496 .................... //// (configured) by host, FALSE if it has not. //// 3496 .................... //// (configured) by host, FALSE if it has not. ////
3497 .................... //// Do not try to use the USB peripheral for //// 3497 .................... //// Do not try to use the USB peripheral for ////
3498 .................... //// sending and receiving packets until you //// 3498 .................... //// sending and receiving packets until you ////
3499 .................... //// are enumerated. //// 3499 .................... //// are enumerated. ////
3500 .................... //// //// 3500 .................... //// ////
3501 .................... //// usb_wait_for_enumeration() - Sits in an infinte loop until device //// 3501 .................... //// usb_wait_for_enumeration() - Sits in an infinte loop until device ////
3502 .................... //// is enumerated. //// 3502 .................... //// is enumerated. ////
3503 .................... //// //// 3503 .................... //// ////
3504 .................... //// usb_tbe(endpoint) - Returns TRUE if the endpoint transmit buffer //// 3504 .................... //// usb_tbe(endpoint) - Returns TRUE if the endpoint transmit buffer ////
3505 .................... //// is free and ready to accept a new packet for transmission. //// 3505 .................... //// is free and ready to accept a new packet for transmission. ////
3506 .................... //// //// 3506 .................... //// ////
3507 .................... //// usb_put_packet(endpoint, ptr, len, tgl) - Sends one packet to the //// 3507 .................... //// usb_put_packet(endpoint, ptr, len, tgl) - Sends one packet to the ////
3508 .................... //// host. If you need to send a message that //// 3508 .................... //// host. If you need to send a message that ////
3509 .................... //// spans more than one packet then use //// 3509 .................... //// spans more than one packet then use ////
3510 .................... //// usb_puts(). Fore more detailed documentation //// 3510 .................... //// usb_puts(). Fore more detailed documentation ////
3511 .................... //// see usb_hw_layer.h //// 3511 .................... //// see usb_hw_layer.h ////
3512 .................... //// //// 3512 .................... //// ////
3513 .................... //// usb_puts(endpoint, ptr, len, timeout) - Sends a multiple packet //// 3513 .................... //// usb_puts(endpoint, ptr, len, timeout) - Sends a multiple packet ////
3514 .................... //// message to the host. If you only need to send one packet, //// 3514 .................... //// message to the host. If you only need to send one packet, ////
3515 .................... //// it is more effecient to use usb_put_packet(). This is //// 3515 .................... //// it is more effecient to use usb_put_packet(). This is ////
3516 .................... //// documented in more detail above the prototype in USB.H. //// 3516 .................... //// documented in more detail above the prototype in USB.H. ////
3517 .................... //// //// 3517 .................... //// ////
3518 .................... //// usb_kbhit(endpoint) - Returns true if OUT endpoint contains data //// 3518 .................... //// usb_kbhit(endpoint) - Returns true if OUT endpoint contains data ////
3519 .................... //// from host. This will remain TRUE until //// 3519 .................... //// from host. This will remain TRUE until ////
3520 .................... //// usb_put_packet() or usb_flush_out() used. //// 3520 .................... //// usb_put_packet() or usb_flush_out() used. ////
3521 .................... //// This function will return an invalid response //// 3521 .................... //// This function will return an invalid response ////
3522 .................... //// if specified endpoint is not enabled for //// 3522 .................... //// if specified endpoint is not enabled for ////
3523 .................... //// receiving data. //// 3523 .................... //// receiving data. ////
3524 .................... //// //// 3524 .................... //// ////
3525 .................... //// len = usb_get_packet(endpoint, ptr, max) - Gets one packet that //// 3525 .................... //// len = usb_get_packet(endpoint, ptr, max) - Gets one packet that ////
3526 .................... //// from the host/PC. usb_kbhit() must return TRUE before you //// 3526 .................... //// from the host/PC. usb_kbhit() must return TRUE before you ////
3527 .................... //// call this routine or your data may not be valid. This //// 3527 .................... //// call this routine or your data may not be valid. This ////
3528 .................... //// only receives one packet, if you are trying to receive a //// 3528 .................... //// only receives one packet, if you are trying to receive a ////
3529 .................... //// multi-packet message use usb_gets(). For more detailed //// 3529 .................... //// multi-packet message use usb_gets(). For more detailed ////
3530 .................... //// documentation see usb_hw_layer.h. //// 3530 .................... //// documentation see usb_hw_layer.h. ////
3531 .................... //// //// 3531 .................... //// ////
3532 .................... //// len = usb_gets(endpoint, ptr, max, timeout) - Gets multiple //// 3532 .................... //// len = usb_gets(endpoint, ptr, max, timeout) - Gets multiple ////
3533 .................... //// packets from the host, you would use this instead //// 3533 .................... //// packets from the host, you would use this instead ////
3534 .................... //// of usb_get_packet() if you wanted to handle multi-packet //// 3534 .................... //// of usb_get_packet() if you wanted to handle multi-packet ////
3535 .................... //// messages. This is documented in more detail above the //// 3535 .................... //// messages. This is documented in more detail above the ////
3536 .................... //// prototype in USB.H. //// 3536 .................... //// prototype in USB.H. ////
3537 .................... //// //// 3537 .................... //// ////
3538 .................... //// //// 3538 .................... //// ////
3539 .................... //// ********* DEFINITIONS / CONFIGURATION ********** //// 3539 .................... //// ********* DEFINITIONS / CONFIGURATION ********** ////
3540 .................... //// //// 3540 .................... //// ////
3541 .................... //// The following definitions are declared here, but can be //// 3541 .................... //// The following definitions are declared here, but can be ////
3542 .................... //// overwritten in your code. Unless needed otherwise, leave //// 3542 .................... //// overwritten in your code. Unless needed otherwise, leave ////
3543 .................... //// to default value. If confused about a definition read the //// 3543 .................... //// to default value. If confused about a definition read the ////
3544 .................... //// comments at each defintion //// 3544 .................... //// comments at each defintion ////
3545 .................... //// //// 3545 .................... //// ////
3546 .................... //// USB_HID_IDLE (TRUE) - Set to TRUE if your device supports //// 3546 .................... //// USB_HID_IDLE (TRUE) - Set to TRUE if your device supports ////
3547 .................... //// Set_Idle HID class request. Set to //// 3547 .................... //// Set_Idle HID class request. Set to ////
3548 .................... //// False if you do not (device will //// 3548 .................... //// False if you do not (device will ////
3549 .................... //// send a Wrong-state if computer //// 3549 .................... //// send a Wrong-state if computer ////
3550 .................... //// sends a Set_Idle / Get_Idle command) //// 3550 .................... //// sends a Set_Idle / Get_Idle command) ////
3551 .................... //// NOTE: If you set to TRUE you must //// 3551 .................... //// NOTE: If you set to TRUE you must ////
3552 .................... //// provide your own code. See //// 3552 .................... //// provide your own code. See ////
3553 .................... //// usb_isr_tkn_setup_ClassInterface() in //// 3553 .................... //// usb_isr_tkn_setup_ClassInterface() in ////
3554 .................... //// usb.c //// 3554 .................... //// usb.c ////
3555 .................... //// //// 3555 .................... //// ////
3556 .................... //// USB_HID_BOOT_PROTOCOL (FALSE) - Set to TRUE if your device supports //// 3556 .................... //// USB_HID_BOOT_PROTOCOL (FALSE) - Set to TRUE if your device supports ////
3557 .................... //// Set_Protocl HID class request. Set to //// 3557 .................... //// Set_Protocl HID class request. Set to ////
3558 .................... //// False if you do not (device will //// 3558 .................... //// False if you do not (device will ////
3559 .................... //// send a Wrong-state if computer //// 3559 .................... //// send a Wrong-state if computer ////
3560 .................... //// sends a Set_Protocl / Get_Protocol //// 3560 .................... //// sends a Set_Protocl / Get_Protocol ////
3561 .................... //// command). //// 3561 .................... //// command). ////
3562 .................... //// NOTE: If you set to TRUE you must //// 3562 .................... //// NOTE: If you set to TRUE you must ////
3563 .................... //// provide your own code in the //// 3563 .................... //// provide your own code in the ////
3564 .................... //// application that properly send boot //// 3564 .................... //// application that properly send boot ////
3565 .................... //// or HID packets. //// 3565 .................... //// or HID packets. ////
3566 .................... //// //// 3566 .................... //// ////
3567 .................... //// USB_MAX_EP0_PACKET_LENGTH (8) - Max Packet size for Endpoint 0. //// 3567 .................... //// USB_MAX_EP0_PACKET_LENGTH (8) - Max Packet size for Endpoint 0. ////
3568 .................... //// The hardware level driver (ex //// 3568 .................... //// The hardware level driver (ex ////
3569 .................... //// pic18_usb.h will define this value if //// 3569 .................... //// pic18_usb.h will define this value if ////
3570 .................... //// not already overwritten). Increasing //// 3570 .................... //// not already overwritten). Increasing ////
3571 .................... //// this size will speed up the //// 3571 .................... //// this size will speed up the ////
3572 .................... //// enumeration process. //// 3572 .................... //// enumeration process. ////
3573 .................... //// //// 3573 .................... //// ////
3574 .................... //// USB_EPx_RX_ENABLE (USB_ENABLE_DISABLED) - Where x is the //// 3574 .................... //// USB_EPx_RX_ENABLE (USB_ENABLE_DISABLED) - Where x is the ////
3575 .................... //// endpoint number. Change this define //// 3575 .................... //// endpoint number. Change this define ////
3576 .................... //// to specify what kind of transfer method //// 3576 .................... //// to specify what kind of transfer method ////
3577 .................... //// this RX (PC to device) endpoint uses. //// 3577 .................... //// this RX (PC to device) endpoint uses. ////
3578 .................... //// Here is the list of valid transfer methods: //// 3578 .................... //// Here is the list of valid transfer methods: ////
3579 .................... //// USB_ENABLE_CONTROL //// 3579 .................... //// USB_ENABLE_CONTROL ////
3580 .................... //// USB_ENABLE_ISOCHRONOUS //// 3580 .................... //// USB_ENABLE_ISOCHRONOUS ////
3581 .................... //// USB_ENABLE_BULK //// 3581 .................... //// USB_ENABLE_BULK ////
3582 .................... //// USB_ENABLE_INTERRUPT //// 3582 .................... //// USB_ENABLE_INTERRUPT ////
3583 .................... //// USB_ENABLE_DISABLED //// 3583 .................... //// USB_ENABLE_DISABLED ////
3584 .................... //// Don't forget that you must specify the //// 3584 .................... //// Don't forget that you must specify the ////
3585 .................... //// transfer method properly in your endpoint //// 3585 .................... //// transfer method properly in your endpoint ////
3586 .................... //// descriptor, too. //// 3586 .................... //// descriptor, too. ////
3587 .................... //// //// 3587 .................... //// ////
3588 .................... //// USB_EPx_RX_SIZE (0) - For some hardware it is important to know //// 3588 .................... //// USB_EPx_RX_SIZE (0) - For some hardware it is important to know ////
3589 .................... //// how much memory to reserve for receiving //// 3589 .................... //// how much memory to reserve for receiving ////
3590 .................... //// packets. //// 3590 .................... //// packets. ////
3591 .................... //// //// 3591 .................... //// ////
3592 .................... //// *** NOTE *** You must have both USB_EPx_RX_ENABLE defined and //// 3592 .................... //// *** NOTE *** You must have both USB_EPx_RX_ENABLE defined and ////
3593 .................... //// USB_EPx_RX_SIZE defined (non 0) to enable a RX //// 3593 .................... //// USB_EPx_RX_SIZE defined (non 0) to enable a RX ////
3594 .................... //// endpoint. //// 3594 .................... //// endpoint. ////
3595 .................... //// *** NOTE *** Endpoint 0 is always enabled. //// 3595 .................... //// *** NOTE *** Endpoint 0 is always enabled. ////
3596 .................... //// //// 3596 .................... //// ////
3597 .................... //// USB_EPx_TX_ENABLE (USB_ENABLE_DISABLED) - Where x is the //// 3597 .................... //// USB_EPx_TX_ENABLE (USB_ENABLE_DISABLED) - Where x is the ////
3598 .................... //// endpoint number. Change this define //// 3598 .................... //// endpoint number. Change this define ////
3599 .................... //// to specify what kind of transfer method //// 3599 .................... //// to specify what kind of transfer method ////
3600 .................... //// this TX (device to PC) endpoint uses. //// 3600 .................... //// this TX (device to PC) endpoint uses. ////
3601 .................... //// Here is the list of valid transfer methods: //// 3601 .................... //// Here is the list of valid transfer methods: ////
3602 .................... //// USB_ENABLE_CONTROL //// 3602 .................... //// USB_ENABLE_CONTROL ////
3603 .................... //// USB_ENABLE_ISOCHRONOUS //// 3603 .................... //// USB_ENABLE_ISOCHRONOUS ////
3604 .................... //// USB_ENABLE_BULK //// 3604 .................... //// USB_ENABLE_BULK ////
3605 .................... //// USB_ENABLE_INTERRUPT //// 3605 .................... //// USB_ENABLE_INTERRUPT ////
3606 .................... //// USB_ENABLE_DISABLED //// 3606 .................... //// USB_ENABLE_DISABLED ////
3607 .................... //// Don't forget that you must specify the //// 3607 .................... //// Don't forget that you must specify the ////
3608 .................... //// transfer method properly in your endpoint //// 3608 .................... //// transfer method properly in your endpoint ////
3609 .................... //// descriptor, too. //// 3609 .................... //// descriptor, too. ////
3610 .................... //// //// 3610 .................... //// ////
3611 .................... //// USB_EPx_TX_SIZE (0) - For some hardware it is important to know //// 3611 .................... //// USB_EPx_TX_SIZE (0) - For some hardware it is important to know ////
3612 .................... //// how much memory to reserve for transmitting //// 3612 .................... //// how much memory to reserve for transmitting ////
3613 .................... //// packets. //// 3613 .................... //// packets. ////
3614 .................... //// //// 3614 .................... //// ////
3615 .................... //// *** NOTE *** You must have both USB_EPx_TX_ENABLE defined and //// 3615 .................... //// *** NOTE *** You must have both USB_EPx_TX_ENABLE defined and ////
3616 .................... //// USB_EPx_TX_SIZE defined (non 0) to enable a TX //// 3616 .................... //// USB_EPx_TX_SIZE defined (non 0) to enable a TX ////
3617 .................... //// endpoint. //// 3617 .................... //// endpoint. ////
3618 .................... //// //// 3618 .................... //// ////
3619 .................... //// //// 3619 .................... //// ////
3620 .................... //// USB_HID_DEVICE (TRUE) - HID devices require extra code to handle //// 3620 .................... //// USB_HID_DEVICE (TRUE) - HID devices require extra code to handle ////
3621 .................... //// HID requests. You can disable to save //// 3621 .................... //// HID requests. You can disable to save ////
3622 .................... //// ROM space if you are not using a HID //// 3622 .................... //// ROM space if you are not using a HID ////
3623 .................... //// device. If you are not using a HID //// 3623 .................... //// device. If you are not using a HID ////
3624 .................... //// device you must provide your own O/S //// 3624 .................... //// device you must provide your own O/S ////
3625 .................... //// (Windows) driver. //// 3625 .................... //// (Windows) driver. ////
3626 .................... //// //// 3626 .................... //// ////
3627 .................... //// The other definitions should not be changed. //// 3627 .................... //// The other definitions should not be changed. ////
3628 .................... //// //// 3628 .................... //// ////
3629 .................... /////////////////////////////////////////////////////////////////////////// 3629 .................... ///////////////////////////////////////////////////////////////////////////
3630 .................... //// //// 3630 .................... //// ////
3631 .................... //// Version History: //// 3631 .................... //// Version History: ////
3632 .................... //// //// 3632 .................... //// ////
3633 .................... //// March 5th, 2009: //// 3633 .................... //// March 5th, 2009: ////
3634 .................... //// Cleanup for Wizard. //// 3634 .................... //// Cleanup for Wizard. ////
3635 .................... //// PIC24 Initial release. //// 3635 .................... //// PIC24 Initial release. ////
3636 .................... //// //// 3636 .................... //// ////
3637 .................... //// July 13th, 2005: //// 3637 .................... //// July 13th, 2005: ////
3638 .................... //// usb_ep_tx_size[] and usb_ep_rx_size[] changed to 16bits //// 3638 .................... //// usb_ep_tx_size[] and usb_ep_rx_size[] changed to 16bits ////
3639 .................... //// //// 3639 .................... //// ////
3640 .................... //// June 20th, 2005: //// 3640 .................... //// June 20th, 2005: ////
3641 .................... //// Initial 18fxx5x release //// 3641 .................... //// Initial 18fxx5x release ////
3642 .................... //// //// 3642 .................... //// ////
3643 .................... //// May 13th, 2005: //// 3643 .................... //// May 13th, 2005: ////
3644 .................... //// Beta release, only works with 18Fxx5x hardware layer. //// 3644 .................... //// Beta release, only works with 18Fxx5x hardware layer. ////
3645 .................... //// Now supports multiple interfaces (many defines in descriptors //// 3645 .................... //// Now supports multiple interfaces (many defines in descriptors ////
3646 .................... //// will have to be changed, see examples) //// 3646 .................... //// will have to be changed, see examples) ////
3647 .................... //// //// 3647 .................... //// ////
3648 .................... //// Mar 21st, 2005: //// 3648 .................... //// Mar 21st, 2005: ////
3649 .................... //// Initial Alpha Release with PIC18Fxx5x support. (ONLY TESTED //// 3649 .................... //// Initial Alpha Release with PIC18Fxx5x support. (ONLY TESTED ////
3650 .................... //// WITH 18F4550) //// 3650 .................... //// WITH 18F4550) ////
3651 .................... //// usb_gets() and usb_puts() changed (see usb.c) //// 3651 .................... //// usb_gets() and usb_puts() changed (see usb.c) ////
3652 .................... //// //// 3652 .................... //// ////
3653 .................... //// June 24th, 2004: //// 3653 .................... //// June 24th, 2004: ////
3654 .................... //// Optimization and cleanup. //// 3654 .................... //// Optimization and cleanup. ////
3655 .................... //// The following definitions changed: //// 3655 .................... //// The following definitions changed: ////
3656 .................... //// USB_EPx_TX_ENABLE and USB_EPx_RX_ENABLE have changed. See usb.h //// 3656 .................... //// USB_EPx_TX_ENABLE and USB_EPx_RX_ENABLE have changed. See usb.h ////
3657 .................... //// USB_CONFIG_DESCRIPTORS[] removed //// 3657 .................... //// USB_CONFIG_DESCRIPTORS[] removed ////
3658 .................... //// USB_CONFIG_DESC_LEN changed to USB_DESC_CONFIG_LEN //// 3658 .................... //// USB_CONFIG_DESC_LEN changed to USB_DESC_CONFIG_LEN ////
3659 .................... //// USB_INTERFACE_DESC_LEN changed to USB_DESC_INTERFACE_LEN //// 3659 .................... //// USB_INTERFACE_DESC_LEN changed to USB_DESC_INTERFACE_LEN ////
3660 .................... //// USB_CLASS_DESC_LEN changed to USB_DESC_CLASS_LEN //// 3660 .................... //// USB_CLASS_DESC_LEN changed to USB_DESC_CLASS_LEN ////
3661 .................... //// USB_ENDPOINT_DESC_LEN changed to USB_DESC_ENDPOINT_LEN //// 3661 .................... //// USB_ENDPOINT_DESC_LEN changed to USB_DESC_ENDPOINT_LEN ////
3662 .................... //// USB_CONFIG_DESC_KEY changed to USB_DESC_CONFIG_TYPE //// 3662 .................... //// USB_CONFIG_DESC_KEY changed to USB_DESC_CONFIG_TYPE ////
3663 .................... //// USB_INTERFACE_DESC_KEY changed to USB_DESC_INTERFACE_TYPE //// 3663 .................... //// USB_INTERFACE_DESC_KEY changed to USB_DESC_INTERFACE_TYPE ////
3664 .................... //// USB_CLASS_DESC_KEY changed to USB_DESC_CLASS_TYPE //// 3664 .................... //// USB_CLASS_DESC_KEY changed to USB_DESC_CLASS_TYPE ////
3665 .................... //// USB_ENDPOINT_DESC_KEY changed to USB_DESC_ENDPOINT_TYPE //// 3665 .................... //// USB_ENDPOINT_DESC_KEY changed to USB_DESC_ENDPOINT_TYPE ////
3666 .................... //// USB_STRING_X[] arrays removed, see USB_STRING_DESC[] and //// 3666 .................... //// USB_STRING_X[] arrays removed, see USB_STRING_DESC[] and ////
3667 .................... //// USB_STRING_DESC_OFFSET[] //// 3667 .................... //// USB_STRING_DESC_OFFSET[] ////
3668 .................... //// dev_req, curr_config, status_device and getdesc_type global //// 3668 .................... //// dev_req, curr_config, status_device and getdesc_type global ////
3669 .................... //// variables moved into struct USB_stack_status //// 3669 .................... //// variables moved into struct USB_stack_status ////
3670 .................... //// //// 3670 .................... //// ////
3671 .................... //// October 15th, 2003: Support for boot protocol added. //// 3671 .................... //// October 15th, 2003: Support for boot protocol added. ////
3672 .................... //// Set USB_HID_BOOT_PROTOCOL to TRUE to support this. //// 3672 .................... //// Set USB_HID_BOOT_PROTOCOL to TRUE to support this. ////
3673 .................... //// The array hid_protocol[] saves which protocol mode each //// 3673 .................... //// The array hid_protocol[] saves which protocol mode each ////
3674 .................... //// interface is in. It is your applications job to send //// 3674 .................... //// interface is in. It is your applications job to send ////
3675 .................... //// data that either fit the boot protocol or HID protocol. //// 3675 .................... //// data that either fit the boot protocol or HID protocol. ////
3676 .................... //// //// 3676 .................... //// ////
3677 .................... //// May 6th, 2003: Fixed a potential stack overflow using PCM //// 3677 .................... //// May 6th, 2003: Fixed a potential stack overflow using PCM ////
3678 .................... //// //// 3678 .................... //// ////
3679 .................... //// October 29th, 2002: New definition added to USB_STATES //// 3679 .................... //// October 29th, 2002: New definition added to USB_STATES ////
3680 .................... //// //// 3680 .................... //// ////
3681 .................... //// August 2nd, 2002: Initial Public Release //// 3681 .................... //// August 2nd, 2002: Initial Public Release ////
3682 .................... //// //// 3682 .................... //// ////
3683 .................... /////////////////////////////////////////////////////////////////////////// 3683 .................... ///////////////////////////////////////////////////////////////////////////
3684 .................... //// (C) Copyright 1996,2009 Custom Computer Services //// 3684 .................... //// (C) Copyright 1996,2009 Custom Computer Services ////
3685 .................... //// This source code may only be used by licensed users of the CCS //// 3685 .................... //// This source code may only be used by licensed users of the CCS ////
3686 .................... //// C compiler. This source code may only be distributed to other //// 3686 .................... //// C compiler. This source code may only be distributed to other ////
3687 .................... //// licensed users of the CCS C compiler. No other use, //// 3687 .................... //// licensed users of the CCS C compiler. No other use, ////
3688 .................... //// reproduction or distribution is permitted without written //// 3688 .................... //// reproduction or distribution is permitted without written ////
3689 .................... //// permission. Derivative programs created using this software //// 3689 .................... //// permission. Derivative programs created using this software ////
3690 .................... //// in object code form are not restricted in any way. //// 3690 .................... //// in object code form are not restricted in any way. ////
3691 .................... /////////////////////////////////////////////////////////////////////////// 3691 .................... ///////////////////////////////////////////////////////////////////////////
3692 .................... 3692 ....................
3693 .................... #IFNDEF __USB_PROTOTYPES__ 3693 .................... #IFNDEF __USB_PROTOTYPES__
3694 .................... #DEFINE __USB_PROTOTYPES__ 3694 .................... #DEFINE __USB_PROTOTYPES__
3695 .................... 3695 ....................
3696 .................... //// CONFIGURATION //////////////////////////////////////////////////////////// 3696 .................... //// CONFIGURATION ////////////////////////////////////////////////////////////
3697 .................... 3697 ....................
3698 .................... #ifndef USB_CON_SENSE_PIN 3698 .................... #ifndef USB_CON_SENSE_PIN
3699 .................... #define USB_CON_SENSE_PIN 0 3699 .................... #define USB_CON_SENSE_PIN 0
3700 .................... #endif 3700 .................... #endif
3701 .................... 3701 ....................
3702 .................... #IFNDEF USB_HID_BOOT_PROTOCOL 3702 .................... #IFNDEF USB_HID_BOOT_PROTOCOL
3703 .................... #DEFINE USB_HID_BOOT_PROTOCOL FALSE 3703 .................... #DEFINE USB_HID_BOOT_PROTOCOL FALSE
3704 .................... #ENDIF 3704 .................... #ENDIF
3705 .................... 3705 ....................
3706 .................... #IFNDEF USB_HID_IDLE 3706 .................... #IFNDEF USB_HID_IDLE
3707 .................... #DEFINE USB_HID_IDLE FALSE 3707 .................... #DEFINE USB_HID_IDLE FALSE
3708 .................... #ENDIF 3708 .................... #ENDIF
3709 .................... 3709 ....................
3710 .................... //should the compiler add the extra HID handler code? Defaults to yes. 3710 .................... //should the compiler add the extra HID handler code? Defaults to yes.
3711 .................... #IFNDEF USB_HID_DEVICE 3711 .................... #IFNDEF USB_HID_DEVICE
3712 .................... #DEFINE USB_HID_DEVICE TRUE 3712 .................... #DEFINE USB_HID_DEVICE TRUE
3713 .................... #ENDIF 3713 .................... #ENDIF
3714 .................... 3714 ....................
3715 .................... #IFNDEF USB_CDC_DEVICE 3715 .................... #IFNDEF USB_CDC_DEVICE
3716 .................... #DEFINE USB_CDC_DEVICE FALSE 3716 .................... #DEFINE USB_CDC_DEVICE FALSE
3717 .................... #ENDIF 3717 .................... #ENDIF
3718 .................... 3718 ....................
3719 .................... //set to false to opt for less RAM, true to opt for less ROM 3719 .................... //set to false to opt for less RAM, true to opt for less ROM
3720 .................... #ifndef USB_OPT_FOR_ROM 3720 .................... #ifndef USB_OPT_FOR_ROM
3721 .................... #define USB_OPT_FOR_ROM TRUE 3721 .................... #define USB_OPT_FOR_ROM TRUE
3722 .................... #endif 3722 .................... #endif
3723 .................... 3723 ....................
3724 .................... #IFNDEF USB_MAX_EP0_PACKET_LENGTH 3724 .................... #IFNDEF USB_MAX_EP0_PACKET_LENGTH
3725 .................... #DEFINE USB_MAX_EP0_PACKET_LENGTH 8 3725 .................... #DEFINE USB_MAX_EP0_PACKET_LENGTH 8
3726 .................... #ENDIF 3726 .................... #ENDIF
3727 .................... 3727 ....................
3728 .................... 3728 ....................
3729 .................... ////// USER-LEVEL API ///////////////////////////////////////////////////////// 3729 .................... ////// USER-LEVEL API /////////////////////////////////////////////////////////
3730 .................... 3730 ....................
3731 .................... /************************************************************** 3731 .................... /**************************************************************
3732 .................... /* usb_enumerated() 3732 .................... /* usb_enumerated()
3733 .................... /* 3733 .................... /*
3734 .................... /* Input: Global variable USB_Curr_Config 3734 .................... /* Input: Global variable USB_Curr_Config
3735 .................... /* Returns: Returns a 1 if device is configured / enumerated, 3735 .................... /* Returns: Returns a 1 if device is configured / enumerated,
3736 .................... /* Returns a 0 if device is un-configured / not enumerated. 3736 .................... /* Returns a 0 if device is un-configured / not enumerated.
3737 .................... /* 3737 .................... /*
3738 .................... /* Summary: See API section of USB.H for more documentation. 3738 .................... /* Summary: See API section of USB.H for more documentation.
3739 .................... /***************************************************************/ 3739 .................... /***************************************************************/
3740 .................... int1 usb_enumerated(void); 3740 .................... int1 usb_enumerated(void);
3741 .................... 3741 ....................
3742 .................... /************************************************************** 3742 .................... /**************************************************************
3743 .................... /* usb_wait_for_enumeration() 3743 .................... /* usb_wait_for_enumeration()
3744 .................... /* 3744 .................... /*
3745 .................... /* Input: Global variable USB_Curr_Config 3745 .................... /* Input: Global variable USB_Curr_Config
3746 .................... /* 3746 .................... /*
3747 .................... /* Summary: Waits in-definately until device is configured / enumerated. 3747 .................... /* Summary: Waits in-definately until device is configured / enumerated.
3748 .................... /* See API section of USB.H for more information. 3748 .................... /* See API section of USB.H for more information.
3749 .................... /***************************************************************/ 3749 .................... /***************************************************************/
3750 .................... void usb_wait_for_enumeration(void); 3750 .................... void usb_wait_for_enumeration(void);
3751 .................... 3751 ....................
3752 .................... /**************************************************************************** 3752 .................... /****************************************************************************
3753 .................... /* usb_gets(endpoint, ptr, max, timeout) 3753 .................... /* usb_gets(endpoint, ptr, max, timeout)
3754 .................... /* 3754 .................... /*
3755 .................... /* Input: endpoint - endpoint to get data from 3755 .................... /* Input: endpoint - endpoint to get data from
3756 .................... /* ptr - place / array to store data to 3756 .................... /* ptr - place / array to store data to
3757 .................... /* max - max amount of data to get from USB and store into ptr 3757 .................... /* max - max amount of data to get from USB and store into ptr
3758 .................... /* timeout - time in milliseconds, for each packet, to wait before 3758 .................... /* timeout - time in milliseconds, for each packet, to wait before
3759 .................... /* timeout. set to 0 for no timeout. 3759 .................... /* timeout. set to 0 for no timeout.
3760 .................... /* 3760 .................... /*
3761 .................... /* Output: Amount of data returned. It may be less than max. 3761 .................... /* Output: Amount of data returned. It may be less than max.
3762 .................... /* 3762 .................... /*
3763 .................... /* Summary: Gets data from the host. Will get multiple-packet messages 3763 .................... /* Summary: Gets data from the host. Will get multiple-packet messages
3764 .................... /* and finish when either it receives a 0-len packet or a packet 3764 .................... /* and finish when either it receives a 0-len packet or a packet
3765 .................... /* of less size than maximum. 3765 .................... /* of less size than maximum.
3766 .................... /* 3766 .................... /*
3767 .................... /*****************************************************************************/ 3767 .................... /*****************************************************************************/
3768 .................... unsigned int16 usb_gets(int8 endpoint, int8 * ptr, unsigned int16 max, unsigned int16 timeout); 3768 .................... unsigned int16 usb_gets(int8 endpoint, int8 * ptr, unsigned int16 max, unsigned int16 timeout);
3769 .................... 3769 ....................
3770 .................... /**************************************************************************** 3770 .................... /****************************************************************************
3771 .................... /* usb_puts() 3771 .................... /* usb_puts()
3772 .................... /* 3772 .................... /*
3773 .................... /* Inputs: endpoint - endpoint to send data out 3773 .................... /* Inputs: endpoint - endpoint to send data out
3774 .................... /* ptr - points to array of data to send 3774 .................... /* ptr - points to array of data to send
3775 .................... /* len - amount of data to send 3775 .................... /* len - amount of data to send
3776 .................... /* timeout - time in milli-seconds, for each packet, to wait before 3776 .................... /* timeout - time in milli-seconds, for each packet, to wait before
3777 .................... /* timeout. set to 0 for no timeout. 3777 .................... /* timeout. set to 0 for no timeout.
3778 .................... /* 3778 .................... /*
3779 .................... /* Outputs: Returns TRUE if message sent succesfully, FALSE if it was not 3779 .................... /* Outputs: Returns TRUE if message sent succesfully, FALSE if it was not
3780 .................... /* sent before timeout period expired. 3780 .................... /* sent before timeout period expired.
3781 .................... /* 3781 .................... /*
3782 .................... /* Summary: Used for sending multiple packets of data as one message. This 3782 .................... /* Summary: Used for sending multiple packets of data as one message. This
3783 .................... /* function can still be used to send messages consiting of only one 3783 .................... /* function can still be used to send messages consiting of only one
3784 .................... /* packet. See usb_put_packet() documentation for the rules about when 3784 .................... /* packet. See usb_put_packet() documentation for the rules about when
3785 .................... /* multiple packet messages or 0-lenght packets are needed. 3785 .................... /* multiple packet messages or 0-lenght packets are needed.
3786 .................... /* 3786 .................... /*
3787 .................... /*****************************************************************************/ 3787 .................... /*****************************************************************************/
3788 .................... int1 usb_puts(int8 endpoint, int8 * ptr, unsigned int16 len, unsigned int8 timeout); 3788 .................... int1 usb_puts(int8 endpoint, int8 * ptr, unsigned int16 len, unsigned int8 timeout);
3789 .................... 3789 ....................
3790 .................... /****************************************************************************** 3790 .................... /******************************************************************************
3791 .................... /* usb_attached() 3791 .................... /* usb_attached()
3792 .................... /* 3792 .................... /*
3793 .................... /* Summary: Returns TRUE if the device is attached to a USB cable. 3793 .................... /* Summary: Returns TRUE if the device is attached to a USB cable.
3794 .................... /* See the API section of USB.H for more documentation. 3794 .................... /* See the API section of USB.H for more documentation.
3795 .................... /* 3795 .................... /*
3796 .................... /*****************************************************************************/ 3796 .................... /*****************************************************************************/
3797 .................... #if USB_CON_SENSE_PIN 3797 .................... #if USB_CON_SENSE_PIN
3798 .................... #define usb_attached() input(USB_CON_SENSE_PIN) 3798 .................... #define usb_attached() input(USB_CON_SENSE_PIN)
3799 .................... #else 3799 .................... #else
3800 .................... #define usb_attached() TRUE 3800 .................... #define usb_attached() TRUE
3801 .................... #endif 3801 .................... #endif
3802 .................... 3802 ....................
3803 .................... ////// END USER-LEVEL API ///////////////////////////////////////////////////// 3803 .................... ////// END USER-LEVEL API /////////////////////////////////////////////////////
3804 .................... 3804 ....................
3805 .................... 3805 ....................
3806 .................... ////// STACK-LEVEL API USED BY HW DRIVERS //////////////////////////////////// 3806 .................... ////// STACK-LEVEL API USED BY HW DRIVERS ////////////////////////////////////
3807 .................... 3807 ....................
3808 .................... enum USB_STATES {GET_DESCRIPTOR=1,SET_ADDRESS=2,NONE=0}; 3808 .................... enum USB_STATES {GET_DESCRIPTOR=1,SET_ADDRESS=2,NONE=0};
3809 .................... 3809 ....................
3810 .................... enum USB_GETDESC_TYPES {USB_GETDESC_CONFIG_TYPE=0,USB_GETDESC_HIDREPORT_TYPE=1,USB_GETDESC_STRING_TYPE=2,USB_GETDESC_DEVICE_TYPE=3}; 3810 .................... enum USB_GETDESC_TYPES {USB_GETDESC_CONFIG_TYPE=0,USB_GETDESC_HIDREPORT_TYPE=1,USB_GETDESC_STRING_TYPE=2,USB_GETDESC_DEVICE_TYPE=3};
3811 .................... 3811 ....................
3812 .................... #if USB_OPT_FOR_ROM 3812 .................... #if USB_OPT_FOR_ROM
3813 .................... typedef struct { 3813 .................... typedef struct {
3814 .................... USB_STATES dev_req; //what did the last setup token set us up to do?. init at none 3814 .................... USB_STATES dev_req; //what did the last setup token set us up to do?. init at none
3815 .................... int curr_config; //our current config. start at none/powered (NOT THAT THIS LIMITS US TO 3 CONFIGURATIONS) 3815 .................... int curr_config; //our current config. start at none/powered (NOT THAT THIS LIMITS US TO 3 CONFIGURATIONS)
3816 .................... int status_device; //Holds our state for Set_Feature and Clear_Feature 3816 .................... int status_device; //Holds our state for Set_Feature and Clear_Feature
3817 .................... USB_GETDESC_TYPES getdesc_type; //which get_descriptor() we are handling 3817 .................... USB_GETDESC_TYPES getdesc_type; //which get_descriptor() we are handling
3818 .................... } TYPE_USB_STACK_STATUS; 3818 .................... } TYPE_USB_STACK_STATUS;
3819 .................... #else 3819 .................... #else
3820 .................... typedef struct { 3820 .................... typedef struct {
3821 .................... USB_STATES dev_req:2; //what did the last setup token set us up to do?. init at none 3821 .................... USB_STATES dev_req:2; //what did the last setup token set us up to do?. init at none
3822 .................... int Curr_config:2; //our current config. start at none/powered (NOT THAT THIS LIMITS US TO 3 CONFIGURATIONS) 3822 .................... int Curr_config:2; //our current config. start at none/powered (NOT THAT THIS LIMITS US TO 3 CONFIGURATIONS)
3823 .................... int status_device:2; //Holds our state for Set_Feature and Clear_Feature 3823 .................... int status_device:2; //Holds our state for Set_Feature and Clear_Feature
3824 .................... USB_GETDESC_TYPES getdesc_type:2; //which get_descriptor() we are handling 3824 .................... USB_GETDESC_TYPES getdesc_type:2; //which get_descriptor() we are handling
3825 .................... } TYPE_USB_STACK_STATUS; 3825 .................... } TYPE_USB_STACK_STATUS;
3826 .................... #endif 3826 .................... #endif
3827 .................... 3827 ....................
3828 .................... extern TYPE_USB_STACK_STATUS USB_stack_status; 3828 .................... extern TYPE_USB_STACK_STATUS USB_stack_status;
3829 .................... 3829 ....................
3830 .................... /************************************************************** 3830 .................... /**************************************************************
3831 .................... /* usb_token_reset() 3831 .................... /* usb_token_reset()
3832 .................... /* 3832 .................... /*
3833 .................... /* Output: No output (but many global registers are modified) 3833 .................... /* Output: No output (but many global registers are modified)
3834 .................... /* 3834 .................... /*
3835 .................... /* Summary: Resets the token handler to initial (unconfigured) state. 3835 .................... /* Summary: Resets the token handler to initial (unconfigured) state.
3836 .................... /***************************************************************/ 3836 .................... /***************************************************************/
3837 .................... void usb_token_reset(void); 3837 .................... void usb_token_reset(void);
3838 .................... 3838 ....................
3839 .................... /************************************************************** 3839 .................... /**************************************************************
3840 .................... /* usb_isr_tok_setup_dne() 3840 .................... /* usb_isr_tok_setup_dne()
3841 .................... /* 3841 .................... /*
3842 .................... /* Input: usb_ep0_rx_buffer[] contains the the setup packet. 3842 .................... /* Input: usb_ep0_rx_buffer[] contains the the setup packet.
3843 .................... /* 3843 .................... /*
3844 .................... /* Output: None (many globals are changed) 3844 .................... /* Output: None (many globals are changed)
3845 .................... /* 3845 .................... /*
3846 .................... /* Summary: This function is that handles the setup token. 3846 .................... /* Summary: This function is that handles the setup token.
3847 .................... /* We must handle all relevant requests, such as Set_Configuration, 3847 .................... /* We must handle all relevant requests, such as Set_Configuration,
3848 .................... /* Get_Descriptor, etc. 3848 .................... /* Get_Descriptor, etc.
3849 .................... /* 3849 .................... /*
3850 .................... /* usb_ep0_rx_buffer[] contains setup data packet, which has the 3850 .................... /* usb_ep0_rx_buffer[] contains setup data packet, which has the
3851 .................... /* following records: 3851 .................... /* following records:
3852 .................... /* ------------------------------------------------------------------------------------------- 3852 .................... /* -------------------------------------------------------------------------------------------
3853 .................... /* usb_ep0_rx_buffer[ 0 ]=bmRequestType; Where the setup packet goes 3853 .................... /* usb_ep0_rx_buffer[ 0 ]=bmRequestType; Where the setup packet goes
3854 .................... /* bit7 (0) host-to-device 3854 .................... /* bit7 (0) host-to-device
3855 .................... /* (1) device-to-host 3855 .................... /* (1) device-to-host
3856 .................... /* bit6-5 (00) usb standard request; 3856 .................... /* bit6-5 (00) usb standard request;
3857 .................... /* (01) class request; 3857 .................... /* (01) class request;
3858 .................... /* (10) vendor request 3858 .................... /* (10) vendor request
3859 .................... /* (11) reserved 3859 .................... /* (11) reserved
3860 .................... /* bit4-0 (0000) device 3860 .................... /* bit4-0 (0000) device
3861 .................... /* (0001) interface 3861 .................... /* (0001) interface
3862 .................... /* (0010) endpoint 3862 .................... /* (0010) endpoint
3863 .................... /* (0011) other element 3863 .................... /* (0011) other element
3864 .................... /* (0100) to (1111) reserved 3864 .................... /* (0100) to (1111) reserved
3865 .................... /* usb_ep0_rx_buffer[ 1 ]=bRequest ; the request 3865 .................... /* usb_ep0_rx_buffer[ 1 ]=bRequest ; the request
3866 .................... /* usb_ep0_rx_buffer[2,3]=wValue ; a value which corresponds to request 3866 .................... /* usb_ep0_rx_buffer[2,3]=wValue ; a value which corresponds to request
3867 .................... /* usb_ep0_rx_buffer[4,5]=wIndex ; could correspond to interface or endpoint... 3867 .................... /* usb_ep0_rx_buffer[4,5]=wIndex ; could correspond to interface or endpoint...
3868 .................... /* usb_ep0_rx_buffer[6,7]=wLength ; number of bytes in next data packet; 3868 .................... /* usb_ep0_rx_buffer[6,7]=wLength ; number of bytes in next data packet;
3869 .................... /* for host-to-device, this exactly how many bytes in data packet. 3869 .................... /* for host-to-device, this exactly how many bytes in data packet.
3870 .................... /* for device-to-host, this is the maximum bytes that can fit one packet. 3870 .................... /* for device-to-host, this is the maximum bytes that can fit one packet.
3871 .................... /***************************************************************/ 3871 .................... /***************************************************************/
3872 .................... void usb_isr_tok_setup_dne(void); 3872 .................... void usb_isr_tok_setup_dne(void);
3873 .................... 3873 ....................
3874 .................... /************************************************************** 3874 .................... /**************************************************************
3875 .................... /* usb_isr_tok_out_dne() 3875 .................... /* usb_isr_tok_out_dne()
3876 .................... /* 3876 .................... /*
3877 .................... /* Input: endpoint contains which endpoint we are receiving data (0..15) 3877 .................... /* Input: endpoint contains which endpoint we are receiving data (0..15)
3878 .................... /* 3878 .................... /*
3879 .................... /* Summary: Processes out tokens (out is respective of the host, so actualy 3879 .................... /* Summary: Processes out tokens (out is respective of the host, so actualy
3880 .................... /* incoming to the pic), but not out setup tokens. Normally when 3880 .................... /* incoming to the pic), but not out setup tokens. Normally when
3881 .................... /* data is received it is left in the buffer (user would use 3881 .................... /* data is received it is left in the buffer (user would use
3882 .................... /* usb_kbhit() and usb_get_packet() to receive data), but certain 3882 .................... /* usb_kbhit() and usb_get_packet() to receive data), but certain
3883 .................... /* libraries (like CDC) have to answer setup packets. 3883 .................... /* libraries (like CDC) have to answer setup packets.
3884 .................... /* 3884 .................... /*
3885 .................... /***************************************************************/ 3885 .................... /***************************************************************/
3886 .................... void usb_isr_tok_out_dne(int8 endpoint); 3886 .................... void usb_isr_tok_out_dne(int8 endpoint);
3887 .................... 3887 ....................
3888 .................... /************************************************************** 3888 .................... /**************************************************************
3889 .................... /* usb_isr_tok_in_dne(endpoint) 3889 .................... /* usb_isr_tok_in_dne(endpoint)
3890 .................... /* 3890 .................... /*
3891 .................... /* Input: endpoint - which endpoint we are processing a setup token. 3891 .................... /* Input: endpoint - which endpoint we are processing a setup token.
3892 .................... /* 3892 .................... /*
3893 .................... /* Summary: This handles an IN packet (HOST <- PIC). For endpoint 0, this 3893 .................... /* Summary: This handles an IN packet (HOST <- PIC). For endpoint 0, this
3894 .................... /* is usually to setup a response packet to a setup packet. Endpoints 1..15 3894 .................... /* is usually to setup a response packet to a setup packet. Endpoints 1..15
3895 .................... /* are generally ignored, and the user has to use usb_tbe() to determine if 3895 .................... /* are generally ignored, and the user has to use usb_tbe() to determine if
3896 .................... /* if the buffer is ready for a new transmit packet (there are special cases, 3896 .................... /* if the buffer is ready for a new transmit packet (there are special cases,
3897 .................... /* like CDC which handles the CDC protocl). 3897 .................... /* like CDC which handles the CDC protocl).
3898 .................... /* 3898 .................... /*
3899 .................... /***************************************************************/ 3899 .................... /***************************************************************/
3900 .................... void usb_isr_tok_in_dne(int8 endpoint); 3900 .................... void usb_isr_tok_in_dne(int8 endpoint);
3901 .................... 3901 ....................
3902 .................... ////// END STACK-LEVEL API USED BY HW DRIVERS ///////////////////////////////// 3902 .................... ////// END STACK-LEVEL API USED BY HW DRIVERS /////////////////////////////////
3903 .................... 3903 ....................
3904 .................... 3904 ....................
3905 .................... //CCS only supports one configuration at this time 3905 .................... //CCS only supports one configuration at this time
3906 .................... #DEFINE USB_NUM_CONFIGURATIONS 1 //DO NOT CHANGE 3906 .................... #DEFINE USB_NUM_CONFIGURATIONS 1 //DO NOT CHANGE
3907 .................... 3907 ....................
3908 .................... //PID values for tokens (see page 48 of USB Complete ed.1) 3908 .................... //PID values for tokens (see page 48 of USB Complete ed.1)
3909 .................... #define PID_IN 0x09 //device to host transactions 3909 .................... #define PID_IN 0x09 //device to host transactions
3910 .................... #define PID_OUT 0x01 //host to device transactions 3910 .................... #define PID_OUT 0x01 //host to device transactions
3911 .................... #define PID_SETUP 0x0D //host to device setup transaction 3911 .................... #define PID_SETUP 0x0D //host to device setup transaction
3912 .................... #define PID_ACK 0x02 //receiver accepts error-free data packet 3912 .................... #define PID_ACK 0x02 //receiver accepts error-free data packet
3913 .................... #define PID_DATA0 0x03 //data packet with even sync bit 3913 .................... #define PID_DATA0 0x03 //data packet with even sync bit
3914 .................... #define PID_SOF 0x05 //start of framer marker and frame number 3914 .................... #define PID_SOF 0x05 //start of framer marker and frame number
3915 .................... #define PID_NAK 0x0A //receiver can't accept data or sender cant send data or has no data to transmit 3915 .................... #define PID_NAK 0x0A //receiver can't accept data or sender cant send data or has no data to transmit
3916 .................... #define PID_DATA1 0x0B //data packet with odd sync bit 3916 .................... #define PID_DATA1 0x0B //data packet with odd sync bit
3917 .................... #define PID_PRE 0x0C //preamble issued by host. enables downstream traffic to low-speed device 3917 .................... #define PID_PRE 0x0C //preamble issued by host. enables downstream traffic to low-speed device
3918 .................... #define PID_STALL 0x0E //a control request isnt supported or the endpoint is halted 3918 .................... #define PID_STALL 0x0E //a control request isnt supported or the endpoint is halted
3919 .................... 3919 ....................
3920 .................... //Key which identifies descritpors 3920 .................... //Key which identifies descritpors
3921 .................... #DEFINE USB_DESC_DEVICE_TYPE 0x01 //#DEFINE USB_DEVICE_DESC_KEY 0x01 3921 .................... #DEFINE USB_DESC_DEVICE_TYPE 0x01 //#DEFINE USB_DEVICE_DESC_KEY 0x01
3922 .................... #DEFINE USB_DESC_CONFIG_TYPE 0x02 //#DEFINE USB_CONFIG_DESC_KEY 0x02 3922 .................... #DEFINE USB_DESC_CONFIG_TYPE 0x02 //#DEFINE USB_CONFIG_DESC_KEY 0x02
3923 .................... #DEFINE USB_DESC_STRING_TYPE 0x03 //#DEFINE USB_STRING_DESC_KEY 0x03 3923 .................... #DEFINE USB_DESC_STRING_TYPE 0x03 //#DEFINE USB_STRING_DESC_KEY 0x03
3924 .................... #DEFINE USB_DESC_INTERFACE_TYPE 0x04 //#DEFINE USB_INTERFACE_DESC_KEY 0x04 3924 .................... #DEFINE USB_DESC_INTERFACE_TYPE 0x04 //#DEFINE USB_INTERFACE_DESC_KEY 0x04
3925 .................... #DEFINE USB_DESC_ENDPOINT_TYPE 0x05 //#DEFINE USB_ENDPOINT_DESC_KEY 0x05 3925 .................... #DEFINE USB_DESC_ENDPOINT_TYPE 0x05 //#DEFINE USB_ENDPOINT_DESC_KEY 0x05
3926 .................... #DEFINE USB_DESC_CLASS_TYPE 0x21 //#DEFINE USB_CLASS_DESC_KEY 0x21 3926 .................... #DEFINE USB_DESC_CLASS_TYPE 0x21 //#DEFINE USB_CLASS_DESC_KEY 0x21
3927 .................... #DEFINE USB_DESC_HIDREPORT_TYPE 0x22 3927 .................... #DEFINE USB_DESC_HIDREPORT_TYPE 0x22
3928 .................... 3928 ....................
3929 .................... //The length of each descriptor 3929 .................... //The length of each descriptor
3930 .................... #DEFINE USB_DESC_DEVICE_LEN 18 //#DEFINE USB_DEVICE_DESC_LEN 18 3930 .................... #DEFINE USB_DESC_DEVICE_LEN 18 //#DEFINE USB_DEVICE_DESC_LEN 18
3931 .................... #DEFINE USB_DESC_CONFIG_LEN 9 //#DEFINE USB_CONFIG_DESC_LEN 9 3931 .................... #DEFINE USB_DESC_CONFIG_LEN 9 //#DEFINE USB_CONFIG_DESC_LEN 9
3932 .................... #DEFINE USB_DESC_INTERFACE_LEN 9 //#DEFINE USB_INTERFACE_DESC_LEN 9 3932 .................... #DEFINE USB_DESC_INTERFACE_LEN 9 //#DEFINE USB_INTERFACE_DESC_LEN 9
3933 .................... #DEFINE USB_DESC_CLASS_LEN 9 //#DEFINE USB_CLASS_DESC_LEN 9 3933 .................... #DEFINE USB_DESC_CLASS_LEN 9 //#DEFINE USB_CLASS_DESC_LEN 9
3934 .................... #DEFINE USB_DESC_ENDPOINT_LEN 7 //#DEFINE USB_ENDPOINT_DESC_LEN 7 3934 .................... #DEFINE USB_DESC_ENDPOINT_LEN 7 //#DEFINE USB_ENDPOINT_DESC_LEN 7
3935 .................... 3935 ....................
3936 .................... //Standard USB Setup bRequest Codes 3936 .................... //Standard USB Setup bRequest Codes
3937 .................... #define USB_STANDARD_REQUEST_GET_STATUS 0x00 3937 .................... #define USB_STANDARD_REQUEST_GET_STATUS 0x00
3938 .................... #define USB_STANDARD_REQUEST_CLEAR_FEATURE 0x01 3938 .................... #define USB_STANDARD_REQUEST_CLEAR_FEATURE 0x01
3939 .................... #define USB_STANDARD_REQUEST_SET_FEATURE 0x03 3939 .................... #define USB_STANDARD_REQUEST_SET_FEATURE 0x03
3940 .................... #define USB_STANDARD_REQUEST_SET_ADDRESS 0x05 3940 .................... #define USB_STANDARD_REQUEST_SET_ADDRESS 0x05
3941 .................... #define USB_STANDARD_REQUEST_GET_DESCRIPTOR 0x06 3941 .................... #define USB_STANDARD_REQUEST_GET_DESCRIPTOR 0x06
3942 .................... #define USB_STANDARD_REQUEST_SET_DESCRIPTOR 0x07 3942 .................... #define USB_STANDARD_REQUEST_SET_DESCRIPTOR 0x07
3943 .................... #define USB_STANDARD_REQUEST_GET_CONFIGURATION 0x08 3943 .................... #define USB_STANDARD_REQUEST_GET_CONFIGURATION 0x08
3944 .................... #define USB_STANDARD_REQUEST_SET_CONFIGURATION 0x09 3944 .................... #define USB_STANDARD_REQUEST_SET_CONFIGURATION 0x09
3945 .................... #define USB_STANDARD_REQUEST_GET_INTERFACE 0x0A 3945 .................... #define USB_STANDARD_REQUEST_GET_INTERFACE 0x0A
3946 .................... #define USB_STANDARD_REQUEST_SET_INTERFACE 0x0B 3946 .................... #define USB_STANDARD_REQUEST_SET_INTERFACE 0x0B
3947 .................... #define USB_STANDARD_REQUEST_SYNCH_FRAME 0x0C 3947 .................... #define USB_STANDARD_REQUEST_SYNCH_FRAME 0x0C
3948 .................... 3948 ....................
3949 .................... //HID Class Setup bRequest Codes 3949 .................... //HID Class Setup bRequest Codes
3950 .................... #define USB_HID_REQUEST_GET_REPORT 0x01 3950 .................... #define USB_HID_REQUEST_GET_REPORT 0x01
3951 .................... #define USB_HID_REQUEST_GET_IDLE 0x02 3951 .................... #define USB_HID_REQUEST_GET_IDLE 0x02
3952 .................... #define USB_HID_REQUEST_GET_PROTOCOL 0x03 3952 .................... #define USB_HID_REQUEST_GET_PROTOCOL 0x03
3953 .................... #define USB_HID_REQUEST_SET_REPORT 0x09 3953 .................... #define USB_HID_REQUEST_SET_REPORT 0x09
3954 .................... #define USB_HID_REQUEST_SET_IDLE 0x0A 3954 .................... #define USB_HID_REQUEST_SET_IDLE 0x0A
3955 .................... #define USB_HID_REQUEST_SET_PROTOCOL 0x0B 3955 .................... #define USB_HID_REQUEST_SET_PROTOCOL 0x0B
3956 .................... 3956 ....................
3957 .................... //types of endpoints as defined in the descriptor 3957 .................... //types of endpoints as defined in the descriptor
3958 .................... #define USB_ENDPOINT_TYPE_CONTROL 0x00 3958 .................... #define USB_ENDPOINT_TYPE_CONTROL 0x00
3959 .................... #define USB_ENDPOINT_TYPE_ISOCHRONOUS 0x01 3959 .................... #define USB_ENDPOINT_TYPE_ISOCHRONOUS 0x01
3960 .................... #define USB_ENDPOINT_TYPE_BULK 0x02 3960 .................... #define USB_ENDPOINT_TYPE_BULK 0x02
3961 .................... #define USB_ENDPOINT_TYPE_INTERRUPT 0x03 3961 .................... #define USB_ENDPOINT_TYPE_INTERRUPT 0x03
3962 .................... 3962 ....................
3963 .................... //types of endpoints used internally in this api 3963 .................... //types of endpoints used internally in this api
3964 .................... #define USB_ENABLE_DISABLED -1 3964 .................... #define USB_ENABLE_DISABLED -1
3965 .................... #define USB_ENABLE_BULK USB_ENDPOINT_TYPE_BULK 3965 .................... #define USB_ENABLE_BULK USB_ENDPOINT_TYPE_BULK
3966 .................... #define USB_ENABLE_ISOCHRONOUS USB_ENDPOINT_TYPE_ISOCHRONOUS 3966 .................... #define USB_ENABLE_ISOCHRONOUS USB_ENDPOINT_TYPE_ISOCHRONOUS
3967 .................... #define USB_ENABLE_INTERRUPT USB_ENDPOINT_TYPE_INTERRUPT 3967 .................... #define USB_ENABLE_INTERRUPT USB_ENDPOINT_TYPE_INTERRUPT
3968 .................... #define USB_ENABLE_CONTROL USB_ENDPOINT_TYPE_CONTROL 3968 .................... #define USB_ENABLE_CONTROL USB_ENDPOINT_TYPE_CONTROL
3969 .................... 3969 ....................
3970 .................... 3970 ....................
3971 .................... //*** ENABLE RX ENDPOINTS AND BUFFERS 3971 .................... //*** ENABLE RX ENDPOINTS AND BUFFERS
3972 .................... 3972 ....................
3973 .................... //--------- endpoint 0 defines ---------- 3973 .................... //--------- endpoint 0 defines ----------
3974 .................... #define USB_EP0_TX_ENABLE USB_ENABLE_CONTROL 3974 .................... #define USB_EP0_TX_ENABLE USB_ENABLE_CONTROL
3975 .................... #define USB_EP0_RX_ENABLE USB_ENABLE_CONTROL 3975 .................... #define USB_EP0_RX_ENABLE USB_ENABLE_CONTROL
3976 .................... #define USB_EP0_RX_SIZE USB_MAX_EP0_PACKET_LENGTH //endpoint 0 is setup, and should always be the MAX_PACKET_LENGTH. Slow speed specifies 8 3976 .................... #define USB_EP0_RX_SIZE USB_MAX_EP0_PACKET_LENGTH //endpoint 0 is setup, and should always be the MAX_PACKET_LENGTH. Slow speed specifies 8
3977 .................... #define USB_EP0_TX_SIZE USB_MAX_EP0_PACKET_LENGTH //endpoint 0 is setup, and should always be the MAX_PACKET_LENGTH. Slow speed specifies 8 3977 .................... #define USB_EP0_TX_SIZE USB_MAX_EP0_PACKET_LENGTH //endpoint 0 is setup, and should always be the MAX_PACKET_LENGTH. Slow speed specifies 8
3978 .................... 3978 ....................
3979 .................... //--------- endpoint 1 defines ---------- 3979 .................... //--------- endpoint 1 defines ----------
3980 .................... #ifndef USB_EP1_TX_ENABLE 3980 .................... #ifndef USB_EP1_TX_ENABLE
3981 .................... #define USB_EP1_TX_ENABLE USB_ENABLE_DISABLED 3981 .................... #define USB_EP1_TX_ENABLE USB_ENABLE_DISABLED
3982 .................... #endif 3982 .................... #endif
3983 .................... #ifndef USB_EP1_RX_ENABLE 3983 .................... #ifndef USB_EP1_RX_ENABLE
3984 .................... #define USB_EP1_RX_ENABLE USB_ENABLE_DISABLED 3984 .................... #define USB_EP1_RX_ENABLE USB_ENABLE_DISABLED
3985 .................... #endif 3985 .................... #endif
3986 .................... 3986 ....................
3987 .................... #if USB_EP1_RX_ENABLE==USB_ENABLE_DISABLED 3987 .................... #if USB_EP1_RX_ENABLE==USB_ENABLE_DISABLED
3988 .................... #ifdef USB_EP1_RX_SIZE 3988 .................... #ifdef USB_EP1_RX_SIZE
3989 .................... #undef USB_EP1_RX_SIZE 3989 .................... #undef USB_EP1_RX_SIZE
3990 .................... #endif 3990 .................... #endif
3991 .................... #define USB_EP1_RX_SIZE 0 3991 .................... #define USB_EP1_RX_SIZE 0
3992 .................... #else 3992 .................... #else
3993 .................... #ifndef USB_EP1_RX_SIZE 3993 .................... #ifndef USB_EP1_RX_SIZE
3994 .................... #error You enabled EP1 for RX but didn't specify endpoint size 3994 .................... #error You enabled EP1 for RX but didn't specify endpoint size
3995 .................... #endif 3995 .................... #endif
3996 .................... #endif 3996 .................... #endif
3997 .................... 3997 ....................
3998 .................... #if USB_EP1_TX_ENABLE==USB_ENABLE_DISABLED 3998 .................... #if USB_EP1_TX_ENABLE==USB_ENABLE_DISABLED
3999 .................... #ifdef USB_EP1_TX_SIZE 3999 .................... #ifdef USB_EP1_TX_SIZE
4000 .................... #undef USB_EP1_TX_SIZE 4000 .................... #undef USB_EP1_TX_SIZE
4001 .................... #endif 4001 .................... #endif
4002 .................... #define USB_EP1_TX_SIZE 0 4002 .................... #define USB_EP1_TX_SIZE 0
4003 .................... #else 4003 .................... #else
4004 .................... #ifndef USB_EP1_TX_SIZE 4004 .................... #ifndef USB_EP1_TX_SIZE
4005 .................... #error You enabled EP1 for TX but didn't specify endpoint size 4005 .................... #error You enabled EP1 for TX but didn't specify endpoint size
4006 .................... #endif 4006 .................... #endif
4007 .................... #endif 4007 .................... #endif
4008 .................... 4008 ....................
4009 .................... 4009 ....................
4010 .................... //--------- endpoint 2 defines ---------- 4010 .................... //--------- endpoint 2 defines ----------
4011 .................... #ifndef USB_EP2_TX_ENABLE 4011 .................... #ifndef USB_EP2_TX_ENABLE
4012 .................... #define USB_EP2_TX_ENABLE USB_ENABLE_DISABLED 4012 .................... #define USB_EP2_TX_ENABLE USB_ENABLE_DISABLED
4013 .................... #endif 4013 .................... #endif
4014 .................... #ifndef USB_EP2_RX_ENABLE 4014 .................... #ifndef USB_EP2_RX_ENABLE
4015 .................... #define USB_EP2_RX_ENABLE USB_ENABLE_DISABLED 4015 .................... #define USB_EP2_RX_ENABLE USB_ENABLE_DISABLED
4016 .................... #endif 4016 .................... #endif
4017 .................... 4017 ....................
4018 .................... #if USB_EP2_RX_ENABLE==USB_ENABLE_DISABLED 4018 .................... #if USB_EP2_RX_ENABLE==USB_ENABLE_DISABLED
4019 .................... #ifdef USB_EP2_RX_SIZE 4019 .................... #ifdef USB_EP2_RX_SIZE
4020 .................... #undef USB_EP2_RX_SIZE 4020 .................... #undef USB_EP2_RX_SIZE
4021 .................... #endif 4021 .................... #endif
4022 .................... #define USB_EP2_RX_SIZE 0 4022 .................... #define USB_EP2_RX_SIZE 0
4023 .................... #else 4023 .................... #else
4024 .................... #ifndef USB_EP2_RX_SIZE 4024 .................... #ifndef USB_EP2_RX_SIZE
4025 .................... #error You enabled EP2 for RX but didn't specify endpoint size 4025 .................... #error You enabled EP2 for RX but didn't specify endpoint size
4026 .................... #endif 4026 .................... #endif
4027 .................... #endif 4027 .................... #endif
4028 .................... 4028 ....................
4029 .................... #if USB_EP2_TX_ENABLE==USB_ENABLE_DISABLED 4029 .................... #if USB_EP2_TX_ENABLE==USB_ENABLE_DISABLED
4030 .................... #ifdef USB_EP2_TX_SIZE 4030 .................... #ifdef USB_EP2_TX_SIZE
4031 .................... #undef USB_EP2_TX_SIZE 4031 .................... #undef USB_EP2_TX_SIZE
4032 .................... #endif 4032 .................... #endif
4033 .................... #define USB_EP2_TX_SIZE 0 4033 .................... #define USB_EP2_TX_SIZE 0
4034 .................... #else 4034 .................... #else
4035 .................... #ifndef USB_EP2_TX_SIZE 4035 .................... #ifndef USB_EP2_TX_SIZE
4036 .................... #error You enabled EP2 for TX but didn't specify endpoint size 4036 .................... #error You enabled EP2 for TX but didn't specify endpoint size
4037 .................... #endif 4037 .................... #endif
4038 .................... #endif 4038 .................... #endif
4039 .................... 4039 ....................
4040 .................... 4040 ....................
4041 .................... //--------- endpoint 3 defines ---------- 4041 .................... //--------- endpoint 3 defines ----------
4042 .................... #ifndef USB_EP3_TX_ENABLE 4042 .................... #ifndef USB_EP3_TX_ENABLE
4043 .................... #define USB_EP3_TX_ENABLE USB_ENABLE_DISABLED 4043 .................... #define USB_EP3_TX_ENABLE USB_ENABLE_DISABLED
4044 .................... #endif 4044 .................... #endif
4045 .................... #ifndef USB_EP3_RX_ENABLE 4045 .................... #ifndef USB_EP3_RX_ENABLE
4046 .................... #define USB_EP3_RX_ENABLE USB_ENABLE_DISABLED 4046 .................... #define USB_EP3_RX_ENABLE USB_ENABLE_DISABLED
4047 .................... #endif 4047 .................... #endif
4048 .................... 4048 ....................
4049 .................... #if USB_EP3_RX_ENABLE==USB_ENABLE_DISABLED 4049 .................... #if USB_EP3_RX_ENABLE==USB_ENABLE_DISABLED
4050 .................... #ifdef USB_EP3_RX_SIZE 4050 .................... #ifdef USB_EP3_RX_SIZE
4051 .................... #undef USB_EP3_RX_SIZE 4051 .................... #undef USB_EP3_RX_SIZE
4052 .................... #endif 4052 .................... #endif
4053 .................... #define USB_EP3_RX_SIZE 0 4053 .................... #define USB_EP3_RX_SIZE 0
4054 .................... #else 4054 .................... #else
4055 .................... #ifndef USB_EP3_RX_SIZE 4055 .................... #ifndef USB_EP3_RX_SIZE
4056 .................... #error You enabled EP3 for RX but didn't specify endpoint size 4056 .................... #error You enabled EP3 for RX but didn't specify endpoint size
4057 .................... #endif 4057 .................... #endif
4058 .................... #endif 4058 .................... #endif
4059 .................... 4059 ....................
4060 .................... #if USB_EP3_TX_ENABLE==USB_ENABLE_DISABLED 4060 .................... #if USB_EP3_TX_ENABLE==USB_ENABLE_DISABLED
4061 .................... #ifdef USB_EP3_TX_SIZE 4061 .................... #ifdef USB_EP3_TX_SIZE
4062 .................... #undef USB_EP3_TX_SIZE 4062 .................... #undef USB_EP3_TX_SIZE
4063 .................... #endif 4063 .................... #endif
4064 .................... #define USB_EP3_TX_SIZE 0 4064 .................... #define USB_EP3_TX_SIZE 0
4065 .................... #else 4065 .................... #else
4066 .................... #ifndef USB_EP3_TX_SIZE 4066 .................... #ifndef USB_EP3_TX_SIZE
4067 .................... #error You enabled EP3 for TX but didn't specify endpoint size 4067 .................... #error You enabled EP3 for TX but didn't specify endpoint size
4068 .................... #endif 4068 .................... #endif
4069 .................... #endif 4069 .................... #endif
4070 .................... 4070 ....................
4071 .................... 4071 ....................
4072 .................... //--------- endpoint 4 defines ---------- 4072 .................... //--------- endpoint 4 defines ----------
4073 .................... #ifndef USB_EP4_TX_ENABLE 4073 .................... #ifndef USB_EP4_TX_ENABLE
4074 .................... #define USB_EP4_TX_ENABLE USB_ENABLE_DISABLED 4074 .................... #define USB_EP4_TX_ENABLE USB_ENABLE_DISABLED
4075 .................... #endif 4075 .................... #endif
4076 .................... #ifndef USB_EP4_RX_ENABLE 4076 .................... #ifndef USB_EP4_RX_ENABLE
4077 .................... #define USB_EP4_RX_ENABLE USB_ENABLE_DISABLED 4077 .................... #define USB_EP4_RX_ENABLE USB_ENABLE_DISABLED
4078 .................... #endif 4078 .................... #endif
4079 .................... 4079 ....................
4080 .................... #if USB_EP4_RX_ENABLE==USB_ENABLE_DISABLED 4080 .................... #if USB_EP4_RX_ENABLE==USB_ENABLE_DISABLED
4081 .................... #ifdef USB_EP4_RX_SIZE 4081 .................... #ifdef USB_EP4_RX_SIZE
4082 .................... #undef USB_EP4_RX_SIZE 4082 .................... #undef USB_EP4_RX_SIZE
4083 .................... #endif 4083 .................... #endif
4084 .................... #define USB_EP4_RX_SIZE 0 4084 .................... #define USB_EP4_RX_SIZE 0
4085 .................... #else 4085 .................... #else
4086 .................... #ifndef USB_EP4_RX_SIZE 4086 .................... #ifndef USB_EP4_RX_SIZE
4087 .................... #error You enabled EP4 for RX but didn't specify endpoint size 4087 .................... #error You enabled EP4 for RX but didn't specify endpoint size
4088 .................... #endif 4088 .................... #endif
4089 .................... #endif 4089 .................... #endif
4090 .................... 4090 ....................
4091 .................... #if USB_EP4_TX_ENABLE==USB_ENABLE_DISABLED 4091 .................... #if USB_EP4_TX_ENABLE==USB_ENABLE_DISABLED
4092 .................... #ifdef USB_EP4_TX_SIZE 4092 .................... #ifdef USB_EP4_TX_SIZE
4093 .................... #undef USB_EP4_TX_SIZE 4093 .................... #undef USB_EP4_TX_SIZE
4094 .................... #endif 4094 .................... #endif
4095 .................... #define USB_EP4_TX_SIZE 0 4095 .................... #define USB_EP4_TX_SIZE 0
4096 .................... #else 4096 .................... #else
4097 .................... #ifndef USB_EP4_TX_SIZE 4097 .................... #ifndef USB_EP4_TX_SIZE
4098 .................... #error You enabled EP4 for TX but didn't specify endpoint size 4098 .................... #error You enabled EP4 for TX but didn't specify endpoint size
4099 .................... #endif 4099 .................... #endif
4100 .................... #endif 4100 .................... #endif
4101 .................... 4101 ....................
4102 .................... 4102 ....................
4103 .................... //--------- endpoint 5 defines ---------- 4103 .................... //--------- endpoint 5 defines ----------
4104 .................... #ifndef USB_EP5_TX_ENABLE 4104 .................... #ifndef USB_EP5_TX_ENABLE
4105 .................... #define USB_EP5_TX_ENABLE USB_ENABLE_DISABLED 4105 .................... #define USB_EP5_TX_ENABLE USB_ENABLE_DISABLED
4106 .................... #endif 4106 .................... #endif
4107 .................... #ifndef USB_EP5_RX_ENABLE 4107 .................... #ifndef USB_EP5_RX_ENABLE
4108 .................... #define USB_EP5_RX_ENABLE USB_ENABLE_DISABLED 4108 .................... #define USB_EP5_RX_ENABLE USB_ENABLE_DISABLED
4109 .................... #endif 4109 .................... #endif
4110 .................... 4110 ....................
4111 .................... #if USB_EP5_RX_ENABLE==USB_ENABLE_DISABLED 4111 .................... #if USB_EP5_RX_ENABLE==USB_ENABLE_DISABLED
4112 .................... #ifdef USB_EP5_RX_SIZE 4112 .................... #ifdef USB_EP5_RX_SIZE
4113 .................... #undef USB_EP5_RX_SIZE 4113 .................... #undef USB_EP5_RX_SIZE
4114 .................... #endif 4114 .................... #endif
4115 .................... #define USB_EP5_RX_SIZE 0 4115 .................... #define USB_EP5_RX_SIZE 0
4116 .................... #else 4116 .................... #else
4117 .................... #ifndef USB_EP5_RX_SIZE 4117 .................... #ifndef USB_EP5_RX_SIZE
4118 .................... #error You enabled EP5 for RX but didn't specify endpoint size 4118 .................... #error You enabled EP5 for RX but didn't specify endpoint size
4119 .................... #endif 4119 .................... #endif
4120 .................... #endif 4120 .................... #endif
4121 .................... 4121 ....................
4122 .................... #if USB_EP5_TX_ENABLE==USB_ENABLE_DISABLED 4122 .................... #if USB_EP5_TX_ENABLE==USB_ENABLE_DISABLED
4123 .................... #ifdef USB_EP5_TX_SIZE 4123 .................... #ifdef USB_EP5_TX_SIZE
4124 .................... #undef USB_EP5_TX_SIZE 4124 .................... #undef USB_EP5_TX_SIZE
4125 .................... #endif 4125 .................... #endif
4126 .................... #define USB_EP5_TX_SIZE 0 4126 .................... #define USB_EP5_TX_SIZE 0
4127 .................... #else 4127 .................... #else
4128 .................... #ifndef USB_EP5_TX_SIZE 4128 .................... #ifndef USB_EP5_TX_SIZE
4129 .................... #error You enabled EP5 for TX but didn't specify endpoint size 4129 .................... #error You enabled EP5 for TX but didn't specify endpoint size
4130 .................... #endif 4130 .................... #endif
4131 .................... #endif 4131 .................... #endif
4132 .................... 4132 ....................
4133 .................... 4133 ....................
4134 .................... //--------- endpoint 6 defines ---------- 4134 .................... //--------- endpoint 6 defines ----------
4135 .................... #ifndef USB_EP6_TX_ENABLE 4135 .................... #ifndef USB_EP6_TX_ENABLE
4136 .................... #define USB_EP6_TX_ENABLE USB_ENABLE_DISABLED 4136 .................... #define USB_EP6_TX_ENABLE USB_ENABLE_DISABLED
4137 .................... #endif 4137 .................... #endif
4138 .................... #ifndef USB_EP6_RX_ENABLE 4138 .................... #ifndef USB_EP6_RX_ENABLE
4139 .................... #define USB_EP6_RX_ENABLE USB_ENABLE_DISABLED 4139 .................... #define USB_EP6_RX_ENABLE USB_ENABLE_DISABLED
4140 .................... #endif 4140 .................... #endif
4141 .................... 4141 ....................
4142 .................... #if USB_EP6_RX_ENABLE==USB_ENABLE_DISABLED 4142 .................... #if USB_EP6_RX_ENABLE==USB_ENABLE_DISABLED
4143 .................... #ifdef USB_EP6_RX_SIZE 4143 .................... #ifdef USB_EP6_RX_SIZE
4144 .................... #undef USB_EP6_RX_SIZE 4144 .................... #undef USB_EP6_RX_SIZE
4145 .................... #endif 4145 .................... #endif
4146 .................... #define USB_EP6_RX_SIZE 0 4146 .................... #define USB_EP6_RX_SIZE 0
4147 .................... #else 4147 .................... #else
4148 .................... #ifndef USB_EP6_RX_SIZE 4148 .................... #ifndef USB_EP6_RX_SIZE
4149 .................... #error You enabled EP6 for RX but didn't specify endpoint size 4149 .................... #error You enabled EP6 for RX but didn't specify endpoint size
4150 .................... #endif 4150 .................... #endif
4151 .................... #endif 4151 .................... #endif
4152 .................... 4152 ....................
4153 .................... #if USB_EP6_TX_ENABLE==USB_ENABLE_DISABLED 4153 .................... #if USB_EP6_TX_ENABLE==USB_ENABLE_DISABLED
4154 .................... #ifdef USB_EP6_TX_SIZE 4154 .................... #ifdef USB_EP6_TX_SIZE
4155 .................... #undef USB_EP6_TX_SIZE 4155 .................... #undef USB_EP6_TX_SIZE
4156 .................... #endif 4156 .................... #endif
4157 .................... #define USB_EP6_TX_SIZE 0 4157 .................... #define USB_EP6_TX_SIZE 0
4158 .................... #else 4158 .................... #else
4159 .................... #ifndef USB_EP6_TX_SIZE 4159 .................... #ifndef USB_EP6_TX_SIZE
4160 .................... #error You enabled EP6 for TX but didn't specify endpoint size 4160 .................... #error You enabled EP6 for TX but didn't specify endpoint size
4161 .................... #endif 4161 .................... #endif
4162 .................... #endif 4162 .................... #endif
4163 .................... 4163 ....................
4164 .................... 4164 ....................
4165 .................... //--------- endpoint 7 defines ---------- 4165 .................... //--------- endpoint 7 defines ----------
4166 .................... #ifndef USB_EP7_TX_ENABLE 4166 .................... #ifndef USB_EP7_TX_ENABLE
4167 .................... #define USB_EP7_TX_ENABLE USB_ENABLE_DISABLED 4167 .................... #define USB_EP7_TX_ENABLE USB_ENABLE_DISABLED
4168 .................... #endif 4168 .................... #endif
4169 .................... #ifndef USB_EP7_RX_ENABLE 4169 .................... #ifndef USB_EP7_RX_ENABLE
4170 .................... #define USB_EP7_RX_ENABLE USB_ENABLE_DISABLED 4170 .................... #define USB_EP7_RX_ENABLE USB_ENABLE_DISABLED
4171 .................... #endif 4171 .................... #endif
4172 .................... 4172 ....................
4173 .................... #if USB_EP7_RX_ENABLE==USB_ENABLE_DISABLED 4173 .................... #if USB_EP7_RX_ENABLE==USB_ENABLE_DISABLED
4174 .................... #ifdef USB_EP7_RX_SIZE 4174 .................... #ifdef USB_EP7_RX_SIZE
4175 .................... #undef USB_EP7_RX_SIZE 4175 .................... #undef USB_EP7_RX_SIZE
4176 .................... #endif 4176 .................... #endif
4177 .................... #define USB_EP7_RX_SIZE 0 4177 .................... #define USB_EP7_RX_SIZE 0
4178 .................... #else 4178 .................... #else
4179 .................... #ifndef USB_EP7_RX_SIZE 4179 .................... #ifndef USB_EP7_RX_SIZE
4180 .................... #error You enabled EP7 for RX but didn't specify endpoint size 4180 .................... #error You enabled EP7 for RX but didn't specify endpoint size
4181 .................... #endif 4181 .................... #endif
4182 .................... #endif 4182 .................... #endif
4183 .................... 4183 ....................
4184 .................... #if USB_EP7_TX_ENABLE==USB_ENABLE_DISABLED 4184 .................... #if USB_EP7_TX_ENABLE==USB_ENABLE_DISABLED
4185 .................... #ifdef USB_EP7_TX_SIZE 4185 .................... #ifdef USB_EP7_TX_SIZE
4186 .................... #undef USB_EP7_TX_SIZE 4186 .................... #undef USB_EP7_TX_SIZE
4187 .................... #endif 4187 .................... #endif
4188 .................... #define USB_EP7_TX_SIZE 0 4188 .................... #define USB_EP7_TX_SIZE 0
4189 .................... #else 4189 .................... #else
4190 .................... #ifndef USB_EP7_TX_SIZE 4190 .................... #ifndef USB_EP7_TX_SIZE
4191 .................... #error You enabled EP7 for TX but didn't specify endpoint size 4191 .................... #error You enabled EP7 for TX but didn't specify endpoint size
4192 .................... #endif 4192 .................... #endif
4193 .................... #endif 4193 .................... #endif
4194 .................... 4194 ....................
4195 .................... 4195 ....................
4196 .................... //--------- endpoint 8 defines ---------- 4196 .................... //--------- endpoint 8 defines ----------
4197 .................... #ifndef USB_EP8_TX_ENABLE 4197 .................... #ifndef USB_EP8_TX_ENABLE
4198 .................... #define USB_EP8_TX_ENABLE USB_ENABLE_DISABLED 4198 .................... #define USB_EP8_TX_ENABLE USB_ENABLE_DISABLED
4199 .................... #endif 4199 .................... #endif
4200 .................... #ifndef USB_EP8_RX_ENABLE 4200 .................... #ifndef USB_EP8_RX_ENABLE
4201 .................... #define USB_EP8_RX_ENABLE USB_ENABLE_DISABLED 4201 .................... #define USB_EP8_RX_ENABLE USB_ENABLE_DISABLED
4202 .................... #endif 4202 .................... #endif
4203 .................... 4203 ....................
4204 .................... #if USB_EP8_RX_ENABLE==USB_ENABLE_DISABLED 4204 .................... #if USB_EP8_RX_ENABLE==USB_ENABLE_DISABLED
4205 .................... #ifdef USB_EP8_RX_SIZE 4205 .................... #ifdef USB_EP8_RX_SIZE
4206 .................... #undef USB_EP8_RX_SIZE 4206 .................... #undef USB_EP8_RX_SIZE
4207 .................... #endif 4207 .................... #endif
4208 .................... #define USB_EP8_RX_SIZE 0 4208 .................... #define USB_EP8_RX_SIZE 0
4209 .................... #else 4209 .................... #else
4210 .................... #ifndef USB_EP8_RX_SIZE 4210 .................... #ifndef USB_EP8_RX_SIZE
4211 .................... #error You enabled EP8 for RX but didn't specify endpoint size 4211 .................... #error You enabled EP8 for RX but didn't specify endpoint size
4212 .................... #endif 4212 .................... #endif
4213 .................... #endif 4213 .................... #endif
4214 .................... 4214 ....................
4215 .................... #if USB_EP8_TX_ENABLE==USB_ENABLE_DISABLED 4215 .................... #if USB_EP8_TX_ENABLE==USB_ENABLE_DISABLED
4216 .................... #ifdef USB_EP8_TX_SIZE 4216 .................... #ifdef USB_EP8_TX_SIZE
4217 .................... #undef USB_EP8_TX_SIZE 4217 .................... #undef USB_EP8_TX_SIZE
4218 .................... #endif 4218 .................... #endif
4219 .................... #define USB_EP8_TX_SIZE 0 4219 .................... #define USB_EP8_TX_SIZE 0
4220 .................... #else 4220 .................... #else
4221 .................... #ifndef USB_EP8_TX_SIZE 4221 .................... #ifndef USB_EP8_TX_SIZE
4222 .................... #error You enabled EP8 for TX but didn't specify endpoint size 4222 .................... #error You enabled EP8 for TX but didn't specify endpoint size
4223 .................... #endif 4223 .................... #endif
4224 .................... #endif 4224 .................... #endif
4225 .................... 4225 ....................
4226 .................... 4226 ....................
4227 .................... //--------- endpoint 9 defines ---------- 4227 .................... //--------- endpoint 9 defines ----------
4228 .................... #ifndef USB_EP9_TX_ENABLE 4228 .................... #ifndef USB_EP9_TX_ENABLE
4229 .................... #define USB_EP9_TX_ENABLE USB_ENABLE_DISABLED 4229 .................... #define USB_EP9_TX_ENABLE USB_ENABLE_DISABLED
4230 .................... #endif 4230 .................... #endif
4231 .................... #ifndef USB_EP9_RX_ENABLE 4231 .................... #ifndef USB_EP9_RX_ENABLE
4232 .................... #define USB_EP9_RX_ENABLE USB_ENABLE_DISABLED 4232 .................... #define USB_EP9_RX_ENABLE USB_ENABLE_DISABLED
4233 .................... #endif 4233 .................... #endif
4234 .................... 4234 ....................
4235 .................... #if USB_EP9_RX_ENABLE==USB_ENABLE_DISABLED 4235 .................... #if USB_EP9_RX_ENABLE==USB_ENABLE_DISABLED
4236 .................... #ifdef USB_EP9_RX_SIZE 4236 .................... #ifdef USB_EP9_RX_SIZE
4237 .................... #undef USB_EP9_RX_SIZE 4237 .................... #undef USB_EP9_RX_SIZE
4238 .................... #endif 4238 .................... #endif
4239 .................... #define USB_EP9_RX_SIZE 0 4239 .................... #define USB_EP9_RX_SIZE 0
4240 .................... #else 4240 .................... #else
4241 .................... #ifndef USB_EP9_RX_SIZE 4241 .................... #ifndef USB_EP9_RX_SIZE
4242 .................... #error You enabled EP9 for RX but didn't specify endpoint size 4242 .................... #error You enabled EP9 for RX but didn't specify endpoint size
4243 .................... #endif 4243 .................... #endif
4244 .................... #endif 4244 .................... #endif
4245 .................... 4245 ....................
4246 .................... #if USB_EP9_TX_ENABLE==USB_ENABLE_DISABLED 4246 .................... #if USB_EP9_TX_ENABLE==USB_ENABLE_DISABLED
4247 .................... #ifdef USB_EP9_TX_SIZE 4247 .................... #ifdef USB_EP9_TX_SIZE
4248 .................... #undef USB_EP9_TX_SIZE 4248 .................... #undef USB_EP9_TX_SIZE
4249 .................... #endif 4249 .................... #endif
4250 .................... #define USB_EP9_TX_SIZE 0 4250 .................... #define USB_EP9_TX_SIZE 0
4251 .................... #else 4251 .................... #else
4252 .................... #ifndef USB_EP9_TX_SIZE 4252 .................... #ifndef USB_EP9_TX_SIZE
4253 .................... #error You enabled EP9 for TX but didn't specify endpoint size 4253 .................... #error You enabled EP9 for TX but didn't specify endpoint size
4254 .................... #endif 4254 .................... #endif
4255 .................... #endif 4255 .................... #endif
4256 .................... 4256 ....................
4257 .................... 4257 ....................
4258 .................... //--------- endpoint 10 defines ---------- 4258 .................... //--------- endpoint 10 defines ----------
4259 .................... #ifndef USB_EP10_TX_ENABLE 4259 .................... #ifndef USB_EP10_TX_ENABLE
4260 .................... #define USB_EP10_TX_ENABLE USB_ENABLE_DISABLED 4260 .................... #define USB_EP10_TX_ENABLE USB_ENABLE_DISABLED
4261 .................... #endif 4261 .................... #endif
4262 .................... #ifndef USB_EP10_RX_ENABLE 4262 .................... #ifndef USB_EP10_RX_ENABLE
4263 .................... #define USB_EP10_RX_ENABLE USB_ENABLE_DISABLED 4263 .................... #define USB_EP10_RX_ENABLE USB_ENABLE_DISABLED
4264 .................... #endif 4264 .................... #endif
4265 .................... 4265 ....................
4266 .................... #if USB_EP10_RX_ENABLE==USB_ENABLE_DISABLED 4266 .................... #if USB_EP10_RX_ENABLE==USB_ENABLE_DISABLED
4267 .................... #ifdef USB_EP10_RX_SIZE 4267 .................... #ifdef USB_EP10_RX_SIZE
4268 .................... #undef USB_EP10_RX_SIZE 4268 .................... #undef USB_EP10_RX_SIZE
4269 .................... #endif 4269 .................... #endif
4270 .................... #define USB_EP10_RX_SIZE 0 4270 .................... #define USB_EP10_RX_SIZE 0
4271 .................... #else 4271 .................... #else
4272 .................... #ifndef USB_EP10_RX_SIZE 4272 .................... #ifndef USB_EP10_RX_SIZE
4273 .................... #error You enabled EP10 for RX but didn't specify endpoint size 4273 .................... #error You enabled EP10 for RX but didn't specify endpoint size
4274 .................... #endif 4274 .................... #endif
4275 .................... #endif 4275 .................... #endif
4276 .................... 4276 ....................
4277 .................... #if USB_EP10_TX_ENABLE==USB_ENABLE_DISABLED 4277 .................... #if USB_EP10_TX_ENABLE==USB_ENABLE_DISABLED
4278 .................... #ifdef USB_EP10_TX_SIZE 4278 .................... #ifdef USB_EP10_TX_SIZE
4279 .................... #undef USB_EP10_TX_SIZE 4279 .................... #undef USB_EP10_TX_SIZE
4280 .................... #endif 4280 .................... #endif
4281 .................... #define USB_EP10_TX_SIZE 0 4281 .................... #define USB_EP10_TX_SIZE 0
4282 .................... #else 4282 .................... #else
4283 .................... #ifndef USB_EP10_TX_SIZE 4283 .................... #ifndef USB_EP10_TX_SIZE
4284 .................... #error You enabled EP10 for TX but didn't specify endpoint size 4284 .................... #error You enabled EP10 for TX but didn't specify endpoint size
4285 .................... #endif 4285 .................... #endif
4286 .................... #endif 4286 .................... #endif
4287 .................... 4287 ....................
4288 .................... 4288 ....................
4289 .................... //--------- endpoint 11 defines ---------- 4289 .................... //--------- endpoint 11 defines ----------
4290 .................... #ifndef USB_EP11_TX_ENABLE 4290 .................... #ifndef USB_EP11_TX_ENABLE
4291 .................... #define USB_EP11_TX_ENABLE USB_ENABLE_DISABLED 4291 .................... #define USB_EP11_TX_ENABLE USB_ENABLE_DISABLED
4292 .................... #endif 4292 .................... #endif
4293 .................... #ifndef USB_EP11_RX_ENABLE 4293 .................... #ifndef USB_EP11_RX_ENABLE
4294 .................... #define USB_EP11_RX_ENABLE USB_ENABLE_DISABLED 4294 .................... #define USB_EP11_RX_ENABLE USB_ENABLE_DISABLED
4295 .................... #endif 4295 .................... #endif
4296 .................... 4296 ....................
4297 .................... #if USB_EP11_RX_ENABLE==USB_ENABLE_DISABLED 4297 .................... #if USB_EP11_RX_ENABLE==USB_ENABLE_DISABLED
4298 .................... #ifdef USB_EP11_RX_SIZE 4298 .................... #ifdef USB_EP11_RX_SIZE
4299 .................... #undef USB_EP11_RX_SIZE 4299 .................... #undef USB_EP11_RX_SIZE
4300 .................... #endif 4300 .................... #endif
4301 .................... #define USB_EP11_RX_SIZE 0 4301 .................... #define USB_EP11_RX_SIZE 0
4302 .................... #else 4302 .................... #else
4303 .................... #ifndef USB_EP11_RX_SIZE 4303 .................... #ifndef USB_EP11_RX_SIZE
4304 .................... #error You enabled EP11 for RX but didn't specify endpoint size 4304 .................... #error You enabled EP11 for RX but didn't specify endpoint size
4305 .................... #endif 4305 .................... #endif
4306 .................... #endif 4306 .................... #endif
4307 .................... 4307 ....................
4308 .................... #if USB_EP11_TX_ENABLE==USB_ENABLE_DISABLED 4308 .................... #if USB_EP11_TX_ENABLE==USB_ENABLE_DISABLED
4309 .................... #ifdef USB_EP11_TX_SIZE 4309 .................... #ifdef USB_EP11_TX_SIZE
4310 .................... #undef USB_EP11_TX_SIZE 4310 .................... #undef USB_EP11_TX_SIZE
4311 .................... #endif 4311 .................... #endif
4312 .................... #define USB_EP11_TX_SIZE 0 4312 .................... #define USB_EP11_TX_SIZE 0
4313 .................... #else 4313 .................... #else
4314 .................... #ifndef USB_EP11_TX_SIZE 4314 .................... #ifndef USB_EP11_TX_SIZE
4315 .................... #error You enabled EP11 for TX but didn't specify endpoint size 4315 .................... #error You enabled EP11 for TX but didn't specify endpoint size
4316 .................... #endif 4316 .................... #endif
4317 .................... #endif 4317 .................... #endif
4318 .................... 4318 ....................
4319 .................... 4319 ....................
4320 .................... //--------- endpoint 12 defines ---------- 4320 .................... //--------- endpoint 12 defines ----------
4321 .................... #ifndef USB_EP12_TX_ENABLE 4321 .................... #ifndef USB_EP12_TX_ENABLE
4322 .................... #define USB_EP12_TX_ENABLE USB_ENABLE_DISABLED 4322 .................... #define USB_EP12_TX_ENABLE USB_ENABLE_DISABLED
4323 .................... #endif 4323 .................... #endif
4324 .................... #ifndef USB_EP12_RX_ENABLE 4324 .................... #ifndef USB_EP12_RX_ENABLE
4325 .................... #define USB_EP12_RX_ENABLE USB_ENABLE_DISABLED 4325 .................... #define USB_EP12_RX_ENABLE USB_ENABLE_DISABLED
4326 .................... #endif 4326 .................... #endif
4327 .................... 4327 ....................
4328 .................... #if USB_EP12_RX_ENABLE==USB_ENABLE_DISABLED 4328 .................... #if USB_EP12_RX_ENABLE==USB_ENABLE_DISABLED
4329 .................... #ifdef USB_EP12_RX_SIZE 4329 .................... #ifdef USB_EP12_RX_SIZE
4330 .................... #undef USB_EP12_RX_SIZE 4330 .................... #undef USB_EP12_RX_SIZE
4331 .................... #endif 4331 .................... #endif
4332 .................... #define USB_EP12_RX_SIZE 0 4332 .................... #define USB_EP12_RX_SIZE 0
4333 .................... #else 4333 .................... #else
4334 .................... #ifndef USB_EP12_RX_SIZE 4334 .................... #ifndef USB_EP12_RX_SIZE
4335 .................... #error You enabled EP12 for RX but didn't specify endpoint size 4335 .................... #error You enabled EP12 for RX but didn't specify endpoint size
4336 .................... #endif 4336 .................... #endif
4337 .................... #endif 4337 .................... #endif
4338 .................... 4338 ....................
4339 .................... #if USB_EP12_TX_ENABLE==USB_ENABLE_DISABLED 4339 .................... #if USB_EP12_TX_ENABLE==USB_ENABLE_DISABLED
4340 .................... #ifdef USB_EP12_TX_SIZE 4340 .................... #ifdef USB_EP12_TX_SIZE
4341 .................... #undef USB_EP12_TX_SIZE 4341 .................... #undef USB_EP12_TX_SIZE
4342 .................... #endif 4342 .................... #endif
4343 .................... #define USB_EP12_TX_SIZE 0 4343 .................... #define USB_EP12_TX_SIZE 0
4344 .................... #else 4344 .................... #else
4345 .................... #ifndef USB_EP12_TX_SIZE 4345 .................... #ifndef USB_EP12_TX_SIZE
4346 .................... #error You enabled EP12 for TX but didn't specify endpoint size 4346 .................... #error You enabled EP12 for TX but didn't specify endpoint size
4347 .................... #endif 4347 .................... #endif
4348 .................... #endif 4348 .................... #endif
4349 .................... 4349 ....................
4350 .................... 4350 ....................
4351 .................... //--------- endpoint 13 defines ---------- 4351 .................... //--------- endpoint 13 defines ----------
4352 .................... #ifndef USB_EP13_TX_ENABLE 4352 .................... #ifndef USB_EP13_TX_ENABLE
4353 .................... #define USB_EP13_TX_ENABLE USB_ENABLE_DISABLED 4353 .................... #define USB_EP13_TX_ENABLE USB_ENABLE_DISABLED
4354 .................... #endif 4354 .................... #endif
4355 .................... #ifndef USB_EP13_RX_ENABLE 4355 .................... #ifndef USB_EP13_RX_ENABLE
4356 .................... #define USB_EP13_RX_ENABLE USB_ENABLE_DISABLED 4356 .................... #define USB_EP13_RX_ENABLE USB_ENABLE_DISABLED
4357 .................... #endif 4357 .................... #endif
4358 .................... 4358 ....................
4359 .................... #if USB_EP13_RX_ENABLE==USB_ENABLE_DISABLED 4359 .................... #if USB_EP13_RX_ENABLE==USB_ENABLE_DISABLED
4360 .................... #ifdef USB_EP13_RX_SIZE 4360 .................... #ifdef USB_EP13_RX_SIZE
4361 .................... #undef USB_EP13_RX_SIZE 4361 .................... #undef USB_EP13_RX_SIZE
4362 .................... #endif 4362 .................... #endif
4363 .................... #define USB_EP13_RX_SIZE 0 4363 .................... #define USB_EP13_RX_SIZE 0
4364 .................... #else 4364 .................... #else
4365 .................... #ifndef USB_EP13_RX_SIZE 4365 .................... #ifndef USB_EP13_RX_SIZE
4366 .................... #error You enabled EP13 for RX but didn't specify endpoint size 4366 .................... #error You enabled EP13 for RX but didn't specify endpoint size
4367 .................... #endif 4367 .................... #endif
4368 .................... #endif 4368 .................... #endif
4369 .................... 4369 ....................
4370 .................... #if USB_EP13_TX_ENABLE==USB_ENABLE_DISABLED 4370 .................... #if USB_EP13_TX_ENABLE==USB_ENABLE_DISABLED
4371 .................... #ifdef USB_EP13_TX_SIZE 4371 .................... #ifdef USB_EP13_TX_SIZE
4372 .................... #undef USB_EP13_TX_SIZE 4372 .................... #undef USB_EP13_TX_SIZE
4373 .................... #endif 4373 .................... #endif
4374 .................... #define USB_EP13_TX_SIZE 0 4374 .................... #define USB_EP13_TX_SIZE 0
4375 .................... #else 4375 .................... #else
4376 .................... #ifndef USB_EP13_TX_SIZE 4376 .................... #ifndef USB_EP13_TX_SIZE
4377 .................... #error You enabled EP13 for TX but didn't specify endpoint size 4377 .................... #error You enabled EP13 for TX but didn't specify endpoint size
4378 .................... #endif 4378 .................... #endif
4379 .................... #endif 4379 .................... #endif
4380 .................... 4380 ....................
4381 .................... 4381 ....................
4382 .................... //--------- endpoint 14 defines ---------- 4382 .................... //--------- endpoint 14 defines ----------
4383 .................... #ifndef USB_EP14_TX_ENABLE 4383 .................... #ifndef USB_EP14_TX_ENABLE
4384 .................... #define USB_EP14_TX_ENABLE USB_ENABLE_DISABLED 4384 .................... #define USB_EP14_TX_ENABLE USB_ENABLE_DISABLED
4385 .................... #endif 4385 .................... #endif
4386 .................... #ifndef USB_EP14_RX_ENABLE 4386 .................... #ifndef USB_EP14_RX_ENABLE
4387 .................... #define USB_EP14_RX_ENABLE USB_ENABLE_DISABLED 4387 .................... #define USB_EP14_RX_ENABLE USB_ENABLE_DISABLED
4388 .................... #endif 4388 .................... #endif
4389 .................... 4389 ....................
4390 .................... #if USB_EP14_RX_ENABLE==USB_ENABLE_DISABLED 4390 .................... #if USB_EP14_RX_ENABLE==USB_ENABLE_DISABLED
4391 .................... #ifdef USB_EP14_RX_SIZE 4391 .................... #ifdef USB_EP14_RX_SIZE
4392 .................... #undef USB_EP14_RX_SIZE 4392 .................... #undef USB_EP14_RX_SIZE
4393 .................... #endif 4393 .................... #endif
4394 .................... #define USB_EP14_RX_SIZE 0 4394 .................... #define USB_EP14_RX_SIZE 0
4395 .................... #else 4395 .................... #else
4396 .................... #ifndef USB_EP14_RX_SIZE 4396 .................... #ifndef USB_EP14_RX_SIZE
4397 .................... #error You enabled EP14 for RX but didn't specify endpoint size 4397 .................... #error You enabled EP14 for RX but didn't specify endpoint size
4398 .................... #endif 4398 .................... #endif
4399 .................... #endif 4399 .................... #endif
4400 .................... 4400 ....................
4401 .................... #if USB_EP14_TX_ENABLE==USB_ENABLE_DISABLED 4401 .................... #if USB_EP14_TX_ENABLE==USB_ENABLE_DISABLED
4402 .................... #ifdef USB_EP14_TX_SIZE 4402 .................... #ifdef USB_EP14_TX_SIZE
4403 .................... #undef USB_EP14_TX_SIZE 4403 .................... #undef USB_EP14_TX_SIZE
4404 .................... #endif 4404 .................... #endif
4405 .................... #define USB_EP14_TX_SIZE 0 4405 .................... #define USB_EP14_TX_SIZE 0
4406 .................... #else 4406 .................... #else
4407 .................... #ifndef USB_EP14_TX_SIZE 4407 .................... #ifndef USB_EP14_TX_SIZE
4408 .................... #error You enabled EP14 for TX but didn't specify endpoint size 4408 .................... #error You enabled EP14 for TX but didn't specify endpoint size
4409 .................... #endif 4409 .................... #endif
4410 .................... #endif 4410 .................... #endif
4411 .................... 4411 ....................
4412 .................... 4412 ....................
4413 .................... //--------- endpoint 15 defines ---------- 4413 .................... //--------- endpoint 15 defines ----------
4414 .................... #ifndef USB_EP15_TX_ENABLE 4414 .................... #ifndef USB_EP15_TX_ENABLE
4415 .................... #define USB_EP15_TX_ENABLE USB_ENABLE_DISABLED 4415 .................... #define USB_EP15_TX_ENABLE USB_ENABLE_DISABLED
4416 .................... #endif 4416 .................... #endif
4417 .................... #ifndef USB_EP15_RX_ENABLE 4417 .................... #ifndef USB_EP15_RX_ENABLE
4418 .................... #define USB_EP15_RX_ENABLE USB_ENABLE_DISABLED 4418 .................... #define USB_EP15_RX_ENABLE USB_ENABLE_DISABLED
4419 .................... #endif 4419 .................... #endif
4420 .................... 4420 ....................
4421 .................... #if USB_EP15_RX_ENABLE==USB_ENABLE_DISABLED 4421 .................... #if USB_EP15_RX_ENABLE==USB_ENABLE_DISABLED
4422 .................... #ifdef USB_EP15_RX_SIZE 4422 .................... #ifdef USB_EP15_RX_SIZE
4423 .................... #undef USB_EP15_RX_SIZE 4423 .................... #undef USB_EP15_RX_SIZE
4424 .................... #endif 4424 .................... #endif
4425 .................... #define USB_EP15_RX_SIZE 0 4425 .................... #define USB_EP15_RX_SIZE 0
4426 .................... #else 4426 .................... #else
4427 .................... #ifndef USB_EP15_RX_SIZE 4427 .................... #ifndef USB_EP15_RX_SIZE
4428 .................... #error You enabled EP15 for RX but didn't specify endpoint size 4428 .................... #error You enabled EP15 for RX but didn't specify endpoint size
4429 .................... #endif 4429 .................... #endif
4430 .................... #endif 4430 .................... #endif
4431 .................... 4431 ....................
4432 .................... #if USB_EP15_TX_ENABLE==USB_ENABLE_DISABLED 4432 .................... #if USB_EP15_TX_ENABLE==USB_ENABLE_DISABLED
4433 .................... #ifdef USB_EP15_TX_SIZE 4433 .................... #ifdef USB_EP15_TX_SIZE
4434 .................... #undef USB_EP15_TX_SIZE 4434 .................... #undef USB_EP15_TX_SIZE
4435 .................... #endif 4435 .................... #endif
4436 .................... #define USB_EP15_TX_SIZE 0 4436 .................... #define USB_EP15_TX_SIZE 0
4437 .................... #else 4437 .................... #else
4438 .................... #ifndef USB_EP15_TX_SIZE 4438 .................... #ifndef USB_EP15_TX_SIZE
4439 .................... #error You enabled EP15 for TX but didn't specify endpoint size 4439 .................... #error You enabled EP15 for TX but didn't specify endpoint size
4440 .................... #endif 4440 .................... #endif
4441 .................... #endif 4441 .................... #endif
4442 .................... 4442 ....................
4443 .................... const int8 usb_ep_tx_type[16]={ 4443 .................... const int8 usb_ep_tx_type[16]={
4444 .................... USB_EP0_TX_ENABLE, USB_EP1_TX_ENABLE, USB_EP2_TX_ENABLE, 4444 .................... USB_EP0_TX_ENABLE, USB_EP1_TX_ENABLE, USB_EP2_TX_ENABLE,
4445 .................... USB_EP3_TX_ENABLE, USB_EP4_TX_ENABLE, USB_EP5_TX_ENABLE, 4445 .................... USB_EP3_TX_ENABLE, USB_EP4_TX_ENABLE, USB_EP5_TX_ENABLE,
4446 .................... USB_EP6_TX_ENABLE, USB_EP7_TX_ENABLE, USB_EP8_TX_ENABLE, 4446 .................... USB_EP6_TX_ENABLE, USB_EP7_TX_ENABLE, USB_EP8_TX_ENABLE,
4447 .................... USB_EP9_TX_ENABLE, USB_EP10_TX_ENABLE, USB_EP11_TX_ENABLE, 4447 .................... USB_EP9_TX_ENABLE, USB_EP10_TX_ENABLE, USB_EP11_TX_ENABLE,
4448 .................... USB_EP12_TX_ENABLE, USB_EP13_TX_ENABLE, USB_EP14_TX_ENABLE, 4448 .................... USB_EP12_TX_ENABLE, USB_EP13_TX_ENABLE, USB_EP14_TX_ENABLE,
4449 .................... USB_EP15_TX_ENABLE 4449 .................... USB_EP15_TX_ENABLE
4450 .................... }; 4450 .................... };
4451 .................... 4451 ....................
4452 .................... const int8 usb_ep_rx_type[16]={ 4452 .................... const int8 usb_ep_rx_type[16]={
4453 .................... USB_EP0_RX_ENABLE, USB_EP1_RX_ENABLE, USB_EP2_RX_ENABLE, 4453 .................... USB_EP0_RX_ENABLE, USB_EP1_RX_ENABLE, USB_EP2_RX_ENABLE,
4454 .................... USB_EP3_RX_ENABLE, USB_EP4_RX_ENABLE, USB_EP5_RX_ENABLE, 4454 .................... USB_EP3_RX_ENABLE, USB_EP4_RX_ENABLE, USB_EP5_RX_ENABLE,
4455 .................... USB_EP6_RX_ENABLE, USB_EP7_RX_ENABLE, USB_EP8_RX_ENABLE, 4455 .................... USB_EP6_RX_ENABLE, USB_EP7_RX_ENABLE, USB_EP8_RX_ENABLE,
4456 .................... USB_EP9_RX_ENABLE, USB_EP10_RX_ENABLE, USB_EP11_RX_ENABLE, 4456 .................... USB_EP9_RX_ENABLE, USB_EP10_RX_ENABLE, USB_EP11_RX_ENABLE,
4457 .................... USB_EP12_RX_ENABLE, USB_EP13_RX_ENABLE, USB_EP14_RX_ENABLE, 4457 .................... USB_EP12_RX_ENABLE, USB_EP13_RX_ENABLE, USB_EP14_RX_ENABLE,
4458 .................... USB_EP15_RX_ENABLE 4458 .................... USB_EP15_RX_ENABLE
4459 .................... }; 4459 .................... };
4460 .................... 4460 ....................
4461 .................... const unsigned int16 usb_ep_tx_size[16]={ 4461 .................... const unsigned int16 usb_ep_tx_size[16]={
4462 .................... USB_EP0_TX_SIZE, USB_EP1_TX_SIZE, USB_EP2_TX_SIZE, 4462 .................... USB_EP0_TX_SIZE, USB_EP1_TX_SIZE, USB_EP2_TX_SIZE,
4463 .................... USB_EP3_TX_SIZE, USB_EP4_TX_SIZE, USB_EP5_TX_SIZE, 4463 .................... USB_EP3_TX_SIZE, USB_EP4_TX_SIZE, USB_EP5_TX_SIZE,
4464 .................... USB_EP6_TX_SIZE, USB_EP7_TX_SIZE, USB_EP8_TX_SIZE, 4464 .................... USB_EP6_TX_SIZE, USB_EP7_TX_SIZE, USB_EP8_TX_SIZE,
4465 .................... USB_EP9_TX_SIZE, USB_EP10_TX_SIZE, USB_EP11_TX_SIZE, 4465 .................... USB_EP9_TX_SIZE, USB_EP10_TX_SIZE, USB_EP11_TX_SIZE,
4466 .................... USB_EP12_TX_SIZE, USB_EP13_TX_SIZE, USB_EP14_TX_SIZE, 4466 .................... USB_EP12_TX_SIZE, USB_EP13_TX_SIZE, USB_EP14_TX_SIZE,
4467 .................... USB_EP15_TX_SIZE 4467 .................... USB_EP15_TX_SIZE
4468 .................... }; 4468 .................... };
4469 .................... 4469 ....................
4470 .................... const unsigned int16 usb_ep_rx_size[16]={ 4470 .................... const unsigned int16 usb_ep_rx_size[16]={
4471 .................... USB_EP0_RX_SIZE, USB_EP1_RX_SIZE, USB_EP2_RX_SIZE, 4471 .................... USB_EP0_RX_SIZE, USB_EP1_RX_SIZE, USB_EP2_RX_SIZE,
4472 .................... USB_EP3_RX_SIZE, USB_EP4_RX_SIZE, USB_EP5_RX_SIZE, 4472 .................... USB_EP3_RX_SIZE, USB_EP4_RX_SIZE, USB_EP5_RX_SIZE,
4473 .................... USB_EP6_RX_SIZE, USB_EP7_RX_SIZE, USB_EP8_RX_SIZE, 4473 .................... USB_EP6_RX_SIZE, USB_EP7_RX_SIZE, USB_EP8_RX_SIZE,
4474 .................... USB_EP9_RX_SIZE, USB_EP10_RX_SIZE, USB_EP11_RX_SIZE, 4474 .................... USB_EP9_RX_SIZE, USB_EP10_RX_SIZE, USB_EP11_RX_SIZE,
4475 .................... USB_EP12_RX_SIZE, USB_EP13_RX_SIZE, USB_EP14_RX_SIZE, 4475 .................... USB_EP12_RX_SIZE, USB_EP13_RX_SIZE, USB_EP14_RX_SIZE,
4476 .................... USB_EP15_RX_SIZE 4476 .................... USB_EP15_RX_SIZE
4477 .................... }; 4477 .................... };
4478 .................... 4478 ....................
4479 .................... #ENDIF 4479 .................... #ENDIF
4480 .................... 4480 ....................
4481 .................... 4481 ....................
4482 .................... //if you are worried that the PIC is not receiving packets because a bug in the 4482 .................... //if you are worried that the PIC is not receiving packets because a bug in the
4483 .................... //DATA0/DATA1 synch code, you can set this to TRUE to ignore the DTS on 4483 .................... //DATA0/DATA1 synch code, you can set this to TRUE to ignore the DTS on
4484 .................... //receiving. 4484 .................... //receiving.
4485 .................... #ifndef USB_IGNORE_RX_DTS 4485 .................... #ifndef USB_IGNORE_RX_DTS
4486 .................... #define USB_IGNORE_RX_DTS FALSE 4486 .................... #define USB_IGNORE_RX_DTS FALSE
4487 .................... #endif 4487 .................... #endif
4488 .................... 4488 ....................
4489 .................... #ifndef USB_IGNORE_TX_DTS 4489 .................... #ifndef USB_IGNORE_TX_DTS
4490 .................... #define USB_IGNORE_TX_DTS FALSE 4490 .................... #define USB_IGNORE_TX_DTS FALSE
4491 .................... #endif 4491 .................... #endif
4492 .................... 4492 ....................
4493 .................... #if ((getenv("DEVICE")=="PIC18F87J50") || (getenv("DEVICE")=="PIC18F86J55") || \ 4493 .................... #if ((getenv("DEVICE")=="PIC18F87J50") || (getenv("DEVICE")=="PIC18F86J55") || \
4494 .................... (getenv("DEVICE")=="PIC18F86J50") || (getenv("DEVICE")=="PIC18F85J50") || \ 4494 .................... (getenv("DEVICE")=="PIC18F86J50") || (getenv("DEVICE")=="PIC18F85J50") || \
4495 .................... (getenv("DEVICE")=="PIC18F67J50") || (getenv("DEVICE")=="PIC18F66J55") || \ 4495 .................... (getenv("DEVICE")=="PIC18F67J50") || (getenv("DEVICE")=="PIC18F66J55") || \
4496 .................... (getenv("DEVICE")=="PIC18F66J50") || (getenv("DEVICE")=="PIC18F65J50")) 4496 .................... (getenv("DEVICE")=="PIC18F66J50") || (getenv("DEVICE")=="PIC18F65J50"))
4497 .................... #define __USB_87J50__ 4497 .................... #define __USB_87J50__
4498 .................... #define USB_TOTAL_RAM_SPACE ((int16)getenv("RAM")-0x400) 4498 .................... #define USB_TOTAL_RAM_SPACE ((int16)getenv("RAM")-0x400)
4499 .................... #define USB_RAM_START 0x400 4499 .................... #define USB_RAM_START 0x400
4500 .................... #define USB_LAST_ALLOWED_ENDPOINT 16 4500 .................... #define USB_LAST_ALLOWED_ENDPOINT 16
4501 .................... #elif ((getenv("DEVICE")=="PIC18F2450") || (getenv("DEVICE")=="PIC18F4450")) 4501 .................... #elif ((getenv("DEVICE")=="PIC18F2450") || (getenv("DEVICE")=="PIC18F4450"))
4502 .................... #define __USB_4450__ 4502 .................... #define __USB_4450__
4503 .................... #define USB_TOTAL_RAM_SPACE ((int16)0x100) 4503 .................... #define USB_TOTAL_RAM_SPACE ((int16)0x100)
4504 .................... #define USB_RAM_START 0x400 4504 .................... #define USB_RAM_START 0x400
4505 .................... #define USB_LAST_ALLOWED_ENDPOINT 3 4505 .................... #define USB_LAST_ALLOWED_ENDPOINT 3
4506 .................... #elif ((getenv("DEVICE")=="PIC18F13K50") || (getenv("DEVICE")=="PIC18F14K50")) 4506 .................... #elif ((getenv("DEVICE")=="PIC18F13K50") || (getenv("DEVICE")=="PIC18F14K50"))
4507 .................... #define __USB_K50__ 4507 .................... #define __USB_K50__
4508 .................... #define USB_TOTAL_RAM_SPACE ((int16)0x200) 4508 .................... #define USB_TOTAL_RAM_SPACE ((int16)0x200)
4509 .................... #define USB_RAM_START 0x200 4509 .................... #define USB_RAM_START 0x200
4510 .................... #define USB_LAST_ALLOWED_ENDPOINT 8 4510 .................... #define USB_LAST_ALLOWED_ENDPOINT 8
4511 .................... #elif ((getenv("DEVICE")=="PIC18F2455") || (getenv("DEVICE")=="PIC18F2550") || \ 4511 .................... #elif ((getenv("DEVICE")=="PIC18F2455") || (getenv("DEVICE")=="PIC18F2550") || \
4512 .................... (getenv("DEVICE")=="PIC18F4455") || (getenv("DEVICE")=="PIC18F4550") || \ 4512 .................... (getenv("DEVICE")=="PIC18F4455") || (getenv("DEVICE")=="PIC18F4550") || \
4513 .................... (getenv("DEVICE")=="PIC18F2458") || (getenv("DEVICE")=="PIC18F2553") || \ 4513 .................... (getenv("DEVICE")=="PIC18F2458") || (getenv("DEVICE")=="PIC18F2553") || \
4514 .................... (getenv("DEVICE")=="PIC18F4458") || (getenv("DEVICE")=="PIC18F4553") \ 4514 .................... (getenv("DEVICE")=="PIC18F4458") || (getenv("DEVICE")=="PIC18F4553") \
4515 .................... ) 4515 .................... )
4516 .................... #define __USB_4550__ 4516 .................... #define __USB_4550__
4517 .................... #define USB_TOTAL_RAM_SPACE ((int16)0x400) 4517 .................... #define USB_TOTAL_RAM_SPACE ((int16)0x400)
4518 .................... #define USB_RAM_START 0x400 4518 .................... #define USB_RAM_START 0x400
4519 .................... #define USB_LAST_ALLOWED_ENDPOINT 16 4519 .................... #define USB_LAST_ALLOWED_ENDPOINT 16
4520 .................... #else 4520 .................... #else
4521 .................... #error Unknown PIC device, USB not supported in this library. 4521 .................... #error Unknown PIC device, USB not supported in this library.
4522 .................... #endif 4522 .................... #endif
4523 .................... 4523 ....................
4524 .................... #if USB_EP15_TX_SIZE || USB_EP15_RX_SIZE 4524 .................... #if USB_EP15_TX_SIZE || USB_EP15_RX_SIZE
4525 .................... #define USB_LAST_DEFINED_ENDPOINT 15 4525 .................... #define USB_LAST_DEFINED_ENDPOINT 15
4526 .................... #elif USB_EP14_TX_SIZE || USB_EP14_RX_SIZE 4526 .................... #elif USB_EP14_TX_SIZE || USB_EP14_RX_SIZE
4527 .................... #define USB_LAST_DEFINED_ENDPOINT 14 4527 .................... #define USB_LAST_DEFINED_ENDPOINT 14
4528 .................... #elif USB_EP13_TX_SIZE || USB_EP13_RX_SIZE 4528 .................... #elif USB_EP13_TX_SIZE || USB_EP13_RX_SIZE
4529 .................... #define USB_LAST_DEFINED_ENDPOINT 13 4529 .................... #define USB_LAST_DEFINED_ENDPOINT 13
4530 .................... #elif USB_EP12_TX_SIZE || USB_EP12_RX_SIZE 4530 .................... #elif USB_EP12_TX_SIZE || USB_EP12_RX_SIZE
4531 .................... #define USB_LAST_DEFINED_ENDPOINT 12 4531 .................... #define USB_LAST_DEFINED_ENDPOINT 12
4532 .................... #elif USB_EP11_TX_SIZE || USB_EP11_RX_SIZE 4532 .................... #elif USB_EP11_TX_SIZE || USB_EP11_RX_SIZE
4533 .................... #define USB_LAST_DEFINED_ENDPOINT 11 4533 .................... #define USB_LAST_DEFINED_ENDPOINT 11
4534 .................... #elif USB_EP10_TX_SIZE || USB_EP10_RX_SIZE 4534 .................... #elif USB_EP10_TX_SIZE || USB_EP10_RX_SIZE
4535 .................... #define USB_LAST_DEFINED_ENDPOINT 10 4535 .................... #define USB_LAST_DEFINED_ENDPOINT 10
4536 .................... #elif USB_EP9_TX_SIZE || USB_EP9_RX_SIZE 4536 .................... #elif USB_EP9_TX_SIZE || USB_EP9_RX_SIZE
4537 .................... #define USB_LAST_DEFINED_ENDPOINT 9 4537 .................... #define USB_LAST_DEFINED_ENDPOINT 9
4538 .................... #elif USB_EP8_TX_SIZE || USB_EP8_RX_SIZE 4538 .................... #elif USB_EP8_TX_SIZE || USB_EP8_RX_SIZE
4539 .................... #define USB_LAST_DEFINED_ENDPOINT 8 4539 .................... #define USB_LAST_DEFINED_ENDPOINT 8
4540 .................... #elif USB_EP7_TX_SIZE || USB_EP7_RX_SIZE 4540 .................... #elif USB_EP7_TX_SIZE || USB_EP7_RX_SIZE
4541 .................... #define USB_LAST_DEFINED_ENDPOINT 7 4541 .................... #define USB_LAST_DEFINED_ENDPOINT 7
4542 .................... #elif USB_EP6_TX_SIZE || USB_EP6_RX_SIZE 4542 .................... #elif USB_EP6_TX_SIZE || USB_EP6_RX_SIZE
4543 .................... #define USB_LAST_DEFINED_ENDPOINT 6 4543 .................... #define USB_LAST_DEFINED_ENDPOINT 6
4544 .................... #elif USB_EP5_TX_SIZE || USB_EP5_RX_SIZE 4544 .................... #elif USB_EP5_TX_SIZE || USB_EP5_RX_SIZE
4545 .................... #define USB_LAST_DEFINED_ENDPOINT 5 4545 .................... #define USB_LAST_DEFINED_ENDPOINT 5
4546 .................... #elif USB_EP4_TX_SIZE || USB_EP4_RX_SIZE 4546 .................... #elif USB_EP4_TX_SIZE || USB_EP4_RX_SIZE
4547 .................... #define USB_LAST_DEFINED_ENDPOINT 4 4547 .................... #define USB_LAST_DEFINED_ENDPOINT 4
4548 .................... #elif USB_EP3_TX_SIZE || USB_EP3_RX_SIZE 4548 .................... #elif USB_EP3_TX_SIZE || USB_EP3_RX_SIZE
4549 .................... #define USB_LAST_DEFINED_ENDPOINT 3 4549 .................... #define USB_LAST_DEFINED_ENDPOINT 3
4550 .................... #elif USB_EP2_TX_SIZE || USB_EP2_RX_SIZE 4550 .................... #elif USB_EP2_TX_SIZE || USB_EP2_RX_SIZE
4551 .................... #define USB_LAST_DEFINED_ENDPOINT 2 4551 .................... #define USB_LAST_DEFINED_ENDPOINT 2
4552 .................... #elif USB_EP1_TX_SIZE || USB_EP1_RX_SIZE 4552 .................... #elif USB_EP1_TX_SIZE || USB_EP1_RX_SIZE
4553 .................... #define USB_LAST_DEFINED_ENDPOINT 1 4553 .................... #define USB_LAST_DEFINED_ENDPOINT 1
4554 .................... #else 4554 .................... #else
4555 .................... #define USB_LAST_DEFINED_ENDPOINT 0 4555 .................... #define USB_LAST_DEFINED_ENDPOINT 0
4556 .................... #endif 4556 .................... #endif
4557 .................... 4557 ....................
4558 .................... #define USB_CONTROL_REGISTER_SIZE ((USB_LAST_DEFINED_ENDPOINT+1)*8) 4558 .................... #define USB_CONTROL_REGISTER_SIZE ((USB_LAST_DEFINED_ENDPOINT+1)*8)
4559 .................... 4559 ....................
4560 .................... #define USB_DATA_BUFFER_NEEDED (USB_EP0_TX_SIZE+USB_EP0_RX_SIZE+USB_EP1_TX_SIZE+\ 4560 .................... #define USB_DATA_BUFFER_NEEDED (USB_EP0_TX_SIZE+USB_EP0_RX_SIZE+USB_EP1_TX_SIZE+\
4561 .................... USB_EP1_RX_SIZE+USB_EP2_TX_SIZE+USB_EP2_RX_SIZE+\ 4561 .................... USB_EP1_RX_SIZE+USB_EP2_TX_SIZE+USB_EP2_RX_SIZE+\
4562 .................... USB_EP3_TX_SIZE+USB_EP3_RX_SIZE+USB_EP4_TX_SIZE+\ 4562 .................... USB_EP3_TX_SIZE+USB_EP3_RX_SIZE+USB_EP4_TX_SIZE+\
4563 .................... USB_EP4_RX_SIZE+USB_EP5_TX_SIZE+USB_EP5_RX_SIZE+\ 4563 .................... USB_EP4_RX_SIZE+USB_EP5_TX_SIZE+USB_EP5_RX_SIZE+\
4564 .................... USB_EP6_TX_SIZE+USB_EP6_RX_SIZE+USB_EP7_TX_SIZE+\ 4564 .................... USB_EP6_TX_SIZE+USB_EP6_RX_SIZE+USB_EP7_TX_SIZE+\
4565 .................... USB_EP7_RX_SIZE+USB_EP8_TX_SIZE+USB_EP8_RX_SIZE+\ 4565 .................... USB_EP7_RX_SIZE+USB_EP8_TX_SIZE+USB_EP8_RX_SIZE+\
4566 .................... USB_EP9_TX_SIZE+USB_EP9_RX_SIZE+USB_EP10_TX_SIZE+\ 4566 .................... USB_EP9_TX_SIZE+USB_EP9_RX_SIZE+USB_EP10_TX_SIZE+\
4567 .................... USB_EP10_RX_SIZE+USB_EP11_TX_SIZE+USB_EP11_RX_SIZE+\ 4567 .................... USB_EP10_RX_SIZE+USB_EP11_TX_SIZE+USB_EP11_RX_SIZE+\
4568 .................... USB_EP12_TX_SIZE+USB_EP12_RX_SIZE+USB_EP13_TX_SIZE+\ 4568 .................... USB_EP12_TX_SIZE+USB_EP12_RX_SIZE+USB_EP13_TX_SIZE+\
4569 .................... USB_EP13_RX_SIZE+USB_EP14_TX_SIZE+USB_EP14_RX_SIZE+\ 4569 .................... USB_EP13_RX_SIZE+USB_EP14_TX_SIZE+USB_EP14_RX_SIZE+\
4570 .................... USB_EP15_TX_SIZE+USB_EP15_RX_SIZE) 4570 .................... USB_EP15_TX_SIZE+USB_EP15_RX_SIZE)
4571 .................... 4571 ....................
4572 .................... #if ((USB_DATA_BUFFER_NEEDED+USB_CONTROL_REGISTER_SIZE) > USB_TOTAL_RAM_SPACE) 4572 .................... #if ((USB_DATA_BUFFER_NEEDED+USB_CONTROL_REGISTER_SIZE) > USB_TOTAL_RAM_SPACE)
4573 .................... #error You are trying to allocate more memory for endpoints than the PIC can handle 4573 .................... #error You are trying to allocate more memory for endpoints than the PIC can handle
4574 .................... #endif 4574 .................... #endif
4575 .................... 4575 ....................
4576 .................... #if (USB_LAST_DEFINED_ENDPOINT > USB_LAST_ALLOWED_ENDPOINT) 4576 .................... #if (USB_LAST_DEFINED_ENDPOINT > USB_LAST_ALLOWED_ENDPOINT)
4577 .................... #error You are trying ot use an invalid endpoint for this hardware! 4577 .................... #error You are trying ot use an invalid endpoint for this hardware!
4578 .................... #endif 4578 .................... #endif
4579 .................... 4579 ....................
4580 .................... #define USB_DATA_BUFFER_LOCATION ((int16)USB_RAM_START+USB_CONTROL_REGISTER_SIZE) 4580 .................... #define USB_DATA_BUFFER_LOCATION ((int16)USB_RAM_START+USB_CONTROL_REGISTER_SIZE)
4581 .................... 4581 ....................
4582 .................... typedef struct 4582 .................... typedef struct
4583 .................... { 4583 .................... {
4584 .................... int8 stat; 4584 .................... int8 stat;
4585 .................... int8 cnt; 4585 .................... int8 cnt;
4586 .................... int16 addr; 4586 .................... int16 addr;
4587 .................... } STRUCT_BD; 4587 .................... } STRUCT_BD;
4588 .................... 4588 ....................
4589 .................... struct 4589 .................... struct
4590 .................... { 4590 .................... {
4591 .................... struct 4591 .................... struct
4592 .................... { 4592 .................... {
4593 .................... STRUCT_BD out; //pc -> pic 4593 .................... STRUCT_BD out; //pc -> pic
4594 .................... STRUCT_BD in; //pc <- pic 4594 .................... STRUCT_BD in; //pc <- pic
4595 .................... } bd[USB_LAST_DEFINED_ENDPOINT+1]; 4595 .................... } bd[USB_LAST_DEFINED_ENDPOINT+1];
4596 .................... union 4596 .................... union
4597 .................... { 4597 .................... {
4598 .................... struct 4598 .................... struct
4599 .................... { 4599 .................... {
4600 .................... int8 ep0_rx_buffer[USB_MAX_EP0_PACKET_LENGTH]; 4600 .................... int8 ep0_rx_buffer[USB_MAX_EP0_PACKET_LENGTH];
4601 .................... int8 ep0_tx_buffer[USB_MAX_EP0_PACKET_LENGTH]; 4601 .................... int8 ep0_tx_buffer[USB_MAX_EP0_PACKET_LENGTH];
4602 .................... 4602 ....................
4603 .................... //these buffer definitions needed for CDC library 4603 .................... //these buffer definitions needed for CDC library
4604 .................... #if USB_EP1_RX_SIZE 4604 .................... #if USB_EP1_RX_SIZE
4605 .................... int8 ep1_rx_buffer[USB_EP1_RX_SIZE]; 4605 .................... int8 ep1_rx_buffer[USB_EP1_RX_SIZE];
4606 .................... #endif 4606 .................... #endif
4607 .................... #if USB_EP1_TX_SIZE 4607 .................... #if USB_EP1_TX_SIZE
4608 .................... int8 ep1_tx_buffer[USB_EP1_TX_SIZE]; 4608 .................... int8 ep1_tx_buffer[USB_EP1_TX_SIZE];
4609 .................... #endif 4609 .................... #endif
4610 .................... #if USB_EP2_RX_SIZE 4610 .................... #if USB_EP2_RX_SIZE
4611 .................... int8 ep2_rx_buffer[USB_EP2_RX_SIZE]; 4611 .................... int8 ep2_rx_buffer[USB_EP2_RX_SIZE];
4612 .................... #endif 4612 .................... #endif
4613 .................... #if USB_EP2_TX_SIZE 4613 .................... #if USB_EP2_TX_SIZE
4614 .................... int8 ep2_tx_buffer[USB_EP2_TX_SIZE]; 4614 .................... int8 ep2_tx_buffer[USB_EP2_TX_SIZE];
4615 .................... #endif 4615 .................... #endif
4616 .................... }; 4616 .................... };
4617 .................... int8 general[USB_DATA_BUFFER_NEEDED]; 4617 .................... int8 general[USB_DATA_BUFFER_NEEDED];
4618 .................... } buffer; 4618 .................... } buffer;
4619 .................... } g_USBRAM; 4619 .................... } g_USBRAM;
4620 .................... #locate g_USBRAM=USB_RAM_START 4620 .................... #locate g_USBRAM=USB_RAM_START
4621 .................... 4621 ....................
4622 .................... #define usb_ep0_rx_buffer g_USBRAM.buffer.ep0_rx_buffer 4622 .................... #define usb_ep0_rx_buffer g_USBRAM.buffer.ep0_rx_buffer
4623 .................... #define usb_ep0_tx_buffer g_USBRAM.buffer.ep0_tx_buffer 4623 .................... #define usb_ep0_tx_buffer g_USBRAM.buffer.ep0_tx_buffer
4624 .................... 4624 ....................
4625 .................... //these buffer definitions needed for CDC library 4625 .................... //these buffer definitions needed for CDC library
4626 .................... #define usb_ep1_rx_buffer g_USBRAM.buffer.ep1_rx_buffer 4626 .................... #define usb_ep1_rx_buffer g_USBRAM.buffer.ep1_rx_buffer
4627 .................... #define usb_ep1_tx_buffer g_USBRAM.buffer.ep1_tx_buffer 4627 .................... #define usb_ep1_tx_buffer g_USBRAM.buffer.ep1_tx_buffer
4628 .................... #define usb_ep2_rx_buffer g_USBRAM.buffer.ep2_rx_buffer 4628 .................... #define usb_ep2_rx_buffer g_USBRAM.buffer.ep2_rx_buffer
4629 .................... #define usb_ep2_tx_buffer g_USBRAM.buffer.ep2_tx_buffer 4629 .................... #define usb_ep2_tx_buffer g_USBRAM.buffer.ep2_tx_buffer
4630 .................... 4630 ....................
4631 .................... #define debug_usb(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z) 4631 .................... #define debug_usb(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z)
4632 .................... //#define debug_usb printf 4632 .................... //#define debug_usb printf
4633 .................... //#define debug_putc putc_tbe 4633 .................... //#define debug_putc putc_tbe
4634 .................... #define debug_display_ram(x,y) 4634 .................... #define debug_display_ram(x,y)
4635 .................... /* 4635 .................... /*
4636 .................... void debug_display_ram(int8 len, int8 *ptr) { 4636 .................... void debug_display_ram(int8 len, int8 *ptr) {
4637 .................... int8 max=16; 4637 .................... int8 max=16;
4638 .................... debug_usb(debug_putc,"%U - ",len); 4638 .................... debug_usb(debug_putc,"%U - ",len);
4639 .................... if (max>len) {max=len;} 4639 .................... if (max>len) {max=len;}
4640 .................... while(max--) { 4640 .................... while(max--) {
4641 .................... debug_usb(debug_putc,"%X",*ptr); 4641 .................... debug_usb(debug_putc,"%X",*ptr);
4642 .................... len--; 4642 .................... len--;
4643 .................... ptr++; 4643 .................... ptr++;
4644 .................... } 4644 .................... }
4645 .................... if (len) {debug_usb(debug_putc,"...");} 4645 .................... if (len) {debug_usb(debug_putc,"...");}
4646 .................... } 4646 .................... }
4647 .................... */ 4647 .................... */
4648 .................... 4648 ....................
4649 .................... //if you enable this it will keep a counter of the 6 possible errors the 4649 .................... //if you enable this it will keep a counter of the 6 possible errors the
4650 .................... //pic can detect. disabling this will save you ROM, RAM and execution time. 4650 .................... //pic can detect. disabling this will save you ROM, RAM and execution time.
4651 .................... #if !defined(USB_USE_ERROR_COUNTER) 4651 .................... #if !defined(USB_USE_ERROR_COUNTER)
4652 .................... #define USB_USE_ERROR_COUNTER FALSE 4652 .................... #define USB_USE_ERROR_COUNTER FALSE
4653 .................... #endif 4653 .................... #endif
4654 .................... 4654 ....................
4655 .................... #define USB_PING_PONG_MODE_OFF 0 //no ping pong 4655 .................... #define USB_PING_PONG_MODE_OFF 0 //no ping pong
4656 .................... #define USB_PING_PONG_MODE_E0 1 //ping pong endpoint 0 only 4656 .................... #define USB_PING_PONG_MODE_E0 1 //ping pong endpoint 0 only
4657 .................... #define USB_PING_PONG_MODE_ON 2 //ping pong all endpoints 4657 .................... #define USB_PING_PONG_MODE_ON 2 //ping pong all endpoints
4658 .................... 4658 ....................
4659 .................... //NOTE - PING PONG MODE IS NOT SUPPORTED BY CCS! 4659 .................... //NOTE - PING PONG MODE IS NOT SUPPORTED BY CCS!
4660 .................... #if !defined(USB_PING_PONG_MODE) 4660 .................... #if !defined(USB_PING_PONG_MODE)
4661 .................... #define USB_PING_PONG_MODE USB_PING_PONG_MODE_OFF 4661 .................... #define USB_PING_PONG_MODE USB_PING_PONG_MODE_OFF
4662 .................... #endif 4662 .................... #endif
4663 .................... 4663 ....................
4664 .................... #if USB_USE_ERROR_COUNTER 4664 .................... #if USB_USE_ERROR_COUNTER
4665 .................... int ERROR_COUNTER[6]; 4665 .................... int ERROR_COUNTER[6];
4666 .................... #endif 4666 .................... #endif
4667 .................... 4667 ....................
4668 .................... //---pic18fxx5x memory locations 4668 .................... //---pic18fxx5x memory locations
4669 .................... #if defined(__USB_4550__) || defined(__USB_4450__) 4669 .................... #if defined(__USB_4550__) || defined(__USB_4450__)
4670 .................... #byte UFRML = 0xF66 4670 .................... #byte UFRML = 0xF66
4671 .................... #byte UFRMH = 0xF67 4671 .................... #byte UFRMH = 0xF67
4672 .................... #byte UIR = 0xF68 4672 .................... #byte UIR = 0xF68
4673 .................... #byte UIE = 0xF69 4673 .................... #byte UIE = 0xF69
4674 .................... #byte UEIR = 0xF6A 4674 .................... #byte UEIR = 0xF6A
4675 .................... #byte UEIE = 0xF6B 4675 .................... #byte UEIE = 0xF6B
4676 .................... #byte USTAT = 0xF6C 4676 .................... #byte USTAT = 0xF6C
4677 .................... #byte UCON = 0xF6D 4677 .................... #byte UCON = 0xF6D
4678 .................... #byte UADDR = 0xF6E 4678 .................... #byte UADDR = 0xF6E
4679 .................... #byte UCFG = 0xF6F 4679 .................... #byte UCFG = 0xF6F
4680 .................... #define UEP0_LOC 0xF70 4680 .................... #define UEP0_LOC 0xF70
4681 .................... #elif defined(__USB_K50__) 4681 .................... #elif defined(__USB_K50__)
4682 .................... #byte UFRML = 0xF5D 4682 .................... #byte UFRML = 0xF5D
4683 .................... #byte UFRMH = 0xF5E 4683 .................... #byte UFRMH = 0xF5E
4684 .................... #byte UIR = 0xF62 4684 .................... #byte UIR = 0xF62
4685 .................... #byte UIE = 0xF60 4685 .................... #byte UIE = 0xF60
4686 .................... #byte UEIR = 0xF5F 4686 .................... #byte UEIR = 0xF5F
4687 .................... #byte UEIE = 0xF5B 4687 .................... #byte UEIE = 0xF5B
4688 .................... #byte USTAT = 0xF63 4688 .................... #byte USTAT = 0xF63
4689 .................... #byte UCON = 0xF64 4689 .................... #byte UCON = 0xF64
4690 .................... #byte UADDR = 0xF5C 4690 .................... #byte UADDR = 0xF5C
4691 .................... #byte UCFG = 0xF61 4691 .................... #byte UCFG = 0xF61
4692 .................... #define UEP0_LOC 0xF53 4692 .................... #define UEP0_LOC 0xF53
4693 .................... #else 4693 .................... #else
4694 .................... #byte UFRML = 0xF60 4694 .................... #byte UFRML = 0xF60
4695 .................... #byte UFRMH = 0xF61 4695 .................... #byte UFRMH = 0xF61
4696 .................... #byte UIR = 0xF62 4696 .................... #byte UIR = 0xF62
4697 .................... #byte UIE = 0xF5C 4697 .................... #byte UIE = 0xF5C
4698 .................... #byte UEIR = 0xF63 4698 .................... #byte UEIR = 0xF63
4699 .................... #byte UEIE = 0xF5D 4699 .................... #byte UEIE = 0xF5D
4700 .................... #byte USTAT = 0xF64 4700 .................... #byte USTAT = 0xF64
4701 .................... #byte UCON = 0xF65 4701 .................... #byte UCON = 0xF65
4702 .................... #byte UADDR = 0xF5E 4702 .................... #byte UADDR = 0xF5E
4703 .................... #byte UCFG = 0xF5F 4703 .................... #byte UCFG = 0xF5F
4704 .................... #define UEP0_LOC 0xF4C 4704 .................... #define UEP0_LOC 0xF4C
4705 .................... #endif 4705 .................... #endif
4706 .................... 4706 ....................
4707 .................... int8 g_UEP[16]; 4707 .................... int8 g_UEP[16];
4708 .................... #locate g_UEP=UEP0_LOC 4708 .................... #locate g_UEP=UEP0_LOC
4709 .................... #define UEP(x) g_UEP[x] 4709 .................... #define UEP(x) g_UEP[x]
4710 .................... 4710 ....................
4711 .................... #BIT UIR_SOF = UIR.6 4711 .................... #BIT UIR_SOF = UIR.6
4712 .................... #BIT UIR_STALL = UIR.5 4712 .................... #BIT UIR_STALL = UIR.5
4713 .................... #BIT UIR_IDLE = UIR.4 4713 .................... #BIT UIR_IDLE = UIR.4
4714 .................... #BIT UIR_TRN = UIR.3 4714 .................... #BIT UIR_TRN = UIR.3
4715 .................... #BIT UIR_ACTV = UIR.2 4715 .................... #BIT UIR_ACTV = UIR.2
4716 .................... #BIT UIR_UERR = UIR.1 4716 .................... #BIT UIR_UERR = UIR.1
4717 .................... #BIT UIR_URST = UIR.0 4717 .................... #BIT UIR_URST = UIR.0
4718 .................... 4718 ....................
4719 .................... #BIT UIE_SOF = UIE.6 4719 .................... #BIT UIE_SOF = UIE.6
4720 .................... #BIT UIE_STALL = UIE.5 4720 .................... #BIT UIE_STALL = UIE.5
4721 .................... #BIT UIE_IDLE = UIE.4 4721 .................... #BIT UIE_IDLE = UIE.4
4722 .................... #BIT UIE_TRN = UIE.3 4722 .................... #BIT UIE_TRN = UIE.3
4723 .................... #BIT UIE_ACTV = UIE.2 4723 .................... #BIT UIE_ACTV = UIE.2
4724 .................... #BIT UIE_UERR = UIE.1 4724 .................... #BIT UIE_UERR = UIE.1
4725 .................... #BIT UIE_URST = UIE.0 4725 .................... #BIT UIE_URST = UIE.0
4726 .................... 4726 ....................
4727 .................... #bit UCON_PBRST=UCON.6 4727 .................... #bit UCON_PBRST=UCON.6
4728 .................... #bit UCON_SE0=UCON.5 4728 .................... #bit UCON_SE0=UCON.5
4729 .................... #bit UCON_PKTDIS=UCON.4 4729 .................... #bit UCON_PKTDIS=UCON.4
4730 .................... #bit UCON_USBEN=UCON.3 4730 .................... #bit UCON_USBEN=UCON.3
4731 .................... #bit UCON_RESUME=UCON.2 4731 .................... #bit UCON_RESUME=UCON.2
4732 .................... #bit UCON_SUSPND=UCON.1 4732 .................... #bit UCON_SUSPND=UCON.1
4733 .................... 4733 ....................
4734 .................... #if (USB_PING_PONG_MODE==USB_PING_PONG_MODE_OFF) 4734 .................... #if (USB_PING_PONG_MODE==USB_PING_PONG_MODE_OFF)
4735 .................... #define EP_BDxST_O(x) g_USBRAM.bd[x].out.stat 4735 .................... #define EP_BDxST_O(x) g_USBRAM.bd[x].out.stat
4736 .................... #define EP_BDxCNT_O(x) g_USBRAM.bd[x].out.cnt 4736 .................... #define EP_BDxCNT_O(x) g_USBRAM.bd[x].out.cnt
4737 .................... #define EP_BDxADR_O(x) g_USBRAM.bd[x].out.addr 4737 .................... #define EP_BDxADR_O(x) g_USBRAM.bd[x].out.addr
4738 .................... #define EP_BDxST_I(x) g_USBRAM.bd[x].in.stat 4738 .................... #define EP_BDxST_I(x) g_USBRAM.bd[x].in.stat
4739 .................... #define EP_BDxCNT_I(x) g_USBRAM.bd[x].in.cnt 4739 .................... #define EP_BDxCNT_I(x) g_USBRAM.bd[x].in.cnt
4740 .................... #define EP_BDxADR_I(x) g_USBRAM.bd[x].in.addr 4740 .................... #define EP_BDxADR_I(x) g_USBRAM.bd[x].in.addr
4741 .................... #else 4741 .................... #else
4742 .................... #error Right now this driver only supports no ping pong 4742 .................... #error Right now this driver only supports no ping pong
4743 .................... #endif 4743 .................... #endif
4744 .................... 4744 ....................
4745 .................... //See UEPn (0xF70-0xF7F) 4745 .................... //See UEPn (0xF70-0xF7F)
4746 .................... #define ENDPT_DISABLED 0x00 //endpoint not used 4746 .................... #define ENDPT_DISABLED 0x00 //endpoint not used
4747 .................... #define ENDPT_IN_ONLY 0x02 //endpoint supports IN transactions only 4747 .................... #define ENDPT_IN_ONLY 0x02 //endpoint supports IN transactions only
4748 .................... #define ENDPT_OUT_ONLY 0x04 //endpoint supports OUT transactions only 4748 .................... #define ENDPT_OUT_ONLY 0x04 //endpoint supports OUT transactions only
4749 .................... #define ENDPT_CONTROL 0x06 //Supports IN, OUT and CONTROL transactions - Only use with EP0 4749 .................... #define ENDPT_CONTROL 0x06 //Supports IN, OUT and CONTROL transactions - Only use with EP0
4750 .................... #define ENDPT_NON_CONTROL 0x0E //Supports both IN and OUT transactions 4750 .................... #define ENDPT_NON_CONTROL 0x0E //Supports both IN and OUT transactions
4751 .................... 4751 ....................
4752 .................... //Define the states that the USB interface can be in 4752 .................... //Define the states that the USB interface can be in
4753 .................... enum {USB_STATE_DETACHED=0, USB_STATE_ATTACHED=1, USB_STATE_POWERED=2, USB_STATE_DEFAULT=3, 4753 .................... enum {USB_STATE_DETACHED=0, USB_STATE_ATTACHED=1, USB_STATE_POWERED=2, USB_STATE_DEFAULT=3,
4754 .................... USB_STATE_ADDRESS=4, USB_STATE_CONFIGURED=5} usb_state=0; 4754 .................... USB_STATE_ADDRESS=4, USB_STATE_CONFIGURED=5} usb_state=0;
4755 .................... 4755 ....................
4756 .................... //--BDendST has their PIDs upshifed 2 4756 .................... //--BDendST has their PIDs upshifed 2
4757 .................... #define USB_PIC_PID_IN 0x24 //device to host transactions 4757 .................... #define USB_PIC_PID_IN 0x24 //device to host transactions
4758 .................... #define USB_PIC_PID_OUT 0x04 //host to device transactions 4758 .................... #define USB_PIC_PID_OUT 0x04 //host to device transactions
4759 .................... #define USB_PIC_PID_SETUP 0x34 //host to device setup transaction 4759 .................... #define USB_PIC_PID_SETUP 0x34 //host to device setup transaction
4760 .................... 4760 ....................
4761 .................... #define USTAT_IN_E0 4 4761 .................... #define USTAT_IN_E0 4
4762 .................... #define USTAT_OUT_SETUP_E0 0 4762 .................... #define USTAT_OUT_SETUP_E0 0
4763 .................... 4763 ....................
4764 .................... #define __USB_UIF_RESET 0x01 4764 .................... #define __USB_UIF_RESET 0x01
4765 .................... #define __USB_UIF_ERROR 0x02 4765 .................... #define __USB_UIF_ERROR 0x02
4766 .................... #define __USB_UIF_ACTIVE 0x04 4766 .................... #define __USB_UIF_ACTIVE 0x04
4767 .................... #define __USB_UIF_TOKEN 0x08 4767 .................... #define __USB_UIF_TOKEN 0x08
4768 .................... #define __USB_UIF_IDLE 0x10 4768 .................... #define __USB_UIF_IDLE 0x10
4769 .................... #define __USB_UIF_STALL 0x20 4769 .................... #define __USB_UIF_STALL 0x20
4770 .................... #define __USB_UIF_SOF 0x40 4770 .................... #define __USB_UIF_SOF 0x40
4771 .................... 4771 ....................
4772 .................... #if USB_USE_ERROR_COUNTER 4772 .................... #if USB_USE_ERROR_COUNTER
4773 .................... #define STANDARD_INTS __USB_UIF_STALL|__USB_UIF_IDLE|__USB_UIF_TOKEN|__USB_UIF_ACTIVE|__USB_UIF_ERROR|__USB_UIF_RESET 4773 .................... #define STANDARD_INTS __USB_UIF_STALL|__USB_UIF_IDLE|__USB_UIF_TOKEN|__USB_UIF_ACTIVE|__USB_UIF_ERROR|__USB_UIF_RESET
4774 .................... #else 4774 .................... #else
4775 .................... #define STANDARD_INTS __USB_UIF_STALL|__USB_UIF_IDLE|__USB_UIF_TOKEN|__USB_UIF_ACTIVE|__USB_UIF_RESET 4775 .................... #define STANDARD_INTS __USB_UIF_STALL|__USB_UIF_IDLE|__USB_UIF_TOKEN|__USB_UIF_ACTIVE|__USB_UIF_RESET
4776 .................... #endif 4776 .................... #endif
4777 .................... 4777 ....................
4778 .................... #define __USB_UCFG_UTEYE 0x80 4778 .................... #define __USB_UCFG_UTEYE 0x80
4779 .................... #if defined(__USB_4550__) 4779 .................... #if defined(__USB_4550__)
4780 .................... #define __USB_UCFG_UOEMON 0x40 4780 .................... #define __USB_UCFG_UOEMON 0x40
4781 .................... #endif 4781 .................... #endif
4782 .................... #define __USB_UCFG_UPUEN 0x10 4782 .................... #define __USB_UCFG_UPUEN 0x10
4783 .................... #define __USB_UCFG_UTRDIS 0x08 4783 .................... #define __USB_UCFG_UTRDIS 0x08
4784 .................... #define __USB_UCFG_FSEN 0x04 4784 .................... #define __USB_UCFG_FSEN 0x04
4785 .................... 4785 ....................
4786 .................... #if USB_USE_FULL_SPEED 4786 .................... #if USB_USE_FULL_SPEED
4787 .................... #define __UCFG_VAL_ENABLED__ (__USB_UCFG_UPUEN | __USB_UCFG_FSEN | USB_PING_PONG_MODE) 4787 .................... #define __UCFG_VAL_ENABLED__ (__USB_UCFG_UPUEN | __USB_UCFG_FSEN | USB_PING_PONG_MODE)
4788 .................... #else 4788 .................... #else
4789 .................... #define __UCFG_VAL_ENABLED__ (__USB_UCFG_UPUEN | USB_PING_PONG_MODE); 4789 .................... #define __UCFG_VAL_ENABLED__ (__USB_UCFG_UPUEN | USB_PING_PONG_MODE);
4790 .................... #endif 4790 .................... #endif
4791 .................... 4791 ....................
4792 .................... #define __UCFG_VAL_DISABLED__ 0x08 4792 .................... #define __UCFG_VAL_DISABLED__ 0x08
4793 .................... 4793 ....................
4794 .................... int8 __setup_0_tx_size; 4794 .................... int8 __setup_0_tx_size;
4795 .................... 4795 ....................
4796 .................... //interrupt handler, specific to PIC18Fxx5x peripheral only 4796 .................... //interrupt handler, specific to PIC18Fxx5x peripheral only
4797 .................... void usb_handle_interrupt(); 4797 .................... void usb_handle_interrupt();
4798 .................... void usb_isr_rst(); 4798 .................... void usb_isr_rst();
4799 .................... void usb_isr_uerr(); 4799 .................... void usb_isr_uerr();
4800 .................... void usb_isr_sof(void); 4800 .................... void usb_isr_sof(void);
4801 .................... void usb_isr_activity(); 4801 .................... void usb_isr_activity();
4802 .................... void usb_isr_uidle(); 4802 .................... void usb_isr_uidle();
4803 .................... void usb_isr_tok_dne(); 4803 .................... void usb_isr_tok_dne();
4804 .................... void usb_isr_stall(void); 4804 .................... void usb_isr_stall(void);
4805 .................... void usb_init_ep0_setup(void); 4805 .................... void usb_init_ep0_setup(void);
4806 .................... 4806 ....................
4807 .................... //// BEGIN User Functions: 4807 .................... //// BEGIN User Functions:
4808 .................... 4808 ....................
4809 .................... // see usb_hw_layer.h for more documentation 4809 .................... // see usb_hw_layer.h for more documentation
4810 .................... int1 usb_kbhit(int8 en) 4810 .................... int1 usb_kbhit(int8 en)
4811 .................... { 4811 .................... {
4812 .................... return((UEP(en)!=ENDPT_DISABLED)&&(!bit_test(EP_BDxST_O(en),7))); 4812 .................... return((UEP(en)!=ENDPT_DISABLED)&&(!bit_test(EP_BDxST_O(en),7)));
4813 .................... } 4813 .................... }
4814 .................... 4814 ....................
4815 .................... // see usb_hw_layer.h for documentation 4815 .................... // see usb_hw_layer.h for documentation
4816 .................... int1 usb_tbe(int8 en) 4816 .................... int1 usb_tbe(int8 en)
4817 .................... { 4817 .................... {
4818 .................... return((UEP(en)!=ENDPT_DISABLED)&&(!bit_test(EP_BDxST_I(en),7))); 4818 .................... return((UEP(en)!=ENDPT_DISABLED)&&(!bit_test(EP_BDxST_I(en),7)));
4819 * 4819 *
4820 0D06: CLRF 03 4820 0D06: CLRF 03
4821 0D08: MOVLB 7 4821 0D08: MOVLB 7
4822 0D0A: MOVF x47,W 4822 0D0A: MOVF x47,W
4823 0D0C: ADDLW 70 4823 0D0C: ADDLW 70
4824 0D0E: MOVWF FE9 4824 0D0E: MOVWF FE9
4825 0D10: MOVLW 0F 4825 0D10: MOVLW 0F
4826 0D12: ADDWFC 03,W 4826 0D12: ADDWFC 03,W
4827 0D14: MOVWF FEA 4827 0D14: MOVWF FEA
4828 0D16: MOVF FEF,F 4828 0D16: MOVF FEF,F
4829 0D18: BZ 0D50 4829 0D18: BZ 0D50
4830 0D1A: CLRF x49 4830 0D1A: CLRF x49
4831 0D1C: MOVFF 747,748 4831 0D1C: MOVFF 747,748
4832 0D20: CLRF x4B 4832 0D20: CLRF x4B
4833 0D22: MOVLW 08 4833 0D22: MOVLW 08
4834 0D24: MOVWF x4A 4834 0D24: MOVWF x4A
4835 0D26: MOVLB 0 4835 0D26: MOVLB 0
4836 0D28: CALL 02BA 4836 0D28: CALL 02BA
4837 0D2C: MOVFF 02,749 4837 0D2C: MOVFF 02,749
4838 0D30: MOVFF 01,748 4838 0D30: MOVFF 01,748
4839 0D34: MOVLW 04 4839 0D34: MOVLW 04
4840 0D36: MOVLB 7 4840 0D36: MOVLB 7
4841 0D38: ADDWF x48,F 4841 0D38: ADDWF x48,F
4842 0D3A: MOVLW 00 4842 0D3A: MOVLW 00
4843 0D3C: ADDWFC x49,F 4843 0D3C: ADDWFC x49,F
4844 0D3E: MOVFF 748,FE9 4844 0D3E: MOVFF 748,FE9
4845 0D42: MOVLW 04 4845 0D42: MOVLW 04
4846 0D44: ADDWF x49,W 4846 0D44: ADDWF x49,W
4847 0D46: MOVWF FEA 4847 0D46: MOVWF FEA
4848 0D48: MOVFF FEF,748 4848 0D48: MOVFF FEF,748
4849 0D4C: BTFSS x48.7 4849 0D4C: BTFSS x48.7
4850 0D4E: BRA 0D54 4850 0D4E: BRA 0D54
4851 0D50: MOVLW 00 4851 0D50: MOVLW 00
4852 0D52: BRA 0D56 4852 0D52: BRA 0D56
4853 0D54: MOVLW 01 4853 0D54: MOVLW 01
4854 0D56: MOVWF 01 4854 0D56: MOVWF 01
4855 .................... } 4855 .................... }
4856 0D58: MOVLB 0 4856 0D58: MOVLB 0
4857 0D5A: RETLW 00 4857 0D5A: RETLW 00
4858 .................... 4858 ....................
4859 .................... // see usb_hw_layer.h for documentation 4859 .................... // see usb_hw_layer.h for documentation
4860 .................... void usb_detach(void) 4860 .................... void usb_detach(void)
4861 .................... { 4861 .................... {
4862 .................... UCON = 0; //disable USB hardware 4862 .................... UCON = 0; //disable USB hardware
4863 * 4863 *
4864 12F4: CLRF F6D 4864 12F4: CLRF F6D
4865 .................... UIE = 0; //disable USB interrupts 4865 .................... UIE = 0; //disable USB interrupts
4866 12F6: CLRF F69 4866 12F6: CLRF F69
4867 .................... UCFG = __UCFG_VAL_DISABLED__; 4867 .................... UCFG = __UCFG_VAL_DISABLED__;
4868 12F8: MOVLW 08 4868 12F8: MOVLW 08
4869 12FA: MOVWF F6F 4869 12FA: MOVWF F6F
4870 .................... 4870 ....................
4871 .................... // set D+/D- to inputs 4871 .................... // set D+/D- to inputs
4872 .................... #if defined(__USB_87J50__) 4872 .................... #if defined(__USB_87J50__)
4873 .................... set_tris_f(get_tris_f() | 0x18); 4873 .................... set_tris_f(get_tris_f() | 0x18);
4874 .................... #elif defined(__USB_K50__) 4874 .................... #elif defined(__USB_K50__)
4875 .................... set_tris_a(get_tris_a() | 0x3); 4875 .................... set_tris_a(get_tris_a() | 0x3);
4876 .................... #else 4876 .................... #else
4877 .................... set_tris_c(get_tris_c() | 0x30); 4877 .................... set_tris_c(get_tris_c() | 0x30);
4878 12FC: MOVF F94,W 4878 12FC: MOVF F94,W
4879 12FE: IORLW 30 4879 12FE: IORLW 30
4880 1300: MOVLB 6 4880 1300: MOVLB 6
4881 1302: MOVWF F94 4881 1302: MOVWF F94
4882 .................... #endif 4882 .................... #endif
4883 .................... 4883 ....................
4884 .................... usb_state = USB_STATE_DETACHED; 4884 .................... usb_state = USB_STATE_DETACHED;
4885 1304: CLRF 24 4885 1304: CLRF 24
4886 1306: CLRF 18 4886 1306: CLRF 18
4887 1308: BTFSC FF2.7 4887 1308: BTFSC FF2.7
4888 130A: BSF 18.7 4888 130A: BSF 18.7
4889 130C: BCF FF2.7 4889 130C: BCF FF2.7
4890 .................... 4890 ....................
4891 .................... usb_token_reset(); //clear the chapter9 stack 4891 .................... usb_token_reset(); //clear the chapter9 stack
4892 130E: MOVLB 0 4892 130E: MOVLB 0
4893 1310: CALL 037E 4893 1310: CALL 037E
4894 1314: BTFSC 18.7 4894 1314: BTFSC 18.7
4895 1316: BSF FF2.7 4895 1316: BSF FF2.7
4896 .................... //__usb_kbhit_status=0; 4896 .................... //__usb_kbhit_status=0;
4897 .................... } 4897 .................... }
4898 1318: GOTO 131E (RETURN) 4898 1318: GOTO 131E (RETURN)
4899 .................... 4899 ....................
4900 .................... // see usb_hw_layer.h for documentation 4900 .................... // see usb_hw_layer.h for documentation
4901 .................... void usb_attach(void) 4901 .................... void usb_attach(void)
4902 .................... { 4902 .................... {
4903 * 4903 *
4904 1322: CLRF 18 4904 1322: CLRF 18
4905 1324: BTFSC FF2.7 4905 1324: BTFSC FF2.7
4906 1326: BSF 18.7 4906 1326: BSF 18.7
4907 1328: BCF FF2.7 4907 1328: BCF FF2.7
4908 .................... usb_token_reset(); 4908 .................... usb_token_reset();
4909 132A: CALL 037E 4909 132A: CALL 037E
4910 132E: BTFSC 18.7 4910 132E: BTFSC 18.7
4911 1330: BSF FF2.7 4911 1330: BSF FF2.7
4912 .................... UCON = 0; 4912 .................... UCON = 0;
4913 1332: CLRF F6D 4913 1332: CLRF F6D
4914 .................... UCFG = __UCFG_VAL_ENABLED__; 4914 .................... UCFG = __UCFG_VAL_ENABLED__;
4915 1334: MOVLW 14 4915 1334: MOVLW 14
4916 1336: MOVWF F6F 4916 1336: MOVWF F6F
4917 .................... UIE = 0; // Mask all USB interrupts 4917 .................... UIE = 0; // Mask all USB interrupts
4918 1338: CLRF F69 4918 1338: CLRF F69
4919 .................... UCON_USBEN = 1; // Enable module & attach to bus 4919 .................... UCON_USBEN = 1; // Enable module & attach to bus
4920 133A: BSF F6D.3 4920 133A: BSF F6D.3
4921 .................... usb_state = USB_STATE_ATTACHED; // Defined in usbmmap.c & .h 4921 .................... usb_state = USB_STATE_ATTACHED; // Defined in usbmmap.c & .h
4922 133C: MOVLW 01 4922 133C: MOVLW 01
4923 133E: MOVWF 24 4923 133E: MOVWF 24
4924 .................... } 4924 .................... }
4925 1340: GOTO 134A (RETURN) 4925 1340: GOTO 134A (RETURN)
4926 .................... 4926 ....................
4927 .................... // see usb_hw_layer.h for documentation 4927 .................... // see usb_hw_layer.h for documentation
4928 .................... void usb_init_cs(void) 4928 .................... void usb_init_cs(void)
4929 .................... { 4929 .................... {
4930 .................... usb_detach(); 4930 .................... usb_detach();
4931 * 4931 *
4932 131C: BRA 12F4 4932 131C: BRA 12F4
4933 .................... } 4933 .................... }
4934 131E: GOTO 136A (RETURN) 4934 131E: GOTO 136A (RETURN)
4935 .................... 4935 ....................
4936 .................... // see usb_hw_layer.h for documentation 4936 .................... // see usb_hw_layer.h for documentation
4937 .................... void usb_task(void) 4937 .................... void usb_task(void)
4938 .................... { 4938 .................... {
4939 .................... if (usb_attached()) 4939 .................... if (usb_attached())
4940 .................... { 4940 .................... {
4941 .................... if (UCON_USBEN==0) 4941 .................... if (UCON_USBEN==0)
4942 * 4942 *
4943 1344: BTFSC F6D.3 4943 1344: BTFSC F6D.3
4944 1346: BRA 134A 4944 1346: BRA 134A
4945 .................... { 4945 .................... {
4946 .................... debug_usb(debug_putc, "\r\n\nUSB TASK: ATTACH"); 4946 .................... debug_usb(debug_putc, "\r\n\nUSB TASK: ATTACH");
4947 .................... usb_attach(); 4947 .................... usb_attach();
4948 1348: BRA 1322 4948 1348: BRA 1322
4949 .................... } 4949 .................... }
4950 .................... } 4950 .................... }
4951 .................... else 4951 .................... else
4952 .................... { 4952 .................... {
4953 .................... if (UCON_USBEN==1) 4953 .................... if (UCON_USBEN==1)
4954 .................... { 4954 .................... {
4955 .................... debug_usb(debug_putc, "\r\n\nUSB TASK: DE-ATTACH"); 4955 .................... debug_usb(debug_putc, "\r\n\nUSB TASK: DE-ATTACH");
4956 .................... usb_detach(); 4956 .................... usb_detach();
4957 .................... } 4957 .................... }
4958 .................... } 4958 .................... }
4959 .................... 4959 ....................
4960 .................... if ((usb_state == USB_STATE_ATTACHED)&&(!UCON_SE0)) 4960 .................... if ((usb_state == USB_STATE_ATTACHED)&&(!UCON_SE0))
4961 134A: DECFSZ 24,W 4961 134A: DECFSZ 24,W
4962 134C: BRA 1364 4962 134C: BRA 1364
4963 134E: BTFSC F6D.5 4963 134E: BTFSC F6D.5
4964 1350: BRA 1364 4964 1350: BRA 1364
4965 .................... { 4965 .................... {
4966 .................... UIR=0; 4966 .................... UIR=0;
4967 1352: CLRF F68 4967 1352: CLRF F68
4968 .................... UIE=0; 4968 .................... UIE=0;
4969 1354: CLRF F69 4969 1354: CLRF F69
4970 .................... enable_interrupts(INT_USB); 4970 .................... enable_interrupts(INT_USB);
4971 1356: BSF FA0.5 4971 1356: BSF FA0.5
4972 .................... enable_interrupts(GLOBAL); 4972 .................... enable_interrupts(GLOBAL);
4973 1358: MOVLW C0 4973 1358: MOVLW C0
4974 135A: IORWF FF2,F 4974 135A: IORWF FF2,F
4975 .................... UIE=__USB_UIF_IDLE | __USB_UIF_RESET; //enable IDLE and RESET USB ISR 4975 .................... UIE=__USB_UIF_IDLE | __USB_UIF_RESET; //enable IDLE and RESET USB ISR
4976 135C: MOVLW 11 4976 135C: MOVLW 11
4977 135E: MOVWF F69 4977 135E: MOVWF F69
4978 .................... usb_state=USB_STATE_POWERED; 4978 .................... usb_state=USB_STATE_POWERED;
4979 1360: MOVLW 02 4979 1360: MOVLW 02
4980 1362: MOVWF 24 4980 1362: MOVWF 24
4981 .................... debug_usb(debug_putc, "\r\n\nUSB TASK: POWERED"); 4981 .................... debug_usb(debug_putc, "\r\n\nUSB TASK: POWERED");
4982 .................... } 4982 .................... }
4983 .................... } 4983 .................... }
4984 1364: GOTO 136C (RETURN) 4984 1364: GOTO 136C (RETURN)
4985 .................... 4985 ....................
4986 .................... // see usb_hw_layer.h for documentation 4986 .................... // see usb_hw_layer.h for documentation
4987 .................... void usb_init(void) 4987 .................... void usb_init(void)
4988 .................... { 4988 .................... {
4989 .................... usb_init_cs(); 4989 .................... usb_init_cs();
4990 1368: BRA 131C 4990 1368: BRA 131C
4991 .................... 4991 ....................
4992 .................... do 4992 .................... do
4993 .................... { 4993 .................... {
4994 .................... usb_task(); 4994 .................... usb_task();
4995 136A: BRA 1344 4995 136A: BRA 1344
4996 .................... } while (usb_state != USB_STATE_POWERED); 4996 .................... } while (usb_state != USB_STATE_POWERED);
4997 136C: MOVF 24,W 4997 136C: MOVF 24,W
4998 136E: SUBLW 02 4998 136E: SUBLW 02
4999 1370: BNZ 136A 4999 1370: BNZ 136A
5000 .................... } 5000 .................... }
5001 1372: GOTO 1FE4 (RETURN) 5001 1372: GOTO 1FE4 (RETURN)
5002 .................... 5002 ....................
5003 .................... 5003 ....................
5004 .................... // see pic18_usb.h for documentation 5004 .................... // see pic18_usb.h for documentation
5005 .................... int1 usb_flush_in(int8 endpoint, int16 len, USB_DTS_BIT tgl) 5005 .................... int1 usb_flush_in(int8 endpoint, int16 len, USB_DTS_BIT tgl)
5006 .................... { 5006 .................... {
5007 .................... int8 i; 5007 .................... int8 i;
5008 .................... 5008 ....................
5009 .................... debug_usb(debug_putc,"\r\nPUT %X %U %LU",endpoint, tgl, len); 5009 .................... debug_usb(debug_putc,"\r\nPUT %X %U %LU",endpoint, tgl, len);
5010 .................... 5010 ....................
5011 .................... if (usb_tbe(endpoint)) 5011 .................... if (usb_tbe(endpoint))
5012 * 5012 *
5013 0D5C: MOVFF 742,747 5013 0D5C: MOVFF 742,747
5014 0D60: RCALL 0D06 5014 0D60: RCALL 0D06
5015 0D62: MOVF 01,F 5015 0D62: MOVF 01,F
5016 0D64: BTFSC FD8.2 5016 0D64: BTFSC FD8.2
5017 0D66: BRA 0E74 5017 0D66: BRA 0E74
5018 .................... { 5018 .................... {
5019 .................... EP_BDxCNT_I(endpoint)=len; 5019 .................... EP_BDxCNT_I(endpoint)=len;
5020 0D68: MOVLB 7 5020 0D68: MOVLB 7
5021 0D6A: CLRF x49 5021 0D6A: CLRF x49
5022 0D6C: MOVFF 742,748 5022 0D6C: MOVFF 742,748
5023 0D70: CLRF x4B 5023 0D70: CLRF x4B
5024 0D72: MOVLW 08 5024 0D72: MOVLW 08
5025 0D74: MOVWF x4A 5025 0D74: MOVWF x4A
5026 0D76: MOVLB 0 5026 0D76: MOVLB 0
5027 0D78: CALL 02BA 5027 0D78: CALL 02BA
5028 0D7C: MOVFF 02,748 5028 0D7C: MOVFF 02,748
5029 0D80: MOVFF 01,747 5029 0D80: MOVFF 01,747
5030 0D84: MOVLW 04 5030 0D84: MOVLW 04
5031 0D86: MOVLB 7 5031 0D86: MOVLB 7
5032 0D88: ADDWF x47,F 5032 0D88: ADDWF x47,F
5033 0D8A: MOVLW 00 5033 0D8A: MOVLW 00
5034 0D8C: ADDWFC x48,F 5034 0D8C: ADDWFC x48,F
5035 0D8E: MOVLW 01 5035 0D8E: MOVLW 01
5036 0D90: ADDWF x47,W 5036 0D90: ADDWF x47,W
5037 0D92: MOVWF 01 5037 0D92: MOVWF 01
5038 0D94: MOVLW 00 5038 0D94: MOVLW 00
5039 0D96: ADDWFC x48,W 5039 0D96: ADDWFC x48,W
5040 0D98: MOVWF 03 5040 0D98: MOVWF 03
5041 0D9A: MOVFF 01,FE9 5041 0D9A: MOVFF 01,FE9
5042 0D9E: MOVLW 04 5042 0D9E: MOVLW 04
5043 0DA0: ADDWF 03,W 5043 0DA0: ADDWF 03,W
5044 0DA2: MOVWF FEA 5044 0DA2: MOVWF FEA
5045 0DA4: MOVFF 743,FEF 5045 0DA4: MOVFF 743,FEF
5046 .................... 5046 ....................
5047 .................... debug_display_ram(len, EP_BDxADR_I(endpoint)); 5047 .................... debug_display_ram(len, EP_BDxADR_I(endpoint));
5048 .................... 5048 ....................
5049 .................... #if USB_IGNORE_TX_DTS 5049 .................... #if USB_IGNORE_TX_DTS
5050 .................... i=0x80; 5050 .................... i=0x80;
5051 .................... #else 5051 .................... #else
5052 .................... if (tgl == USB_DTS_TOGGLE) 5052 .................... if (tgl == USB_DTS_TOGGLE)
5053 0DA8: MOVF x45,W 5053 0DA8: MOVF x45,W
5054 0DAA: SUBLW 02 5054 0DAA: SUBLW 02
5055 0DAC: BNZ 0DEE 5055 0DAC: BNZ 0DEE
5056 .................... { 5056 .................... {
5057 .................... i = EP_BDxST_I(endpoint); 5057 .................... i = EP_BDxST_I(endpoint);
5058 0DAE: CLRF x49 5058 0DAE: CLRF x49
5059 0DB0: MOVFF 742,748 5059 0DB0: MOVFF 742,748
5060 0DB4: CLRF x4B 5060 0DB4: CLRF x4B
5061 0DB6: MOVLW 08 5061 0DB6: MOVLW 08
5062 0DB8: MOVWF x4A 5062 0DB8: MOVWF x4A
5063 0DBA: MOVLB 0 5063 0DBA: MOVLB 0
5064 0DBC: CALL 02BA 5064 0DBC: CALL 02BA
5065 0DC0: MOVFF 02,748 5065 0DC0: MOVFF 02,748
5066 0DC4: MOVFF 01,747 5066 0DC4: MOVFF 01,747
5067 0DC8: MOVLW 04 5067 0DC8: MOVLW 04
5068 0DCA: MOVLB 7 5068 0DCA: MOVLB 7
5069 0DCC: ADDWF x47,F 5069 0DCC: ADDWF x47,F
5070 0DCE: MOVLW 00 5070 0DCE: MOVLW 00
5071 0DD0: ADDWFC x48,F 5071 0DD0: ADDWFC x48,F
5072 0DD2: MOVFF 747,FE9 5072 0DD2: MOVFF 747,FE9
5073 0DD6: MOVLW 04 5073 0DD6: MOVLW 04
5074 0DD8: ADDWF x48,W 5074 0DD8: ADDWF x48,W
5075 0DDA: MOVWF FEA 5075 0DDA: MOVWF FEA
5076 0DDC: MOVFF FEF,746 5076 0DDC: MOVFF FEF,746
5077 .................... if (bit_test(i,6)) 5077 .................... if (bit_test(i,6))
5078 0DE0: BTFSS x46.6 5078 0DE0: BTFSS x46.6
5079 0DE2: BRA 0DE8 5079 0DE2: BRA 0DE8
5080 .................... tgl = USB_DTS_DATA0; //was DATA1, goto DATA0 5080 .................... tgl = USB_DTS_DATA0; //was DATA1, goto DATA0
5081 0DE4: CLRF x45 5081 0DE4: CLRF x45
5082 .................... else 5082 .................... else
5083 0DE6: BRA 0DEC 5083 0DE6: BRA 0DEC
5084 .................... tgl = USB_DTS_DATA1; //was DATA0, goto DATA1 5084 .................... tgl = USB_DTS_DATA1; //was DATA0, goto DATA1
5085 0DE8: MOVLW 01 5085 0DE8: MOVLW 01
5086 0DEA: MOVWF x45 5086 0DEA: MOVWF x45
5087 .................... } 5087 .................... }
5088 .................... else if (tgl == USB_DTS_USERX) 5088 .................... else if (tgl == USB_DTS_USERX)
5089 0DEC: BRA 0E22 5089 0DEC: BRA 0E22
5090 0DEE: MOVF x45,W 5090 0DEE: MOVF x45,W
5091 0DF0: SUBLW 04 5091 0DF0: SUBLW 04
5092 0DF2: BNZ 0E22 5092 0DF2: BNZ 0E22
5093 .................... { 5093 .................... {
5094 .................... i = EP_BDxST_O(endpoint); 5094 .................... i = EP_BDxST_O(endpoint);
5095 0DF4: CLRF x49 5095 0DF4: CLRF x49
5096 0DF6: MOVFF 742,748 5096 0DF6: MOVFF 742,748
5097 0DFA: CLRF x4B 5097 0DFA: CLRF x4B
5098 0DFC: MOVLW 08 5098 0DFC: MOVLW 08
5099 0DFE: MOVWF x4A 5099 0DFE: MOVWF x4A
5100 0E00: MOVLB 0 5100 0E00: MOVLB 0
5101 0E02: CALL 02BA 5101 0E02: CALL 02BA
5102 0E06: MOVLB 7 5102 0E06: MOVLB 7
5103 0E08: MOVFF 01,FE9 5103 0E08: MOVFF 01,FE9
5104 0E0C: MOVLW 04 5104 0E0C: MOVLW 04
5105 0E0E: ADDWF 02,W 5105 0E0E: ADDWF 02,W
5106 0E10: MOVWF FEA 5106 0E10: MOVWF FEA
5107 0E12: MOVFF FEF,746 5107 0E12: MOVFF FEF,746
5108 .................... if (bit_test(i,6)) 5108 .................... if (bit_test(i,6))
5109 0E16: BTFSS x46.6 5109 0E16: BTFSS x46.6
5110 0E18: BRA 0E20 5110 0E18: BRA 0E20
5111 .................... tgl = USB_DTS_DATA1; 5111 .................... tgl = USB_DTS_DATA1;
5112 0E1A: MOVLW 01 5112 0E1A: MOVLW 01
5113 0E1C: MOVWF x45 5113 0E1C: MOVWF x45
5114 .................... else 5114 .................... else
5115 0E1E: BRA 0E22 5115 0E1E: BRA 0E22
5116 .................... tgl = USB_DTS_DATA0; 5116 .................... tgl = USB_DTS_DATA0;
5117 0E20: CLRF x45 5117 0E20: CLRF x45
5118 .................... } 5118 .................... }
5119 .................... if (tgl == USB_DTS_DATA1) 5119 .................... if (tgl == USB_DTS_DATA1)
5120 0E22: DECFSZ x45,W 5120 0E22: DECFSZ x45,W
5121 0E24: BRA 0E2C 5121 0E24: BRA 0E2C
5122 .................... i=0xC8; //DATA1, UOWN 5122 .................... i=0xC8; //DATA1, UOWN
5123 0E26: MOVLW C8 5123 0E26: MOVLW C8
5124 0E28: MOVWF x46 5124 0E28: MOVWF x46
5125 .................... else //if (tgl == USB_DTS_DATA0) 5125 .................... else //if (tgl == USB_DTS_DATA0)
5126 0E2A: BRA 0E30 5126 0E2A: BRA 0E30
5127 .................... i=0x88; //DATA0, UOWN 5127 .................... i=0x88; //DATA0, UOWN
5128 0E2C: MOVLW 88 5128 0E2C: MOVLW 88
5129 0E2E: MOVWF x46 5129 0E2E: MOVWF x46
5130 .................... #endif 5130 .................... #endif
5131 .................... 5131 ....................
5132 .................... //set BC8 and BC9 5132 .................... //set BC8 and BC9
5133 .................... if (bit_test(len,8)) {bit_set(i,0);} 5133 .................... if (bit_test(len,8)) {bit_set(i,0);}
5134 0E30: BTFSC x44.0 5134 0E30: BTFSC x44.0
5135 0E32: BSF x46.0 5135 0E32: BSF x46.0
5136 .................... if (bit_test(len,9)) {bit_set(i,1);} 5136 .................... if (bit_test(len,9)) {bit_set(i,1);}
5137 0E34: BTFSC x44.1 5137 0E34: BTFSC x44.1
5138 0E36: BSF x46.1 5138 0E36: BSF x46.1
5139 .................... 5139 ....................
5140 .................... debug_usb(debug_putc, " %X", i); 5140 .................... debug_usb(debug_putc, " %X", i);
5141 .................... 5141 ....................
5142 .................... EP_BDxST_I(endpoint) = i;//save changes 5142 .................... EP_BDxST_I(endpoint) = i;//save changes
5143 0E38: CLRF x49 5143 0E38: CLRF x49
5144 0E3A: MOVFF 742,748 5144 0E3A: MOVFF 742,748
5145 0E3E: CLRF x4B 5145 0E3E: CLRF x4B
5146 0E40: MOVLW 08 5146 0E40: MOVLW 08
5147 0E42: MOVWF x4A 5147 0E42: MOVWF x4A
5148 0E44: MOVLB 0 5148 0E44: MOVLB 0
5149 0E46: CALL 02BA 5149 0E46: CALL 02BA
5150 0E4A: MOVFF 02,748 5150 0E4A: MOVFF 02,748
5151 0E4E: MOVFF 01,747 5151 0E4E: MOVFF 01,747
5152 0E52: MOVLW 04 5152 0E52: MOVLW 04
5153 0E54: MOVLB 7 5153 0E54: MOVLB 7
5154 0E56: ADDWF x47,F 5154 0E56: ADDWF x47,F
5155 0E58: MOVLW 00 5155 0E58: MOVLW 00
5156 0E5A: ADDWFC x48,F 5156 0E5A: ADDWFC x48,F
5157 0E5C: MOVFF 747,FE9 5157 0E5C: MOVFF 747,FE9
5158 0E60: MOVLW 04 5158 0E60: MOVLW 04
5159 0E62: ADDWF x48,W 5159 0E62: ADDWF x48,W
5160 0E64: MOVWF FEA 5160 0E64: MOVWF FEA
5161 0E66: MOVFF 746,FEF 5161 0E66: MOVFF 746,FEF
5162 .................... 5162 ....................
5163 .................... //putc('!'); 5163 .................... //putc('!');
5164 .................... 5164 ....................
5165 .................... return(1); 5165 .................... return(1);
5166 0E6A: MOVLW 01 5166 0E6A: MOVLW 01
5167 0E6C: MOVWF 01 5167 0E6C: MOVWF 01
5168 0E6E: BRA 0E7A 5168 0E6E: BRA 0E7A
5169 .................... } 5169 .................... }
5170 .................... else 5170 .................... else
5171 0E70: BRA 0E72 5171 0E70: BRA 0E72
5172 0E72: MOVLB 0 5172 0E72: MOVLB 0
5173 .................... { 5173 .................... {
5174 .................... //putc('_'); 5174 .................... //putc('_');
5175 .................... debug_usb(debug_putc,"\r\nPUT ERR"); 5175 .................... debug_usb(debug_putc,"\r\nPUT ERR");
5176 .................... } 5176 .................... }
5177 .................... return(0); 5177 .................... return(0);
5178 0E74: MOVLW 00 5178 0E74: MOVLW 00
5179 0E76: MOVWF 01 5179 0E76: MOVWF 01
5180 0E78: MOVLB 7 5180 0E78: MOVLB 7
5181 .................... } 5181 .................... }
5182 0E7A: MOVLB 0 5182 0E7A: MOVLB 0
5183 0E7C: RETLW 00 5183 0E7C: RETLW 00
5184 .................... 5184 ....................
5185 .................... // see usb_hw_layer.h for documentation 5185 .................... // see usb_hw_layer.h for documentation
5186 .................... int1 usb_put_packet(int8 endpoint, int8 * ptr, int16 len, USB_DTS_BIT tgl) 5186 .................... int1 usb_put_packet(int8 endpoint, int8 * ptr, int16 len, USB_DTS_BIT tgl)
5187 .................... { 5187 .................... {
5188 .................... int8 * buff_add; 5188 .................... int8 * buff_add;
5189 .................... 5189 ....................
5190 .................... if (usb_tbe(endpoint)) 5190 .................... if (usb_tbe(endpoint))
5191 * 5191 *
5192 0F88: MOVFF 73A,747 5192 0F88: MOVFF 73A,747
5193 0F8C: RCALL 0D06 5193 0F8C: RCALL 0D06
5194 0F8E: MOVF 01,F 5194 0F8E: MOVF 01,F
5195 0F90: BZ 1026 5195 0F90: BZ 1026
5196 .................... { 5196 .................... {
5197 .................... buff_add = EP_BDxADR_I(endpoint); 5197 .................... buff_add = EP_BDxADR_I(endpoint);
5198 0F92: MOVLB 7 5198 0F92: MOVLB 7
5199 0F94: CLRF x49 5199 0F94: CLRF x49
5200 0F96: MOVFF 73A,748 5200 0F96: MOVFF 73A,748
5201 0F9A: CLRF x4B 5201 0F9A: CLRF x4B
5202 0F9C: MOVLW 08 5202 0F9C: MOVLW 08
5203 0F9E: MOVWF x4A 5203 0F9E: MOVWF x4A
5204 0FA0: MOVLB 0 5204 0FA0: MOVLB 0
5205 0FA2: CALL 02BA 5205 0FA2: CALL 02BA
5206 0FA6: MOVFF 02,743 5206 0FA6: MOVFF 02,743
5207 0FAA: MOVFF 01,742 5207 0FAA: MOVFF 01,742
5208 0FAE: MOVLW 04 5208 0FAE: MOVLW 04
5209 0FB0: MOVLB 7 5209 0FB0: MOVLB 7
5210 0FB2: ADDWF x42,F 5210 0FB2: ADDWF x42,F
5211 0FB4: MOVLW 00 5211 0FB4: MOVLW 00
5212 0FB6: ADDWFC x43,F 5212 0FB6: ADDWFC x43,F
5213 0FB8: MOVLW 02 5213 0FB8: MOVLW 02
5214 0FBA: ADDWF x42,W 5214 0FBA: ADDWF x42,W
5215 0FBC: MOVWF 01 5215 0FBC: MOVWF 01
5216 0FBE: MOVLW 00 5216 0FBE: MOVLW 00
5217 0FC0: ADDWFC x43,W 5217 0FC0: ADDWFC x43,W
5218 0FC2: MOVWF 03 5218 0FC2: MOVWF 03
5219 0FC4: MOVFF 01,FE9 5219 0FC4: MOVFF 01,FE9
5220 0FC8: MOVLW 04 5220 0FC8: MOVLW 04
5221 0FCA: ADDWF 03,W 5221 0FCA: ADDWF 03,W
5222 0FCC: MOVWF FEA 5222 0FCC: MOVWF FEA
5223 0FCE: MOVFF FEC,03 5223 0FCE: MOVFF FEC,03
5224 0FD2: MOVF FED,F 5224 0FD2: MOVF FED,F
5225 0FD4: MOVFF FEF,740 5225 0FD4: MOVFF FEF,740
5226 0FD8: MOVFF 03,741 5226 0FD8: MOVFF 03,741
5227 .................... memcpy(buff_add, ptr, len); 5227 .................... memcpy(buff_add, ptr, len);
5228 0FDC: MOVFF 741,FEA 5228 0FDC: MOVFF 741,FEA
5229 0FE0: MOVFF 740,FE9 5229 0FE0: MOVFF 740,FE9
5230 0FE4: MOVFF 73C,FE2 5230 0FE4: MOVFF 73C,FE2
5231 0FE8: MOVFF 73B,FE1 5231 0FE8: MOVFF 73B,FE1
5232 0FEC: MOVFF 73E,02 5232 0FEC: MOVFF 73E,02
5233 0FF0: MOVFF 73D,01 5233 0FF0: MOVFF 73D,01
5234 0FF4: MOVF 01,F 5234 0FF4: MOVF 01,F
5235 0FF6: BZ 0FFC 5235 0FF6: BZ 0FFC
5236 0FF8: INCF 02,F 5236 0FF8: INCF 02,F
5237 0FFA: BRA 1000 5237 0FFA: BRA 1000
5238 0FFC: MOVF 02,F 5238 0FFC: MOVF 02,F
5239 0FFE: BZ 100C 5239 0FFE: BZ 100C
5240 1000: MOVFF FE6,FEE 5240 1000: MOVFF FE6,FEE
5241 1004: DECFSZ 01,F 5241 1004: DECFSZ 01,F
5242 1006: BRA 1000 5242 1006: BRA 1000
5243 1008: DECFSZ 02,F 5243 1008: DECFSZ 02,F
5244 100A: BRA 1000 5244 100A: BRA 1000
5245 .................... 5245 ....................
5246 .................... return(usb_flush_in(endpoint, len, tgl)); 5246 .................... return(usb_flush_in(endpoint, len, tgl));
5247 100C: MOVFF 73A,742 5247 100C: MOVFF 73A,742
5248 1010: MOVFF 73E,744 5248 1010: MOVFF 73E,744
5249 1014: MOVFF 73D,743 5249 1014: MOVFF 73D,743
5250 1018: MOVFF 73F,745 5250 1018: MOVFF 73F,745
5251 101C: MOVLB 0 5251 101C: MOVLB 0
5252 101E: RCALL 0D5C 5252 101E: RCALL 0D5C
5253 1020: MOVF 01,W 5253 1020: MOVF 01,W
5254 1022: BRA 102A 5254 1022: BRA 102A
5255 .................... } 5255 .................... }
5256 .................... else 5256 .................... else
5257 1024: BRA 1026 5257 1024: BRA 1026
5258 .................... { 5258 .................... {
5259 .................... //putc('-'); 5259 .................... //putc('-');
5260 .................... //printf("%X", EP_BDxST_I(endpoint)); 5260 .................... //printf("%X", EP_BDxST_I(endpoint));
5261 .................... debug_usb(debug_putc,"\r\nPUT ERR"); 5261 .................... debug_usb(debug_putc,"\r\nPUT ERR");
5262 .................... } 5262 .................... }
5263 .................... 5263 ....................
5264 .................... return(0); 5264 .................... return(0);
5265 1026: MOVLW 00 5265 1026: MOVLW 00
5266 1028: MOVWF 01 5266 1028: MOVWF 01
5267 .................... } 5267 .................... }
5268 102A: RETLW 00 5268 102A: RETLW 00
5269 .................... 5269 ....................
5270 .................... // see pic18_usb.h for documentation 5270 .................... // see pic18_usb.h for documentation
5271 .................... void usb_flush_out(int8 endpoint, USB_DTS_BIT tgl) 5271 .................... void usb_flush_out(int8 endpoint, USB_DTS_BIT tgl)
5272 .................... { 5272 .................... {
5273 .................... int8 i; 5273 .................... int8 i;
5274 .................... int16 len; 5274 .................... int16 len;
5275 .................... 5275 ....................
5276 .................... #if USB_IGNORE_RX_DTS 5276 .................... #if USB_IGNORE_RX_DTS
5277 .................... if (tgl == USB_DTS_STALL) 5277 .................... if (tgl == USB_DTS_STALL)
5278 .................... { 5278 .................... {
5279 .................... debug_usb(debug_putc, '*'); 5279 .................... debug_usb(debug_putc, '*');
5280 .................... EP_BDxCNT_O(endpoint) = 0x84; 5280 .................... EP_BDxCNT_O(endpoint) = 0x84;
5281 .................... EP_BDxST_I(endpoint) = 0x84; 5281 .................... EP_BDxST_I(endpoint) = 0x84;
5282 .................... return; 5282 .................... return;
5283 .................... } 5283 .................... }
5284 .................... else 5284 .................... else
5285 .................... i=0x80; 5285 .................... i=0x80;
5286 .................... #else 5286 .................... #else
5287 .................... i = EP_BDxST_O(endpoint); 5287 .................... i = EP_BDxST_O(endpoint);
5288 * 5288 *
5289 0BEA: MOVLB 7 5289 0BEA: MOVLB 7
5290 0BEC: CLRF x49 5290 0BEC: CLRF x49
5291 0BEE: MOVFF 6FD,748 5291 0BEE: MOVFF 6FD,748
5292 0BF2: CLRF x4B 5292 0BF2: CLRF x4B
5293 0BF4: MOVLW 08 5293 0BF4: MOVLW 08
5294 0BF6: MOVWF x4A 5294 0BF6: MOVWF x4A
5295 0BF8: MOVLB 0 5295 0BF8: MOVLB 0
5296 0BFA: CALL 02BA 5296 0BFA: CALL 02BA
5297 0BFE: MOVLB 7 5297 0BFE: MOVLB 7
5298 0C00: MOVFF 01,FE9 5298 0C00: MOVFF 01,FE9
5299 0C04: MOVLW 04 5299 0C04: MOVLW 04
5300 0C06: ADDWF 02,W 5300 0C06: ADDWF 02,W
5301 0C08: MOVWF FEA 5301 0C08: MOVWF FEA
5302 0C0A: MOVFF FEF,6FF 5302 0C0A: MOVFF FEF,6FF
5303 0C0E: MOVLB 6 5303 0C0E: MOVLB 6
5304 .................... if (tgl == USB_DTS_TOGGLE) 5304 .................... if (tgl == USB_DTS_TOGGLE)
5305 0C10: MOVF xFE,W 5305 0C10: MOVF xFE,W
5306 0C12: SUBLW 02 5306 0C12: SUBLW 02
5307 0C14: BNZ 0C22 5307 0C14: BNZ 0C22
5308 .................... { 5308 .................... {
5309 .................... if (bit_test(i,6)) 5309 .................... if (bit_test(i,6))
5310 0C16: BTFSS xFF.6 5310 0C16: BTFSS xFF.6
5311 0C18: BRA 0C1E 5311 0C18: BRA 0C1E
5312 .................... tgl = USB_DTS_DATA0; //was DATA1, goto DATA0 5312 .................... tgl = USB_DTS_DATA0; //was DATA1, goto DATA0
5313 0C1A: CLRF xFE 5313 0C1A: CLRF xFE
5314 .................... else 5314 .................... else
5315 0C1C: BRA 0C22 5315 0C1C: BRA 0C22
5316 .................... tgl = USB_DTS_DATA1; //was DATA0, goto DATA1 5316 .................... tgl = USB_DTS_DATA1; //was DATA0, goto DATA1
5317 0C1E: MOVLW 01 5317 0C1E: MOVLW 01
5318 0C20: MOVWF xFE 5318 0C20: MOVWF xFE
5319 .................... } 5319 .................... }
5320 .................... if (tgl == USB_DTS_STALL) 5320 .................... if (tgl == USB_DTS_STALL)
5321 0C22: MOVF xFE,W 5321 0C22: MOVF xFE,W
5322 0C24: SUBLW 03 5322 0C24: SUBLW 03
5323 0C26: BNZ 0C64 5323 0C26: BNZ 0C64
5324 .................... { 5324 .................... {
5325 .................... i = 0x84; 5325 .................... i = 0x84;
5326 0C28: MOVLW 84 5326 0C28: MOVLW 84
5327 0C2A: MOVWF xFF 5327 0C2A: MOVWF xFF
5328 .................... EP_BDxST_I(endpoint) = 0x84; //stall both in and out endpoints 5328 .................... EP_BDxST_I(endpoint) = 0x84; //stall both in and out endpoints
5329 0C2C: MOVLB 7 5329 0C2C: MOVLB 7
5330 0C2E: CLRF x49 5330 0C2E: CLRF x49
5331 0C30: MOVFF 6FD,748 5331 0C30: MOVFF 6FD,748
5332 0C34: CLRF x4B 5332 0C34: CLRF x4B
5333 0C36: MOVLW 08 5333 0C36: MOVLW 08
5334 0C38: MOVWF x4A 5334 0C38: MOVWF x4A
5335 0C3A: MOVLB 0 5335 0C3A: MOVLB 0
5336 0C3C: CALL 02BA 5336 0C3C: CALL 02BA
5337 0C40: MOVFF 02,703 5337 0C40: MOVFF 02,703
5338 0C44: MOVFF 01,702 5338 0C44: MOVFF 01,702
5339 0C48: MOVLW 04 5339 0C48: MOVLW 04
5340 0C4A: MOVLB 7 5340 0C4A: MOVLB 7
5341 0C4C: ADDWF x02,F 5341 0C4C: ADDWF x02,F
5342 0C4E: MOVLW 00 5342 0C4E: MOVLW 00
5343 0C50: ADDWFC x03,F 5343 0C50: ADDWFC x03,F
5344 0C52: MOVFF 702,FE9 5344 0C52: MOVFF 702,FE9
5345 0C56: MOVLW 04 5345 0C56: MOVLW 04
5346 0C58: ADDWF x03,W 5346 0C58: ADDWF x03,W
5347 0C5A: MOVWF FEA 5347 0C5A: MOVWF FEA
5348 0C5C: MOVLW 84 5348 0C5C: MOVLW 84
5349 0C5E: MOVWF FEF 5349 0C5E: MOVWF FEF
5350 .................... } 5350 .................... }
5351 .................... else if (tgl == USB_DTS_DATA1) 5351 .................... else if (tgl == USB_DTS_DATA1)
5352 0C60: BRA 0C74 5352 0C60: BRA 0C74
5353 0C62: MOVLB 6 5353 0C62: MOVLB 6
5354 0C64: DECFSZ xFE,W 5354 0C64: DECFSZ xFE,W
5355 0C66: BRA 0C6E 5355 0C66: BRA 0C6E
5356 .................... i = 0xC8; //DATA1, UOWN 5356 .................... i = 0xC8; //DATA1, UOWN
5357 0C68: MOVLW C8 5357 0C68: MOVLW C8
5358 0C6A: MOVWF xFF 5358 0C6A: MOVWF xFF
5359 .................... else //if (tgl == USB_DTS_DATA0) 5359 .................... else //if (tgl == USB_DTS_DATA0)
5360 0C6C: BRA 0C72 5360 0C6C: BRA 0C72
5361 .................... i = 0x88; //DATA0, UOWN 5361 .................... i = 0x88; //DATA0, UOWN
5362 0C6E: MOVLW 88 5362 0C6E: MOVLW 88
5363 0C70: MOVWF xFF 5363 0C70: MOVWF xFF
5364 0C72: MOVLB 7 5364 0C72: MOVLB 7
5365 .................... #endif 5365 .................... #endif
5366 .................... 5366 ....................
5367 .................... //bit_clear(__usb_kbhit_status,endpoint); 5367 .................... //bit_clear(__usb_kbhit_status,endpoint);
5368 .................... 5368 ....................
5369 .................... len = usb_ep_rx_size[endpoint]; 5369 .................... len = usb_ep_rx_size[endpoint];
5370 0C74: BCF FD8.0 5370 0C74: BCF FD8.0
5371 0C76: MOVLB 6 5371 0C76: MOVLB 6
5372 0C78: RLCF xFD,W 5372 0C78: RLCF xFD,W
5373 0C7A: CLRF 03 5373 0C7A: CLRF 03
5374 0C7C: MOVFF FF2,702 5374 0C7C: MOVFF FF2,702
5375 0C80: BCF FF2.7 5375 0C80: BCF FF2.7
5376 0C82: MOVLB 0 5376 0C82: MOVLB 0
5377 0C84: CALL 011A 5377 0C84: CALL 011A
5378 0C88: TBLRD*+ 5378 0C88: TBLRD*+
5379 0C8A: MOVFF FF5,03 5379 0C8A: MOVFF FF5,03
5380 0C8E: MOVLB 7 5380 0C8E: MOVLB 7
5381 0C90: BTFSC x02.7 5381 0C90: BTFSC x02.7
5382 0C92: BSF FF2.7 5382 0C92: BSF FF2.7
5383 0C94: MOVWF x00 5383 0C94: MOVWF x00
5384 0C96: MOVFF 03,701 5384 0C96: MOVFF 03,701
5385 .................... EP_BDxCNT_O(endpoint) = len; 5385 .................... EP_BDxCNT_O(endpoint) = len;
5386 0C9A: CLRF x49 5386 0C9A: CLRF x49
5387 0C9C: MOVFF 6FD,748 5387 0C9C: MOVFF 6FD,748
5388 0CA0: CLRF x4B 5388 0CA0: CLRF x4B
5389 0CA2: MOVLW 08 5389 0CA2: MOVLW 08
5390 0CA4: MOVWF x4A 5390 0CA4: MOVWF x4A
5391 0CA6: MOVLB 0 5391 0CA6: MOVLB 0
5392 0CA8: CALL 02BA 5392 0CA8: CALL 02BA
5393 0CAC: MOVFF 01,702 5393 0CAC: MOVFF 01,702
5394 0CB0: MOVLW 01 5394 0CB0: MOVLW 01
5395 0CB2: MOVLB 7 5395 0CB2: MOVLB 7
5396 0CB4: ADDWF 01,W 5396 0CB4: ADDWF 01,W
5397 0CB6: MOVWF 01 5397 0CB6: MOVWF 01
5398 0CB8: MOVLW 00 5398 0CB8: MOVLW 00
5399 0CBA: ADDWFC 02,W 5399 0CBA: ADDWFC 02,W
5400 0CBC: MOVWF 03 5400 0CBC: MOVWF 03
5401 0CBE: MOVFF 01,FE9 5401 0CBE: MOVFF 01,FE9
5402 0CC2: MOVLW 04 5402 0CC2: MOVLW 04
5403 0CC4: ADDWF 03,W 5403 0CC4: ADDWF 03,W
5404 0CC6: MOVWF FEA 5404 0CC6: MOVWF FEA
5405 0CC8: MOVFF 700,FEF 5405 0CC8: MOVFF 700,FEF
5406 .................... if (bit_test(len,8)) {bit_set(i,0);} 5406 .................... if (bit_test(len,8)) {bit_set(i,0);}
5407 0CCC: BTFSS x01.0 5407 0CCC: BTFSS x01.0
5408 0CCE: BRA 0CD6 5408 0CCE: BRA 0CD6
5409 0CD0: MOVLB 6 5409 0CD0: MOVLB 6
5410 0CD2: BSF xFF.0 5410 0CD2: BSF xFF.0
5411 0CD4: MOVLB 7 5411 0CD4: MOVLB 7
5412 .................... if (bit_test(len,9)) {bit_set(i,1);} 5412 .................... if (bit_test(len,9)) {bit_set(i,1);}
5413 0CD6: BTFSS x01.1 5413 0CD6: BTFSS x01.1
5414 0CD8: BRA 0CE0 5414 0CD8: BRA 0CE0
5415 0CDA: MOVLB 6 5415 0CDA: MOVLB 6
5416 0CDC: BSF xFF.1 5416 0CDC: BSF xFF.1
5417 0CDE: MOVLB 7 5417 0CDE: MOVLB 7
5418 .................... 5418 ....................
5419 .................... EP_BDxST_O(endpoint) = i; 5419 .................... EP_BDxST_O(endpoint) = i;
5420 0CE0: CLRF x49 5420 0CE0: CLRF x49
5421 0CE2: MOVFF 6FD,748 5421 0CE2: MOVFF 6FD,748
5422 0CE6: CLRF x4B 5422 0CE6: CLRF x4B
5423 0CE8: MOVLW 08 5423 0CE8: MOVLW 08
5424 0CEA: MOVWF x4A 5424 0CEA: MOVWF x4A
5425 0CEC: MOVLB 0 5425 0CEC: MOVLB 0
5426 0CEE: CALL 02BA 5426 0CEE: CALL 02BA
5427 0CF2: MOVLB 7 5427 0CF2: MOVLB 7
5428 0CF4: MOVFF 01,FE9 5428 0CF4: MOVFF 01,FE9
5429 0CF8: MOVLW 04 5429 0CF8: MOVLW 04
5430 0CFA: ADDWF 02,W 5430 0CFA: ADDWF 02,W
5431 0CFC: MOVWF FEA 5431 0CFC: MOVWF FEA
5432 0CFE: MOVFF 6FF,FEF 5432 0CFE: MOVFF 6FF,FEF
5433 .................... } 5433 .................... }
5434 0D02: MOVLB 0 5434 0D02: MOVLB 0
5435 0D04: RETLW 00 5435 0D04: RETLW 00
5436 .................... 5436 ....................
5437 .................... // see pic18_usb.h for documentation 5437 .................... // see pic18_usb.h for documentation
5438 .................... int16 usb_rx_packet_size(int8 endpoint) 5438 .................... int16 usb_rx_packet_size(int8 endpoint)
5439 .................... { 5439 .................... {
5440 .................... return(EP_BDxCNT_O(endpoint)); 5440 .................... return(EP_BDxCNT_O(endpoint));
5441 * 5441 *
5442 0EE6: MOVLB 7 5442 0EE6: MOVLB 7
5443 0EE8: CLRF x49 5443 0EE8: CLRF x49
5444 0EEA: MOVFF 6FE,748 5444 0EEA: MOVFF 6FE,748
5445 0EEE: CLRF x4B 5445 0EEE: CLRF x4B
5446 0EF0: MOVLW 08 5446 0EF0: MOVLW 08
5447 0EF2: MOVWF x4A 5447 0EF2: MOVWF x4A
5448 0EF4: MOVLB 0 5448 0EF4: MOVLB 0
5449 0EF6: CALL 02BA 5449 0EF6: CALL 02BA
5450 0EFA: MOVFF 02,700 5450 0EFA: MOVFF 02,700
5451 0EFE: MOVFF 01,6FF 5451 0EFE: MOVFF 01,6FF
5452 0F02: MOVLW 01 5452 0F02: MOVLW 01
5453 0F04: MOVLB 6 5453 0F04: MOVLB 6
5454 0F06: ADDWF 01,W 5454 0F06: ADDWF 01,W
5455 0F08: MOVWF 01 5455 0F08: MOVWF 01
5456 0F0A: MOVLW 00 5456 0F0A: MOVLW 00
5457 0F0C: MOVLB 7 5457 0F0C: MOVLB 7
5458 0F0E: ADDWFC 02,W 5458 0F0E: ADDWFC 02,W
5459 0F10: MOVWF 03 5459 0F10: MOVWF 03
5460 0F12: MOVFF 01,FE9 5460 0F12: MOVFF 01,FE9
5461 0F16: MOVLW 04 5461 0F16: MOVLW 04
5462 0F18: ADDWF 03,W 5462 0F18: ADDWF 03,W
5463 0F1A: MOVWF FEA 5463 0F1A: MOVWF FEA
5464 0F1C: CLRF 03 5464 0F1C: CLRF 03
5465 0F1E: MOVFF FEF,01 5465 0F1E: MOVFF FEF,01
5466 0F22: MOVFF 03,02 5466 0F22: MOVFF 03,02
5467 .................... } 5467 .................... }
5468 0F26: MOVLB 0 5468 0F26: MOVLB 0
5469 0F28: GOTO 0F3A (RETURN) 5469 0F28: GOTO 0F3A (RETURN)
5470 .................... 5470 ....................
5471 .................... /// END User Functions 5471 .................... /// END User Functions
5472 .................... 5472 ....................
5473 .................... 5473 ....................
5474 .................... /// BEGIN Hardware layer functions required by USB. 5474 .................... /// BEGIN Hardware layer functions required by USB.
5475 .................... 5475 ....................
5476 .................... /***************************************************************************** 5476 .................... /*****************************************************************************
5477 .................... /* usb_get_packet_buffer(endpoint, *ptr, max) 5477 .................... /* usb_get_packet_buffer(endpoint, *ptr, max)
5478 .................... /* 5478 .................... /*
5479 .................... /* Input: endpoint - endpoint to get data from 5479 .................... /* Input: endpoint - endpoint to get data from
5480 .................... /* ptr - where to save data to local PIC RAM 5480 .................... /* ptr - where to save data to local PIC RAM
5481 .................... /* max - max amount of data to receive from buffer 5481 .................... /* max - max amount of data to receive from buffer
5482 .................... /* 5482 .................... /*
5483 .................... /* Output: the amount of data taken from the buffer. 5483 .................... /* Output: the amount of data taken from the buffer.
5484 .................... /* 5484 .................... /*
5485 .................... /* Summary: Gets a packet of data from the USB buffer and puts into local PIC 5485 .................... /* Summary: Gets a packet of data from the USB buffer and puts into local PIC
5486 .................... /* RAM. 5486 .................... /* RAM.
5487 .................... /* Does not mark the endpoint as ready for more data. Once you are 5487 .................... /* Does not mark the endpoint as ready for more data. Once you are
5488 .................... /* done with data, call usb_flush_out() to mark the endpoint ready 5488 .................... /* done with data, call usb_flush_out() to mark the endpoint ready
5489 .................... /* to receive more data. 5489 .................... /* to receive more data.
5490 .................... /* 5490 .................... /*
5491 .................... /*****************************************************************************/ 5491 .................... /*****************************************************************************/
5492 .................... static int16 usb_get_packet_buffer(int8 endpoint, int8 *ptr, int16 max) 5492 .................... static int16 usb_get_packet_buffer(int8 endpoint, int8 *ptr, int16 max)
5493 .................... { 5493 .................... {
5494 .................... int8 * al; 5494 .................... int8 * al;
5495 .................... int8 st; 5495 .................... int8 st;
5496 .................... int16 i; 5496 .................... int16 i;
5497 .................... 5497 ....................
5498 .................... al = EP_BDxADR_O(endpoint); 5498 .................... al = EP_BDxADR_O(endpoint);
5499 .................... i = EP_BDxCNT_O(endpoint); 5499 .................... i = EP_BDxCNT_O(endpoint);
5500 .................... st = EP_BDxST_O(endpoint); 5500 .................... st = EP_BDxST_O(endpoint);
5501 .................... 5501 ....................
5502 .................... //read BC8 and BC9 5502 .................... //read BC8 and BC9
5503 .................... if (bit_test(st,0)) {bit_set(i,8);} 5503 .................... if (bit_test(st,0)) {bit_set(i,8);}
5504 .................... if (bit_test(st,1)) {bit_set(i,9);} 5504 .................... if (bit_test(st,1)) {bit_set(i,9);}
5505 .................... 5505 ....................
5506 .................... if (i < max) {max = i;} 5506 .................... if (i < max) {max = i;}
5507 .................... 5507 ....................
5508 .................... memcpy(ptr, al ,max); 5508 .................... memcpy(ptr, al ,max);
5509 .................... 5509 ....................
5510 .................... return(max); 5510 .................... return(max);
5511 .................... } 5511 .................... }
5512 .................... 5512 ....................
5513 .................... // see usb_hw_layer.h for documentation 5513 .................... // see usb_hw_layer.h for documentation
5514 .................... unsigned int16 usb_get_packet(int8 endpoint, int8 * ptr, unsigned int16 max) 5514 .................... unsigned int16 usb_get_packet(int8 endpoint, int8 * ptr, unsigned int16 max)
5515 .................... { 5515 .................... {
5516 .................... max = usb_get_packet_buffer(endpoint, ptr, max); 5516 .................... max = usb_get_packet_buffer(endpoint, ptr, max);
5517 .................... usb_flush_out(endpoint, USB_DTS_TOGGLE); 5517 .................... usb_flush_out(endpoint, USB_DTS_TOGGLE);
5518 .................... 5518 ....................
5519 .................... return(max); 5519 .................... return(max);
5520 .................... } 5520 .................... }
5521 .................... 5521 ....................
5522 .................... // see usb_hw_layer.h for documentation 5522 .................... // see usb_hw_layer.h for documentation
5523 .................... void usb_stall_ep(int8 endpoint) 5523 .................... void usb_stall_ep(int8 endpoint)
5524 .................... { 5524 .................... {
5525 .................... int1 direction; 5525 .................... int1 direction;
5526 .................... 5526 ....................
5527 .................... direction = bit_test(endpoint,7); 5527 .................... direction = bit_test(endpoint,7);
5528 * 5528 *
5529 09B4: MOVLB 6 5529 09B4: MOVLB 6
5530 09B6: BCF xFE.0 5530 09B6: BCF xFE.0
5531 09B8: BTFSC xFD.7 5531 09B8: BTFSC xFD.7
5532 09BA: BSF xFE.0 5532 09BA: BSF xFE.0
5533 .................... endpoint &= 0x7F; 5533 .................... endpoint &= 0x7F;
5534 09BC: BCF xFD.7 5534 09BC: BCF xFD.7
5535 .................... 5535 ....................
5536 .................... if (direction) 5536 .................... if (direction)
5537 09BE: BTFSS xFE.0 5537 09BE: BTFSS xFE.0
5538 09C0: BRA 09FC 5538 09C0: BRA 09FC
5539 .................... { 5539 .................... {
5540 .................... EP_BDxST_I(endpoint) = 0x84; 5540 .................... EP_BDxST_I(endpoint) = 0x84;
5541 09C2: MOVLB 7 5541 09C2: MOVLB 7
5542 09C4: CLRF x49 5542 09C4: CLRF x49
5543 09C6: MOVFF 6FD,748 5543 09C6: MOVFF 6FD,748
5544 09CA: CLRF x4B 5544 09CA: CLRF x4B
5545 09CC: MOVLW 08 5545 09CC: MOVLW 08
5546 09CE: MOVWF x4A 5546 09CE: MOVWF x4A
5547 09D0: MOVLB 0 5547 09D0: MOVLB 0
5548 09D2: RCALL 02BA 5548 09D2: RCALL 02BA
5549 09D4: MOVFF 02,700 5549 09D4: MOVFF 02,700
5550 09D8: MOVFF 01,6FF 5550 09D8: MOVFF 01,6FF
5551 09DC: MOVLW 04 5551 09DC: MOVLW 04
5552 09DE: MOVLB 6 5552 09DE: MOVLB 6
5553 09E0: ADDWF xFF,F 5553 09E0: ADDWF xFF,F
5554 09E2: MOVLW 00 5554 09E2: MOVLW 00
5555 09E4: MOVLB 7 5555 09E4: MOVLB 7
5556 09E6: ADDWFC x00,F 5556 09E6: ADDWFC x00,F
5557 09E8: MOVFF 6FF,FE9 5557 09E8: MOVFF 6FF,FE9
5558 09EC: MOVLW 04 5558 09EC: MOVLW 04
5559 09EE: MOVLB 7 5559 09EE: MOVLB 7
5560 09F0: ADDWF x00,W 5560 09F0: ADDWF x00,W
5561 09F2: MOVWF FEA 5561 09F2: MOVWF FEA
5562 09F4: MOVLW 84 5562 09F4: MOVLW 84
5563 09F6: MOVWF FEF 5563 09F6: MOVWF FEF
5564 .................... } 5564 .................... }
5565 .................... else 5565 .................... else
5566 09F8: BRA 0A1E 5566 09F8: BRA 0A1E
5567 09FA: MOVLB 6 5567 09FA: MOVLB 6
5568 .................... { 5568 .................... {
5569 .................... EP_BDxST_O(endpoint) = 0x84; 5569 .................... EP_BDxST_O(endpoint) = 0x84;
5570 09FC: MOVLB 7 5570 09FC: MOVLB 7
5571 09FE: CLRF x49 5571 09FE: CLRF x49
5572 0A00: MOVFF 6FD,748 5572 0A00: MOVFF 6FD,748
5573 0A04: CLRF x4B 5573 0A04: CLRF x4B
5574 0A06: MOVLW 08 5574 0A06: MOVLW 08
5575 0A08: MOVWF x4A 5575 0A08: MOVWF x4A
5576 0A0A: MOVLB 0 5576 0A0A: MOVLB 0
5577 0A0C: RCALL 02BA 5577 0A0C: RCALL 02BA
5578 0A0E: MOVFF 01,FE9 5578 0A0E: MOVFF 01,FE9
5579 0A12: MOVLW 04 5579 0A12: MOVLW 04
5580 0A14: MOVLB 7 5580 0A14: MOVLB 7
5581 0A16: ADDWF 02,W 5581 0A16: ADDWF 02,W
5582 0A18: MOVWF FEA 5582 0A18: MOVWF FEA
5583 0A1A: MOVLW 84 5583 0A1A: MOVLW 84
5584 0A1C: MOVWF FEF 5584 0A1C: MOVWF FEF
5585 .................... } 5585 .................... }
5586 .................... } 5586 .................... }
5587 0A1E: MOVLB 0 5587 0A1E: MOVLB 0
5588 0A20: GOTO 0AD6 (RETURN) 5588 0A20: GOTO 0AD6 (RETURN)
5589 .................... 5589 ....................
5590 .................... // see usb_hw_layer.h for documentation 5590 .................... // see usb_hw_layer.h for documentation
5591 .................... void usb_unstall_ep(int8 endpoint) 5591 .................... void usb_unstall_ep(int8 endpoint)
5592 .................... { 5592 .................... {
5593 .................... int1 direction; 5593 .................... int1 direction;
5594 .................... 5594 ....................
5595 .................... direction = bit_test(endpoint,7); 5595 .................... direction = bit_test(endpoint,7);
5596 * 5596 *
5597 0946: MOVLB 6 5597 0946: MOVLB 6
5598 0948: BCF xFE.0 5598 0948: BCF xFE.0
5599 094A: BTFSC xFD.7 5599 094A: BTFSC xFD.7
5600 094C: BSF xFE.0 5600 094C: BSF xFE.0
5601 .................... endpoint &= 0x7F; 5601 .................... endpoint &= 0x7F;
5602 094E: BCF xFD.7 5602 094E: BCF xFD.7
5603 .................... 5603 ....................
5604 .................... if (direction) 5604 .................... if (direction)
5605 0950: BTFSS xFE.0 5605 0950: BTFSS xFE.0
5606 0952: BRA 098E 5606 0952: BRA 098E
5607 .................... { 5607 .................... {
5608 .................... #if USB_IGNORE_RX_DTS 5608 .................... #if USB_IGNORE_RX_DTS
5609 .................... EP_BDxST_I(endpoint) = 0x80; 5609 .................... EP_BDxST_I(endpoint) = 0x80;
5610 .................... #else 5610 .................... #else
5611 .................... EP_BDxST_I(endpoint) = 0x88; 5611 .................... EP_BDxST_I(endpoint) = 0x88;
5612 0954: MOVLB 7 5612 0954: MOVLB 7
5613 0956: CLRF x49 5613 0956: CLRF x49
5614 0958: MOVFF 6FD,748 5614 0958: MOVFF 6FD,748
5615 095C: CLRF x4B 5615 095C: CLRF x4B
5616 095E: MOVLW 08 5616 095E: MOVLW 08
5617 0960: MOVWF x4A 5617 0960: MOVWF x4A
5618 0962: MOVLB 0 5618 0962: MOVLB 0
5619 0964: RCALL 02BA 5619 0964: RCALL 02BA
5620 0966: MOVFF 02,700 5620 0966: MOVFF 02,700
5621 096A: MOVFF 01,6FF 5621 096A: MOVFF 01,6FF
5622 096E: MOVLW 04 5622 096E: MOVLW 04
5623 0970: MOVLB 6 5623 0970: MOVLB 6
5624 0972: ADDWF xFF,F 5624 0972: ADDWF xFF,F
5625 0974: MOVLW 00 5625 0974: MOVLW 00
5626 0976: MOVLB 7 5626 0976: MOVLB 7
5627 0978: ADDWFC x00,F 5627 0978: ADDWFC x00,F
5628 097A: MOVFF 6FF,FE9 5628 097A: MOVFF 6FF,FE9
5629 097E: MOVLW 04 5629 097E: MOVLW 04
5630 0980: MOVLB 7 5630 0980: MOVLB 7
5631 0982: ADDWF x00,W 5631 0982: ADDWF x00,W
5632 0984: MOVWF FEA 5632 0984: MOVWF FEA
5633 0986: MOVLW 88 5633 0986: MOVLW 88
5634 0988: MOVWF FEF 5634 0988: MOVWF FEF
5635 .................... #endif 5635 .................... #endif
5636 .................... } 5636 .................... }
5637 .................... else 5637 .................... else
5638 098A: BRA 09AE 5638 098A: BRA 09AE
5639 098C: MOVLB 6 5639 098C: MOVLB 6
5640 .................... { 5640 .................... {
5641 .................... EP_BDxST_O(endpoint) = 0x00; 5641 .................... EP_BDxST_O(endpoint) = 0x00;
5642 098E: MOVLB 7 5642 098E: MOVLB 7
5643 0990: CLRF x49 5643 0990: CLRF x49
5644 0992: MOVFF 6FD,748 5644 0992: MOVFF 6FD,748
5645 0996: CLRF x4B 5645 0996: CLRF x4B
5646 0998: MOVLW 08 5646 0998: MOVLW 08
5647 099A: MOVWF x4A 5647 099A: MOVWF x4A
5648 099C: MOVLB 0 5648 099C: MOVLB 0
5649 099E: RCALL 02BA 5649 099E: RCALL 02BA
5650 09A0: MOVFF 01,FE9 5650 09A0: MOVFF 01,FE9
5651 09A4: MOVLW 04 5651 09A4: MOVLW 04
5652 09A6: MOVLB 7 5652 09A6: MOVLB 7
5653 09A8: ADDWF 02,W 5653 09A8: ADDWF 02,W
5654 09AA: MOVWF FEA 5654 09AA: MOVWF FEA
5655 09AC: CLRF FEF 5655 09AC: CLRF FEF
5656 .................... } 5656 .................... }
5657 .................... } 5657 .................... }
5658 09AE: MOVLB 0 5658 09AE: MOVLB 0
5659 09B0: GOTO 0AC6 (RETURN) 5659 09B0: GOTO 0AC6 (RETURN)
5660 .................... 5660 ....................
5661 .................... // see usb_hw_layer.h for documentation 5661 .................... // see usb_hw_layer.h for documentation
5662 .................... int1 usb_endpoint_stalled(int8 endpoint) 5662 .................... int1 usb_endpoint_stalled(int8 endpoint)
5663 .................... { 5663 .................... {
5664 .................... int1 direction; 5664 .................... int1 direction;
5665 .................... int8 st; 5665 .................... int8 st;
5666 .................... 5666 ....................
5667 .................... direction = bit_test(endpoint,7); 5667 .................... direction = bit_test(endpoint,7);
5668 * 5668 *
5669 0A24: MOVLB 6 5669 0A24: MOVLB 6
5670 0A26: BCF xFE.0 5670 0A26: BCF xFE.0
5671 0A28: BTFSC xFD.7 5671 0A28: BTFSC xFD.7
5672 0A2A: BSF xFE.0 5672 0A2A: BSF xFE.0
5673 .................... endpoint &= 0x7F; 5673 .................... endpoint &= 0x7F;
5674 0A2C: BCF xFD.7 5674 0A2C: BCF xFD.7
5675 .................... 5675 ....................
5676 .................... if (direction) 5676 .................... if (direction)
5677 0A2E: BTFSS xFE.0 5677 0A2E: BTFSS xFE.0
5678 0A30: BRA 0A68 5678 0A30: BRA 0A68
5679 .................... { 5679 .................... {
5680 .................... st=EP_BDxST_I(endpoint); 5680 .................... st=EP_BDxST_I(endpoint);
5681 0A32: MOVLB 7 5681 0A32: MOVLB 7
5682 0A34: CLRF x49 5682 0A34: CLRF x49
5683 0A36: MOVFF 6FD,748 5683 0A36: MOVFF 6FD,748
5684 0A3A: CLRF x4B 5684 0A3A: CLRF x4B
5685 0A3C: MOVLW 08 5685 0A3C: MOVLW 08
5686 0A3E: MOVWF x4A 5686 0A3E: MOVWF x4A
5687 0A40: MOVLB 0 5687 0A40: MOVLB 0
5688 0A42: RCALL 02BA 5688 0A42: RCALL 02BA
5689 0A44: MOVFF 02,701 5689 0A44: MOVFF 02,701
5690 0A48: MOVFF 01,700 5690 0A48: MOVFF 01,700
5691 0A4C: MOVLW 04 5691 0A4C: MOVLW 04
5692 0A4E: MOVLB 7 5692 0A4E: MOVLB 7
5693 0A50: ADDWF x00,F 5693 0A50: ADDWF x00,F
5694 0A52: MOVLW 00 5694 0A52: MOVLW 00
5695 0A54: ADDWFC x01,F 5695 0A54: ADDWFC x01,F
5696 0A56: MOVFF 700,FE9 5696 0A56: MOVFF 700,FE9
5697 0A5A: MOVLW 04 5697 0A5A: MOVLW 04
5698 0A5C: ADDWF x01,W 5698 0A5C: ADDWF x01,W
5699 0A5E: MOVWF FEA 5699 0A5E: MOVWF FEA
5700 0A60: MOVFF FEF,6FF 5700 0A60: MOVFF FEF,6FF
5701 0A64: MOVLB 6 5701 0A64: MOVLB 6
5702 .................... } 5702 .................... }
5703 .................... else 5703 .................... else
5704 0A66: BRA 0A8C 5704 0A66: BRA 0A8C
5705 .................... { 5705 .................... {
5706 .................... st=EP_BDxST_O(endpoint); 5706 .................... st=EP_BDxST_O(endpoint);
5707 0A68: MOVLB 7 5707 0A68: MOVLB 7
5708 0A6A: CLRF x49 5708 0A6A: CLRF x49
5709 0A6C: MOVFF 6FD,748 5709 0A6C: MOVFF 6FD,748
5710 0A70: CLRF x4B 5710 0A70: CLRF x4B
5711 0A72: MOVLW 08 5711 0A72: MOVLW 08
5712 0A74: MOVWF x4A 5712 0A74: MOVWF x4A
5713 0A76: MOVLB 0 5713 0A76: MOVLB 0
5714 0A78: RCALL 02BA 5714 0A78: RCALL 02BA
5715 0A7A: MOVLB 7 5715 0A7A: MOVLB 7
5716 0A7C: MOVFF 01,FE9 5716 0A7C: MOVFF 01,FE9
5717 0A80: MOVLW 04 5717 0A80: MOVLW 04
5718 0A82: ADDWF 02,W 5718 0A82: ADDWF 02,W
5719 0A84: MOVWF FEA 5719 0A84: MOVWF FEA
5720 0A86: MOVFF FEF,6FF 5720 0A86: MOVFF FEF,6FF
5721 0A8A: MOVLB 6 5721 0A8A: MOVLB 6
5722 .................... } 5722 .................... }
5723 .................... 5723 ....................
5724 .................... return(bit_test(st,7) && bit_test(st,2)); 5724 .................... return(bit_test(st,7) && bit_test(st,2));
5725 0A8C: BTFSS xFF.7 5725 0A8C: BTFSS xFF.7
5726 0A8E: BRA 0A94 5726 0A8E: BRA 0A94
5727 0A90: BTFSC xFF.2 5727 0A90: BTFSC xFF.2
5728 0A92: BRA 0A98 5728 0A92: BRA 0A98
5729 0A94: MOVLW 00 5729 0A94: MOVLW 00
5730 0A96: BRA 0A9A 5730 0A96: BRA 0A9A
5731 0A98: MOVLW 01 5731 0A98: MOVLW 01
5732 0A9A: MOVWF 01 5732 0A9A: MOVWF 01
5733 .................... } 5733 .................... }
5734 0A9C: MOVLB 0 5734 0A9C: MOVLB 0
5735 0A9E: GOTO 0AEE (RETURN) 5735 0A9E: GOTO 0AEE (RETURN)
5736 .................... 5736 ....................
5737 .................... // see usb_hw_layer.h for documentation 5737 .................... // see usb_hw_layer.h for documentation
5738 .................... void usb_set_address(int8 address) 5738 .................... void usb_set_address(int8 address)
5739 .................... { 5739 .................... {
5740 .................... UADDR = address; 5740 .................... UADDR = address;
5741 * 5741 *
5742 0F60: MOVFF 6FE,F6E 5742 0F60: MOVFF 6FE,F6E
5743 .................... 5743 ....................
5744 .................... if (address) 5744 .................... if (address)
5745 0F64: MOVLB 6 5745 0F64: MOVLB 6
5746 0F66: MOVF xFE,F 5746 0F66: MOVF xFE,F
5747 0F68: BZ 0F70 5747 0F68: BZ 0F70
5748 .................... { 5748 .................... {
5749 .................... usb_state = USB_STATE_ADDRESS; 5749 .................... usb_state = USB_STATE_ADDRESS;
5750 0F6A: MOVLW 04 5750 0F6A: MOVLW 04
5751 0F6C: MOVWF 24 5751 0F6C: MOVWF 24
5752 .................... } 5752 .................... }
5753 .................... else 5753 .................... else
5754 0F6E: BRA 0F74 5754 0F6E: BRA 0F74
5755 .................... { 5755 .................... {
5756 .................... usb_state = USB_STATE_POWERED; 5756 .................... usb_state = USB_STATE_POWERED;
5757 0F70: MOVLW 02 5757 0F70: MOVLW 02
5758 0F72: MOVWF 24 5758 0F72: MOVWF 24
5759 .................... } 5759 .................... }
5760 .................... } 5760 .................... }
5761 0F74: MOVLB 0 5761 0F74: MOVLB 0
5762 0F76: GOTO 0F84 (RETURN) 5762 0F76: GOTO 0F84 (RETURN)
5763 .................... 5763 ....................
5764 .................... // see usb_hw_layer.h for documentation 5764 .................... // see usb_hw_layer.h for documentation
5765 .................... void usb_set_configured(int8 config) 5765 .................... void usb_set_configured(int8 config)
5766 .................... { 5766 .................... {
5767 .................... int8 en; 5767 .................... int8 en;
5768 .................... int16 addy; 5768 .................... int16 addy;
5769 .................... int8 new_uep; 5769 .................... int8 new_uep;
5770 .................... int16 len; 5770 .................... int16 len;
5771 .................... int8 i; 5771 .................... int8 i;
5772 .................... 5772 ....................
5773 .................... if (config == 0) 5773 .................... if (config == 0)
5774 * 5774 *
5775 055C: MOVLB 6 5775 055C: MOVLB 6
5776 055E: MOVF xFD,F 5776 055E: MOVF xFD,F
5777 0560: BNZ 056E 5777 0560: BNZ 056E
5778 .................... { 5778 .................... {
5779 .................... // if config=0 then set addressed state 5779 .................... // if config=0 then set addressed state
5780 .................... usb_state = USB_STATE_ADDRESS; 5780 .................... usb_state = USB_STATE_ADDRESS;
5781 0562: MOVLW 04 5781 0562: MOVLW 04
5782 0564: MOVWF 24 5782 0564: MOVWF 24
5783 .................... usb_disable_endpoints(); 5783 .................... usb_disable_endpoints();
5784 0566: MOVLB 0 5784 0566: MOVLB 0
5785 0568: RCALL 033E 5785 0568: RCALL 033E
5786 .................... } 5786 .................... }
5787 .................... else 5787 .................... else
5788 056A: BRA 0786 5788 056A: BRA 0786
5789 056C: MOVLB 6 5789 056C: MOVLB 6
5790 .................... { 5790 .................... {
5791 .................... // else set configed state 5791 .................... // else set configed state
5792 .................... usb_state = USB_STATE_CONFIGURED; 5792 .................... usb_state = USB_STATE_CONFIGURED;
5793 056E: MOVLW 05 5793 056E: MOVLW 05
5794 0570: MOVWF 24 5794 0570: MOVWF 24
5795 .................... addy = (int16)USB_DATA_BUFFER_LOCATION+(2*USB_MAX_EP0_PACKET_LENGTH); 5795 .................... addy = (int16)USB_DATA_BUFFER_LOCATION+(2*USB_MAX_EP0_PACKET_LENGTH);
5796 0572: MOVLW 04 5796 0572: MOVLW 04
5797 0574: MOVLB 7 5797 0574: MOVLB 7
5798 0576: MOVWF x00 5798 0576: MOVWF x00
5799 0578: MOVLW 98 5799 0578: MOVLW 98
5800 057A: MOVLB 6 5800 057A: MOVLB 6
5801 057C: MOVWF xFF 5801 057C: MOVWF xFF
5802 .................... for (en=1; en<16; en++) 5802 .................... for (en=1; en<16; en++)
5803 057E: MOVLW 01 5803 057E: MOVLW 01
5804 0580: MOVWF xFE 5804 0580: MOVWF xFE
5805 0582: MOVF xFE,W 5805 0582: MOVF xFE,W
5806 0584: SUBLW 0F 5806 0584: SUBLW 0F
5807 0586: BTFSS FD8.0 5807 0586: BTFSS FD8.0
5808 0588: BRA 0786 5808 0588: BRA 0786
5809 .................... { 5809 .................... {
5810 .................... // enable and config endpoints based upon user configuration 5810 .................... // enable and config endpoints based upon user configuration
5811 .................... usb_disable_endpoint(en); 5811 .................... usb_disable_endpoint(en);
5812 058A: MOVFF 6FE,706 5812 058A: MOVFF 6FE,706
5813 058E: MOVLB 0 5813 058E: MOVLB 0
5814 0590: RCALL 02DC 5814 0590: RCALL 02DC
5815 .................... new_uep = 0; 5815 .................... new_uep = 0;
5816 0592: MOVLB 7 5816 0592: MOVLB 7
5817 0594: CLRF x01 5817 0594: CLRF x01
5818 .................... if (usb_ep_rx_type[en] != USB_ENABLE_DISABLED) 5818 .................... if (usb_ep_rx_type[en] != USB_ENABLE_DISABLED)
5819 0596: CLRF 03 5819 0596: CLRF 03
5820 0598: MOVLB 6 5820 0598: MOVLB 6
5821 059A: MOVF xFE,W 5821 059A: MOVF xFE,W
5822 059C: MOVFF FF2,705 5822 059C: MOVFF FF2,705
5823 05A0: BCF FF2.7 5823 05A0: BCF FF2.7
5824 05A2: MOVLB 0 5824 05A2: MOVLB 0
5825 05A4: RCALL 00CA 5825 05A4: RCALL 00CA
5826 05A6: MOVLB 7 5826 05A6: MOVLB 7
5827 05A8: BTFSC x05.7 5827 05A8: BTFSC x05.7
5828 05AA: BSF FF2.7 5828 05AA: BSF FF2.7
5829 05AC: SUBLW FF 5829 05AC: SUBLW FF
5830 05AE: BZ 0692 5830 05AE: BZ 0692
5831 .................... { 5831 .................... {
5832 .................... new_uep = 0x04; 5832 .................... new_uep = 0x04;
5833 05B0: MOVLW 04 5833 05B0: MOVLW 04
5834 05B2: MOVWF x01 5834 05B2: MOVWF x01
5835 .................... len = usb_ep_rx_size[en]; 5835 .................... len = usb_ep_rx_size[en];
5836 05B4: BCF FD8.0 5836 05B4: BCF FD8.0
5837 05B6: MOVLB 6 5837 05B6: MOVLB 6
5838 05B8: RLCF xFE,W 5838 05B8: RLCF xFE,W
5839 05BA: CLRF 03 5839 05BA: CLRF 03
5840 05BC: MOVFF FF2,705 5840 05BC: MOVFF FF2,705
5841 05C0: BCF FF2.7 5841 05C0: BCF FF2.7
5842 05C2: MOVLB 0 5842 05C2: MOVLB 0
5843 05C4: RCALL 011A 5843 05C4: RCALL 011A
5844 05C6: TBLRD*+ 5844 05C6: TBLRD*+
5845 05C8: MOVFF FF5,03 5845 05C8: MOVFF FF5,03
5846 05CC: MOVLB 7 5846 05CC: MOVLB 7
5847 05CE: BTFSC x05.7 5847 05CE: BTFSC x05.7
5848 05D0: BSF FF2.7 5848 05D0: BSF FF2.7
5849 05D2: MOVWF x02 5849 05D2: MOVWF x02
5850 05D4: MOVFF 03,703 5850 05D4: MOVFF 03,703
5851 .................... EP_BDxCNT_O(en) = len; 5851 .................... EP_BDxCNT_O(en) = len;
5852 05D8: CLRF x49 5852 05D8: CLRF x49
5853 05DA: MOVFF 6FE,748 5853 05DA: MOVFF 6FE,748
5854 05DE: CLRF x4B 5854 05DE: CLRF x4B
5855 05E0: MOVLW 08 5855 05E0: MOVLW 08
5856 05E2: MOVWF x4A 5856 05E2: MOVWF x4A
5857 05E4: MOVLB 0 5857 05E4: MOVLB 0
5858 05E6: RCALL 02BA 5858 05E6: RCALL 02BA
5859 05E8: MOVFF 01,705 5859 05E8: MOVFF 01,705
5860 05EC: MOVLW 01 5860 05EC: MOVLW 01
5861 05EE: MOVLB 7 5861 05EE: MOVLB 7
5862 05F0: ADDWF 01,W 5862 05F0: ADDWF 01,W
5863 05F2: MOVWF 01 5863 05F2: MOVWF 01
5864 05F4: MOVLW 00 5864 05F4: MOVLW 00
5865 05F6: ADDWFC 02,W 5865 05F6: ADDWFC 02,W
5866 05F8: MOVWF 03 5866 05F8: MOVWF 03
5867 05FA: MOVFF 01,FE9 5867 05FA: MOVFF 01,FE9
5868 05FE: MOVLW 04 5868 05FE: MOVLW 04
5869 0600: ADDWF 03,W 5869 0600: ADDWF 03,W
5870 0602: MOVWF FEA 5870 0602: MOVWF FEA
5871 0604: MOVFF 702,FEF 5871 0604: MOVFF 702,FEF
5872 .................... EP_BDxADR_O(en) = addy; 5872 .................... EP_BDxADR_O(en) = addy;
5873 0608: CLRF x49 5873 0608: CLRF x49
5874 060A: MOVFF 6FE,748 5874 060A: MOVFF 6FE,748
5875 060E: CLRF x4B 5875 060E: CLRF x4B
5876 0610: MOVLW 08 5876 0610: MOVLW 08
5877 0612: MOVWF x4A 5877 0612: MOVWF x4A
5878 0614: MOVLB 0 5878 0614: MOVLB 0
5879 0616: RCALL 02BA 5879 0616: RCALL 02BA
5880 0618: MOVFF 01,705 5880 0618: MOVFF 01,705
5881 061C: MOVLW 02 5881 061C: MOVLW 02
5882 061E: MOVLB 7 5882 061E: MOVLB 7
5883 0620: ADDWF 01,W 5883 0620: ADDWF 01,W
5884 0622: MOVWF 01 5884 0622: MOVWF 01
5885 0624: MOVLW 00 5885 0624: MOVLW 00
5886 0626: ADDWFC 02,W 5886 0626: ADDWFC 02,W
5887 0628: MOVWF 03 5887 0628: MOVWF 03
5888 062A: MOVFF 01,FE9 5888 062A: MOVFF 01,FE9
5889 062E: MOVLW 04 5889 062E: MOVLW 04
5890 0630: ADDWF 03,W 5890 0630: ADDWF 03,W
5891 0632: MOVWF FEA 5891 0632: MOVWF FEA
5892 0634: MOVFF 700,FEC 5892 0634: MOVFF 700,FEC
5893 0638: MOVF FED,F 5893 0638: MOVF FED,F
5894 063A: MOVFF 6FF,FEF 5894 063A: MOVFF 6FF,FEF
5895 .................... addy += usb_ep_rx_size[en]; 5895 .................... addy += usb_ep_rx_size[en];
5896 063E: BCF FD8.0 5896 063E: BCF FD8.0
5897 0640: MOVLB 6 5897 0640: MOVLB 6
5898 0642: RLCF xFE,W 5898 0642: RLCF xFE,W
5899 0644: CLRF 03 5899 0644: CLRF 03
5900 0646: MOVFF FF2,705 5900 0646: MOVFF FF2,705
5901 064A: BCF FF2.7 5901 064A: BCF FF2.7
5902 064C: MOVLB 0 5902 064C: MOVLB 0
5903 064E: RCALL 011A 5903 064E: RCALL 011A
5904 0650: TBLRD*+ 5904 0650: TBLRD*+
5905 0652: MOVFF FF5,03 5905 0652: MOVFF FF5,03
5906 0656: MOVLB 7 5906 0656: MOVLB 7
5907 0658: BTFSC x05.7 5907 0658: BTFSC x05.7
5908 065A: BSF FF2.7 5908 065A: BSF FF2.7
5909 065C: MOVLB 6 5909 065C: MOVLB 6
5910 065E: ADDWF xFF,F 5910 065E: ADDWF xFF,F
5911 0660: MOVF 03,W 5911 0660: MOVF 03,W
5912 0662: MOVLB 7 5912 0662: MOVLB 7
5913 0664: ADDWFC x00,F 5913 0664: ADDWFC x00,F
5914 .................... #if USB_IGNORE_RX_DTS 5914 .................... #if USB_IGNORE_RX_DTS
5915 .................... i = 0x80; 5915 .................... i = 0x80;
5916 .................... #else 5916 .................... #else
5917 .................... i = 0x88; 5917 .................... i = 0x88;
5918 0666: MOVLW 88 5918 0666: MOVLW 88
5919 0668: MOVWF x04 5919 0668: MOVWF x04
5920 .................... #endif 5920 .................... #endif
5921 .................... if (bit_test(len,8)) {bit_set(i,0);} 5921 .................... if (bit_test(len,8)) {bit_set(i,0);}
5922 066A: BTFSC x03.0 5922 066A: BTFSC x03.0
5923 066C: BSF x04.0 5923 066C: BSF x04.0
5924 .................... if (bit_test(len,9)) {bit_set(i,1);} 5924 .................... if (bit_test(len,9)) {bit_set(i,1);}
5925 066E: BTFSC x03.1 5925 066E: BTFSC x03.1
5926 0670: BSF x04.1 5926 0670: BSF x04.1
5927 .................... EP_BDxST_O(en) = i; 5927 .................... EP_BDxST_O(en) = i;
5928 0672: CLRF x49 5928 0672: CLRF x49
5929 0674: MOVFF 6FE,748 5929 0674: MOVFF 6FE,748
5930 0678: CLRF x4B 5930 0678: CLRF x4B
5931 067A: MOVLW 08 5931 067A: MOVLW 08
5932 067C: MOVWF x4A 5932 067C: MOVWF x4A
5933 067E: MOVLB 0 5933 067E: MOVLB 0
5934 0680: RCALL 02BA 5934 0680: RCALL 02BA
5935 0682: MOVLB 7 5935 0682: MOVLB 7
5936 0684: MOVFF 01,FE9 5936 0684: MOVFF 01,FE9
5937 0688: MOVLW 04 5937 0688: MOVLW 04
5938 068A: ADDWF 02,W 5938 068A: ADDWF 02,W
5939 068C: MOVWF FEA 5939 068C: MOVWF FEA
5940 068E: MOVFF 704,FEF 5940 068E: MOVFF 704,FEF
5941 .................... } 5941 .................... }
5942 .................... if (usb_ep_tx_type[en] != USB_ENABLE_DISABLED) 5942 .................... if (usb_ep_tx_type[en] != USB_ENABLE_DISABLED)
5943 0692: CLRF 03 5943 0692: CLRF 03
5944 0694: MOVLB 6 5944 0694: MOVLB 6
5945 0696: MOVF xFE,W 5945 0696: MOVF xFE,W
5946 0698: MOVFF FF2,705 5946 0698: MOVFF FF2,705
5947 069C: BCF FF2.7 5947 069C: BCF FF2.7
5948 069E: MOVLB 0 5948 069E: MOVLB 0
5949 06A0: RCALL 00AA 5949 06A0: RCALL 00AA
5950 06A2: MOVLB 7 5950 06A2: MOVLB 7
5951 06A4: BTFSC x05.7 5951 06A4: BTFSC x05.7
5952 06A6: BSF FF2.7 5952 06A6: BSF FF2.7
5953 06A8: SUBLW FF 5953 06A8: SUBLW FF
5954 06AA: BZ 0748 5954 06AA: BZ 0748
5955 .................... { 5955 .................... {
5956 .................... new_uep |= 0x02; 5956 .................... new_uep |= 0x02;
5957 06AC: BSF x01.1 5957 06AC: BSF x01.1
5958 .................... EP_BDxADR_I(en) = addy; 5958 .................... EP_BDxADR_I(en) = addy;
5959 06AE: CLRF x49 5959 06AE: CLRF x49
5960 06B0: MOVFF 6FE,748 5960 06B0: MOVFF 6FE,748
5961 06B4: CLRF x4B 5961 06B4: CLRF x4B
5962 06B6: MOVLW 08 5962 06B6: MOVLW 08
5963 06B8: MOVWF x4A 5963 06B8: MOVWF x4A
5964 06BA: MOVLB 0 5964 06BA: MOVLB 0
5965 06BC: RCALL 02BA 5965 06BC: RCALL 02BA
5966 06BE: MOVFF 02,706 5966 06BE: MOVFF 02,706
5967 06C2: MOVFF 01,705 5967 06C2: MOVFF 01,705
5968 06C6: MOVLW 04 5968 06C6: MOVLW 04
5969 06C8: MOVLB 7 5969 06C8: MOVLB 7
5970 06CA: ADDWF x05,F 5970 06CA: ADDWF x05,F
5971 06CC: MOVLW 00 5971 06CC: MOVLW 00
5972 06CE: ADDWFC x06,F 5972 06CE: ADDWFC x06,F
5973 06D0: MOVLW 02 5973 06D0: MOVLW 02
5974 06D2: ADDWF x05,W 5974 06D2: ADDWF x05,W
5975 06D4: MOVWF 01 5975 06D4: MOVWF 01
5976 06D6: MOVLW 00 5976 06D6: MOVLW 00
5977 06D8: ADDWFC x06,W 5977 06D8: ADDWFC x06,W
5978 06DA: MOVWF 03 5978 06DA: MOVWF 03
5979 06DC: MOVFF 01,FE9 5979 06DC: MOVFF 01,FE9
5980 06E0: MOVLW 04 5980 06E0: MOVLW 04
5981 06E2: ADDWF 03,W 5981 06E2: ADDWF 03,W
5982 06E4: MOVWF FEA 5982 06E4: MOVWF FEA
5983 06E6: MOVFF 700,FEC 5983 06E6: MOVFF 700,FEC
5984 06EA: MOVF FED,F 5984 06EA: MOVF FED,F
5985 06EC: MOVFF 6FF,FEF 5985 06EC: MOVFF 6FF,FEF
5986 .................... addy += usb_ep_tx_size[en]; 5986 .................... addy += usb_ep_tx_size[en];
5987 06F0: BCF FD8.0 5987 06F0: BCF FD8.0
5988 06F2: MOVLB 6 5988 06F2: MOVLB 6
5989 06F4: RLCF xFE,W 5989 06F4: RLCF xFE,W
5990 06F6: CLRF 03 5990 06F6: CLRF 03
5991 06F8: MOVFF FF2,705 5991 06F8: MOVFF FF2,705
5992 06FC: BCF FF2.7 5992 06FC: BCF FF2.7
5993 06FE: MOVLB 0 5993 06FE: MOVLB 0
5994 0700: RCALL 00EA 5994 0700: RCALL 00EA
5995 0702: TBLRD*+ 5995 0702: TBLRD*+
5996 0704: MOVFF FF5,03 5996 0704: MOVFF FF5,03
5997 0708: MOVLB 7 5997 0708: MOVLB 7
5998 070A: BTFSC x05.7 5998 070A: BTFSC x05.7
5999 070C: BSF FF2.7 5999 070C: BSF FF2.7
6000 070E: MOVLB 6 6000 070E: MOVLB 6
6001 0710: ADDWF xFF,F 6001 0710: ADDWF xFF,F
6002 0712: MOVF 03,W 6002 0712: MOVF 03,W
6003 0714: MOVLB 7 6003 0714: MOVLB 7
6004 0716: ADDWFC x00,F 6004 0716: ADDWFC x00,F
6005 .................... EP_BDxST_I(en) = 0x40; 6005 .................... EP_BDxST_I(en) = 0x40;
6006 0718: CLRF x49 6006 0718: CLRF x49
6007 071A: MOVFF 6FE,748 6007 071A: MOVFF 6FE,748
6008 071E: CLRF x4B 6008 071E: CLRF x4B
6009 0720: MOVLW 08 6009 0720: MOVLW 08
6010 0722: MOVWF x4A 6010 0722: MOVWF x4A
6011 0724: MOVLB 0 6011 0724: MOVLB 0
6012 0726: RCALL 02BA 6012 0726: RCALL 02BA
6013 0728: MOVFF 02,706 6013 0728: MOVFF 02,706
6014 072C: MOVFF 01,705 6014 072C: MOVFF 01,705
6015 0730: MOVLW 04 6015 0730: MOVLW 04
6016 0732: MOVLB 7 6016 0732: MOVLB 7
6017 0734: ADDWF x05,F 6017 0734: ADDWF x05,F
6018 0736: MOVLW 00 6018 0736: MOVLW 00
6019 0738: ADDWFC x06,F 6019 0738: ADDWFC x06,F
6020 073A: MOVFF 705,FE9 6020 073A: MOVFF 705,FE9
6021 073E: MOVLW 04 6021 073E: MOVLW 04
6022 0740: ADDWF x06,W 6022 0740: ADDWF x06,W
6023 0742: MOVWF FEA 6023 0742: MOVWF FEA
6024 0744: MOVLW 40 6024 0744: MOVLW 40
6025 0746: MOVWF FEF 6025 0746: MOVWF FEF
6026 .................... } 6026 .................... }
6027 .................... if (new_uep == 0x06) {new_uep = 0x0E;} 6027 .................... if (new_uep == 0x06) {new_uep = 0x0E;}
6028 0748: MOVF x01,W 6028 0748: MOVF x01,W
6029 074A: SUBLW 06 6029 074A: SUBLW 06
6030 074C: BNZ 0752 6030 074C: BNZ 0752
6031 074E: MOVLW 0E 6031 074E: MOVLW 0E
6032 0750: MOVWF x01 6032 0750: MOVWF x01
6033 .................... if (usb_ep_tx_type[en] != USB_ENABLE_ISOCHRONOUS) {new_uep |= 0x10;} 6033 .................... if (usb_ep_tx_type[en] != USB_ENABLE_ISOCHRONOUS) {new_uep |= 0x10;}
6034 0752: CLRF 03 6034 0752: CLRF 03
6035 0754: MOVLB 6 6035 0754: MOVLB 6
6036 0756: MOVF xFE,W 6036 0756: MOVF xFE,W
6037 0758: MOVFF FF2,705 6037 0758: MOVFF FF2,705
6038 075C: BCF FF2.7 6038 075C: BCF FF2.7
6039 075E: MOVLB 0 6039 075E: MOVLB 0
6040 0760: RCALL 00AA 6040 0760: RCALL 00AA
6041 0762: MOVLB 7 6041 0762: MOVLB 7
6042 0764: BTFSC x05.7 6042 0764: BTFSC x05.7
6043 0766: BSF FF2.7 6043 0766: BSF FF2.7
6044 0768: SUBLW 01 6044 0768: SUBLW 01
6045 076A: BTFSS FD8.2 6045 076A: BTFSS FD8.2
6046 076C: BSF x01.4 6046 076C: BSF x01.4
6047 .................... 6047 ....................
6048 .................... UEP(en) = new_uep; 6048 .................... UEP(en) = new_uep;
6049 076E: CLRF 03 6049 076E: CLRF 03
6050 0770: MOVLB 6 6050 0770: MOVLB 6
6051 0772: MOVF xFE,W 6051 0772: MOVF xFE,W
6052 0774: ADDLW 70 6052 0774: ADDLW 70
6053 0776: MOVWF FE9 6053 0776: MOVWF FE9
6054 0778: MOVLW 0F 6054 0778: MOVLW 0F
6055 077A: ADDWFC 03,W 6055 077A: ADDWFC 03,W
6056 077C: MOVWF FEA 6056 077C: MOVWF FEA
6057 077E: MOVFF 701,FEF 6057 077E: MOVFF 701,FEF
6058 .................... } 6058 .................... }
6059 0782: INCF xFE,F 6059 0782: INCF xFE,F
6060 0784: BRA 0582 6060 0784: BRA 0582
6061 0786: MOVLB 0 6061 0786: MOVLB 0
6062 .................... } 6062 .................... }
6063 .................... } 6063 .................... }
6064 0788: GOTO 082C (RETURN) 6064 0788: GOTO 082C (RETURN)
6065 .................... 6065 ....................
6066 .................... // see usb_hw_layer.h for documentation 6066 .................... // see usb_hw_layer.h for documentation
6067 .................... void usb_disable_endpoint(int8 en) 6067 .................... void usb_disable_endpoint(int8 en)
6068 .................... { 6068 .................... {
6069 .................... UEP(en) = ENDPT_DISABLED; 6069 .................... UEP(en) = ENDPT_DISABLED;
6070 * 6070 *
6071 02DC: CLRF 03 6071 02DC: CLRF 03
6072 02DE: MOVLB 7 6072 02DE: MOVLB 7
6073 02E0: MOVF x06,W 6073 02E0: MOVF x06,W
6074 02E2: ADDLW 70 6074 02E2: ADDLW 70
6075 02E4: MOVWF FE9 6075 02E4: MOVWF FE9
6076 02E6: MOVLW 0F 6076 02E6: MOVLW 0F
6077 02E8: ADDWFC 03,W 6077 02E8: ADDWFC 03,W
6078 02EA: MOVWF FEA 6078 02EA: MOVWF FEA
6079 02EC: CLRF FEF 6079 02EC: CLRF FEF
6080 .................... EP_BDxST_O(en) = 0; //clear state, deque if necessary 6080 .................... EP_BDxST_O(en) = 0; //clear state, deque if necessary
6081 02EE: CLRF x49 6081 02EE: CLRF x49
6082 02F0: MOVFF 706,748 6082 02F0: MOVFF 706,748
6083 02F4: CLRF x4B 6083 02F4: CLRF x4B
6084 02F6: MOVLW 08 6084 02F6: MOVLW 08
6085 02F8: MOVWF x4A 6085 02F8: MOVWF x4A
6086 02FA: MOVLB 0 6086 02FA: MOVLB 0
6087 02FC: RCALL 02BA 6087 02FC: RCALL 02BA
6088 02FE: MOVLB 7 6088 02FE: MOVLB 7
6089 0300: MOVFF 01,FE9 6089 0300: MOVFF 01,FE9
6090 0304: MOVLW 04 6090 0304: MOVLW 04
6091 0306: ADDWF 02,W 6091 0306: ADDWF 02,W
6092 0308: MOVWF FEA 6092 0308: MOVWF FEA
6093 030A: CLRF FEF 6093 030A: CLRF FEF
6094 .................... EP_BDxST_I(en) = 0; //clear state, deque if necessary 6094 .................... EP_BDxST_I(en) = 0; //clear state, deque if necessary
6095 030C: CLRF x49 6095 030C: CLRF x49
6096 030E: MOVFF 706,748 6096 030E: MOVFF 706,748
6097 0312: CLRF x4B 6097 0312: CLRF x4B
6098 0314: MOVLW 08 6098 0314: MOVLW 08
6099 0316: MOVWF x4A 6099 0316: MOVWF x4A
6100 0318: MOVLB 0 6100 0318: MOVLB 0
6101 031A: RCALL 02BA 6101 031A: RCALL 02BA
6102 031C: MOVFF 02,708 6102 031C: MOVFF 02,708
6103 0320: MOVFF 01,707 6103 0320: MOVFF 01,707
6104 0324: MOVLW 04 6104 0324: MOVLW 04
6105 0326: MOVLB 7 6105 0326: MOVLB 7
6106 0328: ADDWF x07,F 6106 0328: ADDWF x07,F
6107 032A: MOVLW 00 6107 032A: MOVLW 00
6108 032C: ADDWFC x08,F 6108 032C: ADDWFC x08,F
6109 032E: MOVFF 707,FE9 6109 032E: MOVFF 707,FE9
6110 0332: MOVLW 04 6110 0332: MOVLW 04
6111 0334: ADDWF x08,W 6111 0334: ADDWF x08,W
6112 0336: MOVWF FEA 6112 0336: MOVWF FEA
6113 0338: CLRF FEF 6113 0338: CLRF FEF
6114 .................... } 6114 .................... }
6115 033A: MOVLB 0 6115 033A: MOVLB 0
6116 033C: RETLW 00 6116 033C: RETLW 00
6117 .................... 6117 ....................
6118 .................... // see usb_hw_layer.h for documentation 6118 .................... // see usb_hw_layer.h for documentation
6119 .................... void usb_disable_endpoints(void) 6119 .................... void usb_disable_endpoints(void)
6120 .................... { 6120 .................... {
6121 .................... int8 i; 6121 .................... int8 i;
6122 .................... 6122 ....................
6123 .................... for (i=1; i<16; i++) 6123 .................... for (i=1; i<16; i++)
6124 033E: MOVLW 01 6124 033E: MOVLW 01
6125 0340: MOVLB 7 6125 0340: MOVLB 7
6126 0342: MOVWF x05 6126 0342: MOVWF x05
6127 0344: MOVF x05,W 6127 0344: MOVF x05,W
6128 0346: SUBLW 0F 6128 0346: SUBLW 0F
6129 0348: BNC 0358 6129 0348: BNC 0358
6130 .................... usb_disable_endpoint(i); 6130 .................... usb_disable_endpoint(i);
6131 034A: MOVFF 705,706 6131 034A: MOVFF 705,706
6132 034E: MOVLB 0 6132 034E: MOVLB 0
6133 0350: RCALL 02DC 6133 0350: RCALL 02DC
6134 0352: MOVLB 7 6134 0352: MOVLB 7
6135 0354: INCF x05,F 6135 0354: INCF x05,F
6136 0356: BRA 0344 6136 0356: BRA 0344
6137 .................... 6137 ....................
6138 .................... //__usb_kbhit_status=0; 6138 .................... //__usb_kbhit_status=0;
6139 .................... } 6139 .................... }
6140 0358: MOVLB 0 6140 0358: MOVLB 0
6141 035A: RETLW 00 6141 035A: RETLW 00
6142 .................... 6142 ....................
6143 .................... /// END Hardware layer functions required by USB.C 6143 .................... /// END Hardware layer functions required by USB.C
6144 .................... 6144 ....................
6145 .................... 6145 ....................
6146 .................... /// BEGIN USB Interrupt Service Routine 6146 .................... /// BEGIN USB Interrupt Service Routine
6147 .................... 6147 ....................
6148 .................... static void usb_clear_trn(void) 6148 .................... static void usb_clear_trn(void)
6149 .................... { 6149 .................... {
6150 .................... UIR_TRN = 0; 6150 .................... UIR_TRN = 0;
6151 * 6151 *
6152 03AA: BCF F68.3 6152 03AA: BCF F68.3
6153 .................... delay_cycles(6); 6153 .................... delay_cycles(6);
6154 03AC: BRA 03AE 6154 03AC: BRA 03AE
6155 03AE: BRA 03B0 6155 03AE: BRA 03B0
6156 03B0: BRA 03B2 6156 03B0: BRA 03B2
6157 .................... } 6157 .................... }
6158 03B2: RETLW 00 6158 03B2: RETLW 00
6159 .................... 6159 ....................
6160 .................... /***************************************************************************** 6160 .................... /*****************************************************************************
6161 .................... /* usb_handle_interrupt() 6161 .................... /* usb_handle_interrupt()
6162 .................... /* 6162 .................... /*
6163 .................... /* Summary: Checks the interrupt, and acts upon event. Processing finished 6163 .................... /* Summary: Checks the interrupt, and acts upon event. Processing finished
6164 .................... /* tokens is the majority of this code, and is handled by usb.c 6164 .................... /* tokens is the majority of this code, and is handled by usb.c
6165 .................... /* 6165 .................... /*
6166 .................... /* NOTE: If you wish to change to a polling method (and not an interrupt 6166 .................... /* NOTE: If you wish to change to a polling method (and not an interrupt
6167 .................... /* method), then you must call this function rapidly. If there is more 6167 .................... /* method), then you must call this function rapidly. If there is more
6168 .................... /* than 10ms latency the PC may think the USB device is stalled and 6168 .................... /* than 10ms latency the PC may think the USB device is stalled and
6169 .................... /* disable it. 6169 .................... /* disable it.
6170 .................... /* To switch to a polling method, remove the #int_usb line above this 6170 .................... /* To switch to a polling method, remove the #int_usb line above this
6171 .................... /* fuction. Also, goto usb_init() and remove the code that enables the 6171 .................... /* fuction. Also, goto usb_init() and remove the code that enables the
6172 .................... /* USB interrupt. 6172 .................... /* USB interrupt.
6173 .................... /******************************************************************************/ 6173 .................... /******************************************************************************/
6174 .................... #int_usb 6174 .................... #int_usb
6175 .................... void usb_isr() 6175 .................... void usb_isr()
6176 .................... { 6176 .................... {
6177 .................... int8 TRNAttempts; 6177 .................... int8 TRNAttempts;
6178 .................... 6178 ....................
6179 .................... if (usb_state == USB_STATE_DETACHED) return; //should never happen, though 6179 .................... if (usb_state == USB_STATE_DETACHED) return; //should never happen, though
6180 * 6180 *
6181 1274: MOVF 24,F 6181 1274: MOVF 24,F
6182 1276: BNZ 127A 6182 1276: BNZ 127A
6183 1278: BRA 12EE 6183 1278: BRA 12EE
6184 .................... if (UIR) 6184 .................... if (UIR)
6185 127A: MOVF F68,F 6185 127A: MOVF F68,F
6186 127C: BZ 12EE 6186 127C: BZ 12EE
6187 .................... { 6187 .................... {
6188 .................... debug_usb(debug_putc,"\r\n\n[%X] ",UIR); 6188 .................... debug_usb(debug_putc,"\r\n\n[%X] ",UIR);
6189 .................... 6189 ....................
6190 .................... //activity detected. (only enable after sleep) 6190 .................... //activity detected. (only enable after sleep)
6191 .................... if (UIR_ACTV && UIE_ACTV) {usb_isr_activity();} 6191 .................... if (UIR_ACTV && UIE_ACTV) {usb_isr_activity();}
6192 127E: BTFSS F68.2 6192 127E: BTFSS F68.2
6193 1280: BRA 128A 6193 1280: BRA 128A
6194 1282: BTFSS F69.2 6194 1282: BTFSS F69.2
6195 1284: BRA 128A 6195 1284: BRA 128A
6196 1286: GOTO 0274 6196 1286: GOTO 0274
6197 .................... 6197 ....................
6198 .................... if (UCON_SUSPND) return; 6198 .................... if (UCON_SUSPND) return;
6199 128A: BTFSS F6D.1 6199 128A: BTFSS F6D.1
6200 128C: BRA 1290 6200 128C: BRA 1290
6201 128E: BRA 12EE 6201 128E: BRA 12EE
6202 .................... 6202 ....................
6203 .................... if (UIR_STALL && UIE_STALL) {usb_isr_stall();} //a stall handshake was sent 6203 .................... if (UIR_STALL && UIE_STALL) {usb_isr_stall();} //a stall handshake was sent
6204 1290: BTFSS F68.5 6204 1290: BTFSS F68.5
6205 1292: BRA 129C 6205 1292: BRA 129C
6206 1294: BTFSS F69.5 6206 1294: BTFSS F69.5
6207 1296: BRA 129C 6207 1296: BRA 129C
6208 1298: GOTO 02A4 6208 1298: GOTO 02A4
6209 .................... 6209 ....................
6210 .................... if (UIR_UERR && UIE_UERR) {usb_isr_uerr();} //error has been detected 6210 .................... if (UIR_UERR && UIE_UERR) {usb_isr_uerr();} //error has been detected
6211 129C: BTFSS F68.1 6211 129C: BTFSS F68.1
6212 129E: BRA 12A8 6212 129E: BRA 12A8
6213 12A0: BTFSS F69.1 6213 12A0: BTFSS F69.1
6214 12A2: BRA 12A8 6214 12A2: BRA 12A8
6215 12A4: GOTO 02B2 6215 12A4: GOTO 02B2
6216 .................... 6216 ....................
6217 .................... if (UIR_URST && UIE_URST) {usb_isr_rst();} //usb reset has been detected 6217 .................... if (UIR_URST && UIE_URST) {usb_isr_rst();} //usb reset has been detected
6218 12A8: BTFSS F68.0 6218 12A8: BTFSS F68.0
6219 12AA: BRA 12B4 6219 12AA: BRA 12B4
6220 12AC: BTFSS F69.0 6220 12AC: BTFSS F69.0
6221 12AE: BRA 12B4 6221 12AE: BRA 12B4
6222 12B0: GOTO 03B4 6222 12B0: GOTO 03B4
6223 .................... 6223 ....................
6224 .................... if (UIR_IDLE && UIE_IDLE) {usb_isr_uidle();} //idle time, we can go to sleep 6224 .................... if (UIR_IDLE && UIE_IDLE) {usb_isr_uidle();} //idle time, we can go to sleep
6225 12B4: BTFSS F68.4 6225 12B4: BTFSS F68.4
6226 12B6: BRA 12C0 6226 12B6: BRA 12C0
6227 12B8: BTFSS F69.4 6227 12B8: BTFSS F69.4
6228 12BA: BRA 12C0 6228 12BA: BRA 12C0
6229 12BC: GOTO 03DE 6229 12BC: GOTO 03DE
6230 .................... 6230 ....................
6231 .................... if (UIR_SOF && UIE_SOF) {usb_isr_sof();} 6231 .................... if (UIR_SOF && UIE_SOF) {usb_isr_sof();}
6232 12C0: BTFSS F68.6 6232 12C0: BTFSS F68.6
6233 12C2: BRA 12CC 6233 12C2: BRA 12CC
6234 12C4: BTFSS F69.6 6234 12C4: BTFSS F69.6
6235 12C6: BRA 12CC 6235 12C6: BRA 12CC
6236 12C8: GOTO 03E8 6236 12C8: GOTO 03E8
6237 .................... 6237 ....................
6238 .................... TRNAttempts = 0; 6238 .................... TRNAttempts = 0;
6239 12CC: MOVLB 6 6239 12CC: MOVLB 6
6240 12CE: CLRF xFA 6240 12CE: CLRF xFA
6241 .................... do 6241 .................... do
6242 .................... { 6242 .................... {
6243 .................... if (UIR_TRN && UIE_TRN) 6243 .................... if (UIR_TRN && UIE_TRN)
6244 12D0: BTFSS F68.3 6244 12D0: BTFSS F68.3
6245 12D2: BRA 12E0 6245 12D2: BRA 12E0
6246 12D4: BTFSS F69.3 6246 12D4: BTFSS F69.3
6247 12D6: BRA 12E0 6247 12D6: BRA 12E0
6248 .................... { 6248 .................... {
6249 .................... usb_isr_tok_dne(); 6249 .................... usb_isr_tok_dne();
6250 12D8: MOVLB 0 6250 12D8: MOVLB 0
6251 12DA: BRA 108A 6251 12DA: BRA 108A
6252 .................... } 6252 .................... }
6253 .................... else 6253 .................... else
6254 12DC: BRA 12E2 6254 12DC: BRA 12E2
6255 12DE: MOVLB 6 6255 12DE: MOVLB 6
6256 .................... break; 6256 .................... break;
6257 12E0: BRA 12EC 6257 12E0: BRA 12EC
6258 .................... } while (TRNAttempts++ < 4); 6258 .................... } while (TRNAttempts++ < 4);
6259 12E2: MOVLB 6 6259 12E2: MOVLB 6
6260 12E4: MOVF xFA,W 6260 12E4: MOVF xFA,W
6261 12E6: INCF xFA,F 6261 12E6: INCF xFA,F
6262 12E8: SUBLW 03 6262 12E8: SUBLW 03
6263 12EA: BC 12D0 6263 12EA: BC 12D0
6264 12EC: MOVLB 0 6264 12EC: MOVLB 0
6265 .................... } 6265 .................... }
6266 .................... } 6266 .................... }
6267 .................... 6267 ....................
6268 .................... // SOF interrupt not handled. user must add this depending on application 6268 .................... // SOF interrupt not handled. user must add this depending on application
6269 12EE: BCF FA1.5 6269 12EE: BCF FA1.5
6270 12F0: GOTO 0064 6270 12F0: GOTO 0064
6271 .................... void usb_isr_sof(void) 6271 .................... void usb_isr_sof(void)
6272 .................... { 6272 .................... {
6273 .................... debug_usb(debug_putc, "\r\nSOF"); 6273 .................... debug_usb(debug_putc, "\r\nSOF");
6274 .................... 6274 ....................
6275 .................... UIR_SOF = 0; 6275 .................... UIR_SOF = 0;
6276 * 6276 *
6277 03E8: BCF F68.6 6277 03E8: BCF F68.6
6278 .................... } 6278 .................... }
6279 03EA: GOTO 12CC (RETURN) 6279 03EA: GOTO 12CC (RETURN)
6280 .................... 6280 ....................
6281 .................... /***************************************************************************** 6281 .................... /*****************************************************************************
6282 .................... /* usb_isr_rst() 6282 .................... /* usb_isr_rst()
6283 .................... /* 6283 .................... /*
6284 .................... /* Summary: The host (computer) sent us a RESET command. Reset USB device 6284 .................... /* Summary: The host (computer) sent us a RESET command. Reset USB device
6285 .................... /* and token handler code to initial state. 6285 .................... /* and token handler code to initial state.
6286 .................... /* 6286 .................... /*
6287 .................... /******************************************************************************/ 6287 .................... /******************************************************************************/
6288 .................... void usb_isr_rst(void) 6288 .................... void usb_isr_rst(void)
6289 .................... { 6289 .................... {
6290 .................... debug_usb(debug_putc,"R"); 6290 .................... debug_usb(debug_putc,"R");
6291 .................... 6291 ....................
6292 .................... UEIR = 0; 6292 .................... UEIR = 0;
6293 * 6293 *
6294 03B4: CLRF F6A 6294 03B4: CLRF F6A
6295 .................... UIR = 0; 6295 .................... UIR = 0;
6296 03B6: CLRF F68 6296 03B6: CLRF F68
6297 .................... UEIE = 0x9F; 6297 .................... UEIE = 0x9F;
6298 03B8: MOVLW 9F 6298 03B8: MOVLW 9F
6299 03BA: MOVWF F6B 6299 03BA: MOVWF F6B
6300 .................... UIE = STANDARD_INTS & ~__USB_UIF_ACTIVE; 6300 .................... UIE = STANDARD_INTS & ~__USB_UIF_ACTIVE;
6301 03BC: MOVLW 3D 6301 03BC: MOVLW 3D
6302 03BE: MOVWF F69 6302 03BE: MOVWF F69
6303 .................... 6303 ....................
6304 .................... UADDR = 0; 6304 .................... UADDR = 0;
6305 03C0: CLRF F6E 6305 03C0: CLRF F6E
6306 .................... 6306 ....................
6307 .................... usb_disable_endpoints(); 6307 .................... usb_disable_endpoints();
6308 03C2: RCALL 033E 6308 03C2: RCALL 033E
6309 .................... 6309 ....................
6310 .................... usb_token_reset(); 6310 .................... usb_token_reset();
6311 03C4: RCALL 037E 6311 03C4: RCALL 037E
6312 .................... 6312 ....................
6313 .................... UEP(0) = ENDPT_CONTROL | 0x10; 6313 .................... UEP(0) = ENDPT_CONTROL | 0x10;
6314 03C6: MOVLW 16 6314 03C6: MOVLW 16
6315 03C8: MOVWF F70 6315 03C8: MOVWF F70
6316 .................... 6316 ....................
6317 .................... while (UIR_TRN) 6317 .................... while (UIR_TRN)
6318 .................... { 6318 .................... {
6319 03CA: BTFSS F68.3 6319 03CA: BTFSS F68.3
6320 03CC: BRA 03D2 6320 03CC: BRA 03D2
6321 .................... usb_clear_trn(); 6321 .................... usb_clear_trn();
6322 03CE: RCALL 03AA 6322 03CE: RCALL 03AA
6323 .................... } 6323 .................... }
6324 03D0: BRA 03CA 6324 03D0: BRA 03CA
6325 .................... 6325 ....................
6326 .................... UCON_PKTDIS = 0; //SIE token and packet processing enabled 6326 .................... UCON_PKTDIS = 0; //SIE token and packet processing enabled
6327 03D2: BCF F6D.4 6327 03D2: BCF F6D.4
6328 .................... 6328 ....................
6329 .................... usb_init_ep0_setup(); 6329 .................... usb_init_ep0_setup();
6330 03D4: RCALL 0284 6330 03D4: RCALL 0284
6331 .................... 6331 ....................
6332 .................... usb_state = USB_STATE_DEFAULT; //put usb mcu into default state 6332 .................... usb_state = USB_STATE_DEFAULT; //put usb mcu into default state
6333 03D6: MOVLW 03 6333 03D6: MOVLW 03
6334 03D8: MOVWF 24 6334 03D8: MOVWF 24
6335 .................... } 6335 .................... }
6336 03DA: GOTO 12B4 (RETURN) 6336 03DA: GOTO 12B4 (RETURN)
6337 .................... 6337 ....................
6338 .................... /***************************************************************************** 6338 .................... /*****************************************************************************
6339 .................... /* usb_init_ep0_setup() 6339 .................... /* usb_init_ep0_setup()
6340 .................... /* 6340 .................... /*
6341 .................... /* Summary: Configure EP0 to receive setup packets 6341 .................... /* Summary: Configure EP0 to receive setup packets
6342 .................... /* 6342 .................... /*
6343 .................... /*****************************************************************************/ 6343 .................... /*****************************************************************************/
6344 .................... void usb_init_ep0_setup(void) 6344 .................... void usb_init_ep0_setup(void)
6345 .................... { 6345 .................... {
6346 .................... EP_BDxCNT_O(0) = USB_MAX_EP0_PACKET_LENGTH; 6346 .................... EP_BDxCNT_O(0) = USB_MAX_EP0_PACKET_LENGTH;
6347 * 6347 *
6348 0284: MOVLW 40 6348 0284: MOVLW 40
6349 0286: MOVLB 4 6349 0286: MOVLB 4
6350 0288: MOVWF x01 6350 0288: MOVWF x01
6351 .................... EP_BDxADR_O(0) = USB_DATA_BUFFER_LOCATION; 6351 .................... EP_BDxADR_O(0) = USB_DATA_BUFFER_LOCATION;
6352 028A: MOVLW 04 6352 028A: MOVLW 04
6353 028C: MOVWF x03 6353 028C: MOVWF x03
6354 028E: MOVLW 18 6354 028E: MOVLW 18
6355 0290: MOVWF x02 6355 0290: MOVWF x02
6356 .................... #if USB_IGNORE_RX_DTS 6356 .................... #if USB_IGNORE_RX_DTS
6357 .................... EP_BDxST_O(0) = 0x80; //give control to SIE, data toggle synch off 6357 .................... EP_BDxST_O(0) = 0x80; //give control to SIE, data toggle synch off
6358 .................... #else 6358 .................... #else
6359 .................... EP_BDxST_O(0) = 0x88; //give control to SIE, DATA0, data toggle synch on 6359 .................... EP_BDxST_O(0) = 0x88; //give control to SIE, DATA0, data toggle synch on
6360 0292: MOVLW 88 6360 0292: MOVLW 88
6361 0294: MOVWF x00 6361 0294: MOVWF x00
6362 .................... #endif 6362 .................... #endif
6363 .................... 6363 ....................
6364 .................... EP_BDxST_I(0) = 0; 6364 .................... EP_BDxST_I(0) = 0;
6365 0296: CLRF x04 6365 0296: CLRF x04
6366 .................... EP_BDxADR_I(0) = USB_DATA_BUFFER_LOCATION + (int16)USB_MAX_EP0_PACKET_LENGTH; 6366 .................... EP_BDxADR_I(0) = USB_DATA_BUFFER_LOCATION + (int16)USB_MAX_EP0_PACKET_LENGTH;
6367 0298: MOVLW 04 6367 0298: MOVLW 04
6368 029A: MOVWF x07 6368 029A: MOVWF x07
6369 029C: MOVLW 58 6369 029C: MOVLW 58
6370 029E: MOVWF x06 6370 029E: MOVWF x06
6371 .................... } 6371 .................... }
6372 02A0: MOVLB 0 6372 02A0: MOVLB 0
6373 02A2: RETLW 00 6373 02A2: RETLW 00
6374 .................... 6374 ....................
6375 .................... /******************************************************************************* 6375 .................... /*******************************************************************************
6376 .................... /* usb_isr_uerr() 6376 .................... /* usb_isr_uerr()
6377 .................... /* 6377 .................... /*
6378 .................... /* Summary: The USB peripheral had an error. If user specified, error counter 6378 .................... /* Summary: The USB peripheral had an error. If user specified, error counter
6379 .................... /* will incerement. If having problems check the status of these 8 bytes. 6379 .................... /* will incerement. If having problems check the status of these 8 bytes.
6380 .................... /* 6380 .................... /*
6381 .................... /* NOTE: This code is not enabled by default. 6381 .................... /* NOTE: This code is not enabled by default.
6382 .................... /********************************************************************************/ 6382 .................... /********************************************************************************/
6383 .................... void usb_isr_uerr(void) 6383 .................... void usb_isr_uerr(void)
6384 .................... { 6384 .................... {
6385 .................... #if USB_USE_ERROR_COUNTER 6385 .................... #if USB_USE_ERROR_COUNTER
6386 .................... int ints; 6386 .................... int ints;
6387 .................... #endif 6387 .................... #endif
6388 .................... 6388 ....................
6389 .................... debug_usb(debug_putc,"E %X ",UEIR); 6389 .................... debug_usb(debug_putc,"E %X ",UEIR);
6390 .................... 6390 ....................
6391 .................... #if USB_USE_ERROR_COUNTER 6391 .................... #if USB_USE_ERROR_COUNTER
6392 .................... ints=UEIR & UEIE; //mask off the flags with the ones that are enabled 6392 .................... ints=UEIR & UEIE; //mask off the flags with the ones that are enabled
6393 .................... 6393 ....................
6394 .................... if ( bit_test(ints,0) ) 6394 .................... if ( bit_test(ints,0) )
6395 .................... { 6395 .................... {
6396 .................... //increment pid_error counter 6396 .................... //increment pid_error counter
6397 .................... debug_usb(debug_putc,"PID "); 6397 .................... debug_usb(debug_putc,"PID ");
6398 .................... ERROR_COUNTER[0]++; 6398 .................... ERROR_COUNTER[0]++;
6399 .................... } 6399 .................... }
6400 .................... 6400 ....................
6401 .................... if ( bit_test(ints,1) ) 6401 .................... if ( bit_test(ints,1) )
6402 .................... { 6402 .................... {
6403 .................... //increment crc5 error counter 6403 .................... //increment crc5 error counter
6404 .................... debug_usb(debug_putc,"CRC5 "); 6404 .................... debug_usb(debug_putc,"CRC5 ");
6405 .................... ERROR_COUNTER[1]++; 6405 .................... ERROR_COUNTER[1]++;
6406 .................... } 6406 .................... }
6407 .................... 6407 ....................
6408 .................... if ( bit_test(ints,2) ) 6408 .................... if ( bit_test(ints,2) )
6409 .................... { 6409 .................... {
6410 .................... //increment crc16 error counter 6410 .................... //increment crc16 error counter
6411 .................... debug_usb(debug_putc,"CRC16 "); 6411 .................... debug_usb(debug_putc,"CRC16 ");
6412 .................... ERROR_COUNTER[2]++; 6412 .................... ERROR_COUNTER[2]++;
6413 .................... } 6413 .................... }
6414 .................... 6414 ....................
6415 .................... if ( bit_test(ints,3) ) 6415 .................... if ( bit_test(ints,3) )
6416 .................... { 6416 .................... {
6417 .................... //increment dfn8 error counter 6417 .................... //increment dfn8 error counter
6418 .................... debug_usb(debug_putc,"DFN8 "); 6418 .................... debug_usb(debug_putc,"DFN8 ");
6419 .................... ERROR_COUNTER[3]++; 6419 .................... ERROR_COUNTER[3]++;
6420 .................... } 6420 .................... }
6421 .................... 6421 ....................
6422 .................... if ( bit_test(ints,4) ) 6422 .................... if ( bit_test(ints,4) )
6423 .................... { 6423 .................... {
6424 .................... //increment bto error counter 6424 .................... //increment bto error counter
6425 .................... debug_usb(debug_putc,"BTO "); 6425 .................... debug_usb(debug_putc,"BTO ");
6426 .................... ERROR_COUNTER[4]++; 6426 .................... ERROR_COUNTER[4]++;
6427 .................... } 6427 .................... }
6428 .................... 6428 ....................
6429 .................... if ( bit_test(ints,7) ) 6429 .................... if ( bit_test(ints,7) )
6430 .................... { 6430 .................... {
6431 .................... //increment bts error counter 6431 .................... //increment bts error counter
6432 .................... debug_usb(debug_putc,"BTS "); 6432 .................... debug_usb(debug_putc,"BTS ");
6433 .................... ERROR_COUNTER[5]++; 6433 .................... ERROR_COUNTER[5]++;
6434 .................... } 6434 .................... }
6435 .................... #endif 6435 .................... #endif
6436 .................... 6436 ....................
6437 .................... UEIR = 0; 6437 .................... UEIR = 0;
6438 * 6438 *
6439 02B2: CLRF F6A 6439 02B2: CLRF F6A
6440 .................... UIR_UERR = 0; 6440 .................... UIR_UERR = 0;
6441 02B4: BCF F68.1 6441 02B4: BCF F68.1
6442 .................... } 6442 .................... }
6443 02B6: GOTO 12A8 (RETURN) 6443 02B6: GOTO 12A8 (RETURN)
6444 .................... 6444 ....................
6445 .................... /***************************************************************************** 6445 .................... /*****************************************************************************
6446 .................... /* usb_isr_uidle() 6446 .................... /* usb_isr_uidle()
6447 .................... /* 6447 .................... /*
6448 .................... /* Summary: USB peripheral detected IDLE. Put the USB peripheral to sleep. 6448 .................... /* Summary: USB peripheral detected IDLE. Put the USB peripheral to sleep.
6449 .................... /* 6449 .................... /*
6450 .................... /*****************************************************************************/ 6450 .................... /*****************************************************************************/
6451 .................... void usb_isr_uidle(void) 6451 .................... void usb_isr_uidle(void)
6452 .................... { 6452 .................... {
6453 .................... debug_usb(debug_putc, "I"); 6453 .................... debug_usb(debug_putc, "I");
6454 .................... 6454 ....................
6455 .................... UIE_ACTV = 1; //enable activity interrupt flag. (we are now suspended until we get an activity interrupt. nice) 6455 .................... UIE_ACTV = 1; //enable activity interrupt flag. (we are now suspended until we get an activity interrupt. nice)
6456 * 6456 *
6457 03DE: BSF F69.2 6457 03DE: BSF F69.2
6458 .................... UIR_IDLE = 0; //clear idle interrupt flag 6458 .................... UIR_IDLE = 0; //clear idle interrupt flag
6459 03E0: BCF F68.4 6459 03E0: BCF F68.4
6460 .................... UCON_SUSPND = 1; //set suspend. we are now suspended 6460 .................... UCON_SUSPND = 1; //set suspend. we are now suspended
6461 03E2: BSF F6D.1 6461 03E2: BSF F6D.1
6462 .................... } 6462 .................... }
6463 03E4: GOTO 12C0 (RETURN) 6463 03E4: GOTO 12C0 (RETURN)
6464 .................... 6464 ....................
6465 .................... 6465 ....................
6466 .................... /****************************************************************************** 6466 .................... /******************************************************************************
6467 .................... /* usb_isr_activity() 6467 .................... /* usb_isr_activity()
6468 .................... /* 6468 .................... /*
6469 .................... /* Summary: USB peripheral detected activity on the USB device. Wake-up the USB 6469 .................... /* Summary: USB peripheral detected activity on the USB device. Wake-up the USB
6470 .................... /* peripheral. 6470 .................... /* peripheral.
6471 .................... /* 6471 .................... /*
6472 .................... /*****************************************************************************/ 6472 .................... /*****************************************************************************/
6473 .................... void usb_isr_activity(void) 6473 .................... void usb_isr_activity(void)
6474 .................... { 6474 .................... {
6475 .................... debug_usb(debug_putc, "A"); 6475 .................... debug_usb(debug_putc, "A");
6476 .................... 6476 ....................
6477 .................... UCON_SUSPND = 0; //turn off low power suspending 6477 .................... UCON_SUSPND = 0; //turn off low power suspending
6478 * 6478 *
6479 0274: BCF F6D.1 6479 0274: BCF F6D.1
6480 .................... UIE_ACTV = 0; //clear activity interupt enabling 6480 .................... UIE_ACTV = 0; //clear activity interupt enabling
6481 0276: BCF F69.2 6481 0276: BCF F69.2
6482 .................... 6482 ....................
6483 .................... while(UIR_ACTV) 6483 .................... while(UIR_ACTV)
6484 .................... UIR_ACTV = 0; 6484 .................... UIR_ACTV = 0;
6485 0278: BTFSS F68.2 6485 0278: BTFSS F68.2
6486 027A: BRA 0280 6486 027A: BRA 0280
6487 027C: BCF F68.2 6487 027C: BCF F68.2
6488 027E: BRA 0278 6488 027E: BRA 0278
6489 .................... } 6489 .................... }
6490 0280: GOTO 128A (RETURN) 6490 0280: GOTO 128A (RETURN)
6491 .................... 6491 ....................
6492 .................... /****************************************************************************** 6492 .................... /******************************************************************************
6493 .................... /* usb_isr_stall() 6493 .................... /* usb_isr_stall()
6494 .................... /* 6494 .................... /*
6495 .................... /* Summary: Stall handshake detected. 6495 .................... /* Summary: Stall handshake detected.
6496 .................... /* 6496 .................... /*
6497 .................... /*****************************************************************************/ 6497 .................... /*****************************************************************************/
6498 .................... void usb_isr_stall(void) 6498 .................... void usb_isr_stall(void)
6499 .................... { 6499 .................... {
6500 .................... debug_usb(debug_putc, "S"); 6500 .................... debug_usb(debug_putc, "S");
6501 .................... 6501 ....................
6502 .................... 6502 ....................
6503 .................... if (bit_test(UEP(0),0)) 6503 .................... if (bit_test(UEP(0),0))
6504 * 6504 *
6505 02A4: BTFSS F70.0 6505 02A4: BTFSS F70.0
6506 02A6: BRA 02AC 6506 02A6: BRA 02AC
6507 .................... { 6507 .................... {
6508 .................... usb_init_ep0_setup(); 6508 .................... usb_init_ep0_setup();
6509 02A8: RCALL 0284 6509 02A8: RCALL 0284
6510 .................... bit_clear(UEP(0), 0); 6510 .................... bit_clear(UEP(0), 0);
6511 02AA: BCF F70.0 6511 02AA: BCF F70.0
6512 .................... } 6512 .................... }
6513 .................... 6513 ....................
6514 .................... UIR_STALL = 0; 6514 .................... UIR_STALL = 0;
6515 02AC: BCF F68.5 6515 02AC: BCF F68.5
6516 .................... } 6516 .................... }
6517 02AE: GOTO 129C (RETURN) 6517 02AE: GOTO 129C (RETURN)
6518 .................... 6518 ....................
6519 .................... // see usb_hw_layer.h for documentation 6519 .................... // see usb_hw_layer.h for documentation
6520 .................... void usb_request_send_response(unsigned int8 len) {__setup_0_tx_size = len;} 6520 .................... void usb_request_send_response(unsigned int8 len) {__setup_0_tx_size = len;}
6521 * 6521 *
6522 03EE: MOVFF 700,25 6522 03EE: MOVFF 700,25
6523 03F2: RETLW 00 6523 03F2: RETLW 00
6524 .................... void usb_request_get_data(void) {__setup_0_tx_size = 0xFE;} 6524 .................... void usb_request_get_data(void) {__setup_0_tx_size = 0xFE;}
6525 * 6525 *
6526 0B0C: MOVLW FE 6526 0B0C: MOVLW FE
6527 0B0E: MOVWF 25 6527 0B0E: MOVWF 25
6528 0B10: RETLW 00 6528 0B10: RETLW 00
6529 .................... void usb_request_stall(void) {__setup_0_tx_size = 0xFF;} 6529 .................... void usb_request_stall(void) {__setup_0_tx_size = 0xFF;}
6530 * 6530 *
6531 03F4: MOVLW FF 6531 03F4: MOVLW FF
6532 03F6: MOVWF 25 6532 03F6: MOVWF 25
6533 03F8: RETLW 00 6533 03F8: RETLW 00
6534 .................... 6534 ....................
6535 .................... /***************************************************************************** 6535 .................... /*****************************************************************************
6536 .................... /* usb_isr_tok_dne() 6536 .................... /* usb_isr_tok_dne()
6537 .................... /* 6537 .................... /*
6538 .................... /* Summary: A Token (IN/OUT/SETUP) has been received by the USB peripheral. 6538 .................... /* Summary: A Token (IN/OUT/SETUP) has been received by the USB peripheral.
6539 .................... /* If a setup token on EP0 was received, run the chapter 9 code and 6539 .................... /* If a setup token on EP0 was received, run the chapter 9 code and
6540 .................... /* handle the request. 6540 .................... /* handle the request.
6541 .................... /* If an IN token on EP0 was received, continue transmitting any 6541 .................... /* If an IN token on EP0 was received, continue transmitting any
6542 .................... /* unfinished requests that may take more than one packet to transmit 6542 .................... /* unfinished requests that may take more than one packet to transmit
6543 .................... /* (if necessary). 6543 .................... /* (if necessary).
6544 .................... /* If an OUT token on any other EP was received, mark that EP as ready 6544 .................... /* If an OUT token on any other EP was received, mark that EP as ready
6545 .................... /* for a usb_get_packet(). 6545 .................... /* for a usb_get_packet().
6546 .................... /* Does not handle any IN or OUT tokens on EP0. 6546 .................... /* Does not handle any IN or OUT tokens on EP0.
6547 .................... /* 6547 .................... /*
6548 .................... /*****************************************************************************/ 6548 .................... /*****************************************************************************/
6549 .................... void usb_isr_tok_dne(void) 6549 .................... void usb_isr_tok_dne(void)
6550 .................... { 6550 .................... {
6551 .................... int8 en; 6551 .................... int8 en;
6552 .................... 6552 ....................
6553 .................... en = USTAT>>3; 6553 .................... en = USTAT>>3;
6554 * 6554 *
6555 108A: RRCF F6C,W 6555 108A: RRCF F6C,W
6556 108C: MOVLB 6 6556 108C: MOVLB 6
6557 108E: MOVWF xFB 6557 108E: MOVWF xFB
6558 1090: RRCF xFB,F 6558 1090: RRCF xFB,F
6559 1092: RRCF xFB,F 6559 1092: RRCF xFB,F
6560 1094: MOVLW 1F 6560 1094: MOVLW 1F
6561 1096: ANDWF xFB,F 6561 1096: ANDWF xFB,F
6562 .................... 6562 ....................
6563 .................... debug_usb(debug_putc, "T "); 6563 .................... debug_usb(debug_putc, "T ");
6564 .................... debug_usb(debug_putc, "%X ", USTAT); 6564 .................... debug_usb(debug_putc, "%X ", USTAT);
6565 .................... 6565 ....................
6566 .................... if (USTAT == USTAT_OUT_SETUP_E0) 6566 .................... if (USTAT == USTAT_OUT_SETUP_E0)
6567 1098: MOVF F6C,F 6567 1098: MOVF F6C,F
6568 109A: BNZ 1138 6568 109A: BNZ 1138
6569 .................... { 6569 .................... {
6570 .................... //new out or setup token in the buffer 6570 .................... //new out or setup token in the buffer
6571 .................... int8 pidKey; 6571 .................... int8 pidKey;
6572 .................... 6572 ....................
6573 .................... debug_usb(debug_putc,"%X ", EP_BDxST_O(0)); 6573 .................... debug_usb(debug_putc,"%X ", EP_BDxST_O(0));
6574 .................... 6574 ....................
6575 .................... pidKey = EP_BDxST_O(0) & 0x3C; //save PID 6575 .................... pidKey = EP_BDxST_O(0) & 0x3C; //save PID
6576 109C: MOVLB 4 6576 109C: MOVLB 4
6577 109E: MOVF x00,W 6577 109E: MOVF x00,W
6578 10A0: ANDLW 3C 6578 10A0: ANDLW 3C
6579 10A2: MOVLB 6 6579 10A2: MOVLB 6
6580 10A4: MOVWF xFC 6580 10A4: MOVWF xFC
6581 .................... 6581 ....................
6582 .................... EP_BDxST_O(0) &= 0x43; //clear pid, prevent bdstal/pid confusion 6582 .................... EP_BDxST_O(0) &= 0x43; //clear pid, prevent bdstal/pid confusion
6583 10A6: MOVLW 43 6583 10A6: MOVLW 43
6584 10A8: MOVLB 4 6584 10A8: MOVLB 4
6585 10AA: ANDWF x00,F 6585 10AA: ANDWF x00,F
6586 .................... usb_clear_trn(); 6586 .................... usb_clear_trn();
6587 10AC: MOVLB 0 6587 10AC: MOVLB 0
6588 10AE: CALL 03AA 6588 10AE: CALL 03AA
6589 .................... 6589 ....................
6590 .................... if (pidKey == USB_PIC_PID_SETUP) 6590 .................... if (pidKey == USB_PIC_PID_SETUP)
6591 10B2: MOVLB 6 6591 10B2: MOVLB 6
6592 10B4: MOVF xFC,W 6592 10B4: MOVF xFC,W
6593 10B6: SUBLW 34 6593 10B6: SUBLW 34
6594 10B8: BNZ 10FE 6594 10B8: BNZ 10FE
6595 .................... { 6595 .................... {
6596 .................... EP_BDxST_I(0)=0; // return the in buffer to us (dequeue any pending requests) 6596 .................... EP_BDxST_I(0)=0; // return the in buffer to us (dequeue any pending requests)
6597 10BA: MOVLB 4 6597 10BA: MOVLB 4
6598 10BC: CLRF x04 6598 10BC: CLRF x04
6599 .................... 6599 ....................
6600 .................... debug_usb(debug_putc,"(%U) ", EP_BDxCNT_O(0)); 6600 .................... debug_usb(debug_putc,"(%U) ", EP_BDxCNT_O(0));
6601 .................... debug_display_ram(EP_BDxCNT_O(0), usb_ep0_rx_buffer); 6601 .................... debug_display_ram(EP_BDxCNT_O(0), usb_ep0_rx_buffer);
6602 .................... 6602 ....................
6603 .................... usb_isr_tok_setup_dne(); 6603 .................... usb_isr_tok_setup_dne();
6604 10BE: MOVLB 0 6604 10BE: MOVLB 0
6605 10C0: BRA 0BC0 6605 10C0: BRA 0BC0
6606 .................... 6606 ....................
6607 .................... UCON_PKTDIS=0; // UCON,PKT_DIS ; Assuming there is nothing to dequeue, clear the packet disable bit 6607 .................... UCON_PKTDIS=0; // UCON,PKT_DIS ; Assuming there is nothing to dequeue, clear the packet disable bit
6608 10C2: BCF F6D.4 6608 10C2: BCF F6D.4
6609 .................... 6609 ....................
6610 .................... //if setup_0_tx_size==0xFF - stall ep0 (unhandled request) (see usb_request_stall()) 6610 .................... //if setup_0_tx_size==0xFF - stall ep0 (unhandled request) (see usb_request_stall())
6611 .................... //if setup_0_tx_size==0xFE - get EP0OUT ready for a data packet, leave EP0IN alone (see usb_request_get_data()) 6611 .................... //if setup_0_tx_size==0xFE - get EP0OUT ready for a data packet, leave EP0IN alone (see usb_request_get_data())
6612 .................... //else setup_0_tx_size=size of response, get EP0OUT ready for a setup packet, mark EPOIN ready for transmit (see usb_request_send_response()) 6612 .................... //else setup_0_tx_size=size of response, get EP0OUT ready for a setup packet, mark EPOIN ready for transmit (see usb_request_send_response())
6613 .................... if (__setup_0_tx_size == 0xFF) 6613 .................... if (__setup_0_tx_size == 0xFF)
6614 10C4: INCFSZ 25,W 6614 10C4: INCFSZ 25,W
6615 10C6: BRA 10D6 6615 10C6: BRA 10D6
6616 .................... usb_flush_out(0, USB_DTS_STALL); 6616 .................... usb_flush_out(0, USB_DTS_STALL);
6617 10C8: MOVLB 6 6617 10C8: MOVLB 6
6618 10CA: CLRF xFD 6618 10CA: CLRF xFD
6619 10CC: MOVLW 03 6619 10CC: MOVLW 03
6620 10CE: MOVWF xFE 6620 10CE: MOVWF xFE
6621 10D0: MOVLB 0 6621 10D0: MOVLB 0
6622 10D2: RCALL 0BEA 6622 10D2: RCALL 0BEA
6623 .................... else 6623 .................... else
6624 10D4: BRA 10FA 6624 10D4: BRA 10FA
6625 .................... { 6625 .................... {
6626 .................... usb_flush_out(0, USB_DTS_TOGGLE); 6626 .................... usb_flush_out(0, USB_DTS_TOGGLE);
6627 10D6: MOVLB 6 6627 10D6: MOVLB 6
6628 10D8: CLRF xFD 6628 10D8: CLRF xFD
6629 10DA: MOVLW 02 6629 10DA: MOVLW 02
6630 10DC: MOVWF xFE 6630 10DC: MOVWF xFE
6631 10DE: MOVLB 0 6631 10DE: MOVLB 0
6632 10E0: RCALL 0BEA 6632 10E0: RCALL 0BEA
6633 .................... if (__setup_0_tx_size != 0xFE) 6633 .................... if (__setup_0_tx_size != 0xFE)
6634 10E2: MOVF 25,W 6634 10E2: MOVF 25,W
6635 10E4: SUBLW FE 6635 10E4: SUBLW FE
6636 10E6: BZ 10FA 6636 10E6: BZ 10FA
6637 .................... usb_flush_in(0 ,__setup_0_tx_size, USB_DTS_USERX); 6637 .................... usb_flush_in(0 ,__setup_0_tx_size, USB_DTS_USERX);
6638 10E8: MOVLB 7 6638 10E8: MOVLB 7
6639 10EA: CLRF x42 6639 10EA: CLRF x42
6640 10EC: CLRF x44 6640 10EC: CLRF x44
6641 10EE: MOVFF 25,743 6641 10EE: MOVFF 25,743
6642 10F2: MOVLW 04 6642 10F2: MOVLW 04
6643 10F4: MOVWF x45 6643 10F4: MOVWF x45
6644 10F6: MOVLB 0 6644 10F6: MOVLB 0
6645 10F8: RCALL 0D5C 6645 10F8: RCALL 0D5C
6646 .................... } 6646 .................... }
6647 .................... //why was this here? 6647 .................... //why was this here?
6648 .................... //UCON_PKTDIS=0; // UCON,PKT_DIS ; Assuming there is nothing to dequeue, clear the packet disable bit 6648 .................... //UCON_PKTDIS=0; // UCON,PKT_DIS ; Assuming there is nothing to dequeue, clear the packet disable bit
6649 .................... } 6649 .................... }
6650 .................... else if (pidKey == USB_PIC_PID_OUT) 6650 .................... else if (pidKey == USB_PIC_PID_OUT)
6651 10FA: BRA 1134 6651 10FA: BRA 1134
6652 10FC: MOVLB 6 6652 10FC: MOVLB 6
6653 10FE: MOVF xFC,W 6653 10FE: MOVF xFC,W
6654 1100: SUBLW 04 6654 1100: SUBLW 04
6655 1102: BNZ 1136 6655 1102: BNZ 1136
6656 .................... { 6656 .................... {
6657 .................... usb_isr_tok_out_dne(0); 6657 .................... usb_isr_tok_out_dne(0);
6658 1104: CLRF xFD 6658 1104: CLRF xFD
6659 1106: MOVLB 0 6659 1106: MOVLB 0
6660 1108: RCALL 0F42 6660 1108: RCALL 0F42
6661 .................... usb_flush_out(0, USB_DTS_TOGGLE); 6661 .................... usb_flush_out(0, USB_DTS_TOGGLE);
6662 110A: MOVLB 6 6662 110A: MOVLB 6
6663 110C: CLRF xFD 6663 110C: CLRF xFD
6664 110E: MOVLW 02 6664 110E: MOVLW 02
6665 1110: MOVWF xFE 6665 1110: MOVWF xFE
6666 1112: MOVLB 0 6666 1112: MOVLB 0
6667 1114: RCALL 0BEA 6667 1114: RCALL 0BEA
6668 .................... if ((__setup_0_tx_size!=0xFE) && (__setup_0_tx_size!=0xFF)) 6668 .................... if ((__setup_0_tx_size!=0xFE) && (__setup_0_tx_size!=0xFF))
6669 1116: MOVF 25,W 6669 1116: MOVF 25,W
6670 1118: SUBLW FE 6670 1118: SUBLW FE
6671 111A: BZ 1134 6671 111A: BZ 1134
6672 111C: INCFSZ 25,W 6672 111C: INCFSZ 25,W
6673 111E: BRA 1122 6673 111E: BRA 1122
6674 1120: BRA 1134 6674 1120: BRA 1134
6675 .................... { 6675 .................... {
6676 .................... usb_flush_in(0,__setup_0_tx_size,USB_DTS_DATA1); //send response (usually a 0len) 6676 .................... usb_flush_in(0,__setup_0_tx_size,USB_DTS_DATA1); //send response (usually a 0len)
6677 1122: MOVLB 7 6677 1122: MOVLB 7
6678 1124: CLRF x42 6678 1124: CLRF x42
6679 1126: CLRF x44 6679 1126: CLRF x44
6680 1128: MOVFF 25,743 6680 1128: MOVFF 25,743
6681 112C: MOVLW 01 6681 112C: MOVLW 01
6682 112E: MOVWF x45 6682 112E: MOVWF x45
6683 1130: MOVLB 0 6683 1130: MOVLB 0
6684 1132: RCALL 0D5C 6684 1132: RCALL 0D5C
6685 1134: MOVLB 6 6685 1134: MOVLB 6
6686 .................... } 6686 .................... }
6687 .................... } 6687 .................... }
6688 .................... } 6688 .................... }
6689 .................... else if (USTAT == USTAT_IN_E0) 6689 .................... else if (USTAT == USTAT_IN_E0)
6690 1136: BRA 126E 6690 1136: BRA 126E
6691 1138: MOVF F6C,W 6691 1138: MOVF F6C,W
6692 113A: SUBLW 04 6692 113A: SUBLW 04
6693 113C: BNZ 1178 6693 113C: BNZ 1178
6694 .................... { 6694 .................... {
6695 .................... //pic -> host transfer completed 6695 .................... //pic -> host transfer completed
6696 .................... EP_BDxST_I(0) = EP_BDxST_I(0) & 0x43; //clear up any BDSTAL confusion 6696 .................... EP_BDxST_I(0) = EP_BDxST_I(0) & 0x43; //clear up any BDSTAL confusion
6697 113E: MOVLW 43 6697 113E: MOVLW 43
6698 1140: MOVLB 4 6698 1140: MOVLB 4
6699 1142: ANDWF x04,F 6699 1142: ANDWF x04,F
6700 .................... usb_clear_trn(); 6700 .................... usb_clear_trn();
6701 1144: MOVLB 0 6701 1144: MOVLB 0
6702 1146: CALL 03AA 6702 1146: CALL 03AA
6703 .................... __setup_0_tx_size = 0xFF; 6703 .................... __setup_0_tx_size = 0xFF;
6704 114A: MOVLW FF 6704 114A: MOVLW FF
6705 114C: MOVWF 25 6705 114C: MOVWF 25
6706 .................... usb_isr_tok_in_dne(0); 6706 .................... usb_isr_tok_in_dne(0);
6707 114E: MOVLB 6 6707 114E: MOVLB 6
6708 1150: CLRF xFD 6708 1150: CLRF xFD
6709 1152: MOVLB 0 6709 1152: MOVLB 0
6710 1154: RCALL 1058 6710 1154: RCALL 1058
6711 .................... if (__setup_0_tx_size!=0xFF) 6711 .................... if (__setup_0_tx_size!=0xFF)
6712 1156: INCFSZ 25,W 6712 1156: INCFSZ 25,W
6713 1158: BRA 115C 6713 1158: BRA 115C
6714 115A: BRA 1170 6714 115A: BRA 1170
6715 .................... usb_flush_in(0, __setup_0_tx_size, USB_DTS_TOGGLE); 6715 .................... usb_flush_in(0, __setup_0_tx_size, USB_DTS_TOGGLE);
6716 115C: MOVLB 7 6716 115C: MOVLB 7
6717 115E: CLRF x42 6717 115E: CLRF x42
6718 1160: CLRF x44 6718 1160: CLRF x44
6719 1162: MOVFF 25,743 6719 1162: MOVFF 25,743
6720 1166: MOVLW 02 6720 1166: MOVLW 02
6721 1168: MOVWF x45 6721 1168: MOVWF x45
6722 116A: MOVLB 0 6722 116A: MOVLB 0
6723 116C: RCALL 0D5C 6723 116C: RCALL 0D5C
6724 .................... else 6724 .................... else
6725 116E: BRA 1174 6725 116E: BRA 1174
6726 .................... usb_init_ep0_setup(); 6726 .................... usb_init_ep0_setup();
6727 1170: CALL 0284 6727 1170: CALL 0284
6728 .................... } 6728 .................... }
6729 .................... else 6729 .................... else
6730 1174: BRA 126C 6730 1174: BRA 126C
6731 1176: MOVLB 6 6731 1176: MOVLB 6
6732 .................... { 6732 .................... {
6733 .................... if (!bit_test(USTAT, 2)) 6733 .................... if (!bit_test(USTAT, 2))
6734 1178: BTFSC F6C.2 6734 1178: BTFSC F6C.2
6735 117A: BRA 11E6 6735 117A: BRA 11E6
6736 .................... { 6736 .................... {
6737 .................... EP_BDxST_O(en) = EP_BDxST_O(en) & 0x43; //clear up any BDSTAL confusion 6737 .................... EP_BDxST_O(en) = EP_BDxST_O(en) & 0x43; //clear up any BDSTAL confusion
6738 117C: MOVLB 7 6738 117C: MOVLB 7
6739 117E: CLRF x49 6739 117E: CLRF x49
6740 1180: MOVFF 6FB,748 6740 1180: MOVFF 6FB,748
6741 1184: CLRF x4B 6741 1184: CLRF x4B
6742 1186: MOVLW 08 6742 1186: MOVLW 08
6743 1188: MOVWF x4A 6743 1188: MOVWF x4A
6744 118A: MOVLB 0 6744 118A: MOVLB 0
6745 118C: CALL 02BA 6745 118C: CALL 02BA
6746 1190: MOVFF 01,6FD 6746 1190: MOVFF 01,6FD
6747 1194: MOVLB 6 6747 1194: MOVLB 6
6748 1196: MOVFF 01,01 6748 1196: MOVFF 01,01
6749 119A: MOVLW 04 6749 119A: MOVLW 04
6750 119C: ADDWF 02,W 6750 119C: ADDWF 02,W
6751 119E: MOVWF 03 6751 119E: MOVWF 03
6752 11A0: MOVFF 01,6FD 6752 11A0: MOVFF 01,6FD
6753 11A4: MOVWF xFE 6753 11A4: MOVWF xFE
6754 11A6: MOVLB 7 6754 11A6: MOVLB 7
6755 11A8: CLRF x49 6755 11A8: CLRF x49
6756 11AA: MOVFF 6FB,748 6756 11AA: MOVFF 6FB,748
6757 11AE: CLRF x4B 6757 11AE: CLRF x4B
6758 11B0: MOVLW 08 6758 11B0: MOVLW 08
6759 11B2: MOVWF x4A 6759 11B2: MOVWF x4A
6760 11B4: MOVLB 0 6760 11B4: MOVLB 0
6761 11B6: CALL 02BA 6761 11B6: CALL 02BA
6762 11BA: MOVFF 01,FE9 6762 11BA: MOVFF 01,FE9
6763 11BE: MOVLW 04 6763 11BE: MOVLW 04
6764 11C0: MOVLB 7 6764 11C0: MOVLB 7
6765 11C2: ADDWF 02,W 6765 11C2: ADDWF 02,W
6766 11C4: MOVWF FEA 6766 11C4: MOVWF FEA
6767 11C6: MOVF FEF,W 6767 11C6: MOVF FEF,W
6768 11C8: ANDLW 43 6768 11C8: ANDLW 43
6769 11CA: MOVLB 6 6769 11CA: MOVLB 6
6770 11CC: MOVFF 6FE,FEA 6770 11CC: MOVFF 6FE,FEA
6771 11D0: MOVFF 6FD,FE9 6771 11D0: MOVFF 6FD,FE9
6772 11D4: MOVWF FEF 6772 11D4: MOVWF FEF
6773 .................... usb_clear_trn(); 6773 .................... usb_clear_trn();
6774 11D6: MOVLB 0 6774 11D6: MOVLB 0
6775 11D8: CALL 03AA 6775 11D8: CALL 03AA
6776 .................... usb_isr_tok_out_dne(en); 6776 .................... usb_isr_tok_out_dne(en);
6777 11DC: MOVFF 6FB,6FD 6777 11DC: MOVFF 6FB,6FD
6778 11E0: RCALL 0F42 6778 11E0: RCALL 0F42
6779 .................... } 6779 .................... }
6780 .................... else 6780 .................... else
6781 11E2: BRA 126C 6781 11E2: BRA 126C
6782 11E4: MOVLB 6 6782 11E4: MOVLB 6
6783 .................... { 6783 .................... {
6784 .................... EP_BDxST_I(en) = EP_BDxST_I(en) & 0x43; //clear up any BDSTAL confusion 6784 .................... EP_BDxST_I(en) = EP_BDxST_I(en) & 0x43; //clear up any BDSTAL confusion
6785 11E6: MOVLB 7 6785 11E6: MOVLB 7
6786 11E8: CLRF x49 6786 11E8: CLRF x49
6787 11EA: MOVFF 6FB,748 6787 11EA: MOVFF 6FB,748
6788 11EE: CLRF x4B 6788 11EE: CLRF x4B
6789 11F0: MOVLW 08 6789 11F0: MOVLW 08
6790 11F2: MOVWF x4A 6790 11F2: MOVWF x4A
6791 11F4: MOVLB 0 6791 11F4: MOVLB 0
6792 11F6: CALL 02BA 6792 11F6: CALL 02BA
6793 11FA: MOVFF 02,6FE 6793 11FA: MOVFF 02,6FE
6794 11FE: MOVFF 01,6FD 6794 11FE: MOVFF 01,6FD
6795 1202: MOVLW 04 6795 1202: MOVLW 04
6796 1204: MOVLB 6 6796 1204: MOVLB 6
6797 1206: ADDWF xFD,F 6797 1206: ADDWF xFD,F
6798 1208: MOVLW 00 6798 1208: MOVLW 00
6799 120A: ADDWFC xFE,F 6799 120A: ADDWFC xFE,F
6800 120C: MOVFF 6FD,01 6800 120C: MOVFF 6FD,01
6801 1210: MOVLW 04 6801 1210: MOVLW 04
6802 1212: ADDWF xFE,W 6802 1212: ADDWF xFE,W
6803 1214: MOVWF 03 6803 1214: MOVWF 03
6804 1216: MOVFF 6FD,6FD 6804 1216: MOVFF 6FD,6FD
6805 121A: MOVWF xFE 6805 121A: MOVWF xFE
6806 121C: MOVLB 7 6806 121C: MOVLB 7
6807 121E: CLRF x49 6807 121E: CLRF x49
6808 1220: MOVFF 6FB,748 6808 1220: MOVFF 6FB,748
6809 1224: CLRF x4B 6809 1224: CLRF x4B
6810 1226: MOVLW 08 6810 1226: MOVLW 08
6811 1228: MOVWF x4A 6811 1228: MOVWF x4A
6812 122A: MOVLB 0 6812 122A: MOVLB 0
6813 122C: CALL 02BA 6813 122C: CALL 02BA
6814 1230: MOVFF 02,700 6814 1230: MOVFF 02,700
6815 1234: MOVFF 01,6FF 6815 1234: MOVFF 01,6FF
6816 1238: MOVLW 04 6816 1238: MOVLW 04
6817 123A: MOVLB 6 6817 123A: MOVLB 6
6818 123C: ADDWF xFF,F 6818 123C: ADDWF xFF,F
6819 123E: MOVLW 00 6819 123E: MOVLW 00
6820 1240: MOVLB 7 6820 1240: MOVLB 7
6821 1242: ADDWFC x00,F 6821 1242: ADDWFC x00,F
6822 1244: MOVFF 6FF,FE9 6822 1244: MOVFF 6FF,FE9
6823 1248: MOVLW 04 6823 1248: MOVLW 04
6824 124A: MOVLB 7 6824 124A: MOVLB 7
6825 124C: ADDWF x00,W 6825 124C: ADDWF x00,W
6826 124E: MOVWF FEA 6826 124E: MOVWF FEA
6827 1250: MOVF FEF,W 6827 1250: MOVF FEF,W
6828 1252: ANDLW 43 6828 1252: ANDLW 43
6829 1254: MOVLB 6 6829 1254: MOVLB 6
6830 1256: MOVFF 6FE,FEA 6830 1256: MOVFF 6FE,FEA
6831 125A: MOVFF 6FD,FE9 6831 125A: MOVFF 6FD,FE9
6832 125E: MOVWF FEF 6832 125E: MOVWF FEF
6833 .................... usb_clear_trn(); 6833 .................... usb_clear_trn();
6834 1260: MOVLB 0 6834 1260: MOVLB 0
6835 1262: CALL 03AA 6835 1262: CALL 03AA
6836 .................... usb_isr_tok_in_dne(en); 6836 .................... usb_isr_tok_in_dne(en);
6837 1266: MOVFF 6FB,6FD 6837 1266: MOVFF 6FB,6FD
6838 126A: RCALL 1058 6838 126A: RCALL 1058
6839 126C: MOVLB 6 6839 126C: MOVLB 6
6840 .................... } 6840 .................... }
6841 .................... } 6841 .................... }
6842 .................... } 6842 .................... }
6843 126E: MOVLB 0 6843 126E: MOVLB 0
6844 1270: GOTO 12DC (RETURN) 6844 1270: GOTO 12DC (RETURN)
6845 .................... 6845 ....................
6846 .................... /// END USB Interrupt Service Routine 6846 .................... /// END USB Interrupt Service Routine
6847 .................... 6847 ....................
6848 .................... #ENDIF 6848 .................... #ENDIF
6849 .................... 6849 ....................
6850 .................... #endif 6850 .................... #endif
6851 .................... 6851 ....................
6852 .................... #if defined(__PIC24_USB_H__) 6852 .................... #if defined(__PIC24_USB_H__)
6853 .................... #include <pic24_usb.c> 6853 .................... #include <pic24_usb.c>
6854 .................... #endif 6854 .................... #endif
6855 .................... 6855 ....................
6856 .................... #if defined(__USBN960X_H__) 6856 .................... #if defined(__USBN960X_H__)
6857 .................... #include <usbn960x.c> 6857 .................... #include <usbn960x.c>
6858 .................... #endif 6858 .................... #endif
6859 .................... 6859 ....................
6860 .................... 6860 ....................
6861 .................... #IFNDEF __USB_HARDWARE__ 6861 .................... #IFNDEF __USB_HARDWARE__
6862 .................... #ERROR You must include USB hardware driver. 6862 .................... #ERROR You must include USB hardware driver.
6863 .................... #ENDIF 6863 .................... #ENDIF
6864 .................... 6864 ....................
6865 .................... #IFNDEF __USB_DESCRIPTORS__ 6865 .................... #IFNDEF __USB_DESCRIPTORS__
6866 .................... #ERROR You must include USB descriptors. 6866 .................... #ERROR You must include USB descriptors.
6867 .................... #ENDIF 6867 .................... #ENDIF
6868 .................... 6868 ....................
6869 .................... TYPE_USB_STACK_STATUS USB_stack_status; 6869 .................... TYPE_USB_STACK_STATUS USB_stack_status;
6870 .................... 6870 ....................
6871 .................... int8 USB_address_pending; //save previous state because packets can take several isrs 6871 .................... int8 USB_address_pending; //save previous state because packets can take several isrs
6872 .................... int8 usb_getdesc_ptr; unsigned int8 usb_getdesc_len=0; //for reading string and config descriptors 6872 .................... int8 usb_getdesc_ptr; unsigned int8 usb_getdesc_len=0; //for reading string and config descriptors
6873 .................... 6873 ....................
6874 .................... #IF USB_HID_BOOT_PROTOCOL 6874 .................... #IF USB_HID_BOOT_PROTOCOL
6875 .................... int8 hid_protocol[USB_NUM_HID_INTERFACES]; 6875 .................... int8 hid_protocol[USB_NUM_HID_INTERFACES];
6876 .................... #ENDIF 6876 .................... #ENDIF
6877 .................... 6877 ....................
6878 .................... void usb_put_0len_0(void); 6878 .................... void usb_put_0len_0(void);
6879 .................... void usb_match_registers(int8 endpoint, int16 *status, int16 *buffer, int8 *size); 6879 .................... void usb_match_registers(int8 endpoint, int16 *status, int16 *buffer, int8 *size);
6880 .................... 6880 ....................
6881 .................... void usb_isr_tkn_setup_StandardEndpoint(void); 6881 .................... void usb_isr_tkn_setup_StandardEndpoint(void);
6882 .................... void usb_isr_tkn_setup_StandardDevice(void); 6882 .................... void usb_isr_tkn_setup_StandardDevice(void);
6883 .................... void usb_isr_tkn_setup_StandardInterface(void); 6883 .................... void usb_isr_tkn_setup_StandardInterface(void);
6884 .................... #IF USB_HID_DEVICE 6884 .................... #IF USB_HID_DEVICE
6885 .................... void usb_isr_tkn_setup_ClassInterface(void); 6885 .................... void usb_isr_tkn_setup_ClassInterface(void);
6886 .................... #ENDIF 6886 .................... #ENDIF
6887 .................... void usb_Get_Descriptor(void); 6887 .................... void usb_Get_Descriptor(void);
6888 .................... void usb_copy_desc_seg_to_ep(void); 6888 .................... void usb_copy_desc_seg_to_ep(void);
6889 .................... void usb_finish_set_address(void); 6889 .................... void usb_finish_set_address(void);
6890 .................... 6890 ....................
6891 .................... int8 USB_Interface[USB_MAX_NUM_INTERFACES]; //config state for all of our interfaces, NUM_INTERFACES defined with descriptors 6891 .................... int8 USB_Interface[USB_MAX_NUM_INTERFACES]; //config state for all of our interfaces, NUM_INTERFACES defined with descriptors
6892 .................... 6892 ....................
6893 .................... /// BEGIN User Functions 6893 .................... /// BEGIN User Functions
6894 .................... 6894 ....................
6895 .................... // see usb.h for documentation 6895 .................... // see usb.h for documentation
6896 .................... int1 usb_enumerated(void) 6896 .................... int1 usb_enumerated(void)
6897 .................... { 6897 .................... {
6898 .................... return(USB_stack_status.curr_config); 6898 .................... return(USB_stack_status.curr_config);
6899 .................... } 6899 .................... }
6900 .................... 6900 ....................
6901 .................... // see usb.h for documentation 6901 .................... // see usb.h for documentation
6902 .................... void usb_wait_for_enumeration(void) 6902 .................... void usb_wait_for_enumeration(void)
6903 .................... { 6903 .................... {
6904 .................... while (USB_stack_status.curr_config == 0) {restart_wdt();} 6904 .................... while (USB_stack_status.curr_config == 0) {restart_wdt();}
6905 .................... } 6905 .................... }
6906 .................... 6906 ....................
6907 .................... // see USB.H for documentation 6907 .................... // see USB.H for documentation
6908 .................... int1 usb_puts(int8 endpoint, int8 * ptr, unsigned int16 len, unsigned int8 timeout) { 6908 .................... int1 usb_puts(int8 endpoint, int8 * ptr, unsigned int16 len, unsigned int8 timeout) {
6909 .................... unsigned int16 i=0; 6909 .................... unsigned int16 i=0;
6910 .................... int1 res; 6910 .................... int1 res;
6911 .................... unsigned int16 this_packet_len; 6911 .................... unsigned int16 this_packet_len;
6912 .................... unsigned int16 packet_size; 6912 .................... unsigned int16 packet_size;
6913 .................... unsigned int32 timeout_1us; 6913 .................... unsigned int32 timeout_1us;
6914 .................... 6914 ....................
6915 .................... packet_size = usb_ep_tx_size[endpoint]; 6915 .................... packet_size = usb_ep_tx_size[endpoint];
6916 .................... 6916 ....................
6917 .................... //printf("\r\nUSB PUTS %U LEN=%LU MAX_PACK=%LU\r\n", endpoint, len, packet_size); 6917 .................... //printf("\r\nUSB PUTS %U LEN=%LU MAX_PACK=%LU\r\n", endpoint, len, packet_size);
6918 .................... 6918 ....................
6919 .................... //send data packets until timeout or no more packets to send 6919 .................... //send data packets until timeout or no more packets to send
6920 .................... while (i < len) 6920 .................... while (i < len)
6921 .................... { 6921 .................... {
6922 .................... timeout_1us = (int32)timeout*1000; 6922 .................... timeout_1us = (int32)timeout*1000;
6923 .................... if ((len - i) > packet_size) {this_packet_len = packet_size;} 6923 .................... if ((len - i) > packet_size) {this_packet_len = packet_size;}
6924 .................... else {this_packet_len = len-i;} 6924 .................... else {this_packet_len = len-i;}
6925 .................... //putc('*'); 6925 .................... //putc('*');
6926 .................... do 6926 .................... do
6927 .................... { 6927 .................... {
6928 .................... res = usb_put_packet(endpoint, ptr + i, this_packet_len, USB_DTS_TOGGLE); //send 64 byte packets 6928 .................... res = usb_put_packet(endpoint, ptr + i, this_packet_len, USB_DTS_TOGGLE); //send 64 byte packets
6929 .................... //putc('.'); 6929 .................... //putc('.');
6930 .................... if (!res) 6930 .................... if (!res)
6931 .................... { 6931 .................... {
6932 .................... delay_us(1); 6932 .................... delay_us(1);
6933 .................... //delay_ms(500); 6933 .................... //delay_ms(500);
6934 .................... timeout_1us--; 6934 .................... timeout_1us--;
6935 .................... } 6935 .................... }
6936 .................... } while (!res && timeout_1us); 6936 .................... } while (!res && timeout_1us);
6937 .................... i += packet_size; 6937 .................... i += packet_size;
6938 .................... } 6938 .................... }
6939 .................... 6939 ....................
6940 .................... 6940 ....................
6941 .................... //send 0len packet if needed 6941 .................... //send 0len packet if needed
6942 .................... if (i==len) { 6942 .................... if (i==len) {
6943 .................... timeout_1us=(int32)timeout*1000; 6943 .................... timeout_1us=(int32)timeout*1000;
6944 .................... do { 6944 .................... do {
6945 .................... res = usb_put_packet(endpoint,0,0,USB_DTS_TOGGLE); //indicate end of message 6945 .................... res = usb_put_packet(endpoint,0,0,USB_DTS_TOGGLE); //indicate end of message
6946 .................... if (!res) { 6946 .................... if (!res) {
6947 .................... delay_us(1); 6947 .................... delay_us(1);
6948 .................... timeout_1us--; 6948 .................... timeout_1us--;
6949 .................... } 6949 .................... }
6950 .................... } while (!res && timeout_1us); 6950 .................... } while (!res && timeout_1us);
6951 .................... } 6951 .................... }
6952 .................... 6952 ....................
6953 .................... return(res); 6953 .................... return(res);
6954 .................... } 6954 .................... }
6955 .................... 6955 ....................
6956 .................... // see usb.h for documentation 6956 .................... // see usb.h for documentation
6957 .................... unsigned int16 usb_gets(int8 endpoint, int8 * ptr, unsigned int16 max, unsigned int16 timeout) { 6957 .................... unsigned int16 usb_gets(int8 endpoint, int8 * ptr, unsigned int16 max, unsigned int16 timeout) {
6958 .................... unsigned int16 ret=0; 6958 .................... unsigned int16 ret=0;
6959 .................... unsigned int16 to; 6959 .................... unsigned int16 to;
6960 .................... unsigned int16 len; 6960 .................... unsigned int16 len;
6961 .................... unsigned int16 packet_size; 6961 .................... unsigned int16 packet_size;
6962 .................... unsigned int16 this_packet_max; 6962 .................... unsigned int16 this_packet_max;
6963 .................... 6963 ....................
6964 .................... packet_size=usb_ep_rx_size[endpoint]; 6964 .................... packet_size=usb_ep_rx_size[endpoint];
6965 .................... 6965 ....................
6966 .................... do { 6966 .................... do {
6967 .................... if (packet_size < max) {this_packet_max=packet_size;} else {this_packet_max=max;} 6967 .................... if (packet_size < max) {this_packet_max=packet_size;} else {this_packet_max=max;}
6968 .................... to=0; 6968 .................... to=0;
6969 .................... do { 6969 .................... do {
6970 .................... if (usb_kbhit(endpoint)) { 6970 .................... if (usb_kbhit(endpoint)) {
6971 .................... len=usb_get_packet(endpoint,ptr,this_packet_max); 6971 .................... len=usb_get_packet(endpoint,ptr,this_packet_max);
6972 .................... ptr+=len; 6972 .................... ptr+=len;
6973 .................... max-=len; 6973 .................... max-=len;
6974 .................... ret+=len; 6974 .................... ret+=len;
6975 .................... break; 6975 .................... break;
6976 .................... } 6976 .................... }
6977 .................... else { 6977 .................... else {
6978 .................... to++; 6978 .................... to++;
6979 .................... delay_ms(1); 6979 .................... delay_ms(1);
6980 .................... } 6980 .................... }
6981 .................... } while (to!=timeout); 6981 .................... } while (to!=timeout);
6982 .................... } while ((len == packet_size) && (to!=timeout) && max); 6982 .................... } while ((len == packet_size) && (to!=timeout) && max);
6983 .................... 6983 ....................
6984 .................... return(ret); 6984 .................... return(ret);
6985 .................... } 6985 .................... }
6986 .................... 6986 ....................
6987 .................... /// END User Functions 6987 .................... /// END User Functions
6988 .................... 6988 ....................
6989 .................... 6989 ....................
6990 .................... /// BEGIN USB Token, standard and HID request handler (part of ISR) 6990 .................... /// BEGIN USB Token, standard and HID request handler (part of ISR)
6991 .................... 6991 ....................
6992 .................... // see usb.h for documentation 6992 .................... // see usb.h for documentation
6993 .................... void usb_token_reset(void) 6993 .................... void usb_token_reset(void)
6994 .................... { 6994 .................... {
6995 .................... unsigned int i; 6995 .................... unsigned int i;
6996 .................... 6996 ....................
6997 .................... for (i=0;i<USB_MAX_NUM_INTERFACES;i++) 6997 .................... for (i=0;i<USB_MAX_NUM_INTERFACES;i++)
6998 * 6998 *
6999 037E: MOVLB 7 6999 037E: MOVLB 7
7000 0380: CLRF x19 7000 0380: CLRF x19
7001 0382: MOVF x19,W 7001 0382: MOVF x19,W
7002 0384: SUBLW 01 7002 0384: SUBLW 01
7003 0386: BNC 039C 7003 0386: BNC 039C
7004 .................... USB_Interface[i] = 0; //reset each interface to default 7004 .................... USB_Interface[i] = 0; //reset each interface to default
7005 0388: CLRF 03 7005 0388: CLRF 03
7006 038A: MOVF x19,W 7006 038A: MOVF x19,W
7007 038C: ADDLW 29 7007 038C: ADDLW 29
7008 038E: MOVWF FE9 7008 038E: MOVWF FE9
7009 0390: MOVLW 00 7009 0390: MOVLW 00
7010 0392: ADDWFC 03,W 7010 0392: ADDWFC 03,W
7011 0394: MOVWF FEA 7011 0394: MOVWF FEA
7012 0396: CLRF FEF 7012 0396: CLRF FEF
7013 .................... 7013 ....................
7014 .................... #IF USB_HID_BOOT_PROTOCOL 7014 .................... #IF USB_HID_BOOT_PROTOCOL
7015 .................... for (i=0;i<USB_NUM_HID_INTERFACES; i++) 7015 .................... for (i=0;i<USB_NUM_HID_INTERFACES; i++)
7016 .................... hid_protocol[i] = 1; 7016 .................... hid_protocol[i] = 1;
7017 .................... #endif 7017 .................... #endif
7018 .................... 7018 ....................
7019 .................... #if USB_CDC_DEVICE 7019 .................... #if USB_CDC_DEVICE
7020 0398: INCF x19,F 7020 0398: INCF x19,F
7021 039A: BRA 0382 7021 039A: BRA 0382
7022 .................... usb_cdc_init(); 7022 .................... usb_cdc_init();
7023 039C: MOVLB 0 7023 039C: MOVLB 0
7024 039E: RCALL 035C 7024 039E: RCALL 035C
7025 .................... #endif 7025 .................... #endif
7026 .................... 7026 ....................
7027 .................... USB_stack_status.curr_config = 0; //unconfigured device 7027 .................... USB_stack_status.curr_config = 0; //unconfigured device
7028 03A0: CLRF 1E 7028 03A0: CLRF 1E
7029 .................... 7029 ....................
7030 .................... USB_stack_status.status_device = 1; //previous state. init at none 7030 .................... USB_stack_status.status_device = 1; //previous state. init at none
7031 03A2: MOVLW 01 7031 03A2: MOVLW 01
7032 03A4: MOVWF 1F 7032 03A4: MOVWF 1F
7033 .................... USB_stack_status.dev_req = NONE; //previous token request state. init at none 7033 .................... USB_stack_status.dev_req = NONE; //previous token request state. init at none
7034 03A6: CLRF 1D 7034 03A6: CLRF 1D
7035 .................... } 7035 .................... }
7036 03A8: RETLW 00 7036 03A8: RETLW 00
7037 .................... 7037 ....................
7038 .................... //send a 0len packet to endpoint 0 (optimization) 7038 .................... //send a 0len packet to endpoint 0 (optimization)
7039 .................... //notice that this doesnt return the status 7039 .................... //notice that this doesnt return the status
7040 .................... #define usb_put_0len_0() usb_request_send_response(0) 7040 .................... #define usb_put_0len_0() usb_request_send_response(0)
7041 .................... 7041 ....................
7042 .................... /************************************************************** 7042 .................... /**************************************************************
7043 .................... /* usb_endpoint_is_valid(endpoint) 7043 .................... /* usb_endpoint_is_valid(endpoint)
7044 .................... /* 7044 .................... /*
7045 .................... /* Input: endpoint - endpoint to check. 7045 .................... /* Input: endpoint - endpoint to check.
7046 .................... /* bit 7 is direction (set is IN, clear is OUT) 7046 .................... /* bit 7 is direction (set is IN, clear is OUT)
7047 .................... /* 7047 .................... /*
7048 .................... /* Output: TRUE if endpoint is valid, FALSE if not 7048 .................... /* Output: TRUE if endpoint is valid, FALSE if not
7049 .................... /* 7049 .................... /*
7050 .................... /* Summary: Checks the dynamic configuration to see if requested 7050 .................... /* Summary: Checks the dynamic configuration to see if requested
7051 .................... /* endpoint is a valid endpoint. 7051 .................... /* endpoint is a valid endpoint.
7052 .................... /***************************************************************/ 7052 .................... /***************************************************************/
7053 .................... int1 usb_endpoint_is_valid(int8 endpoint) 7053 .................... int1 usb_endpoint_is_valid(int8 endpoint)
7054 .................... { 7054 .................... {
7055 .................... int1 direction; 7055 .................... int1 direction;
7056 .................... direction = bit_test(endpoint,7); 7056 .................... direction = bit_test(endpoint,7);
7057 * 7057 *
7058 08E8: MOVLB 6 7058 08E8: MOVLB 6
7059 08EA: BCF xFE.0 7059 08EA: BCF xFE.0
7060 08EC: BTFSC xFD.7 7060 08EC: BTFSC xFD.7
7061 08EE: BSF xFE.0 7061 08EE: BSF xFE.0
7062 .................... endpoint &= 0x7F; 7062 .................... endpoint &= 0x7F;
7063 08F0: BCF xFD.7 7063 08F0: BCF xFD.7
7064 .................... if (direction) { //IN 7064 .................... if (direction) { //IN
7065 08F2: BTFSS xFE.0 7065 08F2: BTFSS xFE.0
7066 08F4: BRA 091C 7066 08F4: BRA 091C
7067 .................... return(usb_ep_tx_type[endpoint] != USB_ENABLE_DISABLED); 7067 .................... return(usb_ep_tx_type[endpoint] != USB_ENABLE_DISABLED);
7068 08F6: CLRF 03 7068 08F6: CLRF 03
7069 08F8: MOVF xFD,W 7069 08F8: MOVF xFD,W
7070 08FA: MOVFF FF2,6FF 7070 08FA: MOVFF FF2,6FF
7071 08FE: BCF FF2.7 7071 08FE: BCF FF2.7
7072 0900: MOVLB 0 7072 0900: MOVLB 0
7073 0902: CALL 00AA 7073 0902: CALL 00AA
7074 0906: MOVLB 6 7074 0906: MOVLB 6
7075 0908: BTFSC xFF.7 7075 0908: BTFSC xFF.7
7076 090A: BSF FF2.7 7076 090A: BSF FF2.7
7077 090C: SUBLW FF 7077 090C: SUBLW FF
7078 090E: BNZ 0914 7078 090E: BNZ 0914
7079 0910: MOVLW 00 7079 0910: MOVLW 00
7080 0912: BRA 0916 7080 0912: BRA 0916
7081 0914: MOVLW 01 7081 0914: MOVLW 01
7082 0916: MOVWF 01 7082 0916: MOVWF 01
7083 0918: BRA 0940 7083 0918: BRA 0940
7084 .................... } 7084 .................... }
7085 .................... else { //OUT 7085 .................... else { //OUT
7086 091A: BRA 0940 7086 091A: BRA 0940
7087 .................... return(usb_ep_rx_type[endpoint] != USB_ENABLE_DISABLED); 7087 .................... return(usb_ep_rx_type[endpoint] != USB_ENABLE_DISABLED);
7088 091C: CLRF 03 7088 091C: CLRF 03
7089 091E: MOVF xFD,W 7089 091E: MOVF xFD,W
7090 0920: MOVFF FF2,6FF 7090 0920: MOVFF FF2,6FF
7091 0924: BCF FF2.7 7091 0924: BCF FF2.7
7092 0926: MOVLB 0 7092 0926: MOVLB 0
7093 0928: CALL 00CA 7093 0928: CALL 00CA
7094 092C: MOVLB 6 7094 092C: MOVLB 6
7095 092E: BTFSC xFF.7 7095 092E: BTFSC xFF.7
7096 0930: BSF FF2.7 7096 0930: BSF FF2.7
7097 0932: SUBLW FF 7097 0932: SUBLW FF
7098 0934: BNZ 093A 7098 0934: BNZ 093A
7099 0936: MOVLW 00 7099 0936: MOVLW 00
7100 0938: BRA 093C 7100 0938: BRA 093C
7101 093A: MOVLW 01 7101 093A: MOVLW 01
7102 093C: MOVWF 01 7102 093C: MOVWF 01
7103 093E: BRA 0940 7103 093E: BRA 0940
7104 .................... } 7104 .................... }
7105 .................... } 7105 .................... }
7106 0940: MOVLB 0 7106 0940: MOVLB 0
7107 0942: GOTO 0AA8 (RETURN) 7107 0942: GOTO 0AA8 (RETURN)
7108 .................... 7108 ....................
7109 .................... // see usb.h for documentation 7109 .................... // see usb.h for documentation
7110 .................... void usb_isr_tok_in_dne(int8 endpoint) { 7110 .................... void usb_isr_tok_in_dne(int8 endpoint) {
7111 .................... if (endpoint==0) { 7111 .................... if (endpoint==0) {
7112 * 7112 *
7113 1058: MOVLB 6 7113 1058: MOVLB 6
7114 105A: MOVF xFD,F 7114 105A: MOVF xFD,F
7115 105C: BNZ 107A 7115 105C: BNZ 107A
7116 .................... if (USB_stack_status.dev_req == GET_DESCRIPTOR) {usb_copy_desc_seg_to_ep();} //check this, we are missing report descriptor? 7116 .................... if (USB_stack_status.dev_req == GET_DESCRIPTOR) {usb_copy_desc_seg_to_ep();} //check this, we are missing report descriptor?
7117 105E: DECFSZ 1D,W 7117 105E: DECFSZ 1D,W
7118 1060: BRA 106C 7118 1060: BRA 106C
7119 1062: MOVLB 0 7119 1062: MOVLB 0
7120 1064: CALL 03FA 7120 1064: CALL 03FA
7121 .................... else if (USB_stack_status.dev_req == SET_ADDRESS) {usb_finish_set_address();} 7121 .................... else if (USB_stack_status.dev_req == SET_ADDRESS) {usb_finish_set_address();}
7122 1068: BRA 1076 7122 1068: BRA 1076
7123 106A: MOVLB 6 7123 106A: MOVLB 6
7124 106C: MOVF 1D,W 7124 106C: MOVF 1D,W
7125 106E: SUBLW 02 7125 106E: SUBLW 02
7126 1070: BNZ 1078 7126 1070: BNZ 1078
7127 1072: MOVLB 0 7127 1072: MOVLB 0
7128 1074: BRA 0F7A 7128 1074: BRA 0F7A
7129 1076: MOVLB 6 7129 1076: MOVLB 6
7130 .................... } 7130 .................... }
7131 .................... #if USB_CDC_DEVICE 7131 .................... #if USB_CDC_DEVICE
7132 .................... else if (endpoint==USB_CDC_DATA_IN_ENDPOINT) { //see ex_usb_serial.c example and usb_cdc.h driver 7132 .................... else if (endpoint==USB_CDC_DATA_IN_ENDPOINT) { //see ex_usb_serial.c example and usb_cdc.h driver
7133 1078: BRA 1086 7133 1078: BRA 1086
7134 107A: MOVF xFD,W 7134 107A: MOVF xFD,W
7135 107C: SUBLW 02 7135 107C: SUBLW 02
7136 107E: BNZ 1086 7136 107E: BNZ 1086
7137 .................... usb_isr_tok_in_cdc_data_dne(); 7137 .................... usb_isr_tok_in_cdc_data_dne();
7138 1080: MOVLB 0 7138 1080: MOVLB 0
7139 1082: BRA 104E 7139 1082: BRA 104E
7140 1084: MOVLB 6 7140 1084: MOVLB 6
7141 .................... } 7141 .................... }
7142 .................... #endif 7142 .................... #endif
7143 .................... } 7143 .................... }
7144 1086: MOVLB 0 7144 1086: MOVLB 0
7145 1088: RETLW 00 7145 1088: RETLW 00
7146 .................... 7146 ....................
7147 .................... // see usb.h for documentation 7147 .................... // see usb.h for documentation
7148 .................... void usb_isr_tok_out_dne(int8 endpoint) 7148 .................... void usb_isr_tok_out_dne(int8 endpoint)
7149 .................... { 7149 .................... {
7150 .................... //TODO: 7150 .................... //TODO:
7151 .................... if (endpoint==0) { 7151 .................... if (endpoint==0) {
7152 * 7152 *
7153 0F42: MOVLB 6 7153 0F42: MOVLB 6
7154 0F44: MOVF xFD,F 7154 0F44: MOVF xFD,F
7155 0F46: BNZ 0F50 7155 0F46: BNZ 0F50
7156 .................... debug_usb(debug_putc,"TOUT 0 "); 7156 .................... debug_usb(debug_putc,"TOUT 0 ");
7157 .................... #if USB_CDC_DEVICE 7157 .................... #if USB_CDC_DEVICE
7158 .................... usb_isr_tok_out_cdc_control_dne(); 7158 .................... usb_isr_tok_out_cdc_control_dne();
7159 0F48: MOVLB 0 7159 0F48: MOVLB 0
7160 0F4A: BRA 0E7E 7160 0F4A: BRA 0E7E
7161 .................... #else 7161 .................... #else
7162 .................... usb_init_ep0_setup(); 7162 .................... usb_init_ep0_setup();
7163 .................... #endif 7163 .................... #endif
7164 .................... } 7164 .................... }
7165 .................... #if USB_CDC_DEVICE 7165 .................... #if USB_CDC_DEVICE
7166 .................... else if (endpoint==USB_CDC_DATA_OUT_ENDPOINT) { //see ex_usb_serial.c example and usb_cdc.h driver 7166 .................... else if (endpoint==USB_CDC_DATA_OUT_ENDPOINT) { //see ex_usb_serial.c example and usb_cdc.h driver
7167 0F4C: BRA 0F5A 7167 0F4C: BRA 0F5A
7168 0F4E: MOVLB 6 7168 0F4E: MOVLB 6
7169 0F50: MOVF xFD,W 7169 0F50: MOVF xFD,W
7170 0F52: SUBLW 02 7170 0F52: SUBLW 02
7171 0F54: BNZ 0F5C 7171 0F54: BNZ 0F5C
7172 .................... usb_isr_tok_out_cdc_data_dne(); 7172 .................... usb_isr_tok_out_cdc_data_dne();
7173 0F56: MOVLB 0 7173 0F56: MOVLB 0
7174 0F58: BRA 0F2C 7174 0F58: BRA 0F2C
7175 0F5A: MOVLB 6 7175 0F5A: MOVLB 6
7176 .................... } 7176 .................... }
7177 .................... #endif 7177 .................... #endif
7178 .................... //else { 7178 .................... //else {
7179 .................... // bit_set(__usb_kbhit_status,endpoint); 7179 .................... // bit_set(__usb_kbhit_status,endpoint);
7180 .................... //} 7180 .................... //}
7181 .................... } 7181 .................... }
7182 0F5C: MOVLB 0 7182 0F5C: MOVLB 0
7183 0F5E: RETLW 00 7183 0F5E: RETLW 00
7184 .................... 7184 ....................
7185 .................... 7185 ....................
7186 .................... //---- process setup message stage -----------// 7186 .................... //---- process setup message stage -----------//
7187 .................... 7187 ....................
7188 .................... // see usb.h for documentation 7188 .................... // see usb.h for documentation
7189 .................... void usb_isr_tok_setup_dne(void) 7189 .................... void usb_isr_tok_setup_dne(void)
7190 .................... { 7190 .................... {
7191 .................... USB_stack_status.dev_req=NONE; // clear the device request.. 7191 .................... USB_stack_status.dev_req=NONE; // clear the device request..
7192 * 7192 *
7193 0BC0: CLRF 1D 7193 0BC0: CLRF 1D
7194 .................... 7194 ....................
7195 .................... switch(usb_ep0_rx_buffer[0] & 0x7F) { 7195 .................... switch(usb_ep0_rx_buffer[0] & 0x7F) {
7196 0BC2: MOVLB 4 7196 0BC2: MOVLB 4
7197 0BC4: MOVF x18,W 7197 0BC4: MOVF x18,W
7198 0BC6: ANDLW 7F 7198 0BC6: ANDLW 7F
7199 0BC8: MOVLB 0 7199 0BC8: MOVLB 0
7200 0BCA: BZ 0BDA 7200 0BCA: BZ 0BDA
7201 0BCC: XORLW 01 7201 0BCC: XORLW 01
7202 0BCE: BZ 0BDC 7202 0BCE: BZ 0BDC
7203 0BD0: XORLW 03 7203 0BD0: XORLW 03
7204 0BD2: BZ 0BDE 7204 0BD2: BZ 0BDE
7205 0BD4: XORLW 23 7205 0BD4: XORLW 23
7206 0BD6: BZ 0BE0 7206 0BD6: BZ 0BE0
7207 0BD8: BRA 0BE2 7207 0BD8: BRA 0BE2
7208 .................... 7208 ....................
7209 .................... case 0x00: //standard to device 7209 .................... case 0x00: //standard to device
7210 .................... debug_usb(debug_putc," d"); 7210 .................... debug_usb(debug_putc," d");
7211 .................... usb_isr_tkn_setup_StandardDevice(); 7211 .................... usb_isr_tkn_setup_StandardDevice();
7212 0BDA: BRA 078C 7212 0BDA: BRA 078C
7213 .................... break; 7213 .................... break;
7214 .................... 7214 ....................
7215 .................... case 0x01: //standard to interface 7215 .................... case 0x01: //standard to interface
7216 .................... debug_usb(debug_putc," i"); 7216 .................... debug_usb(debug_putc," i");
7217 .................... usb_isr_tkn_setup_StandardInterface(); 7217 .................... usb_isr_tkn_setup_StandardInterface();
7218 0BDC: BRA 0840 7218 0BDC: BRA 0840
7219 .................... break; 7219 .................... break;
7220 .................... 7220 ....................
7221 .................... case 0x02: //standard to endpoint 7221 .................... case 0x02: //standard to endpoint
7222 .................... debug_usb(debug_putc," e"); 7222 .................... debug_usb(debug_putc," e");
7223 .................... usb_isr_tkn_setup_StandardEndpoint(); 7223 .................... usb_isr_tkn_setup_StandardEndpoint();
7224 0BDE: BRA 0AA2 7224 0BDE: BRA 0AA2
7225 .................... break; 7225 .................... break;
7226 .................... 7226 ....................
7227 .................... #IF USB_HID_DEVICE 7227 .................... #IF USB_HID_DEVICE
7228 .................... case 0x21: //class specific request. the only class this driver supports is HID 7228 .................... case 0x21: //class specific request. the only class this driver supports is HID
7229 .................... debug_usb(debug_putc," hid"); 7229 .................... debug_usb(debug_putc," hid");
7230 .................... usb_isr_tkn_setup_ClassInterface(); 7230 .................... usb_isr_tkn_setup_ClassInterface();
7231 .................... break; 7231 .................... break;
7232 .................... #endif 7232 .................... #endif
7233 .................... 7233 ....................
7234 .................... #if USB_CDC_DEVICE 7234 .................... #if USB_CDC_DEVICE
7235 .................... case 0x21: 7235 .................... case 0x21:
7236 .................... debug_usb(debug_putc," cdc"); 7236 .................... debug_usb(debug_putc," cdc");
7237 .................... usb_isr_tkn_cdc(); 7237 .................... usb_isr_tkn_cdc();
7238 0BE0: BRA 0B12 7238 0BE0: BRA 0B12
7239 .................... break; 7239 .................... break;
7240 .................... #endif 7240 .................... #endif
7241 .................... //TODO: IF YOU WANT VENDOR SPECIFC REQUEST SUPPORT YOU MUST ADD IT HERE 7241 .................... //TODO: IF YOU WANT VENDOR SPECIFC REQUEST SUPPORT YOU MUST ADD IT HERE
7242 .................... 7242 ....................
7243 .................... default: 7243 .................... default:
7244 .................... usb_request_stall(); 7244 .................... usb_request_stall();
7245 0BE2: RCALL 03F4 7245 0BE2: RCALL 03F4
7246 .................... break; 7246 .................... break;
7247 0BE4: BRA 0BE6 7247 0BE4: BRA 0BE6
7248 .................... } 7248 .................... }
7249 .................... } 7249 .................... }
7250 0BE6: GOTO 10C2 (RETURN) 7250 0BE6: GOTO 10C2 (RETURN)
7251 .................... 7251 ....................
7252 .................... /************************************************************** 7252 .................... /**************************************************************
7253 .................... /* usb_isr_tkn_setup_StandardDevice() 7253 .................... /* usb_isr_tkn_setup_StandardDevice()
7254 .................... /* 7254 .................... /*
7255 .................... /* Input: usb_ep0_rx_buffer[1] == bRequest 7255 .................... /* Input: usb_ep0_rx_buffer[1] == bRequest
7256 .................... /* 7256 .................... /*
7257 .................... /* Summary: bmRequestType told us it was a Standard Device request. 7257 .................... /* Summary: bmRequestType told us it was a Standard Device request.
7258 .................... /* bRequest says which request. Only certain requests are valid, 7258 .................... /* bRequest says which request. Only certain requests are valid,
7259 .................... /* if a non-valid request was made then return with an Wrong-Statue (IDLE) 7259 .................... /* if a non-valid request was made then return with an Wrong-Statue (IDLE)
7260 .................... /* 7260 .................... /*
7261 .................... /* Part of usb_isr_tok_setup_dne() 7261 .................... /* Part of usb_isr_tok_setup_dne()
7262 .................... /***************************************************************/ 7262 .................... /***************************************************************/
7263 .................... void usb_isr_tkn_setup_StandardDevice(void) { 7263 .................... void usb_isr_tkn_setup_StandardDevice(void) {
7264 .................... switch(usb_ep0_rx_buffer[1]) { 7264 .................... switch(usb_ep0_rx_buffer[1]) {
7265 * 7265 *
7266 078C: MOVLB 4 7266 078C: MOVLB 4
7267 078E: MOVF x19,W 7267 078E: MOVF x19,W
7268 0790: MOVLB 0 7268 0790: MOVLB 0
7269 0792: BZ 07AE 7269 0792: BZ 07AE
7270 0794: XORLW 01 7270 0794: XORLW 01
7271 0796: BZ 07C2 7271 0796: BZ 07C2
7272 0798: XORLW 02 7272 0798: XORLW 02
7273 079A: BZ 07DC 7273 079A: BZ 07DC
7274 079C: XORLW 06 7274 079C: XORLW 06
7275 079E: BZ 07F4 7275 079E: BZ 07F4
7276 07A0: XORLW 03 7276 07A0: XORLW 03
7277 07A2: BZ 0806 7277 07A2: BZ 0806
7278 07A4: XORLW 0E 7278 07A4: XORLW 0E
7279 07A6: BZ 0808 7279 07A6: BZ 0808
7280 07A8: XORLW 01 7280 07A8: XORLW 01
7281 07AA: BZ 0818 7281 07AA: BZ 0818
7282 07AC: BRA 0838 7282 07AC: BRA 0838
7283 .................... 7283 ....................
7284 .................... case USB_STANDARD_REQUEST_GET_STATUS: //0 7284 .................... case USB_STANDARD_REQUEST_GET_STATUS: //0
7285 .................... debug_usb(debug_putc,"GS"); 7285 .................... debug_usb(debug_putc,"GS");
7286 .................... usb_ep0_tx_buffer[0]=USB_stack_status.status_device; 7286 .................... usb_ep0_tx_buffer[0]=USB_stack_status.status_device;
7287 07AE: MOVFF 1F,458 7287 07AE: MOVFF 1F,458
7288 .................... usb_ep0_tx_buffer[1]=0; 7288 .................... usb_ep0_tx_buffer[1]=0;
7289 07B2: MOVLB 4 7289 07B2: MOVLB 4
7290 07B4: CLRF x59 7290 07B4: CLRF x59
7291 .................... usb_request_send_response(2); 7291 .................... usb_request_send_response(2);
7292 07B6: MOVLW 02 7292 07B6: MOVLW 02
7293 07B8: MOVLB 7 7293 07B8: MOVLB 7
7294 07BA: MOVWF x00 7294 07BA: MOVWF x00
7295 07BC: MOVLB 0 7295 07BC: MOVLB 0
7296 07BE: RCALL 03EE 7296 07BE: RCALL 03EE
7297 .................... break; 7297 .................... break;
7298 07C0: BRA 083C 7298 07C0: BRA 083C
7299 .................... 7299 ....................
7300 .................... case USB_STANDARD_REQUEST_CLEAR_FEATURE: //1 7300 .................... case USB_STANDARD_REQUEST_CLEAR_FEATURE: //1
7301 .................... if (usb_ep0_rx_buffer[2] == 1) { 7301 .................... if (usb_ep0_rx_buffer[2] == 1) {
7302 07C2: MOVLB 4 7302 07C2: MOVLB 4
7303 07C4: DECFSZ x1A,W 7303 07C4: DECFSZ x1A,W
7304 07C6: BRA 07D6 7304 07C6: BRA 07D6
7305 .................... debug_usb(debug_putc,"CF"); 7305 .................... debug_usb(debug_putc,"CF");
7306 .................... USB_stack_status.status_device &= 1; 7306 .................... USB_stack_status.status_device &= 1;
7307 07C8: MOVLW 01 7307 07C8: MOVLW 01
7308 07CA: ANDWF 1F,F 7308 07CA: ANDWF 1F,F
7309 .................... usb_put_0len_0(); 7309 .................... usb_put_0len_0();
7310 07CC: MOVLB 7 7310 07CC: MOVLB 7
7311 07CE: CLRF x00 7311 07CE: CLRF x00
7312 07D0: MOVLB 0 7312 07D0: MOVLB 0
7313 07D2: RCALL 03EE 7313 07D2: RCALL 03EE
7314 .................... } 7314 .................... }
7315 .................... else 7315 .................... else
7316 07D4: BRA 07DA 7316 07D4: BRA 07DA
7317 .................... usb_request_stall(); 7317 .................... usb_request_stall();
7318 07D6: MOVLB 0 7318 07D6: MOVLB 0
7319 07D8: RCALL 03F4 7319 07D8: RCALL 03F4
7320 .................... break; 7320 .................... break;
7321 07DA: BRA 083C 7321 07DA: BRA 083C
7322 .................... 7322 ....................
7323 .................... case USB_STANDARD_REQUEST_SET_FEATURE: //3 7323 .................... case USB_STANDARD_REQUEST_SET_FEATURE: //3
7324 .................... if (usb_ep0_rx_buffer[2] == 1) { 7324 .................... if (usb_ep0_rx_buffer[2] == 1) {
7325 07DC: MOVLB 4 7325 07DC: MOVLB 4
7326 07DE: DECFSZ x1A,W 7326 07DE: DECFSZ x1A,W
7327 07E0: BRA 07EE 7327 07E0: BRA 07EE
7328 .................... debug_usb(debug_putc,"SF"); 7328 .................... debug_usb(debug_putc,"SF");
7329 .................... USB_stack_status.status_device |= 2; 7329 .................... USB_stack_status.status_device |= 2;
7330 07E2: BSF 1F.1 7330 07E2: BSF 1F.1
7331 .................... usb_put_0len_0(); 7331 .................... usb_put_0len_0();
7332 07E4: MOVLB 7 7332 07E4: MOVLB 7
7333 07E6: CLRF x00 7333 07E6: CLRF x00
7334 07E8: MOVLB 0 7334 07E8: MOVLB 0
7335 07EA: RCALL 03EE 7335 07EA: RCALL 03EE
7336 .................... } 7336 .................... }
7337 .................... else 7337 .................... else
7338 07EC: BRA 07F2 7338 07EC: BRA 07F2
7339 .................... usb_request_stall(); 7339 .................... usb_request_stall();
7340 07EE: MOVLB 0 7340 07EE: MOVLB 0
7341 07F0: RCALL 03F4 7341 07F0: RCALL 03F4
7342 .................... break; 7342 .................... break;
7343 07F2: BRA 083C 7343 07F2: BRA 083C
7344 .................... 7344 ....................
7345 .................... case USB_STANDARD_REQUEST_SET_ADDRESS: //5 7345 .................... case USB_STANDARD_REQUEST_SET_ADDRESS: //5
7346 .................... debug_usb(debug_putc,"SA"); 7346 .................... debug_usb(debug_putc,"SA");
7347 .................... USB_stack_status.dev_req=SET_ADDRESS; //currently processing set_address request 7347 .................... USB_stack_status.dev_req=SET_ADDRESS; //currently processing set_address request
7348 07F4: MOVLW 02 7348 07F4: MOVLW 02
7349 07F6: MOVWF 1D 7349 07F6: MOVWF 1D
7350 .................... USB_address_pending=usb_ep0_rx_buffer[2]; 7350 .................... USB_address_pending=usb_ep0_rx_buffer[2];
7351 07F8: MOVFF 41A,26 7351 07F8: MOVFF 41A,26
7352 .................... #ifdef __USBN__ //NATIONAL part handles this differently than pic16c7x5 7352 .................... #ifdef __USBN__ //NATIONAL part handles this differently than pic16c7x5
7353 .................... USB_stack_status.dev_req=NONE; //currently processing set_address request 7353 .................... USB_stack_status.dev_req=NONE; //currently processing set_address request
7354 .................... usb_set_address(USB_address_pending); 7354 .................... usb_set_address(USB_address_pending);
7355 .................... USB_stack_status.curr_config=0; // make sure current configuration is 0 7355 .................... USB_stack_status.curr_config=0; // make sure current configuration is 0
7356 .................... #endif 7356 .................... #endif
7357 .................... usb_put_0len_0(); 7357 .................... usb_put_0len_0();
7358 07FC: MOVLB 7 7358 07FC: MOVLB 7
7359 07FE: CLRF x00 7359 07FE: CLRF x00
7360 0800: MOVLB 0 7360 0800: MOVLB 0
7361 0802: RCALL 03EE 7361 0802: RCALL 03EE
7362 .................... break; 7362 .................... break;
7363 0804: BRA 083C 7363 0804: BRA 083C
7364 .................... 7364 ....................
7365 .................... case USB_STANDARD_REQUEST_GET_DESCRIPTOR: //6 7365 .................... case USB_STANDARD_REQUEST_GET_DESCRIPTOR: //6
7366 .................... debug_usb(debug_putc,"GD"); 7366 .................... debug_usb(debug_putc,"GD");
7367 .................... usb_Get_Descriptor(); 7367 .................... usb_Get_Descriptor();
7368 0806: BRA 049C 7368 0806: BRA 049C
7369 .................... break; 7369 .................... break;
7370 .................... 7370 ....................
7371 .................... case USB_STANDARD_REQUEST_GET_CONFIGURATION: //8 7371 .................... case USB_STANDARD_REQUEST_GET_CONFIGURATION: //8
7372 .................... debug_usb(debug_putc,"GC"); 7372 .................... debug_usb(debug_putc,"GC");
7373 .................... usb_ep0_tx_buffer[0]=USB_stack_status.curr_config; 7373 .................... usb_ep0_tx_buffer[0]=USB_stack_status.curr_config;
7374 0808: MOVFF 1E,458 7374 0808: MOVFF 1E,458
7375 .................... usb_request_send_response(1); 7375 .................... usb_request_send_response(1);
7376 080C: MOVLW 01 7376 080C: MOVLW 01
7377 080E: MOVLB 7 7377 080E: MOVLB 7
7378 0810: MOVWF x00 7378 0810: MOVWF x00
7379 0812: MOVLB 0 7379 0812: MOVLB 0
7380 0814: RCALL 03EE 7380 0814: RCALL 03EE
7381 .................... break; 7381 .................... break;
7382 0816: BRA 083C 7382 0816: BRA 083C
7383 .................... 7383 ....................
7384 .................... case USB_STANDARD_REQUEST_SET_CONFIGURATION: //9 7384 .................... case USB_STANDARD_REQUEST_SET_CONFIGURATION: //9
7385 .................... if (usb_ep0_rx_buffer[2] <= USB_NUM_CONFIGURATIONS) { 7385 .................... if (usb_ep0_rx_buffer[2] <= USB_NUM_CONFIGURATIONS) {
7386 0818: MOVLB 4 7386 0818: MOVLB 4
7387 081A: MOVF x1A,W 7387 081A: MOVF x1A,W
7388 081C: SUBLW 01 7388 081C: SUBLW 01
7389 081E: BNC 0834 7389 081E: BNC 0834
7390 .................... USB_stack_status.curr_config=usb_ep0_rx_buffer[2]; 7390 .................... USB_stack_status.curr_config=usb_ep0_rx_buffer[2];
7391 0820: MOVFF 41A,1E 7391 0820: MOVFF 41A,1E
7392 .................... usb_set_configured(usb_ep0_rx_buffer[2]); 7392 .................... usb_set_configured(usb_ep0_rx_buffer[2]);
7393 0824: MOVFF 41A,6FD 7393 0824: MOVFF 41A,6FD
7394 0828: MOVLB 0 7394 0828: MOVLB 0
7395 082A: BRA 055C 7395 082A: BRA 055C
7396 .................... debug_usb(debug_putc,"SC%U", USB_stack_status.curr_config); 7396 .................... debug_usb(debug_putc,"SC%U", USB_stack_status.curr_config);
7397 .................... usb_put_0len_0(); 7397 .................... usb_put_0len_0();
7398 082C: MOVLB 7 7398 082C: MOVLB 7
7399 082E: CLRF x00 7399 082E: CLRF x00
7400 0830: MOVLB 0 7400 0830: MOVLB 0
7401 0832: RCALL 03EE 7401 0832: RCALL 03EE
7402 .................... } 7402 .................... }
7403 .................... break; 7403 .................... break;
7404 0834: MOVLB 0 7404 0834: MOVLB 0
7405 0836: BRA 083C 7405 0836: BRA 083C
7406 .................... 7406 ....................
7407 .................... default: 7407 .................... default:
7408 .................... usb_request_stall(); 7408 .................... usb_request_stall();
7409 0838: RCALL 03F4 7409 0838: RCALL 03F4
7410 .................... break; 7410 .................... break;
7411 083A: BRA 083C 7411 083A: BRA 083C
7412 .................... } 7412 .................... }
7413 .................... } 7413 .................... }
7414 083C: GOTO 0BE6 (RETURN) 7414 083C: GOTO 0BE6 (RETURN)
7415 .................... 7415 ....................
7416 .................... /************************************************************** 7416 .................... /**************************************************************
7417 .................... /* usb_isr_tkn_setup_StandardInterface() 7417 .................... /* usb_isr_tkn_setup_StandardInterface()
7418 .................... /* 7418 .................... /*
7419 .................... /* Input: usb_ep0_rx_buffer[1] == bRequest 7419 .................... /* Input: usb_ep0_rx_buffer[1] == bRequest
7420 .................... /* 7420 .................... /*
7421 .................... /* Summary: bmRequestType told us it was a Standard Interface request. 7421 .................... /* Summary: bmRequestType told us it was a Standard Interface request.
7422 .................... /* bRequest says which request. Only certain requests are valid, 7422 .................... /* bRequest says which request. Only certain requests are valid,
7423 .................... /* if a non-valid request was made then return with an Wrong-Statue (IDLE) 7423 .................... /* if a non-valid request was made then return with an Wrong-Statue (IDLE)
7424 .................... /* 7424 .................... /*
7425 .................... /* Part of usb_isr_tok_setup_dne() 7425 .................... /* Part of usb_isr_tok_setup_dne()
7426 .................... /***************************************************************/ 7426 .................... /***************************************************************/
7427 .................... void usb_isr_tkn_setup_StandardInterface(void) { 7427 .................... void usb_isr_tkn_setup_StandardInterface(void) {
7428 .................... int8 curr_config; 7428 .................... int8 curr_config;
7429 .................... 7429 ....................
7430 .................... curr_config=USB_stack_status.curr_config; 7430 .................... curr_config=USB_stack_status.curr_config;
7431 0840: MOVFF 1E,6FD 7431 0840: MOVFF 1E,6FD
7432 .................... 7432 ....................
7433 .................... switch (usb_ep0_rx_buffer[1]) { 7433 .................... switch (usb_ep0_rx_buffer[1]) {
7434 0844: MOVLB 4 7434 0844: MOVLB 4
7435 0846: MOVF x19,W 7435 0846: MOVF x19,W
7436 0848: MOVLB 0 7436 0848: MOVLB 0
7437 084A: BZ 0856 7437 084A: BZ 0856
7438 084C: XORLW 0A 7438 084C: XORLW 0A
7439 084E: BZ 0868 7439 084E: BZ 0868
7440 0850: XORLW 01 7440 0850: XORLW 01
7441 0852: BZ 08B6 7441 0852: BZ 08B6
7442 0854: BRA 08E0 7442 0854: BRA 08E0
7443 .................... case USB_STANDARD_REQUEST_GET_STATUS: 7443 .................... case USB_STANDARD_REQUEST_GET_STATUS:
7444 .................... debug_usb(debug_putc,"GS"); 7444 .................... debug_usb(debug_putc,"GS");
7445 .................... usb_ep0_tx_buffer[0]=0; 7445 .................... usb_ep0_tx_buffer[0]=0;
7446 0856: MOVLB 4 7446 0856: MOVLB 4
7447 0858: CLRF x58 7447 0858: CLRF x58
7448 .................... usb_ep0_tx_buffer[1]=0; 7448 .................... usb_ep0_tx_buffer[1]=0;
7449 085A: CLRF x59 7449 085A: CLRF x59
7450 .................... usb_request_send_response(2); 7450 .................... usb_request_send_response(2);
7451 085C: MOVLW 02 7451 085C: MOVLW 02
7452 085E: MOVLB 7 7452 085E: MOVLB 7
7453 0860: MOVWF x00 7453 0860: MOVWF x00
7454 0862: MOVLB 0 7454 0862: MOVLB 0
7455 0864: RCALL 03EE 7455 0864: RCALL 03EE
7456 .................... break; 7456 .................... break;
7457 0866: BRA 08E4 7457 0866: BRA 08E4
7458 .................... 7458 ....................
7459 .................... case USB_STANDARD_REQUEST_GET_INTERFACE: 7459 .................... case USB_STANDARD_REQUEST_GET_INTERFACE:
7460 .................... if ( curr_config && (usb_ep0_rx_buffer[4] < USB_NUM_INTERFACES[curr_config-1]) ) { //book says only supports configed state 7460 .................... if ( curr_config && (usb_ep0_rx_buffer[4] < USB_NUM_INTERFACES[curr_config-1]) ) { //book says only supports configed state
7461 0868: MOVLB 6 7461 0868: MOVLB 6
7462 086A: MOVF xFD,F 7462 086A: MOVF xFD,F
7463 086C: BZ 08B0 7463 086C: BZ 08B0
7464 086E: MOVLW 01 7464 086E: MOVLW 01
7465 0870: SUBWF xFD,W 7465 0870: SUBWF xFD,W
7466 0872: CLRF 03 7466 0872: CLRF 03
7467 0874: MOVFF FF2,6FE 7467 0874: MOVFF FF2,6FE
7468 0878: BCF FF2.7 7468 0878: BCF FF2.7
7469 087A: MOVLB 0 7469 087A: MOVLB 0
7470 087C: RCALL 019E 7470 087C: RCALL 019E
7471 087E: MOVLB 6 7471 087E: MOVLB 6
7472 0880: BTFSC xFE.7 7472 0880: BTFSC xFE.7
7473 0882: BSF FF2.7 7473 0882: BSF FF2.7
7474 0884: MOVWF 01 7474 0884: MOVWF 01
7475 0886: MOVLB 4 7475 0886: MOVLB 4
7476 0888: SUBWF x1C,W 7476 0888: SUBWF x1C,W
7477 088A: BTFSS FD8.0 7477 088A: BTFSS FD8.0
7478 088C: BRA 0892 7478 088C: BRA 0892
7479 088E: MOVLB 6 7479 088E: MOVLB 6
7480 0890: BRA 08B0 7480 0890: BRA 08B0
7481 .................... debug_usb(debug_putc,"GI"); 7481 .................... debug_usb(debug_putc,"GI");
7482 .................... usb_ep0_tx_buffer[0]=USB_Interface[usb_ep0_rx_buffer[4]];//our new outgoing byte 7482 .................... usb_ep0_tx_buffer[0]=USB_Interface[usb_ep0_rx_buffer[4]];//our new outgoing byte
7483 0892: CLRF 03 7483 0892: CLRF 03
7484 0894: MOVF x1C,W 7484 0894: MOVF x1C,W
7485 0896: ADDLW 29 7485 0896: ADDLW 29
7486 0898: MOVWF FE9 7486 0898: MOVWF FE9
7487 089A: MOVLW 00 7487 089A: MOVLW 00
7488 089C: ADDWFC 03,W 7488 089C: ADDWFC 03,W
7489 089E: MOVWF FEA 7489 089E: MOVWF FEA
7490 08A0: MOVFF FEF,458 7490 08A0: MOVFF FEF,458
7491 .................... usb_request_send_response(1);; //send byte back 7491 .................... usb_request_send_response(1);; //send byte back
7492 08A4: MOVLW 01 7492 08A4: MOVLW 01
7493 08A6: MOVLB 7 7493 08A6: MOVLB 7
7494 08A8: MOVWF x00 7494 08A8: MOVWF x00
7495 08AA: MOVLB 0 7495 08AA: MOVLB 0
7496 08AC: RCALL 03EE 7496 08AC: RCALL 03EE
7497 .................... } 7497 .................... }
7498 .................... else 7498 .................... else
7499 08AE: BRA 08B4 7499 08AE: BRA 08B4
7500 .................... usb_request_stall(); 7500 .................... usb_request_stall();
7501 08B0: MOVLB 0 7501 08B0: MOVLB 0
7502 08B2: RCALL 03F4 7502 08B2: RCALL 03F4
7503 .................... break; 7503 .................... break;
7504 08B4: BRA 08E4 7504 08B4: BRA 08E4
7505 .................... 7505 ....................
7506 .................... case USB_STANDARD_REQUEST_SET_INTERFACE: 7506 .................... case USB_STANDARD_REQUEST_SET_INTERFACE:
7507 .................... if (curr_config) { //if configured state 7507 .................... if (curr_config) { //if configured state
7508 08B6: MOVLB 6 7508 08B6: MOVLB 6
7509 08B8: MOVF xFD,F 7509 08B8: MOVF xFD,F
7510 08BA: BZ 08DA 7510 08BA: BZ 08DA
7511 .................... debug_usb(debug_putc,"SI"); 7511 .................... debug_usb(debug_putc,"SI");
7512 .................... USB_Interface[usb_ep0_rx_buffer[4]]=usb_ep0_rx_buffer[2]; 7512 .................... USB_Interface[usb_ep0_rx_buffer[4]]=usb_ep0_rx_buffer[2];
7513 08BC: CLRF 03 7513 08BC: CLRF 03
7514 08BE: MOVLB 4 7514 08BE: MOVLB 4
7515 08C0: MOVF x1C,W 7515 08C0: MOVF x1C,W
7516 08C2: ADDLW 29 7516 08C2: ADDLW 29
7517 08C4: MOVWF FE9 7517 08C4: MOVWF FE9
7518 08C6: MOVLW 00 7518 08C6: MOVLW 00
7519 08C8: ADDWFC 03,W 7519 08C8: ADDWFC 03,W
7520 08CA: MOVWF FEA 7520 08CA: MOVWF FEA
7521 08CC: MOVFF 41A,FEF 7521 08CC: MOVFF 41A,FEF
7522 .................... usb_put_0len_0(); 7522 .................... usb_put_0len_0();
7523 08D0: MOVLB 7 7523 08D0: MOVLB 7
7524 08D2: CLRF x00 7524 08D2: CLRF x00
7525 08D4: MOVLB 0 7525 08D4: MOVLB 0
7526 08D6: RCALL 03EE 7526 08D6: RCALL 03EE
7527 .................... } 7527 .................... }
7528 .................... else 7528 .................... else
7529 08D8: BRA 08DE 7529 08D8: BRA 08DE
7530 .................... usb_request_stall(); 7530 .................... usb_request_stall();
7531 08DA: MOVLB 0 7531 08DA: MOVLB 0
7532 08DC: RCALL 03F4 7532 08DC: RCALL 03F4
7533 .................... break; 7533 .................... break;
7534 08DE: BRA 08E4 7534 08DE: BRA 08E4
7535 .................... 7535 ....................
7536 .................... #IF USB_HID_DEVICE 7536 .................... #IF USB_HID_DEVICE
7537 .................... case USB_STANDARD_REQUEST_GET_DESCRIPTOR: 7537 .................... case USB_STANDARD_REQUEST_GET_DESCRIPTOR:
7538 .................... debug_usb(debug_putc,"GD"); 7538 .................... debug_usb(debug_putc,"GD");
7539 .................... usb_Get_Descriptor(); 7539 .................... usb_Get_Descriptor();
7540 .................... break; 7540 .................... break;
7541 .................... #endif 7541 .................... #endif
7542 .................... 7542 ....................
7543 .................... // case USB_STANDARD_REQUEST_CLEAR_FEATURE: 7543 .................... // case USB_STANDARD_REQUEST_CLEAR_FEATURE:
7544 .................... // case USB_STANDARD_REQUEST_SET_FEATURE: 7544 .................... // case USB_STANDARD_REQUEST_SET_FEATURE:
7545 .................... // let default take care of these, goto wrongstate 7545 .................... // let default take care of these, goto wrongstate
7546 .................... default: 7546 .................... default:
7547 .................... usb_request_stall(); 7547 .................... usb_request_stall();
7548 08E0: RCALL 03F4 7548 08E0: RCALL 03F4
7549 .................... break; 7549 .................... break;
7550 08E2: BRA 08E4 7550 08E2: BRA 08E4
7551 .................... } 7551 .................... }
7552 .................... } 7552 .................... }
7553 08E4: GOTO 0BE6 (RETURN) 7553 08E4: GOTO 0BE6 (RETURN)
7554 .................... 7554 ....................
7555 .................... /************************************************************** 7555 .................... /**************************************************************
7556 .................... /* usb_isr_tkn_setup_StandardEndpoint() 7556 .................... /* usb_isr_tkn_setup_StandardEndpoint()
7557 .................... /* 7557 .................... /*
7558 .................... /* Input: usb_ep0_rx_buffer[1] == bRequest 7558 .................... /* Input: usb_ep0_rx_buffer[1] == bRequest
7559 .................... /* 7559 .................... /*
7560 .................... /* Summary: bmRequestType told us it was a Standard Endpoint request. 7560 .................... /* Summary: bmRequestType told us it was a Standard Endpoint request.
7561 .................... /* bRequest says which request. Only certain requests are valid, 7561 .................... /* bRequest says which request. Only certain requests are valid,
7562 .................... /* if a non-valid request was made then return with an Wrong-Statue (IDLE) 7562 .................... /* if a non-valid request was made then return with an Wrong-Statue (IDLE)
7563 .................... /* 7563 .................... /*
7564 .................... /* Part of usb_isr_tok_setup_dne() 7564 .................... /* Part of usb_isr_tok_setup_dne()
7565 .................... /***************************************************************/ 7565 .................... /***************************************************************/
7566 .................... void usb_isr_tkn_setup_StandardEndpoint(void) { 7566 .................... void usb_isr_tkn_setup_StandardEndpoint(void) {
7567 .................... if (usb_endpoint_is_valid(usb_ep0_rx_buffer[4])) { 7567 .................... if (usb_endpoint_is_valid(usb_ep0_rx_buffer[4])) {
7568 * 7568 *
7569 0AA2: MOVFF 41C,6FD 7569 0AA2: MOVFF 41C,6FD
7570 0AA6: BRA 08E8 7570 0AA6: BRA 08E8
7571 0AA8: MOVF 01,F 7571 0AA8: MOVF 01,F
7572 0AAA: BZ 0B08 7572 0AAA: BZ 0B08
7573 .................... switch(usb_ep0_rx_buffer[1]) { 7573 .................... switch(usb_ep0_rx_buffer[1]) {
7574 0AAC: MOVLB 4 7574 0AAC: MOVLB 4
7575 0AAE: MOVF x19,W 7575 0AAE: MOVF x19,W
7576 0AB0: XORLW 01 7576 0AB0: XORLW 01
7577 0AB2: MOVLB 0 7577 0AB2: MOVLB 0
7578 0AB4: BZ 0AC0 7578 0AB4: BZ 0AC0
7579 0AB6: XORLW 02 7579 0AB6: XORLW 02
7580 0AB8: BZ 0AD0 7580 0AB8: BZ 0AD0
7581 0ABA: XORLW 03 7581 0ABA: XORLW 03
7582 0ABC: BZ 0AE0 7582 0ABC: BZ 0AE0
7583 0ABE: BRA 0B04 7583 0ABE: BRA 0B04
7584 .................... 7584 ....................
7585 .................... case USB_STANDARD_REQUEST_CLEAR_FEATURE: 7585 .................... case USB_STANDARD_REQUEST_CLEAR_FEATURE:
7586 .................... debug_usb(debug_putc,"CF"); 7586 .................... debug_usb(debug_putc,"CF");
7587 .................... usb_unstall_ep(usb_ep0_rx_buffer[4]); 7587 .................... usb_unstall_ep(usb_ep0_rx_buffer[4]);
7588 0AC0: MOVFF 41C,6FD 7588 0AC0: MOVFF 41C,6FD
7589 0AC4: BRA 0946 7589 0AC4: BRA 0946
7590 .................... usb_put_0len_0(); 7590 .................... usb_put_0len_0();
7591 0AC6: MOVLB 7 7591 0AC6: MOVLB 7
7592 0AC8: CLRF x00 7592 0AC8: CLRF x00
7593 0ACA: MOVLB 0 7593 0ACA: MOVLB 0
7594 0ACC: RCALL 03EE 7594 0ACC: RCALL 03EE
7595 .................... break; 7595 .................... break;
7596 0ACE: BRA 0B08 7596 0ACE: BRA 0B08
7597 .................... 7597 ....................
7598 .................... case USB_STANDARD_REQUEST_SET_FEATURE: 7598 .................... case USB_STANDARD_REQUEST_SET_FEATURE:
7599 .................... debug_usb(debug_putc,"SF"); 7599 .................... debug_usb(debug_putc,"SF");
7600 .................... usb_stall_ep(usb_ep0_rx_buffer[4]); 7600 .................... usb_stall_ep(usb_ep0_rx_buffer[4]);
7601 0AD0: MOVFF 41C,6FD 7601 0AD0: MOVFF 41C,6FD
7602 0AD4: BRA 09B4 7602 0AD4: BRA 09B4
7603 .................... usb_put_0len_0(); 7603 .................... usb_put_0len_0();
7604 0AD6: MOVLB 7 7604 0AD6: MOVLB 7
7605 0AD8: CLRF x00 7605 0AD8: CLRF x00
7606 0ADA: MOVLB 0 7606 0ADA: MOVLB 0
7607 0ADC: RCALL 03EE 7607 0ADC: RCALL 03EE
7608 .................... break; 7608 .................... break;
7609 0ADE: BRA 0B08 7609 0ADE: BRA 0B08
7610 .................... 7610 ....................
7611 .................... case USB_STANDARD_REQUEST_GET_STATUS: 7611 .................... case USB_STANDARD_REQUEST_GET_STATUS:
7612 .................... debug_usb(debug_putc,"GS"); 7612 .................... debug_usb(debug_putc,"GS");
7613 .................... usb_ep0_tx_buffer[0]=0; 7613 .................... usb_ep0_tx_buffer[0]=0;
7614 0AE0: MOVLB 4 7614 0AE0: MOVLB 4
7615 0AE2: CLRF x58 7615 0AE2: CLRF x58
7616 .................... usb_ep0_tx_buffer[1]=0; 7616 .................... usb_ep0_tx_buffer[1]=0;
7617 0AE4: CLRF x59 7617 0AE4: CLRF x59
7618 .................... if (usb_endpoint_stalled(usb_ep0_rx_buffer[4])) { 7618 .................... if (usb_endpoint_stalled(usb_ep0_rx_buffer[4])) {
7619 0AE6: MOVFF 41C,6FD 7619 0AE6: MOVFF 41C,6FD
7620 0AEA: MOVLB 0 7620 0AEA: MOVLB 0
7621 0AEC: BRA 0A24 7621 0AEC: BRA 0A24
7622 0AEE: MOVF 01,F 7622 0AEE: MOVF 01,F
7623 0AF0: BZ 0AF8 7623 0AF0: BZ 0AF8
7624 .................... usb_ep0_tx_buffer[0]=1; 7624 .................... usb_ep0_tx_buffer[0]=1;
7625 0AF2: MOVLW 01 7625 0AF2: MOVLW 01
7626 0AF4: MOVLB 4 7626 0AF4: MOVLB 4
7627 0AF6: MOVWF x58 7627 0AF6: MOVWF x58
7628 .................... } 7628 .................... }
7629 .................... usb_request_send_response(2); 7629 .................... usb_request_send_response(2);
7630 0AF8: MOVLW 02 7630 0AF8: MOVLW 02
7631 0AFA: MOVLB 7 7631 0AFA: MOVLB 7
7632 0AFC: MOVWF x00 7632 0AFC: MOVWF x00
7633 0AFE: MOVLB 0 7633 0AFE: MOVLB 0
7634 0B00: RCALL 03EE 7634 0B00: RCALL 03EE
7635 .................... break; 7635 .................... break;
7636 0B02: BRA 0B08 7636 0B02: BRA 0B08
7637 .................... 7637 ....................
7638 .................... default: 7638 .................... default:
7639 .................... usb_request_stall(); 7639 .................... usb_request_stall();
7640 0B04: RCALL 03F4 7640 0B04: RCALL 03F4
7641 .................... break; 7641 .................... break;
7642 0B06: BRA 0B08 7642 0B06: BRA 0B08
7643 .................... } 7643 .................... }
7644 .................... } 7644 .................... }
7645 .................... } 7645 .................... }
7646 0B08: GOTO 0BE6 (RETURN) 7646 0B08: GOTO 0BE6 (RETURN)
7647 .................... 7647 ....................
7648 .................... /************************************************************** 7648 .................... /**************************************************************
7649 .................... /* usb_isr_tkn_setup_ClassInterface() 7649 .................... /* usb_isr_tkn_setup_ClassInterface()
7650 .................... /* 7650 .................... /*
7651 .................... /* Input: usb_ep0_rx_buffer[1] == bRequest 7651 .................... /* Input: usb_ep0_rx_buffer[1] == bRequest
7652 .................... /* 7652 .................... /*
7653 .................... /* Summary: bmRequestType told us it was a Class request. The only Class this drivers supports is HID. 7653 .................... /* Summary: bmRequestType told us it was a Class request. The only Class this drivers supports is HID.
7654 .................... /* bRequest says which request. Only certain requests are valid, 7654 .................... /* bRequest says which request. Only certain requests are valid,
7655 .................... /* if a non-valid request was made then return with an Wrong-Statue (IDLE) 7655 .................... /* if a non-valid request was made then return with an Wrong-Statue (IDLE)
7656 .................... /* 7656 .................... /*
7657 .................... /* Part of usb_isr_tok_setup_dne() 7657 .................... /* Part of usb_isr_tok_setup_dne()
7658 .................... /* Only compiled if HID_DEVICE is TRUE 7658 .................... /* Only compiled if HID_DEVICE is TRUE
7659 .................... /***************************************************************/ 7659 .................... /***************************************************************/
7660 .................... #IF USB_HID_DEVICE 7660 .................... #IF USB_HID_DEVICE
7661 .................... void usb_isr_tkn_setup_ClassInterface(void) { 7661 .................... void usb_isr_tkn_setup_ClassInterface(void) {
7662 .................... switch(usb_ep0_rx_buffer[1]) { 7662 .................... switch(usb_ep0_rx_buffer[1]) {
7663 .................... 7663 ....................
7664 .................... #IF USB_HID_BOOT_PROTOCOL 7664 .................... #IF USB_HID_BOOT_PROTOCOL
7665 .................... case USB_HID_REQUEST_GET_PROTOCOL: //03 7665 .................... case USB_HID_REQUEST_GET_PROTOCOL: //03
7666 .................... debug_usb(debug_putc,"GP"); 7666 .................... debug_usb(debug_putc,"GP");
7667 .................... usb_ep0_tx_buffer[0]=hid_protocol[usb_ep0_rx_buffer[4]]; 7667 .................... usb_ep0_tx_buffer[0]=hid_protocol[usb_ep0_rx_buffer[4]];
7668 .................... usb_request_send_response(1); 7668 .................... usb_request_send_response(1);
7669 .................... break; 7669 .................... break;
7670 .................... #ENDIF 7670 .................... #ENDIF
7671 .................... 7671 ....................
7672 .................... #IF USB_HID_BOOT_PROTOCOL 7672 .................... #IF USB_HID_BOOT_PROTOCOL
7673 .................... case USB_HID_REQUEST_SET_PROTOCOL: //0b 7673 .................... case USB_HID_REQUEST_SET_PROTOCOL: //0b
7674 .................... debug_usb(debug_putc,"SP"); 7674 .................... debug_usb(debug_putc,"SP");
7675 .................... hid_protocol[usb_ep0_rx_buffer[4]]=usb_ep0_rx_buffer[2]; 7675 .................... hid_protocol[usb_ep0_rx_buffer[4]]=usb_ep0_rx_buffer[2];
7676 .................... usb_put_0len_0(); //send 0len packet69 7676 .................... usb_put_0len_0(); //send 0len packet69
7677 .................... break; 7677 .................... break;
7678 .................... #ENDIF 7678 .................... #ENDIF
7679 .................... 7679 ....................
7680 .................... #IF USB_HID_IDLE 7680 .................... #IF USB_HID_IDLE
7681 .................... case USB_HID_REQUEST_SET_IDLE: //0a 7681 .................... case USB_HID_REQUEST_SET_IDLE: //0a
7682 .................... #error TODO: if you want to support SET_IDLE, add code here 7682 .................... #error TODO: if you want to support SET_IDLE, add code here
7683 .................... #ENDIF 7683 .................... #ENDIF
7684 .................... 7684 ....................
7685 .................... #IF USB_HID_IDLE 7685 .................... #IF USB_HID_IDLE
7686 .................... case USB_HID_REQUEST_GET_IDLE: //02 7686 .................... case USB_HID_REQUEST_GET_IDLE: //02
7687 .................... #error TODO: if you want to support GET_IDLE, add code here 7687 .................... #error TODO: if you want to support GET_IDLE, add code here
7688 .................... #ENDIF 7688 .................... #ENDIF
7689 .................... 7689 ....................
7690 .................... default: 7690 .................... default:
7691 .................... usb_request_stall(); 7691 .................... usb_request_stall();
7692 .................... break; 7692 .................... break;
7693 .................... } 7693 .................... }
7694 .................... } 7694 .................... }
7695 .................... #ENDIF 7695 .................... #ENDIF
7696 .................... 7696 ....................
7697 .................... /************************************************************** 7697 .................... /**************************************************************
7698 .................... /* usb_Get_Descriptor() 7698 .................... /* usb_Get_Descriptor()
7699 .................... /* 7699 .................... /*
7700 .................... /* Input: usb_ep0_rx_buffer[3] == wValue, which descriptor we want 7700 .................... /* Input: usb_ep0_rx_buffer[3] == wValue, which descriptor we want
7701 .................... /* usb_ep0_rx_buffer[6,7] == Max length the host will accept 7701 .................... /* usb_ep0_rx_buffer[6,7] == Max length the host will accept
7702 .................... /* 7702 .................... /*
7703 .................... /* Summary: Checks to see if we want a standard descriptor (Interface, Endpoint, Config, Device, String, etc.), 7703 .................... /* Summary: Checks to see if we want a standard descriptor (Interface, Endpoint, Config, Device, String, etc.),
7704 .................... /* or a class specific (HID) descriptor. Since some pics (especially the PIC167x5) doesn't have 7704 .................... /* or a class specific (HID) descriptor. Since some pics (especially the PIC167x5) doesn't have
7705 .................... /* pointers to constants we must simulate or own by setting up global registers that say 7705 .................... /* pointers to constants we must simulate or own by setting up global registers that say
7706 .................... /* which constant array to deal with, which position to start in this array, and the length. 7706 .................... /* which constant array to deal with, which position to start in this array, and the length.
7707 .................... /* Once these globals are setup the first packet is sent. If a descriptor takes more than one packet 7707 .................... /* Once these globals are setup the first packet is sent. If a descriptor takes more than one packet
7708 .................... /* the PC will send an IN request to endpoint 0, and this will be handled by usb_isr_tok_in_dne() 7708 .................... /* the PC will send an IN request to endpoint 0, and this will be handled by usb_isr_tok_in_dne()
7709 .................... /* which will send the rest of the data. 7709 .................... /* which will send the rest of the data.
7710 .................... /* 7710 .................... /*
7711 .................... /* Part of usb_isr_tok_setup_dne() 7711 .................... /* Part of usb_isr_tok_setup_dne()
7712 .................... /***************************************************************/ 7712 .................... /***************************************************************/
7713 .................... void usb_Get_Descriptor() { 7713 .................... void usb_Get_Descriptor() {
7714 .................... usb_getdesc_ptr=0; 7714 .................... usb_getdesc_ptr=0;
7715 * 7715 *
7716 049C: CLRF 27 7716 049C: CLRF 27
7717 .................... USB_stack_status.getdesc_type=USB_GETDESC_CONFIG_TYPE; 7717 .................... USB_stack_status.getdesc_type=USB_GETDESC_CONFIG_TYPE;
7718 049E: CLRF 20 7718 049E: CLRF 20
7719 .................... 7719 ....................
7720 .................... switch(usb_ep0_rx_buffer[3]) { 7720 .................... switch(usb_ep0_rx_buffer[3]) {
7721 04A0: MOVLB 4 7721 04A0: MOVLB 4
7722 04A2: MOVF x1B,W 7722 04A2: MOVF x1B,W
7723 04A4: XORLW 01 7723 04A4: XORLW 01
7724 04A6: MOVLB 0 7724 04A6: MOVLB 0
7725 04A8: BZ 04B8 7725 04A8: BZ 04B8
7726 04AA: XORLW 03 7726 04AA: XORLW 03
7727 04AC: BZ 04C2 7727 04AC: BZ 04C2
7728 04AE: XORLW 01 7728 04AE: XORLW 01
7729 04B0: BZ 04C8 7729 04B0: BZ 04C8
7730 04B2: XORLW 22 7730 04B2: XORLW 22
7731 04B4: BZ 04FA 7731 04B4: BZ 04FA
7732 04B6: BRA 053C 7732 04B6: BRA 053C
7733 .................... case USB_DESC_DEVICE_TYPE: //1 7733 .................... case USB_DESC_DEVICE_TYPE: //1
7734 .................... usb_getdesc_len=USB_DESC_DEVICE_LEN; 7734 .................... usb_getdesc_len=USB_DESC_DEVICE_LEN;
7735 04B8: MOVLW 12 7735 04B8: MOVLW 12
7736 04BA: MOVWF 28 7736 04BA: MOVWF 28
7737 .................... USB_stack_status.getdesc_type=USB_GETDESC_DEVICE_TYPE; 7737 .................... USB_stack_status.getdesc_type=USB_GETDESC_DEVICE_TYPE;
7738 04BC: MOVLW 03 7738 04BC: MOVLW 03
7739 04BE: MOVWF 20 7739 04BE: MOVWF 20
7740 .................... break; 7740 .................... break;
7741 04C0: BRA 0540 7741 04C0: BRA 0540
7742 .................... 7742 ....................
7743 .................... //windows hosts will send a FF max len and expect you to send all configs without asking for them individually. 7743 .................... //windows hosts will send a FF max len and expect you to send all configs without asking for them individually.
7744 .................... case USB_DESC_CONFIG_TYPE: //2 7744 .................... case USB_DESC_CONFIG_TYPE: //2
7745 .................... usb_getdesc_len=USB_TOTAL_CONFIG_LEN; 7745 .................... usb_getdesc_len=USB_TOTAL_CONFIG_LEN;
7746 04C2: MOVLW 43 7746 04C2: MOVLW 43
7747 04C4: MOVWF 28 7747 04C4: MOVWF 28
7748 .................... break; 7748 .................... break;
7749 04C6: BRA 0540 7749 04C6: BRA 0540
7750 .................... 7750 ....................
7751 .................... case USB_DESC_STRING_TYPE: //3 7751 .................... case USB_DESC_STRING_TYPE: //3
7752 .................... USB_stack_status.getdesc_type=USB_GETDESC_STRING_TYPE; 7752 .................... USB_stack_status.getdesc_type=USB_GETDESC_STRING_TYPE;
7753 04C8: MOVLW 02 7753 04C8: MOVLW 02
7754 04CA: MOVWF 20 7754 04CA: MOVWF 20
7755 .................... usb_getdesc_ptr=USB_STRING_DESC_OFFSET[usb_ep0_rx_buffer[2]]; 7755 .................... usb_getdesc_ptr=USB_STRING_DESC_OFFSET[usb_ep0_rx_buffer[2]];
7756 04CC: CLRF 03 7756 04CC: CLRF 03
7757 04CE: MOVLB 4 7757 04CE: MOVLB 4
7758 04D0: MOVF x1A,W 7758 04D0: MOVF x1A,W
7759 04D2: ADDLW 21 7759 04D2: ADDLW 21
7760 04D4: MOVWF FE9 7760 04D4: MOVWF FE9
7761 04D6: MOVLW 00 7761 04D6: MOVLW 00
7762 04D8: ADDWFC 03,W 7762 04D8: ADDWFC 03,W
7763 04DA: MOVWF FEA 7763 04DA: MOVWF FEA
7764 04DC: MOVFF FEF,27 7764 04DC: MOVFF FEF,27
7765 .................... usb_getdesc_len=USB_STRING_DESC[usb_getdesc_ptr]; 7765 .................... usb_getdesc_len=USB_STRING_DESC[usb_getdesc_ptr];
7766 04E0: CLRF 03 7766 04E0: CLRF 03
7767 04E2: MOVF 27,W 7767 04E2: MOVF 27,W
7768 04E4: MOVFF FF2,6FD 7768 04E4: MOVFF FF2,6FD
7769 04E8: BCF FF2.7 7769 04E8: BCF FF2.7
7770 04EA: MOVLB 0 7770 04EA: MOVLB 0
7771 04EC: RCALL 01EA 7771 04EC: RCALL 01EA
7772 04EE: MOVLB 6 7772 04EE: MOVLB 6
7773 04F0: BTFSC xFD.7 7773 04F0: BTFSC xFD.7
7774 04F2: BSF FF2.7 7774 04F2: BSF FF2.7
7775 04F4: MOVWF 28 7775 04F4: MOVWF 28
7776 .................... break; 7776 .................... break;
7777 04F6: MOVLB 0 7777 04F6: MOVLB 0
7778 04F8: BRA 0540 7778 04F8: BRA 0540
7779 .................... 7779 ....................
7780 .................... #IF USB_HID_DEVICE || USB_CDC_DEVICE 7780 .................... #IF USB_HID_DEVICE || USB_CDC_DEVICE
7781 .................... case USB_DESC_CLASS_TYPE: //0x21 7781 .................... case USB_DESC_CLASS_TYPE: //0x21
7782 .................... //TODO does this work for multiple interfaces or multiple languages? 7782 .................... //TODO does this work for multiple interfaces or multiple languages?
7783 .................... //usb_getdesc_ptr=USB_CLASS_DESCRIPTORS[0][usb_ep0_rx_buffer[4]][usb_ep0_rx_buffer[2]]; 7783 .................... //usb_getdesc_ptr=USB_CLASS_DESCRIPTORS[0][usb_ep0_rx_buffer[4]][usb_ep0_rx_buffer[2]];
7784 .................... usb_getdesc_ptr=USB_CLASS_DESCRIPTORS[0][0][usb_ep0_rx_buffer[2]]; 7784 .................... usb_getdesc_ptr=USB_CLASS_DESCRIPTORS[0][0][usb_ep0_rx_buffer[2]];
7785 04FA: CLRF 03 7785 04FA: CLRF 03
7786 04FC: MOVLB 4 7786 04FC: MOVLB 4
7787 04FE: MOVF x1A,W 7787 04FE: MOVF x1A,W
7788 0500: MOVFF FF2,6FD 7788 0500: MOVFF FF2,6FD
7789 0504: BCF FF2.7 7789 0504: BCF FF2.7
7790 0506: MOVLB 0 7790 0506: MOVLB 0
7791 0508: RCALL 01B0 7791 0508: RCALL 01B0
7792 050A: MOVLB 6 7792 050A: MOVLB 6
7793 050C: BTFSC xFD.7 7793 050C: BTFSC xFD.7
7794 050E: BSF FF2.7 7794 050E: BSF FF2.7
7795 0510: MOVWF 27 7795 0510: MOVWF 27
7796 .................... if (usb_getdesc_ptr!=0xFF) { 7796 .................... if (usb_getdesc_ptr!=0xFF) {
7797 0512: INCFSZ 27,W 7797 0512: INCFSZ 27,W
7798 0514: BRA 0518 7798 0514: BRA 0518
7799 0516: BRA 0536 7799 0516: BRA 0536
7800 .................... usb_getdesc_len=USB_CONFIG_DESC[usb_getdesc_ptr]; 7800 .................... usb_getdesc_len=USB_CONFIG_DESC[usb_getdesc_ptr];
7801 0518: CLRF 03 7801 0518: CLRF 03
7802 051A: MOVF 27,W 7802 051A: MOVF 27,W
7803 051C: MOVFF FF2,6FD 7803 051C: MOVFF FF2,6FD
7804 0520: BCF FF2.7 7804 0520: BCF FF2.7
7805 0522: MOVLB 0 7805 0522: MOVLB 0
7806 0524: RCALL 014A 7806 0524: RCALL 014A
7807 0526: MOVLB 6 7807 0526: MOVLB 6
7808 0528: BTFSC xFD.7 7808 0528: BTFSC xFD.7
7809 052A: BSF FF2.7 7809 052A: BSF FF2.7
7810 052C: MOVWF 28 7810 052C: MOVWF 28
7811 .................... break; 7811 .................... break;
7812 052E: MOVLB 0 7812 052E: MOVLB 0
7813 0530: BRA 0540 7813 0530: BRA 0540
7814 .................... } 7814 .................... }
7815 .................... else { 7815 .................... else {
7816 0532: BRA 053C 7816 0532: BRA 053C
7817 0534: MOVLB 6 7817 0534: MOVLB 6
7818 .................... usb_request_stall(); 7818 .................... usb_request_stall();
7819 0536: MOVLB 0 7819 0536: MOVLB 0
7820 0538: RCALL 03F4 7820 0538: RCALL 03F4
7821 .................... return; 7821 .................... return;
7822 053A: BRA 0558 7822 053A: BRA 0558
7823 .................... } 7823 .................... }
7824 .................... #endif 7824 .................... #endif
7825 .................... 7825 ....................
7826 .................... #IF USB_HID_DEVICE 7826 .................... #IF USB_HID_DEVICE
7827 .................... case USB_DESC_HIDREPORT_TYPE: //0x22 7827 .................... case USB_DESC_HIDREPORT_TYPE: //0x22
7828 .................... usb_getdesc_ptr=USB_CLASS_SPECIFIC_DESC_LOOKUP[0][usb_ep0_rx_buffer[4]]; 7828 .................... usb_getdesc_ptr=USB_CLASS_SPECIFIC_DESC_LOOKUP[0][usb_ep0_rx_buffer[4]];
7829 .................... if (usb_getdesc_ptr !=0xFF) { 7829 .................... if (usb_getdesc_ptr !=0xFF) {
7830 .................... USB_stack_status.getdesc_type=USB_GETDESC_HIDREPORT_TYPE; 7830 .................... USB_stack_status.getdesc_type=USB_GETDESC_HIDREPORT_TYPE;
7831 .................... usb_getdesc_len=USB_CLASS_SPECIFIC_DESC_LOOKUP_SIZE[0][usb_ep0_rx_buffer[4]]; 7831 .................... usb_getdesc_len=USB_CLASS_SPECIFIC_DESC_LOOKUP_SIZE[0][usb_ep0_rx_buffer[4]];
7832 .................... break; 7832 .................... break;
7833 .................... } 7833 .................... }
7834 .................... else { 7834 .................... else {
7835 .................... usb_request_stall(); 7835 .................... usb_request_stall();
7836 .................... return; 7836 .................... return;
7837 .................... } 7837 .................... }
7838 .................... #endif 7838 .................... #endif
7839 .................... 7839 ....................
7840 .................... default: 7840 .................... default:
7841 .................... usb_request_stall(); 7841 .................... usb_request_stall();
7842 053C: RCALL 03F4 7842 053C: RCALL 03F4
7843 .................... return; 7843 .................... return;
7844 053E: BRA 0558 7844 053E: BRA 0558
7845 .................... } 7845 .................... }
7846 .................... if (usb_ep0_rx_buffer[7]==0) { 7846 .................... if (usb_ep0_rx_buffer[7]==0) {
7847 0540: MOVLB 4 7847 0540: MOVLB 4
7848 0542: MOVF x1F,F 7848 0542: MOVF x1F,F
7849 0544: BNZ 0550 7849 0544: BNZ 0550
7850 .................... if (usb_getdesc_len > usb_ep0_rx_buffer[6]) 7850 .................... if (usb_getdesc_len > usb_ep0_rx_buffer[6])
7851 0546: MOVF 28,W 7851 0546: MOVF 28,W
7852 0548: SUBWF x1E,W 7852 0548: SUBWF x1E,W
7853 054A: BC 0550 7853 054A: BC 0550
7854 .................... usb_getdesc_len = usb_ep0_rx_buffer[6]; 7854 .................... usb_getdesc_len = usb_ep0_rx_buffer[6];
7855 054C: MOVFF 41E,28 7855 054C: MOVFF 41E,28
7856 .................... } 7856 .................... }
7857 .................... USB_stack_status.dev_req=GET_DESCRIPTOR; 7857 .................... USB_stack_status.dev_req=GET_DESCRIPTOR;
7858 0550: MOVLW 01 7858 0550: MOVLW 01
7859 0552: MOVWF 1D 7859 0552: MOVWF 1D
7860 .................... usb_copy_desc_seg_to_ep(); 7860 .................... usb_copy_desc_seg_to_ep();
7861 0554: MOVLB 0 7861 0554: MOVLB 0
7862 0556: RCALL 03FA 7862 0556: RCALL 03FA
7863 .................... } 7863 .................... }
7864 0558: GOTO 083C (RETURN) 7864 0558: GOTO 083C (RETURN)
7865 .................... 7865 ....................
7866 .................... /************************************************************** 7866 .................... /**************************************************************
7867 .................... /* usb_finish_set_address() 7867 .................... /* usb_finish_set_address()
7868 .................... /* 7868 .................... /*
7869 .................... /* Input: USB_address_pending holds the address we were asked to set to. 7869 .................... /* Input: USB_address_pending holds the address we were asked to set to.
7870 .................... /* 7870 .................... /*
7871 .................... /* Summary: Sets the address. 7871 .................... /* Summary: Sets the address.
7872 .................... /* 7872 .................... /*
7873 .................... /* This code should only be run on the PIC USB peripheral, and not the 7873 .................... /* This code should only be run on the PIC USB peripheral, and not the
7874 .................... /* National peripheral. 7874 .................... /* National peripheral.
7875 .................... /* 7875 .................... /*
7876 .................... /* Part of usb_isr_tok_setup_dne() 7876 .................... /* Part of usb_isr_tok_setup_dne()
7877 .................... /***************************************************************/ 7877 .................... /***************************************************************/
7878 .................... void usb_finish_set_address() { 7878 .................... void usb_finish_set_address() {
7879 .................... debug_usb(debug_putc," FSA "); 7879 .................... debug_usb(debug_putc," FSA ");
7880 .................... USB_stack_status.curr_config=0; // make sure current configuration is 0 7880 .................... USB_stack_status.curr_config=0; // make sure current configuration is 0
7881 * 7881 *
7882 0F7A: CLRF 1E 7882 0F7A: CLRF 1E
7883 .................... 7883 ....................
7884 .................... #ifdef __PIC__ 7884 .................... #ifdef __PIC__
7885 .................... USB_stack_status.dev_req=NONE; // no request pending 7885 .................... USB_stack_status.dev_req=NONE; // no request pending
7886 0F7C: CLRF 1D 7886 0F7C: CLRF 1D
7887 .................... usb_set_address(USB_address_pending); 7887 .................... usb_set_address(USB_address_pending);
7888 0F7E: MOVFF 26,6FE 7888 0F7E: MOVFF 26,6FE
7889 0F82: BRA 0F60 7889 0F82: BRA 0F60
7890 .................... #endif 7890 .................... #endif
7891 .................... } 7891 .................... }
7892 0F84: GOTO 1076 (RETURN) 7892 0F84: GOTO 1076 (RETURN)
7893 .................... 7893 ....................
7894 .................... //////////////////////////////////////////////////////////////////////////// 7894 .................... ////////////////////////////////////////////////////////////////////////////
7895 .................... /// 7895 .................... ///
7896 .................... /// The following function retrieve data from constant arrays. This may 7896 .................... /// The following function retrieve data from constant arrays. This may
7897 .................... /// look un-optimized, but remember that you can't create a pointer to 7897 .................... /// look un-optimized, but remember that you can't create a pointer to
7898 .................... /// a constant array. 7898 .................... /// a constant array.
7899 .................... /// 7899 .................... ///
7900 .................... /////////////////////////////////////////////////////////////////////////// 7900 .................... ///////////////////////////////////////////////////////////////////////////
7901 .................... void usb_copy_desc_seg_to_ep(void) { 7901 .................... void usb_copy_desc_seg_to_ep(void) {
7902 .................... unsigned int i=0; 7902 .................... unsigned int i=0;
7903 * 7903 *
7904 03FA: MOVLB 6 7904 03FA: MOVLB 6
7905 03FC: CLRF xFE 7905 03FC: CLRF xFE
7906 .................... char c; 7906 .................... char c;
7907 .................... 7907 ....................
7908 .................... while ((usb_getdesc_len)&&(i<USB_MAX_EP0_PACKET_LENGTH)) 7908 .................... while ((usb_getdesc_len)&&(i<USB_MAX_EP0_PACKET_LENGTH))
7909 .................... { 7909 .................... {
7910 03FE: MOVF 28,F 7910 03FE: MOVF 28,F
7911 0400: BZ 0486 7911 0400: BZ 0486
7912 0402: MOVF xFE,W 7912 0402: MOVF xFE,W
7913 0404: SUBLW 3F 7913 0404: SUBLW 3F
7914 0406: BNC 0486 7914 0406: BNC 0486
7915 .................... switch(USB_stack_status.getdesc_type) { 7915 .................... switch(USB_stack_status.getdesc_type) {
7916 0408: MOVF 20,W 7916 0408: MOVF 20,W
7917 040A: MOVLB 0 7917 040A: MOVLB 0
7918 040C: BZ 0418 7918 040C: BZ 0418
7919 040E: XORLW 02 7919 040E: XORLW 02
7920 0410: BZ 0432 7920 0410: BZ 0432
7921 0412: XORLW 01 7921 0412: XORLW 01
7922 0414: BZ 044C 7922 0414: BZ 044C
7923 0416: BRA 0466 7923 0416: BRA 0466
7924 .................... case USB_GETDESC_CONFIG_TYPE: 7924 .................... case USB_GETDESC_CONFIG_TYPE:
7925 .................... c=USB_CONFIG_DESC[usb_getdesc_ptr]; 7925 .................... c=USB_CONFIG_DESC[usb_getdesc_ptr];
7926 0418: CLRF 03 7926 0418: CLRF 03
7927 041A: MOVF 27,W 7927 041A: MOVF 27,W
7928 041C: MOVFF FF2,700 7928 041C: MOVFF FF2,700
7929 0420: BCF FF2.7 7929 0420: BCF FF2.7
7930 0422: RCALL 014A 7930 0422: RCALL 014A
7931 0424: MOVLB 7 7931 0424: MOVLB 7
7932 0426: BTFSC x00.7 7932 0426: BTFSC x00.7
7933 0428: BSF FF2.7 7933 0428: BSF FF2.7
7934 042A: MOVFF FE8,6FF 7934 042A: MOVFF FE8,6FF
7935 .................... break; 7935 .................... break;
7936 042E: MOVLB 0 7936 042E: MOVLB 0
7937 0430: BRA 0466 7937 0430: BRA 0466
7938 .................... 7938 ....................
7939 .................... #IF USB_HID_DEVICE 7939 .................... #IF USB_HID_DEVICE
7940 .................... case USB_GETDESC_HIDREPORT_TYPE: 7940 .................... case USB_GETDESC_HIDREPORT_TYPE:
7941 .................... c=USB_CLASS_SPECIFIC_DESC[usb_getdesc_ptr]; 7941 .................... c=USB_CLASS_SPECIFIC_DESC[usb_getdesc_ptr];
7942 .................... break; 7942 .................... break;
7943 .................... #endif 7943 .................... #endif
7944 .................... 7944 ....................
7945 .................... case USB_GETDESC_STRING_TYPE: 7945 .................... case USB_GETDESC_STRING_TYPE:
7946 .................... c=USB_STRING_DESC[usb_getdesc_ptr]; 7946 .................... c=USB_STRING_DESC[usb_getdesc_ptr];
7947 0432: CLRF 03 7947 0432: CLRF 03
7948 0434: MOVF 27,W 7948 0434: MOVF 27,W
7949 0436: MOVFF FF2,700 7949 0436: MOVFF FF2,700
7950 043A: BCF FF2.7 7950 043A: BCF FF2.7
7951 043C: RCALL 01EA 7951 043C: RCALL 01EA
7952 043E: MOVLB 7 7952 043E: MOVLB 7
7953 0440: BTFSC x00.7 7953 0440: BTFSC x00.7
7954 0442: BSF FF2.7 7954 0442: BSF FF2.7
7955 0444: MOVFF FE8,6FF 7955 0444: MOVFF FE8,6FF
7956 .................... break; 7956 .................... break;
7957 0448: MOVLB 0 7957 0448: MOVLB 0
7958 044A: BRA 0466 7958 044A: BRA 0466
7959 .................... 7959 ....................
7960 .................... case USB_GETDESC_DEVICE_TYPE: 7960 .................... case USB_GETDESC_DEVICE_TYPE:
7961 .................... c=USB_DEVICE_DESC[usb_getdesc_ptr]; 7961 .................... c=USB_DEVICE_DESC[usb_getdesc_ptr];
7962 044C: CLRF 03 7962 044C: CLRF 03
7963 044E: MOVF 27,W 7963 044E: MOVF 27,W
7964 0450: MOVFF FF2,700 7964 0450: MOVFF FF2,700
7965 0454: BCF FF2.7 7965 0454: BCF FF2.7
7966 0456: RCALL 01C8 7966 0456: RCALL 01C8
7967 0458: MOVLB 7 7967 0458: MOVLB 7
7968 045A: BTFSC x00.7 7968 045A: BTFSC x00.7
7969 045C: BSF FF2.7 7969 045C: BSF FF2.7
7970 045E: MOVFF FE8,6FF 7970 045E: MOVFF FE8,6FF
7971 .................... break; 7971 .................... break;
7972 0462: MOVLB 0 7972 0462: MOVLB 0
7973 0464: BRA 0466 7973 0464: BRA 0466
7974 .................... } 7974 .................... }
7975 .................... usb_getdesc_ptr++; 7975 .................... usb_getdesc_ptr++;
7976 0466: INCF 27,F 7976 0466: INCF 27,F
7977 .................... usb_getdesc_len--; 7977 .................... usb_getdesc_len--;
7978 0468: DECF 28,F 7978 0468: DECF 28,F
7979 .................... usb_ep0_tx_buffer[i++]=c; 7979 .................... usb_ep0_tx_buffer[i++]=c;
7980 046A: MOVLB 6 7980 046A: MOVLB 6
7981 046C: MOVF xFE,W 7981 046C: MOVF xFE,W
7982 046E: INCF xFE,F 7982 046E: INCF xFE,F
7983 0470: ADDLW 58 7983 0470: ADDLW 58
7984 0472: CLRF 03 7984 0472: CLRF 03
7985 0474: BTFSC FD8.0 7985 0474: BTFSC FD8.0
7986 0476: INCF 03,F 7986 0476: INCF 03,F
7987 0478: MOVWF FE9 7987 0478: MOVWF FE9
7988 047A: MOVLW 04 7988 047A: MOVLW 04
7989 047C: ADDWF 03,W 7989 047C: ADDWF 03,W
7990 047E: MOVWF FEA 7990 047E: MOVWF FEA
7991 0480: MOVFF 6FF,FEF 7991 0480: MOVFF 6FF,FEF
7992 .................... } 7992 .................... }
7993 0484: BRA 03FE 7993 0484: BRA 03FE
7994 .................... 7994 ....................
7995 .................... if ((!usb_getdesc_len)&&(i!=USB_MAX_EP0_PACKET_LENGTH)) { 7995 .................... if ((!usb_getdesc_len)&&(i!=USB_MAX_EP0_PACKET_LENGTH)) {
7996 0486: MOVF 28,F 7996 0486: MOVF 28,F
7997 0488: BNZ 0492 7997 0488: BNZ 0492
7998 048A: MOVF xFE,W 7998 048A: MOVF xFE,W
7999 048C: SUBLW 40 7999 048C: SUBLW 40
8000 048E: BZ 0492 8000 048E: BZ 0492
8001 .................... USB_stack_status.dev_req = NONE; 8001 .................... USB_stack_status.dev_req = NONE;
8002 0490: CLRF 1D 8002 0490: CLRF 1D
8003 .................... } 8003 .................... }
8004 .................... 8004 ....................
8005 .................... usb_request_send_response(i); 8005 .................... usb_request_send_response(i);
8006 0492: MOVFF 6FE,700 8006 0492: MOVFF 6FE,700
8007 0496: MOVLB 0 8007 0496: MOVLB 0
8008 0498: RCALL 03EE 8008 0498: RCALL 03EE
8009 .................... } 8009 .................... }
8010 049A: RETLW 00 8010 049A: RETLW 00
8011 .................... 8011 ....................
8012 .................... #ENDIF 8012 .................... #ENDIF
8013 .................... 8013 ....................
8014 .................... 8014 ....................
8015 .................... struct { 8015 .................... struct {
8016 .................... unsigned int32 dwDTERrate; //data terminal rate, in bits per second 8016 .................... unsigned int32 dwDTERrate; //data terminal rate, in bits per second
8017 .................... unsigned int8 bCharFormat; //num of stop bits (0=1, 1=1.5, 2=2) 8017 .................... unsigned int8 bCharFormat; //num of stop bits (0=1, 1=1.5, 2=2)
8018 .................... unsigned int8 bParityType; //parity (0=none, 1=odd, 2=even, 3=mark, 4=space) 8018 .................... unsigned int8 bParityType; //parity (0=none, 1=odd, 2=even, 3=mark, 4=space)
8019 .................... unsigned int8 bDataBits; //data bits (5,6,7,8 or 16) 8019 .................... unsigned int8 bDataBits; //data bits (5,6,7,8 or 16)
8020 .................... } __attribute__((__packed__)) usb_cdc_line_coding; 8020 .................... } __attribute__((__packed__)) usb_cdc_line_coding;
8021 .................... 8021 ....................
8022 .................... //length of time, in ms, of break signal as we received in a SendBreak message. 8022 .................... //length of time, in ms, of break signal as we received in a SendBreak message.
8023 .................... //if ==0xFFFF, send break signal until we receive a 0x0000. 8023 .................... //if ==0xFFFF, send break signal until we receive a 0x0000.
8024 .................... unsigned int16 usb_cdc_break; 8024 .................... unsigned int16 usb_cdc_break;
8025 .................... 8025 ....................
8026 .................... unsigned int8 usb_cdc_encapsulated_cmd[8]; 8026 .................... unsigned int8 usb_cdc_encapsulated_cmd[8];
8027 .................... 8027 ....................
8028 .................... unsigned int8 usb_cdc_put_buffer[USB_CDC_DATA_IN_SIZE]; 8028 .................... unsigned int8 usb_cdc_put_buffer[USB_CDC_DATA_IN_SIZE];
8029 .................... #define usb_cdc_put_buffer_free() usb_tbe(USB_CDC_DATA_IN_ENDPOINT) 8029 .................... #define usb_cdc_put_buffer_free() usb_tbe(USB_CDC_DATA_IN_ENDPOINT)
8030 .................... #if USB_CDC_DATA_IN_SIZE>=0x100 8030 .................... #if USB_CDC_DATA_IN_SIZE>=0x100
8031 .................... unsigned int16 usb_cdc_put_buffer_nextin=0; 8031 .................... unsigned int16 usb_cdc_put_buffer_nextin=0;
8032 .................... // int16 usb_cdc_last_data_packet_size; 8032 .................... // int16 usb_cdc_last_data_packet_size;
8033 .................... #else 8033 .................... #else
8034 .................... unsigned int8 usb_cdc_put_buffer_nextin=0; 8034 .................... unsigned int8 usb_cdc_put_buffer_nextin=0;
8035 .................... // int8 usb_cdc_last_data_packet_size; 8035 .................... // int8 usb_cdc_last_data_packet_size;
8036 .................... #endif 8036 .................... #endif
8037 .................... 8037 ....................
8038 .................... struct { 8038 .................... struct {
8039 .................... int1 got; 8039 .................... int1 got;
8040 .................... #if USB_CDC_DATA_OUT_SIZE>=0x100 8040 .................... #if USB_CDC_DATA_OUT_SIZE>=0x100
8041 .................... unsigned int16 len; 8041 .................... unsigned int16 len;
8042 .................... unsigned int16 index; 8042 .................... unsigned int16 index;
8043 .................... #else 8043 .................... #else
8044 .................... unsigned int8 len; 8044 .................... unsigned int8 len;
8045 .................... unsigned int8 index; 8045 .................... unsigned int8 index;
8046 .................... #endif 8046 .................... #endif
8047 .................... } usb_cdc_get_buffer_status; 8047 .................... } usb_cdc_get_buffer_status;
8048 .................... 8048 ....................
8049 .................... #if defined(__PIC__) 8049 .................... #if defined(__PIC__)
8050 .................... #define usb_cdc_get_buffer_status_buffer usb_ep2_rx_buffer 8050 .................... #define usb_cdc_get_buffer_status_buffer usb_ep2_rx_buffer
8051 .................... #else 8051 .................... #else
8052 .................... unsigned int8 usb_cdc_get_buffer_status_buffer[USB_CDC_DATA_OUT_SIZE]; 8052 .................... unsigned int8 usb_cdc_get_buffer_status_buffer[USB_CDC_DATA_OUT_SIZE];
8053 .................... #endif 8053 .................... #endif
8054 .................... 8054 ....................
8055 .................... int1 usb_cdc_got_set_line_coding; 8055 .................... int1 usb_cdc_got_set_line_coding;
8056 .................... 8056 ....................
8057 .................... struct { 8057 .................... struct {
8058 .................... int1 dte_present; //1=DTE present, 0=DTE not present 8058 .................... int1 dte_present; //1=DTE present, 0=DTE not present
8059 .................... int1 active; //1=activate carrier, 0=deactivate carrier 8059 .................... int1 active; //1=activate carrier, 0=deactivate carrier
8060 .................... unsigned int reserved:6; 8060 .................... unsigned int reserved:6;
8061 .................... } usb_cdc_carrier; 8061 .................... } usb_cdc_carrier;
8062 .................... 8062 ....................
8063 .................... unsigned int8 g_LastCDCDataPacketSize; 8063 .................... unsigned int8 g_LastCDCDataPacketSize;
8064 .................... 8064 ....................
8065 .................... enum {USB_CDC_OUT_NOTHING=0, USB_CDC_OUT_COMMAND=1, USB_CDC_OUT_LINECODING=2, USB_CDC_WAIT_0LEN=3} __usb_cdc_state=0; 8065 .................... enum {USB_CDC_OUT_NOTHING=0, USB_CDC_OUT_COMMAND=1, USB_CDC_OUT_LINECODING=2, USB_CDC_WAIT_0LEN=3} __usb_cdc_state=0;
8066 .................... 8066 ....................
8067 .................... #if defined(__PCH__) 8067 .................... #if defined(__PCH__)
8068 .................... #byte INTCON=0xFF2 8068 .................... #byte INTCON=0xFF2
8069 .................... #bit INT_GIE=INTCON.7 8069 .................... #bit INT_GIE=INTCON.7
8070 .................... #else 8070 .................... #else
8071 .................... #word SR=0x42 8071 .................... #word SR=0x42
8072 .................... #endif 8072 .................... #endif
8073 .................... 8073 ....................
8074 .................... //handle OUT token done interrupt on endpoint 0 [read encapsulated cmd and line coding data] 8074 .................... //handle OUT token done interrupt on endpoint 0 [read encapsulated cmd and line coding data]
8075 .................... void usb_isr_tok_out_cdc_control_dne(void) { 8075 .................... void usb_isr_tok_out_cdc_control_dne(void) {
8076 .................... debug_usb(debug_putc,"CDC %X ",__usb_cdc_state); 8076 .................... debug_usb(debug_putc,"CDC %X ",__usb_cdc_state);
8077 .................... 8077 ....................
8078 .................... switch (__usb_cdc_state) { 8078 .................... switch (__usb_cdc_state) {
8079 * 8079 *
8080 0E7E: MOVF x83,W 8080 0E7E: MOVF x83,W
8081 0E80: XORLW 01 8081 0E80: XORLW 01
8082 0E82: BZ 0E8A 8082 0E82: BZ 0E8A
8083 0E84: XORLW 03 8083 0E84: XORLW 03
8084 0E86: BZ 0EB2 8084 0E86: BZ 0EB2
8085 0E88: BRA 0EDA 8085 0E88: BRA 0EDA
8086 .................... //printf(putc_tbe,"@%X@\r\n", __usb_cdc_state); 8086 .................... //printf(putc_tbe,"@%X@\r\n", __usb_cdc_state);
8087 .................... case USB_CDC_OUT_COMMAND: 8087 .................... case USB_CDC_OUT_COMMAND:
8088 .................... //usb_get_packet(0, usb_cdc_encapsulated_cmd, 8); 8088 .................... //usb_get_packet(0, usb_cdc_encapsulated_cmd, 8);
8089 .................... memcpy(usb_cdc_encapsulated_cmd, usb_ep0_rx_buffer,8); 8089 .................... memcpy(usb_cdc_encapsulated_cmd, usb_ep0_rx_buffer,8);
8090 0E8A: CLRF FEA 8090 0E8A: CLRF FEA
8091 0E8C: MOVLW 34 8091 0E8C: MOVLW 34
8092 0E8E: MOVWF FE9 8092 0E8E: MOVWF FE9
8093 0E90: MOVLW 04 8093 0E90: MOVLW 04
8094 0E92: MOVWF FE2 8094 0E92: MOVWF FE2
8095 0E94: MOVLW 18 8095 0E94: MOVLW 18
8096 0E96: MOVWF FE1 8096 0E96: MOVWF FE1
8097 0E98: MOVLW 08 8097 0E98: MOVLW 08
8098 0E9A: MOVWF 01 8098 0E9A: MOVWF 01
8099 0E9C: MOVFF FE6,FEE 8099 0E9C: MOVFF FE6,FEE
8100 0EA0: DECFSZ 01,F 8100 0EA0: DECFSZ 01,F
8101 0EA2: BRA 0E9C 8101 0EA2: BRA 0E9C
8102 .................... #if USB_MAX_EP0_PACKET_LENGTH==8 8102 .................... #if USB_MAX_EP0_PACKET_LENGTH==8
8103 .................... __usb_cdc_state=USB_CDC_WAIT_0LEN; 8103 .................... __usb_cdc_state=USB_CDC_WAIT_0LEN;
8104 .................... usb_request_get_data(); 8104 .................... usb_request_get_data();
8105 .................... #else 8105 .................... #else
8106 .................... usb_put_0len_0(); 8106 .................... usb_put_0len_0();
8107 0EA4: MOVLB 7 8107 0EA4: MOVLB 7
8108 0EA6: CLRF x00 8108 0EA6: CLRF x00
8109 0EA8: MOVLB 0 8109 0EA8: MOVLB 0
8110 0EAA: CALL 03EE 8110 0EAA: CALL 03EE
8111 .................... __usb_cdc_state=0; 8111 .................... __usb_cdc_state=0;
8112 0EAE: CLRF x83 8112 0EAE: CLRF x83
8113 .................... #endif 8113 .................... #endif
8114 .................... break; 8114 .................... break;
8115 0EB0: BRA 0EE2 8115 0EB0: BRA 0EE2
8116 .................... 8116 ....................
8117 .................... #if USB_MAX_EP0_PACKET_LENGTH==8 8117 .................... #if USB_MAX_EP0_PACKET_LENGTH==8
8118 .................... case USB_CDC_WAIT_0LEN: 8118 .................... case USB_CDC_WAIT_0LEN:
8119 .................... usb_put_0len_0(); 8119 .................... usb_put_0len_0();
8120 .................... __usb_cdc_state=0; 8120 .................... __usb_cdc_state=0;
8121 .................... break; 8121 .................... break;
8122 .................... #endif 8122 .................... #endif
8123 .................... 8123 ....................
8124 .................... case USB_CDC_OUT_LINECODING: 8124 .................... case USB_CDC_OUT_LINECODING:
8125 .................... //usb_get_packet(0, &usb_cdc_line_coding, 7); 8125 .................... //usb_get_packet(0, &usb_cdc_line_coding, 7);
8126 .................... //printf(putc_tbe,"\r\n!GSLC FIN!\r\n"); 8126 .................... //printf(putc_tbe,"\r\n!GSLC FIN!\r\n");
8127 .................... memcpy(&usb_cdc_line_coding, usb_ep0_rx_buffer,7); 8127 .................... memcpy(&usb_cdc_line_coding, usb_ep0_rx_buffer,7);
8128 0EB2: CLRF FEA 8128 0EB2: CLRF FEA
8129 0EB4: MOVLW 2B 8129 0EB4: MOVLW 2B
8130 0EB6: MOVWF FE9 8130 0EB6: MOVWF FE9
8131 0EB8: MOVLW 04 8131 0EB8: MOVLW 04
8132 0EBA: MOVWF FE2 8132 0EBA: MOVWF FE2
8133 0EBC: MOVLW 18 8133 0EBC: MOVLW 18
8134 0EBE: MOVWF FE1 8134 0EBE: MOVWF FE1
8135 0EC0: MOVLW 07 8135 0EC0: MOVLW 07
8136 0EC2: MOVWF 01 8136 0EC2: MOVWF 01
8137 0EC4: MOVFF FE6,FEE 8137 0EC4: MOVFF FE6,FEE
8138 0EC8: DECFSZ 01,F 8138 0EC8: DECFSZ 01,F
8139 0ECA: BRA 0EC4 8139 0ECA: BRA 0EC4
8140 .................... __usb_cdc_state=0; 8140 .................... __usb_cdc_state=0;
8141 0ECC: CLRF x83 8141 0ECC: CLRF x83
8142 .................... usb_put_0len_0(); 8142 .................... usb_put_0len_0();
8143 0ECE: MOVLB 7 8143 0ECE: MOVLB 7
8144 0ED0: CLRF x00 8144 0ED0: CLRF x00
8145 0ED2: MOVLB 0 8145 0ED2: MOVLB 0
8146 0ED4: CALL 03EE 8146 0ED4: CALL 03EE
8147 .................... break; 8147 .................... break;
8148 0ED8: BRA 0EE2 8148 0ED8: BRA 0EE2
8149 .................... 8149 ....................
8150 .................... default: 8150 .................... default:
8151 .................... __usb_cdc_state=0; 8151 .................... __usb_cdc_state=0;
8152 0EDA: CLRF x83 8152 0EDA: CLRF x83
8153 .................... usb_init_ep0_setup(); 8153 .................... usb_init_ep0_setup();
8154 0EDC: CALL 0284 8154 0EDC: CALL 0284
8155 .................... break; 8155 .................... break;
8156 0EE0: BRA 0EE2 8156 0EE0: BRA 0EE2
8157 .................... } 8157 .................... }
8158 .................... } 8158 .................... }
8159 0EE2: GOTO 0F4C (RETURN) 8159 0EE2: GOTO 0F4C (RETURN)
8160 .................... 8160 ....................
8161 .................... //handle IN token on 0 (setup packet) 8161 .................... //handle IN token on 0 (setup packet)
8162 .................... void usb_isr_tkn_cdc(void) { 8162 .................... void usb_isr_tkn_cdc(void) {
8163 .................... //make sure the request goes to a CDC interface 8163 .................... //make sure the request goes to a CDC interface
8164 .................... if ((usb_ep0_rx_buffer[4] == 1) || (usb_ep0_rx_buffer[4] == 0)) { 8164 .................... if ((usb_ep0_rx_buffer[4] == 1) || (usb_ep0_rx_buffer[4] == 0)) {
8165 * 8165 *
8166 0B12: MOVLB 4 8166 0B12: MOVLB 4
8167 0B14: DECFSZ x1C,W 8167 0B14: DECFSZ x1C,W
8168 0B16: BRA 0B1A 8168 0B16: BRA 0B1A
8169 0B18: BRA 0B1E 8169 0B18: BRA 0B1E
8170 0B1A: MOVF x1C,F 8170 0B1A: MOVF x1C,F
8171 0B1C: BNZ 0BBA 8171 0B1C: BNZ 0BBA
8172 .................... //printf(putc_tbe,"!%X!\r\n", usb_ep0_rx_buffer[1]); 8172 .................... //printf(putc_tbe,"!%X!\r\n", usb_ep0_rx_buffer[1]);
8173 .................... switch(usb_ep0_rx_buffer[1]) { 8173 .................... switch(usb_ep0_rx_buffer[1]) {
8174 0B1E: MOVF x19,W 8174 0B1E: MOVF x19,W
8175 0B20: MOVLB 0 8175 0B20: MOVLB 0
8176 0B22: BZ 0B3A 8176 0B22: BZ 0B3A
8177 0B24: XORLW 01 8177 0B24: XORLW 01
8178 0B26: BZ 0B42 8178 0B26: BZ 0B42
8179 0B28: XORLW 21 8179 0B28: XORLW 21
8180 0B2A: BZ 0B64 8180 0B2A: BZ 0B64
8181 0B2C: XORLW 01 8181 0B2C: XORLW 01
8182 0B2E: BZ 0B6E 8182 0B2E: BZ 0B6E
8183 0B30: XORLW 03 8183 0B30: XORLW 03
8184 0B32: BZ 0B94 8184 0B32: BZ 0B94
8185 0B34: XORLW 01 8185 0B34: XORLW 01
8186 0B36: BZ 0BA2 8186 0B36: BZ 0BA2
8187 0B38: BRA 0BB4 8187 0B38: BRA 0BB4
8188 .................... case 0x00: //send_encapsulated_command 8188 .................... case 0x00: //send_encapsulated_command
8189 .................... __usb_cdc_state=USB_CDC_OUT_COMMAND; 8189 .................... __usb_cdc_state=USB_CDC_OUT_COMMAND;
8190 0B3A: MOVLW 01 8190 0B3A: MOVLW 01
8191 0B3C: MOVWF x83 8191 0B3C: MOVWF x83
8192 .................... usb_request_get_data(); 8192 .................... usb_request_get_data();
8193 0B3E: RCALL 0B0C 8193 0B3E: RCALL 0B0C
8194 .................... break; 8194 .................... break;
8195 0B40: BRA 0BB8 8195 0B40: BRA 0BB8
8196 .................... 8196 ....................
8197 .................... case 0x01: //get_encapsulated_command 8197 .................... case 0x01: //get_encapsulated_command
8198 .................... memcpy(usb_ep0_tx_buffer, usb_cdc_encapsulated_cmd, 8); 8198 .................... memcpy(usb_ep0_tx_buffer, usb_cdc_encapsulated_cmd, 8);
8199 0B42: MOVLW 04 8199 0B42: MOVLW 04
8200 0B44: MOVWF FEA 8200 0B44: MOVWF FEA
8201 0B46: MOVLW 58 8201 0B46: MOVLW 58
8202 0B48: MOVWF FE9 8202 0B48: MOVWF FE9
8203 0B4A: CLRF FE2 8203 0B4A: CLRF FE2
8204 0B4C: MOVLW 34 8204 0B4C: MOVLW 34
8205 0B4E: MOVWF FE1 8205 0B4E: MOVWF FE1
8206 0B50: MOVLW 08 8206 0B50: MOVLW 08
8207 0B52: MOVWF 01 8207 0B52: MOVWF 01
8208 0B54: MOVFF FE6,FEE 8208 0B54: MOVFF FE6,FEE
8209 0B58: DECFSZ 01,F 8209 0B58: DECFSZ 01,F
8210 0B5A: BRA 0B54 8210 0B5A: BRA 0B54
8211 .................... usb_request_send_response(usb_ep0_rx_buffer[6]); //send wLength bytes 8211 .................... usb_request_send_response(usb_ep0_rx_buffer[6]); //send wLength bytes
8212 0B5C: MOVFF 41E,700 8212 0B5C: MOVFF 41E,700
8213 0B60: RCALL 03EE 8213 0B60: RCALL 03EE
8214 .................... break; 8214 .................... break;
8215 0B62: BRA 0BB8 8215 0B62: BRA 0BB8
8216 .................... 8216 ....................
8217 .................... case 0x20: //set_line_coding 8217 .................... case 0x20: //set_line_coding
8218 .................... debug_usb(debug_putc,"!GSLC!"); 8218 .................... debug_usb(debug_putc,"!GSLC!");
8219 .................... __usb_cdc_state=USB_CDC_OUT_LINECODING; 8219 .................... __usb_cdc_state=USB_CDC_OUT_LINECODING;
8220 0B64: MOVLW 02 8220 0B64: MOVLW 02
8221 0B66: MOVWF x83 8221 0B66: MOVWF x83
8222 .................... usb_cdc_got_set_line_coding=TRUE; 8222 .................... usb_cdc_got_set_line_coding=TRUE;
8223 0B68: BSF x80.0 8223 0B68: BSF x80.0
8224 .................... usb_request_get_data(); 8224 .................... usb_request_get_data();
8225 0B6A: RCALL 0B0C 8225 0B6A: RCALL 0B0C
8226 .................... break; 8226 .................... break;
8227 0B6C: BRA 0BB8 8227 0B6C: BRA 0BB8
8228 .................... 8228 ....................
8229 .................... case 0x21: //get_line_coding 8229 .................... case 0x21: //get_line_coding
8230 .................... memcpy(usb_ep0_tx_buffer, &usb_cdc_line_coding, sizeof(usb_cdc_line_coding)); 8230 .................... memcpy(usb_ep0_tx_buffer, &usb_cdc_line_coding, sizeof(usb_cdc_line_coding));
8231 0B6E: MOVLW 04 8231 0B6E: MOVLW 04
8232 0B70: MOVWF FEA 8232 0B70: MOVWF FEA
8233 0B72: MOVLW 58 8233 0B72: MOVLW 58
8234 0B74: MOVWF FE9 8234 0B74: MOVWF FE9
8235 0B76: CLRF FE2 8235 0B76: CLRF FE2
8236 0B78: MOVLW 2B 8236 0B78: MOVLW 2B
8237 0B7A: MOVWF FE1 8237 0B7A: MOVWF FE1
8238 0B7C: MOVLW 07 8238 0B7C: MOVLW 07
8239 0B7E: MOVWF 01 8239 0B7E: MOVWF 01
8240 0B80: MOVFF FE6,FEE 8240 0B80: MOVFF FE6,FEE
8241 0B84: DECFSZ 01,F 8241 0B84: DECFSZ 01,F
8242 0B86: BRA 0B80 8242 0B86: BRA 0B80
8243 .................... usb_request_send_response(sizeof(usb_cdc_line_coding)); //send wLength bytes 8243 .................... usb_request_send_response(sizeof(usb_cdc_line_coding)); //send wLength bytes
8244 0B88: MOVLW 07 8244 0B88: MOVLW 07
8245 0B8A: MOVLB 7 8245 0B8A: MOVLB 7
8246 0B8C: MOVWF x00 8246 0B8C: MOVWF x00
8247 0B8E: MOVLB 0 8247 0B8E: MOVLB 0
8248 0B90: RCALL 03EE 8248 0B90: RCALL 03EE
8249 .................... break; 8249 .................... break;
8250 0B92: BRA 0BB8 8250 0B92: BRA 0BB8
8251 .................... 8251 ....................
8252 .................... case 0x22: //set_control_line_state 8252 .................... case 0x22: //set_control_line_state
8253 .................... usb_cdc_carrier=usb_ep0_rx_buffer[2]; 8253 .................... usb_cdc_carrier=usb_ep0_rx_buffer[2];
8254 0B94: MOVFF 41A,81 8254 0B94: MOVFF 41A,81
8255 .................... usb_put_0len_0(); 8255 .................... usb_put_0len_0();
8256 0B98: MOVLB 7 8256 0B98: MOVLB 7
8257 0B9A: CLRF x00 8257 0B9A: CLRF x00
8258 0B9C: MOVLB 0 8258 0B9C: MOVLB 0
8259 0B9E: RCALL 03EE 8259 0B9E: RCALL 03EE
8260 .................... break; 8260 .................... break;
8261 0BA0: BRA 0BB8 8261 0BA0: BRA 0BB8
8262 .................... 8262 ....................
8263 .................... case 0x23: //send_break 8263 .................... case 0x23: //send_break
8264 .................... usb_cdc_break=make16(usb_ep0_rx_buffer[2],usb_ep0_rx_buffer[3]); 8264 .................... usb_cdc_break=make16(usb_ep0_rx_buffer[2],usb_ep0_rx_buffer[3]);
8265 0BA2: MOVFF 41A,33 8265 0BA2: MOVFF 41A,33
8266 0BA6: MOVFF 41B,32 8266 0BA6: MOVFF 41B,32
8267 .................... usb_put_0len_0(); 8267 .................... usb_put_0len_0();
8268 0BAA: MOVLB 7 8268 0BAA: MOVLB 7
8269 0BAC: CLRF x00 8269 0BAC: CLRF x00
8270 0BAE: MOVLB 0 8270 0BAE: MOVLB 0
8271 0BB0: RCALL 03EE 8271 0BB0: RCALL 03EE
8272 .................... break; 8272 .................... break;
8273 0BB2: BRA 0BB8 8273 0BB2: BRA 0BB8
8274 .................... 8274 ....................
8275 .................... default: 8275 .................... default:
8276 .................... usb_request_stall(); 8276 .................... usb_request_stall();
8277 0BB4: RCALL 03F4 8277 0BB4: RCALL 03F4
8278 .................... break; 8278 .................... break;
8279 0BB6: BRA 0BB8 8279 0BB6: BRA 0BB8
8280 0BB8: MOVLB 4 8280 0BB8: MOVLB 4
8281 .................... } 8281 .................... }
8282 .................... } 8282 .................... }
8283 .................... } 8283 .................... }
8284 0BBA: MOVLB 0 8284 0BBA: MOVLB 0
8285 0BBC: GOTO 0BE6 (RETURN) 8285 0BBC: GOTO 0BE6 (RETURN)
8286 .................... 8286 ....................
8287 .................... //handle OUT token done interrupt on endpoint 3 [buffer incoming received chars] 8287 .................... //handle OUT token done interrupt on endpoint 3 [buffer incoming received chars]
8288 .................... void usb_isr_tok_out_cdc_data_dne(void) { 8288 .................... void usb_isr_tok_out_cdc_data_dne(void) {
8289 .................... usb_cdc_get_buffer_status.got=TRUE; 8289 .................... usb_cdc_get_buffer_status.got=TRUE;
8290 * 8290 *
8291 0F2C: BSF x7D.0 8291 0F2C: BSF x7D.0
8292 .................... usb_cdc_get_buffer_status.index=0; 8292 .................... usb_cdc_get_buffer_status.index=0;
8293 0F2E: CLRF x7F 8293 0F2E: CLRF x7F
8294 .................... #if (defined(__PIC__) && __PIC__) 8294 .................... #if (defined(__PIC__) && __PIC__)
8295 .................... usb_cdc_get_buffer_status.len=usb_rx_packet_size(USB_CDC_DATA_OUT_ENDPOINT); 8295 .................... usb_cdc_get_buffer_status.len=usb_rx_packet_size(USB_CDC_DATA_OUT_ENDPOINT);
8296 0F30: MOVLW 02 8296 0F30: MOVLW 02
8297 0F32: MOVLB 6 8297 0F32: MOVLB 6
8298 0F34: MOVWF xFE 8298 0F34: MOVWF xFE
8299 0F36: MOVLB 0 8299 0F36: MOVLB 0
8300 0F38: BRA 0EE6 8300 0F38: BRA 0EE6
8301 0F3A: MOVFF 01,7E 8301 0F3A: MOVFF 01,7E
8302 .................... #else 8302 .................... #else
8303 .................... usb_cdc_get_buffer_status.len=usb_get_packet_buffer( 8303 .................... usb_cdc_get_buffer_status.len=usb_get_packet_buffer(
8304 .................... USB_CDC_DATA_OUT_ENDPOINT,&usb_cdc_get_buffer_status_buffer[0],USB_CDC_DATA_OUT_SIZE); 8304 .................... USB_CDC_DATA_OUT_ENDPOINT,&usb_cdc_get_buffer_status_buffer[0],USB_CDC_DATA_OUT_SIZE);
8305 .................... #endif 8305 .................... #endif
8306 .................... } 8306 .................... }
8307 0F3E: GOTO 0F5A (RETURN) 8307 0F3E: GOTO 0F5A (RETURN)
8308 .................... 8308 ....................
8309 .................... //handle IN token done interrupt on endpoint 2 [transmit buffered characters] 8309 .................... //handle IN token done interrupt on endpoint 2 [transmit buffered characters]
8310 .................... void usb_isr_tok_in_cdc_data_dne(void) 8310 .................... void usb_isr_tok_in_cdc_data_dne(void)
8311 .................... { 8311 .................... {
8312 .................... //putc('!'); 8312 .................... //putc('!');
8313 .................... if (usb_cdc_put_buffer_nextin /* || (g_LastCDCDataPacketSize == USB_CDC_DATA_IN_SIZE)*/ ) 8313 .................... if (usb_cdc_put_buffer_nextin /* || (g_LastCDCDataPacketSize == USB_CDC_DATA_IN_SIZE)*/ )
8314 * 8314 *
8315 104E: MOVF x7C,F 8315 104E: MOVF x7C,F
8316 1050: BZ 1054 8316 1050: BZ 1054
8317 .................... { 8317 .................... {
8318 .................... //printf("FL3 %LU\r\n", (int16)usb_cdc_put_buffer_nextin); 8318 .................... //printf("FL3 %LU\r\n", (int16)usb_cdc_put_buffer_nextin);
8319 .................... usb_cdc_flush_out_buffer(); 8319 .................... usb_cdc_flush_out_buffer();
8320 1052: RCALL 102C 8320 1052: RCALL 102C
8321 .................... } 8321 .................... }
8322 .................... } 8322 .................... }
8323 1054: GOTO 1084 (RETURN) 8323 1054: GOTO 1084 (RETURN)
8324 .................... 8324 ....................
8325 .................... void usb_cdc_flush_out_buffer(void) 8325 .................... void usb_cdc_flush_out_buffer(void)
8326 .................... { 8326 .................... {
8327 .................... //printf(putc_tbe, "FL %U\r\n", usb_cdc_put_buffer_nextin); 8327 .................... //printf(putc_tbe, "FL %U\r\n", usb_cdc_put_buffer_nextin);
8328 .................... usb_put_packet(USB_CDC_DATA_IN_ENDPOINT,usb_cdc_put_buffer,usb_cdc_put_buffer_nextin,USB_DTS_TOGGLE); 8328 .................... usb_put_packet(USB_CDC_DATA_IN_ENDPOINT,usb_cdc_put_buffer,usb_cdc_put_buffer_nextin,USB_DTS_TOGGLE);
8329 * 8329 *
8330 102C: MOVLW 02 8330 102C: MOVLW 02
8331 102E: MOVLB 7 8331 102E: MOVLB 7
8332 1030: MOVWF x3A 8332 1030: MOVWF x3A
8333 1032: CLRF x3C 8333 1032: CLRF x3C
8334 1034: MOVLW 3C 8334 1034: MOVLW 3C
8335 1036: MOVWF x3B 8335 1036: MOVWF x3B
8336 1038: CLRF x3E 8336 1038: CLRF x3E
8337 103A: MOVFF 7C,73D 8337 103A: MOVFF 7C,73D
8338 103E: MOVLW 02 8338 103E: MOVLW 02
8339 1040: MOVWF x3F 8339 1040: MOVWF x3F
8340 1042: MOVLB 0 8340 1042: MOVLB 0
8341 1044: RCALL 0F88 8341 1044: RCALL 0F88
8342 .................... g_LastCDCDataPacketSize = usb_cdc_put_buffer_nextin; 8342 .................... g_LastCDCDataPacketSize = usb_cdc_put_buffer_nextin;
8343 1046: MOVFF 7C,82 8343 1046: MOVFF 7C,82
8344 .................... usb_cdc_put_buffer_nextin=0; 8344 .................... usb_cdc_put_buffer_nextin=0;
8345 104A: CLRF x7C 8345 104A: CLRF x7C
8346 .................... } 8346 .................... }
8347 104C: RETLW 00 8347 104C: RETLW 00
8348 .................... 8348 ....................
8349 .................... void usb_cdc_init(void) 8349 .................... void usb_cdc_init(void)
8350 .................... { 8350 .................... {
8351 .................... usb_cdc_line_coding.dwDTERrate = 9600; 8351 .................... usb_cdc_line_coding.dwDTERrate = 9600;
8352 * 8352 *
8353 035C: CLRF 2E 8353 035C: CLRF 2E
8354 035E: CLRF 2D 8354 035E: CLRF 2D
8355 0360: MOVLW 25 8355 0360: MOVLW 25
8356 0362: MOVWF 2C 8356 0362: MOVWF 2C
8357 0364: MOVLW 80 8357 0364: MOVLW 80
8358 0366: MOVWF 2B 8358 0366: MOVWF 2B
8359 .................... usb_cdc_line_coding.bCharFormat = 0; 8359 .................... usb_cdc_line_coding.bCharFormat = 0;
8360 0368: CLRF 2F 8360 0368: CLRF 2F
8361 .................... usb_cdc_line_coding.bParityType = 0; 8361 .................... usb_cdc_line_coding.bParityType = 0;
8362 036A: CLRF 30 8362 036A: CLRF 30
8363 .................... usb_cdc_line_coding.bDataBits = 8; 8363 .................... usb_cdc_line_coding.bDataBits = 8;
8364 036C: MOVLW 08 8364 036C: MOVLW 08
8365 036E: MOVWF 31 8365 036E: MOVWF 31
8366 .................... (int8)usb_cdc_carrier = 0; 8366 .................... (int8)usb_cdc_carrier = 0;
8367 0370: CLRF x81 8367 0370: CLRF x81
8368 .................... usb_cdc_got_set_line_coding = FALSE; 8368 .................... usb_cdc_got_set_line_coding = FALSE;
8369 0372: BCF x80.0 8369 0372: BCF x80.0
8370 .................... usb_cdc_break = 0; 8370 .................... usb_cdc_break = 0;
8371 0374: CLRF 33 8371 0374: CLRF 33
8372 0376: CLRF 32 8372 0376: CLRF 32
8373 .................... usb_cdc_put_buffer_nextin = 0; 8373 .................... usb_cdc_put_buffer_nextin = 0;
8374 0378: CLRF x7C 8374 0378: CLRF x7C
8375 .................... usb_cdc_get_buffer_status.got = 0; 8375 .................... usb_cdc_get_buffer_status.got = 0;
8376 037A: BCF x7D.0 8376 037A: BCF x7D.0
8377 .................... } 8377 .................... }
8378 037C: RETLW 00 8378 037C: RETLW 00
8379 .................... 8379 ....................
8380 .................... ////////////////// END USB CONTROL HANDLING ////////////////////////////////// 8380 .................... ////////////////// END USB CONTROL HANDLING //////////////////////////////////
8381 .................... 8381 ....................
8382 .................... ////////////////// BEGIN USB<->RS232 CDC LIBRARY ///////////////////////////// 8382 .................... ////////////////// BEGIN USB<->RS232 CDC LIBRARY /////////////////////////////
8383 .................... 8383 ....................
8384 .................... void usb_cdc_get_discard(void) 8384 .................... void usb_cdc_get_discard(void)
8385 .................... { 8385 .................... {
8386 .................... usb_cdc_get_buffer_status.got = FALSE; 8386 .................... usb_cdc_get_buffer_status.got = FALSE;
8387 .................... usb_flush_out(USB_CDC_DATA_OUT_ENDPOINT, USB_DTS_TOGGLE); 8387 .................... usb_flush_out(USB_CDC_DATA_OUT_ENDPOINT, USB_DTS_TOGGLE);
8388 .................... } 8388 .................... }
8389 .................... 8389 ....................
8390 .................... char usb_cdc_getc(void) 8390 .................... char usb_cdc_getc(void)
8391 .................... { 8391 .................... {
8392 .................... char c; 8392 .................... char c;
8393 .................... 8393 ....................
8394 .................... while (!usb_cdc_kbhit()) {} 8394 .................... while (!usb_cdc_kbhit()) {}
8395 .................... 8395 ....................
8396 .................... c=usb_cdc_get_buffer_status_buffer[usb_cdc_get_buffer_status.index++]; 8396 .................... c=usb_cdc_get_buffer_status_buffer[usb_cdc_get_buffer_status.index++];
8397 .................... 8397 ....................
8398 .................... if (usb_cdc_get_buffer_status.index >= usb_cdc_get_buffer_status.len) 8398 .................... if (usb_cdc_get_buffer_status.index >= usb_cdc_get_buffer_status.len)
8399 .................... { 8399 .................... {
8400 .................... usb_cdc_get_discard(); 8400 .................... usb_cdc_get_discard();
8401 .................... } 8401 .................... }
8402 .................... 8402 ....................
8403 .................... return(c); 8403 .................... return(c);
8404 .................... } 8404 .................... }
8405 .................... 8405 ....................
8406 .................... void usb_cdc_putc_fast(char c) 8406 .................... void usb_cdc_putc_fast(char c)
8407 .................... { 8407 .................... {
8408 .................... #if defined(__PCH__) 8408 .................... #if defined(__PCH__)
8409 .................... int1 old_gie; 8409 .................... int1 old_gie;
8410 .................... 8410 ....................
8411 .................... //disable global interrupts 8411 .................... //disable global interrupts
8412 .................... old_gie = INT_GIE; 8412 .................... old_gie = INT_GIE;
8413 * 8413 *
8414 1376: MOVLB 6 8414 1376: MOVLB 6
8415 1378: BCF xDD.0 8415 1378: BCF xDD.0
8416 137A: BTFSC FF2.7 8416 137A: BTFSC FF2.7
8417 137C: BSF xDD.0 8417 137C: BSF xDD.0
8418 .................... INT_GIE = 0; 8418 .................... INT_GIE = 0;
8419 137E: BCF FF2.7 8419 137E: BCF FF2.7
8420 .................... #else 8420 .................... #else
8421 .................... int16 oldSR; 8421 .................... int16 oldSR;
8422 .................... 8422 ....................
8423 .................... oldSR = SR; 8423 .................... oldSR = SR;
8424 .................... SR |= 0xE0; 8424 .................... SR |= 0xE0;
8425 .................... #endif 8425 .................... #endif
8426 .................... 8426 ....................
8427 .................... if (usb_cdc_put_buffer_nextin >= USB_CDC_DATA_IN_SIZE) { 8427 .................... if (usb_cdc_put_buffer_nextin >= USB_CDC_DATA_IN_SIZE) {
8428 1380: MOVLB 0 8428 1380: MOVLB 0
8429 1382: MOVF x7C,W 8429 1382: MOVF x7C,W
8430 1384: SUBLW 3F 8430 1384: SUBLW 3F
8431 1386: BC 138C 8431 1386: BC 138C
8432 .................... usb_cdc_put_buffer_nextin = USB_CDC_DATA_IN_SIZE-1; //we just overflowed the buffer! 8432 .................... usb_cdc_put_buffer_nextin = USB_CDC_DATA_IN_SIZE-1; //we just overflowed the buffer!
8433 1388: MOVLW 3F 8433 1388: MOVLW 3F
8434 138A: MOVWF x7C 8434 138A: MOVWF x7C
8435 .................... } 8435 .................... }
8436 .................... usb_cdc_put_buffer[usb_cdc_put_buffer_nextin++] = c; 8436 .................... usb_cdc_put_buffer[usb_cdc_put_buffer_nextin++] = c;
8437 138C: MOVF x7C,W 8437 138C: MOVF x7C,W
8438 138E: INCF x7C,F 8438 138E: INCF x7C,F
8439 1390: CLRF 03 8439 1390: CLRF 03
8440 1392: ADDLW 3C 8440 1392: ADDLW 3C
8441 1394: MOVWF FE9 8441 1394: MOVWF FE9
8442 1396: MOVLW 00 8442 1396: MOVLW 00
8443 1398: ADDWFC 03,W 8443 1398: ADDWFC 03,W
8444 139A: MOVWF FEA 8444 139A: MOVWF FEA
8445 139C: MOVFF 6DC,FEF 8445 139C: MOVFF 6DC,FEF
8446 .................... 8446 ....................
8447 .................... //renable global interrupts 8447 .................... //renable global interrupts
8448 .................... #if defined(__PCH__) 8448 .................... #if defined(__PCH__)
8449 .................... INT_GIE = old_gie; 8449 .................... INT_GIE = old_gie;
8450 13A0: BCF FF2.7 8450 13A0: BCF FF2.7
8451 13A2: MOVLB 6 8451 13A2: MOVLB 6
8452 13A4: BTFSC xDD.0 8452 13A4: BTFSC xDD.0
8453 13A6: BSF FF2.7 8453 13A6: BSF FF2.7
8454 13A8: CLRF 18 8454 13A8: CLRF 18
8455 13AA: BTFSC FF2.7 8455 13AA: BTFSC FF2.7
8456 13AC: BSF 18.7 8456 13AC: BSF 18.7
8457 13AE: BCF FF2.7 8457 13AE: BCF FF2.7
8458 .................... #else 8458 .................... #else
8459 .................... SR = oldSR; 8459 .................... SR = oldSR;
8460 .................... #endif 8460 .................... #endif
8461 .................... 8461 ....................
8462 .................... /* 8462 .................... /*
8463 .................... if (usb_tbe(USB_CDC_DATA_IN_ENDPOINT)) { 8463 .................... if (usb_tbe(USB_CDC_DATA_IN_ENDPOINT)) {
8464 .................... if (usb_cdc_put_buffer_nextin) 8464 .................... if (usb_cdc_put_buffer_nextin)
8465 .................... usb_cdc_flush_out_buffer(); 8465 .................... usb_cdc_flush_out_buffer();
8466 .................... } 8466 .................... }
8467 .................... */ 8467 .................... */
8468 .................... if (usb_cdc_put_buffer_free()) { 8468 .................... if (usb_cdc_put_buffer_free()) {
8469 13B0: MOVLW 02 8469 13B0: MOVLW 02
8470 13B2: MOVLB 7 8470 13B2: MOVLB 7
8471 13B4: MOVWF x47 8471 13B4: MOVWF x47
8472 13B6: MOVLB 0 8472 13B6: MOVLB 0
8473 13B8: RCALL 0D06 8473 13B8: RCALL 0D06
8474 13BA: BTFSC 18.7 8474 13BA: BTFSC 18.7
8475 13BC: BSF FF2.7 8475 13BC: BSF FF2.7
8476 13BE: MOVF 01,F 8476 13BE: MOVF 01,F
8477 13C0: BZ 13D0 8477 13C0: BZ 13D0
8478 13C2: CLRF 18 8478 13C2: CLRF 18
8479 13C4: BTFSC FF2.7 8479 13C4: BTFSC FF2.7
8480 13C6: BSF 18.7 8480 13C6: BSF 18.7
8481 13C8: BCF FF2.7 8481 13C8: BCF FF2.7
8482 .................... //printf("FL2 %LU\r\n", (int16)usb_cdc_put_buffer_nextin); 8482 .................... //printf("FL2 %LU\r\n", (int16)usb_cdc_put_buffer_nextin);
8483 .................... usb_cdc_flush_out_buffer(); 8483 .................... usb_cdc_flush_out_buffer();
8484 13CA: RCALL 102C 8484 13CA: RCALL 102C
8485 13CC: BTFSC 18.7 8485 13CC: BTFSC 18.7
8486 13CE: BSF FF2.7 8486 13CE: BSF FF2.7
8487 .................... } 8487 .................... }
8488 .................... //putc('*'); 8488 .................... //putc('*');
8489 .................... } 8489 .................... }
8490 13D0: GOTO 140A (RETURN) 8490 13D0: GOTO 140A (RETURN)
8491 .................... 8491 ....................
8492 .................... void usb_cdc_putc(char c) 8492 .................... void usb_cdc_putc(char c)
8493 .................... { 8493 .................... {
8494 .................... while (!usb_cdc_putready()) 8494 .................... while (!usb_cdc_putready())
8495 .................... { 8495 .................... {
8496 13D4: MOVF x7C,W 8496 13D4: MOVF x7C,W
8497 13D6: SUBLW 3F 8497 13D6: SUBLW 3F
8498 13D8: BC 1404 8498 13D8: BC 1404
8499 13DA: CLRF 18 8499 13DA: CLRF 18
8500 13DC: BTFSC FF2.7 8500 13DC: BTFSC FF2.7
8501 13DE: BSF 18.7 8501 13DE: BSF 18.7
8502 13E0: BCF FF2.7 8502 13E0: BCF FF2.7
8503 .................... if (usb_cdc_put_buffer_free()) 8503 .................... if (usb_cdc_put_buffer_free())
8504 13E2: MOVLW 02 8504 13E2: MOVLW 02
8505 13E4: MOVLB 7 8505 13E4: MOVLB 7
8506 13E6: MOVWF x47 8506 13E6: MOVWF x47
8507 13E8: MOVLB 0 8507 13E8: MOVLB 0
8508 13EA: RCALL 0D06 8508 13EA: RCALL 0D06
8509 13EC: BTFSC 18.7 8509 13EC: BTFSC 18.7
8510 13EE: BSF FF2.7 8510 13EE: BSF FF2.7
8511 13F0: MOVF 01,F 8511 13F0: MOVF 01,F
8512 13F2: BZ 1402 8512 13F2: BZ 1402
8513 13F4: CLRF 18 8513 13F4: CLRF 18
8514 13F6: BTFSC FF2.7 8514 13F6: BTFSC FF2.7
8515 13F8: BSF 18.7 8515 13F8: BSF 18.7
8516 13FA: BCF FF2.7 8516 13FA: BCF FF2.7
8517 .................... { 8517 .................... {
8518 .................... //printf("FL1 %LU\r\n", (int16)usb_cdc_put_buffer_nextin); 8518 .................... //printf("FL1 %LU\r\n", (int16)usb_cdc_put_buffer_nextin);
8519 .................... usb_cdc_flush_out_buffer(); 8519 .................... usb_cdc_flush_out_buffer();
8520 13FC: RCALL 102C 8520 13FC: RCALL 102C
8521 13FE: BTFSC 18.7 8521 13FE: BTFSC 18.7
8522 1400: BSF FF2.7 8522 1400: BSF FF2.7
8523 .................... } 8523 .................... }
8524 .................... //delay_ms(500); 8524 .................... //delay_ms(500);
8525 .................... //printf(putc_tbe,"TBE=%U CNT=%U LST=%U\r\n",usb_tbe(USB_CDC_DATA_IN_ENDPOINT), usb_cdc_put_buffer_nextin, usb_cdc_last_data_packet_size); 8525 .................... //printf(putc_tbe,"TBE=%U CNT=%U LST=%U\r\n",usb_tbe(USB_CDC_DATA_IN_ENDPOINT), usb_cdc_put_buffer_nextin, usb_cdc_last_data_packet_size);
8526 .................... } 8526 .................... }
8527 1402: BRA 13D4 8527 1402: BRA 13D4
8528 .................... //putc('.'); 8528 .................... //putc('.');
8529 .................... //putc(c); 8529 .................... //putc(c);
8530 .................... usb_cdc_putc_fast(c); 8530 .................... usb_cdc_putc_fast(c);
8531 1404: MOVFF 6DB,6DC 8531 1404: MOVFF 6DB,6DC
8532 1408: BRA 1376 8532 1408: BRA 1376
8533 .................... } 8533 .................... }
8534 140A: RETLW 00 8534 140A: RETLW 00
8535 .................... 8535 ....................
8536 .................... #include <ctype.h> 8536 .................... #include <ctype.h>
8537 .................... //////////////////////////////////////////////////////////////////////////// 8537 .................... ////////////////////////////////////////////////////////////////////////////
8538 .................... //// (C) Copyright 1996,2003 Custom Computer Services //// 8538 .................... //// (C) Copyright 1996,2003 Custom Computer Services ////
8539 .................... //// This source code may only be used by licensed users of the CCS C //// 8539 .................... //// This source code may only be used by licensed users of the CCS C ////
8540 .................... //// compiler. This source code may only be distributed to other //// 8540 .................... //// compiler. This source code may only be distributed to other ////
8541 .................... //// licensed users of the CCS C compiler. No other use, reproduction //// 8541 .................... //// licensed users of the CCS C compiler. No other use, reproduction ////
8542 .................... //// or distribution is permitted without written permission. //// 8542 .................... //// or distribution is permitted without written permission. ////
8543 .................... //// Derivative programs created using this software in object code //// 8543 .................... //// Derivative programs created using this software in object code ////
8544 .................... //// form are not restricted in any way. //// 8544 .................... //// form are not restricted in any way. ////
8545 .................... //////////////////////////////////////////////////////////////////////////// 8545 .................... ////////////////////////////////////////////////////////////////////////////
8546 .................... 8546 ....................
8547 .................... #ifndef _CTYPE 8547 .................... #ifndef _CTYPE
8548 .................... #define _CTYPE 8548 .................... #define _CTYPE
8549 .................... 8549 ....................
8550 .................... #define islower(x) isamong(x,"abcdefghijklmnopqrstuvwxyz") 8550 .................... #define islower(x) isamong(x,"abcdefghijklmnopqrstuvwxyz")
8551 .................... #define isupper(x) isamong(x,"ABCDEFGHIJKLMNOPQRSTUVWXYZ") 8551 .................... #define isupper(x) isamong(x,"ABCDEFGHIJKLMNOPQRSTUVWXYZ")
8552 .................... #define isalnum(x) isamong(x,"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz") 8552 .................... #define isalnum(x) isamong(x,"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")
8553 .................... #define isalpha(x) isamong(x,"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz") 8553 .................... #define isalpha(x) isamong(x,"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")
8554 .................... #define isdigit(x) isamong(x,"0123456789") 8554 .................... #define isdigit(x) isamong(x,"0123456789")
8555 .................... #define isspace(x) ((x)==' ') 8555 .................... #define isspace(x) ((x)==' ')
8556 .................... #define isxdigit(x) isamong(x,"0123456789ABCDEFabcdef") 8556 .................... #define isxdigit(x) isamong(x,"0123456789ABCDEFabcdef")
8557 .................... #define iscntrl(x) ((x)<' ') 8557 .................... #define iscntrl(x) ((x)<' ')
8558 .................... #define isprint(x) ((x)>=' ') 8558 .................... #define isprint(x) ((x)>=' ')
8559 .................... #define isgraph(x) ((x)>' ') 8559 .................... #define isgraph(x) ((x)>' ')
8560 .................... #define ispunct(x) (((x)>' ')&&!isalnum(x)) 8560 .................... #define ispunct(x) (((x)>' ')&&!isalnum(x))
8561 .................... 8561 ....................
8562 .................... #endif 8562 .................... #endif
8563 .................... 8563 ....................
8564 .................... 8564 ....................
8565 .................... 8565 ....................
8566 .................... BYTE gethex1_usb() 8566 .................... BYTE gethex1_usb()
8567 .................... { 8567 .................... {
8568 .................... char digit; 8568 .................... char digit;
8569 .................... 8569 ....................
8570 .................... digit = usb_cdc_getc(); 8570 .................... digit = usb_cdc_getc();
8571 .................... 8571 ....................
8572 .................... usb_cdc_putc(digit); 8572 .................... usb_cdc_putc(digit);
8573 .................... 8573 ....................
8574 .................... if(digit<='9') 8574 .................... if(digit<='9')
8575 .................... return(digit-'0'); 8575 .................... return(digit-'0');
8576 .................... else 8576 .................... else
8577 .................... return((toupper(digit)-'A')+10); 8577 .................... return((toupper(digit)-'A')+10);
8578 .................... } 8578 .................... }
8579 .................... 8579 ....................
8580 .................... BYTE gethex_usb() { 8580 .................... BYTE gethex_usb() {
8581 .................... unsigned int8 lo,hi; 8581 .................... unsigned int8 lo,hi;
8582 .................... 8582 ....................
8583 .................... hi = gethex1_usb(); 8583 .................... hi = gethex1_usb();
8584 .................... lo = gethex1_usb(); 8584 .................... lo = gethex1_usb();
8585 .................... if(lo==0xdd) 8585 .................... if(lo==0xdd)
8586 .................... return(hi); 8586 .................... return(hi);
8587 .................... else 8587 .................... else
8588 .................... return( hi*16+lo ); 8588 .................... return( hi*16+lo );
8589 .................... } 8589 .................... }
8590 .................... 8590 ....................
8591 .................... void get_string_usb(char* s, unsigned int max) { 8591 .................... void get_string_usb(char* s, unsigned int max) {
8592 .................... unsigned int len; 8592 .................... unsigned int len;
8593 .................... char c; 8593 .................... char c;
8594 .................... 8594 ....................
8595 .................... --max; 8595 .................... --max;
8596 .................... len=0; 8596 .................... len=0;
8597 .................... do { 8597 .................... do {
8598 .................... c=usb_cdc_getc(); 8598 .................... c=usb_cdc_getc();
8599 .................... if(c==8) { // Backspace 8599 .................... if(c==8) { // Backspace
8600 .................... if(len>0) { 8600 .................... if(len>0) {
8601 .................... len--; 8601 .................... len--;
8602 .................... usb_cdc_putc(c); 8602 .................... usb_cdc_putc(c);
8603 .................... usb_cdc_putc(' '); 8603 .................... usb_cdc_putc(' ');
8604 .................... usb_cdc_putc(c); 8604 .................... usb_cdc_putc(c);
8605 .................... } 8605 .................... }
8606 .................... } else if ((c>=' ')&&(c<='~')) 8606 .................... } else if ((c>=' ')&&(c<='~'))
8607 .................... if(len<max) { 8607 .................... if(len<max) {
8608 .................... s[len++]=c; 8608 .................... s[len++]=c;
8609 .................... usb_cdc_putc(c); 8609 .................... usb_cdc_putc(c);
8610 .................... } 8610 .................... }
8611 .................... } while(c!=13); 8611 .................... } while(c!=13);
8612 .................... s[len]=0; 8612 .................... s[len]=0;
8613 .................... } 8613 .................... }
8614 .................... 8614 ....................
8615 .................... 8615 ....................
8616 .................... // stdlib.h is required for the ato_ conversions 8616 .................... // stdlib.h is required for the ato_ conversions
8617 .................... // in the following functions 8617 .................... // in the following functions
8618 .................... #ifdef _STDLIB 8618 .................... #ifdef _STDLIB
8619 .................... 8619 ....................
8620 .................... signed int get_int_usb() { 8620 .................... signed int get_int_usb() {
8621 .................... char s[7]; 8621 .................... char s[7];
8622 .................... signed int i; 8622 .................... signed int i;
8623 .................... 8623 ....................
8624 .................... get_string_usb(s, 7); 8624 .................... get_string_usb(s, 7);
8625 .................... 8625 ....................
8626 .................... i=atoi(s); 8626 .................... i=atoi(s);
8627 .................... return(i); 8627 .................... return(i);
8628 .................... } 8628 .................... }
8629 .................... 8629 ....................
8630 .................... signed long get_long_usb() { 8630 .................... signed long get_long_usb() {
8631 .................... char s[13]; 8631 .................... char s[13];
8632 .................... signed long l; 8632 .................... signed long l;
8633 .................... 8633 ....................
8634 .................... get_string_usb(s, 13); 8634 .................... get_string_usb(s, 13);
8635 .................... l=atol(s); 8635 .................... l=atol(s);
8636 .................... return(l); 8636 .................... return(l);
8637 .................... } 8637 .................... }
8638 .................... 8638 ....................
8639 .................... float get_float_usb() { 8639 .................... float get_float_usb() {
8640 .................... char s[20]; 8640 .................... char s[20];
8641 .................... float f; 8641 .................... float f;
8642 .................... 8642 ....................
8643 .................... get_string_usb(s, 20); 8643 .................... get_string_usb(s, 20);
8644 .................... f = atof(s); 8644 .................... f = atof(s);
8645 .................... return(f); 8645 .................... return(f);
8646 .................... } 8646 .................... }
8647 .................... 8647 ....................
8648 .................... #endif 8648 .................... #endif
8649 .................... 8649 ....................
8650 .................... #include <math.h> 8650 .................... #include <math.h>
8651 .................... //////////////////////////////////////////////////////////////////////////// 8651 .................... ////////////////////////////////////////////////////////////////////////////
8652 .................... //// (C) Copyright 1996,2008 Custom Computer Services //// 8652 .................... //// (C) Copyright 1996,2008 Custom Computer Services ////
8653 .................... //// This source code may only be used by licensed users of the CCS C //// 8653 .................... //// This source code may only be used by licensed users of the CCS C ////
8654 .................... //// compiler. This source code may only be distributed to other //// 8654 .................... //// compiler. This source code may only be distributed to other ////
8655 .................... //// licensed users of the CCS C compiler. No other use, reproduction //// 8655 .................... //// licensed users of the CCS C compiler. No other use, reproduction ////
8656 .................... //// or distribution is permitted without written permission. //// 8656 .................... //// or distribution is permitted without written permission. ////
8657 .................... //// Derivative programs created using this software in object code //// 8657 .................... //// Derivative programs created using this software in object code ////
8658 .................... //// form are not restricted in any way. //// 8658 .................... //// form are not restricted in any way. ////
8659 .................... //////////////////////////////////////////////////////////////////////////// 8659 .................... ////////////////////////////////////////////////////////////////////////////
8660 .................... //// //// 8660 .................... //// ////
8661 .................... //// History: //// 8661 .................... //// History: ////
8662 .................... //// * 9/20/2001 : Improvments are made to sin/cos code. //// 8662 .................... //// * 9/20/2001 : Improvments are made to sin/cos code. ////
8663 .................... //// The code now is small, much faster, //// 8663 .................... //// The code now is small, much faster, ////
8664 .................... //// and more accurate. //// 8664 .................... //// and more accurate. ////
8665 .................... //// * 2/21/2007 : Compiler handles & operator differently and does 8665 .................... //// * 2/21/2007 : Compiler handles & operator differently and does
8666 .................... //// not return generic (int8 *) so type cast is done //// 8666 .................... //// not return generic (int8 *) so type cast is done ////
8667 .................... //// //// 8667 .................... //// ////
8668 .................... //////////////////////////////////////////////////////////////////////////// 8668 .................... ////////////////////////////////////////////////////////////////////////////
8669 .................... 8669 ....................
8670 .................... #ifndef MATH_H 8670 .................... #ifndef MATH_H
8671 .................... #define MATH_H 8671 .................... #define MATH_H
8672 .................... 8672 ....................
8673 .................... #ifdef PI 8673 .................... #ifdef PI
8674 .................... #undef PI 8674 .................... #undef PI
8675 .................... #endif 8675 .................... #endif
8676 .................... #define PI 3.1415926535897932 8676 .................... #define PI 3.1415926535897932
8677 .................... 8677 ....................
8678 .................... 8678 ....................
8679 .................... #define SQRT2 1.4142135623730950 8679 .................... #define SQRT2 1.4142135623730950
8680 .................... 8680 ....................
8681 .................... //float const ps[4] = {5.9304945, 21.125224, 8.9403076, 0.29730279}; 8681 .................... //float const ps[4] = {5.9304945, 21.125224, 8.9403076, 0.29730279};
8682 .................... //float const qs[4] = {1.0000000, 15.035723, 17.764134, 2.4934718}; 8682 .................... //float const qs[4] = {1.0000000, 15.035723, 17.764134, 2.4934718};
8683 .................... 8683 ....................
8684 .................... ///////////////////////////// Round Functions ////////////////////////////// 8684 .................... ///////////////////////////// Round Functions //////////////////////////////
8685 .................... 8685 ....................
8686 .................... float32 CEIL_FLOOR(float32 x, unsigned int8 n) 8686 .................... float32 CEIL_FLOOR(float32 x, unsigned int8 n)
8687 .................... { 8687 .................... {
8688 .................... float32 y, res; 8688 .................... float32 y, res;
8689 .................... unsigned int16 l; 8689 .................... unsigned int16 l;
8690 .................... int1 s; 8690 .................... int1 s;
8691 .................... 8691 ....................
8692 .................... s = 0; 8692 .................... s = 0;
8693 .................... y = x; 8693 .................... y = x;
8694 .................... 8694 ....................
8695 .................... if (x < 0) 8695 .................... if (x < 0)
8696 .................... { 8696 .................... {
8697 .................... s = 1; 8697 .................... s = 1;
8698 .................... y = -y; 8698 .................... y = -y;
8699 .................... } 8699 .................... }
8700 .................... 8700 ....................
8701 .................... if (y <= 32768.0) 8701 .................... if (y <= 32768.0)
8702 .................... res = (float32)(unsigned int16)y; 8702 .................... res = (float32)(unsigned int16)y;
8703 .................... 8703 ....................
8704 .................... else if (y < 10000000.0) 8704 .................... else if (y < 10000000.0)
8705 .................... { 8705 .................... {
8706 .................... l = (unsigned int16)(y/32768.0); 8706 .................... l = (unsigned int16)(y/32768.0);
8707 .................... y = 32768.0*(y/32768.0 - (float32)l); 8707 .................... y = 32768.0*(y/32768.0 - (float32)l);
8708 .................... res = 32768.0*(float32)l; 8708 .................... res = 32768.0*(float32)l;
8709 .................... res += (float32)(unsigned int16)y; 8709 .................... res += (float32)(unsigned int16)y;
8710 .................... } 8710 .................... }
8711 .................... 8711 ....................
8712 .................... else 8712 .................... else
8713 .................... res = y; 8713 .................... res = y;
8714 .................... 8714 ....................
8715 .................... y = y - (float32)(unsigned int16)y; 8715 .................... y = y - (float32)(unsigned int16)y;
8716 .................... 8716 ....................
8717 .................... if (s) 8717 .................... if (s)
8718 .................... res = -res; 8718 .................... res = -res;
8719 .................... 8719 ....................
8720 .................... if (y != 0) 8720 .................... if (y != 0)
8721 .................... { 8721 .................... {
8722 .................... if (s == 1 && n == 0) 8722 .................... if (s == 1 && n == 0)
8723 .................... res -= 1.0; 8723 .................... res -= 1.0;
8724 .................... 8724 ....................
8725 .................... if (s == 0 && n == 1) 8725 .................... if (s == 0 && n == 1)
8726 .................... res += 1.0; 8726 .................... res += 1.0;
8727 .................... } 8727 .................... }
8728 .................... if (x == 0) 8728 .................... if (x == 0)
8729 .................... res = 0; 8729 .................... res = 0;
8730 .................... 8730 ....................
8731 .................... return (res); 8731 .................... return (res);
8732 .................... } 8732 .................... }
8733 .................... 8733 ....................
8734 .................... // Overloaded Functions to take care for new Data types in PCD 8734 .................... // Overloaded Functions to take care for new Data types in PCD
8735 .................... // Overloaded function CEIL_FLOOR() for data type - Float48 8735 .................... // Overloaded function CEIL_FLOOR() for data type - Float48
8736 .................... #if defined(__PCD__) 8736 .................... #if defined(__PCD__)
8737 .................... float48 CEIL_FLOOR(float48 x, unsigned int8 n) 8737 .................... float48 CEIL_FLOOR(float48 x, unsigned int8 n)
8738 .................... { 8738 .................... {
8739 .................... float48 y, res; 8739 .................... float48 y, res;
8740 .................... unsigned int16 l; 8740 .................... unsigned int16 l;
8741 .................... int1 s; 8741 .................... int1 s;
8742 .................... 8742 ....................
8743 .................... s = 0; 8743 .................... s = 0;
8744 .................... y = x; 8744 .................... y = x;
8745 .................... 8745 ....................
8746 .................... if (x < 0) 8746 .................... if (x < 0)
8747 .................... { 8747 .................... {
8748 .................... s = 1; 8748 .................... s = 1;
8749 .................... y = -y; 8749 .................... y = -y;
8750 .................... } 8750 .................... }
8751 .................... 8751 ....................
8752 .................... if (y <= 32768.0) 8752 .................... if (y <= 32768.0)
8753 .................... res = (float48)(unsigned int16)y; 8753 .................... res = (float48)(unsigned int16)y;
8754 .................... 8754 ....................
8755 .................... else if (y < 10000000.0) 8755 .................... else if (y < 10000000.0)
8756 .................... { 8756 .................... {
8757 .................... l = (unsigned int16)(y/32768.0); 8757 .................... l = (unsigned int16)(y/32768.0);
8758 .................... y = 32768.0*(y/32768.0 - (float48)l); 8758 .................... y = 32768.0*(y/32768.0 - (float48)l);
8759 .................... res = 32768.0*(float32)l; 8759 .................... res = 32768.0*(float32)l;
8760 .................... res += (float48)(unsigned int16)y; 8760 .................... res += (float48)(unsigned int16)y;
8761 .................... } 8761 .................... }
8762 .................... 8762 ....................
8763 .................... else 8763 .................... else
8764 .................... res = y; 8764 .................... res = y;
8765 .................... 8765 ....................
8766 .................... y = y - (float48)(unsigned int16)y; 8766 .................... y = y - (float48)(unsigned int16)y;
8767 .................... 8767 ....................
8768 .................... if (s) 8768 .................... if (s)
8769 .................... res = -res; 8769 .................... res = -res;
8770 .................... 8770 ....................
8771 .................... if (y != 0) 8771 .................... if (y != 0)
8772 .................... { 8772 .................... {
8773 .................... if (s == 1 && n == 0) 8773 .................... if (s == 1 && n == 0)
8774 .................... res -= 1.0; 8774 .................... res -= 1.0;
8775 .................... 8775 ....................
8776 .................... if (s == 0 && n == 1) 8776 .................... if (s == 0 && n == 1)
8777 .................... res += 1.0; 8777 .................... res += 1.0;
8778 .................... } 8778 .................... }
8779 .................... if (x == 0) 8779 .................... if (x == 0)
8780 .................... res = 0; 8780 .................... res = 0;
8781 .................... 8781 ....................
8782 .................... return (res); 8782 .................... return (res);
8783 .................... } 8783 .................... }
8784 .................... 8784 ....................
8785 .................... 8785 ....................
8786 .................... // Overloaded function CEIL_FLOOR() for data type - Float64 8786 .................... // Overloaded function CEIL_FLOOR() for data type - Float64
8787 .................... float64 CEIL_FLOOR(float64 x, unsigned int8 n) 8787 .................... float64 CEIL_FLOOR(float64 x, unsigned int8 n)
8788 .................... { 8788 .................... {
8789 .................... float64 y, res; 8789 .................... float64 y, res;
8790 .................... unsigned int16 l; 8790 .................... unsigned int16 l;
8791 .................... int1 s; 8791 .................... int1 s;
8792 .................... 8792 ....................
8793 .................... s = 0; 8793 .................... s = 0;
8794 .................... y = x; 8794 .................... y = x;
8795 .................... 8795 ....................
8796 .................... if (x < 0) 8796 .................... if (x < 0)
8797 .................... { 8797 .................... {
8798 .................... s = 1; 8798 .................... s = 1;
8799 .................... y = -y; 8799 .................... y = -y;
8800 .................... } 8800 .................... }
8801 .................... 8801 ....................
8802 .................... if (y <= 32768.0) 8802 .................... if (y <= 32768.0)
8803 .................... res = (float64)(unsigned int16)y; 8803 .................... res = (float64)(unsigned int16)y;
8804 .................... 8804 ....................
8805 .................... else if (y < 10000000.0) 8805 .................... else if (y < 10000000.0)
8806 .................... { 8806 .................... {
8807 .................... l = (unsigned int16)(y/32768.0); 8807 .................... l = (unsigned int16)(y/32768.0);
8808 .................... y = 32768.0*(y/32768.0 - (float64)l); 8808 .................... y = 32768.0*(y/32768.0 - (float64)l);
8809 .................... res = 32768.0*(float64)l; 8809 .................... res = 32768.0*(float64)l;
8810 .................... res += (float64)(unsigned int16)y; 8810 .................... res += (float64)(unsigned int16)y;
8811 .................... } 8811 .................... }
8812 .................... 8812 ....................
8813 .................... else 8813 .................... else
8814 .................... res = y; 8814 .................... res = y;
8815 .................... 8815 ....................
8816 .................... y = y - (float64)(unsigned int16)y; 8816 .................... y = y - (float64)(unsigned int16)y;
8817 .................... 8817 ....................
8818 .................... if (s) 8818 .................... if (s)
8819 .................... res = -res; 8819 .................... res = -res;
8820 .................... 8820 ....................
8821 .................... if (y != 0) 8821 .................... if (y != 0)
8822 .................... { 8822 .................... {
8823 .................... if (s == 1 && n == 0) 8823 .................... if (s == 1 && n == 0)
8824 .................... res -= 1.0; 8824 .................... res -= 1.0;
8825 .................... 8825 ....................
8826 .................... if (s == 0 && n == 1) 8826 .................... if (s == 0 && n == 1)
8827 .................... res += 1.0; 8827 .................... res += 1.0;
8828 .................... } 8828 .................... }
8829 .................... if (x == 0) 8829 .................... if (x == 0)
8830 .................... res = 0; 8830 .................... res = 0;
8831 .................... 8831 ....................
8832 .................... return (res); 8832 .................... return (res);
8833 .................... } 8833 .................... }
8834 .................... #endif 8834 .................... #endif
8835 .................... 8835 ....................
8836 .................... //////////////////////////////////////////////////////////////////////////// 8836 .................... ////////////////////////////////////////////////////////////////////////////
8837 .................... // float floor(float x) 8837 .................... // float floor(float x)
8838 .................... //////////////////////////////////////////////////////////////////////////// 8838 .................... ////////////////////////////////////////////////////////////////////////////
8839 .................... // Description : rounds down the number x. 8839 .................... // Description : rounds down the number x.
8840 .................... // Date : N/A 8840 .................... // Date : N/A
8841 .................... // 8841 .................... //
8842 .................... float32 floor(float32 x) 8842 .................... float32 floor(float32 x)
8843 .................... { 8843 .................... {
8844 .................... return CEIL_FLOOR(x, 0); 8844 .................... return CEIL_FLOOR(x, 0);
8845 .................... } 8845 .................... }
8846 .................... // Following 2 functions are overloaded functions of floor() for PCD 8846 .................... // Following 2 functions are overloaded functions of floor() for PCD
8847 .................... // Overloaded function floor() for data type - Float48 8847 .................... // Overloaded function floor() for data type - Float48
8848 .................... #if defined(__PCD__) 8848 .................... #if defined(__PCD__)
8849 .................... float48 floor(float48 x) 8849 .................... float48 floor(float48 x)
8850 .................... { 8850 .................... {
8851 .................... return CEIL_FLOOR(x, 0); 8851 .................... return CEIL_FLOOR(x, 0);
8852 .................... } 8852 .................... }
8853 .................... 8853 ....................
8854 .................... // Overloaded function floor() for data type - Float64 8854 .................... // Overloaded function floor() for data type - Float64
8855 .................... float64 floor(float64 x) 8855 .................... float64 floor(float64 x)
8856 .................... { 8856 .................... {
8857 .................... return CEIL_FLOOR(x, 0); 8857 .................... return CEIL_FLOOR(x, 0);
8858 .................... } 8858 .................... }
8859 .................... #endif 8859 .................... #endif
8860 .................... 8860 ....................
8861 .................... 8861 ....................
8862 .................... //////////////////////////////////////////////////////////////////////////// 8862 .................... ////////////////////////////////////////////////////////////////////////////
8863 .................... // float ceil(float x) 8863 .................... // float ceil(float x)
8864 .................... //////////////////////////////////////////////////////////////////////////// 8864 .................... ////////////////////////////////////////////////////////////////////////////
8865 .................... // Description : rounds up the number x. 8865 .................... // Description : rounds up the number x.
8866 .................... // Date : N/A 8866 .................... // Date : N/A
8867 .................... // 8867 .................... //
8868 .................... float32 ceil(float32 x) 8868 .................... float32 ceil(float32 x)
8869 .................... { 8869 .................... {
8870 .................... return CEIL_FLOOR(x, 1); 8870 .................... return CEIL_FLOOR(x, 1);
8871 .................... } 8871 .................... }
8872 .................... // Following 2 functions are overloaded functions of ceil() for PCD 8872 .................... // Following 2 functions are overloaded functions of ceil() for PCD
8873 .................... // Overloaded function ceil() for data type - Float48 8873 .................... // Overloaded function ceil() for data type - Float48
8874 .................... #if defined(__PCD__) 8874 .................... #if defined(__PCD__)
8875 .................... float48 ceil(float48 x) 8875 .................... float48 ceil(float48 x)
8876 .................... { 8876 .................... {
8877 .................... return CEIL_FLOOR(x, 1); 8877 .................... return CEIL_FLOOR(x, 1);
8878 .................... } 8878 .................... }
8879 .................... 8879 ....................
8880 .................... // Overloaded function ceil() for data type - Float64 8880 .................... // Overloaded function ceil() for data type - Float64
8881 .................... float64 ceil(float64 x) 8881 .................... float64 ceil(float64 x)
8882 .................... { 8882 .................... {
8883 .................... return CEIL_FLOOR(x, 1); 8883 .................... return CEIL_FLOOR(x, 1);
8884 .................... } 8884 .................... }
8885 .................... #endif 8885 .................... #endif
8886 .................... 8886 ....................
8887 .................... //////////////////////////////////////////////////////////////////////////// 8887 .................... ////////////////////////////////////////////////////////////////////////////
8888 .................... // float fabs(float x) 8888 .................... // float fabs(float x)
8889 .................... //////////////////////////////////////////////////////////////////////////// 8889 .................... ////////////////////////////////////////////////////////////////////////////
8890 .................... // Description : Computes the absolute value of floating point number x 8890 .................... // Description : Computes the absolute value of floating point number x
8891 .................... // Returns : returns the absolute value of x 8891 .................... // Returns : returns the absolute value of x
8892 .................... // Date : N/A 8892 .................... // Date : N/A
8893 .................... // 8893 .................... //
8894 .................... #define fabs abs 8894 .................... #define fabs abs
8895 .................... 8895 ....................
8896 .................... //////////////////////////////////////////////////////////////////////////// 8896 .................... ////////////////////////////////////////////////////////////////////////////
8897 .................... // float fmod(float x) 8897 .................... // float fmod(float x)
8898 .................... //////////////////////////////////////////////////////////////////////////// 8898 .................... ////////////////////////////////////////////////////////////////////////////
8899 .................... // Description : Computes the floating point remainder of x/y 8899 .................... // Description : Computes the floating point remainder of x/y
8900 .................... // Returns : returns the value of x= i*y, for some integer i such that, if y 8900 .................... // Returns : returns the value of x= i*y, for some integer i such that, if y
8901 .................... // is non zero, the result has the same isgn of x na dmagnitude less than the 8901 .................... // is non zero, the result has the same isgn of x na dmagnitude less than the
8902 .................... // magnitude of y. If y is zero then a domain error occurs. 8902 .................... // magnitude of y. If y is zero then a domain error occurs.
8903 .................... // Date : N/A 8903 .................... // Date : N/A
8904 .................... // 8904 .................... //
8905 .................... 8905 ....................
8906 .................... float fmod(float32 x,float32 y) 8906 .................... float fmod(float32 x,float32 y)
8907 .................... { 8907 .................... {
8908 .................... float32 i; 8908 .................... float32 i;
8909 .................... if (y!=0.0) 8909 .................... if (y!=0.0)
8910 .................... { 8910 .................... {
8911 .................... i=(x/y < 0.0)? ceil(x/y): floor(x/y); 8911 .................... i=(x/y < 0.0)? ceil(x/y): floor(x/y);
8912 .................... return(x-(i*y)); 8912 .................... return(x-(i*y));
8913 .................... } 8913 .................... }
8914 .................... else 8914 .................... else
8915 .................... { 8915 .................... {
8916 .................... #ifdef _ERRNO 8916 .................... #ifdef _ERRNO
8917 .................... { 8917 .................... {
8918 .................... errno=EDOM; 8918 .................... errno=EDOM;
8919 .................... } 8919 .................... }
8920 .................... #endif 8920 .................... #endif
8921 .................... } 8921 .................... }
8922 .................... } 8922 .................... }
8923 .................... //Overloaded function for fmod() for PCD 8923 .................... //Overloaded function for fmod() for PCD
8924 .................... // Overloaded function fmod() for data type - Float48 8924 .................... // Overloaded function fmod() for data type - Float48
8925 .................... #if defined(__PCD__) 8925 .................... #if defined(__PCD__)
8926 .................... float48 fmod(float48 x,float48 y) 8926 .................... float48 fmod(float48 x,float48 y)
8927 .................... { 8927 .................... {
8928 .................... float48 i; 8928 .................... float48 i;
8929 .................... if (y!=0.0) 8929 .................... if (y!=0.0)
8930 .................... { 8930 .................... {
8931 .................... i=(x/y < 0.0)? ceil(x/y): floor(x/y); 8931 .................... i=(x/y < 0.0)? ceil(x/y): floor(x/y);
8932 .................... return(x-(i*y)); 8932 .................... return(x-(i*y));
8933 .................... } 8933 .................... }
8934 .................... else 8934 .................... else
8935 .................... { 8935 .................... {
8936 .................... #ifdef _ERRNO 8936 .................... #ifdef _ERRNO
8937 .................... { 8937 .................... {
8938 .................... errno=EDOM; 8938 .................... errno=EDOM;
8939 .................... } 8939 .................... }
8940 .................... #endif 8940 .................... #endif
8941 .................... } 8941 .................... }
8942 .................... } 8942 .................... }
8943 .................... // Overloaded function fmod() for data type - Float64 8943 .................... // Overloaded function fmod() for data type - Float64
8944 .................... float64 fmod(float64 x,float64 y) 8944 .................... float64 fmod(float64 x,float64 y)
8945 .................... { 8945 .................... {
8946 .................... float64 i; 8946 .................... float64 i;
8947 .................... if (y!=0.0) 8947 .................... if (y!=0.0)
8948 .................... { 8948 .................... {
8949 .................... i=(x/y < 0.0)? ceil(x/y): floor(x/y); 8949 .................... i=(x/y < 0.0)? ceil(x/y): floor(x/y);
8950 .................... return(x-(i*y)); 8950 .................... return(x-(i*y));
8951 .................... } 8951 .................... }
8952 .................... else 8952 .................... else
8953 .................... { 8953 .................... {
8954 .................... #ifdef _ERRNO 8954 .................... #ifdef _ERRNO
8955 .................... { 8955 .................... {
8956 .................... errno=EDOM; 8956 .................... errno=EDOM;
8957 .................... } 8957 .................... }
8958 .................... #endif 8958 .................... #endif
8959 .................... } 8959 .................... }
8960 .................... } 8960 .................... }
8961 .................... #endif 8961 .................... #endif
8962 .................... //////////////////// Exponential and logarithmic functions //////////////////// 8962 .................... //////////////////// Exponential and logarithmic functions ////////////////////
8963 .................... //////////////////////////////////////////////////////////////////////////// 8963 .................... ////////////////////////////////////////////////////////////////////////////
8964 .................... // float exp(float x) 8964 .................... // float exp(float x)
8965 .................... //////////////////////////////////////////////////////////////////////////// 8965 .................... ////////////////////////////////////////////////////////////////////////////
8966 .................... // Description : returns the value (e^x) 8966 .................... // Description : returns the value (e^x)
8967 .................... // Date : N/A 8967 .................... // Date : N/A
8968 .................... // 8968 .................... //
8969 .................... #define LN2 0.6931471805599453 8969 .................... #define LN2 0.6931471805599453
8970 .................... 8970 ....................
8971 .................... float const pe[6] = {0.000207455774, 0.00127100575, 0.00965065093, 8971 .................... float const pe[6] = {0.000207455774, 0.00127100575, 0.00965065093,
8972 .................... 0.0554965651, 0.240227138, 0.693147172}; 8972 .................... 0.0554965651, 0.240227138, 0.693147172};
8973 .................... 8973 ....................
8974 .................... 8974 ....................
8975 .................... float32 exp(float32 x) 8975 .................... float32 exp(float32 x)
8976 .................... { 8976 .................... {
8977 .................... float32 y, res, r; 8977 .................... float32 y, res, r;
8978 .................... #if defined(__PCD__) 8978 .................... #if defined(__PCD__)
8979 .................... int8 data1; 8979 .................... int8 data1;
8980 .................... #endif 8980 .................... #endif
8981 .................... signed int8 n; 8981 .................... signed int8 n;
8982 .................... int1 s; 8982 .................... int1 s;
8983 .................... #ifdef _ERRNO 8983 .................... #ifdef _ERRNO
8984 .................... if(x > 88.722838) 8984 .................... if(x > 88.722838)
8985 .................... { 8985 .................... {
8986 .................... errno=ERANGE; 8986 .................... errno=ERANGE;
8987 .................... return(0); 8987 .................... return(0);
8988 .................... } 8988 .................... }
8989 .................... #endif 8989 .................... #endif
8990 .................... n = (signed int16)(x/LN2); 8990 .................... n = (signed int16)(x/LN2);
8991 .................... s = 0; 8991 .................... s = 0;
8992 .................... y = x; 8992 .................... y = x;
8993 .................... 8993 ....................
8994 .................... if (x < 0) 8994 .................... if (x < 0)
8995 .................... { 8995 .................... {
8996 .................... s = 1; 8996 .................... s = 1;
8997 .................... n = -n; 8997 .................... n = -n;
8998 .................... y = -y; 8998 .................... y = -y;
8999 .................... } 8999 .................... }
9000 .................... 9000 ....................
9001 .................... res = 0.0; 9001 .................... res = 0.0;
9002 .................... #if !defined(__PCD__) 9002 .................... #if !defined(__PCD__)
9003 .................... *((unsigned int8 *)(&res)) = n + 0x7F; 9003 .................... *((unsigned int8 *)(&res)) = n + 0x7F;
9004 .................... #endif 9004 .................... #endif
9005 .................... 9005 ....................
9006 .................... #if defined(__PCD__) // Takes care of IEEE format for PCD 9006 .................... #if defined(__PCD__) // Takes care of IEEE format for PCD
9007 .................... data1 = n+0x7F; 9007 .................... data1 = n+0x7F;
9008 .................... if(bit_test(data1,0)) 9008 .................... if(bit_test(data1,0))
9009 .................... bit_set(*(((unsigned int8 *)(&res)+2)),7); 9009 .................... bit_set(*(((unsigned int8 *)(&res)+2)),7);
9010 .................... rotate_right(&data1,1); 9010 .................... rotate_right(&data1,1);
9011 .................... bit_clear(data1,7); 9011 .................... bit_clear(data1,7);
9012 .................... *(((unsigned int8 *)(&res)+3)) = data1; 9012 .................... *(((unsigned int8 *)(&res)+3)) = data1;
9013 .................... #endif 9013 .................... #endif
9014 .................... 9014 ....................
9015 .................... y = y/LN2 - (float32)n; 9015 .................... y = y/LN2 - (float32)n;
9016 .................... 9016 ....................
9017 .................... r = pe[0]*y + pe[1]; 9017 .................... r = pe[0]*y + pe[1];
9018 .................... r = r*y + pe[2]; 9018 .................... r = r*y + pe[2];
9019 .................... r = r*y + pe[3]; 9019 .................... r = r*y + pe[3];
9020 .................... r = r*y + pe[4]; 9020 .................... r = r*y + pe[4];
9021 .................... r = r*y + pe[5]; 9021 .................... r = r*y + pe[5];
9022 .................... 9022 ....................
9023 .................... res = res*(1.0 + y*r); 9023 .................... res = res*(1.0 + y*r);
9024 .................... 9024 ....................
9025 .................... if (s) 9025 .................... if (s)
9026 .................... res = 1.0/res; 9026 .................... res = 1.0/res;
9027 .................... return(res); 9027 .................... return(res);
9028 .................... } 9028 .................... }
9029 .................... 9029 ....................
9030 .................... 9030 ....................
9031 .................... //Overloaded function for exp() for PCD 9031 .................... //Overloaded function for exp() for PCD
9032 .................... // Overloaded function exp() for data type - Float48 9032 .................... // Overloaded function exp() for data type - Float48
9033 .................... #if defined(__PCD__) 9033 .................... #if defined(__PCD__)
9034 .................... float48 exp(float48 x) 9034 .................... float48 exp(float48 x)
9035 .................... { 9035 .................... {
9036 .................... float48 y, res, r; 9036 .................... float48 y, res, r;
9037 .................... int8 data1; 9037 .................... int8 data1;
9038 .................... signed int8 n; 9038 .................... signed int8 n;
9039 .................... int1 s; 9039 .................... int1 s;
9040 .................... #ifdef _ERRNO 9040 .................... #ifdef _ERRNO
9041 .................... if(x > 88.722838) 9041 .................... if(x > 88.722838)
9042 .................... { 9042 .................... {
9043 .................... errno=ERANGE; 9043 .................... errno=ERANGE;
9044 .................... return(0); 9044 .................... return(0);
9045 .................... } 9045 .................... }
9046 .................... #endif 9046 .................... #endif
9047 .................... n = (signed int16)(x/LN2); 9047 .................... n = (signed int16)(x/LN2);
9048 .................... s = 0; 9048 .................... s = 0;
9049 .................... y = x; 9049 .................... y = x;
9050 .................... 9050 ....................
9051 .................... if (x < 0) 9051 .................... if (x < 0)
9052 .................... { 9052 .................... {
9053 .................... s = 1; 9053 .................... s = 1;
9054 .................... n = -n; 9054 .................... n = -n;
9055 .................... y = -y; 9055 .................... y = -y;
9056 .................... } 9056 .................... }
9057 .................... 9057 ....................
9058 .................... res = 0.0; 9058 .................... res = 0.0;
9059 .................... 9059 ....................
9060 .................... data1 = n+0x7F; 9060 .................... data1 = n+0x7F;
9061 .................... if(bit_test(data1,0)) 9061 .................... if(bit_test(data1,0))
9062 .................... bit_set(*(((unsigned int8 *)(&res)+4)),7); 9062 .................... bit_set(*(((unsigned int8 *)(&res)+4)),7);
9063 .................... rotate_right(&data1,1); 9063 .................... rotate_right(&data1,1);
9064 .................... bit_clear(data1,7); 9064 .................... bit_clear(data1,7);
9065 .................... *(((unsigned int8 *)(&res)+5)) = data1; 9065 .................... *(((unsigned int8 *)(&res)+5)) = data1;
9066 .................... 9066 ....................
9067 .................... y = y/LN2 - (float48)n; 9067 .................... y = y/LN2 - (float48)n;
9068 .................... 9068 ....................
9069 .................... r = pe[0]*y + pe[1]; 9069 .................... r = pe[0]*y + pe[1];
9070 .................... r = r*y + pe[2]; 9070 .................... r = r*y + pe[2];
9071 .................... r = r*y + pe[3]; 9071 .................... r = r*y + pe[3];
9072 .................... r = r*y + pe[4]; 9072 .................... r = r*y + pe[4];
9073 .................... r = r*y + pe[5]; 9073 .................... r = r*y + pe[5];
9074 .................... 9074 ....................
9075 .................... res = res*(1.0 + y*r); 9075 .................... res = res*(1.0 + y*r);
9076 .................... 9076 ....................
9077 .................... if (s) 9077 .................... if (s)
9078 .................... res = 1.0/res; 9078 .................... res = 1.0/res;
9079 .................... return(res); 9079 .................... return(res);
9080 .................... } 9080 .................... }
9081 .................... 9081 ....................
9082 .................... // Overloaded function exp() for data type - Float64 9082 .................... // Overloaded function exp() for data type - Float64
9083 .................... float64 exp(float64 x) 9083 .................... float64 exp(float64 x)
9084 .................... { 9084 .................... {
9085 .................... float64 y, res, r; 9085 .................... float64 y, res, r;
9086 .................... unsigned int16 data1, data2; 9086 .................... unsigned int16 data1, data2;
9087 .................... unsigned int16 *p; 9087 .................... unsigned int16 *p;
9088 .................... signed int16 n; 9088 .................... signed int16 n;
9089 .................... int1 s; 9089 .................... int1 s;
9090 .................... #ifdef _ERRNO 9090 .................... #ifdef _ERRNO
9091 .................... if(x > 709.7827128) 9091 .................... if(x > 709.7827128)
9092 .................... { 9092 .................... {
9093 .................... errno=ERANGE; 9093 .................... errno=ERANGE;
9094 .................... return(0); 9094 .................... return(0);
9095 .................... } 9095 .................... }
9096 .................... #endif 9096 .................... #endif
9097 .................... n = (signed int16)(x/LN2); 9097 .................... n = (signed int16)(x/LN2);
9098 .................... s = 0; 9098 .................... s = 0;
9099 .................... y = x; 9099 .................... y = x;
9100 .................... 9100 ....................
9101 .................... if (x < 0) 9101 .................... if (x < 0)
9102 .................... { 9102 .................... {
9103 .................... s = 1; 9103 .................... s = 1;
9104 .................... n = -n; 9104 .................... n = -n;
9105 .................... y = -y; 9105 .................... y = -y;
9106 .................... } 9106 .................... }
9107 .................... 9107 ....................
9108 .................... res = 0.0; 9108 .................... res = 0.0;
9109 .................... 9109 ....................
9110 .................... #if !defined(__PCD__) 9110 .................... #if !defined(__PCD__)
9111 .................... *((unsigned int16 *)(&res)) = n + 0x7F; 9111 .................... *((unsigned int16 *)(&res)) = n + 0x7F;
9112 .................... #endif 9112 .................... #endif
9113 .................... p= (((unsigned int16 *)(&res))+3); 9113 .................... p= (((unsigned int16 *)(&res))+3);
9114 .................... data1 = *p; 9114 .................... data1 = *p;
9115 .................... data2 = *p; 9115 .................... data2 = *p;
9116 .................... data1 = n + 0x3FF; 9116 .................... data1 = n + 0x3FF;
9117 .................... data1 = data1 <<4; 9117 .................... data1 = data1 <<4;
9118 .................... if(bit_test(data2,15)) 9118 .................... if(bit_test(data2,15))
9119 .................... bit_set(data1,15); 9119 .................... bit_set(data1,15);
9120 .................... data2 = data2 & 0x000F; 9120 .................... data2 = data2 & 0x000F;
9121 .................... data1 ^= data2; 9121 .................... data1 ^= data2;
9122 .................... 9122 ....................
9123 .................... *(((unsigned int16 *)(&res)+3)) = data1; 9123 .................... *(((unsigned int16 *)(&res)+3)) = data1;
9124 .................... 9124 ....................
9125 .................... 9125 ....................
9126 .................... y = y/LN2 - (float64)n; 9126 .................... y = y/LN2 - (float64)n;
9127 .................... 9127 ....................
9128 .................... r = pe[0]*y + pe[1]; 9128 .................... r = pe[0]*y + pe[1];
9129 .................... r = r*y + pe[2]; 9129 .................... r = r*y + pe[2];
9130 .................... r = r*y + pe[3]; 9130 .................... r = r*y + pe[3];
9131 .................... r = r*y + pe[4]; 9131 .................... r = r*y + pe[4];
9132 .................... r = r*y + pe[5]; 9132 .................... r = r*y + pe[5];
9133 .................... 9133 ....................
9134 .................... res = res*(1.0 + y*r); 9134 .................... res = res*(1.0 + y*r);
9135 .................... 9135 ....................
9136 .................... if (s) 9136 .................... if (s)
9137 .................... res = 1.0/res; 9137 .................... res = 1.0/res;
9138 .................... return(res); 9138 .................... return(res);
9139 .................... } 9139 .................... }
9140 .................... 9140 ....................
9141 .................... #ENDIF 9141 .................... #ENDIF
9142 .................... 9142 ....................
9143 .................... 9143 ....................
9144 .................... /************************************************************/ 9144 .................... /************************************************************/
9145 .................... 9145 ....................
9146 .................... float32 const pl[4] = {0.45145214, -9.0558803, 26.940971, -19.860189}; 9146 .................... float32 const pl[4] = {0.45145214, -9.0558803, 26.940971, -19.860189};
9147 .................... float32 const ql[4] = {1.0000000, -8.1354259, 16.780517, -9.9300943}; 9147 .................... float32 const ql[4] = {1.0000000, -8.1354259, 16.780517, -9.9300943};
9148 .................... 9148 ....................
9149 .................... //////////////////////////////////////////////////////////////////////////// 9149 .................... ////////////////////////////////////////////////////////////////////////////
9150 .................... // float log(float x) 9150 .................... // float log(float x)
9151 .................... //////////////////////////////////////////////////////////////////////////// 9151 .................... ////////////////////////////////////////////////////////////////////////////
9152 .................... // Description : returns the the natural log of x 9152 .................... // Description : returns the the natural log of x
9153 .................... // Date : N/A 9153 .................... // Date : N/A
9154 .................... // 9154 .................... //
9155 .................... float32 log(float32 x) 9155 .................... float32 log(float32 x)
9156 .................... { 9156 .................... {
9157 .................... float32 y, res, r, y2; 9157 .................... float32 y, res, r, y2;
9158 .................... #if defined(__PCD__) 9158 .................... #if defined(__PCD__)
9159 .................... unsigned int8 data1,data2; 9159 .................... unsigned int8 data1,data2;
9160 .................... #endif 9160 .................... #endif
9161 .................... signed int8 n; 9161 .................... signed int8 n;
9162 .................... #ifdef _ERRNO 9162 .................... #ifdef _ERRNO
9163 .................... if(x <0) 9163 .................... if(x <0)
9164 .................... { 9164 .................... {
9165 .................... errno=EDOM; 9165 .................... errno=EDOM;
9166 .................... } 9166 .................... }
9167 .................... if(x ==0) 9167 .................... if(x ==0)
9168 .................... { 9168 .................... {
9169 .................... errno=ERANGE; 9169 .................... errno=ERANGE;
9170 .................... return(0); 9170 .................... return(0);
9171 .................... } 9171 .................... }
9172 .................... #endif 9172 .................... #endif
9173 .................... y = x; 9173 .................... y = x;
9174 .................... 9174 ....................
9175 .................... if (y != 1.0) 9175 .................... if (y != 1.0)
9176 .................... { 9176 .................... {
9177 .................... #if !defined(__PCD__) 9177 .................... #if !defined(__PCD__)
9178 .................... *((unsigned int8 *)(&y)) = 0x7E; 9178 .................... *((unsigned int8 *)(&y)) = 0x7E;
9179 .................... #endif 9179 .................... #endif
9180 .................... 9180 ....................
9181 .................... #if defined(__PCD__) // Takes care of IEEE format 9181 .................... #if defined(__PCD__) // Takes care of IEEE format
9182 .................... data2 = *(((unsigned int8 *)(&y))+3); 9182 .................... data2 = *(((unsigned int8 *)(&y))+3);
9183 .................... *(((unsigned int8 *)(&y))+3) = 0x3F; 9183 .................... *(((unsigned int8 *)(&y))+3) = 0x3F;
9184 .................... data1 = *(((unsigned int8 *)(&y))+2); 9184 .................... data1 = *(((unsigned int8 *)(&y))+2);
9185 .................... bit_clear(data1,7); 9185 .................... bit_clear(data1,7);
9186 .................... *(((unsigned int8 *)(&y))+2) = data1; 9186 .................... *(((unsigned int8 *)(&y))+2) = data1;
9187 .................... if(bit_test(data2,7)) 9187 .................... if(bit_test(data2,7))
9188 .................... bit_set(*(((unsigned int8 *)(&y))+3),7); 9188 .................... bit_set(*(((unsigned int8 *)(&y))+3),7);
9189 .................... #endif 9189 .................... #endif
9190 .................... 9190 ....................
9191 .................... y = (y - 1.0)/(y + 1.0); 9191 .................... y = (y - 1.0)/(y + 1.0);
9192 .................... 9192 ....................
9193 .................... y2=y*y; 9193 .................... y2=y*y;
9194 .................... 9194 ....................
9195 .................... res = pl[0]*y2 + pl[1]; 9195 .................... res = pl[0]*y2 + pl[1];
9196 .................... res = res*y2 + pl[2]; 9196 .................... res = res*y2 + pl[2];
9197 .................... res = res*y2 + pl[3]; 9197 .................... res = res*y2 + pl[3];
9198 .................... 9198 ....................
9199 .................... r = ql[0]*y2 + ql[1]; 9199 .................... r = ql[0]*y2 + ql[1];
9200 .................... r = r*y2 + ql[2]; 9200 .................... r = r*y2 + ql[2];
9201 .................... r = r*y2 + ql[3]; 9201 .................... r = r*y2 + ql[3];
9202 .................... 9202 ....................
9203 .................... res = y*res/r; 9203 .................... res = y*res/r;
9204 .................... #if !defined(__PCD__) 9204 .................... #if !defined(__PCD__)
9205 .................... n = *((unsigned int8 *)(&x)) - 0x7E; 9205 .................... n = *((unsigned int8 *)(&x)) - 0x7E;
9206 .................... #endif 9206 .................... #endif
9207 .................... #if defined(__PCD__) 9207 .................... #if defined(__PCD__)
9208 .................... data1 = *(((unsigned int8 *)(&x)+3)); 9208 .................... data1 = *(((unsigned int8 *)(&x)+3));
9209 .................... rotate_left(&data1,1); 9209 .................... rotate_left(&data1,1);
9210 .................... data2 = *(((unsigned int8 *)(&x)+2)); 9210 .................... data2 = *(((unsigned int8 *)(&x)+2));
9211 .................... if(bit_test (data2,7)) 9211 .................... if(bit_test (data2,7))
9212 .................... bit_set(data1,0); 9212 .................... bit_set(data1,0);
9213 .................... n = data1 - 0x7E; 9213 .................... n = data1 - 0x7E;
9214 .................... #endif 9214 .................... #endif
9215 .................... 9215 ....................
9216 .................... if (n<0) 9216 .................... if (n<0)
9217 .................... r = -(float32)-n; 9217 .................... r = -(float32)-n;
9218 .................... else 9218 .................... else
9219 .................... r = (float32)n; 9219 .................... r = (float32)n;
9220 .................... 9220 ....................
9221 .................... res += r*LN2; 9221 .................... res += r*LN2;
9222 .................... } 9222 .................... }
9223 .................... 9223 ....................
9224 .................... else 9224 .................... else
9225 .................... res = 0.0; 9225 .................... res = 0.0;
9226 .................... 9226 ....................
9227 .................... return(res); 9227 .................... return(res);
9228 .................... } 9228 .................... }
9229 .................... 9229 ....................
9230 .................... //Overloaded function for log() for PCD 9230 .................... //Overloaded function for log() for PCD
9231 .................... // Overloaded function log() for data type - Float48 9231 .................... // Overloaded function log() for data type - Float48
9232 .................... #if defined(__PCD__) 9232 .................... #if defined(__PCD__)
9233 .................... float48 log(float48 x) 9233 .................... float48 log(float48 x)
9234 .................... { 9234 .................... {
9235 .................... float48 y, res, r, y2; 9235 .................... float48 y, res, r, y2;
9236 .................... unsigned int8 data1,data2; 9236 .................... unsigned int8 data1,data2;
9237 .................... signed int8 n; 9237 .................... signed int8 n;
9238 .................... #ifdef _ERRNO 9238 .................... #ifdef _ERRNO
9239 .................... if(x <0) 9239 .................... if(x <0)
9240 .................... { 9240 .................... {
9241 .................... errno=EDOM; 9241 .................... errno=EDOM;
9242 .................... } 9242 .................... }
9243 .................... if(x ==0) 9243 .................... if(x ==0)
9244 .................... { 9244 .................... {
9245 .................... errno=ERANGE; 9245 .................... errno=ERANGE;
9246 .................... return(0); 9246 .................... return(0);
9247 .................... } 9247 .................... }
9248 .................... #endif 9248 .................... #endif
9249 .................... y = x; 9249 .................... y = x;
9250 .................... 9250 ....................
9251 .................... if (y != 1.0) 9251 .................... if (y != 1.0)
9252 .................... { 9252 .................... {
9253 .................... 9253 ....................
9254 .................... #if !defined(__PCD__) 9254 .................... #if !defined(__PCD__)
9255 .................... *((unsigned int8 *)(&y)) = 0x7E; 9255 .................... *((unsigned int8 *)(&y)) = 0x7E;
9256 .................... #endif 9256 .................... #endif
9257 .................... data2 = *(((unsigned int8 *)(&y))+5); 9257 .................... data2 = *(((unsigned int8 *)(&y))+5);
9258 .................... *(((unsigned int8 *)(&y))+5) = 0x3F; 9258 .................... *(((unsigned int8 *)(&y))+5) = 0x3F;
9259 .................... data1 = *(((unsigned int8 *)(&y))+4); 9259 .................... data1 = *(((unsigned int8 *)(&y))+4);
9260 .................... bit_clear(data1,7); 9260 .................... bit_clear(data1,7);
9261 .................... *(((unsigned int8 *)(&y))+4) = data1; 9261 .................... *(((unsigned int8 *)(&y))+4) = data1;
9262 .................... 9262 ....................
9263 .................... if(bit_test(data2,7)) 9263 .................... if(bit_test(data2,7))
9264 .................... bit_set(*(((unsigned int8 *)(&y))+4),7); 9264 .................... bit_set(*(((unsigned int8 *)(&y))+4),7);
9265 .................... y = (y - 1.0)/(y + 1.0); 9265 .................... y = (y - 1.0)/(y + 1.0);
9266 .................... 9266 ....................
9267 .................... y2=y*y; 9267 .................... y2=y*y;
9268 .................... 9268 ....................
9269 .................... res = pl[0]*y2 + pl[1]; 9269 .................... res = pl[0]*y2 + pl[1];
9270 .................... res = res*y2 + pl[2]; 9270 .................... res = res*y2 + pl[2];
9271 .................... res = res*y2 + pl[3]; 9271 .................... res = res*y2 + pl[3];
9272 .................... 9272 ....................
9273 .................... r = ql[0]*y2 + ql[1]; 9273 .................... r = ql[0]*y2 + ql[1];
9274 .................... r = r*y2 + ql[2]; 9274 .................... r = r*y2 + ql[2];
9275 .................... r = r*y2 + ql[3]; 9275 .................... r = r*y2 + ql[3];
9276 .................... 9276 ....................
9277 .................... res = y*res/r; 9277 .................... res = y*res/r;
9278 .................... 9278 ....................
9279 .................... data1 = *(((unsigned int8 *)(&x)+5)); 9279 .................... data1 = *(((unsigned int8 *)(&x)+5));
9280 .................... rotate_left(&data1,1); 9280 .................... rotate_left(&data1,1);
9281 .................... data2 = *(((unsigned int8 *)(&x)+4)); 9281 .................... data2 = *(((unsigned int8 *)(&x)+4));
9282 .................... if(bit_test (data2,7)) 9282 .................... if(bit_test (data2,7))
9283 .................... bit_set(data1,0); 9283 .................... bit_set(data1,0);
9284 .................... 9284 ....................
9285 .................... n = data1 - 0x7E; 9285 .................... n = data1 - 0x7E;
9286 .................... 9286 ....................
9287 .................... if (n<0) 9287 .................... if (n<0)
9288 .................... r = -(float48)-n; 9288 .................... r = -(float48)-n;
9289 .................... else 9289 .................... else
9290 .................... r = (float48)n; 9290 .................... r = (float48)n;
9291 .................... 9291 ....................
9292 .................... res += r*LN2; 9292 .................... res += r*LN2;
9293 .................... } 9293 .................... }
9294 .................... 9294 ....................
9295 .................... else 9295 .................... else
9296 .................... res = 0.0; 9296 .................... res = 0.0;
9297 .................... 9297 ....................
9298 .................... return(res); 9298 .................... return(res);
9299 .................... } 9299 .................... }
9300 .................... 9300 ....................
9301 .................... // Overloaded function log() for data type - Float48 9301 .................... // Overloaded function log() for data type - Float48
9302 .................... #if defined(__PCD__) 9302 .................... #if defined(__PCD__)
9303 .................... float32 const pl_64[4] = {0.45145214, -9.0558803, 26.940971, -19.860189}; 9303 .................... float32 const pl_64[4] = {0.45145214, -9.0558803, 26.940971, -19.860189};
9304 .................... float32 const ql_64[4] = {1.0000000, -8.1354259, 16.780517, -9.9300943}; 9304 .................... float32 const ql_64[4] = {1.0000000, -8.1354259, 16.780517, -9.9300943};
9305 .................... #endif 9305 .................... #endif
9306 .................... float64 log(float64 x) 9306 .................... float64 log(float64 x)
9307 .................... { 9307 .................... {
9308 .................... float64 y, res, r, y2; 9308 .................... float64 y, res, r, y2;
9309 .................... unsigned int16 data1,data2; 9309 .................... unsigned int16 data1,data2;
9310 .................... unsigned int16 *p; 9310 .................... unsigned int16 *p;
9311 .................... signed int16 n; 9311 .................... signed int16 n;
9312 .................... #ifdef _ERRNO 9312 .................... #ifdef _ERRNO
9313 .................... if(x <0) 9313 .................... if(x <0)
9314 .................... { 9314 .................... {
9315 .................... errno=EDOM; 9315 .................... errno=EDOM;
9316 .................... } 9316 .................... }
9317 .................... if(x ==0) 9317 .................... if(x ==0)
9318 .................... { 9318 .................... {
9319 .................... errno=ERANGE; 9319 .................... errno=ERANGE;
9320 .................... return(0); 9320 .................... return(0);
9321 .................... } 9321 .................... }
9322 .................... #endif 9322 .................... #endif
9323 .................... y = x; 9323 .................... y = x;
9324 .................... 9324 ....................
9325 .................... if (y != 1.0) 9325 .................... if (y != 1.0)
9326 .................... { 9326 .................... {
9327 .................... #if !defined(__PCD__) 9327 .................... #if !defined(__PCD__)
9328 .................... *((unsigned int8 *)(&y)) = 0x7E; 9328 .................... *((unsigned int8 *)(&y)) = 0x7E;
9329 .................... #endif 9329 .................... #endif
9330 .................... p= (((unsigned int16 *)(&y))+3); 9330 .................... p= (((unsigned int16 *)(&y))+3);
9331 .................... data1 = *p; 9331 .................... data1 = *p;
9332 .................... data2 = *p; 9332 .................... data2 = *p;
9333 .................... data1 = 0x3FE; 9333 .................... data1 = 0x3FE;
9334 .................... data1 = data1 <<4; 9334 .................... data1 = data1 <<4;
9335 .................... if(bit_test (data2,15)) 9335 .................... if(bit_test (data2,15))
9336 .................... bit_set(data1,15); 9336 .................... bit_set(data1,15);
9337 .................... data2 = data2 & 0x000F; 9337 .................... data2 = data2 & 0x000F;
9338 .................... data1 ^=data2; 9338 .................... data1 ^=data2;
9339 .................... 9339 ....................
9340 .................... *p = data1; 9340 .................... *p = data1;
9341 .................... 9341 ....................
9342 .................... y = (y - 1.0)/(y + 1.0); 9342 .................... y = (y - 1.0)/(y + 1.0);
9343 .................... 9343 ....................
9344 .................... y2=y*y; 9344 .................... y2=y*y;
9345 .................... 9345 ....................
9346 .................... res = pl_64[0]*y2 + pl_64[1]; 9346 .................... res = pl_64[0]*y2 + pl_64[1];
9347 .................... res = res*y2 + pl_64[2]; 9347 .................... res = res*y2 + pl_64[2];
9348 .................... res = res*y2 + pl_64[3]; 9348 .................... res = res*y2 + pl_64[3];
9349 .................... 9349 ....................
9350 .................... r = ql_64[0]*y2 + ql_64[1]; 9350 .................... r = ql_64[0]*y2 + ql_64[1];
9351 .................... r = r*y2 + ql_64[2]; 9351 .................... r = r*y2 + ql_64[2];
9352 .................... r = r*y2 + ql_64[3]; 9352 .................... r = r*y2 + ql_64[3];
9353 .................... 9353 ....................
9354 .................... res = y*res/r; 9354 .................... res = y*res/r;
9355 .................... 9355 ....................
9356 .................... p= (((unsigned int16 *)(&x))+3); 9356 .................... p= (((unsigned int16 *)(&x))+3);
9357 .................... data1 = *p; 9357 .................... data1 = *p;
9358 .................... bit_clear(data1,15); 9358 .................... bit_clear(data1,15);
9359 .................... data1 = data1 >>4; 9359 .................... data1 = data1 >>4;
9360 .................... n = data1 - 0x3FE; 9360 .................... n = data1 - 0x3FE;
9361 .................... 9361 ....................
9362 .................... 9362 ....................
9363 .................... if (n<0) 9363 .................... if (n<0)
9364 .................... r = -(float64)-n; 9364 .................... r = -(float64)-n;
9365 .................... else 9365 .................... else
9366 .................... r = (float64)n; 9366 .................... r = (float64)n;
9367 .................... 9367 ....................
9368 .................... res += r*LN2; 9368 .................... res += r*LN2;
9369 .................... } 9369 .................... }
9370 .................... 9370 ....................
9371 .................... else 9371 .................... else
9372 .................... res = 0.0; 9372 .................... res = 0.0;
9373 .................... 9373 ....................
9374 .................... return(res); 9374 .................... return(res);
9375 .................... } 9375 .................... }
9376 .................... #endif 9376 .................... #endif
9377 .................... 9377 ....................
9378 .................... 9378 ....................
9379 .................... #define LN10 2.3025850929940456 9379 .................... #define LN10 2.3025850929940456
9380 .................... 9380 ....................
9381 .................... //////////////////////////////////////////////////////////////////////////// 9381 .................... ////////////////////////////////////////////////////////////////////////////
9382 .................... // float log10(float x) 9382 .................... // float log10(float x)
9383 .................... //////////////////////////////////////////////////////////////////////////// 9383 .................... ////////////////////////////////////////////////////////////////////////////
9384 .................... // Description : returns the the log base 10 of x 9384 .................... // Description : returns the the log base 10 of x
9385 .................... // Date : N/A 9385 .................... // Date : N/A
9386 .................... // 9386 .................... //
9387 .................... float32 log10(float32 x) 9387 .................... float32 log10(float32 x)
9388 .................... { 9388 .................... {
9389 .................... float32 r; 9389 .................... float32 r;
9390 .................... 9390 ....................
9391 .................... r = log(x); 9391 .................... r = log(x);
9392 .................... r = r/LN10; 9392 .................... r = r/LN10;
9393 .................... return(r); 9393 .................... return(r);
9394 .................... } 9394 .................... }
9395 .................... 9395 ....................
9396 .................... //Overloaded functions for log10() for PCD 9396 .................... //Overloaded functions for log10() for PCD
9397 .................... // Overloaded function log10() for data type - Float48 9397 .................... // Overloaded function log10() for data type - Float48
9398 .................... #if defined(__PCD__) 9398 .................... #if defined(__PCD__)
9399 .................... float48 log10(float48 x) 9399 .................... float48 log10(float48 x)
9400 .................... { 9400 .................... {
9401 .................... float48 r; 9401 .................... float48 r;
9402 .................... 9402 ....................
9403 .................... r = log(x); 9403 .................... r = log(x);
9404 .................... r = r/LN10; 9404 .................... r = r/LN10;
9405 .................... return(r); 9405 .................... return(r);
9406 .................... } 9406 .................... }
9407 .................... 9407 ....................
9408 .................... // Overloaded function log10() for data type - Float64 9408 .................... // Overloaded function log10() for data type - Float64
9409 .................... float64 log10(float64 x) 9409 .................... float64 log10(float64 x)
9410 .................... { 9410 .................... {
9411 .................... float64 r; 9411 .................... float64 r;
9412 .................... 9412 ....................
9413 .................... r = log(x); 9413 .................... r = log(x);
9414 .................... r = r/LN10; 9414 .................... r = r/LN10;
9415 .................... return(r); 9415 .................... return(r);
9416 .................... } 9416 .................... }
9417 .................... #endif 9417 .................... #endif
9418 .................... //////////////////////////////////////////////////////////////////////////// 9418 .................... ////////////////////////////////////////////////////////////////////////////
9419 .................... // float modf(float x) 9419 .................... // float modf(float x)
9420 .................... //////////////////////////////////////////////////////////////////////////// 9420 .................... ////////////////////////////////////////////////////////////////////////////
9421 .................... // Description :breaks the argument value int integral and fractional parts, 9421 .................... // Description :breaks the argument value int integral and fractional parts,
9422 .................... // ach of which have the same sign as the argument. It stores the integral part 9422 .................... // ach of which have the same sign as the argument. It stores the integral part
9423 .................... // as a float in the object pointed to by the iptr 9423 .................... // as a float in the object pointed to by the iptr
9424 .................... // Returns : returns the signed fractional part of value. 9424 .................... // Returns : returns the signed fractional part of value.
9425 .................... // Date : N/A 9425 .................... // Date : N/A
9426 .................... // 9426 .................... //
9427 .................... 9427 ....................
9428 .................... float32 modf(float32 value,float32 *iptr) 9428 .................... float32 modf(float32 value,float32 *iptr)
9429 .................... { 9429 .................... {
9430 .................... *iptr=(value < 0.0)? ceil(value): floor(value); 9430 .................... *iptr=(value < 0.0)? ceil(value): floor(value);
9431 .................... return(value - *iptr); 9431 .................... return(value - *iptr);
9432 .................... } 9432 .................... }
9433 .................... //Overloaded functions for modf() for PCD 9433 .................... //Overloaded functions for modf() for PCD
9434 .................... // Overloaded function modf() for data type - Float48 9434 .................... // Overloaded function modf() for data type - Float48
9435 .................... #if defined(__PCD__) 9435 .................... #if defined(__PCD__)
9436 .................... float48 modf(float48 value,float48 *iptr) 9436 .................... float48 modf(float48 value,float48 *iptr)
9437 .................... { 9437 .................... {
9438 .................... *iptr=(value < 0.0)? ceil(value): floor(value); 9438 .................... *iptr=(value < 0.0)? ceil(value): floor(value);
9439 .................... return(value - *iptr); 9439 .................... return(value - *iptr);
9440 .................... } 9440 .................... }
9441 .................... // Overloaded function modf() for data type - Float64 9441 .................... // Overloaded function modf() for data type - Float64
9442 .................... float64 modf(float64 value,float64 *iptr) 9442 .................... float64 modf(float64 value,float64 *iptr)
9443 .................... { 9443 .................... {
9444 .................... *iptr=(value < 0.0)? ceil(value): floor(value); 9444 .................... *iptr=(value < 0.0)? ceil(value): floor(value);
9445 .................... return(value - *iptr); 9445 .................... return(value - *iptr);
9446 .................... } 9446 .................... }
9447 .................... #endif 9447 .................... #endif
9448 .................... 9448 ....................
9449 .................... //////////////////////////////////////////////////////////////////////////// 9449 .................... ////////////////////////////////////////////////////////////////////////////
9450 .................... // float pwr(float x,float y) 9450 .................... // float pwr(float x,float y)
9451 .................... //////////////////////////////////////////////////////////////////////////// 9451 .................... ////////////////////////////////////////////////////////////////////////////
9452 .................... // Description : returns the value (x^y) 9452 .................... // Description : returns the value (x^y)
9453 .................... // Date : N/A 9453 .................... // Date : N/A
9454 .................... // 9454 .................... //
9455 .................... float32 pwr(float32 x,float32 y) 9455 .................... float32 pwr(float32 x,float32 y)
9456 .................... { 9456 .................... {
9457 .................... if(x>=0) 9457 .................... if(x>=0)
9458 .................... return( exp(y*log(x)) ); 9458 .................... return( exp(y*log(x)) );
9459 .................... else 9459 .................... else
9460 .................... return( -exp(y*log(-x)) ); 9460 .................... return( -exp(y*log(-x)) );
9461 .................... } 9461 .................... }
9462 .................... //Overloaded functions for pwr() for PCD 9462 .................... //Overloaded functions for pwr() for PCD
9463 .................... // Overloaded function pwr() for data type - Float48 9463 .................... // Overloaded function pwr() for data type - Float48
9464 .................... #if defined(__PCD__) 9464 .................... #if defined(__PCD__)
9465 .................... float48 pwr(float48 x,float48 y) 9465 .................... float48 pwr(float48 x,float48 y)
9466 .................... { 9466 .................... {
9467 .................... if(x>=0) 9467 .................... if(x>=0)
9468 .................... return( exp(y*log(x)) ); 9468 .................... return( exp(y*log(x)) );
9469 .................... else 9469 .................... else
9470 .................... return( -exp(y*log(-x)) ); 9470 .................... return( -exp(y*log(-x)) );
9471 .................... } 9471 .................... }
9472 .................... // Overloaded function pwr() for data type - Float64 9472 .................... // Overloaded function pwr() for data type - Float64
9473 .................... float64 pwr(float64 x,float64 y) 9473 .................... float64 pwr(float64 x,float64 y)
9474 .................... { 9474 .................... {
9475 .................... if(x>=0) 9475 .................... if(x>=0)
9476 .................... return( exp(y*log(x)) ); 9476 .................... return( exp(y*log(x)) );
9477 .................... else 9477 .................... else
9478 .................... return( -exp(y*log(-x)) ); 9478 .................... return( -exp(y*log(-x)) );
9479 .................... } 9479 .................... }
9480 .................... #endif 9480 .................... #endif
9481 .................... 9481 ....................
9482 .................... //////////////////// Power functions //////////////////// 9482 .................... //////////////////// Power functions ////////////////////
9483 .................... 9483 ....................
9484 .................... //////////////////////////////////////////////////////////////////////////// 9484 .................... ////////////////////////////////////////////////////////////////////////////
9485 .................... // float pow(float x,float y) 9485 .................... // float pow(float x,float y)
9486 .................... //////////////////////////////////////////////////////////////////////////// 9486 .................... ////////////////////////////////////////////////////////////////////////////
9487 .................... // Description : returns the value (x^y) 9487 .................... // Description : returns the value (x^y)
9488 .................... // Date : N/A 9488 .................... // Date : N/A
9489 .................... // 9489 .................... //
9490 .................... float32 pow(float32 x,float32 y) 9490 .................... float32 pow(float32 x,float32 y)
9491 .................... { 9491 .................... {
9492 .................... if(x>=0) 9492 .................... if(x>=0)
9493 .................... return( exp(y*log(x)) ); 9493 .................... return( exp(y*log(x)) );
9494 .................... else 9494 .................... else
9495 .................... return( -exp(y*log(-x)) ); 9495 .................... return( -exp(y*log(-x)) );
9496 .................... } 9496 .................... }
9497 .................... //Overloaded functions for pow() for PCD 9497 .................... //Overloaded functions for pow() for PCD
9498 .................... // Overloaded function for pow() data type - Float48 9498 .................... // Overloaded function for pow() data type - Float48
9499 .................... #if defined(__PCD__) 9499 .................... #if defined(__PCD__)
9500 .................... float48 pow(float48 x,float48 y) 9500 .................... float48 pow(float48 x,float48 y)
9501 .................... { 9501 .................... {
9502 .................... if(x>=0) 9502 .................... if(x>=0)
9503 .................... return( exp(y*log(x)) ); 9503 .................... return( exp(y*log(x)) );
9504 .................... else 9504 .................... else
9505 .................... return( -exp(y*log(-x)) ); 9505 .................... return( -exp(y*log(-x)) );
9506 .................... } 9506 .................... }
9507 .................... 9507 ....................
9508 .................... // Overloaded function pow() for data type - Float64 9508 .................... // Overloaded function pow() for data type - Float64
9509 .................... float64 pow(float64 x,float64 y) 9509 .................... float64 pow(float64 x,float64 y)
9510 .................... { 9510 .................... {
9511 .................... if(x>=0) 9511 .................... if(x>=0)
9512 .................... return( exp(y*log(x)) ); 9512 .................... return( exp(y*log(x)) );
9513 .................... else 9513 .................... else
9514 .................... return( -exp(y*log(-x)) ); 9514 .................... return( -exp(y*log(-x)) );
9515 .................... } 9515 .................... }
9516 .................... #endif 9516 .................... #endif
9517 .................... 9517 ....................
9518 .................... //////////////////////////////////////////////////////////////////////////// 9518 .................... ////////////////////////////////////////////////////////////////////////////
9519 .................... // float sqrt(float x) 9519 .................... // float sqrt(float x)
9520 .................... //////////////////////////////////////////////////////////////////////////// 9520 .................... ////////////////////////////////////////////////////////////////////////////
9521 .................... // Description : returns the square root of x 9521 .................... // Description : returns the square root of x
9522 .................... // Date : N/A 9522 .................... // Date : N/A
9523 .................... // 9523 .................... //
9524 .................... float32 sqrt(float32 x) 9524 .................... float32 sqrt(float32 x)
9525 .................... { 9525 .................... {
9526 .................... float32 y, res; 9526 .................... float32 y, res;
9527 .................... #if defined(__PCD__) 9527 .................... #if defined(__PCD__)
9528 .................... unsigned int16 data1,data2; 9528 .................... unsigned int16 data1,data2;
9529 .................... #endif 9529 .................... #endif
9530 .................... BYTE *p; 9530 .................... BYTE *p;
9531 .................... 9531 ....................
9532 .................... #ifdef _ERRNO 9532 .................... #ifdef _ERRNO
9533 .................... if(x < 0) 9533 .................... if(x < 0)
9534 .................... { 9534 .................... {
9535 .................... errno=EDOM; 9535 .................... errno=EDOM;
9536 .................... } 9536 .................... }
9537 .................... #endif 9537 .................... #endif
9538 .................... 9538 ....................
9539 .................... if( x<=0.0) 9539 .................... if( x<=0.0)
9540 * 9540 *
9541 19C2: MOVFF 6DF,6ED 9541 19C2: MOVFF 6DF,6ED
9542 19C6: MOVFF 6DE,6EC 9542 19C6: MOVFF 6DE,6EC
9543 19CA: MOVFF 6DD,6EB 9543 19CA: MOVFF 6DD,6EB
9544 19CE: MOVFF 6DC,6EA 9544 19CE: MOVFF 6DC,6EA
9545 19D2: MOVLB 6 9545 19D2: MOVLB 6
9546 19D4: CLRF xF1 9546 19D4: CLRF xF1
9547 19D6: CLRF xF0 9547 19D6: CLRF xF0
9548 19D8: CLRF xEF 9548 19D8: CLRF xEF
9549 19DA: CLRF xEE 9549 19DA: CLRF xEE
9550 19DC: MOVLB 0 9550 19DC: MOVLB 0
9551 19DE: RCALL 1948 9551 19DE: RCALL 1948
9552 19E0: BC 19E4 9552 19E0: BC 19E4
9553 19E2: BNZ 19EE 9553 19E2: BNZ 19EE
9554 .................... return(0.0); 9554 .................... return(0.0);
9555 19E4: CLRF 00 9555 19E4: CLRF 00
9556 19E6: CLRF 01 9556 19E6: CLRF 01
9557 19E8: CLRF 02 9557 19E8: CLRF 02
9558 19EA: CLRF 03 9558 19EA: CLRF 03
9559 19EC: BRA 1ADE 9559 19EC: BRA 1ADE
9560 .................... 9560 ....................
9561 .................... y=x; 9561 .................... y=x;
9562 19EE: MOVFF 6DF,6E3 9562 19EE: MOVFF 6DF,6E3
9563 19F2: MOVFF 6DE,6E2 9563 19F2: MOVFF 6DE,6E2
9564 19F6: MOVFF 6DD,6E1 9564 19F6: MOVFF 6DD,6E1
9565 19FA: MOVFF 6DC,6E0 9565 19FA: MOVFF 6DC,6E0
9566 .................... 9566 ....................
9567 .................... #if !defined(__PCD__) 9567 .................... #if !defined(__PCD__)
9568 .................... p=&y; 9568 .................... p=&y;
9569 19FE: MOVLW 06 9569 19FE: MOVLW 06
9570 1A00: MOVLB 6 9570 1A00: MOVLB 6
9571 1A02: MOVWF xE9 9571 1A02: MOVWF xE9
9572 1A04: MOVLW E0 9572 1A04: MOVLW E0
9573 1A06: MOVWF xE8 9573 1A06: MOVWF xE8
9574 .................... (*p)=(BYTE)((((unsigned int16)(*p)) + 127) >> 1); 9574 .................... (*p)=(BYTE)((((unsigned int16)(*p)) + 127) >> 1);
9575 1A08: MOVFF 6E8,FE9 9575 1A08: MOVFF 6E8,FE9
9576 1A0C: MOVFF 6E9,FEA 9576 1A0C: MOVFF 6E9,FEA
9577 1A10: MOVF FEF,W 9577 1A10: MOVF FEF,W
9578 1A12: CLRF xED 9578 1A12: CLRF xED
9579 1A14: MOVWF xEC 9579 1A14: MOVWF xEC
9580 1A16: MOVLW 7F 9580 1A16: MOVLW 7F
9581 1A18: ADDWF xEC,F 9581 1A18: ADDWF xEC,F
9582 1A1A: MOVLW 00 9582 1A1A: MOVLW 00
9583 1A1C: ADDWFC xED,F 9583 1A1C: ADDWFC xED,F
9584 1A1E: BCF FD8.0 9584 1A1E: BCF FD8.0
9585 1A20: RRCF xED,W 9585 1A20: RRCF xED,W
9586 1A22: RRCF xEC,W 9586 1A22: RRCF xEC,W
9587 1A24: MOVFF 6E9,FEA 9587 1A24: MOVFF 6E9,FEA
9588 1A28: MOVFF 6E8,FE9 9588 1A28: MOVFF 6E8,FE9
9589 1A2C: MOVWF FEF 9589 1A2C: MOVWF FEF
9590 .................... #endif 9590 .................... #endif
9591 .................... 9591 ....................
9592 .................... #if defined(__PCD__) 9592 .................... #if defined(__PCD__)
9593 .................... p = (((unsigned int8 *)(&y))+3); 9593 .................... p = (((unsigned int8 *)(&y))+3);
9594 .................... data1 = *(((unsigned int8 *)(&y))+3); 9594 .................... data1 = *(((unsigned int8 *)(&y))+3);
9595 .................... data2 = *(((unsigned int8 *)(&y))+2); 9595 .................... data2 = *(((unsigned int8 *)(&y))+2);
9596 .................... rotate_left(&data1,1); 9596 .................... rotate_left(&data1,1);
9597 .................... if(bit_test(data2,7)) 9597 .................... if(bit_test(data2,7))
9598 .................... bit_set(data1,0); 9598 .................... bit_set(data1,0);
9599 .................... data1 = ((data1+127) >>1); 9599 .................... data1 = ((data1+127) >>1);
9600 .................... bit_clear(data2,7); 9600 .................... bit_clear(data2,7);
9601 .................... if(bit_test(data1,0)) 9601 .................... if(bit_test(data1,0))
9602 .................... bit_set(data2,7); 9602 .................... bit_set(data2,7);
9603 .................... data1 = data1 >>1; 9603 .................... data1 = data1 >>1;
9604 .................... *(((unsigned int8 *)(&y))+3) = data1; 9604 .................... *(((unsigned int8 *)(&y))+3) = data1;
9605 .................... *(((unsigned int8 *)(&y))+2) = data2; 9605 .................... *(((unsigned int8 *)(&y))+2) = data2;
9606 .................... 9606 ....................
9607 .................... #endif 9607 .................... #endif
9608 .................... 9608 ....................
9609 .................... do { 9609 .................... do {
9610 .................... res=y; 9610 .................... res=y;
9611 1A2E: MOVFF 6E3,6E7 9611 1A2E: MOVFF 6E3,6E7
9612 1A32: MOVFF 6E2,6E6 9612 1A32: MOVFF 6E2,6E6
9613 1A36: MOVFF 6E1,6E5 9613 1A36: MOVFF 6E1,6E5
9614 1A3A: MOVFF 6E0,6E4 9614 1A3A: MOVFF 6E0,6E4
9615 .................... y+=(x/y); 9615 .................... y+=(x/y);
9616 1A3E: MOVFF 6DF,6ED 9616 1A3E: MOVFF 6DF,6ED
9617 1A42: MOVFF 6DE,6EC 9617 1A42: MOVFF 6DE,6EC
9618 1A46: MOVFF 6DD,6EB 9618 1A46: MOVFF 6DD,6EB
9619 1A4A: MOVFF 6DC,6EA 9619 1A4A: MOVFF 6DC,6EA
9620 1A4E: MOVFF 6E3,6F1 9620 1A4E: MOVFF 6E3,6F1
9621 1A52: MOVFF 6E2,6F0 9621 1A52: MOVFF 6E2,6F0
9622 1A56: MOVFF 6E1,6EF 9622 1A56: MOVFF 6E1,6EF
9623 1A5A: MOVFF 6E0,6EE 9623 1A5A: MOVFF 6E0,6EE
9624 1A5E: MOVLB 0 9624 1A5E: MOVLB 0
9625 1A60: RCALL 16BA 9625 1A60: RCALL 16BA
9626 1A62: BCF FD8.1 9626 1A62: BCF FD8.1
9627 1A64: MOVFF 6E3,6ED 9627 1A64: MOVFF 6E3,6ED
9628 1A68: MOVFF 6E2,6EC 9628 1A68: MOVFF 6E2,6EC
9629 1A6C: MOVFF 6E1,6EB 9629 1A6C: MOVFF 6E1,6EB
9630 1A70: MOVFF 6E0,6EA 9630 1A70: MOVFF 6E0,6EA
9631 1A74: MOVFF 03,6F1 9631 1A74: MOVFF 03,6F1
9632 1A78: MOVFF 02,6F0 9632 1A78: MOVFF 02,6F0
9633 1A7C: MOVFF 01,6EF 9633 1A7C: MOVFF 01,6EF
9634 1A80: MOVFF 00,6EE 9634 1A80: MOVFF 00,6EE
9635 1A84: RCALL 1442 9635 1A84: RCALL 1442
9636 1A86: MOVFF 03,6E3 9636 1A86: MOVFF 03,6E3
9637 1A8A: MOVFF 02,6E2 9637 1A8A: MOVFF 02,6E2
9638 1A8E: MOVFF 01,6E1 9638 1A8E: MOVFF 01,6E1
9639 1A92: MOVFF 00,6E0 9639 1A92: MOVFF 00,6E0
9640 .................... 9640 ....................
9641 .................... #if !defined(__PCD__) 9641 .................... #if !defined(__PCD__)
9642 .................... (*p)--; 9642 .................... (*p)--;
9643 1A96: MOVLB 6 9643 1A96: MOVLB 6
9644 1A98: MOVFF 6E8,FE9 9644 1A98: MOVFF 6E8,FE9
9645 1A9C: MOVFF 6E9,FEA 9645 1A9C: MOVFF 6E9,FEA
9646 1AA0: DECF FEF,F 9646 1AA0: DECF FEF,F
9647 .................... #endif 9647 .................... #endif
9648 .................... 9648 ....................
9649 .................... #if defined(__PCD__) 9649 .................... #if defined(__PCD__)
9650 .................... data1 = *(((unsigned int8 *)(&y))+3); 9650 .................... data1 = *(((unsigned int8 *)(&y))+3);
9651 .................... data2 = *(((unsigned int8 *)(&y))+2); 9651 .................... data2 = *(((unsigned int8 *)(&y))+2);
9652 .................... rotate_left(&data1,1); 9652 .................... rotate_left(&data1,1);
9653 .................... if(bit_test(data2,7)) 9653 .................... if(bit_test(data2,7))
9654 .................... bit_set(data1,0); 9654 .................... bit_set(data1,0);
9655 .................... data1--; 9655 .................... data1--;
9656 .................... bit_clear(data2,7); 9656 .................... bit_clear(data2,7);
9657 .................... if(bit_test(data1,0)) 9657 .................... if(bit_test(data1,0))
9658 .................... bit_set(data2,7); 9658 .................... bit_set(data2,7);
9659 .................... data1 = data1 >>1; 9659 .................... data1 = data1 >>1;
9660 .................... *(((unsigned int8 *)(&y))+3) = data1; 9660 .................... *(((unsigned int8 *)(&y))+3) = data1;
9661 .................... *(((unsigned int8 *)(&y))+2) = data2; 9661 .................... *(((unsigned int8 *)(&y))+2) = data2;
9662 .................... 9662 ....................
9663 .................... #endif 9663 .................... #endif
9664 .................... } while(res != y); 9664 .................... } while(res != y);
9665 1AA2: MOVFF 6E7,6ED 9665 1AA2: MOVFF 6E7,6ED
9666 1AA6: MOVFF 6E6,6EC 9666 1AA6: MOVFF 6E6,6EC
9667 1AAA: MOVFF 6E5,6EB 9667 1AAA: MOVFF 6E5,6EB
9668 1AAE: MOVFF 6E4,6EA 9668 1AAE: MOVFF 6E4,6EA
9669 1AB2: MOVFF 6E3,6F1 9669 1AB2: MOVFF 6E3,6F1
9670 1AB6: MOVFF 6E2,6F0 9670 1AB6: MOVFF 6E2,6F0
9671 1ABA: MOVFF 6E1,6EF 9671 1ABA: MOVFF 6E1,6EF
9672 1ABE: MOVFF 6E0,6EE 9672 1ABE: MOVFF 6E0,6EE
9673 1AC2: MOVLB 0 9673 1AC2: MOVLB 0
9674 1AC4: RCALL 1948 9674 1AC4: RCALL 1948
9675 1AC6: BTFSC FD8.2 9675 1AC6: BTFSC FD8.2
9676 1AC8: BRA 1ACE 9676 1AC8: BRA 1ACE
9677 1ACA: MOVLB 6 9677 1ACA: MOVLB 6
9678 1ACC: BRA 1A2E 9678 1ACC: BRA 1A2E
9679 .................... 9679 ....................
9680 .................... return(res); 9680 .................... return(res);
9681 1ACE: MOVFF 6E4,00 9681 1ACE: MOVFF 6E4,00
9682 1AD2: MOVFF 6E5,01 9682 1AD2: MOVFF 6E5,01
9683 1AD6: MOVFF 6E6,02 9683 1AD6: MOVFF 6E6,02
9684 1ADA: MOVFF 6E7,03 9684 1ADA: MOVFF 6E7,03
9685 .................... } 9685 .................... }
9686 1ADE: GOTO 1CCA (RETURN) 9686 1ADE: GOTO 1CCA (RETURN)
9687 .................... //Overloaded functions for sqrt() for PCD 9687 .................... //Overloaded functions for sqrt() for PCD
9688 .................... // Overloaded function sqrt() for data type - Float48 9688 .................... // Overloaded function sqrt() for data type - Float48
9689 .................... #if defined(__PCD__) 9689 .................... #if defined(__PCD__)
9690 .................... float48 sqrt(float48 x) 9690 .................... float48 sqrt(float48 x)
9691 .................... { 9691 .................... {
9692 .................... float48 y, res; 9692 .................... float48 y, res;
9693 .................... unsigned int16 data1,data2; 9693 .................... unsigned int16 data1,data2;
9694 .................... BYTE *p; 9694 .................... BYTE *p;
9695 .................... 9695 ....................
9696 .................... #ifdef _ERRNO 9696 .................... #ifdef _ERRNO
9697 .................... if(x < 0) 9697 .................... if(x < 0)
9698 .................... { 9698 .................... {
9699 .................... errno=EDOM; 9699 .................... errno=EDOM;
9700 .................... } 9700 .................... }
9701 .................... #endif 9701 .................... #endif
9702 .................... 9702 ....................
9703 .................... if( x<=0.0) 9703 .................... if( x<=0.0)
9704 .................... return(0.0); 9704 .................... return(0.0);
9705 .................... 9705 ....................
9706 .................... y=x; 9706 .................... y=x;
9707 .................... 9707 ....................
9708 .................... #if !defined(__PCD__) 9708 .................... #if !defined(__PCD__)
9709 .................... p=&y; 9709 .................... p=&y;
9710 .................... (*p)=(BYTE)((((unsigned int16)(*p)) + 127) >> 1); 9710 .................... (*p)=(BYTE)((((unsigned int16)(*p)) + 127) >> 1);
9711 .................... #endif 9711 .................... #endif
9712 .................... 9712 ....................
9713 .................... #if defined(__PCD__) 9713 .................... #if defined(__PCD__)
9714 .................... p = (((unsigned int8 *)(&y))+5); 9714 .................... p = (((unsigned int8 *)(&y))+5);
9715 .................... data1 = *(((unsigned int8 *)(&y))+5); 9715 .................... data1 = *(((unsigned int8 *)(&y))+5);
9716 .................... data2 = *(((unsigned int8 *)(&y))+4); 9716 .................... data2 = *(((unsigned int8 *)(&y))+4);
9717 .................... rotate_left(&data1,1); 9717 .................... rotate_left(&data1,1);
9718 .................... if(bit_test(data2,7)) 9718 .................... if(bit_test(data2,7))
9719 .................... bit_set(data1,0); 9719 .................... bit_set(data1,0);
9720 .................... data1 = ((data1+127) >>1); 9720 .................... data1 = ((data1+127) >>1);
9721 .................... bit_clear(data2,7); 9721 .................... bit_clear(data2,7);
9722 .................... if(bit_test(data1,0)) 9722 .................... if(bit_test(data1,0))
9723 .................... bit_set(data2,7); 9723 .................... bit_set(data2,7);
9724 .................... data1 = data1 >>1; 9724 .................... data1 = data1 >>1;
9725 .................... *(((unsigned int8 *)(&y))+5) = data1; 9725 .................... *(((unsigned int8 *)(&y))+5) = data1;
9726 .................... *(((unsigned int8 *)(&y))+4) = data2; 9726 .................... *(((unsigned int8 *)(&y))+4) = data2;
9727 .................... 9727 ....................
9728 .................... #endif 9728 .................... #endif
9729 .................... 9729 ....................
9730 .................... do { 9730 .................... do {
9731 .................... res=y; 9731 .................... res=y;
9732 .................... y+=(x/y); 9732 .................... y+=(x/y);
9733 .................... 9733 ....................
9734 .................... #if !defined(__PCD__) 9734 .................... #if !defined(__PCD__)
9735 .................... (*p)--; 9735 .................... (*p)--;
9736 .................... #endif 9736 .................... #endif
9737 .................... 9737 ....................
9738 .................... data1 = *(((unsigned int8 *)(&y))+5); 9738 .................... data1 = *(((unsigned int8 *)(&y))+5);
9739 .................... data2 = *(((unsigned int8 *)(&y))+4); 9739 .................... data2 = *(((unsigned int8 *)(&y))+4);
9740 .................... rotate_left(&data1,1); 9740 .................... rotate_left(&data1,1);
9741 .................... if(bit_test(data2,7)) 9741 .................... if(bit_test(data2,7))
9742 .................... bit_set(data1,0); 9742 .................... bit_set(data1,0);
9743 .................... data1--; 9743 .................... data1--;
9744 .................... bit_clear(data2,7); 9744 .................... bit_clear(data2,7);
9745 .................... if(bit_test(data1,0)) 9745 .................... if(bit_test(data1,0))
9746 .................... bit_set(data2,7); 9746 .................... bit_set(data2,7);
9747 .................... data1 = data1 >>1; 9747 .................... data1 = data1 >>1;
9748 .................... *(((unsigned int8 *)(&y))+5) = data1; 9748 .................... *(((unsigned int8 *)(&y))+5) = data1;
9749 .................... *(((unsigned int8 *)(&y))+4) = data2; 9749 .................... *(((unsigned int8 *)(&y))+4) = data2;
9750 .................... 9750 ....................
9751 .................... } while(res != y); 9751 .................... } while(res != y);
9752 .................... 9752 ....................
9753 .................... return(res); 9753 .................... return(res);
9754 .................... } 9754 .................... }
9755 .................... 9755 ....................
9756 .................... // Overloaded function sqrt() for data type - Float64 9756 .................... // Overloaded function sqrt() for data type - Float64
9757 .................... float64 sqrt(float64 x) 9757 .................... float64 sqrt(float64 x)
9758 .................... { 9758 .................... {
9759 .................... float64 y, res; 9759 .................... float64 y, res;
9760 .................... unsigned int16 *p; 9760 .................... unsigned int16 *p;
9761 .................... unsigned int16 temp1,temp2; 9761 .................... unsigned int16 temp1,temp2;
9762 .................... 9762 ....................
9763 .................... #ifdef _ERRNO 9763 .................... #ifdef _ERRNO
9764 .................... if(x < 0) 9764 .................... if(x < 0)
9765 .................... { 9765 .................... {
9766 .................... errno=EDOM; 9766 .................... errno=EDOM;
9767 .................... } 9767 .................... }
9768 .................... #endif 9768 .................... #endif
9769 .................... 9769 ....................
9770 .................... if( x<=0.0) 9770 .................... if( x<=0.0)
9771 .................... return(0.0); 9771 .................... return(0.0);
9772 .................... 9772 ....................
9773 .................... y=x; 9773 .................... y=x;
9774 .................... p= (((unsigned int16 *)(&y))+3); 9774 .................... p= (((unsigned int16 *)(&y))+3);
9775 .................... temp1 = *p; 9775 .................... temp1 = *p;
9776 .................... temp2 = *p; 9776 .................... temp2 = *p;
9777 .................... bit_clear(temp1,15); 9777 .................... bit_clear(temp1,15);
9778 .................... temp1 = (temp1>>4)+1023; 9778 .................... temp1 = (temp1>>4)+1023;
9779 .................... temp1 = temp1 >> 1; 9779 .................... temp1 = temp1 >> 1;
9780 .................... temp1 = (temp1<<4) & 0xFFF0; 9780 .................... temp1 = (temp1<<4) & 0xFFF0;
9781 .................... if(bit_test(temp2,15)) 9781 .................... if(bit_test(temp2,15))
9782 .................... bit_set(temp1,15); 9782 .................... bit_set(temp1,15);
9783 .................... temp2 = temp2 & 0x000F; 9783 .................... temp2 = temp2 & 0x000F;
9784 .................... temp1 ^= temp2; 9784 .................... temp1 ^= temp2;
9785 .................... 9785 ....................
9786 .................... (*p) = temp1; 9786 .................... (*p) = temp1;
9787 .................... 9787 ....................
9788 .................... do { 9788 .................... do {
9789 .................... res=y; 9789 .................... res=y;
9790 .................... y+=(x/y); 9790 .................... y+=(x/y);
9791 .................... temp1 = *p; 9791 .................... temp1 = *p;
9792 .................... temp2 = *p; 9792 .................... temp2 = *p;
9793 .................... bit_clear(temp1,15); 9793 .................... bit_clear(temp1,15);
9794 .................... temp1 = (temp1>>4); 9794 .................... temp1 = (temp1>>4);
9795 .................... temp1--; 9795 .................... temp1--;
9796 .................... temp1 = (temp1<<4) & 0xFFF0; 9796 .................... temp1 = (temp1<<4) & 0xFFF0;
9797 .................... if(bit_test(temp2,15)) 9797 .................... if(bit_test(temp2,15))
9798 .................... bit_set(temp1,15); 9798 .................... bit_set(temp1,15);
9799 .................... temp2 = temp2 & 0x000F; 9799 .................... temp2 = temp2 & 0x000F;
9800 .................... temp1 ^= temp2; 9800 .................... temp1 ^= temp2;
9801 .................... (*p) = temp1; 9801 .................... (*p) = temp1;
9802 .................... 9802 ....................
9803 .................... } while(res != y); 9803 .................... } while(res != y);
9804 .................... 9804 ....................
9805 .................... return(res); 9805 .................... return(res);
9806 .................... } 9806 .................... }
9807 .................... #endif 9807 .................... #endif
9808 .................... 9808 ....................
9809 .................... ////////////////////////////// Trig Functions ////////////////////////////// 9809 .................... ////////////////////////////// Trig Functions //////////////////////////////
9810 .................... #ifdef PI_DIV_BY_TWO 9810 .................... #ifdef PI_DIV_BY_TWO
9811 .................... #undef PI_DIV_BY_TWO 9811 .................... #undef PI_DIV_BY_TWO
9812 .................... #endif 9812 .................... #endif
9813 .................... #define PI_DIV_BY_TWO 1.5707963267948966 9813 .................... #define PI_DIV_BY_TWO 1.5707963267948966
9814 .................... #ifdef TWOBYPI 9814 .................... #ifdef TWOBYPI
9815 .................... #undef TWOBYPI 9815 .................... #undef TWOBYPI
9816 .................... #define TWOBYPI 0.6366197723675813 9816 .................... #define TWOBYPI 0.6366197723675813
9817 .................... #endif 9817 .................... #endif
9818 .................... //////////////////////////////////////////////////////////////////////////// 9818 .................... ////////////////////////////////////////////////////////////////////////////
9819 .................... // float cos(float x) 9819 .................... // float cos(float x)
9820 .................... //////////////////////////////////////////////////////////////////////////// 9820 .................... ////////////////////////////////////////////////////////////////////////////
9821 .................... // Description : returns the cosine value of the angle x, which is in radian 9821 .................... // Description : returns the cosine value of the angle x, which is in radian
9822 .................... // Date : 9/20/2001 9822 .................... // Date : 9/20/2001
9823 .................... // 9823 .................... //
9824 .................... float32 cos(float32 x) 9824 .................... float32 cos(float32 x)
9825 .................... { 9825 .................... {
9826 .................... float32 y, t, t2 = 1.0; 9826 .................... float32 y, t, t2 = 1.0;
9827 .................... unsigned int8 quad, i; 9827 .................... unsigned int8 quad, i;
9828 .................... float32 frac; 9828 .................... float32 frac;
9829 .................... float32 p[4] = { 9829 .................... float32 p[4] = {
9830 .................... -0.499999993585, 9830 .................... -0.499999993585,
9831 .................... 0.041666636258, 9831 .................... 0.041666636258,
9832 .................... -0.0013888361399, 9832 .................... -0.0013888361399,
9833 .................... 0.00002476016134 9833 .................... 0.00002476016134
9834 .................... }; 9834 .................... };
9835 .................... 9835 ....................
9836 .................... if (x < 0) x = -x; // absolute value of input 9836 .................... if (x < 0) x = -x; // absolute value of input
9837 .................... 9837 ....................
9838 .................... quad = (unsigned int8)(x / PI_DIV_BY_TWO); // quadrant 9838 .................... quad = (unsigned int8)(x / PI_DIV_BY_TWO); // quadrant
9839 .................... frac = (x / PI_DIV_BY_TWO) - quad; // fractional part of input 9839 .................... frac = (x / PI_DIV_BY_TWO) - quad; // fractional part of input
9840 .................... quad = quad % 4; // quadrant (0 to 3) 9840 .................... quad = quad % 4; // quadrant (0 to 3)
9841 .................... 9841 ....................
9842 .................... if (quad == 0 || quad == 2) 9842 .................... if (quad == 0 || quad == 2)
9843 .................... t = frac * PI_DIV_BY_TWO; 9843 .................... t = frac * PI_DIV_BY_TWO;
9844 .................... else if (quad == 1) 9844 .................... else if (quad == 1)
9845 .................... t = (1-frac) * PI_DIV_BY_TWO; 9845 .................... t = (1-frac) * PI_DIV_BY_TWO;
9846 .................... else // should be 3 9846 .................... else // should be 3
9847 .................... t = (frac-1) * PI_DIV_BY_TWO; 9847 .................... t = (frac-1) * PI_DIV_BY_TWO;
9848 .................... 9848 ....................
9849 .................... y = 0.999999999781; 9849 .................... y = 0.999999999781;
9850 .................... t = t * t; 9850 .................... t = t * t;
9851 .................... for (i = 0; i <= 3; i++) 9851 .................... for (i = 0; i <= 3; i++)
9852 .................... { 9852 .................... {
9853 .................... t2 = t2 * t; 9853 .................... t2 = t2 * t;
9854 .................... y = y + p[i] * t2; 9854 .................... y = y + p[i] * t2;
9855 .................... } 9855 .................... }
9856 .................... 9856 ....................
9857 .................... if (quad == 2 || quad == 1) 9857 .................... if (quad == 2 || quad == 1)
9858 .................... y = -y; // correct sign 9858 .................... y = -y; // correct sign
9859 .................... 9859 ....................
9860 .................... return (y); 9860 .................... return (y);
9861 .................... } 9861 .................... }
9862 .................... 9862 ....................
9863 .................... 9863 ....................
9864 .................... //Overloaded functions for cos() for PCD 9864 .................... //Overloaded functions for cos() for PCD
9865 .................... // Overloaded function cos() for data type - Float48 9865 .................... // Overloaded function cos() for data type - Float48
9866 .................... #if defined(__PCD__) 9866 .................... #if defined(__PCD__)
9867 .................... float48 cos(float48 x) 9867 .................... float48 cos(float48 x)
9868 .................... { 9868 .................... {
9869 .................... float48 y, t, t2 = 1.0; 9869 .................... float48 y, t, t2 = 1.0;
9870 .................... unsigned int8 quad, i; 9870 .................... unsigned int8 quad, i;
9871 .................... float48 frac; 9871 .................... float48 frac;
9872 .................... float48 p[4] = { 9872 .................... float48 p[4] = {
9873 .................... -0.499999993585, 9873 .................... -0.499999993585,
9874 .................... 0.041666636258, 9874 .................... 0.041666636258,
9875 .................... -0.0013888361399, 9875 .................... -0.0013888361399,
9876 .................... 0.00002476016134 9876 .................... 0.00002476016134
9877 .................... }; 9877 .................... };
9878 .................... 9878 ....................
9879 .................... if (x < 0) x = -x; // absolute value of input 9879 .................... if (x < 0) x = -x; // absolute value of input
9880 .................... 9880 ....................
9881 .................... quad = (unsigned int8)(x / PI_DIV_BY_TWO); // quadrant 9881 .................... quad = (unsigned int8)(x / PI_DIV_BY_TWO); // quadrant
9882 .................... frac = (x / PI_DIV_BY_TWO) - quad; // fractional part of input 9882 .................... frac = (x / PI_DIV_BY_TWO) - quad; // fractional part of input
9883 .................... quad = quad % 4; // quadrant (0 to 3) 9883 .................... quad = quad % 4; // quadrant (0 to 3)
9884 .................... 9884 ....................
9885 .................... if (quad == 0 || quad == 2) 9885 .................... if (quad == 0 || quad == 2)
9886 .................... t = frac * PI_DIV_BY_TWO; 9886 .................... t = frac * PI_DIV_BY_TWO;
9887 .................... else if (quad == 1) 9887 .................... else if (quad == 1)
9888 .................... t = (1-frac) * PI_DIV_BY_TWO; 9888 .................... t = (1-frac) * PI_DIV_BY_TWO;
9889 .................... else // should be 3 9889 .................... else // should be 3
9890 .................... t = (frac-1) * PI_DIV_BY_TWO; 9890 .................... t = (frac-1) * PI_DIV_BY_TWO;
9891 .................... 9891 ....................
9892 .................... y = 0.999999999781; 9892 .................... y = 0.999999999781;
9893 .................... t = t * t; 9893 .................... t = t * t;
9894 .................... for (i = 0; i <= 3; i++) 9894 .................... for (i = 0; i <= 3; i++)
9895 .................... { 9895 .................... {
9896 .................... t2 = t2 * t; 9896 .................... t2 = t2 * t;
9897 .................... y = y + p[i] * t2; 9897 .................... y = y + p[i] * t2;
9898 .................... } 9898 .................... }
9899 .................... 9899 ....................
9900 .................... if (quad == 2 || quad == 1) 9900 .................... if (quad == 2 || quad == 1)
9901 .................... y = -y; // correct sign 9901 .................... y = -y; // correct sign
9902 .................... 9902 ....................
9903 .................... return (y); 9903 .................... return (y);
9904 .................... } 9904 .................... }
9905 .................... 9905 ....................
9906 .................... // Overloaded function cos() for data type - Float48 9906 .................... // Overloaded function cos() for data type - Float48
9907 .................... float64 cos(float64 x) 9907 .................... float64 cos(float64 x)
9908 .................... { 9908 .................... {
9909 .................... float64 y, t, t2 = 1.0; 9909 .................... float64 y, t, t2 = 1.0;
9910 .................... unsigned int8 quad, i; 9910 .................... unsigned int8 quad, i;
9911 .................... float64 frac; 9911 .................... float64 frac;
9912 .................... float64 p[4] = { 9912 .................... float64 p[4] = {
9913 .................... -0.499999993585, 9913 .................... -0.499999993585,
9914 .................... 0.041666636258, 9914 .................... 0.041666636258,
9915 .................... -0.0013888361399, 9915 .................... -0.0013888361399,
9916 .................... 0.00002476016134 9916 .................... 0.00002476016134
9917 .................... }; 9917 .................... };
9918 .................... 9918 ....................
9919 .................... if (x < 0) x = -x; // absolute value of input 9919 .................... if (x < 0) x = -x; // absolute value of input
9920 .................... 9920 ....................
9921 .................... quad = (unsigned int8)(x / PI_DIV_BY_TWO); // quadrant 9921 .................... quad = (unsigned int8)(x / PI_DIV_BY_TWO); // quadrant
9922 .................... frac = (x / PI_DIV_BY_TWO) - quad; // fractional part of input 9922 .................... frac = (x / PI_DIV_BY_TWO) - quad; // fractional part of input
9923 .................... quad = quad % 4; // quadrant (0 to 3) 9923 .................... quad = quad % 4; // quadrant (0 to 3)
9924 .................... 9924 ....................
9925 .................... if (quad == 0 || quad == 2) 9925 .................... if (quad == 0 || quad == 2)
9926 .................... t = frac * PI_DIV_BY_TWO; 9926 .................... t = frac * PI_DIV_BY_TWO;
9927 .................... else if (quad == 1) 9927 .................... else if (quad == 1)
9928 .................... t = (1-frac) * PI_DIV_BY_TWO; 9928 .................... t = (1-frac) * PI_DIV_BY_TWO;
9929 .................... else // should be 3 9929 .................... else // should be 3
9930 .................... t = (frac-1) * PI_DIV_BY_TWO; 9930 .................... t = (frac-1) * PI_DIV_BY_TWO;
9931 .................... 9931 ....................
9932 .................... y = 0.999999999781; 9932 .................... y = 0.999999999781;
9933 .................... t = t * t; 9933 .................... t = t * t;
9934 .................... for (i = 0; i <= 3; i++) 9934 .................... for (i = 0; i <= 3; i++)
9935 .................... { 9935 .................... {
9936 .................... t2 = t2 * t; 9936 .................... t2 = t2 * t;
9937 .................... y = y + p[i] * t2; 9937 .................... y = y + p[i] * t2;
9938 .................... } 9938 .................... }
9939 .................... 9939 ....................
9940 .................... if (quad == 2 || quad == 1) 9940 .................... if (quad == 2 || quad == 1)
9941 .................... y = -y; // correct sign 9941 .................... y = -y; // correct sign
9942 .................... 9942 ....................
9943 .................... return (y); 9943 .................... return (y);
9944 .................... } 9944 .................... }
9945 .................... 9945 ....................
9946 .................... #endif 9946 .................... #endif
9947 .................... 9947 ....................
9948 .................... //////////////////////////////////////////////////////////////////////////// 9948 .................... ////////////////////////////////////////////////////////////////////////////
9949 .................... // float sin(float x) 9949 .................... // float sin(float x)
9950 .................... //////////////////////////////////////////////////////////////////////////// 9950 .................... ////////////////////////////////////////////////////////////////////////////
9951 .................... // Description : returns the sine value of the angle x, which is in radian 9951 .................... // Description : returns the sine value of the angle x, which is in radian
9952 .................... // Date : 9/20/2001 9952 .................... // Date : 9/20/2001
9953 .................... // 9953 .................... //
9954 .................... float32 sin(float32 x) 9954 .................... float32 sin(float32 x)
9955 .................... { 9955 .................... {
9956 .................... return cos(x - PI_DIV_BY_TWO); 9956 .................... return cos(x - PI_DIV_BY_TWO);
9957 .................... } 9957 .................... }
9958 .................... 9958 ....................
9959 .................... //Overloaded functions for sin() for PCD 9959 .................... //Overloaded functions for sin() for PCD
9960 .................... // Overloaded function sin() for data type - Float48 9960 .................... // Overloaded function sin() for data type - Float48
9961 .................... #if defined(__PCD__) 9961 .................... #if defined(__PCD__)
9962 .................... float48 sin(float48 x) 9962 .................... float48 sin(float48 x)
9963 .................... { 9963 .................... {
9964 .................... return cos(x - PI_DIV_BY_TWO); 9964 .................... return cos(x - PI_DIV_BY_TWO);
9965 .................... } 9965 .................... }
9966 .................... 9966 ....................
9967 .................... // Overloaded function sin() for data type - Float48 9967 .................... // Overloaded function sin() for data type - Float48
9968 .................... float64 sin(float64 x) 9968 .................... float64 sin(float64 x)
9969 .................... { 9969 .................... {
9970 .................... return cos(x - PI_DIV_BY_TWO); 9970 .................... return cos(x - PI_DIV_BY_TWO);
9971 .................... } 9971 .................... }
9972 .................... #endif 9972 .................... #endif
9973 .................... 9973 ....................
9974 .................... //////////////////////////////////////////////////////////////////////////// 9974 .................... ////////////////////////////////////////////////////////////////////////////
9975 .................... // float tan(float x) 9975 .................... // float tan(float x)
9976 .................... //////////////////////////////////////////////////////////////////////////// 9976 .................... ////////////////////////////////////////////////////////////////////////////
9977 .................... // Description : returns the tangent value of the angle x, which is in radian 9977 .................... // Description : returns the tangent value of the angle x, which is in radian
9978 .................... // Date : 9/20/2001 9978 .................... // Date : 9/20/2001
9979 .................... // 9979 .................... //
9980 .................... float32 tan(float32 x) 9980 .................... float32 tan(float32 x)
9981 .................... { 9981 .................... {
9982 .................... float32 c, s; 9982 .................... float32 c, s;
9983 .................... 9983 ....................
9984 .................... c = cos(x); 9984 .................... c = cos(x);
9985 .................... if (c == 0.0) 9985 .................... if (c == 0.0)
9986 .................... return (1.0e+36); 9986 .................... return (1.0e+36);
9987 .................... 9987 ....................
9988 .................... s = sin(x); 9988 .................... s = sin(x);
9989 .................... return(s/c); 9989 .................... return(s/c);
9990 .................... } 9990 .................... }
9991 .................... //Overloaded functions for tan() for PCD 9991 .................... //Overloaded functions for tan() for PCD
9992 .................... // Overloaded function tan() for data type - Float48 9992 .................... // Overloaded function tan() for data type - Float48
9993 .................... #if defined(__PCD__) 9993 .................... #if defined(__PCD__)
9994 .................... float48 tan(float48 x) 9994 .................... float48 tan(float48 x)
9995 .................... { 9995 .................... {
9996 .................... float48 c, s; 9996 .................... float48 c, s;
9997 .................... 9997 ....................
9998 .................... c = cos(x); 9998 .................... c = cos(x);
9999 .................... if (c == 0.0) 9999 .................... if (c == 0.0)
10000 .................... return (1.0e+36); 10000 .................... return (1.0e+36);
10001 .................... 10001 ....................
10002 .................... s = sin(x); 10002 .................... s = sin(x);
10003 .................... return(s/c); 10003 .................... return(s/c);
10004 .................... } 10004 .................... }
10005 .................... 10005 ....................
10006 .................... // Overloaded function tan() for data type - Float48 10006 .................... // Overloaded function tan() for data type - Float48
10007 .................... float64 tan(float64 x) 10007 .................... float64 tan(float64 x)
10008 .................... { 10008 .................... {
10009 .................... float64 c, s; 10009 .................... float64 c, s;
10010 .................... 10010 ....................
10011 .................... c = cos(x); 10011 .................... c = cos(x);
10012 .................... if (c == 0.0) 10012 .................... if (c == 0.0)
10013 .................... return (1.0e+36); 10013 .................... return (1.0e+36);
10014 .................... 10014 ....................
10015 .................... s = sin(x); 10015 .................... s = sin(x);
10016 .................... return(s/c); 10016 .................... return(s/c);
10017 .................... } 10017 .................... }
10018 .................... #endif 10018 .................... #endif
10019 .................... 10019 ....................
10020 .................... float32 const pas[3] = {0.49559947, -4.6145309, 5.6036290}; 10020 .................... float32 const pas[3] = {0.49559947, -4.6145309, 5.6036290};
10021 .................... float32 const qas[3] = {1.0000000, -5.5484666, 5.6036290}; 10021 .................... float32 const qas[3] = {1.0000000, -5.5484666, 5.6036290};
10022 .................... 10022 ....................
10023 .................... float32 ASIN_COS(float32 x, unsigned int8 n) 10023 .................... float32 ASIN_COS(float32 x, unsigned int8 n)
10024 .................... { 10024 .................... {
10025 .................... float32 y, res, r, y2; 10025 .................... float32 y, res, r, y2;
10026 .................... int1 s; 10026 .................... int1 s;
10027 .................... #ifdef _ERRNO 10027 .................... #ifdef _ERRNO
10028 .................... if(x <-1 || x > 1) 10028 .................... if(x <-1 || x > 1)
10029 .................... { 10029 .................... {
10030 .................... errno=EDOM; 10030 .................... errno=EDOM;
10031 .................... } 10031 .................... }
10032 .................... #endif 10032 .................... #endif
10033 .................... s = 0; 10033 .................... s = 0;
10034 .................... y = x; 10034 .................... y = x;
10035 .................... 10035 ....................
10036 .................... if (x < 0) 10036 .................... if (x < 0)
10037 .................... { 10037 .................... {
10038 .................... s = 1; 10038 .................... s = 1;
10039 .................... y = -y; 10039 .................... y = -y;
10040 .................... } 10040 .................... }
10041 .................... 10041 ....................
10042 .................... if (y > 0.5) 10042 .................... if (y > 0.5)
10043 .................... { 10043 .................... {
10044 .................... y = sqrt((1.0 - y)/2.0); 10044 .................... y = sqrt((1.0 - y)/2.0);
10045 .................... n += 2; 10045 .................... n += 2;
10046 .................... } 10046 .................... }
10047 .................... 10047 ....................
10048 .................... y2=y*y; 10048 .................... y2=y*y;
10049 .................... 10049 ....................
10050 .................... res = pas[0]*y2 + pas[1]; 10050 .................... res = pas[0]*y2 + pas[1];
10051 .................... res = res*y2 + pas[2]; 10051 .................... res = res*y2 + pas[2];
10052 .................... 10052 ....................
10053 .................... r = qas[0]*y2 + qas[1]; 10053 .................... r = qas[0]*y2 + qas[1];
10054 .................... r = r*y2 + qas[2]; 10054 .................... r = r*y2 + qas[2];
10055 .................... 10055 ....................
10056 .................... res = y*res/r; 10056 .................... res = y*res/r;
10057 .................... 10057 ....................
10058 .................... if (n & 2) // |x| > 0.5 10058 .................... if (n & 2) // |x| > 0.5
10059 .................... res = PI_DIV_BY_TWO - 2.0*res; 10059 .................... res = PI_DIV_BY_TWO - 2.0*res;
10060 .................... if (s) 10060 .................... if (s)
10061 .................... res = -res; 10061 .................... res = -res;
10062 .................... if (n & 1) // take arccos 10062 .................... if (n & 1) // take arccos
10063 .................... res = PI_DIV_BY_TWO - res; 10063 .................... res = PI_DIV_BY_TWO - res;
10064 .................... 10064 ....................
10065 .................... return(res); 10065 .................... return(res);
10066 .................... } 10066 .................... }
10067 .................... 10067 ....................
10068 .................... //Overloaded functions for ASIN_COS() for PCD 10068 .................... //Overloaded functions for ASIN_COS() for PCD
10069 .................... // Overloaded function ASIN_COS() for data type - Float48 10069 .................... // Overloaded function ASIN_COS() for data type - Float48
10070 .................... #if defined(__PCD__) 10070 .................... #if defined(__PCD__)
10071 .................... float48 ASIN_COS(float48 x, unsigned int8 n) 10071 .................... float48 ASIN_COS(float48 x, unsigned int8 n)
10072 .................... { 10072 .................... {
10073 .................... float48 y, res, r, y2; 10073 .................... float48 y, res, r, y2;
10074 .................... int1 s; 10074 .................... int1 s;
10075 .................... #ifdef _ERRNO 10075 .................... #ifdef _ERRNO
10076 .................... if(x <-1 || x > 1) 10076 .................... if(x <-1 || x > 1)
10077 .................... { 10077 .................... {
10078 .................... errno=EDOM; 10078 .................... errno=EDOM;
10079 .................... } 10079 .................... }
10080 .................... #endif 10080 .................... #endif
10081 .................... s = 0; 10081 .................... s = 0;
10082 .................... y = x; 10082 .................... y = x;
10083 .................... 10083 ....................
10084 .................... if (x < 0) 10084 .................... if (x < 0)
10085 .................... { 10085 .................... {
10086 .................... s = 1; 10086 .................... s = 1;
10087 .................... y = -y; 10087 .................... y = -y;
10088 .................... } 10088 .................... }
10089 .................... 10089 ....................
10090 .................... if (y > 0.5) 10090 .................... if (y > 0.5)
10091 .................... { 10091 .................... {
10092 .................... y = sqrt((1.0 - y)/2.0); 10092 .................... y = sqrt((1.0 - y)/2.0);
10093 .................... n += 2; 10093 .................... n += 2;
10094 .................... } 10094 .................... }
10095 .................... 10095 ....................
10096 .................... y2=y*y; 10096 .................... y2=y*y;
10097 .................... 10097 ....................
10098 .................... res = pas[0]*y2 + pas[1]; 10098 .................... res = pas[0]*y2 + pas[1];
10099 .................... res = res*y2 + pas[2]; 10099 .................... res = res*y2 + pas[2];
10100 .................... 10100 ....................
10101 .................... r = qas[0]*y2 + qas[1]; 10101 .................... r = qas[0]*y2 + qas[1];
10102 .................... r = r*y2 + qas[2]; 10102 .................... r = r*y2 + qas[2];
10103 .................... 10103 ....................
10104 .................... res = y*res/r; 10104 .................... res = y*res/r;
10105 .................... 10105 ....................
10106 .................... if (n & 2) // |x| > 0.5 10106 .................... if (n & 2) // |x| > 0.5
10107 .................... res = PI_DIV_BY_TWO - 2.0*res; 10107 .................... res = PI_DIV_BY_TWO - 2.0*res;
10108 .................... if (s) 10108 .................... if (s)
10109 .................... res = -res; 10109 .................... res = -res;
10110 .................... if (n & 1) // take arccos 10110 .................... if (n & 1) // take arccos
10111 .................... res = PI_DIV_BY_TWO - res; 10111 .................... res = PI_DIV_BY_TWO - res;
10112 .................... 10112 ....................
10113 .................... return(res); 10113 .................... return(res);
10114 .................... } 10114 .................... }
10115 .................... 10115 ....................
10116 .................... // Overloaded function ASIN_COS() for data type - Float64 10116 .................... // Overloaded function ASIN_COS() for data type - Float64
10117 .................... float64 ASIN_COS(float64 x, unsigned int8 n) 10117 .................... float64 ASIN_COS(float64 x, unsigned int8 n)
10118 .................... { 10118 .................... {
10119 .................... float64 y, res, r, y2; 10119 .................... float64 y, res, r, y2;
10120 .................... int1 s; 10120 .................... int1 s;
10121 .................... #ifdef _ERRNO 10121 .................... #ifdef _ERRNO
10122 .................... if(x <-1 || x > 1) 10122 .................... if(x <-1 || x > 1)
10123 .................... { 10123 .................... {
10124 .................... errno=EDOM; 10124 .................... errno=EDOM;
10125 .................... } 10125 .................... }
10126 .................... #endif 10126 .................... #endif
10127 .................... s = 0; 10127 .................... s = 0;
10128 .................... y = x; 10128 .................... y = x;
10129 .................... 10129 ....................
10130 .................... if (x < 0) 10130 .................... if (x < 0)
10131 .................... { 10131 .................... {
10132 .................... s = 1; 10132 .................... s = 1;
10133 .................... y = -y; 10133 .................... y = -y;
10134 .................... } 10134 .................... }
10135 .................... 10135 ....................
10136 .................... if (y > 0.5) 10136 .................... if (y > 0.5)
10137 .................... { 10137 .................... {
10138 .................... y = sqrt((1.0 - y)/2.0); 10138 .................... y = sqrt((1.0 - y)/2.0);
10139 .................... n += 2; 10139 .................... n += 2;
10140 .................... } 10140 .................... }
10141 .................... 10141 ....................
10142 .................... y2=y*y; 10142 .................... y2=y*y;
10143 .................... 10143 ....................
10144 .................... res = pas[0]*y2 + pas[1]; 10144 .................... res = pas[0]*y2 + pas[1];
10145 .................... res = res*y2 + pas[2]; 10145 .................... res = res*y2 + pas[2];
10146 .................... 10146 ....................
10147 .................... r = qas[0]*y2 + qas[1]; 10147 .................... r = qas[0]*y2 + qas[1];
10148 .................... r = r*y2 + qas[2]; 10148 .................... r = r*y2 + qas[2];
10149 .................... 10149 ....................
10150 .................... res = y*res/r; 10150 .................... res = y*res/r;
10151 .................... 10151 ....................
10152 .................... if (n & 2) // |x| > 0.5 10152 .................... if (n & 2) // |x| > 0.5
10153 .................... res = PI_DIV_BY_TWO - 2.0*res; 10153 .................... res = PI_DIV_BY_TWO - 2.0*res;
10154 .................... if (s) 10154 .................... if (s)
10155 .................... res = -res; 10155 .................... res = -res;
10156 .................... if (n & 1) // take arccos 10156 .................... if (n & 1) // take arccos
10157 .................... res = PI_DIV_BY_TWO - res; 10157 .................... res = PI_DIV_BY_TWO - res;
10158 .................... 10158 ....................
10159 .................... return(res); 10159 .................... return(res);
10160 .................... } 10160 .................... }
10161 .................... #endif 10161 .................... #endif
10162 .................... 10162 ....................
10163 .................... //////////////////////////////////////////////////////////////////////////// 10163 .................... ////////////////////////////////////////////////////////////////////////////
10164 .................... // float asin(float x) 10164 .................... // float asin(float x)
10165 .................... //////////////////////////////////////////////////////////////////////////// 10165 .................... ////////////////////////////////////////////////////////////////////////////
10166 .................... // Description : returns the arcsine value of the value x. 10166 .................... // Description : returns the arcsine value of the value x.
10167 .................... // Date : N/A 10167 .................... // Date : N/A
10168 .................... // 10168 .................... //
10169 .................... float32 asin(float32 x) 10169 .................... float32 asin(float32 x)
10170 .................... { 10170 .................... {
10171 .................... float32 r; 10171 .................... float32 r;
10172 .................... 10172 ....................
10173 .................... r = ASIN_COS(x, 0); 10173 .................... r = ASIN_COS(x, 0);
10174 .................... return(r); 10174 .................... return(r);
10175 .................... } 10175 .................... }
10176 .................... //Overloaded functions for asin() for PCD 10176 .................... //Overloaded functions for asin() for PCD
10177 .................... // Overloaded function asin() for data type - Float48 10177 .................... // Overloaded function asin() for data type - Float48
10178 .................... #if defined(__PCD__) 10178 .................... #if defined(__PCD__)
10179 .................... float48 asin(float48 x) 10179 .................... float48 asin(float48 x)
10180 .................... { 10180 .................... {
10181 .................... float48 r; 10181 .................... float48 r;
10182 .................... 10182 ....................
10183 .................... r = ASIN_COS(x, 0); 10183 .................... r = ASIN_COS(x, 0);
10184 .................... return(r); 10184 .................... return(r);
10185 .................... } 10185 .................... }
10186 .................... 10186 ....................
10187 .................... // Overloaded function asin() for data type - Float64 10187 .................... // Overloaded function asin() for data type - Float64
10188 .................... float64 asin(float64 x) 10188 .................... float64 asin(float64 x)
10189 .................... { 10189 .................... {
10190 .................... float64 r; 10190 .................... float64 r;
10191 .................... 10191 ....................
10192 .................... r = ASIN_COS(x, 0); 10192 .................... r = ASIN_COS(x, 0);
10193 .................... return(r); 10193 .................... return(r);
10194 .................... } 10194 .................... }
10195 .................... #endif 10195 .................... #endif
10196 .................... 10196 ....................
10197 .................... //////////////////////////////////////////////////////////////////////////// 10197 .................... ////////////////////////////////////////////////////////////////////////////
10198 .................... // float acos(float x) 10198 .................... // float acos(float x)
10199 .................... //////////////////////////////////////////////////////////////////////////// 10199 .................... ////////////////////////////////////////////////////////////////////////////
10200 .................... // Description : returns the arccosine value of the value x. 10200 .................... // Description : returns the arccosine value of the value x.
10201 .................... // Date : N/A 10201 .................... // Date : N/A
10202 .................... // 10202 .................... //
10203 .................... float32 acos(float32 x) 10203 .................... float32 acos(float32 x)
10204 .................... { 10204 .................... {
10205 .................... float32 r; 10205 .................... float32 r;
10206 .................... 10206 ....................
10207 .................... r = ASIN_COS(x, 1); 10207 .................... r = ASIN_COS(x, 1);
10208 .................... return(r); 10208 .................... return(r);
10209 .................... } 10209 .................... }
10210 .................... //Overloaded functions for acos() for PCD 10210 .................... //Overloaded functions for acos() for PCD
10211 .................... // Overloaded function acos() for data type - Float48 10211 .................... // Overloaded function acos() for data type - Float48
10212 .................... #if defined(__PCD__) 10212 .................... #if defined(__PCD__)
10213 .................... float48 acos(float48 x) 10213 .................... float48 acos(float48 x)
10214 .................... { 10214 .................... {
10215 .................... float48 r; 10215 .................... float48 r;
10216 .................... 10216 ....................
10217 .................... r = ASIN_COS(x, 1); 10217 .................... r = ASIN_COS(x, 1);
10218 .................... return(r); 10218 .................... return(r);
10219 .................... } 10219 .................... }
10220 .................... 10220 ....................
10221 .................... // Overloaded function acos() for data type - Float64 10221 .................... // Overloaded function acos() for data type - Float64
10222 .................... float64 acos(float64 x) 10222 .................... float64 acos(float64 x)
10223 .................... { 10223 .................... {
10224 .................... float64 r; 10224 .................... float64 r;
10225 .................... 10225 ....................
10226 .................... r = ASIN_COS(x, 1); 10226 .................... r = ASIN_COS(x, 1);
10227 .................... return(r); 10227 .................... return(r);
10228 .................... } 10228 .................... }
10229 .................... #endif 10229 .................... #endif
10230 .................... 10230 ....................
10231 .................... float32 const pat[4] = {0.17630401, 5.6710795, 22.376096, 19.818457}; 10231 .................... float32 const pat[4] = {0.17630401, 5.6710795, 22.376096, 19.818457};
10232 .................... float32 const qat[4] = {1.0000000, 11.368190, 28.982246, 19.818457}; 10232 .................... float32 const qat[4] = {1.0000000, 11.368190, 28.982246, 19.818457};
10233 .................... 10233 ....................
10234 .................... //////////////////////////////////////////////////////////////////////////// 10234 .................... ////////////////////////////////////////////////////////////////////////////
10235 .................... // float atan(float x) 10235 .................... // float atan(float x)
10236 .................... //////////////////////////////////////////////////////////////////////////// 10236 .................... ////////////////////////////////////////////////////////////////////////////
10237 .................... // Description : returns the arctangent value of the value x. 10237 .................... // Description : returns the arctangent value of the value x.
10238 .................... // Date : N/A 10238 .................... // Date : N/A
10239 .................... // 10239 .................... //
10240 .................... float32 atan(float32 x) 10240 .................... float32 atan(float32 x)
10241 .................... { 10241 .................... {
10242 .................... float32 y, res, r; 10242 .................... float32 y, res, r;
10243 .................... int1 s, flag; 10243 .................... int1 s, flag;
10244 .................... 10244 ....................
10245 .................... s = 0; 10245 .................... s = 0;
10246 .................... flag = 0; 10246 .................... flag = 0;
10247 .................... y = x; 10247 .................... y = x;
10248 .................... 10248 ....................
10249 .................... if (x < 0) 10249 .................... if (x < 0)
10250 .................... { 10250 .................... {
10251 .................... s = 1; 10251 .................... s = 1;
10252 .................... y = -y; 10252 .................... y = -y;
10253 .................... } 10253 .................... }
10254 .................... 10254 ....................
10255 .................... if (y > 1.0) 10255 .................... if (y > 1.0)
10256 .................... { 10256 .................... {
10257 .................... y = 1.0/y; 10257 .................... y = 1.0/y;
10258 .................... flag = 1; 10258 .................... flag = 1;
10259 .................... } 10259 .................... }
10260 .................... 10260 ....................
10261 .................... res = pat[0]*y*y + pat[1]; 10261 .................... res = pat[0]*y*y + pat[1];
10262 .................... res = res*y*y + pat[2]; 10262 .................... res = res*y*y + pat[2];
10263 .................... res = res*y*y + pat[3]; 10263 .................... res = res*y*y + pat[3];
10264 .................... 10264 ....................
10265 .................... r = qat[0]*y*y + qat[1]; 10265 .................... r = qat[0]*y*y + qat[1];
10266 .................... r = r*y*y + qat[2]; 10266 .................... r = r*y*y + qat[2];
10267 .................... r = r*y*y + qat[3]; 10267 .................... r = r*y*y + qat[3];
10268 .................... 10268 ....................
10269 .................... res = y*res/r; 10269 .................... res = y*res/r;
10270 .................... 10270 ....................
10271 .................... 10271 ....................
10272 .................... if (flag) // for |x| > 1 10272 .................... if (flag) // for |x| > 1
10273 .................... res = PI_DIV_BY_TWO - res; 10273 .................... res = PI_DIV_BY_TWO - res;
10274 .................... if (s) 10274 .................... if (s)
10275 .................... res = -res; 10275 .................... res = -res;
10276 .................... 10276 ....................
10277 .................... return(res); 10277 .................... return(res);
10278 .................... } 10278 .................... }
10279 .................... //Overloaded functions for atan() for PCD 10279 .................... //Overloaded functions for atan() for PCD
10280 .................... // Overloaded function atan() for data type - Float48 10280 .................... // Overloaded function atan() for data type - Float48
10281 .................... #if defined(__PCD__) 10281 .................... #if defined(__PCD__)
10282 .................... float48 atan(float48 x) 10282 .................... float48 atan(float48 x)
10283 .................... { 10283 .................... {
10284 .................... float48 y, res, r; 10284 .................... float48 y, res, r;
10285 .................... int1 s, flag; 10285 .................... int1 s, flag;
10286 .................... 10286 ....................
10287 .................... s = 0; 10287 .................... s = 0;
10288 .................... flag = 0; 10288 .................... flag = 0;
10289 .................... y = x; 10289 .................... y = x;
10290 .................... 10290 ....................
10291 .................... if (x < 0) 10291 .................... if (x < 0)
10292 .................... { 10292 .................... {
10293 .................... s = 1; 10293 .................... s = 1;
10294 .................... y = -y; 10294 .................... y = -y;
10295 .................... } 10295 .................... }
10296 .................... 10296 ....................
10297 .................... if (y > 1.0) 10297 .................... if (y > 1.0)
10298 .................... { 10298 .................... {
10299 .................... y = 1.0/y; 10299 .................... y = 1.0/y;
10300 .................... flag = 1; 10300 .................... flag = 1;
10301 .................... } 10301 .................... }
10302 .................... 10302 ....................
10303 .................... res = pat[0]*y*y + pat[1]; 10303 .................... res = pat[0]*y*y + pat[1];
10304 .................... res = res*y*y + pat[2]; 10304 .................... res = res*y*y + pat[2];
10305 .................... res = res*y*y + pat[3]; 10305 .................... res = res*y*y + pat[3];
10306 .................... 10306 ....................
10307 .................... r = qat[0]*y*y + qat[1]; 10307 .................... r = qat[0]*y*y + qat[1];
10308 .................... r = r*y*y + qat[2]; 10308 .................... r = r*y*y + qat[2];
10309 .................... r = r*y*y + qat[3]; 10309 .................... r = r*y*y + qat[3];
10310 .................... 10310 ....................
10311 .................... res = y*res/r; 10311 .................... res = y*res/r;
10312 .................... 10312 ....................
10313 .................... 10313 ....................
10314 .................... if (flag) // for |x| > 1 10314 .................... if (flag) // for |x| > 1
10315 .................... res = PI_DIV_BY_TWO - res; 10315 .................... res = PI_DIV_BY_TWO - res;
10316 .................... if (s) 10316 .................... if (s)
10317 .................... res = -res; 10317 .................... res = -res;
10318 .................... 10318 ....................
10319 .................... return(res); 10319 .................... return(res);
10320 .................... } 10320 .................... }
10321 .................... 10321 ....................
10322 .................... // Overloaded function atan() for data type - Float64 10322 .................... // Overloaded function atan() for data type - Float64
10323 .................... float64 atan(float64 x) 10323 .................... float64 atan(float64 x)
10324 .................... { 10324 .................... {
10325 .................... float64 y, res, r; 10325 .................... float64 y, res, r;
10326 .................... int1 s, flag; 10326 .................... int1 s, flag;
10327 .................... 10327 ....................
10328 .................... s = 0; 10328 .................... s = 0;
10329 .................... flag = 0; 10329 .................... flag = 0;
10330 .................... y = x; 10330 .................... y = x;
10331 .................... 10331 ....................
10332 .................... if (x < 0) 10332 .................... if (x < 0)
10333 .................... { 10333 .................... {
10334 .................... s = 1; 10334 .................... s = 1;
10335 .................... y = -y; 10335 .................... y = -y;
10336 .................... } 10336 .................... }
10337 .................... 10337 ....................
10338 .................... if (y > 1.0) 10338 .................... if (y > 1.0)
10339 .................... { 10339 .................... {
10340 .................... y = 1.0/y; 10340 .................... y = 1.0/y;
10341 .................... flag = 1; 10341 .................... flag = 1;
10342 .................... } 10342 .................... }
10343 .................... 10343 ....................
10344 .................... res = pat[0]*y*y + pat[1]; 10344 .................... res = pat[0]*y*y + pat[1];
10345 .................... res = res*y*y + pat[2]; 10345 .................... res = res*y*y + pat[2];
10346 .................... res = res*y*y + pat[3]; 10346 .................... res = res*y*y + pat[3];
10347 .................... 10347 ....................
10348 .................... r = qat[0]*y*y + qat[1]; 10348 .................... r = qat[0]*y*y + qat[1];
10349 .................... r = r*y*y + qat[2]; 10349 .................... r = r*y*y + qat[2];
10350 .................... r = r*y*y + qat[3]; 10350 .................... r = r*y*y + qat[3];
10351 .................... 10351 ....................
10352 .................... res = y*res/r; 10352 .................... res = y*res/r;
10353 .................... 10353 ....................
10354 .................... 10354 ....................
10355 .................... if (flag) // for |x| > 1 10355 .................... if (flag) // for |x| > 1
10356 .................... res = PI_DIV_BY_TWO - res; 10356 .................... res = PI_DIV_BY_TWO - res;
10357 .................... if (s) 10357 .................... if (s)
10358 .................... res = -res; 10358 .................... res = -res;
10359 .................... 10359 ....................
10360 .................... return(res); 10360 .................... return(res);
10361 .................... } 10361 .................... }
10362 .................... #endif 10362 .................... #endif
10363 .................... 10363 ....................
10364 .................... ///////////////////////////////////////////////////////////////////////////// 10364 .................... /////////////////////////////////////////////////////////////////////////////
10365 .................... // float atan2(float y, float x) 10365 .................... // float atan2(float y, float x)
10366 .................... ///////////////////////////////////////////////////////////////////////////// 10366 .................... /////////////////////////////////////////////////////////////////////////////
10367 .................... // Description :computes the principal value of arc tangent of y/x, using the 10367 .................... // Description :computes the principal value of arc tangent of y/x, using the
10368 .................... // signs of both the arguments to determine the quadrant of the return value 10368 .................... // signs of both the arguments to determine the quadrant of the return value
10369 .................... // Returns : returns the arc tangent of y/x. 10369 .................... // Returns : returns the arc tangent of y/x.
10370 .................... // Date : N/A 10370 .................... // Date : N/A
10371 .................... // 10371 .................... //
10372 .................... 10372 ....................
10373 .................... float32 atan2(float32 y,float32 x) 10373 .................... float32 atan2(float32 y,float32 x)
10374 .................... { 10374 .................... {
10375 .................... float32 z; 10375 .................... float32 z;
10376 .................... int1 sign; 10376 .................... int1 sign;
10377 .................... unsigned int8 quad; 10377 .................... unsigned int8 quad;
10378 .................... sign=0; 10378 .................... sign=0;
10379 .................... quad=0; //quadrant 10379 .................... quad=0; //quadrant
10380 .................... quad=((y<=0.0)?((x<=0.0)?3:4):((x<0.0)?2:1)); 10380 .................... quad=((y<=0.0)?((x<=0.0)?3:4):((x<0.0)?2:1));
10381 .................... if(y<0.0) 10381 .................... if(y<0.0)
10382 .................... { 10382 .................... {
10383 .................... sign=1; 10383 .................... sign=1;
10384 .................... y=-y; 10384 .................... y=-y;
10385 .................... } 10385 .................... }
10386 .................... if(x<0.0) 10386 .................... if(x<0.0)
10387 .................... { 10387 .................... {
10388 .................... x=-x; 10388 .................... x=-x;
10389 .................... } 10389 .................... }
10390 .................... if (x==0.0) 10390 .................... if (x==0.0)
10391 .................... { 10391 .................... {
10392 .................... if(y==0.0) 10392 .................... if(y==0.0)
10393 .................... { 10393 .................... {
10394 .................... #ifdef _ERRNO 10394 .................... #ifdef _ERRNO
10395 .................... { 10395 .................... {
10396 .................... errno=EDOM; 10396 .................... errno=EDOM;
10397 .................... } 10397 .................... }
10398 .................... #endif 10398 .................... #endif
10399 .................... } 10399 .................... }
10400 .................... else 10400 .................... else
10401 .................... { 10401 .................... {
10402 .................... if(sign) 10402 .................... if(sign)
10403 .................... { 10403 .................... {
10404 .................... return (-(PI_DIV_BY_TWO)); 10404 .................... return (-(PI_DIV_BY_TWO));
10405 .................... } 10405 .................... }
10406 .................... else 10406 .................... else
10407 .................... { 10407 .................... {
10408 .................... return (PI_DIV_BY_TWO); 10408 .................... return (PI_DIV_BY_TWO);
10409 .................... } 10409 .................... }
10410 .................... } 10410 .................... }
10411 .................... } 10411 .................... }
10412 .................... else 10412 .................... else
10413 .................... { 10413 .................... {
10414 .................... z=y/x; 10414 .................... z=y/x;
10415 .................... switch(quad) 10415 .................... switch(quad)
10416 .................... { 10416 .................... {
10417 .................... case 1: 10417 .................... case 1:
10418 .................... { 10418 .................... {
10419 .................... return atan(z); 10419 .................... return atan(z);
10420 .................... break; 10420 .................... break;
10421 .................... } 10421 .................... }
10422 .................... case 2: 10422 .................... case 2:
10423 .................... { 10423 .................... {
10424 .................... // return (atan(z)+PI_DIV_BY_TWO); //2L3122 10424 .................... // return (atan(z)+PI_DIV_BY_TWO); //2L3122
10425 .................... return (PI-atan(z)); 10425 .................... return (PI-atan(z));
10426 .................... break; 10426 .................... break;
10427 .................... } 10427 .................... }
10428 .................... case 3: 10428 .................... case 3:
10429 .................... { 10429 .................... {
10430 .................... return (atan(z)-PI); 10430 .................... return (atan(z)-PI);
10431 .................... break; 10431 .................... break;
10432 .................... } 10432 .................... }
10433 .................... case 4: 10433 .................... case 4:
10434 .................... { 10434 .................... {
10435 .................... return (-atan(z)); 10435 .................... return (-atan(z));
10436 .................... break; 10436 .................... break;
10437 .................... } 10437 .................... }
10438 .................... } 10438 .................... }
10439 .................... } 10439 .................... }
10440 .................... } 10440 .................... }
10441 .................... 10441 ....................
10442 .................... //Overloaded functions for atan2() for PCD 10442 .................... //Overloaded functions for atan2() for PCD
10443 .................... // Overloaded function atan2() for data type - Float48 10443 .................... // Overloaded function atan2() for data type - Float48
10444 .................... #if defined(__PCD__) 10444 .................... #if defined(__PCD__)
10445 .................... float48 atan2(float48 y,float48 x) 10445 .................... float48 atan2(float48 y,float48 x)
10446 .................... { 10446 .................... {
10447 .................... float48 z; 10447 .................... float48 z;
10448 .................... int1 sign; 10448 .................... int1 sign;
10449 .................... unsigned int8 quad; 10449 .................... unsigned int8 quad;
10450 .................... sign=0; 10450 .................... sign=0;
10451 .................... quad=0; //quadrant 10451 .................... quad=0; //quadrant
10452 .................... quad=((y<=0.0)?((x<=0.0)?3:4):((x<0.0)?2:1)); 10452 .................... quad=((y<=0.0)?((x<=0.0)?3:4):((x<0.0)?2:1));
10453 .................... if(y<0.0) 10453 .................... if(y<0.0)
10454 .................... { 10454 .................... {
10455 .................... sign=1; 10455 .................... sign=1;
10456 .................... y=-y; 10456 .................... y=-y;
10457 .................... } 10457 .................... }
10458 .................... if(x<0.0) 10458 .................... if(x<0.0)
10459 .................... { 10459 .................... {
10460 .................... x=-x; 10460 .................... x=-x;
10461 .................... } 10461 .................... }
10462 .................... if (x==0.0) 10462 .................... if (x==0.0)
10463 .................... { 10463 .................... {
10464 .................... if(y==0.0) 10464 .................... if(y==0.0)
10465 .................... { 10465 .................... {
10466 .................... #ifdef _ERRNO 10466 .................... #ifdef _ERRNO
10467 .................... { 10467 .................... {
10468 .................... errno=EDOM; 10468 .................... errno=EDOM;
10469 .................... } 10469 .................... }
10470 .................... #endif 10470 .................... #endif
10471 .................... } 10471 .................... }
10472 .................... else 10472 .................... else
10473 .................... { 10473 .................... {
10474 .................... if(sign) 10474 .................... if(sign)
10475 .................... { 10475 .................... {
10476 .................... return (-(PI_DIV_BY_TWO)); 10476 .................... return (-(PI_DIV_BY_TWO));
10477 .................... } 10477 .................... }
10478 .................... else 10478 .................... else
10479 .................... { 10479 .................... {
10480 .................... return (PI_DIV_BY_TWO); 10480 .................... return (PI_DIV_BY_TWO);
10481 .................... } 10481 .................... }
10482 .................... } 10482 .................... }
10483 .................... } 10483 .................... }
10484 .................... else 10484 .................... else
10485 .................... { 10485 .................... {
10486 .................... z=y/x; 10486 .................... z=y/x;
10487 .................... switch(quad) 10487 .................... switch(quad)
10488 .................... { 10488 .................... {
10489 .................... case 1: 10489 .................... case 1:
10490 .................... { 10490 .................... {
10491 .................... return atan(z); 10491 .................... return atan(z);
10492 .................... break; 10492 .................... break;
10493 .................... } 10493 .................... }
10494 .................... case 2: 10494 .................... case 2:
10495 .................... { 10495 .................... {
10496 .................... // return (atan(z)+PI_DIV_BY_TWO); //2L3122 10496 .................... // return (atan(z)+PI_DIV_BY_TWO); //2L3122
10497 .................... return (PI-atan(z)); 10497 .................... return (PI-atan(z));
10498 .................... break; 10498 .................... break;
10499 .................... } 10499 .................... }
10500 .................... case 3: 10500 .................... case 3:
10501 .................... { 10501 .................... {
10502 .................... return (atan(z)-PI); 10502 .................... return (atan(z)-PI);
10503 .................... break; 10503 .................... break;
10504 .................... } 10504 .................... }
10505 .................... case 4: 10505 .................... case 4:
10506 .................... { 10506 .................... {
10507 .................... return (-atan(z)); 10507 .................... return (-atan(z));
10508 .................... break; 10508 .................... break;
10509 .................... } 10509 .................... }
10510 .................... } 10510 .................... }
10511 .................... } 10511 .................... }
10512 .................... } 10512 .................... }
10513 .................... 10513 ....................
10514 .................... // Overloaded function atan2() for data type - Float64 10514 .................... // Overloaded function atan2() for data type - Float64
10515 .................... float64 atan2(float64 y,float64 x) 10515 .................... float64 atan2(float64 y,float64 x)
10516 .................... { 10516 .................... {
10517 .................... float64 z; 10517 .................... float64 z;
10518 .................... int1 sign; 10518 .................... int1 sign;
10519 .................... unsigned int8 quad; 10519 .................... unsigned int8 quad;
10520 .................... sign=0; 10520 .................... sign=0;
10521 .................... quad=0; //quadrant 10521 .................... quad=0; //quadrant
10522 .................... quad=((y<=0.0)?((x<=0.0)?3:4):((x<0.0)?2:1)); 10522 .................... quad=((y<=0.0)?((x<=0.0)?3:4):((x<0.0)?2:1));
10523 .................... if(y<0.0) 10523 .................... if(y<0.0)
10524 .................... { 10524 .................... {
10525 .................... sign=1; 10525 .................... sign=1;
10526 .................... y=-y; 10526 .................... y=-y;
10527 .................... } 10527 .................... }
10528 .................... if(x<0.0) 10528 .................... if(x<0.0)
10529 .................... { 10529 .................... {
10530 .................... x=-x; 10530 .................... x=-x;
10531 .................... } 10531 .................... }
10532 .................... if (x==0.0) 10532 .................... if (x==0.0)
10533 .................... { 10533 .................... {
10534 .................... if(y==0.0) 10534 .................... if(y==0.0)
10535 .................... { 10535 .................... {
10536 .................... #ifdef _ERRNO 10536 .................... #ifdef _ERRNO
10537 .................... { 10537 .................... {
10538 .................... errno=EDOM; 10538 .................... errno=EDOM;
10539 .................... } 10539 .................... }
10540 .................... #endif 10540 .................... #endif
10541 .................... } 10541 .................... }
10542 .................... else 10542 .................... else
10543 .................... { 10543 .................... {
10544 .................... if(sign) 10544 .................... if(sign)
10545 .................... { 10545 .................... {
10546 .................... return (-(PI_DIV_BY_TWO)); 10546 .................... return (-(PI_DIV_BY_TWO));
10547 .................... } 10547 .................... }
10548 .................... else 10548 .................... else
10549 .................... { 10549 .................... {
10550 .................... return (PI_DIV_BY_TWO); 10550 .................... return (PI_DIV_BY_TWO);
10551 .................... } 10551 .................... }
10552 .................... } 10552 .................... }
10553 .................... } 10553 .................... }
10554 .................... else 10554 .................... else
10555 .................... { 10555 .................... {
10556 .................... z=y/x; 10556 .................... z=y/x;
10557 .................... switch(quad) 10557 .................... switch(quad)
10558 .................... { 10558 .................... {
10559 .................... case 1: 10559 .................... case 1:
10560 .................... { 10560 .................... {
10561 .................... return atan(z); 10561 .................... return atan(z);
10562 .................... break; 10562 .................... break;
10563 .................... } 10563 .................... }
10564 .................... case 2: 10564 .................... case 2:
10565 .................... { 10565 .................... {
10566 .................... // return (atan(z)+PI_DIV_BY_TWO); //2L3122 10566 .................... // return (atan(z)+PI_DIV_BY_TWO); //2L3122
10567 .................... return (PI-atan(z)); 10567 .................... return (PI-atan(z));
10568 .................... break; 10568 .................... break;
10569 .................... } 10569 .................... }
10570 .................... case 3: 10570 .................... case 3:
10571 .................... { 10571 .................... {
10572 .................... return (atan(z)-PI); 10572 .................... return (atan(z)-PI);
10573 .................... break; 10573 .................... break;
10574 .................... } 10574 .................... }
10575 .................... case 4: 10575 .................... case 4:
10576 .................... { 10576 .................... {
10577 .................... return (-atan(z)); 10577 .................... return (-atan(z));
10578 .................... break; 10578 .................... break;
10579 .................... } 10579 .................... }
10580 .................... } 10580 .................... }
10581 .................... } 10581 .................... }
10582 .................... } 10582 .................... }
10583 .................... #endif 10583 .................... #endif
10584 .................... 10584 ....................
10585 .................... //////////////////// Hyperbolic functions //////////////////// 10585 .................... //////////////////// Hyperbolic functions ////////////////////
10586 .................... 10586 ....................
10587 .................... //////////////////////////////////////////////////////////////////////////// 10587 .................... ////////////////////////////////////////////////////////////////////////////
10588 .................... // float cosh(float x) 10588 .................... // float cosh(float x)
10589 .................... //////////////////////////////////////////////////////////////////////////// 10589 .................... ////////////////////////////////////////////////////////////////////////////
10590 .................... // Description : Computes the hyperbolic cosine value of x 10590 .................... // Description : Computes the hyperbolic cosine value of x
10591 .................... // Returns : returns the hyperbolic cosine value of x 10591 .................... // Returns : returns the hyperbolic cosine value of x
10592 .................... // Date : N/A 10592 .................... // Date : N/A
10593 .................... // 10593 .................... //
10594 .................... 10594 ....................
10595 .................... float32 cosh(float32 x) 10595 .................... float32 cosh(float32 x)
10596 .................... { 10596 .................... {
10597 .................... return ((exp(x)+exp(-x))/2); 10597 .................... return ((exp(x)+exp(-x))/2);
10598 .................... } 10598 .................... }
10599 .................... //Overloaded functions for cosh() for PCD 10599 .................... //Overloaded functions for cosh() for PCD
10600 .................... // Overloaded function cosh() for data type - Float48 10600 .................... // Overloaded function cosh() for data type - Float48
10601 .................... #if defined(__PCD__) 10601 .................... #if defined(__PCD__)
10602 .................... float48 cosh(float48 x) 10602 .................... float48 cosh(float48 x)
10603 .................... { 10603 .................... {
10604 .................... return ((exp(x)+exp(-x))/2); 10604 .................... return ((exp(x)+exp(-x))/2);
10605 .................... } 10605 .................... }
10606 .................... 10606 ....................
10607 .................... // Overloaded function cosh() for data type - Float64 10607 .................... // Overloaded function cosh() for data type - Float64
10608 .................... float64 cosh(float64 x) 10608 .................... float64 cosh(float64 x)
10609 .................... { 10609 .................... {
10610 .................... return ((exp(x)+exp(-x))/2); 10610 .................... return ((exp(x)+exp(-x))/2);
10611 .................... } 10611 .................... }
10612 .................... #endif 10612 .................... #endif
10613 .................... 10613 ....................
10614 .................... //////////////////////////////////////////////////////////////////////////// 10614 .................... ////////////////////////////////////////////////////////////////////////////
10615 .................... // float sinh(float x) 10615 .................... // float sinh(float x)
10616 .................... //////////////////////////////////////////////////////////////////////////// 10616 .................... ////////////////////////////////////////////////////////////////////////////
10617 .................... // Description : Computes the hyperbolic sine value of x 10617 .................... // Description : Computes the hyperbolic sine value of x
10618 .................... // Returns : returns the hyperbolic sine value of x 10618 .................... // Returns : returns the hyperbolic sine value of x
10619 .................... // Date : N/A 10619 .................... // Date : N/A
10620 .................... // 10620 .................... //
10621 .................... 10621 ....................
10622 .................... float32 sinh(float32 x) 10622 .................... float32 sinh(float32 x)
10623 .................... { 10623 .................... {
10624 .................... 10624 ....................
10625 .................... return ((exp(x) - exp(-x))/2); 10625 .................... return ((exp(x) - exp(-x))/2);
10626 .................... } 10626 .................... }
10627 .................... //Overloaded functions for sinh() for PCD 10627 .................... //Overloaded functions for sinh() for PCD
10628 .................... // Overloaded function sinh() for data type - Float48 10628 .................... // Overloaded function sinh() for data type - Float48
10629 .................... #if defined(__PCD__) 10629 .................... #if defined(__PCD__)
10630 .................... float48 sinh(float48 x) 10630 .................... float48 sinh(float48 x)
10631 .................... { 10631 .................... {
10632 .................... 10632 ....................
10633 .................... return ((exp(x) - exp(-x))/2); 10633 .................... return ((exp(x) - exp(-x))/2);
10634 .................... } 10634 .................... }
10635 .................... 10635 ....................
10636 .................... // Overloaded function sinh() for data type - Float48 10636 .................... // Overloaded function sinh() for data type - Float48
10637 .................... float64 sinh(float64 x) 10637 .................... float64 sinh(float64 x)
10638 .................... { 10638 .................... {
10639 .................... 10639 ....................
10640 .................... return ((exp(x) - exp(-x))/2); 10640 .................... return ((exp(x) - exp(-x))/2);
10641 .................... } 10641 .................... }
10642 .................... #endif 10642 .................... #endif
10643 .................... 10643 ....................
10644 .................... //////////////////////////////////////////////////////////////////////////// 10644 .................... ////////////////////////////////////////////////////////////////////////////
10645 .................... // float tanh(float x) 10645 .................... // float tanh(float x)
10646 .................... //////////////////////////////////////////////////////////////////////////// 10646 .................... ////////////////////////////////////////////////////////////////////////////
10647 .................... // Description : Computes the hyperbolic tangent value of x 10647 .................... // Description : Computes the hyperbolic tangent value of x
10648 .................... // Returns : returns the hyperbolic tangent value of x 10648 .................... // Returns : returns the hyperbolic tangent value of x
10649 .................... // Date : N/A 10649 .................... // Date : N/A
10650 .................... // 10650 .................... //
10651 .................... 10651 ....................
10652 .................... float32 tanh(float32 x) 10652 .................... float32 tanh(float32 x)
10653 .................... { 10653 .................... {
10654 .................... return(sinh(x)/cosh(x)); 10654 .................... return(sinh(x)/cosh(x));
10655 .................... } 10655 .................... }
10656 .................... //Overloaded functions for tanh() for PCD 10656 .................... //Overloaded functions for tanh() for PCD
10657 .................... // Overloaded function tanh() for data type - Float48 10657 .................... // Overloaded function tanh() for data type - Float48
10658 .................... #if defined(__PCD__) 10658 .................... #if defined(__PCD__)
10659 .................... float48 tanh(float48 x) 10659 .................... float48 tanh(float48 x)
10660 .................... { 10660 .................... {
10661 .................... return(sinh(x)/cosh(x)); 10661 .................... return(sinh(x)/cosh(x));
10662 .................... } 10662 .................... }
10663 .................... 10663 ....................
10664 .................... // Overloaded function tanh() for data type - Float64 10664 .................... // Overloaded function tanh() for data type - Float64
10665 .................... float64 tanh(float64 x) 10665 .................... float64 tanh(float64 x)
10666 .................... { 10666 .................... {
10667 .................... return(sinh(x)/cosh(x)); 10667 .................... return(sinh(x)/cosh(x));
10668 .................... } 10668 .................... }
10669 .................... #endif 10669 .................... #endif
10670 .................... 10670 ....................
10671 .................... //////////////////////////////////////////////////////////////////////////// 10671 .................... ////////////////////////////////////////////////////////////////////////////
10672 .................... // float frexp(float x, signed int *exp) 10672 .................... // float frexp(float x, signed int *exp)
10673 .................... //////////////////////////////////////////////////////////////////////////// 10673 .................... ////////////////////////////////////////////////////////////////////////////
10674 .................... // Description : breaks a floating point number into a normalized fraction and an integral 10674 .................... // Description : breaks a floating point number into a normalized fraction and an integral
10675 .................... // power of 2. It stores the integer in the signed int object pointed to by exp. 10675 .................... // power of 2. It stores the integer in the signed int object pointed to by exp.
10676 .................... // Returns : returns the value x, such that x is a double with magnitude in the interval 10676 .................... // Returns : returns the value x, such that x is a double with magnitude in the interval
10677 .................... // [1/2,1) or zero, and value equals x times 2 raised to the power *exp.If value is zero, 10677 .................... // [1/2,1) or zero, and value equals x times 2 raised to the power *exp.If value is zero,
10678 .................... // both parts of the result are zero. 10678 .................... // both parts of the result are zero.
10679 .................... // Date : N/A 10679 .................... // Date : N/A
10680 .................... // 10680 .................... //
10681 .................... 10681 ....................
10682 .................... #define LOG2 .30102999566398119521 10682 .................... #define LOG2 .30102999566398119521
10683 .................... float32 frexp(float32 x, signed int8 *exp) 10683 .................... float32 frexp(float32 x, signed int8 *exp)
10684 .................... { 10684 .................... {
10685 .................... float32 res; 10685 .................... float32 res;
10686 .................... int1 sign = 0; 10686 .................... int1 sign = 0;
10687 .................... if(x == 0.0) 10687 .................... if(x == 0.0)
10688 .................... { 10688 .................... {
10689 .................... *exp=0; 10689 .................... *exp=0;
10690 .................... return (0.0); 10690 .................... return (0.0);
10691 .................... } 10691 .................... }
10692 .................... if(x < 0.0) 10692 .................... if(x < 0.0)
10693 .................... { 10693 .................... {
10694 .................... x=-x; 10694 .................... x=-x;
10695 .................... sign=1; 10695 .................... sign=1;
10696 .................... } 10696 .................... }
10697 .................... if (x > 1.0) 10697 .................... if (x > 1.0)
10698 .................... { 10698 .................... {
10699 .................... *exp=(ceil(log10(x)/LOG2)); 10699 .................... *exp=(ceil(log10(x)/LOG2));
10700 .................... res=x/(pow(2, *exp)); 10700 .................... res=x/(pow(2, *exp));
10701 .................... if (res == 1) 10701 .................... if (res == 1)
10702 .................... { 10702 .................... {
10703 .................... *exp=*exp+1; 10703 .................... *exp=*exp+1;
10704 .................... res=.5; 10704 .................... res=.5;
10705 .................... } 10705 .................... }
10706 .................... } 10706 .................... }
10707 .................... else 10707 .................... else
10708 .................... { 10708 .................... {
10709 .................... if(x < 0.5) 10709 .................... if(x < 0.5)
10710 .................... { 10710 .................... {
10711 .................... *exp=-1; 10711 .................... *exp=-1;
10712 .................... res=x*2; 10712 .................... res=x*2;
10713 .................... } 10713 .................... }
10714 .................... else 10714 .................... else
10715 .................... { 10715 .................... {
10716 .................... *exp=0; 10716 .................... *exp=0;
10717 .................... res=x; 10717 .................... res=x;
10718 .................... } 10718 .................... }
10719 .................... } 10719 .................... }
10720 .................... if(sign) 10720 .................... if(sign)
10721 .................... { 10721 .................... {
10722 .................... res=-res; 10722 .................... res=-res;
10723 .................... } 10723 .................... }
10724 .................... return res; 10724 .................... return res;
10725 .................... } 10725 .................... }
10726 .................... 10726 ....................
10727 .................... //Overloaded functions for frexp() for PCD 10727 .................... //Overloaded functions for frexp() for PCD
10728 .................... // Overloaded function frexp() for data type - Float48 10728 .................... // Overloaded function frexp() for data type - Float48
10729 .................... #if defined(__PCD__) 10729 .................... #if defined(__PCD__)
10730 .................... float48 frexp(float48 x, signed int8 *exp) 10730 .................... float48 frexp(float48 x, signed int8 *exp)
10731 .................... { 10731 .................... {
10732 .................... float48 res; 10732 .................... float48 res;
10733 .................... int1 sign = 0; 10733 .................... int1 sign = 0;
10734 .................... if(x == 0.0) 10734 .................... if(x == 0.0)
10735 .................... { 10735 .................... {
10736 .................... *exp=0; 10736 .................... *exp=0;
10737 .................... return (0.0); 10737 .................... return (0.0);
10738 .................... } 10738 .................... }
10739 .................... if(x < 0.0) 10739 .................... if(x < 0.0)
10740 .................... { 10740 .................... {
10741 .................... x=-x; 10741 .................... x=-x;
10742 .................... sign=1; 10742 .................... sign=1;
10743 .................... } 10743 .................... }
10744 .................... if (x > 1.0) 10744 .................... if (x > 1.0)
10745 .................... { 10745 .................... {
10746 .................... *exp=(ceil(log10(x)/LOG2)); 10746 .................... *exp=(ceil(log10(x)/LOG2));
10747 .................... res=x/(pow(2, *exp)); 10747 .................... res=x/(pow(2, *exp));
10748 .................... if (res == 1) 10748 .................... if (res == 1)
10749 .................... { 10749 .................... {
10750 .................... *exp=*exp+1; 10750 .................... *exp=*exp+1;
10751 .................... res=.5; 10751 .................... res=.5;
10752 .................... } 10752 .................... }
10753 .................... } 10753 .................... }
10754 .................... else 10754 .................... else
10755 .................... { 10755 .................... {
10756 .................... if(x < 0.5) 10756 .................... if(x < 0.5)
10757 .................... { 10757 .................... {
10758 .................... *exp=-1; 10758 .................... *exp=-1;
10759 .................... res=x*2; 10759 .................... res=x*2;
10760 .................... } 10760 .................... }
10761 .................... else 10761 .................... else
10762 .................... { 10762 .................... {
10763 .................... *exp=0; 10763 .................... *exp=0;
10764 .................... res=x; 10764 .................... res=x;
10765 .................... } 10765 .................... }
10766 .................... } 10766 .................... }
10767 .................... if(sign) 10767 .................... if(sign)
10768 .................... { 10768 .................... {
10769 .................... res=-res; 10769 .................... res=-res;
10770 .................... } 10770 .................... }
10771 .................... return res; 10771 .................... return res;
10772 .................... } 10772 .................... }
10773 .................... 10773 ....................
10774 .................... // Overloaded function frexp() for data type - Float64 10774 .................... // Overloaded function frexp() for data type - Float64
10775 .................... float64 frexp(float64 x, signed int8 *exp) 10775 .................... float64 frexp(float64 x, signed int8 *exp)
10776 .................... { 10776 .................... {
10777 .................... float64 res; 10777 .................... float64 res;
10778 .................... int1 sign = 0; 10778 .................... int1 sign = 0;
10779 .................... if(x == 0.0) 10779 .................... if(x == 0.0)
10780 .................... { 10780 .................... {
10781 .................... *exp=0; 10781 .................... *exp=0;
10782 .................... return (0.0); 10782 .................... return (0.0);
10783 .................... } 10783 .................... }
10784 .................... if(x < 0.0) 10784 .................... if(x < 0.0)
10785 .................... { 10785 .................... {
10786 .................... x=-x; 10786 .................... x=-x;
10787 .................... sign=1; 10787 .................... sign=1;
10788 .................... } 10788 .................... }
10789 .................... if (x > 1.0) 10789 .................... if (x > 1.0)
10790 .................... { 10790 .................... {
10791 .................... *exp=(ceil(log10(x)/LOG2)); 10791 .................... *exp=(ceil(log10(x)/LOG2));
10792 .................... res=x/(pow(2, *exp)); 10792 .................... res=x/(pow(2, *exp));
10793 .................... if (res == 1) 10793 .................... if (res == 1)
10794 .................... { 10794 .................... {
10795 .................... *exp=*exp+1; 10795 .................... *exp=*exp+1;
10796 .................... res=.5; 10796 .................... res=.5;
10797 .................... } 10797 .................... }
10798 .................... } 10798 .................... }
10799 .................... else 10799 .................... else
10800 .................... { 10800 .................... {
10801 .................... if(x < 0.5) 10801 .................... if(x < 0.5)
10802 .................... { 10802 .................... {
10803 .................... *exp=-1; 10803 .................... *exp=-1;
10804 .................... res=x*2; 10804 .................... res=x*2;
10805 .................... } 10805 .................... }
10806 .................... else 10806 .................... else
10807 .................... { 10807 .................... {
10808 .................... *exp=0; 10808 .................... *exp=0;
10809 .................... res=x; 10809 .................... res=x;
10810 .................... } 10810 .................... }
10811 .................... } 10811 .................... }
10812 .................... if(sign) 10812 .................... if(sign)
10813 .................... { 10813 .................... {
10814 .................... res=-res; 10814 .................... res=-res;
10815 .................... } 10815 .................... }
10816 .................... return res; 10816 .................... return res;
10817 .................... } 10817 .................... }
10818 .................... #endif 10818 .................... #endif
10819 .................... 10819 ....................
10820 .................... ////////////////////////////////////////////////////////////////////////////// 10820 .................... //////////////////////////////////////////////////////////////////////////////
10821 .................... // float ldexp(float x, signed int *exp) 10821 .................... // float ldexp(float x, signed int *exp)
10822 .................... ////////////////////////////////////////////////////////////////////////////// 10822 .................... //////////////////////////////////////////////////////////////////////////////
10823 .................... // Description : multiplies a floating point number by an integral power of 2. 10823 .................... // Description : multiplies a floating point number by an integral power of 2.
10824 .................... // Returns : returns the value of x times 2 raised to the power exp. 10824 .................... // Returns : returns the value of x times 2 raised to the power exp.
10825 .................... // Date : N/A 10825 .................... // Date : N/A
10826 .................... // 10826 .................... //
10827 .................... 10827 ....................
10828 .................... float32 ldexp(float32 value, signed int8 exp) 10828 .................... float32 ldexp(float32 value, signed int8 exp)
10829 .................... { 10829 .................... {
10830 .................... return (value * pow(2,exp)); 10830 .................... return (value * pow(2,exp));
10831 .................... } 10831 .................... }
10832 .................... //Overloaded functions for ldexp() for PCD 10832 .................... //Overloaded functions for ldexp() for PCD
10833 .................... // Overloaded function ldexp() for data type - Float48 10833 .................... // Overloaded function ldexp() for data type - Float48
10834 .................... 10834 ....................
10835 .................... #if defined(__PCD__) 10835 .................... #if defined(__PCD__)
10836 .................... float48 ldexp(float48 value, signed int8 exp) 10836 .................... float48 ldexp(float48 value, signed int8 exp)
10837 .................... { 10837 .................... {
10838 .................... return (value * pow(2,exp)); 10838 .................... return (value * pow(2,exp));
10839 .................... } 10839 .................... }
10840 .................... // Overloaded function ldexp() for data type - Float64 10840 .................... // Overloaded function ldexp() for data type - Float64
10841 .................... float64 ldexp(float64 value, signed int8 exp) 10841 .................... float64 ldexp(float64 value, signed int8 exp)
10842 .................... { 10842 .................... {
10843 .................... return (value * pow(2,exp)); 10843 .................... return (value * pow(2,exp));
10844 .................... } 10844 .................... }
10845 .................... #endif 10845 .................... #endif
10846 .................... 10846 ....................
10847 .................... #endif 10847 .................... #endif
10848 .................... 10848 ....................
10849 .................... 10849 ....................
10850 .................... float quadraticerror(float average, float buf[], int16 size) // compute average quadratic error 10850 .................... float quadraticerror(float average, float buf[], int16 size) // compute average quadratic error
10851 .................... { 10851 .................... {
10852 .................... int16 i; 10852 .................... int16 i;
10853 .................... float err=0; 10853 .................... float err=0;
10854 1AE2: MOVLB 6 10854 1AE2: MOVLB 6
10855 1AE4: CLRF xD4 10855 1AE4: CLRF xD4
10856 1AE6: CLRF xD5 10856 1AE6: CLRF xD5
10857 1AE8: CLRF xD6 10857 1AE8: CLRF xD6
10858 1AEA: CLRF xD7 10858 1AEA: CLRF xD7
10859 .................... 10859 ....................
10860 .................... for(i=0; i<size; i++) err += (buf[i]-average)*(buf[i]-average); // sum quadratic errors 10860 .................... for(i=0; i<size; i++) err += (buf[i]-average)*(buf[i]-average); // sum quadratic errors
10861 1AEC: CLRF xD3 10861 1AEC: CLRF xD3
10862 1AEE: CLRF xD2 10862 1AEE: CLRF xD2
10863 1AF0: MOVF xD3,W 10863 1AF0: MOVF xD3,W
10864 1AF2: SUBWF xD1,W 10864 1AF2: SUBWF xD1,W
10865 1AF4: BTFSS FD8.0 10865 1AF4: BTFSS FD8.0
10866 1AF6: BRA 1C48 10866 1AF6: BRA 1C48
10867 1AF8: BNZ 1B02 10867 1AF8: BNZ 1B02
10868 1AFA: MOVF xD0,W 10868 1AFA: MOVF xD0,W
10869 1AFC: SUBWF xD2,W 10869 1AFC: SUBWF xD2,W
10870 1AFE: BTFSC FD8.0 10870 1AFE: BTFSC FD8.0
10871 1B00: BRA 1C48 10871 1B00: BRA 1C48
10872 1B02: RLCF xD2,W 10872 1B02: RLCF xD2,W
10873 1B04: MOVWF 02 10873 1B04: MOVWF 02
10874 1B06: RLCF xD3,W 10874 1B06: RLCF xD3,W
10875 1B08: MOVWF 03 10875 1B08: MOVWF 03
10876 1B0A: RLCF 02,F 10876 1B0A: RLCF 02,F
10877 1B0C: RLCF 03,F 10877 1B0C: RLCF 03,F
10878 1B0E: MOVLW FC 10878 1B0E: MOVLW FC
10879 1B10: ANDWF 02,F 10879 1B10: ANDWF 02,F
10880 1B12: MOVF 02,W 10880 1B12: MOVF 02,W
10881 1B14: ADDWF xCE,W 10881 1B14: ADDWF xCE,W
10882 1B16: MOVWF FE9 10882 1B16: MOVWF FE9
10883 1B18: MOVF xCF,W 10883 1B18: MOVF xCF,W
10884 1B1A: ADDWFC 03,W 10884 1B1A: ADDWFC 03,W
10885 1B1C: MOVWF FEA 10885 1B1C: MOVWF FEA
10886 1B1E: MOVFF FEF,6D8 10886 1B1E: MOVFF FEF,6D8
10887 1B22: MOVFF FEC,6D9 10887 1B22: MOVFF FEC,6D9
10888 1B26: MOVFF FEC,6DA 10888 1B26: MOVFF FEC,6DA
10889 1B2A: MOVFF FEC,6DB 10889 1B2A: MOVFF FEC,6DB
10890 1B2E: MOVFF FEA,6DD 10890 1B2E: MOVFF FEA,6DD
10891 1B32: MOVFF FE9,6DC 10891 1B32: MOVFF FE9,6DC
10892 1B36: BSF FD8.1 10892 1B36: BSF FD8.1
10893 1B38: MOVFF 6DB,6ED 10893 1B38: MOVFF 6DB,6ED
10894 1B3C: MOVFF 6DA,6EC 10894 1B3C: MOVFF 6DA,6EC
10895 1B40: MOVFF 6D9,6EB 10895 1B40: MOVFF 6D9,6EB
10896 1B44: MOVFF 6D8,6EA 10896 1B44: MOVFF 6D8,6EA
10897 1B48: MOVFF 6CD,6F1 10897 1B48: MOVFF 6CD,6F1
10898 1B4C: MOVFF 6CC,6F0 10898 1B4C: MOVFF 6CC,6F0
10899 1B50: MOVFF 6CB,6EF 10899 1B50: MOVFF 6CB,6EF
10900 1B54: MOVFF 6CA,6EE 10900 1B54: MOVFF 6CA,6EE
10901 1B58: MOVLB 0 10901 1B58: MOVLB 0
10902 1B5A: RCALL 1442 10902 1B5A: RCALL 1442
10903 1B5C: MOVFF 6DD,FEA 10903 1B5C: MOVFF 6DD,FEA
10904 1B60: MOVFF 6DC,FE9 10904 1B60: MOVFF 6DC,FE9
10905 1B64: MOVFF 00,6D8 10905 1B64: MOVFF 00,6D8
10906 1B68: MOVFF 01,6D9 10906 1B68: MOVFF 01,6D9
10907 1B6C: MOVFF 02,6DA 10907 1B6C: MOVFF 02,6DA
10908 1B70: MOVFF 03,6DB 10908 1B70: MOVFF 03,6DB
10909 1B74: MOVLB 6 10909 1B74: MOVLB 6
10910 1B76: RLCF xD2,W 10910 1B76: RLCF xD2,W
10911 1B78: MOVWF 02 10911 1B78: MOVWF 02
10912 1B7A: RLCF xD3,W 10912 1B7A: RLCF xD3,W
10913 1B7C: MOVWF 03 10913 1B7C: MOVWF 03
10914 1B7E: RLCF 02,F 10914 1B7E: RLCF 02,F
10915 1B80: RLCF 03,F 10915 1B80: RLCF 03,F
10916 1B82: MOVLW FC 10916 1B82: MOVLW FC
10917 1B84: ANDWF 02,F 10917 1B84: ANDWF 02,F
10918 1B86: MOVF 02,W 10918 1B86: MOVF 02,W
10919 1B88: ADDWF xCE,W 10919 1B88: ADDWF xCE,W
10920 1B8A: MOVWF FE9 10920 1B8A: MOVWF FE9
10921 1B8C: MOVF xCF,W 10921 1B8C: MOVF xCF,W
10922 1B8E: ADDWFC 03,W 10922 1B8E: ADDWFC 03,W
10923 1B90: MOVWF FEA 10923 1B90: MOVWF FEA
10924 1B92: MOVFF FEF,6DE 10924 1B92: MOVFF FEF,6DE
10925 1B96: MOVFF FEC,6DF 10925 1B96: MOVFF FEC,6DF
10926 1B9A: MOVFF FEC,6E0 10926 1B9A: MOVFF FEC,6E0
10927 1B9E: MOVFF FEC,6E1 10927 1B9E: MOVFF FEC,6E1
10928 1BA2: MOVFF FEA,6E3 10928 1BA2: MOVFF FEA,6E3
10929 1BA6: MOVFF FE9,6E2 10929 1BA6: MOVFF FE9,6E2
10930 1BAA: BSF FD8.1 10930 1BAA: BSF FD8.1
10931 1BAC: MOVFF 6E1,6ED 10931 1BAC: MOVFF 6E1,6ED
10932 1BB0: MOVFF 6E0,6EC 10932 1BB0: MOVFF 6E0,6EC
10933 1BB4: MOVFF 6DF,6EB 10933 1BB4: MOVFF 6DF,6EB
10934 1BB8: MOVFF 6DE,6EA 10934 1BB8: MOVFF 6DE,6EA
10935 1BBC: MOVFF 6CD,6F1 10935 1BBC: MOVFF 6CD,6F1
10936 1BC0: MOVFF 6CC,6F0 10936 1BC0: MOVFF 6CC,6F0
10937 1BC4: MOVFF 6CB,6EF 10937 1BC4: MOVFF 6CB,6EF
10938 1BC8: MOVFF 6CA,6EE 10938 1BC8: MOVFF 6CA,6EE
10939 1BCC: MOVLB 0 10939 1BCC: MOVLB 0
10940 1BCE: RCALL 1442 10940 1BCE: RCALL 1442
10941 1BD0: MOVFF 6E3,FEA 10941 1BD0: MOVFF 6E3,FEA
10942 1BD4: MOVFF 6E2,FE9 10942 1BD4: MOVFF 6E2,FE9
10943 1BD8: MOVFF 6DB,6E7 10943 1BD8: MOVFF 6DB,6E7
10944 1BDC: MOVFF 6DA,6E6 10944 1BDC: MOVFF 6DA,6E6
10945 1BE0: MOVFF 6D9,6E5 10945 1BE0: MOVFF 6D9,6E5
10946 1BE4: MOVFF 6D8,6E4 10946 1BE4: MOVFF 6D8,6E4
10947 1BE8: MOVFF 03,6EB 10947 1BE8: MOVFF 03,6EB
10948 1BEC: MOVFF 02,6EA 10948 1BEC: MOVFF 02,6EA
10949 1BF0: MOVFF 01,6E9 10949 1BF0: MOVFF 01,6E9
10950 1BF4: MOVFF 00,6E8 10950 1BF4: MOVFF 00,6E8
10951 1BF8: RCALL 1852 10951 1BF8: RCALL 1852
10952 1BFA: MOVFF FEA,6D9 10952 1BFA: MOVFF FEA,6D9
10953 1BFE: MOVFF FE9,6D8 10953 1BFE: MOVFF FE9,6D8
10954 1C02: BCF FD8.1 10954 1C02: BCF FD8.1
10955 1C04: MOVFF 6D7,6ED 10955 1C04: MOVFF 6D7,6ED
10956 1C08: MOVFF 6D6,6EC 10956 1C08: MOVFF 6D6,6EC
10957 1C0C: MOVFF 6D5,6EB 10957 1C0C: MOVFF 6D5,6EB
10958 1C10: MOVFF 6D4,6EA 10958 1C10: MOVFF 6D4,6EA
10959 1C14: MOVFF 03,6F1 10959 1C14: MOVFF 03,6F1
10960 1C18: MOVFF 02,6F0 10960 1C18: MOVFF 02,6F0
10961 1C1C: MOVFF 01,6EF 10961 1C1C: MOVFF 01,6EF
10962 1C20: MOVFF 00,6EE 10962 1C20: MOVFF 00,6EE
10963 1C24: RCALL 1442 10963 1C24: RCALL 1442
10964 1C26: MOVFF 6D9,FEA 10964 1C26: MOVFF 6D9,FEA
10965 1C2A: MOVFF 6D8,FE9 10965 1C2A: MOVFF 6D8,FE9
10966 1C2E: MOVFF 03,6D7 10966 1C2E: MOVFF 03,6D7
10967 1C32: MOVFF 02,6D6 10967 1C32: MOVFF 02,6D6
10968 1C36: MOVFF 01,6D5 10968 1C36: MOVFF 01,6D5
10969 1C3A: MOVFF 00,6D4 10969 1C3A: MOVFF 00,6D4
10970 1C3E: MOVLB 6 10970 1C3E: MOVLB 6
10971 1C40: INCF xD2,F 10971 1C40: INCF xD2,F
10972 1C42: BTFSC FD8.2 10972 1C42: BTFSC FD8.2
10973 1C44: INCF xD3,F 10973 1C44: INCF xD3,F
10974 1C46: BRA 1AF0 10974 1C46: BRA 1AF0
10975 .................... err = sqrt((1/(float)size)*err); 10975 .................... err = sqrt((1/(float)size)*err);
10976 1C48: MOVFF 6D1,6D9 10976 1C48: MOVFF 6D1,6D9
10977 1C4C: MOVFF 6D0,6D8 10977 1C4C: MOVFF 6D0,6D8
10978 1C50: MOVLB 0 10978 1C50: MOVLB 0
10979 1C52: CALL 140C 10979 1C52: CALL 140C
10980 1C56: MOVLB 6 10980 1C56: MOVLB 6
10981 1C58: CLRF xED 10981 1C58: CLRF xED
10982 1C5A: CLRF xEC 10982 1C5A: CLRF xEC
10983 1C5C: CLRF xEB 10983 1C5C: CLRF xEB
10984 1C5E: MOVLW 7F 10984 1C5E: MOVLW 7F
10985 1C60: MOVWF xEA 10985 1C60: MOVWF xEA
10986 1C62: MOVFF 03,6F1 10986 1C62: MOVFF 03,6F1
10987 1C66: MOVFF 02,6F0 10987 1C66: MOVFF 02,6F0
10988 1C6A: MOVFF 01,6EF 10988 1C6A: MOVFF 01,6EF
10989 1C6E: MOVFF 00,6EE 10989 1C6E: MOVFF 00,6EE
10990 1C72: MOVLB 0 10990 1C72: MOVLB 0
10991 1C74: RCALL 16BA 10991 1C74: RCALL 16BA
10992 1C76: MOVFF 00,6D8 10992 1C76: MOVFF 00,6D8
10993 1C7A: MOVFF 01,6D9 10993 1C7A: MOVFF 01,6D9
10994 1C7E: MOVFF 02,6DA 10994 1C7E: MOVFF 02,6DA
10995 1C82: MOVFF 03,6DB 10995 1C82: MOVFF 03,6DB
10996 1C86: MOVFF 03,6E7 10996 1C86: MOVFF 03,6E7
10997 1C8A: MOVFF 02,6E6 10997 1C8A: MOVFF 02,6E6
10998 1C8E: MOVFF 01,6E5 10998 1C8E: MOVFF 01,6E5
10999 1C92: MOVFF 00,6E4 10999 1C92: MOVFF 00,6E4
11000 1C96: MOVFF 6D7,6EB 11000 1C96: MOVFF 6D7,6EB
11001 1C9A: MOVFF 6D6,6EA 11001 1C9A: MOVFF 6D6,6EA
11002 1C9E: MOVFF 6D5,6E9 11002 1C9E: MOVFF 6D5,6E9
11003 1CA2: MOVFF 6D4,6E8 11003 1CA2: MOVFF 6D4,6E8
11004 1CA6: RCALL 1852 11004 1CA6: RCALL 1852
11005 1CA8: MOVFF 00,6D8 11005 1CA8: MOVFF 00,6D8
11006 1CAC: MOVFF 01,6D9 11006 1CAC: MOVFF 01,6D9
11007 1CB0: MOVFF 02,6DA 11007 1CB0: MOVFF 02,6DA
11008 1CB4: MOVFF 03,6DB 11008 1CB4: MOVFF 03,6DB
11009 1CB8: MOVFF 03,6DF 11009 1CB8: MOVFF 03,6DF
11010 1CBC: MOVFF 02,6DE 11010 1CBC: MOVFF 02,6DE
11011 1CC0: MOVFF 01,6DD 11011 1CC0: MOVFF 01,6DD
11012 1CC4: MOVFF 00,6DC 11012 1CC4: MOVFF 00,6DC
11013 1CC8: BRA 19C2 11013 1CC8: BRA 19C2
11014 1CCA: MOVFF 03,6D7 11014 1CCA: MOVFF 03,6D7
11015 1CCE: MOVFF 02,6D6 11015 1CCE: MOVFF 02,6D6
11016 1CD2: MOVFF 01,6D5 11016 1CD2: MOVFF 01,6D5
11017 1CD6: MOVFF 00,6D4 11017 1CD6: MOVFF 00,6D4
11018 .................... return err; 11018 .................... return err;
11019 1CDA: MOVFF 6D4,00 11019 1CDA: MOVFF 6D4,00
11020 1CDE: MOVFF 6D5,01 11020 1CDE: MOVFF 6D5,01
11021 1CE2: MOVFF 6D6,02 11021 1CE2: MOVFF 6D6,02
11022 1CE6: MOVFF 6D7,03 11022 1CE6: MOVFF 6D7,03
11023 .................... } 11023 .................... }
11024 1CEA: RETLW 00 11024 1CEA: RETLW 00
11025 .................... 11025 ....................
11026 .................... void main() 11026 .................... void main()
11027 .................... { 11027 .................... {
11028 * 11028 *
11029 1F62: CLRF FF8 11029 1F62: CLRF FF8
11030 1F64: BCF FD0.7 11030 1F64: BCF FD0.7
11031 1F66: BSF 08.7 11031 1F66: BSF 08.7
11032 1F68: CLRF FEA 11032 1F68: CLRF FEA
11033 1F6A: CLRF FE9 11033 1F6A: CLRF FE9
11034 1F6C: MOVF FC1,W 11034 1F6C: MOVF FC1,W
11035 1F6E: ANDLW C0 11035 1F6E: ANDLW C0
11036 1F70: IORLW 0F 11036 1F70: IORLW 0F
11037 1F72: MOVWF FC1 11037 1F72: MOVWF FC1
11038 1F74: MOVLW 07 11038 1F74: MOVLW 07
11039 1F76: MOVWF FB4 11039 1F76: MOVWF FB4
11040 1F78: CLRF 21 11040 1F78: CLRF 21
11041 1F7A: MOVLW 04 11041 1F7A: MOVLW 04
11042 1F7C: MOVWF 22 11042 1F7C: MOVWF 22
11043 1F7E: MOVLW 0C 11043 1F7E: MOVLW 0C
11044 1F80: MOVWF 23 11044 1F80: MOVWF 23
11045 1F82: CLRF 24 11045 1F82: CLRF 24
11046 1F84: CLRF 28 11046 1F84: CLRF 28
11047 1F86: CLRF x7C 11047 1F86: CLRF x7C
11048 1F88: CLRF x83 11048 1F88: CLRF x83
11049 .................... 11049 ....................
11050 .................... float x[BUFLEN], y[BUFLEN], z[BUFLEN]; 11050 .................... float x[BUFLEN], y[BUFLEN], z[BUFLEN];
11051 .................... float xavg, yavg, zavg; 11051 .................... float xavg, yavg, zavg;
11052 .................... int i; 11052 .................... int i;
11053 .................... port_b_pullups(FALSE); 11053 .................... port_b_pullups(FALSE);
11054 1F8A: BSF FF1.7 11054 1F8A: BSF FF1.7
11055 .................... setup_psp(PSP_DISABLED); 11055 .................... setup_psp(PSP_DISABLED);
11056 1F8C: BCF FB0.4 11056 1F8C: BCF FB0.4
11057 .................... setup_spi(SPI_SS_DISABLED); 11057 .................... setup_spi(SPI_SS_DISABLED);
11058 1F8E: BCF FC6.5 11058 1F8E: BCF FC6.5
11059 1F90: BCF F94.7 11059 1F90: BCF F94.7
11060 1F92: BSF F93.0 11060 1F92: BSF F93.0
11061 1F94: BCF F93.1 11061 1F94: BCF F93.1
11062 1F96: MOVLW 01 11062 1F96: MOVLW 01
11063 1F98: MOVWF FC6 11063 1F98: MOVWF FC6
11064 1F9A: MOVLW 00 11064 1F9A: MOVLW 00
11065 1F9C: MOVWF FC7 11065 1F9C: MOVWF FC7
11066 .................... setup_wdt(WDT_OFF); 11066 .................... setup_wdt(WDT_OFF);
11067 1F9E: BCF FD1.0 11067 1F9E: BCF FD1.0
11068 .................... setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256); 11068 .................... setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256);
11069 1FA0: MOVLW 87 11069 1FA0: MOVLW 87
11070 1FA2: MOVWF FD5 11070 1FA2: MOVWF FD5
11071 .................... setup_timer_1(T1_DISABLED); 11071 .................... setup_timer_1(T1_DISABLED);
11072 1FA4: CLRF FCD 11072 1FA4: CLRF FCD
11073 .................... setup_timer_2(T2_DISABLED,0,1); 11073 .................... setup_timer_2(T2_DISABLED,0,1);
11074 1FA6: MOVLW 00 11074 1FA6: MOVLW 00
11075 1FA8: MOVWF FCA 11075 1FA8: MOVWF FCA
11076 1FAA: MOVLW 00 11076 1FAA: MOVLW 00
11077 1FAC: MOVWF FCB 11077 1FAC: MOVWF FCB
11078 .................... setup_timer_3(T3_DISABLED|T3_DIV_BY_1); 11078 .................... setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
11079 1FAE: CLRF FB1 11079 1FAE: CLRF FB1
11080 .................... setup_comparator(NC_NC_NC_NC); 11080 .................... setup_comparator(NC_NC_NC_NC);
11081 1FB0: MOVLW 07 11081 1FB0: MOVLW 07
11082 1FB2: MOVWF FB4 11082 1FB2: MOVWF FB4
11083 1FB4: MOVF F92,W 11083 1FB4: MOVF F92,W
11084 1FB6: MOVWF F92 11084 1FB6: MOVWF F92
11085 1FB8: MOVLW 13 11085 1FB8: MOVLW 13
11086 1FBA: MOVWF 00 11086 1FBA: MOVWF 00
11087 1FBC: DECFSZ 00,F 11087 1FBC: DECFSZ 00,F
11088 1FBE: BRA 1FBC 11088 1FBE: BRA 1FBC
11089 1FC0: BRA 1FC2 11089 1FC0: BRA 1FC2
11090 1FC2: MOVF FB4,W 11090 1FC2: MOVF FB4,W
11091 1FC4: BCF FA1.6 11091 1FC4: BCF FA1.6
11092 .................... setup_vref(FALSE); 11092 .................... setup_vref(FALSE);
11093 1FC6: CLRF FB5 11093 1FC6: CLRF FB5
11094 .................... enable_interrupts(INT_TIMER0); 11094 .................... enable_interrupts(INT_TIMER0);
11095 1FC8: BSF FF2.5 11095 1FC8: BSF FF2.5
11096 .................... enable_interrupts(GLOBAL); 11096 .................... enable_interrupts(GLOBAL);
11097 1FCA: MOVLW C0 11097 1FCA: MOVLW C0
11098 1FCC: IORWF FF2,F 11098 1FCC: IORWF FF2,F
11099 .................... 11099 ....................
11100 .................... setup_adc_ports(AN0_TO_AN2|VSS_VREF); 11100 .................... setup_adc_ports(AN0_TO_AN2|VSS_VREF);
11101 1FCE: MOVF FC1,W 11101 1FCE: MOVF FC1,W
11102 1FD0: ANDLW C0 11102 1FD0: ANDLW C0
11103 1FD2: IORLW 1C 11103 1FD2: IORLW 1C
11104 1FD4: MOVWF FC1 11104 1FD4: MOVWF FC1
11105 .................... setup_adc(ADC_CLOCK_DIV_32); 11105 .................... setup_adc(ADC_CLOCK_DIV_32);
11106 1FD6: BCF FC0.0 11106 1FD6: BCF FC0.0
11107 1FD8: BSF FC0.1 11107 1FD8: BSF FC0.1
11108 1FDA: BCF FC0.2 11108 1FDA: BCF FC0.2
11109 1FDC: BSF FC0.7 11109 1FDC: BSF FC0.7
11110 1FDE: BSF FC2.0 11110 1FDE: BSF FC2.0
11111 .................... 11111 ....................
11112 .................... usb_init(); // initialise USB module 11112 .................... usb_init(); // initialise USB module
11113 1FE0: GOTO 1368 11113 1FE0: GOTO 1368
11114 .................... 11114 ....................
11115 .................... while(!usb_cdc_connected()); 11115 .................... while(!usb_cdc_connected());
11116 1FE4: BTFSS x80.0 11116 1FE4: BTFSS x80.0
11117 1FE6: BRA 1FE4 11117 1FE6: BRA 1FE4
11118 .................... time=0; 11118 .................... time=0;
11119 1FE8: CLRF 1C 11119 1FE8: CLRF 1C
11120 1FEA: CLRF 1B 11120 1FEA: CLRF 1B
11121 1FEC: CLRF 1A 11121 1FEC: CLRF 1A
11122 1FEE: CLRF 19 11122 1FEE: CLRF 19
11123 .................... set_timer0(0); 11123 .................... set_timer0(0);
11124 1FF0: CLRF FD7 11124 1FF0: CLRF FD7
11125 1FF2: CLRF FD6 11125 1FF2: CLRF FD6
11126 .................... printf(usb_cdc_putc,"time[s] X Xerr Y Yerr Z Zerr \n\r"); 11126 .................... printf(usb_cdc_putc,"time[s] X Xerr Y Yerr Z Zerr \n\r");
11127 1FF4: MOVLB 3 11127 1FF4: MOVLB 3
11128 1FF6: CLRF xB1 11128 1FF6: CLRF xB1
11129 1FF8: MOVF xB1,W 11129 1FF8: MOVF xB1,W
11130 1FFA: MOVLB 0 11130 1FFA: MOVLB 0
11131 1FFC: CALL 021E 11131 1FFC: CALL 021E
11132 2000: MOVLB 3 11132 2000: MOVLB 3
11133 2002: INCF xB1,F 11133 2002: INCF xB1,F
11134 2004: MOVWF 00 11134 2004: MOVWF 00
11135 2006: MOVFF FE8,6DB 11135 2006: MOVFF FE8,6DB
11136 200A: MOVLB 0 11136 200A: MOVLB 0
11137 200C: CALL 13D4 11137 200C: CALL 13D4
11138 2010: MOVLW 25 11138 2010: MOVLW 25
11139 2012: MOVLB 3 11139 2012: MOVLB 3
11140 2014: SUBWF xB1,W 11140 2014: SUBWF xB1,W
11141 2016: BNZ 1FF8 11141 2016: BNZ 1FF8
11142 .................... 11142 ....................
11143 .................... while(usb_cdc_connected()) // pockej nez se pripoji seriovy port PC 11143 .................... while(usb_cdc_connected()) // pockej nez se pripoji seriovy port PC
11144 .................... { 11144 .................... {
11145 2018: MOVLB 0 11145 2018: MOVLB 0
11146 201A: BTFSS x80.0 11146 201A: BTFSS x80.0
11147 201C: BRA 25DE 11147 201C: BRA 25DE
11148 .................... for(i=0; i <BUFLEN; i++) 11148 .................... for(i=0; i <BUFLEN; i++)
11149 201E: MOVLB 3 11149 201E: MOVLB 3
11150 2020: CLRF xB0 11150 2020: CLRF xB0
11151 2022: MOVF xB0,W 11151 2022: MOVF xB0,W
11152 2024: SUBLW 63 11152 2024: SUBLW 63
11153 2026: BTFSS FD8.0 11153 2026: BTFSS FD8.0
11154 2028: BRA 2300 11154 2028: BRA 2300
11155 .................... { 11155 .................... {
11156 .................... set_adc_channel(0); 11156 .................... set_adc_channel(0);
11157 202A: MOVLW 00 11157 202A: MOVLW 00
11158 202C: MOVWF 01 11158 202C: MOVWF 01
11159 202E: MOVF FC2,W 11159 202E: MOVF FC2,W
11160 2030: ANDLW C3 11160 2030: ANDLW C3
11161 2032: IORWF 01,W 11161 2032: IORWF 01,W
11162 2034: MOVWF FC2 11162 2034: MOVWF FC2
11163 .................... delay_us(10); 11163 .................... delay_us(10);
11164 2036: MOVLW 13 11164 2036: MOVLW 13
11165 2038: MOVWF 00 11165 2038: MOVWF 00
11166 203A: DECFSZ 00,F 11166 203A: DECFSZ 00,F
11167 203C: BRA 203A 11167 203C: BRA 203A
11168 203E: BRA 2040 11168 203E: BRA 2040
11169 2040: CLRF 18 11169 2040: CLRF 18
11170 2042: BTFSC FF2.7 11170 2042: BTFSC FF2.7
11171 2044: BSF 18.7 11171 2044: BSF 18.7
11172 2046: BCF FF2.7 11172 2046: BCF FF2.7
11173 .................... x[i]=read_adc(); 11173 .................... x[i]=read_adc();
11174 2048: MOVLB 7 11174 2048: MOVLB 7
11175 204A: CLRF x49 11175 204A: CLRF x49
11176 204C: MOVFF 3B0,748 11176 204C: MOVFF 3B0,748
11177 2050: CLRF x4B 11177 2050: CLRF x4B
11178 2052: MOVLW 04 11178 2052: MOVLW 04
11179 2054: MOVWF x4A 11179 2054: MOVWF x4A
11180 2056: MOVLB 0 11180 2056: MOVLB 0
11181 2058: CALL 02BA 11181 2058: CALL 02BA
11182 205C: BTFSC 18.7 11182 205C: BTFSC 18.7
11183 205E: BSF FF2.7 11183 205E: BSF FF2.7
11184 2060: MOVFF 02,03 11184 2060: MOVFF 02,03
11185 2064: MOVF 01,W 11185 2064: MOVF 01,W
11186 2066: ADDLW 84 11186 2066: ADDLW 84
11187 2068: MOVWF FE9 11187 2068: MOVWF FE9
11188 206A: MOVLW 00 11188 206A: MOVLW 00
11189 206C: ADDWFC 02,W 11189 206C: ADDWFC 02,W
11190 206E: MOVWF FEA 11190 206E: MOVWF FEA
11191 2070: BSF FC2.1 11191 2070: BSF FC2.1
11192 2072: BTFSC FC2.1 11192 2072: BTFSC FC2.1
11193 2074: BRA 2072 11193 2074: BRA 2072
11194 2076: MOVFF FC4,6D9 11194 2076: MOVFF FC4,6D9
11195 207A: MOVFF FC3,6D8 11195 207A: MOVFF FC3,6D8
11196 207E: MOVLB 0 11196 207E: MOVLB 0
11197 2080: CALL 140C 11197 2080: CALL 140C
11198 2084: MOVFF 00,FEF 11198 2084: MOVFF 00,FEF
11199 2088: MOVFF 01,FEC 11199 2088: MOVFF 01,FEC
11200 208C: MOVFF 02,FEC 11200 208C: MOVFF 02,FEC
11201 2090: MOVFF 03,FEC 11201 2090: MOVFF 03,FEC
11202 2094: CLRF 18 11202 2094: CLRF 18
11203 2096: BTFSC FF2.7 11203 2096: BTFSC FF2.7
11204 2098: BSF 18.7 11204 2098: BSF 18.7
11205 209A: BCF FF2.7 11205 209A: BCF FF2.7
11206 .................... xavg+=x[i]; 11206 .................... xavg+=x[i];
11207 209C: MOVLB 7 11207 209C: MOVLB 7
11208 209E: CLRF x49 11208 209E: CLRF x49
11209 20A0: MOVFF 3B0,748 11209 20A0: MOVFF 3B0,748
11210 20A4: CLRF x4B 11210 20A4: CLRF x4B
11211 20A6: MOVLW 04 11211 20A6: MOVLW 04
11212 20A8: MOVWF x4A 11212 20A8: MOVWF x4A
11213 20AA: MOVLB 0 11213 20AA: MOVLB 0
11214 20AC: CALL 02BA 11214 20AC: CALL 02BA
11215 20B0: BTFSC 18.7 11215 20B0: BTFSC 18.7
11216 20B2: BSF FF2.7 11216 20B2: BSF FF2.7
11217 20B4: MOVFF 02,03 11217 20B4: MOVFF 02,03
11218 20B8: MOVF 01,W 11218 20B8: MOVF 01,W
11219 20BA: ADDLW 84 11219 20BA: ADDLW 84
11220 20BC: MOVWF FE9 11220 20BC: MOVWF FE9
11221 20BE: MOVLW 00 11221 20BE: MOVLW 00
11222 20C0: ADDWFC 02,W 11222 20C0: ADDWFC 02,W
11223 20C2: MOVWF FEA 11223 20C2: MOVWF FEA
11224 20C4: MOVFF FEF,00 11224 20C4: MOVFF FEF,00
11225 20C8: MOVFF FEC,01 11225 20C8: MOVFF FEC,01
11226 20CC: MOVFF FEC,02 11226 20CC: MOVFF FEC,02
11227 20D0: MOVFF FEC,03 11227 20D0: MOVFF FEC,03
11228 20D4: MOVFF FEA,3B2 11228 20D4: MOVFF FEA,3B2
11229 20D8: MOVFF FE9,3B1 11229 20D8: MOVFF FE9,3B1
11230 20DC: BCF FD8.1 11230 20DC: BCF FD8.1
11231 20DE: MOVFF 3A7,6ED 11231 20DE: MOVFF 3A7,6ED
11232 20E2: MOVFF 3A6,6EC 11232 20E2: MOVFF 3A6,6EC
11233 20E6: MOVFF 3A5,6EB 11233 20E6: MOVFF 3A5,6EB
11234 20EA: MOVFF 3A4,6EA 11234 20EA: MOVFF 3A4,6EA
11235 20EE: MOVFF 03,6F1 11235 20EE: MOVFF 03,6F1
11236 20F2: MOVFF 02,6F0 11236 20F2: MOVFF 02,6F0
11237 20F6: MOVFF 01,6EF 11237 20F6: MOVFF 01,6EF
11238 20FA: MOVFF 00,6EE 11238 20FA: MOVFF 00,6EE
11239 20FE: CALL 1442 11239 20FE: CALL 1442
11240 2102: MOVFF 3B2,FEA 11240 2102: MOVFF 3B2,FEA
11241 2106: MOVFF 3B1,FE9 11241 2106: MOVFF 3B1,FE9
11242 210A: MOVFF 03,3A7 11242 210A: MOVFF 03,3A7
11243 210E: MOVFF 02,3A6 11243 210E: MOVFF 02,3A6
11244 2112: MOVFF 01,3A5 11244 2112: MOVFF 01,3A5
11245 2116: MOVFF 00,3A4 11245 2116: MOVFF 00,3A4
11246 .................... 11246 ....................
11247 .................... set_adc_channel(1); 11247 .................... set_adc_channel(1);
11248 211A: MOVLW 04 11248 211A: MOVLW 04
11249 211C: MOVWF 01 11249 211C: MOVWF 01
11250 211E: MOVF FC2,W 11250 211E: MOVF FC2,W
11251 2120: ANDLW C3 11251 2120: ANDLW C3
11252 2122: IORWF 01,W 11252 2122: IORWF 01,W
11253 2124: MOVWF FC2 11253 2124: MOVWF FC2
11254 .................... delay_us(10); 11254 .................... delay_us(10);
11255 2126: MOVLW 13 11255 2126: MOVLW 13
11256 2128: MOVWF 00 11256 2128: MOVWF 00
11257 212A: DECFSZ 00,F 11257 212A: DECFSZ 00,F
11258 212C: BRA 212A 11258 212C: BRA 212A
11259 212E: BRA 2130 11259 212E: BRA 2130
11260 2130: CLRF 18 11260 2130: CLRF 18
11261 2132: BTFSC FF2.7 11261 2132: BTFSC FF2.7
11262 2134: BSF 18.7 11262 2134: BSF 18.7
11263 2136: BCF FF2.7 11263 2136: BCF FF2.7
11264 .................... y[i]=read_adc(); 11264 .................... y[i]=read_adc();
11265 2138: MOVLB 7 11265 2138: MOVLB 7
11266 213A: CLRF x49 11266 213A: CLRF x49
11267 213C: MOVFF 3B0,748 11267 213C: MOVFF 3B0,748
11268 2140: CLRF x4B 11268 2140: CLRF x4B
11269 2142: MOVLW 04 11269 2142: MOVLW 04
11270 2144: MOVWF x4A 11270 2144: MOVWF x4A
11271 2146: MOVLB 0 11271 2146: MOVLB 0
11272 2148: CALL 02BA 11272 2148: CALL 02BA
11273 214C: BTFSC 18.7 11273 214C: BTFSC 18.7
11274 214E: BSF FF2.7 11274 214E: BSF FF2.7
11275 2150: MOVFF 02,03 11275 2150: MOVFF 02,03
11276 2154: MOVF 01,W 11276 2154: MOVF 01,W
11277 2156: ADDLW 14 11277 2156: ADDLW 14
11278 2158: MOVWF FE9 11278 2158: MOVWF FE9
11279 215A: MOVLW 02 11279 215A: MOVLW 02
11280 215C: ADDWFC 02,W 11280 215C: ADDWFC 02,W
11281 215E: MOVWF FEA 11281 215E: MOVWF FEA
11282 2160: BSF FC2.1 11282 2160: BSF FC2.1
11283 2162: BTFSC FC2.1 11283 2162: BTFSC FC2.1
11284 2164: BRA 2162 11284 2164: BRA 2162
11285 2166: MOVFF FC4,6D9 11285 2166: MOVFF FC4,6D9
11286 216A: MOVFF FC3,6D8 11286 216A: MOVFF FC3,6D8
11287 216E: MOVLB 0 11287 216E: MOVLB 0
11288 2170: CALL 140C 11288 2170: CALL 140C
11289 2174: MOVFF 00,FEF 11289 2174: MOVFF 00,FEF
11290 2178: MOVFF 01,FEC 11290 2178: MOVFF 01,FEC
11291 217C: MOVFF 02,FEC 11291 217C: MOVFF 02,FEC
11292 2180: MOVFF 03,FEC 11292 2180: MOVFF 03,FEC
11293 2184: CLRF 18 11293 2184: CLRF 18
11294 2186: BTFSC FF2.7 11294 2186: BTFSC FF2.7
11295 2188: BSF 18.7 11295 2188: BSF 18.7
11296 218A: BCF FF2.7 11296 218A: BCF FF2.7
11297 .................... yavg+=y[i]; 11297 .................... yavg+=y[i];
11298 218C: MOVLB 7 11298 218C: MOVLB 7
11299 218E: CLRF x49 11299 218E: CLRF x49
11300 2190: MOVFF 3B0,748 11300 2190: MOVFF 3B0,748
11301 2194: CLRF x4B 11301 2194: CLRF x4B
11302 2196: MOVLW 04 11302 2196: MOVLW 04
11303 2198: MOVWF x4A 11303 2198: MOVWF x4A
11304 219A: MOVLB 0 11304 219A: MOVLB 0
11305 219C: CALL 02BA 11305 219C: CALL 02BA
11306 21A0: BTFSC 18.7 11306 21A0: BTFSC 18.7
11307 21A2: BSF FF2.7 11307 21A2: BSF FF2.7
11308 21A4: MOVFF 02,03 11308 21A4: MOVFF 02,03
11309 21A8: MOVF 01,W 11309 21A8: MOVF 01,W
11310 21AA: ADDLW 14 11310 21AA: ADDLW 14
11311 21AC: MOVWF FE9 11311 21AC: MOVWF FE9
11312 21AE: MOVLW 02 11312 21AE: MOVLW 02
11313 21B0: ADDWFC 02,W 11313 21B0: ADDWFC 02,W
11314 21B2: MOVWF FEA 11314 21B2: MOVWF FEA
11315 21B4: MOVFF FEF,00 11315 21B4: MOVFF FEF,00
11316 21B8: MOVFF FEC,01 11316 21B8: MOVFF FEC,01
11317 21BC: MOVFF FEC,02 11317 21BC: MOVFF FEC,02
11318 21C0: MOVFF FEC,03 11318 21C0: MOVFF FEC,03
11319 21C4: MOVFF FEA,3B2 11319 21C4: MOVFF FEA,3B2
11320 21C8: MOVFF FE9,3B1 11320 21C8: MOVFF FE9,3B1
11321 21CC: BCF FD8.1 11321 21CC: BCF FD8.1
11322 21CE: MOVFF 3AB,6ED 11322 21CE: MOVFF 3AB,6ED
11323 21D2: MOVFF 3AA,6EC 11323 21D2: MOVFF 3AA,6EC
11324 21D6: MOVFF 3A9,6EB 11324 21D6: MOVFF 3A9,6EB
11325 21DA: MOVFF 3A8,6EA 11325 21DA: MOVFF 3A8,6EA
11326 21DE: MOVFF 03,6F1 11326 21DE: MOVFF 03,6F1
11327 21E2: MOVFF 02,6F0 11327 21E2: MOVFF 02,6F0
11328 21E6: MOVFF 01,6EF 11328 21E6: MOVFF 01,6EF
11329 21EA: MOVFF 00,6EE 11329 21EA: MOVFF 00,6EE
11330 21EE: CALL 1442 11330 21EE: CALL 1442
11331 21F2: MOVFF 3B2,FEA 11331 21F2: MOVFF 3B2,FEA
11332 21F6: MOVFF 3B1,FE9 11332 21F6: MOVFF 3B1,FE9
11333 21FA: MOVFF 03,3AB 11333 21FA: MOVFF 03,3AB
11334 21FE: MOVFF 02,3AA 11334 21FE: MOVFF 02,3AA
11335 2202: MOVFF 01,3A9 11335 2202: MOVFF 01,3A9
11336 2206: MOVFF 00,3A8 11336 2206: MOVFF 00,3A8
11337 .................... 11337 ....................
11338 .................... set_adc_channel(2); 11338 .................... set_adc_channel(2);
11339 220A: MOVLW 08 11339 220A: MOVLW 08
11340 220C: MOVWF 01 11340 220C: MOVWF 01
11341 220E: MOVF FC2,W 11341 220E: MOVF FC2,W
11342 2210: ANDLW C3 11342 2210: ANDLW C3
11343 2212: IORWF 01,W 11343 2212: IORWF 01,W
11344 2214: MOVWF FC2 11344 2214: MOVWF FC2
11345 .................... delay_us(10); 11345 .................... delay_us(10);
11346 2216: MOVLW 13 11346 2216: MOVLW 13
11347 2218: MOVWF 00 11347 2218: MOVWF 00
11348 221A: DECFSZ 00,F 11348 221A: DECFSZ 00,F
11349 221C: BRA 221A 11349 221C: BRA 221A
11350 221E: BRA 2220 11350 221E: BRA 2220
11351 2220: CLRF 18 11351 2220: CLRF 18
11352 2222: BTFSC FF2.7 11352 2222: BTFSC FF2.7
11353 2224: BSF 18.7 11353 2224: BSF 18.7
11354 2226: BCF FF2.7 11354 2226: BCF FF2.7
11355 .................... z[i]=read_adc(); 11355 .................... z[i]=read_adc();
11356 2228: MOVLB 7 11356 2228: MOVLB 7
11357 222A: CLRF x49 11357 222A: CLRF x49
11358 222C: MOVFF 3B0,748 11358 222C: MOVFF 3B0,748
11359 2230: CLRF x4B 11359 2230: CLRF x4B
11360 2232: MOVLW 04 11360 2232: MOVLW 04
11361 2234: MOVWF x4A 11361 2234: MOVWF x4A
11362 2236: MOVLB 0 11362 2236: MOVLB 0
11363 2238: CALL 02BA 11363 2238: CALL 02BA
11364 223C: BTFSC 18.7 11364 223C: BTFSC 18.7
11365 223E: BSF FF2.7 11365 223E: BSF FF2.7
11366 2240: MOVFF 02,03 11366 2240: MOVFF 02,03
11367 2244: MOVF 01,W 11367 2244: MOVF 01,W
11368 2246: ADDLW 20 11368 2246: ADDLW 20
11369 2248: MOVWF FE9 11369 2248: MOVWF FE9
11370 224A: MOVLW 05 11370 224A: MOVLW 05
11371 224C: ADDWFC 02,W 11371 224C: ADDWFC 02,W
11372 224E: MOVWF FEA 11372 224E: MOVWF FEA
11373 2250: BSF FC2.1 11373 2250: BSF FC2.1
11374 2252: BTFSC FC2.1 11374 2252: BTFSC FC2.1
11375 2254: BRA 2252 11375 2254: BRA 2252
11376 2256: MOVFF FC4,6D9 11376 2256: MOVFF FC4,6D9
11377 225A: MOVFF FC3,6D8 11377 225A: MOVFF FC3,6D8
11378 225E: MOVLB 0 11378 225E: MOVLB 0
11379 2260: CALL 140C 11379 2260: CALL 140C
11380 2264: MOVFF 00,FEF 11380 2264: MOVFF 00,FEF
11381 2268: MOVFF 01,FEC 11381 2268: MOVFF 01,FEC
11382 226C: MOVFF 02,FEC 11382 226C: MOVFF 02,FEC
11383 2270: MOVFF 03,FEC 11383 2270: MOVFF 03,FEC
11384 2274: CLRF 18 11384 2274: CLRF 18
11385 2276: BTFSC FF2.7 11385 2276: BTFSC FF2.7
11386 2278: BSF 18.7 11386 2278: BSF 18.7
11387 227A: BCF FF2.7 11387 227A: BCF FF2.7
11388 .................... zavg+=z[i]; 11388 .................... zavg+=z[i];
11389 227C: MOVLB 7 11389 227C: MOVLB 7
11390 227E: CLRF x49 11390 227E: CLRF x49
11391 2280: MOVFF 3B0,748 11391 2280: MOVFF 3B0,748
11392 2284: CLRF x4B 11392 2284: CLRF x4B
11393 2286: MOVLW 04 11393 2286: MOVLW 04
11394 2288: MOVWF x4A 11394 2288: MOVWF x4A
11395 228A: MOVLB 0 11395 228A: MOVLB 0
11396 228C: CALL 02BA 11396 228C: CALL 02BA
11397 2290: BTFSC 18.7 11397 2290: BTFSC 18.7
11398 2292: BSF FF2.7 11398 2292: BSF FF2.7
11399 2294: MOVFF 02,03 11399 2294: MOVFF 02,03
11400 2298: MOVF 01,W 11400 2298: MOVF 01,W
11401 229A: ADDLW 20 11401 229A: ADDLW 20
11402 229C: MOVWF FE9 11402 229C: MOVWF FE9
11403 229E: MOVLW 05 11403 229E: MOVLW 05
11404 22A0: ADDWFC 02,W 11404 22A0: ADDWFC 02,W
11405 22A2: MOVWF FEA 11405 22A2: MOVWF FEA
11406 22A4: MOVFF FEF,00 11406 22A4: MOVFF FEF,00
11407 22A8: MOVFF FEC,01 11407 22A8: MOVFF FEC,01
11408 22AC: MOVFF FEC,02 11408 22AC: MOVFF FEC,02
11409 22B0: MOVFF FEC,03 11409 22B0: MOVFF FEC,03
11410 22B4: MOVFF FEA,3B2 11410 22B4: MOVFF FEA,3B2
11411 22B8: MOVFF FE9,3B1 11411 22B8: MOVFF FE9,3B1
11412 22BC: BCF FD8.1 11412 22BC: BCF FD8.1
11413 22BE: MOVFF 3AF,6ED 11413 22BE: MOVFF 3AF,6ED
11414 22C2: MOVFF 3AE,6EC 11414 22C2: MOVFF 3AE,6EC
11415 22C6: MOVFF 3AD,6EB 11415 22C6: MOVFF 3AD,6EB
11416 22CA: MOVFF 3AC,6EA 11416 22CA: MOVFF 3AC,6EA
11417 22CE: MOVFF 03,6F1 11417 22CE: MOVFF 03,6F1
11418 22D2: MOVFF 02,6F0 11418 22D2: MOVFF 02,6F0
11419 22D6: MOVFF 01,6EF 11419 22D6: MOVFF 01,6EF
11420 22DA: MOVFF 00,6EE 11420 22DA: MOVFF 00,6EE
11421 22DE: CALL 1442 11421 22DE: CALL 1442
11422 22E2: MOVFF 3B2,FEA 11422 22E2: MOVFF 3B2,FEA
11423 22E6: MOVFF 3B1,FE9 11423 22E6: MOVFF 3B1,FE9
11424 22EA: MOVFF 03,3AF 11424 22EA: MOVFF 03,3AF
11425 22EE: MOVFF 02,3AE 11425 22EE: MOVFF 02,3AE
11426 22F2: MOVFF 01,3AD 11426 22F2: MOVFF 01,3AD
11427 22F6: MOVFF 00,3AC 11427 22F6: MOVFF 00,3AC
11428 .................... } 11428 .................... }
11429 22FA: MOVLB 3 11429 22FA: MOVLB 3
11430 22FC: INCF xB0,F 11430 22FC: INCF xB0,F
11431 22FE: BRA 2022 11431 22FE: BRA 2022
11432 .................... 11432 ....................
11433 .................... xavg=xavg/BUFLEN; 11433 .................... xavg=xavg/BUFLEN;
11434 2300: MOVFF 3A7,6ED 11434 2300: MOVFF 3A7,6ED
11435 2304: MOVFF 3A6,6EC 11435 2304: MOVFF 3A6,6EC
11436 2308: MOVFF 3A5,6EB 11436 2308: MOVFF 3A5,6EB
11437 230C: MOVFF 3A4,6EA 11437 230C: MOVFF 3A4,6EA
11438 2310: MOVLB 6 11438 2310: MOVLB 6
11439 2312: CLRF xF1 11439 2312: CLRF xF1
11440 2314: CLRF xF0 11440 2314: CLRF xF0
11441 2316: MOVLW 48 11441 2316: MOVLW 48
11442 2318: MOVWF xEF 11442 2318: MOVWF xEF
11443 231A: MOVLW 85 11443 231A: MOVLW 85
11444 231C: MOVWF xEE 11444 231C: MOVWF xEE
11445 231E: MOVLB 0 11445 231E: MOVLB 0
11446 2320: CALL 16BA 11446 2320: CALL 16BA
11447 2324: MOVFF 03,3A7 11447 2324: MOVFF 03,3A7
11448 2328: MOVFF 02,3A6 11448 2328: MOVFF 02,3A6
11449 232C: MOVFF 01,3A5 11449 232C: MOVFF 01,3A5
11450 2330: MOVFF 00,3A4 11450 2330: MOVFF 00,3A4
11451 .................... yavg=yavg/BUFLEN; 11451 .................... yavg=yavg/BUFLEN;
11452 2334: MOVFF 3AB,6ED 11452 2334: MOVFF 3AB,6ED
11453 2338: MOVFF 3AA,6EC 11453 2338: MOVFF 3AA,6EC
11454 233C: MOVFF 3A9,6EB 11454 233C: MOVFF 3A9,6EB
11455 2340: MOVFF 3A8,6EA 11455 2340: MOVFF 3A8,6EA
11456 2344: MOVLB 6 11456 2344: MOVLB 6
11457 2346: CLRF xF1 11457 2346: CLRF xF1
11458 2348: CLRF xF0 11458 2348: CLRF xF0
11459 234A: MOVLW 48 11459 234A: MOVLW 48
11460 234C: MOVWF xEF 11460 234C: MOVWF xEF
11461 234E: MOVLW 85 11461 234E: MOVLW 85
11462 2350: MOVWF xEE 11462 2350: MOVWF xEE
11463 2352: MOVLB 0 11463 2352: MOVLB 0
11464 2354: CALL 16BA 11464 2354: CALL 16BA
11465 2358: MOVFF 03,3AB 11465 2358: MOVFF 03,3AB
11466 235C: MOVFF 02,3AA 11466 235C: MOVFF 02,3AA
11467 2360: MOVFF 01,3A9 11467 2360: MOVFF 01,3A9
11468 2364: MOVFF 00,3A8 11468 2364: MOVFF 00,3A8
11469 .................... zavg=zavg/BUFLEN; 11469 .................... zavg=zavg/BUFLEN;
11470 2368: MOVFF 3AF,6ED 11470 2368: MOVFF 3AF,6ED
11471 236C: MOVFF 3AE,6EC 11471 236C: MOVFF 3AE,6EC
11472 2370: MOVFF 3AD,6EB 11472 2370: MOVFF 3AD,6EB
11473 2374: MOVFF 3AC,6EA 11473 2374: MOVFF 3AC,6EA
11474 2378: MOVLB 6 11474 2378: MOVLB 6
11475 237A: CLRF xF1 11475 237A: CLRF xF1
11476 237C: CLRF xF0 11476 237C: CLRF xF0
11477 237E: MOVLW 48 11477 237E: MOVLW 48
11478 2380: MOVWF xEF 11478 2380: MOVWF xEF
11479 2382: MOVLW 85 11479 2382: MOVLW 85
11480 2384: MOVWF xEE 11480 2384: MOVWF xEE
11481 2386: MOVLB 0 11481 2386: MOVLB 0
11482 2388: CALL 16BA 11482 2388: CALL 16BA
11483 238C: MOVFF 03,3AF 11483 238C: MOVFF 03,3AF
11484 2390: MOVFF 02,3AE 11484 2390: MOVFF 02,3AE
11485 2394: MOVFF 01,3AD 11485 2394: MOVFF 01,3AD
11486 2398: MOVFF 00,3AC 11486 2398: MOVFF 00,3AC
11487 .................... 11487 ....................
11488 .................... // odesli namerene hodnoty 11488 .................... // odesli namerene hodnoty
11489 .................... printf(usb_cdc_putc, "%7.3f %4.3f %4.3f %4.3f %4.3f %4.3f %4.3f \n\r",((time << 16) + get_timer0())/15625.0, xavg, quadraticerror(xavg,x,BUFLEN), yavg, quadraticerror(yavg,y,BUFLEN), zavg, quadraticerror(zavg,z,BUFLEN)); //konstanta k je kvuli prevodu do rozzumnych jednotek [s] 11489 .................... printf(usb_cdc_putc, "%7.3f %4.3f %4.3f %4.3f %4.3f %4.3f %4.3f \n\r",((time << 16) + get_timer0())/15625.0, xavg, quadraticerror(xavg,x,BUFLEN), yavg, quadraticerror(yavg,y,BUFLEN), zavg, quadraticerror(zavg,z,BUFLEN)); //konstanta k je kvuli prevodu do rozzumnych jednotek [s]
11490 239C: MOVFF 1A,3B5 11490 239C: MOVFF 1A,3B5
11491 23A0: MOVFF 19,3B4 11491 23A0: MOVFF 19,3B4
11492 23A4: MOVLB 3 11492 23A4: MOVLB 3
11493 23A6: CLRF xB2 11493 23A6: CLRF xB2
11494 23A8: CLRF xB3 11494 23A8: CLRF xB3
11495 23AA: MOVF FD6,W 11495 23AA: MOVF FD6,W
11496 23AC: MOVFF FD7,03 11496 23AC: MOVFF FD7,03
11497 23B0: ADDWF xB2,F 11497 23B0: ADDWF xB2,F
11498 23B2: MOVF FD7,W 11498 23B2: MOVF FD7,W
11499 23B4: ADDWFC xB3,F 11499 23B4: ADDWFC xB3,F
11500 23B6: MOVLW 00 11500 23B6: MOVLW 00
11501 23B8: ADDWFC xB4,F 11501 23B8: ADDWFC xB4,F
11502 23BA: ADDWFC xB5,F 11502 23BA: ADDWFC xB5,F
11503 23BC: MOVFF 3B5,6C5 11503 23BC: MOVFF 3B5,6C5
11504 23C0: MOVFF 3B4,6C4 11504 23C0: MOVFF 3B4,6C4
11505 23C4: MOVFF 3B3,6C3 11505 23C4: MOVFF 3B3,6C3
11506 23C8: MOVFF 3B2,6C2 11506 23C8: MOVFF 3B2,6C2
11507 23CC: MOVLB 0 11507 23CC: MOVLB 0
11508 23CE: GOTO 1818 11508 23CE: GOTO 1818
11509 23D2: MOVFF 03,6ED 11509 23D2: MOVFF 03,6ED
11510 23D6: MOVFF 02,6EC 11510 23D6: MOVFF 02,6EC
11511 23DA: MOVFF 01,6EB 11511 23DA: MOVFF 01,6EB
11512 23DE: MOVFF 00,6EA 11512 23DE: MOVFF 00,6EA
11513 23E2: MOVLB 6 11513 23E2: MOVLB 6
11514 23E4: CLRF xF1 11514 23E4: CLRF xF1
11515 23E6: MOVLW 24 11515 23E6: MOVLW 24
11516 23E8: MOVWF xF0 11516 23E8: MOVWF xF0
11517 23EA: MOVLW 74 11517 23EA: MOVLW 74
11518 23EC: MOVWF xEF 11518 23EC: MOVWF xEF
11519 23EE: MOVLW 8C 11519 23EE: MOVLW 8C
11520 23F0: MOVWF xEE 11520 23F0: MOVWF xEE
11521 23F2: MOVLB 0 11521 23F2: MOVLB 0
11522 23F4: CALL 16BA 11522 23F4: CALL 16BA
11523 23F8: MOVFF 00,3B2 11523 23F8: MOVFF 00,3B2
11524 23FC: MOVFF 01,3B3 11524 23FC: MOVFF 01,3B3
11525 2400: MOVFF 02,3B4 11525 2400: MOVFF 02,3B4
11526 2404: MOVFF 03,3B5 11526 2404: MOVFF 03,3B5
11527 2408: MOVFF 3A7,6CD 11527 2408: MOVFF 3A7,6CD
11528 240C: MOVFF 3A6,6CC 11528 240C: MOVFF 3A6,6CC
11529 2410: MOVFF 3A5,6CB 11529 2410: MOVFF 3A5,6CB
11530 2414: MOVFF 3A4,6CA 11530 2414: MOVFF 3A4,6CA
11531 2418: MOVLB 6 11531 2418: MOVLB 6
11532 241A: CLRF xCF 11532 241A: CLRF xCF
11533 241C: MOVLW 84 11533 241C: MOVLW 84
11534 241E: MOVWF xCE 11534 241E: MOVWF xCE
11535 2420: CLRF xD1 11535 2420: CLRF xD1
11536 2422: MOVLW 64 11536 2422: MOVLW 64
11537 2424: MOVWF xD0 11537 2424: MOVWF xD0
11538 2426: MOVLB 0 11538 2426: MOVLB 0
11539 2428: CALL 1AE2 11539 2428: CALL 1AE2
11540 242C: MOVFF 00,3B6 11540 242C: MOVFF 00,3B6
11541 2430: MOVFF 01,3B7 11541 2430: MOVFF 01,3B7
11542 2434: MOVFF 02,3B8 11542 2434: MOVFF 02,3B8
11543 2438: MOVFF 03,3B9 11543 2438: MOVFF 03,3B9
11544 243C: MOVFF 3AB,6CD 11544 243C: MOVFF 3AB,6CD
11545 2440: MOVFF 3AA,6CC 11545 2440: MOVFF 3AA,6CC
11546 2444: MOVFF 3A9,6CB 11546 2444: MOVFF 3A9,6CB
11547 2448: MOVFF 3A8,6CA 11547 2448: MOVFF 3A8,6CA
11548 244C: MOVLW 02 11548 244C: MOVLW 02
11549 244E: MOVLB 6 11549 244E: MOVLB 6
11550 2450: MOVWF xCF 11550 2450: MOVWF xCF
11551 2452: MOVLW 14 11551 2452: MOVLW 14
11552 2454: MOVWF xCE 11552 2454: MOVWF xCE
11553 2456: CLRF xD1 11553 2456: CLRF xD1
11554 2458: MOVLW 64 11554 2458: MOVLW 64
11555 245A: MOVWF xD0 11555 245A: MOVWF xD0
11556 245C: MOVLB 0 11556 245C: MOVLB 0
11557 245E: CALL 1AE2 11557 245E: CALL 1AE2
11558 2462: MOVFF 00,3BA 11558 2462: MOVFF 00,3BA
11559 2466: MOVFF 01,3BB 11559 2466: MOVFF 01,3BB
11560 246A: MOVFF 02,3BC 11560 246A: MOVFF 02,3BC
11561 246E: MOVFF 03,3BD 11561 246E: MOVFF 03,3BD
11562 2472: MOVFF 3AF,6CD 11562 2472: MOVFF 3AF,6CD
11563 2476: MOVFF 3AE,6CC 11563 2476: MOVFF 3AE,6CC
11564 247A: MOVFF 3AD,6CB 11564 247A: MOVFF 3AD,6CB
11565 247E: MOVFF 3AC,6CA 11565 247E: MOVFF 3AC,6CA
11566 2482: MOVLW 05 11566 2482: MOVLW 05
11567 2484: MOVLB 6 11567 2484: MOVLB 6
11568 2486: MOVWF xCF 11568 2486: MOVWF xCF
11569 2488: MOVLW 20 11569 2488: MOVLW 20
11570 248A: MOVWF xCE 11570 248A: MOVWF xCE
11571 248C: CLRF xD1 11571 248C: CLRF xD1
11572 248E: MOVLW 64 11572 248E: MOVLW 64
11573 2490: MOVWF xD0 11573 2490: MOVWF xD0
11574 2492: MOVLB 0 11574 2492: MOVLB 0
11575 2494: CALL 1AE2 11575 2494: CALL 1AE2
11576 2498: MOVFF 00,3BE 11576 2498: MOVFF 00,3BE
11577 249C: MOVFF 01,3BF 11577 249C: MOVFF 01,3BF
11578 24A0: MOVFF 02,3C0 11578 24A0: MOVFF 02,3C0
11579 24A4: MOVFF 03,3C1 11579 24A4: MOVFF 03,3C1
11580 24A8: MOVLW 06 11580 24A8: MOVLW 06
11581 24AA: MOVWF FE9 11581 24AA: MOVWF FE9
11582 24AC: MOVFF 3B5,6D1 11582 24AC: MOVFF 3B5,6D1
11583 24B0: MOVFF 3B4,6D0 11583 24B0: MOVFF 3B4,6D0
11584 24B4: MOVFF 3B3,6CF 11584 24B4: MOVFF 3B3,6CF
11585 24B8: MOVFF 3B2,6CE 11585 24B8: MOVFF 3B2,6CE
11586 24BC: MOVLW 03 11586 24BC: MOVLW 03
11587 24BE: MOVLB 6 11587 24BE: MOVLB 6
11588 24C0: MOVWF xD2 11588 24C0: MOVWF xD2
11589 24C2: MOVLB 0 11589 24C2: MOVLB 0
11590 24C4: RCALL 1DB0 11590 24C4: RCALL 1DB0
11591 24C6: MOVLW 20 11591 24C6: MOVLW 20
11592 24C8: MOVLB 6 11592 24C8: MOVLB 6
11593 24CA: MOVWF xDB 11593 24CA: MOVWF xDB
11594 24CC: MOVLB 0 11594 24CC: MOVLB 0
11595 24CE: CALL 13D4 11595 24CE: CALL 13D4
11596 24D2: MOVLW 03 11596 24D2: MOVLW 03
11597 24D4: MOVWF FE9 11597 24D4: MOVWF FE9
11598 24D6: MOVFF 3A7,6D1 11598 24D6: MOVFF 3A7,6D1
11599 24DA: MOVFF 3A6,6D0 11599 24DA: MOVFF 3A6,6D0
11600 24DE: MOVFF 3A5,6CF 11600 24DE: MOVFF 3A5,6CF
11601 24E2: MOVFF 3A4,6CE 11601 24E2: MOVFF 3A4,6CE
11602 24E6: MOVLB 6 11602 24E6: MOVLB 6
11603 24E8: MOVWF xD2 11603 24E8: MOVWF xD2
11604 24EA: MOVLB 0 11604 24EA: MOVLB 0
11605 24EC: RCALL 1DB0 11605 24EC: RCALL 1DB0
11606 24EE: MOVLW 20 11606 24EE: MOVLW 20
11607 24F0: MOVLB 6 11607 24F0: MOVLB 6
11608 24F2: MOVWF xDB 11608 24F2: MOVWF xDB
11609 24F4: MOVLB 0 11609 24F4: MOVLB 0
11610 24F6: CALL 13D4 11610 24F6: CALL 13D4
11611 24FA: MOVLW 03 11611 24FA: MOVLW 03
11612 24FC: MOVWF FE9 11612 24FC: MOVWF FE9
11613 24FE: MOVFF 3B9,6D1 11613 24FE: MOVFF 3B9,6D1
11614 2502: MOVFF 3B8,6D0 11614 2502: MOVFF 3B8,6D0
11615 2506: MOVFF 3B7,6CF 11615 2506: MOVFF 3B7,6CF
11616 250A: MOVFF 3B6,6CE 11616 250A: MOVFF 3B6,6CE
11617 250E: MOVLB 6 11617 250E: MOVLB 6
11618 2510: MOVWF xD2 11618 2510: MOVWF xD2
11619 2512: MOVLB 0 11619 2512: MOVLB 0
11620 2514: RCALL 1DB0 11620 2514: RCALL 1DB0
11621 2516: MOVLW 20 11621 2516: MOVLW 20
11622 2518: MOVLB 6 11622 2518: MOVLB 6
11623 251A: MOVWF xDB 11623 251A: MOVWF xDB
11624 251C: MOVLB 0 11624 251C: MOVLB 0
11625 251E: CALL 13D4 11625 251E: CALL 13D4
11626 2522: MOVLW 03 11626 2522: MOVLW 03
11627 2524: MOVWF FE9 11627 2524: MOVWF FE9
11628 2526: MOVFF 3AB,6D1 11628 2526: MOVFF 3AB,6D1
11629 252A: MOVFF 3AA,6D0 11629 252A: MOVFF 3AA,6D0
11630 252E: MOVFF 3A9,6CF 11630 252E: MOVFF 3A9,6CF
11631 2532: MOVFF 3A8,6CE 11631 2532: MOVFF 3A8,6CE
11632 2536: MOVLB 6 11632 2536: MOVLB 6
11633 2538: MOVWF xD2 11633 2538: MOVWF xD2
11634 253A: MOVLB 0 11634 253A: MOVLB 0
11635 253C: RCALL 1DB0 11635 253C: RCALL 1DB0
11636 253E: MOVLW 20 11636 253E: MOVLW 20
11637 2540: MOVLB 6 11637 2540: MOVLB 6
11638 2542: MOVWF xDB 11638 2542: MOVWF xDB
11639 2544: MOVLB 0 11639 2544: MOVLB 0
11640 2546: CALL 13D4 11640 2546: CALL 13D4
11641 254A: MOVLW 03 11641 254A: MOVLW 03
11642 254C: MOVWF FE9 11642 254C: MOVWF FE9
11643 254E: MOVFF 3BD,6D1 11643 254E: MOVFF 3BD,6D1
11644 2552: MOVFF 3BC,6D0 11644 2552: MOVFF 3BC,6D0
11645 2556: MOVFF 3BB,6CF 11645 2556: MOVFF 3BB,6CF
11646 255A: MOVFF 3BA,6CE 11646 255A: MOVFF 3BA,6CE
11647 255E: MOVLB 6 11647 255E: MOVLB 6
11648 2560: MOVWF xD2 11648 2560: MOVWF xD2
11649 2562: MOVLB 0 11649 2562: MOVLB 0
11650 2564: RCALL 1DB0 11650 2564: RCALL 1DB0
11651 2566: MOVLW 20 11651 2566: MOVLW 20
11652 2568: MOVLB 6 11652 2568: MOVLB 6
11653 256A: MOVWF xDB 11653 256A: MOVWF xDB
11654 256C: MOVLB 0 11654 256C: MOVLB 0
11655 256E: CALL 13D4 11655 256E: CALL 13D4
11656 2572: MOVLW 03 11656 2572: MOVLW 03
11657 2574: MOVWF FE9 11657 2574: MOVWF FE9
11658 2576: MOVFF 3AF,6D1 11658 2576: MOVFF 3AF,6D1
11659 257A: MOVFF 3AE,6D0 11659 257A: MOVFF 3AE,6D0
11660 257E: MOVFF 3AD,6CF 11660 257E: MOVFF 3AD,6CF
11661 2582: MOVFF 3AC,6CE 11661 2582: MOVFF 3AC,6CE
11662 2586: MOVLB 6 11662 2586: MOVLB 6
11663 2588: MOVWF xD2 11663 2588: MOVWF xD2
11664 258A: MOVLB 0 11664 258A: MOVLB 0
11665 258C: RCALL 1DB0 11665 258C: RCALL 1DB0
11666 258E: MOVLW 20 11666 258E: MOVLW 20
11667 2590: MOVLB 6 11667 2590: MOVLB 6
11668 2592: MOVWF xDB 11668 2592: MOVWF xDB
11669 2594: MOVLB 0 11669 2594: MOVLB 0
11670 2596: CALL 13D4 11670 2596: CALL 13D4
11671 259A: MOVLW 03 11671 259A: MOVLW 03
11672 259C: MOVWF FE9 11672 259C: MOVWF FE9
11673 259E: MOVFF 3C1,6D1 11673 259E: MOVFF 3C1,6D1
11674 25A2: MOVFF 3C0,6D0 11674 25A2: MOVFF 3C0,6D0
11675 25A6: MOVFF 3BF,6CF 11675 25A6: MOVFF 3BF,6CF
11676 25AA: MOVFF 3BE,6CE 11676 25AA: MOVFF 3BE,6CE
11677 25AE: MOVLB 6 11677 25AE: MOVLB 6
11678 25B0: MOVWF xD2 11678 25B0: MOVWF xD2
11679 25B2: MOVLB 0 11679 25B2: MOVLB 0
11680 25B4: CALL 1DB0 11680 25B4: CALL 1DB0
11681 25B8: MOVLW 20 11681 25B8: MOVLW 20
11682 25BA: MOVLB 6 11682 25BA: MOVLB 6
11683 25BC: MOVWF xDB 11683 25BC: MOVWF xDB
11684 25BE: MOVLB 0 11684 25BE: MOVLB 0
11685 25C0: CALL 13D4 11685 25C0: CALL 13D4
11686 25C4: MOVLW 0A 11686 25C4: MOVLW 0A
11687 25C6: MOVLB 6 11687 25C6: MOVLB 6
11688 25C8: MOVWF xDB 11688 25C8: MOVWF xDB
11689 25CA: MOVLB 0 11689 25CA: MOVLB 0
11690 25CC: CALL 13D4 11690 25CC: CALL 13D4
11691 25D0: MOVLW 0D 11691 25D0: MOVLW 0D
11692 25D2: MOVLB 6 11692 25D2: MOVLB 6
11693 25D4: MOVWF xDB 11693 25D4: MOVWF xDB
11694 25D6: MOVLB 0 11694 25D6: MOVLB 0
11695 25D8: CALL 13D4 11695 25D8: CALL 13D4
11696 .................... } 11696 .................... }
11697 25DC: BRA 201A 11697 25DC: BRA 201A
11698 .................... } 11698 .................... }
11699 25DE: SLEEP 11699 25DE: SLEEP
11700   11700  
11701 Configuration Fuses: 11701 Configuration Fuses:
11702 Word 1: CE3C IESO FCMEN HSPLL PLL5 CPUDIV4 USBDIV 11702 Word 1: CE3C IESO FCMEN HSPLL PLL5 CPUDIV4 USBDIV
11703 Word 2: 0E39 NOBROWNOUT WDT128 NOWDT BORV20 NOPUT VREGEN 11703 Word 2: 0E39 NOBROWNOUT WDT128 NOWDT BORV20 NOPUT VREGEN
11704 Word 3: 8700 PBADEN CCP2C1 MCLR LPT1OSC 11704 Word 3: 8700 PBADEN CCP2C1 MCLR LPT1OSC
11705 Word 4: 00A1 STVREN NODEBUG NOLVP NOXINST ICPRT 11705 Word 4: 00A1 STVREN NODEBUG NOLVP NOXINST ICPRT
11706 Word 5: C00F NOPROTECT NOCPD NOCPB 11706 Word 5: C00F NOPROTECT NOCPD NOCPB
11707 Word 6: E00F NOWRT NOWRTD NOWRTC NOWRTB 11707 Word 6: E00F NOWRT NOWRTD NOWRTC NOWRTB
11708 Word 7: 400F NOEBTR NOEBTRB 11708 Word 7: 400F NOEBTR NOEBTRB