1
mirror of https://github.com/DarkFlippers/unleashed-firmware.git synced 2025-12-12 04:34:43 +04:00

Furi, FuriHal: remove FreeRTOS headers leaks (#3179)

* Furi: remove direct FreeRTOS timers use
* Furi: eliminate FreeRTOS headers leak. What did it cost? Everything...
* SubGhz: proper public api for protocols. Format Sources.
* Furi: slightly less redundant declarations
* Desktop: proper types in printf
* Sync API Symbols
* Furi: add timer reset and fix dolphin service, fix unit tests
* Furi: proper timer restart method naming and correct behavior in timer stopped state.

---------

Co-authored-by: hedger <hedger@nanode.su>
This commit is contained in:
あく
2023-11-01 16:24:11 +09:00
committed by GitHub
parent 7bd3bd7ea4
commit aa06328516
68 changed files with 316 additions and 472 deletions

View File

@@ -1,7 +1,6 @@
#include "dolphin/dolphin.h"
#include "dolphin/helpers/dolphin_state.h"
#include "dolphin_i.h"
#include "portmacro.h"
#include "projdefs.h"
#include <furi_hal.h>
#include <stdint.h>
@@ -45,8 +44,8 @@ void dolphin_flush(Dolphin* dolphin) {
dolphin_event_send_wait(dolphin, &event);
}
void dolphin_butthurt_timer_callback(TimerHandle_t xTimer) {
Dolphin* dolphin = pvTimerGetTimerID(xTimer);
void dolphin_butthurt_timer_callback(void* context) {
Dolphin* dolphin = context;
furi_assert(dolphin);
DolphinEvent event;
@@ -54,8 +53,8 @@ void dolphin_butthurt_timer_callback(TimerHandle_t xTimer) {
dolphin_event_send_async(dolphin, &event);
}
void dolphin_flush_timer_callback(TimerHandle_t xTimer) {
Dolphin* dolphin = pvTimerGetTimerID(xTimer);
void dolphin_flush_timer_callback(void* context) {
Dolphin* dolphin = context;
furi_assert(dolphin);
DolphinEvent event;
@@ -63,11 +62,11 @@ void dolphin_flush_timer_callback(TimerHandle_t xTimer) {
dolphin_event_send_async(dolphin, &event);
}
void dolphin_clear_limits_timer_callback(TimerHandle_t xTimer) {
Dolphin* dolphin = pvTimerGetTimerID(xTimer);
void dolphin_clear_limits_timer_callback(void* context) {
Dolphin* dolphin = context;
furi_assert(dolphin);
xTimerChangePeriod(dolphin->clear_limits_timer, HOURS_IN_TICKS(24), portMAX_DELAY);
furi_timer_start(dolphin->clear_limits_timer, HOURS_IN_TICKS(24));
DolphinEvent event;
event.type = DolphinEventTypeClearLimits;
@@ -80,12 +79,12 @@ Dolphin* dolphin_alloc() {
dolphin->state = dolphin_state_alloc();
dolphin->event_queue = furi_message_queue_alloc(8, sizeof(DolphinEvent));
dolphin->pubsub = furi_pubsub_alloc();
dolphin->butthurt_timer = xTimerCreate(
NULL, HOURS_IN_TICKS(2 * 24), pdTRUE, dolphin, dolphin_butthurt_timer_callback);
dolphin->butthurt_timer =
furi_timer_alloc(dolphin_butthurt_timer_callback, FuriTimerTypePeriodic, dolphin);
dolphin->flush_timer =
xTimerCreate(NULL, 30 * 1000, pdFALSE, dolphin, dolphin_flush_timer_callback);
dolphin->clear_limits_timer = xTimerCreate(
NULL, HOURS_IN_TICKS(24), pdTRUE, dolphin, dolphin_clear_limits_timer_callback);
furi_timer_alloc(dolphin_flush_timer_callback, FuriTimerTypeOnce, dolphin);
dolphin->clear_limits_timer =
furi_timer_alloc(dolphin_clear_limits_timer_callback, FuriTimerTypePeriodic, dolphin);
return dolphin;
}
@@ -125,14 +124,14 @@ FuriPubSub* dolphin_get_pubsub(Dolphin* dolphin) {
static void dolphin_update_clear_limits_timer_period(Dolphin* dolphin) {
furi_assert(dolphin);
TickType_t now_ticks = xTaskGetTickCount();
TickType_t timer_expires_at = xTimerGetExpiryTime(dolphin->clear_limits_timer);
uint32_t now_ticks = furi_get_tick();
uint32_t timer_expires_at = furi_timer_get_expire_time(dolphin->clear_limits_timer);
if((timer_expires_at - now_ticks) > HOURS_IN_TICKS(0.1)) {
FuriHalRtcDateTime date;
furi_hal_rtc_get_datetime(&date);
TickType_t now_time_in_ms = ((date.hour * 60 + date.minute) * 60 + date.second) * 1000;
TickType_t time_to_clear_limits = 0;
uint32_t now_time_in_ms = ((date.hour * 60 + date.minute) * 60 + date.second) * 1000;
uint32_t time_to_clear_limits = 0;
if(date.hour < 5) {
time_to_clear_limits = HOURS_IN_TICKS(5) - now_time_in_ms;
@@ -140,7 +139,7 @@ static void dolphin_update_clear_limits_timer_period(Dolphin* dolphin) {
time_to_clear_limits = HOURS_IN_TICKS(24 + 5) - now_time_in_ms;
}
xTimerChangePeriod(dolphin->clear_limits_timer, time_to_clear_limits, portMAX_DELAY);
furi_timer_start(dolphin->clear_limits_timer, time_to_clear_limits);
}
}
@@ -156,9 +155,9 @@ int32_t dolphin_srv(void* p) {
furi_record_create(RECORD_DOLPHIN, dolphin);
dolphin_state_load(dolphin->state);
xTimerReset(dolphin->butthurt_timer, portMAX_DELAY);
furi_timer_stop(dolphin->butthurt_timer);
dolphin_update_clear_limits_timer_period(dolphin);
xTimerReset(dolphin->clear_limits_timer, portMAX_DELAY);
furi_timer_stop(dolphin->clear_limits_timer);
DolphinEvent event;
while(1) {
@@ -168,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);
xTimerReset(dolphin->butthurt_timer, portMAX_DELAY);
xTimerReset(dolphin->flush_timer, portMAX_DELAY);
furi_timer_restart(dolphin->butthurt_timer);
furi_timer_restart(dolphin->flush_timer);
} else if(event.type == DolphinEventTypeStats) {
event.stats->icounter = dolphin->state->data.icounter;
event.stats->butthurt = dolphin->state->data.butthurt;