mirror of
https://github.com/mudita/MuditaOS.git
synced 2026-01-24 22:08:33 -05:00
In order to synchronize the Low Power mode, the services were immediately informed about the frequency change, so that they can update their resources (e.g. PWM filling) and services may request the maximum CPU frequency in order to perform a task (e.g. screen redraw, telephone conversation)
35 lines
1.0 KiB
C++
35 lines
1.0 KiB
C++
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
|
|
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
|
|
|
|
#include "CpuSentinel.hpp"
|
|
#include "SystemManager/messages/RequestCpuFrequencyMessage.hpp"
|
|
#include "SystemManager/Constants.hpp"
|
|
#include <memory>
|
|
|
|
namespace sys
|
|
{
|
|
|
|
CpuSentinel::CpuSentinel(std::string name, sys::Service *service, std::function<void(bsp::CpuFrequencyHz)> callback)
|
|
: name(name), owner(service), callback(callback)
|
|
{}
|
|
|
|
[[nodiscard]] auto CpuSentinel::GetName() const noexcept -> std::string
|
|
{
|
|
return name;
|
|
}
|
|
|
|
void CpuSentinel::HoldMinimumFrequency(bsp::CpuFrequencyHz frequencyToHold)
|
|
{
|
|
auto msg = std::make_shared<sys::RequestCpuFrequencyMessage>(GetName(), frequencyToHold);
|
|
owner->bus.sendUnicast(msg, service::name::system_manager);
|
|
}
|
|
|
|
void CpuSentinel::CpuFrequencyHasChanged(bsp::CpuFrequencyHz newFrequency)
|
|
{
|
|
if (callback) {
|
|
callback(newFrequency);
|
|
}
|
|
}
|
|
|
|
} // namespace sys
|