Ethercat Doc
Ethercat Doc
Ethercat Doc
2
Documentation
2 Architecture 5
2.1 Master Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.2 Master Phases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.3 Process Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3 Application Interface 13
3.1 Master Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.1.1 Slave Configuration . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.2 Cyclic Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3.3 VoE Handlers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.4 Concurrent Master Access . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.5 Distributed Clocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
4 Ethernet Devices 23
4.1 Network Driver Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
4.2 Native EtherCAT Device Drivers . . . . . . . . . . . . . . . . . . . . . 25
4.3 Generic EtherCAT Device Driver . . . . . . . . . . . . . . . . . . . . . 28
4.4 Providing Ethernet Devices . . . . . . . . . . . . . . . . . . . . . . . . 29
4.5 Redundancy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
4.6 EtherCAT Device Interface . . . . . . . . . . . . . . . . . . . . . . . . . 29
4.7 Patching Native Network Drivers . . . . . . . . . . . . . . . . . . . . . 30
5 State Machines 31
5.1 State Machine Theory . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
5.2 The Master’s State Model . . . . . . . . . . . . . . . . . . . . . . . . . 34
5.3 The Master State Machine . . . . . . . . . . . . . . . . . . . . . . . . . 37
5.4 The Slave Scan State Machine . . . . . . . . . . . . . . . . . . . . . . . 37
5.5 The Slave Configuration State Machine . . . . . . . . . . . . . . . . . . 40
5.6 The State Change State Machine . . . . . . . . . . . . . . . . . . . . . 42
5.7 The SII State Machine . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
5.8 The PDO State Machines . . . . . . . . . . . . . . . . . . . . . . . . . 43
7 Userspace Interfaces 53
7.1 Command-line Tool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
7.1.1 Character Devices . . . . . . . . . . . . . . . . . . . . . . . . . . 53
7.1.2 Setting Alias Addresses . . . . . . . . . . . . . . . . . . . . . . . 54
7.1.3 Displaying the Bus Configuration . . . . . . . . . . . . . . . . . 54
7.1.4 Display CRC Error Counters . . . . . . . . . . . . . . . . . . . . 55
7.1.5 Output PDO information in C Language . . . . . . . . . . . . . 55
7.1.6 Displaying Process Data . . . . . . . . . . . . . . . . . . . . . . 56
7.1.7 Setting a Master’s Debug Level . . . . . . . . . . . . . . . . . . 56
7.1.8 Configured Domains . . . . . . . . . . . . . . . . . . . . . . . . 56
7.1.9 SDO Access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
7.1.10 EoE Statistics . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
7.1.11 File-Access over EtherCAT . . . . . . . . . . . . . . . . . . . . . 59
7.1.12 Creating Topology Graphs . . . . . . . . . . . . . . . . . . . . . 60
7.1.13 Master and Ethernet Devices . . . . . . . . . . . . . . . . . . . 60
7.1.14 Sync Managers, PDOs and PDO Entries . . . . . . . . . . . . . 60
7.1.15 Register Access . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
7.1.16 Trigger a Bus Scan . . . . . . . . . . . . . . . . . . . . . . . . . 63
7.1.17 SDO Dictionary . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
7.1.18 SII Access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
7.1.19 Slaves on the Bus . . . . . . . . . . . . . . . . . . . . . . . . . . 65
7.1.20 SoE IDN Access . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
7.1.21 Requesting Application-Layer States . . . . . . . . . . . . . . . 68
7.1.22 Displaying the Master Version . . . . . . . . . . . . . . . . . . . 68
7.1.23 Generating Slave Description XML . . . . . . . . . . . . . . . . 68
7.2 Userspace Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
7.2.1 Using the Library . . . . . . . . . . . . . . . . . . . . . . . . . . 69
7.2.2 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
7.2.3 Timing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
7.3 RTDM Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
7.4 System Integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
7.4.1 Init Script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
7.4.2 Sysconfig File . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
7.4.3 Starting the Master as a Service . . . . . . . . . . . . . . . . . . 73
7.4.4 Integration with systemd . . . . . . . . . . . . . . . . . . . . . . 73
7.5 Debug Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
iv –revision–, 2022/09/05
8 Timing Aspects 77
8.1 Application Interface Profiling . . . . . . . . . . . . . . . . . . . . . . . 77
8.2 Bus Cycle Measuring . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
9 Installation 81
9.1 Getting the Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
9.2 Building the Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
9.3 Building the Interface Documentation . . . . . . . . . . . . . . . . . . . 83
9.4 Installing the Software . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
9.5 Automatic Device Node Creation . . . . . . . . . . . . . . . . . . . . . 85
Bibliography 87
Glossary 89
Index 91
–revision–, 2022/09/05 v
vi –revision–, 2022/09/05
List of Tables
3.1 Specifying a Slave Position . . . . . . . . . . . . . . . . . . . . . . . . . 15
–revision–, 2022/09/05 ix
Conventions
Conventions
The following typographic conventions are used:
• Italic face is used for newly introduced terms and file names.
• Typewriter face is used for code examples and command line output.
• Bold typewriter face is used for user input in command lines.
Data values and addresses are usually specified as hexadecimal values. These are
marked in the C programming language style with the prefix 0x (example: 0x88A4).
Unless otherwise noted, address values are specified as byte addresses.
Function names are always printed with parentheses, but without parameters. So, if
a function ecrt_request_master() has empty parentheses, this shall not imply that
it has no parameters.
If shell commands have to be entered, this is marked by a dollar prompt:
Further, if a shell command has to be entered as the superuser, the prompt is a mesh:
x –revision–, 2022/09/05
1 The IgH EtherCAT Master
This chapter covers some general information about the EtherCAT master.
–revision–, 2022/09/05 1
1 The IgH EtherCAT Master
2 –revision–, 2022/09/05
1.2 License
1.2 License
The master code is released under the terms and conditions of the GNU General Public
License (GPL [4]), version 2. Other developers, that want to use EtherCAT with Linux
systems, are invited to use the master code or even participate on development.
To allow static linking of userspace application against the master’s application inter-
face (see chapter 3), the userspace library (see section 7.2) is licensed under the terms
and conditions of the GNU Lesser General Public License (LGPL [5]), version 2.1.
–revision–, 2022/09/05 3
1 The IgH EtherCAT Master
4 –revision–, 2022/09/05
2 Architecture
The EtherCAT master is integrated into the Linux kernel. This was an early design
decision, which has been made for several reasons:
• Kernel code has significantly better realtime characteristics, i. e. less latency
than userspace code. It was foreseeable, that a fieldbus master has a lot of
cyclic work to do. Cyclic work is usually triggered by timer interrupts inside
the kernel. The execution delay of a function that processes timer interrupts is
less, when it resides in kernelspace, because there is no need of time-consuming
context switches to a userspace process.
• It was also foreseeable, that the master code has to directly communicate with
the Ethernet hardware. This has to be done in the kernel anyway (through
network device drivers), which is one more reason for the master code being in
kernelspace.
Figure 2.1 gives a general overview of the master architecture.
The components of the master environment are described below:
Master Module Kernel module containing one or more EtherCAT master instances
(see section 2.1), the “Device Interface” (see section 4.6) and the “Application
Interface” (see chapter 3).
Device Modules EtherCAT-capable Ethernet device driver modules, that offer their
devices to the EtherCAT master via the device interface (see section 4.6). These
modified network drivers can handle network devices used for EtherCAT oper-
ation and “normal” Ethernet devices in parallel. A master can accept a certain
device and then is able to send and receive EtherCAT frames. Ethernet devices
declined by the master module are connected to the kernel’s network stack as
usual.
Application A program that uses the EtherCAT master (usually for cyclic exchange
of process data with EtherCAT slaves). These programs are not part of the
EtherCAT master code1 , but have to be generated or written by the user. An
application can request a master through the application interface (see chap-
ter 3). If this succeeds, it has the control over the master: It can provide a bus
configuration and exchange process data. Applications can be kernel modules
(that use the kernel application interface directly) or userspace programs, that
use the application interface via the EtherCAT library (see section 7.2), or the
RTDM library (see section 7.3).
1
Although there are some examples provided in the examples/ directory.
–revision–, 2022/09/05 5
2 Architecture
6 –revision–, 2022/09/05
2.1 Master Module
The two masters can be addressed by their indices 0 and 1 respectively (see Figure 2.2).
The master index is needed for the ecrt_master_request() function of the application
interface (see chapter 3) and the --master option of the ethercat command-line tool
(see section 7.1), which defaults to 0.
Debug Level The master module also has a parameter debug level to set the initial
debug level for all masters (see also subsection 7.1.7).
Init Script In most cases it is not necessary to load the master module and the
Ethernet driver modules manually. There is an init script available, so the master can
be started as a service (see section 7.4). For systems that are managed by systemd
[7], there is also a service file available.
Syslog The master module outputs information about its state and events to the
kernel ring buffer. These also end up in the system logs. The above module loading
command should result in the messages below:
# dmesg | tail -2
EtherCAT : Master driver 1.5.2
EtherCAT : 2 masters waiting for devices .
# tail -2 /var/log/messages
Jul 4 10:22:45 ethercat kernel : EtherCAT : Master driver 1.5.2
Jul 4 10:22:45 ethercat kernel : EtherCAT : 2 masters waiting
for devices .
Master output is prefixed with EtherCAT which makes searching the logs easier.
–revision–, 2022/09/05 7
2 Architecture
Kernel space
master 0 master 1
8 –revision–, 2022/09/05
2.2 Master Phases
Process Data Image Slaves offer their inputs and outputs by presenting the mas-
ter so-called “Process Data Objects” (PDOs). The available PDOs can be either
determined by reading out the slave’s TxPDO and RxPDO SII categories from the
E2 PROM (in case of fixed PDOs) or by reading out the appropriate CoE objects (see
section 6.2), if available. The application can register the PDOs’ entries for exchange
during cyclic operation. The sum of all registered PDO entries defines the “process
data image”, which is exchanged via datagrams with “logical” memory access (like
LWR, LRD or LRW) introduced in [2, sec. 5.4].
Process Data Domains The process data image can be easily managed by creat-
ing so-called “domains”, which allow grouped PDO exchange. They also take care
of managing the datagram structures needed to exchange the PDOs. Domains are
mandatory for process data exchange, so there has to be at least one. They were
introduced for the following reasons:
• The maximum size of a datagram is limited due to the limited size of an Eth-
ernet frame: The maximum data size is the Ethernet data field size minus the
EtherCAT frame header, EtherCAT datagram header and EtherCAT datagram
footer: 1500 − 2 − 12 − 2 = 1484 octets. If the size of the process data image
exceeds this limit, multiple frames have to be sent, and the image has to be
partitioned for the use of multiple datagrams. A domain manages this auto-
matically.
–revision–, 2022/09/05 9
2 Architecture
10 –revision–, 2022/09/05
2.3 Process Data
• Not every PDO has to be exchanged with the same frequency: The values of
PDOs can vary slowly over time (for example temperature values), so exchanging
them with a high frequency would just waste bus bandwidth. For this reason,
multiple domains can be created, to group different PDOs and so allow separate
exchange.
There is no upper limit for the number of domains, but each domain occupies one
FMMU in each slave involved, so the maximum number of domains is de facto limited
by the slaves.
FMMU Configuration An application can register PDO entries for exchange. Every
PDO entry and its parent PDO is part of a memory area in the slave’s physical
memory, that is protected by a sync manager [2, sec. 6.7] for synchronized access.
In order to make a sync manager react on a datagram accessing its memory, it is
necessary to access the last byte covered by the sync manager. Otherwise the sync
manager will not react on the datagram and no data will be exchanged. That is
why the whole synchronized memory area has to be included into the process data
image: For example, if a certain PDO entry of a slave is registered for exchange with
a certain domain, one FMMU will be configured to map the complete sync-manager-
protected memory, the PDO entry resides in. If a second PDO entry of the same slave
is registered for process data exchange within the same domain, and it resides in the
same sync-manager-protected memory as the first one, the FMMU configuration is
not altered, because the desired memory is already part of the domain’s process data
image. If the second PDO entry would belong to another sync-manager-protected
area, this complete area would also be included into the domains process data image.
Figure 2.4 gives an overview, how FMMUs are configured to map physical memory
to logical process data images.
–revision–, 2022/09/05 11
2 Architecture
Slave0 Slave1
12 –revision–, 2022/09/05
3 Application Interface
The application interface provides functions and data structures for applications to
access an EtherCAT master. The complete documentation of the interface is included
as Doxygen [13] comments in the header file include/ecrt.h. It can either be read
directly from the file comments, or as a more comfortable HTML documentation.
The HTML generation is described in section 9.3.
The following sections cover a general description of the application interface.
Every application should use the master in two steps:
Configuration The master is requested and the configuration is applied. For example,
domains are created, slaves are configured and PDO entries are registered (see
section 3.1).
Operation Cyclic code is run and process data are exchanged (see section 3.2).
Example Applications There are a few example applications in the examples/ sub-
directory of the master code. They are documented in the source code.
–revision–, 2022/09/05 13
3 Application Interface
n
Master Domain
Index
n n
n SDO Request
Index
Subindex
14 –revision–, 2022/09/05
3.2 Cyclic Operation
Slave Position The slave position has to be specified as a tuple of “alias” and
“position”. This allows addressing slaves either via an absolute bus position, or a
stored identifier called “alias”, or a mixture of both. The alias is a 16-bit value
stored in the slave’s E2 PROM. It can be modified via the command-line tool (see
subsection 7.1.2). Table 3.1 shows, how the values are interpreted.
Figure 3.2 shows an example of how slave configurations are attached. Some of the
configurations were attached, while others remain detached. The below lists gives the
reasons beginning with the top slave configuration.
1. A zero alias means to use simple position addressing. Slave 1 exists and vendor
id and product code match the expected values.
2. Although the slave with position 0 is found, the product code does not match,
so the configuration is not attached.
3. The alias is non-zero, so alias addressing is used. Slave 2 is the first slave with
alias 0x2000. Because the position value is zero, the same slave is used.
4. There is no slave with the given alias, so the configuration can not be attached.
5. Slave 2 is again the first slave with the alias 0x2000, but position is now 1, so
slave 3 is attached.
If the master sources are configured with --enable-wildcards, then 0xffffffff matches
every vendor ID and/or product code.
–revision–, 2022/09/05 15
3 Application Interface
Alias: 0x2000
Position: 1
Vendor: 0x00000001
Product: 0x00000002
16 –revision–, 2022/09/05
3.3 VoE Handlers
–revision–, 2022/09/05 17
3 Application Interface
Master Module
Application Module
Application
Interface
Task Master0
EoE
18 –revision–, 2022/09/05
3.5 Distributed Clocks
mechanism to avoid accessing the bus at the same time. See the application interface
documentation (chapter 3) for how to use these callbacks.
Local Clocks Any EtherCAT slave that supports DC has a local clock register with
nanosecond resolution. If the slave is powered, the clock starts from zero, meaning
that when slaves are powered on at different times, their clocks will have different
values. These “offsets” have to be compensated by the distributed clocks mechanism.
On the other hand, the clocks do not run exactly with the same speed, since the
used quarts units have a natural frequency deviation. This deviation is usually very
small, but over longer periods, the error would accumulate and the difference between
local clocks would grow. This clock “drift” has also to be compensated by the DC
mechanism.
Application Time The common time base for the bus has to be provided by the
application. This application time tapp is used
Offset Compensation For the offset compensation, each slave provides a “System
Time Offset” register toff , that is added to the internal clock value tint to get the
“System Time” tsys :
The master reads the values of both registers to calculate a new system time offset in
a way, that the resulting system time shall match the master’s application time tapp :
–revision–, 2022/09/05 19
3 Application Interface
Master
20 –revision–, 2022/09/05
3.5 Distributed Clocks
!
tsys = tapp (3.2)
!
⇒ tint + toff = tapp
⇒ toff = tapp − tint
⇒ toff = tapp − (tsys − toff )
⇒ toff = tapp − tsys + toff (3.3)
The small time offset error resulting from the different times of reading and writing
the registers will be compensated by the drift compensation.
Transmission Delays The Ethernet frame needs a small amount of time to get from
slave to slave. The resulting transmission delay times accumulate on the bus and
can reach microsecond magnitude and thus have to be considered during the drift
compensation. EtherCAT slaves supporting DC provide a mechanism to measure the
transmission delays: For each of the four slave ports there is a receive time register.
A write operation to the receive time register of port 0 starts the measuring and the
current system time is latched and stored in a receive time register once the frame
is received on the corresponding port. The master can read out the relative receive
times, then calculate time delays between the slaves (using its knowledge of the bus
topology), and finally calculate the time delays from the reference clock to each slave.
These values are programmed into the slaves’ transmission delay registers. In this
way, the drift compensation can reach nanosecond synchrony.
Checking Synchrony DC-capable slaves provide the 32-bit “System time difference”
register at address 0x092c, where the system time difference of the last drift compensa-
tion is stored in nanosecond resolution and in sign-and-magnitude coding3 . To check
for bus synchrony, the system time difference registers can also be cyclically read via
the command-line-tool (see subsection 7.1.15):
2
The local slave clock will be incremented either with 9 ns, 10 ns or 11 ns every 10 ns.
3
This allows broadcast-reading all system time difference registers on the bus to get an upper
approximation
–revision–, 2022/09/05 21
3 Application Interface
Sync Signals Synchronous clocks are only the prerequisite for synchronous events
on the bus. Each slave with DC support provides two “sync signals”, that can be
programmed to create events, that will for example cause the slave application to
latch its inputs on a certain time. A sync event can either be generated once or
cyclically, depending on what makes sense for the slave application. Programming
the sync signals is a matter of setting the so-called “AssignActivate” word and the
sync signals’ cycle- and shift times. The AssignActivate word is slave-specific and has
to be taken from the XML slave description (Device → Dc), where also typical sync
signal configurations “OpModes” can be found.
22 –revision–, 2022/09/05
4 Ethernet Devices
The EtherCAT protocol is based on the Ethernet standard, so a master relies on
standard Ethernet hardware to communicate with the bus.
The term device is used as a synonym for Ethernet network interface hardware.
Native Ethernet Device Drivers There are native device driver modules (see sec-
tion 4.2) that handle Ethernet hardware, which a master can use to connect to an
EtherCAT bus. They offer their Ethernet hardware to the master module via the
device interface (see section 4.6) and must be capable to prepare Ethernet devices
either for EtherCAT (realtime) operation or for “normal” operation using the kernel’s
network stack. The advantage of this approach is that the master can operate nearly
directly on the hardware, which allows a high performance. The disadvantage is, that
there has to be an EtherCAT-capable version of the original Ethernet driver.
Generic Ethernet Device Driver From master version 1.5, there is a generic Eth-
ernet device driver module (see section 4.3), that uses the lower layers of the network
stack to connect to the hardware. The advantage is, that arbitrary Ethernet hardware
can be used for EtherCAT operation, independently of the actual hardware driver (so
all Linux Ethernet drivers are supported without modifications). The disadvantage
is, that this approach does not support realtime extensions like RTAI, because the
Linux network stack is addressed. Moreover the performance is a little worse than
the native approach, because the Ethernet frame data have to traverse the network
stack.
Tasks of a Network Driver Network device drivers usually handle the lower two
layers of the OSI model, that is the physical layer and the data-link layer. A network
device itself natively handles the physical layer issues: It represents the hardware to
connect to the medium and to send and receive data in the way, the physical layer
–revision–, 2022/09/05 23
4 Ethernet Devices
protocol describes. The network device driver is responsible for getting data from the
kernel’s networking stack and forwarding it to the hardware, that does the physical
transmission. If data is received by the hardware respectively, the driver is notified
(usually by means of an interrupt) and has to read the data from the hardware memory
and forward it to the network stack. There are a few more tasks, a network device
driver has to handle, including queue control, statistics and device dependent features.
Driver Startup Usually, a driver searches for compatible devices on module loading.
For PCI drivers, this is done by scanning the PCI bus and checking for known device
IDs. If a device is found, data structures are allocated and the device is taken into
operation.
The net_device Structure The driver registers a net_device structure for each
device to communicate with the network stack and to create a “network interface”.
In case of an Ethernet driver, this interface appears as ethX, where X is a number
assigned by the kernel on registration. The net_device structure receives events
(either from userspace or from the network stack) via several callbacks, which have
to be set before registration. Not every callback is mandatory, but for reasonable
operation the ones below are needed in any case:
open() This function is called when network communication has to be started, for ex-
ample after a command ip link set ethX up from userspace. Frame reception
has to be enabled by the driver.
stop() The purpose of this callback is to “close” the device, i. e. make the hardware
stop receiving frames.
hard_start_xmit() This function is called for each frame that has to be transmitted.
The network stack passes the frame as a pointer to an sk_buff structure (“socket
buffer”, see below), which has to be freed after sending.
get_stats() This call has to return a pointer to the device’s net_device_stats struc-
ture, which permanently has to be filled with frame statistics. This means,
that every time a frame is received, sent, or an error happened, the appropriate
counter in this structure has to be increased.
The actual registration is done with the register_netdev() call, unregistering is done
with unregister_netdev().
24 –revision–, 2022/09/05
4.2 Native EtherCAT Device Drivers
The netif Interface All other communication in the direction interface → network
stack is done via the netif_*() calls. For example, on successful device opening,
the network stack has to be notified, that it can now pass frames to the interface.
This is done by calling netif_start_queue(). After this call, the hard_start_xmit()
callback can be called by the network stack. Furthermore a network driver usually
manages a frame transmission queue. If this gets filled up, the network stack has
to be told to stop passing further frames for a while. This happens with a call
to netif_stop_queue(). If some frames have been sent, and there is enough space
again to queue new frames, this can be notified with netif_wake_queue(). Another
important call is netif_receive_skb()1 : It passes a frame to the network stack, that
was just received by the device. Frame data has to be included in a so-called “socket
buffer” for that (see below).
Socket Buffers Socket buffers are the basic data type for the whole network stack.
They serve as containers for network data and are able to quickly add data headers
and footers, or strip them off again. Therefore a socket buffer consists of an allocated
buffer and several pointers that mark beginning of the buffer (head), beginning of data
(data), end of data (tail) and end of buffer (end). In addition, a socket buffer holds
network header information and (in case of received data) a pointer to the net_device,
it was received on. There exist functions that create a socket buffer (dev_alloc_skb
()), add data either from front (skb_push()) or back (skb_put()), remove data from
front (skb_pull()) or back (skb_trim()), or delete the buffer (kfree_skb()). A socket
buffer is passed from layer to layer, and is freed by the layer that uses it the last time.
In case of sending, freeing has to be done by the network driver.
Dedicated Hardware For performance and realtime purposes, the EtherCAT master
needs direct and exclusive access to the Ethernet hardware. This implies that the
network device must not be connected to the kernel’s network stack as usual, because
the kernel would try to use it as an ordinary Ethernet device.
–revision–, 2022/09/05 25
4 Ethernet Devices
notify the driver about frame reception: The master can instead query the hardware
for received frames, if it expects them to be already received.
Figure 4.1 shows two workflows for cyclic frame transmission and reception with and
without interrupts.
In the left workflow “Interrupt Operation”, the data from the last cycle is first pro-
cessed and a new frame is assembled with new datagrams, which is then sent. The
cyclic work is done for now. Later, when the frame is received again by the hardware,
an interrupt is triggered and the ISR is executed. The ISR will fetch the frame data
from the hardware and initiate the frame dissection: The datagrams will be processed,
so that the data is ready for processing in the next cycle.
In the right workflow “Interrupt-less Operation”, there is no hardware interrupt en-
abled. Instead, the hardware will be polled by the master by executing the ISR. If the
frame has been received in the meantime, it will be dissected. The situation is now
the same as at the beginning of the left workflow: The received data is processed and
a new frame is assembled and sent. There is nothing to do for the rest of the cycle.
The interrupt-less operation is desirable, because hardware interrupts are not con-
ducive in improving the driver’s realtime behaviour: Their indeterministic incidences
contribute to increasing the jitter. Besides, if a realtime extension (like RTAI) is used,
some additional effort would have to be made to prioritize interrupts.
Ethernet and EtherCAT Devices Another issue lies in the way Linux handles de-
vices of the same type. For example, a PCI driver scans the PCI bus for devices it can
handle. Then it registers itself as the responsible driver for all of the devices found.
The problem is, that an unmodified driver can not be told to ignore a device because
it will be used for EtherCAT later. There must be a way to handle multiple devices
of the same type, where one is reserved for EtherCAT, while the other is treated as
an ordinary Ethernet device.
For all this reasons, the author decided that the only acceptable solution is to modify
standard Ethernet drivers in a way that they keep their normal functionality, but gain
the ability to treat one or more of the devices as EtherCAT-capable.
Below are the advantages of this solution:
• No need to tell the standard drivers to ignore certain devices.
• One networking driver for EtherCAT and non-EtherCAT devices.
• No need to implement a network driver from scratch and running into issues,
the former developers already solved.
The chosen approach has the following disadvantages:
• The modified driver gets more complicated, as it must handle EtherCAT and
non-EtherCAT devices.
• Many additional case differentiations in the driver code.
• Changes and bug fixes on the standard drivers have to be ported to the Ether-
CAT-capable versions from time to time.
26 –revision–, 2022/09/05
4.2 Native EtherCAT Device Drivers
Realtime Cycle
Frame Assembly
Interrupt
Frame Sending
Time
ISR
Frame Dissection
–revision–, 2022/09/05 27
4 Ethernet Devices
Since there are approaches to enable the complete Linux kernel for realtime operation
[12], it is possible to operate without native implementations of EtherCAT-capable
Ethernet device drivers and use the Linux network stack instead. Figure 2.1 shows
the “Generic Ethernet Driver Module”, that connects to local Ethernet devices via
the network stack. The kernel module is named ec_generic and can be loaded after
the master module like a native EtherCAT-capable Ethernet driver.
The generic device driver scans the network stack for interfaces, that have been reg-
istered by Ethernet device drivers. It offers all possible devices to the EtherCAT
master. If the master accepts a device, the generic driver creates a packet socket (see
man 7 packet) with socket_type set to SOCK_RAW, bound to that device. All functions
of the device interface (see section 4.6) will then operate on that socket.
Below are the advantages of this solution:
• Any Ethernet hardware, that is covered by a Linux Ethernet driver can be used
for EtherCAT.
• No modifications have to be made to the actual Ethernet drivers.
• The performance is a little worse than the native approach, because the frame
data have to traverse the lower layers of the network stack.
• It is not possible to use in-kernel realtime extensions like RTAI with the generic
driver, because the network stack code uses dynamic memory allocations and
other things, that could cause the system to freeze in realtime context.
Device Activation In order to send and receive frames through a socket, the Eth-
ernet device linked to that socket has to be activated, otherwise all frames will be
rejected. Activation has to take place before the master module is loaded and can
happen in several ways:
• Ad-hoc, using the command ip link set dev ethX up (or the older ifconfig
ethX up),
• Configured, depending on the distribution, for example using ifcfg files (/etc
/sysconfig/network/ifcfg-ethX) in openSUSE and others. This is the better
choice, if the EtherCAT master shall start at system boot time. Since the
Ethernet device shall only be activated, but no IP address etc. shall be assigned,
it is enough to use STARTMODE=auto as configuration.
28 –revision–, 2022/09/05
4.4 Providing Ethernet Devices
4.5 Redundancy
Redundant bus operation means, that there is more than one Ethernet connection
from the master to the slaves. Process data exchange datagrams are sent out on
every master link, so that the exchange is still complete, even if the bus is disconnected
somewhere in between.
Prerequisite for fully redundant bus operation is, that every slave can be reached by
at least one master link. In this case a single connection failure (i. e. cable break) will
never lead to incomplete process data. Double-faults can not be handled with two
Ethernet devices.
Redundancy is configured with the --with-devices switch at configure time (see chap-
ter 9) and using the backup_devices parameter of the ec_master kernel module (see
section 2.1) or the appropriate variable MASTERx_BACKUP in the (sys-)config file (see
subsection 7.4.2).
Bus scanning is done after a topology change on any Ethernet link. The applica-
tion interface (see chapter 3) and the command-line tool (see section 7.1) both have
methods to query the status of the redundant operation.
–revision–, 2022/09/05 29
4 Ethernet Devices
The documentation of the device interface can be found in the header file or in the
appropriate module of the interface documentation (see section 9.3 for generation
instructions).
30 –revision–, 2022/09/05
5 State Machines
Many parts of the EtherCAT master are implemented as finite state machines (FSMs).
Though this leads to a higher grade of complexity in some aspects, is opens many
new possibilities.
The below short code example exemplary shows how to read all slave states and
moreover illustrates the restrictions of “sequential” coding:
The ec master simple io() function provides a simple interface for synchronously send-
ing a single datagram and receiving the result1 . Internally, it queues the specified
datagram, invokes the ec master send datagrams() function to send a frame with the
queued datagram and then waits actively for its reception.
This sequential approach is very simple, reflecting in only three lines of code. The
disadvantage is, that the master is blocked for the time it waits for datagram reception.
There is no difficulty when only one instance is using the master, but if more instances
want to (synchronously2 ) use the master, it is inevitable to think about an alternative
to the sequential model.
Master access has to be sequentialized for more than one instance wanting to send
and receive datagrams synchronously. With the present approach, this would result in
having one phase of active waiting for each instance, which would be non-acceptable
especially in realtime circumstances, because of the huge time overhead.
A possible solution is, that all instances would be executed sequentially to queue
their datagrams, then give the control to the next instance instead of waiting for the
datagram reception. Finally, bus IO is done by a higher instance, which means that
all queued datagrams are sent and received. The next step is to execute all instances
again, which then process their received datagrams and issue new ones.
This approach results in all instances having to retain their state, when giving the
control back to the higher instance. It is quite obvious to use a finite state machine
model in this case. section 5.1 will introduce some of the theory used, while the
1
For all communication issues have been meanwhile sourced out into state machines, the function
is deprecated and stopped existing. Nevertheless it is adequate for showing it’s own restrictions.
2
At this time, synchronous master access will be adequate to show the advantages of an FSM. The
asynchronous approach will be discussed in section 6.1
–revision–, 2022/09/05 31
5 State Machines
listings below show the basic approach by coding the example from above as a state
machine:
1 // state 1
2 ec_datagram_brd ( datagram , 0 x0130 , 2) ; // prepare datagram
3 ec_master_queue ( master , datagram ) ; // queue datagram
4 next_state = state_2 ;
5 // state processing finished
After all instances executed their current state and queued their datagrams, these are
sent and received. Then the respective next states are executed:
1 // state 2
2 if ( datagram - > state != E C _ D G R A M _ S T A T E _ R E C E I V E D ) {
3 next_state = state_error ;
4 return ; // state processing finished
5 }
6 slave_states = EC_READ_U8 ( datagram - > data ) ; // process datagram
7 // state processing finished .
See section 5.2 for an introduction to the state machine programming concept used
in the master code.
32 –revision–, 2022/09/05
5.1 State Machine Theory
The state diagram for the same example looks like the one in Figure 5.1. The states
are represented as circles or ellipses and the transitions are drawn as arrows between
them. Close to a transition arrow can be the condition that must be fulfilled to
allow the transition. The initial state is marked by a filled black circle with an arrow
pointing to the respective state.
b
a, b
s0 s1
ε
ε
a
a, b, ε
s2
–revision–, 2022/09/05 33
5 State Machines
Moore and Mealy machines There is a distinction between so-called Moore ma-
chines, and Mealy machines. Mathematically spoken, the distinction lies in the output
function ω: If it only depends on the current state (ω : S → Γ), the machine corre-
sponds to the “Moore Model”. Otherwise, if ω is a function of a state and the input
alphabet (ω : S × Σ → Γ) the state machine corresponds to the “Mealy model”.
Mealy machines are the more practical solution in most cases, because their design
allows machines with a minimum number of states. In practice, a mixture of both
models is often used.
State Machine Programming There are certain ways to implement a state machine
in C code. An obvious way is to implement the different states and actions by one
big case differentiation:
34 –revision–, 2022/09/05
5.2 The Master’s State Model
17 state = STATE_1 ;
18 break ;
19 }
20 }
For small state machines, this is an option. The disadvantage is, that with an increas-
ing number of states the code soon gets complex and an additional case differentiation
is executed each run. Besides, lots of indentation is wasted.
The method used in the master is to implement every state in an own function and
to store the current state function with a function pointer:
In the master code, state pointers of all state machines3 are gathered in a single
object of the ec_fsm_master_t class. This is advantageous, because there is always
one instance of every state machine available and can be started on demand.
Mealy and Moore If a closer look is taken to the above listing, it can be seen that
the actions executed (the “outputs” of the state machine) only depend on the current
state. This accords to the “Moore” model introduced in section 5.1. As mentioned,
the “Mealy” model offers a higher flexibility, which can be seen in the listing below:
–revision–, 2022/09/05 35
5 State Machines
2 if ( some_condition ) {
3 action_7a () ;
4 state = state1 ;
5 }
6 else {
7 action_7b () ;
8 state = state8 ;
9 }
10 }
3 +
7 The state function executes the actions depending on the state transition,
that is about to be done.
The most flexible alternative is to execute certain actions depending on the state,
followed by some actions dependent on the state transition:
This model is often used in the master. It combines the best aspects of both ap-
proaches.
Using Sub State Machines To avoid having too much states, certain functions of
the EtherCAT master state machine have been sourced out into sub state machines.
This helps to encapsulate the related workflows and moreover avoids the “state ex-
plosion” phenomenon described in section 5.1. If the master would instead use one
big state machine, the number of states would be a multiple of the actual number.
This would increase the level of complexity to a non-manageable grade.
Executing Sub State Machines If a state machine starts to execute a sub state
machine, it usually remains in one state until the sub state machine terminates. This
is usually done like in the listing below, which is taken out of the slave configuration
state machine code:
36 –revision–, 2022/09/05
5.3 The Master State Machine
3 change_state is the state pointer of the state change state machine. The state
function, the pointer points on, is executed. . .
6 . . . either until the state machine terminates with the error state . . .
11 . . . or until the state machine terminates in the end state. Until then, the “higher”
state machine remains in the current state and executes the sub state machine
again in the next cycle.
State Machine Descriptions The below sections describe every state machine used
in the EtherCAT master. The textual descriptions of the state machines contain
references to the transitions in the corresponding state transition diagrams, that are
marked with an arrow followed by the name of the successive state. Transitions caused
by trivial error cases (i. e. no response from slave) are not described explicitly. These
transitions are drawn as dashed arrows in the diagrams.
–revision–, 2022/09/05 37
5 State Machines
00 00 00 00 00
73 74 61 72 74
00 00 00 00 00 00 00 00 00
62 72 6F 61 64 63 61 73 74
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
63 6C 65 61 72 5F 61 64 64 72 65 73 73 65 73 72 65 61 64 5F 73 74 61 74 65
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
64 63 5F 6D 65 61 73 75 72 65 5F 64 65 6C 61 79 73 61 63 6B 6E 6F 77 6C 65 64 67 65
00 00 00 00 00 00 00 00 00 00
73 63 61 6E 5F 73 6C 61 76 65
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
77 72 69 74 65 5F 73 79 73 74 65 6D 5F 74 69 6D 65 73 63 6F 6E 66 69 67 75 72 65 5F 73 6C 61 76 65
00 00 00 00 00 00 00 00 00 00 00 00 00 00
64 63 5F 72 65 61 64 5F 6F 66 66 73 65 74
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
64 63 5F 77 72 69 74 65 5F 6F 66 66 73 65 74
00 00 00 00 00 00 00 00 00 00 00 00 00 00
73 64 6F 5F 64 69 63 74 69 6F 6E 61 72 79
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
73 64 6F 5F 72 65 71 75 65 73 74 77 72 69 74 65 5F 73 69 69 72 65 67 5F 72 65 71 75 65 73 74
38 –revision–, 2022/09/05
5.4 The Slave Scan State Machine
00 00 00 00 00
73 74 61 72 74
00 00 00 00 00 00 00
61 64 64 72 65 73 73
00 00 00 00 00
73 74 61 74 65
00 00 00 00
62 61 73 65
00 00 00 00 00
00 00 00 00 00 00 44 43 6E 6F 74
64 63 5F 63 61 70 00 00 00 00 00 00 00 00 00
73 75 70 70 6F 72 74 65 64
00 00 00 00 00 00 00 00
64 61 74 61 6C 69 6E 6B
00 00 00 00 00 00 00 00
73 69 69 5F 73 69 7A 65
00 00 00 00 00 00 00 00
73 69 69 5F 64 61 74 61
00 00 00 00 00
4E 6F 74 69 6E
00 00 00 00 00
50 52 45 4F 50
00 00 00 00 00 00 00 00 00
70 72 65 6F 70 73 79 6E 63
00 00 00 00 00 00 00 00 00 00
4E 6F 63 61 74 65 67 6F 72 79
00 00 00 00
64 61 74 61
00 00 00 00
70 64 6F 73
00 00 00
65 6E 64
–revision–, 2022/09/05 39
5 State Machines
Node Address The node address is set for the slave, so that it can be node-addressed
for all following operations.
AL State The initial application-layer state is read.
Base Information Base information (like the number of supported FMMUs) is read
from the lower physical memory.
Data Link Information about the physical ports is read.
SII Size The size of the SII contents is determined to allocate SII image memory.
SII Data The SII contents are read into the master’s image.
PREOP If the slave supports CoE, it is set to PREOP state using the State change
FSM (see section 5.6) to enable mailbox communication and read the PDO
configuration via CoE.
PDOs The PDOs are read via CoE (if supported) using the PDO Reading FSM (see
section 5.8). If this is successful, the PDO information from the SII (if any) is
overwritten.
40 –revision–, 2022/09/05
5.5 The Slave Configuration State Machine
00 00 00 00 00
73 74 61 72 74
00 00 00 00
69 6E 69 74
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
63 6C 65 61 72 5F 66 6D 6D 75 73 4E 6F 46 4D 4D 55 73
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
63 6C 65 61 72 5F 73 79 6E 63 4E 6F 53 4D 73
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
64 63 5F 63 6C 65 61 72 5F 61 73 73 69 67 6E
00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 4E 6F 44 43
64 63 5F 72 65 61 64 5F 6F 66 66 73 65 74 00 00 00 00 00 00 00
73 75 70 70 6F 72 74
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
64 63 5F 77 72 69 74 65 5F 6F 66 66 73 65 74
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
6D 62 6F 78 5F 73 79 6E 63 4E 6F 6D 61 69 6C 62 6F 78 65 73
00 00 00 00 00 00
43 6F 6E 66 69 67 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 62 6F 6F 74 5F 70 72 65 6F 70
64 65 74 61 63 68 65 64
00 00 00 00 00 00
00 00 00 00 00 00 00 00 4E 6F 53 44 4F 73
73 64 6F 5F 63 6F 6E 66 00 00 00 00 00 00 00 00 00 00
63 6F 6E 66 69 67 75 72 65 64
00 00 00 00 00 00 00 00
4E 6F 63 6F 6E 66 69 67
00 00 00 00 00 00 00 00
61 74 74 61 63 68 65 64
00 00 00 00 00 00 00 00
70 64 6F 5F 63 6F 6E 66
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
70 64 6F 5F 73 79 6E 63 4E 6F 50 44 4F 53 4D 73
00 00 00 00
49 4E 49 54
00 00 00 00 00 00 00 00 00
72 65 71 75 65 73 74 65 64
00 00 00 00 00
50 52 45 4F 50 00 00 00 00 00 00 00
00 00 00 00 00 00 4E 6F 46 4D 4D 55 73 00 00 00 00
6F 72 42 4F 4F 54 00 00 00 00 00 00 00 00 00 00 66 6D 6D 75
00 00 00 00 00 00 00 00 00 63 6F 6E 66 69 67 75 72 65 64
72 65 71 75 65 73 74 65 64
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 4E 6F 63 6F 6E 66 69 67
64 63 5F 63 79 63 6C 65 00 00 00 00 00 00 00 00
61 74 74 61 63 68 65 64
00 00 00 00 00
00 00 00 00 00 00 00 00 44 43 6E 6F 74
64 63 5F 73 74 61 72 74 00 00 00 00 00 00 00 00 00 00
63 6F 6E 66 69 67 75 72 65 64
00 00 00 00 00 00 00 00 00
64 63 5F 61 73 73 69 67 6E
00 00 00 00 00 00
73 61 66 65 6F 70
00 00 00 00 00 00
00 00 53 41 46 45 4F 50
6F 70 00 00 00 00 00 00 00 00 00
72 65 71 75 65 73 74 65 64
00 00 00
65 6E 64
00 00 00 00 00
73 74 61 72 74
00 00 00 00 00
63 68 65 63 6B
00 00 00 00 00 00
73 74 61 74 75 73
00 00 00 00 00 00
52 65 66 75 73 65
00 00 00 00 00 00 00 00 00 00 00 00 00
63 6F 64 65 73 74 61 72 74 5F 61 63 6B
00 00 00 00 00 00 00 00
52 65 73 70 6F 6E 73 65 00 00 00 00 00 00 00
00 00 00 00 00 00 00 41 63 6B 6F 6E 6C 79
74 69 6D 65 6F 75 74
00 00 00 00 00 00
43 68 61 6E 67 65 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 61 63 6B 53 75 63 63 65 73 73
74 69 6D 65 6F 75 74
00 00 00 00 00 00 00 00 00
63 68 65 63 6B 5F 61 63 6B
00 00 00 00 00 00 00
41 63 6B 6F 6E 6C 79
00 00 00 00 00 00 00 00
65 72 72 6F 72 65 6E 64
Start The new application-layer state is requested via the “AL Control Request”
register (see [3, sec. 5.3.1]).
Check for Response Some slave need some time to respond to an AL state change
command, and do not respond for some time. For this case, the command is
issued again, until it is acknowledged.
Check AL Status If the AL State change datagram was acknowledged, the “AL Con-
trol Response” register (see [3, sec. 5.3.2]) must be read out until the slave
changes the AL state.
AL Status Code If the slave refused the state change command, the reason can be
read from the “AL Status Code” field in the “AL State Changed” registers
(see [3, sec. 5.3.3]).
Acknowledge State If the state change was not successful, the master has to ac-
knowledge the old state by writing to the “AL Control request” register again.
Check Acknowledge After sending the acknowledge command, it has to read out the
“AL Control Response” register again.
The “start ack” state is a shortcut in the state machine for the case, that the master
wants to acknowledge a spontaneous AL state change, that was not requested.
42 –revision–, 2022/09/05
5.7 The SII State Machine
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
73 74 61 72 74 5F 72 65 61 64 69 6E 67 73 74 61 72 74 5F 77 72 69 74 69 6E 67
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
72 65 61 64 5F 63 68 65 63 6B 77 72 69 74 65 5F 63 68 65 63 6B
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
72 65 61 64 5F 66 65 74 63 68 77 72 69 74 65 5F 63 68 65 63 6B 32
00 00 00 00 00 00 00 00
65 72 72 6F 72 65 6E 64
–revision–, 2022/09/05 43
5 State Machines
PDO Reading FSM This state machine (Figure 5.7) has the purpose to read the
complete PDO configuration of a slave. It reads the PDO assignment for each Sync
Manager and uses the PDO Entry Reading FSM (Figure 5.8) to read the mapping
for each assigned PDO.
00 00 00 00 00
73 74 61 72 74
00 00 00 00 00 00 00
46 69 72 73 74 53 4D
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
70 64 6F 5F 63 6F 75 6E 74 65 6E 64 4E 6F 6D 6F 72 65 50 44 4F 73
00 00 00 00 00 00 00
4E 65 78 74 50 44 4F
00 00 00
70 64 6F
00 00 00 00 00 00 00 00 00 00 00
70 64 6F 5F 65 6E 74 72 69 65 73
Basically it reads the every Sync manager’s PDO assignment SDO’s (0x1C1x) number
of elements to determine the number of assigned PDOs for this sync manager and
then reads out the subindices of the SDO to get the assigned PDO’s indices. When
a PDO index is read, the PDO Entry Reading FSM is executed to read the PDO’s
mapped PDO entries.
PDO Entry Reading FSM This state machine (Figure 5.8) reads the PDO mapping
(the PDO entries) of a PDO. It reads the respective mapping SDO (0x1600 – 0x17ff,
or 0x1a00 – 0x1bff) for the given PDO by reading first the subindex zero (number of
elements) to determine the number of mapped PDO entries. After that, each subindex
is read to get the mapped PDO entry index, subindex and bit size.
00 00 00 00 00
73 74 61 72 74
00 00 00 00 00
63 6F 75 6E 74
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
4E 65 78 74 65 6E 74 72 79 4E 6F 6D 6F 72 65 65 6E 74 72 69 65 73
00 00 00 00 00 00 00 00 00 00 00 00
70 64 6F 5F 65 6E 74 72 79 65 6E 64
Figure 5.8: Transition Diagram of the PDO Entry Reading State Machine
44 –revision–, 2022/09/05
5.8 The PDO State Machines
00 00 00 00 00
73 74 61 72 74
00 00 00 00 00 00 00
46 69 72 73 74 53 4D
00 00 00 00 00 00 00 00
4E 6F 63 6F 6E 66 69 67
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
46 69 72 73 74 50 44 4F 4E 6F 6D 6F 72 65 53 4D 73
00 00 00
65 6E 64
00 00 00 00 00 00 00
55 6E 6B 6E 6F 77 6E
00 00 00 00 00 00 00 00 00 00 00 00
72 65 61 64 5F 6D 61 70 70 69 6E 67
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
41 73 73 69 67 6E 6F 6B 4E 6F 50 44 4F 73 4E 65 78 74 50 44 4F
00 00 00 00 00 00
4E 6F 50 44 4F 73
00 00 00 00 00 00 00
6D 61 70 70 69 6E 67
00 00 00 00 00 00 00 00 00 00 00 00 00 00
7A 65 72 6F 5F 70 64 6F 5F 63 6F 75 6E 74
00 00 00 00 00 00 00 00
46 69 72 73 74 50 44 4F
00 00 00 00 00 00 00
4E 65 78 74 50 44 4F
00 00 00 00 00 00 00 00 00 00
61 73 73 69 67 6E 5F 70 64 6F
00 00 00 00 00 00 00 00 00 00
4E 6F 6D 6F 72 65 50 44 4F 73
00 00 00 00 00 00 00 00 00 00 00 00 00
73 65 74 5F 70 64 6F 5F 63 6F 75 6E 74
00 00 00 00 00
73 74 61 72 74
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
7A 65 72 6F 5F 65 6E 74 72 79 5F 63 6F 75 6E 74
00 00 00 00 00 00 00 00 00 00 00 00 00
41 64 64 66 69 72 73 74 65 6E 74 72 79
00 00 00 00 00 00 00 00 00
4E 65 78 74 65 6E 74 72 79
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
4E 6F 45 6E 74 72 69 65 73 6D 61 70 5F 65 6E 74 72 79
00 00 00 00 00 00 00 00 00 00 00 00 00
4E 6F 6D 6F 72 65 45 6E 74 72 69 65 73
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
73 65 74 5F 65 6E 74 72 79 5F 63 6F 75 6E 74
00 00 00
65 6E 64
Figure 5.10: Transition Diagram of the PDO Entry Configuration State Machine
–revision–, 2022/09/05 45
5 State Machines
46 –revision–, 2022/09/05
6 Mailbox Protocol Implementations
The EtherCAT master implements the CANopen over EtherCAT (CoE), Ethernet
over EtherCAT (EoE), File-access over EtherCAT (FoE), Vendor-specific over Ether-
CAT (VoE) and Servo Profile over EtherCAT (SoE) mailbox protocols. See the below
sections for details.
Virtual Network Interfaces The master creates a virtual EoE network interface for
every EoE-capable slave. These interfaces are called either
eoeXsY for a slave without an alias address (see subsection 7.1.2), where X is the
master index and Y is the slave’s ring position, or
eoeXaY for a slave with a non-zero alias address, where X is the master index and
Y is the decimal alias address.
Frames sent to these interfaces are forwarded to the associated slaves by the master.
Frames, that are received by the slaves, are fetched by the master and forwarded to
the virtual interfaces.
This bears the following advantages:
• Flexibility: The user can decide, how the EoE-capable slaves are interconnected
with the rest of the world.
• Standard tools can be used to monitor the EoE activity and to configure the
EoE interfaces.
• The Linux kernel’s layer-2-bridging implementation (according to the IEEE
802.1D MAC Bridging standard) can be used natively to bridge Ethernet traffic
between EoE-capable slaves.
• The Linux kernel’s network stack can be used to route packets between EoE-
capable slaves and to track security issues, just like having physical network
interfaces.
–revision–, 2022/09/05 47
6 Mailbox Protocol Implementations
EoE Handlers The virtual EoE interfaces and the related functionality is encap-
sulated in the ec_eoe_t class. An object of this class is called “EoE handler”. For
example the master does not create the network interfaces directly: This is done inside
the constructor of an EoE handler. An EoE handler additionally contains a frame
queue. Each time, the kernel passes a new socket buffer for sending via the interface’s
hard_start_xmit() callback, the socket buffer is queued for transmission by the EoE
state machine (see below). If the queue gets filled up, the passing of new socket buffers
is suspended with a call to netif_stop_queue().
Creation of EoE Handlers During bus scanning (see section 5.4), the master deter-
mines the supported mailbox protocols for each slave. This is done by examining the
“Supported Mailbox Protocols” mask field at word address 0x001C of the SII. If bit
1 is set, the slave supports the EoE protocol. In this case, an EoE handler is created
for that slave.
EoE State Machine Every EoE handler owns an EoE state machine, that is used
to send frames to the corresponding slave and receive frames from the it via the EoE
communication primitives. This state machine is showed in Figure 6.1.
RX START The beginning state of the EoE state machine. A mailbox check data-
gram is sent, to query the slave’s mailbox for new frames. → RX CHECK
RX CHECK The mailbox check datagram is received. If the slave’s mailbox did not
contain data, a transmit cycle is started. → TX START
If there are new data in the mailbox, a datagram is sent to fetch the new data.
→ RX FETCH
RX FETCH The fetch datagram is received. If the mailbox data do not contain
a “EoE Fragment request” command, the data are dropped and a transmit
sequence is started. → TX START
If the received Ethernet frame fragment is the first fragment, a new socket buffer
is allocated. In either case, the data are copied into the correct position of the
socket buffer.
If the fragment is the last fragment, the socket buffer is forwarded to the network
stack and a transmit sequence is started. → TX START
Otherwise, a new receive sequence is started to fetch the next fragment. → RX -
START
TX START The beginning state of a transmit sequence. It is checked, if the trans-
mission queue contains a frame to send. If not, a receive sequence is started.
→ RX START
If there is a frame to send, it is dequeued. If the queue was inactive before
(because it was full), the queue is woken up with a call to netif wake queue().
The first fragment of the frame is sent. → TX SENT
48 –revision–, 2022/09/05
6.1 Ethernet over EtherCAT (EoE)
TX_START TX_SENT
–revision–, 2022/09/05 49
6 Mailbox Protocol Implementations
TX SENT It is checked, if the first fragment was sent successfully. If the current
frame consists of further fragments, the next one is sent. → TX SENT
If the last fragment was sent, a new receive sequence is started. → RX START
EoE Processing To execute the EoE state machine of every active EoE handler,
there must be a cyclic process. The easiest solution would be to execute the EoE
state machines synchronously with the master state machine (see section 5.3). This
approach has the following disadvantage:
Only one EoE fragment could be sent or received every few cycles. This causes the
data rate to be very low, because the EoE state machines are not executed in the
time between the application cycles. Moreover, the data rate would be dependent on
the period of the application task.
To overcome this problem, an own cyclic process is needed to asynchronously execute
the EoE state machines. For that, the master owns a kernel timer, that is executed
each timer interrupt. This guarantees a constant bandwidth, but poses the new
problem of concurrent access to the master. The locking mechanisms needed for this
are introduced in section 3.4.
SDO Download State Machine The best time to apply SDO configurations is
during the slave’s PREOP state, because mailbox communication is already possible
and slave’s application will start with updating input data in the succeeding SAFEOP
state. Therefore the SDO configuration has to be part of the slave configuration state
machine (see section 5.5): It is implemented via an SDO download state machine, that
is executed just before entering the slave’s SAFEOP state. In this way, it is guaranteed
that the SDO configurations are applied each time, the slave is reconfigured.
The transition diagram of the SDO Download state machine can be seen in Figure 6.2.
START The beginning state of the CoE download state machine. The “SDO Down-
load Normal Request” mailbox command is sent. → REQUEST
REQUEST It is checked, if the CoE download request has been received by the
slave. After that, a mailbox check command is issued and a timer is started.
→ CHECK
50 –revision–, 2022/09/05
6.2 CANopen over EtherCAT (CoE)
ERROR END
–revision–, 2022/09/05 51
6 Mailbox Protocol Implementations
52 –revision–, 2022/09/05
7 Userspace Interfaces
For the master runs as a kernel module, accessing it is natively limited to analyzing
Syslog messages and controlling using modutils.
It was necessary to implement further interfaces, that make it easier to access the
master from userspace and allow a finer influence. It should be possible to view and
to change special parameters at runtime.
Bus visualization is another point: For development and debugging purposes it is
necessary to show the connected slaves with a single command, for instance (see
section 7.1).
The application interface has to be available in userspace, to allow userspace programs
to use EtherCAT master functionality. This was implemented via a character device
and a userspace library (see section 7.2).
Another aspect is automatic startup and configuration. The master must be able to
automatically start up with a persistent configuration (see section 7.4).
A last thing is monitoring EtherCAT communication. For debugging purposes, there
had to be a way to analyze EtherCAT datagrams. The best way would be with a
popular network analyzer, like Wireshark [8] or others (see section 7.5).
This chapter covers all these points and introduces the interfaces and tools to make
all that possible.
Each master instance will get a character device as a userspace interface. The devices
are named /dev/EtherCATx, where x ∈ {0 . . . n} is the index of the master.
Device Node Creation The character device nodes are automatically created, if the
udev Package is installed. See section 9.5 for how to install and configure it.
–revision–, 2022/09/05 53
7 Userspace Interfaces
Arguments :
ALIAS must be an unsigned 16 bit number . Zero means
removing an alias address .
Configuration selection :
Slave configurations can be selected with
54 –revision–, 2022/09/05
7.1 Command-line Tool
ethercat crc
ethercat crc reset
–revision–, 2022/09/05 55
7 Userspace Interfaces
Arguments :
LEVEL can have one of the following values :
0 for no debugging output ,
1 for some debug messages , or
2 for printing all frame contents ( use with caution !) .
56 –revision–, 2022/09/05
7.1 Command-line Tool
ethercat download [ OPTIONS ] < INDEX > < SUBINDEX > < VALUE >
[ OPTIONS ] < INDEX > < VALUE >
The data type of the SDO entry is taken from the SDO
dictionary by default . It can be overridden with the
-- type option . If the slave does not support the SDO
information service or the SDO is not in the dictionary ,
the -- type option is mandatory .
The second call ( without < SUBINDEX >) uses the complete
access method .
Arguments :
INDEX is the SDO index and must be an unsigned
–revision–, 2022/09/05 57
7 Userspace Interfaces
16 bit number .
SUBINDEX is the SDO entry subindex and must be an
unsigned 8 bit number .
VALUE is the value to download and must correspond
to the SDO entry datatype ( see above ) . Use
’-’ to read from standard input .
The data type of the SDO entry is taken from the SDO
dictionary by default . It can be overridden with the
-- type option . If the slave does not support the SDO
information service or the SDO is not in the dictionary ,
the -- type option is mandatory .
Arguments :
INDEX is the SDO index and must be an unsigned
16 bit number .
SUBINDEX is the SDO entry subindex and must be an
unsigned 8 bit number .
58 –revision–, 2022/09/05
7.1 Command-line Tool
ethercat eoe
Arguments :
SOURCEFILE is the name of the source file on the slave .
Arguments :
FILENAME can either be a path to a file , or ’ - ’. In
the latter case , data are read from stdin and
the -- output - file option has to be specified .
–revision–, 2022/09/05 59
7 Userspace Interfaces
60 –revision–, 2022/09/05
7.1 Command-line Tool
Arguments :
ADDRESS is the register address . Must
be an unsigned 16 bit number .
SIZE is the number of bytes to read and must also be
an unsigned 16 bit number . ADDRESS plus SIZE
may not exceed 64 k . The size is ignored ( and
can be omitted ) , if a selected data type
implies a size .
–revision–, 2022/09/05 61
7 Userspace Interfaces
Arguments :
ADDRESS is the register address to write to .
DATA depends on whether a datatype was specified
with the -- type option : If not , DATA must be
either a path to a file with data to write ,
or ’-’, which means , that data are read from
stdin . If a datatype was specified , VALUE is
interpreted respective to the given type .
62 –revision–, 2022/09/05
7.1 Command-line Tool
ethercat rescan
–revision–, 2022/09/05 63
7 Userspace Interfaces
• The format of the SII data is still in development and categories can be added
in the future. With read and write access, the complete memory contents can
be easily backed up and restored.
• Some SII data fields have to be altered (like the alias address). A quick writing
must be possible for that.
• Through reading access, analyzing category data is possible from userspace.
Reading out SII data is as easy as other commands. Though the data are in binary
format, analysis is easier with a tool like hexdump:
To download SII contents to a slave, writing access to the master’s character device
is necessary (see subsection 7.1.1).
ethercat sii_write [ OPTIONS ] < FILENAME >
64 –revision–, 2022/09/05
7.1 Command-line Tool
Arguments :
FILENAME must be a path to a file that contains a
positive number of words . If it is ’-’,
data are read from stdin .
The SII contents will be checked for validity and then sent to the slave. The write
operation may take a few seconds.
–revision–, 2022/09/05 65
7 Userspace Interfaces
Slave selection :
Slaves for this and other commands can be selected with
the -- alias and -- position parameters as follows :
$ ethercat slaves
0 0:0 PREOP + EK1100 Ethernet Kopplerklemme (2 A E - Bus )
1 5555:0 PREOP + EL3162 2 K . Ana . Eingang 0 -10 V
2 5555:1 PREOP + EL4102 2 K . Ana . Ausgang 0 -10 V
3 5555:2 PREOP + EL2004 4 K . Dig . Ausgang 24 V , 0 ,5 A
Arguments :
DRIVE is the drive number (0 - 7) . If omitted , 0 is assumed .
IDN is the IDN and must be either an unsigned
66 –revision–, 2022/09/05
7.1 Command-line Tool
Arguments :
DRIVE is the drive number (0 - 7) . If omitted , 0 is assumed .
IDN is the IDN and must be either an unsigned
16 bit number acc . to IEC 61800 -7 -204:
Bit 15: (0) Standard data , (1) Product data
Bit 14 - 12: Parameter set (0 - 7)
Bit 11 - 0: Data block number
or a string like ’P -0 -150 ’.
VALUE is the value to write ( see below ) .
–revision–, 2022/09/05 67
7 Userspace Interfaces
Arguments :
STATE can be ’ INIT ’ , ’ PREOP ’ , ’ BOOT ’ , ’ SAFEOP ’ , or ’OP ’.
68 –revision–, 2022/09/05
7.2 Userspace Library
if (! master )
return 1; // error
The program can be compiled and dynamically linked to the library with the below
command:
–revision–, 2022/09/05 69
7 Userspace Interfaces
7.2.2 Implementation
Basically the kernel API was transferred into userspace via the master character device
(see chapter 2, Figure 2.1 and subsection 7.1.1).
The function calls of the kernel API are mapped to the userspace via an ioctl()
interface. The userspace API functions share a set of generic ioctl() calls. The
kernel part of the interface calls the according API functions directly, what results in
a minimum additional delay (see subsection 7.2.3).
For performance reasons, the actual domain process data (see section 2.3) are not
copied between kernel and user memory on every access: Instead, the data are
memory-mapped to the userspace application. Once the master is configured and
activated, the master module creates one process data memory area spanning all
domains and maps it to userspace, so that the application can directly access the
process data. As a result, there is no additional delay when accessing process data
from userspace.
7.2.3 Timing
An interesting aspect is the timing of the userspace library calls compared to those of
the kernel API. Table 7.1 shows the call times and standard deviancies of typical (and
time-critical) API functions measured on an Intel Pentium 4 M CPU with 2.2 GHz
and a standard 2.6.26 kernel.
The test results show, that for this configuration, the userspace API causes about
1 µs additional delay for each function, compared to the kernel API.
70 –revision–, 2022/09/05
7.4 System Integration
To accomplish this, the Real-Time Device Model (RTDM) [17] has been developed.
The master module provides an RTDM interface (see Figure 2.1) in addition to the
normal character device, if the master sources were configured with --enable-rtdm
(see chapter 9).
To force an application to use the RTDM interface instead of the normal character
device, it has to be linked with the libethercat rtdm library instead of libethercat. The
use of the libethercat rtdm is transparent, so the EtherCAT header ecrt.h with the
complete API can be used as usual.
To make the example in Listing 7.1 use the RTDM library, the linker command has
to be altered as follows:
–revision–, 2022/09/05 71
7 Userspace Interfaces
#------------------------------------------------------------------------
72 –revision–, 2022/09/05
7.4 System Integration
37 # Except for the generic Ethernet driver module , the init script will try to
38 # unload the usual Ethernet driver modules in the list and replace them with
39 # the EtherCAT - capable ones . If a certain ( EtherCAT - capable ) driver is not
40 # found , a warning will appear .
41 #
42 # Possible values : 8139 too , e100 , e1000 , e1000e , r8169 , generic , ccat , igb .
43 # Separate multiple drivers with spaces .
44 #
45 # Note : The e100 , e1000 , e1000e , r8169 , ccat and igb drivers are not built by
46 # default . Enable them with the -- enable - < driver > configure switches .
47 #
48 # Attention : When using the generic driver , the corresponding Ethernet device
49 # has to be activated ( with OS methods , for example ’ ip link set ethX up ’) ,
50 # before the master is started , otherwise all frames will time out .
51 #
52 DEVI CE_MODUL ES =""
53
54 #
55 # Flags for loading kernel modules .
56 #
57 # This can usually be left empty . Adjust this variable , if you have problems
58 # with module loading .
59 #
60 # MO DPROBE_F LAGS =" - b "
61
62 #------------------------------------------------------------------------------
For systems managed by systemd (see subsection 7.4.4), the sysconfig file has moved
to /etc/ethercat.conf. Both versions are part of the master sources and are meant
to used alternatively.
# insserv ethercat
The init script can also be used for manually starting and stopping the EtherCAT
master. It has to be executed with one of the parameters start, stop, restart or
status.
# /etc/init.d/ethercat restart
Shutting down EtherCAT master done
Starting EtherCAT master done
–revision–, 2022/09/05 73
7 Userspace Interfaces
[ Unit ]
Description = EtherCAT Master Kernel Modules
#
# Uncomment this , if the generic Ethernet driver is used . It assures ,
that the
# network interfaces are configured , before the master starts .
#
# Requires = network . service # Stop master , if network is stopped
# After = network . service # Start master , after network is ready
#
# Uncomment this , if a native Ethernet driver is used . It assures ,
that the
# network interfaces are configured , after the Ethernet drivers have
been
# replaced . Otherwise , the networking configuration tools could be
confused .
#
# Before = network . service
[ Service ]
Type = oneshot
RemainAfterExit = yes
ExecStart =/ usr / local / sbin / ethercatctl start
ExecStop =/ usr / local / sbin / ethercatctl stop
[ Install ]
WantedBy = multi - user . target
The ethercatctl command is used to load and unload the master and network driver
modules in a similar way to the former init script (subsection 7.4.1). Because it is
installed into the sbin/ directory, it can also be used separately:
# ethercatctl start
When using systemd and/or the ethercatctl command, the master configuration must
be in /etc/ethercat.conf instead of /etc/sysconfig/ethercat! The latter is ig-
nored. The configuration options are exactly the same.
74 –revision–, 2022/09/05
7.5 Debug Interfaces
for example. It is also possible to listen to local network interfaces on the machine
running the EtherCAT master directly. If the generic Ethernet driver (see section 4.3)
is used, the network monitor can directly listen on the network interface connected to
the EtherCAT bus.
When using native Ethernet drivers (see section 4.2), there are no local network inter-
faces to listen to, because the Ethernet devices used for EtherCAT are not registered
at the network stack. For that case, so-called “debug interfaces” are supported, which
are virtual network interfaces allowing to capture EtherCAT traffic with a network
monitor (like Wireshark or tcpdump) running on the master machine without using
external hardware. To use this functionality, the master sources have to be configured
with the --enable-debug-if switch (see chapter 9).
Every EtherCAT master registers a read-only network interface per attached physical
Ethernet device. The network interfaces are named ecdbgmX for the main device, and
ecdbgbX for the backup device, where X is the master index. The below listing shows
a debug interface among some standard network interfaces:
# ip link
1: lo : < LOOPBACK , UP > mtu 16436 qdisc noqueue
link / loopback 00 :00:00 :00:00 :00 brd 00 :00:00 :00:00 :00
4: eth0 : < BROADCAST , MULTICAST > mtu 1500 qdisc noop qlen 1000
link / ether 00:13:46:3 b : ad : d7 brd ff : ff : ff : ff : ff : ff
8: ecdbgm0 : < BROADCAST , MULTICAST > mtu 1500 qdisc pfifo_fast
qlen 1000
link / ether 00:04:61:03: d1 :01 brd ff : ff : ff : ff : ff : ff
While a debug interface is enabled, all frames sent or received to or from the physical
device are additionally forwarded to the debug interface by the corresponding master.
Network interfaces can be enabled with the below command:
Please note, that the frame rate can be very high. With an application connected,
the debug interface can produce thousands of frames per second.
Attention The socket buffers needed for the operation of debug interfaces have to
be allocated dynamically. Some Linux realtime extensions (like RTAI) do not allow
this in realtime context!
–revision–, 2022/09/05 75
7 Userspace Interfaces
76 –revision–, 2022/09/05
8 Timing Aspects
Although EtherCAT’s timing is highly deterministic and therefore timing issues are
rare, there are a few aspects that can (and should be) dealt with.
c0 = get_cycles () ;
ecrt_maste r_ r e ce i v e ( master ) ;
c1 = get_cycles () ;
ecrt_domai n_ p r oc e s s ( domain1 ) ;
c2 = get_cycles () ;
ecrt_master_run ( master ) ;
c3 = get_cycles () ;
ecrt_master_send ( master ) ;
c4 = get_cycles () ;
Between each call of an interface function, the CPU timestamp counter is read. The
counter differences are converted to µs with help of the cpu_khz variable, that contains
the number of increments per ms.
For the actual measuring, a system with a 2.0 GHz CPU was used, that ran the above
code in an RTAI thread with a period of 100 µs. The measuring was repeated n = 100
times and the results were averaged. These can be seen in Table 8.1.
–revision–, 2022/09/05 77
8 Timing Aspects
It is obvious, that the functions accessing hardware make up the lion’s share. The
ec master receive() executes the ISR of the Ethernet device, analyzes datagrams and
copies their contents into the memory of the datagram objects. The ec master send()
assembles a frame out of different datagrams and copies it to the hardware buffers.
Interestingly, this makes up only a quarter of the receiving time.
The functions that only operate on the masters internal data structures are very
fast (∆t < 1 µs). Interestingly the runtime of ec domain process() has a small stan-
dard deviancy relative to the mean value, while this ratio is about twice as big for
ec master run(): This probably results from the latter function having to execute
code depending on the current state and the different state functions are more or less
complex.
For a realtime cycle makes up about 10 µs, the theoretical frequency can be up to
100 kHz. For two reasons, this frequency keeps being theoretical:
1. The processor must still be able to run the operating system between the real-
time cycles.
2. The EtherCAT frame must be sent and received, before the next realtime cycle
begins. The determination of the bus cycle time is difficult and covered in
section 8.2.
78 –revision–, 2022/09/05
8.2 Bus Cycle Measuring
same as in the last cycle, because it is not erased by the domain. When the domain
datagrams are queued again, the master notices, that they are already queued (and
marked as sent). The master will mark them as unsent again and output a warning,
that datagrams were “skipped”.
On the mentioned 2.0 GHz system, the possible cycle frequency can be up to 25 kHz
without skipped frames. This value can surely be increased by choosing faster hard-
ware. Especially the RealTek network hardware could be replaced by a faster one.
Besides, implementing a dedicated ISR for EtherCAT devices would also contribute
to increasing the latency. These are two points on the author’s to-do list.
–revision–, 2022/09/05 79
8 Timing Aspects
80 –revision–, 2022/09/05
9 Installation
1. An official release (for example 1.5.2), can be downloaded from the master’s
website1 at the EtherLab project [1] as a tarball.
2. The most recent development revision (and moreover any other revision) can
be obtained via the Git [14] repository on the master’s project page on Git-
Lab.com2 . The whole repository can be cloned with the command
git clone https :// gitlab . com / etherlab . org / ethercat . git
local-dir
The software configuration is managed with Autoconf [15] so the released versions
contain a configure shell script, that has to be executed for configuration (see below).
Bootstrap When downloading or cloning directly from the repository, the configure
script does not yet exist. It can be created via the bootstrap.sh script in the master
sources. The autoconf and automake packages are required for this.
1
http://etherlab.org/en/ethercat/index.php
2
https://gitlab.com/etherlab.org/ethercat
–revision–, 2022/09/05 81
9 Installation
Configuration and Build The configuration and the build process follow the below
commands:
$ ./configure
$ make
$ make modules
82 –revision–, 2022/09/05
9.3 Building the Interface Documentation
† If this option is not specified, the kernel version to use is extracted from the Linux
kernel sources.
The source code is documented using Doxygen [13]. To build the HTML documen-
tation, the Doxygen software has to be installed. The below command will generate
the documents in the subdirectory doxygen-output:
$ make doc
The interface documentation can be viewed by pointing a browser to the file doxygen-
output/html/index.html. The functions and data structures of the application interface
are covered by an own module “Application Interface”.
–revision–, 2022/09/05 83
9 Installation
# make install
# make modules install
If the target kernel’s modules directory is not under /lib/modules, a different destina-
tion directory can be specified with the DESTDIR make variable. For example:
# cd /opt/etherlab
# cp etc/sysconfig/ethercat /etc/sysconfig/
# ln -s etc/init.d/ethercat /etc/init.d/
# insserv ethercat
Now the sysconfig file /etc/sysconfig/ethercat (see subsection 7.4.2), or the con-
figuration file /etc/ethercat.conf, if using systemd, has to be customized. The minimal
customization is to set the MASTER0_DEVICE variable to the MAC address of the Ether-
net device to use (or ff:ff:ff:ff:ff:ff to use the first device offered) and selecting
the driver(s) to load via the DEVICE_MODULES variable.
After the basic configuration is done, the master can be started with the below com-
mand:
# /etc/init.d/ethercat start
# ethercatctl start
At this time, the operation of the master can be observed by viewing the Syslog
messages, which should look like the ones below. If EtherCAT slaves are connected
to the master’s EtherCAT device, the activity indicators should begin to flash.
3
Even if the EtherCAT master shall not be loaded on system startup, the use of the init script is
recommended for manual (un-)loading.
84 –revision–, 2022/09/05
9.5 Automatic Device Node Creation
1 –
2 The master module is loading, and one master is initialized.
3 –
8 The EtherCAT-capable e1000 driver is loading. The master accepts the de-
vice with the address 00:0E:0C:DA:A2:20.
9 –
16 The master goes to idle phase, starts its state machine and begins scanning
the bus.
After the udev rule file is created and the EtherCAT master is restarted with /etc
/init.d/ethercat restart, the device node will be automatically created with the
desired rights:
# ls -l /dev/EtherCAT0
crw - rw -r - - 1 root root 252 , 0 2008 -09 -03 16:19 / dev / EtherCAT0
–revision–, 2022/09/05 85
9 Installation
Now, the ethercat tool can be used (see section 7.1) even as a non-root user.
If non-root users shall have writing access, the following udev rule can be used instead:
KERNEL ==" EtherCAT [0 -9]*" , MODE ="0664" , GROUP =" users "
86 –revision–, 2022/09/05
Bibliography
[1] Ingenieurgemeinschaft IgH: EtherLab – Open Source Toolkit for rapid realtime
code generation under Linux with Simulink/RTW and EtherCAT technology.
http://etherlab.org/en, 2008.
[2] IEC 61158-4-12: Data-link Protocol Specification. International Electrotechnical
Commission (IEC), 2005.
[3] IEC 61158-6-12: Application Layer Protocol Specification. International Elec-
trotechnical Commission (IEC), 2005.
[4] GNU General Public License, Version 2. http://www.gnu.org/licenses/
gpl-2.0.html. October 15, 2008.
[5] GNU Lesser General Public License, Version 2.1. http://www.gnu.org/
licenses/old-licenses/lgpl-2.1.html. October 15, 2008.
[6] Linux Standard Base. http://www.linuxfoundation.org/en/LSB. August 9,
2006.
[7] systemd System and Service Manager http://freedesktop.org/wiki/
Software/systemd. January 18, 2013.
[8] Wireshark. http://www.wireshark.org. 2008.
[9] Hopcroft, J. E. / Ullman, J. D.: Introduction to Automata Theory, Languages
and Computation. Adison-Wesley, Reading, Mass. 1979.
[10] Wagner, F. / Wolstenholme, P.: State machine misunderstandings. In: IEE
journal “Computing and Control Engineering”, 2004.
[11] RTAI. The RealTime Application Interface for Linux from DIAPM. https://
www.rtai.org, 2010.
[12] RT PREEMPT HOWTO. http://rt.wiki.kernel.org/index.php/RT_
PREEMPT_HOWTO, 2010.
[13] Doxygen. Source code documentation generator tool. http://www.stack.nl/
~dimitri/doxygen, 2008.
[14] Git SCM. https://git-scm.com, 2021.
[15] Autoconf – GNU Project – Free Software Foundation (FSF). http://www.gnu.
org/software/autoconf, 2010.
[16] IEC 61800-7-304: Adjustable speed electrical power drive systems - Part 7-300:
Generic interface and use of profiles for power drive systems - Mapping of profiles
to network technologies. International Electrotechnical Commission (IEC), 2007.
[17] J. Kiszka: The Real-Time Driver Model and First Applications.
http://svn.gna.org/svn/xenomai/tags/v2.4.0/doc/nodist/pdf/
RTDM-and-Applications.pdf, 2013.
–revision–, 2022/09/05 87
Bibliography
88 –revision–, 2022/09/05
Glossary
ADEOS Adaptive Domain Environment for Operating Systems, page 1
CoE CANopen over EtherCAT, Mailbox Protocol, page 50
ecdev EtherCAT Device, page 29
EoE Ethernet over EtherCAT, Mailbox Protocol, page 47
FSM Finite State Machine, page 31
ISR Interrupt Service Routine, page 24
LSB Linux Standard Base, page 3
PCI Peripheral Component Interconnect, Computer Bus, page 26
RTAI Realtime Application Interface, page 1
–revision–, 2022/09/05 89
Glossary
90 –revision–, 2022/09/05
Index
LGPL, 3
LSB, 71
–revision–, 2022/09/05 91