2017-01-11 21:48:16 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2017 Kaspar Schleiser <kaspar@schleiser.de>
|
|
|
|
*
|
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser
|
|
|
|
* General Public License v2.1. See the file LICENSE in the top level
|
|
|
|
* directory for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2017-01-13 10:55:53 +01:00
|
|
|
* @defgroup sys_pm_layered Layered PM Infrastructure
|
|
|
|
* @ingroup sys
|
2017-01-11 21:48:16 +01:00
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* This module provides a base infrastructure that MCU's may use to implement
|
|
|
|
* periph/pm.
|
|
|
|
*
|
|
|
|
* This simple power management interface is based on the following assumptions:
|
|
|
|
*
|
2022-04-02 19:19:40 +02:00
|
|
|
* - CPUs define a number of power modes (from zero, the lowest power mode, to
|
|
|
|
* PM_NUM_MODES, the highest)
|
|
|
|
* - there is an implicit extra busy-wait mode (which has the number PM_NUM_MODES)
|
|
|
|
* where the CPU is kept spinning if all modes are blocked.
|
2017-01-11 21:48:16 +01:00
|
|
|
* - individual power modes can be blocked/unblocked, e.g., by peripherals
|
|
|
|
* - if a mode is blocked, so are implicitly all lower modes
|
|
|
|
* - the idle thread automatically selects and sets the lowest unblocked mode
|
|
|
|
*
|
|
|
|
* In order to use this module, you'll need to implement pm_set().
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @brief Layered low power mode infrastructure
|
|
|
|
*
|
|
|
|
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
|
|
|
*/
|
|
|
|
|
2017-01-18 13:00:05 +01:00
|
|
|
#ifndef PM_LAYERED_H
|
|
|
|
#define PM_LAYERED_H
|
2017-01-11 21:48:16 +01:00
|
|
|
|
2020-12-08 18:13:01 +01:00
|
|
|
#include <stdint.h>
|
2017-01-11 21:48:16 +01:00
|
|
|
#include "periph_cpu.h"
|
2022-11-04 16:50:52 +01:00
|
|
|
#include "architecture.h"
|
2017-01-11 21:48:16 +01:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
2017-10-12 16:20:15 +02:00
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef PROVIDES_PM_OFF
|
|
|
|
#define PROVIDES_PM_OFF
|
2017-01-11 21:48:16 +01:00
|
|
|
#endif
|
|
|
|
|
2017-10-25 17:07:55 +02:00
|
|
|
#ifndef PROVIDES_PM_SET_LOWEST
|
|
|
|
#define PROVIDES_PM_SET_LOWEST
|
|
|
|
#endif
|
|
|
|
|
2019-07-10 03:38:37 +02:00
|
|
|
/**
|
|
|
|
* @brief Power Management mode blocker typedef
|
|
|
|
*/
|
2022-04-02 19:19:40 +02:00
|
|
|
typedef struct {
|
2022-04-04 13:47:36 +02:00
|
|
|
uint8_t blockers[PM_NUM_MODES]; /**< number of blockers for the mode */
|
2022-11-04 16:50:52 +01:00
|
|
|
} WORD_ALIGNED pm_blocker_t;
|
2019-07-10 03:38:37 +02:00
|
|
|
|
2017-01-11 21:48:16 +01:00
|
|
|
/**
|
|
|
|
* @brief Block a power mode
|
|
|
|
*
|
|
|
|
* @param[in] mode power mode to block
|
|
|
|
*/
|
2021-01-27 11:48:08 +01:00
|
|
|
#ifdef MODULE_PM_LAYERED
|
2017-01-11 21:48:16 +01:00
|
|
|
void pm_block(unsigned mode);
|
2021-01-27 11:48:08 +01:00
|
|
|
#else
|
|
|
|
static inline void pm_block(unsigned mode) { (void)mode; }
|
|
|
|
#endif
|
2017-01-11 21:48:16 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Unblock a power mode
|
|
|
|
*
|
|
|
|
* @param[in] mode power mode to unblock
|
|
|
|
*/
|
2021-01-27 11:48:08 +01:00
|
|
|
#ifdef MODULE_PM_LAYERED
|
2017-01-11 21:48:16 +01:00
|
|
|
void pm_unblock(unsigned mode);
|
2021-01-27 11:48:08 +01:00
|
|
|
#else
|
|
|
|
static inline void pm_unblock(unsigned mode) { (void)mode; }
|
|
|
|
#endif
|
2017-01-11 21:48:16 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Switches the MCU to a new power mode
|
|
|
|
*
|
|
|
|
* This function will be called by @ref pm_set_lowest() after determining the
|
|
|
|
* lowest non-blocked mode.
|
|
|
|
*
|
|
|
|
* It needs to be implemented for each MCU using this module.
|
|
|
|
*
|
|
|
|
* @param[in] mode Target power mode
|
|
|
|
*/
|
|
|
|
void pm_set(unsigned mode);
|
|
|
|
|
2020-04-29 11:07:12 +02:00
|
|
|
/**
|
|
|
|
* @brief Get currently blocked PM modes
|
|
|
|
*
|
|
|
|
* @return The current blocker state
|
|
|
|
*
|
|
|
|
* This function atomically retrieves the currently blocked PM modes.
|
|
|
|
*/
|
|
|
|
pm_blocker_t pm_get_blocker(void);
|
|
|
|
|
2017-01-11 21:48:16 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-05-23 18:19:52 +02:00
|
|
|
#endif /* PM_LAYERED_H */
|
2017-01-11 21:48:16 +01:00
|
|
|
/** @} */
|