mirror of
https://github.com/DarkFlippers/unleashed-firmware
synced 2024-11-23 13:03:13 +00:00
Furi: wait for timer wind down in destructor (#1716)
This commit is contained in:
parent
d1c79a83de
commit
ff33bc6aea
2 changed files with 15 additions and 16 deletions
|
@ -463,8 +463,6 @@ void text_input_free(TextInput* text_input) {
|
||||||
|
|
||||||
// Send stop command
|
// Send stop command
|
||||||
furi_timer_stop(text_input->timer);
|
furi_timer_stop(text_input->timer);
|
||||||
// Wait till timer stop
|
|
||||||
while(furi_timer_is_running(text_input->timer)) furi_delay_tick(1);
|
|
||||||
// Release allocated memory
|
// Release allocated memory
|
||||||
furi_timer_free(text_input->timer);
|
furi_timer_free(text_input->timer);
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#include "timer.h"
|
#include "timer.h"
|
||||||
#include "check.h"
|
#include "check.h"
|
||||||
|
#include "memmgr.h"
|
||||||
|
#include "kernel.h"
|
||||||
|
|
||||||
#include "core/common_defines.h"
|
#include "core/common_defines.h"
|
||||||
#include <FreeRTOS.h>
|
#include <FreeRTOS.h>
|
||||||
|
@ -39,7 +41,7 @@ FuriTimer* furi_timer_alloc(FuriTimerCallback func, FuriTimerType type, void* co
|
||||||
/* Dynamic memory allocation is available: if memory for callback and */
|
/* Dynamic memory allocation is available: if memory for callback and */
|
||||||
/* its context is not provided, allocate it from dynamic memory pool */
|
/* its context is not provided, allocate it from dynamic memory pool */
|
||||||
if(callb == NULL) {
|
if(callb == NULL) {
|
||||||
callb = (TimerCallback_t*)pvPortMalloc(sizeof(TimerCallback_t));
|
callb = (TimerCallback_t*)malloc(sizeof(TimerCallback_t));
|
||||||
|
|
||||||
if(callb != NULL) {
|
if(callb != NULL) {
|
||||||
/* Callback memory was allocated from dynamic pool, set flag */
|
/* Callback memory was allocated from dynamic pool, set flag */
|
||||||
|
@ -65,7 +67,7 @@ FuriTimer* furi_timer_alloc(FuriTimerCallback func, FuriTimerType type, void* co
|
||||||
if((hTimer == NULL) && (callb != NULL) && (callb_dyn == 1U)) {
|
if((hTimer == NULL) && (callb != NULL) && (callb_dyn == 1U)) {
|
||||||
/* Failed to create a timer, release allocated resources */
|
/* Failed to create a timer, release allocated resources */
|
||||||
callb = (TimerCallback_t*)((uint32_t)callb & ~1U);
|
callb = (TimerCallback_t*)((uint32_t)callb & ~1U);
|
||||||
vPortFree(callb);
|
free(callb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,14 +84,16 @@ void furi_timer_free(FuriTimer* instance) {
|
||||||
|
|
||||||
callb = (TimerCallback_t*)pvTimerGetTimerID(hTimer);
|
callb = (TimerCallback_t*)pvTimerGetTimerID(hTimer);
|
||||||
|
|
||||||
if(xTimerDelete(hTimer, portMAX_DELAY) == pdPASS) {
|
furi_check(xTimerDelete(hTimer, portMAX_DELAY) == pdPASS);
|
||||||
|
|
||||||
|
while (furi_timer_is_running(instance)) furi_delay_tick(2);
|
||||||
|
|
||||||
if((uint32_t)callb & 1U) {
|
if((uint32_t)callb & 1U) {
|
||||||
/* Callback memory was allocated from dynamic pool, clear flag */
|
/* Callback memory was allocated from dynamic pool, clear flag */
|
||||||
callb = (TimerCallback_t*)((uint32_t)callb & ~1U);
|
callb = (TimerCallback_t*)((uint32_t)callb & ~1U);
|
||||||
|
|
||||||
/* Return allocated memory to dynamic pool */
|
/* Return allocated memory to dynamic pool */
|
||||||
vPortFree(callb);
|
free(callb);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,11 +124,8 @@ FuriStatus furi_timer_stop(FuriTimer* instance) {
|
||||||
if(xTimerIsTimerActive(hTimer) == pdFALSE) {
|
if(xTimerIsTimerActive(hTimer) == pdFALSE) {
|
||||||
stat = FuriStatusErrorResource;
|
stat = FuriStatusErrorResource;
|
||||||
} else {
|
} else {
|
||||||
if(xTimerStop(hTimer, portMAX_DELAY) == pdPASS) {
|
furi_check(xTimerStop(hTimer, portMAX_DELAY) == pdPASS);
|
||||||
stat = FuriStatusOk;
|
stat = FuriStatusOk;
|
||||||
} else {
|
|
||||||
stat = FuriStatusError;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return execution status */
|
/* Return execution status */
|
||||||
|
|
Loading…
Reference in a new issue