Lines Matching +full:timer +full:- +full:triggered
4 * SPDX-License-Identifier: Apache-2.0
28 #define COUNTER_DT_DEVICE(_idx) DEVICE_DT_GET_OR_NULL(DT_NODELABEL(timer##_idx))
50 /* Register set for timer */
51 TIMER2_Type *timer; member
53 /* Timer driven by DIVn if 1 or lp_clk if 0 */
83 * a timer block will automatically be switched from DIVN to LP and vice versa.
87 const struct counter_smartbond_config *config = dev->config; in counter_smartbond_is_sleep_allowed()
90 (dev == COUNTER_DT_DEVICE(2))) && !config->clock_src_divn); in counter_smartbond_is_sleep_allowed()
96 const struct counter_smartbond_config *config = dev->config; in counter_smartbond_pdc_trigger_get()
98 switch ((uint32_t)config->timer) { in counter_smartbond_pdc_trigger_get()
99 case (uint32_t)TIMER: in counter_smartbond_pdc_trigger_get()
119 struct counter_smartbond_data *data = dev->data; in counter_smartbond_pdc_add()
122 data->pdc_idx = da1469x_pdc_add(trigger, MCU_PDC_MASTER_M33, PDC_XTAL_EN); in counter_smartbond_pdc_add()
123 __ASSERT_NO_MSG(data->pdc_idx >= 0); in counter_smartbond_pdc_add()
125 da1469x_pdc_set(data->pdc_idx); in counter_smartbond_pdc_add()
126 da1469x_pdc_ack(data->pdc_idx); in counter_smartbond_pdc_add()
131 struct counter_smartbond_data *data = dev->data; in counter_smartbond_pdc_del()
133 da1469x_pdc_del(data->pdc_idx); in counter_smartbond_pdc_del()
139 const struct counter_smartbond_config *config = dev->config; in counter_smartbond_start()
140 TIMER2_Type *timer = config->timer; in counter_smartbond_start() local
155 timer->TIMER2_CTRL_REG |= (TIMER2_TIMER2_CTRL_REG_TIM_CLK_EN_Msk | in counter_smartbond_start()
164 const struct counter_smartbond_config *config = dev->config; in counter_smartbond_stop()
165 struct counter_smartbond_data *data = dev->data; in counter_smartbond_stop()
166 TIMER2_Type *timer = config->timer; in counter_smartbond_stop() local
169 timer->TIMER2_CTRL_REG &= ~(TIMER2_TIMER2_CTRL_REG_TIM_EN_Msk | in counter_smartbond_stop()
172 data->callback = NULL; in counter_smartbond_stop()
194 const struct counter_smartbond_config *config = dev->config; in counter_smartbond_read()
195 TIMER2_Type *timer = config->timer; in counter_smartbond_read() local
197 return timer->TIMER2_TIMER_VAL_REG; in counter_smartbond_read()
210 const struct counter_smartbond_config *config = dev->config; in counter_smartbond_set_alarm()
211 struct counter_smartbond_data *data = dev->data; in counter_smartbond_set_alarm()
212 TIMER2_Type *timer = config->timer; in counter_smartbond_set_alarm() local
213 volatile uint32_t *timer_clear_irq_reg = ((TIMER_Type *)timer) == TIMER ? in counter_smartbond_set_alarm()
214 &((TIMER_Type *)timer)->TIMER_CLEAR_IRQ_REG : in counter_smartbond_set_alarm()
215 &timer->TIMER2_CLEAR_IRQ_REG; in counter_smartbond_set_alarm()
216 bool absolute = alarm_cfg->flags & COUNTER_ALARM_CFG_ABSOLUTE; in counter_smartbond_set_alarm()
217 uint32_t flags = alarm_cfg->flags; in counter_smartbond_set_alarm()
218 uint32_t val = alarm_cfg->ticks; in counter_smartbond_set_alarm()
225 if (chan != 0 || alarm_cfg->ticks > counter_smartbond_get_top_value(dev)) { in counter_smartbond_set_alarm()
226 return -EINVAL; in counter_smartbond_set_alarm()
229 if (data->callback) { in counter_smartbond_set_alarm()
230 return -EBUSY; in counter_smartbond_set_alarm()
234 data->callback = alarm_cfg->callback; in counter_smartbond_set_alarm()
235 data->user_data = alarm_cfg->user_data; in counter_smartbond_set_alarm()
237 __ASSERT_NO_MSG(data->guard_period < TIMER_TOP_VALUE); in counter_smartbond_set_alarm()
240 max_rel_val = TIMER_TOP_VALUE - data->guard_period; in counter_smartbond_set_alarm()
246 * setting is detected, interrupt shall be triggered for in counter_smartbond_set_alarm()
247 * immediate expiration of the timer. Detection is performed in counter_smartbond_set_alarm()
257 timer->TIMER2_RELOAD_REG = val; in counter_smartbond_set_alarm()
262 diff = ((val - 1U) - counter_smartbond_read(dev)) & TIMER_TOP_VALUE; in counter_smartbond_set_alarm()
265 err = -ETIME; in counter_smartbond_set_alarm()
268 /* Interrupt is triggered always for relative alarm and in counter_smartbond_set_alarm()
272 NVIC_SetPendingIRQ(config->irqn); in counter_smartbond_set_alarm()
274 data->callback = NULL; in counter_smartbond_set_alarm()
280 * should be triggered. No need to enable interrupt in counter_smartbond_set_alarm()
281 * on TIMER just make sure interrupt is pending. in counter_smartbond_set_alarm()
283 NVIC_SetPendingIRQ(config->irqn); in counter_smartbond_set_alarm()
285 timer->TIMER2_CTRL_REG |= TIMER2_TIMER2_CTRL_REG_TIM_IRQ_EN_Msk; in counter_smartbond_set_alarm()
294 const struct counter_smartbond_config *config = dev->config; in counter_smartbond_cancel_alarm()
295 TIMER2_Type *timer = config->timer; in counter_smartbond_cancel_alarm() local
296 struct counter_smartbond_data *data = dev->data; in counter_smartbond_cancel_alarm()
300 timer->TIMER2_CTRL_REG &= ~TIMER2_TIMER2_CTRL_REG_TIM_IRQ_EN_Msk; in counter_smartbond_cancel_alarm()
301 data->callback = NULL; in counter_smartbond_cancel_alarm()
311 if (cfg->ticks != 0xFFFFFF) { in counter_smartbond_set_top_value()
312 return -ENOTSUP; in counter_smartbond_set_top_value()
320 const struct counter_smartbond_config *config = dev->config; in counter_smartbond_get_pending_int()
322 /* There is no register to check TIMER peripheral to check for interrupt in counter_smartbond_get_pending_int()
325 return NVIC_GetPendingIRQ(config->irqn); in counter_smartbond_get_pending_int()
330 const struct counter_smartbond_config *cfg = dev->config; in counter_smartbond_init_timer()
331 struct counter_smartbond_data *data = dev->data; in counter_smartbond_init_timer()
332 TIMER2_Type *timer = cfg->timer; in counter_smartbond_init_timer() local
333 TIMER_Type *timer0 = ((TIMER_Type *)cfg->timer) == TIMER ? TIMER : NULL; in counter_smartbond_init_timer()
338 if (cfg->clock_src_divn) { in counter_smartbond_init_timer()
339 /* Timer clock source is DIVn 32MHz */ in counter_smartbond_init_timer()
340 timer->TIMER2_CTRL_REG = TIMER2_TIMER2_CTRL_REG_TIM_SYS_CLK_EN_Msk; in counter_smartbond_init_timer()
341 data->freq = DT_PROP(DT_NODELABEL(divn_clk), clock_frequency) / in counter_smartbond_init_timer()
342 (cfg->prescaler + 1); in counter_smartbond_init_timer()
345 timer->TIMER2_CTRL_REG = 0; in counter_smartbond_init_timer()
346 switch ((CRG_TOP->CLK_CTRL_REG & CRG_TOP_CLK_CTRL_REG_LP_CLK_SEL_Msk) >> in counter_smartbond_init_timer()
360 data->freq = osc_freq / (cfg->prescaler + 1); in counter_smartbond_init_timer()
362 timer->TIMER2_PRESCALER_REG = cfg->prescaler; in counter_smartbond_init_timer()
363 timer->TIMER2_RELOAD_REG = counter_get_max_top_value(dev); in counter_smartbond_init_timer()
364 timer->TIMER2_GPIO1_CONF_REG = 0; in counter_smartbond_init_timer()
365 timer->TIMER2_GPIO2_CONF_REG = 0; in counter_smartbond_init_timer()
366 timer->TIMER2_SHOTWIDTH_REG = 0; in counter_smartbond_init_timer()
367 timer->TIMER2_CAPTURE_GPIO1_REG = 0; in counter_smartbond_init_timer()
368 timer->TIMER2_CAPTURE_GPIO2_REG = 0; in counter_smartbond_init_timer()
369 timer->TIMER2_PWM_FREQ_REG = 0; in counter_smartbond_init_timer()
370 timer->TIMER2_PWM_DC_REG = 0; in counter_smartbond_init_timer()
372 timer0->TIMER_CAPTURE_GPIO3_REG = 0; in counter_smartbond_init_timer()
373 timer0->TIMER_CAPTURE_GPIO4_REG = 0; in counter_smartbond_init_timer()
377 cfg->irq_config_func(dev); in counter_smartbond_init_timer()
391 struct counter_smartbond_data *data = dev->data; in counter_smartbond_get_guard_period()
394 return data->guard_period; in counter_smartbond_get_guard_period()
400 struct counter_smartbond_data *data = dev->data; in counter_smartbond_set_guard_period()
405 data->guard_period = guard; in counter_smartbond_set_guard_period()
412 struct counter_smartbond_data *data = dev->data; in counter_smartbond_get_freq()
414 return data->freq; in counter_smartbond_get_freq()
420 const struct counter_smartbond_config *cfg = dev->config; in counter_smartbond_resume()
421 TIMER2_Type *timer = cfg->timer; in counter_smartbond_resume() local
428 if (cfg->clock_src_divn) { in counter_smartbond_resume()
429 timer->TIMER2_CTRL_REG = TIMER2_TIMER2_CTRL_REG_TIM_SYS_CLK_EN_Msk; in counter_smartbond_resume()
431 timer->TIMER2_CTRL_REG = 0; in counter_smartbond_resume()
433 timer->TIMER2_PRESCALER_REG = cfg->prescaler; in counter_smartbond_resume()
434 timer->TIMER2_RELOAD_REG = counter_get_max_top_value(dev); in counter_smartbond_resume()
449 ret = -ENOTSUP; in counter_smartbond_pm_action()
472 const struct counter_smartbond_config *cfg = dev->config; in counter_smartbond_irq_handler()
473 struct counter_smartbond_data *data = dev->data; in counter_smartbond_irq_handler()
474 counter_alarm_callback_t alarm_callback = data->callback; in counter_smartbond_irq_handler()
475 TIMER2_Type *timer = cfg->timer; in counter_smartbond_irq_handler() local
477 __IOM uint32_t *timer_clear_irq_reg = ((TIMER_Type *)timer) == TIMER ? in counter_smartbond_irq_handler()
478 &((TIMER_Type *)timer)->TIMER_CLEAR_IRQ_REG : in counter_smartbond_irq_handler()
479 &timer->TIMER2_CLEAR_IRQ_REG; in counter_smartbond_irq_handler()
481 timer->TIMER2_CTRL_REG &= ~TIMER2_TIMER2_CTRL_REG_TIM_IRQ_EN_Msk; in counter_smartbond_irq_handler()
485 data->callback = NULL; in counter_smartbond_irq_handler()
486 alarm_callback(dev, 0, timer->TIMER2_TIMER_VAL_REG, in counter_smartbond_irq_handler()
487 data->user_data); in counter_smartbond_irq_handler()
499 "TIMER prescaler out of range (1..32)"); \
519 .timer = TIM(idx), \
520 .prescaler = DT_PROP(TIMERN(idx), prescaler) - 1, \