diff options
| author | Dasky <32983009+daskygit@users.noreply.github.com> | 2024-10-25 18:10:17 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-10-25 18:10:17 +0100 |
| commit | 5c85271e48b4f2be7da47d1728ad1ddb95364ad7 (patch) | |
| tree | b529dc681017349e509bb454a49fb220176400d4 /platforms/chibios | |
| parent | f486605bab51c858edad09deeedbdcefc398f222 (diff) | |
Add timer_save and _restore functions. (#23887)
Co-authored-by: Sergey Vlasov <sigprof@gmail.com>
Co-authored-by: Nick Brassel <nick@tzarc.org>
Diffstat (limited to 'platforms/chibios')
| -rw-r--r-- | platforms/chibios/timer.c | 21 |
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 @@ | |||
| 5 | static uint32_t ticks_offset = 0; | 5 | static uint32_t ticks_offset = 0; |
| 6 | static uint32_t last_ticks = 0; | 6 | static uint32_t last_ticks = 0; |
| 7 | static uint32_t ms_offset = 0; | 7 | static uint32_t ms_offset = 0; |
| 8 | static uint32_t saved_ms = 0; | ||
| 8 | #if CH_CFG_ST_RESOLUTION < 32 | 9 | #if CH_CFG_ST_RESOLUTION < 32 |
| 9 | static uint32_t last_systime = 0; | 10 | static uint32_t last_systime = 0; |
| 10 | static uint32_t overflow = 0; | 11 | static uint32_t overflow = 0; |
| @@ -73,6 +74,26 @@ void timer_clear(void) { | |||
| 73 | chSysUnlock(); | 74 | chSysUnlock(); |
| 74 | } | 75 | } |
| 75 | 76 | ||
| 77 | __attribute__((weak)) void platform_timer_save_value(uint32_t value) { | ||
| 78 | saved_ms = value; | ||
| 79 | } | ||
| 80 | |||
| 81 | __attribute__((weak)) uint32_t platform_timer_restore_value(void) { | ||
| 82 | return saved_ms; | ||
| 83 | } | ||
| 84 | |||
| 85 | void timer_restore(void) { | ||
| 86 | chSysLock(); | ||
| 87 | ticks_offset = get_system_time_ticks(); | ||
| 88 | last_ticks = 0; | ||
| 89 | ms_offset = platform_timer_restore_value(); | ||
| 90 | chSysUnlock(); | ||
| 91 | } | ||
| 92 | |||
| 93 | void timer_save(void) { | ||
| 94 | platform_timer_save_value(timer_read32()); | ||
| 95 | } | ||
| 96 | |||
| 76 | uint16_t timer_read(void) { | 97 | uint16_t timer_read(void) { |
| 77 | return (uint16_t)timer_read32(); | 98 | return (uint16_t)timer_read32(); |
| 78 | } | 99 | } |
