Lines Matching +full:overflow +full:- +full:control

4  * SPDX-License-Identifier: Apache-2.0
73 gpt_extended_cfg_t *p_extend = (gpt_extended_cfg_t *)p_cfg->p_extend; in pwm_renesas_ra_apply_gtior_config()
74 uint32_t gtior = p_extend->gtior_setting.gtior; in pwm_renesas_ra_apply_gtior_config()
79 if (p_extend->gtior_setting.gtior == 0) { in pwm_renesas_ra_apply_gtior_config()
81 if (p_extend->gtioca.output_enabled) { in pwm_renesas_ra_apply_gtior_config()
83 pwm_renesas_ra_gtior_calculate(p_extend->gtioca.stop_level); in pwm_renesas_ra_apply_gtior_config()
88 if (p_extend->gtiocb.output_enabled) { in pwm_renesas_ra_apply_gtior_config()
90 pwm_renesas_ra_gtior_calculate(p_extend->gtiocb.stop_level); in pwm_renesas_ra_apply_gtior_config()
98 gpt_extended_pwm_cfg_t const *p_pwm_cfg = p_extend->p_pwm_cfg; in pwm_renesas_ra_apply_gtior_config()
102 if (p_extend->gtior_setting.gtior == 0) { in pwm_renesas_ra_apply_gtior_config()
106 gtior |= (uint32_t)(p_pwm_cfg->gtioca_disable_setting in pwm_renesas_ra_apply_gtior_config()
108 gtior |= (uint32_t)(p_pwm_cfg->gtiocb_disable_setting in pwm_renesas_ra_apply_gtior_config()
115 if (p_extend->gtior_setting.gtior == 0) { in pwm_renesas_ra_apply_gtior_config()
120 gtior |= (uint32_t)(p_extend->capture_filter_gtioca << R_GPT0_GTIOR_NFAEN_Pos); in pwm_renesas_ra_apply_gtior_config()
121 gtior |= (uint32_t)(p_extend->capture_filter_gtiocb << R_GPT0_GTIOR_NFBEN_Pos); in pwm_renesas_ra_apply_gtior_config()
124 /* Set the I/O control register. */ in pwm_renesas_ra_apply_gtior_config()
125 p_ctrl->p_reg->GTIOR = gtior; in pwm_renesas_ra_apply_gtior_config()
133 struct pwm_renesas_ra_data *data = dev->data; in pwm_renesas_ra_set_cycles()
139 return -EINVAL; in pwm_renesas_ra_set_cycles()
142 if ((data->fsp_ctrl.variant == TIMER_VARIANT_16_BIT && period_cycles > UINT16_MAX) || in pwm_renesas_ra_set_cycles()
143 (data->fsp_ctrl.variant == TIMER_VARIANT_32_BIT && period_cycles > UINT32_MAX)) { in pwm_renesas_ra_set_cycles()
145 return -EINVAL; in pwm_renesas_ra_set_cycles()
150 data->extend_cfg.gtioca.output_enabled = true; in pwm_renesas_ra_set_cycles()
152 data->extend_cfg.gtiocb.output_enabled = true; in pwm_renesas_ra_set_cycles()
155 pulse = (flags & PWM_POLARITY_INVERTED) ? period_cycles - pulse_cycles : pulse_cycles; in pwm_renesas_ra_set_cycles()
158 pwm_renesas_ra_apply_gtior_config(&data->fsp_ctrl, &data->fsp_cfg); in pwm_renesas_ra_set_cycles()
161 err = R_GPT_Stop(&data->fsp_ctrl); in pwm_renesas_ra_set_cycles()
163 return -EIO; in pwm_renesas_ra_set_cycles()
166 /* Update period cycles, reflected at an overflow */ in pwm_renesas_ra_set_cycles()
167 err = R_GPT_PeriodSet(&data->fsp_ctrl, period_cycles); in pwm_renesas_ra_set_cycles()
169 return -EIO; in pwm_renesas_ra_set_cycles()
172 /* Update pulse cycles, reflected at an overflow */ in pwm_renesas_ra_set_cycles()
173 err = R_GPT_DutyCycleSet(&data->fsp_ctrl, pulse, pin); in pwm_renesas_ra_set_cycles()
175 return -EIO; in pwm_renesas_ra_set_cycles()
179 err = R_GPT_Start(&data->fsp_ctrl); in pwm_renesas_ra_set_cycles()
181 return -EIO; in pwm_renesas_ra_set_cycles()
184 LOG_DBG("channel %u, pin %u, pulse %u, period %u, prescaler: %u.", data->fsp_cfg.channel, in pwm_renesas_ra_set_cycles()
185 pin, pulse_cycles, period_cycles, data->fsp_cfg.source_div); in pwm_renesas_ra_set_cycles()
193 struct pwm_renesas_ra_data *data = dev->data; in pwm_renesas_ra_get_cycles_per_sec()
199 return -EINVAL; in pwm_renesas_ra_get_cycles_per_sec()
202 err = R_GPT_InfoGet(&data->fsp_ctrl, &info); in pwm_renesas_ra_get_cycles_per_sec()
204 return -EIO; in pwm_renesas_ra_get_cycles_per_sec()
234 struct pwm_renesas_ra_data *data = dev->data; in pwm_renesas_ra_configure_capture()
238 return -EINVAL; in pwm_renesas_ra_configure_capture()
242 return -EINVAL; in pwm_renesas_ra_configure_capture()
246 return -ENOTSUP; in pwm_renesas_ra_configure_capture()
248 if (data->capture.is_busy) { in pwm_renesas_ra_configure_capture()
250 return -EBUSY; in pwm_renesas_ra_configure_capture()
254 data->capture.is_pulse_capture = false; in pwm_renesas_ra_configure_capture()
257 data->extend_cfg.start_source = in pwm_renesas_ra_configure_capture()
261 data->extend_cfg.capture_a_source = data->extend_cfg.start_source; in pwm_renesas_ra_configure_capture()
264 data->extend_cfg.start_source = in pwm_renesas_ra_configure_capture()
268 data->extend_cfg.capture_a_source = data->extend_cfg.start_source; in pwm_renesas_ra_configure_capture()
271 data->capture.is_pulse_capture = true; in pwm_renesas_ra_configure_capture()
274 data->extend_cfg.start_source = in pwm_renesas_ra_configure_capture()
279 data->extend_cfg.capture_a_source = in pwm_renesas_ra_configure_capture()
284 data->extend_cfg.start_source = in pwm_renesas_ra_configure_capture()
289 data->extend_cfg.capture_a_source = in pwm_renesas_ra_configure_capture()
296 data->capture.callback = cb; in pwm_renesas_ra_configure_capture()
297 data->capture.user_data = user_data; in pwm_renesas_ra_configure_capture()
298 data->capture.continuous = flags & PWM_CAPTURE_MODE_CONTINUOUS; in pwm_renesas_ra_configure_capture()
300 if (data->capture.continuous) { in pwm_renesas_ra_configure_capture()
301 data->extend_cfg.stop_source = data->extend_cfg.capture_a_source; in pwm_renesas_ra_configure_capture()
302 data->extend_cfg.clear_source = data->extend_cfg.start_source; in pwm_renesas_ra_configure_capture()
304 data->extend_cfg.stop_source = (gpt_source_t)(GPT_SOURCE_NONE); in pwm_renesas_ra_configure_capture()
305 data->extend_cfg.clear_source = (gpt_source_t)(GPT_SOURCE_NONE); in pwm_renesas_ra_configure_capture()
313 struct pwm_renesas_ra_data *data = dev->data; in pwm_renesas_ra_enable_capture()
318 return -EINVAL; in pwm_renesas_ra_enable_capture()
321 if (data->capture.is_busy) { in pwm_renesas_ra_enable_capture()
323 return -EBUSY; in pwm_renesas_ra_enable_capture()
326 if (!data->capture.callback) { in pwm_renesas_ra_enable_capture()
328 return -EINVAL; in pwm_renesas_ra_enable_capture()
331 data->capture.is_busy = true; in pwm_renesas_ra_enable_capture()
334 err = R_GPT_Enable(&data->fsp_ctrl); in pwm_renesas_ra_enable_capture()
336 return -EIO; in pwm_renesas_ra_enable_capture()
340 enable_irq(data->fsp_cfg.cycle_end_irq, data->fsp_cfg.cycle_end_irq, &data->fsp_ctrl); in pwm_renesas_ra_enable_capture()
341 enable_irq(data->extend_cfg.capture_a_irq, data->extend_cfg.capture_a_ipl, &data->fsp_ctrl); in pwm_renesas_ra_enable_capture()
343 R_ICU->IELSR[data->fsp_cfg.cycle_end_irq] = (elc_event_t)data->overflow_event; in pwm_renesas_ra_enable_capture()
344 R_ICU->IELSR[data->extend_cfg.capture_a_irq] = (elc_event_t)data->capture_a_event; in pwm_renesas_ra_enable_capture()
351 struct pwm_renesas_ra_data *data = dev->data; in pwm_renesas_ra_disable_capture()
356 return -EINVAL; in pwm_renesas_ra_disable_capture()
358 data->capture.is_busy = false; in pwm_renesas_ra_disable_capture()
361 disable_irq(data->fsp_cfg.cycle_end_irq); in pwm_renesas_ra_disable_capture()
362 disable_irq(data->extend_cfg.capture_a_irq); in pwm_renesas_ra_disable_capture()
364 R_ICU->IELSR[data->fsp_cfg.cycle_end_irq] = (elc_event_t)ELC_EVENT_NONE; in pwm_renesas_ra_disable_capture()
365 R_ICU->IELSR[data->extend_cfg.capture_a_irq] = (elc_event_t)ELC_EVENT_NONE; in pwm_renesas_ra_disable_capture()
368 err = R_GPT_Disable(&data->fsp_ctrl); in pwm_renesas_ra_disable_capture()
370 return -EIO; in pwm_renesas_ra_disable_capture()
374 err = R_GPT_Stop(&data->fsp_ctrl); in pwm_renesas_ra_disable_capture()
376 return -EIO; in pwm_renesas_ra_disable_capture()
380 err = R_GPT_Reset(&data->fsp_ctrl); in pwm_renesas_ra_disable_capture()
382 return -EIO; in pwm_renesas_ra_disable_capture()
390 const struct device *dev = p_args->p_context; in fsp_callback()
391 struct pwm_renesas_ra_data *data = dev->data; in fsp_callback()
394 (void)R_GPT_InfoGet(&data->fsp_ctrl, &info); in fsp_callback()
398 /* The maximum period is one more than the maximum 16,32-bit number, but will be reflected in fsp_callback()
402 if (data->fsp_ctrl.variant == TIMER_VARIANT_16_BIT) { in fsp_callback()
410 if (p_args->event == TIMER_EVENT_CAPTURE_A) { in fsp_callback()
411 if (p_args->capture != 0U) { in fsp_callback()
412 if (data->capture.is_pulse_capture == true) { in fsp_callback()
413 data->capture.pulse = in fsp_callback()
414 (data->capture.overflows * period) + p_args->capture; in fsp_callback()
415 data->capture.callback(dev, GPT_IO_PIN_GTIOCA, 0, in fsp_callback()
416 data->capture.pulse, 0, in fsp_callback()
417 data->capture.user_data); in fsp_callback()
419 data->capture.period = in fsp_callback()
420 (data->capture.overflows * period) + p_args->capture; in fsp_callback()
421 data->capture.callback(dev, GPT_IO_PIN_GTIOCA, data->capture.period, in fsp_callback()
422 0, 0, data->capture.user_data); in fsp_callback()
424 data->capture.overflows = 0U; in fsp_callback()
426 if (data->capture.continuous == false) { in fsp_callback()
430 } else if (p_args->event == TIMER_EVENT_CYCLE_END) { in fsp_callback()
431 data->capture.overflows++; in fsp_callback()
433 data->capture.callback(dev, GPT_IO_PIN_GTIOCA, 0, 0, -ECANCELED, in fsp_callback()
434 data->capture.user_data); in fsp_callback()
452 struct pwm_renesas_ra_data *data = dev->data; in pwm_renesas_ra_init()
453 const struct pwm_renesas_ra_config *cfg = dev->config; in pwm_renesas_ra_init()
456 if (!device_is_ready(cfg->clock_dev)) { in pwm_renesas_ra_init()
457 LOG_ERR("clock control device not ready"); in pwm_renesas_ra_init()
458 return -ENODEV; in pwm_renesas_ra_init()
461 err = clock_control_on(cfg->clock_dev, (clock_control_subsys_t)&cfg->clock_subsys); in pwm_renesas_ra_init()
467 err = pinctrl_apply_state(cfg->pincfg, PINCTRL_STATE_DEFAULT); in pwm_renesas_ra_init()
474 data->fsp_cfg.p_callback = fsp_callback; in pwm_renesas_ra_init()
475 data->fsp_cfg.p_context = dev; in pwm_renesas_ra_init()
478 data->fsp_cfg.p_extend = &data->extend_cfg; in pwm_renesas_ra_init()
480 err = R_GPT_Open(&data->fsp_ctrl, &data->fsp_cfg); in pwm_renesas_ra_init()
482 return -EIO; in pwm_renesas_ra_init()
501 IRQ_CONNECT(DT_INST_IRQ_BY_NAME(index, overflow, irq), \
502 DT_INST_IRQ_BY_NAME(index, overflow, priority), \
545 .cycle_end_ipl = DT_INST_IRQ_BY_NAME(index, overflow, priority), \
546 .cycle_end_irq = DT_INST_IRQ_BY_NAME(index, overflow, irq), \