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} |
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} |
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 |
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 |