增加所有文件

This commit is contained in:
2025-11-07 20:19:23 +08:00
parent b7376523b6
commit 846bd3bbda
8445 changed files with 3006231 additions and 5934 deletions

View File

@@ -0,0 +1,67 @@
/*
* Copyright (c) 2017 Simon Goldschmidt
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Simon Goldschmdit <goldsimon@gmx.de>
*
*/
#ifndef LWIP_ARCH_CC_H
#define LWIP_ARCH_CC_H
#if __GNUC__
#define LWIP_TIMEVAL_PRIVATE 0
#if __SES_ARM
#include <sys/time.h>
#else
#include <sys/_timeval.h>
#endif
#elif __ICCARM__
#define LWIP_TIMEVAL_PRIVATE 1
#endif
#define U16_F "u"
#define S16_F "d"
#define X16_F "x"
#define U32_F "u"
#define S32_F "d"
#define X32_F "x"
#define SZT_F "zu"
#define printf printf_
extern int printf_(const char* format, ...);
#define LWIP_NO_UNISTD_H 1
#define LWIP_CHKSUM_ALGORITHM 2
#define LWIP_PLATFORM_DIAG(x) do {printf x;} while (0)
#define LWIP_PLATFORM_ASSERT(x) do {printf(x); while(1);} while (0)
//typedef int ssize_t;
#endif /* LWIP_ARCH_CC_H */

View File

@@ -0,0 +1,46 @@
/*
* Copyright (c) 2017 Simon Goldschmidt
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Simon Goldschmdit <goldsimon@gmx.de>
*
*/
#ifndef LWIP_ARCH_SYS_ARCH_H
#define LWIP_ARCH_SYS_ARCH_H
#define MBOX_MAGIC 'mbox'
#define SEM_MAGIC 'sem'
typedef void *sys_thread_t;
typedef void *sys_mutex_t;
typedef void *sys_sem_t;
typedef void *sys_mbox_t;
#endif /* LWIP_ARCH_SYS_ARCH_H */

View File

@@ -0,0 +1,122 @@
/**
* @file
*
* lwIP Options Configuration
*/
/*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef LWIP_LWIPOPTS_H
#define LWIP_LWIPOPTS_H
#define NO_SYS 1
#define LWIP_NETCONN 0
#define LWIP_SOCKET 0
/*
* Include user defined options first. Anything not defined in these files
* will be set to standard values. Override anything you don't like!
*/
// use libc malloc
#define MEM_LIBC_MALLOC 0
#define MEMP_USE_CUSTOM_POOLS 1
#define MEM_USE_POOLS 1
// Create static memory pools
#define MEMP_MEM_MALLOC 0
/* Memory block size alignes to 4 bytes, because ARM may access memory block
* by using ldrd/strd instruction which needs 4 bytes alignment
*/
#define MEM_ALIGNMENT 4
// these don't actually affect anything
// unless MEMP_MEM_MALLOC is 0
#define MEM_SIZE (16 * 1024)
#define MEMP_NUM_UDP_PCB 128
#define MEMP_NUM_TCP_PCB 128
#define MEMP_NUM_TCP_PCB_LISTEN 128
#define MEMP_NUM_NETBUF 32
#define MEMP_NUM_NETCONN 32
#define MEMP_NUM_NETDB 32
#define LWIP_COMPAT_SOCKETS 1
#define LWIP_SO_RCVTIMEO 1
#define LWIP_SO_RCVBUF 1
#define LWIP_DHCP 0
#define LWIP_AUTOIP 0
#define LWIP_DHCP_AUTOIP_COOP 0
#define LWIP_DNS 0
#define LWIP_NETIF_HOSTNAME 1
#define LWIP_NETIF_STATUS_CALLBACK 1
#define LWIP_NETIF_HWADDRHINT 1
#define LWIP_NETIF_LOOPBACK 1
#define LWIP_HAVE_LOOPIF 1
#define TCPIP_THREAD_STACKSIZE 4096
#define TCPIP_THREAD_PRIO osPriorityRealtime
#define TCPIP_MBOX_SIZE 16
#define DEFAULT_THREAD_PRIO (osPriorityNormal - 1)
#define DEFAULT_THREAD_STACKSIZE 4096
#define DEFAULT_RAW_RECVMBOX_SIZE 16
#define DEFAULT_UDP_RECVMBOX_SIZE 16
#define DEFAULT_TCP_RECVMBOX_SIZE 16
#define DEFAULT_ACCEPTMBOX_SIZE 16
#define LWIP_STATS_DISPLAY 1
#define LWIP_ERRNO_STDINCLUDE
#define SYS_LIGHTWEIGHT_PROT 0
#define LWIP_DEBUG 1
#define LWIP_RAW 1
#define MEMP_NUM_SYS_TIMEOUT 17
//#define PBUF_DEBUG LWIP_DBG_ON
//#define TCP_OUTPUT_DEBUG LWIP_DBG_ON
//#define LWIP_DBG_MIN_LEVEL 0
/* TCP Maximum segment size. */
#define TCP_MSS 1460
#define TCP_SND_BUF (12 * TCP_MSS)
#define TCP_SND_QUEUELEN 80
#define MEMP_NUM_TCP_SEG TCP_SND_QUEUELEN
#endif /* LWIP_LWIPOPTS_H */

