diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 63656570..4d9a40c0 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -15,6 +15,12 @@ build: - ./configure --with-linux-dir=/usr/src/linux-obj/$(uname -i)/default --enable-tty --with-devices=2 --enable-ccat - make -j8 all modules - make DISTCHECK_CONFIGURE_FLAGS="--with-linux-dir=/usr/src/linux-obj/$(uname -i)/default" distcheck + - make dist + - mkdir test_dist && cd test_dist && tar xzf ../ethercat-*.tar.gz && cd ethercat-*/ + - mkdir build && cd build + - ../configure --with-linux-dir=/usr/src/linux-obj/$(uname -i)/default --disable-8139too --enable-tty --with-devices=2 --enable-ccat + - make -j8 all modules + # Build ethercat tool subcommand help output for documentation commands: diff --git a/Makefile.kbuild b/Makefile.kbuild index a9439e36..92156104 100644 --- a/Makefile.kbuild +++ b/Makefile.kbuild @@ -3,7 +3,7 @@ # ``` # include $(top_srcdir)/Makefile.kbuild # ``` -KBUILD = $(MAKE) -C "$(LINUX_SOURCE_DIR)" M="$(abs_srcdir)" INSTALL_MOD_DIR="$(INSTALL_MOD_DIR)" +KBUILD = $(MAKE) -C "$(LINUX_SOURCE_DIR)" M="$(abs_builddir)" INSTALL_MOD_DIR="$(INSTALL_MOD_DIR)" modules: diff --git a/devices/Kbuild.in b/devices/Kbuild.in index 0b51cbbf..1454d3a2 100644 --- a/devices/Kbuild.in +++ b/devices/Kbuild.in @@ -25,6 +25,9 @@ # #------------------------------------------------------------------------------ +src := @abs_srcdir@ +ccflags-y := -I@abs_top_builddir@ + REV := $(shell if test -s $(src)/../revision; then \ cat $(src)/../revision; \ else \ diff --git a/devices/ccat/Kbuild.in b/devices/ccat/Kbuild.in index 825d89ac..18060caf 100644 --- a/devices/ccat/Kbuild.in +++ b/devices/ccat/Kbuild.in @@ -25,6 +25,9 @@ # #------------------------------------------------------------------------------ +src := @abs_srcdir@ +ccflags-y := -I@abs_top_builddir@ + TOPDIR := $(src)/../.. ifeq (@ENABLE_CCAT@,1) diff --git a/devices/ccat/Makefile.am b/devices/ccat/Makefile.am index be929c96..2c9916db 100644 --- a/devices/ccat/Makefile.am +++ b/devices/ccat/Makefile.am @@ -23,8 +23,14 @@ include $(top_srcdir)/Makefile.kbuild EXTRA_DIST = \ + gpio.c \ + module.c \ module.h \ + netdev.c \ netdev.h \ - update.h + sram.c \ + update.h \ + update.c + #------------------------------------------------------------------------------ diff --git a/devices/e1000/Kbuild.in b/devices/e1000/Kbuild.in index da6e7a15..11ab0dae 100644 --- a/devices/e1000/Kbuild.in +++ b/devices/e1000/Kbuild.in @@ -25,6 +25,9 @@ # #------------------------------------------------------------------------------ +src := @abs_srcdir@ +ccflags-y := -I@abs_top_builddir@ + TOPDIR := $(src)/../.. REV := $(shell if test -s $(TOPDIR)/revision; then \ diff --git a/devices/e1000e/Kbuild.in b/devices/e1000e/Kbuild.in index 06750abc..ce3fc7c1 100644 --- a/devices/e1000e/Kbuild.in +++ b/devices/e1000e/Kbuild.in @@ -25,6 +25,9 @@ # #------------------------------------------------------------------------------ +src := @abs_srcdir@ +ccflags-y := -I@abs_top_builddir@ + TOPDIR := $(src)/../.. REV := $(shell if test -s $(TOPDIR)/revision; then \ diff --git a/devices/igb/Kbuild.in b/devices/igb/Kbuild.in index 35308ef6..cdcdec3e 100644 --- a/devices/igb/Kbuild.in +++ b/devices/igb/Kbuild.in @@ -25,6 +25,9 @@ # #------------------------------------------------------------------------------ +src := @abs_srcdir@ +ccflags-y := -I@abs_top_builddir@ + TOPDIR := $(src)/../.. REV := $(shell if test -s $(TOPDIR)/revision; then \ diff --git a/examples/dc_rtai/Kbuild.in b/examples/dc_rtai/Kbuild.in index cc1cf150..89c2af34 100644 --- a/examples/dc_rtai/Kbuild.in +++ b/examples/dc_rtai/Kbuild.in @@ -25,6 +25,9 @@ # #------------------------------------------------------------------------------ +src := @abs_srcdir@ +ccflags-y := -I@abs_top_builddir@ + obj-m := ec_dc_rtai_sample.o ec_dc_rtai_sample-objs := dc_rtai_sample.o diff --git a/examples/mini/Kbuild.in b/examples/mini/Kbuild.in index da368ae3..c39ca49b 100644 --- a/examples/mini/Kbuild.in +++ b/examples/mini/Kbuild.in @@ -25,6 +25,8 @@ # #------------------------------------------------------------------------------ +src := @abs_srcdir@ + obj-m := ec_mini.o ec_mini-objs := mini.o diff --git a/examples/rtai/Kbuild.in b/examples/rtai/Kbuild.in index 2d371456..e6523f13 100644 --- a/examples/rtai/Kbuild.in +++ b/examples/rtai/Kbuild.in @@ -25,6 +25,9 @@ # #------------------------------------------------------------------------------ +src := @abs_srcdir@ +ccflags-y := -I@abs_top_builddir@ + obj-m := ec_rtai_sample.o ec_rtai_sample-objs := rtai_sample.o diff --git a/examples/tty/Kbuild.in b/examples/tty/Kbuild.in index df7e4374..72a7f109 100644 --- a/examples/tty/Kbuild.in +++ b/examples/tty/Kbuild.in @@ -25,6 +25,9 @@ # #------------------------------------------------------------------------------ +src := @abs_srcdir@ +ccflags-y := -I@abs_top_builddir@ + obj-m := ec_tty_example.o ec_tty_example-objs := \ diff --git a/include/ecrt.h b/include/ecrt.h index 1cf32420..9a041986 100644 --- a/include/ecrt.h +++ b/include/ecrt.h @@ -1,6 +1,6 @@ /****************************************************************************** * - * Copyright (C) 2006-2023 Florian Pose, Ingenieurgemeinschaft IgH + * Copyright (C) 2006-2024 Florian Pose, Ingenieurgemeinschaft IgH * * This file is part of the IgH EtherCAT master userspace library. * @@ -42,6 +42,12 @@ * e.g. in RTAI/Xenomai Real-Time tasks or in atomic/softirq/tasklet * context in kernel modules. You have been warned. * + * Changes in version 1.6.0: + * + * - Added the ecrt_master_scan_progress() method, the + * ec_master_scan_progress_t structure and the EC_HAVE_SCAN_PROGRESS + * definition to check for its existence. + * * Changes since version 1.5.2: * * - Added the ecrt_slave_config_flag() method and the EC_HAVE_FLAGS @@ -232,6 +238,11 @@ */ #define EC_HAVE_SOE_REQUESTS +/** Defined, if the method ecrt_master_scan_progress() and the + * ec_master_scan_progress_t sttucture are available. + */ +#define EC_HAVE_SCAN_PROGRESS + /*****************************************************************************/ /** Symbol visibility control macro. @@ -394,6 +405,21 @@ typedef struct { /*****************************************************************************/ +/** Master scan progress information. + * + * This is used as an output parameter of ecrt_master_scan_progress(). + * + * \see ecrt_master_scan_progress(). + */ +typedef struct { + unsigned int slave_count; /**< Number of slaves detected. */ + unsigned int scan_index; /**< Index of the slave that is currently scanned. + If it is less than the \a slave_count, the + network scan is in progress. */ +} ec_master_scan_progress_t; + +/*****************************************************************************/ + /** EtherCAT slave port descriptor. */ typedef enum { @@ -789,6 +815,20 @@ EC_PUBLIC_API int ecrt_master( information */ ); +/** Obtains network scan progress information. + * + * No memory is allocated on the heap in this function. + * + * \attention The pointer to this structure must point to a valid variable. + * + * \return 0 in case of success, else < 0 + */ +int ecrt_master_scan_progress( + ec_master_t *master, /**< EtherCAT master */ + ec_master_scan_progress_t *progress /**< Structure that will output + the progress information. */ + ); + /** Obtains slave information. * * Tries to find the slave with the given ring position. The obtained diff --git a/lib/master.c b/lib/master.c index 181cebc4..837b2855 100644 --- a/lib/master.c +++ b/lib/master.c @@ -245,6 +245,26 @@ int ecrt_master(ec_master_t *master, ec_master_info_t *master_info) /****************************************************************************/ +int ecrt_master_scan_progress(ec_master_t *master, + ec_master_scan_progress_t *progress) +{ + ec_ioctl_master_t data; + int ret; + + ret = ioctl(master->fd, EC_IOCTL_MASTER, &data); + if (EC_IOCTL_IS_ERROR(ret)) { + fprintf(stderr, "Failed to get master info: %s\n", + strerror(EC_IOCTL_ERRNO(ret))); + return -EC_IOCTL_ERRNO(ret); + } + + progress->slave_count = data.slave_count; + progress->scan_index = data.scan_index; + return 0; +} + +/****************************************************************************/ + int ecrt_master_get_slave(ec_master_t *master, uint16_t slave_position, ec_slave_info_t *slave_info) { diff --git a/master/Kbuild.in b/master/Kbuild.in index 16b2c3be..ad1b7486 100644 --- a/master/Kbuild.in +++ b/master/Kbuild.in @@ -25,6 +25,9 @@ # #------------------------------------------------------------------------------ +src := @abs_srcdir@ +ccflags-y := -I@abs_top_builddir@ + obj-m := ec_master.o ec_master-objs := \ diff --git a/master/Makefile.am b/master/Makefile.am index 17a85a43..4539998d 100644 --- a/master/Makefile.am +++ b/master/Makefile.am @@ -33,6 +33,7 @@ noinst_HEADERS = \ domain.c domain.h \ doxygen.c \ ethernet.c ethernet.h \ + flag.c flag.h \ fmmu_config.c fmmu_config.h \ foe.h \ foe_request.c foe_request.h \ diff --git a/master/fsm_master.c b/master/fsm_master.c index 707ddb03..bc18d170 100644 --- a/master/fsm_master.c +++ b/master/fsm_master.c @@ -333,6 +333,7 @@ void ec_fsm_master_state_broadcast( ec_device_index_t dev_idx; master->scan_busy = 1; + master->scan_index = 0; up(&master->scan_sem); // clear all slaves and scan the bus @@ -836,6 +837,7 @@ void ec_fsm_master_state_clear_addresses( ec_device_names[fsm->dev_idx != 0]); ec_datagram_print_state(datagram); master->scan_busy = 0; + master->scan_index = master->slave_count; wake_up_interruptible(&master->scan_queue); ec_fsm_master_restart(fsm); return; @@ -879,6 +881,7 @@ void ec_fsm_master_state_dc_measure_delays( " on %s link: ", ec_device_names[fsm->dev_idx != 0]); ec_datagram_print_state(datagram); master->scan_busy = 0; + master->scan_index = master->slave_count; wake_up_interruptible(&master->scan_queue); ec_fsm_master_restart(fsm); return; @@ -901,6 +904,7 @@ void ec_fsm_master_state_dc_measure_delays( // begin scanning of slaves fsm->slave = master->slaves; + master->scan_index = 0; EC_MASTER_DBG(master, 1, "Scanning slave %u on %s link.\n", fsm->slave->ring_position, ec_device_names[fsm->slave->device_index != 0]); @@ -946,6 +950,7 @@ void ec_fsm_master_state_scan_slave( // another slave to fetch? fsm->slave++; + master->scan_index++; if (fsm->slave < master->slaves + master->slave_count) { EC_MASTER_DBG(master, 1, "Scanning slave %u on %s link.\n", fsm->slave->ring_position, @@ -960,6 +965,7 @@ void ec_fsm_master_state_scan_slave( (jiffies - fsm->scan_jiffies) * 1000 / HZ); master->scan_busy = 0; + master->scan_index = master->slave_count; wake_up_interruptible(&master->scan_queue); ec_master_calc_dc(master); diff --git a/master/fsm_slave_config.c b/master/fsm_slave_config.c index 6b14229f..c8da0762 100644 --- a/master/fsm_slave_config.c +++ b/master/fsm_slave_config.c @@ -16,8 +16,6 @@ * You should have received a copy of the GNU General Public License along * with the IgH EtherCAT Master; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * --- */ /** \file diff --git a/master/fsm_slave_config.h b/master/fsm_slave_config.h index 0a7edfbb..5086c403 100644 --- a/master/fsm_slave_config.h +++ b/master/fsm_slave_config.h @@ -16,8 +16,6 @@ * You should have received a copy of the GNU General Public License along * with the IgH EtherCAT Master; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * --- */ /** diff --git a/master/ioctl.c b/master/ioctl.c index 25639eaf..2fc863d6 100644 --- a/master/ioctl.c +++ b/master/ioctl.c @@ -16,8 +16,6 @@ * You should have received a copy of the GNU General Public License along * with the IgH EtherCAT Master; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * --- */ /** @@ -120,6 +118,7 @@ static ATTRIBUTES int ec_ioctl_master( } io.slave_count = master->slave_count; + io.scan_index = master->scan_index; io.config_count = ec_master_config_count(master); io.domain_count = ec_master_domain_count(master); #ifdef EC_EOE diff --git a/master/ioctl.h b/master/ioctl.h index 20c4de6d..7a5e57b9 100644 --- a/master/ioctl.h +++ b/master/ioctl.h @@ -47,7 +47,7 @@ * * Increment this when changing the ioctl interface! */ -#define EC_IOCTL_VERSION_MAGIC 33 +#define EC_IOCTL_VERSION_MAGIC 34 // Command-line tool #define EC_IOCTL_MODULE EC_IOR(0x00, ec_ioctl_module_t) @@ -169,6 +169,7 @@ typedef struct { typedef struct { uint32_t slave_count; + uint32_t scan_index; uint32_t config_count; uint32_t domain_count; uint32_t eoe_handler_count; diff --git a/master/master.c b/master/master.c index 3a34a8c2..2ef2c561 100644 --- a/master/master.c +++ b/master/master.c @@ -186,6 +186,7 @@ int ec_master_init(ec_master_t *master, /**< EtherCAT master */ master->dc_ref_time = 0ULL; master->scan_busy = 0; + master->scan_index = 0; master->allow_scan = 1; sema_init(&master->scan_sem, 1); init_waitqueue_head(&master->scan_queue); @@ -2629,6 +2630,19 @@ int ecrt_master(ec_master_t *master, ec_master_info_t *master_info) /*****************************************************************************/ +int ecrt_master_scan_progress(ec_master_t *master, + ec_master_scan_progress_t *progress) +{ + EC_MASTER_DBG(master, 1, "ecrt_master_scan_progress(master = 0x%p," + " progress = 0x%p)\n", master, progress); + + progress->slave_count = master->slave_count; + progress->scan_index = master->scan_index; + return 0; +} + +/*****************************************************************************/ + int ecrt_master_get_slave(ec_master_t *master, uint16_t slave_position, ec_slave_info_t *slave_info) { @@ -3252,6 +3266,7 @@ EXPORT_SYMBOL(ecrt_master_send_ext); EXPORT_SYMBOL(ecrt_master_receive); EXPORT_SYMBOL(ecrt_master_callbacks); EXPORT_SYMBOL(ecrt_master); +EXPORT_SYMBOL(ecrt_master_scan_progress); EXPORT_SYMBOL(ecrt_master_get_slave); EXPORT_SYMBOL(ecrt_master_slave_config); EXPORT_SYMBOL(ecrt_master_select_reference_clock); diff --git a/master/master.h b/master/master.h index afdbde42..12e07cd1 100644 --- a/master/master.h +++ b/master/master.h @@ -1,8 +1,6 @@ /****************************************************************************** * - * $Id$ - * - * Copyright (C) 2006-2012 Florian Pose, Ingenieurgemeinschaft IgH + * Copyright (C) 2006-2024 Florian Pose, Ingenieurgemeinschaft IgH * * This file is part of the IgH EtherCAT Master. * @@ -36,9 +34,7 @@ #include #include #include - #include -#include #include "device.h" #include "domain.h" @@ -235,6 +231,7 @@ struct ec_master { ec_slave_t *dc_ref_clock; /**< DC reference clock slave. */ unsigned int scan_busy; /**< Current scan state. */ + unsigned int scan_index; /**< Index of slave currently scanned. */ unsigned int allow_scan; /**< \a True, if slave scanning is allowed. */ struct semaphore scan_sem; /**< Semaphore protecting the \a scan_busy variable and the \a allow_scan flag. */ diff --git a/tty/Kbuild.in b/tty/Kbuild.in index 09d0ae3a..78370c74 100644 --- a/tty/Kbuild.in +++ b/tty/Kbuild.in @@ -26,6 +26,9 @@ # #------------------------------------------------------------------------------ +src := @abs_srcdir@ +ccflags-y := -I@abs_top_builddir@ + obj-m := ec_tty.o ec_tty-objs := \