Furi: core refactoring and CMSIS removal part 2 (#1410)

* Furi: rename and move core
* Furi: drop CMSIS_OS header and unused api, partially refactor and cleanup the rest
* Furi: CMSIS_OS drop and refactoring.
* Furi: refactoring, remove cmsis legacy
* Furi: fix incorrect assert on queue deallocation, cleanup timer
* Furi: improve delay api, get rid of floats
* hal: dropped furi_hal_crc
* Furi: move DWT based delay to cortex HAL
* Furi: update core documentation

Co-authored-by: hedger <hedger@nanode.su>
This commit is contained in:
あく
2022-07-20 13:56:33 +03:00
committed by GitHub
parent f9c2287ea7
commit e3c7201a20
264 changed files with 2569 additions and 3883 deletions

View File

@@ -1,7 +1,6 @@
#include <stdio.h>
#include <string.h>
#include <furi.h>
#include "furi_hal_delay.h"
#include "../minunit.h"

View File

@@ -104,7 +104,7 @@ static bool nfc_test_digital_signal_test_encode(
nfca_signal_encode(
nfc_test->signal, nfc_test->test_data, nfc_test->test_data_len * 8, parity);
digital_signal_prepare_arr(nfc_test->signal->tx_signal);
time = (DWT->CYCCNT - time) / furi_hal_delay_instructions_per_microsecond();
time = (DWT->CYCCNT - time) / furi_hal_cortex_instructions_per_microsecond();
FURI_CRITICAL_EXIT();
// Check timings

View File

@@ -1,7 +1,6 @@
#include "flipper.pb.h"
#include "furi_hal_delay.h"
#include "furi/check.h"
#include "furi/record.h"
#include <core/check.h>
#include <core/record.h>
#include "pb_decode.h"
#include <rpc/rpc.h>
#include "rpc/rpc_i.h"
@@ -87,7 +86,7 @@ static void test_rpc_setup(void) {
rpc = furi_record_open("rpc");
for(int i = 0; !(rpc_session[0].session) && (i < 10000); ++i) {
rpc_session[0].session = rpc_session_open(rpc);
furi_hal_delay_ms(1);
furi_delay_tick(1);
}
furi_check(rpc_session[0].session);
@@ -107,7 +106,7 @@ static void test_rpc_setup_second_session(void) {
for(int i = 0; !(rpc_session[1].session) && (i < 10000); ++i) {
rpc_session[1].session = rpc_session_open(rpc);
furi_hal_delay_ms(1);
furi_delay_tick(1);
}
furi_check(rpc_session[1].session);
@@ -269,7 +268,7 @@ static void output_bytes_callback(void* ctx, uint8_t* got_bytes, size_t got_size
RpcSessionContext* callbacks_context = ctx;
size_t bytes_sent =
xStreamBufferSend(callbacks_context->output_stream, got_bytes, got_size, osWaitForever);
xStreamBufferSend(callbacks_context->output_stream, got_bytes, got_size, FuriWaitForever);
(void)bytes_sent;
furi_check(bytes_sent == got_size);
}
@@ -1525,28 +1524,28 @@ MU_TEST(test_app_start_and_lock_status) {
test_app_get_status_lock_run(false, ++command_id);
test_app_start_run("Delay Test", "0", PB_CommandStatus_OK, ++command_id);
furi_hal_delay_ms(100);
furi_delay_ms(100);
test_app_get_status_lock_run(false, ++command_id);
test_app_start_run("Delay Test", "200", PB_CommandStatus_OK, ++command_id);
test_app_get_status_lock_run(true, ++command_id);
furi_hal_delay_ms(100);
furi_delay_ms(100);
test_app_get_status_lock_run(true, ++command_id);
test_app_start_run("Delay Test", "0", PB_CommandStatus_ERROR_APP_SYSTEM_LOCKED, ++command_id);
furi_hal_delay_ms(200);
furi_delay_ms(200);
test_app_get_status_lock_run(false, ++command_id);
test_app_start_run("Delay Test", "500", PB_CommandStatus_OK, ++command_id);
furi_hal_delay_ms(100);
furi_delay_ms(100);
test_app_get_status_lock_run(true, ++command_id);
test_app_start_run("Infrared", "0", PB_CommandStatus_ERROR_APP_SYSTEM_LOCKED, ++command_id);
furi_hal_delay_ms(100);
furi_delay_ms(100);
test_app_get_status_lock_run(true, ++command_id);
test_app_start_run(
"2_girls_1_app", "0", PB_CommandStatus_ERROR_INVALID_PARAMETERS, ++command_id);
furi_hal_delay_ms(100);
furi_delay_ms(100);
test_app_get_status_lock_run(true, ++command_id);
furi_hal_delay_ms(500);
furi_delay_ms(500);
test_app_get_status_lock_run(false, ++command_id);
}
@@ -1794,7 +1793,7 @@ int32_t delay_test_app(void* p) {
int timeout = atoi((const char*)p);
if(timeout > 0) {
furi_hal_delay_ms(timeout);
furi_delay_ms(timeout);
}
return 0;

View File

@@ -1,6 +1,5 @@
#include "../minunit.h"
#include <furi.h>
#include <furi_hal_delay.h>
#include <storage/storage.h>
#define STORAGE_LOCKED_FILE "/ext/locked_file.test"
@@ -25,11 +24,11 @@ static void storage_file_open_lock_teardown() {
static int32_t storage_file_locker(void* ctx) {
Storage* storage = furi_record_open("storage");
osSemaphoreId_t semaphore = ctx;
FuriSemaphore* semaphore = ctx;
File* file = storage_file_alloc(storage);
furi_check(storage_file_open(file, STORAGE_LOCKED_FILE, FSAM_READ_WRITE, FSOM_OPEN_EXISTING));
osSemaphoreRelease(semaphore);
furi_hal_delay_ms(1000);
furi_semaphore_release(semaphore);
furi_delay_ms(1000);
furi_check(storage_file_close(file));
furi_record_close("storage");
@@ -40,7 +39,7 @@ static int32_t storage_file_locker(void* ctx) {
MU_TEST(storage_file_open_lock) {
Storage* storage = furi_record_open("storage");
bool result = false;
osSemaphoreId_t semaphore = osSemaphoreNew(1, 0, NULL);
FuriSemaphore* semaphore = furi_semaphore_alloc(1, 0);
File* file = storage_file_alloc(storage);
// file_locker thread start
@@ -52,14 +51,14 @@ MU_TEST(storage_file_open_lock) {
furi_thread_start(locker_thread);
// wait for file lock
osSemaphoreAcquire(semaphore, osWaitForever);
osSemaphoreDelete(semaphore);
furi_semaphore_acquire(semaphore, FuriWaitForever);
furi_semaphore_free(semaphore);
result = storage_file_open(file, STORAGE_LOCKED_FILE, FSAM_READ_WRITE, FSOM_OPEN_EXISTING);
storage_file_close(file);
// file_locker thread stop
mu_check(furi_thread_join(locker_thread) == osOK);
mu_check(furi_thread_join(locker_thread) == FuriStatusOk);
furi_thread_free(locker_thread);
// clean data
@@ -115,11 +114,11 @@ MU_TEST(storage_dir_open_close) {
static int32_t storage_dir_locker(void* ctx) {
Storage* storage = furi_record_open("storage");
osSemaphoreId_t semaphore = ctx;
FuriSemaphore* semaphore = ctx;
File* file = storage_file_alloc(storage);
furi_check(storage_dir_open(file, STORAGE_LOCKED_DIR));
osSemaphoreRelease(semaphore);
furi_hal_delay_ms(1000);
furi_semaphore_release(semaphore);
furi_delay_ms(1000);
furi_check(storage_dir_close(file));
furi_record_close("storage");
@@ -130,7 +129,7 @@ static int32_t storage_dir_locker(void* ctx) {
MU_TEST(storage_dir_open_lock) {
Storage* storage = furi_record_open("storage");
bool result = false;
osSemaphoreId_t semaphore = osSemaphoreNew(1, 0, NULL);
FuriSemaphore* semaphore = furi_semaphore_alloc(1, 0);
File* file = storage_file_alloc(storage);
// file_locker thread start
@@ -142,14 +141,14 @@ MU_TEST(storage_dir_open_lock) {
furi_thread_start(locker_thread);
// wait for dir lock
osSemaphoreAcquire(semaphore, osWaitForever);
osSemaphoreDelete(semaphore);
furi_semaphore_acquire(semaphore, FuriWaitForever);
furi_semaphore_free(semaphore);
result = storage_dir_open(file, STORAGE_LOCKED_DIR);
storage_dir_close(file);
// file_locker thread stop
mu_check(furi_thread_join(locker_thread) == osOK);
mu_check(furi_thread_join(locker_thread) == FuriStatusOk);
furi_thread_free(locker_thread);
// clean data

View File

@@ -56,7 +56,7 @@ static void subghz_test_deinit(void) {
static bool subghz_decoder_test(const char* path, const char* name_decoder) {
subghz_test_decoder_count = 0;
uint32_t test_start = furi_hal_get_tick();
uint32_t test_start = furi_get_tick();
SubGhzProtocolDecoderBase* decoder =
subghz_receiver_search_decoder_base_by_name(receiver_handler, name_decoder);
@@ -65,10 +65,10 @@ static bool subghz_decoder_test(const char* path, const char* name_decoder) {
file_worker_encoder_handler = subghz_file_encoder_worker_alloc();
if(subghz_file_encoder_worker_start(file_worker_encoder_handler, path)) {
// the worker needs a file in order to open and read part of the file
osDelay(100);
furi_delay_ms(100);
LevelDuration level_duration;
while(furi_hal_get_tick() - test_start < TEST_TIMEOUT) {
while(furi_get_tick() - test_start < TEST_TIMEOUT) {
level_duration =
subghz_file_encoder_worker_get_level_duration(file_worker_encoder_handler);
if(!level_duration_is_reset(level_duration)) {
@@ -81,7 +81,7 @@ static bool subghz_decoder_test(const char* path, const char* name_decoder) {
break;
}
}
furi_hal_delay_ms(10);
furi_delay_ms(10);
}
if(subghz_file_encoder_worker_is_running(file_worker_encoder_handler)) {
subghz_file_encoder_worker_stop(file_worker_encoder_handler);
@@ -89,7 +89,7 @@ static bool subghz_decoder_test(const char* path, const char* name_decoder) {
subghz_file_encoder_worker_free(file_worker_encoder_handler);
}
FURI_LOG_T(TAG, "\r\n Decoder count parse \033[0;33m%d\033[0m ", subghz_test_decoder_count);
if(furi_hal_get_tick() - test_start > TEST_TIMEOUT) {
if(furi_get_tick() - test_start > TEST_TIMEOUT) {
printf("\033[0;31mTest decoder %s ERROR TimeOut\033[0m\r\n", name_decoder);
return false;
} else {
@@ -100,15 +100,15 @@ static bool subghz_decoder_test(const char* path, const char* name_decoder) {
static bool subghz_decode_random_test(const char* path) {
subghz_test_decoder_count = 0;
subghz_receiver_reset(receiver_handler);
uint32_t test_start = furi_hal_get_tick();
uint32_t test_start = furi_get_tick();
file_worker_encoder_handler = subghz_file_encoder_worker_alloc();
if(subghz_file_encoder_worker_start(file_worker_encoder_handler, path)) {
// the worker needs a file in order to open and read part of the file
osDelay(100);
furi_delay_ms(100);
LevelDuration level_duration;
while(furi_hal_get_tick() - test_start < TEST_TIMEOUT * 10) {
while(furi_get_tick() - test_start < TEST_TIMEOUT * 10) {
level_duration =
subghz_file_encoder_worker_get_level_duration(file_worker_encoder_handler);
if(!level_duration_is_reset(level_duration)) {
@@ -121,14 +121,14 @@ static bool subghz_decode_random_test(const char* path) {
break;
}
}
furi_hal_delay_ms(10);
furi_delay_ms(10);
if(subghz_file_encoder_worker_is_running(file_worker_encoder_handler)) {
subghz_file_encoder_worker_stop(file_worker_encoder_handler);
}
subghz_file_encoder_worker_free(file_worker_encoder_handler);
}
FURI_LOG_T(TAG, "\r\n Decoder count parse \033[0;33m%d\033[0m ", subghz_test_decoder_count);
if(furi_hal_get_tick() - test_start > TEST_TIMEOUT * 10) {
if(furi_get_tick() - test_start > TEST_TIMEOUT * 10) {
printf("\033[0;31mRandom test ERROR TimeOut\033[0m\r\n");
return false;
} else if(subghz_test_decoder_count == TEST_RANDOM_COUNT_PARSE) {
@@ -140,7 +140,7 @@ static bool subghz_decode_random_test(const char* path) {
static bool subghz_encoder_test(const char* path) {
subghz_test_decoder_count = 0;
uint32_t test_start = furi_hal_get_tick();
uint32_t test_start = furi_get_tick();
string_t temp_str;
string_init(temp_str);
bool file_load = false;
@@ -175,7 +175,7 @@ static bool subghz_encoder_test(const char* path) {
if(decoder) {
LevelDuration level_duration;
while(furi_hal_get_tick() - test_start < TEST_TIMEOUT) {
while(furi_get_tick() - test_start < TEST_TIMEOUT) {
level_duration = subghz_transmitter_yield(transmitter);
if(!level_duration_is_reset(level_duration)) {
bool level = level_duration_get_level(level_duration);
@@ -185,13 +185,13 @@ static bool subghz_encoder_test(const char* path) {
break;
}
}
furi_hal_delay_ms(10);
furi_delay_ms(10);
}
subghz_transmitter_free(transmitter);
}
flipper_format_free(fff_data_file);
FURI_LOG_T(TAG, "\r\n Decoder count parse \033[0;33m%d\033[0m ", subghz_test_decoder_count);
if(furi_hal_get_tick() - test_start > TEST_TIMEOUT) {
if(furi_get_tick() - test_start > TEST_TIMEOUT) {
printf("\033[0;31mTest encoder %s ERROR TimeOut\033[0m\r\n", string_get_cstr(temp_str));
subghz_test_decoder_count = 0;
}

View File

@@ -78,7 +78,7 @@ void unit_tests_cli(Cli* cli, string_t args, void* context) {
notification_message_block(notification, &sequence_set_only_blue_255);
uint32_t heap_before = memmgr_get_free_heap();
uint32_t cycle_counter = furi_hal_get_tick();
uint32_t cycle_counter = furi_get_tick();
for(size_t i = 0; i < COUNT_OF(unit_tests); i++) {
if(cli_cmd_interrupt_received(cli)) {
@@ -98,11 +98,11 @@ void unit_tests_cli(Cli* cli, string_t args, void* context) {
printf("\r\nFailed tests: %lu\r\n", failed_tests);
// Time report
cycle_counter = (furi_hal_get_tick() - cycle_counter);
cycle_counter = (furi_get_tick() - cycle_counter);
printf("Consumed: %lu ms\r\n", cycle_counter);
// Wait for tested services and apps to deallocate memory
furi_hal_delay_ms(200);
furi_delay_ms(200);
uint32_t heap_after = memmgr_get_free_heap();
printf("Leaked: %ld\r\n", heap_before - heap_after);