MCUXpresso SDK API Reference Manual  Rev 2.16.000
NXP Semiconductors
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
ENET: Ethernet Driver

Overview

The MCUXpresso SDK provides a peripheral driver for the 10/100 Mbps Ethernet (ENET) module of MCUXpresso SDK devices.

ENET: Ethernet Driver

Oprations of Ethernet Driver {EthernetDriverOps}

Initialize and Deinitialize interface Operation

Use the ENET_GetDefaultConfig() to get the default basic configuration, Use the default configuration unchanged or changed as the input to the ENET_Init() to do basic configuration for ENET module. Call ENET_DescriptorInit() to intialization the descriptors and Call ENET_StartRxTx() to start the ENET engine after all initialization. ENET_Deinit() is used to to ENET Deinitialization.

MII interface Operation

The MII interface is the interface connected with MAC and PHY. the Serial management interface - MII management interface should be set before any access to the external PHY chip register. Call ENET_SetSMI() to initialize MII management interface. Use ENET_StartSMIRead(), ENET_StartSMIWrite(), and ENET_ReadSMIData() to read/write to PHY registers, ENET_IsSMIBusy() to check the SMI busy status. 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 getting data from the external PHY.

Other basic operation

This group provides the ENET mac address set/get operation with ENET_SetMacAddr() and ENET_GetMacAddr(). The ENET_EnterPowerDown() and ENET_ExitPowerDown() can be used to do power management.

Interrupt operation

This group provide the DMA interrupt get and clear APIs. This can be used by application to create new IRQ handler.

Functional Operation

This group functions are low level tx/rx descriptor operations. It is convenient to use these tx/rx APIs to do application specific rx/tx. For TX: Use ENET_IsTxDescriptorDmaOwn(), ENET_SetupTxDescriptor() to build your packet for transfer and ENET_UpdateTxDescriptorTail to update the tx tail pointer. For RX: Use ENET_GetRxDescriptor() to get the received data/length and use the ENET_UpdateRxDescriptor() to update the buffers/status.

Transactional Operation

When use the Transactional APIs, please make sure to call the ENET_CreateHandler to create the handler which are used to maintain all datas related to tx/tx process.

For ENET receive, the ENET_GetRxFrameSize() function must be called to get the received data size. Then, call the ENET_ReadFrame() function to get the received data.

For ENET transmit, call the ENET_SendFrame() function to send the data out. To save memory and avoid the memory copy in the TX process. The ENET_SendFrame() here is a zero-copy API, so make sure the input data buffers are not requeued or freed before the data are really sent out. To makesure the data buffers reclaim is rightly done. the transmit interrupt must be used. so For transactional APIs here we enabled the tx interrupt in ENET_CreateHandler(). That means the tx interrupt is automatically enabled in transctional APIs. is recommended to be called on the transmit interrupt handler.ENET_ReclaimTxDescriptor() is a transactional API to get the information from the finished transmit data buffers and reclaim the tx index. it is called by the transmit interrupt IRQ handler.

PTP IEEE 1588 Feature Operation

All PTP 1588 fatures are enabled by define "ENET_PTP1588FEATURE_REQUIRED" This function group configures the PTP IEEE 1588 feature, starts/stops/gets/sets/corrects the PTP IEEE 1588 timer, gets the receive/transmit frame timestamp

The ENET_GetRxFrameTime() and ENET_GetTxFrameTime() functions are called by the PTP stack to get the timestamp captured by the ENET driver.

Typical use case

ENET Initialization, receive, and transmit operations

For use the transactional APIs, receive polling Refer to the driver examples codes located at <SDK_ROOT>/boards/<BOARD>/driver_examples/enet For the functional API, rx polling Refer to the driver examples codes located at <SDK_ROOT>/boards/<BOARD>/driver_examples/enet

Data Structures

struct  enet_rx_bd_struct_t
 Defines the receive descriptor structure It has the read-format and write-back format structures. More...
 
struct  enet_tx_bd_struct_t
 Defines the transmit descriptor structure It has the read-format and write-back format structure. More...
 
struct  enet_tx_bd_config_struct_t
 Defines the Tx BD configuration structure. More...
 
struct  enet_ptp_time_t
 Defines the ENET PTP time stamp structure. More...
 
struct  enet_tx_reclaim_info_t
 Defines the Tx reclaim information structure. More...
 
struct  enet_tx_dirty_ring_t
 Defines the ENET transmit dirty addresses ring/queue structure. More...
 
struct  enet_buffer_config_t
 Defines the buffer descriptor configure structure. More...
 
struct  enet_multiqueue_config_t
 Defines the configuration when multi-queue is used. More...
 
struct  enet_config_t
 Defines the basic configuration structure for the ENET device. More...
 
struct  enet_tx_bd_ring_t
 Defines the ENET transmit buffer descriptor ring/queue structure. More...
 
struct  enet_rx_bd_ring_t
 Defines the ENET receive buffer descriptor ring/queue structure. More...
 
struct  enet_handle_t
 Defines the ENET handler structure. More...
 
struct  enet_rx_frame_attribute_t
 Rx frame attribute structure. More...
 
struct  enet_rx_frame_error_t
 Defines the Rx frame error structure. More...
 
struct  enet_rx_frame_struct_t
 Defines the Rx frame data structure. More...
 

Typedefs

typedef void *(* enet_rx_alloc_callback_t )(ENET_Type *base, void *userData, uint8_t channel)
 Defines the Rx memory buffer alloc function pointer. More...
 
typedef void(* enet_rx_free_callback_t )(ENET_Type *base, void *buffer, void *userData, uint8_t channel)
 Defines the Rx memory buffer free function pointer. More...
 
typedef void(* enet_callback_t )(ENET_Type *base, enet_handle_t *handle, enet_event_t event, uint8_t channel, enet_tx_reclaim_info_t *txReclaimInfo, void *userData)
 ENET callback function. More...
 

Enumerations

enum  {
  kStatus_ENET_InitMemoryFail,
  kStatus_ENET_RxFrameError,
  kStatus_ENET_RxFrameFail = MAKE_STATUS(kStatusGroup_ENET, 2U),
  kStatus_ENET_RxFrameEmpty = MAKE_STATUS(kStatusGroup_ENET, 3U),
  kStatus_ENET_RxFrameDrop,
  kStatus_ENET_TxFrameBusy,
  kStatus_ENET_TxFrameFail = MAKE_STATUS(kStatusGroup_ENET, 6U),
  kStatus_ENET_TxFrameOverLen
}
 Defines the status return codes for transaction. More...
 
enum  enet_mii_mode_t {
  kENET_MiiMode = 0U,
  kENET_RmiiMode = 1U
}
 Defines the MII/RMII mode for data interface between the MAC and the PHY. More...
 
enum  enet_mii_speed_t {
  kENET_MiiSpeed10M = 0U,
  kENET_MiiSpeed100M = 1U
}
 Defines the 10/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_normal_opcode_t {
  kENET_MiiWriteFrame = 1U,
  kENET_MiiReadFrame = 3U
}
 Define the MII opcode for normal MDIO_CLAUSES_22 Frame. More...
 
enum  enet_dma_burstlen_t {
  kENET_BurstLen1 = 0x00001U,
  kENET_BurstLen2 = 0x00002U,
  kENET_BurstLen4 = 0x00004U,
  kENET_BurstLen8 = 0x00008U,
  kENET_BurstLen16 = 0x00010U,
  kENET_BurstLen32 = 0x00020U,
  kENET_BurstLen64 = 0x10008U,
  kENET_BurstLen128 = 0x10010U,
  kENET_BurstLen256 = 0x10020U
}
 Define the DMA maximum transmit burst length. More...
 
enum  enet_desc_flag_t {
  kENET_MiddleFlag = 0,
  kENET_LastFlagOnly,
  kENET_FirstFlagOnly,
  kENET_FirstLastFlag
}
 Define the flag for the descriptor. More...
 
enum  enet_systime_op_t {
  kENET_SystimeAdd = 0U,
  kENET_SystimeSubtract = 1U
}
 Define the system time adjust operation control. More...
 
