Lines Matching full:counter

11  * @brief Microchip XEC Counter driver
17 * - Interrupts are triggered (if enabled) when the counter
21 * the counter values are changed so that interrupts are triggered
29 #include <zephyr/drivers/counter.h>
63 struct btmr_regs *counter = COUNTER_XEC_REG_BASE(dev); in counter_xec_start() local
65 if (counter->CTRL & MCHP_BTMR_CTRL_ENABLE) { in counter_xec_start()
69 counter->CTRL |= (MCHP_BTMR_CTRL_ENABLE | MCHP_BTMR_CTRL_START); in counter_xec_start()
71 LOG_DBG("%p Counter started", dev); in counter_xec_start()
78 struct btmr_regs *counter = COUNTER_XEC_REG_BASE(dev); in counter_xec_stop() local
81 if (!(counter->CTRL & MCHP_BTMR_CTRL_ENABLE)) { in counter_xec_stop()
86 reg = counter->CTRL; in counter_xec_stop()
92 counter->CTRL = reg; in counter_xec_stop()
94 counter->IEN = MCHP_BTMR_INTDIS; in counter_xec_stop()
95 counter->CNT = counter->PRLD; in counter_xec_stop()
97 LOG_DBG("%p Counter stopped", dev); in counter_xec_stop()
104 struct btmr_regs *counter = COUNTER_XEC_REG_BASE(dev); in counter_xec_get_value() local
106 *ticks = counter->CNT; in counter_xec_get_value()
113 struct btmr_regs *counter = COUNTER_XEC_REG_BASE(dev); in counter_xec_set_alarm() local
121 /* Interrupts are only triggered when the counter reaches 0. in counter_xec_set_alarm()
136 if (alarm_cfg->ticks > counter->PRLD) { in counter_xec_set_alarm()
140 counter->CNT = alarm_cfg->ticks; in counter_xec_set_alarm()
145 counter->IEN = MCHP_BTMR_INTEN; in counter_xec_set_alarm()
147 LOG_DBG("%p Counter alarm set to %u ticks", dev, alarm_cfg->ticks); in counter_xec_set_alarm()
149 counter->CTRL |= MCHP_BTMR_CTRL_START; in counter_xec_set_alarm()
157 struct btmr_regs *counter = COUNTER_XEC_REG_BASE(dev); in counter_xec_cancel_alarm() local
165 counter->CTRL &= ~MCHP_BTMR_CTRL_START; in counter_xec_cancel_alarm()
166 counter->IEN = MCHP_BTMR_INTDIS; in counter_xec_cancel_alarm()
171 LOG_DBG("%p Counter alarm canceled", dev); in counter_xec_cancel_alarm()
178 struct btmr_regs *counter = COUNTER_XEC_REG_BASE(dev); in counter_xec_get_pending_int() local
180 return counter->STS; in counter_xec_get_pending_int()
185 struct btmr_regs *counter = COUNTER_XEC_REG_BASE(dev); in counter_xec_get_top_value() local
187 return counter->PRLD; in counter_xec_get_top_value()
193 struct btmr_regs *counter = COUNTER_XEC_REG_BASE(dev); in counter_xec_set_top_value() local
207 restart = ((counter->CTRL & MCHP_BTMR_CTRL_START) != 0U); in counter_xec_set_top_value()
209 counter->CTRL &= ~MCHP_BTMR_CTRL_START; in counter_xec_set_top_value()
212 if (counter->CNT > cfg->ticks) { in counter_xec_set_top_value()
216 counter->CNT = cfg->ticks; in counter_xec_set_top_value()
220 counter->CNT = cfg->ticks; in counter_xec_set_top_value()
223 counter->PRLD = cfg->ticks; in counter_xec_set_top_value()
229 counter->IEN = MCHP_BTMR_INTEN; in counter_xec_set_top_value()
230 counter->CTRL |= MCHP_BTMR_CTRL_AUTO_RESTART; in counter_xec_set_top_value()
232 counter->IEN = MCHP_BTMR_INTDIS; in counter_xec_set_top_value()
233 counter->CTRL &= ~MCHP_BTMR_CTRL_AUTO_RESTART; in counter_xec_set_top_value()
236 LOG_DBG("%p Counter top value was set to %u", dev, cfg->ticks); in counter_xec_set_top_value()
239 counter->CTRL |= MCHP_BTMR_CTRL_START; in counter_xec_set_top_value()
247 struct btmr_regs *counter = COUNTER_XEC_REG_BASE(dev); in counter_xec_isr() local
253 counter->STS = MCHP_BTMR_STS_ACTIVE; in counter_xec_isr()
261 LOG_DBG("%p Counter ISR", dev); in counter_xec_isr()
265 counter->IEN = MCHP_BTMR_INTDIS; in counter_xec_isr()
271 alarm_cb(dev, 0, counter->CNT, user_data); in counter_xec_isr()
290 struct btmr_regs *counter = COUNTER_XEC_REG_BASE(dev); in counter_xec_init() local
295 counter->CTRL &= ~MCHP_BTMR_CTRL_COUNT_UP; in counter_xec_init()
296 counter->CTRL |= (counter_cfg->prescaler << MCHP_BTMR_CTRL_PRESCALE_POS) & in counter_xec_init()
299 /* Set preload and actually pre-load the counter */ in counter_xec_init()
300 counter->PRLD = counter_cfg->info.max_top_value; in counter_xec_init()
301 counter->CNT = counter_cfg->info.max_top_value; in counter_xec_init()