adjust root folder
This commit is contained in:
@@ -0,0 +1,245 @@
|
||||
# Hey Emacs, this is a -*- makefile -*-
|
||||
|
||||
# AVR-GCC Makefile template, derived from the WinAVR template (which
|
||||
# is public domain), believed to be neutral to any flavor of "make"
|
||||
# (GNU make, BSD make, SysV make)
|
||||
|
||||
|
||||
MCU = atmega644p
|
||||
FORMAT = ihex
|
||||
TARGET = bootloader
|
||||
SRC = main.c serial.c
|
||||
ASRC =
|
||||
OPT = s
|
||||
BASEADDR = 0xF800
|
||||
|
||||
# Name of this Makefile (used for "make depend").
|
||||
MAKEFILE = Makefile
|
||||
|
||||
# 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
|
||||
|
||||
# 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 =
|
||||
#CDEFS += -DREMOVE_FLASH_BYTE_SUPPORT
|
||||
#CDEFS += -DREMOVE_EEPROM_BYTE_SUPPORT
|
||||
#CDEFS += -DREMOVE_FUSE_AND_LOCK_BIT_SUPPORT
|
||||
#CDEFS += -DREMOVE_AVRPROG_SUPPORT
|
||||
#CDEFS += -DREMOVE_BLOCK_SUPPORT
|
||||
|
||||
# Place -I options here
|
||||
CINCS =
|
||||
|
||||
|
||||
CDEBUG = -g$(DEBUG)
|
||||
CWARN = -Wall -Wstrict-prototypes
|
||||
CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
|
||||
#CEXTRA = -Wa,-adhlns=$(<:.c=.lst)
|
||||
CFLAGS = $(CDEBUG) $(CDEFS) $(CINCS) -O$(OPT) $(CWARN) $(CSTANDARD) $(CTUNING) $(CEXTRA)
|
||||
|
||||
|
||||
#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 =
|
||||
|
||||
#LDMAP = $(LDFLAGS) -Wl,-Map=$(TARGET).map,--cref
|
||||
LDFLAGS = -Ttext=$(BASEADDR) $(EXTMEMOPTS) $(LDMAP) $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
|
||||
|
||||
|
||||
# Programming support using avrdude. Settings and variables.
|
||||
# jtag2fast = Atmel JTAG ICE mkII, running at 115200 Bd
|
||||
# jtag2slow = Atmel JTAG ICE mkII, running at 19200 Bd
|
||||
# avrispmkII = AVR ISP MKII
|
||||
#AVRDUDE_PROGRAMMER = jtag2fast
|
||||
AVRDUDE_PROGRAMMER = avrispmkII
|
||||
#AVRDUDE_PROGRAMMER = dragon_isp
|
||||
#AVRDUDE_PROGRAMMER = dragon_jtag
|
||||
#
|
||||
# # port--serial or parallel port to which your
|
||||
# # hardware programmer is attached
|
||||
# # usb can just be usb
|
||||
# # /dev/ttya
|
||||
AVRDUDE_PORT = usb
|
||||
|
||||
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 <http://savannah.nongnu.org/projects/avrdude>
|
||||
# to submit bug reports.
|
||||
#AVRDUDE_VERBOSE = -v -v
|
||||
|
||||
# Disable auto-erase so that the chip can be initially
|
||||
# programmed with application code, with the bootloader code added second
|
||||
AVRDUDE_AUTOERASE = -D
|
||||
|
||||
AVRDUDE_BASIC = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
|
||||
AVRDUDE_FLAGS = $(AVRDUDE_BASIC)
|
||||
AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
|
||||
AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
|
||||
AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
|
||||
AVRDUDE_FLAGS += $(AVRDUDE_AUTOERASE)
|
||||
|
||||
CC = avr-gcc
|
||||
OBJCOPY = avr-objcopy
|
||||
OBJDUMP = avr-objdump
|
||||
SIZE = avr-size
|
||||
NM = avr-nm
|
||||
AVRDUDE = avrdude
|
||||
REMOVE = rm -f
|
||||
MV = mv -f
|
||||
|
||||
# Define all object files.
|
||||
OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)
|
||||
|
||||
# Define all listing files.
|
||||
LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)
|
||||
|
||||
# Combine all necessary flags and optional flags.
|
||||
# Add target processor to flags.
|
||||
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS)
|
||||
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
|
||||
|
||||
# Default target.
|
||||
all: build
|
||||
|
||||
build: elf hex eep
|
||||
|
||||
elf: $(TARGET).elf
|
||||
hex: $(TARGET).hex
|
||||
eep: $(TARGET).eep
|
||||
lss: $(TARGET).lss
|
||||
sym: $(TARGET).sym
|
||||
|
||||
|
||||
# Program the device.
|
||||
install: $(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
|
||||
$(COFFCONVERT) -O coff-avr $(TARGET).elf $(TARGET).cof
|
||||
|
||||
|
||||
extcoff: $(TARGET).elf
|
||||
$(COFFCONVERT) -O coff-ext-avr $(TARGET).elf $(TARGET).cof
|
||||
|
||||
|
||||
.SUFFIXES: .elf .hex .eep .lss .sym
|
||||
|
||||
.elf.hex:
|
||||
$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
|
||||
|
||||
.elf.eep:
|
||||
-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
|
||||
--change-section-lma .eeprom=0 -O $(FORMAT) $< $@
|
||||
|
||||
# Create extended listing file from ELF output file.
|
||||
.elf.lss:
|
||||
$(OBJDUMP) -h -S $< > $@
|
||||
|
||||
# Create a symbol table from ELF output file.
|
||||
.elf.sym:
|
||||
$(NM) -n $< > $@
|
||||
|
||||
|
||||
|
||||
# Link: create ELF output file from object files.
|
||||
$(TARGET).elf: $(OBJ)
|
||||
$(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)
|
||||
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
.c.o:
|
||||
$(CC) -c $(ALL_CFLAGS) $< -o $@
|
||||
|
||||
|
||||
# Compile: create assembler files from C source files.
|
||||
.c.s:
|
||||
$(CC) -S $(ALL_CFLAGS) $< -o $@
|
||||
|
||||
|
||||
# Assemble: create object files from assembler source files.
|
||||
.S.o:
|
||||
$(CC) -c $(ALL_ASFLAGS) $< -o $@
|
||||
|
||||
|
||||
|
||||
# Target: clean project.
|
||||
clean:
|
||||
$(REMOVE) $(TARGET).hex $(TARGET).eep $(TARGET).cof $(TARGET).elf \
|
||||
$(TARGET).map $(TARGET).sym $(TARGET).lss \
|
||||
$(OBJ) $(LST) $(SRC:.c=.s) $(SRC:.c=.d)
|
||||
|
||||
depend:
|
||||
if grep '^# DO NOT DELETE' $(MAKEFILE) >/dev/null; \
|
||||
then \
|
||||
sed -e '/^# DO NOT DELETE/,$$d' $(MAKEFILE) > \
|
||||
$(MAKEFILE).$$$$ && \
|
||||
$(MV) $(MAKEFILE).$$$$ $(MAKEFILE); \
|
||||
fi
|
||||
echo '# DO NOT DELETE THIS LINE -- make depend depends on it.' \
|
||||
>> $(MAKEFILE); \
|
||||
$(CC) -M -mmcu=$(MCU) $(CDEFS) $(CINCS) $(SRC) $(ASRC) >> $(MAKEFILE)
|
||||
|
||||
.PHONY: all build elf hex eep lss sym program coff extcoff clean depend
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
<AVRStudio><MANAGEMENT><ProjectName>bootloader</ProjectName><Created>27-May-2009 06:28:56</Created><LastEdit>27-May-2009 06:28:56</LastEdit><ICON>241</ICON><ProjectType>0</ProjectType><Created>27-May-2009 06:28:56</Created><Version>4</Version><Build>4, 15, 0, 623</Build><ProjectTypeName>AVR GCC</ProjectTypeName></MANAGEMENT><CODE_CREATION><ObjectFile></ObjectFile><EntryFile></EntryFile><SaveFolder>D:\code\bacnet-stack\ports\bdk-atxx4-mstp\bootloader\</SaveFolder></CODE_CREATION><DEBUG_TARGET><CURRENT_TARGET>JTAGICE mkII</CURRENT_TARGET><CURRENT_PART>ATmega644P.xml</CURRENT_PART><BREAKPOINTS></BREAKPOINTS><IO_EXPAND><HIDE>false</HIDE></IO_EXPAND><REGISTERNAMES><Register>R00</Register><Register>R01</Register><Register>R02</Register><Register>R03</Register><Register>R04</Register><Register>R05</Register><Register>R06</Register><Register>R07</Register><Register>R08</Register><Register>R09</Register><Register>R10</Register><Register>R11</Register><Register>R12</Register><Register>R13</Register><Register>R14</Register><Register>R15</Register><Register>R16</Register><Register>R17</Register><Register>R18</Register><Register>R19</Register><Register>R20</Register><Register>R21</Register><Register>R22</Register><Register>R23</Register><Register>R24</Register><Register>R25</Register><Register>R26</Register><Register>R27</Register><Register>R28</Register><Register>R29</Register><Register>R30</Register><Register>R31</Register></REGISTERNAMES><COM>Auto</COM><COMType>0</COMType><WATCHNUM>0</WATCHNUM><WATCHNAMES><Pane0></Pane0><Pane1></Pane1><Pane2></Pane2><Pane3></Pane3></WATCHNAMES><BreakOnTrcaeFull>0</BreakOnTrcaeFull></DEBUG_TARGET><Debugger><Triggers></Triggers></Debugger><AVRGCCPLUGIN><FILES/><CONFIGS><CONFIG><NAME>default</NAME><USESEXTERNALMAKEFILE>NO</USESEXTERNALMAKEFILE><EXTERNALMAKEFILE></EXTERNALMAKEFILE><PART>atmega128</PART><HEX>1</HEX><LIST>1</LIST><MAP>1</MAP><OUTPUTFILENAME>bootloader.elf</OUTPUTFILENAME><OUTPUTDIR>default\</OUTPUTDIR><ISDIRTY>0</ISDIRTY><OPTIONS/><INCDIRS/><LIBDIRS/><LIBS/><LINKOBJECTS/><OPTIONSFORALL>-Wall -gdwarf-2 -Os -std=gnu99 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums</OPTIONSFORALL><LINKEROPTIONS></LINKEROPTIONS><SEGMENTS/></CONFIG></CONFIGS><LASTCONFIG>default</LASTCONFIG></AVRGCCPLUGIN><IOView><usergroups/><sort sorted="0" column="0" ordername="1" orderaddress="1" ordergroup="1"/></IOView><Files></Files><Events><Bookmarks></Bookmarks></Events><Trace><Filters></Filters></Trace></AVRStudio>
|
||||
@@ -0,0 +1,58 @@
|
||||
/* definitions generated by preprocessor, copy into defines.h */
|
||||
#ifndef PPINC
|
||||
#define _ATMEGA644P /* device select: _ATMEGAxxxx */
|
||||
#define _B2048 /* boot size select: _Bxxxx (words), powers of two only */
|
||||
#ifdef __ICCAVR__
|
||||
#include "iom644.h"
|
||||
#endif
|
||||
#if __GNUC__
|
||||
#include <avr/io.h>
|
||||
|
||||
#if (__GNUC__ <= 4) && (__GNUC_MINOR__ < 3)
|
||||
|
||||
#if !defined(EEWE) && defined(EEPE)
|
||||
#define EEWE EEPE
|
||||
#endif
|
||||
|
||||
#if !defined(EEMWE) && defined(EEMPE)
|
||||
#define EEMWE EEMPE
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* define pin for enter-self-prog-mode */
|
||||
#define PROGPORT PORTB
|
||||
#define PROGPIN PINB
|
||||
#define PROG_NO PB0
|
||||
|
||||
/* baud rate register value calculation */
|
||||
#define CPU_FREQ 18430000
|
||||
#define BAUD_RATE 115200
|
||||
#define BRREG_VALUE 9
|
||||
|
||||
/* definitions for UART control */
|
||||
#define BAUD_RATE_LOW_REG UBRR1
|
||||
#define UART_CONTROL_REG UCSR1B
|
||||
#define ENABLE_TRANSMITTER_BIT TXEN1
|
||||
#define ENABLE_RECEIVER_BIT RXEN1
|
||||
#define UART_STATUS_REG UCSR1A
|
||||
#define TRANSMIT_COMPLETE_BIT TXC1
|
||||
#define RECEIVE_COMPLETE_BIT RXC1
|
||||
#define UART_DATA_REG UDR1
|
||||
|
||||
/* definitions for SPM control */
|
||||
#define SPMCR_REG SPMCSR
|
||||
#define PAGESIZE 256
|
||||
#define APP_END 61440
|
||||
/*#define LARGE_MEMORY */
|
||||
|
||||
/* definitions for device recognition */
|
||||
#define PARTCODE 0
|
||||
#define SIGNATURE_BYTE_1 0x1E
|
||||
#define SIGNATURE_BYTE_2 0x96
|
||||
#define SIGNATURE_BYTE_3 0x0A
|
||||
|
||||
/* indicate that preprocessor result is included */
|
||||
#define PPINC
|
||||
#endif
|
||||
@@ -0,0 +1,74 @@
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Atmel Corporation
|
||||
*
|
||||
* File : flash.h
|
||||
* Compiler : IAR C 3.10C Kickstart, AVR-GCC/avr-libc(>= 1.2.5)
|
||||
* Revision : $Revision: 1.7 $
|
||||
* Date : $Date: Tuesday, June 07, 200 $
|
||||
* Updated by : $Author: raapeland $
|
||||
*
|
||||
* Support mail : avr@atmel.com
|
||||
*
|
||||
* Target platform : All AVRs with bootloader support
|
||||
*
|
||||
* AppNote : AVR109 - Self-programming
|
||||
*
|
||||
* Description : Flash operations for AVR109 Self-programming
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(__ICCAVR__)
|
||||
|
||||
/* IAR Embedded Workbench */
|
||||
#include <inavr.h>
|
||||
|
||||
#define _GET_LOCK_BITS() __AddrToZByteToSPMCR_LPM( (void __flash *) 0x0001, 0x09 )
|
||||
#define _GET_LOW_FUSES() __AddrToZByteToSPMCR_LPM( (void __flash *) 0x0000, 0x09 )
|
||||
#define _GET_HIGH_FUSES() __AddrToZByteToSPMCR_LPM( (void __flash *) 0x0003, 0x09 )
|
||||
#define _GET_EXTENDED_FUSES() __AddrToZByteToSPMCR_LPM( (void __flash *) 0x0002, 0x09 )
|
||||
#define _SET_LOCK_BITS(data) __DataToR0ByteToSPMCR_SPM( data, 0x09 )
|
||||
#define _ENABLE_RWW_SECTION() __DataToR0ByteToSPMCR_SPM( 0x00, 0x11 )
|
||||
|
||||
#define _WAIT_FOR_SPM() while( SPMCR_REG & (1<<SPMEN) );
|
||||
|
||||
#ifndef LARGE_MEMORY
|
||||
#define _LOAD_PROGRAM_MEMORY(addr) __load_program_memory( (const unsigned char __flash *) (addr) )
|
||||
#define _FILL_TEMP_WORD(addr,data) __AddrToZWordToR1R0ByteToSPMCR_SPM( (void __flash *) (addr), data, 0x01 )
|
||||
#define _PAGE_ERASE(addr) __AddrToZByteToSPMCR_SPM( (void __flash *) (addr), 0x03 )
|
||||
#define _PAGE_WRITE(addr) __AddrToZByteToSPMCR_SPM( (void __flash *) (addr), 0x05 )
|
||||
#else /* LARGE_MEMORY */
|
||||
#define _LOAD_PROGRAM_MEMORY(addr) __extended_load_program_memory( (const unsigned char __farflash *) (addr) )
|
||||
#define _FILL_TEMP_WORD(addr,data) __AddrToZ24WordToR1R0ByteToSPMCR_SPM( (void __farflash *) (addr), data, 0x01 )
|
||||
#define _PAGE_ERASE(addr) __AddrToZ24ByteToSPMCR_SPM( (void __farflash *) (addr), 0x03 )
|
||||
#define _PAGE_WRITE(addr) __AddrToZ24ByteToSPMCR_SPM( (void __farflash *) (addr), 0x05 )
|
||||
#endif /* LARGE_MEMORY */
|
||||
|
||||
#elif __GNUC__ > 0
|
||||
|
||||
/* AVR-GCC/avr-libc */
|
||||
#include <avr/boot.h>
|
||||
#include <avr/pgmspace.h>
|
||||
|
||||
#if defined(GET_LOCK_BITS) /* avr-libc >= 1.2.5 */
|
||||
#define _GET_LOCK_BITS() boot_lock_fuse_bits_get(GET_LOCK_BITS)
|
||||
#define _GET_LOW_FUSES() boot_lock_fuse_bits_get(GET_LOW_FUSE_BITS)
|
||||
#define _GET_HIGH_FUSES() boot_lock_fuse_bits_get(GET_HIGH_FUSE_BITS)
|
||||
#define _GET_EXTENDED_FUSES() boot_lock_fuse_bits_get(GET_EXTENDED_FUSE_BITS)
|
||||
#endif /* defined(GET_LOCK_BITS) */
|
||||
#define _SET_LOCK_BITS(data) boot_lock_bits_set(~data)
|
||||
#define _ENABLE_RWW_SECTION() boot_rww_enable()
|
||||
|
||||
#define _WAIT_FOR_SPM() boot_spm_busy_wait()
|
||||
|
||||
#ifndef LARGE_MEMORY
|
||||
#define _LOAD_PROGRAM_MEMORY(addr) pgm_read_byte_near(addr)
|
||||
#else /* LARGE_MEMORY */
|
||||
#define _LOAD_PROGRAM_MEMORY(addr) pgm_read_byte_far(addr)
|
||||
#endif /* LARGE_MEMORY */
|
||||
#define _FILL_TEMP_WORD(addr,data) boot_page_fill(addr, data)
|
||||
#define _PAGE_ERASE(addr) boot_page_erase(addr)
|
||||
#define _PAGE_WRITE(addr) boot_page_write(addr)
|
||||
|
||||
#else
|
||||
#error "Don't know your compiler."
|
||||
#endif
|
||||
@@ -0,0 +1,466 @@
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Atmel Corporation
|
||||
*
|
||||
* File : main.c
|
||||
* Compiler : IAR C 3.10C Kickstart, AVR-GCC/avr-libc(>= 1.2.5)
|
||||
* Revision : $Revision: 1.7 $
|
||||
* Date : $Date: Tuesday, June 07, 200 $
|
||||
* Updated by : $Author: raapeland $
|
||||
*
|
||||
* Support mail : avr@atmel.com
|
||||
*
|
||||
* Target platform : All AVRs with bootloader support
|
||||
*
|
||||
* AppNote : AVR109 - Self-programming
|
||||
*
|
||||
* Description : This Program allows an AVR with bootloader capabilities to
|
||||
* Read/write its own Flash/EEprom. To enter Programming mode
|
||||
* an input pin is checked. If this pin is pulled low, programming mode
|
||||
* is entered. If not, normal execution is done from $0000
|
||||
* "reset" vector in Application area.
|
||||
*
|
||||
* Preparations : Use the preprocessor.xls file for obtaining a customized
|
||||
* defines.h file and linker-file code-segment definition for
|
||||
* the device you are compiling for.
|
||||
****************************************************************************/
|
||||
#include "defines.h"
|
||||
#include "serial.h"
|
||||
#include "flash.h"
|
||||
|
||||
|
||||
|
||||
/* Uncomment the following to save code space */
|
||||
/*#define REMOVE_AVRPROG_SUPPORT */
|
||||
/*#define REMOVE_FUSE_AND_LOCK_BIT_SUPPORT */
|
||||
/*#define REMOVE_BLOCK_SUPPORT */
|
||||
/*#define REMOVE_EEPROM_BYTE_SUPPORT */
|
||||
/*#define REMOVE_FLASH_BYTE_SUPPORT */
|
||||
|
||||
/*
|
||||
* GCC doesn't optimize long int arithmetics very clever. As the
|
||||
* address only needs to be larger than 16 bits for the ATmega128 and
|
||||
* above (where flash consumptions isn't much of an issue as the
|
||||
* entire boot loader will still fit even into the smallest possible
|
||||
* boot loader section), save space by using a 16-bit variable for the
|
||||
* smaller devices.
|
||||
*/
|
||||
#ifdef LARGE_MEMORY
|
||||
#define ADDR_T unsigned long
|
||||
#else /* !LARGE_MEMORY */
|
||||
#define ADDR_T unsigned int
|
||||
#endif /* LARGE_MEMORY */
|
||||
|
||||
#ifndef REMOVE_BLOCK_SUPPORT
|
||||
unsigned char BlockLoad(
|
||||
unsigned int size,
|
||||
unsigned char mem,
|
||||
ADDR_T * address);
|
||||
void BlockRead(
|
||||
unsigned int size,
|
||||
unsigned char mem,
|
||||
ADDR_T * address);
|
||||
|
||||
/* BLOCKSIZE should be chosen so that the following holds: BLOCKSIZE*n = PAGESIZE, where n=1,2,3... */
|
||||
#define BLOCKSIZE PAGESIZE
|
||||
|
||||
#endif /* REMOVE_BLOCK_SUPPORT */
|
||||
|
||||
#ifdef __ICCAVR__
|
||||
__C_task void main(
|
||||
void)
|
||||
#else /* ! __ICCAVR__ */
|
||||
int main(
|
||||
void)
|
||||
#endif /* __ICCAVR__ */
|
||||
{
|
||||
ADDR_T address;
|
||||
unsigned int temp_int;
|
||||
unsigned char val;
|
||||
|
||||
|
||||
/* Initialization */
|
||||
void (
|
||||
*funcptr) (
|
||||
void) = 0x0000; /* Set up function pointer to RESET vector. */
|
||||
PROGPORT |= (1 << PROG_NO); /* Enable pull-up on PROG_NO line on PROGPORT. */
|
||||
initbootuart(); /* Initialize UART. */
|
||||
|
||||
|
||||
/* Branch to bootloader or application code? */
|
||||
if (!(PROGPIN & (1 << PROG_NO))) { /* If PROGPIN is pulled low, enter programmingmode. */
|
||||
/* Main loop */
|
||||
for (;;) {
|
||||
val = recchar(); /* Wait for command character. */
|
||||
|
||||
/* Check autoincrement status. */
|
||||
if (val == 'a') {
|
||||
sendchar('Y'); /* Yes, we do autoincrement. */
|
||||
}
|
||||
|
||||
|
||||
/* Set address. */
|
||||
else if (val == 'A') { /* Set address... *//* NOTE: Flash addresses are given in words, not bytes. */
|
||||
address = (recchar() << 8) | recchar(); /* Read address high and low byte. */
|
||||
sendchar('\r'); /* Send OK back. */
|
||||
}
|
||||
|
||||
|
||||
/* Chip erase. */
|
||||
else if (val == 'e') {
|
||||
for (address = 0; address < APP_END; address += PAGESIZE) { /* NOTE: Here we use address as a byte-address, not word-address, for convenience. */
|
||||
_WAIT_FOR_SPM();
|
||||
#ifdef __ICCAVR__
|
||||
#pragma diag_suppress=Pe1053 /* Suppress warning for conversion from long-type address to flash ptr. */
|
||||
#endif
|
||||
_PAGE_ERASE(address);
|
||||
#ifdef __ICCAVR__
|
||||
#pragma diag_default=Pe1053 /* Back to default. */
|
||||
#endif
|
||||
}
|
||||
|
||||
sendchar('\r'); /* Send OK back. */
|
||||
}
|
||||
#ifndef REMOVE_BLOCK_SUPPORT
|
||||
/* Check block load support. */
|
||||
else if (val == 'b') {
|
||||
sendchar('Y'); /* Report block load supported. */
|
||||
sendchar((BLOCKSIZE >> 8) & 0xFF); /* MSB first. */
|
||||
sendchar(BLOCKSIZE & 0xFF); /* Report BLOCKSIZE (bytes). */
|
||||
}
|
||||
|
||||
|
||||
/* Start block load. */
|
||||
else if (val == 'B') {
|
||||
temp_int = (recchar() << 8) | recchar(); /* Get block size. */
|
||||
val = recchar(); /* Get memtype. */
|
||||
sendchar(BlockLoad(temp_int, val, &address)); /* Block load. */
|
||||
}
|
||||
|
||||
|
||||
/* Start block read. */
|
||||
else if (val == 'g') {
|
||||
temp_int = (recchar() << 8) | recchar(); /* Get block size. */
|
||||
val = recchar(); /* Get memtype */
|
||||
BlockRead(temp_int, val, &address); /* Block read */
|
||||
}
|
||||
#endif /* REMOVE_BLOCK_SUPPORT */
|
||||
|
||||
#ifndef REMOVE_FLASH_BYTE_SUPPORT
|
||||
/* Read program memory. */
|
||||
else if (val == 'R') {
|
||||
/* Send high byte, then low byte of flash word. */
|
||||
_WAIT_FOR_SPM();
|
||||
_ENABLE_RWW_SECTION();
|
||||
#ifdef __ICCAVR__
|
||||
#pragma diag_suppress=Pe1053 /* Suppress warning for conversion from long-type address to flash ptr. */
|
||||
#endif
|
||||
sendchar(_LOAD_PROGRAM_MEMORY((address << 1) + 1));
|
||||
sendchar(_LOAD_PROGRAM_MEMORY((address << 1) + 0));
|
||||
#ifdef __ICCAVR__
|
||||
#pragma diag_default=Pe1053 /* Back to default. */
|
||||
#endif
|
||||
|
||||
address++; /* Auto-advance to next Flash word. */
|
||||
}
|
||||
|
||||
|
||||
/* Write program memory, low byte. */
|
||||
else if (val == 'c') { /* NOTE: Always use this command before sending high byte. */
|
||||
temp_int = recchar(); /* Get low byte for later _FILL_TEMP_WORD. */
|
||||
sendchar('\r'); /* Send OK back. */
|
||||
}
|
||||
|
||||
|
||||
/* Write program memory, high byte. */
|
||||
else if (val == 'C') {
|
||||
temp_int |= (recchar() << 8); /* Get and insert high byte. */
|
||||
_WAIT_FOR_SPM();
|
||||
#ifdef __ICCAVR__
|
||||
#pragma diag_suppress=Pe1053 /* Suppress warning for conversion from long-type address to flash ptr. */
|
||||
#endif
|
||||
_FILL_TEMP_WORD((address << 1), temp_int); /* Convert word-address to byte-address and fill. */
|
||||
#ifdef __ICCAVR__
|
||||
#pragma diag_default=Pe1053 /* Back to default. */
|
||||
#endif
|
||||
address++; /* Auto-advance to next Flash word. */
|
||||
sendchar('\r'); /* Send OK back. */
|
||||
}
|
||||
|
||||
|
||||
/* Write page. */
|
||||
else if (val == 'm') {
|
||||
if (address >= (APP_END >> 1)) { /* Protect bootloader area. */
|
||||
sendchar('?');
|
||||
} else {
|
||||
_WAIT_FOR_SPM();
|
||||
#ifdef __ICCAVR__
|
||||
#pragma diag_suppress=Pe1053 /* Suppress warning for conversion from long-type address to flash ptr. */
|
||||
#endif
|
||||
_PAGE_WRITE(address << 1); /* Convert word-address to byte-address and write. */
|
||||
#ifdef __ICCAVR__
|
||||
#pragma diag_default=Pe1053 /* Back to default. */
|
||||
#endif
|
||||
}
|
||||
|
||||
sendchar('\r'); /* Send OK back. */
|
||||
}
|
||||
#endif /* REMOVE_FLASH_BYTE_SUPPORT */
|
||||
|
||||
#ifndef REMOVE_EEPROM_BYTE_SUPPORT
|
||||
/* Write EEPROM memory. */
|
||||
else if (val == 'D') {
|
||||
_WAIT_FOR_SPM();
|
||||
EEARL = address; /* Setup EEPROM address. */
|
||||
EEARH = (address >> 8);
|
||||
EEDR = recchar(); /* Get byte. */
|
||||
EECR |= (1 << EEMWE); /* Write byte. */
|
||||
EECR |= (1 << EEWE);
|
||||
while (EECR & (1 << EEWE)) /* Wait for write operation to finish. */
|
||||
;
|
||||
|
||||
address++; /* Auto-advance to next EEPROM byte. */
|
||||
sendchar('\r'); /* Send OK back. */
|
||||
}
|
||||
|
||||
|
||||
/* Read EEPROM memory. */
|
||||
else if (val == 'd') {
|
||||
EEARL = address; /* Setup EEPROM address. */
|
||||
EEARH = (address >> 8);
|
||||
EECR |= (1 << EERE); /* Read byte... */
|
||||
sendchar(EEDR); /* ...and send it back. */
|
||||
address++; /* Auto-advance to next EEPROM byte. */
|
||||
}
|
||||
#endif /* REMOVE_EEPROM_BYTE_SUPPORT */
|
||||
|
||||
#ifndef REMOVE_FUSE_AND_LOCK_BIT_SUPPORT
|
||||
/* Write lockbits. */
|
||||
else if (val == 'l') {
|
||||
_WAIT_FOR_SPM();
|
||||
_SET_LOCK_BITS(recchar()); /* Read and set lock bits. */
|
||||
sendchar('\r'); /* Send OK back. */
|
||||
}
|
||||
#if defined(_GET_LOCK_BITS)
|
||||
/* Read lock bits. */
|
||||
else if (val == 'r') {
|
||||
_WAIT_FOR_SPM();
|
||||
sendchar(_GET_LOCK_BITS());
|
||||
}
|
||||
|
||||
|
||||
/* Read fuse bits. */
|
||||
else if (val == 'F') {
|
||||
_WAIT_FOR_SPM();
|
||||
sendchar(_GET_LOW_FUSES());
|
||||
}
|
||||
|
||||
|
||||
/* Read high fuse bits. */
|
||||
else if (val == 'N') {
|
||||
_WAIT_FOR_SPM();
|
||||
sendchar(_GET_HIGH_FUSES());
|
||||
}
|
||||
|
||||
|
||||
/* Read extended fuse bits. */
|
||||
else if (val == 'Q') {
|
||||
_WAIT_FOR_SPM();
|
||||
sendchar(_GET_EXTENDED_FUSES());
|
||||
}
|
||||
#endif /* defined(_GET_LOCK_BITS) */
|
||||
#endif /* REMOVE_FUSE_AND_LOCK_BIT_SUPPORT */
|
||||
|
||||
#ifndef REMOVE_AVRPROG_SUPPORT
|
||||
/* Enter and leave programming mode. */
|
||||
else if ((val == 'P') || (val == 'L')) {
|
||||
sendchar('\r'); /* Nothing special to do, just answer OK. */
|
||||
}
|
||||
|
||||
|
||||
/* Exit bootloader. */
|
||||
else if (val == 'E') {
|
||||
_WAIT_FOR_SPM();
|
||||
_ENABLE_RWW_SECTION();
|
||||
sendchar('\r');
|
||||
funcptr(); /* Jump to Reset vector 0x0000 in Application Section. */
|
||||
}
|
||||
|
||||
|
||||
/* Get programmer type. */
|
||||
else if (val == 'p') {
|
||||
sendchar('S'); /* Answer 'SERIAL'. */
|
||||
}
|
||||
|
||||
|
||||
/* Return supported device codes. */
|
||||
else if (val == 't') {
|
||||
#if PARTCODE+0 > 0
|
||||
sendchar(PARTCODE); /* Supports only this device, of course. */
|
||||
#endif /* PARTCODE */
|
||||
sendchar(0); /* Send list terminator. */
|
||||
}
|
||||
|
||||
|
||||
/* Set LED, clear LED and set device type. */
|
||||
else if ((val == 'x') || (val == 'y') || (val == 'T')) {
|
||||
recchar(); /* Ignore the command and it's parameter. */
|
||||
sendchar('\r'); /* Send OK back. */
|
||||
}
|
||||
#endif /* REMOVE_AVRPROG_SUPPORT */
|
||||
|
||||
/* Return programmer identifier. */
|
||||
else if (val == 'S') {
|
||||
sendchar('A'); /* Return 'AVRBOOT'. */
|
||||
sendchar('V'); /* Software identifier (aka programmer signature) is always 7 characters. */
|
||||
sendchar('R');
|
||||
sendchar('B');
|
||||
sendchar('O');
|
||||
sendchar('O');
|
||||
sendchar('T');
|
||||
}
|
||||
|
||||
|
||||
/* Return software version. */
|
||||
else if (val == 'V') {
|
||||
sendchar('1');
|
||||
sendchar('5');
|
||||
}
|
||||
|
||||
|
||||
/* Return signature bytes. */
|
||||
else if (val == 's') {
|
||||
sendchar(SIGNATURE_BYTE_3);
|
||||
sendchar(SIGNATURE_BYTE_2);
|
||||
sendchar(SIGNATURE_BYTE_1);
|
||||
}
|
||||
|
||||
|
||||
/* The last command to accept is ESC (synchronization). */
|
||||
else if (val != 0x1b) { /* If not ESC, then it is unrecognized... */
|
||||
sendchar('?');
|
||||
}
|
||||
} /* end: for(;;) */
|
||||
} else {
|
||||
_WAIT_FOR_SPM();
|
||||
_ENABLE_RWW_SECTION();
|
||||
funcptr(); /* Jump to Reset vector 0x0000 in Application Section. */
|
||||
}
|
||||
} /* end: main */
|
||||
|
||||
|
||||
#ifndef REMOVE_BLOCK_SUPPORT
|
||||
unsigned char BlockLoad(
|
||||
unsigned int size,
|
||||
unsigned char mem,
|
||||
ADDR_T * address)
|
||||
{
|
||||
unsigned char buffer[BLOCKSIZE];
|
||||
unsigned int data;
|
||||
ADDR_T tempaddress;
|
||||
|
||||
/* EEPROM memory type. */
|
||||
if (mem == 'E') {
|
||||
/* Fill buffer first, as EEPROM is too slow to copy with UART speed */
|
||||
for (tempaddress = 0; tempaddress < size; tempaddress++)
|
||||
buffer[tempaddress] = recchar();
|
||||
|
||||
/* Then program the EEPROM */
|
||||
_WAIT_FOR_SPM();
|
||||
for (tempaddress = 0; tempaddress < size; tempaddress++) {
|
||||
EEARL = *address; /* Setup EEPROM address */
|
||||
EEARH = ((*address) >> 8);
|
||||
EEDR = buffer[tempaddress]; /* Get byte. */
|
||||
EECR |= (1 << EEMWE); /* Write byte. */
|
||||
EECR |= (1 << EEWE);
|
||||
while (EECR & (1 << EEWE)) /* Wait for write operation to finish. */
|
||||
;
|
||||
|
||||
(*address)++; /* Select next EEPROM byte */
|
||||
}
|
||||
|
||||
return '\r'; /* Report programming OK */
|
||||
}
|
||||
|
||||
/* Flash memory type. */
|
||||
else if (mem == 'F') { /* NOTE: For flash programming, 'address' is given in words. */
|
||||
(*address) <<= 1; /* Convert address to bytes temporarily. */
|
||||
tempaddress = (*address); /* Store address in page. */
|
||||
|
||||
do {
|
||||
data = recchar();
|
||||
data |= (recchar() << 8);
|
||||
#ifdef __ICCAVR__
|
||||
#pragma diag_suppress=Pe1053 /* Suppress warning for conversion from long-type address to flash ptr. */
|
||||
#endif
|
||||
_FILL_TEMP_WORD(*address, data);
|
||||
#ifdef __ICCAVR__
|
||||
#pragma diag_default=Pe1053 /* Back to default. */
|
||||
#endif
|
||||
(*address) += 2; /* Select next word in memory. */
|
||||
size -= 2; /* Reduce number of bytes to write by two. */
|
||||
} while (size); /* Loop until all bytes written. */
|
||||
|
||||
#ifdef __ICCAVR__
|
||||
#pragma diag_suppress=Pe1053 /* Suppress warning for conversion from long-type address to flash ptr. */
|
||||
#endif
|
||||
_PAGE_WRITE(tempaddress);
|
||||
#ifdef __ICCAVR__
|
||||
#pragma diag_default=Pe1053 /* Back to default. */
|
||||
#endif
|
||||
_WAIT_FOR_SPM();
|
||||
_ENABLE_RWW_SECTION();
|
||||
|
||||
(*address) >>= 1; /* Convert address back to Flash words again. */
|
||||
return '\r'; /* Report programming OK */
|
||||
}
|
||||
|
||||
/* Invalid memory type? */
|
||||
else {
|
||||
return '?';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void BlockRead(
|
||||
unsigned int size,
|
||||
unsigned char mem,
|
||||
ADDR_T * address)
|
||||
{
|
||||
/* EEPROM memory type. */
|
||||
if (mem == 'E') { /* Read EEPROM */
|
||||
do {
|
||||
EEARL = *address; /* Setup EEPROM address */
|
||||
EEARH = ((*address) >> 8);
|
||||
(*address)++; /* Select next EEPROM byte */
|
||||
EECR |= (1 << EERE); /* Read EEPROM */
|
||||
sendchar(EEDR); /* Transmit EEPROM dat ato PC */
|
||||
|
||||
size--; /* Decrease number of bytes to read */
|
||||
} while (size); /* Repeat until all block has been read */
|
||||
}
|
||||
|
||||
/* Flash memory type. */
|
||||
else if (mem == 'F') {
|
||||
(*address) <<= 1; /* Convert address to bytes temporarily. */
|
||||
|
||||
do {
|
||||
#ifdef __ICCAVR__
|
||||
#pragma diag_suppress=Pe1053 /* Suppress warning for conversion from long-type address to flash ptr. */
|
||||
#endif
|
||||
sendchar(_LOAD_PROGRAM_MEMORY(*address));
|
||||
sendchar(_LOAD_PROGRAM_MEMORY((*address) + 1));
|
||||
#ifdef __ICCAVR__
|
||||
#pragma diag_default=Pe1053 /* Back to default. */
|
||||
#endif
|
||||
(*address) += 2; /* Select next word in memory. */
|
||||
size -= 2; /* Subtract two bytes from number of bytes to read */
|
||||
} while (size); /* Repeat until all block has been read */
|
||||
|
||||
(*address) >>= 1; /* Convert address back to Flash words again. */
|
||||
}
|
||||
}
|
||||
#endif /* REMOVE_BLOCK_SUPPORT */
|
||||
|
||||
|
||||
/* end of file */
|
||||
@@ -0,0 +1,24 @@
|
||||
#Extracted from "Part definitions" of preprocessor.xls
|
||||
#dev include pagesz nrwwpag totpag avr910 sig1 sig2 sig3 baudlo uartc uarts txen rxen txc rxc udr spmcr
|
||||
ATmega8 iom8.h 32 32 128 0x77 0x1E 0x93 0x07 UBRRL UCSRB UCSRA TXEN RXEN TXC RXC UDR SPMCR
|
||||
ATmega8515 iom8515.h 32 32 128 0x3B 0x1E 0x93 0x06 UBRRL UCSRB UCSRA TXEN RXEN TXC RXC UDR SPMCR
|
||||
ATmega8535 iom8535.h 32 32 128 0x6A 0x1E 0x93 0x08 UBRRL UCSRB UCSRA TXEN RXEN TXC RXC UDR SPMCR
|
||||
ATmega88 iom88.h 32 32 128 0x1E 0x93 0x0A UBRR0L UCSR0B UCSR0A TXEN0 RXEN0 TXC0 RXC0 UDR0 SPMCSR
|
||||
ATmega16 iom16.h 64 16 128 0x75 0x1E 0x94 0x03 UBRRL UCSRB UCSRA TXEN RXEN TXC RXC UDR SPMCR
|
||||
ATmega162 iom162.h 64 16 128 0x63 0x1E 0x94 0x04 UBRR0L UCSR0B UCSR0A TXEN0 RXEN0 TXC0 RXC0 UDR0 SPMCR
|
||||
ATmega163 iom163.h 64 16 128 0x66 0x1E 0x94 0x02 UBRRLO UCSRB UCSRA TXEN RXEN TXC RXC UDR SPMCR
|
||||
ATmega165 iom165.h 64 16 128 0x1E 0x94 0x07 UBRRL UCSRB UCSRA TXEN RXEN TXC RXC UDR SPMCSR
|
||||
ATmega168 iom168.h 64 16 128 0x1E 0x94 0x06 UBRR0L UCSR0B UCSR0A TXEN0 RXEN0 TXC0 RXC0 UDR0 SPMCSR
|
||||
ATmega169 iom169.h 64 16 128 0x79 0x1E 0x94 0x05 UBRR0L UCSR0B UCSR0A TXEN0 RXEN0 TXC0 RXC0 UDR0 SPMCSR
|
||||
ATmega32 iom32.h 64 32 256 0x7F 0x1E 0x95 0x02 UBRRL UCSRB UCSRA TXEN RXEN TXC RXC UDR SPMCR
|
||||
ATmega323 iom323.h 64 16 256 0x73 0x1E 0x95 0x01 UBRRL UCSRB UCSRA TXEN RXEN TXC RXC UDR SPMCR
|
||||
ATmega329 iom329.h 64 32 256 0x1E 0x95 0x03 UBRR UCSRB UCSRA TXEN RXEN TXC RXC UDR SPMCSR
|
||||
ATmega3290 iom3290.h 64 32 256 0x1E 0x95 0x04 UBRR UCSRB UCSRA TXEN RXEN TXC RXC UDR SPMCSR
|
||||
ATmega64 iom64.h 128 32 256 0x46 0x1E 0x96 0x02 UBRR0L UCSR0B UCSR0A TXEN0 RXEN0 TXC0 RXC0 UDR0 SPMCR
|
||||
ATmega644 iom644.h 128 32 256 0x1E 0x96 0x09 UBRR0 UCSR0B UCSR0A TXEN0 RXEN0 TXC0 RXC0 UDR0 SPMCSR
|
||||
ATmega644P iom644.h 128 32 256 0x1E 0x96 0x0A UBRR1 UCSR1B UCSR1A TXEN1 RXEN1 TXC1 RXC1 UDR1 SPMCSR
|
||||
ATmega649 iom649.h 128 32 256 0x1E 0x96 0x03 UBRR UCSRB UCSRA TXEN RXEN TXC RXC UDR SPMCSR
|
||||
ATmega6490 iom6490.h 128 32 256 0x1E 0x96 0x04 UBRR UCSRB UCSRA TXEN RXEN TXC RXC UDR SPMCSR
|
||||
ATmega128 iom128.h 128 32 512 0x44 0x1E 0x97 0x02 UBRR0L UCSR0B UCSR0A TXEN0 RXEN0 TXC0 RXC0 UDR0 SPMCSR
|
||||
ATmega128_1 iom128.h 128 32 512 0x44 0x1E 0x97 0x02 UBRR1L UCSR1B UCSR1A TXEN1 RXEN1 TXC1 RXC1 UDR1 SPMCSR
|
||||
|
||||
@@ -0,0 +1,171 @@
|
||||
#! /bin/sh
|
||||
|
||||
# Equivalent script to what preprocessor.xls might do.
|
||||
#
|
||||
# Run e.g. like
|
||||
# sh preprocessor.sh ATmega128 4096 PORTD PD4 3686400 9600 > defines.h
|
||||
#
|
||||
# Written by Joerg Wunsch, 2005-07-29
|
||||
|
||||
PARTFILE=parts.txt
|
||||
|
||||
usage()
|
||||
{
|
||||
echo "usage: preprocessor.sh device bootsize progport prog_no cpu_freq baud_rate" >& 2
|
||||
exit 1
|
||||
}
|
||||
|
||||
if [ $# -ne 6 ]
|
||||
then
|
||||
usage
|
||||
fi
|
||||
|
||||
if [ ! -f ${PARTFILE} ]
|
||||
then
|
||||
echo "part definition file ${PARTFILE} not found" >& 2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
device="$1"
|
||||
bootsize="$2"
|
||||
progport="$3"
|
||||
prog_no="$4"
|
||||
cpu_freq="$5"
|
||||
baud_rate="$6"
|
||||
|
||||
# is there a device at all?
|
||||
if grep -i "^${device} " ${PARTFILE} >/dev/null
|
||||
then
|
||||
:
|
||||
else
|
||||
echo "device ${device} not found in ${PARTFILE}" >& 2
|
||||
exit 1
|
||||
fi
|
||||
devupper=`echo $device | tr '[a-z]' '[A-Z]'`
|
||||
|
||||
# find an awk to use, out of nawk, gawk, or awk
|
||||
AWK=none
|
||||
for name in nawk gawk awk
|
||||
do
|
||||
set -- `type $name 2>/dev/null`
|
||||
if [ "x$2" = 'xis' ]
|
||||
then
|
||||
AWK=$name
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [ $AWK = 'none' ]
|
||||
then
|
||||
echo "Sorry, no useable awk found" >& 2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# OK, now get the individual fields. Unfortunately, the AVR910 device ID
|
||||
# is optional, and the shell cannot parse that natively. Use awk to
|
||||
# re-order the fields, and sort the avr910 column last (so we'll get an
|
||||
# empty variable in read if it is not present).
|
||||
set -- `grep -i "^${device} " ${PARTFILE} |\
|
||||
${AWK} -F ' ' \
|
||||
'{print $1 " " $2 " " $3 " " $4 " " $5 " " $7 " " $8 " " $9 " " $10 " " $11 " " $12 " " $13 " " $14 " " $15 " " $16 " " $17 " " $18 " " $6; exit}'`
|
||||
dev=$1
|
||||
include=$2
|
||||
pagesz=$3
|
||||
nrwwpag=$4
|
||||
totpag=$5
|
||||
sig1=$6
|
||||
sig2=$7
|
||||
sig3=$8
|
||||
baudlo=$9
|
||||
shift 9
|
||||
uartc=$1
|
||||
uarts=$2
|
||||
txen=$3
|
||||
rxen=$4
|
||||
txc=$5
|
||||
rxc=$6
|
||||
udr=$7
|
||||
spmcr=$8
|
||||
avr910=$9
|
||||
|
||||
# Verify boot size
|
||||
pagebytes=`expr $pagesz \* 2`
|
||||
maxboot=`expr $nrwwpag \* $pagebytes`
|
||||
bootbytes=`expr 2 \* $bootsize` || exit 1
|
||||
if [ \( $bootbytes -ne $maxboot \) -a \
|
||||
\( $bootbytes -ne `expr $maxboot / 4` \) -a \
|
||||
\( $bootbytes -ne `expr $maxboot / 2` \) -a \
|
||||
\( $bootbytes -ne `expr $maxboot \* 3 / 4` \) ]
|
||||
then
|
||||
echo "Invalid boot size ${bootsize}, valid: `expr $maxboot / 8`, `expr $maxboot / 4`, `expr $maxboot \* 3 / 8`, `expr $maxboot / 2` words" >& 2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if p=`expr $progport : 'PORT\(.\)'`
|
||||
then
|
||||
: # ok
|
||||
else
|
||||
echo "Invalid port name ${progport}, must be PORTx" >& 2
|
||||
exit 1
|
||||
fi
|
||||
progpin="PIN$p"
|
||||
|
||||
brreg=`expr $cpu_freq / \( 16 \* $baud_rate \) - 1` || exit 1
|
||||
memsize=`expr $totpag \* $pagebytes`
|
||||
append=`expr $memsize - $bootbytes`
|
||||
|
||||
echo "/* definitions generated by preprocessor, copy into defines.h */
|
||||
#ifndef PPINC
|
||||
#define _${devupper} // device select: _ATMEGAxxxx
|
||||
#define _B${bootsize} // boot size select: _Bxxxx (words), powers of two only
|
||||
#ifdef __ICCAVR__
|
||||
#include \"${include}\"
|
||||
#endif
|
||||
#if __GNUC__
|
||||
#include <avr/io.h>
|
||||
#endif
|
||||
|
||||
/* define pin for enter-self-prog-mode */
|
||||
#define PROGPORT ${progport}
|
||||
#define PROGPIN ${progpin}
|
||||
#define PROG_NO ${prog_no}
|
||||
|
||||
/* baud rate register value calculation */
|
||||
#define CPU_FREQ ${cpu_freq}
|
||||
#define BAUD_RATE ${baud_rate}
|
||||
#define BRREG_VALUE ${brreg}
|
||||
|
||||
/* definitions for UART control */
|
||||
#define BAUD_RATE_LOW_REG ${baudlo}
|
||||
#define UART_CONTROL_REG ${uartc}
|
||||
#define ENABLE_TRANSMITTER_BIT ${txen}
|
||||
#define ENABLE_RECEIVER_BIT ${rxen}
|
||||
#define UART_STATUS_REG ${uarts}
|
||||
#define TRANSMIT_COMPLETE_BIT ${txc}
|
||||
#define RECEIVE_COMPLETE_BIT ${rxc}
|
||||
#define UART_DATA_REG ${udr}
|
||||
|
||||
/* definitions for SPM control */
|
||||
#define SPMCR_REG ${spmcr}
|
||||
#define PAGESIZE ${pagebytes}
|
||||
#define APP_END ${append}"
|
||||
|
||||
if [ $memsize -gt 65536 ]
|
||||
then
|
||||
echo "#define LARGE_MEMORY"
|
||||
else
|
||||
echo "//#define LARGE_MEMORY"
|
||||
fi
|
||||
|
||||
echo "
|
||||
/* definitions for device recognition */
|
||||
#define PARTCODE ${avr910}
|
||||
#define SIGNATURE_BYTE_1 ${sig1}
|
||||
#define SIGNATURE_BYTE_2 ${sig2}
|
||||
#define SIGNATURE_BYTE_3 ${sig3}
|
||||
|
||||
/* indicate that preprocessor result is included */
|
||||
#define PPINC
|
||||
#endif"
|
||||
|
||||
echo "(IAR) Replace all code segment definitions in the linker file with the following line:" >& 2
|
||||
${AWK} 'BEGIN {printf "-Z(CODE)INTVEC,FAR_F,SWITCH,CODE=%X-%X\n", '$append', '$memsize' - 1; exit}' >& 2
|
||||
Binary file not shown.
@@ -0,0 +1,44 @@
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Atmel Corporation
|
||||
*
|
||||
* File : serial.c
|
||||
* Compiler : IAR C 3.10C Kickstart, AVR-GCC/avr-libc(>= 1.2.5)
|
||||
* Revision : $Revision: 1.7 $
|
||||
* Date : $Date: Tuesday, June 07, 200 $
|
||||
* Updated by : $Author: raapeland $
|
||||
*
|
||||
* Support mail : avr@atmel.com
|
||||
*
|
||||
* Target platform : All AVRs with bootloader support
|
||||
*
|
||||
* AppNote : AVR109 - Self-programming
|
||||
*
|
||||
* Description : UART communication routines
|
||||
****************************************************************************/
|
||||
#include "defines.h"
|
||||
|
||||
|
||||
void initbootuart(
|
||||
void)
|
||||
{
|
||||
BAUD_RATE_LOW_REG = BRREG_VALUE;
|
||||
UART_CONTROL_REG = (1 << ENABLE_RECEIVER_BIT) | (1 << ENABLE_TRANSMITTER_BIT); /* enable receive and transmit */
|
||||
}
|
||||
|
||||
|
||||
void sendchar(
|
||||
unsigned char c)
|
||||
{
|
||||
UART_DATA_REG = c; /* prepare transmission */
|
||||
while (!(UART_STATUS_REG & (1 << TRANSMIT_COMPLETE_BIT))); /* wait until byte sendt */
|
||||
UART_STATUS_REG |= (1 << TRANSMIT_COMPLETE_BIT); /* delete TXCflag */
|
||||
}
|
||||
|
||||
|
||||
unsigned char recchar(
|
||||
void)
|
||||
{
|
||||
while (!(UART_STATUS_REG & (1 << RECEIVE_COMPLETE_BIT))); /* wait for data */
|
||||
return UART_DATA_REG;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Atmel Corporation
|
||||
*
|
||||
* File : serial.h
|
||||
* Compiler : IAR C 3.10C Kickstart, AVR-GCC/avr-libc(>= 1.2.5)
|
||||
* Revision : $Revision: 1.7 $
|
||||
* Date : $Date: Tuesday, June 07, 200 $
|
||||
* Updated by : $Author: raapeland $
|
||||
*
|
||||
* Support mail : avr@atmel.com
|
||||
*
|
||||
* Target platform : All AVRs with bootloader support
|
||||
*
|
||||
* AppNote : AVR109 - Self-programming
|
||||
*
|
||||
* Description : Header file for serial.c
|
||||
****************************************************************************/
|
||||
|
||||
void initbootuart(
|
||||
void);
|
||||
void sendchar(
|
||||
unsigned char);
|
||||
unsigned char recchar(
|
||||
void);
|
||||
Reference in New Issue
Block a user