Autopilot-CVS: onboard/rev2 loader.c,2.3,2.4
Status: Alpha
Brought to you by:
tramm
|
From: Trammell H. <tr...@us...> - 2003-02-27 05:04:51
|
Update of /cvsroot/autopilot/onboard/rev2
In directory sc8-pr-cvs1:/tmp/cvs-serv14645
Modified Files:
loader.c
Log Message:
Shaved three hundred bytes off the boot loader so that avr-gcc 3.2 will fit it into a 1 kB boot sector. The code is harder to read now due to lots of gotos
Index: loader.c
===================================================================
RCS file: /cvsroot/autopilot/onboard/rev2/loader.c,v
retrieving revision 2.3
retrieving revision 2.4
diff -u -d -r2.3 -r2.4
--- loader.c 22 Oct 2002 19:43:46 -0000 2.3
+++ loader.c 27 Feb 2003 05:04:48 -0000 2.4
@@ -17,6 +17,7 @@
* ENABLE_EEPROM Allow programming the EEPROM
* ENABLE_READ Allow the programmer to read back the code
* ENABLE_FUSE_BITS Allow the programmer to set the fuse bits
+ * ENABLE_BUTTON Allow a button press on boot to start the loader
*
* With all of them turned off, the program just barely fits in a
* 1k boot sector.
@@ -74,11 +75,23 @@
*
*/
+#ifdef NEW_GCC
+#include <avr/io.h>
+#include <avr/signal.h>
+#else
#include <io.h>
#include <sig-avr.h>
+#endif
+
+#include <inttypes.h>
+
+#ifdef ENABLE_BUTTON
#include "button.h"
+#endif
+
#include "memory.h"
+#define CLOCK 16
#define PARTCODE 0x66
#define sig_byte1 0x1E
#define sig_byte2 0x94
@@ -145,6 +158,7 @@
sbi( UCSRA, TXC );
}
+#ifdef ENABLE_PUTS
static void
_puts(
const prog_char * s
@@ -156,6 +170,7 @@
}
#define puts( s ) _puts( PSTR( s ) )
+#endif
static unsigned char
getc( void )
@@ -172,7 +187,13 @@
static inline void
uart_init( void )
{
+#if CLOCK == 16
+ outp( 25, UBRRL );
+#elif CLOCK == 8
outp( 12, UBRR );
+#else
+ #error "Unsupported clock!"
+#endif
sbi( UCSRB, RXEN );
sbi( UCSRB, TXEN );
}
@@ -198,6 +219,7 @@
#ifdef ENABLE_READ
unsigned int intval;
#endif
+ unsigned char output;
static unsigned int address;
static unsigned int data;
@@ -205,38 +227,33 @@
switch(c)
{
- case 'A': /* Write address (MSB first) */
- address = getc();
- address = (address<<8)|getc();
+ case 'A': /* Write address (MSB first) in word size increments*/
+ {
+ uint16_t high = getc();
+ address = ( (high<<8) | getc() ) << 1;
- /* convert from word address to byte address */
- address <<= 1;
- putc( '\r' );
- break;
+ goto new_line;
+ }
case 'c': /* Write program memory, low byte */
ldata = getc();
- putc('\r');
- break;
+ goto new_line;
case 'C': /* Write program memory, high byte */
data = ldata | ( getc() << 8 );
fill_temp_buffer( data, address );
address += 2;
- putc('\r');
- break;
+ goto new_line;
case 'e': /* Chip erase of application section */
for( address=0; address < APP_END; address += PAGESIZE)
write_page( address, (1<<PGERS) + (1<<SPMEN) );
-
- putc('\r');
- break;
+ goto new_line;
case 'a': /* Auto increment */
case 'n': /* Query multiword-write */
- putc( 'Y' );
- break;
+ output = 'Y';
+ goto out_char;
case 'M': /* Write many words at once */
{
@@ -277,31 +294,26 @@
putc( (startaddr >> 0 ) & 0xFF );
putc( (address >> 8 ) & 0xFF );
putc( (address >> 0 ) & 0xFF );
- putc( '\r' );
-
- break;
+ goto new_line;
}
#ifdef ENABLE_FUSE_BITS
case 'l': /* Write lockbits */
write_lock_bits( getc() );
- putc('\r');
- break;
+ goto new_line;
#endif
case 'm': /* Write page: Perform page write */
write_page( address, (1<<PGWRT) + (1<<SPMEN) );
- putc('\r');
- break;
+ // Fall through to goto new_line
case 'P': /* Enter programming mode */
case 'L': /* ??? */
- putc('\r');
- break;
+ goto new_line;
case 'p': /* ??? */
- putc('S');
- break;
+ output = 'S';
+ goto out_char;
#ifdef ENABLE_READ
case 'R': /* Read program memory */
@@ -322,8 +334,7 @@
sbi( EECR, EEMWE );
while( bit_is_set( EECR, EEWE ) )
;
- putc('\r');
- break;
+ goto new_line;
case 'd': /* Read from EEPROM? */
__outw( address, EEARL );
@@ -352,43 +363,58 @@
putc( 0x00 );
break;
+
case 'x': /* ignored??? */
case 'y': /* ignored??? */
case 'T': /* ignored??? */
getc();
- putc( '\r' );
- break;
+ goto new_line;
case 'S': /* Return software identifier */
+ {
+#ifdef ENABLE_PUTS
puts( "AVRBOOT" );
+#else
+ const prog_char *s = PSTR( "AVRBOOT" );
+ while( (c = PRG_RDB( s++ )) )
+ putc( c );
+#endif
break;
+ }
case 'V': /* Return software version */
- puts( "24" );
- break;
+ putc( '2' );
+ output = '4';
+ goto out_char;
case 'v': /* Return hardware version */
- puts( "10" );
- break;
+ putc( '1' );
+ output = '0';
+ goto out_char;
case 's': /* Return signature byte */
putc( sig_byte3 );
putc( sig_byte2 );
- putc( sig_byte1 );
- break;
+ output = sig_byte1;
+ goto out_char;
case 'Z': /* Start application (never returns) */
run_user();
break;
- /* Escape */
- case 0x1b :
- break;
default:
- putc( '?' );
- break;
+ output = '?';
+ goto out_char;
}
+
+ return;
+
+new_line:
+ output = '\r';
+out_char:
+ putc( output );
+ return;
}
@@ -398,10 +424,14 @@
uint16_t i;
uint8_t flash = 0;
+#ifdef ENABLE_BUTTON
button_init();
+#endif
+
uart_init();
- puts( ">> " );
+ putc( '>' );
+ putc( ' ' );
/*
* They get a short while to let us know what they want to do.
@@ -415,11 +445,13 @@
{
uint16_t j;
+#ifdef ENABLE_BUTTON
if( !button_state( 0 ) )
{
flash = 1;
break;
}
+#endif
if( bit_is_set( UCSRA, RXC ) && inp(UDR) == 27 )
{
|