Skip to content

Commit 12b8161

Browse files
committed
Changes for getting supervisor ticks
1 parent a44c09e commit 12b8161

File tree

7 files changed

+19
-14
lines changed

7 files changed

+19
-14
lines changed

lib/protomatter

locale/circuitpython.pot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgid ""
88
msgstr ""
99
"Project-Id-Version: PACKAGE VERSION\n"
1010
"Report-Msgid-Bugs-To: \n"
11-
"POT-Creation-Date: 2020-07-30 07:23-0500\n"
11+
"POT-Creation-Date: 2020-08-01 12:58-0500\n"
1212
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1313
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414
"Language-Team: LANGUAGE <[email protected]>\n"

ports/atmel-samd/common-hal/pulseio/PulseIn.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,8 @@ void pulsein_interrupt_handler(uint8_t channel) {
8888
uint32_t current_count = tc->COUNT16.COUNT.reg;
8989

9090
pulseio_pulsein_obj_t* self = get_eic_channel_data(channel);
91-
if (!supervisor_background_tasks_ok() || self->errored_too_fast) {
92-
self->errored_too_fast = true;
93-
common_hal_pulseio_pulsein_pause(self);
91+
if (!supervisor_background_tasks_ok() ) {
92+
mp_raise_RuntimeError(translate("Input taking too long"));
9493
return;
9594
}
9695
if (self->first_edge) {
@@ -154,7 +153,6 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t* self,
154153
self->start = 0;
155154
self->len = 0;
156155
self->first_edge = true;
157-
self->errored_too_fast = false;
158156

159157
if (refcount == 0) {
160158
// Find a spare timer.
@@ -264,9 +262,6 @@ void common_hal_pulseio_pulsein_resume(pulseio_pulsein_obj_t* self,
264262
// Make sure we're paused.
265263
common_hal_pulseio_pulsein_pause(self);
266264

267-
// Reset erroring
268-
self->errored_too_fast = false;
269-
270265
// Send the trigger pulse.
271266
if (trigger_duration > 0) {
272267
gpio_set_pin_pull_mode(self->pin, GPIO_PULL_OFF);

supervisor/background_callback.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
#ifndef CIRCUITPY_INCLUDED_SUPERVISOR_BACKGROUND_CALLBACK_H
2828
#define CIRCUITPY_INCLUDED_SUPERVISOR_BACKGROUND_CALLBACK_H
2929

30+
#include "supervisor/port.h"
31+
3032
/** Background callbacks are a linked list of tasks to call in the background.
3133
*
3234
* Include a member of type `background_callback_t` inside an object
@@ -84,4 +86,6 @@ void background_callback_end_critical_section(void);
8486
*/
8587
void background_callback_gc_collect(void);
8688

89+
uint64_t background_get_ticks(void);
90+
8791
#endif

supervisor/port.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ uint32_t *port_heap_get_top(void);
7373
void port_set_saved_word(uint32_t);
7474
uint32_t port_get_saved_word(void);
7575

76+
// Used to keep track of last time background was run
77+
uint64_t get_background_ticks(void);
78+
7679
// Get the raw tick count since start up. A tick is 1/1024 of a second, a common low frequency
7780
// clock rate. If subticks is not NULL then the port will fill in the number of subticks where each
7881
// tick is 32 subticks (for a resolution of 1/32768 or 30.5ish microseconds.)

supervisor/shared/background_callback.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ STATIC volatile background_callback_t *callback_head, *callback_tail;
3737
#define CALLBACK_CRITICAL_BEGIN (common_hal_mcu_disable_interrupts())
3838
#define CALLBACK_CRITICAL_END (common_hal_mcu_enable_interrupts())
3939

40+
volatile uint64_t last_background_tick = 0;
41+
42+
uint64_t get_background_ticks(void) {
43+
return last_background_tick;
44+
}
45+
4046
void background_callback_add_core(background_callback_t *cb) {
4147
CALLBACK_CRITICAL_BEGIN;
4248
if (cb->prev || callback_head == cb) {
@@ -64,6 +70,7 @@ void background_callback_add(background_callback_t *cb, background_callback_fun
6470

6571
static bool in_background_callback;
6672
void background_callback_run_all() {
73+
last_background_tick = port_get_raw_ticks(NULL);
6774
if (!callback_head) {
6875
return;
6976
}

supervisor/shared/tick.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ static volatile uint64_t PLACE_IN_DTCM_BSS(background_ticks);
6868

6969
static background_callback_t tick_callback;
7070

71-
volatile uint64_t last_finished_tick = 0;
72-
7371
void supervisor_background_tasks(void *unused) {
7472
port_start_background_task();
7573

@@ -93,13 +91,11 @@ void supervisor_background_tasks(void *unused) {
9391

9492
assert_heap_ok();
9593

96-
last_finished_tick = port_get_raw_ticks(NULL);
97-
9894
port_finish_background_task();
9995
}
10096

10197
bool supervisor_background_tasks_ok(void) {
102-
return port_get_raw_ticks(NULL) - last_finished_tick < 1024;
98+
return port_get_raw_ticks(NULL) - get_background_ticks() < 1024;
10399
}
104100

105101
void supervisor_tick(void) {

0 commit comments

Comments
 (0)