Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions boards/arm/cc1352r1_launchxl/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,9 @@ disable sleep state 2 while polling:

.. code-block:: c

pm_ctrl_disable_state(PM_STATE_STANDBY);
pm_constraint_set(PM_STATE_STANDBY);
<code that calls uart_poll_in() and expects input at any point in time>
pm_ctrl_enable_state(PM_STATE_STANDBY);
pm_constraint_release(PM_STATE_STANDBY);


References
Expand Down
4 changes: 2 additions & 2 deletions boards/arm/cc1352r_sensortag/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,9 @@ disable sleep state 2 while polling:

.. code-block:: c

pm_ctrl_disable_state(PM_STATE_STANDBY);
pm_constraint_set(PM_STATE_STANDBY);
<code that calls uart_poll_in() and expects input at any point in time>
pm_ctrl_enable_state(PM_STATE_STANDBY);
pm_constraint_release(PM_STATE_STANDBY);


References
Expand Down
4 changes: 2 additions & 2 deletions boards/arm/cc26x2r1_launchxl/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,9 @@ disable sleep state 2 while polling:

.. code-block:: c

pm_ctrl_disable_state(PM_STATE_STANDBY);
pm_constraint_set(PM_STATE_STANDBY);
<code that calls uart_poll_in() and expects input at any point in time>
pm_ctrl_enable_state(PM_STATE_STANDBY);
pm_constraint_release(PM_STATE_STANDBY);


