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
|
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...
|
|
|
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...
|
|
|
#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) |
|
|
#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...
|
|
|
#define | ENET_ABNORM_INT_MASK |
|
#define | ENET_NORM_INT_MASK |
|
|
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...
|
|
|
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...
|
|
|
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...
|
|
|
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...
|
|
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 |
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 |
uint8_t enet_tx_bd_config_struct_t::slotNum |
uint64_t enet_ptp_time_t::second |
uint32_t enet_ptp_time_t::nanosecond |
struct enet_tx_reclaim_info_t |
struct enet_tx_dirty_ring_t |
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:
- 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.
uint32_t enet_config_t::interrupt |
A logical OR of enet_dma_interrupt_enable_t and enet_mac_interrupt_enable_t.
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 |
struct enet_rx_frame_attribute_t |
bool enet_rx_frame_attribute_t::isTsAvail |
struct enet_rx_frame_error_t |
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 |
enet_buffer_struct_t* enet_rx_frame_struct_t::rxBuffArray |
uint16_t enet_rx_frame_struct_t::totLen |
#define ENET_RXDESCRIP_RD_BUFF1VALID_MASK (1UL << 24) |
#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_RX_ERROR_BITS |
( |
|
x | ) |
(((x) >> 19U) & 0x3FU) |
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) |
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.
|
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.
- 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. |
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 finishes all Tx/Rx descriptors initialization. The descriptor initialization should be called after ENET_Init().
- Parameters
-
base | ENET peripheral base address. |
config | The configuration for ENET. |
bufferConfig | All 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
-
base | ENET peripheral base address. |
handle | The 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
-
base | ENET peripheral base address. |
handle | The 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
-
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.
void ENET_SetISRHandler |
( |
ENET_Type * |
base, |
|
|
enet_isr_t |
ISRHandler |
|
) |
| |
- Parameters
-
base | ENET peripheral base address. |
ISRHandler | The handler to install. |
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_StartSMIWrite |
( |
ENET_Type * |
base, |
|
|
uint8_t |
phyAddr, |
|
|
uint8_t |
regAddr, |
|
|
uint16_t |
data |
|
) |
| |
- Parameters
-
base | ENET peripheral base address. |
phyAddr | The PHY address. |
regAddr | The PHY register. |
data | The data written to PHY. |
void ENET_StartSMIRead |
( |
ENET_Type * |
base, |
|
|
uint8_t |
phyAddr, |
|
|
uint8_t |
regAddr |
|
) |
| |
- Parameters
-
base | ENET peripheral base address. |
phyAddr | The PHY address. |
regAddr | The PHY register. |
status_t ENET_MDIOWrite |
( |
ENET_Type * |
base, |
|
|
uint8_t |
phyAddr, |
|
|
uint8_t |
regAddr, |
|
|
uint16_t |
data |
|
) |
| |
- Parameters
-
base | ENET peripheral base address. |
phyAddr | The PHY address. |
regAddr | The PHY register. |
data | The 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
-
base | ENET peripheral base address. |
phyAddr | The PHY address. |
regAddr | The PHY register. |
pData | The data read from PHY. |
- Returns
- kStatus_Success MDIO access succeeds.
-
kStatus_Timeout MDIO access timeout.
uint32_t ENET_GetInstance |
( |
ENET_Type * |
base | ) |
|
- Parameters
-
base | ENET peripheral base address. |
- Returns
- ENET instance.
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. |
static void ENET_AcceptAllMulticast |
( |
ENET_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | ENET peripheral base address. |
static void ENET_RejectAllMulticast |
( |
ENET_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | ENET 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
-
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 normal 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. |
mask | 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_t |
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. |
bytes2 | 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_t" . |
slotNum | The 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
-
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.
- 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
-
base | ENET peripheral base address. |
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, |
|
|
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.
* if (length != 0)
* {
* Comment: Allocate memory here with the size of "length"
* uint8_t *data = memory allocate interface;
* if (!data)
* {
* }
* else
* {
* }
* }
* {
* Comment: Update the received buffer when a error frame is received.
* }
*
- 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. |
timestamp | The timestamp address to store received timestamp. |
- Returns
- The execute status, successful or failure.
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
-
base | ENET peripheral base address. |
handle | The ENET handler pointer. This is the same handler pointer used in the ENET_Init. |
rxFrame | The received frame information structure provided by user. |
channel | The Rx DMA channel. Shall not be larger than 2. |
- Return values
-
kStatus_Success | Succeed to get one frame and allocate new memory for Rx buffer. |
kStatus_ENET_RxFrameEmpty | There's no Rx frame in the BD. |
kStatus_ENET_RxFrameError | There's issue in this receiving. In this function, issue frame will be dropped. |
kStatus_ENET_RxFrameDrop | There'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
-
base | ENET peripheral base address. |
handle | The ENET handler pointer. This is the same handler pointer used in the ENET_Init. |
txFrame | The Tx frame structure. |
channel | Channel to send the frame, same with queue index. |
- 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. Also need to pay attention to reclaim Tx frame after Tx is over. |
kStatus_ENET_TxFrameOverLen | Transmit 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
-
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_IRQHandler |
( |
ENET_Type * |
base, |
|
|
enet_handle_t * |
handle |
|
) |
| |
- Parameters
-
base | ENET peripheral base address. |
handle | The ENET handler pointer. |