fixed menu and complilation error

This commit is contained in:
wlyu 2021-12-20 16:44:44 +08:00
commit 5799b31942
14 changed files with 718 additions and 752 deletions

View File

@ -3,6 +3,7 @@ menu "control app"
menuconfig APPLICATION_CONTROL menuconfig APPLICATION_CONTROL
bool "Using control apps" bool "Using control apps"
default n default n
depends on SUPPORT_CONTROL_FRAMEWORK
endmenu endmenu

View File

@ -2,9 +2,11 @@ SRC_DIR :=
ifeq ($(CONFIG_RESOURCES_LWIP),y) ifeq ($(CONFIG_RESOURCES_LWIP),y)
SRC_DIR += lwip_demo SRC_DIR += lwip_demo
endif
ifeq ($(CONFIG_USING_CONTROL_PLC_OPCUA), y) ifeq ($(CONFIG_USING_CONTROL_PLC_OPCUA), y)
SRC_DIR += opcua_demo SRC_DIR += opcua_demo
endif endif
endif
include $(KERNEL_ROOT)/compiler.mk include $(KERNEL_ROOT)/compiler.mk

View File

@ -1,3 +1,3 @@
SRC_FILES := ping.c lwip_ping_demo.c SRC_FILES := ping.c lwip_ping_demo.c udp_echo.c lwip_udp_demo.c
include $(KERNEL_ROOT)/compiler.mk include $(KERNEL_ROOT)/compiler.mk

View File

@ -1,159 +1,157 @@
/* /*
* Copyright (c) 2016, Freescale Semiconductor, Inc. * Copyright (c) 2016, Freescale Semiconductor, Inc.
* Copyright 2016-2019 NXP * Copyright 2016-2019 NXP
* All rights reserved. * All rights reserved.
* *
* *
* SPDX-License-Identifier: BSD-3-Clause * SPDX-License-Identifier: BSD-3-Clause
*/ */
/* /*
* Copyright (c) 2021 AIIT XUOS Lab * Copyright (c) 2021 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2. * XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at: * You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2 * http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details. * See the Mulan PSL v2 for more details.
*/ */
/** /**
* @file lwip_ping_demo.c * @file lwip_ping_demo.c
* @brief Demo for ping function * @brief Demo for ping function
* @version 1.0 * @version 1.0
* @author AIIT XUOS Lab * @author AIIT XUOS Lab
* @date 2021.12.15 * @date 2021.12.15
*/ */
/******************************************************************************* /*******************************************************************************
* Includes * Includes
******************************************************************************/ ******************************************************************************/
#if LWIP_IPV4 && LWIP_RAW #if LWIP_IPV4 && LWIP_RAW
#include "ping.h" #include "ping.h"
#include "lwip/opt.h" #include "lwip/opt.h"
#include "lwip/timeouts.h" #include "lwip/timeouts.h"
#include "lwip/init.h" #include "lwip/init.h"
#include "netif/ethernet.h" #include "netif/ethernet.h"
#include "board.h" #include "board.h"
#include "pin_mux.h" #include "pin_mux.h"
#include "clock_config.h" #include "clock_config.h"
#include "fsl_gpio.h"
#include "fsl_iomuxc.h" #include <transform.h>
#include <sys_arch.h>
#include <transform.h> #include "connect_ethernet.h"
#include <sys_arch.h>
#include "connect_ethernet.h" /*******************************************************************************
* Definitions
/******************************************************************************* ******************************************************************************/
* Definitions /* IP address configuration. */
******************************************************************************/ #define TEST_IP_ADDR0 192
/* IP address configuration. */ #define TEST_IP_ADDR1 168
#define TEST_IP_ADDR0 192 #define TEST_IP_ADDR2 250
#define TEST_IP_ADDR1 168 #define TEST_IP_ADDR3 253
#define TEST_IP_ADDR2 250
#define TEST_IP_ADDR3 253 /* Netmask configuration. */
#define TEST_NET_MASK0 255
/* Netmask configuration. */ #define TEST_NET_MASK1 255
#define TEST_NET_MASK0 255 #define TEST_NET_MASK2 255
#define TEST_NET_MASK1 255 #define TEST_NET_MASK3 0
#define TEST_NET_MASK2 255
#define TEST_NET_MASK3 0 /* Gateway address configuration. */
#define TEST_GW_ADDR0 192
/* Gateway address configuration. */ #define TEST_GW_ADDR1 168
#define TEST_GW_ADDR0 192 #define TEST_GW_ADDR2 250
#define TEST_GW_ADDR1 168 #define TEST_GW_ADDR3 252
#define TEST_GW_ADDR2 250
#define TEST_GW_ADDR3 252 /* MAC address configuration. */
#define TEST_MAC_ADDR {0x02, 0x12, 0x13, 0x10, 0x15, 0x11}
/* MAC address configuration. */
#define TEST_MAC_ADDR {0x02, 0x12, 0x13, 0x10, 0x15, 0x11} /* Address of PHY interface. */
#define TEST_PHY_ADDR 0x02U
/* Address of PHY interface. */
#define TEST_PHY_ADDR 0x02U /* System clock name. */
#define TEST_CLOCK_NAME kCLOCK_CoreSysClk
/* System clock name. */
#define TEST_CLOCK_NAME kCLOCK_CoreSysClk
/*******************************************************************************
* Prototypes
/******************************************************************************* ******************************************************************************/
* Prototypes
******************************************************************************/ /*******************************************************************************
* Variables
/******************************************************************************* ******************************************************************************/
* Variables
******************************************************************************/ /*******************************************************************************
* Code
/******************************************************************************* ******************************************************************************/
* Code
******************************************************************************/ /*!
* @brief Main function.
/*! */
* @brief Main function. int lwip_ping_test(void)
*/ {
int lwip_ping_test(void) struct netif fsl_netif0;
{ #if defined(FSL_FEATURE_SOC_LPC_ENET_COUNT) && (FSL_FEATURE_SOC_LPC_ENET_COUNT > 0)
struct netif fsl_netif0; mem_range_t non_dma_memory[] = NON_DMA_MEMORY_ARRAY;
#if defined(FSL_FEATURE_SOC_LPC_ENET_COUNT) && (FSL_FEATURE_SOC_LPC_ENET_COUNT > 0) #endif /* FSL_FEATURE_SOC_LPC_ENET_COUNT */
mem_range_t non_dma_memory[] = NON_DMA_MEMORY_ARRAY; ip4_addr_t fsl_netif0_ipaddr, fsl_netif0_netmask, fsl_netif0_gw;
#endif /* FSL_FEATURE_SOC_LPC_ENET_COUNT */ ethernetif_config_t fsl_enet_config0 = {
ip4_addr_t fsl_netif0_ipaddr, fsl_netif0_netmask, fsl_netif0_gw; .phyAddress = TEST_PHY_ADDR,
ethernetif_config_t fsl_enet_config0 = { .clockName = TEST_CLOCK_NAME,
.phyAddress = TEST_PHY_ADDR, .macAddress = TEST_MAC_ADDR,
.clockName = TEST_CLOCK_NAME, #if defined(FSL_FEATURE_SOC_LPC_ENET_COUNT) && (FSL_FEATURE_SOC_LPC_ENET_COUNT > 0)
.macAddress = TEST_MAC_ADDR, .non_dma_memory = non_dma_memory,
#if defined(FSL_FEATURE_SOC_LPC_ENET_COUNT) && (FSL_FEATURE_SOC_LPC_ENET_COUNT > 0) #endif /* FSL_FEATURE_SOC_LPC_ENET_COUNT */
.non_dma_memory = non_dma_memory, };
#endif /* FSL_FEATURE_SOC_LPC_ENET_COUNT */
}; lw_print("lw: [%s] start ...\n", __func__);
lw_print("lw: [%s] start ...\n", __func__); ETH_BSP_Config();
ETH_BSP_Config(); IP4_ADDR(&fsl_netif0_ipaddr, TEST_IP_ADDR0, TEST_IP_ADDR1, TEST_IP_ADDR2, TEST_IP_ADDR3);
IP4_ADDR(&fsl_netif0_netmask, TEST_NET_MASK0, TEST_NET_MASK1, TEST_NET_MASK2, TEST_NET_MASK3);
IP4_ADDR(&fsl_netif0_ipaddr, TEST_IP_ADDR0, TEST_IP_ADDR1, TEST_IP_ADDR2, TEST_IP_ADDR3); IP4_ADDR(&fsl_netif0_gw, TEST_GW_ADDR0, TEST_GW_ADDR1, TEST_GW_ADDR2, TEST_GW_ADDR3);
IP4_ADDR(&fsl_netif0_netmask, TEST_NET_MASK0, TEST_NET_MASK1, TEST_NET_MASK2, TEST_NET_MASK3);
IP4_ADDR(&fsl_netif0_gw, TEST_GW_ADDR0, TEST_GW_ADDR1, TEST_GW_ADDR2, TEST_GW_ADDR3); lwip_init();
lwip_init(); netif_add(&fsl_netif0, &fsl_netif0_ipaddr, &fsl_netif0_netmask, &fsl_netif0_gw, &fsl_enet_config0,
ethernetif0_init,
netif_add(&fsl_netif0, &fsl_netif0_ipaddr, &fsl_netif0_netmask, &fsl_netif0_gw, &fsl_enet_config0, ethernet_input);
ethernetif0_init, netif_set_default(&fsl_netif0);
ethernet_input); netif_set_up(&fsl_netif0);
netif_set_default(&fsl_netif0);
netif_set_up(&fsl_netif0); ping_init(&fsl_netif0_gw);
ping_init(&fsl_netif0_gw); lw_print("\r\n************************************************\r\n");
lw_print(" PING example\r\n");
lw_print("\r\n************************************************\r\n"); lw_print("************************************************\r\n");
lw_print(" PING example\r\n"); lw_print(" IPv4 Address : %u.%u.%u.%u\r\n", ((u8_t *)&fsl_netif0_ipaddr)[0], ((u8_t *)&fsl_netif0_ipaddr)[1],
lw_print("************************************************\r\n"); ((u8_t *)&fsl_netif0_ipaddr)[2], ((u8_t *)&fsl_netif0_ipaddr)[3]);
lw_print(" IPv4 Address : %u.%u.%u.%u\r\n", ((u8_t *)&fsl_netif0_ipaddr)[0], ((u8_t *)&fsl_netif0_ipaddr)[1], lw_print(" IPv4 Subnet mask : %u.%u.%u.%u\r\n", ((u8_t *)&fsl_netif0_netmask)[0], ((u8_t *)&fsl_netif0_netmask)[1],
((u8_t *)&fsl_netif0_ipaddr)[2], ((u8_t *)&fsl_netif0_ipaddr)[3]); ((u8_t *)&fsl_netif0_netmask)[2], ((u8_t *)&fsl_netif0_netmask)[3]);
lw_print(" IPv4 Subnet mask : %u.%u.%u.%u\r\n", ((u8_t *)&fsl_netif0_netmask)[0], ((u8_t *)&fsl_netif0_netmask)[1], lw_print(" IPv4 Gateway : %u.%u.%u.%u\r\n", ((u8_t *)&fsl_netif0_gw)[0], ((u8_t *)&fsl_netif0_gw)[1],
((u8_t *)&fsl_netif0_netmask)[2], ((u8_t *)&fsl_netif0_netmask)[3]); ((u8_t *)&fsl_netif0_gw)[2], ((u8_t *)&fsl_netif0_gw)[3]);
lw_print(" IPv4 Gateway : %u.%u.%u.%u\r\n", ((u8_t *)&fsl_netif0_gw)[0], ((u8_t *)&fsl_netif0_gw)[1], lw_print("************************************************\r\n");
((u8_t *)&fsl_netif0_gw)[2], ((u8_t *)&fsl_netif0_gw)[3]);
lw_print("************************************************\r\n"); while (1)
{
while (1) /* Poll the driver, get any outstanding frames */
{ ethernetif_input(&fsl_netif0);
/* Poll the driver, get any outstanding frames */ sys_check_timeouts(); /* Handle all system timeouts for all core protocols */
ethernetif_input(&fsl_netif0); }
sys_check_timeouts(); /* Handle all system timeouts for all core protocols */ }
}
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(0),
LwPingTest, lwip_ping_test, lwip_ping_test);
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(0),
LwPingTest, lwip_ping_test, lwip_ping_test); #endif
#endif

