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

Overview

This section describes the programming interface of the ENET Peripheral Driver. 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.

ENET 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 Mac mode, MII/RMII mode configuration, MAC controller configuration, receive and transmit accelerator, receive and transmit FIFO, special Mac configuration to receive maximum frame length, receive truncate length, pause duration for pause frame and the PTP slave mode. The enet_phy_config_t PHY configuration structure includes the PHY address and PHY loop mode, which needs to be configured. If the PHY address is unknown, use the isAutodiscoverEnabled flag to find the PHY address. Note:

  1. The default maximum frame length is 1518 or 1522(VLAN). The default IPG (inter-packet-gap) is 12 bytes, a sufficient amount for normal Ethernet use. If no special requirements are present, let the macSpecialCfg be NULL.
  2. The recommended receive and transmit buffer size is the maximum frame size: either 1518 or 1522(VLAN).
  3. If the kEnetTxAccelEnable and kEnetRxAccelEnable are set, ensure that the txAccelerCfg and rxAccelerCfg are configured.

ENET Buffer data structure

The ENET device data structure uses the enet_buff_config_t to configure the receive/transmit buffer descriptor numbers and address, the receive/transmit data buffer, the aligned receive/transmit buffer size, the extended receive data buffer queue address and 1588 PTP timestamp data buffer address, etc. Data receive and transmit is easily managed with this context structure.

ENET Initialization

To initialize the ENET module, follow these steps:

  1. First, initialize the ENET MAC and PHY configuration structures, and initialize the upper layer callback function for interrupt mode or initialize semaphore enetIfPtr->enetReceiveSync, create receive task for poll mode.
  2. Call the enet_mac_init() function with 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:

