The MCUXpresso SDK provides a peripheral driver for the 10/100 Mbps Ethernet (ENET)module of MCUXpresso SDK devices.
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.
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.
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.
This group provide the DMA interrupt get and clear APIs. This can be used by application to create new IRQ handler.
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.
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.
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
|
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 = MAKE_STATUS(kStatusGroup_ENET, 3U),
kStatus_ENET_TxFrameFail = MAKE_STATUS(kStatusGroup_ENET, 4U),
kStatus_ENET_TxFrameOverLen = MAKE_STATUS(kStatusGroup_ENET, 5U)
} |
| 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 {
kENET_MiiWriteFrame = 1U,
kENET_MiiReadFrame = 3U
} |
| Define the MII opcode for normal MDIO_CLAUSES_22 Frame. More...
|
|
enum | enet_dma_burstlen {
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 {
kENET_MiddleFlag = 0,
kENET_FirstFlagOnly,
kENET_LastFlagOnly,
kENET_FirstLastFlag
} |
| Define the flag for the descriptor. More...
|
|
enum | enet_systime_op {
kENET_SystimeAdd = 0U,
kENET_SystimeSubtract = 1U
} |
| Define the system time adjust operation control. More...
|
|
enum | enet_ts_rollover_type {
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
} |
| 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 {
kENET_FixPri = 0,
kENET_WeightStrPri,
kENET_WeightRoundRobin
} |
| Define the DMA transmit arbitration for multi-queue. More...
|
|
enum | enet_mtl_multiqueue_txsche {
kENET_txWeightRR = 0U,
kENET_txStrPrio = 3U
} |
| Define the MTL tx scheduling algorithm for multiple queues/rings. More...
|
|
enum | enet_mtl_multiqueue_rxsche {
kENET_rxStrPrio = 0U,
kENET_rxWeightStrPrio
} |
| Define the MTL rx scheduling algorithm for multiple queues/rings. More...
|
|
enum | enet_mtl_rxqueuemap {
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...
|
|
|
#define | ENET_RXDESCRIP_RD_BUFF1VALID_MASK (1U << 24) |
| Defines for read format. More...
|
|
#define | ENET_RXDESCRIP_RD_BUFF2VALID_MASK (1U << 25) |
| Buffer2 address valid. More...
|
|
#define | ENET_RXDESCRIP_RD_IOC_MASK (1U << 30) |
| Interrupt enable on complete. More...
|
|
#define | ENET_RXDESCRIP_RD_OWN_MASK (1U << 31) |
| Own bit. More...
|
|
#define | ENET_RXDESCRIP_WR_ERR_MASK ((1U << 3) | (1U << 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 (1U << 12) |
|
#define | ENET_RXDESCRIP_WR_PTPVERSION_MASK (1U << 13) |
|
#define | ENET_RXDESCRIP_WR_PTPTSA_MASK (1U << 14) |
|
#define | ENET_RXDESCRIP_WR_PACKETLEN_MASK (0x7FFFU) |
|
#define | ENET_RXDESCRIP_WR_ERRSUM_MASK (1U << 15) |
|
#define | ENET_RXDESCRIP_WR_TYPE_MASK (0x30000U) |
|
#define | ENET_RXDESCRIP_WR_DE_MASK (1U << 19) |
|
#define | ENET_RXDESCRIP_WR_RE_MASK (1U << 20) |
|
#define | ENET_RXDESCRIP_WR_OE_MASK (1U << 21) |
|
#define | ENET_RXDESCRIP_WR_RS0V_MASK (1U << 25) |
|
#define | ENET_RXDESCRIP_WR_RS1V_MASK (1U << 26) |
|
#define | ENET_RXDESCRIP_WR_RS2V_MASK (1U << 27) |
|
#define | ENET_RXDESCRIP_WR_LD_MASK (1U << 28) |
|
#define | ENET_RXDESCRIP_WR_FD_MASK (1U << 29) |
|
#define | ENET_RXDESCRIP_WR_CTXT_MASK (1U << 30) |
|
#define | ENET_RXDESCRIP_WR_OWN_MASK (1U << 31) |
|
|
#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 (1U << 30) |
|
#define | ENET_TXDESCRIP_RD_IOC_MASK (1U << 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) & 0x3) << 16) |
|
#define | ENET_TXDESCRIP_RD_TSE_MASK (1U << 18) |
|
#define | ENET_TXDESCRIP_RD_SLOT(n) (((uint32_t)(n) & 0x0f) << 19) |
|
#define | ENET_TXDESCRIP_RD_SAIC(n) (((uint32_t)(n) & 0x07) << 23) |
|
#define | ENET_TXDESCRIP_RD_CPC(n) (((uint32_t)(n) & 0x03) << 26) |
|
#define | ENET_TXDESCRIP_RD_LDFD(n) (((uint32_t)(n) & 0x03) << 28) |
|
#define | ENET_TXDESCRIP_RD_LD_MASK (1U << 28) |
|
#define | ENET_TXDESCRIP_RD_FD_MASK (1U << 29) |
|
#define | ENET_TXDESCRIP_RD_CTXT_MASK (1U << 30) |
|
#define | ENET_TXDESCRIP_RD_OWN_MASK (1UL << 31) |
|
#define | ENET_TXDESCRIP_WB_TTSS_MASK (1UL << 17) |
| Defines for write back format. More...
|
|
|
#define | ENET_ABNORM_INT_MASK |
|
#define | ENET_NORM_INT_MASK |
|
|
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 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...
|
|
|
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) |
| 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_ReclaimTxDescriptor (ENET_Type *base, enet_handle_t *handle, uint8_t channel) |
| Reclaim tx descriptors. More...
|
|
void | ENET_PMTIRQHandler (ENET_Type *base, enet_handle_t *handle) |
| The ENET PMT IRQ handler. More...
|
|
void | ENET_IRQHandler (ENET_Type *base, enet_handle_t *handle) |
| The ENET IRQ handler. More...
|
|
struct enet_rx_bd_struct_t |
They both has the same size with different region definition. so we define the read-format region as the recive descriptor structure Use the read-format region mask bits in the descriptor initialization Use the write-back format region mask bits in the receive data process.
Data Fields |
__IO uint32_t | buff1Addr |
| Buffer 1 address.
|
|
__IO uint32_t | reserved |
| Reserved.
|
|
__IO uint32_t | buff2Addr |
| Buffer 2 or next descriptor address.
|
|
__IO uint32_t | control |
| Buffer 1/2 byte counts and control.
|
|
struct enet_tx_bd_struct_t |
They both has the same size with different region definition. so we define the read-format region as the transmit descriptor structure Use the read-format region mask bits in the descriptor initialization Use the write-back format region mask bits in the transmit data process.
Data Fields |
__IO uint32_t | buff1Addr |
| Buffer 1 address.
|
|
__IO uint32_t | buff2Addr |
| Buffer 2 address.
|
|
__IO uint32_t | buffLen |
| Buffer 1/2 byte counts.
|
|
__IO uint32_t | controlStat |
| TDES control and status word.
|
|
struct enet_buffer_config_t |
Notes:
- The receive and transmit descriptor start address pointer and tail pointer must be word-aligned.
- The recommended minimum tx/rx ring length is 4.
- 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.
- 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.
- 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.
uint8_t enet_buffer_config_t::rxRingLen |
uint8_t enet_buffer_config_t::txRingLen |
uint32_t* enet_buffer_config_t::rxBufferStartAddr |
uint32_t enet_buffer_config_t::rxBuffSizeAlign |
struct enet_multiqueue_config_t |
Note:
- 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.
uint16_t enet_config_t::pauseDuration |
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 |
uint16_t enet_rx_bd_ring_t::rxGenIdx |
uint16_t enet_rx_bd_ring_t::rxRingLen |
uint32_t enet_rx_bd_ring_t::rxBuffSizeAlign |
bool enet_handle_t::multiQueEnable |
bool enet_handle_t::doubleBuffEnable |
bool enet_handle_t::rxintEnable |
void* enet_handle_t::userData |
#define ENET_RXDESCRIP_RD_BUFF1VALID_MASK (1U << 24) |
#define ENET_RXDESCRIP_RD_BUFF2VALID_MASK (1U << 25) |
#define ENET_RXDESCRIP_RD_IOC_MASK (1U << 30) |
#define ENET_RXDESCRIP_RD_OWN_MASK (1U << 31) |
#define ENET_RXDESCRIP_WR_ERR_MASK ((1U << 3) | (1U << 7)) |
#define ENET_TXDESCRIP_RD_BL1_MASK (0x3fffU) |
#define ENET_TXDESCRIP_WB_TTSS_MASK (1UL << 17) |
#define ENET_FRAME_MAX_FRAMELEN (1518U) |
#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) |
typedef void(* enet_callback_t)(ENET_Type *base, enet_handle_t *handle, enet_event_t event, uint8_t channel, void *userData) |
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 descriptors are under process.
|
kStatus_ENET_TxFrameFail |
Transmit frame fail.
|
kStatus_ENET_TxFrameOverLen |
Transmit oversize.
|
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_FirstFlagOnly |
It's the first descriptor of the frame.
|
kENET_LastFlagOnly |
It's the last 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.
|
This enumeration uses one-bot 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-bot 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.
|
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
-
config | The 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.
- Parameters
-
base | ENET peripheral base address. |
config | ENET 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. |
macAddr | ENET mac address of Ethernet device. This MAC address should be provided. |
refclkSrc_Hz | ENET input reference clock. |
void ENET_Deinit |
( |
ENET_Type * |
base | ) |
|
This function gates the module clock and disables the ENET module.
- Parameters
-
base | ENET peripheral base address. |
- Note
- This function is do all tx/rx descriptors initialization. Because this API read all interrupt registers first and then set the interrupt flag for all descriptos, if the interrupt register is set. so the descriptor initialization should be called after ENET_Init(), ENET_EnableInterrupts() and ENET_CreateHandle()(if transactional APIs are used).
- Parameters
-
base | ENET peripheral base address. |
config | The configuration for ENET. |
bufferConfig | All buffers configuration. |
void ENET_StartRxTx |
( |
ENET_Type * |
base, |
|
|
uint8_t |
txRingNum, |
|
|
uint8_t |
rxRingNum |
|
) |
| |
This function enable the tx/rx and starts the rx/tx DMA. This shall be set after ENET initialization and before starting to receive the data.
- Parameters
-
base | ENET peripheral base address. |
rxRingNum | The 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. |
txRingNum | The 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.
This API is provided to dynamically change the speed and dulpex for MAC.
- Parameters
-
base | ENET peripheral base address. |
speed | The speed of the RMII mode. |
duplex | The duplex of the RMII mode. |
void ENET_SetSMI |
( |
ENET_Type * |
base | ) |
|
- Parameters
-
base | ENET peripheral base address. |
static bool ENET_IsSMIBusy |
( |
ENET_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | ENET peripheral base address. |
- Returns
- The status of MII Busy status.
static uint16_t ENET_ReadSMIData |
( |
ENET_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | ENET peripheral base address. |
- Returns
- The data read from PHY
void ENET_StartSMIRead |
( |
ENET_Type * |
base, |
|
|
uint32_t |
phyAddr, |
|
|
uint32_t |
phyReg |
|
) |
| |
support both MDIO IEEE802.3 Clause 22 and clause 45.
- Parameters
-
base | ENET peripheral base address. |
phyAddr | The PHY address. |
phyReg | The PHY register. |
void ENET_StartSMIWrite |
( |
ENET_Type * |
base, |
|
|
uint32_t |
phyAddr, |
|
|
uint32_t |
phyReg, |
|
|
uint32_t |
data |
|
) |
| |
support both MDIO IEEE802.3 Clause 22 and clause 45.
- Parameters
-
base | ENET peripheral base address. |
phyAddr | The PHY address. |
phyReg | The PHY register. |
data | The data written to PHY. |
static void ENET_SetMacAddr |
( |
ENET_Type * |
base, |
|
|
uint8_t * |
macAddr |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | ENET peripheral base address. |
macAddr | The 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
-
base | ENET peripheral base address. |
macAddr | The six-byte Mac address pointer. The pointer is allocated by application and input into the API. |
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
-
base | ENET peripheral base address. |
wakeFilter | The 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 noraml work mode.
- Parameters
-
base | ENET 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.
- Parameters
-
base | ENET peripheral base address. |
mask | ENET 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
-
base | ENET peripheral base address. |
mask | ENET 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
-
base | ENET peripheral base address. |
channel | The 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
-
base | ENET peripheral base address. |
channel | The 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 uint32_t ENET_GetMacInterruptStatus |
( |
ENET_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | ENET 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.
- Parameters
-
base | ENET peripheral base address. |
mask | ENET interrupt source to be cleared. This is the logical OR of members of the enumeration :: enet_mac_interrupt_enable_t. |
- Parameters
-
txDesc | The given tx descriptor. |
- Return values
-
True | the 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 |
flag, |
|
|
uint8_t |
slotNum |
|
) |
| |
This function is a low level functional API to setup or prepare a given tx descriptor.
- Parameters
-
txDesc | The given tx descriptor. |
buffer1 | The first buffer address in the descriptor. |
bytes1 | The bytes in the fist buffer. |
buffer2 | The second buffer address in the descriptor. |
bytes1 | The bytes in the second buffer. |
framelen | The length of the frame to be transmitted. |
intEnable | Interrupt enable flag. |
tsEnable | The timestamp enable. |
flag | The flag of this tx desciriptor, see "enet_desc_flag" . |
slotNum | The slot num used for AV 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
-
base | ENET peripheral base address. |
channel | The tx DMA channel. |
txDescTailAddrAlign | The 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
-
base | ENET peripheral base address. |
channel | The rx DMA channel. |
rxDescTailAddrAlign | The new rx tail pointer address. |
This function is a low level functional API to get the the status flag from a given rx descriptor.
- Parameters
-
rxDesc | The given rx descriptor. |
- Return values
-
The | RDES3 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
-
rxDesc | The given rx descriptor. |
buffer1 | The first buffer address in the descriptor. |
buffer2 | The second buffer address in the descriptor. |
intEnable | Interrupt enable flag. |
doubleBuffEnable | The 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.
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, so all configure API such as ENET_Init(), ENET_DescriptorInit(), ENET_EnableInterrupts() etc.
- Note
- as our transactional transmit API use the zero-copy transmit buffer. so there are two thing we emphasize here:
- 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.
- the tx interrupt is forced to open.
- Parameters
-
base | ENET peripheral base address. |
handle | ENET handler. |
config | ENET configuration. |
bufferConfig | ENET buffer configuration. |
callback | The callback function. |
userData | The 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
-
handle | The ENET handler structure. This is the same handler pointer used in the ENET_Init. |
length | The length of the valid frame received. |
channel | The DMAC channel for the rx. |
- Return values
-
kStatus_ENET_RxFrameEmpty | No frame received. Should not call ENET_ReadFrame to read frame. |
kStatus_ENET_RxFrameError | Data error happens. ENET_ReadFrame should be called with NULL data and NULL length to update the receive buffers. |
kStatus_Success | Receive 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 |
|
) |
| |
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;
*
* if (length != 0)
* {
*
* uint8_t *data = memory allocate interface;
* if (!data)
* {
*
* }
* else
* {
*
* }
* }
* {
*
* }
*
- Parameters
-
base | ENET peripheral base address. |
handle | The ENET handler structure. This is the same handler pointer used in the ENET_Init. |
data | The data buffer provided by user to store the frame which memory size should be at least "length". |
length | The size of the data buffer which is still the length of the received frame. |
channel | The rx DMA channel. shall not be larger than 2. |
- 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
-
base | ENET peripheral base address. |
handle | The ENET handler pointer. This is the same handler pointer used in the ENET_Init. |
data | The data buffer provided by user to be send. |
length | The length of the data to be send. |
- Return values
-
kStatus_Success | Send frame succeed. |
kStatus_ENET_TxFrameBusy | Transmit 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. |
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
-
base | ENET peripheral base address. |
handle | The ENET handler pointer. This is the same handler pointer used in the ENET_Init. |
channel | The tx DMA channnel. |
void ENET_PMTIRQHandler |
( |
ENET_Type * |
base, |
|
|
enet_handle_t * |
handle |
|
) |
| |
- Parameters
-
base | ENET peripheral base address. |
handle | The ENET handler pointer. |
void ENET_IRQHandler |
( |
ENET_Type * |
base, |
|
|
enet_handle_t * |
handle |
|
) |
| |
- Parameters
-
base | ENET peripheral base address. |
handle | The ENET handler pointer. |