added data partitions and app loading logic

This commit is contained in:
Ken Van Hoeylandt
2024-01-02 16:55:17 +01:00
parent b9427d4eba
commit c0824af966
26 changed files with 425 additions and 358 deletions
-76
View File
@@ -5,40 +5,9 @@
#define TAG "app"
const char* prv_type_service = "service";
const char* prv_type_system = "system";
const char* prv_type_user = "user";
static FuriThreadPriority get_thread_priority(AppType type) {
switch (type) {
case AppTypeService:
return FuriThreadPriorityHighest;
case AppTypeSystem:
return FuriThreadPriorityHigh;
case AppTypeUser:
return FuriThreadPriorityNormal;
default:
furi_crash("no priority defined for app type");
}
}
const char* furi_app_type_to_string(AppType type) {
switch (type) {
case AppTypeService:
return prv_type_service;
case AppTypeSystem:
return prv_type_system;
case AppTypeUser:
return prv_type_user;
default:
furi_crash();
}
}
App* furi_app_alloc(const AppManifest* _Nonnull manifest) {
App app = {
.manifest = manifest,
.thread = NULL,
.ep_thread_args = NULL
};
App* app_ptr = malloc(sizeof(App));
@@ -48,11 +17,6 @@ App* furi_app_alloc(const AppManifest* _Nonnull manifest) {
void furi_app_free(App* app) {
furi_assert(app);
if(app->thread) {
furi_thread_join(app->thread);
furi_thread_free(app->thread);
}
if (app->ep_thread_args) {
free(app->ep_thread_args);
app->ep_thread_args = NULL;
@@ -60,43 +24,3 @@ void furi_app_free(App* app) {
free(app);
}
FuriThread* furi_app_alloc_thread(App _Nonnull* app, const char* args) {
FURI_LOG_I(
TAG,
"Starting %s app \"%s\"",
furi_app_type_to_string(app->manifest->type),
app->manifest->name
);
// Free any previous app launching arguments
if (app->ep_thread_args) {
free(app->ep_thread_args);
}
if (args) {
app->ep_thread_args = strdup(args);
} else {
app->ep_thread_args = NULL;
}
FuriThread* thread = furi_thread_alloc_ex(
app->manifest->name,
app->manifest->stack_size,
app->manifest->entry_point,
app
);
if (app->manifest->type == AppTypeService) {
furi_thread_mark_as_service(thread);
}
FuriString* app_name = furi_string_alloc();
furi_thread_set_appid(thread, furi_string_get_cstr(app_name));
furi_string_free(app_name);
FuriThreadPriority priority = get_thread_priority(app->manifest->type);
furi_thread_set_priority(thread, priority);
return thread;
}
-1
View File
@@ -8,7 +8,6 @@ extern "C" {
#endif
typedef struct {
FuriThread* thread;
const AppManifest* manifest;
void* ep_thread_args;
} App;
+40 -2
View File
@@ -6,6 +6,9 @@
extern "C" {
#endif
// Forward declarations
typedef struct _lv_obj_t lv_obj_t;
typedef enum {
AppTypeService,
AppTypeSystem,
@@ -16,14 +19,49 @@ typedef enum {
AppStackSizeNormal = 2048
} AppStackSize;
typedef int32_t (*AppEntryPoint)(void _Nonnull* parameter);
typedef void (*AppOnStart)(void _Nonnull* parameter);
typedef void (*AppOnStop)();
typedef void (*AppOnShow)(lv_obj_t* parent, void* context);
typedef struct {
/**
* The identifier by which the app is launched by the system and other apps.
*/
const char* _Nonnull id;
/**
* The user-readable name of the app. Used in UI.
*/
const char* _Nonnull name;
/**
* Optional icon.
*/
const char* _Nullable icon;
/**
* App type affects launch behaviour.
*/
const AppType type;
const AppEntryPoint _Nullable entry_point;
/**
* Non-blocking method to call when app is started.
*/
const AppOnStart _Nullable on_start;
/**
* Non-blocking method to call when app is stopped.
*/
const AppOnStop _Nullable on_stop;
/**
* Non-blocking method to create the GUI
*/
const AppOnShow _Nullable on_show;
/**
* Callstack size. If you get a stackoverflow, then consider increasing this value.
*/
const AppStackSize stack_size;
} AppManifest;
-3
View File
@@ -5,14 +5,11 @@
#include <freertos/FreeRTOS.h>
#include <freertos/queue.h>
static bool scheduler_was_running = false;
void furi_init() {
furi_assert(!furi_kernel_is_irq());
if (xTaskGetSchedulerState() == taskSCHEDULER_RUNNING) {
vTaskSuspendAll();
scheduler_was_running = true;
}
furi_record_init();