Completes first cut at Kinetis ethernet driver
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3889 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
parent
94a3c61edb
commit
b1edd6327a
@ -67,10 +67,6 @@ ifeq ($(CONFIG_GPIO_IRQ),y)
|
|||||||
CHIP_CSRCS += kinetis_pinirq.c
|
CHIP_CSRCS += kinetis_pinirq.c
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(CONFIG_KINETIS_DMA),y)
|
|
||||||
CHIP_CSRCS += kinetis_pindma.c
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_DEBUG_GPIO),y)
|
ifeq ($(CONFIG_DEBUG_GPIO),y)
|
||||||
CHIP_CSRCS += kinetis_pindbg.c
|
CHIP_CSRCS += kinetis_pindbg.c
|
||||||
endif
|
endif
|
||||||
@ -84,7 +80,7 @@ CHIP_CSRCS += kinetis_usbhost.c
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(CONFIG_KINETIS_DMA),y)
|
ifeq ($(CONFIG_KINETIS_DMA),y)
|
||||||
CHIP_CSRCS += kinetis_dma.c
|
CHIP_CSRCS += kinetis_dma.c kinetis_pindma.c
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(CONFIG_NET),y)
|
ifeq ($(CONFIG_NET),y)
|
||||||
|
@ -186,8 +186,11 @@
|
|||||||
|
|
||||||
/* Ethernet controller configuration */
|
/* Ethernet controller configuration */
|
||||||
|
|
||||||
#ifndef CONFIG_ENET_NBUFFERS
|
#ifndef CONFIG_ENET_NRXBUFFERS
|
||||||
# define CONFIG_ENET_NBUFFERS 8
|
# define CONFIG_ENET_NRXBUFFERS 6
|
||||||
|
#endif
|
||||||
|
#ifndef CONFIG_ENET_NTXBUFFERS
|
||||||
|
# define CONFIG_ENET_NTXBUFFERS 2
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef CONFIG_ENET_PHYADDR
|
#ifndef CONFIG_ENET_PHYADDR
|
||||||
|
@ -42,6 +42,7 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
@ -56,7 +57,11 @@
|
|||||||
#include <net/uip/uip-arp.h>
|
#include <net/uip/uip-arp.h>
|
||||||
#include <net/uip/uip-arch.h>
|
#include <net/uip/uip-arch.h>
|
||||||
|
|
||||||
|
#include "up_arch.h"
|
||||||
#include "chip.h"
|
#include "chip.h"
|
||||||
|
#include "kinetis_internal.h"
|
||||||
|
#include "kinetis_config.h"
|
||||||
|
#include "kinetis_pinmux.h"
|
||||||
#include "kinetis_sim.h"
|
#include "kinetis_sim.h"
|
||||||
#include "kinetis_mpu.h"
|
#include "kinetis_mpu.h"
|
||||||
#include "kinetis_enet.h"
|
#include "kinetis_enet.h"
|
||||||
@ -72,7 +77,21 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#if CONFIG_ENET_NETHIFS != 1
|
#if CONFIG_ENET_NETHIFS != 1
|
||||||
# error "CONFIG_ENET_NETHIFS must be one for now"
|
# error "CONFIG_ENET_NETHIFS must be one for now"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if CONFIG_ENET_NTXBUFFERS < 1
|
||||||
|
# error "Need at least one TX buffer"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if CONFIG_ENET_NRXBUFFERS < 1
|
||||||
|
# error "Need at least one RX buffer"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define NENET_NBUFFERS (CONFIG_ENET_NTXBUFFERS+CONFIG_ENET_NRXBUFFERS)
|
||||||
|
|
||||||
|
#ifndef CONFIG_NET_MULTIBUFFER
|
||||||
|
# errror "CONFIG_NET_MULTIBUFFER is required in the configuration"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* TX poll delay = 1 seconds. CLK_TCK is the number of clock ticks per second */
|
/* TX poll delay = 1 seconds. CLK_TCK is the number of clock ticks per second */
|
||||||
@ -95,15 +114,30 @@
|
|||||||
#define PHY_DUPLEX_STATUS (4 << 2)
|
#define PHY_DUPLEX_STATUS (4 << 2)
|
||||||
#define PHY_SPEED_STATUS (1 << 2)
|
#define PHY_SPEED_STATUS (1 << 2)
|
||||||
|
|
||||||
/* Estimate the hold time to use based on the peripheral (bus) clock.
|
/* Estimate the hold time to use based on the peripheral (bus) clock:
|
||||||
* BUS_FREQ = 48Mhz, hold time clocks = (2*48)/5 + 1 = 19.
|
*
|
||||||
|
* HOLD_TIME = (2*BUS_FREQ_MHZ)/5 + 1
|
||||||
|
* = (BUS_FREQ)/2500000 + 1
|
||||||
|
*
|
||||||
|
* For example, if BUS_FREQ_MHZ=48 (MHz):
|
||||||
|
*
|
||||||
|
* HOLD_TIME = 48Mhz, hold time clocks
|
||||||
|
* = 48000000/2500000 + 1
|
||||||
|
* = 20
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define KINETIS_MII_SPEED ((2*BOARD_BUS_FREQ)/5 + 1)
|
#define KINETIS_MII_SPEED (BOARD_BUS_FREQ/2500000 + 1)
|
||||||
#if KINETIS_MII_SPEED > 63
|
#if KINETIS_MII_SPEED > 63
|
||||||
# error "KINETIS_MII_SPEED is out-of-range"
|
# error "KINETIS_MII_SPEED is out-of-range"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Interrupt groups */
|
||||||
|
|
||||||
|
#define RX_INTERRUPTS (ENET_INT_RXF | ENET_INT_RXB)
|
||||||
|
#define TX_INTERRUPTS ENET_INT_TXF
|
||||||
|
#define ERROR_INTERRUPTS (ENET_INT_UN | ENET_INT_RL | ENET_INT_LC | \
|
||||||
|
ENET_INT_EBERR | ENET_INT_BABT | ENET_INT_BABR)
|
||||||
|
|
||||||
/* This is a helper pointer for accessing the contents of the Ethernet header */
|
/* This is a helper pointer for accessing the contents of the Ethernet header */
|
||||||
|
|
||||||
#define BUF ((struct uip_eth_hdr *)priv->dev.d_buf)
|
#define BUF ((struct uip_eth_hdr *)priv->dev.d_buf)
|
||||||
@ -111,6 +145,21 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Private Types
|
* Private Types
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
/* EMAC statistics (debug only) */
|
||||||
|
|
||||||
|
#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_NET)
|
||||||
|
struct kinetis_statistics_s
|
||||||
|
{
|
||||||
|
uint32_t rx_packets; /* Number of packets received */
|
||||||
|
uint32_t tx_packets; /* Number of Tx packets queued */
|
||||||
|
unit32_t tx_done; /* Number of packets completed */
|
||||||
|
uint32_t tx_timeouts; /* Number of Tx timeout errors */
|
||||||
|
uint32_t errors; /* Number of error interrupts */
|
||||||
|
};
|
||||||
|
# define EMAC_STAT(priv,name) priv->stats.name++
|
||||||
|
#else
|
||||||
|
# define EMAC_STAT(priv,name)
|
||||||
|
#endif
|
||||||
|
|
||||||
/* The kinetis_driver_s encapsulates all state information for a single hardware
|
/* The kinetis_driver_s encapsulates all state information for a single hardware
|
||||||
* interface
|
* interface
|
||||||
@ -118,30 +167,38 @@
|
|||||||
|
|
||||||
struct kinetis_driver_s
|
struct kinetis_driver_s
|
||||||
{
|
{
|
||||||
bool bifup; /* true:ifup false:ifdown */
|
bool bifup; /* true:ifup false:ifdown */
|
||||||
uint8_t nextdesc; /* The next descriptor to use */
|
uint8_t txtail; /* The oldest busy TX descriptor */
|
||||||
WDOG_ID txpoll; /* TX poll timer */
|
uint8_t txhead; /* The next TX descriptor to use */
|
||||||
WDOG_ID txtimeout; /* TX timeout timer */
|
uint8_t rxtail; /* The next RX descriptor to use */
|
||||||
struct enet_desc_s *g_txdesc; /* A pointer to the (single) TX descriptor */
|
WDOG_ID txpoll; /* TX poll timer */
|
||||||
struct enet_desc_s *priv->rxdesc; /* A pointer the list of RX descriptors */
|
WDOG_ID txtimeout; /* TX timeout timer */
|
||||||
|
struct enet_desc_s *txdesc; /* A pointer to the list of TX descriptor */
|
||||||
|
struct enet_desc_s *rxdesc; /* A pointer to the list of RX descriptors */
|
||||||
|
|
||||||
/* This holds the information visible to uIP/NuttX */
|
/* This holds the information visible to uIP/NuttX */
|
||||||
|
|
||||||
struct uip_driver_s dev; /* Interface understood by uIP */
|
struct uip_driver_s dev; /* Interface understood by uIP */
|
||||||
|
|
||||||
|
/* Statistics */
|
||||||
|
|
||||||
|
#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_NET)
|
||||||
|
struct kinetis_statistics_s stats;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* The DMA descriptors. A unaligned uint8_t is used to allocate the
|
/* The DMA descriptors. A unaligned uint8_t is used to allocate the
|
||||||
* memory; 16 is added to assure that we can meet the desciptor alignment
|
* memory; 16 is added to assure that we can meet the desciptor alignment
|
||||||
* requirements; 1 is added for the single TX descriptor.
|
* requirements.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
uint8_t desc[((CONFIG_ENET_NTXBUFFERS+1) * sizeof(struct enet_desc_s)) + 16];
|
uint8_t desc[NENET_NBUFFERS * sizeof(struct enet_desc_s) + 16];
|
||||||
|
|
||||||
/* The DMA buffers. Again, A unaligned uint8_t is used to allocate the
|
/* The DMA buffers. Again, A unaligned uint8_t is used to allocate the
|
||||||
* memory; 16 is added to assure that we can meet the desciptor alignment
|
* memory; 16 is added to assure that we can meet the desciptor alignment
|
||||||
* requirements.
|
* requirements.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
uint8_t rxbuffers[(CONFIG_ENET_NTXBUFFERS * CONFIG_NET_BUFSIZE) + 16];
|
uint8_t buffers[NENET_NBUFFERS * CONFIG_NET_BUFSIZE + 16];
|
||||||
};
|
};
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@ -160,11 +217,12 @@ static struct kinetis_driver_s g_enet[CONFIG_ENET_NETHIFS];
|
|||||||
# define kinesis_swap16(value) (value)
|
# define kinesis_swap16(value) (value)
|
||||||
#else
|
#else
|
||||||
static inline uint32_t kinesis_swap32(uint32_t value);
|
static inline uint32_t kinesis_swap32(uint32_t value);
|
||||||
static inline __asm int32_t kinesis_swap16(int16_t value);
|
static inline uint16_t kinesis_swap16(uint16_t value);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Common TX logic */
|
/* Common TX logic */
|
||||||
|
|
||||||
|
static bool kinetics_txringfull(FAR struct kinetis_driver_s *priv);
|
||||||
static int kinetis_transmit(FAR struct kinetis_driver_s *priv);
|
static int kinetis_transmit(FAR struct kinetis_driver_s *priv);
|
||||||
static int kinetis_uiptxpoll(struct uip_driver_s *dev);
|
static int kinetis_uiptxpoll(struct uip_driver_s *dev);
|
||||||
|
|
||||||
@ -224,16 +282,62 @@ static inline uint32_t kinesis_swap32(uint32_t value)
|
|||||||
{
|
{
|
||||||
uint32_t result = 0;
|
uint32_t result = 0;
|
||||||
|
|
||||||
__asm volatile ("rev %0, %1":"=r" (result): "r"(value));
|
__asm__ __volatile__
|
||||||
|
(
|
||||||
|
"rev %0, %1"
|
||||||
|
:"=r" (result)
|
||||||
|
: "r"(value)
|
||||||
|
);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline __asm int32_t kinesis_swap16(int16_t value)
|
static inline uint16_t kinesis_swap16(uint16_t value)
|
||||||
{
|
{
|
||||||
revsh r0, r0 bx lr
|
uint16_t result = 0;
|
||||||
|
|
||||||
|
__asm__ __volatile__
|
||||||
|
(
|
||||||
|
"revsh %0, %1"
|
||||||
|
:"=r" (result)
|
||||||
|
: "r"(value)
|
||||||
|
);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Function: kinetics_txringfull
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Check if all of the TX descriptors are in use.
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* priv - Reference to the driver state structure
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* true is the TX ring is full; false if there are free slots at the
|
||||||
|
* head index.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static bool kinetics_txringfull(FAR struct kinetis_driver_s *priv)
|
||||||
|
{
|
||||||
|
uint8_t txnext;
|
||||||
|
|
||||||
|
/* Check if there is room in the hardware to hold another outgoing
|
||||||
|
* packet. The ring is full if incrementing the head pointer would
|
||||||
|
* collide with the tail pointer.
|
||||||
|
*/
|
||||||
|
|
||||||
|
txnext = priv->txhead + 1;
|
||||||
|
if (txnext > CONFIG_ENET_NTXBUFFERS)
|
||||||
|
{
|
||||||
|
txnext = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return priv->txtail == txnext;
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Function: kinetis_transmit
|
* Function: kinetis_transmit
|
||||||
*
|
*
|
||||||
@ -256,17 +360,49 @@ static inline __asm int32_t kinesis_swap16(int16_t value)
|
|||||||
|
|
||||||
static int kinetis_transmit(FAR struct kinetis_driver_s *priv)
|
static int kinetis_transmit(FAR struct kinetis_driver_s *priv)
|
||||||
{
|
{
|
||||||
/* Verify that the hardware is ready to send another packet. If we get
|
struct enet_desc_s *txdesc;
|
||||||
* here, then we are committed to sending a packet; Higher level logic
|
uint32_t regval;
|
||||||
* must have assured that there is not transmission in progress.
|
|
||||||
|
/* When we get here the TX descriptor should show that the previous
|
||||||
|
* transfer has completed. If we get here, then we are committed to
|
||||||
|
* sending a packet; Higher level logic must have assured that there is
|
||||||
|
* no transmission in progress.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
txdesc = &priv->txdesc[priv->txhead];
|
||||||
|
priv->txhead++;
|
||||||
|
if (priv->txhead > CONFIG_ENET_NTXBUFFERS)
|
||||||
|
{
|
||||||
|
priv->txhead = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
DEBUGASSERT(priv->txtail != priv->txhead &&
|
||||||
|
(txdesc->status1 & TXDESC_R) == 0);
|
||||||
|
|
||||||
/* Increment statistics */
|
/* Increment statistics */
|
||||||
|
|
||||||
/* Send the packet: address=priv->dev.d_buf, length=priv->dev.d_len */
|
EMAC_STAT(priv, tx_packets);
|
||||||
#warning "Missing logic"
|
|
||||||
|
|
||||||
/* Enable Tx interrupts */
|
/* Setup the buffer descriptor for transmission: address=priv->dev.d_buf,
|
||||||
|
* length=priv->dev.d_len
|
||||||
|
*/
|
||||||
|
|
||||||
|
txdesc->length = kinesis_swap16(priv->dev.d_len);
|
||||||
|
#ifdef CONFIG_ENET_ENHANCEDBD
|
||||||
|
txdesc->bdu = 0x00000000;
|
||||||
|
txdesc->status2 = TXDESC_INT | TXDESC_TS; // | TXDESC_IINS | TXDESC_PINS;
|
||||||
|
#endif
|
||||||
|
txdesc->status1 = (TXDESC_R | TXDESC_L | TXDESC_TC | TXDESC_W);
|
||||||
|
|
||||||
|
/* Start the TX transfer (if it was not already waiting for buffers) */
|
||||||
|
|
||||||
|
putreg32(ENET_TDAR, KINETIS_ENET_TDAR);
|
||||||
|
|
||||||
|
/* Enable TX interrupts */
|
||||||
|
|
||||||
|
regval = getreg32(KINETIS_ENET_EIMR);
|
||||||
|
regval |= TX_INTERRUPTS;
|
||||||
|
putreg32(regval, KINETIS_ENET_EIMR);
|
||||||
|
|
||||||
/* Setup the TX timeout watchdog (perhaps restarting the timer) */
|
/* Setup the TX timeout watchdog (perhaps restarting the timer) */
|
||||||
|
|
||||||
@ -314,7 +450,11 @@ static int kinetis_uiptxpoll(struct uip_driver_s *dev)
|
|||||||
/* Check if there is room in the device to hold another packet. If not,
|
/* Check if there is room in the device to hold another packet. If not,
|
||||||
* return a non-zero value to terminate the poll.
|
* return a non-zero value to terminate the poll.
|
||||||
*/
|
*/
|
||||||
#warning "Missing logic"
|
|
||||||
|
if (kinetics_txringfull(priv))
|
||||||
|
{
|
||||||
|
return -EBUSY;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If zero is returned, the polling will continue until all connections have
|
/* If zero is returned, the polling will continue until all connections have
|
||||||
@ -343,16 +483,36 @@ static int kinetis_uiptxpoll(struct uip_driver_s *dev)
|
|||||||
|
|
||||||
static void kinetis_receive(FAR struct kinetis_driver_s *priv)
|
static void kinetis_receive(FAR struct kinetis_driver_s *priv)
|
||||||
{
|
{
|
||||||
do
|
/* Loop while there are received packets to be processed */
|
||||||
|
|
||||||
|
while ((priv->rxdesc[priv->rxtail].status1 & RXDESC_E) != 0)
|
||||||
{
|
{
|
||||||
/* Check for errors and update statistics */
|
/* Update statistics */
|
||||||
|
|
||||||
/* Check if the packet is a valid size for the uIP buffer configuration */
|
EMAC_STAT(priv, rx_packets);
|
||||||
|
|
||||||
/* Copy the data data from the hardware to priv->dev.d_buf. Set
|
/* Copy the buffer pointer to priv->dev.d_buf. Set amount of data in
|
||||||
* amount of data in priv->dev.d_len
|
* priv->dev.d_len
|
||||||
*/
|
*/
|
||||||
#warning "Missing logic"
|
|
||||||
|
priv->dev.d_len = kinesis_swap16(priv->rxdesc[priv->rxtail].length);
|
||||||
|
priv->dev.d_buf = (uint8_t*)kinesis_swap32((uint32_t)priv->rxdesc[priv->rxtail].data);
|
||||||
|
|
||||||
|
/* Doing this here could cause corruption! */
|
||||||
|
|
||||||
|
priv->rxdesc[priv->rxtail].status1 |= RXDESC_E;
|
||||||
|
|
||||||
|
/* Update the index to the next descriptor */
|
||||||
|
|
||||||
|
priv->rxtail++;
|
||||||
|
if (priv->rxtail >= CONFIG_ENET_NTXBUFFERS)
|
||||||
|
{
|
||||||
|
priv->rxtail = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Indicate that there have been empty receive buffers produced */
|
||||||
|
|
||||||
|
putreg32(ENET_RDAR, KINETIS_ENET_RDAR);
|
||||||
|
|
||||||
/* We only accept IP packets of the configured type and ARP packets */
|
/* We only accept IP packets of the configured type and ARP packets */
|
||||||
|
|
||||||
@ -370,17 +530,18 @@ static void kinetis_receive(FAR struct kinetis_driver_s *priv)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
if (priv->dev.d_len > 0)
|
if (priv->dev.d_len > 0)
|
||||||
{
|
{
|
||||||
uip_arp_out(&priv->dev);
|
uip_arp_out(&priv->dev);
|
||||||
kinetis_transmit(priv);
|
kinetis_transmit(priv);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (BUF->type == htons(UIP_ETHTYPE_ARP))
|
else if (BUF->type == htons(UIP_ETHTYPE_ARP))
|
||||||
{
|
{
|
||||||
uip_arp_arpin(&priv->dev);
|
uip_arp_arpin(&priv->dev);
|
||||||
|
|
||||||
/* If the above function invocation resulted in data that should be
|
/* If the above function invocation resulted in data that should
|
||||||
* sent out on the network, the field d_len will set to a value > 0.
|
* be sent out on the network, the field d_len will set to a
|
||||||
|
* value > 0.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (priv->dev.d_len > 0)
|
if (priv->dev.d_len > 0)
|
||||||
@ -389,7 +550,6 @@ static void kinetis_receive(FAR struct kinetis_driver_s *priv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (); /* While there are more packets to be processed */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@ -411,16 +571,44 @@ static void kinetis_receive(FAR struct kinetis_driver_s *priv)
|
|||||||
|
|
||||||
static void kinetis_txdone(FAR struct kinetis_driver_s *priv)
|
static void kinetis_txdone(FAR struct kinetis_driver_s *priv)
|
||||||
{
|
{
|
||||||
/* Check for errors and update statistics */
|
struct enet_desc_s *txdesc;
|
||||||
|
uint32_t regval;
|
||||||
|
|
||||||
/* If no further xmits are pending, then cancel the TX timeout and
|
/* Verify that the oldest descriptor descriptor completed */
|
||||||
* disable further Tx interrupts.
|
|
||||||
|
txdesc = &priv->txdesc[priv->txtail];
|
||||||
|
if ((txdesc->status1 & TXDESC_R) == 0)
|
||||||
|
{
|
||||||
|
/* Yes.. bump up the tail pointer, making space for a new TX descriptor */
|
||||||
|
|
||||||
|
priv->txtail++;
|
||||||
|
if (priv->txtail > CONFIG_ENET_NTXBUFFERS)
|
||||||
|
{
|
||||||
|
priv->txtail = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Update statistics */
|
||||||
|
|
||||||
|
EMAC_STAT(priv, tx_done);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Are there other transmissions queued? */
|
||||||
|
|
||||||
|
if (priv->txtail == priv->txhead)
|
||||||
|
{
|
||||||
|
/* No.. Cancel the TX timeout and disable further Tx interrupts. */
|
||||||
|
|
||||||
|
wd_cancel(priv->txtimeout);
|
||||||
|
|
||||||
|
regval = getreg32(KINETIS_ENET_EIMR);
|
||||||
|
regval &= ~TX_INTERRUPTS;
|
||||||
|
putreg32(regval, KINETIS_ENET_EIMR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* There should be space for a new TX in any event. Poll uIP for new XMIT
|
||||||
|
* data
|
||||||
*/
|
*/
|
||||||
|
|
||||||
wd_cancel(priv->txtimeout);
|
|
||||||
|
|
||||||
/* Then poll uIP for new XMIT data */
|
|
||||||
|
|
||||||
(void)uip_poll(&priv->dev, kinetis_uiptxpoll);
|
(void)uip_poll(&priv->dev, kinetis_uiptxpoll);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -470,12 +658,6 @@ static int kinetis_interrupt(int irq, FAR void *context)
|
|||||||
|
|
||||||
if ((pending & ENET_INT_TXF) != 0)
|
if ((pending & ENET_INT_TXF) != 0)
|
||||||
{
|
{
|
||||||
/* The Tx has completed. Mark the data pointer as NULL to indicate
|
|
||||||
* that the buffer is now free again.
|
|
||||||
*/
|
|
||||||
|
|
||||||
g_txdesc->data = NULL;
|
|
||||||
|
|
||||||
/* Call kinetis_txdone to handle the end of transfer even. NOTE that
|
/* Call kinetis_txdone to handle the end of transfer even. NOTE that
|
||||||
* this may disable further Tx interrupts if there are no pending
|
* this may disable further Tx interrupts if there are no pending
|
||||||
* tansmissions.
|
* tansmissions.
|
||||||
@ -486,13 +668,15 @@ static int kinetis_interrupt(int irq, FAR void *context)
|
|||||||
|
|
||||||
/* Check for errors */
|
/* Check for errors */
|
||||||
|
|
||||||
if (pending &
|
if (pending & ERROR_INTERRUPTS)
|
||||||
(ENET_INT_UN | ENET_INT_RL | ENET_INT_LC | ENET_INT_EBERR |
|
|
||||||
ENET_INT_BABT | ENET_INT_BABR))
|
|
||||||
{
|
{
|
||||||
/* An error has occurred. Reinitialize all buffers. */
|
/* An error has occurred, update statistics */
|
||||||
|
|
||||||
kinetis_initbuffers();
|
EMAC_STAT(priv, errors);
|
||||||
|
|
||||||
|
/* Reinitialize all buffers. */
|
||||||
|
|
||||||
|
kinetis_initbuffers(priv);
|
||||||
|
|
||||||
/* Indicate that there have been empty receive buffers produced */
|
/* Indicate that there have been empty receive buffers produced */
|
||||||
|
|
||||||
@ -527,8 +711,14 @@ static void kinetis_txtimeout(int argc, uint32_t arg, ...)
|
|||||||
|
|
||||||
/* Increment statistics and dump debug info */
|
/* Increment statistics and dump debug info */
|
||||||
|
|
||||||
/* Then reset the hardware */
|
EMAC_STAT(priv, tx_timeout);
|
||||||
#warning "Missing logic"
|
|
||||||
|
/* Take the interface down and bring it back up. The is the most agressive
|
||||||
|
* hardware reset.
|
||||||
|
*/
|
||||||
|
|
||||||
|
(void)kinetis_ifup(&priv->dev);
|
||||||
|
(void)kinetis_ifdown(&priv->dev);
|
||||||
|
|
||||||
/* Then poll uIP for new XMIT data */
|
/* Then poll uIP for new XMIT data */
|
||||||
|
|
||||||
@ -557,19 +747,21 @@ static void kinetis_polltimer(int argc, uint32_t arg, ...)
|
|||||||
{
|
{
|
||||||
FAR struct kinetis_driver_s *priv = (FAR struct kinetis_driver_s *)arg;
|
FAR struct kinetis_driver_s *priv = (FAR struct kinetis_driver_s *)arg;
|
||||||
|
|
||||||
/* Check if there is room in the send another TX packet. We cannot perform
|
/* Check if there is there is a transmission in progress. We cannot perform
|
||||||
* the TX poll if he are unable to accept another packet for transmission.
|
* the TX poll if he are unable to accept another packet for transmission.
|
||||||
*/
|
*/
|
||||||
#warning "Missing logic"
|
|
||||||
|
|
||||||
/* If so, update TCP timing states and poll uIP for new XMIT data. Hmmm..
|
if (!kinetics_txringfull(priv))
|
||||||
* might be bug here. Does this mean if there is a transmit in progress,
|
{
|
||||||
* we will missing TCP time state updates?
|
/* If so, update TCP timing states and poll uIP for new XMIT data. Hmmm..
|
||||||
*/
|
* might be bug here. Does this mean if there is a transmit in progress,
|
||||||
|
* we will missing TCP time state updates?
|
||||||
|
*/
|
||||||
|
|
||||||
(void)uip_timer(&priv->dev, kinetis_uiptxpoll, KINETIS_POLLHSEC);
|
(void)uip_timer(&priv->dev, kinetis_uiptxpoll, KINETIS_POLLHSEC);
|
||||||
|
}
|
||||||
|
|
||||||
/* Setup the watchdog poll timer again */
|
/* Setup the watchdog poll timer again in any case */
|
||||||
|
|
||||||
(void)wd_start(priv->txpoll, KINETIS_WDDELAY, kinetis_polltimer, 1, arg);
|
(void)wd_start(priv->txpoll, KINETIS_WDDELAY, kinetis_polltimer, 1, arg);
|
||||||
}
|
}
|
||||||
@ -594,19 +786,89 @@ static void kinetis_polltimer(int argc, uint32_t arg, ...)
|
|||||||
static int kinetis_ifup(struct uip_driver_s *dev)
|
static int kinetis_ifup(struct uip_driver_s *dev)
|
||||||
{
|
{
|
||||||
FAR struct kinetis_driver_s *priv = (FAR struct kinetis_driver_s *)dev->d_private;
|
FAR struct kinetis_driver_s *priv = (FAR struct kinetis_driver_s *)dev->d_private;
|
||||||
|
uint32_t regval;
|
||||||
|
|
||||||
ndbg("Bringing up: %d.%d.%d.%d\n",
|
ndbg("Bringing up: %d.%d.%d.%d\n",
|
||||||
dev->d_ipaddr & 0xff, (dev->d_ipaddr >> 8) & 0xff,
|
dev->d_ipaddr & 0xff, (dev->d_ipaddr >> 8) & 0xff,
|
||||||
(dev->d_ipaddr >> 16) & 0xff, dev->d_ipaddr >> 24 );
|
(dev->d_ipaddr >> 16) & 0xff, dev->d_ipaddr >> 24 );
|
||||||
|
|
||||||
/* Initialize PHYs, the Ethernet interface, and setup up Ethernet interrupts */
|
/* Initialize ENET buffers */
|
||||||
#warning "Missing logic"
|
|
||||||
|
kinetis_initbuffers(priv);
|
||||||
|
|
||||||
|
/* Reset and disable the interface */
|
||||||
|
|
||||||
|
kinetis_reset(priv);
|
||||||
|
|
||||||
|
/* Configure the MII interface */
|
||||||
|
|
||||||
|
kinetis_initmii(priv);
|
||||||
|
|
||||||
|
/* Clear the Individual and Group Address Hash registers */
|
||||||
|
|
||||||
|
putreg32(0, KINETIS_ENET_IALR);
|
||||||
|
putreg32(0, KINETIS_ENET_IAUR);
|
||||||
|
putreg32(0, KINETIS_ENET_GALR);
|
||||||
|
putreg32(0, KINETIS_ENET_GAUR);
|
||||||
|
|
||||||
|
/* Configure the PHY */
|
||||||
|
|
||||||
|
kinetis_initphy(priv);
|
||||||
|
|
||||||
|
/* Handle promiscuous mode */
|
||||||
|
|
||||||
|
#ifdef CONFIG_NET_PROMISCUOUS
|
||||||
|
regval = getreg32(KINETIS_ENET_RCR);
|
||||||
|
regval |= ENET_RCR_PROM;
|
||||||
|
putreg32(regval, KINETIS_ENET_RCR);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Select legacy of enhanced buffer descriptor format */
|
||||||
|
|
||||||
|
#ifdef CONFIG_ENET_ENHANCEDBD
|
||||||
|
putreg32(ENET_ECR_EN1588, KINETIS_ENET_ECR);
|
||||||
|
#else
|
||||||
|
putreg32(0, KINETIS_ENET_ECR);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Set the RX buffer size */
|
||||||
|
|
||||||
|
putreg32(CONFIG_NET_BUFSIZE, KINETIS_ENET_MRBR);
|
||||||
|
|
||||||
|
/* Point to the start of the circular RX buffer descriptor queue */
|
||||||
|
|
||||||
|
putreg32((uint32_t)priv->rxdesc, KINETIS_ENET_RDSR);
|
||||||
|
|
||||||
|
/* Point to the start of the circular TX buffer descriptor queue */
|
||||||
|
|
||||||
|
putreg32((uint32_t)priv->txdesc, KINETIS_ENET_TDSR);
|
||||||
|
|
||||||
|
/* Indicate that there have been empty receive buffers produced */
|
||||||
|
|
||||||
|
putreg32(ENET_RDAR, KINETIS_ENET_RDAR);
|
||||||
|
|
||||||
|
/* And enable the MAC itself */
|
||||||
|
|
||||||
|
regval = getreg32(KINETIS_ENET_ECR);
|
||||||
|
regval |= ENET_ECR_ETHEREN;
|
||||||
|
putreg32(regval, KINETIS_ENET_ECR);
|
||||||
|
|
||||||
/* Set and activate a timer process */
|
/* Set and activate a timer process */
|
||||||
|
|
||||||
(void)wd_start(priv->txpoll, KINETIS_WDDELAY, kinetis_polltimer, 1, (uint32_t)priv);
|
(void)wd_start(priv->txpoll, KINETIS_WDDELAY, kinetis_polltimer, 1, (uint32_t)priv);
|
||||||
|
|
||||||
/* Enable the Ethernet interrupts */
|
/* Clear all pending ENET interrupt */
|
||||||
|
|
||||||
|
putreg32(0xffffffff, KINETIS_ENET_EIR);
|
||||||
|
|
||||||
|
/* Enable RX and error interrupts at the controller (TX interrupts are
|
||||||
|
* still disabled).
|
||||||
|
*/
|
||||||
|
|
||||||
|
putreg32(RX_INTERRUPTS | ERROR_INTERRUPTS,
|
||||||
|
KINETIS_ENET_EIMR);
|
||||||
|
|
||||||
|
/* Mark the interrupt "up" and enable interrupts at the NVIC */
|
||||||
|
|
||||||
priv->bifup = true;
|
priv->bifup = true;
|
||||||
#if 0
|
#if 0
|
||||||
@ -639,13 +901,14 @@ static int kinetis_ifdown(struct uip_driver_s *dev)
|
|||||||
FAR struct kinetis_driver_s *priv = (FAR struct kinetis_driver_s *)dev->d_private;
|
FAR struct kinetis_driver_s *priv = (FAR struct kinetis_driver_s *)dev->d_private;
|
||||||
irqstate_t flags;
|
irqstate_t flags;
|
||||||
|
|
||||||
/* Disable the Ethernet interrupt */
|
/* Disable the Ethernet interrupts at the NVIC */
|
||||||
|
|
||||||
flags = irqsave();
|
flags = irqsave();
|
||||||
up_disable_irq(KINETIS_IRQ_EMACTMR);
|
up_disable_irq(KINETIS_IRQ_EMACTMR);
|
||||||
up_disable_irq(KINETIS_IRQ_EMACTX);
|
up_disable_irq(KINETIS_IRQ_EMACTX);
|
||||||
up_disable_irq(KINETIS_IRQ_EMACRX);
|
up_disable_irq(KINETIS_IRQ_EMACRX);
|
||||||
up_disable_irq(KINETIS_IRQ_EMACMISC);
|
up_disable_irq(KINETIS_IRQ_EMACMISC);
|
||||||
|
putreg32(0, KINETIS_ENET_EIMR);
|
||||||
|
|
||||||
/* Cancel the TX poll timer and TX timeout timers */
|
/* Cancel the TX poll timer and TX timeout timers */
|
||||||
|
|
||||||
@ -656,7 +919,8 @@ static int kinetis_ifdown(struct uip_driver_s *dev)
|
|||||||
* a known configuration that will guarantee the kinetis_ifup() always
|
* a known configuration that will guarantee the kinetis_ifup() always
|
||||||
* successfully brings the interface back up.
|
* successfully brings the interface back up.
|
||||||
*/
|
*/
|
||||||
#warning "Missing logic"
|
|
||||||
|
kinetis_reset(priv);
|
||||||
|
|
||||||
/* Mark the device "down" */
|
/* Mark the device "down" */
|
||||||
|
|
||||||
@ -699,11 +963,18 @@ static int kinetis_txavail(struct uip_driver_s *dev)
|
|||||||
|
|
||||||
if (priv->bifup)
|
if (priv->bifup)
|
||||||
{
|
{
|
||||||
/* Check if there is room in the hardware to hold another outgoing packet. */
|
/* Check if there is room in the hardware to hold another outgoing
|
||||||
|
* packet.
|
||||||
|
*/
|
||||||
|
|
||||||
/* If so, then poll uIP for new XMIT data */
|
if (!kinetics_txringfull(priv))
|
||||||
|
{
|
||||||
|
/* No, there is space for another transfer. Poll uIP for new
|
||||||
|
* XMIT data.
|
||||||
|
*/
|
||||||
|
|
||||||
(void)uip_poll(&priv->dev, kinetis_uiptxpoll);
|
(void)uip_poll(&priv->dev, kinetis_uiptxpoll);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
irqrestore(flags);
|
irqrestore(flags);
|
||||||
@ -912,7 +1183,7 @@ static int kinetis_readmii(struct kinetis_driver_s *priv, uint8_t phyaddr,
|
|||||||
|
|
||||||
/* And return the MII data */
|
/* And return the MII data */
|
||||||
|
|
||||||
*data = (uint16_t)(getreg32(KINETIS_ENET_MMFR) & ENET_MMFR_DATA_MASK));
|
*data = (uint16_t)(getreg32(KINETIS_ENET_MMFR) & ENET_MMFR_DATA_MASK);
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -946,13 +1217,13 @@ static inline void kinetis_initphy(struct kinetis_driver_s *priv)
|
|||||||
{
|
{
|
||||||
usleep(LINK_WAITUS);
|
usleep(LINK_WAITUS);
|
||||||
phydata = 0xffff;
|
phydata = 0xffff;
|
||||||
kinetis_readmii(priv, 0, CONFIG_ENET_PHYADDR, MII_PHYID1, &phydata);
|
kinetis_readmii(priv, CONFIG_ENET_PHYADDR, MII_PHYID1, &phydata);
|
||||||
}
|
}
|
||||||
while (phydata == 0xffff);
|
while (phydata == 0xffff);
|
||||||
|
|
||||||
/* Start auto negotiation */
|
/* Start auto negotiation */
|
||||||
|
|
||||||
kinetis_writemii(priv, 0, CONFIG_ENET_PHYADDR, MII_MCR,
|
kinetis_writemii(priv, CONFIG_ENET_PHYADDR, MII_MCR,
|
||||||
(MII_MCR_ANRESTART | MII_MCR_ANENABLE));
|
(MII_MCR_ANRESTART | MII_MCR_ANENABLE));
|
||||||
|
|
||||||
/* Wait (potentially forever) for auto negotiation to complete */
|
/* Wait (potentially forever) for auto negotiation to complete */
|
||||||
@ -960,7 +1231,7 @@ static inline void kinetis_initphy(struct kinetis_driver_s *priv)
|
|||||||
do
|
do
|
||||||
{
|
{
|
||||||
usleep(LINK_WAITUS);
|
usleep(LINK_WAITUS);
|
||||||
kinetis_readmii(0, CONFIG_ENET_PHYADDR, MII_MSR, &phydata);
|
kinetis_readmii(priv, CONFIG_ENET_PHYADDR, MII_MSR, &phydata);
|
||||||
|
|
||||||
}
|
}
|
||||||
while ((phydata & MII_MSR_ANEGCOMPLETE) == 0);
|
while ((phydata & MII_MSR_ANEGCOMPLETE) == 0);
|
||||||
@ -968,7 +1239,7 @@ static inline void kinetis_initphy(struct kinetis_driver_s *priv)
|
|||||||
/* When we get here we have a link - Find the negotiated speed and duplex. */
|
/* When we get here we have a link - Find the negotiated speed and duplex. */
|
||||||
|
|
||||||
phydata = 0;
|
phydata = 0;
|
||||||
kinetis_readmii(0, CONFIG_ENET_PHYADDR, PHY_STATUS, &phydata);
|
kinetis_readmii(priv, CONFIG_ENET_PHYADDR, PHY_STATUS, &phydata);
|
||||||
|
|
||||||
/* Set up the transmit and receive contrel registers based on the
|
/* Set up the transmit and receive contrel registers based on the
|
||||||
* configuration and the auto negotiation results.
|
* configuration and the auto negotiation results.
|
||||||
@ -981,7 +1252,7 @@ static inline void kinetis_initphy(struct kinetis_driver_s *priv)
|
|||||||
rcr = ENET_RCR_RMII_MODE | ENET_RCR_CRCFWD |
|
rcr = ENET_RCR_RMII_MODE | ENET_RCR_CRCFWD |
|
||||||
CONFIG_NET_BUFSIZE << ENET_RCR_MAX_FL_SHIFT;
|
CONFIG_NET_BUFSIZE << ENET_RCR_MAX_FL_SHIFT;
|
||||||
#endif
|
#endif
|
||||||
tcr = 0
|
tcr = 0;
|
||||||
|
|
||||||
putreg32(rcr, KINETIS_ENET_RCR);
|
putreg32(rcr, KINETIS_ENET_RCR);
|
||||||
putreg32(tcr, KINETIS_ENET_TCR);
|
putreg32(tcr, KINETIS_ENET_TCR);
|
||||||
@ -1005,7 +1276,7 @@ static inline void kinetis_initphy(struct kinetis_driver_s *priv)
|
|||||||
{
|
{
|
||||||
/* 10Mbps */
|
/* 10Mbps */
|
||||||
|
|
||||||
ENET_RCR |= ENET_RCR_RMII_10T;
|
rcr |= ENET_RCR_RMII_10T;
|
||||||
}
|
}
|
||||||
|
|
||||||
putreg32(rcr, KINETIS_ENET_RCR);
|
putreg32(rcr, KINETIS_ENET_RCR);
|
||||||
@ -1031,40 +1302,44 @@ static inline void kinetis_initphy(struct kinetis_driver_s *priv)
|
|||||||
static void kinetis_initbuffers(struct kinetis_driver_s *priv)
|
static void kinetis_initbuffers(struct kinetis_driver_s *priv)
|
||||||
{
|
{
|
||||||
uintptr_t addr;
|
uintptr_t addr;
|
||||||
uint8_t *desc;
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* Get an aligned TX descriptor address */
|
/* Get an aligned TX descriptor (array)address */
|
||||||
|
|
||||||
addr = (uintptr_t)priv->desc + 0x0f) & ~0x0f;
|
addr = ((uintptr_t)priv->desc + 0x0f) & ~0x0f;
|
||||||
g_txdesc = (struct enet_desc_s *)addr;
|
priv->txdesc = (struct enet_desc_s *)addr;
|
||||||
|
|
||||||
/* Get an aligned RX descriptor (array) address */
|
/* Get an aligned RX descriptor (array) address */
|
||||||
|
|
||||||
addr += sizeof(struct enet_desc_s);
|
addr += CONFIG_ENET_NTXBUFFERS * sizeof(struct enet_desc_s);
|
||||||
g_txdesc = (struct enet_desc_s *)addr;
|
priv->txdesc = (struct enet_desc_s *)addr;
|
||||||
|
|
||||||
/* There is no TX buffer (the RX buffer is reused). */
|
/* Get the beginning of the first aligned buffer */
|
||||||
|
|
||||||
g_txdesc->length = 0;
|
addr = ((uintptr_t)priv->buffers + 0x0f) & ~0x0f;
|
||||||
g_txdesc->status1 = TXDESC_W;
|
|
||||||
#ifdef CONFIG_ENET_ENHANCEDBD
|
|
||||||
g_txdesc->status2 = TXDESC_IINS | TXDESC_PINS;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Get the beginning of the first aligned RX buffer */
|
/* Then fill in the TX descriptors */
|
||||||
|
|
||||||
addr = ((uintptr_t)priv->rxbuffers + 0x0f) & ~0x0f;
|
|
||||||
|
|
||||||
/* Then fill in the Rx descriptors */
|
|
||||||
|
|
||||||
for (i = 0; i < CONFIG_ENET_NTXBUFFERS; i++)
|
for (i = 0; i < CONFIG_ENET_NTXBUFFERS; i++)
|
||||||
|
{
|
||||||
|
priv->txdesc[i].status1 = 0;
|
||||||
|
priv->txdesc[i].length = 0;
|
||||||
|
priv->txdesc[i].data = (uint8_t*)kinesis_swap32((uint32_t)addr);
|
||||||
|
#ifdef CONFIG_ENET_ENHANCEDBD
|
||||||
|
priv->txdesc[i].status2 = TXDESC_IINS | TXDESC_PINS;
|
||||||
|
#endif
|
||||||
|
addr += CONFIG_NET_BUFSIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Then fill in the RX descriptors */
|
||||||
|
|
||||||
|
for (i = 0; i < CONFIG_ENET_NRXBUFFERS; i++)
|
||||||
{
|
{
|
||||||
priv->rxdesc[i].status1 = RXDESC_E;
|
priv->rxdesc[i].status1 = RXDESC_E;
|
||||||
priv->rxdesc[i].length = 0;
|
priv->rxdesc[i].length = 0;
|
||||||
priv->rxdesc[i].data = (uint8_t*)kinesis_swap32((uint32_t)addr);
|
priv->rxdesc[i].data = (uint8_t*)kinesis_swap32((uint32_t)addr);
|
||||||
#ifdef CONFIG_ENET_ENHANCEDBD
|
#ifdef CONFIG_ENET_ENHANCEDBD
|
||||||
priv->rxdesc[i].bdu = 0x00000000;
|
priv->rxdesc[i].bdu = 0;
|
||||||
priv->rxdesc[i].status2 = RXDESC_INT;
|
priv->rxdesc[i].status2 = RXDESC_INT;
|
||||||
#endif
|
#endif
|
||||||
addr += CONFIG_NET_BUFSIZE;
|
addr += CONFIG_NET_BUFSIZE;
|
||||||
@ -1072,11 +1347,14 @@ static void kinetis_initbuffers(struct kinetis_driver_s *priv)
|
|||||||
|
|
||||||
/* Set the wrap bit in the last descriptors to form a ring */
|
/* Set the wrap bit in the last descriptors to form a ring */
|
||||||
|
|
||||||
priv->rxdesc[CONFIG_ENET_NTXBUFFERS - 1].status1 |= RXDESC_W;
|
priv->txdesc[CONFIG_ENET_NTXBUFFERS-1].status1 |= TXDESC_W;
|
||||||
|
priv->rxdesc[CONFIG_ENET_NRXBUFFERS-1].status1 |= RXDESC_W;
|
||||||
|
|
||||||
/* We start with descriptor 0 */
|
/* We start with RX descriptor 0 and with no TX descriptors in use */
|
||||||
|
|
||||||
priv->nextdesc = 0;
|
priv->txtail = 0;
|
||||||
|
priv->txhead = 0;
|
||||||
|
priv->rxtail = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@ -1116,7 +1394,7 @@ static void kinetis_reset(struct kinetis_driver_s *priv)
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Function: kinetis_initialize
|
* Function: kinetis_netinitialize
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Initialize the Ethernet controller and driver
|
* Initialize the Ethernet controller and driver
|
||||||
@ -1132,7 +1410,7 @@ static void kinetis_reset(struct kinetis_driver_s *priv)
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
int kinetis_initialize(int intf)
|
int kinetis_netinitialize(int intf)
|
||||||
{
|
{
|
||||||
struct kinetis_driver_s *priv;
|
struct kinetis_driver_s *priv;
|
||||||
uint32_t regval;
|
uint32_t regval;
|
||||||
@ -1145,7 +1423,7 @@ int kinetis_initialize(int intf)
|
|||||||
/* Enable the ENET clock */
|
/* Enable the ENET clock */
|
||||||
|
|
||||||
regval = getreg32(KINETIS_SIM_SCGC2);
|
regval = getreg32(KINETIS_SIM_SCGC2);
|
||||||
regval |= SIM_SCGC2_ENET
|
regval |= SIM_SCGC2_ENET;
|
||||||
putreg32(regval, KINETIS_SIM_SCGC2);
|
putreg32(regval, KINETIS_SIM_SCGC2);
|
||||||
|
|
||||||
/* Allow concurrent access to MPU controller. Example: ENET uDMA to SRAM,
|
/* Allow concurrent access to MPU controller. Example: ENET uDMA to SRAM,
|
||||||
@ -1154,18 +1432,6 @@ int kinetis_initialize(int intf)
|
|||||||
|
|
||||||
putreg32(0, KINETIS_MPU_CESR);
|
putreg32(0, KINETIS_MPU_CESR);
|
||||||
|
|
||||||
/* Initialize ENET buffer */
|
|
||||||
|
|
||||||
kinetis_initbuffers(priv);
|
|
||||||
|
|
||||||
/* Reset and disable the interface */
|
|
||||||
|
|
||||||
kinetis_reset(priv);
|
|
||||||
|
|
||||||
/* Configure the MII interface */
|
|
||||||
|
|
||||||
kinetis_initmii(priv);
|
|
||||||
|
|
||||||
/* Configure all ENET/MII pins */
|
/* Configure all ENET/MII pins */
|
||||||
|
|
||||||
#if CONFIG_ENET_USEMII
|
#if CONFIG_ENET_USEMII
|
||||||
@ -1213,6 +1479,7 @@ int kinetis_initialize(int intf)
|
|||||||
{
|
{
|
||||||
/* We could not attach the ISR to the interrupt */
|
/* We could not attach the ISR to the interrupt */
|
||||||
|
|
||||||
|
ndbg("Failed to attach EMACTMR IRQ\n");
|
||||||
return -EAGAIN;
|
return -EAGAIN;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -1223,6 +1490,7 @@ int kinetis_initialize(int intf)
|
|||||||
{
|
{
|
||||||
/* We could not attach the ISR to the interrupt */
|
/* We could not attach the ISR to the interrupt */
|
||||||
|
|
||||||
|
ndbg("Failed to attach EMACTX IRQ\n");
|
||||||
return -EAGAIN;
|
return -EAGAIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1232,6 +1500,7 @@ int kinetis_initialize(int intf)
|
|||||||
{
|
{
|
||||||
/* We could not attach the ISR to the interrupt */
|
/* We could not attach the ISR to the interrupt */
|
||||||
|
|
||||||
|
ndbg("Failed to attach EMACRX IRQ\n");
|
||||||
return -EAGAIN;
|
return -EAGAIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1241,52 +1510,10 @@ int kinetis_initialize(int intf)
|
|||||||
{
|
{
|
||||||
/* We could not attach the ISR to the interrupt */
|
/* We could not attach the ISR to the interrupt */
|
||||||
|
|
||||||
|
ndbg("Failed to attach EMACMISC IRQ\n");
|
||||||
return -EAGAIN;
|
return -EAGAIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Clear the Individual and Group Address Hash registers */
|
|
||||||
|
|
||||||
putreg32(0, KINETIS_ENET_IALR);
|
|
||||||
putreg32(0, KINETIS_ENET_IAUR);
|
|
||||||
putreg32(0, KINETIS_ENET_GALR);
|
|
||||||
putreg32(0, KINETIS_ENET_GAUR);
|
|
||||||
|
|
||||||
/* Configure the PHY */
|
|
||||||
|
|
||||||
kinetis_initphy(priv);
|
|
||||||
|
|
||||||
/* Handle promiscuous mode */
|
|
||||||
|
|
||||||
#ifdef CONFIG_NET_PROMISCUOUS
|
|
||||||
regval = getreg32(KINETIS_ENET_RCR);
|
|
||||||
regval |= ENET_RCR_PROM;
|
|
||||||
putreg32(regval, KINETIS_ENET_RCR);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Select legacy of enhanced buffer descriptor format */
|
|
||||||
|
|
||||||
#ifdef CONFIG_ENET_ENHANCEDBD
|
|
||||||
putreg32(ENET_ECR_EN1588, KINETIS_ENET_ECR);
|
|
||||||
#else
|
|
||||||
putreg32(0, KINETIS_ENET_ECR);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Set the RX buffer size */
|
|
||||||
|
|
||||||
putreg32(CONFIG_NET_BUFSIZE, KINETIS_ENET_MRBR);
|
|
||||||
|
|
||||||
/* Point to the start of the circular RX buffer descriptor queue */
|
|
||||||
|
|
||||||
putreg32((uint32_t)priv->rxdesc, KINETIS_ENET_RDSR);
|
|
||||||
|
|
||||||
/* Point to the single TX buffer descriptor */
|
|
||||||
|
|
||||||
putreg32((uint32_t)priv->txdesc, KINETIS_ENET_TDSR);
|
|
||||||
|
|
||||||
/* Indicate that there have been empty receive buffers produced */
|
|
||||||
|
|
||||||
putreg32(ENET_RDAR, KINETIS_ENET_RDAR);
|
|
||||||
|
|
||||||
/* Initialize the driver structure */
|
/* Initialize the driver structure */
|
||||||
|
|
||||||
memset(priv, 0, sizeof(struct kinetis_driver_s));
|
memset(priv, 0, sizeof(struct kinetis_driver_s));
|
||||||
@ -1297,28 +1524,12 @@ int kinetis_initialize(int intf)
|
|||||||
priv->dev.d_addmac = kinetis_addmac; /* Add multicast MAC address */
|
priv->dev.d_addmac = kinetis_addmac; /* Add multicast MAC address */
|
||||||
priv->dev.d_rmmac = kinetis_rmmac; /* Remove multicast MAC address */
|
priv->dev.d_rmmac = kinetis_rmmac; /* Remove multicast MAC address */
|
||||||
#endif
|
#endif
|
||||||
priv->dev.d_private = (void*)g_enet; /* Used to recover private state from dev */
|
priv->dev.d_private = (void*)g_enet; /* Used to recover private state from dev */
|
||||||
|
|
||||||
/* Create a watchdog for timing polling for and timing of transmisstions */
|
/* Create a watchdog for timing polling for and timing of transmisstions */
|
||||||
|
|
||||||
priv->txpoll = wd_create(); /* Create periodic poll timer */
|
priv->txpoll = wd_create(); /* Create periodic poll timer */
|
||||||
priv->txtimeout = wd_create(); /* Create TX timeout timer */
|
priv->txtimeout = wd_create(); /* Create TX timeout timer */
|
||||||
|
|
||||||
/* Clear all pending ENET interrupt */
|
|
||||||
|
|
||||||
putreg32(0xffffffff, KINETIS_ENET_EIR);
|
|
||||||
|
|
||||||
/* Enable interrupts (interrupts are still disabled at the NVIC). */
|
|
||||||
|
|
||||||
putreg32(ENET_INT_BABR | ENET_INT_TXF | ENET_INT_RXF | ENET_INT_RXB |
|
|
||||||
ENET_INT_EBERR | ENET_INT_LC | ENET_INT_RL | ENET_INT_UN,
|
|
||||||
KINETIS_ENET_EIMR);
|
|
||||||
|
|
||||||
/* And enable the MAC itself */
|
|
||||||
|
|
||||||
regval = getreg32(KINETIS_ENET_ECR);
|
|
||||||
regval |= ENET_ECR_ETHEREN;
|
|
||||||
putreg32(regval, KINETIS_ENET_ECR);
|
|
||||||
|
|
||||||
/* Put the interface in the down state. This usually amounts to resetting
|
/* Put the interface in the down state. This usually amounts to resetting
|
||||||
* the device and/or calling kinetis_ifdown().
|
* the device and/or calling kinetis_ifdown().
|
||||||
@ -1332,5 +1543,23 @@ int kinetis_initialize(int intf)
|
|||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: up_netinitialize
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Initialize the first network interface. If there are more than one
|
||||||
|
* interface in the chip, then board-specific logic will have to provide
|
||||||
|
* this function to determine which, if any, Ethernet controllers should
|
||||||
|
* be initialized.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#if CONFIG_ENET_NETHIFS == 1
|
||||||
|
void up_netinitialize(void)
|
||||||
|
{
|
||||||
|
(void)kinetis_netinitialize(0);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* KINETIS_NENET > 0 */
|
#endif /* KINETIS_NENET > 0 */
|
||||||
#endif /* CONFIG_NET && CONFIG_KINETIS_ENET */
|
#endif /* CONFIG_NET && CONFIG_KINETIS_ENET */
|
||||||
|
@ -320,7 +320,7 @@
|
|||||||
/* Receive FIFO Almost Empty Threshold */
|
/* Receive FIFO Almost Empty Threshold */
|
||||||
|
|
||||||
#define ENET_RAEM_SHIFT (0) /* Bits 0-7: Value of the receive FIFO almost empty threshold */
|
#define ENET_RAEM_SHIFT (0) /* Bits 0-7: Value of the receive FIFO almost empty threshold */
|
||||||
#define ENET_RSEM_MASK (0xff << ENET_RAEM_SHIFT)
|
#define ENET_RAEM_MASK (0xff << ENET_RAEM_SHIFT)
|
||||||
/* Bits 8-31: Reserved */
|
/* Bits 8-31: Reserved */
|
||||||
/* Receive FIFO Almost Full Threshold */
|
/* Receive FIFO Almost Full Threshold */
|
||||||
|
|
||||||
@ -462,7 +462,7 @@
|
|||||||
# define TXDESC_W (1 << 13) /* Common */
|
# define TXDESC_W (1 << 13) /* Common */
|
||||||
# define TXDESC_TO1 (1 << 14) /* Common */
|
# define TXDESC_TO1 (1 << 14) /* Common */
|
||||||
# define TXDESC_R (1 << 15) /* Common */
|
# define TXDESC_R (1 << 15) /* Common */
|
||||||
#endif
|
#else
|
||||||
# define TXDESC_ABC (1 << 1) /* Legacy */
|
# define TXDESC_ABC (1 << 1) /* Legacy */
|
||||||
# define TXDESC_TC (1 << 2) /* Common */
|
# define TXDESC_TC (1 << 2) /* Common */
|
||||||
# define TXDESC_L (1 << 3) /* Common */
|
# define TXDESC_L (1 << 3) /* Common */
|
||||||
@ -489,7 +489,6 @@
|
|||||||
# define TXDESC_INT (1 << 30)
|
# define TXDESC_INT (1 << 30)
|
||||||
|
|
||||||
# define TXDESC_BDU (1 << 31)
|
# define TXDESC_BDU (1 << 31)
|
||||||
|
|
||||||
#else
|
#else
|
||||||
# define TXDESC_IINS (1 << 3)
|
# define TXDESC_IINS (1 << 3)
|
||||||
# define TXDESC_PINS (1 << 4)
|
# define TXDESC_PINS (1 << 4)
|
||||||
|
@ -557,8 +557,10 @@ TWR-K60N512-specific Configuration Options
|
|||||||
|
|
||||||
Kenetis ethernet controller settings
|
Kenetis ethernet controller settings
|
||||||
|
|
||||||
CONFIG_ENET_NBUFFERS - Number of TX/RX buffers. The size of one
|
CONFIG_ENET_NRXBUFFERS - Number of RX buffers. The size of one
|
||||||
buffer is determined by CONFIG_NET_BUFSIZE. Default: 8
|
buffer is determined by CONFIG_NET_BUFSIZE. Default: 6
|
||||||
|
CONFIG_ENET_NTXBUFFERS - Number of TX buffers. The size of one
|
||||||
|
buffer is determined by CONFIG_NET_BUFSIZE. Default: 2
|
||||||
CONFIG_ENET_USEMII - Usee MII mode. Default: RMII mode.
|
CONFIG_ENET_USEMII - Usee MII mode. Default: RMII mode.
|
||||||
CONFIG_ENET_PHYADDR - PHY address
|
CONFIG_ENET_PHYADDR - PHY address
|
||||||
|
|
||||||
|
@ -163,7 +163,7 @@ static int skel_transmit(FAR struct skel_driver_s *skel)
|
|||||||
{
|
{
|
||||||
/* Verify that the hardware is ready to send another packet. If we get
|
/* Verify that the hardware is ready to send another packet. If we get
|
||||||
* here, then we are committed to sending a packet; Higher level logic
|
* here, then we are committed to sending a packet; Higher level logic
|
||||||
* must have assured that there is not transmission in progress.
|
* must have assured that there is no transmission in progress.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Increment statistics */
|
/* Increment statistics */
|
||||||
|
Loading…
Reference in New Issue
Block a user