mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-16 04:24:45 -07:00
Timer appid's (for APP_DATA_PATH() in timers)
This commit is contained in:
@@ -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"
|
||||
|
||||
|
@@ -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 <task.h>
|
||||
#include <timers.h>
|
||||
#include "log.h"
|
||||
#include <furi_hal_rtc.h>
|
||||
#include <furi_hal_console.h>
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "timer.h"
|
||||
#include "thread.h"
|
||||
#include "check.h"
|
||||
#include "memmgr.h"
|
||||
#include "kernel.h"
|
||||
@@ -6,11 +7,17 @@
|
||||
#include <FreeRTOS.h>
|
||||
#include <timers.h>
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user