From 12b81618a3a4d914114aae4ebc647a4f8bd9dc3f Mon Sep 17 00:00:00 2001 From: root Date: Sat, 1 Aug 2020 13:27:02 -0500 Subject: [PATCH] Changes for getting supervisor ticks --- lib/protomatter | 2 +- locale/circuitpython.pot | 2 +- ports/atmel-samd/common-hal/pulseio/PulseIn.c | 9 ++------- supervisor/background_callback.h | 4 ++++ supervisor/port.h | 3 +++ supervisor/shared/background_callback.c | 7 +++++++ supervisor/shared/tick.c | 6 +----- 7 files changed, 19 insertions(+), 14 deletions(-) diff --git a/lib/protomatter b/lib/protomatter index 761d6437e8..00e00ee8ac 160000 --- a/lib/protomatter +++ b/lib/protomatter @@ -1 +1 @@ -Subproject commit 761d6437e8cd6a131d51de96974337121a9c7164 +Subproject commit 00e00ee8acb043b976302051291bc236ae2676cb diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index 5ed32d6382..6176a18dac 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-07-30 07:23-0500\n" +"POT-Creation-Date: 2020-08-01 12:58-0500\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" diff --git a/ports/atmel-samd/common-hal/pulseio/PulseIn.c b/ports/atmel-samd/common-hal/pulseio/PulseIn.c index ae58b089de..5bd3cc7de1 100644 --- a/ports/atmel-samd/common-hal/pulseio/PulseIn.c +++ b/ports/atmel-samd/common-hal/pulseio/PulseIn.c @@ -88,9 +88,8 @@ void pulsein_interrupt_handler(uint8_t channel) { uint32_t current_count = tc->COUNT16.COUNT.reg; pulseio_pulsein_obj_t* self = get_eic_channel_data(channel); - if (!supervisor_background_tasks_ok() || self->errored_too_fast) { - self->errored_too_fast = true; - common_hal_pulseio_pulsein_pause(self); + if (!supervisor_background_tasks_ok() ) { + mp_raise_RuntimeError(translate("Input taking too long")); return; } if (self->first_edge) { @@ -154,7 +153,6 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t* self, self->start = 0; self->len = 0; self->first_edge = true; - self->errored_too_fast = false; if (refcount == 0) { // Find a spare timer. @@ -264,9 +262,6 @@ void common_hal_pulseio_pulsein_resume(pulseio_pulsein_obj_t* self, // Make sure we're paused. common_hal_pulseio_pulsein_pause(self); - // Reset erroring - self->errored_too_fast = false; - // Send the trigger pulse. if (trigger_duration > 0) { gpio_set_pin_pull_mode(self->pin, GPIO_PULL_OFF); diff --git a/supervisor/background_callback.h b/supervisor/background_callback.h index 535dd656be..e943830fd0 100644 --- a/supervisor/background_callback.h +++ b/supervisor/background_callback.h @@ -27,6 +27,8 @@ #ifndef CIRCUITPY_INCLUDED_SUPERVISOR_BACKGROUND_CALLBACK_H #define CIRCUITPY_INCLUDED_SUPERVISOR_BACKGROUND_CALLBACK_H +#include "supervisor/port.h" + /** Background callbacks are a linked list of tasks to call in the background. * * Include a member of type `background_callback_t` inside an object @@ -84,4 +86,6 @@ void background_callback_end_critical_section(void); */ void background_callback_gc_collect(void); +uint64_t background_get_ticks(void); + #endif diff --git a/supervisor/port.h b/supervisor/port.h index ad5b3cf32a..c95e43fd2e 100644 --- a/supervisor/port.h +++ b/supervisor/port.h @@ -73,6 +73,9 @@ uint32_t *port_heap_get_top(void); void port_set_saved_word(uint32_t); uint32_t port_get_saved_word(void); +// Used to keep track of last time background was run +uint64_t get_background_ticks(void); + // Get the raw tick count since start up. A tick is 1/1024 of a second, a common low frequency // clock rate. If subticks is not NULL then the port will fill in the number of subticks where each // tick is 32 subticks (for a resolution of 1/32768 or 30.5ish microseconds.) diff --git a/supervisor/shared/background_callback.c b/supervisor/shared/background_callback.c index 8e12dd3625..4502424acc 100644 --- a/supervisor/shared/background_callback.c +++ b/supervisor/shared/background_callback.c @@ -37,6 +37,12 @@ STATIC volatile background_callback_t *callback_head, *callback_tail; #define CALLBACK_CRITICAL_BEGIN (common_hal_mcu_disable_interrupts()) #define CALLBACK_CRITICAL_END (common_hal_mcu_enable_interrupts()) +volatile uint64_t last_background_tick = 0; + +uint64_t get_background_ticks(void) { + return last_background_tick; +} + void background_callback_add_core(background_callback_t *cb) { CALLBACK_CRITICAL_BEGIN; if (cb->prev || callback_head == cb) { @@ -64,6 +70,7 @@ void background_callback_add(background_callback_t *cb, background_callback_fun static bool in_background_callback; void background_callback_run_all() { + last_background_tick = port_get_raw_ticks(NULL); if (!callback_head) { return; } diff --git a/supervisor/shared/tick.c b/supervisor/shared/tick.c index 4af59f78e3..eac5104a5c 100644 --- a/supervisor/shared/tick.c +++ b/supervisor/shared/tick.c @@ -68,8 +68,6 @@ static volatile uint64_t PLACE_IN_DTCM_BSS(background_ticks); static background_callback_t tick_callback; -volatile uint64_t last_finished_tick = 0; - void supervisor_background_tasks(void *unused) { port_start_background_task(); @@ -93,13 +91,11 @@ void supervisor_background_tasks(void *unused) { assert_heap_ok(); - last_finished_tick = port_get_raw_ticks(NULL); - port_finish_background_task(); } bool supervisor_background_tasks_ok(void) { - return port_get_raw_ticks(NULL) - last_finished_tick < 1024; + return port_get_raw_ticks(NULL) - get_background_ticks() < 1024; } void supervisor_tick(void) {