Files
MuditaOS/module-sys/Service/CpuSentinel.cpp
Maciej-Mudita 11aa4c7ffb [EGD-5382] Add LowPower CpuSentinels
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)
2021-02-12 09:40:36 +01:00

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