Some time ago, we had an object where the terms of reference included the requirement: "Ethercat protocol". In the process of searching for information, I climbed into Habr and was surprised to find that there was no parsing of this protocol there. And in general, information about him is rather fragmented (looking ahead - I was just looking in the wrong place). We made a project, and this article is for the "younger me", an attempt to save time for someone else who is going to use or is simply interested in this protocol.
The only caveat is that I will describe the rather low level of the protocol (Data Layer in EtherCAT terminology). Because it was he who we needed and we limited ourselves to him. Application Layer protocols such as CanOPEN-over-EtherCAT (CoE) will remain undescribed (for now?).
EtherCAT in one sentence
It's easy to google it, but for the sake of order I will say it in my own words. EtherCAT is an industrial communication bus with a high throughput (100 Mbit / s) and a response speed (a few microseconds for dozens of devices on one line, separated by tens of meters), using Ethernet at a low level, but at the same time it differs from the usual Ethernet concept. answer".
Ethernet β , , . EtherCAT β , ( EtherCAT-) , .
, , . β , . β , , β UDP, EtherCAT . EtherCAT- β , β ARP . EtherCAT-.
"" , . , .
, β Infineon XMC4300\4800 Microchip LAN9252. ( - ), β EtherCAT ( ).
EtherCAT XMC4800 Relax EtherCAT Kit. ? β , ( ) .
.
:
- Beckhoff, TwinCAT, . β , . β . β , . . , .
- Open source , https://github.com/OpenEtherCATsociety/SOEM. STM32F207 FreeRTOS . , , . , .
WireShark. , , .
, . -, , , wkc2 APWRw. : EtherCAT_Communication_EN.pdf. β ethercat.org . EtherCAT association. , ( NDA, Beckhoff - ), , .
β , .
,
-, , Ethercat, Ethercat. , Vendor ID. , . https://ethercat.org/en/membership_application.html
VendorID! , VendorID . β "", .. EtherCAT . - , - β .
ethercat
, . β . . ?
4 , 2 (port 0 port 1). :
: , ( ). . 0 ethercat processing unit, , .
, ethercat , port0 , port 0, ethercat processing unit, .. port0 .
:
port0 port1, port0 , .. , (? 0) .
.
? , β Ethercat .
. ""? . β ethernet . . ? , - , : β . β ( ).
, . , , , β "" 1, 0 . β ethercat. , , .
, "4- " "" , , .
, , "". Ethernet β \ . IP ( ARP ), MAC . 4 .
, infineon, microchip 2.
ethercat β Beckhoff 4- ethercat :
https://www.beckhoff.com/ru/default.htm?ethercat/ek1100.htm
https://www.beckhoff.com/ru/default.htm?ethercat/ek1122.htm
, , - ethernet switch. , ( ).
\. Ethercat β broadcast MAC , . β ( ), , , β , .
slave β DPRAM
, slave β , . Infineon , SPI. 4 ( 0x1000) β , ethercat, .
XMC4800 8
( ) , EtherCAT . , .
( XMC), :
- 0x000 β TYPE = 0x98 ( )
- 0x010 β STATION_ADR, ( , )
- 0x040 β RESET_ECAT, .
- 0x100 β DL_CONTROL, (\)
- 0x110 β DL_STATUS, ( )
. .
master'a β ethercat .
. ethercat .
:
, ( TCP UDP, 0x88A4), UDP . UDP ( ethercat ), Ethercat β - UDP .
:
, Working counter (WKC).
Wkc β . , wkc wkc ( wkc ). , , BRD " " wkc .
- Cmd β . , .
- Idx β , . . SOEM \.
- Address β . Cmd β 16- ADP ADO ( ), 32- (Logical Addr).
- Len β .
- C, R, M, IRQ β , β . SOEM .
, Cmd. . . BRD BRD.
APxx | . ADP " ". ? , 0x0000 . |
FPxx | . STATION_ADR ADP |
Bxx | . . , , OR . .. , 0 |
Lxx | . FMMU, 32- , . . |
xxRD | . ( ) |
xxWR | . , |
xxRW | . LRW - , . . |
xxRMW | . ADP (. ) , . LRW . |
SyncManager
EtherCAT ( ) SyncManager.
SyncManager (SM) β ethercat , .
0x800. SM 8 , .. 0x800-0x807 SM1, 0x808-0x80F SM2 . XMC4800 8 SyncManager.
β mailbox . . , .
Mailbox β - ethercat. , .
Buffered β . .
- Mailbox Read. β ( WKC=0). ( ) β - ( WKC=0). ( ) β ( ), (WKC 1) .
- Mailbox Write. . , , ( ) WKC=0.
- Buffered Read. . , . , .. SyncManager 0x1000-0x1010, 0x1000-0x1030. 0x1000-0x1010, , .
- Buffered Write. , . .. , , .
FMMU
Ethercat, LRW. Fieldbus Memory Management Unit (FMMU). . SyncManager, . , . , , , , StartBit 0, EndBit β 7.
, . FMMU0 0x1000 ( ), 0x12345678+4*
, 4 , READ. FMMU0 0x1000 ( ), 0x12345678+400+4*
, WRITE. LRW 0x12345678, 800 , . . , , ( slave2slave communication), .
, FMMU , SyncManager .
EtherCAT Beckhoff . EEPROM . AL_STATUS, EEPROM . CanOPEN-over-EtherCAT(CoE) \. Ethernet-over-EtherCAT(EoE) Files-over-EtherCAT (FoE) . ESI- c VendorID . . , , EtherCAT , , .