Supervisor: move most of systick to the supervisor
This code is shared by most parts, except where not all the #ifdefs inside the tick function were present in all ports. This mostly would have broken gamepad tick support on non-samd ports. The "ms32" and "ms64" variants of the tick functions are introduced because there is no 64-bit atomic read. Disabling interrupts avoids a low probability bug where milliseconds could be off by ~49.5 days once every ~49.5 days (2^32 ms). Avoiding disabling interrupts when only the low 32 bits are needed is a minor optimization. Testing performed: on metro m4 express, USB still works and time.monotonic_ns() still counts upcrypto-aes
parent
45d1b290ee
commit
7f744a2369
@ -0,0 +1,76 @@
|
||||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 Jeff Epler for Adafruit Industries
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "supervisor/shared/tick.h"
|
||||
#include "supervisor/filesystem.h"
|
||||
#include "supervisor/shared/autoreload.h"
|
||||
|
||||
static volatile uint64_t ticks_ms;
|
||||
|
||||
#if CIRCUITPY_GAMEPAD
|
||||
#include "shared-module/gamepad/__init__.h"
|
||||
#endif
|
||||
|
||||
#if CIRCUITPY_GAMEPADSHIFT
|
||||
#include "shared-module/gamepadshift/__init__.h"
|
||||
#endif
|
||||
|
||||
#include "shared-bindings/microcontroller/__init__.h"
|
||||
|
||||
void supervisor_tick(void) {
|
||||
|
||||
ticks_ms ++;
|
||||
|
||||
|
||||
#if CIRCUITPY_FILESYSTEM_FLUSH_INTERVAL_MS > 0
|
||||
filesystem_tick();
|
||||
#endif
|
||||
#ifdef CIRCUITPY_AUTORELOAD_DELAY_MS
|
||||
autoreload_tick();
|
||||
#endif
|
||||
#ifdef CIRCUITPY_GAMEPAD_TICKS
|
||||
if (!(ticks_ms & CIRCUITPY_GAMEPAD_TICKS)) {
|
||||
#if CIRCUITPY_GAMEPAD
|
||||
gamepad_tick();
|
||||
#endif
|
||||
#if CIRCUITPY_GAMEPADSHIFT
|
||||
gamepadshift_tick();
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
uint64_t supervisor_ticks_ms64() {
|
||||
uint64_t result;
|
||||
common_hal_mcu_disable_interrupts();
|
||||
result = ticks_ms;
|
||||
common_hal_mcu_enable_interrupts();
|
||||
return result;
|
||||
}
|
||||
|
||||
uint32_t supervisor_ticks_ms32() {
|
||||
return ticks_ms;
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 Jeff Epler for Adafruit Industries
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef __INCLUDED_SUPERVISOR_TICK_H
|
||||
#define __INCLUDED_SUPERVISOR_TICK_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdatomic.h>
|
||||
|
||||
extern void supervisor_tick(void);
|
||||
extern uint32_t supervisor_ticks_ms32(void);
|
||||
extern uint64_t supervisor_ticks_ms64(void);
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue