First try at lowering the power consumption

This commit is contained in:
Scott Shawcroft 2020-03-05 17:14:54 -08:00
parent 3a5f79acef
commit 6f60afe8c5
No known key found for this signature in database
GPG Key ID: 9349BC7E64B1921E
24 changed files with 143 additions and 265 deletions

View File

@ -148,8 +148,6 @@ endif
SRC_C += \
background.c \
fatfs_port.c \
mphalport.c \
tick.c \
boards/$(BOARD)/board.c \
boards/$(BOARD)/pins.c \
device/$(MCU_VARIANT)/startup_$(MCU_SUB_VARIANT).c \

View File

@ -36,7 +36,6 @@
#include "nrfx_power.h"
#include "nrf_nvic.h"
#include "nrf_sdm.h"
#include "tick.h"
#include "py/gc.h"
#include "py/objstr.h"
#include "py/runtime.h"

View File

@ -35,8 +35,6 @@
#include "py/runtime.h"
#include "py/stream.h"
#include "tick.h"
#include "shared-bindings/_bleio/__init__.h"
#include "shared-bindings/_bleio/Connection.h"
#include "supervisor/shared/tick.h"

View File

@ -35,8 +35,6 @@
#include "py/runtime.h"
#include "py/stream.h"
#include "tick.h"
#include "shared-bindings/_bleio/__init__.h"
#include "shared-bindings/_bleio/Connection.h"
#include "shared-bindings/_bleio/PacketBuffer.h"

View File

@ -35,7 +35,6 @@
#include "py/stream.h"
#include "supervisor/shared/translate.h"
#include "tick.h"
#include "nrfx_uarte.h"
#include <string.h>

View File

@ -33,8 +33,6 @@
#include "shared-bindings/digitalio/DigitalInOut.h"
#include "shared-bindings/microcontroller/__init__.h"
#include "tick.h"
void common_hal_displayio_parallelbus_construct(displayio_parallelbus_obj_t* self,
const mcu_pin_obj_t* data0, const mcu_pin_obj_t* command, const mcu_pin_obj_t* chip_select,
const mcu_pin_obj_t* write, const mcu_pin_obj_t* read, const mcu_pin_obj_t* reset) {

View File

@ -29,8 +29,6 @@
#include "shared-bindings/neopixel_write/__init__.h"
#include "nrf_pwm.h"
#include "tick.h"
// https://github.com/adafruit/Adafruit_NeoPixel/blob/master/Adafruit_NeoPixel.cpp
// [[[Begin of the Neopixel NRF52 EasyDMA implementation
// by the Hackerspace San Salvador]]]
@ -176,7 +174,7 @@ void common_hal_neopixel_write (const digitalio_digitalinout_obj_t* digitalinout
}
// Wait to make sure we don't append onto the last transmission.
wait_until(next_start_tick_ms, next_start_tick_us);
// wait_until(next_start_tick_ms, next_start_tick_us);
// Use the identified device to choose the implementation
// If a PWM device is available and we have a buffer, use DMA.
@ -323,11 +321,11 @@ void common_hal_neopixel_write (const digitalio_digitalinout_obj_t* digitalinout
}
// Update the next start.
current_tick(&next_start_tick_ms, &next_start_tick_us);
if (next_start_tick_us < 100) {
next_start_tick_ms += 1;
next_start_tick_us = 100 - next_start_tick_us;
} else {
next_start_tick_us -= 100;
}
// current_tick(&next_start_tick_ms, &next_start_tick_us);
// if (next_start_tick_us < 100) {
// next_start_tick_ms += 1;
// next_start_tick_us = 100 - next_start_tick_us;
// } else {
// next_start_tick_us -= 100;
// }
}

View File

