mirror of
https://github.com/mudita/MuditaOS.git
synced 2026-10-25 07:58:29 -04: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)
41 lines
1.5 KiB
C++
41 lines
1.5 KiB
C++
// 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 <string>
|
|
#include <functional>
|
|
#include <bsp/common.hpp>
|
|
#include "Service.hpp"
|
|
|
|
namespace sys
|
|
{
|
|
/// 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
|
|
/// resources (e.g. PWM filling). Every sentinel must register itself on startup to CpuGovernor by sending
|
|
/// "SentinelRegistrationMessage".
|
|
class CpuSentinel
|
|
{
|
|
public:
|
|
explicit CpuSentinel(std::string name,
|
|
sys::Service *service,
|
|
std::function<void(bsp::CpuFrequencyHz)> callback = nullptr);
|
|
~CpuSentinel() = default;
|
|
|
|
[[nodiscard]] auto GetName() const noexcept -> std::string;
|
|
void HoldMinimumFrequency(bsp::CpuFrequencyHz frequencyToHold);
|
|
void CpuFrequencyHasChanged(bsp::CpuFrequencyHz newFrequency);
|
|
|
|
protected:
|
|
const std::string name;
|
|
sys::Service *owner{nullptr};
|
|
|
|
/// function called from the PowerManager context
|
|
/// to update resources immediately
|
|
/// critical section or mutex support necessary
|
|
std::function<void(bsp::CpuFrequencyHz)> callback;
|
|
};
|
|
|
|
} // namespace sys
|