enum  enet_ts_rollover_type_t {
  kENET_BinaryRollover = 0,
  kENET_DigitalRollover = 1
}
 Define the system time rollover control. More...
 
enum  enet_special_config_t {
  kENET_DescDoubleBuffer = 0x0001U,
  kENET_StoreAndForward = 0x0002U,
  kENET_PromiscuousEnable = 0x0004U,
  kENET_FlowControlEnable = 0x0008U,
  kENET_BroadCastRxDisable = 0x0010U,
  kENET_MulticastAllEnable = 0x0020U,
  kENET_8023AS2KPacket = 0x0040U,
  kENET_RxChecksumOffloadEnable = 0x0080U
}
 Defines some special configuration for ENET. More...
 
enum  enet_dma_interrupt_enable_t {
  kENET_DmaTx = ENET_DMA_CH_DMA_CHX_INT_EN_TIE_MASK,
  kENET_DmaTxStop = ENET_DMA_CH_DMA_CHX_INT_EN_TSE_MASK,
  kENET_DmaTxBuffUnavail = ENET_DMA_CH_DMA_CHX_INT_EN_TBUE_MASK,
  kENET_DmaRx = ENET_DMA_CH_DMA_CHX_INT_EN_RIE_MASK,
  kENET_DmaRxBuffUnavail = ENET_DMA_CH_DMA_CHX_INT_EN_RBUE_MASK,
  kENET_DmaRxStop = ENET_DMA_CH_DMA_CHX_INT_EN_RSE_MASK,
  kENET_DmaRxWatchdogTimeout = ENET_DMA_CH_DMA_CHX_INT_EN_RWTE_MASK,
  kENET_DmaEarlyTx = ENET_DMA_CH_DMA_CHX_INT_EN_ETIE_MASK,
  kENET_DmaEarlyRx = ENET_DMA_CH_DMA_CHX_INT_EN_ERIE_MASK,
  kENET_DmaBusErr = ENET_DMA_CH_DMA_CHX_INT_EN_FBEE_MASK
}
 List of DMA interrupts supported by the ENET interrupt. More...
 
enum  enet_mac_interrupt_enable_t
 List of mac interrupts supported by the ENET interrupt. More...
 
enum  enet_event_t {
  kENET_RxIntEvent,
  kENET_TxIntEvent,
  kENET_WakeUpIntEvent,
  kENET_TimeStampIntEvent
}
 Defines the common interrupt event for callback use. More...
 
enum  enet_dma_tx_sche_t {
  kENET_FixPri = 0,
  kENET_WeightStrPri,
  kENET_WeightRoundRobin
}
 Define the DMA transmit arbitration for multi-queue. More...
 
enum  enet_mtl_multiqueue_txsche_t {
  kENET_txWeightRR = 0U,
  kENET_txStrPrio = 3U
}
 Define the MTL Tx scheduling algorithm for multiple queues/rings. More...
 
enum  enet_mtl_multiqueue_rxsche_t {
  kENET_rxStrPrio = 0U,
  kENET_rxWeightStrPrio
}
 Define the MTL Rx scheduling algorithm for multiple queues/rings. More...
 
enum  enet_mtl_rxqueuemap_t {
  kENET_StaticDirctMap = 0x100U,
  kENET_DynamicMap
}
 Define the MTL Rx queue and DMA channel mapping. More...
 
enum  enet_ptp_event_type_t {
  kENET_PtpEventMsgType = 3U,
  kENET_PtpSrcPortIdLen = 10U,
  kENET_PtpEventPort = 319U,
  kENET_PtpGnrlPort = 320U
}
 Defines the ENET PTP message related constant. More...
 
enum  enet_tx_offload_t {
  kENET_TxOffloadDisable = 0U,
  kENET_TxOffloadIPHeader = 1U,
  kENET_TxOffloadIPHeaderPlusPayload = 2U,
  kENET_TxOffloadAll = 3U
}
 Define the Tx checksum offload options. More...
 

Variables

const clock_ip_name_t s_enetClock []
 Pointers to enet clocks for each instance. More...
 

Driver version

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

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

#define ENET_RXDESCRIP_RD_BUFF1VALID_MASK   (1UL << 24)
 Defines for read format. More...
 
#define ENET_RXDESCRIP_RD_BUFF2VALID_MASK   (1UL << 25)
 Buffer2 address valid. More...
 
#define ENET_RXDESCRIP_RD_IOC_MASK   (1UL << 30)
 Interrupt enable on complete. More...
 
#define ENET_RXDESCRIP_RD_OWN_MASK   (1UL << 31)
 Own bit. More...
 
#define ENET_RXDESCRIP_WR_ERR_MASK   ((1UL << 3) | (1UL << 7))
 Defines for write back format. More...
 
#define ENET_RXDESCRIP_WR_PYLOAD_MASK   (0x7U)
 
#define ENET_RXDESCRIP_WR_PTPMSGTYPE_MASK   (0xF00U)
 
#define ENET_RXDESCRIP_WR_PTPTYPE_MASK   (1UL << 12)
 
#define ENET_RXDESCRIP_WR_PTPVERSION_MASK   (1UL << 13)
 
#define ENET_RXDESCRIP_WR_PTPTSA_MASK   (1UL << 14)
 
#define ENET_RXDESCRIP_WR_PACKETLEN_MASK   (0x7FFFU)
 
#define ENET_RXDESCRIP_WR_ERRSUM_MASK   (1UL << 15)
 
#define ENET_RXDESCRIP_WR_TYPE_MASK   (0x30000U)
 
#define ENET_RXDESCRIP_WR_DE_MASK   (1UL << 19)
 
#define ENET_RXDESCRIP_WR_RE_MASK   (1UL << 20)
 
#define ENET_RXDESCRIP_WR_OE_MASK   (1UL << 21)
 
#define ENET_RXDESCRIP_WR_RS0V_MASK   (1UL << 25)
 
#define ENET_RXDESCRIP_WR_RS1V_MASK   (1UL << 26)
 
#define ENET_RXDESCRIP_WR_RS2V_MASK   (1UL << 27)
 
#define ENET_RXDESCRIP_WR_LD_MASK   (1UL << 28)
 
#define ENET_RXDESCRIP_WR_FD_MASK   (1UL << 29)
 
#define ENET_RXDESCRIP_WR_CTXT_MASK   (1UL << 30)
 
#define ENET_RXDESCRIP_WR_OWN_MASK   (1UL << 31)
 

Control and status bit masks of the transmit buffer descriptor.

#define ENET_TXDESCRIP_RD_BL1_MASK   (0x3fffU)
 Defines for read format. More...
 
#define ENET_TXDESCRIP_RD_BL2_MASK   (ENET_TXDESCRIP_RD_BL1_MASK << 16)
 
#define ENET_TXDESCRIP_RD_BL1(n)   ((uint32_t)(n)&ENET_TXDESCRIP_RD_BL1_MASK)
 
#define ENET_TXDESCRIP_RD_BL2(n)   (((uint32_t)(n)&ENET_TXDESCRIP_RD_BL1_MASK) << 16)
 
#define ENET_TXDESCRIP_RD_TTSE_MASK   (1UL << 30)
 
#define ENET_TXDESCRIP_RD_IOC_MASK   (1UL << 31)
 
#define ENET_TXDESCRIP_RD_FL_MASK   (0x7FFFU)
 
#define ENET_TXDESCRIP_RD_FL(n)   ((uint32_t)(n)&ENET_TXDESCRIP_RD_FL_MASK)
 
#define ENET_TXDESCRIP_RD_CIC(n)   (((uint32_t)(n)&0x3U) << 16)
 
#define ENET_TXDESCRIP_RD_TSE_MASK   (1UL << 18)
 
#define ENET_TXDESCRIP_RD_SLOT(n)   (((uint32_t)(n)&0x0fU) << 19)
 
#define ENET_TXDESCRIP_RD_SAIC(n)   (((uint32_t)(n)&0x07U) << 23)
 
#define ENET_TXDESCRIP_RD_CPC(n)   (((uint32_t)(n)&0x03U) << 26)
 
#define ENET_TXDESCRIP_RD_LDFD(n)   (((uint32_t)(n)&0x03U) << 28)
 
