| Kinetis SDK API Reference Manual 1.0.0-beta Freescale Semiconductor, Inc.

- Introduction
- Related Pages
- API Usage

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
Data Structures | Macros | Enumerations | Variables
ENET Peripheral Driver
Ethernet MAC (ENET)

The section describes the programming interface of the ENET Peripheral Driver. More...

## Data Structures
struct | enet_multicast_group_t
| Defines the multicast group structure for the ENET device. More...
struct | enet_rxbd_config_t
| Defines the receive buffer descriptor configure structure. More...
struct | enet_txbd_config_t
| Defines the transmit buffer descriptor configure structure. More...
struct | enet_mac_config_t
| Defines the basic configuration structure for the ENET device. More...
struct | enet_phy_config_t
| Defines the basic configuration for PHY. More...
struct | enet_ethernet_header_t
| Defines the ENET header structure. More...
struct | enet_8021vlan_header_t
| Defines the ENET VLAN frame header structure. More...
struct | enet_mac_context_t
| Defines the ENET MAC context structure for the buffer address, buffer descriptor address, etc. More...
struct | enet_stats_t
| Defines the ENET packets statistic structure. More...
struct | enet_mac_packet_buffer_t
| Defines the ENET MAC packet buffer structure. More...
struct | enet_dev_if_t
| Defines the ENET device data structure for the ENET. More...
struct | enet_mac_api_t
| Defines the basic application for the ENET device. More...

## Macros
#define | ENET_RECEIVE_ALL_INTERRUPT 0
| Defines the approach: ENET interrupt handler do receive.
#define | ENET_ENABLE_DETAIL_STATS 0
| Defines the statistic enable macro. More...
#define | ENET_ALIGN(x, align) ((unsigned int)((x) + ((align)-1)) & (unsigned int)(~(unsigned int)((align)- 1)))
| Defines the alignment operation. More...

## Enumerations
enum | enet_interrupt_number_t { kEnetTstimerInt = 0, kEnetTsAvailInt, kEnetWakeUpInt, kEnetPlrInt, kEnetUnInt, kEnetRlInt, kEnetLcInt, kEnetEberrInt, kEnetMiiInt, kEnetRxbInt, kEnetRxfInt, kEnetTxbInt, kEnetTxfInt, kEnetGraInt, kEnetBabtInt, kEnetBabrInt, kEnetIntNum }
| Defines the interrupt source index for the interrupt vector change table. More...
enum | enet_frame_max_t { kEnetMaxTimeout = 0x10000, kEnetMaxFrameSize = 1518, kEnetMaxFrameVlanSize = 1522, kEnetMaxFrameDateSize = 1500, kEnetMaxFrameBdNumbers = 7, kEnetFrameFcsLen = 4, kEnetEthernetHeadLen = 14, kEnetEthernetVlanHeadLen = 18 }
| Defines the ENET main constant. More...
enum | enet_crc_parameter_t { kEnetCrcData = 0xFFFFFFFFU, kEnetCrcOffset = 8, kEnetCrcMask1 = 0x3F }
| Defines the CRC data for a hash value calculation. More...
enum | enet_protocol_type_t { kEnetProtocolIeee8023 = 0x88F7, kEnetProtocolIpv4 = 0x0800, kEnetProtocolIpv6 = 0x86dd, kEnetProtocol8021QVlan = 0x8100, kEnetPacketUdpVersion = 0x11, kEnetPacketIpv4Version = 0x4, kEnetPacketIpv6Version = 0x6 }
| Defines the ENET protocol type and main parameters. More...
enum | enet_mac_control_flag_t { kEnetSleepModeEnable = 0x1, kEnetPayloadlenCheckEnable = 0x2, kEnetRxFlowControlEnable = 0x4, kEnetRxCrcFwdEnable = 0x8, kEnetRxPauseFwdEnable = 0x10, kEnetRxPadRemoveEnable = 0x20, kEnetRxBcRejectEnable = 0x40, kEnetRxPromiscuousEnable = 0x80, kEnetRxMiiLoopback = 0x100, kEnetRxDisRxOnTx = 0x200 }
| Defines the ENET MAC control Configure. More...

## Variables
const enet_mac_api_t | g_enetMacApi