View File

@ -1,68 +1,69 @@
/* /*
* Copyright (c) 2020 AIIT XUOS Lab * Copyright (c) 2020 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2. * XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at: * You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2 * http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details. * See the Mulan PSL v2 for more details.
*/ */
/** /**
* @file tcp_echo_socket_demo.c * @file tcp_echo_socket_demo.c
* @brief One UDP demo based on LwIP * @brief One UDP demo based on LwIP
* @version 1.0 * @version 1.0
* @author AIIT XUOS Lab * @author AIIT XUOS Lab
* @date 2021-05-29 * @date 2021-05-29
*/ */
#include <xiuos.h> #include <xiuos.h>
#include "udp_echo.h" #include "board.h"
#include <connect_ethernet.h> #include "udp_echo.h"
#include <connect_ethernet.h>
static void NetStackTaskCreate(void* param);
static void NetStackTaskCreate(void* param);
extern void TcpIpInit(void);
extern void TcpIpInit(void);
extern char* send_msg;
extern char* send_msg;
int UdpEchoSocketDemo(int argc, char *argv[])
{ int UdpEchoSocketDemo(int argc, char *argv[])
if (argc == 2) {
{ if (argc == 2)
send_msg = argv[1]; {
} send_msg = argv[1];
}
ETH_BSP_Config();
ETH_BSP_Config();
int32 thr_id = KTaskCreate(
(const char* )"NetStackTaskCreate", int32 thr_id = KTaskCreate(
NetStackTaskCreate, (const char* )"NetStackTaskCreate",
(void* )NULL, NetStackTaskCreate,
(uint16_t )512, (void* )NULL,
15); (uint16_t )512,
15);
if(thr_id >= 0)
StartupKTask(thr_id); if(thr_id >= 0)
else{ StartupKTask(thr_id);
KPrintf("NetStackTaskCreate create failed !\n"); else{
return -1; KPrintf("NetStackTaskCreate create failed !\n");
} return -1;
} }
#ifndef SEPARATE_COMPILE }
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN), #ifndef SEPARATE_COMPILE
UdpEchoSocketDemo, UdpEchoSocketDemo, tcp_echo_socket function ); SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
#endif UdpEchoSocketDemo, UdpEchoSocketDemo, tcp_echo_socket function );
#endif
static void NetStackTaskCreate(void* param)
{ static void NetStackTaskCreate(void* param)
TcpIpInit(); {
TcpIpInit();
UdpEchoInit();
} UdpEchoInit();
}

