Microchip® Advanced Software Framework

same70_gmac.c File Reference

GMAC (Gigabit MAC) driver for lwIP.

Copyright (c) 2015-2018 Microchip Technology Inc. and its subsidiaries.

#include "lwip/opt.h"
#include "lwip/sys.h"
#include "lwip/def.h"
#include "lwip/mem.h"
#include "lwip/pbuf.h"
#include "lwip/stats.h"
#include "lwip/snmp.h"
#include "netif/etharp.h"
#include "netif/ppp_oe.h"
#include <string.h>
#include "pmc.h"
#include "ethernet_phy.h"
#include "netif/same70_gmac.h"
#include "sysclk.h"
#include "conf_eth.h"

Data Structures

struct  gmac_device
 GMAC driver structure. More...
 

Macros

#define GMAC_INT_GROUP   0
 
#define GMAC_RX_ERRORS   0
 
#define GMAC_TX_ERRORS   0
 
#define IFNAME0   'e'
 Network interface identifier. More...
 
#define IFNAME1   'n'
 
#define INT_PRIORITY_GMAC   0
 
#define NET_LINK_SPEED   100000000
 Network link speed. More...
 
#define NET_MTU   1500
 Maximum transfer unit. 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 (struct netif *netif)
 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 gmac_low_level_init (struct netif *netif)
 Initialize GMAC and PHY. More...
 
static struct pbufgmac_low_level_input (struct netif *netif)
 Use pre-allocated pbuf as DMA source and return the incoming packet. More...
 
static err_t gmac_low_level_output (struct netif *netif, struct pbuf *p)
 This function should do the actual transmission of the packet. More...
 
static void gmac_rx_init (struct gmac_device *ps_gmac_dev)
 Set up the RX descriptor ring buffers. More...
 
static void gmac_rx_populate_queue (struct gmac_device *p_gmac_dev)
 Populate the RX descriptor ring buffers with pbufs. More...
 
static void gmac_tx_init (struct gmac_device *ps_gmac_dev)
 Set up the TX descriptor ring buffers. More...
 

Variables

static struct gmac_device gs_gmac_dev
 GMAC driver instance. More...
 
static gmac_rx_descriptor_t gs_rx_desc_null
 RX descriptors lists. More...
 
static gmac_tx_descriptor_t gs_tx_desc_null
 TX descriptor lists. More...
 
static uint8_t gs_uc_mac_address []
 MAC address to use. More...
 

#define GMAC_INT_GROUP   0
#define GMAC_RX_ERRORS   0

Referenced by gmac_low_level_input().

#define GMAC_TX_ERRORS   0

Referenced by gmac_low_level_output().

#define IFNAME0   'e'

Network interface identifier.

Referenced by ethernetif_init().

#define IFNAME1   'n'

Referenced by ethernetif_init().

#define INT_PRIORITY_GMAC   0

Referenced by gmac_low_level_init().

#define NET_LINK_SPEED   100000000

Network link speed.

Referenced by ethernetif_init().

#define NET_MTU   1500

Maximum transfer unit.

Referenced by gmac_low_level_init().

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 gmac_low_level_init() to do the actual setup of the hardware.

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_MEM, ERR_OK, etharp_output(), gmac_low_level_init(), gmac_low_level_output(), gs_gmac_dev, IFNAME0, IFNAME1, netif::linkoutput, LWIP_ASSERT, netif::name, NET_LINK_SPEED, gmac_device::netif, NETIF_INIT_SNMP, netifINTERFACE_TASK_PRIORITY, netifINTERFACE_TASK_STACK_SIZE, NULL, netif::output, snmp_ifType_ethernet_csmacd, netif::state, and sys_thread_new.

Referenced by ethernet_configure_interface().

void ethernetif_input ( struct netif netif)

This function should be called when a packet is ready to be read from the interface.

It uses the function gmac_low_level_input() that handles 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, ETHTYPE_ARP, ETHTYPE_IP, ETHTYPE_PPPOE, ETHTYPE_PPPOEDISC, gmac_low_level_input(), htons, netif::input, LWIP_DEBUGF, NETIF_DEBUG, NULL, pbuf::payload, and pbuf_free().

Referenced by ethernet_task().

void GMAC_Handler ( void  )

GMAC interrupt handler.

References gmac_get_interrupt_status(), GMAC_INT_GROUP, and gs_gmac_dev.

static struct pbuf* gmac_low_level_input ( struct netif netif)
static

Use pre-allocated pbuf as DMA source and return the incoming packet.

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

