Browse Source

!160 完善ld文件、mmu、网络测试例程

* update sdk
pull/161/head
wangxiaodong 5 months ago
parent
commit
7c808e326c
  1. 6
      arch/armv8/aarch32/fmmu.c
  2. 1
      arch/armv8/aarch32/gcc/fvectors.S
  3. 20
      doc/ChangeLog.md
  4. BIN
      example/network/lwip_startup/fig/dhcp_example_result.png
  5. BIN
      example/network/lwip_startup/fig/dhcp_ping.png
  6. BIN
      example/network/lwip_startup/fig/ipv4_example_result.png
  7. BIN
      example/network/lwip_startup/fig/ipv6_example_result.png
  8. 1
      example/network/lwip_startup/inc/lwip_dhcp_example.h
  9. 8
      example/network/lwip_startup/main.c
  10. 32
      example/network/lwip_startup/src/lwip_dhcp_example.c
  11. 327
      example/network/raw_api/common/lwip_start.c
  12. 102
      example/network/raw_api/common/raw_api_timer.c
  13. 84
      example/network/raw_api/tcp_client/README.md
  14. 10
      example/network/raw_api/tcp_client/configs/d2000_aarch32_test_tcpclient.config
  15. 10
      example/network/raw_api/tcp_client/configs/d2000_aarch64_test_tcpclient.config
  16. 10
      example/network/raw_api/tcp_client/configs/e2000d_aarch32_demo_tcpclient.config
  17. 10
      example/network/raw_api/tcp_client/configs/e2000d_aarch64_demo_tcpclient.config
  18. 10
      example/network/raw_api/tcp_client/configs/e2000q_aarch32_demo_tcpclient.config
  19. 10
      example/network/raw_api/tcp_client/configs/e2000q_aarch64_demo_tcpclient.config
  20. 10
      example/network/raw_api/tcp_client/configs/ft2004_aarch32_dsk_tcpclient.config
  21. 10
      example/network/raw_api/tcp_client/configs/ft2004_aarch64_dsk_tcpclient.config
  22. 10
      example/network/raw_api/tcp_client/configs/pd2308_aarch64_demo_tcpclient.config
  23. 10
      example/network/raw_api/tcp_client/configs/phytiumpi_aarch32_firefly_tcpclient.config
  24. 10
      example/network/raw_api/tcp_client/configs/phytiumpi_aarch64_firefly_tcpclient.config
  25. BIN
      example/network/raw_api/tcp_client/fig/host_tcp.png
  26. BIN
      example/network/raw_api/tcp_client/fig/menuconfig_select_demo.png
  27. BIN
      example/network/raw_api/tcp_client/fig/tcp_client.png
  28. BIN
      example/network/raw_api/tcp_client/fig/tcp_client_close.png
  29. 57
      example/network/raw_api/tcp_client/inc/lwip_timer.h
  30. 51
      example/network/raw_api/tcp_client/inc/tcp_client_example.h
  31. 63
      example/network/raw_api/tcp_client/main.c
  32. 1
      example/network/raw_api/tcp_client/makefile
  33. 10
      example/network/raw_api/tcp_client/sdkconfig
  34. 10
      example/network/raw_api/tcp_client/sdkconfig.h
  35. 68
      example/network/raw_api/tcp_client/src/cmd_tcp_client.c
  36. 219
      example/network/raw_api/tcp_client/src/lwip_timer.c
  37. 131
      example/network/raw_api/tcp_client/src/tcp_client.c
  38. 291
      example/network/raw_api/tcp_client/src/tcp_client_example.c
  39. 67
      example/network/raw_api/tcp_server/README.md
  40. 10
      example/network/raw_api/tcp_server/configs/d2000_aarch32_test_tcpserver.config
  41. 10
      example/network/raw_api/tcp_server/configs/d2000_aarch64_test_tcpserver.config
  42. 10
      example/network/raw_api/tcp_server/configs/e2000d_aarch32_demo_tcpserver.config
  43. 10
      example/network/raw_api/tcp_server/configs/e2000d_aarch64_demo_tcpserver.config
  44. 10
      example/network/raw_api/tcp_server/configs/e2000q_aarch32_demo_tcpserver.config
  45. 10
      example/network/raw_api/tcp_server/configs/e2000q_aarch64_demo_tcpserver.config
  46. 10
      example/network/raw_api/tcp_server/configs/ft2004_aarch32_dsk_tcpserver.config
  47. 10
      example/network/raw_api/tcp_server/configs/ft2004_aarch64_dsk_tcpserver.config
  48. 10
      example/network/raw_api/tcp_server/configs/pd2308_aarch64_demo_tcpserver.config
  49. 10
      example/network/raw_api/tcp_server/configs/phytiumpi_aarch32_firefly_tcpserver.config
  50. 10
      example/network/raw_api/tcp_server/configs/phytiumpi_aarch64_firefly_tcpserver.config
  51. BIN
      example/network/raw_api/tcp_server/fig/ping_ipv4.png
  52. BIN
      example/network/raw_api/tcp_server/fig/ping_ipv4_dhcp.png
  53. BIN
      example/network/raw_api/tcp_server/fig/ping_ipv6.png
  54. BIN
      example/network/raw_api/tcp_server/fig/probe_ipv4.png
  55. BIN
      example/network/raw_api/tcp_server/fig/probe_ipv4_dhcp.png
  56. BIN
      example/network/raw_api/tcp_server/fig/probe_ipv6.png
  57. BIN
      example/network/raw_api/tcp_server/fig/tcp_server.png
  58. BIN
      example/network/raw_api/tcp_server/fig/tcpserver_host.png
  59. 57
      example/network/raw_api/tcp_server/inc/lwip_timer.h
  60. 51
      example/network/raw_api/tcp_server/inc/tcp_server_example.h
  61. 62
      example/network/raw_api/tcp_server/main.c
  62. 1
      example/network/raw_api/tcp_server/makefile
  63. 10
      example/network/raw_api/tcp_server/sdkconfig
  64. 10
      example/network/raw_api/tcp_server/sdkconfig.h
  65. 69
      example/network/raw_api/tcp_server/src/cmd_tcp_server.c
  66. 219
      example/network/raw_api/tcp_server/src/lwip_timer.c
  67. 92
      example/network/raw_api/tcp_server/src/tcp_server.c
  68. 232
      example/network/raw_api/tcp_server/src/tcp_server_example.c
  69. 67
      example/network/raw_api/udp_client/README.md
  70. 10
      example/network/raw_api/udp_client/configs/d2000_aarch32_test_udpclient.config
  71. 10
      example/network/raw_api/udp_client/configs/d2000_aarch64_test_udpclient.config
  72. 10
      example/network/raw_api/udp_client/configs/e2000d_aarch32_demo_udpclient.config
  73. 10
      example/network/raw_api/udp_client/configs/e2000d_aarch64_demo_udpclient.config
  74. 10
      example/network/raw_api/udp_client/configs/e2000q_aarch32_demo_udpclient.config
  75. 10
      example/network/raw_api/udp_client/configs/e2000q_aarch64_demo_udpclient.config
  76. 10
      example/network/raw_api/udp_client/configs/ft2004_aarch32_dsk_udpclient.config
  77. 10
      example/network/raw_api/udp_client/configs/ft2004_aarch64_dsk_udpclient.config
  78. 10
      example/network/raw_api/udp_client/configs/pd2308_aarch64_demo_udpclient.config
  79. 10
      example/network/raw_api/udp_client/configs/phytiumpi_aarch32_firefly_udpclient.config
  80. 10
      example/network/raw_api/udp_client/configs/phytiumpi_aarch64_firefly_udpclient.config
  81. BIN
      example/network/raw_api/udp_client/fig/ping_ipv4.png
  82. BIN
      example/network/raw_api/udp_client/fig/ping_ipv4_dhcp.png
  83. BIN
      example/network/raw_api/udp_client/fig/ping_ipv6.png
  84. BIN
      example/network/raw_api/udp_client/fig/probe_ipv4.png
  85. BIN
      example/network/raw_api/udp_client/fig/probe_ipv4_dhcp.png
  86. BIN
      example/network/raw_api/udp_client/fig/probe_ipv6.png
  87. BIN
      example/network/raw_api/udp_client/fig/udp_client.png
  88. 57
      example/network/raw_api/udp_client/inc/lwip_timer.h
  89. 51
      example/network/raw_api/udp_client/inc/udp_client_example.h
  90. 64
      example/network/raw_api/udp_client/main.c
  91. 1
      example/network/raw_api/udp_client/makefile
  92. 10
      example/network/raw_api/udp_client/sdkconfig
  93. 10
      example/network/raw_api/udp_client/sdkconfig.h
  94. 68
      example/network/raw_api/udp_client/src/cmd_udp_client.c
  95. 219
      example/network/raw_api/udp_client/src/lwip_timer.c
  96. 83
      example/network/raw_api/udp_client/src/udp_client.c
  97. 215
      example/network/raw_api/udp_client/src/udp_client_example.c
  98. 56
      example/network/raw_api/udp_server/README.md
  99. 10
      example/network/raw_api/udp_server/configs/d2000_aarch32_test_udpserver.config
  100. 10
      example/network/raw_api/udp_server/configs/d2000_aarch64_test_udpserver.config

6
arch/armv8/aarch32/fmmu.c

@ -666,11 +666,6 @@ static void FMmuRemapL1SectionToL2Table(u32 va,
lock_key = FArchIrqLock();
reg_val = AARCH32_READ_SYSREG_32(SCTLR);
AARCH32_WRITE_SYSREG_32(SCTLR,reg_val & (~FMMU_SCTLR_MMU_ENABLE_BIT));
/*
* Clear the entire L1 PTE & re-configure it as a L2 PT reference
* -> already sets the correct values for: zero0, zero1, impl_def.
@ -695,7 +690,6 @@ static void FMmuRemapL1SectionToL2Table(u32 va,
/* Remap complete, re-enable the MMU, unlock the interrupts. */
FMmuInvalidateTlb();
AARCH32_WRITE_SYSREG_32(SCTLR,reg_val);
FArchIrqUnLock(lock_key);
}

1
arch/armv8/aarch32/gcc/fvectors.S

@ -28,7 +28,6 @@
.globl _boot
.globl _vector_table
.weak _vector_table
.globl FiqInterruptHandler
.globl IrqInterruptHandler
.globl SwInterruptHandler

20
doc/ChangeLog.md

@ -1,3 +1,23 @@
# Phytium Standalone SDK 2024-06-14 ChangeLog
Change Log since 2024-06-13
## tools
- refine vector address in ld file
## drivers
- fix mmu config
# Phytium Standalone SDK 2024-06-14 ChangeLog
Change Log since 2024-06-05
## example
- network examples reconfigure to adapt to auto test including lwip-startup and raw-api examples.
# Phytium Standalone SDK 2024-06-13 ChangeLog
Change Log since 2024-06-11

BIN
example/network/lwip_startup/fig/dhcp_example_result.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 205 KiB

After

Width:  |  Height:  |  Size: 27 KiB

BIN
example/network/lwip_startup/fig/dhcp_ping.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 29 KiB

BIN
example/network/lwip_startup/fig/ipv4_example_result.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 134 KiB

After

Width:  |  Height:  |  Size: 17 KiB

BIN
example/network/lwip_startup/fig/ipv6_example_result.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 249 KiB

After

Width:  |  Height:  |  Size: 31 KiB

1
example/network/lwip_startup/inc/lwip_dhcp_example.h

@ -44,6 +44,7 @@ extern "C"
/* entry function for lwip dhcp example */
int LwipDhcpTestCreate(void);
void LwipDhcpTestDeinit(void);
void LwipDhcpTestCheck(void);
#ifdef __cplusplus
}

8
example/network/lwip_startup/main.c

@ -13,13 +13,14 @@
*
* FilePath: main.c
* Created Date: 2023-09-20 11:29:05
* Last Modified: 2023-10-11 15:09:18
* Last Modified: 2024-06-13 16:15:01
* Description: This file is for lwip startup example main functions.
*
* Modify History:
* Ver Who Date Changes
* ----- ---------- -------- ---------------------------------
* 1.0 liuzhihong 2023/10/8 first release
* 1.1 liuzhihong 2024/5/30 add no letter-shell to adapt to auto test
*/
@ -45,15 +46,14 @@ int main()
TimerStaticInit();
LwipIpv4TestCreate();
TimerStaticLoop(10);
LwipIpv4TestDeinit();
LwipIpv6TestCreate();
TimerStaticLoop(10);
LwipIpv6TestDeinit();
LwipDhcpTestCreate();
TimerStaticLoop(10);
TimerStaticLoop(5);
LwipDhcpTestCheck();
LwipDhcpTestDeinit();
#endif

32
example/network/lwip_startup/src/lwip_dhcp_example.c

@ -109,6 +109,22 @@ static void SetIP(ip_addr_t* ipaddr,ip_addr_t* gw,ip_addr_t* netmask,u32 mac_id)
}
static int DhcpService_Is_Sucess()
{
struct netif *netif;
char * ip_addr;
for (int i = 0; i < MAC_NUM; i++)
{
netif = LwipPortGetByName(board_mac_config[i].lwip_mac_config.name);
ip_addr = ipaddr_ntoa(&(netif->ip_addr));
if(strcmp(ip_addr,board_mac_config[i].ipaddr) == 0)
return 0;
}
return 1;
}
int LwipDhcpTestCreate(void)
{
FError ret = FT_SUCCESS;
@ -159,17 +175,27 @@ int LwipDhcpTestCreate(void)
exit:
if (ret == FT_SUCCESS)
{
printf("%s@%d: Lwip dhcp example [success].\r\n", __func__, __LINE__);
printf("%s@%d: Lwip dhcp init [success].\r\n", __func__, __LINE__);
return 0;
}
else
{
printf("%s@%d: Lwip dhcp example [failure].\r\n", __func__, __LINE__);
printf("%s@%d: Lwip dhcp init [failure].\r\n", __func__, __LINE__);
return 1;
}
}
void LwipDhcpTestCheck(void)
{
if(DhcpService_Is_Sucess())
{
printf("%s@%d: Lwip dhcp example [success].\r\n", __func__, __LINE__);
}
else
{
printf("%s@%d: Lwip dhcp example [failure].\r\n", __func__, __LINE__);
}
}
void LwipDhcpTestDeinit(void)
{

327
example/network/raw_api/common/lwip_start.c

@ -1,327 +0,0 @@
/*
* Copyright : (C) 2022 Phytium Information Technology, Inc.
* All Rights Reserved.
*
* This program is OPEN SOURCE software: you can redistribute it and/or modify it
* under the terms of the Phytium Public License as published by the Phytium Technology Co.,Ltd,
* either version 1.0 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the Phytium Public License for more details.
*
*
* FilePath: lwip_start.c
* Date: 2022-11-07 10:16:55
* LastEditTime: 2022-12-06 11:36:50
* Description: This file is for initiailizing a netif.The ip and other infomation can be set manually.
*
* Modify History:
* Ver Who Date Changes
* ----- ------ -------- --------------------------------------
* 1.0 liuzhihong 2022/11/15 first release
* 1.1 liuzhihong 2022/1/9 add functiuon calls in LwipTestLoop:LinkDetectLoop(netif)
*/
#include <string.h>
#include <stdio.h>
#include "strto.h"
#include "sdkconfig.h"
#include "ftypes.h"
#include "fassert.h"
#include "fparameters.h"
#ifndef SDK_CONFIG_H__
#error "Please include sdkconfig.h first"
#endif
#include "lwipopts.h"
#include "lwip_port.h"
#include "lwip/ip4_addr.h"
#include "lwip/init.h"
#include "netif/ethernet.h"
#include "lwip/netif.h"
#include "lwip/tcpip.h"
#include "lwip/inet.h"
#include "shell_port.h"
#if LWIP_IPV6
#include "lwip/ip.h"
#include "lwip/ip6_addr.h"
#else
#if LWIP_DHCP
#include "lwip/dhcp.h"
#endif
#endif
typedef struct
{
const char *ipaddr;
const char *gateway;
const char *netmask;
} InputAddress;
typedef struct
{
UserConfig lwip_mac_config;
InputAddress input_address;
u32 dhcp_en;
} InputConfig;
InputConfig input_config = {0};
static boolean init_flag = FALSE;
void LwipTestCreate(void *args)
{
FASSERT(args != NULL);
struct netif *netif_p = NULL;
InputConfig *input_conf = (InputConfig *)args;
ip_addr_t ipaddr = {0}, netmask = {0}, gw = {0};
/* the mac address of the board. this should be unique per board */
unsigned char mac_address[6] =
{0x98, 0x0e, 0x24, 0x00, 0x11, 0};
netif_p = malloc(sizeof(struct netif));
if (netif_p == NULL)
{
printf("Malloc netif is error.\r\n");
goto exit;
}
printf("netif_p is %p \r\n", netif_p);
mac_address[5] = input_conf->lwip_mac_config.mac_instance;
/* convert string to a binary address */
if (input_conf->input_address.ipaddr)
{
if (inet_aton(input_conf->input_address.ipaddr, &ipaddr) == 0)
{
goto failed;
}
}
if (input_conf->input_address.gateway)
{
if (inet_aton(input_conf->input_address.gateway, &gw) == 0)
{
goto failed;
}
}
if (input_conf->input_address.netmask)
{
if (inet_aton(input_conf->input_address.netmask, &netmask) == 0)
{
goto failed;
}
}
/* 初始化LwIP堆 */
if (init_flag == FALSE)
{
lwip_init(); /* lwip only init once */
init_flag = TRUE;
}
/* Add network interface to the netif_list, and set it as default */
if (!LwipPortAdd(netif_p, &ipaddr, &netmask, &gw, mac_address, (UserConfig *)args))
{
printf("Error adding N/W interface\n\r");
return ;
}
printf("LwipPortAdd is over \n\r");
#if LWIP_IPV6
netif_p->ip6_autoconfig_enabled = 1;
netif_create_ip6_linklocal_address(netif_p, 1);
netif_ip6_addr_set_state(netif_p, 0, IP6_ADDR_VALID);
#endif
netif_set_default(netif_p);
if (netif_is_link_up(netif_p))
{
/* 当netif完全配置好时,必须调用该函数 */
netif_set_up(netif_p);
if (input_conf->dhcp_en == 1)
{
LwipPortDhcpSet(netif_p, TRUE);
}
}
else
{
/* 当netif链接关闭时,必须调用该函数 */
netif_set_down(netif_p);
}
printf("Network setup complete.\n");
goto exit ;
failed:
printf("Failed \r\n");
free(netif_p);
exit:
return;
}
void LwipTestInint(void *args)
{
LwipTestCreate(args);
}
void LwipTestLoop(void)
{
struct netif *netif;
if (init_flag == FALSE)
{
return;
}
netif = netif_list;
while (netif != NULL)
{
if (netif->state)
{
LwipPortInput(netif);
LinkDetectLoop(netif);
}
netif = netif->next;
}
}
void LwipTestDhcpLoop(u32 msec)
{
#if (LWIP_DHCP==1)
LwipPortDhcpLoop(msec);
#endif
}
static int LwipDeviceSet(int argc, char *argv[])
{
u32 id = 0, interface_type = 0, driver_type = 0;
memset(&input_config, 0, sizeof(input_config));
LWIP_PORT_CONFIG_DEFAULT_INIT(input_config.lwip_mac_config);
if (!strcmp(argv[1], "probe"))
{
if (argc < 6)
{
printf("Input error: Too few parameters!\n");
printf("All parameters will be set to 0!\n");
}
else
{
driver_type = (u32)simple_strtoul(argv[2], NULL, 10);
id = (u32)simple_strtoul(argv[3], NULL, 10);
interface_type = (u32)simple_strtoul(argv[4], NULL, 10);
input_config.dhcp_en = (u32)simple_strtoul(argv[5], NULL, 10);
if (input_config.dhcp_en == 0)
{
if (argc == 9)
{
input_config.input_address.ipaddr = argv[6];
input_config.input_address.gateway = argv[7];
input_config.input_address.netmask = argv[8];
}
else
{
printf("Input error: Missing parameters!\n");
printf("All Ip address will be set to 0!\n");
}
}
else
{
if (argc == 9)
{
input_config.input_address.ipaddr = argv[6];
input_config.input_address.gateway = argv[7];
input_config.input_address.netmask = argv[8];
}
printf("Dhcp Open: All IP addresses will be determined by the dhcp server!\n");
}
}
input_config.lwip_mac_config.mac_instance = id;
input_config.lwip_mac_config.name[0] = 'e';
itoa(id, &input_config.lwip_mac_config.name[1], 10);
const char *name = input_config.lwip_mac_config.name;
if (LwipPortGetByName(name))
{
printf("Netif alread exist! \r\n");
return -1;
}
if (interface_type == 0)
{
input_config.lwip_mac_config.mii_interface = LWIP_PORT_INTERFACE_RGMII;
}
else
{
input_config.lwip_mac_config.mii_interface = LWIP_PORT_INTERFACE_SGMII;
}
if (driver_type == 0)
{
input_config.lwip_mac_config.driver_type = LWIP_PORT_TYPE_XMAC;
}
else
{
input_config.lwip_mac_config.driver_type = LWIP_PORT_TYPE_GMAC;
}
LwipTestInint(&input_config);
}
else if (!strcmp(argv[1], "deinit"))
{
if (argc <= 1)
{
printf("Please enter lwip deinit <name>\r\n") ;
printf(" -- use name to deinit neitf object\r\n");
printf(" -- <name> is netif name\r\n");
return -1;
}
struct netif *netif_p = NULL;
netif_p = LwipPortGetByName(argv[2]);
if (netif_p == NULL)
{
printf("netif %s is not invalid.\r\n", argv[2]);
return -1;
}
/* close netif */
LwipPortStop(netif_p,input_config.dhcp_en);
free(netif_p);
}
else
{
printf("Please enter lwip probe <dirver id> <device id> <interface id> <dhcp_en> <ipaddr> <gateway> <netmask> \r\n") ;
printf(" -- driver id is driver type set, 0 is xmac ,1 is gmac \r\n");
printf(" -- device id is mac instance number \r\n");
printf(" -- interface id is media independent interface , 0 is rgmii ,1 is sgmii \r\n");
printf(" -- dhcp_en is dhcp function set ,1 is enable ,0 is disable .But this depends on whether the protocol stack supports it ");
printf(" -- <ipaddr> Ip address of netif \r\n");
printf(" -- <gateway> Gateway of netif \r\n");
printf(" -- <netmask> Netmask of netif \r\n");
printf("Please enter lwip deinit <name> \r\n") ;
printf(" -- use name to deinit neitf object \r\n");
printf(" -- <name> is netif name \r\n");
}
return 0;
}
SHELL_EXPORT_CMD(SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN), lwip, LwipDeviceSet, Setup LWIP device test);