#define ENET_TXDESCRIP_RD_LD_MASK   (1UL << 28)
 
#define ENET_TXDESCRIP_RD_FD_MASK   (1UL << 29)
 
#define ENET_TXDESCRIP_RD_CTXT_MASK   (1UL << 30)
 
#define ENET_TXDESCRIP_RD_OWN_MASK   (1UL << 31)
 
#define ENET_TXDESCRIP_WB_TTSS_MASK   (1UL << 17)
 Defines for write back format. More...
 

Bit mask for interrupt enable type.

#define ENET_ABNORM_INT_MASK
 
#define ENET_NORM_INT_MASK
 

Defines some Ethernet parameters.

#define ENET_FRAME_MAX_FRAMELEN   (1518U)
 Default maximum ethernet frame size. More...
 
#define ENET_FCS_LEN   (4U)
 Ethernet Rx frame FCS length. More...
 
#define ENET_ADDR_ALIGNMENT   (0x3U)
 Recommended ethernet buffer alignment. More...
 
#define ENET_BUFF_ALIGNMENT   (4U)
 Receive buffer alignment shall be 4bytes-aligned. More...
 
#define ENET_RING_NUM_MAX   (2U)
 The maximum number of Tx/Rx descriptor rings. More...
 
#define ENET_MTL_RXFIFOSIZE   (2048U)
 The Rx fifo size. More...
 
#define ENET_MTL_TXFIFOSIZE   (2048U)
 The Tx fifo size. More...
 
#define ENET_MACINT_ENUM_OFFSET   (16U)
 The offset for mac interrupt in enum type. More...
 
#define ENET_FRAME_TX_LEN_LIMITATION   (ENET_TXDESCRIP_RD_BL1_MASK)
 The Tx frame length software limitation. More...
 
#define ENET_FRAME_RX_ERROR_BITS(x)   (((x) >> 19U) & 0x3FU)
 The Rx frame error bits field. 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, const enet_config_t *config, uint8_t *macAddr, uint32_t refclkSrc_Hz)
 Initializes the ENET module. More...
 
void ENET_Deinit (ENET_Type *base)
 Deinitializes the ENET module. More...
 
status_t ENET_DescriptorInit (ENET_Type *base, enet_config_t *config, enet_buffer_config_t *bufferConfig)
 Initialize for all ENET descriptors. More...
 
status_t ENET_RxBufferAllocAll (ENET_Type *base, enet_handle_t *handle)
 Allocates Rx buffers for all BDs. More...
 
void ENET_RxBufferFreeAll (ENET_Type *base, enet_handle_t *handle)
 Frees Rx buffers in all BDs. More...
 
void ENET_StartRxTx (ENET_Type *base, uint8_t txRingNum, uint8_t rxRingNum)
 Starts the ENET Tx/Rx. More...
 
void ENET_SetISRHandler (ENET_Type *base, enet_isr_t ISRHandler)
 Set the second level IRQ handler. More...
 

MII interface operation

static 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)
 Sets the ENET SMI(serial management interface)- MII management interface. More...
 
static bool ENET_IsSMIBusy (ENET_Type *base)
 Checks if the SMI is busy. More...
 
static uint16_t ENET_ReadSMIData (ENET_Type *base)
 Reads data from the PHY register through SMI interface. More...
 
void ENET_StartSMIWrite (ENET_Type *base, uint8_t phyAddr, uint8_t regAddr, uint16_t data)
 Sends the MDIO IEEE802.3 Clause 22 format write command. More...
 
void ENET_StartSMIRead (ENET_Type *base, uint8_t phyAddr, uint8_t regAddr)
 Sends the MDIO IEEE802.3 Clause 22 format read command. More...
 
status_t ENET_MDIOWrite (ENET_Type *base, uint8_t phyAddr, uint8_t regAddr, uint16_t data)
 MDIO write with IEEE802.3 Clause 22 format. More...
 
status_t ENET_MDIORead (ENET_Type *base, uint8_t phyAddr, uint8_t regAddr, uint16_t *pData)
 MDIO read with IEEE802.3 Clause 22 format. More...
 

Other basic operation

uint32_t ENET_GetInstance (ENET_Type *base)
 Get the ENET instance from peripheral base address. More...
 
static 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...
 
static void ENET_AcceptAllMulticast (ENET_Type *base)
 Enable ENET device to accept all multicast frames. More...
 
static void ENET_RejectAllMulticast (ENET_Type *base)
 ENET device reject to accept all multicast frames. More...
 
void ENET_EnterPowerDown (ENET_Type *base, uint32_t *wakeFilter)
 Set the MAC to enter into power down mode. More...
 
static void ENET_ExitPowerDown (ENET_Type *base)
 Set the MAC to exit power down mode. More...
 

Interrupts.

void ENET_EnableInterrupts (ENET_Type *base, uint32_t mask)
 Enables the ENET DMA and MAC interrupts. More...
 
void ENET_DisableInterrupts (ENET_Type *base, uint32_t mask)
 Disables the ENET DMA and MAC interrupts. More...
 
static uint32_t ENET_GetDmaInterruptStatus (ENET_Type *base, uint8_t channel)
 Gets the ENET DMA interrupt status flag. More...
 
static void ENET_ClearDmaInterruptStatus (ENET_Type *base, uint8_t channel, uint32_t mask)
 Clear the ENET DMA interrupt status flag. More...
 
static uint32_t ENET_GetMacInterruptStatus (ENET_Type *base)
 Gets the ENET MAC interrupt status flag. More...
 
void ENET_ClearMacInterruptStatus (ENET_Type *base, uint32_t mask)
 Clears the ENET mac interrupt events status flag. More...
 

Functional operation.

static bool ENET_IsTxDescriptorDmaOwn (enet_tx_bd_struct_t *txDesc)
 Get the Tx descriptor DMA Own flag. More...
 
void ENET_SetupTxDescriptor (enet_tx_bd_struct_t *txDesc, void *buffer1, uint32_t bytes1, void *buffer2, uint32_t bytes2, uint32_t framelen, bool intEnable, bool tsEnable, enet_desc_flag_t flag, uint8_t slotNum)
 Setup a given Tx descriptor. More...
 
static void ENET_UpdateTxDescriptorTail (ENET_Type *base, uint8_t channel, uint32_t txDescTailAddrAlign)
 Update the Tx descriptor tail pointer. More...
 
static void ENET_UpdateRxDescriptorTail (ENET_Type *base, uint8_t channel, uint32_t rxDescTailAddrAlign)
 Update the Rx descriptor tail pointer. More...
 
static uint32_t ENET_GetRxDescriptor (enet_rx_bd_struct_t *rxDesc)
 Gets the context in the ENET Rx descriptor. More...
 
void ENET_UpdateRxDescriptor (enet_rx_bd_struct_t *rxDesc, void *buffer1, void *buffer2, bool intEnable, bool doubleBuffEnable)
 Updates the buffers and the own status for a given Rx descriptor. More...
 

Transactional operation

void ENET_CreateHandler (ENET_Type *base, enet_handle_t *handle, enet_config_t *config, enet_buffer_config_t *bufferConfig, enet_callback_t callback, void *userData)
 Create ENET Handler. More...
 
status_t ENET_GetRxFrameSize (ENET_Type *base, enet_handle_t *handle, uint32_t *length, uint8_t channel)
 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, uint8_t channel, enet_ptp_time_t *timestamp)
 Reads a frame from the ENET device. More...
 
status_t ENET_GetRxFrame (ENET_Type *base, enet_handle_t *handle, enet_rx_frame_struct_t *rxFrame, uint8_t channel)
 Receives one frame in specified BD ring with zero copy. More...
 
status_t ENET_SendFrame (ENET_Type *base, enet_handle_t *handle, enet_tx_frame_struct_t *txFrame, uint8_t channel)
 Transmits an ENET frame. More...
 
void ENET_ReclaimTxDescriptor (ENET_Type *base, enet_handle_t *handle, uint8_t channel)
 Reclaim Tx descriptors. More...
 
void ENET_IRQHandler (ENET_Type *base, enet_handle_t *handle)
 The ENET IRQ handler. More...
 

