TIMER driver

group nrfx_timer

TIMER peripheral driver.

Defines

NRFX_TIMER_INSTANCE(id)

Macro for creating a timer driver instance.

NRFX_TIMER_DEFAULT_CONFIG

TIMER driver default configuration.

This configuration sets up TIMER with the following options:

  • frequency: 16 MHz

  • works as timer

  • width: 16 bit

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. Must not be NULL.

Return values
  • NRFX_SUCCESS – Initialization was successful.

  • NRFX_ERROR_INVALID_STATE – The instance is already initialized.

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.

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.

NRFX_STATIC_INLINE 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.

NRFX_STATIC_INLINE 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 <>

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

The configuration structure of the timer driver instance.

Public Members

nrf_timer_frequency_t frequency

Frequency.

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.