stmhal: Put mod_network_nic_list in global root-pointer state.
It needs to be scanned by GC. Thanks to Daniel Campora.
This commit is contained in:
parent
77089bebd4
commit
8b77e3dd2f
@ -32,6 +32,7 @@
|
||||
#include "py/misc.h"
|
||||
#include "py/nlr.h"
|
||||
#include "py/obj.h"
|
||||
#include "py/objlist.h" // in case port needs mp_obj_list_t in root pointers
|
||||
#include "py/objexcept.h"
|
||||
|
||||
// This file contains structures defining the state of the Micro Python
|
||||
|
@ -38,27 +38,25 @@
|
||||
///
|
||||
/// This module provides network drivers and routing configuration.
|
||||
|
||||
mp_obj_list_t mod_network_nic_list;
|
||||
|
||||
void mod_network_init(void) {
|
||||
mp_obj_list_init(&mod_network_nic_list, 0);
|
||||
mp_obj_list_init(&MP_STATE_PORT(mod_network_nic_list), 0);
|
||||
}
|
||||
|
||||
void mod_network_register_nic(mp_obj_t nic) {
|
||||
for (mp_uint_t i = 0; i < mod_network_nic_list.len; i++) {
|
||||
if (mod_network_nic_list.items[i] == nic) {
|
||||
for (mp_uint_t i = 0; i < MP_STATE_PORT(mod_network_nic_list).len; i++) {
|
||||
if (MP_STATE_PORT(mod_network_nic_list).items[i] == nic) {
|
||||
// nic already registered
|
||||
return;
|
||||
}
|
||||
}
|
||||
// nic not registered so add to list
|
||||
mp_obj_list_append(&mod_network_nic_list, nic);
|
||||
mp_obj_list_append(&MP_STATE_PORT(mod_network_nic_list), nic);
|
||||
}
|
||||
|
||||
mp_obj_t mod_network_find_nic(const uint8_t *ip) {
|
||||
// find a NIC that is suited to given IP address
|
||||
for (mp_uint_t i = 0; i < mod_network_nic_list.len; i++) {
|
||||
mp_obj_t nic = mod_network_nic_list.items[i];
|
||||
for (mp_uint_t i = 0; i < MP_STATE_PORT(mod_network_nic_list).len; i++) {
|
||||
mp_obj_t nic = MP_STATE_PORT(mod_network_nic_list).items[i];
|
||||
// TODO check IP suitability here
|
||||
//mod_network_nic_type_t *nic_type = (mod_network_nic_type_t*)mp_obj_get_type(nic);
|
||||
return nic;
|
||||
@ -68,7 +66,7 @@ mp_obj_t mod_network_find_nic(const uint8_t *ip) {
|
||||
}
|
||||
|
||||
STATIC mp_obj_t network_route(void) {
|
||||
return &mod_network_nic_list;
|
||||
return &MP_STATE_PORT(mod_network_nic_list);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(network_route_obj, network_route);
|
||||
|
||||
|
@ -71,7 +71,6 @@ typedef struct _mod_network_socket_obj_t {
|
||||
};
|
||||
} mod_network_socket_obj_t;
|
||||
|
||||
extern struct _mp_obj_list_t mod_network_nic_list;
|
||||
extern const mod_network_nic_type_t mod_network_nic_type_wiznet5k;
|
||||
extern const mod_network_nic_type_t mod_network_nic_type_cc3k;
|
||||
|
||||
|
@ -385,8 +385,8 @@ STATIC mp_obj_t mod_usocket_getaddrinfo(mp_obj_t host_in, mp_obj_t port_in) {
|
||||
mp_int_t port = mp_obj_get_int(port_in);
|
||||
|
||||
// find a NIC that can do a name lookup
|
||||
for (mp_uint_t i = 0; i < mod_network_nic_list.len; i++) {
|
||||
mp_obj_t nic = mod_network_nic_list.items[i];
|
||||
for (mp_uint_t i = 0; i < MP_STATE_PORT(mod_network_nic_list).len; i++) {
|
||||
mp_obj_t nic = MP_STATE_PORT(mod_network_nic_list).items[i];
|
||||
mod_network_nic_type_t *nic_type = (mod_network_nic_type_t*)mp_obj_get_type(nic);
|
||||
if (nic_type->gethostbyname != NULL) {
|
||||
uint8_t out_ip[MOD_NETWORK_IPADDR_BUF_SIZE];
|
||||
|
@ -152,6 +152,9 @@ extern const struct _mp_obj_module_t mp_module_network;
|
||||
\
|
||||
/* pointers to all UART objects (if they have been created) */ \
|
||||
struct _pyb_uart_obj_t *pyb_uart_obj_all[6]; \
|
||||
\
|
||||
/* list of registered NICs */ \
|
||||
mp_obj_list_t mod_network_nic_list; \
|
||||
|
||||
// type definitions for the specific machine
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user