Kinetis SDK v.2.0 API Reference Manual  Rev. 0
Freescale Semiconductor, Inc.
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
ENET: Ethernet MAC Driver

Overview

The KSDK provides a peripheral driver for the 10/100 Mbps Ethernet MAC (ENET) module of Kinetis devices.

The MII interface is the interface connected with MAC and PHY. the Serial management interface - MII management interface should be set firstly before any access to external PHY chip register. So call ENET_SetSMI() to initialize MII management interface. Use ENET_StartSMIRead(), ENET_StartSMIWrite() and ENET_ReadSMIData() to read/write phy registers. This function group sets up the MII and serial management SMI interface, gets data from the SMI interface, and starts the SMI read and write command. Use ENET_SetMII() to configure the MII before successfully get the data from the external PHY.

This group sets/gets the ENET mac address, setting the multicast group address filter. ENET_AddMulticastGroup() should be called to add the ENET MAC to multicast group. It is important for 1588 feature to receive the PTP message.

For ENET receive side, ENET_GetRxFrameSize() must be called firstly used to get the received data size, then call ENET_ReadFrame() to get the received data. If the received error happen, call ENET_GetRxErrBeforeReadFrame() after ENET_GetRxFrameSize() and before ENET_ReadFrame() to get the detail error informations.

For ENET transmit side, simply call ENET_SendFrame() to send the data out. The transmit data error information only accessible for 1588 enhanced buffer descriptor mode. So when ENET_ENHANCEDBUFFERDESCRIPTOR_MODE is defined the ENET_GetTxErrAfterSendFrame() can be used to get the detail transmit error information. The transmit error information only be updated by uDMA after the data is transmit. So ENET_GetTxErrAfterSendFrame() is recommended to be called on transmit interrupt handler.

This function group configures the PTP 1588 feature, starts/stops/gets/sets/adjusts the PTP IEEE 1588 timer, gets the receive/transmit frame timestamp, and PTP IEEE 1588 timer channel feature setting.

ENET_Ptp1588Configure() must be called when ENET_ENHANCEDBUFFERDESCRIPTOR_MODE is defined and the 1588 feature is required. The ENET_GetRxFrameTime() and ENET_GetTxFrameTime() are called by PTP stack to get the timestamp captured by ENET driver.

Typical use case

ENET Initialization, receive, and transmit operation

For ENET_ENHANCEDBUFFERDESCRIPTOR_MODE not defined use case, use the legacy type buffer descriptor transmit/receive the frame:

enet_config_t config;
uint32_t length = 0;
uint32_t sysClock;
uint32_t phyAddr = 0;
bool link = false;
phy_speed_t speed;
phy_duplex_t duplex;
enet_status_t result;
// Prepares the buffer configuration.
{
ENET_RXBD_NUM,
ENET_TXBD_NUM,
ENET_BuffSizeAlign(ENET_RXBUFF_SIZE),
ENET_BuffSizeAlign(ENET_TXBUFF_SIZE),
&RxBuffDescrip[0], // Prepare buffers
&TxBuffDescrip[0], // Prepare buffers
&RxDataBuff[0][0], // Prepare buffers
&TxDataBuff[0][0], // Prepare buffers
};
// Gets the default configuration.
PHY_Init(EXAMPLE_ENET, 0, sysClock);
// Changes the link status to PHY auto-negotiated link status.
PHY_GetLinkStatus(EXAMPLE_ENET, phyAddr, &link);
if (link)
{
PHY_GetLinkSpeedDuplex(EXAMPLE_ENET, phyAddr, &speed, &duplex);
config.miiSpeed = (enet_mii_speed_t)speed;
config.miiDuplex = (enet_mii_duplex_t)duplex;
}
ENET_Init(EXAMPLE_ENET, &handle, &config, &buffCfg, &macAddr[0], sysClock);
ENET_ActiveRead(EXAMPLE_ENET);
while (1)
{
// Gets the frame size.
result = ENET_GetRxFrameSize(&handle, &length);
// Calls the ENET_ReadFrame when there is a received frame.
if (length != 0)
{
// Receives a valid frame and delivers the receive buffer with the size equal to length.
uint8_t *data = (uint8_t *)malloc(length);
ENET_ReadFrame(EXAMPLE_ENET, &handle, data, length);
// Delivers the data to the upper layer.
.........
free(data);
}
else if (result == kStatus_ENET_RxFrameErr)
{
// Updates the received buffer when an error occurs.
ENET_GetRxErrBeforeReadFrame(&handle, &eErrStatic);
// Updates the receive buffer.
ENET_ReadFrame(EXAMPLE_ENET, &handle, NULL, 0);
}
// Sends a multicast frame when the PHY is linked up.
if(kStatus_Success == PHY_GetLinkStatus(EXAMPLE_ENET, phyAddr, &link))
{
if(link)
{
ENET_SendFrame(EXAMPLE_ENET, &handle, &frame[0], ENET_DATA_LENGTH);
}
}
}

For ENET_ENHANCEDBUFFERDESCRIPTOR_MODE defined case, add the PTP IEEE 1588 configuration to enable the PTP IEEE 1588 feature. The initialization occurs as follows:

uint32_t length = 0;
uint32_t sysClock;
uint32_t phyAddr = 0;
bool link = false;
phy_speed_t speed;
phy_duplex_t duplex;
enet_status_t result;
enet_data_err_stats_t eErrStatic;
{
ENET_RXBD_NUM,
ENET_TXBD_NUM,
ENET_BuffSizeAlign(ENET_RXBUFF_SIZE),
ENET_BuffSizeAlign(ENET_TXBUFF_SIZE),
&RxBuffDescrip[0],
&TxBuffDescrip[0],
&RxDataBuff[0][0],
&TxDataBuff[0][0],
};
// Sets the PTP 1588 source.
CLOCK_SetEnetTime0Clock(2);
// Prepares the PTP configuration.
enet_ptp_config_t ptpConfig =
{
ENET_RXBD_NUM,
ENET_TXBD_NUM,
&g_rxPtpTsBuff[0],
&g_txPtpTsBuff[0],
kENET_PtpTimerChannel1,
ptpClock,
};
// Gets the default configuration.
PHY_Init(EXAMPLE_ENET, 0, sysClock);
// Changes the link status to PHY auto-negotiated link status.
PHY_GetLinkStatus(EXAMPLE_ENET, phyAddr, &link);
if (link)
{
PHY_GetLinkSpeedDuplex(EXAMPLE_ENET, phyAddr, &speed, &duplex);
config.miiSpeed = (enet_mii_speed_t)speed;
config.miiDuplex = (enet_mii_duplex_t)duplex;
}
ENET_Init(EXAMPLE_ENET, &handle, &config, &buffCfg, &macAddr[0], sysClock);
// Configures the PTP 1588 feature.
ENET_Ptp1588Configure(EXAMPLE_ENET, &handle, &ptpConfig);
// Adds the device to the PTP multicast group.
ENET_AddMulticastGroup(EXAMPLE_ENET, &mGAddr[0]);
ENET_ActiveRead(EXAMPLE_ENET);

