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
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <cmsis_os2.h>
|
|
|
|
|
|
|
|
#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;
|
|
|
|
|
2021-03-24 09:35:33 +00:00
|
|
|
/** FuriThread anonymous structure */
|
2021-02-12 17:24:34 +00:00
|
|
|
typedef struct FuriThread FuriThread;
|
|
|
|
|
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);
|
|
|
|
|
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
|
|
|
|
*
|
|
|
|
* @return true on success
|
2021-02-12 17:24:34 +00:00
|
|
|
*/
|
|
|
|
bool furi_thread_start(FuriThread* thread);
|
|
|
|
|
2021-06-23 14:48:44 +00:00
|
|
|
/** Treminate FuriThread
|
2021-10-03 10:36:05 +00:00
|
|
|
*
|
|
|
|
* @param thread FuriThread instance
|
|
|
|
*
|
|
|
|
* @return osStatus_t
|
|
|
|
* @warning terminating statefull thread is dangerous use only if you know
|
|
|
|
* what you doing
|
2021-02-12 17:24:34 +00:00
|
|
|
*/
|
|
|
|
osStatus_t furi_thread_terminate(FuriThread* thread);
|
|
|
|
|
2021-06-23 14:48:44 +00:00
|
|
|
/** Join FuriThread
|
2021-10-03 10:36:05 +00:00
|
|
|
*
|
|
|
|
* @param thread FuriThread instance
|
|
|
|
*
|
|
|
|
* @return osStatus_t
|
2021-02-12 17:24:34 +00:00
|
|
|
*/
|
|
|
|
osStatus_t furi_thread_join(FuriThread* thread);
|
|
|
|
|
2021-06-23 14:48:44 +00:00
|
|
|
/** Get CMSIS Thread ID
|
2021-10-03 10:36:05 +00:00
|
|
|
*
|
|
|
|
* @param thread FuriThread instance
|
|
|
|
*
|
|
|
|
* @return osThreadId_t or NULL
|
2021-06-23 14:48:44 +00:00
|
|
|
*/
|
|
|
|
osThreadId_t furi_thread_get_thread_id(FuriThread* thread);
|
|
|
|
|
|
|
|
/** 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);
|
|
|
|
|
2021-02-12 17:24:34 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
2022-05-06 13:37:10 +00:00
|
|
|
#endif
|