23/08/03 Add Netdev to xidatong-arm32

This commit is contained in:
涂煜洋 2023-08-03 14:15:26 +08:00
parent 06b9d67f2d
commit 219575898a
17 changed files with 225 additions and 80 deletions

View File

@ -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

@ -1 +1 @@
Subproject commit 83d987597cf027177fb3798c6da547a3d3e3d5e1 Subproject commit 60a8a500b93b47876c6eaff600e4cf2b8bf7b283

View File

@ -164,7 +164,7 @@ int PrivTimerModify(timer_t timerid, int flags, const struct itimerspec *restric
/*********************fs**************************/ /*********************fs**************************/
#ifdef FS_VFS #ifdef FS_VFS
/************************Driver Posix Transform***********************/ /************************Driver Posix Transform***********************/
int PrivOpen(const char *path, int flags) int PrivOpen(const char *path, int flags, ...)
{ {
return open(path, flags); return open(path, flags);
} }

View File

@ -427,7 +427,7 @@ uint32_t PrivGetTickTime();
/*********************driver*************************/ /*********************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 PrivRead(int fd, void *buf, size_t len);
int PrivWrite(int fd, const void *buf, size_t len); int PrivWrite(int fd, const void *buf, size_t len);
int PrivClose(int fd); int PrivClose(int fd);

View File

@ -45,7 +45,7 @@ ssize_t mq_receive(mqd_t mqdes, char* msg_ptr, size_t msg_len, unsigned* msg_pri
ssize_t ret; ssize_t ret;
*msg_prio = 0; *msg_prio = 0;
ret = UserMsgQueueRecv(mqdes, (void*)msg_ptr, msg_len, 100000); ret = UserMsgQueueRecv(mqdes, (void*)msg_ptr, msg_len, WAITING_FOREVER);
return ret; return ret;
} }

View File

@ -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

View File

@ -190,44 +190,6 @@ void Time_Update_LwIP(void)
// no need to do // 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. * @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. * @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. * @brief Check the netif link status.
* @param netif the network interface * @param netif the network interface

View File

@ -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 SRC_DIR := lan8720
include $(KERNEL_ROOT)/compiler.mk include $(KERNEL_ROOT)/compiler.mk

View File

@ -68,6 +68,7 @@
#include "fsl_gpio.h" #include "fsl_gpio.h"
#include "fsl_iomuxc.h" #include "fsl_iomuxc.h"
#include "netdev.h"
#include "sys_arch.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 */ #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; return ERR_OK;
} }

View File

@ -0,0 +1,163 @@
#include <connect_ethernet.h>
#include <inet.h>
#include <lwip/dhcp.h>
#include <lwip/netif.h>
#include <netdev.h>
#include <xs_kdbg.h>
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);
}

View File

@ -33,6 +33,8 @@
#define sourceClock CLOCK_GetFreq(kCLOCK_CoreSysClk) #define sourceClock CLOCK_GetFreq(kCLOCK_CoreSysClk)
#endif #endif
int lwip_netdev_add(struct netif* lwip_netif);
void lwip_netdev_del(struct netif* lwip_netif);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -772,7 +772,8 @@ int stat(const char *path, struct stat *buf)
ret = mp->fs->stat(mp, relpath, &vfs_statbuf); ret = mp->fs->stat(mp, relpath, &vfs_statbuf);
if (ret < 0) { 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; goto err;
} }
@ -790,7 +791,6 @@ err:
free(abspath); free(abspath);
if (ret < 0) { if (ret < 0) {
KUpdateExstatus(ret);
return -1; return -1;
} }
return 0; return 0;

View File

@ -43,6 +43,9 @@ extern "C" {
#define KDBG_HOOK 0 #define KDBG_HOOK 0
#define MSGQUEUE_DEBUG 0 #define MSGQUEUE_DEBUG 0
#define FILESYS_DEBUG 0
#define NETDEV_DEBUG 0
#define WEBNET_DEBUG 0
#define SYS_KDEBUG_LOG(section, information) \ #define SYS_KDEBUG_LOG(section, information) \
do { \ do { \

View File

@ -53,6 +53,7 @@ KERNELPATHS += \
-I$(KERNEL_ROOT)/resources/ethernet/LwIP/include/lwip/prot \ -I$(KERNEL_ROOT)/resources/ethernet/LwIP/include/lwip/prot \
-I$(KERNEL_ROOT)/resources/ethernet/LwIP/arch -I$(KERNEL_ROOT)/resources/ethernet/LwIP/arch
KERNELPATHS += -I$(KERNEL_ROOT)/resources/include/netdev
endif endif
endif endif

View File

@ -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) 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; ip4_addr_t net_ipaddr, net_netmask, net_gw;
char* eth_cfg; char* eth_cfg;

View File

@ -11,8 +11,6 @@
extern "C" { extern "C" {
#endif #endif
#define NETDEV_DEBUG true
#define NETDEV_DEBUG_PRINT_IP_INFO(ip, netmask, gw) \ #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", \ ("[%s %d]ip: %u.%u.%u.%u, netmask: %u.%u.%u.%u, gw: %u.%u.%u.%u\n", \
__func__, __LINE__, \ __func__, __LINE__, \

View File

@ -98,7 +98,7 @@ long ShowTask(void)
KPrintf("*************************************************************************************************\n"); KPrintf("*************************************************************************************************\n");
#ifndef SCHED_POLICY_FIFO #ifndef SCHED_POLICY_FIFO
#ifdef ARCH_SMP #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 #else
KPrintf(" STAT ID %-*.s PRI STACK_DEPTH USED LEFT_TICKS ERROR_STAT\n", NAME_NUM_MAX, item_title); KPrintf(" STAT ID %-*.s PRI STACK_DEPTH USED LEFT_TICKS ERROR_STAT\n", NAME_NUM_MAX, item_title);
#endif #endif