Files

file  fsl_enet.h
 

Data Structures

struct  enet_rx_bd_struct_t
 Defines the receive buffer descriptor structure for the little endian system. More...
 
struct  enet_tx_bd_struct_t
 Defines the enhanced transmit buffer descriptor structure for the little endian system. More...
 
struct  enet_data_error_stats_t
 Defines the ENET data error statistic structure. More...
 
struct  enet_buffer_config_t
 Defines the receive buffer descriptor configure structure. More...
 
struct  enet_config_t
 Defines the basic configuration structure for the ENET device. More...
 
struct  enet_handle_t
 Defines the ENET handler structure. More...
 

Macros

#define ENET_BUFFDESCRIPTOR_RX_ERR_MASK
 Defines the receive error status flag mask. More...
 
#define ENET_FIFO_MIN_RX_FULL   5U
 ENET minimum receive FIFO full. More...
 
#define ENET_RX_MIN_BUFFERSIZE   256U
 ENET minimum buffer size. More...
 
#define ENET_BUFF_ALIGNMENT   16U
 Ethernet buffer alignment. More...
 
#define ENET_PHY_MAXADDRESS   (ENET_MMFR_PA_MASK >> ENET_MMFR_PA_SHIFT)
 Defines the PHY address scope for the ENET. More...
 

Typedefs

typedef void(* enet_callback_t )(ENET_Type *base, enet_handle_t *handle, enet_event_t event, void *userData)
 ENET callback function. More...
 

Enumerations

enum  _enet_status {
  kStatus_ENET_RxFrameError = MAKE_STATUS(kStatusGroup_ENET, 0U),
  kStatus_ENET_RxFrameFail = MAKE_STATUS(kStatusGroup_ENET, 1U),
  kStatus_ENET_RxFrameEmpty = MAKE_STATUS(kStatusGroup_ENET, 2U),
  kStatus_ENET_TxFrameBusy,
  kStatus_ENET_TxFrameFail = MAKE_STATUS(kStatusGroup_ENET, 4U)
}
 Defines the status return codes for transaction. More...
 
enum  enet_mii_mode_t {
  kENET_MiiMode = 0U,
  kENET_RmiiMode
}
 Defines the RMII or MII mode for data interface between the MAC and the PHY. More...
 
enum  enet_mii_speed_t {
  kENET_MiiSpeed10M = 0U,
  kENET_MiiSpeed100M
}
 Defines the 10 Mbps or 100 Mbps speed for the MII data interface. More...
 
enum  enet_mii_duplex_t {
  kENET_MiiHalfDuplex = 0U,
  kENET_MiiFullDuplex
}
 Defines the half or full duplex for the MII data interface. More...
 
enum  enet_mii_write_t {
  kENET_MiiWriteNoCompliant = 0U,
  kENET_MiiWriteValidFrame
}
 Defines the write operation for the MII management frame. More...
 
enum  enet_mii_read_t {
  kENET_MiiReadValidFrame = 2U,
  kENET_MiiReadNoCompliant = 3U
}
 Defines the read operation for the MII management frame. More...
 
enum  enet_special_control_flag_t {
  kENET_ControlFlowControlEnable = 0x0001U,
  kENET_ControlRxPayloadCheckEnable = 0x0002U,
  kENET_ControlRxPadRemoveEnable = 0x0004U,
  kENET_ControlRxBroadCastRejectEnable = 0x0008U,
  kENET_ControlMacAddrInsert = 0x0010U,
  kENET_ControlStoreAndFwdDisable = 0x0020U,
  kENET_ControlSMIPreambleDisable = 0x0040U,
  kENET_ControlPromiscuousEnable = 0x0080U,
  kENET_ControlMIILoopEnable = 0x0100U,
  kENET_ControlVLANTagEnable = 0x0200U
}
 Defines a special configuration for ENET MAC controller. More...
 
enum  enet_interrupt_enable_t {
  kENET_BabrInterrupt = ENET_EIR_BABR_MASK,
  kENET_BabtInterrupt = ENET_EIR_BABT_MASK,
  kENET_GraceStopInterrupt = ENET_EIR_GRA_MASK,
  kENET_TxFrameInterrupt = ENET_EIR_TXF_MASK,
  kENET_TxByteInterrupt = ENET_EIR_TXB_MASK,
  kENET_RxFrameInterrupt = ENET_EIR_RXF_MASK,
  kENET_RxByteInterrupt = ENET_EIR_RXB_MASK,
  kENET_MiiInterrupt = ENET_EIR_MII_MASK,
  kENET_EBusERInterrupt = ENET_EIR_EBERR_MASK,
  kENET_LateCollisionInterrupt = ENET_EIR_LC_MASK,
  kENET_RetryLimitInterrupt = ENET_EIR_RL_MASK,
  kENET_UnderrunInterrupt = ENET_EIR_UN_MASK,
  kENET_PayloadRxInterrupt = ENET_EIR_PLR_MASK,
  kENET_WakeupInterrupt = ENET_EIR_WAKEUP_MASK
}
 List of interrupts supported by the peripheral. More...
 
enum  enet_event_t {
  kENET_RxEvent,
  kENET_TxEvent,
  kENET_ErrEvent,
  kENET_WakeUpEvent
}
 Defines the common interrupt event for callback use. More...
 
