简介
设备电源管理由设备驱动程序模型
的接口组成。系统提供API
向设备驱动程序
发送控制命令
,以更新其电源状态
或获取其当前电源状态
。
Zephyr RTOS支持两种进行设备电源管理的方法。
- 运行时设备电源管理
- 系统电源管理
运行时设备电源管理
其实就是设备驱动
自身来维护自己是否需要进入省电模式
,而不需要通过应用程序进行参与,但应用程序可以决定设备是否可以启用
运行时设备电源管理。
系统电源管理
设备的系统电源管理
其实就是在进行系统电源管理
的时候同时将设备也进行管理。
忙碌状态指示
如果设备此时正在进行操作,那由于设备电源管理导致设备进入了休眠状态,此时可能导致设备的数据丢失,更加糟糕的是可能导致系统死机。因此Zephyr给我们提供了API,可以控制设备的忙碌标志,当设备忙碌标志设置的时候,那么此设备就无法进入休眠状态。
/**
* @brief Indicate that the device is in the middle of a transaction
*
* Called by a device driver to indicate that it is in the middle of a
* transaction.
*
* @param dev Pointer to device structure of the driver instance.
*/
void pm_device_busy_set(const struct device *dev);
/**
* @brief Indicate that the device has completed its transaction
*
* Called by a device driver to indicate the end of a transaction.
*
* @param dev Pointer to device structure of the driver instance.
*/
void pm_device_busy_clear(const struct device *dev);
/**
* @brief Check if any device is in the middle of a transaction
*
* Called by an application to see if any device is in the middle
* of a critical transaction that cannot be interrupted.
*
* @retval false if no device is busy
* @retval true if any device is busy
*/
bool pm_device_is_any_busy(void);
/**
* @brief Check if a specific device is in the middle of a transaction
*
* Called by an application to see if a particular device is in the
* middle of a critical transaction that cannot be interrupted.
*
* @param dev Pointer to device structure of the specific device driver
* the caller is interested in.
* @retval false if the device is not busy
* @retval true if the device is busy
*/
bool pm_device_is_busy(const struct device *dev);
- pm_device_busy_set: 设置设备忙碌标志
- pm_device_busy_clear:清除设备忙碌标志
- pm_device_is_any_busy:检查任何设备的忙碌标志
- pm_device_is_busy:检查设备的忙碌标志
设备的唤醒功能
某些设备能够将系统从睡眠
状态唤醒。当设备具有此类功能时,应用程序可以使用pm_device_wakeup_enable()
在设备上动态启用
或禁用
此功能。
也可以在设备树
的设备节点
中声明wakeup-source属性
,来表明此设备可以唤醒系统。例如:
gpio0: gpio@40022000 {
compatible = "ti,cc13xx-cc26xx-gpio";
reg = <0x40022000 0x400>;
interrupts = <0 0>;
status = "disabled";
label = "GPIO_0";
gpio-controller;
wakeup-source;
#gpio-cells = <2>;
};
应用程序可以在以后调用pm_device_wakeup_enable()
来让设备唤醒系统。
电源域
这个电源域的概念其实就是当一个电源芯片上外接了很多的设备,此时如果只将电源芯片进行休眠,那外部设备此时并没有休眠,那么就可能导致一些问题的发生,但如果说我将外部设备休眠后在来休眠电源芯片,那程序的设计复杂度就会很高,那么这个时候电源域就有用处了,比如说我将电源芯片设置成一个域,外围设备都是这个域内的成员,那么当电源芯片休眠的时候,外围设备也会调用休眠函数;当电源设备恢复的时候,外围设备也会调用。虽然这个例子并不能完全说明域的概念。
在启用CONFIG_PM_DEVICE_RUNTIME
后,每次挂起
或恢复
设备时,都会在设备所属的域
中执行相同的操作。