Lines Matching +full:one +full:- +full:timer +full:- +full:only

4  * SPDX-License-Identifier: Apache-2.0
12 #include <zephyr/drivers/timer/system_timer.h>
18 BUILD_ASSERT(!IS_ENABLED(CONFIG_SMP), "XEC RTOS timer doesn't support SMP");
20 "XEC RTOS timer HW frequency is fixed at 32768");
25 /* Enable feature to halt timer on JTAG/SWD CPU halt */
35 * This driver enables the Microchip XEC 32KHz based RTOS timer as the Zephyr
36 * system timer. It supports both legacy ("tickful") mode as well as
37 * TICKLESS_KERNEL. The XEC RTOS timer is a down counter with a fixed
39 * timer driver.
49 * program a periodic timer at this fast rate.
67 * pcrs property at index 0 is register index into array of 32-bit PCR SLP_EN,
77 /* Mask off bits[31:28] of 32-bit count */
82 /* Adjust cycle count programmed into timer for HW restart latency */
86 /* max number of ticks we can load into the timer in one shot */
98 * One important invariant that must be observed: `total_cycles` + `cached_icr`
99 * is always an integral multiple of CYCLE_PER_TICK; this is, timer interrupts
100 * are only ever scheduled to occur at tick boundaries.
118 ECIA_XEC_REGS->GIRQ[girq - 8].SRC = BIT(bitpos); in girq_src_clr()
127 ECIA_XEC_REGS->GIRQ[girq - 8].EN_SET = BIT(bitpos); in girq_src_en()
136 ECIA_XEC_REGS->GIRQ[girq - 8].EN_CLR = BIT(bitpos); in girq_src_dis()
141 TIMER_REGS->CTRL = 0U; in timer_restart()
142 TIMER_REGS->CTRL = MCHP_RTMR_CTRL_BLK_EN; in timer_restart()
143 TIMER_REGS->PRLD = countdown; in timer_restart()
144 TIMER_REGS->CTRL = TIMER_START_VAL; in timer_restart()
148 * Read the RTOS timer counter handling the case where the timer
150 * The RTOS timer hardware must synchronize the write to its control register
154 * was on. We detect the timer is in the load state by checking the read-only
156 * is 0 and the START bit is set then the timer has been started and is in the
161 uint32_t ccr = TIMER_REGS->CNT; in timer_count()
163 if ((ccr == 0) && (TIMER_REGS->CTRL & MCHP_RTMR_CTRL_START)) { in timer_count()
177 * the tick announced as soon as possible, ideally no more than one tick
181 * RTMR counter register is read-only and is loaded from the preload
182 * register by a 0->1 transition of the control register start bit.
183 * Writing a new value to preload only takes effect once the count
198 * global objects safe from pre-emption? in sys_clock_set_timeout()
200 TIMER_REGS->CTRL = 0U; /* stop timer */ in sys_clock_set_timeout()
208 full_ticks = MAX_TICKS - 1; in sys_clock_set_timeout()
210 full_ticks = n - 1; in sys_clock_set_timeout()
220 TIMER_REGS->CTRL = 0u; in sys_clock_set_timeout()
225 temp += (cached_icr - ccr); in sys_clock_set_timeout()
229 partial_cycles = CYCLES_PER_TICK - (total_cycles % CYCLES_PER_TICK); in sys_clock_set_timeout()
231 /* adjust for up to one 32KHz cycle startup time */ in sys_clock_set_timeout()
234 temp -= TIMER_ADJUST_CYCLES; in sys_clock_set_timeout()
258 elapsed = (int32_t)total_cycles - (int32_t)last_announcement; in sys_clock_elapsed()
260 elapsed = -1 * elapsed; in sys_clock_elapsed()
263 ticks += cached_icr - ccr; in sys_clock_elapsed()
283 /* Restart the timer as early as possible to minimize drift... */ in xec_rtos_timer_isr()
292 /* handle wrap by using (power of 2) - 1 mask */ in xec_rtos_timer_isr()
293 ticks = total_cycles - last_announcement; in xec_rtos_timer_isr()
305 /* Non-tickless kernel build. */
315 /* Restart the timer as early as possible to minimize drift... */ in xec_rtos_timer_isr()
334 * Warning RTOS timer resolution is 30.5 us.
336 * 1. Kernel call to k_cycle_get_32() -> arch_k_cycle_get_32() -> here.
351 ret = (total_cycles + (cached_icr - ccr)) & TIMER_COUNT_MASK; in sys_clock_cycle_get_32()
368 TIMER_REGS->CTRL = 0U; in sys_clock_disable()
374 * We implement custom busy wait using a MEC1501 basic timer running on
376 * save/restore of the timer context.
380 * 32-bit basic timer 0 configured for 1MHz count up, auto-reload,
389 uint32_t start = BTMR32_0_REGS->CNT; in arch_busy_wait()
392 uint32_t curr = BTMR32_0_REGS->CNT; in arch_busy_wait()
394 if ((curr - start) >= usec_to_wait) { in arch_busy_wait()
408 TIMER_REGS->CTRL = 0u; in sys_clock_driver_init()
426 PCR_XEC_REGS->SLP_EN[BTMR32_0_PCR_REG_IDX] &= ~BIT(BTMR32_0_PCR_BITPOS); in sys_clock_driver_init()
428 BTMR32_0_REGS->CTRL = MCHP_BTMR_CTRL_SOFT_RESET; in sys_clock_driver_init()
429 BTMR32_0_REGS->CTRL = btmr_ctrl; in sys_clock_driver_init()
430 BTMR32_0_REGS->PRLD = UINT32_MAX; in sys_clock_driver_init()
434 /* wait for RTOS timer to load count register from preload */ in sys_clock_driver_init()
435 while (TIMER_REGS->CNT == 0) { in sys_clock_driver_init()
439 BTMR32_0_REGS->CTRL = btmr_ctrl; in sys_clock_driver_init()