View File

@@ -0,0 +1,51 @@
#ifndef NET_DEV_H_
#define NET_DEV_H_
#include <lwip/opt.h>
#include <lwip/netif.h>
#include <lwip/pbuf.h>
#include <lwip/err.h>
struct net_driver_s;
/* Link layer type. This type is used with netdev_register in order to
* identify the type of the network driver.
*/
enum net_lltype_e {
NET_LL_ETHERNET = 0, /* Ethernet */
NET_LL_LOOPBACK, /* Local loopback */
NET_LL_SLIP, /* Serial Line Internet Protocol (SLIP) */
NET_LL_TUN, /* TUN Virtual Network Device */
NET_LL_BLUETOOTH, /* Bluetooth */
NET_LL_IEEE80211, /* IEEE 802.11 */
NET_LL_IEEE802154, /* IEEE 802.15.4 MAC */
NET_LL_PKTRADIO /* Non-standard packet radio */
};
struct net_driver_s {
struct netif d_netif;
u8_t d_lltype; /* See enum net_lltype_e */
/** IP address configuration in network byte order */
ip_addr_t d_ipaddr;
ip_addr_t d_netmask;
ip_addr_t d_gateway;
err_t (*d_init)(struct net_driver_s *dev);
err_t (*d_txavail)(struct net_driver_s *dev, struct pbuf *p);
u32_t (*d_getmac)(struct net_driver_s *dev, void *buf, u32_t max_len);
u32_t (*d_getmtu)(struct net_driver_s *dev);
void *d_private;
};
err_t netdev_register(struct net_driver_s *dev, enum net_lltype_e lltype);
static inline void netdev_input(struct net_driver_s *dev, struct pbuf *p) {
if (dev->d_netif.input(p, &dev->d_netif) != ERR_OK) {
pbuf_free(p);
}
}
#endif /* NET_DEV_H_ */

View File

