USBasp 2007.07.23.
authorPeter Henn <Peter.Henn@web.de>
Mon, 23 Jul 2007 10:00:00 +0000 (12:00 +0200)
committerPeter Henn <Peter.Henn@web.de>
Mon, 23 Jul 2007 10:00:00 +0000 (12:00 +0200)
unmodified content from archive usbasp.2007-07-23.tar.gz

28 files changed:
Changelog.txt
Readme.txt
bin/firmware/usbasp.atmega48.2006-12-29.hex [deleted file]
bin/firmware/usbasp.atmega48.2007-07-23.hex [new file with mode: 0644]
bin/firmware/usbasp.atmega8.2006-12-29.hex [deleted file]
bin/firmware/usbasp.atmega8.2007-07-23.hex [new file with mode: 0644]
firmware/clock.c
firmware/clock.h
firmware/isp.c
firmware/isp.h
firmware/main.c
firmware/main.hex [new file with mode: 0644]
firmware/usbconfig.h
firmware/usbdrv/Changelog.txt
firmware/usbdrv/CommercialLicense.txt [new file with mode: 0644]
firmware/usbdrv/License.txt
firmware/usbdrv/Readme.txt
firmware/usbdrv/iarcompat.h
firmware/usbdrv/oddebug.c
firmware/usbdrv/oddebug.h
firmware/usbdrv/usbconfig-prototype.h
firmware/usbdrv/usbdrv.c
firmware/usbdrv/usbdrv.h
firmware/usbdrv/usbdrvasm.S
firmware/usbdrv/usbdrvasm.asm
firmware/usbdrv/usbdrvasm12.S [new file with mode: 0644]
firmware/usbdrv/usbdrvasm16.S [new file with mode: 0644]
firmware/usbdrv/usbdrvasm165.S [new file with mode: 0644]

index 0497fa7..d693028 100644 (file)
@@ -1,3 +1,9 @@
+usbasp.2007-07-23
+-----------------
+- changed licence to GNU GPL v2
+- included new AVRUSB driver version (Release 2007-07-07); AVRUSB licence was changed to GNU GPL v2
+- fixed long addressing for Mega128 (by BoskiDialer)
+
 usbasp.2006-12-29
 -----------------
 - fixed returnvalue in usbWriteFunction (by Jeroen Koeter)
index 16d78db..c34bdd7 100644 (file)
@@ -15,16 +15,17 @@ Features:
 
 LICENSE
 
-The project is built with AVR USB driver by Objective Development, which is
-published under a proprietary Open Source license. To conform with this
-license, USBasp is distributed under the same license conditions. See the
-file "firmware/usbdrv/License.txt" for details.
+USBasp is distributed under the terms and conditions of the GNU GPL version
+2 (see "firmware/usbdrv/License.txt" for details).
+
+USBasp is built with AVR USB driver by OBJECTIVE DEVELOPMENT GmbH. See
+"firmware/usbdrv/" for further information.
 
 
 LIMITATIONS
 
 Hardware:
-This package includes a circuit diagram. That circuit can only be used for
+This package includes a circuit diagram. This circuit can only be used for
 programming 5V target systems. For other systems a level converter is needed.
 
 Firmware:
@@ -132,5 +133,5 @@ libusb .......................... http://libusb.sourceforge.net/
 libusb-win32 .................... http://libusb-win32.sourceforge.net/
 
 
-2006-12-29 Thomas Fischl <tfischl@gmx.de>
+2007-07-23 Thomas Fischl <tfischl@gmx.de>
 http://www.fischl.de
diff --git a/bin/firmware/usbasp.atmega48.2006-12-29.hex b/bin/firmware/usbasp.atmega48.2006-12-29.hex
deleted file mode 100644 (file)
index 1fb23b5..0000000
+++ /dev/null
@@ -1,214 +0,0 @@
-:1000000042C083C15AC059C058C057C056C055C01D
-:1000100054C053C052C051C050C04FC04EC04DC05C
-:100020004CC04BC04AC049C048C047C046C045C08C
-:1000300044C043C0090212000101008019090400F4
-:1000400000000000000012010101FF000008C016BE
-:10005000DC050101010200010E03550053004200BE
-:100060006100730070001C037700770077002E009A
-:10007000660069007300630068006C002E00640075
-:1000800065000403090411241FBECFEFD2E0DEBFD8
-:10009000CDBF11E0A0E0B1E0E0E4FDE002C00590DA
-:1000A0000D92A230B107D9F711E0A2E0B1E001C092
-:1000B0001D92A234B107E1F727C6A2CF1F93CF93B9
-:1000C000DF9360913C01662359F1635067FD6CC07A
-:1000D000C2E0D1E0C0913601CF5F20E010E880910E
-:1000E00039018D3209F465C08091180187FD09C07E
-:1000F000CE016BD52FEF821709F49FC0811120E04C
-:1001000010E010931801922F2093010110923C01EE
-:100110009F3F51F483B1837089F110921901E3C0BC
-:10012000909101019F3FB1F38091000184FFF2CFD4
-:10013000692F9930B8F5961B909301011BE48091CB
-:10014000180180FD13EC8F5F80931801ACE2B1E0E1
-:1001500087FD60C0662309F058C060E070E0C62FDC
-:10016000693008F446C02EE18FEF809301011093AF
-:100170002B012093000183B1837079F680911901DE
-:10018000882309F0B0C094E683B1837009F0ABC056
-:100190009150D1F781E08093190190933D019093A4
-:1001A0003801A1C068E0C7CF9091010110923C01D5
-:1001B000AFCF683009F0A5CF8881807609F056C0AE
-:1001C00044E351E0209334018981882309F041C040
-:1001D0002093350122E050933B0140933A018F81F7
-:1001E000882309F08ECF8E81821708F08ACF282FBE
-:1001F00088CF8CE291E02CD22C2F2C5FC83008F0F5
-:10020000B6CF9FEF90930101B2CFCD01A1D4682F5B
-:100210007727A5CFE0913A01F0913B0186FF12C00C
-:10022000962F03C084918D9331969150D8F7F09317
-:100230003B01E0933A01772792CF8EE18093000152
-:1002400010E05FCF962F02C081918D939150E0F71F
-:10025000EECF8530B9F08630C9F0883039F1893079
-:1002600049F18A3009F0BBCF21E0B5CFCE0187D369
-:10027000282F8F3F09F0B3CF888187FF41CF2E8190
-:1002800010E03FCF8A8180933D01A9CF10EC8B8194
-:100290008130A1F08230B1F0833009F0A0CF8A81A3
-:1002A0008823A1F442E850E024E095CF4FE351E0E9
-:1002B00021E091CF8A8180933F0191CF46E450E0C5
-:1002C00022E189CF44E350E022E185CF813039F04B
-:1002D000823009F084CF48E550E02EE07CCF46E63E
-:1002E00050E02CE178CFDF91CF911F91089582E00B
-:1002F00091E0809337010B968093360180916900DD
-:10030000836080936900E89A08950F930FB70F9365
-:10031000189BFECF189B06C0189B04C0189B02C0F8
-:10032000000000C01F933F932F9331E012E003B110
-:10033000102710FD32E0102F3A95C9F700FDE3C0F9
-:1003400003B1102720E010FB20F9DF9313B1012740
-:1003500000FB21F9CF93C091370103B1102710FBA7
-:1003600022F93BE0D1E04F9313B1012700FB23F9C1
-:100370004FEF000055C0189BFECF189B06C0189B7E
-:1003800004C0189B02C0000000C0DF9100C0CDCFA8
-:1003900013B1137079F14F7D206213C003B1037064
-:1003A00049F14F7B206415C0037021F1102F2068A4
-:1003B00003B119C003B10370E9F04E7F216018C08A
-:1003C00039F303B10370B1F0102710FB26F9223086
-:1003D00028F313B1012700FB27F9422749934FEF78
-:1003E00003B1243008F3102710FB20F9297F11F303
-:1003F00013B11370E1F1012700FB21F9237FF1F024
-:1004000003B10370A1F1102710FB22F9277EE1F060
-:1004100013B1012700FB23F93A9541F12F7CD1F06C
-:1004200003B1037021F1102710FB24F92F79C1F0DB
-:1004300013B1012700FB25F92F73C2CF13B113703D
-:10044000B1F04D7F2260DCCF03B1037081F04B7FB0
-:100450002460DECF13B1137051F0477F2860E0CFE6
-:1004600003B1037021F04F7E2061E2CF3BC03C2FEF
-:10047000C09137013C1B01E033300CBB98F108817F
-:100480001981412F1F77209138010D3279F1013EFA
-:1004900069F10936C1F00777033421F510913E0167
-:1004A000112301F100913C010030C1F53430C2F15B
-:1004B00030933C011093390100913601C09336010D
-:1004C000009337012DC0121769F43091000134FDFB
-:1004D00023C00AE500930001CBE2D1E025C000274C
-:1004E00000933E014F91CF91DF910DC01217B9F7E4
-:1004F00000933E010AE5009300014F91CF910CB3A8
-:1005000000FD39CFDF9101E00CBB2F913F911F918E
-:100510000F910FBF0F911895432F03C04AE501C0FB
-:1005200042EDC4E1D0E032E05F9353E0289A05B198
-:10053000209A219A20E80FC0052710E005B910C0C5
-:10054000052710E0089405B913C0052710E015C071
-:10055000052710E019C020FF052705B92795179535
-:100560001C3F50F720FF0527279505B917951C3F1D
-:1005700038F720FF05272795179505B91C3F28F761
-:1005800020FF0527279517951C3F05B908F700C0E0
-:10059000499120FF052705B9279517951C3F80F540
-:1005A00020FF0527279505B917951C3F68F520FF03
-:1005B00005272795179505B91C3F58F520FF0527F6
-:1005C000279517951C3F05B938F5242F3A9519F64C
-:1005D0000C7F5F9105B932E03A95F1F710913D013A
-:1005E000C651D04011F010933801016014B11C7F46
-:1005F00005B90C7F4F91CF9114B905B9DF9183CF25
-:10060000052710E005B9CACF052710E0089405B901
-:10061000CDCF052710E0CFCF052710E0D3CFA82FEF
-:10062000B92F8FEF9FEF41E050EA615070F02D91AC
-:1006300038E0722F782796958795269570FF02C02F
-:10064000842795273A95A9F7F0CF8095909508953E
-:10065000E6DF8D939D93089582E58CBD81E08DBD8D
-:100660000895882339F482E693E0909341018093C2
-:10067000400108958FE793E09093410180934001FA
-:10068000089596B586B5891B8C30E0F3089584B142
-:100690008C6284B92A982D98F4DF2A9AF2DF2A987E
-:1006A00080914001909141018F57934009F0089546
-:1006B000D3DF089584B1837D84B985B1837D85B905
-:1006C0001CBC08950F931F93CF93C82F00E017E031
-:1006D0000CC02B98CC0F000F1C990F5F2D9AD1DF07
-:1006E0002D98CFDF115017FD04C0C7FFF2CF2B9A12
-:1006F000F1CF802F9927CF911F910F9108958EBD33
-:100700000DB407FEFDCF8EB5992708951F93CF93A3
-:10071000CFE103C0C150CF3F51F1E0914001F091D2
-:1007200041018CEA0995E0914001F091410183E596
-:100730000995E0914001F091410180E00995182F61
-:10074000E0914001F091410180E00995133591F06D
-:100750001CBC2D9A96DF2D9894DF809140019091DA
-:1007600041018F579340B1F677DFC150B0F681E079
-:1007700090E002C080E090E0CF911F9108950F9328
-:100780001F938C018170880F880F880FE0914001C2
-:10079000F091410180620995C801892F99278695BA
-:1007A000E0914001F0914101099516950795E0917E
-:1007B0004001F0914101802F0995E0914001F091B5
-:1007C000410180E0099599271F910F9108950F939A
-:1007D0001F93CF93DF93EC01062F142F8170880FA6
-:1007E000880F880FE0914001F091410180640995E4
-:1007F000CE01892F99278695E0914001F091410122
-:100800000995CE0196958795E0914001F0914101BF
-:100810000995E0914001F0914101802F0995112344
-:10082000A9F00F3789F01EE106B5CE01A8DF8F379A
-:1008300069F486B5801B8D3310F006B51150112375
-:10084000A1F781E090E004C08FE08CD080E090E0E0
-:10085000DF91CF911F910F9108950F931F93CF9325
-:10086000DF93EC01162FE0914001F09141018CE4FF
-:100870000995CE01892F99278695E0914001F09145
-:1008800041010995CE0196958795E0914001F0913F
-:1008900041010995E0914001F091410180E0099505
-:1008A0001F3F89F01EE106B5CE0169DF8F3F69F475
-:1008B00086B5801B8D3310F006B511501123A1F7BA
-:1008C00081E090E004C08FE04DD080E090E0DF91C7
-:1008D000CF911F910F9108950F931F938C01E09179
-:1008E0004001F091410180EA0995812F9927E0911B
-:1008F0004001F09141010995E0914001F0914101E1
-:10090000802F0995E0914001F091410180E0099527
-:1009100099271F910F910895FF920F931F938C01B8
-:10092000F62EE0914001F091410180EC0995812F74
-:100930009927E0914001F09141010995E091400132
-:10094000F0914101802F0995E0914001F091410122
-:100950008F2D09958EE106D080E090E01F910F91D8
-:10096000FF900895382F20E0231740F496B586B500
-:10097000891B8C33E0F32F5F2317C0F308951F9377
-:10098000CF93DF93EC0110E089818130A1F08230B8
-:1009900009F489C0833009F489C0843091F087302C
-:1009A00009F467C0853009F4C3C0863039F1883056
-:1009B00009F0C2C09DC0329B812F53DE68DE419892
-:1009C000BBC08B819927982F88272A813327822BB8
-:1009D000932B90932601809325018F819927982F3F
-:1009E00088272E813327822B932B90931B01809392
-:1009F0001A0182E080931C011FEF9EC08B81992712
-:100A0000982F88272A813327822B932B90932601B6
-:100A1000809325018C81482F5527509328014093BE
-:100A200027012D812F70209329018D819927807FA7
-:100A3000907082959295907F9827807F9827840F59
-:100A4000951F909328018093270120FF04C0809177
-:100A5000270180932A018F819927982F88272E813B
-:100A60003327822B932B90931B0180931A0181E0F3
-:100A7000C1CF8B819927982F88272A813327822BF2
-:100A8000932B90932601809325018F819927982F8E
-:100A900088272E813327822B932B90931B018093E1
-:100AA0001A0183E0A7CF06DE419A46C0E0914001DB
-:100AB000F09141018A81099580931D01E0914001E7
-:100AC000F09141018B81099580931E01E0914001D5
-:100AD000F09141018C81099580931F01E0914001C3
-:100AE000F09141018D8109958093200114E024C08B
-:100AF0008B819927982F88272A813327822B932B44
-:100B000090932601809325011092280110922701CD
-:100B1000109329018F819927982F88272E813327B9
-:100B2000822B932B90931B0180931A0184E062CF58
-:100B3000EDDD80931D0111E08DE191E090933B018B
-:100B400080933A01812F9927DF91CF911F910895CA
-:100B5000EF92FF921F93CF937C01162F90911C016F
-:100B6000892F8250823050F5C0E0C617C0F01FC0F8
-:100B70008091250190912601AFDEF701EC0FF11D68
-:100B80008083809125019091260101969093260102
-:100B900080932501CF5FC11750F490911C019230D2
-:100BA00039F78091250190912601E9DDE6CF1830D3
-:100BB00010F410921C01812F992702C08FEF90E052
-:100BC000CF911F91FF90EF900895BF92CF92DF9247
-:100BD000EF92FF920F931F93CF93DF936C01E62E5A
-:100BE000BB2440911C01413019F0443009F080C011
-:100BF000FF24FE1408F079C0413009F049C080910B
-:100C0000270190912801892B09F04EC0CF2DDD27B7
-:100C1000F601EC0FFD1F6081809125019091260166
-:100C2000D6DD80911A0190911B01019790931B01D1
-:100C300080931A01892BD9F410921C01809129010B
-:100C400081FF13C080912A01282F3327809127012B
-:100C5000909128012817390741F0CC0DDD1D6881DE
-:100C60008091250190912601F8DDC1E0BC2E809194
-:100C700025019091260101969093260180932501EC
-:100C8000F394FE1490F540911C01413009F4B7CF64
-:100C9000CF2DDD27F601EC0FFD1F6081809125012E
-:100CA0009091260139DEBDCFCF2DDD2786010C0FB7
-:100CB0001D1F40E0F801608180912501909126017F
-:100CC00086DD80912A01815080932A01882309F0D2
-:100CD000A8CFF80160818091250190912601BDDDAA
-:100CE0008091270180932A019CCF8B2D992702C0E8
-:100CF0008FEF90E0DF91CF911F910F91FF90EF90D8
-:100D0000DF90CF90BF900895CFEFD2E0DEBFCDBF90
-:100D10001BB815B88BEF8AB98FEF84B990E091506A
-:100D2000F1F78150D9F784B993E097B98EEF88B97C
-:100D300095BD81E096DCDBDA7894C0D9BFD9FDCFD0
-:020D40005AFF58
-:00000001FF
diff --git a/bin/firmware/usbasp.atmega48.2007-07-23.hex b/bin/firmware/usbasp.atmega48.2007-07-23.hex
new file mode 100644 (file)
index 0000000..8bae70e
--- /dev/null
@@ -0,0 +1,225 @@
+:1000000042C081C15AC059C058C057C056C055C01F
+:1000100054C053C052C051C050C04FC04EC04DC05C
+:100020004CC04BC04AC049C048C047C046C045C08C
+:1000300044C043C0090212000101008019090400F4
+:1000400000000000000012011001FF000008C016AF
+:10005000DC050201010200010E03550053004200BD
+:100060006100730070001C037700770077002E009A
+:10007000660069007300630068006C002E00640075
+:1000800065000403090411241FBECFEFD2E0DEBFD8
+:10009000CDBF11E0A0E0B1E0E4EEFDE002C00590CC
+:1000A0000D92A230B107D9F711E0A2E0B1E001C092
+:1000B0001D92A334B107E1F779C6A2CF1F93CF9366
+:1000C000DF936091270116160CF580912401C7E398
+:1000D000D1E0C81BD109635020E010E880912301D2
+:1000E0008D3209F44CC08091020187FD09C0CE0118
+:1000F0009CD52FEF821709F470C0811120E010E029
+:1001000010930201209301011092270180910001B8
+:1001100084FF27C0809101018F3F19F1682F89303A
+:1001200008F050C0861B809301011BE480910201FE
+:1001300080FD13EC8F5F80930201A8E1B1E087FDA1
+:1001400056C0662309F04EC060E070E0C62F6930EB
+:10015000D8F19EE18FEF80930101109317019093E6
+:1001600000019AE083B1837011F49150D9F799237B
+:1001700009F0A1C090932801909322019CC08AE5C8
+:1001800080930001683009F0BBCF8881807609F048
+:1001900048C040E251E0209320018981882309F082
+:1001A0004CC02093210122E0509326014093250169
+:1001B0008F81882309F0A4CF8E81821708F0A0CF09
+:1001C000282F9ECF68E0AECF88E191E098D09C2F99
+:1001D0009C5FC83008F0C1CFBDCF8EE18093000195
+:1001E00010E08ECFCD01D4D4682F7727AFCFE09128
+:1001F0002501F091260186FF0DC0962F03C0849142
+:100200008D9331969150D8F7F0932601E093250114
+:1002100077279CCF962F02C081918D939150E0F764
+:10022000F3CFCE0185D3282F8F3F09F0C1CF88812E
+:1002300087FF65CF2E8110E063CF853059F086307F
+:1002400069F08830D9F08930E9F08A3009F0B0CF10
+:1002500021E0AACF8A8180932801AACF10EC8B815C
+:100260008130A1F08230F9F0833009F0A1CF8A818A
+:10027000882381F442E850E024E096CF4AE251E03E
+:1002800021E092CF8A8180932A0192CF46E450E008
+:1002900022E18ACF813059F0823009F089CF48E5D8
+:1002A00050E02EE081CF44E350E022E17DCF46E6EE
+:1002B00050E02CE179CFDF91CF911F91089580918B
+:1002C0006900836080936900E89A0895A82FB92F88
+:1002D0008FEF9FEF41E050EA615070F02D9138E0D0
+:1002E000722F782796958795269570FF02C08427F0
+:1002F00095273A95A9F7F0CF809590950895E6DF78
+:100300008D939D930895CF93CFB7CF93189BFECF36
+:10031000189B09C0189B07C0189B05C0189B03C0F9
+:10032000189B01C09EC0DF93C0912401DD27C55DED
+:10033000DE4F189B02C0DF91EBCF2F930F931F93DB
+:1003400003B12FEF00FB20F94F933F9313B14FEF11
+:10035000012700FB21F93BE031C04E7F012F13B193
+:10036000216028C0102F4D7F2260000003B129C0FA
+:100370004B7F2460012F000013B12BC013B1477FC6
+:1003800028602AC04F7E03B120612CC04F7D13B17D
+:1003900020622FC04F7B03B1206432C0422703B1DB
+:1003A00049934FEF0000102710FB20F913B1137091
+:1003B000A9F1297F91F2012700FB21F903B1237FE5
+:1003C00089F23150F0F1102710FB22F913B1277E8A
+:1003D00079F2012700FB23F92F7C81F203B110276A
+:1003E00010FB24F92F7971F200C013B1012700FB33
+:1003F00025F92F7359F200C003B1102710FB26F91D
+:10040000223040F200C013B1012700FB27F924304D
+:1004100028F64F77206813B10000F9CF3B50319593
+:10042000333011E01CBBB8F0C31BD0400881033C43
+:1004300041F10B3431F11981412F1F7720912201B5
+:10044000121731F4093691F10D3279F0013E69F05D
+:100450002227209329013F914F911F910F912F91B6
+:10046000DF91CF91CFBFCF911895009329013F9194
+:100470004F911F910F912F91DF91CCB3C0FD46CFCB
+:10048000F0CF00912901002331F3109127011123AE
+:1004900049F534304AF1309327010093230110913C
+:1004A00024013BE0311B309324011EC00091270141
+:1004B0000130C4F40AE53091000134FD17C0009307
+:1004C0000001C7E1D1E016C0052710E005B91FC043
+:1004D000052722C0052727C005272CC0052710E0C7
+:1004E00005B933C04AE503C042ED01C0432FC4E162
+:1004F000D0E032E014B11360289A05B114B95F93CB
+:1005000053E020E820FF052705B9279517951C3FE4
+:10051000D8F620FF0527279505B917951C3FC0F68B
+:1005200020FF05272795179505B91C3F98F620FF52
+:100530000527279517951C3F05B970F600C049910E
+:1005400020FF052705B9279517951C3F38F620FF92
+:100550000527279505B917951C3F38F520FF052776
+:100560002795179505B91C3F10F520FF05272795FE
+:1005700017951C3F05B9E8F4242F3A9519F60C7F1E
+:100580005F9105B900C010912801C651D04011F00B
+:100590001093220111E01CBB016014B11C7F402F9D
+:1005A0004C7F05B914B945B956CF0527D3CF0527D8
+:1005B000D8CF0527DDCF82E58CBD81E08DBD0895C4
+:1005C000882339F481E193E09093420180934101C3
+:1005D00008958EE293E09093420180934101089543
+:1005E00096B586B5891B8C30E0F3089584B18C6292
+:1005F00084B92A982D98F4DF2A9AF2DF2A988091FC
+:100600004101909142018E52934009F00895D3DF49
+:10061000089584B1837D84B985B1837D85B91CBC7F
+:1006200008950F931F93CF93C82F00E017E00CC0DD
+:100630002B98CC0F000F1C990F5F2D9AD1DF2D98AE
+:10064000CFDF115017FD04C0C7FFF2CF2B9AF1CFB7
+:10065000802F9927CF911F910F9108958EBD0DB4D2
+:1006600007FEFDCF8EB5992708951F93CF93CFE155
+:1006700003C0C150CF3F51F1E0914101F0914201DF
+:100680008CEA0995E0914101F091420183E50995D9
+:10069000E0914101F091420180E00995182FE0912D
+:1006A0004101F091420180E00995133591F01CBCA5
+:1006B0002D9A96DF2D9894DF80914101909142010F
+:1006C0008E529340B1F677DFC150B0F681E090E0F2
+:1006D00002C080E090E0CF911F910895EF92FF92C9
+:1006E0000F931F937B018C01862F8170880F880FD9
+:1006F000880FE0914101F091420180620995D80193
+:10070000C70129E0B695A795979587952A95D1F7C2
+:10071000E0914101F0914201099516950795F794F2
+:10072000E794E0914101F09142018E2D0995E0910D
+:100730004101F091420180E0099599271F910F91A5
+:10074000FF90EF900895CF92DF92EF92FF921F9368
+:10075000CF936B017C01C42F122F862F8170880FDD
+:10076000880F880FE0914101F09142018064099562
+:10077000D701C60149E0B695A795979587954A9503
+:10078000D1F7E0914101F09142010995D701C601ED
+:10079000B695A79597958795E0914101F091420113
+:1007A0000995E0914101F09142018C2F09951123A7
+:1007B000B1F0CF3791F01EE1C6B5C701B6018EDFAB
+:1007C0008F3769F486B58C1B8D3310F0C6B5115088
+:1007D000112399F781E090E004C08FE09CD080E085
+:1007E00090E0CF911F91FF90EF90DF90CF90089510
+:1007F000CF92DF92EF92FF921F93CF936B017C0118
+:10080000142FE0914101F09142018CE40995D70148
+:10081000C60169E0B695A795979587956A95D1F732
+:10082000E0914101F09142010995D701C601B695C9
+:10083000A79597958795E0914101F091420109951F
+:10084000E0914101F091420180E009951F3F91F054
+:100850001EE1C6B5C701B60141DF8F3F69F486B519
+:100860008C1B8D3310F0C6B51150112399F781E020
+:1008700090E004C08FE04FD080E090E0CF911F91D6
+:10088000FF90EF90DF90CF9008950F931F938C010E
+:10089000E0914101F091420180EA0995812F992769
+:1008A000E0914101F09142010995E0914101F091FF
+:1008B0004201802F0995E0914101F091420180E0D1
+:1008C000099599271F910F910895FF920F931F93F8
+:1008D0008C01F62EE0914101F091420180EC0995E6
+:1008E000812F9927E0914101F09142010995E09112
+:1008F0004101F0914201802F0995E0914101F09171
+:1009000042018F2D09958EE106D080E090E01F9185
+:100910000F91FF900895382F20E0231740F496B5EB
+:1009200086B5891B8C33E0F32F5F2317C0F308953E
+:100930001F93CF93DF93EC0110E089818130B9F0F0
+:10094000823009F49FC0833009F49FC08430B9F02D
+:10095000873009F471C0853009F4FAC08630C1F1DE
+:10096000883009F4C9C0893009F006C1F6C0329B4D
+:10097000812F26DE1092060139DE4198FDC080915C
+:1009800006018823A1F48B819927982F88272A8133
+:100990003327822B932BAA2797FDA095BA2F8093FC
+:1009A0000F0190931001A0931101B09312018F8158
+:1009B0009927982F88272E813327822B932B90936A
+:1009C00004018093030182E0809305011FEFD4C0EE
+:1009D00080910601882309F47AC08C81482F55271D
+:1009E00050931401409313012D812F702093150112
+:1009F0008D819927807F907082959295907F98271E
+:100A0000807F9827840F951F909314018093130182
+:100A100020FF04C080911301809316018F819927D4
+:100A2000982F88272E813327822B932B90930401B4
+:100A30008093030181E0C8CF809106018823A1F44F
+:100A40008B819927982F88272A813327822B932BF4
+:100A5000AA2797FDA095BA2F80930F0190931001BC
+:100A6000A0931101B09312018F819927982F8827A5
+:100A70002E813327822B932B9093040180930301C3
+:100A800083E0A2CFC6DD419A77C0E0914101F091A9
+:100A900042018A81099580930701E0914101F0911B
+:100AA00042018B81099580930801E0914101F09109
+:100AB00042018C81099580930901E0914101F091F7
+:100AC00042018D81099580930A0114E055C08B8104
+:100AD0009927982F88272A813327822B932BAA279F
+:100AE00097FDA095BA2F80930F0190931001A093CA
+:100AF0001101B093120171CF809106018823A1F4F6
+:100B00008B819927982F88272A813327822B932B33
+:100B1000AA2797FDA095BA2F80930F0190931001FB
+:100B2000A0931101B09312011092140110921301BD
+:100B3000109315018F819927982F88272E813327AD
+:100B4000822B932B909304018093030184E03CCF8C
+:100B50008CDD8093070111E00FC081E080930601D6
+:100B60008A819B81AC81BD8180930F01909310019C
+:100B7000A0931101B093120187E091E090932601B8
+:100B800080932501812F9927DF91CF911F9108959F
+:100B9000EF92FF921F93CF937C01162F9091050146
+:100BA000892F82508230D0F5C0E0C61710F12FC0D7
+:100BB00080910F019091100168DEF701EC0FF11D9B
+:100BC000808380910F0190911001A0911101B0914B
+:100BD00012010196A11DB11D80930F019093100188
+:100BE000A0931101B0931201CF5FC11780F49091CF
+:100BF00005019230E9F680910F0190911001A091CA
+:100C00001101B0911201BC01CD0168DDD6CF1830C1
+:100C100010F410920501812F992702C08FEF90E008
+:100C2000CF911F91FF90EF900895BF92CF92DF92E6
+:100C3000EF92FF920F931F93CF93DF936C01062FD8
+:100C4000BB2420910501213019F0243009F0A2C005
+:100C500010E0101708F09BC0213009F05FC08091B0
+:100C6000130190911401892B09F064C0C12FDD2775
+:100C7000F601EC0FFD1F80910F0190911001A091E2
+:100C80001101B09112014081BC01CD015CDD809168
+:100C90000301909104010197909304018093030153
+:100CA000892B09F5109205018091150181FF19C06A
+:100CB00080911601282F3327809113019091140100
+:100CC0002817390771F0CC0DDD1D80910F0190912F
+:100CD0001001A0911101B09112014881BC01CD0118
+:100CE00087DDC1E0BC2E80910F0190911001A09191
+:100CF0001101B09112010196A11DB11D80930F0148
+:100D000090931001A0931101B09312011F5F10176F
+:100D1000F0F520910501213009F4A1CFC12FDD2785
+:100D2000F601EC0FFD1F608180910F019091100181
+:100D3000CCDDADCFC12FDD277601EC0EFD1E8091FD
+:100D40000F0190911001A0911101B091120120E0CA
+:100D5000F7014081BC01CD01F6DC80911601815084
+:100D600080931601882309F092CF80910F01909112
+:100D70001001A0911101B0911201F7014081BC0155
+:100D8000CD0136DD809113018093160180CF8B2D2C
+:100D9000992702C08FEF90E0DF91CF911F910F91C3
+:100DA000FF90EF90DF90CF90BF900895CFEFD2E00B
+:100DB000DEBFCDBF1BB815B88BEF8AB98FEF84B9F2
+:100DC00090E09150F1F78150D9F784B993E097B949
+:100DD0008EEF88B995BD81E0F3DB71DA78946ED936
+:040DE0006DD9FDCFFD
+:020DE4005AFFB4
+:00000001FF
diff --git a/bin/firmware/usbasp.atmega8.2006-12-29.hex b/bin/firmware/usbasp.atmega8.2006-12-29.hex
deleted file mode 100644 (file)
index 388bb13..0000000
+++ /dev/null
@@ -1,213 +0,0 @@
-:100000003BC07CC153C052C051C050C04FC04EC055
-:100010004DC04CC04BC04AC049C048C047C046C094
-:1000200045C044C043C00902120001010080190903
-:10003000040000000000000012010101FF000008A0
-:10004000C016DC050101010200010E03550053003A
-:1000500042006100730070001C0377007700770096
-:100060002E00660069007300630068006C002E00BB
-:10007000640065000403090411241FBECFE5D4E029
-:10008000DEBFCDBF10E0A0E6B0E0E0E3FDE002C0DF
-:1000900005900D92A236B107D9F710E0A2E6B0E0C4
-:1000A00001C01D92A23AB107E1F726C6A9CF1F935E
-:1000B000CF93DF9360919C00662359F1635067FDF5
-:1000C0006CC0C2E6D0E0C0919600CF5F20E010E89F
-:1000D000809199008D3209F465C08091780087FD88
-:1000E00009C0CE016AD52FEF821709F49FC0811194
-:1000F00020E010E010937800922F2093610010927E
-:100100009C009F3F51F486B3837089F1109279006F
-:10011000E3C0909161009F3FB1F38091600084FF44
-:10012000F2CF692F9930B8F5961B909361001BE4CC
-:100130008091780080FD13EC8F5F80937800ACE8AD
-:10014000B0E087FD60C0662309F058C060E070E051
-:10015000C62F693008F446C02EE18FEF809361000E
-:1001600010938B002093600086B3837079F68091A2
-:100170007900882309F0B0C094E686B3837009F053
-:10018000ABC09150D1F781E08093790090939D00AE
-:1001900090939800A1C068E0C7CF90916100109241
-:1001A0009C00AFCF683009F0A5CF8881807609F038
-:1001B00056C044E950E0209394008981882309F0D7
-:1001C00041C02093950022E050939B0040939A00F9
-:1001D0008F81882309F08ECF8E81821708F08ACF15
-:1001E000282F88CF8CE890E02CD22C2F2C5FC830A1
-:1001F00008F0B6CF9FEF90936100B2CFCD01A0D4AD
-:10020000682F7727A5CFE0919A00F0919B0086FF99
-:1002100012C0962F03C084918D9331969150D8F7D8
-:10022000F0939B00E0939A00772792CF8EE1809322
-:10023000600010E05FCF962F02C081918D939150A6
-:10024000E0F7EECF8530B9F08630C9F0883039F16B
-:10025000893049F18A3009F0BBCF21E0B5CFCE011A
-:1002600086D3282F8F3F09F0B3CF888187FF41CFF6
-:100270002E8110E03FCF8A8180939D00A9CF10ECA2
-:100280008B818130A1F08230B1F0833009F0A0CFB2
-:100290008A818823A1F444E750E024E095CF4FE918
-:1002A00050E021E091CF8A8180939F0091CF48E375
-:1002B00050E022E189CF46E250E022E185CF813053
-:1002C00039F0823009F084CF4AE450E02EE07CCF50
-:1002D00048E550E02CE178CFDF91CF911F91089550
-:1002E00082E690E0809397000B968093960085B706
-:1002F000836085BF8BB780648BBF08950F930FB762
-:100300000F93B09BFECFB09B06C0B09B04C0B09BC8
-:1003100002C0000000C01F933F932F9331E012E012
-:1003200006B3102710FD32E0102F3A95C9F700FDF3
-:10033000E3C006B3102720E010FB20F9DF9316B3CB
-:10034000012700FB21F9CF93C091970006B3102736
-:1003500010FB22F93BE0D0E04F9316B3012700FBDE
-:1003600023F94FEF000055C0B09BFECFB09B06C0F5
-:10037000B09B04C0B09B02C0000000C0DF9100C071
-:10038000CDCF16B3137079F14F7D206213C006B341
-:10039000037049F14F7B206415C0037021F1102FC9
-:1003A000206806B319C006B30370E9F04E7F2160E0
-:1003B00018C039F306B30370B1F0102710FB26F90B
-:1003C000223028F316B3012700FB27F9422749936F
-:1003D0004FEF06B3243008F3102710FB20F9297FD4
-:1003E00011F316B31370E1F1012700FB21F9237F0C
-:1003F000F1F006B30370A1F1102710FB22F9277E5C
-:10040000E1F016B3012700FB23F93A9541F12F7C67
-:10041000D1F006B3037021F1102710FB24F92F79D6
-:10042000C1F016B3012700FB25F92F73C2CF16B315
-:100430001370B1F04D7F2260DCCF06B3037081F002
-:100440004B7F2460DECF16B3137051F0477F2860D6
-:10045000E0CF06B3037021F04F7E2061E2CF3BC0B6
-:100460003C2FC09197003C1B00E433300ABF98F149
-:1004700008811981412F1F77209198000D3279F161
-:10048000013E69F10936C1F00777033421F5109177
-:100490009E00112301F100919C000030C1F5343021
-:1004A000C2F130939C001093990000919600C09384
-:1004B0009600009397002DC0121769F430916000E8
-:1004C00034FD23C00AE500936000CBE8D0E025C0EE
-:1004D000002700939E004F91CF91DF910DC012171E
-:1004E000B9F700939E000AE5009360004F91CF9109
-:1004F0000AB706FD39CFDF9100E40ABF2F913F9183
-:100500001F910F910FBF0F911895432F03C04AE51C
-:1005100001C042EDC4E1D0E032E05F9353E0C09A05
-:1005200008B3B89AB99A20E80FC0052710E008BBB5
-:1005300010C0052710E0089408BB13C0052710E081
-:1005400015C0052710E019C020FF052708BB279517
-:1005500017951C3F50F720FF0527279508BB1795D7
-:100560001C3F38F720FF05272795179508BB1C3F30
-:1005700028F720FF0527279517951C3F08BB08F78C
-:1005800000C0499120FF052708BB279517951C3F00
-:1005900080F520FF0527279508BB17951C3F68F5B8
-:1005A00020FF05272795179508BB1C3F58F520FF0E
-:1005B0000527279517951C3F08BB38F5242F3A953A
-:1005C00019F60C7F5F9108BB32E03A95F1F7109174
-:1005D0009D00C651D04011F010939800016017B3F0
-:1005E0001C7F08BB0C7F4F91CF9117BB08BBDF91DD
-:1005F00083CF052710E008BBCACF052710E0089479
-:1006000008BBCDCF052710E0CFCF052710E0D3CF13
-:10061000A82FB92F8FEF9FEF41E050EA615070F0A3
-:100620002D9138E0722F782796958795269570FF43
-:1006300002C0842795273A95A9F7F0CF8095909529
-:100640000895E6DF8D939D93089582E58DB981E04D
-:100650008EB90895882339F48BE593E09093A10037
-:100660008093A000089588E793E09093A100809381
-:10067000A000089592B782B7891B8C30E0F30895EB
-:1006800087B38C6287BBC298C598F4DFC29AF2DF49
-:10069000C2988091A0009091A1008857934009F0E2
-:1006A0000895D3DF089587B3837D87BB88B3837DA7
-:1006B00088BB1DB808950F931F93CF93C82F00E0F8
-:1006C00017E00CC0C398CC0F000FB4990F5FC59A08
-:1006D000D1DFC598CFDF115017FD04C0C7FFF2CF9F
-:1006E000C39AF1CF802F9927CF911F910F91089531
-:1006F0008FB9779BFECF8FB1992708951F93CF9322
-:10070000CFE103C0C150CF3F51F1E091A000F09183
-:10071000A1008CEA0995E091A000F091A10083E589
-:100720000995E091A000F091A10080E00995182FB3
-:10073000E091A000F091A10080E00995133591F0BF
-:100740001DB8C59A97DFC59895DF8091A00090915C
-:10075000A10088579340B1F678DFC150B0F681E030
-:1007600090E002C080E090E0CF911F9108950F9338
-:100770001F938C018170880F880F880FE091A00073
-:10078000F091A10080620995C801892F992786956B
-:10079000E091A000F091A100099516950795E091D0
-:1007A000A000F091A100802F0995E091A000F091A8
-:1007B000A10080E0099599271F910F9108950F934B
-:1007C0001F93CF93DF93EC01062F142F8170880FB6
-:1007D000880F880FE091A000F091A1008064099536
-:1007E000CE01892F99278695E091A000F091A10074
-:1007F0000995CE0196958795E091A000F091A10012
-:100800000995E091A000F091A100802F0995112396
-:10081000A9F00F3789F01EE102B7CE01A8DF8F37AC
-:1008200069F482B7801B8D3310F002B71150112389
-:10083000A1F781E090E004C08FE08CD080E090E0F0
-:10084000DF91CF911F910F9108950F931F93CF9335
-:10085000DF93EC01162FE091A000F091A1008CE451
-:100860000995CE01892F99278695E091A000F091F6
-:10087000A1000995CE0196958795E091A000F09191
-:10088000A1000995E091A000F091A10080E00995F8
-:100890001F3F89F01EE102B7CE0169DF8F3F69F487
-:1008A00082B7801B8D3310F002B711501123A1F7CE
-:1008B00081E090E004C08FE04DD080E090E0DF91D7
-:1008C000CF911F910F9108950F931F938C01E09189
-:1008D000A000F091A10080EA0995812F9927E0916D
-:1008E000A000F091A1000995E091A000F091A10075
-:1008F000802F0995E091A000F091A10080E009957A
-:1009000099271F910F910895FF920F931F938C01C8
-:10091000F62EE091A000F091A10080EC0995812FC6
-:100920009927E091A000F091A1000995E091A00025
-:10093000F091A100802F0995E091A000F091A10015
-:100940008F2D09958EE106D080E090E01F910F91E8
-:10095000FF900895382F20E0231740F492B782B714
-:10096000891B8C33E0F32F5F2317C0F308951F9387
-:10097000CF93DF93EC0110E089818130A1F08230C8
-:1009800009F489C0833009F489C0843091F087303C
-:1009900009F467C0853009F4C3C0863039F1883066
-:1009A00009F0C2C09DC09A9B812F54DE69DEA998D0
-:1009B000BBC08B819927982F88272A813327822BC8
-:1009C000932B90938600809385008F819927982F91
-:1009D00088272E813327822B932B90937B00809343
-:1009E0007A0082E080937C001FEF9EC08B81992764
-:1009F000982F88272A813327822B932B9093860068
-:100A0000809385008C81482F552750938800409310
-:100A100087002D812F70209389008D819927807FF9
-:100A2000907082959295907F9827807F9827840F69
-:100A3000951F909388008093870020FF04C08091C9
-:100A4000870080938A008F819927982F88272E818D
-:100A50003327822B932B90937B0080937A0081E045
-:100A6000C1CF8B819927982F88272A813327822B02
-:100A7000932B90938600809385008F819927982FE0
-:100A800088272E813327822B932B90937B00809392
-:100A90007A0083E0A7CF07DEA99A46C0E091A000C4
-:100AA000F091A1008A81099580937D00E091A000DA
-:100AB000F091A1008B81099580937E00E091A000C8
-:100AC000F091A1008C81099580937F00E091A000B6
-:100AD000F091A1008D8109958093800014E024C0DD
-:100AE0008B819927982F88272A813327822B932B54
-:100AF0009093860080938500109288001092870062
-:100B0000109389008F819927982F88272E8133276A
-:100B1000822B932B90937B0080937A0084E062CFAA
-:100B2000EDDD80937D0011E08DE790E090939B00D8
-:100B300080939A00812F9927DF91CF911F9108957B
-:100B4000EF92FF921F93CF937C01162F90917C0020
-:100B5000892F8250823050F5C0E0C617C0F01FC008
-:100B60008091850090918600AFDEF701EC0FF11DBA
-:100B700080838091850090918600019690938600F5
-:100B800080938500CF5FC11750F490917C00923024
-:100B900039F78091850090918600E9DDE6CF183025
-:100BA00010F410927C00812F992702C08FEF90E003
-:100BB000CF911F91FF90EF900895BF92CF92DF9257
-:100BC000EF92FF920F931F93CF93DF936C01E62E6A
-:100BD000BB2440917C00413019F0443009F080C0C2
-:100BE000FF24FE1408F079C0413009F049C080911B
-:100BF000870090918800892B09F04EC0CF2DDD270A
-:100C0000F601EC0FFD1F60818091850090918600B8
-:100C1000D6DD80917A0090917B00019790937B00C4
-:100C200080937A00892BD9F410927C0080918900FE
-:100C300081FF13C080918A00282F3327809187007D
-:100C4000909188002817390741F0CC0DDD1D68818F
-:100C50008091850090918600F8DDC1E0BC2E8091E6
-:100C60008500909186000196909386008093850080
-:100C7000F394FE1490F540917C00413009F4B7CF15
-:100C8000CF2DDD27F601EC0FFD1F608180918500DF
-:100C90009091860039DEBDCFCF2DDD2786010C0F68
-:100CA0001D1F40E0F80160818091850090918600D1
-:100CB00086DD80918A00815080938A00882309F024
-:100CC000A8CFF80160818091850090918600BDDDFC
-:100CD0008091870080938A009CCF8B2D992702C03A
-:100CE0008FEF90E0DF91CF911F910F91FF90EF90E8
-:100CF000DF90CF90BF900895CFE5D4E0DEBFCDBFA9
-:100D000012BA18BA8BEF81BB8FEF87BB90E091507E
-:100D1000F1F78150D9F787BB93E094BB8EEF85BB89
-:100D200093BF81E097DCDCDA7894C1D9C0D9FDCFDC
-:020D30005AFF68
-:00000001FF
diff --git a/bin/firmware/usbasp.atmega8.2007-07-23.hex b/bin/firmware/usbasp.atmega8.2007-07-23.hex
new file mode 100644 (file)
index 0000000..f4b4af4
--- /dev/null
@@ -0,0 +1,224 @@
+:100000003BC07AC153C052C051C050C04FC04EC057
+:100010004DC04CC04BC04AC049C048C047C046C094
+:1000200045C044C043C00902120001010080190903
+:10003000040000000000000012011001FF00000891
+:10004000C016DC050201010200010E035500530039
+:1000500042006100730070001C0377007700770096
+:100060002E00660069007300630068006C002E00BB
+:10007000640065000403090411241FBECFE5D4E029
+:10008000DEBFCDBF10E0A0E6B0E0E4EDFDE002C0D1
+:1000900005900D92A236B107D9F710E0A2E6B0E0C4
+:1000A00001C01D92A33AB107E1F778C6A9CF1F930B
+:1000B000CF93DF936091870016160CF58091840032
+:1000C000C7E9D0E0C81BD109635020E010E8809157
+:1000D00083008D3209F44CC08091620087FD09C015
+:1000E000CE019BD52FEF821709F470C0811120E05B
+:1000F00010E01093620020936100109287008091BD
+:10010000600084FF27C0809161008F3F19F1682F44
+:10011000893008F050C0861B809361001BE48091F9
+:10012000620080FD13EC8F5F80936200A8E7B0E06F
+:1001300087FD56C0662309F04EC060E070E0C62F10
+:100140006930D8F19EE18FEF8093610010937700C2
+:10015000909360009AE086B3837011F49150D9F7C0
+:10016000992309F0A1C090938800909382009CC0CD
+:100170008AE580936000683009F0BBCF8881807683
+:1001800009F048C040E850E020938000898188232E
+:1001900009F04CC02093810022E0509386004093E8
+:1001A00085008F81882309F0A4CF8E81821708F003
+:1001B000A0CF282F9ECF68E0AECF88E790E098D000
+:1001C0009C2F9C5FC83008F0C1CFBDCF8EE18093DB
+:1001D000600010E08ECFCD01D3D4682F7727AFCF4A
+:1001E000E0918500F091860086FF0DC0962F03C038
+:1001F00084918D9331969150D8F7F0938600E093D7
+:10020000850077279CCF962F02C081918D939150C6
+:10021000E0F7F3CFCE0184D3282F8F3F09F0C1CF71
+:10022000888187FF65CF2E8110E063CF853059F03C
+:10023000863069F08830D9F08930E9F08A3009F0E9
+:10024000B0CF21E0AACF8A8180938800AACF10EC9A
+:100250008B818130A1F08230F9F0833009F0A1CF99
+:100260008A81882381F444E750E024E096CF4AE86D
+:1002700050E021E092CF8A8180938A0092CF48E3B8
+:1002800050E022E18ACF813059F0823009F089CFE5
+:100290004AE450E02EE081CF46E250E022E17DCFFB
+:1002A00048E550E02CE179CFDF91CF911F9108957F
+:1002B00085B7836085BF8BB780648BBF0895A82FF7
+:1002C000B92F8FEF9FEF41E050EA615070F02D9110
+:1002D00038E0722F782796958795269570FF02C093
+:1002E000842795273A95A9F7F0CF809590950895A2
+:1002F000E6DF8D939D930895CF93CFB7CF93B09BB7
+:10030000FECFB09B09C0B09B07C0B09B05C0B09B9F
+:1003100003C0B09B01C09EC0DF93C0918400DD2765
+:10032000C557DF4FB09B02C0DF91EBCF2F930F93E8
+:100330001F9306B32FEF00FB20F94F933F9316B3A3
+:100340004FEF012700FB21F93BE031C04E7F012F29
+:1003500016B3216028C0102F4D7F2260000006B325
+:1003600029C04B7F2460012F000016B32BC016B3A9
+:10037000477F28602AC04F7E06B320612CC04F7D86
+:1003800016B320622FC04F7B06B3206432C04227D1
+:1003900006B349934FEF0000102710FB20F916B366
+:1003A0001370A9F1297F91F2012700FB21F906B30F
+:1003B000237F89F23150F0F1102710FB22F916B398
+:1003C000277E79F2012700FB23F92F7C81F206B307
+:1003D000102710FB24F92F7971F200C016B3012702
+:1003E00000FB25F92F7359F200C006B3102710FB4C
+:1003F00026F9223040F200C016B3012700FB27F98E
+:10040000243028F64F77206816B30000F9CF3B5010
+:100410003195333010E41ABFB8F0C31BD0400881C7
+:10042000033C41F10B3431F11981412F1F772091A9
+:100430008200121731F4093691F10D3279F0013E44
+:1004400069F02227209389003F914F911F910F91CE
+:100450002F91DF91CF91CFBFCF9118950093890055
+:100460003F914F911F910F912F91DF91CAB7C6FD18
+:1004700046CFF0CF00918900002331F3109187001F
+:10048000112349F534304AF13093870000938300FB
+:10049000109184003BE0311B309384001EC000911A
+:1004A00087000130C4F40AE53091600034FD17C0C4
+:1004B00000936000C7E7D0E016C0052710E008BB36
+:1004C0001FC0052722C0052727C005272CC00527E8
+:1004D00010E008BB33C04AE503C042ED01C0432F22
+:1004E000C4E1D0E032E017B31360C09A08B317BB81
+:1004F0005F9353E020E820FF052708BB2795179559
+:100500001C3FD8F620FF0527279508BB17951C3FF1
+:10051000C0F620FF05272795179508BB1C3F98F6C6
+:1005200020FF0527279517951C3F08BB70F600C0D4
+:10053000499120FF052708BB279517951C3F38F6E2
+:1005400020FF0527279508BB17951C3F38F520FF8E
+:1005500005272795179508BB1C3F10F520FF052799
+:10056000279517951C3F08BBE8F4242F3A9519F6F8
+:100570000C7F5F9108BB00C010918800C651D0402D
+:1005800011F01093820010E41ABF016017B31C7FB2
+:10059000402F4C7F08BB17BB48BB56CF0527D3CF96
+:1005A0000527D8CF0527DDCF82E58DB981E08EB94B
+:1005B0000895882339F48AE093E09093A200809311
+:1005C000A100089587E293E09093A2008093A10098
+:1005D000089592B782B7891B8C30E0F3089587B3F2
+:1005E0008C6287BBC298C598F4DFC29AF2DFC298CA
+:1005F0008091A1009091A2008752934009F0089544
+:10060000D3DF089587B3837D87BB88B3837D88BBA1
+:100610001DB808950F931F93CF93C82F00E017E0E4
+:100620000CC0C398CC0F000FB4990F5FC59AD1DFEF
+:10063000C598CFDF115017FD04C0C7FFF2CFC39A92
+:10064000F1CF802F9927CF911F910F9108958FB9E6
+:10065000779BFECF8FB1992708951F93CF93CFE15A
+:1006600003C0C150CF3F51F1E091A100F091A20031
+:100670008CEA0995E091A100F091A20083E509952B
+:10068000E091A100F091A20080E00995182FE0917F
+:10069000A100F091A20080E00995133591F01DB8FA
+:1006A000C59A97DFC59895DF8091A1009091A2002F
+:1006B00087529340B1F678DFC150B0F681E090E008
+:1006C00002C080E090E0CF911F910895EF92FF92D9
+:1006D0000F931F937B018C01862F8170880F880FE9
+:1006E000880FE091A100F091A20080620995D801E5
+:1006F000C70129E0B695A795979587952A95D1F7D3
+:10070000E091A100F091A200099516950795F79444
+:10071000E794E091A100F091A2008E2D0995E0915F
+:10072000A100F091A20080E0099599271F910F91F7
+:10073000FF90EF900895CF92DF92EF92FF921F9378
+:10074000CF936B017C01C42F122F862F8170880FED
+:10075000880F880FE091A100F091A20080640995B4
+:10076000D701C60149E0B695A795979587954A9513
+:10077000D1F7E091A100F091A2000995D701C6013F
+:10078000B695A79597958795E091A100F091A20065
+:100790000995E091A100F091A2008C2F09951123F9
+:1007A000B1F0CF3791F01EE1C2B7C701B6018EDFBD
+:1007B0008F3769F482B78C1B8D3310F0C2B711509C
+:1007C000112399F781E090E004C08FE09CD080E095
+:1007D00090E0CF911F91FF90EF90DF90CF90089520
+:1007E000CF92DF92EF92FF921F93CF936B017C0128
+:1007F000142FE091A100F091A2008CE40995D7019B
+:10080000C60169E0B695A795979587956A95D1F742
+:10081000E091A100F091A2000995D701C601B6951B
+:10082000A79597958795E091A100F091A200099571
+:10083000E091A100F091A20080E009951F3F91F0A6
+:100840001EE1C2B7C701B60141DF8F3F69F482B72D
+:100850008C1B8D3310F0C2B71150112399F781E032
+:1008600090E004C08FE04FD080E090E0CF911F91E6
+:10087000FF90EF90DF90CF9008950F931F938C011E
+:10088000E091A100F091A20080EA0995812F9927BB
+:10089000E091A100F091A2000995E091A100F091F2
+:1008A000A200802F0995E091A100F091A20080E0C4
+:1008B000099599271F910F910895FF920F931F9308
+:1008C0008C01F62EE091A100F091A20080EC099538
+:1008D000812F9927E091A100F091A2000995E09164
+:1008E000A100F091A200802F0995E091A100F09164
+:1008F000A2008F2D09958EE106D080E090E01F9137
+:100900000F91FF900895382F20E0231740F492B7FD
+:1009100082B7891B8C33E0F32F5F2317C0F3089550
+:100920001F93CF93DF93EC0110E089818130B9F000
+:10093000823009F49FC0833009F49FC08430B9F03D
+:10094000873009F471C0853009F4FAC08630C1F1EE
+:10095000883009F4C9C0893009F006C1F6C09A9BF5
+:10096000812F27DE109266003ADEA998FDC08091A3
+:1009700066008823A1F48B819927982F88272A81E4
+:100980003327822B932BAA2797FDA095BA2F80930C
+:100990006F0090937000A0937100B09372008F81EC
+:1009A0009927982F88272E813327822B932B90937A
+:1009B00064008093630082E0809365001FEFD4C0E1
+:1009C00080916600882309F47AC08C81482F5527CE
+:1009D00050937400409373002D812F702093750005
+:1009E0008D819927807F907082959295907F98272E
+:1009F000807F9827840F951F9093740080937300D5
+:100A000020FF04C080917300809376008F81992726
+:100A1000982F88272E813327822B932B9093640065
+:100A20008093630081E0C8CF809166008823A1F4A1
+:100A30008B819927982F88272A813327822B932B04
+:100A4000AA2797FDA095BA2F80936F00909370000E
+:100A5000A0937100B09372008F819927982F8827F7
+:100A60002E813327822B932B909364008093630015
+:100A700083E0A2CFC7DDA99A77C0E091A100F091F1
+:100A8000A2008A81099580936700E091A100F0910E
+:100A9000A2008B81099580936800E091A100F091FC
+:100AA000A2008C81099580936900E091A100F091EA
+:100AB000A2008D81099580936A0014E055C08B8156
+:100AC0009927982F88272A813327822B932BAA27AF
+:100AD00097FDA095BA2F80936F0090937000A0931C
+:100AE0007100B093720071CF809166008823A1F4E9
+:100AF0008B819927982F88272A813327822B932B44
+:100B0000AA2797FDA095BA2F80936F00909370004D
+:100B1000A0937100B0937200109274001092730051
+:100B2000109375008F819927982F88272E8133275E
+:100B3000822B932B909364008093630084E03CCFDE
+:100B40008CDD8093670011E00FC081E08093660028
+:100B50008A819B81AC81BD8180936F0090937000EE
+:100B6000A0937100B093720087E690E090938600A6
+:100B700080938500812F9927DF91CF911F91089550
+:100B8000EF92FF921F93CF937C01162F90916500F7
+:100B9000892F82508230D0F5C0E0C61710F12FC0E7
+:100BA00080916F009091700068DEF701EC0FF11DED
+:100BB000808380916F0090917000A0917100B0913E
+:100BC00072000196A11DB11D80936F00909370007B
+:100BD000A0937100B0937200CF5FC11780F4909121
+:100BE00065009230E9F680916F0090917000A091BD
+:100BF0007100B0917200BC01CD0168DDD6CF183014
+:100C000010F410926500812F992702C08FEF90E0B9
+:100C1000CF911F91FF90EF900895BF92CF92DF92F6
+:100C2000EF92FF920F931F93CF93DF936C01062FE8
+:100C3000BB2420916500213019F0243009F0A2C0B6
+:100C400010E0101708F09BC0213009F05FC08091C0
+:100C5000730090917400892B09F064C0C12FDD27C7
+:100C6000F601EC0FFD1F80916F0090917000A09134
+:100C70007100B09172004081BC01CD015CDD8091BA
+:100C800063009091640001979093640080936300E7
+:100C9000892B09F5109265008091750081FF19C0BC
+:100CA00080917600282F33278091730090917400F3
+:100CB0002817390771F0CC0DDD1D80916F009091E0
+:100CC0007000A0917100B09172004881BC01CD010B
+:100CD00087DDC1E0BC2E80916F0090917000A091E3
+:100CE0007100B09172000196A11DB11D80936F003B
+:100CF00090937000A0937100B09372001F5F101763
+:100D0000F0F520916500213009F4A1CFC12FDD2736
+:100D1000F601EC0FFD1F608180916F0090917000D3
+:100D2000CCDDADCFC12FDD277601EC0EFD1E80910D
+:100D30006F0090917000A0917100B091720020E05E
+:100D4000F7014081BC01CD01F6DC80917600815035
+:100D500080937600882309F092CF80916F00909164
+:100D60007000A0917100B0917200F7014081BC0148
+:100D7000CD0136DD809173008093760080CF8B2D7E
+:100D8000992702C08FEF90E0DF91CF911F910F91D3
+:100D9000FF90EF90DF90CF90BF900895CFE5D4E023
+:100DA000DEBFCDBF12BA18BA8BEF81BB8FEF87BB06
+:100DB00090E09150F1F78150D9F787BB93E094BB55
+:100DC0008EEF85BB93BF81E0F4DB72DA78946FD944
+:040DD0006ED9FDCF0C
+:020DD4005AFFC4
+:00000001FF
index 1397493..52138e5 100644 (file)
@@ -3,7 +3,7 @@
 
   Autor..........: Thomas Fischl <tfischl@gmx.de>
   Description....: Provides functions for timing/waiting
