summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Halbert <halbert@halwitz.org>2020-12-07 11:06:33 -0500
committerDan Halbert <halbert@halwitz.org>2020-12-07 11:07:56 -0500
commit169b4875099869d5d2549e9b717516e4045428d0 (patch)
treeb74dfea353ca46ab68aae15ab5af041c59bdfeae
parenta7ec4a0489d4ff6ca1d9f0f750ba5f18994d32f8 (diff)
Include wifi.radio singleton in gc
-rwxr-xr-xmain.c8
-rw-r--r--ports/esp32s2/common-hal/wifi/Radio.c6
-rw-r--r--ports/esp32s2/common-hal/wifi/Radio.h2
-rw-r--r--ports/esp32s2/common-hal/wifi/__init__.c4
-rw-r--r--shared-bindings/wifi/__init__.h1
5 files changed, 21 insertions, 0 deletions
diff --git a/main.c b/main.c
index 95aeeeb81..48c89d8ad 100755
--- a/main.c
+++ b/main.c
@@ -95,6 +95,10 @@
#include "common-hal/canio/CAN.h"
#endif
+#if CIRCUITPY_WIFI
+#include "shared-bindings/wifi/__init__.h"
+#endif
+
#if MICROPY_ENABLE_PYSTACK
static size_t PLACE_IN_DTCM_BSS(_pystack[CIRCUITPY_PYSTACK_SIZE / sizeof(size_t)]);
#endif
@@ -560,6 +564,10 @@ void gc_collect(void) {
common_hal_bleio_gc_collect();
#endif
+ #if CIRCUITPY_WIFI
+ common_hal_wifi_gc_collect();
+ #endif
+
// This naively collects all object references from an approximate stack
// range.
gc_collect_root((void**)sp, ((uint32_t)port_stack_get_top() - sp) / sizeof(uint32_t));
diff --git a/ports/esp32s2/common-hal/wifi/Radio.c b/ports/esp32s2/common-hal/wifi/Radio.c
index bc987bc1c..49cb8ec30 100644
--- a/ports/esp32s2/common-hal/wifi/Radio.c
+++ b/ports/esp32s2/common-hal/wifi/Radio.c
@@ -31,6 +31,7 @@
#include "common-hal/wifi/__init__.h"
#include "lib/utils/interrupt_char.h"
+#include "py/gc.h"
#include "py/runtime.h"
#include "shared-bindings/ipaddress/IPv4Address.h"
#include "shared-bindings/wifi/ScannedNetworks.h"
@@ -262,3 +263,8 @@ mp_int_t common_hal_wifi_radio_ping(wifi_radio_obj_t *self, mp_obj_t ip_address,
return elapsed_time;
}
+
+void common_hal_wifi_radio_gc_collect(wifi_radio_obj_t *self) {
+ // Only bother to scan the actual object references.
+ gc_collect_ptr(self->current_scan);
+}
diff --git a/ports/esp32s2/common-hal/wifi/Radio.h b/ports/esp32s2/common-hal/wifi/Radio.h
index c7f484eaf..1dac47016 100644
--- a/ports/esp32s2/common-hal/wifi/Radio.h
+++ b/ports/esp32s2/common-hal/wifi/Radio.h
@@ -59,4 +59,6 @@ typedef struct {
uint8_t last_disconnect_reason;
} wifi_radio_obj_t;
+extern void common_hal_wifi_radio_gc_collect(wifi_radio_obj_t *self);
+
#endif // MICROPY_INCLUDED_ESP32S2_COMMON_HAL_WIFI_RADIO_H
diff --git a/ports/esp32s2/common-hal/wifi/__init__.c b/ports/esp32s2/common-hal/wifi/__init__.c
index e06038c22..5945f222e 100644
--- a/ports/esp32s2/common-hal/wifi/__init__.c
+++ b/ports/esp32s2/common-hal/wifi/__init__.c
@@ -160,3 +160,7 @@ void ipaddress_ipaddress_to_esp_idf(mp_obj_t ip_address, ip_addr_t* esp_ip_addre
IP_ADDR4(esp_ip_address, bytes[0], bytes[1], bytes[2], bytes[3]);
}
+
+void common_hal_wifi_gc_collect(void) {
+ common_hal_wifi_radio_gc_collect(&common_hal_wifi_radio_obj);
+}
diff --git a/shared-bindings/wifi/__init__.h b/shared-bindings/wifi/__init__.h
index c06ee16be..124c0bc49 100644
--- a/shared-bindings/wifi/__init__.h
+++ b/shared-bindings/wifi/__init__.h
@@ -34,5 +34,6 @@
extern wifi_radio_obj_t common_hal_wifi_radio_obj;
void common_hal_wifi_init(void);
+void common_hal_wifi_gc_collect(void);
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_WIFI___INIT___H