Data Structure Documentation

struct enet_rx_bd_struct_t

They both have the same size with different region definition. So we define common name as the recive descriptor structure. When initialize the buffer descriptors, read-format region mask bits should be used. When Rx frame has been in the buffer descriptors, write-back format region store the Rx result information.

Data Fields

__IO uint32_t rdes0
 Receive descriptor 0.
 
__IO uint32_t rdes1
 Receive descriptor 1.
 
__IO uint32_t rdes2
 Receive descriptor 2.
 
__IO uint32_t rdes3
 Receive descriptor 3.
 
struct enet_tx_bd_struct_t

They both has the same size with different region definition. So we define common name as the transmit descriptor structure. When initialize the buffer descriptors for Tx, read-format region mask bits should be used. When frame has been transmitted, write-back format region store the Tx result information.

Data Fields

__IO uint32_t tdes0
 Transmit descriptor 0.
 
__IO uint32_t tdes1
 Transmit descriptor 1.
 
__IO uint32_t tdes2
 Transmit descriptor 2.
 
__IO uint32_t tdes3
 Transmit descriptor 3.
 
struct enet_tx_bd_config_struct_t

Data Fields

void * buffer1
 The first buffer address in the descriptor. More...
 
uint32_t bytes1
 The bytes in the fist buffer. More...
 
void * buffer2
 The second buffer address in the descriptor. More...
 
uint32_t bytes2
 The bytes in the second buffer. More...
 
uint32_t framelen
 The length of the frame to be transmitted. More...
 
bool intEnable
 Interrupt enable flag. More...
 
bool tsEnable
 The timestamp enable. More...
 
enet_tx_offload_t txOffloadOps
 The Tx checksum offload option, only vaild for Queue 0. More...
 
enet_desc_flag_t flag
 The flag of this tx desciriptor, see "enet_qos_desc_flag". More...
 
uint8_t slotNum
 The slot number used for AV mode only. More...
 

Field Documentation

void* enet_tx_bd_config_struct_t::buffer1
uint32_t enet_tx_bd_config_struct_t::bytes1
void* enet_tx_bd_config_struct_t::buffer2
uint32_t enet_tx_bd_config_struct_t::bytes2
uint32_t enet_tx_bd_config_struct_t::framelen
bool enet_tx_bd_config_struct_t::intEnable
bool enet_tx_bd_config_struct_t::tsEnable
enet_tx_offload_t enet_tx_bd_config_struct_t::txOffloadOps
enet_desc_flag_t enet_tx_bd_config_struct_t::flag
uint8_t enet_tx_bd_config_struct_t::slotNum
struct enet_ptp_time_t

Data Fields

uint64_t second
 Second. More...
 
uint32_t nanosecond
 Nanosecond. More...
 

Field Documentation

uint64_t enet_ptp_time_t::second
uint32_t enet_ptp_time_t::nanosecond
struct enet_tx_reclaim_info_t

Data Fields

void * context
 User specified data, could be buffer address for free.
 
bool isTsAvail
 Flag indicates timestamp available status.
 
enet_ptp_time_t timeStamp
 Timestamp of frame.
 
struct enet_tx_dirty_ring_t

Data Fields

enet_tx_reclaim_info_ttxDirtyBase
 Dirty buffer descriptor base address pointer. More...
 
uint16_t txGenIdx
 Tx generate index. More...
 
uint16_t txConsumIdx
 Tx consume index. More...
 
uint16_t txRingLen
 Tx ring length. More...
 
bool isFull
 Tx ring is full flag, add this parameter to avoid waste one element. More...
 

Field Documentation

enet_tx_reclaim_info_t* enet_tx_dirty_ring_t::txDirtyBase
uint16_t enet_tx_dirty_ring_t::txGenIdx
uint16_t enet_tx_dirty_ring_t::txConsumIdx
uint16_t enet_tx_dirty_ring_t::txRingLen
bool enet_tx_dirty_ring_t::isFull
struct enet_buffer_config_t

Notes:

  1. The receive and transmit descriptor start address pointer and tail pointer must be word-aligned.
  2. The recommended minimum Tx/Rx ring length is 4.
  3. The Tx/Rx descriptor tail address shall be the address pointer to the address just after the end of the last last descriptor. because only the descriptors between the start address and the tail address will be used by DMA.
  4. The decriptor address is the start address of all used contiguous memory. for example, the rxDescStartAddrAlign is the start address of rxRingLen contiguous descriptor memorise for Rx descriptor ring 0.
  5. The "*rxBufferstartAddr" is the first element of rxRingLen (2*rxRingLen for double buffers) Rx buffers. It means the *rxBufferStartAddr is the Rx buffer for the first descriptor the *rxBufferStartAddr + 1 is the Rx buffer for the second descriptor or the Rx buffer for the second buffer in the first descriptor. So please make sure the rxBufferStartAddr is the address of a rxRingLen or 2*rxRingLen array.

Data Fields

uint8_t rxRingLen
 The length of receive buffer descriptor ring. More...
 
uint8_t txRingLen
 The length of transmit buffer descriptor ring. More...
 
enet_tx_bd_struct_ttxDescStartAddrAlign
 Aligned transmit descriptor start address. More...
 
enet_tx_bd_struct_ttxDescTailAddrAlign
 Aligned transmit descriptor tail address. More...
 
enet_tx_reclaim_info_ttxDirtyStartAddr
 Start address of the dirty Tx frame information. More...
 
enet_rx_bd_struct_trxDescStartAddrAlign
 Aligned receive descriptor start address. More...
 
enet_rx_bd_struct_trxDescTailAddrAlign
 Aligned receive descriptor tail address. More...
 
uint32_t * rxBufferStartAddr
 Start address of the Rx buffers. More...
 
uint32_t rxBuffSizeAlign
 Aligned receive data buffer size. More...
 

Field Documentation

uint8_t enet_buffer_config_t::rxRingLen
uint8_t enet_buffer_config_t::txRingLen
enet_tx_bd_struct_t* enet_buffer_config_t::txDescStartAddrAlign
enet_tx_bd_struct_t* enet_buffer_config_t::txDescTailAddrAlign
enet_tx_reclaim_info_t* enet_buffer_config_t::txDirtyStartAddr
enet_rx_bd_struct_t* enet_buffer_config_t::rxDescStartAddrAlign
enet_rx_bd_struct_t* enet_buffer_config_t::rxDescTailAddrAlign
uint32_t* enet_buffer_config_t::rxBufferStartAddr
uint32_t enet_buffer_config_t::rxBuffSizeAlign
struct enet_multiqueue_config_t

Data Fields

enet_dma_tx_sche_t dmaTxSche
 Transmit arbitation. More...
 
enet_dma_burstlen_t burstLen
 Burset len for the queue 1. More...
 
uint8_t txdmaChnWeight [ENET_RING_NUM_MAX]
 Transmit channel weight. More...
 
enet_mtl_multiqueue_txsche_t mtltxSche
 Transmit schedule for multi-queue. More...
 
enet_mtl_multiqueue_rxsche_t mtlrxSche
 Receive schedule for multi-queue. More...
 
uint8_t rxqueweight [ENET_RING_NUM_MAX]
 Refer to the MTL RxQ Control register. More...
 
uint32_t txqueweight [ENET_RING_NUM_MAX]
 Refer to the MTL TxQ Quantum Weight register. More...
 
uint8_t rxqueuePrio [ENET_RING_NUM_MAX]
 Receive queue priority. More...
 
uint8_t txqueuePrio [ENET_RING_NUM_MAX]
 Refer to Transmit Queue Priority Mapping register. More...
 
enet_mtl_rxqueuemap_t mtlrxQuemap
 Rx queue DMA Channel mapping. More...
 

Field Documentation

