static int init_rtc(struct device *dev, const nrfx_rtc_config_t *config, nrfx_rtc_handler_t handler) { struct device *clock; const struct counter_nrfx_config *nrfx_config = get_nrfx_config(dev); const nrfx_rtc_t *rtc = &nrfx_config->rtc; clock = device_get_binding(DT_NORDIC_NRF_CLOCK_0_LABEL "_32K"); if (!clock) { return -ENODEV; } clock_control_on(clock, (void *)CLOCK_CONTROL_NRF_K32SRC); nrfx_err_t result = nrfx_rtc_init(rtc, config, handler); if (result != NRFX_SUCCESS) { LOG_INST_ERR(nrfx_config->log, "Failed to initialize device."); return -EBUSY; } get_dev_data(dev)->top = COUNTER_MAX_TOP_VALUE; LOG_INST_DBG(nrfx_config->log, "Initialized"); return 0; }
static int init_timer(struct device *dev, const nrfx_timer_config_t *config) { const struct counter_nrfx_config *nrfx_config = get_nrfx_config(dev); const nrfx_timer_t *timer = &nrfx_config->timer; nrfx_err_t result = nrfx_timer_init(timer, config, event_handler); if (result != NRFX_SUCCESS) { LOG_INST_ERR(nrfx_config->log, "Failed to initialize device."); return -EBUSY; } nrfx_timer_compare(timer, TOP_CH, UINT32_MAX, false); LOG_INST_DBG(nrfx_config->log, "Initialized"); return 0; }