diff --git a/arch/armv8/aarch32/fmmu.c b/arch/armv8/aarch32/fmmu.c index 7ef8315da..b99c95add 100644 --- a/arch/armv8/aarch32/fmmu.c +++ b/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); } diff --git a/arch/armv8/aarch32/gcc/fvectors.S b/arch/armv8/aarch32/gcc/fvectors.S index 05b8ea85b..883026c2b 100644 --- a/arch/armv8/aarch32/gcc/fvectors.S +++ b/arch/armv8/aarch32/gcc/fvectors.S @@ -28,7 +28,6 @@ .globl _boot .globl _vector_table -.weak _vector_table .globl FiqInterruptHandler .globl IrqInterruptHandler .globl SwInterruptHandler diff --git a/doc/ChangeLog.md b/doc/ChangeLog.md index e3eab9ef1..d7b84fc34 100644 --- a/doc/ChangeLog.md +++ b/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 diff --git a/example/network/lwip_startup/fig/dhcp_example_result.png b/example/network/lwip_startup/fig/dhcp_example_result.png index 773ef7d91..19fdbdf4e 100644 Binary files a/example/network/lwip_startup/fig/dhcp_example_result.png and b/example/network/lwip_startup/fig/dhcp_example_result.png differ diff --git a/example/network/lwip_startup/fig/dhcp_ping.png b/example/network/lwip_startup/fig/dhcp_ping.png index 062a6114d..4c525de17 100644 Binary files a/example/network/lwip_startup/fig/dhcp_ping.png and b/example/network/lwip_startup/fig/dhcp_ping.png differ diff --git a/example/network/lwip_startup/fig/ipv4_example_result.png b/example/network/lwip_startup/fig/ipv4_example_result.png index aaef95678..fe4813e0b 100644 Binary files a/example/network/lwip_startup/fig/ipv4_example_result.png and b/example/network/lwip_startup/fig/ipv4_example_result.png differ diff --git a/example/network/lwip_startup/fig/ipv6_example_result.png b/example/network/lwip_startup/fig/ipv6_example_result.png index 58430df17..3b482aeb5 100644 Binary files a/example/network/lwip_startup/fig/ipv6_example_result.png and b/example/network/lwip_startup/fig/ipv6_example_result.png differ diff --git a/example/network/lwip_startup/inc/lwip_dhcp_example.h b/example/network/lwip_startup/inc/lwip_dhcp_example.h index 7dc1b3268..c59252715 100644 --- a/example/network/lwip_startup/inc/lwip_dhcp_example.h +++ b/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 } diff --git a/example/network/lwip_startup/main.c b/example/network/lwip_startup/main.c index beb795010..b2f40f951 100644 --- a/example/network/lwip_startup/main.c +++ b/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 diff --git a/example/network/lwip_startup/src/lwip_dhcp_example.c b/example/network/lwip_startup/src/lwip_dhcp_example.c index d33c4ef0e..039037ce5 100644 --- a/example/network/lwip_startup/src/lwip_dhcp_example.c +++ b/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) { diff --git a/example/network/raw_api/common/lwip_start.c b/example/network/raw_api/common/lwip_start.c deleted file mode 100644 index 4c7f7199e..000000000 --- a/example/network/raw_api/common/lwip_start.c +++ /dev/null @@ -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 -#include -#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 \r\n") ; - printf(" -- use name to deinit neitf object\r\n"); - printf(" -- 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 \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(" -- Ip address of netif \r\n"); - printf(" -- Gateway of netif \r\n"); - printf(" -- Netmask of netif \r\n"); - printf("Please enter lwip deinit \r\n") ; - printf(" -- use name to deinit neitf object \r\n"); - printf(" -- is netif name \r\n"); - } - return 0; -} - -SHELL_EXPORT_CMD(SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN), lwip, LwipDeviceSet, Setup LWIP device test); - diff --git a/example/network/raw_api/common/raw_api_timer.c b/example/network/raw_api/common/raw_api_timer.c deleted file mode 100644 index 9d9cdb4a1..000000000 --- a/example/network/raw_api/common/raw_api_timer.c +++ /dev/null @@ -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; -} \ No newline at end of file diff --git a/example/network/raw_api/tcp_client/README.md b/example/network/raw_api/tcp_client/README.md index 4fc4286f5..dd713483b 100644 --- a/example/network/raw_api/tcp_client/README.md +++ b/example/network/raw_api/tcp_client/README.md @@ -4,46 +4,43 @@ > ``介绍例程的用途,使用场景,相关基本概念,描述用户可以使用例程完成哪些工作`
` -本例程利用LWIP网络协议栈中的raw api实现了下述功能: +本例程示范了MAC控制器在lwip ipv4模式下的初始化流程,同时通过LWIP网络协议栈中的raw api,可以实现网卡作为client,利用tcp与外界进行通信。 -- LWIP网络协议栈初始化 +### 1.1 TCP Client特性测试例程 (tcp_client_example.c) +- ipv4模式下初始化开发板上所有网口以及对应网卡控制器 - 建立开发板到主机的tcp连接 -- 开发板周期性向网络主机发送数据包 +- 开发板向网络主机发送数据包 - 网络主机在屏幕端打印收到的数据 +- 开发板发送一次数据后,主动断开与主机的tcp连接 ## 2. 如何使用例程 > ``描述开发平台准备,使用例程配置,构建和下载镜像的过程`
` -- 本例程在E2000上测试通过,您可以参考以下方法配置本例程所需要的硬件和软件环境 +本例程需要以下硬件: + +- E2000D/Q Demo板,FT2000/4开发板,D2000开发板,PhytiumPi +- 串口线和串口上位机 ### 2.1 硬件配置方法 > ``哪些硬件平台是支持的,需要哪些外设,例程与开发板哪些IO口相关等(建议附录开发板照片,展示哪些IO口被引出)`
` -本例程支持以下硬件平台 - -- FT2000/4 -- D2000开发板 -- E2000 系列开发板 - -D2000开发板图片示例如下: +D2000开发板图片示例 ![board](./fig/board.png) -DEMO开发板图片示例如下所示 +E2000Q DEMO开发板图片示例 ![demo_board](./fig/demo_board.jpg) ### 2.2 SDK配置方法 > ``依赖哪些驱动、库和第三方组件,如何完成配置(列出需要使能的关键配置项)`
` -本例程需要, - +本例程需要: - 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 > ``描述输入输出情况,列出存在哪些输出,对应的输出是什么(建议附录相关现象图片)`
` -- 启动进入后,根据连接的网口,输入指令完成网口初始化 - -#### 2.4.1 初始化LWIP网络协议栈 - -- 输入以下命令,初始化LWIP网络协议栈, 依次设置网卡和dhcp使能,配置ip地址,子网掩码,网关地址,运行完成退出后LWIP协议栈会持续运行 -- lwip probe 指令介绍 - -``` -lwip probe -``` - -- 其中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. 如何解决问题 > ``主要记录使用例程中可能会遇到的问题,给出相应的解决方案`
` @@ -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. 修改历史记录 diff --git a/example/network/raw_api/tcp_client/configs/d2000_aarch32_test_tcpclient.config b/example/network/raw_api/tcp_client/configs/d2000_aarch32_test_tcpclient.config index f6ec17aa2..6b74dbda4 100644 --- a/example/network/raw_api/tcp_client/configs/d2000_aarch32_test_tcpclient.config +++ b/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 # diff --git a/example/network/raw_api/tcp_client/configs/d2000_aarch64_test_tcpclient.config b/example/network/raw_api/tcp_client/configs/d2000_aarch64_test_tcpclient.config index fece98653..eac8f4919 100644 --- a/example/network/raw_api/tcp_client/configs/d2000_aarch64_test_tcpclient.config +++ b/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 # diff --git a/example/network/raw_api/tcp_client/configs/e2000d_aarch32_demo_tcpclient.config b/example/network/raw_api/tcp_client/configs/e2000d_aarch32_demo_tcpclient.config index f334063b4..fdd6fb4a6 100644 --- a/example/network/raw_api/tcp_client/configs/e2000d_aarch32_demo_tcpclient.config +++ b/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 # diff --git a/example/network/raw_api/tcp_client/configs/e2000d_aarch64_demo_tcpclient.config b/example/network/raw_api/tcp_client/configs/e2000d_aarch64_demo_tcpclient.config index b9eacc581..267390dc0 100644 --- a/example/network/raw_api/tcp_client/configs/e2000d_aarch64_demo_tcpclient.config +++ b/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 # diff --git a/example/network/raw_api/tcp_client/configs/e2000q_aarch32_demo_tcpclient.config b/example/network/raw_api/tcp_client/configs/e2000q_aarch32_demo_tcpclient.config index 5b2f6d4c2..9e128995b 100644 --- a/example/network/raw_api/tcp_client/configs/e2000q_aarch32_demo_tcpclient.config +++ b/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 # diff --git a/example/network/raw_api/tcp_client/configs/e2000q_aarch64_demo_tcpclient.config b/example/network/raw_api/tcp_client/configs/e2000q_aarch64_demo_tcpclient.config index 6c01e9745..51b39761d 100644 --- a/example/network/raw_api/tcp_client/configs/e2000q_aarch64_demo_tcpclient.config +++ b/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 # diff --git a/example/network/raw_api/tcp_client/configs/ft2004_aarch32_dsk_tcpclient.config b/example/network/raw_api/tcp_client/configs/ft2004_aarch32_dsk_tcpclient.config index a0bf361b3..a893add39 100644 --- a/example/network/raw_api/tcp_client/configs/ft2004_aarch32_dsk_tcpclient.config +++ b/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 # diff --git a/example/network/raw_api/tcp_client/configs/ft2004_aarch64_dsk_tcpclient.config b/example/network/raw_api/tcp_client/configs/ft2004_aarch64_dsk_tcpclient.config index 53c77623e..05750a2fb 100644 --- a/example/network/raw_api/tcp_client/configs/ft2004_aarch64_dsk_tcpclient.config +++ b/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 # diff --git a/example/network/raw_api/tcp_client/configs/pd2308_aarch64_demo_tcpclient.config b/example/network/raw_api/tcp_client/configs/pd2308_aarch64_demo_tcpclient.config index 411475a5b..e00001e60 100644 --- a/example/network/raw_api/tcp_client/configs/pd2308_aarch64_demo_tcpclient.config +++ b/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 # diff --git a/example/network/raw_api/tcp_client/configs/phytiumpi_aarch32_firefly_tcpclient.config b/example/network/raw_api/tcp_client/configs/phytiumpi_aarch32_firefly_tcpclient.config index bd6f3276d..f3a1ed389 100644 --- a/example/network/raw_api/tcp_client/configs/phytiumpi_aarch32_firefly_tcpclient.config +++ b/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 # diff --git a/example/network/raw_api/tcp_client/configs/phytiumpi_aarch64_firefly_tcpclient.config b/example/network/raw_api/tcp_client/configs/phytiumpi_aarch64_firefly_tcpclient.config index 49938cfa3..03e2e4188 100644 --- a/example/network/raw_api/tcp_client/configs/phytiumpi_aarch64_firefly_tcpclient.config +++ b/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 # diff --git a/example/network/raw_api/tcp_client/fig/host_tcp.png b/example/network/raw_api/tcp_client/fig/host_tcp.png index 555943335..034977ef9 100644 Binary files a/example/network/raw_api/tcp_client/fig/host_tcp.png and b/example/network/raw_api/tcp_client/fig/host_tcp.png differ diff --git a/example/network/raw_api/tcp_client/fig/menuconfig_select_demo.png b/example/network/raw_api/tcp_client/fig/menuconfig_select_demo.png deleted file mode 100644 index 24bbe1905..000000000 Binary files a/example/network/raw_api/tcp_client/fig/menuconfig_select_demo.png and /dev/null differ diff --git a/example/network/raw_api/tcp_client/fig/tcp_client.png b/example/network/raw_api/tcp_client/fig/tcp_client.png index 84a4a53e8..0a00b2934 100644 Binary files a/example/network/raw_api/tcp_client/fig/tcp_client.png and b/example/network/raw_api/tcp_client/fig/tcp_client.png differ diff --git a/example/network/raw_api/tcp_client/fig/tcp_client_close.png b/example/network/raw_api/tcp_client/fig/tcp_client_close.png deleted file mode 100644 index 3775085bb..000000000 Binary files a/example/network/raw_api/tcp_client/fig/tcp_client_close.png and /dev/null differ diff --git a/example/network/raw_api/tcp_client/inc/lwip_timer.h b/example/network/raw_api/tcp_client/inc/lwip_timer.h new file mode 100644 index 000000000..c355cb40e --- /dev/null +++ b/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 \ No newline at end of file diff --git a/example/network/raw_api/tcp_client/inc/tcp_client_example.h b/example/network/raw_api/tcp_client/inc/tcp_client_example.h new file mode 100644 index 000000000..ce9755332 --- /dev/null +++ b/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 \ No newline at end of file diff --git a/example/network/raw_api/tcp_client/main.c b/example/network/raw_api/tcp_client/main.c index e39e9055f..ca85a22b4 100644 --- a/example/network/raw_api/tcp_client/main.c +++ b/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 -#include + #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; } \ No newline at end of file diff --git a/example/network/raw_api/tcp_client/makefile b/example/network/raw_api/tcp_client/makefile index 33ee8bc45..fcbb3f459 100644 --- a/example/network/raw_api/tcp_client/makefile +++ b/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 \ diff --git a/example/network/raw_api/tcp_client/sdkconfig b/example/network/raw_api/tcp_client/sdkconfig index 49938cfa3..03e2e4188 100644 --- a/example/network/raw_api/tcp_client/sdkconfig +++ b/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 # diff --git a/example/network/raw_api/tcp_client/sdkconfig.h b/example/network/raw_api/tcp_client/sdkconfig.h index fdcc5fc7c..e678f463c 100644 --- a/example/network/raw_api/tcp_client/sdkconfig.h +++ b/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 */ diff --git a/example/network/raw_api/tcp_client/src/cmd_tcp_client.c b/example/network/raw_api/tcp_client/src/cmd_tcp_client.c new file mode 100644 index 000000000..c1c339fe7 --- /dev/null +++ b/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 +#include + +#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 \ No newline at end of file diff --git a/example/network/raw_api/tcp_client/src/lwip_timer.c b/example/network/raw_api/tcp_client/src/lwip_timer.c new file mode 100644 index 000000000..fb9d02845 --- /dev/null +++ b/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 +#include +#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_cnttimer_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; +} \ No newline at end of file diff --git a/example/network/raw_api/tcp_client/src/tcp_client.c b/example/network/raw_api/tcp_client/src/tcp_client.c deleted file mode 100644 index 0fb1d04c5..000000000 --- a/example/network/raw_api/tcp_client/src/tcp_client.c +++ /dev/null @@ -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 -#include -#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); \ No newline at end of file diff --git a/example/network/raw_api/tcp_client/src/tcp_client_example.c b/example/network/raw_api/tcp_client/src/tcp_client_example.c new file mode 100644 index 000000000..c62d445c6 --- /dev/null +++ b/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 +#include +#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); + } +} \ No newline at end of file diff --git a/example/network/raw_api/tcp_server/README.md b/example/network/raw_api/tcp_server/README.md index 7130a165d..abbc17b2c 100644 --- a/example/network/raw_api/tcp_server/README.md +++ b/example/network/raw_api/tcp_server/README.md @@ -4,10 +4,12 @@ > ``介绍例程的用途,使用场景,相关基本概念,描述用户可以使用例程完成哪些工作`
` -本例程利用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 @@ > ``描述开发平台准备,使用例程配置,构建和下载镜像的过程`
` -- 本例程在E2000上测试通过,您可以参考以下方法配置本例程所需要的硬件和软件环境 +本例程需要以下硬件: + +- E2000D/Q Demo板,FT2000/4开发板,D2000开发板,PhytiumPi +- 串口线和串口上位机 ### 2.1 硬件配置方法 > ``哪些硬件平台是支持的,需要哪些外设,例程与开发板哪些IO口相关等(建议附录开发板照片,展示哪些IO口被引出)`
` -本例程支持以下硬件平台 - -- FT2000/4 -- D2000开发板 -- E2000 系列开发板 - -D2000开发板图片示例如下: +D2000开发板图片示例 ![board](./fig/board.png) -DEMO开发板图片示例如下所示 +E2000Q DEMO开发板图片示例 ![demo_board](./fig/demo_board.jpg) ### 2.2 SDK配置方法 > ``依赖哪些驱动、库和第三方组件,如何完成配置(列出需要使能的关键配置项)`
` -本例程需要, - +本例程需要: - 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 > ``描述输入输出情况,列出存在哪些输出,对应的输出是什么(建议附录相关现象图片)`
` -- 启动进入后,根据连接的网口,输入指令完成网口初始化 - -#### 2.4.1 初始化LWIP网络协议栈 - -- 输入以下命令,初始化LWIP网络协议栈, 依次设置网卡和dhcp使能,配置ip地址,子网掩码,网关地址,运行完成退出后LWIP协议栈会持续运行 -- lwip probe 指令介绍 - -``` -lwip probe -``` - -- 其中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. 修改历史记录 diff --git a/example/network/raw_api/tcp_server/configs/d2000_aarch32_test_tcpserver.config b/example/network/raw_api/tcp_server/configs/d2000_aarch32_test_tcpserver.config index ccdb792de..68a233096 100644 --- a/example/network/raw_api/tcp_server/configs/d2000_aarch32_test_tcpserver.config +++ b/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 # diff --git a/example/network/raw_api/tcp_server/configs/d2000_aarch64_test_tcpserver.config b/example/network/raw_api/tcp_server/configs/d2000_aarch64_test_tcpserver.config index fda451b4f..a72818fc3 100644 --- a/example/network/raw_api/tcp_server/configs/d2000_aarch64_test_tcpserver.config +++ b/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 # diff --git a/example/network/raw_api/tcp_server/configs/e2000d_aarch32_demo_tcpserver.config b/example/network/raw_api/tcp_server/configs/e2000d_aarch32_demo_tcpserver.config index cb07c044e..bc22adbf3 100644 --- a/example/network/raw_api/tcp_server/configs/e2000d_aarch32_demo_tcpserver.config +++ b/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 # diff --git a/example/network/raw_api/tcp_server/configs/e2000d_aarch64_demo_tcpserver.config b/example/network/raw_api/tcp_server/configs/e2000d_aarch64_demo_tcpserver.config index beb44d959..9a9bdbcf7 100644 --- a/example/network/raw_api/tcp_server/configs/e2000d_aarch64_demo_tcpserver.config +++ b/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 # diff --git a/example/network/raw_api/tcp_server/configs/e2000q_aarch32_demo_tcpserver.config b/example/network/raw_api/tcp_server/configs/e2000q_aarch32_demo_tcpserver.config index e27588564..09c3350ef 100644 --- a/example/network/raw_api/tcp_server/configs/e2000q_aarch32_demo_tcpserver.config +++ b/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 # diff --git a/example/network/raw_api/tcp_server/configs/e2000q_aarch64_demo_tcpserver.config b/example/network/raw_api/tcp_server/configs/e2000q_aarch64_demo_tcpserver.config index 96cf9314d..2b563c2b0 100644 --- a/example/network/raw_api/tcp_server/configs/e2000q_aarch64_demo_tcpserver.config +++ b/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 # diff --git a/example/network/raw_api/tcp_server/configs/ft2004_aarch32_dsk_tcpserver.config b/example/network/raw_api/tcp_server/configs/ft2004_aarch32_dsk_tcpserver.config index 8f1614af6..b6f91fa6a 100644 --- a/example/network/raw_api/tcp_server/configs/ft2004_aarch32_dsk_tcpserver.config +++ b/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 # diff --git a/example/network/raw_api/tcp_server/configs/ft2004_aarch64_dsk_tcpserver.config b/example/network/raw_api/tcp_server/configs/ft2004_aarch64_dsk_tcpserver.config index a052d6879..041bae61b 100644 --- a/example/network/raw_api/tcp_server/configs/ft2004_aarch64_dsk_tcpserver.config +++ b/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 # diff --git a/example/network/raw_api/tcp_server/configs/pd2308_aarch64_demo_tcpserver.config b/example/network/raw_api/tcp_server/configs/pd2308_aarch64_demo_tcpserver.config index 7f678d47f..9e087df17 100644 --- a/example/network/raw_api/tcp_server/configs/pd2308_aarch64_demo_tcpserver.config +++ b/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 # diff --git a/example/network/raw_api/tcp_server/configs/phytiumpi_aarch32_firefly_tcpserver.config b/example/network/raw_api/tcp_server/configs/phytiumpi_aarch32_firefly_tcpserver.config index 266044052..bb6342a5a 100644 --- a/example/network/raw_api/tcp_server/configs/phytiumpi_aarch32_firefly_tcpserver.config +++ b/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 # diff --git a/example/network/raw_api/tcp_server/configs/phytiumpi_aarch64_firefly_tcpserver.config b/example/network/raw_api/tcp_server/configs/phytiumpi_aarch64_firefly_tcpserver.config index 4382a955a..58b38b4a9 100644 --- a/example/network/raw_api/tcp_server/configs/phytiumpi_aarch64_firefly_tcpserver.config +++ b/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 # diff --git a/example/network/raw_api/tcp_server/fig/ping_ipv4.png b/example/network/raw_api/tcp_server/fig/ping_ipv4.png deleted file mode 100644 index 2b6806a7d..000000000 Binary files a/example/network/raw_api/tcp_server/fig/ping_ipv4.png and /dev/null differ diff --git a/example/network/raw_api/tcp_server/fig/ping_ipv4_dhcp.png b/example/network/raw_api/tcp_server/fig/ping_ipv4_dhcp.png deleted file mode 100644 index 9c27cb122..000000000 Binary files a/example/network/raw_api/tcp_server/fig/ping_ipv4_dhcp.png and /dev/null differ diff --git a/example/network/raw_api/tcp_server/fig/ping_ipv6.png b/example/network/raw_api/tcp_server/fig/ping_ipv6.png deleted file mode 100644 index e106868c3..000000000 Binary files a/example/network/raw_api/tcp_server/fig/ping_ipv6.png and /dev/null differ diff --git a/example/network/raw_api/tcp_server/fig/probe_ipv4.png b/example/network/raw_api/tcp_server/fig/probe_ipv4.png deleted file mode 100644 index 63820681d..000000000 Binary files a/example/network/raw_api/tcp_server/fig/probe_ipv4.png and /dev/null differ diff --git a/example/network/raw_api/tcp_server/fig/probe_ipv4_dhcp.png b/example/network/raw_api/tcp_server/fig/probe_ipv4_dhcp.png deleted file mode 100644 index 45278de44..000000000 Binary files a/example/network/raw_api/tcp_server/fig/probe_ipv4_dhcp.png and /dev/null differ diff --git a/example/network/raw_api/tcp_server/fig/probe_ipv6.png b/example/network/raw_api/tcp_server/fig/probe_ipv6.png deleted file mode 100644 index 82605b056..000000000 Binary files a/example/network/raw_api/tcp_server/fig/probe_ipv6.png and /dev/null differ diff --git a/example/network/raw_api/tcp_server/fig/tcp_server.png b/example/network/raw_api/tcp_server/fig/tcp_server.png index 90ae3fc7f..fc78eb31f 100644 Binary files a/example/network/raw_api/tcp_server/fig/tcp_server.png and b/example/network/raw_api/tcp_server/fig/tcp_server.png differ diff --git a/example/network/raw_api/tcp_server/fig/tcpserver_host.png b/example/network/raw_api/tcp_server/fig/tcpserver_host.png index 224178f54..4d9bb5888 100644 Binary files a/example/network/raw_api/tcp_server/fig/tcpserver_host.png and b/example/network/raw_api/tcp_server/fig/tcpserver_host.png differ diff --git a/example/network/raw_api/tcp_server/inc/lwip_timer.h b/example/network/raw_api/tcp_server/inc/lwip_timer.h new file mode 100644 index 000000000..5f24739f1 --- /dev/null +++ b/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 \ No newline at end of file diff --git a/example/network/raw_api/tcp_server/inc/tcp_server_example.h b/example/network/raw_api/tcp_server/inc/tcp_server_example.h new file mode 100644 index 000000000..91e7f3d28 --- /dev/null +++ b/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 \ No newline at end of file diff --git a/example/network/raw_api/tcp_server/main.c b/example/network/raw_api/tcp_server/main.c index c3180fe41..24e5affbd 100644 --- a/example/network/raw_api/tcp_server/main.c +++ b/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 -#include + +/***************************** 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; } \ No newline at end of file diff --git a/example/network/raw_api/tcp_server/makefile b/example/network/raw_api/tcp_server/makefile index 33ee8bc45..fcbb3f459 100644 --- a/example/network/raw_api/tcp_server/makefile +++ b/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 \ diff --git a/example/network/raw_api/tcp_server/sdkconfig b/example/network/raw_api/tcp_server/sdkconfig index 4382a955a..58b38b4a9 100644 --- a/example/network/raw_api/tcp_server/sdkconfig +++ b/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 # diff --git a/example/network/raw_api/tcp_server/sdkconfig.h b/example/network/raw_api/tcp_server/sdkconfig.h index 6c101913b..75d3d14e5 100644 --- a/example/network/raw_api/tcp_server/sdkconfig.h +++ b/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 */ diff --git a/example/network/raw_api/tcp_server/src/cmd_tcp_server.c b/example/network/raw_api/tcp_server/src/cmd_tcp_server.c new file mode 100644 index 000000000..44266023e --- /dev/null +++ b/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 +#include + +#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 \ No newline at end of file diff --git a/example/network/raw_api/tcp_server/src/lwip_timer.c b/example/network/raw_api/tcp_server/src/lwip_timer.c new file mode 100644 index 000000000..1051d770c --- /dev/null +++ b/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 +#include +#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_cnttimer_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; +} \ No newline at end of file diff --git a/example/network/raw_api/tcp_server/src/tcp_server.c b/example/network/raw_api/tcp_server/src/tcp_server.c deleted file mode 100644 index ff8841715..000000000 --- a/example/network/raw_api/tcp_server/src/tcp_server.c +++ /dev/null @@ -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 -#include -#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); \ No newline at end of file diff --git a/example/network/raw_api/tcp_server/src/tcp_server_example.c b/example/network/raw_api/tcp_server/src/tcp_server_example.c new file mode 100644 index 000000000..8e4cacf73 --- /dev/null +++ b/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 +#include +#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); + } +} \ No newline at end of file diff --git a/example/network/raw_api/udp_client/README.md b/example/network/raw_api/udp_client/README.md index d8ca3e590..1cfb611bc 100644 --- a/example/network/raw_api/udp_client/README.md +++ b/example/network/raw_api/udp_client/README.md @@ -4,9 +4,10 @@ > ``介绍例程的用途,使用场景,相关基本概念,描述用户可以使用例程完成哪些工作`
` -本例程利用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 @@ > ``描述开发平台准备,使用例程配置,构建和下载镜像的过程`
` -- 本例程在E2000上测试通过,您可以参考以下方法配置本例程所需要的硬件和软件环境 +本例程需要以下硬件: + +- E2000D/Q Demo板,FT2000/4开发板,D2000开发板,PhytiumPi +- 串口线和串口上位机 ### 2.1 硬件配置方法 > ``哪些硬件平台是支持的,需要哪些外设,例程与开发板哪些IO口相关等(建议附录开发板照片,展示哪些IO口被引出)`
` -本例程支持以下硬件平台 - -- FT2000/4 -- D2000开发板 -- E2000 系列开发板 - -D2000开发板图片示例如下: +D2000开发板图片示例 ![board](./fig/board.png) -DEMO开发板图片示例如下所示 +E2000Q DEMO开发板图片示例 ![demo_board](./fig/demo_board.jpg) ### 2.2 SDK配置方法 > ``依赖哪些驱动、库和第三方组件,如何完成配置(列出需要使能的关键配置项)`
` -本例程需要, - +本例程需要: - 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 > ``描述输入输出情况,列出存在哪些输出,对应的输出是什么(建议附录相关现象图片)`
` -- 启动进入后,根据连接的网口,输入指令完成网口初始化 - -#### 2.4.1 初始化LWIP网络协议栈 - -- 输入以下命令,初始化LWIP网络协议栈, 依次设置网卡和dhcp使能,配置ip地址,子网掩码,网关地址,运行完成退出后LWIP协议栈会持续运行 -- lwip probe 指令介绍 - -``` -lwip probe -``` - -- 其中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. 修改历史记录 diff --git a/example/network/raw_api/udp_client/configs/d2000_aarch32_test_udpclient.config b/example/network/raw_api/udp_client/configs/d2000_aarch32_test_udpclient.config index 013b80efa..53cc3c9d8 100644 --- a/example/network/raw_api/udp_client/configs/d2000_aarch32_test_udpclient.config +++ b/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 # diff --git a/example/network/raw_api/udp_client/configs/d2000_aarch64_test_udpclient.config b/example/network/raw_api/udp_client/configs/d2000_aarch64_test_udpclient.config index 1f4c391bb..d672333f0 100644 --- a/example/network/raw_api/udp_client/configs/d2000_aarch64_test_udpclient.config +++ b/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 # diff --git a/example/network/raw_api/udp_client/configs/e2000d_aarch32_demo_udpclient.config b/example/network/raw_api/udp_client/configs/e2000d_aarch32_demo_udpclient.config index db0541c67..efc67966e 100644 --- a/example/network/raw_api/udp_client/configs/e2000d_aarch32_demo_udpclient.config +++ b/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 # diff --git a/example/network/raw_api/udp_client/configs/e2000d_aarch64_demo_udpclient.config b/example/network/raw_api/udp_client/configs/e2000d_aarch64_demo_udpclient.config index 32b8459c2..5497915e3 100644 --- a/example/network/raw_api/udp_client/configs/e2000d_aarch64_demo_udpclient.config +++ b/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 # diff --git a/example/network/raw_api/udp_client/configs/e2000q_aarch32_demo_udpclient.config b/example/network/raw_api/udp_client/configs/e2000q_aarch32_demo_udpclient.config index 14f8836c0..487f61f55 100644 --- a/example/network/raw_api/udp_client/configs/e2000q_aarch32_demo_udpclient.config +++ b/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 # diff --git a/example/network/raw_api/udp_client/configs/e2000q_aarch64_demo_udpclient.config b/example/network/raw_api/udp_client/configs/e2000q_aarch64_demo_udpclient.config index 24f6c0952..7c3fa4e23 100644 --- a/example/network/raw_api/udp_client/configs/e2000q_aarch64_demo_udpclient.config +++ b/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 # diff --git a/example/network/raw_api/udp_client/configs/ft2004_aarch32_dsk_udpclient.config b/example/network/raw_api/udp_client/configs/ft2004_aarch32_dsk_udpclient.config index 880a74ab0..5b1531e2d 100644 --- a/example/network/raw_api/udp_client/configs/ft2004_aarch32_dsk_udpclient.config +++ b/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 # diff --git a/example/network/raw_api/udp_client/configs/ft2004_aarch64_dsk_udpclient.config b/example/network/raw_api/udp_client/configs/ft2004_aarch64_dsk_udpclient.config index 98697ede1..8e792dfad 100644 --- a/example/network/raw_api/udp_client/configs/ft2004_aarch64_dsk_udpclient.config +++ b/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 # diff --git a/example/network/raw_api/udp_client/configs/pd2308_aarch64_demo_udpclient.config b/example/network/raw_api/udp_client/configs/pd2308_aarch64_demo_udpclient.config index ff590a73e..0258b84c2 100644 --- a/example/network/raw_api/udp_client/configs/pd2308_aarch64_demo_udpclient.config +++ b/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 # diff --git a/example/network/raw_api/udp_client/configs/phytiumpi_aarch32_firefly_udpclient.config b/example/network/raw_api/udp_client/configs/phytiumpi_aarch32_firefly_udpclient.config index 283ac0a75..5f0482b05 100644 --- a/example/network/raw_api/udp_client/configs/phytiumpi_aarch32_firefly_udpclient.config +++ b/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 # diff --git a/example/network/raw_api/udp_client/configs/phytiumpi_aarch64_firefly_udpclient.config b/example/network/raw_api/udp_client/configs/phytiumpi_aarch64_firefly_udpclient.config index 4df56a6ae..ce7d569f6 100644 --- a/example/network/raw_api/udp_client/configs/phytiumpi_aarch64_firefly_udpclient.config +++ b/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 # diff --git a/example/network/raw_api/udp_client/fig/ping_ipv4.png b/example/network/raw_api/udp_client/fig/ping_ipv4.png deleted file mode 100644 index 2b6806a7d..000000000 Binary files a/example/network/raw_api/udp_client/fig/ping_ipv4.png and /dev/null differ diff --git a/example/network/raw_api/udp_client/fig/ping_ipv4_dhcp.png b/example/network/raw_api/udp_client/fig/ping_ipv4_dhcp.png deleted file mode 100644 index 9c27cb122..000000000 Binary files a/example/network/raw_api/udp_client/fig/ping_ipv4_dhcp.png and /dev/null differ diff --git a/example/network/raw_api/udp_client/fig/ping_ipv6.png b/example/network/raw_api/udp_client/fig/ping_ipv6.png deleted file mode 100644 index e106868c3..000000000 Binary files a/example/network/raw_api/udp_client/fig/ping_ipv6.png and /dev/null differ diff --git a/example/network/raw_api/udp_client/fig/probe_ipv4.png b/example/network/raw_api/udp_client/fig/probe_ipv4.png deleted file mode 100644 index 63820681d..000000000 Binary files a/example/network/raw_api/udp_client/fig/probe_ipv4.png and /dev/null differ diff --git a/example/network/raw_api/udp_client/fig/probe_ipv4_dhcp.png b/example/network/raw_api/udp_client/fig/probe_ipv4_dhcp.png deleted file mode 100644 index 45278de44..000000000 Binary files a/example/network/raw_api/udp_client/fig/probe_ipv4_dhcp.png and /dev/null differ diff --git a/example/network/raw_api/udp_client/fig/probe_ipv6.png b/example/network/raw_api/udp_client/fig/probe_ipv6.png deleted file mode 100644 index 82605b056..000000000 Binary files a/example/network/raw_api/udp_client/fig/probe_ipv6.png and /dev/null differ diff --git a/example/network/raw_api/udp_client/fig/udp_client.png b/example/network/raw_api/udp_client/fig/udp_client.png index d43ed7a93..743deab5f 100644 Binary files a/example/network/raw_api/udp_client/fig/udp_client.png and b/example/network/raw_api/udp_client/fig/udp_client.png differ diff --git a/example/network/raw_api/udp_client/inc/lwip_timer.h b/example/network/raw_api/udp_client/inc/lwip_timer.h new file mode 100644 index 000000000..31516ccc4 --- /dev/null +++ b/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 \ No newline at end of file diff --git a/example/network/raw_api/udp_client/inc/udp_client_example.h b/example/network/raw_api/udp_client/inc/udp_client_example.h new file mode 100644 index 000000000..b5cd7724d --- /dev/null +++ b/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 \ No newline at end of file diff --git a/example/network/raw_api/udp_client/main.c b/example/network/raw_api/udp_client/main.c index 7b2e6e872..5459c46d4 100644 --- a/example/network/raw_api/udp_client/main.c +++ b/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 -#include -#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; } \ No newline at end of file diff --git a/example/network/raw_api/udp_client/makefile b/example/network/raw_api/udp_client/makefile index 33ee8bc45..fcbb3f459 100644 --- a/example/network/raw_api/udp_client/makefile +++ b/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 \ diff --git a/example/network/raw_api/udp_client/sdkconfig b/example/network/raw_api/udp_client/sdkconfig index 4df56a6ae..ce7d569f6 100644 --- a/example/network/raw_api/udp_client/sdkconfig +++ b/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 # diff --git a/example/network/raw_api/udp_client/sdkconfig.h b/example/network/raw_api/udp_client/sdkconfig.h index d266ab444..f9bed29dd 100644 --- a/example/network/raw_api/udp_client/sdkconfig.h +++ b/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 */ diff --git a/example/network/raw_api/udp_client/src/cmd_udp_client.c b/example/network/raw_api/udp_client/src/cmd_udp_client.c new file mode 100644 index 000000000..7fe926f1d --- /dev/null +++ b/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 +#include + +#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 \ No newline at end of file diff --git a/example/network/raw_api/udp_client/src/lwip_timer.c b/example/network/raw_api/udp_client/src/lwip_timer.c new file mode 100644 index 000000000..5688920d1 --- /dev/null +++ b/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 +#include +#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_cnttimer_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; +} \ No newline at end of file diff --git a/example/network/raw_api/udp_client/src/udp_client.c b/example/network/raw_api/udp_client/src/udp_client.c deleted file mode 100644 index da464534a..000000000 --- a/example/network/raw_api/udp_client/src/udp_client.c +++ /dev/null @@ -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 -#include -#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); diff --git a/example/network/raw_api/udp_client/src/udp_client_example.c b/example/network/raw_api/udp_client/src/udp_client_example.c new file mode 100644 index 000000000..c09b8c78b --- /dev/null +++ b/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 +#include +#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); + } +} \ No newline at end of file diff --git a/example/network/raw_api/udp_server/README.md b/example/network/raw_api/udp_server/README.md index 159424cbd..26b08bce3 100644 --- a/example/network/raw_api/udp_server/README.md +++ b/example/network/raw_api/udp_server/README.md @@ -4,10 +4,12 @@ > ``介绍例程的用途,使用场景,相关基本概念,描述用户可以使用例程完成哪些工作`
` -本例程利用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 @@ > ``描述开发平台准备,使用例程配置,构建和下载镜像的过程`
` -- 本例程在E2000上测试通过,您可以参考以下方法配置本例程所需要的硬件和软件环境 +本例程需要以下硬件: + +- E2000D/Q Demo板,FT2000/4开发板,D2000开发板,PhytiumPi +- 串口线和串口上位机 ### 2.1 硬件配置方法 > ``哪些硬件平台是支持的,需要哪些外设,例程与开发板哪些IO口相关等(建议附录开发板照片,展示哪些IO口被引出)`
` -本例程支持以下硬件平台 - -- 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 > ``描述输入输出情况,列出存在哪些输出,对应的输出是什么(建议附录相关现象图片)`
` -- 启动进入后,根据连接的网口,输入指令完成网口初始化 - -#### 2.4.1 初始化LWIP网络协议栈 - -- 输入以下命令,初始化LWIP网络协议栈, 依次设置网卡和dhcp使能,配置ip地址,子网掩码,网关地址,运行完成退出后LWIP协议栈会持续运行 -- lwip probe 指令介绍 - -``` -lwip probe -``` - -- 其中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 > ``主要记录使用例程中可能会遇到的问题,给出相应的解决方案`
` - 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. 修改历史记录 diff --git a/example/network/raw_api/udp_server/configs/d2000_aarch32_test_udpserver.config b/example/network/raw_api/udp_server/configs/d2000_aarch32_test_udpserver.config index 5e5a66733..12b0832da 100644 --- a/example/network/raw_api/udp_server/configs/d2000_aarch32_test_udpserver.config +++ b/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 # diff --git a/example/network/raw_api/udp_server/configs/d2000_aarch64_test_udpserver.config b/example/network/raw_api/udp_server/configs/d2000_aarch64_test_udpserver.config index 5e8157a01..c2b3a39d8 100644 --- a/example/network/raw_api/udp_server/configs/d2000_aarch64_test_udpserver.config +++ b/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 # diff --git a/example/network/raw_api/udp_server/configs/e2000d_aarch32_demo_udpserver.config b/example/network/raw_api/udp_server/configs/e2000d_aarch32_demo_udpserver.config index 258f3f87f..cf436dc7c 100644 --- a/example/network/raw_api/udp_server/configs/e2000d_aarch32_demo_udpserver.config +++ b/example/network/raw_api/udp_server/configs/e2000d_aarch32_demo_udpserver.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 # diff --git a/example/network/raw_api/udp_server/configs/e2000d_aarch64_demo_udpserver.config b/example/network/raw_api/udp_server/configs/e2000d_aarch64_demo_udpserver.config index 853f5b911..94d6a825b 100644 --- a/example/network/raw_api/udp_server/configs/e2000d_aarch64_demo_udpserver.config +++ b/example/network/raw_api/udp_server/configs/e2000d_aarch64_demo_udpserver.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 # diff --git a/example/network/raw_api/udp_server/configs/e2000q_aarch32_demo_udpserver.config b/example/network/raw_api/udp_server/configs/e2000q_aarch32_demo_udpserver.config index a268814de..7cb7a74bf 100644 --- a/example/network/raw_api/udp_server/configs/e2000q_aarch32_demo_udpserver.config +++ b/example/network/raw_api/udp_server/configs/e2000q_aarch32_demo_udpserver.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 # diff --git a/example/network/raw_api/udp_server/configs/e2000q_aarch64_demo_udpserver.config b/example/network/raw_api/udp_server/configs/e2000q_aarch64_demo_udpserver.config index 89bbf15e1..9e48e3090 100644 --- a/example/network/raw_api/udp_server/configs/e2000q_aarch64_demo_udpserver.config +++ b/example/network/raw_api/udp_server/configs/e2000q_aarch64_demo_udpserver.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 # diff --git a/example/network/raw_api/udp_server/configs/ft2004_aarch32_dsk_udpserver.config b/example/network/raw_api/udp_server/configs/ft2004_aarch32_dsk_udpserver.config index 2a93d7747..57cf09174 100644 --- a/example/network/raw_api/udp_server/configs/ft2004_aarch32_dsk_udpserver.config +++ b/example/network/raw_api/udp_server/configs/ft2004_aarch32_dsk_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 # diff --git a/example/network/raw_api/udp_server/configs/ft2004_aarch64_dsk_udpserver.config b/example/network/raw_api/udp_server/configs/ft2004_aarch64_dsk_udpserver.config index b343ce05e..ad3e95101 100644 --- a/example/network/raw_api/udp_server/configs/ft2004_aarch64_dsk_udpserver.config +++ b/example/network/raw_api/udp_server/configs/ft2004_aarch64_dsk_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 # diff --git a/example/network/raw_api/udp_server/configs/pd2308_aarch64_demo_udpserver.config b/example/network/raw_api/udp_server/configs/pd2308_aarch64_demo_udpserver.config index 8cb709944..f10b82c69 100644 --- a/example/network/raw_api/udp_server/configs/pd2308_aarch64_demo_udpserver.config +++ b/example/network/raw_api/udp_server/configs/pd2308_aarch64_demo_udpserver.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 # diff --git a/example/network/raw_api/udp_server/configs/phytiumpi_aarch32_firefly_udpserver.config b/example/network/raw_api/udp_server/configs/phytiumpi_aarch32_firefly_udpserver.config index 7eae367ed..728a06976 100644 --- a/example/network/raw_api/udp_server/configs/phytiumpi_aarch32_firefly_udpserver.config +++ b/example/network/raw_api/udp_server/configs/phytiumpi_aarch32_firefly_udpserver.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 # diff --git a/example/network/raw_api/udp_server/configs/phytiumpi_aarch64_firefly_udpserver.config b/example/network/raw_api/udp_server/configs/phytiumpi_aarch64_firefly_udpserver.config index 27367155f..e077a115d 100644 --- a/example/network/raw_api/udp_server/configs/phytiumpi_aarch64_firefly_udpserver.config +++ b/example/network/raw_api/udp_server/configs/phytiumpi_aarch64_firefly_udpserver.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 # diff --git a/example/network/raw_api/udp_server/fig/host_udp.png b/example/network/raw_api/udp_server/fig/host_udp.png index 3279569b5..9990dcd28 100644 Binary files a/example/network/raw_api/udp_server/fig/host_udp.png and b/example/network/raw_api/udp_server/fig/host_udp.png differ diff --git a/example/network/raw_api/udp_server/fig/ping_ipv4.png b/example/network/raw_api/udp_server/fig/ping_ipv4.png deleted file mode 100644 index 2b6806a7d..000000000 Binary files a/example/network/raw_api/udp_server/fig/ping_ipv4.png and /dev/null differ diff --git a/example/network/raw_api/udp_server/fig/ping_ipv4_dhcp.png b/example/network/raw_api/udp_server/fig/ping_ipv4_dhcp.png deleted file mode 100644 index 9c27cb122..000000000 Binary files a/example/network/raw_api/udp_server/fig/ping_ipv4_dhcp.png and /dev/null differ diff --git a/example/network/raw_api/udp_server/fig/ping_ipv6.png b/example/network/raw_api/udp_server/fig/ping_ipv6.png deleted file mode 100644 index e106868c3..000000000 Binary files a/example/network/raw_api/udp_server/fig/ping_ipv6.png and /dev/null differ diff --git a/example/network/raw_api/udp_server/fig/probe_ipv4.png b/example/network/raw_api/udp_server/fig/probe_ipv4.png deleted file mode 100644 index 63820681d..000000000 Binary files a/example/network/raw_api/udp_server/fig/probe_ipv4.png and /dev/null differ diff --git a/example/network/raw_api/udp_server/fig/probe_ipv4_dhcp.png b/example/network/raw_api/udp_server/fig/probe_ipv4_dhcp.png deleted file mode 100644 index 45278de44..000000000 Binary files a/example/network/raw_api/udp_server/fig/probe_ipv4_dhcp.png and /dev/null differ diff --git a/example/network/raw_api/udp_server/fig/probe_ipv6.png b/example/network/raw_api/udp_server/fig/probe_ipv6.png deleted file mode 100644 index 82605b056..000000000 Binary files a/example/network/raw_api/udp_server/fig/probe_ipv6.png and /dev/null differ diff --git a/example/network/raw_api/udp_server/fig/udp_server.png b/example/network/raw_api/udp_server/fig/udp_server.png index fd7b3e24a..41b48dc75 100644 Binary files a/example/network/raw_api/udp_server/fig/udp_server.png and b/example/network/raw_api/udp_server/fig/udp_server.png differ diff --git a/example/network/raw_api/udp_server/inc/lwip_timer.h b/example/network/raw_api/udp_server/inc/lwip_timer.h new file mode 100644 index 000000000..127b981a9 --- /dev/null +++ b/example/network/raw_api/udp_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.h + * Created Date: 2024-06-04 17:13:24 + * Last Modified: 2024-06-12 17:38:14 + * 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 \ No newline at end of file diff --git a/example/network/raw_api/udp_server/inc/udp_server_example.h b/example/network/raw_api/udp_server/inc/udp_server_example.h new file mode 100644 index 000000000..beb097179 --- /dev/null +++ b/example/network/raw_api/udp_server/inc/udp_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: udp_server_example.h + * Created Date: 2024-06-04 16:22:08 + * Last Modified: 2024-06-12 17:38:44 + * 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_SERVER_EXAMPLE_H +#define UDP_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 udp server example */ +int UdpServerCreate(void); +void UdpServerDeinit(void); +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/example/network/raw_api/udp_server/main.c b/example/network/raw_api/udp_server/main.c index fbf9e7c75..fb6058114 100644 --- a/example/network/raw_api/udp_server/main.c +++ b/example/network/raw_api/udp_server/main.c @@ -1,40 +1,63 @@ /* - * 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/17 first release + * Created Date: 2024-05-30 19:05:18 + * Last Modified: 2024-06-12 17:55:53 + * Description: This file is for udp server example main functions. + * + * Modify History: + * Ver Who Date Changes + * ----- ---------- -------- --------------------------------- + * 1.0 liuzhihong 2024/06/03 first release */ -#include -#include +/***************************** 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 "udp_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(); + + UdpServerCreate(); + TimerStaticLoop(10); + UdpServerDeinit(); +#endif return 0; } \ No newline at end of file diff --git a/example/network/raw_api/udp_server/makefile b/example/network/raw_api/udp_server/makefile index bb973bccd..f01298501 100644 --- a/example/network/raw_api/udp_server/makefile +++ b/example/network/raw_api/udp_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) \ diff --git a/example/network/raw_api/udp_server/sdkconfig b/example/network/raw_api/udp_server/sdkconfig index 27367155f..e077a115d 100644 --- a/example/network/raw_api/udp_server/sdkconfig +++ b/example/network/raw_api/udp_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 # diff --git a/example/network/raw_api/udp_server/sdkconfig.h b/example/network/raw_api/udp_server/sdkconfig.h index 6db3a124e..02fa5a7f3 100644 --- a/example/network/raw_api/udp_server/sdkconfig.h +++ b/example/network/raw_api/udp_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 */ diff --git a/example/network/raw_api/udp_server/src/cmd_udp_server.c b/example/network/raw_api/udp_server/src/cmd_udp_server.c new file mode 100644 index 000000000..ac8bf7058 --- /dev/null +++ b/example/network/raw_api/udp_server/src/cmd_udp_server.c @@ -0,0 +1,70 @@ +/* + * 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_server.c + * Created Date: 2024-06-04 16:07:46 + * Last Modified: 2024-06-12 17:38:50 + * Description: This file is for udp server example cmd catalogue. + * + * Modify History: + * Ver Who Date Changes + * ----- ---------- -------- --------------------------------- + * 1.0 liuzhihong 2024/06/04 first release + */ + +/***************************** Include Files *********************************/ +#include +#include + +#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_server_example.h" + +#define EXAMPLE_IDLE 0 +#define UDP_SERVER_EXAMPLE_RUNNING 1 + +static u32 init_flag_mask=EXAMPLE_IDLE; + +static void UdpServerExampleCheckState(void) +{ + switch(init_flag_mask) + { + case UDP_SERVER_EXAMPLE_RUNNING: + printf("Udp server example is running, we need to deinitialize it first! \r\n"); + UdpServerDeinit(); + init_flag_mask=EXAMPLE_IDLE; + break; + default: + break; + } +} +/* entry function for udp server example */ +static int UdpServerExampleEntry(int argc, char *argv[]) +{ + int ret = 0; + UdpServerExampleCheckState(); + ret = UdpServerCreate(); + init_flag_mask = UDP_SERVER_EXAMPLE_RUNNING; + return ret; +} + +/* register command for udp server example */ +SHELL_EXPORT_CMD(SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN), udpserver, UdpServerExampleEntry, Start Udp server); +#endif \ No newline at end of file diff --git a/example/network/raw_api/udp_server/src/lwip_timer.c b/example/network/raw_api/udp_server/src/lwip_timer.c new file mode 100644 index 000000000..d5ad988b9 --- /dev/null +++ b/example/network/raw_api/udp_server/src/lwip_timer.c @@ -0,0 +1,220 @@ +/* + * 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-04 16:07:28 + * Last Modified: 2024-06-12 17:38:55 + * Description: This file is for lwip timer function implementation. + * + * Modify History: + * Ver Who Date Changes + * ----- ---------- -------- --------------------------------- + * 1.0 liuzhihong 2024/06/04 first release + */ + +#include +#include +#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_cnttimer_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; +} \ No newline at end of file diff --git a/example/network/raw_api/udp_server/src/udp_server.c b/example/network/raw_api/udp_server/src/udp_server.c deleted file mode 100644 index ab11e91cf..000000000 --- a/example/network/raw_api/udp_server/src/udp_server.c +++ /dev/null @@ -1,78 +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_server.c - * Date: 2022-10-25 10:53:14 - * LastEditTime: 2022-12-05 18:30:49 - * Description: This file is for creating a udp server.The server can return received data to the client which send it! - * - * Modify History: - * Ver Who Date Changes - * ----- ------ -------- -------------------------------------- - * 1.0 liuzhihong 2022/11/17 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 -#include -#include"shell_port.h" -#define UDP_ECHO_PORT 5001 - -static void udp_demo_callback(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16_t port) -{ - struct pbuf *q = NULL; - const char *reply = "This is reply!\n"; - if (arg) - { - printf("%s", (char *)arg); - printf("%s", (char *)p->payload); - } - pbuf_free(p); - 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)); - udp_sendto(upcb, q, addr, port); - pbuf_free(q); -} -static char *st_buffer = "We get a data: "; -void UdpServerInit(void) -{ - struct udp_pcb *server_pcb; - server_pcb = udp_new(); - if (server_pcb == NULL) - { - printf("Udp Server open failed!\r\n"); - printf("Unable to create a new udp_pcb.\r\n"); - return ; - } - /* 绑定端口号 */ - ip_addr_t ipaddr; - IP_ADDR4(&ipaddr, 192, 168, 4, 10); - udp_bind(server_pcb, &ipaddr, UDP_ECHO_PORT); - - /* 注册接收数据回调函数 */ - udp_recv(server_pcb, udp_demo_callback, (void *)st_buffer); - printf("Udp Server Open Success!\r\n"); -} - -SHELL_EXPORT_CMD(SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN), udpserver, UdpServerInit, Start Udp server); \ No newline at end of file diff --git a/example/network/raw_api/udp_server/src/udp_server_example.c b/example/network/raw_api/udp_server/src/udp_server_example.c new file mode 100644 index 000000000..a14232647 --- /dev/null +++ b/example/network/raw_api/udp_server/src/udp_server_example.c @@ -0,0 +1,226 @@ +/* + * 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_server_example.c + * Created Date: 2024-05-30 19:05:18 + * Last Modified: 2024-06-13 17:52:59 + * Description: This file is for udp server example function implementation. + * + * Modify History: + * Ver Who Date Changes + * ----- ---------- -------- --------------------------------- + * 1.0 liuzhihong 2024/06/04 first release + */ +#include +#include +#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_ECHO_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 void udp_recv_callback(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16_t port) +{ + struct pbuf *q = NULL; + const char *reply = "This is reply!\n"; + + + printf("We get a data:%s", (char *)p->payload); + pbuf_free(p); + + 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)); + udp_sendto(upcb, q, addr, port); + pbuf_free(q); +} + +void UdpServerInit(void) +{ + err_t ret = ERR_OK; + struct udp_pcb *server_pcb; + server_pcb = udp_new(); + if (server_pcb == NULL) + { + printf("Udp Server open failed!\r\n"); + printf("Unable to create a new udp_pcb.\r\n"); + return ; + } + /* 绑定端口号 */ + ip_addr_t ipaddr; + IP_ADDR4(&ipaddr, 192, 168, 4, 10); + ret = udp_bind(server_pcb, &ipaddr, UDP_ECHO_PORT); + if (ret == ERR_USE) + { + printf("The port and ip are already binded!\n"); + udp_remove(server_pcb); + return; + } + + /* 注册接收数据回调函数 */ + udp_recv(server_pcb, udp_recv_callback, NULL); + printf("Udp Server Open Success!\r\n"); +} + +int UdpServerCreate(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"); + + UdpServerInit(); + +exit: + if (ret == FT_SUCCESS) + { + printf("%s@%d:Udp server example [success].\r\n", __func__, __LINE__); + return 0; + } + else + { + printf("%s@%d:Udp server example [failure].\r\n", __func__, __LINE__); + return 1; + } +} + +void UdpServerDeinit(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); + } +} + diff --git a/example/peripherals/spi/src/spim_flash_example.c b/example/peripherals/spi/src/spim_flash_example.c index 2fbf31e4d..765f7f545 100644 --- a/example/peripherals/spi/src/spim_flash_example.c +++ b/example/peripherals/spi/src/spim_flash_example.c @@ -102,7 +102,8 @@ int FSpimFlashExample() FSpimSetChipSelection(&spim, FALSE); /* 将cs脚上拉 */ - if ((recv_data[0] == 0xff) && (recv_data[1] == 0xff) && (recv_data[2] == 0xff)) + if (((recv_data[0] == 0xff) && (recv_data[1] == 0xff) && (recv_data[2] == 0xff)) || \ + ((recv_data[0] == 0) && (recv_data[1] == 0) && (recv_data[2] == 0))) { ret = FSPIM_ERR_TRANS_FAIL; FSPIM_ERROR("Receive data from flash is wrong."); diff --git a/soc/common/fmmu_code_table.c b/soc/common/fmmu_code_table.c index 229ce60f1..b6778881a 100644 --- a/soc/common/fmmu_code_table.c +++ b/soc/common/fmmu_code_table.c @@ -52,7 +52,7 @@ const struct ArmMmuRegion code_mmu_regions[] = MMU_REGION_FLAT_ENTRY("CODE_RAM", (uintptr_t)_image_ram_start, (uintptr_t)_image_ram_size, - MT_NORMAL | MT_P_RW_U_RW | MT_NS), + MT_NORMAL | MT_P_RW_U_NA | MT_NS), }; diff --git a/third-party/lwip-2.1.2/ports/lwip_port.c b/third-party/lwip-2.1.2/ports/lwip_port.c index 0f5d61978..cdaccb630 100644 --- a/third-party/lwip-2.1.2/ports/lwip_port.c +++ b/third-party/lwip-2.1.2/ports/lwip_port.c @@ -184,16 +184,18 @@ struct netif *LwipPortAdd(struct netif *netif, /* Start thread to detect link periodically for Hot Plug autodetect */ if(netif_p) { + lwip_port = (struct LwipPort *)netif_p->state; + #if defined(CONFIG_LWIP_PORT_USE_LINK_DETECT_THREAD) memcpy(detect_thread_name, netif->name, 2); strcpy(&detect_thread_name[2], LWIP_PHY_DETECT_THREAD_NAME); - lwip_port = (struct LwipPort *)netif_p->state; lwip_port->detect_thread_handle = sys_thread_new(detect_thread_name, link_detect_thread, netif, CONFIG_LWIP_PORT_LINK_DETECT_STACKSIZE, CONFIG_LWIP_PORT_LINK_DETECT_PRIORITY); #endif - /* create semaphore for rx thread */ + #if defined(CONFIG_LWIP_PORT_USE_RECEIVE_THREAD) + /* create semaphore for rx thread */ sys_countingsem_create(&lwip_port->sem_rx_data_available,SEMAPHORE_MAXCOUNT,SEMAPHORE_INITIALCOUNT); memcpy(rx_thread_name, netif->name, 2); diff --git a/tools/build/ld/aarch32_ram.ld b/tools/build/ld/aarch32_ram.ld index 1f6332f72..9ed9dd717 100644 --- a/tools/build/ld/aarch32_ram.ld +++ b/tools/build/ld/aarch32_ram.ld @@ -24,7 +24,8 @@ SECTIONS *(.boot) . = ALIGN(64); KEEP(*(.vectors)) - + . = ALIGN(64); + KEEP(*(.rtos_vectors_*)) } > MEMORY_SPACE .text : { diff --git a/tools/build/ld/aarch64_ram.ld b/tools/build/ld/aarch64_ram.ld index 1966a9902..0e1bed6fb 100644 --- a/tools/build/ld/aarch64_ram.ld +++ b/tools/build/ld/aarch64_ram.ld @@ -18,7 +18,10 @@ SECTIONS { .text : { __text_region_start = .; + . = ALIGN(64); KEEP (*(.vectors)) + . = ALIGN(64); + KEEP (*(.rtos_vectors_*)) *(.boot) *(.text) *(.text.*)