102
example/network/raw_api/common/raw_api_timer.c

@ -1,102 +0,0 @@
/*
* Copyright : (C) 2022 Phytium Information Technology, Inc.
* All Rights Reserved.
*
* This program is OPEN SOURCE software: you can redistribute it and/or modify it
* under the terms of the Phytium Public License as published by the Phytium Technology Co.,Ltd,
* either version 1.0 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the Phytium Public License for more details.
*
*
* FilePath: raw_api_timer.c
* Date: 2022-11-01 15:52:09
* LastEditTime: 2022-11-01 15:52:10
* Description: This file is for create a timer.The timer can keep the netif receiveing message periodically.
*
* Modify History:
* Ver Who Date Changes
* ----- ------ -------- --------------------------------------
* 1.0 liuzhihong 2022/11/15 first release
* 1.1 liuzhihong 2022/11/23 add func sys_now()
* 1.2 liuzhihong 2022/1/9 u64 -> u32
*/
#include "fgeneric_timer.h"
#include "fparameters.h"
#include "finterrupt.h"
#include "fassert.h"
#include "shell_port.h"
#include "timeouts.h"
#define TIMER_BASE_RATE_HZ 1000
#define TIMER_INTERRUPT_PRO IRQ_PRIORITY_VALUE_3
static u32 timer_base_cnt = 0;
extern void LwipTestLoop(void);
extern void LwipTestDhcpLoop(u32 msec);
static void GenericTimerIntrHandler(s32 vector, void *param)
{
(void)vector;
FASSERT(param != 0);
u32 timer_base_freq = (u32)(uintptr)param;
timer_base_cnt++;
GenericTimerSetTimerValue(GENERIC_TIMER_ID0, GenericTimerFrequecy() / timer_base_freq);/* clear tick interrupt */
}
void TimerLoopInit(void)
{
u32 cnt_frq;
timer_base_cnt = 0;
/* disable timer and get system frequency */
GenericTimerStop(GENERIC_TIMER_ID0);
cnt_frq = GenericTimerFrequecy();
/* set tick rate */
GenericTimerSetTimerValue(GENERIC_TIMER_ID0, cnt_frq / TIMER_BASE_RATE_HZ);
GenericTimerInterruptEnable(GENERIC_TIMER_ID0);
/* set generic timer interrupt */
InterruptSetPriority(GENERIC_TIMER_NS_IRQ_NUM, TIMER_INTERRUPT_PRO);
/* install tick handler */
InterruptInstall(GENERIC_TIMER_NS_IRQ_NUM, GenericTimerIntrHandler,
(void *)TIMER_BASE_RATE_HZ, "GenericTimerTick");
/* enable interrupt */
InterruptUmask(GENERIC_TIMER_NS_IRQ_NUM);
GenericTimerStart(GENERIC_TIMER_ID0);
}
void TimerLoop(void)
{
static u32 _5ms_appear = 0;
TimerLoopInit();
LSUserShellInit();
while (1)
{
LSuserShellNoWaitLoop();
LwipTestLoop();
if (((timer_base_cnt % 5) == 0) && (_5ms_appear == 0)) /*5ms task */
{
_5ms_appear = 1;
LwipTestDhcpLoop(5);
}
else if ((timer_base_cnt % 5) != 0)
{
_5ms_appear = 0;
}
sys_check_timeouts();
}
}
u32_t sys_now(void)
{
return timer_base_cnt;
}

84
example/network/raw_api/tcp_client/README.md

@ -4,46 +4,43 @@
> `<font size="1">`介绍例程的用途,使用场景,相关基本概念,描述用户可以使用例程完成哪些工作`</font><br />`
本例程利用LWIP网络协议栈中的raw api实现了下述功能:
本例程示范了MAC控制器在lwip ipv4模式下的初始化流程,同时通过LWIP网络协议栈中的raw api,可以实现网卡作为client,利用tcp与外界进行通信。
- LWIP网络协议栈初始化
### 1.1 TCP Client特性测试例程 (tcp_client_example.c)
- ipv4模式下初始化开发板上所有网口以及对应网卡控制器
- 建立开发板到主机的tcp连接
- 开发板周期性向网络主机发送数据包
- 开发板向网络主机发送数据包
- 网络主机在屏幕端打印收到的数据
- 开发板发送一次数据后,主动断开与主机的tcp连接
## 2. 如何使用例程
> `<font size="1">`描述开发平台准备,使用例程配置,构建和下载镜像的过程`</font><br />`
- 本例程在E2000上测试通过,您可以参考以下方法配置本例程所需要的硬件和软件环境
本例程需要以下硬件:
- E2000D/Q Demo板,FT2000/4开发板,D2000开发板,PhytiumPi
- 串口线和串口上位机
### 2.1 硬件配置方法
> `<font size="1">`哪些硬件平台是支持的,需要哪些外设,例程与开发板哪些IO口相关等(建议附录开发板照片,展示哪些IO口被引出)`</font><br />`
本例程支持以下硬件平台
- FT2000/4
- D2000开发板
- E2000 系列开发板
D2000开发板图片示例如下:
D2000开发板图片示例
![board](./fig/board.png)
DEMO开发板图片示例如下所示
E2000Q DEMO开发板图片示例
![demo_board](./fig/demo_board.jpg)
### 2.2 SDK配置方法
> `<font size="1">`依赖哪些驱动、库和第三方组件,如何完成配置(列出需要使能的关键配置项)`</font><br />`
本例程需要,
本例程需要:
- LWIP组件,依赖 USE_LWIP
- Letter Shell组件,依赖 USE_LETTER_SHELL
对应的配置项是,
对应的配置项是:
- CONFIG_USE_LWIP
- CONFIG_USE_LETTER_SHELL
@ -67,7 +64,7 @@ DEMO开发板图片示例如下所示
#### 2.3.1 构建过程
本文档将以E2000demo开发板为例,对于其它平台,使用对应的默认配置
本文档将以E2000d demo开发板为例,对于其它平台,使用对应的默认配置
- 在host端完成配置
- 选择目标平台
@ -116,28 +113,7 @@ bootelf -p 0x90100000
> `<font size="1">`描述输入输出情况,列出存在哪些输出,对应的输出是什么(建议附录相关现象图片)`</font><br />`
- 启动进入后,根据连接的网口,输入指令完成网口初始化
#### 2.4.1 初始化LWIP网络协议栈
- 输入以下命令,初始化LWIP网络协议栈, 依次设置网卡和dhcp使能,配置ip地址,子网掩码,网关地址,运行完成退出后LWIP协议栈会持续运行
- lwip probe 指令介绍
```
lwip probe <driver id> <device id> <interface id> <dhcp_en> <ipaddr> <gateway> <netmask>
```
- 其中driver id 为驱动类型 , 0为xmac ,1为gmac
- device id 为控制器id
- interface id ,0 为rgmii ,1 为sgmii
- dhcp en,0 表示关闭dhcp功能,1表示开启dhcp功能,网卡将根据dhcp协议获得ip地址(当协议栈支持dhcp时,该参数才具有实际作用)
- 输入以下命令,初始化LWIP网络协议栈, 依次设置网卡和dhcp使能,配置ip地址,子网掩码,网关地址,运行完成退出后LWIP协议栈会持续运行
```
$ lwip probe 0 0 1 0 192.168.4.10 192.168.4.1 255.255.255.0
```
#### 2.4.2 开启tcpclient
#### 2.4.1 TCP Client特性测试例程 (tcp_client_example.c)
- 首先在host端开启tcp服务器,输入以下命令
@ -147,26 +123,14 @@ nc -l 192.168.4.50 5001
- 接着在开发板端输入以下命令,开始tcp client 测试
```
$ tcpclient
tcpclient
```
- tcpclient 周期发送数据到主机的tcp服务器
- tcpclient 发送数据到主机的tcp服务器,并在发送数据后,主动断开连接
- 开发板实验输出结果
![tcpclient](./fig/tcp_client.png)
- 主机端实验输出结果
![host-tcp](./fig/host_tcp.png)
#### 2.4.3 关闭tcpclient
- 输入以下命令,关闭tcp client 测试 结束tcp连接
```
$ tcpclientclose
```
- 开发板实验结果
![tcpclientclose](./fig/tcp_client_close.png)
## 3. 如何解决问题
> `<font size="1">`主要记录使用例程中可能会遇到的问题,给出相应的解决方案`</font><br />`
@ -175,17 +139,17 @@ $ tcpclientclose
- A: 不可行!此时开发板程序会自我终止tcp连接,释放tcp相关资源。如果想重新连接服务器,需要先打开tcp服务器,再在开发板中输入tcp_client命令,确保例程正常运行;
- Q: 如何配置tcp client的local ip与local port以及remote ip 与remote port?
- A: 在tcp_client.c中修改如下变量tmp_ip以及修改宏定义TCP_CLIENT_PORT,TCP_SERVER_PORT即可:
- A: 在tcp_client_example.c中修改变量local_ip、remote_ip以及修改宏定义TCP_CLIENT_PORT,TCP_SERVER_PORT即可:
```
#define TCP_CLIENT_PORT 0
#define TCP_SERVER_PORT 5001
#define TCP_CLIENT_PORT 5001
#define TCP_SERVER_PORT 5001
......
IP_ADDR4(&tmp_ip, 192, 168, 4, 10);
tcp_bind(client_pcb, &tmp_ip, TCP_CLIENT_PORT);
IP_ADDR4(&tmp_ip, 192, 168, 4, 50);
ret = tcp_connect(client_pcb, &tmp_ip, TCP_SERVER_PORT, client_connected);
IP_ADDR4(&local_ip, 192, 168, 4, 10);
tcp_bind(client_pcb, &local_ip, TCP_CLIENT_PORT);
IP_ADDR4(&remote_ip, 192, 168, 4, 50);
ret = tcp_connect(client_pcb, &remote_ip, TCP_SERVER_PORT, client_connected_callback);
```
## 4. 修改历史记录

10
example/network/raw_api/tcp_client/configs/d2000_aarch32_test_tcpclient.config

@ -234,7 +234,13 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# DHCP
#
# CONFIG_LWIP_DHCP_ENABLE is not set
CONFIG_LWIP_DHCP_ENABLE=y
# CONFIG_LWIP_DHCP_DOES_ARP_CHECK is not set
# CONFIG_LWIP_DHCP_GET_NTP_SRV is not set
# CONFIG_LWIP_DHCP_DISABLE_CLIENT_ID is not set
# CONFIG_LWIP_DHCP_RESTORE_LAST_IP is not set
CONFIG_LWIP_DHCP_OPTIONS_LEN=68
CONFIG_LWIP_DHCP_DISABLE_VENDOR_CLASS_ID=y
# end of DHCP
#
@ -246,7 +252,7 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# IGMP
#
CONFIG_LWIP_IGMP_EN=y
# CONFIG_LWIP_IGMP_EN is not set
# end of IGMP
#

10
example/network/raw_api/tcp_client/configs/d2000_aarch64_test_tcpclient.config

@ -228,7 +228,13 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# DHCP
#
# CONFIG_LWIP_DHCP_ENABLE is not set
CONFIG_LWIP_DHCP_ENABLE=y
# CONFIG_LWIP_DHCP_DOES_ARP_CHECK is not set
# CONFIG_LWIP_DHCP_GET_NTP_SRV is not set
# CONFIG_LWIP_DHCP_DISABLE_CLIENT_ID is not set
# CONFIG_LWIP_DHCP_RESTORE_LAST_IP is not set
CONFIG_LWIP_DHCP_OPTIONS_LEN=68
CONFIG_LWIP_DHCP_DISABLE_VENDOR_CLASS_ID=y
# end of DHCP
#
@ -240,7 +246,7 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# IGMP
#
CONFIG_LWIP_IGMP_EN=y
# CONFIG_LWIP_IGMP_EN is not set
# end of IGMP
#

10
example/network/raw_api/tcp_client/configs/e2000d_aarch32_demo_tcpclient.config

@ -247,7 +247,13 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# DHCP
#
# CONFIG_LWIP_DHCP_ENABLE is not set
CONFIG_LWIP_DHCP_ENABLE=y
# CONFIG_LWIP_DHCP_DOES_ARP_CHECK is not set
# CONFIG_LWIP_DHCP_GET_NTP_SRV is not set
# CONFIG_LWIP_DHCP_DISABLE_CLIENT_ID is not set
# CONFIG_LWIP_DHCP_RESTORE_LAST_IP is not set
CONFIG_LWIP_DHCP_OPTIONS_LEN=68
CONFIG_LWIP_DHCP_DISABLE_VENDOR_CLASS_ID=y
# end of DHCP
#
@ -259,7 +265,7 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# IGMP
#
CONFIG_LWIP_IGMP_EN=y
# CONFIG_LWIP_IGMP_EN is not set
# end of IGMP
#

10
example/network/raw_api/tcp_client/configs/e2000d_aarch64_demo_tcpclient.config

@ -241,7 +241,13 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# DHCP
#
# CONFIG_LWIP_DHCP_ENABLE is not set
CONFIG_LWIP_DHCP_ENABLE=y
# CONFIG_LWIP_DHCP_DOES_ARP_CHECK is not set
# CONFIG_LWIP_DHCP_GET_NTP_SRV is not set
# CONFIG_LWIP_DHCP_DISABLE_CLIENT_ID is not set
# CONFIG_LWIP_DHCP_RESTORE_LAST_IP is not set
CONFIG_LWIP_DHCP_OPTIONS_LEN=68
CONFIG_LWIP_DHCP_DISABLE_VENDOR_CLASS_ID=y
# end of DHCP
#
@ -253,7 +259,7 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# IGMP
#
CONFIG_LWIP_IGMP_EN=y
# CONFIG_LWIP_IGMP_EN is not set
# end of IGMP
#

10
example/network/raw_api/tcp_client/configs/e2000q_aarch32_demo_tcpclient.config

@ -246,7 +246,13 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# DHCP
#
# CONFIG_LWIP_DHCP_ENABLE is not set
CONFIG_LWIP_DHCP_ENABLE=y
# CONFIG_LWIP_DHCP_DOES_ARP_CHECK is not set
# CONFIG_LWIP_DHCP_GET_NTP_SRV is not set
# CONFIG_LWIP_DHCP_DISABLE_CLIENT_ID is not set
# CONFIG_LWIP_DHCP_RESTORE_LAST_IP is not set
CONFIG_LWIP_DHCP_OPTIONS_LEN=68
CONFIG_LWIP_DHCP_DISABLE_VENDOR_CLASS_ID=y
# end of DHCP
#
@ -258,7 +264,7 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# IGMP
#
CONFIG_LWIP_IGMP_EN=y
# CONFIG_LWIP_IGMP_EN is not set
# end of IGMP
#

10
example/network/raw_api/tcp_client/configs/e2000q_aarch64_demo_tcpclient.config

@ -240,7 +240,13 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# DHCP
#
# CONFIG_LWIP_DHCP_ENABLE is not set
CONFIG_LWIP_DHCP_ENABLE=y
# CONFIG_LWIP_DHCP_DOES_ARP_CHECK is not set
# CONFIG_LWIP_DHCP_GET_NTP_SRV is not set
# CONFIG_LWIP_DHCP_DISABLE_CLIENT_ID is not set
# CONFIG_LWIP_DHCP_RESTORE_LAST_IP is not set
CONFIG_LWIP_DHCP_OPTIONS_LEN=68
CONFIG_LWIP_DHCP_DISABLE_VENDOR_CLASS_ID=y
# end of DHCP
#
@ -252,7 +258,7 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# IGMP
#
CONFIG_LWIP_IGMP_EN=y
# CONFIG_LWIP_IGMP_EN is not set
# end of IGMP
#

10
example/network/raw_api/tcp_client/configs/ft2004_aarch32_dsk_tcpclient.config

@ -234,7 +234,13 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# DHCP
#
# CONFIG_LWIP_DHCP_ENABLE is not set
CONFIG_LWIP_DHCP_ENABLE=y
# CONFIG_LWIP_DHCP_DOES_ARP_CHECK is not set
# CONFIG_LWIP_DHCP_GET_NTP_SRV is not set
# CONFIG_LWIP_DHCP_DISABLE_CLIENT_ID is not set
# CONFIG_LWIP_DHCP_RESTORE_LAST_IP is not set
CONFIG_LWIP_DHCP_OPTIONS_LEN=68
CONFIG_LWIP_DHCP_DISABLE_VENDOR_CLASS_ID=y
# end of DHCP
#
@ -246,7 +252,7 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# IGMP
#
CONFIG_LWIP_IGMP_EN=y
# CONFIG_LWIP_IGMP_EN is not set
# end of IGMP
#

10
example/network/raw_api/tcp_client/configs/ft2004_aarch64_dsk_tcpclient.config

@ -228,7 +228,13 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# DHCP
#
# CONFIG_LWIP_DHCP_ENABLE is not set
CONFIG_LWIP_DHCP_ENABLE=y
# CONFIG_LWIP_DHCP_DOES_ARP_CHECK is not set
# CONFIG_LWIP_DHCP_GET_NTP_SRV is not set
# CONFIG_LWIP_DHCP_DISABLE_CLIENT_ID is not set
# CONFIG_LWIP_DHCP_RESTORE_LAST_IP is not set
CONFIG_LWIP_DHCP_OPTIONS_LEN=68
CONFIG_LWIP_DHCP_DISABLE_VENDOR_CLASS_ID=y
# end of DHCP
#
@ -240,7 +246,7 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# IGMP
#
CONFIG_LWIP_IGMP_EN=y
# CONFIG_LWIP_IGMP_EN is not set
# end of IGMP
#

10
example/network/raw_api/tcp_client/configs/pd2308_aarch64_demo_tcpclient.config

@ -237,7 +237,13 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# DHCP
#
# CONFIG_LWIP_DHCP_ENABLE is not set
CONFIG_LWIP_DHCP_ENABLE=y
# CONFIG_LWIP_DHCP_DOES_ARP_CHECK is not set
# CONFIG_LWIP_DHCP_GET_NTP_SRV is not set
# CONFIG_LWIP_DHCP_DISABLE_CLIENT_ID is not set
# CONFIG_LWIP_DHCP_RESTORE_LAST_IP is not set
CONFIG_LWIP_DHCP_OPTIONS_LEN=68
CONFIG_LWIP_DHCP_DISABLE_VENDOR_CLASS_ID=y
# end of DHCP
#
@ -249,7 +255,7 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# IGMP
#
CONFIG_LWIP_IGMP_EN=y
# CONFIG_LWIP_IGMP_EN is not set
# end of IGMP
#

