summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xmain.c3
-rw-r--r--ports/atmel-samd/background.c13
-rw-r--r--ports/atmel-samd/background.h1
-rw-r--r--ports/nrf/background.c12
-rw-r--r--ports/nrf/background.h35
-rw-r--r--ports/nrf/supervisor/qspi_flash.c3
6 files changed, 65 insertions, 2 deletions
diff --git a/main.c b/main.c
index dc47a70de..f7b289776 100755
--- a/main.c
+++ b/main.c
@@ -43,6 +43,7 @@
#include "lib/mp-readline/readline.h"
#include "lib/utils/pyexec.h"
+#include "background.h"
#include "mpconfigboard.h"
#include "shared-module/displayio/__init__.h"
#include "supervisor/cpu.h"
@@ -89,6 +90,8 @@ void start_mp(supervisor_allocation* heap) {
reset_status_led();
autoreload_stop();
+ background_tasks_reset();
+
// Stack limit should be less than real stack size, so we have a chance
// to recover from limit hit. (Limit is measured in bytes.)
mp_stack_ctrl_init();
diff --git a/ports/atmel-samd/background.c b/ports/atmel-samd/background.c
index a8c4e3891..4e88d34e7 100644
--- a/ports/atmel-samd/background.c
+++ b/ports/atmel-samd/background.c
@@ -42,8 +42,20 @@ volatile uint64_t last_finished_tick = 0;
bool stack_ok_so_far = true;
+static bool running_background_tasks = false;
+
+void background_tasks_reset(void) {
+ running_background_tasks = false;
+}
+
void run_background_tasks(void) {
+ // Don't call ourselves recursively.
+ if (running_background_tasks) {
+ return;
+ }
assert_heap_ok();
+ running_background_tasks = true;
+
#if (defined(SAMD21) && defined(PIN_PA02)) || defined(SAMD51)
audio_dma_background();
#endif
@@ -56,6 +68,7 @@ void run_background_tasks(void) {
#endif
filesystem_background();
usb_background();
+ running_background_tasks = false;
assert_heap_ok();
last_finished_tick = ticks_ms;
diff --git a/ports/atmel-samd/background.h b/ports/atmel-samd/background.h
index 8d1316e73..d9866a6ab 100644
--- a/ports/atmel-samd/background.h
+++ b/ports/atmel-samd/background.h
@@ -29,6 +29,7 @@
#include <stdbool.h>
+void background_tasks_reset(void);
void run_background_tasks(void);
void run_background_vm_tasks(void);
bool background_tasks_ok(void);
diff --git a/ports/nrf/background.c b/ports/nrf/background.c
index ea6e846b3..3fb5febd3 100644
--- a/ports/nrf/background.c
+++ b/ports/nrf/background.c
@@ -33,13 +33,25 @@
#include "shared-module/displayio/__init__.h"
#endif
+static bool running_background_tasks = false;
+
+void background_tasks_reset(void) {
+ running_background_tasks = false;
+}
+
void run_background_tasks(void) {
+ // Don't call ourselves recursively.
+ if (running_background_tasks) {
+ return;
+ }
+ running_background_tasks = true;
filesystem_background();
usb_background();
#ifdef CIRCUITPY_DISPLAYIO
displayio_refresh_displays();
#endif
+ running_background_tasks = false;
assert_heap_ok();
}
diff --git a/ports/nrf/background.h b/ports/nrf/background.h
new file mode 100644
index 000000000..d53681c0f
--- /dev/null
+++ b/ports/nrf/background.h
@@ -0,0 +1,35 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2019 Dan Halbert 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_BACKGROUND_H
+#define MICROPY_INCLUDED_NRF_BACKGROUND_H
+
+#include <stdbool.h>
+
+void background_tasks_reset(void);
+void run_background_tasks(void);
+
+#endif // MICROPY_INCLUDED_NRF_BACKGROUND_H
diff --git a/ports/nrf/supervisor/qspi_flash.c b/ports/nrf/supervisor/qspi_flash.c
index 51a9ec032..bb449d881 100644
--- a/ports/nrf/supervisor/qspi_flash.c
+++ b/ports/nrf/supervisor/qspi_flash.c
@@ -47,8 +47,7 @@ bool spi_flash_command(uint8_t command) {
.wipwait = false,
.wren = false
};
- nrfx_qspi_cinstr_xfer(&cinstr_cfg, NULL, NULL);
- return true;
+ return nrfx_qspi_cinstr_xfer(&cinstr_cfg, NULL, NULL) == NRFX_SUCCESS;
}
bool spi_flash_read_command(uint8_t command, uint8_t* response, uint32_t length) {