-  Licence........: Free under certain conditions. See Documentation.
+  Licence........: GNU GPL v2 (see Readme.txt)
   Creation Date..: 2005-02-23
   Last change....: 2005-04-20
 */
index a28e254..405fe2f 100644 (file)
@@ -3,7 +3,7 @@
 
   Autor..........: Thomas Fischl <tfischl@gmx.de>
   Description....: Provides functions for timing/waiting
-  Licence........: Free under certain conditions. See Documentation.
+  Licence........: GNU GPL v2 (see Readme.txt)
   Creation Date..: 2005-02-23
   Last change....: 2006-11-16
 */
index 1bd41d3..5153c8e 100644 (file)
@@ -4,9 +4,9 @@
   Autor..........: Thomas Fischl <tfischl@gmx.de>
   Description....: Provides functions for communication/programming
                    over ISP interface
-  Licence........: Free under certain conditions. See Documentation.
+  Licence........: GNU GPL v2 (see Readme.txt)
   Creation Date..: 2005-02-23
-  Last change....: 2005-04-20
+  Last change....: 2007-07-23
 */
 
 #include <avr/io.h>
@@ -145,7 +145,7 @@ uchar ispEnterProgrammingMode() {
   return 1;  /* error: device dosn't answer */
 }
 
-uchar ispReadFlash(unsigned int address) {
+uchar ispReadFlash(unsigned long address) {
   ispTransmit(0x20 | ((address & 1) << 3));
   ispTransmit(address >> 9);
   ispTransmit(address >> 1);
@@ -153,7 +153,7 @@ uchar ispReadFlash(unsigned int address) {
 }
 
 
-uchar ispWriteFlash(unsigned int address, uchar data, uchar pollmode) {
+uchar ispWriteFlash(unsigned long address, uchar data, uchar pollmode) {
 
   /* 0xFF is value after chip erase, so skip programming
   if (data == 0xFF) {
@@ -194,7 +194,7 @@ uchar ispWriteFlash(unsigned int address, uchar data, uchar pollmode) {
 }
 
 
-uchar ispFlushPage(unsigned int address, uchar pollvalue) {
+uchar ispFlushPage(unsigned long address, uchar pollvalue) {
   ispTransmit(0x4C);
   ispTransmit(address >> 9);
   ispTransmit(address >> 1);
index 7b83201..e3862e5 100644 (file)
@@ -4,9 +4,9 @@
   Autor..........: Thomas Fischl <tfischl@gmx.de>
   Description....: Provides functions for communication/programming
                    over ISP interface
-  Licence........: Free under certain conditions. See Documentation.
+  Licence........: GNU GPL v2 (see Readme.txt)
   Creation Date..: 2005-02-23
-  Last change....: 2005-04-20
+  Last change....: 2007-07-23
 */
 
 #ifndef __isp_h_included__
@@ -47,12 +47,12 @@ uchar ispEnterProgrammingMode();
 uchar ispReadEEPROM(unsigned int address);
 
 /* write byte to flash at given address */
-uchar ispWriteFlash(unsigned int address, uchar data, uchar pollmode);
+uchar ispWriteFlash(unsigned long address, uchar data, uchar pollmode);
 
-uchar ispFlushPage(unsigned int address, uchar pollvalue);
+uchar ispFlushPage(unsigned long address, uchar pollvalue);
 
 /* read byte from flash at given address */
-uchar ispReadFlash(unsigned int address);
+uchar ispReadFlash(unsigned long address);
 
 /* write byte to eeprom at given address */
 uchar ispWriteEEPROM(unsigned int address, uchar data);
index 588a10e..0197ebc 100644 (file)
@@ -3,14 +3,10 @@
 
   Thomas Fischl <tfischl@gmx.de>
 
-  License:
-  The project is built with AVR USB driver by Objective Development, which is
-  published under an own licence based on the GNU General Public License (GPL).
-  USBasp is also distributed under this enhanced licence. See Documentation.
-
+  License........: GNU GPL v2 (see Readme.txt)
   Target.........: ATMega8 at 12 MHz
   Creation Date..: 2005-02-20
-  Last change....: 2006-12-29
+  Last change....: 2007-07-23
 
   PC2 SCK speed option. GND  -> slow (8khz SCK),
                         open -> fast (375kHz SCK)
@@ -33,6 +29,7 @@
 #define USBASP_FUNC_WRITEFLASH  6
 #define USBASP_FUNC_READEEPROM  7
 #define USBASP_FUNC_WRITEEEPROM 8
+#define USBASP_FUNC_SETLONGADDRESS 9
 
 #define PROG_STATE_IDLE         0
 #define PROG_STATE_WRITEFLASH   1
@@ -52,9 +49,10 @@ static uchar replyBuffer[8];
 
 static uchar prog_state = PROG_STATE_IDLE;
 
-static unsigned int prog_address;
+static uchar prog_address_newmode = 0;
+static unsigned long prog_address;
 static unsigned int prog_nbytes = 0;
-static unsigned int prog_pagesize; //TP: Mega128 fix
+static unsigned int prog_pagesize;
 static uchar prog_blockflags;
 static uchar prog_pagecounter;
 
@@ -72,6 +70,9 @@ uchar usbFunctionSetup(uchar data[8]) {
       ispSetSCKOption(ISP_SCK_FAST);
     }
 
+    /* set compatibility mode of address delivering */
+    prog_address_newmode = 0;
+
     ispConnect();
     ledRedOn();
 
@@ -87,13 +88,19 @@ uchar usbFunctionSetup(uchar data[8]) {
     len = 4;
 
   } else if (data[1] == USBASP_FUNC_READFLASH) {
-    prog_address = (data[3] << 8) | data[2];
+
+    if (!prog_address_newmode)
+      prog_address = (data[3] << 8) | data[2];
+
     prog_nbytes = (data[7] << 8) | data[6];
     prog_state = PROG_STATE_READFLASH;
     len = 0xff; /* multiple in */
 
   } else if (data[1] == USBASP_FUNC_READEEPROM) {
-    prog_address = (data[3] << 8) | data[2];
+
+    if (!prog_address_newmode)
+       prog_address = (data[3] << 8) | data[2];
+
     prog_nbytes = (data[7] << 8) | data[6];
     prog_state = PROG_STATE_READEEPROM;
     len = 0xff; /* multiple in */
@@ -103,10 +110,13 @@ uchar usbFunctionSetup(uchar data[8]) {
     len = 1;
 
   } else if (data[1] == USBASP_FUNC_WRITEFLASH) {
-    prog_address = (data[3] << 8) | data[2];
+
+    if (!prog_address_newmode)
+      prog_address = (data[3] << 8) | data[2];
+
     prog_pagesize = data[4];
     prog_blockflags = data[5] & 0x0F;
-    prog_pagesize += (((unsigned int)data[5] & 0xF0)<<4); //TP: Mega128 fix
+    prog_pagesize += (((unsigned int)data[5] & 0xF0)<<4);
     if (prog_blockflags & PROG_BLOCKFLAG_FIRST) {
       prog_pagecounter = prog_pagesize;
     }
@@ -115,12 +125,22 @@ uchar usbFunctionSetup(uchar data[8]) {
     len = 0xff; /* multiple out */
 
   } else if (data[1] == USBASP_FUNC_WRITEEEPROM) {
-    prog_address = (data[3] << 8) | data[2];
+
+    if (!prog_address_newmode)
+      prog_address = (data[3] << 8) | data[2];
+
     prog_pagesize = 0;
     prog_blockflags = 0;
     prog_nbytes = (data[7] << 8) | data[6];
     prog_state = PROG_STATE_WRITEEEPROM;
     len = 0xff; /* multiple out */
+
+  } else if(data[1] == USBASP_FUNC_SETLONGADDRESS) {
+
+    /* set new mode of address delivering (ignore address delivered in commands) */
+    prog_address_newmode = 1;
+    /* set new address */
+    prog_address = *((unsigned long*)&data[2]);
   }
 
   usbMsgPtr = replyBuffer;
diff --git a/firmware/main.hex b/firmware/main.hex
new file mode 100644 (file)
index 0000000..f4b4af4
--- /dev/null
@@ -0,0 +1,224 @@
+:100000003BC07AC153C052C051C050C04FC04EC057
+:100010004DC04CC04BC04AC049C048C047C046C094
+:1000200045C044C043C00902120001010080190903
+:10003000040000000000000012011001FF00000891
+:10004000C016DC050201010200010E035500530039
+:1000500042006100730070001C0377007700770096
+:100060002E00660069007300630068006C002E00BB
+:10007000640065000403090411241FBECFE5D4E029
+:10008000DEBFCDBF10E0A0E6B0E0E4EDFDE002C0D1
+:1000900005900D92A236B107D9F710E0A2E6B0E0C4
+:1000A00001C01D92A33AB107E1F778C6A9CF1F930B
+:1000B000CF93DF936091870016160CF58091840032
+:1000C000C7E9D0E0C81BD109635020E010E8809157
+:1000D00083008D3209F44CC08091620087FD09C015
+:1000E000CE019BD52FEF821709F470C0811120E05B
+:1000F00010E01093620020936100109287008091BD
+:10010000600084FF27C0809161008F3F19F1682F44
+:10011000893008F050C0861B809361001BE48091F9
+:10012000620080FD13EC8F5F80936200A8E7B0E06F
+:1001300087FD56C0662309F04EC060E070E0C62F10
+:100140006930D8F19EE18FEF8093610010937700C2
+:10015000909360009AE086B3837011F49150D9F7C0
+:10016000992309F0A1C090938800909382009CC0CD
+:100170008AE580936000683009F0BBCF8881807683
+:1001800009F048C040E850E020938000898188232E
+:1001900009F04CC02093810022E0509386004093E8
+:1001A00085008F81882309F0A4CF8E81821708F003
+:1001B000A0CF282F9ECF68E0AECF88E790E098D000
+:1001C0009C2F9C5FC83008F0C1CFBDCF8EE18093DB
+:1001D000600010E08ECFCD01D3D4682F7727AFCF4A
+:1001E000E0918500F091860086FF0DC0962F03C038
+:1001F00084918D9331969150D8F7F0938600E093D7
+:10020000850077279CCF962F02C081918D939150C6
+:10021000E0F7F3CFCE0184D3282F8F3F09F0C1CF71
+:10022000888187FF65CF2E8110E063CF853059F03C
+:10023000863069F08830D9F08930E9F08A3009F0E9
+:10024000B0CF21E0AACF8A8180938800AACF10EC9A
+:100250008B818130A1F08230F9F0833009F0A1CF99
+:100260008A81882381F444E750E024E096CF4AE86D
+:1002700050E021E092CF8A8180938A0092CF48E3B8
+:1002800050E022E18ACF813059F0823009F089CFE5
+:100290004AE450E02EE081CF46E250E022E17DCFFB
+:1002A00048E550E02CE179CFDF91CF911F9108957F
+:1002B00085B7836085BF8BB780648BBF0895A82FF7
+:1002C000B92F8FEF9FEF41E050EA615070F02D9110
+:1002D00038E0722F782796958795269570FF02C093
+:1002E000842795273A95A9F7F0CF809590950895A2
+:1002F000E6DF8D939D930895CF93CFB7CF93B09BB7
+:10030000FECFB09B09C0B09B07C0B09B05C0B09B9F
+:1003100003C0B09B01C09EC0DF93C0918400DD2765
+:10032000C557DF4FB09B02C0DF91EBCF2F930F93E8
+:100330001F9306B32FEF00FB20F94F933F9316B3A3
+:100340004FEF012700FB21F93BE031C04E7F012F29
+:1003500016B3216028C0102F4D7F2260000006B325
+:1003600029C04B7F2460012F000016B32BC016B3A9
+:10037000477F28602AC04F7E06B320612CC04F7D86
+:1003800016B320622FC04F7B06B3206432C04227D1
+:1003900006B349934FEF0000102710FB20F916B366
+:1003A0001370A9F1297F91F2012700FB21F906B30F
+:1003B000237F89F23150F0F1102710FB22F916B398
+:1003C000277E79F2012700FB23F92F7C81F206B307
+:1003D000102710FB24F92F7971F200C016B3012702
+:1003E00000FB25F92F7359F200C006B3102710FB4C
+:1003F00026F9223040F200C016B3012700FB27F98E
+:10040000243028F64F77206816B30000F9CF3B5010
+:100410003195333010E41ABFB8F0C31BD0400881C7
+:10042000033C41F10B3431F11981412F1F772091A9
+:100430008200121731F4093691F10D3279F0013E44
+:1004400069F02227209389003F914F911F910F91CE
+:100450002F91DF91CF91CFBFCF9118950093890055
+:100460003F914F911F910F912F91DF91CAB7C6FD18
+:1004700046CFF0CF00918900002331F3109187001F
+:10048000112349F534304AF13093870000938300FB
+:10049000109184003BE0311B309384001EC000911A
+:1004A00087000130C4F40AE53091600034FD17C0C4
+:1004B00000936000C7E7D0E016C0052710E008BB36
+:1004C0001FC0052722C0052727C005272CC00527E8
+:1004D00010E008BB33C04AE503C042ED01C0432F22
+:1004E000C4E1D0E032E017B31360C09A08B317BB81
+:1004F0005F9353E020E820FF052708BB2795179559
+:100500001C3FD8F620FF0527279508BB17951C3FF1
+:10051000C0F620FF05272795179508BB1C3F98F6C6
+:1005200020FF0527279517951C3F08BB70F600C0D4
+:10053000499120FF052708BB279517951C3F38F6E2
+:1005400020FF0527279508BB17951C3F38F520FF8E
+:1005500005272795179508BB1C3F10F520FF052799
+:10056000279517951C3F08BBE8F4242F3A9519F6F8
+:100570000C7F5F9108BB00C010918800C651D0402D
+:1005800011F01093820010E41ABF016017B31C7FB2
+:10059000402F4C7F08BB17BB48BB56CF0527D3CF96
+:1005A0000527D8CF0527DDCF82E58DB981E08EB94B
+:1005B0000895882339F48AE093E09093A200809311
+:1005C000A100089587E293E09093A2008093A10098
+:1005D000089592B782B7891B8C30E0F3089587B3F2
+:1005E0008C6287BBC298C598F4DFC29AF2DFC298CA
+:1005F0008091A1009091A2008752934009F0089544
+:10060000D3DF089587B3837D87BB88B3837D88BBA1
+:100610001DB808950F931F93CF93C82F00E017E0E4
+:100620000CC0C398CC0F000FB4990F5FC59AD1DFEF
+:10063000C598CFDF115017FD04C0C7FFF2CFC39A92
+:10064000F1CF802F9927CF911F910F9108958FB9E6
+:10065000779BFECF8FB1992708951F93CF93CFE15A
+:1006600003C0C150CF3F51F1E091A100F091A20031
+:100670008CEA0995E091A100F091A20083E509952B
+:10068000E091A100F091A20080E00995182FE0917F
+:10069000A100F091A20080E00995133591F01DB8FA
+:1006A000C59A97DFC59895DF8091A1009091A2002F
+:1006B00087529340B1F678DFC150B0F681E090E008
+:1006C00002C080E090E0CF911F910895EF92FF92D9
+:1006D0000F931F937B018C01862F8170880F880FE9
+:1006E000880FE091A100F091A20080620995D801E5
+:1006F000C70129E0B695A795979587952A95D1F7D3
+:10070000E091A100F091A200099516950795F79444
+:10071000E794E091A100F091A2008E2D0995E0915F
+:10072000A100F091A20080E0099599271F910F91F7
+:10073000FF90EF900895CF92DF92EF92FF921F9378
+:10074000CF936B017C01C42F122F862F8170880FED
+:10075000880F880FE091A100F091A20080640995B4
+:10076000D701C60149E0B695A795979587954A9513
+:10077000D1F7E091A100F091A2000995D701C6013F
+:10078000B695A79597958795E091A100F091A20065
+:100790000995E091A100F091A2008C2F09951123F9
+:1007A000B1F0CF3791F01EE1C2B7C701B6018EDFBD
+:1007B0008F3769F482B78C1B8D3310F0C2B711509C
+:1007C000112399F781E090E004C08FE09CD080E095
+:1007D00090E0CF911F91FF90EF90DF90CF90089520
+:1007E000CF92DF92EF92FF921F93CF936B017C0128
+:1007F000142FE091A100F091A2008CE40995D7019B
+:10080000C60169E0B695A795979587956A95D1F742
+:10081000E091A100F091A2000995D701C601B6951B
+:10082000A79597958795E091A100F091A200099571
+:10083000E091A100F091A20080E009951F3F91F0A6
+:100840001EE1C2B7C701B60141DF8F3F69F482B72D
+:100850008C1B8D3310F0C2B71150112399F781E032
+:1008600090E004C08FE04FD080E090E0CF911F91E6
+:10087000FF90EF90DF90CF9008950F931F938C011E
+:10088000E091A100F091A20080EA0995812F9927BB
+:10089000E091A100F091A2000995E091A100F091F2
+:1008A000A200802F0995E091A100F091A20080E0C4
+:1008B000099599271F910F910895FF920F931F9308
+:1008C0008C01F62EE091A100F091A20080EC099538
+:1008D000812F9927E091A100F091A2000995E09164
+:1008E000A100F091A200802F0995E091A100F09164
+:1008F000A2008F2D09958EE106D080E090E01F9137
+:100900000F91FF900895382F20E0231740F492B7FD
+:1009100082B7891B8C33E0F32F5F2317C0F3089550
+:100920001F93CF93DF93EC0110E089818130B9F000
+:10093000823009F49FC0833009F49FC08430B9F03D
+:10094000873009F471C0853009F4FAC08630C1F1EE
+:10095000883009F4C9C0893009F006C1F6C09A9BF5
+:10096000812F27DE109266003ADEA998FDC08091A3
+:1009700066008823A1F48B819927982F88272A81E4
+:100980003327822B932BAA2797FDA095BA2F80930C
+:100990006F0090937000A0937100B09372008F81EC
+:1009A0009927982F88272E813327822B932B90937A
+:1009B00064008093630082E0809365001FEFD4C0E1
+:1009C00080916600882309F47AC08C81482F5527CE
+:1009D00050937400409373002D812F702093750005
+:1009E0008D819927807F907082959295907F98272E
+:1009F000807F9827840F951F9093740080937300D5
+:100A000020FF04C080917300809376008F81992726
+:100A1000982F88272E813327822B932B9093640065
+:100A20008093630081E0C8CF809166008823A1F4A1
+:100A30008B819927982F88272A813327822B932B04
+:100A4000AA2797FDA095BA2F80936F00909370000E
+:100A5000A0937100B09372008F819927982F8827F7
+:100A60002E813327822B932B909364008093630015
+:100A700083E0A2CFC7DDA99A77C0E091A100F091F1
+:100A8000A2008A81099580936700E091A100F0910E
+:100A9000A2008B81099580936800E091A100F091FC
+:100AA000A2008C81099580936900E091A100F091EA
+:100AB000A2008D81099580936A0014E055C08B8156
+:100AC0009927982F88272A813327822B932BAA27AF
+:100AD00097FDA095BA2F80936F0090937000A0931C
+:100AE0007100B093720071CF809166008823A1F4E9
+:100AF0008B819927982F88272A813327822B932B44
+:100B0000AA2797FDA095BA2F80936F00909370004D
+:100B1000A0937100B0937200109274001092730051
+:100B2000109375008F819927982F88272E8133275E
+:100B3000822B932B909364008093630084E03CCFDE
+:100B40008CDD8093670011E00FC081E08093660028
+:100B50008A819B81AC81BD8180936F0090937000EE
+:100B6000A0937100B093720087E690E090938600A6
+:100B700080938500812F9927DF91CF911F91089550
+:100B8000EF92FF921F93CF937C01162F90916500F7
+:100B9000892F82508230D0F5C0E0C61710F12FC0E7
+:100BA00080916F009091700068DEF701EC0FF11DED
+:100BB000808380916F0090917000A0917100B0913E
+:100BC00072000196A11DB11D80936F00909370007B
+:100BD000A0937100B0937200CF5FC11780F4909121
+:100BE00065009230E9F680916F0090917000A091BD
+:100BF0007100B0917200BC01CD0168DDD6CF183014
+:100C000010F410926500812F992702C08FEF90E0B9
+:100C1000CF911F91FF90EF900895BF92CF92DF92F6
+:100C2000EF92FF920F931F93CF93DF936C01062FE8
+:100C3000BB2420916500213019F0243009F0A2C0B6
+:100C400010E0101708F09BC0213009F05FC08091C0
+:100C5000730090917400892B09F064C0C12FDD27C7
+:100C6000F601EC0FFD1F80916F0090917000A09134
+:100C70007100B09172004081BC01CD015CDD8091BA
+:100C800063009091640001979093640080936300E7
+:100C9000892B09F5109265008091750081FF19C0BC
+:100CA00080917600282F33278091730090917400F3
+:100CB0002817390771F0CC0DDD1D80916F009091E0
+:100CC0007000A0917100B09172004881BC01CD010B
+:100CD00087DDC1E0BC2E80916F0090917000A091E3
+:100CE0007100B09172000196A11DB11D80936F003B
+:100CF00090937000A0937100B09372001F5F101763
+:100D0000F0F520916500213009F4A1CFC12FDD2736
+:100D1000F601EC0FFD1F608180916F0090917000D3
+:100D2000CCDDADCFC12FDD277601EC0EFD1E80910D
+:100D30006F0090917000A0917100B091720020E05E
+:100D4000F7014081BC01CD01F6DC80917600815035
+:100D500080937600882309F092CF80916F00909164
+:100D60007000A0917100B0917200F7014081BC0148
+:100D7000CD0136DD809173008093760080CF8B2D7E
+:100D8000992702C08FEF90E0DF91CF911F910F91D3
+:100D9000FF90EF90DF90CF90BF900895CFE5D4E023
+:100DA000DEBFCDBF12BA18BA8BEF81BB8FEF87BB06
+:100DB00090E09150F1F78150D9F787BB93E094BB55
+:100DC0008EEF85BB93BF81E0F4DB72DA78946FD944
+:040DD0006ED9FDCF0C
+:020DD4005AFFC4
+:00000001FF
index 8a1ebd0..7170def 100644 (file)
@@ -1,11 +1,10 @@
 /* Name: usbconfig.h
  * Project: AVR USB driver
- * Author: Christian Starkjohann
+ * Author: Christian Starkjohann, Thomas Fischl
  * Creation Date: 2005-04-01
  * Tabsize: 4
  * Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH
- * License: Proprietary, free under certain conditions. See Documentation.
- * This Revision: $Id: usbconfig.h 43 2005-04-10 21:04:36Z cs $
+ * License: GNU GPL v2 (see License.txt) or proprietary (CommercialLicense.txt)
  */
 
 #ifndef __usbconfig_h_included__
@@ -25,29 +24,37 @@ the newest features and options.
 
 #define USB_CFG_IOPORTNAME      B
 /* This is the port where the USB bus is connected. When you configure it to
- * "PORTB", the registers PORTB, PINB (=PORTB-2) and DDRB (=PORTB-1) will be
- * used.
+ * "B", the registers PORTB, PINB and DDRB will be used.
  */
 #define USB_CFG_DMINUS_BIT      0
 /* This is the bit number in USB_CFG_IOPORT where the USB D- line is connected.
- * This MUST be bit 0 or 7. All other values will result in a compile error!
+ * This may be any bit in the port.
  */
 #define USB_CFG_DPLUS_BIT       1
 /* This is the bit number in USB_CFG_IOPORT where the USB D+ line is connected.
  * This may be any bit in the port. Please note that D+ must also be connected
  * to interrupt pin INT0!
  */
+/* #define USB_CFG_CLOCK_KHZ       (F_CPU/1000) */
+/* Clock rate of the AVR in MHz. Legal values are 12000, 16000 or 16500.
+ * The 16.5 MHz version of the code requires no crystal, it tolerates +/- 1%
+ * deviation from the nominal frequency. All other rates require a precision
+ * of 2000 ppm and thus a crystal!
+ * Default if not specified: 12 MHz
+ */
+
+/* ----------------------- Optional Hardware Config ------------------------ */
 
-/* #define USB_CFG_PULLUP_IOPORTNAME   B */
-/* This is the port where the USB D- pullup resistor is connected. When you
- * configure it to "PORTB", the registers PORTB and DDRB (=PORTB-1) will be
- * used. If this constant is defined, the macros usbDeviceConnect() and
- * usbDeviceDisconnect will be available.
+/* #define USB_CFG_PULLUP_IOPORTNAME   D */
+/* If you connect the 1.5k pullup resistor from D- to a port pin instead of
+ * V+, you can connect and disconnect the device from firmware by calling
+ * the macros usbDeviceConnect() and usbDeviceDisconnect() (see usbdrv.h).
+ * This constant defines the port on which the pullup resistor is connected.
  */
-/* #define USB_CFG_PULLUP_BIT          2 */
-/* This is the bit number in USB_CFG_PULLUP_IOPORT where the USB D- 1.5 kOhm
- * pullup resistor is connected instead of VBUS. This may be any bit in
- * the port.
+/* #define USB_CFG_PULLUP_BIT          4 */
+/* This constant defines the bit number in USB_CFG_PULLUP_IOPORT (defined
+ * above) where the 1.5k pullup resistor is connected. See description
+ * above for details.
  */
 
 /* --------------------------- Functional Range ---------------------------- */
@@ -56,6 +63,11 @@ the newest features and options.
 /* Define this to 1 if you want to compile a version with two endpoints: The
  * default control endpoint 0 and an interrupt-in endpoint 1.
  */
+#define USB_CFG_HAVE_INTRIN_ENDPOINT3   0
+/* Define this to 1 if you want to compile a version with three endpoints: The
+ * default control endpoint 0, an interrupt-in endpoint 1 and an interrupt-in
+ * endpoint 3. You must also enable endpoint 1 above.
+ */
 #define USB_CFG_IMPLEMENT_HALT          0
 /* Define this to 1 if you also want to implement the ENDPOINT_HALT feature
  * for endpoint 1 (interrupt endpoint). Although you may not need this feature,
@@ -76,15 +88,6 @@ the newest features and options.
  * The value is in milliamperes. [It will be divided by two since USB
  * communicates power requirements in units of 2 mA.]
  */
-#define USB_CFG_SAMPLE_EXACT            1
-/* This variable affects Sampling Jitter for USB receiving. When it is 0, the
- * driver guarantees a sampling window of 1/2 bit. The USB spec requires
- * that the receiver has at most 1/4 bit sampling window. The 1/2 bit window
- * should still work reliably enough because we work at low speed. If you want
- * to meet the spec, set this value to 1. This will unroll a loop which
- * results in bigger code size.
- * If you have problems with long cables, try setting this value to 1.
- */
 #define USB_CFG_IMPLEMENT_FN_WRITE      1
 /* Set this to 1 if you want usbFunctionWrite() to be called for control-out
  * transfers. Set it to 0 if you don't need it and want to save a couple of
@@ -96,6 +99,16 @@ the newest features and options.
  * data from a static buffer, set it to 0 and return the data from
  * usbFunctionSetup(). This saves a couple of bytes.
  */
+#define USB_CFG_IMPLEMENT_FN_WRITEOUT   0
+/* Define this to 1 if you want to use interrupt-out (or bulk out) endpoint 1.
+ * You must implement the function usbFunctionWriteOut() which receives all
+ * interrupt/bulk data sent to endpoint 1.
+ */
+#define USB_CFG_HAVE_FLOWCONTROL        0
+/* Define this to 1 if you want flowcontrol over USB data. See the definition
+ * of the macros usbDisableAllRequests() and usbEnableAllRequests() in
+ * usbdrv.h.
+ */
 
 /* -------------------------- Device Description --------------------------- */
 
@@ -111,7 +124,7 @@ the newest features and options.
  * you use obdev's free shared VID/PID pair. Be sure to read the rules in
  * USBID-License.txt!
  */
-#define USB_CFG_DEVICE_VERSION  0x01, 0x01
+#define USB_CFG_DEVICE_VERSION  0x02, 0x01
 /* Version number of the device: Minor number first, then major number.
  */
 #define        USB_CFG_VENDOR_NAME     'w', 'w', 'w', '.', 'f', 'i', 's', 'c', 'h', 'l', '.', 'd', 'e'
@@ -129,21 +142,14 @@ the newest features and options.
 /* Same as above for the device name. If you don't want a device name, undefine
  * the macros. See the file USBID-License.txt before you assign a name.
  */
-#define USB_CFG_SERIAL_NUMBER_LENGTH  0
-/* Set this define to the number of charcters in the serial number if your
- * device should have a serial number to uniquely identify each hardware
- * instance. You must supply the serial number in a string descriptor with the
- * name "usbCfgSerialNumberStringDescriptor", e.g.:
- * #define USB_CFG_SERIAL_NUMBER_LENGTH  5
- * int usbCfgSerialNumberStringDescriptor[] PROGMEM = {
- *     USB_STRING_DESCRIPTOR_HEADER(USB_CFG_SERIAL_NUMBER_LENGTH),
- *     '1', '2', '3', '4', '5'
- * };
- * See usbdrv.h for more information about the USB_STRING_DESCRIPTOR_HEADER()
- * macro or usbdrv.c for example string descriptors.
- * You may want to put "usbCfgSerialNumberStringDescriptor" at a constant
- * flash memory address (with magic linker commands) so that you don't need
- * to recompile if you change it.
+/*#define USB_CFG_SERIAL_NUMBER   'N', 'o', 'n', 'e' */
+/*#define USB_CFG_SERIAL_NUMBER_LEN   0 */
+/* Same as above for the serial number. If you don't want a serial number,
+ * undefine the macros.
+ * It may be useful to provide the serial number through other means than at
+ * compile time. See the section about descriptor properties below for how
+ * to fine tune control over USB descriptors such as the string descriptor
+ * for the serial number.
  */
 #define USB_CFG_DEVICE_CLASS    0xff
 #define USB_CFG_DEVICE_SUBCLASS 0
@@ -160,4 +166,75 @@ the newest features and options.
  * an HID device. Otherwise don't define it or define it to 0.
  */
 
+/* ------------------- Fine Control over USB Descriptors ------------------- */
+/* If you don't want to use the driver's default USB descriptors, you can
+ * provide our own. These can be provided as (1) fixed length static data in
+ * flash memory, (2) fixed length static data in RAM or (3) dynamically at
+ * runtime in the function usbFunctionDescriptor(). See usbdrv.h for more
+ * information about this function.
+ * Descriptor handling is configured through the descriptor's properties. If
+ * no properties are defined or if they are 0, the default descriptor is used.
+ * Possible properties are:
+ *   + USB_PROP_IS_DYNAMIC: The data for the descriptor should be fetched
+ *     at runtime via usbFunctionDescriptor().
+ *   + USB_PROP_IS_RAM: The data returned by usbFunctionDescriptor() or found
+ *     in static memory is in RAM, not in flash memory.
+ *   + USB_PROP_LENGTH(len): If the data is in static memory (RAM or flash),
+ *     the driver must know the descriptor's length. The descriptor itself is
+ *     found at the address of a well known identifier (see below).
+ * List of static descriptor names (must be declared PROGMEM if in flash):
+ *   char usbDescriptorDevice[];
+ *   char usbDescriptorConfiguration[];
+ *   char usbDescriptorHidReport[];
+ *   char usbDescriptorString0[];
+ *   int usbDescriptorStringVendor[];
+ *   int usbDescriptorStringDevice[];
+ *   int usbDescriptorStringSerialNumber[];
+ * Other descriptors can't be provided statically, they must be provided
+ * dynamically at runtime.
+ *
+ * Descriptor properties are or-ed or added together, e.g.:
+ * #define USB_CFG_DESCR_PROPS_DEVICE   (USB_PROP_IS_RAM | USB_PROP_LENGTH(18))
+ *
+ * The following descriptors are defined:
+ *   USB_CFG_DESCR_PROPS_DEVICE
+ *   USB_CFG_DESCR_PROPS_CONFIGURATION
+ *   USB_CFG_DESCR_PROPS_STRINGS
+ *   USB_CFG_DESCR_PROPS_STRING_0
+ *   USB_CFG_DESCR_PROPS_STRING_VENDOR
+ *   USB_CFG_DESCR_PROPS_STRING_PRODUCT
+ *   USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER
+ *   USB_CFG_DESCR_PROPS_HID
+ *   USB_CFG_DESCR_PROPS_HID_REPORT
+ *   USB_CFG_DESCR_PROPS_UNKNOWN (for all descriptors not handled by the driver)
+ *
+ */
+
+#define USB_CFG_DESCR_PROPS_DEVICE                  0
+#define USB_CFG_DESCR_PROPS_CONFIGURATION           0
+#define USB_CFG_DESCR_PROPS_STRINGS                 0
+#define USB_CFG_DESCR_PROPS_STRING_0                0
+#define USB_CFG_DESCR_PROPS_STRING_VENDOR           0
+#define USB_CFG_DESCR_PROPS_STRING_PRODUCT          0
+#define USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER    0
+#define USB_CFG_DESCR_PROPS_HID                     0
+#define USB_CFG_DESCR_PROPS_HID_REPORT              0
+#define USB_CFG_DESCR_PROPS_UNKNOWN                 0
+
+/* ----------------------- Optional MCU Description ------------------------ */
+
+/* The following configurations have working defaults in usbdrv.h. You
+ * usually don't need to set them explicitly. Only if you want to run
+ * the driver on a device which is not yet supported or with a compiler
+ * which is not fully supported (such as IAR C) or if you use a differnt
+ * interrupt than INT0, you may have to define some of these.
+ */
+/* #define USB_INTR_CFG            MCUCR */
+/* #define USB_INTR_CFG_SET        ((1 << ISC00) | (1 << ISC01)) */
+/* #define USB_INTR_CFG_CLR        0 */
+/* #define USB_INTR_ENABLE         GIMSK */
+/* #define USB_INTR_ENABLE_BIT     INT0 */
+/* #define USB_INTR_PENDING        GIFR */
+/* #define USB_INTR_PENDING_BIT    INTF0 */
+
 #endif /* __usbconfig_h_included__ */
index fa381ca..0e9e8bf 100644 (file)
@@ -113,3 +113,40 @@ Scroll down to the bottom to see the most recent changes.
     application code to reset data toggling on interrupt pipes.
 
 * Release 2006-07-18
+
+  - Added an #if !defined __ASSEMBLER__ to the warning in usbdrv.h. This fixes
+    an assembler error.
+  - usbDeviceDisconnect() takes pull-up resistor to high impedance now.
+
+* Release 2007-02-01
+
+  - Merged in some code size improvements from usbtiny (thanks to Dick
+    Streefland for these optimizations!)
+  - Special alignment requirement for usbRxBuf not required any more. Thanks
+    again to Dick Streefland for this hint!
+  - Reverted to "#warning" instead of unused static variables -- new versions
+    of IAR CC should handle this directive.
+  - Changed Open Source license to GNU GPL v2 in order to make linking against
+    other free libraries easier. We no longer require publication of the
+    circuit diagrams, but we STRONGLY encourage it. If you improve the driver
+    itself, PLEASE grant us a royalty free license to your changes for our
+    commercial license.
+
+* Release 2007-03-29
+
+  - New configuration option "USB_PUBLIC" in usbconfig.h.
+  - Set USB version number to 1.10 instead of 1.01.
+  - Code used USB_CFG_DESCR_PROPS_STRING_DEVICE and
+    USB_CFG_DESCR_PROPS_STRING_PRODUCT inconsistently. Changed all occurrences
+    to USB_CFG_DESCR_PROPS_STRING_PRODUCT.
+  - New assembler module for 16.5 MHz RC oscillator clock with PLL in receiver
+    code.
+  - New assembler module for 16 MHz crystal.
+  - usbdrvasm.S contains common code only, clock-specific parts have been moved
+    to usbdrvasm12.S, usbdrvasm16.S and usbdrvasm165.S respectively.
+
+* Release 2007-06-25
+
+  - 16 MHz module: Do SE0 check in stuffed bits as well.
+
+* Release 2007-07-07
diff --git a/firmware/usbdrv/CommercialLicense.txt b/firmware/usbdrv/CommercialLicense.txt
new file mode 100644 (file)
index 0000000..1e4ae0b
--- /dev/null
@@ -0,0 +1,154 @@
+AVR-USB Driver Software License Agreement
+Version 2006-07-24
+
+THIS LICENSE AGREEMENT GRANTS YOU CERTAIN RIGHTS IN A SOFTWARE. YOU CAN
+ENTER INTO THIS AGREEMENT AND ACQUIRE THE RIGHTS OUTLINED BELOW BY PAYING
+THE AMOUNT ACCORDING TO SECTION 4 ("PAYMENT") TO OBJECTIVE DEVELOPMENT.
+
+
+1 DEFINITIONS
+
+1.1 "OBJECTIVE DEVELOPMENT" shall mean OBJECTIVE DEVELOPMENT Software GmbH,
+Grosse Schiffgasse 1A/7, 1020 Wien, AUSTRIA.
+
+1.2 "You" shall mean the Licensee.
+
+1.3 "AVR-USB" shall mean the firmware-only USB device implementation for
+Atmel AVR microcontrollers distributed by OBJECTIVE DEVELOPMENT and
+consisting of the files usbdrv.c, usbdrv.h, usbdrvasm.S, oddebug.c,
+oddebug.h, usbdrvasm.asm, iarcompat.h and usbconfig-prototype.h.
+
+
+2 LICENSE GRANTS
+
+2.1 Source Code. OBJECTIVE DEVELOPMENT shall furnish you with the source
+code of AVR-USB.
+
+2.2 Distribution and Use. OBJECTIVE DEVELOPMENT grants you the
+non-exclusive right to use and distribute AVR-USB with your hardware
+product(s), restricted by the limitations in section 3 below.
+
+2.3 Modifications. OBJECTIVE DEVELOPMENT grants you the right to modify
+your copy of AVR-USB according to your needs.
+
+2.4 USB IDs. OBJECTIVE DEVELOPMENT grants you the exclusive rights to use
+USB Product ID(s) sent to you in e-mail after receiving your payment in
+conjunction with USB Vendor ID 5824. OBJECTIVE DEVELOPMENT has acquired an
+exclusive license for this pair of USB identifiers from Wouter van Ooijen
+(www.voti.nl), who has licensed the VID from the USB Implementers Forum,
+Inc. (www.usb.org).
+
+
+3 LICENSE RESTRICTIONS
+
+3.1 Number of Units. Only one of the following three definitions is
+applicable. Which one is determined by the amount you pay to OBJECTIVE
+DEVELOPMENT, see section 4 ("Payment") below.
+
+Hobby License: You may use AVR-USB according to section 2 above in no more
+than 5 hardware units. These units must not be sold for profit.
+
+Entry Level License: You may use AVR-USB according to section 2 above in no
+more than 150 hardware units.
+
+Professional License: You may use AVR-USB according to section 2 above in
+any number of hardware units, except for large scale production ("unlimited
+fair use"). Quantities below 10,000 units are not considered large scale
+production. If your reach quantities which are obviously large scale
+production, you must pay a license fee of 0.10 EUR per unit for all units
+above 10,000.
+
+3.2 Rental. You may not rent, lease, or lend AVR-USB or otherwise encumber
+any copy of AVR-USB, or any of the rights granted herein.
+
+3.3 Transfer. You may not transfer your rights under this Agreement to
+another party without OBJECTIVE DEVELOPMENT's prior written consent. If
+such consent is obtained, you may permanently transfer this License to
+another party. The recipient of such transfer must agree to all terms and
+conditions of this Agreement.
+
+3.4 Reservation of Rights. OBJECTIVE DEVELOPMENT retains all rights not
+expressly granted.
+
+3.5 Non-Exclusive Rights. Your license rights under this Agreement are
+non-exclusive.
+
+3.6 Third Party Rights. This Agreement cannot grant you rights controlled
+by third parties. In particular, you are not allowed to use the USB logo or
+other trademarks owned by the USB Implementers Forum, Inc. without their
+consent. Since such consent depends on USB certification, it should be
+noted that AVR-USB will not pass certification because it does not
+implement checksum verification and the microcontroller ports do not meet
+the electrical specifications.
+
+
+4 PAYMENT
+
+The payment amount depends on the variation of this agreement (according to
+section 3.1) into which you want to enter. Concrete prices are listed on
+OBJECTIVE DEVELOPMENT's web site, usually at
+http://www.obdev.at/avrusb/license.html. You agree to pay the amount listed
+there to OBJECTIVE DEVELOPMENT or OBJECTIVE DEVELOPMENT's payment processor
+or reseller.
+
+
+5 COPYRIGHT AND OWNERSHIP
+
+AVR-USB is protected by copyright laws and international copyright
+treaties, as well as other intellectual property laws and treaties. AVR-USB
+is licensed, not sold.
+
+
+6 TERM AND TERMINATION
+
+6.1 Term. This Agreement shall continue indefinitely. However, OBJECTIVE
+DEVELOPMENT may terminate this Agreement and revoke the granted license and
+USB-IDs if you fail to comply with any of its terms and conditions.
+
+6.2 Survival of Terms. All provisions regarding secrecy, confidentiality
+and limitation of liability shall survive termination of this agreement.
+
+
+7 DISCLAIMER OF WARRANTY AND LIABILITY
+
+LIMITED WARRANTY. AVR-USB IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+KIND. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, OBJECTIVE
+DEVELOPMENT AND ITS SUPPLIERS HEREBY DISCLAIM ALL WARRANTIES, EITHER
+EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE, AND
+NON-INFRINGEMENT, WITH REGARD TO AVR-USB, AND THE PROVISION OF OR FAILURE
+TO PROVIDE SUPPORT SERVICES. THIS LIMITED WARRANTY GIVES YOU SPECIFIC LEGAL
+RIGHTS. YOU MAY HAVE OTHERS, WHICH VARY FROM STATE/JURISDICTION TO
+STATE/JURISDICTION.
+
+LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW,
+IN NO EVENT SHALL OBJECTIVE DEVELOPMENT OR ITS SUPPLIERS BE LIABLE FOR ANY
+SPECIAL, INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER
+(INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS,
+BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR ANY OTHER PECUNIARY
+LOSS) ARISING OUT OF THE USE OF OR INABILITY TO USE AVR-USB OR THE
+PROVISION OF OR FAILURE TO PROVIDE SUPPORT SERVICES, EVEN IF OBJECTIVE
+DEVELOPMENT HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. IN ANY
+CASE, OBJECTIVE DEVELOPMENT'S ENTIRE LIABILITY UNDER ANY PROVISION OF THIS
+AGREEMENT SHALL BE LIMITED TO THE AMOUNT ACTUALLY PAID BY YOU FOR AVR-USB.
+
+
+8 MISCELLANEOUS TERMS
+
+8.1 Marketing. OBJECTIVE DEVELOPMENT has the right to mention for marketing
+purposes that you entered into this agreement.
+
+8.2 Entire Agreement. This document represents the entire agreement between
+OBJECTIVE DEVELOPMENT and you. It may only be modified in writing signed by
+an authorized representative of both, OBJECTIVE DEVELOPMENT and you.
+
+8.3 Severability. In case a provision of these terms and conditions should
+be or become partly or entirely invalid, ineffective, or not executable,
+the validity of all other provisions shall not be affected.
+
+8.4 Applicable Law. This agreement is governed by the laws of the Republic
+of Austria.
+
+8.5 Responsible Courts. The responsible courts in Vienna/Austria will have
+exclusive jurisdiction regarding all disputes in connection with this
+agreement.
index 9fe7fdf..a435e0e 100644 (file)
-PREFACE
-
-Conceiving and understanding a new license is not an easy task. To make things
-easier for both, the author and the licensee, we have decided to base our
-license for the USB driver on an existing license with well-understood
-properties.
+OBJECTIVE DEVELOPMENT GmbH's AVR-USB driver software is distributed under the
+terms and conditions of the GNU GPL version 2, see the text below. In addition
+to the requirements in the GPL, we STRONGLY ENCOURAGE you to do the following:
 
-Our favorite choice for the base license was the GNU General Public License
-(GPL). However, we cannot use the GNU GPL directly for the following reasons:
-
-(1) It was not intended for projects involving hardware -- we must extend the
-    term "source code" to at least the circuit diagram.
-(2) The GNU GPL does not require publication. Only if a binary is published,
-    it requires that the source is published as well. This is reasonable for
-    software because unpublished software is of little relevance. For projects
-    involving hardware, we want to REQUIRE publication. More than that, we
-    even want to define HOW the publication must be done (files contained,
-    file formats etc).
-(3) As the author of the software, we can distribute it under more than one
-    license. For people who don't want to meet the obligations of the GNU GPL,
-    we want to offer commercial licenses. To avoid a split in revisions of
-    the driver, we need special privileges to distribute contributed
-    modifications under proprietary licenses.
-
-We can not simply modify the GNU GPL and incorporate our changes because the
-Free Software Foundation (FSF) who holds the copyright for the text of the
-GNU GPL does not allow modifications. We therefore set up our own small
-license which incorporates the GNU GPL by reference:
-
-
-
-LICENSE FOR PROJECTS BUILT WITH "OBJECTIVE DEVELOPMENT'S
-FIRMWARE-ONLY USB-DRIVER FOR ATMEL'S AVR MICROCONTROLLERS"
-Version 2006-01
-
-
-I. Definitions
-
-"OBDEV" shall mean OBJECTIVE DEVELOPMENT Software GmbH or any legal successor
-thereof.
-
-"Software Source Code" shall mean the preferred form of the software for
-making modifications to it.
-
-"USB Driver" shall mean the Software Source Code for OBDEV's firmware-only
-USB-driver for Atmel's AVR microcontrollers.
-
-"Function" shall mean the Software Source Code for all software executed on
-the microcontroller except the USB Driver.
-
-"Host Software" shall mean the Software Source Code for all software required
-to control the USB device from the USB host running any operating system.
-
-"Project" shall mean the USB Driver, the Function, the Host Software, circuit
-diagrams of the controller based hardware and accompanying documentation.
-
-"source code" shall have the same meaning as the term "Project" above.
-
-"Web Site" shall mean a collection of text and multimedia documents accessible
-worldwide over internet through the HyperText Transfer Protocol (HTTP) on
-TCP port 80 (standard HTTP port).
-
-
-II. General License Terms
-The general terms of this license consist of the GNU General Public License
-Version 2 (GNU GPL2) which is hereby incorporated into this section as though
-it were fully set forth here. A copy of the GNU GPL2 is included for your
-convenience in appendix A of this license.
-
-The term "source code" in the GNU GPL2 is to be understood as defined in
-section I above. If any term or definition in section I, III, IV or V
-conflicts with the GNU GPL2, the term or definition in section I, III, IV or
-V has precedence of the GNU GPL2.
-
-
-III. Distribution of the Project
-The distributed form of a Project must contain at least the following files:
-(a) Software Source Code files for the USB Driver, the Function and the Host
-    Software.
-(b) Circuit diagrams for the hardware in PDF, PNG or GIF image file format.
-(c) A file with name "Readme.txt" in ASCII format with at least the following
-    content (in English language):
-    - An explanation what the Project does.
-    - What to do with the distributed files (installation procedure etc.).
-    - A reference to Objective Development's USB driver.
-    - Your (author's) name and contact information. E-mail and/or URL is
-      sufficient.
-(d) Optionally a text file with a description of the circuit diagram, an
-    explanation of special (software) techniques used etc.
-(e) A copy of this license in a file with the name "License.txt". This copy
-    can be in the "usbdrv" subdirectory which contains the driver.
-
-
-IV. Requirement for Publication
-All modifications and derived work (Projects using the USB Driver) MUST be
-distributed (published) as described in section III above on a Web Site. The
-main page must reproduce at least a description of the Project (e.g. as
-contained in the "Readme.txt" file distributed) and a download link for the
-entire Project. The URL of the main page must be submitted to OBDEV. OBDEV
-will provide a mechanism for submitting Project URLs and for publishing
-Projects on their Web Site. The Project must remain available for at least
-twelve (12) months after the initial publication or at least six (6) months
-after a subsequent version of that particular Project has been published.
-
-
-V. Author Privileges
-OBDEV reserves the right to distribute the USB Driver and all modified
-versions under other (proprietary) licenses. If you modify the USB Driver
-under the grants of this license, you therefore grant OBDEV (in addition to
-the grants of the GNU GPL2) a worldwide, perpetual, irrevocable royalty free
-license for your modifications. OBDEV shall not automatically gain rights
-other than those of the GNU GPL2 in the other parts of the Project. This
-section V overrides possibly contradicting terms in the GNU GPL2 referenced
-in section II.
+(1) Publish your entire project on a web site and drop us a note with the URL.
+Use the form at http://www.obdev.at/avrusb/feedback.html for your submission.
+
+(2) Adhere to minimum publication standards. Please include AT LEAST:
+    - a circuit diagram in PDF, PNG or GIF format
+    - full source code for the host software
+    - a Readme.txt file in ASCII format which describes the purpose of the
+      project and what can be found in which directories and which files
+    - a reference to http://www.obdev.at/avrusb/
+
+(3) If you improve the driver firmware itself, please give us a free license
+to your modifications for our commercial license offerings.
 
 
-APPENDIX A
 
                     GNU GENERAL PUBLIC LICENSE
                        Version 2, June 1991
index d0a6282..debc756 100644 (file)
@@ -9,8 +9,76 @@ project and add your own version of "usbconfig.h". A template for your own
 
 TECHNICAL DOCUMENTATION
 =======================
-The technical documentation for the firmware driver is contained in the file
-"usbdrv.h". Please read all of it carefully!
+The technical documentation (API) for the firmware driver is contained in the
+file "usbdrv.h". Please read all of it carefully! Configuration options are
+documented in "usbconfig-prototype.h".
+
+The driver consists of the following files:
+  Readme.txt ............. The file you are currently reading.
+  Changelog.txt .......... Release notes for all versions of the driver.
+  usbdrv.h ............... Driver interface definitions and technical docs.
+* usbdrv.c ............... High level language part of the driver. Link this
+                           module to your code!
+* usbdrvasm.S ............ Assembler part of the driver. This module is mostly
+                           a stub and includes one of the usbdrvasm*.S files
+                           depending on processor clock. Link this module to
+                           your code!
+  usbdrvasm12.S .......... 12 MHz version of the assembler routines. Included
+                           by usbdrvasm.S, don't link it directly!
+  usbdrvasm16.S .......... 16 MHz version of the assembler routines. Included
+                           by usbdrvasm.S, don't link it directly!
+  usbdrvasm165.S ......... 16.5 MHz version of the assembler routines including
+                           a PLL so that an 1% accurate RC oscillator can be
+                           used. Included by usbdrvasm.S, don't link directly!
+  usbconfig-prototype.h .. Prototype for your own usbdrv.h file.
+* oddebug.c .............. Debug functions. Only used when DEBUG_LEVEL is
+                           defined to a value greater than 0. Link this module
+                           to your code!
+  oddebug.h .............. Interface definitions of the debug module.
+  iarcompat.h ............ Compatibility definitions for IAR C-compiler.
+  usbdrvasm.asm .......... Compatibility stub for IAR-C-compiler. Use this
+                           module instead of usbdrvasm.S when you assembler
+                           with IAR's tools.
+  License.txt ............ Open Source license for this driver.
+  CommercialLicense.txt .. Optional commercial license for this driver.
+  USBID-License.txt ...... Terms and conditions for using particular USB ID
+                           values for particular purposes.
+
+(*) ... These files should be linked to your project.
+
+
+CPU CORE CLOCK FREQUENCY
+========================
+We supply assembler modules for clock frequencies of 12 MHz, 16 MHz and
+16.5 MHz. Other clock rates are not supported. The actual clock rate must be
+configured in usbdrv.h unless you use the default 12 MHz.
+
+12 MHz Clock
+This is the traditional clock rate of AVR-USB because it's the lowest clock
+rate where the timing constraints of the USB spec can be met.
+
+16 MHz Clock
+This clock rate has been added for users of the Arduino board and other
+ready-made boards which come with a fixed 16 MHz crystal. It's also an option
+if you need the slightly higher clock rate for performance reasons. Since
+16 MHz is not divisible by the USB low speed bit clock of 1.5 MHz, the code
+is somewhat tricky and has to insert a leap cycle every third byte.
+
+16.5 MHz Clock
+The assembler module for this clock rate differs from the other modules because
+it has been built for an RC oscillator with only 1% precision. The receiver
+code inserts leap cycles to compensate for clock deviations. 1% is also the
+precision which can be achieved by calibrating the internal RC oscillator of
+the AVR. Please note that only AVRs with internal 64 MHz PLL oscillator can be
+used since the 8 MHz RC oscillator cannot be trimmed up to 16.5 MHz. This
+includes the very popular ATTiny25, ATTiny45, ATTiny85 series as well as the
+ATTiny26.
+
+We recommend that you obtain appropriate calibration values for 16.5 MHz core
+clock at programming time and store it in flash or EEPROM or compute the value
+from a reference clock at run time. However, since Atmel's 8 MHz calibration
+is much more precise than the guaranteed 10%, it's usually possible to add a
+fixed offset to this value.
 
 
 USB IDENTIFIERS
@@ -27,6 +95,9 @@ and "USB_CFG_DEVICE_ID" accordingly in "usbconfig.h".
 To use our predefined VID/PID pair, you MUST conform to a couple of
 requirements. See the file "USBID-License.txt" for details.
 
+Objective Development also has some offerings which include product IDs. See
+http://www.obdev.at/avrusb/ for details.
+
 
 HOST DRIVER
 ===========
@@ -52,34 +123,29 @@ for gcc.
 
 USING AVR-USB FOR FREE
 ======================
-The AVR firmware driver is published under an Open Source compliant license.
-See the file "License.txt" for details. Since it is not obvious for many
-people how this license applies to their own projects, here's a short guide:
+The AVR firmware driver is published under the GNU General Public License
+Version 2 (GPL2). See the file "License.txt" for details.
 
-(1) The USB driver and all your modifications to the driver itself are owned
-by Objective Development. You must give us a worldwide, perpetual,
-irrevocable royalty free license for your modifications.
+If you decide for the free GPL2, we STRONGLY ENCOURAGE you to do the following
+things IN ADDITION to the obligations from the GPL2:
 
-(2) Since you own the code you have written (except where you modify our
-driver), you can (at least in principle) determine the license for it freely.
-However, to "pay" for the USB driver code you link against, we demand that
-you choose an Open Source compliant license (compatible with our license) for
-your source code and the hardware circuit diagrams. Simply attach your
-license of choice to your parts of the project and leave our "License.txt" in
-the "usbdrv" subdirectory.
+(1) Publish your entire project on a web site and drop us a note with the URL.
+Use the form at http://www.obdev.at/avrusb/feedback.html for your submission.
 
-(3) We also demand that you publish your work on the Internet and drop us a
-note with the URL. The publication must meet certain formal criteria (files
-distributed, file formats etc.). See the file "License.txt" for details.
+(2) Adhere to minimum publication standards. Please include AT LEAST:
+    - a circuit diagram in PDF, PNG or GIF format
+    - full source code for the host software
+    - a Readme.txt file in ASCII format which describes the purpose of the
+      project and what can be found in which directories and which files
+    - a reference to http://www.obdev.at/avrusb/
 
-Other than that, you are allowed to manufacture any number of units and sell
-them for any price. If you like our driver, we also encourage you to make a
-donation on our web site.
+(3) If you improve the driver firmware itself, please give us a free license
+to your modifications for our commercial license offerings.
 
 
 COMMERCIAL LICENSES FOR AVR-USB
 ===============================
-If you don't want to publish your source code and the circuit diagrams under
-an Open Source license, you can simply pay money for AVR-USB. As an
-additional benefit you get USB PIDs for free, licensed exclusively to you.
-See http://www.obdev.at/products/avrusb/license.html for details.
+If you don't want to publish your source code under the terms of the GPL2,
+you can simply pay money for AVR-USB. As an additional benefit you get
+USB PIDs for free, licensed exclusively to you. See the file
+"CommercialLicense.txt" for details.
index 443d3ff..1a45540 100644 (file)
@@ -4,8 +4,8 @@
  * Creation Date: 2006-03-01
  * Tabsize: 4
  * Copyright: (c) 2006 by OBJECTIVE DEVELOPMENT Software GmbH
- * License: Proprietary, free under certain conditions. See Documentation.
- * This Revision: $Id: iarcompat.h 174 2006-03-23 10:09:01Z cs $
+ * License: GNU GPL v2 (see License.txt) or proprietary (CommercialLicense.txt)
+ * This Revision: $Id: iarcompat.h 275 2007-03-20 09:58:28Z cs $
  */
 
 /*
index edd44ee..bd528e2 100644 (file)
@@ -4,18 +4,15 @@
  * Creation Date: 2005-01-16
  * Tabsize: 4
  * Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH
- * License: Proprietary, free under certain conditions. See Documentation.
- * This Revision: $Id: oddebug.c 215 2006-07-10 21:54:51Z cs $
+ * License: GNU GPL v2 (see License.txt) or proprietary (CommercialLicense.txt)
+ * This Revision: $Id: oddebug.c 275 2007-03-20 09:58:28Z cs $
  */
 
 #include "oddebug.h"
 
 #if DEBUG_LEVEL > 0
 
-static uchar Warning__Never_compile_production_devices_with_debugging;
-/* The "#warning" preprocessor directive is non-standard. The unused static
- * variable above should give a compiler warning on all compilers.
- */
+#warning "Never compile production devices with debugging enabled"
 
 static void uartPutc(char c)
 {
index 1c18b60..1b11ef0 100644 (file)
@@ -4,8 +4,8 @@
  * Creation Date: 2005-01-16
  * Tabsize: 4
  * Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH
- * License: Proprietary, free under certain conditions. See Documentation.
- * This Revision: $Id: oddebug.h 215 2006-07-10 21:54:51Z cs $
+ * License: GNU GPL v2 (see License.txt) or proprietary (CommercialLicense.txt)
+ * This Revision: $Id: oddebug.h 275 2007-03-20 09:58:28Z cs $
  */
 
 #ifndef __oddebug_h_included__
index 6af637f..e1138c9 100644 (file)
@@ -4,8 +4,8 @@
  * Creation Date: 2005-04-01
  * Tabsize: 4
  * Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH
- * License: Proprietary, free under certain conditions. See Documentation.
- * This Revision: $Id: usbconfig-prototype.h 216 2006-07-14 21:51:00Z cs $
+ * License: GNU GPL v2 (see License.txt) or proprietary (CommercialLicense.txt)
+ * This Revision: $Id: usbconfig-prototype.h 358 2007-06-23 13:30:30Z cs $
  */
 
 #ifndef __usbconfig_h_included__
@@ -16,8 +16,7 @@ General Description:
 This file is an example configuration (with inline documentation) for the USB
 driver. It configures AVR-USB for an ATMega8 with USB D+ connected to Port D
 bit 2 (which is also hardware interrupt 0) and USB D- to Port D bit 0. You may
-wire the lines to any other port, as long as D- is on bit 0 and D+ is also
-wired to INT0.
+wire the lines to any other port, as long as D+ is also wired to INT0.
 To create your own usbconfig.h file, copy this file to the directory
 containing "usbdrv" (that is your project firmware source directory) and
 rename it to "usbconfig.h". Then edit it accordingly.
@@ -38,6 +37,13 @@ rename it to "usbconfig.h". Then edit it accordingly.
  * This may be any bit in the port. Please note that D+ must also be connected
  * to interrupt pin INT0!
  */
+/* #define USB_CFG_CLOCK_KHZ       (F_CPU/1000) */
+/* Clock rate of the AVR in MHz. Legal values are 12000, 16000 or 16500.
+ * The 16.5 MHz version of the code requires no crystal, it tolerates +/- 1%
+ * deviation from the nominal frequency. All other rates require a precision
+ * of 2000 ppm and thus a crystal!
+ * Default if not specified: 12 MHz
+ */
 
 /* ----------------------- Optional Hardware Config ------------------------ */
 
@@ -52,15 +58,6 @@ rename it to "usbconfig.h". Then edit it accordingly.
  * above) where the 1.5k pullup resistor is connected. See description
  * above for details.
  */
-/* #define  USB_BUFFER_SECTION         ".bss" */
-/* The USB receive buffer (variable "usbRxBuf") with a length of 22 bytes
- * MUST NOT cross a 256 byte boundary. We have introduced this configuration
- * option to allow you to change the data segment where this buffer is
- * allocated. If you have problems with the default segment (start of .bss),
- * you may change this setting. See the comment in usbdrv.h for details.
- * On IAR C, the default is the TINY_Z segment (first 256 bytes). You must
- * change this default for devices which don't have RAM below 0x100.
- */
 
 /* --------------------------- Functional Range ---------------------------- */
 
@@ -93,15 +90,6 @@ rename it to "usbconfig.h". Then edit it accordingly.
  * The value is in milliamperes. [It will be divided by two since USB
  * communicates power requirements in units of 2 mA.]
  */
-#define USB_CFG_SAMPLE_EXACT            1
-/* This variable affects Sampling Jitter for USB receiving. When it is 0, the
- * driver guarantees a sampling window of 1/2 bit. The USB spec requires
- * that the receiver has at most 1/4 bit sampling window. The 1/2 bit window
- * should still work reliably enough because we work at low speed. If you want
- * to meet the spec, set this value to 1. This will unroll a loop which
- * results in bigger code size.
- * If you have problems with long cables, try setting this value to 1.
- */
 #define USB_CFG_IMPLEMENT_FN_WRITE      0
 /* Set this to 1 if you want usbFunctionWrite() to be called for control-out
  * transfers. Set it to 0 if you don't need it and want to save a couple of
@@ -191,6 +179,11 @@ rename it to "usbconfig.h". Then edit it accordingly.
  * Don't forget to keep the array and this define in sync!
  */
 
+/* #define USB_PUBLIC static */
+/* Use the define above if you #include usbdrv.c instead of linking against it.
+ * This technique saves a couple of bytes in flash memory.
+ */
+
 /* ------------------- Fine Control over USB Descriptors ------------------- */
 /* If you don't want to use the driver's default USB descriptors, you can
  * provide our own. These can be provided as (1) fixed length static data in
index 2cf6e69..04603bd 100644 (file)
@@ -4,8 +4,8 @@
  * Creation Date: 2004-12-29
  * Tabsize: 4
  * Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH
- * License: Proprietary, free under certain conditions. See Documentation.
- * This Revision: $Id: usbdrv.c 222 2006-07-17 15:07:34Z cs $
+ * License: GNU GPL v2 (see License.txt) or proprietary (CommercialLicense.txt)
+ * This Revision: $Id: usbdrv.c 350 2007-06-13 11:43:16Z cs $
  */
 
 #include "iarcompat.h"
@@ -33,14 +33,12 @@ documentation of the entire driver.
 /* ------------------------------------------------------------------------- */
 
 /* raw USB registers / interface to assembler code: */
-/* usbRxBuf MUST be in 1 byte addressable range (because usbInputBuf is only 1 byte) */
-__no_init uchar usbRxBuf[2][USB_BUFSIZE] __attribute__ ((section (USB_BUFFER_SECTION))) IAR_SECTION(USB_BUFFER_SECTION);/* raw RX buffer: PID, 8 bytes data, 2 bytes CRC */
+uchar usbRxBuf[2*USB_BUFSIZE];  /* raw RX buffer: PID, 8 bytes data, 2 bytes CRC */
+uchar       usbInputBufOffset;  /* offset in usbRxBuf used for low level receiving */
 uchar       usbDeviceAddr;      /* assigned during enumeration, defaults to 0 */
 uchar       usbNewDeviceAddr;   /* device ID which should be set after status phase */
 uchar       usbConfiguration;   /* currently selected configuration. Administered by driver, but not used */
-uchar       usbInputBuf;        /* ptr to raw buffer used for receiving */
-uchar       usbAppBuf;          /* ptr to raw buffer passed to app for processing */
-volatile schar usbRxLen;        /* = 0; number of bytes in usbAppBuf; 0 means free */
+volatile schar usbRxLen;        /* = 0; number of bytes in usbRxBuf; 0 means free, -1 for flow control */
 uchar       usbCurrentTok;      /* last token received, if more than 1 rx endpoint: MSb=endpoint */
 uchar       usbRxToken;         /* token for data we received; if more than 1 rx endpoint: MSb=endpoint */
 uchar       usbMsgLen = 0xff;   /* remaining number of bytes, no msg to send if -1 (see usbMsgPtr) */
@@ -58,7 +56,6 @@ uchar       usbTxBuf3[USB_BUFSIZE];     /* TX data for endpoint 1 */
 /* USB status registers / not shared with asm code */
 uchar           *usbMsgPtr;     /* data to transmit next -- ROM or RAM address */
 static uchar    usbMsgFlags;    /* flag values see below */
-static uchar    usbIsReset;     /* = 0; USB bus is in reset phase */
 
 #define USB_FLG_TX_PACKET       (1<<0)
 /* Leave free 6 bits after TX_PACKET. This way we can increment usbMsgFlags to toggle TX_PACKET */
@@ -96,9 +93,9 @@ PROGMEM int  usbDescriptorStringVendor[] = {
 };
 #endif
 
-#if USB_CFG_DESCR_PROPS_STRING_DEVICE == 0 && USB_CFG_DEVICE_NAME_LEN
-#undef USB_CFG_DESCR_PROPS_STRING_DEVICE
-#define USB_CFG_DESCR_PROPS_STRING_DEVICE   sizeof(usbDescriptorStringDevice)
+#if USB_CFG_DESCR_PROPS_STRING_PRODUCT == 0 && USB_CFG_DEVICE_NAME_LEN
+#undef USB_CFG_DESCR_PROPS_STRING_PRODUCT
+#define USB_CFG_DESCR_PROPS_STRING_PRODUCT   sizeof(usbDescriptorStringDevice)
 PROGMEM int  usbDescriptorStringDevice[] = {
     USB_STRING_DESCRIPTOR_HEADER(USB_CFG_DEVICE_NAME_LEN),
     USB_CFG_DEVICE_NAME
@@ -122,7 +119,7 @@ PROGMEM int usbDescriptorStringSerialNumber[] = {
 PROGMEM char usbDescriptorDevice[] = {    /* USB device descriptor */
     18,         /* sizeof(usbDescriptorDevice): length of descriptor in bytes */
     USBDESCR_DEVICE,        /* descriptor type */
-    0x01, 0x01,             /* USB version supported */
+    0x10, 0x01,             /* USB version supported */
     USB_CFG_DEVICE_CLASS,
     USB_CFG_DEVICE_SUBCLASS,
     0,                      /* protocol */
@@ -131,7 +128,7 @@ PROGMEM char usbDescriptorDevice[] = {    /* USB device descriptor */
     USB_CFG_DEVICE_ID,      /* 2 bytes */
     USB_CFG_DEVICE_VERSION, /* 2 bytes */
     USB_CFG_DESCR_PROPS_STRING_VENDOR != 0 ? 1 : 0,         /* manufacturer string index */
-    USB_CFG_DESCR_PROPS_STRING_DEVICE != 0 ? 2 : 0,         /* product string index */
+    USB_CFG_DESCR_PROPS_STRING_PRODUCT != 0 ? 2 : 0,        /* product string index */
     USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER != 0 ? 3 : 0,  /* serial number string index */
     1,          /* number of configurations */
 };
@@ -209,9 +206,7 @@ typedef union{
 /* ------------------------------------------------------------------------- */
 
 #if USB_CFG_HAVE_INTRIN_ENDPOINT
-uchar   usbTxPacketCnt1;
-
-void    usbSetInterrupt(uchar *data, uchar len)
+USB_PUBLIC void usbSetInterrupt(uchar *data, uchar len)
 {
 uchar       *p, i;
 
@@ -223,16 +218,12 @@ uchar       *p, i;
     if(len > 8) /* interrupt transfers are limited to 8 bytes */
         len = 8;
 #endif
-    i = USBPID_DATA1;
-    if(usbTxPacketCnt1 & 1)
-        i = USBPID_DATA0;
-    if(usbTxLen1 & 0x10){       /* packet buffer was empty */
-        usbTxPacketCnt1++;
+    if(usbTxLen1 & 0x10){   /* packet buffer was empty */
+        usbTxBuf1[0] ^= USBPID_DATA0 ^ USBPID_DATA1;    /* toggle token */
     }else{
-        usbTxLen1 = USBPID_NAK; /* avoid sending incomplete interrupt data */
+        usbTxLen1 = USBPID_NAK; /* avoid sending outdated (overwritten) interrupt data */
     }
-    p = usbTxBuf1;
-    *p++ = i;
+    p = usbTxBuf1 + 1;
     for(i=len;i--;)
         *p++ = *data++;
     usbCrc16Append(&usbTxBuf1[1], len);
@@ -242,22 +233,16 @@ uchar       *p, i;
 #endif
 
 #if USB_CFG_HAVE_INTRIN_ENDPOINT3
-uchar   usbTxPacketCnt3;
-
-void    usbSetInterrupt3(uchar *data, uchar len)
+USB_PUBLIC void usbSetInterrupt3(uchar *data, uchar len)
 {
 uchar       *p, i;
 
-    i = USBPID_DATA1;
-    if(usbTxPacketCnt3 & 1)
-        i = USBPID_DATA0;
-    if(usbTxLen3 & 0x10){       /* packet buffer was empty */
-        usbTxPacketCnt3++;
+    if(usbTxLen3 & 0x10){   /* packet buffer was empty */
+        usbTxBuf3[0] ^= USBPID_DATA0 ^ USBPID_DATA1;    /* toggle token */
     }else{
-        usbTxLen3 = USBPID_NAK; /* avoid sending incomplete interrupt data */
+        usbTxLen3 = USBPID_NAK; /* avoid sending outdated (overwritten) interrupt data */
     }
-    p = usbTxBuf3;
-    *p++ = i;
+    p = usbTxBuf3 + 1;
     for(i=len;i--;)
         *p++ = *data++;
     usbCrc16Append(&usbTxBuf3[1], len);
@@ -267,7 +252,7 @@ uchar       *p, i;
 #endif
 
 
-static uchar    usbRead(uchar *data, uchar len)
+static uchar usbRead(uchar *data, uchar len)
 {
 #if USB_CFG_IMPLEMENT_FN_READ
     if(usbMsgFlags & USB_FLG_USE_DEFAULT_RW){
@@ -325,16 +310,20 @@ uchar           replyLen = 0, flags = USB_FLG_USE_DEFAULT_RW;
 /* We use if() cascades because the compare is done byte-wise while switch()
  * is int-based. The if() cascades are therefore more efficient.
  */
-    DBG2(0x10 + ((usbRxToken >> 6) & 3), data, len);
+/* usbRxToken can be:
+ * 0x2d 00101101 (USBPID_SETUP for endpoint 0)
+ * 0xe1 11100001 (USBPID_OUT for endpoint 0)
+ * 0xff 11111111 (USBPID_OUT for endpoint 1)
+ */
+    DBG2(0x10 + ((usbRxToken >> 1) & 3), data, len);    /* SETUP0=12; OUT0=10; OUT1=13 */
 #if USB_CFG_IMPLEMENT_FN_WRITEOUT
-    if(usbRxToken & 0x80){
+    if(usbRxToken == 0xff){
         usbFunctionWriteOut(data, len);
         return; /* no reply expected, hence no usbMsgPtr, usbMsgFlags, usbMsgLen set */
     }
-    if(usbRxToken == (uchar)(USBPID_SETUP & 0x7f)){ /* MSb contains endpoint (== 0) */
-#else
-    if(usbRxToken == (uchar)USBPID_SETUP){
 #endif
+    if(usbRxToken == (uchar)USBPID_SETUP){
+        usbTxLen = USBPID_NAK;  /* abort pending transmit */
         if(len == 8){   /* Setup size must be always 8 bytes. Ignore otherwise. */
             uchar type = rq->bmRequestType & USBRQ_TYPE_MASK;
             if(type == USBRQ_TYPE_STANDARD){
@@ -374,7 +363,7 @@ uchar           replyLen = 0, flags = USB_FLG_USE_DEFAULT_RW;
                         }else if(rq->wValue.bytes[0] == 1){
                             GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_STRING_VENDOR, usbDescriptorStringVendor)
                         }else if(rq->wValue.bytes[0] == 2){
-                            GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_STRING_DEVICE, usbDescriptorStringDevice)
+                            GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_STRING_PRODUCT, usbDescriptorStringDevice)
                         }else if(rq->wValue.bytes[0] == 3){
                             GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER, usbDescriptorStringSerialNumber)
                         }else if(USB_CFG_DESCR_PROPS_UNKNOWN & USB_PROP_IS_DYNAMIC){
@@ -400,18 +389,18 @@ uchar           replyLen = 0, flags = USB_FLG_USE_DEFAULT_RW;
                     SET_REPLY_LEN(1);
 #if USB_CFG_HAVE_INTRIN_ENDPOINT
                 }else if(rq->bRequest == USBRQ_SET_INTERFACE){      /* 11 */
-                    usbTxPacketCnt1 = 0;        /* reset data toggling for interrupt endpoint */
+                    USB_SET_DATATOKEN1(USBPID_DATA0);   /* reset data toggling for interrupt endpoint */
 #   if USB_CFG_HAVE_INTRIN_ENDPOINT3
-                    usbTxPacketCnt3 = 0;        /* reset data toggling for interrupt endpoint */
+                    USB_SET_DATATOKEN3(USBPID_DATA0);   /* reset data toggling for interrupt endpoint */
 #   endif
 #   if USB_CFG_IMPLEMENT_HALT
                     usbTxLen1 = USBPID_NAK;
                 }else if(rq->bRequest == USBRQ_CLEAR_FEATURE || rq->bRequest == USBRQ_SET_FEATURE){   /* 1|3 */
                     if(rq->wValue.bytes[0] == 0 && rq->wIndex.bytes[0] == 0x81){   /* feature 0 == HALT for endpoint == 1 */
                         usbTxLen1 = rq->bRequest == USBRQ_CLEAR_FEATURE ? USBPID_NAK : USBPID_STALL;
-                        usbTxPacketCnt1 = 0;    /* reset data toggling for interrupt endpoint */
+                        USB_SET_DATATOKEN1(USBPID_DATA0);   /* reset data toggling for interrupt endpoint */
 #       if USB_CFG_HAVE_INTRIN_ENDPOINT3
-                        usbTxPacketCnt3 = 0;    /* reset data toggling for interrupt endpoint */
+                        USB_SET_DATATOKEN3(USBPID_DATA0);   /* reset data toggling for interrupt endpoint */
 #       endif
                     }
 #   endif
@@ -460,7 +449,7 @@ uchar           replyLen = 0, flags = USB_FLG_USE_DEFAULT_RW;
 
 static void usbBuildTxBlock(void)
 {
-uchar       wantLen, len, txLen, token;
+uchar   wantLen, len, txLen, token;
 
     wantLen = usbMsgLen;
     if(wantLen > 8)
@@ -499,67 +488,52 @@ uchar   rval;
 
 /* ------------------------------------------------------------------------- */
 
-void    usbPoll(void)
+USB_PUBLIC void usbPoll(void)
 {
-uchar   len;
+schar   len;
+uchar   i;
 
     if((len = usbRxLen) > 0){
 /* We could check CRC16 here -- but ACK has already been sent anyway. If you
  * need data integrity checks with this driver, check the CRC in your app
  * code and report errors back to the host. Since the ACK was already sent,
  * retries must be handled on application level.
- * unsigned crc = usbCrc16((uchar *)(unsigned)(usbAppBuf + 1), usbRxLen - 3);
+ * unsigned crc = usbCrc16(buffer + 1, usbRxLen - 3);
  */
-        len -= 3;       /* remove PID and CRC */
-        if(len < 128){  /* no overflow */
-            converter_t appBuf;
-            appBuf.ptr = (uchar *)usbRxBuf;
-            appBuf.bytes[0] = usbAppBuf;
-            appBuf.bytes[0]++;
-            usbProcessRx(appBuf.ptr, len);
-        }
+        usbProcessRx(usbRxBuf + USB_BUFSIZE + 1 - usbInputBufOffset, len - 3);
 #if USB_CFG_HAVE_FLOWCONTROL
         if(usbRxLen > 0)    /* only mark as available if not inactivated */
             usbRxLen = 0;
 #else
-        usbRxLen = 0;   /* mark rx buffer as available */
+        usbRxLen = 0;       /* mark rx buffer as available */
 #endif
     }
-    if(usbMsgLen != 0xff){  /* transmit data pending? */
-        if(usbTxLen & 0x10) /* transmit system idle */
+    if(usbTxLen & 0x10){ /* transmit system idle */
+        if(usbMsgLen != 0xff){  /* transmit data pending? */
             usbBuildTxBlock();
+        }
     }
-    if(isNotSE0()){ /* SE0 state */
-        usbIsReset = 0;
-    }else{
-        /* check whether SE0 lasts for more than 2.5us (3.75 bit times) */
-        if(!usbIsReset){
-            uchar i;
-            for(i=100;i;i--){
-                if(isNotSE0())
-                    goto notUsbReset;
-            }
-            usbIsReset = 1;
-            usbNewDeviceAddr = 0;
-            usbDeviceAddr = 0;
+    for(i = 10; i > 0; i--){
+        if(isNotSE0())
+            break;
+    }
+    if(i == 0){ /* RESET condition, called multiple times during reset */
+        usbNewDeviceAddr = 0;
+        usbDeviceAddr = 0;
 #if USB_CFG_IMPLEMENT_HALT
-            usbTxLen1 = USBPID_NAK;
+        usbTxLen1 = USBPID_NAK;
 #if USB_CFG_HAVE_INTRIN_ENDPOINT3
-            usbTxLen3 = USBPID_NAK;
+        usbTxLen3 = USBPID_NAK;
 #endif
 #endif
-            DBG1(0xff, 0, 0);
-notUsbReset:;
-        }
+        DBG1(0xff, 0, 0);
     }
 }
 
 /* ------------------------------------------------------------------------- */
 
-void    usbInit(void)
+USB_PUBLIC void usbInit(void)
 {
-    usbInputBuf = (uchar)usbRxBuf[0];
-    usbAppBuf = (uchar)usbRxBuf[1];
 #if USB_INTR_CFG_SET != 0
     USB_INTR_CFG |= USB_INTR_CFG_SET;
 #endif
@@ -567,6 +541,12 @@ void    usbInit(void)
     USB_INTR_CFG &= ~(USB_INTR_CFG_CLR);
 #endif
     USB_INTR_ENABLE |= (1 << USB_INTR_ENABLE_BIT);
+#if USB_CFG_HAVE_INTRIN_ENDPOINT
+    USB_SET_DATATOKEN1(USBPID_DATA0);   /* reset data toggling for interrupt endpoint */
+#   if USB_CFG_HAVE_INTRIN_ENDPOINT3
+    USB_SET_DATATOKEN3(USBPID_DATA0);   /* reset data toggling for interrupt endpoint */
+#   endif
+#endif
 }
 
 /* ------------------------------------------------------------------------- */
index 52a324c..9408576 100644 (file)
@@ -4,8 +4,8 @@
  * Creation Date: 2004-12-29
  * Tabsize: 4
  * Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH
- * License: Proprietary, free under certain conditions. See Documentation.
- * This Revision: $Id: usbdrv.h 230 2006-07-18 11:29:00Z cs $
+ * License: GNU GPL v2 (see License.txt) or proprietary (CommercialLicense.txt)
+ * This Revision: $Id: usbdrv.h 375 2007-07-07 12:01:52Z cs $
  */
 
 #ifndef __usbdrv_h_included__
@@ -29,27 +29,12 @@ usbDeviceConnect() and usbDeviceDisconnect() further down in this file.
 
 Please adapt the values in usbconfig.h according to your hardware!
 
-The device MUST be clocked at 12 MHz. This is more than the 10 MHz allowed by
-an AT90S2313 powered at 4.5V. However, if the supply voltage to maximum clock
-relation is interpolated linearly, an ATtiny2313 meets the requirement by
-specification. In practice, the AT90S2313 can be overclocked and works well.
+The device MUST be clocked at exactly 12 MHz or 16 MHz or at 16.5 MHz +/- 1%.
+See usbconfig-prototype.h for details.
 
 
 Limitations:
 ============
-Compiling:
-You should link the usbdrv.o module first because it has special alignment
-requirements for the receive buffer (the buffer must not cross a 256 byte
-page boundary, it must not even touch it at the end). If you can't link it
-first, you must use other measures to ensure alignment.
-Note: gcc does not always assign variable addresses in the order as the modules
-are linked or the variables are declared. You can choose a memory section for
-the receive buffer with the configuration option "USB_BUFFER_SECTION". This
-option defaults to ".bss". If you use your own section, you can place it at
-an arbitrary location with a linker option similar to
-"-Wl,--section-start=.mybuffer=0x800060". Use "avr-nm -ng" on the binary and
-search for "usbRxBuf" to find tbe base address of the 22 bytes rx buffer.
-
 Robustness with respect to communication errors:
 The driver assumes error-free communication. It DOES check for errors in
 the PID, but does NOT check bit stuffing errors, SE0 in middle of a byte,
@@ -59,13 +44,6 @@ Bit stuffing and misplaced SE0 would have to be checked in real-time, but CPU
 performance does not permit that. The driver does not check Data0/Data1
 toggling, but application software can implement the check.
 
-Sampling jitter:
-The driver guarantees a sampling window of 1/2 bit. The USB spec requires
-that the receiver has at most 1/4 bit sampling window. The 1/2 bit window
-should still work reliably enough because we work at low speed. If you want
-to meet the spec, define the macro "USB_CFG_SAMPLE_EXACT" to 1 in usbconfig.h.
-This will unroll a loop which results in bigger code size.
-
 Input characteristics:
 Since no differential receiver circuit is used, electrical interference
 robustness may suffer. The driver samples only one of the data lines with
@@ -118,9 +96,9 @@ are written in assembler with "sei" as the first instruction.
 Maximum interrupt duration / CPU cycle consumption:
 The driver handles all USB communication during the interrupt service
 routine. The routine will not return before an entire USB message is received
-and the reply is sent. This may be up to ca. 1200 cycles = 100us if the host
-conforms to the standard. The driver will consume CPU cycles for all USB
-messages, even if they address another (low-speed) device on the same bus.
+and the reply is sent. This may be up to ca. 1200 cycles @ 12 MHz (= 100us) if
+the host conforms to the standard. The driver will consume CPU cycles for all
+USB messages, even if they address another (low-speed) device on the same bus.
 
 */
 
@@ -128,7 +106,7 @@ messages, even if they address another (low-speed) device on the same bus.
 /* --------------------------- Module Interface ---------------------------- */
 /* ------------------------------------------------------------------------- */
 
-#define USBDRV_VERSION  20060718
+#define USBDRV_VERSION  20070707
 /* This define uniquely identifies a driver version. It is a decimal number
  * constructed from the driver's release date in the form YYYYMMDD. If the
  * driver's behavior or interface changes, you can use this constant to
@@ -136,8 +114,18 @@ messages, even if they address another (low-speed) device on the same bus.
  * older than 2006-01-25.
  */
 
-#ifndef __ASSEMBLER__
 
+#ifndef USB_PUBLIC
+#define USB_PUBLIC
+#endif
+/* USB_PUBLIC is used as declaration attribute for all functions exported by
+ * the USB driver. The default is no attribute (see above). You may define it
+ * to static either in usbconfig.h or from the command line if you include
+ * usbdrv.c instead of linking against it. Including the C module of the driver
+ * directly in your code saves a couple of bytes in flash memory.
+ */
+
+#ifndef __ASSEMBLER__
 #ifndef uchar
 #define uchar   unsigned char
 #endif
@@ -148,23 +136,23 @@ messages, even if they address another (low-speed) device on the same bus.
 
 struct usbRequest;  /* forward declaration */
 
-extern void     usbInit(void);
+USB_PUBLIC void usbInit(void);
 /* This function must be called before interrupts are enabled and the main
  * loop is entered.
  */
-extern void     usbPoll(void);
+USB_PUBLIC void usbPoll(void);
 /* This function must be called at regular intervals from the main loop.
  * Maximum delay between calls is somewhat less than 50ms (USB timeout for
  * accepting a Setup message). Otherwise the device will not be recognized.
  * Please note that debug outputs through the UART take ~ 0.5ms per byte
  * at 19200 bps.
  */
-extern uchar    *usbMsgPtr;
+extern uchar *usbMsgPtr;
 /* This variable may be used to pass transmit data to the driver from the
  * implementation of usbFunctionWrite(). It is also used internally by the
  * driver for standard control requests.
  */
-extern uchar    usbFunctionSetup(uchar data[8]);
+USB_PUBLIC uchar usbFunctionSetup(uchar data[8]);
 /* This function is called when the driver receives a SETUP transaction from
  * the host which is not answered by the driver itself (in practice: class and
  * vendor requests). All control transfers start with a SETUP transaction where
@@ -191,14 +179,14 @@ extern uchar    usbFunctionSetup(uchar data[8]);
  * Note that calls to the functions usbFunctionRead() and usbFunctionWrite()
  * are only done if enabled by the configuration in usbconfig.h.
  */
-extern uchar usbFunctionDescriptor(struct usbRequest *rq);
+USB_PUBLIC uchar usbFunctionDescriptor(struct usbRequest *rq);
 /* You need to implement this function ONLY if you provide USB descriptors at
  * runtime (which is an expert feature). It is very similar to
  * usbFunctionSetup() above, but it is called only to request USB descriptor
  * data. See the documentation of usbFunctionSetup() above for more info.
  */
 #if USB_CFG_HAVE_INTRIN_ENDPOINT
-void    usbSetInterrupt(uchar *data, uchar len);
+USB_PUBLIC void usbSetInterrupt(uchar *data, uchar len);
 /* This function sets the message which will be sent during the next interrupt
  * IN transfer. The message is copied to an internal buffer and must not exceed
  * a length of 8 bytes. The message may be 0 bytes long just to indicate the
@@ -212,7 +200,7 @@ extern volatile uchar usbTxLen1;
  * message already buffered will be lost.
  */
 #if USB_CFG_HAVE_INTRIN_ENDPOINT3
-void    usbSetInterrupt3(uchar *data, uchar len);
+USB_PUBLIC void usbSetInterrupt3(uchar *data, uchar len);
 extern volatile uchar usbTxLen3;
 #define usbInterruptIsReady3()   (usbTxLen3 & 0x10)
 /* Same as above for endpoint 3 */
@@ -229,7 +217,7 @@ extern volatile uchar usbTxLen3;
  */
 #endif  /* USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH */
 #if USB_CFG_IMPLEMENT_FN_WRITE
-extern uchar    usbFunctionWrite(uchar *data, uchar len);
+USB_PUBLIC uchar usbFunctionWrite(uchar *data, uchar len);
 /* This function is called by the driver to provide a control transfer's
  * payload data (control-out). It is called in chunks of up to 8 bytes. The
  * total count provided in the current control transfer can be obtained from
@@ -247,7 +235,7 @@ extern uchar    usbFunctionWrite(uchar *data, uchar len);
  */
 #endif /* USB_CFG_IMPLEMENT_FN_WRITE */
 #if USB_CFG_IMPLEMENT_FN_READ
-extern uchar usbFunctionRead(uchar *data, uchar len);
+USB_PUBLIC uchar usbFunctionRead(uchar *data, uchar len);
 /* This function is called by the driver to ask the application for a control
  * transfer's payload data (control-in). It is called in chunks of up to 8
  * bytes each. You should copy the data to the location given by 'data' and
@@ -259,7 +247,7 @@ extern uchar usbFunctionRead(uchar *data, uchar len);
  */
 #endif /* USB_CFG_IMPLEMENT_FN_READ */
 #if USB_CFG_IMPLEMENT_FN_WRITEOUT
-extern void usbFunctionWriteOut(uchar *data, uchar len);
+USB_PUBLIC void usbFunctionWriteOut(uchar *data, uchar len);
 /* This function is called by the driver when data on interrupt-out or bulk-
  * out endpoint 1 is received. You must define USB_CFG_IMPLEMENT_FN_WRITEOUT
  * to 1 in usbconfig.h to get this function called.
@@ -272,7 +260,8 @@ extern void usbFunctionWriteOut(uchar *data, uchar len);
  * USB bus. It is only available if you have defined the constants
  * USB_CFG_PULLUP_IOPORT and USB_CFG_PULLUP_BIT in usbconfig.h.
  */
-#define usbDeviceDisconnect()   (USB_PULLUP_OUT &= ~(1<<USB_CFG_PULLUP_BIT))
+#define usbDeviceDisconnect()   ((USB_PULLUP_DDR &= ~(1<<USB_CFG_PULLUP_BIT)), \
+                                  (USB_PULLUP_OUT &= ~(1<<USB_CFG_PULLUP_BIT)))
 /* This macro (intended to look like a function) disconnects the device from
  * the USB bus. It is only available if you have defined the constants
  * USB_CFG_PULLUP_IOPORT and USB_CFG_PULLUP_BIT in usbconfig.h.
@@ -321,12 +310,10 @@ extern volatile schar   usbRxLen;
  */
 #endif
 
-extern uchar    usbTxPacketCnt1;
-extern uchar    usbTxPacketCnt3;
-/* The two variables above are mostly for internal use by the driver. You may
- * have to reset usbTxPacketCnt1 to 0 if you start data toggling at DATA0 for
- * interrupt-IN endpoint 1 and usbTxPacketCnt3 for interrupt-IN endpoint 3
- * respectively.
+#define USB_SET_DATATOKEN1(token)   usbTxBuf1[0] = token
+#define USB_SET_DATATOKEN3(token)   usbTxBuf3[0] = token
+/* These two macros can be used by application software to reset data toggling
+ * for interrupt-in endpoints 1 and 3.
  */
 
 #endif  /* __ASSEMBLER__ */
@@ -369,8 +356,8 @@ extern uchar    usbTxPacketCnt3;
 #ifndef USB_CFG_DESCR_PROPS_STRING_VENDOR
 #define USB_CFG_DESCR_PROPS_STRING_VENDOR           0
 #endif
-#ifndef USB_CFG_DESCR_PROPS_STRING_DEVICE
-#define USB_CFG_DESCR_PROPS_STRING_DEVICE           0
+#ifndef USB_CFG_DESCR_PROPS_STRING_PRODUCT
+#define USB_CFG_DESCR_PROPS_STRING_PRODUCT          0
 #endif
 #ifndef USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER
 #define USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER    0
@@ -457,11 +444,9 @@ int usbDescriptorStringSerialNumber[];
 /* ------------------------- Constant definitions -------------------------- */
 /* ------------------------------------------------------------------------- */
 
-#if !defined USB_CFG_VENDOR_ID || !defined USB_CFG_DEVICE_ID
-static uchar Warning_You_should_define_USB_CFG_VENDOR_ID_and_USB_CFG_DEVICE_ID_in_usbconfig_h;
-/* The unused variable above should generate a warning on all compilers. IAR cc
- * does not understand the "#warning" preprocessor direcetive.
- * If the user has not defined IDs, we default to obdev's free IDs.
+#if !defined __ASSEMBLER__ && (!defined USB_CFG_VENDOR_ID || !defined USB_CFG_DEVICE_ID)
+#warning "You should define USB_CFG_VENDOR_ID and USB_CFG_DEVICE_ID in usbconfig.h"
+/* If the user has not defined IDs, we default to obdev's free IDs.
  * See USBID-License.txt for details.
  */
 #endif
@@ -481,10 +466,6 @@ static uchar Warning_You_should_define_USB_CFG_VENDOR_ID_and_USB_CFG_DEVICE_ID_i
 #   endif
 #endif
 
-#ifndef USB_BUFFER_SECTION
-#   define  USB_BUFFER_SECTION  ".bss"      /* if user has not selected a named section */
-#endif
-
 /* Derive Output, Input and DataDirection ports from port names */
 #ifndef USB_CFG_IOPORTNAME
 #error "You must define USB_CFG_IOPORTNAME in usbconfig.h, see usbconfig-prototype.h"
@@ -578,6 +559,9 @@ at90s1200, attiny11, attiny12, attiny15, attiny28: these have no RAM
 #define USBPID_STALL    0x1e
 
 #ifndef __ASSEMBLER__
+
+extern uchar    usbTxBuf1[USB_BUFSIZE], usbTxBuf3[USB_BUFSIZE];
+
 typedef union usbWord{
     unsigned    word;
     uchar       bytes[2];
index 635929c..3f67f53 100644 (file)
@@ -1,28 +1,18 @@
 /* Name: usbdrvasm.S
  * Project: AVR USB driver
  * Author: Christian Starkjohann
- * Creation Date: 2004-12-29
+ * Creation Date: 2007-06-13
  * Tabsize: 4
- * Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH
- * License: Proprietary, free under certain conditions. See Documentation.
- * This Revision: $Id: usbdrvasm.S 218 2006-07-15 17:08:14Z cs $
+ * Copyright: (c) 2007 by OBJECTIVE DEVELOPMENT Software GmbH
+ * License: GNU GPL v2 (see License.txt) or proprietary (CommercialLicense.txt)
+ * Revision: $Id$
  */
 
 /*
 General Description:
-This module implements the assembler part of the USB driver. See usbdrv.h
-for a description of the entire driver.
-Since almost all of this code is timing critical, don't change unless you
-really know what you are doing! Many parts require not only a maximum number
-of CPU cycles, but even an exact number of cycles!
-
-
-Timing constraints according to spec (in bit times):
-timing subject                                      min max    CPUcycles
----------------------------------------------------------------------------
-EOP of OUT/SETUP to sync pattern of DATA0 (both rx) 2   16     16-128
-EOP of IN to sync pattern of DATA0 (rx, then tx)    2   7.5    16-60
-DATAx (rx) to ACK/NAK/STALL (tx)                    2   7.5    16-60
+This module is the assembler part of the USB driver. This file contains
+general code (preprocessor acrobatics and CRC computation) and then includes
+the file appropriate for the given clock rate.
 */
 
 #include "iarcompat.h"
@@ -42,6 +32,9 @@ DATAx (rx) to ACK/NAK/STALL (tx)                    2   7.5    16-60
 #define cnt     r19
 #define x3      r20
 #define x4      r21
+#define bitcnt  r22
+#define phase   x4
+#define leap    x4
 
 /* Some assembler dependent definitions and declarations: */
 
@@ -57,8 +50,8 @@ DATAx (rx) to ACK/NAK/STALL (tx)                    2   7.5    16-60
 #   define lo8(x)   LOW(x)
 #   define hi8(x)   ((x)>>8)    /* not HIGH to allow XLINK to make a proper range check */
 
-    extern  usbRxBuf, usbDeviceAddr, usbNewDeviceAddr, usbInputBuf
-    extern  usbCurrentTok, usbRxLen, usbRxToken, usbAppBuf, usbTxLen
+    extern  usbRxBuf, usbDeviceAddr, usbNewDeviceAddr, usbInputBufOffset
+    extern  usbCurrentTok, usbRxLen, usbRxToken, usbTxLen
     extern  usbTxBuf, usbMsgLen, usbTxLen1, usbTxBuf1, usbTxLen3, usbTxBuf3
     public  usbCrc16
     public  usbCrc16Append
@@ -80,606 +73,9 @@ DATAx (rx) to ACK/NAK/STALL (tx)                    2   7.5    16-60
 
 #endif /* __IAR_SYSTEMS_ASM__ */
 
-
-SIG_INTERRUPT0:
-;Software-receiver engine. Strict timing! Don't change unless you can preserve timing!
-;interrupt response time: 4 cycles + insn running = 7 max if interrupts always enabled
-;max allowable interrupt latency: 32 cycles -> max 25 cycles interrupt disable
-;max stack usage: [ret(2), x1, SREG, x2, cnt, shift, YH, YL, x3, x4] = 11 bytes
-usbInterrupt:
-;order of registers pushed:
-;x1, SREG, x2, cnt, shift, [YH, YL, x3]
-    push    x1              ;2  push only what is necessary to sync with edge ASAP
-    in      x1, SREG        ;1
-    push    x1              ;2
-;sync byte (D-) pattern LSb to MSb: 01010100 [1 = idle = J, 0 = K]
-;sync up with J to K edge during sync pattern -- use fastest possible loops
-;first part has no timeout because it waits for IDLE or SE1 (== disconnected)
-#if !USB_CFG_SAMPLE_EXACT
-    ldi     x1, 5           ;1 setup a timeout for waitForK
-#endif
-waitForJ:
-    sbis    USBIN, USBMINUS ;1 wait for D- == 1
-    rjmp    waitForJ        ;2
-#if USB_CFG_SAMPLE_EXACT
-;The following code represents the unrolled loop in the else branch. It
-;results in a sampling window of 1/4 bit which meets the spec.
-    sbis    USBIN, USBMINUS
-    rjmp    foundK
-    sbis    USBIN, USBMINUS
-    rjmp    foundK
-    sbis    USBIN, USBMINUS
-    rjmp    foundK
-    nop
-    nop2
-foundK:
-#else
-waitForK:
-    dec     x1              ;1
-    sbic    USBIN, USBMINUS ;1 wait for D- == 0
-    brne    waitForK        ;2
-#endif
-;{2, 6} after falling D- edge, average delay: 4 cycles [we want 4 for center sampling]
-;we have 1 bit time for setup purposes, then sample again:
-    push    x2              ;2
-    push    cnt             ;2
-    push    shift           ;2
-shortcutEntry:
-    ldi     cnt, 1          ;1 pre-init bit counter (-1 because no dec follows, -1 because 1 bit already sampled)
-    ldi     x2, 1<<USB_CFG_DPLUS_BIT    ;1 -> 8   edge sync ended with D- == 0
-;now wait until SYNC byte is over. Wait for either 2 bits low (success) or 2 bits high (failure)
-waitNoChange:
-    in      x1, USBIN       ;1 <-- sample, timing: edge + {2, 6} cycles
-    eor     x2, x1          ;1
-    sbrc    x2, USBMINUS    ;1 | 2
-    ldi     cnt, 2          ;1 | 0 cnt = numBits - 1 (because dec follows)
-    mov     x2, x1          ;1
-    dec     cnt             ;1
-    brne    waitNoChange    ;2 | 1
-    sbrc    x1, USBMINUS    ;2
-    rjmp    sofError        ;0 two consecutive "1" bits -> framing error
-;start reading data, but don't check for bitstuffing because these are the
-;first bits. Use the cycles for initialization instead. Note that we read and
-;store the binary complement of the data stream because eor results in 1 for
-;a change and 0 for no change.
-    in      x1, USBIN       ;1 <-- sample bit 0, timing: edge + {3, 7} cycles
-    eor     x2, x1          ;1
-    ldi     shift, 0x00     ;1 prepare for bitstuff check later on in loop
-    bst     x2, USBMINUS    ;1
-    bld     shift, 0        ;1
-    push    YH              ;2 -> 7
-    in      x2, USBIN       ;1 <-- sample bit 1, timing: edge + {2, 6} cycles
-    eor     x1, x2          ;1
-    bst     x1, USBMINUS    ;1
-    bld     shift, 1        ;1
-    push    YL              ;2
-    lds     YL, usbInputBuf ;2 -> 8
-    in      x1, USBIN       ;1 <-- sample bit 2, timing: edge + {2, 6} cycles
-    eor     x2, x1          ;1
-    bst     x2, USBMINUS    ;1
-    bld     shift, 2        ;1
-    ldi     cnt, USB_BUFSIZE;1
-    ldi     YH, hi8(usbRxBuf);1 assume that usbRxBuf does not cross a page
-    push    x3              ;2 -> 8
-    in      x2, USBIN       ;1 <-- sample bit 3, timing: edge + {2, 6} cycles
-    eor     x1, x2          ;1
-    bst     x1, USBMINUS    ;1
-    bld     shift, 3        ;1
-    ser     x3              ;1
-    nop                     ;1
-    rjmp    rxbit4          ;2 -> 8
-
-shortcutToStart:            ;{,43} into next frame: max 5.5 sync bits missed
-#if !USB_CFG_SAMPLE_EXACT
-    ldi     x1, 5           ;2 setup timeout
-#endif
-waitForJ1:
-    sbis    USBIN, USBMINUS ;1 wait for D- == 1
-    rjmp    waitForJ1       ;2
-#if USB_CFG_SAMPLE_EXACT
-;The following code represents the unrolled loop in the else branch. It
-;results in a sampling window of 1/4 bit which meets the spec.
-    sbis    USBIN, USBMINUS
-    rjmp    foundK1
-    sbis    USBIN, USBMINUS
-    rjmp    foundK1
-    sbis    USBIN, USBMINUS
-    rjmp    foundK1
-    nop
-    nop2
-foundK1:
-#else
-waitForK1:
-    dec     x1              ;1
-    sbic    USBIN, USBMINUS ;1 wait for D- == 0
-    brne    waitForK1       ;2
-#endif
-    pop     YH              ;2 correct stack alignment
-    nop2                    ;2 delay for the same time as the pushes in the original code
-    rjmp    shortcutEntry   ;2
-
-; ################# receiver loop #################
-; extra jobs done during bit interval:
-; bit 6:    se0 check
-; bit 7:    or, store, clear
-; bit 0:    recover from delay  [SE0 is unreliable here due to bit dribbling in hubs]
-; bit 1:    se0 check
-; bit 2:    se0 check
-; bit 3:    overflow check
-; bit 4:    se0 check
-; bit 5:    rjmp
-
-; stuffed* helpers have the functionality of a subroutine, but we can't afford
-; the overhead of a call. We therefore need a separate routine for each caller
-; which jumps back appropriately.
-
-stuffed5:               ;1 for branch taken
-    in      x2, USBIN   ;1 <-- sample @ +1
-    andi    x2, USBMASK ;1
-    breq    se0a        ;1
-    andi    x3, ~0x20   ;1
-    ori     shift, 0x20 ;1
-    rjmp    rxbit6      ;2
-
-stuffed6:               ;1 for branch taken
-    in      x1, USBIN   ;1 <-- sample @ +1
-    andi    x1, USBMASK ;1
-    breq    se0a        ;1
-    andi    x3, ~0x40   ;1
-    ori     shift, 0x40 ;1
-    rjmp    rxbit7      ;2
-
-; This is somewhat special because it has to compensate for the delay in bit 7
-stuffed7:               ;1 for branch taken
-    andi    x1, USBMASK ;1 already sampled by caller
-    breq    se0a        ;1
-    mov     x2, x1      ;1 ensure correct NRZI sequence
-    ori     shift, 0x80 ;1 no need to set reconstruction in x3: shift has already been used
-    in      x1, USBIN   ;1 <-- sample bit 0
-    rjmp    unstuffed7  ;2
-
-stuffed0:               ;1 for branch taken
-    in      x1, USBIN   ;1 <-- sample @ +1
-    andi    x1, USBMASK ;1
-    breq    se0a        ;1
-    andi    x3, ~0x01   ;1
-    ori     shift, 0x01 ;1
-    rjmp    rxbit1      ;2
-
-;-----------------------------
-rxLoop:
-    breq    stuffed5    ;1
-rxbit6:
-    in      x1, USBIN   ;1 <-- sample bit 6
-    andi    x1, USBMASK ;1
-    breq    se0a        ;1
-    eor     x2, x1      ;1
-    bst     x2, USBMINUS;1
-    bld     shift, 6    ;1
-    cpi     shift, 0x02 ;1
-    brlo    stuffed6    ;1
-rxbit7:
-    in      x2, USBIN   ;1 <-- sample bit 7
-    eor     x1, x2      ;1
-    bst     x1, USBMINUS;1
-    bld     shift, 7    ;1
-    eor     x3, shift   ;1 x3 is 0 at bit locations we changed, 1 at others
-    st      y+, x3      ;2 the eor above reconstructed modified bits and inverted rx data
-    ser     x3          ;1
-rxbit0:
-    in      x1, USBIN   ;1 <-- sample bit 0
-    cpi     shift, 0x04 ;1
-    brlo    stuffed7    ;1
-unstuffed7:
-    eor     x2, x1      ;1
-    bst     x2, USBMINUS;1
-    bld     shift, 0    ;1
-    andi    shift, 0xf9 ;1
-    breq    stuffed0    ;1
-rxbit1:
-    in      x2, USBIN   ;1 <-- sample bit 1
-    andi    x2, USBMASK ;1
-se0a:                   ; enlarge jump range to SE0
-    breq    se0         ;1 check for SE0 more often close to start of byte
-    eor     x1, x2      ;1
-    bst     x1, USBMINUS;1
-    bld     shift, 1    ;1
-    andi    shift, 0xf3 ;1
-    breq    stuffed1    ;1
-rxbit2:
-    in      x1, USBIN   ;1 <-- sample bit 2
-    andi    x1, USBMASK ;1
-    breq    se0         ;1
-    eor     x2, x1      ;1
-    bst     x2, USBMINUS;1
-    bld     shift, 2    ;1
-    andi    shift, 0xe7 ;1
-    breq    stuffed2    ;1
-rxbit3:
-    in      x2, USBIN   ;1 <-- sample bit 3
-    eor     x1, x2      ;1
-    bst     x1, USBMINUS;1
-    bld     shift, 3    ;1
-    dec     cnt         ;1  check for buffer overflow
-    breq    overflow    ;1
-    andi    shift, 0xcf ;1
-    breq    stuffed3    ;1
-rxbit4:
-    in      x1, USBIN   ;1 <-- sample bit 4
-    andi    x1, USBMASK ;1
-    breq    se0         ;1
-    eor     x2, x1      ;1
-    bst     x2, USBMINUS;1
-    bld     shift, 4    ;1
-    andi    shift, 0x9f ;1
-    breq    stuffed4    ;1
-rxbit5:
-    in      x2, USBIN   ;1 <-- sample bit 5
-    eor     x1, x2      ;1
-    bst     x1, USBMINUS;1
-    bld     shift, 5    ;1
-    andi    shift, 0x3f ;1
-    rjmp    rxLoop      ;2
-;-----------------------------
-
-stuffed1:               ;1 for branch taken
-    in      x2, USBIN   ;1 <-- sample @ +1
-    andi    x2, USBMASK ;1
-    breq    se0         ;1
-    andi    x3, ~0x02   ;1
-    ori     shift, 0x02 ;1
-    rjmp    rxbit2      ;2
-
-stuffed2:               ;1 for branch taken
-    in      x1, USBIN   ;1 <-- sample @ +1
-    andi    x1, USBMASK ;1
-    breq    se0         ;1
-    andi    x3, ~0x04   ;1
-    ori     shift, 0x04 ;1
-    rjmp    rxbit3      ;2
-
-stuffed3:               ;1 for branch taken
-    in      x2, USBIN   ;1 <-- sample @ +1
-    andi    x2, USBMASK ;1
-    breq    se0         ;1
-    andi    x3, ~0x08   ;1
-    ori     shift, 0x08 ;1
-    rjmp    rxbit4      ;2
-
-stuffed4:               ;1 for branch taken
-    in      x1, USBIN   ;1 <-- sample @ +1
-    andi    x1, USBMASK ;1
-    breq    se0         ;1
-    andi    x3, ~0x10   ;1
-    ori     shift, 0x10 ;1
-    rjmp    rxbit5      ;2
-
-;################ end receiver loop ###############
-
-overflow:                   ; ignore package if buffer overflow
-    rjmp    rxDoReturn      ; enlarge jump range
-
-;This is the only non-error exit point for the software receiver loop
-;{4, 20} cycles after start of SE0, typically {10, 18} after SE0 start = {-6, 2} from end of SE0
-;next sync starts {16,} cycles after SE0 -> worst case start: +4 from next sync start
-;we don't check any CRCs here because there is no time left.
-se0:                            ;{-6, 2} from end of SE0 / {,4} into next frame
-    mov     cnt, YL             ;1 assume buffer in lower 256 bytes of memory
-    lds     YL, usbInputBuf     ;2 reposition to buffer start
-    sub     cnt, YL             ;1 length of message
-    ldi     x1, 1<<USB_INTR_PENDING_BIT ;1
-    cpi     cnt, 3              ;1
-    out     USB_INTR_PENDING, x1;1 clear pending intr and check flag later. SE0 must be over. {,10} into next frame
-    brlo    rxDoReturn          ;1 ensure valid packet size, ignore others
-    ld      x1, y               ;2 PID
-    ldd     x2, y+1             ;2 ADDR + 1 bit endpoint number
-    mov     x3, x2              ;1 store for endpoint number
-    andi    x2, 0x7f            ;1 mask endpoint number bit
-    lds     shift, usbDeviceAddr;2
-    cpi     x1, USBPID_SETUP    ;1
-    breq    isSetupOrOut        ;2 -> 19 = {13, 21} from SE0 end
-    cpi     x1, USBPID_OUT      ;1
-    breq    isSetupOrOut        ;2 -> 22 = {16, 24} from SE0 end / {,24} into next frame
-    cpi     x1, USBPID_IN       ;1
-    breq    handleIn            ;1
-#define USB_DATA_MASK   ~(USBPID_DATA0 ^ USBPID_DATA1)
-    andi    x1, USB_DATA_MASK   ;1
-    cpi     x1, USBPID_DATA0 & USB_DATA_MASK ;1
-    brne    rxDoReturn          ;1 not a data PID -- ignore
-isData:
-    lds     x2, usbCurrentTok   ;2
-    tst     x2                  ;1
-    breq    rxDoReturn          ;1 for other device or spontaneous data -- ignore
-    lds     x1, usbRxLen        ;2
-    cpi     x1, 0               ;1
-    brne    sendNakAndReti      ;1 no buffer space available / {30, 38} from SE0 end
-; 2006-03-11: The following two lines fix a problem where the device was not
-; recognized if usbPoll() was called less frequently than once every 4 ms.
-    cpi     cnt, 4              ;1 zero sized data packets are status phase only -- ignore and ack
-    brmi    sendAckAndReti      ;1 keep rx buffer clean -- we must not NAK next SETUP
-    sts     usbRxLen, cnt       ;2 store received data, swap buffers
-    sts     usbRxToken, x2      ;2
-    lds     x1, usbAppBuf       ;2
-    sts     usbAppBuf, YL       ;2
-    sts     usbInputBuf, x1     ;2 buffers now swapped
-    rjmp    sendAckAndReti      ;2 -> {43, 51} from SE0 end
-
-handleIn:                       ; {18, 26} from SE0 end
-    cp      x2, shift           ;1 shift contains our device addr
-    brne    rxDoReturn          ;1 other device
-#if USB_CFG_HAVE_INTRIN_ENDPOINT
-    sbrc    x3, 7               ;2 x3 contains addr + endpoint
-    rjmp    handleIn1           ;0
-#endif
-    lds     cnt, usbTxLen       ;2
-    sbrc    cnt, 4              ;2
-    rjmp    sendCntAndReti      ;0 -> {27, 35} from SE0 end
-    ldi     x1, USBPID_NAK      ;1
-    sts     usbTxLen, x1        ;2 buffer is now free
-    ldi     YL, lo8(usbTxBuf)   ;1
-    ldi     YH, hi8(usbTxBuf)   ;1
-    rjmp    usbSendAndReti      ;2 -> {34, 43} from SE0 end
-
-; Comment about when to set usbTxLen to USBPID_NAK:
-; We should set it back when we receive the ACK from the host. This would
-; be simple to implement: One static variable which stores whether the last
-; tx was for endpoint 0 or 1 and a compare in the receiver to distinguish the
-; ACK. However, we set it back immediately when we send the package,
-; assuming that no error occurs and the host sends an ACK. We save one byte
-; RAM this way and avoid potential problems with endless retries. The rest of
-; the driver assumes error-free transfers anyway.
-
-otherOutOrSetup:
-    clr     x1
-    sts     usbCurrentTok, x1
-rxDoReturn:
-    pop     x3                  ;2
-    pop     YL                  ;2
-    pop     YH                  ;2
-    rjmp    sofError            ;2
-
-isSetupOrOut:                   ; we must be fast here -- a data package may follow / {,24} into next frame
-    cp      x2, shift           ;1 shift contains our device addr
-    brne    otherOutOrSetup     ;1 other device -- ignore
-#if USB_CFG_IMPLEMENT_FN_WRITEOUT   /* if we need second OUT endpoint, store endpoint address */
-    andi    x1, 0x7f            ;1 mask out MSb in token
-    andi    x3, 0x80            ;1 mask out all but endpoint address
-    or      x1, x3              ;1 merge endpoint into currentToken
-    sts     usbCurrentTok, x1   ;2
-    brmi    dontResetEP0        ;1 endpoint 1 -> don't reset endpoint 0 input
-#else
-    sts     usbCurrentTok, x1   ;2
-#endif
-;A transmission can still have data in the output buffer while we receive a
-;SETUP package with an IN phase. To avoid that the old data is sent as a reply,
-;we abort transmission. We don't need to reset usbMsgLen because it is used
-;from the main loop only where the setup is processed anyway.
-    ldi     x1, USBPID_NAK      ;1
-    sts     usbTxLen, x1        ;2 abort transmission
-dontResetEP0:
-    pop     x3                  ;2
-    pop     YL                  ;2
-    in      x1, USB_INTR_PENDING;1
-    sbrc    x1, USB_INTR_PENDING_BIT;1 check whether data is already arriving {,41} into next frame
-    rjmp    shortcutToStart     ;2 save the pops and pushes -- a new interrupt is aready pending
-;If the jump above was not taken, we can be at {,2} into the next frame here
-    pop     YH                  ;2
-txDoReturn:
-sofError:                       ; error in start of frame -- ignore frame
-    ldi     x1, 1<<USB_INTR_PENDING_BIT;1 many int0 events occurred during our processing -- clear pending flag
-    out     USB_INTR_PENDING, x1;1
-    pop     shift               ;2
-    pop     cnt                 ;2
-    pop     x2                  ;2
-    pop     x1                  ;2
-    out     SREG, x1            ;1
-    pop     x1                  ;2
-    reti                        ;4 -> {,21} into next frame -> up to 3 sync bits missed
-
-sendCntAndReti:                 ; 19 cycles until SOP
-    mov     x3, cnt             ;1
-    rjmp    usbSendX3           ;2
-sendNakAndReti:                 ; 19 cycles until SOP
-    ldi     x3, USBPID_NAK      ;1
-    rjmp    usbSendX3           ;2
-sendAckAndReti:                 ; 17 cycles until SOP
-    ldi     x3, USBPID_ACK      ;1
-usbSendX3:
-    ldi     YL, 20              ;1 'x3' is R20
-    ldi     YH, 0               ;1
-    ldi     cnt, 2              ;1
-;;;;rjmp    usbSendAndReti      fallthrough
-
-; USB spec says:
-; idle = J
-; J = (D+ = 0), (D- = 1) or USBOUT = 0x01
-; K = (D+ = 1), (D- = 0) or USBOUT = 0x02
-; Spec allows 7.5 bit times from EOP to SOP for replies (= 60 cycles)
-
-;usbSend:
-;pointer to data in 'Y'
-;number of bytes in 'cnt' -- including sync byte
-;uses: x1...x4, shift, cnt, Y
-usbSendAndReti:             ; SOP starts 13 cycles after call
-    push    x4              ;2
-    ldi     x4, USBMASK     ;1 exor mask
-    sbi     USBOUT, USBMINUS;1 prepare idle state; D+ and D- must have been 0 (no pullups)
-    in      x1, USBOUT      ;1 port mirror for tx loop
-    sbi     USBDDR, USBMINUS;1
-    sbi     USBDDR, USBPLUS ;1 set D+ and D- to output: acquire bus
-; need not init x2 (bitstuff history) because sync starts with 0
-    ldi     shift, 0x80     ;1 sync byte is first byte sent
-    rjmp    txLoop          ;2 -> 13 + 3 = 16 cycles until SOP
-
-#if USB_CFG_HAVE_INTRIN_ENDPOINT    /* placed here due to relative jump range */
-handleIn1:                  ;{23, 31} from SE0
-    ldi     x1, USBPID_NAK  ;1
-#if USB_CFG_HAVE_INTRIN_ENDPOINT3
-; 2006-06-10 as suggested by O.Tamura: support second INTR IN / BULK IN endpoint
-    ldd     x2, y+2         ;2
-    sbrc    x2, 0           ;2 1
-    rjmp    handleIn3       ;0 2
-#endif
-    lds     cnt, usbTxLen1  ;2
-    sbrc    cnt, 4          ;2
-    rjmp    sendCntAndReti  ;0
-    sts     usbTxLen1, x1   ;2
-    ldi     YL, lo8(usbTxBuf1);1
-    ldi     YH, hi8(usbTxBuf1);1
-    rjmp    usbSendAndReti  ;2 -> arrives at usbSendAndReti {34, 42} from SE0
-
-#if USB_CFG_HAVE_INTRIN_ENDPOINT3
-handleIn3:
-    lds     cnt, usbTxLen3  ;2
-    sbrc    cnt, 4          ;2
-    rjmp    sendCntAndReti  ;0
-    sts     usbTxLen3, x1   ;2
-    ldi     YL, lo8(usbTxBuf3);1
-    ldi     YH, hi8(usbTxBuf3);1
-    rjmp    usbSendAndReti  ;2 -> arrives at usbSendAndReti {39, 47} from SE0
-#endif
-#endif
-
-bitstuff0:                  ;1 (for branch taken)
-    eor     x1, x4          ;1
-    ldi     x2, 0           ;1
-    out     USBOUT, x1      ;1 <-- out
-    rjmp    didStuff0       ;2 branch back 2 cycles earlier
-bitstuff1:                  ;1 (for branch taken)
-    eor     x1, x4          ;1
-    ldi     x2, 0           ;1
-    sec                     ;1 set carry so that brsh will not jump
-    out     USBOUT, x1      ;1 <-- out
-    rjmp    didStuff1       ;2 jump back 1 cycle earler
-bitstuff2:                  ;1 (for branch taken)
-    eor     x1, x4          ;1
-    ldi     x2, 0           ;1
-    rjmp    didStuff2       ;2 jump back 3 cycles earlier and do out
-bitstuff3:                  ;1 (for branch taken)
-    eor     x1, x4          ;1
-    ldi     x2, 0           ;1
-    rjmp    didStuff3       ;2 jump back earlier
-
-txLoop:
-    sbrs    shift, 0        ;1
-    eor     x1, x4          ;1
-    out     USBOUT, x1      ;1 <-- out
-    ror     shift           ;1
-    ror     x2              ;1
-didStuff0:
-    cpi     x2, 0xfc        ;1
-    brsh    bitstuff0       ;1
-    sbrs    shift, 0        ;1
-    eor     x1, x4          ;1
-    ror     shift           ;1
-    out     USBOUT, x1      ;1 <-- out
-    ror     x2              ;1
-    cpi     x2, 0xfc        ;1
-didStuff1:
-    brsh    bitstuff1       ;1
-    sbrs    shift, 0        ;1
-    eor     x1, x4          ;1
-    ror     shift           ;1
-    ror     x2              ;1
-didStuff2:
-    out     USBOUT, x1      ;1 <-- out
-    cpi     x2, 0xfc        ;1
-    brsh    bitstuff2       ;1
-    sbrs    shift, 0        ;1
-    eor     x1, x4          ;1
-    ror     shift           ;1
-    ror     x2              ;1
-didStuff3:
-    cpi     x2, 0xfc        ;1
-    out     USBOUT, x1      ;1 <-- out
-    brsh    bitstuff3       ;1
-    nop2                    ;2
-    ld      x3, y+          ;2
-    sbrs    shift, 0        ;1
-    eor     x1, x4          ;1
-    out     USBOUT, x1      ;1 <-- out
-    ror     shift           ;1
-    ror     x2              ;1
-didStuff4:
-    cpi     x2, 0xfc        ;1
-    brsh    bitstuff4       ;1
-    sbrs    shift, 0        ;1
-    eor     x1, x4          ;1
-    ror     shift           ;1
-    out     USBOUT, x1      ;1 <-- out
-    ror     x2              ;1
-    cpi     x2, 0xfc        ;1
-didStuff5:
-    brsh    bitstuff5       ;1
-    sbrs    shift, 0        ;1
-    eor     x1, x4          ;1
-    ror     shift           ;1
-    ror     x2              ;1
-didStuff6:
-    out     USBOUT, x1      ;1 <-- out
-    cpi     x2, 0xfc        ;1
-    brsh    bitstuff6       ;1
-    sbrs    shift, 0        ;1
-    eor     x1, x4          ;1
-    ror     shift           ;1
-    ror     x2              ;1
-didStuff7:
-    cpi     x2, 0xfc        ;1
-    out     USBOUT, x1      ;1 <-- out
-    brsh    bitstuff7       ;1
-    mov     shift, x3       ;1
-    dec     cnt             ;1
-    brne    txLoop          ;2 | 1
-    cbr     x1, USBMASK     ;1 prepare SE0 [spec says EOP may be 15 to 18 cycles]
-    pop     x4              ;2
-    out     USBOUT, x1      ;1 <-- out SE0 -- from now 2 bits = 16 cycles until bus idle
-    ldi     cnt, 2          ;| takes cnt * 3 cycles
-se0Delay:                   ;|
-    dec     cnt             ;|
-    brne    se0Delay        ;| -> 2 * 3 = 6 cycles
-;2006-03-06: moved transfer of new address to usbDeviceAddr from C-Code to asm:
-;set address only after data packet was sent, not after handshake
-    lds     x2, usbNewDeviceAddr;2
-    subi    YL, 20 + 2          ;1
-    sbci    YH, 0               ;1
-    breq    skipAddrAssign      ;2
-    sts     usbDeviceAddr, x2   ;0  if not skipped: SE0 is one cycle longer
-skipAddrAssign:
-;end of usbDeviceAddress transfer
-    ori     x1, USBIDLE     ;1
-    in      x2, USBDDR      ;1
-    cbr     x2, USBMASK     ;1 set both pins to input
-    out     USBOUT, x1      ;1 <-- out J (idle) -- end of SE0 (EOP signal)
-    cbr     x1, USBMASK     ;1 configure no pullup on both pins
-    pop     x3              ;2
-    pop     YL              ;2
-    out     USBDDR, x2      ;1 <-- release bus now
-    out     USBOUT, x1      ;1 set pullup state
-    pop     YH              ;2
-    rjmp    txDoReturn      ;2 [we want to jump to rxDoReturn, but this saves cycles]
-
-
-bitstuff4:                  ;1 (for branch taken)
-    eor     x1, x4          ;1
-    ldi     x2, 0           ;1
-    out     USBOUT, x1      ;1 <-- out
-    rjmp    didStuff4       ;2 jump back 2 cycles earlier
-bitstuff5:                  ;1 (for branch taken)
-    eor     x1, x4          ;1
-    ldi     x2, 0           ;1
-    sec                     ;1 set carry so that brsh is not taken
-    out     USBOUT, x1      ;1 <-- out
-    rjmp    didStuff5       ;2 jump back 1 cycle earlier
-bitstuff6:                  ;1 (for branch taken)
-    eor     x1, x4          ;1
-    ldi     x2, 0           ;1
-    rjmp    didStuff6       ;2 jump back 3 cycles earlier and do out there
-bitstuff7:                  ;1 (for branch taken)
-    eor     x1, x4          ;1
-    ldi     x2, 0           ;1
-    rjmp    didStuff7       ;2 jump back 4 cycles earlier
-
-; ######################## utility functions ########################
+;----------------------------------------------------------------------------
+; Utility functions
+;----------------------------------------------------------------------------
 
 #ifdef __IAR_SYSTEMS_ASM__
 /* Register assignments for usbCrc16 on IAR cc */
@@ -782,3 +178,22 @@ usbCrc16Append:
     st      ptr+, resCrcL
     st      ptr+, resCrcH
     ret
+
+
+;----------------------------------------------------------------------------
+; Now include the clock rate specific code
+;----------------------------------------------------------------------------
+
+#ifndef USB_CFG_CLOCK_KHZ
+#   define USB_CFG_CLOCK_KHZ 12000
+#endif
+
+#if USB_CFG_CLOCK_KHZ == 12000
+#   include "usbdrvasm12.S"
+#elif USB_CFG_CLOCK_KHZ == 16000
+#   include "usbdrvasm16.S"
+#elif USB_CFG_CLOCK_KHZ == 16500
+#   include "usbdrvasm165.S"
+#else
+#   error "USB_CFG_CLOCK_KHZ is not one of the supported rates!"
+#endif
index fba4576..4a5486f 100644 (file)
@@ -4,7 +4,7 @@
  * Creation Date: 2006-03-01
  * Tabsize: 4
  * Copyright: (c) 2006 by OBJECTIVE DEVELOPMENT Software GmbH
- * License: Proprietary, free under certain conditions. See Documentation.
+ * License: GNU GPL v2 (see License.txt) or proprietary (CommercialLicense.txt)
  * This Revision: $Id$
  */
 
diff --git a/firmware/usbdrv/usbdrvasm12.S b/firmware/usbdrv/usbdrvasm12.S
new file mode 100644 (file)
index 0000000..b141e85
--- /dev/null
@@ -0,0 +1,555 @@
+/* Name: usbdrvasm12.S
+ * Project: AVR USB driver
+ * Author: Christian Starkjohann
+ * Creation Date: 2004-12-29
+ * Tabsize: 4
+ * Copyright: (c) 2007 by OBJECTIVE DEVELOPMENT Software GmbH
+ * License: GNU GPL v2 (see License.txt) or proprietary (CommercialLicense.txt)
+ * This Revision: $Id: usbdrvasm12.S 353 2007-06-21 19:05:08Z cs $
+ */
+
+/* Do not link this file! Link usbdrvasm.S instead, which includes the
+ * appropriate implementation!
+ */
+
+/*
+General Description:
+This file is the 12 MHz version of the asssembler part of the USB driver. It
+requires a 12 MHz crystal (not a ceramic resonator and not a calibrated RC
+oscillator).
+
+See usbdrv.h for a description of the entire driver.
+
+Since almost all of this code is timing critical, don't change unless you
+really know what you are doing! Many parts require not only a maximum number
+of CPU cycles, but even an exact number of cycles!
+
+
+Timing constraints according to spec (in bit times):
+timing subject                                      min max    CPUcycles
+---------------------------------------------------------------------------
+EOP of OUT/SETUP to sync pattern of DATA0 (both rx) 2   16     16-128
+EOP of IN to sync pattern of DATA0 (rx, then tx)    2   7.5    16-60
+DATAx (rx) to ACK/NAK/STALL (tx)                    2   7.5    16-60
+*/
+
+;Software-receiver engine. Strict timing! Don't change unless you can preserve timing!
+;interrupt response time: 4 cycles + insn running = 7 max if interrupts always enabled
+;max allowable interrupt latency: 34 cycles -> max 25 cycles interrupt disable
+;max stack usage: [ret(2), YL, SREG, YH, shift, x1, x2, x3, cnt, x4] = 11 bytes
+;Numbers in brackets are maximum cycles since SOF.
+SIG_INTERRUPT0:
+;order of registers pushed: YL, SREG [sofError], YH, shift, x1, x2, x3, cnt
+    push    YL              ;2 [35] push only what is necessary to sync with edge ASAP
+    in      YL, SREG        ;1 [37]
+    push    YL              ;2 [39]
+;----------------------------------------------------------------------------
+; Synchronize with sync pattern:
+;----------------------------------------------------------------------------
+;sync byte (D-) pattern LSb to MSb: 01010100 [1 = idle = J, 0 = K]
+;sync up with J to K edge during sync pattern -- use fastest possible loops
+;first part has no timeout because it waits for IDLE or SE1 (== disconnected)
+waitForJ:
+    sbis    USBIN, USBMINUS ;1 [40] wait for D- == 1
+    rjmp    waitForJ        ;2
+waitForK:
+;The following code results in a sampling window of 1/4 bit which meets the spec.
+    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
+    rjmp    sofError
+foundK:
+;{3, 5} after falling D- edge, average delay: 4 cycles [we want 4 for center sampling]
+;we have 1 bit time for setup purposes, then sample again. Numbers in brackets
+;are cycles from center of first sync (double K) bit after the instruction
+    push    YH                  ;2 [2]
+    lds     YL, usbInputBufOffset;2 [4]
+    clr     YH                  ;1 [5]
+    subi    YL, lo8(-(usbRxBuf));1 [6]
+    sbci    YH, hi8(-(usbRxBuf));1 [7]
+
+    sbis    USBIN, USBMINUS ;1 [8] we want two bits K [sample 1 cycle too early]
+    rjmp    haveTwoBitsK    ;2 [10]
+    pop     YH              ;2 [11] undo the push from before
+    rjmp    waitForK        ;2 [13] this was not the end of sync, retry
+haveTwoBitsK:
+;----------------------------------------------------------------------------
+; push more registers and initialize values while we sample the first bits:
+;----------------------------------------------------------------------------
+    push    shift           ;2 [16]
+    push    x1              ;2 [12]
+    push    x2              ;2 [14]
+
+    in      x1, USBIN       ;1 [17] <-- sample bit 0
+    ldi     shift, 0xff     ;1 [18]
+    bst     x1, USBMINUS    ;1 [19]
+    bld     shift, 0        ;1 [20]
+    push    x3              ;2 [22]
+    push    cnt             ;2 [24]
+
+    in      x2, USBIN       ;1 [25] <-- sample bit 1
+    ser     x3              ;1 [26] [inserted init instruction]
+    eor     x1, x2          ;1 [27]
+    bst     x1, USBMINUS    ;1 [28]
+    bld     shift, 1        ;1 [29]
+    ldi     cnt, USB_BUFSIZE;1 [30] [inserted init instruction]
+    rjmp    rxbit2          ;2 [32]
+
+;----------------------------------------------------------------------------
+; Receiver loop (numbers in brackets are cycles within byte after instr)
+;----------------------------------------------------------------------------
+
+unstuff0:               ;1 (branch taken)
+    andi    x3, ~0x01   ;1 [15]
+    mov     x1, x2      ;1 [16] x2 contains last sampled (stuffed) bit
+    in      x2, USBIN   ;1 [17] <-- sample bit 1 again
+    ori     shift, 0x01 ;1 [18]
+    rjmp    didUnstuff0 ;2 [20]
+
+unstuff1:               ;1 (branch taken)
+    mov     x2, x1      ;1 [21] x1 contains last sampled (stuffed) bit
+    andi    x3, ~0x02   ;1 [22]
+    ori     shift, 0x02 ;1 [23]
+    nop                 ;1 [24]
+    in      x1, USBIN   ;1 [25] <-- sample bit 2 again
+    rjmp    didUnstuff1 ;2 [27]
+
+unstuff2:               ;1 (branch taken)
+    andi    x3, ~0x04   ;1 [29]
+    ori     shift, 0x04 ;1 [30]
+    mov     x1, x2      ;1 [31] x2 contains last sampled (stuffed) bit
+    nop                 ;1 [32]
+    in      x2, USBIN   ;1 [33] <-- sample bit 3
+    rjmp    didUnstuff2 ;2 [35]
+
+unstuff3:               ;1 (branch taken)
+    in      x2, USBIN   ;1 [34] <-- sample stuffed bit 3 [one cycle too late]
+    andi    x3, ~0x08   ;1 [35]
+    ori     shift, 0x08 ;1 [36]
+    rjmp    didUnstuff3 ;2 [38]
+
+unstuff4:               ;1 (branch taken)
+    andi    x3, ~0x10   ;1 [40]
+    in      x1, USBIN   ;1 [41] <-- sample stuffed bit 4
+    ori     shift, 0x10 ;1 [42]
+    rjmp    didUnstuff4 ;2 [44]
+
+unstuff5:               ;1 (branch taken)
+    andi    x3, ~0x20   ;1 [48]
+    in      x2, USBIN   ;1 [49] <-- sample stuffed bit 5
+    ori     shift, 0x20 ;1 [50]
+    rjmp    didUnstuff5 ;2 [52]
+
+unstuff6:               ;1 (branch taken)
+    andi    x3, ~0x40   ;1 [56]
+    in      x1, USBIN   ;1 [57] <-- sample stuffed bit 6
+    ori     shift, 0x40 ;1 [58]
+    rjmp    didUnstuff6 ;2 [60]
+
+; extra jobs done during bit interval:
+; bit 0:    store, clear [SE0 is unreliable here due to bit dribbling in hubs]
+; bit 1:    se0 check
+; bit 2:    overflow check
+; bit 3:    recovery from delay [bit 0 tasks took too long]
+; bit 4:    none
+; bit 5:    none
+; bit 6:    none
+; bit 7:    jump, eor
+rxLoop:
+    eor     x3, shift   ;1 [0] reconstruct: x3 is 0 at bit locations we changed, 1 at others
+    in      x1, USBIN   ;1 [1] <-- sample bit 0
+    st      y+, x3      ;2 [3] store data
+    ser     x3          ;1 [4]
+    nop                 ;1 [5]
+    eor     x2, x1      ;1 [6]
+    bst     x2, USBMINUS;1 [7]
+    bld     shift, 0    ;1 [8]
+    in      x2, USBIN   ;1 [9] <-- sample bit 1 (or possibly bit 0 stuffed)
+    andi    x2, USBMASK ;1 [10]
+    breq    se0         ;1 [11] SE0 check for bit 1
+    andi    shift, 0xf9 ;1 [12]
+didUnstuff0:
+    breq    unstuff0    ;1 [13]
+    eor     x1, x2      ;1 [14]
+    bst     x1, USBMINUS;1 [15]
+    bld     shift, 1    ;1 [16]
+rxbit2:
+    in      x1, USBIN   ;1 [17] <-- sample bit 2 (or possibly bit 1 stuffed)
+    andi    shift, 0xf3 ;1 [18]
+    breq    unstuff1    ;1 [19] do remaining work for bit 1
+didUnstuff1:
+    subi    cnt, 1      ;1 [20]
+    brcs    overflow    ;1 [21] loop control
+    eor     x2, x1      ;1 [22]
+    bst     x2, USBMINUS;1 [23]
+    bld     shift, 2    ;1 [24]
+    in      x2, USBIN   ;1 [25] <-- sample bit 3 (or possibly bit 2 stuffed)
+    andi    shift, 0xe7 ;1 [26]
+    breq    unstuff2    ;1 [27]
+didUnstuff2:
+    eor     x1, x2      ;1 [28]
+    bst     x1, USBMINUS;1 [29]
+    bld     shift, 3    ;1 [30]
+didUnstuff3:
+    andi    shift, 0xcf ;1 [31]
+    breq    unstuff3    ;1 [32]
+    in      x1, USBIN   ;1 [33] <-- sample bit 4
+    eor     x2, x1      ;1 [34]
+    bst     x2, USBMINUS;1 [35]
+    bld     shift, 4    ;1 [36]
+didUnstuff4:
+    andi    shift, 0x9f ;1 [37]
+    breq    unstuff4    ;1 [38]
+    nop2                ;2 [40]
+    in      x2, USBIN   ;1 [41] <-- sample bit 5
+    eor     x1, x2      ;1 [42]
+    bst     x1, USBMINUS;1 [43]
+    bld     shift, 5    ;1 [44]
+didUnstuff5:
+    andi    shift, 0x3f ;1 [45]
+    breq    unstuff5    ;1 [46]
+    nop2                ;2 [48]
+    in      x1, USBIN   ;1 [49] <-- sample bit 6
+    eor     x2, x1      ;1 [50]
+    bst     x2, USBMINUS;1 [51]
+    bld     shift, 6    ;1 [52]
+didUnstuff6:
+    cpi     shift, 0x02 ;1 [53]
+    brlo    unstuff6    ;1 [54]
+    nop2                ;2 [56]
+    in      x2, USBIN   ;1 [57] <-- sample bit 7
+    eor     x1, x2      ;1 [58]
+    bst     x1, USBMINUS;1 [59]
+    bld     shift, 7    ;1 [60]
+didUnstuff7:
+    cpi     shift, 0x04 ;1 [61]
+    brsh    rxLoop      ;2 [63] loop control
+unstuff7:
+    andi    x3, ~0x80   ;1 [63]
+    ori     shift, 0x80 ;1 [64]
+    in      x2, USBIN   ;1 [65] <-- sample stuffed bit 7
+    nop                 ;1 [66]
+    rjmp    didUnstuff7 ;2 [68]
+
+
+;----------------------------------------------------------------------------
+; Processing of received packet (numbers in brackets are cycles after end of SE0)
+;----------------------------------------------------------------------------
+;This is the only non-error exit point for the software receiver loop
+;we don't check any CRCs here because there is no time left.
+#define token   x1
+se0:                            ;  [0]
+    subi    cnt, USB_BUFSIZE    ;1 [1]
+    neg     cnt                 ;1 [2]
+    cpi     cnt, 3              ;1 [3]
+    ldi     x2, 1<<USB_INTR_PENDING_BIT ;1 [4]
+    out     USB_INTR_PENDING, x2;1 [5] clear pending intr and check flag later. SE0 should be over.
+    brlo    doReturn            ;1 [6] this is probably an ACK, NAK or similar packet
+    sub     YL, cnt             ;1 [7]
+    sbci    YH, 0               ;1 [8]
+    ld      token, y            ;2 [10]
+    cpi     token, USBPID_DATA0 ;1 [11]
+    breq    handleData          ;1 [12]
+    cpi     token, USBPID_DATA1 ;1 [13]
+    breq    handleData          ;1 [14]
+    ldd     x2, y+1             ;2 [16] ADDR and 1 bit endpoint number
+    mov     x3, x2              ;1 [17] store for endpoint number
+    andi    x2, 0x7f            ;1 [18] x2 is now ADDR
+    lds     shift, usbDeviceAddr;2 [20]
+    cp      x2, shift           ;1 [21]
+overflow:                       ; This is a hack: brcs overflow will never have Z flag set
+    brne    ignorePacket        ;1 [22] packet for different address
+    cpi     token, USBPID_IN    ;1 [23]
+    breq    handleIn            ;1 [24]
+    cpi     token, USBPID_SETUP ;1 [25]
+    breq    handleSetupOrOut    ;1 [26]
+    cpi     token, USBPID_OUT   ;1 [27]
+    breq    handleSetupOrOut    ;1 [28]
+;   rjmp    ignorePacket        ;fallthrough, should not happen anyway.
+
+ignorePacket:
+    clr     shift
+    sts     usbCurrentTok, shift
+doReturn:
+    pop     cnt
+    pop     x3
+    pop     x2
+    pop     x1
+    pop     shift
+    pop     YH
+sofError:
+    pop     YL
+    out     SREG, YL
+    pop     YL
+    reti
+
+#if USB_CFG_HAVE_INTRIN_ENDPOINT && USB_CFG_HAVE_INTRIN_ENDPOINT3
+handleIn3:                      ;1 [38] (branch taken)
+    lds     cnt, usbTxLen3      ;2 [40]
+    sbrc    cnt, 4              ;2 [42]
+    rjmp    sendCntAndReti      ;0 43 + 17 = 60 until SOP
+    sts     usbTxLen3, x1       ;2 [44] x1 == USBPID_NAK from above
+    ldi     YL, lo8(usbTxBuf3)  ;1 [45]
+    ldi     YH, hi8(usbTxBuf3)  ;1 [46]
+    rjmp    usbSendAndReti      ;2 [48] + 13 = 61 until SOP (violates the spec by 1 cycle)
+#endif
+
+;Setup and Out are followed by a data packet two bit times (16 cycles) after
+;the end of SE0. The sync code allows up to 40 cycles delay from the start of
+;the sync pattern until the first bit is sampled. That's a total of 56 cycles.
+handleSetupOrOut:               ;1 [29] (branch taken)
+#if USB_CFG_IMPLEMENT_FN_WRITEOUT   /* if we have data for second OUT endpoint, set usbCurrentTok to -1 */
+    sbrc    x3, 7               ;1 [30] skip if endpoint 0
+    ldi     token, -1           ;1 [31] indicate that this is endpoint 1 OUT
+#endif
+    sts     usbCurrentTok, token;2 [33]
+    pop     cnt                 ;2 [35]
+    pop     x3                  ;2 [37]
+    pop     x2                  ;2 [39]
+    pop     x1                  ;2 [41]
+    pop     shift               ;2 [43]
+    pop     YH                  ;2 [45]
+    in      YL, USB_INTR_PENDING;1 [46]
+    sbrc    YL, USB_INTR_PENDING_BIT;1 [47] check whether data is already arriving
+    rjmp    waitForJ            ;2 [49] save the pops and pushes -- a new interrupt is aready pending
+    rjmp    sofError            ;2 not an error, but it does the pops and reti we want
+
+
+handleData:                     ;1 [15] (branch taken)
+    lds     token, usbCurrentTok;2 [17]
+    tst     token               ;1 [18]
+    breq    doReturn            ;1 [19]
+    lds     x2, usbRxLen        ;2 [21]
+    tst     x2                  ;1 [22]
+    brne    sendNakAndReti      ;1 [23]
+; 2006-03-11: The following two lines fix a problem where the device was not
+; recognized if usbPoll() was called less frequently than once every 4 ms.
+    cpi     cnt, 4              ;1 [24] zero sized data packets are status phase only -- ignore and ack
+    brmi    sendAckAndReti      ;1 [25] keep rx buffer clean -- we must not NAK next SETUP
+    sts     usbRxLen, cnt       ;2 [27] store received data, swap buffers
+    sts     usbRxToken, token   ;2 [29]
+    lds     x2, usbInputBufOffset;2 [31] swap buffers
+    ldi     cnt, USB_BUFSIZE    ;1 [32]
+    sub     cnt, x2             ;1 [33]
+    sts     usbInputBufOffset, cnt;2 [35] buffers now swapped
+    rjmp    sendAckAndReti      ;2 [37] + 19 = 56 until SOP
+
+handleIn:                       ;1 [25] (branch taken)
+;We don't send any data as long as the C code has not processed the current
+;input data and potentially updated the output data. That's more efficient
+;in terms of code size than clearing the tx buffers when a packet is received.
+    lds     x1, usbRxLen        ;2 [27]
+    cpi     x1, 1               ;1 [28] negative values are flow control, 0 means "buffer free"
+    brge    sendNakAndReti      ;1 [29] unprocessed input packet?
+    ldi     x1, USBPID_NAK      ;1 [30] prepare value for usbTxLen
+#if USB_CFG_HAVE_INTRIN_ENDPOINT
+    sbrc    x3, 7               ;2 [33] x3 contains addr + endpoint
+    rjmp    handleIn1           ;0
+#endif
+    lds     cnt, usbTxLen       ;2 [34]
+    sbrc    cnt, 4              ;2 [36] all handshake tokens have bit 4 set
+    rjmp    sendCntAndReti      ;0 37 + 17 = 54 until SOP
+    sts     usbTxLen, x1        ;2 [38] x1 == USBPID_NAK from above
+    ldi     YL, lo8(usbTxBuf)   ;1 [39]
+    ldi     YH, hi8(usbTxBuf)   ;1 [40]
+    rjmp    usbSendAndReti      ;2 [42] + 14 = 56 until SOP
+
+; Comment about when to set usbTxLen to USBPID_NAK:
+; We should set it back when we receive the ACK from the host. This would
+; be simple to implement: One static variable which stores whether the last
+; tx was for endpoint 0 or 1 and a compare in the receiver to distinguish the
+; ACK. However, we set it back immediately when we send the package,
+; assuming that no error occurs and the host sends an ACK. We save one byte
+; RAM this way and avoid potential problems with endless retries. The rest of
+; the driver assumes error-free transfers anyway.
+
+#if USB_CFG_HAVE_INTRIN_ENDPOINT    /* placed here due to relative jump range */
+handleIn1:                      ;1 [33] (branch taken)
+#if USB_CFG_HAVE_INTRIN_ENDPOINT3
+; 2006-06-10 as suggested by O.Tamura: support second INTR IN / BULK IN endpoint
+    ldd     x2, y+2             ;2 [35]
+    sbrc    x2, 0               ;2 [37]
+    rjmp    handleIn3           ;0
+#endif
+    lds     cnt, usbTxLen1      ;2 [39]
+    sbrc    cnt, 4              ;2 [41] all handshake tokens have bit 4 set
+    rjmp    sendCntAndReti      ;0 42 + 17 = 59 until SOP
+    sts     usbTxLen1, x1       ;2 [43] x1 == USBPID_NAK from above
+    ldi     YL, lo8(usbTxBuf1)  ;1 [44]
+    ldi     YH, hi8(usbTxBuf1)  ;1 [45]
+    rjmp    usbSendAndReti      ;2 [47] + 13 = 60 until SOP
+#endif
+
+
+;----------------------------------------------------------------------------
+; Transmitting data
+;----------------------------------------------------------------------------
+
+bitstuff0:                  ;1 (for branch taken)
+    eor     x1, x4          ;1
+    ldi     x2, 0           ;1
+    out     USBOUT, x1      ;1 <-- out
+    rjmp    didStuff0       ;2 branch back 2 cycles earlier
+bitstuff1:                  ;1 (for branch taken)
+    eor     x1, x4          ;1
+    rjmp    didStuff1       ;2 we know that C is clear, jump back to do OUT and ror 0 into x2
+bitstuff2:                  ;1 (for branch taken)
+    eor     x1, x4          ;1
+    rjmp    didStuff2       ;2 jump back 4 cycles earlier and do out and ror 0 into x2
+bitstuff3:                  ;1 (for branch taken)
+    eor     x1, x4          ;1
+    rjmp    didStuff3       ;2 jump back earlier and ror 0 into x2
+bitstuff4:                  ;1 (for branch taken)
+    eor     x1, x4          ;1
+    ldi     x2, 0           ;1
+    out     USBOUT, x1      ;1 <-- out
+    rjmp    didStuff4       ;2 jump back 2 cycles earlier
+
+sendNakAndReti:                 ;0 [-19] 19 cycles until SOP
+    ldi     x3, USBPID_NAK      ;1 [-18]
+    rjmp    usbSendX3           ;2 [-16]
+sendAckAndReti:                 ;0 [-19] 19 cycles until SOP
+    ldi     x3, USBPID_ACK      ;1 [-18]
+    rjmp    usbSendX3           ;2 [-16]
+sendCntAndReti:                 ;0 [-17] 17 cycles until SOP
+    mov     x3, cnt             ;1 [-16]
+usbSendX3:                      ;0 [-16]
+    ldi     YL, 20              ;1 [-15] 'x3' is R20
+    ldi     YH, 0               ;1 [-14]
+    ldi     cnt, 2              ;1 [-13]
+;   rjmp    usbSendAndReti      fallthrough
+
+; USB spec says:
+; idle = J
+; J = (D+ = 0), (D- = 1) or USBOUT = 0x01
+; K = (D+ = 1), (D- = 0) or USBOUT = 0x02
+; Spec allows 7.5 bit times from EOP to SOP for replies (= 60 cycles)
+
+;usbSend:
+;pointer to data in 'Y'
+;number of bytes in 'cnt' -- including sync byte
+;uses: x1...x4, shift, cnt, Y
+;Numbers in brackets are time since first bit of sync pattern is sent
+usbSendAndReti:             ;0 [-13] timing: 13 cycles until SOP
+    in      x2, USBDDR      ;1 [-12]
+    ori     x2, USBMASK     ;1 [-11]
+    sbi     USBOUT, USBMINUS;2 [-9] prepare idle state; D+ and D- must have been 0 (no pullups)
+    in      x1, USBOUT      ;1 [-8] port mirror for tx loop
+    out     USBDDR, x2      ;1 [-7] <- acquire bus
+; need not init x2 (bitstuff history) because sync starts with 0
+    push    x4              ;2 [-5]
+    ldi     x4, USBMASK     ;1 [-4] exor mask
+    ldi     shift, 0x80     ;1 [-3] sync byte is first byte sent
+txLoop:                     ;       [62]
+    sbrs    shift, 0        ;1 [-2] [62]
+    eor     x1, x4          ;1 [-1] [63]
+    out     USBOUT, x1      ;1 [0] <-- out bit 0
+    ror     shift           ;1 [1]
+    ror     x2              ;1 [2]
+didStuff0:
+    cpi     x2, 0xfc        ;1 [3]
+    brsh    bitstuff0       ;1 [4]
+    sbrs    shift, 0        ;1 [5]
+    eor     x1, x4          ;1 [6]
+    ror     shift           ;1 [7]
+didStuff1:
+    out     USBOUT, x1      ;1 [8] <-- out bit 1
+    ror     x2              ;1 [9]
+    cpi     x2, 0xfc        ;1 [10]
+    brsh    bitstuff1       ;1 [11]
+    sbrs    shift, 0        ;1 [12]
+    eor     x1, x4          ;1 [13]
+    ror     shift           ;1 [14]
+didStuff2:
+    ror     x2              ;1 [15]
+    out     USBOUT, x1      ;1 [16] <-- out bit 2
+    cpi     x2, 0xfc        ;1 [17]
+    brsh    bitstuff2       ;1 [18]
+    sbrs    shift, 0        ;1 [19]
+    eor     x1, x4          ;1 [20]
+    ror     shift           ;1 [21]
+didStuff3:
+    ror     x2              ;1 [22]
+    cpi     x2, 0xfc        ;1 [23]
+    out     USBOUT, x1      ;1 [24] <-- out bit 3
+    brsh    bitstuff3       ;1 [25]
+    nop2                    ;2 [27]
+    ld      x3, y+          ;2 [29]
+    sbrs    shift, 0        ;1 [30]
+    eor     x1, x4          ;1 [31]
+    out     USBOUT, x1      ;1 [32] <-- out bit 4
+    ror     shift           ;1 [33]
+    ror     x2              ;1 [34]
+didStuff4:
+    cpi     x2, 0xfc        ;1 [35]
+    brsh    bitstuff4       ;1 [36]
+    sbrs    shift, 0        ;1 [37]
+    eor     x1, x4          ;1 [38]
+    ror     shift           ;1 [39]
+didStuff5:
+    out     USBOUT, x1      ;1 [40] <-- out bit 5
+    ror     x2              ;1 [41]
+    cpi     x2, 0xfc        ;1 [42]
+    brsh    bitstuff5       ;1 [43]
+    sbrs    shift, 0        ;1 [44]
+    eor     x1, x4          ;1 [45]
+    ror     shift           ;1 [46]
+didStuff6:
+    ror     x2              ;1 [47]
+    out     USBOUT, x1      ;1 [48] <-- out bit 6
+    cpi     x2, 0xfc        ;1 [49]
+    brsh    bitstuff6       ;1 [50]
+    sbrs    shift, 0        ;1 [51]
+    eor     x1, x4          ;1 [52]
+    ror     shift           ;1 [53]
+didStuff7:
+    ror     x2              ;1 [54]
+    cpi     x2, 0xfc        ;1 [55]
+    out     USBOUT, x1      ;1 [56] <-- out bit 7
+    brsh    bitstuff7       ;1 [57]
+    mov     shift, x3       ;1 [58]
+    dec     cnt             ;1 [59]
+    brne    txLoop          ;1/2 [60/61]
+;make SE0:
+    cbr     x1, USBMASK     ;1 [61] prepare SE0 [spec says EOP may be 15 to 18 cycles]
+    pop     x4              ;2 [63]
+;brackets are cycles from start of SE0 now
+    out     USBOUT, x1      ;1 [0] <-- out SE0 -- from now 2 bits = 16 cycles until bus idle
+    nop2                    ;2 [2]
+;2006-03-06: moved transfer of new address to usbDeviceAddr from C-Code to asm:
+;set address only after data packet was sent, not after handshake
+    lds     x2, usbNewDeviceAddr;2 [4]
+    subi    YL, 20 + 2      ;1 [5]
+    sbci    YH, 0           ;1 [6]
+    breq    skipAddrAssign  ;2 [8]
+    sts     usbDeviceAddr, x2;0  if not skipped: SE0 is one cycle longer
+skipAddrAssign:
+;end of usbDeviceAddress transfer
+    ldi     x2, 1<<USB_INTR_PENDING_BIT;1 [9] int0 occurred during TX -- clear pending flag
+    out     USB_INTR_PENDING, x2;1 [10]
+    ori     x1, USBIDLE     ;1 [11]
+    in      x2, USBDDR      ;1 [12]
+    cbr     x2, USBMASK     ;1 [13] set both pins to input
+    mov     x3, x1          ;1 [14]
+    cbr     x3, USBMASK     ;1 [15] configure no pullup on both pins
+    out     USBOUT, x1      ;1 [16] <-- out J (idle) -- end of SE0 (EOP signal)
+    out     USBDDR, x2      ;1 [17] <-- release bus now
+    out     USBOUT, x3      ;1 [18] <-- ensure no pull-up resistors are active
+    rjmp    doReturn
+
+bitstuff5:                  ;1 (for branch taken)
+    eor     x1, x4          ;1
+    rjmp    didStuff5       ;2 same trick as above...
+bitstuff6:                  ;1 (for branch taken)
+    eor     x1, x4          ;1
+    rjmp    didStuff6       ;2 same trick as above...
+bitstuff7:                  ;1 (for branch taken)
+    eor     x1, x4          ;1
+    rjmp    didStuff7       ;2 same trick as above...
diff --git a/firmware/usbdrv/usbdrvasm16.S b/firmware/usbdrv/usbdrvasm16.S
new file mode 100644 (file)
index 0000000..ae4121d
--- /dev/null
@@ -0,0 +1,467 @@
+/* Name: usbdrvasm16.S
+ * Project: AVR USB driver
+ * Author: Christian Starkjohann
+ * Creation Date: 2007-06-15
+ * Tabsize: 4
+ * Copyright: (c) 2007 by OBJECTIVE DEVELOPMENT Software GmbH
+ * License: GNU GPL v2 (see License.txt) or proprietary (CommercialLicense.txt)
+ * Revision: $Id$
+ */
+
+/* Do not link this file! Link usbdrvasm.S instead, which includes the
+ * appropriate implementation!
+ */
+
+/*
+General Description:
+This file is the 16 MHz version of the asssembler part of the USB driver. It
+requires a 16 MHz crystal (not a ceramic resonator and not a calibrated RC
+oscillator).
+
+See usbdrv.h for a description of the entire driver.
+
+Since almost all of this code is timing critical, don't change unless you
+really know what you are doing! Many parts require not only a maximum number
+of CPU cycles, but even an exact number of cycles!
+*/
+
+;max stack usage: [ret(2), YL, SREG, YH, bitcnt, shift, x1, x2, x3, x4, cnt] = 12 bytes
+;nominal frequency: 16 MHz -> 10.6666666 cycles per bit, 85.333333333 cycles per byte
+; Numbers in brackets are clocks counted from center of last sync bit
+; when instruction starts
+
+SIG_INTERRUPT0:
+;order of registers pushed: YL, SREG YH, [sofError], bitcnt, shift, x1, x2, x3, x4, cnt
+    push    YL                  ;[-25] push only what is necessary to sync with edge ASAP
+    in      YL, SREG            ;[-23]
+    push    YL                  ;[-22]
+    push    YH                  ;[-20]
+;----------------------------------------------------------------------------
+; Synchronize with sync pattern:
+;----------------------------------------------------------------------------
+;sync byte (D-) pattern LSb to MSb: 01010100 [1 = idle = J, 0 = K]
+;sync up with J to K edge during sync pattern -- use fastest possible loops
+;first part has no timeout because it waits for IDLE or SE1 (== disconnected)
+waitForJ:
+    sbis    USBIN, USBMINUS     ;[-18] wait for D- == 1
+    rjmp    waitForJ
+waitForK:
+;The following code results in a sampling window of < 1/4 bit which meets the spec.
+    sbis    USBIN, USBMINUS     ;[-15]
+    rjmp    foundK              ;[-14]
+    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
+    rjmp    sofError
+foundK:                         ;[-12]
+;{3, 5} after falling D- edge, average delay: 4 cycles [we want 5 for center sampling]
+;we have 1 bit time for setup purposes, then sample again. Numbers in brackets
+;are cycles from center of first sync (double K) bit after the instruction
+    push    bitcnt              ;[-12]
+;   [---]                       ;[-11]
+    lds     YL, usbInputBufOffset;[-10]
+;   [---]                       ;[-9]
+    clr     YH                  ;[-8]
+    subi    YL, lo8(-(usbRxBuf));[-7] [rx loop init]
+    sbci    YH, hi8(-(usbRxBuf));[-6] [rx loop init]
+    push    shift               ;[-5]
+;   [---]                       ;[-4]
+    ldi     bitcnt, 0x55        ;[-3] [rx loop init]
+    sbis    USBIN, USBMINUS     ;[-2] we want two bits K (sample 2 cycles too early)
+    rjmp    haveTwoBitsK        ;[-1]
+    pop     shift               ;[0] undo the push from before
+    pop     bitcnt              ;[2] undo the push from before
+    rjmp    waitForK            ;[4] this was not the end of sync, retry
+; The entire loop from waitForK until rjmp waitForK above must not exceed two
+; bit times (= 21 cycles).
+
+;----------------------------------------------------------------------------
+; push more registers and initialize values while we sample the first bits:
+;----------------------------------------------------------------------------
+haveTwoBitsK:
+    push    x1              ;[1]
+    push    x2              ;[3]
+    push    x3              ;[5]
+    ldi     shift, 0        ;[7]
+    ldi     x3, 1<<4        ;[8] [rx loop init] first sample is inverse bit, compensate that
+    push    x4              ;[9] == leap
+
+    in      x1, USBIN       ;[11] <-- sample bit 0
+    andi    x1, USBMASK     ;[12]
+    bst     x1, USBMINUS    ;[13]
+    bld     shift, 7        ;[14]
+    push    cnt             ;[15]
+    ldi     leap, 0         ;[17] [rx loop init]
+    ldi     cnt, USB_BUFSIZE;[18] [rx loop init]
+    rjmp    rxbit1          ;[19] arrives at [21]
+
+;----------------------------------------------------------------------------
+; Receiver loop (numbers in brackets are cycles within byte after instr)
+;----------------------------------------------------------------------------
+
+unstuff6:
+    andi    x2, USBMASK ;[03]
+    ori     x3, 1<<6    ;[04] will not be shifted any more
+    andi    shift, ~0x80;[05]
+    mov     x1, x2      ;[06] sampled bit 7 is actually re-sampled bit 6
+    subi    leap, 3     ;[07] since this is a short (10 cycle) bit, enforce leap bit
+    rjmp    didUnstuff6 ;[08]
+
+unstuff7:
+    ori     x3, 1<<7    ;[09] will not be shifted any more
+    in      x2, USBIN   ;[00] [10]  re-sample bit 7
+    andi    x2, USBMASK ;[01]
+    andi    shift, ~0x80;[02]
+    subi    leap, 3     ;[03] since this is a short (10 cycle) bit, enforce leap bit
+    rjmp    didUnstuff7 ;[04]
+
+unstuffEven:
+    ori     x3, 1<<6    ;[09] will be shifted right 6 times for bit 0
+    in      x1, USBIN   ;[00] [10]
+    andi    shift, ~0x80;[01]
+    andi    x1, USBMASK ;[02]
+    breq    se0         ;[03]
+    subi    leap, 3     ;[04] since this is a short (10 cycle) bit, enforce leap bit
+    nop                 ;[05]
+    rjmp    didUnstuffE ;[06]
+
+unstuffOdd:
+    ori     x3, 1<<5    ;[09] will be shifted right 4 times for bit 1
+    in      x2, USBIN   ;[00] [10]
+    andi    shift, ~0x80;[01]
+    andi    x2, USBMASK ;[02]
+    breq    se0         ;[03]
+    subi    leap, 3     ;[04] since this is a short (10 cycle) bit, enforce leap bit
+    nop                 ;[05]
+    rjmp    didUnstuffO ;[06]
+
+rxByteLoop:
+    andi    x1, USBMASK ;[03]
+    eor     x2, x1      ;[04]
+    subi    leap, 1     ;[05]
+    brpl    skipLeap    ;[06]
+    subi    leap, -3    ;1 one leap cycle every 3rd byte -> 85 + 1/3 cycles per byte
+    nop                 ;1
+skipLeap:
+    subi    x2, 1       ;[08]
+    ror     shift       ;[09]
+didUnstuff6:
+    cpi     shift, 0xfc ;[10]
+    in      x2, USBIN   ;[00] [11] <-- sample bit 7
+    brcc    unstuff6    ;[01]
+    andi    x2, USBMASK ;[02]
+    eor     x1, x2      ;[03]
+    subi    x1, 1       ;[04]
+    ror     shift       ;[05]
+didUnstuff7:
+    cpi     shift, 0xfc ;[06]
+    brcc    unstuff7    ;[07]
+    eor     x3, shift   ;[08] reconstruct: x3 is 1 at bit locations we changed, 0 at others
+    st      y+, x3      ;[09] store data
+rxBitLoop:
+    in      x1, USBIN   ;[00] [11] <-- sample bit 0/2/4
+    andi    x1, USBMASK ;[01]
+    eor     x2, x1      ;[02]
+    andi    x3, 0x3f    ;[03] topmost two bits reserved for 6 and 7
+    subi    x2, 1       ;[04]
+    ror     shift       ;[05]
+    cpi     shift, 0xfc ;[06]
+    brcc    unstuffEven ;[07]
+didUnstuffE:
+    lsr     x3          ;[08]
+    lsr     x3          ;[09]
+rxbit1:
+    in      x2, USBIN   ;[00] [10] <-- sample bit 1/3/5
+    andi    x2, USBMASK ;[01]
+    breq    se0         ;[02]
+    eor     x1, x2      ;[03]
+    subi    x1, 1       ;[04]
+    ror     shift       ;[05]
+    cpi     shift, 0xfc ;[06]
+    brcc    unstuffOdd  ;[07]
+didUnstuffO:
+    subi    bitcnt, 0xab;[08] == addi 0x55, 0x55 = 0x100/3
+    brcs    rxBitLoop   ;[09]
+
+    subi    cnt, 1      ;[10]
+    in      x1, USBIN   ;[00] [11] <-- sample bit 6
+    brcc    rxByteLoop  ;[01]
+    rjmp    ignorePacket; overflow
+
+;----------------------------------------------------------------------------
+; Processing of received packet (numbers in brackets are cycles after center of SE0)
+;----------------------------------------------------------------------------
+;This is the only non-error exit point for the software receiver loop
+;we don't check any CRCs here because there is no time left.
+#define token   x1
+se0:
+    subi    cnt, USB_BUFSIZE    ;[5]
+    neg     cnt                 ;[6]
+    cpi     cnt, 3              ;[7]
+    ldi     x2, 1<<USB_INTR_PENDING_BIT ;[8]
+    out     USB_INTR_PENDING, x2;[9] clear pending intr and check flag later. SE0 should be over.
+    brlo    doReturn            ;[10] this is probably an ACK, NAK or similar packet
+    sub     YL, cnt             ;[11]
+    sbci    YH, 0               ;[12]
+    ld      token, y            ;[13]
+    cpi     token, USBPID_DATA0 ;[15]
+    breq    handleData          ;[16]
+    cpi     token, USBPID_DATA1 ;[17]
+    breq    handleData          ;[18]
+    ldd     x2, y+1             ;[19] ADDR and 1 bit endpoint number
+    mov     x3, x2              ;[21] store for endpoint number
+    andi    x2, 0x7f            ;[22] x2 is now ADDR
+    lds     shift, usbDeviceAddr;[23]
+    cp      x2, shift           ;[25]
+overflow:                       ; This is a hack: brcs overflow will never have Z flag set
+    brne    ignorePacket        ;[26] packet for different address
+    cpi     token, USBPID_IN    ;[27]
+    breq    handleIn            ;[28]
+    cpi     token, USBPID_SETUP ;[29]
+    breq    handleSetupOrOut    ;[30]
+    cpi     token, USBPID_OUT   ;[31]
+    breq    handleSetupOrOut    ;[32]
+;   rjmp    ignorePacket        ;fallthrough, should not happen anyway.
+
+ignorePacket:
+    clr     shift
+    sts     usbCurrentTok, shift
+doReturn:
+    pop     cnt
+    pop     x4
+    pop     x3
+    pop     x2
+    pop     x1
+    pop     shift
+    pop     bitcnt
+sofError:
+    pop     YH
+    pop     YL
+    out     SREG, YL
+    pop     YL
+    reti
+
+#if USB_CFG_HAVE_INTRIN_ENDPOINT && USB_CFG_HAVE_INTRIN_ENDPOINT3
+handleIn3:
+    lds     cnt, usbTxLen3      ;[43]
+    sbrc    cnt, 4              ;[45]
+    rjmp    sendCntAndReti      ;[46] 48 + 16 = 64 until SOP
+    sts     usbTxLen3, x1       ;[47] x1 == USBPID_NAK from above
+    ldi     YL, lo8(usbTxBuf3)  ;[49]
+    ldi     YH, hi8(usbTxBuf3)  ;[50]
+    rjmp    usbSendAndReti      ;[51] 53 + 12 = 65 until SOP
+#endif
+
+;Setup and Out are followed by a data packet two bit times (16 cycles) after
+;the end of SE0. The sync code allows up to 40 cycles delay from the start of
+;the sync pattern until the first bit is sampled. That's a total of 56 cycles.
+handleSetupOrOut:               ;[34]
+#if USB_CFG_IMPLEMENT_FN_WRITEOUT   /* if we have data for second OUT endpoint, set usbCurrentTok to -1 */
+    sbrc    x3, 7               ;[34] skip if endpoint 0
+    ldi     token, -1           ;[35] indicate that this is endpoint 1 OUT
+#endif
+    sts     usbCurrentTok, token;[36]
+    pop     cnt                 ;[38]
+    pop     x4                  ;[40]
+    pop     x3                  ;[42]
+    pop     x2                  ;[44]
+    pop     x1                  ;[46]
+    pop     shift               ;[48]
+    pop     bitcnt              ;[50]
+    in      YL, USB_INTR_PENDING;[52]
+    sbrc    YL, USB_INTR_PENDING_BIT;[53] check whether data is already arriving
+    rjmp    waitForJ            ;[54] save the pops and pushes -- a new interrupt is aready pending
+    rjmp    sofError            ;[55] not an error, but it does the pops and reti we want
+
+
+handleData:
+    lds     token, usbCurrentTok;[20]
+    tst     token               ;[22]
+    breq    doReturn            ;[23]
+    lds     x2, usbRxLen        ;[24]
+    tst     x2                  ;[26]
+    brne    sendNakAndReti      ;[27]
+; 2006-03-11: The following two lines fix a problem where the device was not
+; recognized if usbPoll() was called less frequently than once every 4 ms.
+    cpi     cnt, 4              ;[28] zero sized data packets are status phase only -- ignore and ack
+    brmi    sendAckAndReti      ;[29] keep rx buffer clean -- we must not NAK next SETUP
+    sts     usbRxLen, cnt       ;[30] store received data, swap buffers
+    sts     usbRxToken, token   ;[32]
+    lds     x2, usbInputBufOffset;[34] swap buffers
+    ldi     cnt, USB_BUFSIZE    ;[36]
+    sub     cnt, x2             ;[37]
+    sts     usbInputBufOffset, cnt;[38] buffers now swapped
+    rjmp    sendAckAndReti      ;[40] 42 + 17 = 59 until SOP
+
+handleIn:
+;We don't send any data as long as the C code has not processed the current
+;input data and potentially updated the output data. That's more efficient
+;in terms of code size than clearing the tx buffers when a packet is received.
+    lds     x1, usbRxLen        ;[30]
+    cpi     x1, 1               ;[32] negative values are flow control, 0 means "buffer free"
+    brge    sendNakAndReti      ;[33] unprocessed input packet?
+    ldi     x1, USBPID_NAK      ;[34] prepare value for usbTxLen
+#if USB_CFG_HAVE_INTRIN_ENDPOINT
+    sbrc    x3, 7               ;[35] x3 contains addr + endpoint
+    rjmp    handleIn1           ;[36]
+#endif
+    lds     cnt, usbTxLen       ;[37]
+    sbrc    cnt, 4              ;[39] all handshake tokens have bit 4 set
+    rjmp    sendCntAndReti      ;[40] 42 + 16 = 58 until SOP
+    sts     usbTxLen, x1        ;[41] x1 == USBPID_NAK from above
+    ldi     YL, lo8(usbTxBuf)   ;[43]
+    ldi     YH, hi8(usbTxBuf)   ;[44]
+    rjmp    usbSendAndReti      ;[45] 47 + 12 = 59 until SOP
+
+; Comment about when to set usbTxLen to USBPID_NAK:
+; We should set it back when we receive the ACK from the host. This would
+; be simple to implement: One static variable which stores whether the last
+; tx was for endpoint 0 or 1 and a compare in the receiver to distinguish the
+; ACK. However, we set it back immediately when we send the package,
+; assuming that no error occurs and the host sends an ACK. We save one byte
+; RAM this way and avoid potential problems with endless retries. The rest of
+; the driver assumes error-free transfers anyway.
+
+#if USB_CFG_HAVE_INTRIN_ENDPOINT    /* placed here due to relative jump range */
+handleIn1:                      ;[38]
+#if USB_CFG_HAVE_INTRIN_ENDPOINT3
+; 2006-06-10 as suggested by O.Tamura: support second INTR IN / BULK IN endpoint
+    ldd     x2, y+2             ;[38]
+    sbrc    x2, 0               ;[40]
+    rjmp    handleIn3           ;[41]
+#endif
+    lds     cnt, usbTxLen1      ;[42]
+    sbrc    cnt, 4              ;[44] all handshake tokens have bit 4 set
+    rjmp    sendCntAndReti      ;[45] 47 + 16 = 63 until SOP
+    sts     usbTxLen1, x1       ;[46] x1 == USBPID_NAK from above
+    ldi     YL, lo8(usbTxBuf1)  ;[48]
+    ldi     YH, hi8(usbTxBuf1)  ;[49]
+    rjmp    usbSendAndReti      ;[50] 52 + 12 + 64 until SOP
+#endif
+
+
+; USB spec says:
+; idle = J
+; J = (D+ = 0), (D- = 1)
+; K = (D+ = 1), (D- = 0)
+; Spec allows 7.5 bit times from EOP to SOP for replies
+
+bitstuffN:
+    eor     x1, x4          ;[5]
+    ldi     x2, 0           ;[6]
+    nop2                    ;[7]
+    nop                     ;[9]
+    out     USBOUT, x1      ;[10] <-- out
+    rjmp    didStuffN       ;[0]
+
+bitstuff6:
+    eor     x1, x4          ;[4]
+    ldi     x2, 0           ;[5]
+    nop2                    ;[6] C is zero (brcc)
+    rjmp    didStuff6       ;[8]
+
+bitstuff7:
+    eor     x1, x4          ;[3]
+    ldi     x2, 0           ;[4]
+    rjmp    didStuff7       ;[5]
+
+
+sendNakAndReti:
+    ldi     x3, USBPID_NAK  ;[-18]
+    rjmp    sendX3AndReti   ;[-17]
+sendAckAndReti:
+    ldi     cnt, USBPID_ACK ;[-17]
+sendCntAndReti:
+    mov     x3, cnt         ;[-16]
+sendX3AndReti:
+    ldi     YL, 20          ;[-15] x3==r20 address is 20
+    ldi     YH, 0           ;[-14]
+    ldi     cnt, 2          ;[-13]
+;   rjmp    usbSendAndReti      fallthrough
+
+;usbSend:
+;pointer to data in 'Y'
+;number of bytes in 'cnt' -- including sync byte [range 2 ... 12]
+;uses: x1...x4, btcnt, shift, cnt, Y
+;Numbers in brackets are time since first bit of sync pattern is sent
+;We don't match the transfer rate exactly (don't insert leap cycles every third
+;byte) because the spec demands only 1.5% precision anyway.
+usbSendAndReti:             ; 12 cycles until SOP
+    in      x2, USBDDR      ;[-12]
+    ori     x2, USBMASK     ;[-11]
+    sbi     USBOUT, USBMINUS;[-10] prepare idle state; D+ and D- must have been 0 (no pullups)
+    in      x1, USBOUT      ;[-8] port mirror for tx loop
+    out     USBDDR, x2      ;[-7] <- acquire bus
+; need not init x2 (bitstuff history) because sync starts with 0
+    ldi     x4, USBMASK     ;[-6] exor mask
+    ldi     shift, 0x80     ;[-5] sync byte is first byte sent
+txByteLoop:
+    ldi     bitcnt, 0x2a    ;[-4] [6] binary 00101010
+txBitLoop:
+    sbrs    shift, 0        ;[-3] [7]
+    eor     x1, x4          ;[-2] [8]
+    out     USBOUT, x1      ;[-1] [9] <-- out N
+    ror     shift           ;[0] [10]
+    ror     x2              ;[1]
+didStuffN:
+    cpi     x2, 0xfc        ;[2]
+    brcc    bitstuffN       ;[3]
+    lsr     bitcnt          ;[4]
+    brcc    txBitLoop       ;[5]
+    brne    txBitLoop       ;[6]
+
+    sbrs    shift, 0        ;[7]
+    eor     x1, x4          ;[8]
+    ror     shift           ;[9]
+didStuff6:
+    out     USBOUT, x1      ;[-1] [10] <-- out 6
+    ror     x2              ;[0] [11]
+    cpi     x2, 0xfc        ;[1]
+    brcc    bitstuff6       ;[2]
+    sbrs    shift, 0        ;[3]
+    eor     x1, x4          ;[4]
+    ror     shift           ;[5]
+    ror     x2              ;[6]
+didStuff7:
+    nop                     ;[7]
+    nop2                    ;[8]
+    out     USBOUT, x1      ;[-1][10] <-- out 7
+    cpi     x2, 0xfc        ;[0] [11]
+    brcc    bitstuff7       ;[1]
+    ld      shift, y+       ;[2]
+    dec     cnt             ;[4]
+    brne    txByteLoop      ;[4]
+;make SE0:
+    cbr     x1, USBMASK     ;[7] prepare SE0 [spec says EOP may be 21 to 25 cycles]
+    lds     x2, usbNewDeviceAddr;[8]
+    out     USBOUT, x1      ;[10] <-- out SE0 -- from now 2 bits = 22 cycles until bus idle
+;2006-03-06: moved transfer of new address to usbDeviceAddr from C-Code to asm:
+;set address only after data packet was sent, not after handshake
+    subi    YL, 2           ;[0]
+    sbci    YH, 0           ;[1]
+    breq    skipAddrAssign  ;[2]
+    sts     usbDeviceAddr, x2; if not skipped: SE0 is one cycle longer
+skipAddrAssign:
+;end of usbDeviceAddress transfer
+    ldi     x2, 1<<USB_INTR_PENDING_BIT;[4] int0 occurred during TX -- clear pending flag
+    out     USB_INTR_PENDING, x2;[5]
+    ori     x1, USBIDLE     ;[6]
+    in      x2, USBDDR      ;[7]
+    cbr     x2, USBMASK     ;[8] set both pins to input
+    mov     x3, x1          ;[9]
+    cbr     x3, USBMASK     ;[10] configure no pullup on both pins
+    ldi     x4, 4           ;[11]
+se0Delay:
+    dec     x4              ;[12] [15] [18] [21]
+    brne    se0Delay        ;[13] [16] [19] [22]
+    out     USBOUT, x1      ;[23] <-- out J (idle) -- end of SE0 (EOP signal)
+    out     USBDDR, x2      ;[24] <-- release bus now
+    out     USBOUT, x3      ;[25] <-- ensure no pull-up resistors are active
+    rjmp    doReturn
diff --git a/firmware/usbdrv/usbdrvasm165.S b/firmware/usbdrv/usbdrvasm165.S
new file mode 100644 (file)
index 0000000..23261e8
--- /dev/null
@@ -0,0 +1,574 @@
+/* Name: usbdrvasm165.S
+ * Project: AVR USB driver
+ * Author: Christian Starkjohann
+ * Creation Date: 2007-04-22
+ * Tabsize: 4
+ * Copyright: (c) 2007 by OBJECTIVE DEVELOPMENT Software GmbH
+ * License: GNU GPL v2 (see License.txt) or proprietary (CommercialLicense.txt)
+ * Revision: $Id$
+ */
+
+/* Do not link this file! Link usbdrvasm.S instead, which includes the
+ * appropriate implementation!
+ */
+
+/*
+General Description:
+This file is the 16.5 MHz version of the USB driver. It is intended for the
+ATTiny45 and similar controllers running on 16.5 MHz internal RC oscillator.
+This version contains a phase locked loop in the receiver routine to cope with
+slight clock rate deviations of up to +/- 1%.
+
+See usbdrv.h for a description of the entire driver.
+
+Since almost all of this code is timing critical, don't change unless you
+really know what you are doing! Many parts require not only a maximum number
+of CPU cycles, but even an exact number of cycles!
+*/
+
+;Software-receiver engine. Strict timing! Don't change unless you can preserve timing!
+;interrupt response time: 4 cycles + insn running = 7 max if interrupts always enabled
+;max allowable interrupt latency: 59 cycles -> max 52 cycles interrupt disable
+;max stack usage: [ret(2), r0, SREG, YL, YH, shift, x1, x2, x3, x4, cnt] = 12 bytes
+;nominal frequency: 16.5 MHz -> 11 cycles per bit
+; 16.3125 MHz < F_CPU < 16.6875 MHz (+/- 1.1%)
+; Numbers in brackets are clocks counted from center of last sync bit
+; when instruction starts
+
+
+SIG_INTERRUPT0:
+;order of registers pushed: r0, SREG [sofError], YL, YH, shift, x1, x2, x3, x4, cnt
+    push    r0                  ;[-23] push only what is necessary to sync with edge ASAP
+    in      r0, SREG            ;[-21]
+    push    r0                  ;[-20]
+;----------------------------------------------------------------------------
+; Synchronize with sync pattern:
+;----------------------------------------------------------------------------
+;sync byte (D-) pattern LSb to MSb: 01010100 [1 = idle = J, 0 = K]
+;sync up with J to K edge during sync pattern -- use fastest possible loops
+;first part has no timeout because it waits for IDLE or SE1 (== disconnected)
+waitForJ:
+    sbis    USBIN, USBMINUS     ;[-18] wait for D- == 1
+    rjmp    waitForJ
+waitForK:
+;The following code results in a sampling window of < 1/4 bit which meets the spec.
+    sbis    USBIN, USBMINUS     ;[-15]
+    rjmp    foundK              ;[-14]
+    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
+    rjmp    sofError
+foundK:                         ;[-12]
+;{3, 5} after falling D- edge, average delay: 4 cycles [we want 5 for center sampling]
+;we have 1 bit time for setup purposes, then sample again. Numbers in brackets
+;are cycles from center of first sync (double K) bit after the instruction
+    push    YL                  ;[-12]
+;   [---]                       ;[-11]
+    push    YH                  ;[-10]
+;   [---]                       ;[-9]
+    lds     YL, usbInputBufOffset;[-8]
+;   [---]                       ;[-7]
+    clr     YH                  ;[-6]
+    subi    YL, lo8(-(usbRxBuf));[-5] [rx loop init]
+    sbci    YH, hi8(-(usbRxBuf));[-4] [rx loop init]
+    mov     r0, x2              ;[-3] [rx loop init]
+    sbis    USBIN, USBMINUS     ;[-2] we want two bits K (sample 2 cycles too early)
+    rjmp    haveTwoBitsK        ;[-1]
+    pop     YH                  ;[0] undo the pushes from before
+    pop     YL                  ;[2]
+    rjmp    waitForK            ;[4] this was not the end of sync, retry
+; The entire loop from waitForK until rjmp waitForK above must not exceed two
+; bit times (= 22 cycles).
+
+;----------------------------------------------------------------------------
+; push more registers and initialize values while we sample the first bits:
+;----------------------------------------------------------------------------
+haveTwoBitsK:               ;[1]
+    push    shift           ;[1]
+    push    x1              ;[3]
+    push    x2              ;[5]
+    push    x3              ;[7]
+    ldi     shift, 0xff     ;[9] [rx loop init]
+    ori     x3, 0xff        ;[10] [rx loop init] == ser x3, clear zero flag
+
+    in      x1, USBIN       ;[11] <-- sample bit 0
+    bst     x1, USBMINUS    ;[12]
+    bld     shift, 0        ;[13]
+    push    x4              ;[14] == phase
+;   [---]                   ;[15]
+    push    cnt             ;[16]
+;   [---]                   ;[17]
+    ldi     phase, 0        ;[18] [rx loop init]
+    ldi     cnt, USB_BUFSIZE;[19] [rx loop init]
+    rjmp    rxbit1          ;[20]
+;   [---]                   ;[21]
+
+;----------------------------------------------------------------------------
+; Receiver loop (numbers in brackets are cycles within byte after instr)
+;----------------------------------------------------------------------------
+/*
+byte oriented operations done during loop:
+bit 0: store data
+bit 1: SE0 check
+bit 2: overflow check
+bit 3: catch up
+bit 4: rjmp to achieve conditional jump range
+bit 5: PLL
+bit 6: catch up
+bit 7: jump, fixup bitstuff
+; 87 [+ 2] cycles
+------------------------------------------------------------------
+*/
+continueWithBit5:
+    in      x2, USBIN       ;[055] <-- bit 5
+    eor     r0, x2          ;[056]
+    or      phase, r0       ;[057]
+    sbrc    phase, USBMINUS ;[058]
+    lpm                     ;[059] optional nop3; modifies r0
+    in      phase, USBIN    ;[060] <-- phase
+    eor     x1, x2          ;[061]
+    bst     x1, USBMINUS    ;[062]
+    bld     shift, 5        ;[063]
+    andi    shift, 0x3f     ;[064]
+    in      x1, USBIN       ;[065] <-- bit 6
+    breq    unstuff5        ;[066] *** unstuff escape
+    eor     phase, x1       ;[067]
+    eor     x2, x1          ;[068]
+    bst     x2, USBMINUS    ;[069]
+    bld     shift, 6        ;[070]
+didUnstuff6:                ;[   ]
+    in      r0, USBIN       ;[071] <-- phase
+    cpi     shift, 0x02     ;[072]
+    brlo    unstuff6        ;[073] *** unstuff escape
+didUnstuff5:                ;[   ]
+    nop2                    ;[074]
+;   [---]                   ;[075]
+    in      x2, USBIN       ;[076] <-- bit 7
+    eor     x1, x2          ;[077]
+    bst     x1, USBMINUS    ;[078]
+    bld     shift, 7        ;[079]
+didUnstuff7:                ;[   ]
+    eor     r0, x2          ;[080]
+    or      phase, r0       ;[081]
+    in      r0, USBIN       ;[082] <-- phase
+    cpi     shift, 0x04     ;[083]
+    brsh    rxLoop          ;[084]
+;   [---]                   ;[085]
+unstuff7:                   ;[   ]
+    andi    x3, ~0x80       ;[085]
+    ori     shift, 0x80     ;[086]
+    in      x2, USBIN       ;[087] <-- sample stuffed bit 7
+    nop                     ;[088]
+    rjmp    didUnstuff7     ;[089]
+;   [---]                   ;[090]
+                            ;[080]
+
+unstuff5:                   ;[067]
+    eor     phase, x1       ;[068]
+    andi    x3, ~0x20       ;[069]
+    ori     shift, 0x20     ;[070]
+    in      r0, USBIN       ;[071] <-- phase
+    mov     x2, x1          ;[072]
+    nop                     ;[073]
+    nop2                    ;[074]
+;   [---]                   ;[075]
+    in      x1, USBIN       ;[076] <-- bit 6
+    eor     r0, x1          ;[077]
+    or      phase, r0       ;[078]
+    eor     x2, x1          ;[079]
+    bst     x2, USBMINUS    ;[080]
+    bld     shift, 6        ;[081] no need to check bitstuffing, we just had one
+    in      r0, USBIN       ;[082] <-- phase
+    rjmp    didUnstuff5     ;[083]
+;   [---]                   ;[084]
+                            ;[074]
+
+unstuff6:                   ;[074]
+    andi    x3, ~0x40       ;[075]
+    in      x1, USBIN       ;[076] <-- bit 6 again
+    ori     shift, 0x40     ;[077]
+    nop2                    ;[078]
+;   [---]                   ;[079]
+    rjmp    didUnstuff6     ;[080]
+;   [---]                   ;[081]
+                            ;[071]
+
+unstuff0:                   ;[013]
+    eor     r0, x2          ;[014]
+    or      phase, r0       ;[015]
+    andi    x2, USBMASK     ;[016] check for SE0
+    in      r0, USBIN       ;[017] <-- phase
+    breq    didUnstuff0     ;[018] direct jump to se0 would be too long
+    andi    x3, ~0x01       ;[019]
+    ori     shift, 0x01     ;[020]
+    mov     x1, x2          ;[021] mov existing sample
+    in      x2, USBIN       ;[022] <-- bit 1 again
+    rjmp    didUnstuff0     ;[023]
+;   [---]                   ;[024]
+                            ;[014]
+
+unstuff1:                   ;[024]
+    eor     r0, x1          ;[025]
+    or      phase, r0       ;[026]
+    andi    x3, ~0x02       ;[027]
+    in      r0, USBIN       ;[028] <-- phase
+    ori     shift, 0x02     ;[029]
+    mov     x2, x1          ;[030]
+    rjmp    didUnstuff1     ;[031]
+;   [---]                   ;[032]
+                            ;[022]
+
+unstuff2:                   ;[035]
+    eor     r0, x2          ;[036]
+    or      phase, r0       ;[037]
+    andi    x3, ~0x04       ;[038]
+    in      r0, USBIN       ;[039] <-- phase
+    ori     shift, 0x04     ;[040]
+    mov     x1, x2          ;[041]
+    rjmp    didUnstuff2     ;[042]
+;   [---]                   ;[043]
+                            ;[033]
+
+unstuff3:                   ;[043]
+    in      x2, USBIN       ;[044] <-- bit 3 again
+    eor     r0, x2          ;[045]
+    or      phase, r0       ;[046]
+    andi    x3, ~0x08       ;[047]
+    ori     shift, 0x08     ;[048]
+    nop                     ;[049]
+    in      r0, USBIN       ;[050] <-- phase
+    rjmp    didUnstuff3     ;[051]
+;   [---]                   ;[052]
+                            ;[042]
+
+unstuff4:                   ;[053]
+    andi    x3, ~0x10       ;[054]
+    in      x1, USBIN       ;[055] <-- bit 4 again
+    ori     shift, 0x10     ;[056]
+    rjmp    didUnstuff4     ;[057]
+;   [---]                   ;[058]
+                            ;[048]
+
+rxLoop:                     ;[085]
+    eor     x3, shift       ;[086] reconstruct: x3 is 0 at bit locations we changed, 1 at others
+    in      x1, USBIN       ;[000] <-- bit 0
+    st      y+, x3          ;[001]
+;   [---]                   ;[002]
+    eor     r0, x1          ;[003]
+    or      phase, r0       ;[004]
+    eor     x2, x1          ;[005]
+    in      r0, USBIN       ;[006] <-- phase
+    ser     x3              ;[007]
+    bst     x2, USBMINUS    ;[008]
+    bld     shift, 0        ;[009]
+    andi    shift, 0xf9     ;[010]
+rxbit1:                     ;[   ]
+    in      x2, USBIN       ;[011] <-- bit 1
+    breq    unstuff0        ;[012] *** unstuff escape
+    andi    x2, USBMASK     ;[013] SE0 check for bit 1
+didUnstuff0:                ;[   ] Z only set if we detected SE0 in bitstuff
+    breq    se0             ;[014]
+    eor     r0, x2          ;[015]
+    or      phase, r0       ;[016]
+    in      r0, USBIN       ;[017] <-- phase
+    eor     x1, x2          ;[018]
+    bst     x1, USBMINUS    ;[019]
+    bld     shift, 1        ;[020]
+    andi    shift, 0xf3     ;[021]
+didUnstuff1:                ;[   ]
+    in      x1, USBIN       ;[022] <-- bit 2
+    breq    unstuff1        ;[023] *** unstuff escape
+    eor     r0, x1          ;[024]
+    or      phase, r0       ;[025]
+    subi    cnt, 1          ;[026] overflow check
+    brcs    overflow        ;[027]
+    in      r0, USBIN       ;[028] <-- phase
+    eor     x2, x1          ;[029]
+    bst     x2, USBMINUS    ;[030]
+    bld     shift, 2        ;[031]
+    andi    shift, 0xe7     ;[032]
+didUnstuff2:                ;[   ]
+    in      x2, USBIN       ;[033] <-- bit 3
+    breq    unstuff2        ;[034] *** unstuff escape
+    eor     r0, x2          ;[035]
+    or      phase, r0       ;[036]
+    eor     x1, x2          ;[037]
+    bst     x1, USBMINUS    ;[038]
+    in      r0, USBIN       ;[039] <-- phase
+    bld     shift, 3        ;[040]
+    andi    shift, 0xcf     ;[041]
+didUnstuff3:                ;[   ]
+    breq    unstuff3        ;[042] *** unstuff escape
+    nop                     ;[043]
+    in      x1, USBIN       ;[044] <-- bit 4
+    eor     x2, x1          ;[045]
+    bst     x2, USBMINUS    ;[046]
+    bld     shift, 4        ;[047]
+didUnstuff4:                ;[   ]
+    eor     r0, x1          ;[048]
+    or      phase, r0       ;[049]
+    in      r0, USBIN       ;[050] <-- phase
+    andi    shift, 0x9f     ;[051]
+    breq    unstuff4        ;[052] *** unstuff escape
+    rjmp    continueWithBit5;[053]
+;   [---]                   ;[054]
+
+;----------------------------------------------------------------------------
+; Processing of received packet (numbers in brackets are cycles after center of SE0)
+;----------------------------------------------------------------------------
+;This is the only non-error exit point for the software receiver loop
+;we don't check any CRCs here because there is no time left.
+#define token   x1
+se0:
+    subi    cnt, USB_BUFSIZE    ;[5]
+    neg     cnt                 ;[6]
+    cpi     cnt, 3              ;[7]
+    ldi     x2, 1<<USB_INTR_PENDING_BIT ;[8]
+    out     USB_INTR_PENDING, x2;[9] clear pending intr and check flag later. SE0 should be over.
+    brlo    doReturn            ;[10] this is probably an ACK, NAK or similar packet
+    sub     YL, cnt             ;[11]
+    sbci    YH, 0               ;[12]
+    ld      token, y            ;[13]
+    cpi     token, USBPID_DATA0 ;[15]
+    breq    handleData          ;[16]
+    cpi     token, USBPID_DATA1 ;[17]
+    breq    handleData          ;[18]
+    ldd     x2, y+1             ;[19] ADDR and 1 bit endpoint number
+    mov     x3, x2              ;[21] store for endpoint number
+    andi    x2, 0x7f            ;[22] x2 is now ADDR
+    lds     shift, usbDeviceAddr;[23]
+    cp      x2, shift           ;[25]
+overflow:                       ; This is a hack: brcs overflow will never have Z flag set
+    brne    ignorePacket        ;[26] packet for different address
+    cpi     token, USBPID_IN    ;[27]
+    breq    handleIn            ;[28]
+    cpi     token, USBPID_SETUP ;[29]
+    breq    handleSetupOrOut    ;[30]
+    cpi     token, USBPID_OUT   ;[31]
+    breq    handleSetupOrOut    ;[32]
+;   rjmp    ignorePacket        ;fallthrough, should not happen anyway.
+
+ignorePacket:
+    clr     shift
+    sts     usbCurrentTok, shift
+doReturn:
+    pop     cnt
+    pop     x4
+    pop     x3
+    pop     x2
+    pop     x1
+    pop     shift
+    pop     YH
+    pop     YL
+sofError:
+    pop     r0
+    out     SREG, r0
+    pop     r0
+    reti
+
+#if USB_CFG_HAVE_INTRIN_ENDPOINT && USB_CFG_HAVE_INTRIN_ENDPOINT3
+handleIn3:
+    lds     cnt, usbTxLen3      ;[43]
+    sbrc    cnt, 4              ;[45]
+    rjmp    sendCntAndReti      ;[46] 48 + 16 = 64 until SOP
+    sts     usbTxLen3, x1       ;[47] x1 == USBPID_NAK from above
+    ldi     YL, lo8(usbTxBuf3)  ;[49]
+    ldi     YH, hi8(usbTxBuf3)  ;[50]
+    rjmp    usbSendAndReti      ;[51] 53 + 12 = 65 until SOP
+#endif
+
+;Setup and Out are followed by a data packet two bit times (16 cycles) after
+;the end of SE0. The sync code allows up to 40 cycles delay from the start of
+;the sync pattern until the first bit is sampled. That's a total of 56 cycles.
+handleSetupOrOut:               ;[34]
+#if USB_CFG_IMPLEMENT_FN_WRITEOUT   /* if we have data for second OUT endpoint, set usbCurrentTok to -1 */
+    sbrc    x3, 7               ;[34] skip if endpoint 0
+    ldi     token, -1           ;[35] indicate that this is endpoint 1 OUT
+#endif
+    sts     usbCurrentTok, token;[36]
+    pop     cnt                 ;[38]
+    pop     x4                  ;[40]
+    pop     x3                  ;[42]
+    pop     x2                  ;[44]
+    pop     x1                  ;[46]
+    pop     shift               ;[48]
+    pop     YH                  ;[50]
+    pop     YL                  ;[52]
+    in      r0, USB_INTR_PENDING;[54]
+    sbrc    r0, USB_INTR_PENDING_BIT;[55] check whether data is already arriving
+    rjmp    waitForJ            ;[56] save the pops and pushes -- a new interrupt is aready pending
+    rjmp    sofError            ;[57] not an error, but it does the pops and reti we want
+
+
+handleData:
+    lds     token, usbCurrentTok;[20]
+    tst     token               ;[22]
+    breq    doReturn            ;[23]
+    lds     x2, usbRxLen        ;[24]
+    tst     x2                  ;[26]
+    brne    sendNakAndReti      ;[27]
+; 2006-03-11: The following two lines fix a problem where the device was not
+; recognized if usbPoll() was called less frequently than once every 4 ms.
+    cpi     cnt, 4              ;[28] zero sized data packets are status phase only -- ignore and ack
+    brmi    sendAckAndReti      ;[29] keep rx buffer clean -- we must not NAK next SETUP
+    sts     usbRxLen, cnt       ;[30] store received data, swap buffers
+    sts     usbRxToken, token   ;[32]
+    lds     x2, usbInputBufOffset;[34] swap buffers
+    ldi     cnt, USB_BUFSIZE    ;[36]
+    sub     cnt, x2             ;[37]
+    sts     usbInputBufOffset, cnt;[38] buffers now swapped
+    rjmp    sendAckAndReti      ;[40] 42 + 17 = 59 until SOP
+
+handleIn:
+;We don't send any data as long as the C code has not processed the current
+;input data and potentially updated the output data. That's more efficient
+;in terms of code size than clearing the tx buffers when a packet is received.
+    lds     x1, usbRxLen        ;[30]
+    cpi     x1, 1               ;[32] negative values are flow control, 0 means "buffer free"
+    brge    sendNakAndReti      ;[33] unprocessed input packet?
+    ldi     x1, USBPID_NAK      ;[34] prepare value for usbTxLen
+#if USB_CFG_HAVE_INTRIN_ENDPOINT
+    sbrc    x3, 7               ;[35] x3 contains addr + endpoint
+    rjmp    handleIn1           ;[36]
+#endif
+    lds     cnt, usbTxLen       ;[37]
+    sbrc    cnt, 4              ;[39] all handshake tokens have bit 4 set
+    rjmp    sendCntAndReti      ;[40] 42 + 16 = 58 until SOP
+    sts     usbTxLen, x1        ;[41] x1 == USBPID_NAK from above
+    ldi     YL, lo8(usbTxBuf)   ;[43]
+    ldi     YH, hi8(usbTxBuf)   ;[44]
+    rjmp    usbSendAndReti      ;[45] 47 + 12 = 59 until SOP
+
+; Comment about when to set usbTxLen to USBPID_NAK:
+; We should set it back when we receive the ACK from the host. This would
+; be simple to implement: One static variable which stores whether the last
+; tx was for endpoint 0 or 1 and a compare in the receiver to distinguish the
+; ACK. However, we set it back immediately when we send the package,
+; assuming that no error occurs and the host sends an ACK. We save one byte
+; RAM this way and avoid potential problems with endless retries. The rest of
+; the driver assumes error-free transfers anyway.
+
+#if USB_CFG_HAVE_INTRIN_ENDPOINT    /* placed here due to relative jump range */
+handleIn1:                      ;[38]
+#if USB_CFG_HAVE_INTRIN_ENDPOINT3
+; 2006-06-10 as suggested by O.Tamura: support second INTR IN / BULK IN endpoint
+    ldd     x2, y+2             ;[38]
+    sbrc    x2, 0               ;[40]
+    rjmp    handleIn3           ;[41]
+#endif
+    lds     cnt, usbTxLen1      ;[42]
+    sbrc    cnt, 4              ;[44] all handshake tokens have bit 4 set
+    rjmp    sendCntAndReti      ;[45] 47 + 16 = 63 until SOP
+    sts     usbTxLen1, x1       ;[46] x1 == USBPID_NAK from above
+    ldi     YL, lo8(usbTxBuf1)  ;[48]
+    ldi     YH, hi8(usbTxBuf1)  ;[49]
+    rjmp    usbSendAndReti      ;[50] 52 + 12 + 64 until SOP
+#endif
+
+
+; USB spec says:
+; idle = J
+; J = (D+ = 0), (D- = 1)
+; K = (D+ = 1), (D- = 0)
+; Spec allows 7.5 bit times from EOP to SOP for replies
+
+bitstuff7:
+    eor     x1, x4          ;[4]
+    ldi     x2, 0           ;[5]
+    nop2                    ;[6] C is zero (brcc)
+    rjmp    didStuff7       ;[8]
+
+bitstuffN:
+    eor     x1, x4          ;[5]
+    ldi     x2, 0           ;[6]
+    lpm                     ;[7] 3 cycle NOP, modifies r0
+    out     USBOUT, x1      ;[10] <-- out
+    rjmp    didStuffN       ;[0]
+
+#define bitStatus   x3
+
+sendNakAndReti:
+    ldi     cnt, USBPID_NAK ;[-19]
+    rjmp    sendCntAndReti  ;[-18]
+sendAckAndReti:
+    ldi     cnt, USBPID_ACK ;[-17]
+sendCntAndReti:
+    mov     r0, cnt         ;[-16]
+    ldi     YL, 0           ;[-15] R0 address is 0
+    ldi     YH, 0           ;[-14]
+    ldi     cnt, 2          ;[-13]
+;   rjmp    usbSendAndReti      fallthrough
+
+;usbSend:
+;pointer to data in 'Y'
+;number of bytes in 'cnt' -- including sync byte [range 2 ... 12]
+;uses: x1...x4, shift, cnt, Y
+;Numbers in brackets are time since first bit of sync pattern is sent
+usbSendAndReti:             ; 12 cycles until SOP
+    in      x2, USBDDR      ;[-12]
+    ori     x2, USBMASK     ;[-11]
+    sbi     USBOUT, USBMINUS;[-10] prepare idle state; D+ and D- must have been 0 (no pullups)
+    in      x1, USBOUT      ;[-8] port mirror for tx loop
+    out     USBDDR, x2      ;[-7] <- acquire bus
+; need not init x2 (bitstuff history) because sync starts with 0
+    ldi     x4, USBMASK     ;[-6] exor mask
+    ldi     shift, 0x80     ;[-5] sync byte is first byte sent
+    ldi     bitStatus, 0xff ;[-4] init bit loop counter, works for up to 12 bytes
+byteloop:
+bitloop:
+    sbrs    shift, 0        ;[8] [-3]
+    eor     x1, x4          ;[9] [-2]
+    out     USBOUT, x1      ;[10] [-1] <-- out
+    ror     shift           ;[0]
+    ror     x2              ;[1]
+didStuffN:
+    cpi     x2, 0xfc        ;[2]
+    brcc    bitstuffN       ;[3]
+    nop                     ;[4]
+    subi    bitStatus, 37   ;[5] 256 / 7 ~=~ 37
+    brcc    bitloop         ;[6] when we leave the loop, bitStatus has almost the initial value
+    sbrs    shift, 0        ;[7]
+    eor     x1, x4          ;[8]
+    ror     shift           ;[9]
+didStuff7:
+    out     USBOUT, x1      ;[10] <-- out
+    ror     x2              ;[0]
+    cpi     x2, 0xfc        ;[1]
+    brcc    bitstuff7       ;[2]
+    ld      shift, y+       ;[3]
+    dec     cnt             ;[5]
+    brne    byteloop        ;[6]
+;make SE0:
+    cbr     x1, USBMASK     ;[7] prepare SE0 [spec says EOP may be 21 to 25 cycles]
+    lds     x2, usbNewDeviceAddr;[8]
+    out     USBOUT, x1      ;[10] <-- out SE0 -- from now 2 bits = 22 cycles until bus idle
+;2006-03-06: moved transfer of new address to usbDeviceAddr from C-Code to asm:
+;set address only after data packet was sent, not after handshake
+    subi    YL, 2           ;[0]
+    sbci    YH, 0           ;[1]
+    breq    skipAddrAssign  ;[2]
+    sts     usbDeviceAddr, x2; if not skipped: SE0 is one cycle longer
+skipAddrAssign:
+;end of usbDeviceAddress transfer
+    ldi     x2, 1<<USB_INTR_PENDING_BIT;[4] int0 occurred during TX -- clear pending flag
+    out     USB_INTR_PENDING, x2;[5]
+    ori     x1, USBIDLE     ;[6]
+    in      x2, USBDDR      ;[7]
+    cbr     x2, USBMASK     ;[8] set both pins to input
+    mov     x3, x1          ;[9]
+    cbr     x3, USBMASK     ;[10] configure no pullup on both pins
+    ldi     x4, 4           ;[11]
+se0Delay:
+    dec     x4              ;[12] [15] [18] [21]
+    brne    se0Delay        ;[13] [16] [19] [22]
+    out     USBOUT, x1      ;[23] <-- out J (idle) -- end of SE0 (EOP signal)
+    out     USBDDR, x2      ;[24] <-- release bus now
+    out     USBOUT, x3      ;[25] <-- ensure no pull-up resistors are active
+    rjmp    doReturn