nRF5 SDK v15.0.0
Data Structures | Macros | Typedefs | Enumerations | Functions

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

Data Structures

struct  drv_rtc_t
 RTC driver instance structure. More...
 
struct  drv_rtc_config_t
 RTC driver instance configuration structure. More...
 

Macros

#define DRV_RTC_MAX_CNT   RTC_COUNTER_COUNTER_Msk
 Maximum RTC counter value.
 
#define DRV_RTC_CONFIG_APPLY_TIME_US   33
 Time requires to update registers between RTC and MCU domains.
 
#define DRV_RTC_MIN_TICK_HANDLED   3
 Minimum delta value between set value and counter value. More...
 
#define DRV_RTC_US_TO_TICKS(us, freq)
 Macro to convert microseconds into ticks. More...
 
#define DRV_RTC_INSTANCE(id)
 Macro for creating RTC driver instance. More...
 
#define DRV_RTC_DEFAULT_CONFIG
 RTC instance default configuration. More...
 

Typedefs

typedef void(* drv_rtc_handler_t )(drv_rtc_t const *const p_instance)
 RTC driver instance handler type.
 

Enumerations

enum  { DRV_RTC_ENABLED_COUNT }
 

Functions

ret_code_t drv_rtc_init (drv_rtc_t const *const p_instance, drv_rtc_config_t const *p_config, drv_rtc_handler_t handler)
 Function for initializing the RTC driver instance. More...
 
void drv_rtc_uninit (drv_rtc_t const *const p_instance)
 Function for uninitializing the RTC driver instance. More...
 
void drv_rtc_start (drv_rtc_t const *const p_instance)
 Function for starting RTC clock. More...
 
void drv_rtc_stop (drv_rtc_t const *const p_instance)
 Function for stopping RTC clock. More...
 
void drv_rtc_compare_set (drv_rtc_t const *const p_instance, uint32_t cc, uint32_t abs_value, bool irq_enable)
 Function for configuring compare channel. More...
 
ret_code_t drv_rtc_windowed_compare_set (drv_rtc_t const *const p_instance, uint32_t cc, uint32_t abs_value, uint16_t safe_window)
 Function for configuring compare channel with safe window. More...
 
void drv_rtc_overflow_enable (drv_rtc_t const *const p_instance, bool irq_enable)
 Function for enabling overflow event and interrupt. More...
 
void drv_rtc_overflow_disable (drv_rtc_t const *const p_instance)
 Function for diabling overflow event and interrupt. More...
 
bool drv_rtc_overflow_pending (drv_rtc_t const *const p_instance)
 Function for checking if overflow event has occured. More...
 
void drv_rtc_tick_enable (drv_rtc_t const *const p_instance, bool irq_enable)
 Function for enabling tick event and interrupt. More...
 
void drv_rtc_tick_disable (drv_rtc_t const *const p_instance)
 Function for disabling tick event and interrupt. More...
 
bool drv_rtc_tick_pending (drv_rtc_t const *const p_instance)
 Function for checking if tick event has occured. More...
 
void drv_rtc_compare_enable (drv_rtc_t const *const p_instance, uint32_t cc, bool irq_enable)
 Function for enabling compare channel event and interrupt. More...
 
void drv_rtc_compare_disable (drv_rtc_t const *const p_instance, uint32_t cc)
 Function for disabling compare channel event and interrupt. More...
 
bool drv_rtc_compare_pending (drv_rtc_t const *const p_instance, uint32_t cc)
 Function for checking if compare channel event has occured. More...
 
uint32_t drv_rtc_counter_get (drv_rtc_t const *const p_instance)
 Function for getting current value of RTC counter. More...
 
void drv_rtc_irq_trigger (drv_rtc_t const *const p_instance)
 Function for triggering RTC interrupt. More...
 

Detailed Description

Real Timer Counter (RTC) peripheral driver for app_timer.

Macro Definition Documentation

#define DRV_RTC_DEFAULT_CONFIG
Value:
{ \
.prescaler = RTC_FREQ_TO_PRESCALER(DRV_RTC_DEFAULT_CONFIG_FREQUENCY), \
.interrupt_priority = DRV_RTC_DEFAULT_CONFIG_IRQ_PRIORITY, \
}

RTC instance default configuration.

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

Macro for creating RTC driver instance.

#define DRV_RTC_MIN_TICK_HANDLED   3

Minimum delta value between set value and counter value.

RTC peripheral requires two ticks to be sure that value it properly set in RTC value. Compare channel function requires additional one tick to avoid problematic situations (lack or additional unspecified event) when Compare Channel register is reseting or setting to N+2 value.

#define DRV_RTC_US_TO_TICKS (   us,
  freq 
)
Value:
(us >= 2^17 ? \
((((us)/1000)*(freq))/1000U) : (((us)*(freq))/1000000U) )

Macro to convert microseconds into ticks.

