Moved codeplug initialisation from state init function to main initialisation sequence

This commit is contained in:
Silvano Seva 2022-07-01 15:12:17 +02:00
parent d39783af2f
commit 22ce4d6925
2 changed files with 17 additions and 21 deletions

View File

@ -21,6 +21,7 @@
#include <interfaces/platform.h> #include <interfaces/platform.h>
#include <interfaces/graphics.h> #include <interfaces/graphics.h>
#include <interfaces/delays.h> #include <interfaces/delays.h>
#include <interfaces/cps_io.h>
#include <interfaces/gps.h> #include <interfaces/gps.h>
#include <threads.h> #include <threads.h>
#include <openrtx.h> #include <openrtx.h>
@ -42,6 +43,22 @@ void openrtx_init()
display_setContrast(state.settings.contrast); display_setContrast(state.settings.contrast);
#endif #endif
// Load codeplug from nonvolatile memory, create a new one in case of failure.
if(cps_open(NULL) < 0)
{
cps_create(NULL);
if(cps_open(NULL) < 0)
{
// Unrecoverable error
#ifdef PLATFORM_LINUX
exit(-1);
#else
// TODO: implement error handling for non-linux targets
while(1) ;
#endif
}
}
// Display splash screen, turn on backlight after a suitable time to // Display splash screen, turn on backlight after a suitable time to
// hide random pixels during render process // hide random pixels during render process
ui_drawSplashScreen(true); ui_drawSplashScreen(true);

View File

@ -26,7 +26,6 @@
#include <hwconfig.h> #include <hwconfig.h>
#include <interfaces/platform.h> #include <interfaces/platform.h>
#include <interfaces/nvmem.h> #include <interfaces/nvmem.h>
#include <interfaces/cps_io.h>
state_t state; state_t state;
pthread_mutex_t state_mutex; pthread_mutex_t state_mutex;
@ -54,26 +53,6 @@ void state_init()
state.channel = cps_getDefaultChannel(); state.channel = cps_getDefaultChannel();
} }
/*
* Try loading default codeplug from nonvolatile memory, if fails create
* an empty one.
*/
if(cps_open(NULL) < 0)
{
cps_create(NULL);
// If cannot open the newly created codeplug -> unrecoverable error
if(cps_open(NULL) < 0)
{
#ifdef PLATFORM_LINUX
exit(-1);
#else
// TODO: implement error handling for non-linux targets
while(1) ;
#endif
}
}
/* /*
* Initialise remaining fields * Initialise remaining fields
*/ */