enet_dma_tx_sche_t enet_multiqueue_config_t::dmaTxSche
enet_dma_burstlen_t enet_multiqueue_config_t::burstLen
uint8_t enet_multiqueue_config_t::txdmaChnWeight[ENET_RING_NUM_MAX]
enet_mtl_multiqueue_txsche_t enet_multiqueue_config_t::mtltxSche
enet_mtl_multiqueue_rxsche_t enet_multiqueue_config_t::mtlrxSche
uint8_t enet_multiqueue_config_t::rxqueweight[ENET_RING_NUM_MAX]
uint32_t enet_multiqueue_config_t::txqueweight[ENET_RING_NUM_MAX]
uint8_t enet_multiqueue_config_t::rxqueuePrio[ENET_RING_NUM_MAX]
uint8_t enet_multiqueue_config_t::txqueuePrio[ENET_RING_NUM_MAX]
enet_mtl_rxqueuemap_t enet_multiqueue_config_t::mtlrxQuemap
struct enet_config_t

Note:

  1. Default the signal queue is used so the "multiqueueCfg" is set default with NULL. Set the pointer with a valid configration pointer if the multiple queues are required. If multiple queue is enabled, please make sure the buffer configuration for all are prepared also.

Data Fields

uint16_t specialControl
 The logicl or of enet_special_config_t.
 
enet_multiqueue_config_tmultiqueueCfg
 Use both Tx/Rx queue(dma channel) 0 and 1. More...
 
uint32_t interrupt
 MAC interrupt source. 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...
 
uint16_t pauseDuration
 Used in the Tx flow control frame, only valid when kENET_FlowControlEnable is set. More...
 
enet_rx_alloc_callback_t rxBuffAlloc
 Callback to alloc memory, must be provided for zero-copy Rx. More...
 
enet_rx_free_callback_t rxBuffFree
 Callback to free memory, must be provided for zero-copy Rx. More...
 

Field Documentation

enet_multiqueue_config_t* enet_config_t::multiqueueCfg
uint32_t enet_config_t::interrupt

A logical OR of enet_dma_interrupt_enable_t and enet_mac_interrupt_enable_t.

enet_mii_mode_t enet_config_t::miiMode
enet_mii_speed_t enet_config_t::miiSpeed
enet_mii_duplex_t enet_config_t::miiDuplex
uint16_t enet_config_t::pauseDuration
enet_rx_alloc_callback_t enet_config_t::rxBuffAlloc
enet_rx_free_callback_t enet_config_t::rxBuffFree
struct enet_tx_bd_ring_t

Data Fields

enet_tx_bd_struct_ttxBdBase
 Buffer descriptor base address pointer. More...
 
uint16_t txGenIdx
 Tx generate index. More...
 
uint16_t txConsumIdx
 Tx consum index. More...
 
volatile uint16_t txDescUsed
 Tx descriptor used number. More...
 
uint16_t txRingLen
 Tx ring length. More...
 

Field Documentation

enet_tx_bd_struct_t* enet_tx_bd_ring_t::txBdBase
uint16_t enet_tx_bd_ring_t::txGenIdx
uint16_t enet_tx_bd_ring_t::txConsumIdx
volatile uint16_t enet_tx_bd_ring_t::txDescUsed
uint16_t enet_tx_bd_ring_t::txRingLen
struct enet_rx_bd_ring_t

Data Fields

enet_rx_bd_struct_trxBdBase
 Buffer descriptor base address pointer. More...
 
uint16_t rxGenIdx
 The current available receive buffer descriptor pointer. More...
 
uint16_t rxRingLen
 Receive ring length. More...
 
uint32_t rxBuffSizeAlign
 Receive buffer size. More...
 

Field Documentation

enet_rx_bd_struct_t* enet_rx_bd_ring_t::rxBdBase
uint16_t enet_rx_bd_ring_t::rxGenIdx
uint16_t enet_rx_bd_ring_t::rxRingLen
uint32_t enet_rx_bd_ring_t::rxBuffSizeAlign
struct _enet_handle

Data Fields

bool multiQueEnable
 Multi-queue enable status. More...
 
bool doubleBuffEnable
 The double buffer enable status. More...
 
bool rxintEnable
 Rx interrupt enable status. More...
 
enet_rx_bd_ring_t rxBdRing [ENET_RING_NUM_MAX]
 Receive buffer descriptor. More...
 
enet_tx_bd_ring_t txBdRing [ENET_RING_NUM_MAX]
 Transmit buffer descriptor. More...
 
enet_tx_dirty_ring_t txDirtyRing [ENET_RING_NUM_MAX]
 Transmit dirty buffers addresses. More...
 
uint32_t * rxBufferStartAddr [ENET_RING_NUM_MAX]
 The Init-Rx buffers used for reinit corrupted BD due to write-back operation. More...
 
uint32_t txLenLimitation [ENET_RING_NUM_MAX]
 Tx frame length limitation. More...
 
enet_callback_t callback
 Callback function. More...
 
void * userData
 Callback function parameter. More...
 
enet_rx_alloc_callback_t rxBuffAlloc
 Callback to alloc memory, must be provided for zero-copy Rx. More...
 
enet_rx_free_callback_t rxBuffFree
 Callback to free memory, must be provided for zero-copy Rx. More...
 

Field Documentation

bool enet_handle_t::multiQueEnable
bool enet_handle_t::doubleBuffEnable
bool enet_handle_t::rxintEnable
enet_rx_bd_ring_t enet_handle_t::rxBdRing[ENET_RING_NUM_MAX]
enet_tx_bd_ring_t enet_handle_t::txBdRing[ENET_RING_NUM_MAX]
enet_tx_dirty_ring_t enet_handle_t::txDirtyRing[ENET_RING_NUM_MAX]
uint32_t* enet_handle_t::rxBufferStartAddr[ENET_RING_NUM_MAX]
uint32_t enet_handle_t::txLenLimitation[ENET_RING_NUM_MAX]
enet_callback_t enet_handle_t::callback
void* enet_handle_t::userData
enet_rx_alloc_callback_t enet_handle_t::rxBuffAlloc
enet_rx_free_callback_t enet_handle_t::rxBuffFree
struct enet_rx_frame_attribute_t

Data Fields

bool isTsAvail
 Rx frame timestamp is available or not. More...
 
enet_ptp_time_t timestamp
 The nanosecond part timestamp of this Rx frame. More...
 

Field Documentation

bool enet_rx_frame_attribute_t::isTsAvail
enet_ptp_time_t enet_rx_frame_attribute_t::timestamp
struct enet_rx_frame_error_t

Data Fields

bool statsDribbleErr: 1
 The received packet has a non-integer multiple of bytes (odd nibbles). More...
 
bool statsRxErr: 1
 Receive error. More...
 
bool statsOverflowErr: 1
 Rx FIFO overflow error. More...
 
bool statsWatchdogTimeoutErr: 1
 Receive watchdog timeout. More...
 
bool statsGaintPacketErr: 1
 Receive error. More...
 
bool statsRxFcsErr: 1
 Receive CRC error. More...
 

Field Documentation

bool enet_rx_frame_error_t::statsDribbleErr
bool enet_rx_frame_error_t::statsRxErr
bool enet_rx_frame_error_t::statsOverflowErr
bool enet_rx_frame_error_t::statsWatchdogTimeoutErr
bool enet_rx_frame_error_t::statsGaintPacketErr
bool enet_rx_frame_error_t::statsRxFcsErr
struct enet_rx_frame_struct_t

Data Fields

enet_buffer_struct_t * rxBuffArray
 Rx frame buffer structure. More...
 
uint16_t totLen
 Rx frame total length. More...
 
enet_rx_frame_attribute_t rxAttribute
 Rx frame attribute structure. More...
 
enet_rx_frame_error_t rxFrameError
 Rx frame error. More...
 

Field Documentation

enet_buffer_struct_t* enet_rx_frame_struct_t::rxBuffArray
uint16_t enet_rx_frame_struct_t::totLen
enet_rx_frame_attribute_t enet_rx_frame_struct_t::rxAttribute
enet_rx_frame_error_t enet_rx_frame_struct_t::rxFrameError

Macro Definition Documentation

#define FSL_ENET_DRIVER_VERSION   (MAKE_VERSION(2, 3, 4))
#define ENET_RXDESCRIP_RD_BUFF1VALID_MASK   (1UL << 24)

Buffer1 address valid.

