Fixed up file indent, comments, and eol-type.
This commit is contained in:
@@ -1,46 +1,46 @@
|
||||
/* definitions generated by preprocessor, copy into defines.h */
|
||||
#ifndef PPINC
|
||||
#define _ATMEGA644P // device select: _ATMEGAxxxx
|
||||
#define _B2048 // boot size select: _Bxxxx (words), powers of two only
|
||||
#ifdef __ICCAVR__
|
||||
#include "iom644.h"
|
||||
#endif
|
||||
#if __GNUC__
|
||||
#include <avr/io.h>
|
||||
#endif
|
||||
|
||||
/* define pin for enter-self-prog-mode */
|
||||
#define PROGPORT PORTB
|
||||
#define PROGPIN PINB
|
||||
#define PROG_NO PB0
|
||||
|
||||
/* baud rate register value calculation */
|
||||
#define CPU_FREQ 18430000
|
||||
#define BAUD_RATE 115200
|
||||
#define BRREG_VALUE 9
|
||||
|
||||
/* definitions for UART control */
|
||||
#define BAUD_RATE_LOW_REG UBRR1
|
||||
#define UART_CONTROL_REG UCSR1B
|
||||
#define ENABLE_TRANSMITTER_BIT TXEN1
|
||||
#define ENABLE_RECEIVER_BIT RXEN1
|
||||
#define UART_STATUS_REG UCSR1A
|
||||
#define TRANSMIT_COMPLETE_BIT TXC1
|
||||
#define RECEIVE_COMPLETE_BIT RXC1
|
||||
#define UART_DATA_REG UDR1
|
||||
|
||||
/* definitions for SPM control */
|
||||
#define SPMCR_REG SPMCSR
|
||||
#define PAGESIZE 256
|
||||
#define APP_END 61440
|
||||
//#define LARGE_MEMORY
|
||||
|
||||
/* definitions for device recognition */
|
||||
#define PARTCODE 0
|
||||
#define SIGNATURE_BYTE_1 0x1E
|
||||
#define SIGNATURE_BYTE_2 0x96
|
||||
#define SIGNATURE_BYTE_3 0x0A
|
||||
|
||||
/* indicate that preprocessor result is included */
|
||||
#define PPINC
|
||||
#endif
|
||||
/* definitions generated by preprocessor, copy into defines.h */
|
||||
#ifndef PPINC
|
||||
#define _ATMEGA644P /* device select: _ATMEGAxxxx */
|
||||
#define _B2048 /* boot size select: _Bxxxx (words), powers of two only */
|
||||
#ifdef __ICCAVR__
|
||||
#include "iom644.h"
|
||||
#endif
|
||||
#if __GNUC__
|
||||
#include <avr/io.h>
|
||||
#endif
|
||||
|
||||
/* define pin for enter-self-prog-mode */
|
||||
#define PROGPORT PORTB
|
||||
#define PROGPIN PINB
|
||||
#define PROG_NO PB0
|
||||
|
||||
/* baud rate register value calculation */
|
||||
#define CPU_FREQ 18430000
|
||||
#define BAUD_RATE 115200
|
||||
#define BRREG_VALUE 9
|
||||
|
||||
/* definitions for UART control */
|
||||
#define BAUD_RATE_LOW_REG UBRR1
|
||||
#define UART_CONTROL_REG UCSR1B
|
||||
#define ENABLE_TRANSMITTER_BIT TXEN1
|
||||
#define ENABLE_RECEIVER_BIT RXEN1
|
||||
#define UART_STATUS_REG UCSR1A
|
||||
#define TRANSMIT_COMPLETE_BIT TXC1
|
||||
#define RECEIVE_COMPLETE_BIT RXC1
|
||||
#define UART_DATA_REG UDR1
|
||||
|
||||
/* definitions for SPM control */
|
||||
#define SPMCR_REG SPMCSR
|
||||
#define PAGESIZE 256
|
||||
#define APP_END 61440
|
||||
/*#define LARGE_MEMORY */
|
||||
|
||||
/* definitions for device recognition */
|
||||
#define PARTCODE 0
|
||||
#define SIGNATURE_BYTE_1 0x1E
|
||||
#define SIGNATURE_BYTE_2 0x96
|
||||
#define SIGNATURE_BYTE_3 0x0A
|
||||
|
||||
/* indicate that preprocessor result is included */
|
||||
#define PPINC
|
||||
#endif
|
||||
|
||||
@@ -31,11 +31,11 @@
|
||||
|
||||
|
||||
/* Uncomment the following to save code space */
|
||||
//#define REMOVE_AVRPROG_SUPPORT
|
||||
//#define REMOVE_FUSE_AND_LOCK_BIT_SUPPORT
|
||||
//#define REMOVE_BLOCK_SUPPORT
|
||||
//#define REMOVE_EEPROM_BYTE_SUPPORT
|
||||
//#define REMOVE_FLASH_BYTE_SUPPORT
|
||||
/*#define REMOVE_AVRPROG_SUPPORT */
|
||||
/*#define REMOVE_FUSE_AND_LOCK_BIT_SUPPORT */
|
||||
/*#define REMOVE_BLOCK_SUPPORT */
|
||||
/*#define REMOVE_EEPROM_BYTE_SUPPORT */
|
||||
/*#define REMOVE_FLASH_BYTE_SUPPORT */
|
||||
|
||||
/*
|
||||
* GCC doesn't optimize long int arithmetics very clever. As the
|
||||
@@ -47,13 +47,19 @@
|
||||
*/
|
||||
#ifdef LARGE_MEMORY
|
||||
# define ADDR_T unsigned long
|
||||
#else /* !LARGE_MEMORY */
|
||||
#else /* !LARGE_MEMORY */
|
||||
# define ADDR_T unsigned int
|
||||
#endif /* LARGE_MEMORY */
|
||||
|
||||
#ifndef REMOVE_BLOCK_SUPPORT
|
||||
unsigned char BlockLoad(unsigned int size, unsigned char mem, ADDR_T *address);
|
||||
void BlockRead(unsigned int size, unsigned char mem, ADDR_T *address);
|
||||
unsigned char BlockLoad(
|
||||
unsigned int size,
|
||||
unsigned char mem,
|
||||
ADDR_T * address);
|
||||
void BlockRead(
|
||||
unsigned int size,
|
||||
unsigned char mem,
|
||||
ADDR_T * address);
|
||||
|
||||
/* BLOCKSIZE should be chosen so that the following holds: BLOCKSIZE*n = PAGESIZE, where n=1,2,3... */
|
||||
#define BLOCKSIZE PAGESIZE
|
||||
@@ -61,433 +67,398 @@ void BlockRead(unsigned int size, unsigned char mem, ADDR_T *address);
|
||||
#endif /* REMOVE_BLOCK_SUPPORT */
|
||||
|
||||
#ifdef __ICCAVR__
|
||||
__C_task void main(void)
|
||||
__C_task void main(
|
||||
void)
|
||||
#else /* ! __ICCAVR__ */
|
||||
int main(void)
|
||||
int main(
|
||||
void)
|
||||
#endif /* __ICCAVR__ */
|
||||
|
||||
{
|
||||
ADDR_T address;
|
||||
unsigned int temp_int;
|
||||
unsigned char val;
|
||||
|
||||
|
||||
/* Initialization */
|
||||
void (*funcptr)( void ) = 0x0000; // Set up function pointer to RESET vector.
|
||||
PROGPORT |= (1<<PROG_NO); // Enable pull-up on PROG_NO line on PROGPORT.
|
||||
initbootuart(); // Initialize UART.
|
||||
/* Initialization */
|
||||
void (
|
||||
*funcptr) (
|
||||
void) = 0x0000; /* Set up function pointer to RESET vector. */
|
||||
PROGPORT |= (1 << PROG_NO); /* Enable pull-up on PROG_NO line on PROGPORT. */
|
||||
initbootuart(); /* Initialize UART. */
|
||||
|
||||
|
||||
/* Branch to bootloader or application code? */
|
||||
if( !(PROGPIN & (1<<PROG_NO)) ) // If PROGPIN is pulled low, enter programmingmode.
|
||||
{
|
||||
if (!(PROGPIN & (1 << PROG_NO))) { /* If PROGPIN is pulled low, enter programmingmode. */
|
||||
/* Main loop */
|
||||
for(;;)
|
||||
{
|
||||
val=recchar(); // Wait for command character.
|
||||
for (;;) {
|
||||
val = recchar(); /* Wait for command character. */
|
||||
|
||||
// Check autoincrement status.
|
||||
if(val=='a')
|
||||
{
|
||||
sendchar('Y'); // Yes, we do autoincrement.
|
||||
/* Check autoincrement status. */
|
||||
if (val == 'a') {
|
||||
sendchar('Y'); /* Yes, we do autoincrement. */
|
||||
}
|
||||
|
||||
|
||||
// Set address.
|
||||
else if(val=='A') // Set address...
|
||||
{ // NOTE: Flash addresses are given in words, not bytes.
|
||||
address=(recchar()<<8) | recchar(); // Read address high and low byte.
|
||||
sendchar('\r'); // Send OK back.
|
||||
/* Set address. */
|
||||
else if (val == 'A') { /* Set address... *//* NOTE: Flash addresses are given in words, not bytes. */
|
||||
address = (recchar() << 8) | recchar(); /* Read address high and low byte. */
|
||||
sendchar('\r'); /* Send OK back. */
|
||||
}
|
||||
|
||||
|
||||
// Chip erase.
|
||||
else if(val=='e')
|
||||
{
|
||||
for(address = 0; address < APP_END;address += PAGESIZE)
|
||||
{ // NOTE: Here we use address as a byte-address, not word-address, for convenience.
|
||||
_WAIT_FOR_SPM();
|
||||
|
||||
/* Chip erase. */
|
||||
else if (val == 'e') {
|
||||
for (address = 0; address < APP_END; address += PAGESIZE) { /* NOTE: Here we use address as a byte-address, not word-address, for convenience. */
|
||||
_WAIT_FOR_SPM();
|
||||
#ifdef __ICCAVR__
|
||||
#pragma diag_suppress=Pe1053 // Suppress warning for conversion from long-type address to flash ptr.
|
||||
#pragma diag_suppress=Pe1053 /* Suppress warning for conversion from long-type address to flash ptr. */
|
||||
#endif
|
||||
_PAGE_ERASE( address );
|
||||
_PAGE_ERASE(address);
|
||||
#ifdef __ICCAVR__
|
||||
#pragma diag_default=Pe1053 // Back to default.
|
||||
#pragma diag_default=Pe1053 /* Back to default. */
|
||||
#endif
|
||||
}
|
||||
|
||||
sendchar('\r'); // Send OK back.
|
||||
|
||||
sendchar('\r'); /* Send OK back. */
|
||||
}
|
||||
|
||||
#ifndef REMOVE_BLOCK_SUPPORT
|
||||
// Check block load support.
|
||||
else if(val=='b')
|
||||
{
|
||||
sendchar('Y'); // Report block load supported.
|
||||
sendchar((BLOCKSIZE>>8) & 0xFF); // MSB first.
|
||||
sendchar(BLOCKSIZE&0xFF); // Report BLOCKSIZE (bytes).
|
||||
}
|
||||
/* Check block load support. */
|
||||
else if (val == 'b') {
|
||||
sendchar('Y'); /* Report block load supported. */
|
||||
sendchar((BLOCKSIZE >> 8) & 0xFF); /* MSB first. */
|
||||
sendchar(BLOCKSIZE & 0xFF); /* Report BLOCKSIZE (bytes). */
|
||||
}
|
||||
|
||||
|
||||
// Start block load.
|
||||
else if(val=='B')
|
||||
{
|
||||
temp_int = (recchar()<<8) | recchar(); // Get block size.
|
||||
val = recchar(); // Get memtype.
|
||||
sendchar( BlockLoad(temp_int,val,&address) ); // Block load.
|
||||
}
|
||||
|
||||
|
||||
// Start block read.
|
||||
else if(val=='g')
|
||||
{
|
||||
temp_int = (recchar()<<8) | recchar(); // Get block size.
|
||||
val = recchar(); // Get memtype
|
||||
BlockRead(temp_int,val,&address); // Block read
|
||||
}
|
||||
/* Start block load. */
|
||||
else if (val == 'B') {
|
||||
temp_int = (recchar() << 8) | recchar(); /* Get block size. */
|
||||
val = recchar(); /* Get memtype. */
|
||||
sendchar(BlockLoad(temp_int, val, &address)); /* Block load. */
|
||||
}
|
||||
|
||||
|
||||
/* Start block read. */
|
||||
else if (val == 'g') {
|
||||
temp_int = (recchar() << 8) | recchar(); /* Get block size. */
|
||||
val = recchar(); /* Get memtype */
|
||||
BlockRead(temp_int, val, &address); /* Block read */
|
||||
}
|
||||
#endif /* REMOVE_BLOCK_SUPPORT */
|
||||
|
||||
#ifndef REMOVE_FLASH_BYTE_SUPPORT
|
||||
// Read program memory.
|
||||
else if(val=='R')
|
||||
{
|
||||
// Send high byte, then low byte of flash word.
|
||||
_WAIT_FOR_SPM();
|
||||
#ifndef REMOVE_FLASH_BYTE_SUPPORT
|
||||
/* Read program memory. */
|
||||
else if (val == 'R') {
|
||||
/* Send high byte, then low byte of flash word. */
|
||||
_WAIT_FOR_SPM();
|
||||
_ENABLE_RWW_SECTION();
|
||||
#ifdef __ICCAVR__
|
||||
#pragma diag_suppress=Pe1053 // Suppress warning for conversion from long-type address to flash ptr.
|
||||
#pragma diag_suppress=Pe1053 /* Suppress warning for conversion from long-type address to flash ptr. */
|
||||
#endif
|
||||
sendchar( _LOAD_PROGRAM_MEMORY( (address << 1)+1 ) );
|
||||
sendchar( _LOAD_PROGRAM_MEMORY( (address << 1)+0 ) );
|
||||
sendchar(_LOAD_PROGRAM_MEMORY((address << 1) + 1));
|
||||
sendchar(_LOAD_PROGRAM_MEMORY((address << 1) + 0));
|
||||
#ifdef __ICCAVR__
|
||||
#pragma diag_default=Pe1053 // Back to default.
|
||||
#pragma diag_default=Pe1053 /* Back to default. */
|
||||
#endif
|
||||
|
||||
address++; // Auto-advance to next Flash word.
|
||||
address++; /* Auto-advance to next Flash word. */
|
||||
}
|
||||
|
||||
|
||||
// Write program memory, low byte.
|
||||
else if(val=='c')
|
||||
{ // NOTE: Always use this command before sending high byte.
|
||||
temp_int=recchar(); // Get low byte for later _FILL_TEMP_WORD.
|
||||
sendchar('\r'); // Send OK back.
|
||||
|
||||
/* Write program memory, low byte. */
|
||||
else if (val == 'c') { /* NOTE: Always use this command before sending high byte. */
|
||||
temp_int = recchar(); /* Get low byte for later _FILL_TEMP_WORD. */
|
||||
sendchar('\r'); /* Send OK back. */
|
||||
}
|
||||
|
||||
|
||||
// Write program memory, high byte.
|
||||
else if(val=='C')
|
||||
{
|
||||
temp_int |= (recchar()<<8); // Get and insert high byte.
|
||||
|
||||
|
||||
/* Write program memory, high byte. */
|
||||
else if (val == 'C') {
|
||||
temp_int |= (recchar() << 8); /* Get and insert high byte. */
|
||||
_WAIT_FOR_SPM();
|
||||
#ifdef __ICCAVR__
|
||||
#pragma diag_suppress=Pe1053 // Suppress warning for conversion from long-type address to flash ptr.
|
||||
#pragma diag_suppress=Pe1053 /* Suppress warning for conversion from long-type address to flash ptr. */
|
||||
#endif
|
||||
_FILL_TEMP_WORD( (address << 1), temp_int ); // Convert word-address to byte-address and fill.
|
||||
_FILL_TEMP_WORD((address << 1), temp_int); /* Convert word-address to byte-address and fill. */
|
||||
#ifdef __ICCAVR__
|
||||
#pragma diag_default=Pe1053 // Back to default.
|
||||
#pragma diag_default=Pe1053 /* Back to default. */
|
||||
#endif
|
||||
address++; // Auto-advance to next Flash word.
|
||||
sendchar('\r'); // Send OK back.
|
||||
address++; /* Auto-advance to next Flash word. */
|
||||
sendchar('\r'); /* Send OK back. */
|
||||
}
|
||||
|
||||
|
||||
// Write page.
|
||||
else if(val== 'm')
|
||||
{
|
||||
if( address >= (APP_END>>1) ) // Protect bootloader area.
|
||||
{
|
||||
|
||||
|
||||
/* Write page. */
|
||||
else if (val == 'm') {
|
||||
if (address >= (APP_END >> 1)) { /* Protect bootloader area. */
|
||||
sendchar('?');
|
||||
} else
|
||||
{
|
||||
_WAIT_FOR_SPM();
|
||||
} else {
|
||||
_WAIT_FOR_SPM();
|
||||
#ifdef __ICCAVR__
|
||||
#pragma diag_suppress=Pe1053 // Suppress warning for conversion from long-type address to flash ptr.
|
||||
#pragma diag_suppress=Pe1053 /* Suppress warning for conversion from long-type address to flash ptr. */
|
||||
#endif
|
||||
_PAGE_WRITE( address << 1 ); // Convert word-address to byte-address and write.
|
||||
_PAGE_WRITE(address << 1); /* Convert word-address to byte-address and write. */
|
||||
#ifdef __ICCAVR__
|
||||
#pragma diag_default=Pe1053 // Back to default.
|
||||
#pragma diag_default=Pe1053 /* Back to default. */
|
||||
#endif
|
||||
}
|
||||
|
||||
sendchar('\r'); // Send OK back.
|
||||
sendchar('\r'); /* Send OK back. */
|
||||
}
|
||||
#endif /* REMOVE_FLASH_BYTE_SUPPORT */
|
||||
|
||||
#ifndef REMOVE_EEPROM_BYTE_SUPPORT
|
||||
// Write EEPROM memory.
|
||||
else if (val == 'D')
|
||||
{
|
||||
_WAIT_FOR_SPM();
|
||||
EEARL = address; // Setup EEPROM address.
|
||||
/* Write EEPROM memory. */
|
||||
else if (val == 'D') {
|
||||
_WAIT_FOR_SPM();
|
||||
EEARL = address; /* Setup EEPROM address. */
|
||||
EEARH = (address >> 8);
|
||||
EEDR = recchar(); // Get byte.
|
||||
EECR |= (1<<EEMWE); // Write byte.
|
||||
EECR |= (1<<EEWE);
|
||||
while (EECR & (1<<EEWE)) // Wait for write operation to finish.
|
||||
EEDR = recchar(); /* Get byte. */
|
||||
EECR |= (1 << EEMWE); /* Write byte. */
|
||||
EECR |= (1 << EEWE);
|
||||
while (EECR & (1 << EEWE)) /* Wait for write operation to finish. */
|
||||
;
|
||||
|
||||
address++; // Auto-advance to next EEPROM byte.
|
||||
sendchar('\r');// Send OK back.
|
||||
|
||||
address++; /* Auto-advance to next EEPROM byte. */
|
||||
sendchar('\r'); /* Send OK back. */
|
||||
}
|
||||
|
||||
|
||||
// Read EEPROM memory.
|
||||
else if (val == 'd')
|
||||
{
|
||||
EEARL = address; // Setup EEPROM address.
|
||||
|
||||
/* Read EEPROM memory. */
|
||||
else if (val == 'd') {
|
||||
EEARL = address; /* Setup EEPROM address. */
|
||||
EEARH = (address >> 8);
|
||||
EECR |= (1<<EERE); // Read byte...
|
||||
sendchar(EEDR); // ...and send it back.
|
||||
address++; // Auto-advance to next EEPROM byte.
|
||||
EECR |= (1 << EERE); /* Read byte... */
|
||||
sendchar(EEDR); /* ...and send it back. */
|
||||
address++; /* Auto-advance to next EEPROM byte. */
|
||||
}
|
||||
#endif /* REMOVE_EEPROM_BYTE_SUPPORT */
|
||||
|
||||
#ifndef REMOVE_FUSE_AND_LOCK_BIT_SUPPORT
|
||||
// Write lockbits.
|
||||
else if(val=='l')
|
||||
{
|
||||
_WAIT_FOR_SPM();
|
||||
_SET_LOCK_BITS( recchar() ); // Read and set lock bits.
|
||||
sendchar('\r'); // Send OK back.
|
||||
/* Write lockbits. */
|
||||
else if (val == 'l') {
|
||||
_WAIT_FOR_SPM();
|
||||
_SET_LOCK_BITS(recchar()); /* Read and set lock bits. */
|
||||
sendchar('\r'); /* Send OK back. */
|
||||
}
|
||||
|
||||
|
||||
#if defined(_GET_LOCK_BITS)
|
||||
// Read lock bits.
|
||||
else if(val=='r')
|
||||
{
|
||||
_WAIT_FOR_SPM();
|
||||
sendchar( _GET_LOCK_BITS() );
|
||||
/* Read lock bits. */
|
||||
else if (val == 'r') {
|
||||
_WAIT_FOR_SPM();
|
||||
sendchar(_GET_LOCK_BITS());
|
||||
}
|
||||
|
||||
|
||||
// Read fuse bits.
|
||||
else if(val=='F')
|
||||
{
|
||||
_WAIT_FOR_SPM();
|
||||
sendchar( _GET_LOW_FUSES() );
|
||||
/* Read fuse bits. */
|
||||
else if (val == 'F') {
|
||||
_WAIT_FOR_SPM();
|
||||
sendchar(_GET_LOW_FUSES());
|
||||
}
|
||||
|
||||
|
||||
// Read high fuse bits.
|
||||
else if(val=='N')
|
||||
{
|
||||
_WAIT_FOR_SPM();
|
||||
sendchar( _GET_HIGH_FUSES() );
|
||||
/* Read high fuse bits. */
|
||||
else if (val == 'N') {
|
||||
_WAIT_FOR_SPM();
|
||||
sendchar(_GET_HIGH_FUSES());
|
||||
}
|
||||
|
||||
|
||||
// Read extended fuse bits.
|
||||
else if(val=='Q')
|
||||
{
|
||||
_WAIT_FOR_SPM();
|
||||
sendchar( _GET_EXTENDED_FUSES() );
|
||||
/* Read extended fuse bits. */
|
||||
else if (val == 'Q') {
|
||||
_WAIT_FOR_SPM();
|
||||
sendchar(_GET_EXTENDED_FUSES());
|
||||
}
|
||||
#endif /* defined(_GET_LOCK_BITS) */
|
||||
#endif /* REMOVE_FUSE_AND_LOCK_BIT_SUPPORT */
|
||||
|
||||
#ifndef REMOVE_AVRPROG_SUPPORT
|
||||
// Enter and leave programming mode.
|
||||
else if((val=='P')||(val=='L'))
|
||||
{
|
||||
sendchar('\r'); // Nothing special to do, just answer OK.
|
||||
}
|
||||
|
||||
|
||||
// Exit bootloader.
|
||||
else if(val=='E')
|
||||
{
|
||||
_WAIT_FOR_SPM();
|
||||
_ENABLE_RWW_SECTION();
|
||||
sendchar('\r');
|
||||
funcptr(); // Jump to Reset vector 0x0000 in Application Section.
|
||||
#ifndef REMOVE_AVRPROG_SUPPORT
|
||||
/* Enter and leave programming mode. */
|
||||
else if ((val == 'P') || (val == 'L')) {
|
||||
sendchar('\r'); /* Nothing special to do, just answer OK. */
|
||||
}
|
||||
|
||||
|
||||
// Get programmer type.
|
||||
else if (val=='p')
|
||||
{
|
||||
sendchar('S'); // Answer 'SERIAL'.
|
||||
|
||||
/* Exit bootloader. */
|
||||
else if (val == 'E') {
|
||||
_WAIT_FOR_SPM();
|
||||
_ENABLE_RWW_SECTION();
|
||||
sendchar('\r');
|
||||
funcptr(); /* Jump to Reset vector 0x0000 in Application Section. */
|
||||
}
|
||||
|
||||
|
||||
// Return supported device codes.
|
||||
else if(val=='t')
|
||||
{
|
||||
|
||||
|
||||
/* Get programmer type. */
|
||||
else if (val == 'p') {
|
||||
sendchar('S'); /* Answer 'SERIAL'. */
|
||||
}
|
||||
|
||||
|
||||
/* Return supported device codes. */
|
||||
else if (val == 't') {
|
||||
#if PARTCODE+0 > 0
|
||||
sendchar( PARTCODE ); // Supports only this device, of course.
|
||||
sendchar(PARTCODE); /* Supports only this device, of course. */
|
||||
#endif /* PARTCODE */
|
||||
sendchar( 0 ); // Send list terminator.
|
||||
sendchar(0); /* Send list terminator. */
|
||||
}
|
||||
|
||||
|
||||
// Set LED, clear LED and set device type.
|
||||
else if((val=='x')||(val=='y')||(val=='T'))
|
||||
{
|
||||
recchar(); // Ignore the command and it's parameter.
|
||||
sendchar('\r'); // Send OK back.
|
||||
|
||||
|
||||
/* Set LED, clear LED and set device type. */
|
||||
else if ((val == 'x') || (val == 'y') || (val == 'T')) {
|
||||
recchar(); /* Ignore the command and it's parameter. */
|
||||
sendchar('\r'); /* Send OK back. */
|
||||
}
|
||||
#endif /* REMOVE_AVRPROG_SUPPORT */
|
||||
|
||||
// Return programmer identifier.
|
||||
else if(val=='S')
|
||||
{
|
||||
sendchar('A'); // Return 'AVRBOOT'.
|
||||
sendchar('V'); // Software identifier (aka programmer signature) is always 7 characters.
|
||||
|
||||
/* Return programmer identifier. */
|
||||
else if (val == 'S') {
|
||||
sendchar('A'); /* Return 'AVRBOOT'. */
|
||||
sendchar('V'); /* Software identifier (aka programmer signature) is always 7 characters. */
|
||||
sendchar('R');
|
||||
sendchar('B');
|
||||
sendchar('O');
|
||||
sendchar('O');
|
||||
sendchar('T');
|
||||
}
|
||||
|
||||
|
||||
// Return software version.
|
||||
else if(val=='V')
|
||||
{
|
||||
|
||||
|
||||
/* Return software version. */
|
||||
else if (val == 'V') {
|
||||
sendchar('1');
|
||||
sendchar('5');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Return signature bytes.
|
||||
else if(val=='s')
|
||||
{
|
||||
sendchar( SIGNATURE_BYTE_3 );
|
||||
sendchar( SIGNATURE_BYTE_2 );
|
||||
sendchar( SIGNATURE_BYTE_1 );
|
||||
}
|
||||
/* Return signature bytes. */
|
||||
else if (val == 's') {
|
||||
sendchar(SIGNATURE_BYTE_3);
|
||||
sendchar(SIGNATURE_BYTE_2);
|
||||
sendchar(SIGNATURE_BYTE_1);
|
||||
}
|
||||
|
||||
|
||||
// The last command to accept is ESC (synchronization).
|
||||
else if(val!=0x1b) // If not ESC, then it is unrecognized...
|
||||
{
|
||||
/* The last command to accept is ESC (synchronization). */
|
||||
else if (val != 0x1b) { /* If not ESC, then it is unrecognized... */
|
||||
sendchar('?');
|
||||
}
|
||||
} // end: for(;;)
|
||||
}
|
||||
else
|
||||
{
|
||||
_WAIT_FOR_SPM();
|
||||
} /* end: for(;;) */
|
||||
} else {
|
||||
_WAIT_FOR_SPM();
|
||||
_ENABLE_RWW_SECTION();
|
||||
funcptr(); // Jump to Reset vector 0x0000 in Application Section.
|
||||
funcptr(); /* Jump to Reset vector 0x0000 in Application Section. */
|
||||
}
|
||||
} // end: main
|
||||
} /* end: main */
|
||||
|
||||
|
||||
#ifndef REMOVE_BLOCK_SUPPORT
|
||||
unsigned char BlockLoad(unsigned int size, unsigned char mem, ADDR_T *address)
|
||||
unsigned char BlockLoad(
|
||||
unsigned int size,
|
||||
unsigned char mem,
|
||||
ADDR_T * address)
|
||||
{
|
||||
unsigned char buffer[BLOCKSIZE];
|
||||
unsigned int data;
|
||||
ADDR_T tempaddress;
|
||||
|
||||
// EEPROM memory type.
|
||||
if(mem=='E')
|
||||
{
|
||||
|
||||
/* EEPROM memory type. */
|
||||
if (mem == 'E') {
|
||||
/* Fill buffer first, as EEPROM is too slow to copy with UART speed */
|
||||
for(tempaddress=0;tempaddress<size;tempaddress++)
|
||||
for (tempaddress = 0; tempaddress < size; tempaddress++)
|
||||
buffer[tempaddress] = recchar();
|
||||
|
||||
|
||||
/* Then program the EEPROM */
|
||||
_WAIT_FOR_SPM();
|
||||
for( tempaddress=0; tempaddress < size; tempaddress++)
|
||||
{
|
||||
EEARL = *address; // Setup EEPROM address
|
||||
for (tempaddress = 0; tempaddress < size; tempaddress++) {
|
||||
EEARL = *address; /* Setup EEPROM address */
|
||||
EEARH = ((*address) >> 8);
|
||||
EEDR = buffer[tempaddress]; // Get byte.
|
||||
EECR |= (1<<EEMWE); // Write byte.
|
||||
EECR |= (1<<EEWE);
|
||||
while (EECR & (1<<EEWE)) // Wait for write operation to finish.
|
||||
EEDR = buffer[tempaddress]; /* Get byte. */
|
||||
EECR |= (1 << EEMWE); /* Write byte. */
|
||||
EECR |= (1 << EEWE);
|
||||
while (EECR & (1 << EEWE)) /* Wait for write operation to finish. */
|
||||
;
|
||||
|
||||
(*address)++; // Select next EEPROM byte
|
||||
(*address)++; /* Select next EEPROM byte */
|
||||
}
|
||||
|
||||
return '\r'; // Report programming OK
|
||||
}
|
||||
|
||||
// Flash memory type.
|
||||
else if(mem=='F')
|
||||
{ // NOTE: For flash programming, 'address' is given in words.
|
||||
(*address) <<= 1; // Convert address to bytes temporarily.
|
||||
tempaddress = (*address); // Store address in page.
|
||||
|
||||
do
|
||||
{
|
||||
return '\r'; /* Report programming OK */
|
||||
}
|
||||
|
||||
/* Flash memory type. */
|
||||
else if (mem == 'F') { /* NOTE: For flash programming, 'address' is given in words. */
|
||||
(*address) <<= 1; /* Convert address to bytes temporarily. */
|
||||
tempaddress = (*address); /* Store address in page. */
|
||||
|
||||
do {
|
||||
data = recchar();
|
||||
data |= (recchar() << 8);
|
||||
#ifdef __ICCAVR__
|
||||
#pragma diag_suppress=Pe1053 // Suppress warning for conversion from long-type address to flash ptr.
|
||||
#pragma diag_suppress=Pe1053 /* Suppress warning for conversion from long-type address to flash ptr. */
|
||||
#endif
|
||||
_FILL_TEMP_WORD(*address,data);
|
||||
_FILL_TEMP_WORD(*address, data);
|
||||
#ifdef __ICCAVR__
|
||||
#pragma diag_default=Pe1053 // Back to default.
|
||||
#pragma diag_default=Pe1053 /* Back to default. */
|
||||
#endif
|
||||
(*address)+=2; // Select next word in memory.
|
||||
size -= 2; // Reduce number of bytes to write by two.
|
||||
} while(size); // Loop until all bytes written.
|
||||
(*address) += 2; /* Select next word in memory. */
|
||||
size -= 2; /* Reduce number of bytes to write by two. */
|
||||
} while (size); /* Loop until all bytes written. */
|
||||
|
||||
#ifdef __ICCAVR__
|
||||
#pragma diag_suppress=Pe1053 // Suppress warning for conversion from long-type address to flash ptr.
|
||||
#pragma diag_suppress=Pe1053 /* Suppress warning for conversion from long-type address to flash ptr. */
|
||||
#endif
|
||||
_PAGE_WRITE(tempaddress);
|
||||
_PAGE_WRITE(tempaddress);
|
||||
#ifdef __ICCAVR__
|
||||
#pragma diag_default=Pe1053 // Back to default.
|
||||
#pragma diag_default=Pe1053 /* Back to default. */
|
||||
#endif
|
||||
_WAIT_FOR_SPM();
|
||||
_ENABLE_RWW_SECTION();
|
||||
_WAIT_FOR_SPM();
|
||||
_ENABLE_RWW_SECTION();
|
||||
|
||||
(*address) >>= 1; // Convert address back to Flash words again.
|
||||
return '\r'; // Report programming OK
|
||||
(*address) >>= 1; /* Convert address back to Flash words again. */
|
||||
return '\r'; /* Report programming OK */
|
||||
}
|
||||
|
||||
// Invalid memory type?
|
||||
else
|
||||
{
|
||||
|
||||
/* Invalid memory type? */
|
||||
else {
|
||||
return '?';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void BlockRead(unsigned int size, unsigned char mem, ADDR_T *address)
|
||||
void BlockRead(
|
||||
unsigned int size,
|
||||
unsigned char mem,
|
||||
ADDR_T * address)
|
||||
{
|
||||
// EEPROM memory type.
|
||||
if (mem=='E') // Read EEPROM
|
||||
{
|
||||
do
|
||||
{
|
||||
EEARL = *address; // Setup EEPROM address
|
||||
/* EEPROM memory type. */
|
||||
if (mem == 'E') { /* Read EEPROM */
|
||||
do {
|
||||
EEARL = *address; /* Setup EEPROM address */
|
||||
EEARH = ((*address) >> 8);
|
||||
(*address)++; // Select next EEPROM byte
|
||||
EECR |= (1<<EERE); // Read EEPROM
|
||||
sendchar(EEDR); // Transmit EEPROM dat ato PC
|
||||
(*address)++; /* Select next EEPROM byte */
|
||||
EECR |= (1 << EERE); /* Read EEPROM */
|
||||
sendchar(EEDR); /* Transmit EEPROM dat ato PC */
|
||||
|
||||
size--; // Decrease number of bytes to read
|
||||
} while (size); // Repeat until all block has been read
|
||||
size--; /* Decrease number of bytes to read */
|
||||
} while (size); /* Repeat until all block has been read */
|
||||
}
|
||||
|
||||
// Flash memory type.
|
||||
else if(mem=='F')
|
||||
{
|
||||
(*address) <<= 1; // Convert address to bytes temporarily.
|
||||
|
||||
do
|
||||
{
|
||||
#ifdef __ICCAVR__
|
||||
#pragma diag_suppress=Pe1053 // Suppress warning for conversion from long-type address to flash ptr.
|
||||
#endif
|
||||
sendchar( _LOAD_PROGRAM_MEMORY(*address) );
|
||||
sendchar( _LOAD_PROGRAM_MEMORY((*address)+1) );
|
||||
#ifdef __ICCAVR__
|
||||
#pragma diag_default=Pe1053 // Back to default.
|
||||
#endif
|
||||
(*address) += 2; // Select next word in memory.
|
||||
size -= 2; // Subtract two bytes from number of bytes to read
|
||||
} while (size); // Repeat until all block has been read
|
||||
|
||||
(*address) >>= 1; // Convert address back to Flash words again.
|
||||
/* Flash memory type. */
|
||||
else if (mem == 'F') {
|
||||
(*address) <<= 1; /* Convert address to bytes temporarily. */
|
||||
|
||||
do {
|
||||
#ifdef __ICCAVR__
|
||||
#pragma diag_suppress=Pe1053 /* Suppress warning for conversion from long-type address to flash ptr. */
|
||||
#endif
|
||||
sendchar(_LOAD_PROGRAM_MEMORY(*address));
|
||||
sendchar(_LOAD_PROGRAM_MEMORY((*address) + 1));
|
||||
#ifdef __ICCAVR__
|
||||
#pragma diag_default=Pe1053 /* Back to default. */
|
||||
#endif
|
||||
(*address) += 2; /* Select next word in memory. */
|
||||
size -= 2; /* Subtract two bytes from number of bytes to read */
|
||||
} while (size); /* Repeat until all block has been read */
|
||||
|
||||
(*address) >>= 1; /* Convert address back to Flash words again. */
|
||||
}
|
||||
}
|
||||
#endif /* REMOVE_BLOCK_SUPPORT */
|
||||
|
||||
@@ -19,24 +19,26 @@
|
||||
#include "defines.h"
|
||||
|
||||
|
||||
void initbootuart(void)
|
||||
void initbootuart(
|
||||
void)
|
||||
{
|
||||
BAUD_RATE_LOW_REG = BRREG_VALUE;
|
||||
UART_CONTROL_REG = (1 << ENABLE_RECEIVER_BIT) |
|
||||
(1 << ENABLE_TRANSMITTER_BIT); // enable receive and transmit
|
||||
BAUD_RATE_LOW_REG = BRREG_VALUE;
|
||||
UART_CONTROL_REG = (1 << ENABLE_RECEIVER_BIT) | (1 << ENABLE_TRANSMITTER_BIT); /* enable receive and transmit */
|
||||
}
|
||||
|
||||
|
||||
void sendchar(unsigned char c)
|
||||
void sendchar(
|
||||
unsigned char c)
|
||||
{
|
||||
UART_DATA_REG = c; // prepare transmission
|
||||
while (!(UART_STATUS_REG & (1 << TRANSMIT_COMPLETE_BIT)));// wait until byte sendt
|
||||
UART_STATUS_REG |= (1 << TRANSMIT_COMPLETE_BIT); // delete TXCflag
|
||||
UART_DATA_REG = c; /* prepare transmission */
|
||||
while (!(UART_STATUS_REG & (1 << TRANSMIT_COMPLETE_BIT))); /* wait until byte sendt */
|
||||
UART_STATUS_REG |= (1 << TRANSMIT_COMPLETE_BIT); /* delete TXCflag */
|
||||
}
|
||||
|
||||
|
||||
unsigned char recchar(void)
|
||||
unsigned char recchar(
|
||||
void)
|
||||
{
|
||||
while(!(UART_STATUS_REG & (1 << RECEIVE_COMPLETE_BIT))); // wait for data
|
||||
return UART_DATA_REG;
|
||||
while (!(UART_STATUS_REG & (1 << RECEIVE_COMPLETE_BIT))); /* wait for data */
|
||||
return UART_DATA_REG;
|
||||
}
|
||||
|
||||
@@ -17,6 +17,9 @@
|
||||
* Description : Header file for serial.c
|
||||
****************************************************************************/
|
||||
|
||||
void initbootuart( void );
|
||||
void sendchar( unsigned char );
|
||||
unsigned char recchar( void );
|
||||
void initbootuart(
|
||||
void);
|
||||
void sendchar(
|
||||
unsigned char);
|
||||
unsigned char recchar(
|
||||
void);
|
||||
|
||||
Reference in New Issue
Block a user