## ENET Driver
uint32_t | enet_mii_read (uint32_t instance, uint32_t phyAddr, uint32_t phyReg, uint32_t *dataPtr)
| (R)MII Read function. More...
uint32_t | enet_mii_write (uint32_t instance, uint32_t phyAddr, uint32_t phyReg, uint32_t data)
| (R)MII Read function. More...
uint32_t | enet_mac_bd_init (enet_dev_if_t *enetIfPtr)
| Initializes ENET buffer descriptors. More...
uint32_t | enet_mac_mii_init (enet_dev_if_t *enetIfPtr)
| Initializes the ENET MAC MII(MDC/MDIO) interface. More...
uint32_t | enet_mac_rxbd_init (enet_dev_if_t *enetIfPtr, enet_rxbd_config_t *rxbdCfg)
| Initialize the ENET receive buffer descriptors. More...
uint32_t | enet_mac_rxbd_deinit (enet_dev_if_t *enetIfPtr)
| Deinitialize the ENET receive buffer descriptors. More...
uint32_t | enet_mac_txbd_init (enet_dev_if_t *enetIfPtr, enet_txbd_config_t *txbdCfg)
| Initialize the ENET transmit buffer descriptors. More...
uint32_t | enet_mac_txbd_deinit (enet_dev_if_t *enetIfPtr)
| Deinitialize the ENET transmit buffer descriptors. More...
uint32_t | enet_mac_configure_fifo_accel (enet_dev_if_t *enetIfPtr)
| Initializes ENET MAC FIFO and accelerator with the basic configuration. More...
uint32_t | enet_mac_configure_controller (enet_dev_if_t *enetIfPtr)
| the ENET controller with the basic configuration. More...
uint32_t | enet_mac_deinit (enet_dev_if_t *enetIfPtr)
| Deinit the ENET device. More...
uint32_t | enet_mac_update_rxbd (enet_dev_if_t *enetIfPtr, bool isBufferUpdate)
| Updates the receive buffer descriptor. More...
bool | enet_mac_rx_error_stats (enet_dev_if_t *enetIfPtr, uint32_t data)
| Processes the ENET receive frame error statistics. More...
void | enet_mac_tx_error_stats (enet_dev_if_t *enetIfPtr, void *curBd)
| Processes the ENET transmit frame statistics. More...
uint32_t | enet_mac_tx_cleanup (enet_dev_if_t *enetIfPtr)
| ENET transmit buffer descriptor cleanup. More...
uint32_t | enet_mac_receive (enet_dev_if_t *enetIfPtr, enet_mac_packet_buffer_t *packBuffer)
| Receives ENET packets. More...
uint32_t | enet_mac_send (enet_dev_if_t *enetIfPtr, uint8_t *packet, uint32_t size)
| Transmits ENET packets. More...
void | enet_mac_rx_isr (void *enetIfPtr)
| The ENET receive interrupt handler. More...
void | enet_mac_tx_isr (void *enetIfPtr)
| The ENET transmit interrupt handler. More...
void | enet_mac_calculate_crc32 (enetMacAddr address, uint32_t *crcValue)
| Calculates the CRC hash value. More...
uint32_t | enet_mac_add_multicast_group (uint32_t instance, enet_multicast_group_t *multiGroupPtr, enetMacAddr address)
| Adds the ENET device to a multicast group. More...
uint32_t | enet_mac_leave_multicast_group (uint32_t instance, enet_multicast_group_t *multiGroupPtr, enetMacAddr address)
| Moves the ENET device from a multicast group. More...
uint32_t | enet_mac_init (enet_dev_if_t *enetIfPtr, enet_rxbd_config_t *rxbdCfg, enet_txbd_config_t *txbdCfg)
| Initializes the ENET with the basic configuration. More...
void | enet_mac_enqueue_buffer (void **queue, void *buffer)
| Enqueues a data buffer to the buffer queue. More...
void * | enet_mac_dequeue_buffer (void **queue)
| Dequeues a buffer from the buffer queue. More...

### ENET Driver

# Overview

The ENET driver receives data from and transmits data to the wired network. The enhanced 1588 feature supports clock synchronization.

# ENET device data structure

The ENET device data structure, enet_dev_if_t, includes configuration structure, application structure, and data context structure. This structure should be initialized before the ENET device initialization function. Then, the data structure is passed from the API layer to the device.

# Configuration structure

The ENET device data structure uses the enet_mac_config_t and the enet_phy_config_t configuration structure for MAC and PHY configurations. This allows users to configure the most common settings of the ENET peripheral. The enet_mac_config_t mac configuration structure includes the receive and transmit buffer descriptor numbers, data buffer number, buffer size, MII/RMII mode, MAC loop mode. The enet_phy_config_t PHY configuration structure includes the PHY address and PHY loop mode, which need to be configured. If the PHY address is unknown, use the isPhyAutoDiscover flag in MAC enet_mac_config_t configuration to find the PHY address. Note:

1. The recommended maximum frame length is 1518 or 1522(VLAN).
2. The receive buffer size should use the maximum frame size 1518 or 1522(VLAN). In this case, the rxLargeBuffer is not needed and the rxLargeBufferNumber should be set to 0.
3. If a small buffer size is used and the stack you choose does not support a frame with fragments, the drivers will allocate a large external buffer and do memcopy for collecting frames. In this case, the rxLargeBufferNumber value needs to be at least 4.
4. In current driver, transmit frames are with crc.

# Application structure

The ENET device data structure uses the enet_mac_api_t and the enet_phy_api_t as the driver API structure. This API structure allows higher layers to call specific device functions. This is still flexible for different stack porting. The MAC and PHY application structure are defined like this:
const enet_mac_api_t g_enetMacApi =
{
enet_mac_init,
enet_mac_close,
enet_mac_send,
#if !ENET_RECEIVE_ALL_INTERRUPT
enet_mac_receive,
#endif
enet_mii_read,
enet_mii_write,
enet_mac_add_multicast_group,
enet_mac_leave_multicast_group,
};
const enet_phy_api_t g_enetPhyApi =
{
phy_auto_discover,
phy_init,
phy_get_link_speed,
phy_get_link_status,
phy_get_link_duplex,
};

