usbdrv/usbdrvasm.S

Fri, 17 Feb 2017 13:26:39 +0100

author
mbayer
date
Fri, 17 Feb 2017 13:26:39 +0100
changeset 6
b84252fe69c6
parent 0
9e9b2c78bd31
permissions
-rw-r--r--

changes to run client on windows platform too via libusb dev

0
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
1 /* Name: usbdrvasm.S
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
2 * Project: V-USB, virtual USB port for Atmel's(r) AVR(r) microcontrollers
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
3 * Author: Christian Starkjohann
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
4 * Creation Date: 2007-06-13
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
5 * Tabsize: 4
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
6 * Copyright: (c) 2007 by OBJECTIVE DEVELOPMENT Software GmbH
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
7 * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
8 */
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
9
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
10 /*
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
11 General Description:
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
12 This module is the assembler part of the USB driver. This file contains
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
13 general code (preprocessor acrobatics and CRC computation) and then includes
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
14 the file appropriate for the given clock rate.
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
15 */
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
16
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
17 #define __SFR_OFFSET 0 /* used by avr-libc's register definitions */
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
18 #include "usbportability.h"
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
19 #include "usbdrv.h" /* for common defs */
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
20
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
21 /* register names */
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
22 #define x1 r16
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
23 #define x2 r17
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
24 #define shift r18
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
25 #define cnt r19
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
26 #define x3 r20
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
27 #define x4 r21
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
28 #define x5 r22
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
29 #define bitcnt x5
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
30 #define phase x4
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
31 #define leap x4
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
32
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
33 /* Some assembler dependent definitions and declarations: */
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
34
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
35 #ifdef __IAR_SYSTEMS_ASM__
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
36 extern usbRxBuf, usbDeviceAddr, usbNewDeviceAddr, usbInputBufOffset
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
37 extern usbCurrentTok, usbRxLen, usbRxToken, usbTxLen
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
38 extern usbTxBuf, usbTxStatus1, usbTxStatus3
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
39 # if USB_COUNT_SOF
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
40 extern usbSofCount
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
41 # endif
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
42 public usbCrc16
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
43 public usbCrc16Append
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
44
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
45 COMMON INTVEC
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
46 # ifndef USB_INTR_VECTOR
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
47 ORG INT0_vect
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
48 # else /* USB_INTR_VECTOR */
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
49 ORG USB_INTR_VECTOR
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
50 # undef USB_INTR_VECTOR
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
51 # endif /* USB_INTR_VECTOR */
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
52 # define USB_INTR_VECTOR usbInterruptHandler
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
53 rjmp USB_INTR_VECTOR
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
54 RSEG CODE
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
55
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
56 #else /* __IAR_SYSTEMS_ASM__ */
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
57
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
58 # ifndef USB_INTR_VECTOR /* default to hardware interrupt INT0 */
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
59 # ifdef INT0_vect
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
60 # define USB_INTR_VECTOR INT0_vect // this is the "new" define for the vector
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
61 # else
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
62 # define USB_INTR_VECTOR SIG_INTERRUPT0 // this is the "old" vector
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
63 # endif
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
64 # endif
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
65 .text
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
66 .global USB_INTR_VECTOR
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
67 .type USB_INTR_VECTOR, @function
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
68 .global usbCrc16
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
69 .global usbCrc16Append
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
70 #endif /* __IAR_SYSTEMS_ASM__ */
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
71
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
72
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
73 #if USB_INTR_PENDING < 0x40 /* This is an I/O address, use in and out */
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
74 # define USB_LOAD_PENDING(reg) in reg, USB_INTR_PENDING
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
75 # define USB_STORE_PENDING(reg) out USB_INTR_PENDING, reg
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
76 #else /* It's a memory address, use lds and sts */
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
77 # define USB_LOAD_PENDING(reg) lds reg, USB_INTR_PENDING
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
78 # define USB_STORE_PENDING(reg) sts USB_INTR_PENDING, reg
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
79 #endif
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
80
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
81 #define usbTxLen1 usbTxStatus1
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
82 #define usbTxBuf1 (usbTxStatus1 + 1)
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
83 #define usbTxLen3 usbTxStatus3
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
84 #define usbTxBuf3 (usbTxStatus3 + 1)
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
85
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
86
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
87 ;----------------------------------------------------------------------------
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
88 ; Utility functions
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
89 ;----------------------------------------------------------------------------
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
90
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
91 #ifdef __IAR_SYSTEMS_ASM__
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
92 /* Register assignments for usbCrc16 on IAR cc */
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
93 /* Calling conventions on IAR:
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
94 * First parameter passed in r16/r17, second in r18/r19 and so on.
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
95 * Callee must preserve r4-r15, r24-r29 (r28/r29 is frame pointer)
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
96 * Result is passed in r16/r17
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
97 * In case of the "tiny" memory model, pointers are only 8 bit with no
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
98 * padding. We therefore pass argument 1 as "16 bit unsigned".
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
99 */
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
100 RTMODEL "__rt_version", "3"
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
101 /* The line above will generate an error if cc calling conventions change.
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
102 * The value "3" above is valid for IAR 4.10B/W32
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
103 */
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
104 # define argLen r18 /* argument 2 */
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
105 # define argPtrL r16 /* argument 1 */
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
106 # define argPtrH r17 /* argument 1 */
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
107
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
108 # define resCrcL r16 /* result */
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
109 # define resCrcH r17 /* result */
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
110
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
111 # define ptrL ZL
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
112 # define ptrH ZH
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
113 # define ptr Z
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
114 # define byte r22
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
115 # define bitCnt r19
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
116 # define polyL r20
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
117 # define polyH r21
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
118 # define scratch r23
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
119
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
120 #else /* __IAR_SYSTEMS_ASM__ */
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
121 /* Register assignments for usbCrc16 on gcc */
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
122 /* Calling conventions on gcc:
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
123 * First parameter passed in r24/r25, second in r22/23 and so on.
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
124 * Callee must preserve r1-r17, r28/r29
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
125 * Result is passed in r24/r25
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
126 */
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
127 # define argLen r22 /* argument 2 */
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
128 # define argPtrL r24 /* argument 1 */
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
129 # define argPtrH r25 /* argument 1 */
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
130
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
131 # define resCrcL r24 /* result */
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
132 # define resCrcH r25 /* result */
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
133
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
134 # define ptrL XL
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
135 # define ptrH XH
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
136 # define ptr x
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
137 # define byte r18
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
138 # define bitCnt r19
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
139 # define polyL r20
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
140 # define polyH r21
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
141 # define scratch r23
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
142
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
143 #endif
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
144
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
145 #if USB_USE_FAST_CRC
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
146
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
147 ; This implementation is faster, but has bigger code size
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
148 ; Thanks to Slawomir Fras (BoskiDialer) for this code!
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
149 ; It implements the following C pseudo-code:
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
150 ; unsigned table(unsigned char x)
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
151 ; {
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
152 ; unsigned value;
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
153 ;
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
154 ; value = (unsigned)x << 6;
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
155 ; value ^= (unsigned)x << 7;
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
156 ; if(parity(x))
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
157 ; value ^= 0xc001;
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
158 ; return value;
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
159 ; }
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
160 ; unsigned usbCrc16(unsigned char *argPtr, unsigned char argLen)
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
161 ; {
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
162 ; unsigned crc = 0xffff;
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
163 ;
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
164 ; while(argLen--)
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
165 ; crc = table(lo8(crc) ^ *argPtr++) ^ hi8(crc);
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
166 ; return ~crc;
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
167 ; }
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
168
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
169 ; extern unsigned usbCrc16(unsigned char *argPtr, unsigned char argLen);
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
170 ; argPtr r24+25 / r16+r17
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
171 ; argLen r22 / r18
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
172 ; temp variables:
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
173 ; byte r18 / r22
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
174 ; scratch r23
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
175 ; resCrc r24+r25 / r16+r17
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
176 ; ptr X / Z
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
177 usbCrc16:
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
178 mov ptrL, argPtrL
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
179 mov ptrH, argPtrH
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
180 ldi resCrcL, 0xFF
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
181 ldi resCrcH, 0xFF
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
182 rjmp usbCrc16LoopTest
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
183 usbCrc16ByteLoop:
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
184 ld byte, ptr+
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
185 eor resCrcL, byte ; resCrcL is now 'x' in table()
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
186 mov byte, resCrcL ; compute parity of 'x'
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
187 swap byte
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
188 eor byte, resCrcL
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
189 mov scratch, byte
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
190 lsr byte
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
191 lsr byte
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
192 eor byte, scratch
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
193 inc byte
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
194 lsr byte
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
195 andi byte, 1 ; byte is now parity(x)
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
196 mov scratch, resCrcL
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
197 mov resCrcL, resCrcH
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
198 eor resCrcL, byte ; low byte of if(parity(x)) value ^= 0xc001;
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
199 neg byte
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
200 andi byte, 0xc0
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
201 mov resCrcH, byte ; high byte of if(parity(x)) value ^= 0xc001;
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
202 clr byte
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
203 lsr scratch
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
204 ror byte
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
205 eor resCrcH, scratch
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
206 eor resCrcL, byte
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
207 lsr scratch
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
208 ror byte
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
209 eor resCrcH, scratch
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
210 eor resCrcL, byte
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
211 usbCrc16LoopTest:
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
212 subi argLen, 1
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
213 brsh usbCrc16ByteLoop
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
214 com resCrcL
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
215 com resCrcH
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
216 ret
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
217
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
218 #else /* USB_USE_FAST_CRC */
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
219
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
220 ; This implementation is slower, but has less code size
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
221 ;
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
222 ; extern unsigned usbCrc16(unsigned char *argPtr, unsigned char argLen);
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
223 ; argPtr r24+25 / r16+r17
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
224 ; argLen r22 / r18
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
225 ; temp variables:
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
226 ; byte r18 / r22
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
227 ; bitCnt r19
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
228 ; poly r20+r21
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
229 ; scratch r23
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
230 ; resCrc r24+r25 / r16+r17
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
231 ; ptr X / Z
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
232 usbCrc16:
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
233 mov ptrL, argPtrL
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
234 mov ptrH, argPtrH
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
235 ldi resCrcL, 0
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
236 ldi resCrcH, 0
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
237 ldi polyL, lo8(0xa001)
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
238 ldi polyH, hi8(0xa001)
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
239 com argLen ; argLen = -argLen - 1: modified loop to ensure that carry is set
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
240 ldi bitCnt, 0 ; loop counter with starnd condition = end condition
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
241 rjmp usbCrcLoopEntry
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
242 usbCrcByteLoop:
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
243 ld byte, ptr+
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
244 eor resCrcL, byte
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
245 usbCrcBitLoop:
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
246 ror resCrcH ; carry is always set here (see brcs jumps to here)
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
247 ror resCrcL
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
248 brcs usbCrcNoXor
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
249 eor resCrcL, polyL
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
250 eor resCrcH, polyH
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
251 usbCrcNoXor:
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
252 subi bitCnt, 224 ; (8 * 224) % 256 = 0; this loop iterates 8 times
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
253 brcs usbCrcBitLoop
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
254 usbCrcLoopEntry:
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
255 subi argLen, -1
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
256 brcs usbCrcByteLoop
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
257 usbCrcReady:
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
258 ret
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
259 ; Thanks to Reimar Doeffinger for optimizing this CRC routine!
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
260
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
261 #endif /* USB_USE_FAST_CRC */
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
262
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
263 ; extern unsigned usbCrc16Append(unsigned char *data, unsigned char len);
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
264 usbCrc16Append:
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
265 rcall usbCrc16
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
266 st ptr+, resCrcL
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
267 st ptr+, resCrcH
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
268 ret
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
269
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
270 #undef argLen
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
271 #undef argPtrL
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
272 #undef argPtrH
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
273 #undef resCrcL
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
274 #undef resCrcH
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
275 #undef ptrL
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
276 #undef ptrH
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
277 #undef ptr
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
278 #undef byte
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
279 #undef bitCnt
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
280 #undef polyL
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
281 #undef polyH
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
282 #undef scratch
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
283
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
284
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
285 #if USB_CFG_HAVE_MEASURE_FRAME_LENGTH
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
286 #ifdef __IAR_SYSTEMS_ASM__
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
287 /* Register assignments for usbMeasureFrameLength on IAR cc */
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
288 /* Calling conventions on IAR:
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
289 * First parameter passed in r16/r17, second in r18/r19 and so on.
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
290 * Callee must preserve r4-r15, r24-r29 (r28/r29 is frame pointer)
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
291 * Result is passed in r16/r17
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
292 * In case of the "tiny" memory model, pointers are only 8 bit with no
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
293 * padding. We therefore pass argument 1 as "16 bit unsigned".
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
294 */
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
295 # define resL r16
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
296 # define resH r17
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
297 # define cnt16L r30
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
298 # define cnt16H r31
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
299 # define cntH r18
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
300
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
301 #else /* __IAR_SYSTEMS_ASM__ */
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
302 /* Register assignments for usbMeasureFrameLength on gcc */
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
303 /* Calling conventions on gcc:
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
304 * First parameter passed in r24/r25, second in r22/23 and so on.
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
305 * Callee must preserve r1-r17, r28/r29
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
306 * Result is passed in r24/r25
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
307 */
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
308 # define resL r24
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
309 # define resH r25
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
310 # define cnt16L r24
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
311 # define cnt16H r25
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
312 # define cntH r26
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
313 #endif
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
314 # define cnt16 cnt16L
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
315
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
316 ; extern unsigned usbMeasurePacketLength(void);
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
317 ; returns time between two idle strobes in multiples of 7 CPU clocks
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
318 .global usbMeasureFrameLength
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
319 usbMeasureFrameLength:
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
320 ldi cntH, 6 ; wait ~ 10 ms for D- == 0
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
321 clr cnt16L
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
322 clr cnt16H
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
323 usbMFTime16:
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
324 dec cntH
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
325 breq usbMFTimeout
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
326 usbMFWaitStrobe: ; first wait for D- == 0 (idle strobe)
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
327 sbiw cnt16, 1 ;[0] [6]
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
328 breq usbMFTime16 ;[2]
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
329 sbic USBIN, USBMINUS ;[3]
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
330 rjmp usbMFWaitStrobe ;[4]
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
331 usbMFWaitIdle: ; then wait until idle again
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
332 sbis USBIN, USBMINUS ;1 wait for D- == 1
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
333 rjmp usbMFWaitIdle ;2
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
334 ldi cnt16L, 1 ;1 represents cycles so far
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
335 clr cnt16H ;1
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
336 usbMFWaitLoop:
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
337 in cntH, USBIN ;[0] [7]
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
338 adiw cnt16, 1 ;[1]
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
339 breq usbMFTimeout ;[3]
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
340 andi cntH, USBMASK ;[4]
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
341 brne usbMFWaitLoop ;[5]
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
342 usbMFTimeout:
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
343 #if resL != cnt16L
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
344 mov resL, cnt16L
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
345 mov resH, cnt16H
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
346 #endif
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
347 ret
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
348
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
349 #undef resL
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
350 #undef resH
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
351 #undef cnt16
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
352 #undef cnt16L
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
353 #undef cnt16H
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
354 #undef cntH
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
355
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
356 #endif /* USB_CFG_HAVE_MEASURE_FRAME_LENGTH */
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
357
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
358 ;----------------------------------------------------------------------------
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
359 ; Now include the clock rate specific code
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
360 ;----------------------------------------------------------------------------
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
361
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
362 #ifndef USB_CFG_CLOCK_KHZ
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
363 # ifdef F_CPU
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
364 # define USB_CFG_CLOCK_KHZ (F_CPU/1000)
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
365 # else
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
366 # error "USB_CFG_CLOCK_KHZ not defined in usbconfig.h and no F_CPU set!"
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
367 # endif
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
368 #endif
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
369
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
370 #if USB_CFG_CHECK_CRC /* separate dispatcher for CRC type modules */
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
371 # if USB_CFG_CLOCK_KHZ == 18000
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
372 # include "usbdrvasm18-crc.inc"
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
373 # else
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
374 # error "USB_CFG_CLOCK_KHZ is not one of the supported crc-rates!"
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
375 # endif
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
376 #else /* USB_CFG_CHECK_CRC */
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
377 # if USB_CFG_CLOCK_KHZ == 12000
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
378 # include "usbdrvasm12.inc"
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
379 # elif USB_CFG_CLOCK_KHZ == 12800
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
380 # include "usbdrvasm128.inc"
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
381 # elif USB_CFG_CLOCK_KHZ == 15000
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
382 # include "usbdrvasm15.inc"
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
383 # elif USB_CFG_CLOCK_KHZ == 16000
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
384 # include "usbdrvasm16.inc"
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
385 # elif USB_CFG_CLOCK_KHZ == 16500
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
386 # include "usbdrvasm165.inc"
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
387 # elif USB_CFG_CLOCK_KHZ == 20000
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
388 # include "usbdrvasm20.inc"
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
389 # else
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
390 # error "USB_CFG_CLOCK_KHZ is not one of the supported non-crc-rates!"
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
391 # endif
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
392 #endif /* USB_CFG_CHECK_CRC */

mercurial