forked from xuos/xiuos
optimize LWIP demo and OPCua demo
This commit is contained in:
parent
372c097688
commit
7c0b7367d1
|
@ -0,0 +1,25 @@
|
||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
#ifndef __UA_API_H__
|
||||||
|
#define __UA_API_H__
|
||||||
|
|
||||||
|
#include "open62541.h"
|
||||||
|
|
||||||
|
#define OPC_SERVER "opc.tcp://192.168.250.5:4840"
|
||||||
|
#define ua_print printf
|
||||||
|
|
||||||
|
int ua_server_connect(void);
|
||||||
|
int ua_get_server_info(UA_Client *client);
|
||||||
|
void ua_read_time(UA_Client *client);
|
||||||
|
int16 ua_test(void);
|
||||||
|
|
||||||
|
#endif
|
|
@ -469,8 +469,6 @@ static err_t enet_send_frame(struct ethernetif *ethernetif, unsigned char *data,
|
||||||
{
|
{
|
||||||
#ifdef FSL_RTOS_XIUOS
|
#ifdef FSL_RTOS_XIUOS
|
||||||
// KSemaphoreObtain(ethernetif->enetSemaphore, portMAX_DELAY);
|
// KSemaphoreObtain(ethernetif->enetSemaphore, portMAX_DELAY);
|
||||||
lw_trace();
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
xEventGroupWaitBits(ethernetif->enetTransmitAccessEvent, ethernetif->txFlag, pdTRUE, (BaseType_t) false,
|
xEventGroupWaitBits(ethernetif->enetTransmitAccessEvent, ethernetif->txFlag, pdTRUE, (BaseType_t) false,
|
||||||
portMAX_DELAY);
|
portMAX_DELAY);
|
||||||
|
@ -478,7 +476,6 @@ static err_t enet_send_frame(struct ethernetif *ethernetif, unsigned char *data,
|
||||||
}
|
}
|
||||||
|
|
||||||
} while (result == kStatus_ENET_TxFrameBusy);
|
} while (result == kStatus_ENET_TxFrameBusy);
|
||||||
lw_trace();
|
|
||||||
|
|
||||||
return ERR_OK;
|
return ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1563,7 +1563,6 @@ status_t ENET_SendFrame(ENET_Type *base, enet_handle_t *handle, const uint8_t *d
|
||||||
curBuffDescrip = handle->txBdCurrent[0];
|
curBuffDescrip = handle->txBdCurrent[0];
|
||||||
if (curBuffDescrip->control & ENET_BUFFDESCRIPTOR_TX_READY_MASK)
|
if (curBuffDescrip->control & ENET_BUFFDESCRIPTOR_TX_READY_MASK)
|
||||||
{
|
{
|
||||||
lw_trace();
|
|
||||||
return kStatus_ENET_TxFrameBusy;
|
return kStatus_ENET_TxFrameBusy;
|
||||||
}
|
}
|
||||||
#ifdef ENET_ENHANCEDBUFFERDESCRIPTOR_MODE
|
#ifdef ENET_ENHANCEDBUFFERDESCRIPTOR_MODE
|
||||||
|
@ -1616,7 +1615,6 @@ status_t ENET_SendFrame(ENET_Type *base, enet_handle_t *handle, const uint8_t *d
|
||||||
/* Active the transmit buffer descriptor. */
|
/* Active the transmit buffer descriptor. */
|
||||||
ENET_ActiveSend(base, 0);
|
ENET_ActiveSend(base, 0);
|
||||||
|
|
||||||
// lw_trace();
|
|
||||||
return kStatus_Success;
|
return kStatus_Success;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1624,8 +1622,6 @@ status_t ENET_SendFrame(ENET_Type *base, enet_handle_t *handle, const uint8_t *d
|
||||||
/* One frame requires more than one transmit buffers. */
|
/* One frame requires more than one transmit buffers. */
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
lw_trace();
|
|
||||||
|
|
||||||
#ifdef ENET_ENHANCEDBUFFERDESCRIPTOR_MODE
|
#ifdef ENET_ENHANCEDBUFFERDESCRIPTOR_MODE
|
||||||
/* For enable the timestamp. */
|
/* For enable the timestamp. */
|
||||||
if (isPtpEventMessage)
|
if (isPtpEventMessage)
|
||||||
|
|
|
@ -1,86 +0,0 @@
|
||||||
/**
|
|
||||||
******************************************************************************
|
|
||||||
* File Name : ethernetif.h
|
|
||||||
* Description : This file provides initialization code for LWIP
|
|
||||||
* middleWare.
|
|
||||||
******************************************************************************
|
|
||||||
* This notice applies to any and all portions of this file
|
|
||||||
* that are not between comment pairs USER CODE BEGIN and
|
|
||||||
* USER CODE END. Other portions of this file, whether
|
|
||||||
* inserted by the user or by software development tools
|
|
||||||
* are owned by their respective copyright owners.
|
|
||||||
*
|
|
||||||
* Copyright (c) 2018 STMicroelectronics International N.V.
|
|
||||||
* 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. Redistribution 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. Neither the name of STMicroelectronics nor the names of other
|
|
||||||
* contributors to this software may be used to endorse or promote products
|
|
||||||
* derived from this software without specific written permission.
|
|
||||||
* 4. This software, including modifications and/or derivative works of this
|
|
||||||
* software, must execute solely and exclusively on microcontroller or
|
|
||||||
* microprocessor devices manufactured by or for STMicroelectronics.
|
|
||||||
* 5. Redistribution and use of this software other than as permitted under
|
|
||||||
* this license is void and will automatically terminate your rights under
|
|
||||||
* this license.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
|
|
||||||
* AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
|
||||||
* PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
|
|
||||||
* RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
|
|
||||||
* SHALL STMICROELECTRONICS OR CONTRIBUTORS 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.
|
|
||||||
*
|
|
||||||
******************************************************************************
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef __ETHERNETIF_H__
|
|
||||||
#define __ETHERNETIF_H__
|
|
||||||
|
|
||||||
#include "lwip/err.h"
|
|
||||||
#include "lwip/netif.h"
|
|
||||||
|
|
||||||
/* Within 'USER CODE' section, code will be kept by default at each generation */
|
|
||||||
/* USER CODE BEGIN 0 */
|
|
||||||
#define NETIF_MTU ( 1500 )
|
|
||||||
|
|
||||||
#define NETIF_IN_TASK_STACK_SIZE ( 1024 )
|
|
||||||
#define NETIF_IN_TASK_PRIORITY ( 3 )
|
|
||||||
|
|
||||||
#define NETIF_OUT_TASK_STACK_SIZE ( 1024 )
|
|
||||||
#define NETIF_OUT_TASK_PRIORITY ( 3 )
|
|
||||||
|
|
||||||
/* USER CODE END 0 */
|
|
||||||
|
|
||||||
|
|
||||||
/* Exported functions ------------------------------------------------------- */
|
|
||||||
err_t ethernetif_init(struct netif *netif);
|
|
||||||
|
|
||||||
void ethernetif_input( void *argument );
|
|
||||||
void ethernetif_output( void *argument );
|
|
||||||
void ethernetif_update_config(struct netif *netif);
|
|
||||||
void ethernetif_notify_conn_changed(struct netif *netif);
|
|
||||||
|
|
||||||
u32_t sys_jiffies(void);
|
|
||||||
u32_t sys_now(void);
|
|
||||||
|
|
||||||
/* USER CODE BEGIN 1 */
|
|
||||||
|
|
||||||
/* USER CODE END 1 */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
|
|
@ -212,13 +212,13 @@ The STM32F4x7 allows computing and verifying the IP, UDP, TCP and ICMP checksums
|
||||||
#define DEFAULT_TCP_RECVMBOX_SIZE 10
|
#define DEFAULT_TCP_RECVMBOX_SIZE 10
|
||||||
#define DEFAULT_ACCEPTMBOX_SIZE 10
|
#define DEFAULT_ACCEPTMBOX_SIZE 10
|
||||||
|
|
||||||
#define DEFAULT_THREAD_PRIO 25
|
#define DEFAULT_THREAD_PRIO 20
|
||||||
#define DEFAULT_THREAD_STACKSIZE 1024
|
#define DEFAULT_THREAD_STACKSIZE 1024
|
||||||
|
|
||||||
#define TCPIP_THREAD_NAME "tcp"
|
#define TCPIP_THREAD_NAME "tcp"
|
||||||
#define TCPIP_THREAD_STACKSIZE 4096
|
#define TCPIP_THREAD_STACKSIZE 8192
|
||||||
#define TCPIP_MBOX_SIZE 8
|
#define TCPIP_MBOX_SIZE 10
|
||||||
#define TCPIP_THREAD_PRIO 25
|
#define TCPIP_THREAD_PRIO 15
|
||||||
|
|
||||||
//#define IPERF_SERVER_THREAD_NAME "iperf_server"
|
//#define IPERF_SERVER_THREAD_NAME "iperf_server"
|
||||||
//#define IPERF_SERVER_THREAD_STACKSIZE 1024
|
//#define IPERF_SERVER_THREAD_STACKSIZE 1024
|
||||||
|
@ -236,13 +236,24 @@ The STM32F4x7 allows computing and verifying the IP, UDP, TCP and ICMP checksums
|
||||||
|
|
||||||
#define LWIP_IPV4 1
|
#define LWIP_IPV4 1
|
||||||
#define LWIP_RAW 1
|
#define LWIP_RAW 1
|
||||||
|
#define LWIP_DNS 1
|
||||||
|
|
||||||
|
#if LWIP_DNS
|
||||||
|
#define LWIP_RAND rand
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef nfds_t
|
||||||
|
typedef unsigned int nfds_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
#define FSL_FEATURE_PHYKSZ8081_USE_RMII50M_MODE
|
#define FSL_FEATURE_PHYKSZ8081_USE_RMII50M_MODE
|
||||||
|
|
||||||
#define MEMP_LIB_MALLOC 1
|
#define MEMP_LIB_MALLOC 1
|
||||||
#define MEMP_MEM_MALLOC 1
|
#define MEMP_MEM_MALLOC 1
|
||||||
|
|
||||||
#define lw_print KPrintf
|
#define lw_print //KPrintf
|
||||||
|
#define lw_trace() //KPrintf("lw: [%s][%d] passed!\n", __func__, __LINE__)
|
||||||
|
#define lw_error() //KPrintf("lw: [%s][%d] failed!\n", __func__, __LINE__)
|
||||||
|
|
||||||
#endif /* __LWIPOPTS_H__ */
|
#endif /* __LWIPOPTS_H__ */
|
||||||
|
|
||||||
|
|
|
@ -57,15 +57,16 @@
|
||||||
#include "lwip/init.h"
|
#include "lwip/init.h"
|
||||||
#include "lwip/netif.h"
|
#include "lwip/netif.h"
|
||||||
#include "lwip/sio.h"
|
#include "lwip/sio.h"
|
||||||
#include "ethernetif.h"
|
|
||||||
|
|
||||||
#if !NO_SYS
|
|
||||||
#include "sys_arch.h"
|
|
||||||
#endif
|
|
||||||
#include <lwip/stats.h>
|
#include <lwip/stats.h>
|
||||||
#include <lwip/debug.h>
|
#include <lwip/debug.h>
|
||||||
#include <lwip/sys.h>
|
#include <lwip/sys.h>
|
||||||
#include "lwip/dhcp.h"
|
#include "lwip/dhcp.h"
|
||||||
|
#include "tcpip_priv.h"
|
||||||
|
|
||||||
|
#if !NO_SYS
|
||||||
|
#include "sys_arch.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <xs_ktask.h>
|
#include <xs_ktask.h>
|
||||||
#include <xs_ktick.h>
|
#include <xs_ktick.h>
|
||||||
|
@ -74,11 +75,21 @@
|
||||||
#include <xs_mutex.h>
|
#include <xs_mutex.h>
|
||||||
#include <xs_ktask.h>
|
#include <xs_ktask.h>
|
||||||
#include <xs_msg.h>
|
#include <xs_msg.h>
|
||||||
#include <ethernetif.h>
|
|
||||||
|
#include "board.h"
|
||||||
|
#include "ethernet.h"
|
||||||
|
#include "enet_ethernetif.h"
|
||||||
|
#include <transform.h>
|
||||||
|
|
||||||
|
/* MAC address configuration. */
|
||||||
|
#define configMAC_ADDR { 0x02, 0x12, 0x13, 0x10, 0x15, 0x11}
|
||||||
|
|
||||||
|
char lwip_ipaddr[] = {192, 168, 250, 253};
|
||||||
|
char lwip_netmask[] = {255, 255, 255, 0};
|
||||||
|
char lwip_gwaddr[] = {192, 168, 250, 252};
|
||||||
|
|
||||||
int errno;
|
int errno;
|
||||||
|
|
||||||
|
|
||||||
x_ticks_t lwip_sys_now;
|
x_ticks_t lwip_sys_now;
|
||||||
|
|
||||||
struct sys_timeouts {
|
struct sys_timeouts {
|
||||||
|
@ -87,8 +98,8 @@ struct sys_timeouts {
|
||||||
|
|
||||||
struct timeoutlist
|
struct timeoutlist
|
||||||
{
|
{
|
||||||
struct sys_timeouts timeouts;
|
struct sys_timeouts timeouts;
|
||||||
int32 pid;
|
int32 pid;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define SYS_THREAD_MAX 4
|
#define SYS_THREAD_MAX 4
|
||||||
|
@ -114,40 +125,40 @@ sys_now(void)
|
||||||
void
|
void
|
||||||
sys_init(void)
|
sys_init(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for(i = 0; i < SYS_THREAD_MAX; i++)
|
for(i = 0; i < SYS_THREAD_MAX; i++)
|
||||||
{
|
{
|
||||||
s_timeoutlist[i].pid = 0;
|
s_timeoutlist[i].pid = 0;
|
||||||
s_timeoutlist[i].timeouts.next = NULL;
|
s_timeoutlist[i].timeouts.next = NULL;
|
||||||
}
|
}
|
||||||
s_nextthread = 0;
|
s_nextthread = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct sys_timeouts *sys_arch_timeouts(void)
|
struct sys_timeouts *sys_arch_timeouts(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int32 pid;
|
int32 pid;
|
||||||
struct timeoutlist *tl;
|
struct timeoutlist *tl;
|
||||||
pid = (int32)GetKTaskDescriptor()->id.id;
|
pid = (int32)GetKTaskDescriptor()->id.id;
|
||||||
for(i = 0; i < s_nextthread; i++)
|
for(i = 0; i < s_nextthread; i++)
|
||||||
{
|
{
|
||||||
tl = &(s_timeoutlist[i]);
|
tl = &(s_timeoutlist[i]);
|
||||||
if(tl->pid == pid)
|
if(tl->pid == pid)
|
||||||
{
|
{
|
||||||
return &(tl->timeouts);
|
return &(tl->timeouts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
sys_prot_t sys_arch_protect(void)
|
sys_prot_t sys_arch_protect(void)
|
||||||
{
|
{
|
||||||
return CriticalAreaLock();
|
return CriticalAreaLock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void sys_arch_unprotect(sys_prot_t pval)
|
void sys_arch_unprotect(sys_prot_t pval)
|
||||||
{
|
{
|
||||||
CriticalAreaUnLock(pval);
|
CriticalAreaUnLock(pval);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !NO_SYS
|
#if !NO_SYS
|
||||||
|
@ -158,10 +169,10 @@ sys_sem_new(sys_sem_t *sem, u8_t count)
|
||||||
*sem = KSemaphoreCreate((uint16)count);
|
*sem = KSemaphoreCreate((uint16)count);
|
||||||
|
|
||||||
#if SYS_STATS
|
#if SYS_STATS
|
||||||
++lwip_stats.sys.sem.used;
|
++lwip_stats.sys.sem.used;
|
||||||
if (lwip_stats.sys.sem.max < lwip_stats.sys.sem.used) {
|
if (lwip_stats.sys.sem.max < lwip_stats.sys.sem.used) {
|
||||||
lwip_stats.sys.sem.max = lwip_stats.sys.sem.used;
|
lwip_stats.sys.sem.max = lwip_stats.sys.sem.used;
|
||||||
}
|
}
|
||||||
#endif /* SYS_STATS */
|
#endif /* SYS_STATS */
|
||||||
|
|
||||||
if(*sem >= 0)
|
if(*sem >= 0)
|
||||||
|
@ -287,11 +298,15 @@ err_t sys_mbox_new(sys_mbox_t *mbox, int size)
|
||||||
++lwip_stats.sys.mbox.used;
|
++lwip_stats.sys.mbox.used;
|
||||||
if (lwip_stats.sys.mbox.max < lwip_stats.sys.mbox.used) {
|
if (lwip_stats.sys.mbox.max < lwip_stats.sys.mbox.used) {
|
||||||
lwip_stats.sys.mbox.max = lwip_stats.sys.mbox.used;
|
lwip_stats.sys.mbox.max = lwip_stats.sys.mbox.used;
|
||||||
}
|
}
|
||||||
#endif /* SYS_STATS */
|
#endif /* SYS_STATS */
|
||||||
if(*mbox < 0)
|
if(*mbox < 0)
|
||||||
|
{
|
||||||
|
lw_print("lw: [%s] alloc %d mbox %p failed\n", __func__, size, mbox);
|
||||||
return ERR_MEM;
|
return ERR_MEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
lw_print("lw: [%s] alloc %d mbox %p ok!\n", __func__, size, mbox);
|
||||||
return ERR_OK;
|
return ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -370,9 +385,6 @@ struct netif gnetif;
|
||||||
ip4_addr_t ipaddr;
|
ip4_addr_t ipaddr;
|
||||||
ip4_addr_t netmask;
|
ip4_addr_t netmask;
|
||||||
ip4_addr_t gw;
|
ip4_addr_t gw;
|
||||||
uint8_t IP_ADDRESS[4];
|
|
||||||
uint8_t NETMASK_ADDRESS[4];
|
|
||||||
uint8_t GATEWAY_ADDRESS[4];
|
|
||||||
|
|
||||||
void TcpIpInit(void)
|
void TcpIpInit(void)
|
||||||
{
|
{
|
||||||
|
@ -397,7 +409,7 @@ void TcpIpInit(void)
|
||||||
/* USER CODE END 0 */
|
/* USER CODE END 0 */
|
||||||
/* Initilialize the LwIP stack without RTOS */
|
/* Initilialize the LwIP stack without RTOS */
|
||||||
/* add the network interface (IPv4/IPv6) without RTOS */
|
/* add the network interface (IPv4/IPv6) without RTOS */
|
||||||
netif_add(&gnetif, &ipaddr, &netmask, &gw, NULL, ðernetif_init, &tcpip_input);
|
netif_add(&gnetif, &ipaddr, &netmask, &gw, NULL, ðernetif0_init, &tcpip_input);
|
||||||
|
|
||||||
/* Registers the default network interface */
|
/* Registers the default network interface */
|
||||||
netif_set_default(&gnetif);
|
netif_set_default(&gnetif);
|
||||||
|
@ -440,3 +452,131 @@ void TcpIpInit(void)
|
||||||
((gnetif.ip_addr.addr)&0xff000000)>>24);
|
((gnetif.ip_addr.addr)&0xff000000)>>24);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// lwip input thread to get network packet
|
||||||
|
void lwip_input_thread(void *param)
|
||||||
|
{
|
||||||
|
struct netif *net = param;
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
/* Poll the driver, get any outstanding frames */
|
||||||
|
ethernetif_input(net);
|
||||||
|
sys_check_timeouts(); /* Handle all system timeouts for all core protocols */
|
||||||
|
// DelayKTask(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void lwip_config_input(struct netif *net)
|
||||||
|
{
|
||||||
|
pthread_t th_id = 0;
|
||||||
|
|
||||||
|
th_id = sys_thread_new("eth_input", lwip_input_thread, net, 4096, 15);
|
||||||
|
|
||||||
|
if (th_id >= 0) {
|
||||||
|
lw_print("%s %d successfully!\n", __func__, th_id);
|
||||||
|
} else {
|
||||||
|
lw_print("%s failed!\n", __func__);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int lwip_init_flag = 0;
|
||||||
|
|
||||||
|
void lwip_config_net(char *ip, char *mask, char *gw)
|
||||||
|
{
|
||||||
|
#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 net_ipaddr, net_netmask, net_gw;
|
||||||
|
ethernetif_config_t cfg = {
|
||||||
|
.phyAddress = BOARD_ENET0_PHY_ADDRESS,
|
||||||
|
.clockName = kCLOCK_CoreSysClk,
|
||||||
|
.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 */
|
||||||
|
};
|
||||||
|
|
||||||
|
if(lwip_init_flag)
|
||||||
|
{
|
||||||
|
lw_print("lw: [%s] already ...\n", __func__);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
lwip_init_flag = 1;
|
||||||
|
|
||||||
|
lw_print("lw: [%s] start ...\n", __func__);
|
||||||
|
|
||||||
|
IP4_ADDR(&net_ipaddr, ip[0], ip[1], ip[2], ip[3]);
|
||||||
|
IP4_ADDR(&net_netmask, mask[0], mask[1], mask[2], mask[3]);
|
||||||
|
IP4_ADDR(&net_gw, gw[0], gw[1], gw[2], gw[3]);
|
||||||
|
|
||||||
|
lwip_init();
|
||||||
|
|
||||||
|
netif_add(&gnetif, &net_ipaddr, &net_netmask, &net_gw, &cfg, ethernetif0_init,
|
||||||
|
ethernet_input);
|
||||||
|
netif_set_default(&gnetif);
|
||||||
|
netif_set_up(&gnetif);
|
||||||
|
|
||||||
|
lw_print("\r\n************************************************\r\n");
|
||||||
|
lw_print(" Network Configuration\r\n");
|
||||||
|
lw_print("************************************************\r\n");
|
||||||
|
lw_print(" IPv4 Address : %u.%u.%u.%u\r\n", ((u8_t *)&net_ipaddr)[0], ((u8_t *)&net_ipaddr)[1],
|
||||||
|
((u8_t *)&net_ipaddr)[2], ((u8_t *)&net_ipaddr)[3]);
|
||||||
|
lw_print(" IPv4 Subnet mask : %u.%u.%u.%u\r\n", ((u8_t *)&net_netmask)[0], ((u8_t *)&net_netmask)[1],
|
||||||
|
((u8_t *)&net_netmask)[2], ((u8_t *)&net_netmask)[3]);
|
||||||
|
lw_print(" IPv4 Gateway : %u.%u.%u.%u\r\n", ((u8_t *)&net_gw)[0], ((u8_t *)&net_gw)[1],
|
||||||
|
((u8_t *)&net_gw)[2], ((u8_t *)&net_gw)[3]);
|
||||||
|
lw_print("************************************************\r\n");
|
||||||
|
|
||||||
|
lwip_config_input(&gnetif);
|
||||||
|
}
|
||||||
|
|
||||||
|
void lwip_config_tcp(char *ip, char *mask, char *gw)
|
||||||
|
{
|
||||||
|
#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 net_ipaddr, net_netmask, net_gw;
|
||||||
|
ethernetif_config_t cfg = {
|
||||||
|
.phyAddress = BOARD_ENET0_PHY_ADDRESS,
|
||||||
|
.clockName = kCLOCK_CoreSysClk,
|
||||||
|
.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 */
|
||||||
|
};
|
||||||
|
|
||||||
|
if(lwip_init_flag)
|
||||||
|
{
|
||||||
|
lw_print("lw: [%s] already ...\n", __func__);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
lwip_init_flag = 1;
|
||||||
|
|
||||||
|
tcpip_init(NULL, NULL);
|
||||||
|
|
||||||
|
lw_print("lw: [%s] start ...\n", __func__);
|
||||||
|
|
||||||
|
IP4_ADDR(&net_ipaddr, ip[0], ip[1], ip[2], ip[3]);
|
||||||
|
IP4_ADDR(&net_netmask, mask[0], mask[1], mask[2], mask[3]);
|
||||||
|
IP4_ADDR(&net_gw, gw[0], gw[1], gw[2], gw[3]);
|
||||||
|
|
||||||
|
netif_add(&gnetif, &net_ipaddr, &net_netmask, &net_gw, &cfg, ethernetif0_init,
|
||||||
|
tcpip_input);
|
||||||
|
|
||||||
|
netif_set_default(&gnetif);
|
||||||
|
netif_set_up(&gnetif);
|
||||||
|
|
||||||
|
lw_print("\r\n************************************************\r\n");
|
||||||
|
lw_print(" Network Configuration\r\n");
|
||||||
|
lw_print("************************************************\r\n");
|
||||||
|
lw_print(" IPv4 Address : %u.%u.%u.%u\r\n", ((u8_t *)&net_ipaddr)[0], ((u8_t *)&net_ipaddr)[1],
|
||||||
|
((u8_t *)&net_ipaddr)[2], ((u8_t *)&net_ipaddr)[3]);
|
||||||
|
lw_print(" IPv4 Subnet mask : %u.%u.%u.%u\r\n", ((u8_t *)&net_netmask)[0], ((u8_t *)&net_netmask)[1],
|
||||||
|
((u8_t *)&net_netmask)[2], ((u8_t *)&net_netmask)[3]);
|
||||||
|
lw_print(" IPv4 Gateway : %u.%u.%u.%u\r\n", ((u8_t *)&net_gw)[0], ((u8_t *)&net_gw)[1],
|
||||||
|
((u8_t *)&net_gw)[2], ((u8_t *)&net_gw)[3]);
|
||||||
|
lw_print("************************************************\r\n");
|
||||||
|
|
||||||
|
lwip_config_input(&gnetif);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2017 Simon Goldschmidt
|
* Copyright (c) 2017 Simon Goldschmidt
|
||||||
* 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,
|
||||||
|
@ -49,8 +49,13 @@
|
||||||
* @date 2021-05-29
|
* @date 2021-05-29
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef __SYS_ARCH__
|
||||||
|
#define __SYS_ATCH__
|
||||||
|
|
||||||
#include <lwip/opt.h>
|
#include <lwip/opt.h>
|
||||||
#include <lwip/arch.h>
|
#include <lwip/arch.h>
|
||||||
|
#include <lwip/netif.h>
|
||||||
|
|
||||||
#include "tcpip.h"
|
#include "tcpip.h"
|
||||||
|
|
||||||
#include <xs_base.h>
|
#include <xs_base.h>
|
||||||
|
@ -58,19 +63,19 @@
|
||||||
/* USER CODE BEGIN 0 */
|
/* USER CODE BEGIN 0 */
|
||||||
// #define SET_AS_SERVER 1 /* define this terminal is udp server or not*/
|
// #define SET_AS_SERVER 1 /* define this terminal is udp server or not*/
|
||||||
|
|
||||||
#define LOCAL_PORT_SERVER 5001
|
#define LOCAL_PORT_SERVER 4840
|
||||||
#define TARGET_PORT_CLIENT LOCAL_PORT_SERVER
|
#define TARGET_PORT_CLIENT LOCAL_PORT_SERVER
|
||||||
|
|
||||||
/*Static IP ADDRESS: IP_ADDR0.IP_ADDR1.IP_ADDR2.IP_ADDR3 */
|
/*Static IP ADDRESS: IP_ADDR0.IP_ADDR1.IP_ADDR2.IP_ADDR3 */
|
||||||
#define IP_ADDR0_SERVER 192
|
#define IP_ADDR0_SERVER 192
|
||||||
#define IP_ADDR1_SERVER 168
|
#define IP_ADDR1_SERVER 168
|
||||||
#define IP_ADDR2_SERVER 0
|
#define IP_ADDR2_SERVER 250
|
||||||
#define IP_ADDR3_SERVER 166
|
#define IP_ADDR3_SERVER 252
|
||||||
|
|
||||||
#define IP_ADDR0_ClIENT 192
|
#define IP_ADDR0_ClIENT 192
|
||||||
#define IP_ADDR1_ClIENT 168
|
#define IP_ADDR1_ClIENT 168
|
||||||
#define IP_ADDR2_ClIENT 250
|
#define IP_ADDR2_ClIENT 250
|
||||||
#define IP_ADDR3_ClIENT 253
|
#define IP_ADDR3_ClIENT 253
|
||||||
|
|
||||||
/*NETMASK*/
|
/*NETMASK*/
|
||||||
#define NETMASK_ADDR0 255
|
#define NETMASK_ADDR0 255
|
||||||
|
@ -82,7 +87,7 @@
|
||||||
#define GW_ADDR0 192
|
#define GW_ADDR0 192
|
||||||
#define GW_ADDR1 168
|
#define GW_ADDR1 168
|
||||||
#define GW_ADDR2 250
|
#define GW_ADDR2 250
|
||||||
#define GW_ADDR3 252
|
#define GW_ADDR3 5
|
||||||
/* USER CODE END 0 */
|
/* USER CODE END 0 */
|
||||||
|
|
||||||
#define SYS_MBOX_NULL 0
|
#define SYS_MBOX_NULL 0
|
||||||
|
@ -98,5 +103,12 @@ typedef x_base sys_prot_t;
|
||||||
|
|
||||||
#define MS_PER_SYSTICK_F407 1000/TICK_PER_SECOND
|
#define MS_PER_SYSTICK_F407 1000/TICK_PER_SECOND
|
||||||
|
|
||||||
void TcpIpInit(void);
|
extern char lwip_ipaddr[];
|
||||||
|
extern char lwip_netmask[];
|
||||||
|
extern char lwip_gwaddr[];
|
||||||
|
|
||||||
|
void TcpIpInit(void);
|
||||||
|
void lwip_config_net(char *ip, char *mask, char *gw);
|
||||||
|
void lwip_config_tcp(char *ip, char *mask, char *gw);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
|
@ -90,7 +90,7 @@
|
||||||
* systems, this should be defined to something less resource-consuming.
|
* systems, this should be defined to something less resource-consuming.
|
||||||
*/
|
*/
|
||||||
#ifndef LWIP_PLATFORM_ASSERT
|
#ifndef LWIP_PLATFORM_ASSERT
|
||||||
#define LWIP_PLATFORM_ASSERT(x) do {printf("Assertion \"%s\" failed at line %d in %s\n", \
|
#define LWIP_PLATFORM_ASSERT(x) do {KPrintf("Assertion \"%s\" failed at line %d in %s\n", \
|
||||||
x, __LINE__, __FILE__); fflush(NULL); abort();} while(0)
|
x, __LINE__, __FILE__); fflush(NULL); abort();} while(0)
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
Loading…
Reference in New Issue