summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--py/mpstate.h1
-rw-r--r--stmhal/modnetwork.c16
-rw-r--r--stmhal/modnetwork.h1
-rw-r--r--stmhal/modusocket.c4
-rw-r--r--stmhal/mpconfigport.h3
5 files changed, 13 insertions, 12 deletions
diff --git a/py/mpstate.h b/py/mpstate.h
index e966bc80de..10a5db8194 100644
--- a/py/mpstate.h
+++ b/py/mpstate.h
@@ -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
diff --git a/stmhal/modnetwork.c b/stmhal/modnetwork.c
index f1ca4a9546..4163783e2c 100644
--- a/stmhal/modnetwork.c
+++ b/stmhal/modnetwork.c
@@ -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);
diff --git a/stmhal/modnetwork.h b/stmhal/modnetwork.h
index 8e23f877f2..9bde29f73d 100644
--- a/stmhal/modnetwork.h
+++ b/stmhal/modnetwork.h
@@ -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;
diff --git a/stmhal/modusocket.c b/stmhal/modusocket.c
index caa8843eb5..acffb38d1b 100644
--- a/stmhal/modusocket.c
+++ b/stmhal/modusocket.c
@@ -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];
diff --git a/stmhal/mpconfigport.h b/stmhal/mpconfigport.h
index c1e4b0f9de..ad3599ee83 100644
--- a/stmhal/mpconfigport.h
+++ b/stmhal/mpconfigport.h
@@ -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