@@ -397,10 +397,11 @@ NHW_CLOCK_SIDEEFFECTS_SUBSCRIBE(XOTUNEABORT)
397397
398398static void nhw_CLOCK_XOTUNEtimer_triggered (void );
399399
400- static void nhw_CLOCK_request_HFXO (void ) {
401- nhw_clkpwr_st .HFXO_users += 1 ;
400+ static void nhw_CLOCK_request_HFXO (uint32_t mask /* bit mask, with one bit for each user */ ) {
401+ bool start = ( nhw_clkpwr_st .HFXO_users == 0 ) ;
402402
403- if (nhw_clkpwr_st .HFXO_users == 1 ) {
403+ nhw_clkpwr_st .HFXO_users |= mask ;
404+ if (start ) {
404405 nhw_CLOCK_TASK_XOTUNE (0 );
405406 if ((nhw_clkpwr_st .XOtuning_durations [0 ] == 0 ) && (nhw_clkpwr_st .HFXOTUNE_state == Tuning_ok )) {
406407 //Let's raise the event in this same delta cycle in this particular case
@@ -411,8 +412,8 @@ static void nhw_CLOCK_request_HFXO(void) {
411412 }
412413}
413414
414- static void nhw_CLOCK_release_HFXO (void ) {
415- nhw_clkpwr_st .HFXO_users -= 1 ;
415+ static void nhw_CLOCK_release_HFXO (uint32_t mask /* bit mask, with one bit for each user */ ) {
416+ nhw_clkpwr_st .HFXO_users &= ~ mask ;
416417}
417418
418419static void nhw_CLOCK_PLL_128MXO_Timer_triggered (void ) {
@@ -424,10 +425,10 @@ static void nhw_CLOCK_PLL_128MXO_Timer_triggered(void) {
424425
425426 NRF_CLOCK_regs [0 ]-> XO .STAT = CLOCK_XO_STAT_STATE_Msk ;
426427
427- nhw_CLOCK_request_HFXO ();
428+ nhw_CLOCK_request_HFXO (1 /*128M PLL*/ );
428429 nhw_CLOCK_signal_EVENTS_XOSTARTED (0 );
429430 } else if ( nhw_clkpwr_st .PLL_128MXO_state == Stopping ){
430- nhw_CLOCK_release_HFXO ();
431+ nhw_CLOCK_release_HFXO (1 /*128M PLL*/ );
431432 nhw_clkpwr_st .PLL_128MXO_state = Stopped ;
432433 NRF_CLOCK_regs [0 ]-> XO .STAT = 0 ;
433434 }
@@ -480,10 +481,10 @@ static void nhw_CLOCK_PLL_24MXO_Timer_triggered(void) {
480481
481482 NRF_CLOCK_regs [0 ]-> PLL24M .STAT = CLOCK_PLL24M_STAT_STATE_Msk ;
482483
483- nhw_CLOCK_request_HFXO ();
484+ nhw_CLOCK_request_HFXO (2 /*24M PLL*/ );
484485 nhw_CLOCK_signal_EVENTS_XO24MSTARTED (0 );
485486 } else if (nhw_clkpwr_st .PLL_24M_state == Stopping ) {
486- nhw_CLOCK_release_HFXO ();
487+ nhw_CLOCK_release_HFXO (2 /*24M PLL*/ );
487488 nhw_clkpwr_st .PLL_24M_state = Stopped ;
488489 NRF_CLOCK_regs [0 ]-> PLL24M .STAT = 0 ;
489490 }
0 commit comments