10
example/network/raw_api/tcp_client/configs/phytiumpi_aarch32_firefly_tcpclient.config

@ -245,7 +245,13 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# DHCP
#
# CONFIG_LWIP_DHCP_ENABLE is not set
CONFIG_LWIP_DHCP_ENABLE=y
# CONFIG_LWIP_DHCP_DOES_ARP_CHECK is not set
# CONFIG_LWIP_DHCP_GET_NTP_SRV is not set
# CONFIG_LWIP_DHCP_DISABLE_CLIENT_ID is not set
# CONFIG_LWIP_DHCP_RESTORE_LAST_IP is not set
CONFIG_LWIP_DHCP_OPTIONS_LEN=68
CONFIG_LWIP_DHCP_DISABLE_VENDOR_CLASS_ID=y
# end of DHCP
#
@ -257,7 +263,7 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# IGMP
#
CONFIG_LWIP_IGMP_EN=y
# CONFIG_LWIP_IGMP_EN is not set
# end of IGMP
#

10
example/network/raw_api/tcp_client/configs/phytiumpi_aarch64_firefly_tcpclient.config

@ -239,7 +239,13 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# DHCP
#
# CONFIG_LWIP_DHCP_ENABLE is not set
CONFIG_LWIP_DHCP_ENABLE=y
# CONFIG_LWIP_DHCP_DOES_ARP_CHECK is not set
# CONFIG_LWIP_DHCP_GET_NTP_SRV is not set
# CONFIG_LWIP_DHCP_DISABLE_CLIENT_ID is not set
# CONFIG_LWIP_DHCP_RESTORE_LAST_IP is not set
CONFIG_LWIP_DHCP_OPTIONS_LEN=68
CONFIG_LWIP_DHCP_DISABLE_VENDOR_CLASS_ID=y
# end of DHCP
#
@ -251,7 +257,7 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# IGMP
#
CONFIG_LWIP_IGMP_EN=y
# CONFIG_LWIP_IGMP_EN is not set
# end of IGMP
#

BIN
example/network/raw_api/tcp_client/fig/host_tcp.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 12 KiB

BIN
example/network/raw_api/tcp_client/fig/menuconfig_select_demo.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

BIN
example/network/raw_api/tcp_client/fig/tcp_client.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 34 KiB

BIN
example/network/raw_api/tcp_client/fig/tcp_client_close.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

57
example/network/raw_api/tcp_client/inc/lwip_timer.h

@ -0,0 +1,57 @@
/*
* Copyright : (C) 2024 Phytium Information Technology, Inc.
* All Rights Reserved.
*
* This program is OPEN SOURCE software: you can redistribute it and/or modify it
* under the terms of the Phytium Public License as published by the Phytium Technology Co.,Ltd,
* either version 1.0 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the Phytium Public License for more details.
*
*
* FilePath: lwip_timer.h
* Created Date: 2024-06-06 11:28:12
* Last Modified: 2024-06-12 17:38:26
* Description: This file is for lwip timer function definition.
*
* Modify History:
* Ver Who Date Changes
* ----- ---------- -------- ---------------------------------
* 1.0 liuzhihong 2024/06/06 first release
*/
#ifndef LWIP_TIMER_H
#define LWIP_TIMER_H
/***************************** Include Files *********************************/
#include "ftypes.h"
#ifdef __cplusplus
extern "C"
{
#endif
/************************** Constant Definitions *****************************/
/**************************** Type Definitions *******************************/
/************************** Variable Definitions *****************************/
/***************** Macros (Inline Functions) Definitions *********************/
/************************** Function Prototypes ******************************/
/* entry function for lwip timer example */
#ifdef CONFIG_USE_LETTER_SHELL
void TimerLoop(void);
#else
void TimerStaticInit(void);
void TimerStaticLoop(u32 time);
#endif
#ifdef __cplusplus
}
#endif
#endif

51
example/network/raw_api/tcp_client/inc/tcp_client_example.h

@ -0,0 +1,51 @@
/*
* Copyright : (C) 2024 Phytium Information Technology, Inc.
* All Rights Reserved.
*
* This program is OPEN SOURCE software: you can redistribute it and/or modify it
* under the terms of the Phytium Public License as published by the Phytium Technology Co.,Ltd,
* either version 1.0 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the Phytium Public License for more details.
*
*
* FilePath: tcp_client_example.h
* Created Date: 2024-06-06 11:28:27
* Last Modified: 2024-06-12 17:34:42
* Description: This file is for tcp client example function definition.
*
* Modify History:
* Ver Who Date Changes
* ----- ---------- -------- ---------------------------------
* 1.0 liuzhihong 2024/06/06 first release
*/
#ifndef TCP_CLIENT_EXAMPLE_H
#define TCP_CLIENT_EXAMPLE_H
/***************************** Include Files *********************************/
#include "ftypes.h"
#ifdef __cplusplus
extern "C"
{
#endif
/************************** Constant Definitions *****************************/
/**************************** Type Definitions *******************************/
/************************** Variable Definitions *****************************/
/***************** Macros (Inline Functions) Definitions *********************/
/************************** Function Prototypes ******************************/
/* entry function for tcp server example */
int TcpClientCreate(void);
void TcpClientDeinit(void);
#ifdef __cplusplus
}
#endif
#endif

63
example/network/raw_api/tcp_client/main.c

@ -1,39 +1,64 @@
/*
* Copyright : (C) 2022 Phytium Information Technology, Inc.
* Copyright : (C) 2024 Phytium Information Technology, Inc.
* All Rights Reserved.
*
*
* This program is OPEN SOURCE software: you can redistribute it and/or modify it
* under the terms of the Phytium Public License as published by the Phytium Technology Co.,Ltd,
* either version 1.0 of the License, or (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the Phytium Public License for more details.
*
*
*
*
* FilePath: main.c
* Date: 2022-02-10 14:53:41
* LastEditTime: 2022-02-17 17:38:03
* Description:  This file is for creating a main loop from which the programme will start.
*
* Modify History:
* Ver Who Date Changes
* ----- ------ -------- --------------------------------------
* 1.0 liuzhihong 2022/11/23 first release
* Created Date: 2024-05-30 19:05:18
* Last Modified: 2024-06-12 17:55:22
* Description: This file is for tcp client example main functions.
*
* Modify History:
* Ver Who Date Changes
* ----- ---------- -------- ---------------------------------
* 1.0 liuzhihong 2024/06/03 first release
*/
#include <string.h>
#include <stdio.h>
#include "sdkconfig.h"
#ifndef SDK_CONFIG_H__
#warning "Please include sdkconfig.h"
#endif
#ifndef CONFIG_USE_LETTER_SHELL
#error "Please include letter shell first!!!"
#ifdef CONFIG_USE_LETTER_SHELL
#include "shell_port.h"
#endif
extern void TimerLoop(void);
#include "tcp_client_example.h"
#include "lwip_timer.h"
/************************** Constant Definitions *****************************/
/**************************** Type Definitions *******************************/
/************************** Variable Definitions *****************************/
/***************** Macros (Inline Functions) Definitions *********************/
/************************** Function Prototypes ******************************/
/************************** Function *****************************************/
int main()
{
TimerLoop();
#ifdef CONFIG_USE_LETTER_SHELL
/* if shell command is enabled, register example entry as shell command */
TimerLoop();
#else
TimerStaticInit();
TimerStaticLoop(2);
TcpClientCreate();
TimerStaticLoop(10);
TcpClientDeinit();
#endif
return 0;
}

1
example/network/raw_api/tcp_client/makefile

@ -3,7 +3,6 @@ SDK_DIR ?= $(CURDIR)/../../../..
USER_CSRC := main.c
USER_CSRC += $(wildcard src/*.c)
USER_CSRC += $(wildcard ../common/*.c)
USER_INCLUDE := $(PROJECT_DIR) \
$(PROJECT_DIR)/inc \

10
example/network/raw_api/tcp_client/sdkconfig

@ -239,7 +239,13 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# DHCP
#
# CONFIG_LWIP_DHCP_ENABLE is not set
CONFIG_LWIP_DHCP_ENABLE=y
# CONFIG_LWIP_DHCP_DOES_ARP_CHECK is not set
# CONFIG_LWIP_DHCP_GET_NTP_SRV is not set
# CONFIG_LWIP_DHCP_DISABLE_CLIENT_ID is not set
# CONFIG_LWIP_DHCP_RESTORE_LAST_IP is not set
CONFIG_LWIP_DHCP_OPTIONS_LEN=68
CONFIG_LWIP_DHCP_DISABLE_VENDOR_CLASS_ID=y
# end of DHCP
#
@ -251,7 +257,7 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# IGMP
#
CONFIG_LWIP_IGMP_EN=y
# CONFIG_LWIP_IGMP_EN is not set
# end of IGMP
#

10
example/network/raw_api/tcp_client/sdkconfig.h

@ -212,7 +212,13 @@
/* DHCP */
/* CONFIG_LWIP_DHCP_ENABLE is not set */
#define CONFIG_LWIP_DHCP_ENABLE
/* CONFIG_LWIP_DHCP_DOES_ARP_CHECK is not set */
/* CONFIG_LWIP_DHCP_GET_NTP_SRV is not set */
/* CONFIG_LWIP_DHCP_DISABLE_CLIENT_ID is not set */
/* CONFIG_LWIP_DHCP_RESTORE_LAST_IP is not set */
#define CONFIG_LWIP_DHCP_OPTIONS_LEN 68
#define CONFIG_LWIP_DHCP_DISABLE_VENDOR_CLASS_ID
/* end of DHCP */
/* AUTOIP */
@ -222,7 +228,7 @@
/* IGMP */
#define CONFIG_LWIP_IGMP_EN
/* CONFIG_LWIP_IGMP_EN is not set */
/* end of IGMP */
/* DNS */

68
example/network/raw_api/tcp_client/src/cmd_tcp_client.c

@ -0,0 +1,68 @@
/*
* Copyright : (C) 2024 Phytium Information Technology, Inc.
* All Rights Reserved.
*
* This program is OPEN SOURCE software: you can redistribute it and/or modify it
* under the terms of the Phytium Public License as published by the Phytium Technology Co.,Ltd,
* either version 1.0 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the Phytium Public License for more details.
*
*
* FilePath: cmd_tcp_client.c
* Created Date: 2024-06-06 11:30:42
* Last Modified: 2024-06-12 17:34:52
* Description: This file is for tcp client example cmd catalogue.
*
* Modify History:
* Ver Who Date Changes
* ----- ---------- -------- ---------------------------------
* 1.0 liuzhihong 2024/06/06 first release
*/
#include <stdio.h>
#include <string.h>
#include "sdkconfig.h"
#ifndef SDK_CONFIG_H__
#warning "Please include sdkconfig.h"
#endif
#ifdef CONFIG_USE_LETTER_SHELL
#include "shell.h"
#include "strto.h"
#include "tcp_client_example.h"
#define EXAMPLE_IDLE 0
#define TCP_CLIENT_EXAMPLE_RUNNING 1
static u32 init_flag_mask=EXAMPLE_IDLE;
static void TcpClientExampleCheckState(void)
{
switch(init_flag_mask)
{
case TCP_CLIENT_EXAMPLE_RUNNING:
printf("Tcp client example is running, we need to deinitialize it first! \r\n");
TcpClientDeinit();
init_flag_mask=EXAMPLE_IDLE;
break;
default:
break;
}
}
/* entry function for tcp client example */
static int TcpClientExampleEntry(int argc, char *argv[])
{
int ret = 0;
TcpClientExampleCheckState();
ret = TcpClientCreate();
init_flag_mask = TCP_CLIENT_EXAMPLE_RUNNING;
return ret;
}
/* register command for tcp client example */
SHELL_EXPORT_CMD(SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN), tcpclient, TcpClientExampleEntry, Start Tcp client);
#endif

219
example/network/raw_api/tcp_client/src/lwip_timer.c

@ -0,0 +1,219 @@
/*
* Copyright : (C) 2024 Phytium Information Technology, Inc.
* All Rights Reserved.
*
* This program is OPEN SOURCE software: you can redistribute it and/or modify it
* under the terms of the Phytium Public License as published by the Phytium Technology Co.,Ltd,
* either version 1.0 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the Phytium Public License for more details.
*
*
* FilePath: lwip_timer.c
* Created Date: 2024-06-06 11:28:36
* Last Modified: 2024-06-12 17:35:00
* Description: This file is for lwip timer function implementation.
*
* Modify History:
* Ver Who Date Changes
* ----- ---------- -------- ---------------------------------
* 1.0 liuzhihong 2024/06/06 first release
*/
#include <string.h>
#include <stdio.h>
#include "strto.h"
#include "fgeneric_timer.h"
#include "ftypes.h"
#include "fparameters.h"
#include "finterrupt.h"
#include "fassert.h"
#include "timeouts.h"
#ifdef CONFIG_USE_LETTER_SHELL
#include "shell_port.h"
#endif
#include "sdkconfig.h"
#ifndef SDK_CONFIG_H__
#error "Please include sdkconfig.h first"
#endif
#include "lwip_port.h"
#include "lwip/ip4_addr.h"
#include "lwip/init.h"
#include "netif/ethernet.h"
#include "lwip/netif.h"
#include "lwip/tcpip.h"
#include "lwip/inet.h"
#include "lwip/dhcp.h"
#include "ifconfig.h"
#define TIMER_BASE_RATE_HZ 1000 /* 为timer_base_cnt 提供time base */
#define TIMER_INTERRUPT_PRO IRQ_PRIORITY_VALUE_3
#ifdef CONFIG_ARCH_ARMV8_AARCH64
#define MAX_TIMER_CNT 0xffffffffffffffff
#else
#define MAX_TIMER_CNT 0xffffffff
#endif
static u32 timer_base_cnt = 0;
void LwipTestLoop(void)
{
struct netif *netif;
netif = netif_list;
while (netif != NULL)
{
if (netif->state)
{
LwipPortInput(netif);
LinkDetectLoop(netif);
}
netif = netif->next;
}
}
void LwipTestDhcpLoop(u32 msec)
{
LwipPortDhcpLoop(msec);
}
static void GenericTimerIntrHandler(s32 vector, void *param)
{
(void)vector;
FASSERT(param != 0);
u32 timer_base_freq = (u32)(uintptr)param;
timer_base_cnt++;
/* clear tick interrupt */
GenericTimerSetTimerValue(GENERIC_TIMER_ID0, GenericTimerFrequecy() / timer_base_freq);
}
void TimerLoopInit(void)
{
u32 cnt_frq;
timer_base_cnt = 0;
/* disable timer and get system frequency */
GenericTimerStop(GENERIC_TIMER_ID0);
cnt_frq = GenericTimerFrequecy();
/* set tick rate */
GenericTimerSetTimerValue(GENERIC_TIMER_ID0, cnt_frq / TIMER_BASE_RATE_HZ);
GenericTimerInterruptEnable(GENERIC_TIMER_ID0);
/* set generic timer interrupt */
InterruptSetPriority(GENERIC_TIMER_NS_IRQ_NUM, TIMER_INTERRUPT_PRO);
/* install tick handler */
InterruptInstall(GENERIC_TIMER_NS_IRQ_NUM, GenericTimerIntrHandler,
(void *)TIMER_BASE_RATE_HZ, "GenericTimerTick");
/* enable interrupt */
InterruptUmask(GENERIC_TIMER_NS_IRQ_NUM);
GenericTimerStart(GENERIC_TIMER_ID0);
}
#ifdef CONFIG_USE_LETTER_SHELL
void TimerLoop(void)
{
u32 _5ms_appear = 0;
u32 base_cnt_back = 0;
TimerLoopInit();
LSUserShellInit();
lwip_init(); /* lwip only init once */
while (1)
{
LSuserShellNoWaitLoop();
LwipTestLoop();
if (((timer_base_cnt % 5) == 0) && (_5ms_appear == 0)) /*5ms task */
{
_5ms_appear = 1;
LwipTestDhcpLoop(5);
}
else if ((timer_base_cnt % 5) != 0)
{
_5ms_appear = 0;
}
if(timer_base_cnt != base_cnt_back)
{
sys_check_timeouts();
base_cnt_back = timer_base_cnt;
}
}
}
#else
void TimerStaticInit(void)
{
TimerLoopInit();
lwip_init(); /* lwip only init once */
}
/**
* @name: TimerStaticLoop
* @msg: time时间内进行网卡数据收发
* @return void
* @note:
* @param {u32} time
*/
void TimerStaticLoop(u32 time)
{
u32 _5ms_appear = 0;
u32 base_cnt_back = 0;
u32 timer_start=0;
u32 time_pass_cnt=0;
u32 time_cnt;
u32 old = 0;
time_cnt = time * GenericTimerFrequecy();
timer_start = GenericTimerRead(GENERIC_TIMER_ID0);
while (time_pass_cnt<time_cnt)
{
LwipTestLoop();
if (((timer_base_cnt % 5) == 0) && (_5ms_appear == 0)) /*5ms task */
{
_5ms_appear = 1;
LwipTestDhcpLoop(5);
}
else if ((timer_base_cnt % 5) != 0)
{
_5ms_appear = 0;
}
if(timer_base_cnt != base_cnt_back)
{
sys_check_timeouts();
base_cnt_back = timer_base_cnt;
}
if(GenericTimerRead(GENERIC_TIMER_ID0)>timer_start)
time_pass_cnt = GenericTimerRead(GENERIC_TIMER_ID0)-timer_start;
else
time_pass_cnt = GenericTimerRead(GENERIC_TIMER_ID0)+(MAX_TIMER_CNT-timer_start);
if(old != time-time_pass_cnt/GenericTimerFrequecy())
{
printf("Only left %d seconds\r\n", time-time_pass_cnt/GenericTimerFrequecy());
old = time-time_pass_cnt/GenericTimerFrequecy();
}
}
ListIf();
}
#endif
u32_t sys_now(void)
{
return timer_base_cnt;
}

131
example/network/raw_api/tcp_client/src/tcp_client.c

@ -1,131 +0,0 @@
/*
* Copyright : (C) 2023 Phytium Information Technology, Inc.
* All Rights Reserved.
*
* This program is OPEN SOURCE software: you can redistribute it and/or modify it
* under the terms of the Phytium Public License as published by the Phytium Technology Co.,Ltd,
* either version 1.0 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the Phytium Public License for more details.
*
*
* FilePath: tcp_client.c
* Created Date: 2022-11-07 10:16:55
* Last Modified: 2023-06-07 11:00:17
* Description: This file is for creating a tcp client.By Tcp Connection,The client can send a tcp packet to the destination host periodically.
*
* Modify History:
* Ver Who Date Changes
* ----- ---------- -------- ---------------------------------
* 1.0 liuzhihong 2022/11/23 first release
* 1.1 liuzhihong 2023/06/06 memory double free solved
*/
#include "lwip/netif.h"
#include "lwip/ip.h"
#include "lwip/tcp.h"
#include "lwip/init.h"
#include "netif/etharp.h"
#include "lwip/udp.h"
#include "lwip/pbuf.h"
#include <stdio.h>
#include <string.h>
#include "shell.h"
#define TCP_CLIENT_PORT 0
#define TCP_SERVER_PORT 5001
void TcpClientInit(void);
static struct tcp_pcb *client_pcb = NULL;
int init_flag=0;
static void client_err(void *arg, err_t err)
{
/*connect failed, free client_pcb*/
printf("Connect error! PCB Closed by Core!\n");
if(client_pcb->state == SYN_SENT) goto exit;
tcp_close(client_pcb);
exit:
init_flag=0;
printf("Please input command tcp_client to connect to server again!\n");
}
static err_t client_send(void *arg, struct tcp_pcb *tpcb)
{
uint8_t send_buf[] = "This is a data from TCP Client.\n";
printf("Writing data to Send buffer \n");
return tcp_write(tpcb, send_buf, sizeof(send_buf), 1);;
}
static err_t client_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)
{
err_t ret = ERR_OK;
if (p != NULL)
{
/*update the tcp send windows*/
tcp_recved(tpcb, p->tot_len);
printf("We get a data from server\n");
memset(p->payload, 0, p->tot_len);
pbuf_free(p);
}
else if (err == ERR_OK)
{
printf("Server has been Disconnected!\n");
}
return ret;
}
static err_t client_connected(void *arg, struct tcp_pcb *pcb, err_t err)
{
printf("Tcp Client Connected To Server Success!\n");
/*register a timer func the Cycle time is 10*500ms=5s */
tcp_poll(pcb, client_send, 10);
/*register a receive func*/
tcp_recv(pcb, client_recv);
init_flag=1;
return ERR_OK;
}
void TcpClientInit(void)
{
if(init_flag)
{
printf("Tcp client has been opened, Please Close it first!\n");
return ;
}
err_t ret;
ip_addr_t tmp_ip;
/* create a tcp_pcb */
client_pcb = tcp_new();
IP_ADDR4(&tmp_ip, 192, 168, 4, 10);
tcp_bind(client_pcb, &tmp_ip, TCP_CLIENT_PORT);
IP_ADDR4(&tmp_ip, 192, 168, 4, 50);
printf("**************** Client Start Connectting ****************\n");
/*return immediately, call pcb->err if connect failed*/
ret = tcp_connect(client_pcb, &tmp_ip, TCP_SERVER_PORT, client_connected);
if (ret != ERR_OK)
{
printf("Memory is not enough! Connect Failed!\r\n");
tcp_close(client_pcb);
init_flag=0;
return;
}
/*register a Exception Handling Functions*/
tcp_err(client_pcb, client_err);
}
void TcpClientDeinit(void)
{
if (init_flag)
{
printf("We are Closing Tcp Client!\n");
tcp_close(client_pcb);
init_flag=0;
}
else
{
printf("There is no alive client ,Please Open Client first!\n");
}
}
SHELL_EXPORT_CMD(SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN), tcpclient, TcpClientInit, Start Tcp client test);
SHELL_EXPORT_CMD(SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN), tcpclientclose, TcpClientDeinit, Close Tcp client);

