2 * Project: AVR USB driver
3 * Author: Christian Starkjohann
4 * Creation Date: 2007-06-13
6 * Copyright: (c) 2007 by OBJECTIVE DEVELOPMENT Software GmbH
7 * License: GNU GPL v2 (see License.txt) or proprietary (CommercialLicense.txt)
13 This module is the assembler part of the USB driver. This file contains
14 general code (preprocessor acrobatics and CRC computation) and then includes
15 the file appropriate for the given clock rate.
18 #include "iarcompat.h"
19 #ifndef __IAR_SYSTEMS_ASM__
20 /* configs for io.h */
21 # define __SFR_OFFSET 0
22 # define _VECTOR(N) __vector_ ## N /* io.h does not define this for asm */
23 # include <avr/io.h> /* for CPU I/O register definitions and vectors */
24 #endif /* __IAR_SYSTEMS_ASM__ */
25 #include "usbdrv.h" /* for common defs */
39 /* Some assembler dependent definitions and declarations: */
41 #ifdef __IAR_SYSTEMS_ASM__
43 # define nop2 rjmp $+2 /* jump to next instruction */
50 # define lo8(x) LOW(x)
51 # define hi8(x) ((x)>>8) /* not HIGH to allow XLINK to make a proper range check */
53 extern usbRxBuf, usbDeviceAddr, usbNewDeviceAddr, usbInputBufOffset
54 extern usbCurrentTok, usbRxLen, usbRxToken, usbTxLen
55 extern usbTxBuf, usbMsgLen, usbTxLen1, usbTxBuf1, usbTxLen3, usbTxBuf3
64 #else /* __IAR_SYSTEMS_ASM__ */
66 # define nop2 rjmp .+0 /* jump to next instruction */
69 .global SIG_INTERRUPT0
70 .type SIG_INTERRUPT0, @function
72 .global usbCrc16Append
74 #endif /* __IAR_SYSTEMS_ASM__ */
76 ;----------------------------------------------------------------------------
78 ;----------------------------------------------------------------------------
80 #ifdef __IAR_SYSTEMS_ASM__
81 /* Register assignments for usbCrc16 on IAR cc */
82 /* Calling conventions on IAR:
83 * First parameter passed in r16/r17, second in r18/r19 and so on.
84 * Callee must preserve r4-r15, r24-r29 (r28/r29 is frame pointer)
85 * Result is passed in r16/r17
86 * In case of the "tiny" memory model, pointers are only 8 bit with no
87 * padding. We therefore pass argument 1 as "16 bit unsigned".
89 RTMODEL "__rt_version", "3"
90 /* The line above will generate an error if cc calling conventions change.
91 * The value "3" above is valid for IAR 4.10B/W32
93 # define argLen r18 /* argument 2 */
94 # define argPtrL r16 /* argument 1 */
95 # define argPtrH r17 /* argument 1 */
97 # define resCrcL r16 /* result */
98 # define resCrcH r17 /* result */
109 #else /* __IAR_SYSTEMS_ASM__ */
110 /* Register assignments for usbCrc16 on gcc */
111 /* Calling conventions on gcc:
112 * First parameter passed in r24/r25, second in r22/23 and so on.
113 * Callee must preserve r1-r17, r28/r29
114 * Result is passed in r24/r25
116 # define argLen r22 /* argument 2 */
117 # define argPtrL r24 /* argument 1 */
118 # define argPtrH r25 /* argument 1 */
120 # define resCrcL r24 /* result */
121 # define resCrcH r25 /* result */
134 ; extern unsigned usbCrc16(unsigned char *data, unsigned char len);
149 ldi polyL, lo8(0xa001)
150 ldi polyH, hi8(0xa001)
175 ; extern unsigned usbCrc16Append(unsigned char *data, unsigned char len);
183 ;----------------------------------------------------------------------------
184 ; Now include the clock rate specific code
185 ;----------------------------------------------------------------------------
187 #ifndef USB_CFG_CLOCK_KHZ
188 # define USB_CFG_CLOCK_KHZ 12000
191 #if USB_CFG_CLOCK_KHZ == 12000
192 # include "usbdrvasm12.S"
193 #elif USB_CFG_CLOCK_KHZ == 16000
194 # include "usbdrvasm16.S"
195 #elif USB_CFG_CLOCK_KHZ == 16500
196 # include "usbdrvasm165.S"
198 # error "USB_CFG_CLOCK_KHZ is not one of the supported rates!"