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 pbuf * | gmac_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 |
Referenced by GMAC_Handler(), and gmac_low_level_init().
#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().
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.
netif | the lwIP network interface structure for this ethernetif. |
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().
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.
netif | the 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().
GMAC interrupt handler.
References gmac_get_interrupt_status(), GMAC_INT_GROUP, and gs_gmac_dev.
Initialize GMAC and PHY.
netif | the lwIP network interface structure for this ethernetif. |
References gmac_rx_descriptor::addr, gmac_tx_descriptor::addr, BOARD_GMAC_PHY_ADDR, ethernet_phy_auto_negotiate(), ethernet_phy_init(), ethernet_phy_set_link(), netif::flags, gmac_clear_rx_status(), gmac_clear_statistics(), gmac_clear_tx_status(), gmac_disable_broadcast(), gmac_disable_interrupt(), gmac_enable_copy_all(), gmac_enable_interrupt(), gmac_enable_receive(), gmac_enable_statistics_write(), gmac_enable_transmit(), gmac_get_interrupt_status(), GMAC_INT_GROUP, gmac_network_control(), GMAC_OK, GMAC_QUE_0, gmac_rx_init(), GMAC_RXD_ADDR_MASK, GMAC_RXD_WRAP, gmac_set_address(), gmac_set_rx_bufsize(), gmac_tx_init(), GMAC_TXD_USED, GMAC_TXD_WRAP, gs_gmac_dev, gs_rx_desc_null, gs_tx_desc_null, gs_uc_mac_address, netif::hwaddr, netif::hwaddr_len, INT_PRIORITY_GMAC, LWIP_DEBUGF, netif::mtu, NET_MTU, NETIF_DEBUG, NETIF_FLAG_BROADCAST, NETIF_FLAG_DHCP, NETIF_FLAG_ETHARP, NETIF_FLAG_LINK_UP, pmc_enable_periph_clk(), gmac_rx_descriptor::status, gmac_tx_descriptor::status, sysclk_get_cpu_hz(), gmac_rx_descriptor::gmac_rx_addr::val, gmac_rx_descriptor::gmac_rx_status::val, and gmac_tx_descriptor::gmac_tx_status::val.
Referenced by ethernetif_init().
Use pre-allocated pbuf as DMA source and return the incoming packet.
netif | the lwIP network interface structure for this ethernetif. |
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().
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.
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 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 |
Set up the RX descriptor ring buffers.
This function sets up the descriptor list used for receive packets.
ps_gmac_dev | Pointer 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 |
Populate the RX descriptor ring buffers with pbufs.
p_gmac_dev | Pointer 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 |
Set up the TX descriptor ring buffers.
This function sets up the descriptor list used for receive packets.
ps_gmac_dev | Pointer 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().
|
static |
GMAC driver instance.
Referenced by ethernetif_init(), GMAC_Handler(), and gmac_low_level_init().
|
static |
RX descriptors lists.
Referenced by gmac_low_level_init().
|
static |
TX descriptor lists.
Referenced by gmac_low_level_init().
|
static |
MAC address to use.
Referenced by gmac_low_level_init().