656 %------------------------------------------------------------------------------ |
656 %------------------------------------------------------------------------------ |
657 |
657 |
658 \chapter{Ethernet Devices} |
658 \chapter{Ethernet Devices} |
659 \label{sec:devices} |
659 \label{sec:devices} |
660 |
660 |
661 % Device Interface |
661 The EtherCAT protocol is based on the Ethernet standard, so a master relies on |
662 % Device Modules |
662 standard Ethernet hardware to communicate with the bus. |
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. |
|
671 |
663 |
672 The term \textit{device} is used as a synonym for Ethernet network interface |
664 The term \textit{device} is used as a synonym for Ethernet network interface |
673 hardware. There are device driver modules that handle Ethernet hardware, which |
665 hardware. There are device driver modules that handle Ethernet hardware, which |
674 the master can use to connect to an EtherCAT bus. |
666 a master can use to connect to an EtherCAT bus. |
675 |
|
676 Section~\ref{sec:networkdrivers} offers an overview of general Linux |
|
677 network driver modules, while section~\ref{sec:requirements} will show |
|
678 the requirements to an EtherCAT-enabled network driver. Finally, |
|
679 sections~\ref{sec:seldev} to~\ref{sec:patching} show how to fulfill |
|
680 these requirements and implement such a driver module. |
|
681 |
667 |
682 %------------------------------------------------------------------------------ |
668 %------------------------------------------------------------------------------ |
683 |
669 |
684 \section{Network Driver Basics} |
670 \section{Network Driver Basics} |
685 \label{sec:networkdrivers} |
671 \label{sec:networkdrivers} |
1413 |
1399 |
1414 \item[PREOP] If the slave supports CoE, it is set to PREOP state using the |
1400 \item[PREOP] If the slave supports CoE, it is set to PREOP state using the |
1415 State change FSM (see section~\ref{sec:fsm-change}) to enable mailbox |
1401 State change FSM (see section~\ref{sec:fsm-change}) to enable mailbox |
1416 communication and read the Pdo configuration via CoE. |
1402 communication and read the Pdo configuration via CoE. |
1417 |
1403 |
1418 \item[Pdos] The Pdos are read via CoE (if supported) using the Pdo FSM (see |
1404 \item[Pdos] The Pdos are read via CoE (if supported) using the Pdo Reading FSM |
1419 section~\ref{sec:fsm-pdo}). If this is successful, the Pdo information from |
1405 (see section~\ref{sec:fsm-pdo}). If this is successful, the Pdo information |
1420 the SII (if any) is overwritten. |
1406 from the SII (if any) is overwritten. |
1421 |
1407 |
1422 \end{description} |
1408 \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 |
|
1432 |
1409 |
1433 %------------------------------------------------------------------------------ |
1410 %------------------------------------------------------------------------------ |
1434 |
1411 |
1435 \section{The Slave Configuration State Machine} |
1412 \section{The Slave Configuration State Machine} |
1436 \label{sec:fsm-conf} |
1413 \label{sec:fsm-conf} |
1497 application-layer state. This implements the states and transitions described |
1474 application-layer state. This implements the states and transitions described |
1498 in \cite[section~6.4.1]{alspec}. |
1475 in \cite[section~6.4.1]{alspec}. |
1499 |
1476 |
1500 \begin{figure}[htbp] |
1477 \begin{figure}[htbp] |
1501 \centering |
1478 \centering |
1502 \includegraphics[width=.9\textwidth]{images/fsm-change} % FIXME |
1479 \includegraphics[width=.6\textwidth]{graphs/fsm_change} |
1503 \caption{Transition Diagram of the State Change State Machine} |
1480 \caption{Transition Diagram of the State Change State Machine} |
1504 \label{fig:fsm-change} |
1481 \label{fig:fsm-change} |
1505 \end{figure} |
1482 \end{figure} |
1506 |
1483 |
1507 % FIXME |
|
1508 |
|
1509 \begin{description} |
1484 \begin{description} |
1510 \item[START] The beginning state, where a datagram with the state |
1485 |
1511 change command is written to the slave's ``AL Control Request'' |
1486 \item[Start] The new application-layer state is requested via the ``AL Control |
1512 attribute. Nothing can fail. $\rightarrow$~CHECK |
1487 Request'' register (see ~\cite[section 5.3.1]{alspec}). |
1513 |
1488 |
1514 \item[CHECK] After the state change datagram has been sent, the ``AL |
1489 \item[Check for Response] Some slave need some time to respond to an AL state |
1515 Control Response'' attribute is queried with a second datagram. |
1490 change command, and do not respond for some time. For this case, the command |
1516 $\rightarrow$~STATUS |
1491 is issued again, until it is acknowledged. |
1517 |
1492 |
1518 \item[STATUS] The read memory contents are evaluated: While the |
1493 \item[Check AL Status] If the AL State change datagram was acknowledged, the |
1519 parameter \textit{State} still contains the old slave state, the |
1494 ``AL Control Response'' register (see~\cite[section 5.3.2]{alspec}) must be |
1520 slave is busy with reacting on the state change command. In this |
1495 read out until the slave changes the AL state. |
1521 case, the attribute has to be queried again. |
1496 |
1522 $\rightarrow$~STATUS |
1497 \item[AL Status Code] If the slave refused the state change command, the |
1523 |
1498 reason can be read from the ``AL Status Code'' field in the ``AL State |
1524 In case of success, the \textit{State} parameter contains the new |
1499 Changed'' registers (see~\cite[section 5.3.3]{alspec}). |
1525 state and the \textit{Change} bit is cleared. The slave is in the |
1500 |
1526 requested state. $\rightarrow$~END |
1501 \item[Acknowledge State] If the state change was not successful, the master |
1527 |
1502 has to acknowledge the old state by writing to the ``AL Control request'' |
1528 If the slave can not process the state change, the \textit{Change} |
1503 register again. |
1529 bit is set: Now the master tries to get the reason for this by |
1504 |
1530 querying the \textit{AL Status Code} parameter. |
1505 \item[Check Acknowledge] After sending the acknowledge command, it has to read |
1531 $\rightarrow$~CODE |
1506 out the ``AL Control Response'' register again. |
1532 |
|
1533 \item[END] If the state machine ends in this state, the slave's state |
|
1534 change has been successful. |
|
1535 |
|
1536 \item[CODE] The status code query has been sent. Reading the |
|
1537 \textit{AL Status Code} might fail, because not all slaves support |
|
1538 this parameter. Anyway, the master has to acknowledge the state |
|
1539 change error by writing the current slave state to the ``AL Control |
|
1540 Request'' attribute with the \textit{Acknowledge} bit set. |
|
1541 $\rightarrow$~ACK |
|
1542 |
|
1543 \item[ACK] After that, the ``AL Control Response'' attribute is |
|
1544 queried for the state of the acknowledgement. |
|
1545 $\rightarrow$~CHECK ACK |
|
1546 |
|
1547 \item[CHECK ACK] If the acknowledgement has been accepted by the |
|
1548 slave, the old state is kept. Still, the state change was |
|
1549 unsuccessful. $\rightarrow$~ERROR |
|
1550 |
|
1551 If the acknowledgement is ignored by the slave, a timeout happens. |
|
1552 In any case, the overall state change was unsuccessful. |
|
1553 $\rightarrow$~ERROR |
|
1554 |
|
1555 If there is still now response from the slave, but the timer did not |
|
1556 run out yet, the slave's ``AL Control Response'' attribute is |
|
1557 queried again. $\rightarrow$~CHECK ACK |
|
1558 |
|
1559 \item[ERROR] If the state machine ends in this state, the slave's |
|
1560 state change was unsuccessful. |
|
1561 |
1507 |
1562 \end{description} |
1508 \end{description} |
|
1509 |
|
1510 The ``start\_ack'' state is a shortcut in the state machine for the case, that |
|
1511 the master wants to acknowledge a spontaneous AL state change, that was not |
|
1512 requested. |
1563 |
1513 |
1564 %------------------------------------------------------------------------------ |
1514 %------------------------------------------------------------------------------ |
1565 |
1515 |
1566 \section{The SII State Machine} |
1516 \section{The SII State Machine} |
1567 \label{sec:fsm-sii} |
1517 \label{sec:fsm-sii} |
1571 implements the process of reading or writing SII data via the |
1521 implements the process of reading or writing SII data via the |
1572 Slave Information Interface described in \cite[section~6.4]{dlspec}. |
1522 Slave Information Interface described in \cite[section~6.4]{dlspec}. |
1573 |
1523 |
1574 \begin{figure}[htbp] |
1524 \begin{figure}[htbp] |
1575 \centering |
1525 \centering |
1576 \includegraphics[width=.9\textwidth]{images/fsm-sii} % FIXME |
1526 \includegraphics[width=.5\textwidth]{graphs/fsm_sii} |
1577 \caption{Transition Diagram of the SII State Machine} |
1527 \caption{Transition Diagram of the SII State Machine} |
1578 \label{fig:fsm-sii} |
1528 \label{fig:fsm-sii} |
1579 \end{figure} |
1529 \end{figure} |
1580 |
1530 |
1581 % FIXME |
1531 This is how the reading part of the state machine works: |
1582 |
1532 |
1583 \begin{description} |
1533 \begin{description} |
1584 \item[READ\_START] The beginning state for reading access, where the |
1534 |
1585 read request and the requested address are written to the SII |
1535 \item[Start Reading] The read request and the requested word address are |
1586 attribute. Nothing can fail up to now. |
1536 written to the SII attribute. |
1587 $\rightarrow$~READ\_CHECK |
1537 |
1588 |
1538 \item[Check Read Command] If the SII read request command has been |
1589 \item[READ\_CHECK] When the SII read request has been sent |
1539 acknowledged, a timer is started. A datagram is issued, that reads out the SII |
1590 successfully, a timer is started. A check/fetch datagram is issued, |
1540 attribute for state and data. |
1591 that reads out the SII attribute for state and data. |
1541 |
1592 $\rightarrow$~READ\_FETCH |
1542 \item[Fetch Data] If the read operation is still busy (the SII is usually |
1593 |
1543 implemented as an E$^2$PROM), the state is read again. Otherwise the data are |
1594 \item[READ\_FETCH] Upon reception of the check/fetch datagram, the |
1544 copied from the datagram. |
1595 \textit{Read Operation} and \textit{Busy} parameters are checked: |
1545 |
1596 \begin{itemize} |
|
1597 \item If the slave is still busy with fetching E$^2$PROM data into |
|
1598 the interface, the timer is checked. If it timed out, the reading |
|
1599 is aborted ($\rightarrow$~ERROR), if not, the check/fetch datagram |
|
1600 is issued again. $\rightarrow$~READ\_FETCH |
|
1601 |
|
1602 \item If the slave is ready with reading data, these are copied from |
|
1603 the datagram and the read cycle is completed. |
|
1604 $\rightarrow$~END |
|
1605 \end{itemize} |
|
1606 \end{description} |
1546 \end{description} |
1607 |
1547 |
1608 The write access states behave nearly the same: |
1548 The writing part works nearly similar: |
1609 |
1549 |
1610 \begin{description} |
1550 \begin{description} |
1611 \item[WRITE\_START] The beginning state for writing access, |
1551 |
1612 respectively. A write request, the target address and the data word |
1552 \item[Start Writing] A write request, the target address and the data word are |
1613 are written to the SII attribute. Nothing can fail. |
1553 written to the SII attribute. |
1614 $\rightarrow$~WRITE\_CHECK |
1554 |
1615 |
1555 \item[Check Write Command] If the SII write request command has been |
1616 \item[WRITE\_CHECK] When the SII write request has been sent |
1556 acknowledged, a timer is started. A datagram is issued, that reads out the SII |
1617 successfully, the timer is started. A check datagram is issued, that |
1557 attribute for the state of the write operation. |
1618 reads out the SII attribute for the state of the write operation. |
1558 |
1619 $\rightarrow$~WRITE\_CHECK2 |
1559 \item[Wait while Busy] If the write operation is still busy (determined by a |
1620 |
1560 minimum wait time and the state of the busy flag), the state machine remains in |
1621 \item[WRITE\_CHECK2] Upon reception of the check datagram, the |
1561 this state to avoid that another write operation is issued too early. |
1622 \textit{Write Operation} and \textit{Busy} parameters are checked: |
1562 |
1623 \begin{itemize} |
|
1624 \item If the slave is still busy with writing E$^2$PROM data, the |
|
1625 timer is checked. If it timed out, the operation is aborted |
|
1626 ($\rightarrow$~ERROR), if not, the check datagram is issued again. |
|
1627 $\rightarrow$~WRITE\_CHECK2 |
|
1628 \item If the slave is ready with writing data, the write cycle is |
|
1629 completed. $\rightarrow$~END |
|
1630 \end{itemize} |
|
1631 \end{description} |
1563 \end{description} |
|
1564 |
|
1565 %------------------------------------------------------------------------------ |
|
1566 |
|
1567 \section{The Pdo State Machines} |
|
1568 \label{sec:fsm-pdo} |
|
1569 \index{FSM!Pdo} |
|
1570 |
|
1571 The Pdo state machines are a set of state machines that read or write the Pdo |
|
1572 assignment and the Pdo mapping via the ``CoE Communication Area'' described in |
|
1573 \cite[section 5.6.7.4]{alspec}. For the object access, the |
|
1574 CANopen-over-EtherCAT access primitives are used (see |
|
1575 section~\ref{sec:coeimp}), so the slave must support the CoE mailbox protocol. |
|
1576 |
|
1577 \paragraph{Pdo Reading FSM} This state machine (fig.~\ref{fig:fsm-pdo-read}) |
|
1578 has the purpose to read the complete Pdo configuration of a slave. It reads |
|
1579 the Pdo assignment for each Sync Manager and uses the Pdo Entry Reading FSM |
|
1580 (fig.~\ref{fig:fsm_pdo_entry_read}) to read the mapping for each assigned Pdo. |
|
1581 |
|
1582 \begin{figure}[htbp] |
|
1583 \centering |
|
1584 \includegraphics[width=.4\textwidth]{graphs/fsm_pdo_read} |
|
1585 \caption{Transition Diagram of the Pdo Reading State Machine} |
|
1586 \label{fig:fsm-pdo-read} |
|
1587 \end{figure} |
|
1588 |
|
1589 Basically it reads the every Sync manager's Pdo assignment Sdo's |
|
1590 (\lstinline+0x1C1x+) number of elements to determine the number of assigned |
|
1591 Pdos for this sync manager and then reads out the subindices of the Sdo to get |
|
1592 the assigned Pdo's indices. When a Pdo index is read, the Pdo Entry Reading |
|
1593 FSM is executed to read the Pdo's mapped Pdo entries. |
|
1594 |
|
1595 \paragraph{Pdo Entry Reading FSM} This state machine |
|
1596 (fig.~\ref{fig:fsm_pdo_entry_reading}) reads the Pdo mapping (the Pdo entries) |
|
1597 of a Pdo. It reads the respective mapping Sdo (\lstinline+0x1600+ - |
|
1598 \lstinline+0x17ff+, or \lstinline+0x1a00+ - \lstinline+0x1bff+) for the given |
|
1599 Pdo by reading first the subindex zero (number of elements) to determine the |
|
1600 number of mapped Pdo entries. After that, each subindex is read to get the |
|
1601 mapped Pdo entry index, subindex and bit size. |
|
1602 |
|
1603 \begin{figure}[htbp] |
|
1604 \centering |
|
1605 \includegraphics[width=.4\textwidth]{graphs/fsm_pdo_entry_read} |
|
1606 \caption{Transition Diagram of the Pdo Entry Reading State Machine} |
|
1607 \label{fig:fsm-pdo-read} |
|
1608 \end{figure} |
|
1609 |
|
1610 \begin{figure}[htbp] |
|
1611 \centering |
|
1612 \includegraphics[width=.9\textwidth]{graphs/fsm_pdo_conf} |
|
1613 \caption{Transition Diagram of the Pdo Configuration State Machine} |
|
1614 \label{fig:fsm-pdo-read} |
|
1615 \end{figure} |
|
1616 |
|
1617 \begin{figure}[htbp] |
|
1618 \centering |
|
1619 \includegraphics[width=.4\textwidth]{graphs/fsm_pdo_entry_conf} |
|
1620 \caption{Transition Diagram of the Pdo Entry Configuration State Machine} |
|
1621 \label{fig:fsm-pdo-read} |
|
1622 \end{figure} |
1632 |
1623 |
1633 %------------------------------------------------------------------------------ |
1624 %------------------------------------------------------------------------------ |
1634 |
1625 |
1635 \chapter{Mailbox Protocol Implementations} |
1626 \chapter{Mailbox Protocol Implementations} |
1636 \index{Mailbox} |
1627 \index{Mailbox} |
1872 \label{sec:user} |
1871 \label{sec:user} |
1873 \index{User space} |
1872 \index{User space} |
1874 |
1873 |
1875 % FIXME |
1874 % FIXME |
1876 |
1875 |
1877 For the master runs as a kernel module, accessing it is natively |
1876 For the master runs as a kernel module, accessing it is natively limited to |
1878 limited to analyzing Syslog messages and controlling using modutils. |
1877 analyzing Syslog messages and controlling using modutils. |
1879 |
1878 |
1880 It is necessary to implement further interfaces, that make it easier |
1879 It is necessary to implement further interfaces, that make it easier to access |
1881 to access the master from user space and allow a finer influence. It |
1880 the master from user space and allow a finer influence. It should be possible |
1882 should be possible to view and to change special parameters at runtime. |
1881 to view and to change special parameters at runtime. |
1883 |
1882 |
1884 Bus visualization is a second point: For development and debugging |
1883 Bus visualization is a second point: For development and debugging purposes it |
1885 purposes it would be nice, if one could show the connected slaves with |
1884 would be nice, if one could show the connected slaves with a single command. |
1886 a single command. |
1885 |
1887 |
1886 Another aspect is automatic startup and configuration. If the master is to be |
1888 Another aspect is automatic startup and configuration. If the master |
1887 integrated into a running system, it must be able to automatically start with |
1889 is to be integrated into a running system, it must be able to |
1888 a persistent configuration. |
1890 automatically start with a persistent configuration. |
1889 |
1891 |
1890 A last thing is monitoring EtherCAT communication. For debugging purposes, |
1892 A last thing is monitoring EtherCAT communication. For debugging |
1891 there had to be a way to analyze EtherCAT datagrams. The best way would be |
1893 purposes, there had to be a way to analyze EtherCAT datagrams. The |
1892 with a popular network analyzer, like Wireshark \cite{wireshark} (the former |
1894 best way would be with a popular network analyzer, like Wireshark |
1893 Ethereal) or others. |
1895 \cite{wireshark} (the former Ethereal) or others. |
1894 |
1896 |
1895 This section covers all those points and introduces the interfaces and tools |
1897 This section covers all those points and introduces the interfaces and |
1896 to make all that possible. |
1898 tools to make all that possible. |
|
1899 |
1897 |
1900 %------------------------------------------------------------------------------ |
1898 %------------------------------------------------------------------------------ |
1901 |
1899 |
1902 \section{Command-line Tool} |
1900 \section{Command-line Tool} |
1903 \label{sec:ethercat} |
1901 \label{sec:ethercat} |