libxr
Embedded C++ framework for bare-metal, RTOS and Linux
Loading...
Searching...
No Matches
LibXR::PowerManager Class Referenceabstract

电源管理器基类 / Abstract base class for Power Manager More...

#include <power.hpp>

Inheritance diagram for LibXR::PowerManager:
[legend]

Public Member Functions

 PowerManager ()=default
 默认构造函数 / Default constructor
 
virtual ~PowerManager ()=default
 默认析构函数 / Default destructor
 
virtual void Reset ()=0
 复位电源管理模块 / Resets the power management module
 
virtual void Shutdown ()=0
 关闭系统电源 / Shuts down the system power
 
virtual void JumpToBootloader ()
 跳转到启动加载器 / Jumps to the bootloader
 
void RegisterCommand (RamFS &ramfs)
 在 RamFS 根目录注册 power 命令 / Registers the power command in the RamFS root
 
void CheckBootloaderPin (GPIO &pin, bool level)
 启动时按引脚电平进入启动加载器 / Pin-level bootloader entry at startup
 

Detailed Description

电源管理器基类 / Abstract base class for Power Manager

该类定义了电源管理的基本接口,所有电源管理模块应继承此类并实现具体的 Reset 和 Shutdown 方法。 This class defines the basic interface for power management. All power management modules should inherit from this class and implement the Reset and Shutdown methods.

Definition at line 20 of file power.hpp.

Member Function Documentation

◆ CheckBootloaderPin()

void PowerManager::CheckBootloaderPin ( GPIO & pin,
bool level )

启动时按引脚电平进入启动加载器 / Pin-level bootloader entry at startup

读一次 pin,电平等于 level 时调用 JumpToBootloader(),否则直接返回。 在初始化早期调用一次,按住该引脚对应的按键再复位即可进入启动加载器; 运行中该引脚仍归程序使用。引脚的输入方向和上下拉由工程配置决定, 这里不修改;悬空的引脚可能误触发。 Reads pin once and calls JumpToBootloader() when it reads level, otherwise returns. Called once early during initialization, so holding the key on that pin through a reset enters the bootloader, while the pin stays with the application at run time. The input direction and pull of the pin come from the project configuration and are left unchanged; a floating pin may trigger by accident.

Parameters
pin检测的引脚 / The pin to check
level进入启动加载器的电平 / The level that enters the bootloader

Definition at line 45 of file power.cpp.

46{
47 if (pin.Read() == level)
48 {
50 }
51}
virtual bool Read()=0
读取 GPIO 引脚状态 / Reads the GPIO pin state.
virtual void JumpToBootloader()
跳转到启动加载器 / Jumps to the bootloader
Definition power.hpp:58

◆ JumpToBootloader()

virtual void LibXR::PowerManager::JumpToBootloader ( )
inlinevirtual

跳转到启动加载器 / Jumps to the bootloader

平台实现进入芯片的启动加载器(例如 ROM BSL 或 ISP);未实现的平台退化为 Reset()。 Platform implementations enter the bootloader of the chip (such as a ROM BSL or ISP); platforms without one fall back to Reset().

Reimplemented in LibXR::HPMPowerManager, and LibXR::MSPM0PowerManager.

Definition at line 58 of file power.hpp.

58{ Reset(); }
virtual void Reset()=0
复位电源管理模块 / Resets the power management module

◆ RegisterCommand()

void PowerManager::RegisterCommand ( RamFS & ramfs)

在 RamFS 根目录注册 power 命令 / Registers the power command in the RamFS root

终端中 power reset、power shutdown、power bootloader 分别调用 Reset()、 Shutdown()、JumpToBootloader();没有参数或参数不认识时打印用法并返回 -1。命令文件 在第一次注册时分配,之后不释放;同一个对象只应注册一次。 In the terminal, power reset, power shutdown and power bootloader call Reset(), Shutdown() and JumpToBootloader(); without an argument or with an unknown one the command prints its usage and returns -1. The command file is allocated on registration and never freed; register one object only once.

Parameters
ramfs终端使用的文件系统 / The file system the terminal uses

Definition at line 39 of file power.cpp.

40{
41 auto* command = new RamFS::File(RamFS::CreateCommand("power", PowerCommand, this));
42 ramfs.Add(*command);
43}
文件节点片段 / File-node fragment
Definition ramfs.hpp:10
static File CreateCommand(const char *name, int(*exec)(ArgType arg, int argc, char **argv), ArgType &&arg)
创建命令兼容入口,返回可执行文件 / Create a command-compatible executable file
Definition ramfs.hpp:92
void Add(File &file)
添加文件节点到根目录 / Add a file node to the root directory
Definition ramfs.hpp:139

◆ Reset()

virtual void LibXR::PowerManager::Reset ( )
pure virtual

复位电源管理模块 / Resets the power management module

该方法应由子类实现,用于执行特定的复位操作,例如重启电源控制器或恢复默认设置。 This method should be implemented by subclasses to perform specific reset operations, such as restarting the power controller or restoring default settings.

Implemented in LibXR::CH32PowerManager, LibXR::HPMPowerManager, LibXR::LinuxPowerManager, LibXR::MSPM0PowerManager, and LibXR::STM32PowerManager.

◆ Shutdown()

virtual void LibXR::PowerManager::Shutdown ( )
pure virtual

关闭系统电源 / Shuts down the system power

该方法应由子类实现,用于执行系统关机操作,例如断开电源或进入低功耗模式。 This method should be implemented by subclasses to perform system shutdown operations, such as cutting off power or entering a low-power mode.

Implemented in LibXR::CH32PowerManager, LibXR::HPMPowerManager, LibXR::LinuxPowerManager, LibXR::MSPM0PowerManager, and LibXR::STM32PowerManager.


The documentation for this class was generated from the following files: