From 595470823424fcb4ed653a10880e49109f4cefbf Mon Sep 17 00:00:00 2001 From: marcfir Date: Tue, 12 Mar 2024 13:57:22 +0100 Subject: [PATCH 1/4] fix(build_so): Make anon_cb an explicit function in dc.c --- src/dc.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/dc.c b/src/dc.c index 344f911..0e6aa8b 100644 --- a/src/dc.c +++ b/src/dc.c @@ -58,6 +58,12 @@ #define ONE_SEC ((osal_uint64_t)1000000000u) +static void anon_cb(struct ec *cb_pec, pool_entry_t *cb_p_entry, ec_datagram_t *cb_p_dg) { + (void)cb_pec; + (void)cb_p_dg; + osal_binary_semaphore_post(&cb_p_entry->p_idx->waiter); +}; + // mesaure packet duration (important in case of master_as_ref_clock !) static inline osal_uint64_t get_packet_duration(ec_t *pec) { assert(pec != NULL); @@ -86,12 +92,7 @@ static inline osal_uint64_t get_packet_duration(ec_t *pec) { p_dg->irq = 0; p_entry->p_idx = p_idx; - p_entry->user_cb = ({ - void anon_cb(struct ec *cb_pec, pool_entry_t *cb_p_entry, ec_datagram_t *cb_p_dg) { - (void)cb_pec; - (void)cb_p_dg; - osal_binary_semaphore_post(&cb_p_entry->p_idx->waiter); - } &anon_cb; }); + p_entry->user_cb = anon_cb; // queue frame and trigger tx pool_put(&pec->hw.tx_high, p_entry); From 6a5dee21d22391b45887c78295508ca86e2bdd69 Mon Sep 17 00:00:00 2001 From: marcfir Date: Tue, 23 Jul 2024 15:02:13 +0000 Subject: [PATCH 2/4] feat(cmake): Allow multiple devices to be build --- CMakeLists.txt | 37 ++++++++++++++++++++++++++----------- README.md | 3 ++- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2fc83ca..21c40a2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ string(REGEX MATCH "VERSION = ([0-9]*.[0-9]*.[0-9]*)" _ ${PROJECT_PROPERTIES}) set(PROJECT_VERSION ${CMAKE_MATCH_1}) project(libethercat VERSION ${PROJECT_VERSION}) -set(ECAT_DEVICE "sock_raw" CACHE STRING "EtherCAT device layer") +set(ECAT_DEVICE "sock_raw" CACHE STRING "EtherCAT device layer as `;` separated list") include(CheckIncludeFiles) include(CheckSymbolExists) @@ -85,20 +85,35 @@ set(SRC_ETHERCAT src/slave.c src/soe.c) -if (${ECAT_DEVICE} STREQUAL "sock_raw") - set(SRC_HW_LAYER src/hw_sock_raw.c) +list(FIND ECAT_DEVICE "sock_raw" HAS_SOCK_RAW) +list(FIND ECAT_DEVICE "sock_raw_mmaped" HAS_SOCK_RAW_MMAPED) +list(FIND ECAT_DEVICE "file" HAS_SOCK_FILE) +list(FIND ECAT_DEVICE "pikeos" HAS_SOCK_PIKEOS) +list(FIND ECAT_DEVICE "bpf" HAS_SOCK_BPF) + +if (${HAS_SOCK_RAW} GREATER -1) + message("Include device sock_raw") + list(APPEND SRC_HW_LAYER src/hw_sock_raw.c) add_compile_definitions(LIBETHERCAT_BUILD_DEVICE_SOCK_RAW_LEGACY) -elseif (${ECAT_DEVICE} STREQUAL "sock_raw_mmaped") - set(SRC_HW_LAYER src/hw_file.c) +endif() +if (${HAS_SOCK_RAW_MMAPED} GREATER -1) + message("Include device sock_raw_mmaped") + list(APPEND SRC_HW_LAYER src/hw_sock_raw_mmaped.c) add_compile_definitions(LIBETHERCAT_BUILD_DEVICE_SOCK_RAW_MMAPED) -elseif (${ECAT_DEVICE} STREQUAL "file") - set(SRC_HW_LAYER src/hw_file.c) +endif() +if (${HAS_SOCK_FILE} GREATER -1) + message("Include device file") + list(APPEND SRC_HW_LAYER src/hw_file.c) add_compile_definitions(LIBETHERCAT_BUILD_DEVICE_FILE) -elseif (${ECAT_DEVICE} STREQUAL "pikeos") - set(SRC_HW_LAYER src/hw_pikeos.c) +endif() +if (${HAS_SOCK_PIKEOS} GREATER -1) + message("Include device pikeos") + list(APPEND SRC_HW_LAYER src/hw_pikeos.c) add_compile_definitions(LIBETHERCAT_BUILD_DEVICE_PIKEOS) -elseif (${ECAT_DEVICE} STREQUAL "bpf") - set(SRC_HW_LAYER src/hw_bpf.c) +endif() +if (${HAS_SOCK_BPF} GREATER -1) + message("Include device bpf") + list(APPEND SRC_HW_LAYER src/hw_bpf.c) add_compile_definitions(LIBETHERCAT_BUILD_DEVICE_BPD) endif() diff --git a/README.md b/README.md index 5cb68e7..855e63e 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,8 @@ This will build and install a static as well as a dynamic library. For use in ot mkdir build cd build # Please change the path to the install dir. If you chose a global install you can omit the CMAKE_PREFIX_PATH option -cmake .. -DCMAKE_PREFIX_PATH= +# You can specify which EtherCAT devices should be included into the build with -DECAT_DEVICE="sock_raw;sock_raw_mmaped;..." +cmake .. -DCMAKE_PREFIX_PATH= -DECAT_DEVICE="sock_raw;sock_raw_mmaped" cmake --build . ``` From f996924f4e9ccb308adc9948d5eac83fc63e2c67 Mon Sep 17 00:00:00 2001 From: marcfir Date: Tue, 23 Jul 2024 15:02:17 +0000 Subject: [PATCH 3/4] feat(cmake): Add HAVE_NETINET_IN_H --- CMakeLists.txt | 1 + cmake/cmake_config.h.in | 3 +++ 2 files changed, 4 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 21c40a2..fa35922 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,6 +39,7 @@ check_include_files("memory.h" LIBETHERCAT_HAVE_MEMORY_H) check_symbol_exists("memset" "string.h" LIBETHERCAT_HAVE_MALLOC) check_include_files("net/bpf.h" LIBETHERCAT_HAVE_NET_BPF_H) check_include_files("net/if.h" LIBETHERCAT_HAVE_NET_IF_H) +check_include_files("netinet/in.h" LIBETHERCAT_HAVE_NETINET_IN_H) check_include_files("pthread.h" LIBETHERCAT_HAVE_PTHREAD) list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE) check_symbol_exists("pthread_setaffinity_np" "pthread.h" LIBETHERCAT_HAVE_PTHREAD_SETAFFINITY_NP) diff --git a/cmake/cmake_config.h.in b/cmake/cmake_config.h.in index b0185ae..6421a51 100644 --- a/cmake/cmake_config.h.in +++ b/cmake/cmake_config.h.in @@ -38,6 +38,9 @@ /* Define to 1 if you have the header file. */ #cmakedefine LIBETHERCAT_HAVE_NET_IF_H ${LIBETHERCAT_HAVE_NET_IF_H} +/* Define to 1 if you have the header file. */ +#cmakedefine LIBETHERCAT_HAVE_NETINET_IN_H ${LIBETHERCAT_HAVE_NETINET_IN_H} + /* Define if you have POSIX threads libraries and header files. */ #cmakedefine LIBETHERCAT_HAVE_PTHREAD ${LIBETHERCAT_HAVE_PTHREAD} From 5b16b80e8994ff0f388a5e0ffa6ac435febfa0a9 Mon Sep 17 00:00:00 2001 From: marcfir Date: Tue, 23 Jul 2024 15:02:17 +0000 Subject: [PATCH 4/4] fix(hw): Restructure hw_open --- src/hw.c | 51 ++++++++++++++++++++++++--------------------------- 1 file changed, 24 insertions(+), 27 deletions(-) diff --git a/src/hw.c b/src/hw.c index aa5200f..d6c753d 100644 --- a/src/hw.c +++ b/src/hw.c @@ -123,44 +123,41 @@ int hw_open(hw_t *phw, struct ec *pec, const osal_char_t *devname, int prio, int ec_log(10, "HW_OPEN", "Opening interface as device file: %s\n", ifname); ret = hw_device_file_open(phw, ifname); - } else + } #endif - { #if LIBETHERCAT_BUILD_DEVICE_BPF == 1 - if (strncmp(ifname, "bpf:", 4) == 0) { - ifname = &ifname[4]; + if (strncmp(ifname, "bpf:", 4) == 0) { + ifname = &ifname[4]; - ec_log(10, "HW_OPEN", "Opening interface as BPF: %s\n", ifname); - ret = hw_device_bpf_open(phw, ifname); - } else + ec_log(10, "HW_OPEN", "Opening interface as BPF: %s\n", ifname); + ret = hw_device_bpf_open(phw, ifname); + } #endif #if LIBETHERCAT_BUILD_DEVICE_PIKEOS == 1 - if (strncmp(ifname, "pikeos:", 4) == 0) { - ifname = &ifname[7]; + if (strncmp(ifname, "pikeos:", 4) == 0) { + ifname = &ifname[4]; - ec_log(10, "HW_OPEN", "Opening interface as pikeos: %s\n", ifname); - ret = hw_device_pikeos_open(phw, ifname); - } else + ec_log(10, "HW_OPEN", "Opening interface as pikeos: %s\n", ifname); + ret = hw_device_pikeos_open(phw, ifname); + } +#endif +#if LIBETHERCAT_BUILD_DEVICE_SOCK_RAW_LEGACY == 1 + if (strncmp(ifname, "sock-raw:", 9) == 0) { + ifname = &ifname[9]; + + ec_log(10, "HW_OPEN", "Opening interface as SOCK_RAW: %s\n", ifname); + ret = hw_device_sock_raw_open(phw, ifname); + } #endif #if LIBETHERCAT_BUILD_DEVICE_SOCK_RAW_MMAPED == 1 - if (strncmp(ifname, "sock-raw-mmaped:", 16) == 0) { - ifname = &ifname[16]; + if (strncmp(ifname, "sock-raw-mmaped:", 16) == 0) { + ifname = &ifname[16]; - ec_log(10, "HW_OPEN", "Opening interface as mmaped SOCK_RAW: %s\n", ifname); - ret = hw_device_sock_raw_mmaped_open(phw, ifname); - } else + ec_log(10, "HW_OPEN", "Opening interface as mmaped SOCK_RAW: %s\n", ifname); + ret = hw_device_sock_raw_mmaped_open(phw, ifname); + } #endif - { -#if LIBETHERCAT_BUILD_DEVICE_SOCK_RAW_LEGACY == 1 - if (strncmp(ifname, "sock-raw:", 9) == 0) { - ifname = &ifname[9]; - } - ec_log(10, "HW_OPEN", "Opening interface as SOCK_RAW: %s\n", ifname); - ret = hw_device_sock_raw_open(phw, ifname); -#endif - } - } if (ret == EC_OK) { phw->rxthreadrunning = 1;