@@ -0,0 +1,174 @@
/*
* Copyright (c) 2013 Corey Tabaka
*
* 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 <string.h>
#include <lwip/api.h>
#include <lwip/ip_addr.h>
#include <lwip/netif.h>
#include <lwip/inet.h>
#include <lwip/stats.h>
#include <lwip/timeouts.h>
#include <apps/ping/ping.h>
#include "lwip/apps/lwiperf.h"
#include "CLI.h"
#include "debug.h"
static void
lwiperf_report(void *arg, enum lwiperf_report_type report_type,
const ip_addr_t* local_addr, u16_t local_port, const ip_addr_t* remote_addr, u16_t remote_port,
u32_t bytes_transferred, u32_t ms_duration, u32_t bandwidth_kbitpsec)
{
LWIP_UNUSED_ARG(arg);
LWIP_UNUSED_ARG(local_addr);
LWIP_UNUSED_ARG(local_port);
printf("IPERF report: type=%d, remote: %s:%d, total bytes: %"U32_F", duration in ms: %"U32_F", kbits/s: %"U32_F"\n",
(int)report_type, ipaddr_ntoa(remote_addr), (int)remote_port, bytes_transferred, ms_duration, bandwidth_kbitpsec);
}
static int net_cmd(int argc, char *argv[])
{
if (argc < 1) {
printf("net commands:\n");
printf("net ifconfig\n");
printf("net stats\n");
printf("net ping <ip>\n");
printf("net iperf <server | client> [ip]\n");
goto out;
}
if (!strcmp(argv[0], "ifconfig")) {
struct netif *netif = NULL;
if (argc == 1) {
NETIF_FOREACH(netif) {
printf("%s%d\n", netif->name, netif->num);
printf("\tHwaddr:\t%02X:%02X:%02X:%02X:%02X:%02X\n",
netif->hwaddr[0], netif->hwaddr[1], netif->hwaddr[2],
netif->hwaddr[3], netif->hwaddr[4], netif->hwaddr[5]);
printf("\tIPaddr:\t%u.%u.%u.%u\n",
ip4_addr1_16(&netif->ip_addr),
ip4_addr2_16(&netif->ip_addr),
ip4_addr3_16(&netif->ip_addr),
ip4_addr4_16(&netif->ip_addr));
printf("\tMask:\t%u.%u.%u.%u\n",
ip4_addr1_16(&netif->netmask),
ip4_addr2_16(&netif->netmask),
ip4_addr3_16(&netif->netmask),
ip4_addr4_16(&netif->netmask));
printf("\tMTU:\t%d\n", netif->mtu);
}
}
else if (argc > 2) {
netif = netif_find(argv[1]);
if (!netif) {
printf("Invalid network card\n");
goto out;
}
if (!strcmp(argv[2], "down")) {
netif_set_down(netif);
}
else if (!strcmp(argv[2], "up")) {
netif_set_default(netif);
netif_set_up(netif);
}
else {
ip4_addr_t ip;
if (!inet_aton(argv[2], &ip)) {
printf("net ifconfig <net card> <up/down/ip>\n");
}
else {
ip4_addr_t gw;
IP4_ADDR(&gw, ip4_addr1_16(&ip),
ip4_addr2_16(&ip), ip4_addr3_16(&ip), 1);
netif_set_ipaddr(netif, &ip);
netif_set_gw(netif, &gw);
}
goto out;
}
}
}
#if LWIP_STATS
else if (!strcmp(argv[0], "stats")) {
stats_display();
}
#endif
else if (!strcmp(argv[0], "ping")) {
static ip_addr_t ip_addr;
ip4_addr_t ip4_addr;
if (argc < 2) {
printf("net ping <IPaddress>\n");
printf("for example:\n");
printf("net ping 192.168.10.11\n");
goto out;
}
if (inet_aton(argv[1], &ip4_addr) == 0) {
printf("ipaddr %s is wrong\n", argv[1]);
goto out;
}
ip_addr_copy_from_ip4(ip_addr, ip4_addr);
ping_init(&ip_addr);
}
else if (!strcmp(argv[0], "iperf")) {
if (argc < 2) {
printf("for example:\n");
printf("net iperf server\n");
printf("net iperf client 192.168.10.20\n");
goto out;
}
if (!strcmp(argv[1], "server")) {
lwiperf_start_tcp_server_default(lwiperf_report, NULL);
}
else if (!strcmp(argv[1], "client")) {
if (argc < 3) {
printf("missing ip addr\n");
goto out;
}
static ip_addr_t ip_addr;
ip4_addr_t ip4_addr;
if (inet_aton(argv[2], &ip4_addr) == 0) {
printf("ipaddr %s is wrong\n", argv[2]);
goto out;
}
ip_addr_copy_from_ip4(ip_addr, ip4_addr);
lwiperf_start_tcp_client_default(&ip_addr, lwiperf_report, NULL);
}
else {
printf("cmd error: net iperf %s\n", argv[1]);
}
}
out:
return 0;
}
CLI_CMD("net", "\r\nnet:\r\n net toolbox\r\n", net_cmd);

View File

@@ -0,0 +1,64 @@
#include <types.h>
#include <netdev.h>
#include <lwip/debug.h>
#include <lwip/def.h>
#include <lwip/tcpip.h>
#include <lwip/etharp.h>
static err_t netdev_linkoutput_fn(struct netif *netif, struct pbuf *p)
{
struct net_driver_s *dev;
dev = (struct net_driver_s *)netif->state;
return dev->d_txavail ? dev->d_txavail(dev, p) : ERR_IF;
}
static err_t netdev_init_fn(struct netif *netif)
{
struct net_driver_s *dev;
netif->output = etharp_output;
netif->linkoutput = netdev_linkoutput_fn;
dev = (struct net_driver_s *)netif->state;
if (dev->d_getmac) {
netif->hwaddr_len = (u8_t)(dev->d_getmac(dev, netif->hwaddr, sizeof(netif->hwaddr)));
}
if (dev->d_getmtu) {
netif->mtu = (u16_t)(dev->d_getmtu(dev));
}
if (dev->d_lltype == NET_LL_ETHERNET) {
netif->name[0] = 'e';
netif->name[1] = 'n';
netif->num = 0;
netif->flags |= NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP;
}
if (dev->d_init) {
dev->d_init(dev);
}
return ERR_OK;
}
err_t netdev_register(struct net_driver_s *dev, enum net_lltype_e lltype)
{
LWIP_ASSERT("netdev_register: dev is NULL", dev != NULL);
dev->d_lltype = (u8_t)lltype;
netif_add(&dev->d_netif,
ip_2_ip4(&dev->d_ipaddr),
ip_2_ip4(&dev->d_netmask),
ip_2_ip4(&dev->d_gateway),
dev, netdev_init_fn, netif_input);
netif_set_default(&dev->d_netif);
netif_set_up(&dev->d_netif);
return ERR_OK;
}

View File

@@ -0,0 +1,43 @@
/*
* Copyright (c) 2017 Simon Goldschmidt
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Simon Goldschmdit <goldsimon@gmx.de>
*
*/
#include <lwip/arch.h>
extern uint32_t current_time(void);
void sys_init(void)
{
}
u32_t sys_now(void)
{
return current_time();
}