View File

@ -1,418 +1,418 @@
/** /**
* @file * @file
* Ping sender module * Ping sender module
* *
*/ */
/* /*
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, * 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, * 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products * 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * 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 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE. * OF SUCH DAMAGE.
* *
* This file is part of the lwIP TCP/IP stack. * This file is part of the lwIP TCP/IP stack.
* *
*/ */
/** /**
* This is an example of a "ping" sender (with raw API and socket API). * This is an example of a "ping" sender (with raw API and socket API).
* It can be used as a start point to maintain opened a network connection, or * It can be used as a start point to maintain opened a network connection, or
* like a network "watchdog" for your device. * like a network "watchdog" for your device.
* *
*/ */
#include "lwip/opt.h" #include "lwip/opt.h"
//tst by wly //tst by wly
#include "ip.h" #include "ip.h"
#if LWIP_RAW /* don't build if not configured for use in lwipopts.h */ #if LWIP_RAW /* don't build if not configured for use in lwipopts.h */
#include "ping.h" #include "ping.h"
#include "lwip/mem.h" #include "lwip/mem.h"
#include "lwip/raw.h" #include "lwip/raw.h"
#include "lwip/icmp.h" #include "lwip/icmp.h"
#include "lwip/netif.h" #include "lwip/netif.h"
#include "lwip/sys.h" #include "lwip/sys.h"
#include "lwip/timeouts.h" #include "lwip/timeouts.h"
#include "lwip/inet_chksum.h" #include "lwip/inet_chksum.h"
#include "lwip/prot/ip4.h" #include "lwip/prot/ip4.h"
#if PING_USE_SOCKETS #if PING_USE_SOCKETS
#include "lwip/sockets.h" #include "lwip/sockets.h"
#include "lwip/inet.h" #include "lwip/inet.h"
#include <string.h> #include <string.h>
#endif /* PING_USE_SOCKETS */ #endif /* PING_USE_SOCKETS */
/** /**
* PING_DEBUG: Enable debugging for PING. * PING_DEBUG: Enable debugging for PING.
*/ */
#ifndef PING_DEBUG #ifndef PING_DEBUG
#define PING_DEBUG LWIP_DBG_ON #define PING_DEBUG LWIP_DBG_ON
#endif #endif
/** ping receive timeout - in milliseconds */ /** ping receive timeout - in milliseconds */
#ifndef PING_RCV_TIMEO #ifndef PING_RCV_TIMEO
#define PING_RCV_TIMEO 1000 #define PING_RCV_TIMEO 1000
#endif #endif
/** ping delay - in milliseconds */ /** ping delay - in milliseconds */
#ifndef PING_DELAY #ifndef PING_DELAY
#define PING_DELAY 3000 #define PING_DELAY 3000
#endif #endif
/** ping identifier - must fit on a u16_t */ /** ping identifier - must fit on a u16_t */
#ifndef PING_ID #ifndef PING_ID
#define PING_ID 0xAFAF #define PING_ID 0xAFAF
#endif #endif
/** ping additional data size to include in the packet */ /** ping additional data size to include in the packet */
#ifndef PING_DATA_SIZE #ifndef PING_DATA_SIZE
#define PING_DATA_SIZE 32 #define PING_DATA_SIZE 32
#endif #endif
/** ping result action - no default action */ /** ping result action - no default action */
#ifndef PING_RESULT #ifndef PING_RESULT
#define PING_RESULT(ping_ok) #define PING_RESULT(ping_ok)
#endif #endif
/* ping variables */ /* ping variables */
static const ip_addr_t* ping_target; static const ip_addr_t* ping_target;
static u16_t ping_seq_num; static u16_t ping_seq_num;
#ifdef LWIP_DEBUG #ifdef LWIP_DEBUG
static u32_t ping_time; static u32_t ping_time;
#endif /* LWIP_DEBUG */ #endif /* LWIP_DEBUG */
#if !PING_USE_SOCKETS #if !PING_USE_SOCKETS
static struct raw_pcb *ping_pcb; static struct raw_pcb *ping_pcb;
#endif /* PING_USE_SOCKETS */ #endif /* PING_USE_SOCKETS */
/** Prepare a echo ICMP request */ /** Prepare a echo ICMP request */
static void static void
ping_prepare_echo( struct icmp_echo_hdr *iecho, u16_t len) ping_prepare_echo( struct icmp_echo_hdr *iecho, u16_t len)
{ {
size_t i; size_t i;
size_t data_len = len - sizeof(struct icmp_echo_hdr); size_t data_len = len - sizeof(struct icmp_echo_hdr);
ICMPH_TYPE_SET(iecho, ICMP_ECHO); ICMPH_TYPE_SET(iecho, ICMP_ECHO);
ICMPH_CODE_SET(iecho, 0); ICMPH_CODE_SET(iecho, 0);
iecho->chksum = 0; iecho->chksum = 0;
iecho->id = PING_ID; iecho->id = PING_ID;
iecho->seqno = lwip_htons(++ping_seq_num); iecho->seqno = lwip_htons(++ping_seq_num);
/* fill the additional data buffer with some data */ /* fill the additional data buffer with some data */
for(i = 0; i < data_len; i++) { for(i = 0; i < data_len; i++) {
((char*)iecho)[sizeof(struct icmp_echo_hdr) + i] = (char)i; ((char*)iecho)[sizeof(struct icmp_echo_hdr) + i] = (char)i;
} }
iecho->chksum = inet_chksum(iecho, len); iecho->chksum = inet_chksum(iecho, len);
} }
#if PING_USE_SOCKETS #if PING_USE_SOCKETS
/* Ping using the socket ip */ /* Ping using the socket ip */
static err_t static err_t
ping_send(int s, const ip_addr_t *addr) ping_send(int s, const ip_addr_t *addr)
{ {
int err; int err;
struct icmp_echo_hdr *iecho; struct icmp_echo_hdr *iecho;
struct sockaddr_storage to; struct sockaddr_storage to;
size_t ping_size = sizeof(struct icmp_echo_hdr) + PING_DATA_SIZE; size_t ping_size = sizeof(struct icmp_echo_hdr) + PING_DATA_SIZE;
LWIP_ASSERT("ping_size is too big", ping_size <= 0xffff); LWIP_ASSERT("ping_size is too big", ping_size <= 0xffff);
#if LWIP_IPV6 #if LWIP_IPV6
if(IP_IS_V6(addr) && !ip6_addr_isipv4mappedipv6(ip_2_ip6(addr))) { if(IP_IS_V6(addr) && !ip6_addr_isipv4mappedipv6(ip_2_ip6(addr))) {
/* todo: support ICMP6 echo */ /* todo: support ICMP6 echo */
return ERR_VAL; return ERR_VAL;
} }
#endif /* LWIP_IPV6 */ #endif /* LWIP_IPV6 */
iecho = (struct icmp_echo_hdr *)mem_malloc((mem_size_t)ping_size); iecho = (struct icmp_echo_hdr *)mem_malloc((mem_size_t)ping_size);
if (!iecho) { if (!iecho) {
return ERR_MEM; return ERR_MEM;
} }
ping_prepare_echo(iecho, (u16_t)ping_size); ping_prepare_echo(iecho, (u16_t)ping_size);
#if LWIP_IPV4 #if LWIP_IPV4
if(IP_IS_V4(addr)) { if(IP_IS_V4(addr)) {
struct sockaddr_in *to4 = (struct sockaddr_in*)&to; struct sockaddr_in *to4 = (struct sockaddr_in*)&to;
to4->sin_len = sizeof(to4); to4->sin_len = sizeof(to4);
to4->sin_family = AF_INET; to4->sin_family = AF_INET;
inet_addr_from_ip4addr(&to4->sin_addr, ip_2_ip4(addr)); inet_addr_from_ip4addr(&to4->sin_addr, ip_2_ip4(addr));
} }
#endif /* LWIP_IPV4 */ #endif /* LWIP_IPV4 */
#if LWIP_IPV6 #if LWIP_IPV6
if(IP_IS_V6(addr)) { if(IP_IS_V6(addr)) {
struct sockaddr_in6 *to6 = (struct sockaddr_in6*)&to; struct sockaddr_in6 *to6 = (struct sockaddr_in6*)&to;
to6->sin6_len = sizeof(to6); to6->sin6_len = sizeof(to6);
to6->sin6_family = AF_INET6; to6->sin6_family = AF_INET6;
inet6_addr_from_ip6addr(&to6->sin6_addr, ip_2_ip6(addr)); inet6_addr_from_ip6addr(&to6->sin6_addr, ip_2_ip6(addr));
} }
#endif /* LWIP_IPV6 */ #endif /* LWIP_IPV6 */
err = lwip_sendto(s, iecho, ping_size, 0, (struct sockaddr*)&to, sizeof(to)); err = lwip_sendto(s, iecho, ping_size, 0, (struct sockaddr*)&to, sizeof(to));
mem_free(iecho); mem_free(iecho);
return (err ? ERR_OK : ERR_VAL); return (err ? ERR_OK : ERR_VAL);
} }
static void static void
ping_recv(int s) ping_recv(int s)
{ {
char buf[64]; char buf[64];
int len; int len;
struct sockaddr_storage from; struct sockaddr_storage from;
int fromlen = sizeof(from); int fromlen = sizeof(from);
// lw_print("lw: [%s] recv %d\n",__func__, fromlen); // lw_print("lw: [%s] recv %d\n",__func__, fromlen);
while((len = lwip_recvfrom(s, buf, sizeof(buf), 0, (struct sockaddr*)&from, (socklen_t*)&fromlen)) > 0) { while((len = lwip_recvfrom(s, buf, sizeof(buf), 0, (struct sockaddr*)&from, (socklen_t*)&fromlen)) > 0) {
if (len >= (int)(sizeof(struct ip_hdr)+sizeof(struct icmp_echo_hdr))) { if (len >= (int)(sizeof(struct ip_hdr)+sizeof(struct icmp_echo_hdr))) {
ip_addr_t fromaddr; ip_addr_t fromaddr;
memset(&fromaddr, 0, sizeof(fromaddr)); memset(&fromaddr, 0, sizeof(fromaddr));
#if LWIP_IPV4 #if LWIP_IPV4
if(from.ss_family == AF_INET) { if(from.ss_family == AF_INET) {
struct sockaddr_in *from4 = (struct sockaddr_in*)&from; struct sockaddr_in *from4 = (struct sockaddr_in*)&from;
inet_addr_to_ip4addr(ip_2_ip4(&fromaddr), &from4->sin_addr); inet_addr_to_ip4addr(ip_2_ip4(&fromaddr), &from4->sin_addr);
IP_SET_TYPE_VAL(fromaddr, IPADDR_TYPE_V4); IP_SET_TYPE_VAL(fromaddr, IPADDR_TYPE_V4);
} }
#endif /* LWIP_IPV4 */ #endif /* LWIP_IPV4 */
#if LWIP_IPV6 #if LWIP_IPV6
if(from.ss_family == AF_INET6) { if(from.ss_family == AF_INET6) {
struct sockaddr_in6 *from6 = (struct sockaddr_in6*)&from; struct sockaddr_in6 *from6 = (struct sockaddr_in6*)&from;
inet6_addr_to_ip6addr(ip_2_ip6(&fromaddr), &from6->sin6_addr); inet6_addr_to_ip6addr(ip_2_ip6(&fromaddr), &from6->sin6_addr);
IP_SET_TYPE_VAL(fromaddr, IPADDR_TYPE_V6); IP_SET_TYPE_VAL(fromaddr, IPADDR_TYPE_V6);
} }
#endif /* LWIP_IPV6 */ #endif /* LWIP_IPV6 */
LWIP_DEBUGF( PING_DEBUG, ("ping: recv ")); LWIP_DEBUGF( PING_DEBUG, ("ping: recv "));
ip_addr_debug_print_val(PING_DEBUG, fromaddr); ip_addr_debug_print_val(PING_DEBUG, fromaddr);
LWIP_DEBUGF( PING_DEBUG, (" %"U32_F" ms\n", (sys_now() - ping_time))); LWIP_DEBUGF( PING_DEBUG, (" %"U32_F" ms\n", (sys_now() - ping_time)));
/* todo: support ICMP6 echo */ /* todo: support ICMP6 echo */
#if LWIP_IPV4 #if LWIP_IPV4
if (IP_IS_V4_VAL(fromaddr)) { if (IP_IS_V4_VAL(fromaddr)) {
struct ip_hdr *iphdr; struct ip_hdr *iphdr;
struct icmp_echo_hdr *iecho; struct icmp_echo_hdr *iecho;
iphdr = (struct ip_hdr *)buf; iphdr = (struct ip_hdr *)buf;
iecho = (struct icmp_echo_hdr *)(buf + (IPH_HL(iphdr) * 4)); iecho = (struct icmp_echo_hdr *)(buf + (IPH_HL(iphdr) * 4));
if ((iecho->id == PING_ID) && (iecho->seqno == lwip_htons(ping_seq_num))) { if ((iecho->id == PING_ID) && (iecho->seqno == lwip_htons(ping_seq_num))) {
/* do some ping result processing */ /* do some ping result processing */
PING_RESULT((ICMPH_TYPE(iecho) == ICMP_ER)); PING_RESULT((ICMPH_TYPE(iecho) == ICMP_ER));
return; return;
} else { } else {
LWIP_DEBUGF( PING_DEBUG, ("ping: drop\n")); LWIP_DEBUGF( PING_DEBUG, ("ping: drop\n"));
} }
} }
#endif /* LWIP_IPV4 */ #endif /* LWIP_IPV4 */
} }
fromlen = sizeof(from); fromlen = sizeof(from);
} }
if (len == 0) { if (len == 0) {
LWIP_DEBUGF( PING_DEBUG, ("ping: recv - %"U32_F" ms - timeout\n", (sys_now()-ping_time))); LWIP_DEBUGF( PING_DEBUG, ("ping: recv - %"U32_F" ms - timeout\n", (sys_now()-ping_time)));
} }
/* do some ping result processing */ /* do some ping result processing */
PING_RESULT(0); PING_RESULT(0);
} }
static void static void
ping_thread(void *arg) ping_thread(void *arg)
{ {
int s; int s;
int ret; int ret;
#if LWIP_SO_SNDRCVTIMEO_NONSTANDARD #if LWIP_SO_SNDRCVTIMEO_NONSTANDARD
int timeout = PING_RCV_TIMEO; int timeout = PING_RCV_TIMEO;
#else #else
struct timeval timeout; struct timeval timeout;
timeout.tv_sec = PING_RCV_TIMEO/1000; timeout.tv_sec = PING_RCV_TIMEO/1000;
timeout.tv_usec = (PING_RCV_TIMEO%1000)*1000; timeout.tv_usec = (PING_RCV_TIMEO%1000)*1000;
#endif #endif
LWIP_UNUSED_ARG(arg); LWIP_UNUSED_ARG(arg);
lw_print("lw: [%s] start...\n", __func__); lw_print("lw: [%s] start...\n", __func__);
#if LWIP_IPV6 #if LWIP_IPV6
if(IP_IS_V4(ping_target) || ip6_addr_isipv4mappedipv6(ip_2_ip6(ping_target))) { if(IP_IS_V4(ping_target) || ip6_addr_isipv4mappedipv6(ip_2_ip6(ping_target))) {
s = lwip_socket(AF_INET6, SOCK_RAW, IP_PROTO_ICMP); s = lwip_socket(AF_INET6, SOCK_RAW, IP_PROTO_ICMP);
} else { } else {
s = lwip_socket(AF_INET6, SOCK_RAW, IP6_NEXTH_ICMP6); s = lwip_socket(AF_INET6, SOCK_RAW, IP6_NEXTH_ICMP6);
} }
#else #else
s = lwip_socket(AF_INET, SOCK_RAW, IP_PROTO_ICMP); s = lwip_socket(AF_INET, SOCK_RAW, IP_PROTO_ICMP);
#endif #endif
if (s < 0) { if (s < 0) {
lw_print("lw: [%s] ping failed %d!\n", __func__, s); lw_print("lw: [%s] ping failed %d!\n", __func__, s);
return; return;
} }
lw_print("lw: [%s] ping start!\n", __func__); lw_print("lw: [%s] ping start!\n", __func__);
ret = lwip_setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout)); ret = lwip_setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout));
LWIP_ASSERT("setting receive timeout failed", ret == 0); LWIP_ASSERT("setting receive timeout failed", ret == 0);
LWIP_UNUSED_ARG(ret); LWIP_UNUSED_ARG(ret);
while (1) { while (1) {
if (ping_send(s, ping_target) == ERR_OK) { if (ping_send(s, ping_target) == ERR_OK) {
LWIP_DEBUGF( PING_DEBUG, ("ping: send ")); LWIP_DEBUGF( PING_DEBUG, ("ping: send "));
ip_addr_debug_print(PING_DEBUG, ping_target); ip_addr_debug_print(PING_DEBUG, ping_target);
LWIP_DEBUGF( PING_DEBUG, ("\n")); LWIP_DEBUGF( PING_DEBUG, ("\n"));
#ifdef LWIP_DEBUG #ifdef LWIP_DEBUG
ping_time = sys_now(); ping_time = sys_now();
#endif /* LWIP_DEBUG */ #endif /* LWIP_DEBUG */
ping_recv(s); ping_recv(s);
} else { } else {
LWIP_DEBUGF( PING_DEBUG, ("ping: send ")); LWIP_DEBUGF( PING_DEBUG, ("ping: send "));
ip_addr_debug_print(PING_DEBUG, ping_target); ip_addr_debug_print(PING_DEBUG, ping_target);
LWIP_DEBUGF( PING_DEBUG, (" - error\n")); LWIP_DEBUGF( PING_DEBUG, (" - error\n"));
} }
sys_msleep(PING_DELAY); sys_msleep(PING_DELAY);
} }
} }
#else /* PING_USE_SOCKETS */ #else /* PING_USE_SOCKETS */
/* Ping using the raw ip */ /* Ping using the raw ip */
static u8_t static u8_t
ping_recv(void *arg, struct raw_pcb *pcb, struct pbuf *p, const ip_addr_t *addr) ping_recv(void *arg, struct raw_pcb *pcb, struct pbuf *p, const ip_addr_t *addr)
{ {
struct icmp_echo_hdr *iecho; struct icmp_echo_hdr *iecho;
LWIP_UNUSED_ARG(arg); LWIP_UNUSED_ARG(arg);
LWIP_UNUSED_ARG(pcb); LWIP_UNUSED_ARG(pcb);
LWIP_UNUSED_ARG(addr); LWIP_UNUSED_ARG(addr);
LWIP_ASSERT("p != NULL", p != NULL); LWIP_ASSERT("p != NULL", p != NULL);
if ((p->tot_len >= (PBUF_IP_HLEN + sizeof(struct icmp_echo_hdr))) && if ((p->tot_len >= (PBUF_IP_HLEN + sizeof(struct icmp_echo_hdr))) &&
pbuf_remove_header(p, PBUF_IP_HLEN) == 0) { pbuf_remove_header(p, PBUF_IP_HLEN) == 0) {
iecho = (struct icmp_echo_hdr *)p->payload; iecho = (struct icmp_echo_hdr *)p->payload;
if ((iecho->id == PING_ID) && (iecho->seqno == lwip_htons(ping_seq_num))) { if ((iecho->id == PING_ID) && (iecho->seqno == lwip_htons(ping_seq_num))) {
LWIP_DEBUGF( PING_DEBUG, ("ping: recv ")); LWIP_DEBUGF( PING_DEBUG, ("ping: recv "));
ip_addr_debug_print(PING_DEBUG, addr); ip_addr_debug_print(PING_DEBUG, addr);
LWIP_DEBUGF( PING_DEBUG, (" %"U32_F" ms\n", (sys_now()-ping_time))); LWIP_DEBUGF( PING_DEBUG, (" %"U32_F" ms\n", (sys_now()-ping_time)));
/* do some ping result processing */ /* do some ping result processing */
PING_RESULT(1); PING_RESULT(1);
pbuf_free(p); pbuf_free(p);
return 1; /* eat the packet */ return 1; /* eat the packet */
} }
/* not eaten, restore original packet */ /* not eaten, restore original packet */
/* Changed to the "_force" version because of LPC zerocopy pbufs */ /* Changed to the "_force" version because of LPC zerocopy pbufs */
pbuf_add_header_force(p, PBUF_IP_HLEN); pbuf_add_header_force(p, PBUF_IP_HLEN);
} }
return 0; /* don't eat the packet */ return 0; /* don't eat the packet */
} }
static void static void
ping_send(struct raw_pcb *raw, const ip_addr_t *addr) ping_send(struct raw_pcb *raw, const ip_addr_t *addr)
{ {
struct pbuf *p; struct pbuf *p;
struct icmp_echo_hdr *iecho; struct icmp_echo_hdr *iecho;
size_t ping_size = sizeof(struct icmp_echo_hdr) + PING_DATA_SIZE; size_t ping_size = sizeof(struct icmp_echo_hdr) + PING_DATA_SIZE;
LWIP_DEBUGF( PING_DEBUG, ("ping: send ")); LWIP_DEBUGF( PING_DEBUG, ("ping: send "));
ip_addr_debug_print(PING_DEBUG, addr); ip_addr_debug_print(PING_DEBUG, addr);
LWIP_DEBUGF( PING_DEBUG, ("\n")); LWIP_DEBUGF( PING_DEBUG, ("\n"));
LWIP_ASSERT("ping_size <= 0xffff", ping_size <= 0xffff); LWIP_ASSERT("ping_size <= 0xffff", ping_size <= 0xffff);
p = pbuf_alloc(PBUF_IP, (u16_t)ping_size, PBUF_RAM); p = pbuf_alloc(PBUF_IP, (u16_t)ping_size, PBUF_RAM);
if (!p) { if (!p) {
lw_trace(); lw_trace();
return; return;
} }
if ((p->len == p->tot_len) && (p->next == NULL)) { if ((p->len == p->tot_len) && (p->next == NULL)) {
iecho = (struct icmp_echo_hdr *)p->payload; iecho = (struct icmp_echo_hdr *)p->payload;
ping_prepare_echo(iecho, (u16_t)ping_size); ping_prepare_echo(iecho, (u16_t)ping_size);
raw_sendto(raw, p, addr); raw_sendto(raw, p, addr);
#ifdef LWIP_DEBUG #ifdef LWIP_DEBUG
ping_time = sys_now(); ping_time = sys_now();
#endif /* LWIP_DEBUG */ #endif /* LWIP_DEBUG */
} }
pbuf_free(p); pbuf_free(p);
// lw_print("lw: [%s] send %d\n", __func__, ping_size); // lw_print("lw: [%s] send %d\n", __func__, ping_size);
} }
static void static void
ping_timeout(void *arg) ping_timeout(void *arg)
{ {
struct raw_pcb *pcb = (struct raw_pcb*)arg; struct raw_pcb *pcb = (struct raw_pcb*)arg;
LWIP_ASSERT("ping_timeout: no pcb given!", pcb != NULL); LWIP_ASSERT("ping_timeout: no pcb given!", pcb != NULL);
ping_send(pcb, ping_target); ping_send(pcb, ping_target);
sys_timeout(PING_DELAY, ping_timeout, pcb); sys_timeout(PING_DELAY, ping_timeout, pcb);
} }
static void static void
ping_raw_init(void) ping_raw_init(void)
{ {
ping_pcb = raw_new(IP_PROTO_ICMP); ping_pcb = raw_new(IP_PROTO_ICMP);
LWIP_ASSERT("ping_pcb != NULL", ping_pcb != NULL); LWIP_ASSERT("ping_pcb != NULL", ping_pcb != NULL);
//tst by wly //tst by wly
lw_print("lw: [%s] pcb %p\n", __func__, ping_pcb); lw_print("lw: [%s] pcb %p\n", __func__, ping_pcb);
raw_recv(ping_pcb, ping_recv, NULL); raw_recv(ping_pcb, ping_recv, NULL);
raw_bind(ping_pcb, IP_ADDR_ANY); raw_bind(ping_pcb, IP_ADDR_ANY);
sys_timeout(PING_DELAY, ping_timeout, ping_pcb); sys_timeout(PING_DELAY, ping_timeout, ping_pcb);
} }
void void
ping_send_now(void) ping_send_now(void)
{ {
LWIP_ASSERT("ping_pcb != NULL", ping_pcb != NULL); LWIP_ASSERT("ping_pcb != NULL", ping_pcb != NULL);
ping_send(ping_pcb, ping_target); ping_send(ping_pcb, ping_target);
} }
#endif /* PING_USE_SOCKETS */ #endif /* PING_USE_SOCKETS */
#define PING_THREAD_STACKSIZE 4096 #define PING_THREAD_STACKSIZE 4096
#define PING_THREAD_PRIO 0 #define PING_THREAD_PRIO 0
void void
ping_init(const ip_addr_t* ping_addr) ping_init(const ip_addr_t* ping_addr)
{ {
sys_thread_t th; sys_thread_t th;
ping_target = ping_addr; ping_target = ping_addr;
#if PING_USE_SOCKETS #if PING_USE_SOCKETS
th = sys_thread_new("ping_thread", ping_thread, NULL, PING_THREAD_STACKSIZE, PING_THREAD_PRIO); th = sys_thread_new("ping_thread", ping_thread, NULL, PING_THREAD_STACKSIZE, PING_THREAD_PRIO);
lw_print("lw: [%s] sys %d addr %#x\n", __func__, th, (*ping_addr).addr); lw_print("lw: [%s] sys %d addr %#x\n", __func__, th, (*ping_addr).addr);
#else /* PING_USE_SOCKETS */ #else /* PING_USE_SOCKETS */
ping_raw_init(); ping_raw_init();
#endif /* PING_USE_SOCKETS */ #endif /* PING_USE_SOCKETS */
} }
#endif /* LWIP_RAW */ #endif /* LWIP_RAW */

