-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
modules: nrfxlib: nrf_802154: add lptimer pm utils module
Adds pm utils module that updates the Power Management module upon the request from the 802.15.4 lptimer module. Signed-off-by: Piotr Koziar <[email protected]>
- Loading branch information
1 parent
509fa66
commit 37ebaa0
Showing
4 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
modules/nrfxlib/nrf_802154/sl/platform/nrf_802154_platform_sl_lptimer_grtc_pm_utils.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright (c) 2024 Nordic Semiconductor ASA | ||
* | ||
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
*/ | ||
|
||
#include "nrf_802154_platform_sl_lptimer_grtc_pm_utils.h" | ||
|
||
#include <zephyr/kernel.h> | ||
#include <zephyr/pm/policy.h> | ||
|
||
#define LPTIMER_PM_UTILS_STACK_SIZE 1024 | ||
|
||
static K_SEM_DEFINE(m_lptimer_pm_utils_sem, 0, 1); | ||
|
||
static struct pm_policy_event m_pm_event; | ||
static int64_t m_trigger_time; | ||
static bool m_event_registered; | ||
|
||
#define SYS_TICK_PER_GRTC_CYC \ | ||
((uint64_t)CONFIG_SYS_CLOCK_TICKS_PER_SEC / (uint64_t)sys_clock_hw_cycles_per_sec()) | ||
|
||
static int64_t grtc_ticks_to_system_ticks(uint64_t abs_grtc) | ||
{ | ||
int64_t curr_sys = k_uptime_ticks(); | ||
uint64_t curr_grtc = z_nrf_grtc_timer_read(); | ||
|
||
uint64_t result = (abs_grtc > curr_grtc) ? (abs_grtc - curr_grtc) : 0; | ||
|
||
return curr_sys + result * SYS_TICK_PER_GRTC_CYC; | ||
} | ||
|
||
void nrf_802154_platform_sl_lptimer_pm_utils_event_update(uint64_t grtc_ticks) | ||
{ | ||
int64_t event_time = (grtc_ticks > 0) ? grtc_ticks_to_system_ticks(grtc_ticks) : 0; | ||
|
||
if (m_trigger_time != event_time) { | ||
m_trigger_time = event_time; | ||
|
||
k_sem_give(&m_lptimer_pm_utils_sem); | ||
} | ||
} | ||
|
||
static void lptimer_pm_utils_thread_func(void *dummy1, void *dummy2, void *dummy3) | ||
{ | ||
ARG_UNUSED(dummy1); | ||
ARG_UNUSED(dummy2); | ||
ARG_UNUSED(dummy3); | ||
|
||
while (true) { | ||
k_sem_take(&m_lptimer_pm_utils_sem, K_FOREVER); | ||
|
||
if (m_trigger_time == 0) { | ||
if (m_event_registered) { | ||
pm_policy_event_unregister(&m_pm_event); | ||
} | ||
m_event_registered = false; | ||
} else if (!m_event_registered) { | ||
pm_policy_event_register(&m_pm_event, m_trigger_time); | ||
m_event_registered = true; | ||
} else { | ||
pm_policy_event_update(&m_pm_event, m_trigger_time); | ||
} | ||
} | ||
} | ||
|
||
K_THREAD_DEFINE(lptimer_pm_utils_thread, LPTIMER_PM_UTILS_STACK_SIZE, | ||
lptimer_pm_utils_thread_func, NULL, NULL, NULL, K_LOWEST_APPLICATION_THREAD_PRIO, 0, 0); |
43 changes: 43 additions & 0 deletions
43
modules/nrfxlib/nrf_802154/sl/platform/nrf_802154_platform_sl_lptimer_grtc_pm_utils.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright (c) 2024 Nordic Semiconductor ASA | ||
* | ||
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
*/ | ||
|
||
#ifndef NRF_802154_PLATFORM_SL_LPTIMER_GRTC_PM_UTILS_H_ | ||
#define NRF_802154_PLATFORM_SL_LPTIMER_GRTC_PM_UTILS_H_ | ||
|
||
#include <stdint.h> | ||
|
||
/** | ||
* @brief Updates the trigger time of an upcoming event, allowing forwarding it to | ||
* the Power Management module. | ||
* | ||
* After some delay, the event's trigger time is sent to the Power Management module | ||
* via @ref pm_policy_event_register or @ref pm_policy_event_update. | ||
* | ||
* This function opens a sequence that should be closed | ||
* by @ref nrf_802154_platform_sl_lptimer_pm_utils_event_unregister call. | ||
* In the meantime, the @ref nrf_802154_platform_sl_lptimer_pm_utils_event_update can be called | ||
* multiple times. | ||
* | ||
* @note There is no guarantee, that the aforementioned pm_policy methods will be called before | ||
* the event's trigger time. | ||
* | ||
* @param grtc_ticks When the event will occur, in absolute GRTC ticks. | ||
*/ | ||
void nrf_802154_platform_sl_lptimer_pm_utils_event_update(uint64_t grtc_ticks); | ||
|
||
/** | ||
* @brief Informs that there are no events planned and the Power Management event | ||
* registered by @ref nrf_802154_platform_sl_lptimer_pm_utils_event_update requires unregistration. | ||
* | ||
* Unless already called and if the @ref nrf_802154_platform_sl_lptimer_pm_utils_event_update | ||
* precedes this function, the function will call @ref pm_policy_event_unregister with some delay. | ||
*/ | ||
static inline void nrf_802154_platform_sl_lptimer_pm_utils_event_unregister(void) | ||
{ | ||
return nrf_802154_platform_sl_lptimer_pm_utils_event_update(0); | ||
} | ||
|
||
#endif /* NRF_802154_PLATFORM_SL_LPTIMER_GRTC_PM_UTILS_H_ */ |