forked from xuos/xiuos
change demo command and support DHCP demo
This commit is contained in:
parent
d1d4632292
commit
a0337a42e3
|
@ -1,3 +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
|
||||
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 lwip_dhcp_demo.c
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
|
|
|
@ -104,7 +104,7 @@ void lwip_setip_thread(int argc, char *argv[])
|
|||
}
|
||||
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(3),
|
||||
SetIp, lwip_setip_thread, SetIp [IP] [Netmask] [Gateway]);
|
||||
setip, lwip_setip_thread, SetIp [IP] [Netmask] [Gateway]);
|
||||
|
||||
|
||||
void lwip_getip_thread(int argc, char *argv[])
|
||||
|
@ -123,6 +123,6 @@ void lwip_getip_thread(int argc, char *argv[])
|
|||
}
|
||||
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(0),
|
||||
GetIp, lwip_getip_thread, GetIp [IP] [Netmask] [Gateway]);
|
||||
getip, lwip_getip_thread, GetIp [IP] [Netmask] [Gateway]);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,214 @@
|
|||
/*
|
||||
* Copyright (c) 2016, Freescale Semiconductor, Inc.
|
||||
* Copyright 2016-2019 NXP
|
||||
* All rights reserved.
|
||||
*
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
/*******************************************************************************
|
||||
* Includes
|
||||
******************************************************************************/
|
||||
|
||||
#include "lwip/opt.h"
|
||||
|
||||
#if LWIP_IPV4 && LWIP_DHCP
|
||||
|
||||
#include "lwip/timeouts.h"
|
||||
#include "lwip/ip_addr.h"
|
||||
#include "lwip/init.h"
|
||||
#include "lwip/dhcp.h"
|
||||
#include "lwip/prot/dhcp.h"
|
||||
#include "netif/ethernet.h"
|
||||
#include "enet_ethernetif.h"
|
||||
|
||||
#include "board.h"
|
||||
|
||||
#include "pin_mux.h"
|
||||
#include "clock_config.h"
|
||||
#include "fsl_gpio.h"
|
||||
#include "fsl_iomuxc.h"
|
||||
#include "sys_arch.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
/* IP address configuration. */
|
||||
#define configIP_ADDR0 192
|
||||
#define configIP_ADDR1 168
|
||||
#define configIP_ADDR2 0
|
||||
#define configIP_ADDR3 102
|
||||
|
||||
/* 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 0
|
||||
#define configGW_ADDR3 100
|
||||
|
||||
/* MAC address configuration. */
|
||||
#define configMAC_ADDR \
|
||||
{ \
|
||||
0x02, 0x12, 0x13, 0x10, 0x15, 0x11 \
|
||||
}
|
||||
|
||||
/* Address of PHY interface. */
|
||||
#define EXAMPLE_PHY_ADDRESS BOARD_ENET0_PHY_ADDRESS
|
||||
|
||||
/* System clock name. */
|
||||
#define EXAMPLE_CLOCK_NAME kCLOCK_CoreSysClk
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* Prototypes
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Variables
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Code
|
||||
******************************************************************************/
|
||||
|
||||
/*!
|
||||
* @brief Prints DHCP status of the interface when it has changed from last status.
|
||||
*
|
||||
* @param netif network interface structure
|
||||
*/
|
||||
int print_dhcp_state(struct netif *netif)
|
||||
{
|
||||
static u8_t dhcp_last_state = DHCP_STATE_OFF;
|
||||
struct dhcp *dhcp = netif_dhcp_data(netif);
|
||||
|
||||
if (dhcp == NULL)
|
||||
{
|
||||
dhcp_last_state = DHCP_STATE_OFF;
|
||||
}
|
||||
else if (dhcp_last_state != dhcp->state)
|
||||
{
|
||||
dhcp_last_state = dhcp->state;
|
||||
|
||||
lw_pr_info(" DHCP state : ");
|
||||
switch (dhcp_last_state)
|
||||
{
|
||||
case DHCP_STATE_OFF:
|
||||
lw_pr_info("OFF");
|
||||
break;
|
||||
case DHCP_STATE_REQUESTING:
|
||||
lw_pr_info("REQUESTING");
|
||||
break;
|
||||
case DHCP_STATE_INIT:
|
||||
lw_pr_info("INIT");
|
||||
break;
|
||||
case DHCP_STATE_REBOOTING:
|
||||
lw_pr_info("REBOOTING");
|
||||
break;
|
||||
case DHCP_STATE_REBINDING:
|
||||
lw_pr_info("REBINDING");
|
||||
break;
|
||||
case DHCP_STATE_RENEWING:
|
||||
lw_pr_info("RENEWING");
|
||||
break;
|
||||
case DHCP_STATE_SELECTING:
|
||||
lw_pr_info("SELECTING");
|
||||
break;
|
||||
case DHCP_STATE_INFORMING:
|
||||
lw_pr_info("INFORMING");
|
||||
break;
|
||||
case DHCP_STATE_CHECKING:
|
||||
lw_pr_info("CHECKING");
|
||||
break;
|
||||
case DHCP_STATE_BOUND:
|
||||
lw_pr_info("BOUND");
|
||||
break;
|
||||
case DHCP_STATE_BACKING_OFF:
|
||||
lw_pr_info("BACKING_OFF");
|
||||
break;
|
||||
default:
|
||||
lw_pr_info("%u", dhcp_last_state);
|
||||
assert(0);
|
||||
break;
|
||||
}
|
||||
lw_pr_info("\r\n");
|
||||
|
||||
if (dhcp_last_state == DHCP_STATE_BOUND)
|
||||
{
|
||||
lw_pr_info("\r\n IPv4 Address : %s\r\n", ipaddr_ntoa(&netif->ip_addr));
|
||||
lw_pr_info(" IPv4 Subnet mask : %s\r\n", ipaddr_ntoa(&netif->netmask));
|
||||
lw_pr_info(" IPv4 Gateway : %s\r\n\r\n", ipaddr_ntoa(&netif->gw));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Main function.
|
||||
*/
|
||||
void lwip_dhcp_test(void)
|
||||
{
|
||||
static int flag = 0;
|
||||
struct netif fsl_netif0;
|
||||
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,
|
||||
};
|
||||
char ip_addr[4] = {0, 0, 0, 0};
|
||||
|
||||
ETH_BSP_Config();
|
||||
|
||||
// IP4_ADDR(&fsl_netif0_ipaddr, 0U, 0U, 0U, 0U);
|
||||
// IP4_ADDR(&fsl_netif0_netmask, 0U, 0U, 0U, 0U);
|
||||
// IP4_ADDR(&fsl_netif0_gw, 0U, 0U, 0U, 0U);
|
||||
|
||||
// if(flag == 0)
|
||||
// {
|
||||
// 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);
|
||||
// flag = 1;
|
||||
// }
|
||||
|
||||
// netif_set_up(&fsl_netif0);
|
||||
lwip_config_net(ip_addr, ip_addr, ip_addr);
|
||||
is_lwip_test = 1;
|
||||
|
||||
dhcp_start(&gnetif);
|
||||
|
||||
lw_pr_info("\r\n************************************************\r\n");
|
||||
lw_pr_info(" DHCP example\r\n");
|
||||
lw_pr_info("************************************************\r\n");
|
||||
|
||||
while (1)
|
||||
{
|
||||
/* Poll the driver, get any outstanding frames */
|
||||
ethernetif_input(&gnetif);
|
||||
|
||||
/* Handle all system timeouts for all core protocols */
|
||||
sys_check_timeouts();
|
||||
|
||||
/* Print DHCP progress */
|
||||
if(print_dhcp_state(&gnetif))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
is_lwip_test = 0;
|
||||
}
|
||||
|
||||
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(0),
|
||||
DHCPTest, lwip_dhcp_test, DHCP_Test);
|
||||
|
||||
#endif
|
|
@ -105,6 +105,6 @@ void lwip_ping_thread(int argc, char *argv[])
|
|||
}
|
||||
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(3),
|
||||
ping, lwip_ping_thread, ping [IP] 5 times);
|
||||
ping, lwip_ping_thread, ping [IP] 3 times);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -46,7 +46,7 @@ char* tcp_send_msg = "\n\nThis one is TCP pkg. Congratulations on you.\n\n";
|
|||
|
||||
static void lwip_tcp_send_thread(void *arg)
|
||||
{
|
||||
int cnt = 5;
|
||||
int cnt = TEST_LWIP_TIMES;
|
||||
lw_print("lwip_tcp_send_thread start.\n");
|
||||
|
||||
int sock_tcp_send_once = -1;
|
||||
|
@ -85,6 +85,7 @@ static void lwip_tcp_send_thread(void *arg)
|
|||
|
||||
MdelayKTask(1000);
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
__exit:
|
||||
|
@ -114,7 +115,7 @@ void lwip_tcp_client_run(int argc, char *argv[])
|
|||
}
|
||||
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(0),
|
||||
LwTcpClient, lwip_tcp_client_run, TCP Client);
|
||||
TCPSend, lwip_tcp_client_run, TCP Client);
|
||||
|
||||
|
||||
void lwip_tcp_server_run(void)
|
||||
|
@ -125,5 +126,5 @@ void lwip_tcp_server_run(void)
|
|||
}
|
||||
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(0),
|
||||
LwTcpServer, lwip_tcp_server_run, TCP server);
|
||||
TCPRecv, lwip_tcp_server_run, TCP Server);
|
||||
|
||||
|
|
|
@ -77,7 +77,7 @@ void lwip_udp_thread(int argc, char *argv[])
|
|||
}
|
||||
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(3),
|
||||
LwUdpEcho, lwip_udp_thread, UDP send echo);
|
||||
UDPSend, lwip_udp_thread, UDP send echo);
|
||||
|
||||
static void
|
||||
udpecho_raw_recv(void *arg, struct udp_pcb *upcb, struct pbuf *p,
|
||||
|
@ -118,5 +118,5 @@ void lwip_udp_server(void)
|
|||
}
|
||||
|
||||
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);
|
||||
UDPRecv, lwip_udp_server, UDP server echo);
|
||||
|
||||
|
|
|
@ -363,7 +363,7 @@ ping_send(struct raw_pcb *raw, const ip_addr_t *addr)
|
|||
static void
|
||||
ping_timeout(void *arg)
|
||||
{
|
||||
static int cnt = 3;
|
||||
static int cnt = TEST_LWIP_TIMES;
|
||||
struct raw_pcb *pcb = (struct raw_pcb*)arg;
|
||||
|
||||
LWIP_ASSERT("ping_timeout: no pcb given!", pcb != NULL);
|
||||
|
@ -376,7 +376,7 @@ ping_timeout(void *arg)
|
|||
}
|
||||
else
|
||||
{
|
||||
cnt = 3;
|
||||
cnt = TEST_LWIP_TIMES;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -53,6 +53,7 @@
|
|||
#include "udp_echo.h"
|
||||
#include <transform.h>
|
||||
#include "lwip/opt.h"
|
||||
#include "sys_arch.h"
|
||||
|
||||
#if LWIP_SOCKET
|
||||
#include <lwip/sockets.h>
|
||||
|
@ -136,7 +137,7 @@ __exit:
|
|||
|
||||
static void UdpEchoThreadClient(void *arg)
|
||||
{
|
||||
int cnt = 5;
|
||||
int cnt = TEST_LWIP_TIMES;
|
||||
KPrintf("UdpEchoThreadClient start.\n");
|
||||
|
||||
int sock_udp_send_once = -1;
|
||||
|
@ -164,7 +165,7 @@ static void UdpEchoThreadClient(void *arg)
|
|||
|
||||
while (cnt --)
|
||||
{
|
||||
KPrintf("Lwip client is running.\n");
|
||||
lw_print("UDP Client is running.\n");
|
||||
|
||||
sendto(sock_udp_send_once,udp_send_msg,
|
||||
strlen(udp_send_msg),0,
|
||||
|
|
|
@ -76,19 +76,19 @@ static void ZombieKTaskEntry(void *parameter)
|
|||
SuspendKTask(zombie_recycle);
|
||||
CriticalAreaUnLock(lock);
|
||||
DO_KTASK_ASSIGN;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ZombieTaskRecycleInit(void)
|
||||
{
|
||||
InitDoubleLinkList(&KTaskZombie);
|
||||
|
||||
|
||||
zombie_recycle = KTaskCreate("ZombieRecycleKTask",
|
||||
ZombieKTaskEntry,
|
||||
NONE,
|
||||
ZOMBIE_KTASK_STACKSIZE,
|
||||
KTASK_LOWEST_PRIORITY + 1);
|
||||
KTASK_PRIORITY_MAX - 1);
|
||||
|
||||
StartupKTask(zombie_recycle);
|
||||
}
|
|
@ -118,7 +118,7 @@ a lot of data that needs to be copied, this should be set high. */
|
|||
/* Define LWIP_DHCP to 1 if you want DHCP configuration of
|
||||
interfaces. DHCP is not implemented in lwIP 0.5.1, however, so
|
||||
turning this on does currently not work. */
|
||||
#define LWIP_DHCP 0
|
||||
#define LWIP_DHCP 1
|
||||
|
||||
|
||||
/* ---------- UDP options ---------- */
|
||||
|
|
|
@ -89,6 +89,7 @@ char lwip_netmask[] = {255, 255, 255, 0};
|
|||
char lwip_gwaddr[] = {192, 168, 250, 252};
|
||||
|
||||
int errno;
|
||||
int is_lwip_test = 0; //for lwip input thread
|
||||
|
||||
x_ticks_t lwip_sys_now;
|
||||
|
||||
|
@ -442,7 +443,7 @@ void TcpIpInit(void)
|
|||
KPrintf("lwip dhcp init fail...\n\n");
|
||||
while(ip_addr_cmp(&(gnetif.ip_addr),&ipaddr))
|
||||
{
|
||||
vTaskDelay(1);
|
||||
DelayKTask(1);
|
||||
}
|
||||
#endif
|
||||
KPrintf("\n\nIP:%d.%d.%d.%d\n\n", \
|
||||
|
@ -470,6 +471,10 @@ void lwip_config_input(struct netif *net)
|
|||
{
|
||||
pthread_t th_id = 0;
|
||||
|
||||
//neglect create input thread for test
|
||||
if(is_lwip_test)
|
||||
return;
|
||||
|
||||
th_id = sys_thread_new("eth_input", lwip_input_thread, net, 4096, 15);
|
||||
|
||||
if (th_id >= 0) {
|
||||
|
|
|
@ -66,6 +66,8 @@
|
|||
#define LOCAL_PORT_SERVER 4840
|
||||
#define TARGET_PORT_CLIENT LOCAL_PORT_SERVER
|
||||
|
||||
#define TEST_LWIP_TIMES 3
|
||||
|
||||
/*Static IP ADDRESS: IP_ADDR0.IP_ADDR1.IP_ADDR2.IP_ADDR3 */
|
||||
#define IP_ADDR0_SERVER 192
|
||||
#define IP_ADDR1_SERVER 168
|
||||
|
@ -106,6 +108,8 @@ typedef x_base sys_prot_t;
|
|||
extern char lwip_ipaddr[];
|
||||
extern char lwip_netmask[];
|
||||
extern char lwip_gwaddr[];
|
||||
extern int is_lwip_test;
|
||||
extern struct netif gnetif;
|
||||
|
||||
void TcpIpInit(void);
|
||||
void lwip_config_net(char *ip, char *mask, char *gw);
|
||||
|
|
Loading…
Reference in New Issue