summaryrefslogtreecommitdiff
path: root/supervisor
diff options
context:
space:
mode:
Diffstat (limited to 'supervisor')
-rw-r--r--supervisor/port.h8
-rw-r--r--supervisor/shared/tick.c52
-rw-r--r--supervisor/shared/tick.h16
3 files changed, 64 insertions, 12 deletions
diff --git a/supervisor/port.h b/supervisor/port.h
index 8a12d34c8..ad5b3cf32 100644
--- a/supervisor/port.h
+++ b/supervisor/port.h
@@ -91,4 +91,12 @@ void port_interrupt_after_ticks(uint32_t ticks);
// Sleep the CPU until an interrupt is received.
void port_sleep_until_interrupt(void);
+// Execute port specific actions during background tasks.
+void port_background_task(void);
+
+// Take port specific actions at the beginning and end of background tasks.
+// This is used e.g., to set a monitoring pin for debug purposes. "Actual
+// work" should be done in port_background_task() instead.
+void port_start_background_task(void);
+void port_finish_background_task(void);
#endif // MICROPY_INCLUDED_SUPERVISOR_PORT_H
diff --git a/supervisor/shared/tick.c b/supervisor/shared/tick.c
index 46172d0f3..bc270030f 100644
--- a/supervisor/shared/tick.c
+++ b/supervisor/shared/tick.c
@@ -32,8 +32,16 @@
#include "supervisor/background_callback.h"
#include "supervisor/port.h"
#include "supervisor/shared/autoreload.h"
+#include "supervisor/shared/stack.h"
-static volatile uint64_t PLACE_IN_DTCM_BSS(background_ticks);
+#if CIRCUITPY_BLEIO
+#include "supervisor/shared/bluetooth.h"
+#include "common-hal/_bleio/bonding.h"
+#endif
+
+#if CIRCUITPY_DISPLAYIO
+#include "shared-module/displayio/__init__.h"
+#endif
#if CIRCUITPY_GAMEPAD
#include "shared-module/gamepad/__init__.h"
@@ -43,6 +51,10 @@ static volatile uint64_t PLACE_IN_DTCM_BSS(background_ticks);
#include "shared-module/gamepadshift/__init__.h"
#endif
+#if CIRCUITPY_NETWORK
+#include "shared-module/network/__init__.h"
+#endif
+
#include "shared-bindings/microcontroller/__init__.h"
#if CIRCUITPY_WATCHDOG
@@ -52,12 +64,42 @@ static volatile uint64_t PLACE_IN_DTCM_BSS(background_ticks);
#define WATCHDOG_EXCEPTION_CHECK() 0
#endif
+static volatile uint64_t PLACE_IN_DTCM_BSS(background_ticks);
+
static background_callback_t callback;
-extern void run_background_tasks(void);
+volatile uint64_t last_finished_tick = 0;
+
+void supervisor_background_tasks(void *unused) {
+ port_start_background_task();
+
+ assert_heap_ok();
+
+ #if CIRCUITPY_DISPLAYIO
+ displayio_background();
+ #endif
+
+ #if CIRCUITPY_NETWORK
+ network_module_background();
+ #endif
+ filesystem_background();
+
+ #if CIRCUITPY_BLEIO
+ supervisor_bluetooth_background();
+ bonding_background();
+ #endif
+
+ port_background_task();
+
+ assert_heap_ok();
+
+ last_finished_tick = port_get_raw_ticks(NULL);
+
+ port_finish_background_task();
+}
-void background_task_tick(void *unused) {
- run_background_tasks();
+bool supervisor_background_tasks_ok(void) {
+ return port_get_raw_ticks(NULL) - last_finished_tick < 1024;
}
void supervisor_tick(void) {
@@ -77,7 +119,7 @@ void supervisor_tick(void) {
#endif
}
#endif
- background_callback_add(&callback, background_task_tick, NULL);
+ background_callback_add(&callback, supervisor_background_tasks, NULL);
}
uint64_t supervisor_ticks_ms64() {
diff --git a/supervisor/shared/tick.h b/supervisor/shared/tick.h
index e7e808058..3a01bd622 100644
--- a/supervisor/shared/tick.h
+++ b/supervisor/shared/tick.h
@@ -28,6 +28,7 @@
#define __INCLUDED_SUPERVISOR_TICK_H
#include <stdint.h>
+#include <stdbool.h>
/** @brief To be called once every ms
*
@@ -36,13 +37,6 @@
* interrupt context.
*/
extern void supervisor_tick(void);
-/** @brief Cause background tasks to be called soon
- *
- * Normally, background tasks are only run once per tick. For other cases where
- * an event noticed from an interrupt context needs to be completed by a background
- * task activity, the interrupt can call supervisor_fake_tick.
- */
-extern void supervisor_fake_tick(void);
/** @brief Get the lower 32 bits of the time in milliseconds
*
* This can be more efficient than supervisor_ticks_ms64, for sites where a wraparound
@@ -67,4 +61,12 @@ extern void supervisor_run_background_if_tick(void);
extern void supervisor_enable_tick(void);
extern void supervisor_disable_tick(void);
+/**
+ * @brief Return true if tick-based background tasks ran within the last 1s
+ *
+ * Note that when ticks are not enabled, this function can return false; this is
+ * intended.
+ */
+extern bool supervisor_background_tasks_ok(void);
+
#endif