From 2a14888b802d1c5e4cfbe7b33a4b5bab421ad34c Mon Sep 17 00:00:00 2001 From: zxkmmOnHaseeWSL Date: Sat, 22 Apr 2023 22:46:04 +0800 Subject: [PATCH 01/11] fix last commit aka fileman refactor exception --- firmware/application/apps/ui_fileman.cpp | 52 +++++++++++++----------- firmware/application/apps/ui_fileman.hpp | 4 +- 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/firmware/application/apps/ui_fileman.cpp b/firmware/application/apps/ui_fileman.cpp index 9097d602..810cd34d 100644 --- a/firmware/application/apps/ui_fileman.cpp +++ b/firmware/application/apps/ui_fileman.cpp @@ -263,28 +263,32 @@ void FileManagerView::on_rename(NavigationView& nav) { } void FileManagerView::on_refactor(NavigationView& nav) { - text_prompt(nav, name_buffer, max_filename_length, [this](std::string& buffer) { - std::string destination_path = current_path.string(); - if (destination_path.back() != '/') - destination_path += '/'; - destination_path = destination_path + buffer; - rename_file(get_selected_path(), destination_path); //rename the selected file + text_prompt(nav, name_buffer, max_filename_length, [this](std::string& buffer) { + std::string destination_path = current_path.string(); + if (destination_path.back() != '/') + destination_path += '/'; + destination_path = destination_path + buffer; - if (get_selected_path().extension().string().substr(1) == "C16") {//rename it's partner ( C16 <-> TXT ) file. - auto selected_path = get_selected_path(); - auto partner_file_path = selected_path.string().substr(0, selected_path.string().size()-4) + ".TXT"; - destination_path = destination_path.substr(0, destination_path.size()-4) + ".TXT"; - rename_file(partner_file_path, destination_path); - }else if (get_selected_path().extension().string().substr(1) == "TXT") {//If the file user choose is a TXT file - auto selected_path = get_selected_path(); - auto partner_file_path = selected_path.string().substr(0, selected_path.string().size()-4) + ".C16"; - destination_path = destination_path.substr(0, destination_path.size()-4) + ".C16"; - rename_file(partner_file_path, destination_path); - } + rename_file(get_selected_path(), destination_path); //rename the selected file - load_directory_contents(current_path); - refresh_list(); - }); + auto selected_path = get_selected_path(); + auto extension = selected_path.extension().string(); + + if (!extension.empty() && selected_path.string().back() != '/' && extension.substr(1) == "C16") { + // Rename its partner ( C16 <-> TXT ) file. + auto partner_file_path = selected_path.string().substr(0, selected_path.string().size() - 4) + ".TXT"; + destination_path = destination_path.substr(0, destination_path.size() - 4) + ".TXT"; + rename_file(partner_file_path, destination_path); + } else if (!extension.empty() && selected_path.string().back() != '/' && extension.substr(1) == "TXT") { + // If the file user choose is a TXT file. + auto partner_file_path = selected_path.string().substr(0, selected_path.string().size() - 4) + ".C16"; + destination_path = destination_path.substr(0, destination_path.size() - 4) + ".C16"; + rename_file(partner_file_path, destination_path); + } + + load_directory_contents(current_path); + refresh_list(); + }); } void FileManagerView::on_delete() { @@ -353,10 +357,10 @@ FileManagerView::FileManagerView( on_rename(nav); }; - button_refactor.on_select = [this, &nav](Button&) { - name_buffer = entry_list[menu_view.highlighted_index()].entry_path.filename().string().substr(0, max_filename_length); - on_refactor(nav); - }; + button_refactor.on_select = [this, &nav](Button&) { + name_buffer = entry_list[menu_view.highlighted_index()].entry_path.filename().string().substr(0, max_filename_length); + on_refactor(nav); + }; button_delete.on_select = [this, &nav](Button&) { // Use display_modal ? diff --git a/firmware/application/apps/ui_fileman.hpp b/firmware/application/apps/ui_fileman.hpp index ea2b90cc..261295e8 100644 --- a/firmware/application/apps/ui_fileman.hpp +++ b/firmware/application/apps/ui_fileman.hpp @@ -159,7 +159,7 @@ private: }; Button button_rename { - { 0 * 8, 29 * 8, 10 * 8, 32 }, + { 0 * 8, 29 * 8, 9 * 8, 32 }, "Rename" }; @@ -169,7 +169,7 @@ private: }; Button button_delete { - { 20 * 8, 29 * 8, 10 * 8, 32 }, + { 21 * 8, 29 * 8, 9 * 8, 32 }, "Delete" }; From 474fe00146f3698a37ee40ebecbe5647aefa1880 Mon Sep 17 00:00:00 2001 From: zxkmmOnHaseeWSL Date: Sun, 23 Apr 2023 14:53:06 +0800 Subject: [PATCH 02/11] formatting fix --- firmware/application/apps/ui_fileman.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/firmware/application/apps/ui_fileman.cpp b/firmware/application/apps/ui_fileman.cpp index 810cd34d..9271bc92 100644 --- a/firmware/application/apps/ui_fileman.cpp +++ b/firmware/application/apps/ui_fileman.cpp @@ -357,10 +357,10 @@ FileManagerView::FileManagerView( on_rename(nav); }; - button_refactor.on_select = [this, &nav](Button&) { - name_buffer = entry_list[menu_view.highlighted_index()].entry_path.filename().string().substr(0, max_filename_length); - on_refactor(nav); - }; + button_refactor.on_select = [this, &nav](Button&) { + name_buffer = entry_list[menu_view.highlighted_index()].entry_path.filename().string().substr(0, max_filename_length); + on_refactor(nav); + }; button_delete.on_select = [this, &nav](Button&) { // Use display_modal ? From 925c1548a875881b16e34b8544b375daf7dcad25 Mon Sep 17 00:00:00 2001 From: zxkmmOnHaseeWSL Date: Sun, 23 Apr 2023 16:43:19 +0800 Subject: [PATCH 03/11] fix stealth doesn't work --- firmware/application/apps/replay_app.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/firmware/application/apps/replay_app.cpp b/firmware/application/apps/replay_app.cpp index d129a8ba..20b2943d 100644 --- a/firmware/application/apps/replay_app.cpp +++ b/firmware/application/apps/replay_app.cpp @@ -161,10 +161,16 @@ void ReplayAppView::start() { sample_rate * 8, baseband_bandwidth, rf::Direction::Transmit, - rf_amp, // previous code line : "receiver_model.rf_amp()," was passing the same rf_amp of all Receiver Apps + rf_amp, // previous code line : "receiver_model.rf_amp()," was passing the same rf_amp of all Receiver Apps static_cast(receiver_model.lna()), static_cast(receiver_model.vga()) }); + + if (portapack::persistent_memory::stealth_mode()){ + DisplaySleepMessage message; + EventDispatcher::send_message(message); + } + } void ReplayAppView::stop(const bool do_loop) { From 812f0f8211b079f11e8c62a65818136c18db281f Mon Sep 17 00:00:00 2001 From: Bernd Herzog Date: Sun, 23 Apr 2023 16:21:33 +0200 Subject: [PATCH 04/11] added overlay to system view --- firmware/application/CMakeLists.txt | 1 + firmware/application/apps/ui_dfu_menu.cpp | 46 +++++++++++++++++ firmware/application/apps/ui_dfu_menu.hpp | 63 +++++++++++++++++++++++ firmware/application/event_m0.cpp | 10 +++- firmware/application/ui_navigation.cpp | 18 +++++++ firmware/application/ui_navigation.hpp | 6 +++ 6 files changed, 143 insertions(+), 1 deletion(-) create mode 100644 firmware/application/apps/ui_dfu_menu.cpp create mode 100644 firmware/application/apps/ui_dfu_menu.hpp diff --git a/firmware/application/CMakeLists.txt b/firmware/application/CMakeLists.txt index 9e03d737..a2288e00 100644 --- a/firmware/application/CMakeLists.txt +++ b/firmware/application/CMakeLists.txt @@ -230,6 +230,7 @@ set(CPPSRC apps/ui_nrf_rx.cpp apps/ui_aprs_tx.cpp apps/ui_bht_tx.cpp + apps/ui_dfu_menu.cpp apps/ui_coasterp.cpp apps/ui_debug.cpp apps/ui_encoders.cpp diff --git a/firmware/application/apps/ui_dfu_menu.cpp b/firmware/application/apps/ui_dfu_menu.cpp new file mode 100644 index 00000000..69abe02d --- /dev/null +++ b/firmware/application/apps/ui_dfu_menu.cpp @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2023 Bernd Herzog + * + * This file is part of PortaPack. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#include "ui_dfu_menu.hpp" +#include "portapack_shared_memory.hpp" + +namespace ui { + +DfuMenu::DfuMenu(NavigationView& nav) : nav_ (nav) { + add_children({ + &text_info, + &progress, + &dummy, + }); +} + +void DfuMenu::focus() { + dummy.focus(); +} + +void DfuMenu::paint(Painter& painter) { + painter.fill_rectangle( + {{50,50} , {50 , 50}}, + ui::Color::blue() + ); +} + +} /* namespace ui */ diff --git a/firmware/application/apps/ui_dfu_menu.hpp b/firmware/application/apps/ui_dfu_menu.hpp new file mode 100644 index 00000000..d184d2cd --- /dev/null +++ b/firmware/application/apps/ui_dfu_menu.hpp @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2023 Bernd Herzog + * + * This file is part of PortaPack. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __UI_DFU_MENU_H__ +#define __UI_DFU_MENU_H__ + +#include + +#include "ui_widget.hpp" +#include "event_m0.hpp" + +namespace ui { +class NavigationView; + +class DfuMenu : public View { +public: + DfuMenu(NavigationView& nav); + ~DfuMenu() = default; + + void focus() override; + void paint(Painter& painter) override; + + std::string title() const override { return "DFU Menu"; }; + +private: + NavigationView& nav_; + + Text text_info { + { 10 * 8, 16 * 8, 10 * 8, 16 }, + "Working..." + }; + + ProgressBar progress { + { 2 * 8, 19 * 8, 26 * 8, 24 } + }; + + Button dummy { + { 240, 0, 0, 0 }, + "" + }; +}; + +} /* namespace ui */ + +#endif/*__UI_DFU_MENU_H__*/ diff --git a/firmware/application/event_m0.cpp b/firmware/application/event_m0.cpp index 583c4004..146492b9 100644 --- a/firmware/application/event_m0.cpp +++ b/firmware/application/event_m0.cpp @@ -43,6 +43,7 @@ using namespace lpc43xx; #include #include "ui_font_fixed_8x16.hpp" +#include "ui_navigation.hpp" extern "C" { @@ -262,6 +263,8 @@ void EventDispatcher::on_touch_event(ui::TouchEvent event) { void EventDispatcher::handle_lcd_frame_sync() { DisplayFrameSyncMessage message; message_map.send(&message); + + static_cast(top_widget)->paint_overlay(); painter.paint_widget_tree(top_widget); portapack::backlight()->on(); @@ -304,7 +307,12 @@ void EventDispatcher::handle_switches() { if( switches_state[i] ) { const auto event = static_cast(i); if( !event_bubble_key(event) ) { - context.focus_manager().update(top_widget, event); + if (switches_state[(size_t)ui::KeyEvent::Dfu]) { + static_cast(top_widget)->toggle_overlay(); + } + else { + context.focus_manager().update(top_widget, event); + } } in_key_event = true; diff --git a/firmware/application/ui_navigation.cpp b/firmware/application/ui_navigation.cpp index 179e734f..a68e02fe 100644 --- a/firmware/application/ui_navigation.cpp +++ b/firmware/application/ui_navigation.cpp @@ -748,6 +748,24 @@ Context& SystemView::context() const { return context_; } +void SystemView::toggle_overlay() { + if (overlay_active){ + this->remove_child(&this->overlay); + this->set_dirty(); + } + else{ + this->add_child(&this->overlay); + this->set_dirty(); + } + overlay_active = !overlay_active; +} + +void SystemView::paint_overlay() { + if (overlay_active){ + this->overlay.set_dirty(); + } +} + /* ***********************************************************************/ void BMPView::focus() { diff --git a/firmware/application/ui_navigation.hpp b/firmware/application/ui_navigation.hpp index a1a0b5d0..a0ebe4fc 100644 --- a/firmware/application/ui_navigation.hpp +++ b/firmware/application/ui_navigation.hpp @@ -33,6 +33,7 @@ #include "ui_channel.hpp" #include "ui_audio.hpp" #include "ui_sd_card_status_view.hpp" +#include "ui_dfu_menu.hpp" #include "bitmap.hpp" #include "ff.h" @@ -290,10 +291,15 @@ namespace ui const Rect parent_rect); Context &context() const override; + void toggle_overlay(); + void paint_overlay(); private: + bool overlay_active {false}; + SystemStatusView status_view{navigation_view}; InformationView info_view{navigation_view}; + DfuMenu overlay{navigation_view}; NavigationView navigation_view{}; Context &context_; }; From 850a79c9bb257e59e51e72888f4455ec2bad2ed4 Mon Sep 17 00:00:00 2001 From: Bernd Herzog Date: Sun, 23 Apr 2023 19:52:38 +0200 Subject: [PATCH 05/11] added m0 stats to dfu screen --- firmware/application/apps/ui_dfu_menu.cpp | 48 ++++++++++++++++++----- firmware/application/apps/ui_dfu_menu.hpp | 40 ++++++++++++------- firmware/application/ui_navigation.cpp | 6 +++ 3 files changed, 71 insertions(+), 23 deletions(-) diff --git a/firmware/application/apps/ui_dfu_menu.cpp b/firmware/application/apps/ui_dfu_menu.cpp index 69abe02d..85b43a83 100644 --- a/firmware/application/apps/ui_dfu_menu.cpp +++ b/firmware/application/apps/ui_dfu_menu.cpp @@ -26,20 +26,50 @@ namespace ui { DfuMenu::DfuMenu(NavigationView& nav) : nav_ (nav) { add_children({ - &text_info, - &progress, - &dummy, + &text_head, + &labels, + &text_info_line_1, + &text_info_line_2, + &text_info_line_3, + &text_info_line_4, + &text_info_line_5, + &text_info_line_6, + &text_info_line_7 }); } -void DfuMenu::focus() { - dummy.focus(); -} - void DfuMenu::paint(Painter& painter) { + //update child values + // if (chThdSelf() == chSysGetIdleThread()) { chThdGetTicks(chThdSelf()) } + + auto now = chTimeNow(); + auto idle_ticks = chThdGetTicks(chSysGetIdleThread()); + + static systime_t last_time; + static systime_t last_last_time; + + auto time_elapsed = now - last_time; + auto idle_elapsed = idle_ticks - last_last_time; + + last_time = now; + last_last_time = idle_ticks; + + text_info_line_1.set(to_string_dec_uint(chCoreStatus(), 6)); + text_info_line_2.set(to_string_dec_uint((uint32_t)get_free_stack_space(), 6)); + text_info_line_3.set(to_string_dec_uint((time_elapsed - idle_elapsed) / 10, 6)); + text_info_line_4.set("M4 heap"); + text_info_line_5.set("M4 stack"); + text_info_line_6.set("M4 cpu"); + text_info_line_7.set(to_string_dec_uint(chTimeNow()/1000, 6)); + + auto screen_size = portapack::display.screen_rect().size(); + painter.fill_rectangle( - {{50,50} , {50 , 50}}, - ui::Color::blue() + { + {6 * CHARACTER_WIDTH, 3 * LINE_HEIGHT}, + {screen_size.width() - 12 * CHARACTER_WIDTH, screen_size.height() - 6 * LINE_HEIGHT} + }, + ui::Color::black() ); } diff --git a/firmware/application/apps/ui_dfu_menu.hpp b/firmware/application/apps/ui_dfu_menu.hpp index d184d2cd..54272f03 100644 --- a/firmware/application/apps/ui_dfu_menu.hpp +++ b/firmware/application/apps/ui_dfu_menu.hpp @@ -26,6 +26,11 @@ #include "ui_widget.hpp" #include "event_m0.hpp" +#include "debug.hpp" +#include "string_format.hpp" + +#define LINE_HEIGHT 16 +#define CHARACTER_WIDTH 8 namespace ui { class NavigationView; @@ -35,27 +40,34 @@ public: DfuMenu(NavigationView& nav); ~DfuMenu() = default; - void focus() override; void paint(Painter& painter) override; - std::string title() const override { return "DFU Menu"; }; - private: NavigationView& nav_; - Text text_info { - { 10 * 8, 16 * 8, 10 * 8, 16 }, - "Working..." + Text text_head {{ 6 * CHARACTER_WIDTH, 3 * LINE_HEIGHT, 10 * CHARACTER_WIDTH, 1 * LINE_HEIGHT }, "DFU Menu"}; + + Labels labels { + { { 6 * CHARACTER_WIDTH, 5 * LINE_HEIGHT }, "M0 heap:", Color::light_grey() }, + { { 6 * CHARACTER_WIDTH, 6 * LINE_HEIGHT }, "M0 stack:", Color::light_grey() }, + { { 6 * CHARACTER_WIDTH, 7 * LINE_HEIGHT }, "M0 cpu %:", Color::light_grey() }, + { { 6 * CHARACTER_WIDTH, 8 * LINE_HEIGHT }, "M4 heap:", Color::light_grey() }, + { { 6 * CHARACTER_WIDTH, 9 * LINE_HEIGHT }, "M4 stack:", Color::light_grey() }, + { { 6 * CHARACTER_WIDTH,10 * LINE_HEIGHT }, "M4 cpu %:", Color::light_grey() }, + { { 6 * CHARACTER_WIDTH,11 * LINE_HEIGHT }, "uptime:", Color::light_grey() } }; + + Text text_info_line_1 {{ 16 * CHARACTER_WIDTH, 5 * LINE_HEIGHT, 10 * CHARACTER_WIDTH, 1 * LINE_HEIGHT }, ""}; + Text text_info_line_2 {{ 16 * CHARACTER_WIDTH, 6 * LINE_HEIGHT, 10 * CHARACTER_WIDTH, 1 * LINE_HEIGHT }, ""}; + Text text_info_line_3 {{ 16 * CHARACTER_WIDTH, 7 * LINE_HEIGHT, 10 * CHARACTER_WIDTH, 1 * LINE_HEIGHT }, ""}; + Text text_info_line_4 {{ 16 * CHARACTER_WIDTH, 8 * LINE_HEIGHT, 10 * CHARACTER_WIDTH, 1 * LINE_HEIGHT }, ""}; + Text text_info_line_5 {{ 16 * CHARACTER_WIDTH, 9 * LINE_HEIGHT, 10 * CHARACTER_WIDTH, 1 * LINE_HEIGHT }, ""}; + Text text_info_line_6 {{ 16 * CHARACTER_WIDTH,10 * LINE_HEIGHT, 10 * CHARACTER_WIDTH, 1 * LINE_HEIGHT }, ""}; + Text text_info_line_7 {{ 16 * CHARACTER_WIDTH,11 * LINE_HEIGHT, 10 * CHARACTER_WIDTH, 1 * LINE_HEIGHT }, ""}; - ProgressBar progress { - { 2 * 8, 19 * 8, 26 * 8, 24 } - }; - - Button dummy { - { 240, 0, 0, 0 }, - "" - }; + // ProgressBar progress { + // { 6 * CHARACTER_WIDTH, 5 * LINE_HEIGHT, 16 * CHARACTER_WIDTH, 24 } + // }; }; } /* namespace ui */ diff --git a/firmware/application/ui_navigation.cpp b/firmware/application/ui_navigation.cpp index a68e02fe..fc96920a 100644 --- a/firmware/application/ui_navigation.cpp +++ b/firmware/application/ui_navigation.cpp @@ -761,7 +761,13 @@ void SystemView::toggle_overlay() { } void SystemView::paint_overlay() { + static bool last_paint_state = false; if (overlay_active){ + // paint background only every other second + if ((((chTimeNow()>>10) & 0x01) == 0x01) == last_paint_state) + return; + + last_paint_state = !last_paint_state; this->overlay.set_dirty(); } } From 2ef9ebd7bdece7eca3e63545f345b82307cf9274 Mon Sep 17 00:00:00 2001 From: Bernd Herzog Date: Sun, 23 Apr 2023 21:48:45 +0200 Subject: [PATCH 06/11] implemented M4 stats --- firmware/application/apps/ui_dfu_menu.cpp | 49 ++++++++++++++++----- firmware/application/apps/ui_dfu_menu.hpp | 34 +++++++------- firmware/application/main.cpp | 6 +-- firmware/application/ui_navigation.cpp | 4 ++ firmware/baseband/event_m4.cpp | 33 ++++++++++++++ firmware/baseband/event_m4.hpp | 1 + firmware/common/portapack_shared_memory.hpp | 5 +++ 7 files changed, 100 insertions(+), 32 deletions(-) diff --git a/firmware/application/apps/ui_dfu_menu.cpp b/firmware/application/apps/ui_dfu_menu.cpp index 85b43a83..5d127b07 100644 --- a/firmware/application/apps/ui_dfu_menu.cpp +++ b/firmware/application/apps/ui_dfu_menu.cpp @@ -39,9 +39,6 @@ DfuMenu::DfuMenu(NavigationView& nav) : nav_ (nav) { } void DfuMenu::paint(Painter& painter) { - //update child values - // if (chThdSelf() == chSysGetIdleThread()) { chThdGetTicks(chThdSelf()) } - auto now = chTimeNow(); auto idle_ticks = chThdGetTicks(chSysGetIdleThread()); @@ -57,20 +54,52 @@ void DfuMenu::paint(Painter& painter) { text_info_line_1.set(to_string_dec_uint(chCoreStatus(), 6)); text_info_line_2.set(to_string_dec_uint((uint32_t)get_free_stack_space(), 6)); text_info_line_3.set(to_string_dec_uint((time_elapsed - idle_elapsed) / 10, 6)); - text_info_line_4.set("M4 heap"); - text_info_line_5.set("M4 stack"); - text_info_line_6.set("M4 cpu"); + text_info_line_4.set(to_string_dec_uint(shared_memory.m4_heap_usage, 6)); + text_info_line_5.set(to_string_dec_uint(shared_memory.m4_stack_usage, 6)); + text_info_line_6.set(to_string_dec_uint(shared_memory.m4_cpu_usage, 6)); text_info_line_7.set(to_string_dec_uint(chTimeNow()/1000, 6)); - auto screen_size = portapack::display.screen_rect().size(); - + constexpr auto margin = 5; + painter.fill_rectangle( { - {6 * CHARACTER_WIDTH, 3 * LINE_HEIGHT}, - {screen_size.width() - 12 * CHARACTER_WIDTH, screen_size.height() - 6 * LINE_HEIGHT} + {6 * CHARACTER_WIDTH - margin, 3 * LINE_HEIGHT - margin}, + {15 * CHARACTER_WIDTH + margin * 2, 9 * LINE_HEIGHT + margin * 2} }, ui::Color::black() ); + + painter.fill_rectangle( + { + {5 * CHARACTER_WIDTH - margin, 3 * LINE_HEIGHT - margin}, + {CHARACTER_WIDTH, 9 * LINE_HEIGHT + margin * 2} + }, + ui::Color::dark_cyan() + ); + + painter.fill_rectangle( + { + {21 * CHARACTER_WIDTH + margin, 3 * LINE_HEIGHT - margin}, + {CHARACTER_WIDTH, 9 * LINE_HEIGHT + margin * 2} + }, + ui::Color::dark_cyan() + ); + + painter.fill_rectangle( + { + {5 * CHARACTER_WIDTH - margin, 3 * LINE_HEIGHT - margin - 8}, + {17 * CHARACTER_WIDTH + margin * 2, 8} + }, + ui::Color::dark_cyan() + ); + + painter.fill_rectangle( + { + {5 * CHARACTER_WIDTH - margin, 12 * LINE_HEIGHT + margin}, + {17 * CHARACTER_WIDTH + margin * 2, 8} + }, + ui::Color::dark_cyan() + ); } } /* namespace ui */ diff --git a/firmware/application/apps/ui_dfu_menu.hpp b/firmware/application/apps/ui_dfu_menu.hpp index 54272f03..9c2fa1a7 100644 --- a/firmware/application/apps/ui_dfu_menu.hpp +++ b/firmware/application/apps/ui_dfu_menu.hpp @@ -45,29 +45,25 @@ public: private: NavigationView& nav_; - Text text_head {{ 6 * CHARACTER_WIDTH, 3 * LINE_HEIGHT, 10 * CHARACTER_WIDTH, 1 * LINE_HEIGHT }, "DFU Menu"}; + Text text_head {{ 6 * CHARACTER_WIDTH, 3 * LINE_HEIGHT, 11 * CHARACTER_WIDTH, 1 * LINE_HEIGHT }, "Performance"}; Labels labels { - { { 6 * CHARACTER_WIDTH, 5 * LINE_HEIGHT }, "M0 heap:", Color::light_grey() }, - { { 6 * CHARACTER_WIDTH, 6 * LINE_HEIGHT }, "M0 stack:", Color::light_grey() }, - { { 6 * CHARACTER_WIDTH, 7 * LINE_HEIGHT }, "M0 cpu %:", Color::light_grey() }, - { { 6 * CHARACTER_WIDTH, 8 * LINE_HEIGHT }, "M4 heap:", Color::light_grey() }, - { { 6 * CHARACTER_WIDTH, 9 * LINE_HEIGHT }, "M4 stack:", Color::light_grey() }, - { { 6 * CHARACTER_WIDTH,10 * LINE_HEIGHT }, "M4 cpu %:", Color::light_grey() }, - { { 6 * CHARACTER_WIDTH,11 * LINE_HEIGHT }, "uptime:", Color::light_grey() } + { { 6 * CHARACTER_WIDTH, 5 * LINE_HEIGHT }, "M0 heap:", Color::dark_cyan() }, + { { 6 * CHARACTER_WIDTH, 6 * LINE_HEIGHT }, "M0 stack:", Color::dark_cyan() }, + { { 6 * CHARACTER_WIDTH, 7 * LINE_HEIGHT }, "M0 cpu %:", Color::dark_cyan() }, + { { 6 * CHARACTER_WIDTH, 8 * LINE_HEIGHT }, "M4 heap:", Color::dark_cyan() }, + { { 6 * CHARACTER_WIDTH, 9 * LINE_HEIGHT }, "M4 stack:", Color::dark_cyan() }, + { { 6 * CHARACTER_WIDTH,10 * LINE_HEIGHT }, "M4 cpu %:", Color::dark_cyan() }, + { { 6 * CHARACTER_WIDTH,11 * LINE_HEIGHT }, "uptime:", Color::dark_cyan() } }; - Text text_info_line_1 {{ 16 * CHARACTER_WIDTH, 5 * LINE_HEIGHT, 10 * CHARACTER_WIDTH, 1 * LINE_HEIGHT }, ""}; - Text text_info_line_2 {{ 16 * CHARACTER_WIDTH, 6 * LINE_HEIGHT, 10 * CHARACTER_WIDTH, 1 * LINE_HEIGHT }, ""}; - Text text_info_line_3 {{ 16 * CHARACTER_WIDTH, 7 * LINE_HEIGHT, 10 * CHARACTER_WIDTH, 1 * LINE_HEIGHT }, ""}; - Text text_info_line_4 {{ 16 * CHARACTER_WIDTH, 8 * LINE_HEIGHT, 10 * CHARACTER_WIDTH, 1 * LINE_HEIGHT }, ""}; - Text text_info_line_5 {{ 16 * CHARACTER_WIDTH, 9 * LINE_HEIGHT, 10 * CHARACTER_WIDTH, 1 * LINE_HEIGHT }, ""}; - Text text_info_line_6 {{ 16 * CHARACTER_WIDTH,10 * LINE_HEIGHT, 10 * CHARACTER_WIDTH, 1 * LINE_HEIGHT }, ""}; - Text text_info_line_7 {{ 16 * CHARACTER_WIDTH,11 * LINE_HEIGHT, 10 * CHARACTER_WIDTH, 1 * LINE_HEIGHT }, ""}; - - // ProgressBar progress { - // { 6 * CHARACTER_WIDTH, 5 * LINE_HEIGHT, 16 * CHARACTER_WIDTH, 24 } - // }; + Text text_info_line_1 {{ 15 * CHARACTER_WIDTH, 5 * LINE_HEIGHT, 5 * CHARACTER_WIDTH, 1 * LINE_HEIGHT }, ""}; + Text text_info_line_2 {{ 15 * CHARACTER_WIDTH, 6 * LINE_HEIGHT, 5 * CHARACTER_WIDTH, 1 * LINE_HEIGHT }, ""}; + Text text_info_line_3 {{ 15 * CHARACTER_WIDTH, 7 * LINE_HEIGHT, 5 * CHARACTER_WIDTH, 1 * LINE_HEIGHT }, ""}; + Text text_info_line_4 {{ 15 * CHARACTER_WIDTH, 8 * LINE_HEIGHT, 5 * CHARACTER_WIDTH, 1 * LINE_HEIGHT }, ""}; + Text text_info_line_5 {{ 15 * CHARACTER_WIDTH, 9 * LINE_HEIGHT, 5 * CHARACTER_WIDTH, 1 * LINE_HEIGHT }, ""}; + Text text_info_line_6 {{ 15 * CHARACTER_WIDTH,10 * LINE_HEIGHT, 5 * CHARACTER_WIDTH, 1 * LINE_HEIGHT }, ""}; + Text text_info_line_7 {{ 15 * CHARACTER_WIDTH,11 * LINE_HEIGHT, 5 * CHARACTER_WIDTH, 1 * LINE_HEIGHT }, ""}; }; } /* namespace ui */ diff --git a/firmware/application/main.cpp b/firmware/application/main.cpp index d9bef9fb..7af337ec 100755 --- a/firmware/application/main.cpp +++ b/firmware/application/main.cpp @@ -145,14 +145,14 @@ Continuous (Fox-oring) rffc507x::RFFC507x first_if; static void event_loop() { - ui::Context context; - ui::SystemView system_view { + static ui::Context context; + static ui::SystemView system_view { context, portapack::display.screen_rect() }; EventDispatcher event_dispatcher { &system_view, context }; - MessageHandlerRegistration message_handler_display_sleep { + static MessageHandlerRegistration message_handler_display_sleep { Message::ID::DisplaySleep, [&event_dispatcher](const Message* const) { event_dispatcher.set_display_sleep(true); diff --git a/firmware/application/ui_navigation.cpp b/firmware/application/ui_navigation.cpp index fc96920a..70e22e40 100644 --- a/firmware/application/ui_navigation.cpp +++ b/firmware/application/ui_navigation.cpp @@ -29,6 +29,7 @@ #include "bmp_splash.hpp" #include "bmp_modal_warning.hpp" #include "portapack_persistent_memory.hpp" +#include "portapack_shared_memory.hpp" #include "ui_about_simple.hpp" #include "ui_adsb_rx.hpp" @@ -752,11 +753,14 @@ void SystemView::toggle_overlay() { if (overlay_active){ this->remove_child(&this->overlay); this->set_dirty(); + shared_memory.request_m4_performance_counter = 0; } else{ this->add_child(&this->overlay); this->set_dirty(); + shared_memory.request_m4_performance_counter = 1; } + overlay_active = !overlay_active; } diff --git a/firmware/baseband/event_m4.cpp b/firmware/baseband/event_m4.cpp index c1b395b2..dbf3a187 100644 --- a/firmware/baseband/event_m4.cpp +++ b/firmware/baseband/event_m4.cpp @@ -20,6 +20,7 @@ */ #include "event_m4.hpp" +#include "debug.hpp" #include "portapack_shared_memory.hpp" @@ -86,6 +87,10 @@ void EventDispatcher::dispatch(const eventmask_t events) { if( events & EVT_MASK_SPECTRUM ) { handle_spectrum(); } + + if (shared_memory.request_m4_performance_counter == 0x01) { + update_performance_counters(); + } } void EventDispatcher::handle_baseband_queue() { @@ -95,6 +100,34 @@ void EventDispatcher::handle_baseband_queue() { } } +void EventDispatcher::update_performance_counters() { + static bool last_paint_state = false; + if ((((chTimeNow()>>10) & 0x01) == 0x01) == last_paint_state) + return; + + last_paint_state = !last_paint_state; + + auto now = chTimeNow(); + auto idle_ticks = chThdGetTicks(chSysGetIdleThread()); + + static systime_t last_time; + static systime_t last_last_time; + + auto time_elapsed = now - last_time; + auto idle_elapsed = idle_ticks - last_last_time; + + last_time = now; + last_last_time = idle_ticks; + + auto cpu_usage = (time_elapsed - idle_elapsed) / 10; + auto free_stack = (uint32_t)get_free_stack_space(); + auto free_heap = chCoreStatus(); + + shared_memory.m4_cpu_usage = cpu_usage; + shared_memory.m4_stack_usage = free_stack; + shared_memory.m4_heap_usage = free_heap; +} + void EventDispatcher::on_message(const Message* const message) { switch(message->id) { case Message::ID::Shutdown: diff --git a/firmware/baseband/event_m4.hpp b/firmware/baseband/event_m4.hpp index 42b5d3b9..5f3097f9 100644 --- a/firmware/baseband/event_m4.hpp +++ b/firmware/baseband/event_m4.hpp @@ -61,6 +61,7 @@ private: void dispatch(const eventmask_t events); void handle_baseband_queue(); + void update_performance_counters(); void on_message(const Message* const message); void on_message_shutdown(const ShutdownMessage&); diff --git a/firmware/common/portapack_shared_memory.hpp b/firmware/common/portapack_shared_memory.hpp index 3235cef1..3d289a85 100644 --- a/firmware/common/portapack_shared_memory.hpp +++ b/firmware/common/portapack_shared_memory.hpp @@ -64,6 +64,11 @@ struct SharedMemory { JammerChannel jammer_channels[24]; uint8_t data[512]; } bb_data { { { { 0, 0 } }, 0, { 0 } } }; + + uint8_t request_m4_performance_counter{ 0 }; + uint8_t m4_cpu_usage{ 0 }; + uint16_t m4_stack_usage{ 0 }; + uint16_t m4_heap_usage{ 0 }; }; extern SharedMemory& shared_memory; From 29b7a5ee563e04d54e10da393851b70ce88407be Mon Sep 17 00:00:00 2001 From: Bernd Herzog Date: Sun, 23 Apr 2023 23:48:20 +0200 Subject: [PATCH 07/11] improved m4 m0 communication --- firmware/application/ui_navigation.cpp | 3 ++ firmware/baseband/chconf.h | 4 +++ firmware/baseband/debug.cpp | 30 +++++++++++++++++ firmware/baseband/event_m4.cpp | 33 +------------------ firmware/baseband/event_m4.hpp | 1 - .../baseband/sd_over_usb/proc_sd_over_usb.cpp | 2 ++ firmware/common/portapack_shared_memory.hpp | 8 ++--- 7 files changed, 44 insertions(+), 37 deletions(-) diff --git a/firmware/application/ui_navigation.cpp b/firmware/application/ui_navigation.cpp index 70e22e40..1870b126 100644 --- a/firmware/application/ui_navigation.cpp +++ b/firmware/application/ui_navigation.cpp @@ -759,6 +759,9 @@ void SystemView::toggle_overlay() { this->add_child(&this->overlay); this->set_dirty(); shared_memory.request_m4_performance_counter = 1; + shared_memory.m4_cpu_usage = 0; + shared_memory.m4_heap_usage = 0; + shared_memory.m4_stack_usage = 0; } overlay_active = !overlay_active; diff --git a/firmware/baseband/chconf.h b/firmware/baseband/chconf.h index 0ad24529..f5b45196 100755 --- a/firmware/baseband/chconf.h +++ b/firmware/baseband/chconf.h @@ -508,6 +508,8 @@ } #endif + + /** * @brief System tick event hook. * @details This hook is invoked in the system tick handler immediately @@ -516,6 +518,8 @@ #if !defined(SYSTEM_TICK_EVENT_HOOK) || defined(__DOXYGEN__) #define SYSTEM_TICK_EVENT_HOOK() { \ /* System tick event code here.*/ \ + extern void update_performance_counters(); \ + update_performance_counters(); \ } #endif diff --git a/firmware/baseband/debug.cpp b/firmware/baseband/debug.cpp index f69f4053..450c9bce 100644 --- a/firmware/baseband/debug.cpp +++ b/firmware/baseband/debug.cpp @@ -116,5 +116,35 @@ CH_IRQ_HANDLER(HardFaultVector) { #endif } +void update_performance_counters() { + auto performance_counter_active = shared_memory.request_m4_performance_counter; + if (performance_counter_active == 0x00) + return; + static bool last_paint_state = false; + if ((((chTimeNow()>>10) & 0x01) == 0x01) == last_paint_state) + return; + + last_paint_state = !last_paint_state; + + auto now = chTimeNow(); + auto idle_ticks = chThdGetTicks(chSysGetIdleThread()); + + static systime_t last_time; + static systime_t last_last_time; + + auto time_elapsed = now - last_time; + auto idle_elapsed = idle_ticks - last_last_time; + + last_time = now; + last_last_time = idle_ticks; + + auto cpu_usage = (time_elapsed - idle_elapsed) / 10; + auto free_stack = (uint32_t)get_free_stack_space(); + auto free_heap = chCoreStatus(); + + shared_memory.m4_cpu_usage = cpu_usage; + shared_memory.m4_stack_usage = free_stack; + shared_memory.m4_heap_usage = free_heap; } +} /* extern "C" */ diff --git a/firmware/baseband/event_m4.cpp b/firmware/baseband/event_m4.cpp index dbf3a187..ee0079eb 100644 --- a/firmware/baseband/event_m4.cpp +++ b/firmware/baseband/event_m4.cpp @@ -87,10 +87,6 @@ void EventDispatcher::dispatch(const eventmask_t events) { if( events & EVT_MASK_SPECTRUM ) { handle_spectrum(); } - - if (shared_memory.request_m4_performance_counter == 0x01) { - update_performance_counters(); - } } void EventDispatcher::handle_baseband_queue() { @@ -100,34 +96,6 @@ void EventDispatcher::handle_baseband_queue() { } } -void EventDispatcher::update_performance_counters() { - static bool last_paint_state = false; - if ((((chTimeNow()>>10) & 0x01) == 0x01) == last_paint_state) - return; - - last_paint_state = !last_paint_state; - - auto now = chTimeNow(); - auto idle_ticks = chThdGetTicks(chSysGetIdleThread()); - - static systime_t last_time; - static systime_t last_last_time; - - auto time_elapsed = now - last_time; - auto idle_elapsed = idle_ticks - last_last_time; - - last_time = now; - last_last_time = idle_ticks; - - auto cpu_usage = (time_elapsed - idle_elapsed) / 10; - auto free_stack = (uint32_t)get_free_stack_space(); - auto free_heap = chCoreStatus(); - - shared_memory.m4_cpu_usage = cpu_usage; - shared_memory.m4_stack_usage = free_stack; - shared_memory.m4_heap_usage = free_heap; -} - void EventDispatcher::on_message(const Message* const message) { switch(message->id) { case Message::ID::Shutdown: @@ -153,3 +121,4 @@ void EventDispatcher::handle_spectrum() { const UpdateSpectrumMessage message; baseband_processor->on_message(&message); } + diff --git a/firmware/baseband/event_m4.hpp b/firmware/baseband/event_m4.hpp index 5f3097f9..42b5d3b9 100644 --- a/firmware/baseband/event_m4.hpp +++ b/firmware/baseband/event_m4.hpp @@ -61,7 +61,6 @@ private: void dispatch(const eventmask_t events); void handle_baseband_queue(); - void update_performance_counters(); void on_message(const Message* const message); void on_message_shutdown(const ShutdownMessage&); diff --git a/firmware/baseband/sd_over_usb/proc_sd_over_usb.cpp b/firmware/baseband/sd_over_usb/proc_sd_over_usb.cpp index 3645804e..01bcef05 100644 --- a/firmware/baseband/sd_over_usb/proc_sd_over_usb.cpp +++ b/firmware/baseband/sd_over_usb/proc_sd_over_usb.cpp @@ -45,3 +45,5 @@ int main() { return 0; } + +void update_performance_counters() {} diff --git a/firmware/common/portapack_shared_memory.hpp b/firmware/common/portapack_shared_memory.hpp index 3d289a85..014c92db 100644 --- a/firmware/common/portapack_shared_memory.hpp +++ b/firmware/common/portapack_shared_memory.hpp @@ -65,10 +65,10 @@ struct SharedMemory { uint8_t data[512]; } bb_data { { { { 0, 0 } }, 0, { 0 } } }; - uint8_t request_m4_performance_counter{ 0 }; - uint8_t m4_cpu_usage{ 0 }; - uint16_t m4_stack_usage{ 0 }; - uint16_t m4_heap_usage{ 0 }; + uint8_t volatile request_m4_performance_counter{ 0 }; + uint8_t volatile m4_cpu_usage{ 0 }; + uint16_t volatile m4_stack_usage{ 0 }; + uint16_t volatile m4_heap_usage{ 0 }; }; extern SharedMemory& shared_memory; From 948d8d947ee788a16d8f2fa1be3e3a6d7608f490 Mon Sep 17 00:00:00 2001 From: Bernd Herzog Date: Mon, 24 Apr 2023 13:00:34 +0200 Subject: [PATCH 08/11] improved stability of cpu usage calculation --- firmware/application/CMakeLists.txt | 1 + firmware/application/apps/ui_dfu_menu.cpp | 15 ++---- firmware/baseband/CMakeLists.txt | 1 + firmware/baseband/debug.cpp | 25 +++++----- firmware/common/performance_counter.cpp | 57 +++++++++++++++++++++++ firmware/common/performance_counter.hpp | 29 ++++++++++++ 6 files changed, 102 insertions(+), 26 deletions(-) create mode 100644 firmware/common/performance_counter.cpp create mode 100644 firmware/common/performance_counter.hpp diff --git a/firmware/application/CMakeLists.txt b/firmware/application/CMakeLists.txt index a2288e00..fd41cc63 100644 --- a/firmware/application/CMakeLists.txt +++ b/firmware/application/CMakeLists.txt @@ -155,6 +155,7 @@ set(CPPSRC ${COMMON}/ui_widget.cpp ${COMMON}/utility.cpp ${COMMON}/wm8731.cpp + ${COMMON}/performance_counter.cpp app_settings.cpp audio.cpp baseband_api.cpp diff --git a/firmware/application/apps/ui_dfu_menu.cpp b/firmware/application/apps/ui_dfu_menu.cpp index 5d127b07..08fe1f3e 100644 --- a/firmware/application/apps/ui_dfu_menu.cpp +++ b/firmware/application/apps/ui_dfu_menu.cpp @@ -21,6 +21,7 @@ #include "ui_dfu_menu.hpp" #include "portapack_shared_memory.hpp" +#include "performance_counter.hpp" namespace ui { @@ -39,21 +40,11 @@ DfuMenu::DfuMenu(NavigationView& nav) : nav_ (nav) { } void DfuMenu::paint(Painter& painter) { - auto now = chTimeNow(); - auto idle_ticks = chThdGetTicks(chSysGetIdleThread()); - - static systime_t last_time; - static systime_t last_last_time; - - auto time_elapsed = now - last_time; - auto idle_elapsed = idle_ticks - last_last_time; - - last_time = now; - last_last_time = idle_ticks; + auto utilisation = get_cpu_utilisation_in_percent(); text_info_line_1.set(to_string_dec_uint(chCoreStatus(), 6)); text_info_line_2.set(to_string_dec_uint((uint32_t)get_free_stack_space(), 6)); - text_info_line_3.set(to_string_dec_uint((time_elapsed - idle_elapsed) / 10, 6)); + text_info_line_3.set(to_string_dec_uint(utilisation, 6)); text_info_line_4.set(to_string_dec_uint(shared_memory.m4_heap_usage, 6)); text_info_line_5.set(to_string_dec_uint(shared_memory.m4_stack_usage, 6)); text_info_line_6.set(to_string_dec_uint(shared_memory.m4_cpu_usage, 6)); diff --git a/firmware/baseband/CMakeLists.txt b/firmware/baseband/CMakeLists.txt index 0d6e6947..b19059d4 100644 --- a/firmware/baseband/CMakeLists.txt +++ b/firmware/baseband/CMakeLists.txt @@ -139,6 +139,7 @@ set(CPPSRC ${COMMON}/chibios_cpp.cpp debug.cpp ${COMMON}/gcc.cpp + ${COMMON}/performance_counter.cpp tone_gen.cpp ) diff --git a/firmware/baseband/debug.cpp b/firmware/baseband/debug.cpp index 450c9bce..032d0042 100644 --- a/firmware/baseband/debug.cpp +++ b/firmware/baseband/debug.cpp @@ -26,6 +26,7 @@ #include #include "portapack_shared_memory.hpp" +#include "performance_counter.hpp" void write_m4_panic_msg(const char *panic_message, struct extctx *ctxp) { if (ctxp == nullptr) { @@ -120,29 +121,25 @@ void update_performance_counters() { auto performance_counter_active = shared_memory.request_m4_performance_counter; if (performance_counter_active == 0x00) return; + static bool last_paint_state = false; if ((((chTimeNow()>>10) & 0x01) == 0x01) == last_paint_state) return; + volatile auto idle_thread = chSysGetIdleThread(); + if (chThdGetTicks(idle_thread) > 0x10000000) { + return; + } + + idle_thread = nullptr; + last_paint_state = !last_paint_state; - auto now = chTimeNow(); - auto idle_ticks = chThdGetTicks(chSysGetIdleThread()); - - static systime_t last_time; - static systime_t last_last_time; - - auto time_elapsed = now - last_time; - auto idle_elapsed = idle_ticks - last_last_time; - - last_time = now; - last_last_time = idle_ticks; - - auto cpu_usage = (time_elapsed - idle_elapsed) / 10; + auto utilisation = get_cpu_utilisation_in_percent(); auto free_stack = (uint32_t)get_free_stack_space(); auto free_heap = chCoreStatus(); - shared_memory.m4_cpu_usage = cpu_usage; + shared_memory.m4_cpu_usage = utilisation; shared_memory.m4_stack_usage = free_stack; shared_memory.m4_heap_usage = free_heap; } diff --git a/firmware/common/performance_counter.cpp b/firmware/common/performance_counter.cpp new file mode 100644 index 00000000..d5de2ebc --- /dev/null +++ b/firmware/common/performance_counter.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2023 Bernd Herzog + * + * This file is part of PortaPack. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#include "performance_counter.hpp" +#include "ch.h" + +uint8_t get_cpu_utilisation_in_percent() { + static systime_t last_time = 0; + static systime_t last_idle_ticks = 0; + + auto now = chTimeNow(); + auto idle_ticks = chThdGetTicks(chSysGetIdleThread()); + + if (last_time == 0) { + last_time = now; + last_idle_ticks = idle_ticks; + + return 0; + } + + int32_t time_elapsed = now - last_time; + int32_t idle_elapsed = idle_ticks - last_idle_ticks; + + int32_t working_ticks = time_elapsed - idle_elapsed; + + if (working_ticks < 0) + working_ticks = 0; + + auto utilisation = working_ticks * 100 / time_elapsed; + + last_time = now; + last_idle_ticks = idle_ticks; + + if (utilisation > 100) { + return 100; + } + + return (uint8_t) utilisation; +} diff --git a/firmware/common/performance_counter.hpp b/firmware/common/performance_counter.hpp new file mode 100644 index 00000000..4b9b43cb --- /dev/null +++ b/firmware/common/performance_counter.hpp @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2023 Bernd Herzog + * + * This file is part of PortaPack. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __PERFORMANCE_COUNTER_H__ +#define __PERFORMANCE_COUNTER_H__ + +#include + +uint8_t get_cpu_utilisation_in_percent(); + +#endif /* __PERFORMANCE_COUNTER_H__ */ \ No newline at end of file From 4ff92be23b72154ceeff666d290572f80437c898 Mon Sep 17 00:00:00 2001 From: Bernd Herzog Date: Mon, 24 Apr 2023 13:04:59 +0200 Subject: [PATCH 09/11] refactoring --- firmware/baseband/debug.cpp | 7 ++----- firmware/common/performance_counter.hpp | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/firmware/baseband/debug.cpp b/firmware/baseband/debug.cpp index 032d0042..58548e7a 100644 --- a/firmware/baseband/debug.cpp +++ b/firmware/baseband/debug.cpp @@ -126,12 +126,9 @@ void update_performance_counters() { if ((((chTimeNow()>>10) & 0x01) == 0x01) == last_paint_state) return; - volatile auto idle_thread = chSysGetIdleThread(); - if (chThdGetTicks(idle_thread) > 0x10000000) { + // Idle thread state is sometimes unuseable + if (chThdGetTicks(chSysGetIdleThread()) > 0x10000000) return; - } - - idle_thread = nullptr; last_paint_state = !last_paint_state; diff --git a/firmware/common/performance_counter.hpp b/firmware/common/performance_counter.hpp index 4b9b43cb..ee3655ad 100644 --- a/firmware/common/performance_counter.hpp +++ b/firmware/common/performance_counter.hpp @@ -26,4 +26,4 @@ uint8_t get_cpu_utilisation_in_percent(); -#endif /* __PERFORMANCE_COUNTER_H__ */ \ No newline at end of file +#endif /* __PERFORMANCE_COUNTER_H__ */ From e53514aa12873f9c6c2f65b2c5640a77347bc455 Mon Sep 17 00:00:00 2001 From: GullCode Date: Mon, 24 Apr 2023 13:51:31 +0200 Subject: [PATCH 10/11] tweaking scan start values and ranges, allowing <24MHz range --- .../application/apps/ui_looking_glass_app.cpp | 60 ++++++++++++------- .../application/apps/ui_looking_glass_app.hpp | 12 +++- 2 files changed, 49 insertions(+), 23 deletions(-) diff --git a/firmware/application/apps/ui_looking_glass_app.cpp b/firmware/application/apps/ui_looking_glass_app.cpp index 17fdcca9..5d696476 100644 --- a/firmware/application/apps/ui_looking_glass_app.cpp +++ b/firmware/application/apps/ui_looking_glass_app.cpp @@ -1,7 +1,6 @@ /* * Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc. * Copyright (C) 2020 euquiq - * Copyright (C) 2023 gullradriel, Nilorea Studio Inc. * * This file is part of PortaPack. * @@ -39,6 +38,16 @@ namespace ui baseband::shutdown(); } + // Returns the next multiple of num that is a multiple of multiplier + int64_t GlassView::next_mult_of(int64_t num, int64_t multiplier) { + return ((num / multiplier) + 1) * multiplier; + } + + // Returns the previous multiple of num that is a multiple of multiplier + //int64_t GlassView::prev_mult_of(int64_t num, int64_t multiplier) { + // return (num / multiplier) * multiplier; + //} + void GlassView::adjust_range(int64_t* f_min, int64_t* f_max, int64_t width) { int64_t span = *f_max - *f_min; int64_t num_intervals = span / width; @@ -136,7 +145,7 @@ namespace ui void GlassView::on_channel_spectrum(const ChannelSpectrum &spectrum) { baseband::spectrum_streaming_stop(); - if( fast_scan ) + if( fast_scan || ( LOOKING_GLASS_SLICE_WIDTH < LOOKING_GLASS_SLICE_WIDTH_MAX ) ) { // Convert bins of this spectrum slice into a representative max_power and when enough, into pixels // Spectrum.db has 256 bins. Center 12 bins are ignored (DC spike is blanked) Leftmost and rightmost 2 bins are ignored @@ -168,7 +177,7 @@ namespace ui if (!pixel_index) // Received indication that a waterfall line has been completed { bins_Hz_size = 0; // Since this is an entire pixel line, we don't carry "Pixels into next bin" - f_center = f_center_ini; // Start a new sweep + f_center = f_center_ini - 2 * each_bin_size ; // Start a new sweep radio::set_tuning_frequency(f_center); // tune rx for this new slice directly, faster than using persistent memory saving chThdSleepMilliseconds(10); baseband::spectrum_streaming_start(); // Do the RX @@ -177,15 +186,14 @@ namespace ui bins_Hz_size -= marker_pixel_step; // reset bins size, but carrying the eventual excess Hz into next pixel } } - - f_center += LOOKING_GLASS_SLICE_WIDTH; // Move into the next bandwidth slice NOTE: spectrum.sampling_rate = LOOKING_GLASS_SLICE_WIDTH + f_center += 240 * each_bin_size ; // Move into the next bandwidth slice NOTE: spectrum.sampling_rate = LOOKING_GLASS_SLICE_WIDTH } else //slow scan { - for( int16_t bin = 0 ; bin < 120 ; bin++) + for (uint8_t bin = 0; bin < 120 ; bin++) { if (spectrum.db[134 + bin] > max_power) // 134 - max_power = spectrum.db[134 + bin]; + max_power = spectrum.db[134 + bin]; bins_Hz_size += each_bin_size; // add this bin Hz count into the "pixel fulfilled bag of Hz" @@ -200,8 +208,8 @@ namespace ui if (!pixel_index) // Received indication that a waterfall line has been completed { - bins_Hz_size = 0; // Since this is an entire pixel line, we don't carry "Pixels into next bin" - f_center = f_center_ini; // Start a new sweep + bins_Hz_size = 0; // Since this is an entire pixel line, we don't carry "Pixels into next bin" + f_center = f_center_ini - 2 * each_bin_size ; // Start a new sweep radio::set_tuning_frequency(f_center); // tune rx for this new slice directly, faster than using persistent memory saving chThdSleepMilliseconds(10); baseband::spectrum_streaming_start(); // Do the RX @@ -210,11 +218,10 @@ namespace ui bins_Hz_size -= marker_pixel_step; // reset bins size, but carrying the eventual excess Hz into next pixel } } - f_center += LOOKING_GLASS_SLICE_WIDTH / 2 ; + f_center += 120 * each_bin_size ; } radio::set_tuning_frequency(f_center); // tune rx for this new slice directly, faster than using persistent memory saving chThdSleepMilliseconds(5); - // receiver_model.set_tuning_frequency(f_center); //tune rx for this slice baseband::spectrum_streaming_start(); // Do the RX } @@ -269,7 +276,20 @@ namespace ui pixel_index = 0; // reset pixel counter max_power = 0; bins_Hz_size = 0; // reset amount of Hz filled up by pixels - + if( next_mult_of( (f_max - f_min) , 240 ) <= LOOKING_GLASS_SLICE_WIDTH_MAX ) + { + LOOKING_GLASS_SLICE_WIDTH = next_mult_of( (f_max - f_min) , 240 ); + receiver_model.set_sampling_rate(LOOKING_GLASS_SLICE_WIDTH); + receiver_model.set_baseband_bandwidth(LOOKING_GLASS_SLICE_WIDTH/2); + } + else if( LOOKING_GLASS_SLICE_WIDTH != LOOKING_GLASS_SLICE_WIDTH_MAX ) + { + LOOKING_GLASS_SLICE_WIDTH = LOOKING_GLASS_SLICE_WIDTH_MAX ; + receiver_model.set_sampling_rate(LOOKING_GLASS_SLICE_WIDTH); + receiver_model.set_baseband_bandwidth(LOOKING_GLASS_SLICE_WIDTH); + } + receiver_model.set_squelch_level(0); + each_bin_size = LOOKING_GLASS_SLICE_WIDTH / 240 ; baseband::set_spectrum(LOOKING_GLASS_SLICE_WIDTH, field_trigger.value()); receiver_model.set_tuning_frequency(f_center_ini); // tune rx for this slice } @@ -324,8 +344,8 @@ namespace ui int32_t min_size = steps ; if( locked_range ) min_size = search_span ; - if( min_size < 20 ) - min_size = 20 ; + if( min_size < 2 ) + min_size = 2 ; if( v > 7200 - min_size ) { v = 7200 - min_size ; @@ -347,8 +367,8 @@ namespace ui int32_t min_size = steps ; if( locked_range ) min_size = search_span ; - if( min_size < 20 ) - min_size = 20 ; + if( min_size < 2 ) + min_size = 2 ; if( freq > (7200 - min_size ) ) freq = 7200 - min_size ; field_frequency_min.set_value( freq ); @@ -364,8 +384,8 @@ namespace ui int32_t min_size = steps ; if( locked_range ) min_size = search_span ; - if( min_size < 20 ) - min_size = 20 ; + if( min_size < 2 ) + min_size = 2 ; if( v < min_size ) { v = min_size ; @@ -386,8 +406,8 @@ namespace ui int32_t min_size = steps ; if( locked_range ) min_size = search_span ; - if( min_size < 20 ) - min_size = 20 ; + if( min_size < 2 ) + min_size = 2 ; int32_t freq = f / 1000000 ; if( freq < min_size ) freq = min_size ; diff --git a/firmware/application/apps/ui_looking_glass_app.hpp b/firmware/application/apps/ui_looking_glass_app.hpp index 6a885c44..5b1df967 100644 --- a/firmware/application/apps/ui_looking_glass_app.hpp +++ b/firmware/application/apps/ui_looking_glass_app.hpp @@ -37,6 +37,7 @@ namespace ui { +#define LOOKING_GLASS_SLICE_WIDTH_MAX 19999920 #define MHZ_DIV 1000000 #define X2_MHZ_DIV 2000000 @@ -80,11 +81,16 @@ namespace ui std::vector presets_db{}; - int64_t LOOKING_GLASS_SLICE_WIDTH = 19999920; // Each slice bandwidth 20 MHz and a multiple of 240 - // since we are using LOOKING_GLASS_SLICE_WIDTH/240 as the each_bin_size - // it should also be a multiple of 2 since we are using LOOKING_GLASS_SLICE_WIDTH / 2 as centering freq + // Each slice bandwidth 20 MHz and a multiple of 240 + // since we are using LOOKING_GLASS_SLICE_WIDTH/240 as the each_bin_size + // it should also be a multiple of 2 since we are using LOOKING_GLASS_SLICE_WIDTH / 2 as centering freq + int64_t LOOKING_GLASS_SLICE_WIDTH = 19999920; + // frequency rounding helpers + int64_t next_mult_of(int64_t num, int64_t multiplier); + //int64_t prev_mult_of(int64_t num, int64_t multiplier); void adjust_range(int64_t* f_min, int64_t* f_max, int64_t width); + void on_channel_spectrum(const ChannelSpectrum& spectrum); void do_timers(); void on_range_changed(); From 45bdabcef9f84908ad8a6e9a0a885bfdbdcd0997 Mon Sep 17 00:00:00 2001 From: GullCode Date: Mon, 24 Apr 2023 21:14:34 +0200 Subject: [PATCH 11/11] Fix for description being updated at each step on a range --- firmware/application/apps/ui_recon.cpp | 40 ++++++++++++-------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/firmware/application/apps/ui_recon.cpp b/firmware/application/apps/ui_recon.cpp index afe70ead..38b49563 100644 --- a/firmware/application/apps/ui_recon.cpp +++ b/firmware/application/apps/ui_recon.cpp @@ -528,32 +528,28 @@ namespace ui { } } } - } - - uint32_t freq_lock = recon_thread->is_freq_lock(); - - if( freq_lock == 0 ) { - //NO FREQ LOCK, ONGOING STANDARD SCANNING - if( index < 1000 && index < frequency_list.size() ) + text_cycle.set_text( to_string_dec_uint( index + 1 , 3 ) ); + if(frequency_list[index].description.size() > 0) { - text_cycle.set_text( to_string_dec_uint( index + 1 , 3 ) ); - if(frequency_list[index].description.size() > 0) + switch( frequency_list[current_index].type ) { - switch( frequency_list[current_index].type ) - { - case RANGE: - desc_cycle.set( "R: " + frequency_list[current_index].description ); //Show new description - break ; - case HAMRADIO: - desc_cycle.set( "H: " + frequency_list[current_index].description ); //Show new description - break ; - default: - case SINGLE: - desc_cycle.set( "S: " + frequency_list[current_index].description ); //Show new description - break ; - } + case RANGE: + desc_cycle.set( "R: " + frequency_list[current_index].description ); //Show new description + break ; + case HAMRADIO: + desc_cycle.set( "H: " + frequency_list[current_index].description ); //Show new description + break ; + default: + case SINGLE: + desc_cycle.set( "S: " + frequency_list[current_index].description ); //Show new description + break ; } } + } + + uint32_t freq_lock = recon_thread->is_freq_lock(); + if( freq_lock == 0 ) { + //NO FREQ LOCK, ONGOING STANDARD SCANNING big_display.set_style(&style_white); if( !userpause ) button_pause.set_text("");