diff --git a/ports/stm32/modnetwork.c b/extmod/modnetwork.c similarity index 88% rename from ports/stm32/modnetwork.c rename to extmod/modnetwork.c index 06c4eb05db..600f1346bc 100644 --- a/ports/stm32/modnetwork.c +++ b/extmod/modnetwork.c @@ -39,7 +39,6 @@ #if MICROPY_PY_NETWORK #if MICROPY_PY_LWIP - #include "lwip/netif.h" #include "lwip/timeouts.h" #include "lwip/dns.h" @@ -47,40 +46,6 @@ #include "lwip/apps/mdns.h" #include "extmod/network_cyw43.h" #include "drivers/cyw43/cyw43.h" - -// Poll lwIP every 128ms -#define LWIP_TICK(tick) (((tick) & ~(SYSTICK_DISPATCH_NUM_SLOTS - 1) & 0x7f) == 0) - -u32_t sys_now(void) { - return mp_hal_ticks_ms(); -} - -STATIC void pyb_lwip_poll(void) { - #if MICROPY_PY_WIZNET5K - // Poll the NIC for incoming data - wiznet5k_poll(); - #endif - - // Run the lwIP internal updates - sys_check_timeouts(); -} - -void mod_network_lwip_poll_wrapper(uint32_t ticks_ms) { - if (LWIP_TICK(ticks_ms)) { - pendsv_schedule_dispatch(PENDSV_DISPATCH_LWIP, pyb_lwip_poll); - } - - #if MICROPY_PY_NETWORK_CYW43 - if (cyw43_poll) { - if (cyw43_sleep != 0) { - if (--cyw43_sleep == 0) { - pendsv_schedule_dispatch(PENDSV_DISPATCH_CYW43, cyw43_poll); - } - } - } - #endif -} - #endif /// \module network - network configuration diff --git a/ports/stm32/modnetwork.h b/extmod/modnetwork.h similarity index 100% rename from ports/stm32/modnetwork.h rename to extmod/modnetwork.h diff --git a/ports/stm32/modusocket.c b/extmod/modusocket.c similarity index 100% rename from ports/stm32/modusocket.c rename to extmod/modusocket.c diff --git a/ports/stm32/Makefile b/ports/stm32/Makefile index a6804ee616..d0a4d69a6f 100644 --- a/ports/stm32/Makefile +++ b/ports/stm32/Makefile @@ -267,7 +267,9 @@ endif EXTMOD_SRC_C += $(addprefix extmod/,\ modonewire.c \ - ) + modnetwork.c \ + modusocket.c \ + ) DRIVERS_SRC_C += $(addprefix drivers/,\ bus/softspi.c \ @@ -286,6 +288,7 @@ SRC_C += \ usbd_hid_interface.c \ usbd_msc_interface.c \ mphalport.c \ + mpnetworkport.c \ mpthreadport.c \ irq.c \ pendsv.c \ @@ -329,9 +332,7 @@ SRC_C += \ modstm.c \ moduos.c \ modutime.c \ - modusocket.c \ network_lan.c \ - modnetwork.c \ extint.c \ usrsw.c \ rng.c \ diff --git a/ports/stm32/eth.c b/ports/stm32/eth.c index f174b6af0d..be418235e1 100644 --- a/ports/stm32/eth.c +++ b/ports/stm32/eth.c @@ -29,7 +29,7 @@ #include "py/mperrno.h" #include "shared/netutils/netutils.h" #include "pin_static_af.h" -#include "modnetwork.h" +#include "extmod/modnetwork.h" #include "mpu.h" #include "eth.h" diff --git a/ports/stm32/main.c b/ports/stm32/main.c index ccc8fd1ae7..e506cc5713 100644 --- a/ports/stm32/main.c +++ b/ports/stm32/main.c @@ -39,6 +39,7 @@ #include "lib/littlefs/lfs1_util.h" #include "lib/littlefs/lfs2.h" #include "lib/littlefs/lfs2_util.h" +#include "extmod/modnetwork.h" #include "extmod/vfs.h" #include "extmod/vfs_fat.h" #include "extmod/vfs_lfs.h" @@ -83,7 +84,6 @@ #include "servo.h" #include "dac.h" #include "can.h" -#include "modnetwork.h" #if MICROPY_PY_THREAD STATIC pyb_thread_t pyb_thread_main; diff --git a/ports/stm32/modnwcc3k.c b/ports/stm32/modnwcc3k.c index 07178b65c7..5dae9d6407 100644 --- a/ports/stm32/modnwcc3k.c +++ b/ports/stm32/modnwcc3k.c @@ -37,7 +37,7 @@ #include "py/mperrno.h" #include "py/mphal.h" #include "shared/netutils/netutils.h" -#include "modnetwork.h" +#include "extmod/modnetwork.h" #include "pin.h" #include "spi.h" diff --git a/ports/stm32/modnwwiznet5k.c b/ports/stm32/modnwwiznet5k.c index 1e18d03ca1..d3c2c516c3 100644 --- a/ports/stm32/modnwwiznet5k.c +++ b/ports/stm32/modnwwiznet5k.c @@ -34,7 +34,7 @@ #include "py/mperrno.h" #include "py/mphal.h" #include "shared/netutils/netutils.h" -#include "modnetwork.h" +#include "extmod/modnetwork.h" #include "pin.h" #include "spi.h" diff --git a/ports/stm32/mpnetworkport.c b/ports/stm32/mpnetworkport.c new file mode 100644 index 0000000000..a5ee15bc67 --- /dev/null +++ b/ports/stm32/mpnetworkport.c @@ -0,0 +1,81 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2014 Damien P. George + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include +#include +#include + +#include "py/objlist.h" +#include "py/runtime.h" +#include "py/mphal.h" +#include "shared/netutils/netutils.h" +#include "systick.h" +#include "pendsv.h" +#include "extmod/modnetwork.h" + +#if MICROPY_PY_LWIP +#include "lwip/netif.h" +#include "lwip/timeouts.h" +#include "lwip/dns.h" +#include "lwip/dhcp.h" +#include "lwip/apps/mdns.h" +#include "extmod/network_cyw43.h" +#include "drivers/cyw43/cyw43.h" + +// Poll lwIP every 128ms +#define LWIP_TICK(tick) (((tick) & ~(SYSTICK_DISPATCH_NUM_SLOTS - 1) & 0x7f) == 0) + +u32_t sys_now(void) { + return mp_hal_ticks_ms(); +} + +STATIC void pyb_lwip_poll(void) { + #if MICROPY_PY_WIZNET5K + // Poll the NIC for incoming data + wiznet5k_poll(); + #endif + + // Run the lwIP internal updates + sys_check_timeouts(); +} + +void mod_network_lwip_poll_wrapper(uint32_t ticks_ms) { + if (LWIP_TICK(ticks_ms)) { + pendsv_schedule_dispatch(PENDSV_DISPATCH_LWIP, pyb_lwip_poll); + } + + #if MICROPY_PY_NETWORK_CYW43 + if (cyw43_poll) { + if (cyw43_sleep != 0) { + if (--cyw43_sleep == 0) { + pendsv_schedule_dispatch(PENDSV_DISPATCH_CYW43, cyw43_poll); + } + } + } + #endif +} + +#endif // MICROPY_PY_LWIP diff --git a/ports/stm32/network_lan.c b/ports/stm32/network_lan.c index 6dd9aadb65..f19916a1df 100644 --- a/ports/stm32/network_lan.c +++ b/ports/stm32/network_lan.c @@ -26,7 +26,7 @@ #include "py/runtime.h" #include "py/mphal.h" -#include "modnetwork.h" +#include "extmod/modnetwork.h" #include "eth.h" #if defined(MICROPY_HW_ETH_MDC) diff --git a/ports/stm32/network_wiznet5k.c b/ports/stm32/network_wiznet5k.c index bd4c02cb05..b6f1498eff 100644 --- a/ports/stm32/network_wiznet5k.c +++ b/ports/stm32/network_wiznet5k.c @@ -29,8 +29,8 @@ #include "py/runtime.h" #include "py/mphal.h" +#include "extmod/modnetwork.h" #include "spi.h" -#include "modnetwork.h" #if MICROPY_PY_WIZNET5K && MICROPY_PY_LWIP