enum  enet_tx_accelerator_t {
  kENET_TxAccelIsShift16Enabled = ENET_TACC_SHIFT16_MASK,
  kENET_TxAccelIpCheckEnabled = ENET_TACC_IPCHK_MASK,
  kENET_TxAccelProtoCheckEnabled = ENET_TACC_PROCHK_MASK
}
 Defines the transmit accelerator configuration. More...
 
enum  enet_rx_accelerator_t {
  kENET_RxAccelPadRemoveEnabled = ENET_RACC_PADREM_MASK,
  kENET_RxAccelIpCheckEnabled = ENET_RACC_IPDIS_MASK,
  kENET_RxAccelProtoCheckEnabled = ENET_RACC_PRODIS_MASK,
  kENET_RxAccelMacCheckEnabled = ENET_RACC_LINEDIS_MASK,
  kENET_RxAccelisShift16Enabled = ENET_RACC_SHIFT16_MASK
}
 Defines the receive accelerator configuration. More...
 

Driver version

#define FSL_ENET_DRIVER_VERSION   (MAKE_VERSION(2, 0, 0))
 Defines the driver version. More...
 

Control and status region bit masks of the receive buffer descriptor.

#define ENET_BUFFDESCRIPTOR_RX_EMPTY_MASK   0x8000U
 Empty bit mask. More...
 
#define ENET_BUFFDESCRIPTOR_RX_SOFTOWNER1_MASK   0x4000U
 Software owner one mask. More...
 
#define ENET_BUFFDESCRIPTOR_RX_WRAP_MASK   0x2000U
 Next buffer descriptor is the start address. More...
 
#define ENET_BUFFDESCRIPTOR_RX_SOFTOWNER2_Mask   0x1000U
 Software owner two mask. More...
 
#define ENET_BUFFDESCRIPTOR_RX_LAST_MASK   0x0800U
 Last BD of the frame mask. More...
 
#define ENET_BUFFDESCRIPTOR_RX_MISS_MASK   0x0100U
 Received because of the promiscuous mode. More...
 
#define ENET_BUFFDESCRIPTOR_RX_BROADCAST_MASK   0x0080U
 Broadcast packet mask. More...
 
#define ENET_BUFFDESCRIPTOR_RX_MULTICAST_MASK   0x0040U
 Multicast packet mask. More...
 
#define ENET_BUFFDESCRIPTOR_RX_LENVLIOLATE_MASK   0x0020U
 Length violation mask. More...
 
#define ENET_BUFFDESCRIPTOR_RX_NOOCTET_MASK   0x0010U
 Non-octet aligned frame mask. More...
 
#define ENET_BUFFDESCRIPTOR_RX_CRC_MASK   0x0004U
 CRC error mask. More...
 
#define ENET_BUFFDESCRIPTOR_RX_OVERRUN_MASK   0x0002U
 FIFO overrun mask. More...
 
#define ENET_BUFFDESCRIPTOR_RX_TRUNC_MASK   0x0001U
 Frame is truncated mask. More...
 

Control and status bit masks of the transmit buffer descriptor.

#define ENET_BUFFDESCRIPTOR_TX_READY_MASK   0x8000U
 Ready bit mask. More...
 
#define ENET_BUFFDESCRIPTOR_TX_SOFTOWENER1_MASK   0x4000U
 Software owner one mask. More...
 
#define ENET_BUFFDESCRIPTOR_TX_WRAP_MASK   0x2000U
 Wrap buffer descriptor mask. More...
 
#define ENET_BUFFDESCRIPTOR_TX_SOFTOWENER2_MASK   0x1000U
 Software owner two mask. More...
 
#define ENET_BUFFDESCRIPTOR_TX_LAST_MASK   0x0800U
 Last BD of the frame mask. More...
 
#define ENET_BUFFDESCRIPTOR_TX_TRANMITCRC_MASK   0x0400U
 Transmit CRC mask. More...
 

Defines the maximum Ethernet frame size.

#define ENET_FRAME_MAX_FRAMELEN   1518U
 Maximum Ethernet frame size. More...
 
#define ENET_FRAME_MAX_VALNFRAMELEN   1522U
 Maximum VLAN frame size. More...
 

Initialization and De-initialization

void ENET_GetDefaultConfig (enet_config_t *config)
 Gets the ENET default configuration structure. More...
 
void ENET_Init (ENET_Type *base, enet_handle_t *handle, const enet_config_t *config, const enet_buffer_config_t *bufferConfig, uint8_t *macAddr, uint32_t srcClock_Hz)
 Initializes the ENET module. More...
 
void ENET_Deinit (ENET_Type *base)
 Deinitializes the ENET module. More...
 
static void ENET_Reset (ENET_Type *base)
 Resets the ENET module. More...
 

MII interface operation

void ENET_SetMII (ENET_Type *base, enet_mii_speed_t speed, enet_mii_duplex_t duplex)
 Sets the ENET MII speed and duplex. More...
 
void ENET_SetSMI (ENET_Type *base, uint32_t srcClock_Hz, bool isPreambleDisabled)
 Sets the ENET SMI(serial management interface)- MII management interface. More...
 
static bool ENET_GetSMI (ENET_Type *base)
 Gets the ENET SMI- MII management interface configuration. More...
 
static uint32_t ENET_ReadSMIData (ENET_Type *base)
 Reads data from the PHY register through SMI interface. More...
 
void ENET_StartSMIRead (ENET_Type *base, uint32_t phyAddr, uint32_t phyReg, enet_mii_read_t operation)
 Starts an SMI (Serial Management Interface) read command. More...
 
void ENET_StartSMIWrite (ENET_Type *base, uint32_t phyAddr, uint32_t phyReg, enet_mii_write_t operation, uint32_t data)
 Starts a SMI write command. More...
 

MAC Address Filter

void ENET_SetMacAddr (ENET_Type *base, uint8_t *macAddr)
 Sets the ENET module Mac address. More...
 
void ENET_GetMacAddr (ENET_Type *base, uint8_t *macAddr)
 Gets the ENET module Mac address. More...
 
