Skip to content
This repository was archived by the owner on Oct 23, 2025. It is now read-only.

Commit 451f765

Browse files
auroraslbwopu-ot
authored andcommitted
Add some more nrfx clock apis
Signed-off-by: Aurora Sletnes Bjørlo <[email protected]>
1 parent c25df98 commit 451f765

File tree

4 files changed

+98
-1
lines changed

4 files changed

+98
-1
lines changed

src/HW_models/NRF_CLOCK.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ void nrf_clock_reqw_sideeffects_TASKS_LFCLKSTART(){
9999
}
100100
}
101101

102+
void nrf_clock_reqw_sideeffects_TASKS_LFCLKSTOP() {
103+
// There is no effect of turning the clock off that is actually modeled
104+
if ( NRF_CLOCK_regs.TASKS_LFCLKSTOP ){
105+
NRF_CLOCK_regs.LFCLKRUN = 0;
106+
}
107+
}
108+
102109
void nrf_clock_reqw_sideeffects_TASKS_HFCLKSTART(){
103110
if ( NRF_CLOCK_regs.TASKS_HFCLKSTART ){
104111
NRF_CLOCK_regs.TASKS_HFCLKSTART = 0;

src/HW_models/NRF_CLOCK.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ void nrf_clock_TASKS_HFCLKSTART();
2222
void nrf_clock_reqw_sideeffects_INTENSET();
2323
void nrf_clock_reqw_sideeffects_INTENCLR();
2424
void nrf_clock_reqw_sideeffects_TASKS_LFCLKSTART();
25+
void nrf_clock_reqw_sideeffects_TASKS_LFCLKSTOP();
2526
void nrf_clock_reqw_sideeffects_TASKS_HFCLKSTART();
2627
void nrf_clock_reqw_sideeffects_TASKS_HFCLKSTOP();
2728

src/nrfx/hal/nrf_clock.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,15 @@ void nrf_clock_task_trigger(NRF_CLOCK_Type * p_reg, nrf_clock_task_t task)
3939
} else if (task == NRF_CLOCK_TASK_LFCLKSTART) {
4040
NRF_CLOCK_regs.TASKS_LFCLKSTART = 1;
4141
nrf_clock_reqw_sideeffects_TASKS_LFCLKSTART();
42+
} else if (task == NRF_CLOCK_TASK_LFCLKSTOP) {
43+
NRF_CLOCK_regs.TASKS_LFCLKSTOP = 1;
44+
nrf_clock_reqw_sideeffects_TASKS_LFCLKSTOP();
4245
} else {
43-
bs_trace_error_line_time("Not supported task started in nrf_clock\n");
46+
bs_trace_warning_line_time("Not supported task started in nrf_clock, %d\n", task);
4447
}
4548
}
49+
50+
void nrf_clock_cal_timer_timeout_set(NRF_CLOCK_Type * p_reg, uint32_t interval)
51+
{
52+
/*We don't want to model clock calibration as per now*/
53+
}

