Lines Matching +full:ppi +full:- +full:wrap
4 * SPDX-License-Identifier: Apache-2.0
26 ((const struct counter_nrfx_config *)dev->config)->log, __VA_ARGS__)
28 ((const struct counter_nrfx_config *)dev->config)->log, __VA_ARGS__)
30 ((const struct counter_nrfx_config *)dev->config)->log, __VA_ARGS__)
32 ((const struct counter_nrfx_config *)dev->config)->log, __VA_ARGS__)
39 (((const struct counter_nrfx_config *)dev->config)->fixed_top), (true))
42 (((const struct counter_nrfx_config *)dev->config)->use_ppi), (false))
85 const struct counter_nrfx_config *config = dev->config; in start()
87 nrfy_rtc_task_trigger(config->rtc, NRF_RTC_TASK_START); in start()
94 const struct counter_nrfx_config *config = dev->config; in stop()
96 nrfy_rtc_task_trigger(config->rtc, NRF_RTC_TASK_STOP); in stop()
103 const struct counter_nrfx_config *config = dev->config; in read()
105 return nrfy_rtc_counter_get(config->rtc); in read()
115 * argument is in front and that values wrap.
121 return (val - old) & NRF_RTC_COUNTER_MAX; in ticks_sub()
123 return (val - old) & top; in ticks_sub()
126 /* if top is not 2^n-1 */ in ticks_sub()
127 return (val >= old) ? (val - old) : val + top + 1 - old; in ticks_sub()
155 sum = sum > top ? sum - (top + 1) : sum; in ticks_add()
163 const struct counter_nrfx_config *config = dev->config; in set_cc_int_pending()
164 struct counter_nrfx_data *data = dev->data; in set_cc_int_pending()
166 atomic_or(&data->ipend_adj, BIT(chan)); in set_cc_int_pending()
167 NRFY_IRQ_PENDING_SET(NRFX_IRQ_NUMBER_GET(config->rtc)); in set_cc_int_pending()
186 const struct counter_nrfx_config *config = dev->config; in handle_next_tick_case()
187 struct counter_nrfx_data *data = dev->data; in handle_next_tick_case()
189 val = ticks_add(dev, val, 1, data->top); in handle_next_tick_case()
190 nrfy_rtc_cc_set(config->rtc, chan, val); in handle_next_tick_case()
191 atomic_or(&data->ipend_adj, CC_ADJ_MASK(chan)); in handle_next_tick_case()
192 if (nrfy_rtc_counter_get(config->rtc) != now) { in handle_next_tick_case()
195 nrfy_rtc_int_enable(config->rtc, NRF_RTC_CHANNEL_INT_MASK(chan)); in handle_next_tick_case()
203 * - Current COMPARE value written to the register may be close to the current
205 * - Next COMPARE value may be soon in the future. Taking into account potential
207 * - RTC registers are clocked with LF clock (32kHz) and sampled between two
209 * - Setting COMPARE register to COUNTER+1 does not generate COMPARE event if
213 * - COMPARE interrupt is disabled
214 * - absolute value is taking into account guard period. It means that
215 * it won't be further in future than <top> - <guard_period> from now.
223 * @retval -ETIME if absolute alarm was set too late and error reporting is
230 const struct counter_nrfx_config *config = dev->config; in set_cc()
231 struct counter_nrfx_data *data = dev->data; in set_cc()
233 __ASSERT_NO_MSG(data->guard_period < data->top); in set_cc()
234 NRF_RTC_Type *rtc = config->rtc; in set_cc()
250 top = data->top; in set_cc()
274 max_rel_val = top - data->guard_period; in set_cc()
306 diff = ticks_sub(dev, val - 1, now, top); in set_cc()
309 err = -ETIME; in set_cc()
318 config->ch_data[chan].callback = NULL; in set_cc()
338 const struct counter_nrfx_config *nrfx_config = dev->config; in set_channel_alarm()
339 struct counter_nrfx_data *data = dev->data; in set_channel_alarm()
340 struct counter_nrfx_ch_data *chdata = &nrfx_config->ch_data[chan]; in set_channel_alarm()
342 if (alarm_cfg->ticks > data->top) { in set_channel_alarm()
343 return -EINVAL; in set_channel_alarm()
346 if (chdata->callback) { in set_channel_alarm()
347 return -EBUSY; in set_channel_alarm()
350 chdata->callback = alarm_cfg->callback; in set_channel_alarm()
351 chdata->user_data = alarm_cfg->user_data; in set_channel_alarm()
352 atomic_and(&data->ipend_adj, ~CC_ADJ_MASK(chan)); in set_channel_alarm()
354 return set_cc(dev, chan, alarm_cfg->ticks, alarm_cfg->flags); in set_channel_alarm()
359 const struct counter_nrfx_config *config = dev->config; in disable()
360 NRF_RTC_Type *rtc = config->rtc; in disable()
365 config->ch_data[chan].callback = NULL; in disable()
378 const struct counter_nrfx_config *nrfx_config = dev->config; in ppi_setup()
379 struct counter_nrfx_data *data = dev->data; in ppi_setup()
380 NRF_RTC_Type *rtc = nrfx_config->rtc; in ppi_setup()
384 if (!nrfx_config->use_ppi) { in ppi_setup()
392 result = nrfx_dppi_channel_alloc(&dppi, &data->ppi_ch); in ppi_setup()
394 ERR("Failed to allocate PPI channel."); in ppi_setup()
395 return -ENODEV; in ppi_setup()
398 nrfy_rtc_subscribe_set(rtc, NRF_RTC_TASK_CLEAR, data->ppi_ch); in ppi_setup()
399 nrfy_rtc_publish_set(rtc, evt, data->ppi_ch); in ppi_setup()
400 (void)nrfx_dppi_channel_enable(&dppi, data->ppi_ch); in ppi_setup()
408 result = nrfx_ppi_channel_alloc(&data->ppi_ch); in ppi_setup()
410 ERR("Failed to allocate PPI channel."); in ppi_setup()
411 return -ENODEV; in ppi_setup()
413 (void)nrfx_ppi_channel_assign(data->ppi_ch, evt_addr, task_addr); in ppi_setup()
414 (void)nrfx_ppi_channel_enable(data->ppi_ch); in ppi_setup()
423 const struct counter_nrfx_config *nrfx_config = dev->config; in ppi_free()
424 struct counter_nrfx_data *data = dev->data; in ppi_free()
425 uint8_t ppi_ch = data->ppi_ch; in ppi_free()
426 NRF_RTC_Type *rtc = nrfx_config->rtc; in ppi_free()
428 if (!nrfx_config->use_ppi) { in ppi_free()
448 * automatically in case of max top value or PPI usage.
452 struct counter_nrfx_data *data = dev->data; in sw_wrap_required()
454 return (data->top != NRF_RTC_COUNTER_MAX) && !IS_PPI_WRAP(dev); in sw_wrap_required()
460 const struct counter_nrfx_config *config = dev->config; in set_fixed_top_value()
461 struct counter_nrfx_data *data = dev->data; in set_fixed_top_value()
463 NRF_RTC_Type *rtc = config->rtc; in set_fixed_top_value()
465 if (cfg->ticks != NRF_RTC_COUNTER_MAX) { in set_fixed_top_value()
466 return -EINVAL; in set_fixed_top_value()
470 data->top_cb = cfg->callback; in set_fixed_top_value()
471 data->top_user_data = cfg->user_data; in set_fixed_top_value()
473 if (!(cfg->flags & COUNTER_TOP_CFG_DONT_RESET)) { in set_fixed_top_value()
477 if (cfg->callback) { in set_fixed_top_value()
487 const struct counter_nrfx_config *nrfx_config = dev->config; in set_top_value()
488 NRF_RTC_Type *rtc = nrfx_config->rtc; in set_top_value()
489 struct counter_nrfx_data *dev_data = dev->data; in set_top_value()
501 if (nrfx_config->ch_data[i].callback) { in set_top_value()
502 return -EBUSY; in set_top_value()
509 if ((dev_data->top == NRF_RTC_COUNTER_MAX) && in set_top_value()
510 cfg->ticks != NRF_RTC_COUNTER_MAX) { in set_top_value()
512 } else if (((dev_data->top != NRF_RTC_COUNTER_MAX) && in set_top_value()
513 cfg->ticks == NRF_RTC_COUNTER_MAX)) { in set_top_value()
518 dev_data->top_cb = cfg->callback; in set_top_value()
519 dev_data->top_user_data = cfg->user_data; in set_top_value()
520 dev_data->top = cfg->ticks; in set_top_value()
521 nrfy_rtc_cc_set(rtc, top_ch, cfg->ticks); in set_top_value()
523 if (!(cfg->flags & COUNTER_TOP_CFG_DONT_RESET)) { in set_top_value()
525 } else if (read(dev) >= cfg->ticks) { in set_top_value()
526 err = -ETIME; in set_top_value()
527 if (cfg->flags & COUNTER_TOP_CFG_RESET_WHEN_LATE) { in set_top_value()
532 if (cfg->callback || sw_wrap_required(dev)) { in set_top_value()
547 (MAYBE_CONST_CONFIG struct counter_nrfx_config *) dev->config; in init_rtc()
548 struct counter_nrfx_data *data = dev->data; in init_rtc()
557 nrfx_config->rtc = nhw_convert_periph_base_addr(nrfx_config->rtc); in init_rtc()
560 NRF_RTC_Type *rtc = nrfx_config->rtc; in init_rtc()
571 data->top = NRF_RTC_COUNTER_MAX; in init_rtc()
580 struct counter_nrfx_data *data = dev->data; in get_top_value()
582 return data->top; in get_top_value()
587 struct counter_nrfx_data *data = dev->data; in get_guard_period()
589 return data->guard_period; in get_guard_period()
595 struct counter_nrfx_data *data = dev->data; in set_guard_period()
597 data->guard_period = guard; in set_guard_period()
603 const struct counter_nrfx_config *config = dev->config; in top_irq_handle()
604 struct counter_nrfx_data *data = dev->data; in top_irq_handle()
606 NRF_RTC_Type *rtc = config->rtc; in top_irq_handle()
607 counter_top_callback_t cb = data->top_cb; in top_irq_handle()
617 /* Perform manual clear if custom top value is used and PPI in top_irq_handle()
625 cb(dev, data->top_user_data); in top_irq_handle()
632 const struct counter_nrfx_config *config = dev->config; in alarm_irq_handle()
633 struct counter_nrfx_data *data = dev->data; in alarm_irq_handle()
635 NRF_RTC_Type *rtc = config->rtc; in alarm_irq_handle()
641 bool sw_irq_pending = data->ipend_adj & BIT(chan); in alarm_irq_handle()
647 atomic_and(&data->ipend_adj, ~BIT(chan)); in alarm_irq_handle()
650 chdata = &config->ch_data[chan]; in alarm_irq_handle()
651 cb = chdata->callback; in alarm_irq_handle()
652 chdata->callback = NULL; in alarm_irq_handle()
657 if (data->ipend_adj & CC_ADJ_MASK(chan)) { in alarm_irq_handle()
658 cc = ticks_sub(dev, cc, 1, data->top); in alarm_irq_handle()
661 cb(dev, chan, cc, chdata->user_data); in alarm_irq_handle()
707 BUILD_ASSERT((DT_INST_PROP(idx, prescaler) - 1) <= \
720 return init_rtc(dev, DT_INST_PROP(idx, prescaler) - 1); \
735 : DT_INST_PROP(idx, cc_num) - 1 \