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

574 lines
18 KiB
C
Raw Normal View History

/**
* @file thread.h
* @brief Furi: Furi Thread API
*/
#pragma once
#include "base.h"
#include "common_defines.h"
#include <stdint.h>
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Enumeration of possible FuriThread states.
*
* Many of the FuriThread functions MUST ONLY be called when the thread is STOPPED.
*/
typedef enum {
FuriThreadStateStopped, /**< Thread is stopped and is safe to release. Event delivered from system init thread(TCB cleanup routine). It is safe to release thread instance. */
FuriThreadStateStopping, /**< Thread is stopping. Event delivered from child thread. */
FuriThreadStateStarting, /**< Thread is starting. Event delivered from parent(self) thread. */
FuriThreadStateRunning, /**< Thread is running. Event delivered from child thread. */
} FuriThreadState;
/**
* @brief Enumeration of possible FuriThread priorities.
*/
typedef enum {
FuriThreadPriorityIdle = 0, /**< Idle priority */
FuriThreadPriorityInit = 4, /**< Init System Thread Priority */
FuriThreadPriorityLowest = 14, /**< Lowest */
FuriThreadPriorityLow = 15, /**< Low */
FuriThreadPriorityNormal = 16, /**< Normal, system default */
FuriThreadPriorityHigh = 17, /**< High */
FuriThreadPriorityHighest = 18, /**< Highest */
FuriThreadPriorityIsr =
(FURI_CONFIG_THREAD_MAX_PRIORITIES - 1), /**< Deferred ISR (highest possible) */
} FuriThreadPriority;
/**
* @brief FuriThread opaque type.
*/
typedef struct FuriThread FuriThread;
/** FuriThreadList type */
typedef struct FuriThreadList FuriThreadList;
/**
* @brief Unique thread identifier type (used by the OS kernel).
*/
typedef void* FuriThreadId;
/**
* @brief Thread callback function pointer type.
*
* The function to be used as a thread callback MUST follow this signature.
*
* @param[in,out] context pointer to a user-specified object
* @return value to be used as the thread return code
*/
typedef int32_t (*FuriThreadCallback)(void* context);
/**
* @brief Standard output callback function pointer type.
*
* The function to be used as a standard output callback MUST follow this signature.
*
* @warning The handler MUST process ALL of the provided data before returning.
*
* @param[in] data pointer to the data to be written to the standard out
* @param[in] size size of the data in bytes
* @param[in] context optional context
*/
typedef void (*FuriThreadStdoutWriteCallback)(const char* data, size_t size, void* context);
/**
* @brief Standard input callback function pointer type
*
* The function to be used as a standard input callback MUST follow this signature.
*
* @param[out] buffer buffer to read data into
* @param[in] size maximum number of bytes to read into the buffer
* @param[in] timeout how long to wait for (in ticks) before giving up
* @param[in] context optional context
* @returns number of bytes that was actually read into the buffer
*/
typedef size_t (
*FuriThreadStdinReadCallback)(char* buffer, size_t size, FuriWait timeout, void* context);
/**
* @brief State change callback function pointer type.
*
* The function to be used as a state callback MUST follow this
* signature.
*
* @param[in] thread to the FuriThread instance that changed the state
* @param[in] state identifier of the state the thread has transitioned
* to
* @param[in,out] context pointer to a user-specified object
*/
typedef void (*FuriThreadStateCallback)(FuriThread* thread, FuriThreadState state, void* context);
/**
* @brief Signal handler callback function pointer type.
*
* The function to be used as a signal handler callback MUS follow this signature.
*
* @param[in] signal value of the signal to be handled by the recipient
* @param[in,out] arg optional argument (can be of any value, including NULL)
* @param[in,out] context pointer to a user-specified object
* @returns true if the signal was handled, false otherwise
*/
typedef bool (*FuriThreadSignalCallback)(uint32_t signal, void* arg, void* context);
/**
* @brief Create a FuriThread instance.
*
* @return pointer to the created FuriThread instance
*/
FuriThread* furi_thread_alloc(void);
/**
* @brief Create a FuriThread instance (service mode).
*
* Service threads are more memory efficient, but have
* the following limitations:
*
* - Cannot return from the callback
* - Cannot be joined or freed
* - Stack size cannot be altered
*
* @param[in] name human-readable thread name (can be NULL)
* @param[in] stack_size stack size in bytes (cannot be changed later)
* @param[in] callback pointer to a function to be executed in this thread
* @param[in] context pointer to a user-specified object (will be passed to the callback)
* @return pointer to the created FuriThread instance
*/
FuriThread* furi_thread_alloc_service(
const char* name,
uint32_t stack_size,
FuriThreadCallback callback,
void* context);
/**
* @brief Create a FuriThread instance w/ extra parameters.
*
* @param[in] name human-readable thread name (can be NULL)
* @param[in] stack_size stack size in bytes (can be changed later)
* @param[in] callback pointer to a function to be executed in this thread
* @param[in] context pointer to a user-specified object (will be passed to the callback)
* @return pointer to the created FuriThread instance
*/
FuriThread* furi_thread_alloc_ex(
const char* name,
uint32_t stack_size,
FuriThreadCallback callback,
void* context);
/**
* @brief Delete a FuriThread instance.
*
* The thread MUST be stopped when calling this function.
*
* @warning see furi_thread_join for caveats on stopping a thread.
*
* @param[in,out] thread pointer to the FuriThread instance to be deleted
*/
void furi_thread_free(FuriThread* thread);
/**
* @brief Set the name of a FuriThread instance.
*
* The thread MUST be stopped when calling this function.
*
* @param[in,out] thread pointer to the FuriThread instance to be modified
* @param[in] name human-readable thread name (can be NULL)
*/
void furi_thread_set_name(FuriThread* thread, const char* name);
/**
* @brief Set the application ID of a FuriThread instance.
*
* The thread MUST be stopped when calling this function.
*
* Technically, it is like a "process id", but it is not a system-wide unique identifier.
* All threads spawned by the same app will have the same appid.
*
* @param[in,out] thread pointer to the FuriThread instance to be modified
* @param[in] appid thread application ID (can be NULL)
*/
void furi_thread_set_appid(FuriThread* thread, const char* appid);
/**
* @brief Set the stack size of a FuriThread instance.
*
* The thread MUST be stopped when calling this function. Additionally, it is NOT possible
* to change the stack size of a service thread under any circumstances.
*
* @param[in,out] thread pointer to the FuriThread instance to be modified
* @param[in] stack_size stack size in bytes
*/
void furi_thread_set_stack_size(FuriThread* thread, size_t stack_size);
/**
* @brief Set the user callback function to be executed in a FuriThread.
*
* The thread MUST be stopped when calling this function.
*
* @param[in,out] thread pointer to the FuriThread instance to be modified
* @param[in] callback pointer to a user-specified function to be executed in this thread
*/
void furi_thread_set_callback(FuriThread* thread, FuriThreadCallback callback);
/**
* @brief Set the callback function context.
*
* The thread MUST be stopped when calling this function.
*
* @param[in,out] thread pointer to the FuriThread instance to be modified
* @param[in] context pointer to a user-specified object (will be passed to the callback, can be NULL)
*/
void furi_thread_set_context(FuriThread* thread, void* context);
/**
* @brief Set the priority of a FuriThread.
*
* The thread MUST be stopped when calling this function.
*
* @param[in,out] thread pointer to the FuriThread instance to be modified
* @param[in] priority priority level value
*/
void furi_thread_set_priority(FuriThread* thread, FuriThreadPriority priority);
/**
* @brief Get the priority of a FuriThread.
ble: profile rework (#3272) * ble: profile rework, initial * apps: hid: fix for pairing cleanup * app: hid: select transport based on #define * fixing PVS warnings * ble: serial service: fixed uid naming * bt service: on-demand dialog init; ble profiles: docs; battery svc: proper update * Added shci_cmd_resp_wait/shci_cmd_resp_release impl with semaphore * app: hid: separated transport code * ble: fixed service init order for serial svc; moved hardfault check to ble_glue * cli: ps: added thread prio to output, fixed heap display * ble_glue: naming changes; separate thread for event processing; * furi: added runtime stats; cli: added cpu% to `ps` * cli: fixed thread time calculation * furi: added getter for thread priority * fixing pvs warnings * hid profile: fixed naming * more naming fixes * hal: ble init small cleanup * cleanup & draft beacon api * f18: api sync * apps: moved example_custom_font from debug to examples * BLE extra beacon demo app * naming fix * UI fixes for demo app (wip) * desktop, ble svc: added statusbar icon for beacon * minor cleanup * Minor cleanup & naming fixes * api sync * Removed stale header * hal: added FURI_BLE_EXTRA_LOG for extra logging; comments & code cleanup * naming & macro fixes * quick fixes from review * Eliminated stock svc_ctl * cli: ps: removed runtime stats * minor include fixes * (void) * naming fixes * More naming fixes * fbt: always build all libs * fbt: explicitly globbing libs; dist: logging SDK path * scripts: fixed lib path precedence * hal: bt: profiles: naming changes, support for passing params to a profile; include cleanup * ble: hid: added parameter processing for profile template * api sync * BLE HID: long name trim * Removed unused check * desktop: updated beacon status icon; ble: hid: cleaner device name management * desktop: updated status icon Co-authored-by: あく <alleteam@gmail.com> Co-authored-by: nminaylov <nm29719@gmail.com>
2024-02-16 11:20:45 +04:00
*
* @param[in] thread pointer to the FuriThread instance to be queried
* @return priority level value
ble: profile rework (#3272) * ble: profile rework, initial * apps: hid: fix for pairing cleanup * app: hid: select transport based on #define * fixing PVS warnings * ble: serial service: fixed uid naming * bt service: on-demand dialog init; ble profiles: docs; battery svc: proper update * Added shci_cmd_resp_wait/shci_cmd_resp_release impl with semaphore * app: hid: separated transport code * ble: fixed service init order for serial svc; moved hardfault check to ble_glue * cli: ps: added thread prio to output, fixed heap display * ble_glue: naming changes; separate thread for event processing; * furi: added runtime stats; cli: added cpu% to `ps` * cli: fixed thread time calculation * furi: added getter for thread priority * fixing pvs warnings * hid profile: fixed naming * more naming fixes * hal: ble init small cleanup * cleanup & draft beacon api * f18: api sync * apps: moved example_custom_font from debug to examples * BLE extra beacon demo app * naming fix * UI fixes for demo app (wip) * desktop, ble svc: added statusbar icon for beacon * minor cleanup * Minor cleanup & naming fixes * api sync * Removed stale header * hal: added FURI_BLE_EXTRA_LOG for extra logging; comments & code cleanup * naming & macro fixes * quick fixes from review * Eliminated stock svc_ctl * cli: ps: removed runtime stats * minor include fixes * (void) * naming fixes * More naming fixes * fbt: always build all libs * fbt: explicitly globbing libs; dist: logging SDK path * scripts: fixed lib path precedence * hal: bt: profiles: naming changes, support for passing params to a profile; include cleanup * ble: hid: added parameter processing for profile template * api sync * BLE HID: long name trim * Removed unused check * desktop: updated beacon status icon; ble: hid: cleaner device name management * desktop: updated status icon Co-authored-by: あく <alleteam@gmail.com> Co-authored-by: nminaylov <nm29719@gmail.com>
2024-02-16 11:20:45 +04:00
*/
FuriThreadPriority furi_thread_get_priority(FuriThread* thread);
/**
* @brief Set the priority of the current FuriThread.
*
* @param priority priority level value
*/
void furi_thread_set_current_priority(FuriThreadPriority priority);
/**
* @brief Get the priority of the current FuriThread.
*
* @return priority level value
*/
FuriThreadPriority furi_thread_get_current_priority(void);
/**
* Set the callback function to be executed upon a state thransition of a FuriThread.
*
* The thread MUST be stopped when calling this function.
*
* @param[in,out] thread pointer to the FuriThread instance to be modified
* @param[in] callback pointer to a user-specified callback function
*/
void furi_thread_set_state_callback(FuriThread* thread, FuriThreadStateCallback callback);
/**
* @brief Set the state change callback context.
*
* The thread MUST be stopped when calling this function.
*
* @param[in,out] thread pointer to the FuriThread instance to be modified
* @param[in] context pointer to a user-specified object (will be passed to the callback, can be NULL)
*/
void furi_thread_set_state_context(FuriThread* thread, void* context);
/**
* @brief Get the state of a FuriThread isntance.
*
* @param[in] thread pointer to the FuriThread instance to be queried
* @return thread state value
*/
FuriThreadState furi_thread_get_state(FuriThread* thread);
/**
* @brief Set a signal handler callback for a FuriThread instance.
*
Storage: remove LFS (#3577) * Storage: drop internal storage * Storage: rollback some unnecessary changes * Storage: rollback some unnecessary changes part 2 * Storage: cleanup various defines and int handling. Ble: allow short connection interval if internal flash is not used. * Storage: do not return storage if it is not ready * Save PIN code to RTC, update settings * Simplify the code, clean up includes * Rearrange some code * apps: storage_move_to_sd: conditionally enable with --extra-define=STORAGE_INT_ON_LFS * Load Desktop settings automatically * Redirect /any to /ext * Abolish storage_move_to_sd app * Remove as many mentions of ANY_PATH as possible * Fix desktop settings wrongly not loading * Improve desktop settings handling and strings * Load BLE settings and keys automatically * Improve BLE configuration procedure * Do not load bluetooth keys twice if they were already loaded * Load dolphin state automatically * Fix merge artifact * Load notification settings automatically * Update desktop settings strings * Load expansion settings automatically * Do not use thread signals to reload desktop settings * Load region data automatically, separate to its own hook * Improve ble behaviour with no keys * Fix Dolphin state not resetting correctly * Add a status check * Make Desktop save its own settings * Check result when taking and releasing mutex * Improve default thread signal handling in FuriEventLoop * Make bt service in charge of saving settings, add settings api * Fix a deadlock due to timer thread not receiving time * Lock core2 when reinitialising bt * Update clang-format * Revert "Update clang-format" This reverts commit d61295ac063c6ec879375ceeab54d6ff2c90a9a1. * Format sources with clang-format * Revert old stack size for desktop settings * Allocate big struct dynamically * Simplify PIN comparison * Save pointer to storage in Desktop object * Fix region provisioning for hardware regions * Remove stale TODO + siimplify code * Clean up region.c * Use sizeof instead of macro define * Limit PIN length to 10 for consistency * Emit a warning upon usage of /any * Add delay after finding flipper * Remove unnecessary delay * Remove all mentions of STORAGE_INT_ON_LFS * Remove littlefs and internal storage * Remove all possible LittleFS mentions * Fix browser tab in Archive * Ble: fix connection interval explanation * Bump API Symbols * BLE: Update comments interval connection comments * Storage: clear FuriHalRtcFlagStorageFormatInternal if set --------- Co-authored-by: Georgii Surkov <georgii.surkov@outlook.com> Co-authored-by: hedger <hedger@nanode.su> Co-authored-by: Georgii Surkov <37121527+gsurkov@users.noreply.github.com>
2024-08-04 18:54:02 +09:00
* The thread MUST be stopped when calling this function if calling it from another thread.
*
* @param[in,out] thread pointer to the FuriThread instance to be modified
* @param[in] callback pointer to a user-specified callback function
* @param[in] context pointer to a user-specified object (will be passed to the callback, can be NULL)
*/
void furi_thread_set_signal_callback(
FuriThread* thread,
FuriThreadSignalCallback callback,
void* context);
Storage: remove LFS (#3577) * Storage: drop internal storage * Storage: rollback some unnecessary changes * Storage: rollback some unnecessary changes part 2 * Storage: cleanup various defines and int handling. Ble: allow short connection interval if internal flash is not used. * Storage: do not return storage if it is not ready * Save PIN code to RTC, update settings * Simplify the code, clean up includes * Rearrange some code * apps: storage_move_to_sd: conditionally enable with --extra-define=STORAGE_INT_ON_LFS * Load Desktop settings automatically * Redirect /any to /ext * Abolish storage_move_to_sd app * Remove as many mentions of ANY_PATH as possible * Fix desktop settings wrongly not loading * Improve desktop settings handling and strings * Load BLE settings and keys automatically * Improve BLE configuration procedure * Do not load bluetooth keys twice if they were already loaded * Load dolphin state automatically * Fix merge artifact * Load notification settings automatically * Update desktop settings strings * Load expansion settings automatically * Do not use thread signals to reload desktop settings * Load region data automatically, separate to its own hook * Improve ble behaviour with no keys * Fix Dolphin state not resetting correctly * Add a status check * Make Desktop save its own settings * Check result when taking and releasing mutex * Improve default thread signal handling in FuriEventLoop * Make bt service in charge of saving settings, add settings api * Fix a deadlock due to timer thread not receiving time * Lock core2 when reinitialising bt * Update clang-format * Revert "Update clang-format" This reverts commit d61295ac063c6ec879375ceeab54d6ff2c90a9a1. * Format sources with clang-format * Revert old stack size for desktop settings * Allocate big struct dynamically * Simplify PIN comparison * Save pointer to storage in Desktop object * Fix region provisioning for hardware regions * Remove stale TODO + siimplify code * Clean up region.c * Use sizeof instead of macro define * Limit PIN length to 10 for consistency * Emit a warning upon usage of /any * Add delay after finding flipper * Remove unnecessary delay * Remove all mentions of STORAGE_INT_ON_LFS * Remove littlefs and internal storage * Remove all possible LittleFS mentions * Fix browser tab in Archive * Ble: fix connection interval explanation * Bump API Symbols * BLE: Update comments interval connection comments * Storage: clear FuriHalRtcFlagStorageFormatInternal if set --------- Co-authored-by: Georgii Surkov <georgii.surkov@outlook.com> Co-authored-by: hedger <hedger@nanode.su> Co-authored-by: Georgii Surkov <37121527+gsurkov@users.noreply.github.com>
2024-08-04 18:54:02 +09:00
/**
* @brief Get a signal callback for a FuriThread instance.
*
* @param[in] thread pointer to the FuriThread instance to be queried
* @return pointer to the callback function or NULL if none has been set
*/
FuriThreadSignalCallback furi_thread_get_signal_callback(const FuriThread* thread);
/**
* @brief Send a signal to a FuriThread instance.
*
* @param[in] thread pointer to the FuriThread instance to be signaled
* @param[in] signal signal value to be sent
* @param[in,out] arg optional argument (can be of any value, including NULL)
*/
bool furi_thread_signal(const FuriThread* thread, uint32_t signal, void* arg);
/**
* @brief Start a FuriThread instance.
*
* The thread MUST be stopped when calling this function.
*
* @param[in,out] thread pointer to the FuriThread instance to be started
*/
void furi_thread_start(FuriThread* thread);
/**
* @brief Wait for a FuriThread to exit.
*
* The thread callback function must return in order for the FuriThread instance to become joinable.
*
* @warning Use this method only when the CPU is not busy (i.e. when the
* Idle task receives control), otherwise it will wait forever.
*
* @param[in] thread pointer to the FuriThread instance to be joined
* @return always true
*/
bool furi_thread_join(FuriThread* thread);
/**
* @brief Get the unique identifier of a FuriThread instance.
*
* @param[in] thread pointer to the FuriThread instance to be queried
* @return unique identifier value or NULL if thread is not running
*/
FuriThreadId furi_thread_get_id(FuriThread* thread);
/**
* @brief Enable heap usage tracing for a FuriThread.
*
* The thread MUST be stopped when calling this function.
*
* @param[in,out] thread pointer to the FuriThread instance to be modified
*/
void furi_thread_enable_heap_trace(FuriThread* thread);
/**
* @brief Disable heap usage tracing for a FuriThread.
*
* The thread MUST be stopped when calling this function.
*
* @param[in,out] thread pointer to the FuriThread instance to be modified
*/
void furi_thread_disable_heap_trace(FuriThread* thread);
/**
* @brief Get heap usage by a FuriThread instance.
*
* The heap trace MUST be enabled before callgin this function.
*
* @param[in] thread pointer to the FuriThread instance to be queried
* @return heap usage in bytes
*/
size_t furi_thread_get_heap_size(FuriThread* thread);
/**
* @brief Get the return code of a FuriThread instance.
[FL-2263] Flasher service & RAM exec (#1006) * WIP on stripping fw * Compact FW build - use RAM_EXEC=1 COMPACT=1 DEBUG=0 * Fixed uninitialized storage struct; small fixes to compact fw * Flasher srv w/mocked flash ops * Fixed typos & accomodated FFF changes * Alternative fw startup branch * Working load & jmp to RAM fw * +manifest processing for stage loader; + crc verification for stage payload * Fixed questionable code & potential leaks * Lowered screen update rate; added radio stack update stubs; working dfu write * Console EP with manifest & stage validation * Added microtar lib; minor ui fixes for updater * Removed microtar * Removed mtar #2 * Added a better version of microtar * TAR archive api; LFS backup & restore core * Recursive backup/restore * LFS worker thread * Added system apps to loader - not visible in UI; full update process with restarts * Typo fix * Dropped BL & f6; tooling for updater WIP * Minor py fixes * Minor fixes to make it build after merge * Ported flash workaround from BL + fixed visuals * Minor cleanup * Chmod + loader app search fix * Python linter fix * Removed usb stuff & float read support for staged loader == -10% of binary size * Added backup/restore & update pb requests * Added stub impl to RPC for backup/restore/update commands * Reworked TAR to use borrowed Storage api; slightly reduced build size by removing `static string`; hidden update-related RPC behind defines * Moved backup&restore to storage * Fixed new message types * Backup/restore/update RPC impl * Moved furi_hal_crc to LL; minor fixes * CRC HAL rework to LL * Purging STM HAL * Brought back minimal DFU boot mode (no gui); additional crc state checks * Added splash screen, BROKEN usb function * Clock init rework WIP * Stripped graphics from DFU mode * Temp fix for unused static fun * WIP update picker - broken! * Fixed UI * Bumping version * Fixed RTC setup * Backup to update folder instead of ext root * Removed unused scenes & more usb remnants from staged loader * CI updates * Fixed update bundle name * Temporary restored USB handler * Attempt to prevent .text corruption * Comments on how I spent this Saturday * Added update file icon * Documentation updates * Moved common code to lib folder * Storage: more unit tests * Storage: blocking dir open, differentiate file and dir when freed. * Major refactoring; added input processing to updater to allow retrying on failures (not very useful prob). Added API for extraction of thread return value * Removed re-init check for manifest * Changed low-level path manipulation to toolbox/path.h; makefile cleanup; tiny fix in lint.py * Increased update worker stack size * Text fixes in backup CLI * Displaying number of update stages to run; removed timeout in handling errors * Bumping version * Added thread cleanup for spawner thread * Updated build targets to exclude firmware bundle from 'ALL' * Fixed makefile for update_package; skipping VCP init for update mode (ugly) * Switched github build from ALL to update_package * Added +x for dist_update.sh * Cli: add total heap size to "free" command * Moved (RAM) suffix to build version instead of git commit no. * DFU comment * Some fixes suggested by clang-tidy * Fixed recursive PREFIX macro * Makefile: gather all new rules in updater namespace. FuriHal: rename bootloader to boot, isr safe delays * Github: correct build target name in firmware build * FuriHal: move target switch to boot * Makefile: fix firmware flash * Furi, FuriHal: move kernel start to furi, early init * Drop bootloader related stuff * Drop cube. Drop bootloader linker script. * Renamed update_hl, moved constants to #defines * Moved update-related boot mode to separate bitfield * Reworked updater cli to single entry point; fixed crash on tar cleanup * Added Python replacement for dist shell scripts * Linter fixes for dist.py +x * Fixes for environment suffix * Dropped bash scripts * Added dirty build flag to version structure & interfaces * Version string escapes * Fixed flag logic in dist.py; added support for App instances being imported and not terminating the whole program * Fixed fw address in ReadMe.md * Rpc: fix crash on double screen start * Return back original boot behavior and fix jump to system bootloader * Cleanup code, add error sequence for RTC * Update firmware readme * FuriHal: drop boot, restructure RTC registers usage and add header register check * Furi goes first * Toolchain: add ccache support * Renamed update bundle dir Co-authored-by: DrZlo13 <who.just.the.doctor@gmail.com> Co-authored-by: あく <alleteam@gmail.com>
2022-04-13 23:50:25 +03:00
*
* This value is equal to the return value of the thread callback function.
[FL-2263] Flasher service & RAM exec (#1006) * WIP on stripping fw * Compact FW build - use RAM_EXEC=1 COMPACT=1 DEBUG=0 * Fixed uninitialized storage struct; small fixes to compact fw * Flasher srv w/mocked flash ops * Fixed typos & accomodated FFF changes * Alternative fw startup branch * Working load & jmp to RAM fw * +manifest processing for stage loader; + crc verification for stage payload * Fixed questionable code & potential leaks * Lowered screen update rate; added radio stack update stubs; working dfu write * Console EP with manifest & stage validation * Added microtar lib; minor ui fixes for updater * Removed microtar * Removed mtar #2 * Added a better version of microtar * TAR archive api; LFS backup & restore core * Recursive backup/restore * LFS worker thread * Added system apps to loader - not visible in UI; full update process with restarts * Typo fix * Dropped BL & f6; tooling for updater WIP * Minor py fixes * Minor fixes to make it build after merge * Ported flash workaround from BL + fixed visuals * Minor cleanup * Chmod + loader app search fix * Python linter fix * Removed usb stuff & float read support for staged loader == -10% of binary size * Added backup/restore & update pb requests * Added stub impl to RPC for backup/restore/update commands * Reworked TAR to use borrowed Storage api; slightly reduced build size by removing `static string`; hidden update-related RPC behind defines * Moved backup&restore to storage * Fixed new message types * Backup/restore/update RPC impl * Moved furi_hal_crc to LL; minor fixes * CRC HAL rework to LL * Purging STM HAL * Brought back minimal DFU boot mode (no gui); additional crc state checks * Added splash screen, BROKEN usb function * Clock init rework WIP * Stripped graphics from DFU mode * Temp fix for unused static fun * WIP update picker - broken! * Fixed UI * Bumping version * Fixed RTC setup * Backup to update folder instead of ext root * Removed unused scenes & more usb remnants from staged loader * CI updates * Fixed update bundle name * Temporary restored USB handler * Attempt to prevent .text corruption * Comments on how I spent this Saturday * Added update file icon * Documentation updates * Moved common code to lib folder * Storage: more unit tests * Storage: blocking dir open, differentiate file and dir when freed. * Major refactoring; added input processing to updater to allow retrying on failures (not very useful prob). Added API for extraction of thread return value * Removed re-init check for manifest * Changed low-level path manipulation to toolbox/path.h; makefile cleanup; tiny fix in lint.py * Increased update worker stack size * Text fixes in backup CLI * Displaying number of update stages to run; removed timeout in handling errors * Bumping version * Added thread cleanup for spawner thread * Updated build targets to exclude firmware bundle from 'ALL' * Fixed makefile for update_package; skipping VCP init for update mode (ugly) * Switched github build from ALL to update_package * Added +x for dist_update.sh * Cli: add total heap size to "free" command * Moved (RAM) suffix to build version instead of git commit no. * DFU comment * Some fixes suggested by clang-tidy * Fixed recursive PREFIX macro * Makefile: gather all new rules in updater namespace. FuriHal: rename bootloader to boot, isr safe delays * Github: correct build target name in firmware build * FuriHal: move target switch to boot * Makefile: fix firmware flash * Furi, FuriHal: move kernel start to furi, early init * Drop bootloader related stuff * Drop cube. Drop bootloader linker script. * Renamed update_hl, moved constants to #defines * Moved update-related boot mode to separate bitfield * Reworked updater cli to single entry point; fixed crash on tar cleanup * Added Python replacement for dist shell scripts * Linter fixes for dist.py +x * Fixes for environment suffix * Dropped bash scripts * Added dirty build flag to version structure & interfaces * Version string escapes * Fixed flag logic in dist.py; added support for App instances being imported and not terminating the whole program * Fixed fw address in ReadMe.md * Rpc: fix crash on double screen start * Return back original boot behavior and fix jump to system bootloader * Cleanup code, add error sequence for RTC * Update firmware readme * FuriHal: drop boot, restructure RTC registers usage and add header register check * Furi goes first * Toolchain: add ccache support * Renamed update bundle dir Co-authored-by: DrZlo13 <who.just.the.doctor@gmail.com> Co-authored-by: あく <alleteam@gmail.com>
2022-04-13 23:50:25 +03:00
*
* The thread MUST be stopped when calling this function.
*
* @param[in] thread pointer to the FuriThread instance to be queried
* @return return code value
[FL-2263] Flasher service & RAM exec (#1006) * WIP on stripping fw * Compact FW build - use RAM_EXEC=1 COMPACT=1 DEBUG=0 * Fixed uninitialized storage struct; small fixes to compact fw * Flasher srv w/mocked flash ops * Fixed typos & accomodated FFF changes * Alternative fw startup branch * Working load & jmp to RAM fw * +manifest processing for stage loader; + crc verification for stage payload * Fixed questionable code & potential leaks * Lowered screen update rate; added radio stack update stubs; working dfu write * Console EP with manifest & stage validation * Added microtar lib; minor ui fixes for updater * Removed microtar * Removed mtar #2 * Added a better version of microtar * TAR archive api; LFS backup & restore core * Recursive backup/restore * LFS worker thread * Added system apps to loader - not visible in UI; full update process with restarts * Typo fix * Dropped BL & f6; tooling for updater WIP * Minor py fixes * Minor fixes to make it build after merge * Ported flash workaround from BL + fixed visuals * Minor cleanup * Chmod + loader app search fix * Python linter fix * Removed usb stuff & float read support for staged loader == -10% of binary size * Added backup/restore & update pb requests * Added stub impl to RPC for backup/restore/update commands * Reworked TAR to use borrowed Storage api; slightly reduced build size by removing `static string`; hidden update-related RPC behind defines * Moved backup&restore to storage * Fixed new message types * Backup/restore/update RPC impl * Moved furi_hal_crc to LL; minor fixes * CRC HAL rework to LL * Purging STM HAL * Brought back minimal DFU boot mode (no gui); additional crc state checks * Added splash screen, BROKEN usb function * Clock init rework WIP * Stripped graphics from DFU mode * Temp fix for unused static fun * WIP update picker - broken! * Fixed UI * Bumping version * Fixed RTC setup * Backup to update folder instead of ext root * Removed unused scenes & more usb remnants from staged loader * CI updates * Fixed update bundle name * Temporary restored USB handler * Attempt to prevent .text corruption * Comments on how I spent this Saturday * Added update file icon * Documentation updates * Moved common code to lib folder * Storage: more unit tests * Storage: blocking dir open, differentiate file and dir when freed. * Major refactoring; added input processing to updater to allow retrying on failures (not very useful prob). Added API for extraction of thread return value * Removed re-init check for manifest * Changed low-level path manipulation to toolbox/path.h; makefile cleanup; tiny fix in lint.py * Increased update worker stack size * Text fixes in backup CLI * Displaying number of update stages to run; removed timeout in handling errors * Bumping version * Added thread cleanup for spawner thread * Updated build targets to exclude firmware bundle from 'ALL' * Fixed makefile for update_package; skipping VCP init for update mode (ugly) * Switched github build from ALL to update_package * Added +x for dist_update.sh * Cli: add total heap size to "free" command * Moved (RAM) suffix to build version instead of git commit no. * DFU comment * Some fixes suggested by clang-tidy * Fixed recursive PREFIX macro * Makefile: gather all new rules in updater namespace. FuriHal: rename bootloader to boot, isr safe delays * Github: correct build target name in firmware build * FuriHal: move target switch to boot * Makefile: fix firmware flash * Furi, FuriHal: move kernel start to furi, early init * Drop bootloader related stuff * Drop cube. Drop bootloader linker script. * Renamed update_hl, moved constants to #defines * Moved update-related boot mode to separate bitfield * Reworked updater cli to single entry point; fixed crash on tar cleanup * Added Python replacement for dist shell scripts * Linter fixes for dist.py +x * Fixes for environment suffix * Dropped bash scripts * Added dirty build flag to version structure & interfaces * Version string escapes * Fixed flag logic in dist.py; added support for App instances being imported and not terminating the whole program * Fixed fw address in ReadMe.md * Rpc: fix crash on double screen start * Return back original boot behavior and fix jump to system bootloader * Cleanup code, add error sequence for RTC * Update firmware readme * FuriHal: drop boot, restructure RTC registers usage and add header register check * Furi goes first * Toolchain: add ccache support * Renamed update bundle dir Co-authored-by: DrZlo13 <who.just.the.doctor@gmail.com> Co-authored-by: あく <alleteam@gmail.com>
2022-04-13 23:50:25 +03:00
*/
int32_t furi_thread_get_return_code(FuriThread* thread);
/**
* @brief Get the unique identifier of the current FuriThread.
*
* @return unique identifier value
*/
FuriThreadId furi_thread_get_current_id(void);
/**
* @brief Get the FuriThread instance associated with the current thread.
*
* @return pointer to a FuriThread instance or NULL if this thread does not belong to Furi
*/
FuriThread* furi_thread_get_current(void);
/**
* @brief Return control to the scheduler.
*/
void furi_thread_yield(void);
/**
* @brief Set the thread flags of a FuriThread.
*
* Can be used as a simple inter-thread communication mechanism.
*
* @param[in] thread_id unique identifier of the thread to be notified
* @param[in] flags bitmask of thread flags to set
* @return bitmask combination of previous and newly set flags
*/
uint32_t furi_thread_flags_set(FuriThreadId thread_id, uint32_t flags);
/**
* @brief Clear the thread flags of the current FuriThread.
*
* @param[in] flags bitmask of thread flags to clear
* @return bitmask of thread flags before clearing
*/
uint32_t furi_thread_flags_clear(uint32_t flags);
/**
* @brief Get the thread flags of the current FuriThread.
* @return current bitmask of thread flags
*/
uint32_t furi_thread_flags_get(void);
/**
* @brief Wait for some thread flags to be set.
*
* @see FuriFlag for option and error flags.
*
* @param[in] flags bitmask of thread flags to wait for
* @param[in] options combination of option flags determining the behavior of the function
* @param[in] timeout maximum time to wait in milliseconds (use FuriWaitForever to wait forever)
* @return bitmask combination of received thread and error flags
*/
uint32_t furi_thread_flags_wait(uint32_t flags, uint32_t options, uint32_t timeout);
/**
* @brief Enumerate all threads.
*
* @param[out] thread_list pointer to the FuriThreadList container
*
* @return true on success, false otherwise
*/
bool furi_thread_enumerate(FuriThreadList* thread_list);
/**
* @brief Get the name of a thread based on its unique identifier.
*
* @param[in] thread_id unique identifier of the thread to be queried
* @return pointer to a zero-terminated string or NULL
*/
const char* furi_thread_get_name(FuriThreadId thread_id);
/**
* @brief Get the application id of a thread based on its unique identifier.
*
* @param[in] thread_id unique identifier of the thread to be queried
* @return pointer to a zero-terminated string
*/
const char* furi_thread_get_appid(FuriThreadId thread_id);
/**
* @brief Get thread stack watermark.
*
* @param[in] thread_id unique identifier of the thread to be queried
* @return stack watermark value
*/
uint32_t furi_thread_get_stack_space(FuriThreadId thread_id);
/**
* @brief Get the standard output callback for the current thead.
*
* @return pointer to the standard out callback function
*/
FuriThreadStdoutWriteCallback furi_thread_get_stdout_callback(void);
/**
* @brief Get the standard input callback for the current thead.
*
* @return pointer to the standard in callback function
*/
FuriThreadStdinReadCallback furi_thread_get_stdin_callback(void);
/** Set standard output callback for the current thread.
*
* @param[in] callback pointer to the callback function or NULL to clear
* @param[in] context context to be passed to the callback
*/
void furi_thread_set_stdout_callback(FuriThreadStdoutWriteCallback callback, void* context);
/** Set standard input callback for the current thread.
*
* @param[in] callback pointer to the callback function or NULL to clear
* @param[in] context context to be passed to the callback
*/
void furi_thread_set_stdin_callback(FuriThreadStdinReadCallback callback, void* context);
/** Write data to buffered standard output.
*
* @note You can also use the standard C `putc`, `puts`, `printf` and friends.
*
* @param[in] data pointer to the data to be written
* @param[in] size data size in bytes
* @return number of bytes that was actually written
*/
size_t furi_thread_stdout_write(const char* data, size_t size);
/**
* @brief Flush buffered data to standard output.
*
* @return error code value
*/
int32_t furi_thread_stdout_flush(void);
/** Read data from the standard input
*
* @note You can also use the standard C `getc`, `gets` and friends.
*
* @param[in] buffer pointer to the buffer to read data into
* @param[in] size how many bytes to read into the buffer
* @param[in] timeout how long to wait for (in ticks) before giving up
* @return number of bytes that was actually read
*/
size_t furi_thread_stdin_read(char* buffer, size_t size, FuriWait timeout);
/** Puts data back into the standard input buffer
*
* `furi_thread_stdin_read` will return the bytes in the same order that they
* were supplied to this function.
*
* @note You can also use the standard C `ungetc`.
*
* @param[in] buffer pointer to the buffer to get data from
* @param[in] size how many bytes to read from the buffer
*/
void furi_thread_stdin_unread(char* buffer, size_t size);
/**
* @brief Suspend a thread.
*
* Suspended threads are no more receiving any of the processor time.
*
* @param[in] thread_id unique identifier of the thread to be suspended
*/
void furi_thread_suspend(FuriThreadId thread_id);
/**
* @brief Resume a thread.
*
* @param[in] thread_id unique identifier of the thread to be resumed
*/
void furi_thread_resume(FuriThreadId thread_id);
/**
* @brief Test if a thread is suspended.
*
* @param[in] thread_id unique identifier of the thread to be queried
* @return true if thread is suspended, false otherwise
*/
bool furi_thread_is_suspended(FuriThreadId thread_id);
#ifdef __cplusplus
}
#endif