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

最近开始学习EtherCAT总线协议,以开源iGH EtherCAT主站协议栈为基础。由于没做过大型Linux程序开发,学习起来很慢,目前的方法是追踪调试信息,以摸清程序架构。

1.执行/etc/init.d/ethercat start

[91557.546292] EtherCAT: Master driver 1.5.2 33b922ec1871+
[91557.546575] EtherCAT 0: Registering RTDM device EtherCAT.
[91557.546602] EtherCAT: 1 master waiting for devices.
[91557.619343] ec_r8169 Gigabit Ethernet driver 2.3LK-NAPI loaded
[91557.619770] ec_r8169 0000:05:00.0: irq 30 for MSI/MSI-X
[91557.619813] EtherCAT: Accepting 00:00:00:00:00:00 as main device for master 0.
[91557.619829] ec_r8169 0000:05:00.0 ecm0 (uninitialized): RTL8168e/8111e at 0xffffc9000000e000, 00:00:00:00:00:00, XID 0c200000 IRQ 30
[91557.619839] ec_r8169 0000:05:00.0 ecm0 (uninitialized): jumbo features [frames: 9200 bytes, tx checksumming: ko]
[91557.780709] EtherCAT 0: Starting EtherCAT-IDLE thread.

程序入口 为module.c
主要功能为生成/dev/EtherCAT0这个设备,module.c相当于设备驱动

/** Module initialization.
 *
 * Initializes \a master_count masters.
 * \return 0 on success, else < 0
 */
int __init ec_init_module(void)

进入ec_init_module时打印:
Master driver 1.5.2 33b922ec1871+
ec_master_init过程中调用ec_rtdm_dev_init(rtdm.c)打印:
Registering RTDM device EtherCAT.
初始化完成后输出
1 master waiting for devices.

在ec_master_init的最后阶段运行了ec_rtdm_dev_init(),对rtdm设备进行初始化。
ec_master_init完成后,系统生成/dev/EtherCAT0字符设备,内核的驱动守护进程udev会加载该设备的驱动ec_master.ko以及依赖模块ec_r8169.ko。
驱动加载完成后,调用ecdev_offer(module.c)完成网卡的挂载,打印:
Accepting 00:00:00:00:00:00 as main device for master 0.
网卡驱动初始化过程中调用ecdev_open,打开EtherCAT设备,并进入IDLE phase。

2.插上网线
输出调试信息

[101761.955927] EtherCAT 0: Link state of ecm0 changed to UP.
[101761.959969] EtherCAT 0: 6 slave(s) responding on main device.
[101761.959976] EtherCAT 0: Slave states on main device: PREOP.
[101761.960135] EtherCAT 0: Scanning bus.
[101763.451924] EtherCAT 0: Bus scanning completed in 1492 ms.
[101763.451934] EtherCAT 0: Using slave 0 as DC reference clock.

由网卡驱动调用ecdev_set_link() (device.c)
这段操作由内核负责完成ec_master模块和网卡驱动模块的调用,具体由udev来管理,目前未深入研究。

你可能感兴趣的:(EtherCAT)