Skip to content

Commit

Permalink
pm: Use new MPSL PM API
Browse files Browse the repository at this point in the history
Use the new MPSL PM API where event registration
and low latency request are handled separately.

Signed-off-by: Knut Eldhuset <[email protected]>
  • Loading branch information
knutel-nordic committed Dec 27, 2024
1 parent 6862306 commit 3d4273d
Show file tree
Hide file tree
Showing 2 changed files with 157 additions and 197 deletions.
39 changes: 28 additions & 11 deletions subsys/mpsl/pm/mpsl_pm_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ static void m_update_latency_request(uint32_t lat_value_us)
}
}

void mpsl_pm_utils_work_handler(void)
void m_register_event(void)
{
mpsl_pm_params_t params = {0};
bool pm_param_valid = mpsl_pm_params_get(&params);
Expand All @@ -58,8 +58,6 @@ void mpsl_pm_utils_work_handler(void)
switch (params.event_state) {
case MPSL_PM_EVENT_STATE_NO_EVENTS_LEFT:
{
/* No event scheduled, so set latency to restrict deepest sleep states*/
m_update_latency_request(PM_MAX_LATENCY_HCI_COMMANDS_US);
if (m_pm_event_is_registered) {
pm_policy_event_unregister(&m_evt);
m_pm_event_is_registered = false;
Expand All @@ -68,9 +66,6 @@ void mpsl_pm_utils_work_handler(void)
}
case MPSL_PM_EVENT_STATE_BEFORE_EVENT:
{
/* In case we missed a state and are in zero-latency, set low-latency.*/
m_update_latency_request(PM_MAX_LATENCY_HCI_COMMANDS_US);

/* Note: Considering an overflow could only happen if the system runs many years,
* it needen't be considered here.
*/
Expand Down Expand Up @@ -107,15 +102,37 @@ void mpsl_pm_utils_work_handler(void)
}
break;
}
case MPSL_PM_EVENT_STATE_IN_EVENT:
{
m_update_latency_request(0);
break;
}
default:
__ASSERT(false, "MPSL PM is in an undefined state.");
}
m_pm_prev_flag_value = params.cnt_flag;
mpsl_pm_event_registered_ack(params.cnt_flag);
}

static void m_register_latency(void)
{
switch (mpsl_pm_low_latency_state_get()) {
case MPSL_PM_LOW_LATENCY_STATE_OFF:
if (mpsl_pm_low_latency_requested()) {
m_update_latency_request(0);
mpsl_pm_low_latency_state_set(MPSL_PM_LOW_LATENCY_STATE_ON);
}
break;
case MPSL_PM_LOW_LATENCY_STATE_ON:
if (!mpsl_pm_low_latency_requested()) {
m_update_latency_request(PM_MAX_LATENCY_HCI_COMMANDS_US);
mpsl_pm_low_latency_state_set(MPSL_PM_LOW_LATENCY_STATE_OFF);
}
break;
default:
break;
}
}

void mpsl_pm_utils_work_handler(void)
{
m_register_event();
m_register_latency();
}

static void m_work_handler(struct k_work *work)
Expand Down
Loading

0 comments on commit 3d4273d

Please sign in to comment.