fix local flash erase

This commit is contained in:
Olaf Rempel 2011-06-05 18:24:22 +02:00
parent 125bdc1729
commit 6b836baeb0

25
main.c
View File

@ -120,18 +120,16 @@ static void i2c_start_address(uint8_t addr)
} }
} }
static void i2c_switch_app(uint8_t i2c_dev, uint8_t app) static void i2c_switch_app(uint8_t i2c_dev, uint8_t app, uint8_t show_version)
{ {
i2c_start_address(i2c_dev); i2c_start_address(i2c_dev);
i2c_master_tx(CMD_SWITCH_APPLICATION); i2c_master_tx(CMD_SWITCH_APPLICATION);
i2c_master_tx(app); i2c_master_tx(app);
i2c_stop(); i2c_stop();
_delay_ms(20); _delay_ms(100);
}
static void i2c_print_version(uint8_t i2c_dev) if (show_version) {
{
i2c_start_address(i2c_dev); i2c_start_address(i2c_dev);
i2c_master_tx(CMD_READ_VERSION); i2c_master_tx(CMD_READ_VERSION);
i2c_start_address(i2c_dev | 0x01); i2c_start_address(i2c_dev | 0x01);
@ -143,13 +141,14 @@ static void i2c_print_version(uint8_t i2c_dev)
i2c_stop(); i2c_stop();
} }
}
static uint8_t page_buf[SPM_PAGESIZE]; static uint8_t page_buf[SPM_PAGESIZE];
static void eraseFlash(void) static void eraseFlash(void)
{ {
uint16_t address = 0; uint16_t address = 0;
while (APP_END < address) { while (APP_END > address) {
boot_page_erase(address); boot_page_erase(address);
boot_spm_busy_wait(); boot_spm_busy_wait();
address += SPM_PAGESIZE; address += SPM_PAGESIZE;
@ -280,9 +279,9 @@ void cmd_loop(uint8_t val)
i2c_stop(); i2c_stop();
} else { } else {
if (val == 'F') { if (val == 'F' && address < APP_END) {
writeFlashPage(address, size); writeFlashPage(address, size);
} else if (val == 'E') { } else if (val == 'E' && address < E2END) {
writeEEpromPage(address, size); writeEEpromPage(address, size);
} }
address += size; address += size;
@ -337,7 +336,7 @@ void cmd_loop(uint8_t val)
} else if (val == 'P' || val == 'L') { } else if (val == 'P' || val == 'L') {
if (i2c_dev != 0) { if (i2c_dev != 0) {
val = (val == 'P') ? BOOTTYPE_BOOTLOADER : BOOTTYPE_APPLICATION; val = (val == 'P') ? BOOTTYPE_BOOTLOADER : BOOTTYPE_APPLICATION;
i2c_switch_app(i2c_dev, val); i2c_switch_app(i2c_dev, val, 0);
} }
response = '\r'; response = '\r';
@ -391,9 +390,7 @@ void cmd_loop(uint8_t val)
} else if (val >= '1' && val <= '4') { } else if (val >= '1' && val <= '4') {
i2c_dev = (val - '0' + TWI_ADDRESS_BASE) << 1; i2c_dev = (val - '0' + TWI_ADDRESS_BASE) << 1;
i2c_switch_app(i2c_dev, BOOTTYPE_BOOTLOADER); i2c_switch_app(i2c_dev, BOOTTYPE_BOOTLOADER, 1);
_delay_ms(100);
i2c_print_version(i2c_dev);
i2c_start_address(i2c_dev); i2c_start_address(i2c_dev);
i2c_master_tx(CMD_READ_MEMORY); i2c_master_tx(CMD_READ_MEMORY);
@ -421,9 +418,7 @@ void cmd_loop(uint8_t val)
// get Version // get Version
} else if (val == 'I') { } else if (val == 'I') {
if (i2c_dev != 0) { if (i2c_dev != 0) {
i2c_switch_app(i2c_dev, BOOTTYPE_APPLICATION); i2c_switch_app(i2c_dev, BOOTTYPE_APPLICATION, 1);
_delay_ms(100);
i2c_print_version(i2c_dev);
} }
// fake MK-TOOL specific stuff // fake MK-TOOL specific stuff