References gmac_rx_descriptor::addr, gmac_clear_rx_status(), gmac_enable_receive(), gmac_get_rx_status(), GMAC_RX_BUFFERS, GMAC_RX_ERRORS, gmac_rx_init(), gmac_rx_populate_queue(), GMAC_RXD_LEN_MASK, GMAC_RXD_OWNERSHIP, pbuf::len, LINK_STATS_INC, LWIP_DEBUGF, NETIF_DEBUG, pbuf_free(), gmac_device::rx_desc, gmac_device::rx_pbuf, netif::state, gmac_rx_descriptor::status, pbuf::tot_len, gmac_device::us_rx_idx, gmac_rx_descriptor::gmac_rx_addr::val, and gmac_rx_descriptor::gmac_rx_status::val.

Referenced by ethernetif_input().

static err_t gmac_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.

References gmac_tx_descriptor::addr, gmac_tx_descriptor::gmac_tx_status::gmac_tx_status_bm::b_len, gmac_tx_descriptor::gmac_tx_status::gmac_tx_status_bm::b_used, gmac_tx_descriptor::gmac_tx_status::bm, ERR_OK, gmac_clear_tx_status(), gmac_enable_transmit(), gmac_get_tx_status(), gmac_start_transmission(), GMAC_TX_BUFFERS, GMAC_TX_ERRORS, gmac_tx_init(), pbuf::len, LINK_STATS_INC, LWIP_DEBUGF, NETIF_DEBUG, pbuf::next, NULL, pbuf::payload, netif::state, gmac_tx_descriptor::status, pbuf::tot_len, gmac_device::tx_desc, and gmac_device::us_tx_idx.

Referenced by ethernetif_init().

static void gmac_rx_init ( struct gmac_device ps_gmac_dev)
static

Set up the RX descriptor ring buffers.

This function sets up the descriptor list used for receive packets.

Parameters
ps_gmac_devPointer to driver data structure.

References gmac_rx_descriptor::addr, GMAC_RX_BUFFERS, gmac_rx_populate_queue(), GMAC_RXD_WRAP, gmac_set_rx_queue(), gmac_device::rx_desc, gmac_device::rx_pbuf, gmac_rx_descriptor::status, gmac_device::us_rx_idx, gmac_rx_descriptor::gmac_rx_addr::val, and gmac_rx_descriptor::gmac_rx_status::val.

Referenced by gmac_low_level_init(), and gmac_low_level_input().

static void gmac_rx_populate_queue ( struct gmac_device p_gmac_dev)
static

Populate the RX descriptor ring buffers with pbufs.

Note
Make sure that the p->payload pointer is 32 bits aligned. (since the lsb are used as status bits by GMAC).
Parameters
p_gmac_devPointer to driver data structure.

References gmac_rx_descriptor::addr, GMAC_FRAME_LENTGH_MAX, GMAC_RX_BUFFERS, GMAC_RXD_WRAP, LWIP_ASSERT, LWIP_DEBUGF, NETIF_DEBUG, NULL, pbuf::payload, pbuf_alloc(), pbuf_clen(), PBUF_POOL, PBUF_RAW, gmac_device::rx_desc, gmac_device::rx_pbuf, gmac_rx_descriptor::status, gmac_rx_descriptor::gmac_rx_addr::val, and gmac_rx_descriptor::gmac_rx_status::val.

Referenced by gmac_low_level_input(), and gmac_rx_init().

static void gmac_tx_init ( struct gmac_device ps_gmac_dev)
static

Set up the TX descriptor ring buffers.

This function sets up the descriptor list used for receive packets.

Parameters
ps_gmac_devPointer to driver data structure.

References gmac_tx_descriptor::addr, gmac_set_tx_queue(), GMAC_TX_BUFFERS, GMAC_TXD_LAST, GMAC_TXD_USED, GMAC_TXD_WRAP, gmac_tx_descriptor::status, gmac_device::tx_buf, gmac_device::tx_desc, gmac_device::us_tx_idx, and gmac_tx_descriptor::gmac_tx_status::val.

Referenced by gmac_low_level_init(), and gmac_low_level_output().

struct gmac_device gs_gmac_dev
static

GMAC driver instance.

Referenced by ethernetif_init(), GMAC_Handler(), and gmac_low_level_init().

gmac_rx_descriptor_t gs_rx_desc_null
static

RX descriptors lists.

Referenced by gmac_low_level_init().

gmac_tx_descriptor_t gs_tx_desc_null
static

TX descriptor lists.

Referenced by gmac_low_level_init().

uint8_t gs_uc_mac_address[]
static
Initial value:
=
{
}
#define ETHERNET_CONF_ETHADDR2
Definition: conf_eth.h:58
#define ETHERNET_CONF_ETHADDR0
MAC address definition.
Definition: conf_eth.h:56
#define ETHERNET_CONF_ETHADDR4
Definition: conf_eth.h:60
#define ETHERNET_CONF_ETHADDR5
Definition: conf_eth.h:61
#define ETHERNET_CONF_ETHADDR1
Definition: conf_eth.h:57
#define ETHERNET_CONF_ETHADDR3
Definition: conf_eth.h:59

MAC address to use.

Referenced by gmac_low_level_init().