[FL-2219, FL-2251] System, FuriCore, FuriHal: various bug fixes and improvements (#986)
* Replace irq shenanigans with critical section * Power: halt system on power off instead of crash. * Gui: properly handle input event on NULL current_view * FuriHal: correct gpio configuration sequence * FuriHal: cleanup uart initialization. Makefile: allow to disable thread support. * Loader: improve locking, fix simultaneous app start crash, full command line args support for gui apps, more consistent insomnia * Loader: correct spelling * FuriHal: increase gpio configuration readability * FuriHal: correct gpio configuration error when mode is GpioModeEventRiseFall Co-authored-by: DrZlo13 <who.just.the.doctor@gmail.com>
This commit is contained in:
@@ -31,9 +31,9 @@ int WIEGAND::getWiegandType() {
|
||||
|
||||
bool WIEGAND::available() {
|
||||
bool ret;
|
||||
__disable_irq();
|
||||
FURI_CRITICAL_ENTER();
|
||||
ret = DoWiegandConversion();
|
||||
__enable_irq();
|
||||
FURI_CRITICAL_EXIT();
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -221,4 +221,4 @@ bool WIEGAND::DoWiegandConversion() {
|
||||
}
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@@ -37,7 +37,7 @@ bool AccessorSceneStart::on_event(AccessorApp* app, AccessorEvent* event) {
|
||||
data[i] = wiegand->getCodeHigh() >> ((i - 4) * 8);
|
||||
}
|
||||
} else {
|
||||
__disable_irq();
|
||||
FURI_CRITICAL_ENTER();
|
||||
if(onewire->reset()) {
|
||||
type = 255;
|
||||
onewire->write(0x33);
|
||||
@@ -49,7 +49,7 @@ bool AccessorSceneStart::on_event(AccessorApp* app, AccessorEvent* event) {
|
||||
data[i] = data[i + 1];
|
||||
}
|
||||
}
|
||||
__enable_irq();
|
||||
FURI_CRITICAL_EXIT();
|
||||
}
|
||||
|
||||
if(type > 0) {
|
||||
@@ -85,4 +85,4 @@ void AccessorSceneStart::on_exit(AccessorApp* app) {
|
||||
Popup* popup = app->get_view_manager()->get_popup();
|
||||
popup_set_header(popup, NULL, 0, 0, AlignCenter, AlignBottom);
|
||||
popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignTop);
|
||||
}
|
||||
}
|
||||
|
@@ -4,6 +4,8 @@
|
||||
#include "../helpers/archive_browser.h"
|
||||
#include "../views/archive_browser_view.h"
|
||||
|
||||
#define TAG "ArchiveSceneBrowser"
|
||||
|
||||
static const char* flipper_app_name[] = {
|
||||
[ArchiveFileTypeIButton] = "iButton",
|
||||
[ArchiveFileTypeNFC] = "NFC",
|
||||
@@ -25,7 +27,12 @@ static void archive_run_in_app(
|
||||
} else {
|
||||
string_init_set(full_path, selected->name);
|
||||
}
|
||||
loader_start(loader, flipper_app_name[selected->type], string_get_cstr(full_path));
|
||||
|
||||
LoaderStatus status =
|
||||
loader_start(loader, flipper_app_name[selected->type], string_get_cstr(full_path));
|
||||
if(status != LoaderStatusOk) {
|
||||
FURI_LOG_E(TAG, "loader_start failed: %d", status);
|
||||
}
|
||||
|
||||
string_clear(full_path);
|
||||
furi_record_close("loader");
|
||||
|
@@ -9,6 +9,8 @@
|
||||
#include "desktop_scene.h"
|
||||
#include "desktop_scene_i.h"
|
||||
|
||||
#define TAG "DesktopSrv"
|
||||
|
||||
#define MAIN_VIEW_DEFAULT (0UL)
|
||||
|
||||
static void desktop_scene_main_app_started_callback(const void* message, void* context) {
|
||||
@@ -142,10 +144,12 @@ bool desktop_scene_main_on_event(void* context, SceneManagerEvent event) {
|
||||
Loader* loader = furi_record_open("loader");
|
||||
LoaderStatus status =
|
||||
loader_start(loader, FLIPPER_APPS[desktop->settings.favorite].name, NULL);
|
||||
furi_check(status == LoaderStatusOk);
|
||||
if(status != LoaderStatusOk) {
|
||||
FURI_LOG_E(TAG, "loader_start failed: %d", status);
|
||||
}
|
||||
furi_record_close("loader");
|
||||
} else {
|
||||
FURI_LOG_E("DesktopSrv", "Can't find favorite application");
|
||||
FURI_LOG_E(TAG, "Can't find favorite application");
|
||||
}
|
||||
consumed = true;
|
||||
break;
|
||||
|
@@ -253,27 +253,26 @@ void view_dispatcher_handle_input(ViewDispatcher* view_dispatcher, InputEvent* e
|
||||
}
|
||||
|
||||
// Deliver event
|
||||
if(view_dispatcher->ongoing_input_view == view_dispatcher->current_view) {
|
||||
bool is_consumed = false;
|
||||
if(view_dispatcher->current_view) {
|
||||
is_consumed = view_input(view_dispatcher->current_view, event);
|
||||
}
|
||||
if(!is_consumed && (event->type == InputTypeShort || event->type == InputTypeLong)) {
|
||||
// TODO remove view navigation handlers
|
||||
uint32_t view_id = VIEW_IGNORE;
|
||||
if(event->key == InputKeyBack) {
|
||||
view_id = view_previous(view_dispatcher->current_view);
|
||||
if((view_id == VIEW_IGNORE) && (view_dispatcher->navigation_event_callback)) {
|
||||
is_consumed =
|
||||
view_dispatcher->navigation_event_callback(view_dispatcher->event_context);
|
||||
if(!is_consumed) {
|
||||
view_dispatcher_stop(view_dispatcher);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!is_consumed) {
|
||||
if(view_dispatcher->current_view &&
|
||||
view_dispatcher->ongoing_input_view == view_dispatcher->current_view) {
|
||||
// Dispatch input to current view
|
||||
bool is_consumed = view_input(view_dispatcher->current_view, event);
|
||||
|
||||
// Navigate if input is not consumed
|
||||
if(!is_consumed && (event->key == InputKeyBack) &&
|
||||
(event->type == InputTypeShort || event->type == InputTypeLong)) {
|
||||
// Navigate to previous
|
||||
uint32_t view_id = view_previous(view_dispatcher->current_view);
|
||||
if(view_id != VIEW_IGNORE) {
|
||||
// Switch to returned view
|
||||
view_dispatcher_switch_to_view(view_dispatcher, view_id);
|
||||
} else if(view_dispatcher->navigation_event_callback) {
|
||||
// Dispatch navigation event
|
||||
if(!view_dispatcher->navigation_event_callback(view_dispatcher->event_context)) {
|
||||
// TODO: should we allow view_dispatcher to stop without navigation_event_callback?
|
||||
view_dispatcher_stop(view_dispatcher);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if(view_dispatcher->ongoing_input_view && event->type == InputTypeRelease) {
|
||||
|
@@ -59,9 +59,8 @@ KeyReader::~KeyReader() {
|
||||
bool KeyReader::read_key(iButtonKeyType* key_type, uint8_t* data, uint8_t data_size) {
|
||||
bool readed = false;
|
||||
|
||||
switch(read_mode) {
|
||||
case ReadMode::DALLAS:
|
||||
__disable_irq();
|
||||
if(read_mode == ReadMode::DALLAS) {
|
||||
FURI_CRITICAL_ENTER();
|
||||
if(onewire_master->search(data)) {
|
||||
onewire_master->reset_search();
|
||||
readed = true;
|
||||
@@ -69,9 +68,8 @@ bool KeyReader::read_key(iButtonKeyType* key_type, uint8_t* data, uint8_t data_s
|
||||
} else {
|
||||
onewire_master->reset_search();
|
||||
}
|
||||
__enable_irq();
|
||||
break;
|
||||
case ReadMode::CYFRAL_METAKOM:
|
||||
FURI_CRITICAL_EXIT();
|
||||
} else if(read_mode == ReadMode::CYFRAL_METAKOM) {
|
||||
if(cyfral_decoder.read(data, 2)) {
|
||||
readed = true;
|
||||
*key_type = iButtonKeyType::KeyCyfral;
|
||||
@@ -79,7 +77,6 @@ bool KeyReader::read_key(iButtonKeyType* key_type, uint8_t* data, uint8_t data_s
|
||||
readed = true;
|
||||
*key_type = iButtonKeyType::KeyMetakom;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return readed;
|
||||
@@ -88,10 +85,10 @@ bool KeyReader::read_key(iButtonKeyType* key_type, uint8_t* data, uint8_t data_s
|
||||
bool KeyReader::verify_key(iButtonKeyType key_type, const uint8_t* const data, uint8_t data_size) {
|
||||
bool result = true;
|
||||
|
||||
switch(key_type) {
|
||||
case iButtonKeyType::KeyDallas:
|
||||
if(key_type == iButtonKeyType::KeyDallas) {
|
||||
switch_to(ReadMode::DALLAS);
|
||||
__disable_irq();
|
||||
|
||||
FURI_CRITICAL_ENTER();
|
||||
if(onewire_master->reset()) {
|
||||
onewire_master->write(DS1990::CMD_READ_ROM);
|
||||
for(uint8_t i = 0; i < data_size; i++) {
|
||||
@@ -101,14 +98,11 @@ bool KeyReader::verify_key(iButtonKeyType key_type, const uint8_t* const data, u
|
||||
}
|
||||
} else {
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
__enable_irq();
|
||||
break;
|
||||
FURI_CRITICAL_EXIT();
|
||||
|
||||
default:
|
||||
} else {
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@@ -74,7 +74,7 @@ bool KeyWriter::compare_key_ds1990(iButtonKey* key) {
|
||||
bool result = false;
|
||||
|
||||
if(key->get_key_type() == iButtonKeyType::KeyDallas) {
|
||||
__disable_irq();
|
||||
FURI_CRITICAL_ENTER();
|
||||
bool presence = onewire_master->reset();
|
||||
|
||||
if(presence) {
|
||||
@@ -89,7 +89,7 @@ bool KeyWriter::compare_key_ds1990(iButtonKey* key) {
|
||||
}
|
||||
}
|
||||
|
||||
__enable_irq();
|
||||
FURI_CRITICAL_EXIT();
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -99,7 +99,7 @@ bool KeyWriter::write_1990_1(iButtonKey* key) {
|
||||
bool result = false;
|
||||
|
||||
if(key->get_key_type() == iButtonKeyType::KeyDallas) {
|
||||
__disable_irq();
|
||||
FURI_CRITICAL_ENTER();
|
||||
|
||||
// unlock
|
||||
onewire_master->reset();
|
||||
@@ -120,7 +120,7 @@ bool KeyWriter::write_1990_1(iButtonKey* key) {
|
||||
onewire_master->write(RW1990_1::CMD_WRITE_RECORD_FLAG);
|
||||
onewire_write_one_bit(1);
|
||||
|
||||
__enable_irq();
|
||||
FURI_CRITICAL_EXIT();
|
||||
|
||||
if(compare_key_ds1990(key)) {
|
||||
result = true;
|
||||
@@ -134,7 +134,7 @@ bool KeyWriter::write_1990_2(iButtonKey* key) {
|
||||
bool result = false;
|
||||
|
||||
if(key->get_key_type() == iButtonKeyType::KeyDallas) {
|
||||
__disable_irq();
|
||||
FURI_CRITICAL_ENTER();
|
||||
|
||||
// unlock
|
||||
onewire_master->reset();
|
||||
@@ -154,7 +154,7 @@ bool KeyWriter::write_1990_2(iButtonKey* key) {
|
||||
onewire_master->write(RW1990_2::CMD_WRITE_RECORD_FLAG);
|
||||
onewire_write_one_bit(0);
|
||||
|
||||
__enable_irq();
|
||||
FURI_CRITICAL_EXIT();
|
||||
|
||||
if(compare_key_ds1990(key)) {
|
||||
result = true;
|
||||
@@ -169,7 +169,7 @@ bool KeyWriter::write_TM2004(iButtonKey* key) {
|
||||
bool result = true;
|
||||
|
||||
if(key->get_key_type() == iButtonKeyType::KeyDallas) {
|
||||
__disable_irq();
|
||||
FURI_CRITICAL_ENTER();
|
||||
|
||||
// write rom, addr is 0x0000
|
||||
onewire_master->reset();
|
||||
@@ -204,7 +204,7 @@ bool KeyWriter::write_TM2004(iButtonKey* key) {
|
||||
|
||||
onewire_master->reset();
|
||||
|
||||
__enable_irq();
|
||||
FURI_CRITICAL_EXIT();
|
||||
} else {
|
||||
result = false;
|
||||
}
|
||||
@@ -216,7 +216,7 @@ bool KeyWriter::write_TM01(iButtonKey* key) {
|
||||
/*bool result = true;
|
||||
|
||||
// TODO test and encoding
|
||||
__disable_irq();
|
||||
FURI_CRITICAL_ENTER();
|
||||
|
||||
// unlock
|
||||
onewire_master->reset();
|
||||
@@ -240,13 +240,13 @@ bool KeyWriter::write_TM01(iButtonKey* key) {
|
||||
onewire_master->write(TM01::CMD_WRITE_RECORD_FLAG);
|
||||
onewire_write_one_bit(0, 10000);
|
||||
|
||||
__enable_irq();
|
||||
FURI_CRITICAL_EXIT();
|
||||
|
||||
if(!compare_key_ds1990(key)) {
|
||||
result = false;
|
||||
}
|
||||
|
||||
__disable_irq();
|
||||
FURI_CRITICAL_ENTER();
|
||||
|
||||
if(key->get_key_type() == iButtonKeyType::KeyMetakom ||
|
||||
key->get_key_type() == iButtonKeyType::KeyCyfral) {
|
||||
@@ -258,7 +258,7 @@ bool KeyWriter::write_TM01(iButtonKey* key) {
|
||||
onewire_write_one_bit(1);
|
||||
}
|
||||
|
||||
__enable_irq();
|
||||
FURI_CRITICAL_EXIT();
|
||||
|
||||
return result;*/
|
||||
return false;
|
||||
@@ -275,4 +275,4 @@ void KeyWriter::write_byte_ds1990(uint8_t data) {
|
||||
delay_us(5000);
|
||||
data = data >> 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -121,12 +121,12 @@ void RfidWriter::write_em(const uint8_t em_data[5]) {
|
||||
em_card.encode(em_data, 5, reinterpret_cast<uint8_t*>(&em_encoded_data), sizeof(uint64_t));
|
||||
const uint32_t em_config_block_data = 0b00000000000101001000000001000000;
|
||||
|
||||
__disable_irq();
|
||||
FURI_CRITICAL_ENTER();
|
||||
write_block(0, 0, false, em_config_block_data);
|
||||
write_block(0, 1, false, em_encoded_data);
|
||||
write_block(0, 2, false, em_encoded_data >> 32);
|
||||
write_reset();
|
||||
__enable_irq();
|
||||
FURI_CRITICAL_EXIT();
|
||||
}
|
||||
|
||||
void RfidWriter::write_hid(const uint8_t hid_data[3]) {
|
||||
@@ -136,13 +136,13 @@ void RfidWriter::write_hid(const uint8_t hid_data[3]) {
|
||||
|
||||
const uint32_t hid_config_block_data = 0b00000000000100000111000001100000;
|
||||
|
||||
__disable_irq();
|
||||
FURI_CRITICAL_ENTER();
|
||||
write_block(0, 0, false, hid_config_block_data);
|
||||
write_block(0, 1, false, card_data[0]);
|
||||
write_block(0, 2, false, card_data[1]);
|
||||
write_block(0, 3, false, card_data[2]);
|
||||
write_reset();
|
||||
__enable_irq();
|
||||
FURI_CRITICAL_EXIT();
|
||||
}
|
||||
|
||||
void RfidWriter::write_indala(const uint8_t indala_data[3]) {
|
||||
@@ -153,10 +153,10 @@ void RfidWriter::write_indala(const uint8_t indala_data[3]) {
|
||||
|
||||
const uint32_t indala_config_block_data = 0b00000000000010000001000001000000;
|
||||
|
||||
__disable_irq();
|
||||
FURI_CRITICAL_ENTER();
|
||||
write_block(0, 0, false, indala_config_block_data);
|
||||
write_block(0, 1, false, card_data[0]);
|
||||
write_block(0, 2, false, card_data[1]);
|
||||
write_reset();
|
||||
__enable_irq();
|
||||
FURI_CRITICAL_EXIT();
|
||||
}
|
||||
|
@@ -9,28 +9,46 @@
|
||||
|
||||
static Loader* loader_instance = NULL;
|
||||
|
||||
static bool
|
||||
loader_start_application(const FlipperApplication* application, const char* arguments) {
|
||||
loader_instance->application = application;
|
||||
|
||||
furi_assert(loader_instance->application_arguments == NULL);
|
||||
if(arguments && strlen(arguments) > 0) {
|
||||
loader_instance->application_arguments = strdup(arguments);
|
||||
}
|
||||
|
||||
FURI_LOG_I(TAG, "Starting: %s", loader_instance->application->name);
|
||||
|
||||
furi_thread_set_name(loader_instance->application_thread, loader_instance->application->name);
|
||||
furi_thread_set_stack_size(
|
||||
loader_instance->application_thread, loader_instance->application->stack_size);
|
||||
furi_thread_set_context(
|
||||
loader_instance->application_thread, loader_instance->application_arguments);
|
||||
furi_thread_set_callback(
|
||||
loader_instance->application_thread, loader_instance->application->app);
|
||||
|
||||
bool result = furi_thread_start(loader_instance->application_thread);
|
||||
|
||||
if(!result) {
|
||||
loader_instance->application = NULL;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static void loader_menu_callback(void* _ctx, uint32_t index) {
|
||||
const FlipperApplication* flipper_app = _ctx;
|
||||
const FlipperApplication* application = _ctx;
|
||||
|
||||
furi_assert(flipper_app->app);
|
||||
furi_assert(flipper_app->name);
|
||||
furi_assert(application->app);
|
||||
furi_assert(application->name);
|
||||
|
||||
if(!loader_lock(loader_instance)) return;
|
||||
|
||||
if(furi_thread_get_state(loader_instance->thread) != FuriThreadStateStopped) {
|
||||
FURI_LOG_E(TAG, "Can't start app. %s is running", loader_instance->current_app->name);
|
||||
if(!loader_lock(loader_instance)) {
|
||||
FURI_LOG_E(TAG, "Loader is locked");
|
||||
return;
|
||||
}
|
||||
furi_hal_power_insomnia_enter();
|
||||
|
||||
loader_instance->current_app = flipper_app;
|
||||
|
||||
FURI_LOG_I(TAG, "Starting: %s", loader_instance->current_app->name);
|
||||
furi_thread_set_name(loader_instance->thread, flipper_app->name);
|
||||
furi_thread_set_stack_size(loader_instance->thread, flipper_app->stack_size);
|
||||
furi_thread_set_context(loader_instance->thread, NULL);
|
||||
furi_thread_set_callback(loader_instance->thread, flipper_app->app);
|
||||
furi_thread_start(loader_instance->thread);
|
||||
loader_start_application(application, NULL);
|
||||
}
|
||||
|
||||
static void loader_submenu_callback(void* context, uint32_t index) {
|
||||
@@ -73,32 +91,36 @@ const FlipperApplication* loader_find_application_by_name(const char* name) {
|
||||
}
|
||||
|
||||
void loader_cli_open(Cli* cli, string_t args, Loader* instance) {
|
||||
string_strim(args);
|
||||
string_t application_name;
|
||||
string_init(application_name);
|
||||
|
||||
if(string_size(args) == 0) {
|
||||
printf("No application provided\r\n");
|
||||
return;
|
||||
}
|
||||
do {
|
||||
if(!args_read_probably_quoted_string_and_trim(args, application_name)) {
|
||||
printf("No application provided\r\n");
|
||||
break;
|
||||
}
|
||||
|
||||
const FlipperApplication* application = loader_find_application_by_name(string_get_cstr(args));
|
||||
if(!application) {
|
||||
printf("%s doesn't exists\r\n", string_get_cstr(args));
|
||||
return;
|
||||
}
|
||||
const FlipperApplication* application =
|
||||
loader_find_application_by_name(string_get_cstr(application_name));
|
||||
if(!application) {
|
||||
printf("%s doesn't exists\r\n", string_get_cstr(application_name));
|
||||
break;
|
||||
}
|
||||
|
||||
if(furi_thread_get_state(instance->thread) != FuriThreadStateStopped) {
|
||||
printf("Can't start, furi application is running");
|
||||
return;
|
||||
}
|
||||
string_strim(args);
|
||||
if(!loader_start_application(application, string_get_cstr(args))) {
|
||||
printf("Can't start, furi application is running");
|
||||
return;
|
||||
} else {
|
||||
// We must to increment lock counter to keep balance
|
||||
// TODO: rewrite whole thing, it's complex as hell
|
||||
FURI_CRITICAL_ENTER();
|
||||
instance->lock_count++;
|
||||
FURI_CRITICAL_EXIT();
|
||||
}
|
||||
} while(false);
|
||||
|
||||
instance->lock_semaphore++;
|
||||
furi_hal_power_insomnia_enter();
|
||||
instance->current_app = application;
|
||||
printf("Starting: %s\r\n", instance->current_app->name);
|
||||
furi_thread_set_name(instance->thread, application->name);
|
||||
furi_thread_set_stack_size(instance->thread, application->stack_size);
|
||||
furi_thread_set_callback(instance->thread, application->app);
|
||||
furi_thread_start(instance->thread);
|
||||
string_clear(application_name);
|
||||
}
|
||||
|
||||
void loader_cli_list(Cli* cli, string_t args, Loader* instance) {
|
||||
@@ -152,62 +174,44 @@ void loader_cli(Cli* cli, string_t args, void* _ctx) {
|
||||
LoaderStatus loader_start(Loader* instance, const char* name, const char* args) {
|
||||
furi_assert(name);
|
||||
|
||||
const FlipperApplication* flipper_app = loader_find_application_by_name(name);
|
||||
const FlipperApplication* application = loader_find_application_by_name(name);
|
||||
|
||||
if(!flipper_app) {
|
||||
if(!application) {
|
||||
FURI_LOG_E(TAG, "Can't find application with name %s", name);
|
||||
return LoaderStatusErrorUnknownApp;
|
||||
}
|
||||
|
||||
bool locked = loader_lock(instance);
|
||||
|
||||
if(!locked || (furi_thread_get_state(instance->thread) != FuriThreadStateStopped)) {
|
||||
FURI_LOG_E(TAG, "Can't start app. %s is running", instance->current_app->name);
|
||||
/* no need to call loader_unlock() - it is called as soon as application stops */
|
||||
if(!loader_lock(loader_instance)) {
|
||||
FURI_LOG_E(TAG, "Loader is locked");
|
||||
return LoaderStatusErrorAppStarted;
|
||||
}
|
||||
|
||||
instance->current_app = flipper_app;
|
||||
void* thread_args = NULL;
|
||||
if(args) {
|
||||
string_set_str(instance->args, args);
|
||||
string_strim(instance->args);
|
||||
thread_args = (void*)string_get_cstr(instance->args);
|
||||
FURI_LOG_I(TAG, "Start %s app with args: %s", name, args);
|
||||
} else {
|
||||
string_reset(instance->args);
|
||||
FURI_LOG_I(TAG, "Start %s app with no args", name);
|
||||
if(!loader_start_application(application, args)) {
|
||||
return LoaderStatusErrorInternal;
|
||||
}
|
||||
|
||||
furi_thread_set_name(instance->thread, flipper_app->name);
|
||||
furi_thread_set_stack_size(instance->thread, flipper_app->stack_size);
|
||||
furi_thread_set_context(instance->thread, thread_args);
|
||||
furi_thread_set_callback(instance->thread, flipper_app->app);
|
||||
|
||||
bool thread_started = furi_thread_start(instance->thread);
|
||||
return thread_started ? LoaderStatusOk : LoaderStatusErrorInternal;
|
||||
return LoaderStatusOk;
|
||||
}
|
||||
|
||||
bool loader_lock(Loader* instance) {
|
||||
bool ret = false;
|
||||
furi_check(osMutexAcquire(instance->mutex, osWaitForever) == osOK);
|
||||
if(instance->lock_semaphore == 0) {
|
||||
instance->lock_semaphore++;
|
||||
ret = true;
|
||||
FURI_CRITICAL_ENTER();
|
||||
bool result = false;
|
||||
if(instance->lock_count == 0) {
|
||||
instance->lock_count++;
|
||||
result = true;
|
||||
}
|
||||
furi_check(osMutexRelease(instance->mutex) == osOK);
|
||||
return ret;
|
||||
FURI_CRITICAL_EXIT();
|
||||
return result;
|
||||
}
|
||||
|
||||
void loader_unlock(Loader* instance) {
|
||||
furi_check(osMutexAcquire(instance->mutex, osWaitForever) == osOK);
|
||||
furi_check(instance->lock_semaphore > 0);
|
||||
instance->lock_semaphore--;
|
||||
furi_check(osMutexRelease(instance->mutex) == osOK);
|
||||
FURI_CRITICAL_ENTER();
|
||||
if(instance->lock_count > 0) instance->lock_count--;
|
||||
FURI_CRITICAL_EXIT();
|
||||
}
|
||||
|
||||
bool loader_is_locked(Loader* instance) {
|
||||
return (instance->lock_semaphore > 0);
|
||||
return instance->lock_count > 0;
|
||||
}
|
||||
|
||||
static void loader_thread_state_callback(FuriThreadState thread_state, void* context) {
|
||||
@@ -219,6 +223,7 @@ static void loader_thread_state_callback(FuriThreadState thread_state, void* con
|
||||
if(thread_state == FuriThreadStateRunning) {
|
||||
event.type = LoaderEventTypeApplicationStarted;
|
||||
furi_pubsub_publish(loader_instance->pubsub, &event);
|
||||
furi_hal_power_insomnia_enter();
|
||||
|
||||
// Snapshot current memory usage
|
||||
instance->free_heap_size = memmgr_get_free_heap();
|
||||
@@ -239,7 +244,13 @@ static void loader_thread_state_callback(FuriThreadState thread_state, void* con
|
||||
TAG,
|
||||
"Application thread stopped. Heap allocation balance: %d. Thread allocation balance: %d.",
|
||||
heap_diff,
|
||||
furi_thread_get_heap_size(instance->thread));
|
||||
furi_thread_get_heap_size(instance->application_thread));
|
||||
|
||||
if(loader_instance->application_arguments) {
|
||||
free(loader_instance->application_arguments);
|
||||
loader_instance->application_arguments = NULL;
|
||||
}
|
||||
|
||||
furi_hal_power_insomnia_exit();
|
||||
loader_unlock(instance);
|
||||
|
||||
@@ -262,15 +273,12 @@ static uint32_t loader_back_to_primary_menu(void* context) {
|
||||
static Loader* loader_alloc() {
|
||||
Loader* instance = furi_alloc(sizeof(Loader));
|
||||
|
||||
instance->thread = furi_thread_alloc();
|
||||
furi_thread_enable_heap_trace(instance->thread);
|
||||
furi_thread_set_state_context(instance->thread, instance);
|
||||
furi_thread_set_state_callback(instance->thread, loader_thread_state_callback);
|
||||
|
||||
string_init(instance->args);
|
||||
instance->application_thread = furi_thread_alloc();
|
||||
furi_thread_enable_heap_trace(instance->application_thread);
|
||||
furi_thread_set_state_context(instance->application_thread, instance);
|
||||
furi_thread_set_state_callback(instance->application_thread, loader_thread_state_callback);
|
||||
|
||||
instance->pubsub = furi_pubsub_alloc();
|
||||
instance->mutex = osMutexNew(NULL);
|
||||
|
||||
#ifdef SRV_CLI
|
||||
instance->cli = furi_record_open("cli");
|
||||
@@ -327,13 +335,9 @@ static void loader_free(Loader* instance) {
|
||||
furi_record_close("cli");
|
||||
}
|
||||
|
||||
osMutexDelete(instance->mutex);
|
||||
|
||||
furi_pubsub_free(instance->pubsub);
|
||||
|
||||
string_clear(instance->args);
|
||||
|
||||
furi_thread_free(instance->thread);
|
||||
furi_thread_free(instance->application_thread);
|
||||
|
||||
menu_free(loader_instance->primary_menu);
|
||||
view_dispatcher_remove_view(loader_instance->view_dispatcher, LoaderMenuViewPrimary);
|
||||
|
@@ -16,9 +16,11 @@
|
||||
|
||||
struct Loader {
|
||||
osThreadId_t loader_thread;
|
||||
FuriThread* thread;
|
||||
const FlipperApplication* current_app;
|
||||
string_t args;
|
||||
|
||||
const FlipperApplication* application;
|
||||
FuriThread* application_thread;
|
||||
char* application_arguments;
|
||||
|
||||
Cli* cli;
|
||||
Gui* gui;
|
||||
|
||||
@@ -29,8 +31,7 @@ struct Loader {
|
||||
Submenu* settings_menu;
|
||||
|
||||
size_t free_heap_size;
|
||||
osMutexId_t mutex;
|
||||
volatile uint8_t lock_semaphore;
|
||||
volatile uint8_t lock_count;
|
||||
|
||||
FuriPubSub* pubsub;
|
||||
};
|
||||
|
@@ -1,28 +1,29 @@
|
||||
#include "power_cli.h"
|
||||
|
||||
#include <power/power_service/power.h>
|
||||
#include <cli/cli.h>
|
||||
#include <furi_hal.h>
|
||||
#include <cli/cli.h>
|
||||
#include <lib/toolbox/args.h>
|
||||
#include <power/power_service/power.h>
|
||||
|
||||
void power_cli_poweroff(Cli* cli, string_t args, void* context) {
|
||||
void power_cli_off(Cli* cli, string_t args) {
|
||||
Power* power = furi_record_open("power");
|
||||
printf("It's now safe to disconnect USB from your flipper\r\n");
|
||||
power_off(power);
|
||||
}
|
||||
|
||||
void power_cli_reboot(Cli* cli, string_t args, void* context) {
|
||||
void power_cli_reboot(Cli* cli, string_t args) {
|
||||
power_reboot(PowerBootModeNormal);
|
||||
}
|
||||
|
||||
void power_cli_dfu(Cli* cli, string_t args, void* context) {
|
||||
void power_cli_reboot2dfu(Cli* cli, string_t args) {
|
||||
power_reboot(PowerBootModeDfu);
|
||||
}
|
||||
|
||||
void power_cli_info(Cli* cli, string_t args, void* context) {
|
||||
void power_cli_debug(Cli* cli, string_t args) {
|
||||
furi_hal_power_dump_state();
|
||||
}
|
||||
|
||||
void power_cli_otg(Cli* cli, string_t args, void* context) {
|
||||
void power_cli_5v(Cli* cli, string_t args) {
|
||||
if(!string_cmp(args, "0")) {
|
||||
furi_hal_power_disable_otg();
|
||||
} else if(!string_cmp(args, "1")) {
|
||||
@@ -32,7 +33,7 @@ void power_cli_otg(Cli* cli, string_t args, void* context) {
|
||||
}
|
||||
}
|
||||
|
||||
void power_cli_ext(Cli* cli, string_t args, void* context) {
|
||||
void power_cli_3v3(Cli* cli, string_t args) {
|
||||
if(!string_cmp(args, "0")) {
|
||||
furi_hal_power_disable_external_3_3v();
|
||||
} else if(!string_cmp(args, "1")) {
|
||||
@@ -42,16 +43,70 @@ void power_cli_ext(Cli* cli, string_t args, void* context) {
|
||||
}
|
||||
}
|
||||
|
||||
static void power_cli_command_print_usage() {
|
||||
printf("Usage:\r\n");
|
||||
printf("power <cmd> <args>\r\n");
|
||||
printf("Cmd list:\r\n");
|
||||
|
||||
printf("\toff\t - shutdown power\r\n");
|
||||
printf("\treboot\t - reboot\r\n");
|
||||
printf("\treboot2dfu\t - reboot to dfu bootloader\r\n");
|
||||
printf("\tdebug\t - show debug information\r\n");
|
||||
printf("\t5v <0 or 1>\t - enable or disable 5v ext\r\n");
|
||||
printf("\t3v3 <0 or 1>\t - enable or disable 3v3 ext\r\n");
|
||||
}
|
||||
|
||||
void power_cli(Cli* cli, string_t args, void* context) {
|
||||
string_t cmd;
|
||||
string_init(cmd);
|
||||
|
||||
do {
|
||||
if(!args_read_string_and_trim(args, cmd)) {
|
||||
power_cli_command_print_usage();
|
||||
break;
|
||||
}
|
||||
|
||||
if(string_cmp_str(cmd, "off") == 0) {
|
||||
power_cli_off(cli, args);
|
||||
break;
|
||||
}
|
||||
|
||||
if(string_cmp_str(cmd, "reboot") == 0) {
|
||||
power_cli_reboot(cli, args);
|
||||
break;
|
||||
}
|
||||
|
||||
if(string_cmp_str(cmd, "reboot2dfu") == 0) {
|
||||
power_cli_reboot2dfu(cli, args);
|
||||
break;
|
||||
}
|
||||
|
||||
if(string_cmp_str(cmd, "debug") == 0) {
|
||||
power_cli_debug(cli, args);
|
||||
break;
|
||||
}
|
||||
|
||||
if(string_cmp_str(cmd, "5v") == 0) {
|
||||
power_cli_5v(cli, args);
|
||||
break;
|
||||
}
|
||||
|
||||
if(string_cmp_str(cmd, "3v3") == 0) {
|
||||
power_cli_3v3(cli, args);
|
||||
break;
|
||||
}
|
||||
|
||||
power_cli_command_print_usage();
|
||||
} while(false);
|
||||
|
||||
string_clear(cmd);
|
||||
}
|
||||
|
||||
void power_on_system_start() {
|
||||
#ifdef SRV_CLI
|
||||
Cli* cli = furi_record_open("cli");
|
||||
|
||||
cli_add_command(cli, "poweroff", CliCommandFlagParallelSafe, power_cli_poweroff, NULL);
|
||||
cli_add_command(cli, "reboot", CliCommandFlagParallelSafe, power_cli_reboot, NULL);
|
||||
cli_add_command(cli, "dfu", CliCommandFlagParallelSafe, power_cli_dfu, NULL);
|
||||
cli_add_command(cli, "power_info", CliCommandFlagParallelSafe, power_cli_info, NULL);
|
||||
cli_add_command(cli, "power_otg", CliCommandFlagParallelSafe, power_cli_otg, NULL);
|
||||
cli_add_command(cli, "power_ext", CliCommandFlagParallelSafe, power_cli_ext, NULL);
|
||||
cli_add_command(cli, "power", CliCommandFlagParallelSafe, power_cli, NULL);
|
||||
|
||||
furi_record_close("cli");
|
||||
#endif
|
||||
|
@@ -10,7 +10,7 @@ void power_off(Power* power) {
|
||||
view_dispatcher_send_to_front(power->view_dispatcher);
|
||||
view_dispatcher_switch_to_view(power->view_dispatcher, PowerViewPopup);
|
||||
osDelay(10);
|
||||
furi_crash("Disconnect USB for safe shutdown");
|
||||
furi_halt("Disconnect USB for safe shutdown");
|
||||
}
|
||||
|
||||
void power_reboot(PowerBootMode mode) {
|
||||
|
Reference in New Issue
Block a user