aboutsummaryrefslogtreecommitdiff
path: root/platforms/chibios/timer.c
diff options
context:
space:
mode:
authorNick Brassel <nick@tzarc.org>2024-11-27 21:29:12 +1100
committerNick Brassel <nick@tzarc.org>2024-11-27 21:29:12 +1100
commit9f76541b29056150cf57d69569a14a59e13995c7 (patch)
tree66c7398d873fcda88aebe3090603aefe045ff52e /platforms/chibios/timer.c
parent57be4871616ee9a8fe042f6186010d436ec7d4b1 (diff)
parenteb04b94eecbb9b3e64ca9c74f937b5f762440b17 (diff)
Merge branch 'develop'
Diffstat (limited to 'platforms/chibios/timer.c')
-rw-r--r--platforms/chibios/timer.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/platforms/chibios/timer.c b/platforms/chibios/timer.c
index 5e01ea6372..4a347b445d 100644
--- a/platforms/chibios/timer.c
+++ b/platforms/chibios/timer.c
@@ -5,6 +5,7 @@
static uint32_t ticks_offset = 0;
static uint32_t last_ticks = 0;
static uint32_t ms_offset = 0;
+static uint32_t saved_ms = 0;
#if CH_CFG_ST_RESOLUTION < 32
static uint32_t last_systime = 0;
static uint32_t overflow = 0;
@@ -73,6 +74,26 @@ void timer_clear(void) {
chSysUnlock();
}
+__attribute__((weak)) void platform_timer_save_value(uint32_t value) {
+ saved_ms = value;
+}
+
+__attribute__((weak)) uint32_t platform_timer_restore_value(void) {
+ return saved_ms;
+}
+
+void timer_restore(void) {
+ chSysLock();
+ ticks_offset = get_system_time_ticks();
+ last_ticks = 0;
+ ms_offset = platform_timer_restore_value();
+ chSysUnlock();
+}
+
+void timer_save(void) {
+ platform_timer_save_value(timer_read32());
+}
+
uint16_t timer_read(void) {
return (uint16_t)timer_read32();
}