@@ -43,16 +43,18 @@ void microbit_soft_timer_deinit(void) {
43
43
microbit_soft_timer_paused = false;
44
44
}
45
45
46
- void microbit_soft_timer_handler_run (void ) {
46
+ static void microbit_soft_timer_handler_run (bool run_callbacks ) {
47
47
uint32_t ticks_ms = mp_hal_ticks_ms ();
48
48
microbit_soft_timer_entry_t * heap = MP_STATE_PORT (soft_timer_heap );
49
49
while (heap != NULL && TICKS_DIFF (heap -> expiry_ms , ticks_ms ) <= 0 ) {
50
50
microbit_soft_timer_entry_t * entry = heap ;
51
51
heap = (microbit_soft_timer_entry_t * )mp_pairheap_pop (microbit_soft_timer_lt , & heap -> pairheap );
52
- if (entry -> flags & MICROBIT_SOFT_TIMER_FLAG_PY_CALLBACK ) {
53
- mp_sched_schedule (entry -> py_callback , MP_OBJ_FROM_PTR (entry ));
54
- } else {
55
- entry -> c_callback (entry );
52
+ if (run_callbacks ) {
53
+ if (entry -> flags & MICROBIT_SOFT_TIMER_FLAG_PY_CALLBACK ) {
54
+ mp_sched_schedule (entry -> py_callback , MP_OBJ_FROM_PTR (entry ));
55
+ } else {
56
+ entry -> c_callback (entry );
57
+ }
56
58
}
57
59
if (entry -> mode == MICROBIT_SOFT_TIMER_MODE_PERIODIC ) {
58
60
entry -> expiry_ms += entry -> delta_ms ;
@@ -65,7 +67,7 @@ void microbit_soft_timer_handler_run(void) {
65
67
// This function can be executed at interrupt priority.
66
68
void microbit_soft_timer_handler (void ) {
67
69
if (!microbit_soft_timer_paused ) {
68
- microbit_soft_timer_handler_run ();
70
+ microbit_soft_timer_handler_run (true );
69
71
}
70
72
}
71
73
@@ -77,10 +79,10 @@ void microbit_soft_timer_insert(microbit_soft_timer_entry_t *entry, uint32_t ini
77
79
MICROPY_END_ATOMIC_SECTION (atomic_state );
78
80
}
79
81
80
- void microbit_soft_timer_set_pause (bool paused ) {
82
+ void microbit_soft_timer_set_pause (bool paused , bool run_callbacks ) {
81
83
if (microbit_soft_timer_paused && !paused ) {
82
84
// Explicitly run the soft timer before unpausing, to catch up on any queued events.
83
- microbit_soft_timer_handler_run ();
85
+ microbit_soft_timer_handler_run (run_callbacks );
84
86
}
85
87
microbit_soft_timer_paused = paused ;
86
88
}
0 commit comments