nRF5 SDK v11.0.0
Macros | Enumerations | Functions

Hardware access layer for accessing the timer peripheral. More...

Macros

#define NRF_TIMER_IS_BIT_WIDTH_VALID(p_timer, bit_width)   ((p_timer == NRF_TIMER0) || (bit_width <= NRF_TIMER_BIT_WIDTH_16))
 Macro for validating the correctness of the BIT_WIDTH setting. More...
 
#define NRF_TIMER_CC_CHANNEL_COUNT(id)   4
 Macro for getting the number of capture/compare channels available in a given timer instance.
 

Enumerations

enum  nrf_timer_task_t {
  NRF_TIMER_TASK_START = offsetof(NRF_TIMER_Type, TASKS_START),
  NRF_TIMER_TASK_STOP = offsetof(NRF_TIMER_Type, TASKS_STOP),
  NRF_TIMER_TASK_COUNT = offsetof(NRF_TIMER_Type, TASKS_COUNT),
  NRF_TIMER_TASK_CLEAR = offsetof(NRF_TIMER_Type, TASKS_CLEAR),
  NRF_TIMER_TASK_SHUTDOWN = offsetof(NRF_TIMER_Type, TASKS_SHUTDOWN),
  NRF_TIMER_TASK_CAPTURE0 = offsetof(NRF_TIMER_Type, TASKS_CAPTURE[0]),
  NRF_TIMER_TASK_CAPTURE1 = offsetof(NRF_TIMER_Type, TASKS_CAPTURE[1]),
  NRF_TIMER_TASK_CAPTURE2 = offsetof(NRF_TIMER_Type, TASKS_CAPTURE[2]),
  NRF_TIMER_TASK_CAPTURE3 = offsetof(NRF_TIMER_Type, TASKS_CAPTURE[3])
}
 Timer tasks. More...
 
enum  nrf_timer_event_t {
  NRF_TIMER_EVENT_COMPARE0 = offsetof(NRF_TIMER_Type, EVENTS_COMPARE[0]),
  NRF_TIMER_EVENT_COMPARE1 = offsetof(NRF_TIMER_Type, EVENTS_COMPARE[1]),
  NRF_TIMER_EVENT_COMPARE2 = offsetof(NRF_TIMER_Type, EVENTS_COMPARE[2]),
  NRF_TIMER_EVENT_COMPARE3 = offsetof(NRF_TIMER_Type, EVENTS_COMPARE[3])
}
 Timer events. More...
 
enum  nrf_timer_short_mask_t {
  NRF_TIMER_SHORT_COMPARE0_STOP_MASK = TIMER_SHORTS_COMPARE0_STOP_Msk,
  NRF_TIMER_SHORT_COMPARE1_STOP_MASK = TIMER_SHORTS_COMPARE1_STOP_Msk,
  NRF_TIMER_SHORT_COMPARE2_STOP_MASK = TIMER_SHORTS_COMPARE2_STOP_Msk,
  NRF_TIMER_SHORT_COMPARE3_STOP_MASK = TIMER_SHORTS_COMPARE3_STOP_Msk,
  NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK = TIMER_SHORTS_COMPARE0_CLEAR_Msk,
  NRF_TIMER_SHORT_COMPARE1_CLEAR_MASK = TIMER_SHORTS_COMPARE1_CLEAR_Msk,
  NRF_TIMER_SHORT_COMPARE2_CLEAR_MASK = TIMER_SHORTS_COMPARE2_CLEAR_Msk,
  NRF_TIMER_SHORT_COMPARE3_CLEAR_MASK = TIMER_SHORTS_COMPARE3_CLEAR_Msk
}
 Types of timer shortcuts. More...
 
enum  nrf_timer_mode_t {
  NRF_TIMER_MODE_TIMER = TIMER_MODE_MODE_Timer,
  NRF_TIMER_MODE_COUNTER = TIMER_MODE_MODE_Counter
}
 Timer modes. More...
 
enum  nrf_timer_bit_width_t {
  NRF_TIMER_BIT_WIDTH_8 = TIMER_BITMODE_BITMODE_08Bit,
  NRF_TIMER_BIT_WIDTH_16 = TIMER_BITMODE_BITMODE_16Bit,
  NRF_TIMER_BIT_WIDTH_24 = TIMER_BITMODE_BITMODE_24Bit,
  NRF_TIMER_BIT_WIDTH_32 = TIMER_BITMODE_BITMODE_32Bit
}
 Timer bit width. More...
 
