summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoriabdalkader <i.abdalkader@gmail.com>2021-08-22 17:26:13 +0200
committerDamien George <damien@micropython.org>2021-09-15 01:25:12 +1000
commit7aab0dc5d81506de2020b7305cf2ee51894d29eb (patch)
tree606e86f3f1978af631689d90c0366c6cd565d020
parent0d7366c9126f1b306d5cd4eaebe26c801f0e01d8 (diff)
extmod: Move modnetwork and modusocket from stm32 to extmod.
So they can be used by other ports.
-rw-r--r--extmod/modnetwork.c (renamed from ports/stm32/modnetwork.c)35
-rw-r--r--extmod/modnetwork.h (renamed from ports/stm32/modnetwork.h)0
-rw-r--r--extmod/modusocket.c (renamed from ports/stm32/modusocket.c)0
-rw-r--r--ports/stm32/Makefile7
-rw-r--r--ports/stm32/eth.c2
-rw-r--r--ports/stm32/main.c2
-rw-r--r--ports/stm32/modnwcc3k.c2
-rw-r--r--ports/stm32/modnwwiznet5k.c2
-rw-r--r--ports/stm32/mpnetworkport.c81
-rw-r--r--ports/stm32/network_lan.c2
-rw-r--r--ports/stm32/network_wiznet5k.c2
11 files changed, 91 insertions, 44 deletions
diff --git a/ports/stm32/modnetwork.c b/extmod/modnetwork.c
index 06c4eb05d..600f1346b 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
index 0b6d0c4a7..0b6d0c4a7 100644
--- a/ports/stm32/modnetwork.h
+++ b/extmod/modnetwork.h
diff --git a/ports/stm32/modusocket.c b/extmod/modusocket.c
index c59fc8522..c59fc8522 100644
--- a/ports/stm32/modusocket.c
+++ b/extmod/modusocket.c
diff --git a/ports/stm32/Makefile b/ports/stm32/Makefile
index a6804ee61..d0a4d69a6 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 f174b6af0..be418235e 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 ccc8fd1ae..e506cc571 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 07178b65c..5dae9d640 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 1e18d03ca..d3c2c516c 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 000000000..a5ee15bc6
--- /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 <stdio.h>
+#include <stdint.h>
+#include <string.h>
+
+#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 6dd9aadb6..f19916a1d 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 bd4c02cb0..b6f1498ef 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