src/nrfx/hal/nrf_clock.h

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,18 @@ NRF_STATIC_INLINE void nrf_clock_event_clear(NRF_CLOCK_Type * p_reg, nrf_clock_e
264264
*/
265265
NRF_STATIC_INLINE bool nrf_clock_event_check(NRF_CLOCK_Type const * p_reg, nrf_clock_event_t event);
266266

267+
/**
268+
* @brief Function for retrieving the trigger status of the task START for given domain.
269+
*
270+
* @param[in] p_reg Pointer to the structure of registers of the peripheral.
271+
* @param[in] domain Clock domain.
272+
*
273+
* @retval false The task START for the given domain has not been triggered.
274+
* @retval true The task START for the given domain has been triggered.
275+
*/
276+
NRF_STATIC_INLINE bool nrf_clock_start_task_check(NRF_CLOCK_Type const * p_reg,
277+
nrf_clock_domain_t domain);
278+
267279
/**
268280
* @brief Function for changing the low-frequency clock source.
269281
* @details This function cannot be called when the low-frequency clock is running.
@@ -287,6 +299,45 @@ NRF_STATIC_INLINE void nrf_clock_lf_src_set(NRF_CLOCK_Type * p_reg, nrf_clock_lf
287299
*/
288300
NRF_STATIC_INLINE nrf_clock_lfclk_t nrf_clock_lf_src_get(NRF_CLOCK_Type const * p_reg);
289301

302+
/**
303+
* @brief Function for retrieving the clock source for the LFCLK clock when
304+
* the task LKCLKSTART is triggered.
305+
*
306+
* @param[in] p_reg Pointer to the structure of registers of the peripheral.
307+
*
308+
* @retval NRF_CLOCK_LFCLK_RC The internal 32 kHz RC oscillator
309+
* is running and generating the LFCLK clock.
310+
* @retval NRF_CLOCK_LFCLK_Xtal An external 32 kHz crystal oscillator
311+
* is running and generating the LFCLK clock.
312+
* @retval NRF_CLOCK_LFCLK_Synth The internal 32 kHz synthesized from
313+
* the HFCLK is running and generating the LFCLK clock.
314+
*/
315+
NRF_STATIC_INLINE nrf_clock_lfclk_t nrf_clock_lf_srccopy_get(NRF_CLOCK_Type const * p_reg);
316+
317+
/**
318+
* @brief Function for retrieving the selected source of the high-frequency clock.
319+
*
320+
* For SoCs not featuring the HFCLKSRC register, this is always also the active source
321+
* of the high-frequency clock.
322+
*
323+
* @param[in] p_reg Pointer to the structure of registers of the peripheral.
324+
*
325+
* @retval NRF_CLOCK_HFCLK_LOW_ACCURACY The internal RC oscillator is the selected
326+
* source of the high-frequency clock.
327+
* @retval NRF_CLOCK_HFCLK_HIGH_ACCURACY An external crystal oscillator is the selected
328+
* source of the high-frequency clock.
329+
*/
330+
NRF_STATIC_INLINE nrf_clock_hfclk_t nrf_clock_hf_src_get(NRF_CLOCK_Type const * p_reg);
331+
332+
/**
333+
* @brief Function for changing the calibration timer interval.
334+
*
335+
* @param[in] p_reg Pointer to the structure of registers of the peripheral.
336+
* @param[in] interval New calibration timer interval in 0.25 s resolution
337+
* (range: 0.25 seconds to 31.75 seconds).
338+
*/
339+
void nrf_clock_cal_timer_timeout_set(NRF_CLOCK_Type * p_reg, uint32_t interval);
340+
290341

291342
/* Bodies for inlined functions */
292343

@@ -300,6 +351,23 @@ NRF_STATIC_INLINE bool nrf_clock_event_check(NRF_CLOCK_Type const * p_reg, nrf_c
300351
return (bool)*((volatile uint32_t *)((uint8_t *)p_reg + event));
301352
}
302353

354+
NRF_STATIC_INLINE bool nrf_clock_start_task_check(NRF_CLOCK_Type const * p_reg,
355+
nrf_clock_domain_t domain)
356+
{
357+
switch (domain)
358+
{
359+
case NRF_CLOCK_DOMAIN_LFCLK:
360+
return ((p_reg->LFCLKRUN & CLOCK_LFCLKRUN_STATUS_Msk)
361+
>> CLOCK_LFCLKRUN_STATUS_Pos);
362+
case NRF_CLOCK_DOMAIN_HFCLK:
363+
return ((p_reg->HFCLKRUN & CLOCK_HFCLKRUN_STATUS_Msk)
364+
>> CLOCK_HFCLKRUN_STATUS_Pos);
365+
default:
366+
NRFX_ASSERT(0);
367+
return false;
368+
}
369+
}
370+
303371
NRF_STATIC_INLINE void nrf_clock_lf_src_set(NRF_CLOCK_Type * p_reg, nrf_clock_lfclk_t source)
304372
{
305373
p_reg->LFCLKSRC = (uint32_t)(source);
@@ -369,6 +437,19 @@ NRF_STATIC_INLINE bool nrf_clock_is_running(NRF_CLOCK_Type const * p_reg,
369437
return false;
370438
}
371439

440+
NRF_STATIC_INLINE nrf_clock_lfclk_t nrf_clock_lf_srccopy_get(NRF_CLOCK_Type const * p_reg)
441+
{
442+
/*simple approximation LFCLKSRC = LFCLKSRCCOPY*/
443+
return (nrf_clock_lfclk_t)((p_reg->LFCLKSRC & CLOCK_LFCLKSRC_SRC_Msk)
444+
>> CLOCK_LFCLKSRC_SRC_Pos);
445+
}
446+
447+
NRF_STATIC_INLINE nrf_clock_hfclk_t nrf_clock_hf_src_get(NRF_CLOCK_Type const * p_reg)
448+
{
449+
return (nrf_clock_hfclk_t)((p_reg->HFCLKSTAT & CLOCK_HFCLKSTAT_SRC_Msk)
450+
>> CLOCK_HFCLKSTAT_SRC_Pos);
451+
}
452+
372453
#ifdef __cplusplus
373454
}
374455
#endif

0 commit comments

Comments
 (0)