Skip to content

Commit 24c70ed

Browse files
ppryga-nordicrlubos
authored andcommitted
mpsl: Use nrf2 cloc ctrl resolve API to get LFCLK accuracy
When MPSL uses nrf2 clock control e.g. on nRF54h20, is should call nrf_clock_control_resolve to get information about the LFCLK source accuracy. The LFCLK souce is unknown to the MPSL so it asks for the worst alowed LFCLK accuracy, which is 500PPM. The API should provide the most accurate and the most power efficient clock source. Signed-off-by: Piotr Pryga <[email protected]>
1 parent cc126a7 commit 24c70ed

File tree

1 file changed

+38
-12
lines changed

1 file changed

+38
-12
lines changed

subsys/mpsl/clock_ctrl/mpsl_clock_ctrl.c

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -293,20 +293,15 @@ static int32_t m_lfclk_release(void)
293293

294294
#elif defined(CONFIG_CLOCK_CONTROL_NRF2)
295295

296-
/* Temporary macro because there is no system level configuration of LFCLK source and its accuracy
297-
* for nRF54H SoC series. What more, there is no API to retrieve the information about accuracy of
298-
* available LFCLK.
296+
/* Minimum accuracy of LFCLK that is required by Bluetooth Core Specification Version 6.1, Vol 6,
297+
* Part B, Section 4.2.2.
299298
*/
300299
#define MPSL_LFCLK_ACCURACY_PPM 500
301-
302-
static const struct nrf_clock_spec m_lfclk_specs = {
303-
.frequency = 32768,
304-
.accuracy = MPSL_LFCLK_ACCURACY_PPM,
305-
/* This affects selected LFCLK source. It doesn't switch to higher accuracy but selects more
306-
* precise but current hungry lfclk source.
307-
*/
308-
.precision = NRF_CLOCK_CONTROL_PRECISION_DEFAULT,
309-
};
300+
/* The variable holds actual LFCLK specification that is use in the system.
301+
* Enabled LFCLK at least matches the minimum Bluetooth sleep clock accuracy,
302+
* but it might be better.
303+
*/
304+
static struct nrf_clock_spec m_lfclk_specs;
310305

311306
#define HFCLK_LABEL DT_NODELABEL(hfxo)
312307

@@ -515,6 +510,33 @@ static mpsl_clock_hfclk_ctrl_source_t m_nrf_hfclk_ctrl_data = {
515510
.hfclk_is_running = m_hfclk_is_running,
516511
};
517512

513+
#if defined(CONFIG_CLOCK_CONTROL_NRF2)
514+
static int m_lfclk_accuracy_get(void)
515+
{
516+
int err;
517+
static const struct nrf_clock_spec lfclk_specs_req = {
518+
/* LFCLK frequency [Hz] */
519+
.frequency = 32768,
520+
.accuracy = MPSL_LFCLK_ACCURACY_PPM,
521+
/* This affects selected LFCLK source. It doesn't switch to higher accuracy
522+
* but selects more precise but current hungry lfclk source.
523+
*/
524+
.precision = NRF_CLOCK_CONTROL_PRECISION_DEFAULT,
525+
};
526+
527+
err = nrf_clock_control_resolve(DEVICE_DT_GET(DT_NODELABEL(lfclk)), &lfclk_specs_req,
528+
&m_lfclk_specs);
529+
if (err < 0) {
530+
LOG_ERR("Failed to resolve LFCLK spec: %d", err);
531+
return err;
532+
}
533+
534+
LOG_DBG("LF Clock accuracy: %d", m_lfclk_specs.accuracy);
535+
536+
return m_lfclk_specs.accuracy;
537+
}
538+
#endif /* CONFIG_CLOCK_CONTROL_NRF2 */
539+
518540
int32_t mpsl_clock_ctrl_init(void)
519541
{
520542
#if defined(CONFIG_MPSL_EXT_CLK_CTRL_NVM_CLOCK_REQUEST)
@@ -558,6 +580,10 @@ int32_t mpsl_clock_ctrl_init(void)
558580
#error "Unsupported HFCLK statup time get operation"
559581
#endif /* CONFIG_CLOCK_CONTROL_NRF */
560582

583+
#if defined(CONFIG_CLOCK_CONTROL_NRF2)
584+
m_nrf_lfclk_ctrl_data.accuracy_ppm = m_lfclk_accuracy_get();
585+
#endif /* CONFIG_CLOCK_CONTROL_NRF2 */
586+
561587
return mpsl_clock_ctrl_source_register(&m_nrf_lfclk_ctrl_data, &m_nrf_hfclk_ctrl_data);
562588
}
563589

0 commit comments

Comments
 (0)