Browse Source

Revert most changes from optiboot (only keep power-on signal)
Add watchdog routines in app (now required)

k4be 2 years ago
parent
commit
cb3921513d
3 changed files with 24 additions and 31 deletions
  1. 2 2
      optiboot/Makefile
  2. 4 16
      optiboot/optiboot.c
  3. 18 13
      soft/main.c

+ 2 - 2
optiboot/Makefile

@@ -62,7 +62,7 @@ export
 MCU_TARGET = atmega644p
 BIGBOOT = 0
 BOOT_ON_POR = 1
-APP_ON_EXTR = 0
+#APP_ON_EXTR = 0
 TIMEOUT = 4
 UART = 1
 SINGLESPEED = 0
@@ -72,7 +72,7 @@ AVR_FREQ = 7372800L
 LED = A6
 LED_START_ON = 1
 LED_START_FLASHES = 0
-LDSECTIONS  = -Wl,-Tlink_optiboot.ld -Wl,-section-start=.manualcall=0x7ffa
+LDSECTIONS  = -Wl,-Tlink_optiboot.ld
 all: atmega644p
 
 # Build environments

+ 4 - 16
optiboot/optiboot.c

@@ -706,7 +706,7 @@ void pre_main(void) {
 
 
 /* main program starts here */
-void bootloader(unsigned char check_reset) {
+int main(void) {
   uint8_t ch;
 
   /*
@@ -786,7 +786,7 @@ void bootloader(unsigned char check_reset) {
   ch = MCUSR;
 
   // Skip all logic and run bootloader if MCUSR is cleared (application request)
-  if (check_reset && ch != 0) {
+  if (ch != 0) {
     /*
      * To run the boot loader, External Reset Flag must be set.
      * If not, we could make shortcut and jump directly to application code.
@@ -902,6 +902,7 @@ void bootloader(unsigned char check_reset) {
   /* Set LED pin as output */
   LED_DDR |= _BV(LED);
 #endif
+
   /* hold POWER_ON (GPStracker) */
   DDRA |= _BV(PA3);
   PORTA |= _BV(PA3);
@@ -927,12 +928,7 @@ void bootloader(unsigned char check_reset) {
     /* get character from UART */
     ch = getch();
 
-//	putch(ch);
-	/*continue;*/
-    if (ch == STK_GET_SYNC) {
-      verifySpace();
-    }
-    else if (ch == STK_GET_PARAMETER) {
+    if (ch == STK_GET_PARAMETER) {
       unsigned char which = getch();
       verifySpace();
       /*
@@ -1187,14 +1183,6 @@ void bootloader(unsigned char check_reset) {
   }
 }
 
-int main(void) {
-	bootloader(1);
-}
-
-__attribute__((section(".manualcall"))) void manual_call(void) {
-	bootloader(0);
-}
-
 void putch(char ch) {
 #if (SOFT_UART == 0)
   // Hardware UARTs.

+ 18 - 13
soft/main.c

@@ -39,17 +39,18 @@ time_t utc;					/* current time */
 struct location_s location;
 
 void start_bootloader(void) {
-    typedef void (*do_reboot_t)(void);
-    const do_reboot_t do_reboot = (do_reboot_t)(0x7ffa >> 1);
-
-    cli();
-    LCD_Clear();
-    LCD_GoTo(0,0);
-    LCD_WriteTextP(PSTR("Aktualizacja"));
-    LCD_GoTo(8,1);
-    LCD_WriteTextP(PSTR("softu..."));
-    TCCR0A = TCCR1A = TCCR2A = 0; // make sure interrupts are off and timers are reset.
-    do_reboot();
+	typedef void (*do_reboot_t)(void);
+	const do_reboot_t do_reboot = (do_reboot_t)((FLASHEND - 1023) >> 1);
+	cli();
+	LCD_Clear();
+	LCD_GoTo(0,0);
+	LCD_WriteTextP(PSTR("Aktualizacja"));
+	LCD_GoTo(8,1);
+	LCD_WriteTextP(PSTR("softu..."));
+	TCCR0A = TCCR1A = TCCR2A = 0; // make sure interrupts are off and timers are reset.
+	do_reboot();
+	wdt_enable(WDTO_15MS);
+	while(1);
 }
 
 /*---------------------------------------------------------*/
@@ -101,9 +102,9 @@ ISR(TIMER1_COMPA_vect)
 	}
 	
 	if (uart1_test() && uart1_get() == '0' && uart1_get() == ' '){
-	//if (!(PIND & _BV(PD5))) {
 		LEDB_ON();
 		start_bootloader();
+		LEDR_ON();
 	}
 }
 
@@ -179,6 +180,7 @@ UINT get_line (		/* 0:Brownout or timeout, >0: Number of bytes received. */
 	set_timer(recv_timeout, 1000);
 
 	for (;;) {
+		wdt_reset();
 		if (FLAGS & (F_LVD | F_POWEROFF))
 			return 0;	/* A brownout is detected */
 		if (timer_expired(recv_timeout))
@@ -400,6 +402,8 @@ void log_put(char c){
 static
 void ioinit (void)
 {
+	wdt_enable(WDTO_4S);
+    MCUSR = 0;
 	POWER_ON_DDR |= POWER_ON;
 	PORTA |= POWER_ON;
 	
@@ -515,9 +519,9 @@ int main (void)
 	xputs_P(PSTR("STARTUP\r\n"));
 	LCD_GoTo(0,0);
 	LCD_WriteTextP(PSTR("Uruchamianie... "));
-	_delay_ms(3000);
 	
 	for (;;) {
+		wdt_reset();
 		if (FLAGS & (F_POWEROFF | F_LVD)) {
 			xputs_P(PSTR("POWEROFF\r\n"));
 			LCD_GoTo(0,0);
@@ -591,6 +595,7 @@ int main (void)
 //		xfprintf(uart0_put, PSTR("$PSRF106,21*0F\r\n"));	/* Send initialization command (depends on the receiver) */
 
 		for (;;) { /* main loop */
+			wdt_reset();
 			battery_state_display();
 			gettemp();