123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707 |
- ;
- ;
- macro POP_STANDARD
- pop ZH
- pop ZL
- pop cnt
- pop x5
- pop x3
- pop x2
- pop x1
- pop shift
- pop x4
- endm
- macro POP_RETI
- pop YH
- pop YL
- out SREG, YL
- pop YL
- endm
- macro CRC_CLEANUP_AND_CHECK
-
-
- ldi ZH, hi8(usbCrcTableHigh)
- lpm x2, Z
- ldi ZH, hi8(usbCrcTableLow)
- lpm ZL, Z
- eor ZL, x3
- cpi ZL, 0x01
- brne ignorePacket
- cpi x2, 0xb0
- brne ignorePacket
- endm
- 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
- 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 x4
- lds YL, usbInputBufOffset
- clr YH
- subi YL, lo8(-(usbRxBuf))
- sbci YH, hi8(-(usbRxBuf))
- push shift
- ldi shift, 0x80
- clc
- sbis USBIN, USBMINUS
- rjmp haveTwoBitsK
- pop shift
- pop x4
- rjmp waitForK
- haveTwoBitsK:
- push x1
- push x2
- push x3
- ldi x2, 1<<USBPLUS
- push x5
- push cnt
- ldi cnt, USB_BUFSIZE
- in x1, USBIN
- andi x1, USBMASK
- eor x2, x1
- sbrc x2, USBMINUS
- sec
- ror shift
- mov x2, x1
- push ZL
-
- push ZH
-
- ldi x3, 0xFE
- bitloopPid:
- in x1, USBIN
- andi x1, USBMASK
- breq nse0
- eor x2, x1
- sbrc x2, USBMINUS
- sec
- ror shift
- ldi ZL, 0x54
- ser x4
-
- mov x2, x1
- brcc bitloopPid
- eor x4, shift
- rxDataStart:
- in x1, USBIN
- ser x5
- eor x2, x1
- bst x2, USBMINUS
- bld shift, 0
- mov x2, shift
- andi x2, 0xF9
- breq unstuff0
- didunstuff0:
- subi cnt, 1
- brcs nOverflow
- st Y+, x4
-
- in x2, USBIN
- andi x1, USBMASK
- breq nse0
- andi x2, USBMASK
- breq nse0
- eor x1, x2
- bst x1, USBMINUS
- bld shift, 1
- mov x1, shift
- andi x1, 0xF3
- breq unstuff1
- didunstuff1:
- nop
- in x1, USBIN
- andi x1, USBMASK
- breq nOverflow
- eor x2, x1
- bst x2, USBMINUS
- bld shift, 2
- mov x2, shift
- andi x2, 0xE7
- breq unstuff2
- didunstuff2:
- nop2
-
- nop
-
- in x2, USBIN
- andi x2, USBMASK
- breq nOverflow
- eor x1, x2
- bst x1, USBMINUS
- bld shift, 3
- mov x1, shift
- andi x1, 0xCF
- breq unstuff3
- didunstuff3:
- nop
- rjmp rxDataBit4
-
- nse0:
- rjmp se0
-
- nOverflow:
- stuffErr:
- rjmp overflow
- unstuff0:
- andi x1, USBMASK
- breq didunstuff0
- ori shift, 0x01
- in x2, USBIN
- andi x5, 0xFE
- eor x1, x2
- andi x1, USBMASK
- breq stuffErr
- mov x1, x2
- rjmp didunstuff0
-
- unstuff1:
- in x1, USBIN
- ori shift, 0x02
- andi x5, 0xFD
- eor x2, x1
- andi x2, USBMASK
- breq stuffErr
- mov x2, x1
- nop2
-
- rjmp didunstuff1
-
- unstuff2:
- ori shift, 0x04
- andi x5, 0xFB
- in x2, USBIN
- eor x1, x2
- andi x1, USBMASK
- breq stuffErr
- mov x1, x2
- nop2
-
- rjmp didunstuff2
-
- unstuff3:
- ori shift, 0x08
- andi x5, 0xF7
- in x1, USBIN
- eor x2, x1
- andi x2, USBMASK
- breq stuffErr
- mov x2, x1
- nop2
-
- rjmp didunstuff3
-
-
- 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 x2, 0
- ldi x4, USBMASK
- ldi shift, 0x80
- txByteLoop:
- ldi bitcnt, 0x40
- txBitLoop:
- sbrs shift, 0
- eor x1, x4
- out USBOUT, x1
- ror shift
- ror x2
- didStuffN:
- nop
- nop
- cpi x2, 0xfc
- brcc bitstuffN
- lsr bitcnt
- brne txBitLoop
- sbrs shift, 0
- eor x1, x4
- didStuff7:
- ror shift
- out USBOUT, x1
- ror x2
- cpi x2, 0xfc
- brcc bitstuff7
- ld shift, y+
- dec cnt
- brne txByteLoop
-
-
- 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, 4
- se0Delay:
- dec x4
- brne se0Delay
- out USBOUT, x1
- out USBDDR, x2
- out USBOUT, x3
- rjmp doReturn
- bitstuffN:
- eor x1, x4
- ldi x2, 0
- nop2
- out USBOUT, x1
- rjmp didStuffN
- bitstuff7:
- eor x1, x4
- ldi x2, 0
- clc
- rol shift
- rjmp didStuff7
-
- nOverflow2:
- rjmp overflow
- rxDataBit4:
- in x1, USBIN
- andi x1, USBMASK
- breq nOverflow2
- eor x2, x1
- bst x2, USBMINUS
- bld shift, 4
- mov x2, shift
- andi x2, 0x9F
- breq unstuff4
- didunstuff4:
- nop2
- nop
- in x2, USBIN
- ldi ZH, hi8(usbCrcTableHigh)
- eor x1, x2
- bst x1, USBMINUS
- bld shift, 5
- mov x1, shift
- andi x1, 0x3F
- breq unstuff5
- didunstuff5:
- lpm x4, Z
-
-
- ldi ZH, hi8(usbCrcTableLow)
- in x1, USBIN
- eor x2, x1
- bst x2, USBMINUS
- bld shift, 6
- mov x2, shift
- andi x2, 0x7E
- breq unstuff6
- didunstuff6:
- lpm ZL, Z
-
-
- eor ZL, x3
- mov x3, x4
-
- in x2, USBIN
- eor x1, x2
- bst x1, USBMINUS
- bld shift, 7
- mov x1, shift
- andi x1, 0xFC
- breq unstuff7
- didunstuff7:
- eor x5, shift
- mov x4, x5
- eor ZL, x4
- rjmp rxDataStart
-
- unstuff4:
- ori shift, 0x10
- andi x5, 0xEF
- in x2, USBIN
- eor x1, x2
- andi x1, USBMASK
- breq stuffErr2
- mov x1, x2
- nop2
-
- rjmp didunstuff4
-
- unstuff5:
- nop
- ori shift, 0x20
- andi x5, 0xDF
- in x1, USBIN
- eor x2, x1
- andi x2, USBMASK
- breq stuffErr2
- mov x2, x1
- nop
- rjmp didunstuff5
-
- unstuff6:
- nop2
-
- ori shift, 0x40
- andi x5, 0xBF
- in x2, USBIN
- eor x1, x2
- andi x1, USBMASK
- breq stuffErr2
- mov x1, x2
- rjmp didunstuff6
-
- unstuff7:
- nop
- nop
- ori shift, 0x80
- andi x5, 0x7F
- in x1, USBIN
- eor x2, x1
- andi x2, USBMASK
- breq stuffErr2
- mov x2, x1
- rjmp didunstuff7
-
- stuffErr2:
- rjmp stuffErr
- .balign 256
- usbCrcTableLow:
- .byte 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41
- .byte 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40
- .byte 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40
- .byte 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41
- .byte 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40
- .byte 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41
- .byte 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41
- .byte 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40
- .byte 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40
- .byte 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41
- .byte 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41
- .byte 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40
- .byte 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41
- .byte 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40
- .byte 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40
- .byte 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41
- .byte 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40
- .byte 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41
- .byte 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41
- .byte 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40
- .byte 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41
- .byte 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40
- .byte 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40
- .byte 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41
- .byte 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41
- .byte 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40
- .byte 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40
- .byte 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41
- .byte 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40
- .byte 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41
- .byte 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41
- .byte 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40
- usbCrcTableHigh:
- .byte 0x00, 0xC0, 0xC1, 0x01, 0xC3, 0x03, 0x02, 0xC2
- .byte 0xC6, 0x06, 0x07, 0xC7, 0x05, 0xC5, 0xC4, 0x04
- .byte 0xCC, 0x0C, 0x0D, 0xCD, 0x0F, 0xCF, 0xCE, 0x0E
- .byte 0x0A, 0xCA, 0xCB, 0x0B, 0xC9, 0x09, 0x08, 0xC8
- .byte 0xD8, 0x18, 0x19, 0xD9, 0x1B, 0xDB, 0xDA, 0x1A
- .byte 0x1E, 0xDE, 0xDF, 0x1F, 0xDD, 0x1D, 0x1C, 0xDC
- .byte 0x14, 0xD4, 0xD5, 0x15, 0xD7, 0x17, 0x16, 0xD6
- .byte 0xD2, 0x12, 0x13, 0xD3, 0x11, 0xD1, 0xD0, 0x10
- .byte 0xF0, 0x30, 0x31, 0xF1, 0x33, 0xF3, 0xF2, 0x32
- .byte 0x36, 0xF6, 0xF7, 0x37, 0xF5, 0x35, 0x34, 0xF4
- .byte 0x3C, 0xFC, 0xFD, 0x3D, 0xFF, 0x3F, 0x3E, 0xFE
- .byte 0xFA, 0x3A, 0x3B, 0xFB, 0x39, 0xF9, 0xF8, 0x38
- .byte 0x28, 0xE8, 0xE9, 0x29, 0xEB, 0x2B, 0x2A, 0xEA
- .byte 0xEE, 0x2E, 0x2F, 0xEF, 0x2D, 0xED, 0xEC, 0x2C
- .byte 0xE4, 0x24, 0x25, 0xE5, 0x27, 0xE7, 0xE6, 0x26
- .byte 0x22, 0xE2, 0xE3, 0x23, 0xE1, 0x21, 0x20, 0xE0
- .byte 0xA0, 0x60, 0x61, 0xA1, 0x63, 0xA3, 0xA2, 0x62
- .byte 0x66, 0xA6, 0xA7, 0x67, 0xA5, 0x65, 0x64, 0xA4
- .byte 0x6C, 0xAC, 0xAD, 0x6D, 0xAF, 0x6F, 0x6E, 0xAE
- .byte 0xAA, 0x6A, 0x6B, 0xAB, 0x69, 0xA9, 0xA8, 0x68
- .byte 0x78, 0xB8, 0xB9, 0x79, 0xBB, 0x7B, 0x7A, 0xBA
- .byte 0xBE, 0x7E, 0x7F, 0xBF, 0x7D, 0xBD, 0xBC, 0x7C
- .byte 0xB4, 0x74, 0x75, 0xB5, 0x77, 0xB7, 0xB6, 0x76
- .byte 0x72, 0xB2, 0xB3, 0x73, 0xB1, 0x71, 0x70, 0xB0
- .byte 0x50, 0x90, 0x91, 0x51, 0x93, 0x53, 0x52, 0x92
- .byte 0x96, 0x56, 0x57, 0x97, 0x55, 0x95, 0x94, 0x54
- .byte 0x9C, 0x5C, 0x5D, 0x9D, 0x5F, 0x9F, 0x9E, 0x5E
- .byte 0x5A, 0x9A, 0x9B, 0x5B, 0x99, 0x59, 0x58, 0x98
- .byte 0x88, 0x48, 0x49, 0x89, 0x4B, 0x8B, 0x8A, 0x4A
- .byte 0x4E, 0x8E, 0x8F, 0x4F, 0x8D, 0x4D, 0x4C, 0x8C
- .byte 0x44, 0x84, 0x85, 0x45, 0x87, 0x47, 0x46, 0x86
- .byte 0x82, 0x42, 0x43, 0x83, 0x41, 0x81, 0x80, 0x40
|