Skip to content

Commit 26ed181

Browse files
committed
54L CLOCK: Fix: Handle clock being stopped before it is fully started
There was a race in the clock that would cause the XOTUNE logic to fail. Fix it. Signed-off-by: Alberto Escolar Piedras <[email protected]>
1 parent b643b28 commit 26ed181

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/HW_models/NHW_54L_CLOCK.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -397,10 +397,11 @@ NHW_CLOCK_SIDEEFFECTS_SUBSCRIBE(XOTUNEABORT)
397397

398398
static 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

418419
static 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

Comments
 (0)