From 7f9bc6bf6f8ee58c58e4b476bb315ff0fa0ded68 Mon Sep 17 00:00:00 2001 From: Maciej Gibowicz Date: Mon, 29 Nov 2021 18:03:39 +0100 Subject: [PATCH] [EGD-7922] Added Permanent Frequency Setting Added Permanent Frequency setting in Advanced Developer Mode with simple set window. --- .../ApplicationSettings.cpp | 4 + .../application-settings/CMakeLists.txt | 1 + .../windows/WindowNames.hpp | 1 + .../advanced/AdvancedOptionsWindow.cpp | 1 + .../windows/advanced/CPUModeTestWindow.cpp | 193 ++++++++++++++++++ .../windows/advanced/CPUModeTestWindow.hpp | 34 +++ .../linux/eink_frontlight/eink_frontlight.cpp | 2 +- module-bsp/board/linux/lpm/LinuxLPM.cpp | 2 +- module-bsp/board/linux/lpm/LinuxLPM.h | 2 +- module-bsp/board/linux/lpm/PowerProfile.cpp | 2 +- module-bsp/board/linux/vibrator/vibrator.cpp | 2 +- .../rt1051/bellpx/bsp/lpm/PowerProfile.cpp | 2 +- .../bsp/eink_frontlight/eink_frontlight.cpp | 2 +- module-bsp/board/rt1051/bsp/lpm/RT1051LPM.cpp | 16 +- module-bsp/board/rt1051/bsp/lpm/RT1051LPM.hpp | 2 +- .../board/rt1051/bsp/vibrator/vibrator.cpp | 2 +- .../rt1051/puretx/bsp/lpm/PowerProfile.cpp | 2 +- module-bsp/bsp/common.hpp | 16 +- .../bsp/eink_frontlight/eink_frontlight.hpp | 2 +- module-bsp/bsp/lpm/PowerProfile.hpp | 2 +- module-bsp/bsp/lpm/bsp_lpm.cpp | 2 +- module-bsp/bsp/lpm/bsp_lpm.hpp | 6 +- module-bsp/bsp/vibrator/vibrator.hpp | 2 +- .../service-audio/ServiceAudio.cpp | 2 +- .../service-bluetooth/ServiceBluetooth.cpp | 2 +- .../service-cellular/CellularCall.cpp | 2 +- .../service-cellular/ServiceCellular.cpp | 2 +- .../ConnectionManagerCellularCommands.cpp | 2 +- .../service-desktop/WorkerDesktop.cpp | 2 +- .../service-evtmgr/EventManager.cpp | 2 +- .../service-evtmgr/WorkerEventCommon.cpp | 4 +- .../service-evtmgr/EventManagerCommon.hpp | 2 +- .../service-evtmgr/WorkerEventCommon.hpp | 2 +- module-sys/SystemManager/CpuGovernor.cpp | 58 +++++- module-sys/SystemManager/CpuSentinel.cpp | 57 +++++- module-sys/SystemManager/PowerManager.cpp | 87 +++++--- .../SystemManager/SystemManagerCommon.cpp | 26 ++- .../include/SystemManager/CpuGovernor.hpp | 22 +- .../include/SystemManager/CpuSentinel.hpp | 28 ++- .../include/SystemManager/PowerManager.hpp | 13 +- .../SystemManager/SystemManagerCommon.hpp | 2 +- .../tests/unittest_CpuSentinelsGovernor.cpp | 26 +-- .../messages/RequestCpuFrequencyMessage.hpp | 19 +- .../messages/SentinelRegistrationMessage.hpp | 20 +- products/BellHybrid/EinkSentinelBell.cpp | 2 +- .../services/audio/ServiceAudio.cpp | 2 +- .../ScreenLightControl.cpp | 2 +- .../UserActivityHandler.cpp | 2 +- products/PurePhone/EinkSentinelPure.cpp | 4 +- source/MessageType.hpp | 3 +- 50 files changed, 556 insertions(+), 139 deletions(-) create mode 100644 module-apps/application-settings/windows/advanced/CPUModeTestWindow.cpp create mode 100644 module-apps/application-settings/windows/advanced/CPUModeTestWindow.hpp diff --git a/module-apps/application-settings/ApplicationSettings.cpp b/module-apps/application-settings/ApplicationSettings.cpp index c0d901e85..b58497d7d 100644 --- a/module-apps/application-settings/ApplicationSettings.cpp +++ b/module-apps/application-settings/ApplicationSettings.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -368,6 +369,9 @@ namespace app windowsFactory.attach(gui::window::name::ui_test, [](ApplicationCommon *app, const std::string &name) { return std::make_unique(app); }); + windowsFactory.attach(gui::window::name::cpu_test_window, [](ApplicationCommon *app, const std::string &name) { + return std::make_unique(app); + }); windowsFactory.attach(gui::window::name::color_test_window, [](ApplicationCommon *app, const std::string &name) { return std::make_unique(app); diff --git a/module-apps/application-settings/CMakeLists.txt b/module-apps/application-settings/CMakeLists.txt index a7ac3e1a7..aa13b4999 100644 --- a/module-apps/application-settings/CMakeLists.txt +++ b/module-apps/application-settings/CMakeLists.txt @@ -47,6 +47,7 @@ target_sources(application-settings windows/SettingsMainWindow.cpp windows/advanced/AdvancedOptionsWindow.cpp windows/advanced/ColorTestWindow.cpp + windows/advanced/CPUModeTestWindow.cpp windows/advanced/InformationWindow.cpp windows/advanced/TextImageColorWindow.cpp windows/advanced/UITestWindow.cpp diff --git a/module-apps/application-settings/windows/WindowNames.hpp b/module-apps/application-settings/windows/WindowNames.hpp index dffd5cd28..46af0a96d 100644 --- a/module-apps/application-settings/windows/WindowNames.hpp +++ b/module-apps/application-settings/windows/WindowNames.hpp @@ -9,6 +9,7 @@ namespace gui::window::name inline constexpr auto information = "Information"; inline constexpr auto ui_test = "UI Test"; inline constexpr auto color_test_window = "Color Test"; + inline constexpr auto cpu_test_window = "CPUModeTest"; inline constexpr auto status_bar_img_type = "StatusBarImgType"; inline constexpr auto text_image_color = "TextImageColor"; diff --git a/module-apps/application-settings/windows/advanced/AdvancedOptionsWindow.cpp b/module-apps/application-settings/windows/advanced/AdvancedOptionsWindow.cpp index 79405882f..6fd8a9dad 100644 --- a/module-apps/application-settings/windows/advanced/AdvancedOptionsWindow.cpp +++ b/module-apps/application-settings/windows/advanced/AdvancedOptionsWindow.cpp @@ -28,6 +28,7 @@ std::list advancedOptions(app::ApplicationCommon *app) addMenu("Color Test", gui::window::name::color_test_window); addMenu("Statusbar Image Test", gui::window::name::status_bar_img_type); addMenu("Text Image Color test", gui::window::name::text_image_color); + addMenu("CPU Mode Test", gui::window::name::cpu_test_window); return l; } diff --git a/module-apps/application-settings/windows/advanced/CPUModeTestWindow.cpp b/module-apps/application-settings/windows/advanced/CPUModeTestWindow.cpp new file mode 100644 index 000000000..9d1bbece6 --- /dev/null +++ b/module-apps/application-settings/windows/advanced/CPUModeTestWindow.cpp @@ -0,0 +1,193 @@ +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#include "CPUModeTestWindow.hpp" + +#include +#include +#include +#include +#include + +#include + +namespace magic_enum +{ + template <> struct enum_range + { + static constexpr int min = 0; + static constexpr int max = 528; + }; +} // namespace magic_enum + +namespace gui +{ + CPUModeTestWindow::CPUModeTestWindow(app::ApplicationCommon *app) : AppWindow(app, window::name::cpu_test_window) + { + cpuModeTester = std::make_shared(name, app, [&](bsp::CpuFrequencyMHz freq) { + auto freqToPrint = std::to_string(magic_enum::enum_integer(freq)); + currentFreqValue->setMinimumWidthToFitText(freqToPrint); + currentFreqValue->setMaximumWidth(currentFreqValue->widgetMinimumArea.w); + currentFreqValue->informContentChanged(); + currentFreqValue->setText(freqToPrint); + + application->refreshWindow(RefreshModes::GUI_REFRESH_FAST); + }); + + auto sentinelRegistrationMsg = std::make_shared(cpuModeTester); + application->bus.sendUnicastSync(sentinelRegistrationMsg, service::name::system_manager, 30); + + AppWindow::buildInterface(); + + navBar->setText(nav_bar::Side::Right, utils::translate(style::strings::common::back)); + + setTitle(name); + + body = new VBox(this, + style::window::default_left_margin, + style::window::default_vertical_pos, + style::window::default_body_width, + style::window::default_body_height); + + body->setAlignment(Alignment(Alignment::Horizontal::Center, Alignment::Vertical::Top)); + body->setEdges(RectangleEdge::None); + + createCurrentFreqBox(); + createPermanentFreqSettingBox(); + createNewFreqBox(); + + body->resizeItems(); + setFocusItem(body); + } + + void CPUModeTestWindow::onClose(Window::CloseReason reason) + { + if (reason != Window::CloseReason::Popup && reason != Window::CloseReason::PhoneLock) { + auto sentinelRemovalMessage = std::make_shared(name); + application->bus.sendUnicastSync(sentinelRemovalMessage, service::name::system_manager, 30); + } + } + + void CPUModeTestWindow::onBeforeShow(ShowMode mode, SwitchData *data) + { + auto freqToPrint = std::to_string(magic_enum::enum_integer(cpuModeTester->GetFrequency())); + + currentFreqValue->setMinimumWidthToFitText(freqToPrint); + currentFreqValue->setMinimumHeightToFitText(); + currentFreqValue->setMaximumWidth(currentFreqValue->widgetMinimumArea.w); + currentFreqValue->informContentChanged(); + currentFreqValue->setText(freqToPrint); + } + + void CPUModeTestWindow::createCurrentFreqBox() + { + auto currentFreqBody = new VBox(body); + currentFreqBody->setAlignment(Alignment(Alignment::Horizontal::Center, Alignment::Vertical::Center)); + currentFreqBody->setEdges(RectangleEdge::None); + currentFreqBody->setMinimumSize(style::window::default_body_width, 80); + currentFreqBody->setMargins({0, 60, 0, 30}); + currentFreqBody->activeItem = false; + + auto currentFreqLabel = new TextFixedSize(currentFreqBody); + currentFreqLabel->setAlignment({Alignment::Horizontal::Center}); + currentFreqLabel->setFont(style::window::font::small); + currentFreqLabel->setMinimumWidth(style::window::default_body_width); + currentFreqLabel->setMinimumHeightToFitText(); + currentFreqLabel->setMargins({0, 0, 0, 15}); + currentFreqLabel->setText("Current CPU Frequency [MHz]:"); + currentFreqLabel->setEdges(RectangleEdge::None); + currentFreqLabel->drawUnderline(false); + + currentFreqValue = new TextFixedSize(currentFreqBody); + currentFreqValue->setAlignment({Alignment::Horizontal::Center}); + currentFreqValue->setFont(style::window::font::mediumbold); + currentFreqValue->setPenWidth(style::window::default_border_focus_w); + currentFreqValue->setEdges(RectangleEdge::Bottom); + currentFreqValue->drawUnderline(false); + currentFreqValue->setEditMode(EditMode::Browse); + currentFreqValue->activeItem = false; + } + + void CPUModeTestWindow::createPermanentFreqSettingBox() + { + auto permanentFreqBody = new VBox(body); + permanentFreqBody->setAlignment(Alignment(Alignment::Horizontal::Center, Alignment::Vertical::Center)); + permanentFreqBody->setEdges(RectangleEdge::None); + permanentFreqBody->setMinimumSize(style::window::default_body_width, 80); + permanentFreqBody->setMargins({0, 0, 0, 30}); + + auto permanentFreqLabel = new TextFixedSize(permanentFreqBody); + permanentFreqLabel->setAlignment({Alignment::Horizontal::Center}); + permanentFreqLabel->setFont(style::window::font::small); + permanentFreqLabel->setMinimumWidth(style::window::default_body_width); + permanentFreqLabel->setMinimumHeightToFitText(); + permanentFreqLabel->setMargins({0, 0, 0, 15}); + permanentFreqLabel->setText("Set Permanent Frequency:"); + permanentFreqLabel->setEdges(RectangleEdge::None); + permanentFreqLabel->drawUnderline(false); + permanentFreqLabel->activeItem = false; + + permanentFreqSpinner = new gui::TextSpinnerBox(permanentFreqBody, {"OFF", "ON"}, Boundaries::Continuous); + permanentFreqSpinner->setMinimumSize(100, 30); + permanentFreqSpinner->setCurrentValue(cpuModeTester->isPermanentFrequencyActive() ? "ON" : "OFF"); + + permanentFreqBody->inputCallback = [&](Item &item, const InputEvent &event) { + auto ret = permanentFreqSpinner->onInput(event); + if (ret) { + if (permanentFreqSpinner->getCurrentValue() == "ON") { + cpuModeTester->HoldFrequencyPermanently( + magic_enum::enum_cast(std::stoi(currentFreqSpinner->getCurrentValue())) + .value()); + } + else { + cpuModeTester->ReleasePermanentFrequency(); + } + } + + return ret; + }; + } + + void CPUModeTestWindow::createNewFreqBox() + { + auto newFreqBody = new VBox(body); + newFreqBody->setAlignment(Alignment(Alignment::Horizontal::Center, Alignment::Vertical::Center)); + newFreqBody->setEdges(RectangleEdge::None); + newFreqBody->setMinimumSize(style::window::default_body_width, 80); + + auto newFreqLabel = new TextFixedSize(newFreqBody); + newFreqLabel->setAlignment({Alignment::Horizontal::Center}); + newFreqLabel->setFont(style::window::font::small); + newFreqLabel->setMinimumWidth(style::window::default_body_width); + newFreqLabel->setMinimumHeightToFitText(); + newFreqLabel->setMargins({0, 0, 0, 15}); + newFreqLabel->setText("New Frequency to set [MHz]:"); + newFreqLabel->setEdges(RectangleEdge::None); + newFreqLabel->drawUnderline(false); + newFreqLabel->activeItem = false; + + std::vector freqOptions; + for (auto val : magic_enum::enum_values()) { + if (val <= bsp::getPowerProfile().minimalFrequency) { + continue; + } + + freqOptions.push_back(std::to_string(static_cast(val))); + } + + currentFreqSpinner = new gui::TextSpinnerBox(newFreqBody, freqOptions, Boundaries::Continuous); + currentFreqSpinner->setMinimumSize(100, 30); + + newFreqBody->inputCallback = [&](Item &item, const InputEvent &event) { + auto ret = currentFreqSpinner->onInput(event); + + if (cpuModeTester->isPermanentFrequencyActive()) { + cpuModeTester->HoldFrequencyPermanently( + magic_enum::enum_cast(std::stoi(currentFreqSpinner->getCurrentValue())) + .value()); + } + + return ret; + }; + } +} /* namespace gui */ diff --git a/module-apps/application-settings/windows/advanced/CPUModeTestWindow.hpp b/module-apps/application-settings/windows/advanced/CPUModeTestWindow.hpp new file mode 100644 index 000000000..d71ca55be --- /dev/null +++ b/module-apps/application-settings/windows/advanced/CPUModeTestWindow.hpp @@ -0,0 +1,34 @@ +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md +#pragma once + +#include "AppWindow.hpp" + +#include +#include +#include + +namespace gui +{ + class CPUModeTestWindow : public AppWindow + { + private: + static inline auto name = "CPU Mode Tester"; + + VBox *body = nullptr; + TextFixedSize *currentFreqValue = nullptr; + TextSpinnerBox *currentFreqSpinner = nullptr; + TextSpinnerBox *permanentFreqSpinner = nullptr; + + std::shared_ptr cpuModeTester; + + void createCurrentFreqBox(); + void createPermanentFreqSettingBox(); + void createNewFreqBox(); + + public: + explicit CPUModeTestWindow(app::ApplicationCommon *app); + void onClose(CloseReason reason) override; + void onBeforeShow(ShowMode mode, SwitchData *data) override; + }; +} /* namespace gui */ diff --git a/module-bsp/board/linux/eink_frontlight/eink_frontlight.cpp b/module-bsp/board/linux/eink_frontlight/eink_frontlight.cpp index 918c664df..e4c51f8cb 100644 --- a/module-bsp/board/linux/eink_frontlight/eink_frontlight.cpp +++ b/module-bsp/board/linux/eink_frontlight/eink_frontlight.cpp @@ -23,7 +23,7 @@ namespace bsp::eink_frontlight void setGammaFactor(float) {} - void updateClockFrequency(CpuFrequencyHz newFrequency) + void updateClockFrequency(CpuFrequencyMHz newFrequency) {} } // namespace bsp::eink_frontlight diff --git a/module-bsp/board/linux/lpm/LinuxLPM.cpp b/module-bsp/board/linux/lpm/LinuxLPM.cpp index 13fa2b8ff..f340914b5 100644 --- a/module-bsp/board/linux/lpm/LinuxLPM.cpp +++ b/module-bsp/board/linux/lpm/LinuxLPM.cpp @@ -20,7 +20,7 @@ namespace bsp return 0; } - void LinuxLPM::SetCpuFrequency(bsp::CpuFrequencyHz freq) + void LinuxLPM::SetCpuFrequency(bsp::CpuFrequencyMHz freq) { currentFrequency = freq; } diff --git a/module-bsp/board/linux/lpm/LinuxLPM.h b/module-bsp/board/linux/lpm/LinuxLPM.h index 28a63d340..8bcdc96e9 100644 --- a/module-bsp/board/linux/lpm/LinuxLPM.h +++ b/module-bsp/board/linux/lpm/LinuxLPM.h @@ -14,7 +14,7 @@ namespace bsp public: int32_t PowerOff() override final; int32_t Reboot(RebootType reason) override final; - void SetCpuFrequency(CpuFrequencyHz freq) final; + void SetCpuFrequency(CpuFrequencyMHz freq) final; void SetHighestCoreVoltage() final; [[nodiscard]] uint32_t GetCpuFrequency() const noexcept final; void SwitchOscillatorSource(OscillatorSource source) final; diff --git a/module-bsp/board/linux/lpm/PowerProfile.cpp b/module-bsp/board/linux/lpm/PowerProfile.cpp index c7827e09e..8945af6ea 100644 --- a/module-bsp/board/linux/lpm/PowerProfile.cpp +++ b/module-bsp/board/linux/lpm/PowerProfile.cpp @@ -14,7 +14,7 @@ namespace bsp linuxPowerProfile.maxBelowThresholdCount = 30; linuxPowerProfile.maxBelowThresholdInRowCount = 10; linuxPowerProfile.maxAboveThresholdCount = 3; - linuxPowerProfile.minimalFrequency = CpuFrequencyHz::Level_1; + linuxPowerProfile.minimalFrequency = CpuFrequencyMHz::Level_1; linuxPowerProfile.frequencyIncreaseIntermediateStep = false; return linuxPowerProfile; diff --git a/module-bsp/board/linux/vibrator/vibrator.cpp b/module-bsp/board/linux/vibrator/vibrator.cpp index 8ade90420..1f0a499be 100644 --- a/module-bsp/board/linux/vibrator/vibrator.cpp +++ b/module-bsp/board/linux/vibrator/vibrator.cpp @@ -21,7 +21,7 @@ namespace bsp {} void deinit() {} - void updateClockFrequency(CpuFrequencyHz newFrequency) + void updateClockFrequency(CpuFrequencyMHz newFrequency) {} void setVibrationLevel(unsigned int vibrationLevel) {} diff --git a/module-bsp/board/rt1051/bellpx/bsp/lpm/PowerProfile.cpp b/module-bsp/board/rt1051/bellpx/bsp/lpm/PowerProfile.cpp index 8d925ecb6..a8bd34351 100644 --- a/module-bsp/board/rt1051/bellpx/bsp/lpm/PowerProfile.cpp +++ b/module-bsp/board/rt1051/bellpx/bsp/lpm/PowerProfile.cpp @@ -14,7 +14,7 @@ namespace bsp bellPowerProfile.maxBelowThresholdCount = 5; bellPowerProfile.maxBelowThresholdInRowCount = 1; bellPowerProfile.maxAboveThresholdCount = 2; - bellPowerProfile.minimalFrequency = CpuFrequencyHz::Level_0; + bellPowerProfile.minimalFrequency = CpuFrequencyMHz::Level_0; bellPowerProfile.frequencyIncreaseIntermediateStep = true; return bellPowerProfile; diff --git a/module-bsp/board/rt1051/bsp/eink_frontlight/eink_frontlight.cpp b/module-bsp/board/rt1051/bsp/eink_frontlight/eink_frontlight.cpp index b65082fa9..b594d6066 100644 --- a/module-bsp/board/rt1051/bsp/eink_frontlight/eink_frontlight.cpp +++ b/module-bsp/board/rt1051/bsp/eink_frontlight/eink_frontlight.cpp @@ -63,7 +63,7 @@ namespace bsp::eink_frontlight gammaFactor = gamma; } - void updateClockFrequency(CpuFrequencyHz newFrequency) + void updateClockFrequency(CpuFrequencyMHz newFrequency) { pwm->UpdateClockFrequency(static_cast(newFrequency)); } diff --git a/module-bsp/board/rt1051/bsp/lpm/RT1051LPM.cpp b/module-bsp/board/rt1051/bsp/lpm/RT1051LPM.cpp index d083a74f9..35d9ea69a 100644 --- a/module-bsp/board/rt1051/bsp/lpm/RT1051LPM.cpp +++ b/module-bsp/board/rt1051/bsp/lpm/RT1051LPM.cpp @@ -68,29 +68,29 @@ namespace bsp return 0; } - void RT1051LPM::SetCpuFrequency(bsp::CpuFrequencyHz freq) + void RT1051LPM::SetCpuFrequency(bsp::CpuFrequencyMHz freq) { currentFrequency = freq; switch (freq) { - case bsp::CpuFrequencyHz::Level_0: + case bsp::CpuFrequencyMHz::Level_0: CpuFreq->SetCpuFrequency(CpuFreqLPM::CpuClock::CpuClock_Osc_4_Mhz); break; - case bsp::CpuFrequencyHz::Level_1: + case bsp::CpuFrequencyMHz::Level_1: CpuFreq->SetCpuFrequency(CpuFreqLPM::CpuClock::CpuClock_Osc_12_Mhz); break; - case bsp::CpuFrequencyHz::Level_2: + case bsp::CpuFrequencyMHz::Level_2: CpuFreq->SetCpuFrequency(CpuFreqLPM::CpuClock::CpuClock_Osc_24_Mhz); break; - case bsp::CpuFrequencyHz::Level_3: + case bsp::CpuFrequencyMHz::Level_3: CpuFreq->SetCpuFrequency(CpuFreqLPM::CpuClock::CpuClock_Pll2_66_Mhz); break; - case bsp::CpuFrequencyHz::Level_4: + case bsp::CpuFrequencyMHz::Level_4: CpuFreq->SetCpuFrequency(CpuFreqLPM::CpuClock::CpuClock_Pll2_132_Mhz); break; - case bsp::CpuFrequencyHz::Level_5: + case bsp::CpuFrequencyMHz::Level_5: CpuFreq->SetCpuFrequency(CpuFreqLPM::CpuClock::CpuClock_Pll2_264_Mhz); break; - case bsp::CpuFrequencyHz::Level_6: + case bsp::CpuFrequencyMHz::Level_6: CpuFreq->SetCpuFrequency(CpuFreqLPM::CpuClock::CpuClock_Pll2_528_Mhz); break; } diff --git a/module-bsp/board/rt1051/bsp/lpm/RT1051LPM.hpp b/module-bsp/board/rt1051/bsp/lpm/RT1051LPM.hpp index b2b98fb37..ce957add0 100644 --- a/module-bsp/board/rt1051/bsp/lpm/RT1051LPM.hpp +++ b/module-bsp/board/rt1051/bsp/lpm/RT1051LPM.hpp @@ -16,7 +16,7 @@ namespace bsp RT1051LPM(); int32_t PowerOff() override final; int32_t Reboot(RebootType reason) override final; - void SetCpuFrequency(CpuFrequencyHz freq) final; + void SetCpuFrequency(CpuFrequencyMHz freq) final; void SetHighestCoreVoltage() final; [[nodiscard]] uint32_t GetCpuFrequency() const noexcept final; void SwitchOscillatorSource(OscillatorSource source) final; diff --git a/module-bsp/board/rt1051/bsp/vibrator/vibrator.cpp b/module-bsp/board/rt1051/bsp/vibrator/vibrator.cpp index 52ce12f43..b2b37ef5f 100644 --- a/module-bsp/board/rt1051/bsp/vibrator/vibrator.cpp +++ b/module-bsp/board/rt1051/bsp/vibrator/vibrator.cpp @@ -46,7 +46,7 @@ namespace bsp pwm->Stop(pwmChannel); } - void updateClockFrequency(CpuFrequencyHz newFrequency) + void updateClockFrequency(CpuFrequencyMHz newFrequency) { if (pwm) { pwm->UpdateClockFrequency(static_cast(newFrequency)); diff --git a/module-bsp/board/rt1051/puretx/bsp/lpm/PowerProfile.cpp b/module-bsp/board/rt1051/puretx/bsp/lpm/PowerProfile.cpp index 89b61797d..821c3677e 100644 --- a/module-bsp/board/rt1051/puretx/bsp/lpm/PowerProfile.cpp +++ b/module-bsp/board/rt1051/puretx/bsp/lpm/PowerProfile.cpp @@ -14,7 +14,7 @@ namespace bsp purePowerProfile.maxBelowThresholdCount = 30; purePowerProfile.maxBelowThresholdInRowCount = 10; purePowerProfile.maxAboveThresholdCount = 3; - purePowerProfile.minimalFrequency = CpuFrequencyHz::Level_1; + purePowerProfile.minimalFrequency = CpuFrequencyMHz::Level_1; purePowerProfile.frequencyIncreaseIntermediateStep = false; return purePowerProfile; diff --git a/module-bsp/bsp/common.hpp b/module-bsp/bsp/common.hpp index 69d924628..8dc36f3c6 100644 --- a/module-bsp/bsp/common.hpp +++ b/module-bsp/bsp/common.hpp @@ -13,15 +13,15 @@ namespace bsp /// CPU frequency is dependent on the clock settings. /// Only a few thresholds are available in the current configuration - enum class CpuFrequencyHz + enum class CpuFrequencyMHz { - Level_0 = 4000000, - Level_1 = 12000000, - Level_2 = 24000000, - Level_3 = 66000000, - Level_4 = 132000000, - Level_5 = 264000000, - Level_6 = 528000000 + Level_0 = 4, + Level_1 = 12, + Level_2 = 24, + Level_3 = 66, + Level_4 = 132, + Level_5 = 264, + Level_6 = 528 }; enum class Board{ diff --git a/module-bsp/bsp/eink_frontlight/eink_frontlight.hpp b/module-bsp/bsp/eink_frontlight/eink_frontlight.hpp index 1a41e1432..507f2e3af 100644 --- a/module-bsp/bsp/eink_frontlight/eink_frontlight.hpp +++ b/module-bsp/bsp/eink_frontlight/eink_frontlight.hpp @@ -30,5 +30,5 @@ namespace bsp::eink_frontlight void setGammaFactor(float gamma); - void updateClockFrequency(CpuFrequencyHz newFrequency); + void updateClockFrequency(CpuFrequencyMHz newFrequency); } // namespace bsp::eink_frontlight diff --git a/module-bsp/bsp/lpm/PowerProfile.hpp b/module-bsp/bsp/lpm/PowerProfile.hpp index c2987358f..6ccce80be 100644 --- a/module-bsp/bsp/lpm/PowerProfile.hpp +++ b/module-bsp/bsp/lpm/PowerProfile.hpp @@ -15,7 +15,7 @@ namespace bsp std::uint32_t maxBelowThresholdCount; std::uint32_t maxBelowThresholdInRowCount; std::uint32_t maxAboveThresholdCount; - CpuFrequencyHz minimalFrequency; + CpuFrequencyMHz minimalFrequency; bool frequencyIncreaseIntermediateStep; }; diff --git a/module-bsp/bsp/lpm/bsp_lpm.cpp b/module-bsp/bsp/lpm/bsp_lpm.cpp index cf83c3363..c0e2f83d2 100644 --- a/module-bsp/bsp/lpm/bsp_lpm.cpp +++ b/module-bsp/bsp/lpm/bsp_lpm.cpp @@ -29,7 +29,7 @@ namespace bsp{ return inst; } - CpuFrequencyHz LowPowerMode::GetCurrentFrequencyLevel() const noexcept + CpuFrequencyMHz LowPowerMode::GetCurrentFrequencyLevel() const noexcept { return currentFrequency; } diff --git a/module-bsp/bsp/lpm/bsp_lpm.hpp b/module-bsp/bsp/lpm/bsp_lpm.hpp index 892e082a9..4024575ff 100644 --- a/module-bsp/bsp/lpm/bsp_lpm.hpp +++ b/module-bsp/bsp/lpm/bsp_lpm.hpp @@ -34,9 +34,9 @@ namespace bsp virtual int32_t PowerOff() = 0; virtual int32_t Reboot(RebootType reason) = 0; - virtual void SetCpuFrequency(CpuFrequencyHz freq) = 0; + virtual void SetCpuFrequency(CpuFrequencyMHz freq) = 0; virtual void SetHighestCoreVoltage() = 0; - [[nodiscard]] CpuFrequencyHz GetCurrentFrequencyLevel() const noexcept; + [[nodiscard]] CpuFrequencyMHz GetCurrentFrequencyLevel() const noexcept; [[nodiscard]] virtual uint32_t GetCpuFrequency() const noexcept = 0; virtual void SwitchOscillatorSource(OscillatorSource source) = 0; @@ -52,6 +52,6 @@ namespace bsp virtual void SwitchToLowPowerModeLDO() = 0; protected: - CpuFrequencyHz currentFrequency = CpuFrequencyHz::Level_6; + CpuFrequencyMHz currentFrequency = CpuFrequencyMHz::Level_6; }; } // namespace bsp diff --git a/module-bsp/bsp/vibrator/vibrator.hpp b/module-bsp/bsp/vibrator/vibrator.hpp index 64f41bc40..473852ad0 100644 --- a/module-bsp/bsp/vibrator/vibrator.hpp +++ b/module-bsp/bsp/vibrator/vibrator.hpp @@ -25,7 +25,7 @@ namespace bsp void deinit(); void enable(); void disable(); - void updateClockFrequency(CpuFrequencyHz newFrequency); + void updateClockFrequency(CpuFrequencyMHz newFrequency); void setVibrationLevel(unsigned int vibrationLevel); } // namespace vibrator diff --git a/module-services/service-audio/ServiceAudio.cpp b/module-services/service-audio/ServiceAudio.cpp index fa13f2505..ca6832669 100644 --- a/module-services/service-audio/ServiceAudio.cpp +++ b/module-services/service-audio/ServiceAudio.cpp @@ -683,7 +683,7 @@ sys::MessagePointer ServiceAudio::DataReceivedHandler(sys::DataMessage *msgl, sy } if (const auto curIsBusy = IsBusy(); isBusy != curIsBusy) { - curIsBusy ? cpuSentinel->HoldMinimumFrequency(bsp::CpuFrequencyHz::Level_6) + curIsBusy ? cpuSentinel->HoldMinimumFrequency(bsp::CpuFrequencyMHz::Level_6) : cpuSentinel->ReleaseMinimumFrequency(); } diff --git a/module-services/service-bluetooth/ServiceBluetooth.cpp b/module-services/service-bluetooth/ServiceBluetooth.cpp index e80d2c5c4..2ec41a2ce 100644 --- a/module-services/service-bluetooth/ServiceBluetooth.cpp +++ b/module-services/service-bluetooth/ServiceBluetooth.cpp @@ -185,7 +185,7 @@ auto ServiceBluetooth::handle(message::bluetooth::SetStatus *msg) -> std::shared switch (newBtStatus.state) { case BluetoothStatus::State::On: - cpuSentinel->HoldMinimumFrequency(bsp::CpuFrequencyHz::Level_3); + cpuSentinel->HoldMinimumFrequency(bsp::CpuFrequencyMHz::Level_3); sendWorkerCommand(bluetooth::Command(bluetooth::Command::Type::PowerOn)); bus.sendMulticast( std::make_shared(sys::bluetooth::BluetoothMode::Enabled), diff --git a/module-services/service-cellular/CellularCall.cpp b/module-services/service-cellular/CellularCall.cpp index 3b4d54379..7c446dd30 100644 --- a/module-services/service-cellular/CellularCall.cpp +++ b/module-services/service-cellular/CellularCall.cpp @@ -28,7 +28,7 @@ namespace CellularCall } if (cpuSentinel) { - cpuSentinel->HoldMinimumFrequency(bsp::CpuFrequencyHz::Level_6); + cpuSentinel->HoldMinimumFrequency(bsp::CpuFrequencyMHz::Level_6); } clear(); diff --git a/module-services/service-cellular/ServiceCellular.cpp b/module-services/service-cellular/ServiceCellular.cpp index 5a67c7d0f..a28e81172 100644 --- a/module-services/service-cellular/ServiceCellular.cpp +++ b/module-services/service-cellular/ServiceCellular.cpp @@ -2116,7 +2116,7 @@ auto ServiceCellular::handleNetworkStatusUpdateNotification(sys::Message *msg) - auto ServiceCellular::handleUrcIncomingNotification(sys::Message *msg) -> std::shared_ptr { // when handling URC, the CPU frequency does not go below a certain level - cpuSentinel->HoldMinimumFrequency(bsp::CpuFrequencyHz::Level_4); + cpuSentinel->HoldMinimumFrequency(bsp::CpuFrequencyMHz::Level_4); cmux->exitSleepMode(); return std::make_shared(true); } diff --git a/module-services/service-cellular/connection-manager/ConnectionManagerCellularCommands.cpp b/module-services/service-cellular/connection-manager/ConnectionManagerCellularCommands.cpp index a605d4a97..d5102e2fa 100644 --- a/module-services/service-cellular/connection-manager/ConnectionManagerCellularCommands.cpp +++ b/module-services/service-cellular/connection-manager/ConnectionManagerCellularCommands.cpp @@ -102,7 +102,7 @@ void ConnectionManagerCellularCommands::holdMinimumCpuFrequency() { auto handle = cellular.getTaskHandle(); if (cellular.cpuSentinel) { - cellular.cpuSentinel->HoldMinimumFrequencyAndWait(bsp::CpuFrequencyHz::Level_4, handle, 2000); + cellular.cpuSentinel->HoldMinimumFrequencyAndWait(bsp::CpuFrequencyMHz::Level_4, handle, 2000); } return; } diff --git a/module-services/service-desktop/WorkerDesktop.cpp b/module-services/service-desktop/WorkerDesktop.cpp index cdb1e8d18..4a1b5e702 100644 --- a/module-services/service-desktop/WorkerDesktop.cpp +++ b/module-services/service-desktop/WorkerDesktop.cpp @@ -151,7 +151,7 @@ bool WorkerDesktop::handleMessage(uint32_t queueID) usbStatus = bsp::USBDeviceStatus::Connected; } else if (notification == bsp::USBDeviceStatus::Configured) { - cpuSentinel->HoldMinimumFrequency(bsp::CpuFrequencyHz::Level_4); + cpuSentinel->HoldMinimumFrequency(bsp::CpuFrequencyMHz::Level_4); if (usbStatus == bsp::USBDeviceStatus::Connected) { ownerService->bus.sendUnicast(std::make_shared( sdesktop::usb::USBConfigurationType::firstConfiguration), diff --git a/module-services/service-evtmgr/EventManager.cpp b/module-services/service-evtmgr/EventManager.cpp index d61cfb1d7..60341f5c3 100644 --- a/module-services/service-evtmgr/EventManager.cpp +++ b/module-services/service-evtmgr/EventManager.cpp @@ -51,7 +51,7 @@ namespace } // namespace EventManagerSentinel::EventManagerSentinel(std::shared_ptr cpuSentinel, - bsp::CpuFrequencyHz frequencyToHold) + bsp::CpuFrequencyMHz frequencyToHold) : cpuSentinel(cpuSentinel) { cpuSentinel->HoldMinimumFrequency(frequencyToHold); diff --git a/module-services/service-evtmgr/WorkerEventCommon.cpp b/module-services/service-evtmgr/WorkerEventCommon.cpp index 05285bdef..930ed5628 100644 --- a/module-services/service-evtmgr/WorkerEventCommon.cpp +++ b/module-services/service-evtmgr/WorkerEventCommon.cpp @@ -147,7 +147,7 @@ bool WorkerEventCommon::initCommonHardwareComponents() bsp::rtc::getCurrentTimestamp(×tamp); bsp::rtc::setMinuteAlarm(timestamp); - cpuSentinel = std::make_shared("WorkerEvent", service, [this](bsp::CpuFrequencyHz newFrequency) { + cpuSentinel = std::make_shared("WorkerEvent", service, [this](bsp::CpuFrequencyMHz newFrequency) { updateResourcesAfterCpuFrequencyChange(newFrequency); }); @@ -215,7 +215,7 @@ void WorkerEventCommon::processKeyEvent(bsp::KeyEvents event, bsp::KeyCodes code service->bus.sendUnicast(message, service::name::evt_manager); } -void WorkerEventCommon::updateResourcesAfterCpuFrequencyChange(bsp::CpuFrequencyHz newFrequency) +void WorkerEventCommon::updateResourcesAfterCpuFrequencyChange(bsp::CpuFrequencyMHz newFrequency) { bsp::eink_frontlight::updateClockFrequency(newFrequency); bsp::vibrator::updateClockFrequency(newFrequency); diff --git a/module-services/service-evtmgr/service-evtmgr/EventManagerCommon.hpp b/module-services/service-evtmgr/service-evtmgr/EventManagerCommon.hpp index d9a751667..a19cfe432 100644 --- a/module-services/service-evtmgr/service-evtmgr/EventManagerCommon.hpp +++ b/module-services/service-evtmgr/service-evtmgr/EventManagerCommon.hpp @@ -26,7 +26,7 @@ class WorkerEventCommon; class EventManagerSentinel { public: - explicit EventManagerSentinel(std::shared_ptr cpuSentinel, bsp::CpuFrequencyHz frequencyToHold); + explicit EventManagerSentinel(std::shared_ptr cpuSentinel, bsp::CpuFrequencyMHz frequencyToHold); ~EventManagerSentinel(); private: diff --git a/module-services/service-evtmgr/service-evtmgr/WorkerEventCommon.hpp b/module-services/service-evtmgr/service-evtmgr/WorkerEventCommon.hpp index 7c0ee34b7..834e175c3 100644 --- a/module-services/service-evtmgr/service-evtmgr/WorkerEventCommon.hpp +++ b/module-services/service-evtmgr/service-evtmgr/WorkerEventCommon.hpp @@ -69,7 +69,7 @@ class WorkerEventCommon : public sys::Worker * @param code key code * @note It sends message to service if event is processed successfully. */ - void updateResourcesAfterCpuFrequencyChange(bsp::CpuFrequencyHz newFrequency); + void updateResourcesAfterCpuFrequencyChange(bsp::CpuFrequencyMHz newFrequency); bool initEventQueues(); bool initCommonHardwareComponents(); diff --git a/module-sys/SystemManager/CpuGovernor.cpp b/module-sys/SystemManager/CpuGovernor.cpp index 66be6aa5d..f842bc940 100644 --- a/module-sys/SystemManager/CpuGovernor.cpp +++ b/module-sys/SystemManager/CpuGovernor.cpp @@ -9,7 +9,7 @@ namespace sys { GovernorSentinel::GovernorSentinel(std::shared_ptr newSentinel) - : sentinelPtr(newSentinel), requestedFrequency(bsp::CpuFrequencyHz::Level_0) + : sentinelPtr(newSentinel), requestedFrequency(bsp::CpuFrequencyMHz::Level_0) {} [[nodiscard]] auto GovernorSentinel::GetSentinel() const noexcept -> SentinelPointer @@ -17,17 +17,17 @@ namespace sys return sentinelPtr; } - [[nodiscard]] auto GovernorSentinel::GetRequestedFrequency() const noexcept -> bsp::CpuFrequencyHz + [[nodiscard]] auto GovernorSentinel::GetRequestedFrequency() const noexcept -> bsp::CpuFrequencyMHz { return requestedFrequency; } - void GovernorSentinel::SetRequestedFrequency(bsp::CpuFrequencyHz newFrequency) + void GovernorSentinel::SetRequestedFrequency(bsp::CpuFrequencyMHz newFrequency) { requestedFrequency = newFrequency; } - void CpuGovernor::RegisterNewSentinel(std::shared_ptr newSentinel) + bool CpuGovernor::RegisterNewSentinel(std::shared_ptr newSentinel) { if (newSentinel) { auto isNewSentinelAlreadyRegistered = false; @@ -45,11 +45,32 @@ namespace sys if (!isNewSentinelAlreadyRegistered) { sentinels.push_back(std::make_unique(newSentinel)); + return true; } else { + return false; LOG_WARN("New sentinel %s is already registered", newSentinel->GetName().c_str()); } } + return false; + } + + void CpuGovernor::RemoveSentinel(std::string sentinelName) + { + if (!sentinelName.empty()) { + sentinels.erase(std::remove_if(sentinels.begin(), + sentinels.end(), + [sentinelName](auto const &sentinel) { + auto sentinelWeakPointer = sentinel->GetSentinel(); + if (!sentinelWeakPointer.expired()) { + std::shared_ptr sharedResource = + sentinelWeakPointer.lock(); + return sharedResource->GetName() == sentinelName; + } + return false; + }), + sentinels.end()); + } } [[nodiscard]] auto CpuGovernor::GetNumberOfRegisteredSentinels() const noexcept -> uint32_t @@ -62,8 +83,15 @@ namespace sys std::for_each(std::begin(sentinels), std::end(sentinels), PrintName); } - void CpuGovernor::SetCpuFrequencyRequest(std::string sentinelName, bsp::CpuFrequencyHz request) + void CpuGovernor::SetCpuFrequencyRequest(std::string sentinelName, + bsp::CpuFrequencyMHz request, + bool permanentBlock) { + if (permanentBlock) { + permanentFrequencyToHold.isActive = true; + permanentFrequencyToHold.frequencyToHold = request; + return; + } for (auto &sentinel : sentinels) { auto sentinelWeakPointer = sentinel->GetSentinel(); if (!sentinelWeakPointer.expired()) { @@ -75,14 +103,19 @@ namespace sys } } - void CpuGovernor::ResetCpuFrequencyRequest(std::string sentinelName) + void CpuGovernor::ResetCpuFrequencyRequest(std::string sentinelName, bool permanentBlock) { - SetCpuFrequencyRequest(sentinelName, bsp::CpuFrequencyHz::Level_0); + if (permanentBlock) { + permanentFrequencyToHold.isActive = false; + permanentFrequencyToHold.frequencyToHold = bsp::CpuFrequencyMHz::Level_0; + return; + } + SetCpuFrequencyRequest(sentinelName, bsp::CpuFrequencyMHz::Level_0); } - [[nodiscard]] auto CpuGovernor::GetMinimumFrequencyRequested() const noexcept -> bsp::CpuFrequencyHz + [[nodiscard]] auto CpuGovernor::GetMinimumFrequencyRequested() const noexcept -> bsp::CpuFrequencyMHz { - bsp::CpuFrequencyHz minFrequency = bsp::CpuFrequencyHz::Level_0; + bsp::CpuFrequencyMHz minFrequency = bsp::CpuFrequencyMHz::Level_0; for (auto &sentinel : sentinels) { const auto sentinelFrequency = sentinel->GetRequestedFrequency(); @@ -95,7 +128,7 @@ namespace sys return minFrequency; } - void CpuGovernor::InformSentinelsAboutCpuFrequencyChange(bsp::CpuFrequencyHz newFrequency) const noexcept + void CpuGovernor::InformSentinelsAboutCpuFrequencyChange(bsp::CpuFrequencyMHz newFrequency) const noexcept { for (auto &sentinel : sentinels) { auto sentinelWeakPointer = sentinel->GetSentinel(); @@ -115,4 +148,9 @@ namespace sys } } + [[nodiscard]] auto CpuGovernor::GetPermanentFrequencyRequested() const noexcept -> PermanentFrequencyToHold + { + return permanentFrequencyToHold; + } + } // namespace sys diff --git a/module-sys/SystemManager/CpuSentinel.cpp b/module-sys/SystemManager/CpuSentinel.cpp index b368f2018..e7ca912dd 100644 --- a/module-sys/SystemManager/CpuSentinel.cpp +++ b/module-sys/SystemManager/CpuSentinel.cpp @@ -9,7 +9,9 @@ namespace sys { - CpuSentinel::CpuSentinel(std::string name, sys::Service *service, std::function callback) + CpuSentinel::CpuSentinel(std::string name, + sys::Service *service, + std::function callback) : name(name), owner(service), callback(callback) {} @@ -18,7 +20,7 @@ namespace sys return name; } - void CpuSentinel::HoldMinimumFrequency(bsp::CpuFrequencyHz frequencyToHold) + void CpuSentinel::HoldMinimumFrequency(bsp::CpuFrequencyMHz frequencyToHold) { if (currentFrequencyToHold != frequencyToHold) { auto msg = std::make_shared(GetName(), frequencyToHold); @@ -29,14 +31,47 @@ namespace sys void CpuSentinel::ReleaseMinimumFrequency() { - if (currentFrequencyToHold != bsp::CpuFrequencyHz::Level_0) { + if (currentFrequencyToHold != bsp::CpuFrequencyMHz::Level_0) { auto msg = std::make_shared(GetName()); owner->bus.sendUnicast(std::move(msg), service::name::system_manager); - currentFrequencyToHold = bsp::CpuFrequencyHz::Level_0; + currentFrequencyToHold = bsp::CpuFrequencyMHz::Level_0; } } - void CpuSentinel::CpuFrequencyHasChanged(bsp::CpuFrequencyHz newFrequency) + void CpuSentinel::HoldFrequencyPermanently(bsp::CpuFrequencyMHz frequencyToHold) + { + permanentFrequencyToHold.isActive = true; + permanentFrequencyToHold.frequencyToHold = frequencyToHold; + auto msg = std::make_shared(GetName(), frequencyToHold); + owner->bus.sendUnicast(std::move(msg), service::name::system_manager); + } + + [[nodiscard]] auto CpuSentinel::GetFrequency() const noexcept -> bsp::CpuFrequencyMHz + { + if (permanentFrequencyToHold.isActive) { + return permanentFrequencyToHold.frequencyToHold; + } + else { + return currentFrequency; + } + } + + void CpuSentinel::ReleasePermanentFrequency() + { + if (permanentFrequencyToHold.isActive) { + auto msg = std::make_shared(GetName()); + owner->bus.sendUnicast(std::move(msg), service::name::system_manager); + permanentFrequencyToHold.isActive = false; + permanentFrequencyToHold.frequencyToHold = bsp::CpuFrequencyMHz::Level_0; + } + } + + bool CpuSentinel::isPermanentFrequencyActive() + { + return permanentFrequencyToHold.isActive; + } + + void CpuSentinel::CpuFrequencyHasChanged(bsp::CpuFrequencyMHz newFrequency) { currentFrequency = newFrequency; if (callback) { @@ -48,7 +83,7 @@ namespace sys } } - bool CpuSentinel::HoldMinimumFrequencyAndWait(bsp::CpuFrequencyHz frequencyToHold, + bool CpuSentinel::HoldMinimumFrequencyAndWait(bsp::CpuFrequencyMHz frequencyToHold, TaskHandle_t taskToNotify, uint32_t timeout) { @@ -61,4 +96,14 @@ namespace sys return true; } + + void CpuSentinel::ReadRegistrationData(bsp::CpuFrequencyMHz frequencyHz, bool permanentFrequency) + { + currentFrequency = frequencyHz; + permanentFrequencyToHold.isActive = permanentFrequency; + + if (permanentFrequencyToHold.isActive) { + permanentFrequencyToHold.frequencyToHold = currentFrequency; + } + } } // namespace sys diff --git a/module-sys/SystemManager/PowerManager.cpp b/module-sys/SystemManager/PowerManager.cpp index bb7f9b5b4..fa8ad6c4b 100644 --- a/module-sys/SystemManager/PowerManager.cpp +++ b/module-sys/SystemManager/PowerManager.cpp @@ -73,10 +73,26 @@ namespace sys void PowerManager::UpdateCpuFrequency(uint32_t cpuLoad) { - const auto currentCpuFreq = lowPowerControl->GetCurrentFrequencyLevel(); - const auto minFrequencyRequested = cpuGovernor->GetMinimumFrequencyRequested(); + const auto currentCpuFreq = lowPowerControl->GetCurrentFrequencyLevel(); + const auto minFrequencyRequested = cpuGovernor->GetMinimumFrequencyRequested(); + const auto permanentFrequencyToHold = cpuGovernor->GetPermanentFrequencyRequested(); - if (cpuLoad > powerProfile.frequencyShiftUpperThreshold && currentCpuFreq < bsp::CpuFrequencyHz::Level_6) { + if (permanentFrequencyToHold.isActive) { + auto frequencyToHold = std::max(permanentFrequencyToHold.frequencyToHold, powerProfile.minimalFrequency); + + if (currentCpuFreq < frequencyToHold) { + IncreaseCpuFrequency(frequencyToHold); + } + else if (currentCpuFreq > frequencyToHold) { + do { + DecreaseCpuFrequency(); + } while (lowPowerControl->GetCurrentFrequencyLevel() > frequencyToHold); + } + ResetFrequencyShiftCounter(); + return; + } + + if (cpuLoad > powerProfile.frequencyShiftUpperThreshold && currentCpuFreq < bsp::CpuFrequencyMHz::Level_6) { aboveThresholdCounter++; belowThresholdCounter = 0; } @@ -98,13 +114,13 @@ namespace sys IncreaseCpuFrequency(minFrequencyRequested); } else if (aboveThresholdCounter >= powerProfile.maxAboveThresholdCount) { - if (powerProfile.frequencyIncreaseIntermediateStep && currentCpuFreq < bsp::CpuFrequencyHz::Level_4) { + if (powerProfile.frequencyIncreaseIntermediateStep && currentCpuFreq < bsp::CpuFrequencyMHz::Level_4) { ResetFrequencyShiftCounter(); - IncreaseCpuFrequency(bsp::CpuFrequencyHz::Level_4); + IncreaseCpuFrequency(bsp::CpuFrequencyMHz::Level_4); } else { ResetFrequencyShiftCounter(); - IncreaseCpuFrequency(bsp::CpuFrequencyHz::Level_6); + IncreaseCpuFrequency(bsp::CpuFrequencyMHz::Level_6); } } else { @@ -117,11 +133,11 @@ namespace sys } } - void PowerManager::IncreaseCpuFrequency(bsp::CpuFrequencyHz newFrequency) + void PowerManager::IncreaseCpuFrequency(bsp::CpuFrequencyMHz newFrequency) { const auto freq = lowPowerControl->GetCurrentFrequencyLevel(); - if ((freq <= bsp::CpuFrequencyHz::Level_1) && (newFrequency > bsp::CpuFrequencyHz::Level_1)) { + if ((freq <= bsp::CpuFrequencyMHz::Level_1) && (newFrequency > bsp::CpuFrequencyMHz::Level_1)) { // connect internal the load resistor lowPowerControl->ConnectInternalLoadResistor(); // turn off power save mode for DCDC inverter @@ -137,8 +153,8 @@ namespace sys driverSEMC->SwitchToPLL2ClockSource(); } // Add intermediate step in frequency - if (newFrequency > bsp::CpuFrequencyHz::Level_4) - SetCpuFrequency(bsp::CpuFrequencyHz::Level_4); + if (newFrequency > bsp::CpuFrequencyMHz::Level_4) + SetCpuFrequency(bsp::CpuFrequencyMHz::Level_4); } // and increase frequency @@ -153,24 +169,24 @@ namespace sys auto level = powerProfile.minimalFrequency; switch (freq) { - case bsp::CpuFrequencyHz::Level_6: - level = bsp::CpuFrequencyHz::Level_5; + case bsp::CpuFrequencyMHz::Level_6: + level = bsp::CpuFrequencyMHz::Level_5; break; - case bsp::CpuFrequencyHz::Level_5: - level = bsp::CpuFrequencyHz::Level_4; + case bsp::CpuFrequencyMHz::Level_5: + level = bsp::CpuFrequencyMHz::Level_4; break; - case bsp::CpuFrequencyHz::Level_4: - level = bsp::CpuFrequencyHz::Level_3; + case bsp::CpuFrequencyMHz::Level_4: + level = bsp::CpuFrequencyMHz::Level_3; break; - case bsp::CpuFrequencyHz::Level_3: - level = bsp::CpuFrequencyHz::Level_2; + case bsp::CpuFrequencyMHz::Level_3: + level = bsp::CpuFrequencyMHz::Level_2; break; - case bsp::CpuFrequencyHz::Level_2: + case bsp::CpuFrequencyMHz::Level_2: level = powerProfile.minimalFrequency; break; - case bsp::CpuFrequencyHz::Level_1: + case bsp::CpuFrequencyMHz::Level_1: [[fallthrough]]; - case bsp::CpuFrequencyHz::Level_0: + case bsp::CpuFrequencyMHz::Level_0: break; } @@ -179,7 +195,7 @@ namespace sys SetCpuFrequency(level); } - if (level <= bsp::CpuFrequencyHz::Level_1) { + if (level <= bsp::CpuFrequencyMHz::Level_1) { // Enable weak 2P5 and 1P1 LDO and Turn off regular 2P5 and 1P1 LDO lowPowerControl->SwitchToLowPowerModeLDO(); @@ -203,20 +219,30 @@ namespace sys void PowerManager::RegisterNewSentinel(std::shared_ptr newSentinel) const { - cpuGovernor->RegisterNewSentinel(newSentinel); + if (cpuGovernor->RegisterNewSentinel(newSentinel)) { + newSentinel->ReadRegistrationData(lowPowerControl->GetCurrentFrequencyLevel(), + cpuGovernor->GetPermanentFrequencyRequested().isActive); + } } - void PowerManager::SetCpuFrequencyRequest(std::string sentinelName, bsp::CpuFrequencyHz request) + void PowerManager::RemoveSentinel(std::string sentinelName) const { - cpuGovernor->SetCpuFrequencyRequest(std::move(sentinelName), request); + cpuGovernor->RemoveSentinel(sentinelName); } - void PowerManager::ResetCpuFrequencyRequest(std::string sentinelName) + void PowerManager::SetCpuFrequencyRequest(std::string sentinelName, + bsp::CpuFrequencyMHz request, + bool permanentBlock) { - cpuGovernor->ResetCpuFrequencyRequest(std::move(sentinelName)); + cpuGovernor->SetCpuFrequencyRequest(std::move(sentinelName), request, permanentBlock); } - void PowerManager::SetCpuFrequency(bsp::CpuFrequencyHz freq) + void PowerManager::ResetCpuFrequencyRequest(std::string sentinelName, bool permanentBlock) + { + cpuGovernor->ResetCpuFrequencyRequest(std::move(sentinelName), permanentBlock); + } + + void PowerManager::SetCpuFrequency(bsp::CpuFrequencyMHz freq) { UpdateCpuFrequencyMonitor(lowPowerControl->GetCurrentFrequencyLevel()); lowPowerControl->SetCpuFrequency(freq); @@ -234,12 +260,12 @@ namespace sys return driverSEMC; } - void PowerManager::UpdateCpuFrequencyMonitor(bsp::CpuFrequencyHz currentFreq) + void PowerManager::UpdateCpuFrequencyMonitor(bsp::CpuFrequencyMHz currentFreq) { auto ticks = xTaskGetTickCount(); auto levelName = currentFreq == powerProfile.minimalFrequency ? lowestLevelName - : (currentFreq == bsp::CpuFrequencyHz::Level_6 ? highestLevelName : middleLevelName); + : (currentFreq == bsp::CpuFrequencyMHz::Level_6 ? highestLevelName : middleLevelName); for (auto &level : cpuFrequencyMonitor) { if (level.GetName() == levelName) { @@ -266,5 +292,4 @@ namespace sys { lowPowerControl->SetBootSuccess(); } - } // namespace sys diff --git a/module-sys/SystemManager/SystemManagerCommon.cpp b/module-sys/SystemManager/SystemManagerCommon.cpp index 8bd091c36..2338f62a0 100644 --- a/module-sys/SystemManager/SystemManagerCommon.cpp +++ b/module-sys/SystemManager/SystemManagerCommon.cpp @@ -570,6 +570,13 @@ namespace sys return sys::MessageNone{}; }); + connect(typeid(sys::SentinelRemovalMessage), [this](sys::Message *message) -> sys::MessagePointer { + auto msg = static_cast(message); + powerManager->RemoveSentinel(msg->getSentinelName()); + + return sys::MessageNone{}; + }); + connect(typeid(sys::HoldCpuFrequencyMessage), [this](sys::Message *message) -> sys::MessagePointer { auto msg = static_cast(message); powerManager->SetCpuFrequencyRequest(msg->getName(), msg->getRequest()); @@ -584,6 +591,19 @@ namespace sys return sys::MessageNone{}; }); + connect(typeid(sys::HoldCpuFrequencyPermanentlyMessage), [this](sys::Message *message) -> sys::MessagePointer { + auto msg = static_cast(message); + powerManager->SetCpuFrequencyRequest(msg->getName(), msg->getRequest(), true); + + return sys::MessageNone{}; + }); + + connect(typeid(sys::ReleaseCpuPermanentFrequencyMessage), [this](sys::Message *message) -> sys::MessagePointer { + auto msg = static_cast(message); + powerManager->ResetCpuFrequencyRequest(msg->getName(), true); + return sys::MessageNone{}; + }); + connect(typeid(app::manager::CheckIfStartAllowedMessage), [this](sys::Message *) -> sys::MessagePointer { switch (Store::Battery::get().levelState) { case Store::Battery::LevelState::Normal: @@ -612,7 +632,7 @@ namespace sys deviceManager->RegisterNewDevice(powerManager->getExternalRamDevice()); cpuSentinel = std::make_shared( - service::name::system_manager, this, [this](bsp::CpuFrequencyHz newFrequency) { + service::name::system_manager, this, [this](bsp::CpuFrequencyMHz newFrequency) { UpdateResourcesAfterCpuFrequencyChange(newFrequency); }); powerManager->RegisterNewSentinel(cpuSentinel); @@ -699,9 +719,9 @@ namespace sys powerManager->UpdateCpuFrequency(cpuStatistics->GetPercentageCpuLoad()); } - void SystemManagerCommon::UpdateResourcesAfterCpuFrequencyChange(bsp::CpuFrequencyHz newFrequency) + void SystemManagerCommon::UpdateResourcesAfterCpuFrequencyChange(bsp::CpuFrequencyMHz newFrequency) { - if (newFrequency <= bsp::CpuFrequencyHz::Level_1) { + if (newFrequency <= bsp::CpuFrequencyMHz::Level_1) { purefs::subsystem::disk_mgr()->pm_control(purefs::blkdev::pm_state::suspend); } else { diff --git a/module-sys/SystemManager/include/SystemManager/CpuGovernor.hpp b/module-sys/SystemManager/include/SystemManager/CpuGovernor.hpp index 404d47ce0..18911e2a6 100644 --- a/module-sys/SystemManager/include/SystemManager/CpuGovernor.hpp +++ b/module-sys/SystemManager/include/SystemManager/CpuGovernor.hpp @@ -16,12 +16,12 @@ namespace sys public: explicit GovernorSentinel(std::shared_ptr newSentinel); [[nodiscard]] auto GetSentinel() const noexcept -> SentinelPointer; - [[nodiscard]] auto GetRequestedFrequency() const noexcept -> bsp::CpuFrequencyHz; - void SetRequestedFrequency(bsp::CpuFrequencyHz newFrequency); + [[nodiscard]] auto GetRequestedFrequency() const noexcept -> bsp::CpuFrequencyMHz; + void SetRequestedFrequency(bsp::CpuFrequencyMHz newFrequency); private: SentinelPointer sentinelPtr; - bsp::CpuFrequencyHz requestedFrequency; + bsp::CpuFrequencyMHz requestedFrequency; }; using GovernorSentinelPointer = std::unique_ptr; @@ -33,20 +33,26 @@ namespace sys { public: - void RegisterNewSentinel(std::shared_ptr newSentinel); + auto RegisterNewSentinel(std::shared_ptr newSentinel) -> bool; + auto RemoveSentinel(std::string sentinelName) -> void; [[nodiscard]] auto GetNumberOfRegisteredSentinels() const noexcept -> uint32_t; void PrintAllSentinels() const noexcept; - void SetCpuFrequencyRequest(std::string sentinelName, bsp::CpuFrequencyHz request); - void ResetCpuFrequencyRequest(std::string sentinelName); + void SetCpuFrequencyRequest(std::string sentinelName, + bsp::CpuFrequencyMHz request, + bool permanentBlock = false); + void ResetCpuFrequencyRequest(std::string sentinelName, bool permanentBlock = false); - [[nodiscard]] auto GetMinimumFrequencyRequested() const noexcept -> bsp::CpuFrequencyHz; - void InformSentinelsAboutCpuFrequencyChange(bsp::CpuFrequencyHz newFrequency) const noexcept; + [[nodiscard]] auto GetMinimumFrequencyRequested() const noexcept -> bsp::CpuFrequencyMHz; + void InformSentinelsAboutCpuFrequencyChange(bsp::CpuFrequencyMHz newFrequency) const noexcept; + + [[nodiscard]] auto GetPermanentFrequencyRequested() const noexcept -> PermanentFrequencyToHold; private: static void PrintName(const GovernorSentinelPointer &element); GovernorSentinelsVector sentinels; + PermanentFrequencyToHold permanentFrequencyToHold{false, bsp::CpuFrequencyMHz::Level_0}; }; } // namespace sys diff --git a/module-sys/SystemManager/include/SystemManager/CpuSentinel.hpp b/module-sys/SystemManager/include/SystemManager/CpuSentinel.hpp index 07d8136be..3709c9b34 100644 --- a/module-sys/SystemManager/include/SystemManager/CpuSentinel.hpp +++ b/module-sys/SystemManager/include/SystemManager/CpuSentinel.hpp @@ -12,6 +12,12 @@ namespace sys { + struct PermanentFrequencyToHold + { + bool isActive; + bsp::CpuFrequencyMHz frequencyToHold; + }; + /// Each sentinel manages the requests, i.e. when it is needed it sends messages to CpuGovernor with the required /// minimum CPU frequency to perform the task (e.g. screen redraw). Furthermore, every sentinel is informed /// immediately after changing the frequency. This allows it to invoke a callback to the service to update their @@ -22,27 +28,35 @@ namespace sys public: explicit CpuSentinel(std::string name, sys::Service *service, - std::function callback = nullptr); + std::function callback = nullptr); ~CpuSentinel() = default; [[nodiscard]] auto GetName() const noexcept -> std::string; - void HoldMinimumFrequency(bsp::CpuFrequencyHz frequencyToHold); - bool HoldMinimumFrequencyAndWait(bsp::CpuFrequencyHz frequencyToHold, + void HoldMinimumFrequency(bsp::CpuFrequencyMHz frequencyToHold); + bool HoldMinimumFrequencyAndWait(bsp::CpuFrequencyMHz frequencyToHold, TaskHandle_t taskToNotify, uint32_t timeout); void ReleaseMinimumFrequency(); - void CpuFrequencyHasChanged(bsp::CpuFrequencyHz newFrequency); + + void HoldFrequencyPermanently(bsp::CpuFrequencyMHz frequencyToHold); + [[nodiscard]] auto GetFrequency() const noexcept -> bsp::CpuFrequencyMHz; + void ReleasePermanentFrequency(); + [[nodiscard]] bool isPermanentFrequencyActive(); + + void CpuFrequencyHasChanged(bsp::CpuFrequencyMHz newFrequency); + void ReadRegistrationData(bsp::CpuFrequencyMHz frequencyHz, bool permanentFrequency); protected: const std::string name; - bsp::CpuFrequencyHz currentFrequencyToHold{bsp::CpuFrequencyHz::Level_0}; - std::atomic currentFrequency{bsp::CpuFrequencyHz::Level_0}; + bsp::CpuFrequencyMHz currentFrequencyToHold{bsp::CpuFrequencyMHz::Level_0}; + PermanentFrequencyToHold permanentFrequencyToHold{false, bsp::CpuFrequencyMHz::Level_0}; + std::atomic currentFrequency{bsp::CpuFrequencyMHz::Level_0}; sys::Service *owner{nullptr}; /// function called from the PowerManager context /// to update resources immediately /// critical section or mutex support necessary - std::function callback; + std::function callback; TaskHandle_t taskHandle = nullptr; }; diff --git a/module-sys/SystemManager/include/SystemManager/PowerManager.hpp b/module-sys/SystemManager/include/SystemManager/PowerManager.hpp index e22572eb4..858987774 100644 --- a/module-sys/SystemManager/include/SystemManager/PowerManager.hpp +++ b/module-sys/SystemManager/include/SystemManager/PowerManager.hpp @@ -51,23 +51,26 @@ namespace sys [[nodiscard]] auto getExternalRamDevice() const noexcept -> std::shared_ptr; void RegisterNewSentinel(std::shared_ptr newSentinel) const; - void SetCpuFrequencyRequest(std::string sentinelName, bsp::CpuFrequencyHz request); - void ResetCpuFrequencyRequest(std::string sentinelName); + void RemoveSentinel(std::string sentinelName) const; + void SetCpuFrequencyRequest(std::string sentinelName, + bsp::CpuFrequencyMHz request, + bool permanentBlock = false); + void ResetCpuFrequencyRequest(std::string sentinelName, bool permanentBlock = false); void LogPowerManagerEfficiency(); void SetBootSuccess(); private: /// called when the CPU frequency needs to be increased - void IncreaseCpuFrequency(bsp::CpuFrequencyHz newFrequency); + void IncreaseCpuFrequency(bsp::CpuFrequencyMHz newFrequency); /// called when the CPU frequency needs to be reduced /// @note the frequency is always reduced by one step void DecreaseCpuFrequency(); void ResetFrequencyShiftCounter(); - void SetCpuFrequency(bsp::CpuFrequencyHz freq); + void SetCpuFrequency(bsp::CpuFrequencyMHz freq); - void UpdateCpuFrequencyMonitor(bsp::CpuFrequencyHz currentFreq); + void UpdateCpuFrequencyMonitor(bsp::CpuFrequencyMHz currentFreq); uint32_t belowThresholdCounter{0}; uint32_t aboveThresholdCounter{0}; diff --git a/module-sys/SystemManager/include/SystemManager/SystemManagerCommon.hpp b/module-sys/SystemManager/include/SystemManager/SystemManagerCommon.hpp index ed3a1ba98..d9a3f87aa 100644 --- a/module-sys/SystemManager/include/SystemManager/SystemManagerCommon.hpp +++ b/module-sys/SystemManager/include/SystemManager/SystemManagerCommon.hpp @@ -183,7 +183,7 @@ namespace sys void CpuStatisticsTimerHandler(); /// used for power management control for the filesystem - void UpdateResourcesAfterCpuFrequencyChange(bsp::CpuFrequencyHz newFrequency); + void UpdateResourcesAfterCpuFrequencyChange(bsp::CpuFrequencyMHz newFrequency); bool cpuStatisticsTimerInit{false}; diff --git a/module-sys/SystemManager/tests/unittest_CpuSentinelsGovernor.cpp b/module-sys/SystemManager/tests/unittest_CpuSentinelsGovernor.cpp index ffb009287..7b2fd22ff 100644 --- a/module-sys/SystemManager/tests/unittest_CpuSentinelsGovernor.cpp +++ b/module-sys/SystemManager/tests/unittest_CpuSentinelsGovernor.cpp @@ -39,27 +39,27 @@ TEST_CASE("Power Manager CPU sentinels governor test") governor->RegisterNewSentinel(testSentinel_1); governor->RegisterNewSentinel(testSentinel_2); - REQUIRE(governor->GetMinimumFrequencyRequested() == bsp::CpuFrequencyHz::Level_0); + REQUIRE(governor->GetMinimumFrequencyRequested() == bsp::CpuFrequencyMHz::Level_0); - governor->SetCpuFrequencyRequest("testSentinel_1", bsp::CpuFrequencyHz::Level_4); - REQUIRE(governor->GetMinimumFrequencyRequested() == bsp::CpuFrequencyHz::Level_4); + governor->SetCpuFrequencyRequest("testSentinel_1", bsp::CpuFrequencyMHz::Level_4); + REQUIRE(governor->GetMinimumFrequencyRequested() == bsp::CpuFrequencyMHz::Level_4); - governor->SetCpuFrequencyRequest("testSentinel_2", bsp::CpuFrequencyHz::Level_6); - REQUIRE(governor->GetMinimumFrequencyRequested() == bsp::CpuFrequencyHz::Level_6); + governor->SetCpuFrequencyRequest("testSentinel_2", bsp::CpuFrequencyMHz::Level_6); + REQUIRE(governor->GetMinimumFrequencyRequested() == bsp::CpuFrequencyMHz::Level_6); - governor->SetCpuFrequencyRequest("testSentinel_1", bsp::CpuFrequencyHz::Level_2); - REQUIRE(governor->GetMinimumFrequencyRequested() == bsp::CpuFrequencyHz::Level_6); + governor->SetCpuFrequencyRequest("testSentinel_1", bsp::CpuFrequencyMHz::Level_2); + REQUIRE(governor->GetMinimumFrequencyRequested() == bsp::CpuFrequencyMHz::Level_6); governor->ResetCpuFrequencyRequest("testSentinel_2"); - REQUIRE(governor->GetMinimumFrequencyRequested() == bsp::CpuFrequencyHz::Level_2); + REQUIRE(governor->GetMinimumFrequencyRequested() == bsp::CpuFrequencyMHz::Level_2); - governor->SetCpuFrequencyRequest("bedNameSentinel", bsp::CpuFrequencyHz::Level_6); - REQUIRE(governor->GetMinimumFrequencyRequested() == bsp::CpuFrequencyHz::Level_2); + governor->SetCpuFrequencyRequest("bedNameSentinel", bsp::CpuFrequencyMHz::Level_6); + REQUIRE(governor->GetMinimumFrequencyRequested() == bsp::CpuFrequencyMHz::Level_2); - governor->SetCpuFrequencyRequest("testSentinel_1", bsp::CpuFrequencyHz::Level_1); - REQUIRE(governor->GetMinimumFrequencyRequested() == bsp::CpuFrequencyHz::Level_1); + governor->SetCpuFrequencyRequest("testSentinel_1", bsp::CpuFrequencyMHz::Level_1); + REQUIRE(governor->GetMinimumFrequencyRequested() == bsp::CpuFrequencyMHz::Level_1); governor->ResetCpuFrequencyRequest("testSentinel_1"); - REQUIRE(governor->GetMinimumFrequencyRequested() == bsp::CpuFrequencyHz::Level_0); + REQUIRE(governor->GetMinimumFrequencyRequested() == bsp::CpuFrequencyMHz::Level_0); } } diff --git a/module-sys/common/include/system/messages/RequestCpuFrequencyMessage.hpp b/module-sys/common/include/system/messages/RequestCpuFrequencyMessage.hpp index e1b50b6cd..1902eb116 100644 --- a/module-sys/common/include/system/messages/RequestCpuFrequencyMessage.hpp +++ b/module-sys/common/include/system/messages/RequestCpuFrequencyMessage.hpp @@ -12,7 +12,7 @@ namespace sys class HoldCpuFrequencyMessage : public sys::DataMessage { public: - HoldCpuFrequencyMessage(std::string sentinelName, bsp::CpuFrequencyHz request) + HoldCpuFrequencyMessage(std::string sentinelName, bsp::CpuFrequencyMHz request) : sys::DataMessage(MessageType::SystemManagerCpuFrequency), sentinelName(std::move(sentinelName)), frequencyRequested(request) {} @@ -29,7 +29,7 @@ namespace sys private: std::string sentinelName; - bsp::CpuFrequencyHz frequencyRequested = bsp::CpuFrequencyHz::Level_0; + bsp::CpuFrequencyMHz frequencyRequested = bsp::CpuFrequencyMHz::Level_0; }; class ReleaseCpuFrequencyMessage : public sys::DataMessage @@ -48,4 +48,19 @@ namespace sys std::string sentinelName; }; + class HoldCpuFrequencyPermanentlyMessage : public HoldCpuFrequencyMessage + { + public: + HoldCpuFrequencyPermanentlyMessage(std::string sentinelName, bsp::CpuFrequencyMHz request) + : HoldCpuFrequencyMessage(sentinelName, request) + {} + }; + + class ReleaseCpuPermanentFrequencyMessage : public ReleaseCpuFrequencyMessage + { + public: + ReleaseCpuPermanentFrequencyMessage(std::string sentinelName) : ReleaseCpuFrequencyMessage(sentinelName) + {} + }; + } // namespace sys diff --git a/module-sys/common/include/system/messages/SentinelRegistrationMessage.hpp b/module-sys/common/include/system/messages/SentinelRegistrationMessage.hpp index 8a5cb0c86..f1c8c35ee 100644 --- a/module-sys/common/include/system/messages/SentinelRegistrationMessage.hpp +++ b/module-sys/common/include/system/messages/SentinelRegistrationMessage.hpp @@ -11,8 +11,8 @@ namespace sys class SentinelRegistrationMessage : public sys::DataMessage { public: - SentinelRegistrationMessage(std::shared_ptr sentinelPtr) - : sys::DataMessage(MessageType::SystemManagerRegistration), sentinel(sentinelPtr) + explicit SentinelRegistrationMessage(std::shared_ptr sentinelPtr) + : sys::DataMessage(MessageType::SystemManagerSentinelRegistration), sentinel(sentinelPtr) {} [[nodiscard]] auto getSentinel() const noexcept -> std::shared_ptr @@ -23,4 +23,20 @@ namespace sys private: std::shared_ptr sentinel; }; + + class SentinelRemovalMessage : public sys::DataMessage + { + public: + explicit SentinelRemovalMessage(std::string sentinelName) + : sys::DataMessage(MessageType::SystemManagerSentinelRemoval), sentinelName(std::move(sentinelName)) + {} + + [[nodiscard]] auto getSentinelName() const noexcept -> std::string + { + return sentinelName; + }; + + private: + std::string sentinelName; + }; } // namespace sys diff --git a/products/BellHybrid/EinkSentinelBell.cpp b/products/BellHybrid/EinkSentinelBell.cpp index f55df48bb..3338b44f8 100644 --- a/products/BellHybrid/EinkSentinelBell.cpp +++ b/products/BellHybrid/EinkSentinelBell.cpp @@ -9,7 +9,7 @@ namespace service::eink { namespace { - constexpr auto RedrawEinkCpuFrequency = bsp::CpuFrequencyHz::Level_4; + constexpr auto RedrawEinkCpuFrequency = bsp::CpuFrequencyMHz::Level_4; } // namespace EinkSentinel::EinkSentinel(std::string name, sys::Service *service) : sys::CpuSentinel(name, service) diff --git a/products/BellHybrid/services/audio/ServiceAudio.cpp b/products/BellHybrid/services/audio/ServiceAudio.cpp index 37a080519..06dbfb2be 100644 --- a/products/BellHybrid/services/audio/ServiceAudio.cpp +++ b/products/BellHybrid/services/audio/ServiceAudio.cpp @@ -303,7 +303,7 @@ namespace service } void Audio::manageCpuSentinel() { - isBusy() ? cpuSentinel->HoldMinimumFrequency(bsp::CpuFrequencyHz::Level_6) + isBusy() ? cpuSentinel->HoldMinimumFrequency(bsp::CpuFrequencyMHz::Level_6) : cpuSentinel->ReleaseMinimumFrequency(); } void Audio::initializeDatabase() diff --git a/products/BellHybrid/services/evtmgr/screen-light-control/ScreenLightControl.cpp b/products/BellHybrid/services/evtmgr/screen-light-control/ScreenLightControl.cpp index 8b96cb596..d584f5696 100644 --- a/products/BellHybrid/services/evtmgr/screen-light-control/ScreenLightControl.cpp +++ b/products/BellHybrid/services/evtmgr/screen-light-control/ScreenLightControl.cpp @@ -183,7 +183,7 @@ namespace bell::screen_light_control void ScreenLightController::cpuSentinelKeepOn() { - cpuSentinel->HoldMinimumFrequency(bsp::CpuFrequencyHz::Level_6); + cpuSentinel->HoldMinimumFrequency(bsp::CpuFrequencyMHz::Level_6); } void ScreenLightController::cpuSentinelRelease() diff --git a/products/BellHybrid/services/evtmgr/user-activity-handler/UserActivityHandler.cpp b/products/BellHybrid/services/evtmgr/user-activity-handler/UserActivityHandler.cpp index 08f1ab658..d16ba31e7 100644 --- a/products/BellHybrid/services/evtmgr/user-activity-handler/UserActivityHandler.cpp +++ b/products/BellHybrid/services/evtmgr/user-activity-handler/UserActivityHandler.cpp @@ -9,7 +9,7 @@ namespace evm namespace { constexpr auto userActivityTimerTime = std::chrono::seconds(10); - constexpr auto userActivityCPULevel = bsp::CpuFrequencyHz::Level_5; + constexpr auto userActivityCPULevel = bsp::CpuFrequencyMHz::Level_5; } // namespace UserActivityHandler::UserActivityHandler(std::shared_ptr cpuSentinel, sys::Service *parent) diff --git a/products/PurePhone/EinkSentinelPure.cpp b/products/PurePhone/EinkSentinelPure.cpp index 34a29f845..d1c1165d6 100644 --- a/products/PurePhone/EinkSentinelPure.cpp +++ b/products/PurePhone/EinkSentinelPure.cpp @@ -10,8 +10,8 @@ namespace service::eink { namespace { - constexpr auto RedrawLockedEinkCpuFrequency = bsp::CpuFrequencyHz::Level_4; - constexpr auto RedrawUnlockedEinkCpuFrequency = bsp::CpuFrequencyHz::Level_6; + constexpr auto RedrawLockedEinkCpuFrequency = bsp::CpuFrequencyMHz::Level_4; + constexpr auto RedrawUnlockedEinkCpuFrequency = bsp::CpuFrequencyMHz::Level_6; } // namespace EinkSentinel::EinkSentinel(std::string name, sys::Service *service) : sys::CpuSentinel(name, service) diff --git a/source/MessageType.hpp b/source/MessageType.hpp index 260d228f4..0a579123c 100644 --- a/source/MessageType.hpp +++ b/source/MessageType.hpp @@ -91,7 +91,8 @@ enum class MessageType // System manager SystemManagerCpuFrequency, - SystemManagerRegistration, + SystemManagerSentinelRegistration, + SystemManagerSentinelRemoval, // rtc messages EVMMinuteUpdated, ///< This message is send to current focused application on every minute time change.