diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 40fb1e439..da0cfd2c0 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -40,7 +40,7 @@ /assets/ @skotopes @DrZlo13 @hedger # Furi Core -/core/ @skotopes @DrZlo13 @hedger +/furi/ @skotopes @DrZlo13 @hedger # Debug tools and plugins /debug/ @skotopes @DrZlo13 @hedger diff --git a/ReadMe.md b/ReadMe.md index 0d4af0395..f3a350564 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -155,7 +155,7 @@ Connect your device via ST-Link and run: - `applications` - Applications and services used in firmware - `assets` - Assets used by applications and services -- `core` - Furi Core: os level primitives and helpers +- `furi` - Furi Core: os level primitives and helpers - `debug` - Debug tool: GDB-plugins, SVD-file and etc - `docker` - Docker image sources (used for firmware build automation) - `documentation` - Documentation generation system configs and input files diff --git a/applications/accessor/accessor_view_manager.cpp b/applications/accessor/accessor_view_manager.cpp index f54ad62f7..7c681cbba 100644 --- a/applications/accessor/accessor_view_manager.cpp +++ b/applications/accessor/accessor_view_manager.cpp @@ -3,7 +3,7 @@ #include AccessorAppViewManager::AccessorAppViewManager() { - event_queue = osMessageQueueNew(10, sizeof(AccessorEvent), NULL); + event_queue = furi_message_queue_alloc(10, sizeof(AccessorEvent)); view_dispatcher = view_dispatcher_alloc(); auto callback = cbc::obtain_connector(this, &AccessorAppViewManager::previous_view_callback); @@ -38,7 +38,7 @@ AccessorAppViewManager::~AccessorAppViewManager() { view_dispatcher_free(view_dispatcher); // free event queue - osMessageQueueDelete(event_queue); + furi_message_queue_free(event_queue); } void AccessorAppViewManager::switch_to(ViewType type) { @@ -54,14 +54,14 @@ Popup* AccessorAppViewManager::get_popup() { } void AccessorAppViewManager::receive_event(AccessorEvent* event) { - if(osMessageQueueGet(event_queue, event, NULL, 100) != osOK) { + if(furi_message_queue_get(event_queue, event, 100) != FuriStatusOk) { event->type = AccessorEvent::Type::Tick; } } void AccessorAppViewManager::send_event(AccessorEvent* event) { - osStatus_t result = osMessageQueuePut(event_queue, event, 0, 0); - furi_check(result == osOK); + FuriStatus result = furi_message_queue_put(event_queue, event, 0); + furi_check(result == FuriStatusOk); } uint32_t AccessorAppViewManager::previous_view_callback(void*) { diff --git a/applications/accessor/accessor_view_manager.h b/applications/accessor/accessor_view_manager.h index f2c6f2bb2..8cd437797 100644 --- a/applications/accessor/accessor_view_manager.h +++ b/applications/accessor/accessor_view_manager.h @@ -13,7 +13,7 @@ public: Tune, }; - osMessageQueueId_t event_queue; + FuriMessageQueue* event_queue; AccessorAppViewManager(); ~AccessorAppViewManager(); diff --git a/applications/archive/helpers/archive_browser.c b/applications/archive/helpers/archive_browser.c index 3e4d67311..282841365 100644 --- a/applications/archive/helpers/archive_browser.c +++ b/applications/archive/helpers/archive_browser.c @@ -2,8 +2,8 @@ #include "archive_files.h" #include "archive_apps.h" #include "archive_browser.h" -#include "furi/common_defines.h" -#include "furi/log.h" +#include +#include #include "gui/modules/file_browser_worker.h" #include "m-string.h" #include diff --git a/applications/bad_usb/bad_usb_script.c b/applications/bad_usb/bad_usb_script.c index 322a72921..a06f6d593 100644 --- a/applications/bad_usb/bad_usb_script.c +++ b/applications/bad_usb/bad_usb_script.c @@ -485,8 +485,8 @@ static int32_t bad_usb_worker(void* context) { } else if(worker_state == BadUsbStateNotConnected) { // State: USB not connected uint32_t flags = furi_thread_flags_wait( - WorkerEvtEnd | WorkerEvtConnect, osFlagsWaitAny, osWaitForever); - furi_check((flags & osFlagsError) == 0); + WorkerEvtEnd | WorkerEvtConnect, FuriFlagWaitAny, FuriWaitForever); + furi_check((flags & FuriFlagError) == 0); if(flags & WorkerEvtEnd) { break; } else if(flags & WorkerEvtConnect) { @@ -497,9 +497,9 @@ static int32_t bad_usb_worker(void* context) { } else if(worker_state == BadUsbStateIdle) { // State: ready to start uint32_t flags = furi_thread_flags_wait( WorkerEvtEnd | WorkerEvtToggle | WorkerEvtDisconnect, - osFlagsWaitAny, - osWaitForever); - furi_check((flags & osFlagsError) == 0); + FuriFlagWaitAny, + FuriWaitForever); + furi_check((flags & FuriFlagError) == 0); if(flags & WorkerEvtEnd) { break; } else if(flags & WorkerEvtToggle) { // Start executing script @@ -520,9 +520,9 @@ static int32_t bad_usb_worker(void* context) { } else if(worker_state == BadUsbStateRunning) { // State: running uint16_t delay_cur = (delay_val > 1000) ? (1000) : (delay_val); uint32_t flags = furi_thread_flags_wait( - WorkerEvtEnd | WorkerEvtToggle | WorkerEvtDisconnect, osFlagsWaitAny, delay_cur); + WorkerEvtEnd | WorkerEvtToggle | WorkerEvtDisconnect, FuriFlagWaitAny, delay_cur); delay_val -= delay_cur; - if(!(flags & osFlagsError)) { + if(!(flags & FuriFlagError)) { if(flags & WorkerEvtEnd) { break; } else if(flags & WorkerEvtToggle) { @@ -534,7 +534,7 @@ static int32_t bad_usb_worker(void* context) { } bad_usb->st.state = worker_state; continue; - } else if((flags == osFlagsErrorTimeout) || (flags == osFlagsErrorResource)) { + } else if((flags == FuriFlagErrorTimeout) || (flags == FuriFlagErrorResource)) { if(delay_val > 0) { bad_usb->st.delay_remain--; continue; @@ -556,15 +556,15 @@ static int32_t bad_usb_worker(void* context) { bad_usb->st.delay_remain = delay_val / 1000; } } else { - furi_check((flags & osFlagsError) == 0); + furi_check((flags & FuriFlagError) == 0); } } else if( (worker_state == BadUsbStateFileError) || (worker_state == BadUsbStateScriptError)) { // State: error uint32_t flags = furi_thread_flags_wait( - WorkerEvtEnd, osFlagsWaitAny, osWaitForever); // Waiting for exit command - furi_check((flags & osFlagsError) == 0); + WorkerEvtEnd, FuriFlagWaitAny, FuriWaitForever); // Waiting for exit command + furi_check((flags & FuriFlagError) == 0); if(flags & WorkerEvtEnd) { break; } diff --git a/applications/bt/bt_cli.c b/applications/bt/bt_cli.c index 98f73d229..d12724d2e 100644 --- a/applications/bt/bt_cli.c +++ b/applications/bt/bt_cli.c @@ -41,7 +41,7 @@ static void bt_cli_command_carrier_tx(Cli* cli, string_t args, void* context) { furi_hal_bt_start_tone_tx(channel, 0x19 + power); while(!cli_cmd_interrupt_received(cli)) { - osDelay(250); + furi_delay_ms(250); } furi_hal_bt_stop_tone_tx(); @@ -69,7 +69,7 @@ static void bt_cli_command_carrier_rx(Cli* cli, string_t args, void* context) { furi_hal_bt_start_packet_rx(channel, 1); while(!cli_cmd_interrupt_received(cli)) { - osDelay(250); + furi_delay_ms(250); printf("RSSI: %6.1f dB\r", (double)furi_hal_bt_get_rssi()); fflush(stdout); } @@ -119,7 +119,7 @@ static void bt_cli_command_packet_tx(Cli* cli, string_t args, void* context) { furi_hal_bt_start_packet_tx(channel, pattern, datarate); while(!cli_cmd_interrupt_received(cli)) { - osDelay(250); + furi_delay_ms(250); } furi_hal_bt_stop_packet_test(); printf("Transmitted %lu packets", furi_hal_bt_get_transmitted_packets()); @@ -152,7 +152,7 @@ static void bt_cli_command_packet_rx(Cli* cli, string_t args, void* context) { furi_hal_bt_start_packet_rx(channel, datarate); while(!cli_cmd_interrupt_received(cli)) { - osDelay(250); + furi_delay_ms(250); printf("RSSI: %03.1f dB\r", (double)furi_hal_bt_get_rssi()); fflush(stdout); } diff --git a/applications/bt/bt_debug_app/views/bt_carrier_test.c b/applications/bt/bt_debug_app/views/bt_carrier_test.c index 0e0b3792b..c09aa3fdf 100755 --- a/applications/bt/bt_debug_app/views/bt_carrier_test.c +++ b/applications/bt/bt_debug_app/views/bt_carrier_test.c @@ -9,7 +9,7 @@ struct BtCarrierTest { BtTestMode mode; BtTestChannel channel; BtTestPower power; - osTimerId_t timer; + FuriTimer* timer; }; static BtTestParamValue bt_param_mode[] = { @@ -35,10 +35,10 @@ static void bt_carrier_test_start(BtCarrierTest* bt_carrier_test) { furi_assert(bt_carrier_test); if(bt_carrier_test->mode == BtTestModeRx) { furi_hal_bt_start_packet_rx(bt_carrier_test->channel, 1); - osTimerStart(bt_carrier_test->timer, osKernelGetTickFreq() / 4); + furi_timer_start(bt_carrier_test->timer, furi_kernel_get_tick_frequency() / 4); } else if(bt_carrier_test->mode == BtTestModeTxHopping) { furi_hal_bt_start_tone_tx(bt_carrier_test->channel, bt_carrier_test->power); - osTimerStart(bt_carrier_test->timer, osKernelGetTickFreq() * 2); + furi_timer_start(bt_carrier_test->timer, furi_kernel_get_tick_frequency() * 2); } else if(bt_carrier_test->mode == BtTestModeTx) { furi_hal_bt_start_tone_tx(bt_carrier_test->channel, bt_carrier_test->power); } @@ -68,12 +68,12 @@ static void bt_carrier_test_stop(BtCarrierTest* bt_carrier_test) { furi_assert(bt_carrier_test); if(bt_carrier_test->mode == BtTestModeTxHopping) { furi_hal_bt_stop_tone_tx(); - osTimerStop(bt_carrier_test->timer); + furi_timer_stop(bt_carrier_test->timer); } else if(bt_carrier_test->mode == BtTestModeTx) { furi_hal_bt_stop_tone_tx(); } else if(bt_carrier_test->mode == BtTestModeRx) { furi_hal_bt_stop_packet_test(); - osTimerStop(bt_carrier_test->timer); + furi_timer_stop(bt_carrier_test->timer); } } @@ -170,7 +170,7 @@ BtCarrierTest* bt_carrier_test_alloc() { bt_carrier_test->power = BtPower0dB; bt_carrier_test->timer = - osTimerNew(bt_test_carrier_timer_callback, osTimerPeriodic, bt_carrier_test, NULL); + furi_timer_alloc(bt_test_carrier_timer_callback, FuriTimerTypePeriodic, bt_carrier_test); return bt_carrier_test; } @@ -178,7 +178,7 @@ BtCarrierTest* bt_carrier_test_alloc() { void bt_carrier_test_free(BtCarrierTest* bt_carrier_test) { furi_assert(bt_carrier_test); bt_test_free(bt_carrier_test->bt_test); - osTimerDelete(bt_carrier_test->timer); + furi_timer_free(bt_carrier_test->timer); free(bt_carrier_test); } diff --git a/applications/bt/bt_debug_app/views/bt_packet_test.c b/applications/bt/bt_debug_app/views/bt_packet_test.c index e9b3bd757..7cbc3c5c5 100644 --- a/applications/bt/bt_debug_app/views/bt_packet_test.c +++ b/applications/bt/bt_debug_app/views/bt_packet_test.c @@ -8,7 +8,7 @@ struct BtPacketTest { BtTestMode mode; BtTestChannel channel; BtTestDataRate data_rate; - osTimerId_t timer; + FuriTimer* timer; }; static BtTestParamValue bt_param_mode[] = { @@ -31,7 +31,7 @@ static void bt_packet_test_start(BtPacketTest* bt_packet_test) { furi_assert(bt_packet_test); if(bt_packet_test->mode == BtTestModeRx) { furi_hal_bt_start_packet_rx(bt_packet_test->channel, bt_packet_test->data_rate); - osTimerStart(bt_packet_test->timer, osKernelGetTickFreq() / 4); + furi_timer_start(bt_packet_test->timer, furi_kernel_get_tick_frequency() / 4); } else if(bt_packet_test->mode == BtTestModeTx) { furi_hal_bt_start_packet_tx(bt_packet_test->channel, 1, bt_packet_test->data_rate); } @@ -44,7 +44,7 @@ static void bt_packet_test_stop(BtPacketTest* bt_packet_test) { bt_test_set_packets_tx(bt_packet_test->bt_test, furi_hal_bt_get_transmitted_packets()); } else if(bt_packet_test->mode == BtTestModeRx) { bt_test_set_packets_rx(bt_packet_test->bt_test, furi_hal_bt_stop_packet_test()); - osTimerStop(bt_packet_test->timer); + furi_timer_stop(bt_packet_test->timer); } } @@ -137,7 +137,7 @@ BtPacketTest* bt_packet_test_alloc() { bt_packet_test->data_rate = BtDataRate1M; bt_packet_test->timer = - osTimerNew(bt_test_packet_timer_callback, osTimerPeriodic, bt_packet_test, NULL); + furi_timer_alloc(bt_test_packet_timer_callback, FuriTimerTypePeriodic, bt_packet_test); return bt_packet_test; } @@ -145,7 +145,7 @@ BtPacketTest* bt_packet_test_alloc() { void bt_packet_test_free(BtPacketTest* bt_packet_test) { furi_assert(bt_packet_test); bt_test_free(bt_packet_test->bt_test); - osTimerDelete(bt_packet_test->timer); + furi_timer_free(bt_packet_test->timer); free(bt_packet_test); } diff --git a/applications/bt/bt_service/bt.c b/applications/bt/bt_service/bt.c index f387ec6de..d122aa17b 100644 --- a/applications/bt/bt_service/bt.c +++ b/applications/bt/bt_service/bt.c @@ -96,12 +96,14 @@ static void bt_battery_level_changed_callback(const void* _event, void* context) if(event->type == PowerEventTypeBatteryLevelChanged) { message.type = BtMessageTypeUpdateBatteryLevel; message.data.battery_level = event->data.battery_level; - furi_check(osMessageQueuePut(bt->message_queue, &message, 0, osWaitForever) == osOK); + furi_check( + furi_message_queue_put(bt->message_queue, &message, FuriWaitForever) == FuriStatusOk); } else if( event->type == PowerEventTypeStartCharging || event->type == PowerEventTypeFullyCharged || event->type == PowerEventTypeStopCharging) { message.type = BtMessageTypeUpdatePowerState; - furi_check(osMessageQueuePut(bt->message_queue, &message, 0, osWaitForever) == osOK); + furi_check( + furi_message_queue_put(bt->message_queue, &message, FuriWaitForever) == FuriStatusOk); } } @@ -115,7 +117,7 @@ Bt* bt_alloc() { bt_settings_save(&bt->bt_settings); } // Alloc queue - bt->message_queue = osMessageQueueNew(8, sizeof(BtMessage), NULL); + bt->message_queue = furi_message_queue_alloc(8, sizeof(BtMessage)); // Setup statusbar view port bt->statusbar_view_port = bt_statusbar_view_port_alloc(bt); @@ -139,10 +141,10 @@ Bt* bt_alloc() { // RPC bt->rpc = furi_record_open("rpc"); - bt->rpc_event = osEventFlagsNew(NULL); + bt->rpc_event = furi_event_flag_alloc(); // API evnent - bt->api_event = osEventFlagsNew(NULL); + bt->api_event = furi_event_flag_alloc(); return bt; } @@ -162,7 +164,7 @@ static uint16_t bt_serial_event_callback(SerialServiceEvent event, void* context } ret = rpc_session_get_available_size(bt->rpc_session); } else if(event.event == SerialServiceEventTypeDataSent) { - osEventFlagsSet(bt->rpc_event, BT_RPC_EVENT_BUFF_SENT); + furi_event_flag_set(bt->rpc_event, BT_RPC_EVENT_BUFF_SENT); } return ret; } @@ -172,11 +174,11 @@ static void bt_rpc_send_bytes_callback(void* context, uint8_t* bytes, size_t byt furi_assert(context); Bt* bt = context; - if(osEventFlagsGet(bt->rpc_event) & BT_RPC_EVENT_DISCONNECTED) { + if(furi_event_flag_get(bt->rpc_event) & BT_RPC_EVENT_DISCONNECTED) { // Early stop from sending if we're already disconnected return; } - osEventFlagsClear(bt->rpc_event, BT_RPC_EVENT_ALL & (~BT_RPC_EVENT_DISCONNECTED)); + furi_event_flag_clear(bt->rpc_event, BT_RPC_EVENT_ALL & (~BT_RPC_EVENT_DISCONNECTED)); size_t bytes_sent = 0; while(bytes_sent < bytes_len) { size_t bytes_remain = bytes_len - bytes_sent; @@ -188,13 +190,13 @@ static void bt_rpc_send_bytes_callback(void* context, uint8_t* bytes, size_t byt bytes_sent += bytes_remain; } // We want BT_RPC_EVENT_DISCONNECTED to stick, so don't clear - uint32_t event_flag = osEventFlagsWait( - bt->rpc_event, BT_RPC_EVENT_ALL, osFlagsWaitAny | osFlagsNoClear, osWaitForever); + uint32_t event_flag = furi_event_flag_wait( + bt->rpc_event, BT_RPC_EVENT_ALL, FuriFlagWaitAny | FuriFlagNoClear, FuriWaitForever); if(event_flag & BT_RPC_EVENT_DISCONNECTED) { break; } else { // If we didn't get BT_RPC_EVENT_DISCONNECTED, then clear everything else - osEventFlagsClear(bt->rpc_event, BT_RPC_EVENT_ALL & (~BT_RPC_EVENT_DISCONNECTED)); + furi_event_flag_clear(bt->rpc_event, BT_RPC_EVENT_ALL & (~BT_RPC_EVENT_DISCONNECTED)); } } } @@ -209,9 +211,10 @@ static bool bt_on_gap_event_callback(GapEvent event, void* context) { // Update status bar bt->status = BtStatusConnected; BtMessage message = {.type = BtMessageTypeUpdateStatus}; - furi_check(osMessageQueuePut(bt->message_queue, &message, 0, osWaitForever) == osOK); + furi_check( + furi_message_queue_put(bt->message_queue, &message, FuriWaitForever) == FuriStatusOk); // Clear BT_RPC_EVENT_DISCONNECTED because it might be set from previous session - osEventFlagsClear(bt->rpc_event, BT_RPC_EVENT_DISCONNECTED); + furi_event_flag_clear(bt->rpc_event, BT_RPC_EVENT_DISCONNECTED); if(bt->profile == BtProfileSerial) { // Open RPC session bt->rpc_session = rpc_session_open(bt->rpc); @@ -232,12 +235,13 @@ static bool bt_on_gap_event_callback(GapEvent event, void* context) { power_get_info(bt->power, &info); message.type = BtMessageTypeUpdateBatteryLevel; message.data.battery_level = info.charge; - furi_check(osMessageQueuePut(bt->message_queue, &message, 0, osWaitForever) == osOK); + furi_check( + furi_message_queue_put(bt->message_queue, &message, FuriWaitForever) == FuriStatusOk); ret = true; } else if(event.type == GapEventTypeDisconnected) { if(bt->profile == BtProfileSerial && bt->rpc_session) { FURI_LOG_I(TAG, "Close RPC connection"); - osEventFlagsSet(bt->rpc_event, BT_RPC_EVENT_DISCONNECTED); + furi_event_flag_set(bt->rpc_event, BT_RPC_EVENT_DISCONNECTED); rpc_session_close(bt->rpc_session); furi_hal_bt_serial_set_event_callback(0, NULL, NULL); bt->rpc_session = NULL; @@ -246,17 +250,20 @@ static bool bt_on_gap_event_callback(GapEvent event, void* context) { } else if(event.type == GapEventTypeStartAdvertising) { bt->status = BtStatusAdvertising; BtMessage message = {.type = BtMessageTypeUpdateStatus}; - furi_check(osMessageQueuePut(bt->message_queue, &message, 0, osWaitForever) == osOK); + furi_check( + furi_message_queue_put(bt->message_queue, &message, FuriWaitForever) == FuriStatusOk); ret = true; } else if(event.type == GapEventTypeStopAdvertising) { bt->status = BtStatusOff; BtMessage message = {.type = BtMessageTypeUpdateStatus}; - furi_check(osMessageQueuePut(bt->message_queue, &message, 0, osWaitForever) == osOK); + furi_check( + furi_message_queue_put(bt->message_queue, &message, FuriWaitForever) == FuriStatusOk); ret = true; } else if(event.type == GapEventTypePinCodeShow) { BtMessage message = { .type = BtMessageTypePinCodeShow, .data.pin_code = event.data.pin_code}; - furi_check(osMessageQueuePut(bt->message_queue, &message, 0, osWaitForever) == osOK); + furi_check( + furi_message_queue_put(bt->message_queue, &message, FuriWaitForever) == FuriStatusOk); ret = true; } else if(event.type == GapEventTypePinCodeVerify) { ret = bt_pin_code_verify_event_handler(bt, event.data.pin_code); @@ -272,7 +279,8 @@ static void bt_on_key_storage_change_callback(uint8_t* addr, uint16_t size, void Bt* bt = context; FURI_LOG_I(TAG, "Changed addr start: %08lX, size changed: %d", addr, size); BtMessage message = {.type = BtMessageTypeKeysStorageUpdated}; - furi_check(osMessageQueuePut(bt->message_queue, &message, 0, osWaitForever) == osOK); + furi_check( + furi_message_queue_put(bt->message_queue, &message, FuriWaitForever) == FuriStatusOk); } static void bt_statusbar_update(Bt* bt) { @@ -296,7 +304,7 @@ static void bt_show_warning(Bt* bt, const char* text) { static void bt_close_rpc_connection(Bt* bt) { if(bt->profile == BtProfileSerial && bt->rpc_session) { FURI_LOG_I(TAG, "Close RPC connection"); - osEventFlagsSet(bt->rpc_event, BT_RPC_EVENT_DISCONNECTED); + furi_event_flag_set(bt->rpc_event, BT_RPC_EVENT_DISCONNECTED); rpc_session_close(bt->rpc_session); furi_hal_bt_serial_set_event_callback(0, NULL, NULL); bt->rpc_session = NULL; @@ -331,12 +339,12 @@ static void bt_change_profile(Bt* bt, BtMessage* message) { bt_show_warning(bt, "Radio stack doesn't support this app"); *message->result = false; } - osEventFlagsSet(bt->api_event, BT_API_UNLOCK_EVENT); + furi_event_flag_set(bt->api_event, BT_API_UNLOCK_EVENT); } static void bt_close_connection(Bt* bt) { bt_close_rpc_connection(bt); - osEventFlagsSet(bt->api_event, BT_API_UNLOCK_EVENT); + furi_event_flag_set(bt->api_event, BT_API_UNLOCK_EVENT); } int32_t bt_srv() { @@ -377,7 +385,8 @@ int32_t bt_srv() { BtMessage message; while(1) { - furi_check(osMessageQueueGet(bt->message_queue, &message, NULL, osWaitForever) == osOK); + furi_check( + furi_message_queue_get(bt->message_queue, &message, FuriWaitForever) == FuriStatusOk); if(message.type == BtMessageTypeUpdateStatus) { // Update view ports bt_statusbar_update(bt); diff --git a/applications/bt/bt_service/bt_api.c b/applications/bt/bt_service/bt_api.c old mode 100755 new mode 100644 index 884ec4a91..3de896d5a --- a/applications/bt/bt_service/bt_api.c +++ b/applications/bt/bt_service/bt_api.c @@ -7,9 +7,10 @@ bool bt_set_profile(Bt* bt, BtProfile profile) { bool result = false; BtMessage message = { .type = BtMessageTypeSetProfile, .data.profile = profile, .result = &result}; - furi_check(osMessageQueuePut(bt->message_queue, &message, 0, osWaitForever) == osOK); + furi_check( + furi_message_queue_put(bt->message_queue, &message, FuriWaitForever) == FuriStatusOk); // Wait for unlock - osEventFlagsWait(bt->api_event, BT_API_UNLOCK_EVENT, osFlagsWaitAny, osWaitForever); + furi_event_flag_wait(bt->api_event, BT_API_UNLOCK_EVENT, FuriFlagWaitAny, FuriWaitForever); return result; } @@ -19,9 +20,10 @@ void bt_disconnect(Bt* bt) { // Send message BtMessage message = {.type = BtMessageTypeDisconnect}; - furi_check(osMessageQueuePut(bt->message_queue, &message, 0, osWaitForever) == osOK); + furi_check( + furi_message_queue_put(bt->message_queue, &message, FuriWaitForever) == FuriStatusOk); // Wait for unlock - osEventFlagsWait(bt->api_event, BT_API_UNLOCK_EVENT, osFlagsWaitAny, osWaitForever); + furi_event_flag_wait(bt->api_event, BT_API_UNLOCK_EVENT, FuriFlagWaitAny, FuriWaitForever); } void bt_set_status_changed_callback(Bt* bt, BtStatusChangedCallback callback, void* context) { @@ -34,5 +36,6 @@ void bt_set_status_changed_callback(Bt* bt, BtStatusChangedCallback callback, vo void bt_forget_bonded_devices(Bt* bt) { furi_assert(bt); BtMessage message = {.type = BtMessageTypeForgetBondedDevices}; - furi_check(osMessageQueuePut(bt->message_queue, &message, 0, osWaitForever) == osOK); + furi_check( + furi_message_queue_put(bt->message_queue, &message, FuriWaitForever) == FuriStatusOk); } diff --git a/applications/bt/bt_service/bt_i.h b/applications/bt/bt_service/bt_i.h index 90ee08512..a45a36c9e 100644 --- a/applications/bt/bt_service/bt_i.h +++ b/applications/bt/bt_service/bt_i.h @@ -48,7 +48,7 @@ struct Bt { BtSettings bt_settings; BtStatus status; BtProfile profile; - osMessageQueueId_t message_queue; + FuriMessageQueue* message_queue; NotificationApp* notification; Gui* gui; ViewPort* statusbar_view_port; @@ -59,8 +59,8 @@ struct Bt { Power* power; Rpc* rpc; RpcSession* rpc_session; - osEventFlagsId_t rpc_event; - osEventFlagsId_t api_event; + FuriEventFlag* rpc_event; + FuriEventFlag* api_event; BtStatusChangedCallback status_changed_cb; void* status_changed_ctx; }; diff --git a/applications/cli/cli.c b/applications/cli/cli.c index 35baad7eb..a0b239d30 100644 --- a/applications/cli/cli.c +++ b/applications/cli/cli.c @@ -16,10 +16,10 @@ Cli* cli_alloc() { cli->session = NULL; - cli->mutex = osMutexNew(NULL); + cli->mutex = furi_mutex_alloc(FuriMutexTypeNormal); furi_check(cli->mutex); - cli->idle_sem = osSemaphoreNew(1, 0, NULL); + cli->idle_sem = furi_semaphore_alloc(1, 0); return cli; } @@ -35,7 +35,7 @@ char cli_getc(Cli* cli) { furi_assert(cli); char c = 0; if(cli->session != NULL) { - if(cli->session->rx((uint8_t*)&c, 1, osWaitForever) == 0) { + if(cli->session->rx((uint8_t*)&c, 1, FuriWaitForever) == 0) { cli_reset(cli); } } else { @@ -54,7 +54,7 @@ void cli_write(Cli* cli, const uint8_t* buffer, size_t size) { size_t cli_read(Cli* cli, uint8_t* buffer, size_t size) { furi_assert(cli); if(cli->session != NULL) { - return cli->session->rx(buffer, size, osWaitForever); + return cli->session->rx(buffer, size, FuriWaitForever); } else { return 0; } @@ -228,17 +228,17 @@ static void cli_handle_enter(Cli* cli) { } // Search for command - furi_check(osMutexAcquire(cli->mutex, osWaitForever) == osOK); + furi_check(furi_mutex_acquire(cli->mutex, FuriWaitForever) == FuriStatusOk); CliCommand* cli_command_ptr = CliCommandTree_get(cli->commands, command); if(cli_command_ptr) { CliCommand cli_command; memcpy(&cli_command, cli_command_ptr, sizeof(CliCommand)); - furi_check(osMutexRelease(cli->mutex) == osOK); + furi_check(furi_mutex_release(cli->mutex) == FuriStatusOk); cli_nl(cli); cli_execute_command(cli, &cli_command, args); } else { - furi_check(osMutexRelease(cli->mutex) == osOK); + furi_check(furi_mutex_release(cli->mutex) == FuriStatusOk); cli_nl(cli); printf( "`%s` command not found, use `help` or `?` to list all available commands", @@ -339,7 +339,7 @@ void cli_process_input(Cli* cli) { if(in_chr == CliSymbolAsciiTab) { cli_handle_autocomplete(cli); } else if(in_chr == CliSymbolAsciiSOH) { - osDelay(33); // We are too fast, Minicom is not ready yet + furi_delay_ms(33); // We are too fast, Minicom is not ready yet cli_motd(); cli_prompt(cli); } else if(in_chr == CliSymbolAsciiETX) { @@ -406,9 +406,9 @@ void cli_add_command( c.context = context; c.flags = flags; - furi_check(osMutexAcquire(cli->mutex, osWaitForever) == osOK); + furi_check(furi_mutex_acquire(cli->mutex, FuriWaitForever) == FuriStatusOk); CliCommandTree_set_at(cli->commands, name_str, c); - furi_check(osMutexRelease(cli->mutex) == osOK); + furi_check(furi_mutex_release(cli->mutex) == FuriStatusOk); string_clear(name_str); } @@ -423,9 +423,9 @@ void cli_delete_command(Cli* cli, const char* name) { name_replace = string_replace_str(name_str, " ", "_"); } while(name_replace != STRING_FAILURE); - furi_check(osMutexAcquire(cli->mutex, osWaitForever) == osOK); + furi_check(furi_mutex_acquire(cli->mutex, FuriWaitForever) == FuriStatusOk); CliCommandTree_erase(cli->commands, name_str); - furi_check(osMutexRelease(cli->mutex) == osOK); + furi_check(furi_mutex_release(cli->mutex) == FuriStatusOk); string_clear(name_str); } @@ -433,7 +433,7 @@ void cli_delete_command(Cli* cli, const char* name) { void cli_session_open(Cli* cli, void* session) { furi_assert(cli); - furi_check(osMutexAcquire(cli->mutex, osWaitForever) == osOK); + furi_check(furi_mutex_acquire(cli->mutex, FuriWaitForever) == FuriStatusOk); cli->session = session; if(cli->session != NULL) { cli->session->init(); @@ -441,20 +441,20 @@ void cli_session_open(Cli* cli, void* session) { } else { furi_stdglue_set_thread_stdout_callback(NULL); } - osSemaphoreRelease(cli->idle_sem); - furi_check(osMutexRelease(cli->mutex) == osOK); + furi_semaphore_release(cli->idle_sem); + furi_check(furi_mutex_release(cli->mutex) == FuriStatusOk); } void cli_session_close(Cli* cli) { furi_assert(cli); - furi_check(osMutexAcquire(cli->mutex, osWaitForever) == osOK); + furi_check(furi_mutex_acquire(cli->mutex, FuriWaitForever) == FuriStatusOk); if(cli->session != NULL) { cli->session->deinit(); } cli->session = NULL; furi_stdglue_set_thread_stdout_callback(NULL); - furi_check(osMutexRelease(cli->mutex) == osOK); + furi_check(furi_mutex_release(cli->mutex) == FuriStatusOk); } int32_t cli_srv(void* p) { @@ -482,7 +482,7 @@ int32_t cli_srv(void* p) { if(cli->session != NULL) { cli_process_input(cli); } else { - furi_check(osSemaphoreAcquire(cli->idle_sem, osWaitForever) == osOK); + furi_check(furi_semaphore_acquire(cli->idle_sem, FuriWaitForever) == FuriStatusOk); } } diff --git a/applications/cli/cli_i.h b/applications/cli/cli_i.h index feb3bcb72..076dd75ed 100755 --- a/applications/cli/cli_i.h +++ b/applications/cli/cli_i.h @@ -41,8 +41,8 @@ BPTREE_DEF2( struct Cli { CliCommandTree_t commands; - osMutexId_t mutex; - osSemaphoreId_t idle_sem; + FuriMutex* mutex; + FuriSemaphore* idle_sem; string_t last_line; string_t line; CliSession* session; diff --git a/applications/cli/cli_vcp.c b/applications/cli/cli_vcp.c index 332dd7cba..5d66b8f8d 100644 --- a/applications/cli/cli_vcp.c +++ b/applications/cli/cli_vcp.c @@ -103,8 +103,8 @@ static int32_t vcp_worker(void* context) { while(1) { uint32_t flags = - furi_thread_flags_wait(VCP_THREAD_FLAG_ALL, osFlagsWaitAny, osWaitForever); - furi_assert((flags & osFlagsError) == 0); + furi_thread_flags_wait(VCP_THREAD_FLAG_ALL, FuriFlagWaitAny, FuriWaitForever); + furi_assert((flags & FuriFlagError) == 0); // VCP session opened if(flags & VcpEvtConnect) { @@ -113,7 +113,7 @@ static int32_t vcp_worker(void* context) { #endif if(vcp->connected == false) { vcp->connected = true; - xStreamBufferSend(vcp->rx_stream, &ascii_soh, 1, osWaitForever); + xStreamBufferSend(vcp->rx_stream, &ascii_soh, 1, FuriWaitForever); } } @@ -125,7 +125,7 @@ static int32_t vcp_worker(void* context) { if(vcp->connected == true) { vcp->connected = false; xStreamBufferReceive(vcp->tx_stream, vcp->data_buffer, USB_CDC_PKT_LEN, 0); - xStreamBufferSend(vcp->rx_stream, &ascii_eot, 1, osWaitForever); + xStreamBufferSend(vcp->rx_stream, &ascii_eot, 1, FuriWaitForever); } } @@ -149,7 +149,7 @@ static int32_t vcp_worker(void* context) { #endif if(len > 0) { furi_check( - xStreamBufferSend(vcp->rx_stream, vcp->data_buffer, len, osWaitForever) == + xStreamBufferSend(vcp->rx_stream, vcp->data_buffer, len, FuriWaitForever) == (size_t)len); } } else { @@ -203,7 +203,7 @@ static int32_t vcp_worker(void* context) { furi_hal_usb_set_config(vcp->usb_if_prev, NULL); } xStreamBufferReceive(vcp->tx_stream, vcp->data_buffer, USB_CDC_PKT_LEN, 0); - xStreamBufferSend(vcp->rx_stream, &ascii_eot, 1, osWaitForever); + xStreamBufferSend(vcp->rx_stream, &ascii_eot, 1, FuriWaitForever); break; } } @@ -262,7 +262,7 @@ static void cli_vcp_tx(const uint8_t* buffer, size_t size) { size_t batch_size = size; if(batch_size > USB_CDC_PKT_LEN) batch_size = USB_CDC_PKT_LEN; - xStreamBufferSend(vcp->tx_stream, buffer, batch_size, osWaitForever); + xStreamBufferSend(vcp->tx_stream, buffer, batch_size, FuriWaitForever); furi_thread_flags_set(furi_thread_get_id(vcp->thread), VcpEvtStreamTx); #ifdef CLI_VCP_DEBUG FURI_LOG_D(TAG, "tx %u", batch_size); @@ -304,7 +304,7 @@ static void vcp_on_cdc_control_line(void* context, uint8_t state) { static void vcp_on_cdc_rx(void* context) { UNUSED(context); uint32_t ret = furi_thread_flags_set(furi_thread_get_id(vcp->thread), VcpEvtRx); - furi_check((ret & osFlagsError) == 0); + furi_check((ret & FuriFlagError) == 0); } static void vcp_on_cdc_tx_complete(void* context) { diff --git a/applications/debug_tools/blink_test.c b/applications/debug_tools/blink_test.c index 68139a431..3870c11e1 100644 --- a/applications/debug_tools/blink_test.c +++ b/applications/debug_tools/blink_test.c @@ -1,4 +1,4 @@ -#include "furi/common_defines.h" +#include #include #include @@ -55,10 +55,10 @@ static const NotificationSequence* blink_test_colors[] = { static void blink_test_update(void* ctx) { furi_assert(ctx); - osMessageQueueId_t event_queue = ctx; + FuriMessageQueue* event_queue = ctx; BlinkEvent event = {.type = BlinkEventTypeTick}; // It's OK to loose this event if system overloaded - osMessageQueuePut(event_queue, &event, 0, 0); + furi_message_queue_put(event_queue, &event, 0); } static void blink_test_draw_callback(Canvas* canvas, void* ctx) { @@ -70,22 +70,22 @@ static void blink_test_draw_callback(Canvas* canvas, void* ctx) { static void blink_test_input_callback(InputEvent* input_event, void* ctx) { furi_assert(ctx); - osMessageQueueId_t event_queue = ctx; + FuriMessageQueue* event_queue = ctx; BlinkEvent event = {.type = BlinkEventTypeInput, .input = *input_event}; - osMessageQueuePut(event_queue, &event, 0, osWaitForever); + furi_message_queue_put(event_queue, &event, FuriWaitForever); } int32_t blink_test_app(void* p) { UNUSED(p); - osMessageQueueId_t event_queue = osMessageQueueNew(8, sizeof(BlinkEvent), NULL); + FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(BlinkEvent)); // Configure view port ViewPort* view_port = view_port_alloc(); view_port_draw_callback_set(view_port, blink_test_draw_callback, NULL); view_port_input_callback_set(view_port, blink_test_input_callback, event_queue); - osTimerId_t timer = osTimerNew(blink_test_update, osTimerPeriodic, event_queue, NULL); - osTimerStart(timer, osKernelGetTickFreq()); + FuriTimer* timer = furi_timer_alloc(blink_test_update, FuriTimerTypePeriodic, event_queue); + furi_timer_start(timer, furi_kernel_get_tick_frequency()); // Register view port in GUI Gui* gui = furi_record_open("gui"); @@ -97,7 +97,7 @@ int32_t blink_test_app(void* p) { BlinkEvent event; while(1) { - furi_check(osMessageQueueGet(event_queue, &event, NULL, osWaitForever) == osOK); + furi_check(furi_message_queue_get(event_queue, &event, FuriWaitForever) == FuriStatusOk); if(event.type == BlinkEventTypeInput) { if((event.input.type == InputTypeShort) && (event.input.key == InputKeyBack)) { break; @@ -113,11 +113,11 @@ int32_t blink_test_app(void* p) { notification_message(notifications, &blink_test_sequence_hw_blink_stop); - osTimerDelete(timer); + furi_timer_free(timer); gui_remove_view_port(gui, view_port); view_port_free(view_port); - osMessageQueueDelete(event_queue); + furi_message_queue_free(event_queue); furi_record_close("notification"); furi_record_close("gui"); diff --git a/applications/debug_tools/display_test/view_display_test.c b/applications/debug_tools/display_test/view_display_test.c index 133195d0f..f00fe0094 100644 --- a/applications/debug_tools/display_test/view_display_test.c +++ b/applications/debug_tools/display_test/view_display_test.c @@ -9,7 +9,7 @@ typedef struct { struct ViewDisplayTest { View* view; - osTimerId_t timer; + FuriTimer* timer; }; static void view_display_test_draw_callback_intro(Canvas* canvas, void* _model) { @@ -138,12 +138,12 @@ static bool view_display_test_input_callback(InputEvent* event, void* context) { static void view_display_test_enter(void* context) { ViewDisplayTest* instance = context; - osTimerStart(instance->timer, osKernelGetTickFreq() / 32); + furi_timer_start(instance->timer, furi_kernel_get_tick_frequency() / 32); } static void view_display_test_exit(void* context) { ViewDisplayTest* instance = context; - osTimerStop(instance->timer); + furi_timer_stop(instance->timer); } static void view_display_test_timer_callback(void* context) { @@ -167,7 +167,7 @@ ViewDisplayTest* view_display_test_alloc() { view_set_exit_callback(instance->view, view_display_test_exit); instance->timer = - osTimerNew(view_display_test_timer_callback, osTimerPeriodic, instance, NULL); + furi_timer_alloc(view_display_test_timer_callback, FuriTimerTypePeriodic, instance); return instance; } @@ -175,7 +175,7 @@ ViewDisplayTest* view_display_test_alloc() { void view_display_test_free(ViewDisplayTest* instance) { furi_assert(instance); - osTimerDelete(instance->timer); + furi_timer_free(instance->timer); view_free(instance->view); free(instance); } diff --git a/applications/debug_tools/file_browser_test/scenes/file_browser_scene_browser.c b/applications/debug_tools/file_browser_test/scenes/file_browser_scene_browser.c index ca16ad0d1..d9bd1ac53 100644 --- a/applications/debug_tools/file_browser_test/scenes/file_browser_scene_browser.c +++ b/applications/debug_tools/file_browser_test/scenes/file_browser_scene_browser.c @@ -1,6 +1,6 @@ #include "../file_browser_app_i.h" -#include "furi/check.h" -#include "furi/log.h" +#include +#include #include "furi_hal.h" #include "m-string.h" diff --git a/applications/debug_tools/keypad_test.c b/applications/debug_tools/keypad_test.c index 705a15426..9a6e7f25a 100644 --- a/applications/debug_tools/keypad_test.c +++ b/applications/debug_tools/keypad_test.c @@ -55,13 +55,13 @@ static void keypad_test_render_callback(Canvas* canvas, void* ctx) { } static void keypad_test_input_callback(InputEvent* input_event, void* ctx) { - osMessageQueueId_t event_queue = ctx; - osMessageQueuePut(event_queue, input_event, 0, osWaitForever); + FuriMessageQueue* event_queue = ctx; + furi_message_queue_put(event_queue, input_event, FuriWaitForever); } int32_t keypad_test_app(void* p) { UNUSED(p); - osMessageQueueId_t event_queue = osMessageQueueNew(32, sizeof(InputEvent), NULL); + FuriMessageQueue* event_queue = furi_message_queue_alloc(32, sizeof(InputEvent)); furi_check(event_queue); KeypadTestState _state = {{false, false, false, false, false}, 0, 0, 0, 0, 0}; @@ -82,7 +82,7 @@ int32_t keypad_test_app(void* p) { gui_add_view_port(gui, view_port, GuiLayerFullscreen); InputEvent event; - while(osMessageQueueGet(event_queue, &event, NULL, osWaitForever) == osOK) { + while(furi_message_queue_get(event_queue, &event, FuriWaitForever) == FuriStatusOk) { KeypadTestState* state = (KeypadTestState*)acquire_mutex_block(&state_mutex); FURI_LOG_I( TAG, @@ -146,7 +146,7 @@ int32_t keypad_test_app(void* p) { // remove & free all stuff created by app gui_remove_view_port(gui, view_port); view_port_free(view_port); - osMessageQueueDelete(event_queue); + furi_message_queue_free(event_queue); delete_mutex(&state_mutex); furi_record_close("gui"); diff --git a/applications/debug_tools/text_box_test.c b/applications/debug_tools/text_box_test.c index bc56e88b8..837c34b6a 100644 --- a/applications/debug_tools/text_box_test.c +++ b/applications/debug_tools/text_box_test.c @@ -65,13 +65,13 @@ static void text_box_test_render_callback(Canvas* canvas, void* ctx) { } static void text_box_test_input_callback(InputEvent* input_event, void* ctx) { - osMessageQueueId_t event_queue = ctx; - osMessageQueuePut(event_queue, input_event, 0, osWaitForever); + FuriMessageQueue* event_queue = ctx; + furi_message_queue_put(event_queue, input_event, FuriWaitForever); } int32_t text_box_test_app(void* p) { UNUSED(p); - osMessageQueueId_t event_queue = osMessageQueueNew(32, sizeof(InputEvent), NULL); + FuriMessageQueue* event_queue = furi_message_queue_alloc(32, sizeof(InputEvent)); furi_check(event_queue); TextBoxTestState _state = {.idx = 0}; @@ -93,7 +93,7 @@ int32_t text_box_test_app(void* p) { uint32_t test_renders_num = COUNT_OF(text_box_test_render); InputEvent event; - while(osMessageQueueGet(event_queue, &event, NULL, osWaitForever) == osOK) { + while(furi_message_queue_get(event_queue, &event, FuriWaitForever) == FuriStatusOk) { TextBoxTestState* state = acquire_mutex_block(&state_mutex); if(event.type == InputTypeShort) { @@ -118,7 +118,7 @@ int32_t text_box_test_app(void* p) { // remove & free all stuff created by app gui_remove_view_port(gui, view_port); view_port_free(view_port); - osMessageQueueDelete(event_queue); + furi_message_queue_free(event_queue); delete_mutex(&state_mutex); furi_record_close("gui"); diff --git a/applications/debug_tools/uart_echo.c b/applications/debug_tools/uart_echo.c index 213769a5e..8f795c56d 100644 --- a/applications/debug_tools/uart_echo.c +++ b/applications/debug_tools/uart_echo.c @@ -150,8 +150,8 @@ static int32_t uart_echo_worker(void* context) { while(1) { uint32_t events = - furi_thread_flags_wait(WORKER_EVENTS_MASK, osFlagsWaitAny, osWaitForever); - furi_check((events & osFlagsError) == 0); + furi_thread_flags_wait(WORKER_EVENTS_MASK, FuriFlagWaitAny, FuriWaitForever); + furi_check((events & FuriFlagError) == 0); if(events & WorkerEventStop) break; if(events & WorkerEventRx) { diff --git a/applications/debug_tools/usb_mouse.c b/applications/debug_tools/usb_mouse.c index a136375ac..3174ccae3 100644 --- a/applications/debug_tools/usb_mouse.c +++ b/applications/debug_tools/usb_mouse.c @@ -29,17 +29,17 @@ static void usb_mouse_render_callback(Canvas* canvas, void* ctx) { } static void usb_mouse_input_callback(InputEvent* input_event, void* ctx) { - osMessageQueueId_t event_queue = ctx; + FuriMessageQueue* event_queue = ctx; UsbMouseEvent event; event.type = EventTypeInput; event.input = *input_event; - osMessageQueuePut(event_queue, &event, 0, osWaitForever); + furi_message_queue_put(event_queue, &event, FuriWaitForever); } int32_t usb_mouse_app(void* p) { UNUSED(p); - osMessageQueueId_t event_queue = osMessageQueueNew(8, sizeof(UsbMouseEvent), NULL); + FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(UsbMouseEvent)); furi_check(event_queue); ViewPort* view_port = view_port_alloc(); @@ -56,9 +56,9 @@ int32_t usb_mouse_app(void* p) { UsbMouseEvent event; while(1) { - osStatus_t event_status = osMessageQueueGet(event_queue, &event, NULL, osWaitForever); + FuriStatus event_status = furi_message_queue_get(event_queue, &event, FuriWaitForever); - if(event_status == osOK) { + if(event_status == FuriStatusOk) { if(event.type == EventTypeInput) { if(event.input.type == InputTypeLong && event.input.key == InputKeyBack) { break; @@ -118,7 +118,7 @@ int32_t usb_mouse_app(void* p) { // remove & free all stuff created by app gui_remove_view_port(gui, view_port); view_port_free(view_port); - osMessageQueueDelete(event_queue); + furi_message_queue_free(event_queue); return 0; } diff --git a/applications/debug_tools/vibro_test.c b/applications/debug_tools/vibro_test.c index af6d336de..dbd35d601 100644 --- a/applications/debug_tools/vibro_test.c +++ b/applications/debug_tools/vibro_test.c @@ -18,13 +18,13 @@ void vibro_test_draw_callback(Canvas* canvas, void* ctx) { void vibro_test_input_callback(InputEvent* input_event, void* ctx) { furi_assert(ctx); - osMessageQueueId_t event_queue = ctx; - osMessageQueuePut(event_queue, input_event, 0, osWaitForever); + FuriMessageQueue* event_queue = ctx; + furi_message_queue_put(event_queue, input_event, FuriWaitForever); } int32_t vibro_test_app(void* p) { UNUSED(p); - osMessageQueueId_t event_queue = osMessageQueueNew(8, sizeof(InputEvent), NULL); + FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(InputEvent)); // Configure view port ViewPort* view_port = view_port_alloc(); @@ -39,7 +39,7 @@ int32_t vibro_test_app(void* p) { InputEvent event; - while(osMessageQueueGet(event_queue, &event, NULL, osWaitForever) == osOK) { + while(furi_message_queue_get(event_queue, &event, FuriWaitForever) == FuriStatusOk) { if(event.type == InputTypeShort && event.key == InputKeyBack) { notification_message(notification, &sequence_reset_vibro); notification_message(notification, &sequence_reset_green); @@ -58,7 +58,7 @@ int32_t vibro_test_app(void* p) { gui_remove_view_port(gui, view_port); view_port_free(view_port); - osMessageQueueDelete(event_queue); + furi_message_queue_free(event_queue); furi_record_close("notification"); furi_record_close("gui"); diff --git a/applications/desktop/animations/animation_manager.c b/applications/desktop/animations/animation_manager.c index 75d45ef7b..9b702811c 100644 --- a/applications/desktop/animations/animation_manager.c +++ b/applications/desktop/animations/animation_manager.c @@ -44,7 +44,7 @@ struct AnimationManager { FuriPubSubSubscription* pubsub_subscription_dolphin; BubbleAnimationView* animation_view; OneShotView* one_shot_view; - osTimerId_t idle_animation_timer; + FuriTimer* idle_animation_timer; StorageAnimation* current_animation; AnimationManagerInteractCallback interact_callback; AnimationManagerSetNewIdleAnimationCallback new_idle_callback; @@ -198,7 +198,7 @@ static void animation_manager_start_new_idle(AnimationManager* animation_manager const BubbleAnimation* bubble_animation = animation_storage_get_bubble_animation(animation_manager->current_animation); animation_manager->state = AnimationManagerStateIdle; - osTimerStart(animation_manager->idle_animation_timer, bubble_animation->duration * 1000); + furi_timer_start(animation_manager->idle_animation_timer, bubble_animation->duration * 1000); } static bool animation_manager_check_blocking(AnimationManager* animation_manager) { @@ -246,7 +246,7 @@ static bool animation_manager_check_blocking(AnimationManager* animation_manager } if(blocking_animation) { - osTimerStop(animation_manager->idle_animation_timer); + furi_timer_stop(animation_manager->idle_animation_timer); animation_manager_replace_current_animation(animation_manager, blocking_animation); /* no timer starting because this is blocking animation */ animation_manager->state = AnimationManagerStateBlocked; @@ -283,7 +283,7 @@ AnimationManager* animation_manager_alloc(void) { string_init(animation_manager->freezed_animation_name); animation_manager->idle_animation_timer = - osTimerNew(animation_manager_timer_callback, osTimerOnce, animation_manager, NULL); + furi_timer_alloc(animation_manager_timer_callback, FuriTimerTypeOnce, animation_manager); bubble_animation_view_set_interact_callback( animation_manager->animation_view, animation_manager_interact_callback, animation_manager); @@ -322,7 +322,7 @@ void animation_manager_free(AnimationManager* animation_manager) { View* animation_view = bubble_animation_get_view(animation_manager->animation_view); view_stack_remove_view(animation_manager->view_stack, animation_view); bubble_animation_view_free(animation_manager->animation_view); - osTimerDelete(animation_manager->idle_animation_timer); + furi_timer_free(animation_manager->idle_animation_timer); } View* animation_manager_get_animation_view(AnimationManager* animation_manager) { @@ -449,7 +449,7 @@ void animation_manager_unload_and_stall_animation(AnimationManager* animation_ma if(animation_manager->freezed_animation_time_left < 0) { animation_manager->freezed_animation_time_left = 0; } - osTimerStop(animation_manager->idle_animation_timer); + furi_timer_stop(animation_manager->idle_animation_timer); } else { furi_assert(0); } @@ -504,13 +504,13 @@ void animation_manager_load_and_continue_animation(AnimationManager* animation_m animation_manager->state = AnimationManagerStateIdle; if(animation_manager->freezed_animation_time_left) { - osTimerStart( + furi_timer_start( animation_manager->idle_animation_timer, animation_manager->freezed_animation_time_left); } else { const BubbleAnimation* animation = animation_storage_get_bubble_animation( animation_manager->current_animation); - osTimerStart( + furi_timer_start( animation_manager->idle_animation_timer, animation->duration * 1000); } } diff --git a/applications/desktop/animations/animation_storage.c b/applications/desktop/animations/animation_storage.c index 8f2740a7f..36b20bc87 100644 --- a/applications/desktop/animations/animation_storage.c +++ b/applications/desktop/animations/animation_storage.c @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/applications/desktop/animations/views/bubble_animation_view.c b/applications/desktop/animations/views/bubble_animation_view.c index 380664c8d..54a686fb1 100644 --- a/applications/desktop/animations/views/bubble_animation_view.c +++ b/applications/desktop/animations/views/bubble_animation_view.c @@ -11,9 +11,7 @@ #include #include #include -#include -#include -#include +#include #define ACTIVE_SHIFT 2 @@ -31,7 +29,7 @@ typedef struct { struct BubbleAnimationView { View* view; - osTimerId_t timer; + FuriTimer* timer; BubbleAnimationInteractCallback interact_callback; void* interact_callback_context; }; @@ -192,7 +190,7 @@ static void bubble_animation_activate_right_now(BubbleAnimationView* view) { view_commit_model(view->view, true); if(frame_rate) { - osTimerStart(view->timer, 1000 / frame_rate); + furi_timer_start(view->timer, 1000 / frame_rate); } } @@ -294,21 +292,21 @@ static void bubble_animation_enter(void* context) { view_commit_model(view->view, false); if(frame_rate) { - osTimerStart(view->timer, 1000 / frame_rate); + furi_timer_start(view->timer, 1000 / frame_rate); } } static void bubble_animation_exit(void* context) { furi_assert(context); BubbleAnimationView* view = context; - osTimerStop(view->timer); + furi_timer_stop(view->timer); } BubbleAnimationView* bubble_animation_view_alloc(void) { BubbleAnimationView* view = malloc(sizeof(BubbleAnimationView)); view->view = view_alloc(); view->interact_callback = NULL; - view->timer = osTimerNew(bubble_animation_timer_callback, osTimerPeriodic, view, NULL); + view->timer = furi_timer_alloc(bubble_animation_timer_callback, FuriTimerTypePeriodic, view); view_allocate_model(view->view, ViewModelTypeLocking, sizeof(BubbleAnimationViewModel)); view_set_context(view->view, view); @@ -369,7 +367,7 @@ void bubble_animation_view_set_animation( model->active_cycle = 0; view_commit_model(view->view, true); - osTimerStart(view->timer, 1000 / new_animation->icon_animation.frame_rate); + furi_timer_start(view->timer, 1000 / new_animation->icon_animation.frame_rate); } void bubble_animation_freeze(BubbleAnimationView* view) { @@ -381,7 +379,7 @@ void bubble_animation_freeze(BubbleAnimationView* view) { model->freeze_frame = bubble_animation_clone_first_frame(&model->current->icon_animation); model->current = NULL; view_commit_model(view->view, false); - osTimerStop(view->timer); + furi_timer_stop(view->timer); } void bubble_animation_unfreeze(BubbleAnimationView* view) { @@ -395,7 +393,7 @@ void bubble_animation_unfreeze(BubbleAnimationView* view) { frame_rate = model->current->icon_animation.frame_rate; view_commit_model(view->view, true); - osTimerStart(view->timer, 1000 / frame_rate); + furi_timer_start(view->timer, 1000 / frame_rate); bubble_animation_activate(view, false); } diff --git a/applications/desktop/desktop.c b/applications/desktop/desktop.c index 520917535..83b4f0f3f 100644 --- a/applications/desktop/desktop.c +++ b/applications/desktop/desktop.c @@ -93,12 +93,12 @@ static void desktop_auto_lock_timer_callback(void* context) { } static void desktop_start_auto_lock_timer(Desktop* desktop) { - osTimerStart( - desktop->auto_lock_timer, furi_hal_ms_to_ticks(desktop->settings.auto_lock_delay_ms)); + furi_timer_start( + desktop->auto_lock_timer, furi_ms_to_ticks(desktop->settings.auto_lock_delay_ms)); } static void desktop_stop_auto_lock_timer(Desktop* desktop) { - osTimerStop(desktop->auto_lock_timer); + furi_timer_stop(desktop->auto_lock_timer); } static void desktop_auto_lock_arm(Desktop* desktop) { @@ -232,7 +232,7 @@ Desktop* desktop_alloc() { desktop->input_events_subscription = NULL; desktop->auto_lock_timer = - osTimerNew(desktop_auto_lock_timer_callback, osTimerOnce, desktop, NULL); + furi_timer_alloc(desktop_auto_lock_timer_callback, FuriTimerTypeOnce, desktop); return desktop; } @@ -283,7 +283,7 @@ void desktop_free(Desktop* desktop) { furi_record_close("menu"); - osTimerDelete(desktop->auto_lock_timer); + furi_timer_free(desktop->auto_lock_timer); free(desktop); } diff --git a/applications/desktop/desktop_i.h b/applications/desktop/desktop_i.h index 8dc92e849..0b5d607d1 100644 --- a/applications/desktop/desktop_i.h +++ b/applications/desktop/desktop_i.h @@ -67,7 +67,7 @@ struct Desktop { FuriPubSubSubscription* app_start_stop_subscription; FuriPubSub* input_events_pubsub; FuriPubSubSubscription* input_events_subscription; - osTimerId_t auto_lock_timer; + FuriTimer* auto_lock_timer; }; Desktop* desktop_alloc(); diff --git a/applications/desktop/desktop_settings/scenes/desktop_settings_scene_pin_auth.c b/applications/desktop/desktop_settings/scenes/desktop_settings_scene_pin_auth.c index 54330c74f..c43fff6ad 100644 --- a/applications/desktop/desktop_settings/scenes/desktop_settings_scene_pin_auth.c +++ b/applications/desktop/desktop_settings/scenes/desktop_settings_scene_pin_auth.c @@ -1,5 +1,5 @@ #include -#include +#include #include #include "../../helpers/pin_lock.h" #include "../desktop_settings_app.h" diff --git a/applications/desktop/desktop_settings/scenes/desktop_settings_scene_pin_disable.c b/applications/desktop/desktop_settings/scenes/desktop_settings_scene_pin_disable.c index c0b3190e4..f6f6b2562 100644 --- a/applications/desktop/desktop_settings/scenes/desktop_settings_scene_pin_disable.c +++ b/applications/desktop/desktop_settings/scenes/desktop_settings_scene_pin_disable.c @@ -1,5 +1,5 @@ #include -#include +#include #include #include diff --git a/applications/desktop/desktop_settings/scenes/desktop_settings_scene_pin_error.c b/applications/desktop/desktop_settings/scenes/desktop_settings_scene_pin_error.c index a023d6b7a..38852dd8b 100644 --- a/applications/desktop/desktop_settings/scenes/desktop_settings_scene_pin_error.c +++ b/applications/desktop/desktop_settings/scenes/desktop_settings_scene_pin_error.c @@ -1,5 +1,5 @@ #include -#include +#include #include #include "desktop/desktop_settings/desktop_settings.h" diff --git a/applications/desktop/desktop_settings/scenes/desktop_settings_scene_pin_setup.c b/applications/desktop/desktop_settings/scenes/desktop_settings_scene_pin_setup.c index 282bf853b..b536a343a 100644 --- a/applications/desktop/desktop_settings/scenes/desktop_settings_scene_pin_setup.c +++ b/applications/desktop/desktop_settings/scenes/desktop_settings_scene_pin_setup.c @@ -1,5 +1,5 @@ #include -#include +#include #include #include "../desktop_settings_app.h" diff --git a/applications/desktop/helpers/slideshow.c b/applications/desktop/helpers/slideshow.c index 593b2854a..4ec55a5a5 100644 --- a/applications/desktop/helpers/slideshow.c +++ b/applications/desktop/helpers/slideshow.c @@ -4,7 +4,7 @@ #include #include #include -#include +#include #define SLIDESHOW_MAGIC 0x72676468 #define SLIDESHOW_MAX_SUPPORTED_VERSION 1 @@ -118,4 +118,4 @@ void slideshow_draw(Slideshow* slideshow, Canvas* canvas, uint8_t x, uint8_t y) slideshow->icon.width, slideshow->icon.height, slideshow->icon.frames[slideshow->current_frame]); -} \ No newline at end of file +} diff --git a/applications/desktop/scenes/desktop_scene_pin_input.c b/applications/desktop/scenes/desktop_scene_pin_input.c index dd5c8ce38..7d980a85e 100644 --- a/applications/desktop/scenes/desktop_scene_pin_input.c +++ b/applications/desktop/scenes/desktop_scene_pin_input.c @@ -150,7 +150,7 @@ void desktop_scene_pin_input_on_exit(void* context) { desktop->scene_manager, DesktopScenePinInput); xTimerStop(state->timer, portMAX_DELAY); while(xTimerIsTimerActive(state->timer)) { - furi_hal_delay_ms(1); + furi_delay_tick(1); } xTimerDelete(state->timer, portMAX_DELAY); free(state); diff --git a/applications/desktop/views/desktop_view_locked.c b/applications/desktop/views/desktop_view_locked.c index 1245c1529..58ed4face 100644 --- a/applications/desktop/views/desktop_view_locked.c +++ b/applications/desktop/views/desktop_view_locked.c @@ -206,7 +206,7 @@ DesktopViewLocked* desktop_view_locked_alloc() { void desktop_view_locked_free(DesktopViewLocked* locked_view) { furi_assert(locked_view); - osTimerDelete(locked_view->timer); + furi_timer_free(locked_view->timer); view_free(locked_view->view); free(locked_view); } diff --git a/applications/desktop/views/desktop_view_main.c b/applications/desktop/views/desktop_view_main.c index ba944a9ef..2b1d61f41 100644 --- a/applications/desktop/views/desktop_view_main.c +++ b/applications/desktop/views/desktop_view_main.c @@ -99,6 +99,6 @@ DesktopMainView* desktop_main_alloc() { void desktop_main_free(DesktopMainView* main_view) { furi_assert(main_view); view_free(main_view->view); - osTimerDelete(main_view->poweroff_timer); + furi_timer_free(main_view->poweroff_timer); free(main_view); } diff --git a/applications/desktop/views/desktop_view_pin_input.c b/applications/desktop/views/desktop_view_pin_input.c index 2b3b53aa9..d6ce1a02a 100644 --- a/applications/desktop/views/desktop_view_pin_input.c +++ b/applications/desktop/views/desktop_view_pin_input.c @@ -214,7 +214,7 @@ void desktop_view_pin_input_free(DesktopViewPinInput* pin_input) { xTimerStop(pin_input->timer, portMAX_DELAY); while(xTimerIsTimerActive(pin_input->timer)) { - furi_hal_delay_ms(1); + furi_delay_tick(1); } xTimerDelete(pin_input->timer, portMAX_DELAY); diff --git a/applications/dialogs/dialogs.c b/applications/dialogs/dialogs.c index 8929dc116..da047d8a0 100644 --- a/applications/dialogs/dialogs.c +++ b/applications/dialogs/dialogs.c @@ -6,7 +6,7 @@ static DialogsApp* dialogs_app_alloc() { DialogsApp* app = malloc(sizeof(DialogsApp)); - app->message_queue = osMessageQueueNew(8, sizeof(DialogsAppMessage), NULL); + app->message_queue = furi_message_queue_alloc(8, sizeof(DialogsAppMessage)); return app; } @@ -33,7 +33,7 @@ int32_t dialogs_srv(void* p) { DialogsAppMessage message; while(1) { - if(osMessageQueueGet(app->message_queue, &message, NULL, osWaitForever) == osOK) { + if(furi_message_queue_get(app->message_queue, &message, FuriWaitForever) == FuriStatusOk) { dialogs_app_process_message(app, &message); } } diff --git a/applications/dialogs/dialogs_api.c b/applications/dialogs/dialogs_api.c index fab3a5eae..72aa2a1b8 100644 --- a/applications/dialogs/dialogs_api.c +++ b/applications/dialogs/dialogs_api.c @@ -35,7 +35,8 @@ bool dialog_file_browser_show( .return_data = &return_data, }; - furi_check(osMessageQueuePut(context->message_queue, &message, 0, osWaitForever) == osOK); + furi_check( + furi_message_queue_put(context->message_queue, &message, FuriWaitForever) == FuriStatusOk); API_LOCK_WAIT_UNTIL_UNLOCK_AND_FREE(lock); return return_data.bool_value; @@ -60,7 +61,8 @@ DialogMessageButton dialog_message_show(DialogsApp* context, const DialogMessage .return_data = &return_data, }; - furi_check(osMessageQueuePut(context->message_queue, &message, 0, osWaitForever) == osOK); + furi_check( + furi_message_queue_put(context->message_queue, &message, FuriWaitForever) == FuriStatusOk); API_LOCK_WAIT_UNTIL_UNLOCK_AND_FREE(lock); return return_data.dialog_value; diff --git a/applications/dialogs/dialogs_api_lock.h b/applications/dialogs/dialogs_api_lock.h index ad3c78e51..a165803f4 100644 --- a/applications/dialogs/dialogs_api_lock.h +++ b/applications/dialogs/dialogs_api_lock.h @@ -1,17 +1,17 @@ #pragma once -typedef osEventFlagsId_t FuriApiLock; +typedef FuriEventFlag* FuriApiLock; #define API_LOCK_EVENT (1U << 0) -#define API_LOCK_INIT_LOCKED() osEventFlagsNew(NULL); +#define API_LOCK_INIT_LOCKED() furi_event_flag_alloc(); #define API_LOCK_WAIT_UNTIL_UNLOCK(_lock) \ - osEventFlagsWait(_lock, API_LOCK_EVENT, osFlagsWaitAny, osWaitForever); + furi_event_flag_wait(_lock, API_LOCK_EVENT, FuriFlagWaitAny, FuriWaitForever); -#define API_LOCK_FREE(_lock) osEventFlagsDelete(_lock); +#define API_LOCK_FREE(_lock) furi_event_flag_free(_lock); -#define API_LOCK_UNLOCK(_lock) osEventFlagsSet(_lock, API_LOCK_EVENT); +#define API_LOCK_UNLOCK(_lock) furi_event_flag_set(_lock, API_LOCK_EVENT); #define API_LOCK_WAIT_UNTIL_UNLOCK_AND_FREE(_lock) \ API_LOCK_WAIT_UNTIL_UNLOCK(_lock); \ diff --git a/applications/dialogs/dialogs_i.h b/applications/dialogs/dialogs_i.h index b61e10ab9..36bee0248 100644 --- a/applications/dialogs/dialogs_i.h +++ b/applications/dialogs/dialogs_i.h @@ -7,7 +7,7 @@ extern "C" { #endif struct DialogsApp { - osMessageQueueId_t message_queue; + FuriMessageQueue* message_queue; }; #ifdef __cplusplus diff --git a/applications/dialogs/view_holder.c b/applications/dialogs/view_holder.c index eb8a15027..d2ae77503 100644 --- a/applications/dialogs/view_holder.c +++ b/applications/dialogs/view_holder.c @@ -96,7 +96,7 @@ void view_holder_start(ViewHolder* view_holder) { } void view_holder_stop(ViewHolder* view_holder) { - while(view_holder->ongoing_input) osDelay(1); + while(view_holder->ongoing_input) furi_delay_tick(1); view_port_enabled_set(view_holder->view_port, false); } diff --git a/applications/dolphin/dolphin.c b/applications/dolphin/dolphin.c index 479602868..f495068b1 100644 --- a/applications/dolphin/dolphin.c +++ b/applications/dolphin/dolphin.c @@ -77,7 +77,7 @@ Dolphin* dolphin_alloc() { Dolphin* dolphin = malloc(sizeof(Dolphin)); dolphin->state = dolphin_state_alloc(); - dolphin->event_queue = osMessageQueueNew(8, sizeof(DolphinEvent), NULL); + dolphin->event_queue = furi_message_queue_alloc(8, sizeof(DolphinEvent)); dolphin->pubsub = furi_pubsub_alloc(); dolphin->butthurt_timer = xTimerCreate( NULL, HOURS_IN_TICKS(2 * 24), pdTRUE, dolphin, dolphin_butthurt_timer_callback); @@ -93,7 +93,7 @@ void dolphin_free(Dolphin* dolphin) { furi_assert(dolphin); dolphin_state_free(dolphin->state); - osMessageQueueDelete(dolphin->event_queue); + furi_message_queue_free(dolphin->event_queue); free(dolphin); } @@ -102,25 +102,28 @@ void dolphin_event_send_async(Dolphin* dolphin, DolphinEvent* event) { furi_assert(dolphin); furi_assert(event); event->flag = NULL; - furi_check(osMessageQueuePut(dolphin->event_queue, event, 0, osWaitForever) == osOK); + furi_check( + furi_message_queue_put(dolphin->event_queue, event, FuriWaitForever) == FuriStatusOk); } void dolphin_event_send_wait(Dolphin* dolphin, DolphinEvent* event) { furi_assert(dolphin); furi_assert(event); - event->flag = osEventFlagsNew(NULL); + event->flag = furi_event_flag_alloc(); furi_check(event->flag); - furi_check(osMessageQueuePut(dolphin->event_queue, event, 0, osWaitForever) == osOK); furi_check( - osEventFlagsWait(event->flag, DOLPHIN_LOCK_EVENT_FLAG, osFlagsWaitAny, osWaitForever) == + furi_message_queue_put(dolphin->event_queue, event, FuriWaitForever) == FuriStatusOk); + furi_check( + furi_event_flag_wait( + event->flag, DOLPHIN_LOCK_EVENT_FLAG, FuriFlagWaitAny, FuriWaitForever) == DOLPHIN_LOCK_EVENT_FLAG); - furi_check(osEventFlagsDelete(event->flag) == osOK); + furi_event_flag_free(event->flag); } void dolphin_event_release(Dolphin* dolphin, DolphinEvent* event) { UNUSED(dolphin); if(event->flag) { - osEventFlagsSet(event->flag, DOLPHIN_LOCK_EVENT_FLAG); + furi_event_flag_set(event->flag, DOLPHIN_LOCK_EVENT_FLAG); } } @@ -161,7 +164,8 @@ int32_t dolphin_srv(void* p) { DolphinEvent event; while(1) { - if(osMessageQueueGet(dolphin->event_queue, &event, NULL, HOURS_IN_TICKS(1)) == osOK) { + if(furi_message_queue_get(dolphin->event_queue, &event, HOURS_IN_TICKS(1)) == + FuriStatusOk) { if(event.type == DolphinEventTypeDeed) { dolphin_state_on_deed(dolphin->state, event.deed); DolphinPubsubEvent event = DolphinPubsubEventUpdate; diff --git a/applications/dolphin/dolphin.h b/applications/dolphin/dolphin.h index ca3bb4b34..2abb166bf 100644 --- a/applications/dolphin/dolphin.h +++ b/applications/dolphin/dolphin.h @@ -1,6 +1,6 @@ #pragma once -#include "furi/pubsub.h" +#include #include "gui/view.h" #include "helpers/dolphin_deed.h" #include diff --git a/applications/dolphin/dolphin_i.h b/applications/dolphin/dolphin_i.h index 46f149155..4bb0df08e 100644 --- a/applications/dolphin/dolphin_i.h +++ b/applications/dolphin/dolphin_i.h @@ -1,6 +1,6 @@ #pragma once -#include "furi/pubsub.h" +#include #include #include @@ -17,7 +17,7 @@ typedef enum { typedef struct { DolphinEventType type; - osEventFlagsId_t flag; + FuriEventFlag* flag; union { DolphinDeed deed; DolphinStats* stats; @@ -28,7 +28,7 @@ struct Dolphin { // State DolphinState* state; // Queue - osMessageQueueId_t event_queue; + FuriMessageQueue* event_queue; FuriPubSub* pubsub; TimerHandle_t butthurt_timer; TimerHandle_t flush_timer; diff --git a/applications/dolphin/passport/passport.c b/applications/dolphin/passport/passport.c index 13bf086b5..b9be2d228 100644 --- a/applications/dolphin/passport/passport.c +++ b/applications/dolphin/passport/passport.c @@ -1,8 +1,7 @@ #include "assets_icons.h" -#include "cmsis_os2.h" #include "dolphin/helpers/dolphin_state.h" -#include "furi/check.h" -#include "furi/record.h" +#include +#include #include #include #include @@ -28,10 +27,10 @@ static const Icon* const portrait_bad[BUTTHURT_MAX] = { static const Icon* const* portraits[MOODS_TOTAL] = {portrait_happy, portrait_ok, portrait_bad}; static void input_callback(InputEvent* input, void* ctx) { - osSemaphoreId_t semaphore = ctx; + FuriSemaphore* semaphore = ctx; if((input->type == InputTypeShort) && (input->key == InputKeyBack)) { - osSemaphoreRelease(semaphore); + furi_semaphore_release(semaphore); } } @@ -91,7 +90,7 @@ static void render_callback(Canvas* canvas, void* ctx) { int32_t passport_app(void* p) { UNUSED(p); - osSemaphoreId_t semaphore = osSemaphoreNew(1, 0, NULL); + FuriSemaphore* semaphore = furi_semaphore_alloc(1, 0); furi_assert(semaphore); ViewPort* view_port = view_port_alloc(); @@ -105,12 +104,12 @@ int32_t passport_app(void* p) { gui_add_view_port(gui, view_port, GuiLayerFullscreen); view_port_update(view_port); - furi_check(osSemaphoreAcquire(semaphore, osWaitForever) == osOK); + furi_check(furi_semaphore_acquire(semaphore, FuriWaitForever) == FuriStatusOk); gui_remove_view_port(gui, view_port); view_port_free(view_port); furi_record_close("gui"); - osSemaphoreDelete(semaphore); + furi_semaphore_free(semaphore); return 0; } diff --git a/applications/gpio/usb_uart_bridge.c b/applications/gpio/usb_uart_bridge.c index 9c6ba0a6b..c51be513f 100644 --- a/applications/gpio/usb_uart_bridge.c +++ b/applications/gpio/usb_uart_bridge.c @@ -45,9 +45,9 @@ struct UsbUartBridge { StreamBufferHandle_t rx_stream; - osMutexId_t usb_mutex; + FuriMutex* usb_mutex; - osSemaphoreId_t tx_sem; + FuriSemaphore* tx_sem; UsbUartState st; @@ -158,8 +158,8 @@ static int32_t usb_uart_worker(void* context) { usb_uart->rx_stream = xStreamBufferCreate(USB_UART_RX_BUF_SIZE, 1); - usb_uart->tx_sem = osSemaphoreNew(1, 1, NULL); - usb_uart->usb_mutex = osMutexNew(NULL); + usb_uart->tx_sem = furi_semaphore_alloc(1, 1); + usb_uart->usb_mutex = furi_mutex_alloc(FuriMutexTypeNormal); usb_uart->tx_thread = furi_thread_alloc(); furi_thread_set_name(usb_uart->tx_thread, "UsbUartTxWorker"); @@ -185,18 +185,19 @@ static int32_t usb_uart_worker(void* context) { while(1) { uint32_t events = - furi_thread_flags_wait(WORKER_ALL_RX_EVENTS, osFlagsWaitAny, osWaitForever); - furi_check((events & osFlagsError) == 0); + furi_thread_flags_wait(WORKER_ALL_RX_EVENTS, FuriFlagWaitAny, FuriWaitForever); + furi_check((events & FuriFlagError) == 0); if(events & WorkerEvtStop) break; if(events & WorkerEvtRxDone) { size_t len = xStreamBufferReceive(usb_uart->rx_stream, usb_uart->rx_buf, USB_CDC_PKT_LEN, 0); if(len > 0) { - if(osSemaphoreAcquire(usb_uart->tx_sem, 100) == osOK) { + if(furi_semaphore_acquire(usb_uart->tx_sem, 100) == FuriStatusOk) { usb_uart->st.rx_cnt += len; - furi_check(osMutexAcquire(usb_uart->usb_mutex, osWaitForever) == osOK); + furi_check( + furi_mutex_acquire(usb_uart->usb_mutex, FuriWaitForever) == FuriStatusOk); furi_hal_cdc_send(usb_uart->cfg.vcp_ch, usb_uart->rx_buf, len); - furi_check(osMutexRelease(usb_uart->usb_mutex) == osOK); + furi_check(furi_mutex_release(usb_uart->usb_mutex) == FuriStatusOk); } else { xStreamBufferReset(usb_uart->rx_stream); } @@ -270,8 +271,8 @@ static int32_t usb_uart_worker(void* context) { furi_thread_free(usb_uart->tx_thread); vStreamBufferDelete(usb_uart->rx_stream); - osMutexDelete(usb_uart->usb_mutex); - osSemaphoreDelete(usb_uart->tx_sem); + furi_mutex_free(usb_uart->usb_mutex); + furi_semaphore_free(usb_uart->tx_sem); furi_hal_usb_unlock(); furi_check(furi_hal_usb_set_config(&usb_cdc_single, NULL) == true); @@ -288,13 +289,13 @@ static int32_t usb_uart_tx_thread(void* context) { uint8_t data[USB_CDC_PKT_LEN]; while(1) { uint32_t events = - furi_thread_flags_wait(WORKER_ALL_TX_EVENTS, osFlagsWaitAny, osWaitForever); - furi_check((events & osFlagsError) == 0); + furi_thread_flags_wait(WORKER_ALL_TX_EVENTS, FuriFlagWaitAny, FuriWaitForever); + furi_check((events & FuriFlagError) == 0); if(events & WorkerEvtTxStop) break; if(events & WorkerEvtCdcRx) { - furi_check(osMutexAcquire(usb_uart->usb_mutex, osWaitForever) == osOK); + furi_check(furi_mutex_acquire(usb_uart->usb_mutex, FuriWaitForever) == FuriStatusOk); size_t len = furi_hal_cdc_receive(usb_uart->cfg.vcp_ch, data, USB_CDC_PKT_LEN); - furi_check(osMutexRelease(usb_uart->usb_mutex) == osOK); + furi_check(furi_mutex_release(usb_uart->usb_mutex) == FuriStatusOk); if(len > 0) { usb_uart->st.tx_cnt += len; @@ -309,7 +310,7 @@ static int32_t usb_uart_tx_thread(void* context) { static void vcp_on_cdc_tx_complete(void* context) { UsbUartBridge* usb_uart = (UsbUartBridge*)context; - osSemaphoreRelease(usb_uart->tx_sem); + furi_semaphore_release(usb_uart->tx_sem); } static void vcp_on_cdc_rx(void* context) { diff --git a/applications/gui/gui.c b/applications/gui/gui.c index d9e32cdda..50df399ad 100644 --- a/applications/gui/gui.c +++ b/applications/gui/gui.c @@ -28,7 +28,7 @@ void gui_input_events_callback(const void* value, void* ctx) { Gui* gui = ctx; - osMessageQueuePut(gui->input_queue, value, 0, osWaitForever); + furi_message_queue_put(gui->input_queue, value, FuriWaitForever); furi_thread_flags_set(gui->thread_id, GUI_THREAD_FLAG_INPUT); } @@ -308,12 +308,12 @@ void gui_input(Gui* gui, InputEvent* input_event) { void gui_lock(Gui* gui) { furi_assert(gui); - furi_check(osMutexAcquire(gui->mutex, osWaitForever) == osOK); + furi_check(furi_mutex_acquire(gui->mutex, FuriWaitForever) == FuriStatusOk); } void gui_unlock(Gui* gui) { furi_assert(gui); - furi_check(osMutexRelease(gui->mutex) == osOK); + furi_check(furi_mutex_release(gui->mutex) == FuriStatusOk); } void gui_add_view_port(Gui* gui, ViewPort* view_port, GuiLayer layer) { @@ -473,7 +473,7 @@ Gui* gui_alloc() { // Thread ID gui->thread_id = furi_thread_get_current_id(); // Allocate mutex - gui->mutex = osMutexNew(NULL); + gui->mutex = furi_mutex_alloc(FuriMutexTypeNormal); furi_check(gui->mutex); // Layers for(size_t i = 0; i < GuiLayerMAX; i++) { @@ -484,7 +484,7 @@ Gui* gui_alloc() { CanvasCallbackPairArray_init(gui->canvas_callback_pair); // Input - gui->input_queue = osMessageQueueNew(8, sizeof(InputEvent), NULL); + gui->input_queue = furi_message_queue_alloc(8, sizeof(InputEvent)); gui->input_events = furi_record_open("input_events"); furi_check(gui->input_events); @@ -501,12 +501,12 @@ int32_t gui_srv(void* p) { while(1) { uint32_t flags = - furi_thread_flags_wait(GUI_THREAD_FLAG_ALL, osFlagsWaitAny, osWaitForever); + furi_thread_flags_wait(GUI_THREAD_FLAG_ALL, FuriFlagWaitAny, FuriWaitForever); // Process and dispatch input if(flags & GUI_THREAD_FLAG_INPUT) { // Process till queue become empty InputEvent input_event; - while(osMessageQueueGet(gui->input_queue, &input_event, NULL, 0) == osOK) { + while(furi_message_queue_get(gui->input_queue, &input_event, 0) == FuriStatusOk) { gui_input(gui, &input_event); } } diff --git a/applications/gui/gui_i.h b/applications/gui/gui_i.h index abe856155..b3fd0aa7c 100644 --- a/applications/gui/gui_i.h +++ b/applications/gui/gui_i.h @@ -58,7 +58,7 @@ ALGO_DEF(CanvasCallbackPairArray, CanvasCallbackPairArray_t); struct Gui { // Thread and lock FuriThreadId thread_id; - osMutexId_t mutex; + FuriMutex* mutex; // Layers and Canvas bool lockdown; @@ -67,7 +67,7 @@ struct Gui { CanvasCallbackPairArray_t canvas_callback_pair; // Input - osMessageQueueId_t input_queue; + FuriMessageQueue* input_queue; FuriPubSub* input_events; uint8_t ongoing_input; ViewPort* ongoing_input_view_port; diff --git a/applications/gui/icon_animation.c b/applications/gui/icon_animation.c index 5170eea41..48c862208 100644 --- a/applications/gui/icon_animation.c +++ b/applications/gui/icon_animation.c @@ -7,15 +7,16 @@ IconAnimation* icon_animation_alloc(const Icon* icon) { furi_assert(icon); IconAnimation* instance = malloc(sizeof(IconAnimation)); instance->icon = icon; - instance->timer = osTimerNew(icon_animation_timer_callback, osTimerPeriodic, instance, NULL); + instance->timer = + furi_timer_alloc(icon_animation_timer_callback, FuriTimerTypePeriodic, instance); return instance; } void icon_animation_free(IconAnimation* instance) { furi_assert(instance); icon_animation_stop(instance); - while(xTimerIsTimerActive(instance->timer) == pdTRUE) osDelay(1); - furi_check(osTimerDelete(instance->timer) == osOK); + while(xTimerIsTimerActive(instance->timer) == pdTRUE) furi_delay_tick(1); + furi_timer_free(instance->timer); free(instance); } @@ -68,7 +69,7 @@ void icon_animation_start(IconAnimation* instance) { furi_check( xTimerChangePeriod( instance->timer, - (osKernelGetTickFreq() / instance->icon->frame_rate), + (furi_kernel_get_tick_frequency() / instance->icon->frame_rate), portMAX_DELAY) == pdPASS); } } diff --git a/applications/gui/icon_animation_i.h b/applications/gui/icon_animation_i.h index 241bcaa38..4053a120d 100644 --- a/applications/gui/icon_animation_i.h +++ b/applications/gui/icon_animation_i.h @@ -13,7 +13,7 @@ struct IconAnimation { const Icon* icon; uint8_t frame; bool animating; - osTimerId_t timer; + FuriTimer* timer; IconAnimationCallback callback; void* callback_context; }; diff --git a/applications/gui/modules/file_browser.c b/applications/gui/modules/file_browser.c index 4dc0ee547..a987eb1ef 100644 --- a/applications/gui/modules/file_browser.c +++ b/applications/gui/modules/file_browser.c @@ -1,10 +1,9 @@ #include "file_browser.h" #include "assets_icons.h" -#include "cmsis_os2.h" #include "file_browser_worker.h" -#include "furi/check.h" -#include "furi/common_defines.h" -#include "furi/log.h" +#include +#include +#include #include "furi_hal_resources.h" #include "m-string.h" #include diff --git a/applications/gui/modules/file_browser_worker.c b/applications/gui/modules/file_browser_worker.c index cd7b6cb75..ce3def41e 100644 --- a/applications/gui/modules/file_browser_worker.c +++ b/applications/gui/modules/file_browser_worker.c @@ -1,6 +1,6 @@ #include "file_browser_worker.h" -#include "furi/check.h" -#include "furi/common_defines.h" +#include +#include #include "m-string.h" #include "storage/filesystem_api_defines.h" #include @@ -262,8 +262,9 @@ static int32_t browser_worker(void* context) { furi_thread_flags_set(furi_thread_get_id(browser->thread), WorkerEvtConfigChange); while(1) { - uint32_t flags = furi_thread_flags_wait(WORKER_FLAGS_ALL, osFlagsWaitAny, osWaitForever); - furi_assert((flags & osFlagsError) == 0); + uint32_t flags = + furi_thread_flags_wait(WORKER_FLAGS_ALL, FuriFlagWaitAny, FuriWaitForever); + furi_assert((flags & FuriFlagError) == 0); if(flags & WorkerEvtConfigChange) { // If start path is a path to the file - try finding index of this file in a folder diff --git a/applications/gui/modules/popup.c b/applications/gui/modules/popup.c index 3b53d9629..b3cb5e536 100644 --- a/applications/gui/modules/popup.c +++ b/applications/gui/modules/popup.c @@ -7,7 +7,7 @@ struct Popup { void* context; PopupCallback callback; - osTimerId_t timer; + FuriTimer* timer; uint32_t timer_period_in_ms; bool timer_enabled; }; @@ -93,10 +93,11 @@ static bool popup_view_input_callback(InputEvent* event, void* context) { void popup_start_timer(void* context) { Popup* popup = context; if(popup->timer_enabled) { - uint32_t timer_period = popup->timer_period_in_ms / (1000.0f / osKernelGetTickFreq()); + uint32_t timer_period = + popup->timer_period_in_ms / (1000.0f / furi_kernel_get_tick_frequency()); if(timer_period == 0) timer_period = 1; - if(osTimerStart(popup->timer, timer_period) != osOK) { + if(furi_timer_start(popup->timer, timer_period) != FuriStatusOk) { furi_assert(0); }; } @@ -104,13 +105,13 @@ void popup_start_timer(void* context) { void popup_stop_timer(void* context) { Popup* popup = context; - osTimerStop(popup->timer); + furi_timer_stop(popup->timer); } Popup* popup_alloc() { Popup* popup = malloc(sizeof(Popup)); popup->view = view_alloc(); - popup->timer = osTimerNew(popup_timer_callback, osTimerOnce, popup, NULL); + popup->timer = furi_timer_alloc(popup_timer_callback, FuriTimerTypeOnce, popup); furi_assert(popup->timer); popup->timer_period_in_ms = 1000; popup->timer_enabled = false; @@ -146,7 +147,7 @@ Popup* popup_alloc() { void popup_free(Popup* popup) { furi_assert(popup); - osTimerDelete(popup->timer); + furi_timer_free(popup->timer); view_free(popup->view); free(popup); } diff --git a/applications/gui/modules/text_input.c b/applications/gui/modules/text_input.c index 04cd2d7f8..5aa101bb4 100644 --- a/applications/gui/modules/text_input.c +++ b/applications/gui/modules/text_input.c @@ -4,7 +4,7 @@ struct TextInput { View* view; - osTimerId_t timer; + FuriTimer* timer; }; typedef struct { @@ -310,7 +310,7 @@ static void text_input_handle_ok(TextInput* text_input, TextInputModel* model, b (!model->validator_callback( model->text_buffer, model->validator_text, model->validator_callback_context))) { model->valadator_message_visible = true; - osTimerStart(text_input->timer, osKernelGetTickFreq() * 4); + furi_timer_start(text_input->timer, furi_kernel_get_tick_frequency() * 4); } else if(model->callback != 0 && text_length > 0) { model->callback(model->callback_context); } @@ -438,7 +438,7 @@ TextInput* text_input_alloc() { view_set_draw_callback(text_input->view, text_input_view_draw_callback); view_set_input_callback(text_input->view, text_input_view_input_callback); - text_input->timer = osTimerNew(text_input_timer_callback, osTimerOnce, text_input, NULL); + text_input->timer = furi_timer_alloc(text_input_timer_callback, FuriTimerTypeOnce, text_input); with_view_model( text_input->view, (TextInputModel * model) { @@ -460,11 +460,11 @@ void text_input_free(TextInput* text_input) { }); // Send stop command - osTimerStop(text_input->timer); + furi_timer_stop(text_input->timer); // Wait till timer stop - while(osTimerIsRunning(text_input->timer)) osDelay(1); + while(furi_timer_is_running(text_input->timer)) furi_delay_tick(1); // Release allocated memory - osTimerDelete(text_input->timer); + furi_timer_free(text_input->timer); view_free(text_input->view); diff --git a/applications/gui/view.c b/applications/gui/view.c index ec73882de..7ab6d15b7 100644 --- a/applications/gui/view.c +++ b/applications/gui/view.c @@ -81,7 +81,7 @@ void view_allocate_model(View* view, ViewModelType type, size_t size) { view->model = malloc(size); } else if(view->model_type == ViewModelTypeLocking) { ViewModelLocking* model = malloc(sizeof(ViewModelLocking)); - model->mutex = osMutexNew(NULL); + model->mutex = furi_mutex_alloc(FuriMutexTypeNormal); furi_check(model->mutex); model->data = malloc(size); view->model = model; @@ -98,7 +98,7 @@ void view_free_model(View* view) { free(view->model); } else if(view->model_type == ViewModelTypeLocking) { ViewModelLocking* model = view->model; - furi_check(osMutexDelete(model->mutex) == osOK); + furi_mutex_free(model->mutex); free(model->data); free(model); view->model = NULL; @@ -111,7 +111,7 @@ void* view_get_model(View* view) { furi_assert(view); if(view->model_type == ViewModelTypeLocking) { ViewModelLocking* model = (ViewModelLocking*)(view->model); - furi_check(osMutexAcquire(model->mutex, osWaitForever) == osOK); + furi_check(furi_mutex_acquire(model->mutex, FuriWaitForever) == FuriStatusOk); return model->data; } return view->model; @@ -138,7 +138,7 @@ void view_unlock_model(View* view) { furi_assert(view); if(view->model_type == ViewModelTypeLocking) { ViewModelLocking* model = (ViewModelLocking*)(view->model); - furi_check(osMutexRelease(model->mutex) == osOK); + furi_check(furi_mutex_release(model->mutex) == FuriStatusOk); } } diff --git a/applications/gui/view_dispatcher.c b/applications/gui/view_dispatcher.c index 8bfb9e4eb..307206c14 100644 --- a/applications/gui/view_dispatcher.c +++ b/applications/gui/view_dispatcher.c @@ -30,7 +30,7 @@ void view_dispatcher_free(ViewDispatcher* view_dispatcher) { view_port_free(view_dispatcher->view_port); // Free internal queue if(view_dispatcher->queue) { - osMessageQueueDelete(view_dispatcher->queue); + furi_message_queue_free(view_dispatcher->queue); } // Free dispatcher free(view_dispatcher); @@ -39,7 +39,7 @@ void view_dispatcher_free(ViewDispatcher* view_dispatcher) { void view_dispatcher_enable_queue(ViewDispatcher* view_dispatcher) { furi_assert(view_dispatcher); furi_assert(view_dispatcher->queue == NULL); - view_dispatcher->queue = osMessageQueueNew(16, sizeof(ViewDispatcherMessage), NULL); + view_dispatcher->queue = furi_message_queue_alloc(16, sizeof(ViewDispatcherMessage)); } void view_dispatcher_set_event_callback_context(ViewDispatcher* view_dispatcher, void* context) { @@ -77,11 +77,11 @@ void view_dispatcher_run(ViewDispatcher* view_dispatcher) { furi_assert(view_dispatcher); furi_assert(view_dispatcher->queue); - uint32_t tick_period = view_dispatcher->tick_period == 0 ? osWaitForever : + uint32_t tick_period = view_dispatcher->tick_period == 0 ? FuriWaitForever : view_dispatcher->tick_period; ViewDispatcherMessage message; while(1) { - if(osMessageQueueGet(view_dispatcher->queue, &message, NULL, tick_period) != osOK) { + if(furi_message_queue_get(view_dispatcher->queue, &message, tick_period) != FuriStatusOk) { view_dispatcher_handle_tick_event(view_dispatcher); continue; } @@ -96,7 +96,7 @@ void view_dispatcher_run(ViewDispatcher* view_dispatcher) { // Wait till all input events delivered while(view_dispatcher->ongoing_input) { - osMessageQueueGet(view_dispatcher->queue, &message, NULL, osWaitForever); + furi_message_queue_get(view_dispatcher->queue, &message, FuriWaitForever); if(message.type == ViewDispatcherMessageTypeInput) { uint8_t key_bit = (1 << message.input.key); if(message.input.type == InputTypePress) { @@ -113,7 +113,8 @@ void view_dispatcher_stop(ViewDispatcher* view_dispatcher) { furi_assert(view_dispatcher->queue); ViewDispatcherMessage message; message.type = ViewDispatcherMessageTypeStop; - furi_check(osMessageQueuePut(view_dispatcher->queue, &message, 0, osWaitForever) == osOK); + furi_check( + furi_message_queue_put(view_dispatcher->queue, &message, FuriWaitForever) == FuriStatusOk); } void view_dispatcher_add_view(ViewDispatcher* view_dispatcher, uint32_t view_id, View* view) { @@ -224,7 +225,9 @@ void view_dispatcher_input_callback(InputEvent* event, void* context) { ViewDispatcherMessage message; message.type = ViewDispatcherMessageTypeInput; message.input = *event; - furi_check(osMessageQueuePut(view_dispatcher->queue, &message, 0, osWaitForever) == osOK); + furi_check( + furi_message_queue_put(view_dispatcher->queue, &message, FuriWaitForever) == + FuriStatusOk); } else { view_dispatcher_handle_input(view_dispatcher, event); } @@ -314,7 +317,8 @@ void view_dispatcher_send_custom_event(ViewDispatcher* view_dispatcher, uint32_t message.type = ViewDispatcherMessageTypeCustomEvent; message.custom_event = event; - furi_check(osMessageQueuePut(view_dispatcher->queue, &message, 0, osWaitForever) == osOK); + furi_check( + furi_message_queue_put(view_dispatcher->queue, &message, FuriWaitForever) == FuriStatusOk); } void view_dispatcher_set_current_view(ViewDispatcher* view_dispatcher, View* view) { diff --git a/applications/gui/view_dispatcher_i.h b/applications/gui/view_dispatcher_i.h index ad0f08889..f30a84e6b 100644 --- a/applications/gui/view_dispatcher_i.h +++ b/applications/gui/view_dispatcher_i.h @@ -15,7 +15,7 @@ DICT_DEF2(ViewDict, uint32_t, M_DEFAULT_OPLIST, View*, M_PTR_OPLIST) struct ViewDispatcher { - osMessageQueueId_t queue; + FuriMessageQueue* queue; Gui* gui; ViewPort* view_port; ViewDict_t views; diff --git a/applications/gui/view_i.h b/applications/gui/view_i.h index 21b374d52..3e895bd94 100644 --- a/applications/gui/view_i.h +++ b/applications/gui/view_i.h @@ -10,7 +10,7 @@ typedef struct { void* data; - osMutexId_t mutex; + FuriMutex* mutex; } ViewModelLocking; struct View { diff --git a/applications/gui/view_stack.c b/applications/gui/view_stack.c index a1c96faae..3bb00fbf2 100644 --- a/applications/gui/view_stack.c +++ b/applications/gui/view_stack.c @@ -1,5 +1,5 @@ #include "gui/view.h" -#include "furi/memmgr.h" +#include #include "view_stack.h" #include "view_i.h" diff --git a/applications/ibutton/ibutton_cli.c b/applications/ibutton/ibutton_cli.c index 4592cdad9..324c636de 100644 --- a/applications/ibutton/ibutton_cli.c +++ b/applications/ibutton/ibutton_cli.c @@ -67,14 +67,14 @@ void ibutton_cli_print_key_data(iButtonKey* key) { static void ibutton_cli_worker_read_cb(void* context) { furi_assert(context); - osEventFlagsId_t event = context; - osEventFlagsSet(event, EVENT_FLAG_IBUTTON_COMPLETE); + FuriEventFlag* event = context; + furi_event_flag_set(event, EVENT_FLAG_IBUTTON_COMPLETE); } void ibutton_cli_read(Cli* cli) { iButtonKey* key = ibutton_key_alloc(); iButtonWorker* worker = ibutton_worker_alloc(); - osEventFlagsId_t event = osEventFlagsNew(NULL); + FuriEventFlag* event = furi_event_flag_alloc(); ibutton_worker_start_thread(worker); ibutton_worker_read_set_callback(worker, ibutton_cli_worker_read_cb, event); @@ -82,7 +82,8 @@ void ibutton_cli_read(Cli* cli) { printf("Reading iButton...\r\nPress Ctrl+C to abort\r\n"); ibutton_worker_read_start(worker, key); while(true) { - uint32_t flags = osEventFlagsWait(event, EVENT_FLAG_IBUTTON_COMPLETE, osFlagsWaitAny, 100); + uint32_t flags = + furi_event_flag_wait(event, EVENT_FLAG_IBUTTON_COMPLETE, FuriFlagWaitAny, 100); if(flags & EVENT_FLAG_IBUTTON_COMPLETE) { ibutton_cli_print_key_data(key); @@ -107,11 +108,11 @@ void ibutton_cli_read(Cli* cli) { ibutton_worker_free(worker); ibutton_key_free(key); - osEventFlagsDelete(event); + furi_event_flag_free(event); }; typedef struct { - osEventFlagsId_t event; + FuriEventFlag* event; iButtonWorkerWriteResult result; } iButtonWriteContext; @@ -119,7 +120,7 @@ static void ibutton_cli_worker_write_cb(void* context, iButtonWorkerWriteResult furi_assert(context); iButtonWriteContext* write_context = (iButtonWriteContext*)context; write_context->result = result; - osEventFlagsSet(write_context->event, EVENT_FLAG_IBUTTON_COMPLETE); + furi_event_flag_set(write_context->event, EVENT_FLAG_IBUTTON_COMPLETE); } void ibutton_cli_write(Cli* cli, string_t args) { @@ -130,7 +131,7 @@ void ibutton_cli_write(Cli* cli, string_t args) { uint8_t key_data[IBUTTON_KEY_DATA_SIZE]; string_t data; - write_context.event = osEventFlagsNew(NULL); + write_context.event = furi_event_flag_alloc(); string_init(data); ibutton_worker_start_thread(worker); @@ -166,8 +167,8 @@ void ibutton_cli_write(Cli* cli, string_t args) { ibutton_worker_write_start(worker, key); while(true) { - uint32_t flags = osEventFlagsWait( - write_context.event, EVENT_FLAG_IBUTTON_COMPLETE, osFlagsWaitAny, 100); + uint32_t flags = furi_event_flag_wait( + write_context.event, EVENT_FLAG_IBUTTON_COMPLETE, FuriFlagWaitAny, 100); if(flags & EVENT_FLAG_IBUTTON_COMPLETE) { if(write_context.result == iButtonWorkerWriteSameKey || @@ -190,7 +191,7 @@ void ibutton_cli_write(Cli* cli, string_t args) { ibutton_worker_free(worker); ibutton_key_free(key); - osEventFlagsDelete(write_context.event); + furi_event_flag_free(write_context.event); }; void ibutton_cli_emulate(Cli* cli, string_t args) { @@ -228,7 +229,7 @@ void ibutton_cli_emulate(Cli* cli, string_t args) { ibutton_worker_emulate_start(worker, key); while(!cli_cmd_interrupt_received(cli)) { - furi_hal_delay_ms(100); + furi_delay_ms(100); }; ibutton_worker_stop(worker); } while(false); @@ -291,7 +292,7 @@ static void onewire_cli_search(Cli* cli) { } printf("\r\n"); } - furi_hal_delay_ms(100); + furi_delay_ms(100); } furi_hal_power_disable_otg(); diff --git a/applications/ibutton/scenes/ibutton_scene_emulate.c b/applications/ibutton/scenes/ibutton_scene_emulate.c index 0483b77aa..3420f8471 100644 --- a/applications/ibutton/scenes/ibutton_scene_emulate.c +++ b/applications/ibutton/scenes/ibutton_scene_emulate.c @@ -1,5 +1,5 @@ #include "../ibutton_i.h" -#include "furi/log.h" +#include #include #include diff --git a/applications/infrared/infrared_cli.c b/applications/infrared/infrared_cli.c index d88e7fff5..a2dfc2a30 100644 --- a/applications/infrared/infrared_cli.c +++ b/applications/infrared/infrared_cli.c @@ -63,7 +63,7 @@ static void infrared_cli_start_ir_rx(Cli* cli, string_t args) { printf("Receiving INFRARED...\r\nPress Ctrl+C to abort\r\n"); while(!cli_cmd_interrupt_received(cli)) { - furi_hal_delay_ms(50); + furi_delay_ms(50); } infrared_worker_rx_stop(worker); diff --git a/applications/infrared/infrared_remote.c b/applications/infrared/infrared_remote.c index 94658035b..d693be179 100644 --- a/applications/infrared/infrared_remote.c +++ b/applications/infrared/infrared_remote.c @@ -7,7 +7,7 @@ #include #include #include -#include +#include #define TAG "InfraredRemote" diff --git a/applications/infrared/infrared_signal.c b/applications/infrared/infrared_signal.c index 79eafb308..b76717dd3 100644 --- a/applications/infrared/infrared_signal.c +++ b/applications/infrared/infrared_signal.c @@ -2,7 +2,7 @@ #include #include -#include +#include #include #include diff --git a/applications/infrared/views/infrared_progress_view.c b/applications/infrared/views/infrared_progress_view.c index cd2a07543..5c84ce0d9 100644 --- a/applications/infrared/views/infrared_progress_view.c +++ b/applications/infrared/views/infrared_progress_view.c @@ -1,4 +1,4 @@ -#include "furi/check.h" +#include #include "furi_hal_resources.h" #include "assets_icons.h" #include "gui/canvas.h" diff --git a/applications/input/input.c b/applications/input/input.c index 2be67a714..7270a020a 100644 --- a/applications/input/input.c +++ b/applications/input/input.c @@ -4,18 +4,18 @@ static Input* input = NULL; -inline static void input_timer_start(osTimerId_t timer_id, uint32_t ticks) { +inline static void input_timer_start(FuriTimer* timer_id, uint32_t ticks) { TimerHandle_t hTimer = (TimerHandle_t)timer_id; furi_check(xTimerChangePeriod(hTimer, ticks, portMAX_DELAY) == pdPASS); } -inline static void input_timer_stop(osTimerId_t timer_id) { +inline static void input_timer_stop(FuriTimer* timer_id) { TimerHandle_t hTimer = (TimerHandle_t)timer_id; furi_check(xTimerStop(hTimer, portMAX_DELAY) == pdPASS); // xTimerStop is not actually stopping timer, // Instead it places stop event into timer queue // This code ensures that timer is stopped - while(xTimerIsTimerActive(hTimer) == pdTRUE) osDelay(1); + while(xTimerIsTimerActive(hTimer) == pdTRUE) furi_delay_tick(1); } void input_press_timer_callback(void* arg) { @@ -84,8 +84,8 @@ int32_t input_srv() { input->pin_states[i].pin = &input_pins[i]; input->pin_states[i].state = GPIO_Read(input->pin_states[i]); input->pin_states[i].debounce = INPUT_DEBOUNCE_TICKS_HALF; - input->pin_states[i].press_timer = - osTimerNew(input_press_timer_callback, osTimerPeriodic, &input->pin_states[i], NULL); + input->pin_states[i].press_timer = furi_timer_alloc( + input_press_timer_callback, FuriTimerTypePeriodic, &input->pin_states[i]); input->pin_states[i].press_counter = 0; } @@ -127,9 +127,9 @@ int32_t input_srv() { } if(is_changing) { - osDelay(1); + furi_delay_tick(1); } else { - furi_thread_flags_wait(INPUT_THREAD_FLAG_ISR, osFlagsWaitAny, osWaitForever); + furi_thread_flags_wait(INPUT_THREAD_FLAG_ISR, FuriFlagWaitAny, FuriWaitForever); } } diff --git a/applications/input/input_cli.c b/applications/input/input_cli.c index afb05afd4..037ac53e5 100644 --- a/applications/input/input_cli.c +++ b/applications/input/input_cli.c @@ -15,20 +15,20 @@ static void input_cli_usage() { static void input_cli_dump_events_callback(const void* value, void* ctx) { furi_assert(value); furi_assert(ctx); - osMessageQueueId_t input_queue = ctx; - osMessageQueuePut(input_queue, value, 0, osWaitForever); + FuriMessageQueue* input_queue = ctx; + furi_message_queue_put(input_queue, value, FuriWaitForever); } static void input_cli_dump(Cli* cli, string_t args, Input* input) { UNUSED(args); - osMessageQueueId_t input_queue = osMessageQueueNew(8, sizeof(InputEvent), NULL); + FuriMessageQueue* input_queue = furi_message_queue_alloc(8, sizeof(InputEvent)); FuriPubSubSubscription* input_subscription = furi_pubsub_subscribe(input->event_pubsub, input_cli_dump_events_callback, input_queue); InputEvent input_event; printf("Press CTRL+C to stop\r\n"); while(!cli_cmd_interrupt_received(cli)) { - if(osMessageQueueGet(input_queue, &input_event, NULL, 100) == osOK) { + if(furi_message_queue_get(input_queue, &input_event, 100) == FuriStatusOk) { printf( "key: %s type: %s\r\n", input_get_key_name(input_event.key), @@ -37,7 +37,7 @@ static void input_cli_dump(Cli* cli, string_t args, Input* input) { } furi_pubsub_unsubscribe(input->event_pubsub, input_subscription); - osMessageQueueDelete(input_queue); + furi_message_queue_free(input_queue); } static void input_cli_send_print_usage() { diff --git a/applications/input/input_i.h b/applications/input/input_i.h index 63a9c85a2..f709e0487 100644 --- a/applications/input/input_i.h +++ b/applications/input/input_i.h @@ -25,7 +25,7 @@ typedef struct { // State volatile bool state; volatile uint8_t debounce; - volatile osTimerId_t press_timer; + FuriTimer* press_timer; volatile uint8_t press_counter; volatile uint32_t counter; } InputPinState; diff --git a/applications/lfrfid/helpers/rfid_key.cpp b/applications/lfrfid/helpers/rfid_key.cpp index 02e45e686..2d99d40f2 100644 --- a/applications/lfrfid/helpers/rfid_key.cpp +++ b/applications/lfrfid/helpers/rfid_key.cpp @@ -1,5 +1,5 @@ #include "rfid_key.h" -#include +#include #include RfidKey::RfidKey() { diff --git a/applications/lfrfid/helpers/rfid_reader.cpp b/applications/lfrfid/helpers/rfid_reader.cpp index fb837cb7a..029b1cb4b 100644 --- a/applications/lfrfid/helpers/rfid_reader.cpp +++ b/applications/lfrfid/helpers/rfid_reader.cpp @@ -39,12 +39,12 @@ void RfidReader::decode(bool polarity) { } bool RfidReader::switch_timer_elapsed() { - const uint32_t seconds_to_switch = osKernelGetTickFreq() * 2.0f; - return (osKernelGetTickCount() - switch_os_tick_last) > seconds_to_switch; + const uint32_t seconds_to_switch = furi_kernel_get_tick_frequency() * 2.0f; + return (furi_get_tick() - switch_os_tick_last) > seconds_to_switch; } void RfidReader::switch_timer_reset() { - switch_os_tick_last = osKernelGetTickCount(); + switch_os_tick_last = furi_get_tick(); } void RfidReader::switch_mode() { diff --git a/applications/lfrfid/helpers/rfid_writer.cpp b/applications/lfrfid/helpers/rfid_writer.cpp index e85ab9361..31838fde0 100644 --- a/applications/lfrfid/helpers/rfid_writer.cpp +++ b/applications/lfrfid/helpers/rfid_writer.cpp @@ -49,15 +49,15 @@ void RfidWriter::stop() { void RfidWriter::write_gap(uint32_t gap_time) { furi_hal_rfid_tim_read_stop(); - furi_hal_delay_us(gap_time * 8); + furi_delay_us(gap_time * 8); furi_hal_rfid_tim_read_start(); } void RfidWriter::write_bit(bool value) { if(value) { - furi_hal_delay_us(T55xxTiming::data_1 * 8); + furi_delay_us(T55xxTiming::data_1 * 8); } else { - furi_hal_delay_us(T55xxTiming::data_0 * 8); + furi_delay_us(T55xxTiming::data_0 * 8); } write_gap(T55xxTiming::write_gap); } @@ -69,7 +69,7 @@ void RfidWriter::write_byte(uint8_t value) { } void RfidWriter::write_block(uint8_t page, uint8_t block, bool lock_bit, uint32_t data) { - furi_hal_delay_us(T55xxTiming::wait_time * 8); + furi_delay_us(T55xxTiming::wait_time * 8); // start gap write_gap(T55xxTiming::start_gap); @@ -102,9 +102,9 @@ void RfidWriter::write_block(uint8_t page, uint8_t block, bool lock_bit, uint32_ write_bit((block >> 1) & 1); write_bit((block >> 0) & 1); - furi_hal_delay_us(T55xxTiming::program * 8); + furi_delay_us(T55xxTiming::program * 8); - furi_hal_delay_us(T55xxTiming::wait_time * 8); + furi_delay_us(T55xxTiming::wait_time * 8); write_reset(); } diff --git a/applications/lfrfid/lfrfid_app.cpp b/applications/lfrfid/lfrfid_app.cpp index d2c92d248..c491cf40b 100644 --- a/applications/lfrfid/lfrfid_app.cpp +++ b/applications/lfrfid/lfrfid_app.cpp @@ -1,6 +1,6 @@ #include "lfrfid_app.h" #include "assets_icons.h" -#include "furi/common_defines.h" +#include #include "m-string.h" #include "scene/lfrfid_app_scene_start.h" #include "scene/lfrfid_app_scene_read.h" diff --git a/applications/lfrfid/lfrfid_cli.cpp b/applications/lfrfid/lfrfid_cli.cpp index 451f10cef..7d1bb6d4a 100644 --- a/applications/lfrfid/lfrfid_cli.cpp +++ b/applications/lfrfid/lfrfid_cli.cpp @@ -94,7 +94,7 @@ static void lfrfid_cli_read(Cli* cli, string_t args) { printf("\r\n"); break; } - furi_hal_delay_ms(100); + furi_delay_ms(100); } printf("Reading stopped\r\n"); @@ -144,7 +144,7 @@ static void lfrfid_cli_emulate(Cli* cli, string_t args) { printf("Emulating RFID...\r\nPress Ctrl+C to abort\r\n"); while(!cli_cmd_interrupt_received(cli)) { - furi_hal_delay_ms(100); + furi_delay_ms(100); } printf("Emulation stopped\r\n"); emulator.stop(); diff --git a/applications/lfrfid/scene/lfrfid_app_scene_emulate.cpp b/applications/lfrfid/scene/lfrfid_app_scene_emulate.cpp index 3df526d0c..183361a0b 100644 --- a/applications/lfrfid/scene/lfrfid_app_scene_emulate.cpp +++ b/applications/lfrfid/scene/lfrfid_app_scene_emulate.cpp @@ -1,5 +1,5 @@ #include "lfrfid_app_scene_emulate.h" -#include "furi/common_defines.h" +#include #include static const NotificationSequence sequence_blink_start_magenta = { diff --git a/applications/lfrfid/scene/lfrfid_app_scene_rpc.cpp b/applications/lfrfid/scene/lfrfid_app_scene_rpc.cpp index 012c96ac1..80d479345 100644 --- a/applications/lfrfid/scene/lfrfid_app_scene_rpc.cpp +++ b/applications/lfrfid/scene/lfrfid_app_scene_rpc.cpp @@ -1,5 +1,5 @@ #include "lfrfid_app_scene_rpc.h" -#include "furi/common_defines.h" +#include #include void LfRfidAppSceneRpc::on_enter(LfRfidApp* app, bool /* need_restore */) { diff --git a/applications/loader/loader.c b/applications/loader/loader.c index 1acff8b7d..f5db5586d 100644 --- a/applications/loader/loader.c +++ b/applications/loader/loader.c @@ -471,7 +471,7 @@ int32_t loader_srv(void* p) { while(1) { uint32_t flags = - furi_thread_flags_wait(LOADER_THREAD_FLAG_ALL, osFlagsWaitAny, osWaitForever); + furi_thread_flags_wait(LOADER_THREAD_FLAG_ALL, FuriFlagWaitAny, FuriWaitForever); if(flags & LOADER_THREAD_FLAG_SHOW_MENU) { menu_set_selected_item(loader_instance->primary_menu, 0); view_dispatcher_switch_to_view( diff --git a/applications/loader/loader.h b/applications/loader/loader.h index b65539fea..4bf835b48 100644 --- a/applications/loader/loader.h +++ b/applications/loader/loader.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include typedef struct Loader Loader; diff --git a/applications/loader/loader_i.h b/applications/loader/loader_i.h index a311c6e8a..db91f806c 100644 --- a/applications/loader/loader_i.h +++ b/applications/loader/loader_i.h @@ -2,7 +2,7 @@ #include #include -#include +#include #include #include diff --git a/applications/music_player/music_player.c b/applications/music_player/music_player.c index 9b5dda0fa..26dfb8124 100644 --- a/applications/music_player/music_player.c +++ b/applications/music_player/music_player.c @@ -27,9 +27,9 @@ typedef struct { typedef struct { MusicPlayerModel* model; - osMutexId_t* model_mutex; + FuriMutex** model_mutex; - osMessageQueueId_t input_queue; + FuriMessageQueue* input_queue; ViewPort* view_port; Gui* gui; @@ -126,7 +126,7 @@ static bool is_black_note(uint8_t semitone, uint8_t id) { static void render_callback(Canvas* canvas, void* ctx) { MusicPlayer* music_player = ctx; - furi_check(osMutexAcquire(music_player->model_mutex, osWaitForever) == osOK); + furi_check(furi_mutex_acquire(music_player->model_mutex, FuriWaitForever) == FuriStatusOk); canvas_clear(canvas); canvas_set_color(canvas, ColorBlack); @@ -208,13 +208,13 @@ static void render_callback(Canvas* canvas, void* ctx) { canvas_draw_line(canvas, x_pos, 64 - 16 * i, x_pos + 48, 64 - 16 * i); } - osMutexRelease(music_player->model_mutex); + furi_mutex_release(music_player->model_mutex); } static void input_callback(InputEvent* input_event, void* ctx) { MusicPlayer* music_player = ctx; if(input_event->type == InputTypeShort) { - osMessageQueuePut(music_player->input_queue, input_event, 0, 0); + furi_message_queue_put(music_player->input_queue, input_event, 0); } } @@ -225,7 +225,7 @@ static void music_player_worker_callback( float position, void* context) { MusicPlayer* music_player = context; - furi_check(osMutexAcquire(music_player->model_mutex, osWaitForever) == osOK); + furi_check(furi_mutex_acquire(music_player->model_mutex, FuriWaitForever) == FuriStatusOk); for(size_t i = 0; i < MUSIC_PLAYER_SEMITONE_HISTORY_SIZE - 1; i++) { size_t r = MUSIC_PLAYER_SEMITONE_HISTORY_SIZE - 1 - i; @@ -243,7 +243,7 @@ static void music_player_worker_callback( music_player->model->semitone_history[0] = semitone; music_player->model->duration_history[0] = duration; - osMutexRelease(music_player->model_mutex); + furi_mutex_release(music_player->model_mutex); view_port_update(music_player->view_port); } @@ -255,9 +255,9 @@ MusicPlayer* music_player_alloc() { memset(instance->model->semitone_history, 0xff, MUSIC_PLAYER_SEMITONE_HISTORY_SIZE); instance->model->volume = 3; - instance->model_mutex = osMutexNew(NULL); + instance->model_mutex = furi_mutex_alloc(FuriMutexTypeNormal); - instance->input_queue = osMessageQueueNew(8, sizeof(InputEvent), NULL); + instance->input_queue = furi_message_queue_alloc(8, sizeof(InputEvent)); instance->worker = music_player_worker_alloc(); music_player_worker_set_volume( @@ -282,9 +282,9 @@ void music_player_free(MusicPlayer* instance) { music_player_worker_free(instance->worker); - osMessageQueueDelete(instance->input_queue); + furi_message_queue_free(instance->input_queue); - osMutexDelete(instance->model_mutex); + furi_mutex_free(instance->model_mutex); free(instance->model); free(instance); @@ -327,11 +327,13 @@ int32_t music_player_app(void* p) { music_player_worker_start(music_player->worker); InputEvent input; - while(osMessageQueueGet(music_player->input_queue, &input, NULL, osWaitForever) == osOK) { - furi_check(osMutexAcquire(music_player->model_mutex, osWaitForever) == osOK); + while(furi_message_queue_get(music_player->input_queue, &input, FuriWaitForever) == + FuriStatusOk) { + furi_check( + furi_mutex_acquire(music_player->model_mutex, FuriWaitForever) == FuriStatusOk); if(input.key == InputKeyBack) { - osMutexRelease(music_player->model_mutex); + furi_mutex_release(music_player->model_mutex); break; } else if(input.key == InputKeyUp) { if(music_player->model->volume < COUNT_OF(MUSIC_PLAYER_VOLUMES) - 1) @@ -344,7 +346,7 @@ int32_t music_player_app(void* p) { music_player->worker, MUSIC_PLAYER_VOLUMES[music_player->model->volume]); } - osMutexRelease(music_player->model_mutex); + furi_mutex_release(music_player->model_mutex); view_port_update(music_player->view_port); } diff --git a/applications/music_player/music_player_cli.c b/applications/music_player/music_player_cli.c index febb8b106..986c87816 100644 --- a/applications/music_player/music_player_cli.c +++ b/applications/music_player/music_player_cli.c @@ -26,7 +26,7 @@ static void music_player_cli(Cli* cli, string_t args, void* context) { music_player_worker_set_volume(music_player_worker, 1.0f); music_player_worker_start(music_player_worker); while(!cli_cmd_interrupt_received(cli)) { - osDelay(50); + furi_delay_ms(50); } music_player_worker_stop(music_player_worker); } while(0); diff --git a/applications/music_player/music_player_worker.c b/applications/music_player/music_player_worker.c index f43aa7be8..835745b70 100644 --- a/applications/music_player/music_player_worker.c +++ b/applications/music_player/music_player_worker.c @@ -51,20 +51,20 @@ static int32_t music_player_worker_thread_callback(void* context) { while(instance->should_work) { if(NoteBlockArray_end_p(it)) { NoteBlockArray_it(it, instance->notes); - osDelay(10); + furi_delay_ms(10); } else { NoteBlock* note_block = NoteBlockArray_ref(it); float note_from_a4 = (float)note_block->semitone - NOTE_C4_SEMITONE; float frequency = NOTE_C4 * powf(TWO_POW_TWELTH_ROOT, note_from_a4); float duration = - 60.0 * osKernelGetTickFreq() * 4 / instance->bpm / note_block->duration; + 60.0 * furi_kernel_get_tick_frequency() * 4 / instance->bpm / note_block->duration; uint32_t dots = note_block->dots; while(dots > 0) { duration += duration / 2; dots--; } - uint32_t next_tick = furi_hal_get_tick() + duration; + uint32_t next_tick = furi_get_tick() + duration; float volume = instance->volume; if(instance->callback) { @@ -78,10 +78,10 @@ static int32_t music_player_worker_thread_callback(void* context) { furi_hal_speaker_stop(); furi_hal_speaker_start(frequency, volume); - while(instance->should_work && furi_hal_get_tick() < next_tick) { + while(instance->should_work && furi_get_tick() < next_tick) { volume *= 0.9945679; furi_hal_speaker_set_volume(volume); - furi_hal_delay_ms(2); + furi_delay_ms(2); } NoteBlockArray_next(it); } diff --git a/applications/nfc/helpers/nfc_debug_pcap.c b/applications/nfc/helpers/nfc_debug_pcap.c index 85e020b6c..d340791b2 100644 --- a/applications/nfc/helpers/nfc_debug_pcap.c +++ b/applications/nfc/helpers/nfc_debug_pcap.c @@ -77,8 +77,8 @@ static void .event = event, .len = len << 8 | len >> 8, }; - xStreamBufferSend(instance->stream, &pkt_hdr, sizeof(pkt_hdr), osWaitForever); - xStreamBufferSend(instance->stream, data, len, osWaitForever); + xStreamBufferSend(instance->stream, &pkt_hdr, sizeof(pkt_hdr), FuriWaitForever); + xStreamBufferSend(instance->stream, data, len, FuriWaitForever); } static void diff --git a/applications/nfc/nfc_cli.c b/applications/nfc/nfc_cli.c index 9b77a29f3..bed007764 100755 --- a/applications/nfc/nfc_cli.c +++ b/applications/nfc/nfc_cli.c @@ -40,7 +40,7 @@ static void nfc_cli_detect(Cli* cli, string_t args) { break; } furi_hal_nfc_sleep(); - osDelay(50); + furi_delay_ms(50); } furi_hal_nfc_sleep(); } @@ -70,7 +70,7 @@ static void nfc_cli_emulate(Cli* cli, string_t args) { printf("Reader detected\r\n"); furi_hal_nfc_sleep(); } - osDelay(50); + furi_delay_ms(50); } furi_hal_nfc_sleep(); } @@ -90,7 +90,7 @@ static void nfc_cli_field(Cli* cli, string_t args) { printf("Press Ctrl+C to abort\r\n"); while(!cli_cmd_interrupt_received(cli)) { - osDelay(50); + furi_delay_ms(50); } furi_hal_nfc_field_off(); diff --git a/applications/nfc/nfc_worker.c b/applications/nfc/nfc_worker.c index 7d78fa747..0ca267365 100644 --- a/applications/nfc/nfc_worker.c +++ b/applications/nfc/nfc_worker.c @@ -23,7 +23,7 @@ NfcWorker* nfc_worker_alloc() { // Initialize rfal while(furi_hal_nfc_is_busy()) { - osDelay(10); + furi_delay_ms(10); } nfc_worker_change_state(nfc_worker, NfcWorkerStateReady); @@ -59,7 +59,7 @@ void nfc_worker_start( furi_assert(nfc_worker); furi_assert(dev_data); while(furi_hal_nfc_is_busy()) { - osDelay(10); + furi_delay_ms(10); } nfc_worker->callback = callback; @@ -148,7 +148,7 @@ void nfc_worker_detect(NfcWorker* nfc_worker) { break; } furi_hal_nfc_sleep(); - osDelay(100); + furi_delay_ms(100); } } @@ -203,7 +203,7 @@ void nfc_worker_read_emv_app(NfcWorker* nfc_worker) { FURI_LOG_D(TAG, "Can't find any cards"); } furi_hal_nfc_sleep(); - osDelay(20); + furi_delay_ms(20); } } @@ -252,7 +252,7 @@ void nfc_worker_read_emv(NfcWorker* nfc_worker) { FURI_LOG_D(TAG, "Can't find any cards"); } furi_hal_nfc_sleep(); - osDelay(20); + furi_delay_ms(20); } } @@ -277,7 +277,7 @@ void nfc_worker_emulate_apdu(NfcWorker* nfc_worker) { FURI_LOG_D(TAG, "Can't find reader"); } furi_hal_nfc_sleep(); - osDelay(20); + furi_delay_ms(20); } } @@ -312,7 +312,7 @@ void nfc_worker_read_mifare_ultralight(NfcWorker* nfc_worker) { FURI_LOG_D(TAG, "Can't find any tags"); } furi_hal_nfc_sleep(); - osDelay(100); + furi_delay_ms(100); } } @@ -434,7 +434,7 @@ void nfc_worker_mifare_classic_dict_attack(NfcWorker* nfc_worker) { } } if(nfc_worker->state != NfcWorkerStateReadMifareClassic) break; - osDelay(1); + furi_delay_tick(1); } if(nfc_worker->state != NfcWorkerStateReadMifareClassic) break; if(sector_key_found) { @@ -529,14 +529,14 @@ void nfc_worker_read_mifare_desfire(NfcWorker* nfc_worker) { while(nfc_worker->state == NfcWorkerStateReadMifareDesfire) { furi_hal_nfc_sleep(); if(!furi_hal_nfc_detect(nfc_data, 300)) { - osDelay(100); + furi_delay_ms(100); continue; } memset(data, 0, sizeof(MifareDesfireData)); if(nfc_data->type != FuriHalNfcTypeA || !mf_df_check_card_type(nfc_data->atqa[0], nfc_data->atqa[1], nfc_data->sak)) { FURI_LOG_D(TAG, "Tag is not DESFire"); - osDelay(100); + furi_delay_ms(100); continue; } diff --git a/applications/nfc/scenes/nfc_scene_emulate_apdu_sequence.c b/applications/nfc/scenes/nfc_scene_emulate_apdu_sequence.c index 2a6bb9449..e6062ba49 100644 --- a/applications/nfc/scenes/nfc_scene_emulate_apdu_sequence.c +++ b/applications/nfc/scenes/nfc_scene_emulate_apdu_sequence.c @@ -1,5 +1,5 @@ #include "../nfc_i.h" -#include "furi/common_defines.h" +#include void nfc_scene_emulate_apdu_sequence_on_enter(void* context) { Nfc* nfc = context; diff --git a/applications/notification/notification_app.c b/applications/notification/notification_app.c index 9f362358a..437d20ab8 100644 --- a/applications/notification/notification_app.c +++ b/applications/notification/notification_app.c @@ -30,10 +30,12 @@ uint8_t notification_settings_get_rgb_led_brightness(NotificationApp* app, uint8 uint32_t notification_settings_display_off_delay_ticks(NotificationApp* app); void notification_message_save_settings(NotificationApp* app) { - NotificationAppMessage m = {.type = SaveSettingsMessage, .back_event = osEventFlagsNew(NULL)}; - furi_check(osMessageQueuePut(app->queue, &m, 0, osWaitForever) == osOK); - osEventFlagsWait(m.back_event, NOTIFICATION_EVENT_COMPLETE, osFlagsWaitAny, osWaitForever); - osEventFlagsDelete(m.back_event); + NotificationAppMessage m = { + .type = SaveSettingsMessage, .back_event = furi_event_flag_alloc()}; + furi_check(furi_message_queue_put(app->queue, &m, FuriWaitForever) == FuriStatusOk); + furi_event_flag_wait( + m.back_event, NOTIFICATION_EVENT_COMPLETE, FuriFlagWaitAny, FuriWaitForever); + furi_event_flag_free(m.back_event); }; // internal layer @@ -112,7 +114,7 @@ void notification_reset_notification_layer(NotificationApp* app, uint8_t reset_m notification_sound_off(); } if(reset_mask & reset_display_mask) { - osTimerStart(app->display_timer, notification_settings_display_off_delay_ticks(app)); + furi_timer_start(app->display_timer, notification_settings_display_off_delay_ticks(app)); } } @@ -133,7 +135,9 @@ uint8_t notification_settings_get_rgb_led_brightness(NotificationApp* app, uint8 } uint32_t notification_settings_display_off_delay_ticks(NotificationApp* app) { - return ((float)(app->settings.display_off_delay_ms) / (1000.0f / osKernelGetTickFreq())); + return ( + (float)(app->settings.display_off_delay_ms) / + (1000.0f / furi_kernel_get_tick_frequency())); } // generics @@ -189,8 +193,8 @@ void notification_process_notification_message( notification_message->data.led.value * display_brightness_setting); } else { notification_reset_notification_led_layer(&app->display); - if(osTimerIsRunning(app->display_timer)) { - osTimerStop(app->display_timer); + if(furi_timer_is_running(app->display_timer)) { + furi_timer_stop(app->display_timer); } } reset_mask |= reset_display_mask; @@ -280,7 +284,7 @@ void notification_process_notification_message( if(led_active) { if(notification_is_any_led_layer_internal_and_not_empty(app)) { notification_apply_notification_leds(app, led_off_values); - furi_hal_delay_ms(minimal_delay); + furi_delay_ms(minimal_delay); } led_active = false; @@ -291,7 +295,7 @@ void notification_process_notification_message( reset_mask |= reset_blue_mask; } - furi_hal_delay_ms(notification_message->data.delay.length); + furi_delay_ms(notification_message->data.delay.length); break; case NotificationMessageTypeDoNotReset: reset_notifications = false; @@ -334,7 +338,7 @@ void notification_process_notification_message( if((need_minimal_delay) && (reset_notifications)) { notification_apply_notification_leds(app, led_off_values); - furi_hal_delay_ms(minimal_delay); + furi_delay_ms(minimal_delay); } } @@ -416,9 +420,9 @@ static bool notification_load_settings(NotificationApp* app) { FURI_LOG_E( TAG, "version(%d != %d) mismatch", settings.version, NOTIFICATION_SETTINGS_VERSION); } else { - osKernelLock(); + furi_kernel_lock(); memcpy(&app->settings, &settings, settings_size); - osKernelUnlock(); + furi_kernel_unlock(); } } else { FURI_LOG_E(TAG, "load failed, %s", storage_file_get_error_desc(file)); @@ -438,9 +442,9 @@ static bool notification_save_settings(NotificationApp* app) { FURI_LOG_I(TAG, "saving settings to \"%s\"", NOTIFICATION_SETTINGS_PATH); - osKernelLock(); + furi_kernel_lock(); memcpy(&settings, &app->settings, settings_size); - osKernelUnlock(); + furi_kernel_unlock(); bool fs_result = storage_file_open(file, NOTIFICATION_SETTINGS_PATH, FSAM_WRITE, FSOM_CREATE_ALWAYS); @@ -476,8 +480,8 @@ static void input_event_callback(const void* value, void* context) { // App alloc static NotificationApp* notification_app_alloc() { NotificationApp* app = malloc(sizeof(NotificationApp)); - app->queue = osMessageQueueNew(8, sizeof(NotificationAppMessage), NULL); - app->display_timer = osTimerNew(notification_display_timer, osTimerOnce, app, NULL); + app->queue = furi_message_queue_alloc(8, sizeof(NotificationAppMessage)); + app->display_timer = furi_timer_alloc(notification_display_timer, FuriTimerTypeOnce, app); app->settings.speaker_volume = 1.0f; app->settings.display_brightness = 1.0f; @@ -535,7 +539,7 @@ int32_t notification_srv(void* p) { NotificationAppMessage message; while(1) { - furi_check(osMessageQueueGet(app->queue, &message, NULL, osWaitForever) == osOK); + furi_check(furi_message_queue_get(app->queue, &message, FuriWaitForever) == FuriStatusOk); switch(message.type) { case NotificationLayerMessage: @@ -550,7 +554,7 @@ int32_t notification_srv(void* p) { } if(message.back_event != NULL) { - osEventFlagsSet(message.back_event, NOTIFICATION_EVENT_COMPLETE); + furi_event_flag_set(message.back_event, NOTIFICATION_EVENT_COMPLETE); } } diff --git a/applications/notification/notification_app.h b/applications/notification/notification_app.h index b56b7e3b7..f5c7cc46e 100644 --- a/applications/notification/notification_app.h +++ b/applications/notification/notification_app.h @@ -15,7 +15,7 @@ typedef enum { typedef struct { const NotificationSequence* sequence; NotificationAppMessageType type; - osEventFlagsId_t back_event; + FuriEventFlag* back_event; } NotificationAppMessage; typedef enum { @@ -44,9 +44,9 @@ typedef struct { } NotificationSettings; struct NotificationApp { - osMessageQueueId_t queue; + FuriMessageQueue* queue; FuriPubSub* event_record; - osTimerId_t display_timer; + FuriTimer* display_timer; NotificationLedLayer display; NotificationLedLayer led[NOTIFICATION_LED_COUNT]; diff --git a/applications/notification/notification_app_api.c b/applications/notification/notification_app_api.c index d11a289ba..9bc06b013 100644 --- a/applications/notification/notification_app_api.c +++ b/applications/notification/notification_app_api.c @@ -7,31 +7,33 @@ void notification_message(NotificationApp* app, const NotificationSequence* sequence) { NotificationAppMessage m = { .type = NotificationLayerMessage, .sequence = sequence, .back_event = NULL}; - furi_check(osMessageQueuePut(app->queue, &m, 0, osWaitForever) == osOK); + furi_check(furi_message_queue_put(app->queue, &m, FuriWaitForever) == FuriStatusOk); }; void notification_internal_message(NotificationApp* app, const NotificationSequence* sequence) { NotificationAppMessage m = { .type = InternalLayerMessage, .sequence = sequence, .back_event = NULL}; - furi_check(osMessageQueuePut(app->queue, &m, 0, osWaitForever) == osOK); + furi_check(furi_message_queue_put(app->queue, &m, FuriWaitForever) == FuriStatusOk); }; void notification_message_block(NotificationApp* app, const NotificationSequence* sequence) { NotificationAppMessage m = { .type = NotificationLayerMessage, .sequence = sequence, - .back_event = osEventFlagsNew(NULL)}; - furi_check(osMessageQueuePut(app->queue, &m, 0, osWaitForever) == osOK); - osEventFlagsWait(m.back_event, NOTIFICATION_EVENT_COMPLETE, osFlagsWaitAny, osWaitForever); - osEventFlagsDelete(m.back_event); + .back_event = furi_event_flag_alloc()}; + furi_check(furi_message_queue_put(app->queue, &m, FuriWaitForever) == FuriStatusOk); + furi_event_flag_wait( + m.back_event, NOTIFICATION_EVENT_COMPLETE, FuriFlagWaitAny, FuriWaitForever); + furi_event_flag_free(m.back_event); }; void notification_internal_message_block( NotificationApp* app, const NotificationSequence* sequence) { NotificationAppMessage m = { - .type = InternalLayerMessage, .sequence = sequence, .back_event = osEventFlagsNew(NULL)}; - furi_check(osMessageQueuePut(app->queue, &m, 0, osWaitForever) == osOK); - osEventFlagsWait(m.back_event, NOTIFICATION_EVENT_COMPLETE, osFlagsWaitAny, osWaitForever); - osEventFlagsDelete(m.back_event); + .type = InternalLayerMessage, .sequence = sequence, .back_event = furi_event_flag_alloc()}; + furi_check(furi_message_queue_put(app->queue, &m, FuriWaitForever) == FuriStatusOk); + furi_event_flag_wait( + m.back_event, NOTIFICATION_EVENT_COMPLETE, FuriFlagWaitAny, FuriWaitForever); + furi_event_flag_free(m.back_event); }; diff --git a/applications/picopass/picopass_worker.c b/applications/picopass/picopass_worker.c index 40fe44489..645a1bce9 100644 --- a/applications/picopass/picopass_worker.c +++ b/applications/picopass/picopass_worker.c @@ -305,6 +305,6 @@ void picopass_worker_detect(PicopassWorker* picopass_worker) { } break; } - osDelay(100); + furi_delay_ms(100); } } diff --git a/applications/power/power_cli.c b/applications/power/power_cli.c index d474a729c..8c6a986d2 100644 --- a/applications/power/power_cli.c +++ b/applications/power/power_cli.c @@ -10,7 +10,7 @@ void power_cli_off(Cli* cli, string_t args) { UNUSED(args); Power* power = furi_record_open("power"); printf("It's now safe to disconnect USB from your flipper\r\n"); - osDelay(666); + furi_delay_ms(666); power_off(power); } diff --git a/applications/power/power_service/power.c b/applications/power/power_service/power.c index 1315809e9..991c2a81d 100644 --- a/applications/power/power_service/power.c +++ b/applications/power/power_service/power.c @@ -51,7 +51,7 @@ Power* power_alloc() { power->state = PowerStateNotCharging; power->battery_low = false; power->power_off_timeout = POWER_OFF_TIMEOUT; - power->api_mtx = osMutexNew(NULL); + power->api_mtx = furi_mutex_alloc(FuriMutexTypeNormal); // Gui power->view_dispatcher = view_dispatcher_alloc(); @@ -83,7 +83,7 @@ void power_free(Power* power) { view_port_free(power->battery_view_port); // State - osMutexDelete(power->api_mtx); + furi_mutex_free(power->api_mtx); // FuriPubSub furi_pubsub_free(power->event_pubsub); @@ -138,10 +138,10 @@ static bool power_update_info(Power* power) { info.temperature_charger = furi_hal_power_get_battery_temperature(FuriHalPowerICCharger); info.temperature_gauge = furi_hal_power_get_battery_temperature(FuriHalPowerICFuelGauge); - osMutexAcquire(power->api_mtx, osWaitForever); + furi_mutex_acquire(power->api_mtx, FuriWaitForever); bool need_refresh = power->info.charge != info.charge; power->info = info; - osMutexRelease(power->api_mtx); + furi_mutex_release(power->api_mtx); return need_refresh; } @@ -226,7 +226,7 @@ int32_t power_srv(void* p) { furi_hal_power_check_otg_status(); } - osDelay(1000); + furi_delay_ms(1000); } power_free(power); diff --git a/applications/power/power_service/power.h b/applications/power/power_service/power.h index c32c31b33..cea1663f4 100644 --- a/applications/power/power_service/power.h +++ b/applications/power/power_service/power.h @@ -1,7 +1,7 @@ #pragma once #include -#include +#include #include typedef struct Power Power; diff --git a/applications/power/power_service/power_api.c b/applications/power/power_service/power_api.c index 865c21c80..d26fb3b4f 100644 --- a/applications/power/power_service/power_api.c +++ b/applications/power/power_service/power_api.c @@ -9,7 +9,7 @@ void power_off(Power* power) { // Notify user if USB is plugged view_dispatcher_send_to_front(power->view_dispatcher); view_dispatcher_switch_to_view(power->view_dispatcher, PowerViewPopup); - osDelay(10); + furi_delay_ms(10); furi_halt("Disconnect USB for safe shutdown"); } @@ -28,9 +28,9 @@ void power_get_info(Power* power, PowerInfo* info) { furi_assert(power); furi_assert(info); - osMutexAcquire(power->api_mtx, osWaitForever); + furi_mutex_acquire(power->api_mtx, FuriWaitForever); memcpy(info, &power->info, sizeof(power->info)); - osMutexRelease(power->api_mtx); + furi_mutex_release(power->api_mtx); } FuriPubSub* power_get_pubsub(Power* power) { @@ -41,15 +41,15 @@ FuriPubSub* power_get_pubsub(Power* power) { bool power_is_battery_healthy(Power* power) { furi_assert(power); bool is_healthy = false; - osMutexAcquire(power->api_mtx, osWaitForever); + furi_mutex_acquire(power->api_mtx, FuriWaitForever); is_healthy = power->info.health > POWER_BATTERY_HEALTHY_LEVEL; - osMutexRelease(power->api_mtx); + furi_mutex_release(power->api_mtx); return is_healthy; } void power_enable_low_battery_level_notification(Power* power, bool enable) { furi_assert(power); - osMutexAcquire(power->api_mtx, osWaitForever); + furi_mutex_acquire(power->api_mtx, FuriWaitForever); power->show_low_bat_level_message = enable; - osMutexRelease(power->api_mtx); + furi_mutex_release(power->api_mtx); } diff --git a/applications/power/power_service/power_i.h b/applications/power/power_service/power_i.h index f88b8f24b..c7181d0a1 100755 --- a/applications/power/power_service/power_i.h +++ b/applications/power/power_service/power_i.h @@ -38,7 +38,7 @@ struct Power { uint8_t battery_level; uint8_t power_off_timeout; - osMutexId_t api_mtx; + FuriMutex* api_mtx; }; typedef enum { diff --git a/applications/rpc/rpc.c b/applications/rpc/rpc.c index ce063b8e4..a85d0a420 100644 --- a/applications/rpc/rpc.c +++ b/applications/rpc/rpc.c @@ -68,7 +68,7 @@ struct RpcSession { void** system_contexts; bool decode_error; - osMutexId_t callbacks_mutex; + FuriMutex* callbacks_mutex; RpcSendBytesCallback send_bytes_callback; RpcBufferIsEmptyCallback buffer_is_empty_callback; RpcSessionClosedCallback closed_callback; @@ -77,7 +77,7 @@ struct RpcSession { }; struct Rpc { - osMutexId_t busy_mutex; + FuriMutex* busy_mutex; }; static bool content_callback(pb_istream_t* stream, const pb_field_t* field, void** arg); @@ -89,13 +89,13 @@ static void rpc_close_session_process(const PB_Main* request, void* context) { furi_assert(session); rpc_send_and_release_empty(session, request->command_id, PB_CommandStatus_OK); - osMutexAcquire(session->callbacks_mutex, osWaitForever); + furi_mutex_acquire(session->callbacks_mutex, FuriWaitForever); if(session->closed_callback) { session->closed_callback(session->context); } else { FURI_LOG_W(TAG, "Session stop isn't processed by transport layer"); } - osMutexRelease(session->callbacks_mutex); + furi_mutex_release(session->callbacks_mutex); } static size_t rpc_sprintf_msg_file( @@ -359,25 +359,25 @@ void rpc_print_message(const PB_Main* message) { void rpc_session_set_context(RpcSession* session, void* context) { furi_assert(session); - osMutexAcquire(session->callbacks_mutex, osWaitForever); + furi_mutex_acquire(session->callbacks_mutex, FuriWaitForever); session->context = context; - osMutexRelease(session->callbacks_mutex); + furi_mutex_release(session->callbacks_mutex); } void rpc_session_set_close_callback(RpcSession* session, RpcSessionClosedCallback callback) { furi_assert(session); - osMutexAcquire(session->callbacks_mutex, osWaitForever); + furi_mutex_acquire(session->callbacks_mutex, FuriWaitForever); session->closed_callback = callback; - osMutexRelease(session->callbacks_mutex); + furi_mutex_release(session->callbacks_mutex); } void rpc_session_set_send_bytes_callback(RpcSession* session, RpcSendBytesCallback callback) { furi_assert(session); - osMutexAcquire(session->callbacks_mutex, osWaitForever); + furi_mutex_acquire(session->callbacks_mutex, FuriWaitForever); session->send_bytes_callback = callback; - osMutexRelease(session->callbacks_mutex); + furi_mutex_release(session->callbacks_mutex); } void rpc_session_set_buffer_is_empty_callback( @@ -385,9 +385,9 @@ void rpc_session_set_buffer_is_empty_callback( RpcBufferIsEmptyCallback callback) { furi_assert(session); - osMutexAcquire(session->callbacks_mutex, osWaitForever); + furi_mutex_acquire(session->callbacks_mutex, FuriWaitForever); session->buffer_is_empty_callback = callback; - osMutexRelease(session->callbacks_mutex); + furi_mutex_release(session->callbacks_mutex); } void rpc_session_set_terminated_callback( @@ -395,9 +395,9 @@ void rpc_session_set_terminated_callback( RpcSessionTerminatedCallback callback) { furi_assert(session); - osMutexAcquire(session->callbacks_mutex, osWaitForever); + furi_mutex_acquire(session->callbacks_mutex, FuriWaitForever); session->terminated_callback = callback; - osMutexRelease(session->callbacks_mutex); + furi_mutex_release(session->callbacks_mutex); } /* Doesn't forbid using rpc_feed_bytes() after session close - it's safe. @@ -444,7 +444,7 @@ bool rpc_pb_stream_read(pb_istream_t* istream, pb_byte_t* buf, size_t count) { if(count == bytes_received) { break; } else { - flags = furi_thread_flags_wait(RPC_ALL_EVENTS, osFlagsWaitAny, osWaitForever); + flags = furi_thread_flags_wait(RPC_ALL_EVENTS, FuriFlagWaitAny, FuriWaitForever); if(flags & RpcEvtDisconnect) { if(xStreamBufferIsEmpty(session->stream)) { session->terminate = true; @@ -508,9 +508,9 @@ static int32_t rpc_session_worker(void* context) { RpcHandlerDict_get(session->handlers, session->decoded_message->which_content); if(handler && handler->message_handler) { - furi_check(osMutexAcquire(rpc->busy_mutex, osWaitForever) == osOK); + furi_check(furi_mutex_acquire(rpc->busy_mutex, FuriWaitForever) == FuriStatusOk); handler->message_handler(session->decoded_message, handler->context); - furi_check(osMutexRelease(rpc->busy_mutex) == osOK); + furi_check(furi_mutex_release(rpc->busy_mutex) == FuriStatusOk); } else if(session->decoded_message->which_content == 0) { /* Receiving zeroes means message is 0-length, which * is valid for proto3: all fields are filled with default values. @@ -551,11 +551,11 @@ static int32_t rpc_session_worker(void* context) { FURI_LOG_E(TAG, "Decode failed, error: \'%.128s\'", PB_GET_ERROR(&istream)); session->decode_error = true; rpc_send_and_release_empty(session, 0, PB_CommandStatus_ERROR_DECODE); - osMutexAcquire(session->callbacks_mutex, osWaitForever); + furi_mutex_acquire(session->callbacks_mutex, FuriWaitForever); if(session->closed_callback) { session->closed_callback(session->context); } - osMutexRelease(session->callbacks_mutex); + furi_mutex_release(session->callbacks_mutex); } } @@ -586,13 +586,13 @@ static void rpc_session_free_callback(FuriThreadState thread_state, void* contex RpcHandlerDict_clear(session->handlers); vStreamBufferDelete(session->stream); - osMutexAcquire(session->callbacks_mutex, osWaitForever); + furi_mutex_acquire(session->callbacks_mutex, FuriWaitForever); if(session->terminated_callback) { session->terminated_callback(session->context); } - osMutexRelease(session->callbacks_mutex); + furi_mutex_release(session->callbacks_mutex); - osMutexDelete(session->callbacks_mutex); + furi_mutex_free(session->callbacks_mutex); furi_thread_free(session->thread); free(session); } @@ -602,7 +602,7 @@ RpcSession* rpc_session_open(Rpc* rpc) { furi_assert(rpc); RpcSession* session = malloc(sizeof(RpcSession)); - session->callbacks_mutex = osMutexNew(NULL); + session->callbacks_mutex = furi_mutex_alloc(FuriMutexTypeNormal); session->stream = xStreamBufferCreate(RPC_BUFFER_SIZE, 1); session->rpc = rpc; session->terminate = false; @@ -653,7 +653,7 @@ int32_t rpc_srv(void* p) { UNUSED(p); Rpc* rpc = malloc(sizeof(Rpc)); - rpc->busy_mutex = osMutexNew(NULL); + rpc->busy_mutex = furi_mutex_alloc(FuriMutexTypeNormal); Cli* cli = furi_record_open("cli"); cli_add_command( @@ -693,11 +693,11 @@ void rpc_send(RpcSession* session, PB_Main* message) { rpc_print_data("OUTPUT", buffer, ostream.bytes_written); #endif - osMutexAcquire(session->callbacks_mutex, osWaitForever); + furi_mutex_acquire(session->callbacks_mutex, FuriWaitForever); if(session->send_bytes_callback) { session->send_bytes_callback(session->context, buffer, ostream.bytes_written); } - osMutexRelease(session->callbacks_mutex); + furi_mutex_release(session->callbacks_mutex); free(buffer); } diff --git a/applications/rpc/rpc_app.c b/applications/rpc/rpc_app.c index f6678c3b6..84cb54107 100644 --- a/applications/rpc/rpc_app.c +++ b/applications/rpc/rpc_app.c @@ -1,6 +1,5 @@ -#include "cmsis_os2.h" #include "flipper.pb.h" -#include "furi/record.h" +#include #include "rpc_i.h" #include #include @@ -13,7 +12,7 @@ struct RpcAppSystem { RpcSession* session; RpcAppSystemCallback app_callback; void* app_context; - osTimerId_t timer; + FuriTimer* timer; }; static void rpc_system_app_timer_callback(void* context) { @@ -111,7 +110,7 @@ static void rpc_system_app_exit(const PB_Main* request, void* context) { if(rpc_app->app_callback) { if(rpc_app->app_callback(RpcAppEventAppExit, NULL, rpc_app->app_context)) { status = PB_CommandStatus_OK; - osTimerStop(rpc_app->timer); + furi_timer_stop(rpc_app->timer); } else { status = PB_CommandStatus_ERROR_APP_CMD_ERROR; } @@ -160,7 +159,7 @@ static void rpc_system_app_button_press(const PB_Main* request, void* context) { const char* args = request->content.app_button_press_request.args; if(rpc_app->app_callback(RpcAppEventButtonPress, args, rpc_app->app_context)) { status = PB_CommandStatus_OK; - osTimerStart(rpc_app->timer, APP_BUTTON_TIMEOUT); + furi_timer_start(rpc_app->timer, APP_BUTTON_TIMEOUT); } else { status = PB_CommandStatus_ERROR_APP_CMD_ERROR; } @@ -184,7 +183,7 @@ static void rpc_system_app_button_release(const PB_Main* request, void* context) if(rpc_app->app_callback) { if(rpc_app->app_callback(RpcAppEventButtonRelease, NULL, rpc_app->app_context)) { status = PB_CommandStatus_OK; - osTimerStop(rpc_app->timer); + furi_timer_stop(rpc_app->timer); } else { status = PB_CommandStatus_ERROR_APP_CMD_ERROR; } @@ -208,7 +207,7 @@ void* rpc_system_app_alloc(RpcSession* session) { RpcAppSystem* rpc_app = malloc(sizeof(RpcAppSystem)); rpc_app->session = session; - rpc_app->timer = osTimerNew(rpc_system_app_timer_callback, osTimerOnce, rpc_app, NULL); + rpc_app->timer = furi_timer_alloc(rpc_system_app_timer_callback, FuriTimerTypeOnce, rpc_app); RpcHandler rpc_handler = { .message_handler = NULL, @@ -242,7 +241,7 @@ void rpc_system_app_free(void* context) { RpcSession* session = rpc_app->session; furi_assert(session); - osTimerDelete(rpc_app->timer); + furi_timer_free(rpc_app->timer); if(rpc_app->app_callback) { rpc_app->app_callback(RpcAppEventSessionClose, NULL, rpc_app->app_context); diff --git a/applications/rpc/rpc_cli.c b/applications/rpc/rpc_cli.c index 1c8991bc6..efc672193 100644 --- a/applications/rpc/rpc_cli.c +++ b/applications/rpc/rpc_cli.c @@ -9,7 +9,7 @@ typedef struct { Cli* cli; bool session_close_request; - osSemaphoreId_t terminate_semaphore; + FuriSemaphore* terminate_semaphore; } CliRpc; #define CLI_READ_BUFFER_SIZE 64 @@ -34,7 +34,7 @@ static void rpc_session_terminated_callback(void* context) { furi_check(context); CliRpc* cli_rpc = context; - osSemaphoreRelease(cli_rpc->terminate_semaphore); + furi_semaphore_release(cli_rpc->terminate_semaphore); } void rpc_cli_command_start_session(Cli* cli, string_t args, void* context) { @@ -53,7 +53,7 @@ void rpc_cli_command_start_session(Cli* cli, string_t args, void* context) { } CliRpc cli_rpc = {.cli = cli, .session_close_request = false}; - cli_rpc.terminate_semaphore = osSemaphoreNew(1, 0, NULL); + cli_rpc.terminate_semaphore = furi_semaphore_alloc(1, 0); rpc_session_set_context(rpc_session, &cli_rpc); rpc_session_set_send_bytes_callback(rpc_session, rpc_send_bytes_callback); rpc_session_set_close_callback(rpc_session, rpc_session_close_callback); @@ -77,9 +77,10 @@ void rpc_cli_command_start_session(Cli* cli, string_t args, void* context) { rpc_session_close(rpc_session); - furi_check(osSemaphoreAcquire(cli_rpc.terminate_semaphore, osWaitForever) == osOK); + furi_check( + furi_semaphore_acquire(cli_rpc.terminate_semaphore, FuriWaitForever) == FuriStatusOk); - osSemaphoreDelete(cli_rpc.terminate_semaphore); + furi_semaphore_free(cli_rpc.terminate_semaphore); free(buffer); furi_hal_usb_unlock(); diff --git a/applications/rpc/rpc_gui.c b/applications/rpc/rpc_gui.c index da91ae06e..62a232d8f 100644 --- a/applications/rpc/rpc_gui.c +++ b/applications/rpc/rpc_gui.c @@ -50,7 +50,7 @@ static int32_t rpc_system_gui_screen_stream_frame_transmit_thread(void* context) while(true) { uint32_t flags = - furi_thread_flags_wait(RpcGuiWorkerFlagAny, osFlagsWaitAny, osWaitForever); + furi_thread_flags_wait(RpcGuiWorkerFlagAny, FuriFlagWaitAny, FuriWaitForever); if(flags & RpcGuiWorkerFlagTransmit) { rpc_send(rpc_gui->session, rpc_gui->transmit_frame); } diff --git a/applications/rpc/rpc_storage.c b/applications/rpc/rpc_storage.c index 336346b5e..4ab681ae9 100644 --- a/applications/rpc/rpc_storage.c +++ b/applications/rpc/rpc_storage.c @@ -1,7 +1,7 @@ #include "flipper.pb.h" -#include "furi/common_defines.h" -#include "furi/memmgr.h" -#include "furi/record.h" +#include +#include +#include #include "pb_decode.h" #include "rpc/rpc.h" #include "rpc_i.h" diff --git a/applications/snake_game/snake_game.c b/applications/snake_game/snake_game.c index 1a4bf8126..bfd31ced0 100644 --- a/applications/snake_game/snake_game.c +++ b/applications/snake_game/snake_game.c @@ -105,18 +105,18 @@ static void snake_game_render_callback(Canvas* const canvas, void* ctx) { release_mutex((ValueMutex*)ctx, snake_state); } -static void snake_game_input_callback(InputEvent* input_event, osMessageQueueId_t event_queue) { +static void snake_game_input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) { furi_assert(event_queue); SnakeEvent event = {.type = EventTypeKey, .input = *input_event}; - osMessageQueuePut(event_queue, &event, 0, osWaitForever); + furi_message_queue_put(event_queue, &event, FuriWaitForever); } -static void snake_game_update_timer_callback(osMessageQueueId_t event_queue) { +static void snake_game_update_timer_callback(FuriMessageQueue* event_queue) { furi_assert(event_queue); SnakeEvent event = {.type = EventTypeTick}; - osMessageQueuePut(event_queue, &event, 0, 0); + furi_message_queue_put(event_queue, &event, 0); } static void snake_game_init_game(SnakeState* const snake_state) { @@ -283,7 +283,7 @@ int32_t snake_game_app(void* p) { UNUSED(p); srand(DWT->CYCCNT); - osMessageQueueId_t event_queue = osMessageQueueNew(8, sizeof(SnakeEvent), NULL); + FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(SnakeEvent)); SnakeState* snake_state = malloc(sizeof(SnakeState)); snake_game_init_game(snake_state); @@ -299,9 +299,9 @@ int32_t snake_game_app(void* p) { view_port_draw_callback_set(view_port, snake_game_render_callback, &state_mutex); view_port_input_callback_set(view_port, snake_game_input_callback, event_queue); - osTimerId_t timer = - osTimerNew(snake_game_update_timer_callback, osTimerPeriodic, event_queue, NULL); - osTimerStart(timer, osKernelGetTickFreq() / 4); + FuriTimer* timer = + furi_timer_alloc(snake_game_update_timer_callback, FuriTimerTypePeriodic, event_queue); + furi_timer_start(timer, furi_kernel_get_tick_frequency() / 4); // Open GUI and register view_port Gui* gui = furi_record_open("gui"); @@ -309,11 +309,11 @@ int32_t snake_game_app(void* p) { SnakeEvent event; for(bool processing = true; processing;) { - osStatus_t event_status = osMessageQueueGet(event_queue, &event, NULL, 100); + FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100); SnakeState* snake_state = (SnakeState*)acquire_mutex_block(&state_mutex); - if(event_status == osOK) { + if(event_status == FuriStatusOk) { // press events if(event.type == EventTypeKey) { if(event.input.type == InputTypePress) { @@ -351,12 +351,12 @@ int32_t snake_game_app(void* p) { release_mutex(&state_mutex, snake_state); } - osTimerDelete(timer); + furi_timer_free(timer); view_port_enabled_set(view_port, false); gui_remove_view_port(gui, view_port); furi_record_close("gui"); view_port_free(view_port); - osMessageQueueDelete(event_queue); + furi_message_queue_free(event_queue); delete_mutex(&state_mutex); free(snake_state); diff --git a/applications/storage/storage.c b/applications/storage/storage.c index b280547b7..90a191a2e 100644 --- a/applications/storage/storage.c +++ b/applications/storage/storage.c @@ -33,7 +33,7 @@ static void storage_app_sd_icon_draw_callback(Canvas* canvas, void* context) { Storage* storage_app_alloc() { Storage* app = malloc(sizeof(Storage)); - app->message_queue = osMessageQueueNew(8, sizeof(StorageMessage), NULL); + app->message_queue = furi_message_queue_alloc(8, sizeof(StorageMessage)); app->pubsub = furi_pubsub_alloc(); for(uint8_t i = 0; i < STORAGE_COUNT; i++) { @@ -106,7 +106,7 @@ int32_t storage_srv(void* p) { StorageMessage message; while(1) { - if(osMessageQueueGet(app->message_queue, &message, NULL, STORAGE_TICK) == osOK) { + if(furi_message_queue_get(app->message_queue, &message, STORAGE_TICK) == FuriStatusOk) { storage_process_message(app, &message); } else { storage_tick(app); diff --git a/applications/storage/storage_external_api.c b/applications/storage/storage_external_api.c index dc29faa67..426fac9a4 100644 --- a/applications/storage/storage_external_api.c +++ b/applications/storage/storage_external_api.c @@ -1,5 +1,5 @@ -#include "furi/log.h" -#include +#include +#include #include #include "storage.h" #include "storage_i.h" @@ -13,18 +13,20 @@ #define TAG "StorageAPI" -#define S_API_PROLOGUE \ - osSemaphoreId_t semaphore = osSemaphoreNew(1, 0, NULL); \ +#define S_API_PROLOGUE \ + FuriSemaphore* semaphore = furi_semaphore_alloc(1, 0); \ furi_check(semaphore != NULL); #define S_FILE_API_PROLOGUE \ Storage* storage = file->storage; \ furi_assert(storage); -#define S_API_EPILOGUE \ - furi_check(osMessageQueuePut(storage->message_queue, &message, 0, osWaitForever) == osOK); \ - osSemaphoreAcquire(semaphore, osWaitForever); \ - osSemaphoreDelete(semaphore); +#define S_API_EPILOGUE \ + furi_check( \ + furi_message_queue_put(storage->message_queue, &message, FuriWaitForever) == \ + FuriStatusOk); \ + furi_semaphore_acquire(semaphore, FuriWaitForever); \ + furi_semaphore_free(semaphore); #define S_API_MESSAGE(_command) \ SAReturn return_data; \ @@ -88,8 +90,8 @@ static void storage_file_close_callback(const void* message, void* context) { if(storage_event->type == StorageEventTypeFileClose || storage_event->type == StorageEventTypeDirClose) { furi_assert(context); - osEventFlagsId_t event = context; - osEventFlagsSet(event, StorageEventFlagFileClose); + FuriEventFlag* event = context; + furi_event_flag_set(event, StorageEventFlagFileClose); } } @@ -99,7 +101,7 @@ bool storage_file_open( FS_AccessMode access_mode, FS_OpenMode open_mode) { bool result; - osEventFlagsId_t event = osEventFlagsNew(NULL); + FuriEventFlag* event = furi_event_flag_alloc(); FuriPubSubSubscription* subscription = furi_pubsub_subscribe( storage_get_pubsub(file->storage), storage_file_close_callback, event); @@ -107,14 +109,15 @@ bool storage_file_open( result = storage_file_open_internal(file, path, access_mode, open_mode); if(!result && file->error_id == FSE_ALREADY_OPEN) { - osEventFlagsWait(event, StorageEventFlagFileClose, osFlagsWaitAny, osWaitForever); + furi_event_flag_wait( + event, StorageEventFlagFileClose, FuriFlagWaitAny, FuriWaitForever); } else { break; } } while(true); furi_pubsub_unsubscribe(storage_get_pubsub(file->storage), subscription); - osEventFlagsDelete(event); + furi_event_flag_free(event); FURI_LOG_T( TAG, "File %p - %p open (%s)", (uint32_t)file - SRAM_BASE, file->file_id - SRAM_BASE, path); @@ -258,7 +261,7 @@ static bool storage_dir_open_internal(File* file, const char* path) { bool storage_dir_open(File* file, const char* path) { bool result; - osEventFlagsId_t event = osEventFlagsNew(NULL); + FuriEventFlag* event = furi_event_flag_alloc(); FuriPubSubSubscription* subscription = furi_pubsub_subscribe( storage_get_pubsub(file->storage), storage_file_close_callback, event); @@ -266,14 +269,15 @@ bool storage_dir_open(File* file, const char* path) { result = storage_dir_open_internal(file, path); if(!result && file->error_id == FSE_ALREADY_OPEN) { - osEventFlagsWait(event, StorageEventFlagFileClose, osFlagsWaitAny, osWaitForever); + furi_event_flag_wait( + event, StorageEventFlagFileClose, FuriFlagWaitAny, FuriWaitForever); } else { break; } } while(true); furi_pubsub_unsubscribe(storage_get_pubsub(file->storage), subscription); - osEventFlagsDelete(event); + furi_event_flag_free(event); FURI_LOG_T( TAG, "Dir %p - %p open (%s)", (uint32_t)file - SRAM_BASE, file->file_id - SRAM_BASE, path); diff --git a/applications/storage/storage_glue.c b/applications/storage/storage_glue.c index 09656ae34..d9d599c5c 100644 --- a/applications/storage/storage_glue.c +++ b/applications/storage/storage_glue.c @@ -31,7 +31,7 @@ void storage_file_clear(StorageFile* obj) { /****************** storage data ******************/ void storage_data_init(StorageData* storage) { - storage->mutex = osMutexNew(NULL); + storage->mutex = furi_mutex_alloc(FuriMutexTypeNormal); furi_check(storage->mutex != NULL); storage->data = NULL; storage->status = StorageStatusNotReady; @@ -39,11 +39,11 @@ void storage_data_init(StorageData* storage) { } bool storage_data_lock(StorageData* storage) { - return (osMutexAcquire(storage->mutex, osWaitForever) == osOK); + return (furi_mutex_acquire(storage->mutex, FuriWaitForever) == FuriStatusOk); } bool storage_data_unlock(StorageData* storage) { - return (osMutexRelease(storage->mutex) == osOK); + return (furi_mutex_release(storage->mutex) == FuriStatusOk); } StorageStatus storage_data_status(StorageData* storage) { diff --git a/applications/storage/storage_glue.h b/applications/storage/storage_glue.h index 0d50e39b0..7cf2e072a 100644 --- a/applications/storage/storage_glue.h +++ b/applications/storage/storage_glue.h @@ -56,7 +56,7 @@ struct StorageData { const FS_Api* fs_api; StorageApi api; void* data; - osMutexId_t mutex; + FuriMutex* mutex; StorageStatus status; StorageFileList_t files; }; diff --git a/applications/storage/storage_i.h b/applications/storage/storage_i.h index 0db5218d3..5c836ccd2 100644 --- a/applications/storage/storage_i.h +++ b/applications/storage/storage_i.h @@ -17,7 +17,7 @@ typedef struct { } StorageSDGui; struct Storage { - osMessageQueueId_t message_queue; + FuriMessageQueue* message_queue; StorageData storage[STORAGE_COUNT]; StorageSDGui sd_gui; FuriPubSub* pubsub; diff --git a/applications/storage/storage_internal_api.c b/applications/storage/storage_internal_api.c index ee49d6723..093140435 100644 --- a/applications/storage/storage_internal_api.c +++ b/applications/storage/storage_internal_api.c @@ -1,4 +1,4 @@ -#include +#include #include #include "storage.h" #include diff --git a/applications/storage/storage_message.h b/applications/storage/storage_message.h index f3aeaf321..78cd1e03c 100644 --- a/applications/storage/storage_message.h +++ b/applications/storage/storage_message.h @@ -123,7 +123,7 @@ typedef enum { } StorageCommand; typedef struct { - osSemaphoreId_t semaphore; + FuriSemaphore* semaphore; StorageCommand command; SAData* data; SAReturn* return_data; diff --git a/applications/storage/storage_processing.c b/applications/storage/storage_processing.c index 30e6b5e75..0eb8a32cb 100644 --- a/applications/storage/storage_processing.c +++ b/applications/storage/storage_processing.c @@ -573,7 +573,7 @@ void storage_process_message_internal(Storage* app, StorageMessage* message) { break; } - osSemaphoreRelease(message->semaphore); + furi_semaphore_release(message->semaphore); } void storage_process_message(Storage* app, StorageMessage* message) { diff --git a/applications/storage/storage_test_app.c b/applications/storage/storage_test_app.c index f11d2d72a..226024b30 100644 --- a/applications/storage/storage_test_app.c +++ b/applications/storage/storage_test_app.c @@ -335,7 +335,7 @@ int32_t storage_test_app(void* p) { do_test_end(api, "/ext"); while(true) { - furi_hal_delay_ms(1000); + furi_delay_ms(1000); } return 0; diff --git a/applications/storage/storages/storage_ext.c b/applications/storage/storages/storage_ext.c index 49c52f771..abfcb0e72 100644 --- a/applications/storage/storages/storage_ext.c +++ b/applications/storage/storages/storage_ext.c @@ -84,7 +84,7 @@ static bool sd_mount_card(StorageData* storage, bool notify) { } if(!result) { - furi_hal_delay_ms(1000); + furi_delay_ms(1000); FURI_LOG_E( TAG, "init cycle %d, error: %s", counter, storage_data_status_text(storage)); counter--; diff --git a/applications/storage_move_to_sd/scenes/storage_move_to_sd_scene_progress.c b/applications/storage_move_to_sd/scenes/storage_move_to_sd_scene_progress.c index d44b25c38..7aa951bd8 100644 --- a/applications/storage_move_to_sd/scenes/storage_move_to_sd_scene_progress.c +++ b/applications/storage_move_to_sd/scenes/storage_move_to_sd_scene_progress.c @@ -1,5 +1,4 @@ #include "../storage_move_to_sd.h" -#include "cmsis_os2.h" void storage_move_to_sd_scene_progress_on_enter(void* context) { StorageMoveToSd* app = context; diff --git a/applications/storage_move_to_sd/storage_move_to_sd.c b/applications/storage_move_to_sd/storage_move_to_sd.c index f703321d3..fe5807d19 100644 --- a/applications/storage_move_to_sd/storage_move_to_sd.c +++ b/applications/storage_move_to_sd/storage_move_to_sd.c @@ -1,7 +1,6 @@ #include "storage_move_to_sd.h" -#include "cmsis_os2.h" -#include "furi/common_defines.h" -#include "furi/log.h" +#include +#include #include "loader/loader.h" #include "m-string.h" #include diff --git a/applications/storage_settings/scenes/storage_settings_scene_benchmark.c b/applications/storage_settings/scenes/storage_settings_scene_benchmark.c index 707891df3..e7c55ad17 100644 --- a/applications/storage_settings/scenes/storage_settings_scene_benchmark.c +++ b/applications/storage_settings/scenes/storage_settings_scene_benchmark.c @@ -1,4 +1,5 @@ #include "../storage_settings.h" +#include #define BENCH_DATA_SIZE 4096 #define BENCH_COUNT 6 @@ -21,7 +22,7 @@ static bool storage_settings_scene_bench_write( bool result = true; if(storage_file_open(file, BENCH_FILE, FSAM_WRITE, FSOM_CREATE_ALWAYS)) { uint32_t ticks; - ticks = osKernelGetTickCount(); + ticks = furi_get_tick(); for(size_t repeat = 0; repeat < BENCH_REPEATS; repeat++) { for(size_t i = 0; i < BENCH_DATA_SIZE / size; i++) { @@ -32,8 +33,8 @@ static bool storage_settings_scene_bench_write( } } - ticks = osKernelGetTickCount() - ticks; - *speed = BENCH_DATA_SIZE * osKernelGetTickFreq() * BENCH_REPEATS; + ticks = furi_get_tick() - ticks; + *speed = BENCH_DATA_SIZE * furi_kernel_get_tick_frequency() * BENCH_REPEATS; *speed /= ticks; *speed /= 1024; } @@ -50,7 +51,7 @@ static bool if(storage_file_open(file, BENCH_FILE, FSAM_READ, FSOM_OPEN_EXISTING)) { uint32_t ticks; - ticks = osKernelGetTickCount(); + ticks = furi_get_tick(); for(size_t repeat = 0; repeat < BENCH_REPEATS; repeat++) { for(size_t i = 0; i < BENCH_DATA_SIZE / size; i++) { @@ -61,8 +62,8 @@ static bool } } - ticks = osKernelGetTickCount() - ticks; - *speed = BENCH_DATA_SIZE * osKernelGetTickFreq() * BENCH_REPEATS; + ticks = furi_get_tick() - ticks; + *speed = BENCH_DATA_SIZE * furi_kernel_get_tick_frequency() * BENCH_REPEATS; *speed /= ticks; *speed /= 1024; } diff --git a/applications/subghz/helpers/subghz_chat.c b/applications/subghz/helpers/subghz_chat.c index 7a3591652..f821feaa9 100644 --- a/applications/subghz/helpers/subghz_chat.c +++ b/applications/subghz/helpers/subghz_chat.c @@ -10,7 +10,7 @@ struct SubGhzChatWorker { volatile bool worker_running; volatile bool worker_stoping; - osMessageQueueId_t event_queue; + FuriMessageQueue* event_queue; uint32_t last_time_rx_data; Cli* cli; @@ -27,12 +27,12 @@ static int32_t subghz_chat_worker_thread(void* context) { char c; SubGhzChatEvent event; event.event = SubGhzChatEventUserEntrance; - osMessageQueuePut(instance->event_queue, &event, 0, 0); + furi_message_queue_put(instance->event_queue, &event, 0); while(instance->worker_running) { if(cli_read_timeout(instance->cli, (uint8_t*)&c, 1, 1000) == 1) { event.event = SubGhzChatEventInputData; event.c = c; - osMessageQueuePut(instance->event_queue, &event, 0, osWaitForever); + furi_message_queue_put(instance->event_queue, &event, FuriWaitForever); } } @@ -44,14 +44,14 @@ static void subghz_chat_worker_update_rx_event_chat(void* context) { furi_assert(context); SubGhzChatWorker* instance = context; SubGhzChatEvent event; - if((furi_hal_get_tick() - instance->last_time_rx_data) > + if((furi_get_tick() - instance->last_time_rx_data) > SUBGHZ_CHAT_WORKER_TIMEOUT_BETWEEN_MESSAGES) { event.event = SubGhzChatEventNewMessage; - osMessageQueuePut(instance->event_queue, &event, 0, osWaitForever); + furi_message_queue_put(instance->event_queue, &event, FuriWaitForever); } - instance->last_time_rx_data = furi_hal_get_tick(); + instance->last_time_rx_data = furi_get_tick(); event.event = SubGhzChatEventRXData; - osMessageQueuePut(instance->event_queue, &event, 0, osWaitForever); + furi_message_queue_put(instance->event_queue, &event, FuriWaitForever); } SubGhzChatWorker* subghz_chat_worker_alloc(Cli* cli) { @@ -65,14 +65,14 @@ SubGhzChatWorker* subghz_chat_worker_alloc(Cli* cli) { furi_thread_set_context(instance->thread, instance); furi_thread_set_callback(instance->thread, subghz_chat_worker_thread); instance->subghz_txrx = subghz_tx_rx_worker_alloc(); - instance->event_queue = osMessageQueueNew(80, sizeof(SubGhzChatEvent), NULL); + instance->event_queue = furi_message_queue_alloc(80, sizeof(SubGhzChatEvent)); return instance; } void subghz_chat_worker_free(SubGhzChatWorker* instance) { furi_assert(instance); furi_assert(!instance->worker_running); - osMessageQueueDelete(instance->event_queue); + furi_message_queue_free(instance->event_queue); subghz_tx_rx_worker_free(instance->subghz_txrx); furi_thread_free(instance->thread); @@ -85,7 +85,7 @@ bool subghz_chat_worker_start(SubGhzChatWorker* instance, uint32_t frequency) { bool res = false; if(subghz_tx_rx_worker_start(instance->subghz_txrx, frequency)) { - osMessageQueueReset(instance->event_queue); + furi_message_queue_reset(instance->event_queue); subghz_tx_rx_worker_set_callback_have_read( instance->subghz_txrx, subghz_chat_worker_update_rx_event_chat, instance); @@ -119,7 +119,7 @@ bool subghz_chat_worker_is_running(SubGhzChatWorker* instance) { SubGhzChatEvent subghz_chat_worker_get_event_chat(SubGhzChatWorker* instance) { furi_assert(instance); SubGhzChatEvent event; - if(osMessageQueueGet(instance->event_queue, &event, NULL, osWaitForever) == osOK) { + if(furi_message_queue_get(instance->event_queue, &event, FuriWaitForever) == FuriStatusOk) { return event; } else { event.event = SubGhzChatEventNoEvent; @@ -129,7 +129,7 @@ SubGhzChatEvent subghz_chat_worker_get_event_chat(SubGhzChatWorker* instance) { void subghz_chat_worker_put_event_chat(SubGhzChatWorker* instance, SubGhzChatEvent* event) { furi_assert(instance); - osMessageQueuePut(instance->event_queue, event, 0, osWaitForever); + furi_message_queue_put(instance->event_queue, event, FuriWaitForever); } size_t subghz_chat_worker_available(SubGhzChatWorker* instance) { diff --git a/applications/subghz/helpers/subghz_frequency_analyzer_worker.c b/applications/subghz/helpers/subghz_frequency_analyzer_worker.c index 43acf0341..10c5a9ea8 100644 --- a/applications/subghz/helpers/subghz_frequency_analyzer_worker.c +++ b/applications/subghz/helpers/subghz_frequency_analyzer_worker.c @@ -100,7 +100,7 @@ static int32_t subghz_frequency_analyzer_worker_thread(void* context) { furi_hal_subghz_set_path(FuriHalSubGhzPathIsolate); while(instance->worker_running) { - osDelay(10); + furi_delay_ms(10); float rssi_min = 26.0f; float rssi_avg = 0; @@ -129,8 +129,7 @@ static int32_t subghz_frequency_analyzer_worker_thread(void* context) { cc1101_switch_to_rx(&furi_hal_spi_bus_handle_subghz); furi_hal_spi_release(&furi_hal_spi_bus_handle_subghz); - // delay will be in range between 1 and 2ms - osDelay(3); + furi_delay_ms(2); rssi = furi_hal_subghz_get_rssi(); @@ -175,8 +174,7 @@ static int32_t subghz_frequency_analyzer_worker_thread(void* context) { cc1101_switch_to_rx(&furi_hal_spi_bus_handle_subghz); furi_hal_spi_release(&furi_hal_spi_bus_handle_subghz); - // delay will be in range between 1 and 2ms - osDelay(3); + furi_delay_ms(2); rssi = furi_hal_subghz_get_rssi(); diff --git a/applications/subghz/subghz_cli.c b/applications/subghz/subghz_cli.c index 20930df27..541b5c501 100644 --- a/applications/subghz/subghz_cli.c +++ b/applications/subghz/subghz_cli.c @@ -51,7 +51,7 @@ void subghz_cli_command_tx_carrier(Cli* cli, string_t args, void* context) { printf("Transmitting at frequency %lu Hz\r\n", frequency); printf("Press CTRL+C to stop\r\n"); while(!cli_cmd_interrupt_received(cli)) { - osDelay(250); + furi_delay_ms(250); } } else { printf("This frequency can only be used for RX in your region\r\n"); @@ -93,7 +93,7 @@ void subghz_cli_command_rx_carrier(Cli* cli, string_t args, void* context) { furi_hal_subghz_rx(); while(!cli_cmd_interrupt_received(cli)) { - osDelay(250); + furi_delay_ms(250); printf("RSSI: %03.1fdbm\r", (double)furi_hal_subghz_get_rssi()); fflush(stdout); } @@ -172,7 +172,7 @@ void subghz_cli_command_tx(Cli* cli, string_t args, void* context) { while(!(furi_hal_subghz_is_async_tx_complete() || cli_cmd_interrupt_received(cli))) { printf("."); fflush(stdout); - osDelay(333); + furi_delay_ms(333); } furi_hal_subghz_stop_async_tx(); furi_hal_subghz_sleep(); @@ -377,7 +377,7 @@ void subghz_cli_command_decode_raw(Cli* cli, string_t args, void* context) { SubGhzFileEncoderWorker* file_worker_encoder = subghz_file_encoder_worker_alloc(); if(subghz_file_encoder_worker_start(file_worker_encoder, string_get_cstr(file_name))) { //the worker needs a file in order to open and read part of the file - osDelay(100); + furi_delay_ms(100); } printf( @@ -386,7 +386,7 @@ void subghz_cli_command_decode_raw(Cli* cli, string_t args, void* context) { LevelDuration level_duration; while(!cli_cmd_interrupt_received(cli)) { - furi_hal_delay_us(500); //you need to have time to read from the file from the SD card + furi_delay_us(500); //you need to have time to read from the file from the SD card level_duration = subghz_file_encoder_worker_get_level_duration(file_worker_encoder); if(!level_duration_is_reset(level_duration)) { bool level = level_duration_get_level(level_duration); @@ -616,7 +616,7 @@ static void subghz_cli_command_chat(Cli* cli, string_t args) { subghz_chat, (uint8_t*)string_get_cstr(input), strlen(string_get_cstr(input)))) { - furi_hal_delay_ms(10); + furi_delay_ms(10); } string_printf(input, "%s", string_get_cstr(name)); @@ -668,7 +668,7 @@ static void subghz_cli_command_chat(Cli* cli, string_t args) { subghz_chat, (uint8_t*)string_get_cstr(sysmsg), strlen(string_get_cstr(sysmsg))); - furi_hal_delay_ms(10); + furi_delay_ms(10); exit = true; break; default: diff --git a/applications/subghz/subghz_history.c b/applications/subghz/subghz_history.c index a8f86eecb..85578b997 100644 --- a/applications/subghz/subghz_history.c +++ b/applications/subghz/subghz_history.c @@ -140,13 +140,13 @@ bool subghz_history_add_to_history( SubGhzProtocolDecoderBase* decoder_base = context; if((instance->code_last_hash_data == subghz_protocol_decoder_base_get_hash_data(decoder_base)) && - ((furi_hal_get_tick() - instance->last_update_timestamp) < 500)) { - instance->last_update_timestamp = furi_hal_get_tick(); + ((furi_get_tick() - instance->last_update_timestamp) < 500)) { + instance->last_update_timestamp = furi_get_tick(); return false; } instance->code_last_hash_data = subghz_protocol_decoder_base_get_hash_data(decoder_base); - instance->last_update_timestamp = furi_hal_get_tick(); + instance->last_update_timestamp = furi_get_tick(); string_t text; string_init(text); diff --git a/applications/subghz/views/receiver.c b/applications/subghz/views/receiver.c index bb4a8f16d..c28c33636 100644 --- a/applications/subghz/views/receiver.c +++ b/applications/subghz/views/receiver.c @@ -45,7 +45,7 @@ typedef enum { struct SubGhzViewReceiver { SubGhzLock lock; uint8_t lock_count; - osTimerId_t timer; + FuriTimer* timer; View* view; SubGhzViewReceiverCallback callback; void* context; @@ -72,7 +72,7 @@ void subghz_view_receiver_set_lock(SubGhzViewReceiver* subghz_receiver, SubGhzLo model->bar_show = SubGhzViewReceiverBarShowLock; return true; }); - osTimerStart(subghz_receiver->timer, pdMS_TO_TICKS(1000)); + furi_timer_start(subghz_receiver->timer, pdMS_TO_TICKS(1000)); } else { with_view_model( subghz_receiver->view, (SubGhzViewReceiverModel * model) { @@ -266,7 +266,7 @@ bool subghz_view_receiver_input(InputEvent* event, void* context) { return true; }); if(subghz_receiver->lock_count == 0) { - osTimerStart(subghz_receiver->timer, pdMS_TO_TICKS(1000)); + furi_timer_start(subghz_receiver->timer, pdMS_TO_TICKS(1000)); } if(event->key == InputKeyBack && event->type == InputTypeShort) { subghz_receiver->lock_count++; @@ -280,7 +280,7 @@ bool subghz_view_receiver_input(InputEvent* event, void* context) { return true; }); //subghz_receiver->lock = SubGhzLockOff; - osTimerStart(subghz_receiver->timer, pdMS_TO_TICKS(650)); + furi_timer_start(subghz_receiver->timer, pdMS_TO_TICKS(650)); } return true; @@ -345,7 +345,7 @@ void subghz_view_receiver_exit(void* context) { model->history_item = 0; return false; }); - osTimerStop(subghz_receiver->timer); + furi_timer_stop(subghz_receiver->timer); } SubGhzViewReceiver* subghz_view_receiver_alloc() { @@ -375,7 +375,7 @@ SubGhzViewReceiver* subghz_view_receiver_alloc() { return true; }); subghz_receiver->timer = - osTimerNew(subghz_view_receiver_timer_callback, osTimerOnce, subghz_receiver, NULL); + furi_timer_alloc(subghz_view_receiver_timer_callback, FuriTimerTypeOnce, subghz_receiver); return subghz_receiver; } @@ -396,7 +396,7 @@ void subghz_view_receiver_free(SubGhzViewReceiver* subghz_receiver) { free(model->history); return false; }); - osTimerDelete(subghz_receiver->timer); + furi_timer_free(subghz_receiver->timer); view_free(subghz_receiver->view); free(subghz_receiver); } diff --git a/applications/subghz/views/subghz_test_carrier.c b/applications/subghz/views/subghz_test_carrier.c index cd2f70ec2..6729eaad8 100644 --- a/applications/subghz/views/subghz_test_carrier.c +++ b/applications/subghz/views/subghz_test_carrier.c @@ -9,7 +9,7 @@ struct SubGhzTestCarrier { View* view; - osTimerId_t timer; + FuriTimer* timer; SubGhzTestCarrierCallback callback; void* context; }; @@ -154,14 +154,14 @@ void subghz_test_carrier_enter(void* context) { furi_hal_subghz_rx(); - osTimerStart(subghz_test_carrier->timer, osKernelGetTickFreq() / 4); + furi_timer_start(subghz_test_carrier->timer, furi_kernel_get_tick_frequency() / 4); } void subghz_test_carrier_exit(void* context) { furi_assert(context); SubGhzTestCarrier* subghz_test_carrier = context; - osTimerStop(subghz_test_carrier->timer); + furi_timer_stop(subghz_test_carrier->timer); // Reinitialize IC to default state furi_hal_subghz_sleep(); @@ -194,15 +194,15 @@ SubGhzTestCarrier* subghz_test_carrier_alloc() { view_set_enter_callback(subghz_test_carrier->view, subghz_test_carrier_enter); view_set_exit_callback(subghz_test_carrier->view, subghz_test_carrier_exit); - subghz_test_carrier->timer = osTimerNew( - subghz_test_carrier_rssi_timer_callback, osTimerPeriodic, subghz_test_carrier, NULL); + subghz_test_carrier->timer = furi_timer_alloc( + subghz_test_carrier_rssi_timer_callback, FuriTimerTypePeriodic, subghz_test_carrier); return subghz_test_carrier; } void subghz_test_carrier_free(SubGhzTestCarrier* subghz_test_carrier) { furi_assert(subghz_test_carrier); - osTimerDelete(subghz_test_carrier->timer); + furi_timer_free(subghz_test_carrier->timer); view_free(subghz_test_carrier->view); free(subghz_test_carrier); } diff --git a/applications/subghz/views/subghz_test_packet.c b/applications/subghz/views/subghz_test_packet.c index 57f850850..c83aebec9 100644 --- a/applications/subghz/views/subghz_test_packet.c +++ b/applications/subghz/views/subghz_test_packet.c @@ -13,7 +13,7 @@ struct SubGhzTestPacket { View* view; - osTimerId_t timer; + FuriTimer* timer; SubGhzDecoderPrinceton* decoder; SubGhzEncoderPrinceton* encoder; @@ -141,7 +141,7 @@ static bool subghz_test_packet_input(InputEvent* event, void* context) { if(model->status == SubGhzTestPacketModelStatusRx) { furi_hal_subghz_stop_async_rx(); } else if(model->status == SubGhzTestPacketModelStatusTx) { - subghz_encoder_princeton_for_testing_stop(instance->encoder, furi_hal_get_tick()); + subghz_encoder_princeton_for_testing_stop(instance->encoder, furi_get_tick()); furi_hal_subghz_stop_async_tx(); } @@ -206,14 +206,14 @@ void subghz_test_packet_enter(void* context) { furi_hal_subghz_start_async_rx(subghz_test_packet_rx_callback, instance); - osTimerStart(instance->timer, osKernelGetTickFreq() / 4); + furi_timer_start(instance->timer, furi_kernel_get_tick_frequency() / 4); } void subghz_test_packet_exit(void* context) { furi_assert(context); SubGhzTestPacket* instance = context; - osTimerStop(instance->timer); + furi_timer_stop(instance->timer); // Reinitialize IC to default state with_view_model( @@ -221,7 +221,7 @@ void subghz_test_packet_exit(void* context) { if(model->status == SubGhzTestPacketModelStatusRx) { furi_hal_subghz_stop_async_rx(); } else if(model->status == SubGhzTestPacketModelStatusTx) { - subghz_encoder_princeton_for_testing_stop(instance->encoder, furi_hal_get_tick()); + subghz_encoder_princeton_for_testing_stop(instance->encoder, furi_get_tick()); furi_hal_subghz_stop_async_tx(); } return true; @@ -242,7 +242,7 @@ SubGhzTestPacket* subghz_test_packet_alloc() { view_set_exit_callback(instance->view, subghz_test_packet_exit); instance->timer = - osTimerNew(subghz_test_packet_rssi_timer_callback, osTimerPeriodic, instance, NULL); + furi_timer_alloc(subghz_test_packet_rssi_timer_callback, FuriTimerTypePeriodic, instance); instance->decoder = subghz_decoder_princeton_for_testing_alloc(); subghz_decoder_princeton_for_testing_set_callback( @@ -258,7 +258,7 @@ void subghz_test_packet_free(SubGhzTestPacket* instance) { subghz_decoder_princeton_for_testing_free(instance->decoder); subghz_encoder_princeton_for_testing_free(instance->encoder); - osTimerDelete(instance->timer); + furi_timer_free(instance->timer); view_free(instance->view); free(instance); } diff --git a/applications/subghz/views/subghz_test_static.c b/applications/subghz/views/subghz_test_static.c index d1a7bfd42..26cf9b484 100644 --- a/applications/subghz/views/subghz_test_static.c +++ b/applications/subghz/views/subghz_test_static.c @@ -119,7 +119,7 @@ bool subghz_test_static_input(InputEvent* event, void* context) { if(instance->satus_tx == SubGhzTestStaticStatusTX) { FURI_LOG_I(TAG, "TX Stop"); subghz_encoder_princeton_for_testing_stop( - instance->encoder, furi_hal_get_tick()); + instance->encoder, furi_get_tick()); subghz_encoder_princeton_for_testing_print_log(instance->encoder); furi_hal_subghz_stop_async_tx(); notification_message(notification, &sequence_reset_red); diff --git a/applications/u2f/scenes/u2f_scene_main.c b/applications/u2f/scenes/u2f_scene_main.c index f6264338b..60ed71c78 100644 --- a/applications/u2f/scenes/u2f_scene_main.c +++ b/applications/u2f/scenes/u2f_scene_main.c @@ -46,14 +46,14 @@ bool u2f_scene_main_on_event(void* context, SceneManagerEvent event) { if(event.type == SceneManagerEventTypeCustom) { if(event.event == U2fCustomEventConnect) { - osTimerStop(app->timer); + furi_timer_stop(app->timer); u2f_view_set_state(app->u2f_view, U2fMsgIdle); } else if(event.event == U2fCustomEventDisconnect) { - osTimerStop(app->timer); + furi_timer_stop(app->timer); app->event_cur = U2fCustomEventNone; u2f_view_set_state(app->u2f_view, U2fMsgNotConnected); } else if((event.event == U2fCustomEventRegister) || (event.event == U2fCustomEventAuth)) { - osTimerStart(app->timer, U2F_REQUEST_TIMEOUT); + furi_timer_start(app->timer, U2F_REQUEST_TIMEOUT); if(app->event_cur == U2fCustomEventNone) { app->event_cur = event.event; if(event.event == U2fCustomEventRegister) @@ -69,7 +69,7 @@ bool u2f_scene_main_on_event(void* context, SceneManagerEvent event) { } else if(event.event == U2fCustomEventAuthSuccess) { notification_message_block(app->notifications, &sequence_set_green_255); DOLPHIN_DEED(DolphinDeedU2fAuthorized); - osTimerStart(app->timer, U2F_SUCCESS_TIMEOUT); + furi_timer_start(app->timer, U2F_SUCCESS_TIMEOUT); app->event_cur = U2fCustomEventNone; u2f_view_set_state(app->u2f_view, U2fMsgSuccess); } else if(event.event == U2fCustomEventTimeout) { @@ -82,7 +82,7 @@ bool u2f_scene_main_on_event(void* context, SceneManagerEvent event) { } } else if(event.event == U2fCustomEventDataError) { notification_message(app->notifications, &sequence_set_red_255); - osTimerStop(app->timer); + furi_timer_stop(app->timer); u2f_view_set_state(app->u2f_view, U2fMsgError); } consumed = true; @@ -94,7 +94,7 @@ bool u2f_scene_main_on_event(void* context, SceneManagerEvent event) { void u2f_scene_main_on_enter(void* context) { U2fApp* app = context; - app->timer = osTimerNew(u2f_scene_main_timer_callback, osTimerOnce, app, NULL); + app->timer = furi_timer_alloc(u2f_scene_main_timer_callback, FuriTimerTypeOnce, app); app->u2f_instance = u2f_alloc(); app->u2f_ready = u2f_init(app->u2f_instance); @@ -113,8 +113,8 @@ void u2f_scene_main_on_enter(void* context) { void u2f_scene_main_on_exit(void* context) { U2fApp* app = context; notification_message_block(app->notifications, &sequence_reset_rgb); - osTimerStop(app->timer); - osTimerDelete(app->timer); + furi_timer_stop(app->timer); + furi_timer_free(app->timer); if(app->u2f_ready == true) { u2f_hid_stop(app->u2f_hid); u2f_free(app->u2f_instance); diff --git a/applications/u2f/u2f_app_i.h b/applications/u2f/u2f_app_i.h index fa9f6f091..53647859a 100644 --- a/applications/u2f/u2f_app_i.h +++ b/applications/u2f/u2f_app_i.h @@ -51,7 +51,7 @@ struct U2fApp { SceneManager* scene_manager; NotificationApp* notifications; Widget* widget; - osTimerId_t timer; + FuriTimer* timer; U2fHid* u2f_hid; U2fView* u2f_view; U2fData* u2f_instance; diff --git a/applications/u2f/u2f_hid.c b/applications/u2f/u2f_hid.c index 581feadb2..4922d6a5a 100644 --- a/applications/u2f/u2f_hid.c +++ b/applications/u2f/u2f_hid.c @@ -57,7 +57,7 @@ struct U2fHid_packet { struct U2fHid { FuriThread* thread; - osTimerId_t lock_timer; + FuriTimer* lock_timer; struct U2fHid_packet packet; uint8_t seq_id_last; uint16_t req_buf_ptr; @@ -157,7 +157,7 @@ static bool u2f_hid_parse_request(U2fHid* u2f_hid) { } else { // Lock on u2f_hid->lock = true; u2f_hid->lock_cid = u2f_hid->packet.cid; - osTimerStart(u2f_hid->lock_timer, lock_timeout * 1000); + furi_timer_start(u2f_hid->lock_timer, lock_timeout * 1000); } } else if(u2f_hid->packet.cmd == U2F_HID_INIT) { // INIT - channel initialization request @@ -193,16 +193,17 @@ static int32_t u2f_hid_worker(void* context) { FuriHalUsbInterface* usb_mode_prev = furi_hal_usb_get_config(); furi_check(furi_hal_usb_set_config(&usb_hid_u2f, NULL) == true); - u2f_hid->lock_timer = osTimerNew(u2f_hid_lock_timeout_callback, osTimerOnce, u2f_hid, NULL); + u2f_hid->lock_timer = + furi_timer_alloc(u2f_hid_lock_timeout_callback, FuriTimerTypeOnce, u2f_hid); furi_hal_hid_u2f_set_callback(u2f_hid_event_callback, u2f_hid); while(1) { uint32_t flags = furi_thread_flags_wait( WorkerEvtStop | WorkerEvtConnect | WorkerEvtDisconnect | WorkerEvtRequest, - osFlagsWaitAny, - osWaitForever); - furi_check((flags & osFlagsError) == 0); + FuriFlagWaitAny, + FuriWaitForever); + furi_check((flags & FuriFlagError) == 0); if(flags & WorkerEvtStop) break; if(flags & WorkerEvtConnect) { u2f_set_state(u2f_hid->u2f_instance, 1); @@ -266,8 +267,8 @@ static int32_t u2f_hid_worker(void* context) { u2f_hid->lock_cid = 0; } } - osTimerStop(u2f_hid->lock_timer); - osTimerDelete(u2f_hid->lock_timer); + furi_timer_stop(u2f_hid->lock_timer); + furi_timer_free(u2f_hid->lock_timer); furi_hal_hid_u2f_set_callback(NULL, NULL); furi_hal_usb_set_config(usb_mode_prev, NULL); diff --git a/applications/unit_tests/furi/furi_valuemutex_test.c b/applications/unit_tests/furi/furi_valuemutex_test.c index ed98be328..02fd47eeb 100644 --- a/applications/unit_tests/furi/furi_valuemutex_test.c +++ b/applications/unit_tests/furi/furi_valuemutex_test.c @@ -1,7 +1,6 @@ #include #include #include -#include "furi_hal_delay.h" #include "../minunit.h" diff --git a/applications/unit_tests/nfc/nfc_test.c b/applications/unit_tests/nfc/nfc_test.c index a2262735c..4e1b9a646 100644 --- a/applications/unit_tests/nfc/nfc_test.c +++ b/applications/unit_tests/nfc/nfc_test.c @@ -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 diff --git a/applications/unit_tests/rpc/rpc_test.c b/applications/unit_tests/rpc/rpc_test.c index ca894cb45..c5336385b 100644 --- a/applications/unit_tests/rpc/rpc_test.c +++ b/applications/unit_tests/rpc/rpc_test.c @@ -1,7 +1,6 @@ #include "flipper.pb.h" -#include "furi_hal_delay.h" -#include "furi/check.h" -#include "furi/record.h" +#include +#include #include "pb_decode.h" #include #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; diff --git a/applications/unit_tests/storage/storage_test.c b/applications/unit_tests/storage/storage_test.c index db78583df..c21abecca 100644 --- a/applications/unit_tests/storage/storage_test.c +++ b/applications/unit_tests/storage/storage_test.c @@ -1,6 +1,5 @@ #include "../minunit.h" #include -#include #include #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 diff --git a/applications/unit_tests/subghz/subghz_test.c b/applications/unit_tests/subghz/subghz_test.c index fea407ed3..23c6117b8 100644 --- a/applications/unit_tests/subghz/subghz_test.c +++ b/applications/unit_tests/subghz/subghz_test.c @@ -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; } diff --git a/applications/unit_tests/test_index.c b/applications/unit_tests/test_index.c index 9f12adae6..ca7641b1c 100644 --- a/applications/unit_tests/test_index.c +++ b/applications/unit_tests/test_index.c @@ -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); diff --git a/applications/updater/cli/updater_cli.c b/applications/updater/cli/updater_cli.c index fb2edeb93..3dfd145ce 100644 --- a/applications/updater/cli/updater_cli.c +++ b/applications/updater/cli/updater_cli.c @@ -29,7 +29,7 @@ static void updater_cli_install(string_t manifest_path) { return; } printf("OK.\r\nRestarting to apply update. BRB\r\n"); - osDelay(100); + furi_delay_ms(100); furi_hal_power_reset(); } @@ -134,4 +134,4 @@ void updater_on_system_start() { #else UNUSED(updater_start_app); #endif -} \ No newline at end of file +} diff --git a/applications/updater/util/update_task.c b/applications/updater/util/update_task.c index 47bb7ae5a..f7b9f8128 100644 --- a/applications/updater/util/update_task.c +++ b/applications/updater/util/update_task.c @@ -197,7 +197,7 @@ static void update_task_worker_thread_cb(FuriThreadState state, void* context) { } if(furi_thread_get_return_code(update_task->thread) == UPDATE_TASK_NOERR) { - osDelay(UPDATE_DELAY_OPERATION_OK); + furi_delay_ms(UPDATE_DELAY_OPERATION_OK); furi_hal_power_reset(); } } diff --git a/applications/updater/util/update_task_worker_flasher.c b/applications/updater/util/update_task_worker_flasher.c index d02858bc6..d56b4ae0a 100644 --- a/applications/updater/util/update_task_worker_flasher.c +++ b/applications/updater/util/update_task_worker_flasher.c @@ -130,7 +130,7 @@ static bool update_task_write_stack_data(UpdateTask* update_task) { static void update_task_wait_for_restart(UpdateTask* update_task) { update_task_set_progress(update_task, UpdateTaskStageRadioBusy, 10); - osDelay(C2_MODE_SWITCH_TIMEOUT); + furi_delay_ms(C2_MODE_SWITCH_TIMEOUT); furi_crash("C2 timeout"); } diff --git a/core/furi.c b/core/furi.c deleted file mode 100644 index edee15926..000000000 --- a/core/furi.c +++ /dev/null @@ -1,13 +0,0 @@ -#include "furi.h" - -void furi_init() { - osKernelInitialize(); - - furi_log_init(); - furi_record_init(); - furi_stdglue_init(); -} - -void furi_run() { - osKernelStart(); -} diff --git a/core/furi.h b/core/furi.h deleted file mode 100644 index 7a36c1bab..000000000 --- a/core/furi.h +++ /dev/null @@ -1,37 +0,0 @@ -#pragma once - -#include -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -void furi_init(); - -void furi_run(); - -#ifdef __cplusplus -} -#endif diff --git a/core/furi/base.h b/core/furi/base.h deleted file mode 100644 index 41873fbd6..000000000 --- a/core/furi/base.h +++ /dev/null @@ -1,45 +0,0 @@ -#pragma once - -#include -#include - -// FreeRTOS part -#include - -#ifdef __cplusplus -extern "C" { -#endif - -// Timeout value. -#define osWaitForever 0xFFFFFFFFU ///< Wait forever timeout value. - -// Flags options (\ref furi_thread_flags_wait and \ref osEventFlagsWait). -#define osFlagsWaitAny 0x00000000U ///< Wait for any flag (default). -#define osFlagsWaitAll 0x00000001U ///< Wait for all flags. -#define osFlagsNoClear 0x00000002U ///< Do not clear flags which have been specified to wait for. - -// Flags errors (returned by osThreadFlagsXxxx and osEventFlagsXxxx). -#define osFlagsError 0x80000000U ///< Error indicator. -#define osFlagsErrorUnknown 0xFFFFFFFFU ///< osError (-1). -#define osFlagsErrorTimeout 0xFFFFFFFEU ///< osErrorTimeout (-2). -#define osFlagsErrorResource 0xFFFFFFFDU ///< osErrorResource (-3). -#define osFlagsErrorParameter 0xFFFFFFFCU ///< osErrorParameter (-4). -#define osFlagsErrorISR 0xFFFFFFFAU ///< osErrorISR (-6). - -/// Status code values returned by CMSIS-RTOS functions. -typedef enum { - osOK = 0, ///< Operation completed successfully. - osError = -1, ///< Unspecified RTOS error: run-time error but no other error message fits. - osErrorTimeout = -2, ///< Operation not completed within the timeout period. - osErrorResource = -3, ///< Resource not available. - osErrorParameter = -4, ///< Parameter error. - osErrorNoMemory = - -5, ///< System is out of memory: it was impossible to allocate or reserve memory for the operation. - osErrorISR = - -6, ///< Not allowed in ISR context: the function cannot be called from interrupt service routines. - osStatusReserved = 0x7FFFFFFF ///< Prevents enum down-size compiler optimization. -} osStatus_t; - -#ifdef __cplusplus -} -#endif diff --git a/core/furi/event_flags.c b/core/furi/event_flags.c deleted file mode 100644 index ba8cba489..000000000 --- a/core/furi/event_flags.c +++ /dev/null @@ -1,222 +0,0 @@ -#include "event_flags.h" -#include "common_defines.h" - -#include - -#define MAX_BITS_EVENT_GROUPS 24U -#define EVENT_FLAGS_INVALID_BITS (~((1UL << MAX_BITS_EVENT_GROUPS) - 1U)) - -osEventFlagsId_t osEventFlagsNew(const osEventFlagsAttr_t* attr) { - EventGroupHandle_t hEventGroup; - int32_t mem; - - hEventGroup = NULL; - - if(FURI_IS_IRQ_MODE() == 0U) { - mem = -1; - - if(attr != NULL) { - if((attr->cb_mem != NULL) && (attr->cb_size >= sizeof(StaticEventGroup_t))) { - /* The memory for control block is provided, use static object */ - mem = 1; - } else { - if((attr->cb_mem == NULL) && (attr->cb_size == 0U)) { - /* Control block will be allocated from the dynamic pool */ - mem = 0; - } - } - } else { - mem = 0; - } - - if(mem == 1) { -#if(configSUPPORT_STATIC_ALLOCATION == 1) - hEventGroup = xEventGroupCreateStatic(attr->cb_mem); -#endif - } else { - if(mem == 0) { -#if(configSUPPORT_DYNAMIC_ALLOCATION == 1) - hEventGroup = xEventGroupCreate(); -#endif - } - } - } - - /* Return event flags ID */ - return ((osEventFlagsId_t)hEventGroup); -} - -/* - Set the specified Event Flags. - - Limitations: - - Event flags are limited to 24 bits. -*/ -uint32_t osEventFlagsSet(osEventFlagsId_t ef_id, uint32_t flags) { - EventGroupHandle_t hEventGroup = (EventGroupHandle_t)ef_id; - uint32_t rflags; - BaseType_t yield; - - if((hEventGroup == NULL) || ((flags & EVENT_FLAGS_INVALID_BITS) != 0U)) { - rflags = (uint32_t)osErrorParameter; - } else if(FURI_IS_IRQ_MODE() != 0U) { -#if(configUSE_OS2_EVENTFLAGS_FROM_ISR == 0) - (void)yield; - /* Enable timers and xTimerPendFunctionCall function to support osEventFlagsSet from ISR */ - rflags = (uint32_t)osErrorResource; -#else - yield = pdFALSE; - - if(xEventGroupSetBitsFromISR(hEventGroup, (EventBits_t)flags, &yield) == pdFAIL) { - rflags = (uint32_t)osErrorResource; - } else { - rflags = flags; - portYIELD_FROM_ISR(yield); - } -#endif - } else { - rflags = xEventGroupSetBits(hEventGroup, (EventBits_t)flags); - } - - /* Return event flags after setting */ - return (rflags); -} - -/* - Clear the specified Event Flags. - - Limitations: - - Event flags are limited to 24 bits. -*/ -uint32_t osEventFlagsClear(osEventFlagsId_t ef_id, uint32_t flags) { - EventGroupHandle_t hEventGroup = (EventGroupHandle_t)ef_id; - uint32_t rflags; - - if((hEventGroup == NULL) || ((flags & EVENT_FLAGS_INVALID_BITS) != 0U)) { - rflags = (uint32_t)osErrorParameter; - } else if(FURI_IS_IRQ_MODE() != 0U) { -#if(configUSE_OS2_EVENTFLAGS_FROM_ISR == 0) - /* Enable timers and xTimerPendFunctionCall function to support osEventFlagsSet from ISR */ - rflags = (uint32_t)osErrorResource; -#else - rflags = xEventGroupGetBitsFromISR(hEventGroup); - - if(xEventGroupClearBitsFromISR(hEventGroup, (EventBits_t)flags) == pdFAIL) { - rflags = (uint32_t)osErrorResource; - } else { - /* xEventGroupClearBitsFromISR only registers clear operation in the timer command queue. */ - /* Yield is required here otherwise clear operation might not execute in the right order. */ - /* See https://github.com/FreeRTOS/FreeRTOS-Kernel/issues/93 for more info. */ - portYIELD_FROM_ISR(pdTRUE); - } -#endif - } else { - rflags = xEventGroupClearBits(hEventGroup, (EventBits_t)flags); - } - - /* Return event flags before clearing */ - return (rflags); -} - -/* - Get the current Event Flags. - - Limitations: - - Event flags are limited to 24 bits. -*/ -uint32_t osEventFlagsGet(osEventFlagsId_t ef_id) { - EventGroupHandle_t hEventGroup = (EventGroupHandle_t)ef_id; - uint32_t rflags; - - if(ef_id == NULL) { - rflags = 0U; - } else if(FURI_IS_IRQ_MODE() != 0U) { - rflags = xEventGroupGetBitsFromISR(hEventGroup); - } else { - rflags = xEventGroupGetBits(hEventGroup); - } - - /* Return current event flags */ - return (rflags); -} - -/* - Wait for one or more Event Flags to become signaled. - - Limitations: - - Event flags are limited to 24 bits. - - osEventFlagsWait cannot be called from an ISR. -*/ -uint32_t - osEventFlagsWait(osEventFlagsId_t ef_id, uint32_t flags, uint32_t options, uint32_t timeout) { - EventGroupHandle_t hEventGroup = (EventGroupHandle_t)ef_id; - BaseType_t wait_all; - BaseType_t exit_clr; - uint32_t rflags; - - if((hEventGroup == NULL) || ((flags & EVENT_FLAGS_INVALID_BITS) != 0U)) { - rflags = (uint32_t)osErrorParameter; - } else if(FURI_IS_IRQ_MODE() != 0U) { - rflags = (uint32_t)osErrorISR; - } else { - if(options & osFlagsWaitAll) { - wait_all = pdTRUE; - } else { - wait_all = pdFAIL; - } - - if(options & osFlagsNoClear) { - exit_clr = pdFAIL; - } else { - exit_clr = pdTRUE; - } - - rflags = xEventGroupWaitBits( - hEventGroup, (EventBits_t)flags, exit_clr, wait_all, (TickType_t)timeout); - - if(options & osFlagsWaitAll) { - if((flags & rflags) != flags) { - if(timeout > 0U) { - rflags = (uint32_t)osErrorTimeout; - } else { - rflags = (uint32_t)osErrorResource; - } - } - } else { - if((flags & rflags) == 0U) { - if(timeout > 0U) { - rflags = (uint32_t)osErrorTimeout; - } else { - rflags = (uint32_t)osErrorResource; - } - } - } - } - - /* Return event flags before clearing */ - return (rflags); -} - -/* - Delete an Event Flags object. -*/ -osStatus_t osEventFlagsDelete(osEventFlagsId_t ef_id) { - EventGroupHandle_t hEventGroup = (EventGroupHandle_t)ef_id; - osStatus_t stat; - -#ifndef USE_FreeRTOS_HEAP_1 - if(FURI_IS_IRQ_MODE() != 0U) { - stat = osErrorISR; - } else if(hEventGroup == NULL) { - stat = osErrorParameter; - } else { - stat = osOK; - vEventGroupDelete(hEventGroup); - } -#else - stat = osError; -#endif - - /* Return execution status */ - return (stat); -} diff --git a/core/furi/event_flags.h b/core/furi/event_flags.h deleted file mode 100644 index 66aa2d7a4..000000000 --- a/core/furi/event_flags.h +++ /dev/null @@ -1,63 +0,0 @@ -#pragma once - -#include "base.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/// Attributes structure for event flags. -typedef struct { - const char* name; ///< name of the event flags - uint32_t attr_bits; ///< attribute bits - void* cb_mem; ///< memory for control block - uint32_t cb_size; ///< size of provided memory for control block -} osEventFlagsAttr_t; - -/// \details Event Flags ID identifies the event flags. -typedef void* osEventFlagsId_t; - -/// Create and Initialize an Event Flags object. -/// \param[in] attr event flags attributes; NULL: default values. -/// \return event flags ID for reference by other functions or NULL in case of error. -osEventFlagsId_t osEventFlagsNew(const osEventFlagsAttr_t* attr); - -/// Get name of an Event Flags object. -/// \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew. -/// \return name as null-terminated string. -const char* osEventFlagsGetName(osEventFlagsId_t ef_id); - -/// Set the specified Event Flags. -/// \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew. -/// \param[in] flags specifies the flags that shall be set. -/// \return event flags after setting or error code if highest bit set. -uint32_t osEventFlagsSet(osEventFlagsId_t ef_id, uint32_t flags); - -/// Clear the specified Event Flags. -/// \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew. -/// \param[in] flags specifies the flags that shall be cleared. -/// \return event flags before clearing or error code if highest bit set. -uint32_t osEventFlagsClear(osEventFlagsId_t ef_id, uint32_t flags); - -/// Get the current Event Flags. -/// \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew. -/// \return current event flags. -uint32_t osEventFlagsGet(osEventFlagsId_t ef_id); - -/// Wait for one or more Event Flags to become signaled. -/// \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew. -/// \param[in] flags specifies the flags to wait for. -/// \param[in] options specifies flags options (osFlagsXxxx). -/// \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. -/// \return event flags before clearing or error code if highest bit set. -uint32_t - osEventFlagsWait(osEventFlagsId_t ef_id, uint32_t flags, uint32_t options, uint32_t timeout); - -/// Delete an Event Flags object. -/// \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew. -/// \return status code that indicates the execution status of the function. -osStatus_t osEventFlagsDelete(osEventFlagsId_t ef_id); - -#ifdef __cplusplus -} -#endif diff --git a/core/furi/mutex.c b/core/furi/mutex.c deleted file mode 100644 index 42f1d5289..000000000 --- a/core/furi/mutex.c +++ /dev/null @@ -1,217 +0,0 @@ -#include "mutex.h" -#include "check.h" -#include "common_defines.h" - -#include - -osMutexId_t osMutexNew(const osMutexAttr_t* attr) { - SemaphoreHandle_t hMutex; - uint32_t type; - uint32_t rmtx; - int32_t mem; - - hMutex = NULL; - - if(FURI_IS_IRQ_MODE() == 0U) { - if(attr != NULL) { - type = attr->attr_bits; - } else { - type = 0U; - } - - if((type & osMutexRecursive) == osMutexRecursive) { - rmtx = 1U; - } else { - rmtx = 0U; - } - - if((type & osMutexRobust) != osMutexRobust) { - mem = -1; - - if(attr != NULL) { - if((attr->cb_mem != NULL) && (attr->cb_size >= sizeof(StaticSemaphore_t))) { - /* The memory for control block is provided, use static object */ - mem = 1; - } else { - if((attr->cb_mem == NULL) && (attr->cb_size == 0U)) { - /* Control block will be allocated from the dynamic pool */ - mem = 0; - } - } - } else { - mem = 0; - } - - if(mem == 1) { -#if(configSUPPORT_STATIC_ALLOCATION == 1) - if(rmtx != 0U) { -#if(configUSE_RECURSIVE_MUTEXES == 1) - hMutex = xSemaphoreCreateRecursiveMutexStatic(attr->cb_mem); -#endif - } else { - hMutex = xSemaphoreCreateMutexStatic(attr->cb_mem); - } -#endif - } else { - if(mem == 0) { -#if(configSUPPORT_DYNAMIC_ALLOCATION == 1) - if(rmtx != 0U) { -#if(configUSE_RECURSIVE_MUTEXES == 1) - hMutex = xSemaphoreCreateRecursiveMutex(); -#endif - } else { - hMutex = xSemaphoreCreateMutex(); - } -#endif - } - } - -#if(configQUEUE_REGISTRY_SIZE > 0) - if(hMutex != NULL) { - if((attr != NULL) && (attr->name != NULL)) { - /* Only non-NULL name objects are added to the Queue Registry */ - vQueueAddToRegistry(hMutex, attr->name); - } - } -#endif - - if((hMutex != NULL) && (rmtx != 0U)) { - /* Set LSB as 'recursive mutex flag' */ - hMutex = (SemaphoreHandle_t)((uint32_t)hMutex | 1U); - } - } - } - - /* Return mutex ID */ - return ((osMutexId_t)hMutex); -} - -/* - Acquire a Mutex or timeout if it is locked. -*/ -osStatus_t osMutexAcquire(osMutexId_t mutex_id, uint32_t timeout) { - SemaphoreHandle_t hMutex; - osStatus_t stat; - uint32_t rmtx; - - hMutex = (SemaphoreHandle_t)((uint32_t)mutex_id & ~1U); - - /* Extract recursive mutex flag */ - rmtx = (uint32_t)mutex_id & 1U; - - stat = osOK; - - if(FURI_IS_IRQ_MODE() != 0U) { - stat = osErrorISR; - } else if(hMutex == NULL) { - stat = osErrorParameter; - } else { - if(rmtx != 0U) { -#if(configUSE_RECURSIVE_MUTEXES == 1) - if(xSemaphoreTakeRecursive(hMutex, timeout) != pdPASS) { - if(timeout != 0U) { - stat = osErrorTimeout; - } else { - stat = osErrorResource; - } - } -#endif - } else { - if(xSemaphoreTake(hMutex, timeout) != pdPASS) { - if(timeout != 0U) { - stat = osErrorTimeout; - } else { - stat = osErrorResource; - } - } - } - } - - /* Return execution status */ - return (stat); -} - -/* - Release a Mutex that was acquired by osMutexAcquire. -*/ -osStatus_t osMutexRelease(osMutexId_t mutex_id) { - SemaphoreHandle_t hMutex; - osStatus_t stat; - uint32_t rmtx; - - hMutex = (SemaphoreHandle_t)((uint32_t)mutex_id & ~1U); - - /* Extract recursive mutex flag */ - rmtx = (uint32_t)mutex_id & 1U; - - stat = osOK; - - if(FURI_IS_IRQ_MODE() != 0U) { - stat = osErrorISR; - } else if(hMutex == NULL) { - stat = osErrorParameter; - } else { - if(rmtx != 0U) { -#if(configUSE_RECURSIVE_MUTEXES == 1) - if(xSemaphoreGiveRecursive(hMutex) != pdPASS) { - stat = osErrorResource; - } -#endif - } else { - if(xSemaphoreGive(hMutex) != pdPASS) { - stat = osErrorResource; - } - } - } - - /* Return execution status */ - return (stat); -} - -/* - Get Thread which owns a Mutex object. -*/ -FuriThreadId osMutexGetOwner(osMutexId_t mutex_id) { - SemaphoreHandle_t hMutex; - FuriThreadId owner; - - hMutex = (SemaphoreHandle_t)((uint32_t)mutex_id & ~1U); - - if((FURI_IS_IRQ_MODE() != 0U) || (hMutex == NULL)) { - owner = 0; - } else { - owner = (FuriThreadId)xSemaphoreGetMutexHolder(hMutex); - } - - /* Return owner thread ID */ - return (owner); -} - -/* - Delete a Mutex object. -*/ -osStatus_t osMutexDelete(osMutexId_t mutex_id) { - osStatus_t stat; -#ifndef USE_FreeRTOS_HEAP_1 - SemaphoreHandle_t hMutex; - - hMutex = (SemaphoreHandle_t)((uint32_t)mutex_id & ~1U); - - if(FURI_IS_IRQ_MODE() != 0U) { - stat = osErrorISR; - } else if(hMutex == NULL) { - stat = osErrorParameter; - } else { -#if(configQUEUE_REGISTRY_SIZE > 0) - vQueueUnregisterQueue(hMutex); -#endif - stat = osOK; - vSemaphoreDelete(hMutex); - } -#else - stat = osError; -#endif - - /* Return execution status */ - return (stat); -} diff --git a/core/furi/mutex.h b/core/furi/mutex.h deleted file mode 100644 index 44f351b78..000000000 --- a/core/furi/mutex.h +++ /dev/null @@ -1,56 +0,0 @@ -#pragma once - -#include "base.h" -#include "thread.h" - -#ifdef __cplusplus -extern "C" { -#endif - -// Mutex attributes (attr_bits in \ref osMutexAttr_t). -#define osMutexRecursive 0x00000001U ///< Recursive mutex. -#define osMutexPrioInherit 0x00000002U ///< Priority inherit protocol. -#define osMutexRobust 0x00000008U ///< Robust mutex. - -/// Attributes structure for mutex. -typedef struct { - const char* name; ///< name of the mutex - uint32_t attr_bits; ///< attribute bits - void* cb_mem; ///< memory for control block - uint32_t cb_size; ///< size of provided memory for control block -} osMutexAttr_t; - -/// \details Mutex ID identifies the mutex. -typedef void* osMutexId_t; - -/// Create and Initialize a Mutex object. -/// \param[in] attr mutex attributes; NULL: default values. -/// \return mutex ID for reference by other functions or NULL in case of error. -osMutexId_t osMutexNew(const osMutexAttr_t* attr); - -/// Get name of a Mutex object. -/// \param[in] mutex_id mutex ID obtained by \ref osMutexNew. -/// \return name as null-terminated string. -const char* osMutexGetName(osMutexId_t mutex_id); - -/// Acquire a Mutex or timeout if it is locked. -/// \param[in] mutex_id mutex ID obtained by \ref osMutexNew. -/// \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. -/// \return status code that indicates the execution status of the function. -osStatus_t osMutexAcquire(osMutexId_t mutex_id, uint32_t timeout); - -/// Release a Mutex that was acquired by \ref osMutexAcquire. -/// \param[in] mutex_id mutex ID obtained by \ref osMutexNew. -/// \return status code that indicates the execution status of the function. -osStatus_t osMutexRelease(osMutexId_t mutex_id); - -/// Delete a Mutex object. -/// \param[in] mutex_id mutex ID obtained by \ref osMutexNew. -/// \return status code that indicates the execution status of the function. -osStatus_t osMutexDelete(osMutexId_t mutex_id); - -FuriThreadId osMutexGetOwner(osMutexId_t mutex_id); - -#ifdef __cplusplus -} -#endif diff --git a/core/furi/semaphore.c b/core/furi/semaphore.c deleted file mode 100644 index cbacdef00..000000000 --- a/core/furi/semaphore.c +++ /dev/null @@ -1,190 +0,0 @@ -#include "semaphore.h" -#include "check.h" -#include "common_defines.h" - -#include - -osSemaphoreId_t - osSemaphoreNew(uint32_t max_count, uint32_t initial_count, const osSemaphoreAttr_t* attr) { - SemaphoreHandle_t hSemaphore; - int32_t mem; - - hSemaphore = NULL; - - if((FURI_IS_IRQ_MODE() == 0U) && (max_count > 0U) && (initial_count <= max_count)) { - mem = -1; - - if(attr != NULL) { - if((attr->cb_mem != NULL) && (attr->cb_size >= sizeof(StaticSemaphore_t))) { - /* The memory for control block is provided, use static object */ - mem = 1; - } else { - if((attr->cb_mem == NULL) && (attr->cb_size == 0U)) { - /* Control block will be allocated from the dynamic pool */ - mem = 0; - } - } - } else { - mem = 0; - } - - if(mem != -1) { - if(max_count == 1U) { - if(mem == 1) { -#if(configSUPPORT_STATIC_ALLOCATION == 1) - hSemaphore = xSemaphoreCreateBinaryStatic((StaticSemaphore_t*)attr->cb_mem); -#endif - } else { -#if(configSUPPORT_DYNAMIC_ALLOCATION == 1) - hSemaphore = xSemaphoreCreateBinary(); -#endif - } - - if((hSemaphore != NULL) && (initial_count != 0U)) { - if(xSemaphoreGive(hSemaphore) != pdPASS) { - vSemaphoreDelete(hSemaphore); - hSemaphore = NULL; - } - } - } else { - if(mem == 1) { -#if(configSUPPORT_STATIC_ALLOCATION == 1) - hSemaphore = xSemaphoreCreateCountingStatic( - max_count, initial_count, (StaticSemaphore_t*)attr->cb_mem); -#endif - } else { -#if(configSUPPORT_DYNAMIC_ALLOCATION == 1) - hSemaphore = xSemaphoreCreateCounting(max_count, initial_count); -#endif - } - } - -#if(configQUEUE_REGISTRY_SIZE > 0) - if(hSemaphore != NULL) { - if((attr != NULL) && (attr->name != NULL)) { - /* Only non-NULL name objects are added to the Queue Registry */ - vQueueAddToRegistry(hSemaphore, attr->name); - } - } -#endif - } - } - - /* Return semaphore ID */ - return ((osSemaphoreId_t)hSemaphore); -} - -/* - Acquire a Semaphore token or timeout if no tokens are available. -*/ -osStatus_t osSemaphoreAcquire(osSemaphoreId_t semaphore_id, uint32_t timeout) { - SemaphoreHandle_t hSemaphore = (SemaphoreHandle_t)semaphore_id; - osStatus_t stat; - BaseType_t yield; - - stat = osOK; - - if(hSemaphore == NULL) { - stat = osErrorParameter; - } else if(FURI_IS_IRQ_MODE() != 0U) { - if(timeout != 0U) { - stat = osErrorParameter; - } else { - yield = pdFALSE; - - if(xSemaphoreTakeFromISR(hSemaphore, &yield) != pdPASS) { - stat = osErrorResource; - } else { - portYIELD_FROM_ISR(yield); - } - } - } else { - if(xSemaphoreTake(hSemaphore, (TickType_t)timeout) != pdPASS) { - if(timeout != 0U) { - stat = osErrorTimeout; - } else { - stat = osErrorResource; - } - } - } - - /* Return execution status */ - return (stat); -} - -/* - Release a Semaphore token up to the initial maximum count. -*/ -osStatus_t osSemaphoreRelease(osSemaphoreId_t semaphore_id) { - SemaphoreHandle_t hSemaphore = (SemaphoreHandle_t)semaphore_id; - osStatus_t stat; - BaseType_t yield; - - stat = osOK; - - if(hSemaphore == NULL) { - stat = osErrorParameter; - } else if(FURI_IS_IRQ_MODE() != 0U) { - yield = pdFALSE; - - if(xSemaphoreGiveFromISR(hSemaphore, &yield) != pdTRUE) { - stat = osErrorResource; - } else { - portYIELD_FROM_ISR(yield); - } - } else { - if(xSemaphoreGive(hSemaphore) != pdPASS) { - stat = osErrorResource; - } - } - - /* Return execution status */ - return (stat); -} - -/* - Get current Semaphore token count. -*/ -uint32_t osSemaphoreGetCount(osSemaphoreId_t semaphore_id) { - SemaphoreHandle_t hSemaphore = (SemaphoreHandle_t)semaphore_id; - uint32_t count; - - if(hSemaphore == NULL) { - count = 0U; - } else if(FURI_IS_IRQ_MODE() != 0U) { - count = (uint32_t)uxSemaphoreGetCountFromISR(hSemaphore); - } else { - count = (uint32_t)uxSemaphoreGetCount(hSemaphore); - } - - /* Return number of tokens */ - return (count); -} - -/* - Delete a Semaphore object. -*/ -osStatus_t osSemaphoreDelete(osSemaphoreId_t semaphore_id) { - SemaphoreHandle_t hSemaphore = (SemaphoreHandle_t)semaphore_id; - osStatus_t stat; - -#ifndef USE_FreeRTOS_HEAP_1 - if(FURI_IS_IRQ_MODE() != 0U) { - stat = osErrorISR; - } else if(hSemaphore == NULL) { - stat = osErrorParameter; - } else { -#if(configQUEUE_REGISTRY_SIZE > 0) - vQueueUnregisterQueue(hSemaphore); -#endif - - stat = osOK; - vSemaphoreDelete(hSemaphore); - } -#else - stat = osError; -#endif - - /* Return execution status */ - return (stat); -} diff --git a/core/furi/semaphore.h b/core/furi/semaphore.h deleted file mode 100644 index b4de78fdd..000000000 --- a/core/furi/semaphore.h +++ /dev/null @@ -1,57 +0,0 @@ -#pragma once - -#include "base.h" -#include "thread.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/// Attributes structure for semaphore. -typedef struct { - const char* name; ///< name of the semaphore - uint32_t attr_bits; ///< attribute bits - void* cb_mem; ///< memory for control block - uint32_t cb_size; ///< size of provided memory for control block -} osSemaphoreAttr_t; - -/// \details Semaphore ID identifies the semaphore. -typedef void* osSemaphoreId_t; - -/// Create and Initialize a Semaphore object. -/// \param[in] max_count maximum number of available tokens. -/// \param[in] initial_count initial number of available tokens. -/// \param[in] attr semaphore attributes; NULL: default values. -/// \return semaphore ID for reference by other functions or NULL in case of error. -osSemaphoreId_t - osSemaphoreNew(uint32_t max_count, uint32_t initial_count, const osSemaphoreAttr_t* attr); - -/// Get name of a Semaphore object. -/// \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew. -/// \return name as null-terminated string. -const char* osSemaphoreGetName(osSemaphoreId_t semaphore_id); - -/// Acquire a Semaphore token or timeout if no tokens are available. -/// \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew. -/// \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. -/// \return status code that indicates the execution status of the function. -osStatus_t osSemaphoreAcquire(osSemaphoreId_t semaphore_id, uint32_t timeout); - -/// Release a Semaphore token up to the initial maximum count. -/// \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew. -/// \return status code that indicates the execution status of the function. -osStatus_t osSemaphoreRelease(osSemaphoreId_t semaphore_id); - -/// Get current Semaphore token count. -/// \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew. -/// \return number of tokens available. -uint32_t osSemaphoreGetCount(osSemaphoreId_t semaphore_id); - -/// Delete a Semaphore object. -/// \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew. -/// \return status code that indicates the execution status of the function. -osStatus_t osSemaphoreDelete(osSemaphoreId_t semaphore_id); - -#ifdef __cplusplus -} -#endif diff --git a/firmware.scons b/firmware.scons index 2ad29c21c..0d1205926 100644 --- a/firmware.scons +++ b/firmware.scons @@ -23,7 +23,7 @@ env = ENV.Clone( "${LIB_DIST_DIR}", ], CPPPATH=[ - "#/core", + "#/furi", "#/applications", "#/firmware/targets/f${TARGET_HW}/ble_glue", "#/firmware/targets/f${TARGET_HW}/fatfs", @@ -45,7 +45,7 @@ env = ENV.Clone( # If they are present, they have precedence over Default }, # for furi_check to respect build type - "core": { + "furi": { "CCFLAGS": [ "-Os", ], @@ -100,7 +100,7 @@ lib_targets = env.BuildModules( "lib", "assets", "firmware", - "core", + "furi", ], ) @@ -177,7 +177,7 @@ fwelf = fwenv["FW_ELF"] = fwenv.Program( sources, LIBS=[ "flipper${TARGET_HW}", - "core", + "furi", "freertos", "stm32cubewb", "hwdrivers", diff --git a/firmware/targets/f7/Inc/FreeRTOSConfig.h b/firmware/targets/f7/Inc/FreeRTOSConfig.h index 9f1b83c07..4f9d1fcf9 100644 --- a/firmware/targets/f7/Inc/FreeRTOSConfig.h +++ b/firmware/targets/f7/Inc/FreeRTOSConfig.h @@ -19,7 +19,8 @@ extern uint32_t SystemCoreClock; #define configUSE_IDLE_HOOK 0 #define configUSE_TICK_HOOK 0 #define configCPU_CLOCK_HZ (SystemCoreClock) -#define configTICK_RATE_HZ ((TickType_t)1000) +#define configTICK_RATE_HZ_RAW 1000 +#define configTICK_RATE_HZ ((TickType_t)configTICK_RATE_HZ_RAW) #define configMAX_PRIORITIES (32) #define configMINIMAL_STACK_SIZE ((uint16_t)128) @@ -30,7 +31,7 @@ extern uint32_t SystemCoreClock; #define configUSE_TRACE_FACILITY 1 #define configUSE_16_BIT_TICKS 0 #define configUSE_MUTEXES 1 -#define configQUEUE_REGISTRY_SIZE 8 +#define configQUEUE_REGISTRY_SIZE 0 #define configCHECK_FOR_STACK_OVERFLOW 2 #define configUSE_RECURSIVE_MUTEXES 1 #define configUSE_COUNTING_SEMAPHORES 1 @@ -129,7 +130,7 @@ See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */ /* Normal assert() semantics without relying on the provision of an assert.h header file. */ #ifdef DEBUG -#include +#include #define configASSERT(x) \ if((x) == 0) { \ furi_crash("FreeRTOS Assert"); \ diff --git a/firmware/targets/f7/Inc/stm32_assert.h b/firmware/targets/f7/Inc/stm32_assert.h index 3b0a543dd..3a54d23a9 100644 --- a/firmware/targets/f7/Inc/stm32_assert.h +++ b/firmware/targets/f7/Inc/stm32_assert.h @@ -22,7 +22,7 @@ #ifndef STM32_ASSERT_H #define STM32_ASSERT_H -#include +#include #ifdef __cplusplus extern "C" { @@ -49,4 +49,4 @@ extern "C" { } #endif -#endif /* STM32_ASSERT_H */ \ No newline at end of file +#endif /* STM32_ASSERT_H */ diff --git a/firmware/targets/f7/Src/main.c b/firmware/targets/f7/Src/main.c index 82a2819b5..5f33569ae 100644 --- a/firmware/targets/f7/Src/main.c +++ b/firmware/targets/f7/Src/main.c @@ -37,7 +37,7 @@ int main() { furi_hal_light_sequence("RGB"); // Delay is for button sampling - furi_hal_delay_ms(100); + furi_delay_ms(100); FuriHalRtcBootMode boot_mode = furi_hal_rtc_get_boot_mode(); if(boot_mode == FuriHalRtcBootModeDfu || !furi_hal_gpio_read(&gpio_button_left)) { diff --git a/firmware/targets/f7/Src/update.c b/firmware/targets/f7/Src/update.c index a91972e9f..bab3b9aad 100644 --- a/firmware/targets/f7/Src/update.c +++ b/firmware/targets/f7/Src/update.c @@ -27,7 +27,6 @@ static bool flipper_update_init() { furi_hal_clock_init(); furi_hal_rtc_init(); furi_hal_interrupt_init(); - furi_hal_delay_init(); furi_hal_spi_init(); diff --git a/firmware/targets/f7/ble_glue/app_common.h b/firmware/targets/f7/ble_glue/app_common.h index a94a96c7e..214c85acd 100644 --- a/firmware/targets/f7/ble_glue/app_common.h +++ b/firmware/targets/f7/ble_glue/app_common.h @@ -32,7 +32,7 @@ extern "C" { #include #include -#include +#include #include "app_conf.h" diff --git a/firmware/targets/f7/ble_glue/ble_app.c b/firmware/targets/f7/ble_glue/ble_app.c index f0406a888..4d3c96e13 100644 --- a/firmware/targets/f7/ble_glue/ble_app.c +++ b/firmware/targets/f7/ble_glue/ble_app.c @@ -22,8 +22,8 @@ _Static_assert( "Ble stack config structure size mismatch"); typedef struct { - osMutexId_t hci_mtx; - osSemaphoreId_t hci_sem; + FuriMutex* hci_mtx; + FuriSemaphore* hci_sem; FuriThread* thread; } BleApp; @@ -37,8 +37,8 @@ bool ble_app_init() { SHCI_CmdStatus_t status; ble_app = malloc(sizeof(BleApp)); // Allocate semafore and mutex for ble command buffer access - ble_app->hci_mtx = osMutexNew(NULL); - ble_app->hci_sem = osSemaphoreNew(1, 0, NULL); + ble_app->hci_mtx = furi_mutex_alloc(FuriMutexTypeNormal); + ble_app->hci_sem = furi_semaphore_alloc(1, 0); // HCI transport layer thread to handle user asynch events ble_app->thread = furi_thread_alloc(); furi_thread_set_name(ble_app->thread, "BleHciDriver"); @@ -113,8 +113,8 @@ void ble_app_thread_stop() { furi_thread_join(ble_app->thread); furi_thread_free(ble_app->thread); // Free resources - osMutexDelete(ble_app->hci_mtx); - osSemaphoreDelete(ble_app->hci_sem); + furi_mutex_free(ble_app->hci_mtx); + furi_semaphore_free(ble_app->hci_sem); free(ble_app); ble_app = NULL; memset(&ble_app_cmd_buffer, 0, sizeof(ble_app_cmd_buffer)); @@ -126,7 +126,7 @@ static int32_t ble_app_hci_thread(void* arg) { uint32_t flags = 0; while(1) { - flags = furi_thread_flags_wait(BLE_APP_FLAG_ALL, osFlagsWaitAny, osWaitForever); + flags = furi_thread_flags_wait(BLE_APP_FLAG_ALL, FuriFlagWaitAny, FuriWaitForever); if(flags & BLE_APP_FLAG_KILL_THREAD) { break; } @@ -151,14 +151,14 @@ void hci_notify_asynch_evt(void* pdata) { void hci_cmd_resp_release(uint32_t flag) { UNUSED(flag); if(ble_app) { - osSemaphoreRelease(ble_app->hci_sem); + furi_semaphore_release(ble_app->hci_sem); } } void hci_cmd_resp_wait(uint32_t timeout) { UNUSED(timeout); if(ble_app) { - osSemaphoreAcquire(ble_app->hci_sem, osWaitForever); + furi_semaphore_acquire(ble_app->hci_sem, FuriWaitForever); } } @@ -178,9 +178,9 @@ static void ble_app_hci_event_handler(void* pPayload) { static void ble_app_hci_status_not_handler(HCI_TL_CmdStatus_t status) { if(status == HCI_TL_CmdBusy) { - osMutexAcquire(ble_app->hci_mtx, osWaitForever); + furi_mutex_acquire(ble_app->hci_mtx, FuriWaitForever); } else if(status == HCI_TL_CmdAvailable) { - osMutexRelease(ble_app->hci_mtx); + furi_mutex_release(ble_app->hci_mtx); } } diff --git a/firmware/targets/f7/ble_glue/ble_glue.c b/firmware/targets/f7/ble_glue/ble_glue.c index 6fa3dbd0d..be2ae0ee5 100644 --- a/firmware/targets/f7/ble_glue/ble_glue.c +++ b/firmware/targets/f7/ble_glue/ble_glue.c @@ -30,8 +30,8 @@ ALIGN(4) static uint8_t ble_glue_ble_spare_event_buff[sizeof(TL_PacketHeader_t) + TL_EVT_HDR_SIZE + 255]; typedef struct { - osMutexId_t shci_mtx; - osSemaphoreId_t shci_sem; + FuriMutex* shci_mtx; + FuriSemaphore* shci_sem; FuriThread* thread; BleGlueStatus status; BleGlueKeyStorageChangedCallback callback; @@ -74,8 +74,8 @@ void ble_glue_init() { // Reference table initialization TL_Init(); - ble_glue->shci_mtx = osMutexNew(NULL); - ble_glue->shci_sem = osSemaphoreNew(1, 0, NULL); + ble_glue->shci_mtx = furi_mutex_alloc(FuriMutexTypeNormal); + ble_glue->shci_sem = furi_semaphore_alloc(1, 0); // FreeRTOS system task creation ble_glue->thread = furi_thread_alloc(); @@ -201,7 +201,7 @@ bool ble_glue_wait_for_c2_start(int32_t timeout) { started = ble_glue->status == BleGlueStatusC2Started; if(!started) { timeout--; - osDelay(1); + furi_delay_tick(1); } } while(!started && (timeout > 0)); @@ -300,10 +300,10 @@ BleGlueCommandResult ble_glue_force_c2_mode(BleGlueC2Mode desired_mode) { static void ble_glue_sys_status_not_callback(SHCI_TL_CmdStatus_t status) { switch(status) { case SHCI_TL_CmdBusy: - osMutexAcquire(ble_glue->shci_mtx, osWaitForever); + furi_mutex_acquire(ble_glue->shci_mtx, FuriWaitForever); break; case SHCI_TL_CmdAvailable: - osMutexRelease(ble_glue->shci_mtx); + furi_mutex_release(ble_glue->shci_mtx); break; default: break; @@ -368,8 +368,8 @@ void ble_glue_thread_stop() { furi_thread_join(ble_glue->thread); furi_thread_free(ble_glue->thread); // Free resources - osMutexDelete(ble_glue->shci_mtx); - osSemaphoreDelete(ble_glue->shci_sem); + furi_mutex_free(ble_glue->shci_mtx); + furi_semaphore_free(ble_glue->shci_sem); ble_glue_clear_shared_memory(); free(ble_glue); ble_glue = NULL; @@ -382,7 +382,7 @@ static int32_t ble_glue_shci_thread(void* context) { uint32_t flags = 0; while(true) { - flags = furi_thread_flags_wait(BLE_GLUE_FLAG_ALL, osFlagsWaitAny, osWaitForever); + flags = furi_thread_flags_wait(BLE_GLUE_FLAG_ALL, FuriFlagWaitAny, FuriWaitForever); if(flags & BLE_GLUE_FLAG_SHCI_EVENT) { shci_user_evt_proc(); } @@ -406,14 +406,14 @@ void shci_notify_asynch_evt(void* pdata) { void shci_cmd_resp_release(uint32_t flag) { UNUSED(flag); if(ble_glue) { - osSemaphoreRelease(ble_glue->shci_sem); + furi_semaphore_release(ble_glue->shci_sem); } } void shci_cmd_resp_wait(uint32_t timeout) { UNUSED(timeout); if(ble_glue) { - osSemaphoreAcquire(ble_glue->shci_sem, osWaitForever); + furi_semaphore_acquire(ble_glue->shci_sem, FuriWaitForever); } } @@ -468,7 +468,7 @@ BleGlueCommandResult ble_glue_fus_wait_operation() { } wip = fus_status == BleGlueCommandResultOperationOngoing; if(wip) { - osDelay(20); + furi_delay_ms(20); } } while(wip); diff --git a/firmware/targets/f7/ble_glue/gap.c b/firmware/targets/f7/ble_glue/gap.c index 7965d3f5e..7154b9b11 100644 --- a/firmware/targets/f7/ble_glue/gap.c +++ b/firmware/targets/f7/ble_glue/gap.c @@ -27,12 +27,12 @@ typedef struct { GapConfig* config; GapConnectionParams connection_params; GapState state; - osMutexId_t state_mutex; + FuriMutex* state_mutex; GapEventCallback on_event_cb; void* context; - osTimerId_t advertise_timer; + FuriTimer* advertise_timer; FuriThread* thread; - osMessageQueueId_t command_queue; + FuriMessageQueue* command_queue; bool enable_adv; } Gap; @@ -94,7 +94,7 @@ SVCCTL_UserEvtFlowStatus_t SVCCTL_App_Notification(void* pckt) { event_pckt = (hci_event_pckt*)((hci_uart_pckt*)pckt)->data; if(gap) { - osMutexAcquire(gap->state_mutex, osWaitForever); + furi_mutex_acquire(gap->state_mutex, FuriWaitForever); } switch(event_pckt->evt) { case EVT_DISCONN_COMPLETE: { @@ -152,7 +152,7 @@ SVCCTL_UserEvtFlowStatus_t SVCCTL_App_Notification(void* pckt) { gap->connection_params.supervisor_timeout = event->Supervision_Timeout; // Stop advertising as connection completed - osTimerStop(gap->advertise_timer); + furi_timer_stop(gap->advertise_timer); // Update connection status and handle gap->state = GapStateConnected; @@ -268,7 +268,7 @@ SVCCTL_UserEvtFlowStatus_t SVCCTL_App_Notification(void* pckt) { break; } if(gap) { - osMutexRelease(gap->state_mutex); + furi_mutex_release(gap->state_mutex); } return SVCCTL_UserEvtFlowEnable; } @@ -382,7 +382,7 @@ static void gap_advertise_start(GapState new_state) { max_interval = 0x0fa0; // 2.5 s } // Stop advertising timer - osTimerStop(gap->advertise_timer); + furi_timer_stop(gap->advertise_timer); if((new_state == GapStateAdvLowPower) && ((gap->state == GapStateAdvFast) || (gap->state == GapStateAdvLowPower))) { @@ -413,7 +413,7 @@ static void gap_advertise_start(GapState new_state) { gap->state = new_state; GapEvent event = {.type = GapEventTypeStartAdvertising}; gap->on_event_cb(event, gap->context); - osTimerStart(gap->advertise_timer, INITIAL_ADV_TIMEOUT); + furi_timer_start(gap->advertise_timer, INITIAL_ADV_TIMEOUT); } static void gap_advertise_stop() { @@ -429,7 +429,7 @@ static void gap_advertise_stop() { } } // Stop advertising - osTimerStop(gap->advertise_timer); + furi_timer_stop(gap->advertise_timer); ret = aci_gap_set_non_discoverable(); if(ret != BLE_STATUS_SUCCESS) { FURI_LOG_E(TAG, "set_non_discoverable failed %d", ret); @@ -443,32 +443,32 @@ static void gap_advertise_stop() { } void gap_start_advertising() { - osMutexAcquire(gap->state_mutex, osWaitForever); + furi_mutex_acquire(gap->state_mutex, FuriWaitForever); if(gap->state == GapStateIdle) { gap->state = GapStateStartingAdv; FURI_LOG_I(TAG, "Start advertising"); gap->enable_adv = true; GapCommand command = GapCommandAdvFast; - furi_check(osMessageQueuePut(gap->command_queue, &command, 0, 0) == osOK); + furi_check(furi_message_queue_put(gap->command_queue, &command, 0) == FuriStatusOk); } - osMutexRelease(gap->state_mutex); + furi_mutex_release(gap->state_mutex); } void gap_stop_advertising() { - osMutexAcquire(gap->state_mutex, osWaitForever); + furi_mutex_acquire(gap->state_mutex, FuriWaitForever); if(gap->state > GapStateIdle) { FURI_LOG_I(TAG, "Stop advertising"); gap->enable_adv = false; GapCommand command = GapCommandAdvStop; - furi_check(osMessageQueuePut(gap->command_queue, &command, 0, 0) == osOK); + furi_check(furi_message_queue_put(gap->command_queue, &command, 0) == FuriStatusOk); } - osMutexRelease(gap->state_mutex); + furi_mutex_release(gap->state_mutex); } static void gap_advetise_timer_callback(void* context) { UNUSED(context); GapCommand command = GapCommandAdvLowPower; - furi_check(osMessageQueuePut(gap->command_queue, &command, 0, 0) == osOK); + furi_check(furi_message_queue_put(gap->command_queue, &command, 0) == FuriStatusOk); } bool gap_init(GapConfig* config, GapEventCallback on_event_cb, void* context) { @@ -480,14 +480,14 @@ bool gap_init(GapConfig* config, GapEventCallback on_event_cb, void* context) { gap->config = config; srand(DWT->CYCCNT); // Create advertising timer - gap->advertise_timer = osTimerNew(gap_advetise_timer_callback, osTimerOnce, NULL, NULL); + gap->advertise_timer = furi_timer_alloc(gap_advetise_timer_callback, FuriTimerTypeOnce, NULL); // Initialization of GATT & GAP layer gap->service.adv_name = config->adv_name; gap_init_svc(gap); // Initialization of the BLE Services SVCCTL_Init(); // Initialization of the GAP state - gap->state_mutex = osMutexNew(NULL); + gap->state_mutex = furi_mutex_alloc(FuriMutexTypeNormal); gap->state = GapStateIdle; gap->service.connection_handle = 0xFFFF; gap->enable_adv = true; @@ -501,7 +501,7 @@ bool gap_init(GapConfig* config, GapEventCallback on_event_cb, void* context) { furi_thread_start(gap->thread); // Command queue allocation - gap->command_queue = osMessageQueueNew(8, sizeof(GapCommand), NULL); + gap->command_queue = furi_message_queue_alloc(8, sizeof(GapCommand)); uint8_t adv_service_uid[2]; gap->service.adv_svc_uuid_len = 1; @@ -518,9 +518,9 @@ bool gap_init(GapConfig* config, GapEventCallback on_event_cb, void* context) { GapState gap_get_state() { GapState state; if(gap) { - osMutexAcquire(gap->state_mutex, osWaitForever); + furi_mutex_acquire(gap->state_mutex, FuriWaitForever); state = gap->state; - osMutexRelease(gap->state_mutex); + furi_mutex_release(gap->state_mutex); } else { state = GapStateUninitialized; } @@ -529,19 +529,19 @@ GapState gap_get_state() { void gap_thread_stop() { if(gap) { - osMutexAcquire(gap->state_mutex, osWaitForever); + furi_mutex_acquire(gap->state_mutex, FuriWaitForever); gap->enable_adv = false; GapCommand command = GapCommandKillThread; - osMessageQueuePut(gap->command_queue, &command, 0, osWaitForever); - osMutexRelease(gap->state_mutex); + furi_message_queue_put(gap->command_queue, &command, FuriWaitForever); + furi_mutex_release(gap->state_mutex); furi_thread_join(gap->thread); furi_thread_free(gap->thread); // Free resources - osMutexDelete(gap->state_mutex); - osMessageQueueDelete(gap->command_queue); - osTimerStop(gap->advertise_timer); - while(xTimerIsTimerActive(gap->advertise_timer) == pdTRUE) osDelay(1); - furi_check(osTimerDelete(gap->advertise_timer) == osOK); + furi_mutex_free(gap->state_mutex); + furi_message_queue_free(gap->command_queue); + furi_timer_stop(gap->advertise_timer); + while(xTimerIsTimerActive(gap->advertise_timer) == pdTRUE) furi_delay_tick(1); + furi_timer_free(gap->advertise_timer); free(gap); gap = NULL; } @@ -551,12 +551,12 @@ static int32_t gap_app(void* context) { UNUSED(context); GapCommand command; while(1) { - osStatus_t status = osMessageQueueGet(gap->command_queue, &command, NULL, osWaitForever); - if(status != osOK) { + FuriStatus status = furi_message_queue_get(gap->command_queue, &command, FuriWaitForever); + if(status != FuriStatusOk) { FURI_LOG_E(TAG, "Message queue get error: %d", status); continue; } - osMutexAcquire(gap->state_mutex, osWaitForever); + furi_mutex_acquire(gap->state_mutex, FuriWaitForever); if(command == GapCommandKillThread) { break; } @@ -567,7 +567,7 @@ static int32_t gap_app(void* context) { } else if(command == GapCommandAdvStop) { gap_advertise_stop(); } - osMutexRelease(gap->state_mutex); + furi_mutex_release(gap->state_mutex); } return 0; diff --git a/firmware/targets/f7/ble_glue/serial_service.c b/firmware/targets/f7/ble_glue/serial_service.c index a5d3b97a1..91e12dd68 100644 --- a/firmware/targets/f7/ble_glue/serial_service.c +++ b/firmware/targets/f7/ble_glue/serial_service.c @@ -11,7 +11,7 @@ typedef struct { uint16_t rx_char_handle; uint16_t tx_char_handle; uint16_t flow_ctrl_char_handle; - osMutexId_t buff_size_mtx; + FuriMutex* buff_size_mtx; uint32_t buff_size; uint16_t bytes_ready_to_receive; SerialServiceEventCallback callback; @@ -44,7 +44,9 @@ static SVCCTL_EvtAckStatus_t serial_svc_event_handler(void* event) { } else if(attribute_modified->Attr_Handle == serial_svc->rx_char_handle + 1) { FURI_LOG_D(TAG, "Received %d bytes", attribute_modified->Attr_Data_Length); if(serial_svc->callback) { - furi_check(osMutexAcquire(serial_svc->buff_size_mtx, osWaitForever) == osOK); + furi_check( + furi_mutex_acquire(serial_svc->buff_size_mtx, FuriWaitForever) == + FuriStatusOk); if(attribute_modified->Attr_Data_Length > serial_svc->bytes_ready_to_receive) { FURI_LOG_W( TAG, @@ -62,7 +64,7 @@ static SVCCTL_EvtAckStatus_t serial_svc_event_handler(void* event) { }}; uint32_t buff_free_size = serial_svc->callback(event, serial_svc->context); FURI_LOG_D(TAG, "Available buff size: %d", buff_free_size); - furi_check(osMutexRelease(serial_svc->buff_size_mtx) == osOK); + furi_check(furi_mutex_release(serial_svc->buff_size_mtx) == FuriStatusOk); } ret = SVCCTL_EvtAckFlowEnable; } @@ -140,7 +142,7 @@ void serial_svc_start() { FURI_LOG_E(TAG, "Failed to add Flow Control characteristic: %d", status); } // Allocate buffer size mutex - serial_svc->buff_size_mtx = osMutexNew(NULL); + serial_svc->buff_size_mtx = furi_mutex_alloc(FuriMutexTypeNormal); } void serial_svc_set_callbacks( @@ -165,7 +167,7 @@ void serial_svc_notify_buffer_is_empty() { furi_assert(serial_svc); furi_assert(serial_svc->buff_size_mtx); - furi_check(osMutexAcquire(serial_svc->buff_size_mtx, osWaitForever) == osOK); + furi_check(furi_mutex_acquire(serial_svc->buff_size_mtx, FuriWaitForever) == FuriStatusOk); if(serial_svc->bytes_ready_to_receive == 0) { FURI_LOG_D(TAG, "Buffer is empty. Notifying client"); serial_svc->bytes_ready_to_receive = serial_svc->buff_size; @@ -177,7 +179,7 @@ void serial_svc_notify_buffer_is_empty() { sizeof(uint32_t), (uint8_t*)&buff_size_reversed); } - furi_check(osMutexRelease(serial_svc->buff_size_mtx) == osOK); + furi_check(furi_mutex_release(serial_svc->buff_size_mtx) == FuriStatusOk); } void serial_svc_stop() { @@ -202,7 +204,7 @@ void serial_svc_stop() { FURI_LOG_E(TAG, "Failed to delete Serial service: %d", status); } // Delete buffer size mutex - osMutexDelete(serial_svc->buff_size_mtx); + furi_mutex_free(serial_svc->buff_size_mtx); free(serial_svc); serial_svc = NULL; } diff --git a/firmware/targets/f7/fatfs/ffconf.h b/firmware/targets/f7/fatfs/ffconf.h index 83bcfc783..9410cedc8 100644 --- a/firmware/targets/f7/fatfs/ffconf.h +++ b/firmware/targets/f7/fatfs/ffconf.h @@ -245,7 +245,7 @@ #define _FS_REENTRANT 0 /* 0:Disable or 1:Enable */ #define _FS_TIMEOUT 1000 /* Timeout period in unit of time ticks */ -#define _SYNC_t osMutexId_t +#define _SYNC_t FuriMutex* /* The option _FS_REENTRANT switches the re-entrancy (thread safe) of the FatFs / module itself. Note that regardless of this option, file access to different / volume is always re-entrant and volume control functions, f_mount(), f_mkfs() diff --git a/firmware/targets/f7/fatfs/spi_sd_hal.c b/firmware/targets/f7/fatfs/spi_sd_hal.c index 1b96568c2..bfe046b58 100644 --- a/firmware/targets/f7/fatfs/spi_sd_hal.c +++ b/firmware/targets/f7/fatfs/spi_sd_hal.c @@ -46,7 +46,7 @@ void SD_IO_Init(void) { /* SD chip select high */ furi_hal_gpio_write(furi_hal_sd_spi_handle->cs, true); - furi_hal_delay_us(10); + furi_delay_us(10); /* Send dummy byte 0xFF, 10 times with CS high */ /* Rise CS and MOSI for 80 clocks cycles */ @@ -64,11 +64,11 @@ void SD_IO_Init(void) { void SD_IO_CSState(uint8_t val) { /* Some SD Cards are prone to fail if CLK-ed too soon after CS transition. Worst case found: 8us */ if(val == 1) { - furi_hal_delay_us(10); // Exit guard time for some SD cards + furi_delay_us(10); // Exit guard time for some SD cards furi_hal_gpio_write(furi_hal_sd_spi_handle->cs, true); } else { furi_hal_gpio_write(furi_hal_sd_spi_handle->cs, false); - furi_hal_delay_us(10); // Entry guard time for some SD cards + furi_delay_us(10); // Entry guard time for some SD cards } } diff --git a/firmware/targets/f7/fatfs/stm32_adafruit_sd.c b/firmware/targets/f7/fatfs/stm32_adafruit_sd.c index fc2924d43..1ca38abe4 100644 --- a/firmware/targets/f7/fatfs/stm32_adafruit_sd.c +++ b/firmware/targets/f7/fatfs/stm32_adafruit_sd.c @@ -349,13 +349,13 @@ uint8_t BSP_SD_Init(bool reset_card) { furi_hal_power_disable_external_3_3v(); SD_SPI_Bus_To_Down_State(); hal_sd_detect_set_low(); - furi_hal_delay_ms(250); + furi_delay_ms(250); /* reinit bus and enable power */ SD_SPI_Bus_To_Normal_State(); hal_sd_detect_init(); furi_hal_power_enable_external_3_3v(); - furi_hal_delay_ms(100); + furi_delay_ms(100); } /* Configure IO functionalities for SD pin */ @@ -869,7 +869,7 @@ SD_CmdAnswer_typedef SD_SendCmd(uint8_t Cmd, uint32_t Arg, uint8_t Crc, uint8_t retr.r2 = SD_IO_WriteByte(SD_DUMMY_BYTE); /* Set CS High */ SD_IO_CSState(1); - furi_hal_delay_us(1000); + furi_delay_us(1000); /* Set CS Low */ SD_IO_CSState(0); diff --git a/firmware/targets/f7/fatfs/syscall.c b/firmware/targets/f7/fatfs/syscall.c index 7bed93150..00eb8aede 100644 --- a/firmware/targets/f7/fatfs/syscall.c +++ b/firmware/targets/f7/fatfs/syscall.c @@ -38,7 +38,7 @@ int ff_cre_syncobj(/* 1:Function succeeded, 0:Could not create the sync object * //osSemaphoreDef(SEM); //*sobj = osSemaphoreCreate(osSemaphore(SEM), 1); - *sobj = osMutexNew(NULL); + *sobj = furi_mutex_alloc(FuriMutexTypeNormal); ret = (*sobj != NULL); return ret; @@ -55,7 +55,7 @@ int ff_cre_syncobj(/* 1:Function succeeded, 0:Could not create the sync object * int ff_del_syncobj(/* 1:Function succeeded, 0:Could not delete due to any error */ _SYNC_t sobj /* Sync object tied to the logical drive to be deleted */ ) { - osMutexDelete(sobj); + furi_mutex_free(sobj); return 1; } @@ -71,7 +71,7 @@ int ff_req_grant(/* 1:Got a grant to access the volume, 0:Could not get a grant ) { int ret = 0; - if(osMutexAcquire(sobj, _FS_TIMEOUT) == osOK) { + if(furi_mutex_acquire(sobj, _FS_TIMEOUT) == FuriStatusOk) { ret = 1; } @@ -86,7 +86,7 @@ int ff_req_grant(/* 1:Got a grant to access the volume, 0:Could not get a grant void ff_rel_grant(_SYNC_t sobj /* Sync object to be signaled */ ) { - osMutexRelease(sobj); + furi_mutex_release(sobj); } #endif diff --git a/firmware/targets/f7/furi_hal/furi_hal.c b/firmware/targets/f7/furi_hal/furi_hal.c index e97c0e8c1..0cef33ddf 100644 --- a/firmware/targets/f7/furi_hal/furi_hal.c +++ b/firmware/targets/f7/furi_hal/furi_hal.c @@ -7,8 +7,9 @@ #define TAG "FuriHal" void furi_hal_init_early() { + furi_hal_cortex_init_early(); + furi_hal_clock_init_early(); - furi_hal_delay_init(); furi_hal_resources_init_early(); diff --git a/firmware/targets/f7/furi_hal/furi_hal_bt.c b/firmware/targets/f7/furi_hal/furi_hal_bt.c index dde3842d0..47ed5992e 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_bt.c +++ b/firmware/targets/f7/furi_hal/furi_hal_bt.c @@ -2,7 +2,6 @@ #include #include #include -#include #include #include @@ -19,7 +18,7 @@ /* Time, in ms, to wait for mode transition before crashing */ #define C2_MODE_SWITCH_TIMEOUT 10000 -osMutexId_t furi_hal_bt_core2_mtx = NULL; +FuriMutex* furi_hal_bt_core2_mtx = NULL; static FuriHalBtStack furi_hal_bt_stack = FuriHalBtStackUnknown; typedef void (*FuriHalBtProfileStart)(void); @@ -79,7 +78,7 @@ FuriHalBtProfileConfig* current_profile = NULL; void furi_hal_bt_init() { if(!furi_hal_bt_core2_mtx) { - furi_hal_bt_core2_mtx = osMutexNew(NULL); + furi_hal_bt_core2_mtx = furi_mutex_alloc(FuriMutexTypeNormal); furi_assert(furi_hal_bt_core2_mtx); } @@ -94,12 +93,12 @@ void furi_hal_bt_init() { void furi_hal_bt_lock_core2() { furi_assert(furi_hal_bt_core2_mtx); - furi_check(osMutexAcquire(furi_hal_bt_core2_mtx, osWaitForever) == osOK); + furi_check(furi_mutex_acquire(furi_hal_bt_core2_mtx, FuriWaitForever) == FuriStatusOk); } void furi_hal_bt_unlock_core2() { furi_assert(furi_hal_bt_core2_mtx); - furi_check(osMutexRelease(furi_hal_bt_core2_mtx) == osOK); + furi_check(furi_mutex_release(furi_hal_bt_core2_mtx) == FuriStatusOk); } static bool furi_hal_bt_radio_stack_is_supported(const BleGlueC2Info* info) { @@ -126,7 +125,7 @@ bool furi_hal_bt_start_radio_stack() { bool res = false; furi_assert(furi_hal_bt_core2_mtx); - osMutexAcquire(furi_hal_bt_core2_mtx, osWaitForever); + furi_mutex_acquire(furi_hal_bt_core2_mtx, FuriWaitForever); // Explicitly tell that we are in charge of CLK48 domain if(!LL_HSEM_IsSemaphoreLocked(HSEM, CFG_HW_CLK48_CONFIG_SEMID)) { @@ -162,7 +161,7 @@ bool furi_hal_bt_start_radio_stack() { } res = true; } while(false); - osMutexRelease(furi_hal_bt_core2_mtx); + furi_mutex_release(furi_hal_bt_core2_mtx); return res; } @@ -255,7 +254,7 @@ void furi_hal_bt_reinit() { FURI_LOG_I(TAG, "Reset SHCI"); furi_check(ble_glue_reinit_c2()); - osDelay(100); + furi_delay_ms(100); ble_glue_thread_stop(); FURI_LOG_I(TAG, "Start BT initialization"); @@ -292,7 +291,7 @@ void furi_hal_bt_stop_advertising() { if(furi_hal_bt_is_active()) { gap_stop_advertising(); while(furi_hal_bt_is_active()) { - osDelay(1); + furi_delay_tick(1); } } } @@ -436,7 +435,7 @@ bool furi_hal_bt_ensure_c2_mode(BleGlueC2Mode mode) { return true; } else if(fw_start_res == BleGlueCommandResultRestartPending) { // Do nothing and wait for system reset - osDelay(C2_MODE_SWITCH_TIMEOUT); + furi_delay_ms(C2_MODE_SWITCH_TIMEOUT); furi_crash("Waiting for FUS->radio stack transition"); return true; } diff --git a/firmware/targets/f7/furi_hal/furi_hal_cortex.c b/firmware/targets/f7/furi_hal/furi_hal_cortex.c new file mode 100644 index 000000000..2b4ea6e99 --- /dev/null +++ b/firmware/targets/f7/furi_hal/furi_hal_cortex.c @@ -0,0 +1,20 @@ +#include "furi_hal_cortex.h" + +#include + +void furi_hal_cortex_init_early() { + CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk; + DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk; + DWT->CYCCNT = 0U; +} + +void furi_hal_cortex_delay_us(uint32_t microseconds) { + uint32_t start = DWT->CYCCNT; + uint32_t time_ticks = SystemCoreClock / 1000000 * microseconds; + while((DWT->CYCCNT - start) < time_ticks) { + }; +} + +uint32_t furi_hal_cortex_instructions_per_microsecond() { + return SystemCoreClock / 1000000; +} diff --git a/firmware/targets/f7/furi_hal/furi_hal_crc.c b/firmware/targets/f7/furi_hal/furi_hal_crc.c deleted file mode 100644 index 9ac13e970..000000000 --- a/firmware/targets/f7/furi_hal/furi_hal_crc.c +++ /dev/null @@ -1,93 +0,0 @@ -#include -#include - -typedef enum { - CRC_State_Reset, - CRC_State_Ready, - CRC_State_Busy, -} CRC_State; - -typedef struct { - CRC_State state; - osMutexId_t mtx; -} HAL_CRC_Control; - -static volatile HAL_CRC_Control hal_crc_control = { - .state = CRC_State_Reset, - .mtx = NULL, -}; - -void furi_hal_crc_init(bool synchronize) { - /* initialize peripheral with default generating polynomial */ - LL_CRC_SetInputDataReverseMode(CRC, LL_CRC_INDATA_REVERSE_BYTE); - LL_CRC_SetOutputDataReverseMode(CRC, LL_CRC_OUTDATA_REVERSE_BIT); - LL_CRC_SetPolynomialCoef(CRC, LL_CRC_DEFAULT_CRC32_POLY); - LL_CRC_SetPolynomialSize(CRC, LL_CRC_POLYLENGTH_32B); - LL_CRC_SetInitialData(CRC, LL_CRC_DEFAULT_CRC_INITVALUE); - - if(synchronize) { - hal_crc_control.mtx = osMutexNew(NULL); - } - hal_crc_control.state = CRC_State_Ready; -} - -void furi_hal_crc_reset() { - furi_check(hal_crc_control.state == CRC_State_Ready); - if(hal_crc_control.mtx) { - furi_check(osMutexGetOwner(hal_crc_control.mtx) == furi_thread_get_current_id()); - osMutexRelease(hal_crc_control.mtx); - } - LL_CRC_ResetCRCCalculationUnit(CRC); -} - -static uint32_t furi_hal_crc_handle_8(uint8_t pBuffer[], uint32_t BufferLength) { - uint32_t i; /* input data buffer index */ - hal_crc_control.state = CRC_State_Busy; - /* Processing time optimization: 4 bytes are entered in a row with a single word write, - * last bytes must be carefully fed to the CRC calculator to ensure a correct type - * handling by the peripheral */ - for(i = 0U; i < (BufferLength / 4U); i++) { - LL_CRC_FeedData32( - CRC, - ((uint32_t)pBuffer[4U * i] << 24U) | ((uint32_t)pBuffer[(4U * i) + 1U] << 16U) | - ((uint32_t)pBuffer[(4U * i) + 2U] << 8U) | (uint32_t)pBuffer[(4U * i) + 3U]); - } - /* last bytes specific handling */ - if((BufferLength % 4U) != 0U) { - if((BufferLength % 4U) == 1U) { - LL_CRC_FeedData8(CRC, pBuffer[4U * i]); - } else if((BufferLength % 4U) == 2U) { - LL_CRC_FeedData16( - CRC, ((uint16_t)(pBuffer[4U * i]) << 8U) | (uint16_t)pBuffer[(4U * i) + 1U]); - } else if((BufferLength % 4U) == 3U) { - LL_CRC_FeedData16( - CRC, ((uint16_t)(pBuffer[4U * i]) << 8U) | (uint16_t)pBuffer[(4U * i) + 1U]); - LL_CRC_FeedData8(CRC, pBuffer[(4U * i) + 2U]); - } - } - - hal_crc_control.state = CRC_State_Ready; - /* Return the CRC computed value */ - return LL_CRC_ReadData32(CRC); -} - -static uint32_t furi_hal_crc_accumulate(uint32_t pBuffer[], uint32_t BufferLength) { - furi_check(hal_crc_control.state == CRC_State_Ready); - if(hal_crc_control.mtx) { - furi_check(osMutexGetOwner(hal_crc_control.mtx) != NULL); - } - return furi_hal_crc_handle_8((uint8_t*)pBuffer, BufferLength); -} - -uint32_t furi_hal_crc_feed(void* data, uint16_t length) { - return ~furi_hal_crc_accumulate(data, length); -} - -bool furi_hal_crc_acquire(uint32_t timeout) { - furi_assert(hal_crc_control.mtx); - if(osMutexAcquire(hal_crc_control.mtx, timeout) == osOK) { - LL_CRC_ResetCRCCalculationUnit(CRC); - return true; - } - return false; -} diff --git a/firmware/targets/f7/furi_hal/furi_hal_crc.h b/firmware/targets/f7/furi_hal/furi_hal_crc.h deleted file mode 100644 index 8abaaad1d..000000000 --- a/firmware/targets/f7/furi_hal/furi_hal_crc.h +++ /dev/null @@ -1,35 +0,0 @@ -#pragma once - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** Configure for CRC32 calculation - * @param synchronize enforce acquisition & release in multithreaded environment - */ -void furi_hal_crc_init(bool synchronize); - -/** Blocking call to get control of CRC block. Mandatory while RTOS is running - * @param timeout time to wait for CRC to be available. Can be osWaitForever - * @return bool acquisition success - */ -bool furi_hal_crc_acquire(uint32_t timeout); - -/** Reset current calculation state and release CRC block - */ -void furi_hal_crc_reset(); - -/** Process data block. Does not reset current state, - * allowing to process arbitrary data lengths - * @param data pointer to data - * @param length data length - * @return uint32_t CRC32 value - */ -uint32_t furi_hal_crc_feed(void* data, uint16_t length); - -#ifdef __cplusplus -} -#endif diff --git a/firmware/targets/f7/furi_hal/furi_hal_crypto.c b/firmware/targets/f7/furi_hal/furi_hal_crypto.c index 2164ebc32..b3c68e2d0 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_crypto.c +++ b/firmware/targets/f7/furi_hal/furi_hal_crypto.c @@ -23,7 +23,7 @@ #define CRYPTO_KEYSIZE_256B (AES_CR_KEYSIZE) #define CRYPTO_AES_CBC (AES_CR_CHMOD_0) -static osMutexId_t furi_hal_crypto_mutex = NULL; +static FuriMutex* furi_hal_crypto_mutex = NULL; static bool furi_hal_crypto_mode_init_done = false; static const uint8_t enclave_signature_iv[ENCLAVE_FACTORY_KEY_SLOTS][16] = { @@ -66,7 +66,7 @@ static const uint8_t enclave_signature_expected[ENCLAVE_FACTORY_KEY_SLOTS][ENCLA }; void furi_hal_crypto_init() { - furi_hal_crypto_mutex = osMutexNew(NULL); + furi_hal_crypto_mutex = furi_mutex_alloc(FuriMutexTypeNormal); FURI_LOG_I(TAG, "Init OK"); } @@ -143,7 +143,7 @@ bool furi_hal_crypto_store_add_key(FuriHalCryptoKey* key, uint8_t* slot) { furi_assert(key); furi_assert(slot); - furi_check(osMutexAcquire(furi_hal_crypto_mutex, osWaitForever) == osOK); + furi_check(furi_mutex_acquire(furi_hal_crypto_mutex, FuriWaitForever) == FuriStatusOk); if(!furi_hal_bt_is_alive()) { return false; @@ -176,7 +176,7 @@ bool furi_hal_crypto_store_add_key(FuriHalCryptoKey* key, uint8_t* slot) { memcpy(pParam.KeyData, key->data, key_data_size); SHCI_CmdStatus_t shci_state = SHCI_C2_FUS_StoreUsrKey(&pParam, slot); - furi_check(osMutexRelease(furi_hal_crypto_mutex) == osOK); + furi_check(furi_mutex_release(furi_hal_crypto_mutex) == FuriStatusOk); return (shci_state == SHCI_Success); } @@ -239,7 +239,7 @@ static bool crypto_process_block(uint32_t* in, uint32_t* out, uint8_t blk_len) { bool furi_hal_crypto_store_load_key(uint8_t slot, const uint8_t* iv) { furi_assert(slot > 0 && slot <= 100); furi_assert(furi_hal_crypto_mutex); - furi_check(osMutexAcquire(furi_hal_crypto_mutex, osWaitForever) == osOK); + furi_check(furi_mutex_acquire(furi_hal_crypto_mutex, FuriWaitForever) == FuriStatusOk); if(!furi_hal_bt_is_alive()) { return false; @@ -252,7 +252,7 @@ bool furi_hal_crypto_store_load_key(uint8_t slot, const uint8_t* iv) { return true; } else { CLEAR_BIT(AES1->CR, AES_CR_EN); - furi_check(osMutexRelease(furi_hal_crypto_mutex) == osOK); + furi_check(furi_mutex_release(furi_hal_crypto_mutex) == FuriStatusOk); return false; } } @@ -272,7 +272,7 @@ bool furi_hal_crypto_store_unload_key(uint8_t slot) { LL_AHB2_GRP1_ReleaseReset(LL_AHB2_GRP1_PERIPH_AES1); FURI_CRITICAL_EXIT(); - furi_check(osMutexRelease(furi_hal_crypto_mutex) == osOK); + furi_check(furi_mutex_release(furi_hal_crypto_mutex) == FuriStatusOk); return (shci_state == SHCI_Success); } diff --git a/firmware/targets/f7/furi_hal/furi_hal_delay.c b/firmware/targets/f7/furi_hal/furi_hal_delay.c deleted file mode 100644 index 996362309..000000000 --- a/firmware/targets/f7/furi_hal/furi_hal_delay.c +++ /dev/null @@ -1,45 +0,0 @@ -#include "furi_hal_delay.h" - -#include -#include -#include - -#define TAG "FuriHalDelay" - -void furi_hal_delay_init() { - CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk; - DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk; - DWT->CYCCNT = 0U; -} - -uint32_t furi_hal_delay_instructions_per_microsecond() { - return SystemCoreClock / 1000000; -} - -uint32_t furi_hal_get_tick(void) { - return osKernelGetTickCount(); -} - -uint32_t furi_hal_ms_to_ticks(float milliseconds) { - return milliseconds / (1000.0f / osKernelGetTickFreq()); -} - -void furi_hal_delay_us(float microseconds) { - uint32_t start = DWT->CYCCNT; - uint32_t time_ticks = microseconds * furi_hal_delay_instructions_per_microsecond(); - while((DWT->CYCCNT - start) < time_ticks) { - }; -} - -// cannot be used in ISR -// TODO add delay_ISR variant -void furi_hal_delay_ms(float milliseconds) { - if(!FURI_IS_ISR() && osKernelGetState() == osKernelRunning) { - uint32_t ticks = milliseconds / (1000.0f / osKernelGetTickFreq()); - osStatus_t result = osDelay(ticks); - (void)result; - furi_assert(result == osOK); - } else { - furi_hal_delay_us(milliseconds * 1000); - } -} diff --git a/firmware/targets/f7/furi_hal/furi_hal_i2c.c b/firmware/targets/f7/furi_hal/furi_hal_i2c.c index fdef11270..36f5230c2 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_i2c.c +++ b/firmware/targets/f7/furi_hal/furi_hal_i2c.c @@ -1,5 +1,4 @@ #include -#include #include #include @@ -61,11 +60,11 @@ bool furi_hal_i2c_tx( furi_assert(timeout > 0); bool ret = true; - uint32_t timeout_tick = furi_hal_get_tick() + timeout; + uint32_t timeout_tick = furi_get_tick() + timeout; do { while(LL_I2C_IsActiveFlag_BUSY(handle->bus->i2c)) { - if(furi_hal_get_tick() >= timeout_tick) { + if(furi_get_tick() >= timeout_tick) { ret = false; break; } @@ -90,7 +89,7 @@ bool furi_hal_i2c_tx( size--; } - if(furi_hal_get_tick() >= timeout_tick) { + if(furi_get_tick() >= timeout_tick) { ret = false; break; } @@ -112,11 +111,11 @@ bool furi_hal_i2c_rx( furi_assert(timeout > 0); bool ret = true; - uint32_t timeout_tick = furi_hal_get_tick() + timeout; + uint32_t timeout_tick = furi_get_tick() + timeout; do { while(LL_I2C_IsActiveFlag_BUSY(handle->bus->i2c)) { - if(furi_hal_get_tick() >= timeout_tick) { + if(furi_get_tick() >= timeout_tick) { ret = false; break; } @@ -141,7 +140,7 @@ bool furi_hal_i2c_rx( size--; } - if(furi_hal_get_tick() >= timeout_tick) { + if(furi_get_tick() >= timeout_tick) { ret = false; break; } @@ -176,11 +175,11 @@ bool furi_hal_i2c_is_device_ready(FuriHalI2cBusHandle* handle, uint8_t i2c_addr, furi_assert(timeout > 0); bool ret = true; - uint32_t timeout_tick = furi_hal_get_tick() + timeout; + uint32_t timeout_tick = furi_get_tick() + timeout; do { while(LL_I2C_IsActiveFlag_BUSY(handle->bus->i2c)) { - if(furi_hal_get_tick() >= timeout_tick) { + if(furi_get_tick() >= timeout_tick) { return false; } } @@ -191,14 +190,14 @@ bool furi_hal_i2c_is_device_ready(FuriHalI2cBusHandle* handle, uint8_t i2c_addr, while((!LL_I2C_IsActiveFlag_NACK(handle->bus->i2c)) && (!LL_I2C_IsActiveFlag_STOP(handle->bus->i2c))) { - if(furi_hal_get_tick() >= timeout_tick) { + if(furi_get_tick() >= timeout_tick) { return false; } } if(LL_I2C_IsActiveFlag_NACK(handle->bus->i2c)) { while(!LL_I2C_IsActiveFlag_STOP(handle->bus->i2c)) { - if(furi_hal_get_tick() >= timeout_tick) { + if(furi_get_tick() >= timeout_tick) { return false; } } @@ -215,7 +214,7 @@ bool furi_hal_i2c_is_device_ready(FuriHalI2cBusHandle* handle, uint8_t i2c_addr, } while(!LL_I2C_IsActiveFlag_STOP(handle->bus->i2c)) { - if(furi_hal_get_tick() >= timeout_tick) { + if(furi_get_tick() >= timeout_tick) { return false; } } @@ -309,11 +308,11 @@ bool furi_hal_i2c_write_mem( bool ret = true; uint8_t size = len + 1; - uint32_t timeout_tick = furi_hal_get_tick() + timeout; + uint32_t timeout_tick = furi_get_tick() + timeout; do { while(LL_I2C_IsActiveFlag_BUSY(handle->bus->i2c)) { - if(furi_hal_get_tick() >= timeout_tick) { + if(furi_get_tick() >= timeout_tick) { ret = false; break; } @@ -342,7 +341,7 @@ bool furi_hal_i2c_write_mem( size--; } - if(furi_hal_get_tick() >= timeout_tick) { + if(furi_get_tick() >= timeout_tick) { ret = false; break; } diff --git a/firmware/targets/f7/furi_hal/furi_hal_i2c_config.c b/firmware/targets/f7/furi_hal/furi_hal_i2c_config.c index 2cdef23ac..d832c4f66 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_i2c_config.c +++ b/firmware/targets/f7/furi_hal/furi_hal_i2c_config.c @@ -16,26 +16,27 @@ */ #define FURI_HAL_I2C_CONFIG_POWER_I2C_TIMINGS_400 0x00602173 -osMutexId_t furi_hal_i2c_bus_power_mutex = NULL; +FuriMutex* furi_hal_i2c_bus_power_mutex = NULL; static void furi_hal_i2c_bus_power_event(FuriHalI2cBus* bus, FuriHalI2cBusEvent event) { if(event == FuriHalI2cBusEventInit) { - furi_hal_i2c_bus_power_mutex = osMutexNew(NULL); + furi_hal_i2c_bus_power_mutex = furi_mutex_alloc(FuriMutexTypeNormal); FURI_CRITICAL_ENTER(); LL_RCC_SetI2CClockSource(LL_RCC_I2C1_CLKSOURCE_PCLK1); LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_I2C1); FURI_CRITICAL_EXIT(); bus->current_handle = NULL; } else if(event == FuriHalI2cBusEventDeinit) { - furi_check(osMutexDelete(furi_hal_i2c_bus_power_mutex) == osOK); + furi_mutex_free(furi_hal_i2c_bus_power_mutex); FURI_CRITICAL_ENTER(); LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_I2C1); LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_I2C1); FURI_CRITICAL_EXIT(); } else if(event == FuriHalI2cBusEventLock) { - furi_check(osMutexAcquire(furi_hal_i2c_bus_power_mutex, osWaitForever) == osOK); + furi_check( + furi_mutex_acquire(furi_hal_i2c_bus_power_mutex, FuriWaitForever) == FuriStatusOk); } else if(event == FuriHalI2cBusEventUnlock) { - furi_check(osMutexRelease(furi_hal_i2c_bus_power_mutex) == osOK); + furi_check(furi_mutex_release(furi_hal_i2c_bus_power_mutex) == FuriStatusOk); } else if(event == FuriHalI2cBusEventActivate) { FURI_CRITICAL_ENTER(); LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_I2C1); @@ -52,26 +53,27 @@ FuriHalI2cBus furi_hal_i2c_bus_power = { .callback = furi_hal_i2c_bus_power_event, }; -osMutexId_t furi_hal_i2c_bus_external_mutex = NULL; +FuriMutex* furi_hal_i2c_bus_external_mutex = NULL; static void furi_hal_i2c_bus_external_event(FuriHalI2cBus* bus, FuriHalI2cBusEvent event) { if(event == FuriHalI2cBusEventInit) { - furi_hal_i2c_bus_external_mutex = osMutexNew(NULL); + furi_hal_i2c_bus_external_mutex = furi_mutex_alloc(FuriMutexTypeNormal); FURI_CRITICAL_ENTER(); LL_RCC_SetI2CClockSource(LL_RCC_I2C3_CLKSOURCE_PCLK1); LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_I2C3); FURI_CRITICAL_EXIT(); bus->current_handle = NULL; } else if(event == FuriHalI2cBusEventDeinit) { - furi_check(osMutexDelete(furi_hal_i2c_bus_external_mutex) == osOK); + furi_mutex_free(furi_hal_i2c_bus_external_mutex); FURI_CRITICAL_ENTER(); LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_I2C3); LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_I2C3); FURI_CRITICAL_EXIT(); } else if(event == FuriHalI2cBusEventLock) { - furi_check(osMutexAcquire(furi_hal_i2c_bus_external_mutex, osWaitForever) == osOK); + furi_check( + furi_mutex_acquire(furi_hal_i2c_bus_external_mutex, FuriWaitForever) == FuriStatusOk); } else if(event == FuriHalI2cBusEventUnlock) { - furi_check(osMutexRelease(furi_hal_i2c_bus_external_mutex) == osOK); + furi_check(furi_mutex_release(furi_hal_i2c_bus_external_mutex) == FuriStatusOk); } else if(event == FuriHalI2cBusEventActivate) { FURI_CRITICAL_ENTER(); LL_RCC_SetI2CClockSource(LL_RCC_I2C3_CLKSOURCE_PCLK1); diff --git a/firmware/targets/f7/furi_hal/furi_hal_infrared.c b/firmware/targets/f7/furi_hal/furi_hal_infrared.c index f6f01887d..442ae715d 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_infrared.c +++ b/firmware/targets/f7/furi_hal/furi_hal_infrared.c @@ -1,9 +1,7 @@ #include "furi_hal_infrared.h" -#include "furi_hal_delay.h" -#include "furi/check.h" +#include #include "stm32wbxx_ll_dma.h" #include "sys/_stdint.h" -#include #include #include @@ -52,7 +50,7 @@ typedef struct { void* data_context; void* signal_sent_context; InfraredTxBuf buffer[2]; - osSemaphoreId_t stop_semaphore; + FuriSemaphore* stop_semaphore; uint32_t tx_timing_rest_duration; /** if timing is too long (> 0xFFFF), send it in few iterations */ bool tx_timing_rest_level; @@ -225,8 +223,8 @@ static void furi_hal_infrared_tx_dma_terminate(void) { LL_DMA_DisableChannel(DMA1, LL_DMA_CHANNEL_2); LL_DMA_DisableChannel(DMA1, LL_DMA_CHANNEL_1); LL_TIM_DisableCounter(TIM1); - osStatus_t status = osSemaphoreRelease(infrared_tim_tx.stop_semaphore); - furi_check(status == osOK); + FuriStatus status = furi_semaphore_release(infrared_tim_tx.stop_semaphore); + furi_check(status == FuriStatusOk); furi_hal_infrared_state = InfraredStateAsyncTxStopped; } @@ -545,15 +543,13 @@ static void furi_hal_infrared_async_tx_free_resources(void) { furi_assert( (furi_hal_infrared_state == InfraredStateIdle) || (furi_hal_infrared_state == InfraredStateAsyncTxStopped)); - osStatus_t status; furi_hal_gpio_init(&gpio_infrared_tx, GpioModeOutputOpenDrain, GpioPullDown, GpioSpeedLow); furi_hal_interrupt_set_isr(FuriHalInterruptIdDma1Ch1, NULL, NULL); furi_hal_interrupt_set_isr(FuriHalInterruptIdDma1Ch2, NULL, NULL); LL_TIM_DeInit(TIM1); - status = osSemaphoreDelete(infrared_tim_tx.stop_semaphore); - furi_check(status == osOK); + furi_semaphore_free(infrared_tim_tx.stop_semaphore); free(infrared_tim_tx.buffer[0].data); free(infrared_tim_tx.buffer[1].data); free(infrared_tim_tx.buffer[0].polarity); @@ -586,7 +582,7 @@ void furi_hal_infrared_async_tx_start(uint32_t freq, float duty_cycle) { infrared_tim_tx.buffer[0].polarity = malloc(alloc_size_polarity); infrared_tim_tx.buffer[1].polarity = malloc(alloc_size_polarity); - infrared_tim_tx.stop_semaphore = osSemaphoreNew(1, 0, NULL); + infrared_tim_tx.stop_semaphore = furi_semaphore_alloc(1, 0); infrared_tim_tx.cycle_duration = 1000000.0 / freq; infrared_tim_tx.tx_timing_rest_duration = 0; @@ -603,9 +599,9 @@ void furi_hal_infrared_async_tx_start(uint32_t freq, float duty_cycle) { LL_TIM_ClearFlag_UPDATE(TIM1); LL_DMA_EnableChannel(DMA1, LL_DMA_CHANNEL_1); LL_DMA_EnableChannel(DMA1, LL_DMA_CHANNEL_2); - furi_hal_delay_us(5); + furi_delay_us(5); LL_TIM_GenerateEvent_UPDATE(TIM1); /* DMA -> TIMx_RCR */ - furi_hal_delay_us(5); + furi_delay_us(5); LL_GPIO_ResetOutputPin( gpio_infrared_tx.port, gpio_infrared_tx.pin); /* when disable it prevents false pulse */ furi_hal_gpio_init_ex( @@ -621,9 +617,9 @@ void furi_hal_infrared_async_tx_wait_termination(void) { furi_assert(furi_hal_infrared_state >= InfraredStateAsyncTx); furi_assert(furi_hal_infrared_state < InfraredStateMAX); - osStatus_t status; - status = osSemaphoreAcquire(infrared_tim_tx.stop_semaphore, osWaitForever); - furi_check(status == osOK); + FuriStatus status; + status = furi_semaphore_acquire(infrared_tim_tx.stop_semaphore, FuriWaitForever); + furi_check(status == FuriStatusOk); furi_hal_infrared_async_tx_free_resources(); furi_hal_infrared_state = InfraredStateIdle; } diff --git a/firmware/targets/f7/furi_hal/furi_hal_interrupt.c b/firmware/targets/f7/furi_hal/furi_hal_interrupt.c index 526c9f3da..fa595921a 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_interrupt.c +++ b/firmware/targets/f7/furi_hal/furi_hal_interrupt.c @@ -1,5 +1,4 @@ #include "furi_hal_interrupt.h" -#include "furi_hal_delay.h" #include "furi_hal_os.h" #include diff --git a/firmware/targets/f7/furi_hal/furi_hal_light.c b/firmware/targets/f7/furi_hal/furi_hal_light.c index 5ff02f4a0..e6b3ab7d9 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_light.c +++ b/firmware/targets/f7/furi_hal/furi_hal_light.c @@ -1,7 +1,6 @@ -#include "furi/common_defines.h" +#include #include "furi_hal_resources.h" #include -#include #include #include @@ -108,9 +107,9 @@ void furi_hal_light_sequence(const char* sequence) { } else if(*sequence == 'w') { furi_hal_light_set(LightBacklight, 0x00); } else if(*sequence == '.') { - furi_hal_delay_ms(250); + furi_delay_ms(250); } else if(*sequence == '-') { - furi_hal_delay_ms(500); + furi_delay_ms(500); } sequence++; } while(*sequence != 0); diff --git a/firmware/targets/f7/furi_hal/furi_hal_nfc.c b/firmware/targets/f7/furi_hal/furi_hal_nfc.c index 73f83c5c9..7b7d5f275 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_nfc.c +++ b/firmware/targets/f7/furi_hal/furi_hal_nfc.c @@ -7,16 +7,16 @@ #include #include -#include #include #include +#include #include #define TAG "FuriHalNfc" static const uint32_t clocks_in_ms = 64 * 1000; -osEventFlagsId_t event = NULL; +FuriEventFlag* event = NULL; #define EVENT_FLAG_INTERRUPT (1UL << 0) #define EVENT_FLAG_STATE_CHANGED (1UL << 1) #define EVENT_FLAG_STOP (1UL << 2) @@ -28,7 +28,7 @@ void furi_hal_nfc_init() { ReturnCode ret = rfalNfcInitialize(); if(ret == ERR_NONE) { furi_hal_nfc_start_sleep(); - event = osEventFlagsNew(NULL); + event = furi_event_flag_alloc(); FURI_LOG_I(TAG, "Init OK"); } else { FURI_LOG_W(TAG, "Initialization failed, RFAL returned: %d", ret); @@ -109,7 +109,7 @@ bool furi_hal_nfc_detect(FuriHalNfcDevData* nfc_data, uint32_t timeout) { FURI_LOG_T(TAG, "Timeout"); break; } - osDelay(1); + furi_delay_tick(1); } rfalNfcGetDevicesFound(&dev_list, &dev_cnt); if(detected) { @@ -243,7 +243,7 @@ bool furi_hal_nfc_listen( rfalNfcDeactivate(true); return false; } - osDelay(1); + furi_delay_tick(1); } return true; } @@ -273,7 +273,7 @@ bool furi_hal_nfc_listen_rx(FuriHalNfcTxRxContext* tx_rx, uint32_t timeout_ms) { furi_assert(tx_rx); // Wait for interrupts - uint32_t start = osKernelGetTickCount(); + uint32_t start = furi_get_tick(); bool data_received = false; while(true) { if(furi_hal_gpio_read(&gpio_nfc_irq_rfid_pull) == true) { @@ -285,9 +285,9 @@ bool furi_hal_nfc_listen_rx(FuriHalNfcTxRxContext* tx_rx, uint32_t timeout_ms) { } continue; } - if(osKernelGetTickCount() - start > timeout_ms) { + if(furi_get_tick() - start > timeout_ms) { FURI_LOG_T(TAG, "Interrupt waiting timeout"); - osDelay(1); + furi_delay_tick(1); break; } } @@ -352,17 +352,17 @@ void furi_hal_nfc_listen_start(FuriHalNfcDevData* nfc_data) { } void rfal_interrupt_callback_handler() { - osEventFlagsSet(event, EVENT_FLAG_INTERRUPT); + furi_event_flag_set(event, EVENT_FLAG_INTERRUPT); } void rfal_state_changed_callback(void* context) { UNUSED(context); - osEventFlagsSet(event, EVENT_FLAG_STATE_CHANGED); + furi_event_flag_set(event, EVENT_FLAG_STATE_CHANGED); } void furi_hal_nfc_stop() { if(event) { - osEventFlagsSet(event, EVENT_FLAG_STOP); + furi_event_flag_set(event, EVENT_FLAG_STOP); } } @@ -405,8 +405,8 @@ bool furi_hal_nfc_emulate_nfca( while(true) { buff_rx_len = 0; buff_tx_len = 0; - uint32_t flag = osEventFlagsWait(event, EVENT_FLAG_ALL, osFlagsWaitAny, timeout); - if(flag == osFlagsErrorTimeout || flag == EVENT_FLAG_STOP) { + uint32_t flag = furi_event_flag_wait(event, EVENT_FLAG_ALL, FuriFlagWaitAny, timeout); + if(flag == FuriFlagErrorTimeout || flag == EVENT_FLAG_STOP) { break; } bool data_received = false; @@ -515,7 +515,7 @@ static bool furi_hal_nfc_transparent_tx_rx(FuriHalNfcTxRxContext* tx_rx, uint16_ } } uint32_t timeout = DWT->CYCCNT - start; - if(timeout / furi_hal_delay_instructions_per_microsecond() > timeout_ms * 1000) { + if(timeout / furi_hal_cortex_instructions_per_microsecond() > timeout_ms * 1000) { FURI_LOG_D(TAG, "Interrupt waiting timeout"); break; } @@ -668,7 +668,7 @@ bool furi_hal_nfc_tx_rx(FuriHalNfcTxRxContext* tx_rx, uint16_t timeout_ms) { } else { start = DWT->CYCCNT; } - osDelay(1); + furi_delay_tick(1); } if(tx_rx->tx_rx_type == FuriHalNfcTxRxTypeRaw || diff --git a/firmware/targets/f7/furi_hal/furi_hal_os.c b/firmware/targets/f7/furi_hal/furi_hal_os.c index 9dd7191fb..97d022c93 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_os.c +++ b/firmware/targets/f7/furi_hal/furi_hal_os.c @@ -47,8 +47,9 @@ void furi_hal_os_init() { furi_hal_gpio_init_simple(&gpio_ext_pa7, GpioModeOutputPushPull); furi_hal_gpio_init_simple(&gpio_ext_pa6, GpioModeOutputPushPull); furi_hal_gpio_init_simple(&gpio_ext_pa4, GpioModeOutputPushPull); - osTimerId_t second_timer = osTimerNew(furi_hal_os_timer_callback, osTimerPeriodic, NULL, NULL); - osTimerStart(second_timer, FURI_HAL_OS_TICK_HZ); + FuriTimer* second_timer = + furi_timer_alloc(furi_hal_os_timer_callback, FuriTimerTypePeriodic, NULL); + furi_timer_start(second_timer, FURI_HAL_OS_TICK_HZ); #endif FURI_LOG_I(TAG, "Init OK"); diff --git a/firmware/targets/f7/furi_hal/furi_hal_power.c b/firmware/targets/f7/furi_hal/furi_hal_power.c index 28e6cb051..246383921 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_power.c +++ b/firmware/targets/f7/furi_hal/furi_hal_power.c @@ -1,6 +1,5 @@ #include #include -#include #include #include #include @@ -302,7 +301,7 @@ void furi_hal_power_shutdown() { void furi_hal_power_off() { // Crutch: shutting down with ext 3V3 off is causing LSE to stop furi_hal_power_enable_external_3_3v(); - furi_hal_delay_us(1000); + furi_delay_us(1000); // Send poweroff to charger furi_hal_i2c_acquire(&furi_hal_i2c_handle_power); bq25896_poweroff(&furi_hal_i2c_handle_power); diff --git a/firmware/targets/f7/furi_hal/furi_hal_resources.c b/firmware/targets/f7/furi_hal/furi_hal_resources.c index c1238212a..98ebedf51 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_resources.c +++ b/firmware/targets/f7/furi_hal/furi_hal_resources.c @@ -1,5 +1,4 @@ #include -#include #include #include @@ -98,7 +97,7 @@ void furi_hal_resources_init_early() { furi_hal_gpio_init_simple(&gpio_usb_dp, GpioModeOutputOpenDrain); furi_hal_gpio_write(&gpio_usb_dm, 0); furi_hal_gpio_write(&gpio_usb_dp, 0); - furi_hal_delay_us(5); // Device Driven disconnect: 2.5us + extra to compensate cables + furi_delay_us(5); // Device Driven disconnect: 2.5us + extra to compensate cables furi_hal_gpio_write(&gpio_usb_dm, 1); furi_hal_gpio_write(&gpio_usb_dp, 1); furi_hal_gpio_init_simple(&gpio_usb_dm, GpioModeAnalog); diff --git a/firmware/targets/f7/furi_hal/furi_hal_spi_config.c b/firmware/targets/f7/furi_hal/furi_hal_spi_config.c index e01f132e6..56f67bbf8 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_spi_config.c +++ b/firmware/targets/f7/furi_hal/furi_hal_spi_config.c @@ -70,25 +70,25 @@ const LL_SPI_InitTypeDef furi_hal_spi_preset_1edge_low_2m = { /* SPI Buses */ -osMutexId_t furi_hal_spi_bus_r_mutex = NULL; +FuriMutex* furi_hal_spi_bus_r_mutex = NULL; static void furi_hal_spi_bus_r_event_callback(FuriHalSpiBus* bus, FuriHalSpiBusEvent event) { if(event == FuriHalSpiBusEventInit) { - furi_hal_spi_bus_r_mutex = osMutexNew(NULL); + furi_hal_spi_bus_r_mutex = furi_mutex_alloc(FuriMutexTypeNormal); FURI_CRITICAL_ENTER(); LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_SPI1); FURI_CRITICAL_EXIT(); bus->current_handle = NULL; } else if(event == FuriHalSpiBusEventDeinit) { - furi_check(osMutexDelete(furi_hal_spi_bus_r_mutex) == osOK); + furi_mutex_free(furi_hal_spi_bus_r_mutex); FURI_CRITICAL_ENTER(); LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_SPI1); LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_SPI1); FURI_CRITICAL_EXIT(); } else if(event == FuriHalSpiBusEventLock) { - furi_check(osMutexAcquire(furi_hal_spi_bus_r_mutex, osWaitForever) == osOK); + furi_check(furi_mutex_acquire(furi_hal_spi_bus_r_mutex, FuriWaitForever) == FuriStatusOk); } else if(event == FuriHalSpiBusEventUnlock) { - furi_check(osMutexRelease(furi_hal_spi_bus_r_mutex) == osOK); + furi_check(furi_mutex_release(furi_hal_spi_bus_r_mutex) == FuriStatusOk); } else if(event == FuriHalSpiBusEventActivate) { FURI_CRITICAL_ENTER(); LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_SPI1); @@ -105,25 +105,25 @@ FuriHalSpiBus furi_hal_spi_bus_r = { .callback = furi_hal_spi_bus_r_event_callback, }; -osMutexId_t furi_hal_spi_bus_d_mutex = NULL; +FuriMutex* furi_hal_spi_bus_d_mutex = NULL; static void furi_hal_spi_bus_d_event_callback(FuriHalSpiBus* bus, FuriHalSpiBusEvent event) { if(event == FuriHalSpiBusEventInit) { - furi_hal_spi_bus_d_mutex = osMutexNew(NULL); + furi_hal_spi_bus_d_mutex = furi_mutex_alloc(FuriMutexTypeNormal); FURI_CRITICAL_ENTER(); LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_SPI2); FURI_CRITICAL_EXIT(); bus->current_handle = NULL; } else if(event == FuriHalSpiBusEventDeinit) { - furi_check(osMutexDelete(furi_hal_spi_bus_d_mutex) == osOK); + furi_mutex_free(furi_hal_spi_bus_d_mutex); FURI_CRITICAL_ENTER(); LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_SPI2); LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_SPI2); FURI_CRITICAL_EXIT(); } else if(event == FuriHalSpiBusEventLock) { - furi_check(osMutexAcquire(furi_hal_spi_bus_d_mutex, osWaitForever) == osOK); + furi_check(furi_mutex_acquire(furi_hal_spi_bus_d_mutex, FuriWaitForever) == FuriStatusOk); } else if(event == FuriHalSpiBusEventUnlock) { - furi_check(osMutexRelease(furi_hal_spi_bus_d_mutex) == osOK); + furi_check(furi_mutex_release(furi_hal_spi_bus_d_mutex) == FuriStatusOk); } else if(event == FuriHalSpiBusEventActivate) { FURI_CRITICAL_ENTER(); LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_SPI2); diff --git a/firmware/targets/f7/furi_hal/furi_hal_uart.c b/firmware/targets/f7/furi_hal/furi_hal_uart.c index 74b14f4fd..cb44b6d16 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_uart.c +++ b/firmware/targets/f7/furi_hal/furi_hal_uart.c @@ -6,7 +6,6 @@ #include #include -#include static bool furi_hal_usart_prev_enabled[2]; diff --git a/firmware/targets/f7/furi_hal/furi_hal_usb.c b/firmware/targets/f7/furi_hal/furi_hal_usb.c index cedcc82a4..86b10c79c 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_usb.c +++ b/firmware/targets/f7/furi_hal/furi_hal_usb.c @@ -240,8 +240,8 @@ static int32_t furi_hal_usb_thread(void* context) { } while(true) { - uint32_t flags = furi_thread_flags_wait(USB_SRV_ALL_EVENTS, osFlagsWaitAny, 500); - if((flags & osFlagsError) == 0) { + uint32_t flags = furi_thread_flags_wait(USB_SRV_ALL_EVENTS, FuriFlagWaitAny, 500); + if((flags & FuriFlagError) == 0) { if(flags & EventModeChange) { if(usb.if_next != usb.if_cur) { if_new = usb.if_next; @@ -250,7 +250,7 @@ static int32_t furi_hal_usb_thread(void* context) { susp_evt(&udev, 0, 0); usbd_connect(&udev, false); usb.enabled = false; - osDelay(USB_RECONNECT_DELAY); + furi_delay_ms(USB_RECONNECT_DELAY); } flags |= EventModeChangeStart; } @@ -267,7 +267,7 @@ static int32_t furi_hal_usb_thread(void* context) { usbd_enable(&udev, true); if_new = usb.if_cur; - osDelay(USB_RECONNECT_DELAY); + furi_delay_ms(USB_RECONNECT_DELAY); flags |= EventModeChangeStart; } if(flags & EventModeChangeStart) { // Second stage of mode change process diff --git a/firmware/targets/f7/furi_hal/furi_hal_usb_hid.c b/firmware/targets/f7/furi_hal/furi_hal_usb_hid.c index 06f3f231f..a7253223b 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_usb_hid.c +++ b/firmware/targets/f7/furi_hal/furi_hal_usb_hid.c @@ -254,7 +254,7 @@ static bool hid_send_report(uint8_t report_id); static usbd_respond hid_ep_config(usbd_device* dev, uint8_t cfg); static usbd_respond hid_control(usbd_device* dev, usbd_ctlreq* req, usbd_rqc_callback* callback); static usbd_device* usb_dev; -static osSemaphoreId_t hid_semaphore = NULL; +static FuriSemaphore* hid_semaphore = NULL; static bool hid_connected = false; static HidStateCallback callback; static void* cb_ctx; @@ -372,7 +372,7 @@ static void* hid_set_string_descr(char* str) { static void hid_init(usbd_device* dev, FuriHalUsbInterface* intf, void* ctx) { UNUSED(intf); FuriHalUsbHidConfig* cfg = (FuriHalUsbHidConfig*)ctx; - if(hid_semaphore == NULL) hid_semaphore = osSemaphoreNew(1, 1, NULL); + if(hid_semaphore == NULL) hid_semaphore = furi_semaphore_alloc(1, 1); usb_dev = dev; hid_report.keyboard.report_id = ReportIdKeyboard; hid_report.mouse.report_id = ReportIdMouse; @@ -428,7 +428,7 @@ static void hid_on_suspend(usbd_device* dev) { UNUSED(dev); if(hid_connected) { hid_connected = false; - osSemaphoreRelease(hid_semaphore); + furi_semaphore_release(hid_semaphore); if(callback != NULL) { callback(false, cb_ctx); } @@ -438,7 +438,7 @@ static void hid_on_suspend(usbd_device* dev) { static bool hid_send_report(uint8_t report_id) { if((hid_semaphore == NULL) || (hid_connected == false)) return false; - furi_check(osSemaphoreAcquire(hid_semaphore, osWaitForever) == osOK); + furi_check(furi_semaphore_acquire(hid_semaphore, FuriWaitForever) == FuriStatusOk); if(hid_connected == true) { if(report_id == ReportIdKeyboard) usbd_ep_write(usb_dev, HID_EP_IN, &hid_report.keyboard, sizeof(hid_report.keyboard)); @@ -454,7 +454,7 @@ static bool hid_send_report(uint8_t report_id) { static void hid_txrx_ep_callback(usbd_device* dev, uint8_t event, uint8_t ep) { UNUSED(dev); if(event == usbd_evt_eptx) { - osSemaphoreRelease(hid_semaphore); + furi_semaphore_release(hid_semaphore); } else { struct HidReportLED leds; usbd_ep_read(usb_dev, ep, &leds, 2); diff --git a/firmware/targets/f7/furi_hal/furi_hal_usb_u2f.c b/firmware/targets/f7/furi_hal/furi_hal_usb_u2f.c index a80410869..60068f3b4 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_usb_u2f.c +++ b/firmware/targets/f7/furi_hal/furi_hal_usb_u2f.c @@ -147,7 +147,7 @@ static usbd_respond hid_u2f_ep_config(usbd_device* dev, uint8_t cfg); static usbd_respond hid_u2f_control(usbd_device* dev, usbd_ctlreq* req, usbd_rqc_callback* callback); static usbd_device* usb_dev; -static osSemaphoreId_t hid_u2f_semaphore = NULL; +static FuriSemaphore* hid_u2f_semaphore = NULL; static bool hid_u2f_connected = false; static HidU2fCallback callback; @@ -193,7 +193,7 @@ static void hid_u2f_init(usbd_device* dev, FuriHalUsbInterface* intf, void* ctx) UNUSED(intf); UNUSED(ctx); if(hid_u2f_semaphore == NULL) { - hid_u2f_semaphore = osSemaphoreNew(1, 1, NULL); + hid_u2f_semaphore = furi_semaphore_alloc(1, 1); } usb_dev = dev; @@ -220,7 +220,7 @@ static void hid_u2f_on_suspend(usbd_device* dev) { UNUSED(dev); if(hid_u2f_connected) { hid_u2f_connected = false; - osSemaphoreRelease(hid_u2f_semaphore); + furi_semaphore_release(hid_u2f_semaphore); if(callback != NULL) { callback(HidU2fDisconnected, cb_ctx); } @@ -229,7 +229,7 @@ static void hid_u2f_on_suspend(usbd_device* dev) { void furi_hal_hid_u2f_send_response(uint8_t* data, uint8_t len) { if((hid_u2f_semaphore == NULL) || (hid_u2f_connected == false)) return; - furi_check(osSemaphoreAcquire(hid_u2f_semaphore, osWaitForever) == osOK); + furi_check(furi_semaphore_acquire(hid_u2f_semaphore, FuriWaitForever) == FuriStatusOk); if(hid_u2f_connected == true) { usbd_ep_write(usb_dev, HID_EP_OUT, data, len); } @@ -253,7 +253,7 @@ static void hid_u2f_tx_ep_callback(usbd_device* dev, uint8_t event, uint8_t ep) UNUSED(dev); UNUSED(event); UNUSED(ep); - osSemaphoreRelease(hid_u2f_semaphore); + furi_semaphore_release(hid_u2f_semaphore); } static void hid_u2f_txrx_ep_callback(usbd_device* dev, uint8_t event, uint8_t ep) { diff --git a/firmware/targets/furi_hal_include/furi_hal.h b/firmware/targets/furi_hal_include/furi_hal.h index 17814b137..4d1fc9704 100644 --- a/firmware/targets/furi_hal_include/furi_hal.h +++ b/firmware/targets/furi_hal_include/furi_hal.h @@ -9,6 +9,7 @@ template struct STOP_EXTERNING_ME {}; #endif +#include "furi_hal_cortex.h" #include "furi_hal_clock.h" #include "furi_hal_crypto.h" #include "furi_hal_console.h" @@ -21,7 +22,6 @@ template struct STOP_EXTERNING_ME {}; #include "furi_hal_speaker.h" #include "furi_hal_gpio.h" #include "furi_hal_light.h" -#include "furi_hal_delay.h" #include "furi_hal_power.h" #include "furi_hal_interrupt.h" #include "furi_hal_version.h" diff --git a/firmware/targets/furi_hal_include/furi_hal_cortex.h b/firmware/targets/furi_hal_include/furi_hal_cortex.h new file mode 100644 index 000000000..13035161d --- /dev/null +++ b/firmware/targets/furi_hal_include/furi_hal_cortex.h @@ -0,0 +1,32 @@ +/** + * @file furi_hal_cortex.h + * ARM Cortex HAL + */ + +#pragma once + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** Early init stage for cortex + */ +void furi_hal_cortex_init_early(); + +/** Microseconds delay + * + * @param[in] microseconds The microseconds to wait + */ +void furi_hal_cortex_delay_us(uint32_t microseconds); + +/** Get instructions per microsecond count + * + * @return instructions per microsecond count + */ +uint32_t furi_hal_cortex_instructions_per_microsecond(); + +#ifdef __cplusplus +} +#endif diff --git a/firmware/targets/furi_hal_include/furi_hal_delay.h b/firmware/targets/furi_hal_include/furi_hal_delay.h deleted file mode 100644 index 8d88a4c1d..000000000 --- a/firmware/targets/furi_hal_include/furi_hal_delay.h +++ /dev/null @@ -1,51 +0,0 @@ -/** - * @file furi_hal_delay.h - * Delay HAL API - */ - -#pragma once - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** Init Delay subsystem */ -void furi_hal_delay_init(); - -/** Get instructions per microsecond count */ -uint32_t furi_hal_delay_instructions_per_microsecond(); - -/** Get current tick counter - * - * System uptime, may overflow. - * - * @return Current ticks in milliseconds - */ -uint32_t furi_hal_get_tick(void); - -/** Convert milliseconds to ticks - * - * @param[in] milliseconds time in milliseconds - * @return time in ticks - */ -uint32_t furi_hal_ms_to_ticks(float milliseconds); - -/** Delay in milliseconds - * @warning Cannot be used from ISR - * - * @param[in] milliseconds milliseconds to wait - */ -void furi_hal_delay_ms(float milliseconds); - -/** Delay in microseconds - * - * @param[in] microseconds microseconds to wait - */ -void furi_hal_delay_us(float microseconds); - -#ifdef __cplusplus -} -#endif diff --git a/core/SConscript b/furi/SConscript similarity index 71% rename from core/SConscript rename to furi/SConscript index 83548355e..a751eb6e1 100644 --- a/core/SConscript +++ b/furi/SConscript @@ -1,9 +1,9 @@ Import("env") -env.Append(LINT_SOURCES=["core"]) +env.Append(LINT_SOURCES=["furi"]) -libenv = env.Clone(FW_LIB_NAME="core") +libenv = env.Clone(FW_LIB_NAME="furi") libenv.ApplyLibFlags() sources = libenv.GlobRecursive("*.c") diff --git a/furi/core/base.h b/furi/core/base.h new file mode 100644 index 000000000..29e874192 --- /dev/null +++ b/furi/core/base.h @@ -0,0 +1,43 @@ +#pragma once + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + FuriWaitForever = 0xFFFFFFFFU, +} FuriWait; + +typedef enum { + FuriFlagWaitAny = 0x00000000U, ///< Wait for any flag (default). + FuriFlagWaitAll = 0x00000001U, ///< Wait for all flags. + FuriFlagNoClear = 0x00000002U, ///< Do not clear flags which have been specified to wait for. + + FuriFlagError = 0x80000000U, ///< Error indicator. + FuriFlagErrorUnknown = 0xFFFFFFFFU, ///< FuriStatusError (-1). + FuriFlagErrorTimeout = 0xFFFFFFFEU, ///< FuriStatusErrorTimeout (-2). + FuriFlagErrorResource = 0xFFFFFFFDU, ///< FuriStatusErrorResource (-3). + FuriFlagErrorParameter = 0xFFFFFFFCU, ///< FuriStatusErrorParameter (-4). + FuriFlagErrorISR = 0xFFFFFFFAU, ///< FuriStatusErrorISR (-6). +} FuriFlag; + +typedef enum { + FuriStatusOk = 0, ///< Operation completed successfully. + FuriStatusError = + -1, ///< Unspecified RTOS error: run-time error but no other error message fits. + FuriStatusErrorTimeout = -2, ///< Operation not completed within the timeout period. + FuriStatusErrorResource = -3, ///< Resource not available. + FuriStatusErrorParameter = -4, ///< Parameter error. + FuriStatusErrorNoMemory = + -5, ///< System is out of memory: it was impossible to allocate or reserve memory for the operation. + FuriStatusErrorISR = + -6, ///< Not allowed in ISR context: the function cannot be called from interrupt service routines. + FuriStatusReserved = 0x7FFFFFFF ///< Prevents enum down-size compiler optimization. +} FuriStatus; + +#ifdef __cplusplus +} +#endif diff --git a/core/furi/check.c b/furi/core/check.c similarity index 100% rename from core/furi/check.c rename to furi/core/check.c diff --git a/core/furi/check.h b/furi/core/check.h similarity index 100% rename from core/furi/check.h rename to furi/core/check.h diff --git a/core/furi/common_defines.h b/furi/core/common_defines.h similarity index 77% rename from core/furi/common_defines.h rename to furi/core/common_defines.h index 5e9a7904e..d75f7592d 100644 --- a/core/furi/common_defines.h +++ b/furi/core/common_defines.h @@ -1,7 +1,8 @@ #pragma once #include -#include +#include +#include #ifdef __cplusplus extern "C" { @@ -100,16 +101,16 @@ extern "C" { #endif #ifndef FURI_CRITICAL_ENTER -#define FURI_CRITICAL_ENTER() \ - uint32_t __isrm = 0; \ - bool __from_isr = FURI_IS_ISR(); \ - bool __kernel_running = (osKernelGetState() == osKernelRunning); \ - if(__from_isr) { \ - __isrm = taskENTER_CRITICAL_FROM_ISR(); \ - } else if(__kernel_running) { \ - taskENTER_CRITICAL(); \ - } else { \ - __disable_irq(); \ +#define FURI_CRITICAL_ENTER() \ + uint32_t __isrm = 0; \ + bool __from_isr = FURI_IS_ISR(); \ + bool __kernel_running = (xTaskGetSchedulerState() == taskSCHEDULER_RUNNING); \ + if(__from_isr) { \ + __isrm = taskENTER_CRITICAL_FROM_ISR(); \ + } else if(__kernel_running) { \ + taskENTER_CRITICAL(); \ + } else { \ + __disable_irq(); \ } #endif @@ -124,6 +125,30 @@ extern "C" { } #endif +static inline bool furi_is_irq_context() { + bool irq = false; + BaseType_t state; + + if(FURI_IS_IRQ_MODE()) { + /* Called from interrupt context */ + irq = true; + } else { + /* Get FreeRTOS scheduler state */ + state = xTaskGetSchedulerState(); + + if(state != taskSCHEDULER_NOT_STARTED) { + /* Scheduler was started */ + if(FURI_IS_IRQ_MASKED()) { + /* Interrupts are masked */ + irq = true; + } + } + } + + /* Return context, 0: thread context, 1: IRQ context */ + return (irq); +} + #ifdef __cplusplus } #endif diff --git a/core/furi/dangerous_defines.h b/furi/core/dangerous_defines.h similarity index 100% rename from core/furi/dangerous_defines.h rename to furi/core/dangerous_defines.h diff --git a/furi/core/event_flag.c b/furi/core/event_flag.c new file mode 100644 index 000000000..5d2a49910 --- /dev/null +++ b/furi/core/event_flag.c @@ -0,0 +1,135 @@ +#include "event_flag.h" +#include "common_defines.h" +#include "check.h" + +#include + +#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()); + return ((FuriEventFlag*)xEventGroupCreate()); +} + +void furi_event_flag_free(FuriEventFlag* instance) { + furi_assert(!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); + + EventGroupHandle_t hEventGroup = (EventGroupHandle_t)instance; + uint32_t rflags; + BaseType_t yield; + + if(FURI_IS_IRQ_MODE() != 0U) { + yield = pdFALSE; + if(xEventGroupSetBitsFromISR(hEventGroup, (EventBits_t)flags, &yield) == pdFAIL) { + rflags = (uint32_t)FuriStatusErrorResource; + } else { + rflags = flags; + portYIELD_FROM_ISR(yield); + } + } else { + rflags = xEventGroupSetBits(hEventGroup, (EventBits_t)flags); + } + + /* Return event flags after setting */ + return (rflags); +} + +uint32_t furi_event_flag_clear(FuriEventFlag* instance, uint32_t flags) { + furi_assert(instance); + furi_assert((flags & FURI_EVENT_FLAG_INVALID_BITS) == 0U); + + EventGroupHandle_t hEventGroup = (EventGroupHandle_t)instance; + uint32_t rflags; + + if(FURI_IS_IRQ_MODE() != 0U) { + rflags = xEventGroupGetBitsFromISR(hEventGroup); + + if(xEventGroupClearBitsFromISR(hEventGroup, (EventBits_t)flags) == pdFAIL) { + rflags = (uint32_t)FuriStatusErrorResource; + } else { + /* xEventGroupClearBitsFromISR only registers clear operation in the timer command queue. */ + /* Yield is required here otherwise clear operation might not execute in the right order. */ + /* See https://github.com/FreeRTOS/FreeRTOS-Kernel/issues/93 for more info. */ + portYIELD_FROM_ISR(pdTRUE); + } + } else { + rflags = xEventGroupClearBits(hEventGroup, (EventBits_t)flags); + } + + /* Return event flags before clearing */ + return (rflags); +} + +uint32_t furi_event_flag_get(FuriEventFlag* instance) { + furi_assert(instance); + + EventGroupHandle_t hEventGroup = (EventGroupHandle_t)instance; + uint32_t rflags; + + if(FURI_IS_IRQ_MODE() != 0U) { + rflags = xEventGroupGetBitsFromISR(hEventGroup); + } else { + rflags = xEventGroupGetBits(hEventGroup); + } + + /* Return current event flags */ + return (rflags); +} + +uint32_t furi_event_flag_wait( + FuriEventFlag* instance, + 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); + + EventGroupHandle_t hEventGroup = (EventGroupHandle_t)instance; + BaseType_t wait_all; + BaseType_t exit_clr; + uint32_t rflags; + + if(options & FuriFlagWaitAll) { + wait_all = pdTRUE; + } else { + wait_all = pdFAIL; + } + + if(options & FuriFlagNoClear) { + exit_clr = pdFAIL; + } else { + exit_clr = pdTRUE; + } + + rflags = xEventGroupWaitBits( + hEventGroup, (EventBits_t)flags, exit_clr, wait_all, (TickType_t)timeout); + + if(options & FuriFlagWaitAll) { + if((flags & rflags) != flags) { + if(timeout > 0U) { + rflags = (uint32_t)FuriStatusErrorTimeout; + } else { + rflags = (uint32_t)FuriStatusErrorResource; + } + } + } else { + if((flags & rflags) == 0U) { + if(timeout > 0U) { + rflags = (uint32_t)FuriStatusErrorTimeout; + } else { + rflags = (uint32_t)FuriStatusErrorResource; + } + } + } + + /* Return event flags before clearing */ + return (rflags); +} diff --git a/furi/core/event_flag.h b/furi/core/event_flag.h new file mode 100644 index 000000000..133c95e7b --- /dev/null +++ b/furi/core/event_flag.h @@ -0,0 +1,70 @@ +/** + * @file event_flag.h + * Furi Event Flag + */ +#pragma once + +#include "base.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef void FuriEventFlag; + +/** Allocate FuriEventFlag + * + * @return pointer to FuriEventFlag + */ +FuriEventFlag* furi_event_flag_alloc(); + +/** Deallocate FuriEventFlag + * + * @param instance pointer to FuriEventFlag + */ +void furi_event_flag_free(FuriEventFlag* instance); + +/** Set flags + * + * @param instance pointer to FuriEventFlag + * @param[in] flags The flags + * + * @return Resulting flags or error (FuriStatus) + */ +uint32_t furi_event_flag_set(FuriEventFlag* instance, uint32_t flags); + +/** Clear flags + * + * @param instance pointer to FuriEventFlag + * @param[in] flags The flags + * + * @return Resulting flags or error (FuriStatus) + */ +uint32_t furi_event_flag_clear(FuriEventFlag* instance, uint32_t flags); + +/** Get flags + * + * @param instance pointer to FuriEventFlag + * + * @return Resulting flags + */ +uint32_t furi_event_flag_get(FuriEventFlag* instance); + +/** Wait flags + * + * @param instance pointer to FuriEventFlag + * @param[in] flags The flags + * @param[in] options The option flags + * @param[in] timeout The timeout + * + * @return Resulting flags or error (FuriStatus) + */ +uint32_t furi_event_flag_wait( + FuriEventFlag* instance, + uint32_t flags, + uint32_t options, + uint32_t timeout); + +#ifdef __cplusplus +} +#endif diff --git a/furi/core/kernel.c b/furi/core/kernel.c new file mode 100644 index 000000000..73d2012b4 --- /dev/null +++ b/furi/core/kernel.c @@ -0,0 +1,174 @@ +#include "kernel.h" +#include "base.h" +#include "check.h" +#include "common_defines.h" + +#include + +#include CMSIS_device_header + +int32_t furi_kernel_lock() { + furi_assert(!furi_is_irq_context()); + + int32_t lock; + + switch(xTaskGetSchedulerState()) { + case taskSCHEDULER_SUSPENDED: + lock = 1; + break; + + case taskSCHEDULER_RUNNING: + vTaskSuspendAll(); + lock = 0; + break; + + case taskSCHEDULER_NOT_STARTED: + default: + lock = (int32_t)FuriStatusError; + break; + } + + /* Return previous lock state */ + return (lock); +} + +int32_t furi_kernel_unlock() { + furi_assert(!furi_is_irq_context()); + + int32_t lock; + + switch(xTaskGetSchedulerState()) { + case taskSCHEDULER_SUSPENDED: + lock = 1; + + if(xTaskResumeAll() != pdTRUE) { + if(xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED) { + lock = (int32_t)FuriStatusError; + } + } + break; + + case taskSCHEDULER_RUNNING: + lock = 0; + break; + + case taskSCHEDULER_NOT_STARTED: + default: + lock = (int32_t)FuriStatusError; + break; + } + + /* Return previous lock state */ + return (lock); +} + +int32_t furi_kernel_restore_lock(int32_t lock) { + furi_assert(!furi_is_irq_context()); + + switch(xTaskGetSchedulerState()) { + case taskSCHEDULER_SUSPENDED: + case taskSCHEDULER_RUNNING: + if(lock == 1) { + vTaskSuspendAll(); + } else { + if(lock != 0) { + lock = (int32_t)FuriStatusError; + } else { + if(xTaskResumeAll() != pdTRUE) { + if(xTaskGetSchedulerState() != taskSCHEDULER_RUNNING) { + lock = (int32_t)FuriStatusError; + } + } + } + } + break; + + case taskSCHEDULER_NOT_STARTED: + default: + lock = (int32_t)FuriStatusError; + break; + } + + /* Return new lock state */ + return (lock); +} + +uint32_t furi_kernel_get_tick_frequency() { + /* Return frequency in hertz */ + return (configTICK_RATE_HZ_RAW); +} + +void furi_delay_tick(uint32_t ticks) { + furi_assert(!furi_is_irq_context()); + if(ticks == 0U) { + taskYIELD(); + } else { + vTaskDelay(ticks); + } +} + +FuriStatus furi_delay_until_tick(uint32_t tick) { + furi_assert(!furi_is_irq_context()); + + TickType_t tcnt, delay; + FuriStatus stat; + + stat = FuriStatusOk; + tcnt = xTaskGetTickCount(); + + /* Determine remaining number of tick to delay */ + delay = (TickType_t)tick - tcnt; + + /* Check if target tick has not expired */ + if((delay != 0U) && (0 == (delay >> (8 * sizeof(TickType_t) - 1)))) { + if(xTaskDelayUntil(&tcnt, delay) == pdFALSE) { + /* Did not delay */ + stat = FuriStatusError; + } + } else { + /* No delay or already expired */ + stat = FuriStatusErrorParameter; + } + + /* Return execution status */ + return (stat); +} + +uint32_t furi_get_tick() { + TickType_t ticks; + + if(furi_is_irq_context() != 0U) { + ticks = xTaskGetTickCountFromISR(); + } else { + ticks = xTaskGetTickCount(); + } + + return ticks; +} + +uint32_t furi_ms_to_ticks(uint32_t milliseconds) { +#if configTICK_RATE_HZ_RAW == 1000 + return milliseconds; +#else + return (uint32_t)((float)configTICK_RATE_HZ_RAW) / 1000.0f * (float)milliseconds; +#endif +} + +void furi_delay_ms(uint32_t milliseconds) { + if(!FURI_IS_ISR() && xTaskGetSchedulerState() == taskSCHEDULER_RUNNING) { + if(milliseconds > 0 && milliseconds < portMAX_DELAY - 1) { + milliseconds += 1; + } +#if configTICK_RATE_HZ_RAW == 1000 + furi_delay_tick(milliseconds); +#else + furi_delay_tick(furi_ms_to_ticks(milliseconds)); +#endif + } else if(milliseconds > 0) { + furi_delay_us(milliseconds * 1000); + } +} + +void furi_delay_us(uint32_t microseconds) { + furi_hal_cortex_delay_us(microseconds); +} diff --git a/furi/core/kernel.h b/furi/core/kernel.h new file mode 100644 index 000000000..28afffd45 --- /dev/null +++ b/furi/core/kernel.h @@ -0,0 +1,93 @@ +/** + * @file kenrel.h + * Furi Kernel primitives + */ +#pragma once + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** Lock kernel, pause process scheduling + * + * @return previous lock state(0 - unlocked, 1 - locked) + */ +int32_t furi_kernel_lock(); + +/** Unlock kernel, resume process scheduling + * + * @return previous lock state(0 - unlocked, 1 - locked) + */ +int32_t furi_kernel_unlock(); + +/** Restore kernel lock state + * + * @param[in] lock The lock state + * + * @return new lock state or error + */ +int32_t furi_kernel_restore_lock(int32_t lock); + +/** Get kernel systick frequency + * + * @return systick counts per second + */ +uint32_t furi_kernel_get_tick_frequency(); + +/** Delay execution + * + * Also keep in mind delay is aliased to scheduler timer intervals. + * + * @param[in] ticks The ticks count to pause + */ +void furi_delay_tick(uint32_t ticks); + +/** Delay until tick + * + * @param[in] ticks The tick until which kerel should delay task execution + * + * @return The furi status. + */ +FuriStatus furi_delay_until_tick(uint32_t tick); + +/** Get current tick counter + * + * System uptime, may overflow. + * + * @return Current ticks in milliseconds + */ +uint32_t furi_get_tick(void); + +/** Convert milliseconds to ticks + * + * @param[in] milliseconds time in milliseconds + * @return time in ticks + */ +uint32_t furi_ms_to_ticks(uint32_t milliseconds); + +/** Delay in milliseconds + * + * This method uses kernel ticks on the inside, which causes delay to be aliased to scheduler timer intervals. + * Real wait time will be between X+ milliseconds. + * Special value: 0, will cause task yield. + * Also if used when kernel is not running will fall back to `furi_delay_us`. + * + * @warning Cannot be used from ISR + * + * @param[in] milliseconds milliseconds to wait + */ +void furi_delay_ms(uint32_t milliseconds); + +/** Delay in microseconds + * + * Implemented using Cortex DWT counter. Blocking and non aliased. + * + * @param[in] microseconds microseconds to wait + */ +void furi_delay_us(uint32_t microseconds); + +#ifdef __cplusplus +} +#endif diff --git a/core/furi/log.c b/furi/core/log.c similarity index 82% rename from core/furi/log.c rename to furi/core/log.c index 4653603ce..8cf904855 100644 --- a/core/furi/log.c +++ b/furi/core/log.c @@ -1,7 +1,6 @@ #include "log.h" #include "check.h" #include "mutex.h" -#include #include #define FURI_LOG_LEVEL_DEFAULT FuriLogLevelInfo @@ -10,7 +9,7 @@ typedef struct { FuriLogLevel log_level; FuriLogPuts puts; FuriLogTimestamp timetamp; - osMutexId_t mutex; + FuriMutex* mutex; } FuriLogParams; static FuriLogParams furi_log; @@ -19,12 +18,13 @@ void furi_log_init() { // Set default logging parameters furi_log.log_level = FURI_LOG_LEVEL_DEFAULT; furi_log.puts = furi_hal_console_puts; - furi_log.timetamp = furi_hal_get_tick; - furi_log.mutex = osMutexNew(NULL); + furi_log.timetamp = furi_get_tick; + furi_log.mutex = furi_mutex_alloc(FuriMutexTypeNormal); } void furi_log_print(FuriLogLevel level, const char* format, ...) { - if(level <= furi_log.log_level && osMutexAcquire(furi_log.mutex, osWaitForever) == osOK) { + if(level <= furi_log.log_level && + furi_mutex_acquire(furi_log.mutex, FuriWaitForever) == FuriStatusOk) { string_t string; // Timestamp @@ -40,7 +40,7 @@ void furi_log_print(FuriLogLevel level, const char* format, ...) { furi_log.puts(string_get_cstr(string)); string_clear(string); - osMutexRelease(furi_log.mutex); + furi_mutex_release(furi_log.mutex); } } diff --git a/core/furi/log.h b/furi/core/log.h similarity index 77% rename from core/furi/log.h rename to furi/core/log.h index 3c86698bc..6d23a9c29 100644 --- a/core/furi/log.h +++ b/furi/core/log.h @@ -1,3 +1,7 @@ +/** + * @file log.h + * Furi Logging system + */ #pragma once #include @@ -37,11 +41,39 @@ typedef enum { typedef void (*FuriLogPuts)(const char* data); typedef uint32_t (*FuriLogTimestamp)(void); +/** Initialize logging */ void furi_log_init(); + +/** Log record + * + * @param[in] level The level + * @param[in] format The format + * @param[in] VA args + */ void furi_log_print(FuriLogLevel level, const char* format, ...); + +/** Set log level + * + * @param[in] level The level + */ void furi_log_set_level(FuriLogLevel level); + +/** Get log level + * + * @return The furi log level. + */ FuriLogLevel furi_log_get_level(); + +/** Set log output callback + * + * @param[in] puts The puts callback + */ void furi_log_set_puts(FuriLogPuts puts); + +/** Set timestamp callback + * + * @param[in] timestamp The timestamp callback + */ void furi_log_set_timestamp(FuriLogTimestamp timestamp); #define FURI_LOG_FORMAT(log_letter, tag, format) \ @@ -49,6 +81,12 @@ void furi_log_set_timestamp(FuriLogTimestamp timestamp); #define FURI_LOG_SHOW(tag, format, log_level, log_letter, ...) \ furi_log_print(log_level, FURI_LOG_FORMAT(log_letter, tag, format), ##__VA_ARGS__) +/** Log methods + * + * @param tag The application tag + * @param format The format + * @param ... VA Args + */ #define FURI_LOG_E(tag, format, ...) \ FURI_LOG_SHOW(tag, format, FuriLogLevelError, E, ##__VA_ARGS__) #define FURI_LOG_W(tag, format, ...) FURI_LOG_SHOW(tag, format, FuriLogLevelWarn, W, ##__VA_ARGS__) diff --git a/core/furi/memmgr.c b/furi/core/memmgr.c similarity index 100% rename from core/furi/memmgr.c rename to furi/core/memmgr.c diff --git a/core/furi/memmgr.h b/furi/core/memmgr.h similarity index 100% rename from core/furi/memmgr.h rename to furi/core/memmgr.h diff --git a/core/furi/memmgr_heap.c b/furi/core/memmgr_heap.c similarity index 99% rename from core/furi/memmgr_heap.c rename to furi/core/memmgr_heap.c index 92e99b927..32b2875cc 100644 --- a/core/furi/memmgr_heap.c +++ b/furi/core/memmgr_heap.c @@ -38,10 +38,9 @@ #include "check.h" #include #include -#include #include #include -#include +#include /* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining all the API functions to use the MPU wrappers. That should only be done when @@ -222,7 +221,7 @@ static inline void traceFREE(void* pointer, size_t size) { size_t memmgr_heap_get_max_free_block() { size_t max_free_size = 0; BlockLink_t* pxBlock; - osKernelLock(); + vTaskSuspendAll(); pxBlock = xStart.pxNextFreeBlock; while(pxBlock->pxNextFreeBlock != NULL) { @@ -232,14 +231,14 @@ size_t memmgr_heap_get_max_free_block() { pxBlock = pxBlock->pxNextFreeBlock; } - osKernelUnlock(); + xTaskResumeAll(); return max_free_size; } void memmgr_heap_printf_free_blocks() { BlockLink_t* pxBlock; //TODO enable when we can do printf with a locked scheduler - //osKernelLock(); + //vTaskSuspendAll(); pxBlock = xStart.pxNextFreeBlock; while(pxBlock->pxNextFreeBlock != NULL) { @@ -247,7 +246,7 @@ void memmgr_heap_printf_free_blocks() { pxBlock = pxBlock->pxNextFreeBlock; } - //osKernelUnlock(); + //xTaskResumeAll(); } #ifdef HEAP_PRINT_DEBUG diff --git a/core/furi/memmgr_heap.h b/furi/core/memmgr_heap.h similarity index 97% rename from core/furi/memmgr_heap.h rename to furi/core/memmgr_heap.h index f76102ecb..1521fce42 100644 --- a/core/furi/memmgr_heap.h +++ b/furi/core/memmgr_heap.h @@ -6,7 +6,7 @@ #pragma once #include -#include "furi/thread.h" +#include #ifdef __cplusplus extern "C" { diff --git a/furi/core/message_queue.c b/furi/core/message_queue.c new file mode 100644 index 000000000..2658d6ff7 --- /dev/null +++ b/furi/core/message_queue.c @@ -0,0 +1,178 @@ +#include "message_queue.h" +#include "core/common_defines.h" +#include +#include +#include "check.h" + +FuriMessageQueue* furi_message_queue_alloc(uint32_t msg_count, uint32_t msg_size) { + furi_assert((furi_is_irq_context() == 0U) && (msg_count > 0U) && (msg_size > 0U)); + + return ((FuriMessageQueue*)xQueueCreate(msg_count, msg_size)); +} + +void furi_message_queue_free(FuriMessageQueue* instance) { + furi_assert(furi_is_irq_context() == 0U); + furi_assert(instance); + + vQueueDelete((QueueHandle_t)instance); +} + +FuriStatus + furi_message_queue_put(FuriMessageQueue* instance, const void* msg_ptr, uint32_t timeout) { + QueueHandle_t hQueue = (QueueHandle_t)instance; + FuriStatus stat; + BaseType_t yield; + + stat = FuriStatusOk; + + if(furi_is_irq_context() != 0U) { + if((hQueue == NULL) || (msg_ptr == NULL) || (timeout != 0U)) { + stat = FuriStatusErrorParameter; + } else { + yield = pdFALSE; + + if(xQueueSendToBackFromISR(hQueue, msg_ptr, &yield) != pdTRUE) { + stat = FuriStatusErrorResource; + } else { + portYIELD_FROM_ISR(yield); + } + } + } else { + if((hQueue == NULL) || (msg_ptr == NULL)) { + stat = FuriStatusErrorParameter; + } else { + if(xQueueSendToBack(hQueue, msg_ptr, (TickType_t)timeout) != pdPASS) { + if(timeout != 0U) { + stat = FuriStatusErrorTimeout; + } else { + stat = FuriStatusErrorResource; + } + } + } + } + + /* Return execution status */ + return (stat); +} + +FuriStatus furi_message_queue_get(FuriMessageQueue* instance, void* msg_ptr, uint32_t timeout) { + QueueHandle_t hQueue = (QueueHandle_t)instance; + FuriStatus stat; + BaseType_t yield; + + stat = FuriStatusOk; + + if(furi_is_irq_context() != 0U) { + if((hQueue == NULL) || (msg_ptr == NULL) || (timeout != 0U)) { + stat = FuriStatusErrorParameter; + } else { + yield = pdFALSE; + + if(xQueueReceiveFromISR(hQueue, msg_ptr, &yield) != pdPASS) { + stat = FuriStatusErrorResource; + } else { + portYIELD_FROM_ISR(yield); + } + } + } else { + if((hQueue == NULL) || (msg_ptr == NULL)) { + stat = FuriStatusErrorParameter; + } else { + if(xQueueReceive(hQueue, msg_ptr, (TickType_t)timeout) != pdPASS) { + if(timeout != 0U) { + stat = FuriStatusErrorTimeout; + } else { + stat = FuriStatusErrorResource; + } + } + } + } + + /* Return execution status */ + return (stat); +} + +uint32_t furi_message_queue_get_capacity(FuriMessageQueue* instance) { + StaticQueue_t* mq = (StaticQueue_t*)instance; + uint32_t capacity; + + if(mq == NULL) { + capacity = 0U; + } else { + /* capacity = pxQueue->uxLength */ + capacity = mq->uxDummy4[1]; + } + + /* Return maximum number of messages */ + return (capacity); +} + +uint32_t furi_message_queue_get_message_size(FuriMessageQueue* instance) { + StaticQueue_t* mq = (StaticQueue_t*)instance; + uint32_t size; + + if(mq == NULL) { + size = 0U; + } else { + /* size = pxQueue->uxItemSize */ + size = mq->uxDummy4[2]; + } + + /* Return maximum message size */ + return (size); +} + +uint32_t furi_message_queue_get_count(FuriMessageQueue* instance) { + QueueHandle_t hQueue = (QueueHandle_t)instance; + UBaseType_t count; + + if(hQueue == NULL) { + count = 0U; + } else if(furi_is_irq_context() != 0U) { + count = uxQueueMessagesWaitingFromISR(hQueue); + } else { + count = uxQueueMessagesWaiting(hQueue); + } + + /* Return number of queued messages */ + return ((uint32_t)count); +} + +uint32_t furi_message_queue_get_space(FuriMessageQueue* instance) { + StaticQueue_t* mq = (StaticQueue_t*)instance; + uint32_t space; + uint32_t isrm; + + if(mq == NULL) { + space = 0U; + } else if(furi_is_irq_context() != 0U) { + isrm = taskENTER_CRITICAL_FROM_ISR(); + + /* space = pxQueue->uxLength - pxQueue->uxMessagesWaiting; */ + space = mq->uxDummy4[1] - mq->uxDummy4[0]; + + taskEXIT_CRITICAL_FROM_ISR(isrm); + } else { + space = (uint32_t)uxQueueSpacesAvailable((QueueHandle_t)mq); + } + + /* Return number of available slots */ + return (space); +} + +FuriStatus furi_message_queue_reset(FuriMessageQueue* instance) { + QueueHandle_t hQueue = (QueueHandle_t)instance; + FuriStatus stat; + + if(furi_is_irq_context() != 0U) { + stat = FuriStatusErrorISR; + } else if(hQueue == NULL) { + stat = FuriStatusErrorParameter; + } else { + stat = FuriStatusOk; + (void)xQueueReset(hQueue); + } + + /* Return execution status */ + return (stat); +} diff --git a/furi/core/message_queue.h b/furi/core/message_queue.h new file mode 100644 index 000000000..392a145f1 --- /dev/null +++ b/furi/core/message_queue.h @@ -0,0 +1,95 @@ +/** + * @file message_queue.h + * FuriMessageQueue + */ +#pragma once + +#include "core/base.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef void FuriMessageQueue; + +/** Allocate furi message queue + * + * @param[in] msg_count The message count + * @param[in] msg_size The message size + * + * @return pointer to FuriMessageQueue instance + */ +FuriMessageQueue* furi_message_queue_alloc(uint32_t msg_count, uint32_t msg_size); + +/** Free queue + * + * @param instance pointer to FuriMessageQueue instance + */ +void furi_message_queue_free(FuriMessageQueue* instance); + +/** Put message into queue + * + * @param instance pointer to FuriMessageQueue instance + * @param[in] msg_ptr The message pointer + * @param[in] timeout The timeout + * @param[in] msg_prio The message prio + * + * @return The furi status. + */ +FuriStatus + furi_message_queue_put(FuriMessageQueue* instance, const void* msg_ptr, uint32_t timeout); + +/** Get message from queue + * + * @param instance pointer to FuriMessageQueue instance + * @param msg_ptr The message pointer + * @param msg_prio The message prioority + * @param[in] timeout The timeout + * + * @return The furi status. + */ +FuriStatus furi_message_queue_get(FuriMessageQueue* instance, void* msg_ptr, uint32_t timeout); + +/** Get queue capacity + * + * @param instance pointer to FuriMessageQueue instance + * + * @return capacity in object count + */ +uint32_t furi_message_queue_get_capacity(FuriMessageQueue* instance); + +/** Get message size + * + * @param instance pointer to FuriMessageQueue instance + * + * @return Message size in bytes + */ +uint32_t furi_message_queue_get_message_size(FuriMessageQueue* instance); + +/** Get message count in queue + * + * @param instance pointer to FuriMessageQueue instance + * + * @return Message count + */ +uint32_t furi_message_queue_get_count(FuriMessageQueue* instance); + +/** Get queue available space + * + * @param instance pointer to FuriMessageQueue instance + * + * @return Message count + */ +uint32_t furi_message_queue_get_space(FuriMessageQueue* instance); + +/** Reset queue + * + * @param instance pointer to FuriMessageQueue instance + * + * @return The furi status. + */ +FuriStatus furi_message_queue_reset(FuriMessageQueue* instance); + +#ifdef __cplusplus +} +#endif diff --git a/furi/core/mutex.c b/furi/core/mutex.c new file mode 100644 index 000000000..78ea05196 --- /dev/null +++ b/furi/core/mutex.c @@ -0,0 +1,122 @@ +#include "mutex.h" +#include "check.h" +#include "common_defines.h" + +#include + +FuriMutex* furi_mutex_alloc(FuriMutexType type) { + furi_assert(!FURI_IS_IRQ_MODE()); + + SemaphoreHandle_t hMutex = NULL; + + if(type == FuriMutexTypeNormal) { + hMutex = xSemaphoreCreateMutex(); + } else if(type == FuriMutexTypeRecursive) { + hMutex = xSemaphoreCreateRecursiveMutex(); + } else { + furi_crash("Programming error"); + } + + furi_check(hMutex != NULL); + + if(type == FuriMutexTypeRecursive) { + /* Set LSB as 'recursive mutex flag' */ + hMutex = (SemaphoreHandle_t)((uint32_t)hMutex | 1U); + } + + /* Return mutex ID */ + return ((FuriMutex*)hMutex); +} + +void furi_mutex_free(FuriMutex* instance) { + furi_assert(!FURI_IS_IRQ_MODE()); + vSemaphoreDelete((SemaphoreHandle_t)((uint32_t)instance & ~1U)); +} + +FuriStatus furi_mutex_acquire(FuriMutex* instance, uint32_t timeout) { + SemaphoreHandle_t hMutex; + FuriStatus stat; + uint32_t rmtx; + + hMutex = (SemaphoreHandle_t)((uint32_t)instance & ~1U); + + /* Extract recursive mutex flag */ + rmtx = (uint32_t)instance & 1U; + + stat = FuriStatusOk; + + if(FURI_IS_IRQ_MODE() != 0U) { + stat = FuriStatusErrorISR; + } else if(hMutex == NULL) { + stat = FuriStatusErrorParameter; + } else { + if(rmtx != 0U) { + if(xSemaphoreTakeRecursive(hMutex, timeout) != pdPASS) { + if(timeout != 0U) { + stat = FuriStatusErrorTimeout; + } else { + stat = FuriStatusErrorResource; + } + } + } else { + if(xSemaphoreTake(hMutex, timeout) != pdPASS) { + if(timeout != 0U) { + stat = FuriStatusErrorTimeout; + } else { + stat = FuriStatusErrorResource; + } + } + } + } + + /* Return execution status */ + return (stat); +} + +FuriStatus furi_mutex_release(FuriMutex* instance) { + SemaphoreHandle_t hMutex; + FuriStatus stat; + uint32_t rmtx; + + hMutex = (SemaphoreHandle_t)((uint32_t)instance & ~1U); + + /* Extract recursive mutex flag */ + rmtx = (uint32_t)instance & 1U; + + stat = FuriStatusOk; + + if(FURI_IS_IRQ_MODE() != 0U) { + stat = FuriStatusErrorISR; + } else if(hMutex == NULL) { + stat = FuriStatusErrorParameter; + } else { + if(rmtx != 0U) { + if(xSemaphoreGiveRecursive(hMutex) != pdPASS) { + stat = FuriStatusErrorResource; + } + } else { + if(xSemaphoreGive(hMutex) != pdPASS) { + stat = FuriStatusErrorResource; + } + } + } + + /* Return execution status */ + return (stat); +} + +FuriThreadId furi_mutex_get_owner(FuriMutex* instance) { + SemaphoreHandle_t hMutex; + FuriThreadId owner; + + hMutex = (SemaphoreHandle_t)((uint32_t)instance & ~1U); + + if((FURI_IS_IRQ_MODE() != 0U) || (hMutex == NULL)) { + owner = 0; + } else { + owner = (FuriThreadId)xSemaphoreGetMutexHolder(hMutex); + } + + /* Return owner thread ID */ + return (owner); +} diff --git a/furi/core/mutex.h b/furi/core/mutex.h new file mode 100644 index 000000000..aa55fa7bc --- /dev/null +++ b/furi/core/mutex.h @@ -0,0 +1,62 @@ +/** + * @file mutex.h + * FuriMutex + */ +#pragma once + +#include "base.h" +#include "thread.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + FuriMutexTypeNormal, + FuriMutexTypeRecursive, +} FuriMutexType; + +typedef void FuriMutex; + +/** Allocate FuriMutex + * + * @param[in] type The mutex type + * + * @return pointer to FuriMutex instance + */ +FuriMutex* furi_mutex_alloc(FuriMutexType type); + +/** Free FuriMutex + * + * @param instance The pointer to FuriMutex instance + */ +void furi_mutex_free(FuriMutex* instance); + +/** Acquire mutex + * + * @param instance The pointer to FuriMutex instance + * @param[in] timeout The timeout + * + * @return The furi status. + */ +FuriStatus furi_mutex_acquire(FuriMutex* instance, uint32_t timeout); + +/** Release mutex + * + * @param instance The pointer to FuriMutex instance + * + * @return The furi status. + */ +FuriStatus furi_mutex_release(FuriMutex* instance); + +/** Get mutex owner thread id + * + * @param instance The pointer to FuriMutex instance + * + * @return The furi thread identifier. + */ +FuriThreadId furi_mutex_get_owner(FuriMutex* instance); + +#ifdef __cplusplus +} +#endif diff --git a/core/furi/pubsub.c b/furi/core/pubsub.c similarity index 80% rename from core/furi/pubsub.c rename to furi/core/pubsub.c index 88839ec27..44ef20c71 100644 --- a/core/furi/pubsub.c +++ b/furi/core/pubsub.c @@ -14,13 +14,13 @@ LIST_DEF(FuriPubSubSubscriptionList, FuriPubSubSubscription, M_POD_OPLIST); struct FuriPubSub { FuriPubSubSubscriptionList_t items; - osMutexId_t mutex; + FuriMutex* mutex; }; FuriPubSub* furi_pubsub_alloc() { FuriPubSub* pubsub = malloc(sizeof(FuriPubSub)); - pubsub->mutex = osMutexNew(NULL); + pubsub->mutex = furi_mutex_alloc(FuriMutexTypeNormal); furi_assert(pubsub->mutex); FuriPubSubSubscriptionList_init(pubsub->items); @@ -35,14 +35,14 @@ void furi_pubsub_free(FuriPubSub* pubsub) { FuriPubSubSubscriptionList_clear(pubsub->items); - furi_check(osMutexDelete(pubsub->mutex) == osOK); + furi_mutex_free(pubsub->mutex); free(pubsub); } FuriPubSubSubscription* furi_pubsub_subscribe(FuriPubSub* pubsub, FuriPubSubCallback callback, void* callback_context) { - furi_check(osMutexAcquire(pubsub->mutex, osWaitForever) == osOK); + furi_check(furi_mutex_acquire(pubsub->mutex, FuriWaitForever) == FuriStatusOk); // put uninitialized item to the list FuriPubSubSubscription* item = FuriPubSubSubscriptionList_push_raw(pubsub->items); @@ -50,7 +50,7 @@ FuriPubSubSubscription* item->callback = callback; item->callback_context = callback_context; - furi_check(osMutexRelease(pubsub->mutex) == osOK); + furi_check(furi_mutex_release(pubsub->mutex) == FuriStatusOk); return item; } @@ -59,7 +59,7 @@ void furi_pubsub_unsubscribe(FuriPubSub* pubsub, FuriPubSubSubscription* pubsub_ furi_assert(pubsub); furi_assert(pubsub_subscription); - furi_check(osMutexAcquire(pubsub->mutex, osWaitForever) == osOK); + furi_check(furi_mutex_acquire(pubsub->mutex, FuriWaitForever) == FuriStatusOk); bool result = false; // iterate over items @@ -76,12 +76,12 @@ void furi_pubsub_unsubscribe(FuriPubSub* pubsub, FuriPubSubSubscription* pubsub_ } } - furi_check(osMutexRelease(pubsub->mutex) == osOK); + furi_check(furi_mutex_release(pubsub->mutex) == FuriStatusOk); furi_check(result); } void furi_pubsub_publish(FuriPubSub* pubsub, void* message) { - furi_check(osMutexAcquire(pubsub->mutex, osWaitForever) == osOK); + furi_check(furi_mutex_acquire(pubsub->mutex, FuriWaitForever) == FuriStatusOk); // iterate over subscribers FuriPubSubSubscriptionList_it_t it; @@ -91,5 +91,5 @@ void furi_pubsub_publish(FuriPubSub* pubsub, void* message) { item->callback(message, item->callback_context); } - furi_check(osMutexRelease(pubsub->mutex) == osOK); + furi_check(furi_mutex_release(pubsub->mutex) == FuriStatusOk); } diff --git a/core/furi/pubsub.h b/furi/core/pubsub.h similarity index 97% rename from core/furi/pubsub.h rename to furi/core/pubsub.h index 446d423f1..69ca574ac 100644 --- a/core/furi/pubsub.h +++ b/furi/core/pubsub.h @@ -1,3 +1,7 @@ +/** + * @file pubsub.h + * FuriPubSub + */ #pragma once #ifdef __cplusplus diff --git a/core/furi/record.c b/furi/core/record.c similarity index 84% rename from core/furi/record.c rename to furi/core/record.c index d7afbf9c6..666d50761 100644 --- a/core/furi/record.c +++ b/furi/core/record.c @@ -2,7 +2,7 @@ #include "check.h" #include "memmgr.h" #include "mutex.h" -#include "event_flags.h" +#include "event_flag.h" #include #include @@ -10,7 +10,7 @@ #define FURI_RECORD_FLAG_READY (0x1) typedef struct { - osEventFlagsId_t flags; + FuriEventFlag* flags; void* data; size_t holders_count; } FuriRecordData; @@ -18,7 +18,7 @@ typedef struct { DICT_DEF2(FuriRecordDataDict, string_t, STRING_OPLIST, FuriRecordData, M_POD_OPLIST) typedef struct { - osMutexId_t mutex; + FuriMutex* mutex; FuriRecordDataDict_t records; } FuriRecord; @@ -26,7 +26,7 @@ static FuriRecord* furi_record = NULL; void furi_record_init() { furi_record = malloc(sizeof(FuriRecord)); - furi_record->mutex = osMutexNew(NULL); + furi_record->mutex = furi_mutex_alloc(FuriMutexTypeNormal); furi_check(furi_record->mutex); FuriRecordDataDict_init(furi_record->records); } @@ -36,7 +36,7 @@ static FuriRecordData* furi_record_data_get_or_create(string_t name_str) { FuriRecordData* record_data = FuriRecordDataDict_get(furi_record->records, name_str); if(!record_data) { FuriRecordData new_record; - new_record.flags = osEventFlagsNew(NULL); + new_record.flags = furi_event_flag_alloc(); new_record.data = NULL; new_record.holders_count = 0; FuriRecordDataDict_set_at(furi_record->records, name_str, new_record); @@ -46,11 +46,11 @@ static FuriRecordData* furi_record_data_get_or_create(string_t name_str) { } static void furi_record_lock() { - furi_check(osMutexAcquire(furi_record->mutex, osWaitForever) == osOK); + furi_check(furi_mutex_acquire(furi_record->mutex, FuriWaitForever) == FuriStatusOk); } static void furi_record_unlock() { - furi_check(osMutexRelease(furi_record->mutex) == osOK); + furi_check(furi_mutex_release(furi_record->mutex) == FuriStatusOk); } bool furi_record_exists(const char* name) { @@ -83,7 +83,7 @@ void furi_record_create(const char* name, void* data) { FuriRecordData* record_data = furi_record_data_get_or_create(name_str); furi_assert(record_data->data == NULL); record_data->data = data; - osEventFlagsSet(record_data->flags, FURI_RECORD_FLAG_READY); + furi_event_flag_set(record_data->flags, FURI_RECORD_FLAG_READY); furi_record_unlock(); @@ -103,7 +103,7 @@ bool furi_record_destroy(const char* name) { FuriRecordData* record_data = FuriRecordDataDict_get(furi_record->records, name_str); furi_assert(record_data); if(record_data->holders_count == 0) { - furi_check(osOK == osEventFlagsDelete(record_data->flags)); + furi_event_flag_free(record_data->flags); FuriRecordDataDict_erase(furi_record->records, name_str); ret = true; } @@ -130,11 +130,11 @@ void* furi_record_open(const char* name) { // Wait for record to become ready furi_check( - osEventFlagsWait( + furi_event_flag_wait( record_data->flags, FURI_RECORD_FLAG_READY, - osFlagsWaitAny | osFlagsNoClear, - osWaitForever) == FURI_RECORD_FLAG_READY); + FuriFlagWaitAny | FuriFlagNoClear, + FuriWaitForever) == FURI_RECORD_FLAG_READY); string_clear(name_str); diff --git a/core/furi/record.h b/furi/core/record.h similarity index 100% rename from core/furi/record.h rename to furi/core/record.h diff --git a/furi/core/semaphore.c b/furi/core/semaphore.c new file mode 100644 index 000000000..a204cbe6e --- /dev/null +++ b/furi/core/semaphore.c @@ -0,0 +1,115 @@ +#include "semaphore.h" +#include "check.h" +#include "common_defines.h" + +#include + +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)); + + SemaphoreHandle_t hSemaphore = NULL; + if(max_count == 1U) { + hSemaphore = xSemaphoreCreateBinary(); + if((hSemaphore != NULL) && (initial_count != 0U)) { + if(xSemaphoreGive(hSemaphore) != pdPASS) { + vSemaphoreDelete(hSemaphore); + hSemaphore = NULL; + } + } + } else { + hSemaphore = xSemaphoreCreateCounting(max_count, initial_count); + } + + furi_check(hSemaphore); + + /* Return semaphore ID */ + return ((FuriSemaphore*)hSemaphore); +} + +void furi_semaphore_free(FuriSemaphore* instance) { + furi_assert(instance); + furi_assert(!FURI_IS_IRQ_MODE()); + + SemaphoreHandle_t hSemaphore = (SemaphoreHandle_t)instance; + + vSemaphoreDelete(hSemaphore); +} + +FuriStatus furi_semaphore_acquire(FuriSemaphore* instance, uint32_t timeout) { + furi_assert(instance); + + SemaphoreHandle_t hSemaphore = (SemaphoreHandle_t)instance; + FuriStatus stat; + BaseType_t yield; + + stat = FuriStatusOk; + + if(FURI_IS_IRQ_MODE() != 0U) { + if(timeout != 0U) { + stat = FuriStatusErrorParameter; + } else { + yield = pdFALSE; + + if(xSemaphoreTakeFromISR(hSemaphore, &yield) != pdPASS) { + stat = FuriStatusErrorResource; + } else { + portYIELD_FROM_ISR(yield); + } + } + } else { + if(xSemaphoreTake(hSemaphore, (TickType_t)timeout) != pdPASS) { + if(timeout != 0U) { + stat = FuriStatusErrorTimeout; + } else { + stat = FuriStatusErrorResource; + } + } + } + + /* Return execution status */ + return (stat); +} + +FuriStatus furi_semaphore_release(FuriSemaphore* instance) { + furi_assert(instance); + + SemaphoreHandle_t hSemaphore = (SemaphoreHandle_t)instance; + FuriStatus stat; + BaseType_t yield; + + stat = FuriStatusOk; + + if(FURI_IS_IRQ_MODE() != 0U) { + yield = pdFALSE; + + if(xSemaphoreGiveFromISR(hSemaphore, &yield) != pdTRUE) { + stat = FuriStatusErrorResource; + } else { + portYIELD_FROM_ISR(yield); + } + } else { + if(xSemaphoreGive(hSemaphore) != pdPASS) { + stat = FuriStatusErrorResource; + } + } + + /* Return execution status */ + return (stat); +} + +uint32_t furi_semaphore_get_count(FuriSemaphore* instance) { + furi_assert(instance); + + SemaphoreHandle_t hSemaphore = (SemaphoreHandle_t)instance; + uint32_t count; + + if(FURI_IS_IRQ_MODE() != 0U) { + count = (uint32_t)uxSemaphoreGetCountFromISR(hSemaphore); + } else { + count = (uint32_t)uxSemaphoreGetCount(hSemaphore); + } + + /* Return number of tokens */ + return (count); +} diff --git a/furi/core/semaphore.h b/furi/core/semaphore.h new file mode 100644 index 000000000..19d056bfe --- /dev/null +++ b/furi/core/semaphore.h @@ -0,0 +1,58 @@ +/** + * @file semaphore.h + * FuriSemaphore + */ +#pragma once + +#include "base.h" +#include "thread.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef void FuriSemaphore; + +/** Allocate semaphore + * + * @param[in] max_count The maximum count + * @param[in] initial_count The initial count + * + * @return pointer to FuriSemaphore instance + */ +FuriSemaphore* furi_semaphore_alloc(uint32_t max_count, uint32_t initial_count); + +/** Free semaphore + * + * @param instance The pointer to FuriSemaphore instance + */ +void furi_semaphore_free(FuriSemaphore* instance); + +/** Acquire semaphore + * + * @param instance The pointer to FuriSemaphore instance + * @param[in] timeout The timeout + * + * @return The furi status. + */ +FuriStatus furi_semaphore_acquire(FuriSemaphore* instance, uint32_t timeout); + +/** Release semaphore + * + * @param instance The pointer to FuriSemaphore instance + * + * @return The furi status. + */ +FuriStatus furi_semaphore_release(FuriSemaphore* instance); + +/** Get semaphore count + * + * @param instance The pointer to FuriSemaphore instance + * + * @return Semaphore count + */ +uint32_t furi_semaphore_get_count(FuriSemaphore* instance); + +#ifdef __cplusplus +} +#endif diff --git a/core/furi/stdglue.c b/furi/core/stdglue.c similarity index 83% rename from core/furi/stdglue.c rename to furi/core/stdglue.c index 8c1d0813c..573277aa5 100644 --- a/core/furi/stdglue.c +++ b/furi/core/stdglue.c @@ -16,7 +16,7 @@ DICT_DEF2( M_PTR_OPLIST) typedef struct { - osMutexId_t mutex; + FuriMutex* mutex; FuriStdglueCallbackDict_t thread_outputs; } FuriStdglue; @@ -25,10 +25,9 @@ static FuriStdglue* furi_stdglue = NULL; static ssize_t stdout_write(void* _cookie, const char* data, size_t size) { furi_assert(furi_stdglue); bool consumed = false; - osKernelState_t state = osKernelGetState(); FuriThreadId task_id = furi_thread_get_current_id(); - if(state == osKernelRunning && task_id && - osMutexAcquire(furi_stdglue->mutex, osWaitForever) == osOK) { + if(xTaskGetSchedulerState() == taskSCHEDULER_RUNNING && task_id && + furi_mutex_acquire(furi_stdglue->mutex, FuriWaitForever) == FuriStatusOk) { // We are in the thread context // Handle thread callbacks FuriStdglueWriteCallback* callback_ptr = @@ -37,7 +36,7 @@ static ssize_t stdout_write(void* _cookie, const char* data, size_t size) { (*callback_ptr)(_cookie, data, size); consumed = true; } - furi_check(osMutexRelease(furi_stdglue->mutex) == osOK); + furi_check(furi_mutex_release(furi_stdglue->mutex) == FuriStatusOk); } // Flush if(data == 0) { @@ -57,7 +56,7 @@ static ssize_t stdout_write(void* _cookie, const char* data, size_t size) { void furi_stdglue_init() { furi_stdglue = malloc(sizeof(FuriStdglue)); // Init outputs structures - furi_stdglue->mutex = osMutexNew(NULL); + furi_stdglue->mutex = furi_mutex_alloc(FuriMutexTypeNormal); furi_check(furi_stdglue->mutex); FuriStdglueCallbackDict_init(furi_stdglue->thread_outputs); // Prepare and set stdout descriptor @@ -78,14 +77,14 @@ bool furi_stdglue_set_thread_stdout_callback(FuriStdglueWriteCallback callback) furi_assert(furi_stdglue); FuriThreadId task_id = furi_thread_get_current_id(); if(task_id) { - furi_check(osMutexAcquire(furi_stdglue->mutex, osWaitForever) == osOK); + furi_check(furi_mutex_acquire(furi_stdglue->mutex, FuriWaitForever) == FuriStatusOk); if(callback) { FuriStdglueCallbackDict_set_at( furi_stdglue->thread_outputs, (uint32_t)task_id, callback); } else { FuriStdglueCallbackDict_erase(furi_stdglue->thread_outputs, (uint32_t)task_id); } - furi_check(osMutexRelease(furi_stdglue->mutex) == osOK); + furi_check(furi_mutex_release(furi_stdglue->mutex) == FuriStatusOk); return true; } else { return false; diff --git a/core/furi/stdglue.h b/furi/core/stdglue.h similarity index 100% rename from core/furi/stdglue.h rename to furi/core/stdglue.h diff --git a/core/furi/thread.c b/furi/core/thread.c similarity index 91% rename from core/furi/thread.c rename to furi/core/thread.c index 266a3855f..097cedef2 100644 --- a/core/furi/thread.c +++ b/furi/core/thread.c @@ -1,4 +1,5 @@ #include "thread.h" +#include "kernel.h" #include "memmgr.h" #include "memmgr_heap.h" #include "check.h" @@ -57,7 +58,7 @@ static void furi_thread_body(void* context) { thread->ret = thread->callback(thread->context); if(thread->heap_trace_enabled == true) { - osDelay(33); + furi_delay_ms(33); thread->heap_size = memmgr_heap_get_thread_memory((FuriThreadId)task_handle); memmgr_heap_disable_thread_trace((FuriThreadId)task_handle); } @@ -157,10 +158,10 @@ bool furi_thread_join(FuriThread* thread) { furi_assert(thread); while(thread->state != FuriThreadStateStopped) { - osDelay(10); + furi_delay_ms(10); } - return osOK; + return FuriStatusOk; } FuriThreadId furi_thread_get_id(FuriThread* thread) { @@ -216,9 +217,9 @@ uint32_t furi_thread_flags_set(FuriThreadId thread_id, uint32_t flags) { BaseType_t yield; if((hTask == NULL) || ((flags & THREAD_FLAGS_INVALID_BITS) != 0U)) { - rflags = (uint32_t)osErrorParameter; + rflags = (uint32_t)FuriStatusErrorParameter; } else { - rflags = (uint32_t)osError; + rflags = (uint32_t)FuriStatusError; if(FURI_IS_IRQ_MODE()) { yield = pdFALSE; @@ -242,9 +243,9 @@ uint32_t furi_thread_flags_clear(uint32_t flags) { uint32_t rflags, cflags; if(FURI_IS_IRQ_MODE()) { - rflags = (uint32_t)osErrorISR; + rflags = (uint32_t)FuriStatusErrorISR; } else if((flags & THREAD_FLAGS_INVALID_BITS) != 0U) { - rflags = (uint32_t)osErrorParameter; + rflags = (uint32_t)FuriStatusErrorParameter; } else { hTask = xTaskGetCurrentTaskHandle(); @@ -255,10 +256,10 @@ uint32_t furi_thread_flags_clear(uint32_t flags) { if(xTaskNotifyIndexed(hTask, THREAD_NOTIFY_INDEX, cflags, eSetValueWithOverwrite) != pdPASS) { - rflags = (uint32_t)osError; + rflags = (uint32_t)FuriStatusError; } } else { - rflags = (uint32_t)osError; + rflags = (uint32_t)FuriStatusError; } } @@ -271,13 +272,13 @@ uint32_t furi_thread_flags_get(void) { uint32_t rflags; if(FURI_IS_IRQ_MODE()) { - rflags = (uint32_t)osErrorISR; + rflags = (uint32_t)FuriStatusErrorISR; } else { hTask = xTaskGetCurrentTaskHandle(); if(xTaskNotifyAndQueryIndexed(hTask, THREAD_NOTIFY_INDEX, 0, eNoAction, &rflags) != pdPASS) { - rflags = (uint32_t)osError; + rflags = (uint32_t)FuriStatusError; } } @@ -291,11 +292,11 @@ uint32_t furi_thread_flags_wait(uint32_t flags, uint32_t options, uint32_t timeo BaseType_t rval; if(FURI_IS_IRQ_MODE()) { - rflags = (uint32_t)osErrorISR; + rflags = (uint32_t)FuriStatusErrorISR; } else if((flags & THREAD_FLAGS_INVALID_BITS) != 0U) { - rflags = (uint32_t)osErrorParameter; + rflags = (uint32_t)FuriStatusErrorParameter; } else { - if((options & osFlagsNoClear) == osFlagsNoClear) { + if((options & FuriFlagNoClear) == FuriFlagNoClear) { clear = 0U; } else { clear = flags; @@ -312,12 +313,12 @@ uint32_t furi_thread_flags_wait(uint32_t flags, uint32_t options, uint32_t timeo rflags &= flags; rflags |= nval; - if((options & osFlagsWaitAll) == osFlagsWaitAll) { + if((options & FuriFlagWaitAll) == FuriFlagWaitAll) { if((flags & rflags) == flags) { break; } else { if(timeout == 0U) { - rflags = (uint32_t)osErrorResource; + rflags = (uint32_t)FuriStatusErrorResource; break; } } @@ -326,7 +327,7 @@ uint32_t furi_thread_flags_wait(uint32_t flags, uint32_t options, uint32_t timeo break; } else { if(timeout == 0U) { - rflags = (uint32_t)osErrorResource; + rflags = (uint32_t)FuriStatusErrorResource; break; } } @@ -342,9 +343,9 @@ uint32_t furi_thread_flags_wait(uint32_t flags, uint32_t options, uint32_t timeo } } else { if(timeout == 0) { - rflags = (uint32_t)osErrorResource; + rflags = (uint32_t)FuriStatusErrorResource; } else { - rflags = (uint32_t)osErrorTimeout; + rflags = (uint32_t)FuriStatusErrorTimeout; } } } while(rval != pdFAIL); diff --git a/core/furi/thread.h b/furi/core/thread.h similarity index 99% rename from core/furi/thread.h rename to furi/core/thread.h index 11dd997cb..34eb39f03 100644 --- a/core/furi/thread.h +++ b/furi/core/thread.h @@ -6,6 +6,7 @@ #pragma once #include "base.h" +#include "common_defines.h" #ifdef __cplusplus extern "C" { diff --git a/furi/core/timer.c b/furi/core/timer.c new file mode 100644 index 000000000..807f477e4 --- /dev/null +++ b/furi/core/timer.c @@ -0,0 +1,142 @@ +#include "timer.h" +#include "check.h" + +#include "core/common_defines.h" +#include +#include + +typedef struct { + FuriTimerCallback func; + void* context; +} TimerCallback_t; + +static void TimerCallback(TimerHandle_t hTimer) { + TimerCallback_t* callb; + + /* Retrieve pointer to callback function and context */ + callb = (TimerCallback_t*)pvTimerGetTimerID(hTimer); + + /* Remove dynamic allocation flag */ + callb = (TimerCallback_t*)((uint32_t)callb & ~1U); + + if(callb != NULL) { + callb->func(callb->context); + } +} + +FuriTimer* furi_timer_alloc(FuriTimerCallback func, FuriTimerType type, void* context) { + furi_assert((furi_is_irq_context() == 0U) && (func != NULL)); + + TimerHandle_t hTimer; + TimerCallback_t* callb; + UBaseType_t reload; + uint32_t callb_dyn; + + hTimer = NULL; + callb = NULL; + callb_dyn = 0U; + + /* Dynamic memory allocation is available: if memory for callback and */ + /* its context is not provided, allocate it from dynamic memory pool */ + if(callb == NULL) { + callb = (TimerCallback_t*)pvPortMalloc(sizeof(TimerCallback_t)); + + if(callb != NULL) { + /* Callback memory was allocated from dynamic pool, set flag */ + callb_dyn = 1U; + } + } + + if(callb != NULL) { + callb->func = func; + callb->context = context; + + if(type == FuriTimerTypeOnce) { + reload = pdFALSE; + } else { + reload = pdTRUE; + } + + /* Store callback memory dynamic allocation flag */ + callb = (TimerCallback_t*)((uint32_t)callb | callb_dyn); + // TimerCallback function is always provided as a callback and is used to call application + // specified function with its context both stored in structure callb. + hTimer = xTimerCreate(NULL, 1, reload, callb, TimerCallback); + if((hTimer == NULL) && (callb != NULL) && (callb_dyn == 1U)) { + /* Failed to create a timer, release allocated resources */ + callb = (TimerCallback_t*)((uint32_t)callb & ~1U); + vPortFree(callb); + } + } + + /* Return timer ID */ + return ((FuriTimer*)hTimer); +} + +void furi_timer_free(FuriTimer* instance) { + furi_assert(!furi_is_irq_context()); + furi_assert(instance); + + TimerHandle_t hTimer = (TimerHandle_t)instance; + TimerCallback_t* callb; + + callb = (TimerCallback_t*)pvTimerGetTimerID(hTimer); + + if(xTimerDelete(hTimer, portMAX_DELAY) == pdPASS) { + if((uint32_t)callb & 1U) { + /* Callback memory was allocated from dynamic pool, clear flag */ + callb = (TimerCallback_t*)((uint32_t)callb & ~1U); + + /* Return allocated memory to dynamic pool */ + vPortFree(callb); + } + } +} + +FuriStatus furi_timer_start(FuriTimer* instance, uint32_t ticks) { + furi_assert(!furi_is_irq_context()); + furi_assert(instance); + + TimerHandle_t hTimer = (TimerHandle_t)instance; + FuriStatus stat; + + if(xTimerChangePeriod(hTimer, ticks, portMAX_DELAY) == pdPASS) { + stat = FuriStatusOk; + } else { + stat = FuriStatusErrorResource; + } + + /* Return execution status */ + return (stat); +} + +FuriStatus furi_timer_stop(FuriTimer* instance) { + furi_assert(!furi_is_irq_context()); + furi_assert(instance); + + TimerHandle_t hTimer = (TimerHandle_t)instance; + FuriStatus stat; + + if(xTimerIsTimerActive(hTimer) == pdFALSE) { + stat = FuriStatusErrorResource; + } else { + if(xTimerStop(hTimer, portMAX_DELAY) == pdPASS) { + stat = FuriStatusOk; + } else { + stat = FuriStatusError; + } + } + + /* Return execution status */ + return (stat); +} + +uint32_t furi_timer_is_running(FuriTimer* instance) { + furi_assert(!furi_is_irq_context()); + furi_assert(instance); + + TimerHandle_t hTimer = (TimerHandle_t)instance; + + /* Return 0: not running, 1: running */ + return (uint32_t)xTimerIsTimerActive(hTimer); +} diff --git a/furi/core/timer.h b/furi/core/timer.h new file mode 100644 index 000000000..e79c1868d --- /dev/null +++ b/furi/core/timer.h @@ -0,0 +1,61 @@ +#pragma once + +#include "core/base.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef void (*FuriTimerCallback)(void* context); + +typedef enum { + FuriTimerTypeOnce = 0, ///< One-shot timer. + FuriTimerTypePeriodic = 1 ///< Repeating timer. +} FuriTimerType; + +typedef void FuriTimer; + +/** Allocate timer + * + * @param[in] func The callback function + * @param[in] type The timer type + * @param context The callback context + * + * @return The pointer to FuriTimer instance + */ +FuriTimer* furi_timer_alloc(FuriTimerCallback func, FuriTimerType type, void* context); + +/** Free timer + * + * @param instance The pointer to FuriTimer instance + */ +void furi_timer_free(FuriTimer* instance); + +/** Start timer + * + * @param instance The pointer to FuriTimer instance + * @param[in] ticks The ticks + * + * @return The furi status. + */ +FuriStatus furi_timer_start(FuriTimer* instance, uint32_t ticks); + +/** Stop timer + * + * @param instance The pointer to FuriTimer instance + * + * @return The furi status. + */ +FuriStatus furi_timer_stop(FuriTimer* instance); + +/** Is timer running + * + * @param instance The pointer to FuriTimer instance + * + * @return 0: not running, 1: running + */ +uint32_t furi_timer_is_running(FuriTimer* instance); + +#ifdef __cplusplus +} +#endif diff --git a/core/furi/valuemutex.c b/furi/core/valuemutex.c similarity index 79% rename from core/furi/valuemutex.c rename to furi/core/valuemutex.c index 6010c963e..af2a0755c 100644 --- a/core/furi/valuemutex.c +++ b/furi/core/valuemutex.c @@ -6,7 +6,7 @@ bool init_mutex(ValueMutex* valuemutex, void* value, size_t size) { // mutex without name, // no attributes (unfortunatly robust mutex is not supported by FreeRTOS), // with dynamic memory allocation - valuemutex->mutex = osMutexNew(NULL); + valuemutex->mutex = furi_mutex_alloc(FuriMutexTypeNormal); if(valuemutex->mutex == NULL) return false; valuemutex->value = value; @@ -16,15 +16,16 @@ bool init_mutex(ValueMutex* valuemutex, void* value, size_t size) { } bool delete_mutex(ValueMutex* valuemutex) { - if(osMutexAcquire(valuemutex->mutex, osWaitForever) == osOK) { - return osMutexDelete(valuemutex->mutex) == osOK; + if(furi_mutex_acquire(valuemutex->mutex, FuriWaitForever) == FuriStatusOk) { + furi_mutex_free(valuemutex->mutex); + return true; } else { return false; } } void* acquire_mutex(ValueMutex* valuemutex, uint32_t timeout) { - if(osMutexAcquire(valuemutex->mutex, timeout) == osOK) { + if(furi_mutex_acquire(valuemutex->mutex, timeout) == FuriStatusOk) { return valuemutex->value; } else { return NULL; @@ -34,7 +35,7 @@ void* acquire_mutex(ValueMutex* valuemutex, uint32_t timeout) { bool release_mutex(ValueMutex* valuemutex, const void* value) { if(value != valuemutex->value) return false; - if(osMutexRelease(valuemutex->mutex) != osOK) return false; + if(furi_mutex_release(valuemutex->mutex) != FuriStatusOk) return false; return true; } diff --git a/core/furi/valuemutex.h b/furi/core/valuemutex.h similarity index 93% rename from core/furi/valuemutex.h rename to furi/core/valuemutex.h index bd1493160..41762fdd3 100644 --- a/core/furi/valuemutex.h +++ b/furi/core/valuemutex.h @@ -1,6 +1,5 @@ #pragma once -#include #include #include "mutex.h" @@ -19,7 +18,7 @@ extern "C" { typedef struct { void* value; size_t size; - osMutexId_t mutex; + FuriMutex* mutex; } ValueMutex; /** @@ -43,7 +42,7 @@ void* acquire_mutex(ValueMutex* valuemutex, uint32_t timeout); * Helper: infinitly wait for mutex */ static inline void* acquire_mutex_block(ValueMutex* valuemutex) { - return acquire_mutex(valuemutex, osWaitForever); + return acquire_mutex(valuemutex, FuriWaitForever); } /** @@ -75,11 +74,11 @@ bool read_mutex(ValueMutex* valuemutex, void* data, size_t len, uint32_t timeout bool write_mutex(ValueMutex* valuemutex, void* data, size_t len, uint32_t timeout); inline static bool write_mutex_block(ValueMutex* valuemutex, void* data, size_t len) { - return write_mutex(valuemutex, data, len, osWaitForever); + return write_mutex(valuemutex, data, len, FuriWaitForever); } inline static bool read_mutex_block(ValueMutex* valuemutex, void* data, size_t len) { - return read_mutex(valuemutex, data, len, osWaitForever); + return read_mutex(valuemutex, data, len, FuriWaitForever); } #ifdef __cplusplus @@ -118,7 +117,7 @@ void provider_app(void* _p) { } release_mutex(&example_mutex, value); - osDelay(100); + furi_delay_ms(100); } } @@ -143,7 +142,7 @@ void consumer_app(void* _p) { printf("counter value: %d\n", counter); } - osDelay(1000); + furi_delay_ms(1000); } } ``` diff --git a/core/flipper.c b/furi/flipper.c similarity index 100% rename from core/flipper.c rename to furi/flipper.c diff --git a/core/flipper.h b/furi/flipper.h similarity index 100% rename from core/flipper.h rename to furi/flipper.h diff --git a/furi/furi.c b/furi/furi.c new file mode 100644 index 000000000..e6848624b --- /dev/null +++ b/furi/furi.c @@ -0,0 +1,27 @@ +#include "furi.h" +#include +#include "queue.h" + +void furi_init() { + furi_assert(!furi_is_irq_context()); + furi_assert(xTaskGetSchedulerState() == taskSCHEDULER_NOT_STARTED); + + furi_log_init(); + furi_record_init(); + furi_stdglue_init(); +} + +void furi_run() { + furi_assert(!furi_is_irq_context()); + furi_assert(xTaskGetSchedulerState() == taskSCHEDULER_NOT_STARTED); + +#if(__ARM_ARCH_7A__ == 0U) + /* Service Call interrupt might be configured before kernel start */ + /* and when its priority is lower or equal to BASEPRI, svc intruction */ + /* causes a Hard Fault. */ + NVIC_SetPriority(SVCall_IRQn, 0U); +#endif + + /* Start the kernel scheduler */ + vTaskStartScheduler(); +} diff --git a/furi/furi.h b/furi/furi.h new file mode 100644 index 000000000..d78129a82 --- /dev/null +++ b/furi/furi.h @@ -0,0 +1,37 @@ +#pragma once + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +// FreeRTOS timer, REMOVE AFTER REFACTORING +#include + +#ifdef __cplusplus +extern "C" { +#endif + +void furi_init(); + +void furi_run(); + +#ifdef __cplusplus +} +#endif diff --git a/lib/FreeRTOS-glue/cmsis_os2.c b/lib/FreeRTOS-glue/cmsis_os2.c deleted file mode 100644 index bee37572d..000000000 --- a/lib/FreeRTOS-glue/cmsis_os2.c +++ /dev/null @@ -1,1120 +0,0 @@ -/* -------------------------------------------------------------------------- - * Copyright (c) 2013-2021 Arm Limited. All rights reserved. - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Name: cmsis_os2.c - * Purpose: CMSIS RTOS2 wrapper for FreeRTOS - * - *---------------------------------------------------------------------------*/ - -#include - -#include - -#include "cmsis_os2.h" // ::CMSIS:RTOS2 -#include "cmsis_compiler.h" // Compiler agnostic definitions - -#include "FreeRTOS.h" // ARM.FreeRTOS::RTOS:Core -#include "timers.h" // ARM.FreeRTOS::RTOS:Timers -#include "queue.h" - -#include "freertos_os2.h" // Configuration check and setup - -#include CMSIS_device_header - -#ifndef CMSIS_TASK_NOTIFY_INDEX -#define CMSIS_TASK_NOTIFY_INDEX 0 -#endif - -/*---------------------------------------------------------------------------*/ -#ifndef __ARM_ARCH_6M__ - #define __ARM_ARCH_6M__ 0 -#endif -#ifndef __ARM_ARCH_7M__ - #define __ARM_ARCH_7M__ 0 -#endif -#ifndef __ARM_ARCH_7EM__ - #define __ARM_ARCH_7EM__ 0 -#endif -#ifndef __ARM_ARCH_8M_MAIN__ - #define __ARM_ARCH_8M_MAIN__ 0 -#endif -#ifndef __ARM_ARCH_7A__ - #define __ARM_ARCH_7A__ 0 -#endif - -#if ((__ARM_ARCH_7M__ == 1U) || \ - (__ARM_ARCH_7EM__ == 1U) || \ - (__ARM_ARCH_8M_MAIN__ == 1U)) -#define IS_IRQ_MASKED() ((__get_PRIMASK() != 0U) || (__get_BASEPRI() != 0U)) -#elif (__ARM_ARCH_6M__ == 1U) -#define IS_IRQ_MASKED() (__get_PRIMASK() != 0U) -#elif (__ARM_ARCH_7A__ == 1U) -/* CPSR mask bits */ -#define CPSR_MASKBIT_I 0x80U - -#define IS_IRQ_MASKED() ((__get_CPSR() & CPSR_MASKBIT_I) != 0U) -#else -#define IS_IRQ_MASKED() (__get_PRIMASK() != 0U) -#endif - -#if (__ARM_ARCH_7A__ == 1U) -/* CPSR mode bitmasks */ -#define CPSR_MODE_USER 0x10U -#define CPSR_MODE_SYSTEM 0x1FU - -#define IS_IRQ_MODE() ((__get_mode() != CPSR_MODE_USER) && (__get_mode() != CPSR_MODE_SYSTEM)) -#else -#define IS_IRQ_MODE() (__get_IPSR() != 0U) -#endif - -/* Limits */ -#define MAX_BITS_TASK_NOTIFY 31U - -#define THREAD_FLAGS_INVALID_BITS (~((1UL << MAX_BITS_TASK_NOTIFY) - 1U)) - -/* Kernel version and identification string definition (major.minor.rev: mmnnnrrrr dec) */ -#define KERNEL_VERSION (((uint32_t)tskKERNEL_VERSION_MAJOR * 10000000UL) | \ - ((uint32_t)tskKERNEL_VERSION_MINOR * 10000UL) | \ - ((uint32_t)tskKERNEL_VERSION_BUILD * 1UL)) - -#define KERNEL_ID ("FreeRTOS " tskKERNEL_VERSION_NUMBER) - -/* Timer callback information structure definition */ -typedef struct { - osTimerFunc_t func; - void *arg; -} TimerCallback_t; - -/* Kernel initialization state */ -static osKernelState_t KernelState = osKernelInactive; - -/* - Heap region definition used by heap_5 variant - - Define configAPPLICATION_ALLOCATED_HEAP as nonzero value in FreeRTOSConfig.h if - heap regions are already defined and vPortDefineHeapRegions is called in application. - - Otherwise vPortDefineHeapRegions will be called by osKernelInitialize using - definition configHEAP_5_REGIONS as parameter. Overriding configHEAP_5_REGIONS - is possible by defining it globally or in FreeRTOSConfig.h. -*/ -#if defined(USE_FreeRTOS_HEAP_5) -#if (configAPPLICATION_ALLOCATED_HEAP == 0) - /* - FreeRTOS heap is not defined by the application. - Single region of size configTOTAL_HEAP_SIZE (defined in FreeRTOSConfig.h) - is provided by default. Define configHEAP_5_REGIONS to provide custom - HeapRegion_t array. - */ - #define HEAP_5_REGION_SETUP 1 - - #ifndef configHEAP_5_REGIONS - #define configHEAP_5_REGIONS xHeapRegions - - static uint8_t ucHeap[configTOTAL_HEAP_SIZE]; - - static HeapRegion_t xHeapRegions[] = { - { ucHeap, configTOTAL_HEAP_SIZE }, - { NULL, 0 } - }; - #else - /* Global definition is provided to override default heap array */ - extern HeapRegion_t configHEAP_5_REGIONS[]; - #endif -#else - /* - The application already defined the array used for the FreeRTOS heap and - called vPortDefineHeapRegions to initialize heap. - */ - #define HEAP_5_REGION_SETUP 0 -#endif /* configAPPLICATION_ALLOCATED_HEAP */ -#endif /* USE_FreeRTOS_HEAP_5 */ - -/* - Setup SVC to reset value. -*/ -__STATIC_INLINE void SVC_Setup (void) { -#if (__ARM_ARCH_7A__ == 0U) - /* Service Call interrupt might be configured before kernel start */ - /* and when its priority is lower or equal to BASEPRI, svc intruction */ - /* causes a Hard Fault. */ - NVIC_SetPriority (SVCall_IRQn, 0U); -#endif -} - -/* - Function macro used to retrieve semaphore count from ISR -*/ -#ifndef uxSemaphoreGetCountFromISR -#define uxSemaphoreGetCountFromISR( xSemaphore ) uxQueueMessagesWaitingFromISR( ( QueueHandle_t ) ( xSemaphore ) ) -#endif - -/* - Determine if CPU executes from interrupt context or if interrupts are masked. -*/ -__STATIC_INLINE uint32_t IRQ_Context (void) { - uint32_t irq; - BaseType_t state; - - irq = 0U; - - if (IS_IRQ_MODE()) { - /* Called from interrupt context */ - irq = 1U; - } - else { - /* Get FreeRTOS scheduler state */ - state = xTaskGetSchedulerState(); - - if (state != taskSCHEDULER_NOT_STARTED) { - /* Scheduler was started */ - if (IS_IRQ_MASKED()) { - /* Interrupts are masked */ - irq = 1U; - } - } - } - - /* Return context, 0: thread context, 1: IRQ context */ - return (irq); -} - - -/* ==== Kernel Management Functions ==== */ - -/* - Initialize the RTOS Kernel. -*/ -osStatus_t osKernelInitialize (void) { - osStatus_t stat; - BaseType_t state; - - if (IRQ_Context() != 0U) { - stat = osErrorISR; - } - else { - state = xTaskGetSchedulerState(); - - /* Initialize if scheduler not started and not initialized before */ - if ((state == taskSCHEDULER_NOT_STARTED) && (KernelState == osKernelInactive)) { - #if defined(USE_TRACE_EVENT_RECORDER) - /* Initialize the trace macro debugging output channel */ - EvrFreeRTOSSetup(0U); - #endif - #if defined(USE_FreeRTOS_HEAP_5) && (HEAP_5_REGION_SETUP == 1) - /* Initialize the memory regions when using heap_5 variant */ - vPortDefineHeapRegions (configHEAP_5_REGIONS); - #endif - KernelState = osKernelReady; - stat = osOK; - } else { - stat = osError; - } - } - - /* Return execution status */ - return (stat); -} - -/* - Get RTOS Kernel Information. -*/ -osStatus_t osKernelGetInfo (osVersion_t *version, char *id_buf, uint32_t id_size) { - - if (version != NULL) { - /* Version encoding is major.minor.rev: mmnnnrrrr dec */ - version->api = KERNEL_VERSION; - version->kernel = KERNEL_VERSION; - } - - if ((id_buf != NULL) && (id_size != 0U)) { - /* Buffer for retrieving identification string is provided */ - if (id_size > sizeof(KERNEL_ID)) { - id_size = sizeof(KERNEL_ID); - } - /* Copy kernel identification string into provided buffer */ - memcpy(id_buf, KERNEL_ID, id_size); - } - - /* Return execution status */ - return (osOK); -} - -/* - Get the current RTOS Kernel state. -*/ -osKernelState_t osKernelGetState (void) { - osKernelState_t state; - - switch (xTaskGetSchedulerState()) { - case taskSCHEDULER_RUNNING: - state = osKernelRunning; - break; - - case taskSCHEDULER_SUSPENDED: - state = osKernelLocked; - break; - - case taskSCHEDULER_NOT_STARTED: - default: - if (KernelState == osKernelReady) { - /* Ready, osKernelInitialize was already called */ - state = osKernelReady; - } else { - /* Not initialized */ - state = osKernelInactive; - } - break; - } - - /* Return current state */ - return (state); -} - -/* - Start the RTOS Kernel scheduler. -*/ -osStatus_t osKernelStart (void) { - osStatus_t stat; - BaseType_t state; - - if (IRQ_Context() != 0U) { - stat = osErrorISR; - } - else { - state = xTaskGetSchedulerState(); - - /* Start scheduler if initialized and not started before */ - if ((state == taskSCHEDULER_NOT_STARTED) && (KernelState == osKernelReady)) { - /* Ensure SVC priority is at the reset value */ - SVC_Setup(); - /* Change state to ensure correct API flow */ - KernelState = osKernelRunning; - /* Start the kernel scheduler */ - vTaskStartScheduler(); - stat = osOK; - } else { - stat = osError; - } - } - - /* Return execution status */ - return (stat); -} - -/* - Lock the RTOS Kernel scheduler. -*/ -int32_t osKernelLock (void) { - int32_t lock; - - if (IRQ_Context() != 0U) { - lock = (int32_t)osErrorISR; - } - else { - switch (xTaskGetSchedulerState()) { - case taskSCHEDULER_SUSPENDED: - lock = 1; - break; - - case taskSCHEDULER_RUNNING: - vTaskSuspendAll(); - lock = 0; - break; - - case taskSCHEDULER_NOT_STARTED: - default: - lock = (int32_t)osError; - break; - } - } - - /* Return previous lock state */ - return (lock); -} - -/* - Unlock the RTOS Kernel scheduler. -*/ -int32_t osKernelUnlock (void) { - int32_t lock; - - if (IRQ_Context() != 0U) { - lock = (int32_t)osErrorISR; - } - else { - switch (xTaskGetSchedulerState()) { - case taskSCHEDULER_SUSPENDED: - lock = 1; - - if (xTaskResumeAll() != pdTRUE) { - if (xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED) { - lock = (int32_t)osError; - } - } - break; - - case taskSCHEDULER_RUNNING: - lock = 0; - break; - - case taskSCHEDULER_NOT_STARTED: - default: - lock = (int32_t)osError; - break; - } - } - - /* Return previous lock state */ - return (lock); -} - -/* - Restore the RTOS Kernel scheduler lock state. -*/ -int32_t osKernelRestoreLock (int32_t lock) { - - if (IRQ_Context() != 0U) { - lock = (int32_t)osErrorISR; - } - else { - switch (xTaskGetSchedulerState()) { - case taskSCHEDULER_SUSPENDED: - case taskSCHEDULER_RUNNING: - if (lock == 1) { - vTaskSuspendAll(); - } - else { - if (lock != 0) { - lock = (int32_t)osError; - } - else { - if (xTaskResumeAll() != pdTRUE) { - if (xTaskGetSchedulerState() != taskSCHEDULER_RUNNING) { - lock = (int32_t)osError; - } - } - } - } - break; - - case taskSCHEDULER_NOT_STARTED: - default: - lock = (int32_t)osError; - break; - } - } - - /* Return new lock state */ - return (lock); -} - -/* - Get the RTOS kernel tick count. -*/ -uint32_t osKernelGetTickCount (void) { - TickType_t ticks; - - if (IRQ_Context() != 0U) { - ticks = xTaskGetTickCountFromISR(); - } else { - ticks = xTaskGetTickCount(); - } - - /* Return kernel tick count */ - return (ticks); -} - -/* - Get the RTOS kernel tick frequency. -*/ -uint32_t osKernelGetTickFreq (void) { - /* Return frequency in hertz */ - return (configTICK_RATE_HZ); -} - -/* - Get the RTOS kernel system timer frequency. -*/ -uint32_t osKernelGetSysTimerFreq (void) { - /* Return frequency in hertz */ - return (configCPU_CLOCK_HZ); -} - -/* ==== Generic Wait Functions ==== */ - -/* - Wait for Timeout (Time Delay). -*/ -osStatus_t osDelay (uint32_t ticks) { - osStatus_t stat; - - if (IRQ_Context() != 0U) { - stat = osErrorISR; - } - else { - stat = osOK; - - if (ticks != 0U) { - vTaskDelay(ticks); - } - } - - /* Return execution status */ - return (stat); -} - -/* - Wait until specified time. -*/ -osStatus_t osDelayUntil (uint32_t ticks) { - TickType_t tcnt, delay; - osStatus_t stat; - - if (IRQ_Context() != 0U) { - stat = osErrorISR; - } - else { - stat = osOK; - tcnt = xTaskGetTickCount(); - - /* Determine remaining number of ticks to delay */ - delay = (TickType_t)ticks - tcnt; - - /* Check if target tick has not expired */ - if((delay != 0U) && (0 == (delay >> (8 * sizeof(TickType_t) - 1)))) { - if (xTaskDelayUntil (&tcnt, delay) == pdFALSE) { - /* Did not delay */ - stat = osError; - } - } - else - { - /* No delay or already expired */ - stat = osErrorParameter; - } - } - - /* Return execution status */ - return (stat); -} - - -/* ==== Timer Management Functions ==== */ - -#if (configUSE_OS2_TIMER == 1) - -static void TimerCallback (TimerHandle_t hTimer) { - TimerCallback_t *callb; - - /* Retrieve pointer to callback function and argument */ - callb = (TimerCallback_t *)pvTimerGetTimerID (hTimer); - - /* Remove dynamic allocation flag */ - callb = (TimerCallback_t *)((uint32_t)callb & ~1U); - - if (callb != NULL) { - callb->func (callb->arg); - } -} - -/* - Create and Initialize a timer. -*/ -osTimerId_t osTimerNew (osTimerFunc_t func, osTimerType_t type, void *argument, const osTimerAttr_t *attr) { - const char *name; - TimerHandle_t hTimer; - TimerCallback_t *callb; - UBaseType_t reload; - int32_t mem; - uint32_t callb_dyn; - - hTimer = NULL; - - if ((IRQ_Context() == 0U) && (func != NULL)) { - callb = NULL; - callb_dyn = 0U; - - #if (configSUPPORT_STATIC_ALLOCATION == 1) - /* Static memory allocation is available: check if memory for control block */ - /* is provided and if it also contains space for callback and its argument */ - if ((attr != NULL) && (attr->cb_mem != NULL)) { - if (attr->cb_size >= (sizeof(StaticTimer_t) + sizeof(TimerCallback_t))) { - callb = (TimerCallback_t *)((uint32_t)attr->cb_mem + sizeof(StaticTimer_t)); - } - } - #endif - - #if (configSUPPORT_DYNAMIC_ALLOCATION == 1) - /* Dynamic memory allocation is available: if memory for callback and */ - /* its argument is not provided, allocate it from dynamic memory pool */ - if (callb == NULL) { - callb = (TimerCallback_t *)pvPortMalloc (sizeof(TimerCallback_t)); - - if (callb != NULL) { - /* Callback memory was allocated from dynamic pool, set flag */ - callb_dyn = 1U; - } - } - #endif - - if (callb != NULL) { - callb->func = func; - callb->arg = argument; - - if (type == osTimerOnce) { - reload = pdFALSE; - } else { - reload = pdTRUE; - } - - mem = -1; - name = NULL; - - if (attr != NULL) { - if (attr->name != NULL) { - name = attr->name; - } - - if ((attr->cb_mem != NULL) && (attr->cb_size >= sizeof(StaticTimer_t))) { - /* The memory for control block is provided, use static object */ - mem = 1; - } - else { - if ((attr->cb_mem == NULL) && (attr->cb_size == 0U)) { - /* Control block will be allocated from the dynamic pool */ - mem = 0; - } - } - } - else { - mem = 0; - } - /* Store callback memory dynamic allocation flag */ - callb = (TimerCallback_t *)((uint32_t)callb | callb_dyn); - /* - TimerCallback function is always provided as a callback and is used to call application - specified function with its argument both stored in structure callb. - */ - if (mem == 1) { - #if (configSUPPORT_STATIC_ALLOCATION == 1) - hTimer = xTimerCreateStatic (name, 1, reload, callb, TimerCallback, (StaticTimer_t *)attr->cb_mem); - #endif - } - else { - if (mem == 0) { - #if (configSUPPORT_DYNAMIC_ALLOCATION == 1) - hTimer = xTimerCreate (name, 1, reload, callb, TimerCallback); - #endif - } - } - - #if (configSUPPORT_DYNAMIC_ALLOCATION == 1) - if ((hTimer == NULL) && (callb != NULL) && (callb_dyn == 1U)) { - /* Failed to create a timer, release allocated resources */ - callb = (TimerCallback_t *)((uint32_t)callb & ~1U); - - vPortFree (callb); - } - #endif - } - } - - /* Return timer ID */ - return ((osTimerId_t)hTimer); -} - -/* - Get name of a timer. -*/ -const char *osTimerGetName (osTimerId_t timer_id) { - TimerHandle_t hTimer = (TimerHandle_t)timer_id; - const char *p; - - if ((IRQ_Context() != 0U) || (hTimer == NULL)) { - p = NULL; - } else { - p = pcTimerGetName (hTimer); - } - - /* Return name as null-terminated string */ - return (p); -} - -/* - Start or restart a timer. -*/ -osStatus_t osTimerStart (osTimerId_t timer_id, uint32_t ticks) { - TimerHandle_t hTimer = (TimerHandle_t)timer_id; - osStatus_t stat; - - if (IRQ_Context() != 0U) { - stat = osErrorISR; - } - else if (hTimer == NULL) { - stat = osErrorParameter; - } - else { - if (xTimerChangePeriod (hTimer, ticks, portMAX_DELAY) == pdPASS) { - stat = osOK; - } else { - stat = osErrorResource; - } - } - - /* Return execution status */ - return (stat); -} - -/* - Stop a timer. -*/ -osStatus_t osTimerStop (osTimerId_t timer_id) { - TimerHandle_t hTimer = (TimerHandle_t)timer_id; - osStatus_t stat; - - if (IRQ_Context() != 0U) { - stat = osErrorISR; - } - else if (hTimer == NULL) { - stat = osErrorParameter; - } - else { - if (xTimerIsTimerActive (hTimer) == pdFALSE) { - stat = osErrorResource; - } - else { - if (xTimerStop (hTimer, portMAX_DELAY) == pdPASS) { - stat = osOK; - } else { - stat = osError; - } - } - } - - /* Return execution status */ - return (stat); -} - -/* - Check if a timer is running. -*/ -uint32_t osTimerIsRunning (osTimerId_t timer_id) { - TimerHandle_t hTimer = (TimerHandle_t)timer_id; - uint32_t running; - - if ((IRQ_Context() != 0U) || (hTimer == NULL)) { - running = 0U; - } else { - running = (uint32_t)xTimerIsTimerActive (hTimer); - } - - /* Return 0: not running, 1: running */ - return (running); -} - -/* - Delete a timer. -*/ -osStatus_t osTimerDelete (osTimerId_t timer_id) { - TimerHandle_t hTimer = (TimerHandle_t)timer_id; - osStatus_t stat; -#ifndef USE_FreeRTOS_HEAP_1 -#if (configSUPPORT_DYNAMIC_ALLOCATION == 1) - TimerCallback_t *callb; -#endif - - if (IRQ_Context() != 0U) { - stat = osErrorISR; - } - else if (hTimer == NULL) { - stat = osErrorParameter; - } - else { - #if (configSUPPORT_DYNAMIC_ALLOCATION == 1) - callb = (TimerCallback_t *)pvTimerGetTimerID (hTimer); - #endif - - if (xTimerDelete (hTimer, portMAX_DELAY) == pdPASS) { - #if (configSUPPORT_DYNAMIC_ALLOCATION == 1) - if ((uint32_t)callb & 1U) { - /* Callback memory was allocated from dynamic pool, clear flag */ - callb = (TimerCallback_t *)((uint32_t)callb & ~1U); - - /* Return allocated memory to dynamic pool */ - vPortFree (callb); - } - #endif - stat = osOK; - } else { - stat = osErrorResource; - } - } -#else - stat = osError; -#endif - - /* Return execution status */ - return (stat); -} -#endif /* (configUSE_OS2_TIMER == 1) */ - - -/* ==== Message Queue Management Functions ==== */ - -/* - Create and Initialize a Message Queue object. - - Limitations: - - The memory for control block and and message data must be provided in the - osThreadAttr_t structure in order to allocate object statically. -*/ -osMessageQueueId_t osMessageQueueNew (uint32_t msg_count, uint32_t msg_size, const osMessageQueueAttr_t *attr) { - QueueHandle_t hQueue; - int32_t mem; - - hQueue = NULL; - - if ((IRQ_Context() == 0U) && (msg_count > 0U) && (msg_size > 0U)) { - mem = -1; - - if (attr != NULL) { - if ((attr->cb_mem != NULL) && (attr->cb_size >= sizeof(StaticQueue_t)) && - (attr->mq_mem != NULL) && (attr->mq_size >= (msg_count * msg_size))) { - /* The memory for control block and message data is provided, use static object */ - mem = 1; - } - else { - if ((attr->cb_mem == NULL) && (attr->cb_size == 0U) && - (attr->mq_mem == NULL) && (attr->mq_size == 0U)) { - /* Control block will be allocated from the dynamic pool */ - mem = 0; - } - } - } - else { - mem = 0; - } - - if (mem == 1) { - #if (configSUPPORT_STATIC_ALLOCATION == 1) - hQueue = xQueueCreateStatic (msg_count, msg_size, attr->mq_mem, attr->cb_mem); - #endif - } - else { - if (mem == 0) { - #if (configSUPPORT_DYNAMIC_ALLOCATION == 1) - hQueue = xQueueCreate (msg_count, msg_size); - #endif - } - } - - #if (configQUEUE_REGISTRY_SIZE > 0) - if (hQueue != NULL) { - if ((attr != NULL) && (attr->name != NULL)) { - /* Only non-NULL name objects are added to the Queue Registry */ - vQueueAddToRegistry (hQueue, attr->name); - } - } - #endif - - } - - /* Return message queue ID */ - return ((osMessageQueueId_t)hQueue); -} - -/* - Put a Message into a Queue or timeout if Queue is full. - - Limitations: - - Message priority is ignored -*/ -osStatus_t osMessageQueuePut (osMessageQueueId_t mq_id, const void *msg_ptr, uint8_t msg_prio, uint32_t timeout) { - QueueHandle_t hQueue = (QueueHandle_t)mq_id; - osStatus_t stat; - BaseType_t yield; - - (void)msg_prio; /* Message priority is ignored */ - - stat = osOK; - - if (IRQ_Context() != 0U) { - if ((hQueue == NULL) || (msg_ptr == NULL) || (timeout != 0U)) { - stat = osErrorParameter; - } - else { - yield = pdFALSE; - - if (xQueueSendToBackFromISR (hQueue, msg_ptr, &yield) != pdTRUE) { - stat = osErrorResource; - } else { - portYIELD_FROM_ISR (yield); - } - } - } - else { - if ((hQueue == NULL) || (msg_ptr == NULL)) { - stat = osErrorParameter; - } - else { - if (xQueueSendToBack (hQueue, msg_ptr, (TickType_t)timeout) != pdPASS) { - if (timeout != 0U) { - stat = osErrorTimeout; - } else { - stat = osErrorResource; - } - } - } - } - - /* Return execution status */ - return (stat); -} - -/* - Get a Message from a Queue or timeout if Queue is empty. - - Limitations: - - Message priority is ignored -*/ -osStatus_t osMessageQueueGet (osMessageQueueId_t mq_id, void *msg_ptr, uint8_t *msg_prio, uint32_t timeout) { - QueueHandle_t hQueue = (QueueHandle_t)mq_id; - osStatus_t stat; - BaseType_t yield; - - (void)msg_prio; /* Message priority is ignored */ - - stat = osOK; - - if (IRQ_Context() != 0U) { - if ((hQueue == NULL) || (msg_ptr == NULL) || (timeout != 0U)) { - stat = osErrorParameter; - } - else { - yield = pdFALSE; - - if (xQueueReceiveFromISR (hQueue, msg_ptr, &yield) != pdPASS) { - stat = osErrorResource; - } else { - portYIELD_FROM_ISR (yield); - } - } - } - else { - if ((hQueue == NULL) || (msg_ptr == NULL)) { - stat = osErrorParameter; - } - else { - if (xQueueReceive (hQueue, msg_ptr, (TickType_t)timeout) != pdPASS) { - if (timeout != 0U) { - stat = osErrorTimeout; - } else { - stat = osErrorResource; - } - } - } - } - - /* Return execution status */ - return (stat); -} - -/* - Get maximum number of messages in a Message Queue. -*/ -uint32_t osMessageQueueGetCapacity (osMessageQueueId_t mq_id) { - StaticQueue_t *mq = (StaticQueue_t *)mq_id; - uint32_t capacity; - - if (mq == NULL) { - capacity = 0U; - } else { - /* capacity = pxQueue->uxLength */ - capacity = mq->uxDummy4[1]; - } - - /* Return maximum number of messages */ - return (capacity); -} - -/* - Get maximum message size in a Message Queue. -*/ -uint32_t osMessageQueueGetMsgSize (osMessageQueueId_t mq_id) { - StaticQueue_t *mq = (StaticQueue_t *)mq_id; - uint32_t size; - - if (mq == NULL) { - size = 0U; - } else { - /* size = pxQueue->uxItemSize */ - size = mq->uxDummy4[2]; - } - - /* Return maximum message size */ - return (size); -} - -/* - Get number of queued messages in a Message Queue. -*/ -uint32_t osMessageQueueGetCount (osMessageQueueId_t mq_id) { - QueueHandle_t hQueue = (QueueHandle_t)mq_id; - UBaseType_t count; - - if (hQueue == NULL) { - count = 0U; - } - else if (IRQ_Context() != 0U) { - count = uxQueueMessagesWaitingFromISR (hQueue); - } - else { - count = uxQueueMessagesWaiting (hQueue); - } - - /* Return number of queued messages */ - return ((uint32_t)count); -} - -/* - Get number of available slots for messages in a Message Queue. -*/ -uint32_t osMessageQueueGetSpace (osMessageQueueId_t mq_id) { - StaticQueue_t *mq = (StaticQueue_t *)mq_id; - uint32_t space; - uint32_t isrm; - - if (mq == NULL) { - space = 0U; - } - else if (IRQ_Context() != 0U) { - isrm = taskENTER_CRITICAL_FROM_ISR(); - - /* space = pxQueue->uxLength - pxQueue->uxMessagesWaiting; */ - space = mq->uxDummy4[1] - mq->uxDummy4[0]; - - taskEXIT_CRITICAL_FROM_ISR(isrm); - } - else { - space = (uint32_t)uxQueueSpacesAvailable ((QueueHandle_t)mq); - } - - /* Return number of available slots */ - return (space); -} - -/* - Reset a Message Queue to initial empty state. -*/ -osStatus_t osMessageQueueReset (osMessageQueueId_t mq_id) { - QueueHandle_t hQueue = (QueueHandle_t)mq_id; - osStatus_t stat; - - if (IRQ_Context() != 0U) { - stat = osErrorISR; - } - else if (hQueue == NULL) { - stat = osErrorParameter; - } - else { - stat = osOK; - (void)xQueueReset (hQueue); - } - - /* Return execution status */ - return (stat); -} - -/* - Delete a Message Queue object. -*/ -osStatus_t osMessageQueueDelete (osMessageQueueId_t mq_id) { - QueueHandle_t hQueue = (QueueHandle_t)mq_id; - osStatus_t stat; - -#ifndef USE_FreeRTOS_HEAP_1 - if (IRQ_Context() != 0U) { - stat = osErrorISR; - } - else if (hQueue == NULL) { - stat = osErrorParameter; - } - else { - #if (configQUEUE_REGISTRY_SIZE > 0) - vQueueUnregisterQueue (hQueue); - #endif - - stat = osOK; - vQueueDelete (hQueue); - } -#else - stat = osError; -#endif - - /* Return execution status */ - return (stat); -} - -/* Callback function prototypes */ -extern void vApplicationIdleHook (void); -extern void vApplicationMallocFailedHook (void); -extern void vApplicationDaemonTaskStartupHook (void); - -/** - Dummy implementation of the callback function vApplicationIdleHook(). -*/ -#if (configUSE_IDLE_HOOK == 1) -__WEAK void vApplicationIdleHook (void){} -#endif - -/** - Dummy implementation of the callback function vApplicationTickHook(). -*/ -#if (configUSE_TICK_HOOK == 1) - __WEAK void vApplicationTickHook (void){} -#endif - -/** - Dummy implementation of the callback function vApplicationMallocFailedHook(). -*/ -#if (configUSE_MALLOC_FAILED_HOOK == 1) -__WEAK void vApplicationMallocFailedHook (void) { - /* Assert when malloc failed hook is enabled but no application defined function exists */ - configASSERT(0); -} -#endif - -/** - Dummy implementation of the callback function vApplicationDaemonTaskStartupHook(). -*/ -#if (configUSE_DAEMON_TASK_STARTUP_HOOK == 1) -__WEAK void vApplicationDaemonTaskStartupHook (void){} -#endif - -/** - Dummy implementation of the callback function vApplicationStackOverflowHook(). -*/ -#if (configCHECK_FOR_STACK_OVERFLOW > 0) -__WEAK void vApplicationStackOverflowHook (TaskHandle_t xTask, char *pcTaskName) { - (void)xTask; - (void)pcTaskName; - - /* Assert when stack overflow is enabled but no application defined function exists */ - configASSERT(0); -} -#endif diff --git a/lib/FreeRTOS-glue/cmsis_os2.h b/lib/FreeRTOS-glue/cmsis_os2.h deleted file mode 100644 index 044c98513..000000000 --- a/lib/FreeRTOS-glue/cmsis_os2.h +++ /dev/null @@ -1,302 +0,0 @@ -/* - * Copyright (c) 2013-2020 Arm Limited. All rights reserved. - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ---------------------------------------------------------------------- - * - * $Date: 12. June 2020 - * $Revision: V2.1.3 - * - * Project: CMSIS-RTOS2 API - * Title: cmsis_os2.h header file - * - * Version 2.1.3 - * Additional functions allowed to be called from Interrupt Service Routines: - * - osThreadGetId - * Version 2.1.2 - * Additional functions allowed to be called from Interrupt Service Routines: - * - osKernelGetInfo, osKernelGetState - * Version 2.1.1 - * Additional functions allowed to be called from Interrupt Service Routines: - * - osKernelGetTickCount, osKernelGetTickFreq - * Changed Kernel Tick type to uint32_t: - * - updated: osKernelGetTickCount, osDelayUntil - * Version 2.1.0 - * Support for critical and uncritical sections (nesting safe): - * - updated: osKernelLock, osKernelUnlock - * - added: osKernelRestoreLock - * Updated Thread and Event Flags: - * - changed flags parameter and return type from int32_t to uint32_t - * Version 2.0.0 - * Initial Release - *---------------------------------------------------------------------------*/ - -#ifndef CMSIS_OS2_H_ -#define CMSIS_OS2_H_ - -#ifndef __NO_RETURN -#if defined(__CC_ARM) -#define __NO_RETURN __declspec(noreturn) -#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) -#define __NO_RETURN __attribute__((__noreturn__)) -#elif defined(__GNUC__) -#define __NO_RETURN __attribute__((__noreturn__)) -#elif defined(__ICCARM__) -#define __NO_RETURN __noreturn -#else -#define __NO_RETURN -#endif -#endif - -#include - -#ifdef __cplusplus -extern "C" -{ -#endif - - -// ==== Enumerations, structures, defines ==== - -/// Version information. -typedef struct { - uint32_t api; ///< API version (major.minor.rev: mmnnnrrrr dec). - uint32_t kernel; ///< Kernel version (major.minor.rev: mmnnnrrrr dec). -} osVersion_t; - -/// Kernel state. -typedef enum { - osKernelInactive = 0, ///< Inactive. - osKernelReady = 1, ///< Ready. - osKernelRunning = 2, ///< Running. - osKernelLocked = 3, ///< Locked. - osKernelSuspended = 4, ///< Suspended. - osKernelError = -1, ///< Error. - osKernelReserved = 0x7FFFFFFF ///< Prevents enum down-size compiler optimization. -} osKernelState_t; - -/// Timer callback function. -typedef void (*osTimerFunc_t) (void *argument); - -/// Timer type. -typedef enum { - osTimerOnce = 0, ///< One-shot timer. - osTimerPeriodic = 1 ///< Repeating timer. -} osTimerType_t; - - -/// \details Timer ID identifies the timer. -typedef void *osTimerId_t; - -/// \details Message Queue ID identifies the message queue. -typedef void *osMessageQueueId_t; - - -#ifndef TZ_MODULEID_T -#define TZ_MODULEID_T -/// \details Data type that identifies secure software modules called by a process. -typedef uint32_t TZ_ModuleId_t; -#endif - - -/// Attributes structure for timer. -typedef struct { - const char *name; ///< name of the timer - uint32_t attr_bits; ///< attribute bits - void *cb_mem; ///< memory for control block - uint32_t cb_size; ///< size of provided memory for control block -} osTimerAttr_t; - -/// Attributes structure for message queue. -typedef struct { - const char *name; ///< name of the message queue - uint32_t attr_bits; ///< attribute bits - void *cb_mem; ///< memory for control block - uint32_t cb_size; ///< size of provided memory for control block - void *mq_mem; ///< memory for data storage - uint32_t mq_size; ///< size of provided memory for data storage -} osMessageQueueAttr_t; - - -// ==== Kernel Management Functions ==== - -/// Initialize the RTOS Kernel. -/// \return status code that indicates the execution status of the function. -osStatus_t osKernelInitialize (void); - -/// Get RTOS Kernel Information. -/// \param[out] version pointer to buffer for retrieving version information. -/// \param[out] id_buf pointer to buffer for retrieving kernel identification string. -/// \param[in] id_size size of buffer for kernel identification string. -/// \return status code that indicates the execution status of the function. -osStatus_t osKernelGetInfo (osVersion_t *version, char *id_buf, uint32_t id_size); - -/// Get the current RTOS Kernel state. -/// \return current RTOS Kernel state. -osKernelState_t osKernelGetState (void); - -/// Start the RTOS Kernel scheduler. -/// \return status code that indicates the execution status of the function. -osStatus_t osKernelStart (void); - -/// Lock the RTOS Kernel scheduler. -/// \return previous lock state (1 - locked, 0 - not locked, error code if negative). -int32_t osKernelLock (void); - -/// Unlock the RTOS Kernel scheduler. -/// \return previous lock state (1 - locked, 0 - not locked, error code if negative). -int32_t osKernelUnlock (void); - -/// Restore the RTOS Kernel scheduler lock state. -/// \param[in] lock lock state obtained by \ref osKernelLock or \ref osKernelUnlock. -/// \return new lock state (1 - locked, 0 - not locked, error code if negative). -int32_t osKernelRestoreLock (int32_t lock); - -/// Suspend the RTOS Kernel scheduler. -/// \return time in ticks, for how long the system can sleep or power-down. -uint32_t osKernelSuspend (void); - -/// Resume the RTOS Kernel scheduler. -/// \param[in] sleep_ticks time in ticks for how long the system was in sleep or power-down mode. -void osKernelResume (uint32_t sleep_ticks); - -/// Get the RTOS kernel tick count. -/// \return RTOS kernel current tick count. -uint32_t osKernelGetTickCount (void); - -/// Get the RTOS kernel tick frequency. -/// \return frequency of the kernel tick in hertz, i.e. kernel ticks per second. -uint32_t osKernelGetTickFreq (void); - -/// Get the RTOS kernel system timer frequency. -/// \return frequency of the system timer in hertz, i.e. timer ticks per second. -uint32_t osKernelGetSysTimerFreq (void); - -// ==== Generic Wait Functions ==== - -/// Wait for Timeout (Time Delay). -/// \param[in] ticks \ref CMSIS_RTOS_TimeOutValue "time ticks" value -/// \return status code that indicates the execution status of the function. -osStatus_t osDelay (uint32_t ticks); - -/// Wait until specified time. -/// \param[in] ticks absolute time in ticks -/// \return status code that indicates the execution status of the function. -osStatus_t osDelayUntil (uint32_t ticks); - - -// ==== Timer Management Functions ==== - -/// Create and Initialize a timer. -/// \param[in] func function pointer to callback function. -/// \param[in] type \ref osTimerOnce for one-shot or \ref osTimerPeriodic for periodic behavior. -/// \param[in] argument argument to the timer callback function. -/// \param[in] attr timer attributes; NULL: default values. -/// \return timer ID for reference by other functions or NULL in case of error. -osTimerId_t osTimerNew (osTimerFunc_t func, osTimerType_t type, void *argument, const osTimerAttr_t *attr); - -/// Get name of a timer. -/// \param[in] timer_id timer ID obtained by \ref osTimerNew. -/// \return name as null-terminated string. -const char *osTimerGetName (osTimerId_t timer_id); - -/// Start or restart a timer. -/// \param[in] timer_id timer ID obtained by \ref osTimerNew. -/// \param[in] ticks \ref CMSIS_RTOS_TimeOutValue "time ticks" value of the timer. -/// \return status code that indicates the execution status of the function. -osStatus_t osTimerStart (osTimerId_t timer_id, uint32_t ticks); - -/// Stop a timer. -/// \param[in] timer_id timer ID obtained by \ref osTimerNew. -/// \return status code that indicates the execution status of the function. -osStatus_t osTimerStop (osTimerId_t timer_id); - -/// Check if a timer is running. -/// \param[in] timer_id timer ID obtained by \ref osTimerNew. -/// \return 0 not running, 1 running. -uint32_t osTimerIsRunning (osTimerId_t timer_id); - -/// Delete a timer. -/// \param[in] timer_id timer ID obtained by \ref osTimerNew. -/// \return status code that indicates the execution status of the function. -osStatus_t osTimerDelete (osTimerId_t timer_id); - -// ==== Message Queue Management Functions ==== - -/// Create and Initialize a Message Queue object. -/// \param[in] msg_count maximum number of messages in queue. -/// \param[in] msg_size maximum message size in bytes. -/// \param[in] attr message queue attributes; NULL: default values. -/// \return message queue ID for reference by other functions or NULL in case of error. -osMessageQueueId_t osMessageQueueNew (uint32_t msg_count, uint32_t msg_size, const osMessageQueueAttr_t *attr); - -/// Get name of a Message Queue object. -/// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. -/// \return name as null-terminated string. -const char *osMessageQueueGetName (osMessageQueueId_t mq_id); - -/// Put a Message into a Queue or timeout if Queue is full. -/// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. -/// \param[in] msg_ptr pointer to buffer with message to put into a queue. -/// \param[in] msg_prio message priority. -/// \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. -/// \return status code that indicates the execution status of the function. -osStatus_t osMessageQueuePut (osMessageQueueId_t mq_id, const void *msg_ptr, uint8_t msg_prio, uint32_t timeout); - -/// Get a Message from a Queue or timeout if Queue is empty. -/// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. -/// \param[out] msg_ptr pointer to buffer for message to get from a queue. -/// \param[out] msg_prio pointer to buffer for message priority or NULL. -/// \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. -/// \return status code that indicates the execution status of the function. -osStatus_t osMessageQueueGet (osMessageQueueId_t mq_id, void *msg_ptr, uint8_t *msg_prio, uint32_t timeout); - -/// Get maximum number of messages in a Message Queue. -/// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. -/// \return maximum number of messages. -uint32_t osMessageQueueGetCapacity (osMessageQueueId_t mq_id); - -/// Get maximum message size in a Message Queue. -/// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. -/// \return maximum message size in bytes. -uint32_t osMessageQueueGetMsgSize (osMessageQueueId_t mq_id); - -/// Get number of queued messages in a Message Queue. -/// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. -/// \return number of queued messages. -uint32_t osMessageQueueGetCount (osMessageQueueId_t mq_id); - -/// Get number of available slots for messages in a Message Queue. -/// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. -/// \return number of available slots for messages. -uint32_t osMessageQueueGetSpace (osMessageQueueId_t mq_id); - -/// Reset a Message Queue to initial empty state. -/// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. -/// \return status code that indicates the execution status of the function. -osStatus_t osMessageQueueReset (osMessageQueueId_t mq_id); - -/// Delete a Message Queue object. -/// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. -/// \return status code that indicates the execution status of the function. -osStatus_t osMessageQueueDelete (osMessageQueueId_t mq_id); - - -#ifdef __cplusplus -} -#endif - -#endif // CMSIS_OS2_H_ diff --git a/lib/FreeRTOS-glue/freertos_os2.h b/lib/FreeRTOS-glue/freertos_os2.h deleted file mode 100644 index 1e70b3fcc..000000000 --- a/lib/FreeRTOS-glue/freertos_os2.h +++ /dev/null @@ -1,319 +0,0 @@ -/* -------------------------------------------------------------------------- - * Copyright (c) 2013-2021 Arm Limited. All rights reserved. - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Name: freertos_os2.h - * Purpose: CMSIS RTOS2 wrapper for FreeRTOS - * - *---------------------------------------------------------------------------*/ - -#ifndef FREERTOS_OS2_H_ -#define FREERTOS_OS2_H_ - -#include -#include - -#include "FreeRTOS.h" // ARM.FreeRTOS::RTOS:Core - -#if defined(_RTE_) -#include "RTE_Components.h" // Component selection -#include CMSIS_device_header - -/* Configuration and component setup check */ -#if defined(RTE_Compiler_EventRecorder) - #if !defined(EVR_FREERTOS_DISABLE) - #define USE_TRACE_EVENT_RECORDER - /* - FreeRTOS provides functions and hooks to support execution tracing. This - functionality is only enabled if configUSE_TRACE_FACILITY == 1. - Set #define configUSE_TRACE_FACILITY 1 in FreeRTOSConfig.h to enable trace events. - */ - #if (configUSE_TRACE_FACILITY == 0) - #error "Definition configUSE_TRACE_FACILITY must equal 1 to enable FreeRTOS trace events." - #endif - #endif -#endif - -#if defined(RTE_RTOS_FreeRTOS_HEAP_1) - #define USE_FreeRTOS_HEAP_1 -#endif - -#if defined(RTE_RTOS_FreeRTOS_HEAP_5) - #define USE_FreeRTOS_HEAP_5 -#endif -#endif /* _RTE_ */ - -/* - CMSIS-RTOS2 FreeRTOS image size optimization definitions. - - Note: Definitions configUSE_OS2 can be used to optimize FreeRTOS image size when - certain functionality is not required when using CMSIS-RTOS2 API. - In general optimization decisions are left to the tool chain but in cases - when coding style prevents it to optimize the code following optional - definitions can be used. -*/ - -/* - Option to exclude CMSIS-RTOS2 functions osThreadSuspend and osThreadResume from - the application image. -*/ -#ifndef configUSE_OS2_THREAD_SUSPEND_RESUME -#define configUSE_OS2_THREAD_SUSPEND_RESUME 1 -#endif - -/* - Option to exclude CMSIS-RTOS2 function furi_thread_enumerate from the application image. -*/ -#ifndef configUSE_OS2_THREAD_ENUMERATE -#define configUSE_OS2_THREAD_ENUMERATE 1 -#endif - -/* - Option to disable CMSIS-RTOS2 function osEventFlagsSet and osEventFlagsClear - operation from ISR. -*/ -#ifndef configUSE_OS2_EVENTFLAGS_FROM_ISR -#define configUSE_OS2_EVENTFLAGS_FROM_ISR 1 -#endif - -/* - Option to exclude CMSIS-RTOS2 Thread Flags API functions from the application image. -*/ -#ifndef configUSE_OS2_THREAD_FLAGS -#define configUSE_OS2_THREAD_FLAGS configUSE_TASK_NOTIFICATIONS -#endif - -/* - Option to exclude CMSIS-RTOS2 Timer API functions from the application image. -*/ -#ifndef configUSE_OS2_TIMER -#define configUSE_OS2_TIMER configUSE_TIMERS -#endif - -/* - Option to exclude CMSIS-RTOS2 Mutex API functions from the application image. -*/ -#ifndef configUSE_OS2_MUTEX -#define configUSE_OS2_MUTEX configUSE_MUTEXES -#endif - - -/* - CMSIS-RTOS2 FreeRTOS configuration check (FreeRTOSConfig.h). - - Note: CMSIS-RTOS API requires functions included by using following definitions. - In case if certain API function is not used compiler will optimize it away. -*/ -#if (INCLUDE_xSemaphoreGetMutexHolder == 0) - /* - CMSIS-RTOS2 function osMutexGetOwner uses FreeRTOS function xSemaphoreGetMutexHolder. In case if - osMutexGetOwner is not used in the application image, compiler will optimize it away. - Set #define INCLUDE_xSemaphoreGetMutexHolder 1 to fix this error. - */ - #error "Definition INCLUDE_xSemaphoreGetMutexHolder must equal 1 to implement Mutex Management API." -#endif -#if (INCLUDE_vTaskDelay == 0) - /* - CMSIS-RTOS2 function osDelay uses FreeRTOS function vTaskDelay. In case if - osDelay is not used in the application image, compiler will optimize it away. - Set #define INCLUDE_vTaskDelay 1 to fix this error. - */ - #error "Definition INCLUDE_vTaskDelay must equal 1 to implement Generic Wait Functions API." -#endif -#if (INCLUDE_xTaskDelayUntil == 0) - /* - CMSIS-RTOS2 function osDelayUntil uses FreeRTOS function xTaskDelayUntil. In case if - osDelayUntil is not used in the application image, compiler will optimize it away. - Set #define INCLUDE_xTaskDelayUntil 1 to fix this error. - */ - #error "Definition INCLUDE_xTaskDelayUntil must equal 1 to implement Generic Wait Functions API." -#endif -#if (INCLUDE_vTaskDelete == 0) - /* - CMSIS-RTOS2 function osThreadTerminate and osThreadExit uses FreeRTOS function - vTaskDelete. In case if they are not used in the application image, compiler - will optimize them away. - Set #define INCLUDE_vTaskDelete 1 to fix this error. - */ - #error "Definition INCLUDE_vTaskDelete must equal 1 to implement Thread Management API." -#endif -#if (INCLUDE_xTaskGetCurrentTaskHandle == 0) - /* - CMSIS-RTOS2 API uses FreeRTOS function xTaskGetCurrentTaskHandle to implement - functions osThreadGetId, furi_thread_flags_clear and furi_thread_flags_get. In case if these - functions are not used in the application image, compiler will optimize them away. - Set #define INCLUDE_xTaskGetCurrentTaskHandle 1 to fix this error. - */ - #error "Definition INCLUDE_xTaskGetCurrentTaskHandle must equal 1 to implement Thread Management API." -#endif -#if (INCLUDE_xTaskGetSchedulerState == 0) - /* - CMSIS-RTOS2 API uses FreeRTOS function xTaskGetSchedulerState to implement Kernel - tick handling and therefore it is vital that xTaskGetSchedulerState is included into - the application image. - Set #define INCLUDE_xTaskGetSchedulerState 1 to fix this error. - */ - #error "Definition INCLUDE_xTaskGetSchedulerState must equal 1 to implement Kernel Information and Control API." -#endif -#if (INCLUDE_uxTaskGetStackHighWaterMark == 0) - /* - CMSIS-RTOS2 function furi_thread_get_stack_space uses FreeRTOS function uxTaskGetStackHighWaterMark. - In case if furi_thread_get_stack_space is not used in the application image, compiler will - optimize it away. - Set #define INCLUDE_uxTaskGetStackHighWaterMark 1 to fix this error. - */ - #error "Definition INCLUDE_uxTaskGetStackHighWaterMark must equal 1 to implement Thread Management API." -#endif -#if (INCLUDE_uxTaskPriorityGet == 0) - /* - CMSIS-RTOS2 function osThreadGetPriority uses FreeRTOS function uxTaskPriorityGet. In case if - osThreadGetPriority is not used in the application image, compiler will optimize it away. - Set #define INCLUDE_uxTaskPriorityGet 1 to fix this error. - */ - #error "Definition INCLUDE_uxTaskPriorityGet must equal 1 to implement Thread Management API." -#endif -#if (INCLUDE_vTaskPrioritySet == 0) - /* - CMSIS-RTOS2 function osThreadSetPriority uses FreeRTOS function vTaskPrioritySet. In case if - osThreadSetPriority is not used in the application image, compiler will optimize it away. - Set #define INCLUDE_vTaskPrioritySet 1 to fix this error. - */ - #error "Definition INCLUDE_vTaskPrioritySet must equal 1 to implement Thread Management API." -#endif -#if (INCLUDE_eTaskGetState == 0) - /* - CMSIS-RTOS2 API uses FreeRTOS function vTaskDelayUntil to implement functions osThreadGetState - and osThreadTerminate. In case if these functions are not used in the application image, - compiler will optimize them away. - Set #define INCLUDE_eTaskGetState 1 to fix this error. - */ - #error "Definition INCLUDE_eTaskGetState must equal 1 to implement Thread Management API." -#endif -#if (INCLUDE_vTaskSuspend == 0) - /* - CMSIS-RTOS2 API uses FreeRTOS functions vTaskSuspend and vTaskResume to implement - functions osThreadSuspend and osThreadResume. In case if these functions are not - used in the application image, compiler will optimize them away. - Set #define INCLUDE_vTaskSuspend 1 to fix this error. - - Alternatively, if the application does not use osThreadSuspend and - osThreadResume they can be excluded from the image code by setting: - #define configUSE_OS2_THREAD_SUSPEND_RESUME 0 (in FreeRTOSConfig.h) - */ - #if (configUSE_OS2_THREAD_SUSPEND_RESUME == 1) - #error "Definition INCLUDE_vTaskSuspend must equal 1 to implement Kernel Information and Control API." - #endif -#endif -#if (INCLUDE_xTimerPendFunctionCall == 0) - /* - CMSIS-RTOS2 function osEventFlagsSet and osEventFlagsClear, when called from - the ISR, call FreeRTOS functions xEventGroupSetBitsFromISR and - xEventGroupClearBitsFromISR which are only enabled if timers are operational and - xTimerPendFunctionCall in enabled. - Set #define INCLUDE_xTimerPendFunctionCall 1 and #define configUSE_TIMERS 1 - to fix this error. - - Alternatively, if the application does not use osEventFlagsSet and osEventFlagsClear - from the ISR their operation from ISR can be restricted by setting: - #define configUSE_OS2_EVENTFLAGS_FROM_ISR 0 (in FreeRTOSConfig.h) - */ - #if (configUSE_OS2_EVENTFLAGS_FROM_ISR == 1) - #error "Definition INCLUDE_xTimerPendFunctionCall must equal 1 to implement Event Flags API." - #endif -#endif - -#if (configUSE_TIMERS == 0) - /* - CMSIS-RTOS2 Timer Management API functions use FreeRTOS timer functions to implement - timer management. In case if these functions are not used in the application image, - compiler will optimize them away. - Set #define configUSE_TIMERS 1 to fix this error. - - Alternatively, if the application does not use timer functions they can be - excluded from the image code by setting: - #define configUSE_OS2_TIMER 0 (in FreeRTOSConfig.h) - */ - #if (configUSE_OS2_TIMER == 1) - #error "Definition configUSE_TIMERS must equal 1 to implement Timer Management API." - #endif -#endif - -#if (configUSE_MUTEXES == 0) - /* - CMSIS-RTOS2 Mutex Management API functions use FreeRTOS mutex functions to implement - mutex management. In case if these functions are not used in the application image, - compiler will optimize them away. - Set #define configUSE_MUTEXES 1 to fix this error. - - Alternatively, if the application does not use mutex functions they can be - excluded from the image code by setting: - #define configUSE_OS2_MUTEX 0 (in FreeRTOSConfig.h) - */ - #if (configUSE_OS2_MUTEX == 1) - #error "Definition configUSE_MUTEXES must equal 1 to implement Mutex Management API." - #endif -#endif - -#if (configUSE_COUNTING_SEMAPHORES == 0) - /* - CMSIS-RTOS2 Memory Pool functions use FreeRTOS function xSemaphoreCreateCounting - to implement memory pools. In case if these functions are not used in the application image, - compiler will optimize them away. - Set #define configUSE_COUNTING_SEMAPHORES 1 to fix this error. - */ - #error "Definition configUSE_COUNTING_SEMAPHORES must equal 1 to implement Memory Pool API." -#endif -#if (configUSE_TASK_NOTIFICATIONS == 0) - /* - CMSIS-RTOS2 Thread Flags API functions use FreeRTOS Task Notification functions to implement - thread flag management. In case if these functions are not used in the application image, - compiler will optimize them away. - Set #define configUSE_TASK_NOTIFICATIONS 1 to fix this error. - - Alternatively, if the application does not use thread flags functions they can be - excluded from the image code by setting: - #define configUSE_OS2_THREAD_FLAGS 0 (in FreeRTOSConfig.h) - */ - #if (configUSE_OS2_THREAD_FLAGS == 1) - #error "Definition configUSE_TASK_NOTIFICATIONS must equal 1 to implement Thread Flags API." - #endif -#endif - -#if (configUSE_TRACE_FACILITY == 0) - /* - CMSIS-RTOS2 function furi_thread_enumerate requires FreeRTOS function uxTaskGetSystemState - which is only enabled if configUSE_TRACE_FACILITY == 1. - Set #define configUSE_TRACE_FACILITY 1 to fix this error. - - Alternatively, if the application does not use furi_thread_enumerate it can be - excluded from the image code by setting: - #define configUSE_OS2_THREAD_ENUMERATE 0 (in FreeRTOSConfig.h) - */ - #if (configUSE_OS2_THREAD_ENUMERATE == 1) - #error "Definition configUSE_TRACE_FACILITY must equal 1 to implement furi_thread_enumerate." - #endif -#endif - -#if (configUSE_16_BIT_TICKS == 1) - /* - CMSIS-RTOS2 wrapper for FreeRTOS relies on 32-bit tick timer which is also optimal on - a 32-bit CPU architectures. - Set #define configUSE_16_BIT_TICKS 0 to fix this error. - */ - #error "Definition configUSE_16_BIT_TICKS must be zero to implement CMSIS-RTOS2 API." -#endif - -#endif /* FREERTOS_OS2_H_ */ diff --git a/lib/ST25RFAL002/platform.c b/lib/ST25RFAL002/platform.c index 1facfa2ad..af9dc6ff7 100644 --- a/lib/ST25RFAL002/platform.c +++ b/lib/ST25RFAL002/platform.c @@ -26,7 +26,7 @@ int32_t rfal_platform_irq_thread(void* context) { UNUSED(context); while(1) { - uint32_t flags = furi_thread_flags_wait(0x1, osFlagsWaitAny, osWaitForever); + uint32_t flags = furi_thread_flags_wait(0x1, FuriFlagWaitAny, FuriWaitForever); if(flags & 0x1) { rfal_platform.callback(); } diff --git a/lib/ST25RFAL002/platform.h b/lib/ST25RFAL002/platform.h index 832e034ec..d86bba73e 100644 --- a/lib/ST25RFAL002/platform.h +++ b/lib/ST25RFAL002/platform.h @@ -4,7 +4,6 @@ #include #include #include -#include #include "timer.h" #include "math.h" #include @@ -104,10 +103,9 @@ void rfal_platform_spi_release(); timerCalculateTimer(t) /*!< Create a timer with the given time (ms) */ #define platformTimerIsExpired(timer) \ timerIsExpired(timer) /*!< Checks if the given timer is expired */ -#define platformDelay(t) osDelay(t) /*!< Performs a delay for the given time (ms) */ +#define platformDelay(t) furi_delay_ms(t) /*!< Performs a delay for the given time (ms) */ -#define platformGetSysTick() \ - osKernelGetTickCount() /*!< Get System Tick (1 tick = 1 ms) */ +#define platformGetSysTick() furi_get_tick() /*!< Get System Tick (1 tick = 1 ms) */ #define platformAssert(exp) assert_param(exp) /*!< Asserts whether the given expression is true*/ diff --git a/lib/ST25RFAL002/timer.c b/lib/ST25RFAL002/timer.c index b7fe1c284..ea0678a60 100644 --- a/lib/ST25RFAL002/timer.c +++ b/lib/ST25RFAL002/timer.c @@ -41,7 +41,7 @@ ****************************************************************************** */ #include "timer.h" -#include +#include /* ****************************************************************************** @@ -65,7 +65,7 @@ static uint32_t timerStopwatchTick; /*******************************************************************************/ uint32_t timerCalculateTimer(uint16_t time) { - return (furi_hal_get_tick() + time); + return (furi_get_tick() + time); } /*******************************************************************************/ @@ -73,7 +73,7 @@ bool timerIsExpired(uint32_t timer) { uint32_t uDiff; int32_t sDiff; - uDiff = (timer - furi_hal_get_tick()); /* Calculate the diff between the timers */ + uDiff = (timer - furi_get_tick()); /* Calculate the diff between the timers */ sDiff = uDiff; /* Convert the diff to a signed var */ /* Check if the given timer has expired already */ @@ -96,10 +96,10 @@ void timerDelay(uint16_t tOut) { /*******************************************************************************/ void timerStopwatchStart(void) { - timerStopwatchTick = furi_hal_get_tick(); + timerStopwatchTick = furi_get_tick(); } /*******************************************************************************/ uint32_t timerStopwatchMeasure(void) { - return (uint32_t)(furi_hal_get_tick() - timerStopwatchTick); + return (uint32_t)(furi_get_tick() - timerStopwatchTick); } diff --git a/lib/app-scened-template/record_controller.hpp b/lib/app-scened-template/record_controller.hpp index 9dfa96573..9b14274a8 100644 --- a/lib/app-scened-template/record_controller.hpp +++ b/lib/app-scened-template/record_controller.hpp @@ -1,5 +1,5 @@ #pragma once -#include +#include /** * @brief Class for opening, casting, holding and closing records diff --git a/lib/app-scened-template/view_controller.hpp b/lib/app-scened-template/view_controller.hpp index e74673d85..d08751c58 100644 --- a/lib/app-scened-template/view_controller.hpp +++ b/lib/app-scened-template/view_controller.hpp @@ -1,7 +1,7 @@ #pragma once #include "view_modules/generic_view_module.h" #include -#include +#include #include #include #include "typeindex_no_rtti.hpp" @@ -15,7 +15,7 @@ template class ViewController { public: ViewController() { - event_queue = osMessageQueueNew(10, sizeof(typename TApp::Event), NULL); + event_queue = furi_message_queue_alloc(10, sizeof(typename TApp::Event)); view_dispatcher = view_dispatcher_alloc(); previous_view_callback_pointer = cbc::obtain_connector( @@ -36,7 +36,7 @@ public: } view_dispatcher_free(view_dispatcher); - osMessageQueueDelete(event_queue); + furi_message_queue_free(event_queue); } /** @@ -81,7 +81,7 @@ public: * @param event event pointer */ void receive_event(typename TApp::Event* event) { - if(osMessageQueueGet(event_queue, event, NULL, 100) != osOK) { + if(furi_message_queue_get(event_queue, event, 100) != FuriStatusOk) { event->type = TApp::EventType::Tick; } } @@ -92,8 +92,8 @@ public: * @param event event pointer */ void send_event(typename TApp::Event* event) { - osStatus_t result = osMessageQueuePut(event_queue, event, 0, osWaitForever); - furi_check(result == osOK); + FuriStatus result = furi_message_queue_put(event_queue, event, FuriWaitForever); + furi_check(result == FuriStatusOk); } private: @@ -107,7 +107,7 @@ private: * @brief App event queue * */ - osMessageQueueId_t event_queue; + FuriMessageQueue* event_queue; /** * @brief Main ViewDispatcher pointer diff --git a/lib/drivers/bq27220.c b/lib/drivers/bq27220.c index 18f3f028d..f64120fa8 100644 --- a/lib/drivers/bq27220.c +++ b/lib/drivers/bq27220.c @@ -1,8 +1,7 @@ #include "bq27220.h" #include "bq27220_reg.h" -#include -#include +#include #include #define TAG "Gauge" @@ -42,7 +41,7 @@ bool bq27220_set_parameter_u16(FuriHalI2cBusHandle* handle, uint16_t address, ui ret = furi_hal_i2c_write_mem( handle, BQ27220_ADDRESS, CommandSelectSubclass, buffer, 4, BQ27220_I2C_TIMEOUT); - furi_hal_delay_us(10000); + furi_delay_us(10000); uint8_t checksum = bq27220_get_checksum(buffer, 4); buffer[0] = checksum; @@ -50,7 +49,7 @@ bool bq27220_set_parameter_u16(FuriHalI2cBusHandle* handle, uint16_t address, ui ret &= furi_hal_i2c_write_mem( handle, BQ27220_ADDRESS, CommandMACDataSum, buffer, 2, BQ27220_I2C_TIMEOUT); - furi_hal_delay_us(10000); + furi_delay_us(10000); return ret; } @@ -96,7 +95,7 @@ bool bq27220_init(FuriHalI2cBusHandle* handle, const ParamCEDV* cedv) { bq27220_set_parameter_u16(handle, AddressEDV2, cedv->EDV2); bq27220_control(handle, Control_EXIT_CFG_UPDATE_REINIT); - furi_hal_delay_us(10000); + furi_delay_us(10000); design_cap = bq27220_get_design_capacity(handle); if(cedv->design_cap == design_cap) { FURI_LOG_I(TAG, "Battery profile update success"); diff --git a/lib/drivers/cc1101.c b/lib/drivers/cc1101.c index a0c9d44ab..f28165e89 100644 --- a/lib/drivers/cc1101.c +++ b/lib/drivers/cc1101.c @@ -1,6 +1,4 @@ #include "cc1101.h" -#include -#include #include #include diff --git a/lib/drivers/lp5562.c b/lib/drivers/lp5562.c index 7eef2a83c..f5d765fa9 100644 --- a/lib/drivers/lp5562.c +++ b/lib/drivers/lp5562.c @@ -1,5 +1,5 @@ #include "lp5562.h" -#include "furi/common_defines.h" +#include #include "lp5562_reg.h" #include @@ -27,7 +27,7 @@ void lp5562_enable(FuriHalI2cBusHandle* handle) { Reg00_Enable reg = {.CHIP_EN = true, .LOG_EN = true}; furi_hal_i2c_write_reg_8(handle, LP5562_ADDRESS, 0x00, *(uint8_t*)®, LP5562_I2C_TIMEOUT); //>488μs delay is required after writing to 0x00 register, otherwise program engine will not work - furi_hal_delay_us(500); + furi_delay_us(500); } void lp5562_set_channel_current(FuriHalI2cBusHandle* handle, LP5562Channel channel, uint8_t value) { @@ -127,7 +127,7 @@ void lp5562_execute_program( reg_val &= ~(0x3 << bit_offset); reg_val |= (0x01 << bit_offset); // load furi_hal_i2c_write_reg_8(handle, LP5562_ADDRESS, 0x01, reg_val, LP5562_I2C_TIMEOUT); - furi_hal_delay_us(100); + furi_delay_us(100); // Program load for(uint8_t i = 0; i < 16; i++) { diff --git a/lib/flipper_format/flipper_format.c b/lib/flipper_format/flipper_format.c index df848ead3..846129cde 100644 --- a/lib/flipper_format/flipper_format.c +++ b/lib/flipper_format/flipper_format.c @@ -1,4 +1,4 @@ -#include +#include #include #include #include diff --git a/lib/flipper_format/flipper_format_stream.c b/lib/flipper_format/flipper_format_stream.c index 5c2105361..81189b69b 100644 --- a/lib/flipper_format/flipper_format_stream.c +++ b/lib/flipper_format/flipper_format_stream.c @@ -1,6 +1,6 @@ #include #include -#include +#include #include "flipper_format_stream.h" #include "flipper_format_stream_i.h" diff --git a/lib/freertos.scons b/lib/freertos.scons index 992c4f873..1c5a5bf54 100644 --- a/lib/freertos.scons +++ b/lib/freertos.scons @@ -20,7 +20,6 @@ libenv.ApplyLibFlags() sources = libenv.Glob("FreeRTOS-Kernel/*.c", source=True) sources += [ "FreeRTOS-Kernel/portable/GCC/ARM_CM4F/port.c", - "FreeRTOS-glue/cmsis_os2.c", ] lib = libenv.StaticLibrary("${FW_LIB_NAME}", sources) diff --git a/lib/infrared/encoder_decoder/common/infrared_common_decoder.c b/lib/infrared/encoder_decoder/common/infrared_common_decoder.c index 1d9442856..bff4c73db 100644 --- a/lib/infrared/encoder_decoder/common/infrared_common_decoder.c +++ b/lib/infrared/encoder_decoder/common/infrared_common_decoder.c @@ -1,5 +1,5 @@ -#include "furi/check.h" -#include "furi/common_defines.h" +#include +#include #include "infrared.h" #include "infrared_common_i.h" #include diff --git a/lib/infrared/encoder_decoder/common/infrared_common_encoder.c b/lib/infrared/encoder_decoder/common/infrared_common_encoder.c index f755222d1..dcf63acc8 100644 --- a/lib/infrared/encoder_decoder/common/infrared_common_encoder.c +++ b/lib/infrared/encoder_decoder/common/infrared_common_encoder.c @@ -1,4 +1,4 @@ -#include "furi/check.h" +#include #include "infrared.h" #include "infrared_common_i.h" #include diff --git a/lib/infrared/encoder_decoder/infrared.c b/lib/infrared/encoder_decoder/infrared.c index 59b11d5ce..71bd6bb6d 100644 --- a/lib/infrared/encoder_decoder/infrared.c +++ b/lib/infrared/encoder_decoder/infrared.c @@ -1,5 +1,5 @@ #include "infrared.h" -#include "furi/check.h" +#include #include "common/infrared_common_i.h" #include "infrared_protocol_defs_i.h" #include diff --git a/lib/infrared/encoder_decoder/nec/infrared_encoder_nec.c b/lib/infrared/encoder_decoder/nec/infrared_encoder_nec.c index e1afae7b9..d0039c330 100644 --- a/lib/infrared/encoder_decoder/nec/infrared_encoder_nec.c +++ b/lib/infrared/encoder_decoder/nec/infrared_encoder_nec.c @@ -1,4 +1,4 @@ -#include "furi/check.h" +#include #include "infrared.h" #include "common/infrared_common_i.h" #include diff --git a/lib/infrared/encoder_decoder/rc5/infrared_encoder_rc5.c b/lib/infrared/encoder_decoder/rc5/infrared_encoder_rc5.c index f063f7e54..7b55cdc44 100644 --- a/lib/infrared/encoder_decoder/rc5/infrared_encoder_rc5.c +++ b/lib/infrared/encoder_decoder/rc5/infrared_encoder_rc5.c @@ -1,4 +1,4 @@ -#include "furi/memmgr.h" +#include #include "infrared.h" #include "common/infrared_common_i.h" #include "infrared_protocol_defs_i.h" diff --git a/lib/infrared/encoder_decoder/rc6/infrared_encoder_rc6.c b/lib/infrared/encoder_decoder/rc6/infrared_encoder_rc6.c index 7d8ff9756..f1240b17a 100644 --- a/lib/infrared/encoder_decoder/rc6/infrared_encoder_rc6.c +++ b/lib/infrared/encoder_decoder/rc6/infrared_encoder_rc6.c @@ -1,4 +1,4 @@ -#include "furi/memmgr.h" +#include #include "infrared.h" #include "common/infrared_common_i.h" #include "infrared_protocol_defs_i.h" diff --git a/lib/infrared/encoder_decoder/samsung/infrared_encoder_samsung.c b/lib/infrared/encoder_decoder/samsung/infrared_encoder_samsung.c index 88745ff5c..75b037f00 100644 --- a/lib/infrared/encoder_decoder/samsung/infrared_encoder_samsung.c +++ b/lib/infrared/encoder_decoder/samsung/infrared_encoder_samsung.c @@ -1,4 +1,4 @@ -#include "furi/check.h" +#include #include "common/infrared_common_i.h" #include #include "../infrared_i.h" diff --git a/lib/infrared/encoder_decoder/sirc/infrared_encoder_sirc.c b/lib/infrared/encoder_decoder/sirc/infrared_encoder_sirc.c index 8ae9e3717..2c2bda1af 100644 --- a/lib/infrared/encoder_decoder/sirc/infrared_encoder_sirc.c +++ b/lib/infrared/encoder_decoder/sirc/infrared_encoder_sirc.c @@ -1,4 +1,4 @@ -#include "furi/check.h" +#include #include "infrared.h" #include "common/infrared_common_i.h" #include diff --git a/lib/infrared/worker/infrared_transmit.c b/lib/infrared/worker/infrared_transmit.c index d4c87ce58..695be8d1f 100644 --- a/lib/infrared/worker/infrared_transmit.c +++ b/lib/infrared/worker/infrared_transmit.c @@ -4,7 +4,6 @@ #include #include #include -#include static uint32_t infrared_tx_number_of_transmissions = 0; static uint32_t infrared_tx_raw_timings_index = 0; diff --git a/lib/infrared/worker/infrared_worker.c b/lib/infrared/worker/infrared_worker.c index b24b7480a..becd8d882 100644 --- a/lib/infrared/worker/infrared_worker.c +++ b/lib/infrared/worker/infrared_worker.c @@ -1,5 +1,5 @@ -#include "furi/check.h" -#include "furi/common_defines.h" +#include +#include #include "sys/_stdint.h" #include "infrared_worker.h" #include @@ -167,7 +167,7 @@ static int32_t infrared_worker_rx_thread(void* thread_context) { TickType_t last_blink_time = 0; while(1) { - events = furi_thread_flags_wait(INFRARED_WORKER_ALL_RX_EVENTS, 0, osWaitForever); + events = furi_thread_flags_wait(INFRARED_WORKER_ALL_RX_EVENTS, 0, FuriWaitForever); furi_check(events & INFRARED_WORKER_ALL_RX_EVENTS); /* at least one caught */ if(events & INFRARED_WORKER_RX_RECEIVED) { @@ -506,7 +506,7 @@ static int32_t infrared_worker_tx_thread(void* thread_context) { break; case InfraredWorkerStateRunTx: - events = furi_thread_flags_wait(INFRARED_WORKER_ALL_TX_EVENTS, 0, osWaitForever); + events = furi_thread_flags_wait(INFRARED_WORKER_ALL_TX_EVENTS, 0, FuriWaitForever); furi_check(events & INFRARED_WORKER_ALL_TX_EVENTS); /* at least one caught */ if(events & INFRARED_WORKER_EXIT) { diff --git a/lib/nfc_protocols/emv.c b/lib/nfc_protocols/emv.c index b69675fdd..935c9f630 100644 --- a/lib/nfc_protocols/emv.c +++ b/lib/nfc_protocols/emv.c @@ -1,6 +1,6 @@ #include "emv.h" -#include +#include #define TAG "Emv" diff --git a/lib/one_wire/ibutton/encoder/encoder_cyfral.c b/lib/one_wire/ibutton/encoder/encoder_cyfral.c index f6cbe6301..0b506b2b0 100644 --- a/lib/one_wire/ibutton/encoder/encoder_cyfral.c +++ b/lib/one_wire/ibutton/encoder/encoder_cyfral.c @@ -2,7 +2,7 @@ #include #define CYFRAL_DATA_SIZE sizeof(uint16_t) -#define CYFRAL_PERIOD (125 * furi_hal_delay_instructions_per_microsecond()) +#define CYFRAL_PERIOD (125 * furi_hal_cortex_instructions_per_microsecond()) #define CYFRAL_0_LOW (CYFRAL_PERIOD * 0.66f) #define CYFRAL_0_HI (CYFRAL_PERIOD * 0.33f) #define CYFRAL_1_LOW (CYFRAL_PERIOD * 0.33f) diff --git a/lib/one_wire/ibutton/encoder/encoder_metakom.c b/lib/one_wire/ibutton/encoder/encoder_metakom.c index 3b597e7cb..5b978ebe2 100644 --- a/lib/one_wire/ibutton/encoder/encoder_metakom.c +++ b/lib/one_wire/ibutton/encoder/encoder_metakom.c @@ -2,7 +2,7 @@ #include #define METAKOM_DATA_SIZE sizeof(uint32_t) -#define METAKOM_PERIOD (125 * furi_hal_delay_instructions_per_microsecond()) +#define METAKOM_PERIOD (125 * furi_hal_cortex_instructions_per_microsecond()) #define METAKOM_0_LOW (METAKOM_PERIOD * 0.33f) #define METAKOM_0_HI (METAKOM_PERIOD * 0.66f) #define METAKOM_1_LOW (METAKOM_PERIOD * 0.66f) diff --git a/lib/one_wire/ibutton/ibutton_worker.c b/lib/one_wire/ibutton/ibutton_worker.c index 82c3d6886..755ed32f3 100644 --- a/lib/one_wire/ibutton/ibutton_worker.c +++ b/lib/one_wire/ibutton/ibutton_worker.c @@ -32,7 +32,7 @@ iButtonWorker* ibutton_worker_alloc() { worker->pulse_decoder = pulse_decoder_alloc(); worker->protocol_cyfral = protocol_cyfral_alloc(); worker->protocol_metakom = protocol_metakom_alloc(); - worker->messages = osMessageQueueNew(1, sizeof(iButtonMessage), NULL); + worker->messages = furi_message_queue_alloc(1, sizeof(iButtonMessage)); worker->mode_index = iButtonWorkerIdle; worker->last_dwt_value = 0; worker->read_cb = NULL; @@ -90,22 +90,26 @@ void ibutton_worker_emulate_set_callback( void ibutton_worker_read_start(iButtonWorker* worker, iButtonKey* key) { iButtonMessage message = {.type = iButtonMessageRead, .data.key = key}; - furi_check(osMessageQueuePut(worker->messages, &message, 0, osWaitForever) == osOK); + furi_check( + furi_message_queue_put(worker->messages, &message, FuriWaitForever) == FuriStatusOk); } void ibutton_worker_write_start(iButtonWorker* worker, iButtonKey* key) { iButtonMessage message = {.type = iButtonMessageWrite, .data.key = key}; - furi_check(osMessageQueuePut(worker->messages, &message, 0, osWaitForever) == osOK); + furi_check( + furi_message_queue_put(worker->messages, &message, FuriWaitForever) == FuriStatusOk); } void ibutton_worker_emulate_start(iButtonWorker* worker, iButtonKey* key) { iButtonMessage message = {.type = iButtonMessageEmulate, .data.key = key}; - furi_check(osMessageQueuePut(worker->messages, &message, 0, osWaitForever) == osOK); + furi_check( + furi_message_queue_put(worker->messages, &message, FuriWaitForever) == FuriStatusOk); } void ibutton_worker_stop(iButtonWorker* worker) { iButtonMessage message = {.type = iButtonMessageStop}; - furi_check(osMessageQueuePut(worker->messages, &message, 0, osWaitForever) == osOK); + furi_check( + furi_message_queue_put(worker->messages, &message, FuriWaitForever) == FuriStatusOk); } void ibutton_worker_free(iButtonWorker* worker) { @@ -123,7 +127,7 @@ void ibutton_worker_free(iButtonWorker* worker) { encoder_cyfral_free(worker->encoder_cyfral); encoder_metakom_free(worker->encoder_metakom); - osMessageQueueDelete(worker->messages); + furi_message_queue_free(worker->messages); furi_thread_free(worker->thread); free(worker->key_data); @@ -136,7 +140,8 @@ void ibutton_worker_start_thread(iButtonWorker* worker) { void ibutton_worker_stop_thread(iButtonWorker* worker) { iButtonMessage message = {.type = iButtonMessageEnd}; - furi_check(osMessageQueuePut(worker->messages, &message, 0, osWaitForever) == osOK); + furi_check( + furi_message_queue_put(worker->messages, &message, FuriWaitForever) == FuriStatusOk); furi_thread_join(worker->thread); } @@ -148,7 +153,7 @@ void ibutton_worker_switch_mode(iButtonWorker* worker, iButtonWorkerMode mode) { void ibutton_worker_notify_emulate(iButtonWorker* worker) { iButtonMessage message = {.type = iButtonMessageNotifyEmulate}; - furi_check(osMessageQueuePut(worker->messages, &message, 0, 0) == osOK); + furi_check(furi_message_queue_put(worker->messages, &message, 0) == FuriStatusOk); } void ibutton_worker_set_key_p(iButtonWorker* worker, iButtonKey* key) { @@ -159,14 +164,14 @@ static int32_t ibutton_worker_thread(void* thread_context) { iButtonWorker* worker = thread_context; bool running = true; iButtonMessage message; - osStatus_t status; + FuriStatus status; ibutton_worker_modes[worker->mode_index].start(worker); while(running) { - status = osMessageQueueGet( - worker->messages, &message, NULL, ibutton_worker_modes[worker->mode_index].quant); - if(status == osOK) { + status = furi_message_queue_get( + worker->messages, &message, ibutton_worker_modes[worker->mode_index].quant); + if(status == FuriStatusOk) { switch(message.type) { case iButtonMessageEnd: ibutton_worker_switch_mode(worker, iButtonWorkerIdle); @@ -195,7 +200,7 @@ static int32_t ibutton_worker_thread(void* thread_context) { } break; } - } else if(status == osErrorTimeout) { + } else if(status == FuriStatusErrorTimeout) { ibutton_worker_modes[worker->mode_index].tick(worker); } else { furi_crash("iButton worker error"); diff --git a/lib/one_wire/ibutton/ibutton_worker_i.h b/lib/one_wire/ibutton/ibutton_worker_i.h index 48d03595f..285884439 100644 --- a/lib/one_wire/ibutton/ibutton_worker_i.h +++ b/lib/one_wire/ibutton/ibutton_worker_i.h @@ -52,7 +52,7 @@ struct iButtonWorker { OneWireDevice* device; iButtonWriter* writer; iButtonWorkerMode mode_index; - osMessageQueueId_t messages; + FuriMessageQueue* messages; FuriThread* thread; PulseDecoder* pulse_decoder; diff --git a/lib/one_wire/ibutton/ibutton_worker_modes.c b/lib/one_wire/ibutton/ibutton_worker_modes.c index 5ee768623..78e05d0ee 100644 --- a/lib/one_wire/ibutton/ibutton_worker_modes.c +++ b/lib/one_wire/ibutton/ibutton_worker_modes.c @@ -21,7 +21,7 @@ void ibutton_worker_mode_write_stop(iButtonWorker* worker); const iButtonWorkerModeType ibutton_worker_modes[] = { { - .quant = osWaitForever, + .quant = FuriWaitForever, .start = ibutton_worker_mode_idle_start, .tick = ibutton_worker_mode_idle_tick, .stop = ibutton_worker_mode_idle_stop, @@ -86,7 +86,7 @@ bool ibutton_worker_read_comparator(iButtonWorker* worker) { furi_hal_rfid_comp_start(); // TODO: rework with thread events, "pulse_decoder_get_decoded_index_with_timeout" - furi_hal_delay_ms(100); + furi_delay_ms(100); int32_t decoded_index = pulse_decoder_get_decoded_index(worker->pulse_decoder); if(decoded_index >= 0) { pulse_decoder_get_data( @@ -121,7 +121,7 @@ bool ibutton_worker_read_comparator(iButtonWorker* worker) { bool ibutton_worker_read_dallas(iButtonWorker* worker) { bool result = false; onewire_host_start(worker->host); - furi_hal_delay_ms(100); + furi_delay_ms(100); FURI_CRITICAL_ENTER(); if(onewire_host_search(worker->host, worker->key_data, NORMAL_SEARCH)) { onewire_host_reset_search(worker->host); diff --git a/lib/one_wire/ibutton/ibutton_writer.c b/lib/one_wire/ibutton/ibutton_writer.c index fe19db711..203c4fc07 100644 --- a/lib/one_wire/ibutton/ibutton_writer.c +++ b/lib/one_wire/ibutton/ibutton_writer.c @@ -11,13 +11,13 @@ struct iButtonWriter { static void writer_write_one_bit(iButtonWriter* writer, bool value, uint32_t delay) { onewire_host_write_bit(writer->host, value); - furi_hal_delay_us(delay); + furi_delay_us(delay); } static void writer_write_byte_ds1990(iButtonWriter* writer, uint8_t data) { for(uint8_t n_bit = 0; n_bit < 8; n_bit++) { onewire_host_write_bit(writer->host, data & 1); - furi_hal_delay_us(5000); + furi_delay_us(5000); data = data >> 1; } } @@ -68,7 +68,7 @@ static bool writer_write_TM2004(iButtonWriter* writer, iButtonKey* key) { // TODO: check answer CRC // pulse indicating that data is correct - furi_hal_delay_us(600); + furi_delay_us(600); writer_write_one_bit(writer, 1, 50000); // read written key byte @@ -104,7 +104,7 @@ static bool writer_write_1990_1(iButtonWriter* writer, iButtonKey* key) { // unlock onewire_host_reset(writer->host); onewire_host_write(writer->host, RW1990_1_CMD_WRITE_RECORD_FLAG); - furi_hal_delay_us(10); + furi_delay_us(10); writer_write_one_bit(writer, 0, 5000); // write key @@ -113,7 +113,7 @@ static bool writer_write_1990_1(iButtonWriter* writer, iButtonKey* key) { for(uint8_t i = 0; i < ibutton_key_get_data_size(key); i++) { // inverted key for RW1990.1 writer_write_byte_ds1990(writer, ~ibutton_key_get_data_p(key)[i]); - furi_hal_delay_us(30000); + furi_delay_us(30000); } // lock @@ -139,7 +139,7 @@ static bool writer_write_1990_2(iButtonWriter* writer, iButtonKey* key) { // unlock onewire_host_reset(writer->host); onewire_host_write(writer->host, RW1990_2_CMD_WRITE_RECORD_FLAG); - furi_hal_delay_us(10); + furi_delay_us(10); writer_write_one_bit(writer, 1, 5000); // write key @@ -147,7 +147,7 @@ static bool writer_write_1990_2(iButtonWriter* writer, iButtonKey* key) { onewire_host_write(writer->host, RW1990_2_CMD_WRITE_ROM); for(uint8_t i = 0; i < ibutton_key_get_data_size(key); i++) { writer_write_byte_ds1990(writer, ibutton_key_get_data_p(key)[i]); - furi_hal_delay_us(30000); + furi_delay_us(30000); } // lock @@ -191,7 +191,7 @@ static bool writer_write_TM01( //} else { for(uint8_t i = 0; i < key->get_type_data_size(); i++) { write_byte_ds1990(key->get_data()[i]); - furi_hal_delay_us(10000); + furi_delay_us(10000); } //} @@ -271,9 +271,9 @@ void ibutton_writer_free(iButtonWriter* writer) { iButtonWriterResult ibutton_writer_write(iButtonWriter* writer, iButtonKey* key) { iButtonWriterResult result = iButtonWriterNoDetect; - osKernelLock(); + furi_kernel_lock(); bool blank_present = onewire_host_reset(writer->host); - osKernelUnlock(); + furi_kernel_unlock(); if(blank_present) { switch(ibutton_key_get_type(key)) { diff --git a/lib/one_wire/ibutton/pulse_protocols/protocol_cyfral.c b/lib/one_wire/ibutton/pulse_protocols/protocol_cyfral.c index a992f00d7..7c2897907 100644 --- a/lib/one_wire/ibutton/pulse_protocols/protocol_cyfral.c +++ b/lib/one_wire/ibutton/pulse_protocols/protocol_cyfral.c @@ -1,8 +1,8 @@ #include "protocol_cyfral.h" #include #include -#include -#include +#include +#include #define CYFRAL_DATA_SIZE 2 #define CYFRAL_MAX_PERIOD_US 230 @@ -104,7 +104,7 @@ static void cyfral_reset(void* context) { cyfral->nibble = 0; cyfral->data_valid = true; - cyfral->max_period = CYFRAL_MAX_PERIOD_US * furi_hal_delay_instructions_per_microsecond(); + cyfral->max_period = CYFRAL_MAX_PERIOD_US * furi_hal_cortex_instructions_per_microsecond(); } static bool cyfral_process_bit( diff --git a/lib/one_wire/ibutton/pulse_protocols/protocol_metakom.c b/lib/one_wire/ibutton/pulse_protocols/protocol_metakom.c index d76ef886d..9df9e20be 100644 --- a/lib/one_wire/ibutton/pulse_protocols/protocol_metakom.c +++ b/lib/one_wire/ibutton/pulse_protocols/protocol_metakom.c @@ -1,8 +1,7 @@ #include "protocol_metakom.h" #include #include -#include -#include +#include #define METAKOM_DATA_SIZE 4 #define METAKOM_PERIOD_SAMPLE_COUNT 10 diff --git a/lib/one_wire/one_wire_host.c b/lib/one_wire/one_wire_host.c index 1bb0a1ccb..654b9e45d 100644 --- a/lib/one_wire/one_wire_host.c +++ b/lib/one_wire/one_wire_host.c @@ -31,23 +31,23 @@ bool onewire_host_reset(OneWireHost* host) { furi_hal_ibutton_pin_high(); do { if(--retries == 0) return 0; - furi_hal_delay_us(2); + furi_delay_us(2); } while(!furi_hal_ibutton_pin_get_level()); // pre delay - furi_hal_delay_us(OWH_RESET_DELAY_PRE); + furi_delay_us(OWH_RESET_DELAY_PRE); // drive low furi_hal_ibutton_pin_low(); - furi_hal_delay_us(OWH_RESET_DRIVE); + furi_delay_us(OWH_RESET_DRIVE); // release furi_hal_ibutton_pin_high(); - furi_hal_delay_us(OWH_RESET_RELEASE); + furi_delay_us(OWH_RESET_RELEASE); // read and post delay r = !furi_hal_ibutton_pin_get_level(); - furi_hal_delay_us(OWH_RESET_DELAY_POST); + furi_delay_us(OWH_RESET_DELAY_POST); return r; } @@ -58,15 +58,15 @@ bool onewire_host_read_bit(OneWireHost* host) { // drive low furi_hal_ibutton_pin_low(); - furi_hal_delay_us(OWH_READ_DRIVE); + furi_delay_us(OWH_READ_DRIVE); // release furi_hal_ibutton_pin_high(); - furi_hal_delay_us(OWH_READ_RELEASE); + furi_delay_us(OWH_READ_RELEASE); // read and post delay result = furi_hal_ibutton_pin_get_level(); - furi_hal_delay_us(OWH_READ_DELAY_POST); + furi_delay_us(OWH_READ_DELAY_POST); return result; } @@ -94,19 +94,19 @@ void onewire_host_write_bit(OneWireHost* host, bool value) { if(value) { // drive low furi_hal_ibutton_pin_low(); - furi_hal_delay_us(OWH_WRITE_1_DRIVE); + furi_delay_us(OWH_WRITE_1_DRIVE); // release furi_hal_ibutton_pin_high(); - furi_hal_delay_us(OWH_WRITE_1_RELEASE); + furi_delay_us(OWH_WRITE_1_RELEASE); } else { // drive low furi_hal_ibutton_pin_low(); - furi_hal_delay_us(OWH_WRITE_0_DRIVE); + furi_delay_us(OWH_WRITE_0_DRIVE); // release furi_hal_ibutton_pin_high(); - furi_hal_delay_us(OWH_WRITE_0_RELEASE); + furi_delay_us(OWH_WRITE_0_RELEASE); } } diff --git a/lib/one_wire/one_wire_slave.c b/lib/one_wire/one_wire_slave.c index 1f3896235..af04cfdab 100644 --- a/lib/one_wire/one_wire_slave.c +++ b/lib/one_wire/one_wire_slave.c @@ -2,8 +2,7 @@ #include "one_wire_slave_i.h" #include "one_wire_device.h" #include -#include -#include +#include #define OWS_RESET_MIN 270 #define OWS_RESET_MAX 960 @@ -39,14 +38,14 @@ struct OneWireSlave { uint32_t onewire_slave_wait_while_gpio_is(OneWireSlave* bus, uint32_t time, const bool pin_value) { UNUSED(bus); uint32_t start = DWT->CYCCNT; - uint32_t time_ticks = time * furi_hal_delay_instructions_per_microsecond(); + uint32_t time_ticks = time * furi_hal_cortex_instructions_per_microsecond(); uint32_t time_captured; do { time_captured = DWT->CYCCNT; if(furi_hal_ibutton_pin_get_level() != pin_value) { uint32_t remaining_time = time_ticks - (time_captured - start); - remaining_time /= furi_hal_delay_instructions_per_microsecond(); + remaining_time /= furi_hal_cortex_instructions_per_microsecond(); return remaining_time; } } while((time_captured - start) < time_ticks); @@ -60,7 +59,7 @@ bool onewire_slave_show_presence(OneWireSlave* bus) { // show presence furi_hal_ibutton_pin_low(); - furi_hal_delay_us(OWS_PRESENCE_MIN); + furi_delay_us(OWS_PRESENCE_MIN); furi_hal_ibutton_pin_high(); // somebody also can show presence @@ -127,7 +126,7 @@ bool onewire_slave_send_bit(OneWireSlave* bus, bool value) { } // hold line for ZERO or ONE time - furi_hal_delay_us(time); + furi_delay_us(time); furi_hal_ibutton_pin_high(); return true; @@ -213,7 +212,7 @@ static void exti_cb(void* context) { if(input_state) { uint32_t pulse_length = - (DWT->CYCCNT - pulse_start) / furi_hal_delay_instructions_per_microsecond(); + (DWT->CYCCNT - pulse_start) / furi_hal_cortex_instructions_per_microsecond(); if(pulse_length >= OWS_RESET_MIN) { if(pulse_length <= OWS_RESET_MAX) { // reset cycle ok diff --git a/lib/one_wire/pulse_protocols/pulse_decoder.c b/lib/one_wire/pulse_protocols/pulse_decoder.c index e8197a08d..c7d3b09ec 100644 --- a/lib/one_wire/pulse_protocols/pulse_decoder.c +++ b/lib/one_wire/pulse_protocols/pulse_decoder.c @@ -1,7 +1,7 @@ #include #include "pulse_decoder.h" #include -#include +#include #define MAX_PROTOCOL 5 diff --git a/lib/subghz/blocks/encoder.c b/lib/subghz/blocks/encoder.c index 3cefc2c15..f3349b5fc 100644 --- a/lib/subghz/blocks/encoder.c +++ b/lib/subghz/blocks/encoder.c @@ -1,6 +1,6 @@ #include "encoder.h" #include "math.h" -#include +#include #define TAG "SubGhzBlockEncoder" @@ -42,4 +42,4 @@ size_t subghz_protocol_blocks_get_upload( upload[size_upload++] = level_duration_make( subghz_protocol_blocks_get_bit_array(data_array, index_bit - 1), duration); return size_upload; -} \ No newline at end of file +} diff --git a/lib/subghz/protocols/princeton_for_testing.c b/lib/subghz/protocols/princeton_for_testing.c index 5c3f7151c..43078d2e2 100644 --- a/lib/subghz/protocols/princeton_for_testing.c +++ b/lib/subghz/protocols/princeton_for_testing.c @@ -76,9 +76,8 @@ void subghz_encoder_princeton_for_testing_set( instance->count_key = instance->count_key_package + 3; - if((furi_hal_get_tick() - instance->time_stop) < instance->timeout) { - instance->time_stop = - (instance->timeout - (furi_hal_get_tick() - instance->time_stop)) * 1000; + if((furi_get_tick() - instance->time_stop) < instance->timeout) { + instance->time_stop = (instance->timeout - (furi_get_tick() - instance->time_stop)) * 1000; } else { instance->time_stop = 0; } diff --git a/lib/subghz/protocols/raw.c b/lib/subghz/protocols/raw.c index 516aa6338..ebc84c110 100644 --- a/lib/subghz/protocols/raw.c +++ b/lib/subghz/protocols/raw.c @@ -287,7 +287,7 @@ static bool subghz_protocol_encoder_raw_worker_init(SubGhzProtocolEncoderRAW* in if(subghz_file_encoder_worker_start( instance->file_worker_encoder, string_get_cstr(instance->file_name))) { //the worker needs a file in order to open and read part of the file - osDelay(100); + furi_delay_ms(100); instance->is_runing = true; } else { subghz_protocol_encoder_raw_stop(instance); diff --git a/lib/subghz/subghz_file_encoder_worker.c b/lib/subghz/subghz_file_encoder_worker.c index 0ec4c8616..457c8b02b 100644 --- a/lib/subghz/subghz_file_encoder_worker.c +++ b/lib/subghz/subghz_file_encoder_worker.c @@ -153,19 +153,19 @@ static int32_t subghz_file_encoder_worker_thread(void* context) { break; } } - osDelay(5); + furi_delay_ms(5); } //waiting for the end of the transfer FURI_LOG_I(TAG, "End read file"); while(!furi_hal_subghz_is_async_tx_complete() && instance->worker_running) { - osDelay(5); + furi_delay_ms(5); } FURI_LOG_I(TAG, "End transmission"); while(instance->worker_running) { if(instance->worker_stoping) { if(instance->callback_end) instance->callback_end(instance->context_end); } - osDelay(50); + furi_delay_ms(50); } flipper_format_file_close(instance->flipper_format); diff --git a/lib/subghz/subghz_tx_rx_worker.c b/lib/subghz/subghz_tx_rx_worker.c index 0f687f153..74a6183ce 100644 --- a/lib/subghz/subghz_tx_rx_worker.c +++ b/lib/subghz/subghz_tx_rx_worker.c @@ -68,11 +68,11 @@ bool subghz_tx_rx_worker_rx(SubGhzTxRxWorker* instance, uint8_t* data, uint8_t* if(instance->status != SubGhzTxRxWorkerStatusRx) { furi_hal_subghz_rx(); instance->status = SubGhzTxRxWorkerStatusRx; - osDelay(1); + furi_delay_tick(1); } //waiting for reception to complete while(furi_hal_gpio_read(&gpio_cc1101_g0)) { - osDelay(1); + furi_delay_tick(1); if(!--timeout) { FURI_LOG_W(TAG, "RX cc1101_g0 timeout"); furi_hal_subghz_flush_rx(); @@ -106,14 +106,14 @@ void subghz_tx_rx_worker_tx(SubGhzTxRxWorker* instance, uint8_t* data, size_t si furi_hal_subghz_tx(); //start send instance->status = SubGhzTxRxWorkerStatusTx; while(!furi_hal_gpio_read(&gpio_cc1101_g0)) { // Wait for GDO0 to be set -> sync transmitted - osDelay(1); + furi_delay_tick(1); if(!--timeout) { FURI_LOG_W(TAG, "TX !cc1101_g0 timeout"); break; } } while(furi_hal_gpio_read(&gpio_cc1101_g0)) { // Wait for GDO0 to be cleared -> end of packet - osDelay(1); + furi_delay_tick(1); if(!--timeout) { FURI_LOG_W(TAG, "TX cc1101_g0 timeout"); break; @@ -189,7 +189,7 @@ static int32_t subghz_tx_rx_worker_thread(void* context) { } if(timeout_tx) timeout_tx--; - osDelay(1); + furi_delay_tick(1); } furi_hal_subghz_set_path(FuriHalSubGhzPathIsolate); diff --git a/lib/toolbox/stream/stream.c b/lib/toolbox/stream/stream.c index 982c49836..088996f02 100644 --- a/lib/toolbox/stream/stream.c +++ b/lib/toolbox/stream/stream.c @@ -1,8 +1,8 @@ #include "stream.h" #include "stream_i.h" #include "file_stream.h" -#include -#include +#include +#include void stream_free(Stream* stream) { furi_assert(stream); diff --git a/lib/toolbox/stream/string_stream.c b/lib/toolbox/stream/string_stream.c index 3244b7ba8..f3e1364d1 100644 --- a/lib/toolbox/stream/string_stream.c +++ b/lib/toolbox/stream/string_stream.c @@ -1,7 +1,7 @@ #include "stream.h" #include "stream_i.h" #include "string_stream.h" -#include +#include typedef struct { Stream stream_base; diff --git a/lib/toolbox/tar/tar_archive.c b/lib/toolbox/tar/tar_archive.c index 91d2c8127..cc107530c 100644 --- a/lib/toolbox/tar/tar_archive.c +++ b/lib/toolbox/tar/tar_archive.c @@ -213,7 +213,7 @@ static int archive_extract_foreach_cb(mtar_t* tar, const mtar_header_t* header, } FURI_LOG_W(TAG, "Failed to open '%s', reties: %d", string_get_cstr(fname), n_tries); storage_file_close(out_file); - osDelay(FILE_OPEN_RETRY_DELAY); + furi_delay_ms(FILE_OPEN_RETRY_DELAY); } if(!storage_file_is_open(out_file)) { @@ -265,7 +265,7 @@ bool tar_archive_add_file( } FURI_LOG_W(TAG, "Failed to open '%s', reties: %d", fs_file_path, n_tries); storage_file_close(src_file); - osDelay(FILE_OPEN_RETRY_DELAY); + furi_delay_ms(FILE_OPEN_RETRY_DELAY); } if(!storage_file_is_open(src_file) || diff --git a/lib/u8g2/u8g2_glue.c b/lib/u8g2/u8g2_glue.c index 33d30f292..77f37f14c 100644 --- a/lib/u8g2/u8g2_glue.c +++ b/lib/u8g2/u8g2_glue.c @@ -10,10 +10,10 @@ uint8_t u8g2_gpio_and_delay_stm32(u8x8_t* u8x8, uint8_t msg, uint8_t arg_int, vo /* HAL initialization contains all what we need so we can skip this part. */ break; case U8X8_MSG_DELAY_MILLI: - furi_hal_delay_ms(arg_int); + furi_delay_ms(arg_int); break; case U8X8_MSG_DELAY_10MICRO: - furi_hal_delay_us(10); + furi_delay_us(10); break; case U8X8_MSG_DELAY_100NANO: asm("nop");