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 "gmac.h"
#include "ethernet_phy.h"
#include "netif/ethernetif.h"
#include "sysclk.h"
#include <string.h>
#include "conf_eth.h"
#include "ioport.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 | ioport_set_pin_peripheral_mode(pin, mode) |
Set peripheral mode for one single IOPORT pin. More... | |
#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... | |
Functions | |
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... | |
void | GMAC_Handler (void) |
GMAC interrupt handler. 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 gmac_device_t | gs_gmac_dev |
The GMAC 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 ioport_set_pin_peripheral_mode | ( | pin, | |
mode | |||
) |
Set peripheral mode for one single IOPORT pin.
It will configure port mode and disable pin mode (but enable peripheral).
pin | IOPORT pin to configure |
mode | Mode masks to configure for the specified pin (IOPORT Modes) |
Referenced by low_level_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().
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, 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.
void ethernetif_input | ( | void * | pvParameters | ) |
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().
void GMAC_Handler | ( | void | ) |
GMAC interrupt handler.
References gmac_handler().
|
static |
In this function, the hardware should be initialized.
Called from ethernetif_init().
netif | the already initialized lwip network interface structure for this ethernetif |
References ethernet_phy_auto_negotiate(), ethernet_phy_init(), ethernet_phy_set_link(), ethernetif_input(), netif::flags, gmac_dev_init(), GMAC_OK, gs_uc_mac_address, netif::hwaddr, netif::hwaddr_len, IOPORT_DIR_INPUT, ioport_set_pin_dir(), ioport_set_pin_peripheral_mode, LWIP_DBG_TRACE, LWIP_DEBUGF, netif::mtu, NET_MTU, NETIF_FLAG_BROADCAST, NETIF_FLAG_DHCP, NETIF_FLAG_ETHARP, NULL, gmac_device::p_hw, pmc_enable_periph_clk(), sys_thread_new(), sysclk_get_cpu_hz(), tskIDLE_PRIORITY, gmac_options::uc_copy_all_frame, gmac_options::uc_mac_addr, gmac_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 ETH_PAD_SIZE, gmac_dev_read(), GMAC_OK, 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 ERR_BUF, ERR_OK, ETH_PAD_SIZE, gmac_dev_write(), GMAC_OK, 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 GMAC driver instance.
|
static |
The MAC address used for the test.
Referenced by low_level_init().