Function Documentation

void drv_rtc_compare_disable ( drv_rtc_t const *const  p_instance,
uint32_t  cc 
)

Function for disabling compare channel event and interrupt.

Parameters
[in]p_instancePointer to the driver instance structure.
[in]ccCompare channel index.
void drv_rtc_compare_enable ( drv_rtc_t const *const  p_instance,
uint32_t  cc,
bool  irq_enable 
)

Function for enabling compare channel event and interrupt.

Parameters
[in]p_instancePointer to the driver instance structure.
[in]ccCompare channel index.
[in]irq_enableTrue to enable interrupt.
bool drv_rtc_compare_pending ( drv_rtc_t const *const  p_instance,
uint32_t  cc 
)

Function for checking if compare channel event has occured.

Parameters
[in]p_instancePointer to the driver instance structure.
[in]ccCompare channel index.
Returns
True if interrupt pending, false otherwise.
void drv_rtc_compare_set ( drv_rtc_t const *const  p_instance,
uint32_t  cc,
uint32_t  abs_value,
bool  irq_enable 
)

Function for configuring compare channel.

Note
Function disables interrupts and only enable compare events. Remember to enable interrupt using drv_rtc_compare_enable in case of using it.
Parameters
[in]p_instancePointer to the driver instance structure.
[in]ccCompare channel index.
[in]abs_valueAbsolute value to be set in the compare register.
[in]irq_enableTrue to enable interrupt.
uint32_t drv_rtc_counter_get ( drv_rtc_t const *const  p_instance)

Function for getting current value of RTC counter.

Parameters
[in]p_instancePointer to the driver instance structure.
Returns
Counter value.
ret_code_t drv_rtc_init ( drv_rtc_t const *const  p_instance,
drv_rtc_config_t const *  p_config,
drv_rtc_handler_t  handler 
)

Function for initializing the RTC driver instance.

After initialization, the instance is in power off state. The LFCLK (CLOCK driver) has to be started before using RTC driver.

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
NRF_SUCCESSIf successfully initialized.
NRF_ERROR_INVALID_STATEIf the instance is already initialized.
void drv_rtc_irq_trigger ( drv_rtc_t const *const  p_instance)

Function for triggering RTC interrupt.

Parameters
[in]p_instancePointer to the driver instance structure.
void drv_rtc_overflow_disable ( drv_rtc_t const *const  p_instance)

Function for diabling overflow event and interrupt.

Parameters
[in]p_instancePointer to the driver instance structure.
void drv_rtc_overflow_enable ( drv_rtc_t const *const  p_instance,
bool  irq_enable 
)

Function for enabling overflow event and interrupt.

Parameters
[in]p_instancePointer to the driver instance structure.
[in]irq_enableTrue to enable interrupt.
bool drv_rtc_overflow_pending ( drv_rtc_t const *const  p_instance)

Function for checking if overflow event has occured.

Note
Event is cleared after reading.
Parameters
[in]p_instancePointer to the driver instance structure.
Returns
True if interrupt pending, false otherwise.
void drv_rtc_start ( drv_rtc_t const *const  p_instance)

Function for starting RTC clock.

Parameters
[in]p_instancePointer to the driver instance structure.
void drv_rtc_stop ( drv_rtc_t const *const  p_instance)

Function for stopping RTC clock.

Parameters
[in]p_instancePointer to the driver instance structure.
void drv_rtc_tick_disable ( drv_rtc_t const *const  p_instance)

Function for disabling tick event and interrupt.

Parameters
[in]p_instancePointer to the driver instance structure.
void drv_rtc_tick_enable ( drv_rtc_t const *const  p_instance,
bool  irq_enable 
)

Function for enabling tick event and interrupt.

Parameters
[in]p_instancePointer to the driver instance structure.
[in]irq_enableTrue to enable interrupt.
bool drv_rtc_tick_pending ( drv_rtc_t const *const  p_instance)

Function for checking if tick event has occured.

Parameters
[in]p_instancePointer to the driver instance structure.
Returns
True if interrupt pending, false otherwise.
void drv_rtc_uninit ( drv_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.
ret_code_t drv_rtc_windowed_compare_set ( drv_rtc_t const *const  p_instance,
uint32_t  cc,
uint32_t  abs_value,
uint16_t  safe_window 
)

Function for configuring compare channel with safe window.

Maximum possible relative value is limited by safe window to detect cases when requested compare event has already occured.

Parameters
[in]p_instancePointer to the driver instance structure.
[in]ccCompare channel index.
[in]abs_valueAbsolute value to be set in the compare register.
[in]safe_windowWidth of the safe window.
Return values
NRF_ERROR_TIMEOUTIf
abs_value is in safe window of event occured before
enabling compare channel intterupt.
Return values
NRF_SUCCESSIf successfully set.

Documentation feedback | Developer Zone | Subscribe | Updated