change initialization method + mod_network names
This commit is contained in:
parent
f9bda0ff93
commit
15b59bee1b
12
main.c
12
main.c
|
@ -54,6 +54,10 @@
|
|||
#include "supervisor/shared/stack.h"
|
||||
#include "supervisor/serial.h"
|
||||
|
||||
#ifdef MICROPY_PY_NETWORK
|
||||
#include "shared-bindings/network/__init__.h"
|
||||
#endif
|
||||
|
||||
void do_str(const char *src, mp_parse_input_kind_t input_kind) {
|
||||
mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR__lt_stdin_gt_, src, strlen(src), 0);
|
||||
if (lex == NULL) {
|
||||
|
@ -108,10 +112,16 @@ void start_mp(supervisor_allocation* heap) {
|
|||
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_FROZEN_FAKE_DIR_QSTR));
|
||||
|
||||
mp_obj_list_init(mp_sys_argv, 0);
|
||||
|
||||
#if MICROPY_PY_NETWORK
|
||||
network_module_init();
|
||||
#endif
|
||||
}
|
||||
|
||||
void stop_mp(void) {
|
||||
|
||||
#if MICROPY_PY_NETWORK
|
||||
network_module_deinit();
|
||||
#endif
|
||||
}
|
||||
|
||||
#define STRING_LIST(...) {__VA_ARGS__, ""}
|
||||
|
|
|
@ -96,7 +96,6 @@
|
|||
#define MICROPY_VFS (1)
|
||||
#define MICROPY_VFS_FAT (1)
|
||||
#define MICROPY_PY_MACHINE (1)
|
||||
#define MICROPY_MODULE_BUILTIN_INIT (1)
|
||||
#define MICROPY_MODULE_WEAK_LINKS (0)
|
||||
#define MICROPY_REPL_AUTO_INDENT (1)
|
||||
#define MICROPY_HW_ENABLE_DAC (1)
|
||||
|
|
|
@ -42,14 +42,14 @@
|
|||
///
|
||||
/// This module provides network drivers and routing configuration.
|
||||
|
||||
void mod_network_init(void) {
|
||||
void network_module_init(void) {
|
||||
mp_obj_list_init(&MP_STATE_PORT(mod_network_nic_list), 0);
|
||||
}
|
||||
|
||||
void mod_network_deinit(void) {
|
||||
void network_module_deinit(void) {
|
||||
}
|
||||
|
||||
void mod_network_register_nic(mp_obj_t nic) {
|
||||
void network_module_register_nic(mp_obj_t 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
|
||||
|
@ -60,7 +60,7 @@ void mod_network_register_nic(mp_obj_t nic) {
|
|||
mp_obj_list_append(MP_OBJ_FROM_PTR(&MP_STATE_PORT(mod_network_nic_list)), nic);
|
||||
}
|
||||
|
||||
mp_obj_t mod_network_find_nic(const uint8_t *ip) {
|
||||
mp_obj_t network_module_find_nic(const uint8_t *ip) {
|
||||
// find a NIC that is suited to given IP address
|
||||
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];
|
||||
|
@ -72,12 +72,6 @@ mp_obj_t mod_network_find_nic(const uint8_t *ip) {
|
|||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, translate("no available NIC")));
|
||||
}
|
||||
|
||||
STATIC mp_obj_t network_initialize(void) {
|
||||
mod_network_init();
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(network_initialize_obj, network_initialize);
|
||||
|
||||
STATIC mp_obj_t network_route(void) {
|
||||
return MP_OBJ_FROM_PTR(&MP_STATE_PORT(mod_network_nic_list));
|
||||
}
|
||||
|
@ -85,7 +79,6 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(network_route_obj, network_route);
|
|||
|
||||
STATIC const mp_rom_map_elem_t mp_module_network_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_network) },
|
||||
{ MP_ROM_QSTR(MP_QSTR___init__), MP_ROM_PTR(&network_initialize_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_route), MP_ROM_PTR(&network_route_obj) },
|
||||
};
|
||||
|
||||
|
|
|
@ -76,9 +76,9 @@ typedef struct _mod_network_socket_obj_t {
|
|||
extern const mod_network_nic_type_t mod_network_nic_type_wiznet5k;
|
||||
extern const mod_network_nic_type_t mod_network_nic_type_cc3k;
|
||||
|
||||
void mod_network_init(void);
|
||||
void mod_network_deinit(void);
|
||||
void mod_network_register_nic(mp_obj_t nic);
|
||||
mp_obj_t mod_network_find_nic(const uint8_t *ip);
|
||||
void network_module_init(void);
|
||||
void network_module_deinit(void);
|
||||
void network_module_register_nic(mp_obj_t nic);
|
||||
mp_obj_t network_module_find_nic(const uint8_t *ip);
|
||||
|
||||
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_NETWORK___INIT___H
|
||||
|
|
|
@ -76,7 +76,7 @@ STATIC mp_obj_t socket_make_new(const mp_obj_type_t *type, size_t n_args, size_t
|
|||
STATIC void socket_select_nic(mod_network_socket_obj_t *self, const byte *ip) {
|
||||
if (self->nic == MP_OBJ_NULL) {
|
||||
// select NIC based on IP
|
||||
self->nic = mod_network_find_nic(ip);
|
||||
self->nic = network_module_find_nic(ip);
|
||||
self->nic_type = (mod_network_nic_type_t*)mp_obj_get_type(self->nic);
|
||||
|
||||
// call the NIC to open the socket
|
||||
|
|
|
@ -406,7 +406,7 @@ STATIC mp_obj_t wiznet5k_make_new(const mp_obj_type_t *type, size_t n_args, size
|
|||
mp_hal_delay_ms(250);
|
||||
|
||||
// register with network module
|
||||
mod_network_register_nic(&wiznet5k_obj);
|
||||
network_module_register_nic(&wiznet5k_obj);
|
||||
|
||||
// return wiznet5k object
|
||||
return &wiznet5k_obj;
|
||||
|
|
Loading…
Reference in New Issue