enum  nrf_timer_frequency_t {
  NRF_TIMER_FREQ_16MHz = 0,
  NRF_TIMER_FREQ_8MHz,
  NRF_TIMER_FREQ_4MHz,
  NRF_TIMER_FREQ_2MHz,
  NRF_TIMER_FREQ_1MHz,
  NRF_TIMER_FREQ_500kHz,
  NRF_TIMER_FREQ_250kHz,
  NRF_TIMER_FREQ_125kHz,
  NRF_TIMER_FREQ_62500Hz,
  NRF_TIMER_FREQ_31250Hz
}
 Timer prescalers. More...
 
enum  nrf_timer_cc_channel_t {
  NRF_TIMER_CC_CHANNEL0 = 0,
  NRF_TIMER_CC_CHANNEL1,
  NRF_TIMER_CC_CHANNEL2,
  NRF_TIMER_CC_CHANNEL3
}
 Timer capture/compare channels. More...
 
enum  nrf_timer_int_mask_t {
  NRF_TIMER_INT_COMPARE0_MASK = TIMER_INTENSET_COMPARE0_Msk,
  NRF_TIMER_INT_COMPARE1_MASK = TIMER_INTENSET_COMPARE1_Msk,
  NRF_TIMER_INT_COMPARE2_MASK = TIMER_INTENSET_COMPARE2_Msk,
  NRF_TIMER_INT_COMPARE3_MASK = TIMER_INTENSET_COMPARE3_Msk
}
 Timer interrupts. More...
 

Functions

__STATIC_INLINE void nrf_timer_task_trigger (NRF_TIMER_Type *p_timer, nrf_timer_task_t task)
 Function for activating a specific timer task. More...
 
__STATIC_INLINE uint32_t * nrf_timer_task_address_get (NRF_TIMER_Type *p_timer, nrf_timer_task_t task)
 Function for getting the address of a specific timer task register. More...
 
__STATIC_INLINE void nrf_timer_event_clear (NRF_TIMER_Type *p_timer, nrf_timer_event_t event)
 Function for clearing a specific timer event. More...
 
__STATIC_INLINE bool nrf_timer_event_check (NRF_TIMER_Type *p_timer, nrf_timer_event_t event)
 Function for checking the state of a specific timer event. More...
 
__STATIC_INLINE uint32_t * nrf_timer_event_address_get (NRF_TIMER_Type *p_timer, nrf_timer_event_t event)
 Function for getting the address of a specific timer event register. More...
 
__STATIC_INLINE void nrf_timer_shorts_enable (NRF_TIMER_Type *p_timer, uint32_t timer_shorts_mask)
 Function for enabling specified shortcuts. More...
 
__STATIC_INLINE void nrf_timer_shorts_disable (NRF_TIMER_Type *p_timer, uint32_t timer_shorts_mask)
 Function for disabling specified shortcuts. More...
 
__STATIC_INLINE void nrf_timer_int_enable (NRF_TIMER_Type *p_timer, uint32_t timer_int_mask)
 Function for enabling specified interrupts. More...
 
__STATIC_INLINE void nrf_timer_int_disable (NRF_TIMER_Type *p_timer, uint32_t timer_int_mask)
 Function for disabling specified interrupts. More...
 
__STATIC_INLINE bool nrf_timer_int_enable_check (NRF_TIMER_Type *p_timer, uint32_t timer_int)
 Function for retrieving the state of a given interrupt. More...
 
__STATIC_INLINE void nrf_timer_mode_set (NRF_TIMER_Type *p_timer, nrf_timer_mode_t mode)
 Function for setting the timer mode. More...
 
__STATIC_INLINE nrf_timer_mode_t nrf_timer_mode_get (NRF_TIMER_Type *p_timer)
 Function for retrieving the timer mode. More...
 
__STATIC_INLINE void nrf_timer_bit_width_set (NRF_TIMER_Type *p_timer, nrf_timer_bit_width_t bit_width)
 Function for setting the timer bit width. More...
 
__STATIC_INLINE
nrf_timer_bit_width_t 
nrf_timer_bit_width_get (NRF_TIMER_Type *p_timer)
 Function for retrieving the timer bit width. More...
 
__STATIC_INLINE void nrf_timer_frequency_set (NRF_TIMER_Type *p_timer, nrf_timer_frequency_t frequency)
 Function for setting the timer frequency. More...
 
__STATIC_INLINE
nrf_timer_frequency_t 
nrf_timer_frequency_get (NRF_TIMER_Type *p_timer)
 Function for retrieving the timer frequency. More...
 
