nRF5 SDK v15.3.0
Modules | Data Structures | Macros | Typedefs | Enumerations | Functions
RTC driver

Real Timer Counter (RTC) peripheral driver. More...

Modules

 RTC peripheral driver configuration
 

Data Structures

struct  nrfx_rtc_t
 RTC driver instance structure. More...
 
struct  nrfx_rtc_config_t
 RTC driver instance configuration structure. More...
 

Macros

#define NRFX_RTC_US_TO_TICKS(us, freq)   (((us) * (freq)) / 1000000U)
 Macro to convert microseconds into ticks.
 
#define NRFX_RTC_INSTANCE(id)
 Macro for creating RTC driver instance. More...
 
#define NRFX_RTC_DEFAULT_CONFIG
 RTC instance default configuration. More...
 

Typedefs

typedef void(* nrfx_rtc_handler_t )(nrfx_rtc_int_type_t int_type)
 RTC driver instance handler type.
 

Enumerations

enum  nrfx_rtc_int_type_t {
  NRFX_RTC_INT_COMPARE0 = 0,
  NRFX_RTC_INT_COMPARE1 = 1,
  NRFX_RTC_INT_COMPARE2 = 2,
  NRFX_RTC_INT_COMPARE3 = 3,
  NRFX_RTC_INT_TICK = 4,
  NRFX_RTC_INT_OVERFLOW = 5
}
 RTC driver interrupt types. More...
 
enum  { NRFX_RTC_ENABLED_COUNT }
 

Functions

nrfx_err_t nrfx_rtc_init (nrfx_rtc_t const *const p_instance, nrfx_rtc_config_t const *p_config, nrfx_rtc_handler_t handler)
 Function for initializing the RTC driver instance. More...
 
void nrfx_rtc_uninit (nrfx_rtc_t const *const p_instance)
 Function for uninitializing the RTC driver instance. More...
 
void nrfx_rtc_enable (nrfx_rtc_t const *const p_instance)
 Function for enabling the RTC driver instance. More...
 
void nrfx_rtc_disable (nrfx_rtc_t const *const p_instance)
 Function for disabling the RTC driver instance. More...
 
nrfx_err_t nrfx_rtc_cc_set (nrfx_rtc_t const *const p_instance, uint32_t channel, uint32_t val, bool enable_irq)
 Function for setting a compare channel. More...
 
nrfx_err_t nrfx_rtc_cc_disable (nrfx_rtc_t const *const p_instance, uint32_t channel)
 Function for disabling a channel. More...
 
void nrfx_rtc_tick_enable (nrfx_rtc_t const *const p_instance, bool enable_irq)
 Function for enabling tick. More...
 
void nrfx_rtc_tick_disable (nrfx_rtc_t const *const p_instance)
 Function for disabling tick. More...
 
void nrfx_rtc_overflow_enable (nrfx_rtc_t const *const p_instance, bool enable_irq)
 Function for enabling overflow. More...
 
void nrfx_rtc_overflow_disable (nrfx_rtc_t const *const p_instance)
 Function for disabling overflow. More...
 
uint32_t nrfx_rtc_max_ticks_get (nrfx_rtc_t const *const p_instance)
 Function for getting the maximum relative ticks value that can be set in the compare channel. More...
 
__STATIC_INLINE void nrfx_rtc_int_disable (nrfx_rtc_t const *const p_instance, uint32_t *p_mask)
 Function for disabling all instance interrupts. More...
 
__STATIC_INLINE void nrfx_rtc_int_enable (nrfx_rtc_t const *const p_instance, uint32_t mask)
 Function for enabling instance interrupts. More...
 
__STATIC_INLINE uint32_t nrfx_rtc_counter_get (nrfx_rtc_t const *const p_instance)
 Function for retrieving the current counter value. More...
 
__STATIC_INLINE void nrfx_rtc_counter_clear (nrfx_rtc_t const *const p_instance)
 Function for clearing the counter value. More...
 
__STATIC_INLINE uint32_t nrfx_rtc_task_address_get (nrfx_rtc_t const *const p_instance, nrf_rtc_task_t task)
 Function for returning a requested task address for the RTC driver instance. More...
 
__STATIC_INLINE uint32_t nrfx_rtc_event_address_get (nrfx_rtc_t const *const p_instance, nrf_rtc_event_t event)
 Function for returning a requested event address for the RTC driver instance. More...
 
