@@ -52,7 +52,7 @@ void supervisor_tick(void) {
5252 autoreload_tick ();
5353#endif
5454#ifdef CIRCUITPY_GAMEPAD_TICKS
55- if (!(port_get_raw_ticks () & CIRCUITPY_GAMEPAD_TICKS )) {
55+ if (!(port_get_raw_ticks (NULL ) & CIRCUITPY_GAMEPAD_TICKS )) {
5656 #if CIRCUITPY_GAMEPAD
5757 gamepad_tick ();
5858 #endif
@@ -66,7 +66,7 @@ void supervisor_tick(void) {
6666uint64_t supervisor_ticks_ms64 () {
6767 uint64_t result ;
6868 common_hal_mcu_disable_interrupts ();
69- result = port_get_raw_ticks ();
69+ result = port_get_raw_ticks (NULL );
7070 common_hal_mcu_enable_interrupts ();
7171 result = result * 1000 / 1024 ;
7272 return result ;
@@ -79,23 +79,24 @@ uint32_t supervisor_ticks_ms32() {
7979extern void run_background_tasks (void );
8080
8181void PLACE_IN_ITCM (supervisor_run_background_tasks_if_tick )() {
82- // uint64_t now = port_get_raw_ticks();
82+ uint8_t subticks ;
83+ uint64_t now = port_get_raw_ticks (& subticks );
8384
84- // if (now == background_ticks) {
85- // return;
86- // }
87- // background_ticks = now;
85+ if (now == background_ticks && ( subticks & 0x3 ) != 0 ) {
86+ return ;
87+ }
88+ background_ticks = now ;
8889
8990 run_background_tasks ();
9091}
9192
9293void supervisor_fake_tick () {
93- uint32_t now = port_get_raw_ticks ();
94+ uint32_t now = port_get_raw_ticks (NULL );
9495 background_ticks = (now - 1 );
9596}
9697
9798void mp_hal_delay_ms (mp_uint_t delay ) {
98- uint64_t start_tick = port_get_raw_ticks ();
99+ uint64_t start_tick = port_get_raw_ticks (NULL );
99100 // Adjust the delay to ticks vs ms.
100101 delay = delay * 1024 / 1000 ;
101102 uint64_t duration = 0 ;
@@ -110,7 +111,23 @@ void mp_hal_delay_ms(mp_uint_t delay) {
110111 // Sleep until an interrupt happens.
111112 port_sleep_until_interrupt ();
112113 // asm("bkpt");
113- duration = (port_get_raw_ticks () - start_tick );
114+ duration = (port_get_raw_ticks (NULL ) - start_tick );
115+ port_interrupt_after_ticks (duration );
116+ }
117+ }
118+
119+ volatile size_t tick_enable_count = 0 ;
120+ extern void supervisor_enable_tick (void ) {
121+ if (tick_enable_count == 0 ) {
122+ port_enable_tick ();
123+ }
124+ tick_enable_count ++ ;
125+ }
126+
127+ extern void supervisor_disable_tick (void ) {
128+ tick_enable_count -- ;
129+ if (tick_enable_count == 0 ) {
130+ port_disable_tick ();
114131 }
115132}
116133
0 commit comments