@@ -43,11 +43,7 @@ void microbit_soft_timer_deinit(void) {
4343 microbit_soft_timer_paused = false;
4444}
4545
46- // This function can be executed at interrupt priority.
47- void microbit_soft_timer_handler (void ) {
48- if (microbit_soft_timer_paused ) {
49- return ;
50- }
46+ void microbit_soft_timer_handler_run (void ) {
5147 uint32_t ticks_ms = mp_hal_ticks_ms ();
5248 microbit_soft_timer_entry_t * heap = MP_STATE_PORT (soft_timer_heap );
5349 while (heap != NULL && TICKS_DIFF (heap -> expiry_ms , ticks_ms ) <= 0 ) {
@@ -66,6 +62,13 @@ void microbit_soft_timer_handler(void) {
6662 MP_STATE_PORT (soft_timer_heap ) = heap ;
6763}
6864
65+ // This function can be executed at interrupt priority.
66+ void microbit_soft_timer_handler (void ) {
67+ if (!microbit_soft_timer_paused ) {
68+ microbit_soft_timer_handler_run ();
69+ }
70+ }
71+
6972void microbit_soft_timer_insert (microbit_soft_timer_entry_t * entry , uint32_t initial_delta_ms ) {
7073 mp_pairheap_init_node (microbit_soft_timer_lt , & entry -> pairheap );
7174 entry -> expiry_ms = mp_hal_ticks_ms () + initial_delta_ms ;
@@ -75,6 +78,10 @@ void microbit_soft_timer_insert(microbit_soft_timer_entry_t *entry, uint32_t ini
7578}
7679
7780void microbit_soft_timer_set_pause (bool paused ) {
81+ if (microbit_soft_timer_paused && !paused ) {
82+ // Explicitly run the soft timer before unpausing, to catch up on any queued events.
83+ microbit_soft_timer_handler_run ();
84+ }
7885 microbit_soft_timer_paused = paused ;
7986}
8087
0 commit comments