Commit a0536658 authored by Mahesh Mahadevan's avatar Mahesh Mahadevan Committed by Henrik Brix Andersen
Browse files

drivers: timer: mcux_os_timer: Improve the overflow handling logic



Clear the remanining ticks value.

Signed-off-by: default avatarMahesh Mahadevan <mahesh.mahadevan@nxp.com>
parent aeb7cad1
Loading
Loading
Loading
Loading
+7 −5
Original line number Diff line number Diff line
@@ -191,7 +191,7 @@ static uint32_t mcux_lpc_ostick_compensate_system_timer(void)
	return 0;
}

static uint32_t mcux_os_timer_set_lp_counter_timeout(void)
static void mcux_os_timer_set_lp_counter_timeout(void)
{
	uint64_t timeout;

@@ -200,10 +200,9 @@ static uint32_t mcux_os_timer_set_lp_counter_timeout(void)
	 * from low power modes.
	 */
	if (pm_state_next_get(0)->state != PM_STATE_STANDBY) {
		return 1;
		return;
	}


	if (wait_forever) {
		timeout = UINT32_MAX;
	} else if (counter_remaining_ticks) {
@@ -222,7 +221,7 @@ static uint32_t mcux_os_timer_set_lp_counter_timeout(void)
		timeout = (((timeout / CYC_PER_TICK) * CYC_PER_TICK) * CYC_PER_US);
	}

	return mcux_lpc_ostick_set_counter_timeout(timeout);
	mcux_lpc_ostick_set_counter_timeout(timeout);
}
#else
#define mcux_os_timer_set_lp_counter_timeout(...) do { } while (0)
@@ -242,7 +241,8 @@ void sys_clock_set_timeout(int32_t ticks, bool idle)

#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(standby)) && CONFIG_PM
	/* We intercept calls from idle with a 0 tick count when PM=y */
	if (idle && (ticks == 0) && (mcux_os_timer_set_lp_counter_timeout() == 0)) {
	if (idle && (ticks == 0)) {
		mcux_os_timer_set_lp_counter_timeout();
		/* A low power counter has been started. No need to
		 * go further, simply return
		 */
@@ -277,6 +277,8 @@ void sys_clock_set_timeout(int32_t ticks, bool idle)

	OSTIMER_SetMatchValue(base, cyc + last_count - cyc_sys_compensated, NULL);

	counter_remaining_ticks = 0;

	k_spin_unlock(&lock, key);
}