| nRF5 SDK v12.0.0 |

Choose documentation: | nRF5 SDK | S130 SoftDevice API | S132 SoftDevice API | S212 SoftDevice API | S332 SoftDevice API

All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
Modules | Data Structures | Macros | Typedefs | Functions
Timer driver
Timer HAL and driver

Multi-instance timer driver. More...

## Modules
| TIMER periperal driver configuration

## Data Structures
struct | nrf_drv_timer_t
| Timer driver instance data structure. More...
struct | nrf_drv_timer_config_t
| Timer driver instance configuration structure. More...

## Macros
#define | ENABLED_TIMER_COUNT (TIMER0_ENABLED+TIMER1_ENABLED+TIMER2_ENABLED+TIMER3_ENABLED+TIMER4_ENABLED)
#define | TIMER0_INSTANCE_INDEX 0
#define | TIMER1_INSTANCE_INDEX TIMER0_INSTANCE_INDEX+TIMER0_ENABLED
#define | TIMER2_INSTANCE_INDEX TIMER1_INSTANCE_INDEX+TIMER1_ENABLED
#define | TIMER3_INSTANCE_INDEX TIMER2_INSTANCE_INDEX+TIMER2_ENABLED
#define | TIMER4_INSTANCE_INDEX TIMER3_INSTANCE_INDEX+TIMER3_ENABLED
#define | NRF_DRV_TIMER_INSTANCE(id)
| Macro for creating a timer driver instance. More...
#define | NRF_DRV_TIMER_DEFAULT_CONFIG
| Timer driver instance default configuration. More...

## Typedefs
typedef void(* | nrf_timer_event_handler_t )(nrf_timer_event_t event_type, void *p_context)
| Timer driver event handler type. More...