void ENET_AddMulticastGroup (ENET_Type *base, uint8_t *address)
 Adds the ENET device to a multicast group. More...
 
void ENET_LeaveMulticastGroup (ENET_Type *base, uint8_t *address)
 Moves the ENET device from a multicast group. More...
 

Other basic operation

static void ENET_ActiveRead (ENET_Type *base)
 Activates ENET read or receive. More...
 
static void ENET_EnableSleepMode (ENET_Type *base, bool enable)
 Enables/disables the MAC to enter sleep mode. More...
 
static void ENET_GetAccelFunction (ENET_Type *base, uint32_t *txAccelOption, uint32_t *rxAccelOption)
 Gets ENET transmit and receive accelerator functions from MAC controller. More...
 

Interrupts.

static void ENET_EnableInterrupts (ENET_Type *base, uint32_t mask)
 Enables the ENET interrupt. More...
 
static void ENET_DisableInterrupts (ENET_Type *base, uint32_t mask)
 Disables the ENET interrupt. More...
 
static uint32_t ENET_GetInterruptStatus (ENET_Type *base)
 Gets the ENET interrupt status flag. More...
 
static void ENET_ClearInterruptStatus (ENET_Type *base, uint32_t mask)
 Clears the ENET interrupt events status flag. More...
 

Transactional operation

void ENET_SetCallback (enet_handle_t *handle, enet_callback_t callback, void *userData)
 Set the callback function. More...
 
void ENET_GetRxErrBeforeReadFrame (enet_handle_t *handle, enet_data_error_stats_t *eErrorStatic)
 Gets the ENET the error statistics of a received frame. More...
 
status_t ENET_GetRxFrameSize (enet_handle_t *handle, uint32_t *length)
 Gets the size of the read frame. More...
 
status_t ENET_ReadFrame (ENET_Type *base, enet_handle_t *handle, uint8_t *data, uint32_t length)
 Reads a frame from the ENET device. More...
 
status_t ENET_SendFrame (ENET_Type *base, enet_handle_t *handle, uint8_t *data, uint32_t length)
 Transmits an ENET frame. More...
 
void ENET_TransmitIRQHandler (ENET_Type *base, enet_handle_t *handle)
 The transmit IRQ handler. More...
 
void ENET_ReceiveIRQHandler (ENET_Type *base, enet_handle_t *handle)
 The receive IRQ handler. More...
 
void ENET_ErrorIRQHandler (ENET_Type *base, enet_handle_t *handle)
 The error IRQ handler. More...
 

Data Structure Documentation

struct enet_rx_bd_struct_t

Data Fields

uint16_t length
 Buffer descriptor data length. More...
 
uint16_t control
 Buffer descriptor control and status. More...
 
uint8_t * buffer
 Data buffer pointer. More...
 

Field Documentation

uint16_t enet_rx_bd_struct_t::length
uint16_t enet_rx_bd_struct_t::control
uint8_t* enet_rx_bd_struct_t::buffer
struct enet_tx_bd_struct_t

Data Fields

uint16_t length
 Buffer descriptor data length. More...
 
uint16_t control
 Buffer descriptor control and status. More...
 
uint8_t * buffer
 Data buffer pointer. More...
 

Field Documentation

uint16_t enet_tx_bd_struct_t::length
uint16_t enet_tx_bd_struct_t::control
uint8_t* enet_tx_bd_struct_t::buffer
struct enet_data_error_stats_t

Data Fields

uint32_t statsRxLenGreaterErr
 Receive length greater than RCR[MAX_FL]. More...
 
uint32_t statsRxAlignErr
 Receive non-octet alignment/.
 
uint32_t statsRxFcsErr
 Receive CRC error. More...
 
uint32_t statsRxOverRunErr
 Receive over run. More...
 
uint32_t statsRxTruncateErr
 Receive truncate. More...
 

Field Documentation

uint32_t enet_data_error_stats_t::statsRxLenGreaterErr
uint32_t enet_data_error_stats_t::statsRxFcsErr
uint32_t enet_data_error_stats_t::statsRxOverRunErr
uint32_t enet_data_error_stats_t::statsRxTruncateErr
struct enet_buffer_config_t

Note: For the internal DMA requirements, the buffers have a corresponding alignment requirement:

  1. The aligned receive and transmit buffer size must be evenly divisible by 16.
  2. The aligned transmit and receive buffer descriptor start address must be at least 64 bit aligned. However, it's recommended to be evenly divisible by 16.
  3. The aligned transmit and receive buffer start address must be evenly divisible by 16. Receive buffers should be continuous with the total size equal to "rxBdNumber * rxBuffSizeAlign". Transmit buffers should be continuous with the total size equal to "txBdNumber * txBuffSizeAlign".

Data Fields

uint16_t rxBdNumber
 Receive buffer descriptor number. More...
 
uint16_t txBdNumber
 Transmit buffer descriptor number. More...
 
uint32_t rxBuffSizeAlign
 Aligned receive data buffer size. More...
 
uint32_t txBuffSizeAlign
 Aligned transmit data buffer size. More...
 
volatile enet_rx_bd_struct_trxBdStartAddrAlign
 Aligned receive buffer descriptor start address. More...
 
volatile enet_tx_bd_struct_ttxBdStartAddrAlign
 Aligned transmit buffer descriptor start address. More...
 
uint8_t * rxBufferAlign
 Receive data buffer start address. More...
 
uint8_t * txBufferAlign
 Transmit data buffer start address. More...
 

Field Documentation

uint16_t enet_buffer_config_t::rxBdNumber
uint16_t enet_buffer_config_t::txBdNumber
uint32_t enet_buffer_config_t::rxBuffSizeAlign
uint32_t enet_buffer_config_t::txBuffSizeAlign
volatile enet_rx_bd_struct_t* enet_buffer_config_t::rxBdStartAddrAlign
volatile enet_tx_bd_struct_t* enet_buffer_config_t::txBdStartAddrAlign
uint8_t* enet_buffer_config_t::rxBufferAlign
uint8_t* enet_buffer_config_t::txBufferAlign
struct enet_config_t

