Skip to content

Commit 1ddc69f

Browse files
committed
drivers: timer: ostimer: Change to use reset API
Use reset API to reset OSTIMER for better portability. Improve RW610 for this change. Signed-off-by: Jason Yu <zejiang.yu@nxp.com>
1 parent 4d7091d commit 1ddc69f

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

drivers/timer/mcux_os_timer.c

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <zephyr/spinlock.h>
1717
#include <zephyr/drivers/counter.h>
1818
#include <zephyr/pm/pm.h>
19+
#include <zephyr/drivers/reset.h>
1920
#include "fsl_ostimer.h"
2021
#if !defined(CONFIG_SOC_FAMILY_MCXN) && !defined(CONFIG_SOC_FAMILY_MCXA)
2122
#include "fsl_power.h"
@@ -142,12 +143,12 @@ static uint32_t mcux_lpc_ostick_set_counter_timeout(int32_t curr_timeout)
142143
}
143144
counter_running = true;
144145

145-
if (IS_ENABLED(CONFIG_MCUX_OS_TIMER_PM_POWERED_OFF)) {
146-
/* Capture the current timer value for cases where it loses its state
147-
* in low power modes.
148-
*/
149-
cyc_sys_compensated += OSTIMER_GetCurrentTimerValue(base);
150-
}
146+
#if defined(CONFIG_MCUX_OS_TIMER_PM_POWERED_OFF)
147+
/* Capture the current timer value for cases where it loses its state
148+
* in low power modes.
149+
*/
150+
cyc_sys_compensated += OSTIMER_GetCurrentTimerValue(base);
151+
#endif /* defined(CONFIG_MCUX_OS_TIMER_PM_POWERED_OFF) */
151152

152153
return 0;
153154
}
@@ -179,12 +180,15 @@ static uint32_t mcux_lpc_ostick_compensate_system_timer(void)
179180
}
180181
slept_time_us = counter_ticks_to_us(counter_dev, slept_time_ticks);
181182
cyc_sys_compensated += CYC_PER_US * slept_time_us;
182-
if (IS_ENABLED(CONFIG_MCUX_OS_TIMER_PM_POWERED_OFF)) {
183-
/* Reset the OS Timer to a known state */
184-
RESET_PeripheralReset(kOSEVENT_TIMER_RST_SHIFT_RSTn);
185-
/* Reactivate os_timer for cases where it loses its state */
186-
OSTIMER_Init(base);
187-
}
183+
184+
#if defined(CONFIG_MCUX_OS_TIMER_PM_POWERED_OFF)
185+
/* Reset the OS Timer to a known state */
186+
const struct reset_dt_spec reset = RESET_DT_SPEC_GET(DT_DRV_INST(0));
187+
188+
reset_line_toggle_dt(&reset);
189+
/* Reactivate os_timer for cases where it loses its state */
190+
OSTIMER_Init(base);
191+
#endif /* defined(CONFIG_MCUX_OS_TIMER_PM_POWERED_OFF) */
188192

189193
/* Announce the time slept to the kernel*/
190194
mcux_lpc_ostick_isr(NULL);

dts/arm/nxp/nxp_rw6xx_common.dtsi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,7 @@
610610
compatible = "nxp,os-timer";
611611
reg = <0x13b000 0x1000>;
612612
interrupts = <41 0>;
613+
resets = <&rstctl1 NXP_SYSCON_RESET(0, 27)>;
613614
status = "disabled";
614615
};
615616

soc/nxp/rw/Kconfig.defconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ config COUNTER
8888
config MCUX_OS_TIMER_PM_POWERED_OFF
8989
default y
9090

91+
# When MCUX_OS_TIMER_PM_POWERED_OFF is used, reset function
92+
# is needed to place OS_TIMER in a known state after power cycling
93+
config RESET
94+
default y if MCUX_OS_TIMER_PM_POWERED_OFF
95+
9196
# PM code that runs from the idle loop has a large
9297
# footprint. Hence increase the size when PM is enabled.
9398
config IDLE_STACK_SIZE

0 commit comments

Comments
 (0)