#define ENET_RXDESCRIP_RD_BUFF2VALID_MASK   (1UL << 25)
#define ENET_RXDESCRIP_RD_IOC_MASK   (1UL << 30)
#define ENET_RXDESCRIP_RD_OWN_MASK   (1UL << 31)
#define ENET_RXDESCRIP_WR_ERR_MASK   ((1UL << 3) | (1UL << 7))
#define ENET_TXDESCRIP_RD_BL1_MASK   (0x3fffU)
#define ENET_TXDESCRIP_WB_TTSS_MASK   (1UL << 17)
#define ENET_FRAME_MAX_FRAMELEN   (1518U)
#define ENET_FCS_LEN   (4U)
#define ENET_ADDR_ALIGNMENT   (0x3U)
#define ENET_BUFF_ALIGNMENT   (4U)
#define ENET_RING_NUM_MAX   (2U)
#define ENET_MTL_RXFIFOSIZE   (2048U)
#define ENET_MTL_TXFIFOSIZE   (2048U)
#define ENET_MACINT_ENUM_OFFSET   (16U)
#define ENET_FRAME_TX_LEN_LIMITATION   (ENET_TXDESCRIP_RD_BL1_MASK)
#define ENET_FRAME_RX_ERROR_BITS (   x)    (((x) >> 19U) & 0x3FU)

Typedef Documentation

typedef void*(* enet_rx_alloc_callback_t)(ENET_Type *base, void *userData, uint8_t channel)
typedef void(* enet_rx_free_callback_t)(ENET_Type *base, void *buffer, void *userData, uint8_t channel)
typedef void(* enet_callback_t)(ENET_Type *base, enet_handle_t *handle, enet_event_t event, uint8_t channel, enet_tx_reclaim_info_t *txReclaimInfo, void *userData)

Enumeration Type Documentation

anonymous enum
Enumerator
kStatus_ENET_InitMemoryFail 

Status code 4000.

Init failed since buffer memory was not enough.

kStatus_ENET_RxFrameError 

Status code 4001.

A frame received but data error occurred.

kStatus_ENET_RxFrameFail 

Status code 4002.

Failed to receive a frame.

kStatus_ENET_RxFrameEmpty 

Status code 4003.

No frame arrived.

kStatus_ENET_RxFrameDrop 

Status code 4004.

Rx frame was dropped since there's no buffer memory.

kStatus_ENET_TxFrameBusy 

Status code 4005.

There were no resources for Tx operation.

kStatus_ENET_TxFrameFail 

Status code 4006.

Transmit frame failed.

kStatus_ENET_TxFrameOverLen 

Status code 4007.

Failed to send an oversize frame.

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_MiiWriteFrame 

Write frame operation for a valid MII management frame.

kENET_MiiReadFrame 

Read frame operation for a valid MII management frame.

Enumerator
kENET_BurstLen1 

DMA burst length 1.

kENET_BurstLen2 

DMA burst length 2.

kENET_BurstLen4 

DMA burst length 4.

kENET_BurstLen8 

DMA burst length 8.

kENET_BurstLen16 

DMA burst length 16.

kENET_BurstLen32 

DMA burst length 32.

kENET_BurstLen64 

DMA burst length 64.

eight times enabled.

kENET_BurstLen128 

DMA burst length 128.

eight times enabled.

kENET_BurstLen256 

DMA burst length 256.

eight times enabled.

Enumerator
kENET_MiddleFlag 

It's a middle descriptor of the frame.

kENET_LastFlagOnly 

It's the last descriptor of the frame.

kENET_FirstFlagOnly 

It's the first descriptor of the frame.

kENET_FirstLastFlag 

It's the first and last descriptor of the frame.

Enumerator
kENET_SystimeAdd 

System time add to.

kENET_SystimeSubtract 

System time subtract.

Enumerator
kENET_BinaryRollover 

System time binary rollover.

kENET_DigitalRollover 

System time digital rollover.

These control flags are provided for special user requirements. Normally, these is no need to set this control flags for ENET initialization. But if you have some special requirements, set the flags to specialControl in the enet_config_t.

Note
"kENET_StoreAndForward" is recommended to be set when the ENET_PTP1588FEATURE_REQUIRED is defined or else the timestamp will be mess-up when the overflow happens.
Enumerator
kENET_DescDoubleBuffer 

The double buffer is used in the Tx/Rx descriptor.

kENET_StoreAndForward 

The Rx/Tx store and forward enable.

kENET_PromiscuousEnable 

The promiscuous enabled.

kENET_FlowControlEnable 

The flow control enabled.

kENET_BroadCastRxDisable 

The broadcast disabled.

kENET_MulticastAllEnable 

All multicast are passed.

kENET_8023AS2KPacket 

8023as support for 2K packets.

kENET_RxChecksumOffloadEnable 

The Rx checksum offload enabled.

This enumeration uses one-hot encoding to allow a logical OR of multiple members.

Enumerator
kENET_DmaTx 

Tx interrupt.

kENET_DmaTxStop 

Tx stop interrupt.

kENET_DmaTxBuffUnavail 

Tx buffer unavailable.

kENET_DmaRx 

Rx interrupt.

kENET_DmaRxBuffUnavail 

Rx buffer unavailable.

kENET_DmaRxStop 

Rx stop.

kENET_DmaRxWatchdogTimeout 

Rx watchdog timeout.

kENET_DmaEarlyTx 

Early transmit.

kENET_DmaEarlyRx 

Early receive.

kENET_DmaBusErr 

Fatal bus error.

This enumeration uses one-hot encoding to allow a logical OR of multiple members.

Enumerator
kENET_RxIntEvent 

Receive interrupt event.

kENET_TxIntEvent 

Transmit interrupt event.

kENET_WakeUpIntEvent 

Wake up interrupt event.

kENET_TimeStampIntEvent 

Time stamp interrupt event.

Enumerator
kENET_FixPri 

Fixed priority.

channel 0 has lower priority than channel 1.

kENET_WeightStrPri 

Weighted(burst length) strict priority.

kENET_WeightRoundRobin 

Weighted (weight factor) round robin.

Enumerator
kENET_txWeightRR 

Tx weight round-robin.

kENET_txStrPrio 

Tx strict priority.

Enumerator
kENET_rxStrPrio 

Tx weight round-robin, Rx strict priority.

kENET_rxWeightStrPrio 

Tx strict priority, Rx weight strict priority.

Enumerator
kENET_StaticDirctMap 

The received fame in Rx Qn(n = 0,1) direclty map to dma channel n.

kENET_DynamicMap 

The received frame in Rx Qn(n = 0,1) map to the dma channel m(m = 0,1) related with the same Mac.

Enumerator
kENET_PtpEventMsgType 

PTP event message type.

kENET_PtpSrcPortIdLen 

PTP message sequence id length.

kENET_PtpEventPort 

PTP event port number.

kENET_PtpGnrlPort 

PTP general port number.

Enumerator
kENET_TxOffloadDisable 

Disable Tx checksum offload.

kENET_TxOffloadIPHeader 

Enable IP header checksum calculation and insertion.

kENET_TxOffloadIPHeaderPlusPayload 

Enable IP header and payload checksum calculation and insertion.

kENET_TxOffloadAll 

Enable IP header, payload and pseudo header checksum calculation and insertion.

Function Documentation

void ENET_GetDefaultConfig ( enet_config_t config)

The purpose of this API is to get the default ENET 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,
const enet_config_t config,
uint8_t *  macAddr,
uint32_t  refclkSrc_Hz 
)

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

Note
As our transactional transmit API use the zero-copy transmit buffer. So there are two thing we emphasize here:
  1. Tx buffer free/requeue for application should be done in the Tx interrupt handler. Please set callback: kENET_TxIntEvent with Tx buffer free/requeue process APIs.
  2. The Tx interrupt is forced to open.
Parameters
baseENET peripheral base address.
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.
macAddrENET mac address of Ethernet device. This MAC address should be provided.
refclkSrc_HzENET input reference clock.
void ENET_Deinit ( ENET_Type *  base)

This function gates the module clock and disables the ENET module.

