documentation/ethercat_doc.tex
branchstable-1.4
changeset 1661 3861554f3c9d
parent 1660 f183b0c12b1f
child 1662 a211bcf10030
equal deleted inserted replaced
1660:f183b0c12b1f 1661:3861554f3c9d
   436   \includegraphics[width=.5\textwidth]{images/masters}
   436   \includegraphics[width=.5\textwidth]{images/masters}
   437   \caption{Multiple masters in one module}
   437   \caption{Multiple masters in one module}
   438   \label{fig:masters}
   438   \label{fig:masters}
   439 \end{figure}
   439 \end{figure}
   440 
   440 
   441 \paragraph{Init script}
   441 \paragraph{Init Script}
   442 \index{Init script}
   442 \index{Init script}
   443 
   443 
   444 In most cases it is not necessary to load the master module and the Ethernet
   444 In most cases it is not necessary to load the master module and the Ethernet
   445 driver modules manually. There is an init script available, so the master can
   445 driver modules manually. There is an init script available, so the master can
   446 be started as a service (see sec.~\ref{sec:system}).
   446 be started as a service (see sec.~\ref{sec:system}).
   447 
   447 
   448 \paragraph{Syslog}
   448 \paragraph{Syslog}
   449 
   449 
   450 The master module outputs information about it's state and events to the
   450 The master module outputs information about its state and events to the kernel
   451 kernel ring buffer. These also end up in the system logs.  The above module
   451 ring buffer. These also end up in the system logs.  The above module loading
   452 loading command should result in the messages below:
   452 command should result in the messages below:
   453 
   453 
   454 \begin{lstlisting}
   454 \begin{lstlisting}
   455 # `\textbf{dmesg | tail -2}`
   455 # `\textbf{dmesg | tail -2}`
   456 EtherCAT: Master driver `\masterversion`
   456 EtherCAT: Master driver `\masterversion`
   457 EtherCAT: 2 masters waiting for devices.
   457 EtherCAT: 2 masters waiting for devices.
   465 All EtherCAT master output is prefixed with \lstinline+EtherCAT+ which makes
   465 All EtherCAT master output is prefixed with \lstinline+EtherCAT+ which makes
   466 searching the logs easier.
   466 searching the logs easier.
   467 
   467 
   468 %------------------------------------------------------------------------------
   468 %------------------------------------------------------------------------------
   469 
   469 
   470 \section{Handling of Process Data} % FIXME
   470 \section{Process Data}
   471 \label{sec:processdata}
   471 \label{sec:processdata}
   472 
   472 
   473 \ldots
   473 This section shall introduce a few terms and ideas how the master handles
       
   474 process data.
   474 
   475 
   475 \paragraph{Process Data Image}
   476 \paragraph{Process Data Image}
   476 \index{Process data}
   477 \index{Process data}
   477 
   478 
   478 The slaves offer their inputs and outputs by presenting the master so-called
   479 Slaves offer their inputs and outputs by presenting the master so-called
   479 ``Process Data Objects'' (Pdos\index{Pdo}). The available Pdos can be
   480 ``Process Data Objects'' (Pdos\index{Pdo}). The available Pdos can be either
   480 determined by reading out the slave's TXPDO and RXPDO E$^2$PROM categories.
   481 determined by reading out the slave's TXPDO and RXPDO SII categories from the
   481 The application can register the Pdos for data exchange during cyclic
   482 E$^2$PROM (in case of fixed Pdos) or by reading out the appropriate CoE
   482 operation.  The sum of all registered Pdos defines the ``process data image'',
   483 objects (see sec.~\ref{sec:coe}), if available.  The application can register
   483 which is exchanged via the ``Logical ReadWrite'' datagrams introduced
   484 the Pdos' entries for exchange during cyclic operation. The sum of all
   484 in~\cite[sec.~5.4.2.4]{dlspec}.
   485 registered Pdo entries defines the ``process data image'', which is exchanged
       
   486 via datagrams with ``logical'' memory access (like LWR, LRD or LRW) introduced
       
   487 in~\cite[sec.~5.4]{dlspec}.
   485 
   488 
   486 \paragraph{Process Data Domains}
   489 \paragraph{Process Data Domains}
   487 \index{Domain}
   490 \index{Domain}
   488 
   491 
   489 The process data image can be easily managed by creating so-called
   492 The process data image can be easily managed by creating so-called
   490 ``domains'', which group Pdos and allocate the datagrams needed to
   493 ``domains'', which allow grouped Pdo exchange. They also take care of managing
   491 exchange them. Domains are mandatory for process data exchange, so
   494 the datagram structures needed to exchange the Pdos. Domains are mandatory for
   492 there has to be at least one. They were introduced for the following
   495 process data exchange, so there has to be at least one. They were introduced
   493 reasons:
   496 for the following reasons:
   494 
   497 
   495 \begin{itemize}
   498 \begin{itemize}
   496 \item The maximum size of a ``Logical ReadWrite'' datagram is limited
   499 
   497   due to the limited size of an Ethernet frame: The maximum data size
   500 \item The maximum size of a datagram is limited due to the limited size of an
   498   is the Ethernet data field size minus the EtherCAT frame header,
   501 Ethernet frame: The maximum data size is the Ethernet data field size minus
   499   EtherCAT datagram header and EtherCAT datagram footer: $1500 - 2 -
   502 the EtherCAT frame header, EtherCAT datagram header and EtherCAT datagram
   500   12 - 2 = 1484$ octets. If the size of the process data image exceeds
   503 footer: $1500 - 2 - 12 - 2 = 1484$ octets. If the size of the process data
   501   this limit, multiple frames have to be sent, and the image has to be
   504 image exceeds this limit, multiple frames have to be sent, and the image has
   502   partitioned for the use of multiple datagrams. A domain manages this
   505 to be partitioned for the use of multiple datagrams. A domain manages this
   503   automatically.
   506 automatically.
   504 \item Not every Pdo has to be exchanged with the same frequency: The
   507 
   505   values of Pdos can vary slowly over time (for example temperature
   508 \item Not every Pdo has to be exchanged with the same frequency: The values of
   506   values), so exchanging them with a high frequency would just waste
   509 Pdos can vary slowly over time (for example temperature values), so exchanging
   507   bus bandwidth. For this reason, multiple domains can be created, to
   510 them with a high frequency would just waste bus bandwidth. For this reason,
   508   group different Pdos and so allow separate exchange.
   511 multiple domains can be created, to group different Pdos and so allow separate
       
   512 exchange.
       
   513 
   509 \end{itemize}
   514 \end{itemize}
   510 
   515 
   511 There is no upper limit for the number of domains, but each domain
   516 There is no upper limit for the number of domains, but each domain occupies
   512 occupies one FMMU in each slave involved, so the maximum number of
   517 one FMMU in each slave involved, so the maximum number of domains is de facto
   513 domains is also limited by the slaves' capabilities.
   518 limited by the slaves.
   514 
   519 
   515 \paragraph{FMMU Configuration}
   520 \paragraph{FMMU Configuration}
   516 \index{FMMU!Configuration}
   521 \index{FMMU!Configuration}
   517 
   522 
   518 An application can register Pdos for process data exchange. Every Pdo is part
   523 An application can register Pdo entries for exchange. Every Pdo entry and its
   519 of a memory area in the slave's physical memory, that is protected by a sync
   524 parent Pdo is part of a memory area in the slave's physical memory, that is
   520 manager \cite[sec.~6.7]{dlspec} for synchronized access. In order to make a
   525 protected by a sync manager \cite[sec.~6.7]{dlspec} for synchronized access.
   521 sync manager react on a datagram accessing its memory, it is necessary to
   526 In order to make a sync manager react on a datagram accessing its memory, it
   522 access the last byte covered by the sync manager. Otherwise the sync manager
   527 is necessary to access the last byte covered by the sync manager. Otherwise
   523 will not react on the datagram and no data will be exchanged. That is why the
   528 the sync manager will not react on the datagram and no data will be exchanged.
   524 whole synchronized memory area has to be included into the process data image:
   529 That is why the whole synchronized memory area has to be included into the
   525 For example, if a certain Pdo of a slave is registered for exchange with a
   530 process data image: For example, if a certain Pdo entry of a slave is
   526 certain domain, one FMMU will be configured to map the complete
   531 registered for exchange with a certain domain, one FMMU will be configured to
   527 sync-manager-protected memory, the Pdo resides in. If a second Pdo of the same
   532 map the complete sync-manager-protected memory, the Pdo entry resides in. If a
   528 slave is registered for process data exchange within the same domain, and this
   533 second Pdo entry of the same slave is registered for process data exchange
   529 Pdo resides in the same sync-manager-protected memory as the first Pdo, the
   534 within the same domain, and it resides in the same sync-manager-protected
   530 FMMU configuration is not touched, because the appropriate memory is already
   535 memory as the first one, the FMMU configuration is not altered, because the
   531 part of the domain's process data image.  If the second Pdo belongs to another
   536 desired memory is already part of the domain's process data image. If the
   532 sync-manager-protected area, this complete area is also included into the
   537 second Pdo entry would belong to another sync-manager-protected area, this
   533 domains process data image. See figure~\ref{fig:fmmus} for an overview, how
   538 complete area would also be included into the domains process data image.
   534 FMMU's are configured to map physical memory to logical process data images.
   539 
       
   540 Figure~\ref{fig:fmmus} gives an overview, how FMMUs are configured to map
       
   541 physical memory to logical process data images.
   535 
   542 
   536 \begin{figure}[htbp]
   543 \begin{figure}[htbp]
   537   \centering
   544   \centering
   538   \includegraphics[width=\textwidth]{images/fmmus}
   545   \includegraphics[width=\textwidth]{images/fmmus}
   539   \caption{FMMU configuration for several domains}
   546   \caption{FMMU Configuration}
   540   \label{fig:fmmus}
   547   \label{fig:fmmus}
   541 \end{figure}
   548 \end{figure}
   542 
       
   543 \paragraph{Process Data Pointers} % FIXME
       
   544 
       
   545 The figure also demonstrates the way, the application can access the exchanged
       
   546 process data: At Pdo registration, the application has to provide the address
       
   547 of a process data pointer. Upon calculation of the domain image and allocation
       
   548 of process data memory, this pointer is redirected to the appropriate location
       
   549 inside the domain's process data memory and can later be easily dereferenced by
       
   550 the module code.
       
   551 
   549 
   552 %------------------------------------------------------------------------------
   550 %------------------------------------------------------------------------------
   553 
   551 
   554 \chapter{Application Interface}
   552 \chapter{Application Interface}
   555 \label{chap:api}
   553 \label{chap:api}
   568 
   566 
   569 The application interface provides functions and data structures for
   567 The application interface provides functions and data structures for
   570 applications to access an EtherCAT master. The complete documentation of the
   568 applications to access an EtherCAT master. The complete documentation of the
   571 interface is included as Doxygen~\cite{doxygen} comments in the header file
   569 interface is included as Doxygen~\cite{doxygen} comments in the header file
   572 \textit{include/ecrt.h}. It can either be read directly from the file
   570 \textit{include/ecrt.h}. It can either be read directly from the file
   573 comments, or as a more comfortable HTML documentation. The generation is
   571 comments, or as a more comfortable HTML documentation. The HTML generation is
   574 described in sec.~\ref{sec:gendoc}.
   572 described in sec.~\ref{sec:gendoc}.
   575 
   573 
   576 The following sections cover a general description of the application
   574 The following sections cover a general description of the application
   577 interface.
   575 interface.
   578 
   576 
   579 Every application should use the master in two steps:
   577 Every application should use the master in two steps:
   580 
   578 
   581 \begin{description}
   579 \begin{description}
   582 
   580 
   583 \item[Configuration] The master is requested and the configuration is applied.
   581 \item[Configuration] The master is requested and the configuration is applied.
   584 Domains are created Slaves are configured and Pdo entries are registered (see
   582 For example, domains are created, slaves are configured and Pdo entries are
   585 sec.~\ref{sec:masterconfig}).
   583 registered (see sec.~\ref{sec:masterconfig}).
   586 
   584 
   587 \item[Operation] Cyclic code is run, process data is exchanged (see
   585 \item[Operation] Cyclic code is run and process data are exchanged (see
   588 sec.~\ref{sec:cyclic}). To enter operation mode, the master has to be
   586 sec.~\ref{sec:cyclic}).
   589 ``activated'' to calculate the process data image and apply the bus
       
   590 configuration for the first time. After activation, the application is in
       
   591 charge to send and receive frames.
       
   592 
   587 
   593 \end{description}
   588 \end{description}
   594 
   589 
   595 \paragraph{Example Applications} \index{Example Applications} There are a few
   590 \paragraph{Example Applications}\index{Example Applications} There are a few
   596 example applications in the \textit{examples/} subdirectory of the master
   591 example applications in the \textit{examples/} subdirectory of the master
   597 code. They are documented in the source code.
   592 code. They are documented in the source code.
   598 
   593 
   599 %------------------------------------------------------------------------------
   594 %------------------------------------------------------------------------------
   600 
   595 
   601 \section{Master Configuration}
   596 \section{Master Configuration}
   602 \label{sec:masterconfig}
   597 \label{sec:masterconfig}
   603 
   598 
   604 \ldots
   599 The bus configuration is supplied via the application interface.
   605 % FIXME Attaching
   600 Figure~\ref{fig:app-config} gives an overview of the objects, that can be
       
   601 configured by the application.
   606 
   602 
   607 \begin{figure}[htbp]
   603 \begin{figure}[htbp]
   608   \centering
   604   \centering
   609   \includegraphics[width=.8\textwidth]{images/app-config}
   605   \includegraphics[width=.8\textwidth]{images/app-config}
   610   \caption{Master Configuration}
   606   \caption{Master Configuration}
   611   \label{fig:app-config}
   607   \label{fig:app-config}
   612 \end{figure}
   608 \end{figure}
   613 
   609 
       
   610 \subsection{Slave Configuration}
       
   611 
       
   612 The application has to tell the master about the expected bus topology. This
       
   613 can be done by creating ``slave configurations''. A slave configuration can be
       
   614 seen as an expected slave. When a slave configuration is created, the
       
   615 application provides the bus position (see below), vendor id and product code.
       
   616 
       
   617 When the bus configuration is applied, the master checks, if there is a slave
       
   618 with the given vendor id and product code at the given position. If this is
       
   619 the case, the slave configuration is ``attached'' to the real slave on the bus
       
   620 and the slave is configured according to the settings provided by the
       
   621 application. The state of a slave configuration can either be queried via the
       
   622 application interface or via the command-line tool (see
       
   623 sec.~\ref{sec:ethercat-config}).
       
   624 
       
   625 \paragraph{Slave Position} The slave position has to be specified as a tuple
       
   626 of ``alias`` and ``position''. This allows addressing slaves either via an
       
   627 absolute bus position, or a stored identifier called ``alias'', or a mixture
       
   628 of both. The alias is a 16-bit value stored in the slave's E$^2$PROM. It can
       
   629 be modified via the command-line tool (see sec.~\ref{sec:ethercat-alias}).
       
   630 Table~\ref{tab:slaveposition} shows, how the values are interpreted.
       
   631 
       
   632 \begin{table}[htbp]
       
   633   \centering
       
   634   \caption{Specifying a Slave Position}
       
   635   \label{tab:slaveposition}
       
   636   \vspace{2mm}
       
   637   \begin{tabular}{c|c|p{70mm}}
       
   638     Alias & Position & Interpretation\\
       
   639     \hline
       
   640 
       
   641     \lstinline+0+ & \lstinline+0+ -- \lstinline+65535+ &
       
   642 
       
   643     Position addressing. The position parameter is interpreted as the absolute
       
   644     ring position in the bus.\\ \hline
       
   645 
       
   646     \lstinline+1+ -- \lstinline+65535+ & \lstinline+0+ -- \lstinline+65535+ &
       
   647 
       
   648     Alias addressing. The position parameter is interpreted as relative
       
   649     position after the first slave with the given alias address. \\ \hline
       
   650 
       
   651   \end{tabular}
       
   652 \end{table}
       
   653 
       
   654 Figure~\ref{fig:attach} shows an example of how slave configurations are
       
   655 attached. Some of the configurations were attached, while others remain
       
   656 detached. The below lists gives the reasons beginning with the top slave
       
   657 configuration.
       
   658 
       
   659 \begin{figure}[htbp]
       
   660   \centering
       
   661   \includegraphics[width=.7\textwidth]{images/attach}
       
   662   \caption{Slave Configuration Attachment}
       
   663   \label{fig:attach}
       
   664 \end{figure}
       
   665 
       
   666 \begin{enumerate}
       
   667 
       
   668 \item A zero alias means to use simple position addressing. Slave 1 exists and
       
   669 vendor id and product code match the expected values.
       
   670 
       
   671 \item Although the slave with position 0 is found, the product code does not
       
   672 match, so the configuration is not attached.
       
   673 
       
   674 \item The alias is non-zero, so alias addressing is used. Slave 2 is the first
       
   675 slave with alias \lstinline+0x2000+. Because the position value is zero, the
       
   676 same slave is used.
       
   677 
       
   678 \item There is no slave with the given alias, so the configuration can not be
       
   679 attached.
       
   680 
       
   681 \item Slave 2 is again the first slave with the alias \lstinline+0x2000+, but
       
   682 position is now 1, so slave 3 is attached.
       
   683 
       
   684 \end{enumerate}
       
   685 
   614 %------------------------------------------------------------------------------
   686 %------------------------------------------------------------------------------
   615 
   687 
   616 \section{Cyclic Operation}
   688 \section{Cyclic Operation}
   617 \label{sec:cyclic}
   689 \label{sec:cyclic}
   618 
   690 
   619 \ldots
   691 
   620 % FIXME PDOS endianess
   692 To enter cyclic operation mode, the master has to be ``activated'' to
   621 
   693 calculate the process data image and apply the bus configuration for the first
       
   694 time. After activation, the application is in charge to send and receive
       
   695 frames.
       
   696 
       
   697 % TODO PDOS endianess
       
   698 % TODO Datagram injection
   622 
   699 
   623 %------------------------------------------------------------------------------
   700 %------------------------------------------------------------------------------
   624 
   701 
   625 \section{Concurrent Master Access} % FIXME
   702 \section{Concurrent Master Access} % FIXME
   626 \label{sec:concurr}
   703 \label{sec:concurr}
  1595 the assigned Pdo's indices. When a Pdo index is read, the Pdo Entry Reading
  1672 the assigned Pdo's indices. When a Pdo index is read, the Pdo Entry Reading
  1596 FSM is executed to read the Pdo's mapped Pdo entries.
  1673 FSM is executed to read the Pdo's mapped Pdo entries.
  1597 
  1674 
  1598 \paragraph{Pdo Entry Reading FSM} This state machine
  1675 \paragraph{Pdo Entry Reading FSM} This state machine
  1599 (fig.~\ref{fig:fsm-pdo-entry-read}) reads the Pdo mapping (the Pdo entries) of
  1676 (fig.~\ref{fig:fsm-pdo-entry-read}) reads the Pdo mapping (the Pdo entries) of
  1600 a Pdo. It reads the respective mapping Sdo (\lstinline+0x1600+ -
  1677 a Pdo. It reads the respective mapping Sdo (\lstinline+0x1600+ --
  1601 \lstinline+0x17ff+, or \lstinline+0x1a00+ - \lstinline+0x1bff+) for the given
  1678 \lstinline+0x17ff+, or \lstinline+0x1a00+ -- \lstinline+0x1bff+) for the given
  1602 Pdo by reading first the subindex zero (number of elements) to determine the
  1679 Pdo by reading first the subindex zero (number of elements) to determine the
  1603 number of mapped Pdo entries. After that, each subindex is read to get the
  1680 number of mapped Pdo entries. After that, each subindex is read to get the
  1604 mapped Pdo entry index, subindex and bit size.
  1681 mapped Pdo entry index, subindex and bit size.
  1605 
  1682 
  1606 \begin{figure}[htbp]
  1683 \begin{figure}[htbp]
  1648 The master creates a virtual EoE network interface for every EoE-capable
  1725 The master creates a virtual EoE network interface for every EoE-capable
  1649 slave. These interfaces are called either
  1726 slave. These interfaces are called either
  1650 
  1727 
  1651 \begin{description}
  1728 \begin{description}
  1652 
  1729 
  1653 \item[eoeXsY] for a slave without an alias address (see sec.~\ref{sec:alias}),
  1730 \item[eoeXsY] for a slave without an alias address (see
  1654 where X is the master index and Y is the slave's ring position, or
  1731 sec.~\ref{sec:ethercat-alias}), where X is the master index and Y is the
       
  1732 slave's ring position, or
  1655 
  1733 
  1656 \item[eoeXaY] for a slave with a non-zero alias address, where X is the master
  1734 \item[eoeXaY] for a slave with a non-zero alias address, where X is the master
  1657 index and Y is the decimal alias address.
  1735 index and Y is the decimal alias address.
  1658 
  1736 
  1659 \end{description}
  1737 \end{description}
  1913 sec.~\ref{sec:autonode} for how to install and configure it.
  1991 sec.~\ref{sec:autonode} for how to install and configure it.
  1914 
  1992 
  1915 %------------------------------------------------------------------------------
  1993 %------------------------------------------------------------------------------
  1916 
  1994 
  1917 \subsection{Setting Alias Addresses}
  1995 \subsection{Setting Alias Addresses}
  1918 \label{sec:alias} % FIXME
  1996 \label{sec:ethercat-alias}
  1919 
  1997 
  1920 \lstinputlisting[basicstyle=\ttfamily\footnotesize]{external/ethercat_alias}
  1998 \lstinputlisting[basicstyle=\ttfamily\footnotesize]{external/ethercat_alias}
  1921 
  1999 
  1922 %------------------------------------------------------------------------------
  2000 %------------------------------------------------------------------------------
  1923 
  2001 
  1924 \subsection{Displaying the Bus Configuration}
  2002 \subsection{Displaying the Bus Configuration}
       
  2003 \label{sec:ethercat-config}
  1925 
  2004 
  1926 \lstinputlisting[basicstyle=\ttfamily\footnotesize]{external/ethercat_config}
  2005 \lstinputlisting[basicstyle=\ttfamily\footnotesize]{external/ethercat_config}
  1927 
  2006 
  1928 %------------------------------------------------------------------------------
  2007 %------------------------------------------------------------------------------
  1929 
  2008 
  2368 \begin{lstlisting}
  2447 \begin{lstlisting}
  2369 $ `\textbf{make doc}`
  2448 $ `\textbf{make doc}`
  2370 \end{lstlisting}
  2449 \end{lstlisting}
  2371 
  2450 
  2372 The interface documentation can be viewed by pointing a browser to the file
  2451 The interface documentation can be viewed by pointing a browser to the file
  2373 \textit{doxygen-output/html/index.html}.
  2452 \textit{doxygen-output/html/index.html}. The functions and data structures of
       
  2453 the application interface a covered by an own module ``Application
       
  2454 Interface''.
  2374 
  2455 
  2375 \section{Installing the Software}
  2456 \section{Installing the Software}
  2376 
  2457 
  2377 The below commands have to be entered as \textit{root}: The first one will
  2458 The below commands have to be entered as \textit{root}: The first one will
  2378 install the EtherCAT header, init script, sysconfig file and the userspace
  2459 install the EtherCAT header, init script, sysconfig file and the userspace