48 #if RUUVI_NRF5_SDK15_RTC_ENABLED
55 static inline void LOGW (
const char *
const msg)
60 #ifdef NRF5_SDK15_RTC_INSTANCE
61 #include "nrf_drv_rtc.h"
62 #include "nrf_drv_clock.h"
70 const nrf_drv_rtc_t rtc = NRF_DRV_RTC_INSTANCE (NRF5_SDK15_RTC_INSTANCE);
71 static uint64_t ticks = 0;
72 static bool m_is_init =
false;
77 static void rtc_handler (nrf_drv_rtc_int_type_t int_type)
79 if (int_type == NRF_DRV_RTC_INT_OVERFLOW)
95 ret_code_t err_code = NRF_SUCCESS;
98 if (
false == nrf_drv_clock_init_check()) { err_code |= nrf_drv_clock_init(); }
101 nrf_drv_clock_lfclk_request (NULL);
102 nrf_drv_rtc_config_t config = NRF_DRV_RTC_DEFAULT_CONFIG;
103 config.prescaler = 0;
105 err_code = nrf_drv_rtc_init (&rtc, &config, rtc_handler);
107 nrf_drv_rtc_enable (&rtc);
108 nrf_drv_rtc_counter_clear (&rtc);
109 nrf_drv_rtc_overflow_enable (&rtc,
true);
111 if (NRF_SUCCESS == err_code) { m_is_init =
true; }
123 if (
true == m_is_init)
126 nrf_drv_rtc_uninit (&rtc);
127 nrf_drv_clock_lfclk_release();
140 uint64_t ms = nrf_drv_rtc_counter_get (&rtc) + ticks;
141 return ( (ms * 1000) / 32768);
145 #elif RUUVI_NRF5_SDK15_TIMER_ENABLED
148 #define DUMMY_RTC_INTERVAL 1024
150 static volatile uint64_t m_dummy;
151 static void counter_handler (
void * p_context)
153 uint64_t mask = ~ ( (uint64_t) DUMMY_RTC_INTERVAL - 1);
155 m_dummy += DUMMY_RTC_INTERVAL;
166 LOGW (
"Using timer-tick based RTC\r\n");
175 if (NULL == counter_timer)
182 err_code |=
ri_timer_start (counter_timer, DUMMY_RTC_INTERVAL, NULL);
196 if (NULL != counter_timer) {
ri_timer_stop (counter_timer); }
uint32_t rd_status_t
bitfield for representing errors
rd_status_t ruuvi_nrf5_sdk15_to_ruuvi_error(const ret_code_t error)
convert nrf5 sdk15 error code into Ruuvi error code.
#define RD_ERROR_NOT_SUPPORTED
Not supported.
#define RD_SUCCESS
Internal Error.
#define RD_UINT64_INVALID
Signal that value should not be used.
#define RD_ERROR_INVALID_STATE
Invalid state, operation disallowed in this state.
void ri_log(const ri_log_severity_t severity, const char *const message)
Queues messages into log.
bool ri_timer_is_init(void)
Check if timer is initialized.
rd_status_t ri_timer_start(ri_timer_id_t timer_id, uint32_t ms, void *const context)
Start given timer at a mode defined in ri_timer_create.
rd_status_t ri_timer_create(ri_timer_id_t *p_timer_id, ri_timer_mode_t mode, ruuvi_timer_timeout_handler_t timeout_handler)
rd_status_t ri_timer_init(void)
rd_status_t ri_timer_stop(ri_timer_id_t timer_id)
void * ri_timer_id_t
Pointer to timer data.
Header to enable and disable module compilation.
Ruuvi error codes and error check function.
Ruuvi sensor interface Lifecycle: Beta
rd_status_t ri_rtc_init(void)
Initializes RTC at 0 ms.
rd_status_t ri_rtc_uninit(void)
Stop RTC if applicable.
uint64_t ri_rtc_millis(void)
Get milliseconds since init.
Interface functions to timer.