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

4  * SPDX-License-Identifier: Apache-2.0
14 * 64/32-bit timers in Nuvoton NPCX series. Via these two kinds of timers, the
18 * - A system timer based on an ITIM64 (Internal 64-bit timer) instance, clocked
20 * - Provide a 64-bit cycles reading and ticks computation based on it.
21 * - Its prescaler is set to 1 and provide the kernel cycles reading without
23 * - After ec entered "sleep/deep sleep" power state which is used for better
26 * - A event timer based on an ITIM32 (Internal 32-bit timer) instance, clocked
29 * - Provide a system clock timeout notification. In its ISR, the driver informs
31 * - Its prescaler is set to 1 and the formula between event timer's cycles and
33 * - Compensate reading of ITIM64 which clock is gating after ec entered
39 #include <zephyr/drivers/timer/system_timer.h>
72 /* Announced cycles in system timer before executing sys_clock_announce() */
77 /* Current target cycles of time-out signal in event timer */
79 /* Total cycles of system timer stopped in "sleep/deep sleep" mode */
81 /* Current cycles in event timer when ec entered "sleep/deep sleep" mode */
89 /* Read 64-bit counter value from two 32-bit registers */ in npcx_itim_get_sys_cyc64()
91 cnt64h_check = sys_tmr->ITCNT64H; in npcx_itim_get_sys_cyc64()
92 cnt64l = sys_tmr->ITCNT64L; in npcx_itim_get_sys_cyc64()
93 cnt64h = sys_tmr->ITCNT64H; in npcx_itim_get_sys_cyc64()
96 cnt64h = NPCX_ITIM64_MAX_HALF_CNT - cnt64h; in npcx_itim_get_sys_cyc64()
97 cnt64l = NPCX_ITIM64_MAX_HALF_CNT - cnt64l + 1; in npcx_itim_get_sys_cyc64()
99 /* Return current value of 64-bit counter value of system timer */ in npcx_itim_get_sys_cyc64()
112 /* Enable event timer and wait for it to take effect */ in npcx_itim_evt_enable()
113 evt_tmr->ITCTS32 |= BIT(NPCX_ITCTSXX_ITEN); in npcx_itim_evt_enable()
120 while (!IS_BIT_SET(evt_tmr->ITCTS32, NPCX_ITCTSXX_ITEN)) { in npcx_itim_evt_enable()
121 if (npcx_itim_get_sys_cyc64() - cyc_start > in npcx_itim_evt_enable()
124 if (!IS_BIT_SET(evt_tmr->ITCTS32, NPCX_ITCTSXX_ITEN)) { in npcx_itim_evt_enable()
125 LOG_ERR("Timeout: enabling EVT timer!"); in npcx_itim_evt_enable()
126 return -ETIMEDOUT; in npcx_itim_evt_enable()
136 /* Disable event timer and no need to wait for it to take effect */ in npcx_itim_evt_disable()
137 evt_tmr->ITCTS32 &= ~BIT(NPCX_ITCTSXX_ITEN); in npcx_itim_evt_disable()
144 * Get desired cycles of event timer from the requested ticks which in npcx_itim_start_evt_tmr_by_tick()
165 dcycles = next_cycs - curr; in npcx_itim_start_evt_tmr_by_tick()
173 /* Disable event timer if needed before configuring counter */ in npcx_itim_start_evt_tmr_by_tick()
174 if (IS_BIT_SET(evt_tmr->ITCTS32, NPCX_ITCTSXX_ITEN)) { in npcx_itim_start_evt_tmr_by_tick()
178 /* Upload counter of event timer */ in npcx_itim_start_evt_tmr_by_tick()
179 evt_tmr->ITCNT32 = MAX(cyc_evt_timeout - 1, 1); in npcx_itim_start_evt_tmr_by_tick()
181 /* Enable event timer and start ticking */ in npcx_itim_start_evt_tmr_by_tick()
192 evt_tmr->ITCTS32 |= BIT(NPCX_ITCTSXX_TO_STS); in npcx_itim_evt_isr()
197 uint32_t delta_ticks = (uint32_t)((curr - cyc_sys_announced) / SYS_CYCLES_PER_TICK); in npcx_itim_evt_isr()
207 /* Enable event timer for ticking and wait to it take effect */ in npcx_itim_evt_isr()
232 /* Return current value of 32-bit counter of event timer */ in npcx_itim_get_evt_cyc32()
239 uint8_t sys_cts = evt_tmr->ITCTS32; in npcx_itim_evt_elapsed_cyc32()
242 /* Event has been triggered but timer ISR doesn't handle it */ in npcx_itim_evt_elapsed_cyc32()
246 cnt2 = cyc_evt_timeout - cnt2 - 1; in npcx_itim_evt_elapsed_cyc32()
249 /* Return elapsed cycles of 32-bit counter of event timer */ in npcx_itim_evt_elapsed_cyc32()
254 /* System timer api functions */
265 /* Start a event timer in ticks */ in sys_clock_set_timeout()
280 uint64_t delta_cycle = npcx_itim_get_sys_cyc64() - cyc_sys_announced; in sys_clock_elapsed()
297 /* Return how many cycles since system kernel timer start counting */ in sys_clock_cycle_get_32()
308 /* Return how many cycles since system kernel timer start counting */ in sys_clock_cycle_get_64()
312 /* Platform specific system timer functions */
321 uint32_t cyc_evt_elapsed_in_deep = npcx_itim_evt_elapsed_cyc32() - in npcx_clock_compensate_system_timer()
342 return -ENODEV; in sys_clock_driver_init()
350 LOG_ERR("Turn on timer %d clock failed.", i); in sys_clock_driver_init()
356 * In npcx series, we use ITIM64 as system kernel timer. Its source in sys_clock_driver_init()
369 return -EINVAL; in sys_clock_driver_init()
373 * Step 1. Use a ITIM64 timer as system kernel timer for counting. in sys_clock_driver_init()
374 * Configure 64-bit timer counter and its prescaler to 1 first. in sys_clock_driver_init()
376 sys_tmr->ITPRE64 = 0; in sys_clock_driver_init()
377 sys_tmr->ITCNT64L = NPCX_ITIM64_MAX_HALF_CNT; in sys_clock_driver_init()
378 sys_tmr->ITCNT64H = NPCX_ITIM64_MAX_HALF_CNT; in sys_clock_driver_init()
383 sys_tmr->ITCTS64 = BIT(NPCX_ITCTSXX_TO_STS); in sys_clock_driver_init()
384 /* Enable 64-bit timer and start ticking */ in sys_clock_driver_init()
385 sys_tmr->ITCTS64 |= BIT(NPCX_ITCTSXX_ITEN); in sys_clock_driver_init()
388 * Step 2. Use a ITIM32 timer for event handling (ex. timeout event). in sys_clock_driver_init()
389 * Configure 32-bit timer's prescaler to 1 first. in sys_clock_driver_init()
391 evt_tmr->ITPRE32 = 0; in sys_clock_driver_init()
394 * interrupt/wake-up sources, and clear timeout status bit before in sys_clock_driver_init()
397 evt_tmr->ITCTS32 = BIT(NPCX_ITCTSXX_CKSEL) | BIT(NPCX_ITCTSXX_TO_WUE) in sys_clock_driver_init()
403 /* Configure event timer's ISR */ in sys_clock_driver_init()
406 /* Enable event timer interrupt */ in sys_clock_driver_init()
410 /* Start a event timer in one tick */ in sys_clock_driver_init()