291
example/network/raw_api/tcp_client/src/tcp_client_example.c

@ -0,0 +1,291 @@
/*
* Copyright : (C) 2024 Phytium Information Technology, Inc.
* All Rights Reserved.
*
* This program is OPEN SOURCE software: you can redistribute it and/or modify it
* under the terms of the Phytium Public License as published by the Phytium Technology Co.,Ltd,
* either version 1.0 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the Phytium Public License for more details.
*
*
* FilePath: tcp_client_example.c
* Created Date: 2024-05-30 19:05:18
* Last Modified: 2024-06-12 17:35:07
* Description: This file is for tcp client example function implementation.
*
* Modify History:
* Ver Who Date Changes
* ----- ---------- -------- ---------------------------------
* 1.0 liuzhihong 2024/06/06 first release
*/
#include <string.h>
#include <stdio.h>
#include "strto.h"
#include "sdkconfig.h"
#include "ftypes.h"
#include "fassert.h"
#include "fparameters.h"
#include "eth_board.h"
#ifndef SDK_CONFIG_H__
#error "Please include sdkconfig.h first"
#endif
#include "lwip_port.h"
#include "lwip/ip4_addr.h"
#include "lwip/init.h"
#include "netif/ethernet.h"
#include "lwip/netif.h"
#include "lwip/tcpip.h"
#include "lwip/inet.h"
#include "lwip/tcp.h"
#define ETH_NAME_PREFIX 'e'
#define CONFIG_DEFAULT_INIT(config,driver_config,instance_id,interface_type) \
.config.magic_code = LWIP_PORT_CONFIG_MAGIC_CODE, \
.config.driver_type = driver_config, \
.config.mac_instance = instance_id, \
.config.mii_interface = interface_type, \
.config.autonegotiation = 1, \
.config.phy_speed = LWIP_PORT_SPEED_1000M, \
.config.phy_duplex = LWIP_PORT_FULL_DUPLEX, \
.config.capability = LWIP_PORT_MODE_MULTICAST_ADDRESS_FILITER,
#define TCP_CLIENT_PORT 5001
#define TCP_SERVER_PORT 5001
typedef struct
{
UserConfig lwip_mac_config;
u32 dhcp_en;
char* ipaddr;
char* netmask;
char* gw;
unsigned char mac_address[6];
struct netif netif;
} BoardMacConfig;
static BoardMacConfig board_mac_config[MAC_NUM] =
{
#if defined(MAC_NUM0)
{
CONFIG_DEFAULT_INIT(lwip_mac_config,MAC_NUM0_LWIP_PORT_TYPE,MAC_NUM0_CONTROLLER,MAC_NUM0_MII_INTERFACE)
.dhcp_en=0,
.ipaddr="192.168.4.10",
.gw="192.168.4.1",
.netmask="255.255.255.0",
.mac_address={0x98, 0x0e, 0x24, 0x00, 0x11, 0x0},
},
#endif
#if defined(MAC_NUM1)
{
CONFIG_DEFAULT_INIT(lwip_mac_config,MAC_NUM1_LWIP_PORT_TYPE,MAC_NUM1_CONTROLLER,MAC_NUM1_MII_INTERFACE)
.dhcp_en=0,
.ipaddr="192.168.4.11",
.gw="192.168.4.1",
.netmask="255.255.255.0",
.mac_address={0x98, 0x0e, 0x24, 0x00, 0x11, 0x1},
},
#endif
};
static void SetIP(ip_addr_t* ipaddr,ip_addr_t* gw,ip_addr_t* netmask,u32 mac_id)
{
if(inet_aton(board_mac_config[mac_id].ipaddr,ipaddr)==0)
printf("The addr of ipaddr is wrong\r\n");
if(inet_aton(board_mac_config[mac_id].gw,gw)==0)
printf("The addr of gw is wrong\r\n");
if(inet_aton(board_mac_config[mac_id].netmask,netmask)==0)
printf("The addr of netmask is wrong\r\n");
}
static err_t client_poll_callback(void *arg, struct tcp_pcb *tpcb)
{
err_t ret = ERR_OK;
if(tpcb->state == ESTABLISHED)
{
if(arg == NULL)
{
uint8_t send_buf[] = "This is a data from Tcp client!\n";
printf("Writing data to Send buffer \n");
ret = tcp_write(tpcb, send_buf, sizeof(send_buf), 1);
tcp_arg(tpcb,(void * )tpcb);
}
else
{
printf("Sending data finish! We need to disconnect from the server now !\n");
/*
client send FIN packet to server
ESTABLISHED -> FIN_WAIT_1
*/
ret = tcp_close(tpcb);
}
}
else if(tpcb->state == CLOSE_WAIT)
{
printf("The pcb is not in ESTABLISHED state ! Close it now!\n");
/*
client send FIN packet to server
CLOSE_WAIT -> LAST_ACK
*/
ret = tcp_close(tpcb);
}
return ret;
}
static err_t client_recv_callback(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)
{
err_t ret = ERR_OK;
if (p != NULL)
{
/*update the tcp send windows*/
tcp_recved(tpcb, p->tot_len);
printf("We get a data from server\n");
memset(p->payload, 0, p->tot_len);
pbuf_free(p);
}
else if (err == ERR_OK)
{
/*
client recived FIN packet from server,including two situations:
1. FIN_WAIT_2 -> TIME_WAIT
2. ESTABLISHED -> CLOSE_WAIT
*/
printf("The server disconnects from us !\n");
}
return ret;
}
static err_t client_connected_callback(void *arg, struct tcp_pcb *pcb, err_t err)
{
printf("Tcp Client Connected To Server Success!\n");
/*register a timer func the Cycle time is 10*500ms=5s */
tcp_poll(pcb, client_poll_callback,4);
/*register a receive func*/
tcp_recv(pcb, client_recv_callback);
return ERR_OK;
}
static void client_err_callback(void *arg, err_t err)
{
switch (err)
{
case ERR_ABRT:
printf("Connect error! Error type is ERR_ABRT\n");
break;
case ERR_RST:
printf("Connect error! Error type is ERR_RST\n");
break;
case ERR_CLSD:
printf("Connect error! Error type is ERR_CLSD\n");
break;
default:
FASSERT_MSG(0,"code can not reach here!\n");
break;
}
}
void TcpClient(void)
{
err_t ret;
struct tcp_pcb *client_pcb;
ip_addr_t local_ip;
ip_addr_t remote_ip;
/* create a tcp_pcb */
client_pcb = tcp_new();
IP_ADDR4(&local_ip, 192, 168, 4, 10);
tcp_bind(client_pcb, &local_ip, TCP_CLIENT_PORT);
IP_ADDR4(&remote_ip, 192, 168, 4, 50);
printf("**************** Client Start Connectting ****************\n");
/*return immediately, call pcb->err if connect failed*/
ret = tcp_connect(client_pcb, &remote_ip, TCP_SERVER_PORT, client_connected_callback);
if (ret != ERR_OK)
{
printf("Memory is not enough! Connect Failed!\r\n");
tcp_close(client_pcb);
return;
}
/*register a Exception Handling Functions*/
tcp_err(client_pcb, client_err_callback);
}
int TcpClientCreate(void)
{
FError ret = FT_SUCCESS;
/* mac init */
for (int i = 0; i < MAC_NUM; i++)
{
struct netif *netif_p = NULL;
ip_addr_t ipaddr,netmask, gw;
board_mac_config[i].lwip_mac_config.name[0] = ETH_NAME_PREFIX;
itoa(board_mac_config[i].lwip_mac_config.mac_instance, &(board_mac_config[i].lwip_mac_config.name[1]), 10);
/* mac ip addr set: char* -> ip_addr_t */
SetIP(&ipaddr,&gw,&netmask,i);
/* ******************************************************************* */
netif_p= &board_mac_config[i].netif;
/* Add network interface to the netif_list, and set it as default */
if (!LwipPortAdd(netif_p, &ipaddr, &netmask, &gw, board_mac_config[i].mac_address, (UserConfig *)&board_mac_config[i]))
{
printf("Error adding N/W interface %d.\n\r",board_mac_config[i].lwip_mac_config.mac_instance);
ret = ERR_GENERAL;
goto exit;
}
printf("LwipPortAdd mac_instance %d is over.\n\r",board_mac_config[i].lwip_mac_config.mac_instance);
netif_set_default(netif_p);
if (netif_is_link_up(netif_p))
{
/* 当netif完全配置好时,必须调用该函数 */
netif_set_up(netif_p);
if (board_mac_config[i].dhcp_en == 1)
{
LwipPortDhcpSet(netif_p, TRUE);
}
}
else
{
/* 当netif链接关闭时,必须调用该函数 */
netif_set_down(netif_p);
}
}
printf("Network setup complete.\n");
TcpClient();
exit:
if (ret == FT_SUCCESS)
{
printf("%s@%d:Tcp client example [success].\r\n", __func__, __LINE__);
return 0;
}
else
{
printf("%s@%d:Tcp client example [failure].\r\n", __func__, __LINE__);
return 1;
}
}
void TcpClientDeinit(void)
{
for (int i = 0; i < MAC_NUM; i++)
{
struct netif *netif_p = NULL;
netif_p=&board_mac_config[i].netif;
LwipPortStop(netif_p,board_mac_config[i].dhcp_en);
}
}

67
example/network/raw_api/tcp_server/README.md

@ -4,10 +4,12 @@
> `<font size="1">`介绍例程的用途,使用场景,相关基本概念,描述用户可以使用例程完成哪些工作`</font><br />`
本例程利用LWIP网络协议栈中的raw api实现了下述功能:
本例程示范了MAC控制器在lwip ipv4模式下的初始化流程,同时通过LWIP网络协议栈中的raw api,可以实现网卡作为server,利用tcp与外界进行通信。
- LWIP网络协议栈初始化
- 建立主机到开发板的tcp连接
### 1.1 TCP Server特性测试例程 (tcp_server_example.c)
- ipv4模式下初始化开发板上所有网口以及对应网卡控制器
- 在开发板侧建立tcp server,并开始监听
- 在主机端建立与开发板的tcp连接,并发送数据
- 开发板将收到的数据原样发回主机
- 网络主机在屏幕端打印收到的数据
@ -15,35 +17,30 @@
> `<font size="1">`描述开发平台准备,使用例程配置,构建和下载镜像的过程`</font><br />`
- 本例程在E2000上测试通过,您可以参考以下方法配置本例程所需要的硬件和软件环境
本例程需要以下硬件:
- E2000D/Q Demo板,FT2000/4开发板,D2000开发板,PhytiumPi
- 串口线和串口上位机
### 2.1 硬件配置方法
> `<font size="1">`哪些硬件平台是支持的,需要哪些外设,例程与开发板哪些IO口相关等(建议附录开发板照片,展示哪些IO口被引出)`</font><br />`
本例程支持以下硬件平台
- FT2000/4
- D2000开发板
- E2000 系列开发板
D2000开发板图片示例如下:
D2000开发板图片示例
![board](./fig/board.png)
DEMO开发板图片示例如下所示
E2000Q DEMO开发板图片示例
![demo_board](./fig/demo_board.jpg)
### 2.2 SDK配置方法
> `<font size="1">`依赖哪些驱动、库和第三方组件,如何完成配置(列出需要使能的关键配置项)`</font><br />`
本例程需要,
本例程需要:
- LWIP组件,依赖 USE_LWIP
- Letter Shell组件,依赖 USE_LETTER_SHELL
对应的配置项是,
对应的配置项是:
- CONFIG_USE_LWIP
- CONFIG_USE_LETTER_SHELL
@ -67,7 +64,7 @@ DEMO开发板图片示例如下所示
#### 2.3.1 构建过程
本文档将以E2000demo开发板为例,对于其它平台,使用对应的默认配置
本文档将以E2000d demo开发板为例,对于其它平台,使用对应的默认配置
- 在host端完成配置
- 选择目标平台
@ -116,39 +113,18 @@ bootelf -p 0x90100000
> `<font size="1">`描述输入输出情况,列出存在哪些输出,对应的输出是什么(建议附录相关现象图片)`</font><br />`
- 启动进入后,根据连接的网口,输入指令完成网口初始化
#### 2.4.1 初始化LWIP网络协议栈
- 输入以下命令,初始化LWIP网络协议栈, 依次设置网卡和dhcp使能,配置ip地址,子网掩码,网关地址,运行完成退出后LWIP协议栈会持续运行
- lwip probe 指令介绍
```
lwip probe <driver id> <device id> <interface id> <dhcp_en> <ipaddr> <gateway> <netmask>
```
- 其中driver id 为驱动类型 , 0为xmac ,1为gmac
- device id 为控制器id
- interface id ,0 为rgmii ,1 为sgmii
- dhcp en,0 表示关闭dhcp功能,1表示开启dhcp功能,网卡将根据dhcp协议获得ip地址(当协议栈支持dhcp时,该参数才具有实际作用)
- 输入以下命令,初始化LWIP网络协议栈, 依次设置网卡和dhcp使能,配置ip地址,子网掩码,网关地址,运行完成退出后LWIP协议栈会持续运行
```
$ lwip probe 0 0 1 0 192.168.4.10 192.168.4.1 255.255.255.0
```
#### 2.4.2 开启tcpserver
#### 2.4.1 TCP Server特性测试例程 (tcp_server_example.c)
- 输入以下命令,开始tcp server 测试
```
$ tcpserver
tcpserver
```
- 在host端发起tcp用户连接请求,输入以下命令
```
nc 192.168.4.10 5003
nc 192.168.4.10 5001
```
- 主机上的tcp用户发送数据到开发板的tcp服务器,开发板会将收到的数据回显到主机上
@ -163,14 +139,15 @@ nc 192.168.4.10 5003
- Q: 为何开发板上收到数据与主机发送数据不一致?
- A: 路由器具有upnp服务,会向网络中的节点发送广播数据包,而这个数据包被开发板收到,并且打印在了开发板上,可以尝试将路由器的upnp服务关闭
![tcpserver](./fig/tcp_server.png)
- Q: 如何配置tcp server的ip地址以及监听端口?
- A: 在tcp_server.c中修改如下变量local_ip以及5003即可:
- A: 在tcp_server_example.c中修改如下变量local_ip以及TCP_SERVER_PORT即可:
```
IP_ADDR4(&local_ip, 192, 168, 4, 10);
ret = tcp_bind(pcb, &local_ip, 5003);
#define TCP_SERVER_PORT 5001
......
IP_ADDR4(&local_ip, 192, 168, 4, 10);
ret = tcp_bind(temp_pcb, &local_ip, TCP_SERVER_PORT);
```
## 4. 修改历史记录

10
example/network/raw_api/tcp_server/configs/d2000_aarch32_test_tcpserver.config

@ -234,7 +234,13 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# DHCP
#
# CONFIG_LWIP_DHCP_ENABLE is not set
CONFIG_LWIP_DHCP_ENABLE=y
# CONFIG_LWIP_DHCP_DOES_ARP_CHECK is not set
# CONFIG_LWIP_DHCP_GET_NTP_SRV is not set
# CONFIG_LWIP_DHCP_DISABLE_CLIENT_ID is not set
# CONFIG_LWIP_DHCP_RESTORE_LAST_IP is not set
CONFIG_LWIP_DHCP_OPTIONS_LEN=68
CONFIG_LWIP_DHCP_DISABLE_VENDOR_CLASS_ID=y
# end of DHCP
#
@ -246,7 +252,7 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# IGMP
#
CONFIG_LWIP_IGMP_EN=y
# CONFIG_LWIP_IGMP_EN is not set
# end of IGMP
#

10
example/network/raw_api/tcp_server/configs/d2000_aarch64_test_tcpserver.config

@ -228,7 +228,13 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# DHCP
#
# CONFIG_LWIP_DHCP_ENABLE is not set
CONFIG_LWIP_DHCP_ENABLE=y
# CONFIG_LWIP_DHCP_DOES_ARP_CHECK is not set
# CONFIG_LWIP_DHCP_GET_NTP_SRV is not set
# CONFIG_LWIP_DHCP_DISABLE_CLIENT_ID is not set
# CONFIG_LWIP_DHCP_RESTORE_LAST_IP is not set
CONFIG_LWIP_DHCP_OPTIONS_LEN=68
CONFIG_LWIP_DHCP_DISABLE_VENDOR_CLASS_ID=y
# end of DHCP
#
@ -240,7 +246,7 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# IGMP
#
CONFIG_LWIP_IGMP_EN=y
# CONFIG_LWIP_IGMP_EN is not set
# end of IGMP
#

10
example/network/raw_api/tcp_server/configs/e2000d_aarch32_demo_tcpserver.config

@ -247,7 +247,13 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# DHCP
#
# CONFIG_LWIP_DHCP_ENABLE is not set
CONFIG_LWIP_DHCP_ENABLE=y
# CONFIG_LWIP_DHCP_DOES_ARP_CHECK is not set
# CONFIG_LWIP_DHCP_GET_NTP_SRV is not set
# CONFIG_LWIP_DHCP_DISABLE_CLIENT_ID is not set
# CONFIG_LWIP_DHCP_RESTORE_LAST_IP is not set
CONFIG_LWIP_DHCP_OPTIONS_LEN=68
CONFIG_LWIP_DHCP_DISABLE_VENDOR_CLASS_ID=y
# end of DHCP
#
@ -259,7 +265,7 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# IGMP
#
CONFIG_LWIP_IGMP_EN=y
# CONFIG_LWIP_IGMP_EN is not set
# end of IGMP
#

10
example/network/raw_api/tcp_server/configs/e2000d_aarch64_demo_tcpserver.config

@ -241,7 +241,13 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# DHCP
#
# CONFIG_LWIP_DHCP_ENABLE is not set
CONFIG_LWIP_DHCP_ENABLE=y
# CONFIG_LWIP_DHCP_DOES_ARP_CHECK is not set
# CONFIG_LWIP_DHCP_GET_NTP_SRV is not set
# CONFIG_LWIP_DHCP_DISABLE_CLIENT_ID is not set
# CONFIG_LWIP_DHCP_RESTORE_LAST_IP is not set
CONFIG_LWIP_DHCP_OPTIONS_LEN=68
CONFIG_LWIP_DHCP_DISABLE_VENDOR_CLASS_ID=y
# end of DHCP
#
@ -253,7 +259,7 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# IGMP
#
CONFIG_LWIP_IGMP_EN=y
# CONFIG_LWIP_IGMP_EN is not set
# end of IGMP
#

10
example/network/raw_api/tcp_server/configs/e2000q_aarch32_demo_tcpserver.config

