Changes for getting supervisor ticks

This commit is contained in:
root 2020-08-01 13:27:02 -05:00
parent a44c09e286
commit 12b81618a3
7 changed files with 19 additions and 14 deletions

@ -1 +1 @@
Subproject commit 761d6437e8cd6a131d51de96974337121a9c7164
Subproject commit 00e00ee8acb043b976302051291bc236ae2676cb

View File

@ -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 <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"

View File

@ -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);

View File

@ -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

View File

@ -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.)

View File

@ -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;
}

View File

@ -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) {