Skip to content

Commit 15b59be

Browse files
committed
change initialization method + mod_network names
1 parent f9bda0f commit 15b59be

File tree

6 files changed

+21
-19
lines changed

6 files changed

+21
-19
lines changed

main.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@
5454
#include "supervisor/shared/stack.h"
5555
#include "supervisor/serial.h"
5656

57+
#ifdef MICROPY_PY_NETWORK
58+
#include "shared-bindings/network/__init__.h"
59+
#endif
60+
5761
void do_str(const char *src, mp_parse_input_kind_t input_kind) {
5862
mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR__lt_stdin_gt_, src, strlen(src), 0);
5963
if (lex == NULL) {
@@ -108,10 +112,16 @@ void start_mp(supervisor_allocation* heap) {
108112
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_FROZEN_FAKE_DIR_QSTR));
109113

110114
mp_obj_list_init(mp_sys_argv, 0);
115+
116+
#if MICROPY_PY_NETWORK
117+
network_module_init();
118+
#endif
111119
}
112120

113121
void stop_mp(void) {
114-
122+
#if MICROPY_PY_NETWORK
123+
network_module_deinit();
124+
#endif
115125
}
116126

117127
#define STRING_LIST(...) {__VA_ARGS__, ""}

ports/atmel-samd/mpconfigport.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@
9696
#define MICROPY_VFS (1)
9797
#define MICROPY_VFS_FAT (1)
9898
#define MICROPY_PY_MACHINE (1)
99-
#define MICROPY_MODULE_BUILTIN_INIT (1)
10099
#define MICROPY_MODULE_WEAK_LINKS (0)
101100
#define MICROPY_REPL_AUTO_INDENT (1)
102101
#define MICROPY_HW_ENABLE_DAC (1)

shared-bindings/network/__init__.c

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@
4242
///
4343
/// This module provides network drivers and routing configuration.
4444

45-
void mod_network_init(void) {
45+
void network_module_init(void) {
4646
mp_obj_list_init(&MP_STATE_PORT(mod_network_nic_list), 0);
4747
}
4848

49-
void mod_network_deinit(void) {
49+
void network_module_deinit(void) {
5050
}
5151

52-
void mod_network_register_nic(mp_obj_t nic) {
52+
void network_module_register_nic(mp_obj_t nic) {
5353
for (mp_uint_t i = 0; i < MP_STATE_PORT(mod_network_nic_list).len; i++) {
5454
if (MP_STATE_PORT(mod_network_nic_list).items[i] == nic) {
5555
// nic already registered
@@ -60,7 +60,7 @@ void mod_network_register_nic(mp_obj_t nic) {
6060
mp_obj_list_append(MP_OBJ_FROM_PTR(&MP_STATE_PORT(mod_network_nic_list)), nic);
6161
}
6262

63-
mp_obj_t mod_network_find_nic(const uint8_t *ip) {
63+
mp_obj_t network_module_find_nic(const uint8_t *ip) {
6464
// find a NIC that is suited to given IP address
6565
for (mp_uint_t i = 0; i < MP_STATE_PORT(mod_network_nic_list).len; i++) {
6666
mp_obj_t nic = MP_STATE_PORT(mod_network_nic_list).items[i];
@@ -72,20 +72,13 @@ mp_obj_t mod_network_find_nic(const uint8_t *ip) {
7272
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, translate("no available NIC")));
7373
}
7474

75-
STATIC mp_obj_t network_initialize(void) {
76-
mod_network_init();
77-
return mp_const_none;
78-
}
79-
STATIC MP_DEFINE_CONST_FUN_OBJ_0(network_initialize_obj, network_initialize);
80-
8175
STATIC mp_obj_t network_route(void) {
8276
return MP_OBJ_FROM_PTR(&MP_STATE_PORT(mod_network_nic_list));
8377
}
8478
STATIC MP_DEFINE_CONST_FUN_OBJ_0(network_route_obj, network_route);
8579

8680
STATIC const mp_rom_map_elem_t mp_module_network_globals_table[] = {
8781
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_network) },
88-
{ MP_ROM_QSTR(MP_QSTR___init__), MP_ROM_PTR(&network_initialize_obj) },
8982
{ MP_ROM_QSTR(MP_QSTR_route), MP_ROM_PTR(&network_route_obj) },
9083
};
9184

shared-bindings/network/__init__.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ typedef struct _mod_network_socket_obj_t {
7676
extern const mod_network_nic_type_t mod_network_nic_type_wiznet5k;
7777
extern const mod_network_nic_type_t mod_network_nic_type_cc3k;
7878

79-
void mod_network_init(void);
80-
void mod_network_deinit(void);
81-
void mod_network_register_nic(mp_obj_t nic);
82-
mp_obj_t mod_network_find_nic(const uint8_t *ip);
79+
void network_module_init(void);
80+
void network_module_deinit(void);
81+
void network_module_register_nic(mp_obj_t nic);
82+
mp_obj_t network_module_find_nic(const uint8_t *ip);
8383

8484
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_NETWORK___INIT___H

shared-bindings/socket/__init__.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ STATIC mp_obj_t socket_make_new(const mp_obj_type_t *type, size_t n_args, size_t
7676
STATIC void socket_select_nic(mod_network_socket_obj_t *self, const byte *ip) {
7777
if (self->nic == MP_OBJ_NULL) {
7878
// select NIC based on IP
79-
self->nic = mod_network_find_nic(ip);
79+
self->nic = network_module_find_nic(ip);
8080
self->nic_type = (mod_network_nic_type_t*)mp_obj_get_type(self->nic);
8181

8282
// call the NIC to open the socket

shared-bindings/wiznet/__init__.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ STATIC mp_obj_t wiznet5k_make_new(const mp_obj_type_t *type, size_t n_args, size
406406
mp_hal_delay_ms(250);
407407

408408
// register with network module
409-
mod_network_register_nic(&wiznet5k_obj);
409+
network_module_register_nic(&wiznet5k_obj);
410410

411411
// return wiznet5k object
412412
return &wiznet5k_obj;

0 commit comments

Comments
 (0)