# Context data structure

The ENET device data structure uses the enet_mac_context_t to keep the user configuration and keep track of data transfer. Data receive and transmit is easily managed with this context structure.

# Initialization

To initialize the ENET module, do this:

1. First, initialize the ENET MAC and PHY configuration structures, and initialize the upper layer callback function.
2. Call the enet_mac_init() function through the enet_mac_api_t API structure in the enet_dev_if_t and pass in the enet_dev_if_t device data structure. This function enables the ENET module.
   This is an example code to initialize the ENET device data structure:
   enet_dev_if_t enetIfPtr;
   enet_rxbd_config_t rxbdCfg;
   enet_txbd_config_t txbdCfg;
   /* Set up the MAC configuration structure*/
   enet_mac_config_t g_enetMacCfg =
   {
   kEnetMaxFrameSize,
   ENET_RX_LARGE_BUFFER_NUM,
   ENET_RX_RING_LEN,
   ENET_TX_RING_LEN,
   {0},
   kEnetCfgRmii,
   kEnetCfgSpeed100M,
   kEnetCfgFullDuplex,
   kEnetRxCrcFwdEnable, /* No loop, receive Broadcast receive crc forward*/
   false,
   false,
   false,
   {true, true, false, false, false},
   {true, true, false},
   false,
   true,
   ENET_MII_CLOCK,
   #if FSL_FEATURE_ENET_SUPPORT_PTP
   ENET_PTP_RING_BUFFER_NUM,
   false,
   #endif
   };
   /* Set up the PHY configuration structure*/
   enet_phy_config_t g_enetPhyCfg =
   {{0, false }};
   /* Initialize ENET device data structure*/
   enetIfPtr->macCfgPtr = &g_enetMacCfg[device];
   enetIfPtr->phyCfgPtr = &g_enetPhyCfg[device];
   enetIfPtr->macApiPtr = &g_enetMacApi;
   enetIfPtr->phyApiPtr = (void *)&g_enetPhyApi;
   #if ENET_RECEIVE_ALL_INTERRUPT
   /* Initialize ENET callback functions if choose interrupt only approach to do mac receive*/
   enetIfPtr->enetNetifcall = enet_Callback;
   #endif
   /* Initialize ENET buffer and prepare configuration before enet mac init*/
   enet_mac_buffer_init(enetIfPtr, &rxbdCfg, &txbdCfg);
   /* Initialize ENET device*/
   ((enet_mac_api_t *)(enetIfPtr->macApiPtr))->enet_mac_init(enetIfPtr, rxbdCfg, txbdCfg);
   ((enet_phy_api_t *)(enetIfPtr->phyApiPtr))->phy_init(enetIfPtr);

# Data Receive

There are two approaches on ENET receive and the MACRO ENET_RECEIVE_ALL_INTERRUPT is used to choose the approach.

- interrupt add poll(define ENET_RECEIVE_ALL_INTERRUPT with 0)
- interrupt only (define ENET_RECEIVE_ALL_INTERRUPT with 1)

Interrupt add task poll approach: The ENET driver receives data directly from the buffer descriptor to the upper layer. To shorten the receive process time on the receive interrupt, receive data uses the interrupt and poll combination:

