nrfx 4.5.0
Loading...
Searching...
No Matches
Timer driver

TIMER peripheral driver. More...

Topics

 TIMER periperal driver configuration
 

Data Structures

struct  nrfx_timer_config_t
 The configuration structure of the timer driver instance. More...
 
struct  nrfx_timer_t
 Timer driver instance data structure. More...
 

Macros

#define NRFX_TIMER_DEFAULT_CONFIG(_frequency)
 TIMER driver default configuration.
 
#define NRFX_TIMER_FREQUENCY_STATIC_CHECK(id, frequency)
 Macro for checking whether specified frequency can be achived for given timer instance.
 
#define NRFX_TIMER_BASE_FREQUENCY_GET(p_instance)
 Macro for getting base frequency value in Hz for a given timer instance.
 
#define NRFX_TIMER_INSTANCE(reg)
 Macro for creating a timer driver instance.
 

Typedefs

typedef void(* nrfx_timer_event_handler_t) (nrf_timer_event_t event_type, void *p_context)
 Timer driver event handler type.
 

Functions

int nrfx_timer_init (nrfx_timer_t *p_instance, nrfx_timer_config_t const *p_config, nrfx_timer_event_handler_t timer_event_handler)
 Function for initializing the timer.
 
int nrfx_timer_reconfigure (nrfx_timer_t *p_instance, nrfx_timer_config_t const *p_config)
 Function for reconfiguring the timer.
 
void nrfx_timer_uninit (nrfx_timer_t *p_instance)
 Function for uninitializing the timer.
 
bool nrfx_timer_init_check (nrfx_timer_t const *p_instance)
 Function for checking if the TIMER driver instance is initialized.
 
void nrfx_timer_enable (nrfx_timer_t *p_instance)
 Function for turning on the timer.
 
void nrfx_timer_disable (nrfx_timer_t *p_instance)
 Function for turning off the timer.
 
bool nrfx_timer_is_enabled (nrfx_timer_t const *p_instance)
 Function for checking the timer state.
 
void nrfx_timer_pause (nrfx_timer_t const *p_instance)
 Function for pausing the timer.
 
void nrfx_timer_resume (nrfx_timer_t const *p_instance)
 Function for resuming the timer.
 
void nrfx_timer_clear (nrfx_timer_t const *p_instance)
 Function for clearing the timer.
 
void nrfx_timer_increment (nrfx_timer_t const *p_instance)
 Function for incrementing the timer.
 
void nrfx_timer_irq_handler (nrfx_timer_t const *p_instance)
 Driver interrupt handler.
 
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.
 
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.
 
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.
 
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.
 
uint32_t nrfx_timer_capture (nrfx_timer_t const *p_instance, nrf_timer_cc_channel_t cc_channel)
 Function for capturing the timer 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.
 
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.
 
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.
 
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.
 
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.
 
void nrfx_timer_compare_int_enable (nrfx_timer_t const *p_instance, uint32_t channel)
 Function for enabling timer compare interrupt.
 
void nrfx_timer_compare_int_disable (nrfx_timer_t const *p_instance, uint32_t channel)
 Function for disabling timer compare interrupt.
 

Detailed Description

TIMER peripheral driver.

Macro Definition Documentation

◆ NRFX_TIMER_BASE_FREQUENCY_GET

#define NRFX_TIMER_BASE_FREQUENCY_GET ( p_instance)
Value:
NRF_TIMER_BASE_FREQUENCY_GET((p_instance)->p_reg)
#define NRF_TIMER_BASE_FREQUENCY_GET(p_reg)
Macro for getting base frequency value in Hz for the specified timer.
Definition nrf_timer.h:220

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

Parameters
[in]p_instancePointer to the driver instance structure.

◆ NRFX_TIMER_DEFAULT_CONFIG

#define NRFX_TIMER_DEFAULT_CONFIG ( _frequency)
Value:
{ \
.frequency = _frequency, \
.bit_width = NRF_TIMER_BIT_WIDTH_16, \
.interrupt_priority = NRFX_TIMER_DEFAULT_CONFIG_IRQ_PRIORITY, \
.p_context = NULL \
}
@ NRF_TIMER_BIT_WIDTH_16
Timer bit width 16 bit.
Definition nrf_timer.h:369
@ NRF_TIMER_MODE_TIMER
Timer mode: timer.
Definition nrf_timer.h:358
#define NRFX_TIMER_DEFAULT_CONFIG_IRQ_PRIORITY
Interrupt priority.
Definition nrfx_timer_dox_config.h:30

TIMER driver default configuration.

This configuration sets up TIMER with the following options:

  • works as timer
  • width: 16 bit
Parameters
[in]_frequencyTimer frequency in Hz.

◆ NRFX_TIMER_FREQUENCY_STATIC_CHECK

#define NRFX_TIMER_FREQUENCY_STATIC_CHECK ( id,
frequency )
Value:
#define NRF_TIMER_FREQUENCY_STATIC_CHECK(p_reg, frequency)
Macro for checking whether specified frequency can be achived for given timer instance.
Definition nrf_timer.h:247
#define NRF_TIMER_INST_GET(idx)
Macro getting pointer to the structure of registers of the TIMER peripheral.
Definition nrf_timer.h:57

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

Note
Macro is using compile time assertion.
Parameters
[in]idIndex of the specified timer instance.
[in]frequencyDesired frequency value in Hz.

