123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393 |
- USB_INTR_VECTOR:
- push YL
- in YL, SREG
- push YL
- waitForJ:
- inc YL
- sbis USBIN, USBMINUS
- brne waitForJ
- waitForK:
- sbis USBIN, USBMINUS
- rjmp foundK
- sbis USBIN, USBMINUS
- rjmp foundK
- sbis USBIN, USBMINUS
- rjmp foundK
- sbis USBIN, USBMINUS
- rjmp foundK
- sbis USBIN, USBMINUS
- rjmp foundK
- lds YL, usbSofCount
- inc YL
- sts usbSofCount, YL
- USB_SOF_HOOK
- rjmp sofError
- foundK:
- push YH
- lds YL, usbInputBufOffset
- clr YH
- subi YL, lo8(-(usbRxBuf))
- sbci YH, hi8(-(usbRxBuf))
- sbis USBIN, USBMINUS
- rjmp haveTwoBitsK
- pop YH
- rjmp waitForK
- haveTwoBitsK:
- push shift
- push x1
- push x2
- in x1, USBIN
- ldi shift, 0xff
- bst x1, USBMINUS
- bld shift, 0
- push x3
- push cnt
-
- in x2, USBIN
- ser x3
- eor x1, x2
- bst x1, USBMINUS
- bld shift, 1
- ldi cnt, USB_BUFSIZE
- rjmp rxbit2
- unstuff0:
- andi x3, ~0x01
- mov x1, x2
- in x2, USBIN
- ori shift, 0x01
- rjmp didUnstuff0
- unstuff1:
- mov x2, x1
- andi x3, ~0x02
- ori shift, 0x02
- nop
- in x1, USBIN
- rjmp didUnstuff1
- unstuff2:
- andi x3, ~0x04
- ori shift, 0x04
- mov x1, x2
- nop
- in x2, USBIN
- rjmp didUnstuff2
- unstuff3:
- in x2, USBIN
- andi x3, ~0x08
- ori shift, 0x08
- rjmp didUnstuff3
- unstuff4:
- andi x3, ~0x10
- in x1, USBIN
- ori shift, 0x10
- rjmp didUnstuff4
- unstuff5:
- andi x3, ~0x20
- in x2, USBIN
- ori shift, 0x20
- rjmp didUnstuff5
- unstuff6:
- andi x3, ~0x40
- in x1, USBIN
- ori shift, 0x40
- rjmp didUnstuff6
- rxLoop:
- eor x3, shift
- in x1, USBIN
- st y+, x3
- ser x3
- nop
- eor x2, x1
- bst x2, USBMINUS
- bld shift, 0
- in x2, USBIN
- andi x2, USBMASK
- breq se0
- andi shift, 0xf9
- didUnstuff0:
- breq unstuff0
- eor x1, x2
- bst x1, USBMINUS
- bld shift, 1
- rxbit2:
- in x1, USBIN
- andi shift, 0xf3
- breq unstuff1
- didUnstuff1:
- subi cnt, 1
- brcs overflow
- eor x2, x1
- bst x2, USBMINUS
- bld shift, 2
- in x2, USBIN
- andi shift, 0xe7
- breq unstuff2
- didUnstuff2:
- eor x1, x2
- bst x1, USBMINUS
- bld shift, 3
- didUnstuff3:
- andi shift, 0xcf
- breq unstuff3
- in x1, USBIN
- eor x2, x1
- bst x2, USBMINUS
- bld shift, 4
- didUnstuff4:
- andi shift, 0x9f
- breq unstuff4
- nop2
- in x2, USBIN
- eor x1, x2
- bst x1, USBMINUS
- bld shift, 5
- didUnstuff5:
- andi shift, 0x3f
- breq unstuff5
- nop2
- in x1, USBIN
- eor x2, x1
- bst x2, USBMINUS
- bld shift, 6
- didUnstuff6:
- cpi shift, 0x02
- brlo unstuff6
- nop2
- in x2, USBIN
- eor x1, x2
- bst x1, USBMINUS
- bld shift, 7
- didUnstuff7:
- cpi shift, 0x04
- brsh rxLoop
- unstuff7:
- andi x3, ~0x80
- ori shift, 0x80
- in x2, USBIN
- nop
- rjmp didUnstuff7
- macro POP_STANDARD
- pop cnt
- pop x3
- pop x2
- pop x1
- pop shift
- pop YH
- endm
- macro POP_RETI
- pop YL
- out SREG, YL
- pop YL
- endm
- txByteLoop:
- txBitloop:
- stuffN1Delay:
- ror shift
- brcc doExorN1
- subi x4, 1
- brne commonN1
- lsl shift
- nop
- rjmp stuffN1Delay
- sendNakAndReti:
- ldi x3, USBPID_NAK
- rjmp usbSendX3
- sendAckAndReti:
- ldi x3, USBPID_ACK
- rjmp usbSendX3
- sendCntAndReti:
- mov x3, cnt
- usbSendX3:
- ldi YL, 20
- ldi YH, 0
- ldi cnt, 2
- usbSendAndReti:
- in x2, USBDDR
- ori x2, USBMASK
- sbi USBOUT, USBMINUS
- out USBDDR, x2
- in x1, USBOUT
- ldi shift, 0x40
- ldi x2, USBMASK
- push x4
- doExorN1:
- eor x1, x2
- ldi x4, 6
- commonN1:
- stuffN2Delay:
- out USBOUT, x1
- ror shift
- brcc doExorN2
- subi x4, 1
- brne commonN2
- lsl shift
- rjmp stuffN2Delay
- doExorN2:
- eor x1, x2
- ldi x4, 6
- commonN2:
- nop
- subi cnt, 171
- out USBOUT, x1
- brcs txBitloop
- stuff6Delay:
- ror shift
- brcc doExor6
- subi x4, 1
- brne common6
- lsl shift
- nop
- rjmp stuff6Delay
- doExor6:
- eor x1, x2
- ldi x4, 6
- common6:
- stuff7Delay:
- ror shift
- out USBOUT, x1
- brcc doExor7
- subi x4, 1
- brne common7
- lsl shift
- rjmp stuff7Delay
- doExor7:
- eor x1, x2
- ldi x4, 6
- common7:
- ld shift, y+
- tst cnt
- out USBOUT, x1
- brne txByteLoop
- cbr x1, USBMASK
- lds x2, usbNewDeviceAddr
- lsl x2
- subi YL, 2 + 20
- sbci YH, 0
- out USBOUT, x1
- breq skipAddrAssign
- sts usbDeviceAddr, x2
- skipAddrAssign:
- ldi x2, 1<<USB_INTR_PENDING_BIT
- USB_STORE_PENDING(x2)
- ori x1, USBIDLE
- in x2, USBDDR
- cbr x2, USBMASK
- mov x3, x1
- cbr x3, USBMASK
- pop x4
- nop2
- nop2
- out USBOUT, x1
- out USBDDR, x2
- out USBOUT, x3
- rjmp doReturn
|