diff --git a/README.md b/README.md
old mode 100644
new mode 100755
diff --git a/Rmodule/Rmodule.aps b/Rmodule/Rmodule.aps
new file mode 100755
index 0000000..f98c53f
--- /dev/null
+++ b/Rmodule/Rmodule.aps
@@ -0,0 +1 @@
+Rmodule14-Nov-2013 11:48:5718-Nov-2013 21:18:20241014-Nov-2013 11:48:5744, 19, 0, 730AVR GCCdefault\Rmodule.elfc:\Hard\Rmodule\AVR SimulatorATmega8.xmlfalseR00R01R02R03R04R05R06R07R08R09R10R11R12R13R14R15R16R17R18R19R20R21R22R23R24R25R26R27R28R29R30R31Auto000main.cuart\uart.conewire\onewire.cC:\Hard\Git\Rmodule\uart\uart_addon.cuart\uart.hres\strings.honewire\onewire.hC:\Hard\Git\Rmodule\uart\uart_addon.hdefault\Rmodule.lssdefault\Rmodule.mapdefaultNOatmega811
Rmodule.elfdefault\1-Wall -gdwarf-2 -std=gnu99 -DF_CPU=8000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enumsdefault1C:\Program Files\Atmel\AVR Tools\AVR Toolchain\bin\avr-gcc.exeC:\Program Files\Atmel\AVR Tools\AVR Toolchain\bin\make.exec:\Hard\Rmodule\uart\uart.hc:\Hard\Rmodule\res\strings.hc:\Hard\Rmodule\onewire\onewire.hC:\Hard\Git\Rmodule\uart\uart_addon.hc:\Hard\Rmodule\main.cc:\Hard\Rmodule\uart\uart.cc:\Hard\Rmodule\onewire\onewire.cC:\Hard\Git\Rmodule\uart\uart_addon.c00000main.c100001res\strings.h1
diff --git a/Rmodule/default/Makefile b/Rmodule/default/Makefile
new file mode 100755
index 0000000..12f6b4f
--- /dev/null
+++ b/Rmodule/default/Makefile
@@ -0,0 +1,86 @@
+###############################################################################
+# Makefile for the project Rmodule
+###############################################################################
+
+## General Flags
+PROJECT = Rmodule
+MCU = atmega8
+TARGET = Rmodule.elf
+CC = avr-gcc
+
+CPP = avr-g++
+
+## Options common to compile, link and assembly rules
+COMMON = -mmcu=$(MCU)
+
+## Compile options common for all C compilation units.
+CFLAGS = $(COMMON)
+CFLAGS += -Wall -gdwarf-2 -std=gnu99 -DF_CPU=8000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
+CFLAGS += -MD -MP -MT $(*F).o -MF dep/$(@F).d
+
+## Assembly specific flags
+ASMFLAGS = $(COMMON)
+ASMFLAGS += $(CFLAGS)
+ASMFLAGS += -x assembler-with-cpp -Wa,-gdwarf2
+
+## Linker flags
+LDFLAGS = $(COMMON)
+LDFLAGS += -Wl,-Map=Rmodule.map
+
+
+## Intel Hex file production flags
+HEX_FLASH_FLAGS = -R .eeprom -R .fuse -R .lock -R .signature
+
+HEX_EEPROM_FLAGS = -j .eeprom
+HEX_EEPROM_FLAGS += --set-section-flags=.eeprom="alloc,load"
+HEX_EEPROM_FLAGS += --change-section-lma .eeprom=0 --no-change-warnings
+
+
+## Objects that must be built in order to link
+OBJECTS = main.o uart.o onewire.o uart_addon.o
+
+## Objects explicitly added by the user
+LINKONLYOBJECTS =
+
+## Build
+all: $(TARGET) Rmodule.hex Rmodule.eep Rmodule.lss size
+
+## Compile
+main.o: ../main.c
+ $(CC) $(INCLUDES) $(CFLAGS) -c $<
+
+uart.o: ../uart/uart.c
+ $(CC) $(INCLUDES) $(CFLAGS) -c $<
+
+onewire.o: ../onewire/onewire.c
+ $(CC) $(INCLUDES) $(CFLAGS) -c $<
+
+uart_addon.o: ../../Git/Rmodule/uart/uart_addon.c
+ $(CC) $(INCLUDES) $(CFLAGS) -c $<
+
+##Link
+$(TARGET): $(OBJECTS)
+ $(CC) $(LDFLAGS) $(OBJECTS) $(LINKONLYOBJECTS) $(LIBDIRS) $(LIBS) -o $(TARGET)
+
+%.hex: $(TARGET)
+ avr-objcopy -O ihex $(HEX_FLASH_FLAGS) $< $@
+
+%.eep: $(TARGET)
+ -avr-objcopy $(HEX_EEPROM_FLAGS) -O ihex $< $@ || exit 0
+
+%.lss: $(TARGET)
+ avr-objdump -h -S $< > $@
+
+size: ${TARGET}
+ @echo
+ @avr-size -C --mcu=${MCU} ${TARGET}
+
+## Clean target
+.PHONY: clean
+clean:
+ -rm -rf $(OBJECTS) Rmodule.elf dep/* Rmodule.hex Rmodule.eep Rmodule.lss Rmodule.map
+
+
+## Other dependencies
+-include $(shell mkdir dep 2>NUL) $(wildcard dep/*)
+
diff --git a/Rmodule/main.c b/Rmodule/main.c
new file mode 100755
index 0000000..21dfab6
--- /dev/null
+++ b/Rmodule/main.c
@@ -0,0 +1,83 @@
+// Прошивка для удаленного радиомодуля
+
+#include
+#include
+#include
+#include "uart/uart.h"
+#include "uart/uart_addon.h"
+#include "onewire/onewire.h"
+#include "res/strings.h"
+
+#define UART_BAUD_RATE 19200
+
+unsigned char get_uart_char(void){
+ unsigned int res;
+ do{
+ res = uart_getc();
+ } while(res & UART_NO_DATA);
+ return (unsigned char) res;
+}
+
+static int get_uart_line(char *pbuf, int len_ln){
+ int i = 0;
+ unsigned char c;
+ len_ln=len_ln-1;
+
+ while((c=get_uart_char()) != 0x0D && i0){
+ if (strcmp_P(cmd, CmdLD)==0){
+ getListDevices();
+ }
+ if (strcmp_P(cmd, CmdHelp)==0){
+ uart_puts_p(HelpTitle);
+ uart_puts_p(HelpItem1);
+ uart_puts_p(HelpItem2);
+ }
+ }
+ }
+}
diff --git a/Rmodule/onewire/crc8.c b/Rmodule/onewire/crc8.c
new file mode 100755
index 0000000..6a0fc00
--- /dev/null
+++ b/Rmodule/onewire/crc8.c
@@ -0,0 +1,63 @@
+/* please read copyright-notice at EOF */
+
+#include
+
+#define CRC8INIT 0x00
+#define CRC8POLY 0x18 //0X18 = X^8+X^5+X^4+X^0
+
+uint8_t crc8( uint8_t *data, uint16_t number_of_bytes_in_data )
+{
+ uint8_t crc;
+ uint16_t loop_count;
+ uint8_t bit_counter;
+ uint8_t b;
+ uint8_t feedback_bit;
+
+ crc = CRC8INIT;
+
+ for (loop_count = 0; loop_count != number_of_bytes_in_data; loop_count++)
+ {
+ b = data[loop_count];
+
+ bit_counter = 8;
+ do {
+ feedback_bit = (crc ^ b) & 0x01;
+
+ if ( feedback_bit == 0x01 ) {
+ crc = crc ^ CRC8POLY;
+ }
+ crc = (crc >> 1) & 0x7F;
+ if ( feedback_bit == 0x01 ) {
+ crc = crc | 0x80;
+ }
+
+ b = b >> 1;
+ bit_counter--;
+
+ } while (bit_counter > 0);
+ }
+
+ return crc;
+}
+
+/*
+This code is from Colin O'Flynn - Copyright (c) 2002
+only minor changes by M.Thomas 9/2004
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+the Software, and to permit persons to whom the Software is furnished to do so,
+subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+*/
diff --git a/Rmodule/onewire/crc8.h b/Rmodule/onewire/crc8.h
new file mode 100755
index 0000000..bf82365
--- /dev/null
+++ b/Rmodule/onewire/crc8.h
@@ -0,0 +1,40 @@
+#ifndef CRC8_H_
+#define CRC8_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include
+
+uint8_t crc8( uint8_t* data, uint16_t number_of_bytes_in_data );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+/*
+This is based on code from :
+
+Copyright (c) 2002 Colin O'Flynn
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+the Software, and to permit persons to whom the Software is furnished to do so,
+subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+*/
+
diff --git a/Rmodule/onewire/onewire.c b/Rmodule/onewire/onewire.c
new file mode 100755
index 0000000..de131ea
--- /dev/null
+++ b/Rmodule/onewire/onewire.c
@@ -0,0 +1,287 @@
+/*
+Access Dallas 1-Wire Devices with ATMEL AVRs
+Author of the initial code: Peter Dannegger (danni(at)specs.de)
+modified by Martin Thomas (mthomas(at)rhrk.uni-kl.de)
+ 9/2004 - use of delay.h, optional bus configuration at runtime
+10/2009 - additional delay in ow_bit_io for recovery
+ 5/2010 - timing modifcations, additonal config-values and comments,
+ use of atomic.h macros, internal pull-up support
+ 7/2010 - added method to skip recovery time after last bit transfered
+ via ow_command_skip_last_recovery
+*/
+
+
+#include
+#include
+#include
+
+#include "onewire.h"
+
+#ifdef OW_ONE_BUS
+
+#define OW_GET_IN() ( OW_IN & (1< 1usec accoding to timing-diagramm
+ if ( b ) {
+ OW_DIR_IN(); // to write "1" release bus, resistor pulls high
+#if OW_USE_INTERNAL_PULLUP
+ OW_OUT_HIGH();
+#endif
+ }
+
+ // "Output data from the DS18B20 is valid for 15usec after the falling
+ // edge that initiated the read time slot. Therefore, the master must
+ // release the bus and then sample the bus state within 15ussec from
+ // the start of the slot."
+ _delay_us(15-2-OW_CONF_DELAYOFFSET);
+
+ if( OW_GET_IN() == 0 ) {
+ b = 0; // sample at end of read-timeslot
+ }
+
+ _delay_us(60-15-2+OW_CONF_DELAYOFFSET);
+#if OW_USE_INTERNAL_PULLUP
+ OW_OUT_HIGH();
+#endif
+ OW_DIR_IN();
+
+ if ( with_parasite_enable ) {
+ ow_parasite_enable();
+ }
+
+ } /* ATOMIC_BLOCK */
+
+ _delay_us(OW_RECOVERY_TIME); // may be increased for longer wires
+
+ return b;
+}
+
+uint8_t ow_bit_io( uint8_t b )
+{
+ return ow_bit_io_intern( b & 1, 0 );
+}
+
+uint8_t ow_byte_wr( uint8_t b )
+{
+ uint8_t i = 8, j;
+
+ do {
+ j = ow_bit_io( b & 1 );
+ b >>= 1;
+ if( j ) {
+ b |= 0x80;
+ }
+ } while( --i );
+
+ return b;
+}
+
+uint8_t ow_byte_wr_with_parasite_enable( uint8_t b )
+{
+ uint8_t i = 8, j;
+
+ do {
+ if ( i != 1 ) {
+ j = ow_bit_io_intern( b & 1, 0 );
+ } else {
+ j = ow_bit_io_intern( b & 1, 1 );
+ }
+ b >>= 1;
+ if( j ) {
+ b |= 0x80;
+ }
+ } while( --i );
+
+ return b;
+}
+
+
+uint8_t ow_byte_rd( void )
+{
+ // read by sending only "1"s, so bus gets released
+ // after the init low-pulse in every slot
+ return ow_byte_wr( 0xFF );
+}
+
+
+uint8_t ow_rom_search( uint8_t diff, uint8_t *id )
+{
+ uint8_t i, j, next_diff;
+ uint8_t b;
+
+ if( ow_reset() ) {
+ return OW_PRESENCE_ERR; // error, no device found <--- early exit!
+ }
+
+ ow_byte_wr( OW_SEARCH_ROM ); // ROM search command
+ next_diff = OW_LAST_DEVICE; // unchanged on last device
+
+ i = OW_ROMCODE_SIZE * 8; // 8 bytes
+
+ do {
+ j = 8; // 8 bits
+ do {
+ b = ow_bit_io( 1 ); // read bit
+ if( ow_bit_io( 1 ) ) { // read complement bit
+ if( b ) { // 0b11
+ return OW_DATA_ERR; // data error <--- early exit!
+ }
+ }
+ else {
+ if( !b ) { // 0b00 = 2 devices
+ if( diff > i || ((*id & 1) && diff != i) ) {
+ b = 1; // now 1
+ next_diff = i; // next pass 0
+ }
+ }
+ }
+ ow_bit_io( b ); // write bit
+ *id >>= 1;
+ if( b ) {
+ *id |= 0x80; // store bit
+ }
+
+ i--;
+
+ } while( --j );
+
+ id++; // next byte
+
+ } while( i );
+
+ return next_diff; // to continue search
+}
+
+
+static void ow_command_intern( uint8_t command, uint8_t *id, uint8_t with_parasite_enable )
+{
+ uint8_t i;
+
+ ow_reset();
+
+ if( id ) {
+ ow_byte_wr( OW_MATCH_ROM ); // to a single device
+ i = OW_ROMCODE_SIZE;
+ do {
+ ow_byte_wr( *id );
+ id++;
+ } while( --i );
+ }
+ else {
+ ow_byte_wr( OW_SKIP_ROM ); // to all devices
+ }
+
+ if ( with_parasite_enable ) {
+ ow_byte_wr_with_parasite_enable( command );
+ } else {
+ ow_byte_wr( command );
+ }
+}
+
+void ow_command( uint8_t command, uint8_t *id )
+{
+ ow_command_intern( command, id, 0);
+}
+
+void ow_command_with_parasite_enable( uint8_t command, uint8_t *id )
+{
+ ow_command_intern( command, id, 1 );
+}
+
diff --git a/Rmodule/onewire/onewire.h b/Rmodule/onewire/onewire.h
new file mode 100755
index 0000000..5f25f8a
--- /dev/null
+++ b/Rmodule/onewire/onewire.h
@@ -0,0 +1,93 @@
+#ifndef ONEWIRE_H_
+#define ONEWIRE_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include
+
+/*******************************************/
+/* Hardware connection */
+/*******************************************/
+
+/* Define OW_ONE_BUS if only one 1-Wire-Bus is used
+ in the application -> shorter code.
+ If not defined make sure to call ow_set_bus() before using
+ a bus. Runtime bus-select increases code size by around 300
+ bytes so use OW_ONE_BUS if possible */
+// #define OW_ONE_BUS
+
+#ifdef OW_ONE_BUS
+
+#define OW_PIN PD6
+#define OW_IN PIND
+#define OW_OUT PORTD
+#define OW_DDR DDRD
+#define OW_CONF_DELAYOFFSET 0
+
+#else
+#if ( F_CPU < 1843200 )
+#warning | Experimental multi-bus-mode is not tested for
+#warning | frequencies below 1,84MHz. Use OW_ONE_WIRE or
+#warning | faster clock-source (i.e. internal 2MHz R/C-Osc.).
+#endif
+#define OW_CONF_CYCLESPERACCESS 13
+#define OW_CONF_DELAYOFFSET ( (uint16_t)( ((OW_CONF_CYCLESPERACCESS) * 1000000L) / F_CPU ) )
+#endif
+
+// Recovery time (T_Rec) minimum 1usec - increase for long lines
+// 5 usecs is a value give in some Maxim AppNotes
+// 30u secs seem to be reliable for longer lines
+//#define OW_RECOVERY_TIME 5 /* usec */
+//#define OW_RECOVERY_TIME 300 /* usec */
+#define OW_RECOVERY_TIME 10 /* usec */
+
+// Use AVR's internal pull-up resistor instead of external 4,7k resistor.
+// Based on information from Sascha Schade. Experimental but worked in tests
+// with one DS18B20 and one DS18S20 on a rather short bus (60cm), where both
+// sensores have been parasite-powered.
+#define OW_USE_INTERNAL_PULLUP 1 /* 0=external, 1=internal */
+
+/*******************************************/
+
+
+#define OW_MATCH_ROM 0x55
+#define OW_SKIP_ROM 0xCC
+#define OW_SEARCH_ROM 0xF0
+
+#define OW_SEARCH_FIRST 0xFF // start new search
+#define OW_PRESENCE_ERR 0xFF
+#define OW_DATA_ERR 0xFE
+#define OW_LAST_DEVICE 0x00 // last device found
+
+// rom-code size including CRC
+#define OW_ROMCODE_SIZE 8
+
+extern uint8_t ow_reset(void);
+
+extern uint8_t ow_bit_io( uint8_t b );
+extern uint8_t ow_byte_wr( uint8_t b );
+extern uint8_t ow_byte_rd( void );
+
+extern uint8_t ow_rom_search( uint8_t diff, uint8_t *id );
+
+extern void ow_command( uint8_t command, uint8_t *id );
+extern void ow_command_with_parasite_enable( uint8_t command, uint8_t *id );
+
+extern void ow_parasite_enable( void );
+extern void ow_parasite_disable( void );
+extern uint8_t ow_input_pin_state( void );
+
+#ifndef OW_ONE_BUS
+extern void ow_set_bus( volatile uint8_t* in,
+ volatile uint8_t* out,
+ volatile uint8_t* ddr,
+ uint8_t pin );
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/Rmodule/res/strings.h b/Rmodule/res/strings.h
new file mode 100755
index 0000000..cea7272
--- /dev/null
+++ b/Rmodule/res/strings.h
@@ -0,0 +1,17 @@
+#include
+
+#define CRLF "\r\n"
+
+//
+const char CmdLD[] PROGMEM = "ld";
+const char CmdHelp[] PROGMEM = "h";
+
+// Список команд
+const char HelpTitle[] PROGMEM = CRLF "Command list:";
+const char HelpItem1[] PROGMEM = CRLF "ld - List devices";
+const char HelpItem2[] PROGMEM = CRLF "h - Show this help";
+const char CmdPrompt[] PROGMEM = CRLF "$ ";
+
+// Разные нужные строки
+const char ScanStr[] PROGMEM = CRLF "Scanning 1-wire bus" CRLF;
+
diff --git a/Rmodule/rmodule.aws b/Rmodule/rmodule.aws
new file mode 100755
index 0000000..f836f76
--- /dev/null
+++ b/Rmodule/rmodule.aws
@@ -0,0 +1 @@
+
diff --git a/Rmodule/uart/uart.c b/Rmodule/uart/uart.c
new file mode 100755
index 0000000..3cb2a81
--- /dev/null
+++ b/Rmodule/uart/uart.c
@@ -0,0 +1,663 @@
+/*************************************************************************
+Title: Interrupt UART library with receive/transmit circular buffers
+Author: Peter Fleury http://jump.to/fleury
+File: $Id: uart.c,v 1.10 2013/06/02 07:27:04 peter Exp $
+Software: AVR-GCC 4.1, AVR Libc 1.4.6 or higher
+Hardware: any AVR with built-in UART,
+License: GNU General Public License
+
+DESCRIPTION:
+ An interrupt is generated when the UART has finished transmitting or
+ receiving a byte. The interrupt handling routines use circular buffers
+ for buffering received and transmitted data.
+
+ The UART_RX_BUFFER_SIZE and UART_TX_BUFFER_SIZE variables define
+ the buffer size in bytes. Note that these variables must be a
+ power of 2.
+
+USAGE:
+ Refere to the header file uart.h for a description of the routines.
+ See also example test_uart.c.
+
+NOTES:
+ Based on Atmel Application Note AVR306
+
+LICENSE:
+ Copyright (C) 2006 Peter Fleury
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+*************************************************************************/
+#include
+#include
+#include
+#include "uart.h"
+
+
+/*
+ * constants and macros
+ */
+
+/* size of RX/TX buffers */
+#define UART_RX_BUFFER_MASK ( UART_RX_BUFFER_SIZE - 1)
+#define UART_TX_BUFFER_MASK ( UART_TX_BUFFER_SIZE - 1)
+
+#if ( UART_RX_BUFFER_SIZE & UART_RX_BUFFER_MASK )
+#error RX buffer size is not a power of 2
+#endif
+#if ( UART_TX_BUFFER_SIZE & UART_TX_BUFFER_MASK )
+#error TX buffer size is not a power of 2
+#endif
+
+#if defined(__AVR_AT90S2313__) \
+ || defined(__AVR_AT90S4414__) || defined(__AVR_AT90S4434__) \
+ || defined(__AVR_AT90S8515__) || defined(__AVR_AT90S8535__) \
+ || defined(__AVR_ATmega103__)
+ /* old AVR classic or ATmega103 with one UART */
+ #define AT90_UART
+ #define UART0_RECEIVE_INTERRUPT UART_RX_vect
+ #define UART0_TRANSMIT_INTERRUPT UART_UDRE_vect
+ #define UART0_STATUS USR
+ #define UART0_CONTROL UCR
+ #define UART0_DATA UDR
+ #define UART0_UDRIE UDRIE
+#elif defined(__AVR_AT90S2333__) || defined(__AVR_AT90S4433__)
+ /* old AVR classic with one UART */
+ #define AT90_UART
+ #define UART0_RECEIVE_INTERRUPT UART_RX_vect
+ #define UART0_TRANSMIT_INTERRUPT UART_UDRE_vect
+ #define UART0_STATUS UCSRA
+ #define UART0_CONTROL UCSRB
+ #define UART0_DATA UDR
+ #define UART0_UDRIE UDRIE
+#elif defined(__AVR_ATmega8__) || defined(__AVR_ATmega16__) || defined(__AVR_ATmega32__) \
+ || defined(__AVR_ATmega323__)
+ /* ATmega with one USART */
+ #define ATMEGA_USART
+ #define UART0_RECEIVE_INTERRUPT USART_RXC_vect
+ #define UART0_TRANSMIT_INTERRUPT USART_UDRE_vect
+ #define UART0_STATUS UCSRA
+ #define UART0_CONTROL UCSRB
+ #define UART0_DATA UDR
+ #define UART0_UDRIE UDRIE
+#elif defined (__AVR_ATmega8515__) || defined(__AVR_ATmega8535__)
+ #define ATMEGA_USART
+ #define UART0_RECEIVE_INTERRUPT USART_RX_vect
+ #define UART0_TRANSMIT_INTERRUPT USART_UDRE_vect
+ #define UART0_STATUS UCSRA
+ #define UART0_CONTROL UCSRB
+ #define UART0_DATA UDR
+ #define UART0_UDRIE UDRIE
+#elif defined(__AVR_ATmega163__)
+ /* ATmega163 with one UART */
+ #define ATMEGA_UART
+ #define UART0_RECEIVE_INTERRUPT UART_RX_vect
+ #define UART0_TRANSMIT_INTERRUPT UART_UDRE_vect
+ #define UART0_STATUS UCSRA
+ #define UART0_CONTROL UCSRB
+ #define UART0_DATA UDR
+ #define UART0_UDRIE UDRIE
+#elif defined(__AVR_ATmega162__)
+ /* ATmega with two USART */
+ #define ATMEGA_USART0
+ #define ATMEGA_USART1
+ #define UART0_RECEIVE_INTERRUPT USART0_RXC_vect
+ #define UART1_RECEIVE_INTERRUPT USART1_RXC_vect
+ #define UART0_TRANSMIT_INTERRUPT USART0_UDRE_vect
+ #define UART1_TRANSMIT_INTERRUPT USART1_UDRE_vect
+ #define UART0_STATUS UCSR0A
+ #define UART0_CONTROL UCSR0B
+ #define UART0_DATA UDR0
+ #define UART0_UDRIE UDRIE0
+ #define UART1_STATUS UCSR1A
+ #define UART1_CONTROL UCSR1B
+ #define UART1_DATA UDR1
+ #define UART1_UDRIE UDRIE1
+#elif defined(__AVR_ATmega64__) || defined(__AVR_ATmega128__)
+ /* ATmega with two USART */
+ #define ATMEGA_USART0
+ #define ATMEGA_USART1
+ #define UART0_RECEIVE_INTERRUPT USART0_RX_vect
+ #define UART1_RECEIVE_INTERRUPT USART1_RX_vect
+ #define UART0_TRANSMIT_INTERRUPT USART0_UDRE_vect
+ #define UART1_TRANSMIT_INTERRUPT USART1_UDRE_vect
+ #define UART0_STATUS UCSR0A
+ #define UART0_CONTROL UCSR0B
+ #define UART0_DATA UDR0
+ #define UART0_UDRIE UDRIE0
+ #define UART1_STATUS UCSR1A
+ #define UART1_CONTROL UCSR1B
+ #define UART1_DATA UDR1
+ #define UART1_UDRIE UDRIE1
+#elif defined(__AVR_ATmega161__)
+ /* ATmega with UART */
+ #error "AVR ATmega161 currently not supported by this libaray !"
+#elif defined(__AVR_ATmega169__)
+ /* ATmega with one USART */
+ #define ATMEGA_USART
+ #define UART0_RECEIVE_INTERRUPT USART0_RX_vect
+ #define UART0_TRANSMIT_INTERRUPT USART0_UDRE_vect
+ #define UART0_STATUS UCSRA
+ #define UART0_CONTROL UCSRB
+ #define UART0_DATA UDR
+ #define UART0_UDRIE UDRIE
+#elif defined(__AVR_ATmega48__) || defined(__AVR_ATmega88__) || defined(__AVR_ATmega168__) || defined(__AVR_ATmega48P__) || defined(__AVR_ATmega88P__) || defined(__AVR_ATmega168P__) || defined(__AVR_ATmega328P__) \
+ || defined(__AVR_ATmega3250__) || defined(__AVR_ATmega3290__) ||defined(__AVR_ATmega6450__) || defined(__AVR_ATmega6490__)
+ /* ATmega with one USART */
+ #define ATMEGA_USART0
+ #define UART0_RECEIVE_INTERRUPT USART_RX_vect
+ #define UART0_TRANSMIT_INTERRUPT USART_UDRE_vect
+ #define UART0_STATUS UCSR0A
+ #define UART0_CONTROL UCSR0B
+ #define UART0_DATA UDR0
+ #define UART0_UDRIE UDRIE0
+#elif defined(__AVR_ATtiny2313__)
+ #define ATMEGA_USART
+ #define UART0_RECEIVE_INTERRUPT USART_RX_vect
+ #define UART0_TRANSMIT_INTERRUPT USART_UDRE_vect
+ #define UART0_STATUS UCSRA
+ #define UART0_CONTROL UCSRB
+ #define UART0_DATA UDR
+ #define UART0_UDRIE UDRIE
+#elif defined(__AVR_ATmega329__) || \
+ defined(__AVR_ATmega649__) || \
+ defined(__AVR_ATmega325__) || \
+ defined(__AVR_ATmega645__)
+ /* ATmega with one USART */
+ #define ATMEGA_USART0
+ #define UART0_RECEIVE_INTERRUPT USART0_RX_vect
+ #define UART0_TRANSMIT_INTERRUPT USART0_UDRE_vect
+ #define UART0_STATUS UCSR0A
+ #define UART0_CONTROL UCSR0B
+ #define UART0_DATA UDR0
+ #define UART0_UDRIE UDRIE0
+#elif defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega1281__) || defined(__AVR_ATmega640__)
+/* ATmega with two USART */
+ #define ATMEGA_USART0
+ #define ATMEGA_USART1
+ #define UART0_RECEIVE_INTERRUPT USART0_RX_vect
+ #define UART1_RECEIVE_INTERRUPT USART1_RX_vect
+ #define UART0_TRANSMIT_INTERRUPT USART0_UDRE_vect
+ #define UART1_TRANSMIT_INTERRUPT USART1_UDRE_vect
+ #define UART0_STATUS UCSR0A
+ #define UART0_CONTROL UCSR0B
+ #define UART0_DATA UDR0
+ #define UART0_UDRIE UDRIE0
+ #define UART1_STATUS UCSR1A
+ #define UART1_CONTROL UCSR1B
+ #define UART1_DATA UDR1
+ #define UART1_UDRIE UDRIE1
+#elif defined(__AVR_ATmega644__)
+ /* ATmega with one USART */
+ #define ATMEGA_USART0
+ #define UART0_RECEIVE_INTERRUPT USART0_RX_vect
+ #define UART0_TRANSMIT_INTERRUPT USART0_UDRE_vect
+ #define UART0_STATUS UCSR0A
+ #define UART0_CONTROL UCSR0B
+ #define UART0_DATA UDR0
+ #define UART0_UDRIE UDRIE0
+#elif defined(__AVR_ATmega164P__) || defined(__AVR_ATmega324P__) || defined(__AVR_ATmega644P__)
+ /* ATmega with two USART */
+ #define ATMEGA_USART0
+ #define ATMEGA_USART1
+ #define UART0_RECEIVE_INTERRUPT USART0_RX_vect
+ #define UART1_RECEIVE_INTERRUPT USART1_RX_vect
+ #define UART0_TRANSMIT_INTERRUPT USART0_UDRE_vect
+ #define UART1_TRANSMIT_INTERRUPT USART1_UDRE_vect
+ #define UART0_STATUS UCSR0A
+ #define UART0_CONTROL UCSR0B
+ #define UART0_DATA UDR0
+ #define UART0_UDRIE UDRIE0
+ #define UART1_STATUS UCSR1A
+ #define UART1_CONTROL UCSR1B
+ #define UART1_DATA UDR1
+ #define UART1_UDRIE UDRIE1
+#else
+ #error "no UART definition for MCU available"
+#endif
+
+
+/*
+ * module global variables
+ */
+static volatile unsigned char UART_TxBuf[UART_TX_BUFFER_SIZE];
+static volatile unsigned char UART_RxBuf[UART_RX_BUFFER_SIZE];
+static volatile unsigned char UART_TxHead;
+static volatile unsigned char UART_TxTail;
+static volatile unsigned char UART_RxHead;
+static volatile unsigned char UART_RxTail;
+static volatile unsigned char UART_LastRxError;
+
+#if defined( ATMEGA_USART1 )
+static volatile unsigned char UART1_TxBuf[UART_TX_BUFFER_SIZE];
+static volatile unsigned char UART1_RxBuf[UART_RX_BUFFER_SIZE];
+static volatile unsigned char UART1_TxHead;
+static volatile unsigned char UART1_TxTail;
+static volatile unsigned char UART1_RxHead;
+static volatile unsigned char UART1_RxTail;
+static volatile unsigned char UART1_LastRxError;
+#endif
+
+
+
+ISR (UART0_RECEIVE_INTERRUPT)
+/*************************************************************************
+Function: UART Receive Complete interrupt
+Purpose: called when the UART has received a character
+**************************************************************************/
+{
+ unsigned char tmphead;
+ unsigned char data;
+ unsigned char usr;
+ unsigned char lastRxError;
+
+
+ /* read UART status register and UART data register */
+ usr = UART0_STATUS;
+ data = UART0_DATA;
+
+ /* */
+#if defined( AT90_UART )
+ lastRxError = (usr & (_BV(FE)|_BV(DOR)) );
+#elif defined( ATMEGA_USART )
+ lastRxError = (usr & (_BV(FE)|_BV(DOR)) );
+#elif defined( ATMEGA_USART0 )
+ lastRxError = (usr & (_BV(FE0)|_BV(DOR0)) );
+#elif defined ( ATMEGA_UART )
+ lastRxError = (usr & (_BV(FE)|_BV(DOR)) );
+#endif
+
+ /* calculate buffer index */
+ tmphead = ( UART_RxHead + 1) & UART_RX_BUFFER_MASK;
+
+ if ( tmphead == UART_RxTail ) {
+ /* error: receive buffer overflow */
+ lastRxError = UART_BUFFER_OVERFLOW >> 8;
+ }else{
+ /* store new index */
+ UART_RxHead = tmphead;
+ /* store received data in buffer */
+ UART_RxBuf[tmphead] = data;
+ }
+ UART_LastRxError |= lastRxError;
+}
+
+
+ISR (UART0_TRANSMIT_INTERRUPT)
+/*************************************************************************
+Function: UART Data Register Empty interrupt
+Purpose: called when the UART is ready to transmit the next byte
+**************************************************************************/
+{
+ unsigned char tmptail;
+
+
+ if ( UART_TxHead != UART_TxTail) {
+ /* calculate and store new buffer index */
+ tmptail = (UART_TxTail + 1) & UART_TX_BUFFER_MASK;
+ UART_TxTail = tmptail;
+ /* get one byte from buffer and write it to UART */
+ UART0_DATA = UART_TxBuf[tmptail]; /* start transmission */
+ }else{
+ /* tx buffer empty, disable UDRE interrupt */
+ UART0_CONTROL &= ~_BV(UART0_UDRIE);
+ }
+}
+
+
+/*************************************************************************
+Function: uart_init()
+Purpose: initialize UART and set baudrate
+Input: baudrate using macro UART_BAUD_SELECT()
+Returns: none
+**************************************************************************/
+void uart_init(unsigned int baudrate)
+{
+ UART_TxHead = 0;
+ UART_TxTail = 0;
+ UART_RxHead = 0;
+ UART_RxTail = 0;
+
+#if defined( AT90_UART )
+ /* set baud rate */
+ UBRR = (unsigned char)baudrate;
+
+ /* enable UART receiver and transmmitter and receive complete interrupt */
+ UART0_CONTROL = _BV(RXCIE)|_BV(RXEN)|_BV(TXEN);
+
+#elif defined (ATMEGA_USART)
+ /* Set baud rate */
+ if ( baudrate & 0x8000 )
+ {
+ UART0_STATUS = (1<>8);
+ UBRRL = (unsigned char) baudrate;
+
+ /* Enable USART receiver and transmitter and receive complete interrupt */
+ UART0_CONTROL = _BV(RXCIE)|(1<>8);
+ UBRR0L = (unsigned char) baudrate;
+
+ /* Enable USART receiver and transmitter and receive complete interrupt */
+ UART0_CONTROL = _BV(RXCIE0)|(1<>8);
+ UBRR = (unsigned char) baudrate;
+
+ /* Enable UART receiver and transmitter and receive complete interrupt */
+ UART0_CONTROL = _BV(RXCIE)|(1<> 8;
+ }else{
+ /* store new index */
+ UART1_RxHead = tmphead;
+ /* store received data in buffer */
+ UART1_RxBuf[tmphead] = data;
+ }
+ UART1_LastRxError |= lastRxError;
+}
+
+
+ISR(UART1_TRANSMIT_INTERRUPT)
+/*************************************************************************
+Function: UART1 Data Register Empty interrupt
+Purpose: called when the UART1 is ready to transmit the next byte
+**************************************************************************/
+{
+ unsigned char tmptail;
+
+
+ if ( UART1_TxHead != UART1_TxTail) {
+ /* calculate and store new buffer index */
+ tmptail = (UART1_TxTail + 1) & UART_TX_BUFFER_MASK;
+ UART1_TxTail = tmptail;
+ /* get one byte from buffer and write it to UART */
+ UART1_DATA = UART1_TxBuf[tmptail]; /* start transmission */
+ }else{
+ /* tx buffer empty, disable UDRE interrupt */
+ UART1_CONTROL &= ~_BV(UART1_UDRIE);
+ }
+}
+
+
+/*************************************************************************
+Function: uart1_init()
+Purpose: initialize UART1 and set baudrate
+Input: baudrate using macro UART_BAUD_SELECT()
+Returns: none
+**************************************************************************/
+void uart1_init(unsigned int baudrate)
+{
+ UART1_TxHead = 0;
+ UART1_TxTail = 0;
+ UART1_RxHead = 0;
+ UART1_RxTail = 0;
+
+
+ /* Set baud rate */
+ if ( baudrate & 0x8000 )
+ {
+ UART1_STATUS = (1<>8);
+ UBRR1L = (unsigned char) baudrate;
+
+ /* Enable USART receiver and transmitter and receive complete interrupt */
+ UART1_CONTROL = _BV(RXCIE1)|(1< http://jump.to/fleury
+File: $Id: uart.h,v 1.12 2012/11/19 19:52:27 peter Exp $
+Software: AVR-GCC 4.1, AVR Libc 1.4
+Hardware: any AVR with built-in UART, tested on AT90S8515 & ATmega8 at 4 Mhz
+License: GNU General Public License
+Usage: see Doxygen manual
+
+LICENSE:
+ Copyright (C) 2006 Peter Fleury
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+************************************************************************/
+
+/**
+ * @defgroup pfleury_uart UART Library
+ * @code #include @endcode
+ *
+ * @brief Interrupt UART library using the built-in UART with transmit and receive circular buffers.
+ *
+ * This library can be used to transmit and receive data through the built in UART.
+ *
+ * An interrupt is generated when the UART has finished transmitting or
+ * receiving a byte. The interrupt handling routines use circular buffers
+ * for buffering received and transmitted data.
+ *
+ * The UART_RX_BUFFER_SIZE and UART_TX_BUFFER_SIZE constants define
+ * the size of the circular buffers in bytes. Note that these constants must be a power of 2.
+ * You may need to adapt this constants to your target and your application by adding
+ * CDEFS += -DUART_RX_BUFFER_SIZE=nn -DUART_RX_BUFFER_SIZE=nn to your Makefile.
+ *
+ * @note Based on Atmel Application Note AVR306
+ * @author Peter Fleury pfleury@gmx.ch http://jump.to/fleury
+ */
+
+/**@{*/
+
+
+#if (__GNUC__ * 100 + __GNUC_MINOR__) < 304
+#error "This library requires AVR-GCC 3.4 or later, update to newer AVR-GCC compiler !"
+#endif
+
+
+/*
+** constants and macros
+*/
+
+/** @brief UART Baudrate Expression
+ * @param xtalcpu system clock in Mhz, e.g. 4000000UL for 4Mhz
+ * @param baudrate baudrate in bps, e.g. 1200, 2400, 9600
+ */
+#define UART_BAUD_SELECT(baudRate,xtalCpu) (((xtalCpu) + 8UL * (baudRate)) / (16UL * (baudRate)) -1UL)
+
+/** @brief UART Baudrate Expression for ATmega double speed mode
+ * @param xtalcpu system clock in Mhz, e.g. 4000000UL for 4Mhz
+ * @param baudrate baudrate in bps, e.g. 1200, 2400, 9600
+ */
+#define UART_BAUD_SELECT_DOUBLE_SPEED(baudRate,xtalCpu) ( ((((xtalCpu) + 4UL * (baudRate)) / (8UL * (baudRate)) -1UL)) | 0x8000)
+
+
+/** Size of the circular receive buffer, must be power of 2 */
+#ifndef UART_RX_BUFFER_SIZE
+#define UART_RX_BUFFER_SIZE 32
+#endif
+/** Size of the circular transmit buffer, must be power of 2 */
+#ifndef UART_TX_BUFFER_SIZE
+#define UART_TX_BUFFER_SIZE 32
+#endif
+
+/* test if the size of the circular buffers fits into SRAM */
+#if ( (UART_RX_BUFFER_SIZE+UART_TX_BUFFER_SIZE) >= (RAMEND-0x60 ) )
+#error "size of UART_RX_BUFFER_SIZE + UART_TX_BUFFER_SIZE larger than size of SRAM"
+#endif
+
+/*
+** high byte error return code of uart_getc()
+*/
+#define UART_FRAME_ERROR 0x1000 /* Framing Error by UART */
+#define UART_OVERRUN_ERROR 0x0800 /* Overrun condition by UART */
+#define UART_PARITY_ERROR 0x0400 /* Parity Error by UART */
+#define UART_BUFFER_OVERFLOW 0x0200 /* receive ringbuffer overflow */
+#define UART_NO_DATA 0x0100 /* no receive data available */
+
+
+/*
+** function prototypes
+*/
+
+/**
+ @brief Initialize UART and set baudrate
+ @param baudrate Specify baudrate using macro UART_BAUD_SELECT()
+ @return none
+*/
+extern void uart_init(unsigned int baudrate);
+
+
+/**
+ * @brief Get received byte from ringbuffer
+ *
+ * Returns in the lower byte the received character and in the
+ * higher byte the last receive error.
+ * UART_NO_DATA is returned when no data is available.
+ *
+ * @param void
+ * @return lower byte: received byte from ringbuffer
+ * @return higher byte: last receive status
+ * - \b 0 successfully received data from UART
+ * - \b UART_NO_DATA
+ *
no receive data available
+ * - \b UART_BUFFER_OVERFLOW
+ *
Receive ringbuffer overflow.
+ * We are not reading the receive buffer fast enough,
+ * one or more received character have been dropped
+ * - \b UART_OVERRUN_ERROR
+ *
Overrun condition by UART.
+ * A character already present in the UART UDR register was
+ * not read by the interrupt handler before the next character arrived,
+ * one or more received characters have been dropped.
+ * - \b UART_FRAME_ERROR
+ *
Framing Error by UART
+ */
+extern unsigned int uart_getc(void);
+
+
+/**
+ * @brief Put byte to ringbuffer for transmitting via UART
+ * @param data byte to be transmitted
+ * @return none
+ */
+extern void uart_putc(unsigned char data);
+
+
+/**
+ * @brief Put string to ringbuffer for transmitting via UART
+ *
+ * The string is buffered by the uart library in a circular buffer
+ * and one character at a time is transmitted to the UART using interrupts.
+ * Blocks if it can not write the whole string into the circular buffer.
+ *
+ * @param s string to be transmitted
+ * @return none
+ */
+extern void uart_puts(const char *s );
+
+
+/**
+ * @brief Put string from program memory to ringbuffer for transmitting via UART.
+ *
+ * The string is buffered by the uart library in a circular buffer
+ * and one character at a time is transmitted to the UART using interrupts.
+ * Blocks if it can not write the whole string into the circular buffer.
+ *
+ * @param s program memory string to be transmitted
+ * @return none
+ * @see uart_puts_P
+ */
+extern void uart_puts_p(const char *s );
+
+/**
+ * @brief Macro to automatically put a string constant into program memory
+ */
+#define uart_puts_P(__s) uart_puts_p(PSTR(__s))
+
+
+
+/** @brief Initialize USART1 (only available on selected ATmegas) @see uart_init */
+extern void uart1_init(unsigned int baudrate);
+/** @brief Get received byte of USART1 from ringbuffer. (only available on selected ATmega) @see uart_getc */
+extern unsigned int uart1_getc(void);
+/** @brief Put byte to ringbuffer for transmitting via USART1 (only available on selected ATmega) @see uart_putc */
+extern void uart1_putc(unsigned char data);
+/** @brief Put string to ringbuffer for transmitting via USART1 (only available on selected ATmega) @see uart_puts */
+extern void uart1_puts(const char *s );
+/** @brief Put string from program memory to ringbuffer for transmitting via USART1 (only available on selected ATmega) @see uart_puts_p */
+extern void uart1_puts_p(const char *s );
+/** @brief Macro to automatically put a string constant into program memory */
+#define uart1_puts_P(__s) uart1_puts_p(PSTR(__s))
+
+/**@}*/
+
+
+#endif // UART_H
+
diff --git a/Rmodule/uart/uart_addon.c b/Rmodule/uart/uart_addon.c
new file mode 100755
index 0000000..b2544da
--- /dev/null
+++ b/Rmodule/uart/uart_addon.c
@@ -0,0 +1,118 @@
+/*************************************************************************
+Title: UART addon-library
+Author: Martin Thomas
+ http://www.siwawi.arubi.uni-kl.de/avr_projects
+Software: AVR-GCC 3.3/3.4, Peter Fleury's UART-Library
+
+DESCRIPTION:
+
+USAGE:
+ Refere to the header file uart_addon.h for a description of the routines.
+
+*************************************************************************/
+
+#include
+
+#include
+#include "uart.h"
+
+
+/*************************************************************************
+Function: uart_put_int()
+Purpose: transmit integer as ASCII to UART
+Input: integer value
+Returns: none
+**************************************************************************/
+void uart_put_int( const int val )
+{
+ char buffer[10];
+ uart_puts( itoa( val, buffer, 10 ) );
+} /* uart_puti */
+
+/*************************************************************************
+Function: uart_put_longint()
+Purpose: transmit long integer as ASCII to UART
+Input: integer value
+Returns: none
+**************************************************************************/
+void uart_put_longint( const long int val )
+{
+ char buffer[15];
+ uart_puts( ltoa( val, buffer, 10 ) );
+} /* uart_puti */
+
+/*************************************************************************
+Function: uart_put_ulongint()
+Purpose: transmit long integer as ASCII to UART
+Input: integer value
+Returns: none
+**************************************************************************/
+void uart_put_ulongint( const unsigned long int val )
+{
+ char buffer[15];
+ uart_puts( utoa( val, buffer, 10 ) );
+} /* uart_puti */
+
+/*************************************************************************
+Function: uart_puthex_nibble()
+Purpose: transmit lower nibble as ASCII-hex to UART
+Input: byte value
+Returns: none
+**************************************************************************/
+void uart_puthex_nibble(const unsigned char b)
+{
+ unsigned char c = b & 0x0f;
+ if ( c > 9 ) {
+ c += 'A'-10;
+ }
+ else {
+ c += '0';
+ }
+ uart_putc(c);
+} /* uart_puthex_nibble */
+
+/*************************************************************************
+Function: uart_puthex_byte()
+Purpose: transmit upper and lower nibble as ASCII-hex to UART
+Input: byte value
+Returns: none
+**************************************************************************/
+void uart_puthex_byte( const unsigned char b )
+{
+ uart_puthex_nibble( b >> 4 );
+ uart_puthex_nibble( b );
+} /* uart_puthex_byte */
+
+/*************************************************************************
+Function: uart_puthex_long()
+Purpose: transmit unsigned long as ASCII-hex to UART
+Input: uint32_t value
+Returns: none
+**************************************************************************/
+void uart_puthex_long( const unsigned long l )
+{
+ uart_puthex_byte( (unsigned char)( l >> 24 ) );
+ uart_puthex_byte( (unsigned char)( l >> 16 ) );
+ uart_puthex_byte( (unsigned char)( l >> 8 ) );
+ uart_puthex_byte( (unsigned char)( l ) );
+} /* uart_puthex_byte */
+
+
+/*************************************************************************
+Function: uart_putbin_byte()
+Purpose: transmit byte as ASCII-bin to UART
+Input: byte value
+Returns: none
+**************************************************************************/
+void uart_putbin_byte( const unsigned char b )
+{
+ signed char i;
+ for ( i= 7;i >= 0;i-- ) {
+ if ( b & ( 1 << i ) ) {
+ uart_putc( '1' );
+ }
+ else {
+ uart_putc( '0' );
+ }
+ }
+} /* uart_putbin_byte */
diff --git a/Rmodule/uart/uart_addon.h b/Rmodule/uart/uart_addon.h
new file mode 100755
index 0000000..3c4ff91
--- /dev/null
+++ b/Rmodule/uart/uart_addon.h
@@ -0,0 +1,121 @@
+#ifndef UART_ADDON_H
+#define UART_ADDON_H
+/************************************************************************
+Title: UART addon-library
+Author: Martin Thomas
+ http://www.siwawi.arubi.uni-kl.de/avr_projects
+Software: AVR-GCC 3.3/3.4, Peter Fleury's UART-Library
+************************************************************************/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @defgroup UART library-addon
+ * @code #include @endcode
+ *
+ * @brief Additional functions for send numbers as decimal and hex to UART
+ *
+ * @note needs Peter Fleury's UART-Library http://jump.to/fleury
+ * @author Martin Thomas eversmith@heizung-thomas.de
+ */
+
+/*@{*/
+
+/**
+ * @brief Put long integer to ringbuffer for transmitting via UART.
+ *
+ * The integer is converted to a string which is buffered by the uart
+ * library in a circular buffer and one character at a time is transmitted
+ * to the UART using interrupts.
+ *
+ * @param value to transfer
+ * @return none
+ * @see uart_puts_p
+ */
+extern void uart_put_longint( long int i );
+
+
+/**
+ * @brief Put unsigned long integer to ringbuffer for transmitting via UART.
+ *
+ * The integer is converted to a string which is buffered by the uart
+ * library in a circular buffer and one character at a time is transmitted
+ * to the UART using interrupts.
+ *
+ * @param value to transfer
+ * @return none
+ * @see uart_puts_p
+ */
+extern void uart_put_ulongint( unsigned long int i );
+
+
+/**
+ * @brief Put integer to ringbuffer for transmitting via UART.
+ *
+ * The integer is converted to a string which is buffered by the uart
+ * library in a circular buffer and one character at a time is transmitted
+ * to the UART using interrupts.
+ *
+ * @param value to transfer
+ * @return none
+ * @see uart_puts_p
+ */
+extern void uart_put_int( int i );
+
+
+/**
+ * @brief Put nibble as hex to ringbuffer for transmit via UART.
+ *
+ * The lower nibble of the parameter is convertet to correspondig
+ * hex-char and put in a circular buffer and one character at a time
+ * is transmitted to the UART using interrupts.
+ *
+ * @param value to transfer (byte, only lower nibble converted)
+ * @return none
+ * @see uart_putc
+ */
+extern void uart_puthex_nibble( const unsigned char b );
+
+/**
+ * @brief Put byte as hex to ringbuffer for transmit via UART.
+ *
+ * The upper and lower nibble of the parameter are convertet to
+ * correspondig hex-chars and put in a circular buffer and one
+ * character at a time is transmitted to the UART using interrupts.
+ *
+ * @param value to transfer
+ * @return none
+ * @see uart_puthex_nibble
+ */
+extern void uart_puthex_byte( const unsigned char b );
+
+/**
+ * @brief Put unsigned long as ASCII to ringbuffer for transmit via UART.
+ *
+ * @param value to transfer
+ * @return none
+ * @see none
+ */
+extern void uart_puthex_long( unsigned long l );
+
+/**
+ * @brief Put byte as bin to ringbuffer for transmit via UART.
+ *
+ * @param value to transfer
+ * @return none
+ * @see uart_putc
+ */
+extern void uart_putbin_byte( const unsigned char b );
+
+
+/*@}*/
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* UART_ADDON_H */
+
diff --git a/boot/avrprog_boot.pnproj b/boot/avrprog_boot.pnproj
new file mode 100755
index 0000000..1777f3c
--- /dev/null
+++ b/boot/avrprog_boot.pnproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/boot/avrprog_boot.pnps b/boot/avrprog_boot.pnps
new file mode 100755
index 0000000..10c6d31
--- /dev/null
+++ b/boot/avrprog_boot.pnps
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/boot/boot.aps b/boot/boot.aps
new file mode 100755
index 0000000..2e0e98c
--- /dev/null
+++ b/boot/boot.aps
@@ -0,0 +1 @@
+boot12-Nov-2013 16:48:0114-Nov-2013 10:36:05241012-Nov-2013 16:48:0144, 19, 0, 730AVR GCCC:\Hard\boot\AVR SimulatorATmega8.xmlfalseR00R01R02R03R04R05R06R07R08R09R10R11R12R13R14R15R16R17R18R19R20R21R22R23R24R25R26R27R28R29R30R31Auto000main.cmakefiledefaultYESmakefileatmega811
boot.elfdefault\0-Wall -gdwarf-2 -std=gnu99 -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enumsdefault0C:\Hard\WinAVR-20100110\bin\avr-gcc.exeC:\Hard\WinAVR-20100110\utils\bin\make.exeC:\Hard\boot\main.c00000main.c1
diff --git a/boot/boot.aws b/boot/boot.aws
new file mode 100755
index 0000000..1a002cb
--- /dev/null
+++ b/boot/boot.aws
@@ -0,0 +1 @@
+
diff --git a/boot/chipdef.h b/boot/chipdef.h
new file mode 100755
index 0000000..63f67e7
--- /dev/null
+++ b/boot/chipdef.h
@@ -0,0 +1,59 @@
+#ifndef CHIPDEF_H
+#define CHIPDEF_H
+
+#include
+
+#if defined (SPMCSR)
+#define SPM_REG SPMCSR
+#elif defined (SPMCR)
+#define SPM_REG SPMCR
+#else
+#error "AVR processor does not provide bootloader support!"
+#endif
+
+#define APP_END (FLASHEND - (BOOTSIZE * 2))
+
+#if (SPM_PAGESIZE > UINT8_MAX)
+typedef uint16_t pagebuf_t;
+#else
+typedef uint8_t pagebuf_t;
+#endif
+
+#if defined(__AVR_ATmega169__)
+#include "mega169.h"
+
+#elif defined(__AVR_ATmega16__)
+#include "mega16.h"
+
+#elif defined(__AVR_ATmega162__)
+#include "mega162.h"
+
+#elif defined(__AVR_ATmega8__)
+#include "mega8.h"
+
+#elif defined(__AVR_ATmega32__)
+#include "mega32.h"
+
+#elif defined(__AVR_ATmega324P__)
+#include "mega324p.h"
+
+#elif defined(__AVR_ATmega64__)
+#include "mega64.h"
+
+#elif defined(__AVR_ATmega644__)
+#include "mega644.h"
+
+#elif defined(__AVR_ATmega644P__)
+#include "mega644p.h"
+
+#elif defined(__AVR_ATmega128__)
+#include "mega128.h"
+
+#elif defined(__AVR_AT90CAN128__)
+#include "mega128can.h"
+
+#else
+#error "no definition for MCU available in chipdef.h"
+#endif
+
+#endif
diff --git a/boot/default/Makefile b/boot/default/Makefile
new file mode 100755
index 0000000..69ebf14
--- /dev/null
+++ b/boot/default/Makefile
@@ -0,0 +1,75 @@
+###############################################################################
+# Makefile for the project Bootloader
+###############################################################################
+
+## General Flags
+PROJECT = Bootloader
+MCU = atmega16
+TARGET = Bootloader.elf
+CC = avr-gcc
+
+## Options common to compile, link and assembly rules
+COMMON = -mmcu=$(MCU)
+
+## Compile options common for all C compilation units.
+CFLAGS = $(COMMON)
+CFLAGS += -Wall -gdwarf-2 -Os -std=gnu99 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
+CFLAGS += -MD -MP -MT $(*F).o -MF dep/$(@F).d
+
+## Assembly specific flags
+ASMFLAGS = $(COMMON)
+ASMFLAGS += $(CFLAGS)
+ASMFLAGS += -x assembler-with-cpp -Wa,-gdwarf2
+
+## Linker flags
+LDFLAGS = $(COMMON)
+LDFLAGS += -Wl,-Map=Bootloader.map
+
+
+## Intel Hex file production flags
+HEX_FLASH_FLAGS = -R .eeprom -R .fuse -R .lock -R .signature
+
+HEX_EEPROM_FLAGS = -j .eeprom
+HEX_EEPROM_FLAGS += --set-section-flags=.eeprom="alloc,load"
+HEX_EEPROM_FLAGS += --change-section-lma .eeprom=0 --no-change-warnings
+
+
+## Objects that must be built in order to link
+OBJECTS = main.o
+
+## Objects explicitly added by the user
+LINKONLYOBJECTS =
+
+## Build
+all: $(TARGET) Bootloader.hex Bootloader.eep Bootloader.lss size
+
+## Compile
+main.o: ../main.c
+ $(CC) $(INCLUDES) $(CFLAGS) -c $<
+
+##Link
+$(TARGET): $(OBJECTS)
+ $(CC) $(LDFLAGS) $(OBJECTS) $(LINKONLYOBJECTS) $(LIBDIRS) $(LIBS) -o $(TARGET)
+
+%.hex: $(TARGET)
+ avr-objcopy -O ihex $(HEX_FLASH_FLAGS) $< $@
+
+%.eep: $(TARGET)
+ -avr-objcopy $(HEX_EEPROM_FLAGS) -O ihex $< $@ || exit 0
+
+%.lss: $(TARGET)
+ avr-objdump -h -S $< > $@
+
+size: ${TARGET}
+ @echo
+ @avr-size -C --mcu=${MCU} ${TARGET}
+
+## Clean target
+.PHONY: clean
+clean:
+ -rm -rf $(OBJECTS) Bootloader.elf dep/* Bootloader.hex Bootloader.eep Bootloader.lss Bootloader.map
+
+
+## Other dependencies
+-include $(shell mkdir dep 2>/dev/null) $(wildcard dep/*)
+
diff --git a/boot/default/dep/main.o.d b/boot/default/dep/main.o.d
new file mode 100755
index 0000000..4b1eb18
--- /dev/null
+++ b/boot/default/dep/main.o.d
@@ -0,0 +1,62 @@
+main.o: ../main.c c:/winavr/lib/gcc/../../avr/include/stdint.h \
+ c:/winavr/lib/gcc/../../avr/include/avr/io.h \
+ c:/winavr/lib/gcc/../../avr/include/avr/sfr_defs.h \
+ c:/winavr/lib/gcc/../../avr/include/inttypes.h \
+ c:/winavr/lib/gcc/../../avr/include/avr/iom16.h \
+ c:/winavr/lib/gcc/../../avr/include/avr/portpins.h \
+ c:/winavr/lib/gcc/../../avr/include/avr/common.h \
+ c:/winavr/lib/gcc/../../avr/include/avr/version.h \
+ c:/winavr/lib/gcc/../../avr/include/avr/fuse.h \
+ c:/winavr/lib/gcc/../../avr/include/avr/lock.h \
+ c:/winavr/lib/gcc/../../avr/include/avr/wdt.h \
+ c:/winavr/lib/gcc/../../avr/include/avr/boot.h \
+ c:/winavr/lib/gcc/../../avr/include/avr/eeprom.h \
+ c:\winavr\bin\../lib/gcc/avr/4.3.2/include/stddef.h \
+ c:\winavr\bin\../lib/gcc/avr/4.3.2/include-fixed/limits.h \
+ c:/winavr/lib/gcc/../../avr/include/avr/pgmspace.h \
+ c:/winavr/lib/gcc/../../avr/include/avr/interrupt.h \
+ c:/winavr/lib/gcc/../../avr/include/util/delay.h \
+ c:/winavr/lib/gcc/../../avr/include/util/delay_basic.h ../chipdef.h \
+ ../mega16.h
+
+c:/winavr/lib/gcc/../../avr/include/stdint.h:
+
+c:/winavr/lib/gcc/../../avr/include/avr/io.h:
+
+c:/winavr/lib/gcc/../../avr/include/avr/sfr_defs.h:
+
+c:/winavr/lib/gcc/../../avr/include/inttypes.h:
+
+c:/winavr/lib/gcc/../../avr/include/avr/iom16.h:
+
+c:/winavr/lib/gcc/../../avr/include/avr/portpins.h:
+
+c:/winavr/lib/gcc/../../avr/include/avr/common.h:
+
+c:/winavr/lib/gcc/../../avr/include/avr/version.h:
+
+c:/winavr/lib/gcc/../../avr/include/avr/fuse.h:
+
+c:/winavr/lib/gcc/../../avr/include/avr/lock.h:
+
+c:/winavr/lib/gcc/../../avr/include/avr/wdt.h:
+
+c:/winavr/lib/gcc/../../avr/include/avr/boot.h:
+
+c:/winavr/lib/gcc/../../avr/include/avr/eeprom.h:
+
+c:\winavr\bin\../lib/gcc/avr/4.3.2/include/stddef.h:
+
+c:\winavr\bin\../lib/gcc/avr/4.3.2/include-fixed/limits.h:
+
+c:/winavr/lib/gcc/../../avr/include/avr/pgmspace.h:
+
+c:/winavr/lib/gcc/../../avr/include/avr/interrupt.h:
+
+c:/winavr/lib/gcc/../../avr/include/util/delay.h:
+
+c:/winavr/lib/gcc/../../avr/include/util/delay_basic.h:
+
+../chipdef.h:
+
+../mega16.h:
diff --git a/boot/ldscripts_no_vector/avr1.x b/boot/ldscripts_no_vector/avr1.x
new file mode 100755
index 0000000..77ff9c7
--- /dev/null
+++ b/boot/ldscripts_no_vector/avr1.x
@@ -0,0 +1,169 @@
+/* Default linker script, for normal executables */
+OUTPUT_FORMAT("elf32-avr","elf32-avr","elf32-avr")
+OUTPUT_ARCH(avr:1)
+MEMORY
+{
+ text (rx) : ORIGIN = 0, LENGTH = 8K
+ data (rw!x) : ORIGIN = 0x800060, LENGTH = 0
+ eeprom (rw!x) : ORIGIN = 0x810000, LENGTH = 64K
+}
+SECTIONS
+{
+ /* Read-only sections, merged into text segment: */
+ .hash : { *(.hash) }
+ .dynsym : { *(.dynsym) }
+ .dynstr : { *(.dynstr) }
+ .gnu.version : { *(.gnu.version) }
+ .gnu.version_d : { *(.gnu.version_d) }
+ .gnu.version_r : { *(.gnu.version_r) }
+ .rel.init : { *(.rel.init) }
+ .rela.init : { *(.rela.init) }
+ .rel.text :
+ {
+ *(.rel.text)
+ *(.rel.text.*)
+ *(.rel.gnu.linkonce.t*)
+ }
+ .rela.text :
+ {
+ *(.rela.text)
+ *(.rela.text.*)
+ *(.rela.gnu.linkonce.t*)
+ }
+ .rel.fini : { *(.rel.fini) }
+ .rela.fini : { *(.rela.fini) }
+ .rel.rodata :
+ {
+ *(.rel.rodata)
+ *(.rel.rodata.*)
+ *(.rel.gnu.linkonce.r*)
+ }
+ .rela.rodata :
+ {
+ *(.rela.rodata)
+ *(.rela.rodata.*)
+ *(.rela.gnu.linkonce.r*)
+ }
+ .rel.data :
+ {
+ *(.rel.data)
+ *(.rel.data.*)
+ *(.rel.gnu.linkonce.d*)
+ }
+ .rela.data :
+ {
+ *(.rela.data)
+ *(.rela.data.*)
+ *(.rela.gnu.linkonce.d*)
+ }
+ .rel.ctors : { *(.rel.ctors) }
+ .rela.ctors : { *(.rela.ctors) }
+ .rel.dtors : { *(.rel.dtors) }
+ .rela.dtors : { *(.rela.dtors) }
+ .rel.got : { *(.rel.got) }
+ .rela.got : { *(.rela.got) }
+ .rel.bss : { *(.rel.bss) }
+ .rela.bss : { *(.rela.bss) }
+ .rel.plt : { *(.rel.plt) }
+ .rela.plt : { *(.rela.plt) }
+ /* Internal text space or external memory */
+/DISCARD/ : { *(.vectors); }
+ .text :
+ {
+/* *(.vectors) */
+ __ctors_start = . ;
+ *(.ctors)
+ __ctors_end = . ;
+ __dtors_start = . ;
+ *(.dtors)
+ __dtors_end = . ;
+ *(.progmem.gcc*)
+ *(.progmem*)
+ . = ALIGN(2);
+ *(.init0) /* Start here after reset. */
+ *(.init1)
+ *(.init2) /* Clear __zero_reg__, set up stack pointer. */
+ *(.init3)
+ *(.init4) /* Initialize data and BSS. */
+ *(.init5)
+ *(.init6) /* C++ constructors. */
+ *(.init7)
+ *(.init8)
+ *(.init9) /* Call main(). */
+ *(.text)
+ . = ALIGN(2);
+ *(.text.*)
+ . = ALIGN(2);
+ *(.fini9) /* _exit() starts here. */
+ *(.fini8)
+ *(.fini7)
+ *(.fini6) /* C++ destructors. */
+ *(.fini5)
+ *(.fini4)
+ *(.fini3)
+ *(.fini2)
+ *(.fini1)
+ *(.fini0) /* Infinite loop after program termination. */
+ _etext = . ;
+ } > text
+ .data : AT (ADDR (.text) + SIZEOF (.text))
+ {
+ PROVIDE (__data_start = .) ;
+ *(.data)
+ *(.gnu.linkonce.d*)
+ . = ALIGN(2);
+ _edata = . ;
+ PROVIDE (__data_end = .) ;
+ } > data
+ .bss SIZEOF(.data) + ADDR(.data) :
+ {
+ PROVIDE (__bss_start = .) ;
+ *(.bss)
+ *(COMMON)
+ PROVIDE (__bss_end = .) ;
+ } > data
+ __data_load_start = LOADADDR(.data);
+ __data_load_end = __data_load_start + SIZEOF(.data);
+ /* Global data not cleared after reset. */
+ .noinit SIZEOF(.bss) + ADDR(.bss) :
+ {
+ PROVIDE (__noinit_start = .) ;
+ *(.noinit*)
+ PROVIDE (__noinit_end = .) ;
+ _end = . ;
+ PROVIDE (__heap_start = .) ;
+ } > data
+ .eeprom :
+ {
+ *(.eeprom*)
+ __eeprom_end = . ;
+ } > eeprom
+ /* Stabs debugging sections. */
+ .stab 0 : { *(.stab) }
+ .stabstr 0 : { *(.stabstr) }
+ .stab.excl 0 : { *(.stab.excl) }
+ .stab.exclstr 0 : { *(.stab.exclstr) }
+ .stab.index 0 : { *(.stab.index) }
+ .stab.indexstr 0 : { *(.stab.indexstr) }
+ .comment 0 : { *(.comment) }
+ /* DWARF debug sections.
+ Symbols in the DWARF debugging sections are relative to the beginning
+ of the section so we begin them at 0. */
+ /* DWARF 1 */
+ .debug 0 : { *(.debug) }
+ .line 0 : { *(.line) }
+ /* GNU DWARF 1 extensions */
+ .debug_srcinfo 0 : { *(.debug_srcinfo) }
+ .debug_sfnames 0 : { *(.debug_sfnames) }
+ /* DWARF 1.1 and DWARF 2 */
+ .debug_aranges 0 : { *(.debug_aranges) }
+ .debug_pubnames 0 : { *(.debug_pubnames) }
+ /* DWARF 2 */
+ .debug_info 0 : { *(.debug_info) *(.gnu.linkonce.wi.*) }
+ .debug_abbrev 0 : { *(.debug_abbrev) }
+ .debug_line 0 : { *(.debug_line) }
+ .debug_frame 0 : { *(.debug_frame) }
+ .debug_str 0 : { *(.debug_str) }
+ .debug_loc 0 : { *(.debug_loc) }
+ .debug_macinfo 0 : { *(.debug_macinfo) }
+}
diff --git a/boot/ldscripts_no_vector/avr2.x b/boot/ldscripts_no_vector/avr2.x
new file mode 100755
index 0000000..86a9ed6
--- /dev/null
+++ b/boot/ldscripts_no_vector/avr2.x
@@ -0,0 +1,169 @@
+/* Default linker script, for normal executables */
+OUTPUT_FORMAT("elf32-avr","elf32-avr","elf32-avr")
+OUTPUT_ARCH(avr:2)
+MEMORY
+{
+ text (rx) : ORIGIN = 0, LENGTH = 8K
+ data (rw!x) : ORIGIN = 0x800060, LENGTH = 0xffa0
+ eeprom (rw!x) : ORIGIN = 0x810000, LENGTH = 64K
+}
+SECTIONS
+{
+ /* Read-only sections, merged into text segment: */
+ .hash : { *(.hash) }
+ .dynsym : { *(.dynsym) }
+ .dynstr : { *(.dynstr) }
+ .gnu.version : { *(.gnu.version) }
+ .gnu.version_d : { *(.gnu.version_d) }
+ .gnu.version_r : { *(.gnu.version_r) }
+ .rel.init : { *(.rel.init) }
+ .rela.init : { *(.rela.init) }
+ .rel.text :
+ {
+ *(.rel.text)
+ *(.rel.text.*)
+ *(.rel.gnu.linkonce.t*)
+ }
+ .rela.text :
+ {
+ *(.rela.text)
+ *(.rela.text.*)
+ *(.rela.gnu.linkonce.t*)
+ }
+ .rel.fini : { *(.rel.fini) }
+ .rela.fini : { *(.rela.fini) }
+ .rel.rodata :
+ {
+ *(.rel.rodata)
+ *(.rel.rodata.*)
+ *(.rel.gnu.linkonce.r*)
+ }
+ .rela.rodata :
+ {
+ *(.rela.rodata)
+ *(.rela.rodata.*)
+ *(.rela.gnu.linkonce.r*)
+ }
+ .rel.data :
+ {
+ *(.rel.data)
+ *(.rel.data.*)
+ *(.rel.gnu.linkonce.d*)
+ }
+ .rela.data :
+ {
+ *(.rela.data)
+ *(.rela.data.*)
+ *(.rela.gnu.linkonce.d*)
+ }
+ .rel.ctors : { *(.rel.ctors) }
+ .rela.ctors : { *(.rela.ctors) }
+ .rel.dtors : { *(.rel.dtors) }
+ .rela.dtors : { *(.rela.dtors) }
+ .rel.got : { *(.rel.got) }
+ .rela.got : { *(.rela.got) }
+ .rel.bss : { *(.rel.bss) }
+ .rela.bss : { *(.rela.bss) }
+ .rel.plt : { *(.rel.plt) }
+ .rela.plt : { *(.rela.plt) }
+ /* Internal text space or external memory */
+/DISCARD/ : { *(.vectors); }
+ .text :
+ {
+/* *(.vectors) */
+ __ctors_start = . ;
+ *(.ctors)
+ __ctors_end = . ;
+ __dtors_start = . ;
+ *(.dtors)
+ __dtors_end = . ;
+ *(.progmem.gcc*)
+ *(.progmem*)
+ . = ALIGN(2);
+ *(.init0) /* Start here after reset. */
+ *(.init1)
+ *(.init2) /* Clear __zero_reg__, set up stack pointer. */
+ *(.init3)
+ *(.init4) /* Initialize data and BSS. */
+ *(.init5)
+ *(.init6) /* C++ constructors. */
+ *(.init7)
+ *(.init8)
+ *(.init9) /* Call main(). */
+ *(.text)
+ . = ALIGN(2);
+ *(.text.*)
+ . = ALIGN(2);
+ *(.fini9) /* _exit() starts here. */
+ *(.fini8)
+ *(.fini7)
+ *(.fini6) /* C++ destructors. */
+ *(.fini5)
+ *(.fini4)
+ *(.fini3)
+ *(.fini2)
+ *(.fini1)
+ *(.fini0) /* Infinite loop after program termination. */
+ _etext = . ;
+ } > text
+ .data : AT (ADDR (.text) + SIZEOF (.text))
+ {
+ PROVIDE (__data_start = .) ;
+ *(.data)
+ *(.gnu.linkonce.d*)
+ . = ALIGN(2);
+ _edata = . ;
+ PROVIDE (__data_end = .) ;
+ } > data
+ .bss SIZEOF(.data) + ADDR(.data) :
+ {
+ PROVIDE (__bss_start = .) ;
+ *(.bss)
+ *(COMMON)
+ PROVIDE (__bss_end = .) ;
+ } > data
+ __data_load_start = LOADADDR(.data);
+ __data_load_end = __data_load_start + SIZEOF(.data);
+ /* Global data not cleared after reset. */
+ .noinit SIZEOF(.bss) + ADDR(.bss) :
+ {
+ PROVIDE (__noinit_start = .) ;
+ *(.noinit*)
+ PROVIDE (__noinit_end = .) ;
+ _end = . ;
+ PROVIDE (__heap_start = .) ;
+ } > data
+ .eeprom :
+ {
+ *(.eeprom*)
+ __eeprom_end = . ;
+ } > eeprom
+ /* Stabs debugging sections. */
+ .stab 0 : { *(.stab) }
+ .stabstr 0 : { *(.stabstr) }
+ .stab.excl 0 : { *(.stab.excl) }
+ .stab.exclstr 0 : { *(.stab.exclstr) }
+ .stab.index 0 : { *(.stab.index) }
+ .stab.indexstr 0 : { *(.stab.indexstr) }
+ .comment 0 : { *(.comment) }
+ /* DWARF debug sections.
+ Symbols in the DWARF debugging sections are relative to the beginning
+ of the section so we begin them at 0. */
+ /* DWARF 1 */
+ .debug 0 : { *(.debug) }
+ .line 0 : { *(.line) }
+ /* GNU DWARF 1 extensions */
+ .debug_srcinfo 0 : { *(.debug_srcinfo) }
+ .debug_sfnames 0 : { *(.debug_sfnames) }
+ /* DWARF 1.1 and DWARF 2 */
+ .debug_aranges 0 : { *(.debug_aranges) }
+ .debug_pubnames 0 : { *(.debug_pubnames) }
+ /* DWARF 2 */
+ .debug_info 0 : { *(.debug_info) *(.gnu.linkonce.wi.*) }
+ .debug_abbrev 0 : { *(.debug_abbrev) }
+ .debug_line 0 : { *(.debug_line) }
+ .debug_frame 0 : { *(.debug_frame) }
+ .debug_str 0 : { *(.debug_str) }
+ .debug_loc 0 : { *(.debug_loc) }
+ .debug_macinfo 0 : { *(.debug_macinfo) }
+}
diff --git a/boot/ldscripts_no_vector/avr3.x b/boot/ldscripts_no_vector/avr3.x
new file mode 100755
index 0000000..12d34ae
--- /dev/null
+++ b/boot/ldscripts_no_vector/avr3.x
@@ -0,0 +1,169 @@
+/* Default linker script, for normal executables */
+OUTPUT_FORMAT("elf32-avr","elf32-avr","elf32-avr")
+OUTPUT_ARCH(avr:3)
+MEMORY
+{
+ text (rx) : ORIGIN = 0, LENGTH = 128K
+ data (rw!x) : ORIGIN = 0x800060, LENGTH = 0xffa0
+ eeprom (rw!x) : ORIGIN = 0x810000, LENGTH = 64K
+}
+SECTIONS
+{
+ /* Read-only sections, merged into text segment: */
+ .hash : { *(.hash) }
+ .dynsym : { *(.dynsym) }
+ .dynstr : { *(.dynstr) }
+ .gnu.version : { *(.gnu.version) }
+ .gnu.version_d : { *(.gnu.version_d) }
+ .gnu.version_r : { *(.gnu.version_r) }
+ .rel.init : { *(.rel.init) }
+ .rela.init : { *(.rela.init) }
+ .rel.text :
+ {
+ *(.rel.text)
+ *(.rel.text.*)
+ *(.rel.gnu.linkonce.t*)
+ }
+ .rela.text :
+ {
+ *(.rela.text)
+ *(.rela.text.*)
+ *(.rela.gnu.linkonce.t*)
+ }
+ .rel.fini : { *(.rel.fini) }
+ .rela.fini : { *(.rela.fini) }
+ .rel.rodata :
+ {
+ *(.rel.rodata)
+ *(.rel.rodata.*)
+ *(.rel.gnu.linkonce.r*)
+ }
+ .rela.rodata :
+ {
+ *(.rela.rodata)
+ *(.rela.rodata.*)
+ *(.rela.gnu.linkonce.r*)
+ }
+ .rel.data :
+ {
+ *(.rel.data)
+ *(.rel.data.*)
+ *(.rel.gnu.linkonce.d*)
+ }
+ .rela.data :
+ {
+ *(.rela.data)
+ *(.rela.data.*)
+ *(.rela.gnu.linkonce.d*)
+ }
+ .rel.ctors : { *(.rel.ctors) }
+ .rela.ctors : { *(.rela.ctors) }
+ .rel.dtors : { *(.rel.dtors) }
+ .rela.dtors : { *(.rela.dtors) }
+ .rel.got : { *(.rel.got) }
+ .rela.got : { *(.rela.got) }
+ .rel.bss : { *(.rel.bss) }
+ .rela.bss : { *(.rela.bss) }
+ .rel.plt : { *(.rel.plt) }
+ .rela.plt : { *(.rela.plt) }
+ /* Internal text space or external memory */
+/DISCARD/ : { *(.vectors); }
+ .text :
+ {
+/* *(.vectors) */
+ __ctors_start = . ;
+ *(.ctors)
+ __ctors_end = . ;
+ __dtors_start = . ;
+ *(.dtors)
+ __dtors_end = . ;
+ *(.progmem.gcc*)
+ *(.progmem*)
+ . = ALIGN(2);
+ *(.init0) /* Start here after reset. */
+ *(.init1)
+ *(.init2) /* Clear __zero_reg__, set up stack pointer. */
+ *(.init3)
+ *(.init4) /* Initialize data and BSS. */
+ *(.init5)
+ *(.init6) /* C++ constructors. */
+ *(.init7)
+ *(.init8)
+ *(.init9) /* Call main(). */
+ *(.text)
+ . = ALIGN(2);
+ *(.text.*)
+ . = ALIGN(2);
+ *(.fini9) /* _exit() starts here. */
+ *(.fini8)
+ *(.fini7)
+ *(.fini6) /* C++ destructors. */
+ *(.fini5)
+ *(.fini4)
+ *(.fini3)
+ *(.fini2)
+ *(.fini1)
+ *(.fini0) /* Infinite loop after program termination. */
+ _etext = . ;
+ } > text
+ .data : AT (ADDR (.text) + SIZEOF (.text))
+ {
+ PROVIDE (__data_start = .) ;
+ *(.data)
+ *(.gnu.linkonce.d*)
+ . = ALIGN(2);
+ _edata = . ;
+ PROVIDE (__data_end = .) ;
+ } > data
+ .bss SIZEOF(.data) + ADDR(.data) :
+ {
+ PROVIDE (__bss_start = .) ;
+ *(.bss)
+ *(COMMON)
+ PROVIDE (__bss_end = .) ;
+ } > data
+ __data_load_start = LOADADDR(.data);
+ __data_load_end = __data_load_start + SIZEOF(.data);
+ /* Global data not cleared after reset. */
+ .noinit SIZEOF(.bss) + ADDR(.bss) :
+ {
+ PROVIDE (__noinit_start = .) ;
+ *(.noinit*)
+ PROVIDE (__noinit_end = .) ;
+ _end = . ;
+ PROVIDE (__heap_start = .) ;
+ } > data
+ .eeprom :
+ {
+ *(.eeprom*)
+ __eeprom_end = . ;
+ } > eeprom
+ /* Stabs debugging sections. */
+ .stab 0 : { *(.stab) }
+ .stabstr 0 : { *(.stabstr) }
+ .stab.excl 0 : { *(.stab.excl) }
+ .stab.exclstr 0 : { *(.stab.exclstr) }
+ .stab.index 0 : { *(.stab.index) }
+ .stab.indexstr 0 : { *(.stab.indexstr) }
+ .comment 0 : { *(.comment) }
+ /* DWARF debug sections.
+ Symbols in the DWARF debugging sections are relative to the beginning
+ of the section so we begin them at 0. */
+ /* DWARF 1 */
+ .debug 0 : { *(.debug) }
+ .line 0 : { *(.line) }
+ /* GNU DWARF 1 extensions */
+ .debug_srcinfo 0 : { *(.debug_srcinfo) }
+ .debug_sfnames 0 : { *(.debug_sfnames) }
+ /* DWARF 1.1 and DWARF 2 */
+ .debug_aranges 0 : { *(.debug_aranges) }
+ .debug_pubnames 0 : { *(.debug_pubnames) }
+ /* DWARF 2 */
+ .debug_info 0 : { *(.debug_info) *(.gnu.linkonce.wi.*) }
+ .debug_abbrev 0 : { *(.debug_abbrev) }
+ .debug_line 0 : { *(.debug_line) }
+ .debug_frame 0 : { *(.debug_frame) }
+ .debug_str 0 : { *(.debug_str) }
+ .debug_loc 0 : { *(.debug_loc) }
+ .debug_macinfo 0 : { *(.debug_macinfo) }
+}
diff --git a/boot/ldscripts_no_vector/avr4.x b/boot/ldscripts_no_vector/avr4.x
new file mode 100755
index 0000000..6b371f4
--- /dev/null
+++ b/boot/ldscripts_no_vector/avr4.x
@@ -0,0 +1,169 @@
+/* MODIFIED LINKER SCRIPT - BOOTLOADER: without .vectors */
+OUTPUT_FORMAT("elf32-avr","elf32-avr","elf32-avr")
+OUTPUT_ARCH(avr:4)
+MEMORY
+{
+ text (rx) : ORIGIN = 0, LENGTH = 8K
+ data (rw!x) : ORIGIN = 0x800060, LENGTH = 0xffa0
+ eeprom (rw!x) : ORIGIN = 0x810000, LENGTH = 64K
+}
+SECTIONS
+{
+ /* Read-only sections, merged into text segment: */
+ .hash : { *(.hash) }
+ .dynsym : { *(.dynsym) }
+ .dynstr : { *(.dynstr) }
+ .gnu.version : { *(.gnu.version) }
+ .gnu.version_d : { *(.gnu.version_d) }
+ .gnu.version_r : { *(.gnu.version_r) }
+ .rel.init : { *(.rel.init) }
+ .rela.init : { *(.rela.init) }
+ .rel.text :
+ {
+ *(.rel.text)
+ *(.rel.text.*)
+ *(.rel.gnu.linkonce.t*)
+ }
+ .rela.text :
+ {
+ *(.rela.text)
+ *(.rela.text.*)
+ *(.rela.gnu.linkonce.t*)
+ }
+ .rel.fini : { *(.rel.fini) }
+ .rela.fini : { *(.rela.fini) }
+ .rel.rodata :
+ {
+ *(.rel.rodata)
+ *(.rel.rodata.*)
+ *(.rel.gnu.linkonce.r*)
+ }
+ .rela.rodata :
+ {
+ *(.rela.rodata)
+ *(.rela.rodata.*)
+ *(.rela.gnu.linkonce.r*)
+ }
+ .rel.data :
+ {
+ *(.rel.data)
+ *(.rel.data.*)
+ *(.rel.gnu.linkonce.d*)
+ }
+ .rela.data :
+ {
+ *(.rela.data)
+ *(.rela.data.*)
+ *(.rela.gnu.linkonce.d*)
+ }
+ .rel.ctors : { *(.rel.ctors) }
+ .rela.ctors : { *(.rela.ctors) }
+ .rel.dtors : { *(.rel.dtors) }
+ .rela.dtors : { *(.rela.dtors) }
+ .rel.got : { *(.rel.got) }
+ .rela.got : { *(.rela.got) }
+ .rel.bss : { *(.rel.bss) }
+ .rela.bss : { *(.rela.bss) }
+ .rel.plt : { *(.rel.plt) }
+ .rela.plt : { *(.rela.plt) }
+ /* Internal text space or external memory */
+/DISCARD/ : { *(.vectors); }
+ .text :
+ {
+/* *(.vectors) */
+ __ctors_start = . ;
+ *(.ctors)
+ __ctors_end = . ;
+ __dtors_start = . ;
+ *(.dtors)
+ __dtors_end = . ;
+ *(.progmem.gcc*)
+ *(.progmem*)
+ . = ALIGN(2);
+ *(.init0) /* Start here after reset. */
+ *(.init1)
+ *(.init2) /* Clear __zero_reg__, set up stack pointer. */
+ *(.init3)
+ *(.init4) /* Initialize data and BSS. */
+ *(.init5)
+ *(.init6) /* C++ constructors. */
+ *(.init7)
+ *(.init8)
+ *(.init9) /* Call main(). */
+ *(.text)
+ . = ALIGN(2);
+ *(.text.*)
+ . = ALIGN(2);
+ *(.fini9) /* _exit() starts here. */
+ *(.fini8)
+ *(.fini7)
+ *(.fini6) /* C++ destructors. */
+ *(.fini5)
+ *(.fini4)
+ *(.fini3)
+ *(.fini2)
+ *(.fini1)
+ *(.fini0) /* Infinite loop after program termination. */
+ _etext = . ;
+ } > text
+ .data : AT (ADDR (.text) + SIZEOF (.text))
+ {
+ PROVIDE (__data_start = .) ;
+ *(.data)
+ *(.gnu.linkonce.d*)
+ . = ALIGN(2);
+ _edata = . ;
+ PROVIDE (__data_end = .) ;
+ } > data
+ .bss SIZEOF(.data) + ADDR(.data) :
+ {
+ PROVIDE (__bss_start = .) ;
+ *(.bss)
+ *(COMMON)
+ PROVIDE (__bss_end = .) ;
+ } > data
+ __data_load_start = LOADADDR(.data);
+ __data_load_end = __data_load_start + SIZEOF(.data);
+ /* Global data not cleared after reset. */
+ .noinit SIZEOF(.bss) + ADDR(.bss) :
+ {
+ PROVIDE (__noinit_start = .) ;
+ *(.noinit*)
+ PROVIDE (__noinit_end = .) ;
+ _end = . ;
+ PROVIDE (__heap_start = .) ;
+ } > data
+ .eeprom :
+ {
+ *(.eeprom*)
+ __eeprom_end = . ;
+ } > eeprom
+ /* Stabs debugging sections. */
+ .stab 0 : { *(.stab) }
+ .stabstr 0 : { *(.stabstr) }
+ .stab.excl 0 : { *(.stab.excl) }
+ .stab.exclstr 0 : { *(.stab.exclstr) }
+ .stab.index 0 : { *(.stab.index) }
+ .stab.indexstr 0 : { *(.stab.indexstr) }
+ .comment 0 : { *(.comment) }
+ /* DWARF debug sections.
+ Symbols in the DWARF debugging sections are relative to the beginning
+ of the section so we begin them at 0. */
+ /* DWARF 1 */
+ .debug 0 : { *(.debug) }
+ .line 0 : { *(.line) }
+ /* GNU DWARF 1 extensions */
+ .debug_srcinfo 0 : { *(.debug_srcinfo) }
+ .debug_sfnames 0 : { *(.debug_sfnames) }
+ /* DWARF 1.1 and DWARF 2 */
+ .debug_aranges 0 : { *(.debug_aranges) }
+ .debug_pubnames 0 : { *(.debug_pubnames) }
+ /* DWARF 2 */
+ .debug_info 0 : { *(.debug_info) *(.gnu.linkonce.wi.*) }
+ .debug_abbrev 0 : { *(.debug_abbrev) }
+ .debug_line 0 : { *(.debug_line) }
+ .debug_frame 0 : { *(.debug_frame) }
+ .debug_str 0 : { *(.debug_str) }
+ .debug_loc 0 : { *(.debug_loc) }
+ .debug_macinfo 0 : { *(.debug_macinfo) }
+}
diff --git a/boot/ldscripts_no_vector/avr5.x b/boot/ldscripts_no_vector/avr5.x
new file mode 100755
index 0000000..a1a1fa2
--- /dev/null
+++ b/boot/ldscripts_no_vector/avr5.x
@@ -0,0 +1,172 @@
+/* MODIFIED LINKER SCRIPT - BOOTLOADER: without .vectors */
+OUTPUT_FORMAT("elf32-avr","elf32-avr","elf32-avr")
+OUTPUT_ARCH(avr:5)
+MEMORY
+{
+ text (rx) : ORIGIN = 0, LENGTH = 128K
+ data (rw!x) : ORIGIN = 0x800060, LENGTH = 0xffa0
+ eeprom (rw!x) : ORIGIN = 0x810000, LENGTH = 64K
+}
+SECTIONS
+{
+ /* Read-only sections, merged into text segment: */
+ .hash : { *(.hash) }
+ .dynsym : { *(.dynsym) }
+ .dynstr : { *(.dynstr) }
+ .gnu.version : { *(.gnu.version) }
+ .gnu.version_d : { *(.gnu.version_d) }
+ .gnu.version_r : { *(.gnu.version_r) }
+ .rel.init : { *(.rel.init) }
+ .rela.init : { *(.rela.init) }
+ .rel.text :
+ {
+ *(.rel.text)
+ *(.rel.text.*)
+ *(.rel.gnu.linkonce.t*)
+ }
+ .rela.text :
+ {
+ *(.rela.text)
+ *(.rela.text.*)
+ *(.rela.gnu.linkonce.t*)
+ }
+ .rel.fini : { *(.rel.fini) }
+ .rela.fini : { *(.rela.fini) }
+ .rel.rodata :
+ {
+ *(.rel.rodata)
+ *(.rel.rodata.*)
+ *(.rel.gnu.linkonce.r*)
+ }
+ .rela.rodata :
+ {
+ *(.rela.rodata)
+ *(.rela.rodata.*)
+ *(.rela.gnu.linkonce.r*)
+ }
+ .rel.data :
+ {
+ *(.rel.data)
+ *(.rel.data.*)
+ *(.rel.gnu.linkonce.d*)
+ }
+ .rela.data :
+ {
+ *(.rela.data)
+ *(.rela.data.*)
+ *(.rela.gnu.linkonce.d*)
+ }
+ .rel.ctors : { *(.rel.ctors) }
+ .rela.ctors : { *(.rela.ctors) }
+ .rel.dtors : { *(.rel.dtors) }
+ .rela.dtors : { *(.rela.dtors) }
+ .rel.got : { *(.rel.got) }
+ .rela.got : { *(.rela.got) }
+ .rel.bss : { *(.rel.bss) }
+ .rela.bss : { *(.rela.bss) }
+ .rel.plt : { *(.rel.plt) }
+ .rela.plt : { *(.rela.plt) }
+
+ /* Internal text space or external memory */
+
+/* BOOTLOADER-MODIFICATION - not interrupt-vectors */
+ /DISCARD/ : { *(.vectors) }
+ .text :
+ {
+/* *(.vectors) */ /* BOOTLOADER-MODIFICATION ! */
+ __ctors_start = . ;
+ *(.ctors)
+ __ctors_end = . ;
+ __dtors_start = . ;
+ *(.dtors)
+ __dtors_end = . ;
+ *(.progmem.gcc*)
+ *(.progmem*)
+ . = ALIGN(2);
+ *(.init0) /* Start here after reset. */
+ *(.init1)
+ *(.init2) /* Clear __zero_reg__, set up stack pointer. */
+ *(.init3)
+ *(.init4) /* Initialize data and BSS. */
+ *(.init5)
+ *(.init6) /* C++ constructors. */
+ *(.init7)
+ *(.init8)
+ *(.init9) /* Call main(). */
+ *(.text)
+ . = ALIGN(2);
+ *(.text.*)
+ . = ALIGN(2);
+ *(.fini9) /* _exit() starts here. */
+ *(.fini8)
+ *(.fini7)
+ *(.fini6) /* C++ destructors. */
+ *(.fini5)
+ *(.fini4)
+ *(.fini3)
+ *(.fini2)
+ *(.fini1)
+ *(.fini0) /* Infinite loop after program termination. */
+ _etext = . ;
+ } > text
+ .data : AT (ADDR (.text) + SIZEOF (.text))
+ {
+ PROVIDE (__data_start = .) ;
+ *(.data)
+ *(.gnu.linkonce.d*)
+ . = ALIGN(2);
+ _edata = . ;
+ PROVIDE (__data_end = .) ;
+ } > data
+ .bss SIZEOF(.data) + ADDR(.data) :
+ {
+ PROVIDE (__bss_start = .) ;
+ *(.bss)
+ *(COMMON)
+ PROVIDE (__bss_end = .) ;
+ } > data
+ __data_load_start = LOADADDR(.data);
+ __data_load_end = __data_load_start + SIZEOF(.data);
+ /* Global data not cleared after reset. */
+ .noinit SIZEOF(.bss) + ADDR(.bss) :
+ {
+ PROVIDE (__noinit_start = .) ;
+ *(.noinit*)
+ PROVIDE (__noinit_end = .) ;
+ _end = . ;
+ PROVIDE (__heap_start = .) ;
+ } > data
+ .eeprom :
+ {
+ *(.eeprom*)
+ __eeprom_end = . ;
+ } > eeprom
+ /* Stabs debugging sections. */
+ .stab 0 : { *(.stab) }
+ .stabstr 0 : { *(.stabstr) }
+ .stab.excl 0 : { *(.stab.excl) }
+ .stab.exclstr 0 : { *(.stab.exclstr) }
+ .stab.index 0 : { *(.stab.index) }
+ .stab.indexstr 0 : { *(.stab.indexstr) }
+ .comment 0 : { *(.comment) }
+ /* DWARF debug sections.
+ Symbols in the DWARF debugging sections are relative to the beginning
+ of the section so we begin them at 0. */
+ /* DWARF 1 */
+ .debug 0 : { *(.debug) }
+ .line 0 : { *(.line) }
+ /* GNU DWARF 1 extensions */
+ .debug_srcinfo 0 : { *(.debug_srcinfo) }
+ .debug_sfnames 0 : { *(.debug_sfnames) }
+ /* DWARF 1.1 and DWARF 2 */
+ .debug_aranges 0 : { *(.debug_aranges) }
+ .debug_pubnames 0 : { *(.debug_pubnames) }
+ /* DWARF 2 */
+ .debug_info 0 : { *(.debug_info) *(.gnu.linkonce.wi.*) }
+ .debug_abbrev 0 : { *(.debug_abbrev) }
+ .debug_line 0 : { *(.debug_line) }
+ .debug_frame 0 : { *(.debug_frame) }
+ .debug_str 0 : { *(.debug_str) }
+ .debug_loc 0 : { *(.debug_loc) }
+ .debug_macinfo 0 : { *(.debug_macinfo) }
+}
diff --git a/boot/main b/boot/main
new file mode 100755
index 0000000..c4b93b7
Binary files /dev/null and b/boot/main differ
diff --git a/boot/main.c b/boot/main.c
new file mode 100755
index 0000000..61d74a7
--- /dev/null
+++ b/boot/main.c
@@ -0,0 +1,686 @@
+/*****************************************************************************
+*
+* AVRPROG compatible boot-loader
+* Version : 0.85 (Dec. 2008)
+* Compiler : avr-gcc 4.1.2 / avr-libc 1.4.6
+* size : depends on features and startup ( minmal features < 512 words)
+* by : Martin Thomas, Kaiserslautern, Germany
+* eversmith@heizung-thomas.de
+* Additional code and improvements contributed by:
+* - Uwe Bonnes
+* - Bjoern Riemer
+* - Olaf Rempel
+*
+* License : Copyright (c) 2006-2008 M. Thomas, U. Bonnes, O. Rempel
+* Free to use. You have to mention the copyright
+* owners in source-code and documentation of derived
+* work. No warranty! (Yes, you can insert the BSD
+* license here)
+*
+* Tested with ATmega8, ATmega16, ATmega162, ATmega32, ATmega324P,
+* ATmega644, ATmega644P, ATmega128, AT90CAN128
+*
+* - Initial versions have been based on the Butterfly bootloader-code
+* by Atmel Corporation (Authors: BBrandal, PKastnes, ARodland, LHM)
+*
+****************************************************************************
+*
+* See the makefile and readme.txt for information on how to adapt
+* the linker-settings to the selected Boot Size (BOOTSIZE=xxxx) and
+* the MCU-type. Other configurations futher down in this file.
+*
+* With BOOT_SIMPLE, minimal features and discarded int-vectors
+* this bootloader has should fit into a a 512 word (1024, 0x400 bytes)
+* bootloader-section.
+*
+****************************************************************************/
+
+/* Частота контроллера (кварца) */
+#ifndef F_CPU
+// #define F_CPU 7372800
+//#define F_CPU (7372800/2)
+#define F_CPU 8000000
+#endif
+
+/* UART Скорость UART оптимально 19200 */
+//#define BAUDRATE 9600
+#define BAUDRATE 19200
+//#define BAUDRATE 115200
+
+/* Режим двойной скорости UART (бит U2C)*/
+//#define UART_DOUBLESPEED
+
+/* Используется второй UART на mega128 / can128 / mega162 / mega324p / mega644p */
+//#define UART_USE_SECOND
+
+/* Тип устройства:
+ Для AVRProg выбирать BOOT
+ Это корректное значение для bootloader.
+ avrdude может определить только part-code для ISP */
+#define DEVTYPE DEVTYPE_BOOT
+// #define DEVTYPE DEVTYPE_ISP
+
+/*
+ * Выбор порта для кнопки входа в загрузчик
+ * Чтобы войти в загрузчик надо чтобы при запуске эта кнопка замыкала пин на землю
+ */
+#define BLPORT PORTD
+#define BLDDR DDRD
+#define BLPIN PIND
+#define BLPNUM PIND7
+
+/*
+ * Выбор порта для индикатора работы загрузчика
+ * Светодиод горит - мы в загрузчике
+ */
+
+#define ENABLE_BOOT_LED
+#define BIPORT PORTD
+#define BIDDR DDRD
+#define BIPIN PIND
+#define BIPNUM PIND5
+
+
+/*
+ * Выключить Собачий таймер на время загрузчика
+ */
+#define DISABLE_WDT_AT_STARTUP
+
+/*
+ * Watchdog-reset is issued at exit
+ * define the timeout-value here (see avr-libc manual)
+ */
+#define EXIT_WDT_TIME WDTO_250MS
+
+/*
+ * Выбор режима загрузчика
+ * SIMPLE-Mode - Загрузчик стартует когда нажата его кнопка
+ * переход к основной программе осуществляется после сброса
+ * (кнопка должна быть отжата) либо по команде от программатора
+ * При этом режиме вывод на кнопку конфигурируется как вход-с подтягом,
+ * но при выходе из загрузчика все выставляется по умолчанию
+ * POWERSAVE-Mode - Startup is separated in two loops
+ * which makes power-saving a little easier if no firmware
+ * is on the chip. Needs more memory
+ * BOOTICE-Mode - для зашивки JTAGICE файла upgrade.ebn в Мегу16.
+ * что превращает ее в JTAG отладчик. Разумеется нужно добавить весь необходимый
+ * обвяз на кристалл для этого. И частота должна быть везде прописана как 7372800
+ * в F_CPU Для совместимости с родной прошивкой JTAG ICE
+ * WAIT-mode Bootloader ожидает команды на вход, если ее не было в течении промежутка времени
+ * (который настраивается) то проихсодит переход к основной программе.
+ */
+//#define START_SIMPLE
+#define START_WAIT
+//#define START_POWERSAVE
+//#define START_BOOTICE
+
+/* Команда для входа в загрузчик в START_WAIT */
+#define START_WAIT_UARTCHAR 'S'
+
+/* Выдержка для START_WAIT mode ( t = WAIT_TIME * 10ms ) */
+#define WAIT_VALUE 300 /* сейчас: 300*10ms = 3000ms = 3sec */
+
+/*
+ * enable/disable readout of fuse and lock-bits
+ * (AVRPROG has to detect the AVR correctly by device-code
+ * to show the correct information).
+ */
+//#define ENABLEREADFUSELOCK
+
+/* enable/disable write of lock-bits
+ * WARNING: lock-bits can not be reseted by bootloader (as far as I know)
+ * Only protection no unprotection, "chip erase" from bootloader only
+ * clears the flash but does no real "chip erase" (this is not possible
+ * with a bootloader as far as I know)
+ * Keep this undefined!
+ */
+//#define WRITELOCKBITS
+
+/*
+ * define the following if the bootloader should not output
+ * itself at flash read (will fake an empty boot-section)
+ */
+//#define READ_PROTECT_BOOTLOADER
+
+#define VERSION_HIGH '0'
+#define VERSION_LOW '8'
+
+#define GET_LOCK_BITS 0x0001
+#define GET_LOW_FUSE_BITS 0x0000
+#define GET_HIGH_FUSE_BITS 0x0003
+#define GET_EXTENDED_FUSE_BITS 0x0002
+
+/* Расчет делителя частоты для USART*/
+#ifdef UART_DOUBLESPEED
+
+ #define UART_CALC_BAUDRATE(baudRate) ((uint32_t)((F_CPU) + ((uint32_t)baudRate * 4UL)) / ((uint32_t)(baudRate) * 8UL) - 1)
+
+#else
+
+ #define UART_CALC_BAUDRATE(baudRate) ((uint32_t)((F_CPU) + ((uint32_t)baudRate * 8UL)) / ((uint32_t)(baudRate) * 16UL) - 1)
+
+#endif
+
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "chipdef.h"
+
+uint8_t gBuffer[SPM_PAGESIZE];
+
+#if defined(BOOTLOADERHASNOVECTORS)
+ #warning "This Bootloader does not link interrupt vectors - see makefile"
+ /* make the linker happy - it wants to see __vector_default */
+ // void __vector_default(void) { ; }
+ void __vector_default(void) { ; }
+#endif
+
+static void sendchar(uint8_t data)
+{
+ while (!(UART_STATUS & (1< addr)
+ {
+ boot_page_erase(addr); // Perform page erase
+ boot_spm_busy_wait(); // Wait until the memory is erased.
+ addr += SPM_PAGESIZE;
+ }
+ boot_rww_enable();
+}
+
+static inline void recvBuffer(pagebuf_t size)
+{
+ pagebuf_t cnt;
+ uint8_t *tmp = gBuffer;
+
+ for (cnt = 0; cnt < sizeof(gBuffer); cnt++)
+ {
+ *tmp++ = (cnt < size) ? recvchar() : 0xFF;
+ }
+}
+
+static inline uint16_t writeFlashPage(uint16_t waddr, pagebuf_t size)
+{
+ uint32_t pagestart = (uint32_t)waddr<<1;
+ uint32_t baddr = pagestart;
+ uint16_t data;
+ uint8_t *tmp = gBuffer;
+
+ do
+ {
+ data = *tmp++;
+ data |= *tmp++ << 8;
+ boot_page_fill(baddr, data); // call asm routine.
+
+ baddr += 2; // Select next word in memory
+ size -= 2; // Reduce number of bytes to write by two
+ }
+ while (size); // Loop until all bytes written
+
+ boot_page_write(pagestart);
+ boot_spm_busy_wait();
+ boot_rww_enable(); // Re-enable the RWW section
+
+ return baddr>>1;
+}
+
+static inline uint16_t writeEEpromPage(uint16_t address, pagebuf_t size)
+{
+ uint8_t *tmp = gBuffer;
+
+ do
+ {
+ eeprom_write_byte( (uint8_t*)address, *tmp++ );
+ address++; // Select next byte
+ size--; // Decreas number of bytes to write
+ }
+ while (size); // Loop until all bytes written
+
+ // eeprom_busy_wait();
+
+ return address;
+}
+
+static inline uint16_t readFlashPage(uint16_t waddr, pagebuf_t size)
+{
+ uint32_t baddr = (uint32_t)waddr<<1;
+ uint16_t data;
+
+ do
+ {
+
+#ifndef READ_PROTECT_BOOTLOADER
+#warning "Bootloader not read-protected"
+
+ #if defined(RAMPZ)
+ data = pgm_read_word_far(baddr);
+ #else
+ data = pgm_read_word_near(baddr);
+ #endif
+
+#else
+ // don't read bootloader
+ if ( baddr < APP_END )
+ {
+ #if defined(RAMPZ)
+ data = pgm_read_word_far(baddr);
+ #else
+ data = pgm_read_word_near(baddr);
+ #endif
+ }
+ else
+ {
+ data = 0xFFFF; // fake empty
+ }
+#endif
+ sendchar(data); // send LSB
+ sendchar((data >> 8)); // send MSB
+ baddr += 2; // Select next word in memory
+ size -= 2; // Subtract two bytes from number of bytes to read
+ }
+ while (size); // Repeat until block has been read
+ return baddr>>1;
+}
+
+static inline uint16_t readEEpromPage(uint16_t address, pagebuf_t size)
+{
+ do
+ {
+ sendchar( eeprom_read_byte( (uint8_t*)address ) );
+ address++;
+ size--; // Decrease number of bytes to read
+ }
+ while (size); // Repeat until block has been read
+
+ return address;
+}
+
+#if defined(ENABLEREADFUSELOCK)
+static uint8_t read_fuse_lock(uint16_t addr)
+{
+ uint8_t mode = (1<>8) & 0xFF;
+ UART_BAUD_LOW = (UART_CALC_BAUDRATE(BAUDRATE) & 0xFF);
+
+#ifdef UART_DOUBLESPEED
+ UART_STATUS = ( 1<= WAIT_VALUE) {
+ BLPORT &= ~(1<> 8) & 0xFF); // Report buffer size in bytes
+ sendchar(sizeof(gBuffer) & 0xFF);
+
+ // Start buffer load
+ }
+ else if (val == 'B')
+ {
+ pagebuf_t size;
+ size = recvchar() << 8; // Load high byte of buffersize
+ size |= recvchar(); // Load low byte of buffersize
+ val = recvchar(); // Load memory type ('E' or 'F')
+ recvBuffer(size);
+
+ if (device == DEVTYPE)
+ {
+ if (val == 'F')
+ {
+ address = writeFlashPage(address, size);
+ }
+ else if (val == 'E')
+ {
+ address = writeEEpromPage(address, size);
+ }
+ sendchar('\r');
+ }
+ else
+ {
+ sendchar(0);
+ }
+
+ // Block read
+ }
+ else if (val == 'g')
+ {
+ pagebuf_t size;
+ size = recvchar() << 8; // Load high byte of buffersize
+ size |= recvchar(); // Load low byte of buffersize
+ val = recvchar(); // Get memtype
+
+ if (val == 'F')
+ {
+ address = readFlashPage(address, size);
+ }
+ else if (val == 'E')
+ {
+ address = readEEpromPage(address, size);
+ }
+
+ // Chip erase
+ }
+ else if (val == 'e')
+ {
+ if (device == DEVTYPE)
+ {
+ eraseFlash();
+ }
+ sendchar('\r');
+
+ // Exit upgrade
+ }
+ else if (val == 'E')
+ {
+ wdt_enable(EXIT_WDT_TIME); // Enable Watchdog Timer to give reset
+ sendchar('\r');
+
+ #ifdef WRITELOCKBITS
+ #warning "Extension 'WriteLockBits' enabled"
+ // TODO: does not work reliably
+ // write lockbits
+ }
+ else if (val == 'l')
+ {
+ if (device == DEVTYPE)
+ {
+ // write_lock_bits(recvchar());
+ boot_lock_bits_set(recvchar()); // boot.h takes care of mask
+ boot_spm_busy_wait();
+ }
+ sendchar('\r');
+ #endif
+ // Enter programming mode
+ }
+ else if (val == 'P')
+ {
+ sendchar('\r');
+
+ // Leave programming mode
+ }
+ else if (val == 'L')
+ {
+ sendchar('\r');
+ // return programmer type
+ }
+ else if (val == 'p')
+ {
+ sendchar('S'); // always serial programmer
+
+ #ifdef ENABLEREADFUSELOCK
+ #warning "Extension 'ReadFuseLock' enabled"
+ // read "low" fuse bits
+ }
+ else if (val == 'F')
+ {
+ sendchar(read_fuse_lock(GET_LOW_FUSE_BITS));
+
+ // read lock bits
+ }
+ else if (val == 'r')
+ {
+ sendchar(read_fuse_lock(GET_LOCK_BITS));
+
+ // read high fuse bits
+ }
+ else if (val == 'N')
+ {
+ sendchar(read_fuse_lock(GET_HIGH_FUSE_BITS));
+ // read extended fuse bits
+ }
+ else if (val == 'Q')
+ {
+ sendchar(read_fuse_lock(GET_EXTENDED_FUSE_BITS));
+ #endif
+
+ // Return device type
+ }
+ else if (val == 't')
+ {
+ sendchar(DEVTYPE);
+ sendchar(0);
+ // clear and set LED ignored
+ }
+ else if ((val == 'x') || (val == 'y'))
+ {
+ recvchar();
+ sendchar('\r');
+
+ // set device
+ }
+ else if (val == 'T')
+ {
+ device = recvchar();
+ sendchar('\r');
+ // Return software identifier
+ }
+ else if (val == 'S')
+ {
+ send_boot();
+
+ // Return Software Version
+ }
+ else if (val == 'V') {
+ sendchar(VERSION_HIGH);
+ sendchar(VERSION_LOW);
+
+ // Return Signature Bytes (it seems that
+ // AVRProg expects the "Atmel-byte" 0x1E last
+ // but shows it first in the dialog-window)
+ }
+ else if (val == 's')
+ {
+ sendchar(SIG_BYTE3);
+ sendchar(SIG_BYTE2);
+ sendchar(SIG_BYTE1);
+
+ /* ESC */
+ }
+ else if(val != 0x1b)
+ {
+ sendchar('?');
+ }
+ }
+ return 0;
+}
diff --git a/boot/makefile b/boot/makefile
new file mode 100755
index 0000000..19887e3
--- /dev/null
+++ b/boot/makefile
@@ -0,0 +1,669 @@
+# Hey Emacs, this is a -*- makefile -*-
+#
+# Makefile for the AVRProg-compatible Bootloader
+#
+# based on the
+# WinAVR Sample makefile written by Eric B. Weddington, Jцrg Wunsch, et al.
+# Released to the Public Domain
+# Please read the make user manual!
+#
+# Additional material for this makefile was submitted by:
+# Tim Henigan
+# Peter Fleury
+# Reiner Patommel
+# Sander Pool
+# Frederik Rouleau
+# Markus Pfaff
+#
+# On command line:
+#
+# make all = Make software.
+#
+# make clean = Clean out built project files.
+#
+# make coff = Convert ELF to AVR COFF (for use with AVR Studio 3.x or VMLAB).
+#
+# make extcoff = Convert ELF to AVR Extended COFF (for use with AVR Studio
+# 4.07 or greater).
+#
+# make program = Download the hex file to the device, using avrdude. Please
+# customize the avrdude settings below first!
+#
+# make filename.s = Just compile filename.c into the assembler code only
+#
+# To rebuild project do "make clean" then "make all".
+#
+
+# user defined values
+
+# MCU name
+MCU = atmega8
+##MCU = atmega16
+## MCU = atmega162
+## MCU = atmega169
+## MCU = atmega32
+## MCU = atmega324p
+## MCU = atmega64
+## MCU = atmega644
+## MCU = atmega644p
+## MCU = atmega128
+## MCU = at90can128
+
+################## BOOTLOADER ######################
+# mt: Boot loader support. So far not done with a separate section
+# to get the interrupt vector into the bootloader area (for BOOTINTVEC=yes).
+# Bootloader address in datasheet and stk500 is given as
+# "word", gcc toolchain needs "byte"-address
+# (see LDFLAGS further down)
+
+#/* Select Boot Size in Words (select one, comment out the others) */
+## NO! BOOTSIZE=128
+## NO! BOOTSIZE=256
+ BOOTSIZE=512
+## BOOTSIZE=1024
+## BOOTSIZE=2048
+
+# /* Select if bootloader should include the inverrupt-vectors
+# when selecting 'no' here, the bootloader must not use
+# any interrupts and the modified linker-scripts are used. */
+##BOOTINTVEC=yes
+BOOTINTVEC=no
+
+##
+ifeq ($(MCU), atmega8)
+BFD_MACH=avr4
+ifeq ($(BOOTSIZE), 128)
+ MT_BOOTLOADER_ADDRESS = 0x1F00
+endif
+ifeq ($(BOOTSIZE), 256)
+ MT_BOOTLOADER_ADDRESS = 0x1E00
+endif
+ifeq ($(BOOTSIZE), 512)
+ MT_BOOTLOADER_ADDRESS = 0x1C00
+endif
+ifeq ($(BOOTSIZE), 1024)
+ MT_BOOTLOADER_ADDRESS = 0x1800
+endif
+endif
+
+##
+ifeq ($(MCU), atmega16)
+BFD_MACH=avr5
+ifeq ($(BOOTSIZE), 128)
+ MT_BOOTLOADER_ADDRESS = 0x3F00
+endif
+ifeq ($(BOOTSIZE), 256)
+ MT_BOOTLOADER_ADDRESS = 0x3E00
+endif
+ifeq ($(BOOTSIZE), 512)
+ MT_BOOTLOADER_ADDRESS = 0x3C00
+endif
+ifeq ($(BOOTSIZE), 1024)
+ MT_BOOTLOADER_ADDRESS = 0x3800
+endif
+endif
+
+##
+ifeq ($(MCU), atmega162)
+BFD_MACH=avr5
+ifeq ($(BOOTSIZE), 128)
+ MT_BOOTLOADER_ADDRESS = 0x3F00
+endif
+ifeq ($(BOOTSIZE), 256)
+ MT_BOOTLOADER_ADDRESS = 0x3E00
+endif
+ifeq ($(BOOTSIZE), 512)
+ MT_BOOTLOADER_ADDRESS = 0x3C00
+endif
+ifeq ($(BOOTSIZE), 1024)
+ MT_BOOTLOADER_ADDRESS = 0x3800
+endif
+endif
+
+##
+ifeq ($(MCU), atmega169)
+BFD_MACH=avr5
+ifeq ($(BOOTSIZE), 128)
+ MT_BOOTLOADER_ADDRESS = 0x3F00
+endif
+ifeq ($(BOOTSIZE), 256)
+ MT_BOOTLOADER_ADDRESS = 0x3E00
+endif
+ifeq ($(BOOTSIZE), 512)
+ MT_BOOTLOADER_ADDRESS = 0x3C00
+endif
+ifeq ($(BOOTSIZE), 1024)
+ MT_BOOTLOADER_ADDRESS = 0x3800
+endif
+endif
+
+##
+ifeq ($(MCU), atmega32)
+BFD_MACH=avr5
+ifeq ($(BOOTSIZE), 256)
+ MT_BOOTLOADER_ADDRESS = 0x7E00
+endif
+ifeq ($(BOOTSIZE), 512)
+ MT_BOOTLOADER_ADDRESS = 0x7C00
+endif
+ifeq ($(BOOTSIZE), 1024)
+ MT_BOOTLOADER_ADDRESS = 0x7800
+endif
+ifeq ($(BOOTSIZE), 2048)
+ MT_BOOTLOADER_ADDRESS = 0x7000
+endif
+endif
+
+##
+ifeq ($(MCU), atmega324p)
+BFD_MACH=avr5
+ifeq ($(BOOTSIZE), 256)
+ MT_BOOTLOADER_ADDRESS = 0x7E00
+endif
+ifeq ($(BOOTSIZE), 512)
+ MT_BOOTLOADER_ADDRESS = 0x7C00
+endif
+ifeq ($(BOOTSIZE), 1024)
+ MT_BOOTLOADER_ADDRESS = 0x7800
+endif
+ifeq ($(BOOTSIZE), 2048)
+ MT_BOOTLOADER_ADDRESS = 0x7000
+endif
+endif
+
+##
+ifeq ($(MCU), atmega64)
+BFD_MACH=avr5
+ifeq ($(BOOTSIZE), 512)
+ MT_BOOTLOADER_ADDRESS = 0xFC00
+endif
+ifeq ($(BOOTSIZE), 1024)
+ MT_BOOTLOADER_ADDRESS = 0xF800
+endif
+ifeq ($(BOOTSIZE), 2048)
+ MT_BOOTLOADER_ADDRESS = 0xF000
+endif
+ifeq ($(BOOTSIZE), 4096)
+ MT_BOOTLOADER_ADDRESS = 0xE000
+endif
+endif
+
+##
+ifeq ($(MCU), atmega644)
+BFD_MACH=avr5
+ifeq ($(BOOTSIZE), 512)
+ MT_BOOTLOADER_ADDRESS = 0xFC00
+endif
+ifeq ($(BOOTSIZE), 1024)
+ MT_BOOTLOADER_ADDRESS = 0xF800
+endif
+ifeq ($(BOOTSIZE), 2048)
+ MT_BOOTLOADER_ADDRESS = 0xF000
+endif
+ifeq ($(BOOTSIZE), 4096)
+ MT_BOOTLOADER_ADDRESS = 0xE000
+endif
+endif
+
+##
+ifeq ($(MCU), atmega644p)
+BFD_MACH=avr5
+ifeq ($(BOOTSIZE), 512)
+ MT_BOOTLOADER_ADDRESS = 0xFC00
+endif
+ifeq ($(BOOTSIZE), 1024)
+ MT_BOOTLOADER_ADDRESS = 0xF800
+endif
+ifeq ($(BOOTSIZE), 2048)
+ MT_BOOTLOADER_ADDRESS = 0xF000
+endif
+ifeq ($(BOOTSIZE), 4096)
+ MT_BOOTLOADER_ADDRESS = 0xE000
+endif
+endif
+
+##
+ifeq ($(MCU), atmega128)
+BFD_MACH=avr5
+ifeq ($(BOOTSIZE), 512)
+ MT_BOOTLOADER_ADDRESS = 0x1FC00
+endif
+ifeq ($(BOOTSIZE), 1024)
+ MT_BOOTLOADER_ADDRESS = 0x1F800
+endif
+ifeq ($(BOOTSIZE), 2048)
+ MT_BOOTLOADER_ADDRESS = 0x1F000
+endif
+ifeq ($(BOOTSIZE), 4096)
+ MT_BOOTLOADER_ADDRESS = 0x1E000
+endif
+endif
+
+##
+ifeq ($(MCU), at90can128)
+BFD_MACH=avr5
+ifeq ($(BOOTSIZE), 512)
+ MT_BOOTLOADER_ADDRESS = 0x1FC00
+endif
+ifeq ($(BOOTSIZE), 1024)
+ MT_BOOTLOADER_ADDRESS = 0x1F800
+endif
+ifeq ($(BOOTSIZE), 2048)
+ MT_BOOTLOADER_ADDRESS = 0x1F000
+endif
+ifeq ($(BOOTSIZE), 4096)
+ MT_BOOTLOADER_ADDRESS = 0x1E000
+endif
+endif
+
+
+# Output format. (can be srec, ihex, binary)
+FORMAT = ihex
+#FORMAT = srec
+
+# Target file name (without extension).
+TARGET = main
+
+
+# List C source files here. (C dependencies are automatically generated.)
+SRC = $(TARGET).c
+
+
+# List Assembler source files here.
+# Make them always end in a capital .S. Files ending in a lowercase .s
+# will not be considered source files but generated files (assembler
+# output from the compiler), and will be deleted upon "make clean"!
+# Even though the DOS/Win* filesystem matches both .s and .S the same,
+# it will preserve the spelling of the filenames, and gcc itself does
+# care about how the name is spelled on its command-line.
+ASRC =
+
+
+
+# Optimization level, can be [0, 1, 2, 3, s].
+# 0 = turn off optimization. s = optimize for size.
+# (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
+OPT = s
+
+# Debugging format.
+# Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
+# AVR (extended) COFF requires stabs, plus an avr-objcopy run.
+DEBUG = stabs
+
+# List any extra directories to look for include files here.
+# Each directory must be seperated by a space.
+EXTRAINCDIRS =
+
+
+# Compiler flag to set the C Standard level.
+# c89 - "ANSI" C
+# gnu89 - c89 plus GCC extensions
+# c99 - ISO C99 standard (not yet fully implemented)
+# gnu99 - c99 plus GCC extensions
+CSTANDARD = -std=gnu99
+
+# Place -D or -U options here
+CDEFS = -DBOOTSIZE=$(BOOTSIZE)
+
+# Place -I options here
+CINCS =
+
+
+# Compiler flags.
+# -g*: generate debugging information
+# -O*: optimization level
+# -f...: tuning, see GCC manual and avr-libc documentation
+# -Wall...: warning level
+# -Wa,...: tell GCC to pass this to the assembler.
+# -adhlns...: create assembler listing
+CFLAGS = -g$(DEBUG)
+CFLAGS += $(CDEFS) $(CINCS)
+CFLAGS += -O$(OPT)
+CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
+CFLAGS += -Wall -Wstrict-prototypes
+CFLAGS += -Wa,-adhlns=$(<:.c=.lst)
+CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
+CFLAGS += $(CSTANDARD)
+
+
+
+# Assembler flags.
+# -Wa,...: tell GCC to pass this to the assembler.
+# -ahlms: create listing
+# -gstabs: have the assembler create line number information; note that
+# for use in COFF files, additional information about filenames
+# and function names needs to be present in the assembler source
+# files -- see avr-libc docs [FIXME: not yet described there]
+ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
+
+
+
+#Additional libraries.
+
+# Minimalistic printf version
+PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
+
+# Floating point printf version (requires MATH_LIB = -lm below)
+PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
+
+PRINTF_LIB =
+
+# Minimalistic scanf version
+SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
+
+# Floating point + %[ scanf version (requires MATH_LIB = -lm below)
+SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
+
+SCANF_LIB =
+
+MATH_LIB = -lm
+
+# External memory options
+
+# 64 KB of external RAM, starting after internal RAM (ATmega128!),
+# used for variables (.data/.bss) and heap (malloc()).
+#EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
+
+# 64 KB of external RAM, starting after internal RAM (ATmega128!),
+# only used for heap (malloc()).
+#EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff
+
+EXTMEMOPTS =
+
+# Linker flags.
+# -Wl,...: tell GCC to pass this to linker.
+# -Map: create map file
+# --cref: add cross reference to map file
+LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
+LDFLAGS += $(EXTMEMOPTS)
+LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
+
+################## BOOTLOADER ######################
+# MT_BOOTLOADER_ADDRESS (=Start of Boot Loader section
+# in bytes - not words) as defined above.
+LDFLAGS += -Wl,--section-start=.text=$(MT_BOOTLOADER_ADDRESS)
+
+# check if linker-scripts without interrupt-vectors should
+# be used and set linker-option, announce to C-code by define
+ifeq ($(BOOTINTVEC), no)
+LDFLAGS += -T./ldscripts_no_vector/$(BFD_MACH).x
+CFLAGS += -DBOOTLOADERHASNOVECTORS
+endif
+
+
+# Programming support using avrdude. Settings and variables.
+
+# Programming hardware: alf avr910 avrisp bascom bsd
+# dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
+#
+# Type: avrdude -c ?
+# to get a full listing.
+#
+AVRDUDE_PROGRAMMER = stk500v2
+
+# com1 = serial port. Use lpt1 to connect to parallel port.
+AVRDUDE_PORT = com1 # programmer connected to serial device
+#AVRDUDE_PORT = /dev/ttyS0 # programmer connected to serial device
+
+AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
+#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
+
+
+# Uncomment the following if you want avrdude's erase cycle counter.
+# Note that this counter needs to be initialized first using -Yn,
+# see avrdude manual.
+#AVRDUDE_ERASE_COUNTER = -y
+
+# Uncomment the following if you do /not/ wish a verification to be
+# performed after programming the device.
+#AVRDUDE_NO_VERIFY = -V
+
+# Increase verbosity level. Please use this when submitting bug
+# reports about avrdude. See
+# to submit bug reports.
+#AVRDUDE_VERBOSE = -v -v
+
+AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
+AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
+AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
+AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
+
+
+
+# ---------------------------------------------------------------------------
+
+# Define directories, if needed.
+DIRAVR = c:/Hard/WinAVR-20100110
+DIRAVRBIN = $(DIRAVR)/bin
+DIRAVRUTILS = $(DIRAVR)/utils/bin
+DIRINC = .
+DIRLIB = $(DIRAVR)/avr/lib
+
+
+# Define programs and commands.
+#SHELL = $(DIRAVRUTILS)/sh
+#NM = $(DIRAVRBIN)/avr-nm
+#CC = $(DIRAVRBIN)/avr-gcc
+#OBJCOPY = $(DIRAVRBIN)/avr-objcopy
+#OBJDUMP= $(DIRAVRBIN)/avr-objdump
+#SIZE = $(DIRAVRBIN)/avr-size
+#AVRDUDE = $(DIRAVRBIN)/avrdude.sh
+#REMOVE = rm -f
+#COPY = cp
+
+# Define programs and commands.
+SHELL = sh
+CC = avr-gcc
+OBJCOPY = avr-objcopy
+OBJDUMP = avr-objdump
+SIZE = avr-size
+NM = avr-nm
+AVRDUDE = avrdude
+REMOVE = rm -f
+COPY = cp
+WINSHELL = cmd
+
+
+# Define Messages
+# English
+MSG_ERRORS_NONE = Errors: none
+MSG_BEGIN = -------- begin --------
+MSG_END = -------- end --------
+MSG_SIZE_BEFORE = Size before:
+MSG_SIZE_AFTER = Size after:
+MSG_COFF = Converting to AVR COFF:
+MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
+MSG_FLASH = Creating load file for Flash:
+MSG_EEPROM = Creating load file for EEPROM:
+MSG_EXTENDED_LISTING = Creating Extended Listing:
+MSG_SYMBOL_TABLE = Creating Symbol Table:
+MSG_LINKING = Linking:
+MSG_COMPILING = Compiling:
+MSG_ASSEMBLING = Assembling:
+MSG_CLEANING = Cleaning project:
+
+
+
+
+# Define all object files.
+OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)
+
+# Define all listing files.
+LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)
+
+
+# Compiler flags to generate dependency files.
+### GENDEPFLAGS = -Wp,-M,-MP,-MT,$(*F).o,-MF,.dep/$(@F).d
+GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d
+
+# Combine all necessary flags and optional flags.
+# Add target processor to flags.
+ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
+ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
+
+
+
+
+
+# Default target.
+all: begin gccversion sizebefore build sizeafter finished end
+
+build: elf hex eep lss sym
+
+elf: $(TARGET).elf
+hex: $(TARGET).hex
+eep: $(TARGET).eep
+lss: $(TARGET).lss
+sym: $(TARGET).sym
+
+
+
+# Eye candy.
+# AVR Studio 3.x does not check make's exit code but relies on
+# the following magic strings to be generated by the compile job.
+begin:
+ @echo
+ @echo $(MSG_BEGIN)
+
+finished:
+ @echo $(MSG_ERRORS_NONE)
+
+end:
+ @echo $(MSG_END)
+ @echo
+
+
+# Display size of file.
+HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
+ELFSIZE = $(SIZE) -x -A $(TARGET).elf
+sizebefore:
+ @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi
+
+sizeafter:
+ @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
+
+
+
+# Display compiler version information.
+gccversion :
+ @$(CC) --version
+
+
+
+# Program the device.
+program: $(TARGET).hex $(TARGET).eep
+ $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
+
+
+
+
+# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
+COFFCONVERT=$(OBJCOPY) --debugging \
+--change-section-address .data-0x800000 \
+--change-section-address .bss-0x800000 \
+--change-section-address .noinit-0x800000 \
+--change-section-address .eeprom-0x810000
+
+
+coff: $(TARGET).elf
+ @echo
+ @echo $(MSG_COFF) $(TARGET).cof
+ $(COFFCONVERT) -O coff-avr $< $(TARGET).cof
+
+
+extcoff: $(TARGET).elf
+ @echo
+ @echo $(MSG_EXTENDED_COFF) $(TARGET).cof
+ $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
+
+
+
+# Create final output files (.hex, .eep) from ELF output file.
+%.hex: %.elf
+ @echo
+ @echo $(MSG_FLASH) $@
+ $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
+
+%.eep: %.elf
+ @echo
+ @echo $(MSG_EEPROM) $@
+ -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
+ --change-section-lma .eeprom=0 -O $(FORMAT) $< $@
+
+# Create extended listing file from ELF output file.
+%.lss: %.elf
+ @echo
+ @echo $(MSG_EXTENDED_LISTING) $@
+ $(OBJDUMP) -h -S $< > $@
+
+# Create a symbol table from ELF output file.
+%.sym: %.elf
+ @echo
+ @echo $(MSG_SYMBOL_TABLE) $@
+ $(NM) -n $< > $@
+
+
+
+# Link: create ELF output file from object files.
+.SECONDARY : $(TARGET).elf
+.PRECIOUS : $(OBJ)
+%.elf: $(OBJ)
+ @echo
+ @echo $(MSG_LINKING) $@
+ $(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)
+
+
+# Compile: create object files from C source files.
+%.o : %.c
+ @echo
+ @echo $(MSG_COMPILING) $<
+ $(CC) -c $(ALL_CFLAGS) $< -o $@
+
+
+# Compile: create assembler files from C source files.
+%.s : %.c
+ $(CC) -S $(ALL_CFLAGS) $< -o $@
+
+
+# Assemble: create object files from assembler source files.
+%.o : %.S
+ @echo
+ @echo $(MSG_ASSEMBLING) $<
+ $(CC) -c $(ALL_ASFLAGS) $< -o $@
+
+
+
+# Target: clean project.
+clean: begin clean_list finished end
+
+clean_list :
+ @echo
+ @echo $(MSG_CLEANING)
+ $(REMOVE) $(TARGET).hex
+ $(REMOVE) $(TARGET).eep
+ $(REMOVE) $(TARGET).obj
+ $(REMOVE) $(TARGET).cof
+ $(REMOVE) $(TARGET).elf
+ $(REMOVE) $(TARGET).map
+ $(REMOVE) $(TARGET).obj
+ $(REMOVE) $(TARGET).a90
+ $(REMOVE) $(TARGET).sym
+ $(REMOVE) $(TARGET).lnk
+ $(REMOVE) $(TARGET).lss
+ $(REMOVE) $(OBJ)
+ $(REMOVE) $(LST)
+ $(REMOVE) $(SRC:.c=.s)
+ $(REMOVE) $(SRC:.c=.d)
+ $(REMOVE) .dep/*
+
+
+
+# Include the dependency files.
+-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
+
+
+# Listing of phony targets.
+.PHONY : all begin finish end sizebefore sizeafter gccversion \
+build elf hex eep lss sym coff extcoff \
+clean clean_list program
+
diff --git a/boot/mega128.h b/boot/mega128.h
new file mode 100755
index 0000000..a8f148c
--- /dev/null
+++ b/boot/mega128.h
@@ -0,0 +1,39 @@
+#ifndef _MEGA128_H_
+#define _MEGA128_H_
+
+/* Part-Code ISP */
+#define DEVTYPE_ISP 0x43
+/* Part-Code Boot */
+#define DEVTYPE_BOOT 0x44
+
+#define SIG_BYTE1 0x1E
+#define SIG_BYTE2 0x97
+#define SIG_BYTE3 0x02
+
+#ifndef UART_USE_SECOND
+#define UART_BAUD_HIGH UBRR0H
+#define UART_BAUD_LOW UBRR0L
+#define UART_STATUS UCSR0A
+#define UART_TXREADY UDRE0
+#define UART_RXREADY RXC0
+#define UART_DOUBLE U2X0
+#define UART_CTRL UCSR0B
+#define UART_CTRL_DATA ((1<"ATmega32" and boot-code is 0x73->"ATmega32 BOOT".
+ When using avrdude the bootloader's device-code must match
+ the device-code in the avrdude.conf. Check the avrdude-
+ code to see if both codes (AVR910 and AVR109) are supported.
+ -- I have got some e-mails from users which have been
+ confused by this. Hopefully this explanation is good enough.
+* This bootloader lets the watchdog do a reset when the
+ user selects "Exit programmer" (i.e. in AVRProg) after an
+ update. Make sure to disable or reset the watchdog early in
+ your application.
+
+27. May 2006 - Version 0.8beta2
+
+* More very well done improvements contributed by Olaf Rempel.
+* Olaf Rempel also modified the STARTUP_WAIT method.
+
+21. May 2006 - Version 0.8beta
+
+* Version contributed by Olaf Rempel. He has done a lot of modifications.
+ -> "cleaner code", smaller binaries.
+
+09. Feb. 2006 - Version 0.75
+
+* additional STARTUP_WAIT support contributed by Bjoern Riemer
+
+18. Aug. 2005 - Version 0.74
+
+* AT90CAN128 support contributed by Uwe Bonnes
+* Makefile modifications contributed by Uwe Bonnes
+
+23. Feb. 2005 - Version 0.7
+
+* (Version 0.6 has never been available on the web-page)
+* ATmega128 support
+* code cleanup
+* This version has been tested with ATmega8, ATmega32 and
+ ATmega128
+
+7. Apr. 2004 - Version 0.5
+
+* added different startup-methods
+* compatible with ATmega8 now
+* included makefile adapted to ATmega8 now
+ (ATmega16 options still available)
+* fixed jump to application which did not work
+ reliably before
+* tested with ATmega8
+* minimal options and startup-code result in
+ bootloader-size < 512 words
+
+6. Apr. 2004 - Version 0.4
+
+* Buffered read of chars from UART during programming
+since eeprom-write is too slow for unbuffered
+operation. So EEPROM-upload does work now.
+* Added BOOTICE-mode to flash JTAGICE-compatible
+hardware (ATmega16@7,3Mhz) (if you know about BOOTICE,
+you may unterstand why this has been added, if not
+just keep the option disabled)
+* small changes in (my)boot.h (lock-bit-mask) found
+out during the development of the STK-500-compatible
+bootloader. But setting lock-bits still does not
+work with this bootloader.
+* read of the low-fuse byte works (high byte still TODO)
+* read of the lock-byte works (write still TODO)
+
+27. Mar 2004 - Version 0.3
+
+Felt that as much functions from avr-libc's boot.h
+as possible should be used without modifications.
+Latest CVS-version of boot.h is included.
+Only the read-routine is still "self-made" based
+on ATMELs assembler-code.
+EEPROM write on Mega16 does not work (and did not
+work with V0.2 too). May be caused by my old Mega16
+chip. Needs testing. Flash read/write and EEPROM
+read works. Still only tested with ATmega16.
+This version may not work with the ATmega169 any
+more.
+
+24. Mar 2004 - Version 0.2
+
+During the development of a data-logger application
+with the AVR-Butterfly there was a need to make
+some changes in the bootloader. The same problem
+again: no IAR compiler. The same way to solve the
+problem: a port of the code to avr-gcc/avr-libc.
+So this code is based on the ATMEL Butterfly
+bootloader source code Rev 0.2 for IAR.
+
+The bootloader-port for the Butterfly which mimics
+the complete functionality of the original
+BF-bootloader is availabe at:
+www.siwawi.arubi.uni-kl.de/avr_projects
+
+Atmel used a separate "lib" written in "pure"
+assembly to access the low-level functions
+for flash read/write. Well, so far I
+don't know how to use "mixed language sources"
+with the avr-gcc toolchain, so the low-level
+routines have been implemented as inline assembler.
+The avr-libc boot.h module written by Eric
+Weddington served as a template Three of the four
+low-level routines found in lowlevel.c come from
+boot.h with minimal changes. The read routine has
+been developed based on the ATMEL assembler code.
+
+Ignore the fuse and lock-bit readout. Read and Set is
+not enabled (TODO).
+
+
+--------------- Installation -----------------
+
+- Change the MCU type in the makefile.
+
+- Change the boot(loader)-size in Makefile. The needed
+ space depends on the features selected in main.c
+
+- Set baudrate in main.c, a doublespeed configuration-option
+ is available too.
+
+- Change the F_CPU in main.c to the clock-frequency
+ of your board. See the datasheet for frequencies
+ with minimum error at the selected baudrate.
+
+- Select the start-condition in main.c.
+
+- Please use at least avr-gcc 3.3.1/avr-libc 1.0
+ or WINAVR Sept. 2003 or later to compile and link
+ this bootloader.
+
+- Upload the hex-File to the AVR (STK500, STK200, SP12
+ evertool, AVR910 etc.)
+
+- Program the "Boot Flash section size" (BOOTSZ fuses)
+ according to the boot-size selected in the makefile
+ i.e. BOOTSZ=00 for boot-size 1024 words (2048 bytes)
+ on ATmega16
+
+- enable the BOOT Reset Vector fuse (BOOTRST=0)
+
+- Set the lock bits to protect the bootloader from
+ SPM-writes (Boot Loader Protection Mode 2 in STK500-
+ plugin) so that it can not overwrite itself.
+
+- Connect the AVR UART Pins via level-shifter/inverter
+ (i.e. MAX232) to your PCs COM-Port.
+
+- Reset the AVR while fullfilling the bootloader start-
+ condition. (Default: selected pin connected to GND).
+ The condition must be "true" until you see the
+ AVRPROG dialog or avrdude connects.
+
+- Start AVRPROG (AVRStudio/Tools or stand-alone avrprog.exe)
+ AVRDUDE is supported too, check it's manual
+ for command-line options. Read the text above for
+ information about Device-Types and AVRDUDE
+
+- AVRPROG or AVRDUDE should detect the bootloader.
+
+- see AVRStudio's online-help for more information how
+ to use AVRPROG
+
+- make sure to EXIT from AVRPROG (button) to start
+ your main-application or toogle power/reset.
+
+
+Feedback welcome, Good luck.
+Martin
diff --git a/boot/testapp/Makefile b/boot/testapp/Makefile
new file mode 100755
index 0000000..e892207
--- /dev/null
+++ b/boot/testapp/Makefile
@@ -0,0 +1,619 @@
+# Hey Emacs, this is a -*- makefile -*-
+#----------------------------------------------------------------------------
+# WinAVR Makefile Template written by Eric B. Weddington, Jцrg Wunsch, et al.
+#
+# Released to the Public Domain
+#
+# Additional material for this makefile was written by:
+# Peter Fleury
+# Tim Henigan
+# Colin O'Flynn
+# Reiner Patommel
+# Markus Pfaff
+# Sander Pool
+# Frederik Rouleau
+# Carlos Lamas
+#
+#----------------------------------------------------------------------------
+# On command line:
+#
+# make all = Make software.
+#
+# make clean = Clean out built project files.
+#
+# make coff = Convert ELF to AVR COFF.
+#
+# make extcoff = Convert ELF to AVR Extended COFF.
+#
+# make program = Download the hex file to the device, using avrdude.
+# Please customize the avrdude settings below first!
+#
+# make debug = Start either simulavr or avarice as specified for debugging,
+# with avr-gdb or avr-insight as the front end for debugging.
+#
+# make filename.s = Just compile filename.c into the assembler code only.
+#
+# make filename.i = Create a preprocessed source file for use in submitting
+# bug reports to the GCC project.
+#
+# To rebuild project do "make clean" then "make all".
+#----------------------------------------------------------------------------
+
+
+# MCU name
+MCU = atmega324p
+
+
+# Processor frequency.
+# This will define a symbol, F_CPU, in all source code files equal to the
+# processor frequency. You can then use this symbol in your source code to
+# calculate timings. Do NOT tack on a 'UL' at the end, this will be done
+# automatically to create a 32-bit value in your source code.
+# Typical values are:
+# F_CPU = 1000000
+# F_CPU = 1843200
+# F_CPU = 2000000
+# F_CPU = 3686400
+# F_CPU = 4000000
+# F_CPU = 7372800
+# F_CPU = 8000000
+# F_CPU = 11059200
+# F_CPU = 14745600
+# F_CPU = 16000000
+# F_CPU = 18432000
+# F_CPU = 20000000
+F_CPU = 3686400
+
+
+# Output format. (can be srec, ihex, binary)
+FORMAT = ihex
+
+
+# Target file name (without extension).
+TARGET = testapp
+
+
+# Object files directory
+# To put object files in current directory, use a dot (.), do NOT make
+# this an empty or blank macro!
+OBJDIR = .
+
+
+# List C source files here. (C dependencies are automatically generated.)
+SRC = $(TARGET).c
+
+
+# List C++ source files here. (C dependencies are automatically generated.)
+CPPSRC =
+
+
+# List Assembler source files here.
+# Make them always end in a capital .S. Files ending in a lowercase .s
+# will not be considered source files but generated files (assembler
+# output from the compiler), and will be deleted upon "make clean"!
+# Even though the DOS/Win* filesystem matches both .s and .S the same,
+# it will preserve the spelling of the filenames, and gcc itself does
+# care about how the name is spelled on its command-line.
+ASRC =
+
+
+# Optimization level, can be [0, 1, 2, 3, s].
+# 0 = turn off optimization. s = optimize for size.
+# (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
+OPT = s
+
+
+# Debugging format.
+# Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
+# AVR Studio 4.10 requires dwarf-2.
+# AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
+DEBUG = dwarf-2
+
+
+# List any extra directories to look for include files here.
+# Each directory must be seperated by a space.
+# Use forward slashes for directory separators.
+# For a directory that has spaces, enclose it in quotes.
+EXTRAINCDIRS =
+
+
+# Compiler flag to set the C Standard level.
+# c89 = "ANSI" C
+# gnu89 = c89 plus GCC extensions
+# c99 = ISO C99 standard (not yet fully implemented)
+# gnu99 = c99 plus GCC extensions
+CSTANDARD = -std=gnu99
+
+
+# Place -D or -U options here for C sources
+CDEFS = -DF_CPU=$(F_CPU)UL
+
+
+# Place -D or -U options here for ASM sources
+ADEFS = -DF_CPU=$(F_CPU)
+
+
+# Place -D or -U options here for C++ sources
+CPPDEFS = -DF_CPU=$(F_CPU)UL
+#CPPDEFS += -D__STDC_LIMIT_MACROS
+#CPPDEFS += -D__STDC_CONSTANT_MACROS
+
+
+
+#---------------- Compiler Options C ----------------
+# -g*: generate debugging information
+# -O*: optimization level
+# -f...: tuning, see GCC manual and avr-libc documentation
+# -Wall...: warning level
+# -Wa,...: tell GCC to pass this to the assembler.
+# -adhlns...: create assembler listing
+CFLAGS = -g$(DEBUG)
+CFLAGS += $(CDEFS)
+CFLAGS += -O$(OPT)
+CFLAGS += -funsigned-char
+CFLAGS += -funsigned-bitfields
+CFLAGS += -fpack-struct
+CFLAGS += -fshort-enums
+CFLAGS += -Wall
+CFLAGS += -Wstrict-prototypes
+#CFLAGS += -mshort-calls
+#CFLAGS += -fno-unit-at-a-time
+#CFLAGS += -Wundef
+#CFLAGS += -Wunreachable-code
+#CFLAGS += -Wsign-compare
+CFLAGS += -Wa,-adhlns=$(<:%.c=$(OBJDIR)/%.lst)
+CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
+CFLAGS += $(CSTANDARD)
+
+
+#---------------- Compiler Options C++ ----------------
+# -g*: generate debugging information
+# -O*: optimization level
+# -f...: tuning, see GCC manual and avr-libc documentation
+# -Wall...: warning level
+# -Wa,...: tell GCC to pass this to the assembler.
+# -adhlns...: create assembler listing
+CPPFLAGS = -g$(DEBUG)
+CPPFLAGS += $(CPPDEFS)
+CPPFLAGS += -O$(OPT)
+CPPFLAGS += -funsigned-char
+CPPFLAGS += -funsigned-bitfields
+CPPFLAGS += -fpack-struct
+CPPFLAGS += -fshort-enums
+CPPFLAGS += -fno-exceptions
+CPPFLAGS += -Wall
+CFLAGS += -Wundef
+#CPPFLAGS += -mshort-calls
+#CPPFLAGS += -fno-unit-at-a-time
+#CPPFLAGS += -Wstrict-prototypes
+#CPPFLAGS += -Wunreachable-code
+#CPPFLAGS += -Wsign-compare
+CPPFLAGS += -Wa,-adhlns=$(<:%.cpp=$(OBJDIR)/%.lst)
+CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
+#CPPFLAGS += $(CSTANDARD)
+
+
+#---------------- Assembler Options ----------------
+# -Wa,...: tell GCC to pass this to the assembler.
+# -adhlns: create listing
+# -gstabs: have the assembler create line number information; note that
+# for use in COFF files, additional information about filenames
+# and function names needs to be present in the assembler source
+# files -- see avr-libc docs [FIXME: not yet described there]
+# -listing-cont-lines: Sets the maximum number of continuation lines of hex
+# dump that will be displayed for a given single line of source input.
+ASFLAGS = $(ADEFS) -Wa,-adhlns=$(<:%.S=$(OBJDIR)/%.lst),-gstabs,--listing-cont-lines=100
+
+
+#---------------- Library Options ----------------
+# Minimalistic printf version
+PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
+
+# Floating point printf version (requires MATH_LIB = -lm below)
+PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
+
+# If this is left blank, then it will use the Standard printf version.
+PRINTF_LIB =
+#PRINTF_LIB = $(PRINTF_LIB_MIN)
+#PRINTF_LIB = $(PRINTF_LIB_FLOAT)
+
+
+# Minimalistic scanf version
+SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
+
+# Floating point + %[ scanf version (requires MATH_LIB = -lm below)
+SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
+
+# If this is left blank, then it will use the Standard scanf version.
+SCANF_LIB =
+#SCANF_LIB = $(SCANF_LIB_MIN)
+#SCANF_LIB = $(SCANF_LIB_FLOAT)
+
+
+MATH_LIB = -lm
+
+
+# List any extra directories to look for libraries here.
+# Each directory must be seperated by a space.
+# Use forward slashes for directory separators.
+# For a directory that has spaces, enclose it in quotes.
+EXTRALIBDIRS =
+
+
+
+#---------------- External Memory Options ----------------
+
+# 64 KB of external RAM, starting after internal RAM (ATmega128!),
+# used for variables (.data/.bss) and heap (malloc()).
+#EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
+
+# 64 KB of external RAM, starting after internal RAM (ATmega128!),
+# only used for heap (malloc()).
+#EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff
+
+EXTMEMOPTS =
+
+
+
+#---------------- Linker Options ----------------
+# -Wl,...: tell GCC to pass this to linker.
+# -Map: create map file
+# --cref: add cross reference to map file
+LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
+LDFLAGS += $(EXTMEMOPTS)
+LDFLAGS += $(patsubst %,-L%,$(EXTRALIBDIRS))
+LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
+#LDFLAGS += -T linker_script.x
+
+
+
+#---------------- Programming Options (avrdude) ----------------
+
+# Programming hardware: alf avr910 avrisp bascom bsd
+# dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
+#
+# Type: avrdude -c ?
+# to get a full listing.
+#
+AVRDUDE_PROGRAMMER = stk500
+
+# com1 = serial port. Use lpt1 to connect to parallel port.
+AVRDUDE_PORT = com1 # programmer connected to serial device
+
+AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
+#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
+
+
+# Uncomment the following if you want avrdude's erase cycle counter.
+# Note that this counter needs to be initialized first using -Yn,
+# see avrdude manual.
+#AVRDUDE_ERASE_COUNTER = -y
+
+# Uncomment the following if you do /not/ wish a verification to be
+# performed after programming the device.
+#AVRDUDE_NO_VERIFY = -V
+
+# Increase verbosity level. Please use this when submitting bug
+# reports about avrdude. See
+# to submit bug reports.
+#AVRDUDE_VERBOSE = -v -v
+
+AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
+AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
+AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
+AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
+
+
+
+#---------------- Debugging Options ----------------
+
+# For simulavr only - target MCU frequency.
+DEBUG_MFREQ = $(F_CPU)
+
+# Set the DEBUG_UI to either gdb or insight.
+# DEBUG_UI = gdb
+DEBUG_UI = insight
+
+# Set the debugging back-end to either avarice, simulavr.
+DEBUG_BACKEND = avarice
+#DEBUG_BACKEND = simulavr
+
+# GDB Init Filename.
+GDBINIT_FILE = __avr_gdbinit
+
+# When using avarice settings for the JTAG
+JTAG_DEV = /dev/com1
+
+# Debugging port used to communicate between GDB / avarice / simulavr.
+DEBUG_PORT = 4242
+
+# Debugging host used to communicate between GDB / avarice / simulavr, normally
+# just set to localhost unless doing some sort of crazy debugging when
+# avarice is running on a different computer.
+DEBUG_HOST = localhost
+
+
+
+#============================================================================
+
+
+# Define programs and commands.
+SHELL = sh
+CC = avr-gcc
+OBJCOPY = avr-objcopy
+OBJDUMP = avr-objdump
+SIZE = avr-size
+AR = avr-ar rcs
+NM = avr-nm
+AVRDUDE = avrdude
+REMOVE = rm -f
+REMOVEDIR = rm -rf
+COPY = cp
+WINSHELL = cmd
+
+
+# Define Messages
+# English
+MSG_ERRORS_NONE = Errors: none
+MSG_BEGIN = -------- begin --------
+MSG_END = -------- end --------
+MSG_SIZE_BEFORE = Size before:
+MSG_SIZE_AFTER = Size after:
+MSG_COFF = Converting to AVR COFF:
+MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
+MSG_FLASH = Creating load file for Flash:
+MSG_EEPROM = Creating load file for EEPROM:
+MSG_EXTENDED_LISTING = Creating Extended Listing:
+MSG_SYMBOL_TABLE = Creating Symbol Table:
+MSG_LINKING = Linking:
+MSG_COMPILING = Compiling C:
+MSG_COMPILING_CPP = Compiling C++:
+MSG_ASSEMBLING = Assembling:
+MSG_CLEANING = Cleaning project:
+MSG_CREATING_LIBRARY = Creating library:
+
+
+
+
+# Define all object files.
+OBJ = $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o)
+
+# Define all listing files.
+LST = $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst)
+
+
+# Compiler flags to generate dependency files.
+GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d
+
+
+# Combine all necessary flags and optional flags.
+# Add target processor to flags.
+ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
+ALL_CPPFLAGS = -mmcu=$(MCU) -I. -x c++ $(CPPFLAGS) $(GENDEPFLAGS)
+ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
+
+
+
+
+
+# Default target.
+all: begin gccversion sizebefore build sizeafter end
+
+# Change the build target to build a HEX file or a library.
+build: elf hex eep lss sym
+#build: lib
+
+
+elf: $(TARGET).elf
+hex: $(TARGET).hex
+eep: $(TARGET).eep
+lss: $(TARGET).lss
+sym: $(TARGET).sym
+LIBNAME=lib$(TARGET).a
+lib: $(LIBNAME)
+
+
+
+# Eye candy.
+# AVR Studio 3.x does not check make's exit code but relies on
+# the following magic strings to be generated by the compile job.
+begin:
+ @echo
+ @echo $(MSG_BEGIN)
+
+end:
+ @echo $(MSG_END)
+ @echo
+
+
+# Display size of file.
+HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
+ELFSIZE = $(SIZE) --mcu=$(MCU) --format=avr $(TARGET).elf
+
+sizebefore:
+ @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
+ 2>/dev/null; echo; fi
+
+sizeafter:
+ @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
+ 2>/dev/null; echo; fi
+
+
+
+# Display compiler version information.
+gccversion :
+ @$(CC) --version
+
+
+
+# Program the device.
+program: $(TARGET).hex $(TARGET).eep
+ $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
+
+
+# Generate avr-gdb config/init file which does the following:
+# define the reset signal, load the target file, connect to target, and set
+# a breakpoint at main().
+gdb-config:
+ @$(REMOVE) $(GDBINIT_FILE)
+ @echo define reset >> $(GDBINIT_FILE)
+ @echo SIGNAL SIGHUP >> $(GDBINIT_FILE)
+ @echo end >> $(GDBINIT_FILE)
+ @echo file $(TARGET).elf >> $(GDBINIT_FILE)
+ @echo target remote $(DEBUG_HOST):$(DEBUG_PORT) >> $(GDBINIT_FILE)
+ifeq ($(DEBUG_BACKEND),simulavr)
+ @echo load >> $(GDBINIT_FILE)
+endif
+ @echo break main >> $(GDBINIT_FILE)
+
+debug: gdb-config $(TARGET).elf
+ifeq ($(DEBUG_BACKEND), avarice)
+ @echo Starting AVaRICE - Press enter when "waiting to connect" message displays.
+ @$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \
+ $(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)
+ @$(WINSHELL) /c pause
+
+else
+ @$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
+ $(DEBUG_MFREQ) --port $(DEBUG_PORT)
+endif
+ @$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)
+
+
+
+
+# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
+COFFCONVERT = $(OBJCOPY) --debugging
+COFFCONVERT += --change-section-address .data-0x800000
+COFFCONVERT += --change-section-address .bss-0x800000
+COFFCONVERT += --change-section-address .noinit-0x800000
+COFFCONVERT += --change-section-address .eeprom-0x810000
+
+
+
+coff: $(TARGET).elf
+ @echo
+ @echo $(MSG_COFF) $(TARGET).cof
+ $(COFFCONVERT) -O coff-avr $< $(TARGET).cof
+
+
+extcoff: $(TARGET).elf
+ @echo
+ @echo $(MSG_EXTENDED_COFF) $(TARGET).cof
+ $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
+
+
+
+# Create final output files (.hex, .eep) from ELF output file.
+%.hex: %.elf
+ @echo
+ @echo $(MSG_FLASH) $@
+ $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
+
+%.eep: %.elf
+ @echo
+ @echo $(MSG_EEPROM) $@
+ -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
+ --change-section-lma .eeprom=0 --no-change-warnings -O $(FORMAT) $< $@ || exit 0
+
+# Create extended listing file from ELF output file.
+%.lss: %.elf
+ @echo
+ @echo $(MSG_EXTENDED_LISTING) $@
+ $(OBJDUMP) -h -S $< > $@
+
+# Create a symbol table from ELF output file.
+%.sym: %.elf
+ @echo
+ @echo $(MSG_SYMBOL_TABLE) $@
+ $(NM) -n $< > $@
+
+
+
+# Create library from object files.
+.SECONDARY : $(TARGET).a
+.PRECIOUS : $(OBJ)
+%.a: $(OBJ)
+ @echo
+ @echo $(MSG_CREATING_LIBRARY) $@
+ $(AR) $@ $(OBJ)
+
+
+# Link: create ELF output file from object files.
+.SECONDARY : $(TARGET).elf
+.PRECIOUS : $(OBJ)
+%.elf: $(OBJ)
+ @echo
+ @echo $(MSG_LINKING) $@
+ $(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
+
+
+# Compile: create object files from C source files.
+$(OBJDIR)/%.o : %.c
+ @echo
+ @echo $(MSG_COMPILING) $<
+ $(CC) -c $(ALL_CFLAGS) $< -o $@
+
+
+# Compile: create object files from C++ source files.
+$(OBJDIR)/%.o : %.cpp
+ @echo
+ @echo $(MSG_COMPILING_CPP) $<
+ $(CC) -c $(ALL_CPPFLAGS) $< -o $@
+
+
+# Compile: create assembler files from C source files.
+%.s : %.c
+ $(CC) -S $(ALL_CFLAGS) $< -o $@
+
+
+# Compile: create assembler files from C++ source files.
+%.s : %.cpp
+ $(CC) -S $(ALL_CPPFLAGS) $< -o $@
+
+
+# Assemble: create object files from assembler source files.
+$(OBJDIR)/%.o : %.S
+ @echo
+ @echo $(MSG_ASSEMBLING) $<
+ $(CC) -c $(ALL_ASFLAGS) $< -o $@
+
+
+# Create preprocessed source for use in sending a bug report.
+%.i : %.c
+ $(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@
+
+
+# Target: clean project.
+clean: begin clean_list end
+
+clean_list :
+ @echo
+ @echo $(MSG_CLEANING)
+ $(REMOVE) $(TARGET).hex
+ $(REMOVE) $(TARGET).eep
+ $(REMOVE) $(TARGET).cof
+ $(REMOVE) $(TARGET).elf
+ $(REMOVE) $(TARGET).map
+ $(REMOVE) $(TARGET).sym
+ $(REMOVE) $(TARGET).lss
+ $(REMOVE) $(SRC:%.c=$(OBJDIR)/%.o)
+ $(REMOVE) $(SRC:%.c=$(OBJDIR)/%.lst)
+ $(REMOVE) $(SRC:.c=.s)
+ $(REMOVE) $(SRC:.c=.d)
+ $(REMOVE) $(SRC:.c=.i)
+ $(REMOVEDIR) .dep
+
+
+# Create object files directory
+$(shell mkdir $(OBJDIR) 2>/dev/null)
+
+
+# Include the dependency files.
+-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
+
+
+# Listing of phony targets.
+.PHONY : all begin finish end sizebefore sizeafter gccversion \
+build elf hex eep lss sym coff extcoff \
+clean clean_list program debug gdb-config
diff --git a/boot/testapp/testapp.c b/boot/testapp/testapp.c
new file mode 100755
index 0000000..8e03edc
--- /dev/null
+++ b/boot/testapp/testapp.c
@@ -0,0 +1,62 @@
+// Martin Thomas 4/2008
+
+#include
+#include
+#include
+#include
+
+#define LED_PORT PORTB
+#define LED_DDR DDRB
+#define LED_BIT PB2
+
+#define BT_PORT PORTC
+#define BT_DDR DDRC
+#define BT_PIN PINC
+#define BT_BIT PC7
+
+static inline void my_wdt_off(void)
+{
+ cli();
+ wdt_reset();
+ /* Clear WDRF in MCUSR */
+ MCUSR &= ~(1<