nRF5 SDK v13.0.0
Modules | Data Structures | Macros | Typedefs | Functions

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:

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_typeTimer event.
[in]p_contextGeneral 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_instancePointer to the driver instance structure.
[in]cc_channelCapture 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_instancePointer to the driver instance structure.
[in]cc_channelCapture 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_instancePointer to the driver instance structure.
[in]channelCapture 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_instancePointer 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_instancePointer to the driver instance structure.
[in]cc_channelCompare channel number.
[in]cc_valueCompare value.
[in]enable_intEnable 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_instancePointer to the driver instance structure.
[in]channelCompare 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_instancePointer to the driver instance structure.
[in]channelCompare 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_instancePointer to the driver instance structure.
[in]channelCompare 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_instancePointer 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_instancePointer 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_instancePointer to the driver instance structure.
[in]timer_eventTimer 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_instancePointer to the driver instance structure.
[in]cc_channelCompare channel number.
[in]cc_valueCompare value.
[in]timer_short_maskShortcut between the compare event on the channel and the timer task (STOP or CLEAR).
[in]enable_intEnable 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_instancePointer 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_instancePointer to the driver instance structure.
[in]p_configInitial configuration. Must not be NULL.
[in]timer_event_handlerEvent handler provided by the user. Must not be NULL.
Return values
NRF_SUCCESSIf initialization was successful.
NRF_ERROR_INVALID_STATEIf the instance is already initialized.
NRF_ERROR_INVALID_PARAMIf 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_instancePointer to the driver instance structure.
[in]time_msTime 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_instancePointer 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_instancePointer 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_instancePointer to the driver instance structure.
[in]timer_taskTimer 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_instancePointer 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_instancePointer to the driver instance structure.
[in]time_usTime in microseconds.
Returns
Number of ticks.

Documentation feedback | Developer Zone | Subscribe | Updated