Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PM: allow custom policy to use default policy code without duplication #62550

Closed
wants to merge 2 commits into from
Closed
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
21 changes: 18 additions & 3 deletions include/zephyr/pm/policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,17 @@ struct pm_policy_event {
uint32_t value_cyc;
};

/** @cond INTERNAL_HIDDEN */

/**
* @brief Function to get the next PM state
*
* This function is called by the power subsystem when the system is
* idle and returns the most appropriate state based on the number of
* ticks to the next event.
*
* When :kconfig:option:`CONFIG_PM_POLICY_DEFAULT` is not set, the application
* or SoC implementation can implement this function to provide a custom
* policy.
*
* @param cpu CPU index.
* @param ticks The number of ticks to the next scheduled event.
*
Expand All @@ -81,7 +83,20 @@ struct pm_policy_event {
*/
const struct pm_state_info *pm_policy_next_state(uint8_t cpu, int32_t ticks);

/** @endcond */
/**
* @brief Function to get the next PM state (Default policy)
*
* This function is called by the power subsystem when the system is
* idle and returns the most appropriate state based on the number of
* ticks to the next event.
*
* @param cpu CPU index.
* @param ticks The number of ticks to the next scheduled event.
*
* @return The power state the system should use for the given cpu. The function
* will return NULL if system should remain into PM_STATE_ACTIVE.
*/
const struct pm_state_info *pm_policy_default_next_state(uint8_t cpu, int32_t ticks);

/** Special value for 'all substates'. */
#define PM_ALL_SUBSTATES (UINT8_MAX)
Expand Down
10 changes: 8 additions & 2 deletions subsys/pm/policy.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,7 @@ static void update_next_event(uint32_t cyc)
next_event_cyc = new_next_event_cyc;
}

#ifdef CONFIG_PM_POLICY_DEFAULT
const struct pm_state_info *pm_policy_next_state(uint8_t cpu, int32_t ticks)
const struct pm_state_info *pm_policy_default_next_state(uint8_t cpu, int32_t ticks)
{
int64_t cyc = -1;
uint8_t num_cpu_states;
Expand Down Expand Up @@ -189,6 +188,13 @@ const struct pm_state_info *pm_policy_next_state(uint8_t cpu, int32_t ticks)

return NULL;
}

#ifdef CONFIG_PM_POLICY_DEFAULT
const struct pm_state_info *pm_policy_next_state(uint8_t cpu, int32_t ticks)
{

return pm_policy_default_next_state(cpu, ticks);
}
#endif

void pm_policy_state_lock_get(enum pm_state state, uint8_t substate_id)
Expand Down
Loading