Note:

  1. macSpecialConfig is used for a special control configuration, A logical OR of "enet_special_control_flag_t". For a special configuration for MAC, set this parameter to 0.
  2. txWatermark is used for a cut-through operation. It is in steps of 64 bytes: 0/1 - 64 bytes written to TX FIFO before transmission of a frame begins. 2 - 128 bytes written to TX FIFO .... 3 - 192 bytes written to TX FIFO .... The maximum of txWatermark is 0x2F - 4032 bytes written to TX FIFO .... txWatermark allows minimizing the transmit latency to set the txWatermark to 0 or 1 or for larger bus access latency 3 or larger due to contention for the system bus.
  3. rxFifoFullThreshold is similar to the txWatermark for cut-through operation in RX. It is in 64-bit words. The minimum is ENET_FIFO_MIN_RX_FULL and the maximum is 0xFF. If the end of the frame is stored in FIFO and the frame size if smaller than the txWatermark, the frame is still transmitted. The rule is the same for rxFifoFullThreshold in the receive direction.
  4. When "kENET_ControlFlowControlEnable" is set in the macSpecialConfig, ensure that the pauseDuration, rxFifoEmptyThreshold, and rxFifoStatEmptyThreshold are set for flow control enabled case.
  5. When "kENET_ControlStoreAndFwdDisabled" is set in the macSpecialConfig, ensure that the rxFifoFullThreshold and txFifoWatermark are set for store and forward disable.
  6. The rxAccelerConfig and txAccelerConfig default setting with 0 - accelerator are disabled. The "enet_tx_accelerator_t" and "enet_rx_accelerator_t" are recommended to be used to enable the transmit and receive accelerator. After the accelerators are enabled, the store and forward feature should be enabled. As a result, kENET_ControlStoreAndFwdDisabled should not be set.

Data Fields

uint32_t macSpecialConfig
 Mac special configuration. More...
 
uint32_t interrupt
 Mac interrupt source. More...
 
uint16_t rxMaxFrameLen
 Receive maximum frame length. More...
 
enet_mii_mode_t miiMode
 MII mode. More...
 
enet_mii_speed_t miiSpeed
 MII Speed. More...
 
enet_mii_duplex_t miiDuplex
 MII duplex. More...
 
uint8_t rxAccelerConfig
 Receive accelerator, A logical OR of "enet_rx_accelerator_t". More...
 
uint8_t txAccelerConfig
 Transmit accelerator, A logical OR of "enet_rx_accelerator_t". More...
 
uint16_t pauseDuration
 For flow control enabled case: Pause duration. More...
 
uint8_t rxFifoEmptyThreshold
 For flow control enabled case: when RX FIFO level reaches this value, it makes MAC generate XOFF pause frame. More...
 
uint8_t rxFifoFullThreshold
 For store and forward disable case, the data required in RX FIFO to notify the MAC receive ready status. More...
 
uint8_t txFifoWatermark
 For store and forward disable case, the data required in TX FIFO before a frame transmit start. More...
 

Field Documentation

uint32_t enet_config_t::macSpecialConfig

A logical OR of "enet_special_control_flag_t".

uint32_t enet_config_t::interrupt

A logical OR of "enet_interrupt_enable_t".

uint16_t enet_config_t::rxMaxFrameLen
enet_mii_mode_t enet_config_t::miiMode
enet_mii_speed_t enet_config_t::miiSpeed
enet_mii_duplex_t enet_config_t::miiDuplex
uint8_t enet_config_t::rxAccelerConfig
uint8_t enet_config_t::txAccelerConfig
uint16_t enet_config_t::pauseDuration
uint8_t enet_config_t::rxFifoEmptyThreshold
uint8_t enet_config_t::rxFifoFullThreshold
uint8_t enet_config_t::txFifoWatermark
struct _enet_handle

Data Fields

volatile enet_rx_bd_struct_trxBdBase
 Receive buffer descriptor base address pointer. More...
 
volatile enet_rx_bd_struct_trxBdCurrent
 The current available receive buffer descriptor pointer. More...
 
volatile enet_rx_bd_struct_trxBdDirty
 The dirty receive buffer descriptor needed to be updated from. More...
 
volatile enet_tx_bd_struct_ttxBdBase
 Transmit buffer descriptor base address pointer. More...
 
volatile enet_tx_bd_struct_ttxBdCurrent
 The current available transmit buffer descriptor pointer. More...
 
uint32_t rxBuffSizeAlign
 Receive buffer size alignment. More...
 
uint32_t txBuffSizeAlign
 Transmit buffer size alignment. More...
 
enet_callback_t callback
 Callback function. More...
 
void * userData
 Callback function parameter. More...
 

Field Documentation

volatile enet_rx_bd_struct_t* enet_handle_t::rxBdBase
volatile enet_rx_bd_struct_t* enet_handle_t::rxBdCurrent
volatile enet_rx_bd_struct_t* enet_handle_t::rxBdDirty
volatile enet_tx_bd_struct_t* enet_handle_t::txBdBase
volatile enet_tx_bd_struct_t* enet_handle_t::txBdCurrent
uint32_t enet_handle_t::rxBuffSizeAlign
uint32_t enet_handle_t::txBuffSizeAlign
enet_callback_t enet_handle_t::callback
void* enet_handle_t::userData

Macro Definition Documentation

#define FSL_ENET_DRIVER_VERSION   (MAKE_VERSION(2, 0, 0))

Version 2.0.0.

