Microchip® Advanced Software Framework

lwip-port-1.3.2/sam/netif/ethernetif.c File Reference

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

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 pbuflow_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().

void EMAC_Handler ( void  )

EMAC interrupt handler.

References emac_handler().

err_t ethernetif_init ( struct netif netif)

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().

Parameters
netifthe lwip network interface structure for this ethernetif.
Returns
ERR_OK if the loopif is initialized ERR_MEM if private data couldn't be allocated any other err_t on error.

Referenced by ethernet_configure_interface().

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.

Parameters
pv_parametersthe lwip network interface structure for this ethernetif.

Referenced by ethernet_task(), and low_level_init().

static struct pbuf* low_level_input ( struct netif netif)
static

Should allocate a pbuf and transfer the bytes of the incoming packet from the interface into the pbuf.

Parameters
netifthe lwip network interface structure for this ethernetif.
Returns
a pbuf filled with the received packet (including MAC header) NULL on memory error.

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().

static err_t low_level_output ( struct netif netif,
struct pbuf p 
)
static

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).

Parameters
netifthe lwip network interface structure for this ethernetif
pthe MAC packet to send (e.g. IP packet including MAC addresses and type)
Returns
ERR_OK if the packet could be sent an err_t value if the packet couldn't be sent.

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().

emac_device_t gs_emac_dev
static

The EMAC driver instance.

uint8_t gs_uc_mac_address[]
static
Initial value:
=
{ ETHERNET_CONF_ETHADDR0, ETHERNET_CONF_ETHADDR1, ETHERNET_CONF_ETHADDR2,
ETHERNET_CONF_ETHADDR3, ETHERNET_CONF_ETHADDR4, ETHERNET_CONF_ETHADDR5}

The MAC address used for the test.

Referenced by low_level_init().