## Functions
ret_code_t | nrf_drv_timer_init (nrf_drv_timer_t const *const p_instance, nrf_drv_timer_config_t const *p_config, nrf_timer_event_handler_t timer_event_handler)
| Function for initializing the timer. More...
void | nrf_drv_timer_uninit (nrf_drv_timer_t const *const p_instance)
| Function for uninitializing the timer. More...
void | nrf_drv_timer_enable (nrf_drv_timer_t const *const p_instance)
| Function for turning on the timer. More...
void | nrf_drv_timer_disable (nrf_drv_timer_t const *const p_instance)
| Function for turning off the timer. More...
void | nrf_drv_timer_pause (nrf_drv_timer_t const *const p_instance)
| Function for pausing the timer. More...
void | nrf_drv_timer_resume (nrf_drv_timer_t const *const p_instance)
| Function for resuming the timer. More...
void | nrf_drv_timer_clear (nrf_drv_timer_t const *const p_instance)
| Function for clearing the timer. More...
void | nrf_drv_timer_increment (nrf_drv_timer_t const *const p_instance)
| Function for incrementing the timer. More...
__STATIC_INLINE uint32_t | nrf_drv_timer_task_address_get (nrf_drv_timer_t const *const p_instance, nrf_timer_task_t timer_task)
| Function for returning the address of a specific timer task. More...
__STATIC_INLINE uint32_t | nrf_drv_timer_capture_task_address_get (nrf_drv_timer_t const *const p_instance, uint32_t channel)
| Function for returning the address of a specific timer capture task. More...
__STATIC_INLINE uint32_t | nrf_drv_timer_event_address_get (nrf_drv_timer_t const *const p_instance, nrf_timer_event_t timer_event)
| Function for returning the address of a specific timer event. More...
__STATIC_INLINE uint32_t | nrf_drv_timer_compare_event_address_get (nrf_drv_timer_t const *const p_instance, uint32_t channel)
| Function for returning the address of a specific timer compare event. More...
uint32_t | nrf_drv_timer_capture (nrf_drv_timer_t const *const p_instance, nrf_timer_cc_channel_t cc_channel)
| Function for capturing the timer value. More...
__STATIC_INLINE uint32_t | nrf_drv_timer_capture_get (nrf_drv_timer_t const *const p_instance, nrf_timer_cc_channel_t cc_channel)
| Function for returning the capture value from a specific channel. More...
void | nrf_drv_timer_compare (nrf_drv_timer_t const *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. More...
void | nrf_drv_timer_extended_compare (nrf_drv_timer_t const *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 extended compare mode. More...
__STATIC_INLINE uint32_t | nrf_drv_timer_us_to_ticks (nrf_drv_timer_t const *const p_instance, uint32_t time_us)
| Function for converting time in microseconds to timer ticks. More...
__STATIC_INLINE uint32_t | nrf_drv_timer_ms_to_ticks (nrf_drv_timer_t const *const p_instance, uint32_t time_ms)
| Function for converting time in milliseconds to timer ticks. More...
void | nrf_drv_timer_compare_int_enable (nrf_drv_timer_t const *const p_instance, uint32_t channel)
| Function for enabling timer compare interrupt. More...
void | nrf_drv_timer_compare_int_disable (nrf_drv_timer_t const *const p_instance, uint32_t channel)
| Function for disabling timer compare interrupt. More...

## Detailed Description

Multi-instance timer driver.

## Macro Definition Documentation

#define NRF_DRV_TIMER_DEFAULT_CONFIG

Value:
{ \
.frequency = (nrf_timer_frequency_t)TIMER_DEFAULT_CONFIG_FREQUENCY,\
.mode = (nrf_timer_mode_t)TIMER_DEFAULT_CONFIG_MODE, \
.bit_width = (nrf_timer_bit_width_t)TIMER_DEFAULT_CONFIG_BIT_WIDTH,\
.interrupt_priority = TIMER_DEFAULT_CONFIG_IRQ_PRIORITY, \
.p_context = NULL \
}

Timer driver instance default configuration.

#define NRF_DRV_TIMER_INSTANCE | ( |  | id | ) |

Value:
{ \
.p_reg = CONCAT_2(NRF_TIMER, id), \
.instance_id = CONCAT_3(TIMER, id, _INSTANCE_INDEX), \
.cc_channel_count = NRF_TIMER_CC_CHANNEL_COUNT(id), \
}

Macro for creating a timer driver instance.

## Typedef Documentation

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

Timer driver event handler type.

Parameters

  [in] | event_type | Timer event.
  [in] | p_context | 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.

## Function Documentation

uint32_t nrf_drv_timer_capture | ( | nrf_drv_timer_t const *const | p_instance,
|  | nrf_timer_cc_channel_t | cc_channel
| ) |  |

Function for capturing the timer value.

Parameters

  [in] | p_instance | Pointer to the driver instance structure.
  [in] | cc_channel | Capture channel number.

Returns
  Captured value.

__STATIC_INLINE uint32_t nrf_drv_timer_capture_get | ( | nrf_drv_timer_t const *const | p_instance,
|  | nrf_timer_cc_channel_t | cc_channel
| ) |  |

Function for returning the capture value from a specific channel.

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

Parameters

  [in] | p_instance | Pointer to the driver instance structure.
  [in] | cc_channel | Capture channel number.

Returns
  Captured value.

__STATIC_INLINE uint32_t nrf_drv_timer_capture_task_address_get | ( | nrf_drv_timer_t const *const | p_instance,
|  | uint32_t | channel
| ) |  |

Function for returning the address of a specific timer capture task.

Parameters

  [in] | p_instance | Pointer to the driver instance structure.
  [in] | channel | Capture channel number.

Returns
  Task address.

void nrf_drv_timer_clear | ( | nrf_drv_timer_t const *const | p_instance | ) |

Function for clearing the timer.

Parameters

  [in] | p_instance | Pointer to the driver instance structure.

void nrf_drv_timer_compare | ( | nrf_drv_timer_t const *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

  [in] | p_instance | Pointer to the driver instance structure.
  [in] | cc_channel | Compare channel number.
  [in] | cc_value | Compare value.
  [in] | enable_int | Enable or disable the interrupt for the compare channel.

__STATIC_INLINE uint32_t nrf_drv_timer_compare_event_address_get | ( | nrf_drv_timer_t const *const | p_instance,
|  | uint32_t | channel
| ) |  |

Function for returning the address of a specific timer compare event.

Parameters

  [in] | p_instance | Pointer to the driver instance structure.
  [in] | channel | Compare channel number.

Returns
  Event address.

void nrf_drv_timer_compare_int_disable | ( | nrf_drv_timer_t const *const | p_instance,
|  | uint32_t | channel
| ) |  |

Function for disabling timer compare interrupt.

Parameters

  [in] | p_instance | Pointer to the driver instance structure.
  [in] | channel | Compare channel.

void nrf_drv_timer_compare_int_enable | ( | nrf_drv_timer_t const *const | p_instance,
|  | uint32_t | channel
| ) |  |

Function for enabling timer compare interrupt.

Parameters

  [in] | p_instance | Pointer to the driver instance structure.
  [in] | channel | Compare channel.

void nrf_drv_timer_disable | ( | nrf_drv_timer_t const *const | p_instance | ) |

Function for turning off the timer.

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

Parameters

  [in] | p_instance | Pointer to the driver instance structure.

void nrf_drv_timer_enable | ( | nrf_drv_timer_t const *const | p_instance | ) |

Function for turning on the timer.

Parameters

  [in] | p_instance | Pointer to the driver instance structure.

__STATIC_INLINE uint32_t nrf_drv_timer_event_address_get | ( | nrf_drv_timer_t const *const | p_instance,
|  | nrf_timer_event_t | timer_event
| ) |  |

Function for returning the address of a specific timer event.

Parameters

  [in] | p_instance | Pointer to the driver instance structure.
  [in] | timer_event | Timer event.

Returns
  Event address.

void nrf_drv_timer_extended_compare | ( | nrf_drv_timer_t const *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 extended compare mode.

Parameters

  [in] | p_instance | Pointer to the driver instance structure.
  [in] | cc_channel | Compare channel number.
  [in] | cc_value | Compare value.
  [in] | timer_short_mask | Shortcut between the compare event on the channel and the timer task (STOP or CLEAR).
  [in] | enable_int | Enable or disable the interrupt for the compare channel.

void nrf_drv_timer_increment | ( | nrf_drv_timer_t const *const | p_instance | ) |

Function for incrementing the timer.

Parameters

  [in] | p_instance | Pointer to the driver instance structure.

ret_code_t nrf_drv_timer_init | ( | nrf_drv_timer_t const *const | p_instance,
|  | nrf_drv_timer_config_t const * | p_config,
|  | nrf_timer_event_handler_t | timer_event_handler
| ) |  |

Function for initializing the timer.

Parameters

  [in] | p_instance | Pointer to the driver instance structure.
  [in] | p_config | Initial configuration. If NULL, the default configuration is used.
  [in] | timer_event_handler | Event handler provided by the user. Must not be NULL.

Return values

  NRF_SUCCESS | If initialization was successful.
  NRF_ERROR_INVALID_STATE | If the instance is already initialized.
  NRF_ERROR_INVALID_PARAM | If no handler was provided.

__STATIC_INLINE uint32_t nrf_drv_timer_ms_to_ticks | ( | nrf_drv_timer_t const *const | p_instance,
|  | uint32_t | time_ms
| ) |  |

Function for converting time in milliseconds to timer ticks.

Parameters

  [in] | p_instance | Pointer to the driver instance structure.
  [in] | time_ms | Time in milliseconds.

Returns
  Number of ticks.

void nrf_drv_timer_pause | ( | nrf_drv_timer_t const *const | p_instance | ) |

Function for pausing the timer.

Parameters

  [in] | p_instance | Pointer to the driver instance structure.

void nrf_drv_timer_resume | ( | nrf_drv_timer_t const *const | p_instance | ) |

Function for resuming the timer.

Parameters

  [in] | p_instance | Pointer to the driver instance structure.

__STATIC_INLINE uint32_t nrf_drv_timer_task_address_get | ( | nrf_drv_timer_t const *const | p_instance,
|  | nrf_timer_task_t | timer_task
| ) |  |

Function for returning the address of a specific timer task.

Parameters

  [in] | p_instance | Pointer to the driver instance structure.
  [in] | timer_task | Timer task.

Returns
  Task address.

void nrf_drv_timer_uninit | ( | nrf_drv_timer_t const *const | p_instance | ) |

Function for uninitializing the timer.

Parameters

  [in] | p_instance | Pointer to the driver instance structure.

__STATIC_INLINE uint32_t nrf_drv_timer_us_to_ticks | ( | nrf_drv_timer_t const *const | p_instance,
|  | uint32_t | time_us
| ) |  |

Function for converting time in microseconds to timer ticks.

Parameters

  [in] | p_instance | Pointer to the driver instance structure.
  [in] | time_us | Time in microseconds.

Returns
  Number of ticks.