mirror of
https://github.com/mudita/MuditaOS.git
synced 2026-04-20 15:07:17 -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)
53 lines
1.9 KiB
C++
53 lines
1.9 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 <memory>
|
|
#include <vector>
|
|
#include "Service/CpuSentinel.hpp"
|
|
|
|
namespace sys
|
|
{
|
|
using SentinelPointer = std::weak_ptr<CpuSentinel>;
|
|
|
|
class GovernorSentinel
|
|
{
|
|
public:
|
|
explicit GovernorSentinel(std::shared_ptr<CpuSentinel> newSentinel);
|
|
[[nodiscard]] auto GetSentinel() const noexcept -> SentinelPointer;
|
|
[[nodiscard]] auto GetRequestedFrequency() const noexcept -> bsp::CpuFrequencyHz;
|
|
void SetRequestedFrequency(bsp::CpuFrequencyHz newFrequency);
|
|
|
|
private:
|
|
SentinelPointer sentinelPtr;
|
|
bsp::CpuFrequencyHz requestedFrequency;
|
|
};
|
|
|
|
using GovernorSentinelPointer = std::unique_ptr<GovernorSentinel>;
|
|
using GovernorSentinelsVector = std::vector<GovernorSentinelPointer>;
|
|
|
|
/// CpuGovernor manages all sentinels in the system and has CPU frequency requests from them (e.g. eInkSentinel).
|
|
/// It is also responsible for informing all sentinels that the CPU frequency has changed.
|
|
class CpuGovernor
|
|
{
|
|
|
|
public:
|
|
void RegisterNewSentinel(std::shared_ptr<CpuSentinel> newSentinel);
|
|
[[nodiscard]] auto GetNumberOfRegisteredSentinels() const noexcept -> uint32_t;
|
|
void PrintAllSentinels() const noexcept;
|
|
|
|
void SetCpuFrequencyRequest(std::string sentinelName, bsp::CpuFrequencyHz request);
|
|
void ResetCpuFrequencyRequest(std::string sentinelName);
|
|
|
|
[[nodiscard]] auto GetMinimumFrequencyRequested() const noexcept -> bsp::CpuFrequencyHz;
|
|
void InformSentinelsAboutCpuFrequencyChange(bsp::CpuFrequencyHz newFrequency) const noexcept;
|
|
|
|
private:
|
|
static void PrintName(const GovernorSentinelPointer &element);
|
|
|
|
GovernorSentinelsVector sentinels;
|
|
};
|
|
|
|
} // namespace sys
|