driver: timer: fix accumulated counter increment

The current value of the counter must not be added to the accumulator.
It will be added when calling z_timer_cycle_get_32.

Signed-off-by: Julien D'Ascenzio <julien.dascenzio@paratronic.fr>
This commit is contained in:
Julien D'Ascenzio 2020-05-08 11:39:46 +02:00 committed by Carles Cufí
commit 3894c6ee50

View file

@ -47,32 +47,21 @@ static void lptim_irq_handler(struct device *unused)
k_spinlock_key_t key = k_spin_lock(&lock); k_spinlock_key_t key = k_spin_lock(&lock);
/* LPTIM1 CNT register is already reset after one autoreload */
volatile u32_t lp_time = LL_LPTIM_GetCounter(LPTIM1);
/* It should be noted that to read reliably the content
* of the LPTIM_CNT register, two successive read accesses
* must be performed and compared
*/
while (lp_time != LL_LPTIM_GetCounter(LPTIM1)) {
lp_time = LL_LPTIM_GetCounter(LPTIM1);
}
lp_time += LL_LPTIM_GetAutoReload(LPTIM1) + 1;
/* do not change ARR yet, z_clock_announce will do */ /* do not change ARR yet, z_clock_announce will do */
LL_LPTIM_ClearFLAG_ARRM(LPTIM1); LL_LPTIM_ClearFLAG_ARRM(LPTIM1);
/* increase the total nb of lptim count /* increase the total nb of autoreload count
* used in the z_timer_cycle_get_32() function. * used in the z_timer_cycle_get_32() function.
* Reading the CNT register gives a reliable value * Reading the CNT register gives a reliable value
*/ */
accumulated_lptim_cnt += lp_time; u32_t autoreload = LL_LPTIM_GetAutoReload(LPTIM1) + 1;
accumulated_lptim_cnt += autoreload;
k_spin_unlock(&lock, key); k_spin_unlock(&lock, key);
/* announce the elapsed time in ms (count register is 16bit) */ /* announce the elapsed time in ms (count register is 16bit) */
u32_t dticks = (lp_time u32_t dticks = (autoreload
* CONFIG_SYS_CLOCK_TICKS_PER_SEC) * CONFIG_SYS_CLOCK_TICKS_PER_SEC)
/ LPTIM_CLOCK; / LPTIM_CLOCK;