[FL-781] FURI, CLI, stdlib: stdout hooks, integration between subsystems, uniform printf usage (#311)
* FURI stdglue: stdout hooks, local and global, ISR safe printf. Uniform newlines for terminal/debug output. Power: prevent sleep while core 2 has not started. * Furi record, stdglue: check mutex allocation * remove unused test * Furi stdglue: buferized output, dynamically allocated state. Furi record: dynamically allocated state. Input dump: proper line ending. Hal VCP: dynamically allocated state. * Interrupt manager: explicitly init list. * Makefile: cleanup rules, fix broken dfu upload. F4: add compiler stack protection options. * BLE: call debug uart callback on transmission complete * FreeRTOS: add configUSE_NEWLIB_REENTRANT * API HAL Timebase: fix issue with idle thread stack corruption caused by systick interrupt. BT: cleanup debug info output. FreeRTOS: disable reentry for newlib. * F4: update stack protection CFLAGS to match used compiller * F4: disable compiller stack protection because of incompatibility with current compiller * Makefile: return openocd logs to gdb * BLE: fixed pin, moar power, ble trace info. * Prevent sleep when connection is active * Makefile: return serial port to upload rule, add workaround for mac os * Furi: prevent usage of stack for cmsis functions. * F4: add missing includes, add debugger breakpoints * Applications: per app stack size. * Furi: honor kernel state in stdglue * FreeRTOS: remove unused hooks * Cleanup and format sources Co-authored-by: DrZlo13 <who.just.the.doctor@gmail.com>
This commit is contained in:
		@@ -1,5 +1,6 @@
 | 
			
		||||
#include "record.h"
 | 
			
		||||
#include "check.h"
 | 
			
		||||
#include "memmgr.h"
 | 
			
		||||
 | 
			
		||||
#include <cmsis_os2.h>
 | 
			
		||||
#include <m-string.h>
 | 
			
		||||
@@ -22,34 +23,38 @@ typedef struct {
 | 
			
		||||
    FuriRecordDict_t records;
 | 
			
		||||
} FuriRecordData;
 | 
			
		||||
 | 
			
		||||
FuriRecordData furi_record_data;
 | 
			
		||||
static FuriRecordData* furi_record_data = NULL;
 | 
			
		||||
 | 
			
		||||
void furi_record_init() {
 | 
			
		||||
    furi_record_data.records_mutex = osMutexNew(NULL);
 | 
			
		||||
    FuriRecordDict_init(furi_record_data.records);
 | 
			
		||||
    furi_record_data = furi_alloc(sizeof(FuriRecordData));
 | 
			
		||||
    furi_record_data->records_mutex = osMutexNew(NULL);
 | 
			
		||||
    furi_check(furi_record_data->records_mutex);
 | 
			
		||||
    FuriRecordDict_init(furi_record_data->records);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
FuriRecord* furi_record_get_or_create(string_t name_str) {
 | 
			
		||||
    FuriRecord* record = FuriRecordDict_get(furi_record_data.records, name_str);
 | 
			
		||||
    assert(furi_record_data);
 | 
			
		||||
    FuriRecord* record = FuriRecordDict_get(furi_record_data->records, name_str);
 | 
			
		||||
    if(!record) {
 | 
			
		||||
        FuriRecord new_record;
 | 
			
		||||
        new_record.data = NULL;
 | 
			
		||||
        new_record.owner = NULL;
 | 
			
		||||
        osThreadIdSet_init(new_record.holders);
 | 
			
		||||
        FuriRecordDict_set_at(furi_record_data.records, name_str, new_record);
 | 
			
		||||
        record = FuriRecordDict_get(furi_record_data.records, name_str);
 | 
			
		||||
        FuriRecordDict_set_at(furi_record_data->records, name_str, new_record);
 | 
			
		||||
        record = FuriRecordDict_get(furi_record_data->records, name_str);
 | 
			
		||||
    }
 | 
			
		||||
    return record;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void furi_record_create(const char* name, void* data) {
 | 
			
		||||
    assert(furi_record_data);
 | 
			
		||||
    osThreadId_t thread_id = osThreadGetId();
 | 
			
		||||
 | 
			
		||||
    string_t name_str;
 | 
			
		||||
    string_init_set_str(name_str, name);
 | 
			
		||||
 | 
			
		||||
    // Acquire mutex
 | 
			
		||||
    furi_check(osMutexAcquire(furi_record_data.records_mutex, osWaitForever) == osOK);
 | 
			
		||||
    furi_check(osMutexAcquire(furi_record_data->records_mutex, osWaitForever) == osOK);
 | 
			
		||||
    FuriRecord* record = furi_record_get_or_create(name_str);
 | 
			
		||||
    record->data = data;
 | 
			
		||||
    record->owner = thread_id;
 | 
			
		||||
@@ -60,31 +65,34 @@ void furi_record_create(const char* name, void* data) {
 | 
			
		||||
        osThreadFlagsSet((osThreadId_t)*osThreadIdSet_ref(it), FURI_RECORD_FLAG_UPDATED);
 | 
			
		||||
    }
 | 
			
		||||
    // Release mutex
 | 
			
		||||
    furi_check(osMutexRelease(furi_record_data.records_mutex) == osOK);
 | 
			
		||||
    furi_check(osMutexRelease(furi_record_data->records_mutex) == osOK);
 | 
			
		||||
 | 
			
		||||
    string_clear(name_str);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool furi_record_destroy(const char* name) {
 | 
			
		||||
    assert(furi_record_data);
 | 
			
		||||
    osThreadId_t thread_id = osThreadGetId();
 | 
			
		||||
 | 
			
		||||
    string_t name_str;
 | 
			
		||||
    string_init_set_str(name_str, name);
 | 
			
		||||
 | 
			
		||||
    bool destroyed = false;
 | 
			
		||||
    furi_check(osMutexAcquire(furi_record_data.records_mutex, osWaitForever) == osOK);
 | 
			
		||||
    FuriRecord* record = FuriRecordDict_get(furi_record_data.records, name_str);
 | 
			
		||||
    furi_check(osMutexAcquire(furi_record_data->records_mutex, osWaitForever) == osOK);
 | 
			
		||||
    FuriRecord* record = FuriRecordDict_get(furi_record_data->records, name_str);
 | 
			
		||||
    if(record && record->owner == thread_id && osThreadIdSet_size(record->holders) == 0) {
 | 
			
		||||
        osThreadIdSet_clear(record->holders);
 | 
			
		||||
        FuriRecordDict_erase(furi_record_data.records, name_str);
 | 
			
		||||
        FuriRecordDict_erase(furi_record_data->records, name_str);
 | 
			
		||||
        destroyed = true;
 | 
			
		||||
    }
 | 
			
		||||
    furi_check(osMutexRelease(furi_record_data.records_mutex) == osOK);
 | 
			
		||||
    furi_check(osMutexRelease(furi_record_data->records_mutex) == osOK);
 | 
			
		||||
 | 
			
		||||
    string_clear(name_str);
 | 
			
		||||
    return destroyed;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void* furi_record_open(const char* name) {
 | 
			
		||||
    assert(furi_record_data);
 | 
			
		||||
    osThreadId_t thread_id = osThreadGetId();
 | 
			
		||||
 | 
			
		||||
    string_t name_str;
 | 
			
		||||
@@ -92,10 +100,10 @@ void* furi_record_open(const char* name) {
 | 
			
		||||
 | 
			
		||||
    FuriRecord* record = NULL;
 | 
			
		||||
    while(1) {
 | 
			
		||||
        furi_check(osMutexAcquire(furi_record_data.records_mutex, osWaitForever) == osOK);
 | 
			
		||||
        furi_check(osMutexAcquire(furi_record_data->records_mutex, osWaitForever) == osOK);
 | 
			
		||||
        record = furi_record_get_or_create(name_str);
 | 
			
		||||
        osThreadIdSet_push(record->holders, (uint32_t)thread_id);
 | 
			
		||||
        furi_check(osMutexRelease(furi_record_data.records_mutex) == osOK);
 | 
			
		||||
        furi_check(osMutexRelease(furi_record_data->records_mutex) == osOK);
 | 
			
		||||
        // Check if owner is already arrived
 | 
			
		||||
        if(record->owner) {
 | 
			
		||||
            break;
 | 
			
		||||
@@ -109,15 +117,16 @@ void* furi_record_open(const char* name) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void furi_record_close(const char* name) {
 | 
			
		||||
    assert(furi_record_data);
 | 
			
		||||
    osThreadId_t thread_id = osThreadGetId();
 | 
			
		||||
 | 
			
		||||
    string_t name_str;
 | 
			
		||||
    string_init_set_str(name_str, name);
 | 
			
		||||
 | 
			
		||||
    furi_check(osMutexAcquire(furi_record_data.records_mutex, osWaitForever) == osOK);
 | 
			
		||||
    FuriRecord* record = FuriRecordDict_get(furi_record_data.records, name_str);
 | 
			
		||||
    furi_check(osMutexAcquire(furi_record_data->records_mutex, osWaitForever) == osOK);
 | 
			
		||||
    FuriRecord* record = FuriRecordDict_get(furi_record_data->records, name_str);
 | 
			
		||||
    osThreadIdSet_erase(record->holders, (uint32_t)thread_id);
 | 
			
		||||
    furi_check(osMutexRelease(furi_record_data.records_mutex) == osOK);
 | 
			
		||||
    furi_check(osMutexRelease(furi_record_data->records_mutex) == osOK);
 | 
			
		||||
 | 
			
		||||
    string_clear(name_str);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user