2021-10-03 13:36:05 +03:00
|
|
|
/**
|
|
|
|
|
* @file thread.h
|
2024-06-05 20:04:03 +03:00
|
|
|
* @brief Furi: Furi Thread API
|
2021-10-03 13:36:05 +03:00
|
|
|
*/
|
|
|
|
|
|
2021-02-12 20:24:34 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
2022-06-20 17:54:48 +03:00
|
|
|
#include "base.h"
|
2022-07-20 13:56:33 +03:00
|
|
|
#include "common_defines.h"
|
2021-02-12 20:24:34 +03:00
|
|
|
|
2023-11-01 16:24:11 +09:00
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <stddef.h>
|
|
|
|
|
|
2021-02-12 20:24:34 +03:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
2024-06-05 20:04:03 +03:00
|
|
|
/**
|
|
|
|
|
* @brief Enumeration of possible FuriThread states.
|
|
|
|
|
*
|
|
|
|
|
* Many of the FuriThread functions MUST ONLY be called when the thread is STOPPED.
|
|
|
|
|
*/
|
2021-02-12 20:24:34 +03:00
|
|
|
typedef enum {
|
2024-06-05 20:04:03 +03:00
|
|
|
FuriThreadStateStopped, /**< Thread is stopped */
|
|
|
|
|
FuriThreadStateStarting, /**< Thread is starting */
|
|
|
|
|
FuriThreadStateRunning, /**< Thread is running */
|
2021-02-12 20:24:34 +03:00
|
|
|
} FuriThreadState;
|
|
|
|
|
|
2024-06-05 20:04:03 +03:00
|
|
|
/**
|
|
|
|
|
* @brief Enumeration of possible FuriThread priorities.
|
|
|
|
|
*/
|
2022-06-20 17:54:48 +03:00
|
|
|
typedef enum {
|
|
|
|
|
FuriThreadPriorityNone = 0, /**< Uninitialized, choose system default */
|
|
|
|
|
FuriThreadPriorityIdle = 1, /**< Idle priority */
|
|
|
|
|
FuriThreadPriorityLowest = 14, /**< Lowest */
|
|
|
|
|
FuriThreadPriorityLow = 15, /**< Low */
|
|
|
|
|
FuriThreadPriorityNormal = 16, /**< Normal */
|
|
|
|
|
FuriThreadPriorityHigh = 17, /**< High */
|
|
|
|
|
FuriThreadPriorityHighest = 18, /**< Highest */
|
2023-11-01 16:24:11 +09:00
|
|
|
FuriThreadPriorityIsr =
|
|
|
|
|
(FURI_CONFIG_THREAD_MAX_PRIORITIES - 1), /**< Deferred ISR (highest possible) */
|
2022-06-20 17:54:48 +03:00
|
|
|
} FuriThreadPriority;
|
|
|
|
|
|
2024-06-05 20:04:03 +03:00
|
|
|
/**
|
|
|
|
|
* @brief FuriThread opaque type.
|
|
|
|
|
*/
|
2021-02-12 20:24:34 +03:00
|
|
|
typedef struct FuriThread FuriThread;
|
|
|
|
|
|
2024-06-05 20:04:03 +03:00
|
|
|
/**
|
|
|
|
|
* @brief Unique thread identifier type (used by the OS kernel).
|
|
|
|
|
*/
|
2022-06-20 17:54:48 +03:00
|
|
|
typedef void* FuriThreadId;
|
|
|
|
|
|
2024-06-05 20:04:03 +03:00
|
|
|
/**
|
|
|
|
|
* @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
|
2021-02-12 20:24:34 +03:00
|
|
|
*/
|
|
|
|
|
typedef int32_t (*FuriThreadCallback)(void* context);
|
|
|
|
|
|
2024-06-05 20:04:03 +03:00
|
|
|
/**
|
|
|
|
|
* @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
|
2022-08-04 02:00:17 +10:00
|
|
|
*/
|
|
|
|
|
typedef void (*FuriThreadStdoutWriteCallback)(const char* data, size_t size);
|
|
|
|
|
|
2024-06-05 20:04:03 +03:00
|
|
|
/**
|
|
|
|
|
* @brief State change callback function pointer type.
|
|
|
|
|
*
|
|
|
|
|
* The function to be used as a state callback MUST follow this signature.
|
|
|
|
|
*
|
|
|
|
|
* @param[in] state identifier of the state the thread has transitioned to
|
|
|
|
|
* @param[in,out] context pointer to a user-specified object
|
2021-02-12 20:24:34 +03:00
|
|
|
*/
|
|
|
|
|
typedef void (*FuriThreadStateCallback)(FuriThreadState state, void* context);
|
|
|
|
|
|
2024-06-05 20:04:03 +03:00
|
|
|
/**
|
|
|
|
|
* @brief Create a FuriThread instance.
|
2021-10-03 13:36:05 +03:00
|
|
|
*
|
2024-06-05 20:04:03 +03:00
|
|
|
* @return pointer to the created FuriThread instance
|
2021-02-12 20:24:34 +03:00
|
|
|
*/
|
2024-03-19 23:43:52 +09:00
|
|
|
FuriThread* furi_thread_alloc(void);
|
2021-02-12 20:24:34 +03:00
|
|
|
|
2024-06-05 20:04:03 +03:00
|
|
|
/**
|
|
|
|
|
* @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.
|
2022-11-23 22:49:17 +10:00
|
|
|
*
|
2024-06-05 20:04:03 +03:00
|
|
|
* @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
|
2022-11-23 22:49:17 +10:00
|
|
|
*/
|
|
|
|
|
FuriThread* furi_thread_alloc_ex(
|
|
|
|
|
const char* name,
|
|
|
|
|
uint32_t stack_size,
|
|
|
|
|
FuriThreadCallback callback,
|
|
|
|
|
void* context);
|
|
|
|
|
|
2024-06-05 20:04:03 +03:00
|
|
|
/**
|
|
|
|
|
* @brief Delete a FuriThread instance.
|
|
|
|
|
*
|
|
|
|
|
* The thread MUST be stopped when calling this function.
|
2023-03-28 00:34:49 -07:00
|
|
|
*
|
2024-06-05 20:04:03 +03:00
|
|
|
* @warning see furi_thread_join for caveats on stopping a thread.
|
2021-10-03 13:36:05 +03:00
|
|
|
*
|
2024-06-05 20:04:03 +03:00
|
|
|
* @param[in,out] thread pointer to the FuriThread instance to be deleted
|
2021-02-12 20:24:34 +03:00
|
|
|
*/
|
|
|
|
|
void furi_thread_free(FuriThread* thread);
|
|
|
|
|
|
2024-06-05 20:04:03 +03:00
|
|
|
/**
|
|
|
|
|
* @brief Set the name of a FuriThread instance.
|
|
|
|
|
*
|
|
|
|
|
* The thread MUST be stopped when calling this function.
|
2021-10-03 13:36:05 +03:00
|
|
|
*
|
2024-06-05 20:04:03 +03:00
|
|
|
* @param[in,out] thread pointer to the FuriThread instance to be modified
|
|
|
|
|
* @param[in] name human-readable thread name (can be NULL)
|
2021-02-12 20:24:34 +03:00
|
|
|
*/
|
|
|
|
|
void furi_thread_set_name(FuriThread* thread, const char* name);
|
|
|
|
|
|
2023-03-01 20:57:27 +03:00
|
|
|
/**
|
2024-06-05 20:04:03 +03:00
|
|
|
* @brief Set the application ID of a FuriThread instance.
|
|
|
|
|
*
|
|
|
|
|
* The thread MUST be stopped when calling this function.
|
|
|
|
|
*
|
2023-03-01 20:57:27 +03:00
|
|
|
* 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.
|
|
|
|
|
*
|
2024-06-05 20:04:03 +03:00
|
|
|
* @param[in,out] thread pointer to the FuriThread instance to be modified
|
|
|
|
|
* @param[in] appid thread application ID (can be NULL)
|
2023-03-01 20:57:27 +03:00
|
|
|
*/
|
|
|
|
|
void furi_thread_set_appid(FuriThread* thread, const char* appid);
|
|
|
|
|
|
2024-06-05 20:04:03 +03:00
|
|
|
/**
|
|
|
|
|
* @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.
|
2021-10-03 13:36:05 +03:00
|
|
|
*
|
2024-06-05 20:04:03 +03:00
|
|
|
* @param[in,out] thread pointer to the FuriThread instance to be modified
|
|
|
|
|
* @param[in] stack_size stack size in bytes
|
2021-02-12 20:24:34 +03:00
|
|
|
*/
|
|
|
|
|
void furi_thread_set_stack_size(FuriThread* thread, size_t stack_size);
|
|
|
|
|
|
2024-06-05 20:04:03 +03:00
|
|
|
/**
|
|
|
|
|
* @brief Set the user callback function to be executed in a FuriThread.
|
|
|
|
|
*
|
|
|
|
|
* The thread MUST be stopped when calling this function.
|
2021-10-03 13:36:05 +03:00
|
|
|
*
|
2024-06-05 20:04:03 +03:00
|
|
|
* @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
|
2021-02-12 20:24:34 +03:00
|
|
|
*/
|
|
|
|
|
void furi_thread_set_callback(FuriThread* thread, FuriThreadCallback callback);
|
|
|
|
|
|
2024-06-05 20:04:03 +03:00
|
|
|
/**
|
|
|
|
|
* @brief Set the callback function context.
|
2021-10-03 13:36:05 +03:00
|
|
|
*
|
2024-06-05 20:04:03 +03:00
|
|
|
* 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)
|
2021-02-12 20:24:34 +03:00
|
|
|
*/
|
|
|
|
|
void furi_thread_set_context(FuriThread* thread, void* context);
|
|
|
|
|
|
2024-06-05 20:04:03 +03:00
|
|
|
/**
|
|
|
|
|
* @brief Set the priority of a FuriThread.
|
2022-06-20 17:54:48 +03:00
|
|
|
*
|
2024-06-05 20:04:03 +03:00
|
|
|
* 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
|
2022-06-20 17:54:48 +03:00
|
|
|
*/
|
|
|
|
|
void furi_thread_set_priority(FuriThread* thread, FuriThreadPriority priority);
|
|
|
|
|
|
2024-06-05 20:04:03 +03:00
|
|
|
/**
|
|
|
|
|
* @brief Get the priority of a FuriThread.
|
2024-02-16 11:20:45 +04:00
|
|
|
*
|
2024-06-05 20:04:03 +03:00
|
|
|
* @param[in] thread pointer to the FuriThread instance to be queried
|
|
|
|
|
* @return priority level value
|
2024-02-16 11:20:45 +04:00
|
|
|
*/
|
|
|
|
|
FuriThreadPriority furi_thread_get_priority(FuriThread* thread);
|
|
|
|
|
|
2024-06-05 20:04:03 +03:00
|
|
|
/**
|
|
|
|
|
* @brief Set the priority of the current FuriThread.
|
2023-02-08 07:41:22 +03:00
|
|
|
*
|
2024-06-05 20:04:03 +03:00
|
|
|
* @param priority priority level value
|
2023-02-08 07:41:22 +03:00
|
|
|
*/
|
|
|
|
|
void furi_thread_set_current_priority(FuriThreadPriority priority);
|
|
|
|
|
|
2024-06-05 20:04:03 +03:00
|
|
|
/**
|
|
|
|
|
* @brief Get the priority of the current FuriThread.
|
2023-02-08 07:41:22 +03:00
|
|
|
*
|
2024-06-05 20:04:03 +03:00
|
|
|
* @return priority level value
|
2023-02-08 07:41:22 +03:00
|
|
|
*/
|
2024-03-19 23:43:52 +09:00
|
|
|
FuriThreadPriority furi_thread_get_current_priority(void);
|
2023-02-08 07:41:22 +03:00
|
|
|
|
2024-06-05 20:04:03 +03:00
|
|
|
/**
|
|
|
|
|
* Set the callback function to be executed upon a state thransition of a FuriThread.
|
|
|
|
|
*
|
|
|
|
|
* The thread MUST be stopped when calling this function.
|
2021-10-03 13:36:05 +03:00
|
|
|
*
|
2024-06-05 20:04:03 +03:00
|
|
|
* @param[in,out] thread pointer to the FuriThread instance to be modified
|
|
|
|
|
* @param[in] callback pointer to a user-specified callback function
|
2021-02-12 20:24:34 +03:00
|
|
|
*/
|
|
|
|
|
void furi_thread_set_state_callback(FuriThread* thread, FuriThreadStateCallback callback);
|
|
|
|
|
|
2024-06-05 20:04:03 +03:00
|
|
|
/**
|
|
|
|
|
* @brief Set the state change callback context.
|
|
|
|
|
*
|
|
|
|
|
* The thread MUST be stopped when calling this function.
|
2021-10-03 13:36:05 +03:00
|
|
|
*
|
2024-06-05 20:04:03 +03:00
|
|
|
* @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)
|
2021-02-12 20:24:34 +03:00
|
|
|
*/
|
|
|
|
|
void furi_thread_set_state_context(FuriThread* thread, void* context);
|
|
|
|
|
|
2024-06-05 20:04:03 +03:00
|
|
|
/**
|
|
|
|
|
* @brief Get the state of a FuriThread isntance.
|
2021-10-03 13:36:05 +03:00
|
|
|
*
|
2024-06-05 20:04:03 +03:00
|
|
|
* @param[in] thread pointer to the FuriThread instance to be queried
|
|
|
|
|
* @return thread state value
|
2021-03-18 10:58:16 +03:00
|
|
|
*/
|
|
|
|
|
FuriThreadState furi_thread_get_state(FuriThread* thread);
|
|
|
|
|
|
2024-06-05 20:04:03 +03:00
|
|
|
/**
|
|
|
|
|
* @brief Start a FuriThread instance.
|
|
|
|
|
*
|
|
|
|
|
* The thread MUST be stopped when calling this function.
|
2021-10-03 13:36:05 +03:00
|
|
|
*
|
2024-06-05 20:04:03 +03:00
|
|
|
* @param[in,out] thread pointer to the FuriThread instance to be started
|
2021-02-12 20:24:34 +03:00
|
|
|
*/
|
2022-06-20 17:54:48 +03:00
|
|
|
void furi_thread_start(FuriThread* thread);
|
2021-02-12 20:24:34 +03:00
|
|
|
|
2024-06-05 20:04:03 +03:00
|
|
|
/**
|
|
|
|
|
* @brief Wait for a FuriThread to exit.
|
2023-03-28 00:34:49 -07:00
|
|
|
*
|
2024-06-05 20:04:03 +03:00
|
|
|
* The thread callback function must return in order for the FuriThread instance to become joinable.
|
2021-10-03 13:36:05 +03:00
|
|
|
*
|
2024-06-05 20:04:03 +03:00
|
|
|
* @warning Use this method only when the CPU is not busy (i.e. when the
|
|
|
|
|
* Idle task receives control), otherwise it will wait forever.
|
2021-10-03 13:36:05 +03:00
|
|
|
*
|
2024-06-05 20:04:03 +03:00
|
|
|
* @param[in] thread pointer to the FuriThread instance to be joined
|
|
|
|
|
* @return always true
|
2021-02-12 20:24:34 +03:00
|
|
|
*/
|
2022-06-20 17:54:48 +03:00
|
|
|
bool furi_thread_join(FuriThread* thread);
|
2021-02-12 20:24:34 +03:00
|
|
|
|
2024-06-05 20:04:03 +03:00
|
|
|
/**
|
|
|
|
|
* @brief Get the unique identifier of a FuriThread instance.
|
2021-10-03 13:36:05 +03:00
|
|
|
*
|
2024-06-05 20:04:03 +03:00
|
|
|
* @param[in] thread pointer to the FuriThread instance to be queried
|
|
|
|
|
* @return unique identifier value or NULL if thread is not running
|
2021-06-23 17:48:44 +03:00
|
|
|
*/
|
2022-06-20 17:54:48 +03:00
|
|
|
FuriThreadId furi_thread_get_id(FuriThread* thread);
|
2021-06-23 17:48:44 +03:00
|
|
|
|
2024-06-05 20:04:03 +03:00
|
|
|
/**
|
|
|
|
|
* @brief Enable heap usage tracing for a FuriThread.
|
|
|
|
|
*
|
|
|
|
|
* The thread MUST be stopped when calling this function.
|
2021-10-03 13:36:05 +03:00
|
|
|
*
|
2024-06-05 20:04:03 +03:00
|
|
|
* @param[in,out] thread pointer to the FuriThread instance to be modified
|
2021-06-23 17:48:44 +03:00
|
|
|
*/
|
|
|
|
|
void furi_thread_enable_heap_trace(FuriThread* thread);
|
|
|
|
|
|
2024-06-05 20:04:03 +03:00
|
|
|
/**
|
|
|
|
|
* @brief Disable heap usage tracing for a FuriThread.
|
2021-10-03 13:36:05 +03:00
|
|
|
*
|
2024-06-05 20:04:03 +03:00
|
|
|
* The thread MUST be stopped when calling this function.
|
|
|
|
|
*
|
|
|
|
|
* @param[in,out] thread pointer to the FuriThread instance to be modified
|
2021-06-23 17:48:44 +03:00
|
|
|
*/
|
|
|
|
|
void furi_thread_disable_heap_trace(FuriThread* thread);
|
|
|
|
|
|
2024-06-05 20:04:03 +03:00
|
|
|
/**
|
|
|
|
|
* @brief Get heap usage by a FuriThread instance.
|
2021-10-03 13:36:05 +03:00
|
|
|
*
|
2024-06-05 20:04:03 +03:00
|
|
|
* The heap trace MUST be enabled before callgin this function.
|
2021-10-03 13:36:05 +03:00
|
|
|
*
|
2024-06-05 20:04:03 +03:00
|
|
|
* @param[in] thread pointer to the FuriThread instance to be queried
|
|
|
|
|
* @return heap usage in bytes
|
2021-06-23 17:48:44 +03:00
|
|
|
*/
|
|
|
|
|
size_t furi_thread_get_heap_size(FuriThread* thread);
|
|
|
|
|
|
2024-06-05 20:04:03 +03:00
|
|
|
/**
|
|
|
|
|
* @brief Get the return code of a FuriThread instance.
|
2022-04-13 23:50:25 +03:00
|
|
|
*
|
2024-06-05 20:04:03 +03:00
|
|
|
* This value is equal to the return value of the thread callback function.
|
2022-04-13 23:50:25 +03:00
|
|
|
*
|
2024-06-05 20:04:03 +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
|
2022-04-13 23:50:25 +03:00
|
|
|
*/
|
|
|
|
|
int32_t furi_thread_get_return_code(FuriThread* thread);
|
|
|
|
|
|
2024-06-05 20:04:03 +03:00
|
|
|
/**
|
|
|
|
|
* @brief Get the unique identifier of the current FuriThread.
|
2022-06-20 17:54:48 +03:00
|
|
|
*
|
2024-06-05 20:04:03 +03:00
|
|
|
* @return unique identifier value
|
2022-06-20 17:54:48 +03:00
|
|
|
*/
|
2024-03-19 23:43:52 +09:00
|
|
|
FuriThreadId furi_thread_get_current_id(void);
|
2022-06-20 17:54:48 +03:00
|
|
|
|
2024-06-05 20:04:03 +03:00
|
|
|
/**
|
|
|
|
|
* @brief Get the FuriThread instance associated with the current thread.
|
2022-08-04 02:00:17 +10:00
|
|
|
*
|
2024-06-05 20:04:03 +03:00
|
|
|
* @return pointer to a FuriThread instance or NULL if this thread does not belong to Furi
|
2022-08-04 02:00:17 +10:00
|
|
|
*/
|
2024-03-19 23:43:52 +09:00
|
|
|
FuriThread* furi_thread_get_current(void);
|
2022-08-04 02:00:17 +10:00
|
|
|
|
2024-06-05 20:04:03 +03:00
|
|
|
/**
|
|
|
|
|
* @brief Return control to the scheduler.
|
|
|
|
|
*/
|
2024-03-19 23:43:52 +09:00
|
|
|
void furi_thread_yield(void);
|
2022-06-20 17:54:48 +03:00
|
|
|
|
2024-06-05 20:04:03 +03:00
|
|
|
/**
|
|
|
|
|
* @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
|
|
|
|
|
*/
|
2022-06-20 17:54:48 +03:00
|
|
|
uint32_t furi_thread_flags_set(FuriThreadId thread_id, uint32_t flags);
|
|
|
|
|
|
2024-06-05 20:04:03 +03:00
|
|
|
/**
|
|
|
|
|
* @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
|
|
|
|
|
*/
|
2022-06-20 17:54:48 +03:00
|
|
|
uint32_t furi_thread_flags_clear(uint32_t flags);
|
|
|
|
|
|
2024-06-05 20:04:03 +03:00
|
|
|
/**
|
|
|
|
|
* @brief Get the thread flags of the current FuriThread.
|
|
|
|
|
* @return current bitmask of thread flags
|
|
|
|
|
*/
|
2022-06-20 17:54:48 +03:00
|
|
|
uint32_t furi_thread_flags_get(void);
|
|
|
|
|
|
2024-06-05 20:04:03 +03:00
|
|
|
/**
|
|
|
|
|
* @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
|
|
|
|
|
*/
|
2022-06-20 17:54:48 +03:00
|
|
|
uint32_t furi_thread_flags_wait(uint32_t flags, uint32_t options, uint32_t timeout);
|
|
|
|
|
|
2023-03-01 20:57:27 +03:00
|
|
|
/**
|
2024-06-05 20:04:03 +03:00
|
|
|
* @brief Enumerate all threads.
|
2023-03-01 20:57:27 +03:00
|
|
|
*
|
2024-06-05 20:04:03 +03:00
|
|
|
* @param[out] thread_array pointer to the output array (must be properly allocated)
|
|
|
|
|
* @param[in] array_item_count output array capacity in elements (NOT bytes)
|
|
|
|
|
* @return total thread count (array_item_count or less)
|
2023-03-01 20:57:27 +03:00
|
|
|
*/
|
2024-02-16 11:20:45 +04:00
|
|
|
uint32_t furi_thread_enumerate(FuriThreadId* thread_array, uint32_t array_item_count);
|
2022-06-20 17:54:48 +03:00
|
|
|
|
2023-03-01 20:57:27 +03:00
|
|
|
/**
|
2024-06-05 20:04:03 +03:00
|
|
|
* @brief Get the name of a thread based on its unique identifier.
|
2023-03-01 20:57:27 +03:00
|
|
|
*
|
2024-06-05 20:04:03 +03:00
|
|
|
* @param[in] thread_id unique identifier of the thread to be queried
|
|
|
|
|
* @return pointer to a zero-terminated string or NULL
|
2023-03-01 20:57:27 +03:00
|
|
|
*/
|
2022-06-20 17:54:48 +03:00
|
|
|
const char* furi_thread_get_name(FuriThreadId thread_id);
|
|
|
|
|
|
2023-03-01 20:57:27 +03:00
|
|
|
/**
|
2024-06-05 20:04:03 +03:00
|
|
|
* @brief Get the application id of a thread based on its unique identifier.
|
2023-03-01 20:57:27 +03:00
|
|
|
*
|
2024-06-05 20:04:03 +03:00
|
|
|
* @param[in] thread_id unique identifier of the thread to be queried
|
|
|
|
|
* @return pointer to a zero-terminated string
|
2023-03-01 20:57:27 +03:00
|
|
|
*/
|
|
|
|
|
const char* furi_thread_get_appid(FuriThreadId thread_id);
|
|
|
|
|
|
|
|
|
|
/**
|
2024-06-05 20:04:03 +03:00
|
|
|
* @brief Get thread stack watermark.
|
2023-03-01 20:57:27 +03:00
|
|
|
*
|
2024-06-05 20:04:03 +03:00
|
|
|
* @param[in] thread_id unique identifier of the thread to be queried
|
|
|
|
|
* @return stack watermark value
|
2023-03-01 20:57:27 +03:00
|
|
|
*/
|
2022-06-20 17:54:48 +03:00
|
|
|
uint32_t furi_thread_get_stack_space(FuriThreadId thread_id);
|
|
|
|
|
|
2024-06-05 20:04:03 +03:00
|
|
|
/**
|
|
|
|
|
* @brief Get the standard output callback for the current thead.
|
2023-01-30 10:54:15 +03:00
|
|
|
*
|
2024-06-05 20:04:03 +03:00
|
|
|
* @return pointer to the standard out callback function
|
2023-01-30 10:54:15 +03:00
|
|
|
*/
|
2024-03-19 23:43:52 +09:00
|
|
|
FuriThreadStdoutWriteCallback furi_thread_get_stdout_callback(void);
|
2023-01-30 10:54:15 +03:00
|
|
|
|
2024-06-05 20:04:03 +03:00
|
|
|
/** Set standard output callback for the current thread.
|
2023-05-05 21:40:55 +09:00
|
|
|
*
|
2024-06-05 20:04:03 +03:00
|
|
|
* @param[in] callback pointer to the callback function or NULL to clear
|
2022-08-04 02:00:17 +10:00
|
|
|
*/
|
2023-05-05 21:40:55 +09:00
|
|
|
void furi_thread_set_stdout_callback(FuriThreadStdoutWriteCallback callback);
|
2022-08-04 02:00:17 +10:00
|
|
|
|
2024-06-05 20:04:03 +03:00
|
|
|
/** Write data to buffered standard output.
|
2022-08-04 02:00:17 +10:00
|
|
|
*
|
2024-06-05 20:04:03 +03:00
|
|
|
* @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
|
2022-08-04 02:00:17 +10:00
|
|
|
*/
|
|
|
|
|
size_t furi_thread_stdout_write(const char* data, size_t size);
|
|
|
|
|
|
2024-06-05 20:04:03 +03:00
|
|
|
/**
|
|
|
|
|
* @brief Flush buffered data to standard output.
|
2022-08-04 02:00:17 +10:00
|
|
|
*
|
2024-06-05 20:04:03 +03:00
|
|
|
* @return error code value
|
2022-08-04 02:00:17 +10:00
|
|
|
*/
|
2024-03-19 23:43:52 +09:00
|
|
|
int32_t furi_thread_stdout_flush(void);
|
2022-08-04 02:00:17 +10:00
|
|
|
|
2024-06-05 20:04:03 +03:00
|
|
|
/**
|
|
|
|
|
* @brief Suspend a thread.
|
|
|
|
|
*
|
|
|
|
|
* Suspended threads are no more receiving any of the processor time.
|
2022-09-21 18:42:59 +04:00
|
|
|
*
|
2024-06-05 20:04:03 +03:00
|
|
|
* @param[in] thread_id unique identifier of the thread to be suspended
|
2022-09-21 18:42:59 +04:00
|
|
|
*/
|
|
|
|
|
void furi_thread_suspend(FuriThreadId thread_id);
|
|
|
|
|
|
2024-06-05 20:04:03 +03:00
|
|
|
/**
|
|
|
|
|
* @brief Resume a thread.
|
2022-09-21 18:42:59 +04:00
|
|
|
*
|
2024-06-05 20:04:03 +03:00
|
|
|
* @param[in] thread_id unique identifier of the thread to be resumed
|
2022-09-21 18:42:59 +04:00
|
|
|
*/
|
|
|
|
|
void furi_thread_resume(FuriThreadId thread_id);
|
|
|
|
|
|
2024-06-05 20:04:03 +03:00
|
|
|
/**
|
|
|
|
|
* @brief Test if a thread is suspended.
|
2022-09-21 18:42:59 +04:00
|
|
|
*
|
2024-06-05 20:04:03 +03:00
|
|
|
* @param[in] thread_id unique identifier of the thread to be queried
|
|
|
|
|
* @return true if thread is suspended, false otherwise
|
2022-09-21 18:42:59 +04:00
|
|
|
*/
|
|
|
|
|
bool furi_thread_is_suspended(FuriThreadId thread_id);
|
|
|
|
|
|
2021-02-12 20:24:34 +03:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
2022-05-06 16:37:10 +03:00
|
|
|
#endif
|