aboutsummaryrefslogtreecommitdiff
path: root/platforms/avr/timer.c
diff options
context:
space:
mode:
authorDasky <[email protected]>2024-10-25 18:10:17 +0100
committerGitHub <[email protected]>2024-10-25 18:10:17 +0100
commit5c85271e48b4f2be7da47d1728ad1ddb95364ad7 (patch)
treeb529dc681017349e509bb454a49fb220176400d4 /platforms/avr/timer.c
parentf486605bab51c858edad09deeedbdcefc398f222 (diff)
downloadqmk_firmware-5c85271e48b4f2be7da47d1728ad1ddb95364ad7.tar.gz
qmk_firmware-5c85271e48b4f2be7da47d1728ad1ddb95364ad7.zip
Add timer_save and _restore functions. (#23887)
Co-authored-by: Sergey Vlasov <[email protected]> Co-authored-by: Nick Brassel <[email protected]>
Diffstat (limited to 'platforms/avr/timer.c')
-rw-r--r--platforms/avr/timer.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/platforms/avr/timer.c b/platforms/avr/timer.c
index 9fb671ae8d..26ba0e29fa 100644
--- a/platforms/avr/timer.c
+++ b/platforms/avr/timer.c
@@ -25,6 +25,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// counter resolution 1ms
// NOTE: union { uint32_t timer32; struct { uint16_t dummy; uint16_t timer16; }}
volatile uint32_t timer_count;
+static uint32_t saved_ms;
/** \brief timer initialization
*
@@ -78,6 +79,24 @@ inline void timer_clear(void) {
}
}
+/** \brief timer save
+ *
+ * Set saved_ms to current time.
+ */
+void timer_save(void) {
+ saved_ms = timer_read32();
+}
+
+/** \brief timer restore
+ *
+ * Set timer_count to saved_ms
+ */
+void timer_restore(void) {
+ ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
+ timer_count = saved_ms;
+ }
+}
+
/** \brief timer read
*
* FIXME: needs doc