Plane: allow reboot on APM1, and add reboot to main CLI menu

This commit is contained in:
Andrew Tridgell 2012-11-24 18:14:26 +11:00
parent 3783d0b6de
commit e5e6131085
2 changed files with 19 additions and 8 deletions

View File

@ -1117,10 +1117,8 @@ void GCS_MAVLINK::handleMessage(mavlink_message_t* msg)
case MAV_CMD_PREFLIGHT_REBOOT_SHUTDOWN: case MAV_CMD_PREFLIGHT_REBOOT_SHUTDOWN:
if (packet.param1 == 1) { if (packet.param1 == 1) {
#if CONFIG_APM_HARDWARE == APM_HARDWARE_APM2
reboot_apm(); reboot_apm();
result = MAV_RESULT_ACCEPTED; result = MAV_RESULT_ACCEPTED;
#endif
} }
break; break;

View File

@ -12,6 +12,7 @@
static int8_t process_logs(uint8_t argc, const Menu::arg *argv); // in Log.pde static int8_t process_logs(uint8_t argc, const Menu::arg *argv); // in Log.pde
static int8_t setup_mode(uint8_t argc, const Menu::arg *argv); // in setup.pde static int8_t setup_mode(uint8_t argc, const Menu::arg *argv); // in setup.pde
static int8_t test_mode(uint8_t argc, const Menu::arg *argv); // in test.cpp static int8_t test_mode(uint8_t argc, const Menu::arg *argv); // in test.cpp
static int8_t reboot_board(uint8_t argc, const Menu::arg *argv);
// This is the help function // This is the help function
// PSTR is an AVR macro to read strings from flash memory // PSTR is an AVR macro to read strings from flash memory
@ -22,8 +23,7 @@ static int8_t main_menu_help(uint8_t argc, const Menu::arg *argv)
" logs log readback/setup mode\n" " logs log readback/setup mode\n"
" setup setup mode\n" " setup setup mode\n"
" test test mode\n" " test test mode\n"
"\n" " reboot reboot to flight mode\n"
"Move the slide switch and reset to FLY.\n"
"\n")); "\n"));
return(0); return(0);
} }
@ -35,12 +35,19 @@ static const struct Menu::command main_menu_commands[] PROGMEM = {
{"logs", process_logs}, {"logs", process_logs},
{"setup", setup_mode}, {"setup", setup_mode},
{"test", test_mode}, {"test", test_mode},
{"reboot", reboot_board},
{"help", main_menu_help}, {"help", main_menu_help},
}; };
// Create the top-level menu object. // Create the top-level menu object.
MENU(main_menu, THISFIRMWARE, main_menu_commands); MENU(main_menu, THISFIRMWARE, main_menu_commands);
static int8_t reboot_board(uint8_t argc, const Menu::arg *argv)
{
reboot_apm();
return 0;
}
// the user wants the CLI. It never exits // the user wants the CLI. It never exits
static void run_cli(FastSerial *port) static void run_cli(FastSerial *port)
{ {
@ -556,21 +563,27 @@ uint16_t board_voltage(void)
} }
#if CONFIG_APM_HARDWARE == APM_HARDWARE_APM2
/* /*
force a software reset of the APM force a software reset of the APM
*/ */
static void reboot_apm(void) static void reboot_apm(void)
{ {
cliSerial->println_P(PSTR("REBOOTING")); cliSerial->printf_P(PSTR("REBOOTING\n"));
delay(100); delay(100); // let serial flush
// see http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1250663814/ // see http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1250663814/
// for the method // for the method
#if CONFIG_APM_HARDWARE == APM_HARDWARE_APM2
// this relies on the bootloader resetting the watchdog, which
// APM1 doesn't do
cli(); cli();
wdt_enable(WDTO_15MS); wdt_enable(WDTO_15MS);
#else
// this works on APM1
void (*fn)(void) = NULL;
fn();
#endif
while (1); while (1);
} }
#endif
static void static void