cleanup cpu selection

- splitting chipdef.h, one header per cpu
- use integer define for BOOTSIZE
- calc correct bootloader address
This commit is contained in:
Olaf Rempel 2006-05-19 21:52:42 +02:00
parent 51182dbccb
commit cb5d02f4ba
9 changed files with 162 additions and 194 deletions

173
chipdef.h
View File

@ -11,184 +11,25 @@
#error "AVR processor does not provide bootloader support!"
#endif
// TODO: make use of RAMEND in the avr-libc io-files and
// avoid a lot of by-device definitions here
#define APP_END (FLASHEND - (BOOTSIZE * 2))
#if defined(__AVR_ATmega169__)
#define sig_byte3 0x1E
#define sig_byte2 0x94
#define sig_byte1 0x05
#define devtype 0x79 // Mega 169 device code
// #define PAGESIZE 128 // 2*64 Words = Size in Bytes
#ifdef _B128
#define APP_PAGES ((2*8192 / SPM_PAGESIZE)- (2*128 / SPM_PAGESIZE ))
#define APP_END APP_PAGES * SPM_PAGESIZE
#endif
#ifdef _B256
#define APP_PAGES ((2*8192 / SPM_PAGESIZE)- (2*256 / SPM_PAGESIZE ))
#define APP_END APP_PAGES * SPM_PAGESIZE
#endif
#ifdef _B512
#define APP_PAGES ((2*8192 / SPM_PAGESIZE)- (2*512 / SPM_PAGESIZE ))
#define APP_END APP_PAGES * SPM_PAGESIZE
#endif
#ifdef _B1024
#define APP_PAGES ((2*8192 / SPM_PAGESIZE)- (2*1024 / SPM_PAGESIZE ))
#define APP_END APP_PAGES * SPM_PAGESIZE
#endif
#ifdef _B2048
#error "_B2048 not suppoted on this device"
#endif
#include "mega169.h"
#elif defined(__AVR_ATmega16__)
#define sig_byte3 0x1E
#define sig_byte2 0x94
#define sig_byte1 0x03
#define devtype 0x75 // Mega16 device code
// #define PAGESIZE 128 // Size in Bytes
#ifdef _B128
#define APP_PAGES ((2*8192 / SPM_PAGESIZE)- (2*128 / SPM_PAGESIZE ))
#define APP_END APP_PAGES * SPM_PAGESIZE
#endif
#ifdef _B256
#define APP_PAGES ((2*8192 / SPM_PAGESIZE)- (2*256 / SPM_PAGESIZE ))
#define APP_END APP_PAGES * SPM_PAGESIZE
#endif
#ifdef _B512
#define APP_PAGES ((2*8192 / SPM_PAGESIZE)- (2*512 / SPM_PAGESIZE ))
#define APP_END APP_PAGES * SPM_PAGESIZE
#endif
#ifdef _B1024
#define APP_PAGES ((2*8192 / SPM_PAGESIZE)- (2*1024 / SPM_PAGESIZE ))
#define APP_END APP_PAGES * SPM_PAGESIZE
#endif
#ifdef _B2048
#error "_B2048 not suppoted on this device"
#endif
#include "mega16.h"
#elif defined(__AVR_ATmega8__)
#define sig_byte3 0x1E
#define sig_byte2 0x93
#define sig_byte1 0x07
//#define devtype 0x77 // Mega8 boot device code
#define devtype 0x76 // Mega8 boot device code
// #define PAGESIZE 64 // Size in Bytes
#ifdef _B128
#define APP_PAGES ((2*4096 / SPM_PAGESIZE)- (2*128 / SPM_PAGESIZE ))
#define APP_END APP_PAGES * SPM_PAGESIZE
#endif
#ifdef _B256
#define APP_PAGES ((2*4096 / SPM_PAGESIZE)- (2*256 / SPM_PAGESIZE ))
#define APP_END APP_PAGES * SPM_PAGESIZE
#endif
#ifdef _B512
#define APP_PAGES ((2*4096 / SPM_PAGESIZE)- (2*512 / SPM_PAGESIZE ))
#define APP_END APP_PAGES * SPM_PAGESIZE
#endif
#ifdef _B1024
#define APP_PAGES ((2*4096 / SPM_PAGESIZE)- (2*1024 / SPM_PAGESIZE ))
#define APP_END APP_PAGES * SPM_PAGESIZE
#endif
#ifdef _B2048
#error "_B2048 not suppoted on this device"
#endif
#include "mega8.h"
#elif defined(__AVR_ATmega32__)
#define sig_byte3 0x1E
#define sig_byte2 0x95
#define sig_byte1 0x02
#define devtype 0x73 // Mega32 device code
// #define PAGESIZE 128 // Size in Bytes
#ifdef _B128
#define APP_PAGES ((2*16384UL / SPM_PAGESIZE)- (2*128 / SPM_PAGESIZE ))
#define APP_END APP_PAGES * SPM_PAGESIZE
#endif
#ifdef _B256
#define APP_PAGES ((2*16384UL / SPM_PAGESIZE)- (2*256 / SPM_PAGESIZE ))
#define APP_END APP_PAGES * SPM_PAGESIZE
#endif
#ifdef _B512
#define APP_PAGES ((2*16384UL / SPM_PAGESIZE)- (2*512 / SPM_PAGESIZE ))
#define APP_END APP_PAGES * SPM_PAGESIZE
#endif
#ifdef _B1024
#define APP_PAGES ((2*16384UL / SPM_PAGESIZE)- (2*1024 / SPM_PAGESIZE ))
#define APP_END APP_PAGES * SPM_PAGESIZE
#endif
#ifdef _B2048
#define APP_PAGES ((2*16384UL / SPM_PAGESIZE)- (2*2048 / SPM_PAGESIZE ))
#define APP_END APP_PAGES * SPM_PAGESIZE
#endif
#include "mega32.h"
#elif defined(__AVR_ATmega128__)
#define sig_byte3 0x1E
#define sig_byte2 0x97
#define sig_byte1 0x02
#define devtype 0x44 //
// #define PAGESIZE 128 // Size in Bytes
#ifdef _B512
#define APP_PAGES ((2*65536UL / SPM_PAGESIZE)- (2*512 / SPM_PAGESIZE ))
#define APP_END APP_PAGES * SPM_PAGESIZE
#endif
#ifdef _B1024
#define APP_PAGES ((2*65536UL / SPM_PAGESIZE)- (2*1024 / SPM_PAGESIZE ))
#define APP_END APP_PAGES * SPM_PAGESIZE
#endif
#ifdef _B2048
#define APP_PAGES ((2*65536UL / SPM_PAGESIZE)- (2*2048 / SPM_PAGESIZE ))
#define APP_END APP_PAGES * SPM_PAGESIZE
#endif
#ifdef _B4096
#define APP_PAGES ((2*65536UL / SPM_PAGESIZE)- (2*4096 / SPM_PAGESIZE ))
#define APP_END APP_PAGES * SPM_PAGESIZE
#endif
#include "mega128.h"
#elif defined(__AVR_AT90CAN128__)
#define sig_byte3 0x1E
#define sig_byte2 0x97
#define sig_byte1 0x81
#define devtype 0x43 /* Dummy device code for now, must be same as
used in avrdude.conf */
// #define PAGESIZE 128 // Size in Bytes
#ifdef _B512
#define APP_PAGES ((2*65536UL / SPM_PAGESIZE)- (2*512 / SPM_PAGESIZE ))
#define APP_END APP_PAGES * SPM_PAGESIZE
#endif
#ifdef _B1024
#define APP_PAGES ((2*65536UL / SPM_PAGESIZE)- (2*1024 / SPM_PAGESIZE ))
#define APP_END APP_PAGES * SPM_PAGESIZE
#endif
#ifdef _B2048
#define APP_PAGES ((2*65536UL / SPM_PAGESIZE)- (2*2048 / SPM_PAGESIZE ))
#define APP_END APP_PAGES * SPM_PAGESIZE
#endif
#ifdef _B4096
#define APP_PAGES ((2*65536UL / SPM_PAGESIZE)- (2*4096 / SPM_PAGESIZE ))
#define APP_END APP_PAGES * SPM_PAGESIZE
#endif
#include "mega128can.h"
#else
#error "no definition for MCU available in chipdef.h"

