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] 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