TIMER HAL

group nrf_timer_hal

Hardware access layer for managing the TIMER peripheral.

Defines

NRF_TIMER_INST_GET(idx)

Macro getting pointer to the structure of registers of the TIMER peripheral.

Parameters:
  • idx[in] TIMER instance index.

Returns:

Pointer to the structure of registers of the TIMER peripheral.

NRF_TIMER_HAS_CC4

Symbol indicating whether timer has capture/compare channel 4.

NRF_TIMER_HAS_CC5

Symbol indicating whether timer has capture/compare channel 5.

NRF_TIMER_HAS_CC6

Symbol indicating whether timer has capture/compare channel 6.

NRF_TIMER_HAS_CC7

Symbol indicating whether timer has capture/compare channel 7.

NRF_TIMER_HAS_LOW_POWER_MODE

Symbol indicating whether timer supports low power mode.

NRF_TIMER_HAS_ONE_SHOT

Symbol indicating whether timer supports one-shot operation.

NRF_TIMER_BASE_FREQUENCY_320MHZ

Base frequency value 320 MHz for TIMER.

NRF_TIMER_BASE_FREQUENCY_64MHZ

Base frequency value 64 MHz for TIMER.

NRF_TIMER_BASE_FREQUENCY_32MHZ

Base frequency value 32 MHz for TIMER.

NRF_TIMER_BASE_FREQUENCY_16MHZ

Base frequency value 16 MHz for TIMER.

NRF_TIMER_PRESCALER_MAX

Maximum value of PRESCALER register.

TIMER_MAX_SIZE(id)

Macro for getting the maximum bit resolution of the specified timer instance.

Parameters:
  • id[in] Index of the specified timer instance.

Return values:

Maximum – bit resolution of the specified timer instance.

TIMER_BIT_WIDTH_MAX(id, bit_width)

Macro for validating the correctness of the bit width resolution setting.

Parameters:
  • id[in] Index of the specified timer instance.

  • bit_width[in] Bit width resolution value to be checked.

Return values:
  • true – Timer instance supports the specified bit width resolution value.

  • false – Timer instance does not support the specified bit width resolution value.

NRF_TIMER_IS_BIT_WIDTH_VALID(p_reg, bit_width)

Macro for checking correctness of bit width configuration for the specified timer.

Parameters:
  • p_reg[in] Timer instance register.

  • bit_width[in] Bit width resolution value to be checked.

Return values:
  • true – Timer instance supports the specified bit width resolution value.

  • false – Timer instance does not support the specified bit width resolution value.

NRF_TIMER_IS_320MHZ_TIMER(p_reg)

Macro for checking whether the base frequency for the specified timer is 320 MHz.

NRF_TIMER_IS_64MHZ_TIMER(p_reg)

Macro for checking whether the base frequency for the specified timer is 64 MHz.

NRF_TIMER_IS_32MHZ_TIMER(p_reg)

Macro for checking whether the base frequency for the specified timer is 32 MHz.

NRF_TIMER_IS_16MHZ_TIMER(p_reg)

Macro for checking whether the base frequency for the specified timer is 16 MHz.

NRF_TIMER_BASE_FREQUENCY_GET(p_reg)

Macro for getting base frequency value in Hz for the specified timer.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

NRF_TIMER_PRESCALER_CALCULATE(base_freq, frequency)

Macro for computing prescaler value for given base frequency and desired frequency.

Warning

Not every combination of base frequency and desired frequency is supported.

Parameters:
  • base_freq[in] Base clock frequency for timer in Hz.

  • frequency[in] Desired frequency value in Hz.

NRF_TIMER_FREQUENCY_STATIC_CHECK(p_reg, frequency)

Macro for checking whether specified frequency can be achived for given timer instance.

Note

Macro is using compile time assertion.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • frequency[in] Desired frequency value in Hz.

NRF_TIMER_CC_CHANNEL_COUNT(id)

