rp2: Add framework for networking.

MICROPY_PY_NETWORK and MICROPY_PY_USOCKET need to be enabled by a board to
get networking.  No NICs have yet been defined.
This commit is contained in:
iabdalkader 2021-08-15 18:30:18 +02:00 committed by Damien George
parent c973cfd2f3
commit 38f8e852e0
5 changed files with 32 additions and 2 deletions

View File

@ -16,6 +16,7 @@ set(MICROPY_SOURCE_EXTMOD
${MICROPY_EXTMOD_DIR}/modbluetooth.c
${MICROPY_EXTMOD_DIR}/modbtree.c
${MICROPY_EXTMOD_DIR}/modframebuf.c
${MICROPY_EXTMOD_DIR}/modnetwork.c
${MICROPY_EXTMOD_DIR}/modonewire.c
${MICROPY_EXTMOD_DIR}/moduasyncio.c
${MICROPY_EXTMOD_DIR}/modubinascii.c
@ -27,6 +28,7 @@ set(MICROPY_SOURCE_EXTMOD
${MICROPY_EXTMOD_DIR}/modurandom.c
${MICROPY_EXTMOD_DIR}/modure.c
${MICROPY_EXTMOD_DIR}/moduselect.c
${MICROPY_EXTMOD_DIR}/modusocket.c
${MICROPY_EXTMOD_DIR}/modussl_axtls.c
${MICROPY_EXTMOD_DIR}/modussl_mbedtls.c
${MICROPY_EXTMOD_DIR}/modutimeq.c

View File

@ -35,7 +35,7 @@
#include "shared/netutils/netutils.h"
#include "modnetwork.h"
#if MICROPY_PY_USOCKET && !MICROPY_PY_LWIP
#if MICROPY_PY_NETWORK && MICROPY_PY_USOCKET && !MICROPY_PY_LWIP
/******************************************************************************/
// socket class
@ -517,4 +517,4 @@ const mp_obj_module_t mp_module_usocket = {
.globals = (mp_obj_dict_t *)&mp_module_usocket_globals,
};
#endif // MICROPY_PY_USOCKET && !MICROPY_PY_LWIP
#endif // MICROPY_PY_NETWORK && MICROPY_PY_USOCKET && !MICROPY_PY_LWIP

View File

@ -66,6 +66,7 @@ set(MICROPY_SOURCE_LIB
${MICROPY_DIR}/lib/littlefs/lfs2_util.c
${MICROPY_DIR}/lib/oofatfs/ff.c
${MICROPY_DIR}/lib/oofatfs/ffunicode.c
${MICROPY_DIR}/shared/netutils/netutils.c
${MICROPY_DIR}/shared/readline/readline.c
${MICROPY_DIR}/shared/runtime/gchelper_m0.s
${MICROPY_DIR}/shared/runtime/gchelper_native.c

View File

@ -33,6 +33,7 @@
#include "py/mphal.h"
#include "py/stackctrl.h"
#include "extmod/modbluetooth.h"
#include "extmod/modnetwork.h"
#include "shared/readline/readline.h"
#include "shared/runtime/gchelper.h"
#include "shared/runtime/pyexec.h"
@ -112,6 +113,9 @@ int main(int argc, char **argv) {
#if MICROPY_PY_BLUETOOTH
mp_bluetooth_hci_init();
#endif
#if MICROPY_PY_NETWORK
mod_network_init();
#endif
// Execute _boot.py to set up the filesystem.
pyexec_frozen_module("_boot.py");
@ -142,6 +146,9 @@ int main(int argc, char **argv) {
soft_reset_exit:
mp_printf(MP_PYTHON_PRINTER, "MPY: soft reboot\n");
#if MICROPY_PY_NETWORK
mod_network_deinit();
#endif
rp2_pio_deinit();
#if MICROPY_PY_BLUETOOTH
mp_bluetooth_deinit();

View File

@ -166,11 +166,26 @@
{ MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&mp_builtin_open_obj) },
extern const struct _mp_obj_module_t mp_module_machine;
extern const struct _mp_obj_module_t mp_module_network;
extern const struct _mp_obj_module_t mp_module_onewire;
extern const struct _mp_obj_module_t mp_module_rp2;
extern const struct _mp_obj_module_t mp_module_uos;
extern const struct _mp_obj_module_t mp_module_usocket;
extern const struct _mp_obj_module_t mp_module_utime;
#if MICROPY_PY_USOCKET
#define SOCKET_BUILTIN_MODULE { MP_ROM_QSTR(MP_QSTR_usocket), MP_ROM_PTR(&mp_module_usocket) },
#else
#define SOCKET_BUILTIN_MODULE
#endif
#if MICROPY_PY_NETWORK
#define NETWORK_BUILTIN_MODULE { MP_ROM_QSTR(MP_QSTR_network), MP_ROM_PTR(&mp_module_network) },
#define NETWORK_ROOT_POINTERS mp_obj_list_t mod_network_nic_list;
#else
#define NETWORK_BUILTIN_MODULE
#define NETWORK_ROOT_POINTERS
#endif
#if MICROPY_PY_BLUETOOTH
#define MICROPY_PORT_ROOT_POINTER_BLUETOOTH struct _machine_uart_obj_t *mp_bthci_uart;
#else
@ -191,11 +206,15 @@ struct _mp_bluetooth_nimble_malloc_t;
{ MP_OBJ_NEW_QSTR(MP_QSTR__rp2), (mp_obj_t)&mp_module_rp2 }, \
{ MP_ROM_QSTR(MP_QSTR_uos), MP_ROM_PTR(&mp_module_uos) }, \
{ MP_ROM_QSTR(MP_QSTR_utime), MP_ROM_PTR(&mp_module_utime) }, \
SOCKET_BUILTIN_MODULE \
NETWORK_BUILTIN_MODULE \
#ifndef MICROPY_BOARD_ROOT_POINTERS
#define MICROPY_BOARD_ROOT_POINTERS
#endif
#define MICROPY_PORT_NETWORK_INTERFACES \
#define MICROPY_PORT_ROOT_POINTERS \
const char *readline_hist[8]; \
void *machine_pin_irq_obj[30]; \
@ -203,6 +222,7 @@ struct _mp_bluetooth_nimble_malloc_t;
void *rp2_state_machine_irq_obj[8]; \
void *rp2_uart_rx_buffer[2]; \
void *rp2_uart_tx_buffer[2]; \
NETWORK_ROOT_POINTERS \
MICROPY_BOARD_ROOT_POINTERS \
MICROPY_PORT_ROOT_POINTER_BLUETOOTH \
MICROPY_PORT_ROOT_POINTER_BLUETOOTH_NIMBLE \