References
Expand Down
6 changes: 3 additions & 3 deletions drivers/entropy/entropy_cc13xx_cc26xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ static int entropy_cc13xx_cc26xx_get_entropy(const struct device *dev,
unsigned int key = irq_lock();

if (!data->constrained) {
pm_ctrl_disable_state(PM_STATE_STANDBY);
pm_constraint_set(PM_STATE_STANDBY);
data->constrained = true;
}
irq_unlock(key);
Expand Down Expand Up @@ -154,7 +154,7 @@ static void entropy_cc13xx_cc26xx_isr(const void *arg)
if (cnt != sizeof(num)) {
#ifdef CONFIG_PM
if (data->constrained) {
pm_ctrl_enable_state(
pm_constraint_release(
PM_STATE_STANDBY);
data->constrained = false;
}
Expand Down Expand Up @@ -333,7 +333,7 @@ static int entropy_cc13xx_cc26xx_init(const struct device *dev)
#if defined(CONFIG_PM)
Power_setDependency(PowerCC26XX_PERIPH_TRNG);
/* Stay out of standby until buffer is filled with entropy */
pm_ctrl_disable_state(PM_STATE_STANDBY);
pm_constraint_set(PM_STATE_STANDBY);
data->constrained = true;
/* Register notification function */
Power_registerNotify(&data->post_notify,
Expand Down
4 changes: 2 additions & 2 deletions drivers/i2c/i2c_cc13xx_cc26xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ static int i2c_cc13xx_cc26xx_transfer(const struct device *dev,
k_sem_take(&get_dev_data(dev)->lock, K_FOREVER);

#ifdef CONFIG_PM
pm_ctrl_disable_state(PM_STATE_STANDBY);
pm_constraint_set(PM_STATE_STANDBY);
#endif

for (int i = 0; i < num_msgs; i++) {
Expand All @@ -232,7 +232,7 @@ static int i2c_cc13xx_cc26xx_transfer(const struct device *dev,
}

#ifdef CONFIG_PM
pm_ctrl_enable_state(PM_STATE_STANDBY);
pm_constraint_release(PM_STATE_STANDBY);
#endif

k_sem_give(&get_dev_data(dev)->lock);
Expand Down
8 changes: 4 additions & 4 deletions drivers/serial/uart_cc13xx_cc26xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ static void uart_cc13xx_cc26xx_irq_tx_enable(const struct device *dev)
* standby mode instead, since it is the power state that
* would interfere with a transfer.
*/
pm_ctrl_disable_state(PM_STATE_STANDBY);
pm_constraint_set(PM_STATE_STANDBY);
get_dev_data(dev)->tx_constrained = true;
}
#endif
Expand All @@ -257,7 +257,7 @@ static void uart_cc13xx_cc26xx_irq_tx_disable(const struct device *dev)

#ifdef CONFIG_PM
if (get_dev_data(dev)->tx_constrained) {
pm_ctrl_enable_state(PM_STATE_STANDBY);
pm_constraint_release(PM_STATE_STANDBY);
get_dev_data(dev)->tx_constrained = false;
}
#endif
Expand All @@ -277,7 +277,7 @@ static void uart_cc13xx_cc26xx_irq_rx_enable(const struct device *dev)
* standby.
*/
if (!get_dev_data(dev)->rx_constrained) {
pm_ctrl_disable_state(PM_STATE_STANDBY);
pm_constraint_set(PM_STATE_STANDBY);
get_dev_data(dev)->rx_constrained = true;
}
#endif
Expand All @@ -289,7 +289,7 @@ static void uart_cc13xx_cc26xx_irq_rx_disable(const struct device *dev)
{
#ifdef CONFIG_PM
if (get_dev_data(dev)->rx_constrained) {
pm_ctrl_enable_state(PM_STATE_STANDBY);
pm_constraint_release(PM_STATE_STANDBY);
get_dev_data(dev)->rx_constrained = false;
}
#endif
Expand Down
4 changes: 2 additions & 2 deletions drivers/spi/spi_cc13xx_cc26xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ static int spi_cc13xx_cc26xx_transceive(const struct device *dev,
spi_context_lock(ctx, false, NULL, config);

#ifdef CONFIG_PM
pm_ctrl_disable_state(PM_STATE_STANDBY);
pm_constraint_set(PM_STATE_STANDBY);
#endif

err = spi_cc13xx_cc26xx_configure(dev, config);
Expand Down Expand Up @@ -185,7 +185,7 @@ static int spi_cc13xx_cc26xx_transceive(const struct device *dev,

done:
#ifdef CONFIG_PM
pm_ctrl_enable_state(PM_STATE_STANDBY);
pm_constraint_release(PM_STATE_STANDBY);
#endif
spi_context_release(ctx, err);
return err;
Expand Down
24 changes: 13 additions & 11 deletions include/power/power.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,31 +159,34 @@ void pm_dump_debug_info(void);

#endif /* CONFIG_PM_DEBUG */

#ifdef CONFIG_PM_STATE_LOCK
/**
* @brief Disable particular power state
* @brief Set a constraint for a power state
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One point is not clear to me on this API. Not sure if this is the right pace to discuss. Please discard this comment if this isn't.
When setting a constraint on a particular state, should we assume the same constraint should be used on "deeper sleep states", or is the caller expected to call all related states where the constrain apply?

What about substates ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to wait to discuss that, since this PR is just renaming stuff, but:

  • I'm not sure if we can assume a strict linear ordering such that if you block a transition to STANDBY you implicitly block transition to SUSPEND_TO_RAM and other "lower" states. Need to see what the prior art does.
  • yes, constraints are going to have to take substates into account, either explicitly or through some other back door.

*
* @details Disabled state cannot be selected by the Zephyr power
* management policies. Application defined policy should
* use the @ref pm_ctrl_is_state_enabled function to
* check if given state could is enabled and could be used.
* use the @ref pm_constraint_get function to
* check if given state is enabled and could be used.
*
* @note This API is refcount
*
* @param [in] state Power state to be disabled.
*/
void pm_ctrl_disable_state(enum pm_state state);
void pm_constraint_set(enum pm_state state);

/**
* @brief Enable particular power state
* @brief Release a constraint for a power state
*
* @details Enabled state can be selected by the Zephyr power
* management policies. Application defined policy should
* use the @ref pm_ctrl_is_state_enabled function to
* check if given state could is enabled and could be used.
* use the @ref pm_constraint_get function to
* check if given state is enabled and could be used.
* By default all power states are enabled.
*
* @note This API is refcount
*
* @param [in] state Power state to be enabled.
*/
void pm_ctrl_enable_state(enum pm_state state);
void pm_constraint_release(enum pm_state state);

/**
* @brief Check if particular power state is enabled
Expand All @@ -192,9 +195,8 @@ void pm_ctrl_enable_state(enum pm_state state);
*
* @param [in] state Power state.
*/
bool pm_ctrl_is_state_enabled(enum pm_state state);
bool pm_constraint_get(enum pm_state state);

#endif /* CONFIG_PM_STATE_LOCK */

/**
* @}
Expand Down
1 change: 0 additions & 1 deletion samples/boards/nrf/system_off/prj.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
CONFIG_PM=y
# Required to disable default behavior of deep sleep on timeout
CONFIG_PM_STATE_LOCK=y
CONFIG_PM_DEVICE=y
CONFIG_GPIO=y
2 changes: 1 addition & 1 deletion samples/boards/nrf/system_off/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ static int disable_ds_1(const struct device *dev)
{
ARG_UNUSED(dev);

pm_ctrl_disable_state(PM_STATE_SOFT_OFF);
pm_constraint_set(PM_STATE_SOFT_OFF);
return 0;
}

Expand Down
1 change: 0 additions & 1 deletion soc/arm/ti_simplelink/cc13x2_cc26x2/Kconfig.series
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@ config SOC_SERIES_CC13X2_CC26X2
select SOC_FAMILY_TISIMPLELINK
select HAS_CC13X2_CC26X2_SDK
select HAS_TI_CCFG
select PM_STATE_LOCK if PM
help
Enable support for TI SimpleLink CC13x2 / CC26x2 SoCs
2 changes: 1 addition & 1 deletion subsys/power/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# SPDX-License-Identifier: Apache-2.0

zephyr_sources_ifdef(CONFIG_PM power.c)
zephyr_sources_ifdef(CONFIG_PM pm_ctrl.c)
zephyr_sources_ifdef(CONFIG_PM_DEVICE device.c)
zephyr_sources_ifdef(CONFIG_PM_STATE_LOCK pm_ctrl.c)
zephyr_sources_ifdef(CONFIG_PM_DEVICE_IDLE device_pm.c)
zephyr_sources_ifdef(CONFIG_REBOOT reboot.c)
add_subdirectory(policy)
8 changes: 0 additions & 8 deletions subsys/power/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,6 @@ menuconfig PM

if PM

config PM_STATE_LOCK
bool "Power State locking capability"
help
Enable Power Management system state locking capability
if any application wants to temporarily disable certain
Power States while doing any critical work or needs quick
response from hardware resources.

config PM_DIRECT_FORCE_MODE
bool "System power management direct force trigger mode"
help
Expand Down
6 changes: 3 additions & 3 deletions subsys/power/pm_ctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ LOG_MODULE_DECLARE(power);

static atomic_t power_state_disable_count[PM_STATES_LEN];

void pm_ctrl_disable_state(enum pm_state state)
void pm_constraint_set(enum pm_state state)
{
atomic_val_t v;

Expand All @@ -31,7 +31,7 @@ void pm_ctrl_disable_state(enum pm_state state)
(void)(v);
}

void pm_ctrl_enable_state(enum pm_state state)
void pm_constraint_release(enum pm_state state)
{
atomic_val_t v;

Expand All @@ -43,7 +43,7 @@ void pm_ctrl_enable_state(enum pm_state state)
(void)(v);
}

bool pm_ctrl_is_state_enabled(enum pm_state state)
bool pm_constraint_get(enum pm_state state)
{
__ASSERT(state < PM_STATES_LEN, "Invalid power state!");

Expand Down
5 changes: 2 additions & 3 deletions subsys/power/policy/policy_dummy.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,11 @@ struct pm_state_info pm_policy_next_state(int32_t ticks)
do {
i = (i + 1) % states_len;

#ifdef CONFIG_PM_STATE_LOCK
if (!pm_ctrl_is_state_enabled(
if (!pm_constraint_get(
pm_dummy_states[i].state)) {
continue;
}
#endif

cur_pm_state_info = pm_dummy_states[i];

LOG_DBG("Selected power state: %u", pm_dummy_states[i].state);
Expand Down
5 changes: 2 additions & 3 deletions subsys/power/policy/policy_residency.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ struct pm_state_info pm_policy_next_state(int32_t ticks)
int i;

for (i = ARRAY_SIZE(pm_min_residency) - 1; i >= 0; i--) {
#ifdef CONFIG_PM_STATE_LOCK
if (!pm_ctrl_is_state_enabled(pm_min_residency[i].state)) {
if (!pm_constraint_get(pm_min_residency[i].state)) {
continue;
}
#endif

if ((ticks == K_TICKS_FOREVER) ||
(ticks >= k_us_to_ticks_ceil32(
pm_min_residency[i].min_residency_us))) {
Expand Down
5 changes: 2 additions & 3 deletions subsys/power/policy/policy_residency_cc13x2_cc26x2.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,10 @@ struct pm_state_info pm_policy_next_state(int32_t ticks)
}

for (i = ARRAY_SIZE(residency_info) - 1; i >= 0; i--) {
#ifdef CONFIG_PM_STATE_LOCK
if (!pm_ctrl_is_state_enabled(residency_info[i].state)) {
if (!pm_constraint_get(residency_info[i].state)) {
continue;
}
#endif

if ((ticks <
k_us_to_ticks_ceil32(residency_info[i].min_residency_us))
&& (ticks != K_TICKS_FOREVER)) {
Expand Down