Macro for getting the number of capture/compare channels available in a given timer instance.

Parameters:
  • id[in] Index of the specified timer instance.

NRF_TIMER_CC_COUNT_MAX

Symbol specifying maximum number of available compare channels.

NRF_TIMER_ALL_CHANNELS_INT_MASK

Symbol for creating the interrupt bitmask for all compare channels.

Enums

enum nrf_timer_task_t

Timer tasks.

Values:

enumerator NRF_TIMER_TASK_START

Task for starting the timer.

enumerator NRF_TIMER_TASK_STOP

Task for stopping the timer.

enumerator NRF_TIMER_TASK_COUNT

Task for incrementing the timer (in counter mode).

enumerator NRF_TIMER_TASK_CLEAR

Task for resetting the timer value.

enumerator NRF_TIMER_TASK_SHUTDOWN

Task for powering off the timer.

enumerator NRF_TIMER_TASK_CAPTURE0

Task for capturing the timer value on channel 0.

enumerator NRF_TIMER_TASK_CAPTURE1

Task for capturing the timer value on channel 1.

enumerator NRF_TIMER_TASK_CAPTURE2

Task for capturing the timer value on channel 2.

enumerator NRF_TIMER_TASK_CAPTURE3

Task for capturing the timer value on channel 3.

enumerator NRF_TIMER_TASK_CAPTURE4

Task for capturing the timer value on channel 4.

enumerator NRF_TIMER_TASK_CAPTURE5

Task for capturing the timer value on channel 5.

enumerator NRF_TIMER_TASK_CAPTURE6

Task for capturing the timer value on channel 6.

enumerator NRF_TIMER_TASK_CAPTURE7

Task for capturing the timer value on channel 7.

enum nrf_timer_event_t

Timer events.

Values:

enumerator NRF_TIMER_EVENT_COMPARE0

Event from compare channel 0.

enumerator NRF_TIMER_EVENT_COMPARE1

Event from compare channel 1.

enumerator NRF_TIMER_EVENT_COMPARE2

Event from compare channel 2.

enumerator NRF_TIMER_EVENT_COMPARE3

Event from compare channel 3.

enumerator NRF_TIMER_EVENT_COMPARE4

Event from compare channel 4.

enumerator NRF_TIMER_EVENT_COMPARE5

Event from compare channel 5.

enumerator NRF_TIMER_EVENT_COMPARE6

Event from compare channel 6.

enumerator NRF_TIMER_EVENT_COMPARE7

Event from compare channel 7.

enum nrf_timer_short_mask_t

Types of timer shortcuts.

Values:

enumerator NRF_TIMER_SHORT_COMPARE0_STOP_MASK

Shortcut for stopping the timer based on compare 0.

enumerator NRF_TIMER_SHORT_COMPARE1_STOP_MASK

Shortcut for stopping the timer based on compare 1.

enumerator NRF_TIMER_SHORT_COMPARE2_STOP_MASK

Shortcut for stopping the timer based on compare 2.

enumerator NRF_TIMER_SHORT_COMPARE3_STOP_MASK

Shortcut for stopping the timer based on compare 3.

enumerator NRF_TIMER_SHORT_COMPARE4_STOP_MASK

Shortcut for stopping the timer based on compare 4.

enumerator NRF_TIMER_SHORT_COMPARE5_STOP_MASK

Shortcut for stopping the timer based on compare 5.

enumerator NRF_TIMER_SHORT_COMPARE6_STOP_MASK

Shortcut for stopping the timer based on compare 6.

enumerator NRF_TIMER_SHORT_COMPARE7_STOP_MASK

Shortcut for stopping the timer based on compare 7.

enumerator NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK

Shortcut for clearing the timer based on compare 0.

enumerator NRF_TIMER_SHORT_COMPARE1_CLEAR_MASK

Shortcut for clearing the timer based on compare 1.

enumerator NRF_TIMER_SHORT_COMPARE2_CLEAR_MASK