void nrfx_rtc_0_irq_handler (void)
 
void nrfx_rtc_1_irq_handler (void)
 
void nrfx_rtc_2_irq_handler (void)
 

Detailed Description

Real Timer Counter (RTC) peripheral driver.

Macro Definition Documentation

#define NRFX_RTC_DEFAULT_CONFIG
Value:

RTC instance default configuration.

#define NRFX_RTC_INSTANCE (   id)
Value:
{ \
.p_reg = NRFX_CONCAT_2(NRF_RTC, id), \
.irq = NRFX_CONCAT_3(RTC, id, _IRQn), \
.instance_id = NRFX_CONCAT_3(NRFX_RTC, id, _INST_IDX), \
.cc_channel_count = NRF_RTC_CC_CHANNEL_COUNT(id), \
}

Macro for creating RTC driver instance.

Enumeration Type Documentation

RTC driver interrupt types.

Enumerator
NRFX_RTC_INT_COMPARE0 

Interrupt from COMPARE0 event.

NRFX_RTC_INT_COMPARE1 

Interrupt from COMPARE1 event.

NRFX_RTC_INT_COMPARE2 

Interrupt from COMPARE2 event.

NRFX_RTC_INT_COMPARE3 

Interrupt from COMPARE3 event.

NRFX_RTC_INT_TICK 

Interrupt from TICK event.

NRFX_RTC_INT_OVERFLOW 

Interrupt from OVERFLOW event.

Function Documentation

nrfx_err_t nrfx_rtc_cc_disable ( nrfx_rtc_t const *const  p_instance,
uint32_t  channel 
)

Function for disabling a channel.

This function disables channel events and channel interrupts. The function asserts if the instance is not initialized or if the channel parameter is wrong.

Parameters
[in]p_instancePointer to the driver instance structure.
[in]channelOne of the instance's channels.
Return values
NRFX_SUCCESSIf the procedure was successful.
NRFX_ERROR_TIMEOUTIf an interrupt was pending on the requested channel.
nrfx_err_t nrfx_rtc_cc_set ( nrfx_rtc_t const *const  p_instance,
uint32_t  channel,
uint32_t  val,
bool  enable_irq 
)

Function for setting a compare channel.

The function asserts if the instance is not initialized or if the channel parameter is wrong. The function powers on the instance if the instance was in power off state.

The driver is not entering a critical section when configuring RTC, which means that it can be preempted for a certain amount of time. When the driver was preempted and the value to be set is short in time, there is a risk that the driver sets a compare value that is behind. If RTCn_CONFIG_RELIABLE is 1 for the given instance, the Reliable mode handles that case. However, to detect if the requested value is behind, this mode makes the following assumptions:

  • The maximum preemption time in ticks (8 - bit value) is known and is less than 7.7 ms (for prescaler = 0, RTC frequency 32 kHz).
  • The requested absolute compare value is not bigger than (0x00FFFFFF) - tick_latency. It is the user's responsibility to ensure that.
Parameters
[in]p_instancePointer to the driver instance structure.
[in]channelOne of the instance's channels.
[in]valAbsolute value to be set in the compare register.
[in]enable_irqTrue to enable the interrupt. False to disable the interrupt.
Return values
NRFX_SUCCESSIf the procedure was successful.
NRFX_ERROR_TIMEOUTIf the compare was not set because the request value is behind the current counter value. This error can only be reported if RTCn_CONFIG_RELIABLE = 1.
__STATIC_INLINE void nrfx_rtc_counter_clear ( nrfx_rtc_t const *const  p_instance)

Function for clearing the counter value.

This function asserts if the instance is not powered on.

Parameters
[in]p_instancePointer to the driver instance structure.
__STATIC_INLINE uint32_t nrfx_rtc_counter_get ( nrfx_rtc_t const *const  p_instance)

Function for retrieving the current counter value.

This function asserts if the instance is not powered on or if p_val is NULL.

Parameters
[in]p_instancePointer to the driver instance structure.
Return values
valueCounter value.
void nrfx_rtc_disable ( nrfx_rtc_t const *const  p_instance)

Function for disabling the RTC driver instance.

Note
Function asserts if instance is disabled.
Parameters
[in]p_instancePointer to the driver instance structure.
void nrfx_rtc_enable ( nrfx_rtc_t const *const  p_instance)

