├── .gitattributes ├── .gitignore ├── 0023 └── at90can │ ├── boards.txt │ ├── bootloaders │ └── at90can │ │ ├── ATmegaBOOT_168.c │ │ ├── ATmegaBOOT_168_at90can.hex │ │ └── Makefile │ ├── cores │ └── at90can │ │ ├── HardwareSerial.cpp │ │ ├── HardwareSerial.h │ │ ├── Makefile │ │ ├── Print.cpp │ │ ├── Print.h │ │ ├── WConstants.h │ │ ├── WInterrupts.c │ │ ├── WMath.cpp │ │ ├── WProgram.h │ │ ├── binary.h │ │ ├── can_lib.cpp │ │ ├── can_lib.h │ │ ├── main.cpp │ │ ├── pins_arduino.c │ │ ├── pins_arduino.h │ │ ├── wiring.c │ │ ├── wiring.h │ │ ├── wiring_analog.c │ │ ├── wiring_digital.c │ │ ├── wiring_private.h │ │ ├── wiring_pulse.c │ │ └── wiring_shift.c │ └── programmers.txt ├── 1.0 └── at90can │ ├── boards.txt │ ├── bootloaders │ └── at90can │ │ ├── ATmegaBOOT_168.c │ │ ├── ATmegaBOOT_168_at90can.hex │ │ └── Makefile │ ├── cores │ └── at90can │ │ ├── Arduino.h │ │ ├── HardwareSerial.cpp │ │ ├── HardwareSerial.h │ │ ├── Makefile │ │ ├── Print.cpp │ │ ├── Print.h │ │ ├── Printable.h │ │ ├── Stream.cpp │ │ ├── Stream.h │ │ ├── WCharacter.h │ │ ├── WConstants.h │ │ ├── WInterrupts.c │ │ ├── WMath.cpp │ │ ├── WString.cpp │ │ ├── WString.h │ │ ├── binary.h │ │ ├── can_lib.cpp │ │ ├── can_lib.h │ │ ├── main.cpp │ │ ├── new.cpp │ │ ├── new.h │ │ ├── pins_arduino.c │ │ ├── pins_arduino.h │ │ ├── wiring.c │ │ ├── wiring.h │ │ ├── wiring_analog.c │ │ ├── wiring_digital.c │ │ ├── wiring_private.h │ │ ├── wiring_pulse.c │ │ └── wiring_shift.c │ └── programmers.txt ├── AT90CAN_Pinmap.txt └── README /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | *.bak 3 | 4 | ################# 5 | ## Eclipse 6 | ################# 7 | 8 | *.pydevproject 9 | .project 10 | .metadata 11 | bin/ 12 | tmp/ 13 | *.tmp 14 | *.bak 15 | *.swp 16 | *~.nib 17 | local.properties 18 | .classpath 19 | .settings/ 20 | .loadpath 21 | 22 | # External tool builders 23 | .externalToolBuilders/ 24 | 25 | # Locally stored "Eclipse launch configurations" 26 | *.launch 27 | 28 | # CDT-specific 29 | .cproject 30 | 31 | # PDT-specific 32 | .buildpath 33 | 34 | 35 | ################# 36 | ## Visual Studio 37 | ################# 38 | 39 | ## Ignore Visual Studio temporary files, build results, and 40 | ## files generated by popular Visual Studio add-ons. 41 | 42 | # User-specific files 43 | *.suo 44 | *.user 45 | *.sln.docstates 46 | 47 | # Build results 48 | [Dd]ebug/ 49 | [Rr]elease/ 50 | *_i.c 51 | *_p.c 52 | *.ilk 53 | *.meta 54 | *.obj 55 | *.pch 56 | *.pdb 57 | *.pgc 58 | *.pgd 59 | *.rsp 60 | *.sbr 61 | *.tlb 62 | *.tli 63 | *.tlh 64 | *.tmp 65 | *.vspscc 66 | .builds 67 | *.dotCover 68 | 69 | ## TODO: If you have NuGet Package Restore enabled, uncomment this 70 | #packages/ 71 | 72 | # Visual C++ cache files 73 | ipch/ 74 | *.aps 75 | *.ncb 76 | *.opensdf 77 | *.sdf 78 | 79 | # Visual Studio profiler 80 | *.psess 81 | *.vsp 82 | 83 | # ReSharper is a .NET coding add-in 84 | _ReSharper* 85 | 86 | # Installshield output folder 87 | [Ee]xpress 88 | 89 | # DocProject is a documentation generator add-in 90 | DocProject/buildhelp/ 91 | DocProject/Help/*.HxT 92 | DocProject/Help/*.HxC 93 | DocProject/Help/*.hhc 94 | DocProject/Help/*.hhk 95 | DocProject/Help/*.hhp 96 | DocProject/Help/Html2 97 | DocProject/Help/html 98 | 99 | # Click-Once directory 100 | publish 101 | 102 | # Others 103 | [Bb]in 104 | [Oo]bj 105 | sql 106 | TestResults 107 | *.Cache 108 | ClientBin 109 | stylecop.* 110 | ~$* 111 | *.dbmdl 112 | Generated_Code #added for RIA/Silverlight projects 113 | 114 | # Backup & report files from converting an old project file to a newer 115 | # Visual Studio version. Backup files are not needed, because we have git ;-) 116 | _UpgradeReport_Files/ 117 | Backup*/ 118 | UpgradeLog*.XML 119 | 120 | 121 | 122 | ############ 123 | ## Windows 124 | ############ 125 | 126 | # Windows image file caches 127 | Thumbs.db 128 | 129 | # Folder config file 130 | Desktop.ini 131 | 132 | 133 | ############# 134 | ## Python 135 | ############# 136 | 137 | *.py[co] 138 | 139 | # Packages 140 | *.egg 141 | *.egg-info 142 | dist 143 | build 144 | eggs 145 | parts 146 | bin 147 | var 148 | sdist 149 | develop-eggs 150 | .installed.cfg 151 | 152 | # Installer logs 153 | pip-log.txt 154 | 155 | # Unit test / coverage reports 156 | .coverage 157 | .tox 158 | 159 | #Translations 160 | *.mo 161 | 162 | #Mr Developer 163 | .mr.developer.cfg 164 | 165 | # Mac crap 166 | .DS_Store 167 | -------------------------------------------------------------------------------- /0023/at90can/boards.txt: -------------------------------------------------------------------------------- 1 | at90can128.name=[bootloader]AT90CAN128 2 | at90can128.upload.protocol=stk500 3 | at90can128.upload.maximum_size=129024 4 | at90can128.upload.speed=57600 5 | 6 | at90can128.bootloader.low_fuses=0xFF 7 | at90can128.bootloader.high_fuses=0x1C 8 | at90can128.bootloader.extended_fuses=0xFF 9 | at90can128.bootloader.path=at90can 10 | at90can128.bootloader.file=ATmegaBOOT_168_at90can.hex 11 | at90can128.bootloader.unlock_bits=0x3F 12 | at90can128.bootloader.lock_bits=0x0F 13 | 14 | at90can128.build.mcu=at90can128 15 | at90can128.build.f_cpu=16000000L 16 | at90can128.build.core=at90can 17 | 18 | 19 | ############################################################## 20 | 21 | uat90can128.name=[usbtinyisp]AT90CAN128 22 | uat90can128.upload.using=usbtinyisp 23 | uat90can128.upload.maximum_size=131072 24 | 25 | uat90can128.bootloader.low_fuses=0xFF 26 | uat90can128.bootloader.high_fuses=0x19 27 | uat90can128.bootloader.extended_fuses=0xFF 28 | uat90can128.bootloader.path=at90can 29 | uat90can128.bootloader.file=ATmegaBOOT_168_at90can.hex 30 | uat90can128.bootloader.unlock_bits=0x3F 31 | uat90can128.bootloader.lock_bits=0xCF 32 | 33 | uat90can128.build.mcu=at90can128 34 | uat90can128.build.f_cpu=16000000L 35 | uat90can128.build.core=at90can 36 | 37 | ############################################################## 38 | 39 | jat90can128.name=[JTAG ICE mkI]AT90CAN128 40 | jat90can128.upload.using=jtagicemki 41 | jat90can128.upload.maximum_size=131072 42 | 43 | jat90can128.bootloader.low_fuses=0xFF 44 | jat90can128.bootloader.high_fuses=0x19 45 | jat90can128.bootloader.extended_fuses=0xFF 46 | jat90can128.bootloader.path=at90can 47 | jat90can128.bootloader.file=ATmegaBOOT_168_at90can.hex 48 | jat90can128.bootloader.unlock_bits=0x3F 49 | jat90can128.bootloader.lock_bits=0xCF 50 | 51 | jat90can128.build.mcu=at90can128 52 | jat90can128.build.f_cpu=16000000L 53 | jat90can128.build.core=at90can 54 | 55 | -------------------------------------------------------------------------------- /0023/at90can/bootloaders/at90can/ATmegaBOOT_168_at90can.hex: -------------------------------------------------------------------------------- 1 | :020000021000EC 2 | :10F800000C944AFC0C9469FC0C9469FC0C9469FC03 3 | :10F810000C9469FC0C9469FC0C9469FC0C9469FCD4 4 | :10F820000C9469FC0C9469FC0C9469FC0C9469FCC4 5 | :10F830000C9469FC0C9469FC0C9469FC0C9469FCB4 6 | :10F840000C9469FC0C9469FC0C9469FC0C9469FCA4 7 | :10F850000C9469FC0C9469FC0C9469FC0C9469FC94 8 | :10F860000C9469FC0C9469FC0C9469FC0C9469FC84 9 | :10F870000C9469FC0C9469FC0C9469FC0C9469FC74 10 | :10F880000C9469FC0C9469FC0C9469FC0C9469FC64 11 | :10F890000C9469FC11241FBECFEFD0E1DEBFCDBFB9 12 | :10F8A00011E0A0E0B1E0EAEEFFEF01E00BBF02C023 13 | :10F8B00007900D92A230B107D9F712E0A2E0B1E0B3 14 | :10F8C00001C01D92AD30B107E1F70E9486FD0C9496 15 | :10F8D000F3FF0C9400FC982F80910201813019F005 16 | :10F8E000823041F008958091C00085FFFCCF909355 17 | :10F8F000C60008958091C80085FFFCCF9093CE008C 18 | :10F9000008951F93982F9595959595959595905D4C 19 | :10F910008F708A3054F4182F105D892F0E946BFC71 20 | :10F92000812F0E946BFC1F910895182F195A892F5F 21 | :10F930000E946BFC812F0E946BFC1F910895EF9237 22 | :10F94000FF920F931F9380910201813069F1823001 23 | :10F9500031F080E01F910F91FF90EF900895EE2419 24 | :10F96000FF2487018091C80087FD17C00894E11C1F 25 | :10F97000F11C011D111D81E4E81682E4F8068FE0F8 26 | :10F98000080780E0180770F3E0910401F091050189 27 | :10F9900009958091C80087FFE9CF8091CE001F9123 28 | :10F9A0000F91FF90EF900895EE24FF24870180913E 29 | :10F9B000C00087FD17C00894E11CF11C011D111D3A 30 | :10F9C00081E4E81682E4F8068FE0080780E0180773 31 | :10F9D00070F3E0910401F091050109958091C00058 32 | :10F9E00087FFE9CF8091C6001F910F91FF90EF90A4 33 | :10F9F00008951F930E949FFC182F0E946BFC1136E4 34 | :10FA000034F410330CF01053812F1F9108951755C3 35 | :10FA1000812F1F9108951F930E94F9FC182F0E94B7 36 | :10FA2000F9FC1295107F810F1F910895982F209156 37 | :10FA30000201992339F0213031F0223061F09150E8 38 | :10FA40009923C9F708958091C00087FFFCCF80916A 39 | :10FA5000C6009150F5CF8091C80087FFFCCF809100 40 | :10FA6000CE009150EDCF1F93182F0E949FFC803243 41 | :10FA700081F0809103018F5F80930301853011F045 42 | :10FA80001F910895E0910401F091050109951F91DE 43 | :10FA9000089584E10E946BFC812F0E946BFC80E141 44 | :10FAA0000E946BFC1F9108950E949FFC803271F0B0 45 | :10FAB000809103018F5F80930301853009F00895E1 46 | :10FAC000E0910401F09105010995089584E10E94F7 47 | :10FAD0006BFC80E10E946BFC089540E951E08823B3 48 | :10FAE000A1F0179A28EE33E0FA013197F1F721508F 49 | :10FAF0003040D1F7179828EE33E0FA013197F1F74B 50 | :10FB000021503040D1F7815061F70895FF920F9353 51 | :10FB10001F93CF93DF930000879886988F9A8E9AD1 52 | :10FB200081E08093020180E18093C4001092C500BF 53 | :10FB30001092C00086E08093C20088E18093C100EB 54 | :10FB40006898709A0F9A82E00E946DFDFF24F394EA 55 | :10FB50000E949FFC8033B1F18133B9F1803409F404 56 | :10FB600054C0813409F45AC0823409F469C0853420 57 | :10FB700009F46CC0803531F1823521F1813511F104 58 | :10FB8000853509F469C0863509F471C0843609F4F5 59 | :10FB90007AC0843709F4E4C0853709F448C1863750 60 | :10FBA00009F44AC0809103018F5F8093030185307F 61 | :10FBB00079F6E0910401F091050109950E949FFCFE 62 | :10FBC000803351F60E9454FDC3CF0E949FFC8032C7 63 | :10FBD00049F784E10E946BFC81E40E946BFC86E59E 64 | :10FBE0000E946BFC82E50E946BFC80E20E946BFC31 65 | :10FBF00089E40E946BFC83E50E946BFC80E50E9417 66 | :10FC00006BFC80E10E946BFCA3CF0E949FFC8638B6 67 | :10FC1000C8F20E949FFC0E9454FD9ACF0E949FFC54 68 | :10FC2000803809F499C0813809F4FDC0823809F49C 69 | :10FC300013C1883909F48CC080E00E9433FD88CF5D 70 | :10FC400084E10E9416FD0E9454FD82CF85E00E944F 71 | :10FC500016FD0E9454FD7CCF0E949FFC80930601FC 72 | :10FC60000E949FFC809307010E9454FD71CF0E9467 73 | :10FC70009FFC803309F404C183E00E9416FD80E0FC 74 | :10FC80000E9433FD65CF0E949FFC809309020E9471 75 | :10FC90009FFC8093080280910C028E7F80930C025F 76 | :10FCA0000E949FFC853409F4FCC080910802909169 77 | :10FCB0000902892B89F000E010E00E949FFCF80106 78 | :10FCC000E85FFE4F80830F5F1F4F80910802909185 79 | :10FCD00009020817190788F30E949FFC803209F077 80 | :10FCE00061CF80910C0280FFEEC02091060130911F 81 | :10FCF0000701220F331F30930701209306018091E3 82 | :10FD0000080290910902892BE1F000E010E0F8016F 83 | :10FD1000E85FFE4FC90160810E94E6FF2091060165 84 | :10FD2000309107012F5F3F4F309307012093060169 85 | :10FD30000F5F1F4F80910802909109020817190761 86 | :10FD400030F384E10E946BFC80E10E946BFC00CFE9 87 | :10FD500083E00E9433FDFCCE82E00E9433FDF8CEAA 88 | :10FD60000E949FFC809309020E949FFC80930802DE 89 | :10FD7000209106013091070137FD9FC080910C0250 90 | :10FD80008D7F80930C02220F331F30930701209345 91 | :10FD900006010E949FFC853409F489C080910C0201 92 | :10FDA0008E7F80930C020E949FFC803209F0D0CE9F 93 | :10FDB00084E10E946BFC8091080290910902892BDA 94 | :10FDC00009F446C000E010E02091060130910701DF 95 | :10FDD00017C0F90184910E946BFC209106013091BB 96 | :10FDE00007012F5F3F4F30930701209306010F5FFC 97 | :10FDF0001F4F80910802909109020817190740F5DA 98 | :10FE000080910C0280FD2CC081FFE3CFC901A0E0EE 99 | :10FE1000B0E080509040AF4FBF4FABBFFC01879127 100 | :10FE20000E946BFCDACF81E00E9433FD91CE0E94EC 101 | :10FE30009FFC803209F0B6CE84E10E946BFC8EE11B 102 | :10FE40000E946BFC87E90E946BFC81E80E946BFCBE 103 | :10FE500080E10E946BFC7CCE80E10E9433FD78CE75 104 | :10FE6000C9010E94DEFF0E946BFC209106013091C7 105 | :10FE700007012F5F3F4F3093070120930601B7CF53 106 | :10FE80000E949FFC0E949FFC182F0E949FFC112340 107 | :10FE900009F48CC0113009F48DC081E80E9433FD53 108 | :10FEA00057CE80910C02816080930C02FECE80912F 109 | :10FEB0000C02816080930C0276CF80910C028260EC 110 | :10FEC00080930C0260CF809107018823880F880BF4 111 | :10FED0008F2180930B028BBF8091060190910701C7 112 | :10FEE000880F991F90930701809306018091080263 113 | :10FEF00080FF09C0809108029091090201969093B9 114 | :10FF0000090280930802F894F999FECF1127E09135 115 | :10FF10000601F0910701C8E0D1E0809108029091BC 116 | :10FF20000902103091F40091570001700130D9F3AB 117 | :10FF300003E000935700E8950091570001700130ED 118 | :10FF4000D9F301E100935700E895099019900091C9 119 | :10FF5000570001700130D9F301E000935700E89594 120 | :10FF60001395103898F01127009157000170013057 121 | :10FF7000D9F305E000935700E89500915700017010 122 | :10FF80000130D9F301E100935700E89532960297CA 123 | :10FF900009F0C7CF103011F00296E5CF112484E1AB 124 | :10FFA0000E946BFC80E10E946BFCD2CD8EE10E942E 125 | :10FFB00033FDCECD87E90E9433FDCACDF999FECF3E 126 | :10FFC00092BD81BDF89A992780B50895262FF99999 127 | :10FFD000FECF92BD81BD20BD0FB6F894FA9AF99A72 128 | :0AFFE0000FBE01960895F894FFCFBC 129 | :02FFEA00800095 130 | :040000031000F800F1 131 | :00000001FF 132 | -------------------------------------------------------------------------------- /0023/at90can/bootloaders/at90can/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for ATmegaBOOT 2 | # E.Lins, 18.7.2005 3 | # $Id$ 4 | # 5 | # Instructions 6 | # 7 | # To make bootloader .hex file: 8 | # make diecimila 9 | # make lilypad 10 | # make ng 11 | # etc... 12 | # 13 | # To burn bootloader .hex file: 14 | # make diecimila_isp 15 | # make lilypad_isp 16 | # make ng_isp 17 | # etc... 18 | 19 | # program name should not be changed... 20 | PROGRAM = ATmegaBOOT_168 21 | 22 | # enter the parameters for the avrdude isp tool 23 | ISPTOOL = stk500v2 24 | ISPPORT = usb 25 | ISPSPEED = -b 115200 26 | 27 | MCU_TARGET = AT90can128 28 | LDSECTION = --section-start=.text=0x3800 29 | 30 | # the efuse should really be 0xf8; since, however, only the lower 31 | # three bits of that byte are used on the atmega168, avrdude gets 32 | # confused if you specify 1's for the higher bits, see: 33 | # http://tinker.it/now/2007/02/24/the-tale-of-avrdude-atmega168-and-extended-bits-fuses/ 34 | # 35 | # similarly, the lock bits should be 0xff instead of 0x3f (to 36 | # unlock the bootloader section) and 0xcf instead of 0x0f (to 37 | # lock it), but since the high two bits of the lock byte are 38 | # unused, avrdude would get confused. 39 | 40 | ISPFUSES = avrdude -c $(ISPTOOL) -p $(MCU_TARGET) -P $(ISPPORT) $(ISPSPEED) \ 41 | -e -u -U lock:w:0x3f:m -U efuse:w:0x$(EFUSE):m -U hfuse:w:0x$(HFUSE):m -U lfuse:w:0x$(LFUSE):m 42 | ISPFLASH = avrdude -c $(ISPTOOL) -p $(MCU_TARGET) -P $(ISPPORT) $(ISPSPEED) \ 43 | -U flash:w:$(PROGRAM)_$(TARGET).hex -U lock:w:0x0f:m 44 | 45 | STK500 = "C:\Program Files\Atmel\AVR Tools\STK500\Stk500.exe" 46 | STK500-1 = $(STK500) -e -d$(MCU_TARGET) -pf -vf -if$(PROGRAM)_$(TARGET).hex \ 47 | -lFF -LFF -f$(HFUSE)$(LFUSE) -EF8 -ms -q -cUSB -I200kHz -s -wt 48 | STK500-2 = $(STK500) -d$(MCU_TARGET) -ms -q -lCF -LCF -cUSB -I200kHz -s -wt 49 | 50 | 51 | OBJ = $(PROGRAM).o 52 | OPTIMIZE = -O2 53 | 54 | DEFS = 55 | LIBS = 56 | 57 | CC = avr-gcc 58 | 59 | # Override is only needed by avr-lib build system. 60 | 61 | override CFLAGS = -g -Wall $(OPTIMIZE) -mmcu=$(MCU_TARGET) -DF_CPU=$(AVR_FREQ) $(DEFS) 62 | override LDFLAGS = -Wl,$(LDSECTION) 63 | #override LDFLAGS = -Wl,-Map,$(PROGRAM).map,$(LDSECTION) 64 | 65 | OBJCOPY = avr-objcopy 66 | OBJDUMP = avr-objdump 67 | 68 | all: 69 | 70 | lilypad: TARGET = lilypad 71 | lilypad: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>1' '-DNUM_LED_FLASHES=3' 72 | lilypad: AVR_FREQ = 8000000L 73 | lilypad: $(PROGRAM)_lilypad.hex 74 | 75 | lilypad_isp: lilypad 76 | lilypad_isp: TARGET = lilypad 77 | lilypad_isp: HFUSE = DD 78 | lilypad_isp: LFUSE = E2 79 | lilypad_isp: EFUSE = 00 80 | lilypad_isp: isp 81 | 82 | lilypad_resonator: TARGET = lilypad_resonator 83 | lilypad_resonator: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>4' '-DNUM_LED_FLASHES=3' 84 | lilypad_resonator: AVR_FREQ = 8000000L 85 | lilypad_resonator: $(PROGRAM)_lilypad_resonator.hex 86 | 87 | lilypad_resonator_isp: lilypad_resonator 88 | lilypad_resonator_isp: TARGET = lilypad_resonator 89 | lilypad_resonator_isp: HFUSE = DD 90 | lilypad_resonator_isp: LFUSE = C6 91 | lilypad_resonator_isp: EFUSE = 00 92 | lilypad_resonator_isp: isp 93 | 94 | pro8: TARGET = pro_8MHz 95 | pro8: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>4' '-DNUM_LED_FLASHES=1' '-DWATCHDOG_MODS' 96 | pro8: AVR_FREQ = 8000000L 97 | pro8: $(PROGRAM)_pro_8MHz.hex 98 | 99 | pro8_isp: pro8 100 | pro8_isp: TARGET = pro_8MHz 101 | pro8_isp: HFUSE = DD 102 | pro8_isp: LFUSE = C6 103 | pro8_isp: EFUSE = 00 104 | pro8_isp: isp 105 | 106 | pro16: TARGET = pro_16MHz 107 | pro16: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>4' '-DNUM_LED_FLASHES=1' '-DWATCHDOG_MODS' 108 | pro16: AVR_FREQ = 16000000L 109 | pro16: $(PROGRAM)_pro_16MHz.hex 110 | 111 | pro16_isp: pro16 112 | pro16_isp: TARGET = pro_16MHz 113 | pro16_isp: HFUSE = DD 114 | pro16_isp: LFUSE = C6 115 | pro16_isp: EFUSE = 00 116 | pro16_isp: isp 117 | 118 | pro20: TARGET = pro_20mhz 119 | pro20: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>4' '-DNUM_LED_FLASHES=1' '-DWATCHDOG_MODS' 120 | pro20: AVR_FREQ = 20000000L 121 | pro20: $(PROGRAM)_pro_20mhz.hex 122 | 123 | pro20_isp: pro20 124 | pro20_isp: TARGET = pro_20mhz 125 | pro20_isp: HFUSE = DD 126 | pro20_isp: LFUSE = C6 127 | pro20_isp: EFUSE = 00 128 | pro20_isp: isp 129 | 130 | diecimila: TARGET = diecimila 131 | diecimila: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>4' '-DNUM_LED_FLASHES=1' 132 | diecimila: AVR_FREQ = 16000000L 133 | diecimila: $(PROGRAM)_diecimila.hex 134 | 135 | diecimila_isp: diecimila 136 | diecimila_isp: TARGET = diecimila 137 | diecimila_isp: HFUSE = DD 138 | diecimila_isp: LFUSE = FF 139 | diecimila_isp: EFUSE = 00 140 | diecimila_isp: isp 141 | 142 | ng: TARGET = ng 143 | ng: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>1' '-DNUM_LED_FLASHES=3' 144 | ng: AVR_FREQ = 16000000L 145 | ng: $(PROGRAM)_ng.hex 146 | 147 | ng_isp: ng 148 | ng_isp: TARGET = ng 149 | ng_isp: HFUSE = DD 150 | ng_isp: LFUSE = FF 151 | ng_isp: EFUSE = 00 152 | ng_isp: isp 153 | 154 | atmega328: TARGET = atmega328 155 | atmega328: MCU_TARGET = atmega328p 156 | atmega328: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>4' '-DNUM_LED_FLASHES=1' -DBAUD_RATE=57600 157 | atmega328: AVR_FREQ = 16000000L 158 | atmega328: LDSECTION = --section-start=.text=0x7800 159 | atmega328: $(PROGRAM)_atmega328.hex 160 | 161 | atmega328_isp: atmega328 162 | atmega328_isp: TARGET = atmega328 163 | atmega328_isp: MCU_TARGET = atmega328p 164 | atmega328_isp: HFUSE = DA 165 | atmega328_isp: LFUSE = FF 166 | atmega328_isp: EFUSE = 05 167 | atmega328_isp: isp 168 | 169 | atmega328_pro8: TARGET = atmega328_pro_8MHz 170 | atmega328_pro8: MCU_TARGET = atmega328p 171 | atmega328_pro8: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>4' '-DNUM_LED_FLASHES=1' -DBAUD_RATE=57600 -DDOUBLE_SPEED 172 | atmega328_pro8: AVR_FREQ = 8000000L 173 | atmega328_pro8: LDSECTION = --section-start=.text=0x7800 174 | atmega328_pro8: $(PROGRAM)_atmega328_pro_8MHz.hex 175 | 176 | atmega328_pro8_isp: atmega328_pro8 177 | atmega328_pro8_isp: TARGET = atmega328_pro_8MHz 178 | atmega328_pro8_isp: MCU_TARGET = atmega328p 179 | atmega328_pro8_isp: HFUSE = DA 180 | atmega328_pro8_isp: LFUSE = FF 181 | atmega328_pro8_isp: EFUSE = 05 182 | atmega328_pro8_isp: isp 183 | 184 | mega: TARGET = atmega1280 185 | mega: MCU_TARGET = atmega1280 186 | mega: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>4' '-DNUM_LED_FLASHES=0' -DBAUD_RATE=57600 187 | mega: AVR_FREQ = 16000000L 188 | mega: LDSECTION = --section-start=.text=0x1F000 189 | mega: $(PROGRAM)_atmega1280.hex 190 | 191 | mega_isp: mega 192 | mega_isp: TARGET = atmega1280 193 | mega_isp: MCU_TARGET = atmega1280 194 | mega_isp: HFUSE = DA 195 | mega_isp: LFUSE = FF 196 | mega_isp: EFUSE = F5 197 | mega_isp: isp 198 | 199 | at90can: TARGET = at90can128 200 | at90can: MCU_TARGET = at90can128 201 | at90can: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>4' '-DNUM_LED_FLASHES=1' -DBAUD_RATE=57600 202 | at90can: AVR_FREQ = 16000000L 203 | at90can: LDSECTION = --section-start=.text=0x1F800 204 | at90can: $(PROGRAM)_at90can.hex 205 | 206 | 207 | 208 | isp: $(TARGET) 209 | $(ISPFUSES) 210 | $(ISPFLASH) 211 | 212 | isp-stk500: $(PROGRAM)_$(TARGET).hex 213 | $(STK500-1) 214 | $(STK500-2) 215 | 216 | %.elf: $(OBJ) 217 | $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS) 218 | 219 | clean: 220 | rm -rf *.o *.elf *.lst *.map *.sym *.lss *.eep *.srec *.bin *.hex 221 | 222 | %.lst: %.elf 223 | $(OBJDUMP) -h -S $< > $@ 224 | 225 | %.hex: %.elf 226 | $(OBJCOPY) -j .text -j .data -O ihex $< $@ 227 | 228 | %.srec: %.elf 229 | $(OBJCOPY) -j .text -j .data -O srec $< $@ 230 | 231 | %.bin: %.elf 232 | $(OBJCOPY) -j .text -j .data -O binary $< $@ 233 | -------------------------------------------------------------------------------- /0023/at90can/cores/at90can/HardwareSerial.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | HardwareSerial.cpp - Hardware serial library for Wiring 3 | Copyright (c) 2006 Nicholas Zambetti. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | Modified 23 November 2006 by David A. Mellis 20 | */ 21 | 22 | #include 23 | #include 24 | #include 25 | #include "wiring.h" 26 | #include "wiring_private.h" 27 | 28 | #include "HardwareSerial.h" 29 | 30 | // Define constants and variables for buffering incoming serial data. We're 31 | // using a ring buffer (I think), in which rx_buffer_head is the index of the 32 | // location to which to write the next incoming character and rx_buffer_tail 33 | // is the index of the location from which to read. 34 | #define RX_BUFFER_SIZE 128 35 | 36 | struct ring_buffer { 37 | unsigned char buffer[RX_BUFFER_SIZE]; 38 | int head; 39 | int tail; 40 | }; 41 | 42 | ring_buffer rx_buffer = { { 0 }, 0, 0 }; 43 | ring_buffer rx_buffer1 = { { 0 }, 0, 0 }; 44 | 45 | 46 | inline void store_char(unsigned char c, ring_buffer *rx_buffer) 47 | { 48 | int i = (rx_buffer->head + 1) % RX_BUFFER_SIZE; 49 | 50 | // if we should be storing the received character into the location 51 | // just before the tail (meaning that the head would advance to the 52 | // current location of the tail), we're about to overflow the buffer 53 | // and so we don't write the character or advance the head. 54 | if (i != rx_buffer->tail) { 55 | rx_buffer->buffer[rx_buffer->head] = c; 56 | rx_buffer->head = i; 57 | } 58 | } 59 | 60 | 61 | SIGNAL(SIG_USART0_RECV) 62 | { 63 | unsigned char c = UDR0; 64 | store_char(c, &rx_buffer); 65 | } 66 | 67 | SIGNAL(SIG_USART1_RECV) 68 | { 69 | unsigned char c = UDR1; 70 | store_char(c, &rx_buffer1); 71 | } 72 | 73 | // Constructors //////////////////////////////////////////////////////////////// 74 | 75 | HardwareSerial::HardwareSerial(ring_buffer *rx_buffer, 76 | volatile uint8_t *ubrrh, volatile uint8_t *ubrrl, 77 | volatile uint8_t *ucsra, volatile uint8_t *ucsrb, 78 | volatile uint8_t *udr, 79 | uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udre, uint8_t u2x) 80 | { 81 | _rx_buffer = rx_buffer; 82 | _ubrrh = ubrrh; 83 | _ubrrl = ubrrl; 84 | _ucsra = ucsra; 85 | _ucsrb = ucsrb; 86 | _udr = udr; 87 | _rxen = rxen; 88 | _txen = txen; 89 | _rxcie = rxcie; 90 | _udre = udre; 91 | _u2x = u2x; 92 | } 93 | 94 | // Public Methods ////////////////////////////////////////////////////////////// 95 | 96 | void HardwareSerial::begin(long baud) 97 | { 98 | uint16_t baud_setting; 99 | bool use_u2x; 100 | 101 | // U2X mode is needed for baud rates higher than (CPU Hz / 16) 102 | if (baud > F_CPU / 16) { 103 | use_u2x = true; 104 | } else { 105 | // figure out if U2X mode would allow for a better connection 106 | 107 | // calculate the percent difference between the baud-rate specified and 108 | // the real baud rate for both U2X and non-U2X mode (0-255 error percent) 109 | uint8_t nonu2x_baud_error = abs((int)(255-((F_CPU/(16*(((F_CPU/8/baud-1)/2)+1))*255)/baud))); 110 | uint8_t u2x_baud_error = abs((int)(255-((F_CPU/(8*(((F_CPU/4/baud-1)/2)+1))*255)/baud))); 111 | 112 | // prefer non-U2X mode because it handles clock skew better 113 | use_u2x = (nonu2x_baud_error > u2x_baud_error); 114 | } 115 | 116 | if (use_u2x) { 117 | *_ucsra = 1 << _u2x; 118 | baud_setting = (F_CPU / 4 / baud - 1) / 2; 119 | } else { 120 | *_ucsra = 0; 121 | baud_setting = (F_CPU / 8 / baud - 1) / 2; 122 | } 123 | 124 | // assign the baud_setting, a.k.a. ubbr (USART Baud Rate Register) 125 | *_ubrrh = baud_setting >> 8; 126 | *_ubrrl = baud_setting; 127 | 128 | sbi(*_ucsrb, _rxen); 129 | sbi(*_ucsrb, _txen); 130 | sbi(*_ucsrb, _rxcie); 131 | } 132 | 133 | uint8_t HardwareSerial::available(void) 134 | { 135 | return (RX_BUFFER_SIZE + _rx_buffer->head - _rx_buffer->tail) % RX_BUFFER_SIZE; 136 | } 137 | 138 | int HardwareSerial::read(void) 139 | { 140 | // if the head isn't ahead of the tail, we don't have any characters 141 | if (_rx_buffer->head == _rx_buffer->tail) { 142 | return -1; 143 | } else { 144 | unsigned char c = _rx_buffer->buffer[_rx_buffer->tail]; 145 | _rx_buffer->tail = (_rx_buffer->tail + 1) % RX_BUFFER_SIZE; 146 | return c; 147 | } 148 | } 149 | 150 | void HardwareSerial::flush() 151 | { 152 | // don't reverse this or there may be problems if the RX interrupt 153 | // occurs after reading the value of rx_buffer_head but before writing 154 | // the value to rx_buffer_tail; the previous value of rx_buffer_head 155 | // may be written to rx_buffer_tail, making it appear as if the buffer 156 | // don't reverse this or there may be problems if the RX interrupt 157 | // occurs after reading the value of rx_buffer_head but before writing 158 | // the value to rx_buffer_tail; the previous value of rx_buffer_head 159 | // may be written to rx_buffer_tail, making it appear as if the buffer 160 | // were full, not empty. 161 | _rx_buffer->head = _rx_buffer->tail; 162 | } 163 | 164 | void HardwareSerial::write(uint8_t c) 165 | { 166 | while (!((*_ucsra) & (1 << _udre))) 167 | ; 168 | 169 | *_udr = c; 170 | } 171 | 172 | // Preinstantiate Objects ////////////////////////////////////////////////////// 173 | 174 | 175 | HardwareSerial Serial(&rx_buffer, &UBRR0H, &UBRR0L, &UCSR0A, &UCSR0B, &UDR0, RXEN0, TXEN0, RXCIE0, UDRE0, U2X0); 176 | HardwareSerial Serial1(&rx_buffer1, &UBRR1H, &UBRR1L, &UCSR1A, &UCSR1B, &UDR1, RXEN1, TXEN1, RXCIE1, UDRE1, U2X1); 177 | 178 | -------------------------------------------------------------------------------- /0023/at90can/cores/at90can/HardwareSerial.h: -------------------------------------------------------------------------------- 1 | /* 2 | HardwareSerial.h - Hardware serial library for Wiring 3 | Copyright (c) 2006 Nicholas Zambetti. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef HardwareSerial_h 21 | #define HardwareSerial_h 22 | 23 | #include 24 | 25 | #include "Print.h" 26 | 27 | struct ring_buffer; 28 | 29 | class HardwareSerial : public Print 30 | { 31 | private: 32 | ring_buffer *_rx_buffer; 33 | volatile uint8_t *_ubrrh; 34 | volatile uint8_t *_ubrrl; 35 | volatile uint8_t *_ucsra; 36 | volatile uint8_t *_ucsrb; 37 | volatile uint8_t *_udr; 38 | uint8_t _rxen; 39 | uint8_t _txen; 40 | uint8_t _rxcie; 41 | uint8_t _udre; 42 | uint8_t _u2x; 43 | public: 44 | HardwareSerial(ring_buffer *rx_buffer, 45 | volatile uint8_t *ubrrh, volatile uint8_t *ubrrl, 46 | volatile uint8_t *ucsra, volatile uint8_t *ucsrb, 47 | volatile uint8_t *udr, 48 | uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udre, uint8_t u2x); 49 | void begin(long); 50 | uint8_t available(void); 51 | int read(void); 52 | void flush(void); 53 | virtual void write(uint8_t); 54 | using Print::write; // pull in write(str) and write(buf, size) from Print 55 | }; 56 | 57 | extern HardwareSerial Serial; 58 | extern HardwareSerial Serial1; 59 | 60 | #endif -------------------------------------------------------------------------------- /0023/at90can/cores/at90can/Makefile: -------------------------------------------------------------------------------- 1 | # Arduino 0015 Makefile 2 | # Arduino adaptation by mellis, eighthave, oli.keller 3 | # 4 | # This makefile allows you to build sketches from the command line 5 | # without the Arduino environment (or Java). 6 | # 7 | # Detailed instructions for using the makefile: 8 | # 9 | # 1. Copy this file into the folder with your sketch. There should be a 10 | # file with the same name as the folder and with the extension .pde 11 | # (e.g. foo.pde in the foo/ folder). 12 | # 13 | # 2. Modify the line containg "INSTALL_DIR" to point to the directory that 14 | # contains the Arduino installation (for example, under Mac OS X, this 15 | # might be /Applications/arduino-0012). 16 | # 17 | # 3. Modify the line containing "PORT" to refer to the filename 18 | # representing the USB or serial connection to your Arduino board 19 | # (e.g. PORT = /dev/tty.USB0). If the exact name of this file 20 | # changes, you can use * as a wildcard (e.g. PORT = /dev/tty.usb*). 21 | # 22 | # 4. Set the line containing "MCU" to match your board's processor. 23 | # Older one's are atmega8 based, newer ones like Arduino Mini, Bluetooth 24 | # or Diecimila have the atmega168. If you're using a LilyPad Arduino, 25 | # change F_CPU to 8000000. 26 | # 27 | # 5. At the command line, change to the directory containing your 28 | # program's file and the makefile. 29 | # 30 | # 6. Type "make" and press enter to compile/verify your program. 31 | # 32 | # 7. Type "make upload", reset your Arduino board, and press enter to 33 | # upload your program to the Arduino board. 34 | # 35 | # $Id$ 36 | 37 | TARGET = $(notdir $(CURDIR)) 38 | INSTALL_DIR = ../../.. 39 | PORT = /dev/tty.usb* 40 | UPLOAD_RATE = 115200 41 | AVRDUDE_PROGRAMMER = jtagmki 42 | MCU = at90can128 43 | F_CPU = 16000000 44 | 45 | ############################################################################ 46 | # Below here nothing should be changed... 47 | 48 | ARDUINO = $(INSTALL_DIR)/hardware/cores/arduino 49 | AVR_TOOLS_PATH = $(INSTALL_DIR)/hardware/tools/avr/bin 50 | SRC = $(ARDUINO)/pins_arduino.c $(ARDUINO)/wiring.c \ 51 | $(ARDUINO)/wiring_analog.c $(ARDUINO)/wiring_digital.c \ 52 | $(ARDUINO)/wiring_pulse.c $(ARDUINO)/wiring_serial.c \ 53 | $(ARDUINO)/wiring_shift.c $(ARDUINO)/WInterrupts.c 54 | CXXSRC = $(ARDUINO)/HardwareSerial.cpp $(ARDUINO)/WMath.cpp \ 55 | $(ARDUINO)/Print.cpp 56 | FORMAT = ihex 57 | 58 | 59 | # Name of this Makefile (used for "make depend"). 60 | MAKEFILE = Makefile 61 | 62 | # Debugging format. 63 | # Native formats for AVR-GCC's -g are stabs [default], or dwarf-2. 64 | # AVR (extended) COFF requires stabs, plus an avr-objcopy run. 65 | DEBUG = stabs 66 | 67 | OPT = s 68 | 69 | # Place -D or -U options here 70 | CDEFS = -DF_CPU=$(F_CPU) 71 | CXXDEFS = -DF_CPU=$(F_CPU) 72 | 73 | # Place -I options here 74 | CINCS = -I$(ARDUINO) 75 | CXXINCS = -I$(ARDUINO) 76 | 77 | # Compiler flag to set the C Standard level. 78 | # c89 - "ANSI" C 79 | # gnu89 - c89 plus GCC extensions 80 | # c99 - ISO C99 standard (not yet fully implemented) 81 | # gnu99 - c99 plus GCC extensions 82 | CSTANDARD = -std=gnu99 83 | CDEBUG = -g$(DEBUG) 84 | CWARN = -Wall -Wstrict-prototypes 85 | CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums 86 | #CEXTRA = -Wa,-adhlns=$(<:.c=.lst) 87 | 88 | CFLAGS = $(CDEBUG) $(CDEFS) $(CINCS) -O$(OPT) $(CWARN) $(CSTANDARD) $(CEXTRA) 89 | CXXFLAGS = $(CDEFS) $(CINCS) -O$(OPT) 90 | #ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs 91 | LDFLAGS = -lm 92 | 93 | 94 | # Programming support using avrdude. Settings and variables. 95 | AVRDUDE_PORT = $(PORT) 96 | AVRDUDE_WRITE_FLASH = -U flash:w:applet/$(TARGET).hex 97 | AVRDUDE_FLAGS = -V -F -C $(INSTALL_DIR)/hardware/tools/avr/etc/avrdude.conf \ 98 | -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) \ 99 | -b $(UPLOAD_RATE) 100 | 101 | # Program settings 102 | CC = $(AVR_TOOLS_PATH)/avr-gcc 103 | CXX = $(AVR_TOOLS_PATH)/avr-g++ 104 | OBJCOPY = $(AVR_TOOLS_PATH)/avr-objcopy 105 | OBJDUMP = $(AVR_TOOLS_PATH)/avr-objdump 106 | AR = $(AVR_TOOLS_PATH)/avr-ar 107 | SIZE = $(AVR_TOOLS_PATH)/avr-size 108 | NM = $(AVR_TOOLS_PATH)/avr-nm 109 | AVRDUDE = $(AVR_TOOLS_PATH)/avrdude 110 | REMOVE = rm -f 111 | MV = mv -f 112 | 113 | # Define all object files. 114 | OBJ = $(SRC:.c=.o) $(CXXSRC:.cpp=.o) $(ASRC:.S=.o) 115 | 116 | # Define all listing files. 117 | LST = $(ASRC:.S=.lst) $(CXXSRC:.cpp=.lst) $(SRC:.c=.lst) 118 | 119 | # Combine all necessary flags and optional flags. 120 | # Add target processor to flags. 121 | ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) 122 | ALL_CXXFLAGS = -mmcu=$(MCU) -I. $(CXXFLAGS) 123 | ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS) 124 | 125 | 126 | # Default target. 127 | all: applet_files build sizeafter 128 | 129 | build: elf hex 130 | 131 | applet_files: $(TARGET).pde 132 | # Here is the "preprocessing". 133 | # It creates a .cpp file based with the same name as the .pde file. 134 | # On top of the new .cpp file comes the WProgram.h header. 135 | # At the end there is a generic main() function attached. 136 | # Then the .cpp file will be compiled. Errors during compile will 137 | # refer to this new, automatically generated, file. 138 | # Not the original .pde file you actually edit... 139 | test -d applet || mkdir applet 140 | echo '#include "WProgram.h"' > applet/$(TARGET).cpp 141 | cat $(TARGET).pde >> applet/$(TARGET).cpp 142 | cat $(ARDUINO)/main.cxx >> applet/$(TARGET).cpp 143 | 144 | elf: applet/$(TARGET).elf 145 | hex: applet/$(TARGET).hex 146 | eep: applet/$(TARGET).eep 147 | lss: applet/$(TARGET).lss 148 | sym: applet/$(TARGET).sym 149 | 150 | # Program the device. 151 | upload: applet/$(TARGET).hex 152 | $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) 153 | 154 | 155 | # Display size of file. 156 | HEXSIZE = $(SIZE) --target=$(FORMAT) applet/$(TARGET).hex 157 | ELFSIZE = $(SIZE) applet/$(TARGET).elf 158 | sizebefore: 159 | @if [ -f applet/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(HEXSIZE); echo; fi 160 | 161 | sizeafter: 162 | @if [ -f applet/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(HEXSIZE); echo; fi 163 | 164 | 165 | # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB. 166 | COFFCONVERT=$(OBJCOPY) --debugging \ 167 | --change-section-address .data-0x800000 \ 168 | --change-section-address .bss-0x800000 \ 169 | --change-section-address .noinit-0x800000 \ 170 | --change-section-address .eeprom-0x810000 171 | 172 | 173 | coff: applet/$(TARGET).elf 174 | $(COFFCONVERT) -O coff-avr applet/$(TARGET).elf $(TARGET).cof 175 | 176 | 177 | extcoff: $(TARGET).elf 178 | $(COFFCONVERT) -O coff-ext-avr applet/$(TARGET).elf $(TARGET).cof 179 | 180 | 181 | .SUFFIXES: .elf .hex .eep .lss .sym 182 | 183 | .elf.hex: 184 | $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@ 185 | 186 | .elf.eep: 187 | -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \ 188 | --change-section-lma .eeprom=0 -O $(FORMAT) $< $@ 189 | 190 | # Create extended listing file from ELF output file. 191 | .elf.lss: 192 | $(OBJDUMP) -h -S $< > $@ 193 | 194 | # Create a symbol table from ELF output file. 195 | .elf.sym: 196 | $(NM) -n $< > $@ 197 | 198 | # Link: create ELF output file from library. 199 | applet/$(TARGET).elf: $(TARGET).pde applet/core.a 200 | $(CC) $(ALL_CFLAGS) -o $@ applet/$(TARGET).cpp -L. applet/core.a $(LDFLAGS) 201 | 202 | applet/core.a: $(OBJ) 203 | @for i in $(OBJ); do echo $(AR) rcs applet/core.a $$i; $(AR) rcs applet/core.a $$i; done 204 | 205 | 206 | 207 | # Compile: create object files from C++ source files. 208 | .cpp.o: 209 | $(CXX) -c $(ALL_CXXFLAGS) $< -o $@ 210 | 211 | # Compile: create object files from C source files. 212 | .c.o: 213 | $(CC) -c $(ALL_CFLAGS) $< -o $@ 214 | 215 | 216 | # Compile: create assembler files from C source files. 217 | .c.s: 218 | $(CC) -S $(ALL_CFLAGS) $< -o $@ 219 | 220 | 221 | # Assemble: create object files from assembler source files. 222 | .S.o: 223 | $(CC) -c $(ALL_ASFLAGS) $< -o $@ 224 | 225 | 226 | # Automatic dependencies 227 | %.d: %.c 228 | $(CC) -M $(ALL_CFLAGS) $< | sed "s;$(notdir $*).o:;$*.o $*.d:;" > $@ 229 | 230 | %.d: %.cpp 231 | $(CXX) -M $(ALL_CXXFLAGS) $< | sed "s;$(notdir $*).o:;$*.o $*.d:;" > $@ 232 | 233 | 234 | # Target: clean project. 235 | clean: 236 | $(REMOVE) applet/$(TARGET).hex applet/$(TARGET).eep applet/$(TARGET).cof applet/$(TARGET).elf \ 237 | applet/$(TARGET).map applet/$(TARGET).sym applet/$(TARGET).lss applet/core.a \ 238 | $(OBJ) $(LST) $(SRC:.c=.s) $(SRC:.c=.d) $(CXXSRC:.cpp=.s) $(CXXSRC:.cpp=.d) 239 | 240 | .PHONY: all build elf hex eep lss sym program coff extcoff clean applet_files sizebefore sizeafter 241 | 242 | include $(SRC:.c=.d) 243 | include $(CXXSRC:.cpp=.d) 244 | -------------------------------------------------------------------------------- /0023/at90can/cores/at90can/Print.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Print.cpp - Base class that provides print() and println() 3 | Copyright (c) 2008 David A. Mellis. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | Modified 23 November 2006 by David A. Mellis 20 | */ 21 | 22 | #include 23 | #include 24 | #include 25 | #include "wiring.h" 26 | 27 | #include "Print.h" 28 | 29 | // Public Methods ////////////////////////////////////////////////////////////// 30 | 31 | /* default implementation: may be overridden */ 32 | void Print::write(const char *str) 33 | { 34 | while (*str) 35 | write(*str++); 36 | } 37 | 38 | /* default implementation: may be overridden */ 39 | void Print::write(const uint8_t *buffer, size_t size) 40 | { 41 | while (size--) 42 | write(*buffer++); 43 | } 44 | 45 | void Print::print(uint8_t b) 46 | { 47 | this->write(b); 48 | } 49 | 50 | void Print::print(char c) 51 | { 52 | print((byte) c); 53 | } 54 | 55 | void Print::print(const char str[]) 56 | { 57 | write(str); 58 | } 59 | 60 | void Print::print(int n) 61 | { 62 | print((long) n); 63 | } 64 | 65 | void Print::print(unsigned int n) 66 | { 67 | print((unsigned long) n); 68 | } 69 | 70 | void Print::print(long n) 71 | { 72 | if (n < 0) { 73 | print('-'); 74 | n = -n; 75 | } 76 | printNumber(n, 10); 77 | } 78 | 79 | void Print::print(unsigned long n) 80 | { 81 | printNumber(n, 10); 82 | } 83 | 84 | void Print::print(long n, int base) 85 | { 86 | if (base == 0) 87 | print((char) n); 88 | else if (base == 10) 89 | print(n); 90 | else 91 | printNumber(n, base); 92 | } 93 | 94 | void Print::print(double n) 95 | { 96 | printFloat(n, 2); 97 | } 98 | 99 | void Print::println(void) 100 | { 101 | print('\r'); 102 | print('\n'); 103 | } 104 | 105 | void Print::println(char c) 106 | { 107 | print(c); 108 | println(); 109 | } 110 | 111 | void Print::println(const char c[]) 112 | { 113 | print(c); 114 | println(); 115 | } 116 | 117 | void Print::println(uint8_t b) 118 | { 119 | print(b); 120 | println(); 121 | } 122 | 123 | void Print::println(int n) 124 | { 125 | print(n); 126 | println(); 127 | } 128 | 129 | void Print::println(unsigned int n) 130 | { 131 | print(n); 132 | println(); 133 | } 134 | 135 | void Print::println(long n) 136 | { 137 | print(n); 138 | println(); 139 | } 140 | 141 | void Print::println(unsigned long n) 142 | { 143 | print(n); 144 | println(); 145 | } 146 | 147 | void Print::println(long n, int base) 148 | { 149 | print(n, base); 150 | println(); 151 | } 152 | 153 | void Print::println(double n) 154 | { 155 | print(n); 156 | println(); 157 | } 158 | 159 | // Private Methods ///////////////////////////////////////////////////////////// 160 | 161 | void Print::printNumber(unsigned long n, uint8_t base) 162 | { 163 | unsigned char buf[8 * sizeof(long)]; // Assumes 8-bit chars. 164 | unsigned long i = 0; 165 | 166 | if (n == 0) { 167 | print('0'); 168 | return; 169 | } 170 | 171 | while (n > 0) { 172 | buf[i++] = n % base; 173 | n /= base; 174 | } 175 | 176 | for (; i > 0; i--) 177 | print((char) (buf[i - 1] < 10 ? 178 | '0' + buf[i - 1] : 179 | 'A' + buf[i - 1] - 10)); 180 | } 181 | 182 | void Print::printFloat(double number, uint8_t digits) 183 | { 184 | // Handle negative numbers 185 | if (number < 0.0) 186 | { 187 | print('-'); 188 | number = -number; 189 | } 190 | 191 | // Round correctly so that print(1.999, 2) prints as "2.00" 192 | double rounding = 0.5; 193 | for (uint8_t i=0; i 0) 205 | print("."); 206 | 207 | // Extract digits from the remainder one at a time 208 | while (digits-- > 0) 209 | { 210 | remainder *= 10.0; 211 | int toPrint = int(remainder); 212 | print(toPrint); 213 | remainder -= toPrint; 214 | } 215 | } 216 | -------------------------------------------------------------------------------- /0023/at90can/cores/at90can/Print.h: -------------------------------------------------------------------------------- 1 | /* 2 | Print.h - Base class that provides print() and println() 3 | Copyright (c) 2008 David A. Mellis. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef Print_h 21 | #define Print_h 22 | 23 | #include 24 | #include // for size_t 25 | 26 | #define DEC 10 27 | #define HEX 16 28 | #define OCT 8 29 | #define BIN 2 30 | #define BYTE 0 31 | 32 | class Print 33 | { 34 | private: 35 | void printNumber(unsigned long, uint8_t); 36 | void printFloat(double, uint8_t); 37 | public: 38 | virtual void write(uint8_t) = 0; 39 | virtual void write(const char *str); 40 | virtual void write(const uint8_t *buffer, size_t size); 41 | void print(char); 42 | void print(const char[]); 43 | void print(uint8_t); 44 | void print(int); 45 | void print(unsigned int); 46 | void print(long); 47 | void print(unsigned long); 48 | void print(long, int); 49 | void print(double); 50 | void println(void); 51 | void println(char); 52 | void println(const char[]); 53 | void println(uint8_t); 54 | void println(int); 55 | void println(unsigned int); 56 | void println(long); 57 | void println(unsigned long); 58 | void println(long, int); 59 | void println(double); 60 | }; 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /0023/at90can/cores/at90can/WConstants.h: -------------------------------------------------------------------------------- 1 | #include "wiring.h" 2 | -------------------------------------------------------------------------------- /0023/at90can/cores/at90can/WInterrupts.c: -------------------------------------------------------------------------------- 1 | /* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2 | 3 | /* 4 | Part of the Wiring project - http://wiring.uniandes.edu.co 5 | 6 | Copyright (c) 2004-05 Hernando Barragan 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 2.1 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General 19 | Public License along with this library; if not, write to the 20 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 21 | Boston, MA 02111-1307 USA 22 | 23 | Modified 24 November 2006 by David A. Mellis 24 | */ 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include "WConstants.h" 33 | #include "wiring_private.h" 34 | 35 | volatile static voidFuncPtr intFunc[EXTERNAL_NUM_INTERRUPTS]; 36 | // volatile static voidFuncPtr twiIntFunc; 37 | 38 | 39 | void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode) { 40 | if(interruptNum < EXTERNAL_NUM_INTERRUPTS) { 41 | intFunc[interruptNum] = userFunc; 42 | 43 | // Configure the interrupt mode (trigger on low input, any change, rising 44 | // edge, or falling edge). The mode constants were chosen to correspond 45 | // to the configuration bits in the hardware register, so we simply shift 46 | // the mode into place. 47 | 48 | // Enable the interrupt. 49 | 50 | switch (interruptNum) { 51 | case 0: 52 | EICRA = (EICRA & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00); 53 | EIMSK |= (1 << INT0); 54 | break; 55 | case 1: 56 | EICRA = (EICRA & ~((1 << ISC10) | (1 << ISC11))) | (mode << ISC10); 57 | EIMSK |= (1 << INT1); 58 | break; 59 | case 2: 60 | EICRA = (EICRA & ~((1 << ISC20) | (1 << ISC21))) | (mode << ISC20); 61 | EIMSK |= (1 << INT2); 62 | break; 63 | case 3: 64 | EICRA = (EICRA & ~((1 << ISC30) | (1 << ISC31))) | (mode << ISC30); 65 | EIMSK |= (1 << INT3); 66 | break; 67 | case 4: 68 | EICRB = (EICRB & ~((1 << ISC40) | (1 << ISC41))) | (mode << ISC40); 69 | EIMSK |= (1 << INT4); 70 | break; 71 | case 5: 72 | EICRB = (EICRB & ~((1 << ISC50) | (1 << ISC51))) | (mode << ISC50); 73 | EIMSK |= (1 << INT5); 74 | break; 75 | case 6: 76 | EICRB = (EICRB & ~((1 << ISC60) | (1 << ISC61))) | (mode << ISC60); 77 | EIMSK |= (1 << INT6); 78 | break; 79 | case 7: 80 | EICRB = (EICRB & ~((1 << ISC70) | (1 << ISC71))) | (mode << ISC70); 81 | EIMSK |= (1 << INT7); 82 | break; 83 | } 84 | } 85 | } 86 | 87 | void detachInterrupt(uint8_t interruptNum) { 88 | if(interruptNum < EXTERNAL_NUM_INTERRUPTS) { 89 | // Disable the interrupt. (We can't assume that interruptNum is equal 90 | // to the number of the EIMSK bit to clear, as this isn't true on the 91 | // ATmega8. There, INT0 is 6 and INT1 is 7.) 92 | switch (interruptNum) { 93 | case 0: 94 | EIMSK &= ~(1 << INT0); 95 | break; 96 | case 1: 97 | EIMSK &= ~(1 << INT1); 98 | break; 99 | case 2: 100 | EIMSK &= ~(1 << INT2); 101 | break; 102 | case 3: 103 | EIMSK &= ~(1 << INT3); 104 | break; 105 | case 4: 106 | EIMSK &= ~(1 << INT4); 107 | break; 108 | case 5: 109 | EIMSK &= ~(1 << INT5); 110 | break; 111 | case 6: 112 | EIMSK &= ~(1 << INT6); 113 | break; 114 | case 7: 115 | EIMSK &= ~(1 << INT7); 116 | break; 117 | } 118 | 119 | intFunc[interruptNum] = 0; 120 | } 121 | } 122 | 123 | /* 124 | void attachInterruptTwi(void (*userFunc)(void) ) { 125 | twiIntFunc = userFunc; 126 | } 127 | */ 128 | 129 | 130 | SIGNAL(INT0_vect) { 131 | if(intFunc[EXTERNAL_INT_0]) 132 | intFunc[EXTERNAL_INT_0](); 133 | } 134 | 135 | SIGNAL(INT1_vect) { 136 | if(intFunc[EXTERNAL_INT_1]) 137 | intFunc[EXTERNAL_INT_1](); 138 | } 139 | 140 | SIGNAL(INT2_vect) { 141 | if(intFunc[EXTERNAL_INT_2]) 142 | intFunc[EXTERNAL_INT_2](); 143 | } 144 | 145 | SIGNAL(INT3_vect) { 146 | if(intFunc[EXTERNAL_INT_3]) 147 | intFunc[EXTERNAL_INT_3](); 148 | } 149 | 150 | SIGNAL(INT4_vect) { 151 | if(intFunc[EXTERNAL_INT_4]) 152 | intFunc[EXTERNAL_INT_4](); 153 | } 154 | 155 | SIGNAL(INT5_vect) { 156 | if(intFunc[EXTERNAL_INT_5]) 157 | intFunc[EXTERNAL_INT_5](); 158 | } 159 | 160 | SIGNAL(INT6_vect) { 161 | if(intFunc[EXTERNAL_INT_6]) 162 | intFunc[EXTERNAL_INT_6](); 163 | } 164 | 165 | SIGNAL(INT7_vect) { 166 | if(intFunc[EXTERNAL_INT_7]) 167 | intFunc[EXTERNAL_INT_7](); 168 | } 169 | 170 | /* 171 | SIGNAL(SIG_2WIRE_SERIAL) { 172 | if(twiIntFunc) 173 | twiIntFunc(); 174 | } 175 | */ 176 | 177 | -------------------------------------------------------------------------------- /0023/at90can/cores/at90can/WMath.cpp: -------------------------------------------------------------------------------- 1 | /* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2 | 3 | /* 4 | Part of the Wiring project - http://wiring.org.co 5 | Copyright (c) 2004-06 Hernando Barragan 6 | Modified 13 August 2006, David A. Mellis for Arduino - http://www.arduino.cc/ 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 2.1 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General 19 | Public License along with this library; if not, write to the 20 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 21 | Boston, MA 02111-1307 USA 22 | 23 | $Id$ 24 | */ 25 | 26 | extern "C" { 27 | #include "stdlib.h" 28 | } 29 | 30 | void randomSeed(unsigned int seed) 31 | { 32 | if (seed != 0) { 33 | srandom(seed); 34 | } 35 | } 36 | 37 | long random(long howbig) 38 | { 39 | if (howbig == 0) { 40 | return 0; 41 | } 42 | return random() % howbig; 43 | } 44 | 45 | long random(long howsmall, long howbig) 46 | { 47 | if (howsmall >= howbig) { 48 | return howsmall; 49 | } 50 | long diff = howbig - howsmall; 51 | return random(diff) + howsmall; 52 | } 53 | 54 | long map(long x, long in_min, long in_max, long out_min, long out_max) 55 | { 56 | return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; 57 | } 58 | 59 | unsigned int makeWord(unsigned int w) { return w; } 60 | unsigned int makeWord(unsigned char h, unsigned char l) { return (h << 8) | l; } -------------------------------------------------------------------------------- /0023/at90can/cores/at90can/WProgram.h: -------------------------------------------------------------------------------- 1 | #ifndef WProgram_h 2 | #define WProgram_h 3 | 4 | #define NULL 0 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | 12 | #include "wiring.h" 13 | 14 | #ifdef __cplusplus 15 | #include "HardwareSerial.h" 16 | #include "can_lib.h" 17 | 18 | uint16_t makeWord(uint16_t w); 19 | uint16_t makeWord(byte h, byte l); 20 | 21 | #define word(...) makeWord(__VA_ARGS__) 22 | 23 | unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L); 24 | 25 | // WMath prototypes 26 | long random(long); 27 | long random(long, long); 28 | void randomSeed(unsigned int); 29 | long map(long, long, long, long, long); 30 | #endif 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /0023/at90can/cores/at90can/binary.h: -------------------------------------------------------------------------------- 1 | #ifndef Binary_h 2 | #define Binary_h 3 | 4 | #define B0 0 5 | #define B00 0 6 | #define B000 0 7 | #define B0000 0 8 | #define B00000 0 9 | #define B000000 0 10 | #define B0000000 0 11 | #define B00000000 0 12 | #define B1 1 13 | #define B01 1 14 | #define B001 1 15 | #define B0001 1 16 | #define B00001 1 17 | #define B000001 1 18 | #define B0000001 1 19 | #define B00000001 1 20 | #define B10 2 21 | #define B010 2 22 | #define B0010 2 23 | #define B00010 2 24 | #define B000010 2 25 | #define B0000010 2 26 | #define B00000010 2 27 | #define B11 3 28 | #define B011 3 29 | #define B0011 3 30 | #define B00011 3 31 | #define B000011 3 32 | #define B0000011 3 33 | #define B00000011 3 34 | #define B100 4 35 | #define B0100 4 36 | #define B00100 4 37 | #define B000100 4 38 | #define B0000100 4 39 | #define B00000100 4 40 | #define B101 5 41 | #define B0101 5 42 | #define B00101 5 43 | #define B000101 5 44 | #define B0000101 5 45 | #define B00000101 5 46 | #define B110 6 47 | #define B0110 6 48 | #define B00110 6 49 | #define B000110 6 50 | #define B0000110 6 51 | #define B00000110 6 52 | #define B111 7 53 | #define B0111 7 54 | #define B00111 7 55 | #define B000111 7 56 | #define B0000111 7 57 | #define B00000111 7 58 | #define B1000 8 59 | #define B01000 8 60 | #define B001000 8 61 | #define B0001000 8 62 | #define B00001000 8 63 | #define B1001 9 64 | #define B01001 9 65 | #define B001001 9 66 | #define B0001001 9 67 | #define B00001001 9 68 | #define B1010 10 69 | #define B01010 10 70 | #define B001010 10 71 | #define B0001010 10 72 | #define B00001010 10 73 | #define B1011 11 74 | #define B01011 11 75 | #define B001011 11 76 | #define B0001011 11 77 | #define B00001011 11 78 | #define B1100 12 79 | #define B01100 12 80 | #define B001100 12 81 | #define B0001100 12 82 | #define B00001100 12 83 | #define B1101 13 84 | #define B01101 13 85 | #define B001101 13 86 | #define B0001101 13 87 | #define B00001101 13 88 | #define B1110 14 89 | #define B01110 14 90 | #define B001110 14 91 | #define B0001110 14 92 | #define B00001110 14 93 | #define B1111 15 94 | #define B01111 15 95 | #define B001111 15 96 | #define B0001111 15 97 | #define B00001111 15 98 | #define B10000 16 99 | #define B010000 16 100 | #define B0010000 16 101 | #define B00010000 16 102 | #define B10001 17 103 | #define B010001 17 104 | #define B0010001 17 105 | #define B00010001 17 106 | #define B10010 18 107 | #define B010010 18 108 | #define B0010010 18 109 | #define B00010010 18 110 | #define B10011 19 111 | #define B010011 19 112 | #define B0010011 19 113 | #define B00010011 19 114 | #define B10100 20 115 | #define B010100 20 116 | #define B0010100 20 117 | #define B00010100 20 118 | #define B10101 21 119 | #define B010101 21 120 | #define B0010101 21 121 | #define B00010101 21 122 | #define B10110 22 123 | #define B010110 22 124 | #define B0010110 22 125 | #define B00010110 22 126 | #define B10111 23 127 | #define B010111 23 128 | #define B0010111 23 129 | #define B00010111 23 130 | #define B11000 24 131 | #define B011000 24 132 | #define B0011000 24 133 | #define B00011000 24 134 | #define B11001 25 135 | #define B011001 25 136 | #define B0011001 25 137 | #define B00011001 25 138 | #define B11010 26 139 | #define B011010 26 140 | #define B0011010 26 141 | #define B00011010 26 142 | #define B11011 27 143 | #define B011011 27 144 | #define B0011011 27 145 | #define B00011011 27 146 | #define B11100 28 147 | #define B011100 28 148 | #define B0011100 28 149 | #define B00011100 28 150 | #define B11101 29 151 | #define B011101 29 152 | #define B0011101 29 153 | #define B00011101 29 154 | #define B11110 30 155 | #define B011110 30 156 | #define B0011110 30 157 | #define B00011110 30 158 | #define B11111 31 159 | #define B011111 31 160 | #define B0011111 31 161 | #define B00011111 31 162 | #define B100000 32 163 | #define B0100000 32 164 | #define B00100000 32 165 | #define B100001 33 166 | #define B0100001 33 167 | #define B00100001 33 168 | #define B100010 34 169 | #define B0100010 34 170 | #define B00100010 34 171 | #define B100011 35 172 | #define B0100011 35 173 | #define B00100011 35 174 | #define B100100 36 175 | #define B0100100 36 176 | #define B00100100 36 177 | #define B100101 37 178 | #define B0100101 37 179 | #define B00100101 37 180 | #define B100110 38 181 | #define B0100110 38 182 | #define B00100110 38 183 | #define B100111 39 184 | #define B0100111 39 185 | #define B00100111 39 186 | #define B101000 40 187 | #define B0101000 40 188 | #define B00101000 40 189 | #define B101001 41 190 | #define B0101001 41 191 | #define B00101001 41 192 | #define B101010 42 193 | #define B0101010 42 194 | #define B00101010 42 195 | #define B101011 43 196 | #define B0101011 43 197 | #define B00101011 43 198 | #define B101100 44 199 | #define B0101100 44 200 | #define B00101100 44 201 | #define B101101 45 202 | #define B0101101 45 203 | #define B00101101 45 204 | #define B101110 46 205 | #define B0101110 46 206 | #define B00101110 46 207 | #define B101111 47 208 | #define B0101111 47 209 | #define B00101111 47 210 | #define B110000 48 211 | #define B0110000 48 212 | #define B00110000 48 213 | #define B110001 49 214 | #define B0110001 49 215 | #define B00110001 49 216 | #define B110010 50 217 | #define B0110010 50 218 | #define B00110010 50 219 | #define B110011 51 220 | #define B0110011 51 221 | #define B00110011 51 222 | #define B110100 52 223 | #define B0110100 52 224 | #define B00110100 52 225 | #define B110101 53 226 | #define B0110101 53 227 | #define B00110101 53 228 | #define B110110 54 229 | #define B0110110 54 230 | #define B00110110 54 231 | #define B110111 55 232 | #define B0110111 55 233 | #define B00110111 55 234 | #define B111000 56 235 | #define B0111000 56 236 | #define B00111000 56 237 | #define B111001 57 238 | #define B0111001 57 239 | #define B00111001 57 240 | #define B111010 58 241 | #define B0111010 58 242 | #define B00111010 58 243 | #define B111011 59 244 | #define B0111011 59 245 | #define B00111011 59 246 | #define B111100 60 247 | #define B0111100 60 248 | #define B00111100 60 249 | #define B111101 61 250 | #define B0111101 61 251 | #define B00111101 61 252 | #define B111110 62 253 | #define B0111110 62 254 | #define B00111110 62 255 | #define B111111 63 256 | #define B0111111 63 257 | #define B00111111 63 258 | #define B1000000 64 259 | #define B01000000 64 260 | #define B1000001 65 261 | #define B01000001 65 262 | #define B1000010 66 263 | #define B01000010 66 264 | #define B1000011 67 265 | #define B01000011 67 266 | #define B1000100 68 267 | #define B01000100 68 268 | #define B1000101 69 269 | #define B01000101 69 270 | #define B1000110 70 271 | #define B01000110 70 272 | #define B1000111 71 273 | #define B01000111 71 274 | #define B1001000 72 275 | #define B01001000 72 276 | #define B1001001 73 277 | #define B01001001 73 278 | #define B1001010 74 279 | #define B01001010 74 280 | #define B1001011 75 281 | #define B01001011 75 282 | #define B1001100 76 283 | #define B01001100 76 284 | #define B1001101 77 285 | #define B01001101 77 286 | #define B1001110 78 287 | #define B01001110 78 288 | #define B1001111 79 289 | #define B01001111 79 290 | #define B1010000 80 291 | #define B01010000 80 292 | #define B1010001 81 293 | #define B01010001 81 294 | #define B1010010 82 295 | #define B01010010 82 296 | #define B1010011 83 297 | #define B01010011 83 298 | #define B1010100 84 299 | #define B01010100 84 300 | #define B1010101 85 301 | #define B01010101 85 302 | #define B1010110 86 303 | #define B01010110 86 304 | #define B1010111 87 305 | #define B01010111 87 306 | #define B1011000 88 307 | #define B01011000 88 308 | #define B1011001 89 309 | #define B01011001 89 310 | #define B1011010 90 311 | #define B01011010 90 312 | #define B1011011 91 313 | #define B01011011 91 314 | #define B1011100 92 315 | #define B01011100 92 316 | #define B1011101 93 317 | #define B01011101 93 318 | #define B1011110 94 319 | #define B01011110 94 320 | #define B1011111 95 321 | #define B01011111 95 322 | #define B1100000 96 323 | #define B01100000 96 324 | #define B1100001 97 325 | #define B01100001 97 326 | #define B1100010 98 327 | #define B01100010 98 328 | #define B1100011 99 329 | #define B01100011 99 330 | #define B1100100 100 331 | #define B01100100 100 332 | #define B1100101 101 333 | #define B01100101 101 334 | #define B1100110 102 335 | #define B01100110 102 336 | #define B1100111 103 337 | #define B01100111 103 338 | #define B1101000 104 339 | #define B01101000 104 340 | #define B1101001 105 341 | #define B01101001 105 342 | #define B1101010 106 343 | #define B01101010 106 344 | #define B1101011 107 345 | #define B01101011 107 346 | #define B1101100 108 347 | #define B01101100 108 348 | #define B1101101 109 349 | #define B01101101 109 350 | #define B1101110 110 351 | #define B01101110 110 352 | #define B1101111 111 353 | #define B01101111 111 354 | #define B1110000 112 355 | #define B01110000 112 356 | #define B1110001 113 357 | #define B01110001 113 358 | #define B1110010 114 359 | #define B01110010 114 360 | #define B1110011 115 361 | #define B01110011 115 362 | #define B1110100 116 363 | #define B01110100 116 364 | #define B1110101 117 365 | #define B01110101 117 366 | #define B1110110 118 367 | #define B01110110 118 368 | #define B1110111 119 369 | #define B01110111 119 370 | #define B1111000 120 371 | #define B01111000 120 372 | #define B1111001 121 373 | #define B01111001 121 374 | #define B1111010 122 375 | #define B01111010 122 376 | #define B1111011 123 377 | #define B01111011 123 378 | #define B1111100 124 379 | #define B01111100 124 380 | #define B1111101 125 381 | #define B01111101 125 382 | #define B1111110 126 383 | #define B01111110 126 384 | #define B1111111 127 385 | #define B01111111 127 386 | #define B10000000 128 387 | #define B10000001 129 388 | #define B10000010 130 389 | #define B10000011 131 390 | #define B10000100 132 391 | #define B10000101 133 392 | #define B10000110 134 393 | #define B10000111 135 394 | #define B10001000 136 395 | #define B10001001 137 396 | #define B10001010 138 397 | #define B10001011 139 398 | #define B10001100 140 399 | #define B10001101 141 400 | #define B10001110 142 401 | #define B10001111 143 402 | #define B10010000 144 403 | #define B10010001 145 404 | #define B10010010 146 405 | #define B10010011 147 406 | #define B10010100 148 407 | #define B10010101 149 408 | #define B10010110 150 409 | #define B10010111 151 410 | #define B10011000 152 411 | #define B10011001 153 412 | #define B10011010 154 413 | #define B10011011 155 414 | #define B10011100 156 415 | #define B10011101 157 416 | #define B10011110 158 417 | #define B10011111 159 418 | #define B10100000 160 419 | #define B10100001 161 420 | #define B10100010 162 421 | #define B10100011 163 422 | #define B10100100 164 423 | #define B10100101 165 424 | #define B10100110 166 425 | #define B10100111 167 426 | #define B10101000 168 427 | #define B10101001 169 428 | #define B10101010 170 429 | #define B10101011 171 430 | #define B10101100 172 431 | #define B10101101 173 432 | #define B10101110 174 433 | #define B10101111 175 434 | #define B10110000 176 435 | #define B10110001 177 436 | #define B10110010 178 437 | #define B10110011 179 438 | #define B10110100 180 439 | #define B10110101 181 440 | #define B10110110 182 441 | #define B10110111 183 442 | #define B10111000 184 443 | #define B10111001 185 444 | #define B10111010 186 445 | #define B10111011 187 446 | #define B10111100 188 447 | #define B10111101 189 448 | #define B10111110 190 449 | #define B10111111 191 450 | #define B11000000 192 451 | #define B11000001 193 452 | #define B11000010 194 453 | #define B11000011 195 454 | #define B11000100 196 455 | #define B11000101 197 456 | #define B11000110 198 457 | #define B11000111 199 458 | #define B11001000 200 459 | #define B11001001 201 460 | #define B11001010 202 461 | #define B11001011 203 462 | #define B11001100 204 463 | #define B11001101 205 464 | #define B11001110 206 465 | #define B11001111 207 466 | #define B11010000 208 467 | #define B11010001 209 468 | #define B11010010 210 469 | #define B11010011 211 470 | #define B11010100 212 471 | #define B11010101 213 472 | #define B11010110 214 473 | #define B11010111 215 474 | #define B11011000 216 475 | #define B11011001 217 476 | #define B11011010 218 477 | #define B11011011 219 478 | #define B11011100 220 479 | #define B11011101 221 480 | #define B11011110 222 481 | #define B11011111 223 482 | #define B11100000 224 483 | #define B11100001 225 484 | #define B11100010 226 485 | #define B11100011 227 486 | #define B11100100 228 487 | #define B11100101 229 488 | #define B11100110 230 489 | #define B11100111 231 490 | #define B11101000 232 491 | #define B11101001 233 492 | #define B11101010 234 493 | #define B11101011 235 494 | #define B11101100 236 495 | #define B11101101 237 496 | #define B11101110 238 497 | #define B11101111 239 498 | #define B11110000 240 499 | #define B11110001 241 500 | #define B11110010 242 501 | #define B11110011 243 502 | #define B11110100 244 503 | #define B11110101 245 504 | #define B11110110 246 505 | #define B11110111 247 506 | #define B11111000 248 507 | #define B11111001 249 508 | #define B11111010 250 509 | #define B11111011 251 510 | #define B11111100 252 511 | #define B11111101 253 512 | #define B11111110 254 513 | #define B11111111 255 514 | 515 | #endif 516 | -------------------------------------------------------------------------------- /0023/at90can/cores/at90can/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | init(); 6 | 7 | setup(); 8 | 9 | for (;;) 10 | loop(); 11 | 12 | return 0; 13 | } 14 | 15 | -------------------------------------------------------------------------------- /0023/at90can/cores/at90can/pins_arduino.c: -------------------------------------------------------------------------------- 1 | /* 2 | pins_arduino.c - pin definitions for the Arduino board 3 | Part of Arduino / Wiring Lite 4 | 5 | Copyright (c) 2005 David A. Mellis 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | 22 | $Id: pins_arduino.c 565 2009-03-25 10:50:00Z dmellis $ 23 | */ 24 | 25 | #include 26 | #include "wiring_private.h" 27 | #include "pins_arduino.h" 28 | 29 | // On the Arduino board, digital pins are also used 30 | // for the analog output (software PWM). Analog input 31 | // pins are a separate set. 32 | 33 | 34 | #define PA 1 35 | #define PB 2 36 | #define PC 3 37 | #define PD 4 38 | #define PE 5 39 | #define PF 6 40 | #define PG 7 41 | 42 | 43 | #define REPEAT8(x) x, x, x, x, x, x, x, x 44 | #define BV0TO7 _BV(0), _BV(1), _BV(2), _BV(3), _BV(4), _BV(5), _BV(6), _BV(7) 45 | #define BV7TO0 _BV(7), _BV(6), _BV(5), _BV(4), _BV(3), _BV(2), _BV(1), _BV(0) 46 | 47 | const uint16_t PROGMEM port_to_mode_PGM[] = { 48 | NOT_A_PORT, 49 | &DDRA, 50 | &DDRB, 51 | &DDRC, 52 | &DDRD, 53 | &DDRE, 54 | &DDRF, 55 | &DDRG, 56 | }; 57 | 58 | const uint16_t PROGMEM port_to_output_PGM[] = { 59 | NOT_A_PORT, 60 | &PORTA, 61 | &PORTB, 62 | &PORTC, 63 | &PORTD, 64 | &PORTE, 65 | &PORTF, 66 | &PORTG, 67 | }; 68 | 69 | const uint16_t PROGMEM port_to_input_PGM[] = { 70 | NOT_A_PIN, 71 | &PINA, 72 | &PINB, 73 | &PINC, 74 | &PIND, 75 | &PINE, 76 | &PINF, 77 | &PING, 78 | }; 79 | 80 | const uint8_t PROGMEM digital_pin_to_port_PGM[] = { 81 | PA, /* PORT A D0*/ 82 | PA, 83 | PA, 84 | PA, 85 | PA, 86 | PA, 87 | PA, 88 | PA, 89 | PB, /* PORT B D8*/ 90 | PB, 91 | PB, 92 | PB, 93 | PB, 94 | PB, 95 | PB, 96 | PB, 97 | PC, /* PORT C D16*/ 98 | PC, 99 | PC, 100 | PC, 101 | PC, 102 | PC, 103 | PC, 104 | PC, 105 | PD, /* PORT D D24*/ 106 | PD, 107 | PD, 108 | PD, 109 | PD, 110 | PD, 111 | PD, 112 | PD, 113 | PE, /* PORT E D32*/ 114 | PE, 115 | PE, 116 | PE, 117 | PE, 118 | PE, 119 | PE, 120 | PE, 121 | PG, /* PORT G D40*/ 122 | PG, 123 | PG, 124 | PG, 125 | PG, 126 | PF, /* PORT F D45*/ 127 | PF, 128 | PF, 129 | PF, 130 | }; 131 | 132 | const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = { 133 | _BV(0), /* 0 PORT A */ 134 | _BV(1), 135 | _BV(2), 136 | _BV(3), 137 | _BV(4), 138 | _BV(5), 139 | _BV(6), 140 | _BV(7), 141 | _BV(0), /* 8 PORT B */ 142 | _BV(1), 143 | _BV(2), 144 | _BV(3), 145 | _BV(4), 146 | _BV(5), 147 | _BV(6), 148 | _BV(7), 149 | _BV(0), /* 16 PORT C */ 150 | _BV(1), 151 | _BV(2), 152 | _BV(3), 153 | _BV(4), 154 | _BV(5), 155 | _BV(6), 156 | _BV(7), 157 | _BV(0), /* 24 PORT D */ 158 | _BV(1), 159 | _BV(2), 160 | _BV(3), 161 | _BV(4), 162 | _BV(5), 163 | _BV(6), 164 | _BV(7), 165 | _BV(0), /* 32 PORT E */ 166 | _BV(1), 167 | _BV(2), 168 | _BV(3), 169 | _BV(4), 170 | _BV(5), 171 | _BV(6), 172 | _BV(7), 173 | _BV(0), /* 40 PORT G */ 174 | _BV(1), 175 | _BV(2), 176 | _BV(3), 177 | _BV(4), 178 | _BV(0), /* 45 PORT F ANALOOG*/ 179 | _BV(1), 180 | _BV(2), 181 | _BV(3), 182 | }; 183 | 184 | const uint8_t PROGMEM digital_pin_to_timer_PGM[] = { 185 | NOT_ON_TIMER, /* 0 PORT A */ 186 | NOT_ON_TIMER, 187 | NOT_ON_TIMER, 188 | NOT_ON_TIMER, 189 | NOT_ON_TIMER, 190 | NOT_ON_TIMER, 191 | NOT_ON_TIMER, 192 | NOT_ON_TIMER, 193 | NOT_ON_TIMER, /* 8 PORT B */ 194 | NOT_ON_TIMER, 195 | NOT_ON_TIMER, 196 | NOT_ON_TIMER, 197 | TIMER2A, // 12 198 | TIMER1A, // 13 199 | TIMER1B, // 14 200 | TIMER1C, // 15 201 | NOT_ON_TIMER, /* 16 PORT C */ 202 | NOT_ON_TIMER, 203 | NOT_ON_TIMER, 204 | NOT_ON_TIMER, 205 | NOT_ON_TIMER, 206 | NOT_ON_TIMER, 207 | NOT_ON_TIMER, 208 | NOT_ON_TIMER, 209 | NOT_ON_TIMER, /* 24 PORT D */ 210 | NOT_ON_TIMER, 211 | NOT_ON_TIMER, 212 | NOT_ON_TIMER, 213 | NOT_ON_TIMER, 214 | NOT_ON_TIMER, 215 | NOT_ON_TIMER, 216 | NOT_ON_TIMER, 217 | NOT_ON_TIMER, /* 32 PORT E */ 218 | NOT_ON_TIMER, 219 | NOT_ON_TIMER, 220 | TIMER3A, // 35 221 | TIMER3B, // 36 222 | TIMER3C, // 37 223 | NOT_ON_TIMER, 224 | NOT_ON_TIMER, 225 | NOT_ON_TIMER, /* PORT G */ 226 | NOT_ON_TIMER, 227 | NOT_ON_TIMER, 228 | NOT_ON_TIMER, 229 | NOT_ON_TIMER, 230 | NOT_ON_TIMER, /* PORT F */ 231 | NOT_ON_TIMER, 232 | NOT_ON_TIMER, 233 | NOT_ON_TIMER, 234 | }; 235 | -------------------------------------------------------------------------------- /0023/at90can/cores/at90can/pins_arduino.h: -------------------------------------------------------------------------------- 1 | /* 2 | pins_arduino.h - Pin definition functions for Arduino 3 | Part of Arduino - http://www.arduino.cc/ 4 | 5 | Copyright (c) 2007 David A. Mellis 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | 22 | $Id: wiring.h 249 2007-02-03 16:52:51Z mellis $ 23 | */ 24 | 25 | #ifndef Pins_Arduino_h 26 | #define Pins_Arduino_h 27 | 28 | #include 29 | 30 | #define NOT_A_PIN 0 31 | #define NOT_A_PORT 0 32 | 33 | #define NOT_ON_TIMER 0 34 | #define TIMER0A 1 35 | #define TIMER1A 2 36 | #define TIMER1B 3 37 | #define TIMER1C 4 38 | #define TIMER2A 5 39 | #define TIMER3A 6 40 | #define TIMER3B 7 41 | #define TIMER3C 8 42 | 43 | const static uint8_t SS = 8; // PB0 44 | const static uint8_t MOSI = 10; // PB2 45 | const static uint8_t MISO = 11; // PB3 46 | const static uint8_t SCK = 9; // PB1 47 | 48 | static const uint8_t SDA = 25; // PD1 49 | static const uint8_t SCL = 24; // PD0 50 | 51 | // On the ATmega1280, the addresses of some of the port registers are 52 | // greater than 255, so we can't store them in uint8_t's. 53 | extern const uint16_t PROGMEM port_to_mode_PGM[]; 54 | extern const uint16_t PROGMEM port_to_input_PGM[]; 55 | extern const uint16_t PROGMEM port_to_output_PGM[]; 56 | 57 | extern const uint8_t PROGMEM digital_pin_to_port_PGM[]; 58 | // extern const uint8_t PROGMEM digital_pin_to_bit_PGM[]; 59 | extern const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[]; 60 | extern const uint8_t PROGMEM digital_pin_to_timer_PGM[]; 61 | 62 | // Get the bit location within the hardware port of the given virtual pin. 63 | // This comes from the pins_*.c file for the active board configuration. 64 | // 65 | // These perform slightly better as macros compared to inline functions 66 | // 67 | #define digitalPinToPort(P) ( pgm_read_byte( digital_pin_to_port_PGM + (P) ) ) 68 | #define digitalPinToBitMask(P) ( pgm_read_byte( digital_pin_to_bit_mask_PGM + (P) ) ) 69 | #define digitalPinToTimer(P) ( pgm_read_byte( digital_pin_to_timer_PGM + (P) ) ) 70 | #define analogInPinToBit(P) (P) 71 | #define portOutputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_output_PGM + (P))) ) 72 | #define portInputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_input_PGM + (P))) ) 73 | #define portModeRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_mode_PGM + (P))) ) 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /0023/at90can/cores/at90can/wiring.c: -------------------------------------------------------------------------------- 1 | /* 2 | wiring.c - Partial implementation of the Wiring API for the ATmega8. 3 | Part of Arduino - http://www.arduino.cc/ 4 | 5 | Copyright (c) 2005-2006 David A. Mellis 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | 22 | $Id: wiring.c 585 2009-05-12 10:55:26Z dmellis $ 23 | */ 24 | 25 | #include "wiring_private.h" 26 | 27 | // the prescaler is set so that timer0 ticks every 64 clock cycles, and the 28 | // the overflow handler is called every 256 ticks. 29 | #define MICROSECONDS_PER_TIMER0_OVERFLOW (clockCyclesToMicroseconds(64 * 256)) 30 | 31 | // the whole number of milliseconds per timer0 overflow 32 | #define MILLIS_INC (MICROSECONDS_PER_TIMER0_OVERFLOW / 1000) 33 | 34 | // the fractional number of milliseconds per timer0 overflow. we shift right 35 | // by three to fit these numbers into a byte. (for the clock speeds we care 36 | // about - 8 and 16 MHz - this doesn't lose precision.) 37 | #define FRACT_INC ((MICROSECONDS_PER_TIMER0_OVERFLOW % 1000) >> 3) 38 | #define FRACT_MAX (1000 >> 3) 39 | 40 | volatile unsigned long timer0_overflow_count = 0; 41 | volatile unsigned long timer0_millis = 0; 42 | static unsigned char timer0_fract = 0; 43 | 44 | SIGNAL(TIMER0_OVF_vect) 45 | { 46 | // copy these to local variables so they can be stored in registers 47 | // (volatile variables must be read from memory on every access) 48 | unsigned long m = timer0_millis; 49 | unsigned char f = timer0_fract; 50 | 51 | m += MILLIS_INC; 52 | f += FRACT_INC; 53 | if (f >= FRACT_MAX) { 54 | f -= FRACT_MAX; 55 | m += 1; 56 | } 57 | 58 | timer0_fract = f; 59 | timer0_millis = m; 60 | timer0_overflow_count++; 61 | } 62 | 63 | unsigned long millis() 64 | { 65 | unsigned long m; 66 | uint8_t oldSREG = SREG; 67 | 68 | // disable interrupts while we read timer0_millis or we might get an 69 | // inconsistent value (e.g. in the middle of a write to timer0_millis) 70 | cli(); 71 | m = timer0_millis; 72 | SREG = oldSREG; 73 | 74 | return m; 75 | } 76 | 77 | unsigned long micros() { 78 | unsigned long m, t; 79 | uint8_t oldSREG = SREG; 80 | 81 | cli(); 82 | t = TCNT0; 83 | 84 | #ifdef TIFR0 85 | if ((TIFR0 & _BV(TOV0)) && (t == 0)) 86 | t = 256; 87 | #else 88 | if ((TIFR & _BV(TOV0)) && (t == 0)) 89 | t = 256; 90 | #endif 91 | 92 | m = timer0_overflow_count; 93 | SREG = oldSREG; 94 | 95 | return ((m << 8) + t) * (64 / clockCyclesPerMicrosecond()); 96 | } 97 | 98 | void delay(unsigned long ms) 99 | { 100 | unsigned long start = millis(); 101 | 102 | while (millis() - start <= ms) 103 | ; 104 | } 105 | 106 | /* Delay for the given number of microseconds. Assumes a 8 or 16 MHz clock. 107 | * Disables interrupts, which will disrupt the millis() function if used 108 | * too frequently. */ 109 | void delayMicroseconds(unsigned int us) 110 | { 111 | uint8_t oldSREG; 112 | 113 | // calling avrlib's delay_us() function with low values (e.g. 1 or 114 | // 2 microseconds) gives delays longer than desired. 115 | //delay_us(us); 116 | 117 | #if F_CPU >= 16000000L 118 | // for the 16 MHz clock on most Arduino boards 119 | 120 | // for a one-microsecond delay, simply return. the overhead 121 | // of the function call yields a delay of approximately 1 1/8 us. 122 | if (--us == 0) 123 | return; 124 | 125 | // the following loop takes a quarter of a microsecond (4 cycles) 126 | // per iteration, so execute it four times for each microsecond of 127 | // delay requested. 128 | us <<= 2; 129 | 130 | // account for the time taken in the preceeding commands. 131 | us -= 2; 132 | #else 133 | // for the 8 MHz internal clock on the ATmega168 134 | 135 | // for a one- or two-microsecond delay, simply return. the overhead of 136 | // the function calls takes more than two microseconds. can't just 137 | // subtract two, since us is unsigned; we'd overflow. 138 | if (--us == 0) 139 | return; 140 | if (--us == 0) 141 | return; 142 | 143 | // the following loop takes half of a microsecond (4 cycles) 144 | // per iteration, so execute it twice for each microsecond of 145 | // delay requested. 146 | us <<= 1; 147 | 148 | // partially compensate for the time taken by the preceeding commands. 149 | // we can't subtract any more than this or we'd overflow w/ small delays. 150 | us--; 151 | #endif 152 | 153 | // disable interrupts, otherwise the timer 0 overflow interrupt that 154 | // tracks milliseconds will make us delay longer than we want. 155 | oldSREG = SREG; 156 | cli(); 157 | 158 | // busy wait 159 | __asm__ __volatile__ ( 160 | "1: sbiw %0,1" "\n\t" // 2 cycles 161 | "brne 1b" : "=w" (us) : "0" (us) // 2 cycles 162 | ); 163 | 164 | // reenable interrupts. 165 | SREG = oldSREG; 166 | } 167 | 168 | void init() 169 | { 170 | // this needs to be called before setup() or some functions won't 171 | // work there 172 | sei(); 173 | 174 | // on the ATmega168, timer 0 is also used for fast hardware pwm 175 | // (using phase-correct PWM would mean that timer 0 overflowed half as often 176 | // resulting in different millis() behavior on the ATmega8 and ATmega168) 177 | //8 bit timer 178 | sbi(TCCR0A, WGM01); 179 | sbi(TCCR0A, WGM00); 180 | 181 | // set timer 0 prescale factor to 64 182 | sbi(TCCR0A, CS01); 183 | sbi(TCCR0A, CS00); 184 | 185 | // enable timer 0 overflow interrupt 186 | sbi(TIMSK0, TOIE0); 187 | 188 | // timers 1, 2 and 3 are used for phase-correct hardware pwm 189 | // this is better for motors as it ensures an even waveform 190 | // note, however, that fast pwm mode can achieve a frequency of up 191 | // 8 MHz (with a 16 MHz clock) at 50% duty cycle 192 | 193 | // set timer 1 prescale factor to 64 194 | sbi(TCCR1B, CS11); 195 | sbi(TCCR1B, CS10); 196 | // put timer 1 in 8-bit phase correct pwm mode 197 | sbi(TCCR1A, WGM10); 198 | 199 | // set timer 1 prescale factor to 64 200 | sbi(TCCR3B, CS31); 201 | sbi(TCCR3B, CS30); 202 | // put timer 1 in 8-bit phase correct pwm mode 203 | sbi(TCCR3A, WGM30); 204 | 205 | // set timer 2 prescale factor to 64 206 | sbi(TCCR2A, CS22); 207 | // configure timer 2 for phase correct pwm (8-bit) 208 | sbi(TCCR2A, WGM20); 209 | 210 | 211 | // set a2d prescale factor to 128 212 | // 16 MHz / 128 = 125 KHz, inside the desired 50-200 KHz range. 213 | // XXX: this will not work properly for other clock speeds, and 214 | // this code should use F_CPU to determine the prescale factor. 215 | sbi(ADCSRA, ADPS2); 216 | sbi(ADCSRA, ADPS1); 217 | sbi(ADCSRA, ADPS0); 218 | 219 | // enable a2d conversions 220 | sbi(ADCSRA, ADEN); 221 | 222 | // the bootloader connects pins 0 and 1 to the USART; disconnect them 223 | // here so they can be used as normal digital i/o; they will be 224 | // reconnected in Serial.begin() 225 | UCSR0B = 0; 226 | } -------------------------------------------------------------------------------- /0023/at90can/cores/at90can/wiring.h: -------------------------------------------------------------------------------- 1 | /* 2 | wiring.h - Partial implementation of the Wiring API for the ATmega8. 3 | Part of Arduino - http://www.arduino.cc/ 4 | 5 | Copyright (c) 2005-2006 David A. Mellis 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | 22 | $Id: wiring.h 602 2009-06-01 08:32:11Z dmellis $ 23 | */ 24 | 25 | #ifndef Wiring_h 26 | #define Wiring_h 27 | 28 | #include 29 | #include "binary.h" 30 | 31 | #ifdef __cplusplus 32 | extern "C"{ 33 | #endif 34 | 35 | #ifndef ARDUINO 36 | #define ARDUINO 16 37 | #endif 38 | 39 | #define HIGH 0x1 40 | #define LOW 0x0 41 | 42 | #define INPUT 0x0 43 | #define OUTPUT 0x1 44 | 45 | #define true 0x1 46 | #define false 0x0 47 | 48 | #define PI 3.1415926535897932384626433832795 49 | #define HALF_PI 1.5707963267948966192313216916398 50 | #define TWO_PI 6.283185307179586476925286766559 51 | #define DEG_TO_RAD 0.017453292519943295769236907684886 52 | #define RAD_TO_DEG 57.295779513082320876798154814105 53 | 54 | #define SERIAL 0x0 55 | #define DISPLAY 0x1 56 | 57 | #define LSBFIRST 0 58 | #define MSBFIRST 1 59 | 60 | #define CHANGE 1 61 | #define FALLING 2 62 | #define RISING 3 63 | 64 | #define INTERNAL 3 65 | #define DEFAULT 1 66 | #define EXTERNAL 0 67 | 68 | // undefine stdlib's abs if encountered 69 | #ifdef abs 70 | #undef abs 71 | #endif 72 | 73 | #define min(a,b) ((a)<(b)?(a):(b)) 74 | #define max(a,b) ((a)>(b)?(a):(b)) 75 | #define abs(x) ((x)>0?(x):-(x)) 76 | #define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt))) 77 | #define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5)) 78 | #define radians(deg) ((deg)*DEG_TO_RAD) 79 | #define degrees(rad) ((rad)*RAD_TO_DEG) 80 | #define sq(x) ((x)*(x)) 81 | 82 | #define interrupts() sei() 83 | #define noInterrupts() cli() 84 | 85 | #define clockCyclesPerMicrosecond() ( F_CPU / 1000000L ) 86 | #define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() ) 87 | #define microsecondsToClockCycles(a) ( (a) * clockCyclesPerMicrosecond() ) 88 | 89 | #define lowByte(w) ((uint8_t) ((w) & 0xff)) 90 | #define highByte(w) ((uint8_t) ((w) >> 8)) 91 | 92 | #define bitRead(value, bit) (((value) >> (bit)) & 0x01) 93 | #define bitSet(value, bit) ((value) |= (1UL << (bit))) 94 | #define bitClear(value, bit) ((value) &= ~(1UL << (bit))) 95 | #define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit)) 96 | 97 | typedef unsigned int word; 98 | 99 | #define bit(b) (1UL << (b)) 100 | 101 | typedef uint8_t boolean; 102 | typedef uint8_t byte; 103 | 104 | void init(void); 105 | 106 | void pinMode(uint8_t, uint8_t); 107 | void digitalWrite(uint8_t, uint8_t); 108 | int digitalRead(uint8_t); 109 | int analogRead(uint8_t); 110 | void analogReference(uint8_t mode); 111 | void analogWrite(uint8_t, int); 112 | 113 | void beginSerial(long); 114 | void serialWrite(unsigned char); 115 | int serialAvailable(void); 116 | int serialRead(void); 117 | void serialFlush(void); 118 | 119 | unsigned long millis(void); 120 | unsigned long micros(void); 121 | void delay(unsigned long); 122 | void delayMicroseconds(unsigned int us); 123 | unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout); 124 | 125 | void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, byte val); 126 | 127 | void attachInterrupt(uint8_t, void (*)(void), int mode); 128 | void detachInterrupt(uint8_t); 129 | 130 | void setup(void); 131 | void loop(void); 132 | 133 | #ifdef __cplusplus 134 | } // extern "C" 135 | #endif 136 | 137 | #endif 138 | -------------------------------------------------------------------------------- /0023/at90can/cores/at90can/wiring_analog.c: -------------------------------------------------------------------------------- 1 | /* 2 | wiring_analog.c - analog input and output 3 | Part of Arduino - http://www.arduino.cc/ 4 | 5 | Copyright (c) 2005-2006 David A. Mellis 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | 22 | $Id: wiring.c 248 2007-02-03 15:36:30Z mellis $ 23 | */ 24 | 25 | #include "wiring_private.h" 26 | #include "pins_arduino.h" 27 | 28 | uint8_t analog_reference = DEFAULT; 29 | 30 | /*#define ABIT11 4 31 | #define ABIT12 16 32 | #define ABIT13 64 33 | #define ABIT14 256 34 | #define ABIT15 1024 35 | #define ABIT16 4096 36 | 37 | int analogRead(uint8_t pin, uint8_t sampleRate) 38 | { 39 | uint32_t samples = 0; 40 | uint8_t right_shift; 41 | for (uint8_t sample = 0; sample < sampleRate; sample++) 42 | { 43 | samples += analogRead(pin); 44 | } 45 | switch (sampleRate) 46 | { 47 | case ABIT11: right_shift = 1; break; 48 | case ABIT12: right_shift = 2; break; 49 | case ABIT13: right_shift = 3; break; 50 | case ABIT14: right_shift = 4; break; 51 | case ABIT15: right_shift = 5; break; 52 | case ABIT16: right_shift = 6; break; 53 | } 54 | return (samples >> right_shift) 55 | }*/ 56 | 57 | void analogReference(uint8_t mode) 58 | { 59 | // can't actually set the register here because the default setting 60 | // will connect AVCC and the AREF pin, which would cause a short if 61 | // there's something connected to AREF. 62 | analog_reference = mode; 63 | } 64 | 65 | int analogRead(uint8_t pin) 66 | { 67 | uint8_t low, high; 68 | 69 | if (pin > 3) 70 | return 0; 71 | 72 | // set the analog reference (high two bits of ADMUX) and select the 73 | // channel (low 4 bits). this also sets ADLAR (left-adjust result) 74 | // to 0 (the default). 75 | ADMUX = (analog_reference << 6) | (pin & 0xf); 76 | 77 | // without a delay, we seem to read from the wrong channel 78 | //delay(1); 79 | 80 | // start the conversion 81 | sbi(ADCSRA, ADSC); 82 | 83 | // ADSC is cleared when the conversion finishes 84 | while (bit_is_set(ADCSRA, ADSC)); 85 | 86 | // we have to read ADCL first; doing so locks both ADCL 87 | // and ADCH until ADCH is read. reading ADCL second would 88 | // cause the results of each conversion to be discarded, 89 | // as ADCL and ADCH would be locked when it completed. 90 | low = ADCL; 91 | high = ADCH; 92 | 93 | // combine the two bytes 94 | return (high << 8) | low; 95 | } 96 | 97 | // Right now, PWM output only works on the pins with 98 | // hardware support. These are defined in the appropriate 99 | // pins_*.c file. For the rest of the pins, we default 100 | // to digital output. 101 | void analogWrite(uint8_t pin, int val) 102 | { 103 | // We need to make sure the PWM output is enabled for those pins 104 | // that support it, as we turn it off when digitally reading or 105 | // writing with them. Also, make sure the pin is in output mode 106 | // for consistenty with Wiring, which doesn't require a pinMode 107 | // call for the analog output pins. 108 | pinMode(pin, OUTPUT); 109 | 110 | if (digitalPinToTimer(pin) == TIMER1A) { 111 | // connect pwm to pin on timer 1, channel A 112 | sbi(TCCR1A, COM1A1); 113 | // set pwm duty 114 | OCR1A = val; 115 | } else if (digitalPinToTimer(pin) == TIMER1B) { 116 | // connect pwm to pin on timer 1, channel B 117 | sbi(TCCR1A, COM1B1); 118 | // set pwm duty 119 | OCR1B = val; 120 | } else if (digitalPinToTimer(pin) == TIMER1C) { 121 | // connect pwm to pin on timer 1, channel B 122 | sbi(TCCR1A, COM1C1); 123 | // set pwm duty 124 | OCR1C = val; 125 | } else if (digitalPinToTimer(pin) == TIMER2A) { 126 | // connect pwm to pin on timer 2, channel A 127 | sbi(TCCR2A, COM2A1); 128 | // set pwm duty 129 | OCR2A = val; 130 | } else if (digitalPinToTimer(pin) == TIMER3A) { 131 | // connect pwm to pin on timer 3, channel A 132 | sbi(TCCR3A, COM3A1); 133 | // set pwm duty 134 | OCR3A = val; 135 | } else if (digitalPinToTimer(pin) == TIMER3B) { 136 | // connect pwm to pin on timer 3, channel B 137 | sbi(TCCR3A, COM3B1); 138 | // set pwm duty 139 | OCR3B = val; 140 | } else if (digitalPinToTimer(pin) == TIMER3C) { 141 | // connect pwm to pin on timer 3, channel C 142 | sbi(TCCR3A, COM3C1); 143 | // set pwm duty 144 | OCR3C = val; 145 | } else if (val < 128) 146 | digitalWrite(pin, LOW); 147 | else 148 | digitalWrite(pin, HIGH); 149 | } 150 | -------------------------------------------------------------------------------- /0023/at90can/cores/at90can/wiring_digital.c: -------------------------------------------------------------------------------- 1 | /* 2 | wiring_digital.c - digital input and output functions 3 | Part of Arduino - http://www.arduino.cc/ 4 | 5 | Copyright (c) 2005-2006 David A. Mellis 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | 22 | $Id: wiring.c 248 2007-02-03 15:36:30Z mellis $ 23 | */ 24 | 25 | #include "wiring_private.h" 26 | #include "pins_arduino.h" 27 | 28 | void pinMode(uint8_t pin, uint8_t mode) 29 | { 30 | uint8_t bit = digitalPinToBitMask(pin); 31 | uint8_t port = digitalPinToPort(pin); 32 | volatile uint8_t *reg; 33 | 34 | if (port == NOT_A_PIN) return; 35 | 36 | // JWS: can I let the optimizer do this? 37 | reg = portModeRegister(port); 38 | 39 | if (mode == INPUT) *reg &= ~bit; 40 | else *reg |= bit; 41 | } 42 | 43 | // Forcing this inline keeps the callers from having to push their own stuff 44 | // on the stack. It is a good performance win and only takes 1 more byte per 45 | // user than calling. (It will take more bytes on the 168.) 46 | // 47 | // But shouldn't this be moved into pinMode? Seems silly to check and do on 48 | // each digitalread or write. 49 | // 50 | static inline void turnOffPWM(uint8_t timer) __attribute__ ((always_inline)); 51 | static inline void turnOffPWM(uint8_t timer) 52 | { 53 | if (timer == TIMER1A) cbi(TCCR1A, COM1A1); 54 | if (timer == TIMER1B) cbi(TCCR1A, COM1B1); 55 | if (timer == TIMER1C) cbi(TCCR1A, COM1C1); 56 | //if (timer == TIMER0A) cbi(TCCR0A, COM0A1); 57 | //if (timer == TIMER0B) cbi(TCCR0A, COM0B1); 58 | if (timer == TIMER2A) cbi(TCCR2A, COM2A1); 59 | if (timer == TIMER3A) cbi(TCCR3A, COM3A1); 60 | if (timer == TIMER3B) cbi(TCCR3A, COM3B1); 61 | if (timer == TIMER3C) cbi(TCCR3A, COM3C1); 62 | } 63 | 64 | void digitalWrite(uint8_t pin, uint8_t val) 65 | { 66 | uint8_t timer = digitalPinToTimer(pin); 67 | uint8_t bit = digitalPinToBitMask(pin); 68 | uint8_t port = digitalPinToPort(pin); 69 | volatile uint8_t *out; 70 | 71 | if (port == NOT_A_PIN) return; 72 | 73 | // If the pin that support PWM output, we need to turn it off 74 | // before doing a digital write. 75 | if (timer != NOT_ON_TIMER) turnOffPWM(timer); 76 | 77 | out = portOutputRegister(port); 78 | 79 | if (val == LOW) *out &= ~bit; 80 | else *out |= bit; 81 | } 82 | 83 | int digitalRead(uint8_t pin) 84 | { 85 | uint8_t timer = digitalPinToTimer(pin); 86 | uint8_t bit = digitalPinToBitMask(pin); 87 | uint8_t port = digitalPinToPort(pin); 88 | 89 | if (port == NOT_A_PIN) return LOW; 90 | 91 | // If the pin that support PWM output, we need to turn it off 92 | // before getting a digital reading. 93 | if (timer != NOT_ON_TIMER) turnOffPWM(timer); 94 | 95 | if (*portInputRegister(port) & bit) return HIGH; 96 | return LOW; 97 | } 98 | -------------------------------------------------------------------------------- /0023/at90can/cores/at90can/wiring_private.h: -------------------------------------------------------------------------------- 1 | /* 2 | wiring_private.h - Internal header file. 3 | Part of Arduino - http://www.arduino.cc/ 4 | 5 | Copyright (c) 2005-2006 David A. Mellis 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | 22 | $Id: wiring.h 239 2007-01-12 17:58:39Z mellis $ 23 | */ 24 | 25 | #ifndef WiringPrivate_h 26 | #define WiringPrivate_h 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | #include "wiring.h" 35 | 36 | #ifdef __cplusplus 37 | extern "C"{ 38 | #endif 39 | 40 | #ifndef cbi 41 | #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit)) 42 | #endif 43 | #ifndef sbi 44 | #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit)) 45 | #endif 46 | 47 | #define EXTERNAL_INT_0 0 48 | #define EXTERNAL_INT_1 1 49 | #define EXTERNAL_INT_2 2 50 | #define EXTERNAL_INT_3 3 51 | #define EXTERNAL_INT_4 4 52 | #define EXTERNAL_INT_5 5 53 | #define EXTERNAL_INT_6 6 54 | #define EXTERNAL_INT_7 7 55 | 56 | 57 | #define EXTERNAL_NUM_INTERRUPTS 8 58 | 59 | 60 | typedef void (*voidFuncPtr)(void); 61 | 62 | #ifdef __cplusplus 63 | } // extern "C" 64 | #endif 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /0023/at90can/cores/at90can/wiring_pulse.c: -------------------------------------------------------------------------------- 1 | /* 2 | wiring_pulse.c - pulseIn() function 3 | Part of Arduino - http://www.arduino.cc/ 4 | 5 | Copyright (c) 2005-2006 David A. Mellis 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | 22 | $Id: wiring.c 248 2007-02-03 15:36:30Z mellis $ 23 | */ 24 | 25 | #include "wiring_private.h" 26 | #include "pins_arduino.h" 27 | 28 | /* Measures the length (in microseconds) of a pulse on the pin; state is HIGH 29 | * or LOW, the type of pulse to measure. Works on pulses from 2-3 microseconds 30 | * to 3 minutes in length, but must be called at least a few dozen microseconds 31 | * before the start of the pulse. */ 32 | unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout) 33 | { 34 | // cache the port and bit of the pin in order to speed up the 35 | // pulse width measuring loop and achieve finer resolution. calling 36 | // digitalRead() instead yields much coarser resolution. 37 | uint8_t bit = digitalPinToBitMask(pin); 38 | uint8_t port = digitalPinToPort(pin); 39 | uint8_t stateMask = (state ? bit : 0); 40 | unsigned long width = 0; // keep initialization out of time critical area 41 | 42 | // convert the timeout from microseconds to a number of times through 43 | // the initial loop; it takes 16 clock cycles per iteration. 44 | unsigned long numloops = 0; 45 | unsigned long maxloops = microsecondsToClockCycles(timeout) / 16; 46 | 47 | // wait for any previous pulse to end 48 | while ((*portInputRegister(port) & bit) == stateMask) 49 | if (numloops++ == maxloops) 50 | return 0; 51 | 52 | // wait for the pulse to start 53 | while ((*portInputRegister(port) & bit) != stateMask) 54 | if (numloops++ == maxloops) 55 | return 0; 56 | 57 | // wait for the pulse to stop 58 | while ((*portInputRegister(port) & bit) == stateMask) 59 | width++; 60 | 61 | // convert the reading to microseconds. The loop has been determined 62 | // to be 10 clock cycles long and have about 16 clocks between the edge 63 | // and the start of the loop. There will be some error introduced by 64 | // the interrupt handlers. 65 | return clockCyclesToMicroseconds(width * 10 + 16); 66 | } 67 | -------------------------------------------------------------------------------- /0023/at90can/cores/at90can/wiring_shift.c: -------------------------------------------------------------------------------- 1 | /* 2 | wiring_shift.c - shiftOut() function 3 | Part of Arduino - http://www.arduino.cc/ 4 | 5 | Copyright (c) 2005-2006 David A. Mellis 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | 22 | $Id: wiring.c 248 2007-02-03 15:36:30Z mellis $ 23 | */ 24 | 25 | #include "wiring_private.h" 26 | 27 | void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, byte val) 28 | { 29 | int i; 30 | 31 | for (i = 0; i < 8; i++) { 32 | if (bitOrder == LSBFIRST) 33 | digitalWrite(dataPin, !!(val & (1 << i))); 34 | else 35 | digitalWrite(dataPin, !!(val & (1 << (7 - i)))); 36 | 37 | digitalWrite(clockPin, HIGH); 38 | digitalWrite(clockPin, LOW); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /0023/at90can/programmers.txt: -------------------------------------------------------------------------------- 1 | jtagicemki.name=JTAG ICE mkI 2 | jtagicemki.communication=serial 3 | jtagicemki.protocol=jtag1 4 | 5 | usbtinyisp.name=USBtinyISP 6 | usbtinyisp.protocol=usbtiny 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /1.0/at90can/boards.txt: -------------------------------------------------------------------------------- 1 | at90can128.name=[bootloader]AT90CAN128 2 | at90can128.upload.protocol=arduino 3 | at90can128.upload.maximum_size=129024 4 | at90can128.upload.speed=57600 5 | 6 | at90can128.bootloader.low_fuses=0xFF 7 | at90can128.bootloader.high_fuses=0x1C 8 | at90can128.bootloader.extended_fuses=0xFF 9 | at90can128.bootloader.path=at90can 10 | at90can128.bootloader.file=ATmegaBOOT_168_at90can.hex 11 | at90can128.bootloader.unlock_bits=0x3F 12 | at90can128.bootloader.lock_bits=0x0F 13 | 14 | at90can128.build.mcu=at90can128 15 | at90can128.build.f_cpu=16000000L 16 | at90can128.build.core=at90can 17 | 18 | ############################################################## 19 | 20 | uat90can128.name=[usbtinyisp]AT90CAN128 21 | uat90can128.upload.using=usbtinyisp 22 | uat90can128.upload.maximum_size=131072 23 | 24 | uat90can128.bootloader.low_fuses=0xFF 25 | uat90can128.bootloader.high_fuses=0x19 26 | uat90can128.bootloader.extended_fuses=0xFF 27 | uat90can128.bootloader.path=at90can 28 | uat90can128.bootloader.file=ATmegaBOOT_168_at90can.hex 29 | uat90can128.bootloader.unlock_bits=0x3F 30 | uat90can128.bootloader.lock_bits=0xCF 31 | 32 | uat90can128.build.mcu=at90can128 33 | uat90can128.build.f_cpu=16000000L 34 | uat90can128.build.core=at90can 35 | 36 | ############################################################## 37 | 38 | jat90can128.name=[JTAG ICE mkI]AT90CAN128 39 | jat90can128.upload.using=jtagicemki 40 | jat90can128.upload.maximum_size=131072 41 | 42 | jat90can128.bootloader.low_fuses=0xFF 43 | jat90can128.bootloader.high_fuses=0x18 44 | jat90can128.bootloader.extended_fuses=0xFF 45 | jat90can128.bootloader.path=at90can 46 | jat90can128.bootloader.file=ATmegaBOOT_168_at90can.hex 47 | jat90can128.bootloader.unlock_bits=0x3F 48 | jat90can128.bootloader.lock_bits=0xCF 49 | 50 | jat90can128.build.mcu=at90can128 51 | jat90can128.build.f_cpu=16000000L 52 | jat90can128.build.core=at90can 53 | 54 | -------------------------------------------------------------------------------- /1.0/at90can/bootloaders/at90can/ATmegaBOOT_168_at90can.hex: -------------------------------------------------------------------------------- 1 | :020000021000EC 2 | :10F800000C944AFC0C9469FC0C9469FC0C9469FC03 3 | :10F810000C9469FC0C9469FC0C9469FC0C9469FCD4 4 | :10F820000C9469FC0C9469FC0C9469FC0C9469FCC4 5 | :10F830000C9469FC0C9469FC0C9469FC0C9469FCB4 6 | :10F840000C9469FC0C9469FC0C9469FC0C9469FCA4 7 | :10F850000C9469FC0C9469FC0C9469FC0C9469FC94 8 | :10F860000C9469FC0C9469FC0C9469FC0C9469FC84 9 | :10F870000C9469FC0C9469FC0C9469FC0C9469FC74 10 | :10F880000C9469FC0C9469FC0C9469FC0C9469FC64 11 | :10F890000C9469FC11241FBECFEFD0E1DEBFCDBFB9 12 | :10F8A00011E0A0E0B1E0EAEEFFEF01E00BBF02C023 13 | :10F8B00007900D92A230B107D9F712E0A2E0B1E0B3 14 | :10F8C00001C01D92AD30B107E1F70E9486FD0C9496 15 | :10F8D000F3FF0C9400FC982F80910201813019F005 16 | :10F8E000823041F008958091C00085FFFCCF909355 17 | :10F8F000C60008958091C80085FFFCCF9093CE008C 18 | :10F9000008951F93982F9595959595959595905D4C 19 | :10F910008F708A3054F4182F105D892F0E946BFC71 20 | :10F92000812F0E946BFC1F910895182F195A892F5F 21 | :10F930000E946BFC812F0E946BFC1F910895EF9237 22 | :10F94000FF920F931F9380910201813069F1823001 23 | :10F9500031F080E01F910F91FF90EF900895EE2419 24 | :10F96000FF2487018091C80087FD17C00894E11C1F 25 | :10F97000F11C011D111D81E4E81682E4F8068FE0F8 26 | :10F98000080780E0180770F3E0910401F091050189 27 | :10F9900009958091C80087FFE9CF8091CE001F9123 28 | :10F9A0000F91FF90EF900895EE24FF24870180913E 29 | :10F9B000C00087FD17C00894E11CF11C011D111D3A 30 | :10F9C00081E4E81682E4F8068FE0080780E0180773 31 | :10F9D00070F3E0910401F091050109958091C00058 32 | :10F9E00087FFE9CF8091C6001F910F91FF90EF90A4 33 | :10F9F00008951F930E949FFC182F0E946BFC1136E4 34 | :10FA000034F410330CF01053812F1F9108951755C3 35 | :10FA1000812F1F9108951F930E94F9FC182F0E94B7 36 | :10FA2000F9FC1295107F810F1F910895982F209156 37 | :10FA30000201992339F0213031F0223061F09150E8 38 | :10FA40009923C9F708958091C00087FFFCCF80916A 39 | :10FA5000C6009150F5CF8091C80087FFFCCF809100 40 | :10FA6000CE009150EDCF1F93182F0E949FFC803243 41 | :10FA700081F0809103018F5F80930301853011F045 42 | :10FA80001F910895E0910401F091050109951F91DE 43 | :10FA9000089584E10E946BFC812F0E946BFC80E141 44 | :10FAA0000E946BFC1F9108950E949FFC803271F0B0 45 | :10FAB000809103018F5F80930301853009F00895E1 46 | :10FAC000E0910401F09105010995089584E10E94F7 47 | :10FAD0006BFC80E10E946BFC089540E951E08823B3 48 | :10FAE000A1F0179A28EE33E0FA013197F1F721508F 49 | :10FAF0003040D1F7179828EE33E0FA013197F1F74B 50 | :10FB000021503040D1F7815061F70895FF920F9353 51 | :10FB10001F93CF93DF930000879886988F9A8E9AD1 52 | :10FB200081E08093020180E18093C4001092C500BF 53 | :10FB30001092C00086E08093C20088E18093C100EB 54 | :10FB40006898709A0F9A82E00E946DFDFF24F394EA 55 | :10FB50000E949FFC8033B1F18133B9F1803409F404 56 | :10FB600054C0813409F45AC0823409F469C0853420 57 | :10FB700009F46CC0803531F1823521F1813511F104 58 | :10FB8000853509F469C0863509F471C0843609F4F5 59 | :10FB90007AC0843709F4E4C0853709F448C1863750 60 | :10FBA00009F44AC0809103018F5F8093030185307F 61 | :10FBB00079F6E0910401F091050109950E949FFCFE 62 | :10FBC000803351F60E9454FDC3CF0E949FFC8032C7 63 | :10FBD00049F784E10E946BFC81E40E946BFC86E59E 64 | :10FBE0000E946BFC82E50E946BFC80E20E946BFC31 65 | :10FBF00089E40E946BFC83E50E946BFC80E50E9417 66 | :10FC00006BFC80E10E946BFCA3CF0E949FFC8638B6 67 | :10FC1000C8F20E949FFC0E9454FD9ACF0E949FFC54 68 | :10FC2000803809F499C0813809F4FDC0823809F49C 69 | :10FC300013C1883909F48CC080E00E9433FD88CF5D 70 | :10FC400084E10E9416FD0E9454FD82CF85E00E944F 71 | :10FC500016FD0E9454FD7CCF0E949FFC80930601FC 72 | :10FC60000E949FFC809307010E9454FD71CF0E9467 73 | :10FC70009FFC803309F404C183E00E9416FD80E0FC 74 | :10FC80000E9433FD65CF0E949FFC809309020E9471 75 | :10FC90009FFC8093080280910C028E7F80930C025F 76 | :10FCA0000E949FFC853409F4FCC080910802909169 77 | :10FCB0000902892B89F000E010E00E949FFCF80106 78 | :10FCC000E85FFE4F80830F5F1F4F80910802909185 79 | :10FCD00009020817190788F30E949FFC803209F077 80 | :10FCE00061CF80910C0280FFEEC02091060130911F 81 | :10FCF0000701220F331F30930701209306018091E3 82 | :10FD0000080290910902892BE1F000E010E0F8016F 83 | :10FD1000E85FFE4FC90160810E94E6FF2091060165 84 | :10FD2000309107012F5F3F4F309307012093060169 85 | :10FD30000F5F1F4F80910802909109020817190761 86 | :10FD400030F384E10E946BFC80E10E946BFC00CFE9 87 | :10FD500083E00E9433FDFCCE82E00E9433FDF8CEAA 88 | :10FD60000E949FFC809309020E949FFC80930802DE 89 | :10FD7000209106013091070137FD9FC080910C0250 90 | :10FD80008D7F80930C02220F331F30930701209345 91 | :10FD900006010E949FFC853409F489C080910C0201 92 | :10FDA0008E7F80930C020E949FFC803209F0D0CE9F 93 | :10FDB00084E10E946BFC8091080290910902892BDA 94 | :10FDC00009F446C000E010E02091060130910701DF 95 | :10FDD00017C0F90184910E946BFC209106013091BB 96 | :10FDE00007012F5F3F4F30930701209306010F5FFC 97 | :10FDF0001F4F80910802909109020817190740F5DA 98 | :10FE000080910C0280FD2CC081FFE3CFC901A0E0EE 99 | :10FE1000B0E080509040AF4FBF4FABBFFC01879127 100 | :10FE20000E946BFCDACF81E00E9433FD91CE0E94EC 101 | :10FE30009FFC803209F0B6CE84E10E946BFC8EE11B 102 | :10FE40000E946BFC87E90E946BFC81E80E946BFCBE 103 | :10FE500080E10E946BFC7CCE80E10E9433FD78CE75 104 | :10FE6000C9010E94DEFF0E946BFC209106013091C7 105 | :10FE700007012F5F3F4F3093070120930601B7CF53 106 | :10FE80000E949FFC0E949FFC182F0E949FFC112340 107 | :10FE900009F48CC0113009F48DC081E80E9433FD53 108 | :10FEA00057CE80910C02816080930C02FECE80912F 109 | :10FEB0000C02816080930C0276CF80910C028260EC 110 | :10FEC00080930C0260CF809107018823880F880BF4 111 | :10FED0008F2180930B028BBF8091060190910701C7 112 | :10FEE000880F991F90930701809306018091080263 113 | :10FEF00080FF09C0809108029091090201969093B9 114 | :10FF0000090280930802F894F999FECF1127E09135 115 | :10FF10000601F0910701C8E0D1E0809108029091BC 116 | :10FF20000902103091F40091570001700130D9F3AB 117 | :10FF300003E000935700E8950091570001700130ED 118 | :10FF4000D9F301E100935700E895099019900091C9 119 | :10FF5000570001700130D9F301E000935700E89594 120 | :10FF60001395103898F01127009157000170013057 121 | :10FF7000D9F305E000935700E89500915700017010 122 | :10FF80000130D9F301E100935700E89532960297CA 123 | :10FF900009F0C7CF103011F00296E5CF112484E1AB 124 | :10FFA0000E946BFC80E10E946BFCD2CD8EE10E942E 125 | :10FFB00033FDCECD87E90E9433FDCACDF999FECF3E 126 | :10FFC00092BD81BDF89A992780B50895262FF99999 127 | :10FFD000FECF92BD81BD20BD0FB6F894FA9AF99A72 128 | :0AFFE0000FBE01960895F894FFCFBC 129 | :02FFEA00800095 130 | :040000031000F800F1 131 | :00000001FF 132 | -------------------------------------------------------------------------------- /1.0/at90can/bootloaders/at90can/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for ATmegaBOOT 2 | # E.Lins, 18.7.2005 3 | # $Id$ 4 | # 5 | # Instructions 6 | # 7 | # To make bootloader .hex file: 8 | # make diecimila 9 | # make lilypad 10 | # make ng 11 | # etc... 12 | # 13 | # To burn bootloader .hex file: 14 | # make diecimila_isp 15 | # make lilypad_isp 16 | # make ng_isp 17 | # etc... 18 | 19 | # program name should not be changed... 20 | PROGRAM = ATmegaBOOT_168 21 | 22 | # enter the parameters for the avrdude isp tool 23 | ISPTOOL = stk500v2 24 | ISPPORT = usb 25 | ISPSPEED = -b 115200 26 | 27 | MCU_TARGET = AT90can128 28 | LDSECTION = --section-start=.text=0x3800 29 | 30 | # the efuse should really be 0xf8; since, however, only the lower 31 | # three bits of that byte are used on the atmega168, avrdude gets 32 | # confused if you specify 1's for the higher bits, see: 33 | # http://tinker.it/now/2007/02/24/the-tale-of-avrdude-atmega168-and-extended-bits-fuses/ 34 | # 35 | # similarly, the lock bits should be 0xff instead of 0x3f (to 36 | # unlock the bootloader section) and 0xcf instead of 0x0f (to 37 | # lock it), but since the high two bits of the lock byte are 38 | # unused, avrdude would get confused. 39 | 40 | ISPFUSES = avrdude -c $(ISPTOOL) -p $(MCU_TARGET) -P $(ISPPORT) $(ISPSPEED) \ 41 | -e -u -U lock:w:0x3f:m -U efuse:w:0x$(EFUSE):m -U hfuse:w:0x$(HFUSE):m -U lfuse:w:0x$(LFUSE):m 42 | ISPFLASH = avrdude -c $(ISPTOOL) -p $(MCU_TARGET) -P $(ISPPORT) $(ISPSPEED) \ 43 | -U flash:w:$(PROGRAM)_$(TARGET).hex -U lock:w:0x0f:m 44 | 45 | STK500 = "C:\Program Files\Atmel\AVR Tools\STK500\Stk500.exe" 46 | STK500-1 = $(STK500) -e -d$(MCU_TARGET) -pf -vf -if$(PROGRAM)_$(TARGET).hex \ 47 | -lFF -LFF -f$(HFUSE)$(LFUSE) -EF8 -ms -q -cUSB -I200kHz -s -wt 48 | STK500-2 = $(STK500) -d$(MCU_TARGET) -ms -q -lCF -LCF -cUSB -I200kHz -s -wt 49 | 50 | 51 | OBJ = $(PROGRAM).o 52 | OPTIMIZE = -O2 53 | 54 | DEFS = 55 | LIBS = 56 | 57 | CC = avr-gcc 58 | 59 | # Override is only needed by avr-lib build system. 60 | 61 | override CFLAGS = -g -Wall $(OPTIMIZE) -mmcu=$(MCU_TARGET) -DF_CPU=$(AVR_FREQ) $(DEFS) 62 | override LDFLAGS = -Wl,$(LDSECTION) 63 | #override LDFLAGS = -Wl,-Map,$(PROGRAM).map,$(LDSECTION) 64 | 65 | OBJCOPY = avr-objcopy 66 | OBJDUMP = avr-objdump 67 | 68 | all: 69 | 70 | lilypad: TARGET = lilypad 71 | lilypad: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>1' '-DNUM_LED_FLASHES=3' 72 | lilypad: AVR_FREQ = 8000000L 73 | lilypad: $(PROGRAM)_lilypad.hex 74 | 75 | lilypad_isp: lilypad 76 | lilypad_isp: TARGET = lilypad 77 | lilypad_isp: HFUSE = DD 78 | lilypad_isp: LFUSE = E2 79 | lilypad_isp: EFUSE = 00 80 | lilypad_isp: isp 81 | 82 | lilypad_resonator: TARGET = lilypad_resonator 83 | lilypad_resonator: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>4' '-DNUM_LED_FLASHES=3' 84 | lilypad_resonator: AVR_FREQ = 8000000L 85 | lilypad_resonator: $(PROGRAM)_lilypad_resonator.hex 86 | 87 | lilypad_resonator_isp: lilypad_resonator 88 | lilypad_resonator_isp: TARGET = lilypad_resonator 89 | lilypad_resonator_isp: HFUSE = DD 90 | lilypad_resonator_isp: LFUSE = C6 91 | lilypad_resonator_isp: EFUSE = 00 92 | lilypad_resonator_isp: isp 93 | 94 | pro8: TARGET = pro_8MHz 95 | pro8: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>4' '-DNUM_LED_FLASHES=1' '-DWATCHDOG_MODS' 96 | pro8: AVR_FREQ = 8000000L 97 | pro8: $(PROGRAM)_pro_8MHz.hex 98 | 99 | pro8_isp: pro8 100 | pro8_isp: TARGET = pro_8MHz 101 | pro8_isp: HFUSE = DD 102 | pro8_isp: LFUSE = C6 103 | pro8_isp: EFUSE = 00 104 | pro8_isp: isp 105 | 106 | pro16: TARGET = pro_16MHz 107 | pro16: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>4' '-DNUM_LED_FLASHES=1' '-DWATCHDOG_MODS' 108 | pro16: AVR_FREQ = 16000000L 109 | pro16: $(PROGRAM)_pro_16MHz.hex 110 | 111 | pro16_isp: pro16 112 | pro16_isp: TARGET = pro_16MHz 113 | pro16_isp: HFUSE = DD 114 | pro16_isp: LFUSE = C6 115 | pro16_isp: EFUSE = 00 116 | pro16_isp: isp 117 | 118 | pro20: TARGET = pro_20mhz 119 | pro20: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>4' '-DNUM_LED_FLASHES=1' '-DWATCHDOG_MODS' 120 | pro20: AVR_FREQ = 20000000L 121 | pro20: $(PROGRAM)_pro_20mhz.hex 122 | 123 | pro20_isp: pro20 124 | pro20_isp: TARGET = pro_20mhz 125 | pro20_isp: HFUSE = DD 126 | pro20_isp: LFUSE = C6 127 | pro20_isp: EFUSE = 00 128 | pro20_isp: isp 129 | 130 | diecimila: TARGET = diecimila 131 | diecimila: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>4' '-DNUM_LED_FLASHES=1' 132 | diecimila: AVR_FREQ = 16000000L 133 | diecimila: $(PROGRAM)_diecimila.hex 134 | 135 | diecimila_isp: diecimila 136 | diecimila_isp: TARGET = diecimila 137 | diecimila_isp: HFUSE = DD 138 | diecimila_isp: LFUSE = FF 139 | diecimila_isp: EFUSE = 00 140 | diecimila_isp: isp 141 | 142 | ng: TARGET = ng 143 | ng: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>1' '-DNUM_LED_FLASHES=3' 144 | ng: AVR_FREQ = 16000000L 145 | ng: $(PROGRAM)_ng.hex 146 | 147 | ng_isp: ng 148 | ng_isp: TARGET = ng 149 | ng_isp: HFUSE = DD 150 | ng_isp: LFUSE = FF 151 | ng_isp: EFUSE = 00 152 | ng_isp: isp 153 | 154 | atmega328: TARGET = atmega328 155 | atmega328: MCU_TARGET = atmega328p 156 | atmega328: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>4' '-DNUM_LED_FLASHES=1' -DBAUD_RATE=57600 157 | atmega328: AVR_FREQ = 16000000L 158 | atmega328: LDSECTION = --section-start=.text=0x7800 159 | atmega328: $(PROGRAM)_atmega328.hex 160 | 161 | atmega328_isp: atmega328 162 | atmega328_isp: TARGET = atmega328 163 | atmega328_isp: MCU_TARGET = atmega328p 164 | atmega328_isp: HFUSE = DA 165 | atmega328_isp: LFUSE = FF 166 | atmega328_isp: EFUSE = 05 167 | atmega328_isp: isp 168 | 169 | atmega328_pro8: TARGET = atmega328_pro_8MHz 170 | atmega328_pro8: MCU_TARGET = atmega328p 171 | atmega328_pro8: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>4' '-DNUM_LED_FLASHES=1' -DBAUD_RATE=57600 -DDOUBLE_SPEED 172 | atmega328_pro8: AVR_FREQ = 8000000L 173 | atmega328_pro8: LDSECTION = --section-start=.text=0x7800 174 | atmega328_pro8: $(PROGRAM)_atmega328_pro_8MHz.hex 175 | 176 | atmega328_pro8_isp: atmega328_pro8 177 | atmega328_pro8_isp: TARGET = atmega328_pro_8MHz 178 | atmega328_pro8_isp: MCU_TARGET = atmega328p 179 | atmega328_pro8_isp: HFUSE = DA 180 | atmega328_pro8_isp: LFUSE = FF 181 | atmega328_pro8_isp: EFUSE = 05 182 | atmega328_pro8_isp: isp 183 | 184 | mega: TARGET = atmega1280 185 | mega: MCU_TARGET = atmega1280 186 | mega: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>4' '-DNUM_LED_FLASHES=0' -DBAUD_RATE=57600 187 | mega: AVR_FREQ = 16000000L 188 | mega: LDSECTION = --section-start=.text=0x1F000 189 | mega: $(PROGRAM)_atmega1280.hex 190 | 191 | mega_isp: mega 192 | mega_isp: TARGET = atmega1280 193 | mega_isp: MCU_TARGET = atmega1280 194 | mega_isp: HFUSE = DA 195 | mega_isp: LFUSE = FF 196 | mega_isp: EFUSE = F5 197 | mega_isp: isp 198 | 199 | at90can: TARGET = at90can128 200 | at90can: MCU_TARGET = at90can128 201 | at90can: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>4' '-DNUM_LED_FLASHES=1' -DBAUD_RATE=57600 202 | at90can: AVR_FREQ = 16000000L 203 | at90can: LDSECTION = --section-start=.text=0x1F800 204 | at90can: $(PROGRAM)_at90can.hex 205 | 206 | 207 | 208 | isp: $(TARGET) 209 | $(ISPFUSES) 210 | $(ISPFLASH) 211 | 212 | isp-stk500: $(PROGRAM)_$(TARGET).hex 213 | $(STK500-1) 214 | $(STK500-2) 215 | 216 | %.elf: $(OBJ) 217 | $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS) 218 | 219 | clean: 220 | rm -rf *.o *.elf *.lst *.map *.sym *.lss *.eep *.srec *.bin *.hex 221 | 222 | %.lst: %.elf 223 | $(OBJDUMP) -h -S $< > $@ 224 | 225 | %.hex: %.elf 226 | $(OBJCOPY) -j .text -j .data -O ihex $< $@ 227 | 228 | %.srec: %.elf 229 | $(OBJCOPY) -j .text -j .data -O srec $< $@ 230 | 231 | %.bin: %.elf 232 | $(OBJCOPY) -j .text -j .data -O binary $< $@ 233 | -------------------------------------------------------------------------------- /1.0/at90can/cores/at90can/Arduino.h: -------------------------------------------------------------------------------- 1 | #ifndef Arduino_h 2 | #define Arduino_h 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | #include "wiring.h" 11 | 12 | #ifdef __cplusplus 13 | #include "WCharacter.h" 14 | #include "WString.h" 15 | #include "HardwareSerial.h" 16 | #include "can_lib.h" 17 | 18 | uint16_t makeWord(uint16_t w); 19 | uint16_t makeWord(byte h, byte l); 20 | 21 | #define word(...) makeWord(__VA_ARGS__) 22 | 23 | unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L); 24 | 25 | // WMath prototypes 26 | long random(long); 27 | long random(long, long); 28 | void randomSeed(unsigned int); 29 | long map(long, long, long, long, long); 30 | #endif 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /1.0/at90can/cores/at90can/HardwareSerial.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | HardwareSerial.cpp - Hardware serial library for Wiring 3 | Copyright (c) 2006 Nicholas Zambetti. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | Modified 23 November 2006 by David A. Mellis 20 | */ 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include "wiring.h" 26 | #include "wiring_private.h" 27 | 28 | #include "HardwareSerial.h" 29 | 30 | // Define constants and variables for buffering incoming serial data. We're 31 | // using a ring buffer (I think), in which rx_buffer_head is the index of the 32 | // location to which to write the next incoming character and rx_buffer_tail 33 | // is the index of the location from which to read. 34 | #define RX_BUFFER_SIZE 128 35 | 36 | struct ring_buffer { 37 | unsigned char buffer[RX_BUFFER_SIZE]; 38 | int head; 39 | int tail; 40 | }; 41 | 42 | ring_buffer rx_buffer = { { 0 }, 0, 0 }; 43 | ring_buffer rx_buffer1 = { { 0 }, 0, 0 }; 44 | 45 | 46 | inline void store_char(unsigned char c, ring_buffer *rx_buffer) 47 | { 48 | int i = (rx_buffer->head + 1) % RX_BUFFER_SIZE; 49 | 50 | // if we should be storing the received character into the location 51 | // just before the tail (meaning that the head would advance to the 52 | // current location of the tail), we're about to overflow the buffer 53 | // and so we don't write the character or advance the head. 54 | if (i != rx_buffer->tail) { 55 | rx_buffer->buffer[rx_buffer->head] = c; 56 | rx_buffer->head = i; 57 | } 58 | } 59 | 60 | 61 | SIGNAL(SIG_USART0_RECV) 62 | { 63 | unsigned char c = UDR0; 64 | store_char(c, &rx_buffer); 65 | } 66 | 67 | SIGNAL(SIG_USART1_RECV) 68 | { 69 | unsigned char c = UDR1; 70 | store_char(c, &rx_buffer1); 71 | } 72 | 73 | // Constructors //////////////////////////////////////////////////////////////// 74 | 75 | HardwareSerial::HardwareSerial(ring_buffer *rx_buffer, 76 | volatile uint8_t *ubrrh, volatile uint8_t *ubrrl, 77 | volatile uint8_t *ucsra, volatile uint8_t *ucsrb, 78 | volatile uint8_t *udr, 79 | uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udre, uint8_t u2x) 80 | { 81 | _rx_buffer = rx_buffer; 82 | _ubrrh = ubrrh; 83 | _ubrrl = ubrrl; 84 | _ucsra = ucsra; 85 | _ucsrb = ucsrb; 86 | _udr = udr; 87 | _rxen = rxen; 88 | _txen = txen; 89 | _rxcie = rxcie; 90 | _udre = udre; 91 | _u2x = u2x; 92 | } 93 | 94 | // Public Methods ////////////////////////////////////////////////////////////// 95 | 96 | void HardwareSerial::begin(long baud) 97 | { 98 | uint16_t baud_setting; 99 | bool use_u2x; 100 | 101 | // U2X mode is needed for baud rates higher than (CPU Hz / 16) 102 | if (baud > F_CPU / 16) { 103 | use_u2x = true; 104 | } else { 105 | // figure out if U2X mode would allow for a better connection 106 | 107 | // calculate the percent difference between the baud-rate specified and 108 | // the real baud rate for both U2X and non-U2X mode (0-255 error percent) 109 | uint8_t nonu2x_baud_error = abs((int)(255-((F_CPU/(16*(((F_CPU/8/baud-1)/2)+1))*255)/baud))); 110 | uint8_t u2x_baud_error = abs((int)(255-((F_CPU/(8*(((F_CPU/4/baud-1)/2)+1))*255)/baud))); 111 | 112 | // prefer non-U2X mode because it handles clock skew better 113 | use_u2x = (nonu2x_baud_error > u2x_baud_error); 114 | } 115 | 116 | if (use_u2x) { 117 | *_ucsra = 1 << _u2x; 118 | baud_setting = (F_CPU / 4 / baud - 1) / 2; 119 | } else { 120 | *_ucsra = 0; 121 | baud_setting = (F_CPU / 8 / baud - 1) / 2; 122 | } 123 | 124 | // assign the baud_setting, a.k.a. ubbr (USART Baud Rate Register) 125 | *_ubrrh = baud_setting >> 8; 126 | *_ubrrl = baud_setting; 127 | 128 | sbi(*_ucsrb, _rxen); 129 | sbi(*_ucsrb, _txen); 130 | sbi(*_ucsrb, _rxcie); 131 | } 132 | 133 | int HardwareSerial::available(void) 134 | { 135 | return (int)(RX_BUFFER_SIZE + _rx_buffer->head - _rx_buffer->tail) % RX_BUFFER_SIZE; 136 | } 137 | 138 | int HardwareSerial::read(void) 139 | { 140 | // if the head isn't ahead of the tail, we don't have any characters 141 | if (_rx_buffer->head == _rx_buffer->tail) { 142 | return -1; 143 | } else { 144 | unsigned char c = _rx_buffer->buffer[_rx_buffer->tail]; 145 | _rx_buffer->tail = (_rx_buffer->tail + 1) % RX_BUFFER_SIZE; 146 | return c; 147 | } 148 | } 149 | 150 | void HardwareSerial::flush() 151 | { 152 | // don't reverse this or there may be problems if the RX interrupt 153 | // occurs after reading the value of rx_buffer_head but before writing 154 | // the value to rx_buffer_tail; the previous value of rx_buffer_head 155 | // may be written to rx_buffer_tail, making it appear as if the buffer 156 | // don't reverse this or there may be problems if the RX interrupt 157 | // occurs after reading the value of rx_buffer_head but before writing 158 | // the value to rx_buffer_tail; the previous value of rx_buffer_head 159 | // may be written to rx_buffer_tail, making it appear as if the buffer 160 | // were full, not empty. 161 | _rx_buffer->head = _rx_buffer->tail; 162 | } 163 | 164 | size_t HardwareSerial::write(uint8_t c) 165 | { 166 | while (!((*_ucsra) & (1 << _udre))) 167 | ; 168 | 169 | *_udr = c; 170 | 171 | return 1; 172 | } 173 | 174 | // Preinstantiate Objects ////////////////////////////////////////////////////// 175 | 176 | 177 | HardwareSerial Serial(&rx_buffer, &UBRR0H, &UBRR0L, &UCSR0A, &UCSR0B, &UDR0, RXEN0, TXEN0, RXCIE0, UDRE0, U2X0); 178 | HardwareSerial Serial1(&rx_buffer1, &UBRR1H, &UBRR1L, &UCSR1A, &UCSR1B, &UDR1, RXEN1, TXEN1, RXCIE1, UDRE1, U2X1); 179 | 180 | -------------------------------------------------------------------------------- /1.0/at90can/cores/at90can/HardwareSerial.h: -------------------------------------------------------------------------------- 1 | /* 2 | HardwareSerial.h - Hardware serial library for Wiring 3 | Copyright (c) 2006 Nicholas Zambetti. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef HardwareSerial_h 21 | #define HardwareSerial_h 22 | 23 | #include 24 | 25 | #include "Stream.h" 26 | 27 | struct ring_buffer; 28 | 29 | class HardwareSerial : public Stream 30 | { 31 | private: 32 | ring_buffer *_rx_buffer; 33 | volatile uint8_t *_ubrrh; 34 | volatile uint8_t *_ubrrl; 35 | volatile uint8_t *_ucsra; 36 | volatile uint8_t *_ucsrb; 37 | volatile uint8_t *_udr; 38 | uint8_t _rxen; 39 | uint8_t _txen; 40 | uint8_t _rxcie; 41 | uint8_t _udre; 42 | uint8_t _u2x; 43 | public: 44 | HardwareSerial(ring_buffer *rx_buffer, 45 | volatile uint8_t *ubrrh, volatile uint8_t *ubrrl, 46 | volatile uint8_t *ucsra, volatile uint8_t *ucsrb, 47 | volatile uint8_t *udr, 48 | uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udre, uint8_t u2x); 49 | void begin(long); 50 | int available(void); 51 | int peek(void) { return 0; } // SCL20121009 N.B - placeholder - needs to be implemented 52 | int read(void); 53 | void flush(void); 54 | virtual size_t write(uint8_t); 55 | using Print::write; // pull in write(str) and write(buf, size) from Print 56 | operator bool(); 57 | }; 58 | 59 | extern HardwareSerial Serial; 60 | extern HardwareSerial Serial1; 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /1.0/at90can/cores/at90can/Makefile: -------------------------------------------------------------------------------- 1 | # Arduino 0015 Makefile 2 | # Arduino adaptation by mellis, eighthave, oli.keller 3 | # 4 | # This makefile allows you to build sketches from the command line 5 | # without the Arduino environment (or Java). 6 | # 7 | # Detailed instructions for using the makefile: 8 | # 9 | # 1. Copy this file into the folder with your sketch. There should be a 10 | # file with the same name as the folder and with the extension .pde 11 | # (e.g. foo.pde in the foo/ folder). 12 | # 13 | # 2. Modify the line containg "INSTALL_DIR" to point to the directory that 14 | # contains the Arduino installation (for example, under Mac OS X, this 15 | # might be /Applications/arduino-0012). 16 | # 17 | # 3. Modify the line containing "PORT" to refer to the filename 18 | # representing the USB or serial connection to your Arduino board 19 | # (e.g. PORT = /dev/tty.USB0). If the exact name of this file 20 | # changes, you can use * as a wildcard (e.g. PORT = /dev/tty.usb*). 21 | # 22 | # 4. Set the line containing "MCU" to match your board's processor. 23 | # Older one's are atmega8 based, newer ones like Arduino Mini, Bluetooth 24 | # or Diecimila have the atmega168. If you're using a LilyPad Arduino, 25 | # change F_CPU to 8000000. 26 | # 27 | # 5. At the command line, change to the directory containing your 28 | # program's file and the makefile. 29 | # 30 | # 6. Type "make" and press enter to compile/verify your program. 31 | # 32 | # 7. Type "make upload", reset your Arduino board, and press enter to 33 | # upload your program to the Arduino board. 34 | # 35 | # $Id$ 36 | 37 | TARGET = $(notdir $(CURDIR)) 38 | INSTALL_DIR = ../../.. 39 | PORT = /dev/tty.usb* 40 | UPLOAD_RATE = 115200 41 | AVRDUDE_PROGRAMMER = jtagmki 42 | MCU = at90can128 43 | F_CPU = 16000000 44 | 45 | ############################################################################ 46 | # Below here nothing should be changed... 47 | 48 | ARDUINO = $(INSTALL_DIR)/hardware/cores/arduino 49 | AVR_TOOLS_PATH = $(INSTALL_DIR)/hardware/tools/avr/bin 50 | SRC = $(ARDUINO)/pins_arduino.c $(ARDUINO)/wiring.c \ 51 | $(ARDUINO)/wiring_analog.c $(ARDUINO)/wiring_digital.c \ 52 | $(ARDUINO)/wiring_pulse.c $(ARDUINO)/wiring_serial.c \ 53 | $(ARDUINO)/wiring_shift.c $(ARDUINO)/WInterrupts.c 54 | CXXSRC = $(ARDUINO)/HardwareSerial.cpp $(ARDUINO)/WMath.cpp \ 55 | $(ARDUINO)/Print.cpp 56 | FORMAT = ihex 57 | 58 | 59 | # Name of this Makefile (used for "make depend"). 60 | MAKEFILE = Makefile 61 | 62 | # Debugging format. 63 | # Native formats for AVR-GCC's -g are stabs [default], or dwarf-2. 64 | # AVR (extended) COFF requires stabs, plus an avr-objcopy run. 65 | DEBUG = stabs 66 | 67 | OPT = s 68 | 69 | # Place -D or -U options here 70 | CDEFS = -DF_CPU=$(F_CPU) 71 | CXXDEFS = -DF_CPU=$(F_CPU) 72 | 73 | # Place -I options here 74 | CINCS = -I$(ARDUINO) 75 | CXXINCS = -I$(ARDUINO) 76 | 77 | # Compiler flag to set the C Standard level. 78 | # c89 - "ANSI" C 79 | # gnu89 - c89 plus GCC extensions 80 | # c99 - ISO C99 standard (not yet fully implemented) 81 | # gnu99 - c99 plus GCC extensions 82 | CSTANDARD = -std=gnu99 83 | CDEBUG = -g$(DEBUG) 84 | CWARN = -Wall -Wstrict-prototypes 85 | CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums 86 | #CEXTRA = -Wa,-adhlns=$(<:.c=.lst) 87 | 88 | CFLAGS = $(CDEBUG) $(CDEFS) $(CINCS) -O$(OPT) $(CWARN) $(CSTANDARD) $(CEXTRA) 89 | CXXFLAGS = $(CDEFS) $(CINCS) -O$(OPT) 90 | #ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs 91 | LDFLAGS = -lm 92 | 93 | 94 | # Programming support using avrdude. Settings and variables. 95 | AVRDUDE_PORT = $(PORT) 96 | AVRDUDE_WRITE_FLASH = -U flash:w:applet/$(TARGET).hex 97 | AVRDUDE_FLAGS = -V -F -C $(INSTALL_DIR)/hardware/tools/avr/etc/avrdude.conf \ 98 | -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) \ 99 | -b $(UPLOAD_RATE) 100 | 101 | # Program settings 102 | CC = $(AVR_TOOLS_PATH)/avr-gcc 103 | CXX = $(AVR_TOOLS_PATH)/avr-g++ 104 | OBJCOPY = $(AVR_TOOLS_PATH)/avr-objcopy 105 | OBJDUMP = $(AVR_TOOLS_PATH)/avr-objdump 106 | AR = $(AVR_TOOLS_PATH)/avr-ar 107 | SIZE = $(AVR_TOOLS_PATH)/avr-size 108 | NM = $(AVR_TOOLS_PATH)/avr-nm 109 | AVRDUDE = $(AVR_TOOLS_PATH)/avrdude 110 | REMOVE = rm -f 111 | MV = mv -f 112 | 113 | # Define all object files. 114 | OBJ = $(SRC:.c=.o) $(CXXSRC:.cpp=.o) $(ASRC:.S=.o) 115 | 116 | # Define all listing files. 117 | LST = $(ASRC:.S=.lst) $(CXXSRC:.cpp=.lst) $(SRC:.c=.lst) 118 | 119 | # Combine all necessary flags and optional flags. 120 | # Add target processor to flags. 121 | ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) 122 | ALL_CXXFLAGS = -mmcu=$(MCU) -I. $(CXXFLAGS) 123 | ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS) 124 | 125 | 126 | # Default target. 127 | all: applet_files build sizeafter 128 | 129 | build: elf hex 130 | 131 | applet_files: $(TARGET).pde 132 | # Here is the "preprocessing". 133 | # It creates a .cpp file based with the same name as the .pde file. 134 | # On top of the new .cpp file comes the WProgram.h header. 135 | # At the end there is a generic main() function attached. 136 | # Then the .cpp file will be compiled. Errors during compile will 137 | # refer to this new, automatically generated, file. 138 | # Not the original .pde file you actually edit... 139 | test -d applet || mkdir applet 140 | echo '#include "WProgram.h"' > applet/$(TARGET).cpp 141 | cat $(TARGET).pde >> applet/$(TARGET).cpp 142 | cat $(ARDUINO)/main.cxx >> applet/$(TARGET).cpp 143 | 144 | elf: applet/$(TARGET).elf 145 | hex: applet/$(TARGET).hex 146 | eep: applet/$(TARGET).eep 147 | lss: applet/$(TARGET).lss 148 | sym: applet/$(TARGET).sym 149 | 150 | # Program the device. 151 | upload: applet/$(TARGET).hex 152 | $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) 153 | 154 | 155 | # Display size of file. 156 | HEXSIZE = $(SIZE) --target=$(FORMAT) applet/$(TARGET).hex 157 | ELFSIZE = $(SIZE) applet/$(TARGET).elf 158 | sizebefore: 159 | @if [ -f applet/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(HEXSIZE); echo; fi 160 | 161 | sizeafter: 162 | @if [ -f applet/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(HEXSIZE); echo; fi 163 | 164 | 165 | # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB. 166 | COFFCONVERT=$(OBJCOPY) --debugging \ 167 | --change-section-address .data-0x800000 \ 168 | --change-section-address .bss-0x800000 \ 169 | --change-section-address .noinit-0x800000 \ 170 | --change-section-address .eeprom-0x810000 171 | 172 | 173 | coff: applet/$(TARGET).elf 174 | $(COFFCONVERT) -O coff-avr applet/$(TARGET).elf $(TARGET).cof 175 | 176 | 177 | extcoff: $(TARGET).elf 178 | $(COFFCONVERT) -O coff-ext-avr applet/$(TARGET).elf $(TARGET).cof 179 | 180 | 181 | .SUFFIXES: .elf .hex .eep .lss .sym 182 | 183 | .elf.hex: 184 | $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@ 185 | 186 | .elf.eep: 187 | -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \ 188 | --change-section-lma .eeprom=0 -O $(FORMAT) $< $@ 189 | 190 | # Create extended listing file from ELF output file. 191 | .elf.lss: 192 | $(OBJDUMP) -h -S $< > $@ 193 | 194 | # Create a symbol table from ELF output file. 195 | .elf.sym: 196 | $(NM) -n $< > $@ 197 | 198 | # Link: create ELF output file from library. 199 | applet/$(TARGET).elf: $(TARGET).pde applet/core.a 200 | $(CC) $(ALL_CFLAGS) -o $@ applet/$(TARGET).cpp -L. applet/core.a $(LDFLAGS) 201 | 202 | applet/core.a: $(OBJ) 203 | @for i in $(OBJ); do echo $(AR) rcs applet/core.a $$i; $(AR) rcs applet/core.a $$i; done 204 | 205 | 206 | 207 | # Compile: create object files from C++ source files. 208 | .cpp.o: 209 | $(CXX) -c $(ALL_CXXFLAGS) $< -o $@ 210 | 211 | # Compile: create object files from C source files. 212 | .c.o: 213 | $(CC) -c $(ALL_CFLAGS) $< -o $@ 214 | 215 | 216 | # Compile: create assembler files from C source files. 217 | .c.s: 218 | $(CC) -S $(ALL_CFLAGS) $< -o $@ 219 | 220 | 221 | # Assemble: create object files from assembler source files. 222 | .S.o: 223 | $(CC) -c $(ALL_ASFLAGS) $< -o $@ 224 | 225 | 226 | # Automatic dependencies 227 | %.d: %.c 228 | $(CC) -M $(ALL_CFLAGS) $< | sed "s;$(notdir $*).o:;$*.o $*.d:;" > $@ 229 | 230 | %.d: %.cpp 231 | $(CXX) -M $(ALL_CXXFLAGS) $< | sed "s;$(notdir $*).o:;$*.o $*.d:;" > $@ 232 | 233 | 234 | # Target: clean project. 235 | clean: 236 | $(REMOVE) applet/$(TARGET).hex applet/$(TARGET).eep applet/$(TARGET).cof applet/$(TARGET).elf \ 237 | applet/$(TARGET).map applet/$(TARGET).sym applet/$(TARGET).lss applet/core.a \ 238 | $(OBJ) $(LST) $(SRC:.c=.s) $(SRC:.c=.d) $(CXXSRC:.cpp=.s) $(CXXSRC:.cpp=.d) 239 | 240 | .PHONY: all build elf hex eep lss sym program coff extcoff clean applet_files sizebefore sizeafter 241 | 242 | include $(SRC:.c=.d) 243 | include $(CXXSRC:.cpp=.d) 244 | -------------------------------------------------------------------------------- /1.0/at90can/cores/at90can/Print.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Print.cpp - Base class that provides print() and println() 3 | Copyright (c) 2008 David A. Mellis. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | Modified 23 November 2006 by David A. Mellis 20 | */ 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include "Arduino.h" 27 | 28 | #include "Print.h" 29 | 30 | // Public Methods ////////////////////////////////////////////////////////////// 31 | 32 | /* default implementation: may be overridden */ 33 | size_t Print::write(const uint8_t *buffer, size_t size) 34 | { 35 | size_t n = 0; 36 | while (size--) { 37 | n += write(*buffer++); 38 | } 39 | return n; 40 | } 41 | 42 | size_t Print::print(const __FlashStringHelper *ifsh) 43 | { 44 | const char PROGMEM *p = (const char PROGMEM *)ifsh; 45 | size_t n = 0; 46 | while (1) { 47 | unsigned char c = pgm_read_byte(p++); 48 | if (c == 0) break; 49 | n += write(c); 50 | } 51 | return n; 52 | } 53 | 54 | size_t Print::print(const String &s) 55 | { 56 | size_t n = 0; 57 | for (uint16_t i = 0; i < s.length(); i++) { 58 | n += write(s[i]); 59 | } 60 | return n; 61 | } 62 | 63 | size_t Print::print(const char str[]) 64 | { 65 | return write(str); 66 | } 67 | 68 | size_t Print::print(char c) 69 | { 70 | return write(c); 71 | } 72 | 73 | size_t Print::print(unsigned char b, int base) 74 | { 75 | return print((unsigned long) b, base); 76 | } 77 | 78 | size_t Print::print(int n, int base) 79 | { 80 | return print((long) n, base); 81 | } 82 | 83 | size_t Print::print(unsigned int n, int base) 84 | { 85 | return print((unsigned long) n, base); 86 | } 87 | 88 | size_t Print::print(long n, int base) 89 | { 90 | if (base == 0) { 91 | return write(n); 92 | } else if (base == 10) { 93 | if (n < 0) { 94 | int t = print('-'); 95 | n = -n; 96 | return printNumber(n, 10) + t; 97 | } 98 | return printNumber(n, 10); 99 | } else { 100 | return printNumber(n, base); 101 | } 102 | } 103 | 104 | size_t Print::print(unsigned long n, int base) 105 | { 106 | if (base == 0) return write(n); 107 | else return printNumber(n, base); 108 | } 109 | 110 | size_t Print::print(double n, int digits) 111 | { 112 | return printFloat(n, digits); 113 | } 114 | 115 | size_t Print::println(const __FlashStringHelper *ifsh) 116 | { 117 | size_t n = print(ifsh); 118 | n += println(); 119 | return n; 120 | } 121 | 122 | size_t Print::print(const Printable& x) 123 | { 124 | return x.printTo(*this); 125 | } 126 | 127 | size_t Print::println(void) 128 | { 129 | size_t n = print('\r'); 130 | n += print('\n'); 131 | return n; 132 | } 133 | 134 | size_t Print::println(const String &s) 135 | { 136 | size_t n = print(s); 137 | n += println(); 138 | return n; 139 | } 140 | 141 | size_t Print::println(const char c[]) 142 | { 143 | size_t n = print(c); 144 | n += println(); 145 | return n; 146 | } 147 | 148 | size_t Print::println(char c) 149 | { 150 | size_t n = print(c); 151 | n += println(); 152 | return n; 153 | } 154 | 155 | size_t Print::println(unsigned char b, int base) 156 | { 157 | size_t n = print(b, base); 158 | n += println(); 159 | return n; 160 | } 161 | 162 | size_t Print::println(int num, int base) 163 | { 164 | size_t n = print(num, base); 165 | n += println(); 166 | return n; 167 | } 168 | 169 | size_t Print::println(unsigned int num, int base) 170 | { 171 | size_t n = print(num, base); 172 | n += println(); 173 | return n; 174 | } 175 | 176 | size_t Print::println(long num, int base) 177 | { 178 | size_t n = print(num, base); 179 | n += println(); 180 | return n; 181 | } 182 | 183 | size_t Print::println(unsigned long num, int base) 184 | { 185 | size_t n = print(num, base); 186 | n += println(); 187 | return n; 188 | } 189 | 190 | size_t Print::println(double num, int digits) 191 | { 192 | size_t n = print(num, digits); 193 | n += println(); 194 | return n; 195 | } 196 | 197 | size_t Print::println(const Printable& x) 198 | { 199 | size_t n = print(x); 200 | n += println(); 201 | return n; 202 | } 203 | 204 | // Private Methods ///////////////////////////////////////////////////////////// 205 | 206 | size_t Print::printNumber(unsigned long n, uint8_t base) { 207 | char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte. 208 | char *str = &buf[sizeof(buf) - 1]; 209 | 210 | *str = '\0'; 211 | 212 | // prevent crash if called with base == 1 213 | if (base < 2) base = 10; 214 | 215 | do { 216 | unsigned long m = n; 217 | n /= base; 218 | char c = m - base * n; 219 | *--str = c < 10 ? c + '0' : c + 'A' - 10; 220 | } while(n); 221 | 222 | return write(str); 223 | } 224 | 225 | size_t Print::printFloat(double number, uint8_t digits) 226 | { 227 | size_t n = 0; 228 | 229 | // Handle negative numbers 230 | if (number < 0.0) 231 | { 232 | n += print('-'); 233 | number = -number; 234 | } 235 | 236 | // Round correctly so that print(1.999, 2) prints as "2.00" 237 | double rounding = 0.5; 238 | for (uint8_t i=0; i 0) { 250 | n += print("."); 251 | } 252 | 253 | // Extract digits from the remainder one at a time 254 | while (digits-- > 0) 255 | { 256 | remainder *= 10.0; 257 | int toPrint = int(remainder); 258 | n += print(toPrint); 259 | remainder -= toPrint; 260 | } 261 | 262 | return n; 263 | } 264 | -------------------------------------------------------------------------------- /1.0/at90can/cores/at90can/Print.h: -------------------------------------------------------------------------------- 1 | /* 2 | Print.h - Base class that provides print() and println() 3 | Copyright (c) 2008 David A. Mellis. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef Print_h 21 | #define Print_h 22 | 23 | #include 24 | #include // for size_t 25 | 26 | #include "WString.h" 27 | #include "Printable.h" 28 | 29 | #define DEC 10 30 | #define HEX 16 31 | #define OCT 8 32 | #define BIN 2 33 | 34 | class Print 35 | { 36 | private: 37 | int write_error; 38 | size_t printNumber(unsigned long, uint8_t); 39 | size_t printFloat(double, uint8_t); 40 | protected: 41 | void setWriteError(int err = 1) { write_error = err; } 42 | public: 43 | Print() : write_error(0) {} 44 | 45 | int getWriteError() { return write_error; } 46 | void clearWriteError() { setWriteError(0); } 47 | 48 | virtual size_t write(uint8_t) = 0; 49 | size_t write(const char *str) { return write((const uint8_t *)str, strlen(str)); } 50 | virtual size_t write(const uint8_t *buffer, size_t size); 51 | 52 | size_t print(const __FlashStringHelper *); 53 | size_t print(const String &); 54 | size_t print(const char[]); 55 | size_t print(char); 56 | size_t print(unsigned char, int = DEC); 57 | size_t print(int, int = DEC); 58 | size_t print(unsigned int, int = DEC); 59 | size_t print(long, int = DEC); 60 | size_t print(unsigned long, int = DEC); 61 | size_t print(double, int = 2); 62 | size_t print(const Printable&); 63 | 64 | size_t println(const __FlashStringHelper *); 65 | size_t println(const String &s); 66 | size_t println(const char[]); 67 | size_t println(char); 68 | size_t println(unsigned char, int = DEC); 69 | size_t println(int, int = DEC); 70 | size_t println(unsigned int, int = DEC); 71 | size_t println(long, int = DEC); 72 | size_t println(unsigned long, int = DEC); 73 | size_t println(double, int = 2); 74 | size_t println(const Printable&); 75 | size_t println(void); 76 | }; 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /1.0/at90can/cores/at90can/Printable.h: -------------------------------------------------------------------------------- 1 | /* 2 | Printable.h - Interface class that allows printing of complex types 3 | Copyright (c) 2011 Adrian McEwen. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef Printable_h 21 | #define Printable_h 22 | 23 | #include 24 | 25 | class Print; 26 | 27 | /** The Printable class provides a way for new classes to allow themselves to be printed. 28 | By deriving from Printable and implementing the printTo method, it will then be possible 29 | for users to print out instances of this class by passing them into the usual 30 | Print::print and Print::println methods. 31 | */ 32 | 33 | class Printable 34 | { 35 | public: 36 | virtual size_t printTo(Print& p) const = 0; 37 | }; 38 | 39 | #endif 40 | 41 | -------------------------------------------------------------------------------- /1.0/at90can/cores/at90can/Stream.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Stream.cpp - adds parsing methods to Stream class 3 | Copyright (c) 2008 David A. Mellis. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | Created July 2011 20 | parsing functions based on TextFinder library by Michael Margolis 21 | */ 22 | 23 | #include "Arduino.h" 24 | #include "Stream.h" 25 | 26 | #define PARSE_TIMEOUT 1000 // default number of milli-seconds to wait 27 | #define NO_SKIP_CHAR 1 // a magic char not found in a valid ASCII numeric field 28 | 29 | // private method to read stream with timeout 30 | int Stream::timedRead() 31 | { 32 | int c; 33 | _startMillis = millis(); 34 | do { 35 | c = read(); 36 | if (c >= 0) return c; 37 | } while(millis() - _startMillis < _timeout); 38 | return -1; // -1 indicates timeout 39 | } 40 | 41 | // private method to peek stream with timeout 42 | int Stream::timedPeek() 43 | { 44 | int c; 45 | _startMillis = millis(); 46 | do { 47 | c = peek(); 48 | if (c >= 0) return c; 49 | } while(millis() - _startMillis < _timeout); 50 | return -1; // -1 indicates timeout 51 | } 52 | 53 | // returns peek of the next digit in the stream or -1 if timeout 54 | // discards non-numeric characters 55 | int Stream::peekNextDigit() 56 | { 57 | int c; 58 | while (1) { 59 | c = timedPeek(); 60 | if (c < 0) return c; // timeout 61 | if (c == '-') return c; 62 | if (c >= '0' && c <= '9') return c; 63 | read(); // discard non-numeric 64 | } 65 | } 66 | 67 | // Public Methods 68 | ////////////////////////////////////////////////////////////// 69 | 70 | void Stream::setTimeout(unsigned long timeout) // sets the maximum number of milliseconds to wait 71 | { 72 | _timeout = timeout; 73 | } 74 | 75 | // find returns true if the target string is found 76 | bool Stream::find(char *target) 77 | { 78 | return findUntil(target, NULL); 79 | } 80 | 81 | // reads data from the stream until the target string of given length is found 82 | // returns true if target string is found, false if timed out 83 | bool Stream::find(char *target, size_t length) 84 | { 85 | return findUntil(target, length, NULL, 0); 86 | } 87 | 88 | // as find but search ends if the terminator string is found 89 | bool Stream::findUntil(char *target, char *terminator) 90 | { 91 | return findUntil(target, strlen(target), terminator, strlen(terminator)); 92 | } 93 | 94 | // reads data from the stream until the target string of the given length is found 95 | // search terminated if the terminator string is found 96 | // returns true if target string is found, false if terminated or timed out 97 | bool Stream::findUntil(char *target, size_t targetLen, char *terminator, size_t termLen) 98 | { 99 | size_t index = 0; // maximum target string length is 64k bytes! 100 | size_t termIndex = 0; 101 | int c; 102 | 103 | if( *target == 0) 104 | return true; // return true if target is a null string 105 | while( (c = timedRead()) > 0){ 106 | 107 | if(c != target[index]) 108 | index = 0; // reset index if any char does not match 109 | 110 | if( c == target[index]){ 111 | //////Serial.print("found "); Serial.write(c); Serial.print("index now"); Serial.println(index+1); 112 | if(++index >= targetLen){ // return true if all chars in the target match 113 | return true; 114 | } 115 | } 116 | 117 | if(termLen > 0 && c == terminator[termIndex]){ 118 | if(++termIndex >= termLen) 119 | return false; // return false if terminate string found before target string 120 | } 121 | else 122 | termIndex = 0; 123 | } 124 | return false; 125 | } 126 | 127 | 128 | // returns the first valid (long) integer value from the current position. 129 | // initial characters that are not digits (or the minus sign) are skipped 130 | // function is terminated by the first character that is not a digit. 131 | long Stream::parseInt() 132 | { 133 | return parseInt(NO_SKIP_CHAR); // terminate on first non-digit character (or timeout) 134 | } 135 | 136 | // as above but a given skipChar is ignored 137 | // this allows format characters (typically commas) in values to be ignored 138 | long Stream::parseInt(char skipChar) 139 | { 140 | boolean isNegative = false; 141 | long value = 0; 142 | int c; 143 | 144 | c = peekNextDigit(); 145 | // ignore non numeric leading characters 146 | if(c < 0) 147 | return 0; // zero returned if timeout 148 | 149 | do{ 150 | if(c == skipChar) 151 | ; // ignore this charactor 152 | else if(c == '-') 153 | isNegative = true; 154 | else if(c >= '0' && c <= '9') // is c a digit? 155 | value = value * 10 + c - '0'; 156 | read(); // consume the character we got with peek 157 | c = timedPeek(); 158 | } 159 | while( (c >= '0' && c <= '9') || c == skipChar ); 160 | 161 | if(isNegative) 162 | value = -value; 163 | return value; 164 | } 165 | 166 | 167 | // as parseInt but returns a floating point value 168 | float Stream::parseFloat() 169 | { 170 | return parseFloat(NO_SKIP_CHAR); 171 | } 172 | 173 | // as above but the given skipChar is ignored 174 | // this allows format characters (typically commas) in values to be ignored 175 | float Stream::parseFloat(char skipChar){ 176 | boolean isNegative = false; 177 | boolean isFraction = false; 178 | long value = 0; 179 | char c; 180 | float fraction = 1.0; 181 | 182 | c = peekNextDigit(); 183 | // ignore non numeric leading characters 184 | if(c < 0) 185 | return 0; // zero returned if timeout 186 | 187 | do{ 188 | if(c == skipChar) 189 | ; // ignore 190 | else if(c == '-') 191 | isNegative = true; 192 | else if (c == '.') 193 | isFraction = true; 194 | else if(c >= '0' && c <= '9') { // is c a digit? 195 | value = value * 10 + c - '0'; 196 | if(isFraction) 197 | fraction *= 0.1; 198 | } 199 | read(); // consume the character we got with peek 200 | c = timedPeek(); 201 | } 202 | while( (c >= '0' && c <= '9') || c == '.' || c == skipChar ); 203 | 204 | if(isNegative) 205 | value = -value; 206 | if(isFraction) 207 | return value * fraction; 208 | else 209 | return value; 210 | } 211 | 212 | // read characters from stream into buffer 213 | // terminates if length characters have been read, or timeout (see setTimeout) 214 | // returns the number of characters placed in the buffer 215 | // the buffer is NOT null terminated. 216 | // 217 | size_t Stream::readBytes(char *buffer, size_t length) 218 | { 219 | size_t count = 0; 220 | while (count < length) { 221 | int c = timedRead(); 222 | if (c < 0) break; 223 | *buffer++ = (char)c; 224 | count++; 225 | } 226 | return count; 227 | } 228 | 229 | 230 | // as readBytes with terminator character 231 | // terminates if length characters have been read, timeout, or if the terminator character detected 232 | // returns the number of characters placed in the buffer (0 means no valid data found) 233 | 234 | size_t Stream::readBytesUntil(char terminator, char *buffer, size_t length) 235 | { 236 | if (length < 1) return 0; 237 | size_t index = 0; 238 | while (index < length) { 239 | int c = timedRead(); 240 | if (c < 0 || c == terminator) break; 241 | *buffer++ = (char)c; 242 | index++; 243 | } 244 | return index; // return number of characters, not including null terminator 245 | } 246 | 247 | String Stream::readString() 248 | { 249 | String ret; 250 | int c = timedRead(); 251 | while (c >= 0) 252 | { 253 | ret += (char)c; 254 | c = timedRead(); 255 | } 256 | return ret; 257 | } 258 | 259 | String Stream::readStringUntil(char terminator) 260 | { 261 | String ret; 262 | int c = timedRead(); 263 | while (c >= 0 && c != terminator) 264 | { 265 | ret += (char)c; 266 | c = timedRead(); 267 | } 268 | return ret; 269 | } 270 | 271 | -------------------------------------------------------------------------------- /1.0/at90can/cores/at90can/Stream.h: -------------------------------------------------------------------------------- 1 | /* 2 | Stream.h - base class for character-based streams. 3 | Copyright (c) 2010 David A. Mellis. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | parsing functions based on TextFinder library by Michael Margolis 20 | */ 21 | 22 | #ifndef Stream_h 23 | #define Stream_h 24 | 25 | #include 26 | #include "Print.h" 27 | #include "WString.h" 28 | 29 | // compatability macros for testing 30 | /* 31 | #define getInt() parseInt() 32 | #define getInt(skipChar) parseInt(skipchar) 33 | #define getFloat() parseFloat() 34 | #define getFloat(skipChar) parseFloat(skipChar) 35 | #define getString( pre_string, post_string, buffer, length) 36 | readBytesBetween( pre_string, terminator, buffer, length) 37 | */ 38 | 39 | class Stream : public Print 40 | { 41 | private: 42 | unsigned long _timeout; // number of milliseconds to wait for the next char before aborting timed read 43 | unsigned long _startMillis; // used for timeout measurement 44 | int timedRead(); // private method to read stream with timeout 45 | int timedPeek(); // private method to peek stream with timeout 46 | int peekNextDigit(); // returns the next numeric digit in the stream or -1 if timeout 47 | 48 | public: 49 | virtual int available() = 0; 50 | virtual int read() = 0; 51 | virtual int peek() = 0; 52 | virtual void flush() = 0; 53 | 54 | Stream() {_timeout=1000;} 55 | 56 | // parsing methods 57 | 58 | void setTimeout(unsigned long timeout); // sets maximum milliseconds to wait for stream data, default is 1 second 59 | 60 | bool find(char *target); // reads data from the stream until the target string is found 61 | // returns true if target string is found, false if timed out (see setTimeout) 62 | 63 | bool find(char *target, size_t length); // reads data from the stream until the target string of given length is found 64 | // returns true if target string is found, false if timed out 65 | 66 | bool findUntil(char *target, char *terminator); // as find but search ends if the terminator string is found 67 | 68 | bool findUntil(char *target, size_t targetLen, char *terminate, size_t termLen); // as above but search ends if the terminate string is found 69 | 70 | 71 | long parseInt(); // returns the first valid (long) integer value from the current position. 72 | // initial characters that are not digits (or the minus sign) are skipped 73 | // integer is terminated by the first character that is not a digit. 74 | 75 | float parseFloat(); // float version of parseInt 76 | 77 | size_t readBytes( char *buffer, size_t length); // read chars from stream into buffer 78 | // terminates if length characters have been read or timeout (see setTimeout) 79 | // returns the number of characters placed in the buffer (0 means no valid data found) 80 | 81 | size_t readBytesUntil( char terminator, char *buffer, size_t length); // as readBytes with terminator character 82 | // terminates if length characters have been read, timeout, or if the terminator character detected 83 | // returns the number of characters placed in the buffer (0 means no valid data found) 84 | 85 | // Arduino String functions to be added here 86 | String readString(); 87 | String readStringUntil(char terminator); 88 | 89 | protected: 90 | long parseInt(char skipChar); // as above but the given skipChar is ignored 91 | // as above but the given skipChar is ignored 92 | // this allows format characters (typically commas) in values to be ignored 93 | 94 | float parseFloat(char skipChar); // as above but the given skipChar is ignored 95 | }; 96 | 97 | #endif 98 | -------------------------------------------------------------------------------- /1.0/at90can/cores/at90can/WCharacter.h: -------------------------------------------------------------------------------- 1 | /* 2 | WCharacter.h - Character utility functions for Wiring & Arduino 3 | Copyright (c) 2010 Hernando Barragan. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef Character_h 21 | #define Character_h 22 | 23 | #include 24 | 25 | // WCharacter.h prototypes 26 | inline boolean isAlphaNumeric(int c) __attribute__((always_inline)); 27 | inline boolean isAlpha(int c) __attribute__((always_inline)); 28 | inline boolean isAscii(int c) __attribute__((always_inline)); 29 | inline boolean isWhitespace(int c) __attribute__((always_inline)); 30 | inline boolean isControl(int c) __attribute__((always_inline)); 31 | inline boolean isDigit(int c) __attribute__((always_inline)); 32 | inline boolean isGraph(int c) __attribute__((always_inline)); 33 | inline boolean isLowerCase(int c) __attribute__((always_inline)); 34 | inline boolean isPrintable(int c) __attribute__((always_inline)); 35 | inline boolean isPunct(int c) __attribute__((always_inline)); 36 | inline boolean isSpace(int c) __attribute__((always_inline)); 37 | inline boolean isUpperCase(int c) __attribute__((always_inline)); 38 | inline boolean isHexadecimalDigit(int c) __attribute__((always_inline)); 39 | inline int toAscii(int c) __attribute__((always_inline)); 40 | inline int toLowerCase(int c) __attribute__((always_inline)); 41 | inline int toUpperCase(int c)__attribute__((always_inline)); 42 | 43 | 44 | // Checks for an alphanumeric character. 45 | // It is equivalent to (isalpha(c) || isdigit(c)). 46 | inline boolean isAlphaNumeric(int c) 47 | { 48 | return ( isalnum(c) == 0 ? false : true); 49 | } 50 | 51 | 52 | // Checks for an alphabetic character. 53 | // It is equivalent to (isupper(c) || islower(c)). 54 | inline boolean isAlpha(int c) 55 | { 56 | return ( isalpha(c) == 0 ? false : true); 57 | } 58 | 59 | 60 | // Checks whether c is a 7-bit unsigned char value 61 | // that fits into the ASCII character set. 62 | inline boolean isAscii(int c) 63 | { 64 | return ( isascii (c) == 0 ? false : true); 65 | } 66 | 67 | 68 | // Checks for a blank character, that is, a space or a tab. 69 | inline boolean isWhitespace(int c) 70 | { 71 | return ( isblank (c) == 0 ? false : true); 72 | } 73 | 74 | 75 | // Checks for a control character. 76 | inline boolean isControl(int c) 77 | { 78 | return ( iscntrl (c) == 0 ? false : true); 79 | } 80 | 81 | 82 | // Checks for a digit (0 through 9). 83 | inline boolean isDigit(int c) 84 | { 85 | return ( isdigit (c) == 0 ? false : true); 86 | } 87 | 88 | 89 | // Checks for any printable character except space. 90 | inline boolean isGraph(int c) 91 | { 92 | return ( isgraph (c) == 0 ? false : true); 93 | } 94 | 95 | 96 | // Checks for a lower-case character. 97 | inline boolean isLowerCase(int c) 98 | { 99 | return (islower (c) == 0 ? false : true); 100 | } 101 | 102 | 103 | // Checks for any printable character including space. 104 | inline boolean isPrintable(int c) 105 | { 106 | return ( isprint (c) == 0 ? false : true); 107 | } 108 | 109 | 110 | // Checks for any printable character which is not a space 111 | // or an alphanumeric character. 112 | inline boolean isPunct(int c) 113 | { 114 | return ( ispunct (c) == 0 ? false : true); 115 | } 116 | 117 | 118 | // Checks for white-space characters. For the avr-libc library, 119 | // these are: space, formfeed ('\f'), newline ('\n'), carriage 120 | // return ('\r'), horizontal tab ('\t'), and vertical tab ('\v'). 121 | inline boolean isSpace(int c) 122 | { 123 | return ( isspace (c) == 0 ? false : true); 124 | } 125 | 126 | 127 | // Checks for an uppercase letter. 128 | inline boolean isUpperCase(int c) 129 | { 130 | return ( isupper (c) == 0 ? false : true); 131 | } 132 | 133 | 134 | // Checks for a hexadecimal digits, i.e. one of 0 1 2 3 4 5 6 7 135 | // 8 9 a b c d e f A B C D E F. 136 | inline boolean isHexadecimalDigit(int c) 137 | { 138 | return ( isxdigit (c) == 0 ? false : true); 139 | } 140 | 141 | 142 | // Converts c to a 7-bit unsigned char value that fits into the 143 | // ASCII character set, by clearing the high-order bits. 144 | inline int toAscii(int c) 145 | { 146 | return toascii (c); 147 | } 148 | 149 | 150 | // Warning: 151 | // Many people will be unhappy if you use this function. 152 | // This function will convert accented letters into random 153 | // characters. 154 | 155 | // Converts the letter c to lower case, if possible. 156 | inline int toLowerCase(int c) 157 | { 158 | return tolower (c); 159 | } 160 | 161 | 162 | // Converts the letter c to upper case, if possible. 163 | inline int toUpperCase(int c) 164 | { 165 | return toupper (c); 166 | } 167 | 168 | #endif -------------------------------------------------------------------------------- /1.0/at90can/cores/at90can/WConstants.h: -------------------------------------------------------------------------------- 1 | #include "wiring.h" 2 | -------------------------------------------------------------------------------- /1.0/at90can/cores/at90can/WInterrupts.c: -------------------------------------------------------------------------------- 1 | /* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2 | 3 | /* 4 | Part of the Wiring project - http://wiring.uniandes.edu.co 5 | 6 | Copyright (c) 2004-05 Hernando Barragan 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 2.1 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General 19 | Public License along with this library; if not, write to the 20 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 21 | Boston, MA 02111-1307 USA 22 | 23 | Modified 24 November 2006 by David A. Mellis 24 | */ 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include "WConstants.h" 33 | #include "wiring_private.h" 34 | 35 | volatile static voidFuncPtr intFunc[EXTERNAL_NUM_INTERRUPTS]; 36 | // volatile static voidFuncPtr twiIntFunc; 37 | 38 | 39 | void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode) { 40 | if(interruptNum < EXTERNAL_NUM_INTERRUPTS) { 41 | intFunc[interruptNum] = userFunc; 42 | 43 | // Configure the interrupt mode (trigger on low input, any change, rising 44 | // edge, or falling edge). The mode constants were chosen to correspond 45 | // to the configuration bits in the hardware register, so we simply shift 46 | // the mode into place. 47 | 48 | // Enable the interrupt. 49 | 50 | switch (interruptNum) { 51 | case 0: 52 | EICRA = (EICRA & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00); 53 | EIMSK |= (1 << INT0); 54 | break; 55 | case 1: 56 | EICRA = (EICRA & ~((1 << ISC10) | (1 << ISC11))) | (mode << ISC10); 57 | EIMSK |= (1 << INT1); 58 | break; 59 | case 2: 60 | EICRA = (EICRA & ~((1 << ISC20) | (1 << ISC21))) | (mode << ISC20); 61 | EIMSK |= (1 << INT2); 62 | break; 63 | case 3: 64 | EICRA = (EICRA & ~((1 << ISC30) | (1 << ISC31))) | (mode << ISC30); 65 | EIMSK |= (1 << INT3); 66 | break; 67 | case 4: 68 | EICRB = (EICRB & ~((1 << ISC40) | (1 << ISC41))) | (mode << ISC40); 69 | EIMSK |= (1 << INT4); 70 | break; 71 | case 5: 72 | EICRB = (EICRB & ~((1 << ISC50) | (1 << ISC51))) | (mode << ISC50); 73 | EIMSK |= (1 << INT5); 74 | break; 75 | case 6: 76 | EICRB = (EICRB & ~((1 << ISC60) | (1 << ISC61))) | (mode << ISC60); 77 | EIMSK |= (1 << INT6); 78 | break; 79 | case 7: 80 | EICRB = (EICRB & ~((1 << ISC70) | (1 << ISC71))) | (mode << ISC70); 81 | EIMSK |= (1 << INT7); 82 | break; 83 | } 84 | } 85 | } 86 | 87 | void detachInterrupt(uint8_t interruptNum) { 88 | if(interruptNum < EXTERNAL_NUM_INTERRUPTS) { 89 | // Disable the interrupt. (We can't assume that interruptNum is equal 90 | // to the number of the EIMSK bit to clear, as this isn't true on the 91 | // ATmega8. There, INT0 is 6 and INT1 is 7.) 92 | switch (interruptNum) { 93 | case 0: 94 | EIMSK &= ~(1 << INT0); 95 | break; 96 | case 1: 97 | EIMSK &= ~(1 << INT1); 98 | break; 99 | case 2: 100 | EIMSK &= ~(1 << INT2); 101 | break; 102 | case 3: 103 | EIMSK &= ~(1 << INT3); 104 | break; 105 | case 4: 106 | EIMSK &= ~(1 << INT4); 107 | break; 108 | case 5: 109 | EIMSK &= ~(1 << INT5); 110 | break; 111 | case 6: 112 | EIMSK &= ~(1 << INT6); 113 | break; 114 | case 7: 115 | EIMSK &= ~(1 << INT7); 116 | break; 117 | } 118 | 119 | intFunc[interruptNum] = 0; 120 | } 121 | } 122 | 123 | /* 124 | void attachInterruptTwi(void (*userFunc)(void) ) { 125 | twiIntFunc = userFunc; 126 | } 127 | */ 128 | 129 | 130 | SIGNAL(INT0_vect) { 131 | if(intFunc[EXTERNAL_INT_0]) 132 | intFunc[EXTERNAL_INT_0](); 133 | } 134 | 135 | SIGNAL(INT1_vect) { 136 | if(intFunc[EXTERNAL_INT_1]) 137 | intFunc[EXTERNAL_INT_1](); 138 | } 139 | 140 | SIGNAL(INT2_vect) { 141 | if(intFunc[EXTERNAL_INT_2]) 142 | intFunc[EXTERNAL_INT_2](); 143 | } 144 | 145 | SIGNAL(INT3_vect) { 146 | if(intFunc[EXTERNAL_INT_3]) 147 | intFunc[EXTERNAL_INT_3](); 148 | } 149 | 150 | SIGNAL(INT4_vect) { 151 | if(intFunc[EXTERNAL_INT_4]) 152 | intFunc[EXTERNAL_INT_4](); 153 | } 154 | 155 | SIGNAL(INT5_vect) { 156 | if(intFunc[EXTERNAL_INT_5]) 157 | intFunc[EXTERNAL_INT_5](); 158 | } 159 | 160 | SIGNAL(INT6_vect) { 161 | if(intFunc[EXTERNAL_INT_6]) 162 | intFunc[EXTERNAL_INT_6](); 163 | } 164 | 165 | SIGNAL(INT7_vect) { 166 | if(intFunc[EXTERNAL_INT_7]) 167 | intFunc[EXTERNAL_INT_7](); 168 | } 169 | 170 | /* 171 | SIGNAL(SIG_2WIRE_SERIAL) { 172 | if(twiIntFunc) 173 | twiIntFunc(); 174 | } 175 | */ 176 | 177 | -------------------------------------------------------------------------------- /1.0/at90can/cores/at90can/WMath.cpp: -------------------------------------------------------------------------------- 1 | /* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2 | 3 | /* 4 | Part of the Wiring project - http://wiring.org.co 5 | Copyright (c) 2004-06 Hernando Barragan 6 | Modified 13 August 2006, David A. Mellis for Arduino - http://www.arduino.cc/ 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 2.1 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General 19 | Public License along with this library; if not, write to the 20 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 21 | Boston, MA 02111-1307 USA 22 | 23 | $Id$ 24 | */ 25 | 26 | extern "C" { 27 | #include "stdlib.h" 28 | } 29 | 30 | void randomSeed(unsigned int seed) 31 | { 32 | if (seed != 0) { 33 | srandom(seed); 34 | } 35 | } 36 | 37 | long random(long howbig) 38 | { 39 | if (howbig == 0) { 40 | return 0; 41 | } 42 | return random() % howbig; 43 | } 44 | 45 | long random(long howsmall, long howbig) 46 | { 47 | if (howsmall >= howbig) { 48 | return howsmall; 49 | } 50 | long diff = howbig - howsmall; 51 | return random(diff) + howsmall; 52 | } 53 | 54 | long map(long x, long in_min, long in_max, long out_min, long out_max) 55 | { 56 | return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; 57 | } 58 | 59 | unsigned int makeWord(unsigned int w) { return w; } 60 | unsigned int makeWord(unsigned char h, unsigned char l) { return (h << 8) | l; } -------------------------------------------------------------------------------- /1.0/at90can/cores/at90can/WString.h: -------------------------------------------------------------------------------- 1 | /* 2 | WString.h - String library for Wiring & Arduino 3 | ...mostly rewritten by Paul Stoffregen... 4 | Copyright (c) 2009-10 Hernando Barragan. All right reserved. 5 | Copyright 2011, Paul Stoffregen, paul@pjrc.com 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public 18 | License along with this library; if not, write to the Free Software 19 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #ifndef String_class_h 23 | #define String_class_h 24 | #ifdef __cplusplus 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | // When compiling programs with this class, the following gcc parameters 32 | // dramatically increase performance and memory (RAM) efficiency, typically 33 | // with little or no increase in code size. 34 | // -felide-constructors 35 | // -std=c++0x 36 | 37 | class __FlashStringHelper; 38 | #define F(string_literal) (reinterpret_cast<__FlashStringHelper *>(PSTR(string_literal))) 39 | 40 | // An inherited class for holding the result of a concatenation. These 41 | // result objects are assumed to be writable by subsequent concatenations. 42 | class StringSumHelper; 43 | 44 | // The string class 45 | class String 46 | { 47 | // use a function pointer to allow for "if (s)" without the 48 | // complications of an operator bool(). for more information, see: 49 | // http://www.artima.com/cppsource/safebool.html 50 | typedef void (String::*StringIfHelperType)() const; 51 | void StringIfHelper() const {} 52 | 53 | public: 54 | // constructors 55 | // creates a copy of the initial value. 56 | // if the initial value is null or invalid, or if memory allocation 57 | // fails, the string will be marked as invalid (i.e. "if (s)" will 58 | // be false). 59 | String(const char *cstr = ""); 60 | String(const String &str); 61 | #ifdef __GXX_EXPERIMENTAL_CXX0X__ 62 | String(String &&rval); 63 | String(StringSumHelper &&rval); 64 | #endif 65 | explicit String(char c); 66 | explicit String(unsigned char, unsigned char base=10); 67 | explicit String(int, unsigned char base=10); 68 | explicit String(unsigned int, unsigned char base=10); 69 | explicit String(long, unsigned char base=10); 70 | explicit String(unsigned long, unsigned char base=10); 71 | ~String(void); 72 | 73 | // memory management 74 | // return true on success, false on failure (in which case, the string 75 | // is left unchanged). reserve(0), if successful, will validate an 76 | // invalid string (i.e., "if (s)" will be true afterwards) 77 | unsigned char reserve(unsigned int size); 78 | inline unsigned int length(void) const {return len;} 79 | 80 | // creates a copy of the assigned value. if the value is null or 81 | // invalid, or if the memory allocation fails, the string will be 82 | // marked as invalid ("if (s)" will be false). 83 | String & operator = (const String &rhs); 84 | String & operator = (const char *cstr); 85 | #ifdef __GXX_EXPERIMENTAL_CXX0X__ 86 | String & operator = (String &&rval); 87 | String & operator = (StringSumHelper &&rval); 88 | #endif 89 | 90 | // concatenate (works w/ built-in types) 91 | 92 | // returns true on success, false on failure (in which case, the string 93 | // is left unchanged). if the argument is null or invalid, the 94 | // concatenation is considered unsucessful. 95 | unsigned char concat(const String &str); 96 | unsigned char concat(const char *cstr); 97 | unsigned char concat(char c); 98 | unsigned char concat(unsigned char c); 99 | unsigned char concat(int num); 100 | unsigned char concat(unsigned int num); 101 | unsigned char concat(long num); 102 | unsigned char concat(unsigned long num); 103 | 104 | // if there's not enough memory for the concatenated value, the string 105 | // will be left unchanged (but this isn't signalled in any way) 106 | String & operator += (const String &rhs) {concat(rhs); return (*this);} 107 | String & operator += (const char *cstr) {concat(cstr); return (*this);} 108 | String & operator += (char c) {concat(c); return (*this);} 109 | String & operator += (unsigned char num) {concat(num); return (*this);} 110 | String & operator += (int num) {concat(num); return (*this);} 111 | String & operator += (unsigned int num) {concat(num); return (*this);} 112 | String & operator += (long num) {concat(num); return (*this);} 113 | String & operator += (unsigned long num) {concat(num); return (*this);} 114 | 115 | friend StringSumHelper & operator + (const StringSumHelper &lhs, const String &rhs); 116 | friend StringSumHelper & operator + (const StringSumHelper &lhs, const char *cstr); 117 | friend StringSumHelper & operator + (const StringSumHelper &lhs, char c); 118 | friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned char num); 119 | friend StringSumHelper & operator + (const StringSumHelper &lhs, int num); 120 | friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned int num); 121 | friend StringSumHelper & operator + (const StringSumHelper &lhs, long num); 122 | friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned long num); 123 | 124 | // comparison (only works w/ Strings and "strings") 125 | operator StringIfHelperType() const { return buffer ? &String::StringIfHelper : 0; } 126 | int compareTo(const String &s) const; 127 | unsigned char equals(const String &s) const; 128 | unsigned char equals(const char *cstr) const; 129 | unsigned char operator == (const String &rhs) const {return equals(rhs);} 130 | unsigned char operator == (const char *cstr) const {return equals(cstr);} 131 | unsigned char operator != (const String &rhs) const {return !equals(rhs);} 132 | unsigned char operator != (const char *cstr) const {return !equals(cstr);} 133 | unsigned char operator < (const String &rhs) const; 134 | unsigned char operator > (const String &rhs) const; 135 | unsigned char operator <= (const String &rhs) const; 136 | unsigned char operator >= (const String &rhs) const; 137 | unsigned char equalsIgnoreCase(const String &s) const; 138 | unsigned char startsWith( const String &prefix) const; 139 | unsigned char startsWith(const String &prefix, unsigned int offset) const; 140 | unsigned char endsWith(const String &suffix) const; 141 | 142 | // character acccess 143 | char charAt(unsigned int index) const; 144 | void setCharAt(unsigned int index, char c); 145 | char operator [] (unsigned int index) const; 146 | char& operator [] (unsigned int index); 147 | void getBytes(unsigned char *buf, unsigned int bufsize, unsigned int index=0) const; 148 | void toCharArray(char *buf, unsigned int bufsize, unsigned int index=0) const 149 | {getBytes((unsigned char *)buf, bufsize, index);} 150 | 151 | // search 152 | int indexOf( char ch ) const; 153 | int indexOf( char ch, unsigned int fromIndex ) const; 154 | int indexOf( const String &str ) const; 155 | int indexOf( const String &str, unsigned int fromIndex ) const; 156 | int lastIndexOf( char ch ) const; 157 | int lastIndexOf( char ch, unsigned int fromIndex ) const; 158 | int lastIndexOf( const String &str ) const; 159 | int lastIndexOf( const String &str, unsigned int fromIndex ) const; 160 | String substring( unsigned int beginIndex ) const; 161 | String substring( unsigned int beginIndex, unsigned int endIndex ) const; 162 | 163 | // modification 164 | void replace(char find, char replace); 165 | void replace(const String& find, const String& replace); 166 | void toLowerCase(void); 167 | void toUpperCase(void); 168 | void trim(void); 169 | 170 | // parsing/conversion 171 | long toInt(void) const; 172 | 173 | protected: 174 | char *buffer; // the actual char array 175 | unsigned int capacity; // the array length minus one (for the '\0') 176 | unsigned int len; // the String length (not counting the '\0') 177 | unsigned char flags; // unused, for future features 178 | protected: 179 | void init(void); 180 | void invalidate(void); 181 | unsigned char changeBuffer(unsigned int maxStrLen); 182 | unsigned char concat(const char *cstr, unsigned int length); 183 | 184 | // copy and move 185 | String & copy(const char *cstr, unsigned int length); 186 | #ifdef __GXX_EXPERIMENTAL_CXX0X__ 187 | void move(String &rhs); 188 | #endif 189 | }; 190 | 191 | class StringSumHelper : public String 192 | { 193 | public: 194 | StringSumHelper(const String &s) : String(s) {} 195 | StringSumHelper(const char *p) : String(p) {} 196 | StringSumHelper(char c) : String(c) {} 197 | StringSumHelper(unsigned char num) : String(num) {} 198 | StringSumHelper(int num) : String(num) {} 199 | StringSumHelper(unsigned int num) : String(num) {} 200 | StringSumHelper(long num) : String(num) {} 201 | StringSumHelper(unsigned long num) : String(num) {} 202 | }; 203 | 204 | #endif // __cplusplus 205 | #endif // String_class_h 206 | -------------------------------------------------------------------------------- /1.0/at90can/cores/at90can/binary.h: -------------------------------------------------------------------------------- 1 | #ifndef Binary_h 2 | #define Binary_h 3 | 4 | #define B0 0 5 | #define B00 0 6 | #define B000 0 7 | #define B0000 0 8 | #define B00000 0 9 | #define B000000 0 10 | #define B0000000 0 11 | #define B00000000 0 12 | #define B1 1 13 | #define B01 1 14 | #define B001 1 15 | #define B0001 1 16 | #define B00001 1 17 | #define B000001 1 18 | #define B0000001 1 19 | #define B00000001 1 20 | #define B10 2 21 | #define B010 2 22 | #define B0010 2 23 | #define B00010 2 24 | #define B000010 2 25 | #define B0000010 2 26 | #define B00000010 2 27 | #define B11 3 28 | #define B011 3 29 | #define B0011 3 30 | #define B00011 3 31 | #define B000011 3 32 | #define B0000011 3 33 | #define B00000011 3 34 | #define B100 4 35 | #define B0100 4 36 | #define B00100 4 37 | #define B000100 4 38 | #define B0000100 4 39 | #define B00000100 4 40 | #define B101 5 41 | #define B0101 5 42 | #define B00101 5 43 | #define B000101 5 44 | #define B0000101 5 45 | #define B00000101 5 46 | #define B110 6 47 | #define B0110 6 48 | #define B00110 6 49 | #define B000110 6 50 | #define B0000110 6 51 | #define B00000110 6 52 | #define B111 7 53 | #define B0111 7 54 | #define B00111 7 55 | #define B000111 7 56 | #define B0000111 7 57 | #define B00000111 7 58 | #define B1000 8 59 | #define B01000 8 60 | #define B001000 8 61 | #define B0001000 8 62 | #define B00001000 8 63 | #define B1001 9 64 | #define B01001 9 65 | #define B001001 9 66 | #define B0001001 9 67 | #define B00001001 9 68 | #define B1010 10 69 | #define B01010 10 70 | #define B001010 10 71 | #define B0001010 10 72 | #define B00001010 10 73 | #define B1011 11 74 | #define B01011 11 75 | #define B001011 11 76 | #define B0001011 11 77 | #define B00001011 11 78 | #define B1100 12 79 | #define B01100 12 80 | #define B001100 12 81 | #define B0001100 12 82 | #define B00001100 12 83 | #define B1101 13 84 | #define B01101 13 85 | #define B001101 13 86 | #define B0001101 13 87 | #define B00001101 13 88 | #define B1110 14 89 | #define B01110 14 90 | #define B001110 14 91 | #define B0001110 14 92 | #define B00001110 14 93 | #define B1111 15 94 | #define B01111 15 95 | #define B001111 15 96 | #define B0001111 15 97 | #define B00001111 15 98 | #define B10000 16 99 | #define B010000 16 100 | #define B0010000 16 101 | #define B00010000 16 102 | #define B10001 17 103 | #define B010001 17 104 | #define B0010001 17 105 | #define B00010001 17 106 | #define B10010 18 107 | #define B010010 18 108 | #define B0010010 18 109 | #define B00010010 18 110 | #define B10011 19 111 | #define B010011 19 112 | #define B0010011 19 113 | #define B00010011 19 114 | #define B10100 20 115 | #define B010100 20 116 | #define B0010100 20 117 | #define B00010100 20 118 | #define B10101 21 119 | #define B010101 21 120 | #define B0010101 21 121 | #define B00010101 21 122 | #define B10110 22 123 | #define B010110 22 124 | #define B0010110 22 125 | #define B00010110 22 126 | #define B10111 23 127 | #define B010111 23 128 | #define B0010111 23 129 | #define B00010111 23 130 | #define B11000 24 131 | #define B011000 24 132 | #define B0011000 24 133 | #define B00011000 24 134 | #define B11001 25 135 | #define B011001 25 136 | #define B0011001 25 137 | #define B00011001 25 138 | #define B11010 26 139 | #define B011010 26 140 | #define B0011010 26 141 | #define B00011010 26 142 | #define B11011 27 143 | #define B011011 27 144 | #define B0011011 27 145 | #define B00011011 27 146 | #define B11100 28 147 | #define B011100 28 148 | #define B0011100 28 149 | #define B00011100 28 150 | #define B11101 29 151 | #define B011101 29 152 | #define B0011101 29 153 | #define B00011101 29 154 | #define B11110 30 155 | #define B011110 30 156 | #define B0011110 30 157 | #define B00011110 30 158 | #define B11111 31 159 | #define B011111 31 160 | #define B0011111 31 161 | #define B00011111 31 162 | #define B100000 32 163 | #define B0100000 32 164 | #define B00100000 32 165 | #define B100001 33 166 | #define B0100001 33 167 | #define B00100001 33 168 | #define B100010 34 169 | #define B0100010 34 170 | #define B00100010 34 171 | #define B100011 35 172 | #define B0100011 35 173 | #define B00100011 35 174 | #define B100100 36 175 | #define B0100100 36 176 | #define B00100100 36 177 | #define B100101 37 178 | #define B0100101 37 179 | #define B00100101 37 180 | #define B100110 38 181 | #define B0100110 38 182 | #define B00100110 38 183 | #define B100111 39 184 | #define B0100111 39 185 | #define B00100111 39 186 | #define B101000 40 187 | #define B0101000 40 188 | #define B00101000 40 189 | #define B101001 41 190 | #define B0101001 41 191 | #define B00101001 41 192 | #define B101010 42 193 | #define B0101010 42 194 | #define B00101010 42 195 | #define B101011 43 196 | #define B0101011 43 197 | #define B00101011 43 198 | #define B101100 44 199 | #define B0101100 44 200 | #define B00101100 44 201 | #define B101101 45 202 | #define B0101101 45 203 | #define B00101101 45 204 | #define B101110 46 205 | #define B0101110 46 206 | #define B00101110 46 207 | #define B101111 47 208 | #define B0101111 47 209 | #define B00101111 47 210 | #define B110000 48 211 | #define B0110000 48 212 | #define B00110000 48 213 | #define B110001 49 214 | #define B0110001 49 215 | #define B00110001 49 216 | #define B110010 50 217 | #define B0110010 50 218 | #define B00110010 50 219 | #define B110011 51 220 | #define B0110011 51 221 | #define B00110011 51 222 | #define B110100 52 223 | #define B0110100 52 224 | #define B00110100 52 225 | #define B110101 53 226 | #define B0110101 53 227 | #define B00110101 53 228 | #define B110110 54 229 | #define B0110110 54 230 | #define B00110110 54 231 | #define B110111 55 232 | #define B0110111 55 233 | #define B00110111 55 234 | #define B111000 56 235 | #define B0111000 56 236 | #define B00111000 56 237 | #define B111001 57 238 | #define B0111001 57 239 | #define B00111001 57 240 | #define B111010 58 241 | #define B0111010 58 242 | #define B00111010 58 243 | #define B111011 59 244 | #define B0111011 59 245 | #define B00111011 59 246 | #define B111100 60 247 | #define B0111100 60 248 | #define B00111100 60 249 | #define B111101 61 250 | #define B0111101 61 251 | #define B00111101 61 252 | #define B111110 62 253 | #define B0111110 62 254 | #define B00111110 62 255 | #define B111111 63 256 | #define B0111111 63 257 | #define B00111111 63 258 | #define B1000000 64 259 | #define B01000000 64 260 | #define B1000001 65 261 | #define B01000001 65 262 | #define B1000010 66 263 | #define B01000010 66 264 | #define B1000011 67 265 | #define B01000011 67 266 | #define B1000100 68 267 | #define B01000100 68 268 | #define B1000101 69 269 | #define B01000101 69 270 | #define B1000110 70 271 | #define B01000110 70 272 | #define B1000111 71 273 | #define B01000111 71 274 | #define B1001000 72 275 | #define B01001000 72 276 | #define B1001001 73 277 | #define B01001001 73 278 | #define B1001010 74 279 | #define B01001010 74 280 | #define B1001011 75 281 | #define B01001011 75 282 | #define B1001100 76 283 | #define B01001100 76 284 | #define B1001101 77 285 | #define B01001101 77 286 | #define B1001110 78 287 | #define B01001110 78 288 | #define B1001111 79 289 | #define B01001111 79 290 | #define B1010000 80 291 | #define B01010000 80 292 | #define B1010001 81 293 | #define B01010001 81 294 | #define B1010010 82 295 | #define B01010010 82 296 | #define B1010011 83 297 | #define B01010011 83 298 | #define B1010100 84 299 | #define B01010100 84 300 | #define B1010101 85 301 | #define B01010101 85 302 | #define B1010110 86 303 | #define B01010110 86 304 | #define B1010111 87 305 | #define B01010111 87 306 | #define B1011000 88 307 | #define B01011000 88 308 | #define B1011001 89 309 | #define B01011001 89 310 | #define B1011010 90 311 | #define B01011010 90 312 | #define B1011011 91 313 | #define B01011011 91 314 | #define B1011100 92 315 | #define B01011100 92 316 | #define B1011101 93 317 | #define B01011101 93 318 | #define B1011110 94 319 | #define B01011110 94 320 | #define B1011111 95 321 | #define B01011111 95 322 | #define B1100000 96 323 | #define B01100000 96 324 | #define B1100001 97 325 | #define B01100001 97 326 | #define B1100010 98 327 | #define B01100010 98 328 | #define B1100011 99 329 | #define B01100011 99 330 | #define B1100100 100 331 | #define B01100100 100 332 | #define B1100101 101 333 | #define B01100101 101 334 | #define B1100110 102 335 | #define B01100110 102 336 | #define B1100111 103 337 | #define B01100111 103 338 | #define B1101000 104 339 | #define B01101000 104 340 | #define B1101001 105 341 | #define B01101001 105 342 | #define B1101010 106 343 | #define B01101010 106 344 | #define B1101011 107 345 | #define B01101011 107 346 | #define B1101100 108 347 | #define B01101100 108 348 | #define B1101101 109 349 | #define B01101101 109 350 | #define B1101110 110 351 | #define B01101110 110 352 | #define B1101111 111 353 | #define B01101111 111 354 | #define B1110000 112 355 | #define B01110000 112 356 | #define B1110001 113 357 | #define B01110001 113 358 | #define B1110010 114 359 | #define B01110010 114 360 | #define B1110011 115 361 | #define B01110011 115 362 | #define B1110100 116 363 | #define B01110100 116 364 | #define B1110101 117 365 | #define B01110101 117 366 | #define B1110110 118 367 | #define B01110110 118 368 | #define B1110111 119 369 | #define B01110111 119 370 | #define B1111000 120 371 | #define B01111000 120 372 | #define B1111001 121 373 | #define B01111001 121 374 | #define B1111010 122 375 | #define B01111010 122 376 | #define B1111011 123 377 | #define B01111011 123 378 | #define B1111100 124 379 | #define B01111100 124 380 | #define B1111101 125 381 | #define B01111101 125 382 | #define B1111110 126 383 | #define B01111110 126 384 | #define B1111111 127 385 | #define B01111111 127 386 | #define B10000000 128 387 | #define B10000001 129 388 | #define B10000010 130 389 | #define B10000011 131 390 | #define B10000100 132 391 | #define B10000101 133 392 | #define B10000110 134 393 | #define B10000111 135 394 | #define B10001000 136 395 | #define B10001001 137 396 | #define B10001010 138 397 | #define B10001011 139 398 | #define B10001100 140 399 | #define B10001101 141 400 | #define B10001110 142 401 | #define B10001111 143 402 | #define B10010000 144 403 | #define B10010001 145 404 | #define B10010010 146 405 | #define B10010011 147 406 | #define B10010100 148 407 | #define B10010101 149 408 | #define B10010110 150 409 | #define B10010111 151 410 | #define B10011000 152 411 | #define B10011001 153 412 | #define B10011010 154 413 | #define B10011011 155 414 | #define B10011100 156 415 | #define B10011101 157 416 | #define B10011110 158 417 | #define B10011111 159 418 | #define B10100000 160 419 | #define B10100001 161 420 | #define B10100010 162 421 | #define B10100011 163 422 | #define B10100100 164 423 | #define B10100101 165 424 | #define B10100110 166 425 | #define B10100111 167 426 | #define B10101000 168 427 | #define B10101001 169 428 | #define B10101010 170 429 | #define B10101011 171 430 | #define B10101100 172 431 | #define B10101101 173 432 | #define B10101110 174 433 | #define B10101111 175 434 | #define B10110000 176 435 | #define B10110001 177 436 | #define B10110010 178 437 | #define B10110011 179 438 | #define B10110100 180 439 | #define B10110101 181 440 | #define B10110110 182 441 | #define B10110111 183 442 | #define B10111000 184 443 | #define B10111001 185 444 | #define B10111010 186 445 | #define B10111011 187 446 | #define B10111100 188 447 | #define B10111101 189 448 | #define B10111110 190 449 | #define B10111111 191 450 | #define B11000000 192 451 | #define B11000001 193 452 | #define B11000010 194 453 | #define B11000011 195 454 | #define B11000100 196 455 | #define B11000101 197 456 | #define B11000110 198 457 | #define B11000111 199 458 | #define B11001000 200 459 | #define B11001001 201 460 | #define B11001010 202 461 | #define B11001011 203 462 | #define B11001100 204 463 | #define B11001101 205 464 | #define B11001110 206 465 | #define B11001111 207 466 | #define B11010000 208 467 | #define B11010001 209 468 | #define B11010010 210 469 | #define B11010011 211 470 | #define B11010100 212 471 | #define B11010101 213 472 | #define B11010110 214 473 | #define B11010111 215 474 | #define B11011000 216 475 | #define B11011001 217 476 | #define B11011010 218 477 | #define B11011011 219 478 | #define B11011100 220 479 | #define B11011101 221 480 | #define B11011110 222 481 | #define B11011111 223 482 | #define B11100000 224 483 | #define B11100001 225 484 | #define B11100010 226 485 | #define B11100011 227 486 | #define B11100100 228 487 | #define B11100101 229 488 | #define B11100110 230 489 | #define B11100111 231 490 | #define B11101000 232 491 | #define B11101001 233 492 | #define B11101010 234 493 | #define B11101011 235 494 | #define B11101100 236 495 | #define B11101101 237 496 | #define B11101110 238 497 | #define B11101111 239 498 | #define B11110000 240 499 | #define B11110001 241 500 | #define B11110010 242 501 | #define B11110011 243 502 | #define B11110100 244 503 | #define B11110101 245 504 | #define B11110110 246 505 | #define B11110111 247 506 | #define B11111000 248 507 | #define B11111001 249 508 | #define B11111010 250 509 | #define B11111011 251 510 | #define B11111100 252 511 | #define B11111101 253 512 | #define B11111110 254 513 | #define B11111111 255 514 | 515 | #endif 516 | -------------------------------------------------------------------------------- /1.0/at90can/cores/at90can/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | init(); 6 | 7 | setup(); 8 | 9 | for (;;) 10 | loop(); 11 | 12 | return 0; 13 | } 14 | 15 | -------------------------------------------------------------------------------- /1.0/at90can/cores/at90can/new.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void * operator new(size_t size) 4 | { 5 | return malloc(size); 6 | } 7 | 8 | void operator delete(void * ptr) 9 | { 10 | free(ptr); 11 | } 12 | 13 | int __cxa_guard_acquire(__guard *g) {return !*(char *)(g);}; 14 | void __cxa_guard_release (__guard *g) {*(char *)g = 1;}; 15 | void __cxa_guard_abort (__guard *) {}; 16 | 17 | void __cxa_pure_virtual(void) {}; 18 | 19 | -------------------------------------------------------------------------------- /1.0/at90can/cores/at90can/new.h: -------------------------------------------------------------------------------- 1 | /* Header to define new/delete operators as they aren't provided by avr-gcc by default 2 | Taken from http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=59453 3 | */ 4 | 5 | #ifndef NEW_H 6 | #define NEW_H 7 | 8 | #include 9 | 10 | void * operator new(size_t size); 11 | void operator delete(void * ptr); 12 | 13 | __extension__ typedef int __guard __attribute__((mode (__DI__))); 14 | 15 | extern "C" int __cxa_guard_acquire(__guard *); 16 | extern "C" void __cxa_guard_release (__guard *); 17 | extern "C" void __cxa_guard_abort (__guard *); 18 | 19 | extern "C" void __cxa_pure_virtual(void); 20 | 21 | #endif 22 | 23 | -------------------------------------------------------------------------------- /1.0/at90can/cores/at90can/pins_arduino.c: -------------------------------------------------------------------------------- 1 | /* 2 | pins_arduino.c - pin definitions for the Arduino board 3 | Part of Arduino / Wiring Lite 4 | 5 | Copyright (c) 2005 David A. Mellis 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | 22 | $Id: pins_arduino.c 565 2009-03-25 10:50:00Z dmellis $ 23 | */ 24 | 25 | #include 26 | #include "wiring_private.h" 27 | #include "pins_arduino.h" 28 | 29 | // On the Arduino board, digital pins are also used 30 | // for the analog output (software PWM). Analog input 31 | // pins are a separate set. 32 | 33 | 34 | #define PA 1 35 | #define PB 2 36 | #define PC 3 37 | #define PD 4 38 | #define PE 5 39 | #define PF 6 40 | #define PG 7 41 | 42 | 43 | #define REPEAT8(x) x, x, x, x, x, x, x, x 44 | #define BV0TO7 _BV(0), _BV(1), _BV(2), _BV(3), _BV(4), _BV(5), _BV(6), _BV(7) 45 | #define BV7TO0 _BV(7), _BV(6), _BV(5), _BV(4), _BV(3), _BV(2), _BV(1), _BV(0) 46 | 47 | const uint16_t PROGMEM port_to_mode_PGM[] = { 48 | NOT_A_PORT, 49 | &DDRA, 50 | &DDRB, 51 | &DDRC, 52 | &DDRD, 53 | &DDRE, 54 | &DDRF, 55 | &DDRG, 56 | }; 57 | 58 | const uint16_t PROGMEM port_to_output_PGM[] = { 59 | NOT_A_PORT, 60 | &PORTA, 61 | &PORTB, 62 | &PORTC, 63 | &PORTD, 64 | &PORTE, 65 | &PORTF, 66 | &PORTG, 67 | }; 68 | 69 | const uint16_t PROGMEM port_to_input_PGM[] = { 70 | NOT_A_PIN, 71 | &PINA, 72 | &PINB, 73 | &PINC, 74 | &PIND, 75 | &PINE, 76 | &PINF, 77 | &PING, 78 | }; 79 | 80 | const uint8_t PROGMEM digital_pin_to_port_PGM[] = { 81 | PA, /* PORT A D0*/ 82 | PA, 83 | PA, 84 | PA, 85 | PA, 86 | PA, 87 | PA, 88 | PA, 89 | PB, /* PORT B D8*/ 90 | PB, 91 | PB, 92 | PB, 93 | PB, 94 | PB, 95 | PB, 96 | PB, 97 | PC, /* PORT C D16*/ 98 | PC, 99 | PC, 100 | PC, 101 | PC, 102 | PC, 103 | PC, 104 | PC, 105 | PD, /* PORT D D24*/ 106 | PD, 107 | PD, 108 | PD, 109 | PD, 110 | PD, 111 | PD, 112 | PD, 113 | PE, /* PORT E D32*/ 114 | PE, 115 | PE, 116 | PE, 117 | PE, 118 | PE, 119 | PE, 120 | PE, 121 | PG, /* PORT G D40*/ 122 | PG, 123 | PG, 124 | PG, 125 | PG, 126 | PF, /* PORT F D45*/ 127 | PF, 128 | PF, 129 | PF, 130 | }; 131 | 132 | const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = { 133 | _BV(0), /* 0 PORT A */ 134 | _BV(1), 135 | _BV(2), 136 | _BV(3), 137 | _BV(4), 138 | _BV(5), 139 | _BV(6), 140 | _BV(7), 141 | _BV(0), /* 8 PORT B */ 142 | _BV(1), 143 | _BV(2), 144 | _BV(3), 145 | _BV(4), 146 | _BV(5), 147 | _BV(6), 148 | _BV(7), 149 | _BV(0), /* 16 PORT C */ 150 | _BV(1), 151 | _BV(2), 152 | _BV(3), 153 | _BV(4), 154 | _BV(5), 155 | _BV(6), 156 | _BV(7), 157 | _BV(0), /* 24 PORT D */ 158 | _BV(1), 159 | _BV(2), 160 | _BV(3), 161 | _BV(4), 162 | _BV(5), 163 | _BV(6), 164 | _BV(7), 165 | _BV(0), /* 32 PORT E */ 166 | _BV(1), 167 | _BV(2), 168 | _BV(3), 169 | _BV(4), 170 | _BV(5), 171 | _BV(6), 172 | _BV(7), 173 | _BV(0), /* 40 PORT G */ 174 | _BV(1), 175 | _BV(2), 176 | _BV(3), 177 | _BV(4), 178 | _BV(0), /* 45 PORT F ANALOOG*/ 179 | _BV(1), 180 | _BV(2), 181 | _BV(3), 182 | }; 183 | 184 | const uint8_t PROGMEM digital_pin_to_timer_PGM[] = { 185 | NOT_ON_TIMER, /* 0 PORT A */ 186 | NOT_ON_TIMER, 187 | NOT_ON_TIMER, 188 | NOT_ON_TIMER, 189 | NOT_ON_TIMER, 190 | NOT_ON_TIMER, 191 | NOT_ON_TIMER, 192 | NOT_ON_TIMER, 193 | NOT_ON_TIMER, /* 8 PORT B */ 194 | NOT_ON_TIMER, 195 | NOT_ON_TIMER, 196 | NOT_ON_TIMER, 197 | TIMER2A, // 12 198 | TIMER1A, // 13 199 | TIMER1B, // 14 200 | TIMER1C, // 15 201 | NOT_ON_TIMER, /* 16 PORT C */ 202 | NOT_ON_TIMER, 203 | NOT_ON_TIMER, 204 | NOT_ON_TIMER, 205 | NOT_ON_TIMER, 206 | NOT_ON_TIMER, 207 | NOT_ON_TIMER, 208 | NOT_ON_TIMER, 209 | NOT_ON_TIMER, /* 24 PORT D */ 210 | NOT_ON_TIMER, 211 | NOT_ON_TIMER, 212 | NOT_ON_TIMER, 213 | NOT_ON_TIMER, 214 | NOT_ON_TIMER, 215 | NOT_ON_TIMER, 216 | NOT_ON_TIMER, 217 | NOT_ON_TIMER, /* 32 PORT E */ 218 | NOT_ON_TIMER, 219 | NOT_ON_TIMER, 220 | TIMER3A, // 35 221 | TIMER3B, // 36 222 | TIMER3C, // 37 223 | NOT_ON_TIMER, 224 | NOT_ON_TIMER, 225 | NOT_ON_TIMER, /* PORT G */ 226 | NOT_ON_TIMER, 227 | NOT_ON_TIMER, 228 | NOT_ON_TIMER, 229 | NOT_ON_TIMER, 230 | NOT_ON_TIMER, /* PORT F */ 231 | NOT_ON_TIMER, 232 | NOT_ON_TIMER, 233 | NOT_ON_TIMER, 234 | }; 235 | -------------------------------------------------------------------------------- /1.0/at90can/cores/at90can/pins_arduino.h: -------------------------------------------------------------------------------- 1 | /* 2 | pins_arduino.h - Pin definition functions for Arduino 3 | Part of Arduino - http://www.arduino.cc/ 4 | 5 | Copyright (c) 2007 David A. Mellis 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | 22 | $Id: wiring.h 249 2007-02-03 16:52:51Z mellis $ 23 | */ 24 | 25 | #ifndef Pins_Arduino_h 26 | #define Pins_Arduino_h 27 | 28 | #include 29 | 30 | #define NOT_A_PIN 0 31 | #define NOT_A_PORT 0 32 | 33 | #define NOT_ON_TIMER 0 34 | #define TIMER0A 1 35 | #define TIMER1A 2 36 | #define TIMER1B 3 37 | #define TIMER1C 4 38 | #define TIMER2A 5 39 | #define TIMER3A 6 40 | #define TIMER3B 7 41 | #define TIMER3C 8 42 | 43 | 44 | const static uint8_t SS = 8; // PB0 45 | const static uint8_t MOSI = 10; // PB2 46 | const static uint8_t MISO = 11; // PB3 47 | const static uint8_t SCK = 9; // PB1 48 | 49 | static const uint8_t SDA = 25; // PD1 50 | static const uint8_t SCL = 24; // PD0 51 | 52 | // On the ATmega1280, the addresses of some of the port registers are 53 | // greater than 255, so we can't store them in uint8_t's. 54 | extern const uint16_t PROGMEM port_to_mode_PGM[]; 55 | extern const uint16_t PROGMEM port_to_input_PGM[]; 56 | extern const uint16_t PROGMEM port_to_output_PGM[]; 57 | 58 | extern const uint8_t PROGMEM digital_pin_to_port_PGM[]; 59 | // extern const uint8_t PROGMEM digital_pin_to_bit_PGM[]; 60 | extern const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[]; 61 | extern const uint8_t PROGMEM digital_pin_to_timer_PGM[]; 62 | 63 | // Get the bit location within the hardware port of the given virtual pin. 64 | // This comes from the pins_*.c file for the active board configuration. 65 | // 66 | // These perform slightly better as macros compared to inline functions 67 | // 68 | #define digitalPinToPort(P) ( pgm_read_byte( digital_pin_to_port_PGM + (P) ) ) 69 | #define digitalPinToBitMask(P) ( pgm_read_byte( digital_pin_to_bit_mask_PGM + (P) ) ) 70 | #define digitalPinToTimer(P) ( pgm_read_byte( digital_pin_to_timer_PGM + (P) ) ) 71 | #define analogInPinToBit(P) (P) 72 | #define portOutputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_output_PGM + (P))) ) 73 | #define portInputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_input_PGM + (P))) ) 74 | #define portModeRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_mode_PGM + (P))) ) 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /1.0/at90can/cores/at90can/wiring.c: -------------------------------------------------------------------------------- 1 | /* 2 | wiring.c - Partial implementation of the Wiring API for the ATmega8. 3 | Part of Arduino - http://www.arduino.cc/ 4 | 5 | Copyright (c) 2005-2006 David A. Mellis 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | 22 | $Id: wiring.c 585 2009-05-12 10:55:26Z dmellis $ 23 | */ 24 | 25 | #include "wiring_private.h" 26 | 27 | // the prescaler is set so that timer0 ticks every 64 clock cycles, and the 28 | // the overflow handler is called every 256 ticks. 29 | #define MICROSECONDS_PER_TIMER0_OVERFLOW (clockCyclesToMicroseconds(64 * 256)) 30 | 31 | // the whole number of milliseconds per timer0 overflow 32 | #define MILLIS_INC (MICROSECONDS_PER_TIMER0_OVERFLOW / 1000) 33 | 34 | // the fractional number of milliseconds per timer0 overflow. we shift right 35 | // by three to fit these numbers into a byte. (for the clock speeds we care 36 | // about - 8 and 16 MHz - this doesn't lose precision.) 37 | #define FRACT_INC ((MICROSECONDS_PER_TIMER0_OVERFLOW % 1000) >> 3) 38 | #define FRACT_MAX (1000 >> 3) 39 | 40 | volatile unsigned long timer0_overflow_count = 0; 41 | volatile unsigned long timer0_millis = 0; 42 | static unsigned char timer0_fract = 0; 43 | 44 | SIGNAL(TIMER0_OVF_vect) 45 | { 46 | // copy these to local variables so they can be stored in registers 47 | // (volatile variables must be read from memory on every access) 48 | unsigned long m = timer0_millis; 49 | unsigned char f = timer0_fract; 50 | 51 | m += MILLIS_INC; 52 | f += FRACT_INC; 53 | if (f >= FRACT_MAX) { 54 | f -= FRACT_MAX; 55 | m += 1; 56 | } 57 | 58 | timer0_fract = f; 59 | timer0_millis = m; 60 | timer0_overflow_count++; 61 | } 62 | 63 | unsigned long millis() 64 | { 65 | unsigned long m; 66 | uint8_t oldSREG = SREG; 67 | 68 | // disable interrupts while we read timer0_millis or we might get an 69 | // inconsistent value (e.g. in the middle of a write to timer0_millis) 70 | cli(); 71 | m = timer0_millis; 72 | SREG = oldSREG; 73 | 74 | return m; 75 | } 76 | 77 | unsigned long micros() { 78 | unsigned long m, t; 79 | uint8_t oldSREG = SREG; 80 | 81 | cli(); 82 | t = TCNT0; 83 | 84 | #ifdef TIFR0 85 | if ((TIFR0 & _BV(TOV0)) && (t == 0)) 86 | t = 256; 87 | #else 88 | if ((TIFR & _BV(TOV0)) && (t == 0)) 89 | t = 256; 90 | #endif 91 | 92 | m = timer0_overflow_count; 93 | SREG = oldSREG; 94 | 95 | return ((m << 8) + t) * (64 / clockCyclesPerMicrosecond()); 96 | } 97 | 98 | void delay(unsigned long ms) 99 | { 100 | unsigned long start = millis(); 101 | 102 | while (millis() - start <= ms) 103 | ; 104 | } 105 | 106 | /* Delay for the given number of microseconds. Assumes a 8 or 16 MHz clock. 107 | * Disables interrupts, which will disrupt the millis() function if used 108 | * too frequently. */ 109 | void delayMicroseconds(unsigned int us) 110 | { 111 | uint8_t oldSREG; 112 | 113 | // calling avrlib's delay_us() function with low values (e.g. 1 or 114 | // 2 microseconds) gives delays longer than desired. 115 | //delay_us(us); 116 | 117 | #if F_CPU >= 16000000L 118 | // for the 16 MHz clock on most Arduino boards 119 | 120 | // for a one-microsecond delay, simply return. the overhead 121 | // of the function call yields a delay of approximately 1 1/8 us. 122 | if (--us == 0) 123 | return; 124 | 125 | // the following loop takes a quarter of a microsecond (4 cycles) 126 | // per iteration, so execute it four times for each microsecond of 127 | // delay requested. 128 | us <<= 2; 129 | 130 | // account for the time taken in the preceeding commands. 131 | us -= 2; 132 | #else 133 | // for the 8 MHz internal clock on the ATmega168 134 | 135 | // for a one- or two-microsecond delay, simply return. the overhead of 136 | // the function calls takes more than two microseconds. can't just 137 | // subtract two, since us is unsigned; we'd overflow. 138 | if (--us == 0) 139 | return; 140 | if (--us == 0) 141 | return; 142 | 143 | // the following loop takes half of a microsecond (4 cycles) 144 | // per iteration, so execute it twice for each microsecond of 145 | // delay requested. 146 | us <<= 1; 147 | 148 | // partially compensate for the time taken by the preceeding commands. 149 | // we can't subtract any more than this or we'd overflow w/ small delays. 150 | us--; 151 | #endif 152 | 153 | // disable interrupts, otherwise the timer 0 overflow interrupt that 154 | // tracks milliseconds will make us delay longer than we want. 155 | oldSREG = SREG; 156 | cli(); 157 | 158 | // busy wait 159 | __asm__ __volatile__ ( 160 | "1: sbiw %0,1" "\n\t" // 2 cycles 161 | "brne 1b" : "=w" (us) : "0" (us) // 2 cycles 162 | ); 163 | 164 | // reenable interrupts. 165 | SREG = oldSREG; 166 | } 167 | 168 | void init() 169 | { 170 | // this needs to be called before setup() or some functions won't 171 | // work there 172 | sei(); 173 | 174 | // on the ATmega168, timer 0 is also used for fast hardware pwm 175 | // (using phase-correct PWM would mean that timer 0 overflowed half as often 176 | // resulting in different millis() behavior on the ATmega8 and ATmega168) 177 | //8 bit timer 178 | sbi(TCCR0A, WGM01); 179 | sbi(TCCR0A, WGM00); 180 | 181 | // set timer 0 prescale factor to 64 182 | sbi(TCCR0A, CS01); 183 | sbi(TCCR0A, CS00); 184 | 185 | // enable timer 0 overflow interrupt 186 | sbi(TIMSK0, TOIE0); 187 | 188 | // timers 1, 2 and 3 are used for phase-correct hardware pwm 189 | // this is better for motors as it ensures an even waveform 190 | // note, however, that fast pwm mode can achieve a frequency of up 191 | // 8 MHz (with a 16 MHz clock) at 50% duty cycle 192 | 193 | // set timer 1 prescale factor to 64 194 | sbi(TCCR1B, CS11); 195 | sbi(TCCR1B, CS10); 196 | // put timer 1 in 8-bit phase correct pwm mode 197 | sbi(TCCR1A, WGM10); 198 | 199 | // set timer 1 prescale factor to 64 200 | sbi(TCCR3B, CS31); 201 | sbi(TCCR3B, CS30); 202 | // put timer 1 in 8-bit phase correct pwm mode 203 | sbi(TCCR3A, WGM30); 204 | 205 | // set timer 2 prescale factor to 64 206 | sbi(TCCR2A, CS22); 207 | // configure timer 2 for phase correct pwm (8-bit) 208 | sbi(TCCR2A, WGM20); 209 | 210 | 211 | // set a2d prescale factor to 128 212 | // 16 MHz / 128 = 125 KHz, inside the desired 50-200 KHz range. 213 | // XXX: this will not work properly for other clock speeds, and 214 | // this code should use F_CPU to determine the prescale factor. 215 | sbi(ADCSRA, ADPS2); 216 | sbi(ADCSRA, ADPS1); 217 | sbi(ADCSRA, ADPS0); 218 | 219 | // enable a2d conversions 220 | sbi(ADCSRA, ADEN); 221 | 222 | // the bootloader connects pins 0 and 1 to the USART; disconnect them 223 | // here so they can be used as normal digital i/o; they will be 224 | // reconnected in Serial.begin() 225 | UCSR0B = 0; 226 | } -------------------------------------------------------------------------------- /1.0/at90can/cores/at90can/wiring.h: -------------------------------------------------------------------------------- 1 | /* 2 | wiring.h - Partial implementation of the Wiring API for the ATmega8. 3 | Part of Arduino - http://www.arduino.cc/ 4 | 5 | Copyright (c) 2005-2006 David A. Mellis 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | 22 | $Id: wiring.h 602 2009-06-01 08:32:11Z dmellis $ 23 | */ 24 | 25 | #ifndef Wiring_h 26 | #define Wiring_h 27 | 28 | #include 29 | #include "binary.h" 30 | 31 | #ifdef __cplusplus 32 | extern "C"{ 33 | #endif 34 | 35 | #ifndef ARDUINO 36 | #define ARDUINO 16 37 | #endif 38 | 39 | #define HIGH 0x1 40 | #define LOW 0x0 41 | 42 | #define INPUT 0x0 43 | #define OUTPUT 0x1 44 | 45 | #define true 0x1 46 | #define false 0x0 47 | 48 | #define PI 3.1415926535897932384626433832795 49 | #define HALF_PI 1.5707963267948966192313216916398 50 | #define TWO_PI 6.283185307179586476925286766559 51 | #define DEG_TO_RAD 0.017453292519943295769236907684886 52 | #define RAD_TO_DEG 57.295779513082320876798154814105 53 | 54 | #define SERIAL 0x0 55 | #define DISPLAY 0x1 56 | 57 | #define LSBFIRST 0 58 | #define MSBFIRST 1 59 | 60 | #define CHANGE 1 61 | #define FALLING 2 62 | #define RISING 3 63 | 64 | #define INTERNAL 3 65 | #define DEFAULT 1 66 | #define EXTERNAL 0 67 | 68 | // undefine stdlib's abs if encountered 69 | #ifdef abs 70 | #undef abs 71 | #endif 72 | 73 | #define min(a,b) ((a)<(b)?(a):(b)) 74 | #define max(a,b) ((a)>(b)?(a):(b)) 75 | #define abs(x) ((x)>0?(x):-(x)) 76 | #define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt))) 77 | #define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5)) 78 | #define radians(deg) ((deg)*DEG_TO_RAD) 79 | #define degrees(rad) ((rad)*RAD_TO_DEG) 80 | #define sq(x) ((x)*(x)) 81 | 82 | #define interrupts() sei() 83 | #define noInterrupts() cli() 84 | 85 | #define clockCyclesPerMicrosecond() ( F_CPU / 1000000L ) 86 | #define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() ) 87 | #define microsecondsToClockCycles(a) ( (a) * clockCyclesPerMicrosecond() ) 88 | 89 | #define lowByte(w) ((uint8_t) ((w) & 0xff)) 90 | #define highByte(w) ((uint8_t) ((w) >> 8)) 91 | 92 | #define bitRead(value, bit) (((value) >> (bit)) & 0x01) 93 | #define bitSet(value, bit) ((value) |= (1UL << (bit))) 94 | #define bitClear(value, bit) ((value) &= ~(1UL << (bit))) 95 | #define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit)) 96 | 97 | typedef unsigned int word; 98 | 99 | #define bit(b) (1UL << (b)) 100 | 101 | typedef uint8_t boolean; 102 | typedef uint8_t byte; 103 | 104 | void init(void); 105 | 106 | void pinMode(uint8_t, uint8_t); 107 | void digitalWrite(uint8_t, uint8_t); 108 | int digitalRead(uint8_t); 109 | int analogRead(uint8_t); 110 | void analogReference(uint8_t mode); 111 | void analogWrite(uint8_t, int); 112 | 113 | void beginSerial(long); 114 | void serialWrite(unsigned char); 115 | int serialAvailable(void); 116 | int serialRead(void); 117 | void serialFlush(void); 118 | 119 | unsigned long millis(void); 120 | unsigned long micros(void); 121 | void delay(unsigned long); 122 | void delayMicroseconds(unsigned int us); 123 | unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout); 124 | 125 | void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, byte val); 126 | 127 | void attachInterrupt(uint8_t, void (*)(void), int mode); 128 | void detachInterrupt(uint8_t); 129 | 130 | void setup(void); 131 | void loop(void); 132 | 133 | #ifdef __cplusplus 134 | } // extern "C" 135 | #endif 136 | 137 | #endif 138 | -------------------------------------------------------------------------------- /1.0/at90can/cores/at90can/wiring_analog.c: -------------------------------------------------------------------------------- 1 | /* 2 | wiring_analog.c - analog input and output 3 | Part of Arduino - http://www.arduino.cc/ 4 | 5 | Copyright (c) 2005-2006 David A. Mellis 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | 22 | $Id: wiring.c 248 2007-02-03 15:36:30Z mellis $ 23 | */ 24 | 25 | #include "wiring_private.h" 26 | #include "pins_arduino.h" 27 | 28 | uint8_t analog_reference = DEFAULT; 29 | 30 | /*#define ABIT11 4 31 | #define ABIT12 16 32 | #define ABIT13 64 33 | #define ABIT14 256 34 | #define ABIT15 1024 35 | #define ABIT16 4096 36 | 37 | int analogRead(uint8_t pin, uint8_t sampleRate) 38 | { 39 | uint32_t samples = 0; 40 | uint8_t right_shift; 41 | for (uint8_t sample = 0; sample < sampleRate; sample++) 42 | { 43 | samples += analogRead(pin); 44 | } 45 | switch (sampleRate) 46 | { 47 | case ABIT11: right_shift = 1; break; 48 | case ABIT12: right_shift = 2; break; 49 | case ABIT13: right_shift = 3; break; 50 | case ABIT14: right_shift = 4; break; 51 | case ABIT15: right_shift = 5; break; 52 | case ABIT16: right_shift = 6; break; 53 | } 54 | return (samples >> right_shift) 55 | }*/ 56 | 57 | void analogReference(uint8_t mode) 58 | { 59 | // can't actually set the register here because the default setting 60 | // will connect AVCC and the AREF pin, which would cause a short if 61 | // there's something connected to AREF. 62 | analog_reference = mode; 63 | } 64 | 65 | int analogRead(uint8_t pin) 66 | { 67 | uint8_t low, high; 68 | 69 | if (pin > 3) 70 | return 0; 71 | 72 | // set the analog reference (high two bits of ADMUX) and select the 73 | // channel (low 4 bits). this also sets ADLAR (left-adjust result) 74 | // to 0 (the default). 75 | ADMUX = (analog_reference << 6) | (pin & 0xf); 76 | 77 | // without a delay, we seem to read from the wrong channel 78 | //delay(1); 79 | 80 | // start the conversion 81 | sbi(ADCSRA, ADSC); 82 | 83 | // ADSC is cleared when the conversion finishes 84 | while (bit_is_set(ADCSRA, ADSC)); 85 | 86 | // we have to read ADCL first; doing so locks both ADCL 87 | // and ADCH until ADCH is read. reading ADCL second would 88 | // cause the results of each conversion to be discarded, 89 | // as ADCL and ADCH would be locked when it completed. 90 | low = ADCL; 91 | high = ADCH; 92 | 93 | // combine the two bytes 94 | return (high << 8) | low; 95 | } 96 | 97 | // Right now, PWM output only works on the pins with 98 | // hardware support. These are defined in the appropriate 99 | // pins_*.c file. For the rest of the pins, we default 100 | // to digital output. 101 | void analogWrite(uint8_t pin, int val) 102 | { 103 | // We need to make sure the PWM output is enabled for those pins 104 | // that support it, as we turn it off when digitally reading or 105 | // writing with them. Also, make sure the pin is in output mode 106 | // for consistenty with Wiring, which doesn't require a pinMode 107 | // call for the analog output pins. 108 | pinMode(pin, OUTPUT); 109 | 110 | if (digitalPinToTimer(pin) == TIMER1A) { 111 | // connect pwm to pin on timer 1, channel A 112 | sbi(TCCR1A, COM1A1); 113 | // set pwm duty 114 | OCR1A = val; 115 | } else if (digitalPinToTimer(pin) == TIMER1B) { 116 | // connect pwm to pin on timer 1, channel B 117 | sbi(TCCR1A, COM1B1); 118 | // set pwm duty 119 | OCR1B = val; 120 | } else if (digitalPinToTimer(pin) == TIMER1C) { 121 | // connect pwm to pin on timer 1, channel B 122 | sbi(TCCR1A, COM1C1); 123 | // set pwm duty 124 | OCR1C = val; 125 | } else if (digitalPinToTimer(pin) == TIMER2A) { 126 | // connect pwm to pin on timer 2, channel A 127 | sbi(TCCR2A, COM2A1); 128 | // set pwm duty 129 | OCR2A = val; 130 | } else if (digitalPinToTimer(pin) == TIMER3A) { 131 | // connect pwm to pin on timer 3, channel A 132 | sbi(TCCR3A, COM3A1); 133 | // set pwm duty 134 | OCR3A = val; 135 | } else if (digitalPinToTimer(pin) == TIMER3B) { 136 | // connect pwm to pin on timer 3, channel B 137 | sbi(TCCR3A, COM3B1); 138 | // set pwm duty 139 | OCR3B = val; 140 | } else if (digitalPinToTimer(pin) == TIMER3C) { 141 | // connect pwm to pin on timer 3, channel C 142 | sbi(TCCR3A, COM3C1); 143 | // set pwm duty 144 | OCR3C = val; 145 | } else if (val < 128) 146 | digitalWrite(pin, LOW); 147 | else 148 | digitalWrite(pin, HIGH); 149 | } 150 | -------------------------------------------------------------------------------- /1.0/at90can/cores/at90can/wiring_digital.c: -------------------------------------------------------------------------------- 1 | /* 2 | wiring_digital.c - digital input and output functions 3 | Part of Arduino - http://www.arduino.cc/ 4 | 5 | Copyright (c) 2005-2006 David A. Mellis 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | 22 | $Id: wiring.c 248 2007-02-03 15:36:30Z mellis $ 23 | */ 24 | 25 | #include "wiring_private.h" 26 | #include "pins_arduino.h" 27 | 28 | void pinMode(uint8_t pin, uint8_t mode) 29 | { 30 | uint8_t bit = digitalPinToBitMask(pin); 31 | uint8_t port = digitalPinToPort(pin); 32 | volatile uint8_t *reg; 33 | 34 | if (port == NOT_A_PIN) return; 35 | 36 | // JWS: can I let the optimizer do this? 37 | reg = portModeRegister(port); 38 | 39 | if (mode == INPUT) *reg &= ~bit; 40 | else *reg |= bit; 41 | } 42 | 43 | // Forcing this inline keeps the callers from having to push their own stuff 44 | // on the stack. It is a good performance win and only takes 1 more byte per 45 | // user than calling. (It will take more bytes on the 168.) 46 | // 47 | // But shouldn't this be moved into pinMode? Seems silly to check and do on 48 | // each digitalread or write. 49 | // 50 | static inline void turnOffPWM(uint8_t timer) __attribute__ ((always_inline)); 51 | static inline void turnOffPWM(uint8_t timer) 52 | { 53 | if (timer == TIMER1A) cbi(TCCR1A, COM1A1); 54 | if (timer == TIMER1B) cbi(TCCR1A, COM1B1); 55 | if (timer == TIMER1C) cbi(TCCR1A, COM1C1); 56 | //if (timer == TIMER0A) cbi(TCCR0A, COM0A1); 57 | //if (timer == TIMER0B) cbi(TCCR0A, COM0B1); 58 | if (timer == TIMER2A) cbi(TCCR2A, COM2A1); 59 | if (timer == TIMER3A) cbi(TCCR3A, COM3A1); 60 | if (timer == TIMER3B) cbi(TCCR3A, COM3B1); 61 | if (timer == TIMER3C) cbi(TCCR3A, COM3C1); 62 | } 63 | 64 | void digitalWrite(uint8_t pin, uint8_t val) 65 | { 66 | uint8_t timer = digitalPinToTimer(pin); 67 | uint8_t bit = digitalPinToBitMask(pin); 68 | uint8_t port = digitalPinToPort(pin); 69 | volatile uint8_t *out; 70 | 71 | if (port == NOT_A_PIN) return; 72 | 73 | // If the pin that support PWM output, we need to turn it off 74 | // before doing a digital write. 75 | if (timer != NOT_ON_TIMER) turnOffPWM(timer); 76 | 77 | out = portOutputRegister(port); 78 | 79 | if (val == LOW) *out &= ~bit; 80 | else *out |= bit; 81 | } 82 | 83 | int digitalRead(uint8_t pin) 84 | { 85 | uint8_t timer = digitalPinToTimer(pin); 86 | uint8_t bit = digitalPinToBitMask(pin); 87 | uint8_t port = digitalPinToPort(pin); 88 | 89 | if (port == NOT_A_PIN) return LOW; 90 | 91 | // If the pin that support PWM output, we need to turn it off 92 | // before getting a digital reading. 93 | if (timer != NOT_ON_TIMER) turnOffPWM(timer); 94 | 95 | if (*portInputRegister(port) & bit) return HIGH; 96 | return LOW; 97 | } 98 | -------------------------------------------------------------------------------- /1.0/at90can/cores/at90can/wiring_private.h: -------------------------------------------------------------------------------- 1 | /* 2 | wiring_private.h - Internal header file. 3 | Part of Arduino - http://www.arduino.cc/ 4 | 5 | Copyright (c) 2005-2006 David A. Mellis 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | 22 | $Id: wiring.h 239 2007-01-12 17:58:39Z mellis $ 23 | */ 24 | 25 | #ifndef WiringPrivate_h 26 | #define WiringPrivate_h 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | #include "wiring.h" 35 | 36 | #ifdef __cplusplus 37 | extern "C"{ 38 | #endif 39 | 40 | #ifndef cbi 41 | #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit)) 42 | #endif 43 | #ifndef sbi 44 | #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit)) 45 | #endif 46 | 47 | #define EXTERNAL_INT_0 0 48 | #define EXTERNAL_INT_1 1 49 | #define EXTERNAL_INT_2 2 50 | #define EXTERNAL_INT_3 3 51 | #define EXTERNAL_INT_4 4 52 | #define EXTERNAL_INT_5 5 53 | #define EXTERNAL_INT_6 6 54 | #define EXTERNAL_INT_7 7 55 | 56 | 57 | #define EXTERNAL_NUM_INTERRUPTS 8 58 | 59 | 60 | typedef void (*voidFuncPtr)(void); 61 | 62 | #ifdef __cplusplus 63 | } // extern "C" 64 | #endif 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /1.0/at90can/cores/at90can/wiring_pulse.c: -------------------------------------------------------------------------------- 1 | /* 2 | wiring_pulse.c - pulseIn() function 3 | Part of Arduino - http://www.arduino.cc/ 4 | 5 | Copyright (c) 2005-2006 David A. Mellis 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | 22 | $Id: wiring.c 248 2007-02-03 15:36:30Z mellis $ 23 | */ 24 | 25 | #include "wiring_private.h" 26 | #include "pins_arduino.h" 27 | 28 | /* Measures the length (in microseconds) of a pulse on the pin; state is HIGH 29 | * or LOW, the type of pulse to measure. Works on pulses from 2-3 microseconds 30 | * to 3 minutes in length, but must be called at least a few dozen microseconds 31 | * before the start of the pulse. */ 32 | unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout) 33 | { 34 | // cache the port and bit of the pin in order to speed up the 35 | // pulse width measuring loop and achieve finer resolution. calling 36 | // digitalRead() instead yields much coarser resolution. 37 | uint8_t bit = digitalPinToBitMask(pin); 38 | uint8_t port = digitalPinToPort(pin); 39 | uint8_t stateMask = (state ? bit : 0); 40 | unsigned long width = 0; // keep initialization out of time critical area 41 | 42 | // convert the timeout from microseconds to a number of times through 43 | // the initial loop; it takes 16 clock cycles per iteration. 44 | unsigned long numloops = 0; 45 | unsigned long maxloops = microsecondsToClockCycles(timeout) / 16; 46 | 47 | // wait for any previous pulse to end 48 | while ((*portInputRegister(port) & bit) == stateMask) 49 | if (numloops++ == maxloops) 50 | return 0; 51 | 52 | // wait for the pulse to start 53 | while ((*portInputRegister(port) & bit) != stateMask) 54 | if (numloops++ == maxloops) 55 | return 0; 56 | 57 | // wait for the pulse to stop 58 | while ((*portInputRegister(port) & bit) == stateMask) 59 | width++; 60 | 61 | // convert the reading to microseconds. The loop has been determined 62 | // to be 10 clock cycles long and have about 16 clocks between the edge 63 | // and the start of the loop. There will be some error introduced by 64 | // the interrupt handlers. 65 | return clockCyclesToMicroseconds(width * 10 + 16); 66 | } 67 | -------------------------------------------------------------------------------- /1.0/at90can/cores/at90can/wiring_shift.c: -------------------------------------------------------------------------------- 1 | /* 2 | wiring_shift.c - shiftOut() function 3 | Part of Arduino - http://www.arduino.cc/ 4 | 5 | Copyright (c) 2005-2006 David A. Mellis 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | 22 | $Id: wiring.c 248 2007-02-03 15:36:30Z mellis $ 23 | */ 24 | 25 | #include "wiring_private.h" 26 | 27 | void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, byte val) 28 | { 29 | int i; 30 | 31 | for (i = 0; i < 8; i++) { 32 | if (bitOrder == LSBFIRST) 33 | digitalWrite(dataPin, !!(val & (1 << i))); 34 | else 35 | digitalWrite(dataPin, !!(val & (1 << (7 - i)))); 36 | 37 | digitalWrite(clockPin, HIGH); 38 | digitalWrite(clockPin, LOW); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /1.0/at90can/programmers.txt: -------------------------------------------------------------------------------- 1 | jtagicemki.name=JTAG ICE mkI 2 | jtagicemki.communication=serial 3 | jtagicemki.protocol=jtag1 4 | 5 | usbtinyisp.name=USBtinyISP 6 | usbtinyisp.protocol=usbtiny 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /AT90CAN_Pinmap.txt: -------------------------------------------------------------------------------- 1 | AT90CAN128 Pin Map 2 | 3 | AT90CAN128 ArduinoDigitalPin 4 | PA0 0 5 | PA1 1 6 | PA2 2 7 | PA3 3 8 | PA4 4 9 | PA5 5 10 | PA6 6 11 | PA7 7 12 | PB0 8 13 | PB1 9 14 | PB2 10 15 | PB3 11 16 | PB4 12 17 | PB5 13 18 | PB6 14 19 | PB7 15 20 | PC0 16 21 | PC1 17 22 | PC2 18 23 | PC3 19 24 | PC4 20 25 | PC5 21 26 | PC6 22 27 | PC7 23 28 | PD0 24 29 | PD1 25 30 | PD2 26 31 | PD3 27 32 | PD4 28 33 | PD5 29 34 | PD6 30 35 | PD7 31 36 | PE0 32 37 | PE1 33 38 | PE2 34 39 | PE3 35 40 | PE4 36 41 | PE5 37 42 | PE6 38 43 | PE7 39 44 | PG0 40 45 | PG1 41 46 | PG2 42 47 | PG3 43 48 | PG4 44 49 | PF0 45 50 | PF1 46 51 | PF2 47 52 | PF3 48 53 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | AT90CAN Support for Arduino 2 | Maintainer: Sam C. Lin 3 | 4 | This is a continuation of SuperCow's work on adapting Arduino to work with AT90CANxx MCU's at http://arduino.cc/forum/index.php/topic,8446.0.html 5 | 6 | Compile Arduino sketches on Atmel AT90CANxx MCU's. 7 | Supports USBtinyISP and JTAG ICE mk1 8 | 9 | For Arduino <= 0023: copy the 0023/at90can folder to /hardware/at90can 10 | For Arduino >= 1.0: copy the 1.0/at90can folder to /hardware/at90can 11 | 12 | From the Arduino IDE's Tools->Board menu, select either 13 | 14 | [usbtinyisp]AT90CAN128 15 | 16 | or 17 | 18 | [JTAG ICE mk1]AT90CAN128 19 | 20 | Set your fuses with avrdude: 21 | avrdude -c usbtiny -p at90can128 -U lfuse:w:0xFF:m 22 | avrdude -c usbtiny -p at90can128 -U hfuse:w:0x19:m 23 | avrdude -c usbtiny -p at90can128 -U efuse:w:0xFF:m 24 | 25 | To install bootloader for programming over serial, you must set in hfuse BOOTSZ=10 and BOOTRST=0. Use the following fuse settings: 26 | avrdude -c usbtiny -p at90can128 -U lfuse:w:0xFF:m 27 | avrdude -c usbtiny -p at90can128 -U hfuse:w:0x1C:m 28 | avrdude -c usbtiny -p at90can128 -U efuse:w:0xFF:m 29 | You will also need to set up the automatic reset circuit to use DTR to toggle the RESET pin: DTR---|100nF|----|1n4148>|--VCC 30 | Select [bootloader]AT90CAN128 board type in Arduino IDE and burn the bootloader. 31 | Thereafter, you can burn sketches without a hardware programmer via USART0 (RXD0/TXD0) by selecting board type [bootloader]AT90CAN128. 32 | 33 | 34 | For Arduino pin mappings, see AT90CAN_Pinmap.txt 35 | 36 | For more information, see http://blog.lincomatic.com/?tag=can-bus 37 | 38 | ---------------- 39 | ChangeLog 40 | 20130421 SCL 41 | - restore missing usbtinyisp to 1.0 boards.txt 42 | 43 | 20130104 SCL 44 | - get bootloader working. Thanks to a4x4kiwi for help 45 | - changed lock bits when locked from CF to 0F because even though AT90CAN128 46 | datasheet shows top 2 bits fixed = 1, avrdude always reads back 0's. 47 | 48 | 49 | 50 | --------------------------------------------------------------------------------