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

4  * SPDX-License-Identifier: Apache-2.0
20 /* DW APB timer register offsets */
30 /* DW APB timer control flags */
35 /* DW APB timer modes */
39 #define DEV_CFG(_dev) ((const struct counter_dw_timer_config *)(_dev)->config)
40 #define DEV_DATA(_dev) ((struct counter_dw_timer_drv_data *const)(_dev)->data)
48 /* clock frequency of timer */
53 /* identifier for timer to get clock freq from clk manager */
71 /* clock frequency of timer */
90 counter_alarm_callback_t alarm_cb = data->alarm_cb; in counter_dw_timer_irq_handler()
97 key = k_spin_lock(&data->lock); in counter_dw_timer_irq_handler()
102 if (data->alarm_cb) { in counter_dw_timer_irq_handler()
105 data->alarm_cb = NULL; in counter_dw_timer_irq_handler()
106 alarm_cb(timer_dev, 0, ticks, data->prv_data); in counter_dw_timer_irq_handler()
108 } else if (data->top_cb) { in counter_dw_timer_irq_handler()
109 data->top_cb(timer_dev, data->prv_data); in counter_dw_timer_irq_handler()
112 k_spin_unlock(&data->lock, key); in counter_dw_timer_irq_handler()
119 /* disable timer before starting in free-running mode */ in counter_dw_timer_start()
122 /* starting timer in free running mode */ in counter_dw_timer_start()
127 /* enable timer */ in counter_dw_timer_start()
136 /* stop timer */ in counter_dw_timer_disable()
171 return -EINVAL; in counter_dw_timer_set_top_value()
175 if (top_cfg->flags & COUNTER_TOP_CFG_DONT_RESET) { in counter_dw_timer_set_top_value()
177 return -ENOTSUP; in counter_dw_timer_set_top_value()
180 key = k_spin_lock(&data->lock); in counter_dw_timer_set_top_value()
183 if (data->alarm_cb) { in counter_dw_timer_set_top_value()
184 k_spin_unlock(&data->lock, key); in counter_dw_timer_set_top_value()
186 return -EBUSY; in counter_dw_timer_set_top_value()
189 if (!top_cfg->callback) { in counter_dw_timer_set_top_value()
197 data->top_cb = top_cfg->callback; in counter_dw_timer_set_top_value()
198 data->prv_data = top_cfg->user_data; in counter_dw_timer_set_top_value()
200 /* top value can be loaded only when timer is stopped and re-enabled */ in counter_dw_timer_set_top_value()
203 /* configuring timer in user-defined mode */ in counter_dw_timer_set_top_value()
207 sys_write32(top_cfg->ticks, reg_base + LOADCOUNT_OFST); in counter_dw_timer_set_top_value()
210 k_spin_unlock(&data->lock, key); in counter_dw_timer_set_top_value()
225 return -EINVAL; in counter_dw_timer_set_alarm()
229 if (!alarm_cfg->callback) { in counter_dw_timer_set_alarm()
231 return -EINVAL; in counter_dw_timer_set_alarm()
234 /* absolute alarm is not supported as interrupts are triggered in counter_dw_timer_set_alarm()
237 if (alarm_cfg->flags & COUNTER_ALARM_CFG_ABSOLUTE) { in counter_dw_timer_set_alarm()
239 return -ENOTSUP; in counter_dw_timer_set_alarm()
242 key = k_spin_lock(&data->lock); in counter_dw_timer_set_alarm()
245 if (data->alarm_cb != NULL) { in counter_dw_timer_set_alarm()
247 k_spin_unlock(&data->lock, key); in counter_dw_timer_set_alarm()
248 return -EBUSY; in counter_dw_timer_set_alarm()
251 data->alarm_cb = alarm_cfg->callback; in counter_dw_timer_set_alarm()
252 data->prv_data = alarm_cfg->user_data; in counter_dw_timer_set_alarm()
256 /* start timer in user-defined mode */ in counter_dw_timer_set_alarm()
260 sys_write32(alarm_cfg->ticks, reg_base + LOADCOUNT_OFST); in counter_dw_timer_set_alarm()
263 k_spin_unlock(&data->lock, key); in counter_dw_timer_set_alarm()
275 key = k_spin_lock(&data->lock); in counter_dw_timer_cancel_alarm()
279 data->alarm_cb = NULL; in counter_dw_timer_cancel_alarm()
280 data->prv_data = NULL; in counter_dw_timer_cancel_alarm()
282 k_spin_unlock(&data->lock, key); in counter_dw_timer_cancel_alarm()
292 return data->freq; in counter_dw_timer_get_freq()
296 return config->freq; in counter_dw_timer_get_freq()
326 if (!device_is_ready(timer_config->clk_dev)) { in counter_dw_timer_init()
328 return -ENODEV; in counter_dw_timer_init()
330 ret = clock_control_get_rate(timer_config->clk_dev, in counter_dw_timer_init()
331 timer_config->clkid, &data->freq); in counter_dw_timer_init()
338 /* Reset timer only if reset controller driver is supported */ in counter_dw_timer_init()
340 if (timer_config->reset.dev != NULL) { in counter_dw_timer_init()
341 if (!device_is_ready(timer_config->reset.dev)) { in counter_dw_timer_init()
343 return -ENODEV; in counter_dw_timer_init()
346 ret = reset_line_toggle(timer_config->reset.dev, timer_config->reset.id); in counter_dw_timer_init()
348 LOG_ERR("Timer reset failed"); in counter_dw_timer_init()
354 timer_config->irq_config(); in counter_dw_timer_init()