1. Receive interrupt: releases the receive synchronize signal(enetReceiveSync).
2. Poll: receives task and waits for the receive synchronize signal when no data is received. The receive data returns the address and data length of the received data. To receive data from the ENET device, create a receive task as follows:
   /* Create the task when do net device initialize*/
   task_create(ENET_receive, ENET_TEST_TASK_PRIO, enetIfPtr, &revHandle);
   .......................................
   ENET_receive(void *param)
   {
   uint8_t *packet;
   uint16_t length;
   enet_mac_packet_buffer_t packetBuffer[kEnetMaxFrameBdNumbers];
   enet_dev_if_t * enetIfPtr = (enet_dev_if_t *)param;
   while(1)
   {
   /* Receive frame*/
   result = enetIfPtr->macApiPtr->enet_mac_receive(enetIfPtr, &packetBuffer[0]);
   if((result == kStatus_ENET_RxbdEmpty) || (result == kStatus_ENET_InvalidInput))
   {
   /* Block when there is no data received*/
   event_wait(&enetIfPtr->enetReceiveSync, kSyncWaitForever, &flag);
   }
   ....................
   /* The packets delivery to upper layer*/
   ....................
   }
   }
   /* Receive interrupt handler to wake up blocked receive task*/
   void enet_mac_rx_isr(void *enetIfPtr)
   {
   event_group_t flag = 0x1;
   /*Check input parameter*/
   if (!enetIfPtr)
   {
   return;
   }
   /* Get interrupt status.*/
   while (enet_hal_get_interrupt_status(((enet_dev_if_t *)enetIfPtr)->deviceNumber, (kEnetRxFrameInterrupt | kEnetRxByteInterrupt)))
   {
   /* Clear interrupt*/
   enet_hal_clear_interrupt(((enet_dev_if_t *)enetIfPtr)->deviceNumber,
   (kEnetRxFrameInterrupt | kEnetRxByteInterrupt));
   /* Release sync signal and wake up ENET receive task to process received data*/
   event_set(&((enet_dev_if_t *)enetIfPtr)->enetReceiveSync, flag);
   }
   }
   Interrupt only approach for MAC receive:
   The ENET driver receives data directly from the buffer descriptor to the upper layer.
   In this case, data is received on receive interrupt handler:
   1. Receive interrupt handler calls the receive peripheral driver.
   2. Receive peripheral driver calls the initialized callback function.
   3. The callback function checks the protocol and delivers the received data to the upper layer of the TCP/IP stack.
   These are the details:
   ~~~~~{.c}
   void enet_mac_rx_isr(void *enetIfPtr)
   {
   /*Check input parameter*/
   if(!enetIfPtr)
   {
   return;
   }
   /* Get interrupt status.*/
   while(enet_hal_get_interrupt_status(((enet_dev_if_t *)enetIfPtr)->deviceNumber, (kEnetRxFrameInterrupt | kEnetRxByteInterrupt)))
   {
   /*Clear interrupt*/
   enet_hal_clear_interrupt(((enet_dev_if_t *)enetIfPtr)->deviceNumber,
   (kEnetRxFrameInterrupt | kEnetRxByteInterrupt));
   /* Receive peripheral driver*/
   enet_mac_receive((enet_dev_if_t *)enetIfPtr);
   }
   }
   .......................................
   uint32_t enet_mac_receive(enet_dev_if_t * enetIfPtr)
   {
   void *curBd;
   uint32_t length;
   uint8_t *packet;
   uint32_t controlStatus;
   /* Check input parameters*/
   if(!enetIfPtr->macContextPtr)
   {
   return kStatus_ENET_InvalidInput;
   }
   /* Check the current buffer descriptor address*/
   curBd = enetIfPtr->macContextPtr->rxBdCurPtr;
   if(!curBd)
   {
   return kStatus_ENET_RxbdInvalid;
   }
   ...........
   /* callback function to delivery to stack upper layer */
   enetIfPtr->enetNetifcall(enetIfPtr, packet, length);
   ..........
   return kStatus_ENET_Success;
   }
   uint32_t void enet_callback(void *param, uint8_t *packet, uint32_t length)
   {
   uint16_t type;
   /* Process the received frame*/
   type = NTOHS(*(uint16_t *)&((enet_etherent_header_t *)packet)->type);
   /* Collect frame to PCB structure for upper layer process*/
   QUEUEGET(packbuffer[enetIfPtr->deviceNumber].pcbHead,packbuffer[enetIfPtr->deviceNumber].pcbTail, pcbPtr);
   if(pcbPtr)
   {
   pcbPtr->FRAG[0].LENGTH = length;
   pcbPtr->FRAG[0].FRAGMENT = packet;
   pcbPtr->PRIVATE = (void *)enetIfPtr;
   switch(type)
   {
   case ENETPROT_IP:
   IPE_recv_IP((PCB *)pcbPtr,enetIfPtr->netIfPtr);
   break;
   case ENETPROT_ARP:
   IPE_recv_ARP((PCB *)pcbPtr,enetIfPtr->netIfPtr);
   break;
   case ENETPROT_IP6:
   IP6E_recv_IP((PCB *)pcbPtr,enetIfPtr->netIfPtr);
   break;
   case ENETPROT_ETHERNET:
   enet_ptp_service_l2packet(enetIfPtr, packet, length);
   break;
   default:
   PCB_free((PCB *)pcbPtr);
   break;
   }
   }
   else
   {
   enetIfPtr->stats.statsRxMissed++;
   }
   }

# Data Transmit

Data Transmit transmits data from the TCP/IP layer to the device and, then, to the network. The data transmit function should be used like this: PCB_PTR is the data buffer structure of the frame which contains many PCB_FRAGMENT(including the data buffer and length).
void ENET_send(PCB_PTR packet, void *handle)
{
uint16_t length = 0;
PCB_FRAGMENT *fragPtr;
enet_dev_if_t *enetIfPtr = (enet_dev_if_t *)handle;
/* dequeue an available transmit data buffer from txbuffer queue */
frame = enet_mac_dequeue_buffer((void * *)&enetIfPtr->macContextPtr->txBufferPtr);
if( frame == NULL)
{
return ENETERR_ALLOC;
}
/* Fill the buffer with a whole frame you want to transmit*/
for(fragPtr = packet->FRAG; fragPtr->LENGTH; fragPtr++)
{
memcpy(frame + length, fragPtr->FRAGMENT, fragPtr->LENGTH);
length += fragPtr->LENGTH;
}
/*Send the data out*/
((enet_mac_api_t *)(enetIfPtr->macApiPtr))->enet_mac_send(enetIfPtr, frame, length);
}
#Notification:

