extmod: Move modnetwork and modusocket from stm32 to extmod.

So they can be used by other ports.
This commit is contained in:
iabdalkader 2021-08-22 17:26:13 +02:00 committed by Damien George
parent 0d7366c912
commit 7aab0dc5d8
11 changed files with 91 additions and 44 deletions

View File

@ -39,7 +39,6 @@
#if MICROPY_PY_NETWORK #if MICROPY_PY_NETWORK
#if MICROPY_PY_LWIP #if MICROPY_PY_LWIP
#include "lwip/netif.h" #include "lwip/netif.h"
#include "lwip/timeouts.h" #include "lwip/timeouts.h"
#include "lwip/dns.h" #include "lwip/dns.h"
@ -47,40 +46,6 @@
#include "lwip/apps/mdns.h" #include "lwip/apps/mdns.h"
#include "extmod/network_cyw43.h" #include "extmod/network_cyw43.h"
#include "drivers/cyw43/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 #endif
/// \module network - network configuration /// \module network - network configuration

View File

@ -267,7 +267,9 @@ endif
EXTMOD_SRC_C += $(addprefix extmod/,\ EXTMOD_SRC_C += $(addprefix extmod/,\
modonewire.c \ modonewire.c \
) modnetwork.c \
modusocket.c \
)
DRIVERS_SRC_C += $(addprefix drivers/,\ DRIVERS_SRC_C += $(addprefix drivers/,\
bus/softspi.c \ bus/softspi.c \
@ -286,6 +288,7 @@ SRC_C += \
usbd_hid_interface.c \ usbd_hid_interface.c \
usbd_msc_interface.c \ usbd_msc_interface.c \
mphalport.c \ mphalport.c \
mpnetworkport.c \
mpthreadport.c \ mpthreadport.c \
irq.c \ irq.c \
pendsv.c \ pendsv.c \
@ -329,9 +332,7 @@ SRC_C += \
modstm.c \ modstm.c \
moduos.c \ moduos.c \
modutime.c \ modutime.c \
modusocket.c \
network_lan.c \ network_lan.c \
modnetwork.c \
extint.c \ extint.c \
usrsw.c \ usrsw.c \
rng.c \ rng.c \

View File

@ -29,7 +29,7 @@
#include "py/mperrno.h" #include "py/mperrno.h"
#include "shared/netutils/netutils.h" #include "shared/netutils/netutils.h"
#include "pin_static_af.h" #include "pin_static_af.h"
#include "modnetwork.h" #include "extmod/modnetwork.h"
#include "mpu.h" #include "mpu.h"
#include "eth.h" #include "eth.h"

View File

@ -39,6 +39,7 @@
#include "lib/littlefs/lfs1_util.h" #include "lib/littlefs/lfs1_util.h"
#include "lib/littlefs/lfs2.h" #include "lib/littlefs/lfs2.h"
#include "lib/littlefs/lfs2_util.h" #include "lib/littlefs/lfs2_util.h"
#include "extmod/modnetwork.h"
#include "extmod/vfs.h" #include "extmod/vfs.h"
#include "extmod/vfs_fat.h" #include "extmod/vfs_fat.h"
#include "extmod/vfs_lfs.h" #include "extmod/vfs_lfs.h"
@ -83,7 +84,6 @@
#include "servo.h" #include "servo.h"
#include "dac.h" #include "dac.h"
#include "can.h" #include "can.h"
#include "modnetwork.h"
#if MICROPY_PY_THREAD #if MICROPY_PY_THREAD
STATIC pyb_thread_t pyb_thread_main; STATIC pyb_thread_t pyb_thread_main;

View File

@ -37,7 +37,7 @@
#include "py/mperrno.h" #include "py/mperrno.h"
#include "py/mphal.h" #include "py/mphal.h"
#include "shared/netutils/netutils.h" #include "shared/netutils/netutils.h"
#include "modnetwork.h" #include "extmod/modnetwork.h"
#include "pin.h" #include "pin.h"
#include "spi.h" #include "spi.h"

View File

@ -34,7 +34,7 @@
#include "py/mperrno.h" #include "py/mperrno.h"
#include "py/mphal.h" #include "py/mphal.h"
#include "shared/netutils/netutils.h" #include "shared/netutils/netutils.h"
#include "modnetwork.h" #include "extmod/modnetwork.h"
#include "pin.h" #include "pin.h"
#include "spi.h" #include "spi.h"

View File

@ -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

View File

@ -26,7 +26,7 @@
#include "py/runtime.h" #include "py/runtime.h"
#include "py/mphal.h" #include "py/mphal.h"
#include "modnetwork.h" #include "extmod/modnetwork.h"
#include "eth.h" #include "eth.h"
#if defined(MICROPY_HW_ETH_MDC) #if defined(MICROPY_HW_ETH_MDC)

View File

@ -29,8 +29,8 @@
#include "py/runtime.h" #include "py/runtime.h"
#include "py/mphal.h" #include "py/mphal.h"
#include "extmod/modnetwork.h"
#include "spi.h" #include "spi.h"
#include "modnetwork.h"
#if MICROPY_PY_WIZNET5K && MICROPY_PY_LWIP #if MICROPY_PY_WIZNET5K && MICROPY_PY_LWIP