From 219575898acf9655d852aa3f88d6879a76c7264b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B6=82=E7=85=9C=E6=B4=8B?= <1163589503@qq.com> Date: Thu, 3 Aug 2023 14:15:26 +0800 Subject: [PATCH] 23/08/03 Add Netdev to xidatong-arm32 --- APP_Framework/Applications/benchmark/Makefile | 16 -- .../Applications/webnet/WebNet_XiUOS | 2 +- .../transform_layer/xizi/transform.c | 2 +- .../transform_layer/xizi/transform.h | 2 +- .../xizi/user_api/posix_support/mqueue.c | 2 +- .../applications/benchmark/Makefile | 16 -- .../third_party_driver/ethernet/ethernetif.c | 77 +++++---- .../third_party_driver/ethernet/Makefile | 2 +- .../ethernet/enet_ethernetif.c | 7 + .../third_party_driver/ethernet/eth_netdev.c | 163 ++++++++++++++++++ .../include/connect_ethernet.h | 2 + Ubiquitous/XiZi_IIoT/fs/shared/src/iot-vfs.c | 4 +- Ubiquitous/XiZi_IIoT/kernel/include/xs_kdbg.h | 3 + Ubiquitous/XiZi_IIoT/path_kernel.mk | 1 + .../resources/ethernet/LwIP/arch/sys_arch.c | 2 + .../resources/include/netdev/netdev.h | 2 - .../XiZi_IIoT/tool/shell/letter-shell/cmd.c | 2 +- 17 files changed, 225 insertions(+), 80 deletions(-) delete mode 100644 APP_Framework/Applications/benchmark/Makefile delete mode 100644 Ubiquitous/RT-Thread_Fusion_XiUOS/aiit_board/xidatong-riscv64/applications/benchmark/Makefile create mode 100644 Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/ethernet/eth_netdev.c diff --git a/APP_Framework/Applications/benchmark/Makefile b/APP_Framework/Applications/benchmark/Makefile deleted file mode 100644 index d9d5e47dc..000000000 --- a/APP_Framework/Applications/benchmark/Makefile +++ /dev/null @@ -1,16 +0,0 @@ - -# include $(APPDIR)/Application.mk -# ifeq ($(CONFIG_ADD_NUTTX_FETURES),y) - # include $(APPDIR)/Make.defs - # CSRCS += $(wildcard src/*/*.c) $(wildcard support/*.c) - # include $(APPDIR)/Application.mk -# endif - -# ifeq ($(CONFIG_ADD_XIZI_FEATURES),y) - SRC_DIR := - ifeq ($(CONFIG_APP_BENCHMARK), y) - SRC_DIR += src - SRC_DIR += support - endif - include $(KERNEL_ROOT)/compiler.mk -# endif diff --git a/APP_Framework/Applications/webnet/WebNet_XiUOS b/APP_Framework/Applications/webnet/WebNet_XiUOS index 83d987597..60a8a500b 160000 --- a/APP_Framework/Applications/webnet/WebNet_XiUOS +++ b/APP_Framework/Applications/webnet/WebNet_XiUOS @@ -1 +1 @@ -Subproject commit 83d987597cf027177fb3798c6da547a3d3e3d5e1 +Subproject commit 60a8a500b93b47876c6eaff600e4cf2b8bf7b283 diff --git a/APP_Framework/Framework/transform_layer/xizi/transform.c b/APP_Framework/Framework/transform_layer/xizi/transform.c index 002c8f1be..ba0b8f614 100644 --- a/APP_Framework/Framework/transform_layer/xizi/transform.c +++ b/APP_Framework/Framework/transform_layer/xizi/transform.c @@ -164,7 +164,7 @@ int PrivTimerModify(timer_t timerid, int flags, const struct itimerspec *restric /*********************fs**************************/ #ifdef FS_VFS /************************Driver Posix Transform***********************/ -int PrivOpen(const char *path, int flags) +int PrivOpen(const char *path, int flags, ...) { return open(path, flags); } diff --git a/APP_Framework/Framework/transform_layer/xizi/transform.h b/APP_Framework/Framework/transform_layer/xizi/transform.h index fe817f18a..ef1894c32 100644 --- a/APP_Framework/Framework/transform_layer/xizi/transform.h +++ b/APP_Framework/Framework/transform_layer/xizi/transform.h @@ -427,7 +427,7 @@ uint32_t PrivGetTickTime(); /*********************driver*************************/ -int PrivOpen(const char *path, int flags); +int PrivOpen(const char *path, int flags, ...); int PrivRead(int fd, void *buf, size_t len); int PrivWrite(int fd, const void *buf, size_t len); int PrivClose(int fd); diff --git a/APP_Framework/Framework/transform_layer/xizi/user_api/posix_support/mqueue.c b/APP_Framework/Framework/transform_layer/xizi/user_api/posix_support/mqueue.c index a92dc95f6..9f13a1445 100644 --- a/APP_Framework/Framework/transform_layer/xizi/user_api/posix_support/mqueue.c +++ b/APP_Framework/Framework/transform_layer/xizi/user_api/posix_support/mqueue.c @@ -45,7 +45,7 @@ ssize_t mq_receive(mqd_t mqdes, char* msg_ptr, size_t msg_len, unsigned* msg_pri ssize_t ret; *msg_prio = 0; - ret = UserMsgQueueRecv(mqdes, (void*)msg_ptr, msg_len, 100000); + ret = UserMsgQueueRecv(mqdes, (void*)msg_ptr, msg_len, WAITING_FOREVER); return ret; } diff --git a/Ubiquitous/RT-Thread_Fusion_XiUOS/aiit_board/xidatong-riscv64/applications/benchmark/Makefile b/Ubiquitous/RT-Thread_Fusion_XiUOS/aiit_board/xidatong-riscv64/applications/benchmark/Makefile deleted file mode 100644 index 0c8c2bfcf..000000000 --- a/Ubiquitous/RT-Thread_Fusion_XiUOS/aiit_board/xidatong-riscv64/applications/benchmark/Makefile +++ /dev/null @@ -1,16 +0,0 @@ - -# include $(APPDIR)/Application.mk -ifeq ($(CONFIG_ADD_NUTTX_FETURES),y) - include $(APPDIR)/Make.defs - CSRCS += $(wildcard src/*/*.c) $(wildcard support/*.c) - include $(APPDIR)/Application.mk -endif - -ifeq ($(CONFIG_ADD_XIZI_FEATURES),y) - SRC_DIR := - ifeq ($(CONFIG_APP_BENCHMARK), y) - SRC_DIR += src - SRC_DIR += support - endif - include $(KERNEL_ROOT)/compiler.mk -endif diff --git a/Ubiquitous/XiZi_IIoT/board/edu-arm32/third_party_driver/ethernet/ethernetif.c b/Ubiquitous/XiZi_IIoT/board/edu-arm32/third_party_driver/ethernet/ethernetif.c index 7a50d2315..738359b59 100644 --- a/Ubiquitous/XiZi_IIoT/board/edu-arm32/third_party_driver/ethernet/ethernetif.c +++ b/Ubiquitous/XiZi_IIoT/board/edu-arm32/third_party_driver/ethernet/ethernetif.c @@ -190,44 +190,6 @@ void Time_Update_LwIP(void) // no need to do } -/** - * @brief Should be called at the beginning of the program to set up the network interface. - * @param netif The network interface structure for this ethernetif. - * @retval err_t: - * - LL_OK: The IF is initialized - * - LL_ERR: The IF is uninitialized - */ -err_t ethernetif_init(struct netif* netif) -{ -#if LWIP_NETIF_HOSTNAME - /* Initialize interface hostname */ - netif->hostname = "lwip"; -#endif /* LWIP_NETIF_HOSTNAME */ - netif->name[0] = IFNAME0; - netif->name[1] = IFNAME1; - -#ifndef ETHERNET_LOOPBACK_TEST - /* We directly use etharp_output() here to save a function call. - * You can instead declare your own function an call etharp_output() - * from it if you have to do some checks before sending (e.g. if link - * is available...) */ - netif->output = etharp_output; - netif->linkoutput = low_level_output; -#endif - - /* initialize the hardware */ - if (LL_OK != low_level_init(netif)) { - return LL_ERR; - } - - if (EOK != lwip_netdev_add(netif)) { - SYS_KDEBUG_LOG(NETDEV_DEBUG, ("[%s] LWIP add netdev failed.\n", __func__)); - } else { - printf("[%s] Add Netdev successful\n", __func__); - } - return LL_OK; -} - /** * @brief This function should be called when a packet is ready to be read from the interface. * @param netif The network interface structure for this ethernetif. @@ -267,6 +229,45 @@ void ethernetif_input(void* netif_arg) } } +/** + * @brief Should be called at the beginning of the program to set up the network interface. + * @param netif The network interface structure for this ethernetif. + * @retval err_t: + * - LL_OK: The IF is initialized + * - LL_ERR: The IF is uninitialized + */ +err_t ethernetif_init(struct netif* netif) +{ +#if LWIP_NETIF_HOSTNAME + /* Initialize interface hostname */ + netif->hostname = "lwip"; +#endif /* LWIP_NETIF_HOSTNAME */ + netif->name[0] = IFNAME0; + netif->name[1] = IFNAME1; + +#ifndef ETHERNET_LOOPBACK_TEST + /* We directly use etharp_output() here to save a function call. + * You can instead declare your own function an call etharp_output() + * from it if you have to do some checks before sending (e.g. if link + * is available...) */ + netif->output = etharp_output; + netif->linkoutput = low_level_output; + // netif->linkoutput = ethernetif_linkoutput; +#endif + + /* initialize the hardware */ + if (LL_OK != low_level_init(netif)) { + return LL_ERR; + } + + if (EOK != lwip_netdev_add(netif)) { + SYS_KDEBUG_LOG(NETDEV_DEBUG, ("[%s] LWIP add netdev failed.\n", __func__)); + } else { + printf("[%s] Add Netdev successful\n", __func__); + } + return LL_OK; +} + /** * @brief Check the netif link status. * @param netif the network interface diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/ethernet/Makefile b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/ethernet/Makefile index 65f5adc78..6cd8a10fa 100755 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/ethernet/Makefile +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/ethernet/Makefile @@ -1,3 +1,3 @@ -SRC_FILES := enet_ethernetif.c enet_ethernetif_kinetis.c fsl_enet.c +SRC_FILES := enet_ethernetif.c enet_ethernetif_kinetis.c fsl_enet.c eth_netdev.c SRC_DIR := lan8720 include $(KERNEL_ROOT)/compiler.mk \ No newline at end of file diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/ethernet/enet_ethernetif.c b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/ethernet/enet_ethernetif.c index 9b8ca475a..114f1ef61 100755 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/ethernet/enet_ethernetif.c +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/ethernet/enet_ethernetif.c @@ -68,6 +68,7 @@ #include "fsl_gpio.h" #include "fsl_iomuxc.h" +#include "netdev.h" #include "sys_arch.h" /******************************************************************************* @@ -319,6 +320,12 @@ err_t ethernetif_init(struct netif *netif, struct ethernetif *ethernetif, } #endif /* LWIP_IPV6 && LWIP_IPV6_MLD */ + SYS_KDEBUG_LOG(NETDEV_DEBUG, ("[%s] Adding netdev.\n", __func__)); + if (EOK != lwip_netdev_add(netif)) { + SYS_KDEBUG_LOG(NETDEV_DEBUG, ("[%s] LWIP add netdev failed.\n", __func__)); + } else { + printf("[%s] Add Netdev successful\n", __func__); + } return ERR_OK; } diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/ethernet/eth_netdev.c b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/ethernet/eth_netdev.c new file mode 100644 index 000000000..2dfe75795 --- /dev/null +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/ethernet/eth_netdev.c @@ -0,0 +1,163 @@ + +#include +#include +#include +#include +#include +#include + +static const uint32_t NETIF_NAME_LEN = 2; + +static int lwip_netdev_set_up(struct netdev* netdev) +{ + netif_set_up((struct netif*)netdev->user_data); + return ERR_OK; +} + +static int lwip_netdev_set_down(struct netdev* netif) +{ + netif_set_down((struct netif*)netif->user_data); + return ERR_OK; +} + +#ifndef ip_2_ip4 +#define ip_2_ip4(ipaddr) (ipaddr) +#endif +static int lwip_netdev_set_addr_info(struct netdev* netdev, ip_addr_t* ip_addr, ip_addr_t* netmask, ip_addr_t* gw) +{ + if (ip_addr && netmask && gw) { + netif_set_addr((struct netif*)netdev->user_data, ip_2_ip4(ip_addr), ip_2_ip4(netmask), ip_2_ip4(gw)); + } else { + if (ip_addr) { + netif_set_ipaddr((struct netif*)netdev->user_data, ip_2_ip4(ip_addr)); + } + if (netmask) { + netif_set_netmask((struct netif*)netdev->user_data, ip_2_ip4(netmask)); + } + if (gw) { + netif_set_gw((struct netif*)netdev->user_data, ip_2_ip4(gw)); + } + } +} + +#ifdef LWIP_DNS +static int lwip_netdev_set_dns_server(struct netdev* netdev, uint8_t dns_num, ip_addr_t* dns_server) +{ +#if LWIP_VERSION_MAJOR == 1U /* v1.x */ + extern void dns_setserver(u8_t numdns, ip_addr_t * dnsserver); +#else /* >=2.x */ + extern void dns_setserver(uint8_t dns_num, const ip_addr_t* dns_server); +#endif /* LWIP_VERSION_MAJOR == 1U */ + + dns_setserver(dns_num, dns_server); + return ERR_OK; +} +#endif + +#ifdef LWIP_DHCP +static int lwip_netdev_set_dhcp(struct netdev* netdev, bool is_enabled) +{ + netdev_low_level_set_dhcp_status(netdev, is_enabled); + + if (true == is_enabled) { + dhcp_start((struct netif*)netdev->user_data); + } else { + dhcp_stop((struct netif*)netdev->user_data); + } + + return ERR_OK; +} +#endif + +static int lwip_netdev_set_default(struct netdev* netdev) +{ + netif_set_default((struct netif*)netdev->user_data); + return ERR_OK; +} + +static const struct netdev_ops lwip_netdev_ops = { + .set_up = lwip_netdev_set_up, + .set_down = lwip_netdev_set_down, + .set_addr_info = lwip_netdev_set_addr_info, +#ifdef LWIP_DNS + .set_dns_server = lwip_netdev_set_dns_server, +#endif +#ifdef LWIP_DHCP + .set_dhcp = lwip_netdev_set_dhcp, +#endif + .set_default = lwip_netdev_set_default, +}; + +static inline int netdev_set_flags(struct netif* lwip_netif) +{ + CHECK(lwip_netif); + struct netdev* netdev = netdev_get_by_name(lwip_netif->name); + if (netdev == NULL) { + return -ERR_IF; + } + + netdev->mtu = lwip_netif->mtu; + // set flags + if (lwip_netif->flags | NETIF_FLAG_BROADCAST) { + netdev->flags |= NETDEV_FLAG_BROADCAST; + } + if (lwip_netif->flags | NETIF_FLAG_ETHARP) { + netdev->flags |= NETDEV_FLAG_ETHARP; + } + if (lwip_netif->flags | NETIF_FLAG_IGMP) { + netdev->flags |= NETDEV_FLAG_IGMP; + } +#if LWIP_VERSION_MAJOR >= 2U /* >= v2.x */ + if (lwip_netif->flags & NETIF_FLAG_MLD6) { + netdev->flags |= NETDEV_FLAG_MLD6; + } +#endif /* LWIP_VERSION_MAJOR >= 2U */ + +#if LWIP_DHCP + netdev_low_level_set_dhcp_status(netdev, true); +#else + netdev_low_level_set_dhcp_status(netdev, false); +#endif + + return ERR_OK; +} + +int lwip_netdev_add(struct netif* lwip_netif) +{ + CHECK(lwip_netif); + + struct netdev* netdev = calloc(1, sizeof(struct netdev)); + if (netdev == NULL) { + return -ERR_IF; + } + + // init netdev + char netif_name[NETIF_NAME_LEN + 1]; + SYS_KDEBUG_LOG(NETDEV_DEBUG, ("[%s] Lwip netif name: %s\n", __func__, lwip_netif->name)); + strncpy(netif_name, lwip_netif->name, NETIF_NAME_LEN); + // register netdev + int result = netdev_register(netdev, netif_name, (void*)lwip_netif); + // set values of netdev + netdev_set_flags(lwip_netif); + netdev->ops = &lwip_netdev_ops; + netdev->hwaddr_len = lwip_netif->hwaddr_len; + memcpy(netdev->hwaddr, lwip_netif->hwaddr, lwip_netif->hwaddr_len); + netdev->ip_addr = lwip_netif->ip_addr; + netdev->gw = lwip_netif->gw; + netdev->netmask = lwip_netif->netmask; + + return result; +} + +void lwip_netdev_del(struct netif* lwip_netif) +{ + char name[NETIF_NAME_LEN + 1]; + struct netdev* netdev; + + CHECK(lwip_netif); + + strncpy(name, lwip_netif->name, NETIF_NAME_LEN); + netdev = netdev_get_by_name(name); + netdev_unregister(netdev); + free(netdev); +} \ No newline at end of file diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/connect_ethernet.h b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/connect_ethernet.h index 12f65358b..0933eecd5 100755 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/connect_ethernet.h +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/connect_ethernet.h @@ -33,6 +33,8 @@ #define sourceClock CLOCK_GetFreq(kCLOCK_CoreSysClk) #endif +int lwip_netdev_add(struct netif* lwip_netif); +void lwip_netdev_del(struct netif* lwip_netif); #ifdef __cplusplus } diff --git a/Ubiquitous/XiZi_IIoT/fs/shared/src/iot-vfs.c b/Ubiquitous/XiZi_IIoT/fs/shared/src/iot-vfs.c index e340d08fe..d81b9113a 100644 --- a/Ubiquitous/XiZi_IIoT/fs/shared/src/iot-vfs.c +++ b/Ubiquitous/XiZi_IIoT/fs/shared/src/iot-vfs.c @@ -772,7 +772,8 @@ int stat(const char *path, struct stat *buf) ret = mp->fs->stat(mp, relpath, &vfs_statbuf); if (ret < 0) { - SYS_ERR("%s: stat file failed\n", __func__); + // stat() is absolutely fine to check if a file exists + // SYS_ERR("%s: stat file failed\n", __func__); goto err; } @@ -790,7 +791,6 @@ err: free(abspath); if (ret < 0) { - KUpdateExstatus(ret); return -1; } return 0; diff --git a/Ubiquitous/XiZi_IIoT/kernel/include/xs_kdbg.h b/Ubiquitous/XiZi_IIoT/kernel/include/xs_kdbg.h index 7612a959e..7dc4bc7fa 100644 --- a/Ubiquitous/XiZi_IIoT/kernel/include/xs_kdbg.h +++ b/Ubiquitous/XiZi_IIoT/kernel/include/xs_kdbg.h @@ -43,6 +43,9 @@ extern "C" { #define KDBG_HOOK 0 #define MSGQUEUE_DEBUG 0 +#define FILESYS_DEBUG 0 +#define NETDEV_DEBUG 0 +#define WEBNET_DEBUG 0 #define SYS_KDEBUG_LOG(section, information) \ do { \ diff --git a/Ubiquitous/XiZi_IIoT/path_kernel.mk b/Ubiquitous/XiZi_IIoT/path_kernel.mk index 5ee36f062..7b44f073e 100755 --- a/Ubiquitous/XiZi_IIoT/path_kernel.mk +++ b/Ubiquitous/XiZi_IIoT/path_kernel.mk @@ -53,6 +53,7 @@ KERNELPATHS += \ -I$(KERNEL_ROOT)/resources/ethernet/LwIP/include/lwip/prot \ -I$(KERNEL_ROOT)/resources/ethernet/LwIP/arch +KERNELPATHS += -I$(KERNEL_ROOT)/resources/include/netdev endif endif diff --git a/Ubiquitous/XiZi_IIoT/resources/ethernet/LwIP/arch/sys_arch.c b/Ubiquitous/XiZi_IIoT/resources/ethernet/LwIP/arch/sys_arch.c index 29175d23f..7ec40271d 100644 --- a/Ubiquitous/XiZi_IIoT/resources/ethernet/LwIP/arch/sys_arch.c +++ b/Ubiquitous/XiZi_IIoT/resources/ethernet/LwIP/arch/sys_arch.c @@ -347,6 +347,8 @@ void lwip_config_input(struct netif* net) void lwip_config_tcp(uint8_t enet_port, char* ip, char* mask, char* gw) { + sys_sem_new(get_eth_recv_sem(), 0); + ip4_addr_t net_ipaddr, net_netmask, net_gw; char* eth_cfg; diff --git a/Ubiquitous/XiZi_IIoT/resources/include/netdev/netdev.h b/Ubiquitous/XiZi_IIoT/resources/include/netdev/netdev.h index 56cb1c02f..8ebe09c76 100644 --- a/Ubiquitous/XiZi_IIoT/resources/include/netdev/netdev.h +++ b/Ubiquitous/XiZi_IIoT/resources/include/netdev/netdev.h @@ -11,8 +11,6 @@ extern "C" { #endif -#define NETDEV_DEBUG true - #define NETDEV_DEBUG_PRINT_IP_INFO(ip, netmask, gw) \ ("[%s %d]ip: %u.%u.%u.%u, netmask: %u.%u.%u.%u, gw: %u.%u.%u.%u\n", \ __func__, __LINE__, \ diff --git a/Ubiquitous/XiZi_IIoT/tool/shell/letter-shell/cmd.c b/Ubiquitous/XiZi_IIoT/tool/shell/letter-shell/cmd.c index ff5e8f98d..82fd4eb6f 100644 --- a/Ubiquitous/XiZi_IIoT/tool/shell/letter-shell/cmd.c +++ b/Ubiquitous/XiZi_IIoT/tool/shell/letter-shell/cmd.c @@ -98,7 +98,7 @@ long ShowTask(void) KPrintf("*************************************************************************************************\n"); #ifndef SCHED_POLICY_FIFO #ifdef ARCH_SMP - KPrintf(" STAT ID %-*.s PRI CORE STACK_DEPTH USED LEFT_TICKS ERROR_STAT\n", _NUM_MAX, item_title); + KPrintf(" STAT ID %-*.s PRI CORE STACK_DEPTH USED LEFT_TICKS ERROR_STAT\n", NAME_NUM_MAX, item_title); #else KPrintf(" STAT ID %-*.s PRI STACK_DEPTH USED LEFT_TICKS ERROR_STAT\n", NAME_NUM_MAX, item_title); #endif