@ -246,7 +246,13 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# DHCP
#
# CONFIG_LWIP_DHCP_ENABLE is not set
CONFIG_LWIP_DHCP_ENABLE=y
# CONFIG_LWIP_DHCP_DOES_ARP_CHECK is not set
# CONFIG_LWIP_DHCP_GET_NTP_SRV is not set
# CONFIG_LWIP_DHCP_DISABLE_CLIENT_ID is not set
# CONFIG_LWIP_DHCP_RESTORE_LAST_IP is not set
CONFIG_LWIP_DHCP_OPTIONS_LEN=68
CONFIG_LWIP_DHCP_DISABLE_VENDOR_CLASS_ID=y
# end of DHCP
#
@ -258,7 +264,7 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# IGMP
#
CONFIG_LWIP_IGMP_EN=y
# CONFIG_LWIP_IGMP_EN is not set
# end of IGMP
#

10
example/network/raw_api/tcp_server/configs/e2000q_aarch64_demo_tcpserver.config

@ -240,7 +240,13 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# DHCP
#
# CONFIG_LWIP_DHCP_ENABLE is not set
CONFIG_LWIP_DHCP_ENABLE=y
# CONFIG_LWIP_DHCP_DOES_ARP_CHECK is not set
# CONFIG_LWIP_DHCP_GET_NTP_SRV is not set
# CONFIG_LWIP_DHCP_DISABLE_CLIENT_ID is not set
# CONFIG_LWIP_DHCP_RESTORE_LAST_IP is not set
CONFIG_LWIP_DHCP_OPTIONS_LEN=68
CONFIG_LWIP_DHCP_DISABLE_VENDOR_CLASS_ID=y
# end of DHCP
#
@ -252,7 +258,7 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# IGMP
#
CONFIG_LWIP_IGMP_EN=y
# CONFIG_LWIP_IGMP_EN is not set
# end of IGMP
#

10
example/network/raw_api/tcp_server/configs/ft2004_aarch32_dsk_tcpserver.config

@ -234,7 +234,13 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# DHCP
#
# CONFIG_LWIP_DHCP_ENABLE is not set
CONFIG_LWIP_DHCP_ENABLE=y
# CONFIG_LWIP_DHCP_DOES_ARP_CHECK is not set
# CONFIG_LWIP_DHCP_GET_NTP_SRV is not set
# CONFIG_LWIP_DHCP_DISABLE_CLIENT_ID is not set
# CONFIG_LWIP_DHCP_RESTORE_LAST_IP is not set
CONFIG_LWIP_DHCP_OPTIONS_LEN=68
CONFIG_LWIP_DHCP_DISABLE_VENDOR_CLASS_ID=y
# end of DHCP
#
@ -246,7 +252,7 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# IGMP
#
CONFIG_LWIP_IGMP_EN=y
# CONFIG_LWIP_IGMP_EN is not set
# end of IGMP
#

10
example/network/raw_api/tcp_server/configs/ft2004_aarch64_dsk_tcpserver.config

@ -228,7 +228,13 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# DHCP
#
# CONFIG_LWIP_DHCP_ENABLE is not set
CONFIG_LWIP_DHCP_ENABLE=y
# CONFIG_LWIP_DHCP_DOES_ARP_CHECK is not set
# CONFIG_LWIP_DHCP_GET_NTP_SRV is not set
# CONFIG_LWIP_DHCP_DISABLE_CLIENT_ID is not set
# CONFIG_LWIP_DHCP_RESTORE_LAST_IP is not set
CONFIG_LWIP_DHCP_OPTIONS_LEN=68
CONFIG_LWIP_DHCP_DISABLE_VENDOR_CLASS_ID=y
# end of DHCP
#
@ -240,7 +246,7 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# IGMP
#
CONFIG_LWIP_IGMP_EN=y
# CONFIG_LWIP_IGMP_EN is not set
# end of IGMP
#

10
example/network/raw_api/tcp_server/configs/pd2308_aarch64_demo_tcpserver.config

@ -237,7 +237,13 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# DHCP
#
# CONFIG_LWIP_DHCP_ENABLE is not set
CONFIG_LWIP_DHCP_ENABLE=y
# CONFIG_LWIP_DHCP_DOES_ARP_CHECK is not set
# CONFIG_LWIP_DHCP_GET_NTP_SRV is not set
# CONFIG_LWIP_DHCP_DISABLE_CLIENT_ID is not set
# CONFIG_LWIP_DHCP_RESTORE_LAST_IP is not set
CONFIG_LWIP_DHCP_OPTIONS_LEN=68
CONFIG_LWIP_DHCP_DISABLE_VENDOR_CLASS_ID=y
# end of DHCP
#
@ -249,7 +255,7 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# IGMP
#
CONFIG_LWIP_IGMP_EN=y
# CONFIG_LWIP_IGMP_EN is not set
# end of IGMP
#

10
example/network/raw_api/tcp_server/configs/phytiumpi_aarch32_firefly_tcpserver.config

@ -245,7 +245,13 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# DHCP
#
# CONFIG_LWIP_DHCP_ENABLE is not set
CONFIG_LWIP_DHCP_ENABLE=y
# CONFIG_LWIP_DHCP_DOES_ARP_CHECK is not set
# CONFIG_LWIP_DHCP_GET_NTP_SRV is not set
# CONFIG_LWIP_DHCP_DISABLE_CLIENT_ID is not set
# CONFIG_LWIP_DHCP_RESTORE_LAST_IP is not set
CONFIG_LWIP_DHCP_OPTIONS_LEN=68
CONFIG_LWIP_DHCP_DISABLE_VENDOR_CLASS_ID=y
# end of DHCP
#
@ -257,7 +263,7 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# IGMP
#
CONFIG_LWIP_IGMP_EN=y
# CONFIG_LWIP_IGMP_EN is not set
# end of IGMP
#

10
example/network/raw_api/tcp_server/configs/phytiumpi_aarch64_firefly_tcpserver.config

@ -239,7 +239,13 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# DHCP
#
# CONFIG_LWIP_DHCP_ENABLE is not set
CONFIG_LWIP_DHCP_ENABLE=y
# CONFIG_LWIP_DHCP_DOES_ARP_CHECK is not set
# CONFIG_LWIP_DHCP_GET_NTP_SRV is not set
# CONFIG_LWIP_DHCP_DISABLE_CLIENT_ID is not set
# CONFIG_LWIP_DHCP_RESTORE_LAST_IP is not set
CONFIG_LWIP_DHCP_OPTIONS_LEN=68
CONFIG_LWIP_DHCP_DISABLE_VENDOR_CLASS_ID=y
# end of DHCP
#
@ -251,7 +257,7 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# IGMP
#
CONFIG_LWIP_IGMP_EN=y
# CONFIG_LWIP_IGMP_EN is not set
# end of IGMP
#

BIN
example/network/raw_api/tcp_server/fig/ping_ipv4.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

BIN
example/network/raw_api/tcp_server/fig/ping_ipv4_dhcp.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

BIN
example/network/raw_api/tcp_server/fig/ping_ipv6.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 52 KiB

BIN
example/network/raw_api/tcp_server/fig/probe_ipv4.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

BIN
example/network/raw_api/tcp_server/fig/probe_ipv4_dhcp.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

BIN
example/network/raw_api/tcp_server/fig/probe_ipv6.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

BIN
example/network/raw_api/tcp_server/fig/tcp_server.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 22 KiB

BIN
example/network/raw_api/tcp_server/fig/tcpserver_host.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.1 KiB

After

Width:  |  Height:  |  Size: 9.3 KiB

57
example/network/raw_api/tcp_server/inc/lwip_timer.h

@ -0,0 +1,57 @@
/*
* Copyright : (C) 2024 Phytium Information Technology, Inc.
* All Rights Reserved.
*
* This program is OPEN SOURCE software: you can redistribute it and/or modify it
* under the terms of the Phytium Public License as published by the Phytium Technology Co.,Ltd,
* either version 1.0 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the Phytium Public License for more details.
*
*
* FilePath: lwip_timer.c
* Created Date: 2024-06-05 18:42:52
* Last Modified: 2024-06-12 17:35:26
* Description: This file is for lwip timer function definition.
*
* Modify History:
* Ver Who Date Changes
* ----- ---------- -------- ---------------------------------
* 1.0 liuzhihong 2024/06/05 first release
*/
#ifndef LWIP_TIMER_H
#define LWIP_TIMER_H
/***************************** Include Files *********************************/
#include "ftypes.h"
#ifdef __cplusplus
extern "C"
{
#endif
/************************** Constant Definitions *****************************/
/**************************** Type Definitions *******************************/
/************************** Variable Definitions *****************************/
/***************** Macros (Inline Functions) Definitions *********************/
/************************** Function Prototypes ******************************/
/* entry function for lwip timer example */
#ifdef CONFIG_USE_LETTER_SHELL
void TimerLoop(void);
#else
void TimerStaticInit(void);
void TimerStaticLoop(u32 time);
#endif
#ifdef __cplusplus
}
#endif
#endif

51
example/network/raw_api/tcp_server/inc/tcp_server_example.h

@ -0,0 +1,51 @@
/*
* Copyright : (C) 2024 Phytium Information Technology, Inc.
* All Rights Reserved.
*
* This program is OPEN SOURCE software: you can redistribute it and/or modify it
* under the terms of the Phytium Public License as published by the Phytium Technology Co.,Ltd,
* either version 1.0 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the Phytium Public License for more details.
*
*
* FilePath: tcp_server_example.h
* Created Date: 2024-06-05 18:43:00
* Last Modified: 2024-06-12 17:36:14
* Description: This file is for tcp server example function definition.
*
* Modify History:
* Ver Who Date Changes
* ----- ---------- -------- ---------------------------------
* 1.0 liuzhihong 2024/06/05 first release
*/
#ifndef TCP_SERVER_EXAMPLE_H
#define TCP_SERVER_EXAMPLE_H
/***************************** Include Files *********************************/
#include "ftypes.h"
#ifdef __cplusplus
extern "C"
{
#endif
/************************** Constant Definitions *****************************/
/**************************** Type Definitions *******************************/
/************************** Variable Definitions *****************************/
/***************** Macros (Inline Functions) Definitions *********************/
/************************** Function Prototypes ******************************/
/* entry function for tcp server example */
int TcpServerCreate(void);
void TcpServerDeinit(void);
#ifdef __cplusplus
}
#endif
#endif

62
example/network/raw_api/tcp_server/main.c

@ -1,40 +1,64 @@
/*
* Copyright : (C) 2022 Phytium Information Technology, Inc.
* Copyright : (C) 2024 Phytium Information Technology, Inc.
* All Rights Reserved.
*
*
* This program is OPEN SOURCE software: you can redistribute it and/or modify it
* under the terms of the Phytium Public License as published by the Phytium Technology Co.,Ltd,
* either version 1.0 of the License, or (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the Phytium Public License for more details.
*
*
*
*
* FilePath: main.c
* Date: 2022-02-10 14:53:41
* LastEditTime: 2022-02-17 17:38:03
* Description:  This file is for creating a main loop from which the programme will start.
*
* Modify History:
* Ver Who Date Changes
* ----- ------ -------- --------------------------------------
* 1.0 liuzhihong 2022/11/25 first release
* Created Date: 2024-05-30 19:05:18
* Last Modified: 2024-06-12 17:55:33
* Description: This file is for tcp server example main functions.
*
* Modify History:
* Ver Who Date Changes
* ----- ---------- -------- ---------------------------------
* 1.0 liuzhihong 2024/06/03 first release
*/
#include <string.h>
#include <stdio.h>
/***************************** Include Files *********************************/
#include "sdkconfig.h"
#ifndef SDK_CONFIG_H__
#warning "Please include sdkconfig.h"
#endif
#ifndef CONFIG_USE_LETTER_SHELL
#error "Please include letter shell first!!!"
#ifdef CONFIG_USE_LETTER_SHELL
#include "shell_port.h"
#endif
extern void TimerLoop(void);
#include "tcp_server_example.h"
#include "lwip_timer.h"
/************************** Constant Definitions *****************************/
/**************************** Type Definitions *******************************/
/************************** Variable Definitions *****************************/
/***************** Macros (Inline Functions) Definitions *********************/
/************************** Function Prototypes ******************************/
/************************** Function *****************************************/
int main()
{
TimerLoop();
#ifdef CONFIG_USE_LETTER_SHELL
/* if shell command is enabled, register example entry as shell command */
TimerLoop();
#else
TimerStaticInit();
TcpServerCreate();
TimerStaticLoop(10);
TcpServerDeinit();
#endif
return 0;
}

1
example/network/raw_api/tcp_server/makefile

@ -3,7 +3,6 @@ SDK_DIR ?= $(CURDIR)/../../../..
USER_CSRC := main.c
USER_CSRC += $(wildcard src/*.c)
USER_CSRC += $(wildcard ../common/*.c)
USER_INCLUDE := $(PROJECT_DIR) \
$(PROJECT_DIR)/inc \

10
example/network/raw_api/tcp_server/sdkconfig

@ -239,7 +239,13 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# DHCP
#
# CONFIG_LWIP_DHCP_ENABLE is not set
CONFIG_LWIP_DHCP_ENABLE=y
# CONFIG_LWIP_DHCP_DOES_ARP_CHECK is not set
# CONFIG_LWIP_DHCP_GET_NTP_SRV is not set
# CONFIG_LWIP_DHCP_DISABLE_CLIENT_ID is not set
# CONFIG_LWIP_DHCP_RESTORE_LAST_IP is not set
CONFIG_LWIP_DHCP_OPTIONS_LEN=68
CONFIG_LWIP_DHCP_DISABLE_VENDOR_CLASS_ID=y
# end of DHCP
#
@ -251,7 +257,7 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# IGMP
#
CONFIG_LWIP_IGMP_EN=y
# CONFIG_LWIP_IGMP_EN is not set
# end of IGMP
#

10
example/network/raw_api/tcp_server/sdkconfig.h

@ -212,7 +212,13 @@
/* DHCP */
/* CONFIG_LWIP_DHCP_ENABLE is not set */
#define CONFIG_LWIP_DHCP_ENABLE
/* CONFIG_LWIP_DHCP_DOES_ARP_CHECK is not set */
/* CONFIG_LWIP_DHCP_GET_NTP_SRV is not set */
/* CONFIG_LWIP_DHCP_DISABLE_CLIENT_ID is not set */
/* CONFIG_LWIP_DHCP_RESTORE_LAST_IP is not set */
#define CONFIG_LWIP_DHCP_OPTIONS_LEN 68
#define CONFIG_LWIP_DHCP_DISABLE_VENDOR_CLASS_ID
/* end of DHCP */
/* AUTOIP */
@ -222,7 +228,7 @@
/* IGMP */
#define CONFIG_LWIP_IGMP_EN
/* CONFIG_LWIP_IGMP_EN is not set */
/* end of IGMP */
/* DNS */

69
example/network/raw_api/tcp_server/src/cmd_tcp_server.c

@ -0,0 +1,69 @@
/*
* Copyright : (C) 2024 Phytium Information Technology, Inc.
* All Rights Reserved.
*
* This program is OPEN SOURCE software: you can redistribute it and/or modify it
* under the terms of the Phytium Public License as published by the Phytium Technology Co.,Ltd,
* either version 1.0 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the Phytium Public License for more details.
*
*
* FilePath: cmd_tcpserver. c
* Created Date: 2024-06-05 18:43:36
* Last Modified: 2024-06-12 17:36:19
* Description: This file is for tcp server example cmd catalogue.
*
* Modify History:
* Ver Who Date Changes
* ----- ---------- -------- ---------------------------------
* 1.0 liuzhihong 2024/06/05 first release
*/
/***************************** Include Files *********************************/
#include <stdio.h>
#include <string.h>
#include "sdkconfig.h"
#ifndef SDK_CONFIG_H__
#warning "Please include sdkconfig.h"
#endif
#ifdef CONFIG_USE_LETTER_SHELL
#include "shell.h"
#include "strto.h"
#include "tcp_server_example.h"
#define EXAMPLE_IDLE 0
#define TCP_SERVER_EXAMPLE_RUNNING 1
static u32 init_flag_mask=EXAMPLE_IDLE;
static void TcpServerExampleCheckState(void)
{
switch(init_flag_mask)
{
case TCP_SERVER_EXAMPLE_RUNNING:
printf("Tcp server example is running, we need to deinitialize it first! \r\n");
TcpServerDeinit();
init_flag_mask=EXAMPLE_IDLE;
break;
default:
break;
}
}
/* entry function for tcp server example */
static int TcpServerExampleEntry(int argc, char *argv[])
{
int ret = 0;
TcpServerExampleCheckState();
ret = TcpServerCreate();
init_flag_mask = TCP_SERVER_EXAMPLE_RUNNING;
return ret;
}
/* register command for tcp server example */
SHELL_EXPORT_CMD(SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN), tcpserver, TcpServerExampleEntry, Start Tcp server);
#endif

219
example/network/raw_api/tcp_server/src/lwip_timer.c

@ -0,0 +1,219 @@
/*
* Copyright : (C) 2024 Phytium Information Technology, Inc.
* All Rights Reserved.
*
* This program is OPEN SOURCE software: you can redistribute it and/or modify it
* under the terms of the Phytium Public License as published by the Phytium Technology Co.,Ltd,
* either version 1.0 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the Phytium Public License for more details.
*
*
* FilePath: lwip_timer.c
* Created Date: 2024-06-05 18:43:13
* Last Modified: 2024-06-12 17:36:26
* Description: This file is for lwip timer function implementation.
*
* Modify History:
* Ver Who Date Changes
* ----- ---------- -------- ---------------------------------
* 1.0 liuzhihong 2024/06/05 first release
*/
#include <string.h>
#include <stdio.h>
#include "strto.h"
#include "fgeneric_timer.h"
#include "ftypes.h"
#include "fparameters.h"
#include "finterrupt.h"
#include "fassert.h"
#include "timeouts.h"
#ifdef CONFIG_USE_LETTER_SHELL
#include "shell_port.h"
#endif
#include "sdkconfig.h"
#ifndef SDK_CONFIG_H__
#error "Please include sdkconfig.h first"
#endif
#include "lwip_port.h"
#include "lwip/ip4_addr.h"
#include "lwip/init.h"
#include "netif/ethernet.h"
#include "lwip/netif.h"
#include "lwip/tcpip.h"
#include "lwip/inet.h"
#include "lwip/dhcp.h"
#include "ifconfig.h"
#define TIMER_BASE_RATE_HZ 1000 /* 为timer_base_cnt 提供time base */
#define TIMER_INTERRUPT_PRO IRQ_PRIORITY_VALUE_3
#ifdef CONFIG_ARCH_ARMV8_AARCH64
#define MAX_TIMER_CNT 0xffffffffffffffff
#else
#define MAX_TIMER_CNT 0xffffffff
#endif
static u32 timer_base_cnt = 0;
void LwipTestLoop(void)
{
struct netif *netif;
netif = netif_list;
while (netif != NULL)
{
if (netif->state)
{
LwipPortInput(netif);
LinkDetectLoop(netif);
}
netif = netif->next;
}
}
void LwipTestDhcpLoop(u32 msec)
{
LwipPortDhcpLoop(msec);
}
static void GenericTimerIntrHandler(s32 vector, void *param)
{
(void)vector;
FASSERT(param != 0);
u32 timer_base_freq = (u32)(uintptr)param;
timer_base_cnt++;
/* clear tick interrupt */
GenericTimerSetTimerValue(GENERIC_TIMER_ID0, GenericTimerFrequecy() / timer_base_freq);
}
void TimerLoopInit(void)
{
u32 cnt_frq;
timer_base_cnt = 0;
/* disable timer and get system frequency */
GenericTimerStop(GENERIC_TIMER_ID0);
cnt_frq = GenericTimerFrequecy();
/* set tick rate */
GenericTimerSetTimerValue(GENERIC_TIMER_ID0, cnt_frq / TIMER_BASE_RATE_HZ);
GenericTimerInterruptEnable(GENERIC_TIMER_ID0);
/* set generic timer interrupt */
InterruptSetPriority(GENERIC_TIMER_NS_IRQ_NUM, TIMER_INTERRUPT_PRO);
/* install tick handler */
InterruptInstall(GENERIC_TIMER_NS_IRQ_NUM, GenericTimerIntrHandler,
(void *)TIMER_BASE_RATE_HZ, "GenericTimerTick");
/* enable interrupt */
InterruptUmask(GENERIC_TIMER_NS_IRQ_NUM);
GenericTimerStart(GENERIC_TIMER_ID0);
}
#ifdef CONFIG_USE_LETTER_SHELL
void TimerLoop(void)
{
u32 _5ms_appear = 0;
u32 base_cnt_back = 0;
TimerLoopInit();
LSUserShellInit();
lwip_init(); /* lwip only init once */
while (1)
{
LSuserShellNoWaitLoop();
LwipTestLoop();
if (((timer_base_cnt % 5) == 0) && (_5ms_appear == 0)) /*5ms task */
{
_5ms_appear = 1;
LwipTestDhcpLoop(5);
}
else if ((timer_base_cnt % 5) != 0)
{
_5ms_appear = 0;
}
if(timer_base_cnt != base_cnt_back)
{
sys_check_timeouts();
base_cnt_back = timer_base_cnt;
}
}
}
#else
void TimerStaticInit(void)
{
TimerLoopInit();
lwip_init(); /* lwip only init once */
}
/**
* @name: TimerStaticLoop
* @msg: time时间内进行网卡数据收发
* @return void
* @note:
* @param {u32} time
*/
void TimerStaticLoop(u32 time)
{
u32 _5ms_appear = 0;
u32 base_cnt_back = 0;
u32 timer_start=0;
u32 time_pass_cnt=0;
u32 time_cnt;
u32 old = 0;
time_cnt = time * GenericTimerFrequecy();
timer_start = GenericTimerRead(GENERIC_TIMER_ID0);
while (time_pass_cnt<time_cnt)
{
LwipTestLoop();
if (((timer_base_cnt % 5) == 0) && (_5ms_appear == 0)) /*5ms task */
{
_5ms_appear = 1;
LwipTestDhcpLoop(5);
}
else if ((timer_base_cnt % 5) != 0)
{
_5ms_appear = 0;
}
if(timer_base_cnt != base_cnt_back)
{
sys_check_timeouts();
base_cnt_back = timer_base_cnt;
}
if(GenericTimerRead(GENERIC_TIMER_ID0)>timer_start)
time_pass_cnt = GenericTimerRead(GENERIC_TIMER_ID0)-timer_start;
else
time_pass_cnt = GenericTimerRead(GENERIC_TIMER_ID0)+(MAX_TIMER_CNT-timer_start);
if(old != time-time_pass_cnt/GenericTimerFrequecy())
{
printf("Only left %d seconds\r\n", time-time_pass_cnt/GenericTimerFrequecy());
old = time-time_pass_cnt/GenericTimerFrequecy();
}
}
ListIf();
}
#endif
u32_t sys_now(void)
{
return timer_base_cnt;
}

