diff --git a/openrtx/src/core/openrtx.c b/openrtx/src/core/openrtx.c index be8f18cf..e33d9071 100644 --- a/openrtx/src/core/openrtx.c +++ b/openrtx/src/core/openrtx.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -42,6 +43,22 @@ void openrtx_init() display_setContrast(state.settings.contrast); #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 // hide random pixels during render process ui_drawSplashScreen(true); diff --git a/openrtx/src/core/state.c b/openrtx/src/core/state.c index ac72ff7b..6998db47 100644 --- a/openrtx/src/core/state.c +++ b/openrtx/src/core/state.c @@ -26,7 +26,6 @@ #include #include #include -#include state_t state; pthread_mutex_t state_mutex; @@ -54,26 +53,6 @@ void state_init() 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 */