diff --git a/Makefile b/Makefile index e537f07..c5fc062 100644 --- a/Makefile +++ b/Makefile @@ -4,9 +4,13 @@ STRIP=avr-strip SIZE=avr-size AVRDUDE=avrdude -CPPFLAGS += -mmcu=atmega8 -DF_CPU=8000000UL -CFLAGS += -std=gnu99 -Os -g -Wall -W -LDFLAGS += $(CFLAGS) -nostdlib -Wl,--section-start=.text=0x1E00 +#CPPFLAGS += -mmcu=atmega8 -DF_CPU=8000000UL +#CFLAGS += -std=gnu99 -Os -g -Wall -W +#LDFLAGS += $(CFLAGS) -nostdlib -Wl,--section-start=.text=0x1E00 +CPPFLAGS += -mmcu=atmega169 -DF_CPU=8000000UL +CFLAGS += -std=gnu99 -Os -g -Wall -W -mmcu=atmega169 +LDFLAGS += $(CFLAGS) -nostdlib -Wl,--section-start=.text=0x3C00 + all: zbusloader.hex diff --git a/avr_init.S b/avr_init.S index aa9fcb5..fa23b96 100644 --- a/avr_init.S +++ b/avr_init.S @@ -46,9 +46,11 @@ avr_init: ;; timer1 overflow vector ldi r16, _BV (IVCE) - out GICR, r16 ; enable change reset vector + ;;out GICR, r16 ; enable change reset vector + out MCUCR, r16 ; enable change reset vector - out GICR, r1 ; change reset vector to application + ;;out GICR, r1 ; change reset vector to application + out MCUCR, r1 ; change reset vector to application ;; jump to application reset vector mov r30, r1 diff --git a/contrib/zbusloader b/contrib/zbusloader index 34554bc..f72a8ef 100755 --- a/contrib/zbusloader +++ b/contrib/zbusloader @@ -4,7 +4,8 @@ import sys import binascii import optparse -pagesize = 64 # suitable for atmega8 +#pagesize = 64 # suitable for atmega8 +pagesize = 128 # suitable for atmega8 parser = optparse.OptionParser() @@ -55,7 +56,6 @@ def crc_update (crc, data): crc = crc >> 1 data = data >> 1 - return crc def crc_calc(data): @@ -63,10 +63,8 @@ def crc_calc(data): for i in range (pagesize): crc = crc_update (crc, ord (data[i])) - return crc - ############################################################################## chunkno = 0 @@ -116,6 +114,8 @@ while 1: try: reply = s.recv (2) + except KeyboardInterrupt: + sys.exit(0) except: reply = "" diff --git a/pinconfig.h b/pinconfig.h index 89df710..9ea57cc 100644 --- a/pinconfig.h +++ b/pinconfig.h @@ -19,14 +19,15 @@ #ifndef PINCONFIG_H #define PINCONFIG_H -#define ZBUS_TX_DDR DDRD -#define ZBUS_TX_PORT PORTD -#define ZBUS_TX_PIN 2 +#define ZBUS_TX_DDR DDRE +#define ZBUS_TX_PORT PORTE +#define ZBUS_TX_PIN 4 /* If you don't want to have status LEDs, simply comment out these */ -#define STATUS_LED_PORT PORTB -#define STATUS_LED_DDR DDRB -#define STATUS_LED_TX PB6 -#define STATUS_LED_RX PB7 +//#define STATUS_LED_PORT PORTB +//#define STATUS_LED_DDR DDRB +//#define STATUS_LED_TX PB6 +//#define STATUS_LED_RX PB7 #endif + diff --git a/zbusloader.c b/zbusloader.c index 79c0b0c..e2531b5 100644 --- a/zbusloader.c +++ b/zbusloader.c @@ -17,6 +17,12 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +/* Fuses: Extended 0xFF + * High 0x9A + * Low 0xFF + *http://frank.circleofcurrent.com/fusecalc/fusecalc.php?chip=atmega169&LOW=FF&HIGH=9A&EXTENDED=FF&LOCKBIT=FF + */ + #include #include #include @@ -26,6 +32,13 @@ #include "pinconfig.h" +#define HR20 + +#ifdef HR20 + #include "../ethersex/pinning.c" + #include "../ethersex/hardware/lcd/hr20.h" +#endif + #define noinline __attribute__((noinline)) #define naked __attribute__((naked)) @@ -36,8 +49,10 @@ unsigned char zbusloader_tx_buf[2]; #define MAGIC_FLASH_PAGE 0x23 #define MAGIC_LAUNCH_APP 0x42 -#define ZBUS_UBRR 25 +#define ZBUS_UBRR 12 +uint8_t TXLine ; +uint8_t RXLine ; static void timer_init (void) @@ -45,31 +60,78 @@ timer_init (void) /* select clk/256 prescaler, at 8 MHz this means 31250 ticks per seconds, i.e. total timeout of 2.09 seconds. */ - TCCR1B = _BV (CS12); + TCCR1B = _BV (CS12); // TCCR1B(CS12) = 1 /* enable overflow interrupt of Timer 1 */ - TIMSK = _BV (TOIE1); +#ifdef HR20 + TIMSK1 = _BV (TOIE1); // TIMSK1(TOIE1) = 1 +#else + TIMSK = _BV (TOIE1); // TIMSK(TOIE1) = 1 +#endif sei (); } +#define USE_2 + +static void uart_xxx(void) { + #define BAUD 76800 + #include + UBRRH = UBRRH_VALUE; + UBRRL = UBRRL_VALUE; + #if USE_2X + UCSRA |= (1 << U2X); + #else + UCSRA &= ~(1 << U2X); + #endif +} + void zbus_init(void) { /* set baud rate */ - UBRRH = ZBUS_UBRR >> 8; - UBRRL = ZBUS_UBRR; + //UBRRH = ZBUS_UBRR >> 8; + //UBRRL = ZBUS_UBRR; + uart_xxx(); ZBUS_TX_DDR |= _BV(ZBUS_TX_PIN); ZBUS_TX_PORT &= ~_BV(ZBUS_TX_PIN); /* set mode: 8 bits, 1 stop, no parity, asynchronous usart and Set URSEL so we write UCSRC and not UBRRH */ - UCSRC = _BV(UCSZ0) | _BV(UCSZ1) | _BV(URSEL); + //UCSRC = _BV(UCSZ0) | _BV(UCSZ1) | _BV(URSEL); + UCSRC = _BV(UCSZ0) | _BV(UCSZ1); /* Enable the RX interrupt and receiver and transmitter */ UCSRB |= _BV(TXEN) | _BV(RXEN); } +#ifdef HR20 + void hr20_lcd_init (void) { + LCDCCR |= 15 ; + LCDCRB = (1<= 41 ) { RXLine = 4 ; }; + LCD_SEG_SET ( RXLine / 4 ); + } + + void tx_bar(void) { + LCD_SEG_CLEAR ( TXLine / 4 ); + TXLine ++ ; + if ( TXLine >= 81 ) { TXLine = 44 ; }; + LCD_SEG_SET ( TXLine / 4 ); + } +#endif static void flash_page (void) @@ -124,6 +186,9 @@ zbusloader_rx () #ifdef STATUS_LED_RX STATUS_LED_PORT |= _BV (STATUS_LED_RX); #endif +#ifdef HR20 + rx_bar(); +#endif } else if (current == '1') break; @@ -159,6 +224,9 @@ zbusloader_tx_reply(void) #ifdef STATUS_LED_TX STATUS_LED_PORT |= _BV (STATUS_LED_TX); #endif +#ifdef HR20 + tx_bar(); +#endif ZBUS_TX_PORT |= _BV(ZBUS_TX_PIN); /* Start Conditon */ zbus_send_byte('\\'); @@ -215,6 +283,9 @@ zbusloader_main (void) { timer_init (); zbus_init(); +#ifdef HR20 + hr20_lcd_init(); +#endif UCSRA |= _BV(TXC); #ifdef STATUS_LED_RX STATUS_LED_DDR |= _BV (STATUS_LED_RX); @@ -259,6 +330,8 @@ zbusloader_main (void) /* leave here, thusly jump into application now */ __asm volatile ("ret"); +#ifdef STATUS_LED_TX STATUS_LED_PORT |= _BV (STATUS_LED_TX); +#endif }