2828
2929#include "peripheral_clk_config.h"
3030
31- #include "supervisor/shared/autoreload.h"
32- #include "supervisor/filesystem.h"
31+ #include "supervisor/shared/tick.h"
3332#include "shared-bindings/microcontroller/__init__.h"
3433#include "shared-bindings/microcontroller/Processor.h"
3534
36- #if CIRCUITPY_GAMEPAD
37- #include "shared-module/gamepad/__init__.h"
38- #endif
39-
40- #if CIRCUITPY_GAMEPADSHIFT
41- #include "shared-module/gamepadshift/__init__.h"
42- #endif
43- // Global millisecond tick count
44- volatile uint64_t ticks_ms = 0 ;
45-
4635void SysTick_Handler (void ) {
4736 // SysTick interrupt handler called when the SysTick timer reaches zero
4837 // (every millisecond).
4938 common_hal_mcu_disable_interrupts ();
50- ticks_ms += 1 ;
5139
5240 // Read the control register to reset the COUNTFLAG.
5341 (void ) SysTick -> CTRL ;
5442 common_hal_mcu_enable_interrupts ();
5543
56- #if CIRCUITPY_FILESYSTEM_FLUSH_INTERVAL_MS > 0
57- filesystem_tick ();
58- #endif
59- #ifdef CIRCUITPY_AUTORELOAD_DELAY_MS
60- autoreload_tick ();
61- #endif
62- #ifdef CIRCUITPY_GAMEPAD_TICKS
63- if (!(ticks_ms & CIRCUITPY_GAMEPAD_TICKS )) {
64- #if CIRCUITPY_GAMEPAD
65- gamepad_tick ();
66- #endif
67- #if CIRCUITPY_GAMEPADSHIFT
68- gamepadshift_tick ();
69- #endif
70- }
71- #endif
44+ // Do things common to all ports when the tick occurs
45+ supervisor_tick ();
7246}
7347
7448void tick_init () {
@@ -115,7 +89,7 @@ void current_tick(uint64_t* ms, uint32_t* us_until_ms) {
11589 uint32_t tick_status = SysTick -> CTRL ;
11690 uint32_t current_us = SysTick -> VAL ;
11791 uint32_t tick_status2 = SysTick -> CTRL ;
118- uint64_t current_ms = ticks_ms ;
92+ uint64_t current_ms = supervisor_ticks_ms64 () ;
11993 // The second clause ensures our value actually rolled over. Its possible it hit zero between
12094 // the VAL read and CTRL read.
12195 if ((tick_status & SysTick_CTRL_COUNTFLAG_Msk ) != 0 ||
@@ -129,5 +103,5 @@ void current_tick(uint64_t* ms, uint32_t* us_until_ms) {
129103
130104void wait_until (uint64_t ms , uint32_t us_until_ms ) {
131105 uint32_t ticks_per_us = common_hal_mcu_processor_get_frequency () / 1000 / 1000 ;
132- while (ticks_ms <= ms && SysTick -> VAL / ticks_per_us >= us_until_ms ) {}
106+ while (supervisor_ticks_ms64 () <= ms && SysTick -> VAL / ticks_per_us >= us_until_ms ) {}
133107}
0 commit comments