Skip to content

Commit

Permalink
[FL-3655] Dolphin: Extreme butthurt loop fix (#3184)
Browse files Browse the repository at this point in the history
* Furi: change timer restart function signature, explicitly require timer time. Dolphin: fix incorrect timer usage caused by refactoring.
* Format Sources
* Furi: update timer documentation
  • Loading branch information
skotopes authored Nov 1, 2023
1 parent aa06328 commit 47cc05d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 14 deletions.
8 changes: 4 additions & 4 deletions applications/services/dolphin/dolphin.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ int32_t dolphin_srv(void* p) {
furi_record_create(RECORD_DOLPHIN, dolphin);

dolphin_state_load(dolphin->state);
furi_timer_stop(dolphin->butthurt_timer);
furi_timer_restart(dolphin->butthurt_timer, HOURS_IN_TICKS(2 * 24));
dolphin_update_clear_limits_timer_period(dolphin);
furi_timer_stop(dolphin->clear_limits_timer);
furi_timer_restart(dolphin->clear_limits_timer, HOURS_IN_TICKS(24));

DolphinEvent event;
while(1) {
Expand All @@ -167,8 +167,8 @@ int32_t dolphin_srv(void* p) {
dolphin_state_on_deed(dolphin->state, event.deed);
DolphinPubsubEvent event = DolphinPubsubEventUpdate;
furi_pubsub_publish(dolphin->pubsub, &event);
furi_timer_restart(dolphin->butthurt_timer);
furi_timer_restart(dolphin->flush_timer);
furi_timer_restart(dolphin->butthurt_timer, HOURS_IN_TICKS(2 * 24));
furi_timer_restart(dolphin->flush_timer, 30 * 1000);
} else if(event.type == DolphinEventTypeStats) {
event.stats->icounter = dolphin->state->data.icounter;
event.stats->butthurt = dolphin->state->data.butthurt;
Expand Down
13 changes: 9 additions & 4 deletions furi/core/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ FuriTimer* furi_timer_alloc(FuriTimerCallback func, FuriTimerType type, void* co
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(NULL, portMAX_DELAY, reload, callb, TimerCallback);
furi_check(hTimer);

/* Return timer ID */
Expand Down Expand Up @@ -83,6 +83,7 @@ void furi_timer_free(FuriTimer* instance) {
FuriStatus furi_timer_start(FuriTimer* instance, uint32_t ticks) {
furi_assert(!furi_kernel_is_irq_or_masked());
furi_assert(instance);
furi_assert(ticks < portMAX_DELAY);

TimerHandle_t hTimer = (TimerHandle_t)instance;
FuriStatus stat;
Expand All @@ -97,14 +98,16 @@ FuriStatus furi_timer_start(FuriTimer* instance, uint32_t ticks) {
return (stat);
}

FuriStatus furi_timer_restart(FuriTimer* instance) {
FuriStatus furi_timer_restart(FuriTimer* instance, uint32_t ticks) {
furi_assert(!furi_kernel_is_irq_or_masked());
furi_assert(instance);
furi_assert(ticks < portMAX_DELAY);

TimerHandle_t hTimer = (TimerHandle_t)instance;
FuriStatus stat;

if(xTimerReset(hTimer, portMAX_DELAY) == pdPASS) {
if(xTimerChangePeriod(hTimer, ticks, portMAX_DELAY) == pdPASS &&
xTimerReset(hTimer, portMAX_DELAY) == pdPASS) {
stat = FuriStatusOk;
} else {
stat = FuriStatusErrorResource;
Expand Down Expand Up @@ -163,7 +166,9 @@ void furi_timer_pending_callback(FuriTimerPendigCallback callback, void* context

void furi_timer_set_thread_priority(FuriTimerThreadPriority priority) {
furi_assert(!furi_kernel_is_irq_or_masked());
TaskHandle_t task_handle = xTaskGetHandle(configTIMER_SERVICE_TASK_NAME);

TaskHandle_t task_handle = xTimerGetTimerDaemonTaskHandle();
furi_check(task_handle); // Don't call this method before timer task start

if(priority == FuriTimerThreadPriorityNormal) {
vTaskPrioritySet(task_handle, configTIMER_TASK_PRIORITY);
Expand Down
5 changes: 3 additions & 2 deletions furi/core/timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void furi_timer_free(FuriTimer* instance);
/** Start timer
*
* @param instance The pointer to FuriTimer instance
* @param[in] ticks The ticks
* @param[in] ticks The interval in ticks
*
* @return The furi status.
*/
Expand All @@ -43,10 +43,11 @@ FuriStatus furi_timer_start(FuriTimer* instance, uint32_t ticks);
/** Restart timer with previous timeout value
*
* @param instance The pointer to FuriTimer instance
* @param[in] ticks The interval in ticks
*
* @return The furi status.
*/
FuriStatus furi_timer_restart(FuriTimer* instance);
FuriStatus furi_timer_restart(FuriTimer* instance, uint32_t ticks);

/** Stop timer
*
Expand Down
4 changes: 2 additions & 2 deletions targets/f18/api_symbols.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
entry,status,name,type,params
Version,+,43.2,,
Version,+,44.0,,
Header,+,applications/services/bt/bt_service/bt.h,,
Header,+,applications/services/cli/cli.h,,
Header,+,applications/services/cli/cli_vcp.h,,
Expand Down Expand Up @@ -1493,7 +1493,7 @@ Function,+,furi_timer_free,void,FuriTimer*
Function,+,furi_timer_get_expire_time,uint32_t,FuriTimer*
Function,+,furi_timer_is_running,uint32_t,FuriTimer*
Function,+,furi_timer_pending_callback,void,"FuriTimerPendigCallback, void*, uint32_t"
Function,+,furi_timer_restart,FuriStatus,FuriTimer*
Function,+,furi_timer_restart,FuriStatus,"FuriTimer*, uint32_t"
Function,+,furi_timer_set_thread_priority,void,FuriTimerThreadPriority
Function,+,furi_timer_start,FuriStatus,"FuriTimer*, uint32_t"
Function,+,furi_timer_stop,FuriStatus,FuriTimer*
Expand Down
4 changes: 2 additions & 2 deletions targets/f7/api_symbols.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
entry,status,name,type,params
Version,+,43.2,,
Version,+,44.0,,
Header,+,applications/drivers/subghz/cc1101_ext/cc1101_ext_interconnect.h,,
Header,+,applications/services/bt/bt_service/bt.h,,
Header,+,applications/services/cli/cli.h,,
Expand Down Expand Up @@ -1688,7 +1688,7 @@ Function,+,furi_timer_free,void,FuriTimer*
Function,+,furi_timer_get_expire_time,uint32_t,FuriTimer*
Function,+,furi_timer_is_running,uint32_t,FuriTimer*
Function,+,furi_timer_pending_callback,void,"FuriTimerPendigCallback, void*, uint32_t"
Function,+,furi_timer_restart,FuriStatus,FuriTimer*
Function,+,furi_timer_restart,FuriStatus,"FuriTimer*, uint32_t"
Function,+,furi_timer_set_thread_priority,void,FuriTimerThreadPriority
Function,+,furi_timer_start,FuriStatus,"FuriTimer*, uint32_t"
Function,+,furi_timer_stop,FuriStatus,FuriTimer*
Expand Down

0 comments on commit 47cc05d

Please sign in to comment.