use stdint types
- use blocklocal variables
This commit is contained in:
parent
570d07d3a0
commit
b29674a1f2
48
main.c
48
main.c
@ -73,7 +73,7 @@
|
||||
/* use second UART on mega128 / can128 */
|
||||
//#define UART_USE_SECOND
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdint.h>
|
||||
#include <avr/io.h>
|
||||
#include <avr/wdt.h>
|
||||
#include <avr/boot.h>
|
||||
@ -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<<BLPNUM); // set as Input
|
||||
@ -381,26 +380,29 @@ int main(void)
|
||||
|
||||
// Start buffer load
|
||||
} else if (val == 'B') {
|
||||
tempi = recvchar() << 8; // Load high byte of buffersize
|
||||
tempi |= recvchar(); // Load low byte of buffersize
|
||||
uint16_t size;
|
||||
size = recvchar() << 8; // Load high byte of buffersize
|
||||
size |= recvchar(); // Load low byte of buffersize
|
||||
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
|
||||
} 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
|
||||
BlockRead(tempi, val); // Perform the block read
|
||||
BlockRead(size, val); // Perform the block read
|
||||
|
||||
// Chip erase
|
||||
} else if (val == 'e') {
|
||||
if (device == DEVTYPE) {
|
||||
// erase only main section (bootloader protection)
|
||||
address = 0;
|
||||
while (APP_END > 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();
|
||||
|
Loading…
Reference in New Issue
Block a user