Skip to content

Include wifi.radio singleton in gc #3799

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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));
Expand Down
6 changes: 6 additions & 0 deletions ports/esp32s2/common-hal/wifi/Radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
}
2 changes: 2 additions & 0 deletions ports/esp32s2/common-hal/wifi/Radio.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions ports/esp32s2/common-hal/wifi/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
1 change: 1 addition & 0 deletions shared-bindings/wifi/__init__.h
Original file line number Diff line number Diff line change
Expand Up @@ -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