Refactoring of startup code, mainly dealing with detection of unexpec… (#4275)

* Refactoring of startup code, mainly dealing with detection of unexpected restart/shutdown

* Added g_FATFS_Obj initialization [Horus]

* Fix normal startup

* Use g_eeGeneral.unexpectedShutdown only on radios that have PWRMANAGE defined
Fixes for radios that don't have power control.
Other fixes

* CLI test for new()

* [Horus] Reboot protection reworked to also handle non-WDT events

(cherry picked from commit fe9a52779d062e3f24639479273c906abe6e440b)

Conflicts:
	radio/src/targets/horus/board.h

* Reverting most of the changes

* Cleanup

* Added comment that explains apparent non usage of the wdt_disable() function

* More cleanup

* Missing include

* Compilation fix
This commit is contained in:
Damjan Adamic
2017-01-24 07:52:33 +01:00
committed by Bertrand Songis
parent bf15410bf1
commit b3f4870da7
9 changed files with 651 additions and 525 deletions
+29 -10
View File
@@ -2438,29 +2438,47 @@ void opentxInit(OPENTX_INIT_ARGS)
#if defined(RTCLOCK) && !defined(COPROCESSOR)
rtcInit(); // RTC must be initialized before rambackupRestore() is called
#endif
#if defined(EEPROM)
storageReadAll();
#endif
// Radios handle UNEXPECTED_SHUTDOWN() differently:
// * radios with WDT and EEPROM and CPU controlled power use Reset status register
// and eeGeneral.unexpectedShutdown
// * radios with SDCARD model storage use Reset status register and special
// variables in RAM. They can not use eeGeneral.unexpectedShutdown
// * radios without CPU controlled power can only use Reset status register (if available)
if (UNEXPECTED_SHUTDOWN()) {
TRACE("Unexpected Shutdown detected");
unexpectedShutdown = 1;
}
else {
#if defined(SDCARD) && !defined(PCBMEGA2560)
// SDCARD related stuff, only done if not unexpectedShutdown
if (!unexpectedShutdown) {
sdInit();
logsInit();
}
#endif
}
#if defined(PCBHORUS)
topbar = new Topbar(&g_model.topbarData);
LUA_INIT_THEMES_AND_WIDGETS();
if (!unexpectedShutdown) {
// g_model.topbarData is still zero here (because it was not yet read from SDCARD),
// but we only remember the pointer to in in constructor.
// The storageReadAll() needs topbar object, so it must be created here
topbar = new Topbar(&g_model.topbarData);
// lua widget state must also be prepared before the call to storageReadAll()
LUA_INIT_THEMES_AND_WIDGETS();
}
#endif
// handling of storage for radios that have no EEPROM
#if !defined(EEPROM)
#if defined(RAMBACKUP)
if (UNEXPECTED_SHUTDOWN()) {
if (unexpectedShutdown) {
// SDCARD not available, try to restore last model from RAM
TRACE("rambackupRestore");
rambackupRestore();
}
else {
@@ -2469,7 +2487,7 @@ void opentxInit(OPENTX_INIT_ARGS)
#else
storageReadAll();
#endif
#endif
#endif // #if !defined(EEPROM)
#if defined(SERIAL2)
serial2Init(g_eeGeneral.serial2Mode, MODEL_TELEMETRY_PROTOCOL());
@@ -2515,11 +2533,12 @@ void opentxInit(OPENTX_INIT_ARGS)
if (g_eeGeneral.backlightMode != e_backlight_mode_off) backlightOn(); // on Tx start turn the light on
if (!UNEXPECTED_SHUTDOWN()) {
if (!unexpectedShutdown) {
opentxStart();
}
#if defined(CPUARM) || defined(CPUM2560)
// TODO Horus does not need this
if (!g_eeGeneral.unexpectedShutdown) {
g_eeGeneral.unexpectedShutdown = 1;
storageDirty(EE_GENERAL);
@@ -2667,7 +2686,7 @@ int main()
drawSleepBitmap();
opentxClose();
boardOff(); // Only turn power off if necessary
wdt_disable();
wdt_disable(); // this function is provided by AVR Libc
while(1); // never return from main() - there is no code to return back, if any delays occurs in physical power it does dead loop.
#endif