__STATIC_INLINE void nrf_timer_cc_write (NRF_TIMER_Type *p_timer, nrf_timer_cc_channel_t cc_channel, uint32_t cc_value)
 Function for writing the capture/compare register for a specified channel. More...
 
__STATIC_INLINE uint32_t nrf_timer_cc_read (NRF_TIMER_Type *p_timer, nrf_timer_cc_channel_t cc_channel)
 Function for retrieving the capture/compare value for a specified channel. More...
 
__STATIC_INLINE nrf_timer_task_t nrf_timer_capture_task_get (uint32_t channel)
 Function for getting a specific timer capture task. More...
 
__STATIC_INLINE nrf_timer_event_t nrf_timer_compare_event_get (uint32_t channel)
 Function for getting a specific timer compare event. More...
 
__STATIC_INLINE
nrf_timer_int_mask_t 
nrf_timer_compare_int_get (uint32_t channel)
 Function for getting a specific timer compare interrupt. More...
 
__STATIC_INLINE uint32_t nrf_timer_us_to_ticks (uint32_t time_us, nrf_timer_frequency_t frequency)
 Function for calculating the number of timer ticks for a given time (in microseconds) and timer frequency. More...
 
__STATIC_INLINE uint32_t nrf_timer_ms_to_ticks (uint32_t time_ms, nrf_timer_frequency_t frequency)
 Function for calculating the number of timer ticks for a given time (in milliseconds) and timer frequency. More...
 

Detailed Description

Hardware access layer for accessing the timer peripheral.

Macro Definition Documentation

#define NRF_TIMER_IS_BIT_WIDTH_VALID (   p_timer,
  bit_width 
)    ((p_timer == NRF_TIMER0) || (bit_width <= NRF_TIMER_BIT_WIDTH_16))

Macro for validating the correctness of the BIT_WIDTH setting.

In the nRF51 Series, timer instance 0 supports all available bit widths. The other two instances support only 8 and 16 bits.

Enumeration Type Documentation

Timer bit width.

Enumerator
NRF_TIMER_BIT_WIDTH_8 

Timer bit width 8 bit.

NRF_TIMER_BIT_WIDTH_16 

Timer bit width 16 bit.

NRF_TIMER_BIT_WIDTH_24 

Timer bit width 24 bit.

NRF_TIMER_BIT_WIDTH_32 

Timer bit width 32 bit.

Timer capture/compare channels.

Enumerator
NRF_TIMER_CC_CHANNEL0 

Timer capture/compare channel 0.

NRF_TIMER_CC_CHANNEL1 

Timer capture/compare channel 1.

NRF_TIMER_CC_CHANNEL2 

Timer capture/compare channel 2.

NRF_TIMER_CC_CHANNEL3 

Timer capture/compare channel 3.

Timer events.

Enumerator
NRF_TIMER_EVENT_COMPARE0 

Event from compare channel 0.

NRF_TIMER_EVENT_COMPARE1 

Event from compare channel 1.

NRF_TIMER_EVENT_COMPARE2 

Event from compare channel 2.

NRF_TIMER_EVENT_COMPARE3 

Event from compare channel 3.

Timer prescalers.

Enumerator
NRF_TIMER_FREQ_16MHz 

Timer frequency 16 MHz.

NRF_TIMER_FREQ_8MHz 

Timer frequency 8 MHz.

NRF_TIMER_FREQ_4MHz 

Timer frequency 4 MHz.

NRF_TIMER_FREQ_2MHz 

Timer frequency 2 MHz.

NRF_TIMER_FREQ_1MHz 

Timer frequency 1 MHz.

NRF_TIMER_FREQ_500kHz 

Timer frequency 500 kHz.

NRF_TIMER_FREQ_250kHz 

Timer frequency 250 kHz.

NRF_TIMER_FREQ_125kHz 

Timer frequency 125 kHz.

NRF_TIMER_FREQ_62500Hz 

Timer frequency 62500 Hz.

NRF_TIMER_FREQ_31250Hz 

Timer frequency 31250 Hz.

Timer interrupts.

Enumerator
NRF_TIMER_INT_COMPARE0_MASK 

Timer interrupt from compare event on channel 0.

NRF_TIMER_INT_COMPARE1_MASK 

Timer interrupt from compare event on channel 1.

NRF_TIMER_INT_COMPARE2_MASK 

Timer interrupt from compare event on channel 2.

