7 |
pfowler |
1 |
1 # 1 "vusb-20120109/usbdrv/usbdrvasm.S"
|
|
|
2 |
1 /* Name: usbdrvasm.S
|
|
|
3 |
|
|
|
4 |
|
|
|
5 |
2 * Project: V-USB, virtual USB port for Atmel's(r) AVR(r) microcontrollers
|
|
|
6 |
3 * Author: Christian Starkjohann
|
|
|
7 |
4 * Creation Date: 2007-06-13
|
|
|
8 |
5 * Tabsize: 4
|
|
|
9 |
6 * Copyright: (c) 2007 by OBJECTIVE DEVELOPMENT Software GmbH
|
|
|
10 |
7 * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
|
|
|
11 |
8 * Revision: $Id$
|
|
|
12 |
9 */
|
|
|
13 |
10
|
|
|
14 |
11 /*
|
|
|
15 |
12 General Description:
|
|
|
16 |
13 This module is the assembler part of the USB driver. This file contains
|
|
|
17 |
14 general code (preprocessor acrobatics and CRC computation) and then includes
|
|
|
18 |
15 the file appropriate for the given clock rate.
|
|
|
19 |
16 */
|
|
|
20 |
17
|
|
|
21 |
18 #define __SFR_OFFSET 0 /* used by avr-libc's register definitions */
|
|
|
22 |
19 #include "usbportability.h"
|
|
|
23 |
1 /* Name: usbportability.h
|
|
|
24 |
2 * Project: V-USB, virtual USB port for Atmel's(r) AVR(r) microcontrollers
|
|
|
25 |
3 * Author: Christian Starkjohann
|
|
|
26 |
4 * Creation Date: 2008-06-17
|
|
|
27 |
5 * Tabsize: 4
|
|
|
28 |
6 * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
|
|
|
29 |
7 * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
|
|
|
30 |
8 * This Revision: $Id$
|
|
|
31 |
9 */
|
|
|
32 |
10
|
|
|
33 |
11 /*
|
|
|
34 |
12 General Description:
|
|
|
35 |
13 This header is intended to contain all (or at least most of) the compiler
|
|
|
36 |
14 and library dependent stuff. The C code is written for avr-gcc and avr-libc.
|
|
|
37 |
15 The API of other development environments is converted to gcc's and avr-libc's
|
|
|
38 |
16 API by means of defines.
|
|
|
39 |
17
|
|
|
40 |
18 This header also contains all system includes since they depend on the
|
|
|
41 |
19 development environment.
|
|
|
42 |
20
|
|
|
43 |
21 Thanks to Oleg Semyonov for his help with the IAR tools port!
|
|
|
44 |
22 */
|
|
|
45 |
23
|
|
|
46 |
24 #ifndef __usbportability_h_INCLUDED__
|
|
|
47 |
25 #define __usbportability_h_INCLUDED__
|
|
|
48 |
26
|
|
|
49 |
27 /* We check explicitly for IAR and CodeVision. Default is avr-gcc/avr-libc. */
|
|
|
50 |
28
|
|
|
51 |
29 /* ------------------------------------------------------------------------- */
|
|
|
52 |
30 #if defined __IAR_SYSTEMS_ICC__ || defined __IAR_SYSTEMS_ASM__ /* check for IAR */
|
|
|
53 |
31 /* ------------------------------------------------------------------------- */
|
|
|
54 |
32
|
|
|
55 |
33 #ifndef ENABLE_BIT_DEFINITIONS
|
|
|
56 |
34 # define ENABLE_BIT_DEFINITIONS 1 /* Enable bit definitions */
|
|
|
57 |
35 #endif
|
|
|
58 |
36
|
|
|
59 |
37 /* Include IAR headers */
|
|
|
60 |
38 #include <ioavr.h>
|
|
|
61 |
39 #ifndef __IAR_SYSTEMS_ASM__
|
|
|
62 |
40 # include <inavr.h>
|
|
|
63 |
41 #endif
|
|
|
64 |
42
|
|
|
65 |
43 #define __attribute__(arg) /* not supported on IAR */
|
|
|
66 |
44
|
|
|
67 |
45 #ifdef __IAR_SYSTEMS_ASM__
|
|
|
68 |
46 # define __ASSEMBLER__ /* IAR does not define standard macro for asm */
|
|
|
69 |
47 #endif
|
|
|
70 |
48
|
|
|
71 |
49 #ifdef __HAS_ELPM__
|
|
|
72 |
50 # define PROGMEM __farflash
|
|
|
73 |
51 #else
|
|
|
74 |
52 # define PROGMEM __flash
|
|
|
75 |
53 #endif
|
|
|
76 |
54
|
|
|
77 |
55 #define USB_READ_FLASH(addr) (*(PROGMEM char *)(addr))
|
|
|
78 |
56
|
|
|
79 |
57 /* The following definitions are not needed by the driver, but may be of some
|
|
|
80 |
58 * help if you port a gcc based project to IAR.
|
|
|
81 |
59 */
|
|
|
82 |
60 #define cli() __disable_interrupt()
|
|
|
83 |
61 #define sei() __enable_interrupt()
|
|
|
84 |
62 #define wdt_reset() __watchdog_reset()
|
|
|
85 |
63 #define _BV(x) (1 << (x))
|
|
|
86 |
64
|
|
|
87 |
65 /* assembler compatibility macros */
|
|
|
88 |
66 #define nop2 rjmp $+2 /* jump to next instruction */
|
|
|
89 |
67 #define XL r26
|
|
|
90 |
68 #define XH r27
|
|
|
91 |
69 #define YL r28
|
|
|
92 |
70 #define YH r29
|
|
|
93 |
71 #define ZL r30
|
|
|
94 |
72 #define ZH r31
|
|
|
95 |
73 #define lo8(x) LOW(x)
|
|
|
96 |
74 #define hi8(x) (((x)>>8) & 0xff) /* not HIGH to allow XLINK to make a proper range check */
|
|
|
97 |
75
|
|
|
98 |
76 /* Depending on the device you use, you may get problems with the way usbdrv.h
|
|
|
99 |
77 * handles the differences between devices. Since IAR does not use #defines
|
|
|
100 |
78 * for MCU registers, we can't check for the existence of a particular
|
|
|
101 |
79 * register with an #ifdef. If the autodetection mechanism fails, include
|
|
|
102 |
80 * definitions for the required USB_INTR_* macros in your usbconfig.h. See
|
|
|
103 |
81 * usbconfig-prototype.h and usbdrv.h for details.
|
|
|
104 |
82 */
|
|
|
105 |
83
|
|
|
106 |
84 /* ------------------------------------------------------------------------- */
|
|
|
107 |
85 #elif __CODEVISIONAVR__ /* check for CodeVision AVR */
|
|
|
108 |
86 /* ------------------------------------------------------------------------- */
|
|
|
109 |
87 /* This port is not working (yet) */
|
|
|
110 |
88
|
|
|
111 |
89 /* #define F_CPU _MCU_CLOCK_FREQUENCY_ seems to be defined automatically */
|
|
|
112 |
90
|
|
|
113 |
91 #include <io.h>
|
|
|
114 |
92 #include <delay.h>
|
|
|
115 |
93
|
|
|
116 |
94 #define __attribute__(arg) /* not supported on IAR */
|
|
|
117 |
95
|
|
|
118 |
96 #define PROGMEM __flash
|
|
|
119 |
97 #define USB_READ_FLASH(addr) (*(PROGMEM char *)(addr))
|
|
|
120 |
98
|
|
|
121 |
99 #ifndef __ASSEMBLER__
|
|
|
122 |
100 static inline void cli(void)
|
|
|
123 |
101 {
|
|
|
124 |
102 #asm("cli");
|
|
|
125 |
103 }
|
|
|
126 |
104 static inline void sei(void)
|
|
|
127 |
105 {
|
|
|
128 |
106 #asm("sei");
|
|
|
129 |
107 }
|
|
|
130 |
108 #endif
|
|
|
131 |
109 #define _delay_ms(t) delay_ms(t)
|
|
|
132 |
110 #define _BV(x) (1 << (x))
|
|
|
133 |
111 #define USB_CFG_USE_SWITCH_STATEMENT 1 /* macro for if() cascase fails for unknown reason */
|
|
|
134 |
112
|
|
|
135 |
113 #define macro .macro
|
|
|
136 |
114 #define endm .endmacro
|
|
|
137 |
115 #define nop2 rjmp .+0 /* jump to next instruction */
|
|
|
138 |
116
|
|
|
139 |
117 /* ------------------------------------------------------------------------- */
|
|
|
140 |
118 #else /* default development environment is avr-gcc/avr-libc */
|
|
|
141 |
119 /* ------------------------------------------------------------------------- */
|
|
|
142 |
120
|
|
|
143 |
121 #include <avr/io.h>
|
|
|
144 |
1 /* Copyright (c) 2002,2003,2005,2006,2007 Marek Michalkiewicz, Joerg Wunsch
|
|
|
145 |
2 Copyright (c) 2007 Eric B. Weddington
|
|
|
146 |
3 All rights reserved.
|
|
|
147 |
4
|
|
|
148 |
5 Redistribution and use in source and binary forms, with or without
|
|
|
149 |
6 modification, are permitted provided that the following conditions are met:
|
|
|
150 |
7
|
|
|
151 |
8 * Redistributions of source code must retain the above copyright
|
|
|
152 |
9 notice, this list of conditions and the following disclaimer.
|
|
|
153 |
10
|
|
|
154 |
11 * Redistributions in binary form must reproduce the above copyright
|
|
|
155 |
12 notice, this list of conditions and the following disclaimer in
|
|
|
156 |
13 the documentation and/or other materials provided with the
|
|
|
157 |
14 distribution.
|
|
|
158 |
15
|
|
|
159 |
16 * Neither the name of the copyright holders nor the names of
|
|
|
160 |
17 contributors may be used to endorse or promote products derived
|
|
|
161 |
18 from this software without specific prior written permission.
|
|
|
162 |
19
|
|
|
163 |
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
164 |
21 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
165 |
22 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
166 |
23 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
167 |
24 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
168 |
25 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
169 |
26 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
170 |
27 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
171 |
28 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
172 |
29 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
173 |
30 POSSIBILITY OF SUCH DAMAGE. */
|
|
|
174 |
31
|
|
|
175 |
32 /* $Id: io.h,v 1.52.2.28 2009/12/20 17:02:53 arcanum Exp $ */
|
|
|
176 |
33
|
|
|
177 |
34 /** \file */
|
|
|
178 |
35 /** \defgroup avr_io <avr/io.h>: AVR device-specific IO definitions
|
|
|
179 |
36 \code #include <avr/io.h> \endcode
|
|
|
180 |
37
|
|
|
181 |
38 This header file includes the apropriate IO definitions for the
|
|
|
182 |
39 device that has been specified by the <tt>-mmcu=</tt> compiler
|
|
|
183 |
40 command-line switch. This is done by diverting to the appropriate
|
|
|
184 |
41 file <tt><avr/io</tt><em>XXXX</em><tt>.h></tt> which should
|
|
|
185 |
42 never be included directly. Some register names common to all
|
|
|
186 |
43 AVR devices are defined directly within <tt><avr/common.h></tt>,
|
|
|
187 |
44 which is included in <tt><avr/io.h></tt>,
|
|
|
188 |
45 but most of the details come from the respective include file.
|
|
|
189 |
46
|
|
|
190 |
47 Note that this file always includes the following files:
|
|
|
191 |
48 \code
|
|
|
192 |
49 #include <avr/sfr_defs.h>
|
|
|
193 |
50 #include <avr/portpins.h>
|
|
|
194 |
51 #include <avr/common.h>
|
|
|
195 |
52 #include <avr/version.h>
|
|
|
196 |
53 \endcode
|
|
|
197 |
54 See \ref avr_sfr for more details about that header file.
|
|
|
198 |
55
|
|
|
199 |
56 Included are definitions of the IO register set and their
|
|
|
200 |
57 respective bit values as specified in the Atmel documentation.
|
|
|
201 |
58 Note that inconsistencies in naming conventions,
|
|
|
202 |
59 so even identical functions sometimes get different names on
|
|
|
203 |
60 different devices.
|
|
|
204 |
61
|
|
|
205 |
62 Also included are the specific names useable for interrupt
|
|
|
206 |
63 function definitions as documented
|
|
|
207 |
64 \ref avr_signames "here".
|
|
|
208 |
65
|
|
|
209 |
66 Finally, the following macros are defined:
|
|
|
210 |
67
|
|
|
211 |
68 - \b RAMEND
|
|
|
212 |
69 <br>
|
|
|
213 |
70 The last on-chip RAM address.
|
|
|
214 |
71 <br>
|
|
|
215 |
72 - \b XRAMEND
|
|
|
216 |
73 <br>
|
|
|
217 |
74 The last possible RAM location that is addressable. This is equal to
|
|
|
218 |
75 RAMEND for devices that do not allow for external RAM. For devices
|
|
|
219 |
76 that allow external RAM, this will be larger than RAMEND.
|
|
|
220 |
77 <br>
|
|
|
221 |
78 - \b E2END
|
|
|
222 |
79 <br>
|
|
|
223 |
80 The last EEPROM address.
|
|
|
224 |
81 <br>
|
|
|
225 |
82 - \b FLASHEND
|
|
|
226 |
83 <br>
|
|
|
227 |
84 The last byte address in the Flash program space.
|
|
|
228 |
85 <br>
|
|
|
229 |
86 - \b SPM_PAGESIZE
|
|
|
230 |
87 <br>
|
|
|
231 |
88 For devices with bootloader support, the flash pagesize
|
|
|
232 |
89 (in bytes) to be used for the \c SPM instruction.
|
|
|
233 |
90 - \b E2PAGESIZE
|
|
|
234 |
91 <br>
|
|
|
235 |
92 The size of the EEPROM page.
|
|
|
236 |
93
|
|
|
237 |
94 */
|
|
|
238 |
95
|
|
|
239 |
96 #ifndef _AVR_IO_H_
|
|
|
240 |
97 #define _AVR_IO_H_
|
|
|
241 |
98
|
|
|
242 |
99 #include <avr/sfr_defs.h>
|
|
|
243 |
1 /* Copyright (c) 2002, Marek Michalkiewicz <marekm@amelek.gda.pl>
|
|
|
244 |
100
|
|
|
245 |
101 #if defined (__AVR_AT94K__)
|
|
|
246 |
102 # include <avr/ioat94k.h>
|
|
|
247 |
103 #elif defined (__AVR_AT43USB320__)
|
|
|
248 |
104 # include <avr/io43u32x.h>
|
|
|
249 |
105 #elif defined (__AVR_AT43USB355__)
|
|
|
250 |
106 # include <avr/io43u35x.h>
|
|
|
251 |
107 #elif defined (__AVR_AT76C711__)
|
|
|
252 |
108 # include <avr/io76c711.h>
|
|
|
253 |
109 #elif defined (__AVR_AT86RF401__)
|
|
|
254 |
110 # include <avr/io86r401.h>
|
|
|
255 |
111 #elif defined (__AVR_AT90PWM1__)
|
|
|
256 |
112 # include <avr/io90pwm1.h>
|
|
|
257 |
113 #elif defined (__AVR_AT90PWM2__)
|
|
|
258 |
114 # include <avr/io90pwmx.h>
|
|
|
259 |
115 #elif defined (__AVR_AT90PWM2B__)
|
|
|
260 |
116 # include <avr/io90pwm2b.h>
|
|
|
261 |
117 #elif defined (__AVR_AT90PWM3__)
|
|
|
262 |
118 # include <avr/io90pwmx.h>
|
|
|
263 |
119 #elif defined (__AVR_AT90PWM3B__)
|
|
|
264 |
120 # include <avr/io90pwm3b.h>
|
|
|
265 |
121 #elif defined (__AVR_AT90PWM216__)
|
|
|
266 |
122 # include <avr/io90pwm216.h>
|
|
|
267 |
123 #elif defined (__AVR_AT90PWM316__)
|
|
|
268 |
124 # include <avr/io90pwm316.h>
|
|
|
269 |
125 #elif defined (__AVR_AT90PWM81__)
|
|
|
270 |
126 # include <avr/io90pwm81.h>
|
|
|
271 |
127 #elif defined (__AVR_ATmega8U2__)
|
|
|
272 |
128 # include <avr/iom8u2.h>
|
|
|
273 |
129 #elif defined (__AVR_ATmega16M1__)
|
|
|
274 |
130 # include <avr/iom16m1.h>
|
|
|
275 |
131 #elif defined (__AVR_ATmega16U2__)
|
|
|
276 |
132 # include <avr/iom16u2.h>
|
|
|
277 |
133 #elif defined (__AVR_ATmega16U4__)
|
|
|
278 |
134 # include <avr/iom16u4.h>
|
|
|
279 |
135 #elif defined (__AVR_ATmega32C1__)
|
|
|
280 |
136 # include <avr/iom32c1.h>
|
|
|
281 |
137 #elif defined (__AVR_ATmega32M1__)
|
|
|
282 |
138 # include <avr/iom32m1.h>
|
|
|
283 |
139 #elif defined (__AVR_ATmega32U2__)
|
|
|
284 |
140 # include <avr/iom32u2.h>
|
|
|
285 |
141 #elif defined (__AVR_ATmega32U4__)
|
|
|
286 |
142 # include <avr/iom32u4.h>
|
|
|
287 |
143 #elif defined (__AVR_ATmega32U6__)
|
|
|
288 |
144 # include <avr/iom32u6.h>
|
|
|
289 |
145 #elif defined (__AVR_ATmega64C1__)
|
|
|
290 |
146 # include <avr/iom64c1.h>
|
|
|
291 |
147 #elif defined (__AVR_ATmega64M1__)
|
|
|
292 |
148 # include <avr/iom64m1.h>
|
|
|
293 |
149 #elif defined (__AVR_ATmega128__)
|
|
|
294 |
150 # include <avr/iom128.h>
|
|
|
295 |
151 #elif defined (__AVR_ATmega1280__)
|
|
|
296 |
152 # include <avr/iom1280.h>
|
|
|
297 |
153 #elif defined (__AVR_ATmega1281__)
|
|
|
298 |
154 # include <avr/iom1281.h>
|
|
|
299 |
155 #elif defined (__AVR_ATmega1284P__)
|
|
|
300 |
156 # include <avr/iom1284p.h>
|
|
|
301 |
157 #elif defined (__AVR_ATmega128RFA1__)
|
|
|
302 |
158 # include <avr/iom128rfa1.h>
|
|
|
303 |
159 #elif defined (__AVR_ATmega2560__)
|
|
|
304 |
160 # include <avr/iom2560.h>
|
|
|
305 |
161 #elif defined (__AVR_ATmega2561__)
|
|
|
306 |
162 # include <avr/iom2561.h>
|
|
|
307 |
163 #elif defined (__AVR_AT90CAN32__)
|
|
|
308 |
164 # include <avr/iocan32.h>
|
|
|
309 |
165 #elif defined (__AVR_AT90CAN64__)
|
|
|
310 |
166 # include <avr/iocan64.h>
|
|
|
311 |
167 #elif defined (__AVR_AT90CAN128__)
|
|
|
312 |
168 # include <avr/iocan128.h>
|
|
|
313 |
169 #elif defined (__AVR_AT90USB82__)
|
|
|
314 |
170 # include <avr/iousb82.h>
|
|
|
315 |
171 #elif defined (__AVR_AT90USB162__)
|
|
|
316 |
172 # include <avr/iousb162.h>
|
|
|
317 |
173 #elif defined (__AVR_AT90USB646__)
|
|
|
318 |
174 # include <avr/iousb646.h>
|
|
|
319 |
175 #elif defined (__AVR_AT90USB647__)
|
|
|
320 |
176 # include <avr/iousb647.h>
|
|
|
321 |
177 #elif defined (__AVR_AT90USB1286__)
|
|
|
322 |
178 # include <avr/iousb1286.h>
|
|
|
323 |
179 #elif defined (__AVR_AT90USB1287__)
|
|
|
324 |
180 # include <avr/iousb1287.h>
|
|
|
325 |
181 #elif defined (__AVR_ATmega64__)
|
|
|
326 |
182 # include <avr/iom64.h>
|
|
|
327 |
183 #elif defined (__AVR_ATmega640__)
|
|
|
328 |
184 # include <avr/iom640.h>
|
|
|
329 |
185 #elif defined (__AVR_ATmega644__) || defined (__AVR_ATmega644A__)
|
|
|
330 |
186 # include <avr/iom644.h>
|
|
|
331 |
187 #elif defined (__AVR_ATmega644P__)
|
|
|
332 |
188 # include <avr/iom644p.h>
|
|
|
333 |
189 #elif defined (__AVR_ATmega644PA__)
|
|
|
334 |
190 # include <avr/iom644pa.h>
|
|
|
335 |
191 #elif defined (__AVR_ATmega645__) || defined (__AVR_ATmega645A__) || defined (__AVR_ATmega645P__)
|
|
|
336 |
192 # include <avr/iom645.h>
|
|
|
337 |
193 #elif defined (__AVR_ATmega6450__) || defined (__AVR_ATmega6450A__) || defined (__AVR_ATmega6450P__
|
|
|
338 |
194 # include <avr/iom6450.h>
|
|
|
339 |
195 #elif defined (__AVR_ATmega649__) || defined (__AVR_ATmega649A__)
|
|
|
340 |
196 # include <avr/iom649.h>
|
|
|
341 |
197 #elif defined (__AVR_ATmega6490__) || defined (__AVR_ATmega6490A__) || defined (__AVR_ATmega6490P__
|
|
|
342 |
198 # include <avr/iom6490.h>
|
|
|
343 |
199 #elif defined (__AVR_ATmega649P__)
|
|
|
344 |
200 # include <avr/iom649p.h>
|
|
|
345 |
201 #elif defined (__AVR_ATmega64HVE__)
|
|
|
346 |
202 # include <avr/iom64hve.h>
|
|
|
347 |
203 #elif defined (__AVR_ATmega103__)
|
|
|
348 |
204 # include <avr/iom103.h>
|
|
|
349 |
205 #elif defined (__AVR_ATmega32__)
|
|
|
350 |
206 # include <avr/iom32.h>
|
|
|
351 |
207 #elif defined (__AVR_ATmega323__)
|
|
|
352 |
208 # include <avr/iom323.h>
|
|
|
353 |
209 #elif defined (__AVR_ATmega324P__) || defined (__AVR_ATmega324A__)
|
|
|
354 |
210 # include <avr/iom324.h>
|
|
|
355 |
211 #elif defined (__AVR_ATmega324PA__)
|
|
|
356 |
212 # include <avr/iom324pa.h>
|
|
|
357 |
213 #elif defined (__AVR_ATmega325__)
|
|
|
358 |
214 # include <avr/iom325.h>
|
|
|
359 |
215 #elif defined (__AVR_ATmega325P__)
|
|
|
360 |
216 # include <avr/iom325.h>
|
|
|
361 |
217 #elif defined (__AVR_ATmega3250__)
|
|
|
362 |
218 # include <avr/iom3250.h>
|
|
|
363 |
219 #elif defined (__AVR_ATmega3250P__)
|
|
|
364 |
220 # include <avr/iom3250.h>
|
|
|
365 |
221 #elif defined (__AVR_ATmega328P__) || defined (__AVR_ATmega328__)
|
|
|
366 |
222 # include <avr/iom328p.h>
|
|
|
367 |
223 #elif defined (__AVR_ATmega329__)
|
|
|
368 |
224 # include <avr/iom329.h>
|
|
|
369 |
225 #elif defined (__AVR_ATmega329P__) || defined (__AVR_ATmega329PA__)
|
|
|
370 |
226 # include <avr/iom329.h>
|
|
|
371 |
227 #elif defined (__AVR_ATmega3290__)
|
|
|
372 |
228 # include <avr/iom3290.h>
|
|
|
373 |
229 #elif defined (__AVR_ATmega3290P__)
|
|
|
374 |
230 # include <avr/iom3290.h>
|
|
|
375 |
231 #elif defined (__AVR_ATmega32HVB__)
|
|
|
376 |
232 # include <avr/iom32hvb.h>
|
|
|
377 |
233 #elif defined (__AVR_ATmega406__)
|
|
|
378 |
234 # include <avr/iom406.h>
|
|
|
379 |
235 #elif defined (__AVR_ATmega16__)
|
|
|
380 |
236 # include <avr/iom16.h>
|
|
|
381 |
237 #elif defined (__AVR_ATmega16A__)
|
|
|
382 |
238 # include <avr/iom16a.h>
|
|
|
383 |
239 #elif defined (__AVR_ATmega161__)
|
|
|
384 |
240 # include <avr/iom161.h>
|
|
|
385 |
241 #elif defined (__AVR_ATmega162__)
|
|
|
386 |
242 # include <avr/iom162.h>
|
|
|
387 |
243 #elif defined (__AVR_ATmega163__)
|
|
|
388 |
244 # include <avr/iom163.h>
|
|
|
389 |
245 #elif defined (__AVR_ATmega164P__) || defined (__AVR_ATmega164A__)
|
|
|
390 |
246 # include <avr/iom164.h>
|
|
|
391 |
247 #elif defined (__AVR_ATmega165__) || defined (__AVR_ATmega165A__)
|
|
|
392 |
248 # include <avr/iom165.h>
|
|
|
393 |
249 #elif defined (__AVR_ATmega165P__)
|
|
|
394 |
250 # include <avr/iom165p.h>
|
|
|
395 |
251 #elif defined (__AVR_ATmega168__) || defined (__AVR_ATmega168A__)
|
|
|
396 |
252 # include <avr/iom168.h>
|
|
|
397 |
253 #elif defined (__AVR_ATmega168P__)
|
|
|
398 |
254 # include <avr/iom168p.h>
|
|
|
399 |
255 #elif defined (__AVR_ATmega169__) || defined (__AVR_ATmega169A__)
|
|
|
400 |
256 # include <avr/iom169.h>
|
|
|
401 |
257 #elif defined (__AVR_ATmega169P__)
|
|
|
402 |
258 # include <avr/iom169p.h>
|
|
|
403 |
259 #elif defined (__AVR_ATmega169PA__)
|
|
|
404 |
260 # include <avr/iom169pa.h>
|
|
|
405 |
261 #elif defined (__AVR_ATmega8HVA__)
|
|
|
406 |
262 # include <avr/iom8hva.h>
|
|
|
407 |
263 #elif defined (__AVR_ATmega16HVA__)
|
|
|
408 |
264 # include <avr/iom16hva.h>
|
|
|
409 |
265 #elif defined (__AVR_ATmega16HVA2__)
|
|
|
410 |
266 # include <avr/iom16hva2.h>
|
|
|
411 |
267 #elif defined (__AVR_ATmega16HVB__)
|
|
|
412 |
268 # include <avr/iom16hvb.h>
|
|
|
413 |
269 #elif defined (__AVR_ATmega8__)
|
|
|
414 |
270 # include <avr/iom8.h>
|
|
|
415 |
271 #elif defined (__AVR_ATmega48__) || defined (__AVR_ATmega48A__)
|
|
|
416 |
272 # include <avr/iom48.h>
|
|
|
417 |
273 #elif defined (__AVR_ATmega48P__)
|
|
|
418 |
274 # include <avr/iom48p.h>
|
|
|
419 |
275 #elif defined (__AVR_ATmega88__) || defined (__AVR_ATmega88A__)
|
|
|
420 |
276 # include <avr/iom88.h>
|
|
|
421 |
277 #elif defined (__AVR_ATmega88P__)
|
|
|
422 |
278 # include <avr/iom88p.h>
|
|
|
423 |
279 #elif defined (__AVR_ATmega88PA__)
|
|
|
424 |
280 # include <avr/iom88pa.h>
|
|
|
425 |
281 #elif defined (__AVR_ATmega8515__)
|
|
|
426 |
282 # include <avr/iom8515.h>
|
|
|
427 |
283 #elif defined (__AVR_ATmega8535__)
|
|
|
428 |
284 # include <avr/iom8535.h>
|
|
|
429 |
285 #elif defined (__AVR_AT90S8535__)
|
|
|
430 |
286 # include <avr/io8535.h>
|
|
|
431 |
287 #elif defined (__AVR_AT90C8534__)
|
|
|
432 |
288 # include <avr/io8534.h>
|
|
|
433 |
289 #elif defined (__AVR_AT90S8515__)
|
|
|
434 |
290 # include <avr/io8515.h>
|
|
|
435 |
291 #elif defined (__AVR_AT90S4434__)
|
|
|
436 |
292 # include <avr/io4434.h>
|
|
|
437 |
293 #elif defined (__AVR_AT90S4433__)
|
|
|
438 |
294 # include <avr/io4433.h>
|
|
|
439 |
295 #elif defined (__AVR_AT90S4414__)
|
|
|
440 |
296 # include <avr/io4414.h>
|
|
|
441 |
297 #elif defined (__AVR_ATtiny22__)
|
|
|
442 |
298 # include <avr/iotn22.h>
|
|
|
443 |
299 #elif defined (__AVR_ATtiny26__)
|
|
|
444 |
300 # include <avr/iotn26.h>
|
|
|
445 |
301 #elif defined (__AVR_AT90S2343__)
|
|
|
446 |
302 # include <avr/io2343.h>
|
|
|
447 |
303 #elif defined (__AVR_AT90S2333__)
|
|
|
448 |
304 # include <avr/io2333.h>
|
|
|
449 |
305 #elif defined (__AVR_AT90S2323__)
|
|
|
450 |
306 # include <avr/io2323.h>
|
|
|
451 |
307 #elif defined (__AVR_AT90S2313__)
|
|
|
452 |
308 # include <avr/io2313.h>
|
|
|
453 |
309 #elif defined (__AVR_ATtiny2313__)
|
|
|
454 |
310 # include <avr/iotn2313.h>
|
|
|
455 |
311 #elif defined (__AVR_ATtiny2313A__)
|
|
|
456 |
312 # include <avr/iotn2313a.h>
|
|
|
457 |
313 #elif defined (__AVR_ATtiny13__)
|
|
|
458 |
314 # include <avr/iotn13.h>
|
|
|
459 |
315 #elif defined (__AVR_ATtiny13A__)
|
|
|
460 |
316 # include <avr/iotn13a.h>
|
|
|
461 |
317 #elif defined (__AVR_ATtiny25__)
|
|
|
462 |
318 # include <avr/iotn25.h>
|
|
|
463 |
319 #elif defined (__AVR_ATtiny4313__)
|
|
|
464 |
320 # include <avr/iotn4313.h>
|
|
|
465 |
321 #elif defined (__AVR_ATtiny45__)
|
|
|
466 |
322 # include <avr/iotn45.h>
|
|
|
467 |
323 #elif defined (__AVR_ATtiny85__)
|
|
|
468 |
324 # include <avr/iotn85.h>
|
|
|
469 |
1 /* Copyright (c) 2005, Joerg Wunsch
|
|
|
470 |
2 All rights reserved.
|
|
|
471 |
3
|
|
|
472 |
4 Redistribution and use in source and binary forms, with or without
|
|
|
473 |
5 modification, are permitted provided that the following conditions are met:
|
|
|
474 |
6
|
|
|
475 |
7 * Redistributions of source code must retain the above copyright
|
|
|
476 |
8 notice, this list of conditions and the following disclaimer.
|
|
|
477 |
9
|
|
|
478 |
10 * Redistributions in binary form must reproduce the above copyright
|
|
|
479 |
11 notice, this list of conditions and the following disclaimer in
|
|
|
480 |
12 the documentation and/or other materials provided with the
|
|
|
481 |
13 distribution.
|
|
|
482 |
14
|
|
|
483 |
15 * Neither the name of the copyright holders nor the names of
|
|
|
484 |
16 contributors may be used to endorse or promote products derived
|
|
|
485 |
17 from this software without specific prior written permission.
|
|
|
486 |
18
|
|
|
487 |
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
488 |
20 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
489 |
21 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
490 |
22 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
491 |
23 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
492 |
24 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
493 |
25 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
494 |
26 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
495 |
27 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
496 |
28 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
497 |
29 POSSIBILITY OF SUCH DAMAGE. */
|
|
|
498 |
30
|
|
|
499 |
31 /* $Id: iotn85.h,v 1.3.2.6 2009/02/11 18:05:33 arcanum Exp $ */
|
|
|
500 |
32
|
|
|
501 |
33 /* avr/iotn85.h - definitions for ATtiny85 */
|
|
|
502 |
34
|
|
|
503 |
35 #ifndef _AVR_IOTN85_H_
|
|
|
504 |
36 #define _AVR_IOTN85_H_ 1
|
|
|
505 |
37
|
|
|
506 |
38 #include <avr/iotnx5.h>
|
|
|
507 |
1 /* Copyright (c) 2005, 2007, 2009 Anatoly Sokolov
|
|
|
508 |
39
|
|
|
509 |
325 #elif defined (__AVR_ATtiny24__)
|
|
|
510 |
326 # include <avr/iotn24.h>
|
|
|
511 |
327 #elif defined (__AVR_ATtiny24A__)
|
|
|
512 |
328 # include <avr/iotn24a.h>
|
|
|
513 |
329 #elif defined (__AVR_ATtiny44__)
|
|
|
514 |
330 # include <avr/iotn44.h>
|
|
|
515 |
331 #elif defined (__AVR_ATtiny44A__)
|
|
|
516 |
332 # include <avr/iotn44a.h>
|
|
|
517 |
333 #elif defined (__AVR_ATtiny84__)
|
|
|
518 |
334 # include <avr/iotn84.h>
|
|
|
519 |
335 #elif defined (__AVR_ATtiny261__)
|
|
|
520 |
336 # include <avr/iotn261.h>
|
|
|
521 |
337 #elif defined (__AVR_ATtiny261A__)
|
|
|
522 |
338 # include <avr/iotn261a.h>
|
|
|
523 |
339 #elif defined (__AVR_ATtiny461__)
|
|
|
524 |
340 # include <avr/iotn461.h>
|
|
|
525 |
341 #elif defined (__AVR_ATtiny461A__)
|
|
|
526 |
342 # include <avr/iotn461a.h>
|
|
|
527 |
343 #elif defined (__AVR_ATtiny861__)
|
|
|
528 |
344 # include <avr/iotn861.h>
|
|
|
529 |
345 #elif defined (__AVR_ATtiny861A__)
|
|
|
530 |
346 # include <avr/iotn861a.h>
|
|
|
531 |
347 #elif defined (__AVR_ATtiny43U__)
|
|
|
532 |
348 # include <avr/iotn43u.h>
|
|
|
533 |
349 #elif defined (__AVR_ATtiny48__)
|
|
|
534 |
350 # include <avr/iotn48.h>
|
|
|
535 |
351 #elif defined (__AVR_ATtiny88__)
|
|
|
536 |
352 # include <avr/iotn88.h>
|
|
|
537 |
353 #elif defined (__AVR_ATtiny87__)
|
|
|
538 |
354 # include <avr/iotn87.h>
|
|
|
539 |
355 #elif defined (__AVR_ATtiny167__)
|
|
|
540 |
356 # include <avr/iotn167.h>
|
|
|
541 |
357 #elif defined (__AVR_AT90SCR100__)
|
|
|
542 |
358 # include <avr/io90scr100.h>
|
|
|
543 |
359 #elif defined (__AVR_ATxmega16A4__)
|
|
|
544 |
360 # include <avr/iox16a4.h>
|
|
|
545 |
361 #elif defined (__AVR_ATxmega16D4__)
|
|
|
546 |
362 # include <avr/iox16d4.h>
|
|
|
547 |
363 #elif defined (__AVR_ATxmega32A4__)
|
|
|
548 |
364 # include <avr/iox32a4.h>
|
|
|
549 |
365 #elif defined (__AVR_ATxmega32D4__)
|
|
|
550 |
366 # include <avr/iox32d4.h>
|
|
|
551 |
367 #elif defined (__AVR_ATxmega64A1__)
|
|
|
552 |
368 # include <avr/iox64a1.h>
|
|
|
553 |
369 #elif defined (__AVR_ATxmega64A3__)
|
|
|
554 |
370 # include <avr/iox64a3.h>
|
|
|
555 |
371 #elif defined (__AVR_ATxmega64D3__)
|
|
|
556 |
372 # include <avr/iox64d3.h>
|
|
|
557 |
373 #elif defined (__AVR_ATxmega128A1__)
|
|
|
558 |
374 # include <avr/iox128a1.h>
|
|
|
559 |
375 #elif defined (__AVR_ATxmega128A3__)
|
|
|
560 |
376 # include <avr/iox128a3.h>
|
|
|
561 |
377 #elif defined (__AVR_ATxmega128D3__)
|
|
|
562 |
378 # include <avr/iox128d3.h>
|
|
|
563 |
379 #elif defined (__AVR_ATxmega192A3__)
|
|
|
564 |
380 # include <avr/iox192a3.h>
|
|
|
565 |
381 #elif defined (__AVR_ATxmega192D3__)
|
|
|
566 |
382 # include <avr/iox192d3.h>
|
|
|
567 |
383 #elif defined (__AVR_ATxmega256A3__)
|
|
|
568 |
384 # include <avr/iox256a3.h>
|
|
|
569 |
385 #elif defined (__AVR_ATxmega256A3B__)
|
|
|
570 |
386 # include <avr/iox256a3b.h>
|
|
|
571 |
387 #elif defined (__AVR_ATxmega256D3__)
|
|
|
572 |
388 # include <avr/iox256d3.h>
|
|
|
573 |
389 #elif defined (__AVR_ATA6289__)
|
|
|
574 |
390 # include <avr/ioa6289.h>
|
|
|
575 |
391 /* avr1: the following only supported for assembler programs */
|
|
|
576 |
392 #elif defined (__AVR_ATtiny28__)
|
|
|
577 |
393 # include <avr/iotn28.h>
|
|
|
578 |
394 #elif defined (__AVR_AT90S1200__)
|
|
|
579 |
395 # include <avr/io1200.h>
|
|
|
580 |
396 #elif defined (__AVR_ATtiny15__)
|
|
|
581 |
397 # include <avr/iotn15.h>
|
|
|
582 |
398 #elif defined (__AVR_ATtiny12__)
|
|
|
583 |
399 # include <avr/iotn12.h>
|
|
|
584 |
400 #elif defined (__AVR_ATtiny11__)
|
|
|
585 |
401 # include <avr/iotn11.h>
|
|
|
586 |
402 #else
|
|
|
587 |
403 # if !defined(__COMPILING_AVR_LIBC__)
|
|
|
588 |
404 # warning "device type not defined"
|
|
|
589 |
405 # endif
|
|
|
590 |
406 #endif
|
|
|
591 |
407
|
|
|
592 |
408 #include <avr/portpins.h>
|
|
|
593 |
1 /* Copyright (c) 2003 Theodore A. Roth
|
|
|
594 |
409
|
|
|
595 |
410 #include <avr/common.h>
|
|
|
596 |
1 /* Copyright (c) 2007 Eric B. Weddington
|
|
|
597 |
411
|
|
|
598 |
412 #include <avr/version.h>
|
|
|
599 |
1 /* Copyright (c) 2005, Joerg Wunsch -*- c -*-
|
|
|
600 |
413
|
|
|
601 |
414 /* Include fuse.h after individual IO header files. */
|
|
|
602 |
415 #include <avr/fuse.h>
|
|
|
603 |
1 /* Copyright (c) 2007, Atmel Corporation
|
|
|
604 |
416
|
|
|
605 |
417 /* Include lock.h after individual IO header files. */
|
|
|
606 |
418 #include <avr/lock.h>
|
|
|
607 |
1 /* Copyright (c) 2007, Atmel Corporation
|
|
|
608 |
419
|
|
|
609 |
122 avr/pgmspace.h>
|
|
|
610 |
20 " /* for common defs */
|
|
|
611 |
1 /* Name: usbdrv.h
|
|
|
612 |
2 * Project: V-USB, virtual USB port for Atmel's(r) AVR(r) microcontrollers
|
|
|
613 |
3 * Author: Christian Starkjohann
|
|
|
614 |
4 * Creation Date: 2004-12-29
|
|
|
615 |
5 * Tabsize: 4
|
|
|
616 |
6 * Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH
|
|
|
617 |
7 * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
|
|
|
618 |
8 * This Revision: $Id$
|
|
|
619 |
9 */
|
|
|
620 |
10
|
|
|
621 |
11 #ifndef __usbdrv_h_included__
|
|
|
622 |
12 #define __usbdrv_h_included__
|
|
|
623 |
13 #include "usbconfig.h"
|
|
|
624 |
1 /* Name: usbconfig.h
|
|
|
625 |
14 portability.h"
|
|
|
626 |
21 /* register names */
|
|
|
627 |
22 #define x1 r16
|
|
|
628 |
23 #define x2 r17
|
|
|
629 |
24 #define shift r18
|
|
|
630 |
25 #define cnt r19
|
|
|
631 |
26 #define x3 r20
|
|
|
632 |
27 #define x4 r21
|
|
|
633 |
28 #define x5 r22
|
|
|
634 |
29 #define bitcnt x5
|
|
|
635 |
30 #define phase x4
|
|
|
636 |
31 #define leap x4
|
|
|
637 |
32
|
|
|
638 |
33 /* Some assembler dependent definitions and declarations: */
|
|
|
639 |
34
|
|
|
640 |
35 #ifdef __IAR_SYSTEMS_ASM__
|
|
|
641 |
36 extern usbRxBuf, usbDeviceAddr, usbNewDeviceAddr, usbInputBufOffset
|
|
|
642 |
37 extern usbCurrentTok, usbRxLen, usbRxToken, usbTxLen
|
|
|
643 |
38 extern usbTxBuf, usbTxStatus1, usbTxStatus3
|
|
|
644 |
39 # if USB_COUNT_SOF
|
|
|
645 |
40 extern usbSofCount
|
|
|
646 |
41 # endif
|
|
|
647 |
42 public usbCrc16
|
|
|
648 |
43 public usbCrc16Append
|
|
|
649 |
44
|
|
|
650 |
45 COMMON INTVEC
|
|
|
651 |
46 # ifndef USB_INTR_VECTOR
|
|
|
652 |
47 ORG INT0_vect
|
|
|
653 |
48 # else /* USB_INTR_VECTOR */
|
|
|
654 |
49 ORG USB_INTR_VECTOR
|
|
|
655 |
50 # undef USB_INTR_VECTOR
|
|
|
656 |
51 # endif /* USB_INTR_VECTOR */
|
|
|
657 |
52 # define USB_INTR_VECTOR usbInterruptHandler
|
|
|
658 |
53 rjmp USB_INTR_VECTOR
|
|
|
659 |
54 RSEG CODE
|
|
|
660 |
55
|
|
|
661 |
56 #else /* __IAR_SYSTEMS_ASM__ */
|
|
|
662 |
57
|
|
|
663 |
58 # ifndef USB_INTR_VECTOR /* default to hardware interrupt INT0 */
|
|
|
664 |
59 # ifdef INT0_vect
|
|
|
665 |
60 # define USB_INTR_VECTOR INT0_vect // this is the "new" define for the vector
|
|
|
666 |
61 # else
|
|
|
667 |
62 # define USB_INTR_VECTOR SIG_INTERRUPT0 // this is the "old" vector
|
|
|
668 |
63 # endif
|
|
|
669 |
64 # endif
|
|
|
670 |
65 .text
|
|
|
671 |
66 .global USB_INTR_VECTOR
|
|
|
672 |
68 .global usbCrc16
|
|
|
673 |
69 .global usbCrc16Append
|
|
|
674 |
70 #endif /* __IAR_SYSTEMS_ASM__ */
|
|
|
675 |
71
|
|
|
676 |
72
|
|
|
677 |
73 #if USB_INTR_PENDING < 0x40 /* This is an I/O address, use in and out */
|
|
|
678 |
74 # define USB_LOAD_PENDING(reg) in reg, USB_INTR_PENDING
|
|
|
679 |
75 # define USB_STORE_PENDING(reg) out USB_INTR_PENDING, reg
|
|
|
680 |
76 #else /* It's a memory address, use lds and sts */
|
|
|
681 |
77 # define USB_LOAD_PENDING(reg) lds reg, USB_INTR_PENDING
|
|
|
682 |
78 # define USB_STORE_PENDING(reg) sts USB_INTR_PENDING, reg
|
|
|
683 |
79 #endif
|
|
|
684 |
80
|
|
|
685 |
81 #define usbTxLen1 usbTxStatus1
|
|
|
686 |
82 #define usbTxBuf1 (usbTxStatus1 + 1)
|
|
|
687 |
83 #define usbTxLen3 usbTxStatus3
|
|
|
688 |
84 #define usbTxBuf3 (usbTxStatus3 + 1)
|
|
|
689 |
85
|
|
|
690 |
86
|
|
|
691 |
87 ;----------------------------------------------------------------------------
|
|
|
692 |
88 ; Utility functions
|
|
|
693 |
89 ;----------------------------------------------------------------------------
|
|
|
694 |
90
|
|
|
695 |
91 #ifdef __IAR_SYSTEMS_ASM__
|
|
|
696 |
92 /* Register assignments for usbCrc16 on IAR cc */
|
|
|
697 |
93 /* Calling conventions on IAR:
|
|
|
698 |
94 * First parameter passed in r16/r17, second in r18/r19 and so on.
|
|
|
699 |
95 * Callee must preserve r4-r15, r24-r29 (r28/r29 is frame pointer)
|
|
|
700 |
96 * Result is passed in r16/r17
|
|
|
701 |
97 * In case of the "tiny" memory model, pointers are only 8 bit with no
|
|
|
702 |
98 * padding. We therefore pass argument 1 as "16 bit unsigned".
|
|
|
703 |
99 */
|
|
|
704 |
100 RTMODEL "__rt_version", "3"
|
|
|
705 |
101 /* The line above will generate an error if cc calling conventions change.
|
|
|
706 |
102 * The value "3" above is valid for IAR 4.10B/W32
|
|
|
707 |
103 */
|
|
|
708 |
104 # define argLen r18 /* argument 2 */
|
|
|
709 |
105 # define argPtrL r16 /* argument 1 */
|
|
|
710 |
106 # define argPtrH r17 /* argument 1 */
|
|
|
711 |
107
|
|
|
712 |
108 # define resCrcL r16 /* result */
|
|
|
713 |
109 # define resCrcH r17 /* result */
|
|
|
714 |
110
|
|
|
715 |
111 # define ptrL ZL
|
|
|
716 |
112 # define ptrH ZH
|
|
|
717 |
113 # define ptr Z
|
|
|
718 |
114 # define byte r22
|
|
|
719 |
115 # define bitCnt r19
|
|
|
720 |
116 # define polyL r20
|
|
|
721 |
117 # define polyH r21
|
|
|
722 |
118 # define scratch r23
|
|
|
723 |
119
|
|
|
724 |
120 #else /* __IAR_SYSTEMS_ASM__ */
|
|
|
725 |
121 /* Register assignments for usbCrc16 on gcc */
|
|
|
726 |
122 /* Calling conventions on gcc:
|
|
|
727 |
123 * First parameter passed in r24/r25, second in r22/23 and so on.
|
|
|
728 |
124 * Callee must preserve r1-r17, r28/r29
|
|
|
729 |
125 * Result is passed in r24/r25
|
|
|
730 |
126 */
|
|
|
731 |
127 # define argLen r22 /* argument 2 */
|
|
|
732 |
128 # define argPtrL r24 /* argument 1 */
|
|
|
733 |
129 # define argPtrH r25 /* argument 1 */
|
|
|
734 |
130
|
|
|
735 |
131 # define resCrcL r24 /* result */
|
|
|
736 |
132 # define resCrcH r25 /* result */
|
|
|
737 |
133
|
|
|
738 |
134 # define ptrL XL
|
|
|
739 |
135 # define ptrH XH
|
|
|
740 |
136 # define ptr x
|
|
|
741 |
137 # define byte r18
|
|
|
742 |
138 # define bitCnt r19
|
|
|
743 |
139 # define polyL r20
|
|
|
744 |
140 # define polyH r21
|
|
|
745 |
141 # define scratch r23
|
|
|
746 |
142
|
|
|
747 |
143 #endif
|
|
|
748 |
144
|
|
|
749 |
145 #if USB_USE_FAST_CRC
|
|
|
750 |
146
|
|
|
751 |
147 ; This implementation is faster, but has bigger code size
|
|
|
752 |
148 ; Thanks to Slawomir Fras (BoskiDialer) for this code!
|
|
|
753 |
149 ; It implements the following C pseudo-code:
|
|
|
754 |
150 ; unsigned table(unsigned char x)
|
|
|
755 |
151 ; {
|
|
|
756 |
152 ; unsigned value;
|
|
|
757 |
153 ;
|
|
|
758 |
154 ; value = (unsigned)x << 6;
|
|
|
759 |
155 ; value ^= (unsigned)x << 7;
|
|
|
760 |
156 ; if(parity(x))
|
|
|
761 |
157 ; value ^= 0xc001;
|
|
|
762 |
158 ; return value;
|
|
|
763 |
159 ; }
|
|
|
764 |
160 ; unsigned usbCrc16(unsigned char *argPtr, unsigned char argLen)
|
|
|
765 |
161 ; {
|
|
|
766 |
162 ; unsigned crc = 0xffff;
|
|
|
767 |
163 ;
|
|
|
768 |
164 ; while(argLen--)
|
|
|
769 |
165 ; crc = table(lo8(crc) ^ *argPtr++) ^ hi8(crc);
|
|
|
770 |
166 ; return ~crc;
|
|
|
771 |
167 ; }
|
|
|
772 |
168
|
|
|
773 |
169 ; extern unsigned usbCrc16(unsigned char *argPtr, unsigned char argLen);
|
|
|
774 |
170 ; argPtr r24+25 / r16+r17
|
|
|
775 |
171 ; argLen r22 / r18
|
|
|
776 |
172 ; temp variables:
|
|
|
777 |
173 ; byte r18 / r22
|
|
|
778 |
174 ; scratch r23
|
|
|
779 |
175 ; resCrc r24+r25 / r16+r17
|
|
|
780 |
176 ; ptr X / Z
|
|
|
781 |
177 usbCrc16:
|
|
|
782 |
178 mov ptrL, argPtrL
|
|
|
783 |
179 mov ptrH, argPtrH
|
|
|
784 |
180 ldi resCrcL, 0xFF
|
|
|
785 |
181 ldi resCrcH, 0xFF
|
|
|
786 |
182 rjmp usbCrc16LoopTest
|
|
|
787 |
183 usbCrc16ByteLoop:
|
|
|
788 |
184 ld byte, ptr+
|
|
|
789 |
185 eor resCrcL, byte ; resCrcL is now 'x' in table()
|
|
|
790 |
186 mov byte, resCrcL ; compute parity of 'x'
|
|
|
791 |
187 swap byte
|
|
|
792 |
188 eor byte, resCrcL
|
|
|
793 |
189 mov scratch, byte
|
|
|
794 |
190 lsr byte
|
|
|
795 |
191 lsr byte
|
|
|
796 |
192 eor byte, scratch
|
|
|
797 |
193 inc byte
|
|
|
798 |
194 lsr byte
|
|
|
799 |
195 andi byte, 1 ; byte is now parity(x)
|
|
|
800 |
196 mov scratch, resCrcL
|
|
|
801 |
197 mov resCrcL, resCrcH
|
|
|
802 |
198 eor resCrcL, byte ; low byte of if(parity(x)) value ^= 0xc001;
|
|
|
803 |
199 neg byte
|
|
|
804 |
200 andi byte, 0xc0
|
|
|
805 |
201 mov resCrcH, byte ; high byte of if(parity(x)) value ^= 0xc001;
|
|
|
806 |
202 clr byte
|
|
|
807 |
203 lsr scratch
|
|
|
808 |
204 ror byte
|
|
|
809 |
205 eor resCrcH, scratch
|
|
|
810 |
206 eor resCrcL, byte
|
|
|
811 |
207 lsr scratch
|
|
|
812 |
208 ror byte
|
|
|
813 |
209 eor resCrcH, scratch
|
|
|
814 |
210 eor resCrcL, byte
|
|
|
815 |
211 usbCrc16LoopTest:
|
|
|
816 |
212 subi argLen, 1
|
|
|
817 |
213 brsh usbCrc16ByteLoop
|
|
|
818 |
214 com resCrcL
|
|
|
819 |
215 com resCrcH
|
|
|
820 |
216 ret
|
|
|
821 |
217
|
|
|
822 |
218 #else /* USB_USE_FAST_CRC */
|
|
|
823 |
219
|
|
|
824 |
220 ; This implementation is slower, but has less code size
|
|
|
825 |
221 ;
|
|
|
826 |
222 ; extern unsigned usbCrc16(unsigned char *argPtr, unsigned char argLen);
|
|
|
827 |
223 ; argPtr r24+25 / r16+r17
|
|
|
828 |
224 ; argLen r22 / r18
|
|
|
829 |
225 ; temp variables:
|
|
|
830 |
226 ; byte r18 / r22
|
|
|
831 |
227 ; bitCnt r19
|
|
|
832 |
228 ; poly r20+r21
|
|
|
833 |
229 ; scratch r23
|
|
|
834 |
230 ; resCrc r24+r25 / r16+r17
|
|
|
835 |
231 ; ptr X / Z
|
|
|
836 |
232 usbCrc16:
|
|
|
837 |
233 mov ptrL, argPtrL
|
|
|
838 |
234:vusb-20120109/usbdrv/usbdrvasm.S **** mov ptrH, argPtrH
|
|
|
839 |
235:vusb-20120109/usbdrv/usbdrvasm.S **** ldi resCrcL, 0
|
|
|
840 |
236:vusb-20120109/usbdrv/usbdrvasm.S **** ldi resCrcH, 0
|
|
|
841 |
237:vusb-20120109/usbdrv/usbdrvasm.S **** ldi polyL, lo8(0xa001)
|
|
|
842 |
238:vusb-20120109/usbdrv/usbdrvasm.S **** ldi polyH, hi8(0xa001)
|
|
|
843 |
239:vusb-20120109/usbdrv/usbdrvasm.S **** com argLen ; argLen = -argLen - 1: modified loop to ensure that carry is set
|
|
|
844 |
240:vusb-20120109/usbdrv/usbdrvasm.S **** ldi bitCnt, 0 ; loop counter with starnd condition = end condition
|
|
|
845 |
241:vusb-20120109/usbdrv/usbdrvasm.S **** rjmp usbCrcLoopEntry
|
|
|
846 |
242:vusb-20120109/usbdrv/usbdrvasm.S **** usbCrcByteLoop:
|
|
|
847 |
243 ld byte, ptr+
|
|
|
848 |
244:vusb-20120109/usbdrv/usbdrvasm.S **** eor resCrcL, byte
|
|
|
849 |
245:vusb-20120109/usbdrv/usbdrvasm.S **** usbCrcBitLoop:
|
|
|
850 |
246 ror resCrcH ; carry is always set here (see brcs jumps to here)
|
|
|
851 |
247:vusb-20120109/usbdrv/usbdrvasm.S **** ror resCrcL
|
|
|
852 |
248:vusb-20120109/usbdrv/usbdrvasm.S **** brcs usbCrcNoXor
|
|
|
853 |
249:vusb-20120109/usbdrv/usbdrvasm.S **** eor resCrcL, polyL
|
|
|
854 |
250:vusb-20120109/usbdrv/usbdrvasm.S **** eor resCrcH, polyH
|
|
|
855 |
251:vusb-20120109/usbdrv/usbdrvasm.S **** usbCrcNoXor:
|
|
|
856 |
252 subi bitCnt, 224 ; (8 * 224) % 256 = 0; this loop iterates 8 times
|
|
|
857 |
253:vusb-20120109/usbdrv/usbdrvasm.S **** brcs usbCrcBitLoop
|
|
|
858 |
254:vusb-20120109/usbdrv/usbdrvasm.S **** usbCrcLoopEntry:
|
|
|
859 |
255 subi argLen, -1
|
|
|
860 |
256:vusb-20120109/usbdrv/usbdrvasm.S **** brcs usbCrcByteLoop
|
|
|
861 |
257:vusb-20120109/usbdrv/usbdrvasm.S **** usbCrcReady:
|
|
|
862 |
258 ret
|
|
|
863 |
259:vusb-20120109/usbdrv/usbdrvasm.S **** ; Thanks to Reimar Doeffinger for optimizing this CRC routine!
|
|
|
864 |
260
|
|
|
865 |
261 #endif /* USB_USE_FAST_CRC */
|
|
|
866 |
262
|
|
|
867 |
263 ; extern unsigned usbCrc16Append(unsigned char *data, unsigned char len);
|
|
|
868 |
264 usbCrc16Append:
|
|
|
869 |
265 rcall usbCrc16
|
|
|
870 |
266:vusb-20120109/usbdrv/usbdrvasm.S **** st ptr+, resCrcL
|
|
|
871 |
267:vusb-20120109/usbdrv/usbdrvasm.S **** st ptr+, resCrcH
|
|
|
872 |
268:vusb-20120109/usbdrv/usbdrvasm.S **** ret
|
|
|
873 |
269:vusb-20120109/usbdrv/usbdrvasm.S ****
|
|
|
874 |
270 #undef argLen
|
|
|
875 |
271 #undef argPtrL
|
|
|
876 |
272 #undef argPtrH
|
|
|
877 |
273 #undef resCrcL
|
|
|
878 |
274 #undef resCrcH
|
|
|
879 |
275 #undef ptrL
|
|
|
880 |
276 #undef ptrH
|
|
|
881 |
277 #undef ptr
|
|
|
882 |
278 #undef byte
|
|
|
883 |
279 #undef bitCnt
|
|
|
884 |
280 #undef polyL
|
|
|
885 |
281 #undef polyH
|
|
|
886 |
282 #undef scratch
|
|
|
887 |
283
|
|
|
888 |
284
|
|
|
889 |
285 #if USB_CFG_HAVE_MEASURE_FRAME_LENGTH
|
|
|
890 |
286 #ifdef __IAR_SYSTEMS_ASM__
|
|
|
891 |
287 /* Register assignments for usbMeasureFrameLength on IAR cc */
|
|
|
892 |
288 /* Calling conventions on IAR:
|
|
|
893 |
289 * First parameter passed in r16/r17, second in r18/r19 and so on.
|
|
|
894 |
290 * Callee must preserve r4-r15, r24-r29 (r28/r29 is frame pointer)
|
|
|
895 |
291 * Result is passed in r16/r17
|
|
|
896 |
292 * In case of the "tiny" memory model, pointers are only 8 bit with no
|
|
|
897 |
293 * padding. We therefore pass argument 1 as "16 bit unsigned".
|
|
|
898 |
294 */
|
|
|
899 |
295 # define resL r16
|
|
|
900 |
296 # define resH r17
|
|
|
901 |
297 # define cnt16L r30
|
|
|
902 |
298 # define cnt16H r31
|
|
|
903 |
299 # define cntH r18
|
|
|
904 |
300
|
|
|
905 |
301 #else /* __IAR_SYSTEMS_ASM__ */
|
|
|
906 |
302 /* Register assignments for usbMeasureFrameLength on gcc */
|
|
|
907 |
303 /* Calling conventions on gcc:
|
|
|
908 |
304 * First parameter passed in r24/r25, second in r22/23 and so on.
|
|
|
909 |
305 * Callee must preserve r1-r17, r28/r29
|
|
|
910 |
306 * Result is passed in r24/r25
|
|
|
911 |
307 */
|
|
|
912 |
308 # define resL r24
|
|
|
913 |
309 # define resH r25
|
|
|
914 |
310 # define cnt16L r24
|
|
|
915 |
311 # define cnt16H r25
|
|
|
916 |
312 # define cntH r26
|
|
|
917 |
313 #endif
|
|
|
918 |
314 # define cnt16 cnt16L
|
|
|
919 |
315
|
|
|
920 |
316 ; extern unsigned usbMeasurePacketLength(void);
|
|
|
921 |
317 ; returns time between two idle strobes in multiples of 7 CPU clocks
|
|
|
922 |
318 .global usbMeasureFrameLength
|
|
|
923 |
319 usbMeasureFrameLength:
|
|
|
924 |
320 ldi cntH, 6 ; wait ~ 10 ms for D- == 0
|
|
|
925 |
321:vusb-20120109/usbdrv/usbdrvasm.S **** clr cnt16L
|
|
|
926 |
322:vusb-20120109/usbdrv/usbdrvasm.S **** clr cnt16H
|
|
|
927 |
323:vusb-20120109/usbdrv/usbdrvasm.S **** usbMFTime16:
|
|
|
928 |
324 dec cntH
|
|
|
929 |
325:vusb-20120109/usbdrv/usbdrvasm.S **** breq usbMFTimeout
|
|
|
930 |
326:vusb-20120109/usbdrv/usbdrvasm.S **** usbMFWaitStrobe: ; first wait for D- == 0 (idle strobe)
|
|
|
931 |
327 sbiw cnt16, 1 ;[0] [6]
|
|
|
932 |
328:vusb-20120109/usbdrv/usbdrvasm.S **** breq usbMFTime16 ;[2]
|
|
|
933 |
329:vusb-20120109/usbdrv/usbdrvasm.S **** sbic USBIN, USBMINUS ;[3]
|
|
|
934 |
330:vusb-20120109/usbdrv/usbdrvasm.S **** rjmp usbMFWaitStrobe ;[4]
|
|
|
935 |
331:vusb-20120109/usbdrv/usbdrvasm.S **** usbMFWaitIdle: ; then wait until idle again
|
|
|
936 |
332 sbis USBIN, USBMINUS ;1 wait for D- == 1
|
|
|
937 |
333:vusb-20120109/usbdrv/usbdrvasm.S **** rjmp usbMFWaitIdle ;2
|
|
|
938 |
334:vusb-20120109/usbdrv/usbdrvasm.S **** ldi cnt16L, 1 ;1 represents cycles so far
|
|
|
939 |
335:vusb-20120109/usbdrv/usbdrvasm.S **** clr cnt16H ;1
|
|
|
940 |
336:vusb-20120109/usbdrv/usbdrvasm.S **** usbMFWaitLoop:
|
|
|
941 |
337 in cntH, USBIN ;[0] [7]
|
|
|
942 |
338:vusb-20120109/usbdrv/usbdrvasm.S **** adiw cnt16, 1 ;[1]
|
|
|
943 |
339:vusb-20120109/usbdrv/usbdrvasm.S **** breq usbMFTimeout ;[3]
|
|
|
944 |
340:vusb-20120109/usbdrv/usbdrvasm.S **** andi cntH, USBMASK ;[4]
|
|
|
945 |
341:vusb-20120109/usbdrv/usbdrvasm.S **** brne usbMFWaitLoop ;[5]
|
|
|
946 |
342:vusb-20120109/usbdrv/usbdrvasm.S **** usbMFTimeout:
|
|
|
947 |
343 #if resL != cnt16L
|
|
|
948 |
344 mov resL, cnt16L
|
|
|
949 |
345 mov resH, cnt16H
|
|
|
950 |
346 #endif
|
|
|
951 |
347 ret
|
|
|
952 |
348:vusb-20120109/usbdrv/usbdrvasm.S ****
|
|
|
953 |
349 #undef resL
|
|
|
954 |
350 #undef resH
|
|
|
955 |
351 #undef cnt16
|
|
|
956 |
352 #undef cnt16L
|
|
|
957 |
353 #undef cnt16H
|
|
|
958 |
354 #undef cntH
|
|
|
959 |
355
|
|
|
960 |
356 #endif /* USB_CFG_HAVE_MEASURE_FRAME_LENGTH */
|
|
|
961 |
357
|
|
|
962 |
358 ;----------------------------------------------------------------------------
|
|
|
963 |
359 ; Now include the clock rate specific code
|
|
|
964 |
360 ;----------------------------------------------------------------------------
|
|
|
965 |
361
|
|
|
966 |
362 #ifndef USB_CFG_CLOCK_KHZ
|
|
|
967 |
363 # ifdef F_CPU
|
|
|
968 |
364 # define USB_CFG_CLOCK_KHZ (F_CPU/1000)
|
|
|
969 |
365 # else
|
|
|
970 |
366 # error "USB_CFG_CLOCK_KHZ not defined in usbconfig.h and no F_CPU set!"
|
|
|
971 |
367 # endif
|
|
|
972 |
368 #endif
|
|
|
973 |
369
|
|
|
974 |
370 #if USB_CFG_CHECK_CRC /* separate dispatcher for CRC type modules */
|
|
|
975 |
371 # if USB_CFG_CLOCK_KHZ == 18000
|
|
|
976 |
372 # include "usbdrvasm18-crc.inc"
|
|
|
977 |
373 # else
|
|
|
978 |
374 # error "USB_CFG_CLOCK_KHZ is not one of the supported crc-rates!"
|
|
|
979 |
375 # endif
|
|
|
980 |
376 #else /* USB_CFG_CHECK_CRC */
|
|
|
981 |
377 # if USB_CFG_CLOCK_KHZ == 12000
|
|
|
982 |
378 # include "usbdrvasm12.inc"
|
|
|
983 |
379 # elif USB_CFG_CLOCK_KHZ == 12800
|
|
|
984 |
380 # include "usbdrvasm128.inc"
|
|
|
985 |
381 # elif USB_CFG_CLOCK_KHZ == 15000
|
|
|
986 |
382 # include "usbdrvasm15.inc"
|
|
|
987 |
383 # elif USB_CFG_CLOCK_KHZ == 16000
|
|
|
988 |
384 # include "usbdrvasm16.inc"
|
|
|
989 |
385 # elif USB_CFG_CLOCK_KHZ == 16500
|
|
|
990 |
386 # include "usbdrvasm165.inc"
|
|
|
991 |
387 # elif USB_CFG_CLOCK_KHZ == 20000
|
|
|
992 |
1 /* Name: usbdrvasm165.inc
|
|
|
993 |
2 * Project: V-USB, virtual USB port for Atmel's(r) AVR(r) microcontrollers
|
|
|
994 |
3 * Author: Christian Starkjohann
|
|
|
995 |
4 * Creation Date: 2007-04-22
|
|
|
996 |
5 * Tabsize: 4
|
|
|
997 |
6 * Copyright: (c) 2007 by OBJECTIVE DEVELOPMENT Software GmbH
|
|
|
998 |
7 * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
|
|
|
999 |
8 * Revision: $Id$
|
|
|
1000 |
9 */
|
|
|
1001 |
10
|
|
|
1002 |
11 /* Do not link this file! Link usbdrvasm.S instead, which includes the
|
|
|
1003 |
12 * appropriate implementation!
|
|
|
1004 |
13 */
|
|
|
1005 |
14
|
|
|
1006 |
15 /*
|
|
|
1007 |
16 General Description:
|
|
|
1008 |
17 This file is the 16.5 MHz version of the USB driver. It is intended for the
|
|
|
1009 |
18 ATTiny45 and similar controllers running on 16.5 MHz internal RC oscillator.
|
|
|
1010 |
19 This version contains a phase locked loop in the receiver routine to cope with
|
|
|
1011 |
20 slight clock rate deviations of up to +/- 1%.
|
|
|
1012 |
21
|
|
|
1013 |
22 See usbdrv.h for a description of the entire driver.
|
|
|
1014 |
23
|
|
|
1015 |
24 Since almost all of this code is timing critical, don't change unless you
|
|
|
1016 |
25 really know what you are doing! Many parts require not only a maximum number
|
|
|
1017 |
26 of CPU cycles, but even an exact number of cycles!
|
|
|
1018 |
27 */
|
|
|
1019 |
28
|
|
|
1020 |
29 ;Software-receiver engine. Strict timing! Don't change unless you can preserve timing!
|
|
|
1021 |
30 ;interrupt response time: 4 cycles + insn running = 7 max if interrupts always enabled
|
|
|
1022 |
31 ;max allowable interrupt latency: 59 cycles -> max 52 cycles interrupt disable
|
|
|
1023 |
32 ;max stack usage: [ret(2), r0, SREG, YL, YH, shift, x1, x2, x3, x4, cnt] = 12 bytes
|
|
|
1024 |
33 ;nominal frequency: 16.5 MHz -> 11 cycles per bit
|
|
|
1025 |
34 ; 16.3125 MHz < F_CPU < 16.6875 MHz (+/- 1.1%)
|
|
|
1026 |
35 ; Numbers in brackets are clocks counted from center of last sync bit
|
|
|
1027 |
36 ; when instruction starts
|
|
|
1028 |
37
|
|
|
1029 |
38
|
|
|
1030 |
39 USB_INTR_VECTOR:
|
|
|
1031 |
40 ;order of registers pushed: YL, SREG [sofError], r0, YH, shift, x1, x2, x3, x4, cnt
|
|
|
1032 |
41:vusb-20120109/usbdrv/usbdrvasm165.inc **** push YL ;[-23] push only what is necessary to sync with edge ASAP
|
|
|
1033 |
42:vusb-20120109/usbdrv/usbdrvasm165.inc **** in YL, SREG ;[-21]
|
|
|
1034 |
43:vusb-20120109/usbdrv/usbdrvasm165.inc **** push YL ;[-20]
|
|
|
1035 |
44 ;----------------------------------------------------------------------------
|
|
|
1036 |
45 ; Synchronize with sync pattern:
|
|
|
1037 |
46 ;----------------------------------------------------------------------------
|
|
|
1038 |
47 ;sync byte (D-) pattern LSb to MSb: 01010100 [1 = idle = J, 0 = K]
|
|
|
1039 |
48 ;sync up with J to K edge during sync pattern -- use fastest possible loops
|
|
|
1040 |
49 ;The first part waits at most 1 bit long since we must be in sync pattern.
|
|
|
1041 |
50 ;YL is guarenteed to be < 0x80 because I flag is clear. When we jump to
|
|
|
1042 |
51 ;waitForJ, ensure that this prerequisite is met.
|
|
|
1043 |
52 waitForJ:
|
|
|
1044 |
53:vusb-20120109/usbdrv/usbdrvasm165.inc **** inc YL
|
|
|
1045 |
54:vusb-20120109/usbdrv/usbdrvasm165.inc **** sbis USBIN, USBMINUS
|
|
|
1046 |
55:vusb-20120109/usbdrv/usbdrvasm165.inc **** brne waitForJ ; just make sure we have ANY timeout
|
|
|
1047 |
56 waitForK:
|
|
|
1048 |
57 ;The following code results in a sampling window of < 1/4 bit which meets the spec.
|
|
|
1049 |
58:vusb-20120109/usbdrv/usbdrvasm165.inc **** sbis USBIN, USBMINUS ;[-15]
|
|
|
1050 |
59:vusb-20120109/usbdrv/usbdrvasm165.inc **** rjmp foundK ;[-14]
|
|
|
1051 |
60:vusb-20120109/usbdrv/usbdrvasm165.inc **** sbis USBIN, USBMINUS
|
|
|
1052 |
61:vusb-20120109/usbdrv/usbdrvasm165.inc **** rjmp foundK
|
|
|
1053 |
62:vusb-20120109/usbdrv/usbdrvasm165.inc **** sbis USBIN, USBMINUS
|
|
|
1054 |
63:vusb-20120109/usbdrv/usbdrvasm165.inc **** rjmp foundK
|
|
|
1055 |
64:vusb-20120109/usbdrv/usbdrvasm165.inc **** sbis USBIN, USBMINUS
|
|
|
1056 |
65:vusb-20120109/usbdrv/usbdrvasm165.inc **** rjmp foundK
|
|
|
1057 |
66:vusb-20120109/usbdrv/usbdrvasm165.inc **** sbis USBIN, USBMINUS
|
|
|
1058 |
67:vusb-20120109/usbdrv/usbdrvasm165.inc **** rjmp foundK
|
|
|
1059 |
68:vusb-20120109/usbdrv/usbdrvasm165.inc **** sbis USBIN, USBMINUS
|
|
|
1060 |
69:vusb-20120109/usbdrv/usbdrvasm165.inc **** rjmp foundK
|
|
|
1061 |
70 #if USB_COUNT_SOF
|
|
|
1062 |
71:vusb-20120109/usbdrv/usbdrvasm165.inc **** lds YL, usbSofCount
|
|
|
1063 |
72:vusb-20120109/usbdrv/usbdrvasm165.inc **** inc YL
|
|
|
1064 |
73:vusb-20120109/usbdrv/usbdrvasm165.inc **** sts usbSofCount, YL
|
|
|
1065 |
74:vusb-20120109/usbdrv/usbdrvasm165.inc **** #endif /* USB_COUNT_SOF */
|
|
|
1066 |
75:vusb-20120109/usbdrv/usbdrvasm165.inc **** #ifdef USB_SOF_HOOK
|
|
|
1067 |
76:vusb-20120109/usbdrv/usbdrvasm165.inc **** USB_SOF_HOOK
|
|
|
1068 |
77:vusb-20120109/usbdrv/usbdrvasm165.inc **** #endif
|
|
|
1069 |
78:vusb-20120109/usbdrv/usbdrvasm165.inc **** rjmp sofError
|
|
|
1070 |
79 foundK: ;[-12]
|
|
|
1071 |
80 ;{3, 5} after falling D- edge, average delay: 4 cycles [we want 5 for center sampling]
|
|
|
1072 |
81 ;we have 1 bit time for setup purposes, then sample again. Numbers in brackets
|
|
|
1073 |
82 ;are cycles from center of first sync (double K) bit after the instruction
|
|
|
1074 |
83:vusb-20120109/usbdrv/usbdrvasm165.inc **** push r0 ;[-12]
|
|
|
1075 |
84 ; [---] ;[-11]
|
|
|
1076 |
85:vusb-20120109/usbdrv/usbdrvasm165.inc **** push YH ;[-10]
|
|
|
1077 |
86 ; [---] ;[-9]
|
|
|
1078 |
87:vusb-20120109/usbdrv/usbdrvasm165.inc **** lds YL, usbInputBufOffset;[-8]
|
|
|
1079 |
88 ; [---] ;[-7]
|
|
|
1080 |
89:vusb-20120109/usbdrv/usbdrvasm165.inc **** clr YH ;[-6]
|
|
|
1081 |
90:vusb-20120109/usbdrv/usbdrvasm165.inc **** subi YL, lo8(-(usbRxBuf));[-5] [rx loop init]
|
|
|
1082 |
91:vusb-20120109/usbdrv/usbdrvasm165.inc **** sbci YH, hi8(-(usbRxBuf));[-4] [rx loop init]
|
|
|
1083 |
92:vusb-20120109/usbdrv/usbdrvasm165.inc **** mov r0, x2 ;[-3] [rx loop init]
|
|
|
1084 |
93:vusb-20120109/usbdrv/usbdrvasm165.inc **** sbis USBIN, USBMINUS ;[-2] we want two bits K (sample 2 cycles too early)
|
|
|
1085 |
94:vusb-20120109/usbdrv/usbdrvasm165.inc **** rjmp haveTwoBitsK ;[-1]
|
|
|
1086 |
95:vusb-20120109/usbdrv/usbdrvasm165.inc **** pop YH ;[0] undo the pushes from before
|
|
|
1087 |
96:vusb-20120109/usbdrv/usbdrvasm165.inc **** pop r0 ;[2]
|
|
|
1088 |
97:vusb-20120109/usbdrv/usbdrvasm165.inc **** rjmp waitForK ;[4] this was not the end of sync, retry
|
|
|
1089 |
98 ; The entire loop from waitForK until rjmp waitForK above must not exceed two
|
|
|
1090 |
99 ; bit times (= 22 cycles).
|
|
|
1091 |
100
|
|
|
1092 |
101 ;----------------------------------------------------------------------------
|
|
|
1093 |
102 ; push more registers and initialize values while we sample the first bits:
|
|
|
1094 |
103 ;----------------------------------------------------------------------------
|
|
|
1095 |
104 haveTwoBitsK: ;[1]
|
|
|
1096 |
105:vusb-20120109/usbdrv/usbdrvasm165.inc **** push shift ;[1]
|
|
|
1097 |
106:vusb-20120109/usbdrv/usbdrvasm165.inc **** push x1 ;[3]
|
|
|
1098 |
107:vusb-20120109/usbdrv/usbdrvasm165.inc **** push x2 ;[5]
|
|
|
1099 |
108:vusb-20120109/usbdrv/usbdrvasm165.inc **** push x3 ;[7]
|
|
|
1100 |
109:vusb-20120109/usbdrv/usbdrvasm165.inc **** ldi shift, 0xff ;[9] [rx loop init]
|
|
|
1101 |
110:vusb-20120109/usbdrv/usbdrvasm165.inc **** ori x3, 0xff ;[10] [rx loop init] == ser x3, clear zero flag
|
|
|
1102 |
111
|
|
|
1103 |
112:vusb-20120109/usbdrv/usbdrvasm165.inc **** in x1, USBIN ;[11] <-- sample bit 0
|
|
|
1104 |
113:vusb-20120109/usbdrv/usbdrvasm165.inc **** bst x1, USBMINUS ;[12]
|
|
|
1105 |
114:vusb-20120109/usbdrv/usbdrvasm165.inc **** bld shift, 0 ;[13]
|
|
|
1106 |
115:vusb-20120109/usbdrv/usbdrvasm165.inc **** push x4 ;[14] == phase
|
|
|
1107 |
116 ; [---] ;[15]
|
|
|
1108 |
117:vusb-20120109/usbdrv/usbdrvasm165.inc **** push cnt ;[16]
|
|
|
1109 |
118 ; [---] ;[17]
|
|
|
1110 |
119:vusb-20120109/usbdrv/usbdrvasm165.inc **** ldi phase, 0 ;[18] [rx loop init]
|
|
|
1111 |
120:vusb-20120109/usbdrv/usbdrvasm165.inc **** ldi cnt, USB_BUFSIZE;[19] [rx loop init]
|
|
|
1112 |
121:vusb-20120109/usbdrv/usbdrvasm165.inc **** rjmp rxbit1 ;[20]
|
|
|
1113 |
122 ; [---] ;[21]
|
|
|
1114 |
123
|
|
|
1115 |
124 ;----------------------------------------------------------------------------
|
|
|
1116 |
125 ; Receiver loop (numbers in brackets are cycles within byte after instr)
|
|
|
1117 |
126 ;----------------------------------------------------------------------------
|
|
|
1118 |
127 /*
|
|
|
1119 |
128 byte oriented operations done during loop:
|
|
|
1120 |
129 bit 0: store data
|
|
|
1121 |
130 bit 1: SE0 check
|
|
|
1122 |
131 bit 2: overflow check
|
|
|
1123 |
132 bit 3: catch up
|
|
|
1124 |
133 bit 4: rjmp to achieve conditional jump range
|
|
|
1125 |
134 bit 5: PLL
|
|
|
1126 |
135 bit 6: catch up
|
|
|
1127 |
136 bit 7: jump, fixup bitstuff
|
|
|
1128 |
137 ; 87 [+ 2] cycles
|
|
|
1129 |
138 ------------------------------------------------------------------
|
|
|
1130 |
139 */
|
|
|
1131 |
140 continueWithBit5:
|
|
|
1132 |
141:vusb-20120109/usbdrv/usbdrvasm165.inc **** in x2, USBIN ;[055] <-- bit 5
|
|
|
1133 |
142:vusb-20120109/usbdrv/usbdrvasm165.inc **** eor r0, x2 ;[056]
|
|
|
1134 |
143:vusb-20120109/usbdrv/usbdrvasm165.inc **** or phase, r0 ;[057]
|
|
|
1135 |
144:vusb-20120109/usbdrv/usbdrvasm165.inc **** sbrc phase, USBMINUS ;[058]
|
|
|
1136 |
145:vusb-20120109/usbdrv/usbdrvasm165.inc **** lpm ;[059] optional nop3; modifies r0
|
|
|
1137 |
146:vusb-20120109/usbdrv/usbdrvasm165.inc **** in phase, USBIN ;[060] <-- phase
|
|
|
1138 |
147:vusb-20120109/usbdrv/usbdrvasm165.inc **** eor x1, x2 ;[061]
|
|
|
1139 |
148:vusb-20120109/usbdrv/usbdrvasm165.inc **** bst x1, USBMINUS ;[062]
|
|
|
1140 |
149:vusb-20120109/usbdrv/usbdrvasm165.inc **** bld shift, 5 ;[063]
|
|
|
1141 |
150:vusb-20120109/usbdrv/usbdrvasm165.inc **** andi shift, 0x3f ;[064]
|
|
|
1142 |
151:vusb-20120109/usbdrv/usbdrvasm165.inc **** in x1, USBIN ;[065] <-- bit 6
|
|
|
1143 |
152:vusb-20120109/usbdrv/usbdrvasm165.inc **** breq unstuff5 ;[066] *** unstuff escape
|
|
|
1144 |
153:vusb-20120109/usbdrv/usbdrvasm165.inc **** eor phase, x1 ;[067]
|
|
|
1145 |
154:vusb-20120109/usbdrv/usbdrvasm165.inc **** eor x2, x1 ;[068]
|
|
|
1146 |
155:vusb-20120109/usbdrv/usbdrvasm165.inc **** bst x2, USBMINUS ;[069]
|
|
|
1147 |
156:vusb-20120109/usbdrv/usbdrvasm165.inc **** bld shift, 6 ;[070]
|
|
|
1148 |
157 didUnstuff6: ;[ ]
|
|
|
1149 |
158:vusb-20120109/usbdrv/usbdrvasm165.inc **** in r0, USBIN ;[071] <-- phase
|
|
|
1150 |
159:vusb-20120109/usbdrv/usbdrvasm165.inc **** cpi shift, 0x02 ;[072]
|
|
|
1151 |
160:vusb-20120109/usbdrv/usbdrvasm165.inc **** brlo unstuff6 ;[073] *** unstuff escape
|
|
|
1152 |
161 didUnstuff5: ;[ ]
|
|
|
1153 |
162:vusb-20120109/usbdrv/usbdrvasm165.inc **** nop2 ;[074]
|
|
|
1154 |
163 ; [---] ;[075]
|
|
|
1155 |
164:vusb-20120109/usbdrv/usbdrvasm165.inc **** in x2, USBIN ;[076] <-- bit 7
|
|
|
1156 |
165:vusb-20120109/usbdrv/usbdrvasm165.inc **** eor x1, x2 ;[077]
|
|
|
1157 |
166:vusb-20120109/usbdrv/usbdrvasm165.inc **** bst x1, USBMINUS ;[078]
|
|
|
1158 |
167:vusb-20120109/usbdrv/usbdrvasm165.inc **** bld shift, 7 ;[079]
|
|
|
1159 |
168 didUnstuff7: ;[ ]
|
|
|
1160 |
169:vusb-20120109/usbdrv/usbdrvasm165.inc **** eor r0, x2 ;[080]
|
|
|
1161 |
170:vusb-20120109/usbdrv/usbdrvasm165.inc **** or phase, r0 ;[081]
|
|
|
1162 |
171:vusb-20120109/usbdrv/usbdrvasm165.inc **** in r0, USBIN ;[082] <-- phase
|
|
|
1163 |
172:vusb-20120109/usbdrv/usbdrvasm165.inc **** cpi shift, 0x04 ;[083]
|
|
|
1164 |
173:vusb-20120109/usbdrv/usbdrvasm165.inc **** brsh rxLoop ;[084]
|
|
|
1165 |
174 ; [---] ;[085]
|
|
|
1166 |
175 unstuff7: ;[ ]
|
|
|
1167 |
176:vusb-20120109/usbdrv/usbdrvasm165.inc **** andi x3, ~0x80 ;[085]
|
|
|
1168 |
177:vusb-20120109/usbdrv/usbdrvasm165.inc **** ori shift, 0x80 ;[086]
|
|
|
1169 |
178:vusb-20120109/usbdrv/usbdrvasm165.inc **** in x2, USBIN ;[087] <-- sample stuffed bit 7
|
|
|
1170 |
179:vusb-20120109/usbdrv/usbdrvasm165.inc **** nop ;[088]
|
|
|
1171 |
180:vusb-20120109/usbdrv/usbdrvasm165.inc **** rjmp didUnstuff7 ;[089]
|
|
|
1172 |
181 ; [---] ;[090]
|
|
|
1173 |
182 ;[080]
|
|
|
1174 |
183
|
|
|
1175 |
184 unstuff5: ;[067]
|
|
|
1176 |
185:vusb-20120109/usbdrv/usbdrvasm165.inc **** eor phase, x1 ;[068]
|
|
|
1177 |
186:vusb-20120109/usbdrv/usbdrvasm165.inc **** andi x3, ~0x20 ;[069]
|
|
|
1178 |
187:vusb-20120109/usbdrv/usbdrvasm165.inc **** ori shift, 0x20 ;[070]
|
|
|
1179 |
188:vusb-20120109/usbdrv/usbdrvasm165.inc **** in r0, USBIN ;[071] <-- phase
|
|
|
1180 |
189:vusb-20120109/usbdrv/usbdrvasm165.inc **** mov x2, x1 ;[072]
|
|
|
1181 |
190:vusb-20120109/usbdrv/usbdrvasm165.inc **** nop ;[073]
|
|
|
1182 |
191:vusb-20120109/usbdrv/usbdrvasm165.inc **** nop2 ;[074]
|
|
|
1183 |
192 ; [---] ;[075]
|
|
|
1184 |
193:vusb-20120109/usbdrv/usbdrvasm165.inc **** in x1, USBIN ;[076] <-- bit 6
|
|
|
1185 |
194:vusb-20120109/usbdrv/usbdrvasm165.inc **** eor r0, x1 ;[077]
|
|
|
1186 |
195:vusb-20120109/usbdrv/usbdrvasm165.inc **** or phase, r0 ;[078]
|
|
|
1187 |
196:vusb-20120109/usbdrv/usbdrvasm165.inc **** eor x2, x1 ;[079]
|
|
|
1188 |
197:vusb-20120109/usbdrv/usbdrvasm165.inc **** bst x2, USBMINUS ;[080]
|
|
|
1189 |
198:vusb-20120109/usbdrv/usbdrvasm165.inc **** bld shift, 6 ;[081] no need to check bitstuffing, we just had one
|
|
|
1190 |
199:vusb-20120109/usbdrv/usbdrvasm165.inc **** in r0, USBIN ;[082] <-- phase
|
|
|
1191 |
200:vusb-20120109/usbdrv/usbdrvasm165.inc **** rjmp didUnstuff5 ;[083]
|
|
|
1192 |
201 ; [---] ;[084]
|
|
|
1193 |
202 ;[074]
|
|
|
1194 |
203
|
|
|
1195 |
204 unstuff6: ;[074]
|
|
|
1196 |
205:vusb-20120109/usbdrv/usbdrvasm165.inc **** andi x3, ~0x40 ;[075]
|
|
|
1197 |
206:vusb-20120109/usbdrv/usbdrvasm165.inc **** in x1, USBIN ;[076] <-- bit 6 again
|
|
|
1198 |
207:vusb-20120109/usbdrv/usbdrvasm165.inc **** ori shift, 0x40 ;[077]
|
|
|
1199 |
208:vusb-20120109/usbdrv/usbdrvasm165.inc **** nop2 ;[078]
|
|
|
1200 |
209 ; [---] ;[079]
|
|
|
1201 |
210:vusb-20120109/usbdrv/usbdrvasm165.inc **** rjmp didUnstuff6 ;[080]
|
|
|
1202 |
211 ; [---] ;[081]
|
|
|
1203 |
212 ;[071]
|
|
|
1204 |
213
|
|
|
1205 |
214 unstuff0: ;[013]
|
|
|
1206 |
215:vusb-20120109/usbdrv/usbdrvasm165.inc **** eor r0, x2 ;[014]
|
|
|
1207 |
216:vusb-20120109/usbdrv/usbdrvasm165.inc **** or phase, r0 ;[015]
|
|
|
1208 |
217:vusb-20120109/usbdrv/usbdrvasm165.inc **** andi x2, USBMASK ;[016] check for SE0
|
|
|
1209 |
218:vusb-20120109/usbdrv/usbdrvasm165.inc **** in r0, USBIN ;[017] <-- phase
|
|
|
1210 |
219:vusb-20120109/usbdrv/usbdrvasm165.inc **** breq didUnstuff0 ;[018] direct jump to se0 would be too long
|
|
|
1211 |
220:vusb-20120109/usbdrv/usbdrvasm165.inc **** andi x3, ~0x01 ;[019]
|
|
|
1212 |
221:vusb-20120109/usbdrv/usbdrvasm165.inc **** ori shift, 0x01 ;[020]
|
|
|
1213 |
222:vusb-20120109/usbdrv/usbdrvasm165.inc **** mov x1, x2 ;[021] mov existing sample
|
|
|
1214 |
223:vusb-20120109/usbdrv/usbdrvasm165.inc **** in x2, USBIN ;[022] <-- bit 1 again
|
|
|
1215 |
224:vusb-20120109/usbdrv/usbdrvasm165.inc **** rjmp didUnstuff0 ;[023]
|
|
|
1216 |
225 ; [---] ;[024]
|
|
|
1217 |
226 ;[014]
|
|
|
1218 |
227
|
|
|
1219 |
228 unstuff1: ;[024]
|
|
|
1220 |
229:vusb-20120109/usbdrv/usbdrvasm165.inc **** eor r0, x1 ;[025]
|
|
|
1221 |
230:vusb-20120109/usbdrv/usbdrvasm165.inc **** or phase, r0 ;[026]
|
|
|
1222 |
231:vusb-20120109/usbdrv/usbdrvasm165.inc **** andi x3, ~0x02 ;[027]
|
|
|
1223 |
232:vusb-20120109/usbdrv/usbdrvasm165.inc **** in r0, USBIN ;[028] <-- phase
|
|
|
1224 |
233:vusb-20120109/usbdrv/usbdrvasm165.inc **** ori shift, 0x02 ;[029]
|
|
|
1225 |
234:vusb-20120109/usbdrv/usbdrvasm165.inc **** mov x2, x1 ;[030]
|
|
|
1226 |
235:vusb-20120109/usbdrv/usbdrvasm165.inc **** rjmp didUnstuff1 ;[031]
|
|
|
1227 |
236 ; [---] ;[032]
|
|
|
1228 |
237 ;[022]
|
|
|
1229 |
238
|
|
|
1230 |
239 unstuff2: ;[035]
|
|
|
1231 |
240:vusb-20120109/usbdrv/usbdrvasm165.inc **** eor r0, x2 ;[036]
|
|
|
1232 |
241:vusb-20120109/usbdrv/usbdrvasm165.inc **** or phase, r0 ;[037]
|
|
|
1233 |
242:vusb-20120109/usbdrv/usbdrvasm165.inc **** andi x3, ~0x04 ;[038]
|
|
|
1234 |
243:vusb-20120109/usbdrv/usbdrvasm165.inc **** in r0, USBIN ;[039] <-- phase
|
|
|
1235 |
244:vusb-20120109/usbdrv/usbdrvasm165.inc **** ori shift, 0x04 ;[040]
|
|
|
1236 |
245:vusb-20120109/usbdrv/usbdrvasm165.inc **** mov x1, x2 ;[041]
|
|
|
1237 |
246:vusb-20120109/usbdrv/usbdrvasm165.inc **** rjmp didUnstuff2 ;[042]
|
|
|
1238 |
247 ; [---] ;[043]
|
|
|
1239 |
248 ;[033]
|
|
|
1240 |
249
|
|
|
1241 |
250 unstuff3: ;[043]
|
|
|
1242 |
251:vusb-20120109/usbdrv/usbdrvasm165.inc **** in x2, USBIN ;[044] <-- bit 3 again
|
|
|
1243 |
252:vusb-20120109/usbdrv/usbdrvasm165.inc **** eor r0, x2 ;[045]
|
|
|
1244 |
253:vusb-20120109/usbdrv/usbdrvasm165.inc **** or phase, r0 ;[046]
|
|
|
1245 |
254:vusb-20120109/usbdrv/usbdrvasm165.inc **** andi x3, ~0x08 ;[047]
|
|
|
1246 |
255:vusb-20120109/usbdrv/usbdrvasm165.inc **** ori shift, 0x08 ;[048]
|
|
|
1247 |
256:vusb-20120109/usbdrv/usbdrvasm165.inc **** nop ;[049]
|
|
|
1248 |
257:vusb-20120109/usbdrv/usbdrvasm165.inc **** in r0, USBIN ;[050] <-- phase
|
|
|
1249 |
258:vusb-20120109/usbdrv/usbdrvasm165.inc **** rjmp didUnstuff3 ;[051]
|
|
|
1250 |
259 ; [---] ;[052]
|
|
|
1251 |
260 ;[042]
|
|
|
1252 |
261
|
|
|
1253 |
262 unstuff4: ;[053]
|
|
|
1254 |
263:vusb-20120109/usbdrv/usbdrvasm165.inc **** andi x3, ~0x10 ;[054]
|
|
|
1255 |
264:vusb-20120109/usbdrv/usbdrvasm165.inc **** in x1, USBIN ;[055] <-- bit 4 again
|
|
|
1256 |
265:vusb-20120109/usbdrv/usbdrvasm165.inc **** ori shift, 0x10 ;[056]
|
|
|
1257 |
266:vusb-20120109/usbdrv/usbdrvasm165.inc **** rjmp didUnstuff4 ;[057]
|
|
|
1258 |
267 ; [---] ;[058]
|
|
|
1259 |
268 ;[048]
|
|
|
1260 |
269
|
|
|
1261 |
270 rxLoop: ;[085]
|
|
|
1262 |
271:vusb-20120109/usbdrv/usbdrvasm165.inc **** eor x3, shift ;[086] reconstruct: x3 is 0 at bit locations we changed, 1 at others
|
|
|
1263 |
272:vusb-20120109/usbdrv/usbdrvasm165.inc **** in x1, USBIN ;[000] <-- bit 0
|
|
|
1264 |
273:vusb-20120109/usbdrv/usbdrvasm165.inc **** st y+, x3 ;[001]
|
|
|
1265 |
274 ; [---] ;[002]
|
|
|
1266 |
275:vusb-20120109/usbdrv/usbdrvasm165.inc **** eor r0, x1 ;[003]
|
|
|
1267 |
276:vusb-20120109/usbdrv/usbdrvasm165.inc **** or phase, r0 ;[004]
|
|
|
1268 |
277:vusb-20120109/usbdrv/usbdrvasm165.inc **** eor x2, x1 ;[005]
|
|
|
1269 |
278:vusb-20120109/usbdrv/usbdrvasm165.inc **** in r0, USBIN ;[006] <-- phase
|
|
|
1270 |
279:vusb-20120109/usbdrv/usbdrvasm165.inc **** ser x3 ;[007]
|
|
|
1271 |
280:vusb-20120109/usbdrv/usbdrvasm165.inc **** bst x2, USBMINUS ;[008]
|
|
|
1272 |
281:vusb-20120109/usbdrv/usbdrvasm165.inc **** bld shift, 0 ;[009]
|
|
|
1273 |
282:vusb-20120109/usbdrv/usbdrvasm165.inc **** andi shift, 0xf9 ;[010]
|
|
|
1274 |
283 rxbit1: ;[ ]
|
|
|
1275 |
284:vusb-20120109/usbdrv/usbdrvasm165.inc **** in x2, USBIN ;[011] <-- bit 1
|
|
|
1276 |
285:vusb-20120109/usbdrv/usbdrvasm165.inc **** breq unstuff0 ;[012] *** unstuff escape
|
|
|
1277 |
286:vusb-20120109/usbdrv/usbdrvasm165.inc **** andi x2, USBMASK ;[013] SE0 check for bit 1
|
|
|
1278 |
287 didUnstuff0: ;[ ] Z only set if we detected SE0 in bitstuff
|
|
|
1279 |
288:vusb-20120109/usbdrv/usbdrvasm165.inc **** breq se0 ;[014]
|
|
|
1280 |
289:vusb-20120109/usbdrv/usbdrvasm165.inc **** eor r0, x2 ;[015]
|
|
|
1281 |
290:vusb-20120109/usbdrv/usbdrvasm165.inc **** or phase, r0 ;[016]
|
|
|
1282 |
291:vusb-20120109/usbdrv/usbdrvasm165.inc **** in r0, USBIN ;[017] <-- phase
|
|
|
1283 |
292:vusb-20120109/usbdrv/usbdrvasm165.inc **** eor x1, x2 ;[018]
|
|
|
1284 |
293:vusb-20120109/usbdrv/usbdrvasm165.inc **** bst x1, USBMINUS ;[019]
|
|
|
1285 |
294:vusb-20120109/usbdrv/usbdrvasm165.inc **** bld shift, 1 ;[020]
|
|
|
1286 |
295:vusb-20120109/usbdrv/usbdrvasm165.inc **** andi shift, 0xf3 ;[021]
|
|
|
1287 |
296 didUnstuff1: ;[ ]
|
|
|
1288 |
297:vusb-20120109/usbdrv/usbdrvasm165.inc **** in x1, USBIN ;[022] <-- bit 2
|
|
|
1289 |
298:vusb-20120109/usbdrv/usbdrvasm165.inc **** breq unstuff1 ;[023] *** unstuff escape
|
|
|
1290 |
299:vusb-20120109/usbdrv/usbdrvasm165.inc **** eor r0, x1 ;[024]
|
|
|
1291 |
300:vusb-20120109/usbdrv/usbdrvasm165.inc **** or phase, r0 ;[025]
|
|
|
1292 |
301:vusb-20120109/usbdrv/usbdrvasm165.inc **** subi cnt, 1 ;[026] overflow check
|
|
|
1293 |
302:vusb-20120109/usbdrv/usbdrvasm165.inc **** brcs overflow ;[027]
|
|
|
1294 |
303:vusb-20120109/usbdrv/usbdrvasm165.inc **** in r0, USBIN ;[028] <-- phase
|
|
|
1295 |
304:vusb-20120109/usbdrv/usbdrvasm165.inc **** eor x2, x1 ;[029]
|
|
|
1296 |
305:vusb-20120109/usbdrv/usbdrvasm165.inc **** bst x2, USBMINUS ;[030]
|
|
|
1297 |
306:vusb-20120109/usbdrv/usbdrvasm165.inc **** bld shift, 2 ;[031]
|
|
|
1298 |
307:vusb-20120109/usbdrv/usbdrvasm165.inc **** andi shift, 0xe7 ;[032]
|
|
|
1299 |
308 didUnstuff2: ;[ ]
|
|
|
1300 |
309:vusb-20120109/usbdrv/usbdrvasm165.inc **** in x2, USBIN ;[033] <-- bit 3
|
|
|
1301 |
310:vusb-20120109/usbdrv/usbdrvasm165.inc **** breq unstuff2 ;[034] *** unstuff escape
|
|
|
1302 |
311:vusb-20120109/usbdrv/usbdrvasm165.inc **** eor r0, x2 ;[035]
|
|
|
1303 |
312:vusb-20120109/usbdrv/usbdrvasm165.inc **** or phase, r0 ;[036]
|
|
|
1304 |
313:vusb-20120109/usbdrv/usbdrvasm165.inc **** eor x1, x2 ;[037]
|
|
|
1305 |
314:vusb-20120109/usbdrv/usbdrvasm165.inc **** bst x1, USBMINUS ;[038]
|
|
|
1306 |
315:vusb-20120109/usbdrv/usbdrvasm165.inc **** in r0, USBIN ;[039] <-- phase
|
|
|
1307 |
316:vusb-20120109/usbdrv/usbdrvasm165.inc **** bld shift, 3 ;[040]
|
|
|
1308 |
317:vusb-20120109/usbdrv/usbdrvasm165.inc **** andi shift, 0xcf ;[041]
|
|
|
1309 |
318 didUnstuff3: ;[ ]
|
|
|
1310 |
319:vusb-20120109/usbdrv/usbdrvasm165.inc **** breq unstuff3 ;[042] *** unstuff escape
|
|
|
1311 |
320:vusb-20120109/usbdrv/usbdrvasm165.inc **** nop ;[043]
|
|
|
1312 |
321:vusb-20120109/usbdrv/usbdrvasm165.inc **** in x1, USBIN ;[044] <-- bit 4
|
|
|
1313 |
322:vusb-20120109/usbdrv/usbdrvasm165.inc **** eor x2, x1 ;[045]
|
|
|
1314 |
323:vusb-20120109/usbdrv/usbdrvasm165.inc **** bst x2, USBMINUS ;[046]
|
|
|
1315 |
324:vusb-20120109/usbdrv/usbdrvasm165.inc **** bld shift, 4 ;[047]
|
|
|
1316 |
325 didUnstuff4: ;[ ]
|
|
|
1317 |
326:vusb-20120109/usbdrv/usbdrvasm165.inc **** eor r0, x1 ;[048]
|
|
|
1318 |
327:vusb-20120109/usbdrv/usbdrvasm165.inc **** or phase, r0 ;[049]
|
|
|
1319 |
328:vusb-20120109/usbdrv/usbdrvasm165.inc **** in r0, USBIN ;[050] <-- phase
|
|
|
1320 |
329:vusb-20120109/usbdrv/usbdrvasm165.inc **** andi shift, 0x9f ;[051]
|
|
|
1321 |
330:vusb-20120109/usbdrv/usbdrvasm165.inc **** breq unstuff4 ;[052] *** unstuff escape
|
|
|
1322 |
331:vusb-20120109/usbdrv/usbdrvasm165.inc **** rjmp continueWithBit5;[053]
|
|
|
1323 |
332 ; [---] ;[054]
|
|
|
1324 |
333
|
|
|
1325 |
334 macro POP_STANDARD ; 16 cycles
|
|
|
1326 |
335 pop cnt
|
|
|
1327 |
336 pop x4
|
|
|
1328 |
337 pop x3
|
|
|
1329 |
338 pop x2
|
|
|
1330 |
339 pop x1
|
|
|
1331 |
340 pop shift
|
|
|
1332 |
341 pop YH
|
|
|
1333 |
342 pop r0
|
|
|
1334 |
343 endm
|
|
|
1335 |
344 macro POP_RETI ; 5 cycles
|
|
|
1336 |
345 pop YL
|
|
|
1337 |
346 out SREG, YL
|
|
|
1338 |
347 pop YL
|
|
|
1339 |
348 endm
|
|
|
1340 |
349
|
|
|
1341 |
350 #include "asmcommon.inc"
|
|
|
1342 |
1 /* Name: asmcommon.inc
|
|
|
1343 |
2 * Project: V-USB, virtual USB port for Atmel's(r) AVR(r) microcontrollers
|
|
|
1344 |
3 * Author: Christian Starkjohann
|
|
|
1345 |
4 * Creation Date: 2007-11-05
|
|
|
1346 |
5 * Tabsize: 4
|
|
|
1347 |
6 * Copyright: (c) 2007 by OBJECTIVE DEVELOPMENT Software GmbH
|
|
|
1348 |
7 * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
|
|
|
1349 |
8 * Revision: $Id$
|
|
|
1350 |
9 */
|
|
|
1351 |
10
|
|
|
1352 |
11 /* Do not link this file! Link usbdrvasm.S instead, which includes the
|
|
|
1353 |
12 * appropriate implementation!
|
|
|
1354 |
13 */
|
|
|
1355 |
14
|
|
|
1356 |
15 /*
|
|
|
1357 |
16 General Description:
|
|
|
1358 |
17 This file contains assembler code which is shared among the USB driver
|
|
|
1359 |
18 implementations for different CPU cocks. Since the code must be inserted
|
|
|
1360 |
19 in the middle of the module, it's split out into this file and #included.
|
|
|
1361 |
20
|
|
|
1362 |
21 Jump destinations called from outside:
|
|
|
1363 |
22 sofError: Called when no start sequence was found.
|
|
|
1364 |
23 se0: Called when a package has been successfully received.
|
|
|
1365 |
24 overflow: Called when receive buffer overflows.
|
|
|
1366 |
25 doReturn: Called after sending data.
|
|
|
1367 |
26
|
|
|
1368 |
27 Outside jump destinations used by this module:
|
|
|
1369 |
28 waitForJ: Called to receive an already arriving packet.
|
|
|
1370 |
29 sendAckAndReti:
|
|
|
1371 |
30 sendNakAndReti:
|
|
|
1372 |
31 sendCntAndReti:
|
|
|
1373 |
32 usbSendAndReti:
|
|
|
1374 |
33
|
|
|
1375 |
34 The following macros must be defined before this file is included:
|
|
|
1376 |
35 .macro POP_STANDARD
|
|
|
1377 |
36 .endm
|
|
|
1378 |
37 .macro POP_RETI
|
|
|
1379 |
38 .endm
|
|
|
1380 |
39 */
|
|
|
1381 |
40
|
|
|
1382 |
41 #define token x1
|
|
|
1383 |
42
|
|
|
1384 |
43 overflow:
|
|
|
1385 |
44:vusb-20120109/usbdrv/asmcommon.inc **** ldi x2, 1<<USB_INTR_PENDING_BIT
|
|
|
1386 |
45:vusb-20120109/usbdrv/asmcommon.inc **** USB_STORE_PENDING(x2) ; clear any pending interrupts
|
|
|
1387 |
46 ignorePacket:
|
|
|
1388 |
47:vusb-20120109/usbdrv/asmcommon.inc **** clr token
|
|
|
1389 |
48:vusb-20120109/usbdrv/asmcommon.inc **** rjmp storeTokenAndReturn
|
|
|
1390 |
49
|
|
|
1391 |
50 ;----------------------------------------------------------------------------
|
|
|
1392 |
51 ; Processing of received packet (numbers in brackets are cycles after center of SE0)
|
|
|
1393 |
52 ;----------------------------------------------------------------------------
|
|
|
1394 |
53 ;This is the only non-error exit point for the software receiver loop
|
|
|
1395 |
54 ;we don't check any CRCs here because there is no time left.
|
|
|
1396 |
55 se0:
|
|
|
1397 |
56:vusb-20120109/usbdrv/asmcommon.inc **** subi cnt, USB_BUFSIZE ;[5]
|
|
|
1398 |
57:vusb-20120109/usbdrv/asmcommon.inc **** neg cnt ;[6]
|
|
|
1399 |
58:vusb-20120109/usbdrv/asmcommon.inc **** sub YL, cnt ;[7]
|
|
|
1400 |
59:vusb-20120109/usbdrv/asmcommon.inc **** sbci YH, 0 ;[8]
|
|
|
1401 |
60:vusb-20120109/usbdrv/asmcommon.inc **** ldi x2, 1<<USB_INTR_PENDING_BIT ;[9]
|
|
|
1402 |
61:vusb-20120109/usbdrv/asmcommon.inc **** USB_STORE_PENDING(x2) ;[10] clear pending intr and check flag later. SE0 should be over.
|
|
|
1403 |
62:vusb-20120109/usbdrv/asmcommon.inc **** ld token, y ;[11]
|
|
|
1404 |
63:vusb-20120109/usbdrv/asmcommon.inc **** cpi token, USBPID_DATA0 ;[13]
|
|
|
1405 |
64:vusb-20120109/usbdrv/asmcommon.inc **** breq handleData ;[14]
|
|
|
1406 |
65:vusb-20120109/usbdrv/asmcommon.inc **** cpi token, USBPID_DATA1 ;[15]
|
|
|
1407 |
66:vusb-20120109/usbdrv/asmcommon.inc **** breq handleData ;[16]
|
|
|
1408 |
67:vusb-20120109/usbdrv/asmcommon.inc **** lds shift, usbDeviceAddr;[17]
|
|
|
1409 |
68:vusb-20120109/usbdrv/asmcommon.inc **** ldd x2, y+1 ;[19] ADDR and 1 bit endpoint number
|
|
|
1410 |
69:vusb-20120109/usbdrv/asmcommon.inc **** lsl x2 ;[21] shift out 1 bit endpoint number
|
|
|
1411 |
70:vusb-20120109/usbdrv/asmcommon.inc **** cpse x2, shift ;[22]
|
|
|
1412 |
71:vusb-20120109/usbdrv/asmcommon.inc **** rjmp ignorePacket ;[23]
|
|
|
1413 |
72 /* only compute endpoint number in x3 if required later */
|
|
|
1414 |
73 #if USB_CFG_HAVE_INTRIN_ENDPOINT || USB_CFG_IMPLEMENT_FN_WRITEOUT
|
|
|
1415 |
74:vusb-20120109/usbdrv/asmcommon.inc **** ldd x3, y+2 ;[24] endpoint number + crc
|
|
|
1416 |
75:vusb-20120109/usbdrv/asmcommon.inc **** rol x3 ;[26] shift in LSB of endpoint
|
|
|
1417 |
76 #endif
|
|
|
1418 |
77:vusb-20120109/usbdrv/asmcommon.inc **** cpi token, USBPID_IN ;[27]
|
|
|
1419 |
78:vusb-20120109/usbdrv/asmcommon.inc **** breq handleIn ;[28]
|
|
|
1420 |
79:vusb-20120109/usbdrv/asmcommon.inc **** cpi token, USBPID_SETUP ;[29]
|
|
|
1421 |
80:vusb-20120109/usbdrv/asmcommon.inc **** breq handleSetupOrOut ;[30]
|
|
|
1422 |
81:vusb-20120109/usbdrv/asmcommon.inc **** cpi token, USBPID_OUT ;[31]
|
|
|
1423 |
82:vusb-20120109/usbdrv/asmcommon.inc **** brne ignorePacket ;[32] must be ack, nak or whatever
|
|
|
1424 |
83 ; rjmp handleSetupOrOut ; fallthrough
|
|
|
1425 |
84
|
|
|
1426 |
85 ;Setup and Out are followed by a data packet two bit times (16 cycles) after
|
|
|
1427 |
86 ;the end of SE0. The sync code allows up to 40 cycles delay from the start of
|
|
|
1428 |
87 ;the sync pattern until the first bit is sampled. That's a total of 56 cycles.
|
|
|
1429 |
88 handleSetupOrOut: ;[32]
|
|
|
1430 |
89 #if USB_CFG_IMPLEMENT_FN_WRITEOUT /* if we have data for endpoint != 0, set usbCurrentTok to addr
|
|
|
1431 |
90 andi x3, 0xf ;[32]
|
|
|
1432 |
91 breq storeTokenAndReturn ;[33]
|
|
|
1433 |
92 mov token, x3 ;[34] indicate that this is endpoint x OUT
|
|
|
1434 |
93 #endif
|
|
|
1435 |
94 storeTokenAndReturn:
|
|
|
1436 |
95:vusb-20120109/usbdrv/asmcommon.inc **** sts usbCurrentTok, token;[35]
|
|
|
1437 |
96 doReturn:
|
|
|
1438 |
97:vusb-20120109/usbdrv/asmcommon.inc **** POP_STANDARD ;[37] 12...16 cycles
|
|
|
1439 |
98:vusb-20120109/usbdrv/asmcommon.inc **** USB_LOAD_PENDING(YL) ;[49]
|
|
|
1440 |
99:vusb-20120109/usbdrv/asmcommon.inc **** sbrc YL, USB_INTR_PENDING_BIT;[50] check whether data is already arriving
|
|
|
1441 |
100:vusb-20120109/usbdrv/asmcommon.inc **** rjmp waitForJ ;[51] save the pops and pushes -- a new interrupt is already pendin
|
|
|
1442 |
101 sofError:
|
|
|
1443 |
102:vusb-20120109/usbdrv/asmcommon.inc **** POP_RETI ;macro call
|
|
|
1444 |
103:vusb-20120109/usbdrv/asmcommon.inc **** reti
|
|
|
1445 |
104
|
|
|
1446 |
105 handleData:
|
|
|
1447 |
106 #if USB_CFG_CHECK_CRC
|
|
|
1448 |
107 CRC_CLEANUP_AND_CHECK ; jumps to ignorePacket if CRC error
|
|
|
1449 |
108 #endif
|
|
|
1450 |
109:vusb-20120109/usbdrv/asmcommon.inc **** lds shift, usbCurrentTok;[18]
|
|
|
1451 |
110:vusb-20120109/usbdrv/asmcommon.inc **** tst shift ;[20]
|
|
|
1452 |
111:vusb-20120109/usbdrv/asmcommon.inc **** breq doReturn ;[21]
|
|
|
1453 |
112:vusb-20120109/usbdrv/asmcommon.inc **** lds x2, usbRxLen ;[22]
|
|
|
1454 |
113:vusb-20120109/usbdrv/asmcommon.inc **** tst x2 ;[24]
|
|
|
1455 |
114:vusb-20120109/usbdrv/asmcommon.inc **** brne sendNakAndReti ;[25]
|
|
|
1456 |
115 ; 2006-03-11: The following two lines fix a problem where the device was not
|
|
|
1457 |
116 ; recognized if usbPoll() was called less frequently than once every 4 ms.
|
|
|
1458 |
117:vusb-20120109/usbdrv/asmcommon.inc **** cpi cnt, 4 ;[26] zero sized data packets are status phase only -- ignore and a
|
|
|
1459 |
118:vusb-20120109/usbdrv/asmcommon.inc **** brmi sendAckAndReti ;[27] keep rx buffer clean -- we must not NAK next SETUP
|
|
|
1460 |
119 #if USB_CFG_CHECK_DATA_TOGGLING
|
|
|
1461 |
120 sts usbCurrentDataToken, token ; store for checking by C code
|
|
|
1462 |
121 #endif
|
|
|
1463 |
122:vusb-20120109/usbdrv/asmcommon.inc **** sts usbRxLen, cnt ;[28] store received data, swap buffers
|
|
|
1464 |
123:vusb-20120109/usbdrv/asmcommon.inc **** sts usbRxToken, shift ;[30]
|
|
|
1465 |
124:vusb-20120109/usbdrv/asmcommon.inc **** lds x2, usbInputBufOffset;[32] swap buffers
|
|
|
1466 |
125:vusb-20120109/usbdrv/asmcommon.inc **** ldi cnt, USB_BUFSIZE ;[34]
|
|
|
1467 |
126:vusb-20120109/usbdrv/asmcommon.inc **** sub cnt, x2 ;[35]
|
|
|
1468 |
127:vusb-20120109/usbdrv/asmcommon.inc **** sts usbInputBufOffset, cnt;[36] buffers now swapped
|
|
|
1469 |
128:vusb-20120109/usbdrv/asmcommon.inc **** rjmp sendAckAndReti ;[38] 40 + 17 = 57 until SOP
|
|
|
1470 |
129
|
|
|
1471 |
130 handleIn:
|
|
|
1472 |
131 ;We don't send any data as long as the C code has not processed the current
|
|
|
1473 |
132 ;input data and potentially updated the output data. That's more efficient
|
|
|
1474 |
133 ;in terms of code size than clearing the tx buffers when a packet is received.
|
|
|
1475 |
134:vusb-20120109/usbdrv/asmcommon.inc **** lds x1, usbRxLen ;[30]
|
|
|
1476 |
135:vusb-20120109/usbdrv/asmcommon.inc **** cpi x1, 1 ;[32] negative values are flow control, 0 means "buffer free"
|
|
|
1477 |
136:vusb-20120109/usbdrv/asmcommon.inc **** brge sendNakAndReti ;[33] unprocessed input packet?
|
|
|
1478 |
137:vusb-20120109/usbdrv/asmcommon.inc **** ldi x1, USBPID_NAK ;[34] prepare value for usbTxLen
|
|
|
1479 |
138 #if USB_CFG_HAVE_INTRIN_ENDPOINT
|
|
|
1480 |
139:vusb-20120109/usbdrv/asmcommon.inc **** andi x3, 0xf ;[35] x3 contains endpoint
|
|
|
1481 |
140 #if USB_CFG_SUPPRESS_INTR_CODE
|
|
|
1482 |
141 brne sendNakAndReti ;[36]
|
|
|
1483 |
142 #else
|
|
|
1484 |
143:vusb-20120109/usbdrv/asmcommon.inc **** brne handleIn1 ;[36]
|
|
|
1485 |
144 #endif
|
|
|
1486 |
145 #endif
|
|
|
1487 |
146:vusb-20120109/usbdrv/asmcommon.inc **** lds cnt, usbTxLen ;[37]
|
|
|
1488 |
147:vusb-20120109/usbdrv/asmcommon.inc **** sbrc cnt, 4 ;[39] all handshake tokens have bit 4 set
|
|
|
1489 |
148:vusb-20120109/usbdrv/asmcommon.inc **** rjmp sendCntAndReti ;[40] 42 + 16 = 58 until SOP
|
|
|
1490 |
149:vusb-20120109/usbdrv/asmcommon.inc **** sts usbTxLen, x1 ;[41] x1 == USBPID_NAK from above
|
|
|
1491 |
150:vusb-20120109/usbdrv/asmcommon.inc **** ldi YL, lo8(usbTxBuf) ;[43]
|
|
|
1492 |
151:vusb-20120109/usbdrv/asmcommon.inc **** ldi YH, hi8(usbTxBuf) ;[44]
|
|
|
1493 |
152:vusb-20120109/usbdrv/asmcommon.inc **** rjmp usbSendAndReti ;[45] 57 + 12 = 59 until SOP
|
|
|
1494 |
153
|
|
|
1495 |
154 ; Comment about when to set usbTxLen to USBPID_NAK:
|
|
|
1496 |
155 ; We should set it back when we receive the ACK from the host. This would
|
|
|
1497 |
156 ; be simple to implement: One static variable which stores whether the last
|
|
|
1498 |
157 ; tx was for endpoint 0 or 1 and a compare in the receiver to distinguish the
|
|
|
1499 |
158 ; ACK. However, we set it back immediately when we send the package,
|
|
|
1500 |
159 ; assuming that no error occurs and the host sends an ACK. We save one byte
|
|
|
1501 |
160 ; RAM this way and avoid potential problems with endless retries. The rest of
|
|
|
1502 |
161 ; the driver assumes error-free transfers anyway.
|
|
|
1503 |
162
|
|
|
1504 |
163 #if !USB_CFG_SUPPRESS_INTR_CODE && USB_CFG_HAVE_INTRIN_ENDPOINT /* placed here due to relative jump
|
|
|
1505 |
164 handleIn1: ;[38]
|
|
|
1506 |
165 #if USB_CFG_HAVE_INTRIN_ENDPOINT3
|
|
|
1507 |
166 ; 2006-06-10 as suggested by O.Tamura: support second INTR IN / BULK IN endpoint
|
|
|
1508 |
167 cpi x3, USB_CFG_EP3_NUMBER;[38]
|
|
|
1509 |
168 breq handleIn3 ;[39]
|
|
|
1510 |
169 #endif
|
|
|
1511 |
170:vusb-20120109/usbdrv/asmcommon.inc **** lds cnt, usbTxLen1 ;[40]
|
|
|
1512 |
171:vusb-20120109/usbdrv/asmcommon.inc **** sbrc cnt, 4 ;[42] all handshake tokens have bit 4 set
|
|
|
1513 |
172:vusb-20120109/usbdrv/asmcommon.inc **** rjmp sendCntAndReti ;[43] 47 + 16 = 63 until SOP
|
|
|
1514 |
173:vusb-20120109/usbdrv/asmcommon.inc **** sts usbTxLen1, x1 ;[44] x1 == USBPID_NAK from above
|
|
|
1515 |
174:vusb-20120109/usbdrv/asmcommon.inc **** ldi YL, lo8(usbTxBuf1) ;[46]
|
|
|
1516 |
175:vusb-20120109/usbdrv/asmcommon.inc **** ldi YH, hi8(usbTxBuf1) ;[47]
|
|
|
1517 |
176:vusb-20120109/usbdrv/asmcommon.inc **** rjmp usbSendAndReti ;[48] 50 + 12 = 62 until SOP
|
|
|
1518 |
177
|
|
|
1519 |
351 = (D+ = 0), (D- = 1)
|
|
|
1520 |
352 ; K = (D+ = 1), (D- = 0)
|
|
|
1521 |
353 ; Spec allows 7.5 bit times from EOP to SOP for replies
|
|
|
1522 |
354
|
|
|
1523 |
355 bitstuff7:
|
|
|
1524 |
356 eor x1, x4 ;[4]
|
|
|
1525 |
357 ldi x2, 0 ;[5]
|
|
|
1526 |
358 nop2 ;[6] C is zero (brcc)
|
|
|
1527 |
359 rjmp didStuff7 ;[8]
|
|
|
1528 |
360:vusb-20120109/usbdrv/usbdrvasm165.inc ****
|
|
|
1529 |
361:vusb-20120109/usbdrv/usbdrvasm165.inc **** bitstuffN:
|
|
|
1530 |
362:vusb-20120109/usbdrv/usbdrvasm165.inc **** eor x1, x4 ;[5]
|
|
|
1531 |
363:vusb-20120109/usbdrv/usbdrvasm165.inc **** ldi x2, 0 ;[6]
|
|
|
1532 |
364 lpm ;[7] 3 cycle NOP, modifies r0
|
|
|
1533 |
365 out USBOUT, x1 ;[10] <-- out
|
|
|
1534 |
366:vusb-20120109/usbdrv/usbdrvasm165.inc **** rjmp didStuffN ;[0]
|
|
|
1535 |
367:vusb-20120109/usbdrv/usbdrvasm165.inc ****
|
|
|
1536 |
368:vusb-20120109/usbdrv/usbdrvasm165.inc **** #define bitStatus x3
|
|
|
1537 |
369:vusb-20120109/usbdrv/usbdrvasm165.inc ****
|
|
|
1538 |
370:vusb-20120109/usbdrv/usbdrvasm165.inc **** sendNakAndReti:
|
|
|
1539 |
371 ldi cnt, USBPID_NAK ;[-19]
|
|
|
1540 |
372 rjmp sendCntAndReti ;[-18]
|
|
|
1541 |
373 sendAckAndReti:
|
|
|
1542 |
374 ldi cnt, USBPID_ACK ;[-17]
|
|
|
1543 |
375:vusb-20120109/usbdrv/usbdrvasm165.inc **** sendCntAndReti:
|
|
|
1544 |
376:vusb-20120109/usbdrv/usbdrvasm165.inc **** mov r0, cnt ;[-16]
|
|
|
1545 |
377 ldi YL, 0 ;[-15] R0 address is 0
|
|
|
1546 |
378:vusb-20120109/usbdrv/usbdrvasm165.inc **** ldi YH, 0 ;[-14]
|
|
|
1547 |
379 ldi cnt, 2 ;[-13]
|
|
|
1548 |
380:vusb-20120109/usbdrv/usbdrvasm165.inc **** ; rjmp usbSendAndReti fallthrough
|
|
|
1549 |
381:vusb-20120109/usbdrv/usbdrvasm165.inc ****
|
|
|
1550 |
382:vusb-20120109/usbdrv/usbdrvasm165.inc **** ;usbSend:
|
|
|
1551 |
383:vusb-20120109/usbdrv/usbdrvasm165.inc **** ;pointer to data in 'Y'
|
|
|
1552 |
384 ;number of bytes in 'cnt' -- including sync byte [range 2 ... 12]
|
|
|
1553 |
385 ;uses: x1...x4, shift, cnt, Y
|
|
|
1554 |
386 ;Numbers in brackets are time since first bit of sync pattern is sent
|
|
|
1555 |
387 usbSendAndReti: ; 12 cycles until SOP
|
|
|
1556 |
388 in x2, USBDDR ;[-12]
|
|
|
1557 |
389 ori x2, USBMASK ;[-11]
|
|
|
1558 |
390 sbi USBOUT, USBMINUS;[-10] prepare idle state; D+ and D- must have been 0 (no pullups)
|
|
|
1559 |
391 in x1, USBOUT ;[-8] port mirror for tx loop
|
|
|
1560 |
392:vusb-20120109/usbdrv/usbdrvasm165.inc **** out USBDDR, x2 ;[-7] <- acquire bus
|
|
|
1561 |
393:vusb-20120109/usbdrv/usbdrvasm165.inc **** ; need not init x2 (bitstuff history) because sync starts with 0
|
|
|
1562 |
394:vusb-20120109/usbdrv/usbdrvasm165.inc **** ldi x4, USBMASK ;[-6] exor mask
|
|
|
1563 |
395:vusb-20120109/usbdrv/usbdrvasm165.inc **** ldi shift, 0x80 ;[-5] sync byte is first byte sent
|
|
|
1564 |
396:vusb-20120109/usbdrv/usbdrvasm165.inc **** ldi bitStatus, 0xff ;[-4] init bit loop counter, works for up to 12 bytes
|
|
|
1565 |
397 byteloop:
|
|
|
1566 |
398:vusb-20120109/usbdrv/usbdrvasm165.inc **** bitloop:
|
|
|
1567 |
399:vusb-20120109/usbdrv/usbdrvasm165.inc **** sbrs shift, 0 ;[8] [-3]
|
|
|
1568 |
400:vusb-20120109/usbdrv/usbdrvasm165.inc **** eor x1, x4 ;[9] [-2]
|
|
|
1569 |
401 out USBOUT, x1 ;[10] [-1] <-- out
|
|
|
1570 |
402 ror shift ;[0]
|
|
|
1571 |
403:vusb-20120109/usbdrv/usbdrvasm165.inc **** ror x2 ;[1]
|
|
|
1572 |
404:vusb-20120109/usbdrv/usbdrvasm165.inc **** didStuffN:
|
|
|
1573 |
405:vusb-20120109/usbdrv/usbdrvasm165.inc **** cpi x2, 0xfc ;[2]
|
|
|
1574 |
406:vusb-20120109/usbdrv/usbdrvasm165.inc **** brcc bitstuffN ;[3]
|
|
|
1575 |
407:vusb-20120109/usbdrv/usbdrvasm165.inc **** nop ;[4]
|
|
|
1576 |
408 subi bitStatus, 37 ;[5] 256 / 7 ~=~ 37
|
|
|
1577 |
409:vusb-20120109/usbdrv/usbdrvasm165.inc **** brcc bitloop ;[6] when we leave the loop, bitStatus has almost the initial value
|
|
|
1578 |
410:vusb-20120109/usbdrv/usbdrvasm165.inc **** sbrs shift, 0 ;[7]
|
|
|
1579 |
411:vusb-20120109/usbdrv/usbdrvasm165.inc **** eor x1, x4 ;[8]
|
|
|
1580 |
412:vusb-20120109/usbdrv/usbdrvasm165.inc **** ror shift ;[9]
|
|
|
1581 |
413:vusb-20120109/usbdrv/usbdrvasm165.inc **** didStuff7:
|
|
|
1582 |
414:vusb-20120109/usbdrv/usbdrvasm165.inc **** out USBOUT, x1 ;[10] <-- out
|
|
|
1583 |
415:vusb-20120109/usbdrv/usbdrvasm165.inc **** ror x2 ;[0]
|
|
|
1584 |
416:vusb-20120109/usbdrv/usbdrvasm165.inc **** cpi x2, 0xfc ;[1]
|
|
|
1585 |
417 brcc bitstuff7 ;[2]
|
|
|
1586 |
418:vusb-20120109/usbdrv/usbdrvasm165.inc **** ld shift, y+ ;[3]
|
|
|
1587 |
419:vusb-20120109/usbdrv/usbdrvasm165.inc **** dec cnt ;[5]
|
|
|
1588 |
420:vusb-20120109/usbdrv/usbdrvasm165.inc **** brne byteloop ;[6]
|
|
|
1589 |
421:vusb-20120109/usbdrv/usbdrvasm165.inc **** ;make SE0:
|
|
|
1590 |
422:vusb-20120109/usbdrv/usbdrvasm165.inc **** cbr x1, USBMASK ;[7] prepare SE0 [spec says EOP may be 21 to 25 cycles]
|
|
|
1591 |
423:vusb-20120109/usbdrv/usbdrvasm165.inc **** lds x2, usbNewDeviceAddr;[8]
|
|
|
1592 |
424:vusb-20120109/usbdrv/usbdrvasm165.inc **** lsl x2 ;[10] we compare with left shifted address
|
|
|
1593 |
425 out USBOUT, x1 ;[11] <-- out SE0 -- from now 2 bits = 22 cycles until bus idle
|
|
|
1594 |
426:vusb-20120109/usbdrv/usbdrvasm165.inc **** ;2006-03-06: moved transfer of new address to usbDeviceAddr from C-Code to asm:
|
|
|
1595 |
427:vusb-20120109/usbdrv/usbdrvasm165.inc **** ;set address only after data packet was sent, not after handshake
|
|
|
1596 |
428:vusb-20120109/usbdrv/usbdrvasm165.inc **** subi YL, 2 ;[0] Only assign address on data packets, not ACK/NAK in r0
|
|
|
1597 |
429:vusb-20120109/usbdrv/usbdrvasm165.inc **** sbci YH, 0 ;[1]
|
|
|
1598 |
430 breq skipAddrAssign ;[2]
|
|
|
1599 |
431 sts usbDeviceAddr, x2; if not skipped: SE0 is one cycle longer
|
|
|
1600 |
432:vusb-20120109/usbdrv/usbdrvasm165.inc **** skipAddrAssign:
|
|
|
1601 |
433:vusb-20120109/usbdrv/usbdrvasm165.inc **** ;end of usbDeviceAddress transfer
|
|
|
1602 |
434:vusb-20120109/usbdrv/usbdrvasm165.inc **** ldi x2, 1<<USB_INTR_PENDING_BIT;[4] int0 occurred during TX -- clear pending flag
|
|
|
1603 |
435:vusb-20120109/usbdrv/usbdrvasm165.inc **** USB_STORE_PENDING(x2) ;[5]
|
|
|
1604 |
436 ori x1, USBIDLE ;[6]
|
|
|
1605 |
437 in x2, USBDDR ;[7]
|
|
|
1606 |
438:vusb-20120109/usbdrv/usbdrvasm165.inc **** cbr x2, USBMASK ;[8] set both pins to input
|
|
|
1607 |
439:vusb-20120109/usbdrv/usbdrvasm165.inc **** mov x3, x1 ;[9]
|
|
|
1608 |
440:vusb-20120109/usbdrv/usbdrvasm165.inc **** cbr x3, USBMASK ;[10] configure no pullup on both pins
|
|
|
1609 |
441:vusb-20120109/usbdrv/usbdrvasm165.inc **** ldi x4, 4 ;[11]
|
|
|
1610 |
442:vusb-20120109/usbdrv/usbdrvasm165.inc **** se0Delay:
|
|
|
1611 |
443:vusb-20120109/usbdrv/usbdrvasm165.inc **** dec x4 ;[12] [15] [18] [21]
|
|
|
1612 |
444:vusb-20120109/usbdrv/usbdrvasm165.inc **** brne se0Delay ;[13] [16] [19] [22]
|
|
|
1613 |
445:vusb-20120109/usbdrv/usbdrvasm165.inc **** out USBOUT, x1 ;[23] <-- out J (idle) -- end of SE0 (EOP signal)
|
|
|
1614 |
446 out USBDDR, x2 ;[24] <-- release bus now
|
|
|
1615 |
447:vusb-20120109/usbdrv/usbdrvasm165.inc **** out USBOUT, x3 ;[25] <-- ensure no pull-up resistors are active
|
|
|
1616 |
448:vusb-20120109/usbdrv/usbdrvasm165.inc **** rjmp doReturn
|
|
|
1617 |
449:vusb-20120109/usbdrv/usbdrvasm165.inc ****
|
|
|
1618 |
450:vusb-20120109/usbdrv/usbdrvasm165.inc **** ...
|
|
|
1619 |
DEFINED SYMBOLS
|
|
|
1620 |
vusb-20120109/usbdrv/usbdrvasm165.inc:39 .text:00000058 __vector_1
|
|
|
1621 |
vusb-20120109/usbdrv/usbdrvasm.S:233 .text:00000000 usbCrc16
|
|
|
1622 |
vusb-20120109/usbdrv/usbdrvasm.S:265 .text:0000002a usbCrc16Append
|
|
|
1623 |
vusb-20120109/usbdrv/usbdrvasm.S:255 .text:00000024 usbCrcLoopEntry
|
|
|
1624 |
vusb-20120109/usbdrv/usbdrvasm.S:243 .text:00000012 usbCrcByteLoop
|
|
|
1625 |
vusb-20120109/usbdrv/usbdrvasm.S:246 .text:00000016 usbCrcBitLoop
|
|
|
1626 |
vusb-20120109/usbdrv/usbdrvasm.S:252 .text:00000020 usbCrcNoXor
|
|
|
1627 |
vusb-20120109/usbdrv/usbdrvasm.S:258 .text:00000028 usbCrcReady
|
|
|
1628 |
vusb-20120109/usbdrv/usbdrvasm.S:320 .text:00000032 usbMeasureFrameLength
|
|
|
1629 |
vusb-20120109/usbdrv/usbdrvasm.S:324 .text:00000038 usbMFTime16
|
|
|
1630 |
vusb-20120109/usbdrv/usbdrvasm.S:343 .text:00000056 usbMFTimeout
|
|
|
1631 |
vusb-20120109/usbdrv/usbdrvasm.S:327 .text:0000003c usbMFWaitStrobe
|
|
|
1632 |
vusb-20120109/usbdrv/usbdrvasm.S:332 .text:00000044 usbMFWaitIdle
|
|
|
1633 |
vusb-20120109/usbdrv/usbdrvasm.S:337 .text:0000004c usbMFWaitLoop
|
|
|
1634 |
vusb-20120109/usbdrv/usbdrvasm165.inc:52 .text:0000005e waitForJ
|
|
|
1635 |
vusb-20120109/usbdrv/usbdrvasm165.inc:56 .text:00000064 waitForK
|
|
|
1636 |
vusb-20120109/usbdrv/usbdrvasm165.inc:79 .text:0000007e foundK
|
|
|
1637 |
vusb-20120109/usbdrv/asmcommon.inc:101 .text:00000228 sofError
|
|
|
1638 |
vusb-20120109/usbdrv/usbdrvasm165.inc:104 .text:00000098 haveTwoBitsK
|
|
|
1639 |
vusb-20120109/usbdrv/usbdrvasm165.inc:283 .text:0000017e rxbit1
|
|
|
1640 |
vusb-20120109/usbdrv/usbdrvasm165.inc:140 .text:000000b4 continueWithBit5
|
|
|
1641 |
vusb-20120109/usbdrv/usbdrvasm165.inc:184 .text:000000f8 unstuff5
|
|
|
1642 |
vusb-20120109/usbdrv/usbdrvasm165.inc:157 .text:000000d4 didUnstuff6
|
|
|
1643 |
vusb-20120109/usbdrv/usbdrvasm165.inc:204 .text:00000116 unstuff6
|
|
|
1644 |
vusb-20120109/usbdrv/usbdrvasm165.inc:161 .text:000000da didUnstuff5
|
|
|
1645 |
vusb-20120109/usbdrv/usbdrvasm165.inc:168 .text:000000e4 didUnstuff7
|
|
|
1646 |
vusb-20120109/usbdrv/usbdrvasm165.inc:270 .text:00000168 rxLoop
|
|
|
1647 |
vusb-20120109/usbdrv/usbdrvasm165.inc:175 .text:000000ee unstuff7
|
|
|
1648 |
vusb-20120109/usbdrv/usbdrvasm165.inc:214 .text:00000120 unstuff0
|
|
|
1649 |
vusb-20120109/usbdrv/usbdrvasm165.inc:287 .text:00000184 didUnstuff0
|
|
|
1650 |
vusb-20120109/usbdrv/usbdrvasm165.inc:228 .text:00000134 unstuff1
|
|
|
1651 |
vusb-20120109/usbdrv/usbdrvasm165.inc:296 .text:00000194 didUnstuff1
|
|
|
1652 |
vusb-20120109/usbdrv/usbdrvasm165.inc:239 .text:00000142 unstuff2
|
|
|
1653 |
vusb-20120109/usbdrv/usbdrvasm165.inc:308 .text:000001aa didUnstuff2
|
|
|
1654 |
vusb-20120109/usbdrv/usbdrvasm165.inc:250 .text:00000150 unstuff3
|
|
|
1655 |
vusb-20120109/usbdrv/usbdrvasm165.inc:318 .text:000001bc didUnstuff3
|
|
|
1656 |
vusb-20120109/usbdrv/usbdrvasm165.inc:262 .text:00000160 unstuff4
|
|
|
1657 |
vusb-20120109/usbdrv/usbdrvasm165.inc:325 .text:000001c8 didUnstuff4
|
|
|
1658 |
vusb-20120109/usbdrv/asmcommon.inc:55 .text:000001dc se0
|
|
|
1659 |
vusb-20120109/usbdrv/asmcommon.inc:43 .text:000001d4 overflow
|
|
|
1660 |
vusb-20120109/usbdrv/asmcommon.inc:46 .text:000001d8 ignorePacket
|
|
|
1661 |
vusb-20120109/usbdrv/asmcommon.inc:94 .text:0000020e storeTokenAndReturn
|
|
|
1662 |
vusb-20120109/usbdrv/asmcommon.inc:105 .text:00000230 handleData
|
|
|
1663 |
vusb-20120109/usbdrv/asmcommon.inc:130 .text:0000025a handleIn
|
|
|
1664 |
vusb-20120109/usbdrv/asmcommon.inc:88 .text:0000020e handleSetupOrOut
|
|
|
1665 |
vusb-20120109/usbdrv/asmcommon.inc:96 .text:00000212 doReturn
|
|
|
1666 |
vusb-20120109/usbdrv/usbdrvasm165.inc:374 .text:0000029e sendNakAndReti
|
|
|
1667 |
vusb-20120109/usbdrv/usbdrvasm165.inc:377 .text:000002a2 sendAckAndReti
|
|
|
1668 |
vusb-20120109/usbdrv/asmcommon.inc:164 .text:0000027a handleIn1
|
|
|
1669 |
vusb-20120109/usbdrv/usbdrvasm165.inc:379 .text:000002a4 sendCntAndReti
|
|
|
1670 |
vusb-20120109/usbdrv/usbdrvasm165.inc:391 .text:000002ac usbSendAndReti
|
|
|
1671 |
vusb-20120109/usbdrv/usbdrvasm165.inc:359 .text:0000028c bitstuff7
|
|
|
1672 |
vusb-20120109/usbdrv/usbdrvasm165.inc:417 .text:000002d6 didStuff7
|
|
|
1673 |
vusb-20120109/usbdrv/usbdrvasm165.inc:365 .text:00000294 bitstuffN
|
|
|
1674 |
vusb-20120109/usbdrv/usbdrvasm165.inc:408 .text:000002c6 didStuffN
|
|
|
1675 |
vusb-20120109/usbdrv/usbdrvasm165.inc:401 .text:000002bc byteloop
|
|
|
1676 |
vusb-20120109/usbdrv/usbdrvasm165.inc:402 .text:000002bc bitloop
|
|
|
1677 |
vusb-20120109/usbdrv/usbdrvasm165.inc:436 .text:000002f8 skipAddrAssign
|
|
|
1678 |
vusb-20120109/usbdrv/usbdrvasm165.inc:446 .text:00000308 se0Delay
|
|
|
1679 |
|
|
|
1680 |
UNDEFINED SYMBOLS
|
|
|
1681 |
usbInputBufOffset
|
|
|
1682 |
usbRxBuf
|
|
|
1683 |
usbDeviceAddr
|
|
|
1684 |
usbCurrentTok
|
|
|
1685 |
usbRxLen
|
|
|
1686 |
usbRxToken
|
|
|
1687 |
usbTxLen
|
|
|
1688 |
usbTxBuf
|
|
|
1689 |
usbTxStatus1
|
|
|
1690 |
usbNewDeviceAddr
|