usbdrv/asmcommon.inc

Thu, 16 Feb 2017 14:40:23 +0100

author
Malte Di Donato <mdd@neo-soft.org>
date
Thu, 16 Feb 2017 14:40:23 +0100
changeset 0
9e9b2c78bd31
permissions
-rw-r--r--

added V-USB stack

0
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
1 /* Name: asmcommon.inc
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-11-05
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 /* Do not link this file! Link usbdrvasm.S instead, which includes the
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
11 * appropriate implementation!
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
12 */
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
13
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
14 /*
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
15 General Description:
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
16 This file contains assembler code which is shared among the USB driver
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
17 implementations for different CPU cocks. Since the code must be inserted
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
18 in the middle of the module, it's split out into this file and #included.
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
19
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
20 Jump destinations called from outside:
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
21 sofError: Called when no start sequence was found.
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
22 se0: Called when a package has been successfully received.
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
23 overflow: Called when receive buffer overflows.
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
24 doReturn: Called after sending data.
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
25
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
26 Outside jump destinations used by this module:
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
27 waitForJ: Called to receive an already arriving packet.
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
28 sendAckAndReti:
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
29 sendNakAndReti:
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
30 sendCntAndReti:
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
31 usbSendAndReti:
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 The following macros must be defined before this file is included:
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
34 .macro POP_STANDARD
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
35 .endm
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
36 .macro POP_RETI
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
37 .endm
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
38 */
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
39
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
40 #define token x1
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
41
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
42 overflow:
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
43 ldi x2, 1<<USB_INTR_PENDING_BIT
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
44 USB_STORE_PENDING(x2) ; clear any pending interrupts
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
45 ignorePacket:
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
46 clr token
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
47 rjmp storeTokenAndReturn
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
48
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
49 ;----------------------------------------------------------------------------
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
50 ; Processing of received packet (numbers in brackets are cycles after center of SE0)
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
51 ;----------------------------------------------------------------------------
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
52 ;This is the only non-error exit point for the software receiver loop
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
53 ;we don't check any CRCs here because there is no time left.
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
54 se0:
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
55 subi cnt, USB_BUFSIZE ;[5]
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
56 neg cnt ;[6]
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
57 sub YL, cnt ;[7]
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
58 sbci YH, 0 ;[8]
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
59 ldi x2, 1<<USB_INTR_PENDING_BIT ;[9]
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
60 USB_STORE_PENDING(x2) ;[10] clear pending intr and check flag later. SE0 should be over.
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
61 ld token, y ;[11]
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
62 cpi token, USBPID_DATA0 ;[13]
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
63 breq handleData ;[14]
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
64 cpi token, USBPID_DATA1 ;[15]
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
65 breq handleData ;[16]
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
66 lds shift, usbDeviceAddr;[17]
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
67 ldd x2, y+1 ;[19] ADDR and 1 bit endpoint number
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
68 lsl x2 ;[21] shift out 1 bit endpoint number
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
69 cpse x2, shift ;[22]
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
70 rjmp ignorePacket ;[23]
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
71 /* only compute endpoint number in x3 if required later */
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
72 #if USB_CFG_HAVE_INTRIN_ENDPOINT || USB_CFG_IMPLEMENT_FN_WRITEOUT
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
73 ldd x3, y+2 ;[24] endpoint number + crc
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
74 rol x3 ;[26] shift in LSB of endpoint
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
75 #endif
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
76 cpi token, USBPID_IN ;[27]
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
77 breq handleIn ;[28]
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
78 cpi token, USBPID_SETUP ;[29]
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
79 breq handleSetupOrOut ;[30]
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
80 cpi token, USBPID_OUT ;[31]
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
81 brne ignorePacket ;[32] must be ack, nak or whatever
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
82 ; rjmp handleSetupOrOut ; fallthrough
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
83
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
84 ;Setup and Out are followed by a data packet two bit times (16 cycles) after
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
85 ;the end of SE0. The sync code allows up to 40 cycles delay from the start of
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
86 ;the sync pattern until the first bit is sampled. That's a total of 56 cycles.
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
87 handleSetupOrOut: ;[32]
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
88 #if USB_CFG_IMPLEMENT_FN_WRITEOUT /* if we have data for endpoint != 0, set usbCurrentTok to address */
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
89 andi x3, 0xf ;[32]
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
90 breq storeTokenAndReturn ;[33]
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
91 mov token, x3 ;[34] indicate that this is endpoint x OUT
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
92 #endif
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
93 storeTokenAndReturn:
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
94 sts usbCurrentTok, token;[35]
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
95 doReturn:
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
96 POP_STANDARD ;[37] 12...16 cycles
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
97 USB_LOAD_PENDING(YL) ;[49]
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
98 sbrc YL, USB_INTR_PENDING_BIT;[50] check whether data is already arriving
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
99 rjmp waitForJ ;[51] save the pops and pushes -- a new interrupt is already pending
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
100 sofError:
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
101 POP_RETI ;macro call
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
102 reti
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 handleData:
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
105 #if USB_CFG_CHECK_CRC
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
106 CRC_CLEANUP_AND_CHECK ; jumps to ignorePacket if CRC error
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
107 #endif
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
108 lds shift, usbCurrentTok;[18]
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
109 tst shift ;[20]
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
110 breq doReturn ;[21]
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
111 lds x2, usbRxLen ;[22]
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
112 tst x2 ;[24]
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
113 brne sendNakAndReti ;[25]
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
114 ; 2006-03-11: The following two lines fix a problem where the device was not
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
115 ; recognized if usbPoll() was called less frequently than once every 4 ms.
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
116 cpi cnt, 4 ;[26] zero sized data packets are status phase only -- ignore and ack
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
117 brmi sendAckAndReti ;[27] keep rx buffer clean -- we must not NAK next SETUP
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
118 #if USB_CFG_CHECK_DATA_TOGGLING
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
119 sts usbCurrentDataToken, token ; store for checking by C code
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
120 #endif
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
121 sts usbRxLen, cnt ;[28] store received data, swap buffers
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
122 sts usbRxToken, shift ;[30]
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
123 lds x2, usbInputBufOffset;[32] swap buffers
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
124 ldi cnt, USB_BUFSIZE ;[34]
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
125 sub cnt, x2 ;[35]
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
126 sts usbInputBufOffset, cnt;[36] buffers now swapped
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
127 rjmp sendAckAndReti ;[38] 40 + 17 = 57 until SOP
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
128
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
129 handleIn:
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
130 ;We don't send any data as long as the C code has not processed the current
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
131 ;input data and potentially updated the output data. That's more efficient
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
132 ;in terms of code size than clearing the tx buffers when a packet is received.
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
133 lds x1, usbRxLen ;[30]
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
134 cpi x1, 1 ;[32] negative values are flow control, 0 means "buffer free"
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
135 brge sendNakAndReti ;[33] unprocessed input packet?
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
136 ldi x1, USBPID_NAK ;[34] prepare value for usbTxLen
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
137 #if USB_CFG_HAVE_INTRIN_ENDPOINT
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
138 andi x3, 0xf ;[35] x3 contains endpoint
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
139 #if USB_CFG_SUPPRESS_INTR_CODE
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
140 brne sendNakAndReti ;[36]
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
141 #else
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
142 brne handleIn1 ;[36]
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 #endif
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
145 lds cnt, usbTxLen ;[37]
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
146 sbrc cnt, 4 ;[39] all handshake tokens have bit 4 set
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
147 rjmp sendCntAndReti ;[40] 42 + 16 = 58 until SOP
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
148 sts usbTxLen, x1 ;[41] x1 == USBPID_NAK from above
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
149 ldi YL, lo8(usbTxBuf) ;[43]
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
150 ldi YH, hi8(usbTxBuf) ;[44]
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
151 rjmp usbSendAndReti ;[45] 57 + 12 = 59 until SOP
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
152
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
153 ; Comment about when to set usbTxLen to USBPID_NAK:
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
154 ; We should set it back when we receive the ACK from the host. This would
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
155 ; be simple to implement: One static variable which stores whether the last
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
156 ; tx was for endpoint 0 or 1 and a compare in the receiver to distinguish the
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
157 ; ACK. However, we set it back immediately when we send the package,
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
158 ; assuming that no error occurs and the host sends an ACK. We save one byte
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
159 ; RAM this way and avoid potential problems with endless retries. The rest of
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
160 ; the driver assumes error-free transfers anyway.
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 #if !USB_CFG_SUPPRESS_INTR_CODE && USB_CFG_HAVE_INTRIN_ENDPOINT /* placed here due to relative jump range */
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
163 handleIn1: ;[38]
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
164 #if USB_CFG_HAVE_INTRIN_ENDPOINT3
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
165 ; 2006-06-10 as suggested by O.Tamura: support second INTR IN / BULK IN endpoint
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
166 cpi x3, USB_CFG_EP3_NUMBER;[38]
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
167 breq handleIn3 ;[39]
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
168 #endif
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
169 lds cnt, usbTxLen1 ;[40]
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
170 sbrc cnt, 4 ;[42] all handshake tokens have bit 4 set
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
171 rjmp sendCntAndReti ;[43] 47 + 16 = 63 until SOP
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
172 sts usbTxLen1, x1 ;[44] x1 == USBPID_NAK from above
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
173 ldi YL, lo8(usbTxBuf1) ;[46]
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
174 ldi YH, hi8(usbTxBuf1) ;[47]
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
175 rjmp usbSendAndReti ;[48] 50 + 12 = 62 until SOP
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
176
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
177 #if USB_CFG_HAVE_INTRIN_ENDPOINT3
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
178 handleIn3:
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
179 lds cnt, usbTxLen3 ;[41]
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
180 sbrc cnt, 4 ;[43]
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
181 rjmp sendCntAndReti ;[44] 49 + 16 = 65 until SOP
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
182 sts usbTxLen3, x1 ;[45] x1 == USBPID_NAK from above
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
183 ldi YL, lo8(usbTxBuf3) ;[47]
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
184 ldi YH, hi8(usbTxBuf3) ;[48]
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
185 rjmp usbSendAndReti ;[49] 51 + 12 = 63 until SOP
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
186 #endif
9e9b2c78bd31 added V-USB stack
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
187 #endif

mercurial