1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-25 09:15:38 +03:00

Radio init / masstorage start / massstorage end / shutdown sequences … (#3674)

* Radio init / masstorage start / massstorage end / shutdown sequences reordering:

- More traces
- Fixes #3642
- Reuses idea of #3662

Still not finished and completely untested

* More traces

* Compilation fix

* Reuses the idea of #3652

* Alarms were checked 2 times on massstorage end
This commit is contained in:
Bertrand Songis 2016-08-01 18:39:34 +02:00 committed by GitHub
parent 6c34752907
commit 6d2c5a4db6
16 changed files with 109 additions and 63 deletions

View file

@ -497,16 +497,13 @@ void audioTask(void * pdata)
setSampleRate(AUDIO_SAMPLE_RATE);
#if !defined(EEPROM)
AUDIO_HELLO();
#elif defined(SDCARD)
while (!sdMounted()) {
CoTickDelay(10);
}
if (!unexpectedShutdown) {
#if defined(EEPROM)
sdInit();
#endif
AUDIO_HELLO();
}
#endif
while (1) {
audioQueue.wakeup();

View file

@ -54,6 +54,9 @@ void handleUsbConnection()
}
if (usbStarted && !usbPlugged()) {
usbStarted = false;
#if defined(USB_MASS_STORAGE) && !defined(EEPROM)
opentxResume();
#endif
}
#if defined(USB_JOYSTICK)

View file

@ -1912,19 +1912,28 @@ uint8_t calcStickScroll( uint8_t index )
}
#endif
void opentxStart()
{
TRACE("opentxStart()");
#if defined(SIMU)
if (main_thread_running == 2)
return;
#if defined(CPUARM)
#define OPENTX_START_ARGS uint8_t splash=true
#define OPENTX_START_SPLASH_NEEDED() (splash)
#else
#define OPENTX_START_ARGS
#define OPENTX_START_SPLASH_NEEDED() true
#endif
bool display_alerts = (g_eeGeneral.chkSum == evalChkSum());
void opentxStart(OPENTX_START_ARGS)
{
TRACE("opentxStart");
#if defined(SIMU)
if (main_thread_running == 2) {
return;
}
#endif
uint8_t calibration_needed = (g_eeGeneral.chkSum != evalChkSum());
#if defined(GUI)
if (display_alerts) {
if (!calibration_needed && OPENTX_START_SPLASH_NEEDED()) {
doSplash();
}
#endif
@ -1940,12 +1949,12 @@ void opentxStart()
#endif
#if defined(GUI)
if (display_alerts) {
checkAlarm();
checkAll();
if (calibration_needed) {
chainMenu(menuFirstCalib);
}
else {
chainMenu(menuFirstCalib);
checkAlarm();
checkAll();
}
#endif
}
@ -1953,7 +1962,7 @@ void opentxStart()
#if defined(CPUARM) || defined(CPUM2560)
void opentxClose(uint8_t shutdown)
{
TRACE("opentxClose()");
TRACE("opentxClose");
if (shutdown) {
#if defined(CPUARM)
@ -2030,6 +2039,33 @@ void opentxClose(uint8_t shutdown)
}
#endif
#if defined(USB_MASS_STORAGE)
void opentxResume()
{
TRACE("opentxResume");
menuHandlers[0] = menuMainView;
sdMount();
storageReadAll();
#if defined(PCBHORUS)
loadTheme();
loadFontCache();
#endif
opentxStart(false);
#if defined(CPUARM) || defined(CPUM2560)
if (!g_eeGeneral.unexpectedShutdown) {
g_eeGeneral.unexpectedShutdown = 1;
storageDirty(EE_GENERAL);
}
#endif
}
#endif
#if defined(NAVIGATION_STICKS)
uint8_t getSticksNavigationEvent()
{
@ -2477,7 +2513,7 @@ void opentxInit(OPENTX_INIT_ARGS)
// CoTickDelay(5000); // 10s
#endif
TRACE("opentxInit()");
TRACE("opentxInit");
#if defined(GUI)
menuHandlers[0] = menuMainView;
@ -2490,11 +2526,14 @@ void opentxInit(OPENTX_INIT_ARGS)
rtcInit(); // RTC must be initialized before rambackupRestore() is called
#endif
#if !defined(EEPROM)
if (!UNEXPECTED_SHUTDOWN()) {
sdInit();
if (UNEXPECTED_SHUTDOWN()) {
unexpectedShutdown = 1;
}
else {
#if defined(SDCARD) && !defined(PCBMEGA2560)
sdInit();
#endif
}
#if defined(PCBHORUS)
topbar = new Topbar(&g_model.topbarData);
@ -2512,12 +2551,6 @@ void opentxInit(OPENTX_INIT_ARGS)
storageReadAll();
#endif
#if defined(CPUARM)
if (UNEXPECTED_SHUTDOWN()) {
unexpectedShutdown = 1;
}
#endif
#if defined(PCBTARANIS)
BACKLIGHT_ON();
#endif
@ -2554,13 +2587,7 @@ 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 !defined(CPUARM)
// is done above on ARM
unexpectedShutdown = 1;
#endif
}
else {
if (!UNEXPECTED_SHUTDOWN()) {
opentxStart();
}

View file

@ -1426,6 +1426,7 @@ extern uint8_t requestScreenshot;
void checkBattery();
void opentxClose(uint8_t shutdown=true);
void opentxInit();
void opentxResume();
#if defined(PCBHORUS) && !defined(SIMU)
#define LED_ERROR_BEGIN() ledRed()
@ -1704,7 +1705,7 @@ FORCEINLINE void convertUnit(getvalue_t & val, uint8_t & unit)
#endif
#if defined(USB_MASS_STORAGE)
extern void usbPluggedIn();
void usbPluggedIn();
#endif
#include "lua/lua_api.h"

View file

@ -44,14 +44,14 @@ void eeLoadModel(uint8_t index)
}
#endif
bool newModel = false;
bool alarms = true;
if (size < EEPROM_MIN_MODEL_SIZE) { // if not loaded a fair amount
modelDefault(index) ;
storageCheck(true);
newModel = true;
alarms = false;
}
postModelLoad(newModel);
postModelLoad(alarms);
}
}

View file

@ -234,7 +234,7 @@ const pm_char * eeRestoreModel(uint8_t i_fileDst, char *model_name);
// For conversions
#if defined(CPUARM)
void loadGeneralSettings();
void loadModel(int index);
void loadModel(int index, bool alarms=true);
#endif
bool eepromOpen();

View file

@ -29,6 +29,8 @@ void getModelPath(char * path, const char * filename)
const char * writeFile(const char * filename, const uint8_t * data, uint16_t size)
{
TRACE("writeFile(%s)", filename);
FIL file;
char buf[8];
UINT written;
@ -68,6 +70,8 @@ const char * writeModel()
const char * loadFile(const char * filename, uint8_t * data, uint16_t maxsize)
{
TRACE("loadFile(%s)", filename);
FIL file;
char buf[8];
UINT read;
@ -112,7 +116,7 @@ const char * readModel(const char * filename, uint8_t * buffer, uint32_t size)
return loadFile(path, buffer, size);
}
const char * loadModel(const char * filename)
const char * loadModel(const char * filename, bool alarms)
{
preModelLoad();
@ -121,14 +125,13 @@ const char * loadModel(const char * filename)
TRACE("loadModel error=%s", error);
}
bool newModel = false;
if (error) {
modelDefault(0) ;
storageCheck(true);
newModel = true;
alarms = false;
}
postModelLoad(newModel);
postModelLoad(alarms);
return error;
}
@ -171,7 +174,7 @@ void storageCheck(bool immediately)
void storageReadAll()
{
sdInit();
TRACE("storageReadAll");
if (loadGeneralSettings() != NULL) {
storageEraseAll(true);
@ -186,7 +189,7 @@ void storageReadAll()
}
#endif
loadModel(g_eeGeneral.currModelFilename);
loadModel(g_eeGeneral.currModelFilename, false);
}
void storageCreateModelsList()
@ -223,14 +226,14 @@ const char * createModel()
storageDirty(EE_MODEL);
storageCheck(true);
}
postModelLoad(true);
postModelLoad(false);
return g_eeGeneral.currModelFilename;
}
void storageEraseAll(bool warn)
{
TRACE("storageEraseAll()");
TRACE("storageEraseAll");
#if defined(COLORLCD)
// the theme has not been loaded before

View file

@ -27,7 +27,7 @@
#define DEFAULT_MODEL_FILENAME "model01.bin"
const char * readModel(const char * filename, uint8_t * buffer, uint32_t size);
const char * loadModel(const char * filename);
const char * loadModel(const char * filename, bool alarms=true);
const char * createModel();
PACK(struct RamBackup {

View file

@ -52,7 +52,7 @@ void storageDirty(uint8_t msk);
void storageCheck(bool immediately);
void preModelLoad();
void postModelLoad(bool newModel);
void postModelLoad(bool alarms);
#if defined(EEPROM_RLC)
#include "eeprom_common.h"

View file

@ -56,14 +56,14 @@ void preModelLoad()
pauseMixerCalculations();
}
void postModelLoad(bool newModel)
void postModelLoad(bool alarms)
{
AUDIO_FLUSH();
flightReset(false);
if (pulsesStarted()) {
#if defined(GUI)
if (!newModel) {
if (alarms) {
checkAll();
}
#endif

View file

@ -149,7 +149,7 @@ void boardInit()
__enable_irq();
TRACE("Horus started :)");
TRACE("\nHorus board started :)");
keysInit();
adcInit();

View file

@ -109,6 +109,7 @@ uint32_t sdGetSpeed(void);
#define SD_GET_FREE_BLOCKNR() (sdGetFreeSectors())
#define SD_CARD_PRESENT() (~SD_PRESENT_GPIO->IDR & SD_PRESENT_GPIO_PIN)
void sdInit(void);
void sdMount(void);
void sdDone(void);
#define sdPoll10ms()
#define sdMountPoll()

View file

@ -292,13 +292,21 @@ FATFS g_FATFS_Obj __DMA;
FIL g_telemetryFile = {0};
#endif
void sdInit(void)
void sdInit()
{
TRACE("sdInit");
ioMutex = CoCreateMutex();
if (ioMutex >= CFG_MAX_MUTEX) {
// sd error
return;
}
sdMount();
}
void sdMount()
{
TRACE("sdMount");
if (f_mount(&g_FATFS_Obj, "", 1) == FR_OK) {
// call sdGetFreeSectors() now because f_getfree() takes a long time first time it's called
@ -320,6 +328,8 @@ void sdInit(void)
void sdDone()
{
TRACE("sdDone");
if (sdMounted()) {
audioQueue.stopSD();
#if defined(LOG_TELEMETRY)

View file

@ -843,6 +843,8 @@ const char * sdEnum()
void sdInit()
{
TRACE("sdInit");
const char * result;
uint8_t i;

View file

@ -151,9 +151,9 @@ uint32_t unlocked = 0;
extern uint32_t EepromBlocked;
extern void init_spi(void);
extern void writeBlock(void);
extern void usbPluggedIn();
void init_spi(void);
void writeBlock(void);
void usbPluggedIn();
#if defined(PCBX9E)
typedef int32_t rotenc_t;

View file

@ -992,6 +992,8 @@ void sdInit(void)
// TODO shouldn't be there!
void sdInit(void)
{
TRACE("sdInit");
ioMutex = CoCreateMutex();
if (ioMutex >= CFG_MAX_MUTEX ) {
//sd error