iGH EtherCAT初始化流程分析(二)

ec_master_init()的主要工作内容:

  1. 设置IDLE模式下数据发送周期;
  2. 初始化数据包队列;
  3. 初始化网络设备;
  4. 初始化master状态机;
  5. 初始化参考时钟数据包;
  6. 初始化对时数据包;
  7. 初始化对时监测数据包;
  8. 初始化字符设备,/dev/EtherCAT0;
  9. 初始化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)发送数据包并处理,其流程如下:

Created with Raphaël 2.1.0 开始 更新数据包统计信息 接收数据包 执行fsm_master状态机和fsm_slave状态机 发送数据包 到达定时时间? yes

2. fsm_master状态机

iGH EtherCAT初始化流程分析(二)_第1张图片
官方文档中的状态转换图

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状态机

iGH EtherCAT初始化流程分析(二)_第2张图片
官方文档中的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信息,对所有从站重复上述操作,不再赘述。

你可能感兴趣的:(EtherCAT)