Lines Matching full:lptim
28 #error Only one LPTIM instance should be enabled
31 #define LPTIM (LPTIM_TypeDef *) DT_INST_REG_ADDR(0) macro
34 #warning Kconfig for LPTIM source clock (LSI/LSE) is deprecated, use device tree.
54 * - system clock based on an LPTIM instance, clocked by LSI or LSE
55 * - prescaler is set to a 2^value from 1 (division of the LPTIM source clock by 1)
56 * to 128 (division of the LPTIM source clock by 128)
57 * - using LPTIM AutoReload capability to trig the IRQ (timeout irq)
96 * case because the LPTIM is not clocked in some low power mode state.
113 return (LL_LPTIM_IsActiveFlag_ARRM(LPTIM) && LL_LPTIM_IsEnabledIT_ARRM(LPTIM)); in arrm_state_get()
121 uint32_t autoreload = LL_LPTIM_GetAutoReload(LPTIM); in lptim_irq_handler()
123 if ((LL_LPTIM_IsActiveFlag_ARROK(LPTIM) != 0) in lptim_irq_handler()
124 && LL_LPTIM_IsEnabledIT_ARROK(LPTIM) != 0) { in lptim_irq_handler()
125 LL_LPTIM_ClearFlag_ARROK(LPTIM); in lptim_irq_handler()
129 LL_LPTIM_SetAutoReload(LPTIM, autoreload_next); in lptim_irq_handler()
139 LL_LPTIM_ClearFLAG_ARRM(LPTIM); in lptim_irq_handler()
170 if ((arr > 0) && (arr != LL_LPTIM_GetAutoReload(LPTIM))) { in lptim_set_autoreload()
173 LL_LPTIM_ClearFlag_ARROK(LPTIM); in lptim_set_autoreload()
174 LL_LPTIM_SetAutoReload(LPTIM, arr); in lptim_set_autoreload()
187 lp_time = LL_LPTIM_GetCounter(LPTIM); in z_clock_lptim_getcounter()
190 lp_time = LL_LPTIM_GetCounter(LPTIM); in z_clock_lptim_getcounter()
197 /* new LPTIM AutoReload value to set (aligned on Kernel ticks) */ in sys_clock_set_timeout()
247 /* Stop clocks for LPTIM, since RTC is used instead */ in sys_clock_set_timeout()
260 * is treated as a lptim off ; never waking up ; lptim not clocked anymore in sys_clock_set_timeout()
271 /* if LPTIM clock was previously stopped, it must now be restored */ in sys_clock_set_timeout()
290 uint32_t autoreload = LL_LPTIM_GetAutoReload(LPTIM); in sys_clock_set_timeout()
292 if (LL_LPTIM_IsActiveFlag_ARRM(LPTIM) in sys_clock_set_timeout()
317 * after current lptim to make sure we don't miss in sys_clock_set_timeout()
341 lp_time = LL_LPTIM_GetAutoReload(LPTIM) + 1; in sys_clock_lp_time_get()
367 /* gives the value of LPTIM counter (ms) in sys_clock_elapsed()
385 /* convert lptim count in a nb of hw cycles with precision */ in sys_clock_cycle_get_32()
398 while (LL_LPTIM_IsActiveFlag_DIEROK(LPTIM) == 0) { in stm32_lptim_wait_ready()
400 LL_LPTIM_ClearFlag_DIEROK(LPTIM); in stm32_lptim_wait_ready()
415 /* Enable LPTIM bus clock */ in sys_clock_driver_init()
425 /* Enable LPTIM clock source */ in sys_clock_driver_init()
433 /* Get LPTIM clock freq */ in sys_clock_driver_init()
442 * which will overflow the LPTIM counter. in sys_clock_driver_init()
443 * Previous LPTIM configuration using device tree was doing forcing this in sys_clock_driver_init()
446 * This issue will be fixed by implementation LPTIM prescaler support. in sys_clock_driver_init()
457 * max lptim period is 0xFFFF/(lptim_clock_freq/lptim_clock_presc) in sys_clock_driver_init()
465 * LPTIM is counting DT_INST_PROP(0, st_timeout), in sys_clock_driver_init()
473 /* Set LPTIM time base based on clock source freq */ in sys_clock_driver_init()
500 /* Actual lptim clock freq when the clock source is reduced by the prescaler */ in sys_clock_driver_init()
510 /* Enable the LPTIM wakeup EXTI line */ in sys_clock_driver_init()
514 /* configure the LPTIM counter */ in sys_clock_driver_init()
515 LL_LPTIM_SetClockSource(LPTIM, LL_LPTIM_CLK_SOURCE_INTERNAL); in sys_clock_driver_init()
516 /* the LPTIM clock freq is affected by the prescaler */ in sys_clock_driver_init()
517 LL_LPTIM_SetPrescaler(LPTIM, (__CLZ(__RBIT(lptim_clock_presc)) << LPTIM_CFGR_PRESC_Pos)); in sys_clock_driver_init()
522 LL_LPTIM_OC_SetPolarity(LPTIM, LL_LPTIM_CHANNEL_CH1, in sys_clock_driver_init()
525 LL_LPTIM_SetPolarity(LPTIM, LL_LPTIM_OUTPUT_POLARITY_REGULAR); in sys_clock_driver_init()
527 LL_LPTIM_SetUpdateMode(LPTIM, LL_LPTIM_UPDATE_MODE_IMMEDIATE); in sys_clock_driver_init()
528 LL_LPTIM_SetCounterMode(LPTIM, LL_LPTIM_COUNTER_MODE_INTERNAL); in sys_clock_driver_init()
529 LL_LPTIM_DisableTimeout(LPTIM); in sys_clock_driver_init()
531 LL_LPTIM_TrigSw(LPTIM); in sys_clock_driver_init()
536 /* Enable the LPTIM before proceeding with configuration */ in sys_clock_driver_init()
537 LL_LPTIM_Enable(LPTIM); in sys_clock_driver_init()
539 LL_LPTIM_DisableIT_CC1(LPTIM); in sys_clock_driver_init()
541 LL_LPTIM_ClearFLAG_CC1(LPTIM); in sys_clock_driver_init()
543 /* LPTIM interrupt set-up before enabling */ in sys_clock_driver_init()
545 LL_LPTIM_DisableIT_CMPM(LPTIM); in sys_clock_driver_init()
546 LL_LPTIM_ClearFLAG_CMPM(LPTIM); in sys_clock_driver_init()
550 LL_LPTIM_EnableIT_ARRM(LPTIM); in sys_clock_driver_init()
552 LL_LPTIM_ClearFLAG_ARRM(LPTIM); in sys_clock_driver_init()
555 LL_LPTIM_EnableIT_ARROK(LPTIM); in sys_clock_driver_init()
557 LL_LPTIM_ClearFlag_ARROK(LPTIM); in sys_clock_driver_init()
562 /* Enable the LPTIM counter */ in sys_clock_driver_init()
563 LL_LPTIM_Enable(LPTIM); in sys_clock_driver_init()
568 /* LPTIM is triggered on a LPTIM_TIMEBASE period */ in sys_clock_driver_init()
571 /* nb of LPTIM counter unit per kernel tick (depends on lptim clock prescaler) */ in sys_clock_driver_init()
573 /* LPTIM is triggered on a Tick period */ in sys_clock_driver_init()
577 /* Start the LPTIM counter in continuous mode */ in sys_clock_driver_init()
578 LL_LPTIM_StartCounter(LPTIM, LL_LPTIM_OPERATING_MODE_CONTINUOUS); in sys_clock_driver_init()
581 /* stop LPTIM during DEBUG */ in sys_clock_driver_init()
611 /* Get current value for standby timer and reset LPTIM counter value in sys_clock_idle_exit()
614 LL_LPTIM_ResetCounter(LPTIM); in sys_clock_idle_exit()
629 /* Convert standby time in LPTIM cnt */ in sys_clock_idle_exit()
632 /* Add the LPTIM cnt pre standby */ in sys_clock_idle_exit()