diff --git a/main.c b/main.c index 44564bb..dbd1174 100644 --- a/main.c +++ b/main.c @@ -73,7 +73,7 @@ /* use second UART on mega128 / can128 */ //#define UART_USE_SECOND -#include +#include #include #include #include @@ -95,29 +95,29 @@ #include "chipdef.h" #define UART_RX_BUFFER_SIZE SPM_PAGESIZE -unsigned char gBuffer[UART_RX_BUFFER_SIZE]; +uint8_t gBuffer[UART_RX_BUFFER_SIZE]; #define eeprom_is_ready() bit_is_clear(EECR, EEWE) #define my_eeprom_busy_wait() do{}while(!eeprom_is_ready()) uint32_t address; -unsigned char device; +uint8_t device; -void sendchar(char data) +void sendchar(uint8_t data) { loop_until_bit_is_set(UART_STATUS, UART_TXREADY); UART_DATA = data; } -char recvchar(void) +uint8_t recvchar(void) { loop_until_bit_is_set(UART_STATUS, UART_RXREADY); return UART_DATA; } -unsigned char BufferLoad(unsigned int size, unsigned char mem) +uint8_t BufferLoad(uint16_t size, uint8_t mem) { - unsigned int data, cnt; + uint16_t data, cnt; uint32_t tempaddress; for (cnt = 0; cnt < UART_RX_BUFFER_SIZE; cnt++) { @@ -183,9 +183,9 @@ unsigned char BufferLoad(unsigned int size, unsigned char mem) return 0; // Report programming failed } -void BlockRead(unsigned int size, unsigned char mem) +void BlockRead(uint16_t size, uint16_t mem) { - unsigned int data; + uint16_t data; my_eeprom_busy_wait(); @@ -216,9 +216,9 @@ void BlockRead(unsigned int size, unsigned char mem) } } -unsigned char read_fuse_lock(unsigned short addr, unsigned char mode) +uint8_t read_fuse_lock(uint16_t addr, uint8_t mode) { - unsigned char retval; + uint8_t retval; asm volatile ( @@ -250,11 +250,10 @@ void (*jump_to_app)(void) = 0x0000; int main(void) { - unsigned tempi; - char val; + uint8_t val; #ifdef START_POWERSAVE - char OK = 1; + uint8_t OK = 1; #endif BLDDR &= ~(1< address) { - boot_page_erase(address); // Perform page erase + uint32_t addr = 0; + while (APP_END > addr) { + boot_page_erase(addr); // Perform page erase boot_spm_busy_wait(); // Wait until the memory is erased. - address += SPM_PAGESIZE; + addr += SPM_PAGESIZE; } } boot_rww_enable();