View File

@ -1,19 +1,19 @@
#ifndef LWIP_PING_H #ifndef LWIP_PING_H
#define LWIP_PING_H #define LWIP_PING_H
#include "lwip/ip_addr.h" #include "lwip/ip_addr.h"
/** /**
* PING_USE_SOCKETS: Set to 1 to use sockets, otherwise the raw api is used * PING_USE_SOCKETS: Set to 1 to use sockets, otherwise the raw api is used
*/ */
#ifndef PING_USE_SOCKETS #ifndef PING_USE_SOCKETS
#define PING_USE_SOCKETS 0//LWIP_SOCKET #define PING_USE_SOCKETS 0//LWIP_SOCKET
#endif #endif
void ping_init(const ip_addr_t* ping_addr); void ping_init(const ip_addr_t* ping_addr);
#if !PING_USE_SOCKETS #if !PING_USE_SOCKETS
void ping_send_now(void); void ping_send_now(void);
#endif /* !PING_USE_SOCKETS */ #endif /* !PING_USE_SOCKETS */
#endif /* LWIP_PING_H */ #endif /* LWIP_PING_H */

View File

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

View File

@ -25,12 +25,9 @@
#include <stdint.h> #include <stdint.h>
#include <sys/types.h> #include <sys/types.h>
#include <lwip/altcp.h> #include <lwip/altcp.h>
#include <fsl_gpio.h>
#include <fsl_iomuxc.h>
#include "netif/ethernet.h" #include "netif/ethernet.h"
#include "enet_ethernetif.h"
#include "connect_ethernet.h" #include "board.h"
typedef unsigned int nfds_t; typedef unsigned int nfds_t;
#include "../../../../APP_Framework/Framework/control/plc/interoperability/opcua/open62541.h" #include "../../../../APP_Framework/Framework/control/plc/interoperability/opcua/open62541.h"
@ -70,14 +67,13 @@ typedef unsigned int nfds_t;
/* System clock name. */ /* System clock name. */
#define EXAMPLE_CLOCK_NAME kCLOCK_CoreSysClk #define EXAMPLE_CLOCK_NAME kCLOCK_CoreSysClk
//#define sourceClock CLOCK_GetFreq(kCLOCK_CoreSysClk)
const char *test_uri = "opc.tcp://192.168.250.5:4840"; const char *test_uri = "opc.tcp://192.168.250.5:4840";
const char *test_cb_str = "tcp client connected\r\n"; const char *test_cb_str = "tcp client connected\r\n";
void ua_ip_init(void) void ua_ip_init(void)
{ {
#ifdef BOARD_CORTEX_M7_EVB
struct netif fsl_netif0; struct netif fsl_netif0;
#if defined(FSL_FEATURE_SOC_LPC_ENET_COUNT) && (FSL_FEATURE_SOC_LPC_ENET_COUNT > 0) #if defined(FSL_FEATURE_SOC_LPC_ENET_COUNT) && (FSL_FEATURE_SOC_LPC_ENET_COUNT > 0)
mem_range_t non_dma_memory[] = NON_DMA_MEMORY_ARRAY; mem_range_t non_dma_memory[] = NON_DMA_MEMORY_ARRAY;
@ -92,8 +88,6 @@ void ua_ip_init(void)
#endif /* FSL_FEATURE_SOC_LPC_ENET_COUNT */ #endif /* FSL_FEATURE_SOC_LPC_ENET_COUNT */
}; };
gpio_pin_config_t gpio_config = {kGPIO_DigitalOutput, 0, kGPIO_NoIntmode};
ua_print("lw: [%s] start ...\n", __func__); ua_print("lw: [%s] start ...\n", __func__);
IP4_ADDR(&fsl_netif0_ipaddr, configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3); IP4_ADDR(&fsl_netif0_ipaddr, configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3);
@ -107,8 +101,6 @@ void ua_ip_init(void)
netif_set_default(&fsl_netif0); netif_set_default(&fsl_netif0);
netif_set_up(&fsl_netif0); netif_set_up(&fsl_netif0);
// ping_init(&fsl_netif0_gw);
ua_print("\r\n************************************************\r\n"); ua_print("\r\n************************************************\r\n");
ua_print(" PING example\r\n"); ua_print(" PING example\r\n");
ua_print("************************************************\r\n"); ua_print("************************************************\r\n");
@ -119,7 +111,7 @@ void ua_ip_init(void)
ua_print(" IPv4 Gateway : %u.%u.%u.%u\r\n", ((u8_t *)&fsl_netif0_gw)[0], ((u8_t *)&fsl_netif0_gw)[1], ua_print(" IPv4 Gateway : %u.%u.%u.%u\r\n", ((u8_t *)&fsl_netif0_gw)[0], ((u8_t *)&fsl_netif0_gw)[1],
((u8_t *)&fsl_netif0_gw)[2], ((u8_t *)&fsl_netif0_gw)[3]); ((u8_t *)&fsl_netif0_gw)[2], ((u8_t *)&fsl_netif0_gw)[3]);
ua_print("************************************************\r\n"); ua_print("************************************************\r\n");
#endif
} }
// tcp client callback // tcp client callback
@ -243,4 +235,3 @@ void TestUaConnect(int argc, char *argv[])
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(0), SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(0),
UaConnect, TestUaConnect, TestUaConnect); UaConnect, TestUaConnect, TestUaConnect);

