Skip to content

Commit becf3de

Browse files
bjarki-andreasenrlubos
authored andcommitted
[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 #: 79934 Signed-off-by: Bjarki Arge Andreasen <[email protected]>
1 parent b7cc11b commit becf3de

File tree

4 files changed

+131
-0
lines changed

4 files changed

+131
-0
lines changed

soc/nordic/common/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,5 @@ if(CONFIG_TFM_PARTITION_PLATFORM)
3232
$<TARGET_PROPERTY:tfm,TFM_BINARY_DIR>/api_ns/interface/include
3333
)
3434
endif()
35+
36+
zephyr_library_sources_ifdef(CONFIG_NRF_SYS_EVENT nrf_sys_event.c)

soc/nordic/common/Kconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,8 @@
44
config HAS_NORDIC_DMM
55
bool
66

7+
config NRF_SYS_EVENT
8+
bool "nRF system event support"
9+
select NRFX_POWER if !NRF_PLATFORM_HALTIUM
10+
711
rsource "vpr/Kconfig"

soc/nordic/common/nrf_sys_event.c

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <nrf_sys_event.h>
8+
9+
#if CONFIG_SOC_SERIES_NRF54HX
10+
11+
/*
12+
* The 54HX is not yet supported by an nrfx driver nor the system controller so
13+
* we implement an ISR and concurrent access safe reference counting implementation
14+
* here using the nrfx hal.
15+
*/
16+
17+
#include <hal/nrf_lrcconf.h>
18+
19+
static struct k_spinlock global_constlat_lock;
20+
static uint16_t global_constlat_count;
21+
22+
int nrf_sys_event_request_global_constlat(void)
23+
{
24+
K_SPINLOCK(&global_constlat_lock) {
25+
if (global_constlat_count == 0) {
26+
#if CONFIG_SOC_NRF54H20_CPUAPP
27+
nrf_lrcconf_task_trigger(NRF_LRCCONF010,
28+
NRF_LRCCONF_TASK_CONSTLAT_ENABLE);
29+
#elif CONFIG_SOC_NRF54H20_CPURAD
30+
nrf_lrcconf_task_trigger(NRF_LRCCONF000,
31+
NRF_LRCCONF_TASK_CONSTLAT_ENABLE);
32+
nrf_lrcconf_task_trigger(NRF_LRCCONF020,
33+
NRF_LRCCONF_TASK_CONSTLAT_ENABLE);
34+
#else
35+
#error "unsupported"
36+
#endif
37+
}
38+
39+
global_constlat_count++;
40+
}
41+
42+
return 0;
43+
}
44+
45+
int nrf_sys_event_release_global_constlat(void)
46+
{
47+
K_SPINLOCK(&global_constlat_lock) {
48+
if (global_constlat_count == 1) {
49+
#if CONFIG_SOC_NRF54H20_CPUAPP
50+
nrf_lrcconf_task_trigger(NRF_LRCCONF010,
51+
NRF_LRCCONF_TASK_CONSTLAT_DISABLE);
52+
#elif CONFIG_SOC_NRF54H20_CPURAD
53+
nrf_lrcconf_task_trigger(NRF_LRCCONF000,
54+
NRF_LRCCONF_TASK_CONSTLAT_DISABLE);
55+
nrf_lrcconf_task_trigger(NRF_LRCCONF020,
56+
NRF_LRCCONF_TASK_CONSTLAT_DISABLE);
57+
#else
58+
#error "unsupported"
59+
#endif
60+
}
61+
62+
global_constlat_count--;
63+
}
64+
65+
return 0;
66+
}
67+
68+
#else
69+
70+
/*
71+
* The nrfx power driver already contains an ISR and concurrent access safe reference
72+
* counting API so we just use it directly when available.
73+
*/
74+
75+
#include <nrfx_power.h>
76+
77+
int nrf_sys_event_request_global_constlat(void)
78+
{
79+
nrfx_err_t err;
80+
81+
err = nrfx_power_constlat_mode_request();
82+
83+
return (err == NRFX_SUCCESS || err == NRFX_ERROR_ALREADY) ? 0 : -EAGAIN;
84+
}
85+
86+
int nrf_sys_event_release_global_constlat(void)
87+
{
88+
nrfx_err_t err;
89+
90+
err = nrfx_power_constlat_mode_free();
91+
92+
return (err == NRFX_SUCCESS || err == NRFX_ERROR_BUSY) ? 0 : -EAGAIN;
93+
}
94+
95+
#endif

soc/nordic/common/nrf_sys_event.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/kernel.h>
8+
9+
/**
10+
* @brief Request lowest latency for system events
11+
*
12+
* @details System will be configured for lowest latency after first
13+
* call to nrf_sys_event_request_global_constlat() and will remain
14+
* configured for lowest latency until matching number of calls to
15+
* nrf_sys_event_release_global_constlat() occur.
16+
*
17+
* @retval 0 if successful
18+
* @retval -errno code otherwise
19+
*/
20+
int nrf_sys_event_request_global_constlat(void);
21+
22+
/**
23+
* @brief Release low latency request
24+
*
25+
* @see nrf_sys_event_request_global_constlat()
26+
*
27+
* @retval 0 if successful
28+
* @retval -errno code otherwise
29+
*/
30+
int nrf_sys_event_release_global_constlat(void);

0 commit comments

Comments
 (0)