Shortcut for clearing the timer based on compare 2.

enumerator NRF_TIMER_SHORT_COMPARE3_CLEAR_MASK

Shortcut for clearing the timer based on compare 3.

enumerator NRF_TIMER_SHORT_COMPARE4_CLEAR_MASK

Shortcut for clearing the timer based on compare 4.

enumerator NRF_TIMER_SHORT_COMPARE5_CLEAR_MASK

Shortcut for clearing the timer based on compare 5.

enumerator NRF_TIMER_SHORT_COMPARE6_CLEAR_MASK

Shortcut for clearing the timer based on compare 6.

enumerator NRF_TIMER_SHORT_COMPARE7_CLEAR_MASK

Shortcut for clearing the timer based on compare 7.

enum nrf_timer_mode_t

Timer modes.

Values:

enumerator NRF_TIMER_MODE_TIMER

Timer mode: timer.

enumerator NRF_TIMER_MODE_COUNTER

Timer mode: counter.

enumerator NRF_TIMER_MODE_LOW_POWER_COUNTER

Timer mode: low-power counter.

enum nrf_timer_bit_width_t

Timer bit width.

Values:

enumerator NRF_TIMER_BIT_WIDTH_8

Timer bit width 8 bit.

enumerator NRF_TIMER_BIT_WIDTH_16

Timer bit width 16 bit.

enumerator NRF_TIMER_BIT_WIDTH_24

Timer bit width 24 bit.

enumerator NRF_TIMER_BIT_WIDTH_32

Timer bit width 32 bit.

enum nrf_timer_frequency_t

Timer prescalers.

Values:

enumerator NRF_TIMER_FREQ_16MHz

Timer frequency 16 MHz.

enumerator NRF_TIMER_FREQ_8MHz

Timer frequency 8 MHz.

enumerator NRF_TIMER_FREQ_4MHz

Timer frequency 4 MHz.

enumerator NRF_TIMER_FREQ_2MHz

Timer frequency 2 MHz.

enumerator NRF_TIMER_FREQ_1MHz

Timer frequency 1 MHz.

enumerator NRF_TIMER_FREQ_500kHz

Timer frequency 500 kHz.

enumerator NRF_TIMER_FREQ_250kHz

Timer frequency 250 kHz.

enumerator NRF_TIMER_FREQ_125kHz

Timer frequency 125 kHz.

enumerator NRF_TIMER_FREQ_62500Hz

Timer frequency 62500 Hz.

enumerator NRF_TIMER_FREQ_31250Hz

Timer frequency 31250 Hz.

enum nrf_timer_cc_channel_t

Timer capture/compare channels.

Values:

enumerator NRF_TIMER_CC_CHANNEL0

Timer capture/compare channel 0.

enumerator NRF_TIMER_CC_CHANNEL1

Timer capture/compare channel 1.

enumerator NRF_TIMER_CC_CHANNEL2

Timer capture/compare channel 2.

enumerator NRF_TIMER_CC_CHANNEL3

Timer capture/compare channel 3.

enumerator NRF_TIMER_CC_CHANNEL4

Timer capture/compare channel 4.

enumerator NRF_TIMER_CC_CHANNEL5

Timer capture/compare channel 5.

enumerator NRF_TIMER_CC_CHANNEL6

Timer capture/compare channel 6.

enumerator NRF_TIMER_CC_CHANNEL7

Timer capture/compare channel 7.

enum nrf_timer_int_mask_t

Timer interrupts.

Values:

enumerator NRF_TIMER_INT_COMPARE0_MASK

Timer interrupt from compare event on channel 0.

enumerator NRF_TIMER_INT_COMPARE1_MASK

Timer interrupt from compare event on channel 1.

enumerator NRF_TIMER_INT_COMPARE2_MASK

Timer interrupt from compare event on channel 2.

enumerator NRF_TIMER_INT_COMPARE3_MASK

Timer interrupt from compare event on channel 3.

