ec_master_init()的主要工作内容:
- 设置IDLE模式下数据发送周期;
- 初始化数据包队列;
- 初始化网络设备;
- 初始化master状态机;
- 初始化参考时钟数据包;
- 初始化对时数据包;
- 初始化对时监测数据包;
- 初始化字符设备,/dev/EtherCAT0;
初始化RTDM设备。
调试信息
[102714.802347] EtherCAT 0: 6 slave(s) responding on main device.
[102714.802354] EtherCAT 0: Slave states on main device: INIT, PREOP.
[102714.802423] EtherCAT DEBUG 0: Sending broadcast-write to measure transmission delays on main link.
[102714.802490] EtherCAT DEBUG 0: 6 slaves responded to delay measuring on main link.
[102714.802496] EtherCAT 0: Scanning bus.
[102714.802500] EtherCAT DEBUG 0: Scanning slave 0 on main link.
[102714.802672] EtherCAT DEBUG 0-0: Slave has the System Time register.
[102714.802769] EtherCAT DEBUG 0-0: Port 0 link status changed to up.
[102714.802776] EtherCAT DEBUG 0-0: Port 0 loop status changed to open.
[102714.802780] EtherCAT DEBUG 0-0: Port 0 signal status changed to yes.
[102714.802785] EtherCAT DEBUG 0-0: Port 1 link status changed to up.
[102714.802790] EtherCAT DEBUG 0-0: Port 1 loop status changed to open.
[102714.802794] EtherCAT DEBUG 0-0: Port 1 signal status changed to yes.
1. IDLE状态进程
设备打开后,设备驱动调用ec_master_enter_idle_phase,该函数中将启动ec_master_idle_thread进程
int ec_master_enter_idle_phase(
ec_master_t *master /**< EtherCAT master */
)
{
......
ret = ec_master_thread_start(master, ec_master_idle_thread, "EtherCAT-IDLE");
......
}
ec_master_idle_thread以设定的周期(send_interval)发送数据包并处理,其流程如下:
2. fsm_master状态机
官方文档中的状态转换图
broadcast状态输出的调试信息:
[102714.802347] EtherCAT 0: 6 slave(s) responding on main device.
[102714.802354] EtherCAT 0: Slave states on main device: INIT, PREOP.
broadcast扫描总线,读取到从站设备后,首先清除所有从站地址,并扫描总线拓扑,读取传输offset值。
在dc_measure_delays状态下输出调试信息:
[102714.802423] EtherCAT DEBUG 0: Sending broadcast-write to measure transmission delays on main link.
[102714.802490] EtherCAT DEBUG 0: 6 slaves responded to delay measuring on main link.
该状态跳转至scan_slave,并启动ec_fsm_slave_scan_start()进行从站设备扫描。
3. fsm_slave状态机
官方文档中的fsm_slave状态转换图
fsm_slave状态机进入datalink状态后,执行ec_slave_set_dl_status,设置dl层状态信息。
输出调试信息如下:
[102714.802672] EtherCAT DEBUG 0-0: Slave has the System Time register.
[102714.802769] EtherCAT DEBUG 0-0: Port 0 link status changed to up.
[102714.802776] EtherCAT DEBUG 0-0: Port 0 loop status changed to open.
[102714.802780] EtherCAT DEBUG 0-0: Port 0 signal status changed to yes.
[102714.802785] EtherCAT DEBUG 0-0: Port 1 link status changed to up.
[102714.802790] EtherCAT DEBUG 0-0: Port 1 loop status changed to open.
[102714.802794] EtherCAT DEBUG 0-0: Port 1 signal status changed to yes.
在sii_data状态下输出调试信息:
[102715.001302] EtherCAT DEBUG 0-0: Unknown category type 0x002A.
[102715.001351] EtherCAT DEBUG 0-0: Unknown category type 0x003C.
执行完成后进入pre-op状态,输出调试信息:
[102715.001357] EtherCAT DEBUG 0-0: Reading mailbox sync manager configuration.
[102715.001407] EtherCAT DEBUG 0-0: Mailbox configuration:
[102715.001416] EtherCAT DEBUG 0-0: RX offset=0x1000 size=128
[102715.001421] EtherCAT DEBUG 0-0: TX offset=0x1400 size=128
接下来进入ec_fsm_slave_scan_enter_pdos状态,输出调试信息:
[102715.001426] EtherCAT DEBUG 0-0: Scanning PDO assignment and mapping.
[102715.001431] EtherCAT DEBUG 0-0: Reading PDO assignment of SM2.
[102715.001436] EtherCAT DEBUG 0-0: Uploading SDO 0x1C12:00.
接下来为读取SDO及PDO信息,对所有从站重复上述操作,不再赘述。