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