#define ENET_BUFFDESCRIPTOR_RX_EMPTY_MASK   0x8000U
#define ENET_BUFFDESCRIPTOR_RX_SOFTOWNER1_MASK   0x4000U
#define ENET_BUFFDESCRIPTOR_RX_WRAP_MASK   0x2000U
#define ENET_BUFFDESCRIPTOR_RX_SOFTOWNER2_Mask   0x1000U
#define ENET_BUFFDESCRIPTOR_RX_LAST_MASK   0x0800U
#define ENET_BUFFDESCRIPTOR_RX_MISS_MASK   0x0100U
#define ENET_BUFFDESCRIPTOR_RX_BROADCAST_MASK   0x0080U
#define ENET_BUFFDESCRIPTOR_RX_MULTICAST_MASK   0x0040U
#define ENET_BUFFDESCRIPTOR_RX_LENVLIOLATE_MASK   0x0020U
#define ENET_BUFFDESCRIPTOR_RX_NOOCTET_MASK   0x0010U
#define ENET_BUFFDESCRIPTOR_RX_CRC_MASK   0x0004U
#define ENET_BUFFDESCRIPTOR_RX_OVERRUN_MASK   0x0002U
#define ENET_BUFFDESCRIPTOR_RX_TRUNC_MASK   0x0001U
#define ENET_BUFFDESCRIPTOR_TX_READY_MASK   0x8000U
#define ENET_BUFFDESCRIPTOR_TX_SOFTOWENER1_MASK   0x4000U
#define ENET_BUFFDESCRIPTOR_TX_WRAP_MASK   0x2000U
#define ENET_BUFFDESCRIPTOR_TX_SOFTOWENER2_MASK   0x1000U
#define ENET_BUFFDESCRIPTOR_TX_LAST_MASK   0x0800U
#define ENET_BUFFDESCRIPTOR_TX_TRANMITCRC_MASK   0x0400U
#define ENET_BUFFDESCRIPTOR_RX_ERR_MASK
Value:
#define ENET_BUFFDESCRIPTOR_RX_LENVLIOLATE_MASK
Length violation mask.
Definition: fsl_enet.h:62
#define ENET_BUFFDESCRIPTOR_RX_TRUNC_MASK
Frame is truncated mask.
Definition: fsl_enet.h:66
#define ENET_BUFFDESCRIPTOR_RX_OVERRUN_MASK
FIFO overrun mask.
Definition: fsl_enet.h:65
#define ENET_BUFFDESCRIPTOR_RX_NOOCTET_MASK
Non-octet aligned frame mask.
Definition: fsl_enet.h:63
#define ENET_BUFFDESCRIPTOR_RX_CRC_MASK
CRC error mask.
Definition: fsl_enet.h:64
#define ENET_FRAME_MAX_FRAMELEN   1518U
#define ENET_FRAME_MAX_VALNFRAMELEN   1522U
#define ENET_FIFO_MIN_RX_FULL   5U
#define ENET_RX_MIN_BUFFERSIZE   256U
#define ENET_BUFF_ALIGNMENT   16U
#define ENET_PHY_MAXADDRESS   (ENET_MMFR_PA_MASK >> ENET_MMFR_PA_SHIFT)

Typedef Documentation

typedef void(* enet_callback_t)(ENET_Type *base, enet_handle_t *handle, enet_event_t event, void *userData)

Enumeration Type Documentation

Enumerator
kStatus_ENET_RxFrameError 

A frame received but data error happen.

kStatus_ENET_RxFrameFail 

Failed to receive a frame.

kStatus_ENET_RxFrameEmpty 

No frame arrive.

kStatus_ENET_TxFrameBusy 

Transmit buffer descriptors are under process.

kStatus_ENET_TxFrameFail 

Transmit frame fail.

Enumerator
kENET_MiiMode 

MII mode for data interface.

kENET_RmiiMode 

RMII mode for data interface.

Enumerator
kENET_MiiSpeed10M 

Speed 10 Mbps.

kENET_MiiSpeed100M 

Speed 100 Mbps.

Enumerator
kENET_MiiHalfDuplex 

Half duplex mode.

kENET_MiiFullDuplex 

Full duplex mode.

Enumerator
kENET_MiiWriteNoCompliant 

Write frame operation, but not MII-compliant.

kENET_MiiWriteValidFrame 

Write frame operation for a valid MII management frame.

Enumerator
kENET_MiiReadValidFrame 

Read frame operation for a valid MII management frame.

kENET_MiiReadNoCompliant 

Read frame operation, but not MII-compliant.

These control flags are provided for special user requirements. Normally, these control flags are unused for ENET initialization. For special requirements, set the flags to macSpecialConfig in the enet_config_t. The kENET_ControlStoreAndFwdDisable is used to disable the FIFO store and forward. FIFO store and forward means that the FIFO read/send is started when a complete frame is stored in TX/RX FIFO. If this flag is set, configure rxFifoFullThreshold and txFifoWatermark in the enet_config_t.

Enumerator
kENET_ControlFlowControlEnable 

Enable ENET flow control: pause frame.

kENET_ControlRxPayloadCheckEnable 

Enable ENET receive payload length check.

kENET_ControlRxPadRemoveEnable 

Padding is removed from received frames.

kENET_ControlRxBroadCastRejectEnable 

Enable broadcast frame reject.

kENET_ControlMacAddrInsert 

Enable MAC address insert.

kENET_ControlStoreAndFwdDisable 

Enable FIFO store and forward.

kENET_ControlSMIPreambleDisable 

Enable SMI preamble.

kENET_ControlPromiscuousEnable 

Enable promiscuous mode.

kENET_ControlMIILoopEnable 

Enable ENET MII loop back.

kENET_ControlVLANTagEnable 

Enable VLAN tag frame.

This enumeration uses one-bot encoding to allow a logical OR of multiple members. Members usually map to interrupt enable bits in one or more peripheral registers.

Enumerator
kENET_BabrInterrupt 

Babbling receive error interrupt source.

kENET_BabtInterrupt 

Babbling transmit error interrupt source.

kENET_GraceStopInterrupt 

Graceful stop complete interrupt source.

kENET_TxFrameInterrupt 

TX FRAME interrupt source.

kENET_TxByteInterrupt 

TX BYTE interrupt source.

kENET_RxFrameInterrupt 

RX FRAME interrupt source.

kENET_RxByteInterrupt 

RX BYTE interrupt source.

kENET_MiiInterrupt 

MII interrupt source.

kENET_EBusERInterrupt 

Ethernet bus error interrupt source.

kENET_LateCollisionInterrupt 

Late collision interrupt source.

kENET_RetryLimitInterrupt 

Collision Retry Limit interrupt source.

kENET_UnderrunInterrupt 

Transmit FIFO underrun interrupt source.

kENET_PayloadRxInterrupt 

Payload Receive interrupt source.

kENET_WakeupInterrupt 