@ -36,7 +36,6 @@
#include "shared-bindings/microcontroller/__init__.h"
#include "shared-bindings/pulseio/PulseIn.h"
#include "tick.h"
#include "nrfx_gpiote.h"
// obj array to map pin -> self since nrfx hide the mapping
@ -55,9 +54,10 @@ static int _find_pulsein_obj(pulseio_pulsein_obj_t* obj) {
static void _pulsein_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) {
// Grab the current time first.
uint32_t current_us;
uint64_t current_ms;
current_tick(&current_ms, &current_us);
uint32_t current_us = 0;
uint64_t current_ms = 0;
// FIXME! We need a higher resolution clock to measure against.
//current_tick(&current_ms, &current_us);
// current_tick gives us the remaining us until the next tick but we want the number since the last ms.
current_us = 1000 - current_us;

View File

@ -30,54 +30,26 @@
#include "py/runtime.h"
#include "lib/timeutils/timeutils.h"
#include "shared-bindings/rtc/__init__.h"
#include "supervisor/port.h"
#include "supervisor/shared/translate.h"
#include "nrfx_rtc.h"
#include "nrf_clock.h"
// We clock the RTC very slowly (8Hz) so that it won't overflow often.
// But the counter is only 24 bits, so overflow is about every 24 days ...
// For testing, set this to 32768 and it'll overflow every few minutes
#define RTC_CLOCK_HZ (8)
volatile static uint32_t rtc_offset = 0;
const nrfx_rtc_t rtc_instance = NRFX_RTC_INSTANCE(2);
const nrfx_rtc_config_t rtc_config = {
.prescaler = RTC_FREQ_TO_PRESCALER(RTC_CLOCK_HZ),
.reliable = 0,
.tick_latency = 0,
.interrupt_priority = 6
};
void rtc_handler(nrfx_rtc_int_type_t int_type) {
if (int_type == NRFX_RTC_INT_OVERFLOW) {
rtc_offset += (1L<<24) / RTC_CLOCK_HZ;
}
}
void rtc_init(void) {
if (!nrf_clock_lf_is_running(NRF_CLOCK)) {
nrf_clock_task_trigger(NRF_CLOCK, NRF_CLOCK_TASK_LFCLKSTART);
}
nrfx_rtc_counter_clear(&rtc_instance);
nrfx_rtc_init(&rtc_instance, &rtc_config, rtc_handler);
nrfx_rtc_enable(&rtc_instance);
nrfx_rtc_overflow_enable(&rtc_instance, 1);
}
// This is the time in seconds since 2000 that the RTC was started.
static uint32_t rtc_offset = 0;
void common_hal_rtc_get_time(timeutils_struct_time_t *tm) {
uint32_t t = rtc_offset + (nrfx_rtc_counter_get(&rtc_instance) / RTC_CLOCK_HZ );
timeutils_seconds_since_2000_to_struct_time(t, tm);
uint64_t ticks_s = port_get_raw_ticks() / 1024;
timeutils_seconds_since_2000_to_struct_time(rtc_offset + ticks_s, tm);
}
void common_hal_rtc_set_time(timeutils_struct_time_t *tm) {
rtc_offset = timeutils_seconds_since_2000(
uint64_t ticks_s = port_get_raw_ticks() / 1024;
uint32_t epoch_s = timeutils_seconds_since_2000(
tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec
);
nrfx_rtc_counter_clear(&rtc_instance);
rtc_offset = epoch_s - ticks_s;
}
int common_hal_rtc_get_calibration(void) {

View File

@ -26,16 +26,15 @@
#include "py/mphal.h"
#include "tick.h"
uint64_t common_hal_time_monotonic(void) {
return supervisor_ticks_ms64();
}
uint64_t common_hal_time_monotonic_ns(void) {
uint64_t ms;
uint32_t us_until_ms;
current_tick(&ms, &us_until_ms);
uint64_t ms = 0;
uint32_t us_until_ms = 0;
// FIXME! Re-implement this.
// current_tick(&ms, &us_until_ms);
// us counts down.
return 1000 * (ms * 1000 + (1000 - us_until_ms));
}

View File

@ -1,52 +0,0 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2019 Dan Halbert for Adafruit Industries
* Copyright (c) 2018 Artur Pacholec
* Copyright (c) 2015 Glenn Ruben Bakke
*
* 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 <string.h>
#include "py/mphal.h"
#include "py/mpstate.h"
#include "py/gc.h"
#include "supervisor/shared/tick.h"
/*------------------------------------------------------------------*/
/* delay
*------------------------------------------------------------------*/
void mp_hal_delay_ms(mp_uint_t delay) {
uint64_t start_tick = supervisor_ticks_ms64();
uint64_t duration = 0;
while (duration < delay) {
RUN_BACKGROUND_TASKS;
// Check to see if we've been CTRL-Ced by autoreload or the user.
if(MP_STATE_VM(mp_pending_exception) == MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception)) ||
MP_STATE_VM(mp_pending_exception) == MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_reload_exception))) {
break;
}
duration = (supervisor_ticks_ms64() - start_tick);
// TODO(tannewt): Go to sleep for a little while while we wait.
}
}

