EtherCAT Slave
 
Loading...
Searching...
No Matches
Ethernet over EtherCAT

Description

Ethernet over EtherCAT (EoE) transparently tunnels standard Ethernet communication via EtherCAT. Tunneling allows the master device to optimize Ethernet communication without affecting the process data communication. EoE enables communication with network devices. EoE is typically used for devices with TCP/IP stack, such as a web server, or for infrastructure devices such as switch ports, to which peripheral devices can be connected.

EoE API

The motivation of the code snippets is to provide a better understanding of how to configure and transport the Ethernet frames. For a detailed overview please refer to the example code.

Network settings

Register a function for network settings. The function is called when the EtherCAT master sends an EoE frame with the network device settings (IP address, Gateway, MAC address and DNS server). These parameters must be given then to the users virtual network interface.

static bool EC_SLV_APP_EoE_SS_settingIndHandler(
void *pContext,
uint16_t *pMac,
uint16_t *pIp,
uint16_t *pSubNet,
uint16_t *pDefaultGateway,
uint16_t *pDnsIp)
{
uint32_t retVal = 0;
uint32_t ipAddr = OSAL_VNET_ntohl(((uint32_t*)pIp)[0]);
uint32_t subNet = OSAL_VNET_ntohl(((uint32_t*)pSubNet)[0]);
uint32_t defGW = OSAL_VNET_ntohl(((uint32_t*)pDefaultGateway)[0]);
OSAL_VNET_configureMAC(vnetInterface, (uint8_t*)pMac);
OSAL_VNET_configureIPv4(vnetInterface, ipAddr, subNet);
OSAL_VNET_setLinkState(vnetInterface, OSAL_LINK_Up);
OSAL_VNET_configureIPv4Route(vnetInterface, defGW);
return true;
}
EC_API_SLV_EoE_cbRegisterSettingIndHandler(handle, EC_SLV_APP_EoE_SS_settingIndHandler, pAppInstance);

Receiving a frame

This function registers a function which must be implemented by the user. The user defined function is called any time an EoE frame is received.

static bool EC_SLV_APP_EoE_SS_receiveHandler(void *pContext, uint16_t *pData, uint16_t size)
{
bool frameHandled = false;
uint32_t ret = 0;
ret = OSAL_VNET_writeFrame(vnetInterface, size, pData);
if(ret == OSAL_ERR_NoError)
{
frameHandled = true;
}
return frameHandled;
}
EC_API_SLV_EoE_cbRegisterReceiveHandler(handle, EC_SLV_APP_EoE_SS_receiveHandler, pAppInstance);

Sending a frame

Use this function to send Ethernet frames over the EtherCAT network.

void EC_SLV_APP_EoE_send()
{
static uint8_t aFrameBuf[1580] = {0}; /* MTU=1540 with headers, so use a bit more */
uint32_t rxLength = 0;
OSAL_VNET_readFrame(vnetInterface, sizeof(aFrameBuf), aFrameBuf, &rxLength);
if(rxLength != 0)
{
EC_API_SLV_EoE_sendFrame(handle, rxLength, aFrameBuf);
}
}

Network interface settings

Set an IP address to the EtherCAT network interface.

IP configuration

TwinCAT settings

Master settings

Enable Virtual Ethernet Switch and the TCP/IP Stack connection for the EtherCAT Master on TwinCAT.

Master configuration

Slave settings

Enable Virtual Ethernet Port and set an IP address to the EtherCAT slave. The default gateway must the EtherCAT network interface IP address.

Slave configuration

Testing

The EtherCAT slave simple demo implements EoE protocol for AM64x EVM with the Linux SDK. The application creates a Linux TAP device (a virtual network interface) and the IP configuration are set by the EtherCAT master.

Restart the communication on TwinCAT with the EoE settings. If the application and the IP configuration are correct, once the slave is brought to PreOP state, then the virtual network interface should be available.

EoE Network interface in Linux

Therefore, now it should be possible to ping the device or to open an SSH communication.

SSH connection to AM64x from Windows

For troubleshooting is highly recommended to use Wireshark.