summaryrefslogtreecommitdiff
path: root/ports
diff options
context:
space:
mode:
authorJeff Epler <jepler@gmail.com>2020-07-13 10:33:58 -0500
committerJeff Epler <jepler@gmail.com>2020-07-15 11:49:44 -0500
commit1df48176ce2e4111c4629269cb86d2a6e365a3d2 (patch)
treea08ff57a9045405c61ee835e840bcef4a7a53244 /ports
parent6160d11c5a04f60e54ce977fd73fafa5ba858aa0 (diff)
supervisor: factor supervisor_background_tasks from sundry ports
Diffstat (limited to 'ports')
-rw-r--r--ports/atmel-samd/background.c48
-rw-r--r--ports/atmel-samd/background.h5
-rw-r--r--ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c3
-rw-r--r--ports/atmel-samd/common-hal/pulseio/PulseIn.c3
-rw-r--r--ports/cxd56/background.c24
-rw-r--r--ports/cxd56/background.h3
-rw-r--r--ports/esp32s2/background.c23
-rw-r--r--ports/esp32s2/background.h3
-rw-r--r--ports/litex/background.c32
-rw-r--r--ports/litex/background.h5
-rw-r--r--ports/mimxrt10xx/background.c53
-rw-r--r--ports/mimxrt10xx/background.h7
-rw-r--r--ports/mimxrt10xx/common-hal/pulseio/PulseIn.c2
-rw-r--r--ports/nrf/background.c27
-rw-r--r--ports/nrf/background.h5
-rw-r--r--ports/stm/background.c28
-rw-r--r--ports/stm/background.h5
17 files changed, 30 insertions, 246 deletions
diff --git a/ports/atmel-samd/background.c b/ports/atmel-samd/background.c
index 5c499ab3a..62c233a3f 100644
--- a/ports/atmel-samd/background.c
+++ b/ports/atmel-samd/background.c
@@ -39,59 +39,21 @@
#include "shared-module/displayio/__init__.h"
#endif
-volatile uint64_t last_finished_tick = 0;
-
-bool stack_ok_so_far = true;
-
-static bool running_background_tasks = false;
-
#ifdef MONITOR_BACKGROUND_TASKS
// PB03 is physical pin "SCL" on the Metro M4 express
// so you can't use this code AND an i2c peripheral
// at the same time unless you change this
-STATIC void start_background_task(void) {
+void port_start_background_task(void) {
REG_PORT_DIRSET1 = (1<<3);
REG_PORT_OUTSET1 = (1<<3);
}
-STATIC void finish_background_task(void) {
+void port_finish_background_task(void) {
REG_PORT_OUTCLR1 = (1<<3);
}
#else
-STATIC void start_background_task(void) {}
-STATIC void finish_background_task(void) {}
+void port_start_background_task(void) {}
+void port_finish_background_task(void) {}
#endif
-void background_tasks_reset(void) {
- running_background_tasks = false;
-}
-
-void run_background_tasks(void) {
- // Don't call ourselves recursively.
- if (running_background_tasks) {
- return;
- }
-
- start_background_task();
-
- assert_heap_ok();
- running_background_tasks = true;
-
- #if CIRCUITPY_DISPLAYIO
- displayio_background();
- #endif
-
- #if CIRCUITPY_NETWORK
- network_module_background();
- #endif
- filesystem_background();
- running_background_tasks = false;
- assert_heap_ok();
-
- last_finished_tick = port_get_raw_ticks(NULL);
- finish_background_task();
-}
-
-bool background_tasks_ok(void) {
- return port_get_raw_ticks(NULL) - last_finished_tick < 1024;
-}
+void port_background_task(void) {}
diff --git a/ports/atmel-samd/background.h b/ports/atmel-samd/background.h
index d9866a6ab..2a89c3b1b 100644
--- a/ports/atmel-samd/background.h
+++ b/ports/atmel-samd/background.h
@@ -29,9 +29,4 @@
#include <stdbool.h>
-void background_tasks_reset(void);
-void run_background_tasks(void);
-void run_background_vm_tasks(void);
-bool background_tasks_ok(void);
-
#endif // MICROPY_INCLUDED_ATMEL_SAMD_BACKGROUND_H
diff --git a/ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c b/ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c
index 1952df563..02d0482dc 100644
--- a/ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c
+++ b/ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c
@@ -46,6 +46,7 @@
#include "hpl_gclk_config.h"
#include "shared-bindings/time/__init__.h"
+#include "supervisor/shared/tick.h"
#include "supervisor/shared/translate.h"
#ifdef SAMD21
@@ -132,7 +133,7 @@ void frequencyin_interrupt_handler(uint8_t index) {
}
// Check if we've reached the upper limit of detection
- if (!background_tasks_ok() || self->errored_too_fast) {
+ if (!supervisor_background_tasks_ok() || self->errored_too_fast) {
self->errored_too_fast = true;
frequencyin_emergency_cancel_capture(i);
}
diff --git a/ports/atmel-samd/common-hal/pulseio/PulseIn.c b/ports/atmel-samd/common-hal/pulseio/PulseIn.c
index b825579db..ae58b089d 100644
--- a/ports/atmel-samd/common-hal/pulseio/PulseIn.c
+++ b/ports/atmel-samd/common-hal/pulseio/PulseIn.c
@@ -42,6 +42,7 @@
#include "samd/timers.h"
#include "shared-bindings/microcontroller/__init__.h"
#include "shared-bindings/pulseio/PulseIn.h"
+#include "supervisor/shared/tick.h"
#include "supervisor/shared/translate.h"
// This timer is shared amongst all PulseIn objects as a higher resolution clock.
@@ -87,7 +88,7 @@ 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 (!background_tasks_ok() || self->errored_too_fast) {
+ if (!supervisor_background_tasks_ok() || self->errored_too_fast) {
self->errored_too_fast = true;
common_hal_pulseio_pulsein_pause(self);
return;
diff --git a/ports/cxd56/background.c b/ports/cxd56/background.c
index ade257dd2..6de6d7275 100644
--- a/ports/cxd56/background.c
+++ b/ports/cxd56/background.c
@@ -30,24 +30,6 @@
#include "supervisor/filesystem.h"
#include "supervisor/shared/stack.h"
-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;
-
- usb_background();
- filesystem_background();
-
- running_background_tasks = false;
- assert_heap_ok();
-}
+void port_background_task(void) {}
+void port_start_background_task(void) {}
+void port_finish_background_task(void) {}
diff --git a/ports/cxd56/background.h b/ports/cxd56/background.h
index a38e3faed..5f76e6442 100644
--- a/ports/cxd56/background.h
+++ b/ports/cxd56/background.h
@@ -27,7 +27,4 @@
#ifndef MICROPY_INCLUDED_CXD56_BACKGROUND_H
#define MICROPY_INCLUDED_CXD56_BACKGROUND_H
-void background_tasks_reset(void);
-void run_background_tasks(void);
-
#endif // MICROPY_INCLUDED_CXD56_BACKGROUND_H
diff --git a/ports/esp32s2/background.c b/ports/esp32s2/background.c
index a90fa7d0a..40ce9ecfd 100644
--- a/ports/esp32s2/background.c
+++ b/ports/esp32s2/background.c
@@ -35,27 +35,12 @@
#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;
- }
+void port_background_task(void) {
// Zero delay in case FreeRTOS wants to switch to something else.
vTaskDelay(0);
- running_background_tasks = true;
- filesystem_background();
+}
- #if CIRCUITPY_DISPLAYIO
- displayio_background();
- #endif
- running_background_tasks = false;
+void port_start_background_task(void) {}
- assert_heap_ok();
-}
+void port_finish_background_task(void) {}
diff --git a/ports/esp32s2/background.h b/ports/esp32s2/background.h
index 0e1fb7a56..cb850d4e5 100644
--- a/ports/esp32s2/background.h
+++ b/ports/esp32s2/background.h
@@ -29,7 +29,4 @@
#include <stdbool.h>
-void background_tasks_reset(void);
-void run_background_tasks(void);
-
#endif // MICROPY_INCLUDED_ESP32S2_BACKGROUND_H
diff --git a/ports/litex/background.c b/ports/litex/background.c
index 8c1897043..174d9588a 100644
--- a/ports/litex/background.c
+++ b/ports/litex/background.c
@@ -29,32 +29,6 @@
#include "supervisor/usb.h"
#include "supervisor/shared/stack.h"
-#if CIRCUITPY_DISPLAYIO
-#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();
-
- #if USB_AVAILABLE
- usb_background();
- #endif
-
- #if CIRCUITPY_DISPLAYIO
- displayio_background();
- #endif
- running_background_tasks = false;
-
- assert_heap_ok();
-}
+void port_background_task(void) {}
+void port_start_background_task(void) {}
+void port_finish_background_task(void) {}
diff --git a/ports/litex/background.h b/ports/litex/background.h
index 09551c7fb..c80fbbe5c 100644
--- a/ports/litex/background.h
+++ b/ports/litex/background.h
@@ -27,9 +27,4 @@
#ifndef MICROPY_INCLUDED_LITEX_BACKGROUND_H
#define MICROPY_INCLUDED_LITEX_BACKGROUND_H
-#include <stdbool.h>
-
-void background_tasks_reset(void);
-void run_background_tasks(void);
-
#endif // MICROPY_INCLUDED_LITEX_BACKGROUND_H
diff --git a/ports/mimxrt10xx/background.c b/ports/mimxrt10xx/background.c
index ff53ea44f..a8a613d41 100644
--- a/ports/mimxrt10xx/background.c
+++ b/ports/mimxrt10xx/background.c
@@ -24,58 +24,13 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-#include "background.h"
-//#include "audio_dma.h"
-#include "supervisor/filesystem.h"
-#include "supervisor/shared/tick.h"
-#include "supervisor/usb.h"
-
-#include "py/runtime.h"
-#include "shared-module/network/__init__.h"
-#include "supervisor/linker.h"
-#include "supervisor/shared/stack.h"
-
-#ifdef CIRCUITPY_DISPLAYIO
-#include "shared-module/displayio/__init__.h"
-#endif
-
-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 PLACE_IN_ITCM(run_background_tasks)(void) {
- // Don't call ourselves recursively.
- if (running_background_tasks) {
- return;
- }
- assert_heap_ok();
- running_background_tasks = true;
+#include "supervisor/port.h"
+void port_background_task(void) {
#if CIRCUITPY_AUDIOIO || CIRCUITPY_AUDIOBUSIO
audio_dma_background();
#endif
- #if CIRCUITPY_DISPLAYIO
- displayio_background();
- #endif
-
- #if CIRCUITPY_NETWORK
- network_module_background();
- #endif
- filesystem_background();
- usb_background();
- running_background_tasks = false;
- assert_heap_ok();
-
- last_finished_tick = supervisor_ticks_ms64();
-}
-
-bool background_tasks_ok(void) {
- return supervisor_ticks_ms64() - last_finished_tick < 1000;
}
+void port_start_background_task(void) {}
+void port_finish_background_task(void) {}
diff --git a/ports/mimxrt10xx/background.h b/ports/mimxrt10xx/background.h
index 52789d038..a3fe102ac 100644
--- a/ports/mimxrt10xx/background.h
+++ b/ports/mimxrt10xx/background.h
@@ -28,11 +28,4 @@
#ifndef MICROPY_INCLUDED_MIMXRT10XX_BACKGROUND_H
#define MICROPY_INCLUDED_MIMXRT10XX_BACKGROUND_H
-#include <stdbool.h>
-
-void background_tasks_reset(void);
-void run_background_tasks(void);
-void run_background_vm_tasks(void);
-bool background_tasks_ok(void);
-
#endif // MICROPY_INCLUDED_MIMXRT10XX_BACKGROUND_H
diff --git a/ports/mimxrt10xx/common-hal/pulseio/PulseIn.c b/ports/mimxrt10xx/common-hal/pulseio/PulseIn.c
index d8bf2017e..ec0290861 100644
--- a/ports/mimxrt10xx/common-hal/pulseio/PulseIn.c
+++ b/ports/mimxrt10xx/common-hal/pulseio/PulseIn.c
@@ -64,7 +64,7 @@
// // 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) {
+// if (!supervisor_background_tasks_ok() || self->errored_too_fast) {
// self->errored_too_fast = true;
// common_hal_pulseio_pulsein_pause(self);
// return;
diff --git a/ports/nrf/background.c b/ports/nrf/background.c
index bc7c0d7d3..10543ddb2 100644
--- a/ports/nrf/background.c
+++ b/ports/nrf/background.c
@@ -46,35 +46,14 @@
#include "common-hal/_bleio/bonding.h"
#endif
-static bool running_background_tasks = false;
+void port_start_background_task(void) {}
+void port_finish_background_task(void) {}
-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();
+void port_background_task(void) {
#if CIRCUITPY_AUDIOPWMIO
audiopwmout_background();
#endif
#if CIRCUITPY_AUDIOBUSIO
i2s_background();
#endif
-
-#if CIRCUITPY_BLEIO
- supervisor_bluetooth_background();
- bonding_background();
-#endif
-
- #if CIRCUITPY_DISPLAYIO
- displayio_background();
- #endif
- running_background_tasks = false;
-
- assert_heap_ok();
}
diff --git a/ports/nrf/background.h b/ports/nrf/background.h
index d53681c0f..64a768cf9 100644
--- a/ports/nrf/background.h
+++ b/ports/nrf/background.h
@@ -27,9 +27,4 @@
#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/stm/background.c b/ports/stm/background.c
index 8c1897043..d83a0ccec 100644
--- a/ports/stm/background.c
+++ b/ports/stm/background.c
@@ -33,28 +33,6 @@
#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();
-
- #if USB_AVAILABLE
- usb_background();
- #endif
-
- #if CIRCUITPY_DISPLAYIO
- displayio_background();
- #endif
- running_background_tasks = false;
-
- assert_heap_ok();
-}
+void port_background_task(void) {}
+void port_start_background_task(void) {}
+void port_finish_background_task(void) {}
diff --git a/ports/stm/background.h b/ports/stm/background.h
index 6225429f8..e57aa40dd 100644
--- a/ports/stm/background.h
+++ b/ports/stm/background.h
@@ -27,9 +27,4 @@
#ifndef MICROPY_INCLUDED_STM32_BACKGROUND_H
#define MICROPY_INCLUDED_STM32_BACKGROUND_H
-#include <stdbool.h>
-
-void background_tasks_reset(void);
-void run_background_tasks(void);
-
#endif // MICROPY_INCLUDED_STM32_BACKGROUND_H