View File

@ -28,8 +28,10 @@
#include "supervisor/port.h"
#include "boards/board.h"
#include "nrfx/hal/nrf_clock.h"
#include "nrfx/hal/nrf_power.h"
#include "nrfx/drivers/include/nrfx_power.h"
#include "nrfx/drivers/include/nrfx_rtc.h"
#include "nrf/cache.h"
#include "nrf/clocks.h"
@ -48,7 +50,6 @@
#include "common-hal/pulseio/PulseIn.h"
#include "common-hal/rtc/RTC.h"
#include "common-hal/neopixel_write/__init__.h"
#include "tick.h"
#include "shared-bindings/rtc/__init__.h"
@ -64,6 +65,37 @@ static void power_warning_handler(void) {
reset_into_safe_mode(BROWNOUT);
}
const nrfx_rtc_t rtc_instance = NRFX_RTC_INSTANCE(2);
const nrfx_rtc_config_t rtc_config = {
.prescaler = RTC_FREQ_TO_PRESCALER(1024),
.reliable = 0,
.tick_latency = 0,
.interrupt_priority = 6
};
static volatile uint64_t overflowed_ticks = 0;
void rtc_handler(nrfx_rtc_int_type_t int_type) {
if (int_type == NRFX_RTC_INT_OVERFLOW) {
overflowed_ticks += (1L<<24);
}
// Do things common to all ports when the tick occurs
if (int_type == NRFX_RTC_INT_TICK) {
supervisor_tick();
}
}
void tick_init(void) {
if (!nrf_clock_lf_is_running(NRF_CLOCK)) {
nrf_clock_task_trigger(NRF_CLOCK, NRF_CLOCK_TASK_LFCLKSTART);
}
nrfx_rtc_counter_clear(&rtc_instance);
nrfx_rtc_init(&rtc_instance, &rtc_config, rtc_handler);
nrfx_rtc_enable(&rtc_instance);
nrfx_rtc_overflow_enable(&rtc_instance, true);
}
safe_mode_t port_init(void) {
nrf_peripherals_clocks_init();
@ -89,10 +121,6 @@ safe_mode_t port_init(void) {
analogin_init();
#endif
#if CIRCUITPY_RTC
rtc_init();
#endif
return NO_SAFE_MODE;
}
@ -123,10 +151,6 @@ void reset_port(void) {
timers_reset();
#if CIRCUITPY_RTC
rtc_reset();
#endif
#if CIRCUITPY_BLEIO
bleio_reset();
#endif
@ -171,6 +195,40 @@ uint32_t port_get_saved_word(void) {
return _ebss;
}
uint64_t port_get_raw_ticks(void) {
return overflowed_ticks + nrfx_rtc_counter_get(&rtc_instance);
}
// Enable 1/1024 second tick.
void port_enable_tick(void) {
nrfx_rtc_tick_enable(&rtc_instance, true);
}
// Disable 1/1024 second tick.
void port_disable_tick(void) {
nrfx_rtc_tick_disable(&rtc_instance);
}
void port_interrupt_after_ticks(uint32_t ticks) {
uint32_t current_ticks = nrfx_rtc_counter_get(&rtc_instance);
uint32_t diff = 3;
if (ticks > diff) {
diff = ticks;
}
nrfx_rtc_cc_set(&rtc_instance, 0, current_ticks + diff, true);
}
void port_sleep_until_interrupt(void) {
// Clear the FPU interrupt because it can prevent us from sleeping.
if (NVIC_GetPendingIRQ(FPU_IRQn)) {
__set_FPSCR(__get_FPSCR() & ~(0x9f));
(void) __get_FPSCR();
NVIC_ClearPendingIRQ(FPU_IRQn);
}
sd_app_evt_wait();
}
void HardFault_Handler(void) {
reset_into_safe_mode(HARD_CRASH);
while (true) {

View File

@ -26,7 +26,6 @@
#include "nrfx.h"
#include "nrfx_power.h"
#include "tick.h"
#include "supervisor/usb.h"
#include "lib/utils/interrupt_char.h"
#include "lib/mp-readline/readline.h"

View File

@ -1,67 +0,0 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2017 Scott Shawcroft 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 "tick.h"
#include "supervisor/shared/tick.h"
#include "shared-module/gamepad/__init__.h"
#include "shared-bindings/microcontroller/Processor.h"
#include "nrf.h"
void SysTick_Handler(void) {
// Do things common to all ports when the tick occurs
supervisor_tick();
}
void tick_init() {
uint32_t ticks_per_ms = common_hal_mcu_processor_get_frequency() / 1000;
SysTick_Config(ticks_per_ms); // interrupt is enabled
}
void tick_delay(uint32_t us) {
uint32_t ticks_per_us = common_hal_mcu_processor_get_frequency() / 1000 / 1000;
uint32_t us_between_ticks = SysTick->VAL / ticks_per_us;
uint64_t start_ms = supervisor_ticks_ms64();
while (us > 1000) {
while (supervisor_ticks_ms64() == start_ms) {}
us -= us_between_ticks;
start_ms = supervisor_ticks_ms64();
us_between_ticks = 1000;
}
while (SysTick->VAL > ((us_between_ticks - us) * ticks_per_us)) {}
}
// us counts down!
void current_tick(uint64_t* ms, uint32_t* us_until_ms) {
uint32_t ticks_per_us = common_hal_mcu_processor_get_frequency() / 1000 / 1000;
*ms = supervisor_ticks_ms64();
*us_until_ms = SysTick->VAL / ticks_per_us;
}
void wait_until(uint64_t ms, uint32_t us_until_ms) {
uint32_t ticks_per_us = common_hal_mcu_processor_get_frequency() / 1000 / 1000;
while(supervisor_ticks_ms64() <= ms && SysTick->VAL / ticks_per_us >= us_until_ms) {}
}

View File

@ -1,44 +0,0 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2017 Scott Shawcroft 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 MICROPY_INCLUDED_NRF_TICK_H
#define MICROPY_INCLUDED_NRF_TICK_H
#include "py/mpconfig.h"
#include <stdint.h>
extern struct timer_descriptor ms_timer;
void tick_init(void);
void tick_delay(uint32_t us);
void current_tick(uint64_t* ms, uint32_t* us_until_ms);
// Do not call this with interrupts disabled because it may be waiting for
// ticks_ms to increment.
void wait_until(uint64_t ms, uint32_t us_until_ms);
#endif // MICROPY_INCLUDED_NRF_TICK_H

View File

@ -41,8 +41,6 @@
#include <stdint.h>
#include <string.h>
#include "tick.h"
void common_hal_displayio_display_construct(displayio_display_obj_t* self,
mp_obj_t bus, uint16_t width, uint16_t height, int16_t colstart, int16_t rowstart,
uint16_t rotation, uint16_t color_depth, bool grayscale, bool pixels_in_byte_share_row,

View File

@ -42,8 +42,6 @@
#include <stdint.h>
#include <string.h>
#include "tick.h"
void common_hal_displayio_epaperdisplay_construct(displayio_epaperdisplay_obj_t* self,
mp_obj_t bus, uint8_t* start_sequence, uint16_t start_sequence_len, uint8_t* stop_sequence, uint16_t stop_sequence_len,
uint16_t width, uint16_t height, uint16_t ram_width, uint16_t ram_height,

View File

@ -36,8 +36,6 @@
#include "shared-bindings/time/__init__.h"
#include "shared-module/displayio/display_core.h"
#include "tick.h"
void common_hal_displayio_fourwire_construct(displayio_fourwire_obj_t* self,
busio_spi_obj_t* spi, const mcu_pin_obj_t* command,
const mcu_pin_obj_t* chip_select, const mcu_pin_obj_t* reset, uint32_t baudrate) {

View File

@ -38,8 +38,6 @@
#include "shared-bindings/time/__init__.h"
#include "shared-module/displayio/display_core.h"
#include "tick.h"
void common_hal_displayio_i2cdisplay_construct(displayio_i2cdisplay_obj_t* self,
busio_i2c_obj_t* i2c, uint16_t device_address, const mcu_pin_obj_t* reset) {

View File

@ -40,8 +40,6 @@
#include <stdint.h>
#include <string.h>
#include "tick.h"
void displayio_display_core_construct(displayio_display_core_t* self,
mp_obj_t bus, uint16_t width, uint16_t height, uint16_t ram_width, uint16_t ram_height, int16_t colstart, int16_t rowstart, uint16_t rotation,
uint16_t color_depth, bool grayscale, bool pixels_in_byte_share_row, uint8_t bytes_per_cell, bool reverse_pixels_in_byte) {

View File

@ -25,7 +25,7 @@
*/
#include <string.h>
#include "tick.h"
#include "py/runtime.h"
#include "shared-bindings/usb_hid/Device.h"
#include "shared-module/usb_hid/Device.h"

View File

@ -70,4 +70,20 @@ uint32_t *port_heap_get_top(void);
void port_set_saved_word(uint32_t);
uint32_t port_get_saved_word(void);
// Get the raw tick count since start up. A tick is 1/32768 of a second, a common low frequency
// clock rate.
uint64_t port_get_raw_ticks(void);
// Enable 1/1024 second tick.
void port_enable_tick(void);
// Disable 1/1024 second tick.
void port_disable_tick(void);
// Wake the CPU after the given number of ticks or sooner.
void port_interrupt_after_ticks(uint32_t ticks);
// Sleep the CPU until an interrupt is received.
void port_sleep_until_interrupt(void);
#endif // MICROPY_INCLUDED_SUPERVISOR_PORT_H

View File

@ -26,12 +26,13 @@
#include "supervisor/shared/tick.h"
#include "py/mpstate.h"
#include "supervisor/linker.h"
#include "supervisor/filesystem.h"
#include "supervisor/port.h"
#include "supervisor/shared/autoreload.h"
static volatile uint64_t PLACE_IN_DTCM_BSS(ticks_ms);
static volatile uint32_t PLACE_IN_DTCM_BSS(background_ticks_ms32);
static volatile uint64_t PLACE_IN_DTCM_BSS(background_ticks);
#if CIRCUITPY_GAMEPAD
#include "shared-module/gamepad/__init__.h"
@ -44,9 +45,6 @@ static volatile uint32_t PLACE_IN_DTCM_BSS(background_ticks_ms32);
#include "shared-bindings/microcontroller/__init__.h"
void supervisor_tick(void) {
ticks_ms ++;
#if CIRCUITPY_FILESYSTEM_FLUSH_INTERVAL_MS > 0
filesystem_tick();
#endif
@ -54,7 +52,7 @@ void supervisor_tick(void) {
autoreload_tick();
#endif
#ifdef CIRCUITPY_GAMEPAD_TICKS
if (!(ticks_ms & CIRCUITPY_GAMEPAD_TICKS)) {
if (!(port_get_raw_ticks() & CIRCUITPY_GAMEPAD_TICKS)) {
#if CIRCUITPY_GAMEPAD
gamepad_tick();
#endif
@ -68,29 +66,51 @@ void supervisor_tick(void) {
uint64_t supervisor_ticks_ms64() {
uint64_t result;
common_hal_mcu_disable_interrupts();
result = ticks_ms;
result = port_get_raw_ticks();
common_hal_mcu_enable_interrupts();
result = result * 1000 / 1024;
return result;
}
uint32_t supervisor_ticks_ms32() {
return ticks_ms;
return supervisor_ticks_ms64();
}
extern void run_background_tasks(void);
void PLACE_IN_ITCM(supervisor_run_background_tasks_if_tick)() {
uint32_t now32 = ticks_ms;
// uint64_t now = port_get_raw_ticks();
if (now32 == background_ticks_ms32) {
return;
}
background_ticks_ms32 = now32;
// if (now == background_ticks) {
// return;
// }
// background_ticks = now;
run_background_tasks();
}
void supervisor_fake_tick() {
uint32_t now32 = ticks_ms;
background_ticks_ms32 = (now32 - 1);
uint32_t now = port_get_raw_ticks();
background_ticks = (now - 1);
}
void mp_hal_delay_ms(mp_uint_t delay) {
uint64_t start_tick = port_get_raw_ticks();
// Adjust the delay to ticks vs ms.
delay = delay * 1024 / 1000;
uint64_t duration = 0;
port_interrupt_after_ticks(delay);
while (duration < delay) {
RUN_BACKGROUND_TASKS;
// Check to see if we've been CTRL-Ced by autoreload or the user.
if(MP_STATE_VM(mp_pending_exception) == MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception)) ||
MP_STATE_VM(mp_pending_exception) == MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_reload_exception))) {
break;
}
// Sleep until an interrupt happens.
port_sleep_until_interrupt();
// asm("bkpt");
duration = (port_get_raw_ticks() - start_tick);
}
}

View File

@ -24,7 +24,6 @@
* THE SOFTWARE.
*/
#include "tick.h"
#include "py/objstr.h"
#include "shared-bindings/microcontroller/Processor.h"
#include "shared-module/usb_midi/__init__.h"