Function for enabling the RTC driver instance.

Note
Function asserts if instance is enabled.
Parameters
[in]p_instancePointer to the driver instance structure.
__STATIC_INLINE uint32_t nrfx_rtc_event_address_get ( nrfx_rtc_t const *const  p_instance,
nrf_rtc_event_t  event 
)

Function for returning a requested event address for the RTC driver instance.

This function asserts if the output pointer is NULL. The event address can be used by the PPI module.

Parameters
[in]p_instancePointer to the driver instance structure.
[in]eventOne of the peripheral events.
Return values
Addressof event register.
nrfx_err_t nrfx_rtc_init ( nrfx_rtc_t const *const  p_instance,
nrfx_rtc_config_t const *  p_config,
nrfx_rtc_handler_t  handler 
)

Function for initializing the RTC driver instance.

After initialization, the instance is in power off state.

Parameters
[in]p_instancePointer to the driver instance structure.
[in]p_configPointer to the structure with initial configuration.
[in]handlerEvent handler provided by the user. Must not be NULL.
Return values
NRFX_SUCCESSIf successfully initialized.
NRFX_ERROR_INVALID_STATEIf the instance is already initialized.
__STATIC_INLINE void nrfx_rtc_int_disable ( nrfx_rtc_t const *const  p_instance,
uint32_t *  p_mask 
)

Function for disabling all instance interrupts.

Parameters
[in]p_instancePointer to the driver instance structure.
[in]p_maskPointer to the location where the mask is filled.
__STATIC_INLINE void nrfx_rtc_int_enable ( nrfx_rtc_t const *const  p_instance,
uint32_t  mask 
)

Function for enabling instance interrupts.

Parameters
[in]p_instancePointer to the driver instance structure.
[in]maskMask of interrupts to enable.
uint32_t nrfx_rtc_max_ticks_get ( nrfx_rtc_t const *const  p_instance)

Function for getting the maximum relative ticks value that can be set in the compare channel.

When a stack (for example SoftDevice) is used and it occupies high priority interrupts, the application code can be interrupted at any moment for a certain period of time. If Reliable mode is enabled, the provided maximum latency is taken into account and the return value is smaller than the RTC counter resolution. If Reliable mode is disabled, the return value equals the counter resolution.

Parameters
[in]p_instancePointer to the driver instance structure.
Return values
ticksMaximum ticks value.
void nrfx_rtc_overflow_disable ( nrfx_rtc_t const *const  p_instance)

Function for disabling overflow.

This function disables the overflow event and interrupt.

Parameters
[in]p_instancePointer to the driver instance structure.
void nrfx_rtc_overflow_enable ( nrfx_rtc_t const *const  p_instance,
bool  enable_irq 
)

Function for enabling overflow.

This function enables the overflow event and optionally the interrupt. The function asserts if the instance is not powered on.

Parameters
[in]p_instancePointer to the driver instance structure.
[in]enable_irqTrue to enable the interrupt. False to disable the interrupt.
__STATIC_INLINE uint32_t nrfx_rtc_task_address_get ( nrfx_rtc_t const *const  p_instance,
nrf_rtc_task_t  task 
)

Function for returning a requested task address for the RTC driver instance.

This function asserts if the output pointer is NULL. The task address can be used by the PPI module.

Parameters
[in]p_instancePointer to the instance.
[in]taskOne of the peripheral tasks.
Return values
Addressof task register.
void nrfx_rtc_tick_disable ( nrfx_rtc_t const *const  p_instance)

Function for disabling tick.

This function disables the tick event and interrupt.

Parameters
[in]p_instancePointer to the driver instance structure.
void nrfx_rtc_tick_enable ( nrfx_rtc_t const *const  p_instance,
bool  enable_irq 
)

Function for enabling tick.

This function enables the tick event and optionally the interrupt. The function asserts if the instance is not powered on.

Parameters
[in]p_instancePointer to the driver instance structure.
[in]enable_irqTrue to enable the interrupt. False to disable the interrupt.
void nrfx_rtc_uninit ( nrfx_rtc_t const *const  p_instance)

Function for uninitializing the RTC driver instance.

After uninitialization, the instance is in idle state. The hardware should return to the state before initialization. The function asserts if the instance is in idle state.

Parameters
[in]p_instancePointer to the driver instance structure.

Documentation feedback | Developer Zone | Subscribe | Updated