View File

@ -2,4 +2,5 @@
menuconfig USING_CONTROL_PLC_OPCUA menuconfig USING_CONTROL_PLC_OPCUA
bool "PLC support OPCUA" bool "PLC support OPCUA"
default y default y
depends on RESOURCES_LWIP

View File

@ -1,9 +1,13 @@
SRC_DIR := SRC_DIR :=
ifeq ($(CONFIG_RESOURCES_LWIP),y)
ifeq ($(CONFIG_USING_CONTROL_PLC_OPCUA), y) ifeq ($(CONFIG_USING_CONTROL_PLC_OPCUA), y)
SRC_DIR += opcua SRC_DIR += opcua
endif endif
endif
SRC_FILES += interoperability.c SRC_FILES += interoperability.c
include $(KERNEL_ROOT)/compiler.mk include $(KERNEL_ROOT)/compiler.mk

View File

@ -426,8 +426,6 @@ void ENET_Init(ENET_Type *base,
/* Reset ENET module. */ /* Reset ENET module. */
ENET_Reset(base); ENET_Reset(base);
lw_print("lw: [%s] config %p %x\n", __func__, config, config->interrupt);
/* Initializes the ENET transmit buffer descriptors. */ /* Initializes the ENET transmit buffer descriptors. */
ENET_SetTxBufferDescriptors(handle, config, bufferConfig); ENET_SetTxBufferDescriptors(handle, config, bufferConfig);
@ -504,9 +502,6 @@ static void ENET_SetHandler(ENET_Type *base,
handle->txBdCurrent[count] = buffCfg->txBdStartAddrAlign; handle->txBdCurrent[count] = buffCfg->txBdStartAddrAlign;
handle->txBuffSizeAlign[count] = buffCfg->txBuffSizeAlign; handle->txBuffSizeAlign[count] = buffCfg->txBuffSizeAlign;
lw_print("lw: [%s] %d instance %d ring %d %p IRQ %p %#x\n", __func__,
count, instance, handle->ringNum, buffCfg->rxBdStartAddrAlign, config, config->interrupt);
buffCfg++; buffCfg++;
} }
@ -516,19 +511,16 @@ static void ENET_SetHandler(ENET_Type *base,
/* Set the IRQ handler when the interrupt is enabled. */ /* Set the IRQ handler when the interrupt is enabled. */
if (config->interrupt & ENET_TX_INTERRUPT) if (config->interrupt & ENET_TX_INTERRUPT)
{ {
lw_trace();
s_enetTxIsr = ENET_TransmitIRQHandler; s_enetTxIsr = ENET_TransmitIRQHandler;
EnableIRQ(s_enetTxIrqId[instance]); EnableIRQ(s_enetTxIrqId[instance]);
} }
if (config->interrupt & ENET_RX_INTERRUPT) if (config->interrupt & ENET_RX_INTERRUPT)
{ {
lw_trace();
s_enetRxIsr = ENET_ReceiveIRQHandler; s_enetRxIsr = ENET_ReceiveIRQHandler;
EnableIRQ(s_enetRxIrqId[instance]); EnableIRQ(s_enetRxIrqId[instance]);
} }
if (config->interrupt & ENET_ERR_INTERRUPT) if (config->interrupt & ENET_ERR_INTERRUPT)
{ {
lw_trace();
s_enetErrIsr = ENET_ErrorIRQHandler; s_enetErrIsr = ENET_ErrorIRQHandler;
EnableIRQ(s_enetErrIrqId[instance]); EnableIRQ(s_enetErrIrqId[instance]);
} }
@ -921,10 +913,6 @@ static void ENET_ActiveSend(ENET_Type *base, uint32_t ringId)
/* Ensure previous data update is completed with Data Synchronization Barrier before activing Tx BD. */ /* Ensure previous data update is completed with Data Synchronization Barrier before activing Tx BD. */
__DSB(); __DSB();
//tst by wly
// lw_print("lw: [%s] ring %d\n", __func__, ringId);
switch (ringId) switch (ringId)
{ {
case kENET_Ring0: case kENET_Ring0:
@ -1322,12 +1310,9 @@ status_t ENET_GetRxFrameSize(enet_handle_t *handle, uint32_t *length)
} }
/* FCS is removed by MAC. */ /* FCS is removed by MAC. */
*length = curBuffDescrip->length; *length = curBuffDescrip->length;
// lw_print("lw: [%s] %p %p ctrl %#x ok\n", __func__, curBuffDescrip, handle->rxBdCurrent[0], curBuffDescrip->control);
return kStatus_Success; return kStatus_Success;
} }
// lw_print("lw: [%s] %p %p ctrl %#x\n", __func__, curBuffDescrip, handle->rxBdCurrent[0], curBuffDescrip->control);
/* Increase the buffer descriptor, if it is the last one, increase to first one of the ring buffer. */ /* Increase the buffer descriptor, if it is the last one, increase to first one of the ring buffer. */
if (curBuffDescrip->control & ENET_BUFFDESCRIPTOR_RX_WRAP_MASK) if (curBuffDescrip->control & ENET_BUFFDESCRIPTOR_RX_WRAP_MASK)
{ {
@ -1396,8 +1381,6 @@ status_t ENET_ReadFrame(ENET_Type *base, enet_handle_t *handle, uint8_t *data, u
/* For data-NULL input, only update the buffer descriptor. */ /* For data-NULL input, only update the buffer descriptor. */
if (!data) if (!data)
{ {
// lw_print("lw: [%s] data %d ctrl %#x\n", __func__, length, handle->rxBdCurrent[0]->control);
do do
{ {
/* Update the control flag. */ /* Update the control flag. */
@ -1418,8 +1401,6 @@ status_t ENET_ReadFrame(ENET_Type *base, enet_handle_t *handle, uint8_t *data, u
else else
{ {
// lw_print("lw: [%s] data len %d ctrl %#x\n", __func__, length, handle->rxBdCurrent[0]->control);
/* A frame on one buffer or several receive buffers are both considered. */ /* A frame on one buffer or several receive buffers are both considered. */
#if defined(FSL_FEATURE_MEMORY_HAS_ADDRESS_OFFSET) && FSL_FEATURE_MEMORY_HAS_ADDRESS_OFFSET #if defined(FSL_FEATURE_MEMORY_HAS_ADDRESS_OFFSET) && FSL_FEATURE_MEMORY_HAS_ADDRESS_OFFSET
address = MEMORY_ConvertMemoryMapAddress((uint32_t)curBuffDescrip->buffer, kMEMORY_DMA2Local); address = MEMORY_ConvertMemoryMapAddress((uint32_t)curBuffDescrip->buffer, kMEMORY_DMA2Local);
@ -1489,9 +1470,6 @@ status_t ENET_ReadFrame(ENET_Type *base, enet_handle_t *handle, uint8_t *data, u
/* Get the current buffer descriptor. */ /* Get the current buffer descriptor. */
curBuffDescrip = handle->rxBdCurrent[0]; curBuffDescrip = handle->rxBdCurrent[0];
// lw_print("lw: [%s] ctrl %#x\n", __func__, handle->rxBdCurrent[0]->control);
/* Add the cache invalidate maintain. */ /* Add the cache invalidate maintain. */
#if defined(FSL_FEATURE_MEMORY_HAS_ADDRESS_OFFSET) && FSL_FEATURE_MEMORY_HAS_ADDRESS_OFFSET #if defined(FSL_FEATURE_MEMORY_HAS_ADDRESS_OFFSET) && FSL_FEATURE_MEMORY_HAS_ADDRESS_OFFSET
address = MEMORY_ConvertMemoryMapAddress((uint32_t)curBuffDescrip->buffer, kMEMORY_DMA2Local); address = MEMORY_ConvertMemoryMapAddress((uint32_t)curBuffDescrip->buffer, kMEMORY_DMA2Local);
@ -1517,8 +1495,6 @@ static void ENET_UpdateReadBuffers(ENET_Type *base, enet_handle_t *handle, uint3
/* Sets the receive buffer descriptor with the empty flag. */ /* Sets the receive buffer descriptor with the empty flag. */
handle->rxBdCurrent[ringId]->control |= ENET_BUFFDESCRIPTOR_RX_EMPTY_MASK; handle->rxBdCurrent[ringId]->control |= ENET_BUFFDESCRIPTOR_RX_EMPTY_MASK;
// lw_print("lw: [%s] ring %d ctrl %#x\n", __func__, ringId, handle->rxBdCurrent[ringId]->control);
/* Increase current buffer descriptor to the next one. */ /* Increase current buffer descriptor to the next one. */
if (handle->rxBdCurrent[ringId]->control & ENET_BUFFDESCRIPTOR_RX_WRAP_MASK) if (handle->rxBdCurrent[ringId]->control & ENET_BUFFDESCRIPTOR_RX_WRAP_MASK)
{ {
@ -1529,8 +1505,6 @@ static void ENET_UpdateReadBuffers(ENET_Type *base, enet_handle_t *handle, uint3
handle->rxBdCurrent[ringId]++; handle->rxBdCurrent[ringId]++;
} }
// lw_print("lw: [%s] ring %d changed ctrl %#x\n", __func__, ringId, handle->rxBdCurrent[ringId]->control);
/* Ensure previous data update is completed with Data Synchronization Barrier before activing Rx BD. */ /* Ensure previous data update is completed with Data Synchronization Barrier before activing Rx BD. */
__DSB(); __DSB();
@ -1636,8 +1610,6 @@ status_t ENET_SendFrame(ENET_Type *base, enet_handle_t *handle, const uint8_t *d
handle->txBdCurrent[0]++; handle->txBdCurrent[0]++;
} }
// lw_print("lw: [%s] ctrl %#x\n", __func__, curBuffDescrip->control);
/* Active the transmit buffer descriptor. */ /* Active the transmit buffer descriptor. */
ENET_ActiveSend(base, 0); ENET_ActiveSend(base, 0);
@ -3130,8 +3102,6 @@ void ENET_ReceiveIRQHandler(ENET_Type *base, enet_handle_t *handle)
assert(handle); assert(handle);
uint32_t mask = kENET_RxFrameInterrupt | kENET_RxBufferInterrupt; uint32_t mask = kENET_RxFrameInterrupt | kENET_RxBufferInterrupt;
lw_print("lw: [%s] input\n", __func__);
/* Check if the receive interrupt happen. */ /* Check if the receive interrupt happen. */
#if FSL_FEATURE_ENET_QUEUE > 1 #if FSL_FEATURE_ENET_QUEUE > 1
switch (ringId) switch (ringId)

View File

@ -1,5 +1,3 @@
SRC_FILES += sys_arch.c \ SRC_FILES += sys_arch.c
tcp_echo_socket_demo.c \
udp_echo.c
include $(KERNEL_ROOT)/compiler.mk include $(KERNEL_ROOT)/compiler.mk