flag eeprom support
This commit is contained in:
parent
525c2e3701
commit
b2c6dc35ce
26
main.c
26
main.c
@ -26,9 +26,8 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* atmega8:
|
* atmega8:
|
||||||
* Fuse E: 0xfa (512 words bootloader)
|
* Fuse H: 0xda (512 words bootloader)
|
||||||
* Fuse H: 0xdd (2.7V BOD)
|
* Fuse L: 0x84 (8Mhz internal RC-Osz., 2.7V BOD)
|
||||||
* Fuse L: 0xc2 (8Mhz internal RC-Osz.)
|
|
||||||
*
|
*
|
||||||
* atmega88:
|
* atmega88:
|
||||||
* Fuse E: 0xfa (512 words bootloader)
|
* Fuse E: 0xfa (512 words bootloader)
|
||||||
@ -57,6 +56,8 @@
|
|||||||
#error MCU not supported
|
#error MCU not supported
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define EEPROM_SUPPORT 1
|
||||||
|
|
||||||
/* 25ms @8MHz */
|
/* 25ms @8MHz */
|
||||||
#define TIMER_RELOAD (0xFF - 195)
|
#define TIMER_RELOAD (0xFF - 195)
|
||||||
|
|
||||||
@ -137,9 +138,12 @@ const static uint8_t chipinfo[8] = {
|
|||||||
|
|
||||||
(APP_END >> 8) & 0xFF,
|
(APP_END >> 8) & 0xFF,
|
||||||
APP_END & 0xFF,
|
APP_END & 0xFF,
|
||||||
|
#if (EEPROM_SUPPORT)
|
||||||
(E2END >> 8 & 0xFF),
|
(E2END >> 8 & 0xFF),
|
||||||
E2END & 0xFF
|
E2END & 0xFF
|
||||||
|
#else
|
||||||
|
0x00, 0x00
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
/* wait 40 * 25ms = 1s */
|
/* wait 40 * 25ms = 1s */
|
||||||
@ -176,6 +180,7 @@ static void write_flash_page(void)
|
|||||||
boot_rww_enable();
|
boot_rww_enable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if (EEPROM_SUPPORT)
|
||||||
static uint8_t read_eeprom_byte(void)
|
static uint8_t read_eeprom_byte(void)
|
||||||
{
|
{
|
||||||
EEARL = addr;
|
EEARL = addr;
|
||||||
@ -200,6 +205,7 @@ static void write_eeprom_byte(uint8_t val)
|
|||||||
#endif
|
#endif
|
||||||
eeprom_busy_wait();
|
eeprom_busy_wait();
|
||||||
}
|
}
|
||||||
|
#endif /* EEPROM_SUPPORT */
|
||||||
|
|
||||||
ISR(TWI_vect)
|
ISR(TWI_vect)
|
||||||
{
|
{
|
||||||
@ -256,10 +262,10 @@ ISR(TWI_vect)
|
|||||||
|
|
||||||
} else if (data == MEMTYPE_FLASH) {
|
} else if (data == MEMTYPE_FLASH) {
|
||||||
cmd = CMD_WRITE_FLASH;
|
cmd = CMD_WRITE_FLASH;
|
||||||
|
#if (EEPROM_SUPPORT)
|
||||||
} else if (data == MEMTYPE_EEPROM) {
|
} else if (data == MEMTYPE_EEPROM) {
|
||||||
cmd = CMD_WRITE_EEPROM;
|
cmd = CMD_WRITE_EEPROM;
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
ack = (0<<TWEA);
|
ack = (0<<TWEA);
|
||||||
}
|
}
|
||||||
@ -289,12 +295,12 @@ ISR(TWI_vect)
|
|||||||
ack = (0<<TWEA);
|
ack = (0<<TWEA);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
#if (EEPROM_SUPPORT)
|
||||||
case CMD_WRITE_EEPROM:
|
case CMD_WRITE_EEPROM:
|
||||||
write_eeprom_byte(data);
|
write_eeprom_byte(data);
|
||||||
bcnt++;
|
bcnt++;
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
default:
|
default:
|
||||||
ack = (0<<TWEA);
|
ack = (0<<TWEA);
|
||||||
break;
|
break;
|
||||||
@ -329,11 +335,11 @@ ISR(TWI_vect)
|
|||||||
case CMD_READ_FLASH:
|
case CMD_READ_FLASH:
|
||||||
data = pgm_read_byte_near(addr++);
|
data = pgm_read_byte_near(addr++);
|
||||||
break;
|
break;
|
||||||
|
#if (EEPROM_SUPPORT)
|
||||||
case CMD_READ_EEPROM:
|
case CMD_READ_EEPROM:
|
||||||
data = read_eeprom_byte();
|
data = read_eeprom_byte();
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
default:
|
default:
|
||||||
data = 0xFF;
|
data = 0xFF;
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user