Merge branch 'prepare_for_master' of https://git.trustie.net/xuos/xiuos into mqtt

This commit is contained in:
wgzAIIT
2023-08-08 08:56:51 +08:00
60 changed files with 3225 additions and 924 deletions
@@ -188,7 +188,7 @@ sudo apt install gdb-multiarch
qemu-system-arm -machine lm3s6965evb -nographic -kernel build/XiZi-cortex-m3-emulator.elf -s -S
```
然后要重新开启另一个linux系统终端一个终端,执行`riscv-none-embed-gdb`命令
然后要重新开启另一个linux系统终端一个终端,执行命令
```
gdb-multiarch build/XiZi-cortex-m3-emulator.elf -ex "target remote localhost:1234"
@@ -1,9 +1,11 @@
export CROSS_COMPILE ?=/usr/bin/arm-none-eabi-
export CFLAGS := -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -ffunction-sections -fdata-sections -Dgcc -O0 -gdwarf-2 -g -fgnu89-inline -Wa,-mimplicit-it=thumb -Werror
export CFLAGS := -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -ffunction-sections -fdata-sections -Dgcc -O0 -fgnu89-inline -Wa,-mimplicit-it=thumb -Werror
# export CFLAGS := -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -ffunction-sections -fdata-sections -Dgcc -O0 -gdwarf-2 -g -fgnu89-inline -Wa,-mimplicit-it=thumb -Werror
export AFLAGS := -c -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -ffunction-sections -fdata-sections -x assembler-with-cpp -Wa,-mimplicit-it=thumb -gdwarf-2
export LFLAGS := -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -ffunction-sections -fdata-sections -Wl,--gc-sections,-Map=XiZi-edu-arm32.map,-cref,-u,Reset_Handler -T $(BSP_ROOT)/link.lds
export CXXFLAGS := -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -ffunction-sections -fdata-sections -Dgcc -O0 -gdwarf-2 -g -Werror
export CXXFLAGS := -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -ffunction-sections -fdata-sections -Dgcc -O0 -Werror
# export CXXFLAGS := -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -ffunction-sections -fdata-sections -Dgcc -O0 -gdwarf-2 -g -Werror
export APPLFLAGS :=
@@ -1,3 +1,3 @@
SRC_FILES := ethernetif.c eth_driver.c
SRC_FILES := ethernetif.c eth_driver.c eth_netdev.c
include $(KERNEL_ROOT)/compiler.mk
@@ -1,21 +1,22 @@
/**
* @file ethernetif.c
* @brief support edu-arm32-board ethernetif function and register to Lwip
* @version 3.0
* @author AIIT XUOS Lab
* @date 2022-12-05
*/
* @file ethernetif.c
* @brief support hc32f4a0-board ethernetif function and register to Lwip
* @version 3.0
* @author AIIT XUOS Lab
* @date 2022-12-05
*/
#include <connect_ethernet.h>
#include <hc32_ll_fcg.h>
#include <hc32_ll_gpio.h>
#include <hc32_ll_utility.h>
#include <hc32_ll_fcg.h>
#include <lwip/timeouts.h>
#include <netif/etharp.h>
#include <sys_arch.h>
void eth_irq_handler(void) {
void eth_irq_handler(void)
{
static x_base eth_irq_lock;
eth_irq_lock = DISABLE_INTERRUPT();
@@ -24,7 +25,7 @@ void eth_irq_handler(void) {
sys_sem_signal(get_eth_recv_sem());
ETH_DMA_ClearStatus(ETH_DMA_FLAG_RIS | ETH_DMA_FLAG_NIS);
}
ENABLE_INTERRUPT(eth_irq_lock);
}
@@ -35,7 +36,7 @@ void eth_irq_handler(void) {
* - LL_OK: Initialize success
* - LL_ERR: Initialize failed
*/
int32_t low_level_init(struct netif *netif)
int32_t low_level_init(struct netif* netif)
{
int32_t i32Ret = LL_ERR;
stc_eth_init_t stcEthInit;
@@ -52,9 +53,9 @@ int32_t low_level_init(struct netif *netif)
(void)ETH_StructInit(&stcEthInit);
#ifdef ETH_INTERFACE_RMII
EthHandle.stcCommInit.u32Interface = ETH_MAC_IF_RMII;
EthHandle.stcCommInit.u32Interface = ETH_MAC_IF_RMII;
#else
EthHandle.stcCommInit.u32Interface = ETH_MAC_IF_MII;
EthHandle.stcCommInit.u32Interface = ETH_MAC_IF_MII;
#endif
// stcEthInit.stcMacInit.u32ReceiveAll = ETH_MAC_RX_ALL_ENABLE;
EthHandle.stcCommInit.u32ReceiveMode = ETH_RX_MD_INT;
@@ -125,7 +126,7 @@ int32_t low_level_init(struct netif *netif)
u16RegVal = PHY_PAGE_ADDR_0;
(void)ETH_PHY_WriteReg(&EthHandle, PHY_PSR, u16RegVal);
#endif
return i32Ret;
}
@@ -137,19 +138,19 @@ int32_t low_level_init(struct netif *netif)
* - LL_OK: The packet could be sent
* - LL_ERR: The packet couldn't be sent
*/
err_t low_level_output(struct netif *netif, struct pbuf *p)
err_t low_level_output(struct netif* netif, struct pbuf* p)
{
err_t i32Ret;
struct pbuf *q;
uint8_t *txBuffer;
__IO stc_eth_dma_desc_t *DmaTxDesc;
struct pbuf* q;
uint8_t* txBuffer;
__IO stc_eth_dma_desc_t* DmaTxDesc;
uint32_t byteCnt;
uint32_t frameLength = 0UL;
uint32_t bufferOffset;
uint32_t payloadOffset;
DmaTxDesc = EthHandle.stcTxDesc;
txBuffer = (uint8_t *)((EthHandle.stcTxDesc)->u32Buf1Addr);
txBuffer = (uint8_t*)((EthHandle.stcTxDesc)->u32Buf1Addr);
bufferOffset = 0UL;
/* Copy frame from pbufs to driver buffers */
for (q = p; q != NULL; q = q->next) {
@@ -165,28 +166,28 @@ err_t low_level_output(struct netif *netif, struct pbuf *p)
/* Check if the length of data to copy is bigger than Tx buffer size */
while ((byteCnt + bufferOffset) > ETH_TX_BUF_SIZE) {
/* Copy data to Tx buffer*/
(void)memcpy((uint8_t *) & (txBuffer[bufferOffset]), (uint8_t *) & (((uint8_t *)q->payload)[payloadOffset]), (ETH_TX_BUF_SIZE - bufferOffset));
(void)memcpy((uint8_t*)&(txBuffer[bufferOffset]), (uint8_t*)&(((uint8_t*)q->payload)[payloadOffset]), (ETH_TX_BUF_SIZE - bufferOffset));
/* Point to next descriptor */
DmaTxDesc = (stc_eth_dma_desc_t *)(DmaTxDesc->u32Buf2NextDescAddr);
DmaTxDesc = (stc_eth_dma_desc_t*)(DmaTxDesc->u32Buf2NextDescAddr);
/* Check if the buffer is available */
if (0UL != (DmaTxDesc->u32ControlStatus & ETH_DMA_TXDESC_OWN)) {
i32Ret = (err_t)ERR_USE;
goto error;
}
txBuffer = (uint8_t *)(DmaTxDesc->u32Buf1Addr);
txBuffer = (uint8_t*)(DmaTxDesc->u32Buf1Addr);
byteCnt = byteCnt - (ETH_TX_BUF_SIZE - bufferOffset);
payloadOffset = payloadOffset + (ETH_TX_BUF_SIZE - bufferOffset);
frameLength = frameLength + (ETH_TX_BUF_SIZE - bufferOffset);
bufferOffset = 0UL;
}
/* Copy the remaining bytes */
(void)memcpy((uint8_t *) & (txBuffer[bufferOffset]), (uint8_t *) & (((uint8_t *)q->payload)[payloadOffset]), byteCnt);
(void)memcpy((uint8_t*)&(txBuffer[bufferOffset]), (uint8_t*)&(((uint8_t*)q->payload)[payloadOffset]), byteCnt);
bufferOffset = bufferOffset + byteCnt;
frameLength = frameLength + byteCnt;
}
/* Prepare transmit descriptors to give to DMA */
if(LL_OK != ETH_DMA_SetTransFrame(&EthHandle, frameLength)) {
if (LL_OK != ETH_DMA_SetTransFrame(&EthHandle, frameLength)) {
KPrintf("[%s] Error sending eth DMA frame\n", __func__);
}
i32Ret = (err_t)ERR_OK;
@@ -208,13 +209,13 @@ error:
* @param netif The network interface structure for this ethernetif.
* @retval A pbuf filled with the received packet (including MAC header) or NULL on memory error.
*/
struct pbuf *low_level_input(struct netif *netif)
struct pbuf* low_level_input(struct netif* netif)
{
struct pbuf *p = NULL;
struct pbuf *q;
struct pbuf* p = NULL;
struct pbuf* q;
uint32_t len;
uint8_t *rxBuffer;
__IO stc_eth_dma_desc_t *DmaRxDesc;
uint8_t* rxBuffer;
__IO stc_eth_dma_desc_t* DmaRxDesc;
uint32_t byteCnt;
uint32_t bufferOffset;
uint32_t payloadOffset;
@@ -227,7 +228,7 @@ struct pbuf *low_level_input(struct netif *netif)
/* Obtain the size of the packet */
len = (EthHandle.stcRxFrame).u32Len;
rxBuffer = (uint8_t *)(EthHandle.stcRxFrame).u32Buf;
rxBuffer = (uint8_t*)(EthHandle.stcRxFrame).u32Buf;
if (len > 0UL) {
/* Allocate a pbuf chain of pbufs from the buffer */
p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL);
@@ -243,17 +244,17 @@ struct pbuf *low_level_input(struct netif *netif)
/* Check if the length of bytes to copy in current pbuf is bigger than Rx buffer size */
while ((byteCnt + bufferOffset) > ETH_RX_BUF_SIZE) {
/* Copy data to pbuf */
(void)memcpy((uint8_t *) & (((uint8_t *)q->payload)[payloadOffset]), (uint8_t *) & (rxBuffer[bufferOffset]), (ETH_RX_BUF_SIZE - bufferOffset));
(void)memcpy((uint8_t*)&(((uint8_t*)q->payload)[payloadOffset]), (uint8_t*)&(rxBuffer[bufferOffset]), (ETH_RX_BUF_SIZE - bufferOffset));
/* Point to next descriptor */
DmaRxDesc = (stc_eth_dma_desc_t *)(DmaRxDesc->u32Buf2NextDescAddr);
rxBuffer = (uint8_t *)(DmaRxDesc->u32Buf1Addr);
DmaRxDesc = (stc_eth_dma_desc_t*)(DmaRxDesc->u32Buf2NextDescAddr);
rxBuffer = (uint8_t*)(DmaRxDesc->u32Buf1Addr);
byteCnt = byteCnt - (ETH_RX_BUF_SIZE - bufferOffset);
payloadOffset = payloadOffset + (ETH_RX_BUF_SIZE - bufferOffset);
bufferOffset = 0UL;
}
/* Copy remaining data in pbuf */
(void)memcpy((uint8_t *) & (((uint8_t *)q->payload)[payloadOffset]), (uint8_t *) & (rxBuffer[bufferOffset]), byteCnt);
(void)memcpy((uint8_t*)&(((uint8_t*)q->payload)[payloadOffset]), (uint8_t*)&(rxBuffer[bufferOffset]), byteCnt);
bufferOffset = bufferOffset + byteCnt;
}
}
@@ -261,7 +262,7 @@ struct pbuf *low_level_input(struct netif *netif)
DmaRxDesc = (EthHandle.stcRxFrame).pstcFSDesc;
for (i = 0UL; i < (EthHandle.stcRxFrame).u32SegCount; i++) {
DmaRxDesc->u32ControlStatus |= ETH_DMA_RXDESC_OWN;
DmaRxDesc = (stc_eth_dma_desc_t *)(DmaRxDesc->u32Buf2NextDescAddr);
DmaRxDesc = (stc_eth_dma_desc_t*)(DmaRxDesc->u32Buf2NextDescAddr);
}
/* Clear Segment_Count */
(EthHandle.stcRxFrame).u32SegCount = 0UL;
@@ -277,11 +278,10 @@ struct pbuf *low_level_input(struct netif *netif)
return p;
}
extern void LwipSetIPTest(int argc, char *argv[]);
int HwEthInit(void) {
// lwip_config_tcp(0, lwip_ipaddr, lwip_netmask, lwip_gwaddr);
LwipSetIPTest(1, NULL);
return EOK;
extern void LwipSetIPTest(int argc, char* argv[]);
int HwEthInit(void)
{
// lwip_config_tcp(0, lwip_ipaddr, lwip_netmask, lwip_gwaddr);
LwipSetIPTest(1, NULL);
return EOK;
}
@@ -0,0 +1,200 @@
/*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*/
/**
* @file eth_netdev.c
* @brief register net dev function for lwip
* @version 3.0
* @author AIIT XUOS Lab
* @date 2023-08-07
*/
#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];
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);
}
@@ -19,21 +19,21 @@
*/
/**
* @file ethernetif.c
* @brief support edu-arm32-board ethernetif function and register to Lwip
* @version 3.0
* @author AIIT XUOS Lab
* @date 2022-12-05
*/
* @file ethernetif.c
* @brief support hc32f4a0-board ethernetif function and register to Lwip
* @version 3.0
* @author AIIT XUOS Lab
* @date 2022-12-05
*/
/*************************************************
File name: ethernetif.c
Description: support edu-arm32-board ethernetif configure and register to Lwip
Others: take projects\ev_hc32f4a0_lqfp176\examples\eth\eth_loopback\source\ethernetif.c for references
History:
History:
1. Date: 2022-12-05
Author: AIIT XUOS Lab
Modification:
Modification:
1、include harware_ethernetif.h、hc32_ll_eth.h、hc32_ll_gpio.h、hc32_ll_utility.h、hc32_ll_fcg.h and lwip H files;
2、modify ethernetif_init as err_t;
3、add ETH_RST_PORT and ETH_RST_PIN;
@@ -47,13 +47,15 @@ Modification:
* Include files
******************************************************************************/
#include <connect_ethernet.h>
#include <hc32_ll_fcg.h>
#include <hc32_ll_gpio.h>
#include <hc32_ll_utility.h>
#include <hc32_ll_fcg.h>
#include <lwip/timeouts.h>
#include <netif/etharp.h>
#include <netdev.h>
#include <xs_isr.h>
#include <xs_kdbg.h>
/**
* @addtogroup HC32F4A0_DDL_Examples
@@ -73,7 +75,6 @@ Modification:
* Local pre-processor symbols/macros ('#define')
******************************************************************************/
/*******************************************************************************
* Global variable definitions (declared in header file with 'extern')
******************************************************************************/
@@ -86,7 +87,6 @@ Modification:
* Local variable definitions ('static')
******************************************************************************/
/*******************************************************************************
* Function implementation - global ('extern') and local ('static')
******************************************************************************/
@@ -180,41 +180,14 @@ void Ethernet_GpioInit(void)
#endif
}
void *ethernetif_config_enet_set(uint8_t enet_port) {
void* ethernetif_config_enet_set(uint8_t enet_port)
{
return NONE;
}
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)
void Time_Update_LwIP(void)
{
#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 */
return low_level_init(netif);
// no need to do
}
/**
@@ -222,16 +195,16 @@ err_t ethernetif_init(struct netif *netif)
* @param netif The network interface structure for this ethernetif.
* @retval None
*/
void ethernetif_input(void *netif_arg)
void ethernetif_input(void* netif_arg)
{
struct pbuf *p;
struct netif *netif = (struct netif *)netif_arg;
struct pbuf* p;
struct netif* netif = (struct netif*)netif_arg;
x_base critical_lock;
/* Move received packet into a new pbuf */
while (1) {
sys_arch_sem_wait(get_eth_recv_sem(), WAITING_FOREVER);
while(1) {
while (1) {
p = low_level_input(netif);
#ifndef ETHERNET_LOOPBACK_TEST
/* Entry point to the LwIP stack */
@@ -256,12 +229,51 @@ 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
* @retval None
*/
void EthernetIF_CheckLink(struct netif *netif)
void EthernetIF_CheckLink(struct netif* netif)
{
uint16_t u16RegVal = 0U;
static uint8_t u8PreStatus = 0U;
@@ -296,7 +308,7 @@ void EthernetIF_CheckLink(struct netif *netif)
* @param netif The network interface.
* @retval None
*/
void EthernetIF_UpdateLink(struct netif *netif)
void EthernetIF_UpdateLink(struct netif* netif)
{
uint16_t u16RegVal;
@@ -337,7 +349,7 @@ void EthernetIF_UpdateLink(struct netif *netif)
* @param netif The network interface
* @retval None
*/
void EthernetIF_PeriodicHandle(struct netif *netif)
void EthernetIF_PeriodicHandle(struct netif* netif)
{
#ifndef ETH_INTERFACE_RMII
uint32_t curTick;
@@ -358,7 +370,7 @@ void EthernetIF_PeriodicHandle(struct netif *netif)
* @param netif The network interface
* @retval None
*/
void EthernetIF_LinkCallback(struct netif *netif)
void EthernetIF_LinkCallback(struct netif* netif)
{
__IO uint32_t tickStart = 0UL;
uint16_t u16RegVal = 0U;
@@ -405,8 +417,7 @@ void EthernetIF_LinkCallback(struct netif *netif)
CLR_REG16_BIT(u16RegVal, PHY_FULLDUPLEX_100M);
/* Set MAC Speed and Duplex Mode to PHY */
(void)ETH_PHY_WriteReg(&EthHandle, PHY_BCR,
((uint16_t)((EthHandle.stcCommInit).u32DuplexMode >> 3U) |
(uint16_t)((EthHandle.stcCommInit).u32Speed >> 1U) | u16RegVal));
((uint16_t)((EthHandle.stcCommInit).u32DuplexMode >> 3U) | (uint16_t)((EthHandle.stcCommInit).u32Speed >> 1U) | u16RegVal));
}
/* ETH MAC Re-Configuration */
ETH_MAC_SetDuplexSpeed((EthHandle.stcCommInit).u32DuplexMode, (EthHandle.stcCommInit).u32Speed);
@@ -427,7 +438,7 @@ void EthernetIF_LinkCallback(struct netif *netif)
* - LL_OK: The IF is link up
* - LL_ERR: The IF is link down
*/
int32_t EthernetIF_IsLinkUp(struct netif *netif)
int32_t EthernetIF_IsLinkUp(struct netif* netif)
{
return (0U != u8PhyLinkStatus) ? LL_OK : LL_ERR;
}
@@ -437,14 +448,14 @@ int32_t EthernetIF_IsLinkUp(struct netif *netif)
* @param netif The network interface
* @retval None
*/
__WEAKDEF void EthernetIF_NotifyLinkChange(struct netif *netif)
__WEAKDEF void EthernetIF_NotifyLinkChange(struct netif* netif)
{
/* This is function could be implemented in user file when the callback is needed */
if (LL_OK == EthernetIF_IsLinkUp(netif)) {
GPIO_SetPins(ETH_LINK_LED_PORT, ETH_LINK_LED_PIN);
} else {
GPIO_ResetPins(ETH_LINK_LED_PORT, ETH_LINK_LED_PIN);
}
}
}
/**
@@ -453,7 +464,8 @@ __WEAKDEF void EthernetIF_NotifyLinkChange(struct netif *netif)
* @param p The MAC packet to receive
* @retval None
*/
__WEAKDEF void EthernetIF_InputCallback(struct netif *netif, struct pbuf *p) {
__WEAKDEF void EthernetIF_InputCallback(struct netif* netif, struct pbuf* p)
{
/* This is function could be implemented in user file when the callback is needed */
#ifdef ETHERNET_LOOPBACK_TEST
if ((0 == (memcmp(p->payload, txPbuf.payload, p->len))) && (p->len == txPbuf.len)) {
@@ -479,7 +491,7 @@ __WEAKDEF void EthernetIF_InputCallback(struct netif *netif, struct pbuf *p) {
#ifdef ETHERNET_LOOPBACK_TEST
static void EthLoopBackTask(void *parameter)
static void EthLoopBackTask(void* parameter)
{
while (1) {
if (RESET == GPIO_ReadInputPins(USER_KEY_PORT, USER_KEY_PIN)) {
@@ -489,7 +501,7 @@ static void EthLoopBackTask(void *parameter)
}
}
//KPrintf("ready to receive eth loop back data\n");
// KPrintf("ready to receive eth loop back data\n");
/* Read a received packet */
ethernetif_input(&testnetif);
/* Handle periodic timers */
@@ -514,24 +526,24 @@ static void EthLoopBackTest(void)
(void)ethernetif_init(&testnetif);
/* fill data to txPbuf */
txPbuf.next = NULL;
txPbuf.next = NULL;
txPbuf.payload = txBuf;
txPbuf.len = strlen(txBuf);
txPbuf.len = strlen(txBuf);
int eth_loopback_task = 0;
eth_loopback_task = KTaskCreate("eth_loopback", EthLoopBackTask, NONE,
2048, 8);
if(eth_loopback_task < 0) {
KPrintf("eth_loopback_task create failed ...%s %d.\n", __FUNCTION__,__LINE__);
return;
}
2048, 8);
if (eth_loopback_task < 0) {
KPrintf("eth_loopback_task create failed ...%s %d.\n", __FUNCTION__, __LINE__);
return;
}
StartupKTask(eth_loopback_task);
return;
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
EthLoopBackTest, EthLoopBackTest, EthLoopBackTest);
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
EthLoopBackTest, EthLoopBackTest, EthLoopBackTest);
#endif
@@ -1,40 +1,39 @@
/*
* Copyright (c) 2021 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
* Copyright (c) 2021 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file connect_ethernet.h
* @brief Adapted network software protocol stack and hardware operation functions
* @version 2.0
* @author AIIT XUOS Lab
* @date 2022-12-05
*/
* @file connect_ethernet.h
* @brief Adapted network software protocol stack and hardware operation functions
* @version 2.0
* @author AIIT XUOS Lab
* @date 2022-12-05
*/
#ifndef CONNECT_ETHERNET_H
#define CONNECT_ETHERNET_H
#include "hardware_ethernetif.h"
#include <sys_arch.h>
#include <hc32_ll_eth.h>
#include <hardware_irq.h>
#include <hc32_ll_eth.h>
#include <sys_arch.h>
#ifdef __cplusplus
extern "C" {
extern "C" {
#endif
struct hc32_irq_config
{
IRQn_Type irq_num;
uint32_t irq_prio;
en_int_src_t int_src;
struct hc32_irq_config {
IRQn_Type irq_num;
uint32_t irq_prio;
en_int_src_t int_src;
};
/* Global Ethernet handle*/
@@ -52,22 +51,23 @@ __ALIGN_BEGIN static uint8_t EthRxBuff[ETH_RX_BUF_NUM][ETH_RX_BUF_SIZE];
static uint8_t u8PhyLinkStatus = 0U, u8EthInitStatus = 0U;
static struct Hc32IrqConfig eth_irq_config = {
.irq_num = BSP_ETH_IRQ_NUM,
.irq_prio = BSP_ETH_IRQ_PRIO,
.int_src = INT_SRC_ETH_GLB_INT,
.irq_num = BSP_ETH_IRQ_NUM,
.irq_prio = BSP_ETH_IRQ_PRIO,
.int_src = INT_SRC_ETH_GLB_INT,
};
void Ethernet_GpioInit(void);
int32_t low_level_init(struct netif *netif);
err_t low_level_output(struct netif *netif, struct pbuf *p);
struct pbuf *low_level_input(struct netif *netif);
int32_t low_level_init(struct netif* netif);
err_t low_level_output(struct netif* netif, struct pbuf* p);
struct pbuf* low_level_input(struct netif* netif);
int lwip_netdev_add(struct netif* lwip_netif);
void lwip_netdev_del(struct netif* lwip_netif);
int HwEthInit(void);
#ifdef __cplusplus
}
#endif
#endif
@@ -1,3 +1,3 @@
SRC_FILES := enet_ethernetif.c enet_ethernetif_kinetis.c fsl_enet.c fsl_enet_qos.c
SRC_FILES := enet_ethernetif.c enet_ethernetif_kinetis.c fsl_enet.c fsl_enet_qos.c eth_netdev.c
SRC_DIR := phy mdio
include $(KERNEL_ROOT)/compiler.mk
@@ -353,5 +353,11 @@ err_t ethernetif_init(struct netif *netif,
}
#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;
}
@@ -0,0 +1,201 @@
/*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*/
/**
* @file eth_netdev.c
* @brief register net dev function for lwip
* @version 3.0
* @author AIIT XUOS Lab
* @date 2023-08-07
*/
#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);
}
@@ -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
}
@@ -164,6 +164,9 @@ void ethernetif_input( void *netif_arg);
int ETH_BSP_Config(void);
void *ethernetif_config_enet_set(uint8_t enet_port);
int lwip_netdev_add(struct netif* lwip_netif);
void lwip_netdev_del(struct netif* lwip_netif);
#if defined(__cplusplus)
}
#endif /* __cplusplus */
@@ -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 := ksz8081
include $(KERNEL_ROOT)/compiler.mk
@@ -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;
}
@@ -0,0 +1,201 @@
/*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*/
/**
* @file eth_netdev.c
* @brief register net dev function for lwip
* @version 3.0
* @author AIIT XUOS Lab
* @date 2023-08-07
*/
#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);
}
@@ -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
}
@@ -181,11 +181,14 @@ err_t ethernetif1_init(struct netif *netif);
*/
void ethernetif_input( void *netif_arg);
void ETH_BSP_Config(void);
int ETH_BSP_Config(void);
void *ethernetif_config_enet_set(uint8_t enet_port);
int32 lwip_obtain_semaphore(struct netif *netif);
int lwip_netdev_add(struct netif* lwip_netif);
void lwip_netdev_del(struct netif* lwip_netif);
#define NETIF_ENET0_INIT_FUNC ethernetif0_init
#if defined(__cplusplus)
@@ -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
@@ -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;
}
@@ -0,0 +1,201 @@
/*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*/
/**
* @file eth_netdev.c
* @brief register net dev function for lwip
* @version 3.0
* @author AIIT XUOS Lab
* @date 2023-08-07
*/
#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);
}
@@ -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
}
@@ -185,6 +185,9 @@ int ETH_BSP_Config(void);
void *ethernetif_config_enet_set(uint8_t enet_port);
int32 lwip_obtain_semaphore(struct netif *netif);
int lwip_netdev_add(struct netif* lwip_netif);
void lwip_netdev_del(struct netif* lwip_netif);
#define NETIF_ENET0_INIT_FUNC ethernetif0_init
#if defined(__cplusplus)
@@ -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
@@ -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;
}
@@ -0,0 +1,201 @@
/*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*/
/**
* @file eth_netdev.c
* @brief register net dev function for lwip
* @version 3.0
* @author AIIT XUOS Lab
* @date 2023-08-07
*/
#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);
}
@@ -1,22 +1,22 @@
/*
* Copyright (c) 2021 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
* Copyright (c) 2021 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file connect_ethernet.h
* @brief Adapted network software protocol stack and hardware operation functions
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021-12-7
*/
* @file connect_ethernet.h
* @brief Adapted network software protocol stack and hardware operation functions
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021-12-7
*/
#ifndef __CONNECT_ETHERNET_H_
#define __CONNECT_ETHERNET_H_
@@ -25,17 +25,18 @@
#include "enet_ethernetif_priv.h"
#ifdef __cplusplus
extern "C" {
extern "C" {
#endif
#ifndef sourceClock
#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
}
#endif
#endif
@@ -185,6 +185,9 @@ int ETH_BSP_Config(void);
void *ethernetif_config_enet_set(uint8_t enet_port);
int32 lwip_obtain_semaphore(struct netif *netif);
int lwip_netdev_add(struct netif* lwip_netif);
void lwip_netdev_del(struct netif* lwip_netif);
#define NETIF_ENET0_INIT_FUNC ethernetif0_init
#if defined(__cplusplus)