forked from nrfconnect/sdk-zephyr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[nrf fromlist] soc: nordic: add fn for setting constlat mode
Nordic SoCs implement an event system, for which the system can optimize for low latency/high power or low power. Add soc level implementation of reference counted API which will optimize for low latency if any part of the system requires it. Upstream PR: zephyrproject-rtos/zephyr#79934 Signed-off-by: Bjarki Arge Andreasen <[email protected]>
- Loading branch information
1 parent
52e3063
commit fe29da2
Showing
4 changed files
with
131 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
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,95 @@ | ||
/* | ||
* Copyright (c) 2024 Nordic Semiconductor ASA | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <nrf_sys_event.h> | ||
|
||
#if CONFIG_SOC_SERIES_NRF54HX | ||
|
||
/* | ||
* The 54HX is not yet supported by an nrfx driver nor the system controller so | ||
* we implement an ISR and concurrent access safe reference counting implementation | ||
* here using the nrfx hal. | ||
*/ | ||
|
||
#include <hal/nrf_lrcconf.h> | ||
|
||
static struct k_spinlock global_constlat_lock; | ||
static uint16_t global_constlat_count; | ||
|
||
int nrf_sys_event_request_global_constlat(void) | ||
{ | ||
K_SPINLOCK(&global_constlat_lock) { | ||
if (global_constlat_count == 0) { | ||
#if CONFIG_SOC_NRF54H20_CPUAPP | ||
nrf_lrcconf_task_trigger(NRF_LRCCONF010, | ||
NRF_LRCCONF_TASK_CONSTLAT_ENABLE); | ||
#elif CONFIG_SOC_NRF54H20_CPURAD | ||
nrf_lrcconf_task_trigger(NRF_LRCCONF000, | ||
NRF_LRCCONF_TASK_CONSTLAT_ENABLE); | ||
nrf_lrcconf_task_trigger(NRF_LRCCONF020, | ||
NRF_LRCCONF_TASK_CONSTLAT_ENABLE); | ||
#else | ||
#error "unsupported" | ||
#endif | ||
} | ||
|
||
global_constlat_count++; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
int nrf_sys_event_release_global_constlat(void) | ||
{ | ||
K_SPINLOCK(&global_constlat_lock) { | ||
if (global_constlat_count == 1) { | ||
#if CONFIG_SOC_NRF54H20_CPUAPP | ||
nrf_lrcconf_task_trigger(NRF_LRCCONF010, | ||
NRF_LRCCONF_TASK_CONSTLAT_DISABLE); | ||
#elif CONFIG_SOC_NRF54H20_CPURAD | ||
nrf_lrcconf_task_trigger(NRF_LRCCONF000, | ||
NRF_LRCCONF_TASK_CONSTLAT_DISABLE); | ||
nrf_lrcconf_task_trigger(NRF_LRCCONF020, | ||
NRF_LRCCONF_TASK_CONSTLAT_DISABLE); | ||
#else | ||
#error "unsupported" | ||
#endif | ||
} | ||
|
||
global_constlat_count--; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
#else | ||
|
||
/* | ||
* The nrfx power driver already contains an ISR and concurrent access safe reference | ||
* counting API so we just use it directly when available. | ||
*/ | ||
|
||
#include <nrfx_power.h> | ||
|
||
int nrf_sys_event_request_global_constlat(void) | ||
{ | ||
nrfx_err_t err; | ||
|
||
err = nrfx_power_constlat_mode_request(); | ||
|
||
return (err == NRFX_SUCCESS || err == NRFX_ERROR_ALREADY) ? 0 : -EAGAIN; | ||
} | ||
|
||
int nrf_sys_event_release_global_constlat(void) | ||
{ | ||
nrfx_err_t err; | ||
|
||
err = nrfx_power_constlat_mode_free(); | ||
|
||
return (err == NRFX_SUCCESS || err == NRFX_ERROR_BUSY) ? 0 : -EAGAIN; | ||
} | ||
|
||
#endif |
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,30 @@ | ||
/* | ||
* Copyright (c) 2024 Nordic Semiconductor ASA | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <zephyr/kernel.h> | ||
|
||
/** | ||
* @brief Request lowest latency for system events | ||
* | ||
* @details System will be configured for lowest latency after first | ||
* call to nrf_sys_event_request_global_constlat() and will remain | ||
* configured for lowest latency until matching number of calls to | ||
* nrf_sys_event_release_global_constlat() occur. | ||
* | ||
* @retval 0 if successful | ||
* @retval -errno code otherwise | ||
*/ | ||
int nrf_sys_event_request_global_constlat(void); | ||
|
||
/** | ||
* @brief Release low latency request | ||
* | ||
* @see nrf_sys_event_request_global_constlat() | ||
* | ||
* @retval 0 if successful | ||
* @retval -errno code otherwise | ||
*/ | ||
int nrf_sys_event_release_global_constlat(void); |