123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346 |
- USB_INTR_VECTOR:
- push YL
- in YL, SREG
- push YL
- push YH
- 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 bitcnt
- lds YL, usbInputBufOffset
- clr YH
- subi YL, lo8(-(usbRxBuf))
- sbci YH, hi8(-(usbRxBuf))
- push shift
- ldi bitcnt, 0x55
- sbis USBIN, USBMINUS
- rjmp haveTwoBitsK
- pop shift
- pop bitcnt
- rjmp waitForK
- haveTwoBitsK:
- push x1
- push x2
- push x3
- ldi shift, 0
- ldi x3, 1<<4
- push x4
- in x1, USBIN
- andi x1, USBMASK
- bst x1, USBMINUS
- bld shift, 7
- push cnt
- ldi leap, 0
- ldi cnt, USB_BUFSIZE
- rjmp rxbit1
- unstuff6:
- andi x2, USBMASK
- ori x3, 1<<6
- andi shift, ~0x80
- mov x1, x2
- subi leap, -1
- rjmp didUnstuff6
- unstuff7:
- ori x3, 1<<7
- in x2, USBIN
- andi x2, USBMASK
- andi shift, ~0x80
- subi leap, 2
- rjmp didUnstuff7
- unstuffEven:
- ori x3, 1<<6
- in x1, USBIN
- andi shift, ~0x80
- andi x1, USBMASK
- breq se0
- subi leap, -1
- nop2
- rjmp didUnstuffE
- unstuffOdd:
- ori x3, 1<<5
- in x2, USBIN
- andi shift, ~0x80
- andi x2, USBMASK
- breq se0
- subi leap, -1
- nop2
- rjmp didUnstuffO
- rxByteLoop:
- andi x1, USBMASK
- eor x2, x1
- subi leap, 1
- brpl skipLeap
- subi leap, -3
- nop
- skipLeap:
- subi x2, 1
- ror shift
- didUnstuff6:
- cpi shift, 0xfc
- in x2, USBIN
- brcc unstuff6
- andi x2, USBMASK
- eor x1, x2
- subi x1, 1
- ror shift
- didUnstuff7:
- cpi shift, 0xfc
- brcc unstuff7
- eor x3, shift
- st y+, x3
- rxBitLoop:
- in x1, USBIN
- andi x1, USBMASK
- eor x2, x1
- andi x3, 0x3f
- subi x2, 1
- ror shift
- cpi shift, 0xfc
- brcc unstuffEven
- didUnstuffE:
- lsr x3
- lsr x3
- rxbit1:
- in x2, USBIN
- andi x2, USBMASK
- breq se0
- eor x1, x2
- subi x1, 1
- ror shift
- cpi shift, 0xfc
- brcc unstuffOdd
- didUnstuffO:
- subi bitcnt, 0xab
- brcs rxBitLoop
- subi cnt, 1
- in x1, USBIN
- brcc rxByteLoop
- rjmp overflow
- macro POP_STANDARD
- pop cnt
- pop x4
- pop x3
- pop x2
- pop x1
- pop shift
- pop bitcnt
- endm
- macro POP_RETI
- pop YH
- pop YL
- out SREG, YL
- pop YL
- endm
- bitstuffN:
- eor x1, x4
- ldi x2, 0
- nop2
- nop
- out USBOUT, x1
- rjmp didStuffN
-
- bitstuff6:
- eor x1, x4
- ldi x2, 0
- rol shift
- rjmp didStuff6
- bitstuff7:
- ldi x2, 0
- 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
- txByteLoop:
- ldi bitcnt, 0x35
- txBitLoop:
- sbrs shift, 0
- eor x1, x4
- out USBOUT, x1
- ror shift
- ror x2
- didStuffN:
- cpi x2, 0xfc
- brcc bitstuffN
- lsr bitcnt
- brcc txBitLoop
- brne txBitLoop
- sbrs shift, 0
- eor x1, x4
- didStuff6:
- out USBOUT, x1
- ror shift
- ror x2
- cpi x2, 0xfc
- brcc bitstuff6
- ror shift
- didStuff7:
- ror x2
- sbrs x2, 7
- eor x1, x4
- nop
- cpi x2, 0xfc
- out USBOUT, x1
- brcc bitstuff7
- ld shift, y+
- dec cnt
- brne txByteLoop
- cbr x1, USBMASK
- lds x2, usbNewDeviceAddr
- lsl x2
- subi YL, 20 + 2
- 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
- ldi x4, 4
- se0Delay:
- dec x4
- brne se0Delay
- out USBOUT, x1
- out USBDDR, x2
- out USBOUT, x3
- rjmp doReturn
|