enumerator NRF_TIMER_INT_COMPARE4_MASK

Timer interrupt from compare event on channel 4.

enumerator NRF_TIMER_INT_COMPARE5_MASK

Timer interrupt from compare event on channel 5.

enumerator NRF_TIMER_INT_COMPARE6_MASK

Timer interrupt from compare event on channel 6.

enumerator NRF_TIMER_INT_COMPARE7_MASK

Timer interrupt from compare event on channel 7.

Functions

NRF_STATIC_INLINE void nrf_timer_prescaler_set(NRF_TIMER_Type *p_reg, uint32_t prescaler_factor)

Function for setting the prescaler factor.

Note

Prescaler value is expressed as \( 2^{prescaler\_factor} \).

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • prescaler_factor[in] Prescaler factor.

NRF_STATIC_INLINE uint32_t nrf_timer_prescaler_get(NRF_TIMER_Type const *p_reg)

Function for retrieving the prescaler factor.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

Returns:

Prescaler factor.

NRF_STATIC_INLINE void nrf_timer_task_trigger(NRF_TIMER_Type *p_reg, nrf_timer_task_t task)

Function for activating the specified timer 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_timer_task_address_get(NRF_TIMER_Type const *p_reg, nrf_timer_task_t task)

Function for getting the address of the specified timer task register.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • task[in] The specified task.

Returns:

Address of the specified task register.

NRF_STATIC_INLINE void nrf_timer_event_clear(NRF_TIMER_Type *p_reg, nrf_timer_event_t event)

Function for clearing the specified timer event.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • event[in] Event to clear.

NRF_STATIC_INLINE bool nrf_timer_event_check(NRF_TIMER_Type const *p_reg, nrf_timer_event_t event)

Function for retrieving the state of the TIMER 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 uint32_t nrf_timer_event_address_get(NRF_TIMER_Type const *p_reg, nrf_timer_event_t event)

Function for getting the address of the specified timer event register.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • event[in] The specified event.

Returns:

Address of the specified event register.

NRF_STATIC_INLINE void nrf_timer_shorts_enable(NRF_TIMER_Type *p_reg, uint32_t mask)

Function for enabling the specified shortcuts.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • mask[in] Shortcuts to be enabled.

NRF_STATIC_INLINE void nrf_timer_shorts_disable(NRF_TIMER_Type *p_reg, uint32_t mask)

Function for disabling the specified shortcuts.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • mask[in] Shortcuts to be disabled.

NRF_STATIC_INLINE void nrf_timer_shorts_set(NRF_TIMER_Type *p_reg, uint32_t mask)

Function for setting the specified shortcuts.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • mask[in] Shortcuts to be set.

NRF_STATIC_INLINE nrf_timer_short_mask_t nrf_timer_short_compare_clear_get(uint8_t channel)

Function for getting COMPARE_CLEAR short mask for the specified channel.

Parameters:
  • channel[in] Channel.

Returns:

Short mask.

NRF_STATIC_INLINE nrf_timer_short_mask_t nrf_timer_short_compare_stop_get(uint8_t channel)

Function for getting COMPARE_STOP short mask for the specified channel.

Parameters:
  • channel[in] Channel.

Returns:

Short mask.

NRF_STATIC_INLINE void nrf_timer_int_enable(NRF_TIMER_Type *p_reg, uint32_t mask)

Function for enabling the specified interrupts.

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_timer_int_disable(NRF_TIMER_Type *p_reg, uint32_t mask)

