forked from xuos/xiuos
optimize lwip demo and ok1052-c directories
This commit is contained in:
parent
8fa0d977a0
commit
62dcbef383
|
@ -1,3 +1,7 @@
|
|||
menu "connection app"
|
||||
|
||||
menuconfig APPLICATION_CONNECTION
|
||||
bool "Using connection apps"
|
||||
default n
|
||||
|
||||
endmenu
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
SRC_DIR :=
|
||||
|
||||
ifeq ($(CONFIG_RESOURCES_LWIP),y)
|
||||
SRC_DIR += lwip_demo
|
||||
endif
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
|
@ -0,0 +1,3 @@
|
|||
SRC_FILES := ping.c lwip_ping_demo.c udp_echo.c lwip_udp_demo.c lwip_tcp_demo.c tcpecho_raw.c lwip_config_demo.c
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
|
@ -0,0 +1,109 @@
|
|||
/*
|
||||
* Copyright (c) 2016, Freescale Semiconductor, Inc.
|
||||
* Copyright 2016-2019 NXP
|
||||
* All rights reserved.
|
||||
*
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2021 AIIT XUOS Lab
|
||||
* XiUOS is licensed under 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:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* 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,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file lwip_config_demo.c
|
||||
* @brief Demo for ping function
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021.12.15
|
||||
*/
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* Includes
|
||||
******************************************************************************/
|
||||
|
||||
#include "lwip/opt.h"
|
||||
|
||||
#if LWIP_IPV4 && LWIP_RAW
|
||||
|
||||
#include "ping.h"
|
||||
|
||||
#include "lwip/timeouts.h"
|
||||
#include "lwip/init.h"
|
||||
#include "netif/ethernet.h"
|
||||
|
||||
#include "board.h"
|
||||
#include "pin_mux.h"
|
||||
#include "clock_config.h"
|
||||
|
||||
#include <transform.h>
|
||||
#include <sys_arch.h>
|
||||
#include "connect_ethernet.h"
|
||||
#include "lwip_demo.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Prototypes
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Variables
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Code
|
||||
******************************************************************************/
|
||||
|
||||
static void *lwip_config_test(void *param)
|
||||
{
|
||||
ETH_BSP_Config();
|
||||
lwip_config_net(lwip_ipaddr, lwip_netmask, lwip_gwaddr);
|
||||
}
|
||||
|
||||
void lwip_config_thread(int argc, char *argv[])
|
||||
{
|
||||
int result = 0;
|
||||
pthread_t th_id;
|
||||
pthread_attr_t attr;
|
||||
|
||||
attr.schedparam.sched_priority = 15;
|
||||
attr.stacksize = 4096;
|
||||
|
||||
if(argc >= 4)
|
||||
{
|
||||
lw_print("lw: [%s] ip %s mask %s gw %s\n", __func__, argv[1], argv[2], argv[3]);
|
||||
sscanf(argv[1], "%d.%d.%d.%d", &lwip_ipaddr[0], &lwip_ipaddr[1], &lwip_ipaddr[2], &lwip_ipaddr[3]);
|
||||
sscanf(argv[2], "%d.%d.%d.%d", &lwip_netmask[0], &lwip_netmask[1], &lwip_netmask[2], &lwip_netmask[3]);
|
||||
sscanf(argv[3], "%d.%d.%d.%d", &lwip_gwaddr[0], &lwip_gwaddr[1], &lwip_gwaddr[2], &lwip_gwaddr[3]);
|
||||
}
|
||||
else if(argc == 2)
|
||||
{
|
||||
lw_print("lw: [%s] ipaddr %s\n", __func__, argv[1]);
|
||||
sscanf(argv[1], "%d.%d.%d.%d", &lwip_ipaddr[0], &lwip_ipaddr[1], &lwip_ipaddr[2], &lwip_ipaddr[3]);
|
||||
}
|
||||
|
||||
result = pthread_create(&th_id, &attr, lwip_config_test, NULL);
|
||||
if (0 == result) {
|
||||
lw_print("lwip_config_test %d successfully!\n", th_id);
|
||||
} else {
|
||||
lw_print("lwip_config_test failed! error code is %d\n", result);
|
||||
}
|
||||
}
|
||||
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(3),
|
||||
eth, lwip_config_thread, eth [IP] [Netmask] [Gateway]);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,6 @@
|
|||
#ifndef __LWIP_DEMO_H__
|
||||
#define __LWIP_DEMO_H__
|
||||
|
||||
void *eth_input_thread(void *param);
|
||||
|
||||
#endif /* __LWIP_DEMO_H__ */
|
|
@ -0,0 +1,116 @@
|
|||
/*
|
||||
* Copyright (c) 2016, Freescale Semiconductor, Inc.
|
||||
* Copyright 2016-2019 NXP
|
||||
* All rights reserved.
|
||||
*
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2021 AIIT XUOS Lab
|
||||
* XiUOS is licensed under 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:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* 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,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file lwip_ping_demo.c
|
||||
* @brief Demo for ping function
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021.12.15
|
||||
*/
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* Includes
|
||||
******************************************************************************/
|
||||
|
||||
#include "lwip/opt.h"
|
||||
|
||||
#if LWIP_IPV4 && LWIP_RAW
|
||||
|
||||
#include "ping.h"
|
||||
|
||||
#include "lwip/timeouts.h"
|
||||
#include "lwip/init.h"
|
||||
#include "netif/ethernet.h"
|
||||
|
||||
#include "board.h"
|
||||
#include "pin_mux.h"
|
||||
#include "clock_config.h"
|
||||
|
||||
#include <transform.h>
|
||||
#include <sys_arch.h>
|
||||
#include "connect_ethernet.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Prototypes
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Variables
|
||||
******************************************************************************/
|
||||
|
||||
char test_ip_addr[] = {192, 168, 250, 253};
|
||||
char test_net_mask[] = {255, 255, 255, 0};
|
||||
char test_gw_addr[] = {192, 168, 250, 252};
|
||||
ip4_addr_t ping_addr;
|
||||
|
||||
/*******************************************************************************
|
||||
* Code
|
||||
******************************************************************************/
|
||||
|
||||
static void *lwip_ping_test(void *param)
|
||||
{
|
||||
IP4_ADDR(&ping_addr, lwip_gwaddr[0], lwip_gwaddr[1], lwip_gwaddr[2], lwip_gwaddr[3]);
|
||||
ETH_BSP_Config();
|
||||
lwip_config_net(lwip_ipaddr, lwip_netmask, lwip_gwaddr);
|
||||
ping_init(&ping_addr);
|
||||
}
|
||||
|
||||
void lwip_ping_thread(int argc, char *argv[])
|
||||
{
|
||||
int result = 0;
|
||||
pthread_t ping_demo_id = 0;
|
||||
pthread_attr_t attr;
|
||||
attr.schedparam.sched_priority = 15;
|
||||
attr.stacksize = 4096;
|
||||
|
||||
if(argc >= 4)
|
||||
{
|
||||
lw_print("lw: [%s] ip %s mask %s gw %s\n", __func__, argv[1], argv[2], argv[3]);
|
||||
sscanf(argv[1], "%d.%d.%d.%d", &lwip_ipaddr[0], &lwip_ipaddr[1], &lwip_ipaddr[2], &lwip_ipaddr[3]);
|
||||
sscanf(argv[2], "%d.%d.%d.%d", &lwip_netmask[0], &lwip_netmask[1], &lwip_netmask[2], &lwip_netmask[3]);
|
||||
sscanf(argv[3], "%d.%d.%d.%d", &lwip_gwaddr[0], &lwip_gwaddr[1], &lwip_gwaddr[2], &lwip_gwaddr[3]);
|
||||
}
|
||||
else if(argc == 2)
|
||||
{
|
||||
lw_print("lw: [%s] gw %s\n", __func__, argv[1]);
|
||||
sscanf(argv[1], "%d.%d.%d.%d", &lwip_gwaddr[0], &lwip_gwaddr[1], &lwip_gwaddr[2], &lwip_gwaddr[3]);
|
||||
}
|
||||
|
||||
lw_print("lw: [%s] argc %d\n", __func__, argc);
|
||||
|
||||
result = PrivTaskCreate(&ping_demo_id, &attr, lwip_ping_test, NULL);
|
||||
if (0 == result) {
|
||||
lw_print("lwip_setip_test %d successfully!\n", ping_demo_id);
|
||||
} else {
|
||||
lw_print("lwip_setip_test failed! error code is %d\n", result);
|
||||
}
|
||||
}
|
||||
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(3),
|
||||
ping, lwip_ping_thread, lwip_ping_thread);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiUOS is licensed under 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:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* 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,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file tcp_echo_socket_demo.c
|
||||
* @brief One UDP demo based on LwIP
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021-05-29
|
||||
*/
|
||||
#include <transform.h>
|
||||
#include <xiuos.h>
|
||||
#include "board.h"
|
||||
#include "sys_arch.h"
|
||||
#include "tcpecho_raw.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Prototypes
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Variables
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Code
|
||||
******************************************************************************/
|
||||
|
||||
void lwip_tcp_run(void)
|
||||
{
|
||||
ETH_BSP_Config();
|
||||
lwip_config_net(lwip_ipaddr, lwip_netmask, lwip_gwaddr);
|
||||
tcpecho_raw_init();
|
||||
}
|
||||
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(0),
|
||||
LwTcpTest, lwip_tcp_run, TCP raw echo);
|
||||
|
|
@ -0,0 +1,115 @@
|
|||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiUOS is licensed under 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:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* 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,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file tcp_echo_socket_demo.c
|
||||
* @brief One UDP demo based on LwIP
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021-05-29
|
||||
*/
|
||||
#include <transform.h>
|
||||
#include <xiuos.h>
|
||||
#include "board.h"
|
||||
#include "sys_arch.h"
|
||||
#include "udp_echo.h"
|
||||
#include "lwip/udp.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
#define UDP_TASK_STACK_SIZE 4096
|
||||
#define UDP_TASK_PRIO 15
|
||||
|
||||
/*******************************************************************************
|
||||
* Prototypes
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Variables
|
||||
******************************************************************************/
|
||||
|
||||
static struct udp_pcb *udpecho_raw_pcb;
|
||||
|
||||
/*******************************************************************************
|
||||
* Code
|
||||
******************************************************************************/
|
||||
|
||||
static void *lwip_udp_test(void* param)
|
||||
{
|
||||
ETH_BSP_Config();
|
||||
lwip_config_tcp(lwip_ipaddr, lwip_netmask, lwip_gwaddr);
|
||||
UdpEchoInit();
|
||||
}
|
||||
|
||||
void lwip_udp_thread(void)
|
||||
{
|
||||
int result = 0;
|
||||
pthread_t th_id;
|
||||
pthread_attr_t attr;
|
||||
|
||||
attr.schedparam.sched_priority = UDP_TASK_PRIO;
|
||||
attr.stacksize = UDP_TASK_STACK_SIZE;
|
||||
|
||||
result = pthread_create(&th_id, &attr, lwip_udp_test, NULL);
|
||||
if (0 == result) {
|
||||
lw_print("lwip_udp_test successfully!\n");
|
||||
} else {
|
||||
lw_print("lwip_udp_test failed! error code is %d\n", result);
|
||||
}
|
||||
}
|
||||
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(0),
|
||||
LwUdpEcho, lwip_udp_thread, UDP send echo);
|
||||
|
||||
static void
|
||||
udpecho_raw_recv(void *arg, struct udp_pcb *upcb, struct pbuf *p,
|
||||
const ip_addr_t *addr, u16_t port)
|
||||
{
|
||||
LWIP_UNUSED_ARG(arg);
|
||||
if (p != NULL) {
|
||||
/* send received packet back to sender */
|
||||
udp_sendto(upcb, p, addr, port);
|
||||
/* free the pbuf */
|
||||
pbuf_free(p);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
udpecho_raw_init(void)
|
||||
{
|
||||
udpecho_raw_pcb = udp_new_ip_type(IPADDR_TYPE_ANY);
|
||||
if (udpecho_raw_pcb != NULL) {
|
||||
err_t err;
|
||||
|
||||
err = udp_bind(udpecho_raw_pcb, IP_ANY_TYPE, LOCAL_PORT_SERVER);
|
||||
if (err == ERR_OK) {
|
||||
udp_recv(udpecho_raw_pcb, udpecho_raw_recv, NULL);
|
||||
} else {
|
||||
/* abort? output diagnostic? */
|
||||
}
|
||||
} else {
|
||||
/* abort? output diagnostic? */
|
||||
}
|
||||
}
|
||||
|
||||
void lwip_udp_server(void)
|
||||
{
|
||||
ETH_BSP_Config();
|
||||
lwip_config_net(lwip_ipaddr, lwip_netmask, lwip_gwaddr);
|
||||
udpecho_raw_init();
|
||||
}
|
||||
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(0),
|
||||
LwUdpServer, lwip_udp_server, UDP server echo);
|
||||
|
|
@ -245,6 +245,7 @@ ping_thread(void *arg)
|
|||
{
|
||||
int s;
|
||||
int ret;
|
||||
int cnt = 5;
|
||||
|
||||
#if LWIP_SO_SNDRCVTIMEO_NONSTANDARD
|
||||
int timeout = PING_RCV_TIMEO;
|
||||
|
@ -277,7 +278,7 @@ ping_thread(void *arg)
|
|||
LWIP_ASSERT("setting receive timeout failed", ret == 0);
|
||||
LWIP_UNUSED_ARG(ret);
|
||||
|
||||
while (1) {
|
||||
while (cnt --) {
|
||||
if (ping_send(s, ping_target) == ERR_OK) {
|
||||
LWIP_DEBUGF( PING_DEBUG, ("ping: send "));
|
||||
ip_addr_debug_print(PING_DEBUG, ping_target);
|
|
@ -0,0 +1,303 @@
|
|||
/*
|
||||
* 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 and a contribution to the lwIP TCP/IP stack.
|
||||
*
|
||||
* Credits go to Adam Dunkels (and the current maintainers) of this software.
|
||||
*
|
||||
* Christiaan Simons rewrote this file to get a more stable echo example.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* TCP echo server example using raw API.
|
||||
*
|
||||
* Echos all bytes sent by connecting client,
|
||||
* and passively closes when client is done.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "lwip/opt.h"
|
||||
#include "lwip/debug.h"
|
||||
#include "lwip/stats.h"
|
||||
#include "lwip/tcp.h"
|
||||
#include "tcpecho_raw.h"
|
||||
|
||||
#if LWIP_TCP && LWIP_CALLBACK_API
|
||||
|
||||
static struct tcp_pcb *tcpecho_raw_pcb;
|
||||
|
||||
enum tcpecho_raw_states
|
||||
{
|
||||
ES_NONE = 0,
|
||||
ES_ACCEPTED,
|
||||
ES_RECEIVED,
|
||||
ES_CLOSING
|
||||
};
|
||||
|
||||
struct tcpecho_raw_state
|
||||
{
|
||||
u8_t state;
|
||||
u8_t retries;
|
||||
struct tcp_pcb *pcb;
|
||||
/* pbuf (chain) to recycle */
|
||||
struct pbuf *p;
|
||||
};
|
||||
|
||||
static void
|
||||
tcpecho_raw_free(struct tcpecho_raw_state *es)
|
||||
{
|
||||
if (es != NULL) {
|
||||
if (es->p) {
|
||||
/* free the buffer chain if present */
|
||||
pbuf_free(es->p);
|
||||
}
|
||||
|
||||
mem_free(es);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
tcpecho_raw_close(struct tcp_pcb *tpcb, struct tcpecho_raw_state *es)
|
||||
{
|
||||
tcp_arg(tpcb, NULL);
|
||||
tcp_sent(tpcb, NULL);
|
||||
tcp_recv(tpcb, NULL);
|
||||
tcp_err(tpcb, NULL);
|
||||
tcp_poll(tpcb, NULL, 0);
|
||||
|
||||
tcpecho_raw_free(es);
|
||||
|
||||
tcp_close(tpcb);
|
||||
}
|
||||
|
||||
static void
|
||||
tcpecho_raw_send(struct tcp_pcb *tpcb, struct tcpecho_raw_state *es)
|
||||
{
|
||||
struct pbuf *ptr;
|
||||
err_t wr_err = ERR_OK;
|
||||
|
||||
while ((wr_err == ERR_OK) &&
|
||||
(es->p != NULL) &&
|
||||
(es->p->len <= tcp_sndbuf(tpcb))) {
|
||||
ptr = es->p;
|
||||
|
||||
/* enqueue data for transmission */
|
||||
wr_err = tcp_write(tpcb, ptr->payload, ptr->len, 1);
|
||||
if (wr_err == ERR_OK) {
|
||||
u16_t plen;
|
||||
|
||||
plen = ptr->len;
|
||||
/* continue with next pbuf in chain (if any) */
|
||||
es->p = ptr->next;
|
||||
if(es->p != NULL) {
|
||||
/* new reference! */
|
||||
pbuf_ref(es->p);
|
||||
}
|
||||
/* chop first pbuf from chain */
|
||||
pbuf_free(ptr);
|
||||
/* we can read more data now */
|
||||
tcp_recved(tpcb, plen);
|
||||
} else if(wr_err == ERR_MEM) {
|
||||
/* we are low on memory, try later / harder, defer to poll */
|
||||
es->p = ptr;
|
||||
} else {
|
||||
/* other problem ?? */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
tcpecho_raw_error(void *arg, err_t err)
|
||||
{
|
||||
struct tcpecho_raw_state *es;
|
||||
|
||||
LWIP_UNUSED_ARG(err);
|
||||
|
||||
es = (struct tcpecho_raw_state *)arg;
|
||||
|
||||
tcpecho_raw_free(es);
|
||||
}
|
||||
|
||||
static err_t
|
||||
tcpecho_raw_poll(void *arg, struct tcp_pcb *tpcb)
|
||||
{
|
||||
err_t ret_err;
|
||||
struct tcpecho_raw_state *es;
|
||||
|
||||
es = (struct tcpecho_raw_state *)arg;
|
||||
if (es != NULL) {
|
||||
if (es->p != NULL) {
|
||||
/* there is a remaining pbuf (chain) */
|
||||
tcpecho_raw_send(tpcb, es);
|
||||
} else {
|
||||
/* no remaining pbuf (chain) */
|
||||
if(es->state == ES_CLOSING) {
|
||||
tcpecho_raw_close(tpcb, es);
|
||||
}
|
||||
}
|
||||
ret_err = ERR_OK;
|
||||
} else {
|
||||
/* nothing to be done */
|
||||
tcp_abort(tpcb);
|
||||
ret_err = ERR_ABRT;
|
||||
}
|
||||
return ret_err;
|
||||
}
|
||||
|
||||
static err_t
|
||||
tcpecho_raw_sent(void *arg, struct tcp_pcb *tpcb, u16_t len)
|
||||
{
|
||||
struct tcpecho_raw_state *es;
|
||||
|
||||
LWIP_UNUSED_ARG(len);
|
||||
|
||||
es = (struct tcpecho_raw_state *)arg;
|
||||
es->retries = 0;
|
||||
|
||||
if(es->p != NULL) {
|
||||
/* still got pbufs to send */
|
||||
tcp_sent(tpcb, tcpecho_raw_sent);
|
||||
tcpecho_raw_send(tpcb, es);
|
||||
} else {
|
||||
/* no more pbufs to send */
|
||||
if(es->state == ES_CLOSING) {
|
||||
tcpecho_raw_close(tpcb, es);
|
||||
}
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
static err_t
|
||||
tcpecho_raw_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)
|
||||
{
|
||||
struct tcpecho_raw_state *es;
|
||||
err_t ret_err;
|
||||
|
||||
LWIP_ASSERT("arg != NULL",arg != NULL);
|
||||
es = (struct tcpecho_raw_state *)arg;
|
||||
if (p == NULL) {
|
||||
/* remote host closed connection */
|
||||
es->state = ES_CLOSING;
|
||||
if(es->p == NULL) {
|
||||
/* we're done sending, close it */
|
||||
tcpecho_raw_close(tpcb, es);
|
||||
} else {
|
||||
/* we're not done yet */
|
||||
tcpecho_raw_send(tpcb, es);
|
||||
}
|
||||
ret_err = ERR_OK;
|
||||
} else if(err != ERR_OK) {
|
||||
/* cleanup, for unknown reason */
|
||||
if (p != NULL) {
|
||||
pbuf_free(p);
|
||||
}
|
||||
ret_err = err;
|
||||
}
|
||||
else if(es->state == ES_ACCEPTED) {
|
||||
/* first data chunk in p->payload */
|
||||
es->state = ES_RECEIVED;
|
||||
/* store reference to incoming pbuf (chain) */
|
||||
es->p = p;
|
||||
tcpecho_raw_send(tpcb, es);
|
||||
ret_err = ERR_OK;
|
||||
} else if (es->state == ES_RECEIVED) {
|
||||
/* read some more data */
|
||||
if(es->p == NULL) {
|
||||
es->p = p;
|
||||
tcpecho_raw_send(tpcb, es);
|
||||
} else {
|
||||
struct pbuf *ptr;
|
||||
|
||||
/* chain pbufs to the end of what we recv'ed previously */
|
||||
ptr = es->p;
|
||||
pbuf_cat(ptr,p);
|
||||
}
|
||||
ret_err = ERR_OK;
|
||||
} else {
|
||||
/* unkown es->state, trash data */
|
||||
tcp_recved(tpcb, p->tot_len);
|
||||
pbuf_free(p);
|
||||
ret_err = ERR_OK;
|
||||
}
|
||||
return ret_err;
|
||||
}
|
||||
|
||||
static err_t
|
||||
tcpecho_raw_accept(void *arg, struct tcp_pcb *newpcb, err_t err)
|
||||
{
|
||||
err_t ret_err;
|
||||
struct tcpecho_raw_state *es;
|
||||
|
||||
LWIP_UNUSED_ARG(arg);
|
||||
if ((err != ERR_OK) || (newpcb == NULL)) {
|
||||
return ERR_VAL;
|
||||
}
|
||||
|
||||
/* Unless this pcb should have NORMAL priority, set its priority now.
|
||||
When running out of pcbs, low priority pcbs can be aborted to create
|
||||
new pcbs of higher priority. */
|
||||
tcp_setprio(newpcb, TCP_PRIO_MIN);
|
||||
|
||||
es = (struct tcpecho_raw_state *)mem_malloc(sizeof(struct tcpecho_raw_state));
|
||||
if (es != NULL) {
|
||||
es->state = ES_ACCEPTED;
|
||||
es->pcb = newpcb;
|
||||
es->retries = 0;
|
||||
es->p = NULL;
|
||||
/* pass newly allocated es to our callbacks */
|
||||
tcp_arg(newpcb, es);
|
||||
tcp_recv(newpcb, tcpecho_raw_recv);
|
||||
tcp_err(newpcb, tcpecho_raw_error);
|
||||
tcp_poll(newpcb, tcpecho_raw_poll, 0);
|
||||
tcp_sent(newpcb, tcpecho_raw_sent);
|
||||
ret_err = ERR_OK;
|
||||
} else {
|
||||
ret_err = ERR_MEM;
|
||||
}
|
||||
return ret_err;
|
||||
}
|
||||
|
||||
void
|
||||
tcpecho_raw_init(void)
|
||||
{
|
||||
tcpecho_raw_pcb = tcp_new_ip_type(IPADDR_TYPE_ANY);
|
||||
if (tcpecho_raw_pcb != NULL) {
|
||||
err_t err;
|
||||
//tst by wly
|
||||
err = tcp_bind(tcpecho_raw_pcb, IP_ANY_TYPE, 4840);
|
||||
if (err == ERR_OK) {
|
||||
tcpecho_raw_pcb = tcp_listen(tcpecho_raw_pcb);
|
||||
tcp_accept(tcpecho_raw_pcb, tcpecho_raw_accept);
|
||||
} else {
|
||||
/* abort? output diagnostic? */
|
||||
}
|
||||
} else {
|
||||
/* abort? output diagnostic? */
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* LWIP_TCP && LWIP_CALLBACK_API */
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
#ifndef LWIP_TCPECHO_RAW_H
|
||||
#define LWIP_TCPECHO_RAW_H
|
||||
|
||||
void tcpecho_raw_init(void);
|
||||
|
||||
#endif /* LWIP_TCPECHO_RAW_H */
|
17
APP_Framework/Applications/control_app/lwip_demo/udp_echo.c → APP_Framework/Applications/connection_app/lwip_demo/udp_echo.c
Normal file → Executable file
17
APP_Framework/Applications/control_app/lwip_demo/udp_echo.c → APP_Framework/Applications/connection_app/lwip_demo/udp_echo.c
Normal file → Executable file
|
@ -51,15 +51,12 @@
|
|||
*/
|
||||
|
||||
#include "udp_echo.h"
|
||||
|
||||
#include <transform.h>
|
||||
#include "lwip/opt.h"
|
||||
|
||||
#if LWIP_SOCKET
|
||||
#include <lwip/sockets.h>
|
||||
|
||||
#include "lwip/sys.h"
|
||||
#include "lwip/api.h"
|
||||
#include <xs_ktask.h>
|
||||
|
||||
#ifdef BOARD_CORTEX_M7_EVB
|
||||
#define LWIP_UDP_TASK_STACK 4096
|
||||
|
@ -67,6 +64,8 @@
|
|||
#define LWIP_UDP_TASK_STACK 2048
|
||||
#endif
|
||||
|
||||
#define LWIP_UDP_TASK_PRIO 25
|
||||
|
||||
#define RECV_DATA (1024)
|
||||
|
||||
char* send_msg = "\n\nThis one is UDP pkg. Congratulations on you.\n\n";
|
||||
|
@ -137,6 +136,7 @@ __exit:
|
|||
|
||||
static void UdpEchoThreadClient(void *arg)
|
||||
{
|
||||
int cnt = 5;
|
||||
KPrintf("UdpEchoThreadClient start.\n");
|
||||
|
||||
int sock_udp_send_once = -1;
|
||||
|
@ -159,10 +159,10 @@ static void UdpEchoThreadClient(void *arg)
|
|||
goto __exit;
|
||||
}
|
||||
|
||||
KPrintf("UDP connect sucess, start to send.\n");
|
||||
KPrintf("UDP connect success, start to send.\n");
|
||||
KPrintf("\n\nTarget Port:%d\n\n", udp_sock.sin_port);
|
||||
|
||||
while (1)
|
||||
while (cnt --)
|
||||
{
|
||||
KPrintf("Lwip client is running.\n");
|
||||
|
||||
|
@ -175,6 +175,7 @@ static void UdpEchoThreadClient(void *arg)
|
|||
|
||||
MdelayKTask(1000);
|
||||
}
|
||||
return;
|
||||
|
||||
__exit:
|
||||
if (sock_udp_send_once >= 0) closesocket(sock_udp_send_once);
|
||||
|
@ -186,9 +187,9 @@ void
|
|||
UdpEchoInit(void)
|
||||
{
|
||||
#ifdef SET_AS_SERVER
|
||||
sys_thread_new("UdpEchoThreadServer", UdpEchoThreadServer, NULL, LWIP_UDP_TASK_STACK, 4);
|
||||
sys_thread_new("UdpEchoThreadServer", UdpEchoThreadServer, NULL, LWIP_UDP_TASK_STACK, LWIP_UDP_TASK_PRIO);
|
||||
#else
|
||||
sys_thread_new("UdpEchoThreadClient", UdpEchoThreadClient, NULL, LWIP_UDP_TASK_STACK, 4);
|
||||
sys_thread_new("UdpEchoThreadClient", UdpEchoThreadClient, NULL, LWIP_UDP_TASK_STACK, LWIP_UDP_TASK_PRIO);
|
||||
#endif
|
||||
}
|
||||
|
0
APP_Framework/Applications/control_app/lwip_demo/udp_echo.h → APP_Framework/Applications/connection_app/lwip_demo/udp_echo.h
Normal file → Executable file
0
APP_Framework/Applications/control_app/lwip_demo/udp_echo.h → APP_Framework/Applications/connection_app/lwip_demo/udp_echo.h
Normal file → Executable file
|
@ -1,7 +1,6 @@
|
|||
SRC_DIR :=
|
||||
|
||||
ifeq ($(CONFIG_RESOURCES_LWIP),y)
|
||||
SRC_DIR += lwip_demo
|
||||
|
||||
ifeq ($(CONFIG_USING_CONTROL_PLC_OPCUA), y)
|
||||
SRC_DIR += opcua_demo
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
SRC_FILES := ping.c lwip_ping_demo.c udp_echo.c lwip_udp_demo.c
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
|
@ -1,176 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2016, Freescale Semiconductor, Inc.
|
||||
* Copyright 2016-2019 NXP
|
||||
* All rights reserved.
|
||||
*
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2021 AIIT XUOS Lab
|
||||
* XiUOS is licensed under 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:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* 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,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file lwip_ping_demo.c
|
||||
* @brief Demo for ping function
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021.12.15
|
||||
*/
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* Includes
|
||||
******************************************************************************/
|
||||
|
||||
#include <transform.h>
|
||||
#include "lwip/opt.h"
|
||||
|
||||
#if LWIP_IPV4 && LWIP_RAW
|
||||
|
||||
#include "ping.h"
|
||||
|
||||
#include "lwip/timeouts.h"
|
||||
#include "lwip/init.h"
|
||||
#include "netif/ethernet.h"
|
||||
|
||||
#include "board.h"
|
||||
|
||||
#include "pin_mux.h"
|
||||
#include "clock_config.h"
|
||||
|
||||
#include <transform.h>
|
||||
#include <sys_arch.h>
|
||||
#include "connect_ethernet.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
/* IP address configuration. */
|
||||
#define TEST_IP_ADDR0 192
|
||||
#define TEST_IP_ADDR1 168
|
||||
#define TEST_IP_ADDR2 250
|
||||
#define TEST_IP_ADDR3 253
|
||||
|
||||
/* Netmask configuration. */
|
||||
#define TEST_NET_MASK0 255
|
||||
#define TEST_NET_MASK1 255
|
||||
#define TEST_NET_MASK2 255
|
||||
#define TEST_NET_MASK3 0
|
||||
|
||||
/* Gateway address configuration. */
|
||||
#define TEST_GW_ADDR0 192
|
||||
#define TEST_GW_ADDR1 168
|
||||
#define TEST_GW_ADDR2 250
|
||||
#define TEST_GW_ADDR3 252
|
||||
|
||||
/* MAC address configuration. */
|
||||
#define TEST_MAC_ADDR {0x02, 0x12, 0x13, 0x10, 0x15, 0x11}
|
||||
|
||||
/* Address of PHY interface. */
|
||||
#define TEST_PHY_ADDR 0x02U
|
||||
|
||||
/* System clock name. */
|
||||
#define TEST_CLOCK_NAME kCLOCK_CoreSysClk
|
||||
|
||||
/*******************************************************************************
|
||||
* Prototypes
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Variables
|
||||
******************************************************************************/
|
||||
|
||||
static pthread_t ping_demo_id = 0;
|
||||
|
||||
/*******************************************************************************
|
||||
* Code
|
||||
******************************************************************************/
|
||||
|
||||
/*!
|
||||
* @brief Main function.
|
||||
*/
|
||||
static void *lwip_ping_test(void *param)
|
||||
{
|
||||
struct netif fsl_netif0;
|
||||
#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;
|
||||
#endif /* FSL_FEATURE_SOC_LPC_ENET_COUNT */
|
||||
ip4_addr_t fsl_netif0_ipaddr, fsl_netif0_netmask, fsl_netif0_gw;
|
||||
ethernetif_config_t fsl_enet_config0 = {
|
||||
.phyAddress = TEST_PHY_ADDR,
|
||||
.clockName = TEST_CLOCK_NAME,
|
||||
.macAddress = TEST_MAC_ADDR,
|
||||
#if defined(FSL_FEATURE_SOC_LPC_ENET_COUNT) && (FSL_FEATURE_SOC_LPC_ENET_COUNT > 0)
|
||||
.non_dma_memory = non_dma_memory,
|
||||
#endif /* FSL_FEATURE_SOC_LPC_ENET_COUNT */
|
||||
};
|
||||
|
||||
lw_print("lw: [%s] start ...\n", __func__);
|
||||
|
||||
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_gw, TEST_GW_ADDR0, TEST_GW_ADDR1, TEST_GW_ADDR2, TEST_GW_ADDR3);
|
||||
|
||||
lwip_init();
|
||||
|
||||
netif_add(&fsl_netif0, &fsl_netif0_ipaddr, &fsl_netif0_netmask, &fsl_netif0_gw, &fsl_enet_config0,
|
||||
ethernetif0_init,
|
||||
ethernet_input);
|
||||
netif_set_default(&fsl_netif0);
|
||||
netif_set_up(&fsl_netif0);
|
||||
|
||||
lw_print("\r\n************************************************\r\n");
|
||||
lw_print(" PING example\r\n");
|
||||
lw_print("************************************************\r\n");
|
||||
lw_print(" IPv4 Address : %u.%u.%u.%u\r\n", ((u8_t *)&fsl_netif0_ipaddr)[0], ((u8_t *)&fsl_netif0_ipaddr)[1],
|
||||
((u8_t *)&fsl_netif0_ipaddr)[2], ((u8_t *)&fsl_netif0_ipaddr)[3]);
|
||||
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_netmask)[2], ((u8_t *)&fsl_netif0_netmask)[3]);
|
||||
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_gw)[2], ((u8_t *)&fsl_netif0_gw)[3]);
|
||||
lw_print("************************************************\r\n");
|
||||
|
||||
ping_init(&fsl_netif0_gw);
|
||||
|
||||
while (1)
|
||||
{
|
||||
/* Poll the driver, get any outstanding frames */
|
||||
ethernetif_input(&fsl_netif0);
|
||||
sys_check_timeouts(); /* Handle all system timeouts for all core protocols */
|
||||
}
|
||||
}
|
||||
|
||||
void lwip_ping_thread(void)
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
pthread_attr_t attr;
|
||||
|
||||
attr.schedparam.sched_priority = 15;
|
||||
attr.stacksize = 4096;
|
||||
|
||||
result = pthread_create(&ping_demo_id, &attr, lwip_ping_test, NULL);
|
||||
if (0 == result) {
|
||||
lw_print("lwip_ping_test successfully!\n");
|
||||
} else {
|
||||
lw_print("lwip_ping_test failed! error code is %d\n", result);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(0),
|
||||
LwPingTest, lwip_ping_thread, lwip_ping_thread);
|
||||
|
||||
#endif
|
|
@ -1,65 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiUOS is licensed under 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:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* 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,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file tcp_echo_socket_demo.c
|
||||
* @brief One UDP demo based on LwIP
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021-05-29
|
||||
*/
|
||||
|
||||
#include <xiuos.h>
|
||||
#include "board.h"
|
||||
#include "udp_echo.h"
|
||||
#include <connect_ethernet.h>
|
||||
|
||||
#define UDP_TASK_STACK_SIZE 2048
|
||||
|
||||
extern void TcpIpInit(void);
|
||||
extern char* send_msg;
|
||||
|
||||
static void NetStackTaskCreate(void* param)
|
||||
{
|
||||
TcpIpInit();
|
||||
UdpEchoInit();
|
||||
}
|
||||
|
||||
int LwipUdpDemo(int argc, char *argv[])
|
||||
{
|
||||
if (argc == 2)
|
||||
{
|
||||
send_msg = argv[1];
|
||||
}
|
||||
|
||||
ETH_BSP_Config();
|
||||
|
||||
int32 thr_id = KTaskCreate(
|
||||
(const char* )"NetStackTaskCreate",
|
||||
NetStackTaskCreate,
|
||||
(void* )NULL,
|
||||
(uint16_t )UDP_TASK_STACK_SIZE,
|
||||
15);
|
||||
|
||||
if(thr_id >= 0)
|
||||
StartupKTask(thr_id);
|
||||
else{
|
||||
KPrintf("NetStackTaskCreate create failed !\n");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifndef SEPARATE_COMPILE
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
|
||||
UdpTest, LwipUdpDemo, UDP socket demo function);
|
||||
#endif
|
|
@ -20,197 +20,46 @@
|
|||
|
||||
#include <list.h>
|
||||
#include <transform.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
#include <lwip/altcp.h>
|
||||
#include "netif/ethernet.h"
|
||||
|
||||
#include "board.h"
|
||||
#include <lwip/altcp.h>
|
||||
#include "open62541.h"
|
||||
#include "ua_api.h"
|
||||
|
||||
typedef unsigned int nfds_t;
|
||||
#include "../../../../APP_Framework/Framework/control/plc/interoperability/opcua/open62541.h"
|
||||
|
||||
#define ua_print printf
|
||||
#define ua_trace() printf("ua: [%s] %d pass!\n", __func__, __LINE__)
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
//#define ua_print KPrintf
|
||||
#define ua_trace() KPrintf("ua: [%s] %d pass!\n", __func__, __LINE__)
|
||||
|
||||
#define TCP_LOCAL_PORT 4840
|
||||
|
||||
/* IP address configuration. */
|
||||
#define configIP_ADDR0 192
|
||||
#define configIP_ADDR1 168
|
||||
#define configIP_ADDR2 250
|
||||
#define configIP_ADDR3 253
|
||||
/*******************************************************************************
|
||||
* Prototypes
|
||||
******************************************************************************/
|
||||
|
||||
/* Netmask configuration. */
|
||||
#define configNET_MASK0 255
|
||||
#define configNET_MASK1 255
|
||||
#define configNET_MASK2 255
|
||||
#define configNET_MASK3 0
|
||||
|
||||
/* Gateway address configuration. */
|
||||
#define configGW_ADDR0 192
|
||||
#define configGW_ADDR1 168
|
||||
#define configGW_ADDR2 250
|
||||
#define configGW_ADDR3 252
|
||||
|
||||
/* MAC address configuration. */
|
||||
#define configMAC_ADDR { 0x02, 0x12, 0x13, 0x10, 0x15, 0x11}
|
||||
|
||||
/* ENET PHY address. */
|
||||
#define BOARD_ENET0_PHY_ADDRESS (0x02U) /* Phy address of enet port 0. */
|
||||
|
||||
/* Address of PHY interface. */
|
||||
#define EXAMPLE_PHY_ADDRESS BOARD_ENET0_PHY_ADDRESS
|
||||
|
||||
/* System clock name. */
|
||||
#define EXAMPLE_CLOCK_NAME kCLOCK_CoreSysClk
|
||||
/*******************************************************************************
|
||||
* Variables
|
||||
******************************************************************************/
|
||||
|
||||
const char *test_uri = "opc.tcp://192.168.250.5:4840";
|
||||
const char *test_cb_str = "tcp client connected\r\n";
|
||||
|
||||
char test_ua_gw[] = {192, 168, 250, 5};
|
||||
|
||||
void ua_ip_init(void)
|
||||
{
|
||||
#ifdef BOARD_CORTEX_M7_EVB
|
||||
struct netif fsl_netif0;
|
||||
#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;
|
||||
#endif /* FSL_FEATURE_SOC_LPC_ENET_COUNT */
|
||||
ip4_addr_t fsl_netif0_ipaddr, fsl_netif0_netmask, fsl_netif0_gw;
|
||||
ethernetif_config_t fsl_enet_config0 = {
|
||||
.phyAddress = EXAMPLE_PHY_ADDRESS,
|
||||
.clockName = EXAMPLE_CLOCK_NAME,
|
||||
.macAddress = configMAC_ADDR,
|
||||
#if defined(FSL_FEATURE_SOC_LPC_ENET_COUNT) && (FSL_FEATURE_SOC_LPC_ENET_COUNT > 0)
|
||||
.non_dma_memory = non_dma_memory,
|
||||
#endif /* FSL_FEATURE_SOC_LPC_ENET_COUNT */
|
||||
};
|
||||
|
||||
ua_print("lw: [%s] start ...\n", __func__);
|
||||
|
||||
IP4_ADDR(&fsl_netif0_ipaddr, configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3);
|
||||
IP4_ADDR(&fsl_netif0_netmask, configNET_MASK0, configNET_MASK1, configNET_MASK2, configNET_MASK3);
|
||||
IP4_ADDR(&fsl_netif0_gw, configGW_ADDR0, configGW_ADDR1, configGW_ADDR2, configGW_ADDR3);
|
||||
|
||||
lwip_init();
|
||||
|
||||
netif_add(&fsl_netif0, &fsl_netif0_ipaddr, &fsl_netif0_netmask, &fsl_netif0_gw, &fsl_enet_config0, ethernetif0_init,
|
||||
ethernet_input);
|
||||
netif_set_default(&fsl_netif0);
|
||||
netif_set_up(&fsl_netif0);
|
||||
|
||||
ua_print("\r\n************************************************\r\n");
|
||||
ua_print(" PING example\r\n");
|
||||
ua_print("************************************************\r\n");
|
||||
ua_print(" IPv4 Address : %u.%u.%u.%u\r\n", ((u8_t *)&fsl_netif0_ipaddr)[0], ((u8_t *)&fsl_netif0_ipaddr)[1],
|
||||
((u8_t *)&fsl_netif0_ipaddr)[2], ((u8_t *)&fsl_netif0_ipaddr)[3]);
|
||||
ua_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_netmask)[2], ((u8_t *)&fsl_netif0_netmask)[3]);
|
||||
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]);
|
||||
ua_print("************************************************\r\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
// tcp client callback
|
||||
static err_t TcpClientCallback(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)
|
||||
{
|
||||
uint32_t i;
|
||||
|
||||
if (p != NULL)
|
||||
{
|
||||
struct pbuf *ptmp = p;
|
||||
|
||||
ua_print("get msg from %d:%d:%d:%d port:%d:\r\n",
|
||||
*((uint8_t *)&tpcb->remote_ip.addr),
|
||||
*((uint8_t *)&tpcb->remote_ip.addr + 1),
|
||||
*((uint8_t *)&tpcb->remote_ip.addr + 2),
|
||||
*((uint8_t *)&tpcb->remote_ip.addr + 3),
|
||||
tpcb->remote_port);
|
||||
|
||||
while (ptmp != NULL)
|
||||
{
|
||||
for (i = 0; i < p->len; i++)
|
||||
{
|
||||
ua_print("%c", *((char *)p->payload + i));
|
||||
}
|
||||
|
||||
ptmp = p->next;
|
||||
}
|
||||
ua_print("\r\n");
|
||||
tcp_recved(tpcb, p->tot_len);
|
||||
pbuf_free(p);
|
||||
}
|
||||
else if (err == ERR_OK)
|
||||
{
|
||||
ua_print("tcp: tcp client closed\r\n");
|
||||
tcp_recved(tpcb, p->tot_len);
|
||||
return tcp_close(tpcb);
|
||||
}
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
// connect callback function
|
||||
static err_t TcpClientConnected(void *arg, struct tcp_pcb *tpcb, err_t err)
|
||||
{
|
||||
ua_print(test_cb_str);
|
||||
tcp_write(tpcb, test_cb_str, strlen(test_cb_str), 0);
|
||||
tcp_recv(tpcb, TcpClientCallback);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
void ua_set_ip(void *param)
|
||||
{
|
||||
struct tcp_pcb *tpcb = NULL;
|
||||
err_t err;
|
||||
|
||||
ua_print("ua: [%s] start test\n", __func__);
|
||||
|
||||
ua_ip_init();
|
||||
|
||||
tpcb = tcp_new();
|
||||
if (tpcb == NULL)
|
||||
{
|
||||
ua_print("ua: [%s] tcp pcb null\n", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
ua_print("ua: [%s] tcp bind port %d\n", __func__, TCP_LOCAL_PORT);
|
||||
|
||||
/* bind local port and ip addresss*/
|
||||
err = tcp_bind(tpcb, IP_ADDR_ANY, TCP_LOCAL_PORT);
|
||||
|
||||
if (err != ERR_OK)
|
||||
{
|
||||
memp_free(MEMP_TCP_PCB, tpcb);
|
||||
ua_print("ua: [%s] can not bind pcb\n", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
ua_print("ua: [%s] start tcp...\n", __func__);
|
||||
}
|
||||
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(0),
|
||||
UaSetIp, ua_set_ip, ua_set_ip);
|
||||
|
||||
void TestUaConnect(int argc, char *argv[])
|
||||
static pthread_t eth_input_id = 0;
|
||||
static pthread_t ua_demo_id;
|
||||
|
||||
/*******************************************************************************
|
||||
* Code
|
||||
******************************************************************************/
|
||||
|
||||
void *test_ua_get_server_info(void *param);
|
||||
|
||||
static void test_ua_connect(void *arg)
|
||||
{
|
||||
struct netif net;
|
||||
UA_StatusCode retval;
|
||||
|
||||
char ua_msg[128];
|
||||
int len;
|
||||
if (argc >= 1)
|
||||
{
|
||||
memset(ua_msg, 0, 128);
|
||||
strncpy(ua_msg, argv[1], (len = strlen(argv[1])));
|
||||
ua_print("ua: [%s] start\n", __func__);
|
||||
}
|
||||
|
||||
ua_set_ip(NULL);
|
||||
|
||||
UA_Client *client = UA_Client_new();
|
||||
|
||||
if (client == NULL)
|
||||
|
@ -222,16 +71,96 @@ void TestUaConnect(int argc, char *argv[])
|
|||
UA_ClientConfig *config = UA_Client_getConfig(client);
|
||||
UA_ClientConfig_setDefault(config);
|
||||
|
||||
|
||||
ua_print("cfg ------>\n");
|
||||
|
||||
retval = UA_Client_connect(client, test_uri);
|
||||
if (retval != UA_STATUSCODE_GOOD)
|
||||
{
|
||||
ua_print("ua: [%s] ret %x\n", __func__, retval);
|
||||
UA_Client_delete(client);
|
||||
return;
|
||||
ua_print("tcp: tcp client closed\r\n");
|
||||
tcp_recved(tpcb, p->tot_len);
|
||||
return tcp_close(tpcb);
|
||||
}
|
||||
ua_print("ua: [%s] start Ua Test!\n", __func__);
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
void test_ua_connect_thr(void *arg)
|
||||
{
|
||||
ETH_BSP_Config();
|
||||
lwip_config_tcp(lwip_ipaddr, lwip_netmask, test_ua_gw);
|
||||
test_ua_connect(NULL);
|
||||
}
|
||||
|
||||
void test_sh_ua_connect(void)
|
||||
{
|
||||
int result = 0;
|
||||
pthread_t th_id;
|
||||
pthread_attr_t attr;
|
||||
|
||||
sys_thread_new("ua test", test_ua_connect_thr, NULL, 4096, 15);
|
||||
}
|
||||
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(0),
|
||||
UaConnect, TestUaConnect, TestUaConnect);
|
||||
UaConnect, test_sh_ua_connect, Test Opc UA connection);
|
||||
|
||||
void *test_ua_get_server_info(void *param)
|
||||
{
|
||||
UA_Client *client = UA_Client_new();
|
||||
|
||||
ua_print("ua: [%s] start ...\n", __func__);
|
||||
|
||||
if (client == NULL)
|
||||
{
|
||||
ua_print("ua: [%s] tcp client null\n", __func__);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
UA_ClientConfig *config = UA_Client_getConfig(client);
|
||||
UA_ClientConfig_setDefault(config);
|
||||
|
||||
UA_StatusCode retval = UA_Client_connect(client, OPC_SERVER);
|
||||
if(retval != UA_STATUSCODE_GOOD) {
|
||||
ua_print("ua: [%s] connect failed %d\n", __func__, retval);
|
||||
UA_Client_delete(client);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ua_print("ua: [%s] connect ok!\n", __func__);
|
||||
|
||||
while(1)
|
||||
{
|
||||
ua_read_time(client);
|
||||
ua_get_server_info(client);
|
||||
}
|
||||
/* Clean up */
|
||||
// UA_Client_disconnect(client);
|
||||
// UA_Client_delete(client); /* Disconnects the client internally */
|
||||
}
|
||||
|
||||
void *test_ua_get_server_info_thr(void *arg)
|
||||
{
|
||||
ETH_BSP_Config();
|
||||
lwip_config_tcp(lwip_ipaddr, lwip_netmask, test_ua_gw);
|
||||
test_ua_get_server_info(NULL);
|
||||
}
|
||||
|
||||
void *test_sh_ua_get_server_info(void *param)
|
||||
{
|
||||
int result = 0;
|
||||
pthread_attr_t attr;
|
||||
|
||||
attr.schedparam.sched_priority = 15;
|
||||
attr.stacksize = 4096;
|
||||
|
||||
result = pthread_create(&ua_demo_id, &attr, test_ua_get_server_info_thr, NULL);
|
||||
if (0 == result) {
|
||||
lw_print("test_ua_get_server_info %d successfully!\n", __func__, ua_demo_id);
|
||||
} else {
|
||||
lw_print("test_ua_get_server_info failed! error code is %d\n", __func__, result);
|
||||
}
|
||||
}
|
||||
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(0),
|
||||
UaGetInfo, test_sh_ua_get_server_info, Get information from OpcUA server);
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
SRC_DIR := third_party_driver
|
||||
SRC_DIR := third_party_driver
|
||||
|
||||
SRC_FILES := board.c clock_config.c pin_mux.c
|
||||
SRC_FILES := board.c
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
0
Ubiquitous/XiUOS/board/ok1052-c/board.h → Ubiquitous/XiUOS/board/ok1052-c/include/board.h
Normal file → Executable file
0
Ubiquitous/XiUOS/board/ok1052-c/board.h → Ubiquitous/XiUOS/board/ok1052-c/include/board.h
Normal file → Executable file
0
Ubiquitous/XiUOS/board/ok1052-c/clock_config.h → Ubiquitous/XiUOS/board/ok1052-c/include/clock_config.h
Normal file → Executable file
0
Ubiquitous/XiUOS/board/ok1052-c/clock_config.h → Ubiquitous/XiUOS/board/ok1052-c/include/clock_config.h
Normal file → Executable file
0
Ubiquitous/XiUOS/board/ok1052-c/pin_mux.h → Ubiquitous/XiUOS/board/ok1052-c/include/pin_mux.h
Normal file → Executable file
0
Ubiquitous/XiUOS/board/ok1052-c/pin_mux.h → Ubiquitous/XiUOS/board/ok1052-c/include/pin_mux.h
Normal file → Executable file
|
@ -1,6 +0,0 @@
|
|||
SRC_DIR := drivers
|
||||
|
||||
SRC_FILES := system_MIMXRT1052.c
|
||||
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
|
@ -1,5 +0,0 @@
|
|||
|
||||
SRC_FILES := fsl_cache.c fsl_clock.c fsl_common.c fsl_lpuart.c fsl_enet.c fsl_gpio.c fsl_phy.c
|
||||
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
|
@ -1,4 +1,4 @@
|
|||
SRC_DIR := MIMXRT1052
|
||||
SRC_DIR := common gpio
|
||||
|
||||
ifeq ($(CONFIG_BSP_USING_LPUART),y)
|
||||
SRC_DIR += uart
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
SRC_FILES := system_MIMXRT1052.c fsl_cache.c fsl_clock.c fsl_common.c pin_mux.c clock_config.c
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
0
Ubiquitous/XiUOS/board/ok1052-c/clock_config.c → Ubiquitous/XiUOS/board/ok1052-c/third_party_driver/common/clock_config.c
Normal file → Executable file
0
Ubiquitous/XiUOS/board/ok1052-c/clock_config.c → Ubiquitous/XiUOS/board/ok1052-c/third_party_driver/common/clock_config.c
Normal file → Executable file
0
Ubiquitous/XiUOS/board/ok1052-c/pin_mux.c → Ubiquitous/XiUOS/board/ok1052-c/third_party_driver/common/pin_mux.c
Normal file → Executable file
0
Ubiquitous/XiUOS/board/ok1052-c/pin_mux.c → Ubiquitous/XiUOS/board/ok1052-c/third_party_driver/common/pin_mux.c
Normal file → Executable file
|
@ -1,3 +1,3 @@
|
|||
SRC_FILES := enet_ethernetif.c enet_ethernetif_kinetis.c
|
||||
|
||||
SRC_FILES := enet_ethernetif.c enet_ethernetif_kinetis.c fsl_enet.c
|
||||
SRC_DIR := ksz8081
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
|
@ -206,6 +206,7 @@ void ethernetif_phy_init(struct ethernetif *ethernetif,
|
|||
void ethernetif_input(struct netif *netif)
|
||||
{
|
||||
struct pbuf *p;
|
||||
err_t ret = 0;
|
||||
|
||||
LWIP_ASSERT("netif != NULL", (netif != NULL));
|
||||
|
||||
|
@ -213,9 +214,10 @@ void ethernetif_input(struct netif *netif)
|
|||
while ((p = ethernetif_linkinput(netif)) != NULL)
|
||||
{
|
||||
/* pass all packets to ethernet_input, which decides what packets it supports */
|
||||
if (netif->input(p, netif) != ERR_OK)
|
||||
if ((ret = netif->input(p, netif)) != ERR_OK)
|
||||
{
|
||||
LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n"));
|
||||
// LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n"));
|
||||
lw_print("lw: [%s] ret %d p %p\n", __func__, ret, p);
|
||||
pbuf_free(p);
|
||||
p = NULL;
|
||||
}
|
||||
|
@ -287,7 +289,7 @@ err_t ethernetif_init(struct netif *netif, struct ethernetif *ethernetif,
|
|||
|
||||
/* Init ethernetif parameters.*/
|
||||
*ethernetif_enet_ptr(ethernetif) = ethernetif_get_enet_base(enetIdx);
|
||||
// LWIP_ASSERT("*ethernetif_enet_ptr(ethernetif) != NULL", (*ethernetif_enet_ptr(ethernetif) != NULL));
|
||||
LWIP_ASSERT("*ethernetif_enet_ptr(ethernetif) != NULL", (*ethernetif_enet_ptr(ethernetif) != NULL));
|
||||
|
||||
/* set MAC hardware address length */
|
||||
netif->hwaddr_len = ETH_HWADDR_LEN;
|
||||
|
|
|
@ -70,29 +70,39 @@
|
|||
#include "lwip/igmp.h"
|
||||
#include "lwip/mld6.h"
|
||||
|
||||
//
|
||||
//#define USE_RTOS 1
|
||||
//#define FSL_RTOS_FREE_RTOS
|
||||
//#define FSL_RTOS_XIUOS
|
||||
|
||||
#if USE_RTOS && defined(FSL_RTOS_FREE_RTOS)
|
||||
|
||||
#ifdef FSL_RTOS_XIUOS
|
||||
#include "xs_sem.h"
|
||||
|
||||
#else
|
||||
#include "FreeRTOS.h"
|
||||
#include "event_groups.h"
|
||||
|
||||
#include "list.h"
|
||||
#endif
|
||||
|
||||
typedef uint32_t TickType_t;
|
||||
#define portMAX_DELAY ( TickType_t ) 0xffffffffUL
|
||||
#define portMAX_DELAY ( TickType_t ) 0xffffffffUL
|
||||
|
||||
typedef TickType_t EventBits_t;
|
||||
typedef TickType_t EventBits_t;
|
||||
|
||||
typedef long BaseType_t;
|
||||
typedef unsigned long UBaseType_t;
|
||||
|
||||
#define portBASE_TYPE long
|
||||
#define portBASE_TYPE long
|
||||
|
||||
#define pdFALSE ( ( BaseType_t ) 0 )
|
||||
#define pdTRUE ( ( BaseType_t ) 1 )
|
||||
|
||||
#define pdPASS ( pdTRUE )
|
||||
#define pdFAIL ( pdFALSE )
|
||||
#define pdFALSE ( ( BaseType_t ) 0 )
|
||||
#define pdTRUE ( ( BaseType_t ) 1 )
|
||||
|
||||
#define pdPASS ( pdTRUE )
|
||||
#define pdFAIL ( pdFALSE )
|
||||
|
||||
#ifndef FSL_RTOS_XIUOS
|
||||
typedef struct EventGroupDef_t
|
||||
{
|
||||
EventBits_t uxEventBits;
|
||||
|
@ -109,7 +119,7 @@ typedef struct EventGroupDef_t
|
|||
|
||||
struct EventGroupDef_t;
|
||||
typedef struct EventGroupDef_t * EventGroupHandle_t;
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -121,6 +131,8 @@ typedef struct EventGroupDef_t * EventGroupHandle_t;
|
|||
|
||||
#include "sys_arch.h"
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
@ -136,7 +148,12 @@ struct ethernetif
|
|||
enet_handle_t handle;
|
||||
#endif
|
||||
#if USE_RTOS && defined(FSL_RTOS_FREE_RTOS)
|
||||
|
||||
#ifdef FSL_RTOS_XIUOS
|
||||
int enetSemaphore;
|
||||
#else
|
||||
EventGroupHandle_t enetTransmitAccessEvent;
|
||||
#endif
|
||||
EventBits_t txFlag;
|
||||
#endif
|
||||
enet_rx_bd_struct_t *RxBuffDescrip;
|
||||
|
@ -161,6 +178,8 @@ static void ethernet_callback(ENET_Type *base, enet_handle_t *handle, enet_event
|
|||
BaseType_t xResult;
|
||||
|
||||
|
||||
lw_print("lw: [%s] input event %#x \n", __func__, event);
|
||||
|
||||
switch (event)
|
||||
{
|
||||
case kENET_RxEvent:
|
||||
|
@ -170,6 +189,9 @@ static void ethernet_callback(ENET_Type *base, enet_handle_t *handle, enet_event
|
|||
{
|
||||
portBASE_TYPE taskToWake = pdFALSE;
|
||||
|
||||
#ifdef FSL_RTOS_XIUOS
|
||||
|
||||
#else
|
||||
#ifdef __CA7_REV
|
||||
if (SystemGetIRQNestingLevel())
|
||||
#else
|
||||
|
@ -186,11 +208,14 @@ static void ethernet_callback(ENET_Type *base, enet_handle_t *handle, enet_event
|
|||
{
|
||||
xEventGroupSetBits(ethernetif->enetTransmitAccessEvent, ethernetif->txFlag);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
KSemaphoreAbandon(ethernetif->enetSemaphore);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -274,6 +299,56 @@ err_t ethernetif_mld_mac_filter(struct netif *netif, const ip6_addr_t *group,
|
|||
}
|
||||
#endif
|
||||
|
||||
#define netifINTERFACE_TASK_STACK_SIZE ( 4096 )
|
||||
|
||||
/**
|
||||
* This function is the ethernetif_input task, it is processed when a packet
|
||||
* is ready to be read from the interface. It uses the function low_level_input()
|
||||
* that should handle the actual reception of bytes from the network
|
||||
* interface. Then the type of the received packet is determined and
|
||||
* the appropriate input function is called.
|
||||
*
|
||||
* @param netif the lwip network interface structure for this ethernetif
|
||||
*/
|
||||
//void eth_input( void * pvParameters )
|
||||
//{
|
||||
// struct pbuf *p;
|
||||
//
|
||||
// for( ;; )
|
||||
// {
|
||||
// if (KSemaphoreObtain( s_xSemaphore, WAITING_FOREVER)==EOK)
|
||||
// {
|
||||
// p = low_level_input( s_pxNetIf );
|
||||
//
|
||||
// if (ERR_OK != s_pxNetIf->input( p, s_pxNetIf))
|
||||
// {
|
||||
// KPrintf("netif input return not OK ! \n");
|
||||
// pbuf_free(p);
|
||||
// p=NULL;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//void low_level_init()
|
||||
//{
|
||||
// /* create the task that handles the ETH_MAC */
|
||||
// uint32 thr_id = KTaskCreate((signed char*) "eth_input",
|
||||
// eth_input,
|
||||
// NULL,
|
||||
// netifINTERFACE_TASK_STACK_SIZE,
|
||||
// 15);
|
||||
// if (thr_id >= 0)
|
||||
// {
|
||||
// StartupKTask(thr_id);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// KPrintf("Eth create failed !");
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
/**
|
||||
* Initializes ENET driver.
|
||||
*/
|
||||
|
@ -313,7 +388,14 @@ void ethernetif_enet_init(struct netif *netif, struct ethernetif *ethernetif,
|
|||
#endif /* ENET_ENHANCEDBUFFERDESCRIPTOR_MODE */
|
||||
|
||||
/* Create the Event for transmit busy release trigger. */
|
||||
#ifdef FSL_RTOS_XIUOS
|
||||
if(ethernetif->enetSemaphore < 0)
|
||||
{
|
||||
ethernetif->enetSemaphore = KSemaphoreCreate(0);
|
||||
}
|
||||
#else
|
||||
ethernetif->enetTransmitAccessEvent = xEventGroupCreate();
|
||||
#endif
|
||||
ethernetif->txFlag = 0x1;
|
||||
|
||||
config.interrupt |= kENET_RxFrameInterrupt | kENET_TxFrameInterrupt | kENET_TxBufferInterrupt;
|
||||
|
@ -350,6 +432,7 @@ void ethernetif_enet_init(struct netif *netif, struct ethernetif *ethernetif,
|
|||
#endif
|
||||
|
||||
ENET_ActiveRead(ethernetif->base);
|
||||
// low_level_init();
|
||||
}
|
||||
|
||||
ENET_Type **ethernetif_enet_ptr(struct ethernetif *ethernetif)
|
||||
|
@ -376,17 +459,27 @@ static err_t enet_send_frame(struct ethernetif *ethernetif, unsigned char *data,
|
|||
{
|
||||
status_t result;
|
||||
|
||||
lw_print("lw: [%s] len %d\n", __func__, length);
|
||||
|
||||
do
|
||||
{
|
||||
result = ENET_SendFrame(ethernetif->base, ðernetif->handle, data, length);
|
||||
|
||||
if (result == kStatus_ENET_TxFrameBusy)
|
||||
{
|
||||
#ifdef FSL_RTOS_XIUOS
|
||||
// KSemaphoreObtain(ethernetif->enetSemaphore, portMAX_DELAY);
|
||||
lw_trace();
|
||||
|
||||
#else
|
||||
xEventGroupWaitBits(ethernetif->enetTransmitAccessEvent, ethernetif->txFlag, pdTRUE, (BaseType_t) false,
|
||||
portMAX_DELAY);
|
||||
#endif
|
||||
}
|
||||
|
||||
} while (result == kStatus_ENET_TxFrameBusy);
|
||||
lw_trace();
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
#else
|
||||
|
|
|
@ -32,7 +32,6 @@
|
|||
#endif /* FSL_SDK_ENABLE_DRIVER_CACHE_CONTROL */
|
||||
|
||||
#include "lwipopts.h"
|
||||
unsigned short *lw_enet_ctrl;
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
|
@ -1564,6 +1563,7 @@ status_t ENET_SendFrame(ENET_Type *base, enet_handle_t *handle, const uint8_t *d
|
|||
curBuffDescrip = handle->txBdCurrent[0];
|
||||
if (curBuffDescrip->control & ENET_BUFFDESCRIPTOR_TX_READY_MASK)
|
||||
{
|
||||
lw_trace();
|
||||
return kStatus_ENET_TxFrameBusy;
|
||||
}
|
||||
#ifdef ENET_ENHANCEDBUFFERDESCRIPTOR_MODE
|
||||
|
@ -1571,6 +1571,9 @@ status_t ENET_SendFrame(ENET_Type *base, enet_handle_t *handle, const uint8_t *d
|
|||
/* Check PTP message with the PTP header. */
|
||||
isPtpEventMessage = ENET_Ptp1588ParseFrame(data, NULL, true);
|
||||
#endif /* ENET_ENHANCEDBUFFERDESCRIPTOR_MODE */
|
||||
|
||||
// lw_print("lw: [%s] size %d len %d\n", __func__, handle->txBuffSizeAlign[0], length);
|
||||
|
||||
/* One transmit buffer is enough for one frame. */
|
||||
if (handle->txBuffSizeAlign[0] >= length)
|
||||
{
|
||||
|
@ -1613,6 +1616,7 @@ status_t ENET_SendFrame(ENET_Type *base, enet_handle_t *handle, const uint8_t *d
|
|||
/* Active the transmit buffer descriptor. */
|
||||
ENET_ActiveSend(base, 0);
|
||||
|
||||
// lw_trace();
|
||||
return kStatus_Success;
|
||||
}
|
||||
else
|
||||
|
@ -1620,6 +1624,8 @@ status_t ENET_SendFrame(ENET_Type *base, enet_handle_t *handle, const uint8_t *d
|
|||
/* One frame requires more than one transmit buffers. */
|
||||
do
|
||||
{
|
||||
lw_trace();
|
||||
|
||||
#ifdef ENET_ENHANCEDBUFFERDESCRIPTOR_MODE
|
||||
/* For enable the timestamp. */
|
||||
if (isPtpEventMessage)
|
|
@ -0,0 +1,2 @@
|
|||
SRC_FILES := fsl_phy.c
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
|
@ -0,0 +1,3 @@
|
|||
SRC_FILES := fsl_gpio.c
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
|
@ -104,7 +104,7 @@
|
|||
#endif
|
||||
#else
|
||||
#ifndef ENET_PRIORITY
|
||||
#define ENET_PRIORITY (6U)
|
||||
#define ENET_PRIORITY (15U)//(6U)
|
||||
#endif
|
||||
#ifndef ENET_1588_PRIORITY
|
||||
#define ENET_1588_PRIORITY (5U)
|
|
@ -1,3 +1,3 @@
|
|||
SRC_FILES := connect_uart.c
|
||||
SRC_FILES := connect_uart.c fsl_lpuart.c
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
|
|
|
@ -175,6 +175,7 @@ KERNELPATHS :=-I$(BSP_ROOT) \
|
|||
-I$(BSP_ROOT)/third_party_driver \
|
||||
-I$(BSP_ROOT)/third_party_driver/include \
|
||||
-I$(BSP_ROOT)/third_party_driver/ethernet \
|
||||
-I$(BSP_ROOT)/third_party_driver/ethernet/ksz8081 \
|
||||
-I$(BSP_ROOT)/third_party_driver/MIMXRT1052 \
|
||||
-I$(BSP_ROOT)/third_party_driver/MIMXRT1052/drivers \
|
||||
-I$(BSP_ROOT)/third_party_driver/CMSIS/Include \
|
||||
|
@ -249,6 +250,11 @@ KERNELPATHS += -I$(KERNEL_ROOT)/../../APP_Framework/Framework/knowing/tensorflow
|
|||
KERNELPATHS += -I$(KERNEL_ROOT)/../../APP_Framework/Framework/knowing/tensorflow-lite/tensorflow-lite-for-mcu/source/third_party/ruy #
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_SUPPORT_CONTROL_FRAMEWORK), y)
|
||||
KERNELPATHS += -I$(KERNEL_ROOT)/../../APP_Framework/Framework/control #
|
||||
KERNELPATHS += -I$(KERNEL_ROOT)/../../APP_Framework/Framework/control/plc/interoperability/opcua #
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_CRYPTO), y)
|
||||
KERNELPATHS += -I$(KERNEL_ROOT)/framework/security/crypto/include #
|
||||
endif
|
||||
|
@ -256,10 +262,10 @@ endif
|
|||
KERNELPATHS += -I$(KERNEL_ROOT)/resources/include #
|
||||
|
||||
ifeq ($(CONFIG_RESOURCES_SPI), y)
|
||||
KERNELPATHS +=-I$(KERNEL_ROOT)/resources/spi #
|
||||
KERNELPATHS +=-I$(KERNEL_ROOT)/resources/spi #
|
||||
|
||||
ifeq ($(CONFIG_RESOURCES_SPI_SFUD),y)
|
||||
KERNELPATHS += -I$(KERNEL_ROOT)/resources/spi/third_party_spi/SFUD/sfud/inc #
|
||||
KERNELPATHS += -I$(KERNEL_ROOT)/resources/spi/third_party_spi/SFUD/sfud/inc #
|
||||
endif
|
||||
|
||||
endif
|
||||
|
|
Loading…
Reference in New Issue