Merge remote-tracking branch 'ofw/dev' into mntm-dev

This commit is contained in:
Willy-JL
2024-10-04 21:36:59 +01:00
23 changed files with 1475 additions and 1345 deletions

View File

@@ -1,7 +1,6 @@
#include "thread.h"
#include "thread_i.h"
#include "thread_list_i.h"
#include "timer.h"
#include "thread_list.h"
#include "kernel.h"
#include "memmgr.h"
#include "memmgr_heap.h"
@@ -25,6 +24,52 @@
#define THREAD_MAX_STACK_SIZE (UINT16_MAX * sizeof(StackType_t))
typedef struct FuriThreadStdout FuriThreadStdout;
struct FuriThreadStdout {
FuriThreadStdoutWriteCallback write_callback;
FuriString* buffer;
};
struct FuriThread {
StaticTask_t container;
StackType_t* stack_buffer;
FuriThreadState state;
int32_t ret;
FuriThreadCallback callback;
void* context;
FuriThreadStateCallback state_callback;
void* state_context;
FuriThreadSignalCallback signal_callback;
void* signal_context;
char* name;
char* appid;
FuriThreadPriority priority;
size_t stack_size;
size_t heap_size;
FuriThreadStdout output;
// Keep all non-alignable byte types in one place,
// this ensures that the size of this structure is minimal
bool is_service;
bool heap_trace_enabled;
volatile bool is_active;
};
// IMPORTANT: container MUST be the FIRST struct member
static_assert(offsetof(FuriThread, container) == 0);
// Our idle priority should be equal to the one from FreeRTOS
static_assert(FuriThreadPriorityIdle == tskIDLE_PRIORITY);
static size_t __furi_thread_stdout_write(FuriThread* thread, const char* data, size_t size);
static int32_t __furi_thread_stdout_flush(FuriThread* thread);
@@ -105,6 +150,8 @@ static void furi_thread_init_common(FuriThread* thread) {
furi_thread_set_appid(thread, "driver");
}
thread->priority = FuriThreadPriorityNormal;
FuriHalRtcHeapTrackMode mode = furi_hal_rtc_get_heap_track_mode();
if(mode == FuriHalRtcHeapTrackModeAll) {
thread->heap_trace_enabled = true;
@@ -229,7 +276,7 @@ void furi_thread_set_context(FuriThread* thread, void* context) {
void furi_thread_set_priority(FuriThread* thread, FuriThreadPriority priority) {
furi_check(thread);
furi_check(thread->state == FuriThreadStateStopped);
furi_check(priority >= FuriThreadPriorityIdle && priority <= FuriThreadPriorityIsr);
furi_check(priority <= FuriThreadPriorityIsr);
thread->priority = priority;
}
@@ -241,9 +288,7 @@ FuriThreadPriority furi_thread_get_priority(FuriThread* thread) {
void furi_thread_set_current_priority(FuriThreadPriority priority) {
furi_check(priority <= FuriThreadPriorityIsr);
UBaseType_t new_priority = priority ? priority : FuriThreadPriorityNormal;
vTaskPrioritySet(NULL, new_priority);
vTaskPrioritySet(NULL, priority);
}
FuriThreadPriority furi_thread_get_current_priority(void) {
@@ -305,7 +350,6 @@ void furi_thread_start(FuriThread* thread) {
furi_thread_set_state(thread, FuriThreadStateStarting);
uint32_t stack_depth = thread->stack_size / sizeof(StackType_t);
UBaseType_t priority = thread->priority ? thread->priority : FuriThreadPriorityNormal;
thread->is_active = true;
@@ -315,7 +359,7 @@ void furi_thread_start(FuriThread* thread) {
thread->name,
stack_depth,
thread,
priority,
thread->priority,
thread->stack_buffer,
&thread->container) == (TaskHandle_t)thread);
}

View File

@@ -30,11 +30,10 @@ typedef enum {
* @brief Enumeration of possible FuriThread priorities.
*/
typedef enum {
FuriThreadPriorityNone = 0, /**< Uninitialized, choose system default */
FuriThreadPriorityIdle = 1, /**< Idle priority */
FuriThreadPriorityIdle = 0, /**< Idle priority */
FuriThreadPriorityLowest = 14, /**< Lowest */
FuriThreadPriorityLow = 15, /**< Low */
FuriThreadPriorityNormal = 16, /**< Normal */
FuriThreadPriorityNormal = 16, /**< Normal, system default */
FuriThreadPriorityHigh = 17, /**< High */
FuriThreadPriorityHighest = 18, /**< Highest */
FuriThreadPriorityIsr =

View File

@@ -1,48 +0,0 @@
#pragma once
#include "thread.h"
#include "string.h"
#include <FreeRTOS.h>
#include <task.h>
typedef struct {
FuriThreadStdoutWriteCallback write_callback;
FuriString* buffer;
} FuriThreadStdout;
struct FuriThread {
StaticTask_t container;
StackType_t* stack_buffer;
FuriThreadState state;
int32_t ret;
FuriThreadCallback callback;
void* context;
FuriThreadStateCallback state_callback;
void* state_context;
FuriThreadSignalCallback signal_callback;
void* signal_context;
char* name;
char* appid;
FuriThreadPriority priority;
size_t stack_size;
size_t heap_size;
FuriThreadStdout output;
// Keep all non-alignable byte types in one place,
// this ensures that the size of this structure is minimal
bool is_service;
bool heap_trace_enabled;
volatile bool is_active;
};
// IMPORTANT: container MUST be the FIRST struct member
static_assert(offsetof(FuriThread, container) == 0);

View File

@@ -84,7 +84,7 @@ FuriThreadListItem* furi_thread_list_get_or_insert(FuriThreadList* instance, Fur
}
void furi_thread_list_process(FuriThreadList* instance, uint32_t runtime, uint32_t tick) {
furi_check(instance);
furi_assert(instance);
instance->runtime_previous = instance->runtime_current;
instance->runtime_current = runtime;

View File

@@ -68,14 +68,6 @@ FuriThreadListItem* furi_thread_list_get_at(FuriThreadList* instance, size_t pos
*/
FuriThreadListItem* furi_thread_list_get_or_insert(FuriThreadList* instance, FuriThread* thread);
/** Process items in the FuriThreadList instance
*
* @param instance The instance
* @param[in] runtime The runtime of the system since start
* @param[in] tick The tick when processing happened
*/
void furi_thread_list_process(FuriThreadList* instance, uint32_t runtime, uint32_t tick);
/** Get percent of time spent in ISR
*
* @param instance The instance

19
furi/core/thread_list_i.h Normal file
View File

@@ -0,0 +1,19 @@
#pragma once
#include "thread_list.h"
#ifdef __cplusplus
extern "C" {
#endif
/** Process items in the FuriThreadList instance
*
* @param instance The instance
* @param[in] runtime The runtime of the system since start
* @param[in] tick The tick when processing happened
*/
void furi_thread_list_process(FuriThreadList* instance, uint32_t runtime, uint32_t tick);
#ifdef __cplusplus
}
#endif