92
example/network/raw_api/tcp_server/src/tcp_server.c

@ -1,92 +0,0 @@
/*
* Copyright : (C) 2022 Phytium Information Technology, Inc.
* All Rights Reserved.
*
* This program is OPEN SOURCE software: you can redistribute it and/or modify it
* under the terms of the Phytium Public License as published by the Phytium Technology Co.,Ltd,
* either version 1.0 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the Phytium Public License for more details.
*
*
* FilePath: tcp_server.c
* Date: 2022-10-27 18:16:52
* LastEditTime: 2022-12-05 18:12:14
* Description: This file is creating a tcp server.By Tcp Connection,The server can return received data to the client which send it!
*
* Modify History:
* Ver Who Date Changes
* ----- ------ -------- --------------------------------------
* 1.0 liuzhihong 2022/11/25 first release
*/
#include "lwip/netif.h"
#include "lwip/ip.h"
#include "lwip/tcp.h"
#include "lwip/init.h"
#include "netif/etharp.h"
#include "lwip/udp.h"
#include "lwip/pbuf.h"
#include <stdio.h>
#include <string.h>
#include "shell.h"
static err_t tcpecho_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)
{
if (p != NULL)
{
printf("We get data: ");
printf("%s", (char *)p->payload);
/* update receive buffer */
tcp_recved(tpcb, p->tot_len);
/* Returning received data to the client */
tcp_write(tpcb, p->payload, p->tot_len, 1);
memset(p->payload, 0, p->tot_len);
pbuf_free(p);
}
else if (err == ERR_OK)
{
printf("Connection closed! Waiting client to connect.\n");
return tcp_close(tpcb);
}
return ERR_OK;
}
static err_t tcpecho_accept(void *arg, struct tcp_pcb *newpcb, err_t err)
{
printf("Connection Established!\r\n");
tcp_recv(newpcb, tcpecho_recv);
return ERR_OK;
}
void TcpServerInit(void)
{
ip_addr_t local_ip;
struct tcp_pcb *pcb = NULL;
err_t ret = ERR_OK;
/* create a tcp_pcb*/
pcb = tcp_new();
if (pcb == NULL)
{
printf("Tcp Server Open Failed!\r\n");
printf("Unable to create a new tcp_pcb\r\n");
return ;
}
/* bind the local ip and local port */
IP_ADDR4(&local_ip, 192, 168, 4, 10);
ret = tcp_bind(pcb, &local_ip, 5003);
if (ret == ERR_USE)
{
printf("The port and ip are already binded!\n");
tcp_close(pcb);
return;
}
/* listening */
pcb = tcp_listen(pcb);
/*register a connection-established function*/
tcp_accept(pcb, tcpecho_accept);
printf("Tcp Server Open Success!\r\n");
}
SHELL_EXPORT_CMD(SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN), tcpserver, TcpServerInit, Start Tcp server test);

232
example/network/raw_api/tcp_server/src/tcp_server_example.c

@ -0,0 +1,232 @@
/*
* Copyright : (C) 2024 Phytium Information Technology, Inc.
* All Rights Reserved.
*
* This program is OPEN SOURCE software: you can redistribute it and/or modify it
* under the terms of the Phytium Public License as published by the Phytium Technology Co.,Ltd,
* either version 1.0 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the Phytium Public License for more details.
*
*
* FilePath: tcp_server_example.c
* Created Date: 2024-05-30 19:05:18
* Last Modified: 2024-06-12 17:36:53
* Description: This file is for tcp server example function implementation.
*
* Modify History:
* Ver Who Date Changes
* ----- ---------- -------- ---------------------------------
* 1.0 liuzhihong 2024/06/05 first release
*/
#include <string.h>
#include <stdio.h>
#include "strto.h"
#include "sdkconfig.h"
#include "ftypes.h"
#include "fassert.h"
#include "fparameters.h"
#include "eth_board.h"
#ifndef SDK_CONFIG_H__
#error "Please include sdkconfig.h first"
#endif
#include "lwip_port.h"
#include "lwip/ip4_addr.h"
#include "lwip/init.h"
#include "netif/ethernet.h"
#include "lwip/netif.h"
#include "lwip/tcpip.h"
#include "lwip/inet.h"
#include "lwip/tcp.h"
#define ETH_NAME_PREFIX 'e'
#define CONFIG_DEFAULT_INIT(config,driver_config,instance_id,interface_type) \
.config.magic_code = LWIP_PORT_CONFIG_MAGIC_CODE, \
.config.driver_type = driver_config, \
.config.mac_instance = instance_id, \
.config.mii_interface = interface_type, \
.config.autonegotiation = 1, \
.config.phy_speed = LWIP_PORT_SPEED_1000M, \
.config.phy_duplex = LWIP_PORT_FULL_DUPLEX, \
.config.capability = LWIP_PORT_MODE_MULTICAST_ADDRESS_FILITER,
#define TCP_SERVER_PORT 5001
typedef struct
{
UserConfig lwip_mac_config;
u32 dhcp_en;
char* ipaddr;
char* netmask;
char* gw;
unsigned char mac_address[6];
struct netif netif;
} BoardMacConfig;
static BoardMacConfig board_mac_config[MAC_NUM] =
{
#if defined(MAC_NUM0)
{
CONFIG_DEFAULT_INIT(lwip_mac_config,MAC_NUM0_LWIP_PORT_TYPE,MAC_NUM0_CONTROLLER,MAC_NUM0_MII_INTERFACE)
.dhcp_en=0,
.ipaddr="192.168.4.10",
.gw="192.168.4.1",
.netmask="255.255.255.0",
.mac_address={0x98, 0x0e, 0x24, 0x00, 0x11, 0x0},
},
#endif
#if defined(MAC_NUM1)
{
CONFIG_DEFAULT_INIT(lwip_mac_config,MAC_NUM1_LWIP_PORT_TYPE,MAC_NUM1_CONTROLLER,MAC_NUM1_MII_INTERFACE)
.dhcp_en=0,
.ipaddr="192.168.4.11",
.gw="192.168.4.1",
.netmask="255.255.255.0",
.mac_address={0x98, 0x0e, 0x24, 0x00, 0x11, 0x1},
},
#endif
};
static void SetIP(ip_addr_t* ipaddr,ip_addr_t* gw,ip_addr_t* netmask,u32 mac_id)
{
if(inet_aton(board_mac_config[mac_id].ipaddr,ipaddr)==0)
printf("The addr of ipaddr is wrong\r\n");
if(inet_aton(board_mac_config[mac_id].gw,gw)==0)
printf("The addr of gw is wrong\r\n");
if(inet_aton(board_mac_config[mac_id].netmask,netmask)==0)
printf("The addr of netmask is wrong\r\n");
}
static err_t tcp_recv_callback(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)
{
/* p is NULL means we received tcp packet with FIN flag */
if (p == NULL)
{
printf("Connection closed! Waiting client to connect.\n");
return tcp_close(tpcb);
}
else
{
printf("We get data: %s",(char *)p->payload);
/* update receive buffer */
tcp_recved(tpcb, p->tot_len);
/* Returning received data to the client */
tcp_write(tpcb, p->payload, p->tot_len, 1);
memset(p->payload, 0, p->tot_len);
pbuf_free(p);
}
return ERR_OK;
}
static err_t tcp_accept_callback(void *arg, struct tcp_pcb *newpcb, err_t err)
{
printf("Connection Established!\r\n");
tcp_recv(newpcb, tcp_recv_callback);
return ERR_OK;
}
void TcpServerInit(void)
{
ip_addr_t local_ip;
struct tcp_pcb *temp_pcb;
struct tcp_pcb *listen_pcb;
err_t ret = ERR_OK;
/* create a tcp_pcb*/
temp_pcb = tcp_new();
if (temp_pcb == NULL)
{
printf("Unable to create a new tcp_pcb\r\n");
return ;
}
/* bind the local ip and local port */
IP_ADDR4(&local_ip, 192, 168, 4, 10);
ret = tcp_bind(temp_pcb, &local_ip, TCP_SERVER_PORT);
if (ret == ERR_USE)
{
printf("The port and ip are already binded!\n");
tcp_close(temp_pcb);
return;
}
/* listening */
listen_pcb = tcp_listen(temp_pcb);
/*register a connection-established function*/
tcp_accept(listen_pcb, tcp_accept_callback);
printf("Tcp Server Open Success!\r\n");
}
int TcpServerCreate(void)
{
FError ret = FT_SUCCESS;
/* mac init */
for (int i = 0; i < MAC_NUM; i++)
{
struct netif *netif_p = NULL;
ip_addr_t ipaddr,netmask, gw;
board_mac_config[i].lwip_mac_config.name[0] = ETH_NAME_PREFIX;
itoa(board_mac_config[i].lwip_mac_config.mac_instance, &(board_mac_config[i].lwip_mac_config.name[1]), 10);
/* mac ip addr set: char* -> ip_addr_t */
SetIP(&ipaddr,&gw,&netmask,i);
/* ******************************************************************* */
netif_p= &board_mac_config[i].netif;
/* Add network interface to the netif_list, and set it as default */
if (!LwipPortAdd(netif_p, &ipaddr, &netmask, &gw, board_mac_config[i].mac_address, (UserConfig *)&board_mac_config[i]))
{
printf("Error adding N/W interface %d.\n\r",board_mac_config[i].lwip_mac_config.mac_instance);
ret = ERR_GENERAL;
goto exit;
}
printf("LwipPortAdd mac_instance %d is over.\n\r",board_mac_config[i].lwip_mac_config.mac_instance);
netif_set_default(netif_p);
if (netif_is_link_up(netif_p))
{
/* 当netif完全配置好时,必须调用该函数 */
netif_set_up(netif_p);
if (board_mac_config[i].dhcp_en == 1)
{
LwipPortDhcpSet(netif_p, TRUE);
}
}
else
{
/* 当netif链接关闭时,必须调用该函数 */
netif_set_down(netif_p);
}
}
printf("Network setup complete.\n");
TcpServerInit();
exit:
if (ret == FT_SUCCESS)
{
printf("%s@%d:Tcp server example [success].\r\n", __func__, __LINE__);
return 0;
}
else
{
printf("%s@%d:Tcp server example [failure].\r\n", __func__, __LINE__);
return 1;
}
}
void TcpServerDeinit(void)
{
for (int i = 0; i < MAC_NUM; i++)
{
struct netif *netif_p = NULL;
netif_p=&board_mac_config[i].netif;
LwipPortStop(netif_p,board_mac_config[i].dhcp_en);
}
}

67
example/network/raw_api/udp_client/README.md

@ -4,9 +4,10 @@
> `<font size="1">`介绍例程的用途,使用场景,相关基本概念,描述用户可以使用例程完成哪些工作`</font><br />`
本例程利用LWIP网络协议栈中的raw api实现了下述功能:
本例程示范了MAC控制器在lwip ipv4模式下的初始化流程,同时通过LWIP网络协议栈中的raw api,可以实现网卡作为client,利用udp与外界进行通信。
- LWIP网络协议栈初始化
### 1.1 UDP Client特性测试例程 (udp_client_example.c)
- ipv4模式下初始化开发板上所有网口以及对应网卡控制器
- 开发板向网络主机发送udp数据包
- 网络主机在屏幕端打印收到的数据
@ -14,35 +15,30 @@
> `<font size="1">`描述开发平台准备,使用例程配置,构建和下载镜像的过程`</font><br />`
- 本例程在E2000上测试通过,您可以参考以下方法配置本例程所需要的硬件和软件环境
本例程需要以下硬件:
- E2000D/Q Demo板,FT2000/4开发板,D2000开发板,PhytiumPi
- 串口线和串口上位机
### 2.1 硬件配置方法
> `<font size="1">`哪些硬件平台是支持的,需要哪些外设,例程与开发板哪些IO口相关等(建议附录开发板照片,展示哪些IO口被引出)`</font><br />`
本例程支持以下硬件平台
- FT2000/4
- D2000开发板
- E2000 系列开发板
D2000开发板图片示例如下:
D2000开发板图片示例
![board](./fig/board.png)
DEMO开发板图片示例如下所示
E2000Q DEMO开发板图片示例
![demo_board](./fig/demo_board.jpg)
### 2.2 SDK配置方法
> `<font size="1">`依赖哪些驱动、库和第三方组件,如何完成配置(列出需要使能的关键配置项)`</font><br />`
本例程需要,
本例程需要:
- LWIP组件,依赖 USE_LWIP
- Letter Shell组件,依赖 USE_LETTER_SHELL
对应的配置项是,
对应的配置项是:
- CONFIG_USE_LWIP
- CONFIG_USE_LETTER_SHELL
@ -66,7 +62,7 @@ DEMO开发板图片示例如下所示
#### 2.3.1 构建过程
本文档将以E2000demo开发板为例,对于其它平台,使用对应的默认配置
本文档将以E2000d demo开发板为例,对于其它平台,使用对应的默认配置
- 在host端完成配置
- 选择目标平台
@ -115,31 +111,9 @@ bootelf -p 0x90100000
> `<font size="1">`描述输入输出情况,列出存在哪些输出,对应的输出是什么(建议附录相关现象图片)`</font><br />`
- 启动进入后,根据连接的网口,输入指令完成网口初始化
#### 2.4.1 初始化LWIP网络协议栈
- 输入以下命令,初始化LWIP网络协议栈, 依次设置网卡和dhcp使能,配置ip地址,子网掩码,网关地址,运行完成退出后LWIP协议栈会持续运行
- lwip probe 指令介绍
```
lwip probe <driver id> <device id> <interface id> <dhcp_en> <ipaddr> <gateway> <netmask>
```
- 其中driver id 为驱动类型 , 0为xmac ,1为gmac
- device id 为控制器id
- interface id ,0 为rgmii ,1 为sgmii
- dhcp en,0 表示关闭dhcp功能,1表示开启dhcp功能,网卡将根据dhcp协议获得ip地址(当协议栈支持dhcp时,该参数才具有实际作用)
- 输入以下命令,初始化LWIP网络协议栈, 依次设置网卡和dhcp使能,配置ip地址,子网掩码,网关地址,运行完成退出后LWIP协议栈会持续运行
```
$ lwip probe 0 0 1 0 192.168.4.10 192.168.4.1 255.255.255.0
```
#### 2.4.2 开启udpclient
#### 2.4.1 UDP Client特性测试例程 (udp_client_example.c)
- 首先在host端开启udp端口监听,输入以下命令
```
nc -ul 192.168.4.50 5002
```
@ -147,16 +121,13 @@ nc -ul 192.168.4.50 5002
- 接着在开发板终端输入以下命令,开始udp client 测试
```
$ udpclient
udpclient
```
- 开发板发送UDP数据到主机的端口,主机打印收到的数据
- 开发板实验输出结果
![udpclient](./fig/udp_client.png)
- 主机端实验输出结果
![host-udp](./fig/host_udp.png)
## 3. 如何解决问题
@ -165,16 +136,16 @@ $ udpclient
- Q: 如何配置udp client的local ip与local port以及remote ip 与remote port?
- A: 在udp_client.c中修改如下变量ipaddr以及修改宏定义UDP_ECHO_PORT即可:
- A: 在udp_client_example.c中修改如下变量ipaddr以及修改宏定义UDP_LOCAL_PORT,UDP_REMOTE_PORT即可:
```
#define UDP_ECHO_PORT 5001
#define UDP_LOCAL_PORT 5001
#define UDP_REMOTE_PORT 5002
......
IP_ADDR4(&ipaddr, 192, 168, 4, 10);
udp_bind(client_pcb, &ipaddr, UDP_ECHO_PORT);
udp_bind(client_pcb, &ipaddr, UDP_LOCAL_PORT);
IP_ADDR4(&ipaddr, 192, 168, 4, 50);
udp_connect(client_pcb, &ipaddr, 5002);
udp_connect(client_pcb, &ipaddr, UDP_REMOTE_PORT);
```
## 4. 修改历史记录

10
example/network/raw_api/udp_client/configs/d2000_aarch32_test_udpclient.config

@ -234,7 +234,13 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# DHCP
#
# CONFIG_LWIP_DHCP_ENABLE is not set
CONFIG_LWIP_DHCP_ENABLE=y
# CONFIG_LWIP_DHCP_DOES_ARP_CHECK is not set
# CONFIG_LWIP_DHCP_GET_NTP_SRV is not set
# CONFIG_LWIP_DHCP_DISABLE_CLIENT_ID is not set
# CONFIG_LWIP_DHCP_RESTORE_LAST_IP is not set
CONFIG_LWIP_DHCP_OPTIONS_LEN=68
CONFIG_LWIP_DHCP_DISABLE_VENDOR_CLASS_ID=y
# end of DHCP
#
@ -246,7 +252,7 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# IGMP
#
CONFIG_LWIP_IGMP_EN=y
# CONFIG_LWIP_IGMP_EN is not set
# end of IGMP
#

10
example/network/raw_api/udp_client/configs/d2000_aarch64_test_udpclient.config

@ -228,7 +228,13 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# DHCP
#
# CONFIG_LWIP_DHCP_ENABLE is not set
CONFIG_LWIP_DHCP_ENABLE=y
# CONFIG_LWIP_DHCP_DOES_ARP_CHECK is not set
# CONFIG_LWIP_DHCP_GET_NTP_SRV is not set
# CONFIG_LWIP_DHCP_DISABLE_CLIENT_ID is not set
# CONFIG_LWIP_DHCP_RESTORE_LAST_IP is not set
CONFIG_LWIP_DHCP_OPTIONS_LEN=68
CONFIG_LWIP_DHCP_DISABLE_VENDOR_CLASS_ID=y
# end of DHCP
#
@ -240,7 +246,7 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# IGMP
#
CONFIG_LWIP_IGMP_EN=y
# CONFIG_LWIP_IGMP_EN is not set
# end of IGMP
#

10
example/network/raw_api/udp_client/configs/e2000d_aarch32_demo_udpclient.config