NRF_TIMER_INT_COMPARE3_MASK 

Timer interrupt from compare event on channel 3.

Timer modes.

Enumerator
NRF_TIMER_MODE_TIMER 

Timer mode: timer.

NRF_TIMER_MODE_COUNTER 

Timer mode: counter.

Types of timer shortcuts.

Enumerator
NRF_TIMER_SHORT_COMPARE0_STOP_MASK 

Shortcut for stopping the timer based on compare 0.

NRF_TIMER_SHORT_COMPARE1_STOP_MASK 

Shortcut for stopping the timer based on compare 1.

NRF_TIMER_SHORT_COMPARE2_STOP_MASK 

Shortcut for stopping the timer based on compare 2.

NRF_TIMER_SHORT_COMPARE3_STOP_MASK 

Shortcut for stopping the timer based on compare 3.

NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK 

Shortcut for clearing the timer based on compare 0.

NRF_TIMER_SHORT_COMPARE1_CLEAR_MASK 

Shortcut for clearing the timer based on compare 1.

NRF_TIMER_SHORT_COMPARE2_CLEAR_MASK 

Shortcut for clearing the timer based on compare 2.

NRF_TIMER_SHORT_COMPARE3_CLEAR_MASK 

Shortcut for clearing the timer based on compare 3.

Timer tasks.

Enumerator
NRF_TIMER_TASK_START 

Task for starting the timer.

NRF_TIMER_TASK_STOP 

Task for stopping the timer.

NRF_TIMER_TASK_COUNT 

Task for incrementing the timer (in counter mode).

NRF_TIMER_TASK_CLEAR 

Task for resetting the timer value.

NRF_TIMER_TASK_SHUTDOWN 

Task for powering off the timer.

NRF_TIMER_TASK_CAPTURE0 

Task for capturing the timer value on channel 0.

NRF_TIMER_TASK_CAPTURE1 

Task for capturing the timer value on channel 1.

NRF_TIMER_TASK_CAPTURE2 

Task for capturing the timer value on channel 2.

NRF_TIMER_TASK_CAPTURE3 

Task for capturing the timer value on channel 3.

Function Documentation

__STATIC_INLINE nrf_timer_bit_width_t nrf_timer_bit_width_get ( NRF_TIMER_Type *  p_timer)

Function for retrieving the timer bit width.

Parameters
[in]p_timerTimer instance.
Returns
Timer bit width.
__STATIC_INLINE void nrf_timer_bit_width_set ( NRF_TIMER_Type *  p_timer,
nrf_timer_bit_width_t  bit_width 
)

Function for setting the timer bit width.

Parameters
[in]p_timerTimer instance.
[in]bit_widthTimer bit width.
__STATIC_INLINE nrf_timer_task_t nrf_timer_capture_task_get ( uint32_t  channel)

Function for getting a specific timer capture task.

Parameters
[in]channelCapture channel.
Returns
Capture task.
__STATIC_INLINE uint32_t nrf_timer_cc_read ( NRF_TIMER_Type *  p_timer,
nrf_timer_cc_channel_t  cc_channel 
)

Function for retrieving the capture/compare value for a specified channel.

Parameters
[in]p_timerTimer instance.
[in]cc_channelRequested capture/compare channel.
Returns
Value from the requested capture/compare register.
__STATIC_INLINE void nrf_timer_cc_write ( NRF_TIMER_Type *  p_timer,
nrf_timer_cc_channel_t  cc_channel,
uint32_t  cc_value 
)

Function for writing the capture/compare register for a specified channel.

Parameters
[in]p_timerTimer instance.
[in]cc_channelRequested capture/compare channel.
[in]cc_valueValue to write to the capture/compare register.
__STATIC_INLINE nrf_timer_event_t nrf_timer_compare_event_get ( uint32_t  channel)

Function for getting a specific timer compare event.

Parameters
[in]channelCompare channel.
Returns
Compare event.
__STATIC_INLINE nrf_timer_int_mask_t nrf_timer_compare_int_get ( uint32_t  channel)

Function for getting a specific timer compare interrupt.

Parameters
[in]channelCompare channel.
Returns
Compare interrupt.
__STATIC_INLINE uint32_t* nrf_timer_event_address_get ( NRF_TIMER_Type *  p_timer,
nrf_timer_event_t  event 
)

Function for getting the address of a specific timer event register.

Parameters
[in]p_timerTimer instance.
[in]eventRequested event.
Returns
Address of the specified event register.
__STATIC_INLINE bool nrf_timer_event_check ( NRF_TIMER_Type *  p_timer,
nrf_timer_event_t  event 
)