uint32_t phyAddr;
enet_mac_config_t configMac;
enet_buff_config_t bufferCfg;
rmiiCfg.mode = kEnetCfgRmii;
rmiiCfg.isLoopEnabled = false;
rmiiCfg.isRxOnTxDisabled = false;
memset(&configMac, 0,sizeof(enet_mac_config_t));
configMac.macAddr = source;
configMac.rmiiCfgPtr = &rmiiCfg;
// Buffer configure structure//
memset(&bufferCfg, 0,sizeof(enet_buff_config_t));
bufferCfg.rxBdNumber = ENET_RXBD_NUM;
bufferCfg.rxBdPtrAlign = RxBuffDescrip;
bufferCfg.rxBufferAlign = &RxDataBuff[0][0];
bufferCfg.rxBuffSizeAlign = ENET_RXBuffSizeAlign(ENET_RXBUFF_SIZE);
bufferCfg.txBdNumber = ENET_TXBD_NUM;
bufferCfg.txBdPtrAlign = TxBuffDescrip;
bufferCfg.txBufferAlign = &TxDataBuff[0][0];
bufferCfg.txBuffSizeAlign = ENET_TXBuffSizeAlign(ENET_TXBUFF_SIZE);
#if !ENET_RECEIVE_ALL_INTERRUPT
bufferCfg.extRxBuffQue = &ExtRxDataBuff[0][0];
bufferCfg.extRxBuffNum = ENET_EXTRXBD_NUM;
#endif
#if FSL_FEATURE_ENET_SUPPORT_PTP
configMac.isSlaveMode = false;
bufferCfg.ptpTsRxDataPtr = &ptpTsRxData[0];
bufferCfg.ptpTsRxBuffNum = ENET_PTP_RXTS_RING_LEN;
bufferCfg.ptpTsTxDataPtr = &ptpTsTxData[0];
bufferCfg.ptpTsTxBuffNum = ENET_PTP_TXTS_RING_LEN;
#endif
// Set up the PHY configuration structure//
enet_phy_config_t g_enetPhyCfg =
{{0, false }};
// Initialize ENET device//
result = ENET_DRV_Init(enetIfPtr, &configMac, &bufferCfg);
// Initialize PHY//
if(g_enetPhyCfg[device].isAutodiscoverEnabled)
{
uint32_t phyAddr;
result = PHY_DRV_Autodiscover(device, &phyAddr);
if(result != kStatus_ENET_Success)
return result;
enetIfPtr->phyAddr = phyAddr;
}
else
{
enetIfPtr->phyAddr = g_enetPhyCfg[device].phyAddr;
}
PHY_DRV_Init(device, enetIfPtr->phyAddr, g_enetPhyCfg[device].isLoopEnabled);
// Install ENET stack net interface callback function for receive interrupt mode//
#if ENET_RECEIVE_ALL_INTERRUPT
ENET_DRV_InstallNetIfCall(enetIfPtr, enet_receive_test);
#else
// Initialize semaphore enetIfPtr->enetReceiveSync and create receive task for poll mode //
osa_status_t osaFlag;
osaFlag = OSA_EventCreate(&enetIfPtr->enetReceiveSync, kEventAutoClear);
if(osaFlag != kStatus_OSA_Success)
{
return osaFlag;
}
/* Create receive task
osaFlag = OSA_TaskCreate(ENET_receive, "receive", ENET_TASK_STACK_SIZE, ENET_receive_stack, ENET_RECEIVE_TASK_PRIO, (task_param_t)enetIfPtr, false, &ENET_receive_task_handler);
if(osaFlag != kStatus_OSA_Success)
{
return osaFlag;
}
#endif

ENET Data Receive

ENET can receive data in two different ways. The MACRO ENET_RECEIVE_ALL_INTERRUPT selects the way in which data is received.

Poll approach (Interrupt add task poll) for Mac receive: The ENET driver receives data directly from the buffer descriptor to the upper layer. To shorten the receiving process time on the receive interrupt, the 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;
    uint16_t counter;
    enet_dev_if_t * enetIfPtr = (enet_dev_if_t *)param;
    while(1)
    {
    // Receive frame//
    result = ENET_DRV_ReceiveData(enetIfPtr, packetBuffer);
    if ((result == kStatus_ENET_RxbdEmpty) || (result == kStatus_ENET_InvalidInput))
    #if !USE_RTOS
    {
    status = OSA_EventWait(&enetIfPtr->enetReceiveSync, flag, false, 0, &flagCheck);
    }
    else if(result == kStatus_ENET_Success)
    {
    #else
    {
    OSA_EventWait(&enetIfPtr->enetReceiveSync, flag, false, OSA_WAIT_FOREVER, &flagCheck);
    }
    #endif
    ....................
    // The packets delivery to upper layer and do data buffer enqueue after the data copied to the upper layer buffer//
    if (packetBuffer[0].data != NULL)
    {
    // Collect the frame first to the packet which is the data buffer for upper layer//
    length = 0;
    for(counter = 0; packetBuffer[counter].length != 0 ; counter ++)
    {
    memcpy(packet + length, packetBuffer[counter].data, packetBuffer[counter].length);
    length += packetBuffer[counter].length;
    (uint32_t *)(packetBuffer[counter].data) = 0;
    // data buffers are required to enqueued to the extended receive buffer queue//
    enet_mac_enqueue_buffer((void **)&enetIfPtr->bdContext.extRxBuffQue, packetBuffer[counter].data);
    packetBuffer[counter].length = 0;
    }
    // call upper layer receive function//
    ....................................
    }
    }
    </code>
    // Receive interrupt handler to wake up blocked receive task//
    <code>
    void ENET_DRV_RxIRQHandler(uint32_t instance)
    {
    enet_dev_if_t *enetIfPtr;
    uint32_t baseAddr;
    enetIfPtr = enetIfHandle[instance];
    event_flags_t flag = 0x1;
    //Check input parameter//
    if (!enetIfPtr)
    {
    return;
    }
    baseAddr = g_enetBaseAddr[enetIfPtr->deviceNumber];
    // Get interrupt status.//
    {
    //Clear interrupt//
    // Release sync signal-----------------//
    OSA_EventSet(&enetIfPtr->enetReceiveSync, flag);
    }
    }

Note: The extended receive buffer queue is required in the structure when using the receive polling mode. The data buffer in receive polling mode has to be enqueued by the end of each receive time.

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 the 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:

void ENET_DRV_RxIRQHandler(uint32_t instance)
{
enet_dev_if_t *enetIfPtr;
uint32_t baseAddr;
enetIfPtr = enetIfHandle[instance];
//Check input parameter//
if (!enetIfPtr)
{
return;
}
baseAddr = g_enetBaseAddr[enetIfPtr->deviceNumber];
// Get interrupt status.//
{
//Clear interrupt//
// Receive peripheral driver//
ENET_DRV_ReceiveData(enetIfPtr);
}
}
</code>
.......................................
<code>
uint32_t ENET_DRV_ReceiveData(enet_dev_if_t * enetIfPtr)
{
void *curBd;
uint32_t length;
uint8_t *packet;
uint32_t controlStatus;
// Check input parameters//
if(!enetIfPtr)
{
}
...........
// callback function to delivery to stack upper layer //
enetIfPtr->enetNetifcall(enetIfPtr, packet, length);
..........
return kStatus_ENET_Success;
}
</code>
<code>
uint32_t void enet_callback(void *param, enet_mac_packet_buffer_t *packetBuffer)
{
uint32_t length = 0;
uint16_t type, counter = 0;
uint8_t *packet;
// Collect the frame first//
if(!packetBuffer[1].length)
{
packet = packetBuffer[0].data;
length = packetBuffer[0].length;
}
else
{
// Dequeue a large buffer //
packet = enet_mac_dequeue_buffer((void **)&dataBuffQue);
if(packet!=NULL)
{
for(counter = 0; packetBuffer[counter].next != NULL ; counter ++)
{
memcpy(packet + length, packetBuffer[counter].data, packetBuffer[counter].length);
length += packetBuffer[counter].length;
}
}
else
{
}
}
// 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++;
}
}

Remember to enqueue the packet to the dataBuffQue and enqueue the pcbPtr to the packbuffer after the data is processed by the upper layer. This process is done in the ENET_free API and called by the RTCS. //

ENET 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 as follows: PCB_PTR is the data buffer structure of the frame which contains many PCB_FRAGMENT(including the data buffer and length).

uint32_t ENET_send(_enet_handle handle, PCB_PTR packet, uint32_t type, _enet_address dest, uint32_t flags)
{
uint8_t headerLen, *frame;
PCB_FRAGMENT *fragPtr;
uint16_t size = 0, lenTemp = 0, bdNumUsed = 0;
enet_dev_if_t *enetIfPtr;
volatile enet_bd_struct_t * curBd;
uint32_t result, lenoffset = 0;
//Check out//
if ((!handle) || (!packet))
{
}
enetIfPtr = (enet_dev_if_t *)handle;
// Default frame header size//
headerLen = kEnetEthernetHeadLen;
// Check the frame length//
for (fragPtr = packet->FRAG; fragPtr->LENGTH; fragPtr++)
{
size += fragPtr->LENGTH;
}
if (size > enetIfPtr->maxFrameSize)
{
}
//Add MAC hardware address//
packetPtr = (enet_ethernet_header_t *)packet->FRAG[0].FRAGMENT;
htone(packetPtr->destAddr, dest);
htone(packetPtr->sourceAddr, enetIfPtr->macAddr);
packetPtr->type = HTONS(type);
if (flags & ENET_OPT_8021QTAG)
{
enet_8021vlan_header_t *vlanHeadPtr = (enet_8021vlan_header_t *)packetPtr;
vlanHeadPtr->tpidtag = HTONS(ENETPROT_8021Q);
vlanHeadPtr->othertag = HTONS((ENET_GETOPT_8021QPRIO(flags) << 13));
vlanHeadPtr->type = HTONS(type);
headerLen = sizeof(enet_8021vlan_header_t);
packet->FRAG[0].LENGTH = headerLen;
}
if (flags & ENET_OPT_8023)
{
enet_8022_header_ptr lcPtr = (enet_8022_header_ptr)(packetPtr->type + 2);
packetPtr->type = HTONS(size - headerLen);
lcPtr->dsap[0] = 0xAA;
lcPtr->ssap[0] = 0xAA;
lcPtr->command[0] = 0x03;
lcPtr->oui[0] = 0x00;
lcPtr->oui[1] = 0x00;
lcPtr->oui[2] = 0x00;
lcPtr->type = HTONS(type);
packet->FRAG[0].LENGTH = packet->FRAG[0].LENGTH+ sizeof(enet_8022_header_t);
}
// Get the current transmit data buffer in buffer descriptor //
curBd = enetIfPtr->bdContext.txBdCurPtr;
// Send a whole frame with a signal buffer//
if(size <= enetIfPtr->bdContext.txBuffSizeAlign)
{
bdNumUsed = 1;
for (fragPtr = packet->FRAG; fragPtr->LENGTH; fragPtr++)
{
memcpy(frame + lenTemp, fragPtr->FRAGMENT, fragPtr->LENGTH);
lenTemp += fragPtr->LENGTH;
}
// Send packet to the device//
return ENET_DRV_SendData(enetIfPtr, size, bdNumUsed);
}
// Copy the Ethernet header first//
memcpy(frame, packet->FRAG[0].FRAGMENT, packet->FRAG[0].LENGTH);
// Send a whole frame with multiple buffer descriptors//
while((size - bdNumUsed* enetIfPtr->bdContext.txBuffSizeAlign) > enetIfPtr->bdContext.txBuffSizeAlign)
{
if(bdNumUsed == 0)
{
memcpy((void *)(frame + packet->FRAG[0].LENGTH), (void *)(packet->FRAG[1].FRAGMENT), enetIfPtr->bdContext.txBuffSizeAlign - packet->FRAG[0].LENGTH);
lenoffset += (enetIfPtr->bdContext.txBuffSizeAlign - packet->FRAG[0].LENGTH);
}
else
{
memcpy((void *)frame, (void *)(packet->FRAG[1].FRAGMENT + lenoffset), enetIfPtr->bdContext.txBuffSizeAlign);
lenoffset += enetIfPtr->bdContext.txBuffSizeAlign;
}
// Incremenet the buffer descriptor//
curBd = ENET_DRV_IncrTxBuffDescripIndex(enetIfPtr, curBd);
frame = ENET_HAL_GetBuffDescripData(curBd);
// Increment the index and parameters//
bdNumUsed ++;
}
memcpy((void *)frame, (void *)(packet->FRAG[1].FRAGMENT + lenoffset), size - bdNumUsed * enetIfPtr->bdContext.txBuffSizeAlign);
bdNumUsed ++;
// Send packet to the device//
result = ENET_DRV_SendData(enetIfPtr, size, bdNumUsed);
// Free the PCB buffer if necessary//
PCB_free(packet);
return result;
}

ENET Note:

Data Structures

struct  enet_multicast_group_t
 Defines the multicast group structure for the ENET device. 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_buff_descrip_context_t
 Defines the structure for ENET buffer descriptors status. 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_buff_config_t
 Defines the receive buffer descriptor configure structure. More...
 
struct  enet_dev_if_t
 Defines the ENET device data structure for the ENET. More...
 
struct  enet_user_config_t
 Defines the ENET user configuration structure. More...
 

Macros

#define ENET_RECEIVE_ALL_INTERRUPT   1
 Defines the approach: ENET interrupt handler receive.
 
#define ENET_ENABLE_DETAIL_STATS   0
 Defines the statistic enable macro. More...
 
#define ENET_HTONS(n)   __REV16(n)
 brief Defines the macro for converting constants from host byte order to network byte order
 
#define ENET_ORIGINAL_CRC32   0xFFFFFFFFU
 Defines the CRC-32 calculation constant. More...
 
#define ENET_CRC32_POLYNOMIC   0xEDB88320U
 CRC-32 Polynomic.
 

Enumerations

enum  enet_crc_parameter_t {
  kEnetCrcOffset = 8,
  kEnetCrcMask1 = 0x3F
}
 Defines the CRC data for a hash value calculation. More...
 
enum  enet_protocol_type_t {
  kEnetProtocoll2ptpv2 = 0x88F7,
  kEnetProtocolIpv4 = 0x0800,
  kEnetProtocolIpv6 = 0x86dd,
  kEnetProtocol8021QVlan = 0x8100,
  kEnetPacketUdpVersion = 0x11,
  kEnetPacketIpv4Version = 0x4,
  kEnetPacketIpv6Version = 0x6
}
 Defines the ENET protocol type and main parameters. More...
 

Variables

ENET_Type *const g_enetBase []
 Array for ENET module register base address. More...
 
const IRQn_Type g_enetTxIrqId []
 Two-dimensional array for the ENET interrupt vector number. More...
 

ENET Driver

enet_status_t ENET_DRV_Init (enet_dev_if_t *enetIfPtr, const enet_user_config_t *userConfig)
 Initializes the ENET with the basic configuration. More...
 
enet_status_t ENET_DRV_Deinit (enet_dev_if_t *enetIfPtr)
 De-initializes the ENET device. More...
 
enet_status_t ENET_DRV_UpdateRxBuffDescrip (enet_dev_if_t *enetIfPtr, bool isBuffUpdate)
 Updates the receive buffer descriptor. More...
 
enet_status_t ENET_DRV_CleanupTxBuffDescrip (enet_dev_if_t *enetIfPtr)
 ENET transmit buffer descriptor cleanup. More...
 
volatile enet_bd_struct_tENET_DRV_IncrRxBuffDescripIndex (enet_dev_if_t *enetIfPtr, volatile enet_bd_struct_t *curBd)
 Increases the receive buffer descriptor to the next one. More...
 
volatile enet_bd_struct_tENET_DRV_IncrTxBuffDescripIndex (enet_dev_if_t *enetIfPtr, volatile enet_bd_struct_t *curBd)
 Increases the transmit buffer descriptor to the next one. More...
 
bool ENET_DRV_RxErrorStats (enet_dev_if_t *enetIfPtr, volatile enet_bd_struct_t *curBd)
 Processes the ENET receive frame error statistics. More...
 
void ENET_DRV_TxErrorStats (enet_dev_if_t *enetIfPtr, volatile enet_bd_struct_t *curBd)
 Processes the ENET transmit frame statistics. More...
 
enet_status_t ENET_DRV_ReceiveData (enet_dev_if_t *enetIfPtr)
 Receives ENET packets. More...
 
enet_status_t ENET_DRV_InstallNetIfCall (enet_dev_if_t *enetIfPtr, enet_netif_callback_t function)
 Installs ENET TCP/IP stack net interface callback function. More...
 
enet_status_t ENET_DRV_SendData (enet_dev_if_t *enetIfPtr, uint32_t dataLen, uint32_t bdNumUsed)
 Transmits ENET packets. More...
 
void ENET_DRV_RxIRQHandler (uint32_t instance)
 The ENET receive interrupt handler. More...
 
void ENET_DRV_TxIRQHandler (uint32_t instance)
 The ENET transmit interrupt handler. More...
 
void ENET_DRV_CalculateCrc32 (uint8_t *address, uint32_t *crcValue)
 Calculates the CRC hash value. More...
 
enet_status_t ENET_DRV_AddMulticastGroup (uint32_t instance, uint8_t *address, uint32_t *hash)
 Adds the ENET device to a multicast group. More...
 
enet_status_t ENET_DRV_LeaveMulticastGroup (uint32_t instance, uint8_t *address)
 Moves the ENET device from a multicast group. More...
 
void enet_mac_enqueue_buffer (void **queue, void *buffer)
 ENET buffer enqueue. More...
 
void * enet_mac_dequeue_buffer (void **queue)
 ENET buffer dequeue. More...
 

Data Structure Documentation

struct enet_multicast_group_t

Data Fields

uint8_t groupAdddr [kEnetMacAddrLen]
 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_ethernet_header_t

Data Fields

uint8_t destAddr [kEnetMacAddrLen]
 Destination address.
 
uint8_t sourceAddr [kEnetMacAddrLen]
 Source address.
 
uint16_t type
 Protocol type.
 
struct enet_8021vlan_header_t

Data Fields

uint8_t destAddr [kEnetMacAddrLen]
 Destination address.
 
uint8_t sourceAddr [kEnetMacAddrLen]
 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_buff_descrip_context_t

Data Fields

volatile enet_bd_struct_trxBdBasePtr
 Receive buffer descriptor base address pointer.
 
volatile enet_bd_struct_trxBdCurPtr
 Current receive buffer descriptor pointer.
 
volatile enet_bd_struct_trxBdDirtyPtr
 Receive dirty buffer descriptor.
 
volatile enet_bd_struct_ttxBdBasePtr
 Transmit buffer descriptor base address pointer.
 
volatile enet_bd_struct_ttxBdCurPtr
 Current transmit buffer descriptor pointer.
 
volatile enet_bd_struct_ttxBdDirtyPtr
 Last cleaned transmit buffer descriptor pointer.
 
bool isTxBdFull
 Transmit buffer descriptor full.
 
bool isRxBdFull
 Receive buffer descriptor full.
 
uint32_t rxBuffSizeAlign
 Receive buffer size alignment.
 
uint32_t txBuffSizeAlign
 Transmit buffer size alignment.
 
uint8_t * extRxBuffQue
 Extended Rx data buffer queue to update the data buff in the receive buffer descriptor.
 
uint8_t extRxBuffNum
 extended data buffer number
 
struct enet_stats_t

Data Fields

uint32_t statsRxTotal
 Total number of receive packets.
 
uint32_t statsTxTotal
 Total number of transmit packets.
 
struct enet_mac_packet_buffer_t

Data Fields

uint8_t * data
 Data buffer pointer.
 
uint16_t length
 Data length.
 
struct ENETMacPacketBuffer * next
 Next pointer.
 
struct enet_buff_config_t

Data Fields

uint16_t rxBdNumber
 Receive buffer descriptor number.
 
uint16_t txBdNumber
 Transmit buffer descriptor number.
 
uint32_t rxBuffSizeAlign
 Aligned receive buffer size and must be larger than 256.
 
uint32_t txBuffSizeAlign
 Aligned transmit buffer size and must be larger than 256.
 
volatile enet_bd_struct_trxBdPtrAlign
 Aligned receive buffer descriptor pointer.
 
uint8_t * rxBufferAlign
 Aligned receive data buffer pointer.
 
volatile enet_bd_struct_ttxBdPtrAlign
 Aligned transmit buffer descriptor pointer.
 
uint8_t * txBufferAlign
 Aligned transmit buffer descriptor pointer.
 
uint8_t * extRxBuffQue
 Extended Rx data buffer queue to update the data buff in the receive buffer descriptor.
 
uint8_t extRxBuffNum
 extended data buffer number
 
struct enet_dev_if_t

Data Fields

struct ENETDevIf * next
 Next device structure address.
 
void * netIfPrivate
 For upper layer private structure.
 
enet_multicast_group_tmultiGroupPtr
 Multicast group chain.
 
uint32_t deviceNumber
 Device number.
 
uint8_t macAddr [kEnetMacAddrLen]
 Mac address.
 
uint8_t phyAddr
 PHY address connected to this device.
 
bool isInitialized
 Device initialized.
 
uint16_t maxFrameSize
 Mac maximum frame size.
 
bool isVlanTagEnabled
 ENET VLAN-TAG frames enabled.
 
bool isTxCrcEnable
 Transmit CRC enable in buffer descriptor.
 
bool isRxCrcFwdEnable
 Receive CRC forward.
 
enet_buff_descrip_context_t bdContext
 Mac buffer descriptors context pointer.
 
enet_stats_t stats
 Packets statistic.
 
enet_netif_callback_t enetNetifcall
 Receive callback function to the upper layer.
 
mutex_t enetContextSync
 Sync signal.
 
struct enet_user_config_t

Data Fields

const enet_mac_config_tmacCfgPtr
 MAC configuration structure.
 
const enet_buff_config_tbuffCfgPtr
 ENET buffer configuration structure.
 

Macro Definition Documentation

#define ENET_ENABLE_DETAIL_STATS   0
#define ENET_ORIGINAL_CRC32   0xFFFFFFFFU

CRC-32 Original data

Enumeration Type Documentation

Enumerator
kEnetCrcOffset 

CRC-32 offset2.

kEnetCrcMask1 

CRC-32 mask.

Enumerator
kEnetProtocoll2ptpv2 

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.

Function Documentation

enet_status_t ENET_DRV_Init ( enet_dev_if_t enetIfPtr,
const enet_user_config_t userConfig 
)
Parameters
enetIfPtrThe pointer to the basic Ethernet structure.
userConfigThe ENET user configuration structure pointer.
Returns
The execution status.
enet_status_t ENET_DRV_Deinit ( enet_dev_if_t enetIfPtr)
Parameters
enetIfPtrThe ENET context structure.
Returns
The execution status.
enet_status_t ENET_DRV_UpdateRxBuffDescrip ( enet_dev_if_t enetIfPtr,
bool  isBuffUpdate 
)

This function updates the used receive buffer descriptor ring to ensure that the used BDS is correctly used. 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
enetIfPtrThe ENET context structure.
isBuffUpdateThe data buffer update flag.
Returns
The execution status.
enet_status_t ENET_DRV_CleanupTxBuffDescrip ( 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
enetIfPtrThe ENET context structure.
Returns
The execution status.
volatile enet_bd_struct_t* ENET_DRV_IncrRxBuffDescripIndex ( enet_dev_if_t enetIfPtr,
volatile enet_bd_struct_t curBd 
)
Parameters
enetIfPtrThe ENET context structure.
curBdThe current buffer descriptor pointer.
Returns
the increased received buffer descriptor.
volatile enet_bd_struct_t* ENET_DRV_IncrTxBuffDescripIndex ( enet_dev_if_t enetIfPtr,
volatile enet_bd_struct_t curBd 
)
Parameters
enetIfPtrThe ENET context structure.
curBdThe current buffer descriptor pointer.
Returns
the increased transmit buffer descriptor.
bool ENET_DRV_RxErrorStats ( enet_dev_if_t enetIfPtr,
volatile enet_bd_struct_t curBd 
)

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
enetIfPtrThe ENET context structure.
curBdThe current 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_DRV_TxErrorStats ( enet_dev_if_t enetIfPtr,
volatile enet_bd_struct_t 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
enetIfPtrThe ENET context structure.
curBdThe current buffer descriptor.
enet_status_t ENET_DRV_ReceiveData ( enet_dev_if_t enetIfPtr)
Parameters
enetIfPtrThe ENET context structure.
Returns
The execution status.
enet_status_t ENET_DRV_InstallNetIfCall ( enet_dev_if_t enetIfPtr,
enet_netif_callback_t  function 
)
Parameters
enetIfPtrThe ENET context structure.
functionThe ENET TCP/IP stack net interface callback function.
Returns
The execution status.
enet_status_t ENET_DRV_SendData ( enet_dev_if_t enetIfPtr,
uint32_t  dataLen,
uint32_t  bdNumUsed 
)
Parameters
enetIfPtrThe ENET context structure.
dataLenThe frame data length to be transmitted.
bdNumUsedThe buffer descriptor need to be used.
Returns
The execution status.
void ENET_DRV_RxIRQHandler ( uint32_t  instance)
Parameters
instanceThe ENET instance number.
void ENET_DRV_TxIRQHandler ( uint32_t  instance)
Parameters
instanceThe ENET instance number.
void ENET_DRV_CalculateCrc32 ( uint8_t *  address,
uint32_t *  crcValue 
)
Parameters
addressThe ENET Mac hardware address.
crcValueThe calculated CRC value of the Mac address.
enet_status_t ENET_DRV_AddMulticastGroup ( uint32_t  instance,
uint8_t *  address,
uint32_t *  hash 
)
Parameters
instanceThe ENET instance number.
addressThe multicast group address.
hashThe hash value of the multicast group address.
Returns
The execution status.
enet_status_t ENET_DRV_LeaveMulticastGroup ( uint32_t  instance,
uint8_t *  address 
)
Parameters
instanceThe ENET instance number.
addressThe multicast group address.
Returns
The execution status.
void enet_mac_enqueue_buffer ( void **  queue,
void *  buffer 
)
Parameters
queueThe buffer queue address.
bufferThe buffer will add to the buffer queue.
void* enet_mac_dequeue_buffer ( void **  queue)
Parameters
queueThe buffer queue address.
Returns
The buffer will be dequeued from the buffer queue.

Variable Documentation

ENET_Type* const g_enetBase[]
const IRQn_Type g_enetTxIrqId[]