mirror of
https://github.com/flipperdevices/flipperzero-firmware.git
synced 2025-12-12 04:41:26 +04:00
Api Symbols: replace asserts with checks (#3507)
* Api Symbols: replace asserts with checks * Api Symbols: replace asserts with checks part 2 * Update no args function signatures with void, to help compiler to track incorrect usage * More unavoidable void * Update PVS config and code to make it happy * Format sources * nfc: fix checks * dead code cleanup & include fixes Co-authored-by: gornekich <n.gorbadey@gmail.com> Co-authored-by: hedger <hedger@users.noreply.github.com> Co-authored-by: hedger <hedger@nanode.su>
This commit is contained in:
@@ -67,7 +67,7 @@ static void __furi_put_uint32_as_hex(uint32_t data) {
|
||||
furi_log_puts(tmp_str);
|
||||
}
|
||||
|
||||
static void __furi_print_register_info() {
|
||||
static void __furi_print_register_info(void) {
|
||||
// Print registers
|
||||
for(uint8_t i = 0; i < 12; i++) {
|
||||
furi_log_puts("\r\n\tr");
|
||||
@@ -80,12 +80,12 @@ static void __furi_print_register_info() {
|
||||
__furi_put_uint32_as_hex(__furi_check_registers[12]);
|
||||
}
|
||||
|
||||
static void __furi_print_stack_info() {
|
||||
static void __furi_print_stack_info(void) {
|
||||
furi_log_puts("\r\n\tstack watermark: ");
|
||||
__furi_put_uint32_as_text(uxTaskGetStackHighWaterMark(NULL) * 4);
|
||||
}
|
||||
|
||||
static void __furi_print_bt_stack_info() {
|
||||
static void __furi_print_bt_stack_info(void) {
|
||||
const BleGlueHardfaultInfo* fault_info = ble_glue_get_hardfault_info();
|
||||
if(fault_info == NULL) {
|
||||
furi_log_puts("\r\n\tcore2: not faulted");
|
||||
@@ -99,7 +99,7 @@ static void __furi_print_bt_stack_info() {
|
||||
}
|
||||
}
|
||||
|
||||
static void __furi_print_heap_info() {
|
||||
static void __furi_print_heap_info(void) {
|
||||
furi_log_puts("\r\n\t heap total: ");
|
||||
__furi_put_uint32_as_text(xPortGetTotalHeapSize());
|
||||
furi_log_puts("\r\n\t heap free: ");
|
||||
@@ -125,7 +125,7 @@ static void __furi_print_name(bool isr) {
|
||||
}
|
||||
}
|
||||
|
||||
FURI_NORETURN void __furi_crash_implementation() {
|
||||
FURI_NORETURN void __furi_crash_implementation(void) {
|
||||
__disable_irq();
|
||||
GET_MESSAGE_AND_STORE_REGISTERS();
|
||||
|
||||
@@ -176,7 +176,7 @@ FURI_NORETURN void __furi_crash_implementation() {
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
FURI_NORETURN void __furi_halt_implementation() {
|
||||
FURI_NORETURN void __furi_halt_implementation(void) {
|
||||
__disable_irq();
|
||||
GET_MESSAGE_AND_STORE_REGISTERS();
|
||||
|
||||
|
||||
@@ -14,13 +14,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <m-core.h>
|
||||
#include "common_defines.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#define FURI_NORETURN [[noreturn]]
|
||||
#else
|
||||
#include <stdnoreturn.h>
|
||||
#define FURI_NORETURN noreturn
|
||||
#endif
|
||||
|
||||
// Flags instead of pointers will save ~4 bytes on furi_assert and furi_check calls.
|
||||
@@ -28,10 +25,10 @@ extern "C" {
|
||||
#define __FURI_CHECK_MESSAGE_FLAG (0x02)
|
||||
|
||||
/** Crash system */
|
||||
FURI_NORETURN void __furi_crash_implementation();
|
||||
FURI_NORETURN void __furi_crash_implementation(void);
|
||||
|
||||
/** Halt system */
|
||||
FURI_NORETURN void __furi_halt_implementation();
|
||||
FURI_NORETURN void __furi_halt_implementation(void);
|
||||
|
||||
/** Crash system with message. Show message after reboot. */
|
||||
#define __furi_crash(message) \
|
||||
|
||||
@@ -5,6 +5,10 @@
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#define FURI_NORETURN [[noreturn]]
|
||||
#else
|
||||
#include <stdnoreturn.h>
|
||||
#define FURI_NORETURN noreturn
|
||||
#endif
|
||||
|
||||
#include <cmsis_compiler.h>
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
#define FURI_EVENT_FLAG_MAX_BITS_EVENT_GROUPS 24U
|
||||
#define FURI_EVENT_FLAG_INVALID_BITS (~((1UL << FURI_EVENT_FLAG_MAX_BITS_EVENT_GROUPS) - 1U))
|
||||
|
||||
FuriEventFlag* furi_event_flag_alloc() {
|
||||
furi_assert(!FURI_IS_IRQ_MODE());
|
||||
FuriEventFlag* furi_event_flag_alloc(void) {
|
||||
furi_check(!FURI_IS_IRQ_MODE());
|
||||
|
||||
EventGroupHandle_t handle = xEventGroupCreate();
|
||||
furi_check(handle);
|
||||
@@ -18,13 +18,13 @@ FuriEventFlag* furi_event_flag_alloc() {
|
||||
}
|
||||
|
||||
void furi_event_flag_free(FuriEventFlag* instance) {
|
||||
furi_assert(!FURI_IS_IRQ_MODE());
|
||||
furi_check(!FURI_IS_IRQ_MODE());
|
||||
vEventGroupDelete((EventGroupHandle_t)instance);
|
||||
}
|
||||
|
||||
uint32_t furi_event_flag_set(FuriEventFlag* instance, uint32_t flags) {
|
||||
furi_assert(instance);
|
||||
furi_assert((flags & FURI_EVENT_FLAG_INVALID_BITS) == 0U);
|
||||
furi_check(instance);
|
||||
furi_check((flags & FURI_EVENT_FLAG_INVALID_BITS) == 0U);
|
||||
|
||||
EventGroupHandle_t hEventGroup = (EventGroupHandle_t)instance;
|
||||
uint32_t rflags;
|
||||
@@ -47,8 +47,8 @@ uint32_t furi_event_flag_set(FuriEventFlag* instance, uint32_t flags) {
|
||||
}
|
||||
|
||||
uint32_t furi_event_flag_clear(FuriEventFlag* instance, uint32_t flags) {
|
||||
furi_assert(instance);
|
||||
furi_assert((flags & FURI_EVENT_FLAG_INVALID_BITS) == 0U);
|
||||
furi_check(instance);
|
||||
furi_check((flags & FURI_EVENT_FLAG_INVALID_BITS) == 0U);
|
||||
|
||||
EventGroupHandle_t hEventGroup = (EventGroupHandle_t)instance;
|
||||
uint32_t rflags;
|
||||
@@ -73,7 +73,7 @@ uint32_t furi_event_flag_clear(FuriEventFlag* instance, uint32_t flags) {
|
||||
}
|
||||
|
||||
uint32_t furi_event_flag_get(FuriEventFlag* instance) {
|
||||
furi_assert(instance);
|
||||
furi_check(instance);
|
||||
|
||||
EventGroupHandle_t hEventGroup = (EventGroupHandle_t)instance;
|
||||
uint32_t rflags;
|
||||
@@ -93,9 +93,9 @@ uint32_t furi_event_flag_wait(
|
||||
uint32_t flags,
|
||||
uint32_t options,
|
||||
uint32_t timeout) {
|
||||
furi_assert(!FURI_IS_IRQ_MODE());
|
||||
furi_assert(instance);
|
||||
furi_assert((flags & FURI_EVENT_FLAG_INVALID_BITS) == 0U);
|
||||
furi_check(!FURI_IS_IRQ_MODE());
|
||||
furi_check(instance);
|
||||
furi_check((flags & FURI_EVENT_FLAG_INVALID_BITS) == 0U);
|
||||
|
||||
EventGroupHandle_t hEventGroup = (EventGroupHandle_t)instance;
|
||||
BaseType_t wait_all;
|
||||
|
||||
@@ -16,7 +16,7 @@ typedef void FuriEventFlag;
|
||||
*
|
||||
* @return pointer to FuriEventFlag
|
||||
*/
|
||||
FuriEventFlag* furi_event_flag_alloc();
|
||||
FuriEventFlag* furi_event_flag_alloc(void);
|
||||
|
||||
/** Deallocate FuriEventFlag
|
||||
*
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
#include CMSIS_device_header
|
||||
|
||||
bool furi_kernel_is_irq_or_masked() {
|
||||
bool furi_kernel_is_irq_or_masked(void) {
|
||||
bool irq = false;
|
||||
BaseType_t state;
|
||||
|
||||
@@ -34,12 +34,12 @@ bool furi_kernel_is_irq_or_masked() {
|
||||
return (irq);
|
||||
}
|
||||
|
||||
bool furi_kernel_is_running() {
|
||||
bool furi_kernel_is_running(void) {
|
||||
return xTaskGetSchedulerState() != taskSCHEDULER_RUNNING;
|
||||
}
|
||||
|
||||
int32_t furi_kernel_lock() {
|
||||
furi_assert(!furi_kernel_is_irq_or_masked());
|
||||
int32_t furi_kernel_lock(void) {
|
||||
furi_check(!furi_kernel_is_irq_or_masked());
|
||||
|
||||
int32_t lock;
|
||||
|
||||
@@ -63,8 +63,8 @@ int32_t furi_kernel_lock() {
|
||||
return (lock);
|
||||
}
|
||||
|
||||
int32_t furi_kernel_unlock() {
|
||||
furi_assert(!furi_kernel_is_irq_or_masked());
|
||||
int32_t furi_kernel_unlock(void) {
|
||||
furi_check(!furi_kernel_is_irq_or_masked());
|
||||
|
||||
int32_t lock;
|
||||
|
||||
@@ -94,7 +94,7 @@ int32_t furi_kernel_unlock() {
|
||||
}
|
||||
|
||||
int32_t furi_kernel_restore_lock(int32_t lock) {
|
||||
furi_assert(!furi_kernel_is_irq_or_masked());
|
||||
furi_check(!furi_kernel_is_irq_or_masked());
|
||||
|
||||
switch(xTaskGetSchedulerState()) {
|
||||
case taskSCHEDULER_SUSPENDED:
|
||||
@@ -124,13 +124,13 @@ int32_t furi_kernel_restore_lock(int32_t lock) {
|
||||
return (lock);
|
||||
}
|
||||
|
||||
uint32_t furi_kernel_get_tick_frequency() {
|
||||
uint32_t furi_kernel_get_tick_frequency(void) {
|
||||
/* Return frequency in hertz */
|
||||
return (configTICK_RATE_HZ_RAW);
|
||||
}
|
||||
|
||||
void furi_delay_tick(uint32_t ticks) {
|
||||
furi_assert(!furi_kernel_is_irq_or_masked());
|
||||
furi_check(!furi_kernel_is_irq_or_masked());
|
||||
if(ticks == 0U) {
|
||||
taskYIELD();
|
||||
} else {
|
||||
@@ -139,7 +139,7 @@ void furi_delay_tick(uint32_t ticks) {
|
||||
}
|
||||
|
||||
FuriStatus furi_delay_until_tick(uint32_t tick) {
|
||||
furi_assert(!furi_kernel_is_irq_or_masked());
|
||||
furi_check(!furi_kernel_is_irq_or_masked());
|
||||
|
||||
TickType_t tcnt, delay;
|
||||
FuriStatus stat;
|
||||
@@ -165,7 +165,7 @@ FuriStatus furi_delay_until_tick(uint32_t tick) {
|
||||
return (stat);
|
||||
}
|
||||
|
||||
uint32_t furi_get_tick() {
|
||||
uint32_t furi_get_tick(void) {
|
||||
TickType_t ticks;
|
||||
|
||||
if(furi_kernel_is_irq_or_masked() != 0U) {
|
||||
|
||||
@@ -25,13 +25,13 @@ extern "C" {
|
||||
*
|
||||
* @return true if CPU is in IRQ or kernel running and IRQ is masked
|
||||
*/
|
||||
bool furi_kernel_is_irq_or_masked();
|
||||
bool furi_kernel_is_irq_or_masked(void);
|
||||
|
||||
/** Check if kernel is running
|
||||
*
|
||||
* @return true if running, false otherwise
|
||||
*/
|
||||
bool furi_kernel_is_running();
|
||||
bool furi_kernel_is_running(void);
|
||||
|
||||
/** Lock kernel, pause process scheduling
|
||||
*
|
||||
@@ -39,7 +39,7 @@ bool furi_kernel_is_running();
|
||||
*
|
||||
* @return previous lock state(0 - unlocked, 1 - locked)
|
||||
*/
|
||||
int32_t furi_kernel_lock();
|
||||
int32_t furi_kernel_lock(void);
|
||||
|
||||
/** Unlock kernel, resume process scheduling
|
||||
*
|
||||
@@ -47,7 +47,7 @@ int32_t furi_kernel_lock();
|
||||
*
|
||||
* @return previous lock state(0 - unlocked, 1 - locked)
|
||||
*/
|
||||
int32_t furi_kernel_unlock();
|
||||
int32_t furi_kernel_unlock(void);
|
||||
|
||||
/** Restore kernel lock state
|
||||
*
|
||||
@@ -63,7 +63,7 @@ int32_t furi_kernel_restore_lock(int32_t lock);
|
||||
*
|
||||
* @return systick counts per second
|
||||
*/
|
||||
uint32_t furi_kernel_get_tick_frequency();
|
||||
uint32_t furi_kernel_get_tick_frequency(void);
|
||||
|
||||
/** Delay execution
|
||||
*
|
||||
|
||||
@@ -31,7 +31,7 @@ static const FuriLogLevelDescription FURI_LOG_LEVEL_DESCRIPTIONS[] = {
|
||||
{"trace", FuriLogLevelTrace},
|
||||
};
|
||||
|
||||
void furi_log_init() {
|
||||
void furi_log_init(void) {
|
||||
// Set default logging parameters
|
||||
furi_log.log_level = FURI_LOG_LEVEL_DEFAULT;
|
||||
furi_log.mutex = furi_mutex_alloc(FuriMutexTypeRecursive);
|
||||
@@ -178,6 +178,8 @@ void furi_log_print_raw_format(FuriLogLevel level, const char* format, ...) {
|
||||
}
|
||||
|
||||
void furi_log_set_level(FuriLogLevel level) {
|
||||
furi_check(level <= FuriLogLevelTrace);
|
||||
|
||||
if(level == FuriLogLevelDefault) {
|
||||
level = FURI_LOG_LEVEL_DEFAULT;
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@ static MemmgrHeapThreadDict_t memmgr_heap_thread_dict = {0};
|
||||
static volatile uint32_t memmgr_heap_thread_trace_depth = 0;
|
||||
|
||||
/* Initialize tracing storage on start */
|
||||
void memmgr_heap_init() {
|
||||
void memmgr_heap_init(void) {
|
||||
MemmgrHeapThreadDict_init(memmgr_heap_thread_dict);
|
||||
}
|
||||
|
||||
@@ -224,7 +224,7 @@ static inline void traceFREE(void* pointer, size_t size) {
|
||||
}
|
||||
}
|
||||
|
||||
size_t memmgr_heap_get_max_free_block() {
|
||||
size_t memmgr_heap_get_max_free_block(void) {
|
||||
size_t max_free_size = 0;
|
||||
BlockLink_t* pxBlock;
|
||||
vTaskSuspendAll();
|
||||
@@ -241,7 +241,7 @@ size_t memmgr_heap_get_max_free_block() {
|
||||
return max_free_size;
|
||||
}
|
||||
|
||||
void memmgr_heap_printf_free_blocks() {
|
||||
void memmgr_heap_printf_free_blocks(void) {
|
||||
BlockLink_t* pxBlock;
|
||||
//TODO enable when we can do printf with a locked scheduler
|
||||
//vTaskSuspendAll();
|
||||
@@ -283,7 +283,7 @@ char* ultoa(unsigned long num, char* str, int radix) {
|
||||
return str;
|
||||
}
|
||||
|
||||
static void print_heap_init() {
|
||||
static void print_heap_init(void) {
|
||||
char tmp_str[33];
|
||||
size_t heap_start = (size_t)&__heap_start__;
|
||||
size_t heap_end = (size_t)&__heap_end__;
|
||||
|
||||
@@ -38,11 +38,11 @@ size_t memmgr_heap_get_thread_memory(FuriThreadId thread_id);
|
||||
*
|
||||
* @return size_t max contiguous block size
|
||||
*/
|
||||
size_t memmgr_heap_get_max_free_block();
|
||||
size_t memmgr_heap_get_max_free_block(void);
|
||||
|
||||
/** Print the address and size of all free blocks to stdout
|
||||
*/
|
||||
void memmgr_heap_printf_free_blocks();
|
||||
void memmgr_heap_printf_free_blocks(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include <queue.h>
|
||||
|
||||
FuriMessageQueue* furi_message_queue_alloc(uint32_t msg_count, uint32_t msg_size) {
|
||||
furi_assert((furi_kernel_is_irq_or_masked() == 0U) && (msg_count > 0U) && (msg_size > 0U));
|
||||
furi_check((furi_kernel_is_irq_or_masked() == 0U) && (msg_count > 0U) && (msg_size > 0U));
|
||||
|
||||
QueueHandle_t handle = xQueueCreate(msg_count, msg_size);
|
||||
furi_check(handle);
|
||||
@@ -15,14 +15,16 @@ FuriMessageQueue* furi_message_queue_alloc(uint32_t msg_count, uint32_t msg_size
|
||||
}
|
||||
|
||||
void furi_message_queue_free(FuriMessageQueue* instance) {
|
||||
furi_assert(furi_kernel_is_irq_or_masked() == 0U);
|
||||
furi_assert(instance);
|
||||
furi_check(furi_kernel_is_irq_or_masked() == 0U);
|
||||
furi_check(instance);
|
||||
|
||||
vQueueDelete((QueueHandle_t)instance);
|
||||
}
|
||||
|
||||
FuriStatus
|
||||
furi_message_queue_put(FuriMessageQueue* instance, const void* msg_ptr, uint32_t timeout) {
|
||||
furi_check(instance);
|
||||
|
||||
QueueHandle_t hQueue = (QueueHandle_t)instance;
|
||||
FuriStatus stat;
|
||||
BaseType_t yield;
|
||||
@@ -30,7 +32,7 @@ FuriStatus
|
||||
stat = FuriStatusOk;
|
||||
|
||||
if(furi_kernel_is_irq_or_masked() != 0U) {
|
||||
if((hQueue == NULL) || (msg_ptr == NULL) || (timeout != 0U)) {
|
||||
if((msg_ptr == NULL) || (timeout != 0U)) {
|
||||
stat = FuriStatusErrorParameter;
|
||||
} else {
|
||||
yield = pdFALSE;
|
||||
@@ -42,7 +44,7 @@ FuriStatus
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if((hQueue == NULL) || (msg_ptr == NULL)) {
|
||||
if(msg_ptr == NULL) {
|
||||
stat = FuriStatusErrorParameter;
|
||||
} else {
|
||||
if(xQueueSendToBack(hQueue, msg_ptr, (TickType_t)timeout) != pdPASS) {
|
||||
@@ -60,6 +62,8 @@ FuriStatus
|
||||
}
|
||||
|
||||
FuriStatus furi_message_queue_get(FuriMessageQueue* instance, void* msg_ptr, uint32_t timeout) {
|
||||
furi_check(instance);
|
||||
|
||||
QueueHandle_t hQueue = (QueueHandle_t)instance;
|
||||
FuriStatus stat;
|
||||
BaseType_t yield;
|
||||
@@ -67,7 +71,7 @@ FuriStatus furi_message_queue_get(FuriMessageQueue* instance, void* msg_ptr, uin
|
||||
stat = FuriStatusOk;
|
||||
|
||||
if(furi_kernel_is_irq_or_masked() != 0U) {
|
||||
if((hQueue == NULL) || (msg_ptr == NULL) || (timeout != 0U)) {
|
||||
if((msg_ptr == NULL) || (timeout != 0U)) {
|
||||
stat = FuriStatusErrorParameter;
|
||||
} else {
|
||||
yield = pdFALSE;
|
||||
@@ -79,7 +83,7 @@ FuriStatus furi_message_queue_get(FuriMessageQueue* instance, void* msg_ptr, uin
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if((hQueue == NULL) || (msg_ptr == NULL)) {
|
||||
if(msg_ptr == NULL) {
|
||||
stat = FuriStatusErrorParameter;
|
||||
} else {
|
||||
if(xQueueReceive(hQueue, msg_ptr, (TickType_t)timeout) != pdPASS) {
|
||||
@@ -92,47 +96,42 @@ FuriStatus furi_message_queue_get(FuriMessageQueue* instance, void* msg_ptr, uin
|
||||
}
|
||||
}
|
||||
|
||||
/* Return execution status */
|
||||
return (stat);
|
||||
}
|
||||
|
||||
uint32_t furi_message_queue_get_capacity(FuriMessageQueue* instance) {
|
||||
furi_check(instance);
|
||||
|
||||
StaticQueue_t* mq = (StaticQueue_t*)instance;
|
||||
uint32_t capacity;
|
||||
|
||||
if(mq == NULL) {
|
||||
capacity = 0U;
|
||||
} else {
|
||||
/* capacity = pxQueue->uxLength */
|
||||
capacity = mq->uxDummy4[1];
|
||||
}
|
||||
/* capacity = pxQueue->uxLength */
|
||||
capacity = mq->uxDummy4[1];
|
||||
|
||||
/* Return maximum number of messages */
|
||||
return (capacity);
|
||||
}
|
||||
|
||||
uint32_t furi_message_queue_get_message_size(FuriMessageQueue* instance) {
|
||||
furi_check(instance);
|
||||
|
||||
StaticQueue_t* mq = (StaticQueue_t*)instance;
|
||||
uint32_t size;
|
||||
|
||||
if(mq == NULL) {
|
||||
size = 0U;
|
||||
} else {
|
||||
/* size = pxQueue->uxItemSize */
|
||||
size = mq->uxDummy4[2];
|
||||
}
|
||||
/* size = pxQueue->uxItemSize */
|
||||
size = mq->uxDummy4[2];
|
||||
|
||||
/* Return maximum message size */
|
||||
return (size);
|
||||
}
|
||||
|
||||
uint32_t furi_message_queue_get_count(FuriMessageQueue* instance) {
|
||||
furi_check(instance);
|
||||
|
||||
QueueHandle_t hQueue = (QueueHandle_t)instance;
|
||||
UBaseType_t count;
|
||||
|
||||
if(hQueue == NULL) {
|
||||
count = 0U;
|
||||
} else if(furi_kernel_is_irq_or_masked() != 0U) {
|
||||
if(furi_kernel_is_irq_or_masked() != 0U) {
|
||||
count = uxQueueMessagesWaitingFromISR(hQueue);
|
||||
} else {
|
||||
count = uxQueueMessagesWaiting(hQueue);
|
||||
@@ -143,13 +142,13 @@ uint32_t furi_message_queue_get_count(FuriMessageQueue* instance) {
|
||||
}
|
||||
|
||||
uint32_t furi_message_queue_get_space(FuriMessageQueue* instance) {
|
||||
furi_check(instance);
|
||||
|
||||
StaticQueue_t* mq = (StaticQueue_t*)instance;
|
||||
uint32_t space;
|
||||
uint32_t isrm;
|
||||
|
||||
if(mq == NULL) {
|
||||
space = 0U;
|
||||
} else if(furi_kernel_is_irq_or_masked() != 0U) {
|
||||
if(furi_kernel_is_irq_or_masked() != 0U) {
|
||||
isrm = taskENTER_CRITICAL_FROM_ISR();
|
||||
|
||||
/* space = pxQueue->uxLength - pxQueue->uxMessagesWaiting; */
|
||||
@@ -165,13 +164,13 @@ uint32_t furi_message_queue_get_space(FuriMessageQueue* instance) {
|
||||
}
|
||||
|
||||
FuriStatus furi_message_queue_reset(FuriMessageQueue* instance) {
|
||||
furi_check(instance);
|
||||
|
||||
QueueHandle_t hQueue = (QueueHandle_t)instance;
|
||||
FuriStatus stat;
|
||||
|
||||
if(furi_kernel_is_irq_or_masked() != 0U) {
|
||||
stat = FuriStatusErrorISR;
|
||||
} else if(hQueue == NULL) {
|
||||
stat = FuriStatusErrorParameter;
|
||||
} else {
|
||||
stat = FuriStatusOk;
|
||||
(void)xQueueReset(hQueue);
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include <semphr.h>
|
||||
|
||||
FuriMutex* furi_mutex_alloc(FuriMutexType type) {
|
||||
furi_assert(!FURI_IS_IRQ_MODE());
|
||||
furi_check(!FURI_IS_IRQ_MODE());
|
||||
|
||||
SemaphoreHandle_t hMutex = NULL;
|
||||
|
||||
@@ -15,7 +15,7 @@ FuriMutex* furi_mutex_alloc(FuriMutexType type) {
|
||||
} else if(type == FuriMutexTypeRecursive) {
|
||||
hMutex = xSemaphoreCreateRecursiveMutex();
|
||||
} else {
|
||||
furi_crash("Programming error");
|
||||
furi_crash();
|
||||
}
|
||||
|
||||
furi_check(hMutex != NULL);
|
||||
@@ -30,13 +30,15 @@ FuriMutex* furi_mutex_alloc(FuriMutexType type) {
|
||||
}
|
||||
|
||||
void furi_mutex_free(FuriMutex* instance) {
|
||||
furi_assert(!FURI_IS_IRQ_MODE());
|
||||
furi_assert(instance);
|
||||
furi_check(!FURI_IS_IRQ_MODE());
|
||||
furi_check(instance);
|
||||
|
||||
vSemaphoreDelete((SemaphoreHandle_t)((uint32_t)instance & ~1U));
|
||||
}
|
||||
|
||||
FuriStatus furi_mutex_acquire(FuriMutex* instance, uint32_t timeout) {
|
||||
furi_check(instance);
|
||||
|
||||
SemaphoreHandle_t hMutex;
|
||||
FuriStatus stat;
|
||||
uint32_t rmtx;
|
||||
@@ -77,6 +79,8 @@ FuriStatus furi_mutex_acquire(FuriMutex* instance, uint32_t timeout) {
|
||||
}
|
||||
|
||||
FuriStatus furi_mutex_release(FuriMutex* instance) {
|
||||
furi_check(instance);
|
||||
|
||||
SemaphoreHandle_t hMutex;
|
||||
FuriStatus stat;
|
||||
uint32_t rmtx;
|
||||
@@ -109,6 +113,8 @@ FuriStatus furi_mutex_release(FuriMutex* instance) {
|
||||
}
|
||||
|
||||
FuriThreadId furi_mutex_get_owner(FuriMutex* instance) {
|
||||
furi_check(instance);
|
||||
|
||||
SemaphoreHandle_t hMutex;
|
||||
FuriThreadId owner;
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ struct FuriPubSub {
|
||||
FuriMutex* mutex;
|
||||
};
|
||||
|
||||
FuriPubSub* furi_pubsub_alloc() {
|
||||
FuriPubSub* furi_pubsub_alloc(void) {
|
||||
FuriPubSub* pubsub = malloc(sizeof(FuriPubSub));
|
||||
|
||||
pubsub->mutex = furi_mutex_alloc(FuriMutexTypeNormal);
|
||||
@@ -42,6 +42,9 @@ void furi_pubsub_free(FuriPubSub* pubsub) {
|
||||
|
||||
FuriPubSubSubscription*
|
||||
furi_pubsub_subscribe(FuriPubSub* pubsub, FuriPubSubCallback callback, void* callback_context) {
|
||||
furi_check(pubsub);
|
||||
furi_check(callback);
|
||||
|
||||
furi_check(furi_mutex_acquire(pubsub->mutex, FuriWaitForever) == FuriStatusOk);
|
||||
// put uninitialized item to the list
|
||||
FuriPubSubSubscription* item = FuriPubSubSubscriptionList_push_raw(pubsub->items);
|
||||
@@ -81,6 +84,8 @@ void furi_pubsub_unsubscribe(FuriPubSub* pubsub, FuriPubSubSubscription* pubsub_
|
||||
}
|
||||
|
||||
void furi_pubsub_publish(FuriPubSub* pubsub, void* message) {
|
||||
furi_check(pubsub);
|
||||
|
||||
furi_check(furi_mutex_acquire(pubsub->mutex, FuriWaitForever) == FuriStatusOk);
|
||||
|
||||
// iterate over subscribers
|
||||
|
||||
@@ -23,7 +23,7 @@ typedef struct FuriPubSubSubscription FuriPubSubSubscription;
|
||||
*
|
||||
* @return pointer to FuriPubSub instance
|
||||
*/
|
||||
FuriPubSub* furi_pubsub_alloc();
|
||||
FuriPubSub* furi_pubsub_alloc(void);
|
||||
|
||||
/** Free FuriPubSub
|
||||
*
|
||||
|
||||
@@ -37,7 +37,7 @@ static void furi_record_erase(const char* name, FuriRecordData* record_data) {
|
||||
FuriRecordDataDict_erase(furi_record->records, name);
|
||||
}
|
||||
|
||||
void furi_record_init() {
|
||||
void furi_record_init(void) {
|
||||
furi_record = malloc(sizeof(FuriRecord));
|
||||
furi_record->mutex = furi_mutex_alloc(FuriMutexTypeNormal);
|
||||
furi_check(furi_record->mutex);
|
||||
@@ -45,7 +45,7 @@ void furi_record_init() {
|
||||
}
|
||||
|
||||
static FuriRecordData* furi_record_data_get_or_create(const char* name) {
|
||||
furi_assert(furi_record);
|
||||
furi_check(furi_record);
|
||||
FuriRecordData* record_data = furi_record_get(name);
|
||||
if(!record_data) {
|
||||
FuriRecordData new_record;
|
||||
@@ -58,17 +58,17 @@ static FuriRecordData* furi_record_data_get_or_create(const char* name) {
|
||||
return record_data;
|
||||
}
|
||||
|
||||
static void furi_record_lock() {
|
||||
static void furi_record_lock(void) {
|
||||
furi_check(furi_mutex_acquire(furi_record->mutex, FuriWaitForever) == FuriStatusOk);
|
||||
}
|
||||
|
||||
static void furi_record_unlock() {
|
||||
static void furi_record_unlock(void) {
|
||||
furi_check(furi_mutex_release(furi_record->mutex) == FuriStatusOk);
|
||||
}
|
||||
|
||||
bool furi_record_exists(const char* name) {
|
||||
furi_assert(furi_record);
|
||||
furi_assert(name);
|
||||
furi_check(furi_record);
|
||||
furi_check(name);
|
||||
|
||||
bool ret = false;
|
||||
|
||||
@@ -80,13 +80,14 @@ bool furi_record_exists(const char* name) {
|
||||
}
|
||||
|
||||
void furi_record_create(const char* name, void* data) {
|
||||
furi_assert(furi_record);
|
||||
furi_check(furi_record);
|
||||
furi_check(name);
|
||||
|
||||
furi_record_lock();
|
||||
|
||||
// Get record data and fill it
|
||||
FuriRecordData* record_data = furi_record_data_get_or_create(name);
|
||||
furi_assert(record_data->data == NULL);
|
||||
furi_check(record_data->data == NULL);
|
||||
record_data->data = data;
|
||||
furi_event_flag_set(record_data->flags, FURI_RECORD_FLAG_READY);
|
||||
|
||||
@@ -94,14 +95,15 @@ void furi_record_create(const char* name, void* data) {
|
||||
}
|
||||
|
||||
bool furi_record_destroy(const char* name) {
|
||||
furi_assert(furi_record);
|
||||
furi_check(furi_record);
|
||||
furi_check(name);
|
||||
|
||||
bool ret = false;
|
||||
|
||||
furi_record_lock();
|
||||
|
||||
FuriRecordData* record_data = furi_record_get(name);
|
||||
furi_assert(record_data);
|
||||
furi_check(record_data);
|
||||
if(record_data->holders_count == 0) {
|
||||
furi_record_erase(name, record_data);
|
||||
ret = true;
|
||||
@@ -113,7 +115,8 @@ bool furi_record_destroy(const char* name) {
|
||||
}
|
||||
|
||||
void* furi_record_open(const char* name) {
|
||||
furi_assert(furi_record);
|
||||
furi_check(furi_record);
|
||||
furi_check(name);
|
||||
|
||||
furi_record_lock();
|
||||
|
||||
@@ -134,12 +137,13 @@ void* furi_record_open(const char* name) {
|
||||
}
|
||||
|
||||
void furi_record_close(const char* name) {
|
||||
furi_assert(furi_record);
|
||||
furi_check(furi_record);
|
||||
furi_check(name);
|
||||
|
||||
furi_record_lock();
|
||||
|
||||
FuriRecordData* record_data = furi_record_get(name);
|
||||
furi_assert(record_data);
|
||||
furi_check(record_data);
|
||||
record_data->holders_count--;
|
||||
|
||||
furi_record_unlock();
|
||||
|
||||
@@ -14,7 +14,7 @@ extern "C" {
|
||||
|
||||
/** Initialize record storage For internal use only.
|
||||
*/
|
||||
void furi_record_init();
|
||||
void furi_record_init(void);
|
||||
|
||||
/** Check if record exists
|
||||
*
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
#include <semphr.h>
|
||||
|
||||
FuriSemaphore* furi_semaphore_alloc(uint32_t max_count, uint32_t initial_count) {
|
||||
furi_assert(!FURI_IS_IRQ_MODE());
|
||||
furi_assert((max_count > 0U) && (initial_count <= max_count));
|
||||
furi_check(!FURI_IS_IRQ_MODE());
|
||||
furi_check((max_count > 0U) && (initial_count <= max_count));
|
||||
|
||||
SemaphoreHandle_t hSemaphore = NULL;
|
||||
if(max_count == 1U) {
|
||||
@@ -29,8 +29,8 @@ FuriSemaphore* furi_semaphore_alloc(uint32_t max_count, uint32_t initial_count)
|
||||
}
|
||||
|
||||
void furi_semaphore_free(FuriSemaphore* instance) {
|
||||
furi_assert(instance);
|
||||
furi_assert(!FURI_IS_IRQ_MODE());
|
||||
furi_check(instance);
|
||||
furi_check(!FURI_IS_IRQ_MODE());
|
||||
|
||||
SemaphoreHandle_t hSemaphore = (SemaphoreHandle_t)instance;
|
||||
|
||||
@@ -38,7 +38,7 @@ void furi_semaphore_free(FuriSemaphore* instance) {
|
||||
}
|
||||
|
||||
FuriStatus furi_semaphore_acquire(FuriSemaphore* instance, uint32_t timeout) {
|
||||
furi_assert(instance);
|
||||
furi_check(instance);
|
||||
|
||||
SemaphoreHandle_t hSemaphore = (SemaphoreHandle_t)instance;
|
||||
FuriStatus stat;
|
||||
@@ -73,7 +73,7 @@ FuriStatus furi_semaphore_acquire(FuriSemaphore* instance, uint32_t timeout) {
|
||||
}
|
||||
|
||||
FuriStatus furi_semaphore_release(FuriSemaphore* instance) {
|
||||
furi_assert(instance);
|
||||
furi_check(instance);
|
||||
|
||||
SemaphoreHandle_t hSemaphore = (SemaphoreHandle_t)instance;
|
||||
FuriStatus stat;
|
||||
@@ -100,7 +100,7 @@ FuriStatus furi_semaphore_release(FuriSemaphore* instance) {
|
||||
}
|
||||
|
||||
uint32_t furi_semaphore_get_count(FuriSemaphore* instance) {
|
||||
furi_assert(instance);
|
||||
furi_check(instance);
|
||||
|
||||
SemaphoreHandle_t hSemaphore = (SemaphoreHandle_t)instance;
|
||||
uint32_t count;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <FreeRTOS-Kernel/include/stream_buffer.h>
|
||||
|
||||
FuriStreamBuffer* furi_stream_buffer_alloc(size_t size, size_t trigger_level) {
|
||||
furi_assert(size != 0);
|
||||
furi_check(size != 0);
|
||||
|
||||
StreamBufferHandle_t handle = xStreamBufferCreate(size, trigger_level);
|
||||
furi_check(handle);
|
||||
@@ -16,12 +16,13 @@ FuriStreamBuffer* furi_stream_buffer_alloc(size_t size, size_t trigger_level) {
|
||||
};
|
||||
|
||||
void furi_stream_buffer_free(FuriStreamBuffer* stream_buffer) {
|
||||
furi_assert(stream_buffer);
|
||||
furi_check(stream_buffer);
|
||||
|
||||
vStreamBufferDelete(stream_buffer);
|
||||
};
|
||||
|
||||
bool furi_stream_set_trigger_level(FuriStreamBuffer* stream_buffer, size_t trigger_level) {
|
||||
furi_assert(stream_buffer);
|
||||
furi_check(stream_buffer);
|
||||
return xStreamBufferSetTriggerLevel(stream_buffer, trigger_level) == pdTRUE;
|
||||
};
|
||||
|
||||
@@ -30,6 +31,8 @@ size_t furi_stream_buffer_send(
|
||||
const void* data,
|
||||
size_t length,
|
||||
uint32_t timeout) {
|
||||
furi_check(stream_buffer);
|
||||
|
||||
size_t ret;
|
||||
|
||||
if(FURI_IS_IRQ_MODE()) {
|
||||
@@ -48,6 +51,8 @@ size_t furi_stream_buffer_receive(
|
||||
void* data,
|
||||
size_t length,
|
||||
uint32_t timeout) {
|
||||
furi_check(stream_buffer);
|
||||
|
||||
size_t ret;
|
||||
|
||||
if(FURI_IS_IRQ_MODE()) {
|
||||
@@ -62,22 +67,32 @@ size_t furi_stream_buffer_receive(
|
||||
}
|
||||
|
||||
size_t furi_stream_buffer_bytes_available(FuriStreamBuffer* stream_buffer) {
|
||||
furi_check(stream_buffer);
|
||||
|
||||
return xStreamBufferBytesAvailable(stream_buffer);
|
||||
};
|
||||
|
||||
size_t furi_stream_buffer_spaces_available(FuriStreamBuffer* stream_buffer) {
|
||||
furi_check(stream_buffer);
|
||||
|
||||
return xStreamBufferSpacesAvailable(stream_buffer);
|
||||
};
|
||||
|
||||
bool furi_stream_buffer_is_full(FuriStreamBuffer* stream_buffer) {
|
||||
furi_check(stream_buffer);
|
||||
|
||||
return xStreamBufferIsFull(stream_buffer) == pdTRUE;
|
||||
};
|
||||
|
||||
bool furi_stream_buffer_is_empty(FuriStreamBuffer* stream_buffer) {
|
||||
furi_check(stream_buffer);
|
||||
|
||||
return (xStreamBufferIsEmpty(stream_buffer) == pdTRUE);
|
||||
};
|
||||
|
||||
FuriStatus furi_stream_buffer_reset(FuriStreamBuffer* stream_buffer) {
|
||||
furi_check(stream_buffer);
|
||||
|
||||
if(xStreamBufferReset(stream_buffer) == pdPASS) {
|
||||
return FuriStatusOk;
|
||||
} else {
|
||||
|
||||
@@ -22,7 +22,7 @@ struct FuriString {
|
||||
#undef furi_string_trim
|
||||
#undef furi_string_cat
|
||||
|
||||
FuriString* furi_string_alloc() {
|
||||
FuriString* furi_string_alloc(void) {
|
||||
FuriString* string = malloc(sizeof(FuriString));
|
||||
string_init(string->string);
|
||||
return string;
|
||||
|
||||
@@ -32,7 +32,7 @@ typedef struct FuriString FuriString;
|
||||
* @brief Allocate new FuriString.
|
||||
* @return FuriString*
|
||||
*/
|
||||
FuriString* furi_string_alloc();
|
||||
FuriString* furi_string_alloc(void);
|
||||
|
||||
/**
|
||||
* @brief Allocate new FuriString and set it to string.
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
#include "memmgr_heap.h"
|
||||
#include "check.h"
|
||||
#include "common_defines.h"
|
||||
#include "mutex.h"
|
||||
#include "string.h"
|
||||
|
||||
#include "log.h"
|
||||
@@ -57,7 +56,7 @@ static size_t __furi_thread_stdout_write(FuriThread* thread, const char* data, s
|
||||
static int32_t __furi_thread_stdout_flush(FuriThread* thread);
|
||||
|
||||
/** Catch threads that are trying to exit wrong way */
|
||||
__attribute__((__noreturn__)) void furi_thread_catch() { //-V1082
|
||||
__attribute__((__noreturn__)) void furi_thread_catch(void) { //-V1082
|
||||
// If you're here it means you're probably doing something wrong
|
||||
// with critical sections or with scheduler state
|
||||
asm volatile("nop"); // extra magic
|
||||
@@ -74,14 +73,14 @@ static void furi_thread_set_state(FuriThread* thread, FuriThreadState state) {
|
||||
}
|
||||
|
||||
static void furi_thread_body(void* context) {
|
||||
furi_assert(context);
|
||||
furi_check(context);
|
||||
FuriThread* thread = context;
|
||||
|
||||
// store thread instance to thread local storage
|
||||
furi_assert(pvTaskGetThreadLocalStoragePointer(NULL, 0) == NULL);
|
||||
furi_check(pvTaskGetThreadLocalStoragePointer(NULL, 0) == NULL);
|
||||
vTaskSetThreadLocalStoragePointer(NULL, 0, thread);
|
||||
|
||||
furi_assert(thread->state == FuriThreadStateStarting);
|
||||
furi_check(thread->state == FuriThreadStateStarting);
|
||||
furi_thread_set_state(thread, FuriThreadStateRunning);
|
||||
|
||||
TaskHandle_t task_handle = xTaskGetCurrentTaskHandle();
|
||||
@@ -103,7 +102,7 @@ static void furi_thread_body(void* context) {
|
||||
memmgr_heap_disable_thread_trace((FuriThreadId)task_handle);
|
||||
}
|
||||
|
||||
furi_assert(thread->state == FuriThreadStateRunning);
|
||||
furi_check(thread->state == FuriThreadStateRunning);
|
||||
|
||||
if(thread->is_service) {
|
||||
FURI_LOG_W(
|
||||
@@ -121,7 +120,7 @@ static void furi_thread_body(void* context) {
|
||||
furi_thread_catch();
|
||||
}
|
||||
|
||||
FuriThread* furi_thread_alloc() {
|
||||
FuriThread* furi_thread_alloc(void) {
|
||||
FuriThread* thread = malloc(sizeof(FuriThread));
|
||||
thread->output.buffer = furi_string_alloc();
|
||||
thread->is_service = false;
|
||||
@@ -167,11 +166,11 @@ FuriThread* furi_thread_alloc_ex(
|
||||
}
|
||||
|
||||
void furi_thread_free(FuriThread* thread) {
|
||||
furi_assert(thread);
|
||||
furi_check(thread);
|
||||
|
||||
// Ensure that use join before free
|
||||
furi_assert(thread->state == FuriThreadStateStopped);
|
||||
furi_assert(thread->task_handle == NULL);
|
||||
furi_check(thread->state == FuriThreadStateStopped);
|
||||
furi_check(thread->task_handle == NULL);
|
||||
|
||||
if(thread->name) free(thread->name);
|
||||
if(thread->appid) free(thread->appid);
|
||||
@@ -181,15 +180,17 @@ void furi_thread_free(FuriThread* thread) {
|
||||
}
|
||||
|
||||
void furi_thread_set_name(FuriThread* thread, const char* name) {
|
||||
furi_assert(thread);
|
||||
furi_assert(thread->state == FuriThreadStateStopped);
|
||||
furi_check(thread);
|
||||
furi_check(thread->state == FuriThreadStateStopped);
|
||||
|
||||
if(thread->name) free(thread->name);
|
||||
|
||||
thread->name = name ? strdup(name) : NULL;
|
||||
}
|
||||
|
||||
void furi_thread_set_appid(FuriThread* thread, const char* appid) {
|
||||
furi_assert(thread);
|
||||
furi_assert(thread->state == FuriThreadStateStopped);
|
||||
furi_check(thread);
|
||||
furi_check(thread->state == FuriThreadStateStopped);
|
||||
if(thread->appid) free(thread->appid);
|
||||
thread->appid = appid ? strdup(appid) : NULL;
|
||||
}
|
||||
@@ -199,68 +200,70 @@ void furi_thread_mark_as_service(FuriThread* thread) {
|
||||
}
|
||||
|
||||
void furi_thread_set_stack_size(FuriThread* thread, size_t stack_size) {
|
||||
furi_assert(thread);
|
||||
furi_assert(thread->state == FuriThreadStateStopped);
|
||||
furi_assert(stack_size % 4 == 0);
|
||||
furi_check(thread);
|
||||
furi_check(thread->state == FuriThreadStateStopped);
|
||||
furi_check(stack_size % 4 == 0);
|
||||
thread->stack_size = stack_size;
|
||||
}
|
||||
|
||||
void furi_thread_set_callback(FuriThread* thread, FuriThreadCallback callback) {
|
||||
furi_assert(thread);
|
||||
furi_assert(thread->state == FuriThreadStateStopped);
|
||||
furi_check(thread);
|
||||
furi_check(thread->state == FuriThreadStateStopped);
|
||||
thread->callback = callback;
|
||||
}
|
||||
|
||||
void furi_thread_set_context(FuriThread* thread, void* context) {
|
||||
furi_assert(thread);
|
||||
furi_assert(thread->state == FuriThreadStateStopped);
|
||||
furi_check(thread);
|
||||
furi_check(thread->state == FuriThreadStateStopped);
|
||||
thread->context = context;
|
||||
}
|
||||
|
||||
void furi_thread_set_priority(FuriThread* thread, FuriThreadPriority priority) {
|
||||
furi_assert(thread);
|
||||
furi_assert(thread->state == FuriThreadStateStopped);
|
||||
furi_assert(priority >= FuriThreadPriorityIdle && priority <= FuriThreadPriorityIsr);
|
||||
furi_check(thread);
|
||||
furi_check(thread->state == FuriThreadStateStopped);
|
||||
furi_check(priority >= FuriThreadPriorityIdle && priority <= FuriThreadPriorityIsr);
|
||||
thread->priority = priority;
|
||||
}
|
||||
|
||||
FuriThreadPriority furi_thread_get_priority(FuriThread* thread) {
|
||||
furi_assert(thread);
|
||||
furi_check(thread);
|
||||
TaskHandle_t hTask = furi_thread_get_id(thread);
|
||||
return (FuriThreadPriority)uxTaskPriorityGet(hTask);
|
||||
}
|
||||
|
||||
void furi_thread_set_current_priority(FuriThreadPriority priority) {
|
||||
furi_check(priority <= FuriThreadPriorityIsr);
|
||||
|
||||
UBaseType_t new_priority = priority ? priority : FuriThreadPriorityNormal;
|
||||
vTaskPrioritySet(NULL, new_priority);
|
||||
}
|
||||
|
||||
FuriThreadPriority furi_thread_get_current_priority() {
|
||||
FuriThreadPriority furi_thread_get_current_priority(void) {
|
||||
return (FuriThreadPriority)uxTaskPriorityGet(NULL);
|
||||
}
|
||||
|
||||
void furi_thread_set_state_callback(FuriThread* thread, FuriThreadStateCallback callback) {
|
||||
furi_assert(thread);
|
||||
furi_assert(thread->state == FuriThreadStateStopped);
|
||||
furi_check(thread);
|
||||
furi_check(thread->state == FuriThreadStateStopped);
|
||||
thread->state_callback = callback;
|
||||
}
|
||||
|
||||
void furi_thread_set_state_context(FuriThread* thread, void* context) {
|
||||
furi_assert(thread);
|
||||
furi_assert(thread->state == FuriThreadStateStopped);
|
||||
furi_check(thread);
|
||||
furi_check(thread->state == FuriThreadStateStopped);
|
||||
thread->state_context = context;
|
||||
}
|
||||
|
||||
FuriThreadState furi_thread_get_state(FuriThread* thread) {
|
||||
furi_assert(thread);
|
||||
furi_check(thread);
|
||||
return thread->state;
|
||||
}
|
||||
|
||||
void furi_thread_start(FuriThread* thread) {
|
||||
furi_assert(thread);
|
||||
furi_assert(thread->callback);
|
||||
furi_assert(thread->state == FuriThreadStateStopped);
|
||||
furi_assert(thread->stack_size > 0 && thread->stack_size < (UINT16_MAX * sizeof(StackType_t)));
|
||||
furi_check(thread);
|
||||
furi_check(thread->callback);
|
||||
furi_check(thread->state == FuriThreadStateStopped);
|
||||
furi_check(thread->stack_size > 0 && thread->stack_size < (UINT16_MAX * sizeof(StackType_t)));
|
||||
|
||||
furi_thread_set_state(thread, FuriThreadStateStarting);
|
||||
|
||||
@@ -289,13 +292,13 @@ void furi_thread_cleanup_tcb_event(TaskHandle_t task) {
|
||||
if(thread) {
|
||||
// clear thread local storage
|
||||
vTaskSetThreadLocalStoragePointer(task, 0, NULL);
|
||||
furi_assert(thread->task_handle == task);
|
||||
furi_check(thread->task_handle == task);
|
||||
thread->task_handle = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
bool furi_thread_join(FuriThread* thread) {
|
||||
furi_assert(thread);
|
||||
furi_check(thread);
|
||||
|
||||
furi_check(furi_thread_get_current() != thread);
|
||||
|
||||
@@ -311,45 +314,45 @@ bool furi_thread_join(FuriThread* thread) {
|
||||
}
|
||||
|
||||
FuriThreadId furi_thread_get_id(FuriThread* thread) {
|
||||
furi_assert(thread);
|
||||
furi_check(thread);
|
||||
return thread->task_handle;
|
||||
}
|
||||
|
||||
void furi_thread_enable_heap_trace(FuriThread* thread) {
|
||||
furi_assert(thread);
|
||||
furi_assert(thread->state == FuriThreadStateStopped);
|
||||
furi_check(thread);
|
||||
furi_check(thread->state == FuriThreadStateStopped);
|
||||
thread->heap_trace_enabled = true;
|
||||
}
|
||||
|
||||
void furi_thread_disable_heap_trace(FuriThread* thread) {
|
||||
furi_assert(thread);
|
||||
furi_assert(thread->state == FuriThreadStateStopped);
|
||||
furi_check(thread);
|
||||
furi_check(thread->state == FuriThreadStateStopped);
|
||||
thread->heap_trace_enabled = false;
|
||||
}
|
||||
|
||||
size_t furi_thread_get_heap_size(FuriThread* thread) {
|
||||
furi_assert(thread);
|
||||
furi_assert(thread->heap_trace_enabled == true);
|
||||
furi_check(thread);
|
||||
furi_check(thread->heap_trace_enabled == true);
|
||||
return thread->heap_size;
|
||||
}
|
||||
|
||||
int32_t furi_thread_get_return_code(FuriThread* thread) {
|
||||
furi_assert(thread);
|
||||
furi_assert(thread->state == FuriThreadStateStopped);
|
||||
furi_check(thread);
|
||||
furi_check(thread->state == FuriThreadStateStopped);
|
||||
return thread->ret;
|
||||
}
|
||||
|
||||
FuriThreadId furi_thread_get_current_id() {
|
||||
FuriThreadId furi_thread_get_current_id(void) {
|
||||
return xTaskGetCurrentTaskHandle();
|
||||
}
|
||||
|
||||
FuriThread* furi_thread_get_current() {
|
||||
FuriThread* furi_thread_get_current(void) {
|
||||
FuriThread* thread = pvTaskGetThreadLocalStoragePointer(NULL, 0);
|
||||
return thread;
|
||||
}
|
||||
|
||||
void furi_thread_yield() {
|
||||
furi_assert(!FURI_IS_IRQ_MODE());
|
||||
void furi_thread_yield(void) {
|
||||
furi_check(!FURI_IS_IRQ_MODE());
|
||||
taskYIELD();
|
||||
}
|
||||
|
||||
@@ -594,20 +597,21 @@ static int32_t __furi_thread_stdout_flush(FuriThread* thread) {
|
||||
|
||||
void furi_thread_set_stdout_callback(FuriThreadStdoutWriteCallback callback) {
|
||||
FuriThread* thread = furi_thread_get_current();
|
||||
furi_assert(thread);
|
||||
furi_check(thread);
|
||||
__furi_thread_stdout_flush(thread);
|
||||
thread->output.write_callback = callback;
|
||||
}
|
||||
|
||||
FuriThreadStdoutWriteCallback furi_thread_get_stdout_callback() {
|
||||
FuriThreadStdoutWriteCallback furi_thread_get_stdout_callback(void) {
|
||||
FuriThread* thread = furi_thread_get_current();
|
||||
furi_assert(thread);
|
||||
furi_check(thread);
|
||||
return thread->output.write_callback;
|
||||
}
|
||||
|
||||
size_t furi_thread_stdout_write(const char* data, size_t size) {
|
||||
FuriThread* thread = furi_thread_get_current();
|
||||
furi_assert(thread);
|
||||
furi_check(thread);
|
||||
|
||||
if(size == 0 || data == NULL) {
|
||||
return __furi_thread_stdout_flush(thread);
|
||||
} else {
|
||||
@@ -629,19 +633,26 @@ size_t furi_thread_stdout_write(const char* data, size_t size) {
|
||||
return size;
|
||||
}
|
||||
|
||||
int32_t furi_thread_stdout_flush() {
|
||||
int32_t furi_thread_stdout_flush(void) {
|
||||
FuriThread* thread = furi_thread_get_current();
|
||||
furi_assert(thread);
|
||||
furi_check(thread);
|
||||
|
||||
return __furi_thread_stdout_flush(thread);
|
||||
}
|
||||
|
||||
void furi_thread_suspend(FuriThreadId thread_id) {
|
||||
furi_check(thread_id);
|
||||
|
||||
TaskHandle_t hTask = (TaskHandle_t)thread_id;
|
||||
|
||||
vTaskSuspend(hTask);
|
||||
}
|
||||
|
||||
void furi_thread_resume(FuriThreadId thread_id) {
|
||||
furi_check(thread_id);
|
||||
|
||||
TaskHandle_t hTask = (TaskHandle_t)thread_id;
|
||||
|
||||
if(FURI_IS_IRQ_MODE()) {
|
||||
xTaskResumeFromISR(hTask);
|
||||
} else {
|
||||
@@ -650,6 +661,9 @@ void furi_thread_resume(FuriThreadId thread_id) {
|
||||
}
|
||||
|
||||
bool furi_thread_is_suspended(FuriThreadId thread_id) {
|
||||
furi_check(thread_id);
|
||||
|
||||
TaskHandle_t hTask = (TaskHandle_t)thread_id;
|
||||
|
||||
return eTaskGetState(hTask) == eSuspended;
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ typedef void (*FuriThreadStateCallback)(FuriThreadState state, void* context);
|
||||
*
|
||||
* @return FuriThread instance
|
||||
*/
|
||||
FuriThread* furi_thread_alloc();
|
||||
FuriThread* furi_thread_alloc(void);
|
||||
|
||||
/** Allocate FuriThread, shortcut version
|
||||
*
|
||||
@@ -155,7 +155,7 @@ void furi_thread_set_current_priority(FuriThreadPriority priority);
|
||||
*
|
||||
* @return FuriThreadPriority value
|
||||
*/
|
||||
FuriThreadPriority furi_thread_get_current_priority();
|
||||
FuriThreadPriority furi_thread_get_current_priority(void);
|
||||
|
||||
/** Set FuriThread state change callback
|
||||
*
|
||||
@@ -238,16 +238,16 @@ int32_t furi_thread_get_return_code(FuriThread* thread);
|
||||
*
|
||||
* @return FuriThreadId or NULL
|
||||
*/
|
||||
FuriThreadId furi_thread_get_current_id();
|
||||
FuriThreadId furi_thread_get_current_id(void);
|
||||
|
||||
/** Get FuriThread instance for current thread
|
||||
*
|
||||
* @return pointer to FuriThread or NULL if this thread doesn't belongs to Furi
|
||||
*/
|
||||
FuriThread* furi_thread_get_current();
|
||||
FuriThread* furi_thread_get_current(void);
|
||||
|
||||
/** Return control to scheduler */
|
||||
void furi_thread_yield();
|
||||
void furi_thread_yield(void);
|
||||
|
||||
uint32_t furi_thread_flags_set(FuriThreadId thread_id, uint32_t flags);
|
||||
|
||||
@@ -294,7 +294,7 @@ uint32_t furi_thread_get_stack_space(FuriThreadId thread_id);
|
||||
*
|
||||
* @return STDOUT callback
|
||||
*/
|
||||
FuriThreadStdoutWriteCallback furi_thread_get_stdout_callback();
|
||||
FuriThreadStdoutWriteCallback furi_thread_get_stdout_callback(void);
|
||||
|
||||
/** Set STDOUT callback for thread
|
||||
*
|
||||
@@ -315,7 +315,7 @@ size_t furi_thread_stdout_write(const char* data, size_t size);
|
||||
*
|
||||
* @return int32_t error code
|
||||
*/
|
||||
int32_t furi_thread_stdout_flush();
|
||||
int32_t furi_thread_stdout_flush(void);
|
||||
|
||||
/** Suspend thread
|
||||
*
|
||||
|
||||
@@ -26,7 +26,7 @@ static void TimerCallback(TimerHandle_t hTimer) {
|
||||
}
|
||||
|
||||
FuriTimer* furi_timer_alloc(FuriTimerCallback func, FuriTimerType type, void* context) {
|
||||
furi_assert((furi_kernel_is_irq_or_masked() == 0U) && (func != NULL));
|
||||
furi_check((furi_kernel_is_irq_or_masked() == 0U) && (func != NULL));
|
||||
|
||||
TimerHandle_t hTimer;
|
||||
TimerCallback_t* callb;
|
||||
@@ -59,8 +59,8 @@ FuriTimer* furi_timer_alloc(FuriTimerCallback func, FuriTimerType type, void* co
|
||||
}
|
||||
|
||||
void furi_timer_free(FuriTimer* instance) {
|
||||
furi_assert(!furi_kernel_is_irq_or_masked());
|
||||
furi_assert(instance);
|
||||
furi_check(!furi_kernel_is_irq_or_masked());
|
||||
furi_check(instance);
|
||||
|
||||
TimerHandle_t hTimer = (TimerHandle_t)instance;
|
||||
TimerCallback_t* callb;
|
||||
@@ -86,9 +86,9 @@ void furi_timer_free(FuriTimer* instance) {
|
||||
}
|
||||
|
||||
FuriStatus furi_timer_start(FuriTimer* instance, uint32_t ticks) {
|
||||
furi_assert(!furi_kernel_is_irq_or_masked());
|
||||
furi_assert(instance);
|
||||
furi_assert(ticks < portMAX_DELAY);
|
||||
furi_check(!furi_kernel_is_irq_or_masked());
|
||||
furi_check(instance);
|
||||
furi_check(ticks < portMAX_DELAY);
|
||||
|
||||
TimerHandle_t hTimer = (TimerHandle_t)instance;
|
||||
FuriStatus stat;
|
||||
@@ -104,9 +104,9 @@ FuriStatus furi_timer_start(FuriTimer* instance, uint32_t ticks) {
|
||||
}
|
||||
|
||||
FuriStatus furi_timer_restart(FuriTimer* instance, uint32_t ticks) {
|
||||
furi_assert(!furi_kernel_is_irq_or_masked());
|
||||
furi_assert(instance);
|
||||
furi_assert(ticks < portMAX_DELAY);
|
||||
furi_check(!furi_kernel_is_irq_or_masked());
|
||||
furi_check(instance);
|
||||
furi_check(ticks < portMAX_DELAY);
|
||||
|
||||
TimerHandle_t hTimer = (TimerHandle_t)instance;
|
||||
FuriStatus stat;
|
||||
@@ -123,8 +123,8 @@ FuriStatus furi_timer_restart(FuriTimer* instance, uint32_t ticks) {
|
||||
}
|
||||
|
||||
FuriStatus furi_timer_stop(FuriTimer* instance) {
|
||||
furi_assert(!furi_kernel_is_irq_or_masked());
|
||||
furi_assert(instance);
|
||||
furi_check(!furi_kernel_is_irq_or_masked());
|
||||
furi_check(instance);
|
||||
|
||||
TimerHandle_t hTimer = (TimerHandle_t)instance;
|
||||
|
||||
@@ -134,8 +134,8 @@ FuriStatus furi_timer_stop(FuriTimer* instance) {
|
||||
}
|
||||
|
||||
uint32_t furi_timer_is_running(FuriTimer* instance) {
|
||||
furi_assert(!furi_kernel_is_irq_or_masked());
|
||||
furi_assert(instance);
|
||||
furi_check(!furi_kernel_is_irq_or_masked());
|
||||
furi_check(instance);
|
||||
|
||||
TimerHandle_t hTimer = (TimerHandle_t)instance;
|
||||
|
||||
@@ -144,8 +144,8 @@ uint32_t furi_timer_is_running(FuriTimer* instance) {
|
||||
}
|
||||
|
||||
uint32_t furi_timer_get_expire_time(FuriTimer* instance) {
|
||||
furi_assert(!furi_kernel_is_irq_or_masked());
|
||||
furi_assert(instance);
|
||||
furi_check(!furi_kernel_is_irq_or_masked());
|
||||
furi_check(instance);
|
||||
|
||||
TimerHandle_t hTimer = (TimerHandle_t)instance;
|
||||
|
||||
@@ -153,17 +153,20 @@ uint32_t furi_timer_get_expire_time(FuriTimer* instance) {
|
||||
}
|
||||
|
||||
void furi_timer_pending_callback(FuriTimerPendigCallback callback, void* context, uint32_t arg) {
|
||||
furi_check(callback);
|
||||
|
||||
BaseType_t ret = pdFAIL;
|
||||
if(furi_kernel_is_irq_or_masked()) {
|
||||
ret = xTimerPendFunctionCallFromISR(callback, context, arg, NULL);
|
||||
} else {
|
||||
ret = xTimerPendFunctionCall(callback, context, arg, FuriWaitForever);
|
||||
}
|
||||
|
||||
furi_check(ret == pdPASS);
|
||||
}
|
||||
|
||||
void furi_timer_set_thread_priority(FuriTimerThreadPriority priority) {
|
||||
furi_assert(!furi_kernel_is_irq_or_masked());
|
||||
furi_check(!furi_kernel_is_irq_or_masked());
|
||||
|
||||
TaskHandle_t task_handle = xTimerGetTimerDaemonTaskHandle();
|
||||
furi_check(task_handle); // Don't call this method before timer task start
|
||||
|
||||
@@ -29,7 +29,7 @@ static void flipper_print_version(const char* target, const Version* version) {
|
||||
}
|
||||
}
|
||||
|
||||
void flipper_init() {
|
||||
void flipper_init(void) {
|
||||
flipper_print_version("Firmware", furi_hal_version_get_firmware_version());
|
||||
|
||||
FURI_LOG_I(TAG, "Boot mode %d, starting services", furi_hal_rtc_get_boot_mode());
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
void flipper_init();
|
||||
void flipper_init(void);
|
||||
|
||||
12
furi/furi.c
12
furi/furi.c
@@ -4,17 +4,17 @@
|
||||
#include <FreeRTOS.h>
|
||||
#include <queue.h>
|
||||
|
||||
void furi_init() {
|
||||
furi_assert(!furi_kernel_is_irq_or_masked());
|
||||
furi_assert(xTaskGetSchedulerState() == taskSCHEDULER_NOT_STARTED);
|
||||
void furi_init(void) {
|
||||
furi_check(!furi_kernel_is_irq_or_masked());
|
||||
furi_check(xTaskGetSchedulerState() == taskSCHEDULER_NOT_STARTED);
|
||||
|
||||
furi_log_init();
|
||||
furi_record_init();
|
||||
}
|
||||
|
||||
void furi_run() {
|
||||
furi_assert(!furi_kernel_is_irq_or_masked());
|
||||
furi_assert(xTaskGetSchedulerState() == taskSCHEDULER_NOT_STARTED);
|
||||
void furi_run(void) {
|
||||
furi_check(!furi_kernel_is_irq_or_masked());
|
||||
furi_check(xTaskGetSchedulerState() == taskSCHEDULER_NOT_STARTED);
|
||||
|
||||
#if(__ARM_ARCH_7A__ == 0U)
|
||||
/* Service Call interrupt might be configured before kernel start */
|
||||
|
||||
@@ -28,9 +28,9 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void furi_init();
|
||||
void furi_init(void);
|
||||
|
||||
void furi_run();
|
||||
void furi_run(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user