Microchip® Advanced Software Framework

ethernetif.c File Reference
#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 "conf_eth.h"
#include "macb.h"

Data Structures

struct  ethernetif
 Helper struct to hold private data used to operate your ethernet interface. More...
 

Macros

#define IFNAME0   'e'
 
#define IFNAME1   'n'
 
#define netifGUARD_BLOCK_NBTICKS   ( 250 )
 

Functions

err_t ethernetif_init (struct netif *netif)
 Should be called at the beginning of the program to set up the network interface. More...
 
static 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

unsigned char cMACAddress [6]
 

#define IFNAME0   'e'

Referenced by ethernetif_init().

#define IFNAME1   'n'

Referenced by ethernetif_init().

#define netifGUARD_BLOCK_NBTICKS   ( 250 )

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

References ERR_OK, etharp_output(), IFNAME0, IFNAME1, netif::linkoutput, low_level_init(), low_level_output(), LWIP_ASSERT, netif::name, NETIF_INIT_SNMP, NULL, netif::output, snmp_ifType_ethernet_csmacd, and netif::state.

Referenced by prvEthernetConfigureInterface().

static void ethernetif_input ( void pvParameters)
static

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
netifthe lwip network interface structure for this ethernetif

References ERR_OK, netif::input, low_level_input(), NULL, pbuf_free(), and vMACBWaitForInput().

Referenced by low_level_init().

static void low_level_init ( struct netif netif)
static

In this function, the hardware should be initialized.

Called from ethernetif_init().

Parameters
netifthe already initialized lwip network interface structure for this ethernetif

References cMACAddress, ETHARP_HWADDR_LEN, ethernetif_input(), netif::flags, netif::hwaddr, netif::hwaddr_len, netif::mtu, NETIF_FLAG_BROADCAST, NETIF_FLAG_DHCP, NETIF_FLAG_ETHARP, netifINTERFACE_TASK_PRIORITY, netifINTERFACE_TASK_STACK_SIZE, NULL, sys_thread_new(), tskIDLE_PRIORITY, uxTaskPriorityGet(), vTaskPrioritySet(), and xMACBInit().

Referenced by ethernetif_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 ETH_PAD_SIZE, pbuf::len, LINK_STATS_INC, netifGUARD_BLOCK_NBTICKS, pbuf::next, NULL, pbuf::payload, pbuf_alloc(), pbuf_header(), PBUF_POOL, PBUF_RAW, ulMACBInputLength(), vMACBRead(), void, vSemaphoreCreateBinary, xSemaphoreGive, and xSemaphoreTake.

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.

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

References ERR_OK, ETH_PAD_SIZE, pbuf::len, LINK_STATS_INC, lMACBSend(), netifGUARD_BLOCK_NBTICKS, pbuf::next, NULL, pbuf::payload, pbuf_header(), void, vSemaphoreCreateBinary, xSemaphoreGive, and xSemaphoreTake.

Referenced by ethernetif_init().

unsigned char cMACAddress[6]

Referenced by low_level_init().