◆ NRFX_TIMER_INSTANCE

#define NRFX_TIMER_INSTANCE ( reg)
Value:
{ \
.p_reg = (NRF_TIMER_Type *)reg, \
.cb = {0}, \
}

Macro for creating a timer driver instance.

Typedef Documentation

◆ nrfx_timer_event_handler_t

typedef void(* nrfx_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

◆ nrfx_timer_capture()

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
[in]p_instancePointer to the driver instance structure.
[in]cc_channelCapture channel number.
Returns
Captured value.

◆ nrfx_timer_capture_get()

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
[in]p_instancePointer to the driver instance structure.
[in]cc_channelCapture channel number.
Returns
Captured value.

◆ nrfx_timer_capture_task_address_get()

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
[in]p_instancePointer to the driver instance structure.
[in]channelCapture channel number.
Returns
Task address.

◆ nrfx_timer_clear()

void nrfx_timer_clear ( nrfx_timer_t const * p_instance)

Function for clearing the timer.

Parameters
[in]p_instancePointer to the driver instance structure.

◆ nrfx_timer_compare()

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

◆ nrfx_timer_compare_event_address_get()

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
[in]p_instancePointer to the driver instance structure.
[in]channelCompare channel number.
Returns
Event address.

◆ nrfx_timer_compare_int_disable()

void nrfx_timer_compare_int_disable ( nrfx_timer_t const * p_instance,
uint32_t channel )

Function for disabling timer compare interrupt.

Parameters
[in]p_instancePointer to the driver instance structure.
[in]channelCompare channel.

◆ nrfx_timer_compare_int_enable()

void nrfx_timer_compare_int_enable ( nrfx_timer_t const * p_instance,
uint32_t channel )

Function for enabling timer compare interrupt.

Parameters
[in]p_instancePointer to the driver instance structure.
[in]channelCompare channel.

◆ nrfx_timer_disable()

void nrfx_timer_disable ( nrfx_timer_t * 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
[in]p_instancePointer to the driver instance structure.

◆ nrfx_timer_enable()

void nrfx_timer_enable ( nrfx_timer_t * p_instance)

Function for turning on the timer.

Parameters
[in]p_instancePointer to the driver instance structure.

◆ nrfx_timer_event_address_get()

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
[in]p_instancePointer to the driver instance structure.
[in]timer_eventTimer event.
Returns
Event address.

◆ nrfx_timer_extended_compare()

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

◆ nrfx_timer_increment()

void nrfx_timer_increment ( nrfx_timer_t const * p_instance)

Function for incrementing the timer.

Parameters
[in]p_instancePointer to the driver instance structure.

◆ nrfx_timer_init()

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

Function for initializing the timer.

Parameters
[in]p_instancePointer to the driver instance structure.
[in]p_configPointer to the structure with the initial configuration.
[in]timer_event_handlerEvent handler provided by the user. Can be NULL.
Return values
0Initialization was successful.
-EINVALSpecified frequency is not supported by the TIMER instance.
-EALREADYThe driver is already initialized.

◆ nrfx_timer_init_check()

bool nrfx_timer_init_check ( nrfx_timer_t const * p_instance)

Function for checking if the TIMER driver instance is initialized.

Parameters
[in]p_instancePointer to the driver instance structure.
Return values
trueInstance is already initialized.
falseInstance is not initialized.

◆ nrfx_timer_irq_handler()

void nrfx_timer_irq_handler ( nrfx_timer_t const * p_instance)

Driver interrupt handler.

Parameters
[in]p_instancePointer to the driver instance structure.

◆ nrfx_timer_is_enabled()

bool nrfx_timer_is_enabled ( nrfx_timer_t const * p_instance)

Function for checking the timer state.

Parameters
[in]p_instancePointer to the driver instance structure.
Return values
trueTimer is enabled.
falseTimer is not enabled.

◆ nrfx_timer_ms_to_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
[in]p_instancePointer to the driver instance structure.
[in]time_msTime in milliseconds.
Returns
Number of ticks.

◆ nrfx_timer_pause()

void nrfx_timer_pause ( nrfx_timer_t const * p_instance)

Function for pausing the timer.

Parameters
[in]p_instancePointer to the driver instance structure.

◆ nrfx_timer_reconfigure()

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

Function for reconfiguring the timer.

Parameters
[in]p_instancePointer to the driver instance structure.
[in]p_configPointer to the structure with the configuration.
Return values
0Reconfiguration was successful.
-EINVALSpecified frequency is not supported by the TIMER instance.
-EINPROGRESSThe driver is uninitialized.
-EBUSYThe driver is enabled and cannot be reconfigured.

◆ nrfx_timer_resume()

void nrfx_timer_resume ( nrfx_timer_t const * p_instance)

Function for resuming the timer.

Parameters
[in]p_instancePointer to the driver instance structure.

◆ nrfx_timer_task_address_get()

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
[in]p_instancePointer to the driver instance structure.
[in]timer_taskTimer task.
Returns
Task address.

◆ nrfx_timer_uninit()

void nrfx_timer_uninit ( nrfx_timer_t * p_instance)

Function for uninitializing the timer.

Parameters
[in]p_instancePointer to the driver instance structure.

◆ nrfx_timer_us_to_ticks()

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
[in]p_instancePointer to the driver instance structure.
[in]time_usTime in microseconds.
Returns
Number of ticks.