23/07/27 1.Add netdev module and for edu-arm32, fit Lwip to it; 2.Fit Webnet to edu-arm32;

This commit is contained in:
涂煜洋
2023-07-27 15:05:50 +08:00
parent 1a6ee0234b
commit 0307fb2671
29 changed files with 1884 additions and 627 deletions
@@ -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,162 @@
#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,12 +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
void Time_Update_LwIP(void)
{
// no need to do
}
/**
@@ -195,7 +197,7 @@ void Time_Update_LwIP(void) {
* - LL_OK: The IF is initialized
* - LL_ERR: The IF is uninitialized
*/
err_t ethernetif_init(struct netif *netif)
err_t ethernetif_init(struct netif* netif)
{
#if LWIP_NETIF_HOSTNAME
/* Initialize interface hostname */
@@ -206,15 +208,24 @@ err_t ethernetif_init(struct netif *netif)
#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...) */
* 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);
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;
}
/**
@@ -222,16 +233,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 */
@@ -261,7 +272,7 @@ void ethernetif_input(void *netif_arg)
* @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 +307,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 +348,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 +369,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 +416,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 +437,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 +447,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 +463,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 +490,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 +500,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 +525,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,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,15 @@
#include "enet_ethernetif_priv.h"
#ifdef __cplusplus
extern "C" {
extern "C" {
#endif
#ifndef sourceClock
#define sourceClock CLOCK_GetFreq(kCLOCK_CoreSysClk)
#endif
#ifdef __cplusplus
}
#endif
#endif