Microchip® Advanced Software Framework

sam0_spi_ksz8851snl.c File Reference

KSZ8851SNL SAM0 driver for lwIP.

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

#include "port.h"
#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 "ksz8851snl.h"
#include "ksz8851snl_reg.h"
#include "netif/sam0_spi_ksz8851snl.h"
#include "conf_eth.h"

Data Structures

struct  ksz8851snl_device
 ksz8851snl driver structure. More...
 

Macros

#define IFNAME0   'e'
 Network interface identifier. More...
 
#define IFNAME1   'n'
 
#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...
 
static void INTN_Handler ()
 Handler for INTN falling edge interrupt. More...
 
static void ksz8851snl_low_level_init (struct netif *netif)
 Initialize ksz8851snl ethernet controller. More...
 
static struct pbufksz8851snl_low_level_input (struct netif *netif)
 Use pre-allocated pbuf as DMA source and return the incoming packet. More...
 
static err_t ksz8851snl_low_level_output (struct netif *netif, struct pbuf *p)
 This function should do the actual transmission of the packet. More...
 
static void ksz8851snl_rx_init (struct ksz8851snl_device *ps_ksz8851snl_dev)
 Set up the RX descriptor ring buffers. More...
 
static void ksz8851snl_rx_populate_queue (struct ksz8851snl_device *p_ksz8851snl_dev)
 Populate the RX descriptor ring buffers with pbufs. More...
 
static void ksz8851snl_tx_init (struct ksz8851snl_device *ps_ksz8851snl_dev)
 Set up the TX descriptor ring buffers. More...
 
static void ksz8851snl_update (struct netif *netif)
 Update Micrel state machine and perform required actions. More...
 

Variables

volatile uint32_t g_intn_flag = 0
 
static struct ksz8851snl_device gs_ksz8851snl_dev
 ksz8851snl driver instance. More...
 
static uint8_t gs_uc_mac_address []
 MAC address to use. More...
 
static uint16_t pending_frame = 0
 

#define IFNAME0   'e'

Network interface identifier.

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 ksz8851snl_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 ksz8851snl_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(), gs_ksz8851snl_dev, IFNAME0, IFNAME1, ksz8851snl_low_level_init(), ksz8851snl_low_level_output(), netif::linkoutput, LWIP_ASSERT, netif::name, NET_LINK_SPEED, ksz8851snl_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 ksz8851snl_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, htons, netif::input, ksz8851snl_low_level_input(), ksz8851snl_update(), LWIP_DEBUGF, NETIF_DEBUG, NULL, pbuf::payload, and pbuf_free().

Referenced by ethernet_task().

static void INTN_Handler ( )
static

Handler for INTN falling edge interrupt.

References g_intn_flag, and gs_ksz8851snl_dev.

Referenced by ksz8851snl_low_level_init().

static void ksz8851snl_low_level_init ( struct netif netif)
static
static struct pbuf* ksz8851snl_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 ksz8851snl_rx_populate_queue(), LINK_STATS_INC, LWIP_DEBUGF, NETIF_DEBUG, NETIF_RX_BUFFERS, pbuf::payload, ksz8851snl_device::rx_desc, ksz8851snl_device::rx_pbuf, netif::state, pbuf::tot_len, ksz8851snl_device::us_rx_head, and ksz8851snl_device::us_rx_tail.

Referenced by ethernetif_input().

static err_t ksz8851snl_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 ERR_IF, ERR_OK, LINK_STATS_INC, LWIP_DEBUGF, NETIF_DEBUG, NETIF_TX_BUFFERS, pbuf::payload, pbuf_ref(), netif::state, pbuf::tot_len, ksz8851snl_device::tx_desc, ksz8851snl_device::tx_pbuf, ksz8851snl_device::us_tx_head, and ksz8851snl_device::us_tx_tail.

Referenced by ethernetif_init().

static void ksz8851snl_rx_init ( struct ksz8851snl_device ps_ksz8851snl_dev)
static

Set up the RX descriptor ring buffers.

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

Parameters
ps_ksz8851snl_devPointer to driver data structure.

References ksz8851snl_rx_populate_queue(), NETIF_RX_BUFFERS, ksz8851snl_device::rx_desc, ksz8851snl_device::rx_pbuf, ksz8851snl_device::us_rx_head, and ksz8851snl_device::us_rx_tail.

Referenced by ksz8851snl_low_level_init().

static void ksz8851snl_rx_populate_queue ( struct ksz8851snl_device p_ksz8851snl_dev)
static

Populate the RX descriptor ring buffers with pbufs.

Parameters
p_ksz8851snl_devPointer to driver data structure.

References LWIP_ASSERT, LWIP_DEBUGF, NETIF_DEBUG, NETIF_RX_BUFFERS, pbuf_alloc(), pbuf_clen(), PBUF_POOL, PBUF_POOL_BUFSIZE, PBUF_RAW, ksz8851snl_device::rx_desc, and ksz8851snl_device::rx_pbuf.

Referenced by ksz8851snl_low_level_input(), ksz8851snl_rx_init(), and ksz8851snl_update().

static void ksz8851snl_tx_init ( struct ksz8851snl_device ps_ksz8851snl_dev)
static

Set up the TX descriptor ring buffers.

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

Parameters
ps_ksz8851snl_devPointer to driver data structure.

References NETIF_TX_BUFFERS, ksz8851snl_device::tx_desc, ksz8851snl_device::us_tx_head, and ksz8851snl_device::us_tx_tail.

Referenced by ksz8851snl_low_level_init().

volatile uint32_t g_intn_flag = 0

Referenced by INTN_Handler(), and ksz8851snl_update().

struct ksz8851snl_device gs_ksz8851snl_dev
static

ksz8851snl driver instance.

Referenced by ethernetif_init(), INTN_Handler(), and ksz8851snl_low_level_init().

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

MAC address to use.

Referenced by ksz8851snl_low_level_init().

uint16_t pending_frame = 0
static

Referenced by ksz8851snl_update().