This file is a skeleton for developing Ethernet network interface drivers for lwIP.
Add code to the low_level functions and do a search-and-replace for the word "ethernetif" to replace it with something that better describes your network interface.
Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries.
#include "lwip/opt.h"
#include "lwip/def.h"
#include "lwip/mem.h"
#include "lwip/pbuf.h"
#include "lwip/sys.h"
#include <lwip/stats.h>
#include <lwip/snmp.h>
#include "netif/etharp.h"
#include "netif/ppp_oe.h"
#include "pmc.h"
#include "emac.h"
#include "rstc.h"
#include "ethernet_phy.h"
#include "netif/ethernetif.h"
#include "sysclk.h"
#include <string.h>
#include "conf_eth.h"
#include "gpio.h"
Data Structures | |
struct | ethernetif |
Helper struct to hold private data used to operate your ethernet interface. More... | |
Macros | |
#define | IFNAME0 'e' |
Define those to better describe your network interface. More... | |
#define | IFNAME1 'n' |
#define | NET_LINK_SPEED 100000000 |
Network link speed. More... | |
#define | NET_MTU 1500 |
Maximum transfer unit. More... | |
#define | NET_RW_BUFF_SIZE 1536 |
Read/write buffer size for lwIP. More... | |
#define | netifGUARD_BLOCK_NBTICKS (250) |
Functions | |
void | EMAC_Handler (void) |
EMAC interrupt handler. More... | |
err_t | ethernetif_init (struct netif *netif) |
Should be called at the beginning of the program to set up the network interface. More... | |
void | ethernetif_input (void *pvParameters) |
This function should be called when a packet is ready to be read from the interface. More... | |
static void | low_level_init (struct netif *netif) |
In this function, the hardware should be initialized. More... | |
static struct pbuf * | low_level_input (struct netif *netif) |
Should allocate a pbuf and transfer the bytes of the incoming packet from the interface into the pbuf. More... | |
static err_t | low_level_output (struct netif *netif, struct pbuf *p) |
This function should do the actual transmission of the packet. More... | |
Variables | |
static emac_device_t | gs_emac_dev |
The EMAC driver instance. More... | |
static uint8_t | gs_uc_mac_address [] |
The MAC address used for the test. More... | |
#define IFNAME0 'e' |
Define those to better describe your network interface.
Referenced by ethernetif_init().
#define IFNAME1 'n' |
Referenced by ethernetif_init().
#define NET_LINK_SPEED 100000000 |
Network link speed.
Referenced by ethernetif_init().
#define NET_MTU 1500 |
Maximum transfer unit.
Referenced by low_level_init().
#define NET_RW_BUFF_SIZE 1536 |
Read/write buffer size for lwIP.
Referenced by low_level_input(), and low_level_output().
#define netifGUARD_BLOCK_NBTICKS (250) |
EMAC interrupt handler.
References emac_handler().
Should be called at the beginning of the program to set up the network interface.
It calls the function low_level_init() to do the actual setup of the hardware.
This function should be passed as a parameter to netif_add().
netif | the lwip network interface structure for this ethernetif. |
References ERR_OK, etharp_output(), IFNAME0, IFNAME1, netif::linkoutput, low_level_init(), low_level_output(), LWIP_ASSERT, netif::name, NET_LINK_SPEED, NETIF_INIT_SNMP, NULL, netif::output, snmp_ifType_ethernet_csmacd, and netif::state.
Referenced by ethernet_configure_interface().
This function should be called when a packet is ready to be read from the interface.
It uses the function low_level_input() that should handle the actual reception of bytes from the network interface. Then the type of the received packet is determined and the appropriate input function is called.
pv_parameters | the lwip network interface structure for this ethernetif. |
References ERR_OK, netif::input, low_level_input(), NULL, pbuf_free(), and vTaskDelay().
Referenced by low_level_init().
In this function, the hardware should be initialized.
Called from ethernetif_init().
netif | the already initialized lwip network interface structure for this ethernetif |
References BOARD_EMAC_PHY_ADDR, emac_dev_init(), EMAC_OK, ethernet_phy_auto_negotiate(), ethernet_phy_init(), ethernet_phy_set_link(), ethernetif_input(), netif::flags, gpio_configure_pin, gs_uc_mac_address, netif::hwaddr, netif::hwaddr_len, LWIP_DBG_TRACE, LWIP_DEBUGF, netif::mtu, NET_MTU, NETIF_FLAG_BROADCAST, NETIF_FLAG_DHCP, NETIF_FLAG_ETHARP, netifINTERFACE_TASK_PRIORITY, netifINTERFACE_TASK_STACK_SIZE, NULL, emac_device::p_hw, PIN_EEMAC_EREFCK, PIN_EMAC_ECRSDV, PIN_EMAC_EMDC, PIN_EMAC_EMDIO, PIN_EMAC_ERX0, PIN_EMAC_ERX1, PIN_EMAC_ERXER, PIN_EMAC_ETX0, PIN_EMAC_ETX1, PIN_EMAC_ETXEN, PIN_EMAC_FLAGS, pmc_enable_periph_clk(), rstc_get_status(), rstc_reset_extern(), rstc_set_external_reset(), sys_thread_new(), sysclk_get_cpu_hz(), tskIDLE_PRIORITY, emac_options::uc_copy_all_frame, emac_options::uc_mac_addr, emac_options::uc_no_boardcast, uxTaskPriorityGet(), and vTaskPrioritySet().
Referenced by ethernetif_init().
Should allocate a pbuf and transfer the bytes of the incoming packet from the interface into the pbuf.
netif | the lwip network interface structure for this ethernetif. |
References emac_dev_read(), EMAC_OK, ETH_PAD_SIZE, LINK_STATS_INC, NET_RW_BUFF_SIZE, NULL, pbuf_alloc(), pbuf_header(), PBUF_POOL, and PBUF_RAW.
Referenced by ethernetif_input().
This function should do the actual transmission of the packet.
The packet is contained in the pbuf that is passed to the function. This pbuf might be chained. note: Returning ERR_MEM here if a DMA queue of your MAC is full can lead to strange results. You might consider waiting for space in the DMA queue to become available since the stack doesn't retry to send a packet dropped because of memory failure (except for the TCP timers).
netif | the lwip network interface structure for this ethernetif |
p | the MAC packet to send (e.g. IP packet including MAC addresses and type) |
References emac_dev_write(), EMAC_OK, ERR_BUF, ERR_OK, ETH_PAD_SIZE, pbuf::len, LINK_STATS_INC, NET_RW_BUFF_SIZE, pbuf::next, NULL, pbuf::payload, pbuf_header(), and pbuf::tot_len.
Referenced by ethernetif_init().
|
static |
The EMAC driver instance.
|
static |
The MAC address used for the test.
Referenced by low_level_init().