@ -247,7 +247,13 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# DHCP
#
# CONFIG_LWIP_DHCP_ENABLE is not set
CONFIG_LWIP_DHCP_ENABLE=y
# CONFIG_LWIP_DHCP_DOES_ARP_CHECK is not set
# CONFIG_LWIP_DHCP_GET_NTP_SRV is not set
# CONFIG_LWIP_DHCP_DISABLE_CLIENT_ID is not set
# CONFIG_LWIP_DHCP_RESTORE_LAST_IP is not set
CONFIG_LWIP_DHCP_OPTIONS_LEN=68
CONFIG_LWIP_DHCP_DISABLE_VENDOR_CLASS_ID=y
# end of DHCP
#
@ -259,7 +265,7 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# IGMP
#
CONFIG_LWIP_IGMP_EN=y
# CONFIG_LWIP_IGMP_EN is not set
# end of IGMP
#

10
example/network/raw_api/udp_client/configs/e2000d_aarch64_demo_udpclient.config

@ -241,7 +241,13 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# DHCP
#
# CONFIG_LWIP_DHCP_ENABLE is not set
CONFIG_LWIP_DHCP_ENABLE=y
# CONFIG_LWIP_DHCP_DOES_ARP_CHECK is not set
# CONFIG_LWIP_DHCP_GET_NTP_SRV is not set
# CONFIG_LWIP_DHCP_DISABLE_CLIENT_ID is not set
# CONFIG_LWIP_DHCP_RESTORE_LAST_IP is not set
CONFIG_LWIP_DHCP_OPTIONS_LEN=68
CONFIG_LWIP_DHCP_DISABLE_VENDOR_CLASS_ID=y
# end of DHCP
#
@ -253,7 +259,7 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# IGMP
#
CONFIG_LWIP_IGMP_EN=y
# CONFIG_LWIP_IGMP_EN is not set
# end of IGMP
#

10
example/network/raw_api/udp_client/configs/e2000q_aarch32_demo_udpclient.config

@ -246,7 +246,13 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# DHCP
#
# CONFIG_LWIP_DHCP_ENABLE is not set
CONFIG_LWIP_DHCP_ENABLE=y
# CONFIG_LWIP_DHCP_DOES_ARP_CHECK is not set
# CONFIG_LWIP_DHCP_GET_NTP_SRV is not set
# CONFIG_LWIP_DHCP_DISABLE_CLIENT_ID is not set
# CONFIG_LWIP_DHCP_RESTORE_LAST_IP is not set
CONFIG_LWIP_DHCP_OPTIONS_LEN=68
CONFIG_LWIP_DHCP_DISABLE_VENDOR_CLASS_ID=y
# end of DHCP
#
@ -258,7 +264,7 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# IGMP
#
CONFIG_LWIP_IGMP_EN=y
# CONFIG_LWIP_IGMP_EN is not set
# end of IGMP
#

10
example/network/raw_api/udp_client/configs/e2000q_aarch64_demo_udpclient.config

@ -240,7 +240,13 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# DHCP
#
# CONFIG_LWIP_DHCP_ENABLE is not set
CONFIG_LWIP_DHCP_ENABLE=y
# CONFIG_LWIP_DHCP_DOES_ARP_CHECK is not set
# CONFIG_LWIP_DHCP_GET_NTP_SRV is not set
# CONFIG_LWIP_DHCP_DISABLE_CLIENT_ID is not set
# CONFIG_LWIP_DHCP_RESTORE_LAST_IP is not set
CONFIG_LWIP_DHCP_OPTIONS_LEN=68
CONFIG_LWIP_DHCP_DISABLE_VENDOR_CLASS_ID=y
# end of DHCP
#
@ -252,7 +258,7 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# IGMP
#
CONFIG_LWIP_IGMP_EN=y
# CONFIG_LWIP_IGMP_EN is not set
# end of IGMP
#

10
example/network/raw_api/udp_client/configs/ft2004_aarch32_dsk_udpclient.config

@ -234,7 +234,13 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# DHCP
#
# CONFIG_LWIP_DHCP_ENABLE is not set
CONFIG_LWIP_DHCP_ENABLE=y
# CONFIG_LWIP_DHCP_DOES_ARP_CHECK is not set
# CONFIG_LWIP_DHCP_GET_NTP_SRV is not set
# CONFIG_LWIP_DHCP_DISABLE_CLIENT_ID is not set
# CONFIG_LWIP_DHCP_RESTORE_LAST_IP is not set
CONFIG_LWIP_DHCP_OPTIONS_LEN=68
CONFIG_LWIP_DHCP_DISABLE_VENDOR_CLASS_ID=y
# end of DHCP
#
@ -246,7 +252,7 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# IGMP
#
CONFIG_LWIP_IGMP_EN=y
# CONFIG_LWIP_IGMP_EN is not set
# end of IGMP
#

10
example/network/raw_api/udp_client/configs/ft2004_aarch64_dsk_udpclient.config

@ -228,7 +228,13 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# DHCP
#
# CONFIG_LWIP_DHCP_ENABLE is not set
CONFIG_LWIP_DHCP_ENABLE=y
# CONFIG_LWIP_DHCP_DOES_ARP_CHECK is not set
# CONFIG_LWIP_DHCP_GET_NTP_SRV is not set
# CONFIG_LWIP_DHCP_DISABLE_CLIENT_ID is not set
# CONFIG_LWIP_DHCP_RESTORE_LAST_IP is not set
CONFIG_LWIP_DHCP_OPTIONS_LEN=68
CONFIG_LWIP_DHCP_DISABLE_VENDOR_CLASS_ID=y
# end of DHCP
#
@ -240,7 +246,7 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# IGMP
#
CONFIG_LWIP_IGMP_EN=y
# CONFIG_LWIP_IGMP_EN is not set
# end of IGMP
#

10
example/network/raw_api/udp_client/configs/pd2308_aarch64_demo_udpclient.config

@ -237,7 +237,13 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# DHCP
#
# CONFIG_LWIP_DHCP_ENABLE is not set
CONFIG_LWIP_DHCP_ENABLE=y
# CONFIG_LWIP_DHCP_DOES_ARP_CHECK is not set
# CONFIG_LWIP_DHCP_GET_NTP_SRV is not set
# CONFIG_LWIP_DHCP_DISABLE_CLIENT_ID is not set
# CONFIG_LWIP_DHCP_RESTORE_LAST_IP is not set
CONFIG_LWIP_DHCP_OPTIONS_LEN=68
CONFIG_LWIP_DHCP_DISABLE_VENDOR_CLASS_ID=y
# end of DHCP
#
@ -249,7 +255,7 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# IGMP
#
CONFIG_LWIP_IGMP_EN=y
# CONFIG_LWIP_IGMP_EN is not set
# end of IGMP
#

10
example/network/raw_api/udp_client/configs/phytiumpi_aarch32_firefly_udpclient.config

@ -245,7 +245,13 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# DHCP
#
# CONFIG_LWIP_DHCP_ENABLE is not set
CONFIG_LWIP_DHCP_ENABLE=y
# CONFIG_LWIP_DHCP_DOES_ARP_CHECK is not set
# CONFIG_LWIP_DHCP_GET_NTP_SRV is not set
# CONFIG_LWIP_DHCP_DISABLE_CLIENT_ID is not set
# CONFIG_LWIP_DHCP_RESTORE_LAST_IP is not set
CONFIG_LWIP_DHCP_OPTIONS_LEN=68
CONFIG_LWIP_DHCP_DISABLE_VENDOR_CLASS_ID=y
# end of DHCP
#
@ -257,7 +263,7 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# IGMP
#
CONFIG_LWIP_IGMP_EN=y
# CONFIG_LWIP_IGMP_EN is not set
# end of IGMP
#

10
example/network/raw_api/udp_client/configs/phytiumpi_aarch64_firefly_udpclient.config

@ -239,7 +239,13 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# DHCP
#
# CONFIG_LWIP_DHCP_ENABLE is not set
CONFIG_LWIP_DHCP_ENABLE=y
# CONFIG_LWIP_DHCP_DOES_ARP_CHECK is not set
# CONFIG_LWIP_DHCP_GET_NTP_SRV is not set
# CONFIG_LWIP_DHCP_DISABLE_CLIENT_ID is not set
# CONFIG_LWIP_DHCP_RESTORE_LAST_IP is not set
CONFIG_LWIP_DHCP_OPTIONS_LEN=68
CONFIG_LWIP_DHCP_DISABLE_VENDOR_CLASS_ID=y
# end of DHCP
#
@ -251,7 +257,7 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# IGMP
#
CONFIG_LWIP_IGMP_EN=y
# CONFIG_LWIP_IGMP_EN is not set
# end of IGMP
#

BIN
example/network/raw_api/udp_client/fig/ping_ipv4.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

BIN
example/network/raw_api/udp_client/fig/ping_ipv4_dhcp.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

BIN
example/network/raw_api/udp_client/fig/ping_ipv6.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 52 KiB

BIN
example/network/raw_api/udp_client/fig/probe_ipv4.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

BIN
example/network/raw_api/udp_client/fig/probe_ipv4_dhcp.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

BIN
example/network/raw_api/udp_client/fig/probe_ipv6.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

BIN
example/network/raw_api/udp_client/fig/udp_client.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 20 KiB

57
example/network/raw_api/udp_client/inc/lwip_timer.h

@ -0,0 +1,57 @@
/*
* Copyright : (C) 2024 Phytium Information Technology, Inc.
* All Rights Reserved.
*
* This program is OPEN SOURCE software: you can redistribute it and/or modify it
* under the terms of the Phytium Public License as published by the Phytium Technology Co.,Ltd,
* either version 1.0 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the Phytium Public License for more details.
*
*
* FilePath: lwip_timer.h
* Created Date: 2024-06-05 16:55:41
* Last Modified: 2024-06-12 17:37:29
* Description: This file is for lwip timer function definition.
*
* Modify History:
* Ver Who Date Changes
* ----- ---------- -------- ---------------------------------
* 1.0 liuzhihong 2024/06/04 first release
*/
#ifndef LWIP_TIMER_H
#define LWIP_TIMER_H
/***************************** Include Files *********************************/
#include "ftypes.h"
#ifdef __cplusplus
extern "C"
{
#endif
/************************** Constant Definitions *****************************/
/**************************** Type Definitions *******************************/
/************************** Variable Definitions *****************************/
/***************** Macros (Inline Functions) Definitions *********************/
/************************** Function Prototypes ******************************/
/* entry function for lwip timer example */
#ifdef CONFIG_USE_LETTER_SHELL
void TimerLoop(void);
#else
void TimerStaticInit(void);
void TimerStaticLoop(u32 time);
#endif
#ifdef __cplusplus
}
#endif
#endif

51
example/network/raw_api/udp_client/inc/udp_client_example.h

@ -0,0 +1,51 @@
/*
* Copyright : (C) 2024 Phytium Information Technology, Inc.
* All Rights Reserved.
*
* This program is OPEN SOURCE software: you can redistribute it and/or modify it
* under the terms of the Phytium Public License as published by the Phytium Technology Co.,Ltd,
* either version 1.0 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the Phytium Public License for more details.
*
*
* FilePath: udp_client_example.h
* Created Date: 2024-06-05 16:55:56
* Last Modified: 2024-06-12 17:37:42
* Description: This file is for udp client example function definition.
*
* Modify History:
* Ver Who Date Changes
* ----- ---------- -------- ---------------------------------
* 1.0 liuzhihong 2024/06/04 first release
*/
#ifndef UDP_CLIENT_EXAMPLE_H
#define UDP_CLIENT_EXAMPLE_H
/***************************** Include Files *********************************/
#include "ftypes.h"
#ifdef __cplusplus
extern "C"
{
#endif
/************************** Constant Definitions *****************************/
/**************************** Type Definitions *******************************/
/************************** Variable Definitions *****************************/
/***************** Macros (Inline Functions) Definitions *********************/
/************************** Function Prototypes ******************************/
/* entry function for udp server example */
int UdpClientCreate(void);
void UdpClientDeinit(void);
#ifdef __cplusplus
}
#endif
#endif

64
example/network/raw_api/udp_client/main.c

@ -1,40 +1,64 @@
/*
* Copyright : (C) 2022 Phytium Information Technology, Inc.
* Copyright : (C) 2024 Phytium Information Technology, Inc.
* All Rights Reserved.
*
*
* This program is OPEN SOURCE software: you can redistribute it and/or modify it
* under the terms of the Phytium Public License as published by the Phytium Technology Co.,Ltd,
* either version 1.0 of the License, or (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the Phytium Public License for more details.
*
*
*
*
* FilePath: main.c
* Date: 2022-02-10 14:53:41
* LastEditTime: 2022-02-17 17:38:03
* Description:  This file is for creating a main loop from which the programme will start.
*
* Modify History:
* Ver Who Date Changes
* ----- ------ -------- --------------------------------------
* 1.0 liuzhihong 2022/11/16 first release
* Created Date: 2024-05-30 19:05:18
* Last Modified: 2024-06-12 17:55:39
* Description: This file is for udp client example main functions.
*
* Modify History:
* Ver Who Date Changes
* ----- ---------- -------- ---------------------------------
* 1.0 liuzhihong 2024/06/03 first release
*/
#include <string.h>
#include <stdio.h>
#include "sdkconfig.h"
#include "sdkconfig.h"
#ifndef SDK_CONFIG_H__
#warning "Please include sdkconfig.h"
#endif
#ifndef CONFIG_USE_LETTER_SHELL
#error "Please include letter shell first!!!"
#ifdef CONFIG_USE_LETTER_SHELL
#include "shell_port.h"
#endif
extern void TimerLoop(void);
#include "udp_client_example.h"
#include "lwip_timer.h"
/************************** Constant Definitions *****************************/
/**************************** Type Definitions *******************************/
/************************** Variable Definitions *****************************/
/***************** Macros (Inline Functions) Definitions *********************/
/************************** Function Prototypes ******************************/
/************************** Function *****************************************/
int main()
{
TimerLoop();
#ifdef CONFIG_USE_LETTER_SHELL
/* if shell command is enabled, register example entry as shell command */
TimerLoop();
#else
TimerStaticInit();
TimerStaticLoop(3);
UdpClientCreate();
TimerStaticLoop(3);
UdpClientDeinit();
#endif
return 0;
}

1
example/network/raw_api/udp_client/makefile

@ -3,7 +3,6 @@ SDK_DIR ?= $(CURDIR)/../../../..
USER_CSRC := main.c
USER_CSRC += $(wildcard src/*.c)
USER_CSRC += $(wildcard ../common/*.c)
USER_INCLUDE := $(PROJECT_DIR) \
$(PROJECT_DIR)/inc \

10
example/network/raw_api/udp_client/sdkconfig

@ -239,7 +239,13 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# DHCP
#
# CONFIG_LWIP_DHCP_ENABLE is not set
CONFIG_LWIP_DHCP_ENABLE=y
# CONFIG_LWIP_DHCP_DOES_ARP_CHECK is not set
# CONFIG_LWIP_DHCP_GET_NTP_SRV is not set
# CONFIG_LWIP_DHCP_DISABLE_CLIENT_ID is not set
# CONFIG_LWIP_DHCP_RESTORE_LAST_IP is not set
CONFIG_LWIP_DHCP_OPTIONS_LEN=68
CONFIG_LWIP_DHCP_DISABLE_VENDOR_CLASS_ID=y
# end of DHCP
#
@ -251,7 +257,7 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# IGMP
#
CONFIG_LWIP_IGMP_EN=y
# CONFIG_LWIP_IGMP_EN is not set
# end of IGMP
#

10
example/network/raw_api/udp_client/sdkconfig.h

@ -212,7 +212,13 @@
/* DHCP */
/* CONFIG_LWIP_DHCP_ENABLE is not set */
#define CONFIG_LWIP_DHCP_ENABLE
/* CONFIG_LWIP_DHCP_DOES_ARP_CHECK is not set */
/* CONFIG_LWIP_DHCP_GET_NTP_SRV is not set */
/* CONFIG_LWIP_DHCP_DISABLE_CLIENT_ID is not set */
/* CONFIG_LWIP_DHCP_RESTORE_LAST_IP is not set */
#define CONFIG_LWIP_DHCP_OPTIONS_LEN 68
#define CONFIG_LWIP_DHCP_DISABLE_VENDOR_CLASS_ID
/* end of DHCP */
/* AUTOIP */
@ -222,7 +228,7 @@
/* IGMP */
#define CONFIG_LWIP_IGMP_EN
/* CONFIG_LWIP_IGMP_EN is not set */
/* end of IGMP */
/* DNS */

68
example/network/raw_api/udp_client/src/cmd_udp_client.c

@ -0,0 +1,68 @@
/*
* Copyright : (C) 2024 Phytium Information Technology, Inc.
* All Rights Reserved.
*
* This program is OPEN SOURCE software: you can redistribute it and/or modify it
* under the terms of the Phytium Public License as published by the Phytium Technology Co.,Ltd,
* either version 1.0 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the Phytium Public License for more details.
*
*
* FilePath: cmd_udp_client.c
* Created Date: 2024-06-05 16:55:34
* Last Modified: 2024-06-12 17:37:48
* Description: This file is for udp client example cmd catalogue.
*
* Modify History:
* Ver Who Date Changes
* ----- ---------- -------- ---------------------------------
* 1.0 liuzhihong 2024/06/04 first release
*/
#include <stdio.h>
#include <string.h>
#include "sdkconfig.h"
#ifndef SDK_CONFIG_H__
#warning "Please include sdkconfig.h"
#endif
#ifdef CONFIG_USE_LETTER_SHELL
#include "shell.h"
#include "strto.h"
#include "udp_client_example.h"
#define EXAMPLE_IDLE 0
#define UDP_CLIENT_EXAMPLE_RUNNING 1
static u32 init_flag_mask=EXAMPLE_IDLE;
static void UdpClientExampleCheckState(void)
{
switch(init_flag_mask)
{
case UDP_CLIENT_EXAMPLE_RUNNING:
printf("Udp client example is running, we need to deinitialize it first! \r\n");
UdpClientDeinit();
init_flag_mask=EXAMPLE_IDLE;
break;
default:
break;
}
}
/* entry function for udp client example */
static int UdpClientExampleEntry(int argc, char *argv[])
{
int ret = 0;
UdpClientExampleCheckState();
ret = UdpClientCreate();
init_flag_mask = UDP_CLIENT_EXAMPLE_RUNNING;
return ret;
}
/* register command for udp client example */
SHELL_EXPORT_CMD(SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN), udpclient, UdpClientExampleEntry, Start Udp client);
#endif

219
example/network/raw_api/udp_client/src/lwip_timer.c

