TIMER driver

group nrfx_timer

TIMER peripheral driver.

Defines

NRFX_TIMER_INSTANCE(id)

Macro for creating a timer driver instance.

NRFX_TIMER_DEFAULT_CONFIG(_frequency)

TIMER driver default configuration.

This configuration sets up TIMER with the following options:

  • works as timer

  • width: 16 bit

Parameters:
  • _frequency[in] Timer frequency in Hz.

NRFX_TIMER_FREQUENCY_STATIC_CHECK(id, frequency)

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

Note

Macro is using compile time assertion.

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

  • frequency[in] Desired frequency value in Hz.

NRFX_TIMER_BASE_FREQUENCY_GET(p_instance)

Macro for getting base frequency value in Hz for a given timer instance.

Parameters:
  • p_instance[in] Pointer to the driver instance structure.

NRFX_TIMER_INST_HANDLER_GET(idx)

Macro returning TIMER interrupt handler.

param[in] idx TIMER index.

Returns:

Interrupt handler.

Typedefs

typedef void (*nrfx_timer_event_handler_t)(nrf_timer_event_t event_type, void *p_context)

Timer driver event handler type.

Param event_type:

[in] Timer event.

Param p_context:

[in] General purpose parameter set during initialization of the timer. This parameter can be used to pass additional information to the handler function, for example, the timer ID.

Functions

nrfx_err_t nrfx_timer_init(nrfx_timer_t const *p_instance, nrfx_timer_config_t const *p_config, nrfx_timer_event_handler_t timer_event_handler)

Function for initializing the timer.

Parameters:
  • p_instance[in] Pointer to the driver instance structure.

  • p_config[in] Pointer to the structure with the initial configuration.

  • timer_event_handler[in] Event handler provided by the user. Can be NULL.

Return values:
  • NRFX_SUCCESS – Initialization was successful.

  • NRFX_ERROR_INVALID_PARAM – Specified frequency is not supported by the TIMER instance.

  • NRFX_ERROR_ALREADY – The driver is already initialized.

  • NRFX_ERROR_INVALID_STATE – The driver is already initialized. Deprecated - use NRFX_ERROR_ALREADY instead.

nrfx_err_t nrfx_timer_reconfigure(nrfx_timer_t const *p_instance, nrfx_timer_config_t const *p_config)

Function for reconfiguring the timer.

Parameters:
  • p_instance[in] Pointer to the driver instance structure.

  • p_config[in] Pointer to the structure with the configuration.

Return values:
  • NRFX_SUCCESS – Reconfiguration was successful.

  • NRFX_ERROR_INVALID_PARAM – Specified frequency is not supported by the TIMER instance.

  • NRFX_ERROR_INVALID_STATE – The driver is uninitialized.

  • NRFX_ERROR_BUSY – The driver is enabled and cannot be reconfigured.

void nrfx_timer_uninit(nrfx_timer_t const *p_instance)

Function for uninitializing the timer.

Parameters:
  • p_instance[in] Pointer to the driver instance structure.

bool nrfx_timer_init_check(nrfx_timer_t const *p_instance)

Function for checking if the TIMER driver instance is initialized.

Parameters:
  • p_instance[in] Pointer to the driver instance structure.

Return values:
  • true – Instance is already initialized.

  • false – Instance is not initialized.

void nrfx_timer_enable(nrfx_timer_t const *p_instance)

Function for turning on the timer.

Parameters:
  • p_instance[in] Pointer to the driver instance structure.

void nrfx_timer_disable(nrfx_timer_t const *p_instance)

Function for turning off the timer.

The timer will allow to enter the lowest possible SYSTEM_ON state only after this function is called.

Parameters:
  • p_instance[in] Pointer to the driver instance structure.

bool nrfx_timer_is_enabled(nrfx_timer_t const *p_instance)

Function for checking the timer state.

Parameters:
  • p_instance[in] Pointer to the driver instance structure.

Return values:
  • true – Timer is enabled.

  • false – Timer is not enabled.

void nrfx_timer_pause(nrfx_timer_t const *p_instance)

Function for pausing the timer.

Parameters:
  • p_instance[in] Pointer to the driver instance structure.

void nrfx_timer_resume(nrfx_timer_t const *p_instance)

Function for resuming the timer.

Parameters:
  • p_instance[in] Pointer to the driver instance structure.

void nrfx_timer_clear(nrfx_timer_t const *p_instance)

Function for clearing the timer.

Parameters:
  • p_instance[in] Pointer to the driver instance structure.

void nrfx_timer_increment(nrfx_timer_t const *p_instance)

Function for incrementing the timer.

Parameters:
  • p_instance[in] Pointer to the driver instance structure.

NRFX_STATIC_INLINE uint32_t nrfx_timer_task_address_get(nrfx_timer_t const *p_instance, nrf_timer_task_t timer_task)