WAKEUP interrupt source.

Enumerator
kENET_RxEvent 

Receive event.

kENET_TxEvent 

Transmit event.

kENET_ErrEvent 

Error event: BABR/BABT/EBERR/LC/RL/UN/PLR .

kENET_WakeUpEvent 

Wake up from sleep mode event.

Enumerator
kENET_TxAccelIsShift16Enabled 

Transmit FIFO shift-16.

kENET_TxAccelIpCheckEnabled 

Insert IP header checksum.

kENET_TxAccelProtoCheckEnabled 

Insert protocol checksum.

Enumerator
kENET_RxAccelPadRemoveEnabled 

Padding removal for short IP frames.

kENET_RxAccelIpCheckEnabled 

Discard with wrong IP header checksum.

kENET_RxAccelProtoCheckEnabled 

Discard with wrong protocol checksum.

kENET_RxAccelMacCheckEnabled 

Discard with Mac layer errors.

kENET_RxAccelisShift16Enabled 

Receive FIFO shift-16.

Function Documentation

void ENET_GetDefaultConfig ( enet_config_t config)

The purpose of this API is to get the default ENET MAC controller configure structure for ENET_Init(). User may use the initialized structure unchanged in ENET_Init(), or modify some fields of the structure before calling ENET_Init(). Example:

Parameters
configThe ENET mac controller configuration structure pointer.
void ENET_Init ( ENET_Type *  base,
enet_handle_t *  handle,
const enet_config_t config,
const enet_buffer_config_t bufferConfig,
uint8_t *  macAddr,
uint32_t  srcClock_Hz 
)

This function ungates the module clock and initializes it with the ENET configuration.

Parameters
baseENET peripheral base address.
handleENET handler pointer.
configENET mac configuration structure pointer. The "enet_config_t" type mac configuration return from ENET_GetDefaultConfig can be used directly. It is also possible to verify the Mac configuration using other methods.
bufferConfigENET buffer configuration structure pointer. The buffer configuration should be prepared for ENET Initialization.
macAddrENET mac address of Ethernet device. This MAC address should be provided.
srcClock_HzThe internal module clock source for MII clock.
Note
ENET has two buffer descriptors: legacy buffer descriptors and enhanced 1588 buffer descriptors. The legacy descriptor is used by default. To use 1588 feature, use the enhanced 1588 buffer descriptor by defining "ENET_ENHANCEDBUFFERDESCRIPTOR_MODE" and calling ENET_Ptp1588Configure() to configure the 1588 feature and related buffers after calling ENET_Init().
void ENET_Deinit ( ENET_Type *  base)

This function gates the module clock, clears ENET interrupts, and disables the ENET module.

Parameters
baseENET peripheral base address.
static void ENET_Reset ( ENET_Type *  base)
inlinestatic

This function restores the ENET module to reset state. Note that this function sets all registers to reset state. As a result, the ENET module can't work after calling this function.

Parameters
baseENET peripheral base address.
void ENET_SetMII ( ENET_Type *  base,
enet_mii_speed_t  speed,
enet_mii_duplex_t  duplex 
)
Parameters
baseENET peripheral base address.
speedThe speed of the RMII mode.
duplexThe duplex of the RMII mode.
void ENET_SetSMI ( ENET_Type *  base,
uint32_t  srcClock_Hz,
bool  isPreambleDisabled 
)
Parameters
baseENET peripheral base address.
srcClock_HzThis is the ENET module clock frequency. Normally it's the system clock. See clock distribution.
isPreambleDisabledThe preamble disable flag.
  • true Enables the preamble.
  • false Disables the preamble.
static bool ENET_GetSMI ( ENET_Type *  base)
inlinestatic

This API is used to get the SMI configuration to check if the MII management interface has been set.

Parameters
baseENET peripheral base address.
Returns
The SMI setup status true or false.
static uint32_t ENET_ReadSMIData ( ENET_Type *  base)
inlinestatic
Parameters
baseENET peripheral base address.
Returns
The data read from PHY
void ENET_StartSMIRead ( ENET_Type *  base,
uint32_t  phyAddr,
uint32_t  phyReg,
enet_mii_read_t  operation 
)
Parameters
baseENET peripheral base address.
phyAddrThe PHY address.
phyRegThe PHY register.
operationThe read operation.
void ENET_StartSMIWrite ( ENET_Type *  base,
uint32_t  phyAddr,
uint32_t  phyReg,
enet_mii_write_t  operation,
uint32_t  data 
)
Parameters
baseENET peripheral base address.
phyAddrThe PHY address.
phyRegThe PHY register.
operationThe write operation.
dataThe data written to PHY.
void ENET_SetMacAddr ( ENET_Type *  base,
uint8_t *  macAddr 
)
Parameters
baseENET peripheral base address.
macAddrThe six-byte Mac address pointer. The pointer is allocated by application and input into the API.
void ENET_GetMacAddr ( ENET_Type *  base,
uint8_t *  macAddr 
)
Parameters
baseENET peripheral base address.
macAddrThe six-byte Mac address pointer. The pointer is allocated by application and input into the API.
void ENET_AddMulticastGroup ( ENET_Type *  base,
uint8_t *  address 
)
Parameters
baseENET peripheral base address.
addressThe six-byte multicast group address which is provided by application.
void ENET_LeaveMulticastGroup ( ENET_Type *  base,
uint8_t *  address 
)
Parameters
baseENET peripheral base address.
addressThe six-byte multicast group address which is provided by application.
static void ENET_ActiveRead ( ENET_Type *  base)
inlinestatic
Parameters
baseENET peripheral base address.
Note
This must be called after the MAC configuration and state are ready. It must be called after the ENET_Init() and ENET_Ptp1588Configure(). This should be called when the ENET receive required.
static void ENET_EnableSleepMode ( ENET_Type *  base,
bool  enable 
)
inlinestatic

This function is used to set the MAC enter sleep mode. When entering sleep mode, the magic frame wakeup interrupt should be enabled to wake up MAC from the sleep mode and reset it to normal mode.