14
main.c
View File

@ -126,7 +126,7 @@ unsigned char BufferLoad(unsigned int size, unsigned char mem)
my_eeprom_busy_wait();
if (device == devtype) {
if (device == DEVTYPE) {
// Flash
if (mem == 'F') {
do {
@ -394,7 +394,7 @@ int main(void)
// Chip erase
} else if (val == 'e') {
if (device == devtype) {
if (device == DEVTYPE) {
// erase only main section (bootloader protection)
address = 0;
while (APP_END > address) {
@ -416,7 +416,7 @@ int main(void)
// TODO: does not work reliably
// write lockbits
} else if (val == 'l') {
if (device == devtype) {
if (device == DEVTYPE) {
// write_lock_bits(recchar());
boot_lock_bits_set(recchar()); // boot.h takes care of mask
boot_spm_busy_wait();
@ -456,7 +456,7 @@ int main(void)
// Return device type
} else if (val == 't') {
sendchar(devtype);
sendchar(DEVTYPE);
sendchar(0);
// clear and set LED ignored
@ -480,9 +480,9 @@ int main(void)
// Return Signature Byte
} else if (val == 's') {
sendchar(sig_byte1);
sendchar(sig_byte2);
sendchar(sig_byte3);
sendchar(SIG_BYTE1);
sendchar(SIG_BYTE2);
sendchar(SIG_BYTE3);
/* ESC */
} else if(val != 0x1b) {

105
makefile
View File

@ -73,12 +73,12 @@ STARTMODE=START_WAIT
##STARTMODE=START_BOOTICE
#/* Select Boot Size in Words (select one, comment out the others) */
## NO! BOOTSIZE=_B128
## NO! BOOTSIZE=_B256
## MAYBE: BOOTSIZE=_B512
#BOOTSIZE=_B512
BOOTSIZE=_B1024
##BOOTSIZE=_B2048
## NO! BOOTSIZE=128
## NO! BOOTSIZE=256
## MAYBE: BOOTSIZE=512
#BOOTSIZE=512
BOOTSIZE=1024
##BOOTSIZE=2048
################## BOOTLOADER ######################
@ -88,29 +88,94 @@ BOOTSIZE=_B1024
# "word", gcc toolchain needs "byte"-address
# (see LDFLAGS further down)
# 0x1C00*2=0x3800 for ATmega16 1024 words Boot Size
ifeq ($(MCU), atmega16)
MT_BOOTLOADER_ADDRESS = 3800
endif
# 0x0C00*2=0x1800 for ATmega8 1024 words Boot Size
ifeq ($(MCU), atmega8)
MT_BOOTLOADER_ADDRESS = 1800
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
# 0x3C00*2=0x7800 for ATmega32 1024 words Boot Size
endif
ifeq ($(MCU), atmega16)
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)
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)
MT_BOOTLOADER_ADDRESS = 7800
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
# 0xFC00*2=0x1F800 for ATmega128 1024 words Boot Size
endif
ifeq ($(MCU), atmega128)
MT_BOOTLOADER_ADDRESS = 1F800
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
# 0xFC00*2=0x1F800 for AT90Can128 1024 words Boot Size
endif
ifeq ($(MCU), at90can128)
MT_BOOTLOADER_ADDRESS = 1f800
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
@ -161,7 +226,7 @@ CSTANDARD = -std=gnu99
# Place -D or -U options here
CDEFS = -DBLPORT=$(BLPORT) -DBLDDR=$(BLDDR) -DBLPIN=$(BLPIN) -DBLPNUM=$(BLPNUM)
CDEFS += -D$(STARTMODE) -D$(BOOTSIZE) -DBAUDRATE=$(BAUDRATE)
CDEFS += -D$(STARTMODE) -DBOOTSIZE=$(BOOTSIZE) -DBAUDRATE=$(BAUDRATE)
ifdef XTAL
CDEFS += -DXTAL=$(XTAL)
endif

10
mega128.h Normal file
View File

@ -0,0 +1,10 @@
#ifndef _MEGA128_H_
#define _MEGA128_H_
#define DEVTYPE 0x44
#define SIG_BYTE3 0x1E
#define SIG_BYTE2 0x97
#define SIG_BYTE1 0x02
#endif // #ifndef _MEGA128_H_

11
mega128can.h Normal file
View File

@ -0,0 +1,11 @@
#ifndef _MEGA128CAN_H_
#define _MEGA128CAN_H_
/* Dummy device code for now, must be same as used in avrdude.conf */
#define DEVTYPE 0x43
#define SIG_BYTE3 0x1E
#define SIG_BYTE2 0x97
#define SIG_BYTE1 0x81
#endif // #ifndef _MEGA128CAN_H_

10
mega16.h Normal file
View File

@ -0,0 +1,10 @@
#ifndef _MEGA16_H_
#define _MEGA16_H_
#define DEVTYPE 0x75
#define SIG_BYTE3 0x1E
#define SIG_BYTE2 0x94
#define SIG_BYTE1 0x03
#endif // #ifndef _MEGA16_H_

10
mega169.h Normal file
View File

@ -0,0 +1,10 @@
#ifndef _MEGA169_H_
#define _MEGA169_H_
#define DEVTYPE 0x79
#define SIG_BYTE3 0x1E
#define SIG_BYTE2 0x94
#define SIG_BYTE1 0x05
#endif // #ifndef _MEGA169_H_

10
mega32.h Normal file
View File

@ -0,0 +1,10 @@
#ifndef _MEGA32_H_
#define _MEGA32_H_
#define DEVTYPE 0x73
#define SIG_BYTE3 0x1E
#define SIG_BYTE2 0x95
#define SIG_BYTE1 0x02
#endif // #ifndef _MEGA32_H_

11
mega8.h Normal file
View File

@ -0,0 +1,11 @@
#ifndef _MEGA8_H_
#define _MEGA8_H_
#define DEVTYPE 0x76
//#define DEVTYPE 0x77
#define SIG_BYTE3 0x1E
#define SIG_BYTE2 0x93
#define SIG_BYTE1 0x07
#endif // #ifndef _MEGA8_H_