Function for returning the address of the specified timer task.

Parameters:
  • p_instance[in] Pointer to the driver instance structure.

  • timer_task[in] Timer task.

Returns:

Task address.

NRFX_STATIC_INLINE uint32_t nrfx_timer_capture_task_address_get(nrfx_timer_t const *p_instance, uint32_t channel)

Function for returning the address of the specified timer capture task.

Parameters:
  • p_instance[in] Pointer to the driver instance structure.

  • channel[in] Capture channel number.

Returns:

Task address.

NRFX_STATIC_INLINE uint32_t nrfx_timer_event_address_get(nrfx_timer_t const *p_instance, nrf_timer_event_t timer_event)

Function for returning the address of the specified timer event.

Parameters:
  • p_instance[in] Pointer to the driver instance structure.

  • timer_event[in] Timer event.

Returns:

Event address.

NRFX_STATIC_INLINE uint32_t nrfx_timer_compare_event_address_get(nrfx_timer_t const *p_instance, uint32_t channel)

Function for returning the address of the specified timer compare event.

Parameters:
  • p_instance[in] Pointer to the driver instance structure.

  • channel[in] Compare channel number.

Returns:

Event address.

uint32_t nrfx_timer_capture(nrfx_timer_t const *p_instance, nrf_timer_cc_channel_t cc_channel)

Function for capturing the timer value.

Parameters:
  • p_instance[in] Pointer to the driver instance structure.

  • cc_channel[in] Capture channel number.

Returns:

Captured value.

NRFX_STATIC_INLINE uint32_t nrfx_timer_capture_get(nrfx_timer_t const *p_instance, nrf_timer_cc_channel_t cc_channel)

Function for returning the capture value from the specified channel.

Use this function to read channel values when PPI is used for capturing.

Parameters:
  • p_instance[in] Pointer to the driver instance structure.

  • cc_channel[in] Capture channel number.

Returns:

Captured value.

void nrfx_timer_compare(nrfx_timer_t const *p_instance, nrf_timer_cc_channel_t cc_channel, uint32_t cc_value, bool enable_int)

Function for setting the timer channel in compare mode.

Parameters:
  • p_instance[in] Pointer to the driver instance structure.

  • cc_channel[in] Compare channel number.

  • cc_value[in] Compare value.

  • enable_int[in] Enable or disable the interrupt for the compare channel.

void nrfx_timer_extended_compare(nrfx_timer_t const *p_instance, nrf_timer_cc_channel_t cc_channel, uint32_t cc_value, nrf_timer_short_mask_t timer_short_mask, bool enable_int)

Function for setting the timer channel in the extended compare mode.

Parameters:
  • p_instance[in] Pointer to the driver instance structure.

  • cc_channel[in] Compare channel number.

  • cc_value[in] Compare value.

  • timer_short_mask[in] Shortcut between the compare event on the channel and the timer task (STOP or CLEAR).

  • enable_int[in] Enable or disable the interrupt for the compare channel.

uint32_t nrfx_timer_us_to_ticks(nrfx_timer_t const *p_instance, uint32_t time_us)

Function for converting time in microseconds to timer ticks.

Parameters:
  • p_instance[in] Pointer to the driver instance structure.

  • time_us[in] Time in microseconds.

Returns:

Number of ticks.

uint32_t nrfx_timer_ms_to_ticks(nrfx_timer_t const *p_instance, uint32_t time_ms)

Function for converting time in milliseconds to timer ticks.

Parameters:
  • p_instance[in] Pointer to the driver instance structure.

  • time_ms[in] Time in milliseconds.

Returns:

Number of ticks.

void nrfx_timer_compare_int_enable(nrfx_timer_t const *p_instance, uint32_t channel)

Function for enabling timer compare interrupt.

Parameters:
  • p_instance[in] Pointer to the driver instance structure.

  • channel[in] Compare channel.

void nrfx_timer_compare_int_disable(nrfx_timer_t const *p_instance, uint32_t channel)

Function for disabling timer compare interrupt.

Parameters:
  • p_instance[in] Pointer to the driver instance structure.

  • channel[in] Compare channel.

struct nrfx_timer_t
#include <nrfx_timer.h>

Timer driver instance data structure.

Public Members

NRF_TIMER_Type *p_reg

Pointer to the structure with TIMER peripheral instance registers.

uint8_t instance_id

Index of the driver instance. For internal use only.

uint8_t cc_channel_count

Number of capture/compare channels.

struct nrfx_timer_config_t
#include <nrfx_timer.h>

The configuration structure of the timer driver instance.

Public Members

uint32_t frequency

Frequency value.

nrf_timer_mode_t mode

Mode of operation.

nrf_timer_bit_width_t bit_width

Bit width.

uint8_t interrupt_priority

Interrupt priority.

void *p_context

Context passed to interrupt handler.