- TWR-MK70F120M board only routes the RMII interface signals from the CPU board to the primary connectors. Hence, the rmiiCfgMode in the enet_mac_config_t should be set to the kEnetCfgRmii. TWR-MK64F120M board can configure both RMII and MII modes.
- Jumper setting When ENET is uses the RMII interface signals by default, the RMII input clock must be kept in phase with the clock supplied to the external PHY. Jumpers should be set like this:
  - TWR-SER J2 shunt across 3-4 , J3 shunt across 2-3, J12 shunt across 9-10
  - TWR-MK64f120M board make sure J32 jumper is on to disable the OSC on the CPU board.
  - TWR-MK70f120M board make sure J18 jumper is on to disable the OSC on the CPU board. When ENET chooses the MII interface signals, the jumper should be set as: TWR-SER J2 shunt across 1-2, J12 no shunt across 9-10.

## Data Structure Documentation

struct enet_multicast_group_t

### Data Fields
enetMacAddr | groupAdddr
| Multicast group address.
uint32_t | hash
| Hash value of the multicast group address.
struct ENETMulticastGroup * | next
| Pointer of the next group structure.
struct ENETMulticastGroup * | prv
| Pointer of the previous structure.

struct enet_rxbd_config_t

### Data Fields
uint8_t * | rxBdPtrAlign
| Aligned receive buffer descriptor pointer.
uint8_t * | rxBufferAlign
| Aligned receive data buffer pointer.
uint8_t * | rxLargeBufferAlign
| Aligned receive large data buffer pointer.
uint8_t | rxBdNum
| Aligned receive buffer descriptor pointer.
uint8_t | rxBufferNum
| Receive buffer number.
uint8_t | rxLargeBufferNum
| Large receive buffer number.
uint32_t | rxLargeBufferSizeAlign
| Aligned large receive buffer size.

struct enet_txbd_config_t

### Data Fields
uint8_t * | txBdPtrAlign
| Aligned transmit buffer descriptor pointer.
uint8_t * | txBufferAlign
| Aligned transmit buffer descriptor pointer.
uint8_t | txBufferNum
| Transmit buffer number.
uint32_t | txBufferSizeAlign
| Aligned transmit buffer size.

struct enet_mac_config_t

### Data Fields
uint16_t | rxBufferSize
| Receive buffer size.
uint16_t | rxLargeBufferNumber
| Receive large buffer number; Needed only when the BD size is smaller than the maximum frame length. More...
uint16_t | rxBdNumber
| Receive buffer descriptor number.
uint16_t | txBdNumber
| Transmit buffer descriptor number.
enetMacAddr | macAddr
| MAC hardware address.
enet_config_rmii_t | rmiiCfgMode
| RMII configure mode.
enet_config_speed_t | speed
| Speed configuration.
enet_config_duplex_t | duplex
| Duplex configuration. More...
uint32_t | macCtlConfigure
bool | isTxAccelEnabled
| Switcher to enable transmit accelerator.
bool | isRxAccelEnabled
| Switcher to enable receive accelerator.
bool | isStoreAndFwEnabled
| Switcher to enable store and forward.
enet_config_rx_accelerator_t | rxAcceler
| Receive accelerator configure.
enet_config_tx_accelerator_t | txAcceler
| Transmit accelerator configure.
bool | isVlanEnabled
| Switcher to enable VLAN frame.
bool | isPhyAutoDiscover
| Switcher to use PHY auto discover.
uint32_t | miiClock
| MII speed.

#### Field Documentation

uint16_t enet_mac_config_t::rxLargeBufferNumber

enet_config_duplex_t enet_mac_config_t::duplex

Mac control configure, it is recommended to use enet_mac_control_flag_t it is special control set for loop mode, sleep mode, crc forward/terminate etc

struct enet_phy_config_t

### Data Fields
uint8_t | phyAddr
| PHY address.
bool | isLoopEnabled
| Switcher to enable the HY loop mode.

struct enet_ethernet_header_t

### Data Fields
enetMacAddr | destAddr
| Destination address.
enetMacAddr | sourceAddr
| Source address.
uint16_t | type
| Protocol type.

struct enet_8021vlan_header_t

### Data Fields
enetMacAddr | destAddr
| Destination address.
enetMacAddr | sourceAddr
| Source address.
uint16_t | tpidtag
| ENET 8021tag header tag region.
uint16_t | othertag
| ENET 8021tag header type region.
uint16_t | type
| Protocol type.

struct enet_mac_context_t

### Data Fields
uint8_t * | rxBufferPtr
| Receive buffer pointer.
uint8_t * | rxLargeBufferPtr
| Receive large buffer descriptor.
uint8_t * | txBufferPtr
| Transmit buffer pointer.
uint8_t * | rxBdBasePtr
| Receive buffer descriptor base address pointer.
uint8_t * | rxBdCurPtr
| Current receive buffer descriptor pointer.
uint8_t * | rxBdDirtyPtr
| Receive dirty buffer descriptor.
uint8_t * | txBdBasePtr
| Transmit buffer descriptor base address pointer.
uint8_t * | txBdCurPtr
| Current transmit buffer descriptor pointer.
uint8_t * | txBdDirtyPtr
| Last cleaned transmit buffer descriptor pointer.
bool | isTxFull
| Transmit buffer descriptor full.
bool | isRxFull
| Receive buffer descriptor full.
uint32_t | bufferdescSize
| ENET buffer descriptor size.
uint16_t | rxBufferSizeAligned
| Receive buffer alignment size.
bool | isVlanTagEnabled
| ENET VLAN-TAG frames enabled.

struct enet_stats_t

### Data Fields
uint32_t | statsRxTotal
| Total number of receive packets.
uint32_t | statsRxMissed
| Total number of receive packets.
uint32_t | statsRxDiscard
| Receive discarded with error.
uint32_t | statsRxError
| Receive discarded with error packets.
uint32_t | statsTxTotal
| Total number of transmit packets.
uint32_t | statsTxMissed
| Transmit missed.
uint32_t | statsTxDiscard
| Transmit discarded with error.
uint32_t | statsTxError
| Transmit error.
uint32_t | statsRxAlign
| Receive non-octet alignment.
uint32_t | statsRxFcs
| Receive CRC error.
uint32_t | statsRxTruncate
| Receive truncate.
uint32_t | statsRxLengthGreater
| Receive length greater than RCR[MAX_FL].
uint32_t | statsRxCollision
| Receive collision.
uint32_t | statsRxOverRun
| Receive over run.
uint32_t | statsTxOverFlow
| Transmit overflow.
uint32_t | statsTxLateCollision
| Transmit late collision.
uint32_t | statsTxExcessCollision
| Transmit excess collision.
uint32_t | statsTxUnderFlow
| Transmit under flow.
uint32_t | statsTxLarge
| Transmit large packet.
uint32_t | statsTxSmall
| Transmit small packet.

struct enet_mac_packet_buffer_t

### Data Fields
uint8_t * | data
uint16_t | length

struct enet_dev_if_t

### Data Fields
struct ENETDevIf * | next
| Next device structure address.
void * | netIfPtr
| Store the connected upper layer in the structure.
enet_multicast_group_t * | multiGroupPtr
| Multicast group chain.
uint32_t | deviceNumber
| Device number.
bool | isInitialized
| Device initialized.
uint16_t | maxFrameSize
| MAC maximum frame size.
enet_mac_config_t * | macCfgPtr
| MAC configuration structure.
enet_phy_config_t * | phyCfgPtr
| PHY configuration structure.
struct ENETMacApi * | macApiPtr
| MAC application interface structure.
void * | phyApiPtr
| PHY application interface structure.
enet_mac_context_t * | macContextPtr
| MAC context pointer.
event_object_t | enetReceiveSync
| Receive sync signal.
lock_object_t | enetContextSync
| Sync signal.

struct enet_mac_api_t

### Data Fields
uint32_t(* | enet_mac_init )(enet_dev_if_t *enetIfPtr, enet_rxbd_config_t *rxbdCfg, enet_txbd_config_t *txbdCfg)
| MAC initialize interface.
uint32_t(* | enet_mac_deinit )(enet_dev_if_t *enetIfPtr)
| MAC close interface.
uint32_t(* | enet_mac_send )(enet_dev_if_t *enetIfPtr, uint8_t *packet, uint32_t size)
| MAC send packets.
uint32_t(* | enet_mac_receive )(enet_dev_if_t *enetIfPtr, enet_mac_packet_buffer_t *packBuffer)
| MAC receive interface.
uint32_t(* | enet_mii_read )(uint32_t instance, uint32_t phyAddr, uint32_t phyReg, uint32_t *dataPtr)
| MII reads PHY.
uint32_t(* | enet_mii_write )(uint32_t instance, uint32_t phyAddr, uint32_t phyReg, uint32_t data)
| MII writes PHY.
uint32_t(* | enet_add_multicast_group )(uint32_t instance, enet_multicast_group_t *multiGroupPtr, uint8_t *groupAddr)
| Add multicast group.
uint32_t(* | enet_leave_multicast_group )(uint32_t instance, enet_multicast_group_t *multiGroupPtr, uint8_t *groupAddr)
| Leave multicast group.

## Macro Definition Documentation

#define ENET_ENABLE_DETAIL_STATS 0

#define ENET_ALIGN | ( |  | x,
|  |  | align
| ) |  | ((unsigned int)((x) + ((align)-1)) & (unsigned int)(~(unsigned int)((align)- 1)))

## Enumeration Type Documentation

enum enet_interrupt_number_t

Enumerator
kEnetTstimerInt | Timestamp interrupt.
kEnetTsAvailInt | TS-avail interrupt.
kEnetWakeUpInt | Wakeup interrupt.
kEnetPlrInt | Plr interrupt.
kEnetUnInt | Un interrupt.
kEnetRlInt | RL interrupt.
kEnetLcInt | LC interrupt.
kEnetEberrInt | Eberr interrupt.
kEnetMiiInt | MII interrupt.
kEnetRxbInt | Receive byte interrupt.
kEnetRxfInt | Receive frame interrupt.
kEnetTxbInt | Transmit byte interrupt.
kEnetTxfInt | Transmit frame interrupt.
kEnetGraInt | Gra interrupt.
kEnetBabtInt | Babt interrupt.
kEnetBabrInt | Babr interrupt.
kEnetIntNum | Interrupt number.

enum enet_frame_max_t

Enumerator
kEnetMaxTimeout | Maximum timeout.
kEnetMaxFrameSize | Maximum frame size.
kEnetMaxFrameVlanSize | Maximum VLAN frame size.
kEnetMaxFrameDateSize | Maximum frame data size.
kEnetMaxFrameBdNumbers | Maximum buffer descriptor numbers of a frame.
kEnetFrameFcsLen | FCS length.
kEnetEthernetHeadLen | Ethernet Frame header length.
kEnetEthernetVlanHeadLen | Ethernet Vlan frame header length.

enum enet_crc_parameter_t

Enumerator
kEnetCrcData | CRC-32 maximum data.
kEnetCrcOffset | CRC-32 offset2.
kEnetCrcMask1 | CRC-32 mask.

enum enet_protocol_type_t

Enumerator
kEnetProtocolIeee8023 | Packet type Ethernet ieee802.3.
kEnetProtocolIpv4 | Packet type IPv4.
kEnetProtocolIpv6 | Packet type IPv6.
kEnetProtocol8021QVlan | Packet type VLAN.
kEnetPacketUdpVersion | UDP protocol type.
kEnetPacketIpv4Version | Packet IP version IPv4.
kEnetPacketIpv6Version | Packet IP version IPv6.

enum enet_mac_control_flag_t

Enumerator
kEnetSleepModeEnable | ENET control sleep mode Enable.
kEnetPayloadlenCheckEnable | ENET receive payload length check Enable.
kEnetRxFlowControlEnable | ENET flow control, receiver detects PAUSE frames and stops transmitting data when a PAUSE frame is detected.
kEnetRxCrcFwdEnable | Received frame crc is stripped from the frame.
kEnetRxPauseFwdEnable | Pause frames are forwarded to the user application.
kEnetRxPadRemoveEnable | Padding is removed from received frames.
kEnetRxBcRejectEnable | Broadcast frame reject.
kEnetRxPromiscuousEnable | Promiscuous mode enabled.
kEnetRxMiiLoopback | MAC MII loopback mode.
kEnetRxDisRxOnTx | MAC disable receive on transmit for half-duplex.

## Function Documentation

uint32_t enet_mii_read | ( | uint32_t | instance,
|  | uint32_t | phyAddr,
|  | uint32_t | phyReg,
|  | uint32_t * | dataPtr
| ) |  |

Parameters

  instance | The ENET instance number.
  phyAddr | The PHY address.
  phyReg | The PHY register.
  dataPtr | The data read from MII.

Returns
  The execution status.

uint32_t enet_mii_write | ( | uint32_t | instance,
|  | uint32_t | phyAddr,
|  | uint32_t | phyReg,
|  | uint32_t | data
| ) |  |

Parameters

  instance | The ENET instance number.
  phyAddr | The PHY address.
  phyReg | The PHY register.
  data | The data write to MII.

Returns
  The execution status.

uint32_t enet_mac_bd_init | ( | enet_dev_if_t * | enetIfPtr | ) |

Parameters

  enetIfPtr | The ENET context structure.

Returns
  The execution status.

uint32_t enet_mac_mii_init | ( | enet_dev_if_t * | enetIfPtr | ) |

Parameters

  enetIfPtr | The ENET context structure.

Returns
  The execution status.

uint32_t enet_mac_rxbd_init | ( | enet_dev_if_t * | enetIfPtr,
|  | enet_rxbd_config_t * | rxbdCfg
| ) |  |

If you open ENET_RECEIVE_ALL_INTERRUPT to do receive data buffer numbers can be the same as the receive descriptor numbers. But if you close ENET_RECEIVE_ALL_INTERRUPT and choose polling receive frames please make sure the receive data buffers are more than buffer descriptor numbers to guarantee a good performance.

Parameters

  enetIfPtr | The ENET context structure.
  rxbdCfg | The receive buffer descriptor configuration.

Returns
  The execution status.

uint32_t enet_mac_rxbd_deinit | ( | enet_dev_if_t * | enetIfPtr | ) |

Deinitialize the ENET receive buffer descriptors.

Parameters

  enetIfPtr | The ENET context structure.

Returns
  The execution status.

uint32_t enet_mac_txbd_init | ( | enet_dev_if_t * | enetIfPtr,
|  | enet_txbd_config_t * | txbdCfg
| ) |  |

Parameters

  enetIfPtr | The ENET context structure.
  txbdCfg | The transmit buffer descriptor configuration.

Returns
  The execution status.

uint32_t enet_mac_txbd_deinit | ( | enet_dev_if_t * | enetIfPtr | ) |

Deinitialize the ENET transmit buffer descriptors.

Parameters

  enetIfPtr | The ENET context structure.

Returns
  The execution status.

uint32_t enet_mac_configure_fifo_accel | ( | enet_dev_if_t * | enetIfPtr | ) |

Parameters

  enetIfPtr | The ENET context structure.

Returns
  The execution status.

uint32_t enet_mac_configure_controller | ( | enet_dev_if_t * | enetIfPtr | ) |

Parameters

  enetIfPtr | The ENET context structure.

Returns
  The execution status.

uint32_t enet_mac_deinit | ( | enet_dev_if_t * | enetIfPtr | ) |

Parameters

  enetIfPtr | The ENET context structure.

Returns
  The execution status.

uint32_t enet_mac_update_rxbd | ( | enet_dev_if_t * | enetIfPtr,
|  | bool | isBufferUpdate
| ) |  |

This updates the used receive buffer descriptor ring to ensure that the used BDS is correctly used again. It cleans the status region and sets the control region of the used receive buffer descriptor. If the isBufferUpdate flag is set, the data buffer in the buffer descriptor is updated.

Parameters

  enetIfPtr | The ENET context structure.
  isBufferUpdate | The data buffer update flag.

Returns
  The execution status.

bool enet_mac_rx_error_stats | ( | enet_dev_if_t * | enetIfPtr,
|  | uint32_t | data
| ) |  |

This interface gets the error statistics of the received frame. Because the error information is in the last BD of a frame, this interface should be called when processing the last BD of a frame.

Parameters

  enetIfPtr | The ENET context structure.
  data | The current control and status data of the buffer descriptor.

Returns
  The frame error status.
  - True if the frame has an error.
  - False if the frame does not have an error.

void enet_mac_tx_error_stats | ( | enet_dev_if_t * | enetIfPtr,
|  | void * | curBd
| ) |  |

This interface gets the error statistics of the transmit frame. Because the error information is in the last BD of a frame, this interface should be called when processing the last BD of a frame.

Parameters

  enetIfPtr | The ENET context structure.
  curBd | The current buffer descriptor.

uint32_t enet_mac_tx_cleanup | ( | enet_dev_if_t * | enetIfPtr | ) |

First, store the transmit frame error statistic and PTP timestamp of the transmitted packets. Second, clean up the used transmit buffer descriptors. If the PTP 1588 feature is open, this interface captures the 1588 timestamp. It is called by the transmit interrupt handler.

Parameters

  enetIfPtr | The ENET context structure.

Returns
  The execution status.

uint32_t enet_mac_receive | ( | enet_dev_if_t * | enetIfPtr,
|  | enet_mac_packet_buffer_t * | packBuffer
| ) |  |

Parameters

  enetIfPtr | The ENET context structure.
  packBuffer | The received data buffer.

Returns
  The execution status.

uint32_t enet_mac_send | ( | enet_dev_if_t * | enetIfPtr,
|  | uint8_t * | packet,
|  | uint32_t | size
| ) |  |

Parameters

  enetIfPtr | The ENET context structure.
  packet | The frame to be transmitted.
  size | The frame size.

Returns
  The execution status.

void enet_mac_rx_isr | ( | void * | enetIfPtr | ) |

Parameters

  enetIfPtr | The ENET context structure pointer.

void enet_mac_tx_isr | ( | void * | enetIfPtr | ) |

Parameters

  enetIfPtr | The ENET context structure pointer.

void enet_mac_calculate_crc32 | ( | enetMacAddr | address,
|  | uint32_t * | crcValue
| ) |  |

Parameters

  address | The ENET MAC hardware address.
  crcVlaue | The calculated CRC value of the Mac address.

uint32_t enet_mac_add_multicast_group | ( | uint32_t | instance,
|  | enet_multicast_group_t * | multiGroupPtr,
|  | enetMacAddr | address
| ) |  |

Parameters

  instance | The ENET instance number.
  multiGroupPtr | The ENET multicast group structure.
  address | The ENET MAC hardware address.

Returns
  The execution status.

uint32_t enet_mac_leave_multicast_group | ( | uint32_t | instance,
|  | enet_multicast_group_t * | multiGroupPtr,
|  | enetMacAddr | address
| ) |  |

Parameters

  instance | The ENET instance number.
  multiGroupPtr | The ENET multicast group structure.
  address | The ENET MAC hardware address.

Returns
  The execution status.

uint32_t enet_mac_init | ( | enet_dev_if_t * | enetIfPtr,
|  | enet_rxbd_config_t * | rxbdCfg,
|  | enet_txbd_config_t * | txbdCfg
| ) |  |

Parameters

  enetIfPtr | The pointer to the basic configuration structure.

Returns
  The execution status.

void enet_mac_enqueue_buffer | ( | void ** | queue,
|  | void * | buffer
| ) |  |

Parameters

  queue | The buffer queue.
  buffer | The buffer to add to the buffer queue.

void* enet_mac_dequeue_buffer | ( | void ** | queue | ) |

Parameters

  queue | The buffer queue.

Returns
  The dequeued data buffer.