AP_HAL_AVR: implement reboot in scheduler

* still need to fix system io register inits to do it like bootloader would
This commit is contained in:
Pat Hickey 2012-12-04 15:52:50 -08:00 committed by Andrew Tridgell
parent 592d32ba47
commit 6e45ce12b2
2 changed files with 22 additions and 3 deletions

View File

@ -1,14 +1,16 @@
#include <avr/io.h>
#include <avr/interrupt.h>
#include "HAL_AVR.h" #include "HAL_AVR.h"
#include "Scheduler.h" #include "Scheduler.h"
using namespace AP_HAL_AVR; using namespace AP_HAL_AVR;
#include <avr/io.h>
#include <avr/interrupt.h>
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit)) #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit)) #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
extern const AP_HAL::HAL& hal;
static volatile uint32_t timer0_overflow_count = 0; static volatile uint32_t timer0_overflow_count = 0;
static volatile uint32_t timer0_millis = 0; static volatile uint32_t timer0_millis = 0;
static uint8_t timer0_fract = 0; static uint8_t timer0_fract = 0;
@ -335,3 +337,19 @@ void AVRScheduler::end_atomic() {
sei(); sei();
} }
} }
void AVRScheduler::reboot() {
hal.uartA->println_P(PSTR("GOING DOWN FOR A REBOOT\r\n"));
hal.scheduler->delay(100);
cli();
/* Making a null pointer call will cause all AVRs to reboot
* but they may not come back alive properly - we need to setup
* the IO the way the bootloader would.
* pch will go back and fix this.
*/
void (*fn)(void) = NULL;
fn();
for(;;);
}

View File

@ -27,6 +27,7 @@ public:
void resume_timer_procs(); void resume_timer_procs();
void begin_atomic(); void begin_atomic();
void end_atomic(); void end_atomic();
void reboot();
private: private:
/* Implementation specific methods: */ /* Implementation specific methods: */