[FL-140] Core api dynamic records (#296)
* SYSTEM: tickless mode with deep sleep. * Move FreeRTOS ticks to lptim2 * API: move all sumbodules init routines to one place. Timebase: working lptim2 at tick source. * API Timebase: lp-timer routines, timer access safe zones prediction and synchronization. FreeRTOS: adjust configuration for tickless mode. * NFC: support for tickless mode. * API Timebase: improve tick error handling in IRQ. Apploader: use insomnia mode to run applications. * BLE: prevent sleep while core2 starting * HAL: nap while in insomnia mode * init records work * try to implement record delete * tests and flapp * flapp subsystem * new core functions to get app stat, simplify core code * fix thread termination * add strdup to core * fix tests * Refactoring: remove all unusued parts, update API usage, aggreagate API sources and headers, new record storage * Refactoring: update furi record api usage, cleanup code * Fix broken merge for freertos apps * Core, Target: fix compilation warnings * Drop firmware target local * HAL Timebase, Power, Clock: semaphore guarded access to clock and power modes, better sleep mode. * SD-Filesystem: wait for all deps to arrive before adding widget. Core, BLE: disable debug dump to serial. * delete old app example-ipc * delete old app fatfs list * fix strobe app, add input header * delete old display driver * comment old app qr-code * fix sd-card test, add forced widget update * remove unused new core test * increase heap to 128k * comment and assert old core tests * fix syntax Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
#include "flipper_v2.h"
|
||||
#include <furi.h>
|
||||
#include <cli/cli.h>
|
||||
#include <gui/gui.h>
|
||||
#include "menu/menu.h"
|
||||
@@ -8,14 +8,15 @@
|
||||
#include <api-hal.h>
|
||||
|
||||
typedef struct {
|
||||
FuriApp* handler;
|
||||
osThreadAttr_t app_thread_attr;
|
||||
osThreadId_t app_thread_id;
|
||||
Widget* widget;
|
||||
const FlipperStartupApp* current_app;
|
||||
const FuriApplication* current_app;
|
||||
} AppLoaderState;
|
||||
|
||||
typedef struct {
|
||||
AppLoaderState* state;
|
||||
const FlipperStartupApp* app;
|
||||
const FuriApplication* app;
|
||||
} AppLoaderContext;
|
||||
|
||||
// TODO add mutex for contex
|
||||
@@ -36,7 +37,7 @@ static void input_callback(InputEvent* input_event, void* _ctx) {
|
||||
AppLoaderState* ctx = (AppLoaderState*)_ctx;
|
||||
|
||||
if(input_event->state && input_event->input == InputBack) {
|
||||
furiac_kill(ctx->handler);
|
||||
osThreadTerminate(ctx->app_thread_id);
|
||||
widget_enabled_set(ctx->widget, false);
|
||||
api_hal_timebase_insomnia_exit();
|
||||
}
|
||||
@@ -54,7 +55,16 @@ static void handle_menu(void* _ctx) {
|
||||
api_hal_timebase_insomnia_enter();
|
||||
|
||||
ctx->state->current_app = ctx->app;
|
||||
ctx->state->handler = furiac_start(ctx->app->app, ctx->app->name, NULL);
|
||||
ctx->state->app_thread_attr.name = ctx->app->name;
|
||||
ctx->state->app_thread_attr.attr_bits = osThreadDetached;
|
||||
ctx->state->app_thread_attr.cb_mem = NULL;
|
||||
ctx->state->app_thread_attr.cb_size = 0;
|
||||
ctx->state->app_thread_attr.stack_mem = NULL;
|
||||
ctx->state->app_thread_attr.stack_size = 1024;
|
||||
ctx->state->app_thread_attr.priority = osPriorityNormal;
|
||||
ctx->state->app_thread_attr.tz_module = 0;
|
||||
ctx->state->app_thread_attr.reserved = 0;
|
||||
ctx->state->app_thread_id = osThreadNew(ctx->app->app, NULL, &ctx->state->app_thread_attr);
|
||||
}
|
||||
|
||||
static void handle_cli(string_t args, void* _ctx) {
|
||||
@@ -65,13 +75,22 @@ static void handle_cli(string_t args, void* _ctx) {
|
||||
cli_print("Starting furi application\r\n");
|
||||
|
||||
ctx->state->current_app = ctx->app;
|
||||
ctx->state->handler = furiac_start(ctx->app->app, ctx->app->name, NULL);
|
||||
ctx->state->app_thread_attr.name = ctx->app->name;
|
||||
ctx->state->app_thread_attr.attr_bits = osThreadDetached;
|
||||
ctx->state->app_thread_attr.cb_mem = NULL;
|
||||
ctx->state->app_thread_attr.cb_size = 0;
|
||||
ctx->state->app_thread_attr.stack_mem = NULL;
|
||||
ctx->state->app_thread_attr.stack_size = 1024;
|
||||
ctx->state->app_thread_attr.priority = osPriorityNormal;
|
||||
ctx->state->app_thread_attr.tz_module = 0;
|
||||
ctx->state->app_thread_attr.reserved = 0;
|
||||
ctx->state->app_thread_id = osThreadNew(ctx->app->app, NULL, &ctx->state->app_thread_attr);
|
||||
|
||||
cli_print("Press any key to kill application");
|
||||
|
||||
char c;
|
||||
cli_read(&c, 1);
|
||||
furiac_kill(ctx->state->handler);
|
||||
osThreadTerminate(ctx->state->app_thread_id);
|
||||
}
|
||||
|
||||
void app_loader(void* p) {
|
||||
@@ -79,37 +98,23 @@ void app_loader(void* p) {
|
||||
furi_check(self_id);
|
||||
|
||||
AppLoaderState state;
|
||||
state.handler = NULL;
|
||||
state.app_thread_id = NULL;
|
||||
|
||||
state.widget = widget_alloc();
|
||||
widget_enabled_set(state.widget, false);
|
||||
widget_draw_callback_set(state.widget, render_callback, &state);
|
||||
widget_input_callback_set(state.widget, input_callback, &state);
|
||||
|
||||
ValueMutex* menu_mutex = furi_open("menu");
|
||||
if(menu_mutex == NULL) {
|
||||
printf("menu is not available\n");
|
||||
furiac_exit(NULL);
|
||||
}
|
||||
ValueMutex* menu_mutex = furi_record_open("menu");
|
||||
Cli* cli = furi_record_open("cli");
|
||||
Gui* gui = furi_record_open("gui");
|
||||
|
||||
Cli* cli = furi_open("cli");
|
||||
|
||||
// Open GUI and register widget
|
||||
Gui* gui = furi_open("gui");
|
||||
if(gui == NULL) {
|
||||
printf("gui is not available\n");
|
||||
furiac_exit(NULL);
|
||||
}
|
||||
gui_add_widget(gui, state.widget, GuiLayerFullscreen);
|
||||
|
||||
// FURI startup
|
||||
const size_t flipper_app_count = sizeof(FLIPPER_APPS) / sizeof(FLIPPER_APPS[0]);
|
||||
const size_t flipper_plugins_count = sizeof(FLIPPER_PLUGINS) / sizeof(FLIPPER_PLUGINS[0]);
|
||||
|
||||
// Main menu
|
||||
with_value_mutex(
|
||||
menu_mutex, (Menu * menu) {
|
||||
for(size_t i = 0; i < flipper_app_count; i++) {
|
||||
for(size_t i = 0; i < FLIPPER_APPS_size(); i++) {
|
||||
AppLoaderContext* ctx = furi_alloc(sizeof(AppLoaderContext));
|
||||
ctx->state = &state;
|
||||
ctx->app = &FLIPPER_APPS[i];
|
||||
@@ -123,13 +128,11 @@ void app_loader(void* p) {
|
||||
ctx));
|
||||
|
||||
// Add cli command
|
||||
if(cli) {
|
||||
string_t cli_name;
|
||||
string_init_set_str(cli_name, "app_");
|
||||
string_cat_str(cli_name, FLIPPER_APPS[i].name);
|
||||
cli_add_command(cli, string_get_cstr(cli_name), handle_cli, ctx);
|
||||
string_clear(cli_name);
|
||||
}
|
||||
string_t cli_name;
|
||||
string_init_set_str(cli_name, "app_");
|
||||
string_cat_str(cli_name, FLIPPER_APPS[i].name);
|
||||
cli_add_command(cli, string_get_cstr(cli_name), handle_cli, ctx);
|
||||
string_clear(cli_name);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -157,7 +160,7 @@ void app_loader(void* p) {
|
||||
MenuItem* menu_plugins =
|
||||
menu_item_alloc_menu("Plugins", assets_icons_get(A_Plugins_14));
|
||||
|
||||
for(size_t i = 0; i < flipper_plugins_count; i++) {
|
||||
for(size_t i = 0; i < FLIPPER_PLUGINS_size(); i++) {
|
||||
AppLoaderContext* ctx = furi_alloc(sizeof(AppLoaderContext));
|
||||
ctx->state = &state;
|
||||
ctx->app = &FLIPPER_PLUGINS[i];
|
||||
@@ -171,13 +174,11 @@ void app_loader(void* p) {
|
||||
ctx));
|
||||
|
||||
// Add cli command
|
||||
if(cli) {
|
||||
string_t cli_name;
|
||||
string_init_set_str(cli_name, "app_");
|
||||
string_cat_str(cli_name, FLIPPER_PLUGINS[i].name);
|
||||
cli_add_command(cli, string_get_cstr(cli_name), handle_cli, ctx);
|
||||
string_clear(cli_name);
|
||||
}
|
||||
string_t cli_name;
|
||||
string_init_set_str(cli_name, "app_");
|
||||
string_cat_str(cli_name, FLIPPER_PLUGINS[i].name);
|
||||
cli_add_command(cli, string_get_cstr(cli_name), handle_cli, ctx);
|
||||
string_clear(cli_name);
|
||||
}
|
||||
|
||||
menu_item_add(menu, menu_plugins);
|
||||
@@ -186,4 +187,4 @@ void app_loader(void* p) {
|
||||
printf("[app loader] start\n");
|
||||
|
||||
osThreadSuspend(self_id);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user