EtherCAT support consists of 4 components
1) OPTIONAL Realtime Linux Kernel
2) Etherlab device driver
3) Scanner
4) Simulation
5) IOCs

1) Realtime Linux
PREEMPT-RT RHEL5 built from RedHat SRPMS

2) Etherlab device driver 

etherlab.org kernel driver provided by the RPM ec_master-1.5-1dkms
$SVN_ROOT/diamond/trunk/targetOS/drivers/ethercat

You will need a working build environment (autoconf, gcc and make) to install this RPM
as it uses DKMS and compiles against your Kernel at install time (or reboot)

Your network card will need an IP address otherwise the link will not come up.
eg. /sbin/ifconfig eth1 192.168.0.1 
It may be possible to make the link come up without assigning an IP address on some machines.

This creates /dev/EtherCAT0 and the "ethercat" service:

[jr76@pc0053 driver]$ ls -l /dev/EtherCAT0 
crw-rw-rw- 1 root root 253, 0 May 16 15:37 /dev/EtherCAT0

[jr76@pc0053 docs]$ /sbin/service ethercat status
Checking for EtherCAT master devel 
Master0  running

The "ethercat" service needs to know which network card to use, the
configuration file is stored in the "init" dls svn area under the 
short hostname (hostname -s)

[jr76@pc0053 docs]$ cat /dls_sw/prod/etc/init/$(hostname -s)/ethercat
MASTER0_DEVICE="00:0E:0C:BC:28:91"
DEVICE_MODULES="generic"

The userspace API for the etherlab master is release as a DLS tool.
It can scan the bus and display slave information:

$ ethercat slaves
0  0:0  OP  +  NI 9144

$ which ethercat
/dls_sw/prod/tools/RHEL6-x86_64/defaults/bin/ethercat

There is also a diagnostics tool called "slaveinfo" that is built into the bin directory
of the ethercat support module. It generates a template builder xml which includes device
names and revision numbers (see below):

3) Scanner

The Etherlab device driver is responsible for configuring the devices on the bus
and formatting EtherCAT packets but it does not contain the timer required to
perform bus data cycles! This is because it is designed to work with a variety of
realtime Linuxes that use timers in different ways. The Scanner is a server using
the device driver's userspace API that performs bus cycles and multiplexes client
access (to multiple IOCs or diagnostics tools)

The scanner is built into the "bin" directory from ethercatApp/scannerSrc

The scanner requires a configuration file containing a list of devices on the bus
and their parameters:

[jr76@pc0053 docs]$ less ../iocs/scanTest/etc/chain.xml 
<chain>
<device type_name="EK1101" revision="0x00110000" position="0" name="COUPLER0" />
<device type_name="EL1004" revision="0x00100000" position="1" name="VACUUM0" />
<device type_name="EL3702" revision="0x00020000" position="2" name="RF0" oversample="11" />
<device type_name="EL2004" revision="0x00100000" position="3" name="OUT0" />
</chain>

The "name" field is used later in the IOC to give each EtherCAT device an ASYN port name.

The revision numbers can be read from the devices using the "ethercat" command line tool:

/dls_sw/work/common/rt/ethercat/bin/ethercat slaves -v | less

=== Master 0, Slave 0 ===
State: OP
Flag: +
Identity:
  Vendor Id:       0x00000002
  Product code:    0x044d2c52
  Revision number: 0x00110000
  Serial number:   0x00000000...

The script etc/scripts/expandChain.py is used to expand this configuration file using the
XML description of each EtherCAT device stored in etc/xml

[jr76@pc0053 docs]$ ls ../etc/xml/
Beckhoff AX2xxx.xml  Beckhoff EL37xx.xml  Beckhoff ELx9xx.xml  Beckhoff EP6xxx.xml              EtherCATDict.xsd
Beckhoff BKxxxx.xml  Beckhoff EL3xxx.xml  Beckhoff EM2xxx.xml  Beckhoff EP7xxx.xml              EtherCATInfo.xsd
Beckhoff EKxxxx.xml  Beckhoff EL47xx.xml  Beckhoff EM7xxx.xml  Beckhoff EtherCAT EvaBoard.xml   EtherCATModule.xsd
Beckhoff EL15xx.xml  Beckhoff EL4xxx.xml  Beckhoff EP1xxx.xml  Beckhoff EtherCAT Terminals.xml  NI9144-three.xml
Beckhoff EL1xxx.xml  Beckhoff EL5xxx.xml  Beckhoff EP2xxx.xml  Beckhoff FB1XXX.xml              Ni9144-two.xml
Beckhoff EL2xxx.xml  Beckhoff EL6xxx.xml  Beckhoff EP3xxx.xml  Beckhoff FCxxxx.xml              SMC EX250-SEN1-X156.xml
Beckhoff EL30xx.xml  Beckhoff EL7xxx.xml  Beckhoff EP4xxx.xml  BKxxxx (MDP)
Beckhoff EL31xx.xml  Beckhoff EL9xxx.xml  Beckhoff EP5xxx.xml  EtherCATBase.xsd

These XML files contain the list of named registers that each device supports. Theoretically this
information is also stored in a PROM in each device for auto-discovery but the etherlab master
does not support this fully and some devices (NI) may not provide the information.

4) Simulation

The scanner supports a simulation mode with the '-s' command switch.
The configuration file supports extra elements to specify the simulated
signals as in the example below.

[rjq35657@pc0074 ethercat]$ cat iocs/diagnosticsTest/etc/diagnostics-test-chain.xml 
<chain>
<device type_name="EK1100" revision="0x00110000" position="0" name="COUPLER0" />
<device type_name="EL3104" revision="0x00100000" position="1" name="AI1" >
    <simulation signal_no="1" bit_length="16"
            signal_type="sine_wave" low_value="-32768" high_value="32767" period_ms="10000" />
    <simulation signal_no="2" bit_length="16" 
            signal_type="ramp" low_value="-32768" high_value="32767" period_ms="10000" symmetry="100"/>
    <simulation signal_no="3" bit_length="16" signal_type="constant" value="20000" />
</device>
</chain>

The allocation follows the parameter "signal_no" combined with "bit_length",
thus there's several signals with signal_no "1" depending on the signal bit-lengths.

The supported types are "sine_wave", "ramp", "square_wave" and "constant".
The limits for low_value and high_value are:
bit_length .....  low_value ... high_value
1-bit                   0         1
8-bit                   0         255
16-bit             -32768         32767
24-bit           -8388608         8388607


5) IOCs

IOCs connect to the scanner using a unix domain socket. The configuration information is first
sent over the socket and the ASYN ports are created. Then the Scanner distributes the 
EtherCAT process data to each connected IOC every bus cycle (1ms). The IOCs use the configuration
information to unpack the registers from the process data message and write ASYN parameters.
Writes are send back over the socket to the Scanner which merges them into the process data to be
sent next bus cycle.

EXAMPLE
=======

iocs/scanTest

The etc directory contains the above chain configuration. The Makefile builds the scanner.xml from that.
First run the scanner in one terminal from etc:

../../../bin/linux-x86/scanner scanner.xml

Then start the ioc:

./st.cmd

The IOC instantiates default templates for each bus device and adds ADC support to one oversampling ADC channel.
