summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2021-05-09 00:08:30 +1000
committerDamien George <damien@micropython.org>2021-05-09 00:08:30 +1000
commitd0de16266f92de180bd34f03aa43f1c489cd883a (patch)
tree794fa97275ff78912bc261c4853b78324e8e9cf7
parent7b923d6c72be29e2fe57740c9ea3a2135e7db6f7 (diff)
rp2/mpthreadport: Add mp_thread_deinit to reset core1 on soft reset.
Any code running on core1 should be stopped on soft-reset (the GC heap is reset so if code continues to run on core1 it will see corrupt memory). Signed-off-by: Damien George <damien@micropython.org>
-rw-r--r--ports/rp2/main.c3
-rw-r--r--ports/rp2/mpthreadport.c5
-rw-r--r--ports/rp2/mpthreadport.h1
3 files changed, 9 insertions, 0 deletions
diff --git a/ports/rp2/main.c b/ports/rp2/main.c
index 8fddeaa56..7709a478b 100644
--- a/ports/rp2/main.c
+++ b/ports/rp2/main.c
@@ -138,6 +138,9 @@ int main(int argc, char **argv) {
mp_printf(MP_PYTHON_PRINTER, "MPY: soft reboot\n");
rp2_pio_deinit();
machine_pin_deinit();
+ #if MICROPY_PY_THREAD
+ mp_thread_deinit();
+ #endif
gc_sweep_all();
mp_deinit();
}
diff --git a/ports/rp2/mpthreadport.c b/ports/rp2/mpthreadport.c
index fb4428772..8a36cfca7 100644
--- a/ports/rp2/mpthreadport.c
+++ b/ports/rp2/mpthreadport.c
@@ -46,6 +46,11 @@ void mp_thread_init(void) {
core1_entry = NULL;
}
+void mp_thread_deinit(void) {
+ multicore_reset_core1();
+ core1_entry = NULL;
+}
+
void mp_thread_gc_others(void) {
if (get_core_num() == 0) {
// GC running on core0, trace core1's stack, if it's running.
diff --git a/ports/rp2/mpthreadport.h b/ports/rp2/mpthreadport.h
index 5eb0bff39..868f8d141 100644
--- a/ports/rp2/mpthreadport.h
+++ b/ports/rp2/mpthreadport.h
@@ -34,6 +34,7 @@ typedef struct mutex mp_thread_mutex_t;
extern void *core_state[2];
void mp_thread_init(void);
+void mp_thread_deinit(void);
void mp_thread_gc_others(void);
static inline void mp_thread_set_state(struct _mp_state_thread_t *state) {