Parameters
baseENET peripheral base address.
status_t ENET_DescriptorInit ( ENET_Type *  base,
enet_config_t config,
enet_buffer_config_t bufferConfig 
)
Note
This function finishes all Tx/Rx descriptors initialization. The descriptor initialization should be called after ENET_Init().
Parameters
baseENET peripheral base address.
configThe configuration for ENET.
bufferConfigAll buffers configuration.
status_t ENET_RxBufferAllocAll ( ENET_Type *  base,
enet_handle_t *  handle 
)

It's used for zero copy Rx. In zero copy Rx case, Rx buffers are dynamic. This function will populate initial buffers in all BDs for receiving. Then ENET_GetRxFrame() is used to get Rx frame with zero copy, it will allocate new buffer to replace the buffer in BD taken by application, application should free those buffers after they're used.

Note
This function should be called after ENET_CreateHandler() and buffer allocating callback function should be ready.
Parameters
baseENET peripheral base address.
handleThe ENET handler structure. This is the same handler pointer used in the ENET_Init.
void ENET_RxBufferFreeAll ( ENET_Type *  base,
enet_handle_t *  handle 
)

It's used for zero copy Rx. In zero copy Rx case, Rx buffers are dynamic. This function will free left buffers in all BDs.

Parameters
baseENET peripheral base address.
handleThe ENET handler structure. This is the same handler pointer used in the ENET_Init.
void ENET_StartRxTx ( ENET_Type *  base,
uint8_t  txRingNum,
uint8_t  rxRingNum 
)

This function enable the Tx/Rx and starts the Tx/Rx DMA. This shall be set after ENET initialization and before starting to receive the data.

Parameters
baseENET peripheral base address.
rxRingNumThe number of the used Rx rings. It shall not be larger than the ENET_RING_NUM_MAX(2). If the ringNum is set with 1, the ring 0 will be used.
txRingNumThe number of the used Tx rings. It shall not be larger than the ENET_RING_NUM_MAX(2). If the ringNum is set with 1, the ring 0 will be used.
Note
This must be called after all the ENET initilization. And should be called when the ENET receive/transmit is required.
void ENET_SetISRHandler ( ENET_Type *  base,
enet_isr_t  ISRHandler 
)
Parameters
baseENET peripheral base address.
ISRHandlerThe handler to install.
static void ENET_SetMII ( ENET_Type *  base,
enet_mii_speed_t  speed,
enet_mii_duplex_t  duplex 
)
inlinestatic

This API is provided to dynamically change the speed and dulpex for MAC.

Parameters
baseENET peripheral base address.
speedThe speed of the RMII mode.
duplexThe duplex of the RMII mode.
void ENET_SetSMI ( ENET_Type *  base)
Parameters
baseENET peripheral base address.
static bool ENET_IsSMIBusy ( ENET_Type *  base)
inlinestatic
Parameters
baseENET peripheral base address.
Returns
The status of MII Busy status.
static uint16_t ENET_ReadSMIData ( ENET_Type *  base)
inlinestatic
Parameters
baseENET peripheral base address.
Returns
The data read from PHY
void ENET_StartSMIWrite ( ENET_Type *  base,
uint8_t  phyAddr,
uint8_t  regAddr,
uint16_t  data 
)
Parameters
baseENET peripheral base address.
phyAddrThe PHY address.
regAddrThe PHY register.
dataThe data written to PHY.
void ENET_StartSMIRead ( ENET_Type *  base,
uint8_t  phyAddr,
uint8_t  regAddr 
)
Parameters
baseENET peripheral base address.
phyAddrThe PHY address.
regAddrThe PHY register.
status_t ENET_MDIOWrite ( ENET_Type *  base,
uint8_t  phyAddr,
uint8_t  regAddr,
uint16_t  data 
)
Parameters
baseENET peripheral base address.
phyAddrThe PHY address.
regAddrThe PHY register.
dataThe data written to PHY.
Returns
kStatus_Success MDIO access succeeds.
kStatus_Timeout MDIO access timeout.
status_t ENET_MDIORead ( ENET_Type *  base,
uint8_t  phyAddr,
uint8_t  regAddr,
uint16_t *  pData 
)
Parameters
baseENET peripheral base address.
phyAddrThe PHY address.
regAddrThe PHY register.
pDataThe data read from PHY.
Returns
kStatus_Success MDIO access succeeds.
kStatus_Timeout MDIO access timeout.
uint32_t ENET_GetInstance ( ENET_Type *  base)
Parameters
baseENET peripheral base address.
Returns
ENET instance.
static void ENET_SetMacAddr ( ENET_Type *  base,
uint8_t *  macAddr 
)
inlinestatic
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.
static void ENET_AcceptAllMulticast ( ENET_Type *  base)
inlinestatic
Parameters
baseENET peripheral base address.
static void ENET_RejectAllMulticast ( ENET_Type *  base)
inlinestatic
Parameters
baseENET peripheral base address.
void ENET_EnterPowerDown ( ENET_Type *  base,
uint32_t *  wakeFilter 
)

the remote power wake up frame and magic frame can wake up the ENET from the power down mode.

Parameters
baseENET peripheral base address.
wakeFilterThe wakeFilter provided to configure the wake up frame fitlter. Set the wakeFilter to NULL is not required. But if you have the filter requirement, please make sure the wakeFilter pointer shall be eight continous 32-bits configuration.
static void ENET_ExitPowerDown ( ENET_Type *  base)
inlinestatic

Eixt from the power down mode and recover to normal work mode.

Parameters
baseENET peripheral base address.
void ENET_EnableInterrupts ( ENET_Type *  base,
uint32_t  mask 
)

This function enables the ENET interrupt according to the provided mask. The mask is a logical OR of enet_dma_interrupt_enable_t and enet_mac_interrupt_enable_t. For example, to enable the dma and mac interrupt, do the following.

* ENET_EnableInterrupts(ENET, kENET_DmaRx | kENET_DmaTx | kENET_MacPmt);
*
Parameters
baseENET peripheral base address.
maskENET interrupts to enable. This is a logical OR of both enumeration :: enet_dma_interrupt_enable_t and enet_mac_interrupt_enable_t.
void ENET_DisableInterrupts ( ENET_Type *  base,
uint32_t  mask 
)

This function disables the ENET interrupt according to the provided mask. The mask is a logical OR of enet_dma_interrupt_enable_t and enet_mac_interrupt_enable_t. For example, to disable the dma and mac interrupt, do the following.

*
Parameters
baseENET peripheral base address.
maskENET interrupts to disables. This is a logical OR of both enumeration :: enet_dma_interrupt_enable_t and enet_mac_interrupt_enable_t.
static uint32_t ENET_GetDmaInterruptStatus ( ENET_Type *  base,
uint8_t  channel 
)
inlinestatic
Parameters
baseENET peripheral base address.
channelThe DMA Channel. Shall not be larger than ENET_RING_NUM_MAX.
Returns
The event status of the interrupt source. This is the logical OR of members of the enumeration :: enet_dma_interrupt_enable_t.
static void ENET_ClearDmaInterruptStatus ( ENET_Type *  base,
uint8_t  channel,
uint32_t  mask 
)
inlinestatic
Parameters
baseENET peripheral base address.
channelThe DMA Channel. Shall not be larger than ENET_RING_NUM_MAX.
maskThe event status of the interrupt source. This is the logical OR of members of the enumeration :: enet_dma_interrupt_enable_t.
static uint32_t ENET_GetMacInterruptStatus ( ENET_Type *  base)
inlinestatic
Parameters
baseENET peripheral base address.
Returns
The event status of the interrupt source. Use the enum in enet_mac_interrupt_enable_t and right shift ENET_MACINT_ENUM_OFFSET to mask the returned value to get the exact interrupt status.
void ENET_ClearMacInterruptStatus ( ENET_Type *  base,
uint32_t  mask 
)

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

* ENET_ClearMacInterruptStatus(ENET, kENET_MacPmt);
*
Parameters
baseENET peripheral base address.
maskENET interrupt source to be cleared. This is the logical OR of members of the enumeration :: enet_mac_interrupt_enable_t.
static bool ENET_IsTxDescriptorDmaOwn ( enet_tx_bd_struct_t txDesc)
inlinestatic
Parameters
txDescThe given Tx descriptor.
Return values
Truethe dma own Tx descriptor, false application own Tx descriptor.
void ENET_SetupTxDescriptor ( enet_tx_bd_struct_t txDesc,
void *  buffer1,
uint32_t  bytes1,
void *  buffer2,
uint32_t  bytes2,
uint32_t  framelen,
bool  intEnable,
bool  tsEnable,
enet_desc_flag_t  flag,
uint8_t  slotNum 
)

