summaryrefslogtreecommitdiff
path: root/shared/runtime/softtimer.h
diff options
context:
space:
mode:
Diffstat (limited to 'shared/runtime/softtimer.h')
-rw-r--r--shared/runtime/softtimer.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/shared/runtime/softtimer.h b/shared/runtime/softtimer.h
index 8603ea13f..fe5d02b90 100644
--- a/shared/runtime/softtimer.h
+++ b/shared/runtime/softtimer.h
@@ -48,6 +48,13 @@ typedef struct _soft_timer_entry_t {
extern volatile uint32_t soft_timer_next;
+static inline int32_t soft_timer_ticks_diff(uint32_t t1, uint32_t t0) {
+ // t1 is after t0 (i.e. positive result) if there exists a uint32_t X <= INT_MAX
+ // such that t0 + X = t1. Otherwise t1 is interpreted to be earlier than
+ // t0 (negative result).
+ return t1 - t0;
+}
+
void soft_timer_deinit(void);
void soft_timer_handler(void);
void soft_timer_gc_mark_all(void);
@@ -63,4 +70,17 @@ static inline void soft_timer_reinsert(soft_timer_entry_t *entry, uint32_t initi
soft_timer_insert(entry, initial_delta_ms);
}
+#if !defined(MICROPY_SOFT_TIMER_TICKS_MS)
+// IF MICROPY_SOFT_TIMER_TICKS_MS is not defined then the port must provide the
+// following timer functions:
+// - soft_timer_get_ms() must return a 32-bit millisecond counter that wraps around.
+// - soft_timer_schedule_at_ms(ticks_ms) must schedule a callback of soft_timer_handler()
+// when the above millisecond counter reaches the given ticks_ms value. If ticks_ms
+// is behind the current counter (using int32_t arithmetic) then the callback should
+// be scheduled immediately. The callback of soft_timer_handler() should be made at
+// pend-SV IRQ level, or equivalent.
+uint32_t soft_timer_get_ms(void);
+void soft_timer_schedule_at_ms(uint32_t ticks_ms);
+#endif
+
#endif // MICROPY_INCLUDED_SHARED_RUNTIME_SOFTTIMER_H