summaryrefslogtreecommitdiff
path: root/ports
diff options
context:
space:
mode:
authorDan Halbert <halbert@halwitz.org>2018-06-08 17:59:06 -0400
committerGitHub <noreply@github.com>2018-06-08 17:59:06 -0400
commitb2d98edb4ed99efabd862e540613e4ac8550b50d (patch)
treec6f44d80d34f232777904ed14886c1578c19fcf9 /ports
parent4e4d795da54605b3a541861b4ed387119808f1b4 (diff)
parent8fb34a584664c800a4ea4d2d4c351c822bb03a98 (diff)
Merge pull request #901 from tannewt/pulseio_too_fast
Prevent freezing USB during high frequency PulseIn.
Diffstat (limited to 'ports')
-rw-r--r--ports/atmel-samd/background.c8
-rw-r--r--ports/atmel-samd/background.h3
-rw-r--r--ports/atmel-samd/bindings/samd/Clock.c10
-rw-r--r--ports/atmel-samd/bindings/samd/Clock.h10
-rw-r--r--ports/atmel-samd/boards/arduino_zero/mpconfigboard.h4
-rw-r--r--ports/atmel-samd/boards/circuitplayground_express/mpconfigboard.h4
-rw-r--r--ports/atmel-samd/boards/circuitplayground_express_crickit/mpconfigboard.h4
-rw-r--r--ports/atmel-samd/boards/feather_m0_adalogger/mpconfigboard.h4
-rw-r--r--ports/atmel-samd/boards/feather_m0_basic/mpconfigboard.h4
-rw-r--r--ports/atmel-samd/boards/feather_m0_express/mpconfigboard.h4
-rw-r--r--ports/atmel-samd/boards/feather_m0_rfm69/mpconfigboard.h4
-rw-r--r--ports/atmel-samd/boards/feather_m0_rfm9x/mpconfigboard.h4
-rw-r--r--ports/atmel-samd/boards/feather_m0_supersized/mpconfigboard.h4
-rw-r--r--ports/atmel-samd/boards/feather_m4_express/mpconfigboard.h4
-rw-r--r--ports/atmel-samd/boards/gemma_m0/mpconfigboard.h3
-rw-r--r--ports/atmel-samd/boards/itsybitsy_m0_express/mpconfigboard.h4
-rw-r--r--ports/atmel-samd/boards/itsybitsy_m4_express/mpconfigboard.h4
-rw-r--r--ports/atmel-samd/boards/metro_m0_express/mpconfigboard.h4
-rw-r--r--ports/atmel-samd/boards/metro_m4_express/mpconfigboard.h4
-rw-r--r--ports/atmel-samd/boards/trinket_m0/mpconfigboard.h3
-rw-r--r--ports/atmel-samd/boards/trinket_m0_haxpress/mpconfigboard.h4
-rw-r--r--ports/atmel-samd/boards/ugame10/mpconfigboard.h4
-rw-r--r--ports/atmel-samd/common-hal/microcontroller/__init__.c14
-rw-r--r--ports/atmel-samd/common-hal/pulseio/PulseIn.c16
-rw-r--r--ports/atmel-samd/common-hal/pulseio/PulseIn.h1
-rw-r--r--ports/atmel-samd/peripherals/samd21/clocks.c3
-rw-r--r--ports/atmel-samd/tick.c16
-rw-r--r--ports/nrf/common-hal/pulseio/PulseIn.c4
28 files changed, 130 insertions, 25 deletions
diff --git a/ports/atmel-samd/background.c b/ports/atmel-samd/background.c
index 92648f42e..4cba7a110 100644
--- a/ports/atmel-samd/background.c
+++ b/ports/atmel-samd/background.c
@@ -26,11 +26,19 @@
#include "background.h"
#include "audio_dma.h"
+#include "tick.h"
#include "usb.h"
#include "usb_mass_storage.h"
+volatile uint64_t last_finished_tick = 0;
+
void run_background_tasks(void) {
audio_dma_background();
usb_msc_background();
usb_cdc_background();
+ last_finished_tick = ticks_ms;
+}
+
+bool background_tasks_ok(void) {
+ return ticks_ms - last_finished_tick < 1000;
}
diff --git a/ports/atmel-samd/background.h b/ports/atmel-samd/background.h
index f7fb10a1f..e841049a4 100644
--- a/ports/atmel-samd/background.h
+++ b/ports/atmel-samd/background.h
@@ -27,6 +27,9 @@
#ifndef MICROPY_INCLUDED_ATMEL_SAMD_BACKGROUND_H
#define MICROPY_INCLUDED_ATMEL_SAMD_BACKGROUND_H
+#include <stdbool.h>
+
void run_background_tasks(void);
+bool background_tasks_ok(void);
#endif // MICROPY_INCLUDED_ATMEL_SAMD_BACKGROUND_H
diff --git a/ports/atmel-samd/bindings/samd/Clock.c b/ports/atmel-samd/bindings/samd/Clock.c
index 3c87177a4..e09cc0bd8 100644
--- a/ports/atmel-samd/bindings/samd/Clock.c
+++ b/ports/atmel-samd/bindings/samd/Clock.c
@@ -47,15 +47,7 @@
STATIC void samd_clock_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
samd_clock_obj_t *self = MP_OBJ_TO_PTR(self_in);
- mp_printf(print, "%q.%q.%s(", MP_QSTR_samd, MP_QSTR_clock, self->name);
- if (clock_get_enabled(self->type, self->index)) {
- mp_printf(print, "frequency=%u", clock_get_frequency(self->type, self->index));
- uint32_t calibration = clock_get_calibration(self->type, self->index);
- if (calibration) {
- mp_printf(print, ", calibration=%u", calibration);
- }
- }
- mp_printf(print, ")");
+ mp_printf(print, "%q.%q.%q", MP_QSTR_samd, MP_QSTR_clock, self->name);
}
//| .. attribute:: enabled
diff --git a/ports/atmel-samd/bindings/samd/Clock.h b/ports/atmel-samd/bindings/samd/Clock.h
index 0d13ae253..ccc8f10d1 100644
--- a/ports/atmel-samd/bindings/samd/Clock.h
+++ b/ports/atmel-samd/bindings/samd/Clock.h
@@ -31,7 +31,7 @@
typedef struct {
mp_obj_base_t base;
- const char *name;
+ qstr name;
uint8_t type;
uint8_t index;
} samd_clock_obj_t;
@@ -39,7 +39,7 @@ typedef struct {
#define CLOCK(_name, _type, _index) \
const samd_clock_obj_t clock_ ## _name = { \
{ &samd_clock_type }, \
- .name = #_name, \
+ .name = MP_QSTR_ ## _name, \
.type = _type, \
.index = _index, \
}
@@ -47,7 +47,7 @@ const samd_clock_obj_t clock_ ## _name = { \
#define CLOCK_SOURCE(_name) \
const samd_clock_obj_t clock_ ## _name = { \
{ &samd_clock_type }, \
- .name = #_name, \
+ .name = MP_QSTR_ ## _name, \
.type = 0, \
.index = GCLK_SOURCE_ ## _name, \
}
@@ -55,7 +55,7 @@ const samd_clock_obj_t clock_ ## _name = { \
#define CLOCK_GCLK(_name) \
const samd_clock_obj_t clock_ ## _name = { \
{ &samd_clock_type }, \
- .name = #_name, \
+ .name = MP_QSTR_ ## _name, \
.type = 1, \
.index = _name ## _GCLK_ID, \
}
@@ -63,7 +63,7 @@ const samd_clock_obj_t clock_ ## _name = { \
#define CLOCK_GCLK_(_name, _extra) \
const samd_clock_obj_t clock_ ## _name ## _ ## _extra = { \
{ &samd_clock_type }, \
- .name = #_name "_" #_extra, \
+ .name = MP_QSTR_ ## _name ## _ ## _extra, \
.type = 1, \
.index = _name ## _GCLK_ID_ ## _extra, \
}
diff --git a/ports/atmel-samd/boards/arduino_zero/mpconfigboard.h b/ports/atmel-samd/boards/arduino_zero/mpconfigboard.h
index a32f128f5..1382d4736 100644
--- a/ports/atmel-samd/boards/arduino_zero/mpconfigboard.h
+++ b/ports/atmel-samd/boards/arduino_zero/mpconfigboard.h
@@ -24,3 +24,7 @@
#define DEFAULT_UART_BUS_RX (&pin_PA11)
#define DEFAULT_UART_BUS_TX (&pin_PA10)
+
+// USB is always used internally so skip the pin objects for it.
+#define IGNORE_PIN_PA24 1
+#define IGNORE_PIN_PA25 1
diff --git a/ports/atmel-samd/boards/circuitplayground_express/mpconfigboard.h b/ports/atmel-samd/boards/circuitplayground_express/mpconfigboard.h
index 3d97e2cb1..5077840cb 100644
--- a/ports/atmel-samd/boards/circuitplayground_express/mpconfigboard.h
+++ b/ports/atmel-samd/boards/circuitplayground_express/mpconfigboard.h
@@ -68,3 +68,7 @@
#define DEFAULT_UART_BUS_RX (&pin_PB09)
#define DEFAULT_UART_BUS_TX (&pin_PB08)
+
+// USB is always used internally so skip the pin objects for it.
+#define IGNORE_PIN_PA24 1
+#define IGNORE_PIN_PA25 1
diff --git a/ports/atmel-samd/boards/circuitplayground_express_crickit/mpconfigboard.h b/ports/atmel-samd/boards/circuitplayground_express_crickit/mpconfigboard.h
index 83cc19d9f..638a6646c 100644
--- a/ports/atmel-samd/boards/circuitplayground_express_crickit/mpconfigboard.h
+++ b/ports/atmel-samd/boards/circuitplayground_express_crickit/mpconfigboard.h
@@ -71,3 +71,7 @@
#define DEFAULT_UART_BUS_RX (&pin_PB09)
#define DEFAULT_UART_BUS_TX (&pin_PB08)
+
+// USB is always used internally so skip the pin objects for it.
+#define IGNORE_PIN_PA24 1
+#define IGNORE_PIN_PA25 1
diff --git a/ports/atmel-samd/boards/feather_m0_adalogger/mpconfigboard.h b/ports/atmel-samd/boards/feather_m0_adalogger/mpconfigboard.h
index 94caa7d04..c8b5c56ee 100644
--- a/ports/atmel-samd/boards/feather_m0_adalogger/mpconfigboard.h
+++ b/ports/atmel-samd/boards/feather_m0_adalogger/mpconfigboard.h
@@ -22,3 +22,7 @@
#define DEFAULT_UART_BUS_RX (&pin_PA11)
#define DEFAULT_UART_BUS_TX (&pin_PA10)
+
+// USB is always used internally so skip the pin objects for it.
+#define IGNORE_PIN_PA24 1
+#define IGNORE_PIN_PA25 1
diff --git a/ports/atmel-samd/boards/feather_m0_basic/mpconfigboard.h b/ports/atmel-samd/boards/feather_m0_basic/mpconfigboard.h
index 34de8e166..dcac9749d 100644
--- a/ports/atmel-samd/boards/feather_m0_basic/mpconfigboard.h
+++ b/ports/atmel-samd/boards/feather_m0_basic/mpconfigboard.h
@@ -23,3 +23,7 @@
#define DEFAULT_UART_BUS_RX (&pin_PA11)
#define DEFAULT_UART_BUS_TX (&pin_PA10)
+
+// USB is always used internally so skip the pin objects for it.
+#define IGNORE_PIN_PA24 1
+#define IGNORE_PIN_PA25 1
diff --git a/ports/atmel-samd/boards/feather_m0_express/mpconfigboard.h b/ports/atmel-samd/boards/feather_m0_express/mpconfigboard.h
index bfa8c642a..108d67d9f 100644
--- a/ports/atmel-samd/boards/feather_m0_express/mpconfigboard.h
+++ b/ports/atmel-samd/boards/feather_m0_express/mpconfigboard.h
@@ -58,3 +58,7 @@
#define DEFAULT_UART_BUS_RX (&pin_PA11)
#define DEFAULT_UART_BUS_TX (&pin_PA10)
+
+// USB is always used internally so skip the pin objects for it.
+#define IGNORE_PIN_PA24 1
+#define IGNORE_PIN_PA25 1
diff --git a/ports/atmel-samd/boards/feather_m0_rfm69/mpconfigboard.h b/ports/atmel-samd/boards/feather_m0_rfm69/mpconfigboard.h
index 4f4ea2ffe..4a530ed29 100644
--- a/ports/atmel-samd/boards/feather_m0_rfm69/mpconfigboard.h
+++ b/ports/atmel-samd/boards/feather_m0_rfm69/mpconfigboard.h
@@ -23,3 +23,7 @@
#define DEFAULT_UART_BUS_RX (&pin_PA11)
#define DEFAULT_UART_BUS_TX (&pin_PA10)
+
+// USB is always used internally so skip the pin objects for it.
+#define IGNORE_PIN_PA24 1
+#define IGNORE_PIN_PA25 1
diff --git a/ports/atmel-samd/boards/feather_m0_rfm9x/mpconfigboard.h b/ports/atmel-samd/boards/feather_m0_rfm9x/mpconfigboard.h
index a9d586c2e..3a6f28c12 100644
--- a/ports/atmel-samd/boards/feather_m0_rfm9x/mpconfigboard.h
+++ b/ports/atmel-samd/boards/feather_m0_rfm9x/mpconfigboard.h
@@ -23,3 +23,7 @@
#define DEFAULT_UART_BUS_RX (&pin_PA11)
#define DEFAULT_UART_BUS_TX (&pin_PA10)
+
+// USB is always used internally so skip the pin objects for it.
+#define IGNORE_PIN_PA24 1
+#define IGNORE_PIN_PA25 1
diff --git a/ports/atmel-samd/boards/feather_m0_supersized/mpconfigboard.h b/ports/atmel-samd/boards/feather_m0_supersized/mpconfigboard.h
index c8118e48b..a7a2d7de0 100644
--- a/ports/atmel-samd/boards/feather_m0_supersized/mpconfigboard.h
+++ b/ports/atmel-samd/boards/feather_m0_supersized/mpconfigboard.h
@@ -57,3 +57,7 @@
#define DEFAULT_UART_BUS_RX (&pin_PA11)
#define DEFAULT_UART_BUS_TX (&pin_PA10)
+
+// USB is always used internally so skip the pin objects for it.
+#define IGNORE_PIN_PA24 1
+#define IGNORE_PIN_PA25 1
diff --git a/ports/atmel-samd/boards/feather_m4_express/mpconfigboard.h b/ports/atmel-samd/boards/feather_m4_express/mpconfigboard.h
index bb5c0ddcc..c82395baf 100644
--- a/ports/atmel-samd/boards/feather_m4_express/mpconfigboard.h
+++ b/ports/atmel-samd/boards/feather_m4_express/mpconfigboard.h
@@ -43,3 +43,7 @@
#define DEFAULT_UART_BUS_RX (&pin_PB17)
#define DEFAULT_UART_BUS_TX (&pin_PB16)
+
+// USB is always used internally so skip the pin objects for it.
+#define IGNORE_PIN_PA24 1
+#define IGNORE_PIN_PA25 1
diff --git a/ports/atmel-samd/boards/gemma_m0/mpconfigboard.h b/ports/atmel-samd/boards/gemma_m0/mpconfigboard.h
index 53e802f17..1ec217096 100644
--- a/ports/atmel-samd/boards/gemma_m0/mpconfigboard.h
+++ b/ports/atmel-samd/boards/gemma_m0/mpconfigboard.h
@@ -40,6 +40,9 @@
#define IGNORE_PIN_PA20 1
#define IGNORE_PIN_PA21 1
#define IGNORE_PIN_PA22 1
+// USB is always used.
+#define IGNORE_PIN_PA24 1
+#define IGNORE_PIN_PA25 1
#define IGNORE_PIN_PA27 1
#define IGNORE_PIN_PA28 1
#define IGNORE_PIN_PA30 1
diff --git a/ports/atmel-samd/boards/itsybitsy_m0_express/mpconfigboard.h b/ports/atmel-samd/boards/itsybitsy_m0_express/mpconfigboard.h
index 3adcb7f16..f56f57c46 100644
--- a/ports/atmel-samd/boards/itsybitsy_m0_express/mpconfigboard.h
+++ b/ports/atmel-samd/boards/itsybitsy_m0_express/mpconfigboard.h
@@ -56,3 +56,7 @@
#define DEFAULT_UART_BUS_RX (&pin_PA11)
#define DEFAULT_UART_BUS_TX (&pin_PA10)
+
+// USB is always used internally so skip the pin objects for it.
+#define IGNORE_PIN_PA24 1
+#define IGNORE_PIN_PA25 1
diff --git a/ports/atmel-samd/boards/itsybitsy_m4_express/mpconfigboard.h b/ports/atmel-samd/boards/itsybitsy_m4_express/mpconfigboard.h
index 116d4dac6..e47d5390d 100644
--- a/ports/atmel-samd/boards/itsybitsy_m4_express/mpconfigboard.h
+++ b/ports/atmel-samd/boards/itsybitsy_m4_express/mpconfigboard.h
@@ -41,3 +41,7 @@
#define DEFAULT_UART_BUS_RX (&pin_PA16)
#define DEFAULT_UART_BUS_TX (&pin_PA17)
+
+// USB is always used internally so skip the pin objects for it.
+#define IGNORE_PIN_PA24 1
+#define IGNORE_PIN_PA25 1
diff --git a/ports/atmel-samd/boards/metro_m0_express/mpconfigboard.h b/ports/atmel-samd/boards/metro_m0_express/mpconfigboard.h
index f798c5d36..135d6ae92 100644
--- a/ports/atmel-samd/boards/metro_m0_express/mpconfigboard.h
+++ b/ports/atmel-samd/boards/metro_m0_express/mpconfigboard.h
@@ -59,3 +59,7 @@
#define DEFAULT_UART_BUS_RX (&pin_PA11)
#define DEFAULT_UART_BUS_TX (&pin_PA10)
+
+// USB is always used internally so skip the pin objects for it.
+#define IGNORE_PIN_PA24 1
+#define IGNORE_PIN_PA25 1
diff --git a/ports/atmel-samd/boards/metro_m4_express/mpconfigboard.h b/ports/atmel-samd/boards/metro_m4_express/mpconfigboard.h
index 4d206a4c8..050f678dd 100644
--- a/ports/atmel-samd/boards/metro_m4_express/mpconfigboard.h
+++ b/ports/atmel-samd/boards/metro_m4_express/mpconfigboard.h
@@ -44,3 +44,7 @@
#define DEFAULT_UART_BUS_RX (&pin_PA23)
#define DEFAULT_UART_BUS_TX (&pin_PA22)
+
+// USB is always used internally so skip the pin objects for it.
+#define IGNORE_PIN_PA24 1
+#define IGNORE_PIN_PA25 1
diff --git a/ports/atmel-samd/boards/trinket_m0/mpconfigboard.h b/ports/atmel-samd/boards/trinket_m0/mpconfigboard.h
index d561947e3..9036f8e7b 100644
--- a/ports/atmel-samd/boards/trinket_m0/mpconfigboard.h
+++ b/ports/atmel-samd/boards/trinket_m0/mpconfigboard.h
@@ -30,6 +30,9 @@
#define IGNORE_PIN_PA21 1
#define IGNORE_PIN_PA22 1
#define IGNORE_PIN_PA23 1
+// USB is always used internally so skip the pin objects for it.
+#define IGNORE_PIN_PA24 1
+#define IGNORE_PIN_PA25 1
#define IGNORE_PIN_PA27 1
#define IGNORE_PIN_PA28 1
#define IGNORE_PIN_PA30 1
diff --git a/ports/atmel-samd/boards/trinket_m0_haxpress/mpconfigboard.h b/ports/atmel-samd/boards/trinket_m0_haxpress/mpconfigboard.h
index 3377d1b7e..8e3fdd7a8 100644
--- a/ports/atmel-samd/boards/trinket_m0_haxpress/mpconfigboard.h
+++ b/ports/atmel-samd/boards/trinket_m0_haxpress/mpconfigboard.h
@@ -64,3 +64,7 @@
#define DEFAULT_UART_BUS_RX (&pin_PA07)
#define DEFAULT_UART_BUS_TX (&pin_PA06)
+
+// USB is always used internally so skip the pin objects for it.
+#define IGNORE_PIN_PA24 1
+#define IGNORE_PIN_PA25 1
diff --git a/ports/atmel-samd/boards/ugame10/mpconfigboard.h b/ports/atmel-samd/boards/ugame10/mpconfigboard.h
index 4e5e88569..ed822952d 100644
--- a/ports/atmel-samd/boards/ugame10/mpconfigboard.h
+++ b/ports/atmel-samd/boards/ugame10/mpconfigboard.h
@@ -52,3 +52,7 @@
{ MP_OBJ_NEW_QSTR(MP_QSTR_audioio), (mp_obj_t)&audioio_module }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_gamepad),(mp_obj_t)&gamepad_module }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR__stage), (mp_obj_t)&stage_module }
+
+// USB is always used internally so skip the pin objects for it.
+#define IGNORE_PIN_PA24 1
+#define IGNORE_PIN_PA25 1
diff --git a/ports/atmel-samd/common-hal/microcontroller/__init__.c b/ports/atmel-samd/common-hal/microcontroller/__init__.c
index c57b6939c..ad4d81ddd 100644
--- a/ports/atmel-samd/common-hal/microcontroller/__init__.c
+++ b/ports/atmel-samd/common-hal/microcontroller/__init__.c
@@ -40,18 +40,10 @@ void common_hal_mcu_delay_us(uint32_t delay) {
mp_hal_delay_us(delay);
}
-// Interrupt flags that will be saved and restored during disable/Enable
-// interrupt functions below.
-
-// ASF4's interrupt disable doesn't handle duplicate calls
-volatile uint32_t interrupt_flags;
volatile uint32_t nesting_count = 0;
void common_hal_mcu_disable_interrupts(void) {
- if (nesting_count == 0) {
- interrupt_flags = __get_PRIMASK();
- __disable_irq();
- __DMB();
- }
+ __disable_irq();
+ __DMB();
nesting_count++;
}
@@ -66,7 +58,7 @@ void common_hal_mcu_enable_interrupts(void) {
return;
}
__DMB();
- __set_PRIMASK(interrupt_flags);
+ __enable_irq();
}
extern uint32_t _ezero;
diff --git a/ports/atmel-samd/common-hal/pulseio/PulseIn.c b/ports/atmel-samd/common-hal/pulseio/PulseIn.c
index 99a60a829..d16bbf9d2 100644
--- a/ports/atmel-samd/common-hal/pulseio/PulseIn.c
+++ b/ports/atmel-samd/common-hal/pulseio/PulseIn.c
@@ -31,6 +31,7 @@
#include "atmel_start_pins.h"
#include "hal/include/hal_gpio.h"
+#include "background.h"
#include "mpconfigport.h"
#include "py/gc.h"
#include "py/runtime.h"
@@ -60,10 +61,16 @@ void pulsein_interrupt_handler(uint8_t channel) {
uint32_t current_us;
uint64_t current_ms;
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;
pulseio_pulsein_obj_t* self = get_eic_channel_data(channel);
+ if (!background_tasks_ok() || self->errored_too_fast) {
+ self->errored_too_fast = true;
+ common_hal_pulseio_pulsein_pause(self);
+ return;
+ }
if (self->first_edge) {
self->first_edge = false;
pulsein_set_config(self, false);
@@ -118,6 +125,7 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t* self,
self->first_edge = true;
self->last_us = 0;
self->last_ms = 0;
+ self->errored_too_fast = false;
set_eic_channel_data(pin->extint_channel, (void*) self);
@@ -157,6 +165,9 @@ 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);
@@ -207,6 +218,11 @@ uint16_t common_hal_pulseio_pulsein_get_len(pulseio_pulsein_obj_t* self) {
return self->len;
}
+bool common_hal_pulseio_pulsein_get_paused(pulseio_pulsein_obj_t* self) {
+ uint32_t mask = 1 << self->channel;
+ return (EIC->INTENSET.reg & (mask << EIC_INTENSET_EXTINT_Pos)) == 0;
+}
+
uint16_t common_hal_pulseio_pulsein_get_item(pulseio_pulsein_obj_t* self,
int16_t index) {
common_hal_mcu_disable_interrupts();
diff --git a/ports/atmel-samd/common-hal/pulseio/PulseIn.h b/ports/atmel-samd/common-hal/pulseio/PulseIn.h
index 3d79b50c3..f5326d9e5 100644
--- a/ports/atmel-samd/common-hal/pulseio/PulseIn.h
+++ b/ports/atmel-samd/common-hal/pulseio/PulseIn.h
@@ -43,6 +43,7 @@ typedef struct {
volatile bool first_edge;
volatile uint64_t last_ms;
volatile uint16_t last_us;
+ volatile bool errored_too_fast;
} pulseio_pulsein_obj_t;
void pulsein_reset(void);
diff --git a/ports/atmel-samd/peripherals/samd21/clocks.c b/ports/atmel-samd/peripherals/samd21/clocks.c
index 51b7ad993..422290e8b 100644
--- a/ports/atmel-samd/peripherals/samd21/clocks.c
+++ b/ports/atmel-samd/peripherals/samd21/clocks.c
@@ -130,6 +130,9 @@ static void init_clock_source_dfll48m_xosc(void) {
SYSCTRL_DFLLCTRL_ENABLE;
while (!SYSCTRL->PCLKSR.bit.DFLLRDY) {}
while (GCLK->STATUS.bit.SYNCBUSY) {}
+
+ // Wait for the fine lock on the DFLL.
+ while (!SYSCTRL->PCLKSR.bit.DFLLLCKC || !SYSCTRL->PCLKSR.bit.DFLLLCKF) {}
}
static void init_clock_source_dfll48m_usb(void) {
diff --git a/ports/atmel-samd/tick.c b/ports/atmel-samd/tick.c
index 6cd7c7833..9753a1a0c 100644
--- a/ports/atmel-samd/tick.c
+++ b/ports/atmel-samd/tick.c
@@ -60,6 +60,22 @@ void tick_init() {
uint32_t ticks_per_ms = common_hal_mcu_processor_get_frequency() / 1000;
SysTick_Config(ticks_per_ms-1);
NVIC_EnableIRQ(SysTick_IRQn);
+ // Set all peripheral interrupt priorities to the lowest priority by default.
+ for (uint16_t i = 0; i < PERIPH_COUNT_IRQn; i++) {
+ NVIC_SetPriority(i, (1UL << __NVIC_PRIO_BITS) - 1UL);
+ }
+ // Bump up the systick interrupt.
+ NVIC_SetPriority(SysTick_IRQn, 1);
+ #ifdef SAMD21
+ NVIC_SetPriority(USB_IRQn, 1);
+ #endif
+
+ #ifdef SAMD51
+ NVIC_SetPriority(USB_0_IRQn, 1);
+ NVIC_SetPriority(USB_1_IRQn, 1);
+ NVIC_SetPriority(USB_2_IRQn, 1);
+ NVIC_SetPriority(USB_3_IRQn, 1);
+ #endif
}
void tick_delay(uint32_t us) {
diff --git a/ports/nrf/common-hal/pulseio/PulseIn.c b/ports/nrf/common-hal/pulseio/PulseIn.c
index aa6bb8665..e759ac3a3 100644
--- a/ports/nrf/common-hal/pulseio/PulseIn.c
+++ b/ports/nrf/common-hal/pulseio/PulseIn.c
@@ -71,6 +71,10 @@ uint16_t common_hal_pulseio_pulsein_get_maxlen(pulseio_pulsein_obj_t* self) {
return 0xadaf;
}
+bool common_hal_pulseio_pulsein_get_paused(pulseio_pulsein_obj_t* self) {
+ return true;
+}
+
uint16_t common_hal_pulseio_pulsein_get_len(pulseio_pulsein_obj_t* self) {
return 0xadaf;
}