This function is a low level functional API to setup or prepare a given Tx descriptor.

Parameters
txDescThe given Tx descriptor.
buffer1The first buffer address in the descriptor.
bytes1The bytes in the fist buffer.
buffer2The second buffer address in the descriptor.
bytes2The bytes in the second buffer.
framelenThe length of the frame to be transmitted.
intEnableInterrupt enable flag.
tsEnableThe timestamp enable.
flagThe flag of this Tx desciriptor, see "enet_desc_flag_t" .
slotNumThe slot num used for AV mode only.
Note
This must be called after all the ENET initilization. And should be called when the ENET receive/transmit is required. Transmit buffers are 'zero-copy' buffers, so the buffer must remain in memory until the packet has been fully transmitted. The buffers should be free or requeued in the transmit interrupt irq handler.
static void ENET_UpdateTxDescriptorTail ( ENET_Type *  base,
uint8_t  channel,
uint32_t  txDescTailAddrAlign 
)
inlinestatic

This function is a low level functional API to update the the Tx descriptor tail. This is called after you setup a new Tx descriptor to update the tail pointer to make the new descritor accessable by DMA.

Parameters
baseENET peripheral base address.
channelThe Tx DMA channel.
txDescTailAddrAlignThe new Tx tail pointer address.
static void ENET_UpdateRxDescriptorTail ( ENET_Type *  base,
uint8_t  channel,
uint32_t  rxDescTailAddrAlign 
)
inlinestatic

This function is a low level functional API to update the the Rx descriptor tail. This is called after you setup a new Rx descriptor to update the tail pointer to make the new descritor accessable by DMA and to anouse the Rx poll command for DMA.

Parameters
baseENET peripheral base address.
channelThe Rx DMA channel.
rxDescTailAddrAlignThe new Rx tail pointer address.
static uint32_t ENET_GetRxDescriptor ( enet_rx_bd_struct_t rxDesc)
inlinestatic

This function is a low level functional API to get the the status flag from a given Rx descriptor.

Parameters
rxDescThe given Rx descriptor.
Return values
TheRDES3 regions for write-back format Rx buffer descriptor.
Note
This must be called after all the ENET initilization. And should be called when the ENET receive/transmit is required.
void ENET_UpdateRxDescriptor ( enet_rx_bd_struct_t rxDesc,
void *  buffer1,
void *  buffer2,
bool  intEnable,
bool  doubleBuffEnable 
)

This function is a low level functional API to Updates the buffers and the own status for a given Rx descriptor.

Parameters
rxDescThe given Rx descriptor.
buffer1The first buffer address in the descriptor.
buffer2The second buffer address in the descriptor.
intEnableInterrupt enable flag.
doubleBuffEnableThe double buffer enable flag.
Note
This must be called after all the ENET initilization. And should be called when the ENET receive/transmit is required.
void ENET_CreateHandler ( ENET_Type *  base,
enet_handle_t *  handle,
enet_config_t config,
enet_buffer_config_t bufferConfig,
enet_callback_t  callback,
void *  userData 
)

This is a transactional API and it's provided to store all datas which are needed during the whole transactional process. This API should not be used when you use functional APIs to do data Tx/Rx. This is funtion will store many data/flag for transactional use.

Parameters
baseENET peripheral base address.
handleENET handler.
configENET configuration.
bufferConfigENET buffer configuration.
callbackThe callback function.
userDataThe application data.
status_t ENET_GetRxFrameSize ( ENET_Type *  base,
enet_handle_t *  handle,
uint32_t *  length,
uint8_t  channel 
)

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

Note
The FCS of the frame is automatically removed by MAC 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
baseENET peripheral base address.
handleThe ENET handler structure. This is the same handler pointer used in the ENET_Init.
lengthThe length of the valid frame received.
channelThe DMAC channel for the Rx.
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,
uint8_t  channel,
enet_ptp_time_t timestamp 
)

This function reads a frame from the ENET DMA descriptors. The ENET_GetRxFrameSize should be used to get the size of the prepared data buffer. For example use Rx dma channel 0:

* uint32_t length;
* enet_handle_t g_handle;
* Comment: Get the received frame size firstly.
* status = ENET_GetRxFrameSize(&g_handle, &length, 0);
* if (length != 0)
* {
* Comment: Allocate memory here with the size of "length"
* uint8_t *data = memory allocate interface;
* if (!data)
* {
* ENET_ReadFrame(ENET, &g_handle, NULL, 0, 0);
* }
* else
* {
* status = ENET_ReadFrame(ENET, &g_handle, data, length, 0);
* }
* }
* else if (status == kStatus_ENET_RxFrameError)
* {
* Comment: Update the received buffer when a error frame is received.
* ENET_ReadFrame(ENET, &g_handle, NULL, 0, 0);
* }
*
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.
channelThe Rx DMA channel. Shall not be larger than 2.
timestampThe timestamp address to store received timestamp.
Returns
The execute status, successful or failure.
status_t ENET_GetRxFrame ( ENET_Type *  base,
enet_handle_t *  handle,
enet_rx_frame_struct_t rxFrame,
uint8_t  channel 
)

This function will use the user-defined allocate and free callback. Every time application gets one frame through this function, driver will allocate new buffers for the BDs whose buffers have been taken by application.

Note
This function will drop current frame and update related BDs as available for DMA if new buffers allocating fails. Application must provide a memory pool including at least BD number + 1 buffers(+2 if enable double buffer) to make this function work normally.
Parameters
baseENET peripheral base address.
handleThe ENET handler pointer. This is the same handler pointer used in the ENET_Init.
rxFrameThe received frame information structure provided by user.
channelThe Rx DMA channel. Shall not be larger than 2.
Return values
kStatus_SuccessSucceed to get one frame and allocate new memory for Rx buffer.
kStatus_ENET_RxFrameEmptyThere's no Rx frame in the BD.
kStatus_ENET_RxFrameErrorThere's issue in this receiving. In this function, issue frame will be dropped.
kStatus_ENET_RxFrameDropThere's no new buffer memory for BD, dropped this frame.
status_t ENET_SendFrame ( ENET_Type *  base,
enet_handle_t *  handle,
enet_tx_frame_struct_t *  txFrame,
uint8_t  channel 
)
Note
The CRC is automatically appended to the data. Input the data to send without the CRC. This API uses input buffer for Tx, application should reclaim the buffer after Tx is over.
Parameters
baseENET peripheral base address.
handleThe ENET handler pointer. This is the same handler pointer used in the ENET_Init.
txFrameThe Tx frame structure.
channelChannel to send the frame, same with queue index.
Return values
kStatus_SuccessSend frame succeed.
kStatus_ENET_TxFrameBusyTransmit buffer descriptor is busy under transmission. The transmit busy happens when the data send rate is over the MAC capacity. The waiting mechanism is recommended to be added after each call return with kStatus_ENET_TxFrameBusy. Also need to pay attention to reclaim Tx frame after Tx is over.
kStatus_ENET_TxFrameOverLenTransmit frme length exceeds the 0x3FFF limit defined by the driver.
void ENET_ReclaimTxDescriptor ( ENET_Type *  base,
enet_handle_t *  handle,
uint8_t  channel 
)

This function is used to update the Tx descriptor status and store the Tx timestamp when the 1588 feature is enabled. This is called by the transmit interupt IRQ handler after the complete of a frame transmission.

Parameters
baseENET peripheral base address.
handleThe ENET handler pointer. This is the same handler pointer used in the ENET_Init.
channelThe Tx DMA channnel.
void ENET_IRQHandler ( ENET_Type *  base,
enet_handle_t *  handle 
)
Parameters
baseENET peripheral base address.
handleThe ENET handler pointer.

Variable Documentation

const clock_ip_name_t s_enetClock[]