Function for checking the state of a specific timer event.

Parameters
[in]p_timerTimer instance.
[in]eventEvent to check.
Return values
trueIf the event is set.
falseIf the event is not set.
__STATIC_INLINE void nrf_timer_event_clear ( NRF_TIMER_Type *  p_timer,
nrf_timer_event_t  event 
)

Function for clearing a specific timer event.

Parameters
[in]p_timerTimer instance.
[in]eventEvent to clear.
__STATIC_INLINE nrf_timer_frequency_t nrf_timer_frequency_get ( NRF_TIMER_Type *  p_timer)

Function for retrieving the timer frequency.

Parameters
[in]p_timerTimer instance.
Returns
Timer frequency.
__STATIC_INLINE void nrf_timer_frequency_set ( NRF_TIMER_Type *  p_timer,
nrf_timer_frequency_t  frequency 
)

Function for setting the timer frequency.

Parameters
[in]p_timerTimer instance.
[in]frequencyTimer frequency.
__STATIC_INLINE void nrf_timer_int_disable ( NRF_TIMER_Type *  p_timer,
uint32_t  timer_int_mask 
)

Function for disabling specified interrupts.

Parameters
[in]p_timerTimer instance.
[in]timer_int_maskInterrupts to disable.
__STATIC_INLINE void nrf_timer_int_enable ( NRF_TIMER_Type *  p_timer,
uint32_t  timer_int_mask 
)

Function for enabling specified interrupts.

Parameters
[in]p_timerTimer instance.
[in]timer_int_maskInterrupts to enable.
__STATIC_INLINE bool nrf_timer_int_enable_check ( NRF_TIMER_Type *  p_timer,
uint32_t  timer_int 
)

Function for retrieving the state of a given interrupt.

Parameters
[in]p_timerTimer instance.
[in]timer_intInterrupt to check.
Return values
trueIf the interrupt is enabled.
falseIf the interrupt is not enabled.
__STATIC_INLINE nrf_timer_mode_t nrf_timer_mode_get ( NRF_TIMER_Type *  p_timer)

Function for retrieving the timer mode.

Parameters
[in]p_timerTimer instance.
Returns
Timer mode.
__STATIC_INLINE void nrf_timer_mode_set ( NRF_TIMER_Type *  p_timer,
nrf_timer_mode_t  mode 
)

Function for setting the timer mode.

Parameters
[in]p_timerTimer instance.
[in]modeTimer mode.
__STATIC_INLINE uint32_t nrf_timer_ms_to_ticks ( uint32_t  time_ms,
nrf_timer_frequency_t  frequency 
)

Function for calculating the number of timer ticks for a given time (in milliseconds) and timer frequency.

Parameters
[in]time_msTime in milliseconds.
[in]frequencyTimer frequency.
Returns
Number of timer ticks.
__STATIC_INLINE void nrf_timer_shorts_disable ( NRF_TIMER_Type *  p_timer,
uint32_t  timer_shorts_mask 
)

Function for disabling specified shortcuts.

Parameters
[in]p_timerTimer instance.
[in]timer_shorts_maskShortcuts to disable.
__STATIC_INLINE void nrf_timer_shorts_enable ( NRF_TIMER_Type *  p_timer,
uint32_t  timer_shorts_mask 
)

Function for enabling specified shortcuts.

Parameters
[in]p_timerTimer instance.
[in]timer_shorts_maskShortcuts to enable.
__STATIC_INLINE uint32_t* nrf_timer_task_address_get ( NRF_TIMER_Type *  p_timer,
nrf_timer_task_t  task 
)

Function for getting the address of a specific timer task register.

Parameters
[in]p_timerTimer instance.
[in]taskRequested task.
Returns
Address of the specified task register.
__STATIC_INLINE void nrf_timer_task_trigger ( NRF_TIMER_Type *  p_timer,
nrf_timer_task_t  task 
)

Function for activating a specific timer task.

Parameters
[in]p_timerTimer instance.
[in]taskTask to activate.
__STATIC_INLINE uint32_t nrf_timer_us_to_ticks ( uint32_t  time_us,
nrf_timer_frequency_t  frequency 
)

Function for calculating the number of timer ticks for a given time (in microseconds) and timer frequency.

Parameters
[in]time_usTime in microseconds.
[in]frequencyTimer frequency.
Returns
Number of timer ticks.

Documentation feedback | Developer Zone | Updated