From 0144c18f8e2bfd48fa5fb609dfe464071aecefec Mon Sep 17 00:00:00 2001 From: Alistair Francis Date: Wed, 18 Dec 2024 21:20:13 +1000 Subject: [PATCH 1/2] chips: apollo3: stimer: Support timer reset Signed-off-by: Alistair Francis --- chips/apollo3/src/stimer.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/chips/apollo3/src/stimer.rs b/chips/apollo3/src/stimer.rs index 3c48302a4e..deb5a47359 100644 --- a/chips/apollo3/src/stimer.rs +++ b/chips/apollo3/src/stimer.rs @@ -153,7 +153,8 @@ impl<'a> Counter<'a> for STimer<'a> { } fn reset(&self) -> Result<(), ErrorCode> { - Err(ErrorCode::FAIL) + self.registers.stcfg.write(STCFG::CLEAR::SET); + Ok(()) } fn is_running(&self) -> bool { From cc727b87beadf439b51ee66a909df06c9b6bd9e4 Mon Sep 17 00:00:00 2001 From: Alistair Francis Date: Wed, 18 Dec 2024 21:20:18 +1000 Subject: [PATCH 2/2] chips: apollo3: stimer: Reset timer on creation When creating the STimer reset the count to zero. This way the timer roughly aligns to the total time the system has been running, otherwise the timer starts at a random value. Signed-off-by: Alistair Francis --- chips/apollo3/src/stimer.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/chips/apollo3/src/stimer.rs b/chips/apollo3/src/stimer.rs index deb5a47359..820afba9e8 100644 --- a/chips/apollo3/src/stimer.rs +++ b/chips/apollo3/src/stimer.rs @@ -102,11 +102,16 @@ pub struct STimer<'a> { impl<'a> STimer<'a> { // Unsafe bc of use of STIMER_BASE internally - pub const fn new() -> STimer<'a> { - STimer { + pub fn new() -> STimer<'a> { + let timer = STimer { registers: STIMER_BASE, client: OptionalCell::empty(), - } + }; + + // Reset so that time starts at 0 + let _ = timer.reset(); + + timer } pub fn handle_interrupt(&self) {