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:
parent
6c34752907
commit
6d2c5a4db6
16 changed files with 109 additions and 63 deletions
|
@ -497,16 +497,13 @@ void audioTask(void * pdata)
|
||||||
|
|
||||||
setSampleRate(AUDIO_SAMPLE_RATE);
|
setSampleRate(AUDIO_SAMPLE_RATE);
|
||||||
|
|
||||||
#if !defined(EEPROM)
|
while (!sdMounted()) {
|
||||||
AUDIO_HELLO();
|
CoTickDelay(10);
|
||||||
#elif defined(SDCARD)
|
}
|
||||||
|
|
||||||
if (!unexpectedShutdown) {
|
if (!unexpectedShutdown) {
|
||||||
#if defined(EEPROM)
|
|
||||||
sdInit();
|
|
||||||
#endif
|
|
||||||
AUDIO_HELLO();
|
AUDIO_HELLO();
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
audioQueue.wakeup();
|
audioQueue.wakeup();
|
||||||
|
|
|
@ -54,6 +54,9 @@ void handleUsbConnection()
|
||||||
}
|
}
|
||||||
if (usbStarted && !usbPlugged()) {
|
if (usbStarted && !usbPlugged()) {
|
||||||
usbStarted = false;
|
usbStarted = false;
|
||||||
|
#if defined(USB_MASS_STORAGE) && !defined(EEPROM)
|
||||||
|
opentxResume();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(USB_JOYSTICK)
|
#if defined(USB_JOYSTICK)
|
||||||
|
|
|
@ -1912,19 +1912,28 @@ uint8_t calcStickScroll( uint8_t index )
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void opentxStart()
|
#if defined(CPUARM)
|
||||||
{
|
#define OPENTX_START_ARGS uint8_t splash=true
|
||||||
TRACE("opentxStart()");
|
#define OPENTX_START_SPLASH_NEEDED() (splash)
|
||||||
|
#else
|
||||||
#if defined(SIMU)
|
#define OPENTX_START_ARGS
|
||||||
if (main_thread_running == 2)
|
#define OPENTX_START_SPLASH_NEEDED() true
|
||||||
return;
|
|
||||||
#endif
|
#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 defined(GUI)
|
||||||
if (display_alerts) {
|
if (!calibration_needed && OPENTX_START_SPLASH_NEEDED()) {
|
||||||
doSplash();
|
doSplash();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -1940,12 +1949,12 @@ void opentxStart()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(GUI)
|
#if defined(GUI)
|
||||||
if (display_alerts) {
|
if (calibration_needed) {
|
||||||
checkAlarm();
|
chainMenu(menuFirstCalib);
|
||||||
checkAll();
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
chainMenu(menuFirstCalib);
|
checkAlarm();
|
||||||
|
checkAll();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -1953,7 +1962,7 @@ void opentxStart()
|
||||||
#if defined(CPUARM) || defined(CPUM2560)
|
#if defined(CPUARM) || defined(CPUM2560)
|
||||||
void opentxClose(uint8_t shutdown)
|
void opentxClose(uint8_t shutdown)
|
||||||
{
|
{
|
||||||
TRACE("opentxClose()");
|
TRACE("opentxClose");
|
||||||
|
|
||||||
if (shutdown) {
|
if (shutdown) {
|
||||||
#if defined(CPUARM)
|
#if defined(CPUARM)
|
||||||
|
@ -2030,6 +2039,33 @@ void opentxClose(uint8_t shutdown)
|
||||||
}
|
}
|
||||||
#endif
|
#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)
|
#if defined(NAVIGATION_STICKS)
|
||||||
uint8_t getSticksNavigationEvent()
|
uint8_t getSticksNavigationEvent()
|
||||||
{
|
{
|
||||||
|
@ -2477,7 +2513,7 @@ void opentxInit(OPENTX_INIT_ARGS)
|
||||||
// CoTickDelay(5000); // 10s
|
// CoTickDelay(5000); // 10s
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
TRACE("opentxInit()");
|
TRACE("opentxInit");
|
||||||
|
|
||||||
#if defined(GUI)
|
#if defined(GUI)
|
||||||
menuHandlers[0] = menuMainView;
|
menuHandlers[0] = menuMainView;
|
||||||
|
@ -2490,11 +2526,14 @@ void opentxInit(OPENTX_INIT_ARGS)
|
||||||
rtcInit(); // RTC must be initialized before rambackupRestore() is called
|
rtcInit(); // RTC must be initialized before rambackupRestore() is called
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(EEPROM)
|
if (UNEXPECTED_SHUTDOWN()) {
|
||||||
if (!UNEXPECTED_SHUTDOWN()) {
|
unexpectedShutdown = 1;
|
||||||
sdInit();
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
#if defined(SDCARD) && !defined(PCBMEGA2560)
|
||||||
|
sdInit();
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(PCBHORUS)
|
#if defined(PCBHORUS)
|
||||||
topbar = new Topbar(&g_model.topbarData);
|
topbar = new Topbar(&g_model.topbarData);
|
||||||
|
@ -2512,12 +2551,6 @@ void opentxInit(OPENTX_INIT_ARGS)
|
||||||
storageReadAll();
|
storageReadAll();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(CPUARM)
|
|
||||||
if (UNEXPECTED_SHUTDOWN()) {
|
|
||||||
unexpectedShutdown = 1;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(PCBTARANIS)
|
#if defined(PCBTARANIS)
|
||||||
BACKLIGHT_ON();
|
BACKLIGHT_ON();
|
||||||
#endif
|
#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 (g_eeGeneral.backlightMode != e_backlight_mode_off) backlightOn(); // on Tx start turn the light on
|
||||||
|
|
||||||
if (UNEXPECTED_SHUTDOWN()) {
|
if (!UNEXPECTED_SHUTDOWN()) {
|
||||||
#if !defined(CPUARM)
|
|
||||||
// is done above on ARM
|
|
||||||
unexpectedShutdown = 1;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
opentxStart();
|
opentxStart();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1426,6 +1426,7 @@ extern uint8_t requestScreenshot;
|
||||||
void checkBattery();
|
void checkBattery();
|
||||||
void opentxClose(uint8_t shutdown=true);
|
void opentxClose(uint8_t shutdown=true);
|
||||||
void opentxInit();
|
void opentxInit();
|
||||||
|
void opentxResume();
|
||||||
|
|
||||||
#if defined(PCBHORUS) && !defined(SIMU)
|
#if defined(PCBHORUS) && !defined(SIMU)
|
||||||
#define LED_ERROR_BEGIN() ledRed()
|
#define LED_ERROR_BEGIN() ledRed()
|
||||||
|
@ -1704,7 +1705,7 @@ FORCEINLINE void convertUnit(getvalue_t & val, uint8_t & unit)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(USB_MASS_STORAGE)
|
#if defined(USB_MASS_STORAGE)
|
||||||
extern void usbPluggedIn();
|
void usbPluggedIn();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "lua/lua_api.h"
|
#include "lua/lua_api.h"
|
||||||
|
|
|
@ -44,14 +44,14 @@ void eeLoadModel(uint8_t index)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool newModel = false;
|
bool alarms = true;
|
||||||
if (size < EEPROM_MIN_MODEL_SIZE) { // if not loaded a fair amount
|
if (size < EEPROM_MIN_MODEL_SIZE) { // if not loaded a fair amount
|
||||||
modelDefault(index) ;
|
modelDefault(index) ;
|
||||||
storageCheck(true);
|
storageCheck(true);
|
||||||
newModel = true;
|
alarms = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
postModelLoad(newModel);
|
postModelLoad(alarms);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -234,7 +234,7 @@ const pm_char * eeRestoreModel(uint8_t i_fileDst, char *model_name);
|
||||||
// For conversions
|
// For conversions
|
||||||
#if defined(CPUARM)
|
#if defined(CPUARM)
|
||||||
void loadGeneralSettings();
|
void loadGeneralSettings();
|
||||||
void loadModel(int index);
|
void loadModel(int index, bool alarms=true);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool eepromOpen();
|
bool eepromOpen();
|
||||||
|
|
|
@ -29,6 +29,8 @@ void getModelPath(char * path, const char * filename)
|
||||||
|
|
||||||
const char * writeFile(const char * filename, const uint8_t * data, uint16_t size)
|
const char * writeFile(const char * filename, const uint8_t * data, uint16_t size)
|
||||||
{
|
{
|
||||||
|
TRACE("writeFile(%s)", filename);
|
||||||
|
|
||||||
FIL file;
|
FIL file;
|
||||||
char buf[8];
|
char buf[8];
|
||||||
UINT written;
|
UINT written;
|
||||||
|
@ -68,6 +70,8 @@ const char * writeModel()
|
||||||
|
|
||||||
const char * loadFile(const char * filename, uint8_t * data, uint16_t maxsize)
|
const char * loadFile(const char * filename, uint8_t * data, uint16_t maxsize)
|
||||||
{
|
{
|
||||||
|
TRACE("loadFile(%s)", filename);
|
||||||
|
|
||||||
FIL file;
|
FIL file;
|
||||||
char buf[8];
|
char buf[8];
|
||||||
UINT read;
|
UINT read;
|
||||||
|
@ -112,7 +116,7 @@ const char * readModel(const char * filename, uint8_t * buffer, uint32_t size)
|
||||||
return loadFile(path, buffer, size);
|
return loadFile(path, buffer, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * loadModel(const char * filename)
|
const char * loadModel(const char * filename, bool alarms)
|
||||||
{
|
{
|
||||||
preModelLoad();
|
preModelLoad();
|
||||||
|
|
||||||
|
@ -120,15 +124,14 @@ const char * loadModel(const char * filename)
|
||||||
if (error) {
|
if (error) {
|
||||||
TRACE("loadModel error=%s", error);
|
TRACE("loadModel error=%s", error);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool newModel = false;
|
|
||||||
if (error) {
|
if (error) {
|
||||||
modelDefault(0) ;
|
modelDefault(0) ;
|
||||||
storageCheck(true);
|
storageCheck(true);
|
||||||
newModel = true;
|
alarms = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
postModelLoad(newModel);
|
postModelLoad(alarms);
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
@ -171,8 +174,8 @@ void storageCheck(bool immediately)
|
||||||
|
|
||||||
void storageReadAll()
|
void storageReadAll()
|
||||||
{
|
{
|
||||||
sdInit();
|
TRACE("storageReadAll");
|
||||||
|
|
||||||
if (loadGeneralSettings() != NULL) {
|
if (loadGeneralSettings() != NULL) {
|
||||||
storageEraseAll(true);
|
storageEraseAll(true);
|
||||||
}
|
}
|
||||||
|
@ -186,7 +189,7 @@ void storageReadAll()
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
loadModel(g_eeGeneral.currModelFilename);
|
loadModel(g_eeGeneral.currModelFilename, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void storageCreateModelsList()
|
void storageCreateModelsList()
|
||||||
|
@ -223,14 +226,14 @@ const char * createModel()
|
||||||
storageDirty(EE_MODEL);
|
storageDirty(EE_MODEL);
|
||||||
storageCheck(true);
|
storageCheck(true);
|
||||||
}
|
}
|
||||||
postModelLoad(true);
|
postModelLoad(false);
|
||||||
|
|
||||||
return g_eeGeneral.currModelFilename;
|
return g_eeGeneral.currModelFilename;
|
||||||
}
|
}
|
||||||
|
|
||||||
void storageEraseAll(bool warn)
|
void storageEraseAll(bool warn)
|
||||||
{
|
{
|
||||||
TRACE("storageEraseAll()");
|
TRACE("storageEraseAll");
|
||||||
|
|
||||||
#if defined(COLORLCD)
|
#if defined(COLORLCD)
|
||||||
// the theme has not been loaded before
|
// the theme has not been loaded before
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
#define DEFAULT_MODEL_FILENAME "model01.bin"
|
#define DEFAULT_MODEL_FILENAME "model01.bin"
|
||||||
|
|
||||||
const char * readModel(const char * filename, uint8_t * buffer, uint32_t size);
|
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();
|
const char * createModel();
|
||||||
|
|
||||||
PACK(struct RamBackup {
|
PACK(struct RamBackup {
|
||||||
|
|
|
@ -52,7 +52,7 @@ void storageDirty(uint8_t msk);
|
||||||
void storageCheck(bool immediately);
|
void storageCheck(bool immediately);
|
||||||
|
|
||||||
void preModelLoad();
|
void preModelLoad();
|
||||||
void postModelLoad(bool newModel);
|
void postModelLoad(bool alarms);
|
||||||
|
|
||||||
#if defined(EEPROM_RLC)
|
#if defined(EEPROM_RLC)
|
||||||
#include "eeprom_common.h"
|
#include "eeprom_common.h"
|
||||||
|
|
|
@ -56,14 +56,14 @@ void preModelLoad()
|
||||||
pauseMixerCalculations();
|
pauseMixerCalculations();
|
||||||
}
|
}
|
||||||
|
|
||||||
void postModelLoad(bool newModel)
|
void postModelLoad(bool alarms)
|
||||||
{
|
{
|
||||||
AUDIO_FLUSH();
|
AUDIO_FLUSH();
|
||||||
flightReset(false);
|
flightReset(false);
|
||||||
|
|
||||||
if (pulsesStarted()) {
|
if (pulsesStarted()) {
|
||||||
#if defined(GUI)
|
#if defined(GUI)
|
||||||
if (!newModel) {
|
if (alarms) {
|
||||||
checkAll();
|
checkAll();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -149,7 +149,7 @@ void boardInit()
|
||||||
|
|
||||||
__enable_irq();
|
__enable_irq();
|
||||||
|
|
||||||
TRACE("Horus started :)");
|
TRACE("\nHorus board started :)");
|
||||||
|
|
||||||
keysInit();
|
keysInit();
|
||||||
adcInit();
|
adcInit();
|
||||||
|
|
|
@ -109,6 +109,7 @@ uint32_t sdGetSpeed(void);
|
||||||
#define SD_GET_FREE_BLOCKNR() (sdGetFreeSectors())
|
#define SD_GET_FREE_BLOCKNR() (sdGetFreeSectors())
|
||||||
#define SD_CARD_PRESENT() (~SD_PRESENT_GPIO->IDR & SD_PRESENT_GPIO_PIN)
|
#define SD_CARD_PRESENT() (~SD_PRESENT_GPIO->IDR & SD_PRESENT_GPIO_PIN)
|
||||||
void sdInit(void);
|
void sdInit(void);
|
||||||
|
void sdMount(void);
|
||||||
void sdDone(void);
|
void sdDone(void);
|
||||||
#define sdPoll10ms()
|
#define sdPoll10ms()
|
||||||
#define sdMountPoll()
|
#define sdMountPoll()
|
||||||
|
|
|
@ -292,14 +292,22 @@ FATFS g_FATFS_Obj __DMA;
|
||||||
FIL g_telemetryFile = {0};
|
FIL g_telemetryFile = {0};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void sdInit(void)
|
void sdInit()
|
||||||
{
|
{
|
||||||
|
TRACE("sdInit");
|
||||||
|
|
||||||
ioMutex = CoCreateMutex();
|
ioMutex = CoCreateMutex();
|
||||||
if (ioMutex >= CFG_MAX_MUTEX ) {
|
if (ioMutex >= CFG_MAX_MUTEX) {
|
||||||
// sd error
|
// sd error
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
sdMount();
|
||||||
|
}
|
||||||
|
|
||||||
|
void sdMount()
|
||||||
|
{
|
||||||
|
TRACE("sdMount");
|
||||||
|
|
||||||
if (f_mount(&g_FATFS_Obj, "", 1) == FR_OK) {
|
if (f_mount(&g_FATFS_Obj, "", 1) == FR_OK) {
|
||||||
// call sdGetFreeSectors() now because f_getfree() takes a long time first time it's called
|
// call sdGetFreeSectors() now because f_getfree() takes a long time first time it's called
|
||||||
sdGetFreeSectors();
|
sdGetFreeSectors();
|
||||||
|
@ -320,6 +328,8 @@ void sdInit(void)
|
||||||
|
|
||||||
void sdDone()
|
void sdDone()
|
||||||
{
|
{
|
||||||
|
TRACE("sdDone");
|
||||||
|
|
||||||
if (sdMounted()) {
|
if (sdMounted()) {
|
||||||
audioQueue.stopSD();
|
audioQueue.stopSD();
|
||||||
#if defined(LOG_TELEMETRY)
|
#if defined(LOG_TELEMETRY)
|
||||||
|
|
|
@ -843,6 +843,8 @@ const char * sdEnum()
|
||||||
|
|
||||||
void sdInit()
|
void sdInit()
|
||||||
{
|
{
|
||||||
|
TRACE("sdInit");
|
||||||
|
|
||||||
const char * result;
|
const char * result;
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
|
|
||||||
|
|
|
@ -151,9 +151,9 @@ uint32_t unlocked = 0;
|
||||||
|
|
||||||
extern uint32_t EepromBlocked;
|
extern uint32_t EepromBlocked;
|
||||||
|
|
||||||
extern void init_spi(void);
|
void init_spi(void);
|
||||||
extern void writeBlock(void);
|
void writeBlock(void);
|
||||||
extern void usbPluggedIn();
|
void usbPluggedIn();
|
||||||
|
|
||||||
#if defined(PCBX9E)
|
#if defined(PCBX9E)
|
||||||
typedef int32_t rotenc_t;
|
typedef int32_t rotenc_t;
|
||||||
|
|
|
@ -992,6 +992,8 @@ void sdInit(void)
|
||||||
// TODO shouldn't be there!
|
// TODO shouldn't be there!
|
||||||
void sdInit(void)
|
void sdInit(void)
|
||||||
{
|
{
|
||||||
|
TRACE("sdInit");
|
||||||
|
|
||||||
ioMutex = CoCreateMutex();
|
ioMutex = CoCreateMutex();
|
||||||
if (ioMutex >= CFG_MAX_MUTEX ) {
|
if (ioMutex >= CFG_MAX_MUTEX ) {
|
||||||
//sd error
|
//sd error
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue