Lines Matching +full:timer +full:- +full:triggered
2 * Copyright (c) 2017 - 2018, Nordic Semiconductor ASA
4 * SPDX-License-Identifier: Apache-2.0
18 #define CC_TO_ID(cc_num) (cc_num - 2)
50 NRF_TIMER_Type *timer; member
62 const struct counter_nrfx_config *config = dev->config; in start()
64 nrf_timer_task_trigger(config->timer, NRF_TIMER_TASK_START); in start()
71 const struct counter_nrfx_config *config = dev->config; in stop()
73 nrf_timer_task_trigger(config->timer, NRF_TIMER_TASK_STOP); in stop()
80 const struct counter_nrfx_config *config = dev->config; in get_top_value()
82 return nrf_timer_cc_get(config->timer, TOP_CH); in get_top_value()
87 const struct counter_nrfx_config *config = dev->config; in read()
88 NRF_TIMER_Type *timer = config->timer; in read() local
90 nrf_timer_task_trigger(timer, in read()
94 return nrf_timer_cc_get(timer, COUNTER_READ_CC); in read()
111 to_top = top - val1; in ticks_add()
113 return (val2 <= to_top) ? val1 + val2 : val2 - to_top; in ticks_add()
119 return (val - old) & top; in ticks_sub()
122 /* if top is not 2^n-1 */ in ticks_sub()
123 return (val >= old) ? (val - old) : val + top + 1 - old; in ticks_sub()
128 const struct counter_nrfx_config *config = dev->config; in set_cc_int_pending()
129 struct counter_nrfx_data *data = dev->data; in set_cc_int_pending()
131 atomic_or(&data->cc_int_pending, BIT(chan)); in set_cc_int_pending()
132 NRFX_IRQ_PENDING_SET(NRFX_IRQ_NUMBER_GET(config->timer)); in set_cc_int_pending()
138 const struct counter_nrfx_config *config = dev->config; in set_cc()
139 struct counter_nrfx_data *data = dev->data; in set_cc()
141 __ASSERT_NO_MSG(data->guard_period < get_top_value(dev)); in set_cc()
144 NRF_TIMER_Type *reg = config->timer; in set_cc()
169 max_rel_val = top - data->guard_period; in set_cc()
175 * setting is detected, interrupt shall be triggered for in set_cc()
176 * immediate expiration of the timer. Detection is performed in set_cc()
192 diff = ticks_sub(val - 1, read(dev), top); in set_cc()
195 err = -ETIME; in set_cc()
198 /* Interrupt is triggered always for relative alarm and in set_cc()
204 config->ch_data[id].callback = NULL; in set_cc()
216 const struct counter_nrfx_config *nrfx_config = dev->config; in set_alarm()
217 struct counter_nrfx_ch_data *chdata = &nrfx_config->ch_data[chan]; in set_alarm()
219 if (alarm_cfg->ticks > get_top_value(dev)) { in set_alarm()
220 return -EINVAL; in set_alarm()
223 if (chdata->callback) { in set_alarm()
224 return -EBUSY; in set_alarm()
227 chdata->callback = alarm_cfg->callback; in set_alarm()
228 chdata->user_data = alarm_cfg->user_data; in set_alarm()
230 return set_cc(dev, chan, alarm_cfg->ticks, alarm_cfg->flags); in set_alarm()
235 const struct counter_nrfx_config *config = dev->config; in cancel_alarm()
238 nrf_timer_int_disable(config->timer, int_mask); in cancel_alarm()
239 config->ch_data[chan_id].callback = NULL; in cancel_alarm()
247 const struct counter_nrfx_config *nrfx_config = dev->config; in set_top_value()
248 NRF_TIMER_Type *timer = nrfx_config->timer; in set_top_value() local
249 struct counter_nrfx_data *data = dev->data; in set_top_value()
255 if (nrfx_config->ch_data[i].callback) { in set_top_value()
256 return -EBUSY; in set_top_value()
260 nrf_timer_int_disable(timer, COUNTER_TOP_INT_MASK); in set_top_value()
261 nrf_timer_cc_set(timer, TOP_CH, cfg->ticks); in set_top_value()
262 nrf_timer_event_clear(timer, COUNTER_TOP_EVT); in set_top_value()
263 nrf_timer_shorts_enable(timer, COUNTER_OVERFLOW_SHORT); in set_top_value()
265 data->top_cb = cfg->callback; in set_top_value()
266 data->top_user_data = cfg->user_data; in set_top_value()
268 if (!(cfg->flags & COUNTER_TOP_CFG_DONT_RESET)) { in set_top_value()
269 nrf_timer_task_trigger(timer, NRF_TIMER_TASK_CLEAR); in set_top_value()
270 } else if (read(dev) >= cfg->ticks) { in set_top_value()
271 err = -ETIME; in set_top_value()
272 if (cfg->flags & COUNTER_TOP_CFG_RESET_WHEN_LATE) { in set_top_value()
273 nrf_timer_task_trigger(timer, NRF_TIMER_TASK_CLEAR); in set_top_value()
277 if (cfg->callback) { in set_top_value()
278 nrf_timer_int_enable(timer, COUNTER_TOP_INT_MASK); in set_top_value()
293 (MAYBE_CONST_CONFIG struct counter_nrfx_config *)dev->config; in init_timer()
299 nrfx_config->timer = nhw_convert_periph_base_addr(nrfx_config->timer); in init_timer()
302 NRF_TIMER_Type *reg = nrfx_config->timer; in init_timer()
304 nrf_timer_bit_width_set(reg, config->bit_width); in init_timer()
305 nrf_timer_mode_set(reg, config->mode); in init_timer()
306 nrf_timer_prescaler_set(reg, config->prescaler); in init_timer()
317 struct counter_nrfx_data *data = dev->data; in get_guard_period()
319 return data->guard_period; in get_guard_period()
325 struct counter_nrfx_data *data = dev->data; in set_guard_period()
329 data->guard_period = guard; in set_guard_period()
335 const struct counter_nrfx_config *config = dev->config; in top_irq_handle()
336 struct counter_nrfx_data *data = dev->data; in top_irq_handle()
338 NRF_TIMER_Type *reg = config->timer; in top_irq_handle()
339 counter_top_callback_t cb = data->top_cb; in top_irq_handle()
344 __ASSERT(cb != NULL, "top event enabled - expecting callback"); in top_irq_handle()
345 cb(dev, data->top_user_data); in top_irq_handle()
351 const struct counter_nrfx_config *config = dev->config; in alarm_irq_handle()
352 struct counter_nrfx_data *data = dev->data; in alarm_irq_handle()
355 NRF_TIMER_Type *reg = config->timer; in alarm_irq_handle()
360 bool sw_irq_pending = data->cc_int_pending & BIT(cc); in alarm_irq_handle()
367 atomic_and(&data->cc_int_pending, ~BIT(cc)); in alarm_irq_handle()
370 chdata = &config->ch_data[id]; in alarm_irq_handle()
371 cb = chdata->callback; in alarm_irq_handle()
372 chdata->callback = NULL; in alarm_irq_handle()
377 cb(dev, id, cc_val, chdata->user_data); in alarm_irq_handle()
433 "TIMER prescaler out of range"); \
465 .timer = (NRF_TIMER_Type *)DT_INST_REG_ADDR(idx), \