Parameters
baseENET peripheral base address.
enableTrue enable sleep mode, false disable sleep mode.
static void ENET_GetAccelFunction ( ENET_Type *  base,
uint32_t *  txAccelOption,
uint32_t *  rxAccelOption 
)
inlinestatic
Parameters
baseENET peripheral base address.
txAccelOptionThe transmit accelerator option. The "enet_tx_accelerator_t" is recommended to be used to as the mask to get the exact the accelerator option.
rxAccelOptionThe receive accelerator option. The "enet_rx_accelerator_t" is recommended to be used to as the mask to get the exact the accelerator option.
static void ENET_EnableInterrupts ( ENET_Type *  base,
uint32_t  mask 
)
inlinestatic

This function enables the ENET interrupt according to the provided mask. The mask is a logical OR of enumeration members. See enet_interrupt_enable_t. For example, to enable the TX frame interrupt and RX frame interrupt, do this:

Parameters
baseENET peripheral base address.
maskENET interrupts to enable. This is a logical OR of the enumeration :: enet_interrupt_enable_t.
static void ENET_DisableInterrupts ( ENET_Type *  base,
uint32_t  mask 
)
inlinestatic

This function disables the ENET interrupts according to the provided mask. The mask is a logical OR of enumeration members. See enet_interrupt_enable_t. For example, to disable the TX frame interrupt and RX frame interrupt, do this:

Parameters
baseENET peripheral base address.
maskENET interrupts to disable. This is a logical OR of the enumeration :: enet_interrupt_enable_t.
static uint32_t ENET_GetInterruptStatus ( ENET_Type *  base)
inlinestatic
Parameters
baseENET peripheral base address.
Returns
The event status of the interrupt source. This is the logical OR of members of the enumeration :: enet_interrupt_enable_t.
static void ENET_ClearInterruptStatus ( ENET_Type *  base,
uint32_t  mask 
)
inlinestatic

This function clears enabled ENET interrupts according to the provided mask. The mask is a logical OR of enumeration members. See the enet_interrupt_enable_t. For example, to clear the TX frame interrupt and RX frame interrupt, do this:

Parameters
baseENET peripheral base address.
maskENET interrupt source to be cleared. This is the logical OR of members of the enumeration :: enet_interrupt_enable_t.
void ENET_SetCallback ( enet_handle_t *  handle,
enet_callback_t  callback,
void *  userData 
)

This API is provided for application callback required case when ENET interrupt is enabled. This API should be called after calling ENET_Init.

Parameters
handleENET handler pointer. Should be provided by application.
callbackThe ENET callback function.
userDataThe callback function parameter.
void ENET_GetRxErrBeforeReadFrame ( enet_handle_t *  handle,
enet_data_error_stats_t eErrorStatic 
)

This API must be called after the ENET_GetRxFrameSize and before the ENET_ReadFrame(). If the ENET_GetRxFrameSize returns kStatus_ENET_RxFrameError, the ENET_GetRxErrBeforeReadFrame can be used to get the exact error statistics. For example:

status = ENET_GetRxFrameSize(&g_handle, &length);
{
// Get the error information of the received frame.
ENET_GetRxErrBeforeReadFrame(&g_handle, &eErrStatic);
// update the receive buffer.
ENET_ReadFrame(EXAMPLE_ENET, &g_handle, NULL, 0);
}
Parameters
handleThe ENET handler structure pointer. This is the same handler pointer used in the ENET_Init.
eErrorStaticThe error statistics structure pointer.
status_t ENET_GetRxFrameSize ( enet_handle_t *  handle,
uint32_t *  length 
)

This function reads a received frame size from the ENET buffer descriptors.

Note
The FCS of the frame is removed by MAC controller and the size is the length without the FCS. After calling ENET_GetRxFrameSize, ENET_ReadFrame() should be called to update the receive buffers If the result is not "kStatus_ENET_RxFrameEmpty".
Parameters
handleThe ENET handler structure. This is the same handler pointer used in the ENET_Init.
lengthThe length of the valid frame received.
Return values
kStatus_ENET_RxFrameEmptyNo frame received. Should not call ENET_ReadFrame to read frame.
kStatus_ENET_RxFrameErrorData error happens. ENET_ReadFrame should be called with NULL data and NULL length to update the receive buffers.
kStatus_SuccessReceive a frame Successfully then the ENET_ReadFrame should be called with the right data buffer and the captured data length input.
status_t ENET_ReadFrame ( ENET_Type *  base,
enet_handle_t *  handle,
uint8_t *  data,
uint32_t  length 
)

This function reads a frame (both the data and the length) from the ENET buffer descriptors. The ENET_GetRxFrameSize should be used to get the size of the prepared data buffer.

Note
The FCS of the frame is removed by MAC controller and is not delivered to the application.
Parameters
baseENET peripheral base address.
handleThe ENET handler structure. This is the same handler pointer used in the ENET_Init.
dataThe data buffer provided by user to store the frame which memory size should be at least "length".
lengthThe size of the data buffer which is still the length of the received frame.
Returns
The execute status, successful or failure.
status_t ENET_SendFrame ( ENET_Type *  base,
enet_handle_t *  handle,
uint8_t *  data,
uint32_t  length 
)
Note
The CRC is automatically appended to the data. Input the data to send without the CRC.
Parameters
baseENET peripheral base address.
handleThe ENET handler pointer. This is the same handler pointer used in the ENET_Init.
dataThe data buffer provided by user to be send.
lengthThe length of the data to be send.
Return values
kStatus_SuccessSend frame succeed.
kStatus_ENET_TxFrameBusyTransmit buffer descriptor is busy under transmit.
kStatus_ENET_TxFrameFailTransmit frame fail.
void ENET_TransmitIRQHandler ( ENET_Type *  base,
enet_handle_t *  handle 
)
Parameters
baseENET peripheral base address.
handleThe ENET handler pointer.
void ENET_ReceiveIRQHandler ( ENET_Type *  base,
enet_handle_t *  handle 
)
Parameters
baseENET peripheral base address.
handleThe ENET handler pointer.
void ENET_ErrorIRQHandler ( ENET_Type *  base,
enet_handle_t *  handle 
)
Parameters
baseENET peripheral base address.
handleThe ENET handler pointer.