123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453 |
- 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
- sbis USBIN, USBMINUS
- rjmp foundK
- lds YL, usbSofCount
- inc YL
- sts usbSofCount, YL
- USB_SOF_HOOK
- rjmp sofError
- foundK:
- push r0
- push YH
- lds YL, usbInputBufOffset
- clr YH
- subi YL, lo8(-(usbRxBuf))
- sbci YH, hi8(-(usbRxBuf))
- mov r0, x2
- sbis USBIN, USBMINUS
- rjmp haveTwoBitsK
- pop YH
- pop r0
- rjmp waitForK
- haveTwoBitsK:
- push shift
- push x1
- push x2
- push x3
- ldi shift, 0xff
- ori x3, 0xff
- in x1, USBIN
- bst x1, USBMINUS
- bld shift, 0
- push x4
- push cnt
- ldi phase, 0
- ldi cnt, USB_BUFSIZE
- rjmp rxbit1
- continueWithBit5:
- in x2, USBIN
- eor r0, x2
- or phase, r0
- sbrc phase, USBMINUS
- lpm
- in phase, USBIN
- eor x1, x2
- bst x1, USBMINUS
- bld shift, 5
- andi shift, 0x3f
- in x1, USBIN
- breq unstuff5
- eor phase, x1
- eor x2, x1
- bst x2, USBMINUS
- bld shift, 6
- didUnstuff6:
- in r0, USBIN
- cpi shift, 0x02
- brlo unstuff6
- didUnstuff5:
- nop2
- in x2, USBIN
- eor x1, x2
- bst x1, USBMINUS
- bld shift, 7
- didUnstuff7:
- eor r0, x2
- or phase, r0
- in r0, USBIN
- cpi shift, 0x04
- brsh rxLoop
- unstuff7:
- andi x3, ~0x80
- ori shift, 0x80
- in x2, USBIN
- nop
- rjmp didUnstuff7
-
- unstuff5:
- eor phase, x1
- andi x3, ~0x20
- ori shift, 0x20
- in r0, USBIN
- mov x2, x1
- nop
- nop2
- in x1, USBIN
- eor r0, x1
- or phase, r0
- eor x2, x1
- bst x2, USBMINUS
- bld shift, 6
- in r0, USBIN
- rjmp didUnstuff5
-
- unstuff6:
- andi x3, ~0x40
- in x1, USBIN
- ori shift, 0x40
- nop2
- rjmp didUnstuff6
-
- unstuff0:
- eor r0, x2
- or phase, r0
- andi x2, USBMASK
- in r0, USBIN
- breq didUnstuff0
- andi x3, ~0x01
- ori shift, 0x01
- mov x1, x2
- in x2, USBIN
- rjmp didUnstuff0
-
- unstuff1:
- eor r0, x1
- or phase, r0
- andi x3, ~0x02
- in r0, USBIN
- ori shift, 0x02
- mov x2, x1
- rjmp didUnstuff1
-
- unstuff2:
- eor r0, x2
- or phase, r0
- andi x3, ~0x04
- in r0, USBIN
- ori shift, 0x04
- mov x1, x2
- rjmp didUnstuff2
-
- unstuff3:
- in x2, USBIN
- eor r0, x2
- or phase, r0
- andi x3, ~0x08
- ori shift, 0x08
- nop
- in r0, USBIN
- rjmp didUnstuff3
-
- unstuff4:
- andi x3, ~0x10
- in x1, USBIN
- ori shift, 0x10
- rjmp didUnstuff4
-
- rxLoop:
- eor x3, shift
- in x1, USBIN
- st y+, x3
- eor r0, x1
- or phase, r0
- eor x2, x1
- in r0, USBIN
- ser x3
- bst x2, USBMINUS
- bld shift, 0
- andi shift, 0xf9
- rxbit1:
- in x2, USBIN
- breq unstuff0
- andi x2, USBMASK
- didUnstuff0:
- breq se0
- eor r0, x2
- or phase, r0
- in r0, USBIN
- eor x1, x2
- bst x1, USBMINUS
- bld shift, 1
- andi shift, 0xf3
- didUnstuff1:
- in x1, USBIN
- breq unstuff1
- eor r0, x1
- or phase, r0
- subi cnt, 1
- brcs overflow
- in r0, USBIN
- eor x2, x1
- bst x2, USBMINUS
- bld shift, 2
- andi shift, 0xe7
- didUnstuff2:
- in x2, USBIN
- breq unstuff2
- eor r0, x2
- or phase, r0
- eor x1, x2
- bst x1, USBMINUS
- in r0, USBIN
- bld shift, 3
- andi shift, 0xcf
- didUnstuff3:
- breq unstuff3
- nop
- in x1, USBIN
- eor x2, x1
- bst x2, USBMINUS
- bld shift, 4
- didUnstuff4:
- eor r0, x1
- or phase, r0
- in r0, USBIN
- andi shift, 0x9f
- breq unstuff4
- rjmp continueWithBit5
- macro POP_STANDARD
- pop cnt
- pop x4
- pop x3
- pop x2
- pop x1
- pop shift
- pop YH
- pop r0
- endm
- macro POP_RETI
- pop YL
- out SREG, YL
- pop YL
- endm
- bitstuff7:
- eor x1, x4
- ldi x2, 0
- nop2
- rjmp didStuff7
- bitstuffN:
- eor x1, x4
- ldi x2, 0
- lpm
- out USBOUT, x1
- rjmp didStuffN
- sendNakAndReti:
- ldi cnt, USBPID_NAK
- rjmp sendCntAndReti
- sendAckAndReti:
- ldi cnt, USBPID_ACK
- sendCntAndReti:
- mov r0, cnt
- ldi YL, 0
- ldi YH, 0
- ldi cnt, 2
- usbSendAndReti:
- in x2, USBDDR
- ori x2, USBMASK
- sbi USBOUT, USBMINUS
- in x1, USBOUT
- out USBDDR, x2
- ldi x4, USBMASK
- ldi shift, 0x80
- ldi bitStatus, 0xff
- byteloop:
- bitloop:
- sbrs shift, 0
- eor x1, x4
- out USBOUT, x1
- ror shift
- ror x2
- didStuffN:
- cpi x2, 0xfc
- brcc bitstuffN
- nop
- subi bitStatus, 37
- brcc bitloop
- sbrs shift, 0
- eor x1, x4
- ror shift
- didStuff7:
- out USBOUT, x1
- ror x2
- cpi x2, 0xfc
- brcc bitstuff7
- ld shift, y+
- dec cnt
- brne byteloop
- cbr x1, USBMASK
- lds x2, usbNewDeviceAddr
- lsl x2
- out USBOUT, x1
- subi YL, 2
- sbci YH, 0
- 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
- ldi x4, 4
- se0Delay:
- dec x4
- brne se0Delay
- out USBOUT, x1
- out USBDDR, x2
- out USBOUT, x3
- rjmp doReturn
|