mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-04-24 03:29:57 -07:00
Furi: A Lot of Fixes (#3942)
- BT Service: cleanup code - Dialog: correct release order in file browser - Rpc: rollback to pre #3881 state - Kernel: fix inverted behavior in furi_kernel_is_running - Log: properly take mutex when kernel is not running - Thread: rework tread control block scrubbing procedure, ensure that we don't do stupid things in idle task, add new priority for init task - Timer: add control queue flush method, force flush on stop - Furi: system init task now performs thread scrubbing - BleGlue: add some extra checks - FreeRTOSConfig: fix bunch of issues that were preventing configuration from being properly applied and cleanup
This commit is contained in:
@@ -87,6 +87,8 @@ void ble_glue_init(void) {
|
||||
TL_Init();
|
||||
|
||||
ble_glue->shci_mtx = furi_mutex_alloc(FuriMutexTypeNormal);
|
||||
// Take mutex, SHCI will release it in most unusual way later
|
||||
furi_check(furi_mutex_acquire(ble_glue->shci_mtx, FuriWaitForever) == FuriStatusOk);
|
||||
|
||||
// FreeRTOS system task creation
|
||||
ble_event_thread_start();
|
||||
@@ -248,7 +250,9 @@ void ble_glue_stop(void) {
|
||||
ble_event_thread_stop();
|
||||
// Free resources
|
||||
furi_mutex_free(ble_glue->shci_mtx);
|
||||
ble_glue->shci_mtx = NULL;
|
||||
furi_timer_free(ble_glue->hardfault_check_timer);
|
||||
ble_glue->hardfault_check_timer = NULL;
|
||||
|
||||
ble_glue_clear_shared_memory();
|
||||
free(ble_glue);
|
||||
@@ -309,10 +313,13 @@ BleGlueCommandResult ble_glue_force_c2_mode(BleGlueC2Mode desired_mode) {
|
||||
static void ble_sys_status_not_callback(SHCI_TL_CmdStatus_t status) {
|
||||
switch(status) {
|
||||
case SHCI_TL_CmdBusy:
|
||||
furi_mutex_acquire(ble_glue->shci_mtx, FuriWaitForever);
|
||||
furi_check(
|
||||
furi_mutex_acquire(
|
||||
ble_glue->shci_mtx, furi_kernel_is_running() ? FuriWaitForever : 0) ==
|
||||
FuriStatusOk);
|
||||
break;
|
||||
case SHCI_TL_CmdAvailable:
|
||||
furi_mutex_release(ble_glue->shci_mtx);
|
||||
furi_check(furi_mutex_release(ble_glue->shci_mtx) == FuriStatusOk);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
@@ -129,7 +129,7 @@ BleEventFlowStatus ble_event_app_notification(void* pckt) {
|
||||
event_pckt = (hci_event_pckt*)((hci_uart_pckt*)pckt)->data;
|
||||
|
||||
furi_check(gap);
|
||||
furi_mutex_acquire(gap->state_mutex, FuriWaitForever);
|
||||
furi_check(furi_mutex_acquire(gap->state_mutex, FuriWaitForever) == FuriStatusOk);
|
||||
|
||||
switch(event_pckt->evt) {
|
||||
case HCI_DISCONNECTION_COMPLETE_EVT_CODE: {
|
||||
@@ -304,7 +304,7 @@ BleEventFlowStatus ble_event_app_notification(void* pckt) {
|
||||
break;
|
||||
}
|
||||
|
||||
furi_mutex_release(gap->state_mutex);
|
||||
furi_check(furi_mutex_release(gap->state_mutex) == FuriStatusOk);
|
||||
|
||||
return BleEventFlowEnable;
|
||||
}
|
||||
@@ -490,7 +490,7 @@ static void gap_advertise_stop(void) {
|
||||
}
|
||||
|
||||
void gap_start_advertising(void) {
|
||||
furi_mutex_acquire(gap->state_mutex, FuriWaitForever);
|
||||
furi_check(furi_mutex_acquire(gap->state_mutex, FuriWaitForever) == FuriStatusOk);
|
||||
if(gap->state == GapStateIdle) {
|
||||
gap->state = GapStateStartingAdv;
|
||||
FURI_LOG_I(TAG, "Start advertising");
|
||||
@@ -498,18 +498,18 @@ void gap_start_advertising(void) {
|
||||
GapCommand command = GapCommandAdvFast;
|
||||
furi_check(furi_message_queue_put(gap->command_queue, &command, 0) == FuriStatusOk);
|
||||
}
|
||||
furi_mutex_release(gap->state_mutex);
|
||||
furi_check(furi_mutex_release(gap->state_mutex) == FuriStatusOk);
|
||||
}
|
||||
|
||||
void gap_stop_advertising(void) {
|
||||
furi_mutex_acquire(gap->state_mutex, FuriWaitForever);
|
||||
furi_check(furi_mutex_acquire(gap->state_mutex, FuriWaitForever) == FuriStatusOk);
|
||||
if(gap->state > GapStateIdle) {
|
||||
FURI_LOG_I(TAG, "Stop advertising");
|
||||
gap->enable_adv = false;
|
||||
GapCommand command = GapCommandAdvStop;
|
||||
furi_check(furi_message_queue_put(gap->command_queue, &command, 0) == FuriStatusOk);
|
||||
}
|
||||
furi_mutex_release(gap->state_mutex);
|
||||
furi_check(furi_mutex_release(gap->state_mutex) == FuriStatusOk);
|
||||
}
|
||||
|
||||
static void gap_advetise_timer_callback(void* context) {
|
||||
@@ -566,9 +566,9 @@ bool gap_init(GapConfig* config, GapEventCallback on_event_cb, void* context) {
|
||||
GapState gap_get_state(void) {
|
||||
GapState state;
|
||||
if(gap) {
|
||||
furi_mutex_acquire(gap->state_mutex, FuriWaitForever);
|
||||
furi_check(furi_mutex_acquire(gap->state_mutex, FuriWaitForever) == FuriStatusOk);
|
||||
state = gap->state;
|
||||
furi_mutex_release(gap->state_mutex);
|
||||
furi_check(furi_mutex_release(gap->state_mutex) == FuriStatusOk);
|
||||
} else {
|
||||
state = GapStateUninitialized;
|
||||
}
|
||||
@@ -577,17 +577,21 @@ GapState gap_get_state(void) {
|
||||
|
||||
void gap_thread_stop(void) {
|
||||
if(gap) {
|
||||
furi_mutex_acquire(gap->state_mutex, FuriWaitForever);
|
||||
furi_check(furi_mutex_acquire(gap->state_mutex, FuriWaitForever) == FuriStatusOk);
|
||||
gap->enable_adv = false;
|
||||
GapCommand command = GapCommandKillThread;
|
||||
furi_message_queue_put(gap->command_queue, &command, FuriWaitForever);
|
||||
furi_mutex_release(gap->state_mutex);
|
||||
furi_check(furi_mutex_release(gap->state_mutex) == FuriStatusOk);
|
||||
furi_thread_join(gap->thread);
|
||||
furi_thread_free(gap->thread);
|
||||
gap->thread = NULL;
|
||||
// Free resources
|
||||
furi_mutex_free(gap->state_mutex);
|
||||
gap->state_mutex = NULL;
|
||||
furi_message_queue_free(gap->command_queue);
|
||||
gap->command_queue = NULL;
|
||||
furi_timer_free(gap->advertise_timer);
|
||||
gap->advertise_timer = NULL;
|
||||
|
||||
ble_event_dispatcher_reset();
|
||||
free(gap);
|
||||
@@ -604,7 +608,7 @@ static int32_t gap_app(void* context) {
|
||||
FURI_LOG_E(TAG, "Message queue get error: %d", status);
|
||||
continue;
|
||||
}
|
||||
furi_mutex_acquire(gap->state_mutex, FuriWaitForever);
|
||||
furi_check(furi_mutex_acquire(gap->state_mutex, FuriWaitForever) == FuriStatusOk);
|
||||
if(command == GapCommandKillThread) {
|
||||
break;
|
||||
}
|
||||
@@ -615,7 +619,7 @@ static int32_t gap_app(void* context) {
|
||||
} else if(command == GapCommandAdvStop) {
|
||||
gap_advertise_stop();
|
||||
}
|
||||
furi_mutex_release(gap->state_mutex);
|
||||
furi_check(furi_mutex_release(gap->state_mutex) == FuriStatusOk);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user