Beifengdo commited on
Commit
c40c007
·
verified ·
1 Parent(s): c435f05

Archive original Arduino development files (part 3)

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +8 -0
  2. hardware/arduino/avr/bootloaders/caterina-LilyPadUSB/Caterina.h +99 -0
  3. hardware/arduino/avr/bootloaders/caterina-LilyPadUSB/Descriptors.c +260 -0
  4. hardware/arduino/avr/bootloaders/caterina-LilyPadUSB/Makefile +716 -0
  5. hardware/arduino/avr/bootloaders/caterina-LilyPadUSB/Readme.txt +11 -0
  6. hardware/arduino/avr/bootloaders/gemma/README.md +14 -0
  7. hardware/arduino/avr/bootloaders/gemma/avrdude.conf +0 -0
  8. hardware/arduino/avr/bootloaders/gemma/gemma_v1.hex +182 -0
  9. hardware/arduino/avr/bootloaders/gemma/usbconfig.h +351 -0
  10. hardware/arduino/avr/bootloaders/gemma/usbconfig.patch +24 -0
  11. hardware/arduino/avr/bootloaders/lilypad/LilyPadBOOT_168.hex +117 -0
  12. hardware/arduino/avr/bootloaders/lilypad/src/ATmegaBOOT.c +977 -0
  13. hardware/arduino/avr/bootloaders/lilypad/src/Makefile +83 -0
  14. hardware/arduino/avr/bootloaders/optiboot/Makefile +450 -0
  15. hardware/arduino/avr/bootloaders/optiboot/README.TXT +81 -0
  16. hardware/arduino/avr/bootloaders/optiboot/boot.h +846 -0
  17. hardware/arduino/avr/bootloaders/optiboot/makeall +20 -0
  18. hardware/arduino/avr/bootloaders/optiboot/omake +2 -0
  19. hardware/arduino/avr/bootloaders/optiboot/omake.bat +1 -0
  20. hardware/arduino/avr/bootloaders/optiboot/optiboot.c +672 -0
  21. hardware/arduino/avr/bootloaders/optiboot/optiboot_atmega168.hex +35 -0
  22. hardware/arduino/avr/bootloaders/optiboot/optiboot_atmega168.lst +598 -0
  23. hardware/arduino/avr/bootloaders/optiboot/optiboot_atmega328-Mini.hex +33 -0
  24. hardware/arduino/avr/bootloaders/optiboot/optiboot_atmega328.hex +35 -0
  25. hardware/arduino/avr/bootloaders/optiboot/optiboot_atmega328.lst +598 -0
  26. hardware/arduino/avr/bootloaders/optiboot/optiboot_atmega8.hex +33 -0
  27. hardware/arduino/avr/bootloaders/optiboot/optiboot_atmega8.lst +604 -0
  28. hardware/arduino/avr/bootloaders/optiboot/pin_defs.h +80 -0
  29. hardware/arduino/avr/bootloaders/optiboot/stk500.h +39 -0
  30. hardware/arduino/avr/bootloaders/stk500v2/License.txt +280 -0
  31. hardware/arduino/avr/bootloaders/stk500v2/Makefile +587 -0
  32. hardware/arduino/avr/bootloaders/stk500v2/Mega2560-prod-firmware-2011-06-29.hex +513 -0
  33. hardware/arduino/avr/bootloaders/stk500v2/STK500V2.pnproj +1 -0
  34. hardware/arduino/avr/bootloaders/stk500v2/STK500V2.pnps +1 -0
  35. hardware/arduino/avr/bootloaders/stk500v2/avr_cpunames.h +189 -0
  36. hardware/arduino/avr/bootloaders/stk500v2/avrinterruptnames.h +1040 -0
  37. hardware/arduino/avr/bootloaders/stk500v2/command.h +114 -0
  38. hardware/arduino/avr/bootloaders/stk500v2/stk500boot.c +2122 -0
  39. hardware/arduino/avr/bootloaders/stk500v2/stk500boot.ppg +1 -0
  40. hardware/arduino/avr/bootloaders/stk500v2/stk500boot_v2_mega2560.hex +469 -0
  41. hardware/arduino/avr/cores/arduino/Arduino.h +260 -0
  42. hardware/arduino/avr/cores/arduino/CDC.cpp +302 -0
  43. hardware/arduino/avr/cores/arduino/Client.h +45 -0
  44. hardware/arduino/avr/cores/arduino/HardwareSerial.cpp +281 -0
  45. hardware/arduino/avr/cores/arduino/HardwareSerial.h +161 -0
  46. hardware/arduino/avr/cores/arduino/HardwareSerial0.cpp +79 -0
  47. hardware/arduino/avr/cores/arduino/HardwareSerial1.cpp +69 -0
  48. hardware/arduino/avr/cores/arduino/HardwareSerial2.cpp +57 -0
  49. hardware/arduino/avr/cores/arduino/HardwareSerial3.cpp +57 -0
  50. hardware/arduino/avr/cores/arduino/HardwareSerial_private.h +123 -0
.gitattributes CHANGED
@@ -110,3 +110,11 @@ drivers/FTDI[[:space:]]USB[[:space:]]Drivers/Static/amd64/ftd2xx.lib filter=lfs
110
  drivers/FTDI[[:space:]]USB[[:space:]]Drivers/Static/i386/ftd2xx.lib filter=lfs diff=lfs merge=lfs -text
111
  drivers/ia64/libusb0.dll filter=lfs diff=lfs merge=lfs -text
112
  drivers/ia64/libusb0.sys filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
110
  drivers/FTDI[[:space:]]USB[[:space:]]Drivers/Static/i386/ftd2xx.lib filter=lfs diff=lfs merge=lfs -text
111
  drivers/ia64/libusb0.dll filter=lfs diff=lfs merge=lfs -text
112
  drivers/ia64/libusb0.sys filter=lfs diff=lfs merge=lfs -text
113
+ hardware/arduino/avr/firmwares/wifishield/binary/wifi_dnld.elf filter=lfs diff=lfs merge=lfs -text
114
+ hardware/arduino/avr/firmwares/wifishield/binary/wifi_dnld_2_1.elf filter=lfs diff=lfs merge=lfs -text
115
+ hardware/arduino/avr/firmwares/wifishield/binary/wifiHD.elf filter=lfs diff=lfs merge=lfs -text
116
+ hardware/arduino/avr/firmwares/wifishield/binary/wifiHD_2_1.elf filter=lfs diff=lfs merge=lfs -text
117
+ hardware/arduino/avr/firmwares/wifishield/wifi_dnld/src/Doc/gettingstarted.pdf filter=lfs diff=lfs merge=lfs -text
118
+ hardware/arduino/avr/firmwares/wifishield/wifi_dnld/src/Doc/SPB104[[:space:]]product[[:space:]]brief.pdf filter=lfs diff=lfs merge=lfs -text
119
+ hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/COMPONENTS/WIFI/HD/v2.7.0/UCR1/GCC/lib_ucr1_hd_wl_sta_intwpa_v2.7.0.a filter=lfs diff=lfs merge=lfs -text
120
+ hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/COMPONENTS/WIFI/HD/v2.7.0/UCR2/GCC/lib_ucr2_hd_wl_sta_intwpa_v2.7.0.a filter=lfs diff=lfs merge=lfs -text
hardware/arduino/avr/bootloaders/caterina-LilyPadUSB/Caterina.h ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ LUFA Library
3
+ Copyright (C) Dean Camera, 2011.
4
+
5
+ dean [at] fourwalledcubicle [dot] com
6
+ www.lufa-lib.org
7
+ */
8
+
9
+ /*
10
+ Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
+
12
+ Permission to use, copy, modify, distribute, and sell this
13
+ software and its documentation for any purpose is hereby granted
14
+ without fee, provided that the above copyright notice appear in
15
+ all copies and that both that the copyright notice and this
16
+ permission notice and warranty disclaimer appear in supporting
17
+ documentation, and that the name of the author not be used in
18
+ advertising or publicity pertaining to distribution of the
19
+ software without specific, written prior permission.
20
+
21
+ The author disclaim all warranties with regard to this
22
+ software, including all implied warranties of merchantability
23
+ and fitness. In no event shall the author be liable for any
24
+ special, indirect or consequential damages or any damages
25
+ whatsoever resulting from loss of use, data or profits, whether
26
+ in an action of contract, negligence or other tortious action,
27
+ arising out of or in connection with the use or performance of
28
+ this software.
29
+ */
30
+
31
+ /** \file
32
+ *
33
+ * Header file for BootloaderCDC.c.
34
+ */
35
+
36
+ #ifndef _CDC_H_
37
+ #define _CDC_H_
38
+
39
+ /* Includes: */
40
+ #include <avr/io.h>
41
+ #include <avr/wdt.h>
42
+ #include <avr/boot.h>
43
+ #include <avr/eeprom.h>
44
+ #include <avr/power.h>
45
+ #include <avr/interrupt.h>
46
+ #include <stdbool.h>
47
+
48
+ #include "Descriptors.h"
49
+
50
+ #include <LUFA/Drivers/USB/USB.h>
51
+ /* Macros: */
52
+ /** Version major of the CDC bootloader. */
53
+ #define BOOTLOADER_VERSION_MAJOR 0x01
54
+
55
+ /** Version minor of the CDC bootloader. */
56
+ #define BOOTLOADER_VERSION_MINOR 0x00
57
+
58
+ /** Hardware version major of the CDC bootloader. */
59
+ #define BOOTLOADER_HWVERSION_MAJOR 0x01
60
+
61
+ /** Hardware version minor of the CDC bootloader. */
62
+ #define BOOTLOADER_HWVERSION_MINOR 0x00
63
+
64
+ /** Eight character bootloader firmware identifier reported to the host when requested */
65
+ #define SOFTWARE_IDENTIFIER "CATERINA"
66
+
67
+ #define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n))
68
+ #define LED_SETUP() DDRC |= (1<<7); DDRB |= (1<<0); DDRD |= (1<<5);
69
+ #define L_LED_OFF() PORTC &= ~(1<<7)
70
+ #define L_LED_ON() PORTC |= (1<<7)
71
+ #define L_LED_TOGGLE() PORTC ^= (1<<7)
72
+ #define TX_LED_OFF() PORTD |= (1<<5)
73
+ #define TX_LED_ON() PORTD &= ~(1<<5)
74
+ #define RX_LED_OFF() PORTB |= (1<<0)
75
+ #define RX_LED_ON() PORTB &= ~(1<<0)
76
+
77
+ /* Type Defines: */
78
+ /** Type define for a non-returning pointer to the start of the loaded application in flash memory. */
79
+ typedef void (*AppPtr_t)(void) ATTR_NO_RETURN;
80
+
81
+ /* Function Prototypes: */
82
+ void StartSketch(void);
83
+ void LEDPulse(void);
84
+
85
+ void CDC_Task(void);
86
+ void SetupHardware(void);
87
+
88
+ void EVENT_USB_Device_ConfigurationChanged(void);
89
+
90
+ #if defined(INCLUDE_FROM_CATERINA_C) || defined(__DOXYGEN__)
91
+ #if !defined(NO_BLOCK_SUPPORT)
92
+ static void ReadWriteMemoryBlock(const uint8_t Command);
93
+ #endif
94
+ static uint8_t FetchNextCommandByte(void);
95
+ static void WriteNextResponseByte(const uint8_t Response);
96
+ #endif
97
+
98
+ #endif
99
+
hardware/arduino/avr/bootloaders/caterina-LilyPadUSB/Descriptors.c ADDED
@@ -0,0 +1,260 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ LUFA Library
3
+ Copyright (C) Dean Camera, 2011.
4
+
5
+ dean [at] fourwalledcubicle [dot] com
6
+ www.lufa-lib.org
7
+ */
8
+
9
+ /*
10
+ Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
+
12
+ Permission to use, copy, modify, distribute, and sell this
13
+ software and its documentation for any purpose is hereby granted
14
+ without fee, provided that the above copyright notice appear in
15
+ all copies and that both that the copyright notice and this
16
+ permission notice and warranty disclaimer appear in supporting
17
+ documentation, and that the name of the author not be used in
18
+ advertising or publicity pertaining to distribution of the
19
+ software without specific, written prior permission.
20
+
21
+ The author disclaim all warranties with regard to this
22
+ software, including all implied warranties of merchantability
23
+ and fitness. In no event shall the author be liable for any
24
+ special, indirect or consequential damages or any damages
25
+ whatsoever resulting from loss of use, data or profits, whether
26
+ in an action of contract, negligence or other tortious action,
27
+ arising out of or in connection with the use or performance of
28
+ this software.
29
+ */
30
+
31
+ /** \file
32
+ *
33
+ * USB Device Descriptors, for library use when in USB device mode. Descriptors are special
34
+ * computer-readable structures which the host requests upon device enumeration, to determine
35
+ * the device's capabilities and functions.
36
+ */
37
+
38
+ #include "Descriptors.h"
39
+
40
+ /** Device descriptor structure. This descriptor, located in SRAM memory, describes the overall
41
+ * device characteristics, including the supported USB version, control endpoint size and the
42
+ * number of device configurations. The descriptor is read out by the USB host when the enumeration
43
+ * process begins.
44
+ */
45
+ const USB_Descriptor_Device_t DeviceDescriptor =
46
+ {
47
+ .Header = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device},
48
+
49
+ .USBSpecification = VERSION_BCD(01.10),
50
+ .Class = CDC_CSCP_CDCClass,
51
+ .SubClass = CDC_CSCP_NoSpecificSubclass,
52
+ .Protocol = CDC_CSCP_NoSpecificProtocol,
53
+
54
+ .Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE,
55
+
56
+ .VendorID = DEVICE_VID,
57
+ .ProductID = DEVICE_PID,
58
+ .ReleaseNumber = VERSION_BCD(00.01),
59
+
60
+ .ManufacturerStrIndex = 0x02,
61
+ .ProductStrIndex = 0x01,
62
+ .SerialNumStrIndex = NO_DESCRIPTOR,
63
+
64
+ .NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS
65
+ };
66
+
67
+ /** Configuration descriptor structure. This descriptor, located in SRAM memory, describes the usage
68
+ * of the device in one of its supported configurations, including information about any device interfaces
69
+ * and endpoints. The descriptor is read out by the USB host during the enumeration process when selecting
70
+ * a configuration so that the host may correctly communicate with the USB device.
71
+ */
72
+ const USB_Descriptor_Configuration_t ConfigurationDescriptor =
73
+ {
74
+ .Config =
75
+ {
76
+ .Header = {.Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration},
77
+
78
+ .TotalConfigurationSize = sizeof(USB_Descriptor_Configuration_t),
79
+ .TotalInterfaces = 2,
80
+
81
+ .ConfigurationNumber = 1,
82
+ .ConfigurationStrIndex = NO_DESCRIPTOR,
83
+
84
+ .ConfigAttributes = USB_CONFIG_ATTR_BUSPOWERED,
85
+
86
+ .MaxPowerConsumption = USB_CONFIG_POWER_MA(100)
87
+ },
88
+
89
+ .CDC_CCI_Interface =
90
+ {
91
+ .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
92
+
93
+ .InterfaceNumber = 0,
94
+ .AlternateSetting = 0,
95
+
96
+ .TotalEndpoints = 1,
97
+
98
+ .Class = CDC_CSCP_CDCClass,
99
+ .SubClass = CDC_CSCP_ACMSubclass,
100
+ .Protocol = CDC_CSCP_ATCommandProtocol,
101
+
102
+ .InterfaceStrIndex = NO_DESCRIPTOR
103
+ },
104
+
105
+ .CDC_Functional_Header =
106
+ {
107
+ .Header = {.Size = sizeof(USB_CDC_Descriptor_FunctionalHeader_t), .Type = DTYPE_CSInterface},
108
+ .Subtype = 0x00,
109
+
110
+ .CDCSpecification = VERSION_BCD(01.10),
111
+ },
112
+
113
+ .CDC_Functional_ACM =
114
+ {
115
+ .Header = {.Size = sizeof(USB_CDC_Descriptor_FunctionalACM_t), .Type = DTYPE_CSInterface},
116
+ .Subtype = 0x02,
117
+
118
+ .Capabilities = 0x04,
119
+ },
120
+
121
+ .CDC_Functional_Union =
122
+ {
123
+ .Header = {.Size = sizeof(USB_CDC_Descriptor_FunctionalUnion_t), .Type = DTYPE_CSInterface},
124
+ .Subtype = 0x06,
125
+
126
+ .MasterInterfaceNumber = 0,
127
+ .SlaveInterfaceNumber = 1,
128
+ },
129
+
130
+ .CDC_NotificationEndpoint =
131
+ {
132
+ .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
133
+
134
+ .EndpointAddress = (ENDPOINT_DIR_IN | CDC_NOTIFICATION_EPNUM),
135
+ .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
136
+ .EndpointSize = CDC_NOTIFICATION_EPSIZE,
137
+ .PollingIntervalMS = 0xFF
138
+ },
139
+
140
+ .CDC_DCI_Interface =
141
+ {
142
+ .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
143
+
144
+ .InterfaceNumber = 1,
145
+ .AlternateSetting = 0,
146
+
147
+ .TotalEndpoints = 2,
148
+
149
+ .Class = CDC_CSCP_CDCDataClass,
150
+ .SubClass = CDC_CSCP_NoDataSubclass,
151
+ .Protocol = CDC_CSCP_NoDataProtocol,
152
+
153
+ .InterfaceStrIndex = NO_DESCRIPTOR
154
+ },
155
+
156
+ .CDC_DataOutEndpoint =
157
+ {
158
+ .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
159
+
160
+ .EndpointAddress = (ENDPOINT_DIR_OUT | CDC_RX_EPNUM),
161
+ .Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
162
+ .EndpointSize = CDC_TXRX_EPSIZE,
163
+ .PollingIntervalMS = 0x01
164
+ },
165
+
166
+ .CDC_DataInEndpoint =
167
+ {
168
+ .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
169
+
170
+ .EndpointAddress = (ENDPOINT_DIR_IN | CDC_TX_EPNUM),
171
+ .Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
172
+ .EndpointSize = CDC_TXRX_EPSIZE,
173
+ .PollingIntervalMS = 0x01
174
+ }
175
+ };
176
+
177
+ /** Language descriptor structure. This descriptor, located in SRAM memory, is returned when the host requests
178
+ * the string descriptor with index 0 (the first index). It is actually an array of 16-bit integers, which indicate
179
+ * via the language ID table available at USB.org what languages the device supports for its string descriptors.
180
+ */
181
+ const USB_Descriptor_String_t LanguageString =
182
+ {
183
+ .Header = {.Size = USB_STRING_LEN(1), .Type = DTYPE_String},
184
+
185
+ .UnicodeString = {LANGUAGE_ID_ENG}
186
+ };
187
+
188
+ /** Product descriptor string. This is a Unicode string containing the product's details in human readable form,
189
+ * and is read out upon request by the host when the appropriate string ID is requested, listed in the Device
190
+ * Descriptor.
191
+ */
192
+ const USB_Descriptor_String_t ProductString =
193
+ {
194
+ .Header = {.Size = USB_STRING_LEN(16), .Type = DTYPE_String},
195
+ #if DEVICE_PID == 0x9207
196
+ .UnicodeString = L"LilyPadUSB "
197
+ #else
198
+ .UnicodeString = L"USB IO board "
199
+ #endif
200
+ };
201
+
202
+ const USB_Descriptor_String_t ManufNameString =
203
+ {
204
+ .Header = {.Size = USB_STRING_LEN(20), .Type = DTYPE_String},
205
+ #if DEVICE_VID == 0x1B4F
206
+ .UnicodeString = L"SparkFun Electronics"
207
+ #else
208
+ .UnicodeString = L"Unknown "
209
+ #endif
210
+ };
211
+
212
+ /** This function is called by the library when in device mode, and must be overridden (see LUFA library "USB Descriptors"
213
+ * documentation) by the application code so that the address and size of a requested descriptor can be given
214
+ * to the USB library. When the device receives a Get Descriptor request on the control endpoint, this function
215
+ * is called so that the descriptor details can be passed back and the appropriate descriptor sent back to the
216
+ * USB host.
217
+ */
218
+ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
219
+ const uint8_t wIndex,
220
+ const void** const DescriptorAddress)
221
+ {
222
+ const uint8_t DescriptorType = (wValue >> 8);
223
+ const uint8_t DescriptorNumber = (wValue & 0xFF);
224
+
225
+ const void* Address = NULL;
226
+ uint16_t Size = NO_DESCRIPTOR;
227
+
228
+ switch (DescriptorType)
229
+ {
230
+ case DTYPE_Device:
231
+ Address = &DeviceDescriptor;
232
+ Size = sizeof(USB_Descriptor_Device_t);
233
+ break;
234
+ case DTYPE_Configuration:
235
+ Address = &ConfigurationDescriptor;
236
+ Size = sizeof(USB_Descriptor_Configuration_t);
237
+ break;
238
+ case DTYPE_String:
239
+ if (!(DescriptorNumber))
240
+ {
241
+ Address = &LanguageString;
242
+ Size = LanguageString.Header.Size;
243
+ }
244
+ else if (DescriptorNumber == DeviceDescriptor.ProductStrIndex)
245
+ {
246
+ Address = &ProductString;
247
+ Size = ProductString.Header.Size;
248
+ } else if (DescriptorNumber == DeviceDescriptor.ManufacturerStrIndex)
249
+ {
250
+ Address = &ManufNameString;
251
+ Size = ManufNameString.Header.Size;
252
+ }
253
+
254
+ break;
255
+ }
256
+
257
+ *DescriptorAddress = Address;
258
+ return Size;
259
+ }
260
+
hardware/arduino/avr/bootloaders/caterina-LilyPadUSB/Makefile ADDED
@@ -0,0 +1,716 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Hey Emacs, this is a -*- makefile -*-
2
+ #----------------------------------------------------------------------------
3
+ # WinAVR Makefile Template written by Eric B. Weddington, J�rg Wunsch, et al.
4
+ # >> Modified for use with the LUFA project. <<
5
+ #
6
+ # Released to the Public Domain
7
+ #
8
+ # Additional material for this makefile was written by:
9
+ # Peter Fleury
10
+ # Tim Henigan
11
+ # Colin O'Flynn
12
+ # Reiner Patommel
13
+ # Markus Pfaff
14
+ # Sander Pool
15
+ # Frederik Rouleau
16
+ # Carlos Lamas
17
+ # Dean Camera
18
+ # Opendous Inc.
19
+ # Denver Gingerich
20
+ #
21
+ #----------------------------------------------------------------------------
22
+ # On command line:
23
+ #
24
+ # make all = Make software.
25
+ #
26
+ # make clean = Clean out built project files.
27
+ #
28
+ # make coff = Convert ELF to AVR COFF.
29
+ #
30
+ # make extcoff = Convert ELF to AVR Extended COFF.
31
+ #
32
+ # make program = Download the hex file to the device, using avrdude.
33
+ # Please customize the avrdude settings below first!
34
+ #
35
+ # make doxygen = Generate DoxyGen documentation for the project (must have
36
+ # DoxyGen installed)
37
+ #
38
+ # make debug = Start either simulavr or avarice as specified for debugging,
39
+ # with avr-gdb or avr-insight as the front end for debugging.
40
+ #
41
+ # make filename.s = Just compile filename.c into the assembler code only.
42
+ #
43
+ # make filename.i = Create a preprocessed source file for use in submitting
44
+ # bug reports to the GCC project.
45
+ #
46
+ # To rebuild project do "make clean" then "make all".
47
+ #----------------------------------------------------------------------------
48
+
49
+ # USB vendor ID (VID)
50
+ # official Arduino LLC VID = 0x2341
51
+ # SparkFun VID = 0x1B4F
52
+ VID = 0x1B4F
53
+
54
+ # USB product ID (PID)
55
+ # official Leonardo PID = 0x0036
56
+ # SparkFun LilyPadUSB PID = 0x9207
57
+ PID = 0x9207
58
+
59
+ # MCU name
60
+ MCU = atmega32u4
61
+
62
+ # Target architecture (see library "Board Types" documentation).
63
+ ARCH = AVR8
64
+
65
+ # Target board (see library "Board Types" documentation, NONE for projects not requiring
66
+ # LUFA board drivers). If USER is selected, put custom board drivers in a directory called
67
+ # "Board" inside the application directory.
68
+ BOARD = USER
69
+
70
+ # Processor frequency.
71
+ # This will define a symbol, F_CPU, in all source code files equal to the
72
+ # processor frequency in Hz. You can then use this symbol in your source code to
73
+ # calculate timings. Do NOT tack on a 'UL' at the end, this will be done
74
+ # automatically to create a 32-bit value in your source code.
75
+ #
76
+ # This will be an integer division of F_USB below, as it is sourced by
77
+ # F_USB after it has run through any CPU prescalers. Note that this value
78
+ # does not *change* the processor frequency - it should merely be updated to
79
+ # reflect the processor speed set externally so that the code can use accurate
80
+ # software delays.
81
+ F_CPU = 8000000
82
+
83
+
84
+ # Input clock frequency.
85
+ # This will define a symbol, F_USB, in all source code files equal to the
86
+ # input clock frequency (before any prescaling is performed) in Hz. This value may
87
+ # differ from F_CPU if prescaling is used on the latter, and is required as the
88
+ # raw input clock is fed directly to the PLL sections of the AVR for high speed
89
+ # clock generation for the USB and other AVR subsections. Do NOT tack on a 'UL'
90
+ # at the end, this will be done automatically to create a 32-bit value in your
91
+ # source code.
92
+ #
93
+ # If no clock division is performed on the input clock inside the AVR (via the
94
+ # CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
95
+ F_USB = $(F_CPU)
96
+
97
+
98
+ # Starting byte address of the bootloader, as a byte address - computed via the formula
99
+ # BOOT_START = ((FLASH_SIZE_KB - BOOT_SECTION_SIZE_KB) * 1024)
100
+ #
101
+ # Note that the bootloader size and start address given in AVRStudio is in words and not
102
+ # bytes, and so will need to be doubled to obtain the byte address needed by AVR-GCC.
103
+ FLASH_SIZE_KB = 32
104
+ BOOT_SECTION_SIZE_KB = 4
105
+ BOOT_START = 0x$(shell echo "obase=16; ($(FLASH_SIZE_KB) - $(BOOT_SECTION_SIZE_KB)) * 1024" | bc)
106
+
107
+
108
+ # Output format. (can be srec, ihex, binary)
109
+ FORMAT = ihex
110
+
111
+
112
+ # Target file name (without extension).
113
+ TARGET = Caterina
114
+
115
+
116
+ # Object files directory
117
+ # To put object files in current directory, use a dot (.), do NOT make
118
+ # this an empty or blank macro!
119
+ OBJDIR = .
120
+
121
+
122
+ # Path to the LUFA library
123
+ LUFA_PATH = LUFA-111009
124
+
125
+
126
+ # LUFA library compile-time options and predefined tokens
127
+ LUFA_OPTS = -D USB_DEVICE_ONLY
128
+ LUFA_OPTS += -D DEVICE_STATE_AS_GPIOR=0
129
+ LUFA_OPTS += -D ORDERED_EP_CONFIG
130
+ LUFA_OPTS += -D FIXED_CONTROL_ENDPOINT_SIZE=8
131
+ LUFA_OPTS += -D FIXED_NUM_CONFIGURATIONS=1
132
+ LUFA_OPTS += -D USE_RAM_DESCRIPTORS
133
+ LUFA_OPTS += -D USE_STATIC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)"
134
+ LUFA_OPTS += -D NO_INTERNAL_SERIAL
135
+ LUFA_OPTS += -D NO_DEVICE_SELF_POWER
136
+ LUFA_OPTS += -D NO_DEVICE_REMOTE_WAKEUP
137
+ LUFA_OPTS += -D NO_SOF_EVENTS
138
+
139
+ #LUFA_OPTS += -D NO_BLOCK_SUPPORT
140
+ #LUFA_OPTS += -D NO_EEPROM_BYTE_SUPPORT
141
+ #LUFA_OPTS += -D NO_FLASH_BYTE_SUPPORT
142
+ LUFA_OPTS += -D NO_LOCK_BYTE_WRITE_SUPPORT
143
+
144
+
145
+ # Create the LUFA source path variables by including the LUFA root makefile
146
+ include $(LUFA_PATH)/LUFA/makefile
147
+
148
+
149
+ # List C source files here. (C dependencies are automatically generated.)
150
+ SRC = $(TARGET).c \
151
+ Descriptors.c \
152
+ $(LUFA_SRC_USB) \
153
+
154
+
155
+ # List C++ source files here. (C dependencies are automatically generated.)
156
+ CPPSRC =
157
+
158
+
159
+ # List Assembler source files here.
160
+ # Make them always end in a capital .S. Files ending in a lowercase .s
161
+ # will not be considered source files but generated files (assembler
162
+ # output from the compiler), and will be deleted upon "make clean"!
163
+ # Even though the DOS/Win* filesystem matches both .s and .S the same,
164
+ # it will preserve the spelling of the filenames, and gcc itself does
165
+ # care about how the name is spelled on its command-line.
166
+ ASRC =
167
+
168
+
169
+ # Optimization level, can be [0, 1, 2, 3, s].
170
+ # 0 = turn off optimization. s = optimize for size.
171
+ # (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
172
+ OPT = s
173
+
174
+
175
+ # Debugging format.
176
+ # Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
177
+ # AVR Studio 4.10 requires dwarf-2.
178
+ # AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
179
+ DEBUG = dwarf-2
180
+
181
+
182
+ # List any extra directories to look for include files here.
183
+ # Each directory must be seperated by a space.
184
+ # Use forward slashes for directory separators.
185
+ # For a directory that has spaces, enclose it in quotes.
186
+ EXTRAINCDIRS = $(LUFA_PATH)/
187
+
188
+
189
+ # Compiler flag to set the C Standard level.
190
+ # c89 = "ANSI" C
191
+ # gnu89 = c89 plus GCC extensions
192
+ # c99 = ISO C99 standard (not yet fully implemented)
193
+ # gnu99 = c99 plus GCC extensions
194
+ CSTANDARD = -std=c99
195
+
196
+
197
+ # Place -D or -U options here for C sources
198
+ CDEFS = -DF_CPU=$(F_CPU)UL
199
+ CDEFS += -DF_USB=$(F_USB)UL
200
+ CDEFS += -DBOARD=BOARD_$(BOARD) -DARCH=ARCH_$(ARCH)
201
+ CDEFS += -DBOOT_START_ADDR=$(BOOT_START)UL
202
+ CDEFS += -DDEVICE_VID=$(VID)UL
203
+ CDEFS += -DDEVICE_PID=$(PID)UL
204
+ CDEFS += $(LUFA_OPTS)
205
+
206
+
207
+ # Place -D or -U options here for ASM sources
208
+ ADEFS = -DF_CPU=$(F_CPU)
209
+ ADEFS += -DF_USB=$(F_USB)UL
210
+ ADEFS += -DBOARD=BOARD_$(BOARD)
211
+ ADEFS += -DBOOT_START_ADDR=$(BOOT_START)UL
212
+ ADEFS += $(LUFA_OPTS)
213
+
214
+
215
+ # Place -D or -U options here for C++ sources
216
+ CPPDEFS = -DF_CPU=$(F_CPU)UL
217
+ CPPDEFS += -DF_USB=$(F_USB)UL
218
+ CPPDEFS += -DBOARD=BOARD_$(BOARD)
219
+ CPPDEFS += -DBOOT_START_ADDR=$(BOOT_START)UL
220
+ CPPDEFS += $(LUFA_OPTS)
221
+ #CPPDEFS += -D__STDC_LIMIT_MACROS
222
+ #CPPDEFS += -D__STDC_CONSTANT_MACROS
223
+
224
+
225
+
226
+ #---------------- Compiler Options C ----------------
227
+ # -g*: generate debugging information
228
+ # -O*: optimization level
229
+ # -f...: tuning, see GCC manual and avr-libc documentation
230
+ # -Wall...: warning level
231
+ # -Wa,...: tell GCC to pass this to the assembler.
232
+ # -adhlns...: create assembler listing
233
+ CFLAGS = -g$(DEBUG)
234
+ CFLAGS += $(CDEFS)
235
+ CFLAGS += -O$(OPT)
236
+ CFLAGS += -funsigned-char
237
+ CFLAGS += -funsigned-bitfields
238
+ CFLAGS += -ffunction-sections
239
+ CFLAGS += -fno-inline-small-functions
240
+ CFLAGS += -fpack-struct
241
+ CFLAGS += -fshort-enums
242
+ CFLAGS += -fno-strict-aliasing
243
+ CFLAGS += -Wall
244
+ CFLAGS += -Wstrict-prototypes
245
+ #CFLAGS += -mshort-calls
246
+ #CFLAGS += -fno-unit-at-a-time
247
+ #CFLAGS += -Wundef
248
+ #CFLAGS += -Wunreachable-code
249
+ #CFLAGS += -Wsign-compare
250
+ CFLAGS += -Wa,-adhlns=$(<:%.c=$(OBJDIR)/%.lst)
251
+ CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
252
+ CFLAGS += $(CSTANDARD)
253
+
254
+
255
+ #---------------- Compiler Options C++ ----------------
256
+ # -g*: generate debugging information
257
+ # -O*: optimization level
258
+ # -f...: tuning, see GCC manual and avr-libc documentation
259
+ # -Wall...: warning level
260
+ # -Wa,...: tell GCC to pass this to the assembler.
261
+ # -adhlns...: create assembler listing
262
+ CPPFLAGS = -g$(DEBUG)
263
+ CPPFLAGS += $(CPPDEFS)
264
+ CPPFLAGS += -O$(OPT)
265
+ CPPFLAGS += -funsigned-char
266
+ CPPFLAGS += -funsigned-bitfields
267
+ CPPFLAGS += -fpack-struct
268
+ CPPFLAGS += -fshort-enums
269
+ CPPFLAGS += -fno-exceptions
270
+ CPPFLAGS += -Wall
271
+ CPPFLAGS += -Wundef
272
+ #CPPFLAGS += -mshort-calls
273
+ #CPPFLAGS += -fno-unit-at-a-time
274
+ #CPPFLAGS += -Wstrict-prototypes
275
+ #CPPFLAGS += -Wunreachable-code
276
+ #CPPFLAGS += -Wsign-compare
277
+ CPPFLAGS += -Wa,-adhlns=$(<:%.cpp=$(OBJDIR)/%.lst)
278
+ CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
279
+ #CPPFLAGS += $(CSTANDARD)
280
+
281
+
282
+ #---------------- Assembler Options ----------------
283
+ # -Wa,...: tell GCC to pass this to the assembler.
284
+ # -adhlns: create listing
285
+ # -gstabs: have the assembler create line number information; note that
286
+ # for use in COFF files, additional information about filenames
287
+ # and function names needs to be present in the assembler source
288
+ # files -- see avr-libc docs [FIXME: not yet described there]
289
+ # -listing-cont-lines: Sets the maximum number of continuation lines of hex
290
+ # dump that will be displayed for a given single line of source input.
291
+ ASFLAGS = $(ADEFS) -Wa,-adhlns=$(<:%.S=$(OBJDIR)/%.lst),-gstabs,--listing-cont-lines=100
292
+
293
+
294
+ #---------------- Library Options ----------------
295
+ # Minimalistic printf version
296
+ PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
297
+
298
+ # Floating point printf version (requires MATH_LIB = -lm below)
299
+ PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
300
+
301
+ # If this is left blank, then it will use the Standard printf version.
302
+ PRINTF_LIB =
303
+ #PRINTF_LIB = $(PRINTF_LIB_MIN)
304
+ #PRINTF_LIB = $(PRINTF_LIB_FLOAT)
305
+
306
+
307
+ # Minimalistic scanf version
308
+ SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
309
+
310
+ # Floating point + %[ scanf version (requires MATH_LIB = -lm below)
311
+ SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
312
+
313
+ # If this is left blank, then it will use the Standard scanf version.
314
+ SCANF_LIB =
315
+ #SCANF_LIB = $(SCANF_LIB_MIN)
316
+ #SCANF_LIB = $(SCANF_LIB_FLOAT)
317
+
318
+
319
+ MATH_LIB = -lm
320
+
321
+
322
+ # List any extra directories to look for libraries here.
323
+ # Each directory must be seperated by a space.
324
+ # Use forward slashes for directory separators.
325
+ # For a directory that has spaces, enclose it in quotes.
326
+ EXTRALIBDIRS =
327
+
328
+
329
+
330
+ #---------------- External Memory Options ----------------
331
+
332
+ # 64 KB of external RAM, starting after internal RAM (ATmega128!),
333
+ # used for variables (.data/.bss) and heap (malloc()).
334
+ #EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
335
+
336
+ # 64 KB of external RAM, starting after internal RAM (ATmega128!),
337
+ # only used for heap (malloc()).
338
+ #EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff
339
+
340
+ EXTMEMOPTS =
341
+
342
+
343
+
344
+ #---------------- Linker Options ----------------
345
+ # -Wl,...: tell GCC to pass this to linker.
346
+ # -Map: create map file
347
+ # --cref: add cross reference to map file
348
+ LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
349
+ LDFLAGS += -Wl,--section-start=.text=$(BOOT_START)
350
+ LDFLAGS += -Wl,--relax
351
+ LDFLAGS += -Wl,--gc-sections
352
+ LDFLAGS += $(EXTMEMOPTS)
353
+ LDFLAGS += $(patsubst %,-L%,$(EXTRALIBDIRS))
354
+ LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
355
+ #LDFLAGS += -T linker_script.x
356
+
357
+
358
+
359
+ #---------------- Programming Options (avrdude) ----------------
360
+
361
+ # Programming hardware
362
+ # Type: avrdude -c ?
363
+ # to get a full listing.
364
+ #
365
+ AVRDUDE_PROGRAMMER = avrispmkII
366
+
367
+ # com1 = serial port. Use lpt1 to connect to parallel port.
368
+ AVRDUDE_PORT = usb
369
+
370
+ AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
371
+ #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
372
+ AVRDUDE_WRITE_FUSES = -U efuse:w:0xce:m
373
+ AVRDUDE_WRITE_FUSES += -U hfuse:w:0xd8:m
374
+ AVRDUDE_WRITE_FUSES += -U lfuse:w:0xff:m
375
+
376
+
377
+ # Uncomment the following if you want avrdude's erase cycle counter.
378
+ # Note that this counter needs to be initialized first using -Yn,
379
+ # see avrdude manual.
380
+ #AVRDUDE_ERASE_COUNTER = -y
381
+
382
+ # Uncomment the following if you do /not/ wish a verification to be
383
+ # performed after programming the device.
384
+ #AVRDUDE_NO_VERIFY = -V
385
+
386
+ # Increase verbosity level. Please use this when submitting bug
387
+ # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
388
+ # to submit bug reports.
389
+ #AVRDUDE_VERBOSE = -v -v
390
+
391
+ AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
392
+ AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
393
+ AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
394
+ AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
395
+
396
+
397
+
398
+ #---------------- Debugging Options ----------------
399
+
400
+ # For simulavr only - target MCU frequency.
401
+ DEBUG_MFREQ = $(F_CPU)
402
+
403
+ # Set the DEBUG_UI to either gdb or insight.
404
+ # DEBUG_UI = gdb
405
+ DEBUG_UI = insight
406
+
407
+ # Set the debugging back-end to either avarice, simulavr.
408
+ DEBUG_BACKEND = avarice
409
+ #DEBUG_BACKEND = simulavr
410
+
411
+ # GDB Init Filename.
412
+ GDBINIT_FILE = __avr_gdbinit
413
+
414
+ # When using avarice settings for the JTAG
415
+ JTAG_DEV = /dev/com1
416
+
417
+ # Debugging port used to communicate between GDB / avarice / simulavr.
418
+ DEBUG_PORT = 4242
419
+
420
+ # Debugging host used to communicate between GDB / avarice / simulavr, normally
421
+ # just set to localhost unless doing some sort of crazy debugging when
422
+ # avarice is running on a different computer.
423
+ DEBUG_HOST = localhost
424
+
425
+
426
+
427
+ #============================================================================
428
+
429
+
430
+ # Define programs and commands.
431
+ SHELL = sh
432
+ CC = avr-gcc
433
+ OBJCOPY = avr-objcopy
434
+ OBJDUMP = avr-objdump
435
+ SIZE = avr-size
436
+ AR = avr-ar rcs
437
+ NM = avr-nm
438
+ AVRDUDE = avrdude -B 1
439
+ REMOVE = rm -f
440
+ REMOVEDIR = rm -rf
441
+ COPY = cp
442
+ WINSHELL = cmd
443
+
444
+
445
+ # Define Messages
446
+ # English
447
+ MSG_ERRORS_NONE = Errors: none
448
+ MSG_BEGIN = -------- begin --------
449
+ MSG_END = -------- end --------
450
+ MSG_SIZE_BEFORE = Size before:
451
+ MSG_SIZE_AFTER = Size after:
452
+ MSG_COFF = Converting to AVR COFF:
453
+ MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
454
+ MSG_FLASH = Creating load file for Flash:
455
+ MSG_EEPROM = Creating load file for EEPROM:
456
+ MSG_EXTENDED_LISTING = Creating Extended Listing:
457
+ MSG_SYMBOL_TABLE = Creating Symbol Table:
458
+ MSG_LINKING = Linking:
459
+ MSG_COMPILING = Compiling C:
460
+ MSG_COMPILING_CPP = Compiling C++:
461
+ MSG_ASSEMBLING = Assembling:
462
+ MSG_CLEANING = Cleaning project:
463
+ MSG_CREATING_LIBRARY = Creating library:
464
+
465
+
466
+
467
+
468
+ # Define all object files.
469
+ OBJ = $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o)
470
+
471
+ # Define all listing files.
472
+ LST = $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst)
473
+
474
+
475
+ # Compiler flags to generate dependency files.
476
+ GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d
477
+
478
+
479
+ # Combine all necessary flags and optional flags.
480
+ # Add target processor to flags.
481
+ ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
482
+ ALL_CPPFLAGS = -mmcu=$(MCU) -I. -x c++ $(CPPFLAGS) $(GENDEPFLAGS)
483
+ ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
484
+
485
+
486
+ # Default target.
487
+ all: begin gccversion sizebefore build sizeafter end
488
+
489
+ # Change the build target to build a HEX file or a library.
490
+ build: elf hex eep lss sym
491
+ #build: lib
492
+
493
+ elf: $(TARGET).elf
494
+ hex: $(TARGET).hex
495
+ eep: $(TARGET).eep
496
+ lss: $(TARGET).lss
497
+ sym: $(TARGET).sym
498
+ LIBNAME=lib$(TARGET).a
499
+ lib: $(LIBNAME)
500
+
501
+
502
+
503
+ # Eye candy.
504
+ # AVR Studio 3.x does not check make's exit code but relies on
505
+ # the following magic strings to be generated by the compile job.
506
+ begin:
507
+ @echo
508
+ @echo $(MSG_BEGIN)
509
+
510
+ end:
511
+ @echo $(MSG_END)
512
+ @echo
513
+
514
+
515
+ # Display size of file.
516
+ HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
517
+ ELFSIZE = $(SIZE) $(MCU_FLAG) $(FORMAT_FLAG) $(TARGET).elf
518
+ MCU_FLAG = $(shell $(SIZE) --help | grep -- --mcu > /dev/null && echo --mcu=$(MCU) )
519
+ FORMAT_FLAG = $(shell $(SIZE) --help | grep -- --format=.*avr > /dev/null && echo --format=avr )
520
+
521
+
522
+ sizebefore:
523
+ @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
524
+ 2>/dev/null; echo; fi
525
+
526
+ sizeafter:
527
+ @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
528
+ 2>/dev/null; echo; fi
529
+
530
+
531
+
532
+ # Display compiler version information.
533
+ gccversion :
534
+ @$(CC) --version
535
+
536
+
537
+ # Program the device.
538
+ program: $(TARGET).hex $(TARGET).eep
539
+ $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM) $(AVRDUDE_WRITE_FUSES)
540
+
541
+
542
+ # Generate avr-gdb config/init file which does the following:
543
+ # define the reset signal, load the target file, connect to target, and set
544
+ # a breakpoint at main().
545
+ gdb-config:
546
+ @$(REMOVE) $(GDBINIT_FILE)
547
+ @echo define reset >> $(GDBINIT_FILE)
548
+ @echo SIGNAL SIGHUP >> $(GDBINIT_FILE)
549
+ @echo end >> $(GDBINIT_FILE)
550
+ @echo file $(TARGET).elf >> $(GDBINIT_FILE)
551
+ @echo target remote $(DEBUG_HOST):$(DEBUG_PORT) >> $(GDBINIT_FILE)
552
+ ifeq ($(DEBUG_BACKEND),simulavr)
553
+ @echo load >> $(GDBINIT_FILE)
554
+ endif
555
+ @echo break main >> $(GDBINIT_FILE)
556
+
557
+ debug: gdb-config $(TARGET).elf
558
+ ifeq ($(DEBUG_BACKEND), avarice)
559
+ @echo Starting AVaRICE - Press enter when "waiting to connect" message displays.
560
+ @$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \
561
+ $(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)
562
+ @$(WINSHELL) /c pause
563
+
564
+ else
565
+ @$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
566
+ $(DEBUG_MFREQ) --port $(DEBUG_PORT)
567
+ endif
568
+ @$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)
569
+
570
+ # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
571
+ COFFCONVERT = $(OBJCOPY) --debugging
572
+ COFFCONVERT += --change-section-address .data-0x800000
573
+ COFFCONVERT += --change-section-address .bss-0x800000
574
+ COFFCONVERT += --change-section-address .noinit-0x800000
575
+ COFFCONVERT += --change-section-address .eeprom-0x810000
576
+
577
+ coff: $(TARGET).elf
578
+ @echo
579
+ @echo $(MSG_COFF) $(TARGET).cof
580
+ $(COFFCONVERT) -O coff-avr $< $(TARGET).cof
581
+
582
+ extcoff: $(TARGET).elf
583
+ @echo
584
+ @echo $(MSG_EXTENDED_COFF) $(TARGET).cof
585
+ $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
586
+
587
+ # Create final output files (.hex, .eep) from ELF output file.
588
+ %.hex: %.elf
589
+ @echo
590
+ @echo $(MSG_FLASH) $@
591
+ $(OBJCOPY) -O $(FORMAT) -R .eeprom -R .fuse -R .lock $< $@
592
+
593
+ %.eep: %.elf
594
+ @echo
595
+ @echo $(MSG_EEPROM) $@
596
+ -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
597
+ --change-section-lma .eeprom=0 --no-change-warnings -O $(FORMAT) $< $@ || exit 0
598
+
599
+ # Create extended listing file from ELF output file.
600
+ %.lss: %.elf
601
+ @echo
602
+ @echo $(MSG_EXTENDED_LISTING) $@
603
+ $(OBJDUMP) -h -S -z $< > $@
604
+
605
+ # Create a symbol table from ELF output file.
606
+ %.sym: %.elf
607
+ @echo
608
+ @echo $(MSG_SYMBOL_TABLE) $@
609
+ $(NM) -n $< > $@
610
+
611
+
612
+
613
+ # Create library from object files.
614
+ .SECONDARY : $(TARGET).a
615
+ .PRECIOUS : $(OBJ)
616
+ %.a: $(OBJ)
617
+ @echo
618
+ @echo $(MSG_CREATING_LIBRARY) $@
619
+ $(AR) $@ $(OBJ)
620
+
621
+
622
+ # Link: create ELF output file from object files.
623
+ .SECONDARY : $(TARGET).elf
624
+ .PRECIOUS : $(OBJ)
625
+ %.elf: $(OBJ)
626
+ @echo
627
+ @echo $(MSG_LINKING) $@
628
+ $(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
629
+
630
+
631
+ # Compile: create object files from C source files.
632
+ $(OBJDIR)/%.o : %.c
633
+ @echo
634
+ @echo $(MSG_COMPILING) $<
635
+ $(CC) -c $(ALL_CFLAGS) $< -o $@
636
+
637
+
638
+ # Compile: create object files from C++ source files.
639
+ $(OBJDIR)/%.o : %.cpp
640
+ @echo
641
+ @echo $(MSG_COMPILING_CPP) $<
642
+ $(CC) -c $(ALL_CPPFLAGS) $< -o $@
643
+
644
+
645
+ # Compile: create assembler files from C source files.
646
+ %.s : %.c
647
+ $(CC) -S $(ALL_CFLAGS) $< -o $@
648
+
649
+
650
+ # Compile: create assembler files from C++ source files.
651
+ %.s : %.cpp
652
+ $(CC) -S $(ALL_CPPFLAGS) $< -o $@
653
+
654
+
655
+ # Assemble: create object files from assembler source files.
656
+ $(OBJDIR)/%.o : %.S
657
+ @echo
658
+ @echo $(MSG_ASSEMBLING) $<
659
+ $(CC) -c $(ALL_ASFLAGS) $< -o $@
660
+
661
+
662
+ # Create preprocessed source for use in sending a bug report.
663
+ %.i : %.c
664
+ $(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@
665
+
666
+
667
+ # Target: clean project.
668
+ clean: begin clean_list end
669
+
670
+ clean_list :
671
+ @echo
672
+ @echo $(MSG_CLEANING)
673
+ $(REMOVE) $(TARGET).hex
674
+ $(REMOVE) $(TARGET).eep
675
+ $(REMOVE) $(TARGET).cof
676
+ $(REMOVE) $(TARGET).elf
677
+ $(REMOVE) $(TARGET).map
678
+ $(REMOVE) $(TARGET).sym
679
+ $(REMOVE) $(TARGET).lss
680
+ $(REMOVE) $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o)
681
+ $(REMOVE) $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst)
682
+ $(REMOVE) $(SRC:.c=.s)
683
+ $(REMOVE) $(SRC:.c=.d)
684
+ $(REMOVE) $(SRC:.c=.i)
685
+ $(REMOVEDIR) .dep
686
+
687
+ doxygen:
688
+ @echo Generating Project Documentation \($(TARGET)\)...
689
+ @doxygen Doxygen.conf
690
+ @echo Documentation Generation Complete.
691
+
692
+ clean_doxygen:
693
+ rm -rf Documentation
694
+
695
+ checksource:
696
+ @for f in $(SRC) $(CPPSRC) $(ASRC); do \
697
+ if [ -f $$f ]; then \
698
+ echo "Found Source File: $$f" ; \
699
+ else \
700
+ echo "Source File Not Found: $$f" ; \
701
+ fi; done
702
+
703
+
704
+ # Create object files directory
705
+ $(shell mkdir $(OBJDIR) 2>/dev/null)
706
+
707
+
708
+ # Include the dependency files.
709
+ -include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
710
+
711
+
712
+ # Listing of phony targets.
713
+ .PHONY : all begin finish end sizebefore sizeafter gccversion \
714
+ build elf hex eep lss sym coff extcoff doxygen clean \
715
+ clean_list clean_doxygen program debug gdb-config checksource
716
+
hardware/arduino/avr/bootloaders/caterina-LilyPadUSB/Readme.txt ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Building the bootloader for the LilyPadUSB
2
+ 1. Download the LUFA-111009 file (http://fourwalledcubicle.com/blog/2011/10/lufa-111009-released/).
3
+ 2. Extract that file directly to the Caterina-LilyPadUSB bootloader directory.
4
+ 3. Open a command prompt in the Caterina-LilyPadUSB bootloader directory.
5
+ 4. Type 'make'.
6
+ 5. Enjoy!
7
+
8
+ Programming the bootloader for the LilyPadUSB
9
+ 1. Open a command prompt in the Caterina-LilyPadUSB folder.
10
+ 2. Connect your programmer- use a 2x3 .1" header, pressed against the programming vias.
11
+ 3. Type 'make program' into the command prompt.
hardware/arduino/avr/bootloaders/gemma/README.md ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Arduino Gemma Bootloader
2
+ ========================
3
+
4
+ The Arduino Gemma Bootloader is based on the Adafruit Trinket/Gemma Bootloader. In the Arduino Gemma bootloader the USB VID&PID, the Manufacturer name and the Device name parameters are changed.
5
+
6
+ The source code of the bootloader of the version used at the compile time can be found at the following link: https://github.com/adafruit/Adafruit-Trinket-Gemma-Bootloader/tree/3bc1bb561273535d4d493518a233a3a1fccf6b76
7
+
8
+ The *'usbconfig.h'* and the *'usbconfig.patch'* files are provided if you want to recompile the bootloader.
9
+ You only need to replace the original *'usbconfig.h'* file with this one or patch it with the provided patch file.
10
+
11
+ **Please note: you cannot use the Arduino USB VID/PID for your own non-Gemma products or projects. Purchase a USB VID for yourself at** http://www.usb.org/developers/vendor/
12
+
13
+
14
+
hardware/arduino/avr/bootloaders/gemma/avrdude.conf ADDED
The diff for this file is too large to render. See raw diff
 
hardware/arduino/avr/bootloaders/gemma/gemma_v1.hex ADDED
@@ -0,0 +1,182 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ :100000005FCA5FCA5FCA5FCA5FCA5FCA5FCA5FCAA8
2
+ :1014C00033C05FC08BC05DC05CC05BC05AC059C038
3
+ :1014D00058C057C056C055C054C053C052C009026E
4
+ :1014E0001200010100803209040000000000000029
5
+ :1014F00012011001FF00000841239F0C00010102AE
6
+ :1015000000010C03470065006D006D0061001603CB
7
+ :10151000410072006400750069006E006F002E00CB
8
+ :10152000630063000403090411241FBECFE5D2E069
9
+ :10153000DEBFCDBF84B7877F84BF88E10FB6F89444
10
+ :1015400081BD11BC0FBE91E080E80FB6F89486BD56
11
+ :1015500096BD0FBE0AEA0F9310E0A0E6B0E0EEEDF4
12
+ :10156000FFE102C005900D92A236B107D9F711E054
13
+ :10157000A2E6B0E001C01D92A832B107E1F7EDD3B9
14
+ :101580002CC59ECFA82FB92F80E090E041E050EA13
15
+ :10159000609530E009C02D9182279795879510F0CE
16
+ :1015A00084279527305EC8F36F5FA8F30895EADFBC
17
+ :1015B0008D939D930895A6E088279927AA9569F0B1
18
+ :1015C0000197E1F3B399FCCFB39BFECF81E099275C
19
+ :1015D000A6B3019611F0A871D9F70895CF93CFB7AC
20
+ :1015E000CF93C0915F02CA3A21F0CF91CFBFCF9184
21
+ :1015F00065CFCC27C395B39BE9F7B39B0BC0B39BD7
22
+ :1016000009C0B39B07C0B39B05C0B39B03C0B39B8A
23
+ :1016100001C0D3C00F92DF93C0910B01DD27CE5ED6
24
+ :10162000DE4F012EB39B03C0DF910F90E6CF2F93C7
25
+ :101630000F931F934F932FEF4F6F06B303FB20F9C8
26
+ :101640005F933F9350E03BE065C016B301265029FD
27
+ :1016500053FDC89556B3012703FB25F92F7306B335
28
+ :10166000B1F05027102713FB26F906B22230F0F014
29
+ :1016700000C016B3012703FB27F90126502906B243
30
+ :101680002430E8F54F77206816B30000F6CF5027D6
31
+ :101690004F7D206206B2102F000000C006B3002666
32
+ :1016A0005029102713FB26F906B2E2CF4F7B06B371
33
+ :1016B000206400C0DACF01265029187106B269F102
34
+ :1016C0004E7F2160012F16B328C0002650294D7F80
35
+ :1016D00006B22260102F29C0012650294B7F06B286
36
+ :1016E0002460012F2DC016B301265029477F2860A2
37
+ :1016F000000006B22EC04F7E06B3206130C04227E4
38
+ :1017000006B3499300265029102706B24FEF13FB6A
39
+ :1017100020F9297F16B379F2187159F10126502961
40
+ :1017200006B2012703FB21F9237F06B371F20026DD
41
+ :1017300050293150D0F006B2102713FB22F9277E32
42
+ :1017400016B351F201265029012703FB06B223F9F3
43
+ :101750002F7C49F2000006B3102713FB24F9002662
44
+ :10176000502906B22F7939F270CF10E21ABF002744
45
+ :1017700017C03B503195C31BD04010E21ABF0881FF
46
+ :10178000033CF9F00B34E9F0209109011981110FA4
47
+ :101790001213EDCF093651F10D3211F0013E39F738
48
+ :1017A000009310013F915F914F911F910F912F91E5
49
+ :1017B000DF910F90CAB7C5FD1DCFCF91CFBFCF919D
50
+ :1017C000189520911001222369F310910E01112325
51
+ :1017D00021F5343022F130930E0120930A0110914B
52
+ :1017E0000B013BE0311B30930B0119C000910E013E
53
+ :1017F00001309CF40AE53091610034FD11C0009382
54
+ :101800006100CEEFD0E010C0052710E000C021C07D
55
+ :10181000052710E0C89508BB14C03AE501C032EDB9
56
+ :10182000032EC0E0D0E032E017B31861C39A08B3CA
57
+ :1018300017BB58E120E84FEF20FF052708BB27958D
58
+ :1018400017951C3F28F700004552B0F720FF0527E9
59
+ :10185000279508BB17951C3FB8F629913A9561F773
60
+ :10186000077E10910F01110F08BBC250D04011F03C
61
+ :101870001093090110E21ABF086017B3177E402FBA
62
+ :10188000477E54E05A95F1F708BB17BB48BB8ACF97
63
+ :101890002091F9003091FA002D3B3441B8F421E059
64
+ :1018A0002093F600F894E091F900F091FA000C0111
65
+ :1018B00020935700E895112478948091F900909135
66
+ :1018C000FA0002969093FA008093F90008958091AF
67
+ :1018D000F600882309F43DC08091F9009091FA0048
68
+ :1018E000813C944108F035C0F8948091F9009091C2
69
+ :1018F000FA008238944118F1809166009091670057
70
+ :101900008F559A409F70906CEEEBF4E121E00C0152
71
+ :1019100020935700E895112480916E0090916F00FC
72
+ :101920008C559A409F70906CECEBF4E10C01209385
73
+ :101930005700E8951124789481E080936400E09149
74
+ :10194000F900F091FA00329785E080935700E8950E
75
+ :1019500078941092F6000895FF920F931F93CF93FF
76
+ :10196000DF9380910E01835087FD5AC190910B0146
77
+ :10197000ACE0B0E0A91BB109AE5EBE4F31E03093E0
78
+ :10198000620090910A019D3209F00AC1883009F085
79
+ :1019900045C183EC8093FE008AE58093610010923C
80
+ :1019A000FD008C91807609F47DC01092F3001092B6
81
+ :1019B000F5001092F40011962C911197213009F442
82
+ :1019C00069C0263021F481E08093FC0067C0273095
83
+ :1019D00009F040C03093FC0089EE90E090930D0137
84
+ :1019E00080930C0113969C9113979093EB001092A7
85
+ :1019F000EC0012968C911297803379F491114CC0BF
86
+ :101A00001496EC911497F0E0EE0FFF1F81E28093A3
87
+ :101A10005700E491E093EC003FC08C3A81F4903899
88
+ :101A2000D9F514968C911497811136C015968C9126
89
+ :101A30001597811131C081E08093E8002DC08C346E
90
+ :101A400059F515968C911597811126C081E08093E8
91
+ :101A5000E70022C0283009F4B6CF14968D919C91EE
92
+ :101A600015979093FA008093F90016968C9116972B
93
+ :101A70008093F10087EF820F843080F48FE788BD78
94
+ :101A80003093FB002093F2002A3051F081E08093E4
95
+ :101A9000FC0006C021E077C024E075C020E073C0E0
96
+ :101AA0002FEF68C012969C91129710920701119621
97
+ :101AB0008C911197811106C01092080187E091E086
98
+ :101AC00022E052C0853019F490930F013FC0863058
99
+ :101AD000B9F513968C911397813019F480EF94E146
100
+ :101AE00004C0823041F48EED94E190930D01809317
101
+ :101AF0000C0122E121C08330F1F4911108C084E28D
102
+ :101B000095E190930D0180930C0124E015C0913074
103
+ :101B100041F48EE095E190930D0180930C0126E154
104
+ :101B20000BC0923041F482E095E190930D018093D7
105
+ :101B30000C012CE001C020E080E48093FD0018C07F
106
+ :101B4000883079F0893031F49093110187E091E089
107
+ :101B500020E00AC021E08A3009F020E087E091E02F
108
+ :101B600003C081E191E021E090930D0180930C018D
109
+ :101B70002F3F49F48C9187FF02C016962C9180E884
110
+ :101B80008093FD000AC017968C911797811105C0AC
111
+ :101B900016968C91821708F4282F209360003EC07F
112
+ :101BA0009091FD0097FF3AC09091F100182F98177F
113
+ :101BB00008F4192F092F011B0093F1001092FC006B
114
+ :101BC0008091F2008A3029F0011128C01092600043
115
+ :101BD00025C0FA2ECA2FDB2F8C2F8F198117A0F763
116
+ :101BE0008091F9009091FA008034910590F421E001
117
+ :101BF00020936500FC01EE0FFF1FEA59FF4F28817B
118
+ :101C000039813183208302969093FA008093F90002
119
+ :101C100003C0888199813CDE2296DECF10920E01AE
120
+ :101C20008091610084FF7BC0809160008F3F09F448
121
+ :101C300076C0182F893008F018E0811B809360006F
122
+ :101C40008091FE0098E889278093FE00112309F413
123
+ :101C50005AC08091FD0087FF38C08091F100811744
124
+ :101C600008F4182F811B8093F1003091F200E0916D
125
+ :101C7000F900F091FA0020E0AFEFB0E0211700F595
126
+ :101C80003B3009F4FFCF3930D9F7E034F10560F487
127
+ :101C9000EF01CC0FDD1FCA59DF4F888199818D93E9
128
+ :101CA0009D932E5F3296EACFEC3B84E1F80710F06B
129
+ :101CB0008FEF01C084918C9311962F5F3196DECF08
130
+ :101CC000F093FA00E093F9001EC0E0910C01F0914E
131
+ :101CD0000D0186FF0BC08FEF90E0DC0124912D9366
132
+ :101CE0003196212F280F2A13F9CF09C08FEF90E0EA
133
+ :101CF000DC0121912D93212F280F2A13FACFF09385
134
+ :101D00000D01E0930C01612F8FEF90E050DC1C5F20
135
+ :101D10001C3019F08FEF809360001093610084E114
136
+ :101D200096B3987131F48150D9F710920F01109247
137
+ :101D30000901C1E08111C0E0809163008C1739F086
138
+ :101D4000C11103C0F89401D17894C0936300DF916E
139
+ :101D5000CF911F910F91FF900895C1B7B99A83E277
140
+ :101D60008ABD81E083BFAC9A8BB780628BBFBB9A80
141
+ :101D70002FE132E18AE0215030408040E1F700C09D
142
+ :101D80000000BB987894E8DD8091E800882321F179
143
+ :101D900082E090E09093F8008093F70013C0CF01A9
144
+ :101DA0008F739927892B21F483E080935700E8955E
145
+ :101DB000D3DD8091F7009091F80002969093F8009F
146
+ :101DC0008093F700E091F700F091F800E03C94E197
147
+ :101DD000F90728F31092E8008091E700882329F0A2
148
+ :101DE000BBDD75DD1092E700B7DD809162008823CE
149
+ :101DF00041F08091FC00811104C08091FB008111B1
150
+ :101E0000C2CF80916200882371F08091E600811139
151
+ :101E10000AC088B5805F88BD88B5811104C08AB5C5
152
+ :101E200090E189278ABD8091E6008F5F8093E6006C
153
+ :101E30008EEC90E00197F1F78091F4009091F5001D
154
+ :101E400001969093F5008093F4002091F3000097A1
155
+ :101E500011F42F5F00C02093F30030916200311124
156
+ :101E600005C081323EE4930708F05AC03091FC006F
157
+ :101E7000332321F08131974208F052C080916200F3
158
+ :101E8000882309F480CF8091FB0081117CCF23301F
159
+ :101E900008F479CF45C080916400811149C08CEB72
160
+ :101EA00094E19093FA008093F90081E08093F6002A
161
+ :101EB0000EDD3EC0DF01AA0FBB1FAA59BF4F8D9197
162
+ :101EC0009C919F012B7F232B31F4E054FB4E859195
163
+ :101ED0009491805A954FDCDCE091F900F091FA0082
164
+ :101EE000E034F10538F3F3DC10925F0217BA13BE49
165
+ :101EF0001ABC03C081B78F5F81BF81B78C17D0F345
166
+ :101F000003C081B7815081BF81B7C817D0F391E07A
167
+ :101F100080E80FB6F89486BD96BD0FBED0CA13C038
168
+ :101F200015BA1BBEF894809165008111B4CFDCCF47
169
+ :101F3000E0E0F0E083E080935700E8951092FA002B
170
+ :101F40001092F900C9CF80E090E0DF92EF92FF920B
171
+ :101F50000F931F93CF93DF9390E080E80FB6F89430
172
+ :101F600086BD96BD0FBE08E010E0F12C80E8E82E9B
173
+ :101F7000DF2CDE0CD1BE1FDBEC01C43389E0D807B7
174
+ :101F80000CF4FD2CE694015011090115110581F79F
175
+ :101F90001F2D8FEF8F0D81BF21B730E0812F90E093
176
+ :101FA00001968217930784F006DB8453994097FFCC
177
+ :101FB00003C09195819591098C179D0714F4F1B692
178
+ :101FC000EC0181B78F5FE7CFF1BEDF91CF911F9119
179
+ :0E1FD0000F91FF90EF90DF900895F894FFCFEF
180
+ :021FDE00FF5AA8
181
+ :04000003000014C025
182
+ :00000001FF
hardware/arduino/avr/bootloaders/gemma/usbconfig.h ADDED
@@ -0,0 +1,351 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Name: usbconfig.h
2
+ * Project: V-USB, virtual USB port for Atmel's(r) AVR(r) microcontrollers
3
+ * Author: Christian Starkjohann
4
+ * Creation Date: 2005-04-01
5
+ * Tabsize: 4
6
+ * Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH
7
+ * License: GNU GPL v2 or v3 (see License.txt)
8
+ */
9
+
10
+ /* Modified by me@frank-zhao.com for project GemmaBoot
11
+ *
12
+ * GemmaBoot is a bootloader that emulates a USBtinyISP (from Adafruit Industries)
13
+ *
14
+ * Gemma will use GemmaBoot
15
+ *
16
+ * This code is heavily derived from USBaspLoader, but also from USBtiny, with USBtinyISP's settings
17
+
18
+ Copyright (c) 2013 Adafruit Industries
19
+ All rights reserved.
20
+
21
+ GemmaBoot is free software: you can redistribute it and/or modify
22
+ it under the terms of the GNU Lesser General Public License as
23
+ published by the Free Software Foundation, either version 3 of
24
+ the License, or (at your option) any later version.
25
+
26
+ GemmaBoot is distributed in the hope that it will be useful,
27
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
28
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29
+ GNU Lesser General Public License for more details.
30
+
31
+ You should have received a copy of the GNU Lesser General Public
32
+ License along with GemmaBoot. If not, see
33
+ <http://www.gnu.org/licenses/>.
34
+ */
35
+
36
+ #ifndef __usbconfig_h_included__
37
+ #define __usbconfig_h_included__
38
+
39
+ /* YOU SHOULD NOT NEED TO MODIFY THIS FILE! All configurations are supposed
40
+ * to go into bootloaderconfig.h!
41
+ */
42
+
43
+ /* ---------------------------- Hardware Config ---------------------------- */
44
+
45
+ /* All the port and pin assignments, as well as the clock speed and CRC
46
+ setting are now in bootloaderconfig.h: */
47
+
48
+ #include "bootloaderconfig.h"
49
+
50
+ /* --------------------------- Functional Range ---------------------------- */
51
+
52
+ #define USB_CFG_HAVE_INTRIN_ENDPOINT 0
53
+ /* Define this to 1 if you want to compile a version with two endpoints: The
54
+ * default control endpoint 0 and an interrupt-in endpoint (any other endpoint
55
+ * number).
56
+ */
57
+ #define USB_CFG_HAVE_INTRIN_ENDPOINT3 0
58
+ /* Define this to 1 if you want to compile a version with three endpoints: The
59
+ * default control endpoint 0, an interrupt-in endpoint 3 (or the number
60
+ * configured below) and a catch-all default interrupt-in endpoint as above.
61
+ * You must also define USB_CFG_HAVE_INTRIN_ENDPOINT to 1 for this feature.
62
+ */
63
+ #define USB_CFG_EP3_NUMBER 3
64
+ /* If the so-called endpoint 3 is used, it can now be configured to any other
65
+ * endpoint number (except 0) with this macro. Default if undefined is 3.
66
+ */
67
+ /* #define USB_INITIAL_DATATOKEN USBPID_DATA1 */
68
+ /* The above macro defines the startup condition for data toggling on the
69
+ * interrupt/bulk endpoints 1 and 3. Defaults to USBPID_DATA1.
70
+ * Since the token is toggled BEFORE sending any data, the first packet is
71
+ * sent with the oposite value of this configuration!
72
+ */
73
+ #define USB_CFG_IMPLEMENT_HALT 0
74
+ /* Define this to 1 if you also want to implement the ENDPOINT_HALT feature
75
+ * for endpoint 1 (interrupt endpoint). Although you may not need this feature,
76
+ * it is required by the standard. We have made it a config option because it
77
+ * bloats the code considerably.
78
+ */
79
+ #define USB_CFG_SUPPRESS_INTR_CODE 0
80
+ /* Define this to 1 if you want to declare interrupt-in endpoints, but don't
81
+ * want to send any data over them. If this macro is defined to 1, functions
82
+ * usbSetInterrupt() and usbSetInterrupt3() are omitted. This is useful if
83
+ * you need the interrupt-in endpoints in order to comply to an interface
84
+ * (e.g. HID), but never want to send any data. This option saves a couple
85
+ * of bytes in flash memory and the transmit buffers in RAM.
86
+ */
87
+ #define USB_CFG_INTR_POLL_INTERVAL 10
88
+ /* If you compile a version with endpoint 1 (interrupt-in), this is the poll
89
+ * interval. The value is in milliseconds and must not be less than 10 ms for
90
+ * low speed devices.
91
+ */
92
+ #ifndef USB_CFG_IS_SELF_POWERED // allow bootloaderconfig.h to override
93
+ #define USB_CFG_IS_SELF_POWERED 0
94
+ #endif
95
+ /* Define this to 1 if the device has its own power supply. Set it to 0 if the
96
+ * device is powered from the USB bus.
97
+ */
98
+ #ifndef USB_CFG_MAX_BUS_POWER // allow bootloaderconfig.h to override
99
+ #define USB_CFG_MAX_BUS_POWER 100
100
+ #endif
101
+ /* Set this variable to the maximum USB bus power consumption of your device.
102
+ * The value is in milliamperes. [It will be divided by two since USB
103
+ * communicates power requirements in units of 2 mA.]
104
+ */
105
+ #define USB_CFG_IMPLEMENT_FN_WRITE 1
106
+ /* Set this to 1 if you want usbFunctionWrite() to be called for control-out
107
+ * transfers. Set it to 0 if you don't need it and want to save a couple of
108
+ * bytes.
109
+ */
110
+ #define USB_CFG_IMPLEMENT_FN_READ 1
111
+ /* Set this to 1 if you need to send control replies which are generated
112
+ * "on the fly" when usbFunctionRead() is called. If you only want to send
113
+ * data from a static buffer, set it to 0 and return the data from
114
+ * usbFunctionSetup(). This saves a couple of bytes.
115
+ */
116
+ #define USB_CFG_IMPLEMENT_FN_WRITEOUT 0
117
+ /* Define this to 1 if you want to use interrupt-out (or bulk out) endpoints.
118
+ * You must implement the function usbFunctionWriteOut() which receives all
119
+ * interrupt/bulk data sent to any endpoint other than 0. The endpoint number
120
+ * can be found in 'usbRxToken'.
121
+ */
122
+ #define USB_CFG_HAVE_FLOWCONTROL 0
123
+ /* Define this to 1 if you want flowcontrol over USB data. See the definition
124
+ * of the macros usbDisableAllRequests() and usbEnableAllRequests() in
125
+ * usbdrv.h.
126
+ */
127
+ #define USB_CFG_DRIVER_FLASH_PAGE 0
128
+ /* If the device has more than 64 kBytes of flash, define this to the 64 k page
129
+ * where the driver's constants (descriptors) are located. Or in other words:
130
+ * Define this to 1 for boot loaders on the ATMega128.
131
+ */
132
+ #define USB_CFG_LONG_TRANSFERS 0
133
+ /* Define this to 1 if you want to send/receive blocks of more than 254 bytes
134
+ * in a single control-in or control-out transfer. Note that the capability
135
+ * for long transfers increases the driver size.
136
+ */
137
+ #ifndef __ASSEMBLER__
138
+ extern volatile char usbHasRxed;
139
+ #endif
140
+ #define USB_RX_USER_HOOK(data, len) do { usbHasRxed = 1; } while (0);
141
+ /* This macro is a hook if you want to do unconventional things. If it is
142
+ * defined, it's inserted at the beginning of received message processing.
143
+ * If you eat the received message and don't want default processing to
144
+ * proceed, do a return after doing your things. One possible application
145
+ * (besides debugging) is to flash a status LED on each packet.
146
+ */
147
+ /* #define USB_RESET_HOOK(resetStarts) if(!resetStarts){hadUsbReset();} */
148
+ /* This macro is a hook if you need to know when an USB RESET occurs. It has
149
+ * one parameter which distinguishes between the start of RESET state and its
150
+ * end.
151
+ */
152
+ /* #define USB_SET_ADDRESS_HOOK() hadAddressAssigned(); */
153
+ /* This macro (if defined) is executed when a USB SET_ADDRESS request was
154
+ * received.
155
+ */
156
+ #define USB_COUNT_SOF 0
157
+ /* define this macro to 1 if you need the global variable "usbSofCount" which
158
+ * counts SOF packets. This feature requires that the hardware interrupt is
159
+ * connected to D- instead of D+.
160
+ */
161
+ /* #ifdef __ASSEMBLER__
162
+ * macro myAssemblerMacro
163
+ * in YL, TCNT0
164
+ * sts timer0Snapshot, YL
165
+ * endm
166
+ * #endif
167
+ * #define USB_SOF_HOOK myAssemblerMacro
168
+ * This macro (if defined) is executed in the assembler module when a
169
+ * Start Of Frame condition is detected. It is recommended to define it to
170
+ * the name of an assembler macro which is defined here as well so that more
171
+ * than one assembler instruction can be used. The macro may use the register
172
+ * YL and modify SREG. If it lasts longer than a couple of cycles, USB messages
173
+ * immediately after an SOF pulse may be lost and must be retried by the host.
174
+ * What can you do with this hook? Since the SOF signal occurs exactly every
175
+ * 1 ms (unless the host is in sleep mode), you can use it to tune OSCCAL in
176
+ * designs running on the internal RC oscillator.
177
+ * Please note that Start Of Frame detection works only if D- is wired to the
178
+ * interrupt, not D+. THIS IS DIFFERENT THAN MOST EXAMPLES!
179
+ */
180
+ #define USB_CFG_CHECK_DATA_TOGGLING 0
181
+ /* define this macro to 1 if you want to filter out duplicate data packets
182
+ * sent by the host. Duplicates occur only as a consequence of communication
183
+ * errors, when the host does not receive an ACK. Please note that you need to
184
+ * implement the filtering yourself in usbFunctionWriteOut() and
185
+ * usbFunctionWrite(). Use the global usbCurrentDataToken and a static variable
186
+ * for each control- and out-endpoint to check for duplicate packets.
187
+ */
188
+ #define USB_CFG_HAVE_MEASURE_FRAME_LENGTH 1
189
+ /* define this macro to 1 if you want the function usbMeasureFrameLength()
190
+ * compiled in. This function can be used to calibrate the AVR's RC oscillator.
191
+ */
192
+ #define USB_USE_FAST_CRC 0
193
+ /* The assembler module has two implementations for the CRC algorithm. One is
194
+ * faster, the other is smaller. This CRC routine is only used for transmitted
195
+ * messages where timing is not critical. The faster routine needs 31 cycles
196
+ * per byte while the smaller one needs 61 to 69 cycles. The faster routine
197
+ * may be worth the 32 bytes bigger code size if you transmit lots of data and
198
+ * run the AVR close to its limit.
199
+ */
200
+
201
+ /* -------------------------- Device Description --------------------------- */
202
+
203
+ #define USB_CFG_VENDOR_ID 0x41, 0x23 /* = 0x16c0 = 5824 = voti.nl */
204
+ /* USB vendor ID for the device, low byte first. If you have registered your
205
+ * own Vendor ID, define it here. Otherwise you may use one of obdev's free
206
+ * shared VID/PID pairs. Be sure to read USB-IDs-for-free.txt for rules!
207
+ */
208
+ #define USB_CFG_DEVICE_ID 0x9F, 0x0c /* = 0x05dc = 1500 */
209
+ /* This is the ID of the product, low byte first. It is interpreted in the
210
+ * scope of the vendor ID. If you have registered your own VID with usb.org
211
+ * or if you have licensed a PID from somebody else, define it here. Otherwise
212
+ * you may use one of obdev's free shared VID/PID pairs. See the file
213
+ * USB-IDs-for-free.txt for details!
214
+ */
215
+ #define USB_CFG_DEVICE_VERSION 0x00, 0x01
216
+ /* Version number of the device: Minor number first, then major number.
217
+ */
218
+ #define USB_CFG_VENDOR_NAME 'A','r','d','u','i','n','o','.','c','c'
219
+ #define USB_CFG_VENDOR_NAME_LEN 10
220
+ /* These two values define the vendor name returned by the USB device. The name
221
+ * must be given as a list of characters under single quotes. The characters
222
+ * are interpreted as Unicode (UTF-16) entities.
223
+ * If you don't want a vendor name string, undefine these macros.
224
+ * ALWAYS define a vendor name containing your Internet domain name if you use
225
+ * obdev's free shared VID/PID pair. See the file USB-IDs-for-free.txt for
226
+ * details.
227
+ */
228
+ #define USB_CFG_DEVICE_NAME 'G','e','m','m','a'
229
+ #define USB_CFG_DEVICE_NAME_LEN 5
230
+ /* Same as above for the device name. If you don't want a device name, undefine
231
+ * the macros. See the file USB-IDs-for-free.txt before you assign a name if
232
+ * you use a shared VID/PID.
233
+ */
234
+ /*#define USB_CFG_SERIAL_NUMBER 'N', 'o', 'n', 'e' */
235
+ /*#define USB_CFG_SERIAL_NUMBER_LEN 0 */
236
+ /* Same as above for the serial number. If you don't want a serial number,
237
+ * undefine the macros.
238
+ * It may be useful to provide the serial number through other means than at
239
+ * compile time. See the section about descriptor properties below for how
240
+ * to fine tune control over USB descriptors such as the string descriptor
241
+ * for the serial number.
242
+ */
243
+ #define USB_CFG_DEVICE_CLASS 0xFF /* set to 0 if deferred to interface */
244
+ #define USB_CFG_DEVICE_SUBCLASS 0
245
+ /* See USB specification if you want to conform to an existing device class.
246
+ * Class 0xff is "vendor specific".
247
+ */
248
+ #define USB_CFG_INTERFACE_CLASS 0 /* define class here if not at device level */
249
+ #define USB_CFG_INTERFACE_SUBCLASS 0
250
+ #define USB_CFG_INTERFACE_PROTOCOL 0
251
+ /* See USB specification if you want to conform to an existing device class or
252
+ * protocol. The following classes must be set at interface level:
253
+ * HID class is 3, no subclass and protocol required (but may be useful!)
254
+ * CDC class is 2, use subclass 2 and protocol 1 for ACM
255
+ */
256
+ /* #define USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH 42 */
257
+ /* Define this to the length of the HID report descriptor, if you implement
258
+ * an HID device. Otherwise don't define it or define it to 0.
259
+ * If you use this define, you must add a PROGMEM character array named
260
+ * "usbHidReportDescriptor" to your code which contains the report descriptor.
261
+ * Don't forget to keep the array and this define in sync!
262
+ */
263
+
264
+ #define USB_PUBLIC static
265
+ /* Use the define above if you #include usbdrv.c instead of linking against it.
266
+ * This technique saves a couple of bytes in flash memory.
267
+ */
268
+
269
+ /* ------------------- Fine Control over USB Descriptors ------------------- */
270
+ /* If you don't want to use the driver's default USB descriptors, you can
271
+ * provide our own. These can be provided as (1) fixed length static data in
272
+ * flash memory, (2) fixed length static data in RAM or (3) dynamically at
273
+ * runtime in the function usbFunctionDescriptor(). See usbdrv.h for more
274
+ * information about this function.
275
+ * Descriptor handling is configured through the descriptor's properties. If
276
+ * no properties are defined or if they are 0, the default descriptor is used.
277
+ * Possible properties are:
278
+ * + USB_PROP_IS_DYNAMIC: The data for the descriptor should be fetched
279
+ * at runtime via usbFunctionDescriptor(). If the usbMsgPtr mechanism is
280
+ * used, the data is in FLASH by default. Add property USB_PROP_IS_RAM if
281
+ * you want RAM pointers.
282
+ * + USB_PROP_IS_RAM: The data returned by usbFunctionDescriptor() or found
283
+ * in static memory is in RAM, not in flash memory.
284
+ * + USB_PROP_LENGTH(len): If the data is in static memory (RAM or flash),
285
+ * the driver must know the descriptor's length. The descriptor itself is
286
+ * found at the address of a well known identifier (see below).
287
+ * List of static descriptor names (must be declared PROGMEM if in flash):
288
+ * char usbDescriptorDevice[];
289
+ * char usbDescriptorConfiguration[];
290
+ * char usbDescriptorHidReport[];
291
+ * char usbDescriptorString0[];
292
+ * int usbDescriptorStringVendor[];
293
+ * int usbDescriptorStringDevice[];
294
+ * int usbDescriptorStringSerialNumber[];
295
+ * Other descriptors can't be provided statically, they must be provided
296
+ * dynamically at runtime.
297
+ *
298
+ * Descriptor properties are or-ed or added together, e.g.:
299
+ * #define USB_CFG_DESCR_PROPS_DEVICE (USB_PROP_IS_RAM | USB_PROP_LENGTH(18))
300
+ *
301
+ * The following descriptors are defined:
302
+ * USB_CFG_DESCR_PROPS_DEVICE
303
+ * USB_CFG_DESCR_PROPS_CONFIGURATION
304
+ * USB_CFG_DESCR_PROPS_STRINGS
305
+ * USB_CFG_DESCR_PROPS_STRING_0
306
+ * USB_CFG_DESCR_PROPS_STRING_VENDOR
307
+ * USB_CFG_DESCR_PROPS_STRING_PRODUCT
308
+ * USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER
309
+ * USB_CFG_DESCR_PROPS_HID
310
+ * USB_CFG_DESCR_PROPS_HID_REPORT
311
+ * USB_CFG_DESCR_PROPS_UNKNOWN (for all descriptors not handled by the driver)
312
+ *
313
+ * Note about string descriptors: String descriptors are not just strings, they
314
+ * are Unicode strings prefixed with a 2 byte header. Example:
315
+ * int serialNumberDescriptor[] = {
316
+ * USB_STRING_DESCRIPTOR_HEADER(6),
317
+ * 'S', 'e', 'r', 'i', 'a', 'l'
318
+ * };
319
+ */
320
+
321
+ #define USB_CFG_DESCR_PROPS_DEVICE 0
322
+ #define USB_CFG_DESCR_PROPS_CONFIGURATION 0
323
+ #define USB_CFG_DESCR_PROPS_STRINGS 0
324
+ #define USB_CFG_DESCR_PROPS_STRING_0 0
325
+ #define USB_CFG_DESCR_PROPS_STRING_VENDOR 0
326
+ #define USB_CFG_DESCR_PROPS_STRING_PRODUCT 0
327
+ #define USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER 0
328
+ #define USB_CFG_DESCR_PROPS_HID 0
329
+ #define USB_CFG_DESCR_PROPS_HID_REPORT 0
330
+ #define USB_CFG_DESCR_PROPS_UNKNOWN 0
331
+
332
+ #define usbMsgPtr_t unsigned short // scalar type yields shortest code
333
+
334
+ /* ----------------------- Optional MCU Description ------------------------ */
335
+
336
+ /* The following configurations have working defaults in usbdrv.h. You
337
+ * usually don't need to set them explicitly. Only if you want to run
338
+ * the driver on a device which is not yet supported or with a compiler
339
+ * which is not fully supported (such as IAR C) or if you use a differnt
340
+ * interrupt than INT0, you may have to define some of these.
341
+ */
342
+ #define USB_INTR_CFG PCMSK
343
+ #define USB_INTR_CFG_SET (1 << USB_CFG_DPLUS_BIT)
344
+ #define USB_INTR_CFG_CLR 0
345
+ #define USB_INTR_ENABLE GIMSK
346
+ #define USB_INTR_ENABLE_BIT PCIE
347
+ #define USB_INTR_PENDING GIFR
348
+ #define USB_INTR_PENDING_BIT PCIF
349
+ #define USB_INTR_VECTOR PCINT0_vect
350
+
351
+ #endif /* __usbconfig_h_included__ */
hardware/arduino/avr/bootloaders/gemma/usbconfig.patch ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 203c203
2
+ < #define USB_CFG_VENDOR_ID 0x81, 0x17 /* = 0x16c0 = 5824 = voti.nl */
3
+ ---
4
+ > #define USB_CFG_VENDOR_ID 0x41, 0x23 /* = 0x16c0 = 5824 = voti.nl */
5
+ 208c208
6
+ < #define USB_CFG_DEVICE_ID 0x9F, 0x0C /* = 0x05dc = 1500 */
7
+ ---
8
+ > #define USB_CFG_DEVICE_ID 0x9F, 0x0c /* = 0x05dc = 1500 */
9
+ 215c215
10
+ < #define USB_CFG_DEVICE_VERSION 0x05, 0x01
11
+ ---
12
+ > #define USB_CFG_DEVICE_VERSION 0x00, 0x01
13
+ 218,219c218,219
14
+ < #define USB_CFG_VENDOR_NAME 'A','d','a','f','r','u','i','t'
15
+ < #define USB_CFG_VENDOR_NAME_LEN 8
16
+ ---
17
+ > #define USB_CFG_VENDOR_NAME 'A','r','d','u','i','n','o','.','c','c'
18
+ > #define USB_CFG_VENDOR_NAME_LEN 10
19
+ 228,229c228,229
20
+ < #define USB_CFG_DEVICE_NAME 'T','r','i','n','k','e','t'
21
+ < #define USB_CFG_DEVICE_NAME_LEN 7
22
+ ---
23
+ > #define USB_CFG_DEVICE_NAME 'G','e','m','m','a'
24
+ > #define USB_CFG_DEVICE_NAME_LEN 5
hardware/arduino/avr/bootloaders/lilypad/LilyPadBOOT_168.hex ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ :103800000C94341C0C944F1C0C944F1C0C944F1CA7
2
+ :103810000C944F1C0C944F1C0C944F1C0C944F1C7C
3
+ :103820000C944F1C0C944F1C0C944F1C0C944F1C6C
4
+ :103830000C944F1C0C944F1C0C944F1C0C944F1C5C
5
+ :103840000C944F1C0C944F1C0C944F1C0C944F1C4C
6
+ :103850000C944F1C0C944F1C0C944F1C0C944F1C3C
7
+ :103860000C944F1C0C944F1C11241FBECFEFD4E0BE
8
+ :10387000DEBFCDBF11E0A0E0B1E0E8E1FFE302C0B0
9
+ :1038800005900D92A230B107D9F712E0A2E0B1E0A5
10
+ :1038900001C01D92AD30B107E1F70C94311D0C94BD
11
+ :1038A000001CCF93DF93CDB7DEB724970FB6F89403
12
+ :1038B000DEBF0FBECDBF382F882309F433E010924E
13
+ :1038C0000A02332309F44BC020E02D9A19821A8290
14
+ :1038D0001B821C8289819A81AB81BC8180549F416B
15
+ :1038E000A040B040A0F489819A81AB81BC8101964F
16
+ :1038F000A11DB11D89839A83AB83BC8389819A8181
17
+ :10390000AB81BC8180549F41A040B04060F32D98B2
18
+ :1039100019821A821B821C8289819A81AB81BC81A7
19
+ :1039200080549F41A040B040A0F489819A81AB812E
20
+ :10393000BC810196A11DB11D89839A83AB83BC8391
21
+ :1039400089819A81AB81BC8180549F41A040B04065
22
+ :1039500060F32F5F231708F4B8CF20930A02249650
23
+ :103960000FB6F894DEBF0FBECDBFDF91CF910895A3
24
+ :10397000EF92FF920F931F93EE24FF248701809113
25
+ :10398000C00087FD17C00894E11CF11C011D111D2A
26
+ :1039900081E0E81689E0F8068DE3080780E0180763
27
+ :1039A00070F3E0910201F091030109958091C0004C
28
+ :1039B00087FFE9CF8091C600992787FD90951F91D9
29
+ :1039C0000F91FF90EF900895982F8091C00085FF90
30
+ :1039D000FCCF9093C60008950E94B81C803271F00D
31
+ :1039E000809104018F5F80930401853009F0089570
32
+ :1039F000E0910201F09103010995089584E10E948C
33
+ :103A0000E41C80E10E94E41C08951F93182F0E947B
34
+ :103A1000B81C803269F0809104018F5F80930401AB
35
+ :103A2000853079F4E0910201F0910301099509C014
36
+ :103A300084E10E94E41C812F0E94E41C80E10E942A
37
+ :103A4000E41C1F910895282F882351F090E0809165
38
+ :103A5000C00087FFFCCF8091C6009F5F2917B9F790
39
+ :103A60000895CFEFD4E0DEBFCDBF000089E18093A1
40
+ :103A7000C4001092C50088E18093C10086E0809365
41
+ :103A8000C2005098589A259A83E00E94511C0E94C7
42
+ :103A9000B81C8033B1F18133B9F1803409F454C0DA
43
+ :103AA000813409F45AC0823409F469C0853409F4B8
44
+ :103AB0006CC0803531F1813521F1823511F18535C8
45
+ :103AC00009F4B2C0863509F4BAC0843609F463C07B
46
+ :103AD000843709F4BBC0853709F40EC1863709F471
47
+ :103AE0004AC0809104018F5F80930401853079F68C
48
+ :103AF000E0910201F091030109950E94B81C803306
49
+ :103B000051F60E94EC1CC3CF0E94B81C803249F7CA
50
+ :103B100084E10E94E41C81E40E94E41C86E50E948A
51
+ :103B2000E41C82E50E94E41C80E20E94E41C89E41B
52
+ :103B30000E94E41C83E50E94E41C80E50E94E41CD2
53
+ :103B400080E10E94E41CA3CF0E94B81C8638C8F212
54
+ :103B50000E94B81C0E94EC1C9ACF0E94B81C8038AE
55
+ :103B600009F4F7C0813809F4F8C0823809F4F9C0C3
56
+ :103B7000883909F4BDC080E00E94051D88CF84E12A
57
+ :103B80000E94231D0E94EC1C82CF85E00E94231D11
58
+ :103B90000E94EC1C7CCF0E94B81C809309020E94FA
59
+ :103BA000B81C8093080280910C028E7F80930C02D7
60
+ :103BB0000E94B81C853409F4C6C080910802909117
61
+ :103BC0000902892B09F0ADC00E94B81C803209F0AF
62
+ :103BD00088CF80910C0280FFC8C08091080290912C
63
+ :103BE00009020097D1F02091060130910701E8E029
64
+ :103BF000F1E0AC014E0F5F1FF999FECF32BD21BD40
65
+ :103C0000819180BDFA9AF99A2F5F3F4F4E175F0757
66
+ :103C100099F7309307012093060184E10E94E41C88
67
+ :103C200080E10E94E41C33CF0E94B81C80930601FF
68
+ :103C30000E94B81C809307010E94EC1C28CF84E0EE
69
+ :103C40000E94231D80E00E94051D21CF0E94B81C08
70
+ :103C5000809309020E94B81C809308020E94B81C3D
71
+ :103C6000853409F4F4C080910C028E7F80930C029D
72
+ :103C70008091060190910701880F991F9093070189
73
+ :103C8000809306010E94B81C803209F000CF84E1C5
74
+ :103C90000E94E41C2091080230910902211531058F
75
+ :103CA00019F1C0E0D0E0E0910601F09107018091A8
76
+ :103CB0000C0280FFC4C0F999FECFF2BDE1BDF89AB5
77
+ :103CC00080B50E94E41CE0910601F0910701319655
78
+ :103CD000F0930701E0930601209108023091090258
79
+ :103CE0002196C217D30718F380E10E94E41CCFCEBF
80
+ :103CF00083E00E94051DCBCE0E94B81C803209F0E3
81
+ :103D0000F0CE84E10E94E41C8EE10E94E41C84E970
82
+ :103D10000E94E41C86E00E94E41C80E10E94E41CF6
83
+ :103D2000B6CEC0E0D0E008E011E00E94B81CF80177
84
+ :103D300081938F0121968091080290910902C81702
85
+ :103D4000D90798F341CF80910C02816080930C02D7
86
+ :103D500034CF82E00E94051D9ACE81E00E94051DAD
87
+ :103D600096CE80E10E94051D92CE8091070187FDCD
88
+ :103D700080C010920B028091060190910701880F7C
89
+ :103D8000991F90930701809306018091080280FF9C
90
+ :103D900009C080910802909109020196909309024E
91
+ :103DA00080930802F894F999FECF1127E09106015B
92
+ :103DB000F0910701C8E0D1E08091080290910902DA
93
+ :103DC000103091F40091570001700130D9F303E0F5
94
+ :103DD00000935700E8950091570001700130D9F326
95
+ :103DE00001E100935700E895099019900091570060
96
+ :103DF00001700130D9F301E000935700E895139565
97
+ :103E0000103498F011270091570001700130D9F358
98
+ :103E100005E000935700E8950091570001700130CC
99
+ :103E2000D9F301E100935700E8953296029709F023
100
+ :103E3000C7CF103011F00296E5CF1124EECE81FFEE
101
+ :103E40000CC03196F0930701E093060149CF8091B1
102
+ :103E50000C02816080930C0215CF84910E94E41CB7
103
+ :103E60002091080230910902E0910601F0910701CA
104
+ :103E7000E8CF81E080930B027ECF0F931F930E94C7
105
+ :103E8000B81C182F0E94E41C0E94B81C082F0E9426
106
+ :103E9000E41C11362CF0175501363CF0075508C0CC
107
+ :103EA0001033D4F310530136CCF700330CF0005329
108
+ :103EB0001295107F100F812F992787FD90951F91E4
109
+ :103EC0000F9108951F93282F992787FD9095807F44
110
+ :103ED00090709595879595958795959587959595E6
111
+ :103EE00087958A304CF0982F995A822F8F708A309C
112
+ :103EF0004CF0182F195A08C0982F905D822F8F70A0
113
+ :103F00008A30BCF7182F105D892F0E94E41C812F86
114
+ :083F10000E94E41C1F910895BA
115
+ :023F1800800027
116
+ :0400000300003800C1
117
+ :00000001FF
hardware/arduino/avr/bootloaders/lilypad/src/ATmegaBOOT.c ADDED
@@ -0,0 +1,977 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**********************************************************/
2
+ /* Serial Bootloader for Atmel megaAVR Controllers */
3
+ /* */
4
+ /* tested with ATmega8, ATmega128 and ATmega168 */
5
+ /* should work with other mega's, see code for details */
6
+ /* */
7
+ /* ATmegaBOOT.c */
8
+ /* */
9
+ /* 20070626: hacked for Arduino Diecimila (which auto- */
10
+ /* resets when a USB connection is made to it) */
11
+ /* by D. Mellis */
12
+ /* 20060802: hacked for Arduino by D. Cuartielles */
13
+ /* based on a previous hack by D. Mellis */
14
+ /* and D. Cuartielles */
15
+ /* */
16
+ /* Monitor and debug functions were added to the original */
17
+ /* code by Dr. Erik Lins, chip45.com. (See below) */
18
+ /* */
19
+ /* Thanks to Karl Pitrich for fixing a bootloader pin */
20
+ /* problem and more informative LED blinking! */
21
+ /* */
22
+ /* For the latest version see: */
23
+ /* http://www.chip45.com/ */
24
+ /* */
25
+ /* ------------------------------------------------------ */
26
+ /* */
27
+ /* based on stk500boot.c */
28
+ /* Copyright (c) 2003, Jason P. Kyle */
29
+ /* All rights reserved. */
30
+ /* see avr1.org for original file and information */
31
+ /* */
32
+ /* This program is free software; you can redistribute it */
33
+ /* and/or modify it under the terms of the GNU General */
34
+ /* Public License as published by the Free Software */
35
+ /* Foundation; either version 2 of the License, or */
36
+ /* (at your option) any later version. */
37
+ /* */
38
+ /* This program is distributed in the hope that it will */
39
+ /* be useful, but WITHOUT ANY WARRANTY; without even the */
40
+ /* implied warranty of MERCHANTABILITY or FITNESS FOR A */
41
+ /* PARTICULAR PURPOSE. See the GNU General Public */
42
+ /* License for more details. */
43
+ /* */
44
+ /* You should have received a copy of the GNU General */
45
+ /* Public License along with this program; if not, write */
46
+ /* to the Free Software Foundation, Inc., */
47
+ /* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
48
+ /* */
49
+ /* Licence can be viewed at */
50
+ /* http://www.fsf.org/licenses/gpl.txt */
51
+ /* */
52
+ /* Target = Atmel AVR m128,m64,m32,m16,m8,m162,m163,m169, */
53
+ /* m8515,m8535. ATmega161 has a very small boot block so */
54
+ /* isn't supported. */
55
+ /* */
56
+ /* Tested with m168 */
57
+ /**********************************************************/
58
+
59
+
60
+ /* some includes */
61
+ #include <inttypes.h>
62
+ #include <avr/io.h>
63
+ #include <avr/pgmspace.h>
64
+ #include <avr/interrupt.h>
65
+ #include <avr/wdt.h>
66
+
67
+
68
+ /* the current avr-libc eeprom functions do not support the ATmega168 */
69
+ /* own eeprom write/read functions are used instead */
70
+ #ifndef __AVR_ATmega168__
71
+ #include <avr/eeprom.h>
72
+ #endif
73
+
74
+ /* Use the F_CPU defined in Makefile */
75
+
76
+ /* 20060803: hacked by DojoCorp */
77
+ /* 20070626: hacked by David A. Mellis to decrease waiting time for auto-reset */
78
+ /* set the waiting time for the bootloader */
79
+ /* get this from the Makefile instead */
80
+ /* #define MAX_TIME_COUNT (F_CPU>>4) */
81
+
82
+ /* 20070707: hacked by David A. Mellis - after this many errors give up and launch application */
83
+ #define MAX_ERROR_COUNT 5
84
+
85
+ /* set the UART baud rate */
86
+ /* 20060803: hacked by DojoCorp */
87
+ //#define BAUD_RATE 115200
88
+ #define BAUD_RATE 19200
89
+
90
+
91
+ /* SW_MAJOR and MINOR needs to be updated from time to time to avoid warning message from AVR Studio */
92
+ /* never allow AVR Studio to do an update !!!! */
93
+ #define HW_VER 0x02
94
+ #define SW_MAJOR 0x01
95
+ #define SW_MINOR 0x10
96
+
97
+
98
+ /* Adjust to suit whatever pin your hardware uses to enter the bootloader */
99
+ /* ATmega128 has two UARTS so two pins are used to enter bootloader and select UART */
100
+ /* BL0... means UART0, BL1... means UART1 */
101
+ #ifdef __AVR_ATmega128__
102
+ #define BL_DDR DDRF
103
+ #define BL_PORT PORTF
104
+ #define BL_PIN PINF
105
+ #define BL0 PINF7
106
+ #define BL1 PINF6
107
+ #else
108
+ /* other ATmegas have only one UART, so only one pin is defined to enter bootloader */
109
+ #define BL_DDR DDRD
110
+ #define BL_PORT PORTD
111
+ #define BL_PIN PIND
112
+ #define BL PIND6
113
+ #endif
114
+
115
+
116
+ /* onboard LED is used to indicate, that the bootloader was entered (3x flashing) */
117
+ /* if monitor functions are included, LED goes on after monitor was entered */
118
+ #ifdef __AVR_ATmega128__
119
+ /* Onboard LED is connected to pin PB7 (e.g. Crumb128, PROBOmega128, Savvy128) */
120
+ #define LED_DDR DDRB
121
+ #define LED_PORT PORTB
122
+ #define LED_PIN PINB
123
+ #define LED PINB7
124
+ #else
125
+ /* Onboard LED is connected to pin PB2 (e.g. Crumb8, Crumb168) */
126
+ #define LED_DDR DDRB
127
+ #define LED_PORT PORTB
128
+ #define LED_PIN PINB
129
+ /* 20060803: hacked by DojoCorp, LED pin is B5 in Arduino */
130
+ /* #define LED PINB2 */
131
+ #define LED PINB5
132
+ #endif
133
+
134
+
135
+ /* monitor functions will only be compiled when using ATmega128, due to bootblock size constraints */
136
+ #ifdef __AVR_ATmega128__
137
+ #define MONITOR
138
+ #endif
139
+
140
+
141
+ /* define various device id's */
142
+ /* manufacturer byte is always the same */
143
+ #define SIG1 0x1E // Yep, Atmel is the only manufacturer of AVR micros. Single source :(
144
+
145
+ #if defined __AVR_ATmega128__
146
+ #define SIG2 0x97
147
+ #define SIG3 0x02
148
+ #define PAGE_SIZE 0x80U //128 words
149
+
150
+ #elif defined __AVR_ATmega64__
151
+ #define SIG2 0x96
152
+ #define SIG3 0x02
153
+ #define PAGE_SIZE 0x80U //128 words
154
+
155
+ #elif defined __AVR_ATmega32__
156
+ #define SIG2 0x95
157
+ #define SIG3 0x02
158
+ #define PAGE_SIZE 0x40U //64 words
159
+
160
+ #elif defined __AVR_ATmega16__
161
+ #define SIG2 0x94
162
+ #define SIG3 0x03
163
+ #define PAGE_SIZE 0x40U //64 words
164
+
165
+ #elif defined __AVR_ATmega8__
166
+ #define SIG2 0x93
167
+ #define SIG3 0x07
168
+ #define PAGE_SIZE 0x20U //32 words
169
+
170
+ #elif defined __AVR_ATmega88__
171
+ #define SIG2 0x93
172
+ #define SIG3 0x0a
173
+ #define PAGE_SIZE 0x20U //32 words
174
+
175
+ #elif defined __AVR_ATmega168__
176
+ #define SIG2 0x94
177
+ #define SIG3 0x06
178
+ #define PAGE_SIZE 0x40U //64 words
179
+
180
+ #elif defined __AVR_ATmega162__
181
+ #define SIG2 0x94
182
+ #define SIG3 0x04
183
+ #define PAGE_SIZE 0x40U //64 words
184
+
185
+ #elif defined __AVR_ATmega163__
186
+ #define SIG2 0x94
187
+ #define SIG3 0x02
188
+ #define PAGE_SIZE 0x40U //64 words
189
+
190
+ #elif defined __AVR_ATmega169__
191
+ #define SIG2 0x94
192
+ #define SIG3 0x05
193
+ #define PAGE_SIZE 0x40U //64 words
194
+
195
+ #elif defined __AVR_ATmega8515__
196
+ #define SIG2 0x93
197
+ #define SIG3 0x06
198
+ #define PAGE_SIZE 0x20U //32 words
199
+
200
+ #elif defined __AVR_ATmega8535__
201
+ #define SIG2 0x93
202
+ #define SIG3 0x08
203
+ #define PAGE_SIZE 0x20U //32 words
204
+ #endif
205
+
206
+
207
+ /* function prototypes */
208
+ void putch(char);
209
+ char getch(void);
210
+ void getNch(uint8_t);
211
+ void byte_response(uint8_t);
212
+ void nothing_response(void);
213
+ char gethex(void);
214
+ void puthex(char);
215
+ void flash_led(uint8_t);
216
+
217
+ /* some variables */
218
+ union address_union {
219
+ uint16_t word;
220
+ uint8_t byte[2];
221
+ } address;
222
+
223
+ union length_union {
224
+ uint16_t word;
225
+ uint8_t byte[2];
226
+ } length;
227
+
228
+ struct flags_struct {
229
+ unsigned eeprom : 1;
230
+ unsigned rampz : 1;
231
+ } flags;
232
+
233
+ uint8_t buff[256];
234
+ uint8_t address_high;
235
+
236
+ uint8_t pagesz=0x80;
237
+
238
+ uint8_t i;
239
+ uint8_t bootuart = 0;
240
+
241
+ uint8_t error_count = 0;
242
+
243
+ void (*app_start)(void) = 0x0000;
244
+
245
+
246
+ /* main program starts here */
247
+ int main(void)
248
+ {
249
+ uint8_t ch,ch2;
250
+ uint16_t w;
251
+
252
+ asm volatile("nop\n\t");
253
+
254
+ /* set pin direction for bootloader pin and enable pullup */
255
+ /* for ATmega128, two pins need to be initialized */
256
+ #ifdef __AVR_ATmega128__
257
+ BL_DDR &= ~_BV(BL0);
258
+ BL_DDR &= ~_BV(BL1);
259
+ BL_PORT |= _BV(BL0);
260
+ BL_PORT |= _BV(BL1);
261
+ #else
262
+ /* We run the bootloader regardless of the state of this pin. Thus, don't
263
+ put it in a different state than the other pins. --DAM, 070709
264
+ BL_DDR &= ~_BV(BL);
265
+ BL_PORT |= _BV(BL);
266
+ */
267
+ #endif
268
+
269
+
270
+ #ifdef __AVR_ATmega128__
271
+ /* check which UART should be used for booting */
272
+ if(bit_is_clear(BL_PIN, BL0)) {
273
+ bootuart = 1;
274
+ }
275
+ else if(bit_is_clear(BL_PIN, BL1)) {
276
+ bootuart = 2;
277
+ }
278
+ #endif
279
+
280
+ /* check if flash is programmed already, if not start bootloader anyway */
281
+ if(pgm_read_byte_near(0x0000) != 0xFF) {
282
+
283
+ #ifdef __AVR_ATmega128__
284
+ /* no UART was selected, start application */
285
+ if(!bootuart) {
286
+ app_start();
287
+ }
288
+ #else
289
+ /* check if bootloader pin is set low */
290
+ /* we don't start this part neither for the m8, nor m168 */
291
+ //if(bit_is_set(BL_PIN, BL)) {
292
+ // app_start();
293
+ // }
294
+ #endif
295
+ }
296
+
297
+ #ifdef __AVR_ATmega128__
298
+ /* no bootuart was selected, default to uart 0 */
299
+ if(!bootuart) {
300
+ bootuart = 1;
301
+ }
302
+ #endif
303
+
304
+
305
+ /* initialize UART(s) depending on CPU defined */
306
+ #ifdef __AVR_ATmega128__
307
+ if(bootuart == 1) {
308
+ UBRR0L = (uint8_t)(F_CPU/(BAUD_RATE*16L)-1);
309
+ UBRR0H = (F_CPU/(BAUD_RATE*16L)-1) >> 8;
310
+ UCSR0A = 0x00;
311
+ UCSR0C = 0x06;
312
+ UCSR0B = _BV(TXEN0)|_BV(RXEN0);
313
+ }
314
+ if(bootuart == 2) {
315
+ UBRR1L = (uint8_t)(F_CPU/(BAUD_RATE*16L)-1);
316
+ UBRR1H = (F_CPU/(BAUD_RATE*16L)-1) >> 8;
317
+ UCSR1A = 0x00;
318
+ UCSR1C = 0x06;
319
+ UCSR1B = _BV(TXEN1)|_BV(RXEN1);
320
+ }
321
+ #elif defined __AVR_ATmega163__
322
+ UBRR = (uint8_t)(F_CPU/(BAUD_RATE*16L)-1);
323
+ UBRRHI = (F_CPU/(BAUD_RATE*16L)-1) >> 8;
324
+ UCSRA = 0x00;
325
+ UCSRB = _BV(TXEN)|_BV(RXEN);
326
+ #elif defined __AVR_ATmega168__
327
+ UBRR0L = (uint8_t)(F_CPU/(BAUD_RATE*16L)-1);
328
+ UBRR0H = (F_CPU/(BAUD_RATE*16L)-1) >> 8;
329
+ UCSR0B = (1<<RXEN0) | (1<<TXEN0);
330
+ UCSR0C = (1<<UCSZ00) | (1<<UCSZ01);
331
+
332
+ /* Enable internal pull-up resistor on pin D0 (RX), in order
333
+ to supress line noise that prevents the bootloader from
334
+ timing out (DAM: 20070509) */
335
+ DDRD &= ~_BV(PIND0);
336
+ PORTD |= _BV(PIND0);
337
+ #elif defined __AVR_ATmega8__
338
+ /* m8 */
339
+ UBRRH = (((F_CPU/BAUD_RATE)/16)-1)>>8; // set baud rate
340
+ UBRRL = (((F_CPU/BAUD_RATE)/16)-1);
341
+ UCSRB = (1<<RXEN)|(1<<TXEN); // enable Rx & Tx
342
+ UCSRC = (1<<URSEL)|(1<<UCSZ1)|(1<<UCSZ0); // config USART; 8N1
343
+ #else
344
+ /* m16,m32,m169,m8515,m8535 */
345
+ UBRRL = (uint8_t)(F_CPU/(BAUD_RATE*16L)-1);
346
+ UBRRH = (F_CPU/(BAUD_RATE*16L)-1) >> 8;
347
+ UCSRA = 0x00;
348
+ UCSRC = 0x06;
349
+ UCSRB = _BV(TXEN)|_BV(RXEN);
350
+ #endif
351
+
352
+ /* set LED pin as output */
353
+ LED_DDR |= _BV(LED);
354
+
355
+
356
+ /* flash onboard LED to signal entering of bootloader */
357
+ #ifdef __AVR_ATmega128__
358
+ // 4x for UART0, 5x for UART1
359
+ flash_led(NUM_LED_FLASHES + bootuart);
360
+ #else
361
+ flash_led(NUM_LED_FLASHES);
362
+ #endif
363
+
364
+ /* 20050803: by DojoCorp, this is one of the parts provoking the
365
+ system to stop listening, cancelled from the original */
366
+ //putch('\0');
367
+
368
+
369
+ /* forever loop */
370
+ for (;;) {
371
+
372
+ /* get character from UART */
373
+ ch = getch();
374
+
375
+ /* A bunch of if...else if... gives smaller code than switch...case ! */
376
+
377
+ /* Hello is anyone home ? */
378
+ if(ch=='0') {
379
+ nothing_response();
380
+ }
381
+
382
+
383
+ /* Request programmer ID */
384
+ /* Not using PROGMEM string due to boot block in m128 being beyond 64kB boundry */
385
+ /* Would need to selectively manipulate RAMPZ, and it's only 9 characters anyway so who cares. */
386
+ else if(ch=='1') {
387
+ if (getch() == ' ') {
388
+ putch(0x14);
389
+ putch('A');
390
+ putch('V');
391
+ putch('R');
392
+ putch(' ');
393
+ putch('I');
394
+ putch('S');
395
+ putch('P');
396
+ putch(0x10);
397
+ } else {
398
+ if (++error_count == MAX_ERROR_COUNT)
399
+ app_start();
400
+ }
401
+ }
402
+
403
+
404
+ /* AVR ISP/STK500 board commands DON'T CARE so default nothing_response */
405
+ else if(ch=='@') {
406
+ ch2 = getch();
407
+ if (ch2>0x85) getch();
408
+ nothing_response();
409
+ }
410
+
411
+
412
+ /* AVR ISP/STK500 board requests */
413
+ else if(ch=='A') {
414
+ ch2 = getch();
415
+ if(ch2==0x80) byte_response(HW_VER); // Hardware version
416
+ else if(ch2==0x81) byte_response(SW_MAJOR); // Software major version
417
+ else if(ch2==0x82) byte_response(SW_MINOR); // Software minor version
418
+ else if(ch2==0x98) byte_response(0x03); // Unknown but seems to be required by avr studio 3.56
419
+ else byte_response(0x00); // Covers various unnecessary responses we don't care about
420
+ }
421
+
422
+
423
+ /* Device Parameters DON'T CARE, DEVICE IS FIXED */
424
+ else if(ch=='B') {
425
+ getNch(20);
426
+ nothing_response();
427
+ }
428
+
429
+
430
+ /* Parallel programming stuff DON'T CARE */
431
+ else if(ch=='E') {
432
+ getNch(5);
433
+ nothing_response();
434
+ }
435
+
436
+
437
+ /* Enter programming mode */
438
+ else if(ch=='P') {
439
+ nothing_response();
440
+ }
441
+
442
+
443
+ /* Leave programming mode */
444
+ else if(ch=='Q') {
445
+ nothing_response();
446
+ }
447
+
448
+
449
+ /* Erase device, don't care as we will erase one page at a time anyway. */
450
+ else if(ch=='R') {
451
+ nothing_response();
452
+ }
453
+
454
+
455
+ /* Set address, little endian. EEPROM in bytes, FLASH in words */
456
+ /* Perhaps extra address bytes may be added in future to support > 128kB FLASH. */
457
+ /* This might explain why little endian was used here, big endian used everywhere else. */
458
+ else if(ch=='U') {
459
+ address.byte[0] = getch();
460
+ address.byte[1] = getch();
461
+ nothing_response();
462
+ }
463
+
464
+
465
+ /* Universal SPI programming command, disabled. Would be used for fuses and lock bits. */
466
+ else if(ch=='V') {
467
+ getNch(4);
468
+ byte_response(0x00);
469
+ }
470
+
471
+
472
+ /* Write memory, length is big endian and is in bytes */
473
+ else if(ch=='d') {
474
+ length.byte[1] = getch();
475
+ length.byte[0] = getch();
476
+ flags.eeprom = 0;
477
+ if (getch() == 'E') flags.eeprom = 1;
478
+ for (w=0;w<length.word;w++) {
479
+ buff[w] = getch(); // Store data in buffer, can't keep up with serial data stream whilst programming pages
480
+ }
481
+ if (getch() == ' ') {
482
+ if (flags.eeprom) { //Write to EEPROM one byte at a time
483
+ for(w=0;w<length.word;w++) {
484
+ #ifdef __AVR_ATmega168__
485
+ while(EECR & (1<<EEPE));
486
+ EEAR = (uint16_t)(void *)address.word;
487
+ EEDR = buff[w];
488
+ EECR |= (1<<EEMPE);
489
+ EECR |= (1<<EEPE);
490
+ #else
491
+ eeprom_write_byte((void *)address.word,buff[w]);
492
+ #endif
493
+ address.word++;
494
+ }
495
+ }
496
+ else { //Write to FLASH one page at a time
497
+ if (address.byte[1]>127) address_high = 0x01; //Only possible with m128, m256 will need 3rd address byte. FIXME
498
+ else address_high = 0x00;
499
+ #ifdef __AVR_ATmega128__
500
+ RAMPZ = address_high;
501
+ #endif
502
+ address.word = address.word << 1; //address * 2 -> byte location
503
+ /* if ((length.byte[0] & 0x01) == 0x01) length.word++; //Even up an odd number of bytes */
504
+ if ((length.byte[0] & 0x01)) length.word++; //Even up an odd number of bytes
505
+ cli(); //Disable interrupts, just to be sure
506
+ // HACKME: EEPE used to be EEWE
507
+ while(bit_is_set(EECR,EEPE)); //Wait for previous EEPROM writes to complete
508
+ asm volatile(
509
+ "clr r17 \n\t" //page_word_count
510
+ "lds r30,address \n\t" //Address of FLASH location (in bytes)
511
+ "lds r31,address+1 \n\t"
512
+ "ldi r28,lo8(buff) \n\t" //Start of buffer array in RAM
513
+ "ldi r29,hi8(buff) \n\t"
514
+ "lds r24,length \n\t" //Length of data to be written (in bytes)
515
+ "lds r25,length+1 \n\t"
516
+ "length_loop: \n\t" //Main loop, repeat for number of words in block
517
+ "cpi r17,0x00 \n\t" //If page_word_count=0 then erase page
518
+ "brne no_page_erase \n\t"
519
+ "wait_spm1: \n\t"
520
+ "lds r16,%0 \n\t" //Wait for previous spm to complete
521
+ "andi r16,1 \n\t"
522
+ "cpi r16,1 \n\t"
523
+ "breq wait_spm1 \n\t"
524
+ "ldi r16,0x03 \n\t" //Erase page pointed to by Z
525
+ "sts %0,r16 \n\t"
526
+ "spm \n\t"
527
+ #ifdef __AVR_ATmega163__
528
+ ".word 0xFFFF \n\t"
529
+ "nop \n\t"
530
+ #endif
531
+ "wait_spm2: \n\t"
532
+ "lds r16,%0 \n\t" //Wait for previous spm to complete
533
+ "andi r16,1 \n\t"
534
+ "cpi r16,1 \n\t"
535
+ "breq wait_spm2 \n\t"
536
+
537
+ "ldi r16,0x11 \n\t" //Re-enable RWW section
538
+ "sts %0,r16 \n\t"
539
+ "spm \n\t"
540
+ #ifdef __AVR_ATmega163__
541
+ ".word 0xFFFF \n\t"
542
+ "nop \n\t"
543
+ #endif
544
+ "no_page_erase: \n\t"
545
+ "ld r0,Y+ \n\t" //Write 2 bytes into page buffer
546
+ "ld r1,Y+ \n\t"
547
+
548
+ "wait_spm3: \n\t"
549
+ "lds r16,%0 \n\t" //Wait for previous spm to complete
550
+ "andi r16,1 \n\t"
551
+ "cpi r16,1 \n\t"
552
+ "breq wait_spm3 \n\t"
553
+ "ldi r16,0x01 \n\t" //Load r0,r1 into FLASH page buffer
554
+ "sts %0,r16 \n\t"
555
+ "spm \n\t"
556
+
557
+ "inc r17 \n\t" //page_word_count++
558
+ "cpi r17,%1 \n\t"
559
+ "brlo same_page \n\t" //Still same page in FLASH
560
+ "write_page: \n\t"
561
+ "clr r17 \n\t" //New page, write current one first
562
+ "wait_spm4: \n\t"
563
+ "lds r16,%0 \n\t" //Wait for previous spm to complete
564
+ "andi r16,1 \n\t"
565
+ "cpi r16,1 \n\t"
566
+ "breq wait_spm4 \n\t"
567
+ #ifdef __AVR_ATmega163__
568
+ "andi r30,0x80 \n\t" // m163 requires Z6:Z1 to be zero during page write
569
+ #endif
570
+ "ldi r16,0x05 \n\t" //Write page pointed to by Z
571
+ "sts %0,r16 \n\t"
572
+ "spm \n\t"
573
+ #ifdef __AVR_ATmega163__
574
+ ".word 0xFFFF \n\t"
575
+ "nop \n\t"
576
+ "ori r30,0x7E \n\t" // recover Z6:Z1 state after page write (had to be zero during write)
577
+ #endif
578
+ "wait_spm5: \n\t"
579
+ "lds r16,%0 \n\t" //Wait for previous spm to complete
580
+ "andi r16,1 \n\t"
581
+ "cpi r16,1 \n\t"
582
+ "breq wait_spm5 \n\t"
583
+ "ldi r16,0x11 \n\t" //Re-enable RWW section
584
+ "sts %0,r16 \n\t"
585
+ "spm \n\t"
586
+ #ifdef __AVR_ATmega163__
587
+ ".word 0xFFFF \n\t"
588
+ "nop \n\t"
589
+ #endif
590
+ "same_page: \n\t"
591
+ "adiw r30,2 \n\t" //Next word in FLASH
592
+ "sbiw r24,2 \n\t" //length-2
593
+ "breq final_write \n\t" //Finished
594
+ "rjmp length_loop \n\t"
595
+ "final_write: \n\t"
596
+ "cpi r17,0 \n\t"
597
+ "breq block_done \n\t"
598
+ "adiw r24,2 \n\t" //length+2, fool above check on length after short page write
599
+ "rjmp write_page \n\t"
600
+ "block_done: \n\t"
601
+ "clr __zero_reg__ \n\t" //restore zero register
602
+ #if defined __AVR_ATmega168__
603
+ : "=m" (SPMCSR) : "M" (PAGE_SIZE) : "r0","r16","r17","r24","r25","r28","r29","r30","r31"
604
+ #else
605
+ : "=m" (SPMCR) : "M" (PAGE_SIZE) : "r0","r16","r17","r24","r25","r28","r29","r30","r31"
606
+ #endif
607
+ );
608
+ /* Should really add a wait for RWW section to be enabled, don't actually need it since we never */
609
+ /* exit the bootloader without a power cycle anyhow */
610
+ }
611
+ putch(0x14);
612
+ putch(0x10);
613
+ } else {
614
+ if (++error_count == MAX_ERROR_COUNT)
615
+ app_start();
616
+ }
617
+ }
618
+
619
+
620
+ /* Read memory block mode, length is big endian. */
621
+ else if(ch=='t') {
622
+ length.byte[1] = getch();
623
+ length.byte[0] = getch();
624
+ #if defined __AVR_ATmega128__
625
+ if (address.word>0x7FFF) flags.rampz = 1; // No go with m256, FIXME
626
+ else flags.rampz = 0;
627
+ #endif
628
+ if (getch() == 'E') flags.eeprom = 1;
629
+ else {
630
+ flags.eeprom = 0;
631
+ address.word = address.word << 1; // address * 2 -> byte location
632
+ }
633
+ if (getch() == ' ') { // Command terminator
634
+ putch(0x14);
635
+ for (w=0;w < length.word;w++) { // Can handle odd and even lengths okay
636
+ if (flags.eeprom) { // Byte access EEPROM read
637
+ #ifdef __AVR_ATmega168__
638
+ while(EECR & (1<<EEPE));
639
+ EEAR = (uint16_t)(void *)address.word;
640
+ EECR |= (1<<EERE);
641
+ putch(EEDR);
642
+ #else
643
+ putch(eeprom_read_byte((void *)address.word));
644
+ #endif
645
+ address.word++;
646
+ }
647
+ else {
648
+
649
+ if (!flags.rampz) putch(pgm_read_byte_near(address.word));
650
+ #if defined __AVR_ATmega128__
651
+ else putch(pgm_read_byte_far(address.word + 0x10000));
652
+ // Hmmmm, yuck FIXME when m256 arrvies
653
+ #endif
654
+ address.word++;
655
+ }
656
+ }
657
+ putch(0x10);
658
+ }
659
+ }
660
+
661
+
662
+ /* Get device signature bytes */
663
+ else if(ch=='u') {
664
+ if (getch() == ' ') {
665
+ putch(0x14);
666
+ putch(SIG1);
667
+ putch(SIG2);
668
+ putch(SIG3);
669
+ putch(0x10);
670
+ } else {
671
+ if (++error_count == MAX_ERROR_COUNT)
672
+ app_start();
673
+ }
674
+ }
675
+
676
+
677
+ /* Read oscillator calibration byte */
678
+ else if(ch=='v') {
679
+ byte_response(0x00);
680
+ }
681
+
682
+
683
+ #ifdef MONITOR
684
+
685
+ /* here come the extended monitor commands by Erik Lins */
686
+
687
+ /* check for three times exclamation mark pressed */
688
+ else if(ch=='!') {
689
+ ch = getch();
690
+ if(ch=='!') {
691
+ ch = getch();
692
+ if(ch=='!') {
693
+
694
+ #ifdef __AVR_ATmega128__
695
+ uint16_t extaddr;
696
+ #endif
697
+ uint8_t addrl, addrh;
698
+
699
+ #ifdef CRUMB128
700
+ PGM_P welcome = {"ATmegaBOOT / Crumb128 - (C) J.P.Kyle, E.Lins - 050815\n\r"};
701
+ #elif defined PROBOMEGA128
702
+ PGM_P welcome = {"ATmegaBOOT / PROBOmega128 - (C) J.P.Kyle, E.Lins - 050815\n\r"};
703
+ #elif defined SAVVY128
704
+ PGM_P welcome = {"ATmegaBOOT / Savvy128 - (C) J.P.Kyle, E.Lins - 050815\n\r"};
705
+ #endif
706
+
707
+ /* turn on LED */
708
+ LED_DDR |= _BV(LED);
709
+ LED_PORT &= ~_BV(LED);
710
+
711
+ /* print a welcome message and command overview */
712
+ for(i=0; welcome[i] != '\0'; ++i) {
713
+ putch(welcome[i]);
714
+ }
715
+
716
+ /* test for valid commands */
717
+ for(;;) {
718
+ putch('\n');
719
+ putch('\r');
720
+ putch(':');
721
+ putch(' ');
722
+
723
+ ch = getch();
724
+ putch(ch);
725
+
726
+ /* toggle LED */
727
+ if(ch == 't') {
728
+ if(bit_is_set(LED_PIN,LED)) {
729
+ LED_PORT &= ~_BV(LED);
730
+ putch('1');
731
+ } else {
732
+ LED_PORT |= _BV(LED);
733
+ putch('0');
734
+ }
735
+
736
+ }
737
+
738
+ /* read byte from address */
739
+ else if(ch == 'r') {
740
+ ch = getch(); putch(ch);
741
+ addrh = gethex();
742
+ addrl = gethex();
743
+ putch('=');
744
+ ch = *(uint8_t *)((addrh << 8) + addrl);
745
+ puthex(ch);
746
+ }
747
+
748
+ /* write a byte to address */
749
+ else if(ch == 'w') {
750
+ ch = getch(); putch(ch);
751
+ addrh = gethex();
752
+ addrl = gethex();
753
+ ch = getch(); putch(ch);
754
+ ch = gethex();
755
+ *(uint8_t *)((addrh << 8) + addrl) = ch;
756
+
757
+ }
758
+
759
+ /* read from uart and echo back */
760
+ else if(ch == 'u') {
761
+ for(;;) {
762
+ putch(getch());
763
+ }
764
+ }
765
+ #ifdef __AVR_ATmega128__
766
+ /* external bus loop */
767
+ else if(ch == 'b') {
768
+ putch('b');
769
+ putch('u');
770
+ putch('s');
771
+ MCUCR = 0x80;
772
+ XMCRA = 0;
773
+ XMCRB = 0;
774
+ extaddr = 0x1100;
775
+ for(;;) {
776
+ ch = *(volatile uint8_t *)extaddr;
777
+ if(++extaddr == 0) {
778
+ extaddr = 0x1100;
779
+ }
780
+ }
781
+ }
782
+ #endif
783
+
784
+ else if(ch == 'j') {
785
+ app_start();
786
+ }
787
+
788
+ }
789
+ /* end of monitor functions */
790
+
791
+ }
792
+ }
793
+ }
794
+ /* end of monitor */
795
+ #endif
796
+ else if (++error_count == MAX_ERROR_COUNT) {
797
+ app_start();
798
+ }
799
+ }
800
+ /* end of forever loop */
801
+
802
+ }
803
+
804
+
805
+ char gethex(void) {
806
+ char ah,al;
807
+
808
+ ah = getch(); putch(ah);
809
+ al = getch(); putch(al);
810
+ if(ah >= 'a') {
811
+ ah = ah - 'a' + 0x0a;
812
+ } else if(ah >= '0') {
813
+ ah -= '0';
814
+ }
815
+ if(al >= 'a') {
816
+ al = al - 'a' + 0x0a;
817
+ } else if(al >= '0') {
818
+ al -= '0';
819
+ }
820
+ return (ah << 4) + al;
821
+ }
822
+
823
+
824
+ void puthex(char ch) {
825
+ char ah,al;
826
+
827
+ ah = (ch & 0xf0) >> 4;
828
+ if(ah >= 0x0a) {
829
+ ah = ah - 0x0a + 'a';
830
+ } else {
831
+ ah += '0';
832
+ }
833
+ al = (ch & 0x0f);
834
+ if(al >= 0x0a) {
835
+ al = al - 0x0a + 'a';
836
+ } else {
837
+ al += '0';
838
+ }
839
+ putch(ah);
840
+ putch(al);
841
+ }
842
+
843
+
844
+ void putch(char ch)
845
+ {
846
+ #ifdef __AVR_ATmega128__
847
+ if(bootuart == 1) {
848
+ while (!(UCSR0A & _BV(UDRE0)));
849
+ UDR0 = ch;
850
+ }
851
+ else if (bootuart == 2) {
852
+ while (!(UCSR1A & _BV(UDRE1)));
853
+ UDR1 = ch;
854
+ }
855
+ #elif defined __AVR_ATmega168__
856
+ while (!(UCSR0A & _BV(UDRE0)));
857
+ UDR0 = ch;
858
+ #else
859
+ /* m8,16,32,169,8515,8535,163 */
860
+ while (!(UCSRA & _BV(UDRE)));
861
+ UDR = ch;
862
+ #endif
863
+ }
864
+
865
+
866
+ char getch(void)
867
+ {
868
+ #ifdef __AVR_ATmega128__
869
+ if(bootuart == 1) {
870
+ while(!(UCSR0A & _BV(RXC0)));
871
+ return UDR0;
872
+ }
873
+ else if(bootuart == 2) {
874
+ while(!(UCSR1A & _BV(RXC1)));
875
+ return UDR1;
876
+ }
877
+ return 0;
878
+ #elif defined __AVR_ATmega168__
879
+ uint32_t count = 0;
880
+ while(!(UCSR0A & _BV(RXC0))){
881
+ /* 20060803 DojoCorp:: Addon coming from the previous Bootloader*/
882
+ /* HACKME:: here is a good place to count times*/
883
+ count++;
884
+ if (count > MAX_TIME_COUNT)
885
+ app_start();
886
+ }
887
+ return UDR0;
888
+ #else
889
+ /* m8,16,32,169,8515,8535,163 */
890
+ uint32_t count = 0;
891
+ while(!(UCSRA & _BV(RXC))){
892
+ /* 20060803 DojoCorp:: Addon coming from the previous Bootloader*/
893
+ /* HACKME:: here is a good place to count times*/
894
+ count++;
895
+ if (count > MAX_TIME_COUNT)
896
+ app_start();
897
+ }
898
+ return UDR;
899
+ #endif
900
+ }
901
+
902
+
903
+ void getNch(uint8_t count)
904
+ {
905
+ uint8_t i;
906
+ for(i=0;i<count;i++) {
907
+ #ifdef __AVR_ATmega128__
908
+ if(bootuart == 1) {
909
+ while(!(UCSR0A & _BV(RXC0)));
910
+ UDR0;
911
+ }
912
+ else if(bootuart == 2) {
913
+ while(!(UCSR1A & _BV(RXC1)));
914
+ UDR1;
915
+ }
916
+ #elif defined __AVR_ATmega168__
917
+ while(!(UCSR0A & _BV(RXC0)));
918
+ UDR0;
919
+ #else
920
+ /* m8,16,32,169,8515,8535,163 */
921
+ /* 20060803 DojoCorp:: Addon coming from the previous Bootloader*/
922
+ //while(!(UCSRA & _BV(RXC)));
923
+ //UDR;
924
+ uint8_t i;
925
+ for(i=0;i<count;i++) {
926
+ getch(); // need to handle time out
927
+ }
928
+ #endif
929
+ }
930
+ }
931
+
932
+
933
+ void byte_response(uint8_t val)
934
+ {
935
+ if (getch() == ' ') {
936
+ putch(0x14);
937
+ putch(val);
938
+ putch(0x10);
939
+ } else {
940
+ if (++error_count == MAX_ERROR_COUNT)
941
+ app_start();
942
+ }
943
+ }
944
+
945
+
946
+ void nothing_response(void)
947
+ {
948
+ if (getch() == ' ') {
949
+ putch(0x14);
950
+ putch(0x10);
951
+ } else {
952
+ if (++error_count == MAX_ERROR_COUNT)
953
+ app_start();
954
+ }
955
+ }
956
+
957
+ void flash_led(uint8_t count)
958
+ {
959
+ /* flash onboard LED three times to signal entering of bootloader */
960
+ /* l needs to be volatile or the delay loops below might get
961
+ optimized away if compiling with optimizations (DAM). */
962
+ volatile uint32_t l;
963
+
964
+ if (count == 0) {
965
+ count = 3;
966
+ }
967
+
968
+ for (i = 0; i < count; ++i) {
969
+ LED_PORT |= _BV(LED);
970
+ for(l = 0; l < (F_CPU / 1000); ++l);
971
+ LED_PORT &= ~_BV(LED);
972
+ for(l = 0; l < (F_CPU / 1000); ++l);
973
+ }
974
+ }
975
+
976
+
977
+ /* end of file ATmegaBOOT.c */
hardware/arduino/avr/bootloaders/lilypad/src/Makefile ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Makefile for ATmegaBOOT
2
+ # E.Lins, 18.7.2005
3
+
4
+ # Instructions
5
+ #
6
+ # To build the bootloader for the LilyPad:
7
+ # make lily
8
+
9
+
10
+ # program name should not be changed...
11
+ PROGRAM = ATmegaBOOT_168
12
+
13
+ # enter the target CPU frequency
14
+ AVR_FREQ = 8000000L
15
+
16
+ # enter the parameters for the avrdude isp tool
17
+ ISPTOOL = stk500v2
18
+ ISPPORT = usb
19
+ ISPSPEED = -b 115200
20
+
21
+ MCU_TARGET = atmega168
22
+ LDSECTION = --section-start=.text=0x3800
23
+
24
+ # the efuse should really be 0xf8; since, however, only the lower
25
+ # three bits of that byte are used on the atmega168, avrdude gets
26
+ # confused if you specify 1's for the higher bits, see:
27
+ # http://tinker.it/now/2007/02/24/the-tale-of-avrdude-atmega168-and-extended-bits-fuses/
28
+ #
29
+ # similarly, the lock bits should be 0xff instead of 0x3f (to
30
+ # unlock the bootloader section) and 0xcf instead of 0x0f (to
31
+ # lock it), but since the high two bits of the lock byte are
32
+ # unused, avrdude would get confused.
33
+ ISPFUSES = avrdude -c $(ISPTOOL) -p m168 -P $(ISPPORT) $(ISPSPEED) -e -u -U lock:w:0x3f:m -U efuse:w:0x00:m -U hfuse:w:0xdd:m -U lfuse:w:0xff:m
34
+ ISPFLASH = avrdude -c $(ISPTOOL) -p m168 -P $(ISPPORT) $(ISPSPEED) -U flash:w:$(PROGRAM)_$(TARGET).hex -U lock:w:0x0f:m
35
+
36
+
37
+ OBJ = $(PROGRAM).o
38
+ OPTIMIZE = -O2
39
+
40
+ DEFS =
41
+ LIBS =
42
+
43
+ CC = avr-gcc
44
+
45
+
46
+ # Override is only needed by avr-lib build system.
47
+
48
+ override CFLAGS = -g -Wall $(OPTIMIZE) -mmcu=$(MCU_TARGET) -DF_CPU=$(AVR_FREQ) $(DEFS)
49
+ override LDFLAGS = -Wl,$(LDSECTION)
50
+ #override LDFLAGS = -Wl,-Map,$(PROGRAM).map,$(LDSECTION)
51
+
52
+ OBJCOPY = avr-objcopy
53
+ OBJDUMP = avr-objdump
54
+
55
+ all:
56
+
57
+ lily: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>1' '-DNUM_LED_FLASHES=3'
58
+ lily: $(PROGRAM).hex
59
+
60
+ $(PROGRAM).hex: $(PROGRAM).elf
61
+ $(OBJCOPY) -j .text -j .data -O ihex $< $@
62
+
63
+ $(PROGRAM).elf: $(OBJ)
64
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
65
+
66
+ $(OBJ):
67
+ avr-gcc $(CFLAGS) $(LDFLAGS) -c -g -O2 -Wall -mmcu=atmega168 ATmegaBOOT.c -o ATmegaBOOT_168.o
68
+
69
+ %.lst: %.elf
70
+ $(OBJDUMP) -h -S $< > $@
71
+
72
+ %.srec: %.elf
73
+ $(OBJCOPY) -j .text -j .data -O srec $< $@
74
+
75
+ %.bin: %.elf
76
+ $(OBJCOPY) -j .text -j .data -O binary $< $@
77
+
78
+ clean:
79
+ rm -rf *.o *.elf *.lst *.map *.sym *.lss *.eep *.srec *.bin *.hex
80
+
81
+ install:
82
+ avrdude -p m168 -c stk500v2 -P /dev/cu.USA19H1b1P1.1 -e -u -U lock:w:0x3f:m -U efuse:w:0x00:m -U hfuse:w:0xdd:m -U lfuse:w:0xe2:m
83
+ avrdude -p m168 -c stk500v2 -P /dev/cu.USA19H1b1P1.1 -e -u -U flash:w:ATmegaBOOT_168.hex -U lock:w:0x0f:m
hardware/arduino/avr/bootloaders/optiboot/Makefile ADDED
@@ -0,0 +1,450 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Makefile for ATmegaBOOT
2
+ # E.Lins, 18.7.2005
3
+ #
4
+ # Instructions
5
+ #
6
+ # To make bootloader .hex file:
7
+ # make diecimila
8
+ # make lilypad
9
+ # make ng
10
+ # etc...
11
+ #
12
+ # To burn bootloader .hex file:
13
+ # make diecimila_isp
14
+ # make lilypad_isp
15
+ # make ng_isp
16
+ # etc...
17
+
18
+ # program name should not be changed...
19
+ PROGRAM = optiboot
20
+
21
+ # The default behavior is to build using tools that are in the users
22
+ # current path variables, but we can also build using an installed
23
+ # Arduino user IDE setup, or the Arduino source tree.
24
+ # Uncomment this next lines to build within the arduino environment,
25
+ # using the arduino-included avrgcc toolset (mac and pc)
26
+ # ENV ?= arduino
27
+ # ENV ?= arduinodev
28
+ # OS ?= macosx
29
+ # OS ?= windows
30
+
31
+
32
+ # enter the parameters for the avrdude isp tool
33
+ ISPTOOL = stk500v2
34
+ ISPPORT = usb
35
+ ISPSPEED = -b 115200
36
+
37
+ MCU_TARGET = atmega168
38
+ LDSECTIONS = -Wl,--section-start=.text=0x3e00 -Wl,--section-start=.version=0x3ffe
39
+
40
+ # Build environments
41
+ # Start of some ugly makefile-isms to allow optiboot to be built
42
+ # in several different environments. See the README.TXT file for
43
+ # details.
44
+
45
+ # default
46
+ fixpath = $(1)
47
+
48
+ ifeq ($(ENV), arduino)
49
+ # For Arduino, we assume that we're connected to the optiboot directory
50
+ # included with the arduino distribution, which means that the full set
51
+ # of avr-tools are "right up there" in standard places.
52
+ TOOLROOT = ../../../tools
53
+ GCCROOT = $(TOOLROOT)/avr/bin/
54
+ AVRDUDE_CONF = -C$(TOOLROOT)/avr/etc/avrdude.conf
55
+
56
+ ifeq ($(OS), windows)
57
+ # On windows, SOME of the tool paths will need to have backslashes instead
58
+ # of forward slashes (because they use windows cmd.exe for execution instead
59
+ # of a unix/mingw shell?) We also have to ensure that a consistent shell
60
+ # is used even if a unix shell is installed (ie as part of WINAVR)
61
+ fixpath = $(subst /,\,$1)
62
+ SHELL = cmd.exe
63
+ endif
64
+
65
+ else ifeq ($(ENV), arduinodev)
66
+ # Arduino IDE source code environment. Use the unpacked compilers created
67
+ # by the build (you'll need to do "ant build" first.)
68
+ ifeq ($(OS), macosx)
69
+ TOOLROOT = ../../../../build/macosx/work/Arduino.app/Contents/Resources/Java/hardware/tools
70
+ endif
71
+ ifeq ($(OS), windows)
72
+ TOOLROOT = ../../../../build/windows/work/hardware/tools
73
+ endif
74
+
75
+ GCCROOT = $(TOOLROOT)/avr/bin/
76
+ AVRDUDE_CONF = -C$(TOOLROOT)/avr/etc/avrdude.conf
77
+
78
+ else
79
+ GCCROOT =
80
+ AVRDUDE_CONF =
81
+ endif
82
+ #
83
+ # End of build environment code.
84
+
85
+
86
+ # the efuse should really be 0xf8; since, however, only the lower
87
+ # three bits of that byte are used on the atmega168, avrdude gets
88
+ # confused if you specify 1's for the higher bits, see:
89
+ # http://tinker.it/now/2007/02/24/the-tale-of-avrdude-atmega168-and-extended-bits-fuses/
90
+ #
91
+ # similarly, the lock bits should be 0xff instead of 0x3f (to
92
+ # unlock the bootloader section) and 0xcf instead of 0x2f (to
93
+ # lock it), but since the high two bits of the lock byte are
94
+ # unused, avrdude would get confused.
95
+
96
+ ISPFUSES = $(GCCROOT)avrdude $(AVRDUDE_CONF) -c $(ISPTOOL) \
97
+ -p $(MCU_TARGET) -P $(ISPPORT) $(ISPSPEED) \
98
+ -e -u -U lock:w:0x3f:m -U efuse:w:0x$(EFUSE):m \
99
+ -U hfuse:w:0x$(HFUSE):m -U lfuse:w:0x$(LFUSE):m
100
+ ISPFLASH = $(GCCROOT)avrdude $(AVRDUDE_CONF) -c $(ISPTOOL) \
101
+ -p $(MCU_TARGET) -P $(ISPPORT) $(ISPSPEED) \
102
+ -U flash:w:$(PROGRAM)_$(TARGET).hex -U lock:w:0x2f:m
103
+
104
+ STK500 = "C:\Program Files\Atmel\AVR Tools\STK500\Stk500.exe"
105
+ STK500-1 = $(STK500) -e -d$(MCU_TARGET) -pf -vf -if$(PROGRAM)_$(TARGET).hex \
106
+ -lFF -LFF -f$(HFUSE)$(LFUSE) -EF8 -ms -q -cUSB -I200kHz -s -wt
107
+ STK500-2 = $(STK500) -d$(MCU_TARGET) -ms -q -lCF -LCF -cUSB -I200kHz -s -wt
108
+
109
+ OBJ = $(PROGRAM).o
110
+ OPTIMIZE = -Os -fno-inline-small-functions -fno-split-wide-types -mshort-calls
111
+
112
+ DEFS =
113
+ LIBS =
114
+
115
+ CC = $(GCCROOT)avr-gcc
116
+
117
+ # Override is only needed by avr-lib build system.
118
+
119
+ override CFLAGS = -g -Wall $(OPTIMIZE) -mmcu=$(MCU_TARGET) -DF_CPU=$(AVR_FREQ) $(DEFS)
120
+ override LDFLAGS = $(LDSECTIONS) -Wl,--relax -Wl,--gc-sections -nostartfiles -nostdlib
121
+
122
+ OBJCOPY = $(GCCROOT)avr-objcopy
123
+ OBJDUMP = $(call fixpath,$(GCCROOT)avr-objdump)
124
+
125
+ SIZE = $(GCCROOT)avr-size
126
+
127
+ # Test platforms
128
+ # Virtual boot block test
129
+ virboot328: TARGET = atmega328
130
+ virboot328: MCU_TARGET = atmega328p
131
+ virboot328: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200' '-DVIRTUAL_BOOT'
132
+ virboot328: AVR_FREQ = 16000000L
133
+ virboot328: LDSECTIONS = -Wl,--section-start=.text=0x7e00 -Wl,--section-start=.version=0x7ffe
134
+ virboot328: $(PROGRAM)_atmega328.hex
135
+ virboot328: $(PROGRAM)_atmega328.lst
136
+
137
+ # 20MHz clocked platforms
138
+ #
139
+ # These are capable of 230400 baud, or 115200 baud on PC (Arduino Avrdude issue)
140
+ #
141
+
142
+ pro20: TARGET = pro_20mhz
143
+ pro20: MCU_TARGET = atmega168
144
+ pro20: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200'
145
+ pro20: AVR_FREQ = 20000000L
146
+ pro20: $(PROGRAM)_pro_20mhz.hex
147
+ pro20: $(PROGRAM)_pro_20mhz.lst
148
+
149
+ pro20_isp: pro20
150
+ pro20_isp: TARGET = pro_20mhz
151
+ # 2.7V brownout
152
+ pro20_isp: HFUSE = DD
153
+ # Full swing xtal (20MHz) 258CK/14CK+4.1ms
154
+ pro20_isp: LFUSE = C6
155
+ # 512 byte boot
156
+ pro20_isp: EFUSE = 04
157
+ pro20_isp: isp
158
+
159
+ # 16MHz clocked platforms
160
+ #
161
+ # These are capable of 230400 baud, or 115200 baud on PC (Arduino Avrdude issue)
162
+ #
163
+
164
+ pro16: TARGET = pro_16MHz
165
+ pro16: MCU_TARGET = atmega168
166
+ pro16: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200'
167
+ pro16: AVR_FREQ = 16000000L
168
+ pro16: $(PROGRAM)_pro_16MHz.hex
169
+ pro16: $(PROGRAM)_pro_16MHz.lst
170
+
171
+ pro16_isp: pro16
172
+ pro16_isp: TARGET = pro_16MHz
173
+ # 2.7V brownout
174
+ pro16_isp: HFUSE = DD
175
+ # Full swing xtal (20MHz) 258CK/14CK+4.1ms
176
+ pro16_isp: LFUSE = C6
177
+ # 512 byte boot
178
+ pro16_isp: EFUSE = 04
179
+ pro16_isp: isp
180
+
181
+ # Diecimila, Duemilanove with m168, and NG use identical bootloaders
182
+ # Call it "atmega168" for generality and clarity, keep "diecimila" for
183
+ # backward compatibility of makefile
184
+ #
185
+ atmega168: TARGET = atmega168
186
+ atmega168: MCU_TARGET = atmega168
187
+ atmega168: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200'
188
+ atmega168: AVR_FREQ = 16000000L
189
+ atmega168: $(PROGRAM)_atmega168.hex
190
+ atmega168: $(PROGRAM)_atmega168.lst
191
+
192
+ atmega168_isp: atmega168
193
+ atmega168_isp: TARGET = atmega168
194
+ # 2.7V brownout
195
+ atmega168_isp: HFUSE = DD
196
+ # Low power xtal (16MHz) 16KCK/14CK+65ms
197
+ atmega168_isp: LFUSE = FF
198
+ # 512 byte boot
199
+ atmega168_isp: EFUSE = 04
200
+ atmega168_isp: isp
201
+
202
+ diecimila: TARGET = diecimila
203
+ diecimila: MCU_TARGET = atmega168
204
+ diecimila: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200'
205
+ diecimila: AVR_FREQ = 16000000L
206
+ diecimila: $(PROGRAM)_diecimila.hex
207
+ diecimila: $(PROGRAM)_diecimila.lst
208
+
209
+ diecimila_isp: diecimila
210
+ diecimila_isp: TARGET = diecimila
211
+ # 2.7V brownout
212
+ diecimila_isp: HFUSE = DD
213
+ # Low power xtal (16MHz) 16KCK/14CK+65ms
214
+ diecimila_isp: LFUSE = FF
215
+ # 512 byte boot
216
+ diecimila_isp: EFUSE = 04
217
+ diecimila_isp: isp
218
+
219
+ atmega328: TARGET = atmega328
220
+ atmega328: MCU_TARGET = atmega328p
221
+ atmega328: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200'
222
+ atmega328: AVR_FREQ = 16000000L
223
+ atmega328: LDSECTIONS = -Wl,--section-start=.text=0x7e00 -Wl,--section-start=.version=0x7ffe
224
+ atmega328: $(PROGRAM)_atmega328.hex
225
+ atmega328: $(PROGRAM)_atmega328.lst
226
+
227
+ atmega328_isp: atmega328
228
+ atmega328_isp: TARGET = atmega328
229
+ atmega328_isp: MCU_TARGET = atmega328p
230
+ # 512 byte boot, SPIEN
231
+ atmega328_isp: HFUSE = DE
232
+ # Low power xtal (16MHz) 16KCK/14CK+65ms
233
+ atmega328_isp: LFUSE = FF
234
+ # 2.7V brownout
235
+ atmega328_isp: EFUSE = 05
236
+ atmega328_isp: isp
237
+
238
+ # Sanguino has a minimum boot size of 1024 bytes, so enable extra functions
239
+ #
240
+ sanguino: TARGET = atmega644p
241
+ sanguino: MCU_TARGET = atmega644p
242
+ sanguino: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200' '-DBIGBOOT'
243
+ sanguino: AVR_FREQ = 16000000L
244
+ sanguino: LDSECTIONS = -Wl,--section-start=.text=0xfc00
245
+ sanguino: $(PROGRAM)_atmega644p.hex
246
+ sanguino: $(PROGRAM)_atmega644p.lst
247
+
248
+ sanguino_isp: sanguino
249
+ sanguino_isp: TARGET = atmega644p
250
+ sanguino_isp: MCU_TARGET = atmega644p
251
+ # 1024 byte boot
252
+ sanguino_isp: HFUSE = DE
253
+ # Low power xtal (16MHz) 16KCK/14CK+65ms
254
+ sanguino_isp: LFUSE = FF
255
+ # 2.7V brownout
256
+ sanguino_isp: EFUSE = 05
257
+ sanguino_isp: isp
258
+
259
+ # Mega has a minimum boot size of 1024 bytes, so enable extra functions
260
+ #mega: TARGET = atmega1280
261
+ mega: MCU_TARGET = atmega1280
262
+ mega: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200' '-DBIGBOOT'
263
+ mega: AVR_FREQ = 16000000L
264
+ mega: LDSECTIONS = -Wl,--section-start=.text=0x1fc00
265
+ mega: $(PROGRAM)_atmega1280.hex
266
+ mega: $(PROGRAM)_atmega1280.lst
267
+
268
+ mega_isp: mega
269
+ mega_isp: TARGET = atmega1280
270
+ mega_isp: MCU_TARGET = atmega1280
271
+ # 1024 byte boot
272
+ mega_isp: HFUSE = DE
273
+ # Low power xtal (16MHz) 16KCK/14CK+65ms
274
+ mega_isp: LFUSE = FF
275
+ # 2.7V brownout
276
+ mega_isp: EFUSE = 05
277
+ mega_isp: isp
278
+
279
+ # ATmega8
280
+ #
281
+ atmega8: TARGET = atmega8
282
+ atmega8: MCU_TARGET = atmega8
283
+ atmega8: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200'
284
+ atmega8: AVR_FREQ = 16000000L
285
+ atmega8: LDSECTIONS = -Wl,--section-start=.text=0x1e00 -Wl,--section-start=.version=0x1ffe
286
+ atmega8: $(PROGRAM)_atmega8.hex
287
+ atmega8: $(PROGRAM)_atmega8.lst
288
+
289
+ atmega8_isp: atmega8
290
+ atmega8_isp: TARGET = atmega8
291
+ atmega8_isp: MCU_TARGET = atmega8
292
+ # SPIEN, CKOPT, Bootsize=512B
293
+ atmega8_isp: HFUSE = CC
294
+ # 2.7V brownout, Low power xtal (16MHz) 16KCK/14CK+65ms
295
+ atmega8_isp: LFUSE = BF
296
+ atmega8_isp: isp
297
+
298
+ # ATmega88
299
+ #
300
+ atmega88: TARGET = atmega88
301
+ atmega88: MCU_TARGET = atmega88
302
+ atmega88: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200'
303
+ atmega88: AVR_FREQ = 16000000L
304
+ atmega88: LDSECTIONS = -Wl,--section-start=.text=0x1e00 -Wl,--section-start=.version=0x1ffe
305
+ atmega88: $(PROGRAM)_atmega88.hex
306
+ atmega88: $(PROGRAM)_atmega88.lst
307
+
308
+ atmega88_isp: atmega88
309
+ atmega88_isp: TARGET = atmega88
310
+ atmega88_isp: MCU_TARGET = atmega88
311
+ # 2.7V brownout
312
+ atmega88_isp: HFUSE = DD
313
+ # Low power xtal (16MHz) 16KCK/14CK+65ms
314
+ atemga88_isp: LFUSE = FF
315
+ # 512 byte boot
316
+ atmega88_isp: EFUSE = 04
317
+ atmega88_isp: isp
318
+
319
+
320
+ # 8MHz clocked platforms
321
+ #
322
+ # These are capable of 115200 baud
323
+ #
324
+
325
+ lilypad: TARGET = lilypad
326
+ lilypad: MCU_TARGET = atmega168
327
+ lilypad: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200'
328
+ lilypad: AVR_FREQ = 8000000L
329
+ lilypad: $(PROGRAM)_lilypad.hex
330
+ lilypad: $(PROGRAM)_lilypad.lst
331
+
332
+ lilypad_isp: lilypad
333
+ lilypad_isp: TARGET = lilypad
334
+ # 2.7V brownout
335
+ lilypad_isp: HFUSE = DD
336
+ # Internal 8MHz osc (8MHz) Slow rising power
337
+ lilypad_isp: LFUSE = E2
338
+ # 512 byte boot
339
+ lilypad_isp: EFUSE = 04
340
+ lilypad_isp: isp
341
+
342
+ lilypad_resonator: TARGET = lilypad_resonator
343
+ lilypad_resonator: MCU_TARGET = atmega168
344
+ lilypad_resonator: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200'
345
+ lilypad_resonator: AVR_FREQ = 8000000L
346
+ lilypad_resonator: $(PROGRAM)_lilypad_resonator.hex
347
+ lilypad_resonator: $(PROGRAM)_lilypad_resonator.lst
348
+
349
+ lilypad_resonator_isp: lilypad_resonator
350
+ lilypad_resonator_isp: TARGET = lilypad_resonator
351
+ # 2.7V brownout
352
+ lilypad_resonator_isp: HFUSE = DD
353
+ # Full swing xtal (20MHz) 258CK/14CK+4.1ms
354
+ lilypad_resonator_isp: LFUSE = C6
355
+ # 512 byte boot
356
+ lilypad_resonator_isp: EFUSE = 04
357
+ lilypad_resonator_isp: isp
358
+
359
+ pro8: TARGET = pro_8MHz
360
+ pro8: MCU_TARGET = atmega168
361
+ pro8: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200'
362
+ pro8: AVR_FREQ = 8000000L
363
+ pro8: $(PROGRAM)_pro_8MHz.hex
364
+ pro8: $(PROGRAM)_pro_8MHz.lst
365
+
366
+ pro8_isp: pro8
367
+ pro8_isp: TARGET = pro_8MHz
368
+ # 2.7V brownout
369
+ pro8_isp: HFUSE = DD
370
+ # Full swing xtal (20MHz) 258CK/14CK+4.1ms
371
+ pro8_isp: LFUSE = C6
372
+ # 512 byte boot
373
+ pro8_isp: EFUSE = 04
374
+ pro8_isp: isp
375
+
376
+ atmega328_pro8: TARGET = atmega328_pro_8MHz
377
+ atmega328_pro8: MCU_TARGET = atmega328p
378
+ atmega328_pro8: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200'
379
+ atmega328_pro8: AVR_FREQ = 8000000L
380
+ atmega328_pro8: LDSECTIONS = -Wl,--section-start=.text=0x7e00 -Wl,--section-start=.version=0x7ffe
381
+ atmega328_pro8: $(PROGRAM)_atmega328_pro_8MHz.hex
382
+ atmega328_pro8: $(PROGRAM)_atmega328_pro_8MHz.lst
383
+
384
+ atmega328_pro8_isp: atmega328_pro8
385
+ atmega328_pro8_isp: TARGET = atmega328_pro_8MHz
386
+ atmega328_pro8_isp: MCU_TARGET = atmega328p
387
+ # 512 byte boot, SPIEN
388
+ atmega328_pro8_isp: HFUSE = DE
389
+ # Low power xtal (16MHz) 16KCK/14CK+65ms
390
+ atmega328_pro8_isp: LFUSE = FF
391
+ # 2.7V brownout
392
+ atmega328_pro8_isp: EFUSE = 05
393
+ atmega328_pro8_isp: isp
394
+
395
+ # 1MHz clocked platforms
396
+ #
397
+ # These are capable of 9600 baud
398
+ #
399
+
400
+ luminet: TARGET = luminet
401
+ luminet: MCU_TARGET = attiny84
402
+ luminet: CFLAGS += '-DLED_START_FLASHES=3' '-DSOFT_UART' '-DBAUD_RATE=9600'
403
+ luminet: CFLAGS += '-DVIRTUAL_BOOT_PARTITION'
404
+ luminet: AVR_FREQ = 1000000L
405
+ luminet: LDSECTIONS = -Wl,--section-start=.text=0x1d00 -Wl,--section-start=.version=0x1efe
406
+ luminet: $(PROGRAM)_luminet.hex
407
+ luminet: $(PROGRAM)_luminet.lst
408
+
409
+ luminet_isp: luminet
410
+ luminet_isp: TARGET = luminet
411
+ luminet_isp: MCU_TARGET = attiny84
412
+ # Brownout disabled
413
+ luminet_isp: HFUSE = DF
414
+ # 1MHz internal oscillator, slowly rising power
415
+ luminet_isp: LFUSE = 62
416
+ # Self-programming enable
417
+ luminet_isp: EFUSE = FE
418
+ luminet_isp: isp
419
+
420
+ #
421
+ # Generic build instructions
422
+ #
423
+ #
424
+
425
+ isp: $(TARGET)
426
+ $(ISPFUSES)
427
+ $(ISPFLASH)
428
+
429
+ isp-stk500: $(PROGRAM)_$(TARGET).hex
430
+ $(STK500-1)
431
+ $(STK500-2)
432
+
433
+ %.elf: $(OBJ)
434
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
435
+ $(SIZE) $@
436
+
437
+ clean:
438
+ rm -rf *.o *.elf *.lst *.map *.sym *.lss *.eep *.srec *.bin *.hex
439
+
440
+ %.lst: %.elf
441
+ $(OBJDUMP) -h -S $< > $@
442
+
443
+ %.hex: %.elf
444
+ $(OBJCOPY) -j .text -j .data -j .version --set-section-flags .version=alloc,load -O ihex $< $@
445
+
446
+ %.srec: %.elf
447
+ $(OBJCOPY) -j .text -j .data -j .version --set-section-flags .version=alloc,load -O srec $< $@
448
+
449
+ %.bin: %.elf
450
+ $(OBJCOPY) -j .text -j .data -j .version --set-section-flags .version=alloc,load -O binary $< $@
hardware/arduino/avr/bootloaders/optiboot/README.TXT ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ This directory contains the Optiboot small bootloader for AVR
2
+ microcontrollers, somewhat modified specifically for the Arduino
3
+ environment.
4
+
5
+ Optiboot is more fully described here: http://code.google.com/p/optiboot/
6
+ and is the work of Peter Knight (aka Cathedrow), building on work of Jason P
7
+ Kyle, Spiff, and Ladyada. Arduino-specific modification are by Bill
8
+ Westfield (aka WestfW)
9
+
10
+ Arduino-specific issues are tracked as part of the Arduino project
11
+ at http://code.google.com/p/arduino
12
+
13
+
14
+ ------------------------------------------------------------
15
+ Building optiboot for Arduino.
16
+
17
+ Production builds of optiboot for Arduino are done on a Mac in "unix mode"
18
+ using CrossPack-AVR-20100115. CrossPack tracks WINAVR (for windows), which
19
+ is just a package of avr-gcc and related utilities, so similar builds should
20
+ work on Windows or Linux systems.
21
+
22
+ One of the Arduino-specific changes is modifications to the makefile to
23
+ allow building optiboot using only the tools installed as part of the
24
+ Arduino environment, or the Arduino source development tree. All three
25
+ build procedures should yield identical binaries (.hex files) (although
26
+ this may change if compiler versions drift apart between CrossPack and
27
+ the Arduino IDE.)
28
+
29
+
30
+ Building Optiboot in the Arduino IDE Install.
31
+
32
+ Work in the .../hardware/arduino/bootloaders/optiboot/ and use the
33
+ "omake <targets>" command, which just generates a command that uses
34
+ the arduino-included "make" utility with a command like:
35
+ make OS=windows ENV=arduino <targets>
36
+ or make OS=macosx ENV=arduino <targets>
37
+ On windows, this assumes you're using the windows command shell. If
38
+ you're using a cygwin or mingw shell, or have one of those in your
39
+ path, the build will probably break due to slash vs backslash issues.
40
+ On a Mac, if you have the developer tools installed, you can use the
41
+ Apple-supplied version of make.
42
+ The makefile uses relative paths ("../../../tools/" and such) to find
43
+ the programs it needs, so you need to work in the existing optiboot
44
+ directory (or something created at the same "level") for it to work.
45
+
46
+
47
+ Building Optiboot in the Arduino Source Development Install.
48
+
49
+ In this case, there is no special shell script, and you're assumed to
50
+ have "make" installed somewhere in your path.
51
+ Build the Arduino source ("ant build") to unpack the tools into the
52
+ expected directory.
53
+ Work in Arduino/hardware/arduino/bootloaders/optiboot and use
54
+ make OS=windows ENV=arduinodev <targets>
55
+ or make OS=macosx ENV=arduinodev <targets>
56
+
57
+
58
+ Programming Chips Using the _isp Targets
59
+
60
+ The CPU targets have corresponding ISP targets that will actuall
61
+ program the bootloader into a chip. "atmega328_isp" for the atmega328,
62
+ for example. These will set the fuses and lock bits as appropriate as
63
+ well as uploading the bootloader code.
64
+
65
+ The makefiles default to using a USB programmer, but you can use
66
+ a serial programmer like ArduinoISP by changing the appropriate
67
+ variables when you invoke make:
68
+
69
+ make ISPTOOL=stk500v1 ISPPORT=/dev/tty.usbserial-A20e1eAN \
70
+ ISPSPEED=-b19200 atmega328_isp
71
+
72
+ The "atmega8_isp" target does not currently work, because the mega8
73
+ doesn't have the "extended" fuse that the generic ISP target wants to
74
+ pass on to avrdude. You'll need to run avrdude manually.
75
+
76
+
77
+ Standard Targets
78
+
79
+ I've reduced the pre-built and source-version-controlled targets
80
+ (.hex and .lst files included in the git repository) to just the
81
+ three basic 16MHz targets: atmega8, atmega16, atmega328.
hardware/arduino/avr/bootloaders/optiboot/boot.h ADDED
@@ -0,0 +1,846 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Modified to use out for SPM access
2
+ ** Peter Knight, Optiboot project http://optiboot.googlecode.com
3
+ **
4
+ ** Todo: Tidy up
5
+ **
6
+ ** "_short" routines execute 1 cycle faster and use 1 less word of flash
7
+ ** by using "out" instruction instead of "sts".
8
+ **
9
+ ** Additional elpm variants that trust the value of RAMPZ
10
+ */
11
+
12
+ /* Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007 Eric B. Weddington
13
+ All rights reserved.
14
+
15
+ Redistribution and use in source and binary forms, with or without
16
+ modification, are permitted provided that the following conditions are met:
17
+
18
+ * Redistributions of source code must retain the above copyright
19
+ notice, this list of conditions and the following disclaimer.
20
+ * Redistributions in binary form must reproduce the above copyright
21
+ notice, this list of conditions and the following disclaimer in
22
+ the documentation and/or other materials provided with the
23
+ distribution.
24
+ * Neither the name of the copyright holders nor the names of
25
+ contributors may be used to endorse or promote products derived
26
+ from this software without specific prior written permission.
27
+
28
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
32
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38
+ POSSIBILITY OF SUCH DAMAGE. */
39
+
40
+ #ifndef _AVR_BOOT_H_
41
+ #define _AVR_BOOT_H_ 1
42
+
43
+ /** \file */
44
+ /** \defgroup avr_boot <avr/boot.h>: Bootloader Support Utilities
45
+ \code
46
+ #include <avr/io.h>
47
+ #include <avr/boot.h>
48
+ \endcode
49
+
50
+ The macros in this module provide a C language interface to the
51
+ bootloader support functionality of certain AVR processors. These
52
+ macros are designed to work with all sizes of flash memory.
53
+
54
+ Global interrupts are not automatically disabled for these macros. It
55
+ is left up to the programmer to do this. See the code example below.
56
+ Also see the processor datasheet for caveats on having global interrupts
57
+ enabled during writing of the Flash.
58
+
59
+ \note Not all AVR processors provide bootloader support. See your
60
+ processor datasheet to see if it provides bootloader support.
61
+
62
+ \todo From email with Marek: On smaller devices (all except ATmega64/128),
63
+ __SPM_REG is in the I/O space, accessible with the shorter "in" and "out"
64
+ instructions - since the boot loader has a limited size, this could be an
65
+ important optimization.
66
+
67
+ \par API Usage Example
68
+ The following code shows typical usage of the boot API.
69
+
70
+ \code
71
+ #include <inttypes.h>
72
+ #include <avr/interrupt.h>
73
+ #include <avr/pgmspace.h>
74
+
75
+ void boot_program_page (uint32_t page, uint8_t *buf)
76
+ {
77
+ uint16_t i;
78
+ uint8_t sreg;
79
+
80
+ // Disable interrupts.
81
+
82
+ sreg = SREG;
83
+ cli();
84
+
85
+ eeprom_busy_wait ();
86
+
87
+ boot_page_erase (page);
88
+ boot_spm_busy_wait (); // Wait until the memory is erased.
89
+
90
+ for (i=0; i<SPM_PAGESIZE; i+=2)
91
+ {
92
+ // Set up little-endian word.
93
+
94
+ uint16_t w = *buf++;
95
+ w += (*buf++) << 8;
96
+
97
+ boot_page_fill (page + i, w);
98
+ }
99
+
100
+ boot_page_write (page); // Store buffer in flash page.
101
+ boot_spm_busy_wait(); // Wait until the memory is written.
102
+
103
+ // Reenable RWW-section again. We need this if we want to jump back
104
+ // to the application after bootloading.
105
+
106
+ boot_rww_enable ();
107
+
108
+ // Re-enable interrupts (if they were ever enabled).
109
+
110
+ SREG = sreg;
111
+ }\endcode */
112
+
113
+ #include <avr/eeprom.h>
114
+ #include <avr/io.h>
115
+ #include <inttypes.h>
116
+ #include <limits.h>
117
+
118
+ /* Check for SPM Control Register in processor. */
119
+ #if defined (SPMCSR)
120
+ # define __SPM_REG SPMCSR
121
+ #elif defined (SPMCR)
122
+ # define __SPM_REG SPMCR
123
+ #else
124
+ # error AVR processor does not provide bootloader support!
125
+ #endif
126
+
127
+
128
+ /* Check for SPM Enable bit. */
129
+ #if defined(SPMEN)
130
+ # define __SPM_ENABLE SPMEN
131
+ #elif defined(SELFPRGEN)
132
+ # define __SPM_ENABLE SELFPRGEN
133
+ #else
134
+ # error Cannot find SPM Enable bit definition!
135
+ #endif
136
+
137
+ /** \ingroup avr_boot
138
+ \def BOOTLOADER_SECTION
139
+
140
+ Used to declare a function or variable to be placed into a
141
+ new section called .bootloader. This section and its contents
142
+ can then be relocated to any address (such as the bootloader
143
+ NRWW area) at link-time. */
144
+
145
+ #define BOOTLOADER_SECTION __attribute__ ((section (".bootloader")))
146
+
147
+ /* Create common bit definitions. */
148
+ #ifdef ASB
149
+ #define __COMMON_ASB ASB
150
+ #else
151
+ #define __COMMON_ASB RWWSB
152
+ #endif
153
+
154
+ #ifdef ASRE
155
+ #define __COMMON_ASRE ASRE
156
+ #else
157
+ #define __COMMON_ASRE RWWSRE
158
+ #endif
159
+
160
+ /* Define the bit positions of the Boot Lock Bits. */
161
+
162
+ #define BLB12 5
163
+ #define BLB11 4
164
+ #define BLB02 3
165
+ #define BLB01 2
166
+
167
+ /** \ingroup avr_boot
168
+ \def boot_spm_interrupt_enable()
169
+ Enable the SPM interrupt. */
170
+
171
+ #define boot_spm_interrupt_enable() (__SPM_REG |= (uint8_t)_BV(SPMIE))
172
+
173
+ /** \ingroup avr_boot
174
+ \def boot_spm_interrupt_disable()
175
+ Disable the SPM interrupt. */
176
+
177
+ #define boot_spm_interrupt_disable() (__SPM_REG &= (uint8_t)~_BV(SPMIE))
178
+
179
+ /** \ingroup avr_boot
180
+ \def boot_is_spm_interrupt()
181
+ Check if the SPM interrupt is enabled. */
182
+
183
+ #define boot_is_spm_interrupt() (__SPM_REG & (uint8_t)_BV(SPMIE))
184
+
185
+ /** \ingroup avr_boot
186
+ \def boot_rww_busy()
187
+ Check if the RWW section is busy. */
188
+
189
+ #define boot_rww_busy() (__SPM_REG & (uint8_t)_BV(__COMMON_ASB))
190
+
191
+ /** \ingroup avr_boot
192
+ \def boot_spm_busy()
193
+ Check if the SPM instruction is busy. */
194
+
195
+ #define boot_spm_busy() (__SPM_REG & (uint8_t)_BV(__SPM_ENABLE))
196
+
197
+ /** \ingroup avr_boot
198
+ \def boot_spm_busy_wait()
199
+ Wait while the SPM instruction is busy. */
200
+
201
+ #define boot_spm_busy_wait() do{}while(boot_spm_busy())
202
+
203
+ #define __BOOT_PAGE_ERASE (_BV(__SPM_ENABLE) | _BV(PGERS))
204
+ #define __BOOT_PAGE_WRITE (_BV(__SPM_ENABLE) | _BV(PGWRT))
205
+ #define __BOOT_PAGE_FILL _BV(__SPM_ENABLE)
206
+ #define __BOOT_RWW_ENABLE (_BV(__SPM_ENABLE) | _BV(__COMMON_ASRE))
207
+ #define __BOOT_LOCK_BITS_SET (_BV(__SPM_ENABLE) | _BV(BLBSET))
208
+
209
+ #define __boot_page_fill_short(address, data) \
210
+ (__extension__({ \
211
+ __asm__ __volatile__ \
212
+ ( \
213
+ "movw r0, %3\n\t" \
214
+ "out %0, %1\n\t" \
215
+ "spm\n\t" \
216
+ "clr r1\n\t" \
217
+ : \
218
+ : "i" (_SFR_IO_ADDR(__SPM_REG)), \
219
+ "r" ((uint8_t)__BOOT_PAGE_FILL), \
220
+ "z" ((uint16_t)address), \
221
+ "r" ((uint16_t)data) \
222
+ : "r0" \
223
+ ); \
224
+ }))
225
+
226
+ #define __boot_page_fill_normal(address, data) \
227
+ (__extension__({ \
228
+ __asm__ __volatile__ \
229
+ ( \
230
+ "movw r0, %3\n\t" \
231
+ "sts %0, %1\n\t" \
232
+ "spm\n\t" \
233
+ "clr r1\n\t" \
234
+ : \
235
+ : "i" (_SFR_MEM_ADDR(__SPM_REG)), \
236
+ "r" ((uint8_t)__BOOT_PAGE_FILL), \
237
+ "z" ((uint16_t)address), \
238
+ "r" ((uint16_t)data) \
239
+ : "r0" \
240
+ ); \
241
+ }))
242
+
243
+ #define __boot_page_fill_alternate(address, data)\
244
+ (__extension__({ \
245
+ __asm__ __volatile__ \
246
+ ( \
247
+ "movw r0, %3\n\t" \
248
+ "sts %0, %1\n\t" \
249
+ "spm\n\t" \
250
+ ".word 0xffff\n\t" \
251
+ "nop\n\t" \
252
+ "clr r1\n\t" \
253
+ : \
254
+ : "i" (_SFR_MEM_ADDR(__SPM_REG)), \
255
+ "r" ((uint8_t)__BOOT_PAGE_FILL), \
256
+ "z" ((uint16_t)address), \
257
+ "r" ((uint16_t)data) \
258
+ : "r0" \
259
+ ); \
260
+ }))
261
+
262
+ #define __boot_page_fill_extended(address, data) \
263
+ (__extension__({ \
264
+ __asm__ __volatile__ \
265
+ ( \
266
+ "movw r0, %4\n\t" \
267
+ "movw r30, %A3\n\t" \
268
+ "sts %1, %C3\n\t" \
269
+ "sts %0, %2\n\t" \
270
+ "spm\n\t" \
271
+ "clr r1\n\t" \
272
+ : \
273
+ : "i" (_SFR_MEM_ADDR(__SPM_REG)), \
274
+ "i" (_SFR_MEM_ADDR(RAMPZ)), \
275
+ "r" ((uint8_t)__BOOT_PAGE_FILL), \
276
+ "r" ((uint32_t)address), \
277
+ "r" ((uint16_t)data) \
278
+ : "r0", "r30", "r31" \
279
+ ); \
280
+ }))
281
+
282
+ #define __boot_page_fill_extended_short(address, data) \
283
+ (__extension__({ \
284
+ __asm__ __volatile__ \
285
+ ( \
286
+ "movw r0, %4\n\t" \
287
+ "movw r30, %A3\n\t" \
288
+ "out %1, %C3\n\t" \
289
+ "out %0, %2\n\t" \
290
+ "spm\n\t" \
291
+ "clr r1\n\t" \
292
+ : \
293
+ : "i" (_SFR_IO_ADDR(__SPM_REG)), \
294
+ "i" (_SFR_IO_ADDR(RAMPZ)), \
295
+ "r" ((uint8_t)__BOOT_PAGE_FILL), \
296
+ "r" ((uint32_t)address), \
297
+ "r" ((uint16_t)data) \
298
+ : "r0", "r30", "r31" \
299
+ ); \
300
+ }))
301
+
302
+ #define __boot_page_erase_short(address) \
303
+ (__extension__({ \
304
+ __asm__ __volatile__ \
305
+ ( \
306
+ "out %0, %1\n\t" \
307
+ "spm\n\t" \
308
+ : \
309
+ : "i" (_SFR_IO_ADDR(__SPM_REG)), \
310
+ "r" ((uint8_t)__BOOT_PAGE_ERASE), \
311
+ "z" ((uint16_t)address) \
312
+ ); \
313
+ }))
314
+
315
+
316
+ #define __boot_page_erase_normal(address) \
317
+ (__extension__({ \
318
+ __asm__ __volatile__ \
319
+ ( \
320
+ "sts %0, %1\n\t" \
321
+ "spm\n\t" \
322
+ : \
323
+ : "i" (_SFR_MEM_ADDR(__SPM_REG)), \
324
+ "r" ((uint8_t)__BOOT_PAGE_ERASE), \
325
+ "z" ((uint16_t)address) \
326
+ ); \
327
+ }))
328
+
329
+ #define __boot_page_erase_alternate(address) \
330
+ (__extension__({ \
331
+ __asm__ __volatile__ \
332
+ ( \
333
+ "sts %0, %1\n\t" \
334
+ "spm\n\t" \
335
+ ".word 0xffff\n\t" \
336
+ "nop\n\t" \
337
+ : \
338
+ : "i" (_SFR_MEM_ADDR(__SPM_REG)), \
339
+ "r" ((uint8_t)__BOOT_PAGE_ERASE), \
340
+ "z" ((uint16_t)address) \
341
+ ); \
342
+ }))
343
+
344
+ #define __boot_page_erase_extended(address) \
345
+ (__extension__({ \
346
+ __asm__ __volatile__ \
347
+ ( \
348
+ "movw r30, %A3\n\t" \
349
+ "sts %1, %C3\n\t" \
350
+ "sts %0, %2\n\t" \
351
+ "spm\n\t" \
352
+ : \
353
+ : "i" (_SFR_MEM_ADDR(__SPM_REG)), \
354
+ "i" (_SFR_MEM_ADDR(RAMPZ)), \
355
+ "r" ((uint8_t)__BOOT_PAGE_ERASE), \
356
+ "r" ((uint32_t)address) \
357
+ : "r30", "r31" \
358
+ ); \
359
+ }))
360
+ #define __boot_page_erase_extended_short(address) \
361
+ (__extension__({ \
362
+ __asm__ __volatile__ \
363
+ ( \
364
+ "movw r30, %A3\n\t" \
365
+ "out %1, %C3\n\t" \
366
+ "out %0, %2\n\t" \
367
+ "spm\n\t" \
368
+ : \
369
+ : "i" (_SFR_IO_ADDR(__SPM_REG)), \
370
+ "i" (_SFR_IO_ADDR(RAMPZ)), \
371
+ "r" ((uint8_t)__BOOT_PAGE_ERASE), \
372
+ "r" ((uint32_t)address) \
373
+ : "r30", "r31" \
374
+ ); \
375
+ }))
376
+
377
+ #define __boot_page_write_short(address) \
378
+ (__extension__({ \
379
+ __asm__ __volatile__ \
380
+ ( \
381
+ "out %0, %1\n\t" \
382
+ "spm\n\t" \
383
+ : \
384
+ : "i" (_SFR_IO_ADDR(__SPM_REG)), \
385
+ "r" ((uint8_t)__BOOT_PAGE_WRITE), \
386
+ "z" ((uint16_t)address) \
387
+ ); \
388
+ }))
389
+
390
+ #define __boot_page_write_normal(address) \
391
+ (__extension__({ \
392
+ __asm__ __volatile__ \
393
+ ( \
394
+ "sts %0, %1\n\t" \
395
+ "spm\n\t" \
396
+ : \
397
+ : "i" (_SFR_MEM_ADDR(__SPM_REG)), \
398
+ "r" ((uint8_t)__BOOT_PAGE_WRITE), \
399
+ "z" ((uint16_t)address) \
400
+ ); \
401
+ }))
402
+
403
+ #define __boot_page_write_alternate(address) \
404
+ (__extension__({ \
405
+ __asm__ __volatile__ \
406
+ ( \
407
+ "sts %0, %1\n\t" \
408
+ "spm\n\t" \
409
+ ".word 0xffff\n\t" \
410
+ "nop\n\t" \
411
+ : \
412
+ : "i" (_SFR_MEM_ADDR(__SPM_REG)), \
413
+ "r" ((uint8_t)__BOOT_PAGE_WRITE), \
414
+ "z" ((uint16_t)address) \
415
+ ); \
416
+ }))
417
+
418
+ #define __boot_page_write_extended(address) \
419
+ (__extension__({ \
420
+ __asm__ __volatile__ \
421
+ ( \
422
+ "movw r30, %A3\n\t" \
423
+ "sts %1, %C3\n\t" \
424
+ "sts %0, %2\n\t" \
425
+ "spm\n\t" \
426
+ : \
427
+ : "i" (_SFR_MEM_ADDR(__SPM_REG)), \
428
+ "i" (_SFR_MEM_ADDR(RAMPZ)), \
429
+ "r" ((uint8_t)__BOOT_PAGE_WRITE), \
430
+ "r" ((uint32_t)address) \
431
+ : "r30", "r31" \
432
+ ); \
433
+ }))
434
+ #define __boot_page_write_extended_short(address) \
435
+ (__extension__({ \
436
+ __asm__ __volatile__ \
437
+ ( \
438
+ "movw r30, %A3\n\t" \
439
+ "out %1, %C3\n\t" \
440
+ "out %0, %2\n\t" \
441
+ "spm\n\t" \
442
+ : \
443
+ : "i" (_SFR_IO_ADDR(__SPM_REG)), \
444
+ "i" (_SFR_IO_ADDR(RAMPZ)), \
445
+ "r" ((uint8_t)__BOOT_PAGE_WRITE), \
446
+ "r" ((uint32_t)address) \
447
+ : "r30", "r31" \
448
+ ); \
449
+ }))
450
+
451
+ #define __boot_rww_enable_short() \
452
+ (__extension__({ \
453
+ __asm__ __volatile__ \
454
+ ( \
455
+ "out %0, %1\n\t" \
456
+ "spm\n\t" \
457
+ : \
458
+ : "i" (_SFR_IO_ADDR(__SPM_REG)), \
459
+ "r" ((uint8_t)__BOOT_RWW_ENABLE) \
460
+ ); \
461
+ }))
462
+
463
+ #define __boot_rww_enable() \
464
+ (__extension__({ \
465
+ __asm__ __volatile__ \
466
+ ( \
467
+ "sts %0, %1\n\t" \
468
+ "spm\n\t" \
469
+ : \
470
+ : "i" (_SFR_MEM_ADDR(__SPM_REG)), \
471
+ "r" ((uint8_t)__BOOT_RWW_ENABLE) \
472
+ ); \
473
+ }))
474
+
475
+ #define __boot_rww_enable_alternate() \
476
+ (__extension__({ \
477
+ __asm__ __volatile__ \
478
+ ( \
479
+ "sts %0, %1\n\t" \
480
+ "spm\n\t" \
481
+ ".word 0xffff\n\t" \
482
+ "nop\n\t" \
483
+ : \
484
+ : "i" (_SFR_MEM_ADDR(__SPM_REG)), \
485
+ "r" ((uint8_t)__BOOT_RWW_ENABLE) \
486
+ ); \
487
+ }))
488
+
489
+ /* From the mega16/mega128 data sheets (maybe others):
490
+
491
+ Bits by SPM To set the Boot Loader Lock bits, write the desired data to
492
+ R0, write "X0001001" to SPMCR and execute SPM within four clock cycles
493
+ after writing SPMCR. The only accessible Lock bits are the Boot Lock bits
494
+ that may prevent the Application and Boot Loader section from any
495
+ software update by the MCU.
496
+
497
+ If bits 5..2 in R0 are cleared (zero), the corresponding Boot Lock bit
498
+ will be programmed if an SPM instruction is executed within four cycles
499
+ after BLBSET and SPMEN (or SELFPRGEN) are set in SPMCR. The Z-pointer is
500
+ don't care during this operation, but for future compatibility it is
501
+ recommended to load the Z-pointer with $0001 (same as used for reading the
502
+ Lock bits). For future compatibility It is also recommended to set bits 7,
503
+ 6, 1, and 0 in R0 to 1 when writing the Lock bits. When programming the
504
+ Lock bits the entire Flash can be read during the operation. */
505
+
506
+ #define __boot_lock_bits_set_short(lock_bits) \
507
+ (__extension__({ \
508
+ uint8_t value = (uint8_t)(~(lock_bits)); \
509
+ __asm__ __volatile__ \
510
+ ( \
511
+ "ldi r30, 1\n\t" \
512
+ "ldi r31, 0\n\t" \
513
+ "mov r0, %2\n\t" \
514
+ "out %0, %1\n\t" \
515
+ "spm\n\t" \
516
+ : \
517
+ : "i" (_SFR_IO_ADDR(__SPM_REG)), \
518
+ "r" ((uint8_t)__BOOT_LOCK_BITS_SET), \
519
+ "r" (value) \
520
+ : "r0", "r30", "r31" \
521
+ ); \
522
+ }))
523
+
524
+ #define __boot_lock_bits_set(lock_bits) \
525
+ (__extension__({ \
526
+ uint8_t value = (uint8_t)(~(lock_bits)); \
527
+ __asm__ __volatile__ \
528
+ ( \
529
+ "ldi r30, 1\n\t" \
530
+ "ldi r31, 0\n\t" \
531
+ "mov r0, %2\n\t" \
532
+ "sts %0, %1\n\t" \
533
+ "spm\n\t" \
534
+ : \
535
+ : "i" (_SFR_MEM_ADDR(__SPM_REG)), \
536
+ "r" ((uint8_t)__BOOT_LOCK_BITS_SET), \
537
+ "r" (value) \
538
+ : "r0", "r30", "r31" \
539
+ ); \
540
+ }))
541
+
542
+ #define __boot_lock_bits_set_alternate(lock_bits) \
543
+ (__extension__({ \
544
+ uint8_t value = (uint8_t)(~(lock_bits)); \
545
+ __asm__ __volatile__ \
546
+ ( \
547
+ "ldi r30, 1\n\t" \
548
+ "ldi r31, 0\n\t" \
549
+ "mov r0, %2\n\t" \
550
+ "sts %0, %1\n\t" \
551
+ "spm\n\t" \
552
+ ".word 0xffff\n\t" \
553
+ "nop\n\t" \
554
+ : \
555
+ : "i" (_SFR_MEM_ADDR(__SPM_REG)), \
556
+ "r" ((uint8_t)__BOOT_LOCK_BITS_SET), \
557
+ "r" (value) \
558
+ : "r0", "r30", "r31" \
559
+ ); \
560
+ }))
561
+
562
+ /*
563
+ Reading lock and fuse bits:
564
+
565
+ Similarly to writing the lock bits above, set BLBSET and SPMEN (or
566
+ SELFPRGEN) bits in __SPMREG, and then (within four clock cycles) issue an
567
+ LPM instruction.
568
+
569
+ Z address: contents:
570
+ 0x0000 low fuse bits
571
+ 0x0001 lock bits
572
+ 0x0002 extended fuse bits
573
+ 0x0003 high fuse bits
574
+
575
+ Sounds confusing, doesn't it?
576
+
577
+ Unlike the macros in pgmspace.h, no need to care for non-enhanced
578
+ cores here as these old cores do not provide SPM support anyway.
579
+ */
580
+
581
+ /** \ingroup avr_boot
582
+ \def GET_LOW_FUSE_BITS
583
+ address to read the low fuse bits, using boot_lock_fuse_bits_get
584
+ */
585
+ #define GET_LOW_FUSE_BITS (0x0000)
586
+ /** \ingroup avr_boot
587
+ \def GET_LOCK_BITS
588
+ address to read the lock bits, using boot_lock_fuse_bits_get
589
+ */
590
+ #define GET_LOCK_BITS (0x0001)
591
+ /** \ingroup avr_boot
592
+ \def GET_EXTENDED_FUSE_BITS
593
+ address to read the extended fuse bits, using boot_lock_fuse_bits_get
594
+ */
595
+ #define GET_EXTENDED_FUSE_BITS (0x0002)
596
+ /** \ingroup avr_boot
597
+ \def GET_HIGH_FUSE_BITS
598
+ address to read the high fuse bits, using boot_lock_fuse_bits_get
599
+ */
600
+ #define GET_HIGH_FUSE_BITS (0x0003)
601
+
602
+ /** \ingroup avr_boot
603
+ \def boot_lock_fuse_bits_get(address)
604
+
605
+ Read the lock or fuse bits at \c address.
606
+
607
+ Parameter \c address can be any of GET_LOW_FUSE_BITS,
608
+ GET_LOCK_BITS, GET_EXTENDED_FUSE_BITS, or GET_HIGH_FUSE_BITS.
609
+
610
+ \note The lock and fuse bits returned are the physical values,
611
+ i.e. a bit returned as 0 means the corresponding fuse or lock bit
612
+ is programmed.
613
+ */
614
+ #define boot_lock_fuse_bits_get_short(address) \
615
+ (__extension__({ \
616
+ uint8_t __result; \
617
+ __asm__ __volatile__ \
618
+ ( \
619
+ "ldi r30, %3\n\t" \
620
+ "ldi r31, 0\n\t" \
621
+ "out %1, %2\n\t" \
622
+ "lpm %0, Z\n\t" \
623
+ : "=r" (__result) \
624
+ : "i" (_SFR_IO_ADDR(__SPM_REG)), \
625
+ "r" ((uint8_t)__BOOT_LOCK_BITS_SET), \
626
+ "M" (address) \
627
+ : "r0", "r30", "r31" \
628
+ ); \
629
+ __result; \
630
+ }))
631
+
632
+ #define boot_lock_fuse_bits_get(address) \
633
+ (__extension__({ \
634
+ uint8_t __result; \
635
+ __asm__ __volatile__ \
636
+ ( \
637
+ "ldi r30, %3\n\t" \
638
+ "ldi r31, 0\n\t" \
639
+ "sts %1, %2\n\t" \
640
+ "lpm %0, Z\n\t" \
641
+ : "=r" (__result) \
642
+ : "i" (_SFR_MEM_ADDR(__SPM_REG)), \
643
+ "r" ((uint8_t)__BOOT_LOCK_BITS_SET), \
644
+ "M" (address) \
645
+ : "r0", "r30", "r31" \
646
+ ); \
647
+ __result; \
648
+ }))
649
+
650
+ /** \ingroup avr_boot
651
+ \def boot_signature_byte_get(address)
652
+
653
+ Read the Signature Row byte at \c address. For some MCU types,
654
+ this function can also retrieve the factory-stored oscillator
655
+ calibration bytes.
656
+
657
+ Parameter \c address can be 0-0x1f as documented by the datasheet.
658
+ \note The values are MCU type dependent.
659
+ */
660
+
661
+ #define __BOOT_SIGROW_READ (_BV(__SPM_ENABLE) | _BV(SIGRD))
662
+
663
+ #define boot_signature_byte_get_short(addr) \
664
+ (__extension__({ \
665
+ uint16_t __addr16 = (uint16_t)(addr); \
666
+ uint8_t __result; \
667
+ __asm__ __volatile__ \
668
+ ( \
669
+ "out %1, %2\n\t" \
670
+ "lpm %0, Z" "\n\t" \
671
+ : "=r" (__result) \
672
+ : "i" (_SFR_IO_ADDR(__SPM_REG)), \
673
+ "r" ((uint8_t) __BOOT_SIGROW_READ), \
674
+ "z" (__addr16) \
675
+ ); \
676
+ __result; \
677
+ }))
678
+
679
+ #define boot_signature_byte_get(addr) \
680
+ (__extension__({ \
681
+ uint16_t __addr16 = (uint16_t)(addr); \
682
+ uint8_t __result; \
683
+ __asm__ __volatile__ \
684
+ ( \
685
+ "sts %1, %2\n\t" \
686
+ "lpm %0, Z" "\n\t" \
687
+ : "=r" (__result) \
688
+ : "i" (_SFR_MEM_ADDR(__SPM_REG)), \
689
+ "r" ((uint8_t) __BOOT_SIGROW_READ), \
690
+ "z" (__addr16) \
691
+ ); \
692
+ __result; \
693
+ }))
694
+
695
+ /** \ingroup avr_boot
696
+ \def boot_page_fill(address, data)
697
+
698
+ Fill the bootloader temporary page buffer for flash
699
+ address with data word.
700
+
701
+ \note The address is a byte address. The data is a word. The AVR
702
+ writes data to the buffer a word at a time, but addresses the buffer
703
+ per byte! So, increment your address by 2 between calls, and send 2
704
+ data bytes in a word format! The LSB of the data is written to the lower
705
+ address; the MSB of the data is written to the higher address.*/
706
+
707
+ /** \ingroup avr_boot
708
+ \def boot_page_erase(address)
709
+
710
+ Erase the flash page that contains address.
711
+
712
+ \note address is a byte address in flash, not a word address. */
713
+
714
+ /** \ingroup avr_boot
715
+ \def boot_page_write(address)
716
+
717
+ Write the bootloader temporary page buffer
718
+ to flash page that contains address.
719
+
720
+ \note address is a byte address in flash, not a word address. */
721
+
722
+ /** \ingroup avr_boot
723
+ \def boot_rww_enable()
724
+
725
+ Enable the Read-While-Write memory section. */
726
+
727
+ /** \ingroup avr_boot
728
+ \def boot_lock_bits_set(lock_bits)
729
+
730
+ Set the bootloader lock bits.
731
+
732
+ \param lock_bits A mask of which Boot Loader Lock Bits to set.
733
+
734
+ \note In this context, a 'set bit' will be written to a zero value.
735
+ Note also that only BLBxx bits can be programmed by this command.
736
+
737
+ For example, to disallow the SPM instruction from writing to the Boot
738
+ Loader memory section of flash, you would use this macro as such:
739
+
740
+ \code
741
+ boot_lock_bits_set (_BV (BLB11));
742
+ \endcode
743
+
744
+ \note Like any lock bits, the Boot Loader Lock Bits, once set,
745
+ cannot be cleared again except by a chip erase which will in turn
746
+ also erase the boot loader itself. */
747
+
748
+ /* Normal versions of the macros use 16-bit addresses.
749
+ Extended versions of the macros use 32-bit addresses.
750
+ Alternate versions of the macros use 16-bit addresses and require special
751
+ instruction sequences after LPM.
752
+
753
+ FLASHEND is defined in the ioXXXX.h file.
754
+ USHRT_MAX is defined in <limits.h>. */
755
+
756
+ #if defined(__AVR_ATmega161__) || defined(__AVR_ATmega163__) \
757
+ || defined(__AVR_ATmega323__)
758
+
759
+ /* Alternate: ATmega161/163/323 and 16 bit address */
760
+ #define boot_page_fill(address, data) __boot_page_fill_alternate(address, data)
761
+ #define boot_page_erase(address) __boot_page_erase_alternate(address)
762
+ #define boot_page_write(address) __boot_page_write_alternate(address)
763
+ #define boot_rww_enable() __boot_rww_enable_alternate()
764
+ #define boot_lock_bits_set(lock_bits) __boot_lock_bits_set_alternate(lock_bits)
765
+
766
+ #elif (FLASHEND > USHRT_MAX)
767
+
768
+ /* Extended: >16 bit address */
769
+ #define boot_page_fill(address, data) __boot_page_fill_extended_short(address, data)
770
+ #define boot_page_erase(address) __boot_page_erase_extended_short(address)
771
+ #define boot_page_write(address) __boot_page_write_extended_short(address)
772
+ #define boot_rww_enable() __boot_rww_enable_short()
773
+ #define boot_lock_bits_set(lock_bits) __boot_lock_bits_set_short(lock_bits)
774
+
775
+ #else
776
+
777
+ /* Normal: 16 bit address */
778
+ #define boot_page_fill(address, data) __boot_page_fill_short(address, data)
779
+ #define boot_page_erase(address) __boot_page_erase_short(address)
780
+ #define boot_page_write(address) __boot_page_write_short(address)
781
+ #define boot_rww_enable() __boot_rww_enable_short()
782
+ #define boot_lock_bits_set(lock_bits) __boot_lock_bits_set_short(lock_bits)
783
+
784
+ #endif
785
+
786
+ /** \ingroup avr_boot
787
+
788
+ Same as boot_page_fill() except it waits for eeprom and spm operations to
789
+ complete before filling the page. */
790
+
791
+ #define boot_page_fill_safe(address, data) \
792
+ do { \
793
+ boot_spm_busy_wait(); \
794
+ eeprom_busy_wait(); \
795
+ boot_page_fill(address, data); \
796
+ } while (0)
797
+
798
+ /** \ingroup avr_boot
799
+
800
+ Same as boot_page_erase() except it waits for eeprom and spm operations to
801
+ complete before erasing the page. */
802
+
803
+ #define boot_page_erase_safe(address) \
804
+ do { \
805
+ boot_spm_busy_wait(); \
806
+ eeprom_busy_wait(); \
807
+ boot_page_erase (address); \
808
+ } while (0)
809
+
810
+ /** \ingroup avr_boot
811
+
812
+ Same as boot_page_write() except it waits for eeprom and spm operations to
813
+ complete before writing the page. */
814
+
815
+ #define boot_page_write_safe(address) \
816
+ do { \
817
+ boot_spm_busy_wait(); \
818
+ eeprom_busy_wait(); \
819
+ boot_page_write (address); \
820
+ } while (0)
821
+
822
+ /** \ingroup avr_boot
823
+
824
+ Same as boot_rww_enable() except waits for eeprom and spm operations to
825
+ complete before enabling the RWW mameory. */
826
+
827
+ #define boot_rww_enable_safe() \
828
+ do { \
829
+ boot_spm_busy_wait(); \
830
+ eeprom_busy_wait(); \
831
+ boot_rww_enable(); \
832
+ } while (0)
833
+
834
+ /** \ingroup avr_boot
835
+
836
+ Same as boot_lock_bits_set() except waits for eeprom and spm operations to
837
+ complete before setting the lock bits. */
838
+
839
+ #define boot_lock_bits_set_safe(lock_bits) \
840
+ do { \
841
+ boot_spm_busy_wait(); \
842
+ eeprom_busy_wait(); \
843
+ boot_lock_bits_set (lock_bits); \
844
+ } while (0)
845
+
846
+ #endif /* _AVR_BOOT_H_ */
hardware/arduino/avr/bootloaders/optiboot/makeall ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ make clean
3
+ #
4
+ # The "big three" standard bootloaders.
5
+ make atmega8
6
+ make atmega168
7
+ make atmega328
8
+ #
9
+ # additional buildable platforms of
10
+ # somewhat questionable support level
11
+ make lilypad
12
+ make lilypad_resonator
13
+ make pro8
14
+ make pro16
15
+ make pro20
16
+ make atmega328_pro8
17
+ make sanguino
18
+ make mega
19
+ make atmega88
20
+ make luminet
hardware/arduino/avr/bootloaders/optiboot/omake ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ echo ../../../tools/avr/bin/make OS=macosx ENV=arduino $*
2
+ ../../../tools/avr/bin/make OS=macosx ENV=arduino $*
hardware/arduino/avr/bootloaders/optiboot/omake.bat ADDED
@@ -0,0 +1 @@
 
 
1
+ ..\..\..\tools\avr\utils\bin\make OS=windows ENV=arduino %*
hardware/arduino/avr/bootloaders/optiboot/optiboot.c ADDED
@@ -0,0 +1,672 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**********************************************************/
2
+ /* Optiboot bootloader for Arduino */
3
+ /* */
4
+ /* http://optiboot.googlecode.com */
5
+ /* */
6
+ /* Arduino-maintained version : See README.TXT */
7
+ /* http://code.google.com/p/arduino/ */
8
+ /* */
9
+ /* Heavily optimised bootloader that is faster and */
10
+ /* smaller than the Arduino standard bootloader */
11
+ /* */
12
+ /* Enhancements: */
13
+ /* Fits in 512 bytes, saving 1.5K of code space */
14
+ /* Background page erasing speeds up programming */
15
+ /* Higher baud rate speeds up programming */
16
+ /* Written almost entirely in C */
17
+ /* Customisable timeout with accurate timeconstant */
18
+ /* Optional virtual UART. No hardware UART required. */
19
+ /* Optional virtual boot partition for devices without. */
20
+ /* */
21
+ /* What you lose: */
22
+ /* Implements a skeleton STK500 protocol which is */
23
+ /* missing several features including EEPROM */
24
+ /* programming and non-page-aligned writes */
25
+ /* High baud rate breaks compatibility with standard */
26
+ /* Arduino flash settings */
27
+ /* */
28
+ /* Fully supported: */
29
+ /* ATmega168 based devices (Diecimila etc) */
30
+ /* ATmega328P based devices (Duemilanove etc) */
31
+ /* */
32
+ /* Alpha test */
33
+ /* ATmega1280 based devices (Arduino Mega) */
34
+ /* */
35
+ /* Work in progress: */
36
+ /* ATmega644P based devices (Sanguino) */
37
+ /* ATtiny84 based devices (Luminet) */
38
+ /* */
39
+ /* Does not support: */
40
+ /* USB based devices (eg. Teensy) */
41
+ /* */
42
+ /* Assumptions: */
43
+ /* The code makes several assumptions that reduce the */
44
+ /* code size. They are all true after a hardware reset, */
45
+ /* but may not be true if the bootloader is called by */
46
+ /* other means or on other hardware. */
47
+ /* No interrupts can occur */
48
+ /* UART and Timer 1 are set to their reset state */
49
+ /* SP points to RAMEND */
50
+ /* */
51
+ /* Code builds on code, libraries and optimisations from: */
52
+ /* stk500boot.c by Jason P. Kyle */
53
+ /* Arduino bootloader http://www.arduino.cc */
54
+ /* Spiff's 1K bootloader http://spiffie.org/know/arduino_1k_bootloader/bootloader.shtml */
55
+ /* avr-libc project http://nongnu.org/avr-libc */
56
+ /* Adaboot http://www.ladyada.net/library/arduino/bootloader.html */
57
+ /* AVR305 Atmel Application Note */
58
+ /* */
59
+ /* This program is free software; you can redistribute it */
60
+ /* and/or modify it under the terms of the GNU General */
61
+ /* Public License as published by the Free Software */
62
+ /* Foundation; either version 2 of the License, or */
63
+ /* (at your option) any later version. */
64
+ /* */
65
+ /* This program is distributed in the hope that it will */
66
+ /* be useful, but WITHOUT ANY WARRANTY; without even the */
67
+ /* implied warranty of MERCHANTABILITY or FITNESS FOR A */
68
+ /* PARTICULAR PURPOSE. See the GNU General Public */
69
+ /* License for more details. */
70
+ /* */
71
+ /* You should have received a copy of the GNU General */
72
+ /* Public License along with this program; if not, write */
73
+ /* to the Free Software Foundation, Inc., */
74
+ /* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
75
+ /* */
76
+ /* Licence can be viewed at */
77
+ /* http://www.fsf.org/licenses/gpl.txt */
78
+ /* */
79
+ /**********************************************************/
80
+
81
+
82
+ /**********************************************************/
83
+ /* */
84
+ /* Optional defines: */
85
+ /* */
86
+ /**********************************************************/
87
+ /* */
88
+ /* BIG_BOOT: */
89
+ /* Build a 1k bootloader, not 512 bytes. This turns on */
90
+ /* extra functionality. */
91
+ /* */
92
+ /* BAUD_RATE: */
93
+ /* Set bootloader baud rate. */
94
+ /* */
95
+ /* LUDICROUS_SPEED: */
96
+ /* 230400 baud :-) */
97
+ /* */
98
+ /* SOFT_UART: */
99
+ /* Use AVR305 soft-UART instead of hardware UART. */
100
+ /* */
101
+ /* LED_START_FLASHES: */
102
+ /* Number of LED flashes on bootup. */
103
+ /* */
104
+ /* LED_DATA_FLASH: */
105
+ /* Flash LED when transferring data. For boards without */
106
+ /* TX or RX LEDs, or for people who like blinky lights. */
107
+ /* */
108
+ /* SUPPORT_EEPROM: */
109
+ /* Support reading and writing from EEPROM. This is not */
110
+ /* used by Arduino, so off by default. */
111
+ /* */
112
+ /* TIMEOUT_MS: */
113
+ /* Bootloader timeout period, in milliseconds. */
114
+ /* 500,1000,2000,4000,8000 supported. */
115
+ /* */
116
+ /**********************************************************/
117
+
118
+ /**********************************************************/
119
+ /* Version Numbers! */
120
+ /* */
121
+ /* Arduino Optiboot now includes this Version number in */
122
+ /* the source and object code. */
123
+ /* */
124
+ /* Version 3 was released as zip from the optiboot */
125
+ /* repository and was distributed with Arduino 0022. */
126
+ /* Version 4 starts with the arduino repository commit */
127
+ /* that brought the arduino repository up-to-date with */
128
+ /* the optiboot source tree changes since v3. */
129
+ /* */
130
+ /**********************************************************/
131
+
132
+ /**********************************************************/
133
+ /* Edit History: */
134
+ /* */
135
+ /* 4.4 WestfW: add initialization of address to keep */
136
+ /* the compiler happy. Change SC'ed targets. */
137
+ /* Return the SW version via READ PARAM */
138
+ /* 4.3 WestfW: catch framing errors in getch(), so that */
139
+ /* AVRISP works without HW kludges. */
140
+ /* http://code.google.com/p/arduino/issues/detail?id=368n*/
141
+ /* 4.2 WestfW: reduce code size, fix timeouts, change */
142
+ /* verifySpace to use WDT instead of appstart */
143
+ /* 4.1 WestfW: put version number in binary. */
144
+ /**********************************************************/
145
+
146
+ #define OPTIBOOT_MAJVER 4
147
+ #define OPTIBOOT_MINVER 4
148
+
149
+ #define MAKESTR(a) #a
150
+ #define MAKEVER(a, b) MAKESTR(a*256+b)
151
+
152
+ asm(" .section .version\n"
153
+ "optiboot_version: .word " MAKEVER(OPTIBOOT_MAJVER, OPTIBOOT_MINVER) "\n"
154
+ " .section .text\n");
155
+
156
+ #include <inttypes.h>
157
+ #include <avr/io.h>
158
+ #include <avr/pgmspace.h>
159
+
160
+ // <avr/boot.h> uses sts instructions, but this version uses out instructions
161
+ // This saves cycles and program memory.
162
+ #include "boot.h"
163
+
164
+
165
+ // We don't use <avr/wdt.h> as those routines have interrupt overhead we don't need.
166
+
167
+ #include "pin_defs.h"
168
+ #include "stk500.h"
169
+
170
+ #ifndef LED_START_FLASHES
171
+ #define LED_START_FLASHES 0
172
+ #endif
173
+
174
+ #ifdef LUDICROUS_SPEED
175
+ #define BAUD_RATE 230400L
176
+ #endif
177
+
178
+ /* set the UART baud rate defaults */
179
+ #ifndef BAUD_RATE
180
+ #if F_CPU >= 8000000L
181
+ #define BAUD_RATE 115200L // Highest rate Avrdude win32 will support
182
+ #elsif F_CPU >= 1000000L
183
+ #define BAUD_RATE 9600L // 19200 also supported, but with significant error
184
+ #elsif F_CPU >= 128000L
185
+ #define BAUD_RATE 4800L // Good for 128kHz internal RC
186
+ #else
187
+ #define BAUD_RATE 1200L // Good even at 32768Hz
188
+ #endif
189
+ #endif
190
+
191
+ /* Switch in soft UART for hard baud rates */
192
+ #if (F_CPU/BAUD_RATE) > 280 // > 57600 for 16MHz
193
+ #ifndef SOFT_UART
194
+ #define SOFT_UART
195
+ #endif
196
+ #endif
197
+
198
+ /* Watchdog settings */
199
+ #define WATCHDOG_OFF (0)
200
+ #define WATCHDOG_16MS (_BV(WDE))
201
+ #define WATCHDOG_32MS (_BV(WDP0) | _BV(WDE))
202
+ #define WATCHDOG_64MS (_BV(WDP1) | _BV(WDE))
203
+ #define WATCHDOG_125MS (_BV(WDP1) | _BV(WDP0) | _BV(WDE))
204
+ #define WATCHDOG_250MS (_BV(WDP2) | _BV(WDE))
205
+ #define WATCHDOG_500MS (_BV(WDP2) | _BV(WDP0) | _BV(WDE))
206
+ #define WATCHDOG_1S (_BV(WDP2) | _BV(WDP1) | _BV(WDE))
207
+ #define WATCHDOG_2S (_BV(WDP2) | _BV(WDP1) | _BV(WDP0) | _BV(WDE))
208
+ #ifndef __AVR_ATmega8__
209
+ #define WATCHDOG_4S (_BV(WDP3) | _BV(WDE))
210
+ #define WATCHDOG_8S (_BV(WDP3) | _BV(WDP0) | _BV(WDE))
211
+ #endif
212
+
213
+ /* Function Prototypes */
214
+ /* The main function is in init9, which removes the interrupt vector table */
215
+ /* we don't need. It is also 'naked', which means the compiler does not */
216
+ /* generate any entry or exit code itself. */
217
+ int main(void) __attribute__ ((naked)) __attribute__ ((section (".init9")));
218
+ void putch(char);
219
+ uint8_t getch(void);
220
+ static inline void getNch(uint8_t); /* "static inline" is a compiler hint to reduce code size */
221
+ void verifySpace();
222
+ static inline void flash_led(uint8_t);
223
+ uint8_t getLen();
224
+ static inline void watchdogReset();
225
+ void watchdogConfig(uint8_t x);
226
+ #ifdef SOFT_UART
227
+ void uartDelay() __attribute__ ((naked));
228
+ #endif
229
+ void appStart() __attribute__ ((naked));
230
+
231
+ #if defined(__AVR_ATmega168__)
232
+ #define RAMSTART (0x100)
233
+ #define NRWWSTART (0x3800)
234
+ #elif defined(__AVR_ATmega328P__) || defined(__AVR_ATmega328__)
235
+ #define RAMSTART (0x100)
236
+ #define NRWWSTART (0x7000)
237
+ #elif defined (__AVR_ATmega644P__)
238
+ #define RAMSTART (0x100)
239
+ #define NRWWSTART (0xE000)
240
+ #elif defined(__AVR_ATtiny84__)
241
+ #define RAMSTART (0x100)
242
+ #define NRWWSTART (0x0000)
243
+ #elif defined(__AVR_ATmega1280__)
244
+ #define RAMSTART (0x200)
245
+ #define NRWWSTART (0xE000)
246
+ #elif defined(__AVR_ATmega8__) || defined(__AVR_ATmega88__)
247
+ #define RAMSTART (0x100)
248
+ #define NRWWSTART (0x1800)
249
+ #endif
250
+
251
+ /* C zero initialises all global variables. However, that requires */
252
+ /* These definitions are NOT zero initialised, but that doesn't matter */
253
+ /* This allows us to drop the zero init code, saving us memory */
254
+ #define buff ((uint8_t*)(RAMSTART))
255
+ #ifdef VIRTUAL_BOOT_PARTITION
256
+ #define rstVect (*(uint16_t*)(RAMSTART+SPM_PAGESIZE*2+4))
257
+ #define wdtVect (*(uint16_t*)(RAMSTART+SPM_PAGESIZE*2+6))
258
+ #endif
259
+
260
+ /* main program starts here */
261
+ int main(void) {
262
+ uint8_t ch;
263
+
264
+ /*
265
+ * Making these local and in registers prevents the need for initializing
266
+ * them, and also saves space because code no longer stores to memory.
267
+ * (initializing address keeps the compiler happy, but isn't really
268
+ * necessary, and uses 4 bytes of flash.)
269
+ */
270
+ register uint16_t address = 0;
271
+ register uint8_t length;
272
+
273
+ // After the zero init loop, this is the first code to run.
274
+ //
275
+ // This code makes the following assumptions:
276
+ // No interrupts will execute
277
+ // SP points to RAMEND
278
+ // r1 contains zero
279
+ //
280
+ // If not, uncomment the following instructions:
281
+ // cli();
282
+ asm volatile ("clr __zero_reg__");
283
+ #ifdef __AVR_ATmega8__
284
+ SP=RAMEND; // This is done by hardware reset
285
+ #endif
286
+
287
+ // Adaboot no-wait mod
288
+ ch = MCUSR;
289
+ MCUSR = 0;
290
+ if (!(ch & _BV(EXTRF))) appStart();
291
+
292
+ #if LED_START_FLASHES > 0
293
+ // Set up Timer 1 for timeout counter
294
+ TCCR1B = _BV(CS12) | _BV(CS10); // div 1024
295
+ #endif
296
+ #ifndef SOFT_UART
297
+ #ifdef __AVR_ATmega8__
298
+ UCSRA = _BV(U2X); //Double speed mode USART
299
+ UCSRB = _BV(RXEN) | _BV(TXEN); // enable Rx & Tx
300
+ UCSRC = _BV(URSEL) | _BV(UCSZ1) | _BV(UCSZ0); // config USART; 8N1
301
+ UBRRL = (uint8_t)( (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 );
302
+ #else
303
+ UCSR0A = _BV(U2X0); //Double speed mode USART0
304
+ UCSR0B = _BV(RXEN0) | _BV(TXEN0);
305
+ UCSR0C = _BV(UCSZ00) | _BV(UCSZ01);
306
+ UBRR0L = (uint8_t)( (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 );
307
+ #endif
308
+ #endif
309
+
310
+ // Set up watchdog to trigger after 500ms
311
+ watchdogConfig(WATCHDOG_1S);
312
+
313
+ /* Set LED pin as output */
314
+ LED_DDR |= _BV(LED);
315
+
316
+ #ifdef SOFT_UART
317
+ /* Set TX pin as output */
318
+ UART_DDR |= _BV(UART_TX_BIT);
319
+ #endif
320
+
321
+ #if LED_START_FLASHES > 0
322
+ /* Flash onboard LED to signal entering of bootloader */
323
+ flash_led(LED_START_FLASHES * 2);
324
+ #endif
325
+
326
+ /* Forever loop */
327
+ for (;;) {
328
+ /* get character from UART */
329
+ ch = getch();
330
+
331
+ if(ch == STK_GET_PARAMETER) {
332
+ unsigned char which = getch();
333
+ verifySpace();
334
+ if (which == 0x82) {
335
+ /*
336
+ * Send optiboot version as "minor SW version"
337
+ */
338
+ putch(OPTIBOOT_MINVER);
339
+ } else if (which == 0x81) {
340
+ putch(OPTIBOOT_MAJVER);
341
+ } else {
342
+ /*
343
+ * GET PARAMETER returns a generic 0x03 reply for
344
+ * other parameters - enough to keep Avrdude happy
345
+ */
346
+ putch(0x03);
347
+ }
348
+ }
349
+ else if(ch == STK_SET_DEVICE) {
350
+ // SET DEVICE is ignored
351
+ getNch(20);
352
+ }
353
+ else if(ch == STK_SET_DEVICE_EXT) {
354
+ // SET DEVICE EXT is ignored
355
+ getNch(5);
356
+ }
357
+ else if(ch == STK_LOAD_ADDRESS) {
358
+ // LOAD ADDRESS
359
+ uint16_t newAddress;
360
+ newAddress = getch();
361
+ newAddress = (newAddress & 0xff) | (getch() << 8);
362
+ #ifdef RAMPZ
363
+ // Transfer top bit to RAMPZ
364
+ RAMPZ = (newAddress & 0x8000) ? 1 : 0;
365
+ #endif
366
+ newAddress += newAddress; // Convert from word address to byte address
367
+ address = newAddress;
368
+ verifySpace();
369
+ }
370
+ else if(ch == STK_UNIVERSAL) {
371
+ // UNIVERSAL command is ignored
372
+ getNch(4);
373
+ putch(0x00);
374
+ }
375
+ /* Write memory, length is big endian and is in bytes */
376
+ else if(ch == STK_PROG_PAGE) {
377
+ // PROGRAM PAGE - we support flash programming only, not EEPROM
378
+ uint8_t *bufPtr;
379
+ uint16_t addrPtr;
380
+
381
+ getch(); /* getlen() */
382
+ length = getch();
383
+ getch();
384
+
385
+ // If we are in RWW section, immediately start page erase
386
+ if (address < NRWWSTART) __boot_page_erase_short((uint16_t)(void*)address);
387
+
388
+ // While that is going on, read in page contents
389
+ bufPtr = buff;
390
+ do *bufPtr++ = getch();
391
+ while (--length);
392
+
393
+ // If we are in NRWW section, page erase has to be delayed until now.
394
+ // Todo: Take RAMPZ into account
395
+ if (address >= NRWWSTART) __boot_page_erase_short((uint16_t)(void*)address);
396
+
397
+ // Read command terminator, start reply
398
+ verifySpace();
399
+
400
+ // If only a partial page is to be programmed, the erase might not be complete.
401
+ // So check that here
402
+ boot_spm_busy_wait();
403
+
404
+ #ifdef VIRTUAL_BOOT_PARTITION
405
+ if ((uint16_t)(void*)address == 0) {
406
+ // This is the reset vector page. We need to live-patch the code so the
407
+ // bootloader runs.
408
+ //
409
+ // Move RESET vector to WDT vector
410
+ uint16_t vect = buff[0] | (buff[1]<<8);
411
+ rstVect = vect;
412
+ wdtVect = buff[8] | (buff[9]<<8);
413
+ vect -= 4; // Instruction is a relative jump (rjmp), so recalculate.
414
+ buff[8] = vect & 0xff;
415
+ buff[9] = vect >> 8;
416
+
417
+ // Add jump to bootloader at RESET vector
418
+ buff[0] = 0x7f;
419
+ buff[1] = 0xce; // rjmp 0x1d00 instruction
420
+ }
421
+ #endif
422
+
423
+ // Copy buffer into programming buffer
424
+ bufPtr = buff;
425
+ addrPtr = (uint16_t)(void*)address;
426
+ ch = SPM_PAGESIZE / 2;
427
+ do {
428
+ uint16_t a;
429
+ a = *bufPtr++;
430
+ a |= (*bufPtr++) << 8;
431
+ __boot_page_fill_short((uint16_t)(void*)addrPtr,a);
432
+ addrPtr += 2;
433
+ } while (--ch);
434
+
435
+ // Write from programming buffer
436
+ __boot_page_write_short((uint16_t)(void*)address);
437
+ boot_spm_busy_wait();
438
+
439
+ #if defined(RWWSRE)
440
+ // Reenable read access to flash
441
+ boot_rww_enable();
442
+ #endif
443
+
444
+ }
445
+ /* Read memory block mode, length is big endian. */
446
+ else if(ch == STK_READ_PAGE) {
447
+ // READ PAGE - we only read flash
448
+ getch(); /* getlen() */
449
+ length = getch();
450
+ getch();
451
+
452
+ verifySpace();
453
+ #ifdef VIRTUAL_BOOT_PARTITION
454
+ do {
455
+ // Undo vector patch in bottom page so verify passes
456
+ if (address == 0) ch=rstVect & 0xff;
457
+ else if (address == 1) ch=rstVect >> 8;
458
+ else if (address == 8) ch=wdtVect & 0xff;
459
+ else if (address == 9) ch=wdtVect >> 8;
460
+ else ch = pgm_read_byte_near(address);
461
+ address++;
462
+ putch(ch);
463
+ } while (--length);
464
+ #else
465
+ #ifdef __AVR_ATmega1280__
466
+ // do putch(pgm_read_byte_near(address++));
467
+ // while (--length);
468
+ do {
469
+ uint8_t result;
470
+ __asm__ ("elpm %0,Z\n":"=r"(result):"z"(address));
471
+ putch(result);
472
+ address++;
473
+ }
474
+ while (--length);
475
+ #else
476
+ do putch(pgm_read_byte_near(address++));
477
+ while (--length);
478
+ #endif
479
+ #endif
480
+ }
481
+
482
+ /* Get device signature bytes */
483
+ else if(ch == STK_READ_SIGN) {
484
+ // READ SIGN - return what Avrdude wants to hear
485
+ verifySpace();
486
+ putch(SIGNATURE_0);
487
+ putch(SIGNATURE_1);
488
+ putch(SIGNATURE_2);
489
+ }
490
+ else if (ch == 'Q') {
491
+ // Adaboot no-wait mod
492
+ watchdogConfig(WATCHDOG_16MS);
493
+ verifySpace();
494
+ }
495
+ else {
496
+ // This covers the response to commands like STK_ENTER_PROGMODE
497
+ verifySpace();
498
+ }
499
+ putch(STK_OK);
500
+ }
501
+ }
502
+
503
+ void putch(char ch) {
504
+ #ifndef SOFT_UART
505
+ while (!(UCSR0A & _BV(UDRE0)));
506
+ UDR0 = ch;
507
+ #else
508
+ __asm__ __volatile__ (
509
+ " com %[ch]\n" // ones complement, carry set
510
+ " sec\n"
511
+ "1: brcc 2f\n"
512
+ " cbi %[uartPort],%[uartBit]\n"
513
+ " rjmp 3f\n"
514
+ "2: sbi %[uartPort],%[uartBit]\n"
515
+ " nop\n"
516
+ "3: rcall uartDelay\n"
517
+ " rcall uartDelay\n"
518
+ " lsr %[ch]\n"
519
+ " dec %[bitcnt]\n"
520
+ " brne 1b\n"
521
+ :
522
+ :
523
+ [bitcnt] "d" (10),
524
+ [ch] "r" (ch),
525
+ [uartPort] "I" (_SFR_IO_ADDR(UART_PORT)),
526
+ [uartBit] "I" (UART_TX_BIT)
527
+ :
528
+ "r25"
529
+ );
530
+ #endif
531
+ }
532
+
533
+ uint8_t getch(void) {
534
+ uint8_t ch;
535
+
536
+ #ifdef LED_DATA_FLASH
537
+ #ifdef __AVR_ATmega8__
538
+ LED_PORT ^= _BV(LED);
539
+ #else
540
+ LED_PIN |= _BV(LED);
541
+ #endif
542
+ #endif
543
+
544
+ #ifdef SOFT_UART
545
+ __asm__ __volatile__ (
546
+ "1: sbic %[uartPin],%[uartBit]\n" // Wait for start edge
547
+ " rjmp 1b\n"
548
+ " rcall uartDelay\n" // Get to middle of start bit
549
+ "2: rcall uartDelay\n" // Wait 1 bit period
550
+ " rcall uartDelay\n" // Wait 1 bit period
551
+ " clc\n"
552
+ " sbic %[uartPin],%[uartBit]\n"
553
+ " sec\n"
554
+ " dec %[bitCnt]\n"
555
+ " breq 3f\n"
556
+ " ror %[ch]\n"
557
+ " rjmp 2b\n"
558
+ "3:\n"
559
+ :
560
+ [ch] "=r" (ch)
561
+ :
562
+ [bitCnt] "d" (9),
563
+ [uartPin] "I" (_SFR_IO_ADDR(UART_PIN)),
564
+ [uartBit] "I" (UART_RX_BIT)
565
+ :
566
+ "r25"
567
+ );
568
+ #else
569
+ while(!(UCSR0A & _BV(RXC0)))
570
+ ;
571
+ if (!(UCSR0A & _BV(FE0))) {
572
+ /*
573
+ * A Framing Error indicates (probably) that something is talking
574
+ * to us at the wrong bit rate. Assume that this is because it
575
+ * expects to be talking to the application, and DON'T reset the
576
+ * watchdog. This should cause the bootloader to abort and run
577
+ * the application "soon", if it keeps happening. (Note that we
578
+ * don't care that an invalid char is returned...)
579
+ */
580
+ watchdogReset();
581
+ }
582
+
583
+ ch = UDR0;
584
+ #endif
585
+
586
+ #ifdef LED_DATA_FLASH
587
+ #ifdef __AVR_ATmega8__
588
+ LED_PORT ^= _BV(LED);
589
+ #else
590
+ LED_PIN |= _BV(LED);
591
+ #endif
592
+ #endif
593
+
594
+ return ch;
595
+ }
596
+
597
+ #ifdef SOFT_UART
598
+ // AVR350 equation: #define UART_B_VALUE (((F_CPU/BAUD_RATE)-23)/6)
599
+ // Adding 3 to numerator simulates nearest rounding for more accurate baud rates
600
+ #define UART_B_VALUE (((F_CPU/BAUD_RATE)-20)/6)
601
+ #if UART_B_VALUE > 255
602
+ #error Baud rate too slow for soft UART
603
+ #endif
604
+
605
+ void uartDelay() {
606
+ __asm__ __volatile__ (
607
+ "ldi r25,%[count]\n"
608
+ "1:dec r25\n"
609
+ "brne 1b\n"
610
+ "ret\n"
611
+ ::[count] "M" (UART_B_VALUE)
612
+ );
613
+ }
614
+ #endif
615
+
616
+ void getNch(uint8_t count) {
617
+ do getch(); while (--count);
618
+ verifySpace();
619
+ }
620
+
621
+ void verifySpace() {
622
+ if (getch() != CRC_EOP) {
623
+ watchdogConfig(WATCHDOG_16MS); // shorten WD timeout
624
+ while (1) // and busy-loop so that WD causes
625
+ ; // a reset and app start.
626
+ }
627
+ putch(STK_INSYNC);
628
+ }
629
+
630
+ #if LED_START_FLASHES > 0
631
+ void flash_led(uint8_t count) {
632
+ do {
633
+ TCNT1 = -(F_CPU/(1024*16));
634
+ TIFR1 = _BV(TOV1);
635
+ while(!(TIFR1 & _BV(TOV1)));
636
+ #ifdef __AVR_ATmega8__
637
+ LED_PORT ^= _BV(LED);
638
+ #else
639
+ LED_PIN |= _BV(LED);
640
+ #endif
641
+ watchdogReset();
642
+ } while (--count);
643
+ }
644
+ #endif
645
+
646
+ // Watchdog functions. These are only safe with interrupts turned off.
647
+ void watchdogReset() {
648
+ __asm__ __volatile__ (
649
+ "wdr\n"
650
+ );
651
+ }
652
+
653
+ void watchdogConfig(uint8_t x) {
654
+ WDTCSR = _BV(WDCE) | _BV(WDE);
655
+ WDTCSR = x;
656
+ }
657
+
658
+ void appStart() {
659
+ watchdogConfig(WATCHDOG_OFF);
660
+ __asm__ __volatile__ (
661
+ #ifdef VIRTUAL_BOOT_PARTITION
662
+ // Jump to WDT vector
663
+ "ldi r30,4\n"
664
+ "clr r31\n"
665
+ #else
666
+ // Jump to RST vector
667
+ "clr r30\n"
668
+ "clr r31\n"
669
+ #endif
670
+ "ijmp\n"
671
+ );
672
+ }
hardware/arduino/avr/bootloaders/optiboot/optiboot_atmega168.hex ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ :103E0000112484B714BE81FFF0D085E08093810037
2
+ :103E100082E08093C00088E18093C10086E08093B7
3
+ :103E2000C20080E18093C4008EE0C9D0259A86E06C
4
+ :103E300020E33CEF91E0309385002093840096BB13
5
+ :103E4000B09BFECF1D9AA8958150A9F7CC24DD2404
6
+ :103E500088248394B5E0AB2EA1E19A2EF3E0BF2E27
7
+ :103E6000A2D0813461F49FD0082FAFD0023811F076
8
+ :103E7000013811F484E001C083E08DD089C0823420
9
+ :103E800011F484E103C0853419F485E0A6D080C024
10
+ :103E9000853579F488D0E82EFF2485D0082F10E0EE
11
+ :103EA000102F00270E291F29000F111F8ED0680127
12
+ :103EB0006FC0863521F484E090D080E0DECF843678
13
+ :103EC00009F040C070D06FD0082F6DD080E0C816C8
14
+ :103ED00088E3D80618F4F601B7BEE895C0E0D1E053
15
+ :103EE00062D089930C17E1F7F0E0CF16F8E3DF0614
16
+ :103EF00018F0F601B7BEE89568D007B600FCFDCF14
17
+ :103F0000A601A0E0B1E02C9130E011968C911197C0
18
+ :103F100090E0982F8827822B932B1296FA010C01A0
19
+ :103F200087BEE89511244E5F5F4FF1E0A038BF07D0
20
+ :103F300051F7F601A7BEE89507B600FCFDCF97BE86
21
+ :103F4000E89526C08437B1F42ED02DD0F82E2BD092
22
+ :103F50003CD0F601EF2C8F010F5F1F4F84911BD0D7
23
+ :103F6000EA94F801C1F70894C11CD11CFA94CF0C53
24
+ :103F7000D11C0EC0853739F428D08EE10CD084E9ED
25
+ :103F80000AD086E07ACF813511F488E018D01DD0B0
26
+ :103F900080E101D065CF982F8091C00085FFFCCFD4
27
+ :103FA0009093C60008958091C00087FFFCCF809158
28
+ :103FB000C00084FD01C0A8958091C6000895E0E688
29
+ :103FC000F0E098E1908380830895EDDF803219F06E
30
+ :103FD00088E0F5DFFFCF84E1DECF1F93182FE3DF0A
31
+ :103FE0001150E9F7F2DF1F91089580E0E8DFEE2736
32
+ :043FF000FF2709940A
33
+ :023FFE000404B9
34
+ :0400000300003E00BB
35
+ :00000001FF
hardware/arduino/avr/bootloaders/optiboot/optiboot_atmega168.lst ADDED
@@ -0,0 +1,598 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ optiboot_atmega168.elf: file format elf32-avr
3
+
4
+ Sections:
5
+ Idx Name Size VMA LMA File off Algn
6
+ 0 .text 000001f4 00003e00 00003e00 00000054 2**1
7
+ CONTENTS, ALLOC, LOAD, READONLY, CODE
8
+ 1 .version 00000002 00003ffe 00003ffe 00000248 2**0
9
+ CONTENTS, READONLY
10
+ 2 .debug_aranges 00000028 00000000 00000000 0000024a 2**0
11
+ CONTENTS, READONLY, DEBUGGING
12
+ 3 .debug_pubnames 0000005f 00000000 00000000 00000272 2**0
13
+ CONTENTS, READONLY, DEBUGGING
14
+ 4 .debug_info 000002a8 00000000 00000000 000002d1 2**0
15
+ CONTENTS, READONLY, DEBUGGING
16
+ 5 .debug_abbrev 00000178 00000000 00000000 00000579 2**0
17
+ CONTENTS, READONLY, DEBUGGING
18
+ 6 .debug_line 00000488 00000000 00000000 000006f1 2**0
19
+ CONTENTS, READONLY, DEBUGGING
20
+ 7 .debug_frame 00000080 00000000 00000000 00000b7c 2**2
21
+ CONTENTS, READONLY, DEBUGGING
22
+ 8 .debug_str 0000014f 00000000 00000000 00000bfc 2**0
23
+ CONTENTS, READONLY, DEBUGGING
24
+ 9 .debug_loc 000002d8 00000000 00000000 00000d4b 2**0
25
+ CONTENTS, READONLY, DEBUGGING
26
+ 10 .debug_ranges 00000078 00000000 00000000 00001023 2**0
27
+ CONTENTS, READONLY, DEBUGGING
28
+
29
+ Disassembly of section .text:
30
+
31
+ 00003e00 <main>:
32
+ #define rstVect (*(uint16_t*)(RAMSTART+SPM_PAGESIZE*2+4))
33
+ #define wdtVect (*(uint16_t*)(RAMSTART+SPM_PAGESIZE*2+6))
34
+ #endif
35
+
36
+ /* main program starts here */
37
+ int main(void) {
38
+ 3e00: 11 24 eor r1, r1
39
+ #ifdef __AVR_ATmega8__
40
+ SP=RAMEND; // This is done by hardware reset
41
+ #endif
42
+
43
+ // Adaboot no-wait mod
44
+ ch = MCUSR;
45
+ 3e02: 84 b7 in r24, 0x34 ; 52
46
+ MCUSR = 0;
47
+ 3e04: 14 be out 0x34, r1 ; 52
48
+ if (!(ch & _BV(EXTRF))) appStart();
49
+ 3e06: 81 ff sbrs r24, 1
50
+ 3e08: f0 d0 rcall .+480 ; 0x3fea <appStart>
51
+
52
+ #if LED_START_FLASHES > 0
53
+ // Set up Timer 1 for timeout counter
54
+ TCCR1B = _BV(CS12) | _BV(CS10); // div 1024
55
+ 3e0a: 85 e0 ldi r24, 0x05 ; 5
56
+ 3e0c: 80 93 81 00 sts 0x0081, r24
57
+ UCSRA = _BV(U2X); //Double speed mode USART
58
+ UCSRB = _BV(RXEN) | _BV(TXEN); // enable Rx & Tx
59
+ UCSRC = _BV(URSEL) | _BV(UCSZ1) | _BV(UCSZ0); // config USART; 8N1
60
+ UBRRL = (uint8_t)( (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 );
61
+ #else
62
+ UCSR0A = _BV(U2X0); //Double speed mode USART0
63
+ 3e10: 82 e0 ldi r24, 0x02 ; 2
64
+ 3e12: 80 93 c0 00 sts 0x00C0, r24
65
+ UCSR0B = _BV(RXEN0) | _BV(TXEN0);
66
+ 3e16: 88 e1 ldi r24, 0x18 ; 24
67
+ 3e18: 80 93 c1 00 sts 0x00C1, r24
68
+ UCSR0C = _BV(UCSZ00) | _BV(UCSZ01);
69
+ 3e1c: 86 e0 ldi r24, 0x06 ; 6
70
+ 3e1e: 80 93 c2 00 sts 0x00C2, r24
71
+ UBRR0L = (uint8_t)( (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 );
72
+ 3e22: 80 e1 ldi r24, 0x10 ; 16
73
+ 3e24: 80 93 c4 00 sts 0x00C4, r24
74
+ #endif
75
+ #endif
76
+
77
+ // Set up watchdog to trigger after 500ms
78
+ watchdogConfig(WATCHDOG_1S);
79
+ 3e28: 8e e0 ldi r24, 0x0E ; 14
80
+ 3e2a: c9 d0 rcall .+402 ; 0x3fbe <watchdogConfig>
81
+
82
+ /* Set LED pin as output */
83
+ LED_DDR |= _BV(LED);
84
+ 3e2c: 25 9a sbi 0x04, 5 ; 4
85
+ 3e2e: 86 e0 ldi r24, 0x06 ; 6
86
+ }
87
+
88
+ #if LED_START_FLASHES > 0
89
+ void flash_led(uint8_t count) {
90
+ do {
91
+ TCNT1 = -(F_CPU/(1024*16));
92
+ 3e30: 20 e3 ldi r18, 0x30 ; 48
93
+ 3e32: 3c ef ldi r19, 0xFC ; 252
94
+ TIFR1 = _BV(TOV1);
95
+ 3e34: 91 e0 ldi r25, 0x01 ; 1
96
+ }
97
+
98
+ #if LED_START_FLASHES > 0
99
+ void flash_led(uint8_t count) {
100
+ do {
101
+ TCNT1 = -(F_CPU/(1024*16));
102
+ 3e36: 30 93 85 00 sts 0x0085, r19
103
+ 3e3a: 20 93 84 00 sts 0x0084, r18
104
+ TIFR1 = _BV(TOV1);
105
+ 3e3e: 96 bb out 0x16, r25 ; 22
106
+ while(!(TIFR1 & _BV(TOV1)));
107
+ 3e40: b0 9b sbis 0x16, 0 ; 22
108
+ 3e42: fe cf rjmp .-4 ; 0x3e40 <main+0x40>
109
+ #ifdef __AVR_ATmega8__
110
+ LED_PORT ^= _BV(LED);
111
+ #else
112
+ LED_PIN |= _BV(LED);
113
+ 3e44: 1d 9a sbi 0x03, 5 ; 3
114
+ }
115
+ #endif
116
+
117
+ // Watchdog functions. These are only safe with interrupts turned off.
118
+ void watchdogReset() {
119
+ __asm__ __volatile__ (
120
+ 3e46: a8 95 wdr
121
+ LED_PORT ^= _BV(LED);
122
+ #else
123
+ LED_PIN |= _BV(LED);
124
+ #endif
125
+ watchdogReset();
126
+ } while (--count);
127
+ 3e48: 81 50 subi r24, 0x01 ; 1
128
+ 3e4a: a9 f7 brne .-22 ; 0x3e36 <main+0x36>
129
+ 3e4c: cc 24 eor r12, r12
130
+ 3e4e: dd 24 eor r13, r13
131
+ ch = SPM_PAGESIZE / 2;
132
+ do {
133
+ uint16_t a;
134
+ a = *bufPtr++;
135
+ a |= (*bufPtr++) << 8;
136
+ __boot_page_fill_short((uint16_t)(void*)addrPtr,a);
137
+ 3e50: 88 24 eor r8, r8
138
+ 3e52: 83 94 inc r8
139
+ addrPtr += 2;
140
+ } while (--ch);
141
+
142
+ // Write from programming buffer
143
+ __boot_page_write_short((uint16_t)(void*)address);
144
+ 3e54: b5 e0 ldi r27, 0x05 ; 5
145
+ 3e56: ab 2e mov r10, r27
146
+ boot_spm_busy_wait();
147
+
148
+ #if defined(RWWSRE)
149
+ // Reenable read access to flash
150
+ boot_rww_enable();
151
+ 3e58: a1 e1 ldi r26, 0x11 ; 17
152
+ 3e5a: 9a 2e mov r9, r26
153
+ do *bufPtr++ = getch();
154
+ while (--length);
155
+
156
+ // If we are in NRWW section, page erase has to be delayed until now.
157
+ // Todo: Take RAMPZ into account
158
+ if (address >= NRWWSTART) __boot_page_erase_short((uint16_t)(void*)address);
159
+ 3e5c: f3 e0 ldi r31, 0x03 ; 3
160
+ 3e5e: bf 2e mov r11, r31
161
+ #endif
162
+
163
+ /* Forever loop */
164
+ for (;;) {
165
+ /* get character from UART */
166
+ ch = getch();
167
+ 3e60: a2 d0 rcall .+324 ; 0x3fa6 <getch>
168
+
169
+ if(ch == STK_GET_PARAMETER) {
170
+ 3e62: 81 34 cpi r24, 0x41 ; 65
171
+ 3e64: 61 f4 brne .+24 ; 0x3e7e <main+0x7e>
172
+ unsigned char which = getch();
173
+ 3e66: 9f d0 rcall .+318 ; 0x3fa6 <getch>
174
+ 3e68: 08 2f mov r16, r24
175
+ verifySpace();
176
+ 3e6a: af d0 rcall .+350 ; 0x3fca <verifySpace>
177
+ if (which == 0x82) {
178
+ 3e6c: 02 38 cpi r16, 0x82 ; 130
179
+ 3e6e: 11 f0 breq .+4 ; 0x3e74 <main+0x74>
180
+ /*
181
+ * Send optiboot version as "minor SW version"
182
+ */
183
+ putch(OPTIBOOT_MINVER);
184
+ } else if (which == 0x81) {
185
+ 3e70: 01 38 cpi r16, 0x81 ; 129
186
+ 3e72: 11 f4 brne .+4 ; 0x3e78 <main+0x78>
187
+ putch(OPTIBOOT_MAJVER);
188
+ 3e74: 84 e0 ldi r24, 0x04 ; 4
189
+ 3e76: 01 c0 rjmp .+2 ; 0x3e7a <main+0x7a>
190
+ } else {
191
+ /*
192
+ * GET PARAMETER returns a generic 0x03 reply for
193
+ * other parameters - enough to keep Avrdude happy
194
+ */
195
+ putch(0x03);
196
+ 3e78: 83 e0 ldi r24, 0x03 ; 3
197
+ 3e7a: 8d d0 rcall .+282 ; 0x3f96 <putch>
198
+ 3e7c: 89 c0 rjmp .+274 ; 0x3f90 <main+0x190>
199
+ }
200
+ }
201
+ else if(ch == STK_SET_DEVICE) {
202
+ 3e7e: 82 34 cpi r24, 0x42 ; 66
203
+ 3e80: 11 f4 brne .+4 ; 0x3e86 <main+0x86>
204
+ // SET DEVICE is ignored
205
+ getNch(20);
206
+ 3e82: 84 e1 ldi r24, 0x14 ; 20
207
+ 3e84: 03 c0 rjmp .+6 ; 0x3e8c <main+0x8c>
208
+ }
209
+ else if(ch == STK_SET_DEVICE_EXT) {
210
+ 3e86: 85 34 cpi r24, 0x45 ; 69
211
+ 3e88: 19 f4 brne .+6 ; 0x3e90 <main+0x90>
212
+ // SET DEVICE EXT is ignored
213
+ getNch(5);
214
+ 3e8a: 85 e0 ldi r24, 0x05 ; 5
215
+ 3e8c: a6 d0 rcall .+332 ; 0x3fda <getNch>
216
+ 3e8e: 80 c0 rjmp .+256 ; 0x3f90 <main+0x190>
217
+ }
218
+ else if(ch == STK_LOAD_ADDRESS) {
219
+ 3e90: 85 35 cpi r24, 0x55 ; 85
220
+ 3e92: 79 f4 brne .+30 ; 0x3eb2 <main+0xb2>
221
+ // LOAD ADDRESS
222
+ uint16_t newAddress;
223
+ newAddress = getch();
224
+ 3e94: 88 d0 rcall .+272 ; 0x3fa6 <getch>
225
+ newAddress = (newAddress & 0xff) | (getch() << 8);
226
+ 3e96: e8 2e mov r14, r24
227
+ 3e98: ff 24 eor r15, r15
228
+ 3e9a: 85 d0 rcall .+266 ; 0x3fa6 <getch>
229
+ 3e9c: 08 2f mov r16, r24
230
+ 3e9e: 10 e0 ldi r17, 0x00 ; 0
231
+ 3ea0: 10 2f mov r17, r16
232
+ 3ea2: 00 27 eor r16, r16
233
+ 3ea4: 0e 29 or r16, r14
234
+ 3ea6: 1f 29 or r17, r15
235
+ #ifdef RAMPZ
236
+ // Transfer top bit to RAMPZ
237
+ RAMPZ = (newAddress & 0x8000) ? 1 : 0;
238
+ #endif
239
+ newAddress += newAddress; // Convert from word address to byte address
240
+ 3ea8: 00 0f add r16, r16
241
+ 3eaa: 11 1f adc r17, r17
242
+ address = newAddress;
243
+ verifySpace();
244
+ 3eac: 8e d0 rcall .+284 ; 0x3fca <verifySpace>
245
+ 3eae: 68 01 movw r12, r16
246
+ 3eb0: 6f c0 rjmp .+222 ; 0x3f90 <main+0x190>
247
+ }
248
+ else if(ch == STK_UNIVERSAL) {
249
+ 3eb2: 86 35 cpi r24, 0x56 ; 86
250
+ 3eb4: 21 f4 brne .+8 ; 0x3ebe <main+0xbe>
251
+ // UNIVERSAL command is ignored
252
+ getNch(4);
253
+ 3eb6: 84 e0 ldi r24, 0x04 ; 4
254
+ 3eb8: 90 d0 rcall .+288 ; 0x3fda <getNch>
255
+ putch(0x00);
256
+ 3eba: 80 e0 ldi r24, 0x00 ; 0
257
+ 3ebc: de cf rjmp .-68 ; 0x3e7a <main+0x7a>
258
+ }
259
+ /* Write memory, length is big endian and is in bytes */
260
+ else if(ch == STK_PROG_PAGE) {
261
+ 3ebe: 84 36 cpi r24, 0x64 ; 100
262
+ 3ec0: 09 f0 breq .+2 ; 0x3ec4 <main+0xc4>
263
+ 3ec2: 40 c0 rjmp .+128 ; 0x3f44 <main+0x144>
264
+ // PROGRAM PAGE - we support flash programming only, not EEPROM
265
+ uint8_t *bufPtr;
266
+ uint16_t addrPtr;
267
+
268
+ getch(); /* getlen() */
269
+ 3ec4: 70 d0 rcall .+224 ; 0x3fa6 <getch>
270
+ length = getch();
271
+ 3ec6: 6f d0 rcall .+222 ; 0x3fa6 <getch>
272
+ 3ec8: 08 2f mov r16, r24
273
+ getch();
274
+ 3eca: 6d d0 rcall .+218 ; 0x3fa6 <getch>
275
+
276
+ // If we are in RWW section, immediately start page erase
277
+ if (address < NRWWSTART) __boot_page_erase_short((uint16_t)(void*)address);
278
+ 3ecc: 80 e0 ldi r24, 0x00 ; 0
279
+ 3ece: c8 16 cp r12, r24
280
+ 3ed0: 88 e3 ldi r24, 0x38 ; 56
281
+ 3ed2: d8 06 cpc r13, r24
282
+ 3ed4: 18 f4 brcc .+6 ; 0x3edc <main+0xdc>
283
+ 3ed6: f6 01 movw r30, r12
284
+ 3ed8: b7 be out 0x37, r11 ; 55
285
+ 3eda: e8 95 spm
286
+ 3edc: c0 e0 ldi r28, 0x00 ; 0
287
+ 3ede: d1 e0 ldi r29, 0x01 ; 1
288
+
289
+ // While that is going on, read in page contents
290
+ bufPtr = buff;
291
+ do *bufPtr++ = getch();
292
+ 3ee0: 62 d0 rcall .+196 ; 0x3fa6 <getch>
293
+ 3ee2: 89 93 st Y+, r24
294
+ while (--length);
295
+ 3ee4: 0c 17 cp r16, r28
296
+ 3ee6: e1 f7 brne .-8 ; 0x3ee0 <main+0xe0>
297
+
298
+ // If we are in NRWW section, page erase has to be delayed until now.
299
+ // Todo: Take RAMPZ into account
300
+ if (address >= NRWWSTART) __boot_page_erase_short((uint16_t)(void*)address);
301
+ 3ee8: f0 e0 ldi r31, 0x00 ; 0
302
+ 3eea: cf 16 cp r12, r31
303
+ 3eec: f8 e3 ldi r31, 0x38 ; 56
304
+ 3eee: df 06 cpc r13, r31
305
+ 3ef0: 18 f0 brcs .+6 ; 0x3ef8 <main+0xf8>
306
+ 3ef2: f6 01 movw r30, r12
307
+ 3ef4: b7 be out 0x37, r11 ; 55
308
+ 3ef6: e8 95 spm
309
+
310
+ // Read command terminator, start reply
311
+ verifySpace();
312
+ 3ef8: 68 d0 rcall .+208 ; 0x3fca <verifySpace>
313
+
314
+ // If only a partial page is to be programmed, the erase might not be complete.
315
+ // So check that here
316
+ boot_spm_busy_wait();
317
+ 3efa: 07 b6 in r0, 0x37 ; 55
318
+ 3efc: 00 fc sbrc r0, 0
319
+ 3efe: fd cf rjmp .-6 ; 0x3efa <main+0xfa>
320
+ 3f00: a6 01 movw r20, r12
321
+ 3f02: a0 e0 ldi r26, 0x00 ; 0
322
+ 3f04: b1 e0 ldi r27, 0x01 ; 1
323
+ bufPtr = buff;
324
+ addrPtr = (uint16_t)(void*)address;
325
+ ch = SPM_PAGESIZE / 2;
326
+ do {
327
+ uint16_t a;
328
+ a = *bufPtr++;
329
+ 3f06: 2c 91 ld r18, X
330
+ 3f08: 30 e0 ldi r19, 0x00 ; 0
331
+ a |= (*bufPtr++) << 8;
332
+ 3f0a: 11 96 adiw r26, 0x01 ; 1
333
+ 3f0c: 8c 91 ld r24, X
334
+ 3f0e: 11 97 sbiw r26, 0x01 ; 1
335
+ 3f10: 90 e0 ldi r25, 0x00 ; 0
336
+ 3f12: 98 2f mov r25, r24
337
+ 3f14: 88 27 eor r24, r24
338
+ 3f16: 82 2b or r24, r18
339
+ 3f18: 93 2b or r25, r19
340
+ #define rstVect (*(uint16_t*)(RAMSTART+SPM_PAGESIZE*2+4))
341
+ #define wdtVect (*(uint16_t*)(RAMSTART+SPM_PAGESIZE*2+6))
342
+ #endif
343
+
344
+ /* main program starts here */
345
+ int main(void) {
346
+ 3f1a: 12 96 adiw r26, 0x02 ; 2
347
+ ch = SPM_PAGESIZE / 2;
348
+ do {
349
+ uint16_t a;
350
+ a = *bufPtr++;
351
+ a |= (*bufPtr++) << 8;
352
+ __boot_page_fill_short((uint16_t)(void*)addrPtr,a);
353
+ 3f1c: fa 01 movw r30, r20
354
+ 3f1e: 0c 01 movw r0, r24
355
+ 3f20: 87 be out 0x37, r8 ; 55
356
+ 3f22: e8 95 spm
357
+ 3f24: 11 24 eor r1, r1
358
+ addrPtr += 2;
359
+ 3f26: 4e 5f subi r20, 0xFE ; 254
360
+ 3f28: 5f 4f sbci r21, 0xFF ; 255
361
+ } while (--ch);
362
+ 3f2a: f1 e0 ldi r31, 0x01 ; 1
363
+ 3f2c: a0 38 cpi r26, 0x80 ; 128
364
+ 3f2e: bf 07 cpc r27, r31
365
+ 3f30: 51 f7 brne .-44 ; 0x3f06 <main+0x106>
366
+
367
+ // Write from programming buffer
368
+ __boot_page_write_short((uint16_t)(void*)address);
369
+ 3f32: f6 01 movw r30, r12
370
+ 3f34: a7 be out 0x37, r10 ; 55
371
+ 3f36: e8 95 spm
372
+ boot_spm_busy_wait();
373
+ 3f38: 07 b6 in r0, 0x37 ; 55
374
+ 3f3a: 00 fc sbrc r0, 0
375
+ 3f3c: fd cf rjmp .-6 ; 0x3f38 <main+0x138>
376
+
377
+ #if defined(RWWSRE)
378
+ // Reenable read access to flash
379
+ boot_rww_enable();
380
+ 3f3e: 97 be out 0x37, r9 ; 55
381
+ 3f40: e8 95 spm
382
+ 3f42: 26 c0 rjmp .+76 ; 0x3f90 <main+0x190>
383
+ #endif
384
+
385
+ }
386
+ /* Read memory block mode, length is big endian. */
387
+ else if(ch == STK_READ_PAGE) {
388
+ 3f44: 84 37 cpi r24, 0x74 ; 116
389
+ 3f46: b1 f4 brne .+44 ; 0x3f74 <main+0x174>
390
+ // READ PAGE - we only read flash
391
+ getch(); /* getlen() */
392
+ 3f48: 2e d0 rcall .+92 ; 0x3fa6 <getch>
393
+ length = getch();
394
+ 3f4a: 2d d0 rcall .+90 ; 0x3fa6 <getch>
395
+ 3f4c: f8 2e mov r15, r24
396
+ getch();
397
+ 3f4e: 2b d0 rcall .+86 ; 0x3fa6 <getch>
398
+
399
+ verifySpace();
400
+ 3f50: 3c d0 rcall .+120 ; 0x3fca <verifySpace>
401
+ 3f52: f6 01 movw r30, r12
402
+ 3f54: ef 2c mov r14, r15
403
+ putch(result);
404
+ address++;
405
+ }
406
+ while (--length);
407
+ #else
408
+ do putch(pgm_read_byte_near(address++));
409
+ 3f56: 8f 01 movw r16, r30
410
+ 3f58: 0f 5f subi r16, 0xFF ; 255
411
+ 3f5a: 1f 4f sbci r17, 0xFF ; 255
412
+ 3f5c: 84 91 lpm r24, Z+
413
+ 3f5e: 1b d0 rcall .+54 ; 0x3f96 <putch>
414
+ while (--length);
415
+ 3f60: ea 94 dec r14
416
+ 3f62: f8 01 movw r30, r16
417
+ 3f64: c1 f7 brne .-16 ; 0x3f56 <main+0x156>
418
+ #define rstVect (*(uint16_t*)(RAMSTART+SPM_PAGESIZE*2+4))
419
+ #define wdtVect (*(uint16_t*)(RAMSTART+SPM_PAGESIZE*2+6))
420
+ #endif
421
+
422
+ /* main program starts here */
423
+ int main(void) {
424
+ 3f66: 08 94 sec
425
+ 3f68: c1 1c adc r12, r1
426
+ 3f6a: d1 1c adc r13, r1
427
+ 3f6c: fa 94 dec r15
428
+ 3f6e: cf 0c add r12, r15
429
+ 3f70: d1 1c adc r13, r1
430
+ 3f72: 0e c0 rjmp .+28 ; 0x3f90 <main+0x190>
431
+ #endif
432
+ #endif
433
+ }
434
+
435
+ /* Get device signature bytes */
436
+ else if(ch == STK_READ_SIGN) {
437
+ 3f74: 85 37 cpi r24, 0x75 ; 117
438
+ 3f76: 39 f4 brne .+14 ; 0x3f86 <main+0x186>
439
+ // READ SIGN - return what Avrdude wants to hear
440
+ verifySpace();
441
+ 3f78: 28 d0 rcall .+80 ; 0x3fca <verifySpace>
442
+ putch(SIGNATURE_0);
443
+ 3f7a: 8e e1 ldi r24, 0x1E ; 30
444
+ 3f7c: 0c d0 rcall .+24 ; 0x3f96 <putch>
445
+ putch(SIGNATURE_1);
446
+ 3f7e: 84 e9 ldi r24, 0x94 ; 148
447
+ 3f80: 0a d0 rcall .+20 ; 0x3f96 <putch>
448
+ putch(SIGNATURE_2);
449
+ 3f82: 86 e0 ldi r24, 0x06 ; 6
450
+ 3f84: 7a cf rjmp .-268 ; 0x3e7a <main+0x7a>
451
+ }
452
+ else if (ch == 'Q') {
453
+ 3f86: 81 35 cpi r24, 0x51 ; 81
454
+ 3f88: 11 f4 brne .+4 ; 0x3f8e <main+0x18e>
455
+ // Adaboot no-wait mod
456
+ watchdogConfig(WATCHDOG_16MS);
457
+ 3f8a: 88 e0 ldi r24, 0x08 ; 8
458
+ 3f8c: 18 d0 rcall .+48 ; 0x3fbe <watchdogConfig>
459
+ verifySpace();
460
+ }
461
+ else {
462
+ // This covers the response to commands like STK_ENTER_PROGMODE
463
+ verifySpace();
464
+ 3f8e: 1d d0 rcall .+58 ; 0x3fca <verifySpace>
465
+ }
466
+ putch(STK_OK);
467
+ 3f90: 80 e1 ldi r24, 0x10 ; 16
468
+ 3f92: 01 d0 rcall .+2 ; 0x3f96 <putch>
469
+ 3f94: 65 cf rjmp .-310 ; 0x3e60 <main+0x60>
470
+
471
+ 00003f96 <putch>:
472
+ }
473
+ }
474
+
475
+ void putch(char ch) {
476
+ 3f96: 98 2f mov r25, r24
477
+ #ifndef SOFT_UART
478
+ while (!(UCSR0A & _BV(UDRE0)));
479
+ 3f98: 80 91 c0 00 lds r24, 0x00C0
480
+ 3f9c: 85 ff sbrs r24, 5
481
+ 3f9e: fc cf rjmp .-8 ; 0x3f98 <putch+0x2>
482
+ UDR0 = ch;
483
+ 3fa0: 90 93 c6 00 sts 0x00C6, r25
484
+ [uartBit] "I" (UART_TX_BIT)
485
+ :
486
+ "r25"
487
+ );
488
+ #endif
489
+ }
490
+ 3fa4: 08 95 ret
491
+
492
+ 00003fa6 <getch>:
493
+ [uartBit] "I" (UART_RX_BIT)
494
+ :
495
+ "r25"
496
+ );
497
+ #else
498
+ while(!(UCSR0A & _BV(RXC0)))
499
+ 3fa6: 80 91 c0 00 lds r24, 0x00C0
500
+ 3faa: 87 ff sbrs r24, 7
501
+ 3fac: fc cf rjmp .-8 ; 0x3fa6 <getch>
502
+ ;
503
+ if (!(UCSR0A & _BV(FE0))) {
504
+ 3fae: 80 91 c0 00 lds r24, 0x00C0
505
+ 3fb2: 84 fd sbrc r24, 4
506
+ 3fb4: 01 c0 rjmp .+2 ; 0x3fb8 <getch+0x12>
507
+ }
508
+ #endif
509
+
510
+ // Watchdog functions. These are only safe with interrupts turned off.
511
+ void watchdogReset() {
512
+ __asm__ __volatile__ (
513
+ 3fb6: a8 95 wdr
514
+ * don't care that an invalid char is returned...)
515
+ */
516
+ watchdogReset();
517
+ }
518
+
519
+ ch = UDR0;
520
+ 3fb8: 80 91 c6 00 lds r24, 0x00C6
521
+ LED_PIN |= _BV(LED);
522
+ #endif
523
+ #endif
524
+
525
+ return ch;
526
+ }
527
+ 3fbc: 08 95 ret
528
+
529
+ 00003fbe <watchdogConfig>:
530
+ "wdr\n"
531
+ );
532
+ }
533
+
534
+ void watchdogConfig(uint8_t x) {
535
+ WDTCSR = _BV(WDCE) | _BV(WDE);
536
+ 3fbe: e0 e6 ldi r30, 0x60 ; 96
537
+ 3fc0: f0 e0 ldi r31, 0x00 ; 0
538
+ 3fc2: 98 e1 ldi r25, 0x18 ; 24
539
+ 3fc4: 90 83 st Z, r25
540
+ WDTCSR = x;
541
+ 3fc6: 80 83 st Z, r24
542
+ }
543
+ 3fc8: 08 95 ret
544
+
545
+ 00003fca <verifySpace>:
546
+ do getch(); while (--count);
547
+ verifySpace();
548
+ }
549
+
550
+ void verifySpace() {
551
+ if (getch() != CRC_EOP) {
552
+ 3fca: ed df rcall .-38 ; 0x3fa6 <getch>
553
+ 3fcc: 80 32 cpi r24, 0x20 ; 32
554
+ 3fce: 19 f0 breq .+6 ; 0x3fd6 <verifySpace+0xc>
555
+ watchdogConfig(WATCHDOG_16MS); // shorten WD timeout
556
+ 3fd0: 88 e0 ldi r24, 0x08 ; 8
557
+ 3fd2: f5 df rcall .-22 ; 0x3fbe <watchdogConfig>
558
+ 3fd4: ff cf rjmp .-2 ; 0x3fd4 <verifySpace+0xa>
559
+ while (1) // and busy-loop so that WD causes
560
+ ; // a reset and app start.
561
+ }
562
+ putch(STK_INSYNC);
563
+ 3fd6: 84 e1 ldi r24, 0x14 ; 20
564
+ }
565
+ 3fd8: de cf rjmp .-68 ; 0x3f96 <putch>
566
+
567
+ 00003fda <getNch>:
568
+ ::[count] "M" (UART_B_VALUE)
569
+ );
570
+ }
571
+ #endif
572
+
573
+ void getNch(uint8_t count) {
574
+ 3fda: 1f 93 push r17
575
+ 3fdc: 18 2f mov r17, r24
576
+ do getch(); while (--count);
577
+ 3fde: e3 df rcall .-58 ; 0x3fa6 <getch>
578
+ 3fe0: 11 50 subi r17, 0x01 ; 1
579
+ 3fe2: e9 f7 brne .-6 ; 0x3fde <getNch+0x4>
580
+ verifySpace();
581
+ 3fe4: f2 df rcall .-28 ; 0x3fca <verifySpace>
582
+ }
583
+ 3fe6: 1f 91 pop r17
584
+ 3fe8: 08 95 ret
585
+
586
+ 00003fea <appStart>:
587
+ WDTCSR = _BV(WDCE) | _BV(WDE);
588
+ WDTCSR = x;
589
+ }
590
+
591
+ void appStart() {
592
+ watchdogConfig(WATCHDOG_OFF);
593
+ 3fea: 80 e0 ldi r24, 0x00 ; 0
594
+ 3fec: e8 df rcall .-48 ; 0x3fbe <watchdogConfig>
595
+ __asm__ __volatile__ (
596
+ 3fee: ee 27 eor r30, r30
597
+ 3ff0: ff 27 eor r31, r31
598
+ 3ff2: 09 94 ijmp
hardware/arduino/avr/bootloaders/optiboot/optiboot_atmega328-Mini.hex ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ :107E000085E08093810082E08093C00088E18093C8
2
+ :107E1000C10086E08093C20080E18093C40084B7F3
3
+ :107E200014BE81FFD0D089E2C8D0259A86E020E335
4
+ :107E30003CEF91E0309385002093840096BBB09B8B
5
+ :107E4000FECF1D9AA8958150A9F7DD24D394A5E013
6
+ :107E5000EA2EF1E1FF2EA4D0813421F481E0BED0DE
7
+ :107E600083E024C0823411F484E103C0853419F422
8
+ :107E700085E0B4D08AC08535A1F492D0082F10E0F7
9
+ :107E800010930102009300028BD090E0982F882776
10
+ :107E9000802B912B880F991F9093010280930002F1
11
+ :107EA00073C0863529F484E099D080E071D06DC02C
12
+ :107EB000843609F043C07CD0E0910002F0910102C9
13
+ :107EC00083E080935700E895C0E0D1E069D08993C2
14
+ :107ED000809102028150809302028823B9F778D002
15
+ :107EE00007B600FCFDCF4091000250910102A0E0D6
16
+ :107EF000B1E02C9130E011968C91119790E0982F81
17
+ :107F00008827822B932B1296FA010C01D0925700EE
18
+ :107F1000E89511244E5F5F4FF1E0A038BF0749F7A5
19
+ :107F2000E0910002F0910102E0925700E89507B657
20
+ :107F300000FCFDCFF0925700E89527C08437B9F4D4
21
+ :107F400037D046D0E0910002F09101023196F093D3
22
+ :107F50000102E09300023197E4918E2F19D08091B5
23
+ :107F60000202815080930202882361F70EC0853798
24
+ :107F700039F42ED08EE10CD085E90AD08FE096CF6F
25
+ :107F8000813511F488E019D023D080E101D063CF8E
26
+ :107F9000982F8091C00085FFFCCF9093C600089574
27
+ :107FA000A8958091C00087FFFCCF8091C6000895FE
28
+ :107FB000F7DFF6DF80930202F3CFE0E6F0E098E12E
29
+ :107FC00090838083089580E0F8DFEE27FF270994EF
30
+ :107FD000E7DF803209F0F7DF84E1DACF1F93182F53
31
+ :0C7FE000DFDF1150E9F7F4DF1F91089576
32
+ :0400000300007E007B
33
+ :00000001FF
hardware/arduino/avr/bootloaders/optiboot/optiboot_atmega328.hex ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ :107E0000112484B714BE81FFF0D085E080938100F7
2
+ :107E100082E08093C00088E18093C10086E0809377
3
+ :107E2000C20080E18093C4008EE0C9D0259A86E02C
4
+ :107E300020E33CEF91E0309385002093840096BBD3
5
+ :107E4000B09BFECF1D9AA8958150A9F7CC24DD24C4
6
+ :107E500088248394B5E0AB2EA1E19A2EF3E0BF2EE7
7
+ :107E6000A2D0813461F49FD0082FAFD0023811F036
8
+ :107E7000013811F484E001C083E08DD089C08234E0
9
+ :107E800011F484E103C0853419F485E0A6D080C0E4
10
+ :107E9000853579F488D0E82EFF2485D0082F10E0AE
11
+ :107EA000102F00270E291F29000F111F8ED06801E7
12
+ :107EB0006FC0863521F484E090D080E0DECF843638
13
+ :107EC00009F040C070D06FD0082F6DD080E0C81688
14
+ :107ED00080E7D80618F4F601B7BEE895C0E0D1E017
15
+ :107EE00062D089930C17E1F7F0E0CF16F0E7DF06D8
16
+ :107EF00018F0F601B7BEE89568D007B600FCFDCFD4
17
+ :107F0000A601A0E0B1E02C9130E011968C91119780
18
+ :107F100090E0982F8827822B932B1296FA010C0160
19
+ :107F200087BEE89511244E5F5F4FF1E0A038BF0790
20
+ :107F300051F7F601A7BEE89507B600FCFDCF97BE46
21
+ :107F4000E89526C08437B1F42ED02DD0F82E2BD052
22
+ :107F50003CD0F601EF2C8F010F5F1F4F84911BD097
23
+ :107F6000EA94F801C1F70894C11CD11CFA94CF0C13
24
+ :107F7000D11C0EC0853739F428D08EE10CD085E9AC
25
+ :107F80000AD08FE07ACF813511F488E018D01DD067
26
+ :107F900080E101D065CF982F8091C00085FFFCCF94
27
+ :107FA0009093C60008958091C00087FFFCCF809118
28
+ :107FB000C00084FD01C0A8958091C6000895E0E648
29
+ :107FC000F0E098E1908380830895EDDF803219F02E
30
+ :107FD00088E0F5DFFFCF84E1DECF1F93182FE3DFCA
31
+ :107FE0001150E9F7F2DF1F91089580E0E8DFEE27F6
32
+ :047FF000FF270994CA
33
+ :027FFE00040479
34
+ :0400000300007E007B
35
+ :00000001FF
hardware/arduino/avr/bootloaders/optiboot/optiboot_atmega328.lst ADDED
@@ -0,0 +1,598 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ optiboot_atmega328.elf: file format elf32-avr
3
+
4
+ Sections:
5
+ Idx Name Size VMA LMA File off Algn
6
+ 0 .text 000001f4 00007e00 00007e00 00000054 2**1
7
+ CONTENTS, ALLOC, LOAD, READONLY, CODE
8
+ 1 .version 00000002 00007ffe 00007ffe 00000248 2**0
9
+ CONTENTS, READONLY
10
+ 2 .debug_aranges 00000028 00000000 00000000 0000024a 2**0
11
+ CONTENTS, READONLY, DEBUGGING
12
+ 3 .debug_pubnames 0000005f 00000000 00000000 00000272 2**0
13
+ CONTENTS, READONLY, DEBUGGING
14
+ 4 .debug_info 000002a8 00000000 00000000 000002d1 2**0
15
+ CONTENTS, READONLY, DEBUGGING
16
+ 5 .debug_abbrev 00000178 00000000 00000000 00000579 2**0
17
+ CONTENTS, READONLY, DEBUGGING
18
+ 6 .debug_line 00000488 00000000 00000000 000006f1 2**0
19
+ CONTENTS, READONLY, DEBUGGING
20
+ 7 .debug_frame 00000080 00000000 00000000 00000b7c 2**2
21
+ CONTENTS, READONLY, DEBUGGING
22
+ 8 .debug_str 0000014f 00000000 00000000 00000bfc 2**0
23
+ CONTENTS, READONLY, DEBUGGING
24
+ 9 .debug_loc 000002d8 00000000 00000000 00000d4b 2**0
25
+ CONTENTS, READONLY, DEBUGGING
26
+ 10 .debug_ranges 00000078 00000000 00000000 00001023 2**0
27
+ CONTENTS, READONLY, DEBUGGING
28
+
29
+ Disassembly of section .text:
30
+
31
+ 00007e00 <main>:
32
+ #define rstVect (*(uint16_t*)(RAMSTART+SPM_PAGESIZE*2+4))
33
+ #define wdtVect (*(uint16_t*)(RAMSTART+SPM_PAGESIZE*2+6))
34
+ #endif
35
+
36
+ /* main program starts here */
37
+ int main(void) {
38
+ 7e00: 11 24 eor r1, r1
39
+ #ifdef __AVR_ATmega8__
40
+ SP=RAMEND; // This is done by hardware reset
41
+ #endif
42
+
43
+ // Adaboot no-wait mod
44
+ ch = MCUSR;
45
+ 7e02: 84 b7 in r24, 0x34 ; 52
46
+ MCUSR = 0;
47
+ 7e04: 14 be out 0x34, r1 ; 52
48
+ if (!(ch & _BV(EXTRF))) appStart();
49
+ 7e06: 81 ff sbrs r24, 1
50
+ 7e08: f0 d0 rcall .+480 ; 0x7fea <appStart>
51
+
52
+ #if LED_START_FLASHES > 0
53
+ // Set up Timer 1 for timeout counter
54
+ TCCR1B = _BV(CS12) | _BV(CS10); // div 1024
55
+ 7e0a: 85 e0 ldi r24, 0x05 ; 5
56
+ 7e0c: 80 93 81 00 sts 0x0081, r24
57
+ UCSRA = _BV(U2X); //Double speed mode USART
58
+ UCSRB = _BV(RXEN) | _BV(TXEN); // enable Rx & Tx
59
+ UCSRC = _BV(URSEL) | _BV(UCSZ1) | _BV(UCSZ0); // config USART; 8N1
60
+ UBRRL = (uint8_t)( (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 );
61
+ #else
62
+ UCSR0A = _BV(U2X0); //Double speed mode USART0
63
+ 7e10: 82 e0 ldi r24, 0x02 ; 2
64
+ 7e12: 80 93 c0 00 sts 0x00C0, r24
65
+ UCSR0B = _BV(RXEN0) | _BV(TXEN0);
66
+ 7e16: 88 e1 ldi r24, 0x18 ; 24
67
+ 7e18: 80 93 c1 00 sts 0x00C1, r24
68
+ UCSR0C = _BV(UCSZ00) | _BV(UCSZ01);
69
+ 7e1c: 86 e0 ldi r24, 0x06 ; 6
70
+ 7e1e: 80 93 c2 00 sts 0x00C2, r24
71
+ UBRR0L = (uint8_t)( (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 );
72
+ 7e22: 80 e1 ldi r24, 0x10 ; 16
73
+ 7e24: 80 93 c4 00 sts 0x00C4, r24
74
+ #endif
75
+ #endif
76
+
77
+ // Set up watchdog to trigger after 500ms
78
+ watchdogConfig(WATCHDOG_1S);
79
+ 7e28: 8e e0 ldi r24, 0x0E ; 14
80
+ 7e2a: c9 d0 rcall .+402 ; 0x7fbe <watchdogConfig>
81
+
82
+ /* Set LED pin as output */
83
+ LED_DDR |= _BV(LED);
84
+ 7e2c: 25 9a sbi 0x04, 5 ; 4
85
+ 7e2e: 86 e0 ldi r24, 0x06 ; 6
86
+ }
87
+
88
+ #if LED_START_FLASHES > 0
89
+ void flash_led(uint8_t count) {
90
+ do {
91
+ TCNT1 = -(F_CPU/(1024*16));
92
+ 7e30: 20 e3 ldi r18, 0x30 ; 48
93
+ 7e32: 3c ef ldi r19, 0xFC ; 252
94
+ TIFR1 = _BV(TOV1);
95
+ 7e34: 91 e0 ldi r25, 0x01 ; 1
96
+ }
97
+
98
+ #if LED_START_FLASHES > 0
99
+ void flash_led(uint8_t count) {
100
+ do {
101
+ TCNT1 = -(F_CPU/(1024*16));
102
+ 7e36: 30 93 85 00 sts 0x0085, r19
103
+ 7e3a: 20 93 84 00 sts 0x0084, r18
104
+ TIFR1 = _BV(TOV1);
105
+ 7e3e: 96 bb out 0x16, r25 ; 22
106
+ while(!(TIFR1 & _BV(TOV1)));
107
+ 7e40: b0 9b sbis 0x16, 0 ; 22
108
+ 7e42: fe cf rjmp .-4 ; 0x7e40 <main+0x40>
109
+ #ifdef __AVR_ATmega8__
110
+ LED_PORT ^= _BV(LED);
111
+ #else
112
+ LED_PIN |= _BV(LED);
113
+ 7e44: 1d 9a sbi 0x03, 5 ; 3
114
+ }
115
+ #endif
116
+
117
+ // Watchdog functions. These are only safe with interrupts turned off.
118
+ void watchdogReset() {
119
+ __asm__ __volatile__ (
120
+ 7e46: a8 95 wdr
121
+ LED_PORT ^= _BV(LED);
122
+ #else
123
+ LED_PIN |= _BV(LED);
124
+ #endif
125
+ watchdogReset();
126
+ } while (--count);
127
+ 7e48: 81 50 subi r24, 0x01 ; 1
128
+ 7e4a: a9 f7 brne .-22 ; 0x7e36 <main+0x36>
129
+ 7e4c: cc 24 eor r12, r12
130
+ 7e4e: dd 24 eor r13, r13
131
+ ch = SPM_PAGESIZE / 2;
132
+ do {
133
+ uint16_t a;
134
+ a = *bufPtr++;
135
+ a |= (*bufPtr++) << 8;
136
+ __boot_page_fill_short((uint16_t)(void*)addrPtr,a);
137
+ 7e50: 88 24 eor r8, r8
138
+ 7e52: 83 94 inc r8
139
+ addrPtr += 2;
140
+ } while (--ch);
141
+
142
+ // Write from programming buffer
143
+ __boot_page_write_short((uint16_t)(void*)address);
144
+ 7e54: b5 e0 ldi r27, 0x05 ; 5
145
+ 7e56: ab 2e mov r10, r27
146
+ boot_spm_busy_wait();
147
+
148
+ #if defined(RWWSRE)
149
+ // Reenable read access to flash
150
+ boot_rww_enable();
151
+ 7e58: a1 e1 ldi r26, 0x11 ; 17
152
+ 7e5a: 9a 2e mov r9, r26
153
+ do *bufPtr++ = getch();
154
+ while (--length);
155
+
156
+ // If we are in NRWW section, page erase has to be delayed until now.
157
+ // Todo: Take RAMPZ into account
158
+ if (address >= NRWWSTART) __boot_page_erase_short((uint16_t)(void*)address);
159
+ 7e5c: f3 e0 ldi r31, 0x03 ; 3
160
+ 7e5e: bf 2e mov r11, r31
161
+ #endif
162
+
163
+ /* Forever loop */
164
+ for (;;) {
165
+ /* get character from UART */
166
+ ch = getch();
167
+ 7e60: a2 d0 rcall .+324 ; 0x7fa6 <getch>
168
+
169
+ if(ch == STK_GET_PARAMETER) {
170
+ 7e62: 81 34 cpi r24, 0x41 ; 65
171
+ 7e64: 61 f4 brne .+24 ; 0x7e7e <main+0x7e>
172
+ unsigned char which = getch();
173
+ 7e66: 9f d0 rcall .+318 ; 0x7fa6 <getch>
174
+ 7e68: 08 2f mov r16, r24
175
+ verifySpace();
176
+ 7e6a: af d0 rcall .+350 ; 0x7fca <verifySpace>
177
+ if (which == 0x82) {
178
+ 7e6c: 02 38 cpi r16, 0x82 ; 130
179
+ 7e6e: 11 f0 breq .+4 ; 0x7e74 <main+0x74>
180
+ /*
181
+ * Send optiboot version as "minor SW version"
182
+ */
183
+ putch(OPTIBOOT_MINVER);
184
+ } else if (which == 0x81) {
185
+ 7e70: 01 38 cpi r16, 0x81 ; 129
186
+ 7e72: 11 f4 brne .+4 ; 0x7e78 <main+0x78>
187
+ putch(OPTIBOOT_MAJVER);
188
+ 7e74: 84 e0 ldi r24, 0x04 ; 4
189
+ 7e76: 01 c0 rjmp .+2 ; 0x7e7a <main+0x7a>
190
+ } else {
191
+ /*
192
+ * GET PARAMETER returns a generic 0x03 reply for
193
+ * other parameters - enough to keep Avrdude happy
194
+ */
195
+ putch(0x03);
196
+ 7e78: 83 e0 ldi r24, 0x03 ; 3
197
+ 7e7a: 8d d0 rcall .+282 ; 0x7f96 <putch>
198
+ 7e7c: 89 c0 rjmp .+274 ; 0x7f90 <main+0x190>
199
+ }
200
+ }
201
+ else if(ch == STK_SET_DEVICE) {
202
+ 7e7e: 82 34 cpi r24, 0x42 ; 66
203
+ 7e80: 11 f4 brne .+4 ; 0x7e86 <main+0x86>
204
+ // SET DEVICE is ignored
205
+ getNch(20);
206
+ 7e82: 84 e1 ldi r24, 0x14 ; 20
207
+ 7e84: 03 c0 rjmp .+6 ; 0x7e8c <main+0x8c>
208
+ }
209
+ else if(ch == STK_SET_DEVICE_EXT) {
210
+ 7e86: 85 34 cpi r24, 0x45 ; 69
211
+ 7e88: 19 f4 brne .+6 ; 0x7e90 <main+0x90>
212
+ // SET DEVICE EXT is ignored
213
+ getNch(5);
214
+ 7e8a: 85 e0 ldi r24, 0x05 ; 5
215
+ 7e8c: a6 d0 rcall .+332 ; 0x7fda <getNch>
216
+ 7e8e: 80 c0 rjmp .+256 ; 0x7f90 <main+0x190>
217
+ }
218
+ else if(ch == STK_LOAD_ADDRESS) {
219
+ 7e90: 85 35 cpi r24, 0x55 ; 85
220
+ 7e92: 79 f4 brne .+30 ; 0x7eb2 <main+0xb2>
221
+ // LOAD ADDRESS
222
+ uint16_t newAddress;
223
+ newAddress = getch();
224
+ 7e94: 88 d0 rcall .+272 ; 0x7fa6 <getch>
225
+ newAddress = (newAddress & 0xff) | (getch() << 8);
226
+ 7e96: e8 2e mov r14, r24
227
+ 7e98: ff 24 eor r15, r15
228
+ 7e9a: 85 d0 rcall .+266 ; 0x7fa6 <getch>
229
+ 7e9c: 08 2f mov r16, r24
230
+ 7e9e: 10 e0 ldi r17, 0x00 ; 0
231
+ 7ea0: 10 2f mov r17, r16
232
+ 7ea2: 00 27 eor r16, r16
233
+ 7ea4: 0e 29 or r16, r14
234
+ 7ea6: 1f 29 or r17, r15
235
+ #ifdef RAMPZ
236
+ // Transfer top bit to RAMPZ
237
+ RAMPZ = (newAddress & 0x8000) ? 1 : 0;
238
+ #endif
239
+ newAddress += newAddress; // Convert from word address to byte address
240
+ 7ea8: 00 0f add r16, r16
241
+ 7eaa: 11 1f adc r17, r17
242
+ address = newAddress;
243
+ verifySpace();
244
+ 7eac: 8e d0 rcall .+284 ; 0x7fca <verifySpace>
245
+ 7eae: 68 01 movw r12, r16
246
+ 7eb0: 6f c0 rjmp .+222 ; 0x7f90 <main+0x190>
247
+ }
248
+ else if(ch == STK_UNIVERSAL) {
249
+ 7eb2: 86 35 cpi r24, 0x56 ; 86
250
+ 7eb4: 21 f4 brne .+8 ; 0x7ebe <main+0xbe>
251
+ // UNIVERSAL command is ignored
252
+ getNch(4);
253
+ 7eb6: 84 e0 ldi r24, 0x04 ; 4
254
+ 7eb8: 90 d0 rcall .+288 ; 0x7fda <getNch>
255
+ putch(0x00);
256
+ 7eba: 80 e0 ldi r24, 0x00 ; 0
257
+ 7ebc: de cf rjmp .-68 ; 0x7e7a <main+0x7a>
258
+ }
259
+ /* Write memory, length is big endian and is in bytes */
260
+ else if(ch == STK_PROG_PAGE) {
261
+ 7ebe: 84 36 cpi r24, 0x64 ; 100
262
+ 7ec0: 09 f0 breq .+2 ; 0x7ec4 <main+0xc4>
263
+ 7ec2: 40 c0 rjmp .+128 ; 0x7f44 <main+0x144>
264
+ // PROGRAM PAGE - we support flash programming only, not EEPROM
265
+ uint8_t *bufPtr;
266
+ uint16_t addrPtr;
267
+
268
+ getch(); /* getlen() */
269
+ 7ec4: 70 d0 rcall .+224 ; 0x7fa6 <getch>
270
+ length = getch();
271
+ 7ec6: 6f d0 rcall .+222 ; 0x7fa6 <getch>
272
+ 7ec8: 08 2f mov r16, r24
273
+ getch();
274
+ 7eca: 6d d0 rcall .+218 ; 0x7fa6 <getch>
275
+
276
+ // If we are in RWW section, immediately start page erase
277
+ if (address < NRWWSTART) __boot_page_erase_short((uint16_t)(void*)address);
278
+ 7ecc: 80 e0 ldi r24, 0x00 ; 0
279
+ 7ece: c8 16 cp r12, r24
280
+ 7ed0: 80 e7 ldi r24, 0x70 ; 112
281
+ 7ed2: d8 06 cpc r13, r24
282
+ 7ed4: 18 f4 brcc .+6 ; 0x7edc <main+0xdc>
283
+ 7ed6: f6 01 movw r30, r12
284
+ 7ed8: b7 be out 0x37, r11 ; 55
285
+ 7eda: e8 95 spm
286
+ 7edc: c0 e0 ldi r28, 0x00 ; 0
287
+ 7ede: d1 e0 ldi r29, 0x01 ; 1
288
+
289
+ // While that is going on, read in page contents
290
+ bufPtr = buff;
291
+ do *bufPtr++ = getch();
292
+ 7ee0: 62 d0 rcall .+196 ; 0x7fa6 <getch>
293
+ 7ee2: 89 93 st Y+, r24
294
+ while (--length);
295
+ 7ee4: 0c 17 cp r16, r28
296
+ 7ee6: e1 f7 brne .-8 ; 0x7ee0 <main+0xe0>
297
+
298
+ // If we are in NRWW section, page erase has to be delayed until now.
299
+ // Todo: Take RAMPZ into account
300
+ if (address >= NRWWSTART) __boot_page_erase_short((uint16_t)(void*)address);
301
+ 7ee8: f0 e0 ldi r31, 0x00 ; 0
302
+ 7eea: cf 16 cp r12, r31
303
+ 7eec: f0 e7 ldi r31, 0x70 ; 112
304
+ 7eee: df 06 cpc r13, r31
305
+ 7ef0: 18 f0 brcs .+6 ; 0x7ef8 <main+0xf8>
306
+ 7ef2: f6 01 movw r30, r12
307
+ 7ef4: b7 be out 0x37, r11 ; 55
308
+ 7ef6: e8 95 spm
309
+
310
+ // Read command terminator, start reply
311
+ verifySpace();
312
+ 7ef8: 68 d0 rcall .+208 ; 0x7fca <verifySpace>
313
+
314
+ // If only a partial page is to be programmed, the erase might not be complete.
315
+ // So check that here
316
+ boot_spm_busy_wait();
317
+ 7efa: 07 b6 in r0, 0x37 ; 55
318
+ 7efc: 00 fc sbrc r0, 0
319
+ 7efe: fd cf rjmp .-6 ; 0x7efa <main+0xfa>
320
+ 7f00: a6 01 movw r20, r12
321
+ 7f02: a0 e0 ldi r26, 0x00 ; 0
322
+ 7f04: b1 e0 ldi r27, 0x01 ; 1
323
+ bufPtr = buff;
324
+ addrPtr = (uint16_t)(void*)address;
325
+ ch = SPM_PAGESIZE / 2;
326
+ do {
327
+ uint16_t a;
328
+ a = *bufPtr++;
329
+ 7f06: 2c 91 ld r18, X
330
+ 7f08: 30 e0 ldi r19, 0x00 ; 0
331
+ a |= (*bufPtr++) << 8;
332
+ 7f0a: 11 96 adiw r26, 0x01 ; 1
333
+ 7f0c: 8c 91 ld r24, X
334
+ 7f0e: 11 97 sbiw r26, 0x01 ; 1
335
+ 7f10: 90 e0 ldi r25, 0x00 ; 0
336
+ 7f12: 98 2f mov r25, r24
337
+ 7f14: 88 27 eor r24, r24
338
+ 7f16: 82 2b or r24, r18
339
+ 7f18: 93 2b or r25, r19
340
+ #define rstVect (*(uint16_t*)(RAMSTART+SPM_PAGESIZE*2+4))
341
+ #define wdtVect (*(uint16_t*)(RAMSTART+SPM_PAGESIZE*2+6))
342
+ #endif
343
+
344
+ /* main program starts here */
345
+ int main(void) {
346
+ 7f1a: 12 96 adiw r26, 0x02 ; 2
347
+ ch = SPM_PAGESIZE / 2;
348
+ do {
349
+ uint16_t a;
350
+ a = *bufPtr++;
351
+ a |= (*bufPtr++) << 8;
352
+ __boot_page_fill_short((uint16_t)(void*)addrPtr,a);
353
+ 7f1c: fa 01 movw r30, r20
354
+ 7f1e: 0c 01 movw r0, r24
355
+ 7f20: 87 be out 0x37, r8 ; 55
356
+ 7f22: e8 95 spm
357
+ 7f24: 11 24 eor r1, r1
358
+ addrPtr += 2;
359
+ 7f26: 4e 5f subi r20, 0xFE ; 254
360
+ 7f28: 5f 4f sbci r21, 0xFF ; 255
361
+ } while (--ch);
362
+ 7f2a: f1 e0 ldi r31, 0x01 ; 1
363
+ 7f2c: a0 38 cpi r26, 0x80 ; 128
364
+ 7f2e: bf 07 cpc r27, r31
365
+ 7f30: 51 f7 brne .-44 ; 0x7f06 <main+0x106>
366
+
367
+ // Write from programming buffer
368
+ __boot_page_write_short((uint16_t)(void*)address);
369
+ 7f32: f6 01 movw r30, r12
370
+ 7f34: a7 be out 0x37, r10 ; 55
371
+ 7f36: e8 95 spm
372
+ boot_spm_busy_wait();
373
+ 7f38: 07 b6 in r0, 0x37 ; 55
374
+ 7f3a: 00 fc sbrc r0, 0
375
+ 7f3c: fd cf rjmp .-6 ; 0x7f38 <main+0x138>
376
+
377
+ #if defined(RWWSRE)
378
+ // Reenable read access to flash
379
+ boot_rww_enable();
380
+ 7f3e: 97 be out 0x37, r9 ; 55
381
+ 7f40: e8 95 spm
382
+ 7f42: 26 c0 rjmp .+76 ; 0x7f90 <main+0x190>
383
+ #endif
384
+
385
+ }
386
+ /* Read memory block mode, length is big endian. */
387
+ else if(ch == STK_READ_PAGE) {
388
+ 7f44: 84 37 cpi r24, 0x74 ; 116
389
+ 7f46: b1 f4 brne .+44 ; 0x7f74 <main+0x174>
390
+ // READ PAGE - we only read flash
391
+ getch(); /* getlen() */
392
+ 7f48: 2e d0 rcall .+92 ; 0x7fa6 <getch>
393
+ length = getch();
394
+ 7f4a: 2d d0 rcall .+90 ; 0x7fa6 <getch>
395
+ 7f4c: f8 2e mov r15, r24
396
+ getch();
397
+ 7f4e: 2b d0 rcall .+86 ; 0x7fa6 <getch>
398
+
399
+ verifySpace();
400
+ 7f50: 3c d0 rcall .+120 ; 0x7fca <verifySpace>
401
+ 7f52: f6 01 movw r30, r12
402
+ 7f54: ef 2c mov r14, r15
403
+ putch(result);
404
+ address++;
405
+ }
406
+ while (--length);
407
+ #else
408
+ do putch(pgm_read_byte_near(address++));
409
+ 7f56: 8f 01 movw r16, r30
410
+ 7f58: 0f 5f subi r16, 0xFF ; 255
411
+ 7f5a: 1f 4f sbci r17, 0xFF ; 255
412
+ 7f5c: 84 91 lpm r24, Z+
413
+ 7f5e: 1b d0 rcall .+54 ; 0x7f96 <putch>
414
+ while (--length);
415
+ 7f60: ea 94 dec r14
416
+ 7f62: f8 01 movw r30, r16
417
+ 7f64: c1 f7 brne .-16 ; 0x7f56 <main+0x156>
418
+ #define rstVect (*(uint16_t*)(RAMSTART+SPM_PAGESIZE*2+4))
419
+ #define wdtVect (*(uint16_t*)(RAMSTART+SPM_PAGESIZE*2+6))
420
+ #endif
421
+
422
+ /* main program starts here */
423
+ int main(void) {
424
+ 7f66: 08 94 sec
425
+ 7f68: c1 1c adc r12, r1
426
+ 7f6a: d1 1c adc r13, r1
427
+ 7f6c: fa 94 dec r15
428
+ 7f6e: cf 0c add r12, r15
429
+ 7f70: d1 1c adc r13, r1
430
+ 7f72: 0e c0 rjmp .+28 ; 0x7f90 <main+0x190>
431
+ #endif
432
+ #endif
433
+ }
434
+
435
+ /* Get device signature bytes */
436
+ else if(ch == STK_READ_SIGN) {
437
+ 7f74: 85 37 cpi r24, 0x75 ; 117
438
+ 7f76: 39 f4 brne .+14 ; 0x7f86 <main+0x186>
439
+ // READ SIGN - return what Avrdude wants to hear
440
+ verifySpace();
441
+ 7f78: 28 d0 rcall .+80 ; 0x7fca <verifySpace>
442
+ putch(SIGNATURE_0);
443
+ 7f7a: 8e e1 ldi r24, 0x1E ; 30
444
+ 7f7c: 0c d0 rcall .+24 ; 0x7f96 <putch>
445
+ putch(SIGNATURE_1);
446
+ 7f7e: 85 e9 ldi r24, 0x95 ; 149
447
+ 7f80: 0a d0 rcall .+20 ; 0x7f96 <putch>
448
+ putch(SIGNATURE_2);
449
+ 7f82: 8f e0 ldi r24, 0x0F ; 15
450
+ 7f84: 7a cf rjmp .-268 ; 0x7e7a <main+0x7a>
451
+ }
452
+ else if (ch == 'Q') {
453
+ 7f86: 81 35 cpi r24, 0x51 ; 81
454
+ 7f88: 11 f4 brne .+4 ; 0x7f8e <main+0x18e>
455
+ // Adaboot no-wait mod
456
+ watchdogConfig(WATCHDOG_16MS);
457
+ 7f8a: 88 e0 ldi r24, 0x08 ; 8
458
+ 7f8c: 18 d0 rcall .+48 ; 0x7fbe <watchdogConfig>
459
+ verifySpace();
460
+ }
461
+ else {
462
+ // This covers the response to commands like STK_ENTER_PROGMODE
463
+ verifySpace();
464
+ 7f8e: 1d d0 rcall .+58 ; 0x7fca <verifySpace>
465
+ }
466
+ putch(STK_OK);
467
+ 7f90: 80 e1 ldi r24, 0x10 ; 16
468
+ 7f92: 01 d0 rcall .+2 ; 0x7f96 <putch>
469
+ 7f94: 65 cf rjmp .-310 ; 0x7e60 <main+0x60>
470
+
471
+ 00007f96 <putch>:
472
+ }
473
+ }
474
+
475
+ void putch(char ch) {
476
+ 7f96: 98 2f mov r25, r24
477
+ #ifndef SOFT_UART
478
+ while (!(UCSR0A & _BV(UDRE0)));
479
+ 7f98: 80 91 c0 00 lds r24, 0x00C0
480
+ 7f9c: 85 ff sbrs r24, 5
481
+ 7f9e: fc cf rjmp .-8 ; 0x7f98 <putch+0x2>
482
+ UDR0 = ch;
483
+ 7fa0: 90 93 c6 00 sts 0x00C6, r25
484
+ [uartBit] "I" (UART_TX_BIT)
485
+ :
486
+ "r25"
487
+ );
488
+ #endif
489
+ }
490
+ 7fa4: 08 95 ret
491
+
492
+ 00007fa6 <getch>:
493
+ [uartBit] "I" (UART_RX_BIT)
494
+ :
495
+ "r25"
496
+ );
497
+ #else
498
+ while(!(UCSR0A & _BV(RXC0)))
499
+ 7fa6: 80 91 c0 00 lds r24, 0x00C0
500
+ 7faa: 87 ff sbrs r24, 7
501
+ 7fac: fc cf rjmp .-8 ; 0x7fa6 <getch>
502
+ ;
503
+ if (!(UCSR0A & _BV(FE0))) {
504
+ 7fae: 80 91 c0 00 lds r24, 0x00C0
505
+ 7fb2: 84 fd sbrc r24, 4
506
+ 7fb4: 01 c0 rjmp .+2 ; 0x7fb8 <getch+0x12>
507
+ }
508
+ #endif
509
+
510
+ // Watchdog functions. These are only safe with interrupts turned off.
511
+ void watchdogReset() {
512
+ __asm__ __volatile__ (
513
+ 7fb6: a8 95 wdr
514
+ * don't care that an invalid char is returned...)
515
+ */
516
+ watchdogReset();
517
+ }
518
+
519
+ ch = UDR0;
520
+ 7fb8: 80 91 c6 00 lds r24, 0x00C6
521
+ LED_PIN |= _BV(LED);
522
+ #endif
523
+ #endif
524
+
525
+ return ch;
526
+ }
527
+ 7fbc: 08 95 ret
528
+
529
+ 00007fbe <watchdogConfig>:
530
+ "wdr\n"
531
+ );
532
+ }
533
+
534
+ void watchdogConfig(uint8_t x) {
535
+ WDTCSR = _BV(WDCE) | _BV(WDE);
536
+ 7fbe: e0 e6 ldi r30, 0x60 ; 96
537
+ 7fc0: f0 e0 ldi r31, 0x00 ; 0
538
+ 7fc2: 98 e1 ldi r25, 0x18 ; 24
539
+ 7fc4: 90 83 st Z, r25
540
+ WDTCSR = x;
541
+ 7fc6: 80 83 st Z, r24
542
+ }
543
+ 7fc8: 08 95 ret
544
+
545
+ 00007fca <verifySpace>:
546
+ do getch(); while (--count);
547
+ verifySpace();
548
+ }
549
+
550
+ void verifySpace() {
551
+ if (getch() != CRC_EOP) {
552
+ 7fca: ed df rcall .-38 ; 0x7fa6 <getch>
553
+ 7fcc: 80 32 cpi r24, 0x20 ; 32
554
+ 7fce: 19 f0 breq .+6 ; 0x7fd6 <verifySpace+0xc>
555
+ watchdogConfig(WATCHDOG_16MS); // shorten WD timeout
556
+ 7fd0: 88 e0 ldi r24, 0x08 ; 8
557
+ 7fd2: f5 df rcall .-22 ; 0x7fbe <watchdogConfig>
558
+ 7fd4: ff cf rjmp .-2 ; 0x7fd4 <verifySpace+0xa>
559
+ while (1) // and busy-loop so that WD causes
560
+ ; // a reset and app start.
561
+ }
562
+ putch(STK_INSYNC);
563
+ 7fd6: 84 e1 ldi r24, 0x14 ; 20
564
+ }
565
+ 7fd8: de cf rjmp .-68 ; 0x7f96 <putch>
566
+
567
+ 00007fda <getNch>:
568
+ ::[count] "M" (UART_B_VALUE)
569
+ );
570
+ }
571
+ #endif
572
+
573
+ void getNch(uint8_t count) {
574
+ 7fda: 1f 93 push r17
575
+ 7fdc: 18 2f mov r17, r24
576
+ do getch(); while (--count);
577
+ 7fde: e3 df rcall .-58 ; 0x7fa6 <getch>
578
+ 7fe0: 11 50 subi r17, 0x01 ; 1
579
+ 7fe2: e9 f7 brne .-6 ; 0x7fde <getNch+0x4>
580
+ verifySpace();
581
+ 7fe4: f2 df rcall .-28 ; 0x7fca <verifySpace>
582
+ }
583
+ 7fe6: 1f 91 pop r17
584
+ 7fe8: 08 95 ret
585
+
586
+ 00007fea <appStart>:
587
+ WDTCSR = _BV(WDCE) | _BV(WDE);
588
+ WDTCSR = x;
589
+ }
590
+
591
+ void appStart() {
592
+ watchdogConfig(WATCHDOG_OFF);
593
+ 7fea: 80 e0 ldi r24, 0x00 ; 0
594
+ 7fec: e8 df rcall .-48 ; 0x7fbe <watchdogConfig>
595
+ __asm__ __volatile__ (
596
+ 7fee: ee 27 eor r30, r30
597
+ 7ff0: ff 27 eor r31, r31
598
+ 7ff2: 09 94 ijmp
hardware/arduino/avr/bootloaders/optiboot/optiboot_atmega8.hex ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ :101E000011248FE594E09EBF8DBF84B714BE81FF7F
2
+ :101E1000E2D085E08EBD82E08BB988E18AB986E8A0
3
+ :101E200080BD80E189B98EE0C2D0BD9A96E020E302
4
+ :101E30003CEF54E040E23DBD2CBD58BF08B602FE69
5
+ :101E4000FDCF88B3842788BBA8959150A1F7CC24F7
6
+ :101E5000DD2488248394B5E0AB2EA1E19A2EF3E033
7
+ :101E6000BF2E9ED0813461F49BD0082FA4D00238BD
8
+ :101E700011F0013811F484E001C083E08DD089C0F5
9
+ :101E8000823411F484E103C0853419F485E09BD0D9
10
+ :101E900080C0853579F484D0E82EFF2481D0082FC6
11
+ :101EA00010E0102F00270E291F29000F111F83D0CB
12
+ :101EB00068016FC0863521F484E085D080E0DECFF4
13
+ :101EC000843609F040C06CD06BD0082F69D080E018
14
+ :101ED000C81688E1D80618F4F601B7BEE895C0E048
15
+ :101EE000D1E05ED089930C17E1F7F0E0CF16F8E16E
16
+ :101EF000DF0618F0F601B7BEE8955DD007B600FC26
17
+ :101F0000FDCFA601A0E0B1E02C9130E011968C91BC
18
+ :101F1000119790E0982F8827822B932B1296FA0125
19
+ :101F20000C0187BEE89511244E5F5F4FF1E0A034AD
20
+ :101F3000BF0751F7F601A7BEE89507B600FCFDCF35
21
+ :101F400097BEE89526C08437B1F42AD029D0F82E60
22
+ :101F500027D031D0F601EF2C8F010F5F1F4F8491F6
23
+ :101F60001BD0EA94F801C1F70894C11CD11CFA9463
24
+ :101F7000CF0CD11C0EC0853739F41DD08EE10CD0AA
25
+ :101F800083E90AD087E07ACF813511F488E00FD059
26
+ :101F900012D080E101D065CF5D9BFECF8CB9089552
27
+ :101FA0005F9BFECF5C9901C0A8958CB1089598E124
28
+ :101FB00091BD81BD0895F4DF803219F088E0F7DF2C
29
+ :101FC000FFCF84E1E9CF1F93182FEADF1150E9F723
30
+ :101FD000F2DF1F91089580E0EADFEE27FF270994E2
31
+ :021FFE000404D9
32
+ :0400000300001E00DB
33
+ :00000001FF
hardware/arduino/avr/bootloaders/optiboot/optiboot_atmega8.lst ADDED
@@ -0,0 +1,604 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ optiboot_atmega8.elf: file format elf32-avr
3
+
4
+ Sections:
5
+ Idx Name Size VMA LMA File off Algn
6
+ 0 .text 000001e0 00001e00 00001e00 00000054 2**1
7
+ CONTENTS, ALLOC, LOAD, READONLY, CODE
8
+ 1 .version 00000002 00001ffe 00001ffe 00000234 2**0
9
+ CONTENTS, READONLY
10
+ 2 .debug_aranges 00000028 00000000 00000000 00000236 2**0
11
+ CONTENTS, READONLY, DEBUGGING
12
+ 3 .debug_pubnames 0000005f 00000000 00000000 0000025e 2**0
13
+ CONTENTS, READONLY, DEBUGGING
14
+ 4 .debug_info 000002a6 00000000 00000000 000002bd 2**0
15
+ CONTENTS, READONLY, DEBUGGING
16
+ 5 .debug_abbrev 00000169 00000000 00000000 00000563 2**0
17
+ CONTENTS, READONLY, DEBUGGING
18
+ 6 .debug_line 00000498 00000000 00000000 000006cc 2**0
19
+ CONTENTS, READONLY, DEBUGGING
20
+ 7 .debug_frame 00000080 00000000 00000000 00000b64 2**2
21
+ CONTENTS, READONLY, DEBUGGING
22
+ 8 .debug_str 0000014f 00000000 00000000 00000be4 2**0
23
+ CONTENTS, READONLY, DEBUGGING
24
+ 9 .debug_loc 000002ba 00000000 00000000 00000d33 2**0
25
+ CONTENTS, READONLY, DEBUGGING
26
+ 10 .debug_ranges 00000078 00000000 00000000 00000fed 2**0
27
+ CONTENTS, READONLY, DEBUGGING
28
+
29
+ Disassembly of section .text:
30
+
31
+ 00001e00 <main>:
32
+ #define rstVect (*(uint16_t*)(RAMSTART+SPM_PAGESIZE*2+4))
33
+ #define wdtVect (*(uint16_t*)(RAMSTART+SPM_PAGESIZE*2+6))
34
+ #endif
35
+
36
+ /* main program starts here */
37
+ int main(void) {
38
+ 1e00: 11 24 eor r1, r1
39
+ //
40
+ // If not, uncomment the following instructions:
41
+ // cli();
42
+ asm volatile ("clr __zero_reg__");
43
+ #ifdef __AVR_ATmega8__
44
+ SP=RAMEND; // This is done by hardware reset
45
+ 1e02: 8f e5 ldi r24, 0x5F ; 95
46
+ 1e04: 94 e0 ldi r25, 0x04 ; 4
47
+ 1e06: 9e bf out 0x3e, r25 ; 62
48
+ 1e08: 8d bf out 0x3d, r24 ; 61
49
+ #endif
50
+
51
+ // Adaboot no-wait mod
52
+ ch = MCUSR;
53
+ 1e0a: 84 b7 in r24, 0x34 ; 52
54
+ MCUSR = 0;
55
+ 1e0c: 14 be out 0x34, r1 ; 52
56
+ if (!(ch & _BV(EXTRF))) appStart();
57
+ 1e0e: 81 ff sbrs r24, 1
58
+ 1e10: e2 d0 rcall .+452 ; 0x1fd6 <appStart>
59
+
60
+ #if LED_START_FLASHES > 0
61
+ // Set up Timer 1 for timeout counter
62
+ TCCR1B = _BV(CS12) | _BV(CS10); // div 1024
63
+ 1e12: 85 e0 ldi r24, 0x05 ; 5
64
+ 1e14: 8e bd out 0x2e, r24 ; 46
65
+ #endif
66
+ #ifndef SOFT_UART
67
+ #ifdef __AVR_ATmega8__
68
+ UCSRA = _BV(U2X); //Double speed mode USART
69
+ 1e16: 82 e0 ldi r24, 0x02 ; 2
70
+ 1e18: 8b b9 out 0x0b, r24 ; 11
71
+ UCSRB = _BV(RXEN) | _BV(TXEN); // enable Rx & Tx
72
+ 1e1a: 88 e1 ldi r24, 0x18 ; 24
73
+ 1e1c: 8a b9 out 0x0a, r24 ; 10
74
+ UCSRC = _BV(URSEL) | _BV(UCSZ1) | _BV(UCSZ0); // config USART; 8N1
75
+ 1e1e: 86 e8 ldi r24, 0x86 ; 134
76
+ 1e20: 80 bd out 0x20, r24 ; 32
77
+ UBRRL = (uint8_t)( (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 );
78
+ 1e22: 80 e1 ldi r24, 0x10 ; 16
79
+ 1e24: 89 b9 out 0x09, r24 ; 9
80
+ UBRR0L = (uint8_t)( (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 );
81
+ #endif
82
+ #endif
83
+
84
+ // Set up watchdog to trigger after 500ms
85
+ watchdogConfig(WATCHDOG_1S);
86
+ 1e26: 8e e0 ldi r24, 0x0E ; 14
87
+ 1e28: c2 d0 rcall .+388 ; 0x1fae <watchdogConfig>
88
+
89
+ /* Set LED pin as output */
90
+ LED_DDR |= _BV(LED);
91
+ 1e2a: bd 9a sbi 0x17, 5 ; 23
92
+ 1e2c: 96 e0 ldi r25, 0x06 ; 6
93
+ }
94
+
95
+ #if LED_START_FLASHES > 0
96
+ void flash_led(uint8_t count) {
97
+ do {
98
+ TCNT1 = -(F_CPU/(1024*16));
99
+ 1e2e: 20 e3 ldi r18, 0x30 ; 48
100
+ 1e30: 3c ef ldi r19, 0xFC ; 252
101
+ TIFR1 = _BV(TOV1);
102
+ 1e32: 54 e0 ldi r21, 0x04 ; 4
103
+ while(!(TIFR1 & _BV(TOV1)));
104
+ #ifdef __AVR_ATmega8__
105
+ LED_PORT ^= _BV(LED);
106
+ 1e34: 40 e2 ldi r20, 0x20 ; 32
107
+ }
108
+
109
+ #if LED_START_FLASHES > 0
110
+ void flash_led(uint8_t count) {
111
+ do {
112
+ TCNT1 = -(F_CPU/(1024*16));
113
+ 1e36: 3d bd out 0x2d, r19 ; 45
114
+ 1e38: 2c bd out 0x2c, r18 ; 44
115
+ TIFR1 = _BV(TOV1);
116
+ 1e3a: 58 bf out 0x38, r21 ; 56
117
+ while(!(TIFR1 & _BV(TOV1)));
118
+ 1e3c: 08 b6 in r0, 0x38 ; 56
119
+ 1e3e: 02 fe sbrs r0, 2
120
+ 1e40: fd cf rjmp .-6 ; 0x1e3c <main+0x3c>
121
+ #ifdef __AVR_ATmega8__
122
+ LED_PORT ^= _BV(LED);
123
+ 1e42: 88 b3 in r24, 0x18 ; 24
124
+ 1e44: 84 27 eor r24, r20
125
+ 1e46: 88 bb out 0x18, r24 ; 24
126
+ }
127
+ #endif
128
+
129
+ // Watchdog functions. These are only safe with interrupts turned off.
130
+ void watchdogReset() {
131
+ __asm__ __volatile__ (
132
+ 1e48: a8 95 wdr
133
+ LED_PORT ^= _BV(LED);
134
+ #else
135
+ LED_PIN |= _BV(LED);
136
+ #endif
137
+ watchdogReset();
138
+ } while (--count);
139
+ 1e4a: 91 50 subi r25, 0x01 ; 1
140
+ 1e4c: a1 f7 brne .-24 ; 0x1e36 <main+0x36>
141
+ 1e4e: cc 24 eor r12, r12
142
+ 1e50: dd 24 eor r13, r13
143
+ ch = SPM_PAGESIZE / 2;
144
+ do {
145
+ uint16_t a;
146
+ a = *bufPtr++;
147
+ a |= (*bufPtr++) << 8;
148
+ __boot_page_fill_short((uint16_t)(void*)addrPtr,a);
149
+ 1e52: 88 24 eor r8, r8
150
+ 1e54: 83 94 inc r8
151
+ addrPtr += 2;
152
+ } while (--ch);
153
+
154
+ // Write from programming buffer
155
+ __boot_page_write_short((uint16_t)(void*)address);
156
+ 1e56: b5 e0 ldi r27, 0x05 ; 5
157
+ 1e58: ab 2e mov r10, r27
158
+ boot_spm_busy_wait();
159
+
160
+ #if defined(RWWSRE)
161
+ // Reenable read access to flash
162
+ boot_rww_enable();
163
+ 1e5a: a1 e1 ldi r26, 0x11 ; 17
164
+ 1e5c: 9a 2e mov r9, r26
165
+ do *bufPtr++ = getch();
166
+ while (--length);
167
+
168
+ // If we are in NRWW section, page erase has to be delayed until now.
169
+ // Todo: Take RAMPZ into account
170
+ if (address >= NRWWSTART) __boot_page_erase_short((uint16_t)(void*)address);
171
+ 1e5e: f3 e0 ldi r31, 0x03 ; 3
172
+ 1e60: bf 2e mov r11, r31
173
+ #endif
174
+
175
+ /* Forever loop */
176
+ for (;;) {
177
+ /* get character from UART */
178
+ ch = getch();
179
+ 1e62: 9e d0 rcall .+316 ; 0x1fa0 <getch>
180
+
181
+ if(ch == STK_GET_PARAMETER) {
182
+ 1e64: 81 34 cpi r24, 0x41 ; 65
183
+ 1e66: 61 f4 brne .+24 ; 0x1e80 <main+0x80>
184
+ unsigned char which = getch();
185
+ 1e68: 9b d0 rcall .+310 ; 0x1fa0 <getch>
186
+ 1e6a: 08 2f mov r16, r24
187
+ verifySpace();
188
+ 1e6c: a4 d0 rcall .+328 ; 0x1fb6 <verifySpace>
189
+ if (which == 0x82) {
190
+ 1e6e: 02 38 cpi r16, 0x82 ; 130
191
+ 1e70: 11 f0 breq .+4 ; 0x1e76 <main+0x76>
192
+ /*
193
+ * Send optiboot version as "minor SW version"
194
+ */
195
+ putch(OPTIBOOT_MINVER);
196
+ } else if (which == 0x81) {
197
+ 1e72: 01 38 cpi r16, 0x81 ; 129
198
+ 1e74: 11 f4 brne .+4 ; 0x1e7a <main+0x7a>
199
+ putch(OPTIBOOT_MAJVER);
200
+ 1e76: 84 e0 ldi r24, 0x04 ; 4
201
+ 1e78: 01 c0 rjmp .+2 ; 0x1e7c <main+0x7c>
202
+ } else {
203
+ /*
204
+ * GET PARAMETER returns a generic 0x03 reply for
205
+ * other parameters - enough to keep Avrdude happy
206
+ */
207
+ putch(0x03);
208
+ 1e7a: 83 e0 ldi r24, 0x03 ; 3
209
+ 1e7c: 8d d0 rcall .+282 ; 0x1f98 <putch>
210
+ 1e7e: 89 c0 rjmp .+274 ; 0x1f92 <main+0x192>
211
+ }
212
+ }
213
+ else if(ch == STK_SET_DEVICE) {
214
+ 1e80: 82 34 cpi r24, 0x42 ; 66
215
+ 1e82: 11 f4 brne .+4 ; 0x1e88 <main+0x88>
216
+ // SET DEVICE is ignored
217
+ getNch(20);
218
+ 1e84: 84 e1 ldi r24, 0x14 ; 20
219
+ 1e86: 03 c0 rjmp .+6 ; 0x1e8e <main+0x8e>
220
+ }
221
+ else if(ch == STK_SET_DEVICE_EXT) {
222
+ 1e88: 85 34 cpi r24, 0x45 ; 69
223
+ 1e8a: 19 f4 brne .+6 ; 0x1e92 <main+0x92>
224
+ // SET DEVICE EXT is ignored
225
+ getNch(5);
226
+ 1e8c: 85 e0 ldi r24, 0x05 ; 5
227
+ 1e8e: 9b d0 rcall .+310 ; 0x1fc6 <getNch>
228
+ 1e90: 80 c0 rjmp .+256 ; 0x1f92 <main+0x192>
229
+ }
230
+ else if(ch == STK_LOAD_ADDRESS) {
231
+ 1e92: 85 35 cpi r24, 0x55 ; 85
232
+ 1e94: 79 f4 brne .+30 ; 0x1eb4 <main+0xb4>
233
+ // LOAD ADDRESS
234
+ uint16_t newAddress;
235
+ newAddress = getch();
236
+ 1e96: 84 d0 rcall .+264 ; 0x1fa0 <getch>
237
+ newAddress = (newAddress & 0xff) | (getch() << 8);
238
+ 1e98: e8 2e mov r14, r24
239
+ 1e9a: ff 24 eor r15, r15
240
+ 1e9c: 81 d0 rcall .+258 ; 0x1fa0 <getch>
241
+ 1e9e: 08 2f mov r16, r24
242
+ 1ea0: 10 e0 ldi r17, 0x00 ; 0
243
+ 1ea2: 10 2f mov r17, r16
244
+ 1ea4: 00 27 eor r16, r16
245
+ 1ea6: 0e 29 or r16, r14
246
+ 1ea8: 1f 29 or r17, r15
247
+ #ifdef RAMPZ
248
+ // Transfer top bit to RAMPZ
249
+ RAMPZ = (newAddress & 0x8000) ? 1 : 0;
250
+ #endif
251
+ newAddress += newAddress; // Convert from word address to byte address
252
+ 1eaa: 00 0f add r16, r16
253
+ 1eac: 11 1f adc r17, r17
254
+ address = newAddress;
255
+ verifySpace();
256
+ 1eae: 83 d0 rcall .+262 ; 0x1fb6 <verifySpace>
257
+ 1eb0: 68 01 movw r12, r16
258
+ 1eb2: 6f c0 rjmp .+222 ; 0x1f92 <main+0x192>
259
+ }
260
+ else if(ch == STK_UNIVERSAL) {
261
+ 1eb4: 86 35 cpi r24, 0x56 ; 86
262
+ 1eb6: 21 f4 brne .+8 ; 0x1ec0 <main+0xc0>
263
+ // UNIVERSAL command is ignored
264
+ getNch(4);
265
+ 1eb8: 84 e0 ldi r24, 0x04 ; 4
266
+ 1eba: 85 d0 rcall .+266 ; 0x1fc6 <getNch>
267
+ putch(0x00);
268
+ 1ebc: 80 e0 ldi r24, 0x00 ; 0
269
+ 1ebe: de cf rjmp .-68 ; 0x1e7c <main+0x7c>
270
+ }
271
+ /* Write memory, length is big endian and is in bytes */
272
+ else if(ch == STK_PROG_PAGE) {
273
+ 1ec0: 84 36 cpi r24, 0x64 ; 100
274
+ 1ec2: 09 f0 breq .+2 ; 0x1ec6 <main+0xc6>
275
+ 1ec4: 40 c0 rjmp .+128 ; 0x1f46 <main+0x146>
276
+ // PROGRAM PAGE - we support flash programming only, not EEPROM
277
+ uint8_t *bufPtr;
278
+ uint16_t addrPtr;
279
+
280
+ getch(); /* getlen() */
281
+ 1ec6: 6c d0 rcall .+216 ; 0x1fa0 <getch>
282
+ length = getch();
283
+ 1ec8: 6b d0 rcall .+214 ; 0x1fa0 <getch>
284
+ 1eca: 08 2f mov r16, r24
285
+ getch();
286
+ 1ecc: 69 d0 rcall .+210 ; 0x1fa0 <getch>
287
+
288
+ // If we are in RWW section, immediately start page erase
289
+ if (address < NRWWSTART) __boot_page_erase_short((uint16_t)(void*)address);
290
+ 1ece: 80 e0 ldi r24, 0x00 ; 0
291
+ 1ed0: c8 16 cp r12, r24
292
+ 1ed2: 88 e1 ldi r24, 0x18 ; 24
293
+ 1ed4: d8 06 cpc r13, r24
294
+ 1ed6: 18 f4 brcc .+6 ; 0x1ede <main+0xde>
295
+ 1ed8: f6 01 movw r30, r12
296
+ 1eda: b7 be out 0x37, r11 ; 55
297
+ 1edc: e8 95 spm
298
+ 1ede: c0 e0 ldi r28, 0x00 ; 0
299
+ 1ee0: d1 e0 ldi r29, 0x01 ; 1
300
+
301
+ // While that is going on, read in page contents
302
+ bufPtr = buff;
303
+ do *bufPtr++ = getch();
304
+ 1ee2: 5e d0 rcall .+188 ; 0x1fa0 <getch>
305
+ 1ee4: 89 93 st Y+, r24
306
+ while (--length);
307
+ 1ee6: 0c 17 cp r16, r28
308
+ 1ee8: e1 f7 brne .-8 ; 0x1ee2 <main+0xe2>
309
+
310
+ // If we are in NRWW section, page erase has to be delayed until now.
311
+ // Todo: Take RAMPZ into account
312
+ if (address >= NRWWSTART) __boot_page_erase_short((uint16_t)(void*)address);
313
+ 1eea: f0 e0 ldi r31, 0x00 ; 0
314
+ 1eec: cf 16 cp r12, r31
315
+ 1eee: f8 e1 ldi r31, 0x18 ; 24
316
+ 1ef0: df 06 cpc r13, r31
317
+ 1ef2: 18 f0 brcs .+6 ; 0x1efa <main+0xfa>
318
+ 1ef4: f6 01 movw r30, r12
319
+ 1ef6: b7 be out 0x37, r11 ; 55
320
+ 1ef8: e8 95 spm
321
+
322
+ // Read command terminator, start reply
323
+ verifySpace();
324
+ 1efa: 5d d0 rcall .+186 ; 0x1fb6 <verifySpace>
325
+
326
+ // If only a partial page is to be programmed, the erase might not be complete.
327
+ // So check that here
328
+ boot_spm_busy_wait();
329
+ 1efc: 07 b6 in r0, 0x37 ; 55
330
+ 1efe: 00 fc sbrc r0, 0
331
+ 1f00: fd cf rjmp .-6 ; 0x1efc <main+0xfc>
332
+ 1f02: a6 01 movw r20, r12
333
+ 1f04: a0 e0 ldi r26, 0x00 ; 0
334
+ 1f06: b1 e0 ldi r27, 0x01 ; 1
335
+ bufPtr = buff;
336
+ addrPtr = (uint16_t)(void*)address;
337
+ ch = SPM_PAGESIZE / 2;
338
+ do {
339
+ uint16_t a;
340
+ a = *bufPtr++;
341
+ 1f08: 2c 91 ld r18, X
342
+ 1f0a: 30 e0 ldi r19, 0x00 ; 0
343
+ a |= (*bufPtr++) << 8;
344
+ 1f0c: 11 96 adiw r26, 0x01 ; 1
345
+ 1f0e: 8c 91 ld r24, X
346
+ 1f10: 11 97 sbiw r26, 0x01 ; 1
347
+ 1f12: 90 e0 ldi r25, 0x00 ; 0
348
+ 1f14: 98 2f mov r25, r24
349
+ 1f16: 88 27 eor r24, r24
350
+ 1f18: 82 2b or r24, r18
351
+ 1f1a: 93 2b or r25, r19
352
+ #define rstVect (*(uint16_t*)(RAMSTART+SPM_PAGESIZE*2+4))
353
+ #define wdtVect (*(uint16_t*)(RAMSTART+SPM_PAGESIZE*2+6))
354
+ #endif
355
+
356
+ /* main program starts here */
357
+ int main(void) {
358
+ 1f1c: 12 96 adiw r26, 0x02 ; 2
359
+ ch = SPM_PAGESIZE / 2;
360
+ do {
361
+ uint16_t a;
362
+ a = *bufPtr++;
363
+ a |= (*bufPtr++) << 8;
364
+ __boot_page_fill_short((uint16_t)(void*)addrPtr,a);
365
+ 1f1e: fa 01 movw r30, r20
366
+ 1f20: 0c 01 movw r0, r24
367
+ 1f22: 87 be out 0x37, r8 ; 55
368
+ 1f24: e8 95 spm
369
+ 1f26: 11 24 eor r1, r1
370
+ addrPtr += 2;
371
+ 1f28: 4e 5f subi r20, 0xFE ; 254
372
+ 1f2a: 5f 4f sbci r21, 0xFF ; 255
373
+ } while (--ch);
374
+ 1f2c: f1 e0 ldi r31, 0x01 ; 1
375
+ 1f2e: a0 34 cpi r26, 0x40 ; 64
376
+ 1f30: bf 07 cpc r27, r31
377
+ 1f32: 51 f7 brne .-44 ; 0x1f08 <main+0x108>
378
+
379
+ // Write from programming buffer
380
+ __boot_page_write_short((uint16_t)(void*)address);
381
+ 1f34: f6 01 movw r30, r12
382
+ 1f36: a7 be out 0x37, r10 ; 55
383
+ 1f38: e8 95 spm
384
+ boot_spm_busy_wait();
385
+ 1f3a: 07 b6 in r0, 0x37 ; 55
386
+ 1f3c: 00 fc sbrc r0, 0
387
+ 1f3e: fd cf rjmp .-6 ; 0x1f3a <main+0x13a>
388
+
389
+ #if defined(RWWSRE)
390
+ // Reenable read access to flash
391
+ boot_rww_enable();
392
+ 1f40: 97 be out 0x37, r9 ; 55
393
+ 1f42: e8 95 spm
394
+ 1f44: 26 c0 rjmp .+76 ; 0x1f92 <main+0x192>
395
+ #endif
396
+
397
+ }
398
+ /* Read memory block mode, length is big endian. */
399
+ else if(ch == STK_READ_PAGE) {
400
+ 1f46: 84 37 cpi r24, 0x74 ; 116
401
+ 1f48: b1 f4 brne .+44 ; 0x1f76 <main+0x176>
402
+ // READ PAGE - we only read flash
403
+ getch(); /* getlen() */
404
+ 1f4a: 2a d0 rcall .+84 ; 0x1fa0 <getch>
405
+ length = getch();
406
+ 1f4c: 29 d0 rcall .+82 ; 0x1fa0 <getch>
407
+ 1f4e: f8 2e mov r15, r24
408
+ getch();
409
+ 1f50: 27 d0 rcall .+78 ; 0x1fa0 <getch>
410
+
411
+ verifySpace();
412
+ 1f52: 31 d0 rcall .+98 ; 0x1fb6 <verifySpace>
413
+ 1f54: f6 01 movw r30, r12
414
+ 1f56: ef 2c mov r14, r15
415
+ putch(result);
416
+ address++;
417
+ }
418
+ while (--length);
419
+ #else
420
+ do putch(pgm_read_byte_near(address++));
421
+ 1f58: 8f 01 movw r16, r30
422
+ 1f5a: 0f 5f subi r16, 0xFF ; 255
423
+ 1f5c: 1f 4f sbci r17, 0xFF ; 255
424
+ 1f5e: 84 91 lpm r24, Z+
425
+ 1f60: 1b d0 rcall .+54 ; 0x1f98 <putch>
426
+ while (--length);
427
+ 1f62: ea 94 dec r14
428
+ 1f64: f8 01 movw r30, r16
429
+ 1f66: c1 f7 brne .-16 ; 0x1f58 <main+0x158>
430
+ #define rstVect (*(uint16_t*)(RAMSTART+SPM_PAGESIZE*2+4))
431
+ #define wdtVect (*(uint16_t*)(RAMSTART+SPM_PAGESIZE*2+6))
432
+ #endif
433
+
434
+ /* main program starts here */
435
+ int main(void) {
436
+ 1f68: 08 94 sec
437
+ 1f6a: c1 1c adc r12, r1
438
+ 1f6c: d1 1c adc r13, r1
439
+ 1f6e: fa 94 dec r15
440
+ 1f70: cf 0c add r12, r15
441
+ 1f72: d1 1c adc r13, r1
442
+ 1f74: 0e c0 rjmp .+28 ; 0x1f92 <main+0x192>
443
+ #endif
444
+ #endif
445
+ }
446
+
447
+ /* Get device signature bytes */
448
+ else if(ch == STK_READ_SIGN) {
449
+ 1f76: 85 37 cpi r24, 0x75 ; 117
450
+ 1f78: 39 f4 brne .+14 ; 0x1f88 <main+0x188>
451
+ // READ SIGN - return what Avrdude wants to hear
452
+ verifySpace();
453
+ 1f7a: 1d d0 rcall .+58 ; 0x1fb6 <verifySpace>
454
+ putch(SIGNATURE_0);
455
+ 1f7c: 8e e1 ldi r24, 0x1E ; 30
456
+ 1f7e: 0c d0 rcall .+24 ; 0x1f98 <putch>
457
+ putch(SIGNATURE_1);
458
+ 1f80: 83 e9 ldi r24, 0x93 ; 147
459
+ 1f82: 0a d0 rcall .+20 ; 0x1f98 <putch>
460
+ putch(SIGNATURE_2);
461
+ 1f84: 87 e0 ldi r24, 0x07 ; 7
462
+ 1f86: 7a cf rjmp .-268 ; 0x1e7c <main+0x7c>
463
+ }
464
+ else if (ch == 'Q') {
465
+ 1f88: 81 35 cpi r24, 0x51 ; 81
466
+ 1f8a: 11 f4 brne .+4 ; 0x1f90 <main+0x190>
467
+ // Adaboot no-wait mod
468
+ watchdogConfig(WATCHDOG_16MS);
469
+ 1f8c: 88 e0 ldi r24, 0x08 ; 8
470
+ 1f8e: 0f d0 rcall .+30 ; 0x1fae <watchdogConfig>
471
+ verifySpace();
472
+ }
473
+ else {
474
+ // This covers the response to commands like STK_ENTER_PROGMODE
475
+ verifySpace();
476
+ 1f90: 12 d0 rcall .+36 ; 0x1fb6 <verifySpace>
477
+ }
478
+ putch(STK_OK);
479
+ 1f92: 80 e1 ldi r24, 0x10 ; 16
480
+ 1f94: 01 d0 rcall .+2 ; 0x1f98 <putch>
481
+ 1f96: 65 cf rjmp .-310 ; 0x1e62 <main+0x62>
482
+
483
+ 00001f98 <putch>:
484
+ }
485
+ }
486
+
487
+ void putch(char ch) {
488
+ #ifndef SOFT_UART
489
+ while (!(UCSR0A & _BV(UDRE0)));
490
+ 1f98: 5d 9b sbis 0x0b, 5 ; 11
491
+ 1f9a: fe cf rjmp .-4 ; 0x1f98 <putch>
492
+ UDR0 = ch;
493
+ 1f9c: 8c b9 out 0x0c, r24 ; 12
494
+ [uartBit] "I" (UART_TX_BIT)
495
+ :
496
+ "r25"
497
+ );
498
+ #endif
499
+ }
500
+ 1f9e: 08 95 ret
501
+
502
+ 00001fa0 <getch>:
503
+ [uartBit] "I" (UART_RX_BIT)
504
+ :
505
+ "r25"
506
+ );
507
+ #else
508
+ while(!(UCSR0A & _BV(RXC0)))
509
+ 1fa0: 5f 9b sbis 0x0b, 7 ; 11
510
+ 1fa2: fe cf rjmp .-4 ; 0x1fa0 <getch>
511
+ ;
512
+ if (!(UCSR0A & _BV(FE0))) {
513
+ 1fa4: 5c 99 sbic 0x0b, 4 ; 11
514
+ 1fa6: 01 c0 rjmp .+2 ; 0x1faa <getch+0xa>
515
+ }
516
+ #endif
517
+
518
+ // Watchdog functions. These are only safe with interrupts turned off.
519
+ void watchdogReset() {
520
+ __asm__ __volatile__ (
521
+ 1fa8: a8 95 wdr
522
+ * don't care that an invalid char is returned...)
523
+ */
524
+ watchdogReset();
525
+ }
526
+
527
+ ch = UDR0;
528
+ 1faa: 8c b1 in r24, 0x0c ; 12
529
+ LED_PIN |= _BV(LED);
530
+ #endif
531
+ #endif
532
+
533
+ return ch;
534
+ }
535
+ 1fac: 08 95 ret
536
+
537
+ 00001fae <watchdogConfig>:
538
+ "wdr\n"
539
+ );
540
+ }
541
+
542
+ void watchdogConfig(uint8_t x) {
543
+ WDTCSR = _BV(WDCE) | _BV(WDE);
544
+ 1fae: 98 e1 ldi r25, 0x18 ; 24
545
+ 1fb0: 91 bd out 0x21, r25 ; 33
546
+ WDTCSR = x;
547
+ 1fb2: 81 bd out 0x21, r24 ; 33
548
+ }
549
+ 1fb4: 08 95 ret
550
+
551
+ 00001fb6 <verifySpace>:
552
+ do getch(); while (--count);
553
+ verifySpace();
554
+ }
555
+
556
+ void verifySpace() {
557
+ if (getch() != CRC_EOP) {
558
+ 1fb6: f4 df rcall .-24 ; 0x1fa0 <getch>
559
+ 1fb8: 80 32 cpi r24, 0x20 ; 32
560
+ 1fba: 19 f0 breq .+6 ; 0x1fc2 <verifySpace+0xc>
561
+ watchdogConfig(WATCHDOG_16MS); // shorten WD timeout
562
+ 1fbc: 88 e0 ldi r24, 0x08 ; 8
563
+ 1fbe: f7 df rcall .-18 ; 0x1fae <watchdogConfig>
564
+ 1fc0: ff cf rjmp .-2 ; 0x1fc0 <verifySpace+0xa>
565
+ while (1) // and busy-loop so that WD causes
566
+ ; // a reset and app start.
567
+ }
568
+ putch(STK_INSYNC);
569
+ 1fc2: 84 e1 ldi r24, 0x14 ; 20
570
+ }
571
+ 1fc4: e9 cf rjmp .-46 ; 0x1f98 <putch>
572
+
573
+ 00001fc6 <getNch>:
574
+ ::[count] "M" (UART_B_VALUE)
575
+ );
576
+ }
577
+ #endif
578
+
579
+ void getNch(uint8_t count) {
580
+ 1fc6: 1f 93 push r17
581
+ 1fc8: 18 2f mov r17, r24
582
+ do getch(); while (--count);
583
+ 1fca: ea df rcall .-44 ; 0x1fa0 <getch>
584
+ 1fcc: 11 50 subi r17, 0x01 ; 1
585
+ 1fce: e9 f7 brne .-6 ; 0x1fca <getNch+0x4>
586
+ verifySpace();
587
+ 1fd0: f2 df rcall .-28 ; 0x1fb6 <verifySpace>
588
+ }
589
+ 1fd2: 1f 91 pop r17
590
+ 1fd4: 08 95 ret
591
+
592
+ 00001fd6 <appStart>:
593
+ WDTCSR = _BV(WDCE) | _BV(WDE);
594
+ WDTCSR = x;
595
+ }
596
+
597
+ void appStart() {
598
+ watchdogConfig(WATCHDOG_OFF);
599
+ 1fd6: 80 e0 ldi r24, 0x00 ; 0
600
+ 1fd8: ea df rcall .-44 ; 0x1fae <watchdogConfig>
601
+ __asm__ __volatile__ (
602
+ 1fda: ee 27 eor r30, r30
603
+ 1fdc: ff 27 eor r31, r31
604
+ 1fde: 09 94 ijmp
hardware/arduino/avr/bootloaders/optiboot/pin_defs.h ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) || defined(__AVR_ATmega328__) || defined(__AVR_ATmega88) || defined(__AVR_ATmega8__) || defined(__AVR_ATmega88__)
2
+ /* Onboard LED is connected to pin PB5 in Arduino NG, Diecimila, and Duemilanove */
3
+ #define LED_DDR DDRB
4
+ #define LED_PORT PORTB
5
+ #define LED_PIN PINB
6
+ #define LED PINB5
7
+
8
+ /* Ports for soft UART */
9
+ #ifdef SOFT_UART
10
+ #define UART_PORT PORTD
11
+ #define UART_PIN PIND
12
+ #define UART_DDR DDRD
13
+ #define UART_TX_BIT 1
14
+ #define UART_RX_BIT 0
15
+ #endif
16
+ #endif
17
+
18
+ #if defined(__AVR_ATmega8__)
19
+ //Name conversion R.Wiersma
20
+ #define UCSR0A UCSRA
21
+ #define UDR0 UDR
22
+ #define UDRE0 UDRE
23
+ #define RXC0 RXC
24
+ #define FE0 FE
25
+ #define TIFR1 TIFR
26
+ #define WDTCSR WDTCR
27
+ #endif
28
+
29
+ /* Luminet support */
30
+ #if defined(__AVR_ATtiny84__)
31
+ /* Red LED is connected to pin PA4 */
32
+ #define LED_DDR DDRA
33
+ #define LED_PORT PORTA
34
+ #define LED_PIN PINA
35
+ #define LED PINA4
36
+ /* Ports for soft UART - left port only for now. TX/RX on PA2/PA3 */
37
+ #ifdef SOFT_UART
38
+ #define UART_PORT PORTA
39
+ #define UART_PIN PINA
40
+ #define UART_DDR DDRA
41
+ #define UART_TX_BIT 2
42
+ #define UART_RX_BIT 3
43
+ #endif
44
+ #endif
45
+
46
+ /* Sanguino support */
47
+ #if defined(__AVR_ATmega644P__)
48
+ /* Onboard LED is connected to pin PB0 on Sanguino */
49
+ #define LED_DDR DDRB
50
+ #define LED_PORT PORTB
51
+ #define LED_PIN PINB
52
+ #define LED PINB0
53
+
54
+ /* Ports for soft UART */
55
+ #ifdef SOFT_UART
56
+ #define UART_PORT PORTD
57
+ #define UART_PIN PIND
58
+ #define UART_DDR DDRD
59
+ #define UART_TX_BIT 1
60
+ #define UART_RX_BIT 0
61
+ #endif
62
+ #endif
63
+
64
+ /* Mega support */
65
+ #if defined(__AVR_ATmega1280__)
66
+ /* Onboard LED is connected to pin PB7 on Arduino Mega */
67
+ #define LED_DDR DDRB
68
+ #define LED_PORT PORTB
69
+ #define LED_PIN PINB
70
+ #define LED PINB7
71
+
72
+ /* Ports for soft UART */
73
+ #ifdef SOFT_UART
74
+ #define UART_PORT PORTE
75
+ #define UART_PIN PINE
76
+ #define UART_DDR DDRE
77
+ #define UART_TX_BIT 1
78
+ #define UART_RX_BIT 0
79
+ #endif
80
+ #endif
hardware/arduino/avr/bootloaders/optiboot/stk500.h ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* STK500 constants list, from AVRDUDE */
2
+ #define STK_OK 0x10
3
+ #define STK_FAILED 0x11 // Not used
4
+ #define STK_UNKNOWN 0x12 // Not used
5
+ #define STK_NODEVICE 0x13 // Not used
6
+ #define STK_INSYNC 0x14 // ' '
7
+ #define STK_NOSYNC 0x15 // Not used
8
+ #define ADC_CHANNEL_ERROR 0x16 // Not used
9
+ #define ADC_MEASURE_OK 0x17 // Not used
10
+ #define PWM_CHANNEL_ERROR 0x18 // Not used
11
+ #define PWM_ADJUST_OK 0x19 // Not used
12
+ #define CRC_EOP 0x20 // 'SPACE'
13
+ #define STK_GET_SYNC 0x30 // '0'
14
+ #define STK_GET_SIGN_ON 0x31 // '1'
15
+ #define STK_SET_PARAMETER 0x40 // '@'
16
+ #define STK_GET_PARAMETER 0x41 // 'A'
17
+ #define STK_SET_DEVICE 0x42 // 'B'
18
+ #define STK_SET_DEVICE_EXT 0x45 // 'E'
19
+ #define STK_ENTER_PROGMODE 0x50 // 'P'
20
+ #define STK_LEAVE_PROGMODE 0x51 // 'Q'
21
+ #define STK_CHIP_ERASE 0x52 // 'R'
22
+ #define STK_CHECK_AUTOINC 0x53 // 'S'
23
+ #define STK_LOAD_ADDRESS 0x55 // 'U'
24
+ #define STK_UNIVERSAL 0x56 // 'V'
25
+ #define STK_PROG_FLASH 0x60 // '`'
26
+ #define STK_PROG_DATA 0x61 // 'a'
27
+ #define STK_PROG_FUSE 0x62 // 'b'
28
+ #define STK_PROG_LOCK 0x63 // 'c'
29
+ #define STK_PROG_PAGE 0x64 // 'd'
30
+ #define STK_PROG_FUSE_EXT 0x65 // 'e'
31
+ #define STK_READ_FLASH 0x70 // 'p'
32
+ #define STK_READ_DATA 0x71 // 'q'
33
+ #define STK_READ_FUSE 0x72 // 'r'
34
+ #define STK_READ_LOCK 0x73 // 's'
35
+ #define STK_READ_PAGE 0x74 // 't'
36
+ #define STK_READ_SIGN 0x75 // 'u'
37
+ #define STK_READ_OSCCAL 0x76 // 'v'
38
+ #define STK_READ_FUSE_EXT 0x77 // 'w'
39
+ #define STK_READ_OSCCAL_EXT 0x78 // 'x'
hardware/arduino/avr/bootloaders/stk500v2/License.txt ADDED
@@ -0,0 +1,280 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ GNU GENERAL PUBLIC LICENSE
2
+ Version 2, June 1991
3
+
4
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
5
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
6
+ Everyone is permitted to copy and distribute verbatim copies
7
+ of this license document, but changing it is not allowed.
8
+
9
+ Preamble
10
+
11
+ The licenses for most software are designed to take away your
12
+ freedom to share and change it. By contrast, the GNU General Public
13
+ License is intended to guarantee your freedom to share and change free
14
+ software--to make sure the software is free for all its users. This
15
+ General Public License applies to most of the Free Software
16
+ Foundation's software and to any other program whose authors commit to
17
+ using it. (Some other Free Software Foundation software is covered by
18
+ the GNU Library General Public License instead.) You can apply it to
19
+ your programs, too.
20
+
21
+ When we speak of free software, we are referring to freedom, not
22
+ price. Our General Public Licenses are designed to make sure that you
23
+ have the freedom to distribute copies of free software (and charge for
24
+ this service if you wish), that you receive source code or can get it
25
+ if you want it, that you can change the software or use pieces of it
26
+ in new free programs; and that you know you can do these things.
27
+
28
+ To protect your rights, we need to make restrictions that forbid
29
+ anyone to deny you these rights or to ask you to surrender the rights.
30
+ These restrictions translate to certain responsibilities for you if you
31
+ distribute copies of the software, or if you modify it.
32
+
33
+ For example, if you distribute copies of such a program, whether
34
+ gratis or for a fee, you must give the recipients all the rights that
35
+ you have. You must make sure that they, too, receive or can get the
36
+ source code. And you must show them these terms so they know their
37
+ rights.
38
+
39
+ We protect your rights with two steps: (1) copyright the software, and
40
+ (2) offer you this license which gives you legal permission to copy,
41
+ distribute and/or modify the software.
42
+
43
+ Also, for each author's protection and ours, we want to make certain
44
+ that everyone understands that there is no warranty for this free
45
+ software. If the software is modified by someone else and passed on, we
46
+ want its recipients to know that what they have is not the original, so
47
+ that any problems introduced by others will not reflect on the original
48
+ authors' reputations.
49
+
50
+ Finally, any free program is threatened constantly by software
51
+ patents. We wish to avoid the danger that redistributors of a free
52
+ program will individually obtain patent licenses, in effect making the
53
+ program proprietary. To prevent this, we have made it clear that any
54
+ patent must be licensed for everyone's free use or not licensed at all.
55
+
56
+ The precise terms and conditions for copying, distribution and
57
+ modification follow.
58
+
59
+ GNU GENERAL PUBLIC LICENSE
60
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61
+
62
+ 0. This License applies to any program or other work which contains
63
+ a notice placed by the copyright holder saying it may be distributed
64
+ under the terms of this General Public License. The "Program", below,
65
+ refers to any such program or work, and a "work based on the Program"
66
+ means either the Program or any derivative work under copyright law:
67
+ that is to say, a work containing the Program or a portion of it,
68
+ either verbatim or with modifications and/or translated into another
69
+ language. (Hereinafter, translation is included without limitation in
70
+ the term "modification".) Each licensee is addressed as "you".
71
+
72
+ Activities other than copying, distribution and modification are not
73
+ covered by this License; they are outside its scope. The act of
74
+ running the Program is not restricted, and the output from the Program
75
+ is covered only if its contents constitute a work based on the
76
+ Program (independent of having been made by running the Program).
77
+ Whether that is true depends on what the Program does.
78
+
79
+ 1. You may copy and distribute verbatim copies of the Program's
80
+ source code as you receive it, in any medium, provided that you
81
+ conspicuously and appropriately publish on each copy an appropriate
82
+ copyright notice and disclaimer of warranty; keep intact all the
83
+ notices that refer to this License and to the absence of any warranty;
84
+ and give any other recipients of the Program a copy of this License
85
+ along with the Program.
86
+
87
+ You may charge a fee for the physical act of transferring a copy, and
88
+ you may at your option offer warranty protection in exchange for a fee.
89
+
90
+ 2. You may modify your copy or copies of the Program or any portion
91
+ of it, thus forming a work based on the Program, and copy and
92
+ distribute such modifications or work under the terms of Section 1
93
+ above, provided that you also meet all of these conditions:
94
+
95
+ a) You must cause the modified files to carry prominent notices
96
+ stating that you changed the files and the date of any change.
97
+
98
+ b) You must cause any work that you distribute or publish, that in
99
+ whole or in part contains or is derived from the Program or any
100
+ part thereof, to be licensed as a whole at no charge to all third
101
+ parties under the terms of this License.
102
+
103
+ c) If the modified program normally reads commands interactively
104
+ when run, you must cause it, when started running for such
105
+ interactive use in the most ordinary way, to print or display an
106
+ announcement including an appropriate copyright notice and a
107
+ notice that there is no warranty (or else, saying that you provide
108
+ a warranty) and that users may redistribute the program under
109
+ these conditions, and telling the user how to view a copy of this
110
+ License. (Exception: if the Program itself is interactive but
111
+ does not normally print such an announcement, your work based on
112
+ the Program is not required to print an announcement.)
113
+
114
+ These requirements apply to the modified work as a whole. If
115
+ identifiable sections of that work are not derived from the Program,
116
+ and can be reasonably considered independent and separate works in
117
+ themselves, then this License, and its terms, do not apply to those
118
+ sections when you distribute them as separate works. But when you
119
+ distribute the same sections as part of a whole which is a work based
120
+ on the Program, the distribution of the whole must be on the terms of
121
+ this License, whose permissions for other licensees extend to the
122
+ entire whole, and thus to each and every part regardless of who wrote it.
123
+
124
+ Thus, it is not the intent of this section to claim rights or contest
125
+ your rights to work written entirely by you; rather, the intent is to
126
+ exercise the right to control the distribution of derivative or
127
+ collective works based on the Program.
128
+
129
+ In addition, mere aggregation of another work not based on the Program
130
+ with the Program (or with a work based on the Program) on a volume of
131
+ a storage or distribution medium does not bring the other work under
132
+ the scope of this License.
133
+
134
+ 3. You may copy and distribute the Program (or a work based on it,
135
+ under Section 2) in object code or executable form under the terms of
136
+ Sections 1 and 2 above provided that you also do one of the following:
137
+
138
+ a) Accompany it with the complete corresponding machine-readable
139
+ source code, which must be distributed under the terms of Sections
140
+ 1 and 2 above on a medium customarily used for software interchange; or,
141
+
142
+ b) Accompany it with a written offer, valid for at least three
143
+ years, to give any third party, for a charge no more than your
144
+ cost of physically performing source distribution, a complete
145
+ machine-readable copy of the corresponding source code, to be
146
+ distributed under the terms of Sections 1 and 2 above on a medium
147
+ customarily used for software interchange; or,
148
+
149
+ c) Accompany it with the information you received as to the offer
150
+ to distribute corresponding source code. (This alternative is
151
+ allowed only for noncommercial distribution and only if you
152
+ received the program in object code or executable form with such
153
+ an offer, in accord with Subsection b above.)
154
+
155
+ The source code for a work means the preferred form of the work for
156
+ making modifications to it. For an executable work, complete source
157
+ code means all the source code for all modules it contains, plus any
158
+ associated interface definition files, plus the scripts used to
159
+ control compilation and installation of the executable. However, as a
160
+ special exception, the source code distributed need not include
161
+ anything that is normally distributed (in either source or binary
162
+ form) with the major components (compiler, kernel, and so on) of the
163
+ operating system on which the executable runs, unless that component
164
+ itself accompanies the executable.
165
+
166
+ If distribution of executable or object code is made by offering
167
+ access to copy from a designated place, then offering equivalent
168
+ access to copy the source code from the same place counts as
169
+ distribution of the source code, even though third parties are not
170
+ compelled to copy the source along with the object code.
171
+
172
+ 4. You may not copy, modify, sublicense, or distribute the Program
173
+ except as expressly provided under this License. Any attempt
174
+ otherwise to copy, modify, sublicense or distribute the Program is
175
+ void, and will automatically terminate your rights under this License.
176
+ However, parties who have received copies, or rights, from you under
177
+ this License will not have their licenses terminated so long as such
178
+ parties remain in full compliance.
179
+
180
+ 5. You are not required to accept this License, since you have not
181
+ signed it. However, nothing else grants you permission to modify or
182
+ distribute the Program or its derivative works. These actions are
183
+ prohibited by law if you do not accept this License. Therefore, by
184
+ modifying or distributing the Program (or any work based on the
185
+ Program), you indicate your acceptance of this License to do so, and
186
+ all its terms and conditions for copying, distributing or modifying
187
+ the Program or works based on it.
188
+
189
+ 6. Each time you redistribute the Program (or any work based on the
190
+ Program), the recipient automatically receives a license from the
191
+ original licensor to copy, distribute or modify the Program subject to
192
+ these terms and conditions. You may not impose any further
193
+ restrictions on the recipients' exercise of the rights granted herein.
194
+ You are not responsible for enforcing compliance by third parties to
195
+ this License.
196
+
197
+ 7. If, as a consequence of a court judgment or allegation of patent
198
+ infringement or for any other reason (not limited to patent issues),
199
+ conditions are imposed on you (whether by court order, agreement or
200
+ otherwise) that contradict the conditions of this License, they do not
201
+ excuse you from the conditions of this License. If you cannot
202
+ distribute so as to satisfy simultaneously your obligations under this
203
+ License and any other pertinent obligations, then as a consequence you
204
+ may not distribute the Program at all. For example, if a patent
205
+ license would not permit royalty-free redistribution of the Program by
206
+ all those who receive copies directly or indirectly through you, then
207
+ the only way you could satisfy both it and this License would be to
208
+ refrain entirely from distribution of the Program.
209
+
210
+ If any portion of this section is held invalid or unenforceable under
211
+ any particular circumstance, the balance of the section is intended to
212
+ apply and the section as a whole is intended to apply in other
213
+ circumstances.
214
+
215
+ It is not the purpose of this section to induce you to infringe any
216
+ patents or other property right claims or to contest validity of any
217
+ such claims; this section has the sole purpose of protecting the
218
+ integrity of the free software distribution system, which is
219
+ implemented by public license practices. Many people have made
220
+ generous contributions to the wide range of software distributed
221
+ through that system in reliance on consistent application of that
222
+ system; it is up to the author/donor to decide if he or she is willing
223
+ to distribute software through any other system and a licensee cannot
224
+ impose that choice.
225
+
226
+ This section is intended to make thoroughly clear what is believed to
227
+ be a consequence of the rest of this License.
228
+
229
+ 8. If the distribution and/or use of the Program is restricted in
230
+ certain countries either by patents or by copyrighted interfaces, the
231
+ original copyright holder who places the Program under this License
232
+ may add an explicit geographical distribution limitation excluding
233
+ those countries, so that distribution is permitted only in or among
234
+ countries not thus excluded. In such case, this License incorporates
235
+ the limitation as if written in the body of this License.
236
+
237
+ 9. The Free Software Foundation may publish revised and/or new versions
238
+ of the General Public License from time to time. Such new versions will
239
+ be similar in spirit to the present version, but may differ in detail to
240
+ address new problems or concerns.
241
+
242
+ Each version is given a distinguishing version number. If the Program
243
+ specifies a version number of this License which applies to it and "any
244
+ later version", you have the option of following the terms and conditions
245
+ either of that version or of any later version published by the Free
246
+ Software Foundation. If the Program does not specify a version number of
247
+ this License, you may choose any version ever published by the Free Software
248
+ Foundation.
249
+
250
+ 10. If you wish to incorporate parts of the Program into other free
251
+ programs whose distribution conditions are different, write to the author
252
+ to ask for permission. For software which is copyrighted by the Free
253
+ Software Foundation, write to the Free Software Foundation; we sometimes
254
+ make exceptions for this. Our decision will be guided by the two goals
255
+ of preserving the free status of all derivatives of our free software and
256
+ of promoting the sharing and reuse of software generally.
257
+
258
+ NO WARRANTY
259
+
260
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261
+ FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262
+ OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263
+ PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264
+ OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266
+ TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267
+ PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268
+ REPAIR OR CORRECTION.
269
+
270
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272
+ REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273
+ INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274
+ OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275
+ TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276
+ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277
+ PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278
+ POSSIBILITY OF SUCH DAMAGES.
279
+
280
+ END OF TERMS AND CONDITIONS
hardware/arduino/avr/bootloaders/stk500v2/Makefile ADDED
@@ -0,0 +1,587 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # ----------------------------------------------------------------------------
2
+ # Makefile to compile and link stk500boot bootloader
3
+ # Author: Peter Fleury
4
+ # based on WinAVR Makefile Template written by Eric B. Weddington, J�rg Wunsch, et al.
5
+ #
6
+ # Adjust F_CPU below to the clock frequency in Mhz of your AVR target
7
+ # Adjust BOOTLOADER_ADDRESS to your AVR target
8
+ #
9
+ #----------------------------------------------------------------------------
10
+ # On command line:
11
+ #
12
+ # make all = Make software.
13
+ #
14
+ # make clean = Clean out built project files.
15
+ #
16
+ # make coff = Convert ELF to AVR COFF.
17
+ #
18
+ # make extcoff = Convert ELF to AVR Extended COFF.
19
+ #
20
+ # make program = Download the hex file to the device, using avrdude.
21
+ # Please customize the avrdude settings below first!
22
+ #
23
+ # make debug = Start either simulavr or avarice as specified for debugging,
24
+ # with avr-gdb or avr-insight as the front end for debugging.
25
+ #
26
+ # make filename.s = Just compile filename.c into the assembler code only.
27
+ #
28
+ # make filename.i = Create a preprocessed source file for use in submitting
29
+ # bug reports to the GCC project.
30
+ #
31
+ # To rebuild project do "make clean" then "make all".
32
+ #----------------------------------------------------------------------------
33
+ # <MLS> = Mark Sproul msproul-at-skychariot.com
34
+
35
+
36
+ # MCU name
37
+ #MCU = atmega128
38
+
39
+
40
+ # Processor frequency.
41
+ # This will define a symbol, F_CPU, in all source code files equal to the
42
+ # processor frequency. You can then use this symbol in your source code to
43
+ # calculate timings. Do NOT tack on a 'UL' at the end, this will be done
44
+ # automatically to create a 32-bit value in your source code.
45
+ #F_CPU = 16000000
46
+
47
+
48
+ # Bootloader
49
+ # Please adjust if using a different AVR
50
+ # 0x0e00*2=0x1C00 for ATmega8 512 words Boot Size
51
+ # 0xFC00*2=0x1F800 for ATmega128 1024 words Boot Size
52
+ # 0xF800*2=0x1F000 for ATmega1280
53
+ # 0xF000*2=0x1E000 for ATmega1280
54
+ #BOOTLOADER_ADDRESS = 1E000
55
+
56
+
57
+ # Output format. (can be srec, ihex, binary)
58
+ FORMAT = ihex
59
+
60
+
61
+ # Target file name (without extension).
62
+ TARGET = stk500boot
63
+
64
+
65
+ # List C source files here. (C dependencies are automatically generated.)
66
+ SRC = stk500boot.c
67
+
68
+
69
+ # List Assembler source files here.
70
+ # Make them always end in a capital .S. Files ending in a lowercase .s
71
+ # will not be considered source files but generated files (assembler
72
+ # output from the compiler), and will be deleted upon "make clean"!
73
+ # Even though the DOS/Win* filesystem matches both .s and .S the same,
74
+ # it will preserve the spelling of the filenames, and gcc itself does
75
+ # care about how the name is spelled on its command-line.
76
+ ASRC =
77
+
78
+
79
+ # Optimization level, can be [0, 1, 2, 3, s].
80
+ # 0 = turn off optimization. s = optimize for size.
81
+ # (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
82
+ OPT = s
83
+
84
+
85
+ # Debugging format.
86
+ # Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
87
+ # AVR Studio 4.10 requires dwarf-2.
88
+ # AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
89
+ DEBUG = dwarf-2
90
+
91
+
92
+ # List any extra directories to look for include files here.
93
+ # Each directory must be seperated by a space.
94
+ # Use forward slashes for directory separators.
95
+ # For a directory that has spaces, enclose it in quotes.
96
+ EXTRAINCDIRS =
97
+
98
+
99
+ # Compiler flag to set the C Standard level.
100
+ # c89 = "ANSI" C
101
+ # gnu89 = c89 plus GCC extensions
102
+ # c99 = ISO C99 standard (not yet fully implemented)
103
+ # gnu99 = c99 plus GCC extensions
104
+ CSTANDARD = -std=gnu99
105
+
106
+
107
+ # Place -D or -U options here
108
+ CDEFS = -DF_CPU=$(F_CPU)UL
109
+
110
+
111
+ # Place -I options here
112
+ CINCS =
113
+
114
+
115
+
116
+ #---------------- Compiler Options ----------------
117
+ # -g*: generate debugging information
118
+ # -O*: optimization level
119
+ # -f...: tuning, see GCC manual and avr-libc documentation
120
+ # -Wall...: warning level
121
+ # -Wa,...: tell GCC to pass this to the assembler.
122
+ # -adhlns...: create assembler listing
123
+ CFLAGS = -g$(DEBUG)
124
+ CFLAGS += $(CDEFS) $(CINCS)
125
+ CFLAGS += -O$(OPT)
126
+ CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -fno-jump-tables
127
+ CFLAGS += -Wall -Wstrict-prototypes
128
+ CFLAGS += -Wa,-adhlns=$(<:.c=.lst)
129
+ CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
130
+ CFLAGS += $(CSTANDARD)
131
+
132
+
133
+ #---------------- Assembler Options ----------------
134
+ # -Wa,...: tell GCC to pass this to the assembler.
135
+ # -ahlms: create listing
136
+ # -gstabs: have the assembler create line number information; note that
137
+ # for use in COFF files, additional information about filenames
138
+ # and function names needs to be present in the assembler source
139
+ # files -- see avr-libc docs [FIXME: not yet described there]
140
+ ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
141
+
142
+
143
+ #---------------- Library Options ----------------
144
+ # Minimalistic printf version
145
+ PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
146
+
147
+ # Floating point printf version (requires MATH_LIB = -lm below)
148
+ PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
149
+
150
+ # If this is left blank, then it will use the Standard printf version.
151
+ PRINTF_LIB =
152
+ #PRINTF_LIB = $(PRINTF_LIB_MIN)
153
+ #PRINTF_LIB = $(PRINTF_LIB_FLOAT)
154
+
155
+
156
+ # Minimalistic scanf version
157
+ SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
158
+
159
+ # Floating point + %[ scanf version (requires MATH_LIB = -lm below)
160
+ SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
161
+
162
+ # If this is left blank, then it will use the Standard scanf version.
163
+ SCANF_LIB =
164
+ #SCANF_LIB = $(SCANF_LIB_MIN)
165
+ #SCANF_LIB = $(SCANF_LIB_FLOAT)
166
+
167
+
168
+ MATH_LIB = -lm
169
+
170
+
171
+
172
+ #---------------- External Memory Options ----------------
173
+
174
+ # 64 KB of external RAM, starting after internal RAM (ATmega128!),
175
+ # used for variables (.data/.bss) and heap (malloc()).
176
+ #EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
177
+
178
+ # 64 KB of external RAM, starting after internal RAM (ATmega128!),
179
+ # only used for heap (malloc()).
180
+ #EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff
181
+
182
+ EXTMEMOPTS =
183
+
184
+
185
+
186
+
187
+ #---------------- Linker Options ----------------
188
+ # -Wl,...: tell GCC to pass this to linker.
189
+ # -Map: create map file
190
+ # --cref: add cross reference to map file
191
+ LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
192
+ LDFLAGS += $(EXTMEMOPTS)
193
+ LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
194
+
195
+
196
+ #--------------- bootloader linker Options -------
197
+ # BOOTLOADER_ADDRESS (=Start of Boot Loader section
198
+ # in bytes - not words) is defined above.
199
+ #LDFLAGS += -Wl,--section-start=.text=$(BOOTLOADER_ADDRESS) -nostartfiles -nodefaultlibs
200
+ #LDFLAGS += -Wl,--section-start=.text=$(BOOTLOADER_ADDRESS) -nostartfiles
201
+ LDFLAGS += -Wl,--section-start=.text=$(BOOTLOADER_ADDRESS)
202
+
203
+ #---------------- Programming Options (avrdude) ----------------
204
+
205
+ # Programming hardware: alf avr910 avrisp bascom bsd
206
+ # dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
207
+ #
208
+ # Type: avrdude -c ?
209
+ # to get a full listing.
210
+ #
211
+ AVRDUDE_PROGRAMMER = stk500v2
212
+
213
+ # com1 = serial port. Use lpt1 to connect to parallel port.
214
+ AVRDUDE_PORT = com1 # programmer connected to serial device
215
+
216
+ AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
217
+ #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
218
+
219
+
220
+ # Uncomment the following if you want avrdude's erase cycle counter.
221
+ # Note that this counter needs to be initialized first using -Yn,
222
+ # see avrdude manual.
223
+ #AVRDUDE_ERASE_COUNTER = -y
224
+
225
+ # Uncomment the following if you do /not/ wish a verification to be
226
+ # performed after programming the device.
227
+ #AVRDUDE_NO_VERIFY = -V
228
+
229
+ # Increase verbosity level. Please use this when submitting bug
230
+ # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
231
+ # to submit bug reports.
232
+ #AVRDUDE_VERBOSE = -v -v
233
+
234
+ AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
235
+ AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
236
+ AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
237
+ AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
238
+
239
+
240
+
241
+ #---------------- Debugging Options ----------------
242
+
243
+ # For simulavr only - target MCU frequency.
244
+ DEBUG_MFREQ = $(F_CPU)
245
+
246
+ # Set the DEBUG_UI to either gdb or insight.
247
+ # DEBUG_UI = gdb
248
+ DEBUG_UI = insight
249
+
250
+ # Set the debugging back-end to either avarice, simulavr.
251
+ DEBUG_BACKEND = avarice
252
+ #DEBUG_BACKEND = simulavr
253
+
254
+ # GDB Init Filename.
255
+ GDBINIT_FILE = __avr_gdbinit
256
+
257
+ # When using avarice settings for the JTAG
258
+ JTAG_DEV = /dev/com1
259
+
260
+ # Debugging port used to communicate between GDB / avarice / simulavr.
261
+ DEBUG_PORT = 4242
262
+
263
+ # Debugging host used to communicate between GDB / avarice / simulavr, normally
264
+ # just set to localhost unless doing some sort of crazy debugging when
265
+ # avarice is running on a different computer.
266
+ DEBUG_HOST = localhost
267
+
268
+
269
+
270
+ #============================================================================
271
+
272
+
273
+ # Define programs and commands.
274
+ SHELL = sh
275
+ CC = avr-gcc
276
+ OBJCOPY = avr-objcopy
277
+ OBJDUMP = avr-objdump
278
+ SIZE = avr-size
279
+ NM = avr-nm
280
+ AVRDUDE = avrdude
281
+ REMOVE = rm -f
282
+ COPY = cp
283
+ WINSHELL = cmd
284
+
285
+
286
+ # Define Messages
287
+ # English
288
+ MSG_ERRORS_NONE = Errors: none
289
+ MSG_BEGIN = -------- begin --------
290
+ MSG_END = -------- end --------
291
+ MSG_SIZE_BEFORE = Size before:
292
+ MSG_SIZE_AFTER = Size after:
293
+ MSG_COFF = Converting to AVR COFF:
294
+ MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
295
+ MSG_FLASH = Creating load file for Flash:
296
+ MSG_EEPROM = Creating load file for EEPROM:
297
+ MSG_EXTENDED_LISTING = Creating Extended Listing:
298
+ MSG_SYMBOL_TABLE = Creating Symbol Table:
299
+ MSG_LINKING = Linking:
300
+ MSG_COMPILING = Compiling:
301
+ MSG_ASSEMBLING = Assembling:
302
+ MSG_CLEANING = Cleaning project:
303
+
304
+
305
+
306
+
307
+ # Define all object files.
308
+ OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)
309
+
310
+ # Define all listing files.
311
+ LST = $(SRC:.c=.lst) $(ASRC:.S=.lst)
312
+
313
+
314
+ # Compiler flags to generate dependency files.
315
+ GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d
316
+
317
+
318
+ # Combine all necessary flags and optional flags.
319
+ # Add target processor to flags.
320
+ ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
321
+ ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
322
+
323
+
324
+
325
+ ############################################################
326
+ # May 25, 2010 <MLS> Adding 1280 support
327
+ mega1280: MCU = atmega1280
328
+ mega1280: F_CPU = 16000000
329
+ mega1280: BOOTLOADER_ADDRESS = 1E000
330
+ mega1280: CFLAGS += -D_MEGA_BOARD_
331
+ mega1280: begin gccversion sizebefore build sizeafter end
332
+ mv $(TARGET).hex stk500boot_v2_mega1280.hex
333
+
334
+
335
+ ############################################################
336
+ # Jul 6, 2010 <MLS> Adding 2560 support
337
+ mega2560: MCU = atmega2560
338
+ mega2560: F_CPU = 16000000
339
+ mega2560: BOOTLOADER_ADDRESS = 3E000
340
+ mega2560: CFLAGS += -D_MEGA_BOARD_
341
+ mega2560: begin gccversion sizebefore build sizeafter end
342
+ mv $(TARGET).hex stk500boot_v2_mega2560.hex
343
+
344
+
345
+ ############################################################
346
+ #Initial config on Amber128 board
347
+ # avrdude: Device signature = 0x1e9702
348
+ # avrdude: safemode: lfuse reads as 8F
349
+ # avrdude: safemode: hfuse reads as CB
350
+ # avrdude: safemode: efuse reads as FF
351
+ # Jul 17, 2010 <MLS> Adding 128 support
352
+ ############################################################
353
+ amber128: MCU = atmega128
354
+ #amber128: F_CPU = 16000000
355
+ amber128: F_CPU = 14745600
356
+ amber128: BOOTLOADER_ADDRESS = 1E000
357
+ amber128: CFLAGS += -D_BOARD_AMBER128_
358
+ amber128: begin gccversion sizebefore build sizeafter end
359
+ mv $(TARGET).hex stk500boot_v2_amber128.hex
360
+
361
+ ############################################################
362
+ # Aug 23, 2010 <MLS> Adding atmega2561 support
363
+ m2561: MCU = atmega2561
364
+ m2561: F_CPU = 8000000
365
+ m2561: BOOTLOADER_ADDRESS = 3E000
366
+ m2561: CFLAGS += -D_ANDROID_2561_ -DBAUDRATE=57600
367
+ m2561: begin gccversion sizebefore build sizeafter end
368
+ mv $(TARGET).hex stk500boot_v2_android2561.hex
369
+
370
+
371
+ ############################################################
372
+ # avrdude: Device signature = 0x1e9801
373
+ # avrdude: safemode: lfuse reads as EC
374
+ # avrdude: safemode: hfuse reads as 18
375
+ # avrdude: safemode: efuse reads as FD
376
+ # Aug 23, 2010 <MLS> Adding cerebot 2560 @ 8mhz
377
+ #avrdude -P usb -c usbtiny -p m2560 -v -U flash:w:/Arduino/WiringBootV2_upd1/stk500boot_v2_cerebotplus.hex
378
+ ############################################################
379
+ cerebot: MCU = atmega2560
380
+ cerebot: F_CPU = 8000000
381
+ cerebot: BOOTLOADER_ADDRESS = 3E000
382
+ cerebot: CFLAGS += -D_CEREBOTPLUS_BOARD_ -DBAUDRATE=38400 -DUART_BAUDRATE_DOUBLE_SPEED=1
383
+ cerebot: begin gccversion sizebefore build sizeafter end
384
+ mv $(TARGET).hex stk500boot_v2_cerebotplus.hex
385
+
386
+
387
+ ############################################################
388
+ # Aug 23, 2010 <MLS> Adding atmega2561 support
389
+ penguino: MCU = atmega32
390
+ penguino: F_CPU = 16000000
391
+ penguino: BOOTLOADER_ADDRESS = 7800
392
+ penguino: CFLAGS += -D_PENGUINO_ -DBAUDRATE=57600
393
+ penguino: begin gccversion sizebefore build sizeafter end
394
+ mv $(TARGET).hex stk500boot_v2_penguino.hex
395
+
396
+
397
+ # Default target.
398
+ all: begin gccversion sizebefore build sizeafter end
399
+
400
+ build: elf hex eep lss sym
401
+ #build: hex eep lss sym
402
+
403
+ elf: $(TARGET).elf
404
+ hex: $(TARGET).hex
405
+ eep: $(TARGET).eep
406
+ lss: $(TARGET).lss
407
+ sym: $(TARGET).sym
408
+
409
+
410
+
411
+ # Eye candy.
412
+ # AVR Studio 3.x does not check make's exit code but relies on
413
+ # the following magic strings to be generated by the compile job.
414
+ begin:
415
+ @echo
416
+ @echo $(MSG_BEGIN)
417
+
418
+ end:
419
+ @echo $(MSG_END)
420
+ @echo
421
+
422
+
423
+ # Display size of file.
424
+ HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
425
+ ELFSIZE = $(SIZE) --format=avr --mcu=$(MCU) $(TARGET).elf
426
+
427
+ sizebefore:
428
+ @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
429
+ 2>/dev/null; echo; fi
430
+
431
+ sizeafter:
432
+ @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
433
+ 2>/dev/null; echo; fi
434
+
435
+
436
+
437
+ # Display compiler version information.
438
+ gccversion :
439
+ @$(CC) --version
440
+
441
+
442
+
443
+ # Program the device.
444
+ program: $(TARGET).hex $(TARGET).eep
445
+ $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
446
+
447
+
448
+ # Generate avr-gdb config/init file which does the following:
449
+ # define the reset signal, load the target file, connect to target, and set
450
+ # a breakpoint at main().
451
+ gdb-config:
452
+ @$(REMOVE) $(GDBINIT_FILE)
453
+ @echo define reset >> $(GDBINIT_FILE)
454
+ @echo SIGNAL SIGHUP >> $(GDBINIT_FILE)
455
+ @echo end >> $(GDBINIT_FILE)
456
+ @echo file $(TARGET).elf >> $(GDBINIT_FILE)
457
+ @echo target remote $(DEBUG_HOST):$(DEBUG_PORT) >> $(GDBINIT_FILE)
458
+ ifeq ($(DEBUG_BACKEND),simulavr)
459
+ @echo load >> $(GDBINIT_FILE)
460
+ endif
461
+ @echo break main >> $(GDBINIT_FILE)
462
+
463
+ debug: gdb-config $(TARGET).elf
464
+ ifeq ($(DEBUG_BACKEND), avarice)
465
+ @echo Starting AVaRICE - Press enter when "waiting to connect" message displays.
466
+ @$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \
467
+ $(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)
468
+ @$(WINSHELL) /c pause
469
+
470
+ else
471
+ @$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
472
+ $(DEBUG_MFREQ) --port $(DEBUG_PORT)
473
+ endif
474
+ @$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)
475
+
476
+
477
+
478
+
479
+ # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
480
+ COFFCONVERT=$(OBJCOPY) --debugging \
481
+ --change-section-address .data-0x800000 \
482
+ --change-section-address .bss-0x800000 \
483
+ --change-section-address .noinit-0x800000 \
484
+ --change-section-address .eeprom-0x810000
485
+
486
+
487
+
488
+ coff: $(TARGET).elf
489
+ @echo
490
+ @echo $(MSG_COFF) $(TARGET).cof
491
+ $(COFFCONVERT) -O coff-avr $< $(TARGET).cof
492
+
493
+
494
+ extcoff: $(TARGET).elf
495
+ @echo
496
+ @echo $(MSG_EXTENDED_COFF) $(TARGET).cof
497
+ $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
498
+
499
+
500
+ # Create final output files (.hex, .eep) from ELF output file.
501
+ %.hex: %.elf
502
+ @echo
503
+ @echo $(MSG_FLASH) $@
504
+ $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
505
+
506
+ %.eep: %.elf
507
+ @echo
508
+ @echo $(MSG_EEPROM) $@
509
+ -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
510
+ --change-section-lma .eeprom=0 -O $(FORMAT) $< $@
511
+
512
+ # Create extended listing file from ELF output file.
513
+ %.lss: %.elf
514
+ @echo
515
+ @echo $(MSG_EXTENDED_LISTING) $@
516
+ $(OBJDUMP) -h -S $< > $@
517
+
518
+ # Create a symbol table from ELF output file.
519
+ %.sym: %.elf
520
+ @echo
521
+ @echo $(MSG_SYMBOL_TABLE) $@
522
+ $(NM) -n $< > $@
523
+
524
+
525
+
526
+ # Link: create ELF output file from object files.
527
+ .SECONDARY : $(TARGET).elf
528
+ .PRECIOUS : $(OBJ)
529
+ %.elf: $(OBJ)
530
+ @echo
531
+ @echo $(MSG_LINKING) $@
532
+ $(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
533
+
534
+
535
+ # Compile: create object files from C source files.
536
+ %.o : %.c
537
+ @echo
538
+ @echo $(MSG_COMPILING) $<
539
+ $(CC) -c $(ALL_CFLAGS) $< -o $@
540
+
541
+
542
+ # Compile: create assembler files from C source files.
543
+ %.s : %.c
544
+ $(CC) -S $(ALL_CFLAGS) $< -o $@
545
+
546
+
547
+ # Assemble: create object files from assembler source files.
548
+ %.o : %.S
549
+ @echo
550
+ @echo $(MSG_ASSEMBLING) $<
551
+ $(CC) -c $(ALL_ASFLAGS) $< -o $@
552
+
553
+ # Create preprocessed source for use in sending a bug report.
554
+ %.i : %.c
555
+ $(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@
556
+
557
+
558
+ # Target: clean project.
559
+ clean: begin clean_list end
560
+
561
+ clean_list :
562
+ @echo
563
+ @echo $(MSG_CLEANING)
564
+ $(REMOVE) *.hex
565
+ $(REMOVE) *.eep
566
+ $(REMOVE) *.cof
567
+ $(REMOVE) *.elf
568
+ $(REMOVE) *.map
569
+ $(REMOVE) *.sym
570
+ $(REMOVE) *.lss
571
+ $(REMOVE) $(OBJ)
572
+ $(REMOVE) $(LST)
573
+ $(REMOVE) $(SRC:.c=.s)
574
+ $(REMOVE) $(SRC:.c=.d)
575
+ $(REMOVE) .dep/*
576
+
577
+
578
+
579
+ # Include the dependency files.
580
+ -include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
581
+
582
+
583
+ # Listing of phony targets.
584
+ .PHONY : all begin finish end sizebefore sizeafter gccversion \
585
+ build elf hex eep lss sym coff extcoff \
586
+ clean clean_list program debug gdb-config
587
+
hardware/arduino/avr/bootloaders/stk500v2/Mega2560-prod-firmware-2011-06-29.hex ADDED
@@ -0,0 +1,513 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ :020000023000CC
2
+ :10E000000D94F6F20D941FF30D941FF30D941FF36E
3
+ :10E010000D941FF30D941FF30D941FF30D941FF334
4
+ :10E020000D941FF30D941FF30D941FF30D941FF324
5
+ :10E030000D941FF30D941FF30D941FF30D941FF314
6
+ :10E040000D941FF30D941FF30D941FF30D941FF304
7
+ :10E050000D941FF30D941FF30D941FF30D941FF3F4
8
+ :10E060000D941FF30D941FF30D941FF30D941FF3E4
9
+ :10E070000D941FF30D941FF30D941FF30D941FF3D4
10
+ :10E080000D941FF30D941FF30D941FF30D941FF3C4
11
+ :10E090000D941FF30D941FF30D941FF30D941FF3B4
12
+ :10E0A0000D941FF30D941FF30D941FF30D941FF3A4
13
+ :10E0B0000D941FF30D941FF30D941FF30D941FF394
14
+ :10E0C0000D941FF30D941FF30D941FF30D941FF384
15
+ :10E0D0000D941FF30D941FF30D941FF30D941FF374
16
+ :10E0E0000D941FF341546D65676132353630004140
17
+ :10E0F000726475696E6F206578706C6F72657220DE
18
+ :10E1000073746B3530305632206279204D4C530099
19
+ :10E11000426F6F746C6F616465723E004875683F52
20
+ :10E1200000436F6D70696C6564206F6E20203D2028
21
+ :10E1300000435055205479706520202020203D2038
22
+ :10E14000005F5F4156525F415243485F5F203D2070
23
+ :10E1500000415652204C69624320566572203D2092
24
+ :10E16000004743432056657273696F6E20203D203F
25
+ :10E1700000435055207369676E61747572653D2068
26
+ :10E18000004C6F77206675736520202020203D208D
27
+ :10E1900000486967682066757365202020203D204F
28
+ :10E1A00000457874206675736520202020203D206E
29
+ :10E1B000004C6F636B2066757365202020203D2026
30
+ :10E1C00000536570202039203230313000312E3636
31
+ :10E1D0002E3700342E332E33005623202020414486
32
+ :10E1E00044522020206F7020636F6465202020201F
33
+ :10E1F00020696E737472756374696F6E20616464F4
34
+ :10E2000072202020496E74657272757074006E6F92
35
+ :10E2100020766563746F7200726A6D702020006AE8
36
+ :10E220006D7020005768617420706F72743A0050EE
37
+ :10E230006F7274206E6F7420737570706F72746576
38
+ :10E2400064004D7573742062652061206C65747480
39
+ :10E2500065720020005772697474696E67204545C5
40
+ :10E260000052656164696E6720454500656570729E
41
+ :10E270006F6D206572726F7220636F756E743D00F2
42
+ :10E28000504F525400303D5A65726F206164647281
43
+ :10E290006573732063747273003F3D435055207360
44
+ :10E2A0007461747300403D454550524F4D20746574
45
+ :10E2B000737400423D426C696E6B204C45440045CE
46
+ :10E2C0003D44756D7020454550524F4D00463D44CC
47
+ :10E2D000756D7020464C41534800483D48656C7050
48
+ :10E2E000004C3D4C69737420492F4F20506F72745D
49
+ :10E2F0007300513D517569742026206A756D702038
50
+ :10E30000746F20757365722070676D00523D44759F
51
+ :10E310006D702052414D00563D73686F7720696ED5
52
+ :10E320007465727275707420566563746F727300D1
53
+ :10E33000593D506F727420626C696E6B002A0052F6
54
+ :10E340004553455400494E543000494E543100491C
55
+ :10E350004E543200494E543300494E543400494E15
56
+ :10E36000543500494E543600494E54370050434905
57
+ :10E370004E5430005043494E5431005043494E549E
58
+ :10E3800032005744540054494D45523020434F4DBC
59
+ :10E3900050410054494D45523020434F4D504200AA
60
+ :10E3A00054494D455230204F56460054494D455230
61
+ :10E3B0003120434150540054494D45523120434F80
62
+ :10E3C0004D50410054494D45523120434F4D50422C
63
+ :10E3D0000054494D45523120434F4D50430054495C
64
+ :10E3E0004D455231204F56460054494D455232203A
65
+ :10E3F000434F4D50410054494D45523220434F4DFB
66
+ :10E4000050420054494D455232204F56460054491F
67
+ :10E410004D45523320434150540054494D455233E9
68
+ :10E4200020434F4D50410054494D45523320434FF6
69
+ :10E430004D50420054494D45523320434F4D5043B7
70
+ :10E440000054494D455233204F56460054494D45DE
71
+ :10E45000523420434150540054494D4552342043D6
72
+ :10E460004F4D50410054494D45523420434F4D507B
73
+ :10E47000420054494D45523420434F4D50430054BF
74
+ :10E48000494D455234204F56460054494D4552356A
75
+ :10E4900020434150540054494D45523520434F4D7F
76
+ :10E4A00050410054494D45523520434F4D50420094
77
+ :10E4B00054494D45523520434F4D50430054494D2A
78
+ :10E4C000455235204F564600555341525430205244
79
+ :10E4D000580055534152543020554452450055532D
80
+ :10E4E0004152543020545800555341525431205217
81
+ :10E4F000580055534152543120554452450055530C
82
+ :10E5000041525431205458005553415254322052F4
83
+ :10E5100058005553415254322055445245005553EA
84
+ :10E5200041525432205458005553415254332052D2
85
+ :10E5300058005553415254332055445245005553C9
86
+ :10E5400041525433205458005350492053544300EF
87
+ :10E5500041444300414E414C4F4720434F4D5000F2
88
+ :10E560004545205245414459005457490053504DA8
89
+ :10E57000205245414459002A003FE345E34AE34F16
90
+ :10E58000E354E359E35EE363E368E36DE374E37B41
91
+ :10E59000E382E3E9E3F6E303E4ABE3B7E3C4E3D107
92
+ :10E5A000E3DEE386E393E3A0E348E5C8E4D2E4DEF8
93
+ :10E5B000E454E550E560E50EE41AE427E434E44170
94
+ :10E5C000E4E8E4F2E4FEE469E56DE54CE458E46572
95
+ :10E5D000E472E47FE48AE496E4A3E4B0E4BDE408F2
96
+ :10E5E000E512E51EE528E532E53EE50011241FBEF3
97
+ :10E5F000CFEFD1E2DEBFCDBF01E00CBF12E0A0E063
98
+ :10E60000B2E0EAEDFFEF03E00BBF02C007900D920E
99
+ :10E61000A030B107D9F712E0A0E0B2E001C01D922E
100
+ :10E62000AC30B107E1F70F94FBF40D94EBFF01E27E
101
+ :10E630000EBF0FEF0DBF11241FBE0D94FBF40D9400
102
+ :10E6400000F020E030E040ED57E005C0FA013197DE
103
+ :10E65000F1F72F5F3F4F28173907C0F308959C014A
104
+ :10E66000442737FD4095542FDA01C901860F911DCB
105
+ :10E67000A11DB11DABBFFC018791882369F0809378
106
+ :10E68000C6008091C00086FFFCCF8091C0008064EE
107
+ :10E690008093C0006F5FE8CF08958DE08093C6003F
108
+ :10E6A0008091C00086FFFCCF8091C0008064809381
109
+ :10E6B000C0008AE08093C6008091C00086FFFCCF36
110
+ :10E6C0008091C00080648093C00008950F942FF360
111
+ :10E6D0000F944DF30895FC019081992359F0909384
112
+ :10E6E000C6008091C00086FFFCCF8091C00080648E
113
+ :10E6F0008093C0003196992379F70895282F982F99
114
+ :10E7000092959F70892F805D8A3308F0895F80938E
115
+ :10E71000C6008091C00086FFFCCF8091C00080645D
116
+ :10E720008093C000822F8F70982F905D9A3308F0ED
117
+ :10E73000995F9093C6008091C00086FFFCCF8091C6
118
+ :10E74000C00080648093C00008959C01FB01853661
119
+ :10E7500091051CF46330710594F0C90164E670E022
120
+ :10E760000F948CFF605D7F4F6093C6008091C00066
121
+ :10E7700086FFFCCF8091C00080648093C0002B3066
122
+ :10E78000310514F43297B4F0C90164E670E00F94D7
123
+ :10E790008CFF6AE070E00F948CFF605D7F4F6093A8
124
+ :10E7A000C6008091C00086FFFCCF8091C0008064CD
125
+ :10E7B0008093C000C9016AE070E00F948CFFC0969E
126
+ :10E7C0008093C6008091C00086FFFCCF8091C0007E
127
+ :10E7D00080648093C0000895282F277020642093C0
128
+ :10E7E0007C0020917B0086958695869590E08170CF
129
+ :10E7F000907033E0880F991F3A95E1F7277F282B17
130
+ :10E8000020937B0080917A00806480937A008091CD
131
+ :10E810007A0086FDFCCF2091780040917900942FFA
132
+ :10E8200080E030E0282B392BC90108951F93182F61
133
+ :10E8300080E892EE60E00F942FF31093C600809171
134
+ :10E84000C00086FFFCCF8091C00080648093C00030
135
+ :10E850000F944DF31F9108952F923F924F925F9224
136
+ :10E860006F927F928F929F92AF92BF92CF92DF92E0
137
+ :10E87000EF92FF920F931F93DF93CF93CDB7DEB745
138
+ :10E8800062970FB6F894DEBF0FBECDBF382E622E52
139
+ :10E89000CA01DB015C016D01772460E2262E2E01A6
140
+ :10E8A0000894411C511C8BC081E0A81680E0B8067A
141
+ :10E8B00081E0C80680E0D80628F0C601AA27BB2759
142
+ :10E8C0000F947EF3BB27AD2D9C2D8B2D0F947EF3E3
143
+ :10E8D0008A2D0F947EF32092C6008091C00086FF9F
144
+ :10E8E000FCCF8091C00080648093C0009DE2909333
145
+ :10E8F000C6008091C00086FFFCCF8091C00080647C
146
+ :10E900008093C0002092C6008091C00086FFFCCF9B
147
+ :10E910008091C00080648093C000198286017501D7
148
+ :10E9200088249924A1E03A1651F03A1620F0B2E07A
149
+ :10E930003B1661F409C00BBFF701779007C0C70110
150
+ :10E940000F94D5FF782E02C0F7017080872D0F94A9
151
+ :10E950007EF32092C6008091C00086FFFCCF80919C
152
+ :10E96000C00080648093C000872D8052F401EF7056
153
+ :10E97000F0708F3520F4E40DF51D708204C0E40DB5
154
+ :10E98000F51D8EE280830894E11CF11C011D111D10
155
+ :10E990000894811C911C90E18916910409F0C2CF62
156
+ :10E9A00080E190E0A0E0B0E0A80EB91ECA1EDB1E18
157
+ :10E9B000198AC2010F946BF30F944DF36A94662089
158
+ :10E9C00009F072CF62960FB6F894DEBF0FBECDBFCE
159
+ :10E9D000CF91DF911F910F91FF90EF90DF90CF903B
160
+ :10E9E000BF90AF909F908F907F906F905F904F906F
161
+ :10E9F0003F902F9008952F923F924F925F926F9287
162
+ :10EA00007F928F929F92AF92BF92CF92DF92EF92BE
163
+ :10EA1000FF920F931F93DF93CF93CDB7DEB7CD5304
164
+ :10EA2000D1400FB6F894DEBF0FBECDBF279A2F9A04
165
+ :10EA30008091C00082608093C00080E18093C40018
166
+ :10EA400088E18093C1000000EE24FF248701B4E038
167
+ :10EA5000AB2EB12CCC24DD2424C0C5010197F1F7E5
168
+ :10EA60000894E11CF11C011D111D21E2E2162EE4A7
169
+ :10EA7000F20620E0020720E0120718F0A1E0CA2EFB
170
+ :10EA8000D12CC801B70128E53BE140E050E00F94EC
171
+ :10EA90009FFF611571058105910519F485B18058B5
172
+ :10EAA00085B98091C00087FD03C0C114D104A9F2CB
173
+ :10EAB000A6014F5F5F4FC25EDE4F59834883CE5140
174
+ :10EAC000D140C25EDE4F68817981CE51D140613044
175
+ :10EAD000710511F00D946EFFC05DDE4F1982188232
176
+ :10EAE000C053D14060E0C15DDE4F1882CF52D140AB
177
+ :10EAF000AA24BB24C05EDE4F188219821A821B82B0
178
+ :10EB0000C052D140CE5CDE4F188219821A821B821D
179
+ :10EB1000C253D14080E090E0A0E0B0E0ABBFFC0188
180
+ :10EB2000A791B691C45CDE4FB983A883CC53D14082
181
+ :10EB30000D9469FFC25EDE4FE881F981CE51D1406C
182
+ :10EB4000319709F52091C600C25EDE4F1982188206
183
+ :10EB5000CE51D14022C02F5F3F4F4F4F5F4F2130EA
184
+ :10EB6000F2E13F07FAE74F07F0E05F0780F0C45C8F
185
+ :10EB7000DE4F08811981CC53D1400F5F1F4F19F030
186
+ :10EB8000EE27FF27099420E030E040E050E080913C
187
+ :10EB9000C00087FFE0CF2091C600213209F094C663
188
+ :10EBA0000894A11CB11C33E0A316B10409F08EC671
189
+ :10EBB00000E010E018C041E24093C6008091C00020
190
+ :10EBC00086FFFCCF8091C00080648093C0002F5FDF
191
+ :10EBD0003F4F2931310579F70F944DF30F5F1F4FE8
192
+ :10EBE0000530110519F020E030E0E5CF1092080261
193
+ :10EBF0001092090210920A0210920B021092040263
194
+ :10EC00001092050210920602109207021092000262
195
+ :10EC10001092010210920202109203028FEE90EE07
196
+ :10EC200060E00F9466F380E191EE60E00F942FF3C3
197
+ :10EC30008091C00087FFFCCF9091C600903608F00D
198
+ :10EC40009F759032B8F09093C6008091C00086FF07
199
+ :10EC5000FCCF8091C00080648093C00080E28093EC
200
+ :10EC6000C6008091C00086FFFCCF8091C000806408
201
+ :10EC70008093C000983409F4DBC19934B8F492341D
202
+ :10EC800009F45DC1933458F4903319F1903308F4CA
203
+ :10EC900018C69F33A1F1903409F013C6BDC0953456
204
+ :10ECA00009F474C1963409F00CC69CC1923509F47C
205
+ :10ECB0002FC2933538F49C3409F4F9C1913509F029
206
+ :10ECC00000C61CC2963509F449C2993509F0F9C548
207
+ :10ECD0009CC485E892EE62E00F9466F31092040201
208
+ :10ECE000109205021092060210920702109208027A
209
+ :10ECF0001092090210920A0210920B0217C189E9C0
210
+ :10ED000092EE62E00F9466F38FEE90EE60E00F9467
211
+ :10ED100066F381E291EE60E00F942FF381EC91EEC7
212
+ :10ED200060E00F9466F381E391EE60E00F942FF3BF
213
+ :10ED300084EE90EE60E00F9466F381E491EE60E083
214
+ :10ED40000F942FF386E090E061E070E00F94A5F35C
215
+ :10ED50000F944DF381E691EE60E00F942FF383ED75
216
+ :10ED600091EE60E00F9466F381E591EE60E00F9420
217
+ :10ED70002FF38DEC91EE60E00F9466F381E791EE56
218
+ :10ED800060E00F942FF38EE10F947EF388E90F94E7
219
+ :10ED90007EF381E00F947EF30F944DF381E891EEC2
220
+ :10EDA00060E00F942FF319E0E0E0F0E010935700DB
221
+ :10EDB000E4918E2F0F947EF30F944DF381E991EE41
222
+ :10EDC00060E00F942FF3E3E0F0E010935700E4913C
223
+ :10EDD0008E2F0F947EF30F944DF381EA91EE60E055
224
+ :10EDE0000F942FF3E2E0F0E010935700E4918E2FA0
225
+ :10EDF0000F947EF30F944DF381EB91EE60E00F944E
226
+ :10EE00002FF3E1E0F0E0109357001491812F0F945D
227
+ :10EE10007EF30F944DF307CF85EA92EE62E00F94F4
228
+ :10EE200066F385E592EE60E00F9466F30F944DF380
229
+ :10EE300000E010E019C0C8016F2D0F94DDFFFF2026
230
+ :10EE400031F483E592EE60E00F942FF30BC0F09263
231
+ :10EE5000C6008091C00086FFFCCF8091C000806416
232
+ :10EE60008093C0000F5F1F4FC80181519F41AA27A7
233
+ :10EE700097FDA095BA2FABBFFC01F7905AE2F516AB
234
+ :10EE800021F062E000301607B1F60F944DF30F94B5
235
+ :10EE90004DF381E692EE60E00F9466F30F944DF32C
236
+ :10EEA000CC24DD2400E010E01EC0C8010F94D5FF83
237
+ :10EEB000F82E882331F483E592EE60E00F942FF36F
238
+ :10EEC0000BC08093C6008091C00086FFFCCF80916C
239
+ :10EED000C00080648093C000FE1419F00894C11C27
240
+ :10EEE000D11C0F5F1F4FC80181519F41AA2797FD79
241
+ :10EEF000A095BA2FABBFFC01E7907AE2E71621F0AC
242
+ :10EF000082E00030180789F60F944DF30F944DF30B
243
+ :10EF10008CE692EE60E00F942FF3C60161E070E0A2
244
+ :10EF20000F94A5F30F944DF30F944DF3109200023C
245
+ :10EF300010920102109202021092030274CE83EB2F
246
+ :10EF400092EE62E00F9466F3279A2F9A16C02F98DC
247
+ :10EF500080E090E0E0EDF7E03197F1F7019684363C
248
+ :10EF60009105C1F72F9A80E090E0E0EDF7E031974E
249
+ :10EF7000F1F7019684369105C1F78091C00087FFB3
250
+ :10EF8000E6CF8091C00087FFFCCF95C48FEB92EE57
251
+ :10EF900062E00F9466F3409100025091010260918B
252
+ :10EFA00002027091030281E020E10F942CF4809121
253
+ :10EFB000000290910102A0910202B09103028050E0
254
+ :10EFC0009F4FAF4FBF4F8093000290930102A093D9
255
+ :10EFD0000202B093030280509041A040B04008F478
256
+ :10EFE00022CEA4CF8DEC92EE62E00F9466F34091B6
257
+ :10EFF000040250910502609106027091070280E0C0
258
+ :10F0000020E10F942CF48091040290910502A091CC
259
+ :10F010000602B091070280509F4FAF4FBF4F8093C1
260
+ :10F02000040290930502A0930602B0930702FBCD61
261
+ :10F030008AED92EE62E00F9466F385E892EE60E06E
262
+ :10F040000F9466F389E992EE60E00F9466F385EA27
263
+ :10F0500092EE60E00F9466F383EB92EE60E00F9423
264
+ :10F0600066F38FEB92EE60E00F9466F38DEC92EE18
265
+ :10F0700060E00F9466F38AED92EE60E00F9466F321
266
+ :10F0800081EE92EE60E00F9466F382EF92EE60E024
267
+ :10F090000F9466F38CE093EE60E00F9466F387E1E3
268
+ :10F0A00093EE60E00F9466F380E393EEB9CD81EECA
269
+ :10F0B00092EE62E00F9466F381E40F9416F482E41A
270
+ :10F0C0000F9416F483E40F9416F484E40F9416F46A
271
+ :10F0D00085E40F9416F486E40F9416F487E40F94F5
272
+ :10F0E00016F488E40F9416F48AE40F9416F48BE473
273
+ :10F0F0000F9416F48CE40F9416F495CD82EF92EEF3
274
+ :10F1000062E00F9466F399249394AA24BB2445C427
275
+ :10F110008CE093EE62E00F9466F340910802509108
276
+ :10F12000090260910A0270910B0282E020E10F94C3
277
+ :10F130002CF48091080290910902A0910A02B091EA
278
+ :10F140000B0280509F4FAF4FBF4F809308029093A8
279
+ :10F150000902A0930A02B0930B0265CD87E193EEFA
280
+ :10F1600062E00F9466F384EE90EE60E00F9466F335
281
+ :10F1700089ED91EE60E00F9466F309E715EECC5D42
282
+ :10F18000DE4F19830883C452D1406624772443019B
283
+ :10F19000CA5DDE4F19821882C652D140A401930184
284
+ :10F1A0005695479537952795C85DDE4F2883398357
285
+ :10F1B0004A835B83C852D140CA5DDE4F4881598182
286
+ :10F1C000C652D1404F5F5F4FCA5DDE4F59834883BF
287
+ :10F1D000C652D140CA0162E070E00F94A5F350E23C
288
+ :10F1E0005093C6008091C00086FFFCCF8091C00084
289
+ :10F1F00080648093C0006DE26093C6008091C0007F
290
+ :10F2000086FFFCCF8091C00080648093C00070E2D4
291
+ :10F210007093C6008091C00086FFFCCF8091C00033
292
+ :10F2200080648093C000C85DDE4FE880F9800A8169
293
+ :10F230001B81C852D140BB27A12F902F8F2D0F9437
294
+ :10F240007EF3C85DDE4F8881C852D1400F947EF3B3
295
+ :10F2500070E2F72EF092C6008091C00086FFFCCFCE
296
+ :10F260008091C00080648093C0000DE30093C600CD
297
+ :10F270008091C00086FFFCCF8091C00080648093A5
298
+ :10F28000C00010E21093C6008091C00086FFFCCF42
299
+ :10F290008091C00080648093C0008BBEF3012791F1
300
+ :10F2A000C45DDE4F2883CC52D140A22EBB24CC2497
301
+ :10F2B000DD240894611C711C811C911C8BBEF30120
302
+ :10F2C0008791282E332444245524142D032DF22C09
303
+ :10F2D000EE24EA0CFB1C0C1D1D1D0894611C711C06
304
+ :10F2E000811C911C8BBEF3013791C35DDE4F3883C7
305
+ :10F2F000CD52D1400894611C711C811C911C8BBEA5
306
+ :10F30000F3014791C25DDE4F4883CE52D1402DEFCD
307
+ :10F310003FEF4FEF5FEF620E731E841E951E0F943A
308
+ :10F320007EF330E23093C6008091C00086FFFCCFB0
309
+ :10F330008091C00080648093C000C45DDE4F8881EE
310
+ :10F34000CC52D1400F947EF340E24093C6008091AE
311
+ :10F35000C00086FFFCCF8091C00080648093C00015
312
+ :10F36000C25DDE4F8881CE52D1400F947EF350E2D1
313
+ :10F370005093C6008091C00086FFFCCF8091C000F2
314
+ :10F3800080648093C000C35DDE4F8881CD52D14040
315
+ :10F390000F947EF360E26093C6008091C00086FF08
316
+ :10F3A000FCCF8091C00080648093C0007FEFE7169F
317
+ :10F3B0007FEFF70670E0070770E0170731F48EE083
318
+ :10F3C00092EE60E00F942FF3DFC0D801C701807088
319
+ :10F3D000907CA070B0708050904CA040B040D1F5AF
320
+ :10F3E0002FEF3FE340E050E0E222F3220423152315
321
+ :10F3F000C85DDE4FA880B980CA80DB80C852D1408A
322
+ :10F40000AE0CBF1CC01ED11EAA0CBB1CCC1CDD1C2C
323
+ :10F4100088E192EE60E00F942FF3BB27A12F902F8D
324
+ :10F420008F2D0F947EF38E2D0F947EF330E2309368
325
+ :10F43000C6008091C00086FFFCCF8091C000806430
326
+ :10F440008093C0004EE34093C6008091C00086FFC9
327
+ :10F45000FCCF87C06EE07EEF80E090E0E622F722EE
328
+ :10F46000082319237CE0E71674E9F70670E0070724
329
+ :10F4700070E0170709F088C0C25DDE4F8881CE5268
330
+ :10F48000D140E82EFF2400E010E0102F0F2DFE2CBD
331
+ :10F49000EE24C35DDE4F9881CD52D140E90EF11CC0
332
+ :10F4A000011D111DD601C50181709070A070B07052
333
+ :10F4B000DC0199278827E80EF91E0A1F1B1F20EF81
334
+ :10F4C00030E040E050E0A222B322C422D522F1E194
335
+ :10F4D000AA0CBB1CCC1CDD1CFA95D1F7EA0CFB1C5A
336
+ :10F4E0000C1D1D1D41E050E060E070E0242235223B
337
+ :10F4F00046225722E5E1220C331C441C551CEA9598
338
+ :10F50000D1F7E20CF31C041D151D57016801AA0C6C
339
+ :10F51000BB1CCC1CDD1C8FE192EE60E00F942FF33E
340
+ :10F52000C801AA27BB270F947EF3BB27A12F902FDA
341
+ :10F530008F2D0F947EF38E2D0F947EF350E2509317
342
+ :10F54000C6008091C00086FFFCCF8091C00080641F
343
+ :10F550008093C0006EE36093C6008091C00086FF78
344
+ :10F56000FCCF8091C00080648093C000C601AA27B0
345
+ :10F57000BB270F947EF3BB27AD2D9C2D8B2D0F94B5
346
+ :10F580007EF38A2D0F947EF370E27093C600809113
347
+ :10F59000C00086FFFCCF8091C00080648093C000D3
348
+ :10F5A000CC5DDE4FE881F981C452D140CF01AA275A
349
+ :10F5B00097FDA095BA2FABBFFC018791969160E0B3
350
+ :10F5C0000F942FF30F944DF3CC5DDE4F088119811A
351
+ :10F5D000C452D1400E5F1F4FCC5DDE4F19830883AC
352
+ :10F5E000C452D140CA5DDE4F28813981C652D14014
353
+ :10F5F0002933310509F417CB44E050E060E070E0B6
354
+ :10F60000640E751E861E971EC9CD80E393EE62E0E0
355
+ :10F610000F9466F384E292EE60E00F942FF38091F2
356
+ :10F62000C00087FFFCCF1091C6001F751093C60065
357
+ :10F630008091C00086FFFCCF8091C00080648093E1
358
+ :10F64000C0000F944DF3812F81548A3108F036C1E8
359
+ :10F65000163409F495C0173490F4133409F44EC0ED
360
+ :10F66000143430F41134F1F0123409F01DC130C0FB
361
+ :10F67000143409F459C0153409F016C16BC01A349A
362
+ :10F6800009F4C4C01B3438F4173409F48FC018349B
363
+ :10F6900009F00AC1A1C01B3409F4D2C01C3409F01E
364
+ :10F6A00003C1E8C08FEF81B90DC082B1809582B9E6
365
+ :10F6B00080E090E0E0EDF7E03197F1F70196883CCB
366
+ :10F6C0009105C1F78091C00087FFEFCF12B8EFC05E
367
+ :10F6D0008FEF84B90DC085B1809585B980E090E049
368
+ :10F6E000E0EDF7E03197F1F70196883C9105C1F71D
369
+ :10F6F0008091C00087FFEFCF15B8D9C08FEF87B9D1
370
+ :10F700000DC088B1809588B980E090E0E0EDF7E029
371
+ :10F710003197F1F70196883C9105C1F78091C000BF
372
+ :10F7200087FFEFCF18B8C3C08FEF8AB90DC08BB178
373
+ :10F7300080958BB980E090E0E0EDF7E03197F1F74C
374
+ :10F740000196883C9105C1F78091C00087FFEFCFFB
375
+ :10F750001BB8ADC08FEF8DB90DC08EB180958EB93D
376
+ :10F7600080E090E0E0EDF7E03197F1F70196883C1A
377
+ :10F770009105C1F78091C00087FFEFCF1EB897C0F9
378
+ :10F780008FEF80BB0DC081B3809581BB80E090E09E
379
+ :10F79000E0EDF7E03197F1F70196883C9105C1F76C
380
+ :10F7A0008091C00087FFEFCF11BA81C08FEF83BB7C
381
+ :10F7B0000DC084B3809584BB80E090E0E0EDF7E07D
382
+ :10F7C0003197F1F70196883C9105C1F78091C0000F
383
+ :10F7D00087FFEFCF14BA6BC08FEF809301010FC08A
384
+ :10F7E0008091020180958093020180E090E0E0ED3D
385
+ :10F7F000F7E03197F1F70196883C9105C1F78091C8
386
+ :10F80000C00087FFEDCF1092020151C08FEF8093AF
387
+ :10F8100004010FC08091050180958093050180E06F
388
+ :10F8200090E0E0EDF7E03197F1F70196883C910523
389
+ :10F83000C1F78091C00087FFEDCF1092050137C05E
390
+ :10F840008FEF809307010FC080910801809580930E
391
+ :10F85000080180E090E0E0EDF7E03197F1F70196E4
392
+ :10F86000883C9105C1F78091C00087FFEDCF1092D1
393
+ :10F8700008011DC08FEF80930A010FC080910B011A
394
+ :10F88000809580930B0180E090E0E0EDF7E0319708
395
+ :10F89000F1F70196883C9105C1F78091C00087FF80
396
+ :10F8A000EDCF10920B0103C08FE292EEB9C98091A7
397
+ :10F8B000C00087FFFCCF8091C600B5C982E492EEFC
398
+ :10F8C000AFC98CE191EEACC9AA24BB24933061F19D
399
+ :10F8D000943028F4913089F0923008F508C09530C2
400
+ :10F8E000B1F1953040F1963009F053C04EC02B3144
401
+ :10F8F00009F020C991E06BE11DC9213041F0C15DE3
402
+ :10F90000DE4F5881CF52D140251709F002C362273C
403
+ :10F91000C15DDE4F2883CF52D14092E00BC9B22F98
404
+ :10F92000A0E0622793E006C9822F90E0A82BB92BB4
405
+ :10F93000622794E0FFC82E3009F0EBC2622795E001
406
+ :10F94000C05DDE4F19821882C053D140F3C8E1E098
407
+ :10F95000F0E0EC0FFD1FC05DDE4FE880F980C05382
408
+ :10F96000D140EE0DFF1D208387010F5F1F4FC05D4B
409
+ :10F97000DE4F19830883C053D14062270A171B0743
410
+ :10F9800009F0D8C8D80196E0D5C8261709F0C1C239
411
+ :10F9900003C0973009F0CEC899248981833109F4D6
412
+ :10F9A000FCC08431C8F4863009F4C2C0873050F4FA
413
+ :10F9B000823009F4F0C0833009F458C0813009F076
414
+ :10F9C0000AC23EC0813109F462C0823108F0A6C08B
415
+ :10F9D000803109F000C2DFC0883109F472C089317A
416
+ :10F9E00050F4853109F4D9C0853108F477C18631E6
417
+ :10F9F00009F0F1C173C18A3109F457C08A3108F4A2
418
+ :10FA00007CC08B3109F446C08D3109F0E4C18D8191
419
+ :10FA1000803311F090E00AC08F81882311F49EE1B9
420
+ :10FA200005C0813011F091E001C098E91A821B8273
421
+ :10FA30008D818C831D829E831F8227E030E0CFC1A1
422
+ :10FA40001A8288E08B8381E48C8386E58D8382E54E
423
+ :10FA50008E8389E48F8383E5888780E589878FE5B6
424
+ :10FA60008A8782E38B872BE030E0B9C18A818139B4
425
+ :10FA700041F0823941F0803911F48FE005C080E017
426
+ :10FA800003C082E001C08AE01A828B8344C09924BB
427
+ :10FA9000939481C08D81882311F48EE12CC0813034
428
+ :10FAA00011F081E028C088E926C01A82E1E0F0E088
429
+ :10FAB00089E08093570084918B831C8224E030E09E
430
+ :10FAC0008EC18B81803589F48C81883039F4E2E0F5
431
+ :10FAD000F0E089E08093570084910DC0E0E0F0E011
432
+ :10FAE00089E080935700849106C0E3E0F0E089E06C
433
+ :10FAF0008093570084911A82DFCF8D81836C99E0C7
434
+ :10FB0000E1E0F0E0082E90935700E89507B600FC7E
435
+ :10FB1000FDCF1A821B8223E030E061C11A82CE5CE5
436
+ :10FB2000DE4F188219821A821B82C253D14055C1FE
437
+ :10FB30008A8190E0A0E0B0E0582F442733272227A5
438
+ :10FB40008B8190E0A0E0B0E0DC0199278827282B8A
439
+ :10FB5000392B4A2B5B2B8D8190E0A0E0B0E0282B65
440
+ :10FB6000392B4A2B5B2B8C8190E0A0E0B0E0BA2FC0
441
+ :10FB7000A92F982F8827282B392B4A2B5B2B220F54
442
+ :10FB8000331F441F551FC05EDE4F288339834A83CD
443
+ :10FB90005B83C052D1401A8220C19A812B8183316C
444
+ :10FBA00049F0C05EDE4F488159816A817B81C05235
445
+ :10FBB000D1408AC0CE5CDE4F488159816A817B8109
446
+ :10FBC000C253D140403080EC580783E0680780E0A2
447
+ :10FBD0007807F0F483E0FA0160935B0080935700AC
448
+ :10FBE000E89507B600FCFDCFCE5CDE4F4881598119
449
+ :10FBF0006A817B81C253D14040505F4F6F4F7F4F2E
450
+ :10FC0000CE5CDE4F488359836A837B83C253D140E5
451
+ :10FC1000C95CDE4F9883C753D140CA5CDE4F18825F
452
+ :10FC2000C653D140022F10E0CA5CDE4F6881798153
453
+ :10FC3000C653D140062B172BC05EDE4F4881598139
454
+ :10FC40006A817B81C052D140DE011B9631E08C91EC
455
+ :10FC500011962C9111971296C75CDE4F2883C953D9
456
+ :10FC6000D140C85CDE4F1882C853D14090E0C85CD8
457
+ :10FC7000DE4FE881F981C853D1408E2B9F2B0C01B8
458
+ :10FC8000FA0160935B0030935700E89511244E5FB2
459
+ :10FC90005F4F6F4F7F4F02501040C9F685E0C05E46
460
+ :10FCA000DE4FE880F9800A811B81C052D140F70104
461
+ :10FCB00000935B0080935700E89507B600FCFDCFEA
462
+ :10FCC00081E180935700E8951A82C05EDE4F488339
463
+ :10FCD00059836A837B83C052D1407FC0FA80C55C60
464
+ :10FCE000DE4FF882CB53D140C65CDE4F1882CA5338
465
+ :10FCF000D1408B81C82EDD24C65CDE4F088119817E
466
+ :10FD0000CA53D140C02AD12A1A828981BE016D5FAF
467
+ :10FD10007F4F843121F59601C05EDE4FE880F98087
468
+ :10FD20000A811B81C052D1400BBFF7018791969188
469
+ :10FD3000DB018C9311969C936E5F7F4FD801C701B6
470
+ :10FD40000296A11DB11DC05EDE4F88839983AA83F0
471
+ :10FD5000BB83C052D14022503040F1F636C0C05E65
472
+ :10FD6000DE4F288139814A815B81C052D14008949D
473
+ :10FD7000C108D108760100E010E00894C11CD11C34
474
+ :10FD80000894E11CF11C011D111DE20EF31E041F5D
475
+ :10FD9000151F21BDBB27A52F942F832F82BD2F5F59
476
+ :10FDA0003F4F4F4F5F4FF89A80B5DB018D93BD01F8
477
+ :10FDB0002E153F054007510761F7C05EDE4F2883CF
478
+ :10FDC00039834A835B83C052D14096012D5F3F4FF8
479
+ :10FDD000FB01108204C080EC8A8322E030E08BE1DA
480
+ :10FDE0008093C6008091C00086FFFCCF8091C00048
481
+ :10FDF00080648093C000C15DDE4FF881CF52D14056
482
+ :10FE0000F093C6008091C00086FFFCCF8091C000B7
483
+ :10FE100080648093C000432F3093C6008091C0005F
484
+ :10FE200086FFFCCF8091C00080648093C000922F39
485
+ :10FE30002093C6008091C00086FFFCCF8091C00057
486
+ :10FE400080648093C0008EE08093C6008091C000E3
487
+ :10FE500086FFFCCF8091C00080648093C00065E184
488
+ :10FE6000C15DDE4FE880CF52D1406E2569276427FF
489
+ :10FE7000FE01319610C090819093C6008091C00021
490
+ :10FE800086FFFCCF31968091C00080648093C000D3
491
+ :10FE90006927215030402115310569F76093C6006C
492
+ :10FEA0008091C00086FFFCCF8091C0008064809369
493
+ :10FEB000C00085B1805885B9992081F4C15DDE4FBD
494
+ :10FEC0000881CF52D1400F5FC15DDE4F0883CF5212
495
+ :10FED000D14090E0A0E0B0E00D949AF527982F98DB
496
+ :10FEE00080E090E020ED37E0F9013197F1F70196DD
497
+ :10FEF00084369105C9F700008091C0008D7F809302
498
+ :10FF0000C00081E180935700E895EE27FF27099410
499
+ :10FF1000FFCF90E00D949AF597FB092E07260AD0A3
500
+ :10FF200077FD04D02ED006D000201AF4709561958C
501
+ :10FF30007F4F0895F6F7909581959F4F0895A1E220
502
+ :10FF40001A2EAA1BBB1BFD010DC0AA1FBB1FEE1F53
503
+ :10FF5000FF1FA217B307E407F50720F0A21BB30B9E
504
+ :10FF6000E40BF50B661F771F881F991F1A9469F71A
505
+ :10FF700060957095809590959B01AC01BD01CF0176
506
+ :10FF80000895AA1BBB1B51E107C0AA1FBB1FA617E0
507
+ :10FF9000B70710F0A61BB70B881F991F5A95A9F732
508
+ :10FFA00080959095BC01CD010895F999FECF92BD41
509
+ :10FFB00081BDF89A992780B50895262FF999FECF2B
510
+ :10FFC0001FBA92BD81BD20BD0FB6F894FA9AF99A76
511
+ :0AFFD0000FBE01960895F894FFCFCC
512
+ :040000033000E000E9
513
+ :00000001FF
hardware/arduino/avr/bootloaders/stk500v2/STK500V2.pnproj ADDED
@@ -0,0 +1 @@
 
 
1
+ <Project name="STK500V2"><File path="License.txt"></File><File path="Makefile"></File><File path="stk500boot.c"></File><File path="command.h"></File><File path="Readme.txt"></File></Project>
hardware/arduino/avr/bootloaders/stk500v2/STK500V2.pnps ADDED
@@ -0,0 +1 @@
 
 
1
+ <pd><ViewState><e p="STK500V2" x="true"></e></ViewState></pd>
hardware/arduino/avr/bootloaders/stk500v2/avr_cpunames.h ADDED
@@ -0,0 +1,189 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //**************************************************************************************************
2
+ //*
3
+ //* Atmel AVR CPU name strings
4
+ //*
5
+ //**************************************************************************************************
6
+ //* Sep 19, 2010 <MLS> Started on avr_cpunames.h
7
+ //**************************************************************************************************
8
+
9
+ //#include "avr_cpunames.h"
10
+
11
+ //**************************************************************************************************
12
+
13
+
14
+ #if defined (__AVR_AT94K__)
15
+ #define _AVR_CPU_NAME_ "AT94k"
16
+ #elif defined (__AVR_AT43USB320__)
17
+ #elif defined (__AVR_AT43USB355__)
18
+ #elif defined (__AVR_AT76C711__)
19
+ #elif defined (__AVR_AT86RF401__)
20
+ #elif defined (__AVR_AT90PWM1__)
21
+ #elif defined (__AVR_AT90PWM2__)
22
+ #elif defined (__AVR_AT90PWM2B__)
23
+ #elif defined (__AVR_AT90PWM3__)
24
+ #elif defined (__AVR_AT90PWM3B__)
25
+ #elif defined (__AVR_AT90PWM216__)
26
+ #elif defined (__AVR_AT90PWM316__)
27
+ #elif defined (__AVR_ATmega32C1__)
28
+ #elif defined (__AVR_ATmega32M1__)
29
+ #elif defined (__AVR_ATmega32U4__)
30
+ #define _AVR_CPU_NAME_ "ATmega32U4"
31
+ #elif defined (__AVR_ATmega32U6__)
32
+ #define _AVR_CPU_NAME_ "ATmega32U6"
33
+ #elif defined (__AVR_ATmega128__)
34
+ #define _AVR_CPU_NAME_ "Atmega128"
35
+ #elif defined (__AVR_ATmega1280__)
36
+ #define _AVR_CPU_NAME_ "ATmega1280"
37
+ #elif defined (__AVR_ATmega1281__)
38
+ #define _AVR_CPU_NAME_ "ATmega1281"
39
+ #elif defined (__AVR_ATmega1284P__)
40
+ #define _AVR_CPU_NAME_ "ATmega1284"
41
+ #elif defined (__AVR_ATmega128RFA1__)
42
+ #define _AVR_CPU_NAME_ "ATmega128RFA1"
43
+ #elif defined (__AVR_ATmega2560__)
44
+ #define _AVR_CPU_NAME_ "ATmega2560"
45
+ #elif defined (__AVR_ATmega2561__)
46
+ #define _AVR_CPU_NAME_ "ATmega2561"
47
+ #elif defined (__AVR_AT90CAN32__)
48
+ #define _AVR_CPU_NAME_ "AT90CAN32"
49
+ #elif defined (__AVR_AT90CAN64__)
50
+ #define _AVR_CPU_NAME_ "AT90CAN64"
51
+ #elif defined (__AVR_AT90CAN128__)
52
+ #define _AVR_CPU_NAME_ "AT90CAN128"
53
+ #elif defined (__AVR_AT90USB82__)
54
+ #define _AVR_CPU_NAME_ "AT90USB82"
55
+ #elif defined (__AVR_AT90USB162__)
56
+ #define _AVR_CPU_NAME_ "AT90USB162"
57
+ #elif defined (__AVR_AT90USB646__)
58
+ #define _AVR_CPU_NAME_ "AT90USB646"
59
+ #elif defined (__AVR_AT90USB647__)
60
+ #define _AVR_CPU_NAME_ "AT90USB647"
61
+ #elif defined (__AVR_AT90USB1286__)
62
+ #define _AVR_CPU_NAME_ "AT90USB1286"
63
+ #elif defined (__AVR_AT90USB1287__)
64
+ #define _AVR_CPU_NAME_ "AT90USB1287"
65
+ #elif defined (__AVR_ATmega64__)
66
+ #define _AVR_CPU_NAME_ "ATmega64"
67
+ #elif defined (__AVR_ATmega640__)
68
+ #define _AVR_CPU_NAME_ "ATmega640"
69
+ #elif defined (__AVR_ATmega644__)
70
+ #define _AVR_CPU_NAME_ "ATmega644"
71
+ #elif defined (__AVR_ATmega644P__)
72
+ #define _AVR_CPU_NAME_ "ATmega644P"
73
+ #elif defined (__AVR_ATmega645__)
74
+ #define _AVR_CPU_NAME_ "ATmega645"
75
+ #elif defined (__AVR_ATmega6450__)
76
+ #define _AVR_CPU_NAME_ "ATmega6450"
77
+ #elif defined (__AVR_ATmega649__)
78
+ #define _AVR_CPU_NAME_ "ATmega649"
79
+ #elif defined (__AVR_ATmega6490__)
80
+ #define _AVR_CPU_NAME_ "ATmega6490"
81
+ #elif defined (__AVR_ATmega103__)
82
+ #define _AVR_CPU_NAME_ "ATmega103"
83
+ #elif defined (__AVR_ATmega32__)
84
+ #define _AVR_CPU_NAME_ "Atmega32"
85
+ #elif defined (__AVR_ATmega323__)
86
+ #define _AVR_CPU_NAME_ "ATmega323"
87
+ #elif defined (__AVR_ATmega324P__)
88
+ #define _AVR_CPU_NAME_ "ATmega324P"
89
+ #elif defined (__AVR_ATmega325__)
90
+ #define _AVR_CPU_NAME_ "ATmega325"
91
+ #elif defined (__AVR_ATmega325P__)
92
+ #define _AVR_CPU_NAME_ "ATmega325P"
93
+ #elif defined (__AVR_ATmega3250__)
94
+ #define _AVR_CPU_NAME_ "ATmega3250"
95
+ #elif defined (__AVR_ATmega3250P__)
96
+ #define _AVR_CPU_NAME_ "ATmega3250P"
97
+ #elif defined (__AVR_ATmega328P__)
98
+ #define _AVR_CPU_NAME_ "ATmega328P"
99
+ #elif defined (__AVR_ATmega329__)
100
+ #define _AVR_CPU_NAME_ "ATmega329"
101
+ #elif defined (__AVR_ATmega329P__)
102
+ #define _AVR_CPU_NAME_ "ATmega329P"
103
+ #elif defined (__AVR_ATmega3290__)
104
+ #define _AVR_CPU_NAME_ "ATmega3290"
105
+ #elif defined (__AVR_ATmega3290P__)
106
+ #define _AVR_CPU_NAME_ "ATmega3290P"
107
+ #elif defined (__AVR_ATmega32HVB__)
108
+ #define _AVR_CPU_NAME_ "ATmega32HVB"
109
+ #elif defined (__AVR_ATmega406__)
110
+ #define _AVR_CPU_NAME_ "ATmega406"
111
+ #elif defined (__AVR_ATmega16__)
112
+ #define _AVR_CPU_NAME_ "Atmega16"
113
+ #elif defined (__AVR_ATmega161__)
114
+ #define _AVR_CPU_NAME_ "ATmega161"
115
+ #elif defined (__AVR_ATmega162__)
116
+ #define _AVR_CPU_NAME_ "ATmega162"
117
+ #elif defined (__AVR_ATmega163__)
118
+ #define _AVR_CPU_NAME_ "ATmega163"
119
+ #elif defined (__AVR_ATmega164P__)
120
+ #define _AVR_CPU_NAME_ "ATmega164P"
121
+ #elif defined (__AVR_ATmega165__)
122
+ #define _AVR_CPU_NAME_ "ATmega165"
123
+ #elif defined (__AVR_ATmega165P__)
124
+ #define _AVR_CPU_NAME_ "ATmega165P"
125
+ #elif defined (__AVR_ATmega168__)
126
+ #define _AVR_CPU_NAME_ "ATmega168"
127
+ #elif defined (__AVR_ATmega168P__)
128
+ #define _AVR_CPU_NAME_ "ATmega168P"
129
+ #elif defined (__AVR_ATmega169__)
130
+ #define _AVR_CPU_NAME_ "Atmega169"
131
+ #elif defined (__AVR_ATmega169P__)
132
+ #define _AVR_CPU_NAME_ "ATmega169P"
133
+ #elif defined (__AVR_ATmega8HVA__)
134
+ #define _AVR_CPU_NAME_ "ATmega8HVA"
135
+ #elif defined (__AVR_ATmega16HVA__)
136
+ #define _AVR_CPU_NAME_ "ATmega16HVA"
137
+ #elif defined (__AVR_ATmega8__)
138
+ #define _AVR_CPU_NAME_ "ATmega8"
139
+ #elif defined (__AVR_ATmega48__)
140
+ #define _AVR_CPU_NAME_ "ATmega48"
141
+ #elif defined (__AVR_ATmega48P__)
142
+ #define _AVR_CPU_NAME_ "ATmega48P"
143
+ #elif defined (__AVR_ATmega88__)
144
+ #define _AVR_CPU_NAME_ "ATmega88"
145
+ #elif defined (__AVR_ATmega88P__)
146
+ #define _AVR_CPU_NAME_ "ATmega88P"
147
+ #elif defined (__AVR_ATmega8515__)
148
+ #define _AVR_CPU_NAME_ "ATmega8515"
149
+ #elif defined (__AVR_ATmega8535__)
150
+ #define _AVR_CPU_NAME_ "ATmega8535"
151
+ #elif defined (__AVR_AT90S8535__)
152
+ #elif defined (__AVR_AT90C8534__)
153
+ #elif defined (__AVR_AT90S8515__)
154
+ #elif defined (__AVR_AT90S4434__)
155
+ #elif defined (__AVR_AT90S4433__)
156
+ #elif defined (__AVR_AT90S4414__)
157
+ #elif defined (__AVR_ATtiny22__)
158
+ #elif defined (__AVR_ATtiny26__)
159
+ #elif defined (__AVR_AT90S2343__)
160
+ #elif defined (__AVR_AT90S2333__)
161
+ #elif defined (__AVR_AT90S2323__)
162
+ #elif defined (__AVR_AT90S2313__)
163
+ #elif defined (__AVR_ATtiny2313__)
164
+ #define _AVR_CPU_NAME_ "ATtiny2313"
165
+ #elif defined (__AVR_ATtiny13__)
166
+ #elif defined (__AVR_ATtiny13A__)
167
+ #elif defined (__AVR_ATtiny25__)
168
+ #elif defined (__AVR_ATtiny45__)
169
+ #elif defined (__AVR_ATtiny85__)
170
+ #elif defined (__AVR_ATtiny24__)
171
+ #elif defined (__AVR_ATtiny44__)
172
+ #elif defined (__AVR_ATtiny84__)
173
+ #elif defined (__AVR_ATtiny261__)
174
+ #elif defined (__AVR_ATtiny461__)
175
+ #elif defined (__AVR_ATtiny861__)
176
+ #elif defined (__AVR_ATtiny43U__)
177
+ #elif defined (__AVR_ATtiny48__)
178
+ #elif defined (__AVR_ATtiny88__)
179
+ #elif defined (__AVR_ATtiny167__)
180
+ #elif defined (__AVR_ATmega8U2__)
181
+ #define _AVR_CPU_NAME_ "ATmega8U2"
182
+ #else
183
+ #error cpu not defined
184
+ #endif
185
+
186
+
187
+ #if !defined (_AVR_CPU_NAME_)
188
+ // #define _AVR_CPU_NAME_ "UNKNOWN"
189
+ #endif
hardware/arduino/avr/bootloaders/stk500v2/avrinterruptnames.h ADDED
@@ -0,0 +1,1040 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //**************************************************************************************************
2
+ //*
3
+ //* interrupt vector names
4
+ //*
5
+ //* It is important to note that the vector numbers listed here
6
+ //* are the ATMEL documentation numbers. The Arduino numbers are 1 less
7
+ //* This is because the Atmel docs start numbering the interrupts at 1
8
+ //* when it is actually vector #0 in the table.
9
+ //**************************************************************************************************
10
+ //* Jun 1, 2010 <MLS> Added support for ATmega1281
11
+ //* Jun 30, 2010 <MLS> Putting in more ifdefs to conserve space
12
+ //* Jul 3, 2010 <MLS> More #ifdefs to conserve space and testing on most of my boards
13
+ //* Jul 4, 2010 <MLS> Started using vector defs for #ifdefs as defined in <avr/io.h>
14
+ //* Jul 13, 2010 <MLS> Added support for __AVR_ATmega128__
15
+ //* Aug 26, 2010 <MLS> Added support for __AVR_ATmega2561__
16
+ //* Sep 13, 2010 <MLS> Added support for __AVR_AT90CAN32__ __AVR_AT90CAN64__ __AVR_AT90CAN128__
17
+ //**************************************************************************************************
18
+
19
+ //#include "avrinterruptnames.h"
20
+
21
+ //**************************************************************************************************
22
+ //* this defines the interrupt vectors and allows us to compile ONLY those strings that are actually
23
+ //* in the target CPU. This way we do not have to keep making changes based on cpu, it will be
24
+ //* automatic even if we add a new CPU
25
+ #ifndef _AVR_IO_H_
26
+ #include <avr/io.h>
27
+ #endif
28
+ //**************************************************************************************************
29
+
30
+ #ifdef __MWERKS__
31
+ #define prog_char char
32
+ #define PGM_P char *
33
+ #endif
34
+
35
+ prog_char gAvrInt_RESET[] PROGMEM = "RESET";
36
+ #ifdef INT0_vect
37
+ prog_char gAvrInt_INT0[] PROGMEM = "INT0";
38
+ #endif
39
+ #ifdef INT1_vect
40
+ prog_char gAvrInt_INT1[] PROGMEM = "INT1";
41
+ #endif
42
+ #ifdef INT2_vect
43
+ prog_char gAvrInt_INT2[] PROGMEM = "INT2";
44
+ #endif
45
+ #ifdef INT3_vect
46
+ prog_char gAvrInt_INT3[] PROGMEM = "INT3";
47
+ #endif
48
+ #ifdef INT4_vect
49
+ prog_char gAvrInt_INT4[] PROGMEM = "INT4";
50
+ #endif
51
+ #ifdef INT5_vect
52
+ prog_char gAvrInt_INT5[] PROGMEM = "INT5";
53
+ #endif
54
+ #ifdef INT6_vect
55
+ prog_char gAvrInt_INT6[] PROGMEM = "INT6";
56
+ #endif
57
+ #ifdef INT7_vect
58
+ prog_char gAvrInt_INT7[] PROGMEM = "INT7";
59
+ #endif
60
+ #ifdef PCINT0_vect
61
+ prog_char gAvrInt_PCINT0[] PROGMEM = "PCINT0";
62
+ #endif
63
+ #ifdef PCINT1_vect
64
+ prog_char gAvrInt_PCINT1[] PROGMEM = "PCINT1";
65
+ #endif
66
+ #ifdef PCINT2_vect
67
+ prog_char gAvrInt_PCINT2[] PROGMEM = "PCINT2";
68
+ #endif
69
+ #ifdef PCINT3_vect
70
+ prog_char gAvrInt_PCINT3[] PROGMEM = "PCINT3";
71
+ #endif
72
+ #ifdef WDT_vect
73
+ prog_char gAvrInt_WDT[] PROGMEM = "WDT";
74
+ #endif
75
+ #ifdef TIMER0_COMP_vect
76
+ prog_char gAvrInt_TIMER0_COMP[] PROGMEM = "TIMER0 COMP";
77
+ #endif
78
+ #ifdef TIMER0_COMPA_vect
79
+ prog_char gAvrInt_TIMER0_COMPA[] PROGMEM = "TIMER0 COMPA";
80
+ #endif
81
+ #ifdef TIMER0_COMPB_vect
82
+ prog_char gAvrInt_TIMER0_COMPB[] PROGMEM = "TIMER0 COMPB";
83
+ #endif
84
+ #ifdef TIMER0_OVF_vect
85
+ prog_char gAvrInt_TIMER0_OVF[] PROGMEM = "TIMER0 OVF";
86
+ #endif
87
+ #ifdef TIMER1_CAPT_vect
88
+ prog_char gAvrInt_TIMER1_CAPT[] PROGMEM = "TIMER1 CAPT";
89
+ #endif
90
+ #ifdef TIMER1_COMPA_vect
91
+ prog_char gAvrInt_TIMER1_COMPA[] PROGMEM = "TIMER1 COMPA";
92
+ #endif
93
+ #ifdef TIMER1_COMPB_vect
94
+ prog_char gAvrInt_TIMER1_COMPB[] PROGMEM = "TIMER1 COMPB";
95
+ #endif
96
+ #ifdef TIMER1_COMPC_vect
97
+ prog_char gAvrInt_TIMER1_COMPC[] PROGMEM = "TIMER1 COMPC";
98
+ #endif
99
+ #ifdef TIMER1_OVF_vect
100
+ prog_char gAvrInt_TIMER1_OVF[] PROGMEM = "TIMER1 OVF";
101
+ #endif
102
+ #ifdef TIMER2_COMP_vect
103
+ prog_char gAvrInt_TIMER2_COMP[] PROGMEM = "TIMER2 COMP";
104
+ #endif
105
+ #ifdef TIMER2_COMPA_vect
106
+ prog_char gAvrInt_TIMER2_COMPA[] PROGMEM = "TIMER2 COMPA";
107
+ #endif
108
+ #ifdef TIMER2_COMPB_vect
109
+ prog_char gAvrInt_TIMER2_COMPB[] PROGMEM = "TIMER2 COMPB";
110
+ #endif
111
+ #ifdef TIMER2_OVF_vect
112
+ prog_char gAvrInt_TIMER2_OVF[] PROGMEM = "TIMER2 OVF";
113
+ #endif
114
+ #ifdef TIMER3_CAPT_vect
115
+ prog_char gAvrInt_TIMER3_CAPT[] PROGMEM = "TIMER3 CAPT";
116
+ #endif
117
+ #ifdef TIMER3_COMPA_vect
118
+ prog_char gAvrInt_TIMER3_COMPA[] PROGMEM = "TIMER3 COMPA";
119
+ #endif
120
+ #ifdef TIMER3_COMPB_vect
121
+ prog_char gAvrInt_TIMER3_COMPB[] PROGMEM = "TIMER3 COMPB";
122
+ #endif
123
+ #ifdef TIMER3_COMPC_vect
124
+ prog_char gAvrInt_TIMER3_COMPC[] PROGMEM = "TIMER3 COMPC";
125
+ #endif
126
+ #ifdef TIMER3_OVF_vect
127
+ prog_char gAvrInt_TIMER3_OVF[] PROGMEM = "TIMER3 OVF";
128
+ #endif
129
+ #ifdef TIMER4_CAPT_vect
130
+ prog_char gAvrInt_TIMER4_CAPT[] PROGMEM = "TIMER4 CAPT";
131
+ #endif
132
+ #ifdef TIMER4_COMPA_vect
133
+ prog_char gAvrInt_TIMER4_COMPA[] PROGMEM = "TIMER4 COMPA";
134
+ #endif
135
+ #ifdef TIMER4_COMPB_vect
136
+ prog_char gAvrInt_TIMER4_COMPB[] PROGMEM = "TIMER4 COMPB";
137
+ #endif
138
+ #ifdef TIMER4_COMPC_vect
139
+ prog_char gAvrInt_TIMER4_COMPC[] PROGMEM = "TIMER4 COMPC";
140
+ #endif
141
+ #ifdef TIMER4_COMPD_vect
142
+ prog_char gAvrInt_TIMER4_COMPD[] PROGMEM = "TIMER4 COMPD";
143
+ #endif
144
+ #ifdef TIMER4_OVF_vect
145
+ prog_char gAvrInt_TIMER4_OVF[] PROGMEM = "TIMER4 OVF";
146
+ #endif
147
+ #ifdef TIMER4_FPF_vect
148
+ prog_char gAvrInt_TIMER4_FPF[] PROGMEM = "TIMER4 Fault Protection";
149
+ #endif
150
+ #ifdef TIMER5_CAPT_vect
151
+ prog_char gAvrInt_TIMER5_CAPT[] PROGMEM = "TIMER5 CAPT";
152
+ #endif
153
+ #ifdef TIMER5_COMPA_vect
154
+ prog_char gAvrInt_TIMER5_COMPA[] PROGMEM = "TIMER5 COMPA";
155
+ #endif
156
+ #ifdef TIMER5_COMPB_vect
157
+ prog_char gAvrInt_TIMER5_COMPB[] PROGMEM = "TIMER5 COMPB";
158
+ #endif
159
+ #ifdef TIMER5_COMPC_vect
160
+ prog_char gAvrInt_TIMER5_COMPC[] PROGMEM = "TIMER5 COMPC";
161
+ #endif
162
+ #ifdef TIMER5_OVF_vect
163
+ prog_char gAvrInt_TIMER5_OVF[] PROGMEM = "TIMER5 OVF";
164
+ #endif
165
+
166
+ //* when there is only 1 usart
167
+ #if defined(USART_RX_vect) || defined(USART_RXC_vect)
168
+ prog_char gAvrInt_USART_RX[] PROGMEM = "USART RX";
169
+ #endif
170
+ #if defined(USART_UDRE_vect)
171
+ prog_char gAvrInt_USART_UDRE[] PROGMEM = "USART UDRE";
172
+ #endif
173
+ #if defined(USART_TX_vect) || defined(USART_TXC_vect)
174
+ prog_char gAvrInt_USART_TX[] PROGMEM = "USART TX";
175
+ #endif
176
+
177
+
178
+ //* usart 0
179
+ #if defined(USART0_RX_vect)
180
+ prog_char gAvrInt_USART0_RX[] PROGMEM = "USART0 RX";
181
+ #endif
182
+ #if defined(USART0_UDRE_vect)
183
+ prog_char gAvrInt_USART0_UDRE[] PROGMEM = "USART0 UDRE";
184
+ #endif
185
+ #if defined(USART0_TX_vect)
186
+ prog_char gAvrInt_USART0_TX[] PROGMEM = "USART0 TX";
187
+ #endif
188
+
189
+
190
+ //* usart 1
191
+ #ifdef USART1_RX_vect
192
+ prog_char gAvrInt_USART1_RX[] PROGMEM = "USART1 RX";
193
+ #endif
194
+ #ifdef USART1_UDRE_vect
195
+ prog_char gAvrInt_USART1_UDRE[] PROGMEM = "USART1 UDRE";
196
+ #endif
197
+ #ifdef USART1_TX_vect
198
+ prog_char gAvrInt_USART1_TX[] PROGMEM = "USART1 TX";
199
+ #endif
200
+
201
+ //* usart 2
202
+ #ifdef USART2_RX_vect
203
+ prog_char gAvrInt_USART2_RX[] PROGMEM = "USART2 RX";
204
+ #endif
205
+ #ifdef USART2_UDRE_vect
206
+ prog_char gAvrInt_USART2_UDRE[] PROGMEM = "USART2 UDRE";
207
+ #endif
208
+ #ifdef USART2_TX_vect
209
+ prog_char gAvrInt_USART2_TX[] PROGMEM = "USART2 TX";
210
+ #endif
211
+
212
+ //* usart 3
213
+ #ifdef USART3_RX_vect
214
+ prog_char gAvrInt_USART3_RX[] PROGMEM = "USART3 RX";
215
+ #endif
216
+ #ifdef USART3_UDRE_vect
217
+ prog_char gAvrInt_USART3_UDRE[] PROGMEM = "USART3 UDRE";
218
+ #endif
219
+ #ifdef USART3_TX_vect
220
+ prog_char gAvrInt_USART3_TX[] PROGMEM = "USART3 TX";
221
+ #endif
222
+ #ifdef SPI_STC_vect
223
+ prog_char gAvrInt_SPI_STC[] PROGMEM = "SPI STC";
224
+ #endif
225
+ #ifdef ADC_vect
226
+ prog_char gAvrInt_ADC[] PROGMEM = "ADC";
227
+ #endif
228
+ #if defined(ANALOG_COMP_vect) || defined(ANA_COMP_vect)
229
+ prog_char gAvrInt_ANALOG_COMP[] PROGMEM = "ANALOG COMP";
230
+ #endif
231
+ #if defined(EE_READY_vect) || defined(EE_RDY_vect)
232
+ prog_char gAvrInt_EE_READY[] PROGMEM = "EE READY";
233
+ #endif
234
+ #ifdef TWI_vect
235
+ prog_char gAvrInt_TWI[] PROGMEM = "TWI";
236
+ #endif
237
+ #if defined(SPM_READY_vect) || defined(SPM_RDY_vect)
238
+ prog_char gAvrInt_SPM_READY[] PROGMEM = "SPM READY";
239
+ #endif
240
+ #ifdef USI_START_vect
241
+ prog_char gAvrInt_USI_START[] PROGMEM = "USI START";
242
+ #endif
243
+ #ifdef USI_OVERFLOW_vect
244
+ prog_char gAvrInt_USI_OVERFLOW[] PROGMEM = "USI OVERFLOW";
245
+ #endif
246
+ #ifdef USB_GEN_vect
247
+ prog_char gAvrInt_USB_General[] PROGMEM = "USB General";
248
+ #endif
249
+ #ifdef USB_COM_vect
250
+ prog_char gAvrInt_USB_Endpoint[] PROGMEM = "USB Endpoint";
251
+ #endif
252
+
253
+ #ifdef LCD_vect
254
+ prog_char gAvrInt_LCD_StartFrame[] PROGMEM = "LCD Start of Frame";
255
+ #endif
256
+
257
+ //* these are for the chips with CAN bus support
258
+ #ifdef CANIT_vect
259
+ prog_char gAvrInt_CAN_TrafnsferCE[] PROGMEM = "CAN Transfer Complete or Error";
260
+ #endif
261
+ #ifdef OVRIT_vect
262
+ prog_char gAvrInt_CAN_TimerOverRun[] PROGMEM = "CAN Timer Overrun";
263
+ #endif
264
+
265
+ //* these are for __AVR_ATmega128RFA1__
266
+ #ifdef TRX24_PLL_LOCK_vect
267
+ prog_char gAvrInt_TRN_PLL_LOCK[] PROGMEM = "TRX24_PLL_LOCK";
268
+ #endif
269
+ #ifdef TRX24_PLL_UNLOCK_vect
270
+ prog_char gAvrInt_TRN_PLL_UNLOCK[] PROGMEM = "TRX24_PLL_UNLOCK";
271
+ #endif
272
+ #ifdef TRX24_RX_START_vect
273
+ prog_char gAvrInt_TRN_RX_START[] PROGMEM = "TRX24_RX_START";
274
+ #endif
275
+ #ifdef TRX24_RX_END_vect
276
+ prog_char gAvrInt_TRN_RX_END[] PROGMEM = "TRX24_RX_END";
277
+ #endif
278
+ #ifdef TRX24_CCA_ED_DONE_vect
279
+ prog_char gAvrInt_TRN_CAAED_DONE[] PROGMEM = "TRX24_CCA_ED_DONE";
280
+ #endif
281
+ #ifdef TRX24_XAH_AMI_vect
282
+ prog_char gAvrInt_TRN_FRAME_MATCH[] PROGMEM = "TRX24_FRAME_ADDRESS_MATCH";
283
+ #endif
284
+ #ifdef TRX24_TX_END_vect
285
+ prog_char gAvrInt_TRN_TX_END[] PROGMEM = "TRX24_TX_END";
286
+ #endif
287
+ #ifdef TRX24_AWAKE_vect
288
+ prog_char gAvrInt_TRN_AWAKE[] PROGMEM = "TRX24_AWAKE";
289
+ #endif
290
+ #ifdef SCNT_CMP1_vect
291
+ prog_char gAvrInt_SCNT_CMP1[] PROGMEM = "SCNT_CMP1";
292
+ #endif
293
+ #ifdef SCNT_CMP2_vect
294
+ prog_char gAvrInt_SCNT_CMP2[] PROGMEM = "SCNT_CMP2";
295
+ #endif
296
+ #ifdef SCNT_CMP3_vect
297
+ prog_char gAvrInt_SCNT_CMP3[] PROGMEM = "SCNT_CMP3";
298
+ #endif
299
+ #ifdef SCNT_OVFL_vect
300
+ prog_char gAvrInt_SCNT_OVFL[] PROGMEM = "SCNT_OVFL";
301
+ #endif
302
+ #ifdef SCNT_BACKOFF_vect
303
+ prog_char gAvrInt_SCNT_BACKOFF[] PROGMEM = "SCNT_BACKOFF";
304
+ #endif
305
+ #ifdef AES_READY_vect
306
+ prog_char gAvrInt_AES_READY[] PROGMEM = "AES_READY";
307
+ #endif
308
+ #ifdef BAT_LOW_vect
309
+ prog_char gAvrInt_BAT_LOW[] PROGMEM = "BAT_LOW";
310
+ #endif
311
+
312
+
313
+
314
+ //**************************************************************************************************
315
+ //* these do not have vector defs and have to be done by CPU type
316
+ #if defined(__AVR_ATmega645__ ) || defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2561__)
317
+ prog_char gAvrInt_NOT_USED[] PROGMEM = "NOT_USED";
318
+ #endif
319
+ #if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega128RFA1__)
320
+ prog_char gAvrInt_RESERVED[] PROGMEM = "Reserved";
321
+ #endif
322
+
323
+ prog_char gAvrInt_END[] PROGMEM = "*";
324
+
325
+
326
+
327
+
328
+
329
+ //**************************************************************************************************
330
+ #if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) || defined(__AVR_ATmega328__)
331
+ #pragma mark __AVR_ATmega168__ / __AVR_ATmega328P__ / __AVR_ATmega328__
332
+
333
+ #define _INTERRUPT_NAMES_DEFINED_
334
+
335
+ PGM_P gInterruptNameTable[] PROGMEM =
336
+ {
337
+
338
+ gAvrInt_RESET, // 1
339
+ gAvrInt_INT0, // 2
340
+ gAvrInt_INT1, // 3
341
+ gAvrInt_PCINT0, // 4
342
+ gAvrInt_PCINT1, // 5
343
+ gAvrInt_PCINT2, // 6
344
+ gAvrInt_WDT, // 7
345
+ gAvrInt_TIMER2_COMPA, // 8
346
+ gAvrInt_TIMER2_COMPB, // 9
347
+ gAvrInt_TIMER2_OVF, // 10
348
+ gAvrInt_TIMER1_CAPT, // 11
349
+ gAvrInt_TIMER1_COMPA, // 12
350
+ gAvrInt_TIMER1_COMPB, // 13
351
+ gAvrInt_TIMER1_OVF, // 14
352
+ gAvrInt_TIMER0_COMPA, // 15
353
+ gAvrInt_TIMER0_COMPB, // 16
354
+ gAvrInt_TIMER0_OVF, // 17
355
+ gAvrInt_SPI_STC, // 18
356
+ gAvrInt_USART_RX, // 19
357
+ gAvrInt_USART_UDRE, // 20
358
+ gAvrInt_USART_TX, // 21
359
+ gAvrInt_ADC, // 22
360
+ gAvrInt_EE_READY, // 23
361
+ gAvrInt_ANALOG_COMP, // 24
362
+ gAvrInt_TWI, // 25
363
+ gAvrInt_SPM_READY, // 26
364
+ };
365
+
366
+ #endif
367
+
368
+ //**************************************************************************************************
369
+ #if defined(__AVR_ATmega169__)
370
+ #pragma mark __AVR_ATmega169__
371
+
372
+ #define _INTERRUPT_NAMES_DEFINED_
373
+
374
+ PGM_P gInterruptNameTable[] PROGMEM =
375
+ {
376
+
377
+ gAvrInt_RESET, // 1
378
+ gAvrInt_INT0, // 2
379
+ gAvrInt_PCINT0, // 3
380
+ gAvrInt_PCINT1, // 4
381
+ gAvrInt_TIMER2_COMP, // 5
382
+ gAvrInt_TIMER2_OVF, // 6
383
+ gAvrInt_TIMER1_CAPT, // 7
384
+ gAvrInt_TIMER1_COMPA, // 8
385
+ gAvrInt_TIMER1_COMPB, // 9
386
+ gAvrInt_TIMER1_OVF, // 10
387
+ gAvrInt_TIMER0_COMP, // 11
388
+ gAvrInt_TIMER0_OVF, // 12
389
+ gAvrInt_SPI_STC, // 13
390
+ gAvrInt_USART0_RX, // 14
391
+ gAvrInt_USART0_UDRE, // 15
392
+ gAvrInt_USART0_TX, // 16
393
+ gAvrInt_USI_START, // 17
394
+ gAvrInt_USI_OVERFLOW, // 18
395
+ gAvrInt_ANALOG_COMP, // 19
396
+ gAvrInt_ADC, // 20
397
+ gAvrInt_EE_READY, // 21
398
+ gAvrInt_SPM_READY, // 22
399
+ gAvrInt_LCD_StartFrame, // 23
400
+
401
+ };
402
+
403
+ #endif
404
+
405
+
406
+ //**************************************************************************************************
407
+ #if defined(__AVR_ATmega640__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__)
408
+ #pragma mark __AVR_ATmega640__ __AVR_ATmega1280__ __AVR_ATmega1281__ __AVR_ATmega2560__ __AVR_ATmega2561__
409
+
410
+ #define _INTERRUPT_NAMES_DEFINED_
411
+
412
+ PGM_P gInterruptNameTable[] PROGMEM =
413
+ {
414
+
415
+ gAvrInt_RESET, // 1
416
+ gAvrInt_INT0, // 2
417
+ gAvrInt_INT1, // 3
418
+ gAvrInt_INT2, // 4
419
+ gAvrInt_INT3, // 5
420
+ gAvrInt_INT4, // 6
421
+ gAvrInt_INT5, // 7
422
+ gAvrInt_INT6, // 8
423
+ gAvrInt_INT7, // 9
424
+ gAvrInt_PCINT0, // 10
425
+ gAvrInt_PCINT1, // 11
426
+ #if defined(__AVR_ATmega640__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
427
+ gAvrInt_PCINT2, // 12
428
+ #else
429
+ gAvrInt_NOT_USED, // 12
430
+ #endif
431
+ gAvrInt_WDT, // 13
432
+ gAvrInt_TIMER2_COMPA, // 14
433
+ gAvrInt_TIMER2_COMPB, // 15
434
+ gAvrInt_TIMER2_OVF, // 16
435
+ gAvrInt_TIMER1_CAPT, // 17
436
+ gAvrInt_TIMER1_COMPA, // 18
437
+ gAvrInt_TIMER1_COMPB, // 19
438
+ gAvrInt_TIMER1_COMPC, // 20
439
+ gAvrInt_TIMER1_OVF, // 21
440
+ gAvrInt_TIMER0_COMPA, // 22
441
+ gAvrInt_TIMER0_COMPB, // 23
442
+ gAvrInt_TIMER0_OVF, // 24
443
+ gAvrInt_SPI_STC, // 25
444
+
445
+ gAvrInt_USART0_RX, // 26
446
+ gAvrInt_USART0_UDRE, // 27
447
+ gAvrInt_USART0_TX, // 28
448
+ gAvrInt_ANALOG_COMP, // 29
449
+ gAvrInt_ADC, // 30
450
+ gAvrInt_EE_READY, // 31
451
+
452
+ gAvrInt_TIMER3_CAPT, // 32
453
+ gAvrInt_TIMER3_COMPA, // 33
454
+ gAvrInt_TIMER3_COMPB, // 34
455
+ gAvrInt_TIMER3_COMPC, // 35
456
+ gAvrInt_TIMER3_OVF, // 36
457
+
458
+ gAvrInt_USART1_RX, // 37
459
+ gAvrInt_USART1_UDRE, // 38
460
+ gAvrInt_USART1_TX, // 39
461
+ gAvrInt_TWI, // 40
462
+ gAvrInt_SPM_READY, // 41
463
+ #if defined(__AVR_ATmega640__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
464
+ gAvrInt_TIMER4_CAPT, // 42
465
+ #else
466
+ gAvrInt_NOT_USED, // 42
467
+ #endif
468
+ gAvrInt_TIMER4_COMPA, // 43
469
+ gAvrInt_TIMER4_COMPB, // 44
470
+ gAvrInt_TIMER4_COMPC, // 45
471
+ gAvrInt_TIMER4_OVF, // 46
472
+ #if defined(__AVR_ATmega640__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
473
+ gAvrInt_TIMER5_CAPT, // 47
474
+ #else
475
+ gAvrInt_NOT_USED, // 47
476
+ #endif
477
+ gAvrInt_TIMER5_COMPA, // 48
478
+ gAvrInt_TIMER5_COMPB, // 49
479
+ gAvrInt_TIMER5_COMPC, // 50
480
+ gAvrInt_TIMER5_OVF, // 51
481
+
482
+ #if defined(__AVR_ATmega640__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
483
+ gAvrInt_USART2_RX, // 52
484
+ gAvrInt_USART2_UDRE, // 53
485
+ gAvrInt_USART2_TX, // 54
486
+
487
+ gAvrInt_USART3_RX, // 55
488
+ gAvrInt_USART3_UDRE, // 56
489
+ gAvrInt_USART3_TX, // 57
490
+ #endif
491
+
492
+ };
493
+
494
+ #endif
495
+
496
+
497
+
498
+ //**************************************************************************************************
499
+ #if defined(__AVR_ATmega324P__ ) || defined(__AVR_ATmega644__ ) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__)
500
+ #pragma mark __AVR_ATmega324P__ __AVR_ATmega644__ __AVR_ATmega644P__ __AVR_ATmega1284P__
501
+
502
+ #define _INTERRUPT_NAMES_DEFINED_
503
+
504
+ PGM_P gInterruptNameTable[] PROGMEM =
505
+ {
506
+
507
+ gAvrInt_RESET, // 1
508
+ gAvrInt_INT0, // 2
509
+ gAvrInt_INT1, // 3
510
+ gAvrInt_INT2, // 4
511
+ gAvrInt_PCINT0, // 5
512
+ gAvrInt_PCINT1, // 6
513
+ gAvrInt_PCINT2, // 7
514
+ gAvrInt_PCINT3, // 8
515
+ gAvrInt_WDT, // 9
516
+ gAvrInt_TIMER2_COMPA, // 10
517
+ gAvrInt_TIMER2_COMPB, // 11
518
+ gAvrInt_TIMER2_OVF, // 12
519
+ gAvrInt_TIMER1_CAPT, // 13
520
+ gAvrInt_TIMER1_COMPA, // 14
521
+ gAvrInt_TIMER1_COMPB, // 15
522
+ gAvrInt_TIMER1_OVF, // 16
523
+ gAvrInt_TIMER0_COMPA, // 17
524
+ gAvrInt_TIMER0_COMPB, // 18
525
+ gAvrInt_TIMER0_OVF, // 19
526
+ gAvrInt_SPI_STC, // 20
527
+ gAvrInt_USART0_RX, // 21
528
+ gAvrInt_USART0_UDRE, // 22
529
+ gAvrInt_USART0_TX, // 23
530
+ gAvrInt_ANALOG_COMP, // 24
531
+ gAvrInt_ADC, // 25
532
+ gAvrInt_EE_READY, // 26
533
+ gAvrInt_TWI, // 27
534
+ gAvrInt_SPM_READY, // 28
535
+
536
+ #if defined(__AVR_ATmega324P__ ) || defined(__AVR_ATmega644P__)
537
+ gAvrInt_USART1_RX, // 29
538
+ gAvrInt_USART1_UDRE, // 30
539
+ gAvrInt_USART1_TX, // 31
540
+ #endif
541
+
542
+ };
543
+
544
+
545
+ #endif
546
+
547
+ //**************************************************************************************************
548
+ #if defined(__AVR_ATmega1284P__ )
549
+ #pragma mark __AVR_ATmega1284P__
550
+
551
+ #define _INTERRUPT_NAMES_DEFINED_
552
+
553
+ PGM_P gInterruptNameTable[] PROGMEM =
554
+ {
555
+
556
+ gAvrInt_RESET, // 1
557
+ gAvrInt_INT0, // 2
558
+ gAvrInt_INT1, // 3
559
+ gAvrInt_INT2, // 4
560
+ gAvrInt_PCINT0, // 5
561
+ gAvrInt_PCINT1, // 6
562
+ gAvrInt_PCINT2, // 7
563
+ gAvrInt_PCINT3, // 8
564
+ gAvrInt_WDT, // 9
565
+ gAvrInt_TIMER2_COMPA, // 10
566
+ gAvrInt_TIMER2_COMPB, // 11
567
+ gAvrInt_TIMER2_OVF, // 12
568
+ gAvrInt_TIMER1_CAPT, // 13
569
+ gAvrInt_TIMER1_COMPA, // 14
570
+ gAvrInt_TIMER1_COMPB, // 15
571
+ gAvrInt_TIMER1_OVF, // 16
572
+ gAvrInt_TIMER0_COMPA, // 17
573
+ gAvrInt_TIMER0_COMPB, // 18
574
+ gAvrInt_TIMER0_OVF, // 19
575
+ gAvrInt_SPI_STC, // 20
576
+ gAvrInt_USART0_RX, // 21
577
+ gAvrInt_USART0_UDRE, // 22
578
+ gAvrInt_USART0_TX, // 23
579
+ gAvrInt_ANALOG_COMP, // 24
580
+ gAvrInt_ADC, // 25
581
+ gAvrInt_EE_READY, // 26
582
+ gAvrInt_TWI, // 27
583
+ gAvrInt_SPM_READY, // 28
584
+
585
+ gAvrInt_USART1_RX, // 29
586
+ gAvrInt_USART1_UDRE, // 30
587
+ gAvrInt_USART1_TX, // 31
588
+ //* these are NOT documented in doc8272.pdf
589
+ //* they are in iom1284p.h
590
+ gAvrInt_TIMER3_CAPT, // 32
591
+ gAvrInt_TIMER3_COMPA, // 33
592
+ gAvrInt_TIMER3_COMPB, // 34
593
+ gAvrInt_TIMER3_OVF, // 35
594
+
595
+
596
+ };
597
+
598
+
599
+ #endif
600
+
601
+
602
+ //**************************************************************************************************
603
+ #if defined(__AVR_ATmega645__ )
604
+ #pragma mark __AVR_ATmega645__
605
+
606
+ #define _INTERRUPT_NAMES_DEFINED_
607
+
608
+ PGM_P gInterruptNameTable[] PROGMEM =
609
+ {
610
+
611
+ gAvrInt_RESET, // 1
612
+ gAvrInt_INT0, // 2
613
+ gAvrInt_PCINT0, // 3
614
+ gAvrInt_PCINT1, // 4
615
+ gAvrInt_TIMER2_COMP, // 5
616
+ gAvrInt_TIMER2_OVF, // 6
617
+ gAvrInt_TIMER1_CAPT, // 7
618
+ gAvrInt_TIMER1_COMPA, // 8
619
+ gAvrInt_TIMER1_COMPB, // 9
620
+ gAvrInt_TIMER1_OVF, // 10
621
+ gAvrInt_TIMER0_COMP, // 11
622
+ gAvrInt_TIMER0_OVF, // 12
623
+ gAvrInt_SPI_STC, // 13
624
+ gAvrInt_USART0_RX, // 14
625
+ gAvrInt_USART0_UDRE, // 15
626
+ gAvrInt_USART0_TX, // 16
627
+ gAvrInt_USI_START, // 17
628
+ gAvrInt_USI_OVERFLOW, // 18
629
+ gAvrInt_ANALOG_COMP, // 19
630
+ gAvrInt_ADC, // 20
631
+ gAvrInt_EE_READY, // 21
632
+ gAvrInt_SPM_READY, // 22
633
+ gAvrInt_NOT_USED, // 23
634
+
635
+ #if defined(__AVR_ATmega3250__) || defined(__AVR_ATmega6450__)
636
+ gAvrInt_PCINT2, // 24
637
+ gAvrInt_PCINT3, // 25
638
+ #endif
639
+ };
640
+
641
+
642
+ #endif
643
+
644
+ //**************************************************************************************************
645
+ #if defined(__AVR_ATmega16__ )
646
+ #pragma mark __AVR_ATmega16__
647
+
648
+ #define _INTERRUPT_NAMES_DEFINED_
649
+
650
+ PGM_P gInterruptNameTable[] PROGMEM =
651
+ {
652
+
653
+ gAvrInt_RESET, // 1
654
+ gAvrInt_INT0, // 2
655
+ gAvrInt_INT1, // 3
656
+ gAvrInt_TIMER2_COMP, // 4
657
+ gAvrInt_TIMER2_OVF, // 5
658
+ gAvrInt_TIMER1_CAPT, // 6
659
+ gAvrInt_TIMER1_COMPA, // 7
660
+ gAvrInt_TIMER1_COMPB, // 8
661
+ gAvrInt_TIMER1_OVF, // 9
662
+ gAvrInt_TIMER0_OVF, // 10
663
+ gAvrInt_SPI_STC, // 11
664
+ gAvrInt_USART_RX, // 12
665
+ gAvrInt_USART_UDRE, // 13
666
+ gAvrInt_USART_TX, // 14
667
+ gAvrInt_ADC, // 15
668
+ gAvrInt_EE_READY, // 16
669
+ gAvrInt_ANALOG_COMP, // 17
670
+ gAvrInt_TWI, // 18
671
+ gAvrInt_INT2, // 19
672
+ gAvrInt_TIMER0_COMP, // 20
673
+ gAvrInt_SPM_READY, // 21
674
+
675
+ };
676
+
677
+
678
+ #endif
679
+
680
+ //**************************************************************************************************
681
+ #if defined(__AVR_ATmega32__ )
682
+ #pragma mark __AVR_ATmega32__
683
+
684
+ #define _INTERRUPT_NAMES_DEFINED_
685
+
686
+ PGM_P gInterruptNameTable[] PROGMEM =
687
+ {
688
+
689
+ gAvrInt_RESET, // 1
690
+ gAvrInt_INT0, // 2
691
+ gAvrInt_INT1, // 3
692
+ gAvrInt_INT2, // 4
693
+ gAvrInt_TIMER2_COMP, // 5
694
+ gAvrInt_TIMER2_OVF, // 6
695
+ gAvrInt_TIMER1_CAPT, // 7
696
+ gAvrInt_TIMER1_COMPA, // 8
697
+ gAvrInt_TIMER1_COMPB, // 9
698
+ gAvrInt_TIMER1_OVF, // 10
699
+ gAvrInt_TIMER0_COMP, // 11
700
+ gAvrInt_TIMER0_OVF, // 12
701
+ gAvrInt_SPI_STC, // 13
702
+ gAvrInt_USART_RX, // 14
703
+ gAvrInt_USART_UDRE, // 15
704
+ gAvrInt_USART_TX, // 16
705
+ gAvrInt_ADC, // 17
706
+ gAvrInt_EE_READY, // 18
707
+ gAvrInt_ANALOG_COMP, // 19
708
+ gAvrInt_TWI, // 20
709
+ gAvrInt_SPM_READY, // 21
710
+
711
+ };
712
+
713
+
714
+ #endif
715
+
716
+ //**************************************************************************************************
717
+ #if defined(__AVR_ATmega32U4__)
718
+ #pragma mark __AVR_ATmega32U4__
719
+ //* teensy 2.0
720
+ //* http://www.pjrc.com/teensy/pinout.html
721
+ #define _INTERRUPT_NAMES_DEFINED_
722
+
723
+
724
+ PGM_P gInterruptNameTable[] PROGMEM =
725
+ {
726
+
727
+ gAvrInt_RESET, // 1
728
+ gAvrInt_INT0, // 2
729
+ gAvrInt_INT1, // 3
730
+ gAvrInt_INT2, // 4
731
+ gAvrInt_INT3, // 5
732
+ gAvrInt_RESERVED, // 6
733
+ gAvrInt_RESERVED, // 7
734
+ gAvrInt_INT6, // 8
735
+ gAvrInt_RESERVED, // 9
736
+ gAvrInt_PCINT0, // 10
737
+ gAvrInt_USB_General, // 11
738
+ gAvrInt_USB_Endpoint, // 12
739
+ gAvrInt_WDT, // 13
740
+ gAvrInt_RESERVED, // 14
741
+ gAvrInt_RESERVED, // 15
742
+ gAvrInt_RESERVED, // 16
743
+ gAvrInt_TIMER1_CAPT, // 17
744
+ gAvrInt_TIMER1_COMPA, // 18
745
+ gAvrInt_TIMER1_COMPB, // 19
746
+ gAvrInt_TIMER1_COMPC, // 20
747
+ gAvrInt_TIMER1_OVF, // 21
748
+ gAvrInt_TIMER0_COMPA, // 22
749
+ gAvrInt_TIMER0_COMPB, // 23
750
+ gAvrInt_TIMER0_OVF, // 24
751
+ gAvrInt_SPI_STC, // 25
752
+
753
+ gAvrInt_USART1_RX, // 26
754
+ gAvrInt_USART1_UDRE, // 27
755
+ gAvrInt_USART1_TX, // 28
756
+ gAvrInt_ANALOG_COMP, // 29
757
+
758
+ gAvrInt_ADC, // 30
759
+ gAvrInt_EE_READY, // 31
760
+
761
+ gAvrInt_TIMER3_CAPT, // 32
762
+ gAvrInt_TIMER3_COMPA, // 33
763
+ gAvrInt_TIMER3_COMPB, // 34
764
+ gAvrInt_TIMER3_COMPC, // 35
765
+ gAvrInt_TIMER3_OVF, // 36
766
+ gAvrInt_TWI, // 37
767
+ gAvrInt_SPM_READY, // 38
768
+
769
+ gAvrInt_TIMER4_COMPA, // 39
770
+ gAvrInt_TIMER4_COMPB, // 40
771
+ gAvrInt_TIMER4_COMPD, // 41
772
+ gAvrInt_TIMER4_OVF, // 42
773
+ gAvrInt_TIMER4_FPF, // 43
774
+ };
775
+
776
+ #endif
777
+
778
+ //**************************************************************************************************
779
+ #if defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__)
780
+ #pragma mark __AVR_AT90USB1286__
781
+ //* teensy++ 2.0
782
+ //* http://www.pjrc.com/teensy/pinout.html
783
+ #define _INTERRUPT_NAMES_DEFINED_
784
+
785
+
786
+ PGM_P gInterruptNameTable[] PROGMEM =
787
+ {
788
+
789
+ gAvrInt_RESET, // 1
790
+ gAvrInt_INT0, // 2
791
+ gAvrInt_INT1, // 3
792
+ gAvrInt_INT2, // 4
793
+ gAvrInt_INT3, // 5
794
+ gAvrInt_INT4, // 6
795
+ gAvrInt_INT5, // 7
796
+ gAvrInt_INT6, // 8
797
+ gAvrInt_INT7, // 9
798
+ gAvrInt_PCINT0, // 10
799
+ gAvrInt_USB_General, // 11
800
+ gAvrInt_USB_Endpoint, // 12
801
+ gAvrInt_WDT, // 13
802
+ gAvrInt_TIMER2_COMPA, // 14
803
+ gAvrInt_TIMER2_COMPB, // 15
804
+ gAvrInt_TIMER2_OVF, // 16
805
+ gAvrInt_TIMER1_CAPT, // 17
806
+ gAvrInt_TIMER1_COMPA, // 18
807
+ gAvrInt_TIMER1_COMPB, // 19
808
+ gAvrInt_TIMER1_COMPC, // 20
809
+ gAvrInt_TIMER1_OVF, // 21
810
+ gAvrInt_TIMER0_COMPA, // 22
811
+ gAvrInt_TIMER0_COMPB, // 23
812
+ gAvrInt_TIMER0_OVF, // 24
813
+ gAvrInt_SPI_STC, // 25
814
+
815
+ gAvrInt_USART1_RX, // 26
816
+ gAvrInt_USART1_UDRE, // 27
817
+ gAvrInt_USART1_TX, // 28
818
+ gAvrInt_ANALOG_COMP, // 29
819
+
820
+ gAvrInt_ADC, // 30
821
+ gAvrInt_EE_READY, // 31
822
+
823
+ gAvrInt_TIMER3_CAPT, // 32
824
+ gAvrInt_TIMER3_COMPA, // 33
825
+ gAvrInt_TIMER3_COMPB, // 34
826
+ gAvrInt_TIMER3_COMPC, // 35
827
+ gAvrInt_TIMER3_OVF, // 36
828
+ gAvrInt_TWI, // 37
829
+ gAvrInt_SPM_READY, // 38
830
+
831
+ };
832
+
833
+ #endif
834
+
835
+
836
+
837
+
838
+ //**************************************************************************************************
839
+ #if defined(__AVR_ATmega128__) || defined(__AVR_ATmega64__)
840
+ #pragma mark __AVR_ATmega64__ __AVR_ATmega128__
841
+ #define _INTERRUPT_NAMES_DEFINED_
842
+
843
+
844
+ PGM_P gInterruptNameTable[] PROGMEM =
845
+ {
846
+
847
+ gAvrInt_RESET, // 1
848
+ gAvrInt_INT0, // 2
849
+ gAvrInt_INT1, // 3
850
+ gAvrInt_INT2, // 4
851
+ gAvrInt_INT3, // 5
852
+ gAvrInt_INT4, // 6
853
+ gAvrInt_INT5, // 7
854
+ gAvrInt_INT6, // 8
855
+ gAvrInt_INT7, // 9
856
+ gAvrInt_TIMER2_COMP, // 10
857
+ gAvrInt_TIMER2_OVF, // 11
858
+ gAvrInt_TIMER1_CAPT, // 12
859
+ gAvrInt_TIMER1_COMPA, // 13
860
+ gAvrInt_TIMER1_COMPB, // 14
861
+ gAvrInt_TIMER1_OVF, // 15
862
+ gAvrInt_TIMER0_COMP, // 16
863
+ gAvrInt_TIMER0_OVF, // 17
864
+ gAvrInt_SPI_STC, // 18
865
+ gAvrInt_USART0_RX, // 19
866
+ gAvrInt_USART0_UDRE, // 20
867
+ gAvrInt_USART0_TX, // 21
868
+ gAvrInt_ADC, // 22
869
+ gAvrInt_EE_READY, // 23
870
+ gAvrInt_ANALOG_COMP, // 24
871
+ gAvrInt_TIMER1_COMPC, // 25
872
+ gAvrInt_TIMER3_CAPT, // 26
873
+ gAvrInt_TIMER3_COMPA, // 27
874
+ gAvrInt_TIMER3_COMPB, // 28
875
+ gAvrInt_TIMER3_COMPC, // 29
876
+ gAvrInt_TIMER3_OVF, // 30
877
+ gAvrInt_USART1_RX, // 31
878
+ gAvrInt_USART1_UDRE, // 32
879
+ gAvrInt_USART1_TX, // 33
880
+ gAvrInt_TWI, // 34
881
+ gAvrInt_SPM_READY, // 35
882
+
883
+ };
884
+
885
+ #endif
886
+
887
+ //**************************************************************************************************
888
+ #if defined(__AVR_AT90CAN32__) || defined(__AVR_AT90CAN64__) || defined(__AVR_AT90CAN128__)
889
+ #pragma mark __AVR_AT90CAN32__ __AVR_AT90CAN64__ __AVR_AT90CAN128__
890
+
891
+ #define _INTERRUPT_NAMES_DEFINED_
892
+
893
+ PGM_P gInterruptNameTable[] PROGMEM =
894
+ {
895
+
896
+ gAvrInt_RESET, // 1
897
+ gAvrInt_INT0, // 2
898
+ gAvrInt_INT1, // 3
899
+ gAvrInt_INT2, // 4
900
+ gAvrInt_INT3, // 5
901
+ gAvrInt_INT4, // 6
902
+ gAvrInt_INT5, // 7
903
+ gAvrInt_INT6, // 8
904
+ gAvrInt_INT7, // 9
905
+ gAvrInt_TIMER2_COMP, // 10
906
+ gAvrInt_TIMER2_OVF, // 11
907
+ gAvrInt_TIMER1_CAPT, // 12
908
+ gAvrInt_TIMER1_COMPA, // 13
909
+ gAvrInt_TIMER1_COMPB, // 14
910
+ gAvrInt_TIMER1_COMPC, // 15
911
+ gAvrInt_TIMER1_OVF, // 16
912
+ gAvrInt_TIMER0_COMP, // 17
913
+ gAvrInt_TIMER0_OVF, // 18
914
+ gAvrInt_CAN_TrafnsferCE, // 19
915
+ gAvrInt_CAN_TimerOverRun, // 20
916
+ gAvrInt_SPI_STC, // 21
917
+ gAvrInt_USART0_RX, // 22
918
+ gAvrInt_USART0_UDRE, // 23
919
+ gAvrInt_USART0_TX, // 24
920
+ gAvrInt_ANALOG_COMP, // 25
921
+ gAvrInt_ADC, // 26
922
+ gAvrInt_EE_READY, // 27
923
+ gAvrInt_TIMER3_CAPT, // 28
924
+ gAvrInt_TIMER3_COMPA, // 29
925
+ gAvrInt_TIMER3_COMPB, // 30
926
+ gAvrInt_TIMER3_COMPC, // 31
927
+ gAvrInt_TIMER3_OVF, // 32
928
+ gAvrInt_USART1_RX, // 33
929
+ gAvrInt_USART1_UDRE, // 34
930
+ gAvrInt_USART1_TX, // 35
931
+ gAvrInt_TWI, // 36
932
+ gAvrInt_SPM_READY, // 37
933
+ };
934
+
935
+ #endif
936
+
937
+ //**************************************************************************************************
938
+ #if defined (__AVR_ATmega128RFA1__)
939
+ #pragma mark __AVR_ATmega128RFA1__
940
+ #define _INTERRUPT_NAMES_DEFINED_
941
+
942
+ PGM_P gInterruptNameTable[] PROGMEM =
943
+ {
944
+ //* Atmel changed the number scheme for interrupt vectors
945
+ gAvrInt_RESET, // 0
946
+ gAvrInt_INT0, // 1
947
+ gAvrInt_INT1, // 2
948
+ gAvrInt_INT2, // 3
949
+ gAvrInt_INT3, // 4
950
+ gAvrInt_INT4, // 5
951
+ gAvrInt_INT5, // 6
952
+ gAvrInt_INT6, // 7
953
+ gAvrInt_INT7, // 8
954
+ gAvrInt_PCINT0, // 9
955
+ gAvrInt_PCINT1, // 10
956
+ gAvrInt_PCINT2, // 11
957
+ gAvrInt_WDT, // 12
958
+ gAvrInt_TIMER2_COMPA, // 13
959
+ gAvrInt_TIMER2_COMPB, // 14
960
+ gAvrInt_TIMER2_OVF, // 15
961
+ gAvrInt_TIMER1_CAPT, // 16
962
+ gAvrInt_TIMER1_COMPA, // 17
963
+ gAvrInt_TIMER1_COMPB, // 18
964
+ gAvrInt_TIMER1_COMPC, // 19
965
+ gAvrInt_TIMER1_OVF, // 20
966
+ gAvrInt_TIMER0_COMPA, // 21
967
+ gAvrInt_TIMER0_COMPB, // 22
968
+ gAvrInt_TIMER0_OVF, // 23
969
+ gAvrInt_SPI_STC, // 24
970
+ gAvrInt_USART0_RX, // 25
971
+ gAvrInt_USART0_UDRE, // 26
972
+ gAvrInt_USART0_TX, // 27
973
+ gAvrInt_ANALOG_COMP, // 28
974
+ gAvrInt_ADC, // 29
975
+ gAvrInt_EE_READY, // 30
976
+ gAvrInt_TIMER3_CAPT, // 31
977
+ gAvrInt_TIMER3_COMPA, // 32
978
+ gAvrInt_TIMER3_COMPB, // 33
979
+ gAvrInt_TIMER3_COMPC, // 34
980
+ gAvrInt_TIMER3_OVF, // 35
981
+ gAvrInt_USART1_RX, // 36
982
+ gAvrInt_USART1_UDRE, // 37
983
+ gAvrInt_USART1_TX, // 38
984
+ gAvrInt_TWI, // 39
985
+ gAvrInt_SPM_READY, // 40
986
+ gAvrInt_TIMER4_CAPT, // 41
987
+ gAvrInt_TIMER4_COMPA, // 42
988
+ gAvrInt_TIMER4_COMPB, // 43
989
+ gAvrInt_TIMER4_COMPC, // 44
990
+ gAvrInt_TIMER4_OVF, // 45
991
+ gAvrInt_TIMER5_CAPT, // 46
992
+ gAvrInt_TIMER5_COMPA, // 47
993
+ gAvrInt_TIMER5_COMPB, // 48
994
+ gAvrInt_TIMER5_COMPC, // 49
995
+ gAvrInt_TIMER5_OVF, // 50
996
+ #if 1
997
+ gAvrInt_RESERVED, // 51
998
+ gAvrInt_RESERVED, // 52
999
+ gAvrInt_RESERVED, // 53
1000
+
1001
+ gAvrInt_RESERVED, // 54
1002
+ gAvrInt_RESERVED, // 55
1003
+ gAvrInt_RESERVED, // 56
1004
+
1005
+ #else
1006
+ gAvrInt_USART2_RX, // 51
1007
+ gAvrInt_USART2_UDRE, // 52
1008
+ gAvrInt_USART2_TX, // 53
1009
+
1010
+ gAvrInt_USART3_RX, // 54
1011
+ gAvrInt_USART3_UDRE, // 55
1012
+ gAvrInt_USART3_TX, // 56
1013
+ #endif
1014
+ gAvrInt_TRN_PLL_LOCK, // 57
1015
+ gAvrInt_TRN_PLL_UNLOCK, // 58
1016
+ gAvrInt_TRN_RX_START, // 59
1017
+ gAvrInt_TRN_RX_END, // 60
1018
+ gAvrInt_TRN_CAAED_DONE, // 61
1019
+ gAvrInt_TRN_FRAME_MATCH,// 62
1020
+ gAvrInt_TRN_TX_END, // 63
1021
+ gAvrInt_TRN_AWAKE, // 64
1022
+
1023
+ gAvrInt_SCNT_CMP1, // 65
1024
+ gAvrInt_SCNT_CMP2, // 66
1025
+ gAvrInt_SCNT_CMP3, // 67
1026
+ gAvrInt_SCNT_OVFL, // 68
1027
+ gAvrInt_SCNT_BACKOFF, // 69
1028
+ gAvrInt_AES_READY, // 70
1029
+ gAvrInt_BAT_LOW, // 71
1030
+
1031
+
1032
+ };
1033
+
1034
+ #endif
1035
+
1036
+
1037
+ #if !defined(_INTERRUPT_NAMES_DEFINED_)
1038
+ #warning No interrupt string defs for this cpu
1039
+ #endif
1040
+
hardware/arduino/avr/bootloaders/stk500v2/command.h ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //**** ATMEL AVR - A P P L I C A T I O N N O T E ************************
2
+ //*
3
+ //* Title: AVR068 - STK500 Communication Protocol
4
+ //* Filename: command.h
5
+ //* Version: 1.0
6
+ //* Last updated: 31.01.2005
7
+ //*
8
+ //* Support E-mail: avr@atmel.com
9
+ //*
10
+ //**************************************************************************
11
+
12
+ // *****************[ STK message constants ]***************************
13
+
14
+ #define MESSAGE_START 0x1B //= ESC = 27 decimal
15
+ #define TOKEN 0x0E
16
+
17
+ // *****************[ STK general command constants ]**************************
18
+
19
+ #define CMD_SIGN_ON 0x01
20
+ #define CMD_SET_PARAMETER 0x02
21
+ #define CMD_GET_PARAMETER 0x03
22
+ #define CMD_SET_DEVICE_PARAMETERS 0x04
23
+ #define CMD_OSCCAL 0x05
24
+ #define CMD_LOAD_ADDRESS 0x06
25
+ #define CMD_FIRMWARE_UPGRADE 0x07
26
+
27
+
28
+ // *****************[ STK ISP command constants ]******************************
29
+
30
+ #define CMD_ENTER_PROGMODE_ISP 0x10
31
+ #define CMD_LEAVE_PROGMODE_ISP 0x11
32
+ #define CMD_CHIP_ERASE_ISP 0x12
33
+ #define CMD_PROGRAM_FLASH_ISP 0x13
34
+ #define CMD_READ_FLASH_ISP 0x14
35
+ #define CMD_PROGRAM_EEPROM_ISP 0x15
36
+ #define CMD_READ_EEPROM_ISP 0x16
37
+ #define CMD_PROGRAM_FUSE_ISP 0x17
38
+ #define CMD_READ_FUSE_ISP 0x18
39
+ #define CMD_PROGRAM_LOCK_ISP 0x19
40
+ #define CMD_READ_LOCK_ISP 0x1A
41
+ #define CMD_READ_SIGNATURE_ISP 0x1B
42
+ #define CMD_READ_OSCCAL_ISP 0x1C
43
+ #define CMD_SPI_MULTI 0x1D
44
+
45
+ // *****************[ STK PP command constants ]*******************************
46
+
47
+ #define CMD_ENTER_PROGMODE_PP 0x20
48
+ #define CMD_LEAVE_PROGMODE_PP 0x21
49
+ #define CMD_CHIP_ERASE_PP 0x22
50
+ #define CMD_PROGRAM_FLASH_PP 0x23
51
+ #define CMD_READ_FLASH_PP 0x24
52
+ #define CMD_PROGRAM_EEPROM_PP 0x25
53
+ #define CMD_READ_EEPROM_PP 0x26
54
+ #define CMD_PROGRAM_FUSE_PP 0x27
55
+ #define CMD_READ_FUSE_PP 0x28
56
+ #define CMD_PROGRAM_LOCK_PP 0x29
57
+ #define CMD_READ_LOCK_PP 0x2A
58
+ #define CMD_READ_SIGNATURE_PP 0x2B
59
+ #define CMD_READ_OSCCAL_PP 0x2C
60
+
61
+ #define CMD_SET_CONTROL_STACK 0x2D
62
+
63
+ // *****************[ STK HVSP command constants ]*****************************
64
+
65
+ #define CMD_ENTER_PROGMODE_HVSP 0x30
66
+ #define CMD_LEAVE_PROGMODE_HVSP 0x31
67
+ #define CMD_CHIP_ERASE_HVSP 0x32
68
+ #define CMD_PROGRAM_FLASH_HVSP ` 0x33
69
+ #define CMD_READ_FLASH_HVSP 0x34
70
+ #define CMD_PROGRAM_EEPROM_HVSP 0x35
71
+ #define CMD_READ_EEPROM_HVSP 0x36
72
+ #define CMD_PROGRAM_FUSE_HVSP 0x37
73
+ #define CMD_READ_FUSE_HVSP 0x38
74
+ #define CMD_PROGRAM_LOCK_HVSP 0x39
75
+ #define CMD_READ_LOCK_HVSP 0x3A
76
+ #define CMD_READ_SIGNATURE_HVSP 0x3B
77
+ #define CMD_READ_OSCCAL_HVSP 0x3C
78
+
79
+ // *****************[ STK status constants ]***************************
80
+
81
+ // Success
82
+ #define STATUS_CMD_OK 0x00
83
+
84
+ // Warnings
85
+ #define STATUS_CMD_TOUT 0x80
86
+ #define STATUS_RDY_BSY_TOUT 0x81
87
+ #define STATUS_SET_PARAM_MISSING 0x82
88
+
89
+ // Errors
90
+ #define STATUS_CMD_FAILED 0xC0
91
+ #define STATUS_CKSUM_ERROR 0xC1
92
+ #define STATUS_CMD_UNKNOWN 0xC9
93
+
94
+ // *****************[ STK parameter constants ]***************************
95
+ #define PARAM_BUILD_NUMBER_LOW 0x80
96
+ #define PARAM_BUILD_NUMBER_HIGH 0x81
97
+ #define PARAM_HW_VER 0x90
98
+ #define PARAM_SW_MAJOR 0x91
99
+ #define PARAM_SW_MINOR 0x92
100
+ #define PARAM_VTARGET 0x94
101
+ #define PARAM_VADJUST 0x95
102
+ #define PARAM_OSC_PSCALE 0x96
103
+ #define PARAM_OSC_CMATCH 0x97
104
+ #define PARAM_SCK_DURATION 0x98
105
+ #define PARAM_TOPCARD_DETECT 0x9A
106
+ #define PARAM_STATUS 0x9C
107
+ #define PARAM_DATA 0x9D
108
+ #define PARAM_RESET_POLARITY 0x9E
109
+ #define PARAM_CONTROLLER_INIT 0x9F
110
+
111
+ // *****************[ STK answer constants ]***************************
112
+
113
+ #define ANSWER_CKSUM_ERROR 0xB0
114
+
hardware/arduino/avr/bootloaders/stk500v2/stk500boot.c ADDED
@@ -0,0 +1,2122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*****************************************************************************
2
+ Title: STK500v2 compatible bootloader
3
+ Modified for Wiring board ATMega128-16MHz
4
+ Author: Peter Fleury <pfleury@gmx.ch> http://jump.to/fleury
5
+ Compiler: avr-gcc 3.4.5 or 4.1 / avr-libc 1.4.3
6
+ Hardware: All AVRs with bootloader support, tested with ATmega8
7
+ License: GNU General Public License
8
+
9
+ Modified: Worapoht Kornkaewwattanakul <dev@avride.com> http://www.avride.com
10
+ Date: 17 October 2007
11
+ Update: 1st, 29 Dec 2007 : Enable CMD_SPI_MULTI but ignore unused command by return 0x00 byte response..
12
+ Compiler: WINAVR20060421
13
+ Description: add timeout feature like previous Wiring bootloader
14
+
15
+ DESCRIPTION:
16
+ This program allows an AVR with bootloader capabilities to
17
+ read/write its own Flash/EEprom. To enter Programming mode
18
+ an input pin is checked. If this pin is pulled low, programming mode
19
+ is entered. If not, normal execution is done from $0000
20
+ "reset" vector in Application area.
21
+ Size fits into a 1024 word bootloader section
22
+ when compiled with avr-gcc 4.1
23
+ (direct replace on Wiring Board without fuse setting changed)
24
+
25
+ USAGE:
26
+ - Set AVR MCU type and clock-frequency (F_CPU) in the Makefile.
27
+ - Set baud rate below (AVRISP only works with 115200 bps)
28
+ - compile/link the bootloader with the supplied Makefile
29
+ - program the "Boot Flash section size" (BOOTSZ fuses),
30
+ for boot-size 1024 words: program BOOTSZ01
31
+ - enable the BOOT Reset Vector (program BOOTRST)
32
+ - Upload the hex file to the AVR using any ISP programmer
33
+ - Program Boot Lock Mode 3 (program BootLock 11 and BootLock 12 lock bits) // (leave them)
34
+ - Reset your AVR while keeping PROG_PIN pulled low // (for enter bootloader by switch)
35
+ - Start AVRISP Programmer (AVRStudio/Tools/Program AVR)
36
+ - AVRISP will detect the bootloader
37
+ - Program your application FLASH file and optional EEPROM file using AVRISP
38
+
39
+ Note:
40
+ Erasing the device without flashing, through AVRISP GUI button "Erase Device"
41
+ is not implemented, due to AVRStudio limitations.
42
+ Flash is always erased before programming.
43
+
44
+ AVRdude:
45
+ Please uncomment #define REMOVE_CMD_SPI_MULTI when using AVRdude.
46
+ Comment #define REMOVE_PROGRAM_LOCK_BIT_SUPPORT to reduce code size
47
+ Read Fuse Bits and Read/Write Lock Bits is not supported
48
+
49
+ NOTES:
50
+ Based on Atmel Application Note AVR109 - Self-programming
51
+ Based on Atmel Application Note AVR068 - STK500v2 Protocol
52
+
53
+ LICENSE:
54
+ Copyright (C) 2006 Peter Fleury
55
+
56
+ This program is free software; you can redistribute it and/or modify
57
+ it under the terms of the GNU General Public License as published by
58
+ the Free Software Foundation; either version 2 of the License, or
59
+ any later version.
60
+
61
+ This program is distributed in the hope that it will be useful,
62
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
63
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
64
+ GNU General Public License for more details.
65
+
66
+ *****************************************************************************/
67
+
68
+ //************************************************************************
69
+ //* Edit History
70
+ //************************************************************************
71
+ //* Jul 7, 2010 <MLS> = Mark Sproul msproul@skycharoit.com
72
+ //* Jul 7, 2010 <MLS> Working on mega2560. No Auto-restart
73
+ //* Jul 7, 2010 <MLS> Switched to 8K bytes (4K words) so that we have room for the monitor
74
+ //* Jul 8, 2010 <MLS> Found older version of source that had auto restart, put that code back in
75
+ //* Jul 8, 2010 <MLS> Adding monitor code
76
+ //* Jul 11, 2010 <MLS> Added blinking LED while waiting for download to start
77
+ //* Jul 11, 2010 <MLS> Added EEPROM test
78
+ //* Jul 29, 2010 <MLS> Added recchar_timeout for timing out on bootloading
79
+ //* Aug 23, 2010 <MLS> Added support for atmega2561
80
+ //* Aug 26, 2010 <MLS> Removed support for BOOT_BY_SWITCH
81
+ //* Sep 8, 2010 <MLS> Added support for atmega16
82
+ //* Nov 9, 2010 <MLS> Issue 392:Fixed bug that 3 !!! in code would cause it to jump to monitor
83
+ //* Jun 24, 2011 <MLS> Removed analogRead (was not used)
84
+ //* Dec 29, 2011 <MLS> Issue 181: added watch dog timmer support
85
+ //* Dec 29, 2011 <MLS> Issue 505: bootloader is comparing the seqNum to 1 or the current sequence
86
+ //* Jan 1, 2012 <MLS> Issue 543: CMD_CHIP_ERASE_ISP now returns STATUS_CMD_FAILED instead of STATUS_CMD_OK
87
+ //* Jan 1, 2012 <MLS> Issue 543: Write EEPROM now does something (NOT TESTED)
88
+ //* Jan 1, 2012 <MLS> Issue 544: stk500v2 bootloader doesn't support reading fuses
89
+ //************************************************************************
90
+
91
+ //************************************************************************
92
+ //* these are used to test issues
93
+ //* http://code.google.com/p/arduino/issues/detail?id=505
94
+ //* Reported by mark.stubbs, Mar 14, 2011
95
+ //* The STK500V2 bootloader is comparing the seqNum to 1 or the current sequence
96
+ //* (IE: Requiring the sequence to be 1 or match seqNum before continuing).
97
+ //* The correct behavior is for the STK500V2 to accept the PC's sequence number, and echo it back for the reply message.
98
+ #define _FIX_ISSUE_505_
99
+ //************************************************************************
100
+ //* Issue 181: added watch dog timmer support
101
+ #define _FIX_ISSUE_181_
102
+
103
+ #include <inttypes.h>
104
+ #include <avr/io.h>
105
+ #include <avr/interrupt.h>
106
+ #include <avr/boot.h>
107
+ #include <avr/pgmspace.h>
108
+ #include <util/delay.h>
109
+ #include <avr/eeprom.h>
110
+ #include <avr/common.h>
111
+ #include <stdlib.h>
112
+ #include "command.h"
113
+
114
+
115
+ #if defined(_MEGA_BOARD_) || defined(_BOARD_AMBER128_) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) \
116
+ || defined(__AVR_ATmega2561__) || defined(__AVR_ATmega1284P__) || defined(ENABLE_MONITOR)
117
+ #undef ENABLE_MONITOR
118
+ #define ENABLE_MONITOR
119
+ static void RunMonitor(void);
120
+ #endif
121
+
122
+ #ifndef EEWE
123
+ #define EEWE 1
124
+ #endif
125
+ #ifndef EEMWE
126
+ #define EEMWE 2
127
+ #endif
128
+
129
+ //#define _DEBUG_SERIAL_
130
+ //#define _DEBUG_WITH_LEDS_
131
+
132
+
133
+ /*
134
+ * Uncomment the following lines to save code space
135
+ */
136
+ //#define REMOVE_PROGRAM_LOCK_BIT_SUPPORT // disable program lock bits
137
+ //#define REMOVE_BOOTLOADER_LED // no LED to show active bootloader
138
+ //#define REMOVE_CMD_SPI_MULTI // disable processing of SPI_MULTI commands, Remark this line for AVRDUDE <Worapoht>
139
+ //
140
+
141
+
142
+
143
+ //************************************************************************
144
+ //* LED on pin "PROGLED_PIN" on port "PROGLED_PORT"
145
+ //* indicates that bootloader is active
146
+ //* PG2 -> LED on Wiring board
147
+ //************************************************************************
148
+ #define BLINK_LED_WHILE_WAITING
149
+
150
+ #ifdef _MEGA_BOARD_
151
+ #define PROGLED_PORT PORTB
152
+ #define PROGLED_DDR DDRB
153
+ #define PROGLED_PIN PINB7
154
+ #elif defined( _BOARD_AMBER128_ )
155
+ //* this is for the amber 128 http://www.soc-robotics.com/
156
+ //* onbarod led is PORTE4
157
+ #define PROGLED_PORT PORTD
158
+ #define PROGLED_DDR DDRD
159
+ #define PROGLED_PIN PINE7
160
+ #elif defined( _CEREBOTPLUS_BOARD_ ) || defined(_CEREBOT_II_BOARD_)
161
+ //* this is for the Cerebot 2560 board and the Cerebot-ii
162
+ //* onbarod leds are on PORTE4-7
163
+ #define PROGLED_PORT PORTE
164
+ #define PROGLED_DDR DDRE
165
+ #define PROGLED_PIN PINE7
166
+ #elif defined( _PENGUINO_ )
167
+ //* this is for the Penguino
168
+ //* onbarod led is PORTE4
169
+ #define PROGLED_PORT PORTC
170
+ #define PROGLED_DDR DDRC
171
+ #define PROGLED_PIN PINC6
172
+ #elif defined( _ANDROID_2561_ ) || defined( __AVR_ATmega2561__ )
173
+ //* this is for the Boston Android 2561
174
+ //* onbarod led is PORTE4
175
+ #define PROGLED_PORT PORTA
176
+ #define PROGLED_DDR DDRA
177
+ #define PROGLED_PIN PINA3
178
+ #elif defined( _BOARD_MEGA16 )
179
+ //* onbarod led is PORTA7
180
+ #define PROGLED_PORT PORTA
181
+ #define PROGLED_DDR DDRA
182
+ #define PROGLED_PIN PINA7
183
+ #define UART_BAUDRATE_DOUBLE_SPEED 0
184
+
185
+ #elif defined( _BOARD_BAHBOT_ )
186
+ //* dosent have an onboard LED but this is what will probably be added to this port
187
+ #define PROGLED_PORT PORTB
188
+ #define PROGLED_DDR DDRB
189
+ #define PROGLED_PIN PINB0
190
+
191
+ #elif defined( _BOARD_ROBOTX_ )
192
+ #define PROGLED_PORT PORTB
193
+ #define PROGLED_DDR DDRB
194
+ #define PROGLED_PIN PINB6
195
+ #elif defined( _BOARD_CUSTOM1284_BLINK_B0_ )
196
+ #define PROGLED_PORT PORTB
197
+ #define PROGLED_DDR DDRB
198
+ #define PROGLED_PIN PINB0
199
+ #elif defined( _BOARD_CUSTOM1284_ )
200
+ #define PROGLED_PORT PORTD
201
+ #define PROGLED_DDR DDRD
202
+ #define PROGLED_PIN PIND5
203
+ #elif defined( _AVRLIP_ )
204
+ #define PROGLED_PORT PORTB
205
+ #define PROGLED_DDR DDRB
206
+ #define PROGLED_PIN PINB5
207
+ #elif defined( _BOARD_STK500_ )
208
+ #define PROGLED_PORT PORTA
209
+ #define PROGLED_DDR DDRA
210
+ #define PROGLED_PIN PINA7
211
+ #elif defined( _BOARD_STK502_ )
212
+ #define PROGLED_PORT PORTB
213
+ #define PROGLED_DDR DDRB
214
+ #define PROGLED_PIN PINB5
215
+ #elif defined( _BOARD_STK525_ )
216
+ #define PROGLED_PORT PORTB
217
+ #define PROGLED_DDR DDRB
218
+ #define PROGLED_PIN PINB7
219
+ #else
220
+ #define PROGLED_PORT PORTG
221
+ #define PROGLED_DDR DDRG
222
+ #define PROGLED_PIN PING2
223
+ #endif
224
+
225
+
226
+
227
+ /*
228
+ * define CPU frequency in Mhz here if not defined in Makefile
229
+ */
230
+ #ifndef F_CPU
231
+ #define F_CPU 16000000UL
232
+ #endif
233
+
234
+ #define _BLINK_LOOP_COUNT_ (F_CPU / 2250)
235
+ /*
236
+ * UART Baudrate, AVRStudio AVRISP only accepts 115200 bps
237
+ */
238
+
239
+ #ifndef BAUDRATE
240
+ #define BAUDRATE 115200
241
+ #endif
242
+
243
+ /*
244
+ * Enable (1) or disable (0) USART double speed operation
245
+ */
246
+ #ifndef UART_BAUDRATE_DOUBLE_SPEED
247
+ #if defined (__AVR_ATmega32__)
248
+ #define UART_BAUDRATE_DOUBLE_SPEED 0
249
+ #else
250
+ #define UART_BAUDRATE_DOUBLE_SPEED 1
251
+ #endif
252
+ #endif
253
+
254
+ /*
255
+ * HW and SW version, reported to AVRISP, must match version of AVRStudio
256
+ */
257
+ #define CONFIG_PARAM_BUILD_NUMBER_LOW 0
258
+ #define CONFIG_PARAM_BUILD_NUMBER_HIGH 0
259
+ #define CONFIG_PARAM_HW_VER 0x0F
260
+ #define CONFIG_PARAM_SW_MAJOR 2
261
+ #define CONFIG_PARAM_SW_MINOR 0x0A
262
+
263
+ /*
264
+ * Calculate the address where the bootloader starts from FLASHEND and BOOTSIZE
265
+ * (adjust BOOTSIZE below and BOOTLOADER_ADDRESS in Makefile if you want to change the size of the bootloader)
266
+ */
267
+ //#define BOOTSIZE 1024
268
+ #if FLASHEND > 0x0F000
269
+ #define BOOTSIZE 8192
270
+ #else
271
+ #define BOOTSIZE 2048
272
+ #endif
273
+
274
+ #define APP_END (FLASHEND -(2*BOOTSIZE) + 1)
275
+
276
+ /*
277
+ * Signature bytes are not available in avr-gcc io_xxx.h
278
+ */
279
+ #if defined (__AVR_ATmega8__)
280
+ #define SIGNATURE_BYTES 0x1E9307
281
+ #elif defined (__AVR_ATmega16__)
282
+ #define SIGNATURE_BYTES 0x1E9403
283
+ #elif defined (__AVR_ATmega32__)
284
+ #define SIGNATURE_BYTES 0x1E9502
285
+ #elif defined (__AVR_ATmega8515__)
286
+ #define SIGNATURE_BYTES 0x1E9306
287
+ #elif defined (__AVR_ATmega8535__)
288
+ #define SIGNATURE_BYTES 0x1E9308
289
+ #elif defined (__AVR_ATmega162__)
290
+ #define SIGNATURE_BYTES 0x1E9404
291
+ #elif defined (__AVR_ATmega128__)
292
+ #define SIGNATURE_BYTES 0x1E9702
293
+ #elif defined (__AVR_ATmega1280__)
294
+ #define SIGNATURE_BYTES 0x1E9703
295
+ #elif defined (__AVR_ATmega2560__)
296
+ #define SIGNATURE_BYTES 0x1E9801
297
+ #elif defined (__AVR_ATmega2561__)
298
+ #define SIGNATURE_BYTES 0x1e9802
299
+ #elif defined (__AVR_ATmega1284P__)
300
+ #define SIGNATURE_BYTES 0x1e9705
301
+ #elif defined (__AVR_ATmega640__)
302
+ #define SIGNATURE_BYTES 0x1e9608
303
+ #elif defined (__AVR_ATmega64__)
304
+ #define SIGNATURE_BYTES 0x1E9602
305
+ #elif defined (__AVR_ATmega169__)
306
+ #define SIGNATURE_BYTES 0x1e9405
307
+ #elif defined (__AVR_AT90USB1287__)
308
+ #define SIGNATURE_BYTES 0x1e9782
309
+ #else
310
+ #error "no signature definition for MCU available"
311
+ #endif
312
+
313
+
314
+ #if defined(_BOARD_ROBOTX_) || defined(__AVR_AT90USB1287__) || defined(__AVR_AT90USB1286__)
315
+ #define UART_BAUD_RATE_LOW UBRR1L
316
+ #define UART_STATUS_REG UCSR1A
317
+ #define UART_CONTROL_REG UCSR1B
318
+ #define UART_ENABLE_TRANSMITTER TXEN1
319
+ #define UART_ENABLE_RECEIVER RXEN1
320
+ #define UART_TRANSMIT_COMPLETE TXC1
321
+ #define UART_RECEIVE_COMPLETE RXC1
322
+ #define UART_DATA_REG UDR1
323
+ #define UART_DOUBLE_SPEED U2X1
324
+
325
+ #elif defined(__AVR_ATmega8__) || defined(__AVR_ATmega16__) || defined(__AVR_ATmega32__) \
326
+ || defined(__AVR_ATmega8515__) || defined(__AVR_ATmega8535__)
327
+ /* ATMega8 with one USART */
328
+ #define UART_BAUD_RATE_LOW UBRRL
329
+ #define UART_STATUS_REG UCSRA
330
+ #define UART_CONTROL_REG UCSRB
331
+ #define UART_ENABLE_TRANSMITTER TXEN
332
+ #define UART_ENABLE_RECEIVER RXEN
333
+ #define UART_TRANSMIT_COMPLETE TXC
334
+ #define UART_RECEIVE_COMPLETE RXC
335
+ #define UART_DATA_REG UDR
336
+ #define UART_DOUBLE_SPEED U2X
337
+
338
+ #elif defined(__AVR_ATmega64__) || defined(__AVR_ATmega128__) || defined(__AVR_ATmega162__) \
339
+ || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__)
340
+ /* ATMega with two USART, use UART0 */
341
+ #define UART_BAUD_RATE_LOW UBRR0L
342
+ #define UART_STATUS_REG UCSR0A
343
+ #define UART_CONTROL_REG UCSR0B
344
+ #define UART_ENABLE_TRANSMITTER TXEN0
345
+ #define UART_ENABLE_RECEIVER RXEN0
346
+ #define UART_TRANSMIT_COMPLETE TXC0
347
+ #define UART_RECEIVE_COMPLETE RXC0
348
+ #define UART_DATA_REG UDR0
349
+ #define UART_DOUBLE_SPEED U2X0
350
+ #elif defined(UBRR0L) && defined(UCSR0A) && defined(TXEN0)
351
+ /* ATMega with two USART, use UART0 */
352
+ #define UART_BAUD_RATE_LOW UBRR0L
353
+ #define UART_STATUS_REG UCSR0A
354
+ #define UART_CONTROL_REG UCSR0B
355
+ #define UART_ENABLE_TRANSMITTER TXEN0
356
+ #define UART_ENABLE_RECEIVER RXEN0
357
+ #define UART_TRANSMIT_COMPLETE TXC0
358
+ #define UART_RECEIVE_COMPLETE RXC0
359
+ #define UART_DATA_REG UDR0
360
+ #define UART_DOUBLE_SPEED U2X0
361
+ #elif defined(UBRRL) && defined(UCSRA) && defined(UCSRB) && defined(TXEN) && defined(RXEN)
362
+ //* catch all
363
+ #define UART_BAUD_RATE_LOW UBRRL
364
+ #define UART_STATUS_REG UCSRA
365
+ #define UART_CONTROL_REG UCSRB
366
+ #define UART_ENABLE_TRANSMITTER TXEN
367
+ #define UART_ENABLE_RECEIVER RXEN
368
+ #define UART_TRANSMIT_COMPLETE TXC
369
+ #define UART_RECEIVE_COMPLETE RXC
370
+ #define UART_DATA_REG UDR
371
+ #define UART_DOUBLE_SPEED U2X
372
+ #else
373
+ #error "no UART definition for MCU available"
374
+ #endif
375
+
376
+
377
+
378
+ /*
379
+ * Macro to calculate UBBR from XTAL and baudrate
380
+ */
381
+ #if defined(__AVR_ATmega32__) && UART_BAUDRATE_DOUBLE_SPEED
382
+ #define UART_BAUD_SELECT(baudRate,xtalCpu) ((xtalCpu / 4 / baudRate - 1) / 2)
383
+ #elif defined(__AVR_ATmega32__)
384
+ #define UART_BAUD_SELECT(baudRate,xtalCpu) ((xtalCpu / 8 / baudRate - 1) / 2)
385
+ #elif UART_BAUDRATE_DOUBLE_SPEED
386
+ #define UART_BAUD_SELECT(baudRate,xtalCpu) (((float)(xtalCpu))/(((float)(baudRate))*8.0)-1.0+0.5)
387
+ #else
388
+ #define UART_BAUD_SELECT(baudRate,xtalCpu) (((float)(xtalCpu))/(((float)(baudRate))*16.0)-1.0+0.5)
389
+ #endif
390
+
391
+
392
+ /*
393
+ * States used in the receive state machine
394
+ */
395
+ #define ST_START 0
396
+ #define ST_GET_SEQ_NUM 1
397
+ #define ST_MSG_SIZE_1 2
398
+ #define ST_MSG_SIZE_2 3
399
+ #define ST_GET_TOKEN 4
400
+ #define ST_GET_DATA 5
401
+ #define ST_GET_CHECK 6
402
+ #define ST_PROCESS 7
403
+
404
+ /*
405
+ * use 16bit address variable for ATmegas with <= 64K flash
406
+ */
407
+ #if defined(RAMPZ)
408
+ typedef uint32_t address_t;
409
+ #else
410
+ typedef uint16_t address_t;
411
+ #endif
412
+
413
+ /*
414
+ * function prototypes
415
+ */
416
+ static void sendchar(char c);
417
+ static unsigned char recchar(void);
418
+
419
+ /*
420
+ * since this bootloader is not linked against the avr-gcc crt1 functions,
421
+ * to reduce the code size, we need to provide our own initialization
422
+ */
423
+ void __jumpMain (void) __attribute__ ((naked)) __attribute__ ((section (".init9")));
424
+ #include <avr/sfr_defs.h>
425
+
426
+ //#define SPH_REG 0x3E
427
+ //#define SPL_REG 0x3D
428
+
429
+ //*****************************************************************************
430
+ void __jumpMain(void)
431
+ {
432
+ //* July 17, 2010 <MLS> Added stack pointer initialzation
433
+ //* the first line did not do the job on the ATmega128
434
+
435
+ asm volatile ( ".set __stack, %0" :: "i" (RAMEND) );
436
+
437
+ //* set stack pointer to top of RAM
438
+
439
+ asm volatile ( "ldi 16, %0" :: "i" (RAMEND >> 8) );
440
+ asm volatile ( "out %0,16" :: "i" (AVR_STACK_POINTER_HI_ADDR) );
441
+
442
+ asm volatile ( "ldi 16, %0" :: "i" (RAMEND & 0x0ff) );
443
+ asm volatile ( "out %0,16" :: "i" (AVR_STACK_POINTER_LO_ADDR) );
444
+
445
+ asm volatile ( "clr __zero_reg__" ); // GCC depends on register r1 set to 0
446
+ asm volatile ( "out %0, __zero_reg__" :: "I" (_SFR_IO_ADDR(SREG)) ); // set SREG to 0
447
+ asm volatile ( "jmp main"); // jump to main()
448
+ }
449
+
450
+
451
+ //*****************************************************************************
452
+ void delay_ms(unsigned int timedelay)
453
+ {
454
+ unsigned int i;
455
+ for (i=0;i<timedelay;i++)
456
+ {
457
+ _delay_ms(0.5);
458
+ }
459
+ }
460
+
461
+
462
+ //*****************************************************************************
463
+ /*
464
+ * send single byte to USART, wait until transmission is completed
465
+ */
466
+ static void sendchar(char c)
467
+ {
468
+ UART_DATA_REG = c; // prepare transmission
469
+ while (!(UART_STATUS_REG & (1 << UART_TRANSMIT_COMPLETE))); // wait until byte sent
470
+ UART_STATUS_REG |= (1 << UART_TRANSMIT_COMPLETE); // delete TXCflag
471
+ }
472
+
473
+
474
+ //************************************************************************
475
+ static int Serial_Available(void)
476
+ {
477
+ return(UART_STATUS_REG & (1 << UART_RECEIVE_COMPLETE)); // wait for data
478
+ }
479
+
480
+
481
+ //*****************************************************************************
482
+ /*
483
+ * Read single byte from USART, block if no data available
484
+ */
485
+ static unsigned char recchar(void)
486
+ {
487
+ while (!(UART_STATUS_REG & (1 << UART_RECEIVE_COMPLETE)))
488
+ {
489
+ // wait for data
490
+ }
491
+ return UART_DATA_REG;
492
+ }
493
+
494
+ #define MAX_TIME_COUNT (F_CPU >> 1)
495
+ //*****************************************************************************
496
+ static unsigned char recchar_timeout(void)
497
+ {
498
+ uint32_t count = 0;
499
+
500
+ while (!(UART_STATUS_REG & (1 << UART_RECEIVE_COMPLETE)))
501
+ {
502
+ // wait for data
503
+ count++;
504
+ if (count > MAX_TIME_COUNT)
505
+ {
506
+ unsigned int data;
507
+ #if (FLASHEND > 0x10000)
508
+ data = pgm_read_word_far(0); //* get the first word of the user program
509
+ #else
510
+ data = pgm_read_word_near(0); //* get the first word of the user program
511
+ #endif
512
+ if (data != 0xffff) //* make sure its valid before jumping to it.
513
+ {
514
+ asm volatile(
515
+ "clr r30 \n\t"
516
+ "clr r31 \n\t"
517
+ "ijmp \n\t"
518
+ );
519
+ }
520
+ count = 0;
521
+ }
522
+ }
523
+ return UART_DATA_REG;
524
+ }
525
+
526
+ //* for watch dog timer startup
527
+ void (*app_start)(void) = 0x0000;
528
+
529
+
530
+ //*****************************************************************************
531
+ int main(void)
532
+ {
533
+ address_t address = 0;
534
+ address_t eraseAddress = 0;
535
+ unsigned char msgParseState;
536
+ unsigned int ii = 0;
537
+ unsigned char checksum = 0;
538
+ unsigned char seqNum = 0;
539
+ unsigned int msgLength = 0;
540
+ unsigned char msgBuffer[285];
541
+ unsigned char c, *p;
542
+ unsigned char isLeave = 0;
543
+
544
+ unsigned long boot_timeout;
545
+ unsigned long boot_timer;
546
+ unsigned int boot_state;
547
+ #ifdef ENABLE_MONITOR
548
+ unsigned int exPointCntr = 0;
549
+ unsigned int rcvdCharCntr = 0;
550
+ #endif
551
+
552
+ //* some chips dont set the stack properly
553
+ asm volatile ( ".set __stack, %0" :: "i" (RAMEND) );
554
+ asm volatile ( "ldi 16, %0" :: "i" (RAMEND >> 8) );
555
+ asm volatile ( "out %0,16" :: "i" (AVR_STACK_POINTER_HI_ADDR) );
556
+ asm volatile ( "ldi 16, %0" :: "i" (RAMEND & 0x0ff) );
557
+ asm volatile ( "out %0,16" :: "i" (AVR_STACK_POINTER_LO_ADDR) );
558
+
559
+ #ifdef _FIX_ISSUE_181_
560
+ //************************************************************************
561
+ //* Dec 29, 2011 <MLS> Issue #181, added watch dog timmer support
562
+ //* handle the watch dog timer
563
+ uint8_t mcuStatusReg;
564
+ mcuStatusReg = MCUSR;
565
+
566
+ __asm__ __volatile__ ("cli");
567
+ __asm__ __volatile__ ("wdr");
568
+ MCUSR = 0;
569
+ WDTCSR |= _BV(WDCE) | _BV(WDE);
570
+ WDTCSR = 0;
571
+ __asm__ __volatile__ ("sei");
572
+ // check if WDT generated the reset, if so, go straight to app
573
+ if (mcuStatusReg & _BV(WDRF))
574
+ {
575
+ app_start();
576
+ }
577
+ //************************************************************************
578
+ #endif
579
+
580
+
581
+ boot_timer = 0;
582
+ boot_state = 0;
583
+
584
+ #ifdef BLINK_LED_WHILE_WAITING
585
+ // boot_timeout = 90000; //* should be about 4 seconds
586
+ // boot_timeout = 170000;
587
+ boot_timeout = 20000; //* should be about 1 second
588
+ #else
589
+ boot_timeout = 3500000; // 7 seconds , approx 2us per step when optimize "s"
590
+ #endif
591
+ /*
592
+ * Branch to bootloader or application code ?
593
+ */
594
+
595
+ #ifndef REMOVE_BOOTLOADER_LED
596
+ /* PROG_PIN pulled low, indicate with LED that bootloader is active */
597
+ PROGLED_DDR |= (1<<PROGLED_PIN);
598
+ // PROGLED_PORT &= ~(1<<PROGLED_PIN); // active low LED ON
599
+ PROGLED_PORT |= (1<<PROGLED_PIN); // active high LED ON
600
+
601
+ #ifdef _DEBUG_WITH_LEDS_
602
+ for (ii=0; ii<3; ii++)
603
+ {
604
+ PROGLED_PORT &= ~(1<<PROGLED_PIN); // turn LED off
605
+ delay_ms(100);
606
+ PROGLED_PORT |= (1<<PROGLED_PIN); // turn LED on
607
+ delay_ms(100);
608
+ }
609
+ #endif
610
+
611
+ #endif
612
+ /*
613
+ * Init UART
614
+ * set baudrate and enable USART receiver and transmiter without interrupts
615
+ */
616
+ #if UART_BAUDRATE_DOUBLE_SPEED
617
+ UART_STATUS_REG |= (1 <<UART_DOUBLE_SPEED);
618
+ #endif
619
+ UART_BAUD_RATE_LOW = UART_BAUD_SELECT(BAUDRATE,F_CPU);
620
+ UART_CONTROL_REG = (1 << UART_ENABLE_RECEIVER) | (1 << UART_ENABLE_TRANSMITTER);
621
+
622
+ asm volatile ("nop"); // wait until port has changed
623
+
624
+ #ifdef _DEBUG_SERIAL_
625
+ // delay_ms(500);
626
+
627
+ sendchar('s');
628
+ sendchar('t');
629
+ sendchar('k');
630
+ // sendchar('5');
631
+ // sendchar('0');
632
+ // sendchar('0');
633
+ sendchar('v');
634
+ sendchar('2');
635
+ sendchar(0x0d);
636
+ sendchar(0x0a);
637
+
638
+ delay_ms(100);
639
+ #endif
640
+
641
+ while (boot_state==0)
642
+ {
643
+ while ((!(Serial_Available())) && (boot_state == 0)) // wait for data
644
+ {
645
+ _delay_ms(0.001);
646
+ boot_timer++;
647
+ if (boot_timer > boot_timeout)
648
+ {
649
+ boot_state = 1; // (after ++ -> boot_state=2 bootloader timeout, jump to main 0x00000 )
650
+ }
651
+ #ifdef BLINK_LED_WHILE_WAITING
652
+ if ((boot_timer % _BLINK_LOOP_COUNT_) == 0)
653
+ {
654
+ //* toggle the LED
655
+ PROGLED_PORT ^= (1<<PROGLED_PIN); // turn LED ON
656
+ }
657
+ #endif
658
+ }
659
+ boot_state++; // ( if boot_state=1 bootloader received byte from UART, enter bootloader mode)
660
+ }
661
+
662
+
663
+ if (boot_state==1)
664
+ {
665
+ //* main loop
666
+ while (!isLeave)
667
+ {
668
+ /*
669
+ * Collect received bytes to a complete message
670
+ */
671
+ msgParseState = ST_START;
672
+ while ( msgParseState != ST_PROCESS )
673
+ {
674
+ if (boot_state==1)
675
+ {
676
+ boot_state = 0;
677
+ c = UART_DATA_REG;
678
+ }
679
+ else
680
+ {
681
+ // c = recchar();
682
+ c = recchar_timeout();
683
+
684
+ }
685
+
686
+ #ifdef ENABLE_MONITOR
687
+ rcvdCharCntr++;
688
+
689
+ if ((c == '!') && (rcvdCharCntr < 10))
690
+ {
691
+ exPointCntr++;
692
+ if (exPointCntr == 3)
693
+ {
694
+ RunMonitor();
695
+ exPointCntr = 0; // reset back to zero so we dont get in an endless loop
696
+ isLeave = 1;
697
+ msgParseState = 99; //* we dont want it do anything
698
+ break;
699
+ }
700
+ }
701
+ else
702
+ {
703
+ exPointCntr = 0;
704
+ }
705
+ #endif
706
+
707
+ switch (msgParseState)
708
+ {
709
+ case ST_START:
710
+ if ( c == MESSAGE_START )
711
+ {
712
+ msgParseState = ST_GET_SEQ_NUM;
713
+ checksum = MESSAGE_START^0;
714
+ }
715
+ break;
716
+
717
+ case ST_GET_SEQ_NUM:
718
+ #ifdef _FIX_ISSUE_505_
719
+ seqNum = c;
720
+ msgParseState = ST_MSG_SIZE_1;
721
+ checksum ^= c;
722
+ #else
723
+ if ( (c == 1) || (c == seqNum) )
724
+ {
725
+ seqNum = c;
726
+ msgParseState = ST_MSG_SIZE_1;
727
+ checksum ^= c;
728
+ }
729
+ else
730
+ {
731
+ msgParseState = ST_START;
732
+ }
733
+ #endif
734
+ break;
735
+
736
+ case ST_MSG_SIZE_1:
737
+ msgLength = c<<8;
738
+ msgParseState = ST_MSG_SIZE_2;
739
+ checksum ^= c;
740
+ break;
741
+
742
+ case ST_MSG_SIZE_2:
743
+ msgLength |= c;
744
+ msgParseState = ST_GET_TOKEN;
745
+ checksum ^= c;
746
+ break;
747
+
748
+ case ST_GET_TOKEN:
749
+ if ( c == TOKEN )
750
+ {
751
+ msgParseState = ST_GET_DATA;
752
+ checksum ^= c;
753
+ ii = 0;
754
+ }
755
+ else
756
+ {
757
+ msgParseState = ST_START;
758
+ }
759
+ break;
760
+
761
+ case ST_GET_DATA:
762
+ msgBuffer[ii++] = c;
763
+ checksum ^= c;
764
+ if (ii == msgLength )
765
+ {
766
+ msgParseState = ST_GET_CHECK;
767
+ }
768
+ break;
769
+
770
+ case ST_GET_CHECK:
771
+ if ( c == checksum )
772
+ {
773
+ msgParseState = ST_PROCESS;
774
+ }
775
+ else
776
+ {
777
+ msgParseState = ST_START;
778
+ }
779
+ break;
780
+ } // switch
781
+ } // while(msgParseState)
782
+
783
+ /*
784
+ * Now process the STK500 commands, see Atmel Appnote AVR068
785
+ */
786
+
787
+ switch (msgBuffer[0])
788
+ {
789
+ #ifndef REMOVE_CMD_SPI_MULTI
790
+ case CMD_SPI_MULTI:
791
+ {
792
+ unsigned char answerByte;
793
+ unsigned char flag=0;
794
+
795
+ if ( msgBuffer[4]== 0x30 )
796
+ {
797
+ unsigned char signatureIndex = msgBuffer[6];
798
+
799
+ if ( signatureIndex == 0 )
800
+ {
801
+ answerByte = (SIGNATURE_BYTES >> 16) & 0x000000FF;
802
+ }
803
+ else if ( signatureIndex == 1 )
804
+ {
805
+ answerByte = (SIGNATURE_BYTES >> 8) & 0x000000FF;
806
+ }
807
+ else
808
+ {
809
+ answerByte = SIGNATURE_BYTES & 0x000000FF;
810
+ }
811
+ }
812
+ else if ( msgBuffer[4] & 0x50 )
813
+ {
814
+ //* Issue 544: stk500v2 bootloader doesn't support reading fuses
815
+ //* I cant find the docs that say what these are supposed to be but this was figured out by trial and error
816
+ // answerByte = boot_lock_fuse_bits_get(GET_LOW_FUSE_BITS);
817
+ // answerByte = boot_lock_fuse_bits_get(GET_HIGH_FUSE_BITS);
818
+ // answerByte = boot_lock_fuse_bits_get(GET_EXTENDED_FUSE_BITS);
819
+ if (msgBuffer[4] == 0x50)
820
+ {
821
+ answerByte = boot_lock_fuse_bits_get(GET_LOW_FUSE_BITS);
822
+ }
823
+ else if (msgBuffer[4] == 0x58)
824
+ {
825
+ answerByte = boot_lock_fuse_bits_get(GET_HIGH_FUSE_BITS);
826
+ }
827
+ else
828
+ {
829
+ answerByte = 0;
830
+ }
831
+ }
832
+ else
833
+ {
834
+ answerByte = 0; // for all others command are not implemented, return dummy value for AVRDUDE happy <Worapoht>
835
+ }
836
+ if ( !flag )
837
+ {
838
+ msgLength = 7;
839
+ msgBuffer[1] = STATUS_CMD_OK;
840
+ msgBuffer[2] = 0;
841
+ msgBuffer[3] = msgBuffer[4];
842
+ msgBuffer[4] = 0;
843
+ msgBuffer[5] = answerByte;
844
+ msgBuffer[6] = STATUS_CMD_OK;
845
+ }
846
+ }
847
+ break;
848
+ #endif
849
+ case CMD_SIGN_ON:
850
+ msgLength = 11;
851
+ msgBuffer[1] = STATUS_CMD_OK;
852
+ msgBuffer[2] = 8;
853
+ msgBuffer[3] = 'A';
854
+ msgBuffer[4] = 'V';
855
+ msgBuffer[5] = 'R';
856
+ msgBuffer[6] = 'I';
857
+ msgBuffer[7] = 'S';
858
+ msgBuffer[8] = 'P';
859
+ msgBuffer[9] = '_';
860
+ msgBuffer[10] = '2';
861
+ break;
862
+
863
+ case CMD_GET_PARAMETER:
864
+ {
865
+ unsigned char value;
866
+
867
+ switch(msgBuffer[1])
868
+ {
869
+ case PARAM_BUILD_NUMBER_LOW:
870
+ value = CONFIG_PARAM_BUILD_NUMBER_LOW;
871
+ break;
872
+ case PARAM_BUILD_NUMBER_HIGH:
873
+ value = CONFIG_PARAM_BUILD_NUMBER_HIGH;
874
+ break;
875
+ case PARAM_HW_VER:
876
+ value = CONFIG_PARAM_HW_VER;
877
+ break;
878
+ case PARAM_SW_MAJOR:
879
+ value = CONFIG_PARAM_SW_MAJOR;
880
+ break;
881
+ case PARAM_SW_MINOR:
882
+ value = CONFIG_PARAM_SW_MINOR;
883
+ break;
884
+ default:
885
+ value = 0;
886
+ break;
887
+ }
888
+ msgLength = 3;
889
+ msgBuffer[1] = STATUS_CMD_OK;
890
+ msgBuffer[2] = value;
891
+ }
892
+ break;
893
+
894
+ case CMD_LEAVE_PROGMODE_ISP:
895
+ isLeave = 1;
896
+ //* fall thru
897
+
898
+ case CMD_SET_PARAMETER:
899
+ case CMD_ENTER_PROGMODE_ISP:
900
+ msgLength = 2;
901
+ msgBuffer[1] = STATUS_CMD_OK;
902
+ break;
903
+
904
+ case CMD_READ_SIGNATURE_ISP:
905
+ {
906
+ unsigned char signatureIndex = msgBuffer[4];
907
+ unsigned char signature;
908
+
909
+ if ( signatureIndex == 0 )
910
+ signature = (SIGNATURE_BYTES >>16) & 0x000000FF;
911
+ else if ( signatureIndex == 1 )
912
+ signature = (SIGNATURE_BYTES >> 8) & 0x000000FF;
913
+ else
914
+ signature = SIGNATURE_BYTES & 0x000000FF;
915
+
916
+ msgLength = 4;
917
+ msgBuffer[1] = STATUS_CMD_OK;
918
+ msgBuffer[2] = signature;
919
+ msgBuffer[3] = STATUS_CMD_OK;
920
+ }
921
+ break;
922
+
923
+ case CMD_READ_LOCK_ISP:
924
+ msgLength = 4;
925
+ msgBuffer[1] = STATUS_CMD_OK;
926
+ msgBuffer[2] = boot_lock_fuse_bits_get( GET_LOCK_BITS );
927
+ msgBuffer[3] = STATUS_CMD_OK;
928
+ break;
929
+
930
+ case CMD_READ_FUSE_ISP:
931
+ {
932
+ unsigned char fuseBits;
933
+
934
+ if ( msgBuffer[2] == 0x50 )
935
+ {
936
+ if ( msgBuffer[3] == 0x08 )
937
+ fuseBits = boot_lock_fuse_bits_get( GET_EXTENDED_FUSE_BITS );
938
+ else
939
+ fuseBits = boot_lock_fuse_bits_get( GET_LOW_FUSE_BITS );
940
+ }
941
+ else
942
+ {
943
+ fuseBits = boot_lock_fuse_bits_get( GET_HIGH_FUSE_BITS );
944
+ }
945
+ msgLength = 4;
946
+ msgBuffer[1] = STATUS_CMD_OK;
947
+ msgBuffer[2] = fuseBits;
948
+ msgBuffer[3] = STATUS_CMD_OK;
949
+ }
950
+ break;
951
+
952
+ #ifndef REMOVE_PROGRAM_LOCK_BIT_SUPPORT
953
+ case CMD_PROGRAM_LOCK_ISP:
954
+ {
955
+ unsigned char lockBits = msgBuffer[4];
956
+
957
+ lockBits = (~lockBits) & 0x3C; // mask BLBxx bits
958
+ boot_lock_bits_set(lockBits); // and program it
959
+ boot_spm_busy_wait();
960
+
961
+ msgLength = 3;
962
+ msgBuffer[1] = STATUS_CMD_OK;
963
+ msgBuffer[2] = STATUS_CMD_OK;
964
+ }
965
+ break;
966
+ #endif
967
+ case CMD_CHIP_ERASE_ISP:
968
+ eraseAddress = 0;
969
+ msgLength = 2;
970
+ // msgBuffer[1] = STATUS_CMD_OK;
971
+ msgBuffer[1] = STATUS_CMD_FAILED; //* isue 543, return FAILED instead of OK
972
+ break;
973
+
974
+ case CMD_LOAD_ADDRESS:
975
+ #if defined(RAMPZ)
976
+ address = ( ((address_t)(msgBuffer[1])<<24)|((address_t)(msgBuffer[2])<<16)|((address_t)(msgBuffer[3])<<8)|(msgBuffer[4]) )<<1;
977
+ #else
978
+ address = ( ((msgBuffer[3])<<8)|(msgBuffer[4]) )<<1; //convert word to byte address
979
+ #endif
980
+ msgLength = 2;
981
+ msgBuffer[1] = STATUS_CMD_OK;
982
+ break;
983
+
984
+ case CMD_PROGRAM_FLASH_ISP:
985
+ case CMD_PROGRAM_EEPROM_ISP:
986
+ {
987
+ unsigned int size = ((msgBuffer[1])<<8) | msgBuffer[2];
988
+ unsigned char *p = msgBuffer+10;
989
+ unsigned int data;
990
+ unsigned char highByte, lowByte;
991
+ address_t tempaddress = address;
992
+
993
+
994
+ if ( msgBuffer[0] == CMD_PROGRAM_FLASH_ISP )
995
+ {
996
+ // erase only main section (bootloader protection)
997
+ if (eraseAddress < APP_END )
998
+ {
999
+ boot_page_erase(eraseAddress); // Perform page erase
1000
+ boot_spm_busy_wait(); // Wait until the memory is erased.
1001
+ eraseAddress += SPM_PAGESIZE; // point to next page to be erase
1002
+ }
1003
+
1004
+ /* Write FLASH */
1005
+ do {
1006
+ lowByte = *p++;
1007
+ highByte = *p++;
1008
+
1009
+ data = (highByte << 8) | lowByte;
1010
+ boot_page_fill(address,data);
1011
+
1012
+ address = address + 2; // Select next word in memory
1013
+ size -= 2; // Reduce number of bytes to write by two
1014
+ } while (size); // Loop until all bytes written
1015
+
1016
+ boot_page_write(tempaddress);
1017
+ boot_spm_busy_wait();
1018
+ boot_rww_enable(); // Re-enable the RWW section
1019
+ }
1020
+ else
1021
+ {
1022
+ //* issue 543, this should work, It has not been tested.
1023
+ uint16_t ii = address >> 1;
1024
+ /* write EEPROM */
1025
+ while (size) {
1026
+ eeprom_write_byte((uint8_t*)ii, *p++);
1027
+ address+=2; // Select next EEPROM byte
1028
+ ii++;
1029
+ size--;
1030
+ }
1031
+ }
1032
+ msgLength = 2;
1033
+ msgBuffer[1] = STATUS_CMD_OK;
1034
+ }
1035
+ break;
1036
+
1037
+ case CMD_READ_FLASH_ISP:
1038
+ case CMD_READ_EEPROM_ISP:
1039
+ {
1040
+ unsigned int size = ((msgBuffer[1])<<8) | msgBuffer[2];
1041
+ unsigned char *p = msgBuffer+1;
1042
+ msgLength = size+3;
1043
+
1044
+ *p++ = STATUS_CMD_OK;
1045
+ if (msgBuffer[0] == CMD_READ_FLASH_ISP )
1046
+ {
1047
+ unsigned int data;
1048
+
1049
+ // Read FLASH
1050
+ do {
1051
+ //#if defined(RAMPZ)
1052
+ #if (FLASHEND > 0x10000)
1053
+ data = pgm_read_word_far(address);
1054
+ #else
1055
+ data = pgm_read_word_near(address);
1056
+ #endif
1057
+ *p++ = (unsigned char)data; //LSB
1058
+ *p++ = (unsigned char)(data >> 8); //MSB
1059
+ address += 2; // Select next word in memory
1060
+ size -= 2;
1061
+ }while (size);
1062
+ }
1063
+ else
1064
+ {
1065
+ /* Read EEPROM */
1066
+ do {
1067
+ EEARL = address; // Setup EEPROM address
1068
+ EEARH = ((address >> 8));
1069
+ address++; // Select next EEPROM byte
1070
+ EECR |= (1<<EERE); // Read EEPROM
1071
+ *p++ = EEDR; // Send EEPROM data
1072
+ size--;
1073
+ } while (size);
1074
+ }
1075
+ *p++ = STATUS_CMD_OK;
1076
+ }
1077
+ break;
1078
+
1079
+ default:
1080
+ msgLength = 2;
1081
+ msgBuffer[1] = STATUS_CMD_FAILED;
1082
+ break;
1083
+ }
1084
+
1085
+ /*
1086
+ * Now send answer message back
1087
+ */
1088
+ sendchar(MESSAGE_START);
1089
+ checksum = MESSAGE_START^0;
1090
+
1091
+ sendchar(seqNum);
1092
+ checksum ^= seqNum;
1093
+
1094
+ c = ((msgLength>>8)&0xFF);
1095
+ sendchar(c);
1096
+ checksum ^= c;
1097
+
1098
+ c = msgLength&0x00FF;
1099
+ sendchar(c);
1100
+ checksum ^= c;
1101
+
1102
+ sendchar(TOKEN);
1103
+ checksum ^= TOKEN;
1104
+
1105
+ p = msgBuffer;
1106
+ while ( msgLength )
1107
+ {
1108
+ c = *p++;
1109
+ sendchar(c);
1110
+ checksum ^=c;
1111
+ msgLength--;
1112
+ }
1113
+ sendchar(checksum);
1114
+ seqNum++;
1115
+
1116
+ #ifndef REMOVE_BOOTLOADER_LED
1117
+ //* <MLS> toggle the LED
1118
+ PROGLED_PORT ^= (1<<PROGLED_PIN); // active high LED ON
1119
+ #endif
1120
+
1121
+ }
1122
+ }
1123
+
1124
+ #ifdef _DEBUG_WITH_LEDS_
1125
+ //* this is for debugging it can be removed
1126
+ for (ii=0; ii<10; ii++)
1127
+ {
1128
+ PROGLED_PORT &= ~(1<<PROGLED_PIN); // turn LED off
1129
+ delay_ms(200);
1130
+ PROGLED_PORT |= (1<<PROGLED_PIN); // turn LED on
1131
+ delay_ms(200);
1132
+ }
1133
+ PROGLED_PORT &= ~(1<<PROGLED_PIN); // turn LED off
1134
+ #endif
1135
+
1136
+ #ifdef _DEBUG_SERIAL_
1137
+ sendchar('j');
1138
+ // sendchar('u');
1139
+ // sendchar('m');
1140
+ // sendchar('p');
1141
+ // sendchar(' ');
1142
+ // sendchar('u');
1143
+ // sendchar('s');
1144
+ // sendchar('r');
1145
+ sendchar(0x0d);
1146
+ sendchar(0x0a);
1147
+
1148
+ delay_ms(100);
1149
+ #endif
1150
+
1151
+
1152
+ #ifndef REMOVE_BOOTLOADER_LED
1153
+ PROGLED_DDR &= ~(1<<PROGLED_PIN); // set to default
1154
+ PROGLED_PORT &= ~(1<<PROGLED_PIN); // active low LED OFF
1155
+ // PROGLED_PORT |= (1<<PROGLED_PIN); // active high LED OFf
1156
+ delay_ms(100); // delay after exit
1157
+ #endif
1158
+
1159
+
1160
+ asm volatile ("nop"); // wait until port has changed
1161
+
1162
+ /*
1163
+ * Now leave bootloader
1164
+ */
1165
+
1166
+ UART_STATUS_REG &= 0xfd;
1167
+ boot_rww_enable(); // enable application section
1168
+
1169
+
1170
+ asm volatile(
1171
+ "clr r30 \n\t"
1172
+ "clr r31 \n\t"
1173
+ "ijmp \n\t"
1174
+ );
1175
+ // asm volatile ( "push r1" "\n\t" // Jump to Reset vector in Application Section
1176
+ // "push r1" "\n\t"
1177
+ // "ret" "\n\t"
1178
+ // ::);
1179
+
1180
+ /*
1181
+ * Never return to stop GCC to generate exit return code
1182
+ * Actually we will never reach this point, but the compiler doesn't
1183
+ * understand this
1184
+ */
1185
+ for(;;);
1186
+ }
1187
+
1188
+ /*
1189
+ base address = f800
1190
+
1191
+ avrdude: Device signature = 0x1e9703
1192
+ avrdude: safemode: lfuse reads as FF
1193
+ avrdude: safemode: hfuse reads as DA
1194
+ avrdude: safemode: efuse reads as F5
1195
+ avrdude>
1196
+
1197
+
1198
+ base address = f000
1199
+ avrdude: Device signature = 0x1e9703
1200
+ avrdude: safemode: lfuse reads as FF
1201
+ avrdude: safemode: hfuse reads as D8
1202
+ avrdude: safemode: efuse reads as F5
1203
+ avrdude>
1204
+ */
1205
+
1206
+ //************************************************************************
1207
+ #ifdef ENABLE_MONITOR
1208
+ #include <math.h>
1209
+
1210
+ unsigned long gRamIndex;
1211
+ unsigned long gFlashIndex;
1212
+ unsigned long gEepromIndex;
1213
+
1214
+
1215
+ #define true 1
1216
+ #define false 0
1217
+
1218
+ #include "avr_cpunames.h"
1219
+
1220
+ #ifndef _AVR_CPU_NAME_
1221
+ #error cpu name not defined
1222
+ #endif
1223
+
1224
+ #ifdef _VECTORS_SIZE
1225
+ #define kInterruptVectorCount (_VECTORS_SIZE / 4)
1226
+ #else
1227
+ #define kInterruptVectorCount 23
1228
+ #endif
1229
+
1230
+
1231
+ void PrintDecInt(int theNumber, int digitCnt);
1232
+
1233
+ #ifdef _AVR_CPU_NAME_
1234
+ const char gTextMsg_CPU_Name[] PROGMEM = _AVR_CPU_NAME_;
1235
+ #else
1236
+ const char gTextMsg_CPU_Name[] PROGMEM = "UNKNOWN";
1237
+ #endif
1238
+
1239
+ const char gTextMsg_Explorer[] PROGMEM = "Arduino explorer stk500V2 by MLS";
1240
+ const char gTextMsg_Prompt[] PROGMEM = "Bootloader>";
1241
+ const char gTextMsg_HUH[] PROGMEM = "Huh?";
1242
+ const char gTextMsg_COMPILED_ON[] PROGMEM = "Compiled on = ";
1243
+ const char gTextMsg_CPU_Type[] PROGMEM = "CPU Type = ";
1244
+ const char gTextMsg_AVR_ARCH[] PROGMEM = "__AVR_ARCH__= ";
1245
+ const char gTextMsg_AVR_LIBC[] PROGMEM = "AVR LibC Ver= ";
1246
+ const char gTextMsg_GCC_VERSION[] PROGMEM = "GCC Version = ";
1247
+ const char gTextMsg_CPU_SIGNATURE[] PROGMEM = "CPU ID = ";
1248
+ const char gTextMsg_FUSE_BYTE_LOW[] PROGMEM = "Low fuse = ";
1249
+ const char gTextMsg_FUSE_BYTE_HIGH[] PROGMEM = "High fuse = ";
1250
+ const char gTextMsg_FUSE_BYTE_EXT[] PROGMEM = "Ext fuse = ";
1251
+ const char gTextMsg_FUSE_BYTE_LOCK[] PROGMEM = "Lock fuse = ";
1252
+ const char gTextMsg_GCC_DATE_STR[] PROGMEM = __DATE__;
1253
+ const char gTextMsg_AVR_LIBC_VER_STR[] PROGMEM = __AVR_LIBC_VERSION_STRING__;
1254
+ const char gTextMsg_GCC_VERSION_STR[] PROGMEM = __VERSION__;
1255
+ const char gTextMsg_VECTOR_HEADER[] PROGMEM = "V# ADDR op code instruction addr Interrupt";
1256
+ const char gTextMsg_noVector[] PROGMEM = "no vector";
1257
+ const char gTextMsg_rjmp[] PROGMEM = "rjmp ";
1258
+ const char gTextMsg_jmp[] PROGMEM = "jmp ";
1259
+ const char gTextMsg_WHAT_PORT[] PROGMEM = "What port:";
1260
+ const char gTextMsg_PortNotSupported[] PROGMEM = "Port not supported";
1261
+ const char gTextMsg_MustBeLetter[] PROGMEM = "Must be a letter";
1262
+ const char gTextMsg_SPACE[] PROGMEM = " ";
1263
+ const char gTextMsg_WriteToEEprom[] PROGMEM = "Writting EE";
1264
+ const char gTextMsg_ReadingEEprom[] PROGMEM = "Reading EE";
1265
+ const char gTextMsg_EEPROMerrorCnt[] PROGMEM = "EE err cnt=";
1266
+ const char gTextMsg_PORT[] PROGMEM = "PORT";
1267
+
1268
+
1269
+ //************************************************************************
1270
+ //* Help messages
1271
+ const char gTextMsg_HELP_MSG_0[] PROGMEM = "0=Zero addr";
1272
+ const char gTextMsg_HELP_MSG_QM[] PROGMEM = "?=CPU stats";
1273
+ const char gTextMsg_HELP_MSG_AT[] PROGMEM = "@=EEPROM test";
1274
+ const char gTextMsg_HELP_MSG_B[] PROGMEM = "B=Blink LED";
1275
+ const char gTextMsg_HELP_MSG_E[] PROGMEM = "E=Dump EEPROM";
1276
+ const char gTextMsg_HELP_MSG_F[] PROGMEM = "F=Dump FLASH";
1277
+ const char gTextMsg_HELP_MSG_H[] PROGMEM = "H=Help";
1278
+ const char gTextMsg_HELP_MSG_L[] PROGMEM = "L=List I/O Ports";
1279
+ // const char gTextMsg_HELP_MSG_Q[] PROGMEM = "Q=Quit & jump to user pgm";
1280
+ const char gTextMsg_HELP_MSG_Q[] PROGMEM = "Q=Quit";
1281
+ const char gTextMsg_HELP_MSG_R[] PROGMEM = "R=Dump RAM";
1282
+ const char gTextMsg_HELP_MSG_V[] PROGMEM = "V=show interrupt Vectors";
1283
+ const char gTextMsg_HELP_MSG_Y[] PROGMEM = "Y=Port blink";
1284
+
1285
+ const char gTextMsg_END[] PROGMEM = "*";
1286
+
1287
+
1288
+ //************************************************************************
1289
+ void PrintFromPROGMEM(const void *dataPtr, unsigned char offset)
1290
+ {
1291
+ char theChar;
1292
+
1293
+ dataPtr += offset;
1294
+
1295
+ do {
1296
+ #if (FLASHEND > 0x10000)
1297
+ theChar = pgm_read_byte_far((uint16_t)dataPtr++);
1298
+ #else
1299
+ theChar = pgm_read_byte_near((uint16_t)dataPtr++);
1300
+ #endif
1301
+ if (theChar != 0)
1302
+ {
1303
+ sendchar(theChar);
1304
+ }
1305
+ } while (theChar != 0);
1306
+ }
1307
+
1308
+ //************************************************************************
1309
+ void PrintNewLine(void)
1310
+ {
1311
+ sendchar(0x0d);
1312
+ sendchar(0x0a);
1313
+ }
1314
+
1315
+
1316
+ //************************************************************************
1317
+ void PrintFromPROGMEMln(const void *dataPtr, unsigned char offset)
1318
+ {
1319
+ PrintFromPROGMEM(dataPtr, offset);
1320
+
1321
+ PrintNewLine();
1322
+ }
1323
+
1324
+
1325
+ //************************************************************************
1326
+ void PrintString(char *textString)
1327
+ {
1328
+ char theChar;
1329
+ int ii;
1330
+
1331
+ theChar = 1;
1332
+ ii = 0;
1333
+ while (theChar != 0)
1334
+ {
1335
+ theChar = textString[ii];
1336
+ if (theChar != 0)
1337
+ {
1338
+ sendchar(theChar);
1339
+ }
1340
+ ii++;
1341
+ }
1342
+ }
1343
+
1344
+ //************************************************************************
1345
+ void PrintHexByte(unsigned char theByte)
1346
+ {
1347
+ char theChar;
1348
+
1349
+ theChar = 0x30 + ((theByte >> 4) & 0x0f);
1350
+ if (theChar > 0x39)
1351
+ {
1352
+ theChar += 7;
1353
+ }
1354
+ sendchar(theChar );
1355
+
1356
+ theChar = 0x30 + (theByte & 0x0f);
1357
+ if (theChar > 0x39)
1358
+ {
1359
+ theChar += 7;
1360
+ }
1361
+ sendchar(theChar );
1362
+ }
1363
+
1364
+ //************************************************************************
1365
+ void PrintDecInt(int theNumber, int digitCnt)
1366
+ {
1367
+ int theChar;
1368
+ int myNumber;
1369
+
1370
+ myNumber = theNumber;
1371
+
1372
+ if ((myNumber > 100) || (digitCnt >= 3))
1373
+ {
1374
+ theChar = 0x30 + myNumber / 100;
1375
+ sendchar(theChar );
1376
+ }
1377
+
1378
+ if ((myNumber > 10) || (digitCnt >= 2))
1379
+ {
1380
+ theChar = 0x30 + ((myNumber % 100) / 10 );
1381
+ sendchar(theChar );
1382
+ }
1383
+ theChar = 0x30 + (myNumber % 10);
1384
+ sendchar(theChar );
1385
+ }
1386
+
1387
+
1388
+
1389
+
1390
+ //************************************************************************
1391
+ static void PrintCPUstats(void)
1392
+ {
1393
+ unsigned char fuseByte;
1394
+
1395
+ PrintFromPROGMEMln(gTextMsg_Explorer, 0);
1396
+
1397
+ PrintFromPROGMEM(gTextMsg_COMPILED_ON, 0);
1398
+ PrintFromPROGMEMln(gTextMsg_GCC_DATE_STR, 0);
1399
+
1400
+ PrintFromPROGMEM(gTextMsg_CPU_Type, 0);
1401
+ PrintFromPROGMEMln(gTextMsg_CPU_Name, 0);
1402
+
1403
+ PrintFromPROGMEM(gTextMsg_AVR_ARCH, 0);
1404
+ PrintDecInt(__AVR_ARCH__, 1);
1405
+ PrintNewLine();
1406
+
1407
+ PrintFromPROGMEM(gTextMsg_GCC_VERSION, 0);
1408
+ PrintFromPROGMEMln(gTextMsg_GCC_VERSION_STR, 0);
1409
+
1410
+ //* these can be found in avr/version.h
1411
+ PrintFromPROGMEM(gTextMsg_AVR_LIBC, 0);
1412
+ PrintFromPROGMEMln(gTextMsg_AVR_LIBC_VER_STR, 0);
1413
+
1414
+ #if defined(SIGNATURE_0)
1415
+ PrintFromPROGMEM(gTextMsg_CPU_SIGNATURE, 0);
1416
+ //* these can be found in avr/iomxxx.h
1417
+ PrintHexByte(SIGNATURE_0);
1418
+ PrintHexByte(SIGNATURE_1);
1419
+ PrintHexByte(SIGNATURE_2);
1420
+ PrintNewLine();
1421
+ #endif
1422
+
1423
+
1424
+ #if defined(GET_LOW_FUSE_BITS)
1425
+ //* fuse settings
1426
+ PrintFromPROGMEM(gTextMsg_FUSE_BYTE_LOW, 0);
1427
+ fuseByte = boot_lock_fuse_bits_get(GET_LOW_FUSE_BITS);
1428
+ PrintHexByte(fuseByte);
1429
+ PrintNewLine();
1430
+
1431
+ PrintFromPROGMEM(gTextMsg_FUSE_BYTE_HIGH, 0);
1432
+ fuseByte = boot_lock_fuse_bits_get(GET_HIGH_FUSE_BITS);
1433
+ PrintHexByte(fuseByte);
1434
+ PrintNewLine();
1435
+
1436
+ PrintFromPROGMEM(gTextMsg_FUSE_BYTE_EXT, 0);
1437
+ fuseByte = boot_lock_fuse_bits_get(GET_EXTENDED_FUSE_BITS);
1438
+ PrintHexByte(fuseByte);
1439
+ PrintNewLine();
1440
+
1441
+ PrintFromPROGMEM(gTextMsg_FUSE_BYTE_LOCK, 0);
1442
+ fuseByte = boot_lock_fuse_bits_get(GET_LOCK_BITS);
1443
+ PrintHexByte(fuseByte);
1444
+ PrintNewLine();
1445
+
1446
+ #endif
1447
+
1448
+ }
1449
+
1450
+
1451
+ //************************************************************************
1452
+ static void BlinkLED(void)
1453
+ {
1454
+ PROGLED_DDR |= (1<<PROGLED_PIN);
1455
+ PROGLED_PORT |= (1<<PROGLED_PIN); // active high LED ON
1456
+
1457
+ while (!Serial_Available())
1458
+ {
1459
+ PROGLED_PORT &= ~(1<<PROGLED_PIN); // turn LED off
1460
+ delay_ms(100);
1461
+ PROGLED_PORT |= (1<<PROGLED_PIN); // turn LED on
1462
+ delay_ms(100);
1463
+ }
1464
+ recchar(); // get the char out of the buffer
1465
+ }
1466
+
1467
+ enum
1468
+ {
1469
+ kDUMP_FLASH = 0,
1470
+ kDUMP_EEPROM,
1471
+ kDUMP_RAM
1472
+ };
1473
+
1474
+ //************************************************************************
1475
+ static void DumpHex(unsigned char dumpWhat, unsigned long startAddress, unsigned char numRows)
1476
+ {
1477
+ unsigned long myAddressPointer;
1478
+ uint8_t ii;
1479
+ unsigned char theValue;
1480
+ char asciiDump[18];
1481
+ unsigned char *ramPtr;
1482
+
1483
+
1484
+ ramPtr = 0;
1485
+ theValue = 0;
1486
+ myAddressPointer = startAddress;
1487
+ while (numRows > 0)
1488
+ {
1489
+ if (myAddressPointer > 0x10000)
1490
+ {
1491
+ PrintHexByte((myAddressPointer >> 16) & 0x00ff);
1492
+ }
1493
+ PrintHexByte((myAddressPointer >> 8) & 0x00ff);
1494
+ PrintHexByte(myAddressPointer & 0x00ff);
1495
+ sendchar(0x20);
1496
+ sendchar('-');
1497
+ sendchar(0x20);
1498
+
1499
+ asciiDump[0] = 0;
1500
+ for (ii=0; ii<16; ii++)
1501
+ {
1502
+ switch(dumpWhat)
1503
+ {
1504
+ case kDUMP_FLASH:
1505
+ #if (FLASHEND > 0x10000)
1506
+ theValue = pgm_read_byte_far(myAddressPointer);
1507
+ #else
1508
+ theValue = pgm_read_byte_near(myAddressPointer);
1509
+ #endif
1510
+ break;
1511
+
1512
+ case kDUMP_EEPROM:
1513
+ theValue = eeprom_read_byte((uint8_t *)(uint16_t)myAddressPointer);
1514
+ break;
1515
+
1516
+ case kDUMP_RAM:
1517
+ theValue = ramPtr[myAddressPointer];
1518
+ break;
1519
+
1520
+ }
1521
+ PrintHexByte(theValue);
1522
+ sendchar(0x20);
1523
+ if ((theValue >= 0x20) && (theValue < 0x7f))
1524
+ {
1525
+ asciiDump[ii % 16] = theValue;
1526
+ }
1527
+ else
1528
+ {
1529
+ asciiDump[ii % 16] = '.';
1530
+ }
1531
+
1532
+ myAddressPointer++;
1533
+ }
1534
+ asciiDump[16] = 0;
1535
+ PrintString(asciiDump);
1536
+ PrintNewLine();
1537
+
1538
+ numRows--;
1539
+ }
1540
+ }
1541
+
1542
+
1543
+
1544
+ //************************************************************************
1545
+ //* returns amount of extended memory
1546
+ static void EEPROMtest(void)
1547
+ {
1548
+ int ii;
1549
+ char theChar;
1550
+ char theEEPROMchar;
1551
+ int errorCount;
1552
+
1553
+ PrintFromPROGMEMln(gTextMsg_WriteToEEprom, 0);
1554
+ PrintNewLine();
1555
+ ii = 0;
1556
+ #if (FLASHEND > 0x10000)
1557
+ while (((theChar = pgm_read_byte_far(((uint16_t)gTextMsg_Explorer) + ii)) != '*') && (ii < 512))
1558
+ #else
1559
+ while (((theChar = pgm_read_byte_near(((uint16_t)gTextMsg_Explorer) + ii)) != '*') && (ii < 512))
1560
+ #endif
1561
+ {
1562
+ eeprom_write_byte((uint8_t *)ii, theChar);
1563
+ if (theChar == 0)
1564
+ {
1565
+ PrintFromPROGMEM(gTextMsg_SPACE, 0);
1566
+ }
1567
+ else
1568
+ {
1569
+ sendchar(theChar);
1570
+ }
1571
+ ii++;
1572
+ }
1573
+
1574
+ //* no go back through and test
1575
+ PrintNewLine();
1576
+ PrintNewLine();
1577
+ PrintFromPROGMEMln(gTextMsg_ReadingEEprom, 0);
1578
+ PrintNewLine();
1579
+ errorCount = 0;
1580
+ ii = 0;
1581
+ #if (FLASHEND > 0x10000)
1582
+ while (((theChar = pgm_read_byte_far((uint16_t)gTextMsg_Explorer + ii)) != '*') && (ii < 512))
1583
+ #else
1584
+ while (((theChar = pgm_read_byte_near((uint16_t)gTextMsg_Explorer + ii)) != '*') && (ii < 512))
1585
+ #endif
1586
+ {
1587
+ theEEPROMchar = eeprom_read_byte((uint8_t *)ii);
1588
+ if (theEEPROMchar == 0)
1589
+ {
1590
+ PrintFromPROGMEM(gTextMsg_SPACE, 0);
1591
+ }
1592
+ else
1593
+ {
1594
+ sendchar(theEEPROMchar);
1595
+ }
1596
+ if (theEEPROMchar != theChar)
1597
+ {
1598
+ errorCount++;
1599
+ }
1600
+ ii++;
1601
+ }
1602
+ PrintNewLine();
1603
+ PrintNewLine();
1604
+ PrintFromPROGMEM(gTextMsg_EEPROMerrorCnt, 0);
1605
+ PrintDecInt(errorCount, 1);
1606
+ PrintNewLine();
1607
+ PrintNewLine();
1608
+
1609
+ gEepromIndex = 0; //* set index back to zero for next eeprom dump
1610
+
1611
+ }
1612
+
1613
+
1614
+
1615
+ #if (FLASHEND > 0x08000)
1616
+ //* this includes the interrupt names for the monitor portion. There is no longer enough
1617
+ //* memory to include this
1618
+ // #include "avrinterruptnames.h"
1619
+ // #ifndef _INTERRUPT_NAMES_DEFINED_
1620
+ // #warning Interrupt vectors not defined
1621
+ // #endif
1622
+ #endif
1623
+
1624
+ //************************************************************************
1625
+ static void VectorDisplay(void)
1626
+ {
1627
+ unsigned long byte1;
1628
+ unsigned long byte2;
1629
+ unsigned long byte3;
1630
+ unsigned long byte4;
1631
+ unsigned long word1;
1632
+ unsigned long word2;
1633
+ int vectorIndex;
1634
+ unsigned long myMemoryPtr;
1635
+ unsigned long wordMemoryAddress;
1636
+ unsigned long realitiveAddr;
1637
+ unsigned long myFullAddress;
1638
+ unsigned long absoluteAddr;
1639
+ #if defined(_INTERRUPT_NAMES_DEFINED_)
1640
+ long stringPointer;
1641
+ #endif
1642
+
1643
+ myMemoryPtr = 0;
1644
+ vectorIndex = 0;
1645
+ PrintFromPROGMEMln(gTextMsg_CPU_Name, 0);
1646
+ PrintFromPROGMEMln(gTextMsg_VECTOR_HEADER, 0);
1647
+ // V# ADDR op code
1648
+ // 1 - 0000 = C3 BB 00 00 rjmp 03BB >000776 RESET
1649
+ while (vectorIndex < kInterruptVectorCount)
1650
+ {
1651
+ wordMemoryAddress = myMemoryPtr / 2;
1652
+ // 01 - 0000 = 12 34
1653
+ PrintDecInt(vectorIndex + 1, 2);
1654
+ sendchar(0x20);
1655
+ sendchar('-');
1656
+ sendchar(0x20);
1657
+ PrintHexByte((wordMemoryAddress >> 8) & 0x00ff);
1658
+ PrintHexByte((wordMemoryAddress) & 0x00ff);
1659
+ sendchar(0x20);
1660
+ sendchar('=');
1661
+ sendchar(0x20);
1662
+
1663
+
1664
+ //* the AVR is LITTLE ENDIAN, swap the byte order
1665
+ #if (FLASHEND > 0x10000)
1666
+ byte1 = pgm_read_byte_far(myMemoryPtr++);
1667
+ byte2 = pgm_read_byte_far(myMemoryPtr++);
1668
+ byte3 = pgm_read_byte_far(myMemoryPtr++);
1669
+ byte4 = pgm_read_byte_far(myMemoryPtr++);
1670
+ #else
1671
+ byte1 = pgm_read_byte_near(myMemoryPtr++);
1672
+ byte2 = pgm_read_byte_near(myMemoryPtr++);
1673
+ byte3 = pgm_read_byte_near(myMemoryPtr++);
1674
+ byte4 = pgm_read_byte_near(myMemoryPtr++);
1675
+ #endif
1676
+ word1 = (byte2 << 8) + byte1;
1677
+ word2 = (byte4 << 8) + byte3;
1678
+
1679
+
1680
+ PrintHexByte(byte2);
1681
+ sendchar(0x20);
1682
+ PrintHexByte(byte1);
1683
+ sendchar(0x20);
1684
+ PrintHexByte(byte4);
1685
+ sendchar(0x20);
1686
+ PrintHexByte(byte3);
1687
+ sendchar(0x20);
1688
+
1689
+ if (word1 == 0xffff)
1690
+ {
1691
+ PrintFromPROGMEM(gTextMsg_noVector, 0);
1692
+ }
1693
+ else if ((word1 & 0xc000) == 0xc000)
1694
+ {
1695
+ //* rjmp instruction
1696
+ realitiveAddr = word1 & 0x3FFF;
1697
+ absoluteAddr = wordMemoryAddress + realitiveAddr; //* add the offset to the current address
1698
+ absoluteAddr = absoluteAddr << 1; //* multiply by 2 for byte address
1699
+
1700
+ PrintFromPROGMEM(gTextMsg_rjmp, 0);
1701
+ PrintHexByte((realitiveAddr >> 8) & 0x00ff);
1702
+ PrintHexByte((realitiveAddr) & 0x00ff);
1703
+ sendchar(0x20);
1704
+ sendchar('>');
1705
+ PrintHexByte((absoluteAddr >> 16) & 0x00ff);
1706
+ PrintHexByte((absoluteAddr >> 8) & 0x00ff);
1707
+ PrintHexByte((absoluteAddr) & 0x00ff);
1708
+
1709
+ }
1710
+ else if ((word1 & 0xfE0E) == 0x940c)
1711
+ {
1712
+ //* jmp instruction, this is REALLY complicated, refer to the instruction manual (JMP)
1713
+ myFullAddress = ((byte1 & 0x01) << 16) +
1714
+ ((byte1 & 0xf0) << 17) +
1715
+ ((byte2 & 0x01) << 21) +
1716
+ word2;
1717
+
1718
+ absoluteAddr = myFullAddress << 1;
1719
+
1720
+ PrintFromPROGMEM(gTextMsg_jmp, 0);
1721
+ PrintHexByte((myFullAddress >> 16) & 0x00ff);
1722
+ PrintHexByte((myFullAddress >> 8) & 0x00ff);
1723
+ PrintHexByte((myFullAddress) & 0x00ff);
1724
+ sendchar(0x20);
1725
+ sendchar('>');
1726
+ PrintHexByte((absoluteAddr >> 16) & 0x00ff);
1727
+ PrintHexByte((absoluteAddr >> 8) & 0x00ff);
1728
+ PrintHexByte((absoluteAddr) & 0x00ff);
1729
+ }
1730
+
1731
+ #if defined(_INTERRUPT_NAMES_DEFINED_)
1732
+ sendchar(0x20);
1733
+ #if (FLASHEND > 0x10000)
1734
+ stringPointer = pgm_read_word_far(&(gInterruptNameTable[vectorIndex]));
1735
+ #else
1736
+ stringPointer = pgm_read_word_near(&(gInterruptNameTable[vectorIndex]));
1737
+ #endif
1738
+ PrintFromPROGMEM((char *)stringPointer, 0);
1739
+ #endif
1740
+ PrintNewLine();
1741
+
1742
+ vectorIndex++;
1743
+ }
1744
+ }
1745
+
1746
+ //************************************************************************
1747
+ static void PrintAvailablePort(char thePortLetter)
1748
+ {
1749
+ PrintFromPROGMEM(gTextMsg_PORT, 0);
1750
+ sendchar(thePortLetter);
1751
+ PrintNewLine();
1752
+ }
1753
+
1754
+ //************************************************************************
1755
+ static void ListAvailablePorts(void)
1756
+ {
1757
+
1758
+ #ifdef DDRA
1759
+ PrintAvailablePort('A');
1760
+ #endif
1761
+
1762
+ #ifdef DDRB
1763
+ PrintAvailablePort('B');
1764
+ #endif
1765
+
1766
+ #ifdef DDRC
1767
+ PrintAvailablePort('C');
1768
+ #endif
1769
+
1770
+ #ifdef DDRD
1771
+ PrintAvailablePort('D');
1772
+ #endif
1773
+
1774
+ #ifdef DDRE
1775
+ PrintAvailablePort('E');
1776
+ #endif
1777
+
1778
+ #ifdef DDRF
1779
+ PrintAvailablePort('F');
1780
+ #endif
1781
+
1782
+ #ifdef DDRG
1783
+ PrintAvailablePort('G');
1784
+ #endif
1785
+
1786
+ #ifdef DDRH
1787
+ PrintAvailablePort('H');
1788
+ #endif
1789
+
1790
+ #ifdef DDRI
1791
+ PrintAvailablePort('I');
1792
+ #endif
1793
+
1794
+ #ifdef DDRJ
1795
+ PrintAvailablePort('J');
1796
+ #endif
1797
+
1798
+ #ifdef DDRK
1799
+ PrintAvailablePort('K');
1800
+ #endif
1801
+
1802
+ #ifdef DDRL
1803
+ PrintAvailablePort('L');
1804
+ #endif
1805
+
1806
+ }
1807
+
1808
+ //************************************************************************
1809
+ static void AVR_PortOutput(void)
1810
+ {
1811
+ char portLetter;
1812
+ char getCharFlag;
1813
+
1814
+ PrintFromPROGMEM(gTextMsg_WHAT_PORT, 0);
1815
+
1816
+ portLetter = recchar();
1817
+ portLetter = portLetter & 0x5f;
1818
+ sendchar(portLetter);
1819
+ PrintNewLine();
1820
+
1821
+ if ((portLetter >= 'A') && (portLetter <= 'Z'))
1822
+ {
1823
+ getCharFlag = true;
1824
+ switch(portLetter)
1825
+ {
1826
+ #ifdef DDRA
1827
+ case 'A':
1828
+ DDRA = 0xff;
1829
+ while (!Serial_Available())
1830
+ {
1831
+ PORTA ^= 0xff;
1832
+ delay_ms(200);
1833
+ }
1834
+ PORTA = 0;
1835
+ break;
1836
+ #endif
1837
+
1838
+ #ifdef DDRB
1839
+ case 'B':
1840
+ DDRB = 0xff;
1841
+ while (!Serial_Available())
1842
+ {
1843
+ PORTB ^= 0xff;
1844
+ delay_ms(200);
1845
+ }
1846
+ PORTB = 0;
1847
+ break;
1848
+ #endif
1849
+
1850
+ #ifdef DDRC
1851
+ case 'C':
1852
+ DDRC = 0xff;
1853
+ while (!Serial_Available())
1854
+ {
1855
+ PORTC ^= 0xff;
1856
+ delay_ms(200);
1857
+ }
1858
+ PORTC = 0;
1859
+ break;
1860
+ #endif
1861
+
1862
+ #ifdef DDRD
1863
+ case 'D':
1864
+ DDRD = 0xff;
1865
+ while (!Serial_Available())
1866
+ {
1867
+ PORTD ^= 0xff;
1868
+ delay_ms(200);
1869
+ }
1870
+ PORTD = 0;
1871
+ break;
1872
+ #endif
1873
+
1874
+ #ifdef DDRE
1875
+ case 'E':
1876
+ DDRE = 0xff;
1877
+ while (!Serial_Available())
1878
+ {
1879
+ PORTE ^= 0xff;
1880
+ delay_ms(200);
1881
+ }
1882
+ PORTE = 0;
1883
+ break;
1884
+ #endif
1885
+
1886
+ #ifdef DDRF
1887
+ case 'F':
1888
+ DDRF = 0xff;
1889
+ while (!Serial_Available())
1890
+ {
1891
+ PORTF ^= 0xff;
1892
+ delay_ms(200);
1893
+ }
1894
+ PORTF = 0;
1895
+ break;
1896
+ #endif
1897
+
1898
+ #ifdef DDRG
1899
+ case 'G':
1900
+ DDRG = 0xff;
1901
+ while (!Serial_Available())
1902
+ {
1903
+ PORTG ^= 0xff;
1904
+ delay_ms(200);
1905
+ }
1906
+ PORTG = 0;
1907
+ break;
1908
+ #endif
1909
+
1910
+ #ifdef DDRH
1911
+ case 'H':
1912
+ DDRH = 0xff;
1913
+ while (!Serial_Available())
1914
+ {
1915
+ PORTH ^= 0xff;
1916
+ delay_ms(200);
1917
+ }
1918
+ PORTH = 0;
1919
+ break;
1920
+ #endif
1921
+
1922
+ #ifdef DDRI
1923
+ case 'I':
1924
+ DDRI = 0xff;
1925
+ while (!Serial_Available())
1926
+ {
1927
+ PORTI ^= 0xff;
1928
+ delay_ms(200);
1929
+ }
1930
+ PORTI = 0;
1931
+ break;
1932
+ #endif
1933
+
1934
+ #ifdef DDRJ
1935
+ case 'J':
1936
+ DDRJ = 0xff;
1937
+ while (!Serial_Available())
1938
+ {
1939
+ PORTJ ^= 0xff;
1940
+ delay_ms(200);
1941
+ }
1942
+ PORTJ = 0;
1943
+ break;
1944
+ #endif
1945
+
1946
+ #ifdef DDRK
1947
+ case 'K':
1948
+ DDRK = 0xff;
1949
+ while (!Serial_Available())
1950
+ {
1951
+ PORTK ^= 0xff;
1952
+ delay_ms(200);
1953
+ }
1954
+ PORTK = 0;
1955
+ break;
1956
+ #endif
1957
+
1958
+ #ifdef DDRL
1959
+ case 'L':
1960
+ DDRL = 0xff;
1961
+ while (!Serial_Available())
1962
+ {
1963
+ PORTL ^= 0xff;
1964
+ delay_ms(200);
1965
+ }
1966
+ PORTL = 0;
1967
+ break;
1968
+ #endif
1969
+
1970
+ default:
1971
+ PrintFromPROGMEMln(gTextMsg_PortNotSupported, 0);
1972
+ getCharFlag = false;
1973
+ break;
1974
+ }
1975
+ if (getCharFlag)
1976
+ {
1977
+ recchar();
1978
+ }
1979
+ }
1980
+ else
1981
+ {
1982
+ PrintFromPROGMEMln(gTextMsg_MustBeLetter, 0);
1983
+ }
1984
+ }
1985
+
1986
+
1987
+ //*******************************************************************
1988
+ static void PrintHelp(void)
1989
+ {
1990
+ PrintFromPROGMEMln(gTextMsg_HELP_MSG_0, 0);
1991
+ PrintFromPROGMEMln(gTextMsg_HELP_MSG_QM, 0);
1992
+ PrintFromPROGMEMln(gTextMsg_HELP_MSG_AT, 0);
1993
+ PrintFromPROGMEMln(gTextMsg_HELP_MSG_B, 0);
1994
+ PrintFromPROGMEMln(gTextMsg_HELP_MSG_E, 0);
1995
+ PrintFromPROGMEMln(gTextMsg_HELP_MSG_F, 0);
1996
+ PrintFromPROGMEMln(gTextMsg_HELP_MSG_H, 0);
1997
+
1998
+ PrintFromPROGMEMln(gTextMsg_HELP_MSG_L, 0);
1999
+ PrintFromPROGMEMln(gTextMsg_HELP_MSG_Q, 0);
2000
+ PrintFromPROGMEMln(gTextMsg_HELP_MSG_R, 0);
2001
+ PrintFromPROGMEMln(gTextMsg_HELP_MSG_V, 0);
2002
+ PrintFromPROGMEMln(gTextMsg_HELP_MSG_Y, 0);
2003
+ }
2004
+
2005
+ //************************************************************************
2006
+ static void RunMonitor(void)
2007
+ {
2008
+ char keepGoing;
2009
+ unsigned char theChar;
2010
+ int ii, jj;
2011
+
2012
+ for (ii=0; ii<5; ii++)
2013
+ {
2014
+ for (jj=0; jj<25; jj++)
2015
+ {
2016
+ sendchar('!');
2017
+ }
2018
+ PrintNewLine();
2019
+ }
2020
+
2021
+ gRamIndex = 0;
2022
+ gFlashIndex = 0;
2023
+ gEepromIndex = 0;
2024
+
2025
+ PrintFromPROGMEMln(gTextMsg_Explorer, 0);
2026
+
2027
+ keepGoing = 1;
2028
+ while (keepGoing)
2029
+ {
2030
+ PrintFromPROGMEM(gTextMsg_Prompt, 0);
2031
+ theChar = recchar();
2032
+ if (theChar >= 0x60)
2033
+ {
2034
+ theChar = theChar & 0x5F;
2035
+ }
2036
+
2037
+ if (theChar >= 0x20)
2038
+ {
2039
+ sendchar(theChar);
2040
+ sendchar(0x20);
2041
+ }
2042
+
2043
+ switch(theChar)
2044
+ {
2045
+ case '0':
2046
+ PrintFromPROGMEMln(gTextMsg_HELP_MSG_0, 2);
2047
+ gFlashIndex = 0;
2048
+ gRamIndex = 0;
2049
+ gEepromIndex = 0;
2050
+ break;
2051
+
2052
+ case '?':
2053
+ PrintFromPROGMEMln(gTextMsg_HELP_MSG_QM, 2);
2054
+ PrintCPUstats();
2055
+ break;
2056
+
2057
+ case '@':
2058
+ PrintFromPROGMEMln(gTextMsg_HELP_MSG_AT, 2);
2059
+ EEPROMtest();
2060
+ break;
2061
+
2062
+ case 'B':
2063
+ PrintFromPROGMEMln(gTextMsg_HELP_MSG_B, 2);
2064
+ BlinkLED();
2065
+ break;
2066
+
2067
+ case 'E':
2068
+ PrintFromPROGMEMln(gTextMsg_HELP_MSG_E, 2);
2069
+ DumpHex(kDUMP_EEPROM, gEepromIndex, 16);
2070
+ gEepromIndex += 256;
2071
+ if (gEepromIndex > E2END)
2072
+ {
2073
+ gEepromIndex = 0;
2074
+ }
2075
+ break;
2076
+
2077
+ case 'F':
2078
+ PrintFromPROGMEMln(gTextMsg_HELP_MSG_F, 2);
2079
+ DumpHex(kDUMP_FLASH, gFlashIndex, 16);
2080
+ gFlashIndex += 256;
2081
+ break;
2082
+
2083
+ case 'H':
2084
+ PrintFromPROGMEMln(gTextMsg_HELP_MSG_H, 2);
2085
+ PrintHelp();
2086
+ break;
2087
+
2088
+ case 'L':
2089
+ PrintFromPROGMEMln(gTextMsg_HELP_MSG_L, 2);
2090
+ ListAvailablePorts();
2091
+ break;
2092
+
2093
+ case 'Q':
2094
+ PrintFromPROGMEMln(gTextMsg_HELP_MSG_Q, 2);
2095
+ keepGoing = false;
2096
+ break;
2097
+
2098
+ case 'R':
2099
+ PrintFromPROGMEMln(gTextMsg_HELP_MSG_R, 2);
2100
+ DumpHex(kDUMP_RAM, gRamIndex, 16);
2101
+ gRamIndex += 256;
2102
+ break;
2103
+
2104
+ case 'V':
2105
+ PrintFromPROGMEMln(gTextMsg_HELP_MSG_V, 2);
2106
+ VectorDisplay();
2107
+ break;
2108
+
2109
+ case 'Y':
2110
+ PrintFromPROGMEMln(gTextMsg_HELP_MSG_Y, 2);
2111
+ AVR_PortOutput();
2112
+ break;
2113
+
2114
+ default:
2115
+ PrintFromPROGMEMln(gTextMsg_HUH, 0);
2116
+ break;
2117
+ }
2118
+ }
2119
+ }
2120
+
2121
+ #endif
2122
+
hardware/arduino/avr/bootloaders/stk500v2/stk500boot.ppg ADDED
@@ -0,0 +1 @@
 
 
1
+ <Workspace name="Bootloader"><Project path="STK500V2.pnproj"></Project></Workspace>
hardware/arduino/avr/bootloaders/stk500v2/stk500boot_v2_mega2560.hex ADDED
@@ -0,0 +1,469 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ :020000023000CC
2
+ :10E000000D9489F10D94B2F10D94B2F10D94B2F129
3
+ :10E010000D94B2F10D94B2F10D94B2F10D94B2F1F0
4
+ :10E020000D94B2F10D94B2F10D94B2F10D94B2F1E0
5
+ :10E030000D94B2F10D94B2F10D94B2F10D94B2F1D0
6
+ :10E040000D94B2F10D94B2F10D94B2F10D94B2F1C0
7
+ :10E050000D94B2F10D94B2F10D94B2F10D94B2F1B0
8
+ :10E060000D94B2F10D94B2F10D94B2F10D94B2F1A0
9
+ :10E070000D94B2F10D94B2F10D94B2F10D94B2F190
10
+ :10E080000D94B2F10D94B2F10D94B2F10D94B2F180
11
+ :10E090000D94B2F10D94B2F10D94B2F10D94B2F170
12
+ :10E0A0000D94B2F10D94B2F10D94B2F10D94B2F160
13
+ :10E0B0000D94B2F10D94B2F10D94B2F10D94B2F150
14
+ :10E0C0000D94B2F10D94B2F10D94B2F10D94B2F140
15
+ :10E0D0000D94B2F10D94B2F10D94B2F10D94B2F130
16
+ :10E0E0000D94B2F141546D656761323536300041AF
17
+ :10E0F000726475696E6F206578706C6F72657220DE
18
+ :10E1000073746B3530305632206279204D4C530099
19
+ :10E11000426F6F746C6F616465723E004875683F52
20
+ :10E1200000436F6D70696C6564206F6E203D200048
21
+ :10E130004350552054797065202020203D20005FF9
22
+ :10E140005F4156525F415243485F5F3D2000415658
23
+ :10E1500052204C696243205665723D20004743437C
24
+ :10E160002056657273696F6E203D20004350552024
25
+ :10E1700049442020202020203D20004C6F7720663D
26
+ :10E18000757365202020203D20004869676820665F
27
+ :10E190007573652020203D200045787420667573D6
28
+ :10E1A00065202020203D20004C6F636B2066757336
29
+ :10E1B000652020203D20004D617220203720323024
30
+ :10E1C000313300312E362E3800342E332E350056A2
31
+ :10E1D00023202020414444522020206F7020636F70
32
+ :10E1E00064652020202020696E73747275637469E1
33
+ :10E1F0006F6E2061646472202020496E74657272B3
34
+ :10E20000757074006E6F20766563746F7200726A49
35
+ :10E210006D702020006A6D70200057686174207056
36
+ :10E220006F72743A00506F7274206E6F7420737541
37
+ :10E2300070706F72746564004D7573742062652030
38
+ :10E2400061206C6574746572002000577269747483
39
+ :10E25000696E672045450052656164696E672045B7
40
+ :10E26000450045452065727220636E743D00504F35
41
+ :10E27000525400303D5A65726F2061646472003FF1
42
+ :10E280003D43505520737461747300403D454550C3
43
+ :10E29000524F4D207465737400423D426C696E6B41
44
+ :10E2A000204C454400453D44756D70204545505215
45
+ :10E2B0004F4D00463D44756D7020464C415348001B
46
+ :10E2C000483D48656C70004C3D4C69737420492F83
47
+ :10E2D0004F20506F72747300513D51756974005234
48
+ :10E2E0003D44756D702052414D00563D73686F7707
49
+ :10E2F00020696E7465727275707420566563746FF0
50
+ :10E30000727300593D506F727420626C696E6B00BD
51
+ :10E310002A0011241FBECFEFD1E2DEBFCDBF01E046
52
+ :10E320000CBF12E0A0E0B2E0EEE1FDEF03E00BBFB6
53
+ :10E3300002C007900D92A030B107D9F712E0A0E01B
54
+ :10E34000B2E001C01D92AE30B107E1F70F9460F367
55
+ :10E350000D948DFE01E20EBF0FEF0DBF11241FBE05
56
+ :10E360000D9460F30D9400F020E030E040ED57E0B4
57
+ :10E3700005C0FA013197F1F72F5F3F4F2817390792
58
+ :10E38000C0F308959C01260F311DC901A0E0B0E043
59
+ :10E390002F5F3F4FABBFFC018791882361F08093D3
60
+ :10E3A000C6008091C00086FFFCCF8091C0008064D1
61
+ :10E3B0008093C000EACF08958DE08093C6008091DD
62
+ :10E3C000C00086FFFCCF8091C00080648093C000B5
63
+ :10E3D0008AE08093C6008091C00086FFFCCF8091C8
64
+ :10E3E000C00080648093C00008950F94C2F10F9420
65
+ :10E3F000DCF10895FC019081992359F09093C600B7
66
+ :10E400008091C00086FFFCCF8091C0008064809323
67
+ :10E41000C0003196992379F70895282F982F929567
68
+ :10E420009F70892F805D8A3308F0895F8093C600D2
69
+ :10E430008091C00086FFFCCF8091C00080648093F3
70
+ :10E44000C000822F8F70982F905D9A3308F0995FEB
71
+ :10E450009093C6008091C00086FFFCCF8091C000E1
72
+ :10E4600080648093C00008959C01FB01853691056E
73
+ :10E470001CF46330710594F0C90164E670E00F94F8
74
+ :10E480002EFE605D7F4F6093C6008091C00086FFC6
75
+ :10E49000FCCF8091C00080648093C0002B30310598
76
+ :10E4A00014F43297B4F0C90164E670E00F942EFEC4
77
+ :10E4B0006AE070E00F942EFE605D7F4F6093C600AF
78
+ :10E4C0008091C00086FFFCCF8091C0008064809363
79
+ :10E4D000C000C9016AE070E00F942EFEC0968093E0
80
+ :10E4E000C6008091C00086FFFCCF8091C000806490
81
+ :10E4F0008093C00008951F93182F8EE692EE60E07F
82
+ :10E500000F94C2F11093C6008091C00086FFFCCF2B
83
+ :10E510008091C00080648093C0000F94DCF11F9153
84
+ :10E5200008952F923F924F925F926F927F928F92B7
85
+ :10E530009F92AF92BF92CF92DF92EF92FF920F9392
86
+ :10E540001F93DF93CF93CDB7DEB762970FB6F894E2
87
+ :10E55000DEBF0FBECDBF382E622ECA01DB015C01CB
88
+ :10E560006D01772420E2222E2E010894411C511CBB
89
+ :10E570008BC081E0A81680E0B80681E0C80680E084
90
+ :10E58000D80628F0C601AA27BB270F940DF2BB2797
91
+ :10E59000AD2D9C2D8B2D0F940DF28A2D0F940DF225
92
+ :10E5A0002092C6008091C00086FFFCCF8091C00001
93
+ :10E5B00080648093C0009DE29093C6008091C0006B
94
+ :10E5C00086FFFCCF8091C00080648093C0002092C1
95
+ :10E5D000C6008091C00086FFFCCF8091C00080649F
96
+ :10E5E0008093C00019828601750188249924A1E0D6
97
+ :10E5F0003A1651F03A1620F0B2E03B1661F409C029
98
+ :10E600000BBFF701779007C0C7010F9477FE782EF4
99
+ :10E6100002C0F7017080872D0F940DF22092C60082
100
+ :10E620008091C00086FFFCCF8091C0008064809301
101
+ :10E63000C000872D8052F401EF70F0708F3520F408
102
+ :10E64000E40DF51D708204C0E40DF51D8EE280839B
103
+ :10E650000894E11CF11C011D111D0894811C911CE2
104
+ :10E6600090E18916910409F0C2CF80E190E0A0E02A
105
+ :10E67000B0E0A80EB91ECA1EDB1E198AC2010F9493
106
+ :10E68000FAF10F94DCF16A94662009F072CF629679
107
+ :10E690000FB6F894DEBF0FBECDBFCF91DF911F91B3
108
+ :10E6A0000F91FF90EF90DF90CF90BF90AF909F9031
109
+ :10E6B0008F907F906F905F904F903F902F90089534
110
+ :10E6C0002F923F924F925F926F927F928F929F9282
111
+ :10E6D000AF92BF92CF92DF92EF92FF920F931F9370
112
+ :10E6E000DF93CF93CDB7DEB7CD53D1400FB6F894BB
113
+ :10E6F000DEBF0FBECDBF01E20EBF0FEF0DBF94B75F
114
+ :10E70000F894A89514BE80916000886180936000A1
115
+ :10E7100010926000789493FF05C0E0910002F091A0
116
+ :10E7200001021995279A2F9A8091C00082608093E8
117
+ :10E73000C00080E18093C40088E18093C1000000A4
118
+ :10E74000EE24FF24870144E0A42EB12CCC24DD2448
119
+ :10E7500024C0C5010197F1F70894E11CF11C011DCB
120
+ :10E76000111D21E2E2162EE4F20620E0020720E06D
121
+ :10E77000120718F031E0C32ED12CC801B70127ECE5
122
+ :10E780003BE140E050E00F9441FE611571058105C9
123
+ :10E79000910519F485B1805885B98091C00087FD35
124
+ :10E7A00003C0C114D104A9F2A6014F5F5F4FC25E3E
125
+ :10E7B000DE4F59834883CE51D140C25EDE4F8881FF
126
+ :10E7C0009981CE51D140019711F00D9410FEC05D9A
127
+ :10E7D000DE4F19821882C053D14060E0C15DDE4F28
128
+ :10E7E0001882CF52D14088249924C35DDE4F19820C
129
+ :10E7F0001882CD52D140C05EDE4F188219821A8233
130
+ :10E800001B82C052D140CE5CDE4F188219821A8220
131
+ :10E810001B82C253D140EE24FF2487010BBFF701B6
132
+ :10E8200007911691C45CDE4F19830883CC53D14005
133
+ :10E830000D940BFEC25EDE4F28813981CE51D1404E
134
+ :10E840002130310509F52091C600C25EDE4F1982E4
135
+ :10E850001882CE51D14022C02F5F3F4F4F4F5F4FA4
136
+ :10E86000213082E138078AE7480780E0580780F0C6
137
+ :10E87000C45CDE4FE881F981CC53D140EF5FFF4F9C
138
+ :10E8800019F0EE27FF27099420E030E040E050E047
139
+ :10E890008091C00087FFE0CF2091C600C35DDE4FAE
140
+ :10E8A00048815981CD52D1404F5F5F4FC35DDE4FEC
141
+ :10E8B00059834883CD52D140213209F063C64A3092
142
+ :10E8C000510508F05FC60894811C911C53E0851621
143
+ :10E8D000910409F059C600E010E018C081E280936D
144
+ :10E8E000C6008091C00086FFFCCF8091C00080648C
145
+ :10E8F0008093C0002F5F3F4F2931310579F70F9486
146
+ :10E90000DCF10F5F1F4F0530110519F020E030E0FA
147
+ :10E91000E5CF10920A0210920B0210920C02109294
148
+ :10E920000D02109206021092070210920802109235
149
+ :10E930000902109202021092030210920402109235
150
+ :10E9400005028FEE90EE60E00F94F5F180E191EE1C
151
+ :10E9500060E00F94C2F18091C00087FFFCCF9091DE
152
+ :10E96000C600903608F09F759032B8F09093C600BC
153
+ :10E970008091C00086FFFCCF8091C00080648093AE
154
+ :10E98000C000A0E2A093C6008091C00086FFFCCF2B
155
+ :10E990008091C00080648093C000983409F4D7C18E
156
+ :10E9A0009934B8F4923409F459C1933458F490333B
157
+ :10E9B00019F1903308F4E3C59F33A1F1903409F0C5
158
+ :10E9C000DEC5BDC0953409F470C1963409F0D7C5D1
159
+ :10E9D00098C1923509F42BC2933538F49C3409F46C
160
+ :10E9E000F5C1913509F0CBC518C2963509F445C279
161
+ :10E9F000993509F0C4C567C483E792EE62E00F94CD
162
+ :10EA0000F5F110920602109207021092080210927D
163
+ :10EA1000090210920A0210920B0210920C0210923C
164
+ :10EA20000D0213C18FE792EE62E00F94F5F18FEEC5
165
+ :10EA300090EE60E00F94F5F181E291EE60E00F94CA
166
+ :10EA4000C2F187EB91EE60E00F94F5F180E391EE77
167
+ :10EA500060E00F94C2F184EE90EE60E00F94F5F167
168
+ :10EA60008FE391EE60E00F94C2F186E090E061E008
169
+ :10EA700070E00F9434F20F94DCF18DE591EE60E0DC
170
+ :10EA80000F94C2F189EC91EE60E00F94F5F18EE401
171
+ :10EA900091EE60E00F94C2F183EC91EE60E00F9490
172
+ :10EAA000F5F18CE691EE60E00F94C2F18EE10F94E7
173
+ :10EAB0000DF288E90F940DF281E00F940DF20F949E
174
+ :10EAC000DCF18BE791EE60E00F94C2F119E0E0E039
175
+ :10EAD000F0E010935700E4918E2F0F940DF20F94F5
176
+ :10EAE000DCF18AE891EE60E00F94C2F1E3E0F0E03F
177
+ :10EAF00010935700E4918E2F0F940DF20F94DCF1D8
178
+ :10EB000089E991EE60E00F94C2F1E2E0F0E0109349
179
+ :10EB10005700E4918E2F0F940DF20F94DCF188EAE8
180
+ :10EB200091EE60E00F94C2F1E1E0F0E01093570045
181
+ :10EB30001491812F0F940DF20F94DCF107CF8BE825
182
+ :10EB400092EE62E00F94F5F18BE492EE60E00F94A8
183
+ :10EB5000F5F10F94DCF100E010E019C0C8016F2D51
184
+ :10EB60000F947FFEFF2031F489E492EE60E00F9471
185
+ :10EB7000C2F10BC0F092C6008091C00086FFFCCFAE
186
+ :10EB80008091C00080648093C0000F5F1F4FC80158
187
+ :10EB900081519F41A0E0B0E0ABBFFC01F790BAE229
188
+ :10EBA000FB1621F0E2E000301E07C1F60F94DCF105
189
+ :10EBB0000F94DCF187E592EE60E00F94F5F10F948D
190
+ :10EBC000DCF1CC24DD2400E010E01EC0C8010F946D
191
+ :10EBD00077FEF82E882331F489E492EE60E00F94FA
192
+ :10EBE000C2F10BC08093C6008091C00086FFFCCFAD
193
+ :10EBF0008091C00080648093C000FE1419F00894D6
194
+ :10EC0000C11CD11C0F5F1F4FC80181519F41A0E063
195
+ :10EC1000B0E0ABBFFC01E790FAE2EF1621F022E092
196
+ :10EC20000030120799F60F94DCF10F94DCF182E6C4
197
+ :10EC300092EE60E00F94C2F1C60161E070E00F94C3
198
+ :10EC400034F20F94DCF10F94DCF110920202109276
199
+ :10EC50000302109204021092050278CE89E992EE26
200
+ :10EC600062E00F94F5F1279A2F9A16C02F9880E052
201
+ :10EC700090E0E0EDF7E03197F1F7019684369105E9
202
+ :10EC8000C1F72F9A80E090E0E0EDF7E03197F1F7DF
203
+ :10EC9000019684369105C1F78091C00087FFE6CFC9
204
+ :10ECA0008091C00087FFFCCF64C485EA92EE62E0E9
205
+ :10ECB0000F94F5F140910202509103026091040219
206
+ :10ECC0007091050281E020E10F9491F2809102029F
207
+ :10ECD00090910302A0910402B091050280509F4FD1
208
+ :10ECE000AF4FBF4F8093020290930302A0930402A0
209
+ :10ECF000B093050280509041A040B04008F426CE69
210
+ :10ED0000A4CF83EB92EE62E00F94F5F140910602FE
211
+ :10ED100050910702609108027091090280E020E1A1
212
+ :10ED20000F9491F28091060290910702A09108023F
213
+ :10ED3000B091090280509F4FAF4FBF4F80930602A2
214
+ :10ED400090930702A0930802B0930902FFCD80ECD4
215
+ :10ED500092EE62E00F94F5F183E792EE60E00F949B
216
+ :10ED6000F5F18FE792EE60E00F94F5F18BE892EE0B
217
+ :10ED700060E00F94F5F189E992EE60E00F94F5F10F
218
+ :10ED800085EA92EE60E00F94F5F183EB92EE60E09D
219
+ :10ED90000F94F5F180EC92EE60E00F94F5F187ECC2
220
+ :10EDA00092EE60E00F94F5F188ED92EE60E00F9442
221
+ :10EDB000F5F18FED92EE60E00F94F5F18AEE92EEB0
222
+ :10EDC00060E00F94F5F183E093EEBDCD87EC92EE19
223
+ :10EDD00062E00F94F5F181E40F947BF282E40F94EA
224
+ :10EDE0007BF283E40F947BF284E40F947BF285E45E
225
+ :10EDF0000F947BF286E40F947BF287E40F947BF20E
226
+ :10EE000088E40F947BF28AE40F947BF28BE40F94F6
227
+ :10EE10007BF28CE40F947BF299CD88ED92EE62E068
228
+ :10EE20000F94F5F1772473948824992409C48FED05
229
+ :10EE300092EE62E00F94F5F140910A0250910B02BC
230
+ :10EE400060910C0270910D0282E020E10F9491F22A
231
+ :10EE500080910A0290910B02A0910C02B0910D02D8
232
+ :10EE600080509F4FAF4FBF4F80930A0290930B0289
233
+ :10EE7000A0930C02B0930D0269CD8AEE92EE62E08F
234
+ :10EE80000F94F5F184EE90EE60E00F94F5F18FECC5
235
+ :10EE900091EE60E00F94F5F1662477244301CC5D98
236
+ :10EEA000DE4F19821882C452D140D401C301B695F5
237
+ :10EEB000A79597958795CA5DDE4F88839983AA8326
238
+ :10EEC000BB83C652D140CC5DDE4FA881B981C4520C
239
+ :10EED000D1401196CC5DDE4FB983A883C452D14096
240
+ :10EEE000CD0162E070E00F9434F2B0E2B093C6005E
241
+ :10EEF0008091C00086FFFCCF8091C0008064809329
242
+ :10EF0000C000EDE2E093C6008091C00086FFFCCF18
243
+ :10EF10008091C00080648093C000F0E2F093C6004E
244
+ :10EF20008091C00086FFFCCF8091C00080648093F8
245
+ :10EF3000C000CA5DDE4FE880F9800A811B81C6529D
246
+ :10EF4000D140BB27A12F902F8F2D0F940DF2CA5DBA
247
+ :10EF5000DE4F8881C652D1400F940DF2B0E2FB2EF5
248
+ :10EF6000F092C6008091C00086FFFCCF8091C00067
249
+ :10EF700080648093C0000DE30093C6008091C000C0
250
+ :10EF800086FFFCCF8091C00080648093C00010E2B7
251
+ :10EF90001093C6008091C00086FFFCCF8091C00016
252
+ :10EFA00080648093C0008BBEF3012791C65DDE4F65
253
+ :10EFB0002883CA52D140A22EBB24CC24DD2408943D
254
+ :10EFC000611C711C811C911C8BBEF3018791282E42
255
+ :10EFD0003324442455240894611C711C811C911C09
256
+ :10EFE0008BBEF3013791C55DDE4F3883CB52D140E4
257
+ :10EFF0000894611C711C811C911C8BBEF30147910C
258
+ :10F00000C45DDE4F4883CC52D140ADEFEA2EAFEF66
259
+ :10F01000FA2EAFEF0A2FAFEF1A2F6E0C7F1C801E57
260
+ :10F02000911E142D032DF22CEE24EA0CFB1C0C1D5A
261
+ :10F030001D1D0F940DF220E22093C6008091C000A8
262
+ :10F0400086FFFCCF8091C00080648093C000C65DC5
263
+ :10F05000DE4F8881CA52D1400F940DF230E23093D6
264
+ :10F06000C6008091C00086FFFCCF8091C000806404
265
+ :10F070008093C000C45DDE4F8881CC52D1400F9494
266
+ :10F080000DF240E24093C6008091C00086FFFCCFA5
267
+ :10F090008091C00080648093C000C55DDE4F888190
268
+ :10F0A000CB52D1400F940DF250E25093C6008091A4
269
+ :10F0B000C00086FFFCCF8091C00080648093C000B8
270
+ :10F0C0008FEFE8168FEFF80680E0080780E018075A
271
+ :10F0D00031F484E092EE60E00F94C2F1DFC0D80119
272
+ :10F0E000C7018070907CA070B0708050904CA040A0
273
+ :10F0F000B040D1F52FEF3FE340E050E0E222F322B1
274
+ :10F1000004231523CA5DDE4FA880B980CA80DB8046
275
+ :10F11000C652D140AE0CBF1CC01ED11EAA0CBB1CD7
276
+ :10F12000CC1CDD1C8EE092EE60E00F94C2F1BB2798
277
+ :10F13000A12F902F8F2D0F940DF28E2D0F940DF285
278
+ :10F1400030E23093C6008091C00086FFFCCF8091F2
279
+ :10F15000C00080648093C0004EE34093C60080915D
280
+ :10F16000C00086FFFCCF87C08EE09EEFA0E0B0E03D
281
+ :10F17000E822F9220A231B239CE0E91694E9F90608
282
+ :10F1800090E0090790E0190709F088C0C45DDE4FE0
283
+ :10F19000A881CC52D140EA2EFF2400E010E0102FCD
284
+ :10F1A0000F2DFE2CEE24C55DDE4FB881CB52D14031
285
+ :10F1B000EB0EF11C011D111DD601C501817090706F
286
+ :10F1C000A070B070DC0199278827E80EF91E0A1F8D
287
+ :10F1D0001B1F20EF30E040E050E0A222B322C42207
288
+ :10F1E000D52241E1AA0CBB1CCC1CDD1C4A95D1F7F1
289
+ :10F1F000EA0CFB1C0C1D1D1D81E090E0A0E0B0E0BE
290
+ :10F20000282239224A225B2235E1220C331C441C7D
291
+ :10F21000551C3A95D1F7E20CF31C041D151D57013E
292
+ :10F220006801AA0CBB1CCC1CDD1C85E192EE60E0E1
293
+ :10F230000F94C2F1C801AA27BB270F940DF2BB2778
294
+ :10F24000A12F902F8F2D0F940DF28E2D0F940DF274
295
+ :10F2500090E29093C6008091C00086FFFCCF809121
296
+ :10F26000C00080648093C000AEE3A093C60080918C
297
+ :10F27000C00086FFFCCF8091C00080648093C000F6
298
+ :10F28000C601AA27BB270F940DF2BB27AD2D9C2DDD
299
+ :10F290008B2D0F940DF28A2D0F940DF20F94DCF14B
300
+ :10F2A000CC5DDE4FE881F981C452D140F99709F471
301
+ :10F2B0004DCBF4E0EF2EF12C012D112D6E0C7F1CA7
302
+ :10F2C000801E911EF2CD83E093EE62E00F94F5F183
303
+ :10F2D0008AE192EE60E00F94C2F18091C00087FF56
304
+ :10F2E000FCCF1091C6001F751093C6008091C0001E
305
+ :10F2F00086FFFCCF8091C00080648093C0000F9493
306
+ :10F30000DCF1812F81548A3108F036C1163409F4BA
307
+ :10F3100095C0173490F4133409F44EC0143430F40B
308
+ :10F320001134F1F0123409F01DC130C0143409F465
309
+ :10F3300059C0153409F016C16BC01A3409F4C4C0A1
310
+ :10F340001B3438F4173409F48FC0183409F00AC19B
311
+ :10F35000A1C01B3409F4D2C01C3409F003C1E8C0B9
312
+ :10F360008FEF81B90DC082B1809582B980E090E0C5
313
+ :10F37000E0EDF7E03197F1F70196883C9105C1F790
314
+ :10F380008091C00087FFEFCF12B8EFC08FEF84B934
315
+ :10F390000DC085B1809585B980E090E0E0EDF7E0A3
316
+ :10F3A0003197F1F70196883C9105C1F78091C00033
317
+ :10F3B00087FFEFCF15B8D9C08FEF87B90DC088B1DF
318
+ :10F3C000809588B980E090E0E0EDF7E03197F1F7C3
319
+ :10F3D0000196883C9105C1F78091C00087FFEFCF6F
320
+ :10F3E00018B8C3C08FEF8AB90DC08BB180958BB9A7
321
+ :10F3F00080E090E0E0EDF7E03197F1F70196883C8E
322
+ :10F400009105C1F78091C00087FFEFCF1BB8ADC059
323
+ :10F410008FEF8DB90DC08EB180958EB980E090E0F0
324
+ :10F42000E0EDF7E03197F1F70196883C9105C1F7DF
325
+ :10F430008091C00087FFEFCF1EB897C08FEF80BBD1
326
+ :10F440000DC081B3809581BB80E090E0E0EDF7E0F6
327
+ :10F450003197F1F70196883C9105C1F78091C00082
328
+ :10F4600087FFEFCF11BA81C08FEF83BB0DC084B38C
329
+ :10F47000809584BB80E090E0E0EDF7E03197F1F714
330
+ :10F480000196883C9105C1F78091C00087FFEFCFBE
331
+ :10F4900014BA6BC08FEF809301010FC080910201FD
332
+ :10F4A00080958093020180E090E0E0EDF7E03197F5
333
+ :10F4B000F1F70196883C9105C1F78091C00087FF64
334
+ :10F4C000EDCF1092020151C08FEF809304010FC065
335
+ :10F4D0008091050180958093050180E090E0E0ED4A
336
+ :10F4E000F7E03197F1F70196883C9105C1F78091DB
337
+ :10F4F000C00087FFEDCF1092050137C08FEF8093DA
338
+ :10F5000007010FC08091080180958093080180E079
339
+ :10F5100090E0E0EDF7E03197F1F70196883C910536
340
+ :10F52000C1F78091C00087FFEDCF109208011DC088
341
+ :10F530008FEF80930A010FC080910B01809580931B
342
+ :10F540000B0180E090E0E0EDF7E03197F1F70196F4
343
+ :10F55000883C9105C1F78091C00087FFEDCF1092E4
344
+ :10F560000B0103C085E292EEEEC98091C00087FFD7
345
+ :10F57000FCCF8091C600EAC988E392EEE4C98CE131
346
+ :10F5800091EEE1C988249924933011F1943028F444
347
+ :10F59000913089F09230B8F408C0953061F195301F
348
+ :10F5A000F0F0963009F048C043C02B3109F042C951
349
+ :10F5B00091E06BE13FC96227C15DDE4F2883CF52E6
350
+ :10F5C000D14092E037C9B22FA0E0622793E032C960
351
+ :10F5D000822F90E0A82BB92B622794E02BC92E3004
352
+ :10F5E00009F039C3622795E0C05DDE4F19821882A9
353
+ :10F5F000C053D1401FC9E1E0F0E0EC0FFD1FC05D3A
354
+ :10F60000DE4F08811981C053D140E00FF11F2083E4
355
+ :10F610000F5F1F4FC05DDE4F19830883C053D14079
356
+ :10F6200062270A171B0709F005C9D80196E002C92D
357
+ :10F63000261709F010C303C0973009F0FBC87724E0
358
+ :10F640009981933109F412C19431C8F4963009F4C8
359
+ :10F65000D8C0973050F4923009F406C1933009F4C1
360
+ :10F660006DC0913009F059C253C0913109F477C08F
361
+ :10F67000923108F0BBC0903109F04FC2F5C098310B
362
+ :10F6800009F487C0993150F4953109F4EFC09531F0
363
+ :10F6900008F4C6C1963109F040C2C2C19A3109F4DA
364
+ :10F6A0006CC09A3108F491C09B3109F45BC09D3164
365
+ :10F6B00009F033C29D81903359F48F81882311F46E
366
+ :10F6C0009EE11CC0813011F091E018C098E916C08D
367
+ :10F6D000892F807591F0903539F4E0E0F0E089E011
368
+ :10F6E0008093570094910AC0983539F4E3E0F0E034
369
+ :10F6F00089E080935700949101C090E01A821B82A8
370
+ :10F700008D818C831D829E831F8227E030E009C299
371
+ :10F710001A8288E08B8381E48C8386E58D8382E581
372
+ :10F720008E8389E48F8383E5888780E589878FE5E9
373
+ :10F730008A8782E38B872BE030E0F3C18A818139AD
374
+ :10F7400041F0823941F0803911F48FE005C080E04A
375
+ :10F7500003C082E001C08AE01A828B8344C0772410
376
+ :10F76000739482C08D81882311F48EE12CC0813086
377
+ :10F7700011F081E028C088E926C01A82E1E0F0E0BB
378
+ :10F7800089E08093570084918B831C8224E030E0D1
379
+ :10F79000C8C18B81803589F48C81883039F4E2E0EE
380
+ :10F7A000F0E089E08093570084910DC0E0E0F0E044
381
+ :10F7B00089E080935700849106C0E3E0F0E089E09F
382
+ :10F7C0008093570084911A82DFCF8D81836C99E0FA
383
+ :10F7D000E1E0F0E0082E90935700E89507B600FCB2
384
+ :10F7E000FDCF1A821B8223E030E09BC180EC8A832C
385
+ :10F7F000CE5CDE4F188219821A821B82C253D1401E
386
+ :10F800008EC18A8190E0A0E0B0E0582F44273327D2
387
+ :10F8100022278B8190E0A0E0B0E0DC0199278827C7
388
+ :10F82000282B392B4A2B5B2B8D8190E0A0E0B0E098
389
+ :10F83000282B392B4A2B5B2B8C8190E0A0E0B0E089
390
+ :10F84000BA2FA92F982F8827282B392B4A2B5B2BCF
391
+ :10F85000220F331F441F551FC05EDE4F288339839C
392
+ :10F860004A835B83C052D1401A8259C13A81C95C34
393
+ :10F87000DE4F3883C753D140CA5CDE4F1882C6536F
394
+ :10F88000D1408B81C82EDD24CA5CDE4F488159816E
395
+ :10F89000C653D140C42AD52A933109F082C0CE5C28
396
+ :10F8A000DE4F88819981AA81BB81C253D1408050AB
397
+ :10F8B000904CA340B04030F583E0CE5CDE4FE88052
398
+ :10F8C000F9800A811B81C253D140F70100935B008C
399
+ :10F8D00080935700E89507B600FCFDCFCE5CDE4F65
400
+ :10F8E000088119812A813B81C253D14000501F4FAA
401
+ :10F8F0002F4F3F4FCE5CDE4F088319832A833B8313
402
+ :10F90000C253D140C05EDE4F488159816A817B81FC
403
+ :10F91000C052D140DE011B9631E08C9111962C91A2
404
+ :10F9200011971296C75CDE4F2883C953D140C85C3B
405
+ :10F93000DE4F1882C853D14090E0C85CDE4FE881AA
406
+ :10F94000F981C853D1408E2B9F2B0C01FA01609393
407
+ :10F950005B0030935700E89511244E5F5F4F6F4F67
408
+ :10F960007F4F0EEFE02E0FEFF02ECE0CDF1CC114F8
409
+ :10F97000D10499F685E0C05EDE4F088119812A81A5
410
+ :10F980003B81C052D140F80120935B008093570027
411
+ :10F99000E89507B600FCFDCF81E180935700E8951C
412
+ :10F9A00035C0C05EDE4F88819981AA81BB81C0527B
413
+ :10F9B000D140B695A795979587957C018601ABE0D8
414
+ :10F9C000AA2EB12CAC0EBD1E0BC0D5016D915D01F0
415
+ :10F9D000C7010F947FFE0894E11CF11C01501040F8
416
+ :10F9E0000115110591F7A60160E070E0440F551F65
417
+ :10F9F000661F771FC05EDE4FE880F9800A811B8199
418
+ :10FA0000C052D1404E0D5F1D601F711F1A82C05E33
419
+ :10FA1000DE4F488359836A837B83C052D1407FC0C5
420
+ :10FA2000FA80C55CDE4FF882CB53D140C65CDE4F16
421
+ :10FA30001882CA53D1408B81C82EDD24C65CDE4FAC
422
+ :10FA400008811981CA53D140C02AD12A1A828981DA
423
+ :10FA5000BE016D5F7F4F843121F59601C05EDE4FA0
424
+ :10FA6000E880F9800A811B81C052D1400BBFF701A9
425
+ :10FA700087919691DB018C9311969C936E5F7F4FDB
426
+ :10FA8000D801C7010296A11DB11DC05EDE4F88835B
427
+ :10FA90009983AA83BB83C052D14022503040F1F6F3
428
+ :10FAA00036C0C05EDE4F288139814A815B81C052F9
429
+ :10FAB000D1400894C108D108760100E010E0089414
430
+ :10FAC000C11CD11C0894E11CF11C011D111DE20E8A
431
+ :10FAD000F31E041F151F21BDBB27A52F942F832FB5
432
+ :10FAE00082BD2F5F3F4F4F4F5F4FF89A80B5DB01CC
433
+ :10FAF0008D93BD012E153F054007510761F7C05E8C
434
+ :10FB0000DE4F288339834A835B83C052D1409601FC
435
+ :10FB10002D5F3F4FFB01108204C080EC8A8322E0FE
436
+ :10FB200030E08BE18093C6008091C00086FFFCCF5F
437
+ :10FB30008091C00080648093C000C15DDE4FF88179
438
+ :10FB4000CF52D140F093C6008091C00086FFFCCF19
439
+ :10FB50008091C00080648093C000432F3093C60022
440
+ :10FB60008091C00086FFFCCF8091C00080648093AC
441
+ :10FB7000C000922F2093C6008091C00086FFFCCF6A
442
+ :10FB80008091C00080648093C0008EE08093C600A6
443
+ :10FB90008091C00086FFFCCF8091C000806480937C
444
+ :10FBA000C00065E1C15DDE4FE880CF52D1406E25D7
445
+ :10FBB00069276427FE01319610C090819093C6009A
446
+ :10FBC0008091C00086FFFCCF31968091C000806498
447
+ :10FBD0008093C0006927215030402115310569F715
448
+ :10FBE0006093C6008091C00086FFFCCF8091C0006A
449
+ :10FBF00080648093C00085B1805885B9772081F4F6
450
+ :10FC0000C15DDE4F0881CF52D1400F5FC15DDE4F35
451
+ :10FC10000883CF52D14090E0A0E0B0E00D941AF4F8
452
+ :10FC200027982F9880E090E020ED37E0F901319798
453
+ :10FC3000F1F7019684369105C9F700008091C00064
454
+ :10FC40008D7F8093C00081E180935700E895EE2777
455
+ :10FC5000FF270994FFCF90E00D941AF497FB092E2B
456
+ :10FC600007260AD077FD04D02ED006D000201AF443
457
+ :10FC7000709561957F4F0895F6F7909581959F4F08
458
+ :10FC80000895A1E21A2EAA1BBB1BFD010DC0AA1FDD
459
+ :10FC9000BB1FEE1FFF1FA217B307E407F50720F0F5
460
+ :10FCA000A21BB30BE40BF50B661F771F881F991F70
461
+ :10FCB0001A9469F760957095809590959B01AC01B9
462
+ :10FCC000BD01CF010895AA1BBB1B51E107C0AA1FAC
463
+ :10FCD000BB1FA617B70710F0A61BB70B881F991FED
464
+ :10FCE0005A95A9F780959095BC01CD010895F99991
465
+ :10FCF000FECF92BD81BDF89A992780B50895262F31
466
+ :10FD0000F999FECF1FBA92BD81BD20BD0FB6F89400
467
+ :0EFD1000FA9AF99A0FBE01960895F894FFCF63
468
+ :040000033000E000E9
469
+ :00000001FF
hardware/arduino/avr/cores/arduino/Arduino.h ADDED
@@ -0,0 +1,260 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ Arduino.h - Main include file for the Arduino SDK
3
+ Copyright (c) 2005-2013 Arduino Team. 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 Arduino_h
21
+ #define Arduino_h
22
+
23
+ #include <stdlib.h>
24
+ #include <stdbool.h>
25
+ #include <string.h>
26
+ #include <math.h>
27
+
28
+ #include <avr/pgmspace.h>
29
+ #include <avr/io.h>
30
+ #include <avr/interrupt.h>
31
+
32
+ #include "binary.h"
33
+
34
+ #ifdef __cplusplus
35
+ extern "C"{
36
+ #endif
37
+
38
+ void yield(void);
39
+
40
+ #define HIGH 0x1
41
+ #define LOW 0x0
42
+
43
+ #define INPUT 0x0
44
+ #define OUTPUT 0x1
45
+ #define INPUT_PULLUP 0x2
46
+
47
+ #define PI 3.1415926535897932384626433832795
48
+ #define HALF_PI 1.5707963267948966192313216916398
49
+ #define TWO_PI 6.283185307179586476925286766559
50
+ #define DEG_TO_RAD 0.017453292519943295769236907684886
51
+ #define RAD_TO_DEG 57.295779513082320876798154814105
52
+ #define EULER 2.718281828459045235360287471352
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
+ #if defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
65
+ #define DEFAULT 0
66
+ #define EXTERNAL 1
67
+ #define INTERNAL1V1 2
68
+ #define INTERNAL INTERNAL1V1
69
+ #elif defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
70
+ #define DEFAULT 0
71
+ #define EXTERNAL 4
72
+ #define INTERNAL1V1 8
73
+ #define INTERNAL INTERNAL1V1
74
+ #define INTERNAL2V56 9
75
+ #define INTERNAL2V56_EXTCAP 13
76
+ #else
77
+ #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega644__) || defined(__AVR_ATmega644A__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644PA__)
78
+ #define INTERNAL1V1 2
79
+ #define INTERNAL2V56 3
80
+ #else
81
+ #define INTERNAL 3
82
+ #endif
83
+ #define DEFAULT 1
84
+ #define EXTERNAL 0
85
+ #endif
86
+
87
+ // undefine stdlib's abs if encountered
88
+ #ifdef abs
89
+ #undef abs
90
+ #endif
91
+
92
+ #define min(a,b) ((a)<(b)?(a):(b))
93
+ #define max(a,b) ((a)>(b)?(a):(b))
94
+ #define abs(x) ((x)>0?(x):-(x))
95
+ #define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
96
+ #define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
97
+ #define radians(deg) ((deg)*DEG_TO_RAD)
98
+ #define degrees(rad) ((rad)*RAD_TO_DEG)
99
+ #define sq(x) ((x)*(x))
100
+
101
+ #define interrupts() sei()
102
+ #define noInterrupts() cli()
103
+
104
+ #define clockCyclesPerMicrosecond() ( F_CPU / 1000000L )
105
+ #define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() )
106
+ #define microsecondsToClockCycles(a) ( (a) * clockCyclesPerMicrosecond() )
107
+
108
+ #define lowByte(w) ((uint8_t) ((w) & 0xff))
109
+ #define highByte(w) ((uint8_t) ((w) >> 8))
110
+
111
+ #define bitRead(value, bit) (((value) >> (bit)) & 0x01)
112
+ #define bitSet(value, bit) ((value) |= (1UL << (bit)))
113
+ #define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
114
+ #define bitToggle(value, bit) ((value) ^= (1UL << (bit)))
115
+ #define bitWrite(value, bit, bitvalue) ((bitvalue) ? bitSet(value, bit) : bitClear(value, bit))
116
+
117
+ // avr-libc defines _NOP() since 1.6.2
118
+ #ifndef _NOP
119
+ #define _NOP() do { __asm__ volatile ("nop"); } while (0)
120
+ #endif
121
+
122
+ typedef unsigned int word;
123
+
124
+ #define bit(b) (1UL << (b))
125
+
126
+ typedef bool boolean;
127
+ typedef uint8_t byte;
128
+
129
+ void init(void);
130
+ void initVariant(void);
131
+
132
+ int atexit(void (*func)()) __attribute__((weak));
133
+
134
+ void pinMode(uint8_t pin, uint8_t mode);
135
+ void digitalWrite(uint8_t pin, uint8_t val);
136
+ int digitalRead(uint8_t pin);
137
+ int analogRead(uint8_t pin);
138
+ void analogReference(uint8_t mode);
139
+ void analogWrite(uint8_t pin, int val);
140
+
141
+ unsigned long millis(void);
142
+ unsigned long micros(void);
143
+ void delay(unsigned long ms);
144
+ void delayMicroseconds(unsigned int us);
145
+ unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout);
146
+ unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout);
147
+
148
+ void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val);
149
+ uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder);
150
+
151
+ void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode);
152
+ void detachInterrupt(uint8_t interruptNum);
153
+
154
+ void setup(void);
155
+ void loop(void);
156
+
157
+ // Get the bit location within the hardware port of the given virtual pin.
158
+ // This comes from the pins_*.c file for the active board configuration.
159
+
160
+ #define analogInPinToBit(P) (P)
161
+
162
+ // On the ATmega1280, the addresses of some of the port registers are
163
+ // greater than 255, so we can't store them in uint8_t's.
164
+ extern const uint16_t PROGMEM port_to_mode_PGM[];
165
+ extern const uint16_t PROGMEM port_to_input_PGM[];
166
+ extern const uint16_t PROGMEM port_to_output_PGM[];
167
+
168
+ extern const uint8_t PROGMEM digital_pin_to_port_PGM[];
169
+ // extern const uint8_t PROGMEM digital_pin_to_bit_PGM[];
170
+ extern const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[];
171
+ extern const uint8_t PROGMEM digital_pin_to_timer_PGM[];
172
+
173
+ // Get the bit location within the hardware port of the given virtual pin.
174
+ // This comes from the pins_*.c file for the active board configuration.
175
+ //
176
+ // These perform slightly better as macros compared to inline functions
177
+ //
178
+ #define digitalPinToPort(P) ( pgm_read_byte( digital_pin_to_port_PGM + (P) ) )
179
+ #define digitalPinToBitMask(P) ( pgm_read_byte( digital_pin_to_bit_mask_PGM + (P) ) )
180
+ #define digitalPinToTimer(P) ( pgm_read_byte( digital_pin_to_timer_PGM + (P) ) )
181
+ #define analogInPinToBit(P) (P)
182
+ #define portOutputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_output_PGM + (P))) )
183
+ #define portInputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_input_PGM + (P))) )
184
+ #define portModeRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_mode_PGM + (P))) )
185
+
186
+ #define NOT_A_PIN 0
187
+ #define NOT_A_PORT 0
188
+
189
+ #define NOT_AN_INTERRUPT -1
190
+
191
+ #ifdef ARDUINO_MAIN
192
+ #define PA 1
193
+ #define PB 2
194
+ #define PC 3
195
+ #define PD 4
196
+ #define PE 5
197
+ #define PF 6
198
+ #define PG 7
199
+ #define PH 8
200
+ #define PJ 10
201
+ #define PK 11
202
+ #define PL 12
203
+ #endif
204
+
205
+ #define NOT_ON_TIMER 0
206
+ #define TIMER0A 1
207
+ #define TIMER0B 2
208
+ #define TIMER1A 3
209
+ #define TIMER1B 4
210
+ #define TIMER1C 5
211
+ #define TIMER2 6
212
+ #define TIMER2A 7
213
+ #define TIMER2B 8
214
+
215
+ #define TIMER3A 9
216
+ #define TIMER3B 10
217
+ #define TIMER3C 11
218
+ #define TIMER4A 12
219
+ #define TIMER4B 13
220
+ #define TIMER4C 14
221
+ #define TIMER4D 15
222
+ #define TIMER5A 16
223
+ #define TIMER5B 17
224
+ #define TIMER5C 18
225
+
226
+ #ifdef __cplusplus
227
+ } // extern "C"
228
+ #endif
229
+
230
+ #ifdef __cplusplus
231
+ #include "WCharacter.h"
232
+ #include "WString.h"
233
+ #include "HardwareSerial.h"
234
+ #include "USBAPI.h"
235
+ #if defined(HAVE_HWSERIAL0) && defined(HAVE_CDCSERIAL)
236
+ #error "Targets with both UART0 and CDC serial not supported"
237
+ #endif
238
+
239
+ uint16_t makeWord(uint16_t w);
240
+ uint16_t makeWord(byte h, byte l);
241
+
242
+ #define word(...) makeWord(__VA_ARGS__)
243
+
244
+ unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L);
245
+ unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L);
246
+
247
+ void tone(uint8_t _pin, unsigned int frequency, unsigned long duration = 0);
248
+ void noTone(uint8_t _pin);
249
+
250
+ // WMath prototypes
251
+ long random(long);
252
+ long random(long, long);
253
+ void randomSeed(unsigned long);
254
+ long map(long, long, long, long, long);
255
+
256
+ #endif
257
+
258
+ #include "pins_arduino.h"
259
+
260
+ #endif
hardware/arduino/avr/cores/arduino/CDC.cpp ADDED
@@ -0,0 +1,302 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+
3
+ /* Copyright (c) 2011, Peter Barrett
4
+ **
5
+ ** Permission to use, copy, modify, and/or distribute this software for
6
+ ** any purpose with or without fee is hereby granted, provided that the
7
+ ** above copyright notice and this permission notice appear in all copies.
8
+ **
9
+ ** THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10
+ ** WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11
+ ** WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR
12
+ ** BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
13
+ ** OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
14
+ ** WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
15
+ ** ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
16
+ ** SOFTWARE.
17
+ */
18
+
19
+ #include "USBAPI.h"
20
+ #include <avr/wdt.h>
21
+ #include <util/atomic.h>
22
+
23
+ #if defined(USBCON)
24
+
25
+ typedef struct
26
+ {
27
+ u32 dwDTERate;
28
+ u8 bCharFormat;
29
+ u8 bParityType;
30
+ u8 bDataBits;
31
+ u8 lineState;
32
+ } LineInfo;
33
+
34
+ static volatile LineInfo _usbLineInfo = { 57600, 0x00, 0x00, 0x00, 0x00 };
35
+ static volatile int32_t breakValue = -1;
36
+
37
+ static u8 wdtcsr_save;
38
+
39
+ #define WEAK __attribute__ ((weak))
40
+
41
+ extern const CDCDescriptor _cdcInterface PROGMEM;
42
+ const CDCDescriptor _cdcInterface =
43
+ {
44
+ D_IAD(0,2,CDC_COMMUNICATION_INTERFACE_CLASS,CDC_ABSTRACT_CONTROL_MODEL,0),
45
+
46
+ // CDC communication interface
47
+ D_INTERFACE(CDC_ACM_INTERFACE,1,CDC_COMMUNICATION_INTERFACE_CLASS,CDC_ABSTRACT_CONTROL_MODEL,0),
48
+ D_CDCCS(CDC_HEADER,0x10,0x01), // Header (1.10 bcd)
49
+ D_CDCCS(CDC_CALL_MANAGEMENT,1,1), // Device handles call management (not)
50
+ D_CDCCS4(CDC_ABSTRACT_CONTROL_MANAGEMENT,6), // SET_LINE_CODING, GET_LINE_CODING, SET_CONTROL_LINE_STATE supported
51
+ D_CDCCS(CDC_UNION,CDC_ACM_INTERFACE,CDC_DATA_INTERFACE), // Communication interface is master, data interface is slave 0
52
+ D_ENDPOINT(USB_ENDPOINT_IN (CDC_ENDPOINT_ACM),USB_ENDPOINT_TYPE_INTERRUPT,0x10,0x40),
53
+
54
+ // CDC data interface
55
+ D_INTERFACE(CDC_DATA_INTERFACE,2,CDC_DATA_INTERFACE_CLASS,0,0),
56
+ D_ENDPOINT(USB_ENDPOINT_OUT(CDC_ENDPOINT_OUT),USB_ENDPOINT_TYPE_BULK,USB_EP_SIZE,0),
57
+ D_ENDPOINT(USB_ENDPOINT_IN (CDC_ENDPOINT_IN ),USB_ENDPOINT_TYPE_BULK,USB_EP_SIZE,0)
58
+ };
59
+
60
+ bool isLUFAbootloader()
61
+ {
62
+ return pgm_read_word(FLASHEND - 1) == NEW_LUFA_SIGNATURE;
63
+ }
64
+
65
+ int CDC_GetInterface(u8* interfaceNum)
66
+ {
67
+ interfaceNum[0] += 2; // uses 2
68
+ return USB_SendControl(TRANSFER_PGM,&_cdcInterface,sizeof(_cdcInterface));
69
+ }
70
+
71
+ bool CDC_Setup(USBSetup& setup)
72
+ {
73
+ u8 r = setup.bRequest;
74
+ u8 requestType = setup.bmRequestType;
75
+
76
+ if (REQUEST_DEVICETOHOST_CLASS_INTERFACE == requestType)
77
+ {
78
+ if (CDC_GET_LINE_CODING == r)
79
+ {
80
+ USB_SendControl(0,(void*)&_usbLineInfo,7);
81
+ return true;
82
+ }
83
+ }
84
+
85
+ if (REQUEST_HOSTTODEVICE_CLASS_INTERFACE == requestType)
86
+ {
87
+ if (CDC_SEND_BREAK == r)
88
+ {
89
+ breakValue = ((uint16_t)setup.wValueH << 8) | setup.wValueL;
90
+ }
91
+
92
+ if (CDC_SET_LINE_CODING == r)
93
+ {
94
+ USB_RecvControl((void*)&_usbLineInfo,7);
95
+ }
96
+
97
+ if (CDC_SET_CONTROL_LINE_STATE == r)
98
+ {
99
+ _usbLineInfo.lineState = setup.wValueL;
100
+
101
+ // auto-reset into the bootloader is triggered when the port, already
102
+ // open at 1200 bps, is closed. this is the signal to start the watchdog
103
+ // with a relatively long period so it can finish housekeeping tasks
104
+ // like servicing endpoints before the sketch ends
105
+
106
+ uint16_t magic_key_pos = MAGIC_KEY_POS;
107
+
108
+ // If we don't use the new RAMEND directly, check manually if we have a newer bootloader.
109
+ // This is used to keep compatible with the old leonardo bootloaders.
110
+ // You are still able to set the magic key position manually to RAMEND-1 to save a few bytes for this check.
111
+ #if MAGIC_KEY_POS != (RAMEND-1)
112
+ // For future boards save the key in the inproblematic RAMEND
113
+ // Which is reserved for the main() return value (which will never return)
114
+ if (isLUFAbootloader()) {
115
+ // horray, we got a new bootloader!
116
+ magic_key_pos = (RAMEND-1);
117
+ }
118
+ #endif
119
+
120
+ // We check DTR state to determine if host port is open (bit 0 of lineState).
121
+ if (1200 == _usbLineInfo.dwDTERate && (_usbLineInfo.lineState & 0x01) == 0)
122
+ {
123
+ #if MAGIC_KEY_POS != (RAMEND-1)
124
+ // Backup ram value if its not a newer bootloader and it hasn't already been saved.
125
+ // This should avoid memory corruption at least a bit, not fully
126
+ if (magic_key_pos != (RAMEND-1) && *(uint16_t *)magic_key_pos != MAGIC_KEY) {
127
+ *(uint16_t *)(RAMEND-1) = *(uint16_t *)magic_key_pos;
128
+ }
129
+ #endif
130
+ // Store boot key
131
+ *(uint16_t *)magic_key_pos = MAGIC_KEY;
132
+ // Save the watchdog state in case the reset is aborted.
133
+ wdtcsr_save = WDTCSR;
134
+ wdt_enable(WDTO_120MS);
135
+ }
136
+ else if (*(uint16_t *)magic_key_pos == MAGIC_KEY)
137
+ {
138
+ // Most OSs do some intermediate steps when configuring ports and DTR can
139
+ // twiggle more than once before stabilizing.
140
+ // To avoid spurious resets we set the watchdog to 120ms and eventually
141
+ // cancel if DTR goes back high.
142
+ // Cancellation is only done if an auto-reset was started, which is
143
+ // indicated by the magic key having been set.
144
+
145
+ wdt_reset();
146
+ // Restore the watchdog state in case the sketch was using it.
147
+ WDTCSR |= (1<<WDCE) | (1<<WDE);
148
+ WDTCSR = wdtcsr_save;
149
+ #if MAGIC_KEY_POS != (RAMEND-1)
150
+ // Restore backed up (old bootloader) magic key data
151
+ if (magic_key_pos != (RAMEND-1)) {
152
+ *(uint16_t *)magic_key_pos = *(uint16_t *)(RAMEND-1);
153
+ } else
154
+ #endif
155
+ {
156
+ // Clean up RAMEND key
157
+ *(uint16_t *)magic_key_pos = 0x0000;
158
+ }
159
+ }
160
+ }
161
+ return true;
162
+ }
163
+ return false;
164
+ }
165
+
166
+
167
+ void Serial_::begin(unsigned long /* baud_count */)
168
+ {
169
+ peek_buffer = -1;
170
+ }
171
+
172
+ void Serial_::begin(unsigned long /* baud_count */, byte /* config */)
173
+ {
174
+ peek_buffer = -1;
175
+ }
176
+
177
+ void Serial_::end(void)
178
+ {
179
+ }
180
+
181
+ int Serial_::available(void)
182
+ {
183
+ if (peek_buffer >= 0) {
184
+ return 1 + USB_Available(CDC_RX);
185
+ }
186
+ return USB_Available(CDC_RX);
187
+ }
188
+
189
+ int Serial_::peek(void)
190
+ {
191
+ if (peek_buffer < 0)
192
+ peek_buffer = USB_Recv(CDC_RX);
193
+ return peek_buffer;
194
+ }
195
+
196
+ int Serial_::read(void)
197
+ {
198
+ if (peek_buffer >= 0) {
199
+ int c = peek_buffer;
200
+ peek_buffer = -1;
201
+ return c;
202
+ }
203
+ return USB_Recv(CDC_RX);
204
+ }
205
+
206
+ int Serial_::availableForWrite(void)
207
+ {
208
+ return USB_SendSpace(CDC_TX);
209
+ }
210
+
211
+ void Serial_::flush(void)
212
+ {
213
+ USB_Flush(CDC_TX);
214
+ }
215
+
216
+ size_t Serial_::write(uint8_t c)
217
+ {
218
+ return write(&c, 1);
219
+ }
220
+
221
+ size_t Serial_::write(const uint8_t *buffer, size_t size)
222
+ {
223
+ /* only try to send bytes if the high-level CDC connection itself
224
+ is open (not just the pipe) - the OS should set lineState when the port
225
+ is opened and clear lineState when the port is closed.
226
+ bytes sent before the user opens the connection or after
227
+ the connection is closed are lost - just like with a UART. */
228
+
229
+ // TODO - ZE - check behavior on different OSes and test what happens if an
230
+ // open connection isn't broken cleanly (cable is yanked out, host dies
231
+ // or locks up, or host virtual serial port hangs)
232
+ if (_usbLineInfo.lineState > 0) {
233
+ int r = USB_Send(CDC_TX,buffer,size);
234
+ if (r > 0) {
235
+ return r;
236
+ } else {
237
+ setWriteError();
238
+ return 0;
239
+ }
240
+ }
241
+ setWriteError();
242
+ return 0;
243
+ }
244
+
245
+ // This operator is a convenient way for a sketch to check whether the
246
+ // port has actually been configured and opened by the host (as opposed
247
+ // to just being connected to the host). It can be used, for example, in
248
+ // setup() before printing to ensure that an application on the host is
249
+ // actually ready to receive and display the data.
250
+ // We add a short delay before returning to fix a bug observed by Federico
251
+ // where the port is configured (lineState != 0) but not quite opened.
252
+ Serial_::operator bool() {
253
+ bool result = false;
254
+ if (_usbLineInfo.lineState > 0)
255
+ result = true;
256
+ delay(10);
257
+ return result;
258
+ }
259
+
260
+ unsigned long Serial_::baud() {
261
+ // Disable interrupts while reading a multi-byte value
262
+ uint32_t baudrate;
263
+ ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
264
+ baudrate = _usbLineInfo.dwDTERate;
265
+ }
266
+ return baudrate;
267
+ }
268
+
269
+ uint8_t Serial_::stopbits() {
270
+ return _usbLineInfo.bCharFormat;
271
+ }
272
+
273
+ uint8_t Serial_::paritytype() {
274
+ return _usbLineInfo.bParityType;
275
+ }
276
+
277
+ uint8_t Serial_::numbits() {
278
+ return _usbLineInfo.bDataBits;
279
+ }
280
+
281
+ bool Serial_::dtr() {
282
+ return _usbLineInfo.lineState & 0x1;
283
+ }
284
+
285
+ bool Serial_::rts() {
286
+ return _usbLineInfo.lineState & 0x2;
287
+ }
288
+
289
+ int32_t Serial_::readBreak() {
290
+ int32_t ret;
291
+ // Disable IRQs while reading and clearing breakValue to make
292
+ // sure we don't overwrite a value just set by the ISR.
293
+ ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
294
+ ret = breakValue;
295
+ breakValue = -1;
296
+ }
297
+ return ret;
298
+ }
299
+
300
+ Serial_ Serial;
301
+
302
+ #endif /* if defined(USBCON) */
hardware/arduino/avr/cores/arduino/Client.h ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ Client.h - Base class that provides Client
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 client_h
21
+ #define client_h
22
+ #include "Print.h"
23
+ #include "Stream.h"
24
+ #include "IPAddress.h"
25
+
26
+ class Client : public Stream {
27
+
28
+ public:
29
+ virtual int connect(IPAddress ip, uint16_t port) =0;
30
+ virtual int connect(const char *host, uint16_t port) =0;
31
+ virtual size_t write(uint8_t) =0;
32
+ virtual size_t write(const uint8_t *buf, size_t size) =0;
33
+ virtual int available() = 0;
34
+ virtual int read() = 0;
35
+ virtual int read(uint8_t *buf, size_t size) = 0;
36
+ virtual int peek() = 0;
37
+ virtual void flush() = 0;
38
+ virtual void stop() = 0;
39
+ virtual uint8_t connected() = 0;
40
+ virtual operator bool() = 0;
41
+ protected:
42
+ uint8_t* rawIPAddress(IPAddress& addr) { return addr.raw_address(); };
43
+ };
44
+
45
+ #endif
hardware/arduino/avr/cores/arduino/HardwareSerial.cpp ADDED
@@ -0,0 +1,281 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ Modified 28 September 2010 by Mark Sproul
21
+ Modified 14 August 2012 by Alarus
22
+ Modified 3 December 2013 by Matthijs Kooijman
23
+ */
24
+
25
+ #include <stdlib.h>
26
+ #include <stdio.h>
27
+ #include <string.h>
28
+ #include <inttypes.h>
29
+ #include <util/atomic.h>
30
+ #include "Arduino.h"
31
+
32
+ #include "HardwareSerial.h"
33
+ #include "HardwareSerial_private.h"
34
+
35
+ // this next line disables the entire HardwareSerial.cpp,
36
+ // this is so I can support Attiny series and any other chip without a uart
37
+ #if defined(HAVE_HWSERIAL0) || defined(HAVE_HWSERIAL1) || defined(HAVE_HWSERIAL2) || defined(HAVE_HWSERIAL3)
38
+
39
+ // SerialEvent functions are weak, so when the user doesn't define them,
40
+ // the linker just sets their address to 0 (which is checked below).
41
+ // The Serialx_available is just a wrapper around Serialx.available(),
42
+ // but we can refer to it weakly so we don't pull in the entire
43
+ // HardwareSerial instance if the user doesn't also refer to it.
44
+ #if defined(HAVE_HWSERIAL0)
45
+ void serialEvent() __attribute__((weak));
46
+ bool Serial0_available() __attribute__((weak));
47
+ #endif
48
+
49
+ #if defined(HAVE_HWSERIAL1)
50
+ void serialEvent1() __attribute__((weak));
51
+ bool Serial1_available() __attribute__((weak));
52
+ #endif
53
+
54
+ #if defined(HAVE_HWSERIAL2)
55
+ void serialEvent2() __attribute__((weak));
56
+ bool Serial2_available() __attribute__((weak));
57
+ #endif
58
+
59
+ #if defined(HAVE_HWSERIAL3)
60
+ void serialEvent3() __attribute__((weak));
61
+ bool Serial3_available() __attribute__((weak));
62
+ #endif
63
+
64
+ void serialEventRun(void)
65
+ {
66
+ #if defined(HAVE_HWSERIAL0)
67
+ if (Serial0_available && serialEvent && Serial0_available()) serialEvent();
68
+ #endif
69
+ #if defined(HAVE_HWSERIAL1)
70
+ if (Serial1_available && serialEvent1 && Serial1_available()) serialEvent1();
71
+ #endif
72
+ #if defined(HAVE_HWSERIAL2)
73
+ if (Serial2_available && serialEvent2 && Serial2_available()) serialEvent2();
74
+ #endif
75
+ #if defined(HAVE_HWSERIAL3)
76
+ if (Serial3_available && serialEvent3 && Serial3_available()) serialEvent3();
77
+ #endif
78
+ }
79
+
80
+ // macro to guard critical sections when needed for large TX buffer sizes
81
+ #if (SERIAL_TX_BUFFER_SIZE>256)
82
+ #define TX_BUFFER_ATOMIC ATOMIC_BLOCK(ATOMIC_RESTORESTATE)
83
+ #else
84
+ #define TX_BUFFER_ATOMIC
85
+ #endif
86
+
87
+ // Actual interrupt handlers //////////////////////////////////////////////////////////////
88
+
89
+ void HardwareSerial::_tx_udr_empty_irq(void)
90
+ {
91
+ // If interrupts are enabled, there must be more data in the output
92
+ // buffer. Send the next byte
93
+ unsigned char c = _tx_buffer[_tx_buffer_tail];
94
+ _tx_buffer_tail = (_tx_buffer_tail + 1) % SERIAL_TX_BUFFER_SIZE;
95
+
96
+ *_udr = c;
97
+
98
+ // clear the TXC bit -- "can be cleared by writing a one to its bit
99
+ // location". This makes sure flush() won't return until the bytes
100
+ // actually got written. Other r/w bits are preserved, and zeroes
101
+ // written to the rest.
102
+
103
+ #ifdef MPCM0
104
+ *_ucsra = ((*_ucsra) & ((1 << U2X0) | (1 << MPCM0))) | (1 << TXC0);
105
+ #else
106
+ *_ucsra = ((*_ucsra) & ((1 << U2X0) | (1 << TXC0)));
107
+ #endif
108
+
109
+ if (_tx_buffer_head == _tx_buffer_tail) {
110
+ // Buffer empty, so disable interrupts
111
+ cbi(*_ucsrb, UDRIE0);
112
+ }
113
+ }
114
+
115
+ // Public Methods //////////////////////////////////////////////////////////////
116
+
117
+ void HardwareSerial::begin(unsigned long baud, byte config)
118
+ {
119
+ // Try u2x mode first
120
+ uint16_t baud_setting = (F_CPU / 4 / baud - 1) / 2;
121
+ *_ucsra = 1 << U2X0;
122
+
123
+ // hardcoded exception for 57600 for compatibility with the bootloader
124
+ // shipped with the Duemilanove and previous boards and the firmware
125
+ // on the 8U2 on the Uno and Mega 2560. Also, The baud_setting cannot
126
+ // be > 4095, so switch back to non-u2x mode if the baud rate is too
127
+ // low.
128
+ if (((F_CPU == 16000000UL) && (baud == 57600)) || (baud_setting >4095))
129
+ {
130
+ *_ucsra = 0;
131
+ baud_setting = (F_CPU / 8 / baud - 1) / 2;
132
+ }
133
+
134
+ // assign the baud_setting, a.k.a. ubrr (USART Baud Rate Register)
135
+ *_ubrrh = baud_setting >> 8;
136
+ *_ubrrl = baud_setting;
137
+
138
+ _written = false;
139
+
140
+ //set the data bits, parity, and stop bits
141
+ #if defined(__AVR_ATmega8__)
142
+ config |= 0x80; // select UCSRC register (shared with UBRRH)
143
+ #endif
144
+ *_ucsrc = config;
145
+
146
+ sbi(*_ucsrb, RXEN0);
147
+ sbi(*_ucsrb, TXEN0);
148
+ sbi(*_ucsrb, RXCIE0);
149
+ cbi(*_ucsrb, UDRIE0);
150
+ }
151
+
152
+ void HardwareSerial::end()
153
+ {
154
+ // wait for transmission of outgoing data
155
+ flush();
156
+
157
+ cbi(*_ucsrb, RXEN0);
158
+ cbi(*_ucsrb, TXEN0);
159
+ cbi(*_ucsrb, RXCIE0);
160
+ cbi(*_ucsrb, UDRIE0);
161
+
162
+ // clear any received data
163
+ _rx_buffer_head = _rx_buffer_tail;
164
+ }
165
+
166
+ int HardwareSerial::available(void)
167
+ {
168
+ return ((unsigned int)(SERIAL_RX_BUFFER_SIZE + _rx_buffer_head - _rx_buffer_tail)) % SERIAL_RX_BUFFER_SIZE;
169
+ }
170
+
171
+ int HardwareSerial::peek(void)
172
+ {
173
+ if (_rx_buffer_head == _rx_buffer_tail) {
174
+ return -1;
175
+ } else {
176
+ return _rx_buffer[_rx_buffer_tail];
177
+ }
178
+ }
179
+
180
+ int HardwareSerial::read(void)
181
+ {
182
+ // if the head isn't ahead of the tail, we don't have any characters
183
+ if (_rx_buffer_head == _rx_buffer_tail) {
184
+ return -1;
185
+ } else {
186
+ unsigned char c = _rx_buffer[_rx_buffer_tail];
187
+ _rx_buffer_tail = (rx_buffer_index_t)(_rx_buffer_tail + 1) % SERIAL_RX_BUFFER_SIZE;
188
+ return c;
189
+ }
190
+ }
191
+
192
+ int HardwareSerial::availableForWrite(void)
193
+ {
194
+ tx_buffer_index_t head;
195
+ tx_buffer_index_t tail;
196
+
197
+ TX_BUFFER_ATOMIC {
198
+ head = _tx_buffer_head;
199
+ tail = _tx_buffer_tail;
200
+ }
201
+ if (head >= tail) return SERIAL_TX_BUFFER_SIZE - 1 - head + tail;
202
+ return tail - head - 1;
203
+ }
204
+
205
+ void HardwareSerial::flush()
206
+ {
207
+ // If we have never written a byte, no need to flush. This special
208
+ // case is needed since there is no way to force the TXC (transmit
209
+ // complete) bit to 1 during initialization
210
+ if (!_written)
211
+ return;
212
+
213
+ while (bit_is_set(*_ucsrb, UDRIE0) || bit_is_clear(*_ucsra, TXC0)) {
214
+ if (bit_is_clear(SREG, SREG_I) && bit_is_set(*_ucsrb, UDRIE0))
215
+ // Interrupts are globally disabled, but the DR empty
216
+ // interrupt should be enabled, so poll the DR empty flag to
217
+ // prevent deadlock
218
+ if (bit_is_set(*_ucsra, UDRE0))
219
+ _tx_udr_empty_irq();
220
+ }
221
+ // If we get here, nothing is queued anymore (DRIE is disabled) and
222
+ // the hardware finished tranmission (TXC is set).
223
+ }
224
+
225
+ size_t HardwareSerial::write(uint8_t c)
226
+ {
227
+ _written = true;
228
+ // If the buffer and the data register is empty, just write the byte
229
+ // to the data register and be done. This shortcut helps
230
+ // significantly improve the effective datarate at high (>
231
+ // 500kbit/s) bitrates, where interrupt overhead becomes a slowdown.
232
+ if (_tx_buffer_head == _tx_buffer_tail && bit_is_set(*_ucsra, UDRE0)) {
233
+ // If TXC is cleared before writing UDR and the previous byte
234
+ // completes before writing to UDR, TXC will be set but a byte
235
+ // is still being transmitted causing flush() to return too soon.
236
+ // So writing UDR must happen first.
237
+ // Writing UDR and clearing TC must be done atomically, otherwise
238
+ // interrupts might delay the TXC clear so the byte written to UDR
239
+ // is transmitted (setting TXC) before clearing TXC. Then TXC will
240
+ // be cleared when no bytes are left, causing flush() to hang
241
+ ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
242
+ *_udr = c;
243
+ #ifdef MPCM0
244
+ *_ucsra = ((*_ucsra) & ((1 << U2X0) | (1 << MPCM0))) | (1 << TXC0);
245
+ #else
246
+ *_ucsra = ((*_ucsra) & ((1 << U2X0) | (1 << TXC0)));
247
+ #endif
248
+ }
249
+ return 1;
250
+ }
251
+ tx_buffer_index_t i = (_tx_buffer_head + 1) % SERIAL_TX_BUFFER_SIZE;
252
+
253
+ // If the output buffer is full, there's nothing for it other than to
254
+ // wait for the interrupt handler to empty it a bit
255
+ while (i == _tx_buffer_tail) {
256
+ if (bit_is_clear(SREG, SREG_I)) {
257
+ // Interrupts are disabled, so we'll have to poll the data
258
+ // register empty flag ourselves. If it is set, pretend an
259
+ // interrupt has happened and call the handler to free up
260
+ // space for us.
261
+ if(bit_is_set(*_ucsra, UDRE0))
262
+ _tx_udr_empty_irq();
263
+ } else {
264
+ // nop, the interrupt handler will free up space for us
265
+ }
266
+ }
267
+
268
+ _tx_buffer[_tx_buffer_head] = c;
269
+
270
+ // make atomic to prevent execution of ISR between setting the
271
+ // head pointer and setting the interrupt flag resulting in buffer
272
+ // retransmission
273
+ ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
274
+ _tx_buffer_head = i;
275
+ sbi(*_ucsrb, UDRIE0);
276
+ }
277
+
278
+ return 1;
279
+ }
280
+
281
+ #endif // whole file
hardware/arduino/avr/cores/arduino/HardwareSerial.h ADDED
@@ -0,0 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ Modified 28 September 2010 by Mark Sproul
20
+ Modified 14 August 2012 by Alarus
21
+ Modified 3 December 2013 by Matthijs Kooijman
22
+ */
23
+
24
+ #ifndef HardwareSerial_h
25
+ #define HardwareSerial_h
26
+
27
+ #include <inttypes.h>
28
+
29
+ #include "Stream.h"
30
+
31
+ // Define constants and variables for buffering incoming serial data. We're
32
+ // using a ring buffer (I think), in which head is the index of the location
33
+ // to which to write the next incoming character and tail is the index of the
34
+ // location from which to read.
35
+ // NOTE: a "power of 2" buffer size is reccomended to dramatically
36
+ // optimize all the modulo operations for ring buffers.
37
+ // WARNING: When buffer sizes are increased to > 256, the buffer index
38
+ // variables are automatically increased in size, but the extra
39
+ // atomicity guards needed for that are not implemented. This will
40
+ // often work, but occasionally a race condition can occur that makes
41
+ // Serial behave erratically. See https://github.com/arduino/Arduino/issues/2405
42
+ #if !defined(SERIAL_TX_BUFFER_SIZE)
43
+ #if ((RAMEND - RAMSTART) < 1023)
44
+ #define SERIAL_TX_BUFFER_SIZE 16
45
+ #else
46
+ #define SERIAL_TX_BUFFER_SIZE 64
47
+ #endif
48
+ #endif
49
+ #if !defined(SERIAL_RX_BUFFER_SIZE)
50
+ #if ((RAMEND - RAMSTART) < 1023)
51
+ #define SERIAL_RX_BUFFER_SIZE 16
52
+ #else
53
+ #define SERIAL_RX_BUFFER_SIZE 64
54
+ #endif
55
+ #endif
56
+ #if (SERIAL_TX_BUFFER_SIZE>256)
57
+ typedef uint16_t tx_buffer_index_t;
58
+ #else
59
+ typedef uint8_t tx_buffer_index_t;
60
+ #endif
61
+ #if (SERIAL_RX_BUFFER_SIZE>256)
62
+ typedef uint16_t rx_buffer_index_t;
63
+ #else
64
+ typedef uint8_t rx_buffer_index_t;
65
+ #endif
66
+
67
+ // Define config for Serial.begin(baud, config);
68
+ #define SERIAL_5N1 0x00
69
+ #define SERIAL_6N1 0x02
70
+ #define SERIAL_7N1 0x04
71
+ #define SERIAL_8N1 0x06
72
+ #define SERIAL_5N2 0x08
73
+ #define SERIAL_6N2 0x0A
74
+ #define SERIAL_7N2 0x0C
75
+ #define SERIAL_8N2 0x0E
76
+ #define SERIAL_5E1 0x20
77
+ #define SERIAL_6E1 0x22
78
+ #define SERIAL_7E1 0x24
79
+ #define SERIAL_8E1 0x26
80
+ #define SERIAL_5E2 0x28
81
+ #define SERIAL_6E2 0x2A
82
+ #define SERIAL_7E2 0x2C
83
+ #define SERIAL_8E2 0x2E
84
+ #define SERIAL_5O1 0x30
85
+ #define SERIAL_6O1 0x32
86
+ #define SERIAL_7O1 0x34
87
+ #define SERIAL_8O1 0x36
88
+ #define SERIAL_5O2 0x38
89
+ #define SERIAL_6O2 0x3A
90
+ #define SERIAL_7O2 0x3C
91
+ #define SERIAL_8O2 0x3E
92
+
93
+ class HardwareSerial : public Stream
94
+ {
95
+ protected:
96
+ volatile uint8_t * const _ubrrh;
97
+ volatile uint8_t * const _ubrrl;
98
+ volatile uint8_t * const _ucsra;
99
+ volatile uint8_t * const _ucsrb;
100
+ volatile uint8_t * const _ucsrc;
101
+ volatile uint8_t * const _udr;
102
+ // Has any byte been written to the UART since begin()
103
+ bool _written;
104
+
105
+ volatile rx_buffer_index_t _rx_buffer_head;
106
+ volatile rx_buffer_index_t _rx_buffer_tail;
107
+ volatile tx_buffer_index_t _tx_buffer_head;
108
+ volatile tx_buffer_index_t _tx_buffer_tail;
109
+
110
+ // Don't put any members after these buffers, since only the first
111
+ // 32 bytes of this struct can be accessed quickly using the ldd
112
+ // instruction.
113
+ unsigned char _rx_buffer[SERIAL_RX_BUFFER_SIZE];
114
+ unsigned char _tx_buffer[SERIAL_TX_BUFFER_SIZE];
115
+
116
+ public:
117
+ inline HardwareSerial(
118
+ volatile uint8_t *ubrrh, volatile uint8_t *ubrrl,
119
+ volatile uint8_t *ucsra, volatile uint8_t *ucsrb,
120
+ volatile uint8_t *ucsrc, volatile uint8_t *udr);
121
+ void begin(unsigned long baud) { begin(baud, SERIAL_8N1); }
122
+ void begin(unsigned long, uint8_t);
123
+ void end();
124
+ virtual int available(void);
125
+ virtual int peek(void);
126
+ virtual int read(void);
127
+ virtual int availableForWrite(void);
128
+ virtual void flush(void);
129
+ virtual size_t write(uint8_t);
130
+ inline size_t write(unsigned long n) { return write((uint8_t)n); }
131
+ inline size_t write(long n) { return write((uint8_t)n); }
132
+ inline size_t write(unsigned int n) { return write((uint8_t)n); }
133
+ inline size_t write(int n) { return write((uint8_t)n); }
134
+ using Print::write; // pull in write(str) and write(buf, size) from Print
135
+ operator bool() { return true; }
136
+
137
+ // Interrupt handlers - Not intended to be called externally
138
+ inline void _rx_complete_irq(void);
139
+ void _tx_udr_empty_irq(void);
140
+ };
141
+
142
+ #if defined(UBRRH) || defined(UBRR0H)
143
+ extern HardwareSerial Serial;
144
+ #define HAVE_HWSERIAL0
145
+ #endif
146
+ #if defined(UBRR1H)
147
+ extern HardwareSerial Serial1;
148
+ #define HAVE_HWSERIAL1
149
+ #endif
150
+ #if defined(UBRR2H)
151
+ extern HardwareSerial Serial2;
152
+ #define HAVE_HWSERIAL2
153
+ #endif
154
+ #if defined(UBRR3H)
155
+ extern HardwareSerial Serial3;
156
+ #define HAVE_HWSERIAL3
157
+ #endif
158
+
159
+ extern void serialEventRun(void) __attribute__((weak));
160
+
161
+ #endif
hardware/arduino/avr/cores/arduino/HardwareSerial0.cpp ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ HardwareSerial0.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
+ Modified 28 September 2010 by Mark Sproul
21
+ Modified 14 August 2012 by Alarus
22
+ Modified 3 December 2013 by Matthijs Kooijman
23
+ */
24
+
25
+ #include "Arduino.h"
26
+ #include "HardwareSerial.h"
27
+ #include "HardwareSerial_private.h"
28
+
29
+ // Each HardwareSerial is defined in its own file, since the linker pulls
30
+ // in the entire file when any element inside is used. --gc-sections can
31
+ // additionally cause unused symbols to be dropped, but ISRs have the
32
+ // "used" attribute so are never dropped and they keep the
33
+ // HardwareSerial instance in as well. Putting each instance in its own
34
+ // file prevents the linker from pulling in any unused instances in the
35
+ // first place.
36
+
37
+ #if defined(HAVE_HWSERIAL0)
38
+
39
+ #if defined(USART_RX_vect)
40
+ ISR(USART_RX_vect)
41
+ #elif defined(USART0_RX_vect)
42
+ ISR(USART0_RX_vect)
43
+ #elif defined(USART_RXC_vect)
44
+ ISR(USART_RXC_vect) // ATmega8
45
+ #else
46
+ #error "Don't know what the Data Received vector is called for Serial"
47
+ #endif
48
+ {
49
+ Serial._rx_complete_irq();
50
+ }
51
+
52
+ #if defined(UART0_UDRE_vect)
53
+ ISR(UART0_UDRE_vect)
54
+ #elif defined(UART_UDRE_vect)
55
+ ISR(UART_UDRE_vect)
56
+ #elif defined(USART0_UDRE_vect)
57
+ ISR(USART0_UDRE_vect)
58
+ #elif defined(USART_UDRE_vect)
59
+ ISR(USART_UDRE_vect)
60
+ #else
61
+ #error "Don't know what the Data Register Empty vector is called for Serial"
62
+ #endif
63
+ {
64
+ Serial._tx_udr_empty_irq();
65
+ }
66
+
67
+ #if defined(UBRRH) && defined(UBRRL)
68
+ HardwareSerial Serial(&UBRRH, &UBRRL, &UCSRA, &UCSRB, &UCSRC, &UDR);
69
+ #else
70
+ HardwareSerial Serial(&UBRR0H, &UBRR0L, &UCSR0A, &UCSR0B, &UCSR0C, &UDR0);
71
+ #endif
72
+
73
+ // Function that can be weakly referenced by serialEventRun to prevent
74
+ // pulling in this file if it's not otherwise used.
75
+ bool Serial0_available() {
76
+ return Serial.available();
77
+ }
78
+
79
+ #endif // HAVE_HWSERIAL0
hardware/arduino/avr/cores/arduino/HardwareSerial1.cpp ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ HardwareSerial1.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
+ Modified 28 September 2010 by Mark Sproul
21
+ Modified 14 August 2012 by Alarus
22
+ Modified 3 December 2013 by Matthijs Kooijman
23
+ */
24
+
25
+ #include "Arduino.h"
26
+ #include "HardwareSerial.h"
27
+ #include "HardwareSerial_private.h"
28
+
29
+ // Each HardwareSerial is defined in its own file, since the linker pulls
30
+ // in the entire file when any element inside is used. --gc-sections can
31
+ // additionally cause unused symbols to be dropped, but ISRs have the
32
+ // "used" attribute so are never dropped and they keep the
33
+ // HardwareSerial instance in as well. Putting each instance in its own
34
+ // file prevents the linker from pulling in any unused instances in the
35
+ // first place.
36
+
37
+ #if defined(HAVE_HWSERIAL1)
38
+
39
+ #if defined(UART1_RX_vect)
40
+ ISR(UART1_RX_vect)
41
+ #elif defined(USART1_RX_vect)
42
+ ISR(USART1_RX_vect)
43
+ #else
44
+ #error "Don't know what the Data Register Empty vector is called for Serial1"
45
+ #endif
46
+ {
47
+ Serial1._rx_complete_irq();
48
+ }
49
+
50
+ #if defined(UART1_UDRE_vect)
51
+ ISR(UART1_UDRE_vect)
52
+ #elif defined(USART1_UDRE_vect)
53
+ ISR(USART1_UDRE_vect)
54
+ #else
55
+ #error "Don't know what the Data Register Empty vector is called for Serial1"
56
+ #endif
57
+ {
58
+ Serial1._tx_udr_empty_irq();
59
+ }
60
+
61
+ HardwareSerial Serial1(&UBRR1H, &UBRR1L, &UCSR1A, &UCSR1B, &UCSR1C, &UDR1);
62
+
63
+ // Function that can be weakly referenced by serialEventRun to prevent
64
+ // pulling in this file if it's not otherwise used.
65
+ bool Serial1_available() {
66
+ return Serial1.available();
67
+ }
68
+
69
+ #endif // HAVE_HWSERIAL1
hardware/arduino/avr/cores/arduino/HardwareSerial2.cpp ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ HardwareSerial2.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
+ Modified 28 September 2010 by Mark Sproul
21
+ Modified 14 August 2012 by Alarus
22
+ Modified 3 December 2013 by Matthijs Kooijman
23
+ */
24
+
25
+ #include "Arduino.h"
26
+ #include "HardwareSerial.h"
27
+ #include "HardwareSerial_private.h"
28
+
29
+ // Each HardwareSerial is defined in its own file, since the linker pulls
30
+ // in the entire file when any element inside is used. --gc-sections can
31
+ // additionally cause unused symbols to be dropped, but ISRs have the
32
+ // "used" attribute so are never dropped and they keep the
33
+ // HardwareSerial instance in as well. Putting each instance in its own
34
+ // file prevents the linker from pulling in any unused instances in the
35
+ // first place.
36
+
37
+ #if defined(HAVE_HWSERIAL2)
38
+
39
+ ISR(USART2_RX_vect)
40
+ {
41
+ Serial2._rx_complete_irq();
42
+ }
43
+
44
+ ISR(USART2_UDRE_vect)
45
+ {
46
+ Serial2._tx_udr_empty_irq();
47
+ }
48
+
49
+ HardwareSerial Serial2(&UBRR2H, &UBRR2L, &UCSR2A, &UCSR2B, &UCSR2C, &UDR2);
50
+
51
+ // Function that can be weakly referenced by serialEventRun to prevent
52
+ // pulling in this file if it's not otherwise used.
53
+ bool Serial2_available() {
54
+ return Serial2.available();
55
+ }
56
+
57
+ #endif // HAVE_HWSERIAL2
hardware/arduino/avr/cores/arduino/HardwareSerial3.cpp ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ HardwareSerial3.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
+ Modified 28 September 2010 by Mark Sproul
21
+ Modified 14 August 2012 by Alarus
22
+ Modified 3 December 2013 by Matthijs Kooijman
23
+ */
24
+
25
+ #include "Arduino.h"
26
+ #include "HardwareSerial.h"
27
+ #include "HardwareSerial_private.h"
28
+
29
+ // Each HardwareSerial is defined in its own file, since the linker pulls
30
+ // in the entire file when any element inside is used. --gc-sections can
31
+ // additionally cause unused symbols to be dropped, but ISRs have the
32
+ // "used" attribute so are never dropped and they keep the
33
+ // HardwareSerial instance in as well. Putting each instance in its own
34
+ // file prevents the linker from pulling in any unused instances in the
35
+ // first place.
36
+
37
+ #if defined(HAVE_HWSERIAL3)
38
+
39
+ ISR(USART3_RX_vect)
40
+ {
41
+ Serial3._rx_complete_irq();
42
+ }
43
+
44
+ ISR(USART3_UDRE_vect)
45
+ {
46
+ Serial3._tx_udr_empty_irq();
47
+ }
48
+
49
+ HardwareSerial Serial3(&UBRR3H, &UBRR3L, &UCSR3A, &UCSR3B, &UCSR3C, &UDR3);
50
+
51
+ // Function that can be weakly referenced by serialEventRun to prevent
52
+ // pulling in this file if it's not otherwise used.
53
+ bool Serial3_available() {
54
+ return Serial3.available();
55
+ }
56
+
57
+ #endif // HAVE_HWSERIAL3
hardware/arduino/avr/cores/arduino/HardwareSerial_private.h ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ HardwareSerial_private.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
+ Modified 23 November 2006 by David A. Mellis
20
+ Modified 28 September 2010 by Mark Sproul
21
+ Modified 14 August 2012 by Alarus
22
+ */
23
+
24
+ #include "wiring_private.h"
25
+
26
+ // this next line disables the entire HardwareSerial.cpp,
27
+ // this is so I can support Attiny series and any other chip without a uart
28
+ #if defined(HAVE_HWSERIAL0) || defined(HAVE_HWSERIAL1) || defined(HAVE_HWSERIAL2) || defined(HAVE_HWSERIAL3)
29
+
30
+ // Ensure that the various bit positions we use are available with a 0
31
+ // postfix, so we can always use the values for UART0 for all UARTs. The
32
+ // alternative, passing the various values for each UART to the
33
+ // HardwareSerial constructor also works, but makes the code bigger and
34
+ // slower.
35
+ #if !defined(TXC0)
36
+ #if defined(TXC)
37
+ // Some chips like ATmega8 don't have UPE, only PE. The other bits are
38
+ // named as expected.
39
+ #if !defined(UPE) && defined(PE)
40
+ #define UPE PE
41
+ #endif
42
+ // On ATmega8, the uart and its bits are not numbered, so there is no TXC0 etc.
43
+ #define TXC0 TXC
44
+ #define RXEN0 RXEN
45
+ #define TXEN0 TXEN
46
+ #define RXCIE0 RXCIE
47
+ #define UDRIE0 UDRIE
48
+ #define U2X0 U2X
49
+ #define UPE0 UPE
50
+ #define UDRE0 UDRE
51
+ #elif defined(TXC1)
52
+ // Some devices have uart1 but no uart0
53
+ #define TXC0 TXC1
54
+ #define RXEN0 RXEN1
55
+ #define TXEN0 TXEN1
56
+ #define RXCIE0 RXCIE1
57
+ #define UDRIE0 UDRIE1
58
+ #define U2X0 U2X1
59
+ #define UPE0 UPE1
60
+ #define UDRE0 UDRE1
61
+ #else
62
+ #error No UART found in HardwareSerial.cpp
63
+ #endif
64
+ #endif // !defined TXC0
65
+
66
+ // Check at compiletime that it is really ok to use the bit positions of
67
+ // UART0 for the other UARTs as well, in case these values ever get
68
+ // changed for future hardware.
69
+ #if defined(TXC1) && (TXC1 != TXC0 || RXEN1 != RXEN0 || RXCIE1 != RXCIE0 || \
70
+ UDRIE1 != UDRIE0 || U2X1 != U2X0 || UPE1 != UPE0 || \
71
+ UDRE1 != UDRE0)
72
+ #error "Not all bit positions for UART1 are the same as for UART0"
73
+ #endif
74
+ #if defined(TXC2) && (TXC2 != TXC0 || RXEN2 != RXEN0 || RXCIE2 != RXCIE0 || \
75
+ UDRIE2 != UDRIE0 || U2X2 != U2X0 || UPE2 != UPE0 || \
76
+ UDRE2 != UDRE0)
77
+ #error "Not all bit positions for UART2 are the same as for UART0"
78
+ #endif
79
+ #if defined(TXC3) && (TXC3 != TXC0 || RXEN3 != RXEN0 || RXCIE3 != RXCIE0 || \
80
+ UDRIE3 != UDRIE0 || U3X3 != U3X0 || UPE3 != UPE0 || \
81
+ UDRE3 != UDRE0)
82
+ #error "Not all bit positions for UART3 are the same as for UART0"
83
+ #endif
84
+
85
+ // Constructors ////////////////////////////////////////////////////////////////
86
+
87
+ HardwareSerial::HardwareSerial(
88
+ volatile uint8_t *ubrrh, volatile uint8_t *ubrrl,
89
+ volatile uint8_t *ucsra, volatile uint8_t *ucsrb,
90
+ volatile uint8_t *ucsrc, volatile uint8_t *udr) :
91
+ _ubrrh(ubrrh), _ubrrl(ubrrl),
92
+ _ucsra(ucsra), _ucsrb(ucsrb), _ucsrc(ucsrc),
93
+ _udr(udr),
94
+ _rx_buffer_head(0), _rx_buffer_tail(0),
95
+ _tx_buffer_head(0), _tx_buffer_tail(0)
96
+ {
97
+ }
98
+
99
+ // Actual interrupt handlers //////////////////////////////////////////////////////////////
100
+
101
+ void HardwareSerial::_rx_complete_irq(void)
102
+ {
103
+ if (bit_is_clear(*_ucsra, UPE0)) {
104
+ // No Parity error, read byte and store it in the buffer if there is
105
+ // room
106
+ unsigned char c = *_udr;
107
+ rx_buffer_index_t i = (unsigned int)(_rx_buffer_head + 1) % SERIAL_RX_BUFFER_SIZE;
108
+
109
+ // if we should be storing the received character into the location
110
+ // just before the tail (meaning that the head would advance to the
111
+ // current location of the tail), we're about to overflow the buffer
112
+ // and so we don't write the character or advance the head.
113
+ if (i != _rx_buffer_tail) {
114
+ _rx_buffer[_rx_buffer_head] = c;
115
+ _rx_buffer_head = i;
116
+ }
117
+ } else {
118
+ // Parity error, read byte but discard it
119
+ *_udr;
120
+ };
121
+ }
122
+
123
+ #endif // whole file