furi_check - a new way to asserting (#204)

* hal-related task_is_isr_context function
* furi_check implementation
* change application to use furi_check
* add second level of assertion
* add TODO about ISR context
* Applications: refactor furi_check and furi_assert.
* Apploader: propwer widget usage. Menu: check on furi resource request.
* refactor furi_check

Co-authored-by: Aleksandr Kutuzov <aku@plooks.com>
Co-authored-by: coreglitch <mail@s3f.ru>
This commit is contained in:
DrZlo13
2020-10-29 09:27:17 +03:00
committed by GitHub
parent c9b921f6ce
commit 8aeafd8179
24 changed files with 292 additions and 136 deletions

View File

@@ -1,6 +1,7 @@
#include "dispatcher.h"
#include <flipper.h>
#include <flipper_v2.h>
struct Dispatcher {
void* message;
@@ -16,41 +17,41 @@ Dispatcher* dispatcher_alloc(size_t queue_size, size_t message_size) {
dispatcher->message_size = message_size;
dispatcher->mqueue = osMessageQueueNew(queue_size, message_size, NULL);
assert(dispatcher->mqueue);
furi_check(dispatcher->mqueue);
dispatcher->lock_mutex = osMutexNew(NULL);
assert(dispatcher->lock_mutex);
furi_check(dispatcher->lock_mutex);
dispatcher_lock(dispatcher);
return dispatcher;
}
void dispatcher_free(Dispatcher* dispatcher) {
assert(dispatcher);
furi_assert(dispatcher);
free(dispatcher);
}
void dispatcher_send(Dispatcher* dispatcher, Message* message) {
assert(dispatcher);
assert(message);
assert(osMessageQueuePut(dispatcher->mqueue, message, 0, osWaitForever) == osOK);
furi_assert(dispatcher);
furi_assert(message);
furi_check(osMessageQueuePut(dispatcher->mqueue, message, 0, osWaitForever) == osOK);
}
// TODO: bad side-effect
void dispatcher_recieve(Dispatcher* dispatcher, Message* message) {
assert(dispatcher);
assert(message);
furi_assert(dispatcher);
furi_assert(message);
dispatcher_unlock(dispatcher);
assert(osMessageQueueGet(dispatcher->mqueue, message, NULL, osWaitForever) == osOK);
furi_check(osMessageQueueGet(dispatcher->mqueue, message, NULL, osWaitForever) == osOK);
dispatcher_lock(dispatcher);
}
void dispatcher_lock(Dispatcher* dispatcher) {
assert(dispatcher);
assert(osMutexAcquire(dispatcher->lock_mutex, osWaitForever) == osOK);
furi_assert(dispatcher);
furi_check(osMutexAcquire(dispatcher->lock_mutex, osWaitForever) == osOK);
}
void dispatcher_unlock(Dispatcher* dispatcher) {
assert(dispatcher);
assert(osMutexRelease(dispatcher->lock_mutex) == osOK);
furi_assert(dispatcher);
furi_check(osMutexRelease(dispatcher->lock_mutex) == osOK);
}

View File

@@ -1,6 +1,5 @@
#include "nfc.h"
#include <assert.h>
#include <flipper_v2.h>
#include <gui/gui.h>
@@ -152,7 +151,9 @@ void nfc_worker_task(void* context) {
}
void nfc_draw_callback(CanvasApi* canvas, void* context) {
assert(context);
furi_assert(canvas);
furi_assert(context);
Nfc* nfc = context;
dispatcher_lock(nfc->dispatcher);
@@ -187,7 +188,8 @@ void nfc_draw_callback(CanvasApi* canvas, void* context) {
}
void nfc_input_callback(InputEvent* event, void* context) {
assert(context);
furi_assert(event);
furi_assert(context);
Nfc* nfc = context;
if(!event->state) return;
@@ -196,7 +198,7 @@ void nfc_input_callback(InputEvent* event, void* context) {
}
void nfc_test_callback(void* context) {
assert(context);
furi_assert(context);
Nfc* nfc = context;
dispatcher_lock(nfc->dispatcher);
@@ -213,21 +215,21 @@ void nfc_test_callback(void* context) {
}
void nfc_read_callback(void* context) {
assert(context);
furi_assert(context);
Nfc* nfc = context;
nfc->screen = 1;
widget_enabled_set(nfc->widget, true);
}
void nfc_write_callback(void* context) {
assert(context);
furi_assert(context);
Nfc* nfc = context;
nfc->screen = 1;
widget_enabled_set(nfc->widget, true);
}
void nfc_bridge_callback(void* context) {
assert(context);
furi_assert(context);
Nfc* nfc = context;
nfc->screen = 1;
widget_enabled_set(nfc->widget, true);
@@ -244,7 +246,7 @@ Nfc* nfc_alloc() {
widget_input_callback_set(nfc->widget, nfc_input_callback, nfc);
nfc->menu_vm = furi_open("menu");
assert(nfc->menu_vm);
furi_check(nfc->menu_vm);
nfc->menu = menu_item_alloc_menu("NFC", nfc->icon);
menu_item_subitem_add(
@@ -266,9 +268,9 @@ void nfc_task(void* p) {
Nfc* nfc = nfc_alloc();
FuriRecordSubscriber* gui_record = furi_open_deprecated("gui", false, false, NULL, NULL, NULL);
assert(gui_record);
furi_check(gui_record);
GuiApi* gui = furi_take(gui_record);
assert(gui);
furi_check(gui);
widget_enabled_set(nfc->widget, false);
gui->add_widget(gui, nfc->widget, GuiLayerFullscreen);
furi_commit(gui_record);