From 5c2955139e98c640899a9530b8662fb45b82ce35 Mon Sep 17 00:00:00 2001 From: Shahbaz Youssefi Date: Fri, 18 Dec 2015 09:38:09 -0500 Subject: [PATCH 1/4] Include relative to file This allows the header files to be installed, say in /usr/include/soem and then included with: #include without having to add -I/usr/include/soem. Signed-off-by: Shahbaz Youssefi --- osal/osal.h | 2 +- soem/ethercattype.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/osal/osal.h b/osal/osal.h index fd20817..5db787b 100644 --- a/osal/osal.h +++ b/osal/osal.h @@ -21,7 +21,7 @@ #ifndef _osal_ #define _osal_ -#include +#include "osal_defs.h" #include /* General types */ diff --git a/soem/ethercattype.h b/soem/ethercattype.h index d765470..8fed22f 100644 --- a/soem/ethercattype.h +++ b/soem/ethercattype.h @@ -66,7 +66,7 @@ extern "C" * comment if application uses only ecx_ functions and own context */ #define EC_VER1 -#include +#include "osal.h" /** return value general error */ #define EC_ERROR -3 From 529ffbe0cdd02e4a17424c9e4bf2f4da21c2fd09 Mon Sep 17 00:00:00 2001 From: Shahbaz Youssefi Date: Fri, 18 Dec 2015 09:56:33 -0500 Subject: [PATCH 2/4] Add a single header for all ethercat headers This way, applications don't need to know the details of every header file that exists in the API. With a simple: #include they would get everything. This is specially important because the order of including the header files is important! Signed-off-by: Shahbaz Youssefi --- soem/ethercat.h | 61 ++++++++++++++++++++++++++++ test/intime/ec_master/ec_master.c | 9 +--- test/linux/aliastool.c | 9 +--- test/linux/ebox/ebox.c | 8 +--- test/linux/eepromtool/eepromtool.c | 9 +--- test/linux/firm_update/firm_update.c | 9 +--- test/linux/red_test/red_test.c | 9 +--- test/linux/simple_test/simple_test.c | 10 +---- test/linux/slaveinfo/slaveinfo.c | 9 +--- test/rtk/main.c | 9 +--- test/win32/ebox/ebox.c | 8 +--- test/win32/eepromtool/eepromtool.c | 9 +--- test/win32/firm_update/firm_update.c | 9 +--- test/win32/red_test/red_test.c | 8 +--- test/win32/simple_test/simple_test.c | 10 +---- test/win32/slaveinfo/slaveinfo.c | 9 +--- 16 files changed, 76 insertions(+), 119 deletions(-) create mode 100644 soem/ethercat.h diff --git a/soem/ethercat.h b/soem/ethercat.h new file mode 100644 index 0000000..a0d6321 --- /dev/null +++ b/soem/ethercat.h @@ -0,0 +1,61 @@ +/* + * Simple Open EtherCAT Master Library + * + * File : ethercat.h + * Version : 1.3.1 + * Date : 18-12-2015 + * Copyright (C) 2005-2015 Speciaal Machinefabriek Ketels v.o.f. + * Copyright (C) 2005-2015 Arthur Ketels + * Copyright (C) 2008-2009 TU/e Technische Universiteit Eindhoven + * Copyright (C) 2014-2015 rt-labs AB , Sweden + * + * SOEM is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License version 2 as published by the Free + * Software Foundation. + * + * SOEM is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * As a special exception, if other files instantiate templates or use macros + * or inline functions from this file, or you compile this file and link it + * with other works to produce a work based on this file, this file does not + * by itself cause the resulting work to be covered by the GNU General Public + * License. However the source code for this file must still be made available + * in accordance with section (3) of the GNU General Public License. + * + * This exception does not invalidate any other reasons why a work based on + * this file might be covered by the GNU General Public License. + * + * The EtherCAT Technology, the trade name and logo “EtherCAT” are the intellectual + * property of, and protected by Beckhoff Automation GmbH. You can use SOEM for + * the sole purpose of creating, using and/or selling or otherwise distributing + * an EtherCAT network master provided that an EtherCAT Master License is obtained + * from Beckhoff Automation GmbH. + * + * In case you did not receive a copy of the EtherCAT Master License along with + * SOEM write to Beckhoff Automation GmbH, Eiserstraße 5, D-33415 Verl, Germany + * (www.beckhoff.com). + */ + +/** \file + * \brief + * Headerfile for all ethercat headers + */ + +#ifndef _EC_ETHERCAT_H +#define _EC_ETHERCAT_H + +#include "ethercattype.h" +#include "nicdrv.h" +#include "ethercatbase.h" +#include "ethercatmain.h" +#include "ethercatdc.h" +#include "ethercatcoe.h" +#include "ethercatfoe.h" +#include "ethercatsoe.h" +#include "ethercatconfig.h" +#include "ethercatprint.h" + +#endif /* _EC_ETHERCAT_H */ diff --git a/test/intime/ec_master/ec_master.c b/test/intime/ec_master/ec_master.c index 2065014..06535b1 100644 --- a/test/intime/ec_master/ec_master.c +++ b/test/intime/ec_master/ec_master.c @@ -36,14 +36,7 @@ #include #include -#include "nicdrv.h" -#include "ethercattype.h" -#include "ethercatbase.h" -#include "ethercatmain.h" -#include "ethercatconfig.h" -#include "ethercatcoe.h" -#include "ethercatdc.h" -#include "ethercatprint.h" +#include "ethercat.h" char IOmap[4096]; diff --git a/test/linux/aliastool.c b/test/linux/aliastool.c index 5cd1352..23607b6 100644 --- a/test/linux/aliastool.c +++ b/test/linux/aliastool.c @@ -21,14 +21,7 @@ #include #include -#include "ethercattype.h" -#include "nicdrv.h" -#include "ethercatbase.h" -#include "ethercatmain.h" -#include "ethercatcoe.h" -//#include "ethercatfoe.h" -//#include "ethercatconfig.h" -//#include "ethercatprint.h" +#include "ethercat.h" #define MAXBUF 32768 #define STDBUF 2048 diff --git a/test/linux/ebox/ebox.c b/test/linux/ebox/ebox.c index 81b5a5b..68e0e6a 100644 --- a/test/linux/ebox/ebox.c +++ b/test/linux/ebox/ebox.c @@ -21,13 +21,7 @@ #include #include -#include "ethercattype.h" -#include "nicdrv.h" -#include "ethercatbase.h" -#include "ethercatmain.h" -#include "ethercatcoe.h" -#include "ethercatconfig.h" -#include "ethercatdc.h" +#include "ethercat.h" #define NSEC_PER_SEC 1000000000 diff --git a/test/linux/eepromtool/eepromtool.c b/test/linux/eepromtool/eepromtool.c index 883e1a1..23d29ff 100644 --- a/test/linux/eepromtool/eepromtool.c +++ b/test/linux/eepromtool/eepromtool.c @@ -18,14 +18,7 @@ #include #include -#include "ethercattype.h" -#include "nicdrv.h" -#include "ethercatbase.h" -#include "ethercatmain.h" -#include "ethercatcoe.h" -//#include "ethercatfoe.h" -//#include "ethercatconfig.h" -//#include "ethercatprint.h" +#include "ethercat.h" #define MAXBUF 32768 #define STDBUF 2048 diff --git a/test/linux/firm_update/firm_update.c b/test/linux/firm_update/firm_update.c index 66b9b32..0cd511e 100644 --- a/test/linux/firm_update/firm_update.c +++ b/test/linux/firm_update/firm_update.c @@ -18,14 +18,7 @@ #include #include -#include "ethercattype.h" -#include "nicdrv.h" -#include "ethercatbase.h" -#include "ethercatmain.h" -#include "ethercatcoe.h" -#include "ethercatfoe.h" -#include "ethercatconfig.h" -#include "ethercatprint.h" +#include "ethercat.h" #define FWBUFSIZE (8 * 1024 * 1024) diff --git a/test/linux/red_test/red_test.c b/test/linux/red_test/red_test.c index 967553d..e5d4bd1 100644 --- a/test/linux/red_test/red_test.c +++ b/test/linux/red_test/red_test.c @@ -21,14 +21,7 @@ #include #include -#include "ethercattype.h" -#include "nicdrv.h" -#include "ethercatbase.h" -#include "ethercatmain.h" -#include "ethercatcoe.h" -#include "ethercatconfig.h" -#include "ethercatdc.h" -#include "ethercatprint.h" +#include "ethercat.h" #define NSEC_PER_SEC 1000000000 #define EC_TIMEOUTMON 500 diff --git a/test/linux/simple_test/simple_test.c b/test/linux/simple_test/simple_test.c index 4d67ee8..1ef7773 100644 --- a/test/linux/simple_test/simple_test.c +++ b/test/linux/simple_test/simple_test.c @@ -12,15 +12,7 @@ #include #include -#include "ethercattype.h" -#include "nicdrv.h" -#include "ethercatbase.h" -#include "ethercatmain.h" -#include "ethercatdc.h" -#include "ethercatcoe.h" -#include "ethercatfoe.h" -#include "ethercatconfig.h" -#include "ethercatprint.h" +#include "ethercat.h" #define EC_TIMEOUTMON 500 diff --git a/test/linux/slaveinfo/slaveinfo.c b/test/linux/slaveinfo/slaveinfo.c index cc9cbc2..f9b0621 100644 --- a/test/linux/slaveinfo/slaveinfo.c +++ b/test/linux/slaveinfo/slaveinfo.c @@ -15,14 +15,7 @@ #include #include -#include "ethercattype.h" -#include "nicdrv.h" -#include "ethercatbase.h" -#include "ethercatmain.h" -#include "ethercatconfig.h" -#include "ethercatcoe.h" -#include "ethercatdc.h" -#include "ethercatprint.h" +#include "ethercat.h" char IOmap[4096]; ec_ODlistt ODlist; diff --git a/test/rtk/main.c b/test/rtk/main.c index a9264a9..183392d 100644 --- a/test/rtk/main.c +++ b/test/rtk/main.c @@ -8,14 +8,7 @@ */ #include -#include "ethercattype.h" -#include "nicdrv.h" -#include "ethercatbase.h" -#include "ethercatmain.h" -#include "ethercatcoe.h" -#include "ethercatfoe.h" -#include "ethercatconfig.h" -#include "ethercatprint.h" +#include "ethercat.h" #include "string.h" #include #include diff --git a/test/win32/ebox/ebox.c b/test/win32/ebox/ebox.c index 89abe11..7d232bf 100644 --- a/test/win32/ebox/ebox.c +++ b/test/win32/ebox/ebox.c @@ -21,13 +21,7 @@ #include #include -#include "ethercattype.h" -#include "nicdrv.h" -#include "ethercatbase.h" -#include "ethercatmain.h" -#include "ethercatcoe.h" -#include "ethercatconfig.h" -#include "ethercatdc.h" +#include "ethercat.h" #define NSEC_PER_SEC 1000000000 diff --git a/test/win32/eepromtool/eepromtool.c b/test/win32/eepromtool/eepromtool.c index a950def..6e9092c 100644 --- a/test/win32/eepromtool/eepromtool.c +++ b/test/win32/eepromtool/eepromtool.c @@ -16,14 +16,7 @@ #include #include -#include "ethercattype.h" -#include "nicdrv.h" -#include "ethercatbase.h" -#include "ethercatmain.h" -#include "ethercatcoe.h" -//#include "ethercatfoe.h" -//#include "ethercatconfig.h" -//#include "ethercatprint.h" +#include "ethercat.h" #define MAXBUF 32768 #define STDBUF 2048 diff --git a/test/win32/firm_update/firm_update.c b/test/win32/firm_update/firm_update.c index 66b9b32..0cd511e 100644 --- a/test/win32/firm_update/firm_update.c +++ b/test/win32/firm_update/firm_update.c @@ -18,14 +18,7 @@ #include #include -#include "ethercattype.h" -#include "nicdrv.h" -#include "ethercatbase.h" -#include "ethercatmain.h" -#include "ethercatcoe.h" -#include "ethercatfoe.h" -#include "ethercatconfig.h" -#include "ethercatprint.h" +#include "ethercat.h" #define FWBUFSIZE (8 * 1024 * 1024) diff --git a/test/win32/red_test/red_test.c b/test/win32/red_test/red_test.c index 1d580c6..9adf373 100644 --- a/test/win32/red_test/red_test.c +++ b/test/win32/red_test/red_test.c @@ -21,13 +21,7 @@ #include #include -#include "ethercattype.h" -#include "nicdrv.h" -#include "ethercatbase.h" -#include "ethercatmain.h" -#include "ethercatcoe.h" -#include "ethercatconfig.h" -#include "ethercatdc.h" +#include "ethercat.h" #define NSEC_PER_SEC 1000000000 diff --git a/test/win32/simple_test/simple_test.c b/test/win32/simple_test/simple_test.c index 39f5060..b23e474 100644 --- a/test/win32/simple_test/simple_test.c +++ b/test/win32/simple_test/simple_test.c @@ -14,15 +14,7 @@ //#include #include "osal.h" -#include "ethercattype.h" -#include "nicdrv.h" -#include "ethercatbase.h" -#include "ethercatmain.h" -#include "ethercatdc.h" -#include "ethercatcoe.h" -#include "ethercatfoe.h" -#include "ethercatconfig.h" -#include "ethercatprint.h" +#include "ethercat.h" #define EC_TIMEOUTMON 500 diff --git a/test/win32/slaveinfo/slaveinfo.c b/test/win32/slaveinfo/slaveinfo.c index cf3b6d3..562f643 100644 --- a/test/win32/slaveinfo/slaveinfo.c +++ b/test/win32/slaveinfo/slaveinfo.c @@ -15,14 +15,7 @@ #include #include -#include "ethercattype.h" -#include "nicdrv.h" -#include "ethercatbase.h" -#include "ethercatmain.h" -#include "ethercatconfig.h" -#include "ethercatcoe.h" -#include "ethercatdc.h" -#include "ethercatprint.h" +#include "ethercat.h" char IOmap[4096]; ec_ODlistt ODlist; From 593a81a177a007779ec7978473d3778abe93b57a Mon Sep 17 00:00:00 2001 From: Shahbaz Youssefi Date: Fri, 18 Dec 2015 13:15:24 -0500 Subject: [PATCH 3/4] Build simple_test, but don't install Signed-off-by: Shahbaz Youssefi --- CMakeLists.txt | 4 +--- test/linux/simple_test/CMakeLists.txt | 4 +++- test/linux/simple_test/simple_test.c | 3 ++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b10cf3c..e81e59d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,6 +67,4 @@ install(FILES ${SOEM_HEADERS} ${OSAL_HEADERS} ${OSHW_HEADERS} DESTINATION ${SOEM add_subdirectory(test/linux/slaveinfo) add_subdirectory(test/linux/eepromtool) -if(NOT DEFINED HOST_INSTALL) - add_subdirectory(test/linux/simple_test) -endif() +add_subdirectory(test/linux/simple_test) diff --git a/test/linux/simple_test/CMakeLists.txt b/test/linux/simple_test/CMakeLists.txt index 1541576..344e1f5 100644 --- a/test/linux/simple_test/CMakeLists.txt +++ b/test/linux/simple_test/CMakeLists.txt @@ -9,4 +9,6 @@ elseif(UNIX) target_link_libraries(simple_test pthread rt) endif() -install(TARGETS simple_test DESTINATION bin) +if(NOT DEFINED HOST_INSTALL) + install(TARGETS simple_test DESTINATION bin) +endif() diff --git a/test/linux/simple_test/simple_test.c b/test/linux/simple_test/simple_test.c index 1ef7773..48216a4 100644 --- a/test/linux/simple_test/simple_test.c +++ b/test/linux/simple_test/simple_test.c @@ -11,6 +11,7 @@ #include #include +#include #include "ethercat.h" @@ -102,7 +103,7 @@ void simpletest(char *ifname) { printf(" %2.2x", *(ec_slave[0].inputs + j)); } - printf(" T:%lld\r",ec_DCtime); + printf(" T:%"PRId64"\r",ec_DCtime); needlf = TRUE; } osal_usleep(5000); From 469dd9623a293a683a8faaf5ffaba6837b920955 Mon Sep 17 00:00:00 2001 From: Shahbaz Youssefi Date: Mon, 21 Dec 2015 10:56:49 -0500 Subject: [PATCH 4/4] Be able to take string literal as ifname `ifname` as the argument of `ec_init` and related functions is not changed, and therefore can be safely retyped to `const char *`. This allows using string literals. For example: ec_init(argc > 1 ? argv[1] : "eth0"); Signed-off-by: Shahbaz Youssefi --- soem/ethercatmain.c | 8 ++++---- soem/ethercatmain.h | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/soem/ethercatmain.c b/soem/ethercatmain.c index 3e8bde0..e8314dd 100644 --- a/soem/ethercatmain.c +++ b/soem/ethercatmain.c @@ -321,7 +321,7 @@ static void ecx_mbxemergencyerror(ecx_contextt *context, uint16 Slave,uint16 Err * @param[in] ifname = Dev name, f.e. "eth0" * @return >0 if OK */ -int ecx_init(ecx_contextt *context, char * ifname) +int ecx_init(ecx_contextt *context, const char * ifname) { return ecx_setupnic(context->port, ifname, FALSE); } @@ -333,7 +333,7 @@ int ecx_init(ecx_contextt *context, char * ifname) * @param[in] if2name = Secondary Dev name, f.e. "eth1" * @return >0 if OK */ -int ecx_init_redundant(ecx_contextt *context, ecx_redportt *redport, char *ifname, char *if2name) +int ecx_init_redundant(ecx_contextt *context, ecx_redportt *redport, const char *ifname, char *if2name) { int rval, zbuf; ec_etherheadert *ehp; @@ -1905,7 +1905,7 @@ void ec_packeterror(uint16 Slave, uint16 Index, uint8 SubIdx, uint16 ErrorCode) * @return >0 if OK * @see ecx_init */ -int ec_init(char * ifname) +int ec_init(const char * ifname) { return ecx_init(&ecx_context, ifname); } @@ -1916,7 +1916,7 @@ int ec_init(char * ifname) * @return >0 if OK * @see ecx_init_redundant */ -int ec_init_redundant(char *ifname, char *if2name) +int ec_init_redundant(const char *ifname, char *if2name) { return ecx_init_redundant (&ecx_context, &ecx_redport, ifname, if2name); } diff --git a/soem/ethercatmain.h b/soem/ethercatmain.h index ea0b776..766bc60 100644 --- a/soem/ethercatmain.h +++ b/soem/ethercatmain.h @@ -473,8 +473,8 @@ void ec_pusherror(const ec_errort *Ec); boolean ec_poperror(ec_errort *Ec); boolean ec_iserror(void); void ec_packeterror(uint16 Slave, uint16 Index, uint8 SubIdx, uint16 ErrorCode); -int ec_init(char * ifname); -int ec_init_redundant(char *ifname, char *if2name); +int ec_init(const char * ifname); +int ec_init_redundant(const char *ifname, char *if2name); void ec_close(void); uint8 ec_siigetbyte(uint16 slave, uint16 address); int16 ec_siifind(uint16 slave, uint16 cat); @@ -514,8 +514,8 @@ void ecx_pusherror(ecx_contextt *context, const ec_errort *Ec); boolean ecx_poperror(ecx_contextt *context, ec_errort *Ec); boolean ecx_iserror(ecx_contextt *context); void ecx_packeterror(ecx_contextt *context, uint16 Slave, uint16 Index, uint8 SubIdx, uint16 ErrorCode); -int ecx_init(ecx_contextt *context, char * ifname); -int ecx_init_redundant(ecx_contextt *context, ecx_redportt *redport, char *ifname, char *if2name); +int ecx_init(ecx_contextt *context, const char * ifname); +int ecx_init_redundant(ecx_contextt *context, ecx_redportt *redport, const char *ifname, char *if2name); void ecx_close(ecx_contextt *context); uint8 ecx_siigetbyte(ecx_contextt *context, uint16 slave, uint16 address); int16 ecx_siifind(ecx_contextt *context, uint16 slave, uint16 cat);