CLOCK HAL
- group nrf_clock_hal
Hardware access layer for managing the CLOCK peripheral.
This code can be used to manage low-frequency clock (LFCLK), high-frequency clock (HFCLK), high-frequency 192 MHz clock (HFCLK192M) and high-frequency audio clock (HFCLKAUDIO) settings.
Defines
-
NRF_CLOCK_HAS_CALIBRATION
Presence of the Low Frequency Clock calibration.
-
NRF_CLOCK_HAS_CALIBRATION_TIMER
Presence of the Low Frequency Clock calibration timer.
-
NRF_CLOCK_HAS_HFCLK192M
Presence of the 192 MHz clock.
-
NRF_CLOCK_HAS_HFCLKAUDIO
Presence of the Audio clock.
-
NRF_CLOCK_HAS_ALWAYSRUN
Presence of ALWAYSRUN registers.
-
NRF_CLOCK_HAS_HFCLKSRC
Presence of HFCLKSRC register.
Enums
-
enum nrf_clock_lfclk_t
Low-frequency clock sources.
Used by LFCLKSRC, LFCLKSTAT, and LFCLKSRCCOPY registers.
Values:
-
enumerator NRF_CLOCK_LFCLK_LFULP
Internal 32 kHz Ultra-low power oscillator.
-
enumerator NRF_CLOCK_LFCLK_RC
Internal 32 kHz RC oscillator.
-
enumerator NRF_CLOCK_LFCLK_Xtal
External 32 kHz crystal.
-
enumerator NRF_CLOCK_LFCLK_Synth
Internal 32 kHz synthesized from HFCLK system clock.
-
enumerator NRF_CLOCK_LFCLK_Xtal_Low_Swing
External 32 kHz low swing signal. Used only with the LFCLKSRC register. For the others NRF_CLOCK_LFCLK_Xtal is returned for this setting.
-
enumerator NRF_CLOCK_LFCLK_Xtal_Full_Swing
External 32 kHz full swing signal. Used only with the LFCLKSRC register. For the others NRF_CLOCK_LFCLK_Xtal is returned for this setting.
-
enumerator NRF_CLOCK_LFCLK_LFULP
-
enum nrf_clock_hfclk_t
High-frequency clock sources.
Used by HFCLKSTAT and HFCLK192MSTAT registers.
Values:
-
enumerator NRF_CLOCK_HFCLK_LOW_ACCURACY
Internal 16 MHz RC oscillator.
-
enumerator NRF_CLOCK_HFCLK_HIGH_ACCURACY
External 16 MHz/32 MHz crystal oscillator.
-
enumerator NRF_CLOCK_HFCLK_LOW_ACCURACY
-
enum nrf_clock_domain_t
Clock domains.
Values:
-
enumerator NRF_CLOCK_DOMAIN_LFCLK
-
enumerator NRF_CLOCK_DOMAIN_HFCLK
-
enumerator NRF_CLOCK_DOMAIN_HFCLK192M
-
enumerator NRF_CLOCK_DOMAIN_HFCLKAUDIO
-
enumerator NRF_CLOCK_DOMAIN_LFCLK
-
enum nrf_clock_hfclk_div_t
High-frequency clock frequency configuration.
Used by HFCLKCTRL and HFCLK192MCTRL registers.
Values:
-
enumerator NRF_CLOCK_HFCLK_DIV_1
Divide HFCLK/HFCLK192M by 1
-
enumerator NRF_CLOCK_HFCLK_DIV_2
Divide HFCLK/HFCLK192M by 2
-
enumerator NRF_CLOCK_HFCLK_DIV_4
Divide HFCLK192M by 4
-
enumerator NRF_CLOCK_HFCLK_DIV_1
-
enum nrf_clock_start_task_status_t
Trigger status of task LFCLKSTART/HFCLKSTART.
Used by LFCLKRUN and HFCLKRUN registers.
Note
This enum is deprecated.
Values:
-
enumerator NRF_CLOCK_START_TASK_NOT_TRIGGERED
Task LFCLKSTART/HFCLKSTART has not been triggered.
-
enumerator NRF_CLOCK_START_TASK_TRIGGERED
Task LFCLKSTART/HFCLKSTART has been triggered.
-
enumerator NRF_CLOCK_START_TASK_NOT_TRIGGERED
-
enum nrf_clock_int_mask_t
Interrupts.
Values:
-
enumerator NRF_CLOCK_INT_HF_STARTED_MASK
Interrupt on HFCLKSTARTED event.
-
enumerator NRF_CLOCK_INT_LF_STARTED_MASK
Interrupt on LFCLKSTARTED event.
-
enumerator NRF_CLOCK_INT_DONE_MASK
Interrupt on DONE event.
-
enumerator NRF_CLOCK_INT_CTTO_MASK
Interrupt on CTTO event.
-
enumerator NRF_CLOCK_INT_CTSTARTED_MASK
Interrupt on CTSTARTED event.
-
enumerator NRF_CLOCK_INT_CTSTOPPED_MASK
Interrupt on CTSTOPPED event. Interrupt on HFCLKAUDIOSTARTED event.
-
enumerator NRF_CLOCK_INT_HF192M_STARTED_MASK
Interrupt on HFCLK192MSTARTED event.
-
enumerator NRF_CLOCK_INT_HF_STARTED_MASK
-
enum nrf_clock_task_t
Tasks.
The NRF_CLOCK_TASK_LFCLKSTOP task cannot be set when the low-frequency clock is not running. The NRF_CLOCK_TASK_HFCLKSTOP task cannot be set when the high-frequency clock is not running.
Values:
-
enumerator NRF_CLOCK_TASK_HFCLKSTART
Start HFCLK clock source.
-
enumerator NRF_CLOCK_TASK_HFCLKSTOP
Stop HFCLK clock source.
-
enumerator NRF_CLOCK_TASK_LFCLKSTART
Start LFCLK clock source.
-
enumerator NRF_CLOCK_TASK_LFCLKSTOP
Stop LFCLK clock source.
-
enumerator NRF_CLOCK_TASK_CAL
Start calibration of LFCLK RC oscillator.
-
enumerator NRF_CLOCK_TASK_CTSTART
Start calibration timer.
-
enumerator NRF_CLOCK_TASK_CTSTOP
Stop calibration timer. Start HFCLKAUDIO clock source.
-
enumerator NRF_CLOCK_TASK_HFCLKAUDIOSTOP
Stop HFCLKAUDIO clock source.
-
enumerator NRF_CLOCK_TASK_HFCLK192MSTART
Start HFCLK192M clock source.
-
enumerator NRF_CLOCK_TASK_HFCLK192MSTOP
Stop HFCLK192M clock source.
-
enumerator NRF_CLOCK_TASK_HFCLKSTART
-
enum nrf_clock_event_t
Events.
Values:
-
enumerator NRF_CLOCK_EVENT_HFCLKSTARTED
HFCLK oscillator started.
-
enumerator NRF_CLOCK_EVENT_LFCLKSTARTED
LFCLK oscillator started.
-
enumerator NRF_CLOCK_EVENT_DONE
Calibration of LFCLK RC oscillator completed.
-
enumerator NRF_CLOCK_EVENT_CTTO
Calibration timer time-out.
-
enumerator NRF_CLOCK_EVENT_CTSTARTED
Calibration timer started.
-
enumerator NRF_CLOCK_EVENT_CTSTOPPED
Calibration timer stopped. HFCLKAUDIO oscillator started.
-
enumerator NRF_CLOCK_EVENT_HFCLK192MSTARTED
HFCLK192M oscillator started.
-
enumerator NRF_CLOCK_EVENT_HFCLKSTARTED
Functions
-
NRF_STATIC_INLINE void nrf_clock_int_enable(NRF_CLOCK_Type *p_reg, uint32_t mask)
Function for enabling the specified interrupt.
- Parameters
p_reg – [in] Pointer to the structure of registers of the peripheral.
mask – [in] Mask of interrupts to be enabled.
-
NRF_STATIC_INLINE void nrf_clock_int_disable(NRF_CLOCK_Type *p_reg, uint32_t mask)
Function for disabling the specified interrupt.
- Parameters
p_reg – [in] Pointer to the structure of registers of the peripheral.
mask – [in] Mask of interrupts to be disabled.
-
NRF_STATIC_INLINE uint32_t nrf_clock_int_enable_check(NRF_CLOCK_Type const *p_reg, uint32_t mask)
Function for checking if the specified interrupts are enabled.
- Parameters
p_reg – [in] Pointer to the structure of registers of the peripheral.
mask – [in] Mask of interrupts to be checked.
- Returns
Mask of enabled interrupts.
-
NRF_STATIC_INLINE uint32_t nrf_clock_task_address_get(NRF_CLOCK_Type const *p_reg, nrf_clock_task_t task)
Function for retrieving the address of the specified task.
This function can be used by the PPI module.
- Parameters
p_reg – [in] Pointer to the structure of registers of the peripheral.
task – [in] CLOCK Task.
- Returns
Address of the requested task register.
-
NRF_STATIC_INLINE void nrf_clock_task_trigger(NRF_CLOCK_Type *p_reg, nrf_clock_task_t task)
Function for setting the specified task.
- Parameters
p_reg – [in] Pointer to the structure of registers of the peripheral.
task – [in] Task to be activated.
-
NRF_STATIC_INLINE uint32_t nrf_clock_event_address_get(NRF_CLOCK_Type const *p_reg, nrf_clock_event_t event)
Function for retrieving the address of the specified event.
This function can be used by the PPI module.
- Parameters
p_reg – [in] Pointer to the structure of registers of the peripheral.
event – [in] CLOCK Event.
- Returns
Address of the specified event register.
-
NRF_STATIC_INLINE void nrf_clock_event_clear(NRF_CLOCK_Type *p_reg, nrf_clock_event_t event)
Function for clearing the specified event.
- Parameters
p_reg – [in] Pointer to the structure of registers of the peripheral.
event – [in] Event to clear.
-
NRF_STATIC_INLINE bool nrf_clock_event_check(NRF_CLOCK_Type const *p_reg, nrf_clock_event_t event)
Function for retrieving the state of the specified event.
- Parameters
p_reg – [in] Pointer to the structure of registers of the peripheral.
event – [in] Event to be checked.
- Return values
true – The event has been generated.
false – The event has not been generated.
-
NRF_STATIC_INLINE bool nrf_clock_start_task_check(NRF_CLOCK_Type const *p_reg, nrf_clock_domain_t domain)
Function for retrieving the trigger status of the task START for given domain.
- Parameters
p_reg – [in] Pointer to the structure of registers of the peripheral.
domain – [in] Clock domain.
- Return values
false – The task START for the given domain has not been triggered.
true – The task START for the given domain has been triggered.
-
NRF_STATIC_INLINE bool nrf_clock_is_running(NRF_CLOCK_Type const *p_reg, nrf_clock_domain_t domain, void *p_clk_src)
Function for retrieving the state of the clock.
- Parameters
p_reg – [in] Pointer to the structure of registers of the peripheral.
domain – [in] Clock domain.
p_clk_src – [out] Pointer to clock source that is running. Set to NULL if not needed. Ignored for HFCLKAUDIO domain. Variable pointed by
p_clk_src
must be of either nrf_clock_lfclk_t type for LFCLK or nrf_clock_hfclk_t type for HFCLK and HFCLK192M.
- Return values
false – The clock is not running.
true – The clock is running.
-
NRF_STATIC_INLINE void nrf_clock_lf_src_set(NRF_CLOCK_Type *p_reg, nrf_clock_lfclk_t source)
Function for changing the low-frequency clock source.
Check in Product Specification if this function can be called when the low-frequency clock is running.
- Parameters
p_reg – [in] Pointer to the structure of registers of the peripheral.
source – [in] New low-frequency clock source.
-
NRF_STATIC_INLINE nrf_clock_lfclk_t nrf_clock_lf_src_get(NRF_CLOCK_Type const *p_reg)
Function for retrieving the selected source for the low-frequency clock.
- Parameters
p_reg – [in] Pointer to the structure of registers of the peripheral.
- Return values
NRF_CLOCK_LFCLK_RC – The internal 32 kHz RC oscillator is the selected source for the low-frequency clock.
NRF_CLOCK_LFCLK_Xtal – An external 32 kHz crystal oscillator is the selected source for the low-frequency clock.
NRF_CLOCK_LFCLK_Synth – The internal 32 kHz synthesized from the HFCLK is the selected source for the low-frequency clock.
-
NRF_STATIC_INLINE nrf_clock_lfclk_t nrf_clock_lf_actv_src_get(NRF_CLOCK_Type const *p_reg)
Function for retrieving the active source of the low-frequency clock.
Note
This function is deprecated. Use nrf_clock_is_running instead.
- Parameters
p_reg – [in] Pointer to the structure of registers of the peripheral.
- Return values
NRF_CLOCK_LFCLK_RC – The internal 32 kHz RC oscillator is the active source of the low-frequency clock.
NRF_CLOCK_LFCLK_Xtal – An external 32 kHz crystal oscillator is the active source of the low-frequency clock.
NRF_CLOCK_LFCLK_Synth – The internal 32 kHz synthesized from the HFCLK is the active source of the low-frequency clock.
-
NRF_STATIC_INLINE nrf_clock_lfclk_t nrf_clock_lf_srccopy_get(NRF_CLOCK_Type const *p_reg)
Function for retrieving the clock source for the LFCLK clock when the task LKCLKSTART is triggered.
- Parameters
p_reg – [in] Pointer to the structure of registers of the peripheral.
- Return values
NRF_CLOCK_LFCLK_RC – The internal 32 kHz RC oscillator is running and generating the LFCLK clock.
NRF_CLOCK_LFCLK_Xtal – An external 32 kHz crystal oscillator is running and generating the LFCLK clock.
NRF_CLOCK_LFCLK_Synth – The internal 32 kHz synthesized from the HFCLK is running and generating the LFCLK clock.
-
NRF_STATIC_INLINE bool nrf_clock_lf_is_running(NRF_CLOCK_Type const *p_reg)
Function for retrieving the state of the LFCLK clock.
Note
This function is deprecated. Use nrf_clock_is_running instead.
- Parameters
p_reg – [in] Pointer to the structure of registers of the peripheral.
- Return values
false – The LFCLK clock is not running.
true – The LFCLK clock is running.
-
NRF_STATIC_INLINE nrf_clock_start_task_status_t nrf_clock_lf_start_task_status_get(NRF_CLOCK_Type const *p_reg)
Function for retrieving the trigger status of the task LFCLKSTART.
Note
This function is deprecated. Use nrf_clock_start_task_check instead.
- Parameters
p_reg – [in] Pointer to the structure of registers of the peripheral.
- Return values
NRF_CLOCK_START_TASK_NOT_TRIGGERED – The task LFCLKSTART has not been triggered.
NRF_CLOCK_START_TASK_TRIGGERED – The task LFCLKSTART has been triggered.
-
NRF_STATIC_INLINE void nrf_clock_hf_src_set(NRF_CLOCK_Type *p_reg, nrf_clock_hfclk_t source)
Function for changing the high-frequency clock source.
- Parameters
p_reg – [in] Pointer to the structure of registers of the peripheral.
source – [in] New high-frequency clock source.
-
NRF_STATIC_INLINE nrf_clock_hfclk_t nrf_clock_hf_src_get(NRF_CLOCK_Type const *p_reg)
Function for retrieving the selected source of the high-frequency clock.
For SoCs not featuring the HFCLKSRC register, this is always also the active source of the high-frequency clock.
- Parameters
p_reg – [in] Pointer to the structure of registers of the peripheral.
- Return values
NRF_CLOCK_HFCLK_LOW_ACCURACY – The internal RC oscillator is the selected source of the high-frequency clock.
NRF_CLOCK_HFCLK_HIGH_ACCURACY – An external crystal oscillator is the selected source of the high-frequency clock.
-
NRF_STATIC_INLINE bool nrf_clock_hf_is_running(NRF_CLOCK_Type const *p_reg, nrf_clock_hfclk_t clk_src)
Function for retrieving the state of the HFCLK clock.
Note
This function is deprecated. Use nrf_clock_is_running instead.
- Parameters
p_reg – [in] Pointer to the structure of registers of the peripheral.
clk_src – [in] Clock source to be checked.
- Return values
false – The HFCLK clock is not running.
true – The HFCLK clock is running.
-
NRF_STATIC_INLINE nrf_clock_start_task_status_t nrf_clock_hf_start_task_status_get(NRF_CLOCK_Type const *p_reg)
Function for retrieving the trigger status of the task HFCLKSTART.
Note
This function is deprecated. Use nrf_clock_start_task_check instead.
- Parameters
p_reg – [in] Pointer to the structure of registers of the peripheral.
- Return values
NRF_CLOCK_START_TASK_NOT_TRIGGERED – The task HFCLKSTART has not been triggered.
NRF_CLOCK_START_TASK_TRIGGERED – The task HFCLKSTART has been triggered.
-
NRF_STATIC_INLINE void nrf_clock_hfclkaudio_config_set(NRF_CLOCK_Type *p_reg, uint16_t freq_value)
Function for changing the Audio clock FREQ_VALUE.
The frequency of HFCLKAUDIO ranges from 10.666 MHz to 13.333 MHz in 40.7 Hz steps. To calculate
freq_value
corresponding to the chosen frequency, use the following equation: FREQ_VALUE = 2^16 * ((12 * f_out / 32M) - 4)Warning
Chosen frequency must fit in 11.176 MHz - 11.402 MHz or 12.165 MHz - 12.411 MHz frequency bands.
- Parameters
p_reg – [in] Pointer to the structure of registers of the peripheral.
freq_value – [in] New FREQ_VALUE
-
NRF_STATIC_INLINE uint16_t nrf_clock_hfclkaudio_config_get(NRF_CLOCK_Type const *p_reg)
Function for retrieving the Audio clock FREQ_VALUE.
The frequency of HFCLKAUDIO ranges from 10.666 MHz to 13.333 MHz in 40.7 Hz steps. To calculate frequency corresponding to the returned FREQ_VALUE, use the following equation: f_out = 32M * (4 + FREQ_VALUE * 2^(-16))/12
- Parameters
p_reg – [in] Pointer to the structure of registers of the peripheral.
- Returns
FREQ_VALUE of the Audio clock.
-
NRF_STATIC_INLINE void nrf_clock_cal_timer_timeout_set(NRF_CLOCK_Type *p_reg, uint32_t interval)
Function for changing the calibration timer interval.
- Parameters
p_reg – [in] Pointer to the structure of registers of the peripheral.
interval – [in] New calibration timer interval in 0.25 s resolution (range: 0.25 seconds to 31.75 seconds).
-
NRF_STATIC_INLINE void nrf_clock_hfclk192m_div_set(NRF_CLOCK_Type *p_reg, nrf_clock_hfclk_div_t divider)
Function for changing the HFCLK192M frequency divider.
- Parameters
p_reg – [in] Pointer to the structure of registers of the peripheral.
divider – [in] New HFCLK192M divider.
-
NRF_STATIC_INLINE nrf_clock_hfclk_div_t nrf_clock_hfclk192m_div_get(NRF_CLOCK_Type const *p_reg)
Function for retrieving the HFCLK192M frequency divider.
- Parameters
p_reg – [in] Pointer to the structure of registers of the peripheral.
- Returns
HFCLK192M frequency divider.
-
NRF_STATIC_INLINE void nrf_clock_hfclk192m_src_set(NRF_CLOCK_Type *p_reg, nrf_clock_hfclk_t source)
Function for changing the HFCLK192M source.
- Parameters
p_reg – [in] Pointer to the structure of registers of the peripheral.
source – [in] New HFCLK192M source.
-
NRF_STATIC_INLINE nrf_clock_hfclk_t nrf_clock_hfclk192m_src_get(NRF_CLOCK_Type const *p_reg)
Function for retrieving the selected source of the HFCLK192M.
- Parameters
p_reg – [in] Pointer to the structure of registers of the peripheral.
- Return values
NRF_CLOCK_HFCLK_LOW_ACCURACY – The internal RC oscillator is the selected source of the HFCLK192M.
NRF_CLOCK_HFCLK_HIGH_ACCURACY – An external crystal oscillator is the selected source of the HFCLK192M.
-
NRF_STATIC_INLINE void nrf_clock_alwaysrun_set(NRF_CLOCK_Type *p_reg, nrf_clock_domain_t domain, bool alwaysrun)
Function for setting the clock domain to always run.
- Parameters
p_reg – [in] Pointer to the structure of registers of the peripheral.
domain – [in] Clock domain.
alwaysrun – [in] Ensure the clock is always running.
-
NRF_STATIC_INLINE bool nrf_clock_alwaysrun_get(NRF_CLOCK_Type const *p_reg, nrf_clock_domain_t domain)
Function for checking if the clock domain is configured to always run.
- Parameters
p_reg – [in] Pointer to the structure of registers of the peripheral.
domain – [in] Clock domain.
- Return values
true – The clock domain is configured to always run.
false – The clock domain is not configured to always run.
-
NRF_STATIC_INLINE bool nrf_clock_alwaysrun_active_get(NRF_CLOCK_Type const *p_reg, nrf_clock_domain_t domain)
Function for checking if the clock domain always run setting is active.
- Parameters
p_reg – [in] Pointer to the structure of registers of the peripheral.
domain – [in] Clock domain.
- Return values
true – The clock domain always run setting is active.
false – The clock domain always run setting is not active.
-
NRF_STATIC_INLINE void nrf_clock_subscribe_set(NRF_CLOCK_Type *p_reg, nrf_clock_task_t task, uint8_t channel)
Function for setting the subscribe configuration for a given CLOCK task.
- Parameters
p_reg – [in] Pointer to the structure of registers of the peripheral.
task – [in] Task for which to set the configuration.
channel – [in] Channel through which to subscribe events.
-
NRF_STATIC_INLINE void nrf_clock_subscribe_clear(NRF_CLOCK_Type *p_reg, nrf_clock_task_t task)
Function for clearing the subscribe configuration for a given CLOCK task.
- Parameters
p_reg – [in] Pointer to the structure of registers of the peripheral.
task – [in] Task for which to clear the configuration.
-
NRF_STATIC_INLINE void nrf_clock_publish_set(NRF_CLOCK_Type *p_reg, nrf_clock_event_t event, uint8_t channel)
Function for setting the publish configuration for a given CLOCK event.
- Parameters
p_reg – [in] Pointer to the structure of registers of the peripheral.
event – [in] Event for which to set the configuration.
channel – [in] Channel through which to publish the event.
-
NRF_STATIC_INLINE void nrf_clock_publish_clear(NRF_CLOCK_Type *p_reg, nrf_clock_event_t event)
Function for clearing the publish configuration for a given CLOCK event.
- Parameters
p_reg – [in] Pointer to the structure of registers of the peripheral.
event – [in] Event for which to clear the configuration.
-
NRF_CLOCK_HAS_CALIBRATION