From 4286bacdb63fa47996ac23ad6134f59c05e952be Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Mon, 17 Jul 2023 22:36:59 +0100 Subject: [PATCH 1/4] Timer appid's (for APP_DATA_PATH() in timers) --- firmware/targets/f7/api_symbols.csv | 1 + furi/core/thread.c | 7 +++++++ furi/core/timer.c | 16 ++++++++++++++-- furi/core/timer.h | 6 ++++++ 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/firmware/targets/f7/api_symbols.csv b/firmware/targets/f7/api_symbols.csv index c8c1589f7..39ff6e0d2 100644 --- a/firmware/targets/f7/api_symbols.csv +++ b/firmware/targets/f7/api_symbols.csv @@ -1686,6 +1686,7 @@ Function,+,furi_thread_suspend,void,FuriThreadId Function,+,furi_thread_yield,void, Function,+,furi_timer_alloc,FuriTimer*,"FuriTimerCallback, FuriTimerType, void*" Function,+,furi_timer_free,void,FuriTimer* +Function,-,furi_timer_get_current_name,const char*, Function,+,furi_timer_is_running,uint32_t,FuriTimer* Function,+,furi_timer_pending_callback,void,"FuriTimerPendigCallback, void*, uint32_t" Function,+,furi_timer_start,FuriStatus,"FuriTimer*, uint32_t" diff --git a/furi/core/thread.c b/furi/core/thread.c index 2b27a81f4..7e0c9e68c 100644 --- a/furi/core/thread.c +++ b/furi/core/thread.c @@ -1,5 +1,6 @@ #include "thread.h" #include "thread_i.h" +#include "timer.h" #include "kernel.h" #include "memmgr.h" #include "memmgr_heap.h" @@ -9,6 +10,7 @@ #include "string.h" #include +#include #include "log.h" #include #include @@ -511,6 +513,11 @@ const char* furi_thread_get_appid(FuriThreadId thread_id) { FuriThread* thread = (FuriThread*)pvTaskGetThreadLocalStoragePointer(hTask, 0); if(thread) { appid = thread->appid; + } else if (hTask == xTimerGetTimerDaemonTaskHandle()) { + const char* timer = furi_timer_get_current_name(); + if(timer) { + appid = timer; + } } } diff --git a/furi/core/timer.c b/furi/core/timer.c index 7743ffe70..e058933c5 100644 --- a/furi/core/timer.c +++ b/furi/core/timer.c @@ -1,4 +1,5 @@ #include "timer.h" +#include "thread.h" #include "check.h" #include "memmgr.h" #include "kernel.h" @@ -6,11 +7,17 @@ #include #include +const char* current_timer_name = NULL; + typedef struct { FuriTimerCallback func; void* context; } TimerCallback_t; +const char* furi_timer_get_current_name() { + return current_timer_name; +} + static void TimerCallback(TimerHandle_t hTimer) { TimerCallback_t* callb; @@ -21,7 +28,9 @@ static void TimerCallback(TimerHandle_t hTimer) { callb = (TimerCallback_t*)((uint32_t)callb & ~1U); if(callb != NULL) { + current_timer_name = pcTimerGetName(hTimer); callb->func(callb->context); + current_timer_name = NULL; } } @@ -47,11 +56,14 @@ FuriTimer* furi_timer_alloc(FuriTimerCallback func, FuriTimerType type, void* co reload = pdTRUE; } + // Timer name so thread appid works in timers, and so does APP_DATA_PATH() + const char* name = furi_thread_get_appid(furi_thread_get_current_id()); + /* Store callback memory dynamic allocation flag */ callb = (TimerCallback_t*)((uint32_t)callb | 1U); // TimerCallback function is always provided as a callback and is used to call application // specified function with its context both stored in structure callb. - hTimer = xTimerCreate(NULL, 1, reload, callb, TimerCallback); + hTimer = xTimerCreate(name, 1, reload, callb, TimerCallback); furi_check(hTimer); /* Return timer ID */ @@ -133,4 +145,4 @@ void furi_timer_pending_callback(FuriTimerPendigCallback callback, void* context ret = xTimerPendFunctionCall(callback, context, arg, FuriWaitForever); } furi_check(ret == pdPASS); -} \ No newline at end of file +} diff --git a/furi/core/timer.h b/furi/core/timer.h index 3f43de5fd..6c9c6fd2a 100644 --- a/furi/core/timer.h +++ b/furi/core/timer.h @@ -60,6 +60,12 @@ typedef void (*FuriTimerPendigCallback)(void* context, uint32_t arg); void furi_timer_pending_callback(FuriTimerPendigCallback callback, void* context, uint32_t arg); +/** Get currently executing timer name + * + * @return The pointer to the timer name, or NULL + */ +const char* furi_timer_get_current_name(); + #ifdef __cplusplus } #endif From 68431aa851b91c598fceaf07e495ba70e9eeec87 Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Mon, 17 Jul 2023 23:06:58 +0100 Subject: [PATCH 2/4] <:N1:1130620612352679958><:N2:1130620354440745162> --- furi/core/thread.c | 2 +- furi/core/timer.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/furi/core/thread.c b/furi/core/thread.c index 7e0c9e68c..62ab6fec4 100644 --- a/furi/core/thread.c +++ b/furi/core/thread.c @@ -513,7 +513,7 @@ const char* furi_thread_get_appid(FuriThreadId thread_id) { FuriThread* thread = (FuriThread*)pvTaskGetThreadLocalStoragePointer(hTask, 0); if(thread) { appid = thread->appid; - } else if (hTask == xTimerGetTimerDaemonTaskHandle()) { + } else if(hTask == xTimerGetTimerDaemonTaskHandle()) { const char* timer = furi_timer_get_current_name(); if(timer) { appid = timer; diff --git a/furi/core/timer.c b/furi/core/timer.c index e058933c5..d1fdc4456 100644 --- a/furi/core/timer.c +++ b/furi/core/timer.c @@ -15,7 +15,7 @@ typedef struct { } TimerCallback_t; const char* furi_timer_get_current_name() { - return current_timer_name; + return current_timer_name; } static void TimerCallback(TimerHandle_t hTimer) { From fc243eaa0edc61c521819c5a26cf0f155d3f3af0 Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Mon, 17 Jul 2023 23:09:41 +0100 Subject: [PATCH 3/4] Asteroids can use APP_DATA_PATH() again --- applications/external/asteroids/app.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/applications/external/asteroids/app.c b/applications/external/asteroids/app.c index cd2f50357..fa116a3cd 100644 --- a/applications/external/asteroids/app.c +++ b/applications/external/asteroids/app.c @@ -28,9 +28,7 @@ #define MAXPOWERUPS 3 /* Max powerups allowed on screen */ #define POWERUPSTTL 400 /* Max powerup time to live, in ticks. */ #define SHIP_HIT_ANIMATION_LEN 15 -// Tick runs in thread, cant use APP_DATA_PATH() -#define SAVING_DIRECTORY EXT_PATH("apps_data/asteroids") -#define SAVING_FILENAME SAVING_DIRECTORY "/game_asteroids.save" +#define SAVING_FILENAME APP_DATA_PATH("game_asteroids.save") #ifndef PI #define PI 3.14159265358979f #endif @@ -1147,7 +1145,6 @@ void game_tick(void* ctx) { bool load_game(AsteroidsApp* app) { Storage* storage = furi_record_open(RECORD_STORAGE); - storage_common_mkdir(storage, SAVING_DIRECTORY); storage_common_migrate(storage, EXT_PATH("apps/Games/game_asteroids.save"), SAVING_FILENAME); File* file = storage_file_alloc(storage); From 81953fb23fc358c7363247792f9d0b907cea5a43 Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Mon, 17 Jul 2023 23:20:00 +0100 Subject: [PATCH 4/4] Move jetpack joyride save --- applications/external/jetpack_joyride/jetpack.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/applications/external/jetpack_joyride/jetpack.c b/applications/external/jetpack_joyride/jetpack.c index c12f094c9..7969300bd 100644 --- a/applications/external/jetpack_joyride/jetpack.c +++ b/applications/external/jetpack_joyride/jetpack.c @@ -18,8 +18,7 @@ #include "includes/game_state.h" #define TAG "Jetpack Joyride" -#define SAVING_DIRECTORY "/ext/apps/Games" -#define SAVING_FILENAME SAVING_DIRECTORY "/jetpack.save" +#define SAVING_FILENAME APP_DATA_PATH("jetpack.save") static GameState* global_state; typedef enum { @@ -41,6 +40,7 @@ static SaveGame save_game; static bool storage_game_state_load() { Storage* storage = furi_record_open(RECORD_STORAGE); + storage_common_migrate(storage, EXT_PATH("apps/Games/jetpack.save"), SAVING_FILENAME); File* file = storage_file_alloc(storage); uint16_t bytes_readed = 0; @@ -55,12 +55,6 @@ static bool storage_game_state_load() { static void storage_game_state_save() { Storage* storage = furi_record_open(RECORD_STORAGE); - if(storage_common_stat(storage, SAVING_DIRECTORY, NULL) == FSE_NOT_EXIST) { - if(!storage_simply_mkdir(storage, SAVING_DIRECTORY)) { - return; - } - } - File* file = storage_file_alloc(storage); if(storage_file_open(file, SAVING_FILENAME, FSAM_WRITE, FSOM_CREATE_ALWAYS)) { storage_file_write(file, &save_game, sizeof(SaveGame)); @@ -376,4 +370,4 @@ free_and_exit: furi_message_queue_free(event_queue); return return_code; -} \ No newline at end of file +}