diff --git a/core/flipper_v2.c b/core/flipper_v2.c index 9a4e4bc6..87ea47ce 100644 --- a/core/flipper_v2.c +++ b/core/flipper_v2.c @@ -1,5 +1,15 @@ #include "flipper_v2.h" bool init_flipper_api(void) { - return gpio_api_init(); + bool no_errors = true; + + if(!furi_init()) { + no_errors = false; + } + + if(!gpio_api_init()) { + no_errors = false; + } + + return no_errors; } \ No newline at end of file diff --git a/core/furi-deprecated.c b/core/furi-deprecated.c index 0df40efe..af420d49 100644 --- a/core/furi-deprecated.c +++ b/core/furi-deprecated.c @@ -11,6 +11,13 @@ static FuriRecord records[MAX_RECORD_COUNT]; static size_t current_buffer_idx = 0; +osMutexId_t furi_core_mutex; + +bool furi_init(void) { + furi_core_mutex = osMutexNew(NULL); + if(furi_core_mutex == NULL) return false; + return true; +} // find record pointer by name static FuriRecord* find_record(const char* name) { @@ -32,6 +39,11 @@ bool furi_create_deprecated(const char* name, void* value, size_t size) { printf("[FURI] creating %s record\n", name); #endif + // acquire mutex to prevent simultaneous write to record with same index + if(osMutexAcquire(furi_core_mutex, osWaitForever) != osOK) { + return false; + } + FuriRecord* record = find_record(name); if(record != NULL) { @@ -69,6 +81,8 @@ bool furi_create_deprecated(const char* name, void* value, size_t size) { current_buffer_idx++; + osMutexRelease(furi_core_mutex); + return true; } diff --git a/core/furi-deprecated.h b/core/furi-deprecated.h index 5f401bbe..0aa4cac6 100644 --- a/core/furi-deprecated.h +++ b/core/furi-deprecated.h @@ -87,6 +87,9 @@ typedef struct { FlipperAppLibrary libs; } FlipperStartupApp; +// Init core +bool furi_init(void); + /*! Simply starts application. It call app entrypoint with param passed as argument. diff --git a/core/furi_ac.c b/core/furi_ac.c index fc535dbc..75cc110d 100644 --- a/core/furi_ac.c +++ b/core/furi_ac.c @@ -31,12 +31,12 @@ void furiac_wait_libs(const FlipperAppLibrary* libs) { if(app_id == INVALID_TASK_ID) { #ifdef FURI_DEBUG - printf("[FURIAC] Invalid library name %s\n", lib_name); + printf("[FURIAC] Invalid library name %s\n", libs->name[i]); #endif } else { while(!task_buffer[app_id].ready) { #ifdef FURI_DEBUG - printf("[FURIAC] waiting for library \"%s\"\n", lib_name); + printf("[FURIAC] waiting for library \"%s\"\n", libs->name[i]); #endif osDelay(50); }