2021-10-03 10:36:05 +00:00
|
|
|
/**
|
|
|
|
* @file thread.h
|
|
|
|
* Furi: Furi Thread API
|
|
|
|
*/
|
|
|
|
|
2021-02-12 17:24:34 +00:00
|
|
|
#pragma once
|
|
|
|
|
2022-06-20 14:54:48 +00:00
|
|
|
#include "base.h"
|
2022-07-20 10:56:33 +00:00
|
|
|
#include "common_defines.h"
|
2021-02-12 17:24:34 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2021-03-24 09:35:33 +00:00
|
|
|
/** FuriThreadState */
|
2021-02-12 17:24:34 +00:00
|
|
|
typedef enum {
|
|
|
|
FuriThreadStateStopped,
|
|
|
|
FuriThreadStateStarting,
|
|
|
|
FuriThreadStateRunning,
|
|
|
|
} FuriThreadState;
|
|
|
|
|
2022-06-20 14:54:48 +00:00
|
|
|
/** FuriThreadPriority */
|
|
|
|
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 */
|
|
|
|
FuriThreadPriorityIsr = 32, /**< Deffered Isr (highest possible) */
|
|
|
|
} FuriThreadPriority;
|
|
|
|
|
2021-03-24 09:35:33 +00:00
|
|
|
/** FuriThread anonymous structure */
|
2021-02-12 17:24:34 +00:00
|
|
|
typedef struct FuriThread FuriThread;
|
|
|
|
|
2022-06-20 14:54:48 +00:00
|
|
|
/** FuriThreadId proxy type to OS low level functions */
|
|
|
|
typedef void* FuriThreadId;
|
|
|
|
|
2021-10-03 10:36:05 +00:00
|
|
|
/** FuriThreadCallback Your callback to run in new thread
|
|
|
|
* @warning never use osThreadExit in FuriThread
|
2021-02-12 17:24:34 +00:00
|
|
|
*/
|
|
|
|
typedef int32_t (*FuriThreadCallback)(void* context);
|
|
|
|
|
2021-10-03 10:36:05 +00:00
|
|
|
/** FuriThread state change calback called upon thread state change
|
|
|
|
* @param state new thread state
|
|
|
|
* @param context callback context
|
2021-02-12 17:24:34 +00:00
|
|
|
*/
|
|
|
|
typedef void (*FuriThreadStateCallback)(FuriThreadState state, void* context);
|
|
|
|
|
2021-06-23 14:48:44 +00:00
|
|
|
/** Allocate FuriThread
|
2021-10-03 10:36:05 +00:00
|
|
|
*
|
|
|
|
* @return FuriThread instance
|
2021-02-12 17:24:34 +00:00
|
|
|
*/
|
|
|
|
FuriThread* furi_thread_alloc();
|
|
|
|
|
2021-06-23 14:48:44 +00:00
|
|
|
/** Release FuriThread
|
2021-10-03 10:36:05 +00:00
|
|
|
*
|
|
|
|
* @param thread FuriThread instance
|
2021-02-12 17:24:34 +00:00
|
|
|
*/
|
|
|
|
void furi_thread_free(FuriThread* thread);
|
|
|
|
|
2021-06-23 14:48:44 +00:00
|
|
|
/** Set FuriThread name
|
2021-10-03 10:36:05 +00:00
|
|
|
*
|
|
|
|
* @param thread FuriThread instance
|
|
|
|
* @param name string
|
2021-02-12 17:24:34 +00:00
|
|
|
*/
|
|
|
|
void furi_thread_set_name(FuriThread* thread, const char* name);
|
|
|
|
|
2021-06-23 14:48:44 +00:00
|
|
|
/** Set FuriThread stack size
|
2021-10-03 10:36:05 +00:00
|
|
|
*
|
|
|
|
* @param thread FuriThread instance
|
|
|
|
* @param stack_size stack size in bytes
|
2021-02-12 17:24:34 +00:00
|
|
|
*/
|
|
|
|
void furi_thread_set_stack_size(FuriThread* thread, size_t stack_size);
|
|
|
|
|
2021-06-23 14:48:44 +00:00
|
|
|
/** Set FuriThread callback
|
2021-10-03 10:36:05 +00:00
|
|
|
*
|
|
|
|
* @param thread FuriThread instance
|
|
|
|
* @param callback FuriThreadCallback, called upon thread run
|
2021-02-12 17:24:34 +00:00
|
|
|
*/
|
|
|
|
void furi_thread_set_callback(FuriThread* thread, FuriThreadCallback callback);
|
|
|
|
|
2021-06-23 14:48:44 +00:00
|
|
|
/** Set FuriThread context
|
2021-10-03 10:36:05 +00:00
|
|
|
*
|
|
|
|
* @param thread FuriThread instance
|
|
|
|
* @param context pointer to context for thread callback
|
2021-02-12 17:24:34 +00:00
|
|
|
*/
|
|
|
|
void furi_thread_set_context(FuriThread* thread, void* context);
|
|
|
|
|
2022-06-20 14:54:48 +00:00
|
|
|
/** Set FuriThread priority
|
|
|
|
*
|
|
|
|
* @param thread FuriThread instance
|
|
|
|
* @param priority FuriThreadPriority value
|
|
|
|
*/
|
|
|
|
void furi_thread_set_priority(FuriThread* thread, FuriThreadPriority priority);
|
|
|
|
|
2021-06-23 14:48:44 +00:00
|
|
|
/** Set FuriThread state change callback
|
2021-10-03 10:36:05 +00:00
|
|
|
*
|
|
|
|
* @param thread FuriThread instance
|
|
|
|
* @param callback state change callback
|
2021-02-12 17:24:34 +00:00
|
|
|
*/
|
|
|
|
void furi_thread_set_state_callback(FuriThread* thread, FuriThreadStateCallback callback);
|
|
|
|
|
2021-06-23 14:48:44 +00:00
|
|
|
/** Set FuriThread state change context
|
2021-10-03 10:36:05 +00:00
|
|
|
*
|
|
|
|
* @param thread FuriThread instance
|
|
|
|
* @param context pointer to context
|
2021-02-12 17:24:34 +00:00
|
|
|
*/
|
|
|
|
void furi_thread_set_state_context(FuriThread* thread, void* context);
|
|
|
|
|
2021-06-23 14:48:44 +00:00
|
|
|
/** Get FuriThread state
|
2021-10-03 10:36:05 +00:00
|
|
|
*
|
|
|
|
* @param thread FuriThread instance
|
|
|
|
*
|
|
|
|
* @return thread state from FuriThreadState
|
2021-03-18 07:58:16 +00:00
|
|
|
*/
|
|
|
|
FuriThreadState furi_thread_get_state(FuriThread* thread);
|
|
|
|
|
2021-06-23 14:48:44 +00:00
|
|
|
/** Start FuriThread
|
2021-10-03 10:36:05 +00:00
|
|
|
*
|
|
|
|
* @param thread FuriThread instance
|
2021-02-12 17:24:34 +00:00
|
|
|
*/
|
2022-06-20 14:54:48 +00:00
|
|
|
void furi_thread_start(FuriThread* thread);
|
2021-02-12 17:24:34 +00:00
|
|
|
|
2021-06-23 14:48:44 +00:00
|
|
|
/** Join FuriThread
|
2021-10-03 10:36:05 +00:00
|
|
|
*
|
|
|
|
* @param thread FuriThread instance
|
|
|
|
*
|
2022-06-20 14:54:48 +00:00
|
|
|
* @return bool
|
2021-02-12 17:24:34 +00:00
|
|
|
*/
|
2022-06-20 14:54:48 +00:00
|
|
|
bool furi_thread_join(FuriThread* thread);
|
2021-02-12 17:24:34 +00:00
|
|
|
|
2022-06-20 14:54:48 +00:00
|
|
|
/** Get FreeRTOS FuriThreadId for FuriThread instance
|
2021-10-03 10:36:05 +00:00
|
|
|
*
|
|
|
|
* @param thread FuriThread instance
|
|
|
|
*
|
2022-06-20 14:54:48 +00:00
|
|
|
* @return FuriThreadId or NULL
|
2021-06-23 14:48:44 +00:00
|
|
|
*/
|
2022-06-20 14:54:48 +00:00
|
|
|
FuriThreadId furi_thread_get_id(FuriThread* thread);
|
2021-06-23 14:48:44 +00:00
|
|
|
|
|
|
|
/** Enable heap tracing
|
2021-10-03 10:36:05 +00:00
|
|
|
*
|
|
|
|
* @param thread FuriThread instance
|
2021-06-23 14:48:44 +00:00
|
|
|
*/
|
|
|
|
void furi_thread_enable_heap_trace(FuriThread* thread);
|
|
|
|
|
|
|
|
/** Disable heap tracing
|
2021-10-03 10:36:05 +00:00
|
|
|
*
|
|
|
|
* @param thread FuriThread instance
|
2021-06-23 14:48:44 +00:00
|
|
|
*/
|
|
|
|
void furi_thread_disable_heap_trace(FuriThread* thread);
|
|
|
|
|
|
|
|
/** Get thread heap size
|
2021-10-03 10:36:05 +00:00
|
|
|
*
|
|
|
|
* @param thread FuriThread instance
|
|
|
|
*
|
|
|
|
* @return size in bytes
|
2021-06-23 14:48:44 +00:00
|
|
|
*/
|
|
|
|
size_t furi_thread_get_heap_size(FuriThread* thread);
|
|
|
|
|
2022-04-13 20:50:25 +00:00
|
|
|
/** Get thread return code
|
|
|
|
*
|
|
|
|
* @param thread FuriThread instance
|
|
|
|
*
|
|
|
|
* @return return code
|
|
|
|
*/
|
|
|
|
int32_t furi_thread_get_return_code(FuriThread* thread);
|
|
|
|
|
2022-06-20 14:54:48 +00:00
|
|
|
/** Thread releated methods that doesn't involve FuriThread directly */
|
|
|
|
|
|
|
|
/** Get FreeRTOS FuriThreadId for current thread
|
|
|
|
*
|
|
|
|
* @param thread FuriThread instance
|
|
|
|
*
|
|
|
|
* @return FuriThreadId or NULL
|
|
|
|
*/
|
|
|
|
FuriThreadId furi_thread_get_current_id();
|
|
|
|
|
|
|
|
/** Return control to scheduler */
|
|
|
|
void furi_thread_yield();
|
|
|
|
|
|
|
|
uint32_t furi_thread_flags_set(FuriThreadId thread_id, uint32_t flags);
|
|
|
|
|
|
|
|
uint32_t furi_thread_flags_clear(uint32_t flags);
|
|
|
|
|
|
|
|
uint32_t furi_thread_flags_get(void);
|
|
|
|
|
|
|
|
uint32_t furi_thread_flags_wait(uint32_t flags, uint32_t options, uint32_t timeout);
|
|
|
|
|
|
|
|
uint32_t furi_thread_enumerate(FuriThreadId* thread_array, uint32_t array_items);
|
|
|
|
|
|
|
|
const char* furi_thread_get_name(FuriThreadId thread_id);
|
|
|
|
|
|
|
|
uint32_t furi_thread_get_stack_space(FuriThreadId thread_id);
|
|
|
|
|
2021-02-12 17:24:34 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
2022-05-06 13:37:10 +00:00
|
|
|
#endif
|