static int counter_nrfx_set_top_value(struct device *dev, u32_t ticks, counter_top_callback_t callback, void *user_data) { const struct counter_nrfx_config *nrfx_config = get_nrfx_config(dev); const nrfx_rtc_t *rtc = &nrfx_config->rtc; struct counter_nrfx_data *dev_data = get_dev_data(dev); for (int i = 0; i < counter_get_num_of_channels(dev); i++) { /* Overflow can be changed only when all alarms are * disables. */ if (nrfx_config->ch_data[i].callback) { return -EBUSY; } } nrfx_rtc_cc_disable(rtc, TOP_CH); nrfx_rtc_counter_clear(rtc); dev_data->top_cb = callback; dev_data->top_user_data = user_data; dev_data->top = ticks; nrfx_rtc_cc_set(rtc, TOP_CH, ticks, callback ? true : false); return 0; }
static void event_handler(nrfx_rtc_int_type_t int_type, void *p_context) { struct device *dev = p_context; struct counter_nrfx_data *data = get_dev_data(dev); if (int_type == COUNTER_TOP_INT) { /* Manually reset counter if top value is different than max. */ if ((data->top != COUNTER_MAX_TOP_VALUE) #if CONFIG_COUNTER_RTC_WITH_PPI_WRAP && !get_nrfx_config(dev)->use_ppi #endif ) { nrfx_rtc_counter_clear(&get_nrfx_config(dev)->rtc); } nrfx_rtc_cc_set(&get_nrfx_config(dev)->rtc, TOP_CH, data->top, true); if (data->top_cb) { data->top_cb(dev, data->top_user_data); } } else if (int_type > COUNTER_TOP_INT) { alarm_event_handler(dev, CC_TO_ID(int_type)); } }