2222#include "tfm_platform_api.h"
2323#include "tfm_ioctl_core_api.h"
2424#endif
25- #if IS_ENABLED (CONFIG_SOC_COMPATIBLE_NRF54LX )
25+
26+ #if IS_ENABLED (CONFIG_MPSL_LOW_LATENCY_CALLBACKS )
27+ #if IS_ENABLED (CONFIG_NRFX_POWER )
2628#include <nrfx_power.h>
27- #endif
28- #if IS_ENABLED (CONFIG_SOC_SERIES_NRF54L )
29+ #else
30+ #include <hal/nrf_power.h>
31+ #endif /* CONFIG_NRFX_POWER */
32+
33+ #if IS_ENABLED (CONFIG_NRF_SYS_EVENT )
2934#include <nrf_sys_event.h>
30- #endif
35+ #endif /* CONFIG_NRF_SYS_EVENT */
36+ #endif /* IS_ENABLED(CONFIG_MPSL_LOW_LATENCY_CALLBACKS) */
37+
38+ /* Include SoC-specific parameters for MPSL init.
39+ * Keep this include as is to do not break the overload functionality.
40+ */
41+ #include <mpsl_init_soc.h>
3142
3243#if defined(CONFIG_SOC_SERIES_NRF54H )
3344#include <hal/nrf_dppi.h>
@@ -61,47 +72,20 @@ extern void rtc_pretick_rtc0_isr_hook(void);
6172#endif
6273
6374#if IS_ENABLED (CONFIG_COUNTER )
64- #if IS_ENABLED (CONFIG_SOC_COMPATIBLE_NRF52X ) || IS_ENABLED (CONFIG_SOC_NRF5340_CPUNET )
65- BUILD_ASSERT (!DT_NODE_HAS_STATUS_OKAY (DT_NODELABEL (rtc0 )),
66- "MPSL reserves RTC0 on this SoC." );
67- BUILD_ASSERT (!DT_NODE_HAS_STATUS_OKAY (DT_NODELABEL (timer0 )),
68- "MPSL reserves TIMER0 on this SoC." );
69- #elif IS_ENABLED (CONFIG_SOC_COMPATIBLE_NRF54LX ) || IS_ENABLED (CONFIG_SOC_SERIES_NRF71 )
70- BUILD_ASSERT (!DT_NODE_HAS_STATUS_OKAY (DT_NODELABEL (timer10 )),
71- "MPSL reserves TIMER10 on this SoC." );
72- #elif IS_ENABLED (CONFIG_SOC_SERIES_NRF54H )
73- BUILD_ASSERT (!DT_NODE_HAS_STATUS_OKAY (DT_NODELABEL (timer020 )),
74- "MPSL reserves TIMER020 on this SoC." );
75+ /* Macros used below are declared in mpsl_init_soc.h */
76+ #if defined(MPSL_INIT_SOC_COUNTER_RESERVED_NODES )
77+ #define MPSL_BUILD_ASSERT_COUNTER_NODE_NOT_OKAY (node ) \
78+ BUILD_ASSERT(!DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(node)), \
79+ "MPSL reserves " #node " on this SoC. Please disable this node in device tree")
80+ FOR_EACH (MPSL_BUILD_ASSERT_COUNTER_NODE_NOT_OKAY , (;),
81+ MPSL_INIT_SOC_COUNTER_RESERVED_NODES )
82+ #undef MPSL_BUILD_ASSERT_COUNTER_NODE_NOT_OKAY
7583#else
76- #error
84+ #error "Counter DTS nodes reserved for MPSL are missing"
7785#endif
7886#endif /* IS_ENABLED(CONFIG_COUNTER) */
7987
80- #if defined(CONFIG_SOC_COMPATIBLE_NRF52X ) || defined(CONFIG_SOC_COMPATIBLE_NRF53X )
81- #define MPSL_TIMER_IRQn TIMER0_IRQn
82- #define MPSL_RTC_IRQn RTC0_IRQn
83- #define MPSL_RADIO_IRQn RADIO_IRQn
84- #elif defined(CONFIG_SOC_COMPATIBLE_NRF54LX ) || defined(CONFIG_SOC_SERIES_NRF71 )
85- #define MPSL_TIMER_IRQn TIMER10_IRQn
86- #define MPSL_RTC_IRQn GRTC_3_IRQn
87- #define MPSL_RADIO_IRQn RADIO_0_IRQn
88- #elif defined(CONFIG_SOC_SERIES_NRF54H )
89- #define MPSL_TIMER_IRQn TIMER020_IRQn
90- #define MPSL_RTC_IRQn GRTC_2_IRQn
91- #define MPSL_RADIO_IRQn RADIO_0_IRQn
92- #endif
93-
94- #if defined(CONFIG_SOC_SERIES_NRF54H )
95- /* Basic build time sanity checking */
96- #define MPSL_RESERVED_GRTC_CHANNELS ((1U << 8) | (1U << 9) | (1U << 10) | (1U << 11) | (1U << 12))
97- #elif defined(CONFIG_SOC_COMPATIBLE_NRF54LX ) || defined(CONFIG_SOC_SERIES_NRF71 )
98- #define MPSL_RESERVED_GRTC_CHANNELS ((1U << 7) | (1U << 8) | (1U << 9) | (1U << 10) | (1U << 11))
99- #endif
100-
101- #if defined(CONFIG_SOC_SERIES_NRF54H ) || \
102- defined(CONFIG_SOC_COMPATIBLE_NRF54LX ) || \
103- defined(CONFIG_SOC_SERIES_NRF71 )
104-
88+ #if IS_ENABLED (CONFIG_NRFX_GRTC )
10589BUILD_ASSERT (MPSL_RTC_IRQn != DT_IRQN (DT_NODELABEL (grtc )), "MPSL requires a dedicated GRTC IRQ" );
10690
10791#define CHECK_IRQ (val , _ ) (DT_IRQ_BY_IDX(DT_NODELABEL(grtc), val, irq) == MPSL_RTC_IRQn)
@@ -116,12 +100,9 @@ BUILD_ASSERT(MPSL_IRQ_IN_DT, "The MPSL GRTC IRQ is not in the device tree");
116100BUILD_ASSERT ((NRFX_CONFIG_MASK_DT (DT_NODELABEL (grtc ), child_owned_channels ) &
117101 MPSL_RESERVED_GRTC_CHANNELS ) == MPSL_RESERVED_GRTC_CHANNELS ,
118102 "The GRTC channels used by MPSL must not be used by zephyr" );
119- #endif
103+ #endif /* IS_ENABLED(CONFIG_NRFX_GRTC) */
120104
121- #if defined(CONFIG_SOC_SERIES_NRF54H )
122- #define MPSL_RESERVED_IPCT_SOURCE_CHANNELS (1U << 0)
123- #define MPSL_RESERVED_DPPI_SOURCE_CHANNELS (1U << 0)
124- #define MPSL_RESERVED_DPPI_SINK_CHANNELS (1U << 0)
105+ #if IS_ENABLED (CONFIG_SOC_SERIES_NRF54H ) /* IPCT is relevant for nRF54H only */
125106/* check the GRTC source channels.
126107 * i.e. ensure something similar to this is present in the DT
127108 * &dppic132 {
@@ -173,11 +154,11 @@ BUILD_ASSERT((IPCT_SOURCE_CHANNELS & MPSL_RESERVED_IPCT_SOURCE_CHANNELS) ==
173154 MPSL_RESERVED_IPCT_SOURCE_CHANNELS ,
174155 "The required IPCT source channels are not reserved" );
175156
176- #endif
157+ #endif /* CONFIG_SOC_SERIES_NRF54H */
177158
178- #if defined( CONFIG_SOC_SERIES_NRF54L )
179- BUILD_ASSERT (NRF_CONFIG_CPU_FREQ_MHZ == 128 , "Currently mpsl only works when frequency is 128MHz " );
180- #endif
159+ #ifdef MPSL_INIT_SOC_CPU_FREQ_MHZ
160+ BUILD_ASSERT (NRF_CONFIG_CPU_FREQ_MHZ == MPSL_INIT_SOC_CPU_FREQ_MHZ , "Unsupported CPU frequency" );
161+ #endif /* MPSL_INIT_SOC_CPU_FREQ_MHZ */
181162
182163#if IS_ENABLED (CONFIG_NRF_GRTC_TIMER ) && !defined(CONFIG_SOC_SERIES_NRF54H )
183164BUILD_ASSERT (IS_ENABLED (CONFIG_NRF_GRTC_TIMER_AUTO_KEEP_ALIVE ),
@@ -196,13 +177,26 @@ static struct k_work mpsl_low_prio_work;
196177struct k_work_q mpsl_work_q ;
197178static K_THREAD_STACK_DEFINE (mpsl_work_stack , CONFIG_MPSL_WORK_STACK_SIZE ) ;
198179
199- #if IS_ENABLED (CONFIG_SOC_SERIES_NRF54L ) && !IS_ENABLED (CONFIG_TRUSTED_EXECUTION_NONSECURE )
180+ #if IS_ENABLED (CONFIG_MPSL_LOW_LATENCY_CALLBACKS ) && !IS_ENABLED (CONFIG_TRUSTED_EXECUTION_NONSECURE )
181+ /* Check existence of rram_controller node in the device tree to figure out whether RRAMC is
182+ * supported.
183+ *
184+ * Note: The standard CONFIG_HAS_HW_NRF_RRAMC expects the DTS node to be set (okay).
185+ * The CONFIG_NRFX_RRAMC informs if the node is in DTS but it is not selected by default
186+ * so it is not defined for preprocessor.
187+ */
188+ #if DT_NODE_EXISTS (DT_NODELABEL (rram_controller ))
189+ #define MPSL_HW_HAS_RRAMC 1
190+ #endif /* DT_NODE_EXISTS(DT_NODELABEL(rram_controller)) */
191+
200192#if IS_ENABLED (CONFIG_NRF_SYS_EVENT_IRQ_LATENCY )
201193static int m_nvm_low_latency_event_handle = -1 ;
202194#else
203195static uint32_t m_rram_lowpower_config ;
204196#endif /* IS_ENABLED(CONFIG_NRF_SYS_EVENT_IRQ_LATENCY) */
205- #endif /* IS_ENABLED(CONFIG_SOC_SERIES_NRF54L) && !IS_ENABLED(CONFIG_TRUSTED_EXECUTION_NONSECURE) */
197+ #endif /* IS_ENABLED(CONFIG_MPSL_LOW_LATENCY_CALLBACKS) &&
198+ * !IS_ENABLED(CONFIG_TRUSTED_EXECUTION_NONSECURE)
199+ */
206200
207201#define MPSL_TIMESLOT_SESSION_COUNT (\
208202 CONFIG_MPSL_TIMESLOT_SESSION_COUNT + \
@@ -621,10 +615,13 @@ int32_t mpsl_lib_uninit(void)
621615#endif /* IS_ENABLED(CONFIG_MPSL_DYNAMIC_INTERRUPTS) */
622616}
623617
624- #if defined(CONFIG_SOC_COMPATIBLE_NRF54LX )
618+ #if defined(CONFIG_MPSL_LOW_LATENCY_CALLBACKS )
625619void mpsl_low_latency_acquire_callback (void )
626620{
627- #if IS_ENABLED (CONFIG_SOC_SERIES_NRF54L )
621+ /* We need to know whether RRAMC is supported on the platform. The IS_ENABLED() returns true if the
622+ * KConfig is set. In this case it is enough to check whether there is
623+ */
624+ #if defined(MPSL_HW_HAS_RRAMC )
628625#if IS_ENABLED (CONFIG_NRF_SYS_EVENT )
629626 int err ;
630627
@@ -633,10 +630,10 @@ void mpsl_low_latency_acquire_callback(void)
633630 LOG_ERR ("NVM low latency request has failed (%d)" , err );
634631 }
635632#elif IS_ENABLED (CONFIG_NRFX_POWER )
636- nrfx_power_constlat_mode_request ();
633+ ( void ) nrfx_power_constlat_mode_request ();
637634#else
638635 nrf_power_task_trigger (NRF_POWER , NRF_POWER_TASK_CONSTLAT );
639- #endif /* IS_ENABLED(CONFIG_NRF_SYS_EVENT) */
636+ #endif /* NRF_POWER_HAS_CONST_LATENCY && NRF_POWER_HAS_LOW_POWER */
640637
641638#if !IS_ENABLED (CONFIG_TRUSTED_EXECUTION_NONSECURE )
642639#if IS_ENABLED (CONFIG_NRF_SYS_EVENT_IRQ_LATENCY )
@@ -654,12 +651,12 @@ void mpsl_low_latency_acquire_callback(void)
654651 << RRAMC_POWER_LOWPOWERCONFIG_MODE_Pos ;
655652#endif /* IS_ENABLED(CONFIG_NRF_SYS_EVENT_IRQ_LATENCY) */
656653#endif /* !IS_ENABLED(CONFIG_TRUSTED_EXECUTION_NONSECURE) */
657- #endif /* IS_ENABLED(CONFIG_SOC_SERIES_NRF54L ) */
654+ #endif /* defined(MPSL_HW_HAS_RRAMC ) */
658655}
659656
660657void mpsl_low_latency_release_callback (void )
661658{
662- #if IS_ENABLED ( CONFIG_SOC_SERIES_NRF54L )
659+ #if defined( MPSL_HW_HAS_RRAMC )
663660#if IS_ENABLED (CONFIG_NRF_SYS_EVENT )
664661 int ret ;
665662
@@ -668,7 +665,7 @@ void mpsl_low_latency_release_callback(void)
668665 LOG_ERR ("NVM low latency release has failed (%d)" , ret );
669666 }
670667#elif IS_ENABLED (CONFIG_NRFX_POWER )
671- nrfx_power_constlat_mode_free ();
668+ ( void ) nrfx_power_constlat_mode_free ();
672669#else
673670 nrf_power_task_trigger (NRF_POWER , NRF_POWER_TASK_LOWPWR );
674671#endif /* IS_ENABLED(CONFIG_NRF_SYS_EVENT) */
@@ -685,9 +682,9 @@ void mpsl_low_latency_release_callback(void)
685682 NRF_RRAMC -> POWER .LOWPOWERCONFIG = m_rram_lowpower_config ;
686683#endif /* IS_ENABLED(CONFIG_NRF_SYS_EVENT_IRQ_LATENCY) */
687684#endif /* !IS_ENABLED(CONFIG_TRUSTED_EXECUTION_NONSECURE) */
688- #endif /* IS_ENABLED(CONFIG_SOC_SERIES_NRF54L ) */
685+ #endif /* defined(MPSL_HW_HAS_RRAMC ) */
689686}
690- #endif /* defined(CONFIG_SOC_COMPATIBLE_NRF54LX ) */
687+ #endif /* defined(CONFIG_MPSL_LOW_LATENCY_CALLBACKS ) */
691688
692689#if defined(CONFIG_MPSL_USE_EXTERNAL_CLOCK_CONTROL )
693690#define MPSL_INIT_LEVEL POST_KERNEL
0 commit comments