documentation/ethercat_doc.tex
changeset 1202 91d190223daa
parent 1140 cc779f7d2496
child 1203 acb649738601
equal deleted inserted replaced
1201:732281184c54 1202:91d190223daa
     2 %
     2 %
     3 %  IgH EtherCAT Master Documentation
     3 %  IgH EtherCAT Master Documentation
     4 %
     4 %
     5 %  $Id$
     5 %  $Id$
     6 %
     6 %
     7 %  vi: spell spelllang=en
     7 %  vi: spell spelllang=en tw=78
     8 % 
     8 % 
     9 %------------------------------------------------------------------------------
     9 %------------------------------------------------------------------------------
    10 
       
    11 %
       
    12 %   Conventions
       
    13 % The IgH EtherCAT Master
       
    14 %   Feature Summary
       
    15 %   License
       
    16 % Architecture
       
    17 %   Phases
       
    18 %   Behavior (Scanning) TODO
       
    19 % Application Interface
       
    20 %   Interface version
       
    21 %   Master Requesting and Releasing
       
    22 %   Master Locking
       
    23 %   Slave configuration
       
    24 %   Configuring Pdo assignment and mapping
       
    25 %   Domains (memory)
       
    26 %   Pdo entry registration
       
    27 %   Sdo configuration
       
    28 %   Sdo access
       
    29 %   Cyclic operation
       
    30 % Ethernet Devices
       
    31 %   Device Interface
       
    32 %   Device Modules
       
    33 %   Network Driver Basics
       
    34 %   EtherCAT Network Drivers
       
    35 %   Device Selection
       
    36 %   The Device Interface
       
    37 %   Patching Network Drivers
       
    38 % The Master's State Machines
       
    39 %   Master
       
    40 %   Slave scanning
       
    41 %     SII
       
    42 %     Pdo assign/mapping
       
    43 %   Slave configuration
       
    44 %     State change
       
    45 %     Pdo assign/mapping
       
    46 %   CoE upload/download/information
       
    47 % Mailbox Protocol Implementations
       
    48 %     Ethernet-over-EtherCAT (EoE)
       
    49 %     CANopen-over-EtherCAT (CoE)
       
    50 % User Space
       
    51 %     The ethercat command
       
    52 %     System Integration
       
    53 %         The EtherCAT Init Script
       
    54 %         The EtherCAT Sysconfig File
       
    55 %     Monitoring and Debugging
       
    56 % Installation
       
    57 % Example applications
       
    58 % Bibliography
       
    59 % Glossary
       
    60 %
       
    61 
    10 
    62 \documentclass[a4paper,12pt,BCOR6mm,bibtotoc,idxtotoc]{scrbook}
    11 \documentclass[a4paper,12pt,BCOR6mm,bibtotoc,idxtotoc]{scrbook}
    63 
    12 
    64 \usepackage[latin1]{inputenc}
    13 \usepackage[latin1]{inputenc}
    65 \usepackage[automark,headsepline]{scrpage2}
    14 \usepackage[automark,headsepline]{scrpage2}
   441 
   390 
   442 \end{description}
   391 \end{description}
   443 
   392 
   444 %------------------------------------------------------------------------------
   393 %------------------------------------------------------------------------------
   445 
   394 
   446 \section{General behavior} % FIXME
   395 \section{General Behavior} % FIXME
   447 \index{Master behavior}
   396 \index{Master behavior}
   448 
   397 
   449 \ldots
   398 \ldots
   450 
   399 
       
   400 %   Behavior (Scanning) TODO
       
   401 
   451 %------------------------------------------------------------------------------
   402 %------------------------------------------------------------------------------
   452 
   403 
   453 \section{Master Module}
   404 \section{Master Module}
   454 \label{sec:mastermodule}
   405 \label{sec:mastermod}
   455 \index{Master module}
   406 \index{Master module}
   456 
   407 
   457 The EtherCAT master kernel module \textit{ec\_master} can contain multiple
   408 The EtherCAT master kernel module \textit{ec\_master} can contain multiple
   458 master instances. Each master waits for a certain Ethernet device identified
   409 master instances. Each master waits for a certain Ethernet device identified
   459 by its MAC address\index{MAC address}. These addresses have to be specified on
   410 by its MAC address\index{MAC address}. These addresses have to be specified on
   607 
   558 
   608 \chapter{Application Interface}
   559 \chapter{Application Interface}
   609 \label{sec:ecrt}
   560 \label{sec:ecrt}
   610 \index{Application interface}
   561 \index{Application interface}
   611 
   562 
       
   563 %   Interface version
       
   564 %   Master Requesting and Releasing
       
   565 %   Master Locking
       
   566 %   Slave configuration
       
   567 %   Configuring Pdo assignment and mapping
       
   568 %   Domains (memory)
       
   569 %   Pdo entry registration
       
   570 %   Sdo configuration
       
   571 %   Sdo access
       
   572 %   Cyclic operation
       
   573 
   612 The application interface provides functions and data structures for
   574 The application interface provides functions and data structures for
   613 applications to access and use an EtherCAT master. The complete documentation
   575 applications to access and use an EtherCAT master. The complete documentation
   614 of the interface is included as Doxygen~\cite{doxygen} comments in the header
   576 of the interface is included as Doxygen~\cite{doxygen} comments in the header
   615 file \textit{include/ecrt.h}. You can either directly view the file comments
   577 file \textit{include/ecrt.h}. You can either directly view the file comments
   616 or generate an HTML documentation as described in section~\ref{sec:gendoc}.
   578 or generate an HTML documentation as described in section~\ref{sec:gendoc}.
   666 section~\ref{sec:eoeimp}). For this reason, the master is a shared resource,
   628 section~\ref{sec:eoeimp}). For this reason, the master is a shared resource,
   667 and access to it has to be sequentialized. This is usually done by locking with
   629 and access to it has to be sequentialized. This is usually done by locking with
   668 semaphores, or other methods to protect critical sections.
   630 semaphores, or other methods to protect critical sections.
   669 
   631 
   670 The master itself can not provide locking mechanisms, because it has no chance
   632 The master itself can not provide locking mechanisms, because it has no chance
   671 to know the appropriate kind of lock. Imagine, the application uses RTAI
   633 to know the appropriate kind of lock. For example if the application uses RTAI
   672 functionality, then ordinary kernel semaphores would not be sufficient. For
   634 functionality, ordinary kernel semaphores would not be sufficient. For that, an
   673 that, an important design decision was made: The application that reserved a
   635 important design decision was made: The application that reserved a master must
   674 master must have the total control, therefore it has to take responsibility for
   636 have the total control, therefore it has to take responsibility for providing
   675 providing the appropriate locking mechanisms. If another instance wants to
   637 the appropriate locking mechanisms. If another instance wants to access the
   676 access the master, it has to request the master lock by callbacks, that have to
   638 master, it has to request the master lock by callbacks, that have to be set by
   677 be set by the application. Moreover the application can deny access to the
   639 the application. Moreover the application can deny access to the master if it
   678 master if it considers it to be awkward at the moment.
   640 considers it to be awkward at the moment.
   679 
   641 
   680 \begin{figure}[htbp]
   642 \begin{figure}[htbp]
   681   \centering
   643   \centering
   682   \includegraphics[width=.6\textwidth]{images/master-locks}
   644   \includegraphics[width=.6\textwidth]{images/master-locks}
   683   \caption{Concurrent master access}
   645   \caption{Concurrent master access}
   691 access the lock natively, while the EoE process has to use the callbacks.
   653 access the lock natively, while the EoE process has to use the callbacks.
   692 Section~\ref{sec:concurrency} gives an example, of how to implement this.
   654 Section~\ref{sec:concurrency} gives an example, of how to implement this.
   693 
   655 
   694 %------------------------------------------------------------------------------
   656 %------------------------------------------------------------------------------
   695 
   657 
   696 \chapter{Ethernet devices}
   658 \chapter{Ethernet Devices}
   697 \label{sec:devices}
   659 \label{sec:devices}
   698 
   660 
   699 The EtherCAT protocol is based on the Ethernet standard. That's why the master
   661 %   Device Interface
   700 relies on standard Ethernet hardware to communicate with the bus.
   662 %   Device Modules
       
   663 %   Network Driver Basics
       
   664 %   EtherCAT Network Drivers
       
   665 %   Device Selection
       
   666 %   The Device Interface
       
   667 %   Patching Network Drivers
       
   668 
       
   669 The EtherCAT protocol is based on the Ethernet standard, so the master relies
       
   670 on standard Ethernet hardware to communicate with the bus.
   701 
   671 
   702 The term \textit{device} is used as a synonym for Ethernet network interface
   672 The term \textit{device} is used as a synonym for Ethernet network interface
   703 hardware. There are device driver modules that handle Ethernet hardware, which
   673 hardware. There are device driver modules that handle Ethernet hardware, which
   704 the master can use to connect to an EtherCAT bus.
   674 the master can use to connect to an EtherCAT bus.
   705 
   675 
   753 hardware interrupt), the reason for the interrupt has to be determined
   723 hardware interrupt), the reason for the interrupt has to be determined
   754 by reading the device's interrupt register. For example, if the flag
   724 by reading the device's interrupt register. For example, if the flag
   755 for received frames is set, frame data has to be copied from hardware
   725 for received frames is set, frame data has to be copied from hardware
   756 to kernel memory and passed to the network stack.
   726 to kernel memory and passed to the network stack.
   757 
   727 
   758 \paragraph{The net\_device structure}
   728 \paragraph{The \lstinline+net_device+ structure}
   759 \index{net\_device}
   729 \index{net\_device}
   760 
   730 
   761 The driver registers a \textit{net\_device} structure for each device
   731 The driver registers a \lstinline+net_device+ structure for each device to
   762 to communicate with the network stack and to create a ``network
   732 communicate with the network stack and to create a ``network interface''. In
   763 interface''. In case of an Ethernet driver, this interface appears as
   733 case of an Ethernet driver, this interface appears as \textit{ethX}, where X is
   764 \textit{ethX}, where X is a number assigned by the kernel on
   734 a number assigned by the kernel on registration. The \lstinline+net_device+
   765 registration. The \textit{net\_device} structure receives events
   735 structure receives events (either from user space or from the network stack)
   766 (either from user space or from the network stack) via several
   736 via several callbacks, which have to be set before registration. Not every
   767 callbacks, which have to be set before registration. Not every
   737 callback is mandatory, but for reasonable operation the ones below are needed
   768 callback is mandatory, but for reasonable operation the ones below are
   738 in any case:
   769 needed in any case:
   739 
       
   740 \newsavebox\boxopen
       
   741 \sbox\boxopen{\lstinline+open()+}
       
   742 \newsavebox\boxstop
       
   743 \sbox\boxstop{\lstinline+stop()+}
       
   744 \newsavebox\boxxmit
       
   745 \sbox\boxxmit{\lstinline+hard_start_xmit()+}
       
   746 \newsavebox\boxstats
       
   747 \sbox\boxstats{\lstinline+get_stats()+}
   770 
   748 
   771 \begin{description}
   749 \begin{description}
   772 
   750 
   773 \item[open()] This function is called when network communication has to be
   751 \item[\usebox\boxopen] This function is called when network communication has
   774 started, for example after a command \textit{ifconfig ethX up} from user
   752 to be started, for example after a command \lstinline+ip link set ethX up+ from
   775 space. Frame reception has to be enabled by the driver.
   753 user space. Frame reception has to be enabled by the driver.
   776 
   754 
   777 \item[stop()] The purpose of this callback is to ``close'' the device, i.~e.
   755 \item[\usebox\boxstop] The purpose of this callback is to ``close'' the device,
   778 make the hardware stop receiving frames.
   756 i.~e.  make the hardware stop receiving frames.
   779 
   757 
   780 \item[hard\_start\_xmit()] This function is cal\-led for each frame that has
   758 \item[\usebox\boxxmit] This function is called for each frame that has to be
   781 to be transmitted. The network stack passes the frame as a pointer to an
   759 transmitted. The network stack passes the frame as a pointer to an
   782 \textit{sk\_buff} structure (``socket buffer''\index{Socket buffer}, see
   760 \lstinline+sk_buff+ structure (``socket buffer''\index{Socket buffer}, see
   783 below), which has to be freed after sending.
   761 below), which has to be freed after sending.
   784 
   762 
   785 \item[get\_stats()] This call has to return a pointer to the device's
   763 \item[\usebox\boxstats] This call has to return a pointer to the device's
   786 \textit{net\_device\_stats} structure, which permanently has to be filled with
   764 \lstinline+net_device_stats+ structure, which permanently has to be filled with
   787 frame statistics. This means, that every time a frame is received, sent, or an
   765 frame statistics. This means, that every time a frame is received, sent, or an
   788 error happened, the appropriate counter in this structure has to be increased.
   766 error happened, the appropriate counter in this structure has to be increased.
   789 
   767 
   790 \end{description}
   768 \end{description}
   791 
   769 
   794 
   772 
   795 \paragraph{The netif Interface}
   773 \paragraph{The netif Interface}
   796 \index{netif}
   774 \index{netif}
   797 
   775 
   798 All other communication in the direction interface $\to$ network stack is done
   776 All other communication in the direction interface $\to$ network stack is done
   799 via the \lstinline+netif_*()+ calls. For example, on successful device
   777 via the \lstinline+netif_*()+ calls. For example, on successful device opening,
   800 opening, the network stack has to be notified, that it can now pass frames to
   778 the network stack has to be notified, that it can now pass frames to the
   801 the interface.  This is done by calling \lstinline+netif_start_queue()+. After
   779 interface. This is done by calling \lstinline+netif_start_queue()+. After this
   802 this call, the \lstinline+hard_start_xmit()+ callback can be called by the
   780 call, the \lstinline+hard_start_xmit()+ callback can be called by the network
   803 network stack.  Furthermore a network driver usually manages a frame
   781 stack. Furthermore a network driver usually manages a frame transmission queue.
   804 transmission queue. If this gets filled up, the network stack has to be told
   782 If this gets filled up, the network stack has to be told to stop passing
   805 to stop passing further frames for a while. This happens with a call to
   783 further frames for a while. This happens with a call to
   806 \lstinline+netif_stop_queue()+.  If some frames have been sent, and there is
   784 \lstinline+netif_stop_queue()+. If some frames have been sent, and there is
   807 enough space again to queue new frames, this can be notified with
   785 enough space again to queue new frames, this can be notified with
   808 \lstinline+netif_wake_queue()+. Another important call is
   786 \lstinline+netif_wake_queue()+. Another important call is
   809 \lstinline+netif_receive_skb()+\footnote{This function is part of the NAPI
   787 \lstinline+netif_receive_skb()+\footnote{This function is part of the NAPI
   810 (``New API''), that replaces the kernel 2.4 technique for interfacing to the
   788 (``New API''), that replaces the kernel 2.4 technique for interfacing to the
   811 network stack (with \lstinline+netif_rx()+). NAPI is a technique to improve
   789 network stack (with \lstinline+netif_rx()+). NAPI is a technique to improve
   812 network performance on Linux. Read more in
   790 network performance on Linux. Read more in
   813 \url{http://www.cyberus.ca/~hadi/usenix-paper.tgz}.}: It passes a frame to the
   791 \url{http://www.cyberus.ca/~hadi/usenix-paper.tgz}.}: It passes a frame to the
   814 network stack, that was just received by the device. Frame data has to be
   792 network stack, that was just received by the device. Frame data has to be
   815 packed into a so-called ``socket buffer'' for that (see below).
   793 included in a so-called ``socket buffer'' for that (see below).
   816 
   794 
   817 \paragraph{Socket Buffers}
   795 \paragraph{Socket Buffers}
   818 \index{Socket buffer}
   796 \index{Socket buffer}
   819 
   797 
   820 Socket buffers are the basic data type for the whole network stack.  They
   798 Socket buffers are the basic data type for the whole network stack. They serve
   821 serve as containers for network data and are able to quickly add data headers
   799 as containers for network data and are able to quickly add data headers and
   822 and footers, or strip them off again. Therefore a socket buffer consists of an
   800 footers, or strip them off again. Therefore a socket buffer consists of an
   823 allocated buffer and several pointers that mark beginning of the buffer
   801 allocated buffer and several pointers that mark beginning of the buffer
   824 (\textit{head}), beginning of data (\textit{data}), end of data
   802 (\lstinline+head+), beginning of data (\lstinline+data+), end of data
   825 (\textit{tail}) and end of buffer (\textit{end}). In addition, a socket buffer
   803 (\lstinline+tail+) and end of buffer (\lstinline+end+). In addition, a socket
   826 holds network header information and (in case of received data) a pointer to
   804 buffer holds network header information and (in case of received data) a
   827 the \textit{net\_device}, it was received on. There exist functions that
   805 pointer to the \lstinline+net_device+, it was received on. There exist
   828 create a socket buffer (\lstinline+dev_alloc_skb()+), add data either from
   806 functions that create a socket buffer (\lstinline+dev_alloc_skb()+), add data
   829 front (\lstinline+skb_push()+) or back (\lstinline+skb_put()+), remove data
   807 either from front (\lstinline+skb_push()+) or back (\lstinline+skb_put()+),
   830 from front (\lstinline+skb_pull()+) or back (\lstinline+skb_trim()+), or
   808 remove data from front (\lstinline+skb_pull()+) or back
   831 delete the buffer (\lstinline+kfree_skb()+).  A socket buffer is passed from
   809 (\lstinline+skb_trim()+), or delete the buffer (\lstinline+kfree_skb()+).  A
   832 layer to layer, and is freed by the layer that uses it the last time. In case
   810 socket buffer is passed from layer to layer, and is freed by the layer that
   833 of sending, freeing has to be done by the network driver.
   811 uses it the last time. In case of sending, freeing has to be done by the
       
   812 network driver.
   834 
   813 
   835 %------------------------------------------------------------------------------
   814 %------------------------------------------------------------------------------
   836 
   815 
   837 \section{EtherCAT Device Drivers}
   816 \section{EtherCAT Device Drivers}
   838 \label{sec:requirements}
   817 \label{sec:requirements}
   841 EtherCAT devices, when connected to an EtherCAT bus.
   820 EtherCAT devices, when connected to an EtherCAT bus.
   842 
   821 
   843 \paragraph{Dedicated Interfaces}
   822 \paragraph{Dedicated Interfaces}
   844 
   823 
   845 For performance and realtime purposes, the EtherCAT master needs direct and
   824 For performance and realtime purposes, the EtherCAT master needs direct and
   846 exclusive access to the Ethernet hardware. This implies that the network
   825 exclusive access to the Ethernet hardware. This implies that the network device
   847 device must not be connected to the kernel's network stack as usual, because
   826 must not be connected to the kernel's network stack as usual, because the
   848 the kernel would try to use it as an ordinary Ethernet device.
   827 kernel would try to use it as an ordinary Ethernet device.
   849 
   828 
   850 \paragraph{Interrupt-less Operation}
   829 \paragraph{Interrupt-less Operation}
   851 \index{Interrupt}
   830 \index{Interrupt}
   852 
   831 
   853 EtherCAT frames travel through the logical EtherCAT ring and are then sent
   832 EtherCAT frames travel through the logical EtherCAT ring and are then sent back
   854 back to the master. Communication is highly deterministic: A frame is sent and
   833 to the master. Communication is highly deterministic: A frame is sent and will
   855 will be received again after a constant time.  Therefore, there is no need to
   834 be received again after a constant time, so there is no need to notify the
   856 notify the driver about frame reception: The master can instead query the
   835 driver about frame reception: The master can instead query the hardware for
   857 hardware for received frames.
   836 received frames, if it expects them to be already received.
   858 
   837 
   859 Figure~\ref{fig:interrupt} shows two workflows for cyclic frame transmission
   838 Figure~\ref{fig:interrupt} shows two workflows for cyclic frame transmission
   860 and reception with and without interrupts.
   839 and reception with and without interrupts.
   861 
   840 
   862 \begin{figure}[htbp]
   841 \begin{figure}[htbp]
   863   \centering
   842   \centering
   864   \includegraphics[width=.8\textwidth]{images/interrupt}
   843   \includegraphics[width=.9\textwidth]{images/interrupt}
   865   \caption{Interrupt Operation versus Interrupt-less Operation}
   844   \caption{Interrupt Operation versus Interrupt-less Operation}
   866   \label{fig:interrupt}
   845   \label{fig:interrupt}
   867 \end{figure}
   846 \end{figure}
   868 
   847 
   869 In the left workflow ``Interrupt Operation'', the data from the last cycle is
   848 In the left workflow ``Interrupt Operation'', the data from the last cycle is
   879 executing the ISR. If the frame has been received in the meantime, it will be
   858 executing the ISR. If the frame has been received in the meantime, it will be
   880 dissected. The situation is now the same as at the beginning of the left
   859 dissected. The situation is now the same as at the beginning of the left
   881 workflow: The received data is processed and a new frame is assembled and
   860 workflow: The received data is processed and a new frame is assembled and
   882 sent. There is nothing to do for the rest of the cycle.
   861 sent. There is nothing to do for the rest of the cycle.
   883 
   862 
   884 The interrupt-less operation is desirable, because there is simply no need for
   863 The interrupt-less operation is desirable, because hardware interrupts are not
   885 an interrupt. Moreover hardware interrupts are not conducive in improving the
   864 conducive in improving the driver's realtime behaviour: Their indeterministic
   886 driver's realtime behaviour: Their indeterministic incidences contribute to
   865 incidences contribute to increasing the jitter. Besides, if a realtime
   887 increasing the jitter. Besides, if a realtime extension (like RTAI) is used,
   866 extension (like RTAI) is used, some additional effort would have to be made to
   888 some additional effort would have to be made to prioritize interrupts.
   867 prioritize interrupts.
   889 
   868 
   890 \paragraph{Ethernet and EtherCAT Devices}
   869 \paragraph{Ethernet and EtherCAT Devices}
   891 
   870 
   892 Another issue lies in the way Linux handles devices of the same type.  For
   871 Another issue lies in the way Linux handles devices of the same type.  For
   893 example, a PCI\nomenclature{PCI}{Peripheral Component Interconnect, Computer
   872 example, a PCI\nomenclature{PCI}{Peripheral Component Interconnect, Computer
   925 %------------------------------------------------------------------------------
   904 %------------------------------------------------------------------------------
   926 
   905 
   927 \section{Device Selection}
   906 \section{Device Selection}
   928 \label{sec:deviceselection}
   907 \label{sec:deviceselection}
   929 
   908 
   930 After loading the master module, at least one EtherCAT-capable network
   909 After loading the master module, at least one EtherCAT-capable network driver
   931 driver module has to be loaded, that connects one of its devices to
   910 module has to be loaded, that offers its devices to the master (see
   932 the master. To specify an EtherCAT device and the master to connect
   911 section~\ref{sec:ecdev}. The master module knows the devices to choose from the
   933 to, all EtherCAT-capable network driver modules should provide two
   912 module parameters (see section~\ref{sec:mastermod}). If the init script is used
   934 module parameters:
   913 to start the master, the drivers and devices to use can be specified in the
   935 
   914 sysconfig file (see section~\ref{sec:sysconfig}).
   936 \begin{description}
       
   937 \item[ec\_device\_index] PCI device index of the device that is
       
   938   connected to the EtherCAT bus. If this parameter is left away, all
       
   939   devices found are treated as ordinary Ethernet devices. Default:
       
   940   $-1$
       
   941 \item[ec\_master\_index] Index of the master to connect to. Default:
       
   942   $0$
       
   943 \end{description}
       
   944 
       
   945 The following command loads the EtherCAT-capable RTL8139 device
       
   946 driver, telling it to handle the second device as an EtherCAT device
       
   947 and connecting it to the first master:
       
   948 
       
   949 \begin{lstlisting}[gobble=2]
       
   950   # `\textbf{modprobe ec\_8139too ec\_device\_index=1}`
       
   951 \end{lstlisting}
       
   952 
       
   953 Usually, this command does not have to be entered manually, but is
       
   954 called by the EtherCAT init script. See section~\ref{sec:init} for
       
   955 more information.
       
   956 
   915 
   957 %------------------------------------------------------------------------------
   916 %------------------------------------------------------------------------------
   958 
   917 
   959 \section{The Device Interface}
   918 \section{The Device Interface}
   960 \label{sec:ecdev}
   919 \label{sec:ecdev}
   963 An anticipation to the section about the master module
   922 An anticipation to the section about the master module
   964 (section~\ref{sec:mastermod}) has to be made in order to understand
   923 (section~\ref{sec:mastermod}) has to be made in order to understand
   965 the way, a network device driver module can connect a device to a
   924 the way, a network device driver module can connect a device to a
   966 specific EtherCAT master.
   925 specific EtherCAT master.
   967 
   926 
   968 The master module provides a ``device interface'' for network device
   927 The master module provides a ``device interface'' for network device drivers.
   969 drivers. To use this interface, a network device driver module must
   928 To use this interface, a network device driver module must include the header
   970 include the header
   929 \textit{devices/ecdev.h}\nomenclature{ecdev}{EtherCAT Device}, coming with the
   971 \textit{devices/ecdev.h}\nomenclature{ecdev}{EtherCAT Device}, coming
   930 EtherCAT master code. This header offers a function interface for EtherCAT
   972 with the EtherCAT master code. This header offers a function interface
   931 devices. All functions of the device interface are named with the prefix
   973 for EtherCAT devices which is explained below. All functions of the
   932 \lstinline+ecdev+.
   974 device interface are named with the prefix \textit{ecdev}.
   933 
   975 
   934 The documentation of the device interface can be found in the header file or in
   976 \paragraph{Device Registration}
   935 the appropriate module of the interface documentation (see
   977 
   936 section~\ref{sec:gendoc} for generation instructions).
   978 A network device driver can connect a physical device to an EtherCAT
   937 
   979 master with the \textit{ecdev\_register()} function.
   938 \ldots % FIXME general description of the device interface
   980 
       
   981 \begin{lstlisting}[gobble=2,language=C]
       
   982   ec_device_t *ecdev_register(unsigned int master_index,
       
   983                               struct net_device *net_dev,
       
   984                               ec_isr_t isr,
       
   985                               struct module *module);
       
   986 \end{lstlisting}
       
   987 
       
   988 The first parameter \textit{master\_index} must be the index of the
       
   989 EtherCAT master to connect to (see section~\ref{sec:mastermod}),
       
   990 followed by \textit{net\_dev}, the pointer to the corresponding
       
   991 net\_device structure, which represents the network device to connect.
       
   992 The third parameter \textit{isr} must be a pointer to the interrupt
       
   993 service routine (ISR\index{ISR}) handling the device. The master will
       
   994 later execute the ISR in order to receive frames and to update the
       
   995 device status. The last parameter \textit{module} must be the pointer
       
   996 to the device driver module, which is usually accessible via the macro
       
   997 \textit{THIS\_MODULE} (see next paragraph). On success, the function
       
   998 returns a pointer to an \textit{ec\_device\_t} object, which has to be
       
   999 specified when calling further functions of the device interface.
       
  1000 Therefore the device module has to store this pointer for future use.
       
  1001 In error case, the \textit{ecdev\_register()} returns \textit{NULL},
       
  1002 which means that the device could not be registered.  The reason for
       
  1003 this is printed to \textit{Syslog}\index{Syslog}. In this case, the
       
  1004 device module is supposed to abort the module initialisation and let
       
  1005 the \textit{insmod} command fail.
       
  1006 
       
  1007 \paragraph{Implicit Dependencies}
       
  1008 
       
  1009 The reason for the module pointer has to be specified at device registration is
       
  1010 a non-trivial one: The master has to know about the module, because there will
       
  1011 be an implicit dependency between the device module and a later connected
       
  1012 application module: When an application module connects to the master, the use
       
  1013 count of the master module will be increased, so that the master module can not
       
  1014 be unloaded for the time of the connection. This is reasonable, and so
       
  1015 automatically done by the kernel. The kernel knows about this dependency,
       
  1016 because the application module uses kernel symbols provided by the master
       
  1017 module.  Moreover it is mandatory, that the device module can be unloaded
       
  1018 neither, because it is implicitly used by the application module, too.
       
  1019 Unloading it would lead to a fatal situation, because the master would have no
       
  1020 device to send and receive frames for the application. This dependency can not
       
  1021 be detected automatically, because the application module does not use any
       
  1022 symbols of the device module. Therefore the master explicitly increments the
       
  1023 use counter of the connected device module upon connection of an application
       
  1024 and decrements it, if it disconnects again. In this manner, it is impossible to
       
  1025 unload a device module while the master is in use. This is done with the kernel
       
  1026 function pair \textit{try\_module\_get()}
       
  1027 \index{try\_module\_get@\textit{try\_module\_get()}} and \textit{module\_put()}
       
  1028 \index{module\_put@\textit{module\_put()}}. The first one increases the use
       
  1029 count of a module and only fails, if the module is currently being unloaded.
       
  1030 The last one decreases the use count again and never fails. Both functions take
       
  1031 a pointer to the module as their argument, which the device module therefore
       
  1032 has to specify upon device registration.
       
  1033 
       
  1034 \paragraph{Device Unregistering}
       
  1035 
       
  1036 The deregistration of a device is usually done in the device module's cleanup
       
  1037 function, by calling the \textit{ecdev\_unregister()} function and specifying
       
  1038 the master index and a pointer to the device object again.
       
  1039 
       
  1040 \begin{lstlisting}[gobble=2,language=C]
       
  1041   void ecdev_unregister(unsigned int master_index,
       
  1042                         ec_device_t *device);
       
  1043 \end{lstlisting}
       
  1044 
       
  1045 This function can fail too (if the master index is invalid, or the
       
  1046 given device was not registered), but due to the fact, that this
       
  1047 failure can not be dealt with appropriately, because the device module
       
  1048 is unloading anyway, the failure code would not be of any interest. So
       
  1049 the function has a void return value.
       
  1050 
       
  1051 \paragraph{Starting the Master}
       
  1052 
       
  1053 When a device has been initialized completely and is ready to send and
       
  1054 receive frames, the master has to be notified about this by calling
       
  1055 the \textit{ecdev\_start()} function.
       
  1056 
       
  1057 \begin{lstlisting}[gobble=2,language=C]
       
  1058   int ecdev_start(unsigned int master_index);
       
  1059 \end{lstlisting}
       
  1060 
       
  1061 The master will then enter ``Idle Mode'' and start scanning the bus
       
  1062 (and possibly handling EoE slaves). Moreover it will make the bus
       
  1063 accessible via Sysfs interface and react to user interactions. The
       
  1064 function takes one parameter \textit{master\_index}, which has to be
       
  1065 the same as at the call to \textit{ecdev\_register()}. The return
       
  1066 value will be non-zero if the starting process failed. In this case
       
  1067 the device module is supposed to abort the init sequence and make the
       
  1068 init function return an error code.
       
  1069 
       
  1070 \paragraph{Stopping the Master}
       
  1071 
       
  1072 Before a device can be unregistered, the master has to be stopped by
       
  1073 calling the \textit{ecdev\_stop()} function. It will stop processing
       
  1074 messages of EoE slaves and leave ``Idle Mode''. The only parameter is
       
  1075 \textit{master\_index}. This function can not fail.
       
  1076 
       
  1077 \begin{lstlisting}[gobble=2,language=C]
       
  1078   void ecdev_stop(unsigned int master_index);
       
  1079 \end{lstlisting}
       
  1080 
       
  1081 A subsequent call to \textit{ecdev\_unregister()} will now unregister
       
  1082 the device savely.
       
  1083 
       
  1084 \paragraph{Receiving Frames}
       
  1085 
       
  1086 The interrupt service routine handling device events usually has a
       
  1087 section where new frames are fetched from the hardware and forwarded
       
  1088 to the kernel network stack via \textit{netif\_receive\_skb()}. For an
       
  1089 EtherCAT-capable device, this has to be replaced by calling the
       
  1090 \textit{ecdev\_receive()} function to forward the received data to the
       
  1091 connected EtherCAT master instead.
       
  1092 
       
  1093 \begin{lstlisting}[gobble=2,language=C]
       
  1094   void ecdev_receive(ec_device_t *device,
       
  1095                      const void *data,
       
  1096                      size_t size);
       
  1097 \end{lstlisting}
       
  1098 
       
  1099 This function takes 3 arguments, a pointer to the device object
       
  1100 (\textit{device}), a pointer to the received data, and the size of the
       
  1101 received data. The data range has to include the Ethernet headers
       
  1102 starting with the destination address and reach up to the last octet
       
  1103 of EtherCAT data, excluding the FCS. Most network devices handle the
       
  1104 FCS in hardware, so it is not seen by the driver code and therefore
       
  1105 doesn't have to be cut off manually.
       
  1106 
       
  1107 \paragraph{Handling the Link Status}
       
  1108 
       
  1109 Information about the link status (i.~e. if there is a carrier signal detected
       
  1110 on the physical port) is also important to the master. This information is
       
  1111 usually gathered by the ISR and should be forwarded to the master by calling
       
  1112 the \textit{ecdev\_link\_state()} function. The master then can react on this
       
  1113 and warn the application of a lost link.
       
  1114 
       
  1115 \begin{lstlisting}[gobble=2,language=C]
       
  1116   void ecdev_link_state(ec_device_t *device,
       
  1117                         uint8_t new_state);
       
  1118 \end{lstlisting}
       
  1119 
       
  1120 The parameter \textit{device} has to be a pointer to the device object
       
  1121 returned by \textit{ecdev\_\-register()}. With the second parameter
       
  1122 \textit{new\_state}, the new link state is passed: 1, if the link went
       
  1123 up, and 0, if it went down.
       
  1124 
   939 
  1125 %------------------------------------------------------------------------------
   940 %------------------------------------------------------------------------------
  1126 
   941 
  1127 \section{Patching Network Drivers}
   942 \section{Patching Network Drivers}
  1128 \label{sec:patching}
   943 \label{sec:patching}
  1129 \index{Network drivers}
   944 \index{Network drivers}
  1130 
   945 
  1131 This section will demonstrate, how to make a standard Ethernet driver
   946 This section will describe, how to make a standard Ethernet driver
  1132 EtherCAT-capable. The below code examples are taken out of the
   947 EtherCAT-capable. Unfortunately, there is no standard procedure to enable an
  1133 modified RealTek RTL8139 driver coming with the EtherCAT master
   948 Ethernet driver for use with the EtherCAT master, but there are a few common
  1134 (\textit{devices/8139too.c}). The driver was originally developed by
   949 techniques.
  1135 Donald Becker, and is currently maintained by Jeff Garzik.
       
  1136 
       
  1137 Unfortunately, there is no standard procedure to enable an Ethernet
       
  1138 driver for use with the EtherCAT master, but there are a few common
       
  1139 techniques, that are described in this section.
       
  1140 
   950 
  1141 \begin{enumerate}
   951 \begin{enumerate}
  1142 \item A first simple rule is, that \textit{netif\_*()}-calls must be
   952 
  1143   strictly avoided for all EtherCAT devices. As mentioned before,
   953 \item A first simple rule is, that \lstinline+netif_*()+ calls must be avoided
  1144   EtherCAT devices have no connection to the network stack, and
   954 for all EtherCAT devices. As mentioned before, EtherCAT devices have no
  1145   therefore must not call its interface functions.
   955 connection to the network stack, and therefore must not call its interface
  1146 \item Another important thing is, that EtherCAT devices should be
   956 functions.
  1147   operated without interrupts. So any calls of registering interrupt
   957 
  1148   handlers and enabling interrupts at hardware level must be avoided,
   958 \item Another important thing is, that EtherCAT devices should be operated
  1149   too.
   959 without interrupts. So any calls of registering interrupt handlers and enabling
  1150 \item The master does not use a new socket buffer for each send
   960 interrupts at hardware level must be avoided, too.
  1151   operation: Instead there is a fix one allocated on master
   961 
  1152   initialization. This socket buffer is filled with an EtherCAT frame
   962 \item The master does not use a new socket buffer for each send operation:
  1153   with every send operation and passed to the
   963 Instead there is a fix one allocated on master initialization. This socket
  1154   \textit{hard\_start\_xmit()} callback. For that it is necessary,
   964 buffer is filled with an EtherCAT frame with every send operation and passed to
  1155   that the socket buffer is not be freed by the network driver as
   965 the \lstinline+hard_start_xmit()+ callback. For that it is necessary, that the
  1156   usual.
   966 socket buffer is not be freed by the network driver as usual.
       
   967 
  1157 \end{enumerate}
   968 \end{enumerate}
  1158 
   969 
  1159 As mentioned before, the driver will handle both EtherCAT and ordinary
   970 An Ethernet driver usually handles several Ethernet devices, each described by
  1160 Ethernet devices. This implies, that for each device-dependent
   971 a \lstinline+net_device+ structure with a \lstinline+priv_data+ field to
  1161 operation, it has to be checked if an EtherCAT device is involved, or
   972 attach driver-dependent data to the structure. To distinguish between normal
  1162 just an Ethernet device. For means of simplicity, this example driver
   973 Ethernet devices and the ones used by EtherCAT masters, the private data
  1163 will only handle one EtherCAT device. This makes the case
   974 structure used by the driver could be extended by a pointer, that points to an
  1164 differentiations easier.
   975 \lstinline+ec_device_t+ object returned by \lstinline+ecdev_offer()+ (see
  1165 
   976 section~\ref{sec:ecdev}) if the device is used by a master and otherwise is
  1166 \paragraph{Global Variables}
   977 zero.
  1167 
   978 
  1168 First of all, there have to be additional global variables declared,
   979 The RealTek RTL-8139 Fast Ethernet driver is a ``simple'' Ethernet driver and
  1169 as shown in the listing:
   980 can be taken as an example to patch new drivers. The interesting sections can
  1170 
   981 be found by searching the string ``ecdev" in the file
  1171 \begin{lstlisting}[gobble=2,language=C,numbers=left]
   982 \textit{devices/8139too-2.6.24-ethercat.c}.
  1172   static int ec_device_index = -1;
       
  1173   static int ec_device_master_index = 0;
       
  1174   static ec_device_t *rtl_ec_dev;
       
  1175   struct net_device *rtl_ec_net_dev = NULL;
       
  1176 \end{lstlisting}
       
  1177 
       
  1178 \begin{description}
       
  1179 \item[\linenum{1} -- \linenum{2}] To
       
  1180   comply to the requirements for parameters of EtherCAT device modules
       
  1181   described in section~\ref{sec:seldev}, there have to be additional
       
  1182   parameter variables: \textit{ec\_\-device\_\-index} holds the index
       
  1183   of the EtherCAT device and defaults to $-1$ (no EtherCAT device),
       
  1184   while \textit{ec\_device\_master\_index} stores index of the master,
       
  1185   the single device will be connected to. Default: $0$
       
  1186 \item[\linenum{3}] \textit{rtl\_ec\_dev} will be
       
  1187   the pointer to the later registered RealTek EtherCAT device, which
       
  1188   can be used as a parameter for device methods.
       
  1189 \item[\linenum{4}] \textit{rtl\_ec\_net\_dev} is
       
  1190   a pointer to the \textit{net\_device} structure of the dedicated
       
  1191   device and is set while scanning the PCI bus and finding the device
       
  1192   with the specified index. This is done inside the
       
  1193   \textit{pci\_module\_init()} function executed as the first thing on
       
  1194   module loading.
       
  1195 \end{description}
       
  1196 
       
  1197 \paragraph{Module Initialization}
       
  1198 
       
  1199 Below is the (shortened) coding of the device driver's module init
       
  1200 function:
       
  1201 
       
  1202 \begin{lstlisting}[gobble=2,language=C,numbers=left]
       
  1203   static int __init rtl8139_init_module(void)
       
  1204   {
       
  1205           if (pci_module_init(&rtl8139_pci_driver) < 0) {
       
  1206                   printk(KERN_ERR "Failed to init PCI mod.\n");
       
  1207                   goto out_return;
       
  1208           }
       
  1209 
       
  1210           if (rtl_ec_net_dev) {
       
  1211                   printk(KERN_INFO "Registering"
       
  1212                          " EtherCAT device...\n");
       
  1213                   if (!(rtl_ec_dev =
       
  1214                           ecdev_register(ec_device_master_index,
       
  1215                                          rtl_ec_net_dev,
       
  1216                                          rtl8139_interrupt,
       
  1217                                          THIS_MODULE))) {
       
  1218                           printk(KERN_ERR "Failed to reg."
       
  1219                                           " EtherCAT device!\n");
       
  1220                           goto out_unreg_pci;
       
  1221                   }
       
  1222 
       
  1223                   printk(KERN_INFO "Starting EtherCAT"
       
  1224                          " device...\n");
       
  1225                   if (ecdev_start(ec_device_master_index)) {
       
  1226                           printk(KERN_ERR "Failed to start"
       
  1227                                  " EtherCAT device!\n");
       
  1228                           goto out_unreg_ec;
       
  1229                   }
       
  1230           } else {
       
  1231                   printk(KERN_WARNING "No EtherCAT device"
       
  1232                          " registered!\n");
       
  1233           }
       
  1234 
       
  1235           return 0;
       
  1236 
       
  1237       out_unreg_ec:
       
  1238           ecdev_unregister(ec_device_master_index, rtl_ec_dev);
       
  1239       out_unreg_pci:
       
  1240           pci_unregister_driver(&rtl8139_pci_driver);
       
  1241       out_return:
       
  1242           return -1;
       
  1243   }
       
  1244 \end{lstlisting}
       
  1245 
       
  1246 \begin{description}
       
  1247 \item[\linenum{3}] This call initializes all
       
  1248   RTL8139-compatible devices found on the pci bus. If a device with
       
  1249   index \textit{ec\_device\_index} is found, a pointer to its
       
  1250   \textit{net\_device} structure is stored in
       
  1251   \textit{rtl\_ec\_net\_dev} for later use (see next listings).
       
  1252 \item[\linenum{8}] If the specified device was
       
  1253   found, \textit{rtl\_ec\_net\_dev} is non-zero.
       
  1254 \item[\linenum{11}] The device is connected to
       
  1255   the specified master with a call to \textit{ecdev\_register()}. If
       
  1256   this fails, module loading is aborted.
       
  1257 \item[\linenum{23}] The device registration was
       
  1258   successful and the master is started. This can fail, which aborts
       
  1259   module loading.
       
  1260 \item[\linenum{29}] If no EtherCAT device was
       
  1261   found, a warning is output.
       
  1262 \end{description}
       
  1263 
       
  1264 \paragraph{Device Searching}
       
  1265 
       
  1266 During the PCI initialization phase, a variable \textit{board\_idx} is
       
  1267 increased for each RTL8139-compatible device found. The code below is
       
  1268 executed for each device:
       
  1269 
       
  1270 \begin{lstlisting}[gobble=2,language=C,numbers=left]
       
  1271   if (board_idx == ec_device_index) {
       
  1272           rtl_ec_net_dev = dev;
       
  1273           strcpy(dev->name, "ec0");
       
  1274   }
       
  1275 \end{lstlisting}
       
  1276 
       
  1277 \begin{description}
       
  1278 \item[\linenum{1}] The device with the specified
       
  1279   index will be the EtherCAT device.
       
  1280 \end{description}
       
  1281 
       
  1282 \paragraph{Avoiding Device Registration}
       
  1283 
       
  1284 Later in the PCI initialization phase, the net\_devices get
       
  1285 registered. This has to be avoided for EtherCAT devices and so this is
       
  1286 a typical example for an EtherCAT case differentiation:
       
  1287 
       
  1288 \begin{lstlisting}[gobble=2,language=C,numbers=left]
       
  1289   if (dev != rtl_ec_net_dev) {
       
  1290           i = register_netdev(dev);
       
  1291           if (i) goto err_out;
       
  1292   }
       
  1293 \end{lstlisting}
       
  1294 
       
  1295 \begin{description}
       
  1296 \item[\linenum{1}] If the current net\_device is
       
  1297   not the EtherCAT device, it is registered at the network stack.
       
  1298 \end{description}
       
  1299 
       
  1300 \paragraph{Avoiding Interrupt Registration}
       
  1301 
       
  1302 In the next two listings, there is an interrupt requested and the
       
  1303 device's interrupts are enabled. This also has to be encapsulated by
       
  1304 if-clauses, because interrupt operation is not wanted for EtherCAT
       
  1305 devices.
       
  1306 
       
  1307 \begin{lstlisting}[gobble=2,language=C,numbers=left]
       
  1308   if (dev != rtl_ec_net_dev) {
       
  1309           retval = request_irq(dev->irq, rtl8139_interrupt,
       
  1310                                SA_SHIRQ, dev->name, dev);
       
  1311           if (retval) return retval;
       
  1312   }
       
  1313 \end{lstlisting}
       
  1314 
       
  1315 \begin{lstlisting}[gobble=2,language=C,numbers=left]
       
  1316   if (dev != rtl_ec_net_dev) {
       
  1317           /* Enable all known interrupts by setting
       
  1318              the interrupt mask. */
       
  1319           RTL_W16(IntrMask, rtl8139_intr_mask);
       
  1320   }
       
  1321 \end{lstlisting}
       
  1322 
       
  1323 \paragraph{Frame Sending}
       
  1324 
       
  1325 The listing below shows an excerpt of the function representing the
       
  1326 \textit{hard\_start\_xmit()} callback of the net\_device.
       
  1327 
       
  1328 \begin{lstlisting}[gobble=2,language=C,numbers=left]
       
  1329   /* Note: the chip doesn't have auto-pad! */
       
  1330   if (likely(len < TX_BUF_SIZE)) {
       
  1331           if (len < ETH_ZLEN)
       
  1332                   memset(tp->tx_buf[entry], 0, ETH_ZLEN);
       
  1333           skb_copy_and_csum_dev(skb, tp->tx_buf[entry]);
       
  1334           if (dev != rtl_ec_net_dev) {
       
  1335                   dev_kfree_skb(skb);
       
  1336           }
       
  1337   } else {
       
  1338           if (dev != rtl_ec_net_dev) {
       
  1339                   dev_kfree_skb(skb);
       
  1340           }
       
  1341           tp->stats.tx_dropped++;
       
  1342           return 0;
       
  1343   }
       
  1344 \end{lstlisting}
       
  1345 
       
  1346 \begin{description}
       
  1347 \item[\linenum{6} + \linenum{10}] The
       
  1348   master uses a fixed socket buffer for transmission, which is reused
       
  1349   and may not be freed.
       
  1350 \end{description}
       
  1351 
       
  1352 \paragraph{Frame Receiving}
       
  1353 
       
  1354 During ordinary frame reception, a socket buffer is created and filled
       
  1355 with the received data. This is not necessary for an EtherCAT device:
       
  1356 
       
  1357 \begin{lstlisting}[gobble=2,language=C,numbers=left]
       
  1358   if (dev != rtl_ec_net_dev) {
       
  1359           /* Malloc up new buffer, compatible with net-2e. */
       
  1360           /* Omit the four octet CRC from the length. */
       
  1361 
       
  1362           skb = dev_alloc_skb (pkt_size + 2);
       
  1363           if (likely(skb)) {
       
  1364                   skb->dev = dev;
       
  1365                   skb_reserve(skb, 2); /* 16 byte align
       
  1366                                           the IP fields. */
       
  1367                   eth_copy_and_sum(skb, &rx_ring[ring_off + 4],
       
  1368                                    pkt_size, 0);
       
  1369                   skb_put(skb, pkt_size);
       
  1370                   skb->protocol = eth_type_trans(skb, dev);
       
  1371 
       
  1372                   dev->last_rx = jiffies;
       
  1373                   tp->stats.rx_bytes += pkt_size;
       
  1374                   tp->stats.rx_packets++;
       
  1375 
       
  1376                   netif_receive_skb (skb);
       
  1377           } else {
       
  1378                   if (net_ratelimit())
       
  1379                           printk(KERN_WARNING
       
  1380                                  "%s: Memory squeeze, dropping"
       
  1381                                  " packet.\n", dev->name);
       
  1382                   tp->stats.rx_dropped++;
       
  1383           }
       
  1384   } else {
       
  1385           ecdev_receive(rtl_ec_dev,
       
  1386                         &rx_ring[ring_offset + 4], pkt_size);
       
  1387           dev->last_rx = jiffies;
       
  1388           tp->stats.rx_bytes += pkt_size;
       
  1389           tp->stats.rx_packets++;
       
  1390   }
       
  1391 \end{lstlisting}
       
  1392 
       
  1393 \begin{description}
       
  1394 \item[\linenum{28}] If the device is an EtherCAT
       
  1395   device, no socket buffer is allocated. Instead a pointer to the data
       
  1396   (which is still in the device's receive ring) is passed to the
       
  1397   EtherCAT master. Unnecessary copy operations are avoided.
       
  1398 \item[\linenum{30} -- \linenum{32}] The
       
  1399   device's statistics are updated as usual.
       
  1400 \end{description}
       
  1401 
       
  1402 \paragraph{Link State}
       
  1403 
       
  1404 The link state (i.~e. if there is a carrier signal detected on the
       
  1405 receive port) is determined during execution of the ISR. The listing
       
  1406 below shows the different processing for Ethernet and EtherCAT
       
  1407 devices:
       
  1408 
       
  1409 \begin{lstlisting}[gobble=2,language=C,numbers=left]
       
  1410   if (dev != rtl_ec_net_dev) {
       
  1411           if (tp->phys[0] >= 0) {
       
  1412                   mii_check_media(&tp->mii, netif_msg_link(tp),
       
  1413                                   init_media);
       
  1414           }
       
  1415   } else {
       
  1416           void __iomem *ioaddr = tp->mmio_addr;
       
  1417           uint16_t link = RTL_R16(BasicModeStatus)
       
  1418                           & BMSR_LSTATUS;
       
  1419           ecdev_link_state(rtl_ec_dev, link ? 1 : 0);
       
  1420   }
       
  1421 \end{lstlisting}
       
  1422 
       
  1423 \begin{description}
       
  1424 \item[\linenum{3}] The ``media check'' is done
       
  1425   via the media independent interface (MII\nomenclature{MII}{Media
       
  1426     Independent Interface}), a standard interface for Fast Ethernet
       
  1427   devices.
       
  1428 \item[\linenum{7} -- \linenum{10}] For
       
  1429   EtherCAT devices, the link state is fetched manually from the
       
  1430   appropriate device register, and passed to the EtherCAT master by
       
  1431   calling \textit{ecdev\_\-link\_\-state()}.
       
  1432 \end{description}
       
  1433 
       
  1434 \paragraph{Module Cleanup}
       
  1435 
       
  1436 Below is the module's cleanup function:
       
  1437 
       
  1438 \begin{lstlisting}[gobble=2,language=C,numbers=left]
       
  1439   static void __exit rtl8139_cleanup_module (void)
       
  1440   {
       
  1441           printk(KERN_INFO "Cleaning up RTL8139-EtherCAT"
       
  1442                  " module...\n");
       
  1443 
       
  1444           if (rtl_ec_net_dev) {
       
  1445                   printk(KERN_INFO "Stopping device...\n");
       
  1446                   ecdev_stop(ec_device_master_index);
       
  1447                   printk(KERN_INFO "Unregistering device...\n");
       
  1448                   ecdev_unregister(ec_device_master_index,
       
  1449                                    rtl_ec_dev);
       
  1450                   rtl_ec_dev = NULL;
       
  1451           }
       
  1452 
       
  1453           pci_unregister_driver(&rtl8139_pci_driver);
       
  1454 
       
  1455           printk(KERN_INFO "RTL8139-EtherCAT module"
       
  1456                  " cleaned up.\n");
       
  1457   }
       
  1458 \end{lstlisting}
       
  1459 
       
  1460 \begin{description}
       
  1461 
       
  1462 \item[\linenum{6}] Stopping and deregistration is only done, if a device was
       
  1463 registered before.
       
  1464 
       
  1465 \item[\linenum{8}] The master is first stopped, so it does not access the
       
  1466 device any more.
       
  1467 
       
  1468 \item[\linenum{10}] After this, the device is unregistered. The master is now
       
  1469 ``orphaned''.
       
  1470 
       
  1471 \end{description}
       
  1472 
   983 
  1473 %------------------------------------------------------------------------------
   984 %------------------------------------------------------------------------------
  1474 
   985 
  1475 \chapter{State Machines}
   986 \chapter{State Machines}
  1476 \label{sec:fsm}
   987 \label{sec:fsm}
  1720 \end{lstlisting}
  1231 \end{lstlisting}
  1721 
  1232 
  1722 In the master code, state pointers of all state machines\footnote{All except
  1233 In the master code, state pointers of all state machines\footnote{All except
  1723 for the EoE state machine, because multiple EoE slaves have to be handled in
  1234 for the EoE state machine, because multiple EoE slaves have to be handled in
  1724 parallel. For this reason each EoE handler object has its own state pointer.}
  1235 parallel. For this reason each EoE handler object has its own state pointer.}
  1725 are gathered in a single object of the \textit{ec\_fsm\_t} class. This is
  1236 are gathered in a single object of the \lstinline+ec_fsm_master_t+ class. This
  1726 advantageous, because there is always one instance of every state machine
  1237 is advantageous, because there is always one instance of every state machine
  1727 available and can be started on demand.
  1238 available and can be started on demand.
  1728 
  1239 
  1729 \paragraph{Mealy and Moore}
  1240 \paragraph{Mealy and Moore}
  1730 
  1241 
  1731 If a closer look is taken to the above listing, it can be seen that
  1242 If a closer look is taken to the above listing, it can be seen that the
  1732 the actions executed (the ``outputs'' of the state machine) only
  1243 actions executed (the ``outputs'' of the state machine) only depend on the
  1733 depend on the current state. This accords to the ``Moore'' model
  1244 current state. This accords to the ``Moore'' model introduced in
  1734 introduced in section~\ref{sec:fsmtheory}. As mentioned, the ``Mealy''
  1245 section~\ref{sec:fsmtheory}. As mentioned, the ``Mealy'' model offers a higher
  1735 model offers a higher flexibility, which can be seen in the listing
  1246 flexibility, which can be seen in the listing below:
  1736 below:
       
  1737 
  1247 
  1738 \begin{lstlisting}[gobble=2,language=C,numbers=left]
  1248 \begin{lstlisting}[gobble=2,language=C,numbers=left]
  1739   void state7(void *priv_data) {
  1249   void state7(void *priv_data) {
  1740           if (some_condition) {
  1250           if (some_condition) {
  1741                   action_7a();
  1251                   action_7a();
  1747           }
  1257           }
  1748   }
  1258   }
  1749 \end{lstlisting}
  1259 \end{lstlisting}
  1750 
  1260 
  1751 \begin{description}
  1261 \begin{description}
  1752 \item[\linenum{3} + \linenum{7}] The
  1262 
  1753   state function executes the actions depending on the state
  1263 \item[\linenum{3} + \linenum{7}] The state function executes the actions
  1754   transition, that is about to be done.
  1264 depending on the state transition, that is about to be done.
       
  1265 
  1755 \end{description}
  1266 \end{description}
  1756 
  1267 
  1757 The most flexible alternative is to execute certain actions depending
  1268 The most flexible alternative is to execute certain actions depending
  1758 on the state, followed by some actions dependent on the state
  1269 on the state, followed by some actions dependent on the state
  1759 transition:
  1270 transition:
  1770                   state = state10;
  1281                   state = state10;
  1771           }
  1282           }
  1772   }
  1283   }
  1773 \end{lstlisting}
  1284 \end{lstlisting}
  1774 
  1285 
  1775 This model is oftenly used in the master. It combines the best aspects
  1286 This model is often used in the master. It combines the best aspects of both
  1776 of both approaches.
  1287 approaches.
  1777 
  1288 
  1778 \paragraph{Using Sub State Machines}
  1289 \paragraph{Using Sub State Machines}
  1779 
  1290 
  1780 To avoid having too much states, certain functions of the EtherCAT master state
  1291 To avoid having too much states, certain functions of the EtherCAT master
  1781 machine have been sourced out into sub state machines.  This helps to
  1292 state machine have been sourced out into sub state machines.  This helps to
  1782 encapsulate the related workflows and moreover avoids the ``state explosion''
  1293 encapsulate the related workflows and moreover avoids the ``state explosion''
  1783 phenomenon described in section~\ref{sec:fsmtheory}. If the master would
  1294 phenomenon described in section~\ref{sec:fsmtheory}. If the master would
  1784 instead use one big state machine, the number of states would be a multiple of
  1295 instead use one big state machine, the number of states would be a multiple of
  1785 the actual number. This would increase the level of complexity to a
  1296 the actual number. This would increase the level of complexity to a
  1786 non-manageable grade.
  1297 non-manageable grade.
  1808           // continue state processing
  1319           // continue state processing
  1809           ...
  1320           ...
  1810 \end{lstlisting}
  1321 \end{lstlisting}
  1811 
  1322 
  1812 \begin{description}
  1323 \begin{description}
  1813 \item[\linenum{3}] \textit{change\_state} is the
  1324 
  1814   state pointer of the state change state machine. The state function,
  1325 \item[\linenum{3}] \lstinline+change_state+ is the state pointer of the state
  1815   the pointer points on, is executed\ldots
  1326 change state machine. The state function, the pointer points on, is
  1816 \item[\linenum{6}] \ldots either until the state
  1327 executed\ldots
  1817   machine terminates with the error state \ldots
  1328 
  1818 \item[\linenum{11}] \ldots or until the state
  1329 \item[\linenum{6}] \ldots either until the state machine terminates with the
  1819   machine terminates in the end state. Until then, the ``higher''
  1330 error state \ldots
  1820   state machine remains in the current state and executes the sub
  1331 
  1821   state machine again in the next cycle.
  1332 \item[\linenum{11}] \ldots or until the state machine terminates in the end
       
  1333 state. Until then, the ``higher'' state machine remains in the current state
       
  1334 and executes the sub state machine again in the next cycle.
       
  1335 
  1822 \end{description}
  1336 \end{description}
  1823 
  1337 
  1824 \paragraph{State Machine Descriptions}
  1338 \paragraph{State Machine Descriptions}
  1825 
  1339 
  1826 The below sections describe every state machine used in the EtherCAT
  1340 The below sections describe every state machine used in the EtherCAT master.
  1827 master. The textual descriptions of the state machines contain
  1341 The textual descriptions of the state machines contain references to the
  1828 references to the transitions in the corresponding state transition
  1342 transitions in the corresponding state transition diagrams, that are marked
  1829 diagrams, that are marked with an arrow followed by the name of the
  1343 with an arrow followed by the name of the successive state. Transitions caused
  1830 successive state.  Transitions caused by trivial error cases (i.~e. no
  1344 by trivial error cases (i.~e. no response from slave) are not described
  1831 response from slave) are not described explicitly. These transitions
  1345 explicitly. These transitions are drawn as dashed arrows in the diagrams.
  1832 are drawn as dashed arrows in the diagrams.
  1346 
  1833 
  1347 %------------------------------------------------------------------------------
  1834 %------------------------------------------------------------------------------
  1348 
  1835 
  1349 \section{The Master State Machine}
  1836 \section{The Operation State Machine}
  1350 \label{sec:fsm-master}
  1837 \label{sec:fsm-op}
  1351 \index{FSM!Master}
  1838 \index{FSM!Operation}
  1352 
  1839 
  1353 The master state machine is executed in the context of the master thread.
  1840 The Operation state machine is executed by calling the
  1354 Figure~\ref{fig:fsm-master} shows its transition diagram. Its purposes are:
  1841 \textit{ecrt\_master\_run()} method in cyclic realtime code. Its
       
  1842 purpose is to monitor the bus and to reconfigure slaves after a bus
       
  1843 failure or power failure. Figure~\ref{fig:fsm-op} shows its transition
       
  1844 diagram.
       
  1845 
  1355 
  1846 \begin{figure}[htbp]
  1356 \begin{figure}[htbp]
  1847   \centering
  1357   \centering
  1848   \includegraphics[width=.8\textwidth]{images/fsm-op}
  1358   \includegraphics[width=\textwidth]{graphs/fsm_master}
  1849   \caption{Transition diagram of the operation state machine}
  1359   \caption{Transition diagram of the master state machine}
  1850   \label{fig:fsm-op}
  1360   \label{fig:fsm-master}
  1851 \end{figure}
  1361 \end{figure}
  1852 
  1362 
  1853 \begin{description}
  1363 \begin{description}
  1854 \item[START] This is the beginning state of the operation state
  1364 
  1855   machine. There is a datagram issued, that queries the ``AL Control
  1365 \item[Bus monitoring] The bus topology is monitored. If it changes, the bus is
  1856   Response'' attribute \cite[section~5.3.2]{alspec} of all slaves via
  1366 (re-)scanned.
  1857   broadcast. In this way, all slave states and the number of slaves
  1367 
  1858   responding can be determined.  $\rightarrow$~BROADCAST
  1368 \item[Slave configuration] The application-layer states of the slaves are
  1859 
  1369 monitored. If a slave is not in the state it supposed to be, the slave is
  1860 \item[BROADCAST] The broadcast datagram is evaluated. A change in the number of
  1370 (re-)configured.
  1861 responding slaves is treated as a topology change. If the number of slaves is
  1371 
  1862 not as expected, the bus is marked as ``tainted''. In this state, no slave
  1372 \item[Request handling] Requests (either originating from the application or
  1863 reconfiguration is possible, because the assignment of known slaves and those
  1373 from external sources) are handled. This can be SII accesses, Sdo accesses,
  1864 present on the bus is ambiguous. If the number of slaves is considered as
  1374 etc.
  1865 right, the bus is marked for validation, because it turned from tainted to
       
  1866 normal state and it has to be checked, if all slaves are valid. Now, the state
       
  1867 of every single slave has to be determined. For that, a (unicast) datagram is
       
  1868 issued, that queries the first slave's ``AL Control Response'' attribute.
       
  1869 $\rightarrow$~READ STATES
       
  1870 
       
  1871 \item[READ STATES] If the current slave did not respond to its configured
       
  1872 station address, it is marked as offline, and the next slave is queried.
       
  1873 $\rightarrow$~READ STATES
       
  1874 
       
  1875   If the slave responded, it is marked as online and its current state
       
  1876   is stored. The next slave is queried. $\rightarrow$~READ STATES
       
  1877 
       
  1878   If all slaves have been queried, and the bus is marked for
       
  1879   validation, the validation is started by checking the first slaves
       
  1880   vendor ID. $\rightarrow$~VALIDATE VENDOR
       
  1881 
       
  1882   If no validation has to be done, it is checked, if all slaves are in
       
  1883   the state they are supposed to be. If not, the first of slave with
       
  1884   the wrong state is reconfigured and brought in the required state.
       
  1885   $\rightarrow$~CONFIGURE SLAVES
       
  1886 
       
  1887   If all slaves are in the correct state, the state machine is
       
  1888   restarted. $\rightarrow$~START
       
  1889 
       
  1890 \item[CONFIGURE SLAVES] The slave configuration state machine is
       
  1891   executed until termination. $\rightarrow$~CONFIGURE SLAVES
       
  1892 
       
  1893   If there are still slaves in the wrong state after another check,
       
  1894   the first of these slaves is configured and brought into the correct
       
  1895   state again. $\rightarrow$~CONFIGURE SLAVES
       
  1896 
       
  1897   If all slaves are in the correct state, the state machine is
       
  1898   restarted. $\rightarrow$~START
       
  1899 
       
  1900 \item[VALIDATE VENDOR] The SII state machine is executed until
       
  1901   termination. If the slave has the wrong vendor ID, the state machine
       
  1902   is restarted. $\rightarrow$~START
       
  1903 
       
  1904   If the slave has the correct vendor ID, its product ID is queried.
       
  1905   $\rightarrow$~VALIDATE PRODUCT
       
  1906 
       
  1907 \item[VALIDATE PRODUCT] The SII state machine is executed until
       
  1908   termination. If the slave has the wrong product ID, the state
       
  1909   machine is restarted. $\rightarrow$~START
       
  1910 
       
  1911   If the slave has the correct product ID, the next slave's vendor ID
       
  1912   is queried. $\rightarrow$~VALIDATE VENDOR
       
  1913 
       
  1914   If all slaves have the correct vendor IDs and product codes, the
       
  1915   configured station addresses can be safely rewritten. This is done
       
  1916   for the first slave marked as offline.
       
  1917   $\rightarrow$~REWRITE ADDRESSES
       
  1918 
       
  1919 \item[REWRITE ADDRESSES] If the station address was successfully written, it is
       
  1920 searched for the next slave marked as offline. If there is one, its address is
       
  1921 reconfigured, too.  $\rightarrow$~REWRITE ADDRESSES
       
  1922 
       
  1923   If there are no more slaves marked as offline, the state machine is
       
  1924   restarted. $\rightarrow$~START
       
  1925 \end{description}
       
  1926 
       
  1927 %------------------------------------------------------------------------------
       
  1928 
       
  1929 \section{The Idle State Machine}
       
  1930 \label{sec:fsm-idle}
       
  1931 \index{FSM!Idle}
       
  1932 
       
  1933 The Idle state machine is executed by a kernel thread, if no application is
       
  1934 connected. Its purpose is to make slave information available to user space,
       
  1935 operate EoE-capable slaves, read and write SII contents and test slave
       
  1936 functionality.  Figure~\ref{fig:fsm-idle} shows its transition diagram.
       
  1937 
       
  1938 \begin{figure}[htbp]
       
  1939   \centering
       
  1940   \includegraphics[width=.8\textwidth]{images/fsm-idle}
       
  1941   \caption{Transition diagram of the idle state machine}
       
  1942   \label{fig:fsm-idle}
       
  1943 \end{figure}
       
  1944 
       
  1945 \begin{description}
       
  1946 \item[START] The beginning state of the idle state machine. Similar to
       
  1947   the operation state machine, a broadcast datagram is issued, to
       
  1948   query all slave states and the number of slaves.
       
  1949   $\rightarrow$~BROADCAST
       
  1950 
       
  1951 \item[BROADCAST] The number of responding slaves is evaluated. If it
       
  1952   has changed since the last time, this is treated as a topology
       
  1953   change and the internal list of slaves is cleared and rebuild
       
  1954   completely. The slave scan state machine is started for the first
       
  1955   slave. $\rightarrow$~SCAN FOR SLAVES
       
  1956 
       
  1957   If no topology change happened, every single slave state is fetched.
       
  1958   $\rightarrow$~READ STATES
       
  1959 
       
  1960 \item[SCAN FOR SLAVES] The slave scan state machine is executed until
       
  1961   termination. $\rightarrow$~SCAN FOR SLAVES
       
  1962 
       
  1963   If there is another slave to scan, the slave scan state machine is
       
  1964   started again. $\rightarrow$~SCAN FOR SLAVES
       
  1965 
       
  1966   If all slave information has been fetched, slave addresses are
       
  1967   calculated and EoE processing is started. Then, the state machine is
       
  1968   restarted. $\rightarrow$~START
       
  1969 
       
  1970 \item[READ STATES] If the slave did not respond to the query, it is
       
  1971   marked as offline. The next slave is queried.
       
  1972   $\rightarrow$~READ STATES
       
  1973 
       
  1974   If the slave responded, it is marked as online. And the next slave
       
  1975   is queried. $\rightarrow$~READ STATES
       
  1976 
       
  1977   If all slave states have been determined, it is checked, if any
       
  1978   slaves are not in the state they supposed to be. If this is true,
       
  1979   the slave configuration state machine is started for the first of
       
  1980   them. $\rightarrow$~CONFIGURE SLAVES
       
  1981 
       
  1982   If all slaves are in the correct state, it is checked, if any
       
  1983   E$^2$PROM write operations are pending. If this is true, the first
       
  1984   pending operation is executed by starting the SII state machine for
       
  1985   writing access. $\rightarrow$~WRITE EEPROM
       
  1986 
       
  1987   If all these conditions are false, there is nothing to do and the
       
  1988   state machine is restarted. $\rightarrow$~START
       
  1989 
       
  1990 \item[CONFIGURE SLAVES] The slave configuration state machine is
       
  1991   executed until termination. $\rightarrow$~CONFIGURE SLAVES
       
  1992 
       
  1993   After this, it is checked, if another slave needs a state change. If
       
  1994   this is true, the slave state change state machine is started for
       
  1995   this slave. $\rightarrow$~CONFIGURE SLAVES
       
  1996 
       
  1997   If all slaves are in the correct state, it is determined, if any
       
  1998   E$^2$PROM write operations are pending. If this is true, the first
       
  1999   pending operation is executed by starting the SII state machine for
       
  2000   writing access. $\rightarrow$~WRITE EEPROM
       
  2001 
       
  2002   If all prior conditions are false, the state machine is restarted.
       
  2003   $\rightarrow$~START
       
  2004 
       
  2005 \item[WRITE EEPROM] The SII state machine is executed until
       
  2006   termination. $\rightarrow$~WRITE EEPROM
       
  2007 
       
  2008   If the current word has been written successfully, and there are
       
  2009   still word to write, the SII state machine is started for the next
       
  2010   word. $\rightarrow$~WRITE EEPROM
       
  2011 
       
  2012   If all words have been written successfully, the new E$^2$PROM
       
  2013   contents are evaluated and the state machine is restarted.
       
  2014   $\rightarrow$~START
       
  2015 
  1375 
  2016 \end{description}
  1376 \end{description}
  2017 
  1377 
  2018 %------------------------------------------------------------------------------
  1378 %------------------------------------------------------------------------------
  2019 
  1379 
  2020 \section{The Slave Scan State Machine}
  1380 \section{The Slave Scan State Machine}
  2021 \label{sec:fsm-scan}
  1381 \label{sec:fsm-scan}
  2022 \index{FSM!Slave Scan}
  1382 \index{FSM!Slave Scan}
  2023 
  1383 
  2024 The slave scan state machine, which can be seen in
  1384 The slave scan state machine, which can be seen in
  2025 figure~\ref{fig:fsm-slavescan}, leads through the process of fetching
  1385 figure~\ref{fig:fsm-slavescan}, leads through the process of reading desired
  2026 all slave information.
  1386 slave information.
  2027 
  1387 
  2028 \begin{figure}[htbp]
  1388 \begin{figure}[htbp]
  2029   \centering
  1389   \centering
  2030   \includegraphics[width=.6\textwidth]{images/fsm-slavescan}
  1390   \includegraphics[height=.8\textheight]{graphs/fsm_slave_scan}
  2031   \caption{Transition diagram of the slave scan state machine}
  1391   \caption{Transition diagram of the slave scan state machine}
  2032   \label{fig:fsm-slavescan}
  1392   \label{fig:fsm-slavescan}
  2033 \end{figure}
  1393 \end{figure}
  2034 
  1394 
       
  1395 The scan process includes the following steps:
       
  1396 
  2035 \begin{description}
  1397 \begin{description}
  2036 \item[START] In the beginning state of the slave scan state machine,
  1398 
  2037   the station address is written to the slave, which is always the
  1399 \item[Node Address] The node address is set for the slave, so that it can be
  2038   ring position~+~$1$. In this way, the address 0x0000 (default
  1400 node-addressed for all following operations.
  2039   address) is not used, which makes it easy to detect unconfigured
  1401 
  2040   slaves.  $\rightarrow$~ADDRESS
  1402 \item[AL State] The initial application-layer state is read.
  2041 
  1403 
  2042 \item[ADDRESS] The writing of the station address is verified. After
  1404 \item[Base Information] Base information (like the number of supported FMMUs)
  2043   that, the slave's ``AL Control Response'' attribute is queried.
  1405 is read from the lower physical memory.
  2044   $\rightarrow$~STATE
  1406 
  2045 
  1407 \item[Data Link] Information about the physical ports is read.
  2046 \item[STATE] The AL state is evaluated. A warning is output, if the
  1408 
  2047   slave has still the \textit{Change} bit set. After that, the slave's
  1409 \item[SII Size] The size of the SII contents is determined to allocate SII
  2048   ``DL Information'' attribute is queried.
  1410 image memory.
  2049   $\rightarrow$~BASE
  1411 
  2050 
  1412 \item[SII Data] The SII contents are read into the master's image.
  2051 \item[BASE] The queried base data are evaluated: Slave type, revision
  1413 
  2052   and build number, and even more important, the number of supported
  1414 \item[PREOP] If the slave supports CoE, it is set to PREOP state using the
  2053   sync managers and FMMUs are stored. After that, the slave's data
  1415 State change FSM (see section~\ref{sec:fsm-change}) to enable mailbox
  2054   link layer information is read from the ``DL Status'' attribute at
  1416 communication and read the Pdo configuration via CoE.
  2055   address 0x0110. $\rightarrow$~DATALINK
  1417 
  2056 
  1418 \item[Pdos] The Pdos are read via CoE (if supported) using the Pdo FSM (see
  2057 \item[DATALINK] In this state, the DL information is evaluated: This
  1419 section~\ref{sec:fsm-pdo}). If this is successful, the Pdo information from
  2058   information about the communication ports contains, if the link is
  1420 the SII (if any) is overwritten.
  2059   up, if the loop has been closed and if there is a carrier detected
       
  2060   on the RX side of each port.
       
  2061 
       
  2062   Then, the state machine starts measuring the size of the slave's
       
  2063   E$^2$PROM contents. This is done by subsequently reading out each
       
  2064   category header, until the last category is reached (type 0xFFFF).
       
  2065   This procedure is started by querying the first category header at
       
  2066   word address 0x0040 via the SII state machine.
       
  2067   $\rightarrow$~EEPROM SIZE
       
  2068 
       
  2069 \item[EEPROM SIZE] The SII state machine is executed until
       
  2070   termination. $\rightarrow$~EEPROM SIZE
       
  2071 
       
  2072   If the category type does not mark the end of the categories, the
       
  2073   position of the next category header is determined via the length of
       
  2074   the current category, and the SII state machine is started again.
       
  2075   $\rightarrow$~EEPROM SIZE
       
  2076 
       
  2077   If the size of the E$^2$PROM contents has been determined, memory is
       
  2078   allocated, to read all the contents. The SII state machine is
       
  2079   started to read the first word. $\rightarrow$~EEPROM DATA
       
  2080 
       
  2081 \item[EEPROM DATA] The SII state machine is executed until
       
  2082   termination. $\rightarrow$~EEPROM DATA
       
  2083 
       
  2084   Two words have been read. If more than one word is needed, the two
       
  2085   words are written in the allocated memory. Otherwise only one word
       
  2086   (the last word) is copied. If more words are to read, the SII state
       
  2087   machine is started again to read the next two words.
       
  2088   $\rightarrow$~EEPROM DATA
       
  2089 
       
  2090   The complete E$^2$PROM contents have been read. The slave's identity
       
  2091   object and mailbox information are evaluated. Moreover the category
       
  2092   types STRINGS, GENERAL, SYNC and PDO are evaluated. The slave
       
  2093   scanning has been completed. $\rightarrow$~END
       
  2094 
       
  2095 \item[END] Slave scanning has been finished.
       
  2096 
  1421 
  2097 \end{description}
  1422 \end{description}
       
  1423 
       
  1424 %------------------------------------------------------------------------------
       
  1425 
       
  1426 %     SII
       
  1427 %     Pdo assign/mapping
       
  1428 %   Slave configuration
       
  1429 %     State change
       
  1430 %     Pdo assign/mapping
       
  1431 %   CoE upload/download/information
  2098 
  1432 
  2099 %------------------------------------------------------------------------------
  1433 %------------------------------------------------------------------------------
  2100 
  1434 
  2101 \section{The Slave Configuration State Machine}
  1435 \section{The Slave Configuration State Machine}
  2102 \label{sec:fsm-conf}
  1436 \label{sec:fsm-conf}
  2103 \index{FSM!Slave Configuration}
  1437 \index{FSM!Slave Configuration}
  2104 
  1438 
  2105 The slave configuration state machine, which can be seen in
  1439 The slave configuration state machine, which can be seen in
  2106 figure~\ref{fig:fsm-slaveconf}, leads through the process of
  1440 figure~\ref{fig:fsm-slaveconf}, leads through the process of configuring a
  2107 configuring a slave and bringing it to a certain state.
  1441 slave and bringing it to a certain application-layer state.
  2108 
  1442 
  2109 \begin{figure}[htbp]
  1443 \begin{figure}[htbp]
  2110   \centering
  1444   \centering
  2111   \includegraphics[width=.6\textwidth]{images/fsm-slaveconf}
  1445   \includegraphics[height=.9\textheight]{graphs/fsm_slave_conf}
  2112   \caption{Transition diagram of the slave configuration state
  1446   \caption{Transition diagram of the slave configuration state
  2113     machine}
  1447     machine}
  2114   \label{fig:fsm-slaveconf}
  1448   \label{fig:fsm-slaveconf}
  2115 \end{figure}
  1449 \end{figure}
  2116 
  1450 
  2117 \begin{description}
  1451 \begin{description}
  2118 \item[INIT] The state change state machine has been initialized to
  1452 
  2119   bring the slave into the INIT state. Now, the slave state change
  1453 \item[INIT] The state change FSM is used to bring the slave to the INIT state.
  2120   state machine is executed until termination. $\rightarrow$~INIT
  1454 
  2121 
  1455 \item[FMMU Clearing] To avoid that the slave reacts on any process data, the
  2122   If the slave state change failed, the configuration has to be
  1456 FMMU configuration are cleared. If the slave does not support FMMUs, this
  2123   aborted. $\rightarrow$~END
  1457 state is skipped. If INIT is the requested state, the state machine is
  2124 
  1458 finished.
  2125   The slave state change succeeded and the slave is now in INIT state.
  1459 
  2126   If this is the target state, the configuration is finished.
  1460 \item[Mailbox Sync Manager Configuration] If the slaves support mailbox
  2127   $\rightarrow$~END
  1461 communication, the mailbox sync managers are configured. Otherwise this state
  2128 
  1462 is skipped.
  2129   If the slave does not support any sync managers, the sync manager
  1463 
  2130   configuration can be skipped. The state change state machine is
  1464 \item[PREOP] The state change FSM is used to bring the slave to PREOP state.
  2131   started to bring the slave into PREOP state.
  1465 If this is the requested state, the state machine is finished.
  2132   $\rightarrow$~PREOP
  1466 
  2133 
  1467 \item[Sdo Configuration] If there is a slave configuration attached
  2134   Sync managers are configured conforming to the sync manager category
  1468 (see section~\ref{sec:attach}), and there are any Sdo configurations are
  2135   information provided in the slave's E$^2$PROM. The corresponding
  1469 provided by the application, these are sent to the slave.
  2136   datagram is issued. $\rightarrow$~SYNC
  1470 
  2137 
  1471 \item[Pdo Configuration] The Pdo configuration state machine is executed to
  2138 \item[SYNC] If the sync manager configuration datagram is accepted,
  1472 apply all necessary Pdo configurations.
  2139   the sync manager configuration was successful. The slave may now
  1473 
  2140   enter the PREOP state, and the state change state machine is
  1474 \item[Pdo Sync Manager Configuration] If any Pdo sync managers exist, they are
  2141   started. $\rightarrow$~PREOP
  1475 configured.
  2142 
  1476 
  2143 \item[PREOP] The state change state machine is executed until
  1477 \item[FMMU Configuration] If there are FMMUs configurations supplied by the
  2144   termination. $\rightarrow$~PREOP
  1478 application (i.~e. if the application registered Pdo entries), they are
  2145 
  1479 applied. 
  2146   If the state change failed, the configuration has to be aborted.
  1480 
  2147   $\rightarrow$~END
  1481 \item[SAFEOP] The state change FSM is used to bring the slave to SAFEOP state.
  2148 
  1482 If this is the requested state, the state machine is finished.
  2149   If the PREOP state was the target state, the configuration is
  1483 
  2150   finished. $\rightarrow$~END
  1484 \item[OP] The state change FSM is used to bring the slave to OP state.
  2151 
  1485 If this is the requested state, the state machine is finished.
  2152   If the slave supports no FMMUs, the FMMU configuration can be
       
  2153   skipped. If the slave has Sdos to configure, it is begun with
       
  2154   sending the first Sdo. $\rightarrow$~SDO\_CONF
       
  2155 
       
  2156   If no Sdo configurations are provided, the slave can now directly be
       
  2157   brought into the SAFEOP state and the state change state machine is
       
  2158   started again. $\rightarrow$~SAFEOP
       
  2159 
       
  2160   Otherwise, all supported FMMUs are configured according to the Pdos
       
  2161   requested via the master's realtime interface. The appropriate
       
  2162   datagram is issued. $\rightarrow$~FMMU
       
  2163 
       
  2164 \item[FMMU] The FMMU configuration datagram was accepted. If the slave
       
  2165   has Sdos to configure, it is begun with sending the first Sdo.
       
  2166   $\rightarrow$~SDO\_CONF
       
  2167 
       
  2168   Otherwise, the slave can now be brought into the SAFEOP state. The
       
  2169   state change state machine is started.
       
  2170   $\rightarrow$~SAFEOP
       
  2171 
       
  2172 \item[SDO\_CONF] The CoE state machine is executed until termination.
       
  2173   $\rightarrow$~SDO\_CONF
       
  2174 
       
  2175   If another Sdo has to be configured, a new Sdo download sequence is
       
  2176   begun. $\rightarrow$~SDO\_CONF
       
  2177 
       
  2178   Otherwise, the slave can now be brought into the SAFEOP state. The
       
  2179   state change state machine is started.
       
  2180   $\rightarrow$~SAFEOP
       
  2181 
       
  2182 \item[SAFEOP] The state change state machine is executed until
       
  2183   termination. $\rightarrow$~SAFEOP
       
  2184 
       
  2185   If the state change failed, the configuration has to be aborted.
       
  2186   $\rightarrow$~END
       
  2187 
       
  2188   If the SAFEOP state was the target state, the configuration is
       
  2189   finished. $\rightarrow$~END
       
  2190 
       
  2191   The slave can now directly be brought into the OP state and the
       
  2192   state change state machine is started a last time.
       
  2193   $\rightarrow$~OP
       
  2194 
       
  2195 \item[OP] The state change state machine is executed until
       
  2196   termination. $\rightarrow$~OP
       
  2197 
       
  2198   If the state change state machine terminates, the slave
       
  2199   configuration is finished, regardless of its success.
       
  2200   $\rightarrow$~END
       
  2201 
       
  2202 \item[END] The termination state.
       
  2203 
  1486 
  2204 \end{description}
  1487 \end{description}
  2205 
  1488 
  2206 %------------------------------------------------------------------------------
  1489 %------------------------------------------------------------------------------
  2207 
  1490 
  2208 \section{The State Change State Machine}
  1491 \section{The State Change State Machine}
  2209 \label{sec:fsm-change}
  1492 \label{sec:fsm-change}
  2210 \index{FSM!State Change}
  1493 \index{FSM!State Change}
  2211 
  1494 
  2212 The state change state machine, which can be seen in
  1495 The state change state machine, which can be seen in
  2213 figure~\ref{fig:fsm-change}, leads through the process of changing a
  1496 figure~\ref{fig:fsm-change}, leads through the process of changing a slave's
  2214 slave's state. This implements the states and transitions described in
  1497 application-layer state. This implements the states and transitions described
  2215 \cite[section~6.4.1]{alspec}.
  1498 in \cite[section~6.4.1]{alspec}.
  2216 
  1499 
  2217 \begin{figure}[htbp]
  1500 \begin{figure}[htbp]
  2218   \centering
  1501   \centering
  2219   \includegraphics[width=.9\textwidth]{images/fsm-change}
  1502   \includegraphics[width=.9\textwidth]{images/fsm-change} % FIXME
  2220   \caption{Transition diagram of the state change state machine}
  1503   \caption{Transition Diagram of the State Change State Machine}
  2221   \label{fig:fsm-change}
  1504   \label{fig:fsm-change}
  2222 \end{figure}
  1505 \end{figure}
       
  1506 
       
  1507 % FIXME
  2223 
  1508 
  2224 \begin{description}
  1509 \begin{description}
  2225 \item[START] The beginning state, where a datagram with the state
  1510 \item[START] The beginning state, where a datagram with the state
  2226   change command is written to the slave's ``AL Control Request''
  1511   change command is written to the slave's ``AL Control Request''
  2227   attribute. Nothing can fail. $\rightarrow$~CHECK
  1512   attribute. Nothing can fail. $\rightarrow$~CHECK
  2281 \section{The SII State Machine}
  1566 \section{The SII State Machine}
  2282 \label{sec:fsm-sii}
  1567 \label{sec:fsm-sii}
  2283 \index{FSM!SII}
  1568 \index{FSM!SII}
  2284 
  1569 
  2285 The SII\index{SII} state machine (shown in figure~\ref{fig:fsm-sii})
  1570 The SII\index{SII} state machine (shown in figure~\ref{fig:fsm-sii})
  2286 implements the process of reading or writing E$^2$PROM data via the
  1571 implements the process of reading or writing SII data via the
  2287 Slave Information Interface described in \cite[section~5.4]{alspec}.
  1572 Slave Information Interface described in \cite[section~6.4]{dlspec}.
  2288 
  1573 
  2289 \begin{figure}[htbp]
  1574 \begin{figure}[htbp]
  2290   \centering
  1575   \centering
  2291   \includegraphics[width=.9\textwidth]{images/fsm-sii}
  1576   \includegraphics[width=.9\textwidth]{images/fsm-sii} % FIXME
  2292   \caption{Transition diagram of the SII state machine}
  1577   \caption{Transition Diagram of the SII State Machine}
  2293   \label{fig:fsm-sii}
  1578   \label{fig:fsm-sii}
  2294 \end{figure}
  1579 \end{figure}
       
  1580 
       
  1581 % FIXME
  2295 
  1582 
  2296 \begin{description}
  1583 \begin{description}
  2297 \item[READ\_START] The beginning state for reading access, where the
  1584 \item[READ\_START] The beginning state for reading access, where the
  2298   read request and the requested address are written to the SII
  1585   read request and the requested address are written to the SII
  2299   attribute. Nothing can fail up to now.
  1586   attribute. Nothing can fail up to now.
  2355 
  1642 
  2356 \section{Ethernet-over-EtherCAT (EoE)}
  1643 \section{Ethernet-over-EtherCAT (EoE)}
  2357 \label{sec:eoeimp}
  1644 \label{sec:eoeimp}
  2358 \index{EoE}
  1645 \index{EoE}
  2359 
  1646 
  2360 The EtherCAT master implements the Ethernet-over-EtherCAT mailbox
  1647 The EtherCAT master implements the Ethernet-over-EtherCAT mailbox protocol to
  2361 protocol to enable the tunneling of Ethernet frames to special slaves,
  1648 enable the tunneling of Ethernet frames to special slaves, that can either
  2362 that can either have physical Ethernet ports to forward the frames to,
  1649 have physical Ethernet ports to forward the frames to, or have an own IP stack
  2363 or have an own IP stack to receive the frames.
  1650 to receive the frames.
  2364 
  1651 
  2365 \paragraph{Virtual Network Interfaces}
  1652 \paragraph{Virtual Network Interfaces}
  2366 
  1653 
  2367 The master creates a virtual EoE network interface for every
  1654 The master creates a virtual EoE network interface for every EoE-capable
  2368 EoE-capable slave. These interfaces are called \textit{eoeX}, where X
  1655 slave. These interfaces are called either
  2369 is a number provided by the kernel on interface registration. Frames
  1656 
  2370 sent to these interfaces are forwarded to the associated slaves by the
  1657 \begin{description}
  2371 master. Frames, that are received by the slaves, are fetched by the
  1658 
  2372 master and forwarded to the virtual interfaces.
  1659 \item[eoeXsY] for a slave without an alias address (see
       
  1660 section~\ref{sec:alias}), where X is the master index and Y is the slave's
       
  1661 ring position, or
       
  1662 
       
  1663 \item[eoeXaY] for a slave with a non-zero alias address, where X is the master
       
  1664 index and Y is the decimal alias address.
       
  1665 
       
  1666 \end{description}
       
  1667 
       
  1668 Frames sent to these interfaces are forwarded to the associated slaves by the
       
  1669 master. Frames, that are received by the slaves, are fetched by the master and
       
  1670 forwarded to the virtual interfaces.
  2373 
  1671 
  2374 This bears the following advantages:
  1672 This bears the following advantages:
  2375 
  1673 
  2376 \begin{itemize}
  1674 \begin{itemize}
       
  1675 
  2377 \item Flexibility: The user can decide, how the EoE-capable slaves are
  1676 \item Flexibility: The user can decide, how the EoE-capable slaves are
  2378   interconnected with the rest of the world.
  1677 interconnected with the rest of the world.
  2379 \item Standard tools can be used to monitor the EoE activity and to
  1678 
  2380   configure the EoE interfaces.
  1679 \item Standard tools can be used to monitor the EoE activity and to configure
  2381 \item The Linux kernel's layer-2-bridging implementation (according to
  1680 the EoE interfaces.
  2382   the IEEE 802.1D MAC Bridging standard) can be used natively to
  1681 
  2383   bridge Ethernet traffic between EoE-capable slaves.
  1682 \item The Linux kernel's layer-2-bridging implementation (according to the
  2384 \item The Linux kernel's network stack can be used to route packets
  1683 IEEE 802.1D MAC Bridging standard) can be used natively to bridge Ethernet
  2385   between EoE-capable slaves and to track security issues, just like
  1684 traffic between EoE-capable slaves.
  2386   having physical network interfaces.
  1685 
       
  1686 \item The Linux kernel's network stack can be used to route packets between
       
  1687 EoE-capable slaves and to track security issues, just like having physical
       
  1688 network interfaces.
       
  1689 
  2387 \end{itemize}
  1690 \end{itemize}
  2388 
  1691 
  2389 \paragraph{EoE Handlers}
  1692 \paragraph{EoE Handlers}
  2390 
  1693 
  2391 The virtual EoE interfaces and the related functionality is encapsulated in the
  1694 The virtual EoE interfaces and the related functionality is encapsulated in
  2392 \textit{ec\_eoe\_t} class (see section~\ref{sec:class-eoe}).  So the master
  1695 the \lstinline+ec_eoe_t+ class. An object of this class is called ``EoE
  2393 does not create the network interfaces directly: This is done inside the
  1696 handler''. For example the master does not create the network interfaces
  2394 constructor of the \textit{ec\_eoe\_t} class. An object of this class is called
  1697 directly: This is done inside the constructor of an EoE handler. An EoE
  2395 ``EoE handler'' below. An EoE handler additionally contains a frame queue. Each
  1698 handler additionally contains a frame queue. Each time, the kernel passes a
  2396 time, the kernel passes a new socket buffer for sending via the interface's
  1699 new socket buffer for sending via the interface's
  2397 \textit{hard\_start\_xmit()} callback, the socket buffer is queued for
  1700 \lstinline+hard_start_xmit()+ callback, the socket buffer is queued for
  2398 transmission by the EoE state machine (see below). If the queue gets filled up,
  1701 transmission by the EoE state machine (see below). If the queue gets filled
  2399 the passing of new socket buffers is suspended with a call to
  1702 up, the passing of new socket buffers is suspended with a call to
  2400 \textit{netif\_stop\_queue()}.
  1703 \lstinline+netif_stop_queue()+.
  2401 
  1704 
  2402 \paragraph{Static Handler Creation}
  1705 \paragraph{Creation of EoE Handlers}
  2403 
  1706 
  2404 The master creates a pool of EoE handlers at startup, that are coupled
  1707 During bus scanning (see section~\ref{sec:fsm-scan}), the master determines
  2405 to EoE-capable slaves on demand. The lifetime of the corresponding
  1708 the supported mailbox protocols foe each slave. This is done by examining the
  2406 network interfaces is equal to the lifetime of the master module.
  1709 ``Supported Mailbox Protocols'' mask field at word address 0x001C of the
  2407 This approach is opposed to creating the virtual network interfaces on
  1710 SII\index{SII}. If bit 1 is set, the slave supports the EoE protocol. In this
  2408 demand (i.~e. on running across a new EoE-capable slave). The latter
  1711 case, an EoE handler is created for that slave.
  2409 approach was considered as difficult, because of several reasons:
       
  2410 
       
  2411 \begin{itemize}
       
  2412 \item The \textit{alloc\_netdev()} function can sleep and must be
       
  2413   called from a non-interrupt context. This reduces the flexibility of
       
  2414   choosing an appropriate method for cyclic EoE processing.
       
  2415 \item Unregistering network interfaces requires them to be ``down'',
       
  2416   which can not be guaranteed upon sudden disappearing of an
       
  2417   EoE-capable slave.
       
  2418 \item The connection to the EoE-capable slaves must be as continuous
       
  2419   as possible. Especially the transition from idle to operation mode
       
  2420   (and vice versa) causes the rebuilding of the internal data
       
  2421   structures. These transitions must be as transparent as possible for
       
  2422   the instances using the network interfaces.
       
  2423 \end{itemize}
       
  2424 
       
  2425 \paragraph{Number of Handlers} % FIXME
       
  2426 
       
  2427 The master module has a parameter \textit{ec\_eoeif\_count} to specify
       
  2428 the number of EoE interfaces (and handlers) per master to create. This
       
  2429 parameter can either be specified when manually loading the master
       
  2430 module, or (when using the init script) by setting the
       
  2431 \$EOE\_INTERFACES variable in the sysconfig file (see
       
  2432 section~\ref{sec:sysconfig}). Upon loading of the master module, the
       
  2433 virtual interfaces become available:
       
  2434 
       
  2435 \begin{lstlisting}[gobble=2]
       
  2436   # `\textbf{ifconfig -a}`
       
  2437   eoe0      Link encap:Ethernet  HWaddr 00:11:22:33:44:06
       
  2438             BROADCAST MULTICAST  MTU:1500  Metric:1
       
  2439             RX packets:0 errors:0 dropped:0 overruns:0 frame:0
       
  2440             TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
       
  2441             collisions:0 txqueuelen:1000
       
  2442             RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)
       
  2443 
       
  2444   eoe1      Link encap:Ethernet  HWaddr 00:11:22:33:44:07
       
  2445             BROADCAST MULTICAST  MTU:1500  Metric:1
       
  2446             RX packets:0 errors:0 dropped:0 overruns:0 frame:0
       
  2447             TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
       
  2448             collisions:0 txqueuelen:1000
       
  2449             RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)
       
  2450   ...
       
  2451 \end{lstlisting}
       
  2452 
       
  2453 \paragraph{Coupling of EoE Slaves}
       
  2454 
       
  2455 During execution of the slave scan state machine (see
       
  2456 section~\ref{sec:fsm-scan}), the master determines the supported
       
  2457 mailbox protocols. This is done by examining the ``Supported Mailbox
       
  2458 Protocols'' mask field at word address 0x001C of the SII\index{SII}.
       
  2459 If bit 1 is set, the slave supports the EoE protocol. After slave
       
  2460 scanning, the master runs through all slaves again and couples each
       
  2461 EoE-capable slave to a free EoE handler. It can happen, that there are
       
  2462 not enough EoE handlers to cover all EoE-capable slaves. In this case,
       
  2463 the number of EoE handlers must be increased accordingly.
       
  2464 
  1712 
  2465 \paragraph{EoE State Machine}
  1713 \paragraph{EoE State Machine}
  2466 \index{FSM!EoE}
  1714 \index{FSM!EoE}
  2467 
  1715 
  2468 Every EoE handler owns an EoE state machine, that is used to send
  1716 Every EoE handler owns an EoE state machine, that is used to send frames to
  2469 frames to the coupled slave and receive frames from the it via the EoE
  1717 the corresponding slave and receive frames from the it via the EoE
  2470 communication primitives. This state machine is showed in
  1718 communication primitives. This state machine is showed in
  2471 figure~\ref{fig:fsm-eoe}.
  1719 figure~\ref{fig:fsm-eoe}.
  2472 
  1720 
  2473 \begin{figure}[htbp]
  1721 \begin{figure}[htbp]
  2474   \centering
  1722   \centering
  2475   \includegraphics[width=.7\textwidth]{images/fsm-eoe}
  1723   \includegraphics[width=.7\textwidth]{images/fsm-eoe} % FIXME
  2476   \caption{Transition diagram of the EoE state machine}
  1724   \caption{Transition Diagram of the EoE State Machine}
  2477   \label{fig:fsm-eoe}
  1725   \label{fig:fsm-eoe}
  2478 \end{figure}
  1726 \end{figure}
       
  1727 
       
  1728 % FIXME
  2479 
  1729 
  2480 \begin{description}
  1730 \begin{description}
  2481 \item[RX\_START] The beginning state of the EoE state machine. A
  1731 \item[RX\_START] The beginning state of the EoE state machine. A
  2482   mailbox check datagram is sent, to query the slave's mailbox for new
  1732   mailbox check datagram is sent, to query the slave's mailbox for new
  2483   frames. $\rightarrow$~RX\_CHECK
  1733   frames. $\rightarrow$~RX\_CHECK
  2522   $\rightarrow$~RX\_START
  1772   $\rightarrow$~RX\_START
  2523 \end{description}
  1773 \end{description}
  2524 
  1774 
  2525 \paragraph{EoE Processing}
  1775 \paragraph{EoE Processing}
  2526 
  1776 
  2527 To execute the EoE state machine of every active EoE handler, there
  1777 To execute the EoE state machine of every active EoE handler, there must be a
  2528 must be a cyclic process. The easiest thing would be to execute the
  1778 cyclic process. The easiest solution would be to execute the EoE state
  2529 EoE state machines synchronously to the operation state machine (see
  1779 machines synchronously with the master state machine (see
  2530 section~\ref{sec:fsm-op}) with every realtime cycle. This approach has
  1780 section~\ref{sec:fsm-master}). This approach has the following disadvantage:
  2531 the following disadvantages:
  1781 
  2532 
  1782 Only one EoE fragment could be sent or received every few cycles. This
  2533 \begin{itemize}
       
  2534 
       
  2535 \item Only one EoE fragment can be sent or received every few cycles.  This
       
  2536 causes the data rate to be very low, because the EoE state machines are not
  1783 causes the data rate to be very low, because the EoE state machines are not
  2537 executed in the time between the application cycles. Moreover, the data rate
  1784 executed in the time between the application cycles. Moreover, the data rate
  2538 would be dependent on the period of the application task.
  1785 would be dependent on the period of the application task.
  2539 
  1786 
  2540 \item The receiving and forwarding of frames to the kernel requires the dynamic
  1787 To overcome this problem, an own cyclic process is needed to asynchronously
  2541 allocation of frames. Some realtime extensions do not support calling memory
  1788 execute the EoE state machines. For that, the master owns a kernel timer, that
  2542 allocation functions in realtime context, so the EoE state machine may not be
  1789 is executed each timer interrupt. This guarantees a constant bandwidth, but
  2543 executed with each application cycle.
  1790 poses the new problem of concurrent access to the master. The locking
  2544 
  1791 mechanisms needed for this are introduced in section~\ref{sec:concurr}.
  2545 \end{itemize}
       
  2546 
       
  2547 To overcome these problems, an own cyclic process is needed to
       
  2548 asynchronously execute the EoE state machines. For that, the master
       
  2549 owns a kernel timer, that is executed each timer interrupt. This
       
  2550 guarantees a constant bandwidth, but poses the new problem of
       
  2551 concurrent access to the master. The locking mechanisms needed for
       
  2552 this are introduced in section~\ref{sec:concurr}.
       
  2553 Section~\ref{sec:concurrency} gives practical implementation examples.
  1792 Section~\ref{sec:concurrency} gives practical implementation examples.
  2554 
  1793 
  2555 \paragraph{Idle phase}
       
  2556 
       
  2557 EoE data must also be exchanged in idle phase, to guarantee the continuous
       
  2558 availability of the connection to the EoE-capable slaves. Although there is no
       
  2559 application connected in this case, the master is still accessed by the master
       
  2560 state machine (see section~\ref{sec:fsm-master}). With the EoE timer running in
       
  2561 addition, there is still concurrency, that has to be protected by a lock.
       
  2562 Therefore the master owns an internal spinlock that is used protect master
       
  2563 access during idle phase.
       
  2564 
       
  2565 \paragraph{Automatic Configuration}
  1794 \paragraph{Automatic Configuration}
  2566 
  1795 
  2567 By default, slaves are left in INIT state during idle mode. If an EoE
  1796 By default, slaves are left in PREOP state, if no configuration is applied. If
  2568 interface is set to running state (i.~e. with the \textit{ifconfig up}
  1797 an EoE interface link is set to ``up'', the requested slave's
  2569 command), the requested slave state of the related slave is
  1798 application-layer state is automatically set to OP.
  2570 automatically set to OP, whereupon the idle state machine will attempt
       
  2571 to configure the slave and put it into operation.
       
  2572 
  1799 
  2573 %------------------------------------------------------------------------------
  1800 %------------------------------------------------------------------------------
  2574 
  1801 
  2575 \section{CANopen-over-EtherCAT (CoE)}
  1802 \section{CANopen-over-EtherCAT (CoE)}
  2576 \label{sec:coeimp}
  1803 \label{sec:coeimp}
  2577 \index{CoE}
  1804 \index{CoE}
  2578 
  1805 
  2579 The CANopen-over-EtherCAT protocol \cite[section~5.6]{alspec} is used
  1806 The CANopen-over-EtherCAT protocol \cite[section~5.6]{alspec} is used to
  2580 to configure slaves on application level. Each CoE-capable slave
  1807 configure slaves and exchange data objects on application level.
  2581 provides a list of Sdos for this reason.
  1808 
  2582 
  1809 % FIXME
  2583 \paragraph{Sdo Configuration}
       
  2584 
       
  2585 The Sdo configurations have to be provided by the application.  This is done
       
  2586 via the \textit{ecrt\_slave\_conf\_sdo*()} methods (see
       
  2587 section~\ref{sec:ecrt-slave}), that are part of the realtime interface. The
       
  2588 slave stores the Sdo configurations in a linked list, but does not apply them
       
  2589 at once.
       
  2590 
  1810 
  2591 \paragraph{Sdo Download State Machine}
  1811 \paragraph{Sdo Download State Machine}
  2592 
  1812 
  2593 The best time to apply Sdo configurations is during the slave's PREOP
  1813 The best time to apply Sdo configurations is during the slave's PREOP
  2594 state, because mailbox communication is already possible and slave's
  1814 state, because mailbox communication is already possible and slave's
  2603 The transition diagram of the Sdo Download state machine can be seen
  1823 The transition diagram of the Sdo Download state machine can be seen
  2604 in figure~\ref{fig:fsm-coedown}.
  1824 in figure~\ref{fig:fsm-coedown}.
  2605 
  1825 
  2606 \begin{figure}[htbp]
  1826 \begin{figure}[htbp]
  2607   \centering
  1827   \centering
  2608   \includegraphics[width=.9\textwidth]{images/fsm-coedown}
  1828   \includegraphics[width=.9\textwidth]{images/fsm-coedown} % FIXME
  2609   \caption{Transition diagram of the CoE download state machine}
  1829   \caption{Transition diagram of the CoE download state machine}
  2610   \label{fig:fsm-coedown}
  1830   \label{fig:fsm-coedown}
  2611 \end{figure}
  1831 \end{figure}
       
  1832 
       
  1833 % FIXME
  2612 
  1834 
  2613 \begin{description}
  1835 \begin{description}
  2614 \item[START] The beginning state of the CoE download state
  1836 \item[START] The beginning state of the CoE download state
  2615   machine. The ``Sdo Download Normal Request'' mailbox command is
  1837   machine. The ``Sdo Download Normal Request'' mailbox command is
  2616   sent. $\rightarrow$~REQUEST
  1838   sent. $\rightarrow$~REQUEST
  2648 
  1870 
  2649 \chapter{User Space}
  1871 \chapter{User Space}
  2650 \label{sec:user}
  1872 \label{sec:user}
  2651 \index{User space}
  1873 \index{User space}
  2652 
  1874 
       
  1875 % FIXME
       
  1876 
  2653 For the master runs as a kernel module, accessing it is natively
  1877 For the master runs as a kernel module, accessing it is natively
  2654 limited to analyzing Syslog messages and controlling using modutils.
  1878 limited to analyzing Syslog messages and controlling using modutils.
  2655 
  1879 
  2656 It is necessary to implement further interfaces, that make it easier
  1880 It is necessary to implement further interfaces, that make it easier
  2657 to access the master from user space and allow a finer influence. It
  1881 to access the master from user space and allow a finer influence. It
  2678 \section{Command-line Tool}
  1902 \section{Command-line Tool}
  2679 \label{sec:ethercat}
  1903 \label{sec:ethercat}
  2680 
  1904 
  2681 % --master
  1905 % --master
  2682 
  1906 
  2683 \subsection{Character devices}
  1907 \subsection{Character Devices}
  2684 \label{sec:cdev}
  1908 \label{sec:cdev}
  2685 
  1909 
  2686 Each master instance will get a character device as a user-space interface.
  1910 Each master instance will get a character device as a user-space interface.
  2687 The devices are named \textit{/dev/EtherCATX}, where $X$ is the index of the
  1911 The devices are named \textit{/dev/EtherCATX}, where $X$ is the index of the
  2688 master.
  1912 master.
  2691 % udev
  1915 % udev
  2692 % rights
  1916 % rights
  2693 
  1917 
  2694 %------------------------------------------------------------------------------
  1918 %------------------------------------------------------------------------------
  2695 
  1919 
  2696 \subsection{Setting alias addresses}
  1920 \subsection{Setting Alias Addresses}
  2697 
  1921 
  2698 \lstinputlisting[basicstyle=\ttfamily\footnotesize]{external/ethercat_alias}
  1922 \lstinputlisting[basicstyle=\ttfamily\footnotesize]{external/ethercat_alias}
  2699 
  1923 
  2700 %------------------------------------------------------------------------------
  1924 %------------------------------------------------------------------------------
  2701 
  1925 
  2702 \subsection{Displaying the bus configuration}
  1926 \subsection{Displaying the Bus Configuration}
  2703 
  1927 
  2704 \lstinputlisting[basicstyle=\ttfamily\footnotesize]{external/ethercat_config}
  1928 \lstinputlisting[basicstyle=\ttfamily\footnotesize]{external/ethercat_config}
  2705 
  1929 
  2706 %------------------------------------------------------------------------------
  1930 %------------------------------------------------------------------------------
  2707 
  1931 
  2708 \subsection{Displaying process data}
  1932 \subsection{Displaying Process Data}
  2709 
  1933 
  2710 \lstinputlisting[basicstyle=\ttfamily\footnotesize]{external/ethercat_data}
  1934 \lstinputlisting[basicstyle=\ttfamily\footnotesize]{external/ethercat_data}
  2711 
  1935 
  2712 %------------------------------------------------------------------------------
  1936 %------------------------------------------------------------------------------
  2713 
  1937 
  2714 \subsection{Setting a master's debug level}
  1938 \subsection{Setting a Master's Debug Level}
  2715 
  1939 
  2716 \lstinputlisting[basicstyle=\ttfamily\footnotesize]{external/ethercat_debug}
  1940 \lstinputlisting[basicstyle=\ttfamily\footnotesize]{external/ethercat_debug}
  2717 
  1941 
  2718 %------------------------------------------------------------------------------
  1942 %------------------------------------------------------------------------------
  2719 
  1943 
  2720 \subsection{Configured domains}
  1944 \subsection{Configured Domains}
  2721 
  1945 
  2722 \lstinputlisting[basicstyle=\ttfamily\footnotesize]{external/ethercat_domains}
  1946 \lstinputlisting[basicstyle=\ttfamily\footnotesize]{external/ethercat_domains}
  2723 
  1947 
  2724 %------------------------------------------------------------------------------
  1948 %------------------------------------------------------------------------------
  2725 
  1949 
  2726 \subsection{Master and Ethernet device information}
  1950 \subsection{Master and Ethernet Devices}
  2727 
  1951 
  2728 \lstinputlisting[basicstyle=\ttfamily\footnotesize]{external/ethercat_master}
  1952 \lstinputlisting[basicstyle=\ttfamily\footnotesize]{external/ethercat_master}
  2729 
  1953 
  2730 %------------------------------------------------------------------------------
  1954 %------------------------------------------------------------------------------
  2731 
  1955 
  2732 \subsection{Showing slaves' sync managers, Pdos and Pdo entries}
  1956 \subsection{Sync Managers, Pdos and Pdo Entries}
  2733 
  1957 
  2734 \lstinputlisting[basicstyle=\ttfamily\footnotesize]{external/ethercat_pdos}
  1958 \lstinputlisting[basicstyle=\ttfamily\footnotesize]{external/ethercat_pdos}
  2735 
  1959 
  2736 %------------------------------------------------------------------------------
  1960 %------------------------------------------------------------------------------
  2737 
  1961 
  2738 \subsection{Displaying the Sdo dictionary}
  1962 \subsection{Sdo Dictionary}
  2739 
  1963 
  2740 \lstinputlisting[basicstyle=\ttfamily\footnotesize]{external/ethercat_sdos}
  1964 \lstinputlisting[basicstyle=\ttfamily\footnotesize]{external/ethercat_sdos}
  2741 
  1965 
  2742 %------------------------------------------------------------------------------
  1966 %------------------------------------------------------------------------------
  2743 
  1967 
  2744 \subsection{Sdo access}
  1968 \subsection{Sdo Access}
  2745 
  1969 
  2746 \lstinputlisting[basicstyle=\ttfamily\footnotesize]{external/ethercat_download}
  1970 \lstinputlisting[basicstyle=\ttfamily\footnotesize]{external/ethercat_download}
  2747 
  1971 
  2748 \lstinputlisting[basicstyle=\ttfamily\footnotesize]{external/ethercat_upload}
  1972 \lstinputlisting[basicstyle=\ttfamily\footnotesize]{external/ethercat_upload}
  2749 
  1973 
  2750 %------------------------------------------------------------------------------
  1974 %------------------------------------------------------------------------------
  2751 
  1975 
  2752 \subsection{Displaying slaves on the bus}
  1976 \subsection{Slaves on the Bus}
  2753 
  1977 
  2754 Slave information can be gathered with the subcommand \lstinline+slaves+:
  1978 Slave information can be gathered with the subcommand \lstinline+slaves+:
  2755 
  1979 
  2756 \lstinputlisting[basicstyle=\ttfamily\footnotesize]{external/ethercat_slaves}
  1980 \lstinputlisting[basicstyle=\ttfamily\footnotesize]{external/ethercat_slaves}
  2757 
  1981 
  2792 
  2016 
  2793 Reading out SII data is as easy as other commands. Though the data are in
  2017 Reading out SII data is as easy as other commands. Though the data are in
  2794 binary format, analysis is easier with a tool like \textit{hexdump}:
  2018 binary format, analysis is easier with a tool like \textit{hexdump}:
  2795 
  2019 
  2796 \begin{lstlisting}
  2020 \begin{lstlisting}
  2797 $ `\textbf{ethercat sii\_read --slave 3 | hexdump}`
  2021 $ `\textbf{ethercat sii\_read --position 3 | hexdump}`
  2798 0000000 0103 0000 0000 0000 0000 0000 0000 008c
  2022 0000000 0103 0000 0000 0000 0000 0000 0000 008c
  2799 0000010 0002 0000 3052 07f0 0000 0000 0000 0000
  2023 0000010 0002 0000 3052 07f0 0000 0000 0000 0000
  2800 0000020 0000 0000 0000 0000 0000 0000 0000 0000
  2024 0000020 0000 0000 0000 0000 0000 0000 0000 0000
  2801 ...
  2025 ...
  2802 \end{lstlisting}
  2026 \end{lstlisting}
  2803 
  2027 
  2804 Backing up SII contents can easily done with a redirection:
  2028 Backing up SII contents can easily done with a redirection:
  2805 
  2029 
  2806 \begin{lstlisting}
  2030 \begin{lstlisting}
  2807 $ `\textbf{ethercat sii\_read --slave 3 > sii-of-slave3.bin}`
  2031 $ `\textbf{ethercat sii\_read --position 3 > sii-of-slave3.bin}`
  2808 \end{lstlisting}
  2032 \end{lstlisting}
  2809 
  2033 
  2810 To download SII contents to a slave, writing access to the master's character
  2034 To download SII contents to a slave, writing access to the master's character
  2811 device is necessary (see section~\ref{sec:cdev}).
  2035 device is necessary (see section~\ref{sec:cdev}).
  2812 
  2036 
  2813 \lstinputlisting[basicstyle=\ttfamily\footnotesize]{external/ethercat_sii_write}
  2037 \lstinputlisting[basicstyle=\ttfamily\footnotesize]{external/ethercat_sii_write}
  2814 
  2038 
  2815 \begin{lstlisting}
  2039 \begin{lstlisting}
  2816 # `\textbf{ethercat sii\_write --slave 3 sii-of-slave3.bin}`
  2040 # `\textbf{ethercat sii\_write --position 3 sii-of-slave3.bin}`
  2817 \end{lstlisting}
  2041 \end{lstlisting}
  2818 
  2042 
  2819 The SII contents will be checked for validity and then sent to the slave. The
  2043 The SII contents will be checked for validity and then sent to the slave. The
  2820 write operation may take a few seconds.
  2044 write operation may take a few seconds.
  2821 
  2045 
  2822 %------------------------------------------------------------------------------
  2046 %------------------------------------------------------------------------------
  2823 
  2047 
  2824 \subsection{Requesting application-layer states}
  2048 \subsection{Requesting Application-Layer States}
  2825 
  2049 
  2826 \lstinputlisting[basicstyle=\ttfamily\footnotesize]{external/ethercat_states}
  2050 \lstinputlisting[basicstyle=\ttfamily\footnotesize]{external/ethercat_states}
  2827 
  2051 
  2828 %------------------------------------------------------------------------------
  2052 %------------------------------------------------------------------------------
  2829 
  2053 
  2830 \subsection{Generating slave description XML}
  2054 \subsection{Generating Slave Description XML}
  2831 
  2055 
  2832 \lstinputlisting[basicstyle=\ttfamily\footnotesize]{external/ethercat_xml}
  2056 \lstinputlisting[basicstyle=\ttfamily\footnotesize]{external/ethercat_xml}
  2833 
  2057 
  2834 %------------------------------------------------------------------------------
  2058 %------------------------------------------------------------------------------
  2835 
  2059 
  2843 \label{sec:init}
  2067 \label{sec:init}
  2844 \index{Init script}
  2068 \index{Init script}
  2845 
  2069 
  2846 The EtherCAT master init script conforms to the requirements of the ``Linux
  2070 The EtherCAT master init script conforms to the requirements of the ``Linux
  2847 Standard Base'' (LSB\index{LSB}, \cite{lsb}). The script is installed to
  2071 Standard Base'' (LSB\index{LSB}, \cite{lsb}). The script is installed to
  2848 \textit{etc/init.d/ethercat} below the installation prefix and has to be copied
  2072 \textit{etc/init.d/ethercat} below the installation prefix and has to be
  2849 (or better: linked) to the appropriate location (see
  2073 copied (or better: linked) to the appropriate location (see
  2850 section~\ref{sec:install}), before the master can be inserted as a service.
  2074 section~\ref{sec:install}), before the master can be inserted as a service.
  2851 Please note, that the init script depends on the sysconfig file described
  2075 Please note, that the init script depends on the sysconfig file described
  2852 below.
  2076 below.
  2853 
  2077 
  2854 To provide service dependencies (i.~e. which services have to be started before
  2078 To provide service dependencies (i.~e. which services have to be started before
  2857 the correct place in the startup sequence:
  2081 the correct place in the startup sequence:
  2858 
  2082 
  2859 \lstinputlisting[firstline=38,lastline=48]
  2083 \lstinputlisting[firstline=38,lastline=48]
  2860     {../script/init.d/ethercat}
  2084     {../script/init.d/ethercat}
  2861 
  2085 
  2862 \subsection{Sysconfig}
  2086 \subsection{Sysconfig File}
  2863 \label{sec:sysconfig}
  2087 \label{sec:sysconfig}
  2864 \index{Sysconfig file}
  2088 \index{Sysconfig file}
  2865 
  2089 
  2866 For persistent configuration, the init script uses a sysconfig file installed
  2090 For persistent configuration, the init script uses a sysconfig file installed
  2867 to \textit{etc/sysconfig/ethercat} (below the installation prefix), that is
  2091 to \textit{etc/sysconfig/ethercat} (below the installation prefix), that is
  2870 the file and included below:
  2094 the file and included below:
  2871 
  2095 
  2872 \lstinputlisting[numbers=left,firstline=9,basicstyle=\ttfamily\scriptsize]
  2096 \lstinputlisting[numbers=left,firstline=9,basicstyle=\ttfamily\scriptsize]
  2873     {../script/sysconfig/ethercat}
  2097     {../script/sysconfig/ethercat}
  2874 
  2098 
  2875 \subsection{Service}
  2099 \subsection{Starting the Master as a Service}
  2876 \label{sec:service}
  2100 \label{sec:service}
  2877 \index{Service}
  2101 \index{Service}
  2878 
  2102 
  2879 After the init script and the sysconfig file are placed into the right
  2103 After the init script and the sysconfig file are placed into the right
  2880 location, the EtherCAT master can be inserted as a service. The different Linux
  2104 location, the EtherCAT master can be inserted as a service. The different Linux
  2900 
  2124 
  2901 \section{Monitoring and Debugging}
  2125 \section{Monitoring and Debugging}
  2902 \label{sec:debug}
  2126 \label{sec:debug}
  2903 \index{Monitoring}
  2127 \index{Monitoring}
  2904 
  2128 
       
  2129 % FIXME
       
  2130 
  2905 For debugging purposes, every EtherCAT master registers a read-only network
  2131 For debugging purposes, every EtherCAT master registers a read-only network
  2906 interface \textit{ecX}, where X is a number, provided by the kernel on device
  2132 interface \textit{ecX}, where X is a number, provided by the kernel on device
  2907 registration. While it is ``up'', the master forwards every frame sent and
  2133 registration. While it is ``up'', the master forwards every frame sent and
  2908 received to this interface.
  2134 received to this interface.
  2909 
  2135 
  2928 Although EtherCAT's timing is highly deterministic and therefore timing issues
  2154 Although EtherCAT's timing is highly deterministic and therefore timing issues
  2929 are rare, there are a few aspects that can (and should be) dealt with.
  2155 are rare, there are a few aspects that can (and should be) dealt with.
  2930 
  2156 
  2931 %------------------------------------------------------------------------------
  2157 %------------------------------------------------------------------------------
  2932 
  2158 
  2933 \subsection{Realtime Interface Profiling}
  2159 \subsection{Application Interface Profiling}
  2934 \label{sec:timing-profile}
  2160 \label{sec:timing-profile}
  2935 \index{Realtime!Profiling}
  2161 \index{Realtime!Profiling}
  2936 
  2162 
  2937 One of the most important timing aspects are the execution times of the
  2163 One of the most important timing aspects are the execution times of the
  2938 realtime interface functions, that are called in cyclic context. These
  2164 realtime interface functions, that are called in cyclic context. These
  3062 
  2288 
  3063 \chapter{Installation}
  2289 \chapter{Installation}
  3064 \label{sec:installation}
  2290 \label{sec:installation}
  3065 \index{Master!Installation}
  2291 \index{Master!Installation}
  3066 
  2292 
  3067 \section{Building the software}
  2293 \section{Building the Software}
  3068 
  2294 
  3069 The current EtherCAT master code is available at~\cite{etherlab} or can be
  2295 The current EtherCAT master code is available at~\cite{etherlab} or can be
  3070 obtained from the EtherLab CD. The \textit{tar.bz2} file has to be unpacked
  2296 obtained from the EtherLab CD. The \textit{tar.bz2} file has to be unpacked
  3071 with the commands below (or similar):
  2297 with the commands below (or similar):
  3072 
  2298 
  3073 \begin{lstlisting}[gobble=2]
  2299 \begin{lstlisting}[gobble=2]
  3074   `\$` `\textbf{tar xjf ethercat-\masterversion.tar.bz2}`
  2300   $ `\textbf{tar xjf ethercat-\masterversion.tar.bz2}`
  3075   `\$` `\textbf{cd ethercat-\masterversion/}`
  2301   $ `\textbf{cd ethercat-\masterversion/}`
  3076 \end{lstlisting}
  2302 \end{lstlisting}
  3077 
  2303 
  3078 The tarball was created with GNU Autotools, so the build process
  2304 The tarball was created with GNU Autotools, so the build process
  3079 follows the below commands:
  2305 follows the below commands:
  3080 
  2306 
  3081 \begin{lstlisting}[gobble=2]
  2307 \begin{lstlisting}[gobble=2]
  3082   `\$` `\textbf{./configure}`
  2308   $ `\textbf{./configure}`
  3083   `\$` `\textbf{make}`
  2309   $ `\textbf{make}`
  3084   `\$` `\textbf{make modules}`
  2310   $ `\textbf{make modules}`
  3085 \end{lstlisting}
  2311 \end{lstlisting}
  3086 
  2312 
  3087 Table~\ref{tab:config} lists important configuration switches and options.
  2313 Table~\ref{tab:config} lists important configuration switches and options.
  3088 
  2314 
  3089 \begin{table}
  2315 \begin{table}
  3143 
  2369 
  3144 \end{description}
  2370 \end{description}
  3145 
  2371 
  3146 \end{table}
  2372 \end{table}
  3147 
  2373 
  3148 \section{Building the documentation}
  2374 \section{Building the Interface Documentation}
  3149 \label{sec:gendoc}
  2375 \label{sec:gendoc}
  3150 
  2376 
  3151 The source code is documented using Doxygen~\cite{doxygen}. To build the HTML
  2377 The source code is documented using Doxygen~\cite{doxygen}. To build the HTML
  3152 documentation, you must have the Doxygen software installed. The below command
  2378 documentation, the Doxygen software has to be installed. The below command
  3153 will generate the documents in the subdirectory \textit{doxygen-output}:
  2379 will generate the documents in the subdirectory \textit{doxygen-output}:
  3154 
  2380 
  3155 \begin{lstlisting}
  2381 \begin{lstlisting}
  3156 $ `\textbf{make doc}`
  2382 $ `\textbf{make doc}`
  3157 \end{lstlisting}
  2383 \end{lstlisting}
  3158 
  2384 
  3159 To view them, point your browser to \textit{doxygen-output/html/index.html}.
  2385 The interface documentation can be viewed by pointing a browser to
  3160 
  2386 \textit{doxygen-output/html/index.html}.
  3161 \section{Installation}
  2387 
       
  2388 \section{Installing the Software}
  3162 
  2389 
  3163 The below commands have to be entered as \textit{root}: The first one will
  2390 The below commands have to be entered as \textit{root}: The first one will
  3164 install the EtherCAT header, init script, sysconfig file and the user space
  2391 install the EtherCAT header, init script, sysconfig file and the user space
  3165 tools to the prefix path. The second one will install the kernel modules to the
  2392 tool to the prefix path. The second one will install the kernel modules to the
  3166 kernel's modules directory. The following \lstinline+depmod+ call is necessary
  2393 kernel's modules directory. The final \lstinline+depmod+ call is necessary to
  3167 to include the kernel modules into the \textit{modules.dep} file to make it
  2394 include the kernel modules into the \textit{modules.dep} file to make it
  3168 available to the \lstinline+modprobe+ command, used in the init script. 
  2395 available to the \lstinline+modprobe+ command, used in the init script. 
  3169 
  2396 
  3170 \begin{lstlisting}
  2397 \begin{lstlisting}
  3171 # `\textbf{make install}`
  2398 # `\textbf{make install}`
  3172 # `\textbf{make modules\_install}`
  2399 # `\textbf{make modules\_install}`
  3211 
  2438 
  3212 \begin{lstlisting}
  2439 \begin{lstlisting}
  3213 # `\textbf{/etc/init.d/ethercat start}`
  2440 # `\textbf{/etc/init.d/ethercat start}`
  3214 \end{lstlisting}
  2441 \end{lstlisting}
  3215 
  2442 
  3216 The operation of the master can be observed by looking at the
  2443 The operation of the master can be observed with the command
  3217 Syslog\index{Syslog} messages, which should look like the ones below.  If
  2444 \lstinline+ethercat master+ or by viewing the Syslog\index{Syslog}
  3218 EtherCAT slaves are connected to the master's EtherCAT device, the activity
  2445 messages, which should look like the ones below. If EtherCAT slaves are
  3219 indicators should begin to flash.
  2446 connected to the master's EtherCAT device, the activity indicators should
       
  2447 begin to flash.
  3220 
  2448 
  3221 \begin{lstlisting}[numbers=left]
  2449 \begin{lstlisting}[numbers=left]
  3222 EtherCAT: Master driver `\masterversion`
  2450 EtherCAT: Master driver `\masterversion`
  3223 EtherCAT: 1 master waiting for devices.
  2451 EtherCAT: 1 master waiting for devices.
  3224 EtherCAT Intel(R) PRO/1000 Network Driver - version 6.0.60-k2
  2452 EtherCAT Intel(R) PRO/1000 Network Driver - version 6.0.60-k2
  3253 
  2481 
  3254 \end{description}
  2482 \end{description}
  3255 
  2483 
  3256 %------------------------------------------------------------------------------
  2484 %------------------------------------------------------------------------------
  3257 
  2485 
  3258 \chapter{Application examples}
  2486 \chapter{Application Examples}
  3259 \label{chapter:examples}
  2487 \label{chapter:examples}
  3260 
  2488 
  3261 This chapter will give practical examples of how to use the EtherCAT master via
  2489 This chapter will give practical examples of how to use the EtherCAT master
  3262 the realtime interface by writing an application module.
  2490 via the realtime interface by writing an application module.
       
  2491 
       
  2492 % FIXME remove examples?
  3263 
  2493 
  3264 %------------------------------------------------------------------------------
  2494 %------------------------------------------------------------------------------
  3265 
  2495 
  3266 \section{Minimal Example}
  2496 \section{Minimal Example}
  3267 \label{sec:mini}
  2497 \label{sec:mini}