@ -0,0 +1,219 @@
/*
* Copyright : (C) 2024 Phytium Information Technology, Inc.
* All Rights Reserved.
*
* This program is OPEN SOURCE software: you can redistribute it and/or modify it
* under the terms of the Phytium Public License as published by the Phytium Technology Co.,Ltd,
* either version 1.0 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the Phytium Public License for more details.
*
*
* FilePath: lwip_timer.c
* Created Date: 2024-06-05 16:54:57
* Last Modified: 2024-06-12 17:37:53
* Description: This file is for lwip timer function implementation.
*
* Modify History:
* Ver Who Date Changes
* ----- ---------- -------- ---------------------------------
* 1.0 liuzhihong 2024/06/04 first release
*/
#include <string.h>
#include <stdio.h>
#include "strto.h"
#include "fgeneric_timer.h"
#include "ftypes.h"
#include "fparameters.h"
#include "finterrupt.h"
#include "fassert.h"
#include "timeouts.h"
#ifdef CONFIG_USE_LETTER_SHELL
#include "shell_port.h"
#endif
#include "sdkconfig.h"
#ifndef SDK_CONFIG_H__
#error "Please include sdkconfig.h first"
#endif
#include "lwip_port.h"
#include "lwip/ip4_addr.h"
#include "lwip/init.h"
#include "netif/ethernet.h"
#include "lwip/netif.h"
#include "lwip/tcpip.h"
#include "lwip/inet.h"
#include "lwip/dhcp.h"
#include "ifconfig.h"
#define TIMER_BASE_RATE_HZ 1000 /* 为timer_base_cnt 提供time base */
#define TIMER_INTERRUPT_PRO IRQ_PRIORITY_VALUE_3
#ifdef CONFIG_ARCH_ARMV8_AARCH64
#define MAX_TIMER_CNT 0xffffffffffffffff
#else
#define MAX_TIMER_CNT 0xffffffff
#endif
static u32 timer_base_cnt = 0;
void LwipTestLoop(void)
{
struct netif *netif;
netif = netif_list;
while (netif != NULL)
{
if (netif->state)
{
LwipPortInput(netif);
LinkDetectLoop(netif);
}
netif = netif->next;
}
}
void LwipTestDhcpLoop(u32 msec)
{
LwipPortDhcpLoop(msec);
}
static void GenericTimerIntrHandler(s32 vector, void *param)
{
(void)vector;
FASSERT(param != 0);
u32 timer_base_freq = (u32)(uintptr)param;
timer_base_cnt++;
/* clear tick interrupt */
GenericTimerSetTimerValue(GENERIC_TIMER_ID0, GenericTimerFrequecy() / timer_base_freq);
}
void TimerLoopInit(void)
{
u32 cnt_frq;
timer_base_cnt = 0;
/* disable timer and get system frequency */
GenericTimerStop(GENERIC_TIMER_ID0);
cnt_frq = GenericTimerFrequecy();
/* set tick rate */
GenericTimerSetTimerValue(GENERIC_TIMER_ID0, cnt_frq / TIMER_BASE_RATE_HZ);
GenericTimerInterruptEnable(GENERIC_TIMER_ID0);
/* set generic timer interrupt */
InterruptSetPriority(GENERIC_TIMER_NS_IRQ_NUM, TIMER_INTERRUPT_PRO);
/* install tick handler */
InterruptInstall(GENERIC_TIMER_NS_IRQ_NUM, GenericTimerIntrHandler,
(void *)TIMER_BASE_RATE_HZ, "GenericTimerTick");
/* enable interrupt */
InterruptUmask(GENERIC_TIMER_NS_IRQ_NUM);
GenericTimerStart(GENERIC_TIMER_ID0);
}
#ifdef CONFIG_USE_LETTER_SHELL
void TimerLoop(void)
{
u32 _5ms_appear = 0;
u32 base_cnt_back = 0;
TimerLoopInit();
LSUserShellInit();
lwip_init(); /* lwip only init once */
while (1)
{
LSuserShellNoWaitLoop();
LwipTestLoop();
if (((timer_base_cnt % 5) == 0) && (_5ms_appear == 0)) /*5ms task */
{
_5ms_appear = 1;
LwipTestDhcpLoop(5);
}
else if ((timer_base_cnt % 5) != 0)
{
_5ms_appear = 0;
}
if(timer_base_cnt != base_cnt_back)
{
sys_check_timeouts();
base_cnt_back = timer_base_cnt;
}
}
}
#else
void TimerStaticInit(void)
{
TimerLoopInit();
lwip_init(); /* lwip only init once */
}
/**
* @name: TimerStaticLoop
* @msg: time时间内进行网卡数据收发
* @return void
* @note:
* @param {u32} time
*/
void TimerStaticLoop(u32 time)
{
u32 _5ms_appear = 0;
u32 base_cnt_back = 0;
u32 timer_start=0;
u32 time_pass_cnt=0;
u32 time_cnt;
u32 old = 0;
time_cnt = time * GenericTimerFrequecy();
timer_start = GenericTimerRead(GENERIC_TIMER_ID0);
while (time_pass_cnt<time_cnt)
{
LwipTestLoop();
if (((timer_base_cnt % 5) == 0) && (_5ms_appear == 0)) /*5ms task */
{
_5ms_appear = 1;
LwipTestDhcpLoop(5);
}
else if ((timer_base_cnt % 5) != 0)
{
_5ms_appear = 0;
}
if(timer_base_cnt != base_cnt_back)
{
sys_check_timeouts();
base_cnt_back = timer_base_cnt;
}
if(GenericTimerRead(GENERIC_TIMER_ID0)>timer_start)
time_pass_cnt = GenericTimerRead(GENERIC_TIMER_ID0)-timer_start;
else
time_pass_cnt = GenericTimerRead(GENERIC_TIMER_ID0)+(MAX_TIMER_CNT-timer_start);
if(old != time-time_pass_cnt/GenericTimerFrequecy())
{
printf("Only left %d seconds\r\n", time-time_pass_cnt/GenericTimerFrequecy());
old = time-time_pass_cnt/GenericTimerFrequecy();
}
}
ListIf();
}
#endif
u32_t sys_now(void)
{
return timer_base_cnt;
}

83
example/network/raw_api/udp_client/src/udp_client.c

@ -1,83 +0,0 @@
/*
* Copyright : (C) 2022 Phytium Information Technology, Inc.
* All Rights Reserved.
*
* This program is OPEN SOURCE software: you can redistribute it and/or modify it
* under the terms of the Phytium Public License as published by the Phytium Technology Co.,Ltd,
* either version 1.0 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the Phytium Public License for more details.
*
*
* FilePath: udp_client.c
* Date: 2022-10-25 16:44:49
* LastEditTime: 2022-12-05 18:13:22
* Description: This file is for creating a udp client.The client can send a udp packet to the destination host.
*
* Modify History:
* Ver Who Date Changes
* ----- ------ -------- --------------------------------------
* 1.0 liuzhihong 2022/11/16 first release
*/
#include "lwip/netif.h"
#include "lwip/ip.h"
#include "lwip/tcp.h"
#include "lwip/init.h"
#include "netif/etharp.h"
#include "lwip/udp.h"
#include "lwip/pbuf.h"
#include <stdio.h>
#include <string.h>
#include "shell_port.h"
#define UDP_ECHO_PORT 5001
void UdpClient(void)
{
struct udp_pcb *client_pcb;
struct pbuf *q = NULL;
/* create a udp_pcb */
client_pcb = udp_new();
if (client_pcb == NULL)
{
printf("Create new Udb_pcb falied.\n");
return ;
}
/*bind the local port and local ip */
ip_addr_t ipaddr;
IP_ADDR4(&ipaddr, 192, 168, 4, 10);
udp_bind(client_pcb, &ipaddr, UDP_ECHO_PORT);
IP_ADDR4(&ipaddr, 192, 168, 4, 50);
udp_connect(client_pcb, &ipaddr, 5002);
/*applying for memory resources*/
const char *reply = "This is a data from Udp client!\n";
q = pbuf_alloc(PBUF_TRANSPORT, strlen(reply) + 1, PBUF_RAM);
if (!q)
{
printf("Out of PBUF_RAM.\n");
return;
}
memset(q->payload, 0, q->len);
memcpy(q->payload, reply, strlen(reply));
/*sending data*/
printf("We sent a data to Udp Server.\n");
udp_send(client_pcb, q);
/*Releasing resources*/
udp_remove(client_pcb);
pbuf_free(q);
}
SHELL_EXPORT_CMD(SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN), udpclient, UdpClient, Start Udp client);

215
example/network/raw_api/udp_client/src/udp_client_example.c

@ -0,0 +1,215 @@
/*
* Copyright : (C) 2024 Phytium Information Technology, Inc.
* All Rights Reserved.
*
* This program is OPEN SOURCE software: you can redistribute it and/or modify it
* under the terms of the Phytium Public License as published by the Phytium Technology Co.,Ltd,
* either version 1.0 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the Phytium Public License for more details.
*
*
* FilePath: udp_client_example.c
* Created Date: 2024-05-30 19:05:18
* Last Modified: 2024-06-12 17:37:59
* Description: This file is for udp client example function implementation.
*
* Modify History:
* Ver Who Date Changes
* ----- ---------- -------- ---------------------------------
* 1.0 liuzhihong 2024/06/04 first release
*/
#include <string.h>
#include <stdio.h>
#include "strto.h"
#include "sdkconfig.h"
#include "ftypes.h"
#include "fassert.h"
#include "fparameters.h"
#include "eth_board.h"
#ifndef SDK_CONFIG_H__
#error "Please include sdkconfig.h first"
#endif
#include "lwip_port.h"
#include "lwip/ip4_addr.h"
#include "lwip/init.h"
#include "netif/ethernet.h"
#include "lwip/netif.h"
#include "lwip/tcpip.h"
#include "lwip/inet.h"
#include "lwip/udp.h"
#define ETH_NAME_PREFIX 'e'
#define CONFIG_DEFAULT_INIT(config,driver_config,instance_id,interface_type) \
.config.magic_code = LWIP_PORT_CONFIG_MAGIC_CODE, \
.config.driver_type = driver_config, \
.config.mac_instance = instance_id, \
.config.mii_interface = interface_type, \
.config.autonegotiation = 1, \
.config.phy_speed = LWIP_PORT_SPEED_1000M, \
.config.phy_duplex = LWIP_PORT_FULL_DUPLEX, \
.config.capability = LWIP_PORT_MODE_MULTICAST_ADDRESS_FILITER,
#define UDP_LOCAL_PORT 5001
#define UDP_REMOTE_PORT 5002
typedef struct
{
UserConfig lwip_mac_config;
u32 dhcp_en;
char* ipaddr;
char* netmask;
char* gw;
unsigned char mac_address[6];
struct netif netif;
} BoardMacConfig;
static BoardMacConfig board_mac_config[MAC_NUM] =
{
#if defined(MAC_NUM0)
{
CONFIG_DEFAULT_INIT(lwip_mac_config,MAC_NUM0_LWIP_PORT_TYPE,MAC_NUM0_CONTROLLER,MAC_NUM0_MII_INTERFACE)
.dhcp_en=0,
.ipaddr="192.168.4.10",
.gw="192.168.4.1",
.netmask="255.255.255.0",
.mac_address={0x98, 0x0e, 0x24, 0x00, 0x11, 0x0},
},
#endif
#if defined(MAC_NUM1)
{
CONFIG_DEFAULT_INIT(lwip_mac_config,MAC_NUM1_LWIP_PORT_TYPE,MAC_NUM1_CONTROLLER,MAC_NUM1_MII_INTERFACE)
.dhcp_en=0,
.ipaddr="192.168.4.11",
.gw="192.168.4.1",
.netmask="255.255.255.0",
.mac_address={0x98, 0x0e, 0x24, 0x00, 0x11, 0x1},
},
#endif
};
static void SetIP(ip_addr_t* ipaddr,ip_addr_t* gw,ip_addr_t* netmask,u32 mac_id)
{
if(inet_aton(board_mac_config[mac_id].ipaddr,ipaddr)==0)
printf("The addr of ipaddr is wrong\r\n");
if(inet_aton(board_mac_config[mac_id].gw,gw)==0)
printf("The addr of gw is wrong\r\n");
if(inet_aton(board_mac_config[mac_id].netmask,netmask)==0)
printf("The addr of netmask is wrong\r\n");
}
void UdpClient(void)
{
struct udp_pcb *client_pcb;
struct pbuf *q = NULL;
/* create a udp_pcb */
client_pcb = udp_new();
FASSERT(client_pcb != NULL)
/*bind the local port and local ip */
ip_addr_t ipaddr;
IP_ADDR4(&ipaddr, 192, 168, 4, 10);
udp_bind(client_pcb, &ipaddr, UDP_LOCAL_PORT);
IP_ADDR4(&ipaddr, 192, 168, 4, 50);
udp_connect(client_pcb, &ipaddr, UDP_REMOTE_PORT);
/*applying for memory resources*/
const char *reply = "This is a data from Udp client!\n";
q = pbuf_alloc(PBUF_TRANSPORT, strlen(reply) + 1, PBUF_RAM);
if (!q)
{
printf("Out of PBUF_RAM.\n");
return;
}
memset(q->payload, 0, q->len);
memcpy(q->payload, reply, strlen(reply));
/*sending data*/
printf("We sent a data to Udp Server.\n");
udp_send(client_pcb, q);
printf("We have been sent a data to Udp Server.\n");
/*Releasing resources*/
udp_remove(client_pcb);
pbuf_free(q);
}
int UdpClientCreate(void)
{
FError ret = FT_SUCCESS;
/* mac init */
for (int i = 0; i < MAC_NUM; i++)
{
struct netif *netif_p = NULL;
ip_addr_t ipaddr,netmask, gw;
board_mac_config[i].lwip_mac_config.name[0] = ETH_NAME_PREFIX;
itoa(board_mac_config[i].lwip_mac_config.mac_instance, &(board_mac_config[i].lwip_mac_config.name[1]), 10);
/* mac ip addr set: char* -> ip_addr_t */
SetIP(&ipaddr,&gw,&netmask,i);
/* ******************************************************************* */
netif_p= &board_mac_config[i].netif;
/* Add network interface to the netif_list, and set it as default */
if (!LwipPortAdd(netif_p, &ipaddr, &netmask, &gw, board_mac_config[i].mac_address, (UserConfig *)&board_mac_config[i]))
{
printf("Error adding N/W interface %d.\n\r",board_mac_config[i].lwip_mac_config.mac_instance);
ret = ERR_GENERAL;
goto exit;
}
printf("LwipPortAdd mac_instance %d is over.\n\r",board_mac_config[i].lwip_mac_config.mac_instance);
netif_set_default(netif_p);
if (netif_is_link_up(netif_p))
{
/* 当netif完全配置好时,必须调用该函数 */
netif_set_up(netif_p);
if (board_mac_config[i].dhcp_en == 1)
{
LwipPortDhcpSet(netif_p, TRUE);
}
}
else
{
/* 当netif链接关闭时,必须调用该函数 */
netif_set_down(netif_p);
}
}
printf("Network setup complete.\n");
UdpClient();
exit:
if (ret == FT_SUCCESS)
{
printf("%s@%d:Udp client example [success].\r\n", __func__, __LINE__);
return 0;
}
else
{
printf("%s@%d:Udp client example [failure].\r\n", __func__, __LINE__);
return 1;
}
}
void UdpClientDeinit(void)
{
for (int i = 0; i < MAC_NUM; i++)
{
struct netif *netif_p = NULL;
netif_p=&board_mac_config[i].netif;
LwipPortStop(netif_p,board_mac_config[i].dhcp_en);
}
}

56
example/network/raw_api/udp_server/README.md

@ -4,10 +4,12 @@
> `<font size="1">`介绍例程的用途,使用场景,相关基本概念,描述用户可以使用例程完成哪些工作`</font><br />`
本例程利用LWIP网络协议栈中的raw api实现了下述功能:
本例程示范了MAC控制器在lwip ipv4模式下的初始化流程,同时通过LWIP网络协议栈中的raw api,可以实现网卡作为server,利用udp与外界进行通信。
- LWIP网络协议栈初始化
### 1.1 UDP Server特性测试例程 (udp_server_example.c)
- ipv4模式下初始化开发板上所有网口以及对应网卡控制器
- 开发板上建立一个UDP服务端,监听网络中的udp数据
- 在主机端向开发板发送数据
- 开发板向发送方发送响应数据
- 网络主机在屏幕端打印收到的响应数据
@ -15,22 +17,19 @@
> `<font size="1">`描述开发平台准备,使用例程配置,构建和下载镜像的过程`</font><br />`
- 本例程在E2000上测试通过,您可以参考以下方法配置本例程所需要的硬件和软件环境
本例程需要以下硬件:
- E2000D/Q Demo板,FT2000/4开发板,D2000开发板,PhytiumPi
- 串口线和串口上位机
### 2.1 硬件配置方法
> `<font size="1">`哪些硬件平台是支持的,需要哪些外设,例程与开发板哪些IO口相关等(建议附录开发板照片,展示哪些IO口被引出)`</font><br />`
本例程支持以下硬件平台
- FT2000/4
- D2000开发板
- E2000 系列开发板
D2000开发板图片示例如下:
D2000开发板图片示例
![board](./fig/board.png)
DEMO开发板图片示例如下所示
E2000Q DEMO开发板图片示例
![demo_board](./fig/demo_board.jpg)
### 2.2 SDK配置方法
@ -41,7 +40,7 @@ DEMO开发板图片示例如下所示
- LWIP组件,依赖 USE_LWIP
- Letter Shell组件,依赖 USE_LETTER_SHELL
对应的配置项是
对应的配置项是
- CONFIG_USE_LWIP
- CONFIG_USE_LETTER_SHELL
@ -66,7 +65,7 @@ DEMO开发板图片示例如下所示
#### 2.3.1 构建过程
本文档将以E2000demo开发板为例,对于其它平台,使用对应的默认配置
本文档将以E2000d demo开发板为例,对于其它平台,使用对应的默认配置
- 在host端完成配置
- 选择目标平台
@ -115,33 +114,12 @@ bootelf -p 0x90100000
> `<font size="1">`描述输入输出情况,列出存在哪些输出,对应的输出是什么(建议附录相关现象图片)`</font><br />`
- 启动进入后,根据连接的网口,输入指令完成网口初始化
#### 2.4.1 初始化LWIP网络协议栈
- 输入以下命令,初始化LWIP网络协议栈, 依次设置网卡和dhcp使能,配置ip地址,子网掩码,网关地址,运行完成退出后LWIP协议栈会持续运行
- lwip probe 指令介绍
```
lwip probe <driver id> <device id> <interface id> <dhcp_en> <ipaddr> <gateway> <netmask>
```
- 其中driver id 为驱动类型 , 0为xmac ,1为gmac
- device id 为控制器id
- interface id ,0 为rgmii ,1 为sgmii
- dhcp en,0 表示关闭dhcp功能,1表示开启dhcp功能,网卡将根据dhcp协议获得ip地址(当协议栈支持dhcp时,该参数才具有实际作用)
- 输入以下命令,初始化LWIP网络协议栈, 依次设置网卡和dhcp使能,配置ip地址,子网掩码,网关地址,运行完成退出后LWIP协议栈会持续运行
```
$ lwip probe 0 0 1 0 192.168.4.10 192.168.4.1 255.255.255.0
```
#### 2.4.2 开启udp server
#### 2.4.1 UDP Server特性测试例程 (udp_server_example.c)
- 输入以下命令,开始udp server 测试
```
$ udpserver
udpserver
```
- 在host端向开发板发出udp 数据
@ -163,14 +141,12 @@ nc -u 192.168.4.10 5001
> `<font size="1">`主要记录使用例程中可能会遇到的问题,给出相应的解决方案`</font><br />`
- Q: 如何配置udp server的ip地址以及监听端口?
- A: 在udp_server.c中修改如下变量ipaddr以及修改宏定义UDP_ECHO_PORT即可:
- A: 在udp_server_example.c中修改如下变量ipaddr以及修改宏定义UDP_ECHO_PORT即可:
```
#define UDP_ECHO_PORT 5001
......
ip_addr_t ipaddr;
IP_ADDR4(&ipaddr, 192, 168, 4, 10);
IP_ADDR4(&ipaddr, 192, 168, 4, 10);
udp_bind(server_pcb, &ipaddr, UDP_ECHO_PORT);
```
## 4. 修改历史记录

10
example/network/raw_api/udp_server/configs/d2000_aarch32_test_udpserver.config

@ -234,7 +234,13 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# DHCP
#
# CONFIG_LWIP_DHCP_ENABLE is not set
CONFIG_LWIP_DHCP_ENABLE=y
# CONFIG_LWIP_DHCP_DOES_ARP_CHECK is not set
# CONFIG_LWIP_DHCP_GET_NTP_SRV is not set
# CONFIG_LWIP_DHCP_DISABLE_CLIENT_ID is not set
# CONFIG_LWIP_DHCP_RESTORE_LAST_IP is not set
CONFIG_LWIP_DHCP_OPTIONS_LEN=68
CONFIG_LWIP_DHCP_DISABLE_VENDOR_CLASS_ID=y
# end of DHCP
#
@ -246,7 +252,7 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# IGMP
#
CONFIG_LWIP_IGMP_EN=y
# CONFIG_LWIP_IGMP_EN is not set
# end of IGMP
#

10
example/network/raw_api/udp_server/configs/d2000_aarch64_test_udpserver.config

@ -228,7 +228,13 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# DHCP
#
# CONFIG_LWIP_DHCP_ENABLE is not set
CONFIG_LWIP_DHCP_ENABLE=y
# CONFIG_LWIP_DHCP_DOES_ARP_CHECK is not set
# CONFIG_LWIP_DHCP_GET_NTP_SRV is not set
# CONFIG_LWIP_DHCP_DISABLE_CLIENT_ID is not set
# CONFIG_LWIP_DHCP_RESTORE_LAST_IP is not set
CONFIG_LWIP_DHCP_OPTIONS_LEN=68
CONFIG_LWIP_DHCP_DISABLE_VENDOR_CLASS_ID=y
# end of DHCP
#
@ -240,7 +246,7 @@ CONFIG_LWIP_MAX_RAW_PCBS=16
#
# IGMP
#
CONFIG_LWIP_IGMP_EN=y
# CONFIG_LWIP_IGMP_EN is not set
# end of IGMP
#

Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save