use stdint types

- use blocklocal variables
This commit is contained in:
Olaf Rempel 2006-05-20 00:04:32 +02:00
parent 570d07d3a0
commit b29674a1f2

48
main.c
View File

@ -73,7 +73,7 @@
/* use second UART on mega128 / can128 */ /* use second UART on mega128 / can128 */
//#define UART_USE_SECOND //#define UART_USE_SECOND
#include <inttypes.h> #include <stdint.h>
#include <avr/io.h> #include <avr/io.h>
#include <avr/wdt.h> #include <avr/wdt.h>
#include <avr/boot.h> #include <avr/boot.h>
@ -95,29 +95,29 @@
#include "chipdef.h" #include "chipdef.h"
#define UART_RX_BUFFER_SIZE SPM_PAGESIZE #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 eeprom_is_ready() bit_is_clear(EECR, EEWE)
#define my_eeprom_busy_wait() do{}while(!eeprom_is_ready()) #define my_eeprom_busy_wait() do{}while(!eeprom_is_ready())
uint32_t address; 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); loop_until_bit_is_set(UART_STATUS, UART_TXREADY);
UART_DATA = data; UART_DATA = data;
} }
char recvchar(void) uint8_t recvchar(void)
{ {
loop_until_bit_is_set(UART_STATUS, UART_RXREADY); loop_until_bit_is_set(UART_STATUS, UART_RXREADY);
return UART_DATA; 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; uint32_t tempaddress;
for (cnt = 0; cnt < UART_RX_BUFFER_SIZE; cnt++) { 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 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(); 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 asm volatile
( (
@ -250,11 +250,10 @@ void (*jump_to_app)(void) = 0x0000;
int main(void) int main(void)
{ {
unsigned tempi; uint8_t val;
char val;
#ifdef START_POWERSAVE #ifdef START_POWERSAVE
char OK = 1; uint8_t OK = 1;
#endif #endif
BLDDR &= ~(1<<BLPNUM); // set as Input BLDDR &= ~(1<<BLPNUM); // set as Input
@ -381,26 +380,29 @@ int main(void)
// Start buffer load // Start buffer load
} else if (val == 'B') { } else if (val == 'B') {
tempi = recvchar() << 8; // Load high byte of buffersize uint16_t size;
tempi |= recvchar(); // Load low byte of buffersize size = recvchar() << 8; // Load high byte of buffersize
size |= recvchar(); // Load low byte of buffersize
val = recvchar(); // Load memory type ('E' or 'F') val = recvchar(); // Load memory type ('E' or 'F')
sendchar (BufferLoad(tempi, val)); // Start downloading of buffer sendchar(BufferLoad(size, val)); // Start downloading of buffer
// Block read // Block read
} else if (val == 'g') { } else if (val == 'g') {
tempi = (recvchar() << 8) | recvchar(); uint16_t size;
size = recvchar() << 8; // Load high byte of buffersize
size |= recvchar(); // Load low byte of buffersize
val = recvchar(); // Get memtype val = recvchar(); // Get memtype
BlockRead(tempi, val); // Perform the block read BlockRead(size, val); // Perform the block read
// Chip erase // Chip erase
} else if (val == 'e') { } else if (val == 'e') {
if (device == DEVTYPE) { if (device == DEVTYPE) {
// erase only main section (bootloader protection) // erase only main section (bootloader protection)
address = 0; uint32_t addr = 0;
while (APP_END > address) { while (APP_END > addr) {
boot_page_erase(address); // Perform page erase boot_page_erase(addr); // Perform page erase
boot_spm_busy_wait(); // Wait until the memory is erased. boot_spm_busy_wait(); // Wait until the memory is erased.
address += SPM_PAGESIZE; addr += SPM_PAGESIZE;
} }
} }
boot_rww_enable(); boot_rww_enable();