KSZ8851SNL SAM driver for lwIP.
Copyright (c) 2013-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 "ksz8851snl.h"
#include "ksz8851snl_reg.h"
#include "netif/sam_spi_ksz8851snl.h"
#include "sysclk.h"
#include "spi.h"
#include "pdc.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... | |
#define | SPI_PDC_IDLE 0 |
#define | SPI_PDC_RX_COMPLETE 2 |
#define | SPI_PDC_RX_START 1 |
#define | SPI_PDC_TX_COMPLETE 4 |
#define | SPI_PDC_TX_START 3 |
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 (uint32_t id, uint32_t mask) |
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... | |
void | SPI_Handler (void) |
Handler for SPI interrupt. More... | |
Variables | |
volatile uint32_t | g_intn_flag = 0 |
Pdc * | g_p_spi_pdc |
volatile uint32_t | g_spi_pdc_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 |
uint8_t | tmpbuf [] |
#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().
#define SPI_PDC_IDLE 0 |
Referenced by ksz8851snl_task(), and ksz8851snl_update().
#define SPI_PDC_RX_COMPLETE 2 |
Referenced by ksz8851snl_update(), and SPI_Handler().
#define SPI_PDC_RX_START 1 |
Referenced by ksz8851snl_update(), and SPI_Handler().
#define SPI_PDC_TX_COMPLETE 4 |
Referenced by ksz8851snl_update(), and SPI_Handler().
#define SPI_PDC_TX_START 3 |
Referenced by ksz8851snl_update(), and SPI_Handler().
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_MEM, ERR_OK, gs_ksz8851snl_dev, 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().
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 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 netif::flags, gs_ksz8851snl_dev, gs_uc_mac_address, netif::hwaddr, netif::hwaddr_len, INTN_Handler(), 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(), g_spi_pdc_flag, ksz8851snl_device::netif, pending_frame, SPI_PDC_IDLE, 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 g_intn_flag, g_spi_pdc_flag, ksz8851snl_rx_populate_queue(), pbuf::len, LWIP_DEBUGF, NETIF_DEBUG, NULL, pbuf::payload, pbuf_free(), pending_frame, ksz8851snl_device::rx_desc, ksz8851snl_device::rx_pbuf, SPI_PDC_IDLE, SPI_PDC_RX_COMPLETE, SPI_PDC_RX_START, SPI_PDC_TX_COMPLETE, SPI_PDC_TX_START, netif::state, status, pbuf::tot_len, ksz8851snl_device::tx_cur_pbuf, ksz8851snl_device::tx_desc, ksz8851snl_device::tx_pbuf, 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().
void SPI_Handler | ( | void | ) |
Handler for SPI interrupt.
References g_p_spi_pdc, g_spi_pdc_flag, gs_ksz8851snl_dev, pbuf::len, pbuf::next, NULL, pbuf::payload, spi_disable_interrupt(), spi_enable_interrupt(), SPI_PDC_RX_COMPLETE, SPI_PDC_RX_START, SPI_PDC_TX_COMPLETE, SPI_PDC_TX_START, spi_read_interrupt_mask(), spi_read_status(), status, tmpbuf, and ksz8851snl_device::tx_cur_pbuf.
volatile uint32_t g_intn_flag = 0 |
Referenced by INTN_Handler(), and ksz8851snl_update().
Pdc* g_p_spi_pdc |
Referenced by SPI_Handler().
volatile uint32_t g_spi_pdc_flag = 0 |
Referenced by ksz8851snl_task(), ksz8851snl_update(), and SPI_Handler().
|
static |
ksz8851snl driver instance.
Referenced by ethernetif_init(), INTN_Handler(), ksz8851snl_low_level_init(), and SPI_Handler().
|
static |
MAC address to use.
Referenced by ksz8851snl_low_level_init().
|
static |
Referenced by ksz8851snl_task(), and ksz8851snl_update().
uint8_t tmpbuf[] |
Referenced by SPI_Handler().