Lines Matching +full:timer +full:- +full:triggered

2  * Copyright (c) 2022 KT-Elektronik, Klaucke und Partner GmbH
3 * SPDX-License-Identifier: Apache-2.0
9 * Counter driver for the Quad Timer through the MCUxpresso SDK. Based mainly on counter_mcux_gpt.c
11 * Each quad timer module has four channels (0-3) that can operate independently, but the Zephyr
12 * counter-API does not support starting or stopping different channels independently. Hence, each
50 * @brief ISR for a specific timer channel
52 * @param dev timer channel device
56 const struct mcux_qtmr_config *config = dev->config; in mcux_qtmr_timer_handler()
57 struct mcux_qtmr_data *data = dev->data; in mcux_qtmr_timer_handler()
58 uint32_t current = QTMR_GetCurrentTimerCount(config->base, config->channel); in mcux_qtmr_timer_handler()
60 QTMR_ClearStatusFlags(config->base, config->channel, status); in mcux_qtmr_timer_handler()
63 if ((status & kQTMR_Compare1Flag) && data->alarm_callback) { in mcux_qtmr_timer_handler()
64 QTMR_DisableInterrupts(config->base, config->channel, in mcux_qtmr_timer_handler()
66 data->interrupt_mask &= ~kQTMR_Compare1InterruptEnable; in mcux_qtmr_timer_handler()
67 counter_alarm_callback_t alarm_cb = data->alarm_callback; in mcux_qtmr_timer_handler()
69 data->alarm_callback = NULL; in mcux_qtmr_timer_handler()
70 alarm_cb(dev, config->channel, current, data->alarm_user_data); in mcux_qtmr_timer_handler()
73 if ((status & kQTMR_OverflowFlag) && data->top_callback) { in mcux_qtmr_timer_handler()
74 data->top_callback(dev, data->top_user_data); in mcux_qtmr_timer_handler()
81 * @param timers array containing the counter devices for each channel of the timer module
85 /* the interrupt can be triggered by any of the four channels of the QTMR. Check status in mcux_qtmr_isr()
86 * of all channels and trigger the ISR for the channel(s) that has/have triggered the in mcux_qtmr_isr()
91 const struct mcux_qtmr_config *config = timers[ch]->config; in mcux_qtmr_isr()
92 struct mcux_qtmr_data *data = timers[ch]->data; in mcux_qtmr_isr()
94 uint32_t channel_status = QTMR_GetStatus(config->base, ch); in mcux_qtmr_isr()
96 if ((channel_status & data->interrupt_mask) != 0) { in mcux_qtmr_isr()
126 const struct mcux_qtmr_config *config = dev->config; in DT_INST_FOREACH_STATUS_OKAY()
128 QTMR_StartTimer(config->base, config->channel, config->mode); in DT_INST_FOREACH_STATUS_OKAY()
135 const struct mcux_qtmr_config *config = dev->config; in mcux_qtmr_stop()
137 QTMR_StopTimer(config->base, config->channel); in mcux_qtmr_stop()
144 const struct mcux_qtmr_config *config = dev->config; in mcux_qtmr_get_value()
146 *ticks = QTMR_GetCurrentTimerCount(config->base, config->channel); in mcux_qtmr_get_value()
153 const struct mcux_qtmr_config *config = dev->config; in mcux_qtmr_set_alarm()
154 struct mcux_qtmr_data *data = dev->data; in mcux_qtmr_set_alarm()
160 return -EINVAL; in mcux_qtmr_set_alarm()
163 if (data->alarm_callback) { in mcux_qtmr_set_alarm()
164 return -EBUSY; in mcux_qtmr_set_alarm()
167 data->alarm_callback = alarm_cfg->callback; in mcux_qtmr_set_alarm()
168 data->alarm_user_data = alarm_cfg->user_data; in mcux_qtmr_set_alarm()
170 current = QTMR_GetCurrentTimerCount(config->base, config->channel); in mcux_qtmr_set_alarm()
171 ticks = alarm_cfg->ticks; in mcux_qtmr_set_alarm()
173 if ((alarm_cfg->flags & COUNTER_ALARM_CFG_ABSOLUTE) == 0) { in mcux_qtmr_set_alarm()
177 /* this timer always counts up. */ in mcux_qtmr_set_alarm()
178 config->base->CHANNEL[config->channel].COMP1 = ticks; in mcux_qtmr_set_alarm()
180 data->interrupt_mask |= kQTMR_Compare1InterruptEnable; in mcux_qtmr_set_alarm()
181 QTMR_EnableInterrupts(config->base, config->channel, data->interrupt_mask); in mcux_qtmr_set_alarm()
188 const struct mcux_qtmr_config *config = dev->config; in mcux_qtmr_cancel_alarm()
189 struct mcux_qtmr_data *data = dev->data; in mcux_qtmr_cancel_alarm()
193 return -EINVAL; in mcux_qtmr_cancel_alarm()
196 QTMR_DisableInterrupts(config->base, config->channel, data->interrupt_mask); in mcux_qtmr_cancel_alarm()
197 data->interrupt_mask &= ~kQTMR_Compare1InterruptEnable; in mcux_qtmr_cancel_alarm()
198 data->alarm_callback = NULL; in mcux_qtmr_cancel_alarm()
205 const struct mcux_qtmr_config *config = dev->config; in mcux_qtmr_get_pending_int()
207 return QTMR_GetStatus(config->base, config->channel); in mcux_qtmr_get_pending_int()
213 const struct mcux_qtmr_config *config = dev->config; in mcux_qtmr_set_top_value()
214 struct mcux_qtmr_data *data = dev->data; in mcux_qtmr_set_top_value()
216 if (cfg->ticks != config->info.max_top_value) { in mcux_qtmr_set_top_value()
218 config->info.max_top_value); in mcux_qtmr_set_top_value()
219 return -ENOTSUP; in mcux_qtmr_set_top_value()
222 if ((cfg->flags & COUNTER_TOP_CFG_DONT_RESET) == 0) { in mcux_qtmr_set_top_value()
223 if ((config->base->CHANNEL[config->channel].CTRL & TMR_CTRL_DIR_MASK) != 0U) { in mcux_qtmr_set_top_value()
225 config->base->CHANNEL[config->channel].CNTR = UINT16_MAX; in mcux_qtmr_set_top_value()
228 config->base->CHANNEL[config->channel].CNTR = 0; in mcux_qtmr_set_top_value()
232 if (cfg->callback != NULL) { in mcux_qtmr_set_top_value()
233 data->top_callback = cfg->callback; in mcux_qtmr_set_top_value()
234 data->top_user_data = cfg->user_data; in mcux_qtmr_set_top_value()
236 data->interrupt_mask |= kQTMR_OverflowInterruptEnable; in mcux_qtmr_set_top_value()
237 QTMR_EnableInterrupts(config->base, config->channel, kQTMR_OverflowInterruptEnable); in mcux_qtmr_set_top_value()
245 const struct mcux_qtmr_config *config = dev->config; in mcux_qtmr_get_top_value()
247 return config->info.max_top_value; in mcux_qtmr_get_top_value()
252 struct mcux_qtmr_data *data = dev->data; in mcux_qtmr_get_freq()
254 return data->freq; in mcux_qtmr_get_freq()
265 const struct mcux_qtmr_config *config = dev->config; in mcux_qtmr_init()
266 struct mcux_qtmr_data *data = dev->data; in mcux_qtmr_init()
268 if (config->qtmr_config.primarySource < kQTMR_ClockDivide_1) { in mcux_qtmr_init()
270 data->freq = config->info.freq; in mcux_qtmr_init()
273 if (!device_is_ready(config->clock_dev)) { in mcux_qtmr_init()
275 return -ENODEV; in mcux_qtmr_init()
278 if (clock_control_get_rate(config->clock_dev, config->clock_subsys, in mcux_qtmr_init()
279 &data->freq)) { in mcux_qtmr_init()
280 return -EINVAL; in mcux_qtmr_init()
283 data->freq /= qtmr_primary_source_divider[config->qtmr_config.primarySource - in mcux_qtmr_init()
287 QTMR_Init(config->base, config->channel, &config->qtmr_config); in mcux_qtmr_init()