Function for disabling the specified interrupts.

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_timer_int_enable_check(NRF_TIMER_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 void nrf_timer_subscribe_set(NRF_TIMER_Type *p_reg, nrf_timer_task_t task, uint8_t channel)

Function for setting the subscribe configuration for a given TIMER 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_timer_subscribe_clear(NRF_TIMER_Type *p_reg, nrf_timer_task_t task)

Function for clearing the subscribe configuration for a given TIMER 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_timer_publish_set(NRF_TIMER_Type *p_reg, nrf_timer_event_t event, uint8_t channel)

Function for setting the publish configuration for a given TIMER 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_timer_publish_clear(NRF_TIMER_Type *p_reg, nrf_timer_event_t event)

Function for clearing the publish configuration for a given TIMER event.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • event[in] Event for which to clear the configuration.

NRF_STATIC_INLINE void nrf_timer_mode_set(NRF_TIMER_Type *p_reg, nrf_timer_mode_t mode)

Function for setting the timer mode.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • mode[in] Timer mode.

NRF_STATIC_INLINE nrf_timer_mode_t nrf_timer_mode_get(NRF_TIMER_Type const *p_reg)

Function for retrieving the timer mode.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

Returns:

Timer mode.

NRF_STATIC_INLINE void nrf_timer_bit_width_set(NRF_TIMER_Type *p_reg, nrf_timer_bit_width_t bit_width)

Function for setting the timer bit width.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • bit_width[in] Timer bit width.

NRF_STATIC_INLINE nrf_timer_bit_width_t nrf_timer_bit_width_get(NRF_TIMER_Type const *p_reg)

Function for retrieving the timer bit width.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

Returns:

Timer bit width.

NRF_STATIC_INLINE void nrf_timer_cc_set(NRF_TIMER_Type *p_reg, nrf_timer_cc_channel_t cc_channel, uint32_t cc_value)

Function for setting the capture/compare register for the specified channel.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • cc_channel[in] The specified capture/compare channel.

  • cc_value[in] Value to write to the capture/compare register.

NRF_STATIC_INLINE uint32_t nrf_timer_cc_get(NRF_TIMER_Type const *p_reg, nrf_timer_cc_channel_t cc_channel)

Function for retrieving the capture/compare value for a specified channel.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • cc_channel[in] The specified capture/compare channel.

Returns:

Value from the specified capture/compare register.

NRF_STATIC_INLINE nrf_timer_task_t nrf_timer_capture_task_get(uint8_t channel)

Function for getting the specified timer capture task.

Parameters:
  • channel[in] Capture channel.

Returns:

Capture task.

NRF_STATIC_INLINE nrf_timer_event_t nrf_timer_compare_event_get(uint8_t channel)

Function for getting the specified timer compare event.

Parameters:
  • channel[in] Compare channel.

Returns:

Compare event.

NRF_STATIC_INLINE nrf_timer_int_mask_t nrf_timer_compare_int_get(uint8_t channel)

Function for getting the specified timer compare interrupt.

Parameters:
  • channel[in] Compare channel.

Returns:

Compare interrupt.

NRF_STATIC_INLINE uint32_t nrf_timer_us_to_ticks(uint32_t time_us, nrf_timer_frequency_t frequency)

Function for calculating the number of timer ticks for a given time (in microseconds) and timer frequency.

Parameters:
  • time_us[in] Time in microseconds.

  • frequency[in] Timer frequency.

Returns:

Number of timer ticks.

NRF_STATIC_INLINE uint32_t nrf_timer_ms_to_ticks(uint32_t time_ms, nrf_timer_frequency_t frequency)

Function for calculating the number of timer ticks for a given time (in milliseconds) and timer frequency.

Parameters:
  • time_ms[in] Time in milliseconds.

  • frequency[in] Timer frequency.

Returns:

Number of timer ticks.

NRF_STATIC_INLINE void nrf_timer_one_shot_enable(NRF_TIMER_Type *p_reg, nrf_timer_cc_channel_t cc_channel)

Function for enabling one-shot operation for the specified capture/compare channel.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • cc_channel[in] Capture/compare channel.

NRF_STATIC_INLINE void nrf_timer_one_shot_disable(NRF_TIMER_Type *p_reg, nrf_timer_cc_channel_t cc_channel)

Function for disabling one-shot operation for the specified capture/compare channel.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • cc_channel[in] Capture/compare channel.