[補充資料] EtherCAT Slave 定址 & Protocol 解析
[補充資料] EtherCAT Slave 定址 & Protocol 解析
By Advan @ 20210615
EtherCAT 為一基於Ethernet 基礎的通訊協定,格式的部分使用Ethernet 的表頭(下圖),並在EtherType 定義0x88A4 為EtherCAT 協定格式
雖然通訊協定已有Source & Destination 資訊,實際EtherCAT在Frame Route 採網路Topology 及ESC 的Port order/Port State 狀態決定封包流向,通訊定址方式上並不靠Source MAC & Destination MAC 方式做定址,採以 Slave的裝置排序和 topology的原則依排序做第一層的定位,爾後再依 Startup Check 做定址EtherCAT Addr,這份文件目的為說明上述的實際實現方法,也補充些EtherCAT運作說明。
[前言]
在應用端,我們對Slave(Physical) Read/Write時有幾種方式可以指定如下
Configured Address Physical Read ( FPRD/FPWR) eAdressingType_Fixed
Auto Increment Physical Read ( APRD/APWR) eAdressingType_AutoInc
Broadcast Read ( BRD/BWR) eAdressingType_BroadCAST
今天主要說明的會是AutoInc Addr的部分,因為AutoInc Addr 的位置定位是後續定址的基礎,沒有AutoInc Addr將不會有後續的Fix Address 使用,如下圖
TwinCAT Init command In IP state
由上可知,在TwinCAT Master Init 過程,即會依 TwinCAT Config 的設定,然後將ESC 的EEPROM的對應定義資料位置讀出後做比對,比對成功後,才會寫入EtherCAT Addr,之後才能使用FPxx 命令去指定Slave 的位置。
* Note TwinCAT 目前不提供Check Serial Number
出處 EtherCAT Technology (Section I)
目前到這邊主要帶出的問題如下
Q1. 在Wireshark 中(TwinCAT Promiscuous Mode) 所監看到的封包,會將Source MAC & Destination MAC 做對調,但這一機制是哪一個Slave 所做的,又怎麼知道已經返過不用再反了?
傳送封包資訊
返回封包資訊
Ans . 沒有人對調,是WireShark對調,ESC所做的處置為
Set MAC 資訊裡的Locally administred定義位元為1,Wireshark
收到返回封包時會自動交換這部分的呈現資訊,如下圖
Capure frame via ET2000 Probe unit
傳送封包資訊
返回封包資訊
依上資訊可知,所以在這部分,不論任何位置的ESC 不須做判斷,只要將流過的Locally administred Bit set 為一即可,Master 即可接收到返回封包。
Q2. EtherCAT 通訊方式不靠MAC 定址,靠的是Slave的AutoInc Addr順位,請問在Slave的視角,自己是如何知道在第幾個順位?
Ans. 這個問題,跟EtherCAT的通訊協定的設計,以及AutoInc定址規則有關,我們先來看一下EtherCAT中以位置Access的 命令及說明。
AutoInc Addr 定址規則 (固定規則)
First Slave AutoInc Addr = 0 0x0000
Second Slave AutoInc Addr = -1 0xFFFF
Third Slave AutoInc Addr = -2 0xFFFE
4th Slave AutoInc Addr = -3 0xFFFD
5th Slave AutoInc Addr = -4 0xFFFC.
To ~~~
63335th slave AutoInc Addr = 1 0x0001
0x01 APRD Auto increment physical read
Slave increments address. Slave puts read data into the EtherCAT datagram if received address is zero.
0x02 APWR Auto increment physical write
Slave increments address. Slave writes data into memory location if received address is zero.
0x03 APRW Auto increment physical read write
Slave increments address. Slave puts read data into the EtherCAT datagram and writes the data into the same memory location if received address is zero.
0x0D ARMW Auto increment physical read multiple
write
Slave increments address. Slave puts read data into the
EtherCAT datagram if received address is zero, otherwise slave writes the data
into memory location.
依上面的說明,其實還不易了解含意,以下說明
AutoInc Addr 的位址是指的是從Master 端做認定,Axxx 命令 在流經所有Slave 時,流經的Slave 會先檢查Adp 是否為零,若為0時則表示及為該命令指定的對象,不管是不是指定對象,都會將Adp 資訊做加一,會是先檢查完再加。
所以假設要指定對第五的Slave 做Axxx 命令,Master 會指定-4 (0xFFFC)的Adp 內容,在流經第一個Slave 後,該Slave 檢查Adp ,此時Adp 為-4,第一個Slave不做用,將Adp 資訊做加一
此時Adp 資訊變成-3,第二個Slave 也不做用,將Adp 資訊做加一
此時Adp 資訊變成-2,第三個Slave 也不做用,將Adp 資訊做加一
此時Adp 資訊變成-1,第四個Slave 也不做用,將Adp 資訊做加一
此時Adp 資訊變成0,第五個Slave 將其命令生效,也將Adp 資訊做加一
Q3. 承上述,請問在EtherCAT 的Hot Connect Group中,識別Slave 的能力又是如何實現的?
·
所謂Hot Connect 機制,指的是Slave 可能會在網路拓譜中的任何可能出現位置中連接上(Any Port),或是連接順序可以互換,去依ID的識別做EtherCAT 定址,不再以配置順序方式做依循。
·
Master 可藉由BRD/BWR 所回傳的Working Counter 得知,目前網路中總共有多少連接的Slave.
Ans.底層機制沒變,靠的是Master 端的逐一判斷並另外讀出Identity 數值做比對,比對符合後才會進行給定EtherCAT Address,在這之前Master 並不知道該Slave 存在於哪個AutoInc 位置。
也因為如此,在大型複雜網路中使用Hot Connect 的機制,網路啟動/異常復原時間都將會比較久。
*注意 ,使用DC同步的場合,Reference Clock 不能規劃在Hot Connect 群組內
參考資料
Ethernet frame: definition and variants of the frame format
EtherCAT Technology (Section I)
EtherCAT Technology Group
Alessandro Figini
EtherCAT command overview
0x00 NOP No operation
0x01 APRD Auto increment physical read
0x02 APWR Auto increment physical write
0x03 APRW Auto increment physical read write
0x04 FPRD Configured address physical read 0
0x05 FPWR Configured address physical write
0x06 FPRW Configured address physical read write
0x07 BRD Broadcast read
0x08 BWR Broadcast write
0x09 BRW Broadcast read write
0x0A LRD Logical memory read
0x0B LWR Logical memory write
0x0C LRW Logical memory read write
0x0D ARMW Auto increment physical read multiple write
0x0E FRMW Configured address physical read multiple write
留言
張貼留言