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 pbuf * | ksz8851snl_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_task (void *pvParameters) |
This function waits for the notification semaphore from the interrupt, processes the incoming packet and then passes it to the lwIP stack. 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().
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.
netif | the lwIP network interface structure for this ethernetif. |
References err, ERR_MEM, ERR_OK, gs_ksz8851snl_dev, id, IFNAME0, IFNAME1, ksz8851snl_low_level_init(), ksz8851snl_low_level_output(), ksz8851snl_task(), netif::linkoutput, LWIP_ASSERT, netif::name, NET_LINK_SPEED, ksz8851snl_device::netif, NETIF_INIT_SNMP, NULL, netif::output, snmp_ifType_ethernet_csmacd, netif::state, ksz8851snl_device::sync_sem, sys_sem_new(), 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.
netif | the lwIP network interface structure for this ethernetif. |
References ERR_OK, htons, netif::input, ksz8851snl_low_level_input(), ksz8851snl_update(), LWIP_DEBUGF, NETIF_DEBUG, NULL, pbuf::payload, and pbuf_free().
Referenced by ethernet_task(), and ksz8851snl_task().
|
static |
Handler for INTN falling edge interrupt.
References g_intn_flag, gs_ksz8851snl_dev, pdFALSE, ksz8851snl_device::sync_sem, and xSemaphoreGiveFromISR.
Referenced by ksz8851snl_low_level_init().
|
static |
Initialize ksz8851snl ethernet controller.
netif | the lwIP network interface structure for this ethernetif. |
References configure_intn(), netif::flags, gs_ksz8851snl_dev, gs_uc_mac_address, netif::hwaddr, netif::hwaddr_len, INTN_Handler(), ksz8851snl_init(), ksz8851snl_rx_init(), ksz8851snl_tx_init(), LWIP_ASSERT, LWIP_DEBUGF, netif::mtu, NET_MTU, NETIF_DEBUG, NETIF_FLAG_BROADCAST, NETIF_FLAG_DHCP, and NETIF_FLAG_ETHARP.
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 ksz8851snl_rx_populate_queue(), LINK_STATS_INC, LWIP_DEBUGF, NETIF_DEBUG, 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().
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 ERR_IF, ERR_OK, LINK_STATS_INC, LWIP_DEBUGF, NETIF_DEBUG, pbuf::payload, pbuf_ref(), netif::state, ksz8851snl_device::sync_sem, pbuf::tot_len, ksz8851snl_device::tx_desc, ksz8851snl_device::tx_pbuf, ksz8851snl_device::us_tx_head, ksz8851snl_device::us_tx_tail, and xSemaphoreGive.
Referenced by ethernetif_init().
|
static |
Set up the RX descriptor ring buffers.
This function sets up the descriptor list used for RX packets.
ps_ksz8851snl_dev | Pointer to driver data structure. |
References ksz8851snl_rx_populate_queue(), 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 |
Populate the RX descriptor ring buffers with pbufs.
p_ksz8851snl_dev | Pointer to driver data structure. |
References LWIP_ASSERT, LWIP_DEBUGF, NETIF_DEBUG, 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 |
This function waits for the notification semaphore from the interrupt, processes the incoming packet and then passes it to the lwIP stack.
pvParameters | A pointer to the ksz8851snl_device instance. |
References ethernetif_input(), ksz8851snl_device::netif, pending_frame, ksz8851snl_device::sync_sem, sys_arch_sem_wait(), ksz8851snl_device::tx_desc, and ksz8851snl_device::us_tx_tail.
Referenced by ethernetif_init().
|
static |
Set up the TX descriptor ring buffers.
This function sets up the descriptor list used for TX packets.
ps_ksz8851snl_dev | Pointer to driver data structure. |
References ksz8851snl_device::tx_desc, ksz8851snl_device::us_tx_head, and ksz8851snl_device::us_tx_tail.
Referenced by ksz8851snl_low_level_init().
|
static |
Update Micrel state machine and perform required actions.
netif | the lwIP network interface structure for this ethernetif. |
References ADDR_PTR_MASK, ETH_PAD_SIZE, g_intn_flag, INT_RX, ksz8851_fifo_read(), ksz8851_fifo_write(), ksz8851_fifo_write_begin(), ksz8851_fifo_write_end(), ksz8851_reg_clrbits(), ksz8851_reg_read(), ksz8851_reg_setbits(), ksz8851_reg_write(), ksz8851snl_rx_populate_queue(), pbuf::len, len, LWIP_DEBUGF, NETIF_DEBUG, pbuf::next, NULL, pbuf::payload, pbuf_free(), pbuf_header(), pending_frame, REG_INT_MASK, REG_INT_STATUS, REG_RX_ADDR_PTR, REG_RX_FHR_BYTE_CNT, REG_RX_FHR_STATUS, REG_RX_FRAME_CNT_THRES, REG_RXQ_CMD, REG_TX_MEM_INFO, REG_TXQ_CMD, RX_BYTE_CNT_MASK, ksz8851snl_device::rx_desc, RX_ERRORS, ksz8851snl_device::rx_pbuf, RX_VALID, RXQ_CMD_FREE_PACKET, RXQ_START, netif::state, status, pbuf::tot_len, ksz8851snl_device::tx_desc, TX_MEM_AVAILABLE_MASK, ksz8851snl_device::tx_pbuf, TXQ_ENQUEUE, ksz8851snl_device::us_rx_head, ksz8851snl_device::us_rx_tail, ksz8851snl_device::us_tx_head, and ksz8851snl_device::us_tx_tail.
Referenced by ethernetif_input().
volatile uint32_t g_intn_flag = 0 |
Referenced by INTN_Handler(), and ksz8851snl_update().
|
static |
ksz8851snl driver instance.
Referenced by ethernetif_init(), INTN_Handler(), and ksz8851snl_low_level_init().
|
static |
MAC address to use.
Referenced by ksz8851snl_low_level_init().
|
static |
Referenced by ksz8851snl_task(), and ksz8851snl_update().