├── .gitignore ├── oshw ├── win32 │ ├── wpcap │ │ ├── Lib │ │ │ ├── Packet.lib │ │ │ ├── libwpcap.a │ │ │ ├── wpcap.lib │ │ │ ├── libpacket.a │ │ │ └── x64 │ │ │ │ ├── wpcap.lib │ │ │ │ └── Packet.lib │ │ └── Include │ │ │ ├── pcap │ │ │ ├── bluetooth.h │ │ │ ├── vlan.h │ │ │ ├── usb.h │ │ │ ├── namedb.h │ │ │ └── sll.h │ │ │ ├── pcap-namedb.h │ │ │ ├── pcap.h │ │ │ ├── pcap-bpf.h │ │ │ ├── pcap-stdinc.h │ │ │ ├── Win32-Extensions.h │ │ │ ├── bittypes.h │ │ │ └── ip6_misc.h │ ├── oshw.h │ ├── nicdrv.h │ └── oshw.c ├── linux │ ├── oshw.h │ ├── nicdrv.h │ └── oshw.c └── rtk │ ├── oshw.h │ ├── oshw.c │ └── nicdrv.h ├── samples ├── eoe_test │ └── CMakeLists.txt ├── ec_sample │ └── CMakeLists.txt ├── simple_ng │ └── CMakeLists.txt ├── slaveinfo │ └── CMakeLists.txt ├── eepromtool │ └── CMakeLists.txt ├── firm_update │ ├── CMakeLists.txt │ └── firm_update.c └── eni_test │ ├── CMakeLists.txt │ ├── sample-eni.xml │ └── eni_test.c ├── contrib ├── osal │ ├── erika │ │ ├── README.md │ │ ├── osal_defs.h │ │ └── osal.c │ ├── vxworks │ │ ├── osal_defs.h │ │ └── osal.c │ ├── macosx │ │ ├── osal_defs.h │ │ └── osal.c │ ├── rtems │ │ ├── osal_defs.h │ │ └── osal.c │ └── intime │ │ ├── osal_defs.h │ │ └── osal.c ├── oshw │ ├── vxworks │ │ ├── oshw.h │ │ ├── oshw.c │ │ └── nicdrv.h │ ├── erika │ │ ├── oshw.h │ │ ├── oshw.c │ │ └── nicdrv.h │ ├── intime │ │ ├── oshw.h │ │ ├── oshw.c │ │ └── nicdrv.h │ ├── macosx │ │ ├── oshw.h │ │ ├── nicdrv.h │ │ └── oshw.c │ └── rtems │ │ ├── oshw.h │ │ ├── nicdrv.h │ │ └── oshw.c └── cmake │ ├── Modules │ └── Platform │ │ └── rtems.cmake │ └── rtems.cmake ├── cmake ├── tools │ └── FindSphinx.cmake ├── Linux.cmake ├── AddENI.cmake ├── rt-kernel.cmake └── Windows.cmake ├── .gitattributes ├── .docker ├── linux-arm64.Dockerfile └── windows-x64.Dockerfile ├── .git-blame-ignore-revs ├── .clang-format ├── include └── soem │ ├── soem.h │ ├── ec_dc.h │ ├── ec_foe.h │ ├── ec_print.h │ ├── ec_config.h │ ├── ec_base.h │ ├── ec_coe.h │ ├── ec_soe.h │ ├── ec_options.h.in │ └── ec_eoe.h ├── LICENSE.md ├── CMakePresets.json ├── osal ├── rtk │ ├── osal_defs.h │ └── osal.c ├── linux │ ├── osal_defs.h │ └── osal.c ├── win32 │ ├── osal_defs.h │ └── osal.c └── osal.h ├── README.md ├── .jenkins ├── CMakeLists.txt └── scripts └── eniconv.py /.gitignore: -------------------------------------------------------------------------------- 1 | build*/ 2 | install 3 | *~ 4 | /doc/latex 5 | /doc/html 6 | tags 7 | .vscode 8 | -------------------------------------------------------------------------------- /oshw/win32/wpcap/Lib/Packet.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenEtherCATsociety/SOEM/HEAD/oshw/win32/wpcap/Lib/Packet.lib -------------------------------------------------------------------------------- /oshw/win32/wpcap/Lib/libwpcap.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenEtherCATsociety/SOEM/HEAD/oshw/win32/wpcap/Lib/libwpcap.a -------------------------------------------------------------------------------- /oshw/win32/wpcap/Lib/wpcap.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenEtherCATsociety/SOEM/HEAD/oshw/win32/wpcap/Lib/wpcap.lib -------------------------------------------------------------------------------- /oshw/win32/wpcap/Lib/libpacket.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenEtherCATsociety/SOEM/HEAD/oshw/win32/wpcap/Lib/libpacket.a -------------------------------------------------------------------------------- /oshw/win32/wpcap/Lib/x64/wpcap.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenEtherCATsociety/SOEM/HEAD/oshw/win32/wpcap/Lib/x64/wpcap.lib -------------------------------------------------------------------------------- /oshw/win32/wpcap/Lib/x64/Packet.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenEtherCATsociety/SOEM/HEAD/oshw/win32/wpcap/Lib/x64/Packet.lib -------------------------------------------------------------------------------- /samples/eoe_test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(eoe_test eoe_test.c) 2 | target_link_libraries(eoe_test soem) 3 | install(TARGETS eoe_test DESTINATION bin) 4 | -------------------------------------------------------------------------------- /samples/ec_sample/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(ec_sample ec_sample.c) 2 | target_link_libraries(ec_sample soem) 3 | install(TARGETS ec_sample DESTINATION bin) 4 | -------------------------------------------------------------------------------- /samples/simple_ng/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(simple_ng simple_ng.c) 2 | target_link_libraries(simple_ng soem) 3 | install(TARGETS simple_ng DESTINATION bin) 4 | -------------------------------------------------------------------------------- /samples/slaveinfo/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(slaveinfo slaveinfo.c) 2 | target_link_libraries(slaveinfo soem) 3 | install(TARGETS slaveinfo DESTINATION bin) 4 | -------------------------------------------------------------------------------- /samples/eepromtool/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(eepromtool eepromtool.c) 2 | target_link_libraries(eepromtool soem) 3 | install(TARGETS eepromtool DESTINATION bin) 4 | -------------------------------------------------------------------------------- /contrib/osal/erika/README.md: -------------------------------------------------------------------------------- 1 | ERIKA Enterprise RTOS 2 | --------------------- 3 | 4 | * Refer to http://www.erika-enterprise.com/wiki/index.php?title=EtherCAT_Master 5 | -------------------------------------------------------------------------------- /samples/firm_update/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(firm_update firm_update.c) 2 | target_link_libraries(firm_update soem) 3 | install(TARGETS firm_update DESTINATION bin) 4 | -------------------------------------------------------------------------------- /samples/eni_test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include(AddENI) 2 | 3 | add_executable(eni_test eni_test.c) 4 | add_eni(eni_test 5 | sample-eni.xml 6 | ) 7 | target_link_libraries(eni_test soem) 8 | install(TARGETS eni_test DESTINATION bin) 9 | -------------------------------------------------------------------------------- /cmake/tools/FindSphinx.cmake: -------------------------------------------------------------------------------- 1 | 2 | # Look for an executable called sphinx-build 3 | find_program( 4 | SPHINX_EXECUTABLE 5 | NAMES sphinx-build 6 | DOC "Path to sphinx-build executable" 7 | ) 8 | 9 | include(FindPackageHandleStandardArgs) 10 | 11 | # Handle standard arguments to find_package like REQUIRED and QUIET 12 | find_package_handle_standard_args( 13 | Sphinx 14 | "Failed to find sphinx-build executable" 15 | SPHINX_EXECUTABLE 16 | ) 17 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Set the default behavior, in case people don't have core.autocrlf set. 2 | * text=auto 3 | 4 | # Explicitly declare text files you want to always be normalized and converted 5 | # to native line endings on checkout. 6 | *.c text 7 | *.cpp text 8 | *.h text 9 | *.S text 10 | *.txt text 11 | *.md text 12 | 13 | # Declare files that will always have LF line endings on checkout. 14 | *.sh text eol=lf 15 | 16 | # Denote all files that are truly binary and should not be modified. 17 | *.lib binary 18 | -------------------------------------------------------------------------------- /.docker/linux-arm64.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM dockcross/linux-arm64-lts 2 | ENV DEFAULT_DOCKCROSS_IMAGE=soem-linux-arm64 3 | 4 | # Preinstall uv in our image 5 | COPY --from=ghcr.io/astral-sh/uv:0.5.9 /uv /uvx /usr/local/bin/ 6 | ENV UV_LINK_MODE=copy 7 | 8 | # Prepare dockcross from use in jenkins 9 | ARG BUILDER_UID=1001 10 | ARG BUILDER_GID=1001 11 | ARG BUILDER_USER=rtljenkins 12 | ARG BUILDER_GROUP=rtljenkins 13 | RUN BUILDER_UID=${BUILDER_GID} BUILDER_GID=${BUILDER_GID} BUILDER_USER=${BUILDER_USER} BUILDER_GROUP=${BUILDER_GROUP} /dockcross/entrypoint.sh echo "Setup jenkins user" 14 | -------------------------------------------------------------------------------- /.docker/windows-x64.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM dockcross/windows-static-x64 2 | ENV DEFAULT_DOCKCROSS_IMAGE=soem-windows-x64 3 | 4 | # Preinstall uv in our image 5 | COPY --from=ghcr.io/astral-sh/uv:0.5.9 /uv /uvx /usr/local/bin/ 6 | ENV UV_LINK_MODE=copy 7 | 8 | # Prepare dockcross from use in jenkins 9 | ARG BUILDER_UID=1001 10 | ARG BUILDER_GID=1001 11 | ARG BUILDER_USER=rtljenkins 12 | ARG BUILDER_GROUP=rtljenkins 13 | RUN BUILDER_UID=${BUILDER_GID} BUILDER_GID=${BUILDER_GID} BUILDER_USER=${BUILDER_USER} BUILDER_GROUP=${BUILDER_GROUP} /dockcross/entrypoint.sh echo "Setup jenkins user" 14 | -------------------------------------------------------------------------------- /contrib/oshw/vxworks/oshw.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is dual-licensed under GPLv3 and a commercial 3 | * license. See the file LICENSE.md distributed with this software for 4 | * full license information. 5 | */ 6 | 7 | /** \file 8 | * \brief 9 | * Headerfile for oshw.c 10 | */ 11 | 12 | #ifndef _oshw_ 13 | #define _oshw_ 14 | 15 | #include "soem/soem.h" 16 | #include "nicdrv.h" 17 | 18 | uint16 oshw_htons(uint16 hostshort); 19 | uint16 oshw_ntohs(uint16 networkshort); 20 | ec_adaptert *oshw_find_adapters(void); 21 | void oshw_free_adapters(ec_adaptert *adapter); 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /.git-blame-ignore-revs: -------------------------------------------------------------------------------- 1 | # This file contains a list of commits that are not likely what you 2 | # are looking for in a blame, such as mass reformatting or renaming. 3 | # You can set this file as a default ignore file for blame by running 4 | # the following command. 5 | # 6 | # $ git config blame.ignoreRevsFile .git-blame-ignore-revs 7 | 8 | # Run clang-format on sources 9 | 0ae3d2f056a0642712c86f7fb29c7d9c99176620 10 | 11 | # Refactor repository layout (step 2 of 2) 12 | 9582886c2cef3bf46f0e6db09e6246c84da60973 13 | 14 | # Refactor repository layout (step 1 of 2) 15 | 78b757b2bfd30543f0728b74907960372419b29d 16 | -------------------------------------------------------------------------------- /oshw/linux/oshw.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is dual-licensed under GPLv3 and a commercial 3 | * license. See the file LICENSE.md distributed with this software for 4 | * full license information. 5 | */ 6 | 7 | /** \file 8 | * \brief 9 | * Headerfile for ethercatbase.c 10 | */ 11 | 12 | #ifndef _oshw_ 13 | #define _oshw_ 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | #include "soem/soem.h" 20 | #include "nicdrv.h" 21 | 22 | uint16 oshw_htons(uint16 hostshort); 23 | uint16 oshw_ntohs(uint16 networkshort); 24 | ec_adaptert *oshw_find_adapters(void); 25 | void oshw_free_adapters(ec_adaptert *adapter); 26 | 27 | #ifdef __cplusplus 28 | } 29 | #endif 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /oshw/win32/oshw.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is dual-licensed under GPLv3 and a commercial 3 | * license. See the file LICENSE.md distributed with this software for 4 | * full license information. 5 | */ 6 | 7 | /** \file 8 | * \brief 9 | * Headerfile for ethercatbase.c 10 | */ 11 | 12 | #ifndef _oshw_ 13 | #define _oshw_ 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | #include "soem/soem.h" 20 | #include "nicdrv.h" 21 | 22 | uint16 oshw_htons(uint16 hostshort); 23 | uint16 oshw_ntohs(uint16 networkshort); 24 | ec_adaptert *oshw_find_adapters(void); 25 | void oshw_free_adapters(ec_adaptert *adapter); 26 | 27 | #ifdef __cplusplus 28 | } 29 | #endif 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /contrib/oshw/erika/oshw.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is dual-licensed under GPLv3 and a commercial 3 | * license. See the file LICENSE.md distributed with this software for 4 | * full license information. 5 | */ 6 | 7 | /** \file 8 | * \brief 9 | * Headerfile for ethercatbase.c 10 | */ 11 | 12 | #ifndef _oshw_ 13 | #define _oshw_ 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | #include "soem/soem.h" 20 | #include "nicdrv.h" 21 | 22 | uint16 oshw_htons(uint16 hostshort); 23 | uint16 oshw_ntohs(uint16 networkshort); 24 | ec_adaptert *oshw_find_adapters(void); 25 | void oshw_free_adapters(ec_adaptert *adapter); 26 | 27 | #ifdef __cplusplus 28 | } 29 | #endif 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /contrib/oshw/intime/oshw.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is dual-licensed under GPLv3 and a commercial 3 | * license. See the file LICENSE.md distributed with this software for 4 | * full license information. 5 | */ 6 | 7 | /** \file 8 | * \brief 9 | * Headerfile for oshw.c 10 | */ 11 | 12 | #ifndef _oshw_ 13 | #define _oshw_ 14 | 15 | #include "soem/soem.h" 16 | #include "ethercatmain.h" 17 | 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | uint16 oshw_htons(uint16 hostshort); 23 | uint16 oshw_ntohs(uint16 networkshort); 24 | ec_adaptert *oshw_find_adapters(void); 25 | void oshw_free_adapters(ec_adaptert *adapter); 26 | 27 | #ifdef __cplusplus 28 | } 29 | #endif 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /contrib/oshw/macosx/oshw.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is dual-licensed under GPLv3 and a commercial 3 | * license. See the file LICENSE.md distributed with this software for 4 | * full license information. 5 | */ 6 | 7 | /** \file 8 | * \brief 9 | * Headerfile for ethercatbase.c 10 | */ 11 | 12 | #ifndef _oshw_ 13 | #define _oshw_ 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | #include "soem/soem.h" 20 | #include "nicdrv.h" 21 | 22 | uint16 oshw_htons(uint16 hostshort); 23 | uint16 oshw_ntohs(uint16 networkshort); 24 | ec_adaptert *oshw_find_adapters(void); 25 | void oshw_free_adapters(ec_adaptert *adapter); 26 | 27 | #ifdef __cplusplus 28 | } 29 | #endif 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /contrib/oshw/rtems/oshw.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is dual-licensed under GPLv3 and a commercial 3 | * license. See the file LICENSE.md distributed with this software for 4 | * full license information. 5 | */ 6 | 7 | /** \file 8 | * \brief 9 | * Headerfile for ethercatbase.c 10 | */ 11 | 12 | #ifndef _oshw_ 13 | #define _oshw_ 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | #include "soem/soem.h" 20 | #include "nicdrv.h" 21 | 22 | uint16 oshw_htons(uint16 hostshort); 23 | uint16 oshw_ntohs(uint16 networkshort); 24 | ec_adaptert *oshw_find_adapters(void); 25 | void oshw_free_adapters(ec_adaptert *adapter); 26 | 27 | #ifdef __cplusplus 28 | } 29 | #endif 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | Language: Cpp 3 | AllowShortIfStatementsOnASingleLine: WithoutElse 4 | AlignConsecutiveMacros: AcrossEmptyLinesAndComments 5 | SortIncludes: false 6 | IndentWidth: 3 7 | UseTab: Never 8 | PointerAlignment: Right 9 | ColumnLimit: 0 10 | BreakBeforeBraces: Custom 11 | BraceWrapping: 12 | AfterCaseLabel: true 13 | AfterClass: true 14 | AfterControlStatement: true 15 | AfterEnum: true 16 | AfterFunction: true 17 | AfterNamespace: true 18 | AfterStruct: true 19 | AfterUnion: true 20 | BeforeCatch: true 21 | BeforeElse: true 22 | IndentBraces: false 23 | SplitEmptyFunction: true 24 | SplitEmptyRecord: true 25 | SplitEmptyNamespace: false 26 | AfterExternBlock: false 27 | -------------------------------------------------------------------------------- /contrib/cmake/Modules/Platform/rtems.cmake: -------------------------------------------------------------------------------- 1 | message("rtems.cmake") 2 | 3 | set(ARCH ${HOST}) 4 | set(BSP ${RTEMS_BSP}) 5 | 6 | set(CMAKE_C_COMPILER_FORCED true) 7 | set(CMAKE_CXX_COMPILER_FORCED true) 8 | set(CMAKE_C_COMPILER ${RTEMS_TOOLS_PATH}/bin/${ARCH}-gcc) 9 | set(CMAKE_CXX_COMPILER ${RTEMS_TOOLS_PATH}/bin/${ARCH}-g++) 10 | 11 | set(SOEM_INCLUDE_INSTALL_DIR ${INCLUDE_DIR}/soem) 12 | set(SOEM_LIB_INSTALL_DIR ${LIB_DIR}) 13 | 14 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${HOST_C_FLAGS}") 15 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${HOST_CXX_FLAGS}") 16 | 17 | if(NOT ${HOST_LIBS} STREQUAL "") 18 | set(OS_LIBS "rtemscpu bsd ${HOST_LIBS}") 19 | else() 20 | set(OS_LIBS "-lrtemscpu -lbsd") 21 | endif() 22 | 23 | -------------------------------------------------------------------------------- /include/soem/soem.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is dual-licensed under GPLv3 and a commercial 3 | * license. See the file LICENSE.md distributed with this software for 4 | * full license information. 5 | */ 6 | 7 | /** \file 8 | * \brief 9 | * SOEM main include file 10 | */ 11 | 12 | #ifndef _SOEM_H 13 | #define _SOEM_H 14 | 15 | #include "soem/ec_options.h" 16 | #include "soem/ec_type.h" 17 | #include "nicdrv.h" 18 | #include "soem/ec_base.h" 19 | #include "soem/ec_main.h" 20 | #include "soem/ec_dc.h" 21 | #include "soem/ec_coe.h" 22 | #include "soem/ec_foe.h" 23 | #include "soem/ec_soe.h" 24 | #include "soem/ec_eoe.h" 25 | #include "soem/ec_config.h" 26 | #include "soem/ec_print.h" 27 | 28 | #endif /* _SOEM_H */ 29 | -------------------------------------------------------------------------------- /include/soem/ec_dc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is dual-licensed under GPLv3 and a commercial 3 | * license. See the file LICENSE.md distributed with this software for 4 | * full license information. 5 | */ 6 | 7 | /** \file 8 | * \brief 9 | * Headerfile for ec_dc.c 10 | */ 11 | 12 | #ifndef _EC_ECATDC_H 13 | #define _EC_ECATDC_H 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | boolean ecx_configdc(ecx_contextt *context); 20 | void ecx_dcsync0(ecx_contextt *context, uint16 slave, boolean act, uint32 CyclTime, int32 CyclShift); 21 | void ecx_dcsync01(ecx_contextt *context, uint16 slave, boolean act, uint32 CyclTime0, uint32 CyclTime1, int32 CyclShift); 22 | 23 | #ifdef __cplusplus 24 | } 25 | #endif 26 | 27 | #endif /* _EC_ECATDC_H */ 28 | -------------------------------------------------------------------------------- /include/soem/ec_foe.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is dual-licensed under GPLv3 and a commercial 3 | * license. See the file LICENSE.md distributed with this software for 4 | * full license information. 5 | */ 6 | 7 | /** \file 8 | * \brief 9 | * Headerfile for ec_foe.c 10 | */ 11 | 12 | #ifndef _ec_foe_ 13 | #define _ec_foe_ 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | int ecx_FOEdefinehook(ecx_contextt *context, void *hook); 20 | int ecx_FOEread(ecx_contextt *context, uint16 slave, char *filename, uint32 password, int *psize, void *p, int timeout); 21 | int ecx_FOEwrite(ecx_contextt *context, uint16 slave, char *filename, uint32 password, int psize, void *p, int timeout); 22 | 23 | #ifdef __cplusplus 24 | } 25 | #endif 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /include/soem/ec_print.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is dual-licensed under GPLv3 and a commercial 3 | * license. See the file LICENSE.md distributed with this software for 4 | * full license information. 5 | */ 6 | 7 | /** \file 8 | * \brief 9 | * Headerfile for ec_print.c 10 | */ 11 | 12 | #ifndef _ec_print_ 13 | #define _ec_print_ 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | const char *ec_sdoerror2string(uint32 sdoerrorcode); 20 | char *ec_ALstatuscode2string(uint16 ALstatuscode); 21 | char *ec_soeerror2string(uint16 errorcode); 22 | char *ec_mbxerror2string(uint16 errorcode); 23 | char *ecx_err2string(const ec_errort Ec); 24 | char *ecx_elist2string(ecx_contextt *context); 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /contrib/osal/vxworks/osal_defs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is dual-licensed under GPLv3 and a commercial 3 | * license. See the file LICENSE.md distributed with this software for 4 | * full license information. 5 | */ 6 | 7 | #ifndef _osal_defs_ 8 | #define _osal_defs_ 9 | 10 | // define if debug printf is needed 11 | #ifdef EC_DEBUG 12 | #define EC_PRINT printf 13 | #else 14 | #define EC_PRINT(...) \ 15 | do \ 16 | { \ 17 | } while (0) 18 | #endif 19 | 20 | #ifndef OSAL_PACKED 21 | #define OSAL_PACKED_BEGIN 22 | #define OSAL_PACKED __attribute__((__packed__)) 23 | #define OSAL_PACKED_END 24 | #endif 25 | 26 | #define OSAL_THREAD_HANDLE TASK_ID 27 | #define OSAL_THREAD_FUNC void 28 | #define OSAL_THREAD_FUNC_RT void 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /include/soem/ec_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is dual-licensed under GPLv3 and a commercial 3 | * license. See the file LICENSE.md distributed with this software for 4 | * full license information. 5 | */ 6 | 7 | /** \file 8 | * \brief 9 | * Headerfile for ec_config.c 10 | */ 11 | 12 | #ifndef _ec_config_ 13 | #define _ec_config_ 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | #define EC_NODEOFFSET 0x1000 20 | #define EC_TEMPNODE 0xffff 21 | 22 | int ecx_config_init(ecx_contextt *context); 23 | int ecx_config_map_group(ecx_contextt *context, void *pIOmap, uint8 group); 24 | int ecx_recover_slave(ecx_contextt *context, uint16 slave, int timeout); 25 | int ecx_reconfig_slave(ecx_contextt *context, uint16 slave, int timeout); 26 | 27 | #ifdef __cplusplus 28 | } 29 | #endif 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # Simple Open EtherCAT Master Library 2 | 3 | * Copyright (C) 2005-2025 Speciaal Machinefabriek Ketels v.o.f. 4 | * Copyright (C) 2005-2025 Arthur Ketels 5 | * Copyright (C) 2009-2025 RT-Labs AB, Sweden 6 | 7 | # License 8 | 9 | This software is dual-licensed. 10 | 11 | ## GPL version 3 12 | 13 | This software is distributed under GPLv3. You are allowed to use this 14 | software for an open-source project with a compatible license. 15 | 16 | [GNU GPL license v3](https://www.gnu.org/licenses/gpl-3.0.html) 17 | 18 | ## Commercial license 19 | 20 | This software is also available under a commercial license with 21 | options for support and maintenance. Please contact sales@rt-labs.com 22 | for further details. 23 | 24 | If you intend to use this stack in a commercial product, you likely need to 25 | buy a license. 26 | -------------------------------------------------------------------------------- /oshw/rtk/oshw.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is dual-licensed under GPLv3 and a commercial 3 | * license. See the file LICENSE.md distributed with this software for 4 | * full license information. 5 | */ 6 | 7 | /** \file 8 | * \brief 9 | * Headerfile for oshw.c 10 | */ 11 | 12 | #ifndef _oshw_ 13 | #define _oshw_ 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | #include 20 | #include "soem/soem.h" 21 | #include "nicdrv.h" 22 | 23 | int oshw_mac_init(const uint8_t *mac_address); 24 | int oshw_mac_send(const void *payload, size_t tot_len); 25 | int oshw_mac_recv(void *buffer, size_t buffer_length); 26 | 27 | uint16 oshw_htons(uint16 host); 28 | uint16 oshw_ntohs(uint16 network); 29 | 30 | ec_adaptert *oshw_find_adapters(void); 31 | void oshw_free_adapters(ec_adaptert *adapter); 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /contrib/osal/macosx/osal_defs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is dual-licensed under GPLv3 and a commercial 3 | * license. See the file LICENSE.md distributed with this software for 4 | * full license information. 5 | */ 6 | 7 | #ifndef _osal_defs_ 8 | #define _osal_defs_ 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | // define if debug printf is needed 15 | #ifdef EC_DEBUG 16 | #define EC_PRINT printf 17 | #else 18 | #define EC_PRINT(...) \ 19 | do \ 20 | { \ 21 | } while (0) 22 | #endif 23 | 24 | #ifndef OSAL_PACKED 25 | #define OSAL_PACKED_BEGIN 26 | #define OSAL_PACKED __attribute__((__packed__)) 27 | #define OSAL_PACKED_END 28 | #endif 29 | 30 | #include 31 | #define OSAL_THREAD_HANDLE pthread_t * 32 | #define OSAL_THREAD_FUNC void 33 | #define OSAL_THREAD_FUNC_RT void 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /contrib/osal/rtems/osal_defs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is dual-licensed under GPLv3 and a commercial 3 | * license. See the file LICENSE.md distributed with this software for 4 | * full license information. 5 | */ 6 | 7 | #ifndef _osal_defs_ 8 | #define _osal_defs_ 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | // define if debug printf is needed 15 | #ifdef EC_DEBUG 16 | #define EC_PRINT printf 17 | #else 18 | #define EC_PRINT(...) \ 19 | do \ 20 | { \ 21 | } while (0) 22 | #endif 23 | 24 | #ifndef OSAL_PACKED 25 | #define OSAL_PACKED_BEGIN 26 | #define OSAL_PACKED __attribute__((__packed__)) 27 | #define OSAL_PACKED_END 28 | #endif 29 | 30 | #include 31 | #define OSAL_THREAD_HANDLE pthread_t * 32 | #define OSAL_THREAD_FUNC void 33 | #define OSAL_THREAD_FUNC_RT void 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /contrib/cmake/rtems.cmake: -------------------------------------------------------------------------------- 1 | # This software is dual-licensed under GPLv3 and a commercial 2 | # license. See the file LICENSE.md distributed with this software for 3 | # full license information. 4 | 5 | set(BUILD_TESTS FALSE) 6 | 7 | target_sources(soem PRIVATE 8 | osal/rtems/osal.c 9 | osal/rtems/osal_defs.h 10 | oshw/rtems/oshw.c 11 | oshw/rtems/oshw.h 12 | oshw/rtems/nicdrv.c 13 | oshw/rtems/nicdrv.h 14 | ) 15 | 16 | target_include_directories(soem PUBLIC 17 | $ 18 | $ 19 | ) 20 | 21 | target_include_directories(soem PUBLIC 22 | $ 23 | $ 24 | ) 25 | 26 | add_definitions(-Wall -Wextra -Werror) 27 | 28 | target_link_libraries(soem PUBLIC rtemscpu bsd ${HOST_LIBS}) 29 | 30 | install(FILES 31 | osal/rtems/osal_defs.h 32 | oshw/rtems/nicdrv.h 33 | DESTINATION include/soem 34 | ) 35 | -------------------------------------------------------------------------------- /contrib/osal/erika/osal_defs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is dual-licensed under GPLv3 and a commercial 3 | * license. See the file LICENSE.md distributed with this software for 4 | * full license information. 5 | */ 6 | 7 | #ifndef _osal_defs_ 8 | #define _osal_defs_ 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | // define if debug print is needed 19 | #ifdef EC_DEBUG 20 | #define EC_PRINT OSEE_PRINT 21 | #else 22 | #define EC_PRINT(...) \ 23 | do \ 24 | { \ 25 | } while (0) 26 | #endif 27 | 28 | #ifndef OSAL_PACKED 29 | #define OSAL_PACKED_BEGIN 30 | #define OSAL_PACKED __attribute__((__packed__)) 31 | #define OSAL_PACKED_END 32 | #endif 33 | 34 | int osal_gettimeofday(struct timeval *tv, struct timezone *tz); 35 | void *osal_malloc(size_t size); 36 | void osal_free(void *ptr); 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /CMakePresets.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 6, 3 | "configurePresets": [{ 4 | "name": "base", 5 | "hidden": true, 6 | "generator": "Ninja", 7 | "binaryDir": "build/${presetName}", 8 | "cacheVariables": { 9 | "CMAKE_EXPORT_COMPILE_COMMANDS": true, 10 | "CMAKE_COMPILE_WARNING_AS_ERROR": true, 11 | "CMAKE_FIND_NO_INSTALL_PREFIX": true, 12 | "CMAKE_RUNTIME_OUTPUT_DIRECTORY": "$<0:>../../bin" 13 | } 14 | }, { 15 | "name": "docs", 16 | "inherits": "base", 17 | "cacheVariables": { 18 | "CMAKE_BUILD_TYPE": "RelWithDebInfo" 19 | } 20 | }, { 21 | "name": "default", 22 | "inherits" : "base" 23 | }], 24 | "buildPresets": [{ 25 | "name": "default", 26 | "configurePreset": "default" 27 | }, { 28 | "name": "docs", 29 | "configurePreset": "docs", 30 | "targets": ["sphinx-html"] 31 | }], 32 | "packagePresets": [{ 33 | "name": "default", 34 | "configurePreset": "default", 35 | "generators": [ 36 | "ZIP" 37 | ] 38 | }] 39 | } 40 | -------------------------------------------------------------------------------- /osal/rtk/osal_defs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is dual-licensed under GPLv3 and a commercial 3 | * license. See the file LICENSE.md distributed with this software for 4 | * full license information. 5 | */ 6 | 7 | #ifndef _osal_defs_ 8 | #define _osal_defs_ 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include 15 | 16 | // define if debug printf is needed 17 | #ifdef EC_DEBUG 18 | #include 19 | #define EC_PRINT printf 20 | #else 21 | #define EC_PRINT(...) \ 22 | do \ 23 | { \ 24 | } while (0) 25 | #endif 26 | 27 | #ifndef OSAL_PACKED 28 | #define OSAL_PACKED_BEGIN 29 | #define OSAL_PACKED __attribute__((__packed__)) 30 | #define OSAL_PACKED_END 31 | #endif 32 | 33 | #define ec_timet struct timespec 34 | 35 | #define OSAL_THREAD_HANDLE task_t * 36 | #define OSAL_THREAD_FUNC void 37 | #define OSAL_THREAD_FUNC_RT void 38 | 39 | #define osal_mutext mtx_t * 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /contrib/osal/intime/osal_defs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is dual-licensed under GPLv3 and a commercial 3 | * license. See the file LICENSE.md distributed with this software for 4 | * full license information. 5 | */ 6 | 7 | #ifndef _osal_defs_ 8 | #define _osal_defs_ 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | // define if debug printf is needed 15 | #ifdef EC_DEBUG 16 | #define EC_PRINT printf 17 | #else 18 | #define EC_PRINT(...) \ 19 | do \ 20 | { \ 21 | } while (0) 22 | #endif 23 | 24 | #ifndef OSAL_PACKED 25 | #ifdef _MSC_VER 26 | #define OSAL_PACKED_BEGIN __pragma(pack(push, 1)) 27 | #define OSAL_PACKED 28 | #define OSAL_PACKED_END __pragma(pack(pop)) 29 | #elif defined(__GNUC__) 30 | #define OSAL_PACKED_BEGIN 31 | #define OSAL_PACKED __attribute__((__packed__)) 32 | #define OSAL_PACKED_END 33 | #endif 34 | #endif 35 | 36 | #define OSAL_THREAD_HANDLE RTHANDLE 37 | #define OSAL_THREAD_FUNC void 38 | #define OSAL_THREAD_FUNC_RT void 39 | 40 | #ifdef __cplusplus 41 | } 42 | #endif 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /osal/linux/osal_defs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is dual-licensed under GPLv3 and a commercial 3 | * license. See the file LICENSE.md distributed with this software for 4 | * full license information. 5 | */ 6 | 7 | #ifndef _osal_defs_ 8 | #define _osal_defs_ 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include 15 | #include 16 | 17 | // define if debug printf is needed 18 | #ifdef EC_DEBUG 19 | #include 20 | #define EC_PRINT printf 21 | #else 22 | #define EC_PRINT(...) \ 23 | do \ 24 | { \ 25 | } while (0) 26 | #endif 27 | 28 | #ifndef OSAL_PACKED 29 | #define OSAL_PACKED_BEGIN 30 | #define OSAL_PACKED __attribute__((__packed__)) 31 | #define OSAL_PACKED_END 32 | #endif 33 | 34 | #define ec_timet struct timespec 35 | 36 | #define OSAL_THREAD_HANDLE pthread_t * 37 | #define OSAL_THREAD_FUNC void 38 | #define OSAL_THREAD_FUNC_RT void 39 | 40 | #define osal_mutext pthread_mutex_t 41 | 42 | #ifdef __cplusplus 43 | } 44 | #endif 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /cmake/Linux.cmake: -------------------------------------------------------------------------------- 1 | # This software is dual-licensed under GPLv3 and a commercial 2 | # license. See the file LICENSE.md distributed with this software for 3 | # full license information. 4 | 5 | target_sources(soem PRIVATE 6 | osal/linux/osal.c 7 | osal/linux/osal_defs.h 8 | oshw/linux/oshw.c 9 | oshw/linux/oshw.h 10 | oshw/linux/nicdrv.c 11 | oshw/linux/nicdrv.h 12 | ) 13 | 14 | target_include_directories(soem PUBLIC 15 | $ 16 | $ 17 | $ 18 | ) 19 | 20 | foreach(target IN ITEMS 21 | soem 22 | ec_sample 23 | eepromtool 24 | eni_test 25 | eoe_test 26 | firm_update 27 | simple_ng 28 | slaveinfo) 29 | if (TARGET ${target}) 30 | target_compile_options(${target} PRIVATE 31 | -Wall 32 | -Wextra 33 | ) 34 | endif() 35 | endforeach() 36 | 37 | target_link_libraries(soem PUBLIC pthread rt) 38 | 39 | install(FILES 40 | osal/linux/osal_defs.h 41 | oshw/linux/nicdrv.h 42 | DESTINATION include/soem 43 | ) 44 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Simple Open EtherCAT Master Library 2 | 3 | * Copyright (C) 2005-2025 Speciaal Machinefabriek Ketels v.o.f. 4 | * Copyright (C) 2005-2025 Arthur Ketels 5 | * Copyright (C) 2009-2025 RT-Labs AB, Sweden 6 | 7 | SOEM (Simple Open EtherCAT Master) is a software library for 8 | developing EtherCAT MainDevices. 9 | 10 | This library is specifically designed for real-time communication in 11 | embedded systems. Its lightweight architecture minimizes resource 12 | consumption, making it suitable for environments with limited 13 | resources. SOEM can also be utilized on both Linux and Windows 14 | systems. 15 | 16 | As a library rather than a standalone application, SOEM provides 17 | flexibility and customization for developers looking to implement 18 | EtherCAT technology. 19 | 20 | # Documentation 21 | 22 | See https://docs.rt-labs.com/soem 23 | 24 | # Contributions 25 | 26 | Contributions are welcome. If you want to contribute you will need to 27 | sign a Contributor License Agreement and send it to us either by 28 | e-mail or by physical mail. More information is available on 29 | [https://rt-labs.com/contribution](https://rt-labs.com/contribution). 30 | -------------------------------------------------------------------------------- /cmake/AddENI.cmake: -------------------------------------------------------------------------------- 1 | # This software is dual-licensed under GPLv3 and a commercial 2 | # license. See the file LICENSE.md distributed with this software for 3 | # full license information. 4 | 5 | #[=======================================================================[.rst: 6 | add_eni 7 | -------- 8 | 9 | Helper function to run eniconv on ENI file. 10 | 11 | .. command:: add_eni 12 | 13 | .. code-block:: cmake 14 | 15 | add_eni( ) 16 | 17 | Runs eniconv on ``enifile`` and adds the output file to the list of 18 | sources for ````. 19 | 20 | #]=======================================================================] 21 | find_package(Python3 REQUIRED) 22 | find_program(ENICONV eniconv.py PATH_SUFFIXES scripts PATHS ${SOEM_SOURCE_DIR} REQUIRED) 23 | 24 | function(add_eni target eni) 25 | cmake_path(GET eni STEM _eni_name) 26 | cmake_path(ABSOLUTE_PATH eni OUTPUT_VARIABLE _eni) 27 | 28 | add_custom_command ( 29 | OUTPUT ${_eni_name}.c 30 | DEPENDS ${_eni} 31 | COMMAND ${Python3_EXECUTABLE} ${ENICONV} ${_eni} > ${_eni_name}.c 32 | VERBATIM 33 | ) 34 | 35 | target_sources(${target} 36 | PRIVATE 37 | ${_eni_name}.c 38 | ) 39 | endfunction() 40 | -------------------------------------------------------------------------------- /cmake/rt-kernel.cmake: -------------------------------------------------------------------------------- 1 | # This software is dual-licensed under GPLv3 and a commercial 2 | # license. See the file LICENSE.md distributed with this software for 3 | # full license information. 4 | 5 | find_package(rtkernel) 6 | find_package(${BSP}) 7 | 8 | target_sources(soem PRIVATE 9 | osal/rtk/osal.c 10 | osal/rtk/osal_defs.h 11 | oshw/rtk/oshw.c 12 | oshw/rtk/oshw.h 13 | oshw/rtk/nicdrv.c 14 | oshw/rtk/nicdrv.h 15 | ) 16 | 17 | target_include_directories(soem PUBLIC 18 | $ 19 | $ 20 | ) 21 | 22 | target_include_directories(soem PUBLIC 23 | $ 24 | $ 25 | ) 26 | 27 | foreach(target IN ITEMS 28 | soem 29 | ec_sample 30 | eepromtool 31 | eni_test 32 | eoe_test 33 | firm_update 34 | simple_ng 35 | slaveinfo) 36 | if (TARGET ${target}) 37 | target_compile_options(${target} PRIVATE 38 | -Wall 39 | -Wextra 40 | -Wno-unused-parameter 41 | -Wno-format 42 | ) 43 | endif() 44 | endforeach() 45 | 46 | install(FILES 47 | osal/rtk/osal_defs.h 48 | oshw/rtk/nicdrv.h 49 | DESTINATION include/soem 50 | ) 51 | 52 | target_link_libraries(soem PUBLIC kern ${BSP}) 53 | -------------------------------------------------------------------------------- /osal/win32/osal_defs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is dual-licensed under GPLv3 and a commercial 3 | * license. See the file LICENSE.md distributed with this software for 4 | * full license information. 5 | */ 6 | 7 | #ifndef _osal_defs_ 8 | #define _osal_defs_ 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #define WIN32_LEAN_AND_MEAN // Exclude some conflicting definitions in windows header 15 | #include 16 | #include 17 | // define if debug printf is needed 18 | #ifdef EC_DEBUG 19 | #include 20 | #define EC_PRINT printf 21 | #else 22 | #define EC_PRINT(...) \ 23 | do \ 24 | { \ 25 | } while (0) 26 | #endif 27 | 28 | #ifndef OSAL_PACKED 29 | #define OSAL_PACKED 30 | #ifdef __GNUC__ 31 | #define OSAL_PACKED_BEGIN _Pragma("pack(push,1)") 32 | #define OSAL_PACKED_END _Pragma("pack(pop)") 33 | #else 34 | #define OSAL_PACKED_BEGIN __pragma(pack(push, 1)) 35 | #define OSAL_PACKED_END __pragma(pack(pop)) 36 | #endif 37 | #endif 38 | 39 | #define ec_timet struct timespec 40 | 41 | #define OSAL_THREAD_HANDLE HANDLE 42 | #define OSAL_THREAD_FUNC void 43 | #define OSAL_THREAD_FUNC_RT void 44 | 45 | #define osal_mutext CRITICAL_SECTION 46 | 47 | #ifdef __cplusplus 48 | } 49 | #endif 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /contrib/oshw/intime/oshw.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is dual-licensed under GPLv3 and a commercial 3 | * license. See the file LICENSE.md distributed with this software for 4 | * full license information. 5 | */ 6 | 7 | #include 8 | #include "oshw.h" 9 | 10 | /** 11 | * Host to Network byte order (i.e. to big endian). 12 | * 13 | * Note that Ethercat uses little endian byte order, except for the Ethernet 14 | * header which is big endian as usual. 15 | */ 16 | uint16 oshw_htons(uint16 host) 17 | { 18 | uint16 network = htons(host); 19 | return network; 20 | } 21 | 22 | /** 23 | * Network (i.e. big endian) to Host byte order. 24 | * 25 | * Note that Ethercat uses little endian byte order, except for the Ethernet 26 | * header which is big endian as usual. 27 | */ 28 | uint16 oshw_ntohs(uint16 network) 29 | { 30 | uint16 host = ntohs(network); 31 | return host; 32 | } 33 | 34 | /* Create list over available network adapters. 35 | * @return First element in linked list of adapters 36 | */ 37 | ec_adaptert *oshw_find_adapters(void) 38 | { 39 | return NULL; 40 | } 41 | 42 | /** Free memory allocated memory used by adapter collection. 43 | * @param[in] adapter = First element in linked list of adapters 44 | * EC_NOFRAME. 45 | */ 46 | void oshw_free_adapters(ec_adaptert *adapter) 47 | { 48 | } 49 | -------------------------------------------------------------------------------- /oshw/rtk/oshw.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is dual-licensed under GPLv3 and a commercial 3 | * license. See the file LICENSE.md distributed with this software for 4 | * full license information. 5 | */ 6 | 7 | #include "oshw.h" 8 | #include 9 | #include 10 | 11 | /** 12 | * Host to Network byte order (i.e. to big endian). 13 | * 14 | * Note that Ethercat uses little endian byte order, except for the Ethernet 15 | * header which is big endian as usual. 16 | */ 17 | uint16 oshw_htons(const uint16 host) 18 | { 19 | uint16 network = htons(host); 20 | return network; 21 | } 22 | 23 | /** 24 | * Network (i.e. big endian) to Host byte order. 25 | * 26 | * Note that Ethercat uses little endian byte order, except for the Ethernet 27 | * header which is big endian as usual. 28 | */ 29 | uint16 oshw_ntohs(const uint16 network) 30 | { 31 | uint16 host = ntohs(network); 32 | return host; 33 | } 34 | 35 | /* Create list over available network adapters. 36 | * @return First element in linked list of adapters 37 | */ 38 | ec_adaptert *oshw_find_adapters(void) 39 | { 40 | ec_adaptert *ret_adapter = NULL; 41 | 42 | /* TODO if needed */ 43 | 44 | return ret_adapter; 45 | } 46 | 47 | /** Free memory allocated memory used by adapter collection. 48 | * @param[in] adapter = First element in linked list of adapters 49 | * EC_NOFRAME. 50 | */ 51 | void oshw_free_adapters(ec_adaptert *adapter) 52 | { 53 | /* TODO if needed */ 54 | } 55 | -------------------------------------------------------------------------------- /contrib/oshw/vxworks/oshw.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is dual-licensed under GPLv3 and a commercial 3 | * license. See the file LICENSE.md distributed with this software for 4 | * full license information. 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include "oshw.h" 16 | 17 | /** 18 | * Host to Network byte order (i.e. to big endian). 19 | * 20 | * Note that Ethercat uses little endian byte order, except for the Ethernet 21 | * header which is big endian as usual. 22 | */ 23 | uint16 oshw_htons(uint16 host) 24 | { 25 | uint16 network = htons(host); 26 | return network; 27 | } 28 | 29 | /** 30 | * Network (i.e. big endian) to Host byte order. 31 | * 32 | * Note that Ethercat uses little endian byte order, except for the Ethernet 33 | * header which is big endian as usual. 34 | */ 35 | uint16 oshw_ntohs(uint16 network) 36 | { 37 | uint16 host = ntohs(network); 38 | return host; 39 | } 40 | 41 | /** Create list over available network adapters. 42 | * @return First element in linked list of adapters 43 | */ 44 | ec_adaptert *oshw_find_adapters(void) 45 | { 46 | ec_adaptert *ret_adapter = NULL; 47 | /* Not implemented */ 48 | assert(0); 49 | 50 | return ret_adapter; 51 | } 52 | 53 | /** Free memory allocated memory used by adapter collection. 54 | * @param[in] adapter = First element in linked list of adapters 55 | * EC_NOFRAME. 56 | */ 57 | void oshw_free_adapters(ec_adaptert *adapter) 58 | { 59 | /* Not implemented */ 60 | assert(0); 61 | } 62 | -------------------------------------------------------------------------------- /cmake/Windows.cmake: -------------------------------------------------------------------------------- 1 | # This software is dual-licensed under GPLv3 and a commercial 2 | # license. See the file LICENSE.md distributed with this software for 3 | # full license information. 4 | 5 | target_sources(soem PRIVATE 6 | osal/win32/osal.c 7 | osal/win32/osal_defs.h 8 | oshw/win32/oshw.c 9 | oshw/win32/oshw.h 10 | oshw/win32/nicdrv.c 11 | oshw/win32/nicdrv.h 12 | ) 13 | 14 | target_include_directories(soem PUBLIC 15 | $ 16 | $ 17 | $ 18 | $ 19 | ) 20 | 21 | target_compile_options(soem PUBLIC 22 | $<$:-std=c11> 23 | ) 24 | 25 | target_compile_definitions(soem PUBLIC 26 | $<$:_UCRT> 27 | ) 28 | 29 | target_link_libraries(soem PUBLIC 30 | $<$:ucrt> 31 | ) 32 | 33 | foreach(target IN ITEMS 34 | soem 35 | ec_sample 36 | eepromtool 37 | eni_test 38 | eoe_test 39 | firm_update 40 | simple_ng 41 | slaveinfo) 42 | if (TARGET ${target}) 43 | target_compile_options(${target} PRIVATE 44 | $<$: 45 | /D _CRT_SECURE_NO_WARNINGS 46 | /W3 47 | > 48 | $<$: 49 | -Wall 50 | -Wextra 51 | -Wno-unused-parameter 52 | > 53 | ) 54 | endif() 55 | endforeach() 56 | 57 | 58 | if(CMAKE_SIZEOF_VOID_P EQUAL 8) 59 | set(WPCAP_LIB_PATH ${SOEM_SOURCE_DIR}/oshw/win32/wpcap/Lib/x64) 60 | elseif(CMAKE_SIZEOF_VOID_P EQUAL 4) 61 | set(WPCAP_LIB_PATH ${SOEM_SOURCE_DIR}/oshw/win32/wpcap/Lib) 62 | endif() 63 | 64 | target_link_libraries(soem PUBLIC 65 | ${WPCAP_LIB_PATH}/wpcap.lib 66 | ${WPCAP_LIB_PATH}/Packet.lib 67 | ws2_32.lib 68 | winmm.lib 69 | ) 70 | 71 | install(FILES 72 | osal/win32/osal_defs.h 73 | oshw/win32/nicdrv.h 74 | DESTINATION include/soem 75 | ) 76 | -------------------------------------------------------------------------------- /include/soem/ec_base.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is dual-licensed under GPLv3 and a commercial 3 | * license. See the file LICENSE.md distributed with this software for 4 | * full license information. 5 | */ 6 | 7 | /** \file 8 | * \brief 9 | * Headerfile for ec_base.c 10 | */ 11 | 12 | #ifndef _ec_base_ 13 | #define _ec_base_ 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | int ecx_setupdatagram(ecx_portt *port, void *frame, uint8 com, uint8 idx, uint16 ADP, uint16 ADO, uint16 length, void *data); 20 | uint16 ecx_adddatagram(ecx_portt *port, void *frame, uint8 com, uint8 idx, boolean more, uint16 ADP, uint16 ADO, uint16 length, void *data); 21 | int ecx_BWR(ecx_portt *port, uint16 ADP, uint16 ADO, uint16 length, void *data, int timeout); 22 | int ecx_BRD(ecx_portt *port, uint16 ADP, uint16 ADO, uint16 length, void *data, int timeout); 23 | int ecx_APRD(ecx_portt *port, uint16 ADP, uint16 ADO, uint16 length, void *data, int timeout); 24 | int ecx_ARMW(ecx_portt *port, uint16 ADP, uint16 ADO, uint16 length, void *data, int timeout); 25 | int ecx_FRMW(ecx_portt *port, uint16 ADP, uint16 ADO, uint16 length, void *data, int timeout); 26 | uint16 ecx_APRDw(ecx_portt *port, uint16 ADP, uint16 ADO, int timeout); 27 | int ecx_FPRD(ecx_portt *port, uint16 ADP, uint16 ADO, uint16 length, void *data, int timeout); 28 | uint16 ecx_FPRDw(ecx_portt *port, uint16 ADP, uint16 ADO, int timeout); 29 | int ecx_APWRw(ecx_portt *port, uint16 ADP, uint16 ADO, uint16 data, int timeout); 30 | int ecx_APWR(ecx_portt *port, uint16 ADP, uint16 ADO, uint16 length, void *data, int timeout); 31 | int ecx_FPWRw(ecx_portt *port, uint16 ADP, uint16 ADO, uint16 data, int timeout); 32 | int ecx_FPWR(ecx_portt *port, uint16 ADP, uint16 ADO, uint16 length, void *data, int timeout); 33 | int ecx_LRW(ecx_portt *port, uint32 LogAdr, uint16 length, void *data, int timeout); 34 | int ecx_LRD(ecx_portt *port, uint32 LogAdr, uint16 length, void *data, int timeout); 35 | int ecx_LWR(ecx_portt *port, uint32 LogAdr, uint16 length, void *data, int timeout); 36 | int ecx_LRWDC(ecx_portt *port, uint32 LogAdr, uint16 length, void *data, uint16 DCrs, int64 *DCtime, int timeout); 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /oshw/win32/wpcap/Include/pcap/bluetooth.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006 Paolo Abeni (Italy) 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. The name of the author may not be used to endorse or promote 15 | * products derived from this software without specific prior written 16 | * permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | * bluetooth data struct 31 | * By Paolo Abeni 32 | * 33 | * @(#) $Header: /tcpdump/master/libpcap/pcap/bluetooth.h,v 1.1 2007/09/22 02:10:17 guy Exp $ 34 | */ 35 | 36 | #ifndef _PCAP_BLUETOOTH_STRUCTS_H__ 37 | #define _PCAP_BLUETOOTH_STRUCTS_H__ 38 | 39 | /* 40 | * Header prepended libpcap to each bluetooth h:4 frame. 41 | * fields are in network byte order 42 | */ 43 | typedef struct _pcap_bluetooth_h4_header { 44 | u_int32_t direction; /* if first bit is set direction is incoming */ 45 | } pcap_bluetooth_h4_header; 46 | 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /contrib/oshw/erika/oshw.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is dual-licensed under GPLv3 and a commercial 3 | * license. See the file LICENSE.md distributed with this software for 4 | * full license information. 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "oshw.h" 13 | #include "intel_i210.h" 14 | #include "ethercat.h" 15 | 16 | #if !defined(__gnu_linux__) 17 | #include 18 | #else 19 | #include 20 | #define __htons(x) htobe16(x) 21 | #define __ntohs(x) be16toh(x) 22 | #endif 23 | 24 | ec_adaptert adapters[DEVS_MAX_NB]; 25 | 26 | /** 27 | * Host to Network byte order (i.e. to big endian). 28 | * 29 | * Note that Ethercat uses little endian byte order, except for the Ethernet 30 | * header which is big endian as usual. 31 | */ 32 | inline uint16 oshw_htons(uint16 host) 33 | { 34 | // __htons() is provided by the bare-metal x86 compiler 35 | return __htons(host); 36 | } 37 | 38 | /** 39 | * Network (i.e. big endian) to Host byte order. 40 | * 41 | * Note that Ethercat uses little endian byte order, except for the Ethernet 42 | * header which is big endian as usual. 43 | */ 44 | inline uint16 oshw_ntohs(uint16 network) 45 | { 46 | // __ntohs() is provided by the bare-metal x86 compiler 47 | return __ntohs(network); 48 | } 49 | 50 | /** Create list over available network adapters. 51 | * @return First element in linked list of adapters 52 | */ 53 | ec_adaptert *oshw_find_adapters(void) 54 | { 55 | ec_adaptert *ret = NULL; 56 | if (eth_discover_devices() >= 0) 57 | { 58 | for (int i = 0;; ++i) 59 | { 60 | struct eth_device *dev = eth_get_device(i); 61 | if (dev == NULL) 62 | { 63 | adapters[i - 1].next = NULL; 64 | break; 65 | } 66 | strncpy(adapters[i].name, dev->name, MAX_DEVICE_NAME); 67 | adapters[i].next = &adapters[i + 1]; 68 | } 69 | ret = &(adapters[0]); 70 | } 71 | return ret; 72 | } 73 | 74 | /** Free memory allocated memory used by adapter collection. 75 | * @param[in] adapter = First element in linked list of adapters 76 | * EC_NOFRAME. 77 | */ 78 | void oshw_free_adapters(ec_adaptert *adapter) 79 | { 80 | } 81 | 82 | extern int ec_slavecount; 83 | -------------------------------------------------------------------------------- /oshw/win32/wpcap/Include/pcap-namedb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1994, 1996 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. All advertising materials mentioning features or use of this software 14 | * must display the following acknowledgement: 15 | * This product includes software developed by the Computer Systems 16 | * Engineering Group at Lawrence Berkeley Laboratory. 17 | * 4. Neither the name of the University nor of the Laboratory may be used 18 | * to endorse or promote products derived from this software without 19 | * specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 | * SUCH DAMAGE. 32 | * 33 | * @(#) $Header: /tcpdump/master/libpcap/pcap-namedb.h,v 1.13 2006/10/04 18:13:32 guy Exp $ (LBL) 34 | */ 35 | 36 | /* 37 | * For backwards compatibility. 38 | * 39 | * Note to OS vendors: do NOT get rid of this file! Some applications 40 | * might expect to be able to include . 41 | */ 42 | #include 43 | -------------------------------------------------------------------------------- /oshw/win32/wpcap/Include/pcap/vlan.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. All advertising materials mentioning features or use of this software 14 | * must display the following acknowledgement: 15 | * This product includes software developed by the University of 16 | * California, Berkeley and its contributors. 17 | * 4. Neither the name of the University nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 | * SUCH DAMAGE. 32 | * 33 | * @(#) $Header: /tcpdump/master/libpcap/pcap/vlan.h,v 1.1.2.2 2008-08-06 07:45:59 guy Exp $ 34 | */ 35 | 36 | #ifndef lib_pcap_vlan_h 37 | #define lib_pcap_vlan_h 38 | 39 | struct vlan_tag { 40 | u_int16_t vlan_tpid; /* ETH_P_8021Q */ 41 | u_int16_t vlan_tci; /* VLAN TCI */ 42 | }; 43 | 44 | #define VLAN_TAG_LEN 4 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /contrib/osal/intime/osal.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is dual-licensed under GPLv3 and a commercial 3 | * license. See the file LICENSE.md distributed with this software for 4 | * full license information. 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | static int64_t sysfrequency; 12 | static double qpc2usec; 13 | 14 | #define USECS_PER_SEC 1000000 15 | 16 | int osal_gettimeofday(struct timeval *tv, struct timezone *tz) 17 | { 18 | return gettimeofday(tv, tz); 19 | } 20 | 21 | ec_timet osal_current_time(void) 22 | { 23 | struct timeval current_time; 24 | ec_timet return_value; 25 | 26 | osal_gettimeofday(¤t_time, 0); 27 | return_value.sec = current_time.tv_sec; 28 | return_value.usec = current_time.tv_usec; 29 | return return_value; 30 | } 31 | 32 | void osal_timer_start(osal_timert *self, uint32 timeout_usec) 33 | { 34 | struct timeval start_time; 35 | struct timeval timeout; 36 | struct timeval stop_time; 37 | 38 | osal_gettimeofday(&start_time, 0); 39 | timeout.tv_sec = timeout_usec / USECS_PER_SEC; 40 | timeout.tv_usec = timeout_usec % USECS_PER_SEC; 41 | timeradd(&start_time, &timeout, &stop_time); 42 | 43 | self->stop_time.sec = stop_time.tv_sec; 44 | self->stop_time.usec = stop_time.tv_usec; 45 | } 46 | 47 | boolean osal_timer_is_expired(osal_timert *self) 48 | { 49 | struct timeval current_time; 50 | struct timeval stop_time; 51 | int is_not_yet_expired; 52 | 53 | osal_gettimeofday(¤t_time, 0); 54 | stop_time.tv_sec = self->stop_time.sec; 55 | stop_time.tv_usec = self->stop_time.usec; 56 | is_not_yet_expired = timercmp(¤t_time, &stop_time, <); 57 | 58 | return is_not_yet_expired == FALSE; 59 | } 60 | 61 | int osal_usleep(uint32 usec) 62 | { 63 | RtSleepEx(usec / 1000); 64 | return 1; 65 | } 66 | 67 | /* Mutex is not needed when running single threaded */ 68 | 69 | void osal_mtx_lock(osal_mutex_t *mtx) 70 | { 71 | /* RtWaitForSingleObject((HANDLE)mtx, INFINITE); */ 72 | } 73 | 74 | void osal_mtx_unlock(osal_mutex_t *mtx) 75 | { 76 | /* RtReleaseMutex((HANDLE)mtx); */ 77 | } 78 | 79 | int osal_mtx_lock_timeout(osal_mutex_t *mtx, uint32_t time_ms) 80 | { 81 | /* return RtWaitForSingleObject((HANDLE)mtx, time_ms); */ 82 | return 0; 83 | } 84 | 85 | osal_mutex_t *osal_mtx_create(void) 86 | { 87 | /* return (void*)RtCreateMutex(NULL, FALSE, NULL); */ 88 | return (void *)0; 89 | } 90 | -------------------------------------------------------------------------------- /oshw/win32/wpcap/Include/pcap.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1993, 1994, 1995, 1996, 1997 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. All advertising materials mentioning features or use of this software 14 | * must display the following acknowledgement: 15 | * This product includes software developed by the Computer Systems 16 | * Engineering Group at Lawrence Berkeley Laboratory. 17 | * 4. Neither the name of the University nor of the Laboratory may be used 18 | * to endorse or promote products derived from this software without 19 | * specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 | * SUCH DAMAGE. 32 | * 33 | * @(#) $Header: /tcpdump/master/libpcap/pcap.h,v 1.59 2006/10/04 18:09:22 guy Exp $ (LBL) 34 | */ 35 | 36 | /* 37 | * For backwards compatibility. 38 | * 39 | * Note to OS vendors: do NOT get rid of this file! Many applications 40 | * expect to be able to include , and at least some of them 41 | * go through contortions in their configure scripts to try to detect 42 | * OSes that have "helpfully" moved pcap.h to without 43 | * leaving behind a file. 44 | */ 45 | #include 46 | -------------------------------------------------------------------------------- /oshw/win32/wpcap/Include/pcap-bpf.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * This code is derived from the Stanford/CMU enet packet filter, 6 | * (net/enet.c) distributed as part of 4.3BSD, and code contributed 7 | * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence 8 | * Berkeley Laboratory. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. All advertising materials mentioning features or use of this software 19 | * must display the following acknowledgement: 20 | * This product includes software developed by the University of 21 | * California, Berkeley and its contributors. 22 | * 4. Neither the name of the University nor the names of its contributors 23 | * may be used to endorse or promote products derived from this software 24 | * without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 27 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 30 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 | * SUCH DAMAGE. 37 | * 38 | * @(#) $Header: /tcpdump/master/libpcap/pcap-bpf.h,v 1.50 2007/04/01 21:43:55 guy Exp $ (LBL) 39 | */ 40 | 41 | /* 42 | * For backwards compatibility. 43 | * 44 | * Note to OS vendors: do NOT get rid of this file! Some applications 45 | * might expect to be able to include . 46 | */ 47 | #include 48 | -------------------------------------------------------------------------------- /osal/rtk/osal.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is dual-licensed under GPLv3 and a commercial 3 | * license. See the file LICENSE.md distributed with this software for 4 | * full license information. 5 | */ 6 | 7 | #include 8 | #include 9 | 10 | void osal_get_monotonic_time(ec_timet *tv) 11 | { 12 | tick_t tick = tick_get(); 13 | uint64_t usec = (uint64_t)(tick_to_ms(tick)) * 1000; 14 | 15 | osal_timespec_from_usec(usec, tv); 16 | } 17 | 18 | ec_timet osal_current_time(void) 19 | { 20 | struct timeval tv; 21 | struct timespec ts; 22 | 23 | gettimeofday(&tv, NULL); 24 | TIMEVAL_TO_TIMESPEC(&tv, &ts); 25 | return ts; 26 | } 27 | 28 | void osal_time_diff(ec_timet *start, ec_timet *end, ec_timet *diff) 29 | { 30 | osal_timespecsub(end, start, diff); 31 | } 32 | 33 | void osal_timer_start(osal_timert *self, uint32 timeout_usec) 34 | { 35 | struct timespec start_time; 36 | struct timespec timeout; 37 | 38 | osal_get_monotonic_time(&start_time); 39 | osal_timespec_from_usec(timeout_usec, &timeout); 40 | osal_timespecadd(&start_time, &timeout, &self->stop_time); 41 | } 42 | 43 | boolean osal_timer_is_expired(osal_timert *self) 44 | { 45 | struct timespec current_time; 46 | int is_not_yet_expired; 47 | 48 | osal_get_monotonic_time(¤t_time); 49 | is_not_yet_expired = osal_timespeccmp(¤t_time, &self->stop_time, <); 50 | 51 | return is_not_yet_expired == FALSE; 52 | } 53 | 54 | int osal_usleep(uint32 usec) 55 | { 56 | tick_t ticks = tick_from_ms(usec / 1000) + 1; 57 | task_delay(ticks); 58 | return 0; 59 | } 60 | 61 | void *osal_malloc(size_t size) 62 | { 63 | return malloc(size); 64 | } 65 | 66 | void osal_free(void *ptr) 67 | { 68 | free(ptr); 69 | } 70 | 71 | int osal_thread_create(void *thandle, int stacksize, void *func, void *param) 72 | { 73 | thandle = task_spawn("worker", func, 6, stacksize, param); 74 | if (!thandle) 75 | { 76 | return 0; 77 | } 78 | return 1; 79 | } 80 | 81 | int osal_thread_create_rt(void *thandle, int stacksize, void *func, void *param) 82 | { 83 | thandle = task_spawn("worker_rt", func, 15, stacksize, param); 84 | if (!thandle) 85 | { 86 | return 0; 87 | } 88 | return 1; 89 | } 90 | 91 | void *osal_mutex_create(void) 92 | { 93 | return (void *)mtx_create(); 94 | } 95 | 96 | void osal_mutex_destroy(void *mutex) 97 | { 98 | mtx_destroy(mutex); 99 | } 100 | 101 | void osal_mutex_lock(void *mutex) 102 | { 103 | mtx_lock(mutex); 104 | } 105 | 106 | void osal_mutex_unlock(void *mutex) 107 | { 108 | mtx_unlock(mutex); 109 | } 110 | -------------------------------------------------------------------------------- /include/soem/ec_coe.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is dual-licensed under GPLv3 and a commercial 3 | * license. See the file LICENSE.md distributed with this software for 4 | * full license information. 5 | */ 6 | 7 | /** \file 8 | * \brief 9 | * Headerfile for ec_coe.c 10 | */ 11 | 12 | #ifndef _ec_coe_ 13 | #define _ec_coe_ 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | /* Storage for object description list */ 20 | typedef struct 21 | { 22 | /** slave number */ 23 | uint16 Slave; 24 | /** number of entries in list */ 25 | uint16 Entries; 26 | /** array of indexes */ 27 | uint16 Index[EC_MAXODLIST]; 28 | /** array of datatypes, see EtherCAT specification */ 29 | uint16 DataType[EC_MAXODLIST]; 30 | /** array of object codes, see EtherCAT specification */ 31 | uint8 ObjectCode[EC_MAXODLIST]; 32 | /** number of subindexes for each index */ 33 | uint8 MaxSub[EC_MAXODLIST]; 34 | /** textual description of each index */ 35 | char Name[EC_MAXODLIST][EC_MAXNAME + 1]; 36 | } ec_ODlistt; 37 | 38 | /* storage for object list entry information */ 39 | typedef struct 40 | { 41 | /** number of entries in list */ 42 | uint16 Entries; 43 | /** array of value infos, see EtherCAT specification */ 44 | uint8 ValueInfo[EC_MAXOELIST]; 45 | /** array of value infos, see EtherCAT specification */ 46 | uint16 DataType[EC_MAXOELIST]; 47 | /** array of bit lengths, see EtherCAT specification */ 48 | uint16 BitLength[EC_MAXOELIST]; 49 | /** array of object access bits, see EtherCAT specification */ 50 | uint16 ObjAccess[EC_MAXOELIST]; 51 | /** textual description of each index */ 52 | char Name[EC_MAXOELIST][EC_MAXNAME + 1]; 53 | } ec_OElistt; 54 | 55 | void ecx_SDOerror(ecx_contextt *context, uint16 Slave, uint16 Index, uint8 SubIdx, int32 AbortCode); 56 | int ecx_SDOread(ecx_contextt *context, uint16 slave, uint16 index, uint8 subindex, 57 | boolean CA, int *psize, void *p, int timeout); 58 | int ecx_SDOwrite(ecx_contextt *context, uint16 Slave, uint16 Index, uint8 SubIndex, 59 | boolean CA, int psize, const void *p, int Timeout); 60 | int ecx_RxPDO(ecx_contextt *context, uint16 Slave, uint16 RxPDOnumber, int psize, const void *p); 61 | int ecx_TxPDO(ecx_contextt *context, uint16 slave, uint16 TxPDOnumber, int *psize, void *p, int timeout); 62 | int ecx_readPDOmap(ecx_contextt *context, uint16 Slave, uint32 *Osize, uint32 *Isize); 63 | int ecx_readPDOmapCA(ecx_contextt *context, uint16 Slave, int Thread_n, uint32 *Osize, uint32 *Isize); 64 | int ecx_readODlist(ecx_contextt *context, uint16 Slave, ec_ODlistt *pODlist); 65 | int ecx_readODdescription(ecx_contextt *context, uint16 Item, ec_ODlistt *pODlist); 66 | int ecx_readOEsingle(ecx_contextt *context, uint16 Item, uint8 SubI, ec_ODlistt *pODlist, ec_OElistt *pOElist); 67 | int ecx_readOE(ecx_contextt *context, uint16 Item, ec_ODlistt *pODlist, ec_OElistt *pOElist); 68 | 69 | #ifdef __cplusplus 70 | } 71 | #endif 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /contrib/osal/erika/osal.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is dual-licensed under GPLv3 and a commercial 3 | * license. See the file LICENSE.md distributed with this software for 4 | * full license information. 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include "ee_x86_64_tsc.h" 15 | 16 | #define USECS_PER_SEC 1000000 17 | #define NSECS_PER_SEC 1000000000 18 | 19 | uint64_t osEE_x86_64_tsc_read(void); 20 | 21 | void ee_usleep(uint32 usec); 22 | 23 | inline int osal_usleep(uint32 usec) 24 | { 25 | ee_usleep(usec); 26 | return 0; 27 | } 28 | 29 | int osal_gettimeofday(struct timeval *tv, struct timezone *tz) 30 | { 31 | uint64_t time = osEE_x86_64_tsc_read(); 32 | tv->tv_sec = time / NSECS_PER_SEC; 33 | tv->tv_sec += 946684800UL; /* EtherCAT uses 2000-01-01 as epoch start */ 34 | tv->tv_usec = (time % NSECS_PER_SEC) / 1000; 35 | return 0; 36 | } 37 | 38 | ec_timet osal_current_time(void) 39 | { 40 | struct timeval current_time; 41 | ec_timet ret; 42 | 43 | osal_gettimeofday(¤t_time, 0); 44 | ret.sec = current_time.tv_sec; 45 | ret.usec = current_time.tv_usec; 46 | return ret; 47 | } 48 | 49 | void osal_time_diff(ec_timet *start, ec_timet *end, ec_timet *diff) 50 | { 51 | if (end->usec < start->usec) 52 | { 53 | diff->sec = end->sec - start->sec - 1; 54 | diff->usec = end->usec + USECS_PER_SEC - start->usec; 55 | } 56 | else 57 | { 58 | diff->sec = end->sec - start->sec; 59 | diff->usec = end->usec - start->usec; 60 | } 61 | } 62 | 63 | void osal_timer_start(osal_timert *self, uint32 timeout_usec) 64 | { 65 | struct timeval start_time; 66 | struct timeval timeout; 67 | struct timeval stop_time; 68 | 69 | osal_gettimeofday(&start_time, 0); 70 | timeout.tv_sec = timeout_usec / USECS_PER_SEC; 71 | timeout.tv_usec = timeout_usec % USECS_PER_SEC; 72 | timeradd(&start_time, &timeout, &stop_time); 73 | 74 | self->stop_time.sec = stop_time.tv_sec; 75 | self->stop_time.usec = stop_time.tv_usec; 76 | } 77 | 78 | boolean osal_timer_is_expired(osal_timert *self) 79 | { 80 | struct timeval current_time; 81 | struct timeval stop_time; 82 | int is_not_yet_expired; 83 | 84 | osal_gettimeofday(¤t_time, 0); 85 | stop_time.tv_sec = self->stop_time.sec; 86 | stop_time.tv_usec = self->stop_time.usec; 87 | is_not_yet_expired = timercmp(¤t_time, &stop_time, <); 88 | /* OSEE_PRINT("current: %d:%d -- expire: %d:%d -- result: %d\n", */ 89 | /* current_time.tv_sec, */ 90 | /* current_time.tv_usec, */ 91 | /* stop_time.tv_sec, */ 92 | /* stop_time.tv_usec, */ 93 | /* is_not_yet_expired); */ 94 | 95 | return is_not_yet_expired == FALSE; 96 | } 97 | 98 | void *osal_malloc(size_t size) 99 | { 100 | return malloc(size); 101 | } 102 | 103 | void osal_free(void *ptr) 104 | { 105 | free(ptr); 106 | } 107 | -------------------------------------------------------------------------------- /oshw/rtk/nicdrv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is dual-licensed under GPLv3 and a commercial 3 | * license. See the file LICENSE.md distributed with this software for 4 | * full license information. 5 | */ 6 | 7 | /** \file 8 | * \brief 9 | * Headerfile for nicdrv.c 10 | */ 11 | 12 | #ifndef _nicdrvh_ 13 | #define _nicdrvh_ 14 | 15 | #include 16 | 17 | /** pointer structure to Tx and Rx stacks */ 18 | typedef struct 19 | { 20 | /** socket connection used */ 21 | int *sock; 22 | /** tx buffer */ 23 | ec_bufT (*txbuf)[EC_MAXBUF]; 24 | /** tx buffer lengths */ 25 | int (*txbuflength)[EC_MAXBUF]; 26 | /** temporary receive buffer */ 27 | ec_bufT *tempbuf; 28 | /** rx buffers */ 29 | ec_bufT (*rxbuf)[EC_MAXBUF]; 30 | /** rx buffer status fields */ 31 | int (*rxbufstat)[EC_MAXBUF]; 32 | /** received MAC source address (middle word) */ 33 | int (*rxsa)[EC_MAXBUF]; 34 | /** number of received frames */ 35 | uint64 rxcnt; 36 | } ec_stackT; 37 | 38 | /** pointer structure to buffers for redundant port */ 39 | typedef struct 40 | { 41 | ec_stackT stack; 42 | int sockhandle; 43 | /** rx buffers */ 44 | ec_bufT rxbuf[EC_MAXBUF]; 45 | /** rx buffer status */ 46 | int rxbufstat[EC_MAXBUF]; 47 | /** rx MAC source address */ 48 | int rxsa[EC_MAXBUF]; 49 | /** temporary rx buffer */ 50 | ec_bufT tempinbuf; 51 | } ecx_redportt; 52 | 53 | /** pointer structure to buffers, vars and mutexes for port instantiation */ 54 | typedef struct 55 | { 56 | ec_stackT stack; 57 | int sockhandle; 58 | /** rx buffers */ 59 | ec_bufT rxbuf[EC_MAXBUF]; 60 | /** rx buffer status */ 61 | int rxbufstat[EC_MAXBUF]; 62 | /** rx MAC source address */ 63 | int rxsa[EC_MAXBUF]; 64 | /** temporary rx buffer */ 65 | ec_bufT tempinbuf; 66 | /** temporary rx buffer status */ 67 | int tempinbufs; 68 | /** transmit buffers */ 69 | ec_bufT txbuf[EC_MAXBUF]; 70 | /** transmit buffer lengths */ 71 | int txbuflength[EC_MAXBUF]; 72 | /** temporary tx buffer */ 73 | ec_bufT txbuf2; 74 | /** temporary tx buffer length */ 75 | int txbuflength2; 76 | /** last used frame index */ 77 | uint8 lastidx; 78 | /** current redundancy state */ 79 | int redstate; 80 | /** pointer to redundancy port and buffers */ 81 | ecx_redportt *redport; 82 | mtx_t *getindex_mutex; 83 | mtx_t *tx_mutex; 84 | mtx_t *rx_mutex; 85 | } ecx_portt; 86 | 87 | extern const uint16 priMAC[3]; 88 | extern const uint16 secMAC[3]; 89 | 90 | void ec_setupheader(void *p); 91 | int ecx_setupnic(ecx_portt *port, const char *ifname, int secondary); 92 | int ecx_closenic(ecx_portt *port); 93 | void ecx_setbufstat(ecx_portt *port, uint8 idx, int bufstat); 94 | uint8 ecx_getindex(ecx_portt *port); 95 | int ecx_outframe(ecx_portt *port, uint8 idx, int stacknumber); 96 | int ecx_outframe_red(ecx_portt *port, uint8 idx); 97 | int ecx_waitinframe(ecx_portt *port, uint8 idx, int timeout); 98 | int ecx_srconfirm(ecx_portt *port, uint8 idx, int timeout); 99 | 100 | #endif 101 | -------------------------------------------------------------------------------- /contrib/oshw/erika/nicdrv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is dual-licensed under GPLv3 and a commercial 3 | * license. See the file LICENSE.md distributed with this software for 4 | * full license information. 5 | */ 6 | 7 | /** \file 8 | * \brief 9 | * Headerfile for nicdrv.c 10 | */ 11 | 12 | #ifndef _nicdrvh_ 13 | #define _nicdrvh_ 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | typedef struct 20 | { 21 | /** socket connection used */ 22 | int *sock; 23 | /** tx buffer */ 24 | ec_bufT (*txbuf)[EC_MAXBUF]; 25 | /** tx buffer lengths */ 26 | int (*txbuflength)[EC_MAXBUF]; 27 | /** temporary receive buffer */ 28 | ec_bufT *tempbuf; 29 | /** rx buffers */ 30 | ec_bufT (*rxbuf)[EC_MAXBUF]; 31 | /** rx buffer status fields */ 32 | int (*rxbufstat)[EC_MAXBUF]; 33 | /** received MAC source address (middle word) */ 34 | int (*rxsa)[EC_MAXBUF]; 35 | } ec_stackT; 36 | 37 | /** pointer structure to buffers for redundant port */ 38 | typedef struct 39 | { 40 | ec_stackT stack; 41 | int sockhandle; 42 | /** rx buffers */ 43 | ec_bufT rxbuf[EC_MAXBUF]; 44 | /** rx buffer status */ 45 | int rxbufstat[EC_MAXBUF]; 46 | /** rx MAC source address */ 47 | int rxsa[EC_MAXBUF]; 48 | /** temporary rx buffer */ 49 | ec_bufT tempinbuf; 50 | } ecx_redportt; 51 | 52 | /** pointer structure to buffers, vars and mutexes for port instantiation */ 53 | typedef struct 54 | { 55 | ec_stackT stack; 56 | int sockhandle; 57 | /** rx buffers */ 58 | ec_bufT rxbuf[EC_MAXBUF]; 59 | /** rx buffer status */ 60 | int rxbufstat[EC_MAXBUF]; 61 | /** rx MAC source address */ 62 | int rxsa[EC_MAXBUF]; 63 | /** temporary rx buffer */ 64 | ec_bufT tempinbuf; 65 | /** temporary rx buffer status */ 66 | int tempinbufs; 67 | /** transmit buffers */ 68 | ec_bufT txbuf[EC_MAXBUF]; 69 | /** transmit buffer lengths */ 70 | int txbuflength[EC_MAXBUF]; 71 | /** temporary tx buffer */ 72 | ec_bufT txbuf2; 73 | /** temporary tx buffer length */ 74 | int txbuflength2; 75 | /** last used frame index */ 76 | uint8 lastidx; 77 | /** current redundancy state */ 78 | int redstate; 79 | /** pointer to redundancy port and buffers */ 80 | ecx_redportt *redport; 81 | 82 | /** Device id in the device pool */ 83 | int dev_id; 84 | 85 | // TODO: add mutex support 86 | } ecx_portt; 87 | 88 | extern const uint16 priMAC[3]; 89 | extern const uint16 secMAC[3]; 90 | 91 | void ec_setupheader(void *p); 92 | int ecx_setupnic(ecx_portt *port, const char *ifname, int secondary); 93 | int ecx_closenic(ecx_portt *port); 94 | void ecx_setbufstat(ecx_portt *port, uint8 idx, int bufstat); 95 | uint8 ecx_getindex(ecx_portt *port); 96 | int ecx_outframe(ecx_portt *port, uint8 idx, int sock); 97 | int ecx_outframe_red(ecx_portt *port, uint8 idx); 98 | int ecx_waitinframe(ecx_portt *port, uint8 idx, int timeout); 99 | int ecx_srconfirm(ecx_portt *port, uint8 idx, int timeout); 100 | 101 | int ecx_inframe(ecx_portt *port, uint8 idx, int stacknumber); 102 | 103 | #ifdef __cplusplus 104 | } 105 | #endif 106 | 107 | #endif 108 | -------------------------------------------------------------------------------- /contrib/oshw/rtems/nicdrv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is dual-licensed under GPLv3 and a commercial 3 | * license. See the file LICENSE.md distributed with this software for 4 | * full license information. 5 | */ 6 | 7 | /** \file 8 | * \brief 9 | * Headerfile for nicdrv.c 10 | */ 11 | 12 | #ifndef _nicdrvh_ 13 | #define _nicdrvh_ 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | #include 20 | 21 | /** pointer structure to Tx and Rx stacks */ 22 | typedef struct 23 | { 24 | /** socket connection used */ 25 | int *sock; 26 | /** tx buffer */ 27 | ec_bufT (*txbuf)[EC_MAXBUF]; 28 | /** tx buffer lengths */ 29 | int (*txbuflength)[EC_MAXBUF]; 30 | /** temporary receive buffer */ 31 | ec_bufT *tempbuf; 32 | /** rx buffers */ 33 | ec_bufT (*rxbuf)[EC_MAXBUF]; 34 | /** rx buffer status fields */ 35 | int (*rxbufstat)[EC_MAXBUF]; 36 | /** received MAC source address (middle word) */ 37 | int (*rxsa)[EC_MAXBUF]; 38 | } ec_stackT; 39 | 40 | /** pointer structure to buffers for redundant port */ 41 | typedef struct 42 | { 43 | ec_stackT stack; 44 | int sockhandle; 45 | /** rx buffers */ 46 | ec_bufT rxbuf[EC_MAXBUF]; 47 | /** rx buffer status */ 48 | int rxbufstat[EC_MAXBUF]; 49 | /** rx MAC source address */ 50 | int rxsa[EC_MAXBUF]; 51 | /** temporary rx buffer */ 52 | ec_bufT tempinbuf; 53 | } ecx_redportt; 54 | 55 | /** pointer structure to buffers, vars and mutexes for port instantiation */ 56 | typedef struct 57 | { 58 | ec_stackT stack; 59 | int sockhandle; 60 | /** rx buffers */ 61 | ec_bufT rxbuf[EC_MAXBUF]; 62 | /** rx buffer status */ 63 | int rxbufstat[EC_MAXBUF]; 64 | /** rx MAC source address */ 65 | int rxsa[EC_MAXBUF]; 66 | /** temporary rx buffer */ 67 | ec_bufT tempinbuf; 68 | /** temporary rx buffer status */ 69 | int tempinbufs; 70 | /** transmit buffers */ 71 | ec_bufT txbuf[EC_MAXBUF]; 72 | /** transmit buffer lengths */ 73 | int txbuflength[EC_MAXBUF]; 74 | /** temporary tx buffer */ 75 | ec_bufT txbuf2; 76 | /** temporary tx buffer length */ 77 | int txbuflength2; 78 | /** last used frame index */ 79 | uint8 lastidx; 80 | /** current redundancy state */ 81 | int redstate; 82 | /** pointer to redundancy port and buffers */ 83 | ecx_redportt *redport; 84 | pthread_mutex_t getindex_mutex; 85 | pthread_mutex_t tx_mutex; 86 | pthread_mutex_t rx_mutex; 87 | } ecx_portt; 88 | 89 | extern const uint16 priMAC[3]; 90 | extern const uint16 secMAC[3]; 91 | 92 | void ec_setupheader(void *p); 93 | int ecx_setupnic(ecx_portt *port, const char *ifname, int secondary); 94 | int ecx_closenic(ecx_portt *port); 95 | void ecx_setbufstat(ecx_portt *port, uint8 idx, int bufstat); 96 | uint8 ecx_getindex(ecx_portt *port); 97 | int ecx_outframe(ecx_portt *port, uint8 idx, int sock); 98 | int ecx_outframe_red(ecx_portt *port, uint8 idx); 99 | int ecx_waitinframe(ecx_portt *port, uint8 idx, int timeout); 100 | int ecx_srconfirm(ecx_portt *port, uint8 idx, int timeout); 101 | 102 | #ifdef __cplusplus 103 | } 104 | #endif 105 | 106 | #endif 107 | -------------------------------------------------------------------------------- /contrib/oshw/macosx/nicdrv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is dual-licensed under GPLv3 and a commercial 3 | * license. See the file LICENSE.md distributed with this software for 4 | * full license information. 5 | */ 6 | 7 | /** \file 8 | * \brief 9 | * Headerfile for nicdrv.c 10 | */ 11 | 12 | #ifndef _nicdrvh_ 13 | #define _nicdrvh_ 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | #include 20 | 21 | /** pointer structure to Tx and Rx stacks */ 22 | typedef struct 23 | { 24 | /** socket connection used */ 25 | pcap_t **sock; 26 | /** tx buffer */ 27 | ec_bufT (*txbuf)[EC_MAXBUF]; 28 | /** tx buffer lengths */ 29 | int (*txbuflength)[EC_MAXBUF]; 30 | /** temporary receive buffer */ 31 | ec_bufT *tempbuf; 32 | /** rx buffers */ 33 | ec_bufT (*rxbuf)[EC_MAXBUF]; 34 | /** rx buffer status fields */ 35 | int (*rxbufstat)[EC_MAXBUF]; 36 | /** received MAC source address (middle word) */ 37 | int (*rxsa)[EC_MAXBUF]; 38 | } ec_stackT; 39 | 40 | /** pointer structure to buffers for redundant port */ 41 | typedef struct 42 | { 43 | ec_stackT stack; 44 | pcap_t *sockhandle; 45 | /** rx buffers */ 46 | ec_bufT rxbuf[EC_MAXBUF]; 47 | /** rx buffer status */ 48 | int rxbufstat[EC_MAXBUF]; 49 | /** rx MAC source address */ 50 | int rxsa[EC_MAXBUF]; 51 | /** temporary rx buffer */ 52 | ec_bufT tempinbuf; 53 | } ecx_redportt; 54 | 55 | /** pointer structure to buffers, vars and mutexes for port instantiation */ 56 | typedef struct 57 | { 58 | ec_stackT stack; 59 | pcap_t *sockhandle; 60 | /** rx buffers */ 61 | ec_bufT rxbuf[EC_MAXBUF]; 62 | /** rx buffer status */ 63 | int rxbufstat[EC_MAXBUF]; 64 | /** rx MAC source address */ 65 | int rxsa[EC_MAXBUF]; 66 | /** temporary rx buffer */ 67 | ec_bufT tempinbuf; 68 | /** temporary rx buffer status */ 69 | int tempinbufs; 70 | /** transmit buffers */ 71 | ec_bufT txbuf[EC_MAXBUF]; 72 | /** transmit buffer lenghts */ 73 | int txbuflength[EC_MAXBUF]; 74 | /** temporary tx buffer */ 75 | ec_bufT txbuf2; 76 | /** temporary tx buffer length */ 77 | int txbuflength2; 78 | /** last used frame index */ 79 | uint8 lastidx; 80 | /** current redundancy state */ 81 | int redstate; 82 | /** pointer to redundancy port and buffers */ 83 | ecx_redportt *redport; 84 | pthread_mutex_t getindex_mutex; 85 | pthread_mutex_t tx_mutex; 86 | pthread_mutex_t rx_mutex; 87 | } ecx_portt; 88 | 89 | extern const uint16 priMAC[3]; 90 | extern const uint16 secMAC[3]; 91 | 92 | void ec_setupheader(void *p); 93 | int ecx_setupnic(ecx_portt *port, const char *ifname, int secondary); 94 | int ecx_closenic(ecx_portt *port); 95 | void ecx_setbufstat(ecx_portt *port, uint8 idx, int bufstat); 96 | uint8 ecx_getindex(ecx_portt *port); 97 | int ecx_outframe(ecx_portt *port, uint8 idx, int sock); 98 | int ecx_outframe_red(ecx_portt *port, uint8 idx); 99 | int ecx_waitinframe(ecx_portt *port, uint8 idx, int timeout); 100 | int ecx_srconfirm(ecx_portt *port, uint8 idx, int timeout); 101 | 102 | #ifdef __cplusplus 103 | } 104 | #endif 105 | 106 | #endif 107 | -------------------------------------------------------------------------------- /oshw/linux/nicdrv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is dual-licensed under GPLv3 and a commercial 3 | * license. See the file LICENSE.md distributed with this software for 4 | * full license information. 5 | */ 6 | 7 | /** \file 8 | * \brief 9 | * Headerfile for nicdrv.c 10 | */ 11 | 12 | #ifndef _nicdrvh_ 13 | #define _nicdrvh_ 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | #include 20 | 21 | /** pointer structure to Tx and Rx stacks */ 22 | typedef struct 23 | { 24 | /** socket connection used */ 25 | int *sock; 26 | /** tx buffer */ 27 | ec_bufT (*txbuf)[EC_MAXBUF]; 28 | /** tx buffer lengths */ 29 | int (*txbuflength)[EC_MAXBUF]; 30 | /** temporary receive buffer */ 31 | ec_bufT *tempbuf; 32 | /** rx buffers */ 33 | ec_bufT (*rxbuf)[EC_MAXBUF]; 34 | /** rx buffer status fields */ 35 | int (*rxbufstat)[EC_MAXBUF]; 36 | /** received MAC source address (middle word) */ 37 | int (*rxsa)[EC_MAXBUF]; 38 | /** number of received frames */ 39 | uint64 rxcnt; 40 | } ec_stackT; 41 | 42 | /** pointer structure to buffers for redundant port */ 43 | typedef struct 44 | { 45 | ec_stackT stack; 46 | int sockhandle; 47 | /** rx buffers */ 48 | ec_bufT rxbuf[EC_MAXBUF]; 49 | /** rx buffer status */ 50 | int rxbufstat[EC_MAXBUF]; 51 | /** rx MAC source address */ 52 | int rxsa[EC_MAXBUF]; 53 | /** temporary rx buffer */ 54 | ec_bufT tempinbuf; 55 | } ecx_redportt; 56 | 57 | /** pointer structure to buffers, vars and mutexes for port instantiation */ 58 | typedef struct 59 | { 60 | ec_stackT stack; 61 | int sockhandle; 62 | /** rx buffers */ 63 | ec_bufT rxbuf[EC_MAXBUF]; 64 | /** rx buffer status */ 65 | int rxbufstat[EC_MAXBUF]; 66 | /** rx MAC source address */ 67 | int rxsa[EC_MAXBUF]; 68 | /** temporary rx buffer */ 69 | ec_bufT tempinbuf; 70 | /** temporary rx buffer status */ 71 | int tempinbufs; 72 | /** transmit buffers */ 73 | ec_bufT txbuf[EC_MAXBUF]; 74 | /** transmit buffer lengths */ 75 | int txbuflength[EC_MAXBUF]; 76 | /** temporary tx buffer */ 77 | ec_bufT txbuf2; 78 | /** temporary tx buffer length */ 79 | int txbuflength2; 80 | /** last used frame index */ 81 | uint8 lastidx; 82 | /** current redundancy state */ 83 | int redstate; 84 | /** pointer to redundancy port and buffers */ 85 | ecx_redportt *redport; 86 | pthread_mutex_t getindex_mutex; 87 | pthread_mutex_t tx_mutex; 88 | pthread_mutex_t rx_mutex; 89 | } ecx_portt; 90 | 91 | extern const uint16 priMAC[3]; 92 | extern const uint16 secMAC[3]; 93 | 94 | void ec_setupheader(void *p); 95 | int ecx_setupnic(ecx_portt *port, const char *ifname, int secondary); 96 | int ecx_closenic(ecx_portt *port); 97 | void ecx_setbufstat(ecx_portt *port, uint8 idx, int bufstat); 98 | uint8 ecx_getindex(ecx_portt *port); 99 | int ecx_outframe(ecx_portt *port, uint8 idx, int sock); 100 | int ecx_outframe_red(ecx_portt *port, uint8 idx); 101 | int ecx_waitinframe(ecx_portt *port, uint8 idx, int timeout); 102 | int ecx_srconfirm(ecx_portt *port, uint8 idx, int timeout); 103 | 104 | #ifdef __cplusplus 105 | } 106 | #endif 107 | 108 | #endif 109 | -------------------------------------------------------------------------------- /oshw/win32/wpcap/Include/pcap-stdinc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002 - 2005 NetGroup, Politecnico di Torino (Italy) 3 | * Copyright (c) 2005 - 2009 CACE Technologies, Inc. Davis (California) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 3. Neither the name of the Politecnico di Torino nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | * @(#) $Header: /tcpdump/master/libpcap/pcap-stdinc.h,v 1.10.2.1 2008-10-06 15:38:39 gianluca Exp $ (LBL) 32 | */ 33 | 34 | #define SIZEOF_CHAR 1 35 | #define SIZEOF_SHORT 2 36 | #define SIZEOF_INT 4 37 | #ifndef _MSC_EXTENSIONS 38 | #define SIZEOF_LONG_LONG 8 39 | #endif 40 | 41 | /* 42 | * Avoids a compiler warning in case this was already defined 43 | * (someone defined _WINSOCKAPI_ when including 'windows.h', in order 44 | * to prevent it from including 'winsock.h') 45 | */ 46 | #ifdef _WINSOCKAPI_ 47 | #undef _WINSOCKAPI_ 48 | #endif 49 | #include 50 | 51 | #include 52 | 53 | #include "bittypes.h" 54 | #include 55 | #include 56 | 57 | #ifndef __MINGW32__ 58 | #include "IP6_misc.h" 59 | #endif 60 | 61 | #define caddr_t char* 62 | 63 | #if _MSC_VER < 1500 64 | #define snprintf _snprintf 65 | #define vsnprintf _vsnprintf 66 | #define strdup _strdup 67 | #endif 68 | 69 | #define inline __inline 70 | 71 | #ifdef __MINGW32__ 72 | #include 73 | #else /*__MINGW32__*/ 74 | /* MSVC compiler */ 75 | #ifndef _UINTPTR_T_DEFINED 76 | #ifdef _WIN64 77 | typedef unsigned __int64 uintptr_t; 78 | #else 79 | typedef _W64 unsigned int uintptr_t; 80 | #endif 81 | #define _UINTPTR_T_DEFINED 82 | #endif 83 | 84 | #ifndef _INTPTR_T_DEFINED 85 | #ifdef _WIN64 86 | typedef __int64 intptr_t; 87 | #else 88 | typedef _W64 int intptr_t; 89 | #endif 90 | #define _INTPTR_T_DEFINED 91 | #endif 92 | 93 | #endif /*__MINGW32__*/ 94 | -------------------------------------------------------------------------------- /oshw/win32/wpcap/Include/pcap/usb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006 Paolo Abeni (Italy) 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. The name of the author may not be used to endorse or promote 15 | * products derived from this software without specific prior written 16 | * permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | * Basic USB data struct 31 | * By Paolo Abeni 32 | * 33 | * @(#) $Header: /tcpdump/master/libpcap/pcap/usb.h,v 1.6 2007/09/22 02:06:08 guy Exp $ 34 | */ 35 | 36 | #ifndef _PCAP_USB_STRUCTS_H__ 37 | #define _PCAP_USB_STRUCTS_H__ 38 | 39 | /* 40 | * possible transfer mode 41 | */ 42 | #define URB_TRANSFER_IN 0x80 43 | #define URB_ISOCHRONOUS 0x0 44 | #define URB_INTERRUPT 0x1 45 | #define URB_CONTROL 0x2 46 | #define URB_BULK 0x3 47 | 48 | /* 49 | * possible event type 50 | */ 51 | #define URB_SUBMIT 'S' 52 | #define URB_COMPLETE 'C' 53 | #define URB_ERROR 'E' 54 | 55 | /* 56 | * USB setup header as defined in USB specification. 57 | * Appears at the front of each packet in DLT_USB captures. 58 | */ 59 | typedef struct _usb_setup { 60 | u_int8_t bmRequestType; 61 | u_int8_t bRequest; 62 | u_int16_t wValue; 63 | u_int16_t wIndex; 64 | u_int16_t wLength; 65 | } pcap_usb_setup; 66 | 67 | 68 | /* 69 | * Header prepended by linux kernel to each event. 70 | * Appears at the front of each packet in DLT_USB_LINUX captures. 71 | */ 72 | typedef struct _usb_header { 73 | u_int64_t id; 74 | u_int8_t event_type; 75 | u_int8_t transfer_type; 76 | u_int8_t endpoint_number; 77 | u_int8_t device_address; 78 | u_int16_t bus_id; 79 | char setup_flag;/*if !=0 the urb setup header is not present*/ 80 | char data_flag; /*if !=0 no urb data is present*/ 81 | int64_t ts_sec; 82 | int32_t ts_usec; 83 | int32_t status; 84 | u_int32_t urb_len; 85 | u_int32_t data_len; /* amount of urb data really present in this event*/ 86 | pcap_usb_setup setup; 87 | } pcap_usb_header; 88 | 89 | 90 | #endif 91 | -------------------------------------------------------------------------------- /oshw/win32/nicdrv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is dual-licensed under GPLv3 and a commercial 3 | * license. See the file LICENSE.md distributed with this software for 4 | * full license information. 5 | */ 6 | 7 | /** \file 8 | * \brief 9 | * Headerfile for nicdrv.c 10 | */ 11 | 12 | #ifndef _nicdrvh_ 13 | #define _nicdrvh_ 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | #define HAVE_REMOTE 20 | 21 | #include 22 | #include 23 | 24 | /** pointer structure to Tx and Rx stacks */ 25 | typedef struct 26 | { 27 | /** socket connection used */ 28 | pcap_t **sock; 29 | /** tx buffer */ 30 | ec_bufT (*txbuf)[EC_MAXBUF]; 31 | /** tx buffer lengths */ 32 | int (*txbuflength)[EC_MAXBUF]; 33 | /** temporary receive buffer */ 34 | ec_bufT *tempbuf; 35 | /** rx buffers */ 36 | ec_bufT (*rxbuf)[EC_MAXBUF]; 37 | /** rx buffer status fields */ 38 | int (*rxbufstat)[EC_MAXBUF]; 39 | /** received MAC source address (middle word) */ 40 | int (*rxsa)[EC_MAXBUF]; 41 | /** number of received frames */ 42 | uint64 rxcnt; 43 | } ec_stackT; 44 | 45 | /** pointer structure to buffers for redundant port */ 46 | typedef struct 47 | { 48 | ec_stackT stack; 49 | pcap_t *sockhandle; 50 | /** rx buffers */ 51 | ec_bufT rxbuf[EC_MAXBUF]; 52 | /** rx buffer status */ 53 | int rxbufstat[EC_MAXBUF]; 54 | /** rx MAC source address */ 55 | int rxsa[EC_MAXBUF]; 56 | /** temporary rx buffer */ 57 | ec_bufT tempinbuf; 58 | } ecx_redportt; 59 | 60 | /** pointer structure to buffers, vars and mutexes for port instantiation */ 61 | typedef struct 62 | { 63 | ec_stackT stack; 64 | pcap_t *sockhandle; 65 | /** rx buffers */ 66 | ec_bufT rxbuf[EC_MAXBUF]; 67 | /** rx buffer status */ 68 | int rxbufstat[EC_MAXBUF]; 69 | /** rx MAC source address */ 70 | int rxsa[EC_MAXBUF]; 71 | /** temporary rx buffer */ 72 | ec_bufT tempinbuf; 73 | /** temporary rx buffer status */ 74 | int tempinbufs; 75 | /** transmit buffers */ 76 | ec_bufT txbuf[EC_MAXBUF]; 77 | /** transmit buffer lengths */ 78 | int txbuflength[EC_MAXBUF]; 79 | /** temporary tx buffer */ 80 | ec_bufT txbuf2; 81 | /** temporary tx buffer length */ 82 | int txbuflength2; 83 | /** last used frame index */ 84 | uint8 lastidx; 85 | /** current redundancy state */ 86 | int redstate; 87 | /** pointer to redundancy port and buffers */ 88 | ecx_redportt *redport; 89 | CRITICAL_SECTION getindex_mutex; 90 | CRITICAL_SECTION tx_mutex; 91 | CRITICAL_SECTION rx_mutex; 92 | } ecx_portt; 93 | 94 | extern const uint16 priMAC[3]; 95 | extern const uint16 secMAC[3]; 96 | 97 | void ec_setupheader(void *p); 98 | int ecx_setupnic(ecx_portt *port, const char *ifname, int secondary); 99 | int ecx_closenic(ecx_portt *port); 100 | void ecx_setbufstat(ecx_portt *port, uint8 idx, int bufstat); 101 | uint8 ecx_getindex(ecx_portt *port); 102 | int ecx_outframe(ecx_portt *port, uint8 idx, int sock); 103 | int ecx_outframe_red(ecx_portt *port, uint8 idx); 104 | int ecx_waitinframe(ecx_portt *port, uint8 idx, int timeout); 105 | int ecx_srconfirm(ecx_portt *port, uint8 idx, int timeout); 106 | 107 | #ifdef __cplusplus 108 | } 109 | #endif 110 | 111 | #endif 112 | -------------------------------------------------------------------------------- /oshw/linux/oshw.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is dual-licensed under GPLv3 and a commercial 3 | * license. See the file LICENSE.md distributed with this software for 4 | * full license information. 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include "oshw.h" 14 | 15 | /** 16 | * Host to Network byte order (i.e. to big endian). 17 | * 18 | * Note that Ethercat uses little endian byte order, except for the Ethernet 19 | * header which is big endian as usual. 20 | */ 21 | uint16 oshw_htons(uint16 host) 22 | { 23 | uint16 network = htons(host); 24 | return network; 25 | } 26 | 27 | /** 28 | * Network (i.e. big endian) to Host byte order. 29 | * 30 | * Note that Ethercat uses little endian byte order, except for the Ethernet 31 | * header which is big endian as usual. 32 | */ 33 | uint16 oshw_ntohs(uint16 network) 34 | { 35 | uint16 host = ntohs(network); 36 | return host; 37 | } 38 | 39 | /** Create list over available network adapters. 40 | * @return First element in linked list of adapters 41 | */ 42 | ec_adaptert *oshw_find_adapters(void) 43 | { 44 | int i; 45 | struct if_nameindex *ids; 46 | ec_adaptert *adapter; 47 | ec_adaptert *prev_adapter = NULL; 48 | ec_adaptert *ret_adapter = NULL; 49 | 50 | /* Iterate all devices and create a local copy holding the name and 51 | * description. 52 | */ 53 | 54 | ids = if_nameindex(); 55 | for (i = 0; ids[i].if_index != 0; i++) 56 | { 57 | adapter = (ec_adaptert *)malloc(sizeof(ec_adaptert)); 58 | /* If we got more than one adapter save link list pointer to previous 59 | * adapter. 60 | * Else save as pointer to return. 61 | */ 62 | if (prev_adapter) 63 | { 64 | prev_adapter->next = adapter; 65 | } 66 | else 67 | { 68 | ret_adapter = adapter; 69 | } 70 | 71 | /* fetch description and name, in Linux we use the same on both */ 72 | adapter->next = NULL; 73 | 74 | if (ids[i].if_name) 75 | { 76 | strncpy(adapter->name, ids[i].if_name, EC_MAXLEN_ADAPTERNAME - 1); 77 | adapter->name[EC_MAXLEN_ADAPTERNAME - 1] = '\0'; 78 | strncpy(adapter->desc, ids[i].if_name, EC_MAXLEN_ADAPTERNAME - 1); 79 | adapter->desc[EC_MAXLEN_ADAPTERNAME - 1] = '\0'; 80 | } 81 | else 82 | { 83 | adapter->name[0] = '\0'; 84 | adapter->desc[0] = '\0'; 85 | } 86 | 87 | prev_adapter = adapter; 88 | } 89 | 90 | if_freenameindex(ids); 91 | 92 | return ret_adapter; 93 | } 94 | 95 | /** Free memory allocated memory used by adapter collection. 96 | * @param[in] adapter = First element in linked list of adapters 97 | * EC_NOFRAME. 98 | */ 99 | void oshw_free_adapters(ec_adaptert *adapter) 100 | { 101 | ec_adaptert *next_adapter; 102 | /* Iterate the linked list and free all elements holding 103 | * adapter information 104 | */ 105 | if (adapter) 106 | { 107 | next_adapter = adapter->next; 108 | free(adapter); 109 | while (next_adapter) 110 | { 111 | adapter = next_adapter; 112 | next_adapter = adapter->next; 113 | free(adapter); 114 | } 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /contrib/oshw/macosx/oshw.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is dual-licensed under GPLv3 and a commercial 3 | * license. See the file LICENSE.md distributed with this software for 4 | * full license information. 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include "oshw.h" 15 | 16 | /** 17 | * Host to Network byte order (i.e. to big endian). 18 | * 19 | * Note that Ethercat uses little endian byte order, except for the Ethernet 20 | * header which is big endian as usual. 21 | */ 22 | uint16 oshw_htons(uint16 host) 23 | { 24 | uint16 network = htons(host); 25 | return network; 26 | } 27 | 28 | /** 29 | * Network (i.e. big endian) to Host byte order. 30 | * 31 | * Note that Ethercat uses little endian byte order, except for the Ethernet 32 | * header which is big endian as usual. 33 | */ 34 | uint16 oshw_ntohs(uint16 network) 35 | { 36 | uint16 host = ntohs(network); 37 | return host; 38 | } 39 | 40 | /** Create list over available network adapters. 41 | * @return First element in linked list of adapters 42 | */ 43 | ec_adaptert *oshw_find_adapters(void) 44 | { 45 | int i; 46 | struct if_nameindex *ids; 47 | ec_adaptert *adapter; 48 | ec_adaptert *prev_adapter; 49 | ec_adaptert *ret_adapter = NULL; 50 | 51 | /* Iterate all devices and create a local copy holding the name and 52 | * description. 53 | */ 54 | 55 | ids = if_nameindex(); 56 | for (i = 0; ids[i].if_index != 0; i++) 57 | { 58 | adapter = (ec_adaptert *)malloc(sizeof(ec_adaptert)); 59 | /* If we got more than one adapter save link list pointer to previous 60 | * adapter. 61 | * Else save as pointer to return. 62 | */ 63 | if (i) 64 | { 65 | prev_adapter->next = adapter; 66 | } 67 | else 68 | { 69 | ret_adapter = adapter; 70 | } 71 | 72 | /* fetch description and name, in macosx we use the same on both */ 73 | adapter->next = NULL; 74 | 75 | if (ids[i].if_name) 76 | { 77 | strncpy(adapter->name, ids[i].if_name, EC_MAXLEN_ADAPTERNAME); 78 | adapter->name[EC_MAXLEN_ADAPTERNAME - 1] = '\0'; 79 | strncpy(adapter->desc, ids[i].if_name, EC_MAXLEN_ADAPTERNAME); 80 | adapter->desc[EC_MAXLEN_ADAPTERNAME - 1] = '\0'; 81 | } 82 | else 83 | { 84 | adapter->name[0] = '\0'; 85 | adapter->desc[0] = '\0'; 86 | } 87 | 88 | prev_adapter = adapter; 89 | } 90 | 91 | if_freenameindex(ids); 92 | 93 | return ret_adapter; 94 | } 95 | 96 | /** Free memory allocated memory used by adapter collection. 97 | * @param[in] adapter = First element in linked list of adapters 98 | * EC_NOFRAME. 99 | */ 100 | void oshw_free_adapters(ec_adaptert *adapter) 101 | { 102 | ec_adaptert *next_adapter; 103 | /* Iterate the linked list and free all elements holding 104 | * adapter information 105 | */ 106 | if (adapter) 107 | { 108 | next_adapter = adapter->next; 109 | free(adapter); 110 | while (next_adapter) 111 | { 112 | adapter = next_adapter; 113 | next_adapter = adapter->next; 114 | free(adapter); 115 | } 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /contrib/oshw/rtems/oshw.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is dual-licensed under GPLv3 and a commercial 3 | * license. See the file LICENSE.md distributed with this software for 4 | * full license information. 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include "oshw.h" 15 | 16 | /** 17 | * Host to Network byte order (i.e. to big endian). 18 | * 19 | * Note that Ethercat uses little endian byte order, except for the Ethernet 20 | * header which is big endian as usual. 21 | */ 22 | uint16 oshw_htons(uint16 host) 23 | { 24 | uint16 network = htons(host); 25 | return network; 26 | } 27 | 28 | /** 29 | * Network (i.e. big endian) to Host byte order. 30 | * 31 | * Note that Ethercat uses little endian byte order, except for the Ethernet 32 | * header which is big endian as usual. 33 | */ 34 | uint16 oshw_ntohs(uint16 network) 35 | { 36 | uint16 host = ntohs(network); 37 | return host; 38 | } 39 | 40 | /** Create list over available network adapters. 41 | * @return First element in linked list of adapters 42 | */ 43 | ec_adaptert *oshw_find_adapters(void) 44 | { 45 | int i; 46 | struct if_nameindex *ids; 47 | ec_adaptert *adapter; 48 | ec_adaptert *prev_adapter; 49 | ec_adaptert *ret_adapter = NULL; 50 | 51 | /* Iterate all devices and create a local copy holding the name and 52 | * description. 53 | */ 54 | 55 | ids = if_nameindex(); 56 | for (i = 0; ids[i].if_index != 0; i++) 57 | { 58 | adapter = (ec_adaptert *)malloc(sizeof(ec_adaptert)); 59 | /* If we got more than one adapter save link list pointer to previous 60 | * adapter. 61 | * Else save as pointer to return. 62 | */ 63 | if (i) 64 | { 65 | prev_adapter->next = adapter; 66 | } 67 | else 68 | { 69 | ret_adapter = adapter; 70 | } 71 | 72 | /* fetch description and name, in rtems we use the same on both */ 73 | adapter->next = NULL; 74 | 75 | if (ids[i].if_name) 76 | { 77 | strncpy(adapter->name, ids[i].if_name, EC_MAXLEN_ADAPTERNAME); 78 | adapter->name[EC_MAXLEN_ADAPTERNAME - 1] = '\0'; 79 | strncpy(adapter->desc, ids[i].if_name, EC_MAXLEN_ADAPTERNAME); 80 | adapter->desc[EC_MAXLEN_ADAPTERNAME - 1] = '\0'; 81 | } 82 | else 83 | { 84 | adapter->name[0] = '\0'; 85 | adapter->desc[0] = '\0'; 86 | } 87 | 88 | prev_adapter = adapter; 89 | } 90 | 91 | if_freenameindex(ids); 92 | 93 | return ret_adapter; 94 | } 95 | 96 | /** Free memory allocated memory used by adapter collection. 97 | * @param[in] adapter = First element in linked list of adapters 98 | * EC_NOFRAME. 99 | */ 100 | void oshw_free_adapters(ec_adaptert *adapter) 101 | { 102 | ec_adaptert *next_adapter; 103 | /* Iterate the linked list and free all elements holding 104 | * adapter information 105 | */ 106 | if (adapter) 107 | { 108 | next_adapter = adapter->next; 109 | free(adapter); 110 | while (next_adapter) 111 | { 112 | adapter = next_adapter; 113 | next_adapter = adapter->next; 114 | free(adapter); 115 | } 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /oshw/win32/oshw.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is dual-licensed under GPLv3 and a commercial 3 | * license. See the file LICENSE.md distributed with this software for 4 | * full license information. 5 | */ 6 | 7 | #include "oshw.h" 8 | #include 9 | 10 | /** 11 | * Host to Network byte order (i.e. to big endian). 12 | * 13 | * Note that Ethercat uses little endian byte order, except for the Ethernet 14 | * header which is big endian as usual. 15 | */ 16 | uint16 oshw_htons(uint16 host) 17 | { 18 | uint16 network = htons(host); 19 | return network; 20 | } 21 | 22 | /** 23 | * Network (i.e. big endian) to Host byte order. 24 | * 25 | * Note that Ethercat uses little endian byte order, except for the Ethernet 26 | * header which is big endian as usual. 27 | */ 28 | uint16 oshw_ntohs(uint16 network) 29 | { 30 | uint16 host = ntohs(network); 31 | return host; 32 | } 33 | 34 | /* Create list over available network adapters. 35 | * @return First element in linked list of adapters 36 | */ 37 | ec_adaptert *oshw_find_adapters(void) 38 | { 39 | pcap_if_t *alldevs; 40 | pcap_if_t *d; 41 | ec_adaptert *adapter; 42 | ec_adaptert *prev_adapter = NULL; 43 | ec_adaptert *ret_adapter = NULL; 44 | char errbuf[PCAP_ERRBUF_SIZE]; 45 | 46 | /* find all devices */ 47 | if (pcap_findalldevs(&alldevs, errbuf) == -1) 48 | { 49 | fprintf(stderr, "Error in pcap_findalldevs_ex: %s\n", errbuf); 50 | return (NULL); 51 | } 52 | /* Iterate all devices and create a local copy holding the name and 53 | * description. 54 | */ 55 | for (d = alldevs; d != NULL; d = d->next) 56 | { 57 | adapter = (ec_adaptert *)malloc(sizeof(ec_adaptert)); 58 | /* If we got more than one adapter save link list pointer to previous 59 | * adapter. 60 | * Else save as pointer to return. 61 | */ 62 | if (prev_adapter) 63 | { 64 | prev_adapter->next = adapter; 65 | } 66 | else 67 | { 68 | ret_adapter = adapter; 69 | } 70 | 71 | /* fetch description and name of the device from libpcap */ 72 | adapter->next = NULL; 73 | if (d->name) 74 | { 75 | strncpy(adapter->name, d->name, EC_MAXLEN_ADAPTERNAME); 76 | adapter->name[EC_MAXLEN_ADAPTERNAME - 1] = '\0'; 77 | } 78 | else 79 | { 80 | adapter->name[0] = '\0'; 81 | } 82 | if (d->description) 83 | { 84 | strncpy(adapter->desc, d->description, EC_MAXLEN_ADAPTERNAME); 85 | adapter->desc[EC_MAXLEN_ADAPTERNAME - 1] = '\0'; 86 | } 87 | else 88 | { 89 | adapter->desc[0] = '\0'; 90 | } 91 | prev_adapter = adapter; 92 | } 93 | /* free all devices allocated */ 94 | pcap_freealldevs(alldevs); 95 | 96 | return ret_adapter; 97 | } 98 | 99 | /** Free memory allocated memory used by adapter collection. 100 | * @param[in] adapter = First element in linked list of adapters 101 | * EC_NOFRAME. 102 | */ 103 | void oshw_free_adapters(ec_adaptert *adapter) 104 | { 105 | ec_adaptert *next_adapter; 106 | /* Iterate the linked list and free all elements holding 107 | * adapter information 108 | */ 109 | if (adapter) 110 | { 111 | next_adapter = adapter->next; 112 | free(adapter); 113 | while (next_adapter) 114 | { 115 | adapter = next_adapter; 116 | next_adapter = adapter->next; 117 | free(adapter); 118 | } 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /contrib/oshw/vxworks/nicdrv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is dual-licensed under GPLv3 and a commercial 3 | * license. See the file LICENSE.md distributed with this software for 4 | * full license information. 5 | */ 6 | 7 | /** \file 8 | * \brief 9 | * Headerfile for nicdrv.c 10 | */ 11 | 12 | #ifndef _nicdrvh_ 13 | #define _nicdrvh_ 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | #include 20 | 21 | /** structure to connect EtherCAT stack and VxWorks device */ 22 | typedef struct ETHERCAT_PKT_DEV 23 | { 24 | struct ecx_port *port; 25 | void *pCookie; 26 | void *endObj; 27 | UINT32 redundant; 28 | UINT32 tx_count; 29 | UINT32 rx_count; 30 | UINT32 overrun_count; 31 | UINT32 abandoned_count; 32 | } ETHERCAT_PKT_DEV; 33 | 34 | /** pointer structure to Tx and Rx stacks */ 35 | typedef struct 36 | { 37 | /** tx buffer */ 38 | ec_bufT (*txbuf)[EC_MAXBUF]; 39 | /** tx buffer lengths */ 40 | int (*txbuflength)[EC_MAXBUF]; 41 | /** rx buffers */ 42 | ec_bufT (*rxbuf)[EC_MAXBUF]; 43 | /** rx buffer status fields */ 44 | int (*rxbufstat)[EC_MAXBUF]; 45 | /** received MAC source address (middle word) */ 46 | int (*rxsa)[EC_MAXBUF]; 47 | } ec_stackT; 48 | 49 | /** pointer structure to buffers for redundant port */ 50 | typedef struct ecx_redport 51 | { 52 | /** Stack reference */ 53 | ec_stackT stack; 54 | /** Packet device instance */ 55 | ETHERCAT_PKT_DEV pktDev; 56 | /** rx buffers */ 57 | ec_bufT rxbuf[EC_MAXBUF]; 58 | /** rx buffer status */ 59 | int rxbufstat[EC_MAXBUF]; 60 | /** rx MAC source address */ 61 | int rxsa[EC_MAXBUF]; 62 | /** MSG Q for receive callbacks to post into */ 63 | MSG_Q_ID msgQId[EC_MAXBUF]; 64 | } ecx_redportt; 65 | 66 | /** pointer structure to buffers, vars and mutexes for port instantiation */ 67 | typedef struct ecx_port 68 | { 69 | /** Stack reference */ 70 | ec_stackT stack; 71 | /** Packet device instance */ 72 | ETHERCAT_PKT_DEV pktDev; 73 | /** rx buffers */ 74 | ec_bufT rxbuf[EC_MAXBUF]; 75 | /** rx buffer status */ 76 | int rxbufstat[EC_MAXBUF]; 77 | /** rx MAC source address */ 78 | int rxsa[EC_MAXBUF]; 79 | /** transmit buffers */ 80 | ec_bufT txbuf[EC_MAXBUF]; 81 | /** transmit buffer lengths */ 82 | int txbuflength[EC_MAXBUF]; 83 | /** temporary tx buffer */ 84 | ec_bufT txbuf2; 85 | /** temporary tx buffer length */ 86 | int txbuflength2; 87 | /** last used frame index */ 88 | uint8 lastidx; 89 | /** current redundancy state */ 90 | int redstate; 91 | /** pointer to redundancy port and buffers */ 92 | ecx_redportt *redport; 93 | /** Semaphore to protect single resources */ 94 | SEM_ID sem_get_index; 95 | /** MSG Q for receive callbacks to post into */ 96 | MSG_Q_ID msgQId[EC_MAXBUF]; 97 | } ecx_portt; 98 | 99 | extern const uint16 priMAC[3]; 100 | extern const uint16 secMAC[3]; 101 | 102 | void ec_setupheader(void *p); 103 | int ecx_setupnic(ecx_portt *port, const char *ifname, int secondary); 104 | int ecx_closenic(ecx_portt *port); 105 | void ecx_setbufstat(ecx_portt *port, uint8 idx, int bufstat); 106 | uint8 ecx_getindex(ecx_portt *port); 107 | int ecx_outframe(ecx_portt *port, uint8 idx, int sock); 108 | int ecx_outframe_red(ecx_portt *port, uint8 idx); 109 | int ecx_waitinframe(ecx_portt *port, uint8 idx, int timeout); 110 | int ecx_srconfirm(ecx_portt *port, uint8 idx, int timeout); 111 | 112 | #ifdef __cplusplus 113 | } 114 | #endif 115 | 116 | #endif 117 | -------------------------------------------------------------------------------- /contrib/oshw/intime/nicdrv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is dual-licensed under GPLv3 and a commercial 3 | * license. See the file LICENSE.md distributed with this software for 4 | * full license information. 5 | */ 6 | 7 | /** \file 8 | * \brief 9 | * Headerfile for nicdrv.c 10 | */ 11 | 12 | #ifndef _nicdrvh_ 13 | #define _nicdrvh_ 14 | 15 | #define HAVE_REMOTE 16 | 17 | #include 18 | #include "hpeif2.h" 19 | 20 | /** pointer structure to Tx and Rx stacks */ 21 | typedef struct 22 | { 23 | /** socket connection used */ 24 | int *sock; 25 | /** tx buffer */ 26 | ec_bufT (*txbuf)[EC_MAXBUF]; 27 | /** tx buffer lengths */ 28 | int (*txbuflength)[EC_MAXBUF]; 29 | /** temporary receive buffer */ 30 | ec_bufT *tempbuf; 31 | /** rx buffers */ 32 | ec_bufT (*rxbuf)[EC_MAXBUF]; 33 | /** rx buffer status fields */ 34 | int (*rxbufstat)[EC_MAXBUF]; 35 | /** received MAC source address (middle word) */ 36 | int (*rxsa)[EC_MAXBUF]; 37 | } ec_stackT; 38 | 39 | typedef struct 40 | { 41 | ec_stackT stack; 42 | /** rx buffers */ 43 | ec_bufT rxbuf[EC_MAXBUF]; 44 | /** rx buffer status */ 45 | int rxbufstat[EC_MAXBUF]; 46 | /** rx MAC source address */ 47 | int rxsa[EC_MAXBUF]; 48 | /** temporary rx buffer */ 49 | ec_bufT tempinbuf; 50 | /* Intime */ 51 | HPEHANDLE handle; 52 | HPERXBUFFERSET *rx_buffers; 53 | HPETXBUFFERSET *tx_buffers[EC_MAXBUF]; 54 | } ecx_redportt; 55 | 56 | typedef struct 57 | { 58 | ec_stackT stack; 59 | /** rx buffers */ 60 | ec_bufT rxbuf[EC_MAXBUF]; 61 | /** rx buffer status */ 62 | int rxbufstat[EC_MAXBUF]; 63 | /** rx MAC source address */ 64 | int rxsa[EC_MAXBUF]; 65 | /** temporary rx buffer */ 66 | ec_bufT tempinbuf; 67 | /** temporary rx buffer status */ 68 | int tempinbufs; 69 | /** transmit buffers */ 70 | ec_bufT txbuf[EC_MAXBUF]; 71 | /** transmit buffer lengths */ 72 | int txbuflength[EC_MAXBUF]; 73 | /** temporary tx buffer */ 74 | ec_bufT txbuf2; 75 | /** temporary tx buffer length */ 76 | int txbuflength2; 77 | /** last used frame index */ 78 | uint8 lastidx; 79 | /** current redundancy state */ 80 | int redstate; 81 | /** pointer to redundancy port and buffers */ 82 | ecx_redportt *redport; 83 | RTHANDLE getindex_region; 84 | RTHANDLE tx_region; 85 | RTHANDLE rx_region; 86 | /* Intime */ 87 | HPEHANDLE handle; 88 | HPERXBUFFERSET *rx_buffers; 89 | HPETXBUFFERSET *tx_buffers[EC_MAXBUF]; 90 | } ecx_portt; 91 | 92 | extern const uint16 priMAC[3]; 93 | extern const uint16 secMAC[3]; 94 | 95 | // extern ecx_portt ecx_port; 96 | // extern ecx_redportt ecx_redport; 97 | 98 | int ec_setupnic(const char *ifname, int secondary); 99 | int ec_closenic(void); 100 | void ec_setupheader(void *p); 101 | void ec_setbufstat(uint8 idx, int bufstat); 102 | uint8 ec_getindex(void); 103 | int ec_outframe(uint8 idx, int sock); 104 | int ec_outframe_red(uint8 idx); 105 | int ec_waitinframe(uint8 idx, int timeout); 106 | int ec_srconfirm(uint8 idx, int timeout); 107 | 108 | int ecx_setupnic(ecx_portt *port, const char *ifname, int secondary); 109 | int ecx_closenic(ecx_portt *port); 110 | void ecx_setbufstat(ecx_portt *port, uint8 idx, int bufstat); 111 | uint8 ecx_getindex(ecx_portt *port); 112 | int ecx_outframe(ecx_portt *port, uint8 idx, int sock); 113 | int ecx_outframe_red(ecx_portt *port, uint8 idx); 114 | int ecx_waitinframe(ecx_portt *port, uint8 idx, int timeout); 115 | int ecx_srconfirm(ecx_portt *port, uint8 idx, int timeout); 116 | 117 | #endif 118 | -------------------------------------------------------------------------------- /include/soem/ec_soe.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is dual-licensed under GPLv3 and a commercial 3 | * license. See the file LICENSE.md distributed with this software for 4 | * full license information. 5 | */ 6 | 7 | /** \file 8 | * \brief 9 | * Headerfile for ec_soe.c 10 | */ 11 | 12 | #ifndef _ec_soe_ 13 | #define _ec_soe_ 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | #define EC_SOE_DATASTATE_B 0x01 20 | #define EC_SOE_NAME_B 0x02 21 | #define EC_SOE_ATTRIBUTE_B 0x04 22 | #define EC_SOE_UNIT_B 0x08 23 | #define EC_SOE_MIN_B 0x10 24 | #define EC_SOE_MAX_B 0x20 25 | #define EC_SOE_VALUE_B 0x40 26 | #define EC_SOE_DEFAULT_B 0x80 27 | 28 | #define EC_IDN_MDTCONFIG 24 29 | #define EC_IDN_ATCONFIG 16 30 | 31 | /** SoE name structure */ 32 | OSAL_PACKED_BEGIN 33 | typedef struct OSAL_PACKED 34 | { 35 | /** current length in bytes of list */ 36 | uint16 currentlength; 37 | /** maximum length in bytes of list */ 38 | uint16 maxlength; 39 | char name[EC_SOE_MAXNAME]; 40 | } ec_SoEnamet; 41 | OSAL_PACKED_END 42 | 43 | /** SoE list structure */ 44 | OSAL_PACKED_BEGIN 45 | typedef struct OSAL_PACKED 46 | { 47 | /** current length in bytes of list */ 48 | uint16 currentlength; 49 | /** maximum length in bytes of list */ 50 | uint16 maxlength; 51 | union 52 | { 53 | uint8 byte[8]; 54 | uint16 word[4]; 55 | uint32 dword[2]; 56 | uint64 lword[1]; 57 | }; 58 | } ec_SoElistt; 59 | OSAL_PACKED_END 60 | 61 | /** SoE IDN mapping structure */ 62 | OSAL_PACKED_BEGIN 63 | typedef struct OSAL_PACKED 64 | { 65 | /** current length in bytes of list */ 66 | uint16 currentlength; 67 | /** maximum length in bytes of list */ 68 | uint16 maxlength; 69 | uint16 idn[EC_SOE_MAXMAPPING]; 70 | } ec_SoEmappingt; 71 | OSAL_PACKED_END 72 | 73 | #define EC_SOE_LENGTH_1 0x00 74 | #define EC_SOE_LENGTH_2 0x01 75 | #define EC_SOE_LENGTH_4 0x02 76 | #define EC_SOE_LENGTH_8 0x03 77 | #define EC_SOE_TYPE_BINARY 0x00 78 | #define EC_SOE_TYPE_UINT 0x01 79 | #define EC_SOE_TYPE_INT 0x02 80 | #define EC_SOE_TYPE_HEX 0x03 81 | #define EC_SOE_TYPE_STRING 0x04 82 | #define EC_SOE_TYPE_IDN 0x05 83 | #define EC_SOE_TYPE_FLOAT 0x06 84 | #define EC_SOE_TYPE_PARAMETER 0x07 85 | 86 | /** SoE attribute structure */ 87 | OSAL_PACKED_BEGIN 88 | typedef struct OSAL_PACKED 89 | { 90 | /** evaluation factor for display purposes */ 91 | uint32 evafactor : 16; 92 | /** length of IDN element(s) */ 93 | uint32 length : 2; 94 | /** IDN is list */ 95 | uint32 list : 1; 96 | /** IDN is command */ 97 | uint32 command : 1; 98 | /** datatype */ 99 | uint32 datatype : 3; 100 | uint32 reserved1 : 1; 101 | /** decimals to display if float datatype */ 102 | uint32 decimals : 4; 103 | /** write protected in pre-op */ 104 | uint32 wppreop : 1; 105 | /** write protected in safe-op */ 106 | uint32 wpsafeop : 1; 107 | /** write protected in op */ 108 | uint32 wpop : 1; 109 | uint32 reserved2 : 1; 110 | } ec_SoEattributet; 111 | OSAL_PACKED_END 112 | 113 | int ecx_SoEread(ecx_contextt *context, uint16 slave, uint8 driveNo, uint8 elementflags, uint16 idn, int *psize, void *p, int timeout); 114 | int ecx_SoEwrite(ecx_contextt *context, uint16 slave, uint8 driveNo, uint8 elementflags, uint16 idn, int psize, void *p, int timeout); 115 | int ecx_readIDNmap(ecx_contextt *context, uint16 slave, uint32 *Osize, uint32 *Isize); 116 | 117 | #ifdef __cplusplus 118 | } 119 | #endif 120 | 121 | #endif 122 | -------------------------------------------------------------------------------- /oshw/win32/wpcap/Include/pcap/namedb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1994, 1996 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. All advertising materials mentioning features or use of this software 14 | * must display the following acknowledgement: 15 | * This product includes software developed by the Computer Systems 16 | * Engineering Group at Lawrence Berkeley Laboratory. 17 | * 4. Neither the name of the University nor of the Laboratory may be used 18 | * to endorse or promote products derived from this software without 19 | * specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 | * SUCH DAMAGE. 32 | * 33 | * @(#) $Header: /tcpdump/master/libpcap/pcap/namedb.h,v 1.1 2006/10/04 18:09:22 guy Exp $ (LBL) 34 | */ 35 | 36 | #ifndef lib_pcap_namedb_h 37 | #define lib_pcap_namedb_h 38 | 39 | #ifdef __cplusplus 40 | extern "C" { 41 | #endif 42 | 43 | /* 44 | * As returned by the pcap_next_etherent() 45 | * XXX this stuff doesn't belong in this interface, but this 46 | * library already must do name to address translation, so 47 | * on systems that don't have support for /etc/ethers, we 48 | * export these hooks since they'll 49 | */ 50 | struct pcap_etherent { 51 | u_char addr[6]; 52 | char name[122]; 53 | }; 54 | #ifndef PCAP_ETHERS_FILE 55 | #define PCAP_ETHERS_FILE "/etc/ethers" 56 | #endif 57 | struct pcap_etherent *pcap_next_etherent(FILE *); 58 | u_char *pcap_ether_hostton(const char*); 59 | u_char *pcap_ether_aton(const char *); 60 | 61 | bpf_u_int32 **pcap_nametoaddr(const char *); 62 | #ifdef INET6 63 | struct addrinfo *pcap_nametoaddrinfo(const char *); 64 | #endif 65 | bpf_u_int32 pcap_nametonetaddr(const char *); 66 | 67 | int pcap_nametoport(const char *, int *, int *); 68 | int pcap_nametoportrange(const char *, int *, int *, int *); 69 | int pcap_nametoproto(const char *); 70 | int pcap_nametoeproto(const char *); 71 | int pcap_nametollc(const char *); 72 | /* 73 | * If a protocol is unknown, PROTO_UNDEF is returned. 74 | * Also, pcap_nametoport() returns the protocol along with the port number. 75 | * If there are ambiguous entried in /etc/services (i.e. domain 76 | * can be either tcp or udp) PROTO_UNDEF is returned. 77 | */ 78 | #define PROTO_UNDEF -1 79 | 80 | /* XXX move these to pcap-int.h? */ 81 | int __pcap_atodn(const char *, bpf_u_int32 *); 82 | int __pcap_atoin(const char *, bpf_u_int32 *); 83 | u_short __pcap_nametodnaddr(const char *); 84 | 85 | #ifdef __cplusplus 86 | } 87 | #endif 88 | 89 | #endif 90 | -------------------------------------------------------------------------------- /.jenkins: -------------------------------------------------------------------------------- 1 | currentBuild.displayName = "#${BUILD_NUMBER}" 2 | if (env.GERRIT_CHANGE_SUBJECT) { 3 | currentBuild.displayName += " - ${GERRIT_CHANGE_SUBJECT} (${GERRIT_CHANGE_NUMBER})" 4 | } 5 | if (env.GERRIT_REFNAME) { 6 | currentBuild.displayName += " - ${GERRIT_REFNAME}" 7 | } 8 | 9 | def buildPrepare() 10 | { 11 | sh """ 12 | git clean -xdff 13 | uv venv --seed 14 | uv pip install wheel 15 | uv pip install cmake>=2.28 16 | """ 17 | } 18 | 19 | def buildPreset(String preset, Boolean archive = false) 20 | { 21 | sh """ 22 | . .venv/bin/activate 23 | cmake --preset ${preset} 24 | cmake --build --preset ${preset} 25 | """ 26 | 27 | if (archive) { 28 | sh """ 29 | . .venv/bin/activate 30 | cpack --preset ${preset} -G ZIP 31 | """ 32 | archiveArtifacts ( 33 | artifacts: "build/${preset}/soem-*.zip", 34 | fingerprint: true 35 | ) 36 | } 37 | } 38 | 39 | def dockerBuildArgs() 40 | { 41 | return '''\ 42 | --build-arg BUILDER_UID="$( id -u )" \ 43 | --build-arg BUILDER_GID="$( id -g )" \ 44 | --build-arg BUILDER_USER="$( id -un )" \ 45 | --build-arg BUILDER_GROUP="$( id -gn )" \ 46 | ''' 47 | } 48 | 49 | def buildDocs() 50 | { 51 | sh """ 52 | . .venv/bin/activate 53 | uv pip install -r docs/requirements.txt 54 | cmake --preset docs 55 | cmake --build --preset docs 56 | """ 57 | 58 | dir('build/docs') { 59 | script { 60 | def systemInformation = sh(script: 'cmake --system-information', returnStdout: true) 61 | def versionLine = systemInformation =~ /CMAKE_PROJECT_VERSION:STATIC=(.*)/ 62 | if (versionLine) { 63 | env.PROJECT_VERSION = versionLine[0][1].trim() 64 | env.PROJECT_PREFIX = "soem-${env.PROJECT_VERSION}" 65 | } 66 | } 67 | } 68 | 69 | publishHTML([ 70 | allowMissing: false, 71 | alwaysLinkToLastBuild: false, 72 | keepAll: false, 73 | reportDir: 'build/docs/docs/sphinx/html/', 74 | reportFiles: 'index.html', 75 | reportName: 'Documentation'] 76 | ) 77 | zip(dir: 'build/docs/docs/sphinx', 78 | glob: 'html/**', 79 | zipFile: "build/${env.PROJECT_PREFIX}-html.zip" 80 | ) 81 | archiveArtifacts ( 82 | artifacts: "build/${env.PROJECT_PREFIX}-html.zip" 83 | ) 84 | stash( 85 | name: "sphinx-html", 86 | includes: "build/${env.PROJECT_PREFIX}-html.zip" 87 | ) 88 | } 89 | 90 | pipeline { 91 | agent any 92 | 93 | stages { 94 | stage("build") { 95 | parallel { 96 | stage('linux') { 97 | steps { 98 | buildPrepare() 99 | buildPreset('default', true) 100 | // buildPreset('test') 101 | // buildDocs() 102 | } 103 | } 104 | 105 | stage('linux-arm64') { 106 | agent { 107 | dockerfile { 108 | filename 'linux-arm64.Dockerfile' 109 | dir '.docker' 110 | additionalBuildArgs dockerBuildArgs() 111 | } 112 | } 113 | steps { 114 | buildPrepare() 115 | buildPreset('default', true) 116 | } 117 | } 118 | 119 | stage('windows-x64') { 120 | agent { 121 | dockerfile { 122 | filename 'windows-x64.Dockerfile' 123 | dir '.docker' 124 | additionalBuildArgs dockerBuildArgs() 125 | } 126 | } 127 | steps { 128 | buildPrepare() 129 | buildPreset('default', true) 130 | } 131 | } 132 | 133 | } 134 | } 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /include/soem/ec_options.h.in: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is dual-licensed under GPLv3 and a commercial 3 | * license. See the file LICENSE.md distributed with this software for 4 | * full license information. 5 | */ 6 | 7 | /** \file 8 | * \brief 9 | * Build options for SOEM 10 | */ 11 | 12 | #ifndef _ec_options_ 13 | #define _ec_options_ 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | /* Max sizes */ 20 | 21 | /** standard frame buffer size in bytes */ 22 | #define EC_BUFSIZE (@EC_BUFSIZE@) 23 | 24 | /** number of frame buffers per channel (tx, rx1 rx2) */ 25 | #define EC_MAXBUF (@EC_MAXBUF@) 26 | 27 | /** size of EEPROM bitmap cache */ 28 | #define EC_MAXEEPBITMAP (@EC_MAXEEPBITMAP@) 29 | 30 | /** size of EEPROM cache buffer */ 31 | #define EC_MAXEEPBUF (@EC_MAXEEPBUF@) 32 | 33 | /** default group size in 2^x */ 34 | #define EC_LOGGROUPOFFSET (@EC_LOGGROUPOFFSET@) 35 | 36 | /** max. entries in EtherCAT error list */ 37 | #define EC_MAXELIST (@EC_MAXELIST@) 38 | 39 | /** max. length of readable name in slavelist and Object Description List */ 40 | #define EC_MAXNAME (@EC_MAXNAME@) 41 | 42 | /** max. number of slaves in array */ 43 | #define EC_MAXSLAVE (@EC_MAXSLAVE@) 44 | 45 | /** max. number of groups */ 46 | #define EC_MAXGROUP (@EC_MAXGROUP@) 47 | 48 | /** max. number of IO segments per group */ 49 | #define EC_MAXIOSEGMENTS (@EC_MAXIOSEGMENTS@) 50 | 51 | /** max. mailbox size */ 52 | #define EC_MAXMBX (@EC_MAXMBX@) 53 | 54 | /** number of mailboxes in pool */ 55 | #define EC_MBXPOOLSIZE (@EC_MBXPOOLSIZE@) 56 | 57 | /** max. eeprom PDO entries */ 58 | #define EC_MAXEEPDO (@EC_MAXEEPDO@) 59 | 60 | /** max. SM used */ 61 | #define EC_MAXSM (@EC_MAXSM@) 62 | 63 | /** max. FMMU used */ 64 | #define EC_MAXFMMU (@EC_MAXFMMU@) 65 | 66 | /** max. adapter name length */ 67 | #define EC_MAXLEN_ADAPTERNAME (@EC_MAXLEN_ADAPTERNAME@) 68 | 69 | /** define maximum number of concurrent threads in mapping */ 70 | #define EC_MAX_MAPT (@EC_MAX_MAPT@) 71 | 72 | /** max entries in Object Description list */ 73 | #define EC_MAXODLIST (@EC_MAXODLIST@) 74 | 75 | /** max entries in Object Entry list */ 76 | #define EC_MAXOELIST (@EC_MAXOELIST@) 77 | 78 | /** max. length of readable SoE name */ 79 | #define EC_SOE_MAXNAME (@EC_SOE_MAXNAME@) 80 | 81 | /** max. number of SoE mappings */ 82 | #define EC_SOE_MAXMAPPING (@EC_SOE_MAXMAPPING@) 83 | 84 | /* Timeouts and retries */ 85 | 86 | /** timeout value in us for tx frame to return to rx */ 87 | #define EC_TIMEOUTRET (@EC_TIMEOUTRET@) 88 | 89 | /** timeout value in us for safe data transfer, max. triple retry */ 90 | #define EC_TIMEOUTRET3 (@EC_TIMEOUTRET3@) 91 | 92 | /** timeout value in us for return "safe" variant (f.e. wireless) */ 93 | #define EC_TIMEOUTSAFE (@EC_TIMEOUTSAFE@) 94 | 95 | /** timeout value in us for EEPROM access */ 96 | #define EC_TIMEOUTEEP (@EC_TIMEOUTEEP@) 97 | 98 | /** timeout value in us for tx mailbox cycle */ 99 | #define EC_TIMEOUTTXM (@EC_TIMEOUTTXM@) 100 | 101 | /** timeout value in us for rx mailbox cycle */ 102 | #define EC_TIMEOUTRXM (@EC_TIMEOUTRXM@) 103 | 104 | /** timeout value in us for check statechange */ 105 | #define EC_TIMEOUTSTATE (@EC_TIMEOUTSTATE@) 106 | 107 | /** default number of retries if wkc <= 0 */ 108 | #define EC_DEFAULTRETRIES (@EC_DEFAULTRETRIES@) 109 | 110 | /* MAC addresses */ 111 | 112 | /** Primary source MAC address used for EtherCAT. 113 | * 114 | * This address is not the MAC address used from the NIC. EtherCAT 115 | * does not care about MAC addressing, but it is used here to 116 | * differentiate the route the packet traverses through the EtherCAT 117 | * segment. This is needed to find out the packet flow in redundant 118 | * configurations. */ 119 | #define EC_PRIMARY_MAC_ARRAY @EC_PRIMARY_MAC_ARRAY@ 120 | 121 | /** Secondary source MAC address used for EtherCAT. */ 122 | #define EC_SECONDARY_MAC_ARRAY @EC_SECONDARY_MAC_ARRAY@ 123 | 124 | #ifdef __cplusplus 125 | } 126 | #endif 127 | 128 | #endif 129 | -------------------------------------------------------------------------------- /contrib/osal/macosx/osal.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is dual-licensed under GPLv3 and a commercial 3 | * license. See the file LICENSE.md distributed with this software for 4 | * full license information. 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #define USECS_PER_SEC 1000000 15 | 16 | int osal_usleep(uint32 usec) 17 | { 18 | struct timespec ts; 19 | ts.tv_sec = usec / USECS_PER_SEC; 20 | ts.tv_nsec = (usec % USECS_PER_SEC) * 1000; 21 | /* usleep is deprecated, use nanosleep instead */ 22 | return nanosleep(&ts, NULL); 23 | } 24 | 25 | int osal_gettimeofday(struct timeval *tv, struct timezone *tz) 26 | { 27 | struct timespec ts; 28 | int return_value; 29 | (void)tz; /* Not used */ 30 | 31 | /* Use clock_gettime to prevent possible live-lock. 32 | * Gettimeofday uses CLOCK_REALTIME that can get NTP timeadjust. 33 | * If this function preempts timeadjust and it uses vpage it live-locks. 34 | * Also when using XENOMAI, only clock_gettime is RT safe */ 35 | return_value = clock_gettime(CLOCK_MONOTONIC, &ts); 36 | tv->tv_sec = ts.tv_sec; 37 | tv->tv_usec = ts.tv_nsec / 1000; 38 | return return_value; 39 | } 40 | 41 | ec_timet osal_current_time(void) 42 | { 43 | struct timeval current_time; 44 | ec_timet return_value; 45 | 46 | osal_gettimeofday(¤t_time, 0); 47 | return_value.sec = current_time.tv_sec; 48 | return_value.usec = current_time.tv_usec; 49 | return return_value; 50 | } 51 | 52 | void osal_time_diff(ec_timet *start, ec_timet *end, ec_timet *diff) 53 | { 54 | if (end->usec < start->usec) 55 | { 56 | diff->sec = end->sec - start->sec - 1; 57 | diff->usec = end->usec + 1000000 - start->usec; 58 | } 59 | else 60 | { 61 | diff->sec = end->sec - start->sec; 62 | diff->usec = end->usec - start->usec; 63 | } 64 | } 65 | 66 | void osal_timer_start(osal_timert *self, uint32 timeout_usec) 67 | { 68 | struct timeval start_time; 69 | struct timeval timeout; 70 | struct timeval stop_time; 71 | 72 | osal_gettimeofday(&start_time, 0); 73 | timeout.tv_sec = timeout_usec / USECS_PER_SEC; 74 | timeout.tv_usec = timeout_usec % USECS_PER_SEC; 75 | timeradd(&start_time, &timeout, &stop_time); 76 | 77 | self->stop_time.sec = stop_time.tv_sec; 78 | self->stop_time.usec = stop_time.tv_usec; 79 | } 80 | 81 | boolean osal_timer_is_expired(osal_timert *self) 82 | { 83 | struct timeval current_time; 84 | struct timeval stop_time; 85 | int is_not_yet_expired; 86 | 87 | osal_gettimeofday(¤t_time, 0); 88 | stop_time.tv_sec = self->stop_time.sec; 89 | stop_time.tv_usec = self->stop_time.usec; 90 | is_not_yet_expired = timercmp(¤t_time, &stop_time, <); 91 | 92 | return is_not_yet_expired == FALSE; 93 | } 94 | 95 | void *osal_malloc(size_t size) 96 | { 97 | return malloc(size); 98 | } 99 | 100 | void osal_free(void *ptr) 101 | { 102 | free(ptr); 103 | } 104 | 105 | int osal_thread_create(void *thandle, int stacksize, void *func, void *param) 106 | { 107 | int ret; 108 | pthread_attr_t attr; 109 | pthread_t *threadp; 110 | 111 | threadp = thandle; 112 | pthread_attr_init(&attr); 113 | pthread_attr_setstacksize(&attr, stacksize); 114 | ret = pthread_create(threadp, &attr, func, param); 115 | if (ret < 0) 116 | { 117 | return 0; 118 | } 119 | return 1; 120 | } 121 | 122 | int osal_thread_create_rt(void *thandle, int stacksize, void *func, void *param) 123 | { 124 | int ret; 125 | pthread_attr_t attr; 126 | struct sched_param schparam; 127 | pthread_t *threadp; 128 | 129 | threadp = thandle; 130 | pthread_attr_init(&attr); 131 | pthread_attr_setstacksize(&attr, stacksize); 132 | ret = pthread_create(threadp, &attr, func, param); 133 | pthread_attr_destroy(&attr); 134 | if (ret < 0) 135 | { 136 | return 0; 137 | } 138 | memset(&schparam, 0, sizeof(schparam)); 139 | schparam.sched_priority = 40; 140 | ret = pthread_setschedparam(*threadp, SCHED_FIFO, &schparam); 141 | if (ret < 0) 142 | { 143 | return 0; 144 | } 145 | 146 | return 1; 147 | } 148 | -------------------------------------------------------------------------------- /contrib/osal/rtems/osal.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is dual-licensed under GPLv3 and a commercial 3 | * license. See the file LICENSE.md distributed with this software for 4 | * full license information. 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #define USECS_PER_SEC 1000000 15 | 16 | int osal_usleep(uint32 usec) 17 | { 18 | struct timespec ts; 19 | ts.tv_sec = usec / USECS_PER_SEC; 20 | ts.tv_nsec = (usec % USECS_PER_SEC) * 1000; 21 | /* usleep is deprecated, use nanosleep instead */ 22 | return nanosleep(&ts, NULL); 23 | } 24 | 25 | int osal_gettimeofday(struct timeval *tv, struct timezone *tz) 26 | { 27 | struct timespec ts; 28 | int return_value; 29 | (void)tz; /* Not used */ 30 | 31 | /* Use clock_gettime to prevent possible live-lock. 32 | * Gettimeofday uses CLOCK_REALTIME that can get NTP timeadjust. 33 | * If this function preempts timeadjust and it uses vpage it live-locks. 34 | * Also when using XENOMAI, only clock_gettime is RT safe */ 35 | return_value = clock_gettime(CLOCK_MONOTONIC, &ts); 36 | tv->tv_sec = ts.tv_sec; 37 | tv->tv_usec = ts.tv_nsec / 1000; 38 | return return_value; 39 | } 40 | 41 | ec_timet osal_current_time(void) 42 | { 43 | struct timeval current_time; 44 | ec_timet return_value; 45 | 46 | osal_gettimeofday(¤t_time, 0); 47 | return_value.sec = current_time.tv_sec; 48 | return_value.usec = current_time.tv_usec; 49 | return return_value; 50 | } 51 | 52 | void osal_time_diff(ec_timet *start, ec_timet *end, ec_timet *diff) 53 | { 54 | if (end->usec < start->usec) 55 | { 56 | diff->sec = end->sec - start->sec - 1; 57 | diff->usec = end->usec + 1000000 - start->usec; 58 | } 59 | else 60 | { 61 | diff->sec = end->sec - start->sec; 62 | diff->usec = end->usec - start->usec; 63 | } 64 | } 65 | 66 | void osal_timer_start(osal_timert *self, uint32 timeout_usec) 67 | { 68 | struct timeval start_time; 69 | struct timeval timeout; 70 | struct timeval stop_time; 71 | 72 | osal_gettimeofday(&start_time, 0); 73 | timeout.tv_sec = timeout_usec / USECS_PER_SEC; 74 | timeout.tv_usec = timeout_usec % USECS_PER_SEC; 75 | timeradd(&start_time, &timeout, &stop_time); 76 | 77 | self->stop_time.sec = stop_time.tv_sec; 78 | self->stop_time.usec = stop_time.tv_usec; 79 | } 80 | 81 | boolean osal_timer_is_expired(osal_timert *self) 82 | { 83 | struct timeval current_time; 84 | struct timeval stop_time; 85 | int is_not_yet_expired; 86 | 87 | osal_gettimeofday(¤t_time, 0); 88 | stop_time.tv_sec = self->stop_time.sec; 89 | stop_time.tv_usec = self->stop_time.usec; 90 | is_not_yet_expired = timercmp(¤t_time, &stop_time, <); 91 | 92 | return is_not_yet_expired == FALSE; 93 | } 94 | 95 | void *osal_malloc(size_t size) 96 | { 97 | return malloc(size); 98 | } 99 | 100 | void osal_free(void *ptr) 101 | { 102 | free(ptr); 103 | } 104 | 105 | int osal_thread_create(void *thandle, int stacksize, void *func, void *param) 106 | { 107 | int ret; 108 | pthread_attr_t attr; 109 | pthread_t *threadp; 110 | 111 | threadp = thandle; 112 | pthread_attr_init(&attr); 113 | pthread_attr_setstacksize(&attr, stacksize); 114 | ret = pthread_create(threadp, &attr, func, param); 115 | if (ret < 0) 116 | { 117 | return 0; 118 | } 119 | return 1; 120 | } 121 | 122 | int osal_thread_create_rt(void *thandle, int stacksize, void *func, void *param) 123 | { 124 | int ret; 125 | pthread_attr_t attr; 126 | struct sched_param schparam; 127 | pthread_t *threadp; 128 | 129 | threadp = thandle; 130 | pthread_attr_init(&attr); 131 | pthread_attr_setstacksize(&attr, stacksize); 132 | ret = pthread_create(threadp, &attr, func, param); 133 | pthread_attr_destroy(&attr); 134 | if (ret < 0) 135 | { 136 | return 0; 137 | } 138 | memset(&schparam, 0, sizeof(schparam)); 139 | schparam.sched_priority = 40; 140 | ret = pthread_setschedparam(*threadp, SCHED_FIFO, &schparam); 141 | if (ret < 0) 142 | { 143 | return 0; 144 | } 145 | 146 | return 1; 147 | } 148 | -------------------------------------------------------------------------------- /samples/eni_test/sample-eni.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | ffffffffffff 8 | 010101010101 9 | 10 | 11 | 12 | 13 | 14 | 1 15 | 0x1234 16 | 0 17 | 0 18 | 19 | 20 | 21 | 0x1000 22 | 128 23 | 24 | 25 | 0x1100 26 | 128 27 | 5 28 | 29 | CoE 30 | 31 | 32 | 33 | 34 | PS 35 | 3 36 | 2 37 | 0x1c13 38 | 0 39 | 00 40 | 41 | 42 | 43 | PS 44 | 3 45 | 2 46 | 0x1c13 47 | 1 48 | 021a 49 | 50 | 51 | 52 | PS 53 | 3 54 | 2 55 | 0x1c13 56 | 2 57 | 051a 58 | 59 | 60 | 61 | PS 62 | 3 63 | 2 64 | 0x1c13 65 | 0 66 | 02 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 1 76 | 0x10055aa 77 | 0 78 | 0 79 | 80 | 81 | 82 | 0x1000 83 | 256 84 | 85 | 86 | 0x1200 87 | 256 88 | 5 89 | 90 | CoE 91 | 92 | 93 | 94 | 95 | PS 96 | 3 97 | 2 98 | 0x1c12 99 | 0 100 | 0300011607161c16 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | -------------------------------------------------------------------------------- /osal/linux/osal.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is dual-licensed under GPLv3 and a commercial 3 | * license. See the file LICENSE.md distributed with this software for 4 | * full license information. 5 | */ 6 | #include 7 | #include 8 | #include 9 | 10 | /* Returns time from some unspecified moment in past, 11 | * strictly increasing, used for time intervals measurement. */ 12 | void osal_get_monotonic_time(ec_timet *ts) 13 | { 14 | /* Use clock_gettime to prevent possible live-lock. 15 | * Gettimeofday uses CLOCK_REALTIME that can get NTP timeadjust. 16 | * If this function preempts timeadjust and it uses vpage it live-locks. 17 | * Also when using XENOMAI, only clock_gettime is RT safe */ 18 | clock_gettime(CLOCK_MONOTONIC, ts); 19 | } 20 | 21 | ec_timet osal_current_time(void) 22 | { 23 | struct timespec ts; 24 | 25 | clock_gettime(CLOCK_REALTIME, &ts); 26 | return ts; 27 | } 28 | 29 | void osal_time_diff(ec_timet *start, ec_timet *end, ec_timet *diff) 30 | { 31 | osal_timespecsub(end, start, diff); 32 | } 33 | 34 | void osal_timer_start(osal_timert *self, uint32 timeout_usec) 35 | { 36 | struct timespec start_time; 37 | struct timespec timeout; 38 | 39 | osal_get_monotonic_time(&start_time); 40 | osal_timespec_from_usec(timeout_usec, &timeout); 41 | osal_timespecadd(&start_time, &timeout, &self->stop_time); 42 | } 43 | 44 | boolean osal_timer_is_expired(osal_timert *self) 45 | { 46 | struct timespec current_time; 47 | int is_not_yet_expired; 48 | 49 | osal_get_monotonic_time(¤t_time); 50 | is_not_yet_expired = osal_timespeccmp(¤t_time, &self->stop_time, <); 51 | 52 | return is_not_yet_expired == FALSE; 53 | } 54 | 55 | int osal_usleep(uint32 usec) 56 | { 57 | struct timespec ts; 58 | int result; 59 | 60 | osal_timespec_from_usec(usec, &ts); 61 | result = clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, NULL); 62 | return result == 0 ? 0 : -1; 63 | } 64 | 65 | int osal_monotonic_sleep(ec_timet *ts) 66 | { 67 | int result; 68 | result = clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, ts, NULL); 69 | return result == 0 ? 0 : -1; 70 | } 71 | 72 | void *osal_malloc(size_t size) 73 | { 74 | return malloc(size); 75 | } 76 | 77 | void osal_free(void *ptr) 78 | { 79 | free(ptr); 80 | } 81 | 82 | int osal_thread_create(void *thandle, int stacksize, void *func, void *param) 83 | { 84 | int ret; 85 | pthread_attr_t attr; 86 | pthread_t *threadp; 87 | 88 | threadp = thandle; 89 | pthread_attr_init(&attr); 90 | pthread_attr_setstacksize(&attr, stacksize); 91 | ret = pthread_create(threadp, &attr, func, param); 92 | if (ret < 0) 93 | { 94 | return 0; 95 | } 96 | return 1; 97 | } 98 | 99 | int osal_thread_create_rt(void *thandle, int stacksize, void *func, void *param) 100 | { 101 | int ret; 102 | pthread_attr_t attr; 103 | struct sched_param schparam; 104 | pthread_t *threadp; 105 | 106 | threadp = thandle; 107 | pthread_attr_init(&attr); 108 | pthread_attr_setstacksize(&attr, stacksize); 109 | ret = pthread_create(threadp, &attr, func, param); 110 | pthread_attr_destroy(&attr); 111 | if (ret < 0) 112 | { 113 | return 0; 114 | } 115 | memset(&schparam, 0, sizeof(schparam)); 116 | schparam.sched_priority = 40; 117 | ret = pthread_setschedparam(*threadp, SCHED_FIFO, &schparam); 118 | if (ret < 0) 119 | { 120 | return 0; 121 | } 122 | 123 | return 1; 124 | } 125 | 126 | void *osal_mutex_create(void) 127 | { 128 | pthread_mutexattr_t mutexattr; 129 | osal_mutext *mutex; 130 | mutex = (osal_mutext *)osal_malloc(sizeof(osal_mutext)); 131 | if (mutex) 132 | { 133 | pthread_mutexattr_init(&mutexattr); 134 | pthread_mutexattr_setprotocol(&mutexattr, PTHREAD_PRIO_INHERIT); 135 | pthread_mutex_init(mutex, &mutexattr); 136 | } 137 | return (void *)mutex; 138 | } 139 | 140 | void osal_mutex_destroy(void *mutex) 141 | { 142 | pthread_mutex_destroy((osal_mutext *)mutex); 143 | osal_free(mutex); 144 | } 145 | 146 | void osal_mutex_lock(void *mutex) 147 | { 148 | pthread_mutex_lock((osal_mutext *)mutex); 149 | } 150 | 151 | void osal_mutex_unlock(void *mutex) 152 | { 153 | pthread_mutex_unlock((osal_mutext *)mutex); 154 | } 155 | -------------------------------------------------------------------------------- /oshw/win32/wpcap/Include/Win32-Extensions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1999 - 2005 NetGroup, Politecnico di Torino (Italy) 3 | * Copyright (c) 2005 - 2006 CACE Technologies, Davis (California) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 3. Neither the name of the Politecnico di Torino, CACE Technologies 16 | * nor the names of its contributors may be used to endorse or promote 17 | * products derived from this software without specific prior written 18 | * permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | */ 33 | 34 | #ifndef __WIN32_EXTENSIONS_H__ 35 | #define __WIN32_EXTENSIONS_H__ 36 | 37 | #ifdef __cplusplus 38 | extern "C" { 39 | #endif 40 | 41 | /* Definitions */ 42 | 43 | /*! 44 | \brief A queue of raw packets that will be sent to the network with pcap_sendqueue_transmit(). 45 | */ 46 | struct pcap_send_queue 47 | { 48 | u_int maxlen; ///< Maximum size of the the queue, in bytes. This variable contains the size of the buffer field. 49 | u_int len; ///< Current size of the queue, in bytes. 50 | char *buffer; ///< Buffer containing the packets to be sent. 51 | }; 52 | 53 | typedef struct pcap_send_queue pcap_send_queue; 54 | 55 | /*! 56 | \brief This typedef is a support for the pcap_get_airpcap_handle() function 57 | */ 58 | #if !defined(AIRPCAP_HANDLE__EAE405F5_0171_9592_B3C2_C19EC426AD34__DEFINED_) 59 | #define AIRPCAP_HANDLE__EAE405F5_0171_9592_B3C2_C19EC426AD34__DEFINED_ 60 | typedef struct _AirpcapHandle *PAirpcapHandle; 61 | #endif 62 | 63 | #define BPF_MEM_EX_IMM 0xc0 64 | #define BPF_MEM_EX_IND 0xe0 65 | 66 | /*used for ST*/ 67 | #define BPF_MEM_EX 0xc0 68 | #define BPF_TME 0x08 69 | 70 | #define BPF_LOOKUP 0x90 71 | #define BPF_EXECUTE 0xa0 72 | #define BPF_INIT 0xb0 73 | #define BPF_VALIDATE 0xc0 74 | #define BPF_SET_ACTIVE 0xd0 75 | #define BPF_RESET 0xe0 76 | #define BPF_SET_MEMORY 0x80 77 | #define BPF_GET_REGISTER_VALUE 0x70 78 | #define BPF_SET_REGISTER_VALUE 0x60 79 | #define BPF_SET_WORKING 0x50 80 | #define BPF_SET_ACTIVE_READ 0x40 81 | #define BPF_SET_AUTODELETION 0x30 82 | #define BPF_SEPARATION 0xff 83 | 84 | /* Prototypes */ 85 | pcap_send_queue* pcap_sendqueue_alloc(u_int memsize); 86 | 87 | void pcap_sendqueue_destroy(pcap_send_queue* queue); 88 | 89 | int pcap_sendqueue_queue(pcap_send_queue* queue, const struct pcap_pkthdr *pkt_header, const u_char *pkt_data); 90 | 91 | u_int pcap_sendqueue_transmit(pcap_t *p, pcap_send_queue* queue, int sync); 92 | 93 | HANDLE pcap_getevent(pcap_t *p); 94 | 95 | struct pcap_stat *pcap_stats_ex(pcap_t *p, int *pcap_stat_size); 96 | 97 | int pcap_setuserbuffer(pcap_t *p, int size); 98 | 99 | int pcap_live_dump(pcap_t *p, char *filename, int maxsize, int maxpacks); 100 | 101 | int pcap_live_dump_ended(pcap_t *p, int sync); 102 | 103 | int pcap_offline_filter(struct bpf_program *prog, const struct pcap_pkthdr *header, const u_char *pkt_data); 104 | 105 | int pcap_start_oem(char* err_str, int flags); 106 | 107 | PAirpcapHandle pcap_get_airpcap_handle(pcap_t *p); 108 | 109 | #ifdef __cplusplus 110 | } 111 | #endif 112 | 113 | #endif //__WIN32_EXTENSIONS_H__ 114 | -------------------------------------------------------------------------------- /osal/win32/osal.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is dual-licensed under GPLv3 and a commercial 3 | * license. See the file LICENSE.md distributed with this software for 4 | * full license information. 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | static LARGE_INTEGER sysfrequency; 13 | 14 | void osal_get_monotonic_time(ec_timet *ts) 15 | { 16 | LARGE_INTEGER wintime; 17 | uint64_t sec; 18 | uint64_t nsec; 19 | 20 | if (!sysfrequency.QuadPart) 21 | { 22 | timeBeginPeriod(1); 23 | QueryPerformanceFrequency(&sysfrequency); 24 | } 25 | 26 | QueryPerformanceCounter(&wintime); 27 | 28 | /* Compute seconds */ 29 | sec = wintime.QuadPart / sysfrequency.QuadPart; 30 | wintime.QuadPart = wintime.QuadPart - sec * sysfrequency.QuadPart; 31 | 32 | /* Compute nanoseconds. Multiplying first acts as a guard against 33 | potential loss of precision during the calculation. */ 34 | nsec = wintime.QuadPart * 1000000000; 35 | nsec = nsec / sysfrequency.QuadPart; 36 | 37 | ts->tv_sec = sec; 38 | ts->tv_nsec = (uint32_t)nsec; 39 | } 40 | 41 | ec_timet osal_current_time(void) 42 | { 43 | struct timespec ts; 44 | timespec_get(&ts, TIME_UTC); 45 | return ts; 46 | } 47 | 48 | void osal_time_diff(ec_timet *start, ec_timet *end, ec_timet *diff) 49 | { 50 | osal_timespecsub(end, start, diff); 51 | } 52 | 53 | void osal_timer_start(osal_timert *self, uint32 timeout_usec) 54 | { 55 | struct timespec start_time; 56 | struct timespec timeout; 57 | 58 | osal_get_monotonic_time(&start_time); 59 | osal_timespec_from_usec(timeout_usec, &timeout); 60 | osal_timespecadd(&start_time, &timeout, &self->stop_time); 61 | } 62 | 63 | boolean osal_timer_is_expired(osal_timert *self) 64 | { 65 | struct timespec current_time; 66 | int is_not_yet_expired; 67 | 68 | osal_get_monotonic_time(¤t_time); 69 | is_not_yet_expired = osal_timespeccmp(¤t_time, &self->stop_time, <); 70 | 71 | return is_not_yet_expired == FALSE; 72 | } 73 | 74 | int osal_usleep(uint32 usec) 75 | { 76 | struct timespec wakeup; 77 | struct timespec timeout; 78 | 79 | osal_get_monotonic_time(&wakeup); 80 | osal_timespec_from_usec(usec, &timeout); 81 | osal_timespecadd(&wakeup, &timeout, &wakeup); 82 | osal_monotonic_sleep(&wakeup); 83 | return 1; 84 | } 85 | 86 | /** 87 | * @brief Suspends the execution of the calling thread until a 88 | * specified absolute time. 89 | * 90 | * @param ts Pointer to a struct that specifies the 91 | * absolute wakeup time in milliseconds. 92 | * @return 0 on success, or a negative value on error. 93 | */ 94 | int osal_monotonic_sleep(ec_timet *ts) 95 | { 96 | uint64_t millis; 97 | struct timespec now; 98 | struct timespec delay; 99 | 100 | osal_get_monotonic_time(&now); 101 | 102 | /* Delay already expired? */ 103 | if (!osal_timespeccmp(&now, ts, <)) 104 | return 0; 105 | 106 | /* Sleep for whole milliseconds */ 107 | osal_timespecsub(ts, &now, &delay); 108 | millis = delay.tv_sec * 1000 + delay.tv_nsec / 1000000; 109 | if (millis > 0) 110 | { 111 | SleepEx((DWORD)millis, FALSE); 112 | } 113 | 114 | /* Busy wait for remaining time */ 115 | do 116 | { 117 | osal_get_monotonic_time(&now); 118 | } while osal_timespeccmp(&now, ts, <); 119 | 120 | return 0; 121 | } 122 | 123 | void *osal_malloc(size_t size) 124 | { 125 | return malloc(size); 126 | } 127 | 128 | void osal_free(void *ptr) 129 | { 130 | free(ptr); 131 | } 132 | 133 | int osal_thread_create(void *thandle, int stacksize, void *func, void *param) 134 | { 135 | *(OSAL_THREAD_HANDLE *)thandle = CreateThread(NULL, stacksize, func, param, 0, NULL); 136 | if (!thandle) 137 | { 138 | return 0; 139 | } 140 | return 1; 141 | } 142 | 143 | int osal_thread_create_rt(void *thandle, int stacksize, void *func, void *param) 144 | { 145 | int ret; 146 | ret = osal_thread_create(thandle, stacksize, func, param); 147 | if (ret) 148 | { 149 | ret = SetThreadPriority(thandle, THREAD_PRIORITY_TIME_CRITICAL); 150 | } 151 | return ret; 152 | } 153 | 154 | void *osal_mutex_create(void) 155 | { 156 | return CreateMutex(NULL, FALSE, NULL); 157 | } 158 | 159 | void osal_mutex_destroy(void *mutex) 160 | { 161 | CloseHandle(mutex); 162 | } 163 | 164 | void osal_mutex_lock(void *mutex) 165 | { 166 | WaitForSingleObject(mutex, INFINITE); 167 | } 168 | 169 | void osal_mutex_unlock(void *mutex) 170 | { 171 | ReleaseMutex(mutex); 172 | } 173 | -------------------------------------------------------------------------------- /oshw/win32/wpcap/Include/bittypes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1999 WIDE Project. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. Neither the name of the project nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | */ 29 | #ifndef _BITTYPES_H 30 | #define _BITTYPES_H 31 | 32 | #ifndef HAVE_U_INT8_T 33 | 34 | #if SIZEOF_CHAR == 1 35 | typedef unsigned char u_int8_t; 36 | typedef signed char int8_t; 37 | #elif SIZEOF_INT == 1 38 | typedef unsigned int u_int8_t; 39 | typedef signed int int8_t; 40 | #else /* XXX */ 41 | #error "there's no appropriate type for u_int8_t" 42 | #endif 43 | #define HAVE_U_INT8_T 1 44 | #define HAVE_INT8_T 1 45 | 46 | #endif /* HAVE_U_INT8_T */ 47 | 48 | #ifndef HAVE_U_INT16_T 49 | 50 | #if SIZEOF_SHORT == 2 51 | typedef unsigned short u_int16_t; 52 | typedef signed short int16_t; 53 | #elif SIZEOF_INT == 2 54 | typedef unsigned int u_int16_t; 55 | typedef signed int int16_t; 56 | #elif SIZEOF_CHAR == 2 57 | typedef unsigned char u_int16_t; 58 | typedef signed char int16_t; 59 | #else /* XXX */ 60 | #error "there's no appropriate type for u_int16_t" 61 | #endif 62 | #define HAVE_U_INT16_T 1 63 | #define HAVE_INT16_T 1 64 | 65 | #endif /* HAVE_U_INT16_T */ 66 | 67 | #ifndef HAVE_U_INT32_T 68 | 69 | #if SIZEOF_INT == 4 70 | typedef unsigned int u_int32_t; 71 | typedef signed int int32_t; 72 | #elif SIZEOF_LONG == 4 73 | typedef unsigned long u_int32_t; 74 | typedef signed long int32_t; 75 | #elif SIZEOF_SHORT == 4 76 | typedef unsigned short u_int32_t; 77 | typedef signed short int32_t; 78 | #else /* XXX */ 79 | #error "there's no appropriate type for u_int32_t" 80 | #endif 81 | #define HAVE_U_INT32_T 1 82 | #define HAVE_INT32_T 1 83 | 84 | #endif /* HAVE_U_INT32_T */ 85 | 86 | #ifndef HAVE_U_INT64_T 87 | #if SIZEOF_LONG_LONG == 8 88 | typedef unsigned long long u_int64_t; 89 | typedef long long int64_t; 90 | #elif defined(_MSC_EXTENSIONS) 91 | typedef unsigned _int64 u_int64_t; 92 | typedef _int64 int64_t; 93 | #elif SIZEOF_INT == 8 94 | typedef unsigned int u_int64_t; 95 | #elif SIZEOF_LONG == 8 96 | typedef unsigned long u_int64_t; 97 | #elif SIZEOF_SHORT == 8 98 | typedef unsigned short u_int64_t; 99 | #else /* XXX */ 100 | #error "there's no appropriate type for u_int64_t" 101 | #endif 102 | 103 | #endif /* HAVE_U_INT64_T */ 104 | 105 | #ifndef PRId64 106 | #ifdef _MSC_EXTENSIONS 107 | #define PRId64 "I64d" 108 | #else /* _MSC_EXTENSIONS */ 109 | #define PRId64 "lld" 110 | #endif /* _MSC_EXTENSIONS */ 111 | #endif /* PRId64 */ 112 | 113 | #ifndef PRIo64 114 | #ifdef _MSC_EXTENSIONS 115 | #define PRIo64 "I64o" 116 | #else /* _MSC_EXTENSIONS */ 117 | #define PRIo64 "llo" 118 | #endif /* _MSC_EXTENSIONS */ 119 | #endif /* PRIo64 */ 120 | 121 | #ifndef PRIx64 122 | #ifdef _MSC_EXTENSIONS 123 | #define PRIx64 "I64x" 124 | #else /* _MSC_EXTENSIONS */ 125 | #define PRIx64 "llx" 126 | #endif /* _MSC_EXTENSIONS */ 127 | #endif /* PRIx64 */ 128 | 129 | #ifndef PRIu64 130 | #ifdef _MSC_EXTENSIONS 131 | #define PRIu64 "I64u" 132 | #else /* _MSC_EXTENSIONS */ 133 | #define PRIu64 "llu" 134 | #endif /* _MSC_EXTENSIONS */ 135 | #endif /* PRIu64 */ 136 | 137 | #endif /* _BITTYPES_H */ 138 | -------------------------------------------------------------------------------- /oshw/win32/wpcap/Include/pcap/sll.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * This code is derived from the Stanford/CMU enet packet filter, 6 | * (net/enet.c) distributed as part of 4.3BSD, and code contributed 7 | * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence 8 | * Berkeley Laboratory. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. All advertising materials mentioning features or use of this software 19 | * must display the following acknowledgement: 20 | * This product includes software developed by the University of 21 | * California, Berkeley and its contributors. 22 | * 4. Neither the name of the University nor the names of its contributors 23 | * may be used to endorse or promote products derived from this software 24 | * without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 27 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 30 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 | * SUCH DAMAGE. 37 | * 38 | * @(#) $Header: /tcpdump/master/libpcap/pcap/sll.h,v 1.2.2.1 2008-05-30 01:36:06 guy Exp $ (LBL) 39 | */ 40 | 41 | /* 42 | * For captures on Linux cooked sockets, we construct a fake header 43 | * that includes: 44 | * 45 | * a 2-byte "packet type" which is one of: 46 | * 47 | * LINUX_SLL_HOST packet was sent to us 48 | * LINUX_SLL_BROADCAST packet was broadcast 49 | * LINUX_SLL_MULTICAST packet was multicast 50 | * LINUX_SLL_OTHERHOST packet was sent to somebody else 51 | * LINUX_SLL_OUTGOING packet was sent *by* us; 52 | * 53 | * a 2-byte Ethernet protocol field; 54 | * 55 | * a 2-byte link-layer type; 56 | * 57 | * a 2-byte link-layer address length; 58 | * 59 | * an 8-byte source link-layer address, whose actual length is 60 | * specified by the previous value. 61 | * 62 | * All fields except for the link-layer address are in network byte order. 63 | * 64 | * DO NOT change the layout of this structure, or change any of the 65 | * LINUX_SLL_ values below. If you must change the link-layer header 66 | * for a "cooked" Linux capture, introduce a new DLT_ type (ask 67 | * "tcpdump-workers@lists.tcpdump.org" for one, so that you don't give it 68 | * a value that collides with a value already being used), and use the 69 | * new header in captures of that type, so that programs that can 70 | * handle DLT_LINUX_SLL captures will continue to handle them correctly 71 | * without any change, and so that capture files with different headers 72 | * can be told apart and programs that read them can dissect the 73 | * packets in them. 74 | */ 75 | 76 | #ifndef lib_pcap_sll_h 77 | #define lib_pcap_sll_h 78 | 79 | /* 80 | * A DLT_LINUX_SLL fake link-layer header. 81 | */ 82 | #define SLL_HDR_LEN 16 /* total header length */ 83 | #define SLL_ADDRLEN 8 /* length of address field */ 84 | 85 | struct sll_header { 86 | u_int16_t sll_pkttype; /* packet type */ 87 | u_int16_t sll_hatype; /* link-layer address type */ 88 | u_int16_t sll_halen; /* link-layer address length */ 89 | u_int8_t sll_addr[SLL_ADDRLEN]; /* link-layer address */ 90 | u_int16_t sll_protocol; /* protocol */ 91 | }; 92 | 93 | /* 94 | * The LINUX_SLL_ values for "sll_pkttype"; these correspond to the 95 | * PACKET_ values on Linux, but are defined here so that they're 96 | * available even on systems other than Linux, and so that they 97 | * don't change even if the PACKET_ values change. 98 | */ 99 | #define LINUX_SLL_HOST 0 100 | #define LINUX_SLL_BROADCAST 1 101 | #define LINUX_SLL_MULTICAST 2 102 | #define LINUX_SLL_OTHERHOST 3 103 | #define LINUX_SLL_OUTGOING 4 104 | 105 | /* 106 | * The LINUX_SLL_ values for "sll_protocol"; these correspond to the 107 | * ETH_P_ values on Linux, but are defined here so that they're 108 | * available even on systems other than Linux. We assume, for now, 109 | * that the ETH_P_ values won't change in Linux; if they do, then: 110 | * 111 | * if we don't translate them in "pcap-linux.c", capture files 112 | * won't necessarily be readable if captured on a system that 113 | * defines ETH_P_ values that don't match these values; 114 | * 115 | * if we do translate them in "pcap-linux.c", that makes life 116 | * unpleasant for the BPF code generator, as the values you test 117 | * for in the kernel aren't the values that you test for when 118 | * reading a capture file, so the fixup code run on BPF programs 119 | * handed to the kernel ends up having to do more work. 120 | * 121 | * Add other values here as necessary, for handling packet types that 122 | * might show up on non-Ethernet, non-802.x networks. (Not all the ones 123 | * in the Linux "if_ether.h" will, I suspect, actually show up in 124 | * captures.) 125 | */ 126 | #define LINUX_SLL_P_802_3 0x0001 /* Novell 802.3 frames without 802.2 LLC header */ 127 | #define LINUX_SLL_P_802_2 0x0004 /* 802.2 frames (not D/I/X Ethernet) */ 128 | 129 | #endif 130 | -------------------------------------------------------------------------------- /samples/firm_update/firm_update.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is dual-licensed under GPLv3 and a commercial 3 | * license. See the file LICENSE.md distributed with this software for 4 | * full license information. 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | #include "soem/soem.h" 12 | 13 | #define FWBUFSIZE (8 * 1024 * 1024) 14 | 15 | uint8 ob; 16 | uint16 ow; 17 | uint32 data; 18 | char filename[256]; 19 | char filebuffer[FWBUFSIZE]; // 8MB buffer 20 | int filesize; 21 | int j; 22 | uint16 argslave; 23 | boolean forceByteAlignment = FALSE; 24 | 25 | static ecx_contextt ctx; 26 | 27 | int input_bin(char *fname, int *length) 28 | { 29 | FILE *fp; 30 | 31 | int cc = 0, c; 32 | 33 | fp = fopen(fname, "rb"); 34 | if (fp == NULL) 35 | return 0; 36 | while (((c = fgetc(fp)) != EOF) && (cc < FWBUFSIZE)) 37 | filebuffer[cc++] = (uint8)c; 38 | *length = cc; 39 | fclose(fp); 40 | return 1; 41 | } 42 | 43 | void boottest(char *ifname, uint16 slave, char *filename) 44 | { 45 | printf("Starting firmware update example\n"); 46 | 47 | /* initialise SOEM, bind socket to ifname */ 48 | if (ecx_init(&ctx, ifname)) 49 | { 50 | printf("ecx_init on %s succeeded.\n", ifname); 51 | 52 | /* find and auto-config slaves */ 53 | if (ecx_config_init(&ctx) > 0) 54 | { 55 | printf("%d slaves found and configured.\n", ctx.slavecount); 56 | 57 | /* wait for all slaves to reach PRE_OP state */ 58 | ecx_statecheck(&ctx, 0, EC_STATE_PRE_OP, EC_TIMEOUTSTATE * 4); 59 | 60 | printf("Request init state for slave %d\n", slave); 61 | ctx.slavelist[slave].state = EC_STATE_INIT; 62 | ecx_writestate(&ctx, slave); 63 | 64 | /* wait for slave to reach INIT state */ 65 | ecx_statecheck(&ctx, slave, EC_STATE_INIT, EC_TIMEOUTSTATE * 4); 66 | printf("Slave %d state to INIT.\n", slave); 67 | 68 | /* read BOOT mailbox data, master -> slave */ 69 | data = ecx_readeeprom(&ctx, slave, ECT_SII_BOOTRXMBX, EC_TIMEOUTEEP); 70 | ctx.slavelist[slave].SM[0].StartAddr = (uint16)LO_WORD(data); 71 | ctx.slavelist[slave].SM[0].SMlength = (uint16)HI_WORD(data); 72 | /* store boot write mailbox address */ 73 | ctx.slavelist[slave].mbx_wo = (uint16)LO_WORD(data); 74 | /* store boot write mailbox size */ 75 | ctx.slavelist[slave].mbx_l = (uint16)HI_WORD(data); 76 | 77 | /* read BOOT mailbox data, slave -> master */ 78 | data = ecx_readeeprom(&ctx, slave, ECT_SII_BOOTTXMBX, EC_TIMEOUTEEP); 79 | ctx.slavelist[slave].SM[1].StartAddr = (uint16)LO_WORD(data); 80 | ctx.slavelist[slave].SM[1].SMlength = (uint16)HI_WORD(data); 81 | /* store boot read mailbox address */ 82 | ctx.slavelist[slave].mbx_ro = (uint16)LO_WORD(data); 83 | /* store boot read mailbox size */ 84 | ctx.slavelist[slave].mbx_rl = (uint16)HI_WORD(data); 85 | 86 | printf(" SM0 A:%4.4x L:%4d F:%8.8x\n", ctx.slavelist[slave].SM[0].StartAddr, ctx.slavelist[slave].SM[0].SMlength, 87 | (int)ctx.slavelist[slave].SM[0].SMflags); 88 | printf(" SM1 A:%4.4x L:%4d F:%8.8x\n", ctx.slavelist[slave].SM[1].StartAddr, ctx.slavelist[slave].SM[1].SMlength, 89 | (int)ctx.slavelist[slave].SM[1].SMflags); 90 | /* program SM0 mailbox in for slave */ 91 | ecx_FPWR(&ctx.port, ctx.slavelist[slave].configadr, ECT_REG_SM0, sizeof(ec_smt), &ctx.slavelist[slave].SM[0], EC_TIMEOUTRET); 92 | /* program SM1 mailbox out for slave */ 93 | ecx_FPWR(&ctx.port, ctx.slavelist[slave].configadr, ECT_REG_SM1, sizeof(ec_smt), &ctx.slavelist[slave].SM[1], EC_TIMEOUTRET); 94 | 95 | printf("Request BOOT state for slave %d\n", slave); 96 | ctx.slavelist[slave].state = EC_STATE_BOOT; 97 | ecx_writestate(&ctx, slave); 98 | 99 | /* wait for slave to reach BOOT state */ 100 | if (ecx_statecheck(&ctx, slave, EC_STATE_BOOT, EC_TIMEOUTSTATE * 10) == EC_STATE_BOOT) 101 | { 102 | printf("Slave %d state to BOOT.\n", slave); 103 | 104 | if (input_bin(filename, &filesize)) 105 | { 106 | printf("File read OK, %d bytes.\n", filesize); 107 | printf("FoE write...."); 108 | j = ecx_FOEwrite(&ctx, slave, filename, 0, filesize, &filebuffer, EC_TIMEOUTSTATE); 109 | printf("result %d.\n", j); 110 | printf("Request init state for slave %d\n", slave); 111 | ctx.slavelist[slave].state = EC_STATE_INIT; 112 | ecx_writestate(&ctx, slave); 113 | } 114 | else 115 | printf("File not read OK.\n"); 116 | } 117 | } 118 | else 119 | { 120 | printf("No slaves found!\n"); 121 | } 122 | printf("End firmware update example, close socket\n"); 123 | /* stop SOEM, close socket */ 124 | ecx_close(&ctx); 125 | } 126 | else 127 | { 128 | printf("No socket connection on %s\nExcecute as root\n", ifname); 129 | } 130 | } 131 | 132 | int main(int argc, char *argv[]) 133 | { 134 | printf("SOEM (Simple Open EtherCAT Master)\nFirmware update example\n"); 135 | 136 | if (argc > 3) 137 | { 138 | argslave = atoi(argv[2]); 139 | boottest(argv[1], argslave, argv[3]); 140 | } 141 | else 142 | { 143 | ec_adaptert *adapter = NULL; 144 | ec_adaptert *head = NULL; 145 | printf("Usage: firm_update ifname1 slave fname\n"); 146 | printf("ifname = eth0 for example\n"); 147 | printf("slave = slave number in EtherCAT order 1..n\n"); 148 | printf("fname = binary file to store in slave\n"); 149 | printf("CAUTION! Using the wrong file can result in a bricked slave!\n"); 150 | 151 | printf("\nAvailable adapters:\n"); 152 | head = adapter = ec_find_adapters(); 153 | while (adapter != NULL) 154 | { 155 | printf(" - %s (%s)\n", adapter->name, adapter->desc); 156 | adapter = adapter->next; 157 | } 158 | ec_free_adapters(head); 159 | } 160 | 161 | printf("End program\n"); 162 | return (0); 163 | } 164 | -------------------------------------------------------------------------------- /contrib/osal/vxworks/osal.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is dual-licensed under GPLv3 and a commercial 3 | * license. See the file LICENSE.md distributed with this software for 4 | * full license information. 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #define timercmp(a, b, CMP) \ 18 | (((a)->tv_sec == (b)->tv_sec) ? ((a)->tv_usec CMP(b)->tv_usec) : ((a)->tv_sec CMP(b)->tv_sec)) 19 | #define timeradd(a, b, result) \ 20 | do \ 21 | { \ 22 | (result)->tv_sec = (a)->tv_sec + (b)->tv_sec; \ 23 | (result)->tv_usec = (a)->tv_usec + (b)->tv_usec; \ 24 | if ((result)->tv_usec >= 1000000) \ 25 | { \ 26 | ++(result)->tv_sec; \ 27 | (result)->tv_usec -= 1000000; \ 28 | } \ 29 | } while (0) 30 | #define timersub(a, b, result) \ 31 | do \ 32 | { \ 33 | (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \ 34 | (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \ 35 | if ((result)->tv_usec < 0) \ 36 | { \ 37 | --(result)->tv_sec; \ 38 | (result)->tv_usec += 1000000; \ 39 | } \ 40 | } while (0) 41 | 42 | #define USECS_PER_SEC 1000000 43 | 44 | /* OBS! config worker threads must have higher prio that task running ec_configuration */ 45 | #define ECAT_TASK_PRIO_HIGH 20 /* Priority for high performance network task */ 46 | #define ECAT_TASK_PRIO_LOW 80 /* Priority for high performance network task */ 47 | #define ECAT_STACK_SIZE 10000 /* Stack size for high performance task */ 48 | static int ecatTaskOptions = VX_SUPERVISOR_MODE | VX_UNBREAKABLE; 49 | static int ecatTaskIndex = 0; 50 | 51 | #ifndef use_task_delay 52 | #define use_task_delay 1 53 | #endif 54 | 55 | int osal_usleep(uint32 usec) 56 | { 57 | #if (use_task_delay == 1) 58 | /* Task delay 0 only yields */ 59 | taskDelay(usec / 1000); 60 | return 0; 61 | #else 62 | /* The suspension may be longer than requested due to the rounding up of 63 | * the request to the timer's resolution or to other scheduling activities 64 | * (e.g., a higher priority task intervenes). 65 | */ 66 | struct timespec ts; 67 | ts.tv_sec = usec / USECS_PER_SEC; 68 | ts.tv_nsec = (usec % USECS_PER_SEC) * 1000; 69 | return nanosleep(&ts, NULL); 70 | #endif 71 | } 72 | 73 | int osal_gettimeofday(struct timeval *tv, struct timezone *tz) 74 | { 75 | struct timespec ts; 76 | int return_value; 77 | (void)tz; /* Not used */ 78 | 79 | /* Use clock_gettime CLOCK_MONOTONIC to a avoid NTP time adjustments */ 80 | return_value = clock_gettime(CLOCK_MONOTONIC, &ts); 81 | tv->tv_sec = ts.tv_sec; 82 | tv->tv_usec = ts.tv_nsec / 1000; 83 | return return_value; 84 | } 85 | 86 | ec_timet osal_current_time(void) 87 | { 88 | struct timeval current_time; 89 | ec_timet return_value; 90 | 91 | osal_gettimeofday(¤t_time, 0); 92 | return_value.sec = current_time.tv_sec; 93 | return_value.usec = current_time.tv_usec; 94 | return return_value; 95 | } 96 | 97 | void osal_time_diff(ec_timet *start, ec_timet *end, ec_timet *diff) 98 | { 99 | if (end->usec < start->usec) 100 | { 101 | diff->sec = end->sec - start->sec - 1; 102 | diff->usec = end->usec + 1000000 - start->usec; 103 | } 104 | else 105 | { 106 | diff->sec = end->sec - start->sec; 107 | diff->usec = end->usec - start->usec; 108 | } 109 | } 110 | 111 | void osal_timer_start(osal_timert *self, uint32 timeout_usec) 112 | { 113 | struct timeval start_time; 114 | struct timeval timeout; 115 | struct timeval stop_time; 116 | 117 | osal_gettimeofday(&start_time, 0); 118 | timeout.tv_sec = timeout_usec / USECS_PER_SEC; 119 | timeout.tv_usec = timeout_usec % USECS_PER_SEC; 120 | timeradd(&start_time, &timeout, &stop_time); 121 | 122 | self->stop_time.sec = stop_time.tv_sec; 123 | self->stop_time.usec = stop_time.tv_usec; 124 | } 125 | 126 | boolean osal_timer_is_expired(osal_timert *self) 127 | { 128 | struct timeval current_time; 129 | struct timeval stop_time; 130 | int is_not_yet_expired; 131 | 132 | osal_gettimeofday(¤t_time, 0); 133 | stop_time.tv_sec = self->stop_time.sec; 134 | stop_time.tv_usec = self->stop_time.usec; 135 | is_not_yet_expired = timercmp(¤t_time, &stop_time, <); 136 | 137 | return is_not_yet_expired == FALSE; 138 | } 139 | 140 | void *osal_malloc(size_t size) 141 | { 142 | return malloc(size); 143 | } 144 | 145 | void osal_free(void *ptr) 146 | { 147 | free(ptr); 148 | } 149 | 150 | int osal_thread_create(void *thandle, int stacksize, void *func, void *param) 151 | { 152 | char task_name[20]; 153 | TASK_ID *tid = (TASK_ID *)thandle; 154 | FUNCPTR func_ptr = func; 155 | _Vx_usr_arg_t arg1 = (_Vx_usr_arg_t)param; 156 | 157 | snprintf(task_name, sizeof(task_name), "worker_%d", ecatTaskIndex++); 158 | 159 | *tid = taskSpawn(task_name, ECAT_TASK_PRIO_LOW, 160 | ecatTaskOptions, ECAT_STACK_SIZE, 161 | func_ptr, arg1, 0, 0, 0, 0, 0, 0, 0, 0, 0); 162 | if (*tid == TASK_ID_ERROR) 163 | { 164 | return 0; 165 | } 166 | 167 | return 1; 168 | } 169 | 170 | int osal_thread_create_rt(void *thandle, int stacksize, void *func, void *param) 171 | { 172 | char task_name[20]; 173 | TASK_ID *tid = (TASK_ID *)thandle; 174 | FUNCPTR func_ptr = func; 175 | _Vx_usr_arg_t arg1 = (_Vx_usr_arg_t)param; 176 | 177 | snprintf(task_name, sizeof(task_name), "worker_rt_%d", ecatTaskIndex++); 178 | 179 | *tid = taskSpawn(task_name, ECAT_TASK_PRIO_HIGH, 180 | ecatTaskOptions, ECAT_STACK_SIZE, 181 | func_ptr, arg1, 0, 0, 0, 0, 0, 0, 0, 0, 0); 182 | 183 | if (*tid == TASK_ID_ERROR) 184 | { 185 | return 0; 186 | } 187 | return 1; 188 | } 189 | -------------------------------------------------------------------------------- /oshw/win32/wpcap/Include/ip6_misc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1993, 1994, 1997 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that: (1) source code distributions 7 | * retain the above copyright notice and this paragraph in its entirety, (2) 8 | * distributions including binary code include the above copyright notice and 9 | * this paragraph in its entirety in the documentation or other materials 10 | * provided with the distribution, and (3) all advertising materials mentioning 11 | * features or use of this software display the following acknowledgement: 12 | * ``This product includes software developed by the University of California, 13 | * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 14 | * the University nor the names of its contributors may be used to endorse 15 | * or promote products derived from this software without specific prior 16 | * written permission. 17 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 18 | * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 19 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 20 | * 21 | * @(#) $Header: /tcpdump/master/libpcap/Win32/Include/ip6_misc.h,v 1.5 2006-01-22 18:02:18 gianluca Exp $ (LBL) 22 | */ 23 | 24 | /* 25 | * This file contains a collage of declarations for IPv6 from FreeBSD not present in Windows 26 | */ 27 | 28 | #include 29 | 30 | #include 31 | 32 | #ifndef __MINGW32__ 33 | #define IN_MULTICAST(a) IN_CLASSD(a) 34 | #endif 35 | 36 | #define IN_EXPERIMENTAL(a) ((((u_int32_t) (a)) & 0xf0000000) == 0xf0000000) 37 | 38 | #define IN_LOOPBACKNET 127 39 | 40 | #if defined(__MINGW32__) && defined(DEFINE_ADDITIONAL_IPV6_STUFF) 41 | /* IPv6 address */ 42 | struct in6_addr 43 | { 44 | union 45 | { 46 | u_int8_t u6_addr8[16]; 47 | u_int16_t u6_addr16[8]; 48 | u_int32_t u6_addr32[4]; 49 | } in6_u; 50 | #define s6_addr in6_u.u6_addr8 51 | #define s6_addr16 in6_u.u6_addr16 52 | #define s6_addr32 in6_u.u6_addr32 53 | #define s6_addr64 in6_u.u6_addr64 54 | }; 55 | 56 | #define IN6ADDR_ANY_INIT { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } 57 | #define IN6ADDR_LOOPBACK_INIT { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } 58 | #endif /* __MINGW32__ */ 59 | 60 | 61 | #if (defined _MSC_VER) || (defined(__MINGW32__) && defined(DEFINE_ADDITIONAL_IPV6_STUFF)) 62 | typedef unsigned short sa_family_t; 63 | #endif 64 | 65 | 66 | #if defined(__MINGW32__) && defined(DEFINE_ADDITIONAL_IPV6_STUFF) 67 | 68 | #define __SOCKADDR_COMMON(sa_prefix) \ 69 | sa_family_t sa_prefix##family 70 | 71 | /* Ditto, for IPv6. */ 72 | struct sockaddr_in6 73 | { 74 | __SOCKADDR_COMMON (sin6_); 75 | u_int16_t sin6_port; /* Transport layer port # */ 76 | u_int32_t sin6_flowinfo; /* IPv6 flow information */ 77 | struct in6_addr sin6_addr; /* IPv6 address */ 78 | }; 79 | 80 | #define IN6_IS_ADDR_V4MAPPED(a) \ 81 | ((((u_int32_t *) (a))[0] == 0) && (((u_int32_t *) (a))[1] == 0) && \ 82 | (((u_int32_t *) (a))[2] == htonl (0xffff))) 83 | 84 | #define IN6_IS_ADDR_MULTICAST(a) (((u_int8_t *) (a))[0] == 0xff) 85 | 86 | #define IN6_IS_ADDR_LINKLOCAL(a) \ 87 | ((((u_int32_t *) (a))[0] & htonl (0xffc00000)) == htonl (0xfe800000)) 88 | 89 | #define IN6_IS_ADDR_LOOPBACK(a) \ 90 | (((u_int32_t *) (a))[0] == 0 && ((u_int32_t *) (a))[1] == 0 && \ 91 | ((u_int32_t *) (a))[2] == 0 && ((u_int32_t *) (a))[3] == htonl (1)) 92 | #endif /* __MINGW32__ */ 93 | 94 | #define ip6_vfc ip6_ctlun.ip6_un2_vfc 95 | #define ip6_flow ip6_ctlun.ip6_un1.ip6_un1_flow 96 | #define ip6_plen ip6_ctlun.ip6_un1.ip6_un1_plen 97 | #define ip6_nxt ip6_ctlun.ip6_un1.ip6_un1_nxt 98 | #define ip6_hlim ip6_ctlun.ip6_un1.ip6_un1_hlim 99 | #define ip6_hops ip6_ctlun.ip6_un1.ip6_un1_hlim 100 | 101 | #define nd_rd_type nd_rd_hdr.icmp6_type 102 | #define nd_rd_code nd_rd_hdr.icmp6_code 103 | #define nd_rd_cksum nd_rd_hdr.icmp6_cksum 104 | #define nd_rd_reserved nd_rd_hdr.icmp6_data32[0] 105 | 106 | /* 107 | * IPV6 extension headers 108 | */ 109 | #define IPPROTO_HOPOPTS 0 /* IPv6 hop-by-hop options */ 110 | #define IPPROTO_IPV6 41 /* IPv6 header. */ 111 | #define IPPROTO_ROUTING 43 /* IPv6 routing header */ 112 | #define IPPROTO_FRAGMENT 44 /* IPv6 fragmentation header */ 113 | #define IPPROTO_ESP 50 /* encapsulating security payload */ 114 | #define IPPROTO_AH 51 /* authentication header */ 115 | #define IPPROTO_ICMPV6 58 /* ICMPv6 */ 116 | #define IPPROTO_NONE 59 /* IPv6 no next header */ 117 | #define IPPROTO_DSTOPTS 60 /* IPv6 destination options */ 118 | #define IPPROTO_PIM 103 /* Protocol Independent Multicast. */ 119 | 120 | #define IPV6_RTHDR_TYPE_0 0 121 | 122 | /* Option types and related macros */ 123 | #define IP6OPT_PAD1 0x00 /* 00 0 00000 */ 124 | #define IP6OPT_PADN 0x01 /* 00 0 00001 */ 125 | #define IP6OPT_JUMBO 0xC2 /* 11 0 00010 = 194 */ 126 | #define IP6OPT_JUMBO_LEN 6 127 | #define IP6OPT_ROUTER_ALERT 0x05 /* 00 0 00101 */ 128 | 129 | #define IP6OPT_RTALERT_LEN 4 130 | #define IP6OPT_RTALERT_MLD 0 /* Datagram contains an MLD message */ 131 | #define IP6OPT_RTALERT_RSVP 1 /* Datagram contains an RSVP message */ 132 | #define IP6OPT_RTALERT_ACTNET 2 /* contains an Active Networks msg */ 133 | #define IP6OPT_MINLEN 2 134 | 135 | #define IP6OPT_BINDING_UPDATE 0xc6 /* 11 0 00110 */ 136 | #define IP6OPT_BINDING_ACK 0x07 /* 00 0 00111 */ 137 | #define IP6OPT_BINDING_REQ 0x08 /* 00 0 01000 */ 138 | #define IP6OPT_HOME_ADDRESS 0xc9 /* 11 0 01001 */ 139 | #define IP6OPT_EID 0x8a /* 10 0 01010 */ 140 | 141 | #define IP6OPT_TYPE(o) ((o) & 0xC0) 142 | #define IP6OPT_TYPE_SKIP 0x00 143 | #define IP6OPT_TYPE_DISCARD 0x40 144 | #define IP6OPT_TYPE_FORCEICMP 0x80 145 | #define IP6OPT_TYPE_ICMP 0xC0 146 | 147 | #define IP6OPT_MUTABLE 0x20 148 | 149 | 150 | #if defined(__MINGW32__) && defined(DEFINE_ADDITIONAL_IPV6_STUFF) 151 | #ifndef EAI_ADDRFAMILY 152 | struct addrinfo { 153 | int ai_flags; /* AI_PASSIVE, AI_CANONNAME */ 154 | int ai_family; /* PF_xxx */ 155 | int ai_socktype; /* SOCK_xxx */ 156 | int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */ 157 | size_t ai_addrlen; /* length of ai_addr */ 158 | char *ai_canonname; /* canonical name for hostname */ 159 | struct sockaddr *ai_addr; /* binary address */ 160 | struct addrinfo *ai_next; /* next structure in linked list */ 161 | }; 162 | #endif 163 | #endif /* __MINGW32__ */ 164 | -------------------------------------------------------------------------------- /osal/osal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is dual-licensed under GPLv3 and a commercial 3 | * license. See the file LICENSE.md distributed with this software for 4 | * full license information. 5 | */ 6 | 7 | #ifndef _osal_ 8 | #define _osal_ 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "osal_defs.h" 15 | #include 16 | #include 17 | 18 | /* General types */ 19 | #ifndef TRUE 20 | #define TRUE 1 21 | #endif 22 | #ifndef FALSE 23 | #define FALSE 0 24 | #endif 25 | typedef uint8_t boolean; 26 | typedef int8_t int8; 27 | typedef int16_t int16; 28 | typedef int32_t int32; 29 | typedef uint8_t uint8; 30 | typedef uint16_t uint16; 31 | typedef uint32_t uint32; 32 | typedef int64_t int64; 33 | typedef uint64_t uint64; 34 | typedef float float32; 35 | typedef double float64; 36 | 37 | typedef struct osal_timer 38 | { 39 | ec_timet stop_time; 40 | } osal_timert; 41 | 42 | /** 43 | * @brief Returns monotonic time from some unspecified moment in the 44 | * past. 45 | * 46 | * This time must be strictly increasing. It is used for time 47 | * intervals measurement. 48 | * 49 | * @param ts Pointer to an ec_timet structure where the time will be 50 | * stored. 51 | */ 52 | void osal_get_monotonic_time(ec_timet *ts); 53 | 54 | /** 55 | * @brief Returns the current time. 56 | * 57 | * This time is used to set the initial EtherCAT network DC time and 58 | * for logging purposes. 59 | * 60 | * @return ec_timet containing the current time. 61 | */ 62 | ec_timet osal_current_time(void); 63 | 64 | /** 65 | * @brief Calculates the difference between two timestamps. 66 | * 67 | * @param start Pointer to the start timestamp. 68 | * @param end Pointer to the end timestamp. 69 | * @param diff Pointer to an ec_timet structure where the difference 70 | * will be stored. 71 | */ 72 | void osal_time_diff(ec_timet *start, ec_timet *end, ec_timet *diff); 73 | 74 | /** 75 | * @brief Starts the timer with a specified timeout. 76 | * 77 | * @param self Pointer to the timer object. 78 | * @param timeout_usec Timeout in microseconds. 79 | */ 80 | void osal_timer_start(osal_timert *self, uint32 timeout_usec); 81 | 82 | /** 83 | * @brief Checks if the timer has expired. 84 | * 85 | * @param self Pointer to the timer object. 86 | * @return True if the timer is expired, false otherwise. 87 | */ 88 | boolean osal_timer_is_expired(osal_timert *self); 89 | 90 | /** 91 | * @brief Sleeps for a specified duration in microseconds. 92 | * 93 | * @param usec Duration in microseconds. 94 | * @return 0 on success, -1 on failure. 95 | */ 96 | int osal_usleep(uint32 usec); 97 | 98 | /** 99 | * @brief Sleeps until the specified monotonic time. 100 | * 101 | * @param ts Pointer to an ec_timet structure representing the 102 | * absolute time to sleep until. 103 | * @return 0 on success, -1 on failure. 104 | */ 105 | int osal_monotonic_sleep(ec_timet *ts); 106 | 107 | /** 108 | * @brief Allocates memory of the specified size. 109 | * 110 | * @param size Size in bytes to allocate. 111 | * @return Pointer to the allocated memory or NULL on failure. 112 | */ 113 | void *osal_malloc(size_t size); 114 | 115 | /** 116 | * @brief Frees the allocated memory. 117 | * 118 | * @param ptr Pointer to the memory to free. 119 | */ 120 | void osal_free(void *ptr); 121 | 122 | /** 123 | * @brief Creates a new thread. 124 | * 125 | * @param thandle Pointer to the thread handle which will store the 126 | * thread ID. 127 | * @param stacksize Size of the stack for the new thread. 128 | * @param func Pointer to the function to execute in the new thread. 129 | * @param param Pointer to parameters to pass to the thread function. 130 | * @return 1 on success, 0 on failure. 131 | */ 132 | int osal_thread_create(void *thandle, int stacksize, void *func, void *param); 133 | 134 | /** 135 | * @brief Creates a new real-time thread. 136 | * 137 | * @param thandle Pointer to the thread handle which will store the 138 | * thread ID. 139 | * @param stacksize Size of the stack for the new thread. 140 | * @param func Pointer to the function to execute in the new thread. 141 | * @param param Pointer to parameters to pass to the thread function. 142 | * @return 1 on success, 0 on failure. 143 | */ 144 | int osal_thread_create_rt(void *thandle, int stacksize, void *func, void *param); 145 | 146 | /** 147 | * @brief Creates a mutex. 148 | * 149 | * @return Pointer to the created mutex or NULL on failure. 150 | */ 151 | void *osal_mutex_create(void); 152 | 153 | /** 154 | * @brief Destroys a mutex. 155 | * 156 | * @param mutex Pointer to the mutex to destroy. 157 | */ 158 | void osal_mutex_destroy(void *mutex); 159 | 160 | /** 161 | * @brief Locks the mutex. 162 | * 163 | * @param mutex Pointer to the mutex to lock. 164 | */ 165 | void osal_mutex_lock(void *mutex); 166 | 167 | /** 168 | * @brief Unlocks the mutex. 169 | * 170 | * @param mutex Pointer to the mutex to unlock. 171 | */ 172 | void osal_mutex_unlock(void *mutex); 173 | 174 | #ifndef osal_timespec_from_usec 175 | #define osal_timespec_from_usec(usec, result) \ 176 | do \ 177 | { \ 178 | (result)->tv_sec = usec / 1000000; \ 179 | (result)->tv_nsec = (usec % 1000000) * 1000; \ 180 | } while (0) 181 | #endif 182 | 183 | #ifndef osal_timespeccmp 184 | #define osal_timespeccmp(a, b, CMP) \ 185 | (((a)->tv_sec == (b)->tv_sec) \ 186 | ? ((a)->tv_nsec CMP(b)->tv_nsec) \ 187 | : ((a)->tv_sec CMP(b)->tv_sec)) 188 | #endif 189 | 190 | #ifndef osal_timespecadd 191 | #define osal_timespecadd(a, b, result) \ 192 | do \ 193 | { \ 194 | (result)->tv_sec = (a)->tv_sec + (b)->tv_sec; \ 195 | (result)->tv_nsec = (a)->tv_nsec + (b)->tv_nsec; \ 196 | if ((result)->tv_nsec >= 1000000000) \ 197 | { \ 198 | ++(result)->tv_sec; \ 199 | (result)->tv_nsec -= 1000000000; \ 200 | } \ 201 | } while (0) 202 | #endif 203 | 204 | #ifndef osal_timespecsub 205 | #define osal_timespecsub(a, b, result) \ 206 | do \ 207 | { \ 208 | (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \ 209 | (result)->tv_nsec = (a)->tv_nsec - (b)->tv_nsec; \ 210 | if ((result)->tv_nsec < 0) \ 211 | { \ 212 | --(result)->tv_sec; \ 213 | (result)->tv_nsec += 1000000000; \ 214 | } \ 215 | } while (0) 216 | #endif 217 | 218 | #ifdef __cplusplus 219 | } 220 | #endif 221 | 222 | #endif 223 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This software is dual-licensed under GPLv3 and a commercial 2 | # license. See the file LICENSE.md distributed with this software for 3 | # full license information. 4 | 5 | cmake_minimum_required(VERSION 3.28) 6 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") 7 | project(SOEM VERSION 2.0.0 LANGUAGES C) 8 | 9 | # Debug enable 10 | option(EC_DEBUG "Enable debug output") 11 | 12 | # Configurable sizes 13 | set(EC_BUFSIZE EC_MAXECATFRAME CACHE STRING "standard frame buffer size in bytes") 14 | set(EC_MAXBUF 16 CACHE STRING "number of frame buffers per channel (tx, rx1 rx2)") 15 | set(EC_MAXEEPBITMAP 128 CACHE STRING "size of EEPROM bitmap cache") 16 | set(EC_MAXEEPBUF "EC_MAXEEPBITMAP << 5" CACHE STRING "size of EEPROM cache buffer") 17 | set(EC_LOGGROUPOFFSET 16 CACHE STRING "default group size in 2^x") 18 | set(EC_MAXELIST 64 CACHE STRING "max. entries in EtherCAT error list") 19 | set(EC_MAXNAME 40 CACHE STRING "max. length of readable name in slavelist and Object Description List") 20 | set(EC_MAXSLAVE 200 CACHE STRING "max. number of slaves in array") 21 | set(EC_MAXGROUP 2 CACHE STRING "max. number of groups") 22 | set(EC_MAXIOSEGMENTS 64 CACHE STRING "max. number of IO segments per group") 23 | set(EC_MAXMBX 1486 CACHE STRING "max. mailbox size") 24 | set(EC_MBXPOOLSIZE 32 CACHE STRING "number of mailboxes in pool") 25 | set(EC_MAXEEPDO 0x200 CACHE STRING "max. eeprom PDO entries") 26 | set(EC_MAXSM 8 CACHE STRING "max. SM used") 27 | set(EC_MAXFMMU 4 CACHE STRING "max. FMMU used") 28 | set(EC_MAXLEN_ADAPTERNAME 128 CACHE STRING "max. adapter name length") 29 | set(EC_MAX_MAPT 1 CACHE STRING " define maximum number of concurrent threads in mapping") 30 | set(EC_MAXODLIST 1024 CACHE STRING "max entries in Object Description list") 31 | set(EC_MAXOELIST 256 CACHE STRING "max entries in Object Entry list") 32 | set(EC_SOE_MAXNAME 60 CACHE STRING "max. length of readable SoE name") 33 | set(EC_SOE_MAXMAPPING 64 CACHE STRING "max. number of SoE mappings") 34 | 35 | # Configurable timeouts and retries 36 | set(EC_TIMEOUTRET 2000 CACHE STRING "timeout value in us for tx frame to return to rx") 37 | set(EC_TIMEOUTRET3 "EC_TIMEOUTRET * 3" CACHE STRING "timeout value in us for safe data transfer, max. triple retry") 38 | set(EC_TIMEOUTSAFE 20000 CACHE STRING "timeout value in us for return \"safe\" variant (f.e. wireless)") 39 | set(EC_TIMEOUTEEP 20000 CACHE STRING "timeout value in us for EEPROM access") 40 | set(EC_TIMEOUTTXM 20000 CACHE STRING "timeout value in us for tx mailbox cycle") 41 | set(EC_TIMEOUTRXM 700000 CACHE STRING "timeout value in us for rx mailbox cycle") 42 | set(EC_TIMEOUTSTATE 2000000 CACHE STRING "timeout value in us for check statechange") 43 | set(EC_DEFAULTRETRIES 3 CACHE STRING "default number of retries if wkc <= 0") 44 | 45 | # MAC addresses 46 | set(EC_PRIMARY_MAC "01:01:01:01:01:01" CACHE STRING "Primary MAC address") 47 | set(EC_SECONDARY_MAC "04:04:04:04:04:04" CACHE STRING "Secondary MAC address") 48 | 49 | if(PROJECT_IS_TOP_LEVEL) 50 | # Make option visible in ccmake, cmake-gui 51 | option(BUILD_SHARED_LIBS "Build shared library" OFF) 52 | option(SOEM_BUILD_SAMPLES "Build samples" ON) 53 | 54 | # Default to release build with debug info 55 | if(NOT CMAKE_BUILD_TYPE) 56 | set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING 57 | "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." 58 | FORCE) 59 | endif(NOT CMAKE_BUILD_TYPE) 60 | 61 | # Default to installing in build directory 62 | if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) 63 | set(CMAKE_INSTALL_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/install 64 | CACHE PATH "Default install path" FORCE) 65 | endif() 66 | 67 | message(STATUS "Current build type is: ${CMAKE_BUILD_TYPE}") 68 | message(STATUS "Current install path is: ${CMAKE_INSTALL_PREFIX}") 69 | message(STATUS "Building for ${CMAKE_SYSTEM_NAME}") 70 | endif() 71 | 72 | # Always use standard .o suffix 73 | set(CMAKE_C_OUTPUT_EXTENSION_REPLACE 1) 74 | set(CMAKE_CXX_OUTPUT_EXTENSION_REPLACE 1) 75 | 76 | add_library(soem 77 | src/ec_base.c 78 | src/ec_coe.c 79 | src/ec_config.c 80 | src/ec_dc.c 81 | src/ec_eoe.c 82 | src/ec_foe.c 83 | src/ec_main.c 84 | src/ec_print.c 85 | src/ec_soe.c 86 | ) 87 | 88 | target_include_directories(soem PUBLIC 89 | $ 90 | $ 91 | $ 92 | ) 93 | 94 | target_include_directories(soem PUBLIC 95 | $ 96 | $ 97 | ) 98 | 99 | target_compile_definitions(soem PRIVATE 100 | $<$:EC_DEBUG> 101 | $<$:EC_BIG_ENDIAN> 102 | ) 103 | 104 | # Convert mac address to word arrays for use in options file 105 | macro(convert_mac address array) 106 | set(RE_BYTE "([0-9A-Fa-f][0-9A-Fa-f])") 107 | string(REGEX REPLACE 108 | "^${RE_BYTE}:${RE_BYTE}:${RE_BYTE}:${RE_BYTE}:${RE_BYTE}:${RE_BYTE}$" 109 | "{0x\\1\\2, 0x\\3\\4, 0x\\5\\6}" 110 | ${array} 111 | ${address}) 112 | endmacro() 113 | 114 | convert_mac(${EC_PRIMARY_MAC} EC_PRIMARY_MAC_ARRAY) 115 | convert_mac(${EC_SECONDARY_MAC} EC_SECONDARY_MAC_ARRAY) 116 | 117 | configure_file( 118 | include/soem/ec_options.h.in 119 | ${SOEM_BINARY_DIR}/include/soem/ec_options.h 120 | ) 121 | 122 | install( 123 | TARGETS soem 124 | EXPORT soemConfig 125 | DESTINATION lib 126 | ) 127 | 128 | install( 129 | EXPORT soemConfig 130 | DESTINATION cmake 131 | ) 132 | 133 | install(FILES 134 | include/soem/ec_base.h 135 | include/soem/ec_coe.h 136 | include/soem/ec_config.h 137 | include/soem/ec_dc.h 138 | include/soem/ec_eoe.h 139 | include/soem/ec_foe.h 140 | include/soem/ec_main.h 141 | include/soem/ec_print.h 142 | include/soem/ec_soe.h 143 | include/soem/ec_type.h 144 | include/soem/soem.h 145 | osal/osal.h 146 | ${SOEM_BINARY_DIR}/include/soem/ec_options.h 147 | DESTINATION include/soem 148 | ) 149 | 150 | install(FILES 151 | scripts/eniconv.py 152 | DESTINATION scripts 153 | ) 154 | 155 | install(FILES 156 | cmake/AddENI.cmake 157 | DESTINATION cmake 158 | ) 159 | 160 | install(FILES 161 | README.md 162 | LICENSE.md 163 | DESTINATION . 164 | ) 165 | 166 | if(SOEM_BUILD_SAMPLES) 167 | add_subdirectory(samples/ec_sample) 168 | add_subdirectory(samples/eepromtool) 169 | add_subdirectory(samples/firm_update) 170 | add_subdirectory(samples/simple_ng) 171 | add_subdirectory(samples/slaveinfo) 172 | 173 | if (${CMAKE_SYSTEM_NAME} STREQUAL Linux) 174 | add_subdirectory(samples/eoe_test) 175 | endif() 176 | 177 | find_package (Python3 QUIET) 178 | if (Python3_FOUND) 179 | add_subdirectory(samples/eni_test) 180 | endif() 181 | endif() 182 | 183 | # Platform configuration 184 | include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/${CMAKE_SYSTEM_NAME}.cmake) 185 | 186 | include (InstallRequiredSystemLibraries) 187 | set (CPACK_RESOURCE_FILE_LICENSE "${SOEM_SOURCE_DIR}/LICENSE.md") 188 | set (CPACK_PACKAGE_CONTACT info.soem@rt-labs.com) 189 | set (CPACK_PACKAGE_NAME soem) 190 | set (CPACK_SYSTEM_NAME ${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}) 191 | include (CPack) 192 | -------------------------------------------------------------------------------- /scripts/eniconv.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import argparse 4 | from xml.etree import ElementTree 5 | from sys import stdin, stdout 6 | 7 | ## Simple C generator 8 | 9 | class CGen: 10 | def __init__(self, file, columns = 3, /): 11 | self.file = file 12 | self.tab = " " * columns 13 | self.count = 0 14 | self.content = False 15 | def newline(self): 16 | if self.content: 17 | if self.count > 0: 18 | self.file.write(",\n") 19 | else: 20 | self.file.write(";\n\n") 21 | self.content = False 22 | else: 23 | self.file.write("\n") 24 | def prep(self, line): 25 | if self.content: 26 | self.newline() 27 | self.file.write(f"#{line}\n") 28 | def line(self, line): 29 | self.newline() 30 | self.file.write(self.tab * self.count) 31 | self.file.write(line) 32 | self.content = not not line 33 | def open(self, line = "", c = 1, /): 34 | self.newline() 35 | self.file.write(self.tab * self.count) 36 | if line: 37 | self.file.write(f"{line} = ") 38 | self.file.write("{" * c) 39 | self.count += c 40 | self.content = False 41 | def close(self, c = 1, /): 42 | self.count -= c 43 | self.file.write(f"\n{self.tab * self.count}{'}' * c}") 44 | self.content = True 45 | def comment(self, lines): 46 | for line in [l.rstrip('\\') for l in lines.strip().split("\n")]: 47 | self.newline() 48 | self.file.write(f"{self.tab * self.count}// {line}") 49 | 50 | ## XML parsing convenience 51 | 52 | def getElements(element, path, min = None, max = None, /): 53 | elements = element.findall(f"./{path}") 54 | if (min is not None): 55 | l = len(elements) 56 | if max is not None: 57 | if max < l: 58 | raise(Exception(f"Too many {path} elements.")) 59 | if l < min: 60 | raise(Exception(f"Too few {path} elements.")) 61 | return elements 62 | 63 | def getElement(element, path): 64 | return getElements(element, path, 1, 1)[0] 65 | 66 | def getInt(element, path): 67 | return int(getElement(element, path).text, base = 0) 68 | 69 | def getOptInt(element, path, default = None, /): 70 | es = getElements(element, path, 0, 1) 71 | if es: return int(es[0].text, base = 0) 72 | return default 73 | 74 | def getText(element, path): 75 | return getElement(element, path).text 76 | 77 | def getOptText(element, path, default = "", /): 78 | es = getElements(element, path, 0, 1) 79 | if es: return es[0].text 80 | return default 81 | 82 | ## ENI parsing 83 | 84 | def parseCoEInitCmd(element): 85 | if (element.get("CompleteAccess", "0") == "1"): 86 | ca = "TRUE" 87 | else: 88 | ca = "FALSE" 89 | return { 90 | "Comment": getOptText(element, "Comment"), 91 | "Transition": [t.text for t in getElements(element, "Transition")], 92 | "CA": ca, 93 | "Ccs": (0xff & getInt(element, "Ccs")), 94 | "Index": (0xffff & getInt(element, "Index")), 95 | "SubIdx": (0xff & getInt(element, "SubIndex")), 96 | "Timeout": (1000 * getInt(element, "Timeout")), 97 | "Data": list(bytearray.fromhex(getOptText(element, "Data"))) 98 | } 99 | 100 | def parseCoEInitCmds(elements): 101 | return [parseCoEInitCmd(e) for e in elements if getOptText(e, "Disabled") != "1"] 102 | 103 | def parseSlave(element, slave): 104 | return { 105 | "Slave": (0xffff & (1 - getOptInt(element, "Info/AutoIncAddr", (1 - slave)))), 106 | "VendorId": (0xffffffff & getInt(element, "Info/VendorId")), 107 | "ProductCode": (0xffffffff & getInt(element, "Info/ProductCode")), 108 | "RevisionNo": (0xffffffff & getInt(element, "Info/RevisionNo")), 109 | "CoECmds": parseCoEInitCmds(getElements(element, "Mailbox/CoE/InitCmds/InitCmd")) 110 | } 111 | 112 | def parseSlaves(element): 113 | es = getElements(element, "Slave") 114 | return [parseSlave(es[s], (s + 1)) for s in range(len(es))] 115 | 116 | def parseConfig(element): 117 | return {"slave": parseSlaves(element)} 118 | 119 | ## Output generation 120 | 121 | def genTransition(transitions): 122 | tt = ["ECT_ESMTRANS_" + t for t in transitions] 123 | if len(tt) > 1: 124 | return f"({' | '.join(tt)})" 125 | return tt[0] 126 | 127 | def genCoEData(cg, slave, cmds): 128 | cName = f"s{slave}_coeData" 129 | size = sum(len(c["Data"]) for c in cmds) 130 | if size > 0: 131 | cg.open(f"static uint8 {cName}[{size}]") 132 | for data in [c["Data"] for c in cmds if len(c["Data"]) > 0]: 133 | cg.line(", ".join([f"{b}" for b in data])) 134 | cg.close() 135 | size = 0 136 | coeData = list() 137 | for s in [len(c["Data"]) for c in cmds]: 138 | if s > 0: 139 | offset = size 140 | size += s 141 | coeData.append((s, f"({cName} + {offset})")) 142 | else: 143 | coeData.append((0, "NULL")) 144 | return coeData 145 | 146 | def genCoECmds(cg, slave, cmds): 147 | noCoeCmds = len(cmds) 148 | if noCoeCmds == 0: 149 | cName = "NULL" 150 | else: 151 | cName = f"s{slave}_coeCmds" 152 | coeData = genCoEData(cg, slave, cmds) 153 | cg.open(f"static ec_enicoecmdt {cName}[{noCoeCmds}]") 154 | for c, (DataSize, Data) in zip(cmds, coeData): 155 | cg.open() 156 | if c["Comment"]: 157 | cg.comment(c["Comment"]) 158 | cg.line(f".Transition = {genTransition(c['Transition'])}") 159 | for f in ["CA", "Ccs"]: 160 | cg.line(f".{f} = {c[f]}") 161 | cg.line(".Index = 0x{:04X}".format(c["Index"])) 162 | for f in ["SubIdx", "Timeout"]: 163 | cg.line(f".{f} = {c[f]}") 164 | cg.line(f".DataSize = {DataSize}") 165 | cg.line(f".Data = {Data}") 166 | cg.close() 167 | cg.close() 168 | return (noCoeCmds, cName) 169 | 170 | def genSlaves(cg, slaves): 171 | coeList = [genCoECmds(cg, s["Slave"], s["CoECmds"]) for s in slaves] 172 | noSlaves = sum(n > 0 for n, _ in coeList) 173 | if noSlaves == 0: 174 | cName = "NULL" 175 | else: 176 | cName = "eniSlave" 177 | cg.open(f"static ec_enislavet {cName}[{noSlaves}]") 178 | for s, (CoECmdCount, CoECmds) in zip(slaves, coeList): 179 | if CoECmdCount > 0: 180 | cg.open() 181 | for f in ["Slave", "VendorId", "ProductCode", "RevisionNo"]: 182 | cg.line(f".{f} = {s[f]}") 183 | cg.line(f".CoECmds = {CoECmds}") 184 | cg.line(f".CoECmdCount = {CoECmdCount}") 185 | cg.close() 186 | cg.close() 187 | return (noSlaves, cName) 188 | 189 | def genConfig(cg, config): 190 | slaves = sorted(config["slave"], key = lambda s: s["Slave"]) 191 | slavecount, slave = genSlaves(cg, slaves) 192 | cg.open("ec_enit ec_eni") 193 | cg.line(f".slave = {slave}") 194 | cg.line(f".slavecount = {slavecount}") 195 | cg.close() 196 | 197 | def genFile(file, config): 198 | cg = CGen(file) 199 | cg.prep("include \"soem/soem.h\"") 200 | genConfig(cg, config) 201 | cg.newline() 202 | 203 | ## Interface 204 | 205 | def parseENI(file): 206 | tree = ElementTree.parse(file).getroot() 207 | if tree.tag == "EtherCATConfig": 208 | path = "Config" 209 | else: 210 | path = "EtherCATConfig/Config" 211 | return parseConfig(getElement(tree, path)) 212 | 213 | def process(args): 214 | genFile(args.outfile, parseENI(args.eni)) 215 | 216 | ## Program execution 217 | 218 | def parseArgs(): 219 | parser = argparse.ArgumentParser( 220 | description = "Convert an ENI file to a C file suited for an SOEM application.") 221 | parser.add_argument("eni", help = "the ENI file to convert", 222 | type = argparse.FileType("r")) 223 | parser.add_argument("outfile", help = "the output C file", nargs="?", 224 | type = argparse.FileType("w"), default = stdout) 225 | return parser.parse_args() 226 | 227 | try: 228 | process(parseArgs()) 229 | except Exception as e: 230 | raise SystemExit(f"Failure: {e}.") from None 231 | 232 | -------------------------------------------------------------------------------- /include/soem/ec_eoe.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is dual-licensed under GPLv3 and a commercial 3 | * license. See the file LICENSE.md distributed with this software for 4 | * full license information. 5 | */ 6 | 7 | /** \file 8 | * \brief 9 | * Headerfile for ec_foe.c 10 | */ 11 | 12 | #ifndef _ec_eoe_ 13 | #define _ec_eoe_ 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | #include "soem/soem.h" 20 | 21 | /* use maximum size for EOE mailbox data - mbxheader and 2x frameinfo */ 22 | #define EC_MAXEOEDATA (EC_MAXMBX - (sizeof(ec_mbxheadert) + \ 23 | sizeof(uint16_t) + \ 24 | sizeof(uint16_t))) 25 | 26 | /** DNS length according to ETG 1000.6 */ 27 | #define EOE_DNS_NAME_LENGTH 32 28 | /** Ethernet address length not including VLAN */ 29 | #define EOE_ETHADDR_LENGTH 6 30 | /** IPv4 address length */ 31 | #define EOE_IP4_LENGTH sizeof(uint32_t) 32 | 33 | #define EOE_MAKEU32(a, b, c, d) (((uint32_t)((a) & 0xff) << 24) | \ 34 | ((uint32_t)((b) & 0xff) << 16) | \ 35 | ((uint32_t)((c) & 0xff) << 8) | \ 36 | (uint32_t)((d) & 0xff)) 37 | 38 | #if !defined(EC_BIG_ENDIAN) && defined(EC_LITTLE_ENDIAN) 39 | 40 | #define EOE_HTONS(x) ((((x) & 0x00ffUL) << 8) | (((x) & 0xff00UL) >> 8)) 41 | #define EOE_NTOHS(x) EOE_HTONS(x) 42 | #define EOE_HTONL(x) ((((x) & 0x000000ffUL) << 24) | \ 43 | (((x) & 0x0000ff00UL) << 8) | \ 44 | (((x) & 0x00ff0000UL) >> 8) | \ 45 | (((x) & 0xff000000UL) >> 24)) 46 | #define EOE_NTOHL(x) EOE_HTONL(x) 47 | #else 48 | #define EOE_HTONS(x) (x) 49 | #define EOE_NTOHS(x) (x) 50 | #define EOE_HTONL(x) (x) 51 | #define EOE_NTOHL(x) (x) 52 | #endif /* !defined(EC_BIG_ENDIAN) && defined(EC_LITTLE_ENDIAN) */ 53 | 54 | /** Get one byte from the 4-byte address */ 55 | #define eoe_ip4_addr1(ipaddr) (((const uint8_t *)(&(ipaddr)->addr))[0]) 56 | #define eoe_ip4_addr2(ipaddr) (((const uint8_t *)(&(ipaddr)->addr))[1]) 57 | #define eoe_ip4_addr3(ipaddr) (((const uint8_t *)(&(ipaddr)->addr))[2]) 58 | #define eoe_ip4_addr4(ipaddr) (((const uint8_t *)(&(ipaddr)->addr))[3]) 59 | 60 | /** Set an IP address given by the four byte-parts */ 61 | #define EOE_IP4_ADDR_TO_U32(ipaddr, a, b, c, d) \ 62 | (ipaddr)->addr = EOE_HTONL(EOE_MAKEU32(a, b, c, d)) 63 | 64 | /** Header frame info 1 */ 65 | #define EOE_HDR_FRAME_TYPE_OFFSET 0 66 | #define EOE_HDR_FRAME_TYPE (0xF << 0) 67 | #define EOE_HDR_FRAME_TYPE_SET(x) (((x) & 0xF) << 0) 68 | #define EOE_HDR_FRAME_TYPE_GET(x) (((x) >> 0) & 0xF) 69 | #define EOE_HDR_FRAME_PORT_OFFSET 4 70 | #define EOE_HDR_FRAME_PORT (0xF << 4) 71 | #define EOE_HDR_FRAME_PORT_SET(x) ((uint16)(((x) & 0xF) << 4)) 72 | #define EOE_HDR_FRAME_PORT_GET(x) (((x) >> 4) & 0xF) 73 | #define EOE_HDR_LAST_FRAGMENT_OFFSET 8 74 | #define EOE_HDR_LAST_FRAGMENT (0x1 << 8) 75 | #define EOE_HDR_LAST_FRAGMENT_SET(x) (((x) & 0x1) << 8) 76 | #define EOE_HDR_LAST_FRAGMENT_GET(x) (((x) >> 8) & 0x1) 77 | #define EOE_HDR_TIME_APPEND_OFFSET 9 78 | #define EOE_HDR_TIME_APPEND (0x1 << 9) 79 | #define EOE_HDR_TIME_APPEND_SET(x) (((x) & 0x1) << 9) 80 | #define EOE_HDR_TIME_APPEND_GET(x) (((x) >> 9) & 0x1) 81 | #define EOE_HDR_TIME_REQUEST_OFFSET 10 82 | #define EOE_HDR_TIME_REQUEST (0x1 << 10) 83 | #define EOE_HDR_TIME_REQUEST_SET(x) (((x) & 0x1) << 10) 84 | #define EOE_HDR_TIME_REQUEST_GET(x) (((x) >> 10) & 0x1) 85 | 86 | /** Header frame info 2 */ 87 | #define EOE_HDR_FRAG_NO_OFFSET 0 88 | #define EOE_HDR_FRAG_NO (0x3F << 0) 89 | #define EOE_HDR_FRAG_NO_SET(x) ((uint16)(((x) & 0x3F) << 0)) 90 | #define EOE_HDR_FRAG_NO_GET(x) (((x) >> 0) & 0x3F) 91 | #define EOE_HDR_FRAME_OFFSET_OFFSET 6 92 | #define EOE_HDR_FRAME_OFFSET (0x3F << 6) 93 | #define EOE_HDR_FRAME_OFFSET_SET(x) ((uint16)(((x) & 0x3F) << 6)) 94 | #define EOE_HDR_FRAME_OFFSET_GET(x) (((x) >> 6) & 0x3F) 95 | #define EOE_HDR_FRAME_NO_OFFSET 12 96 | #define EOE_HDR_FRAME_NO (0xF << 12) 97 | #define EOE_HDR_FRAME_NO_SET(x) ((uint16)(((x) & 0xF) << 12)) 98 | #define EOE_HDR_FRAME_NO_GET(x) (((x) >> 12) & 0xF) 99 | 100 | /** EOE param */ 101 | #define EOE_PARAM_OFFSET 4 102 | #define EOE_PARAM_MAC_INCLUDE (0x1 << 0) 103 | #define EOE_PARAM_IP_INCLUDE (0x1 << 1) 104 | #define EOE_PARAM_SUBNET_IP_INCLUDE (0x1 << 2) 105 | #define EOE_PARAM_DEFAULT_GATEWAY_INCLUDE (0x1 << 3) 106 | #define EOE_PARAM_DNS_IP_INCLUDE (0x1 << 4) 107 | #define EOE_PARAM_DNS_NAME_INCLUDE (0x1 << 5) 108 | 109 | /** EoE frame types */ 110 | #define EOE_FRAG_DATA 0 111 | #define EOE_INIT_RESP_TIMESTAMP 1 112 | #define EOE_INIT_REQ 2 /* Spec SET IP REQ */ 113 | #define EOE_INIT_RESP 3 /* Spec SET IP RESP */ 114 | #define EOE_SET_ADDR_FILTER_REQ 4 115 | #define EOE_SET_ADDR_FILTER_RESP 5 116 | #define EOE_GET_IP_PARAM_REQ 6 117 | #define EOE_GET_IP_PARAM_RESP 7 118 | #define EOE_GET_ADDR_FILTER_REQ 8 119 | #define EOE_GET_ADDR_FILTER_RESP 9 120 | 121 | /** EoE parameter result codes */ 122 | #define EOE_RESULT_SUCCESS 0x0000 123 | #define EOE_RESULT_UNSPECIFIED_ERROR 0x0001 124 | #define EOE_RESULT_UNSUPPORTED_FRAME_TYPE 0x0002 125 | #define EOE_RESULT_NO_IP_SUPPORT 0x0201 126 | #define EOE_RESULT_NO_DHCP_SUPPORT 0x0202 127 | #define EOE_RESULT_NO_FILTER_SUPPORT 0x0401 128 | 129 | /** EOE ip4 address in network order */ 130 | typedef struct eoe_ip4_addr 131 | { 132 | uint32_t addr; 133 | } eoe_ip4_addr_t; 134 | 135 | /** EOE ethernet address */ 136 | OSAL_PACKED_BEGIN 137 | typedef struct OSAL_PACKED eoe_ethaddr 138 | { 139 | uint8_t addr[EOE_ETHADDR_LENGTH]; 140 | } eoe_ethaddr_t; 141 | OSAL_PACKED_END 142 | 143 | /** EoE IP request structure, storage only, no need to pack */ 144 | typedef struct eoe_param 145 | { 146 | uint8_t mac_set : 1; 147 | uint8_t ip_set : 1; 148 | uint8_t subnet_set : 1; 149 | uint8_t default_gateway_set : 1; 150 | uint8_t dns_ip_set : 1; 151 | uint8_t dns_name_set : 1; 152 | eoe_ethaddr_t mac; 153 | eoe_ip4_addr_t ip; 154 | eoe_ip4_addr_t subnet; 155 | eoe_ip4_addr_t default_gateway; 156 | eoe_ip4_addr_t dns_ip; 157 | char dns_name[EOE_DNS_NAME_LENGTH]; 158 | } eoe_param_t; 159 | 160 | /** EOE structure. 161 | * Used to interpret EoE mailbox packets. 162 | */ 163 | OSAL_PACKED_BEGIN 164 | typedef struct OSAL_PACKED 165 | { 166 | ec_mbxheadert mbxheader; 167 | uint16_t frameinfo1; 168 | union 169 | { 170 | uint16_t frameinfo2; 171 | uint16_t result; 172 | }; 173 | uint8 data[EC_MAXEOEDATA]; 174 | } ec_EOEt; 175 | OSAL_PACKED_END 176 | 177 | int ecx_EOEdefinehook(ecx_contextt *context, void *hook); 178 | int ecx_EOEsetIp(ecx_contextt *context, 179 | uint16 slave, 180 | uint8 port, 181 | eoe_param_t *ipparam, 182 | int timeout); 183 | int ecx_EOEgetIp(ecx_contextt *context, 184 | uint16 slave, 185 | uint8 port, 186 | eoe_param_t *ipparam, 187 | int timeout); 188 | int ecx_EOEsend(ecx_contextt *context, 189 | uint16 slave, 190 | uint8 port, 191 | int psize, 192 | void *p, 193 | int timeout); 194 | int ecx_EOErecv(ecx_contextt *context, 195 | uint16 slave, 196 | uint8 port, 197 | int *psize, 198 | void *p, 199 | int timeout); 200 | int ecx_EOEreadfragment( 201 | ec_mbxbuft *MbxIn, 202 | uint8 *rxfragmentno, 203 | uint16 *rxframesize, 204 | uint16 *rxframeoffset, 205 | uint16 *rxframeno, 206 | int *psize, 207 | void *p); 208 | 209 | #ifdef __cplusplus 210 | } 211 | #endif 212 | 213 | #endif 214 | -------------------------------------------------------------------------------- /samples/eni_test/eni_test.c: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \brief Example code for Simple Open EtherCAT master 3 | * 4 | * Usage : eni_test [ifname1] 5 | * ifname is NIC interface, f.e. eth0 6 | * 7 | * This is a minimal test. 8 | * 9 | * (c)Arthur Ketels 2010 - 2011 10 | */ 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | #include "soem/soem.h" 17 | 18 | #define EC_TIMEOUTMON 500 19 | 20 | static uint8 IOmap[4096]; 21 | static OSAL_THREAD_HANDLE thread1; 22 | static int expectedWKC; 23 | static boolean needlf; 24 | static volatile int wkc; 25 | static boolean inOP; 26 | static uint8 currentgroup = 0; 27 | 28 | extern ec_enit ec_eni; 29 | 30 | static ecx_contextt ctx = { 31 | .ENI = &ec_eni, 32 | }; 33 | 34 | void eni_test(char *ifname) 35 | { 36 | int i, j, oloop, iloop, chk; 37 | needlf = FALSE; 38 | inOP = FALSE; 39 | 40 | printf("Starting eni test\n"); 41 | 42 | /* initialise SOEM, bind socket to ifname */ 43 | if (ecx_init(&ctx, ifname)) 44 | { 45 | printf("ecx_init on %s succeeded.\n", ifname); 46 | 47 | /* find and auto-config slaves */ 48 | if (ecx_config_init(&ctx) > 0) 49 | { 50 | ec_groupt *group = &ctx.grouplist[0]; 51 | 52 | ecx_config_map_group(&ctx, IOmap, 0); 53 | 54 | ecx_configdc(&ctx); 55 | 56 | printf("%d slaves found and configured.\n", ctx.slavecount); 57 | 58 | /* wait for all slaves to reach SAFE_OP state */ 59 | ecx_statecheck(&ctx, 0, EC_STATE_SAFE_OP, EC_TIMEOUTSTATE * 4); 60 | 61 | oloop = group->Obytes; 62 | if (oloop > 8) oloop = 8; 63 | iloop = group->Ibytes; 64 | if (iloop > 8) iloop = 8; 65 | 66 | printf("segments : %d : %d %d %d %d\n", group->nsegments, group->IOsegment[0], group->IOsegment[1], group->IOsegment[2], group->IOsegment[3]); 67 | 68 | printf("Request operational state for all slaves\n"); 69 | expectedWKC = (group->outputsWKC * 2) + group->inputsWKC; 70 | printf("Calculated workcounter %d\n", expectedWKC); 71 | ctx.slavelist[0].state = EC_STATE_OPERATIONAL; 72 | /* send one valid process data to make outputs in slaves happy*/ 73 | ecx_send_processdata(&ctx); 74 | ecx_receive_processdata(&ctx, EC_TIMEOUTRET); 75 | /* request OP state for all slaves */ 76 | ecx_writestate(&ctx, 0); 77 | chk = 200; 78 | /* wait for all slaves to reach OP state */ 79 | do 80 | { 81 | ecx_send_processdata(&ctx); 82 | ecx_receive_processdata(&ctx, EC_TIMEOUTRET); 83 | ecx_statecheck(&ctx, 0, EC_STATE_OPERATIONAL, 50000); 84 | } while (chk-- && (ctx.slavelist[0].state != EC_STATE_OPERATIONAL)); 85 | if (ctx.slavelist[0].state == EC_STATE_OPERATIONAL) 86 | { 87 | printf("Operational state reached for all slaves.\n"); 88 | inOP = TRUE; 89 | /* cyclic loop */ 90 | for (i = 1; i <= 10000; i++) 91 | { 92 | ecx_send_processdata(&ctx); 93 | wkc = ecx_receive_processdata(&ctx, EC_TIMEOUTRET); 94 | 95 | if (wkc >= expectedWKC) 96 | { 97 | printf("Processdata cycle %4d, WKC %d , O:", i, wkc); 98 | 99 | for (j = 0; j < oloop; j++) 100 | { 101 | printf(" %2.2x", *(ctx.slavelist[0].outputs + j)); 102 | } 103 | 104 | printf(" I:"); 105 | for (j = 0; j < iloop; j++) 106 | { 107 | printf(" %2.2x", *(ctx.slavelist[0].inputs + j)); 108 | } 109 | printf(" T:%" PRId64 "\r", ctx.DCtime); 110 | needlf = TRUE; 111 | } 112 | osal_usleep(5000); 113 | } 114 | inOP = FALSE; 115 | } 116 | else 117 | { 118 | printf("Not all slaves reached operational state.\n"); 119 | ecx_readstate(&ctx); 120 | for (i = 1; i <= ctx.slavecount; i++) 121 | { 122 | ec_slavet *slave = &ctx.slavelist[i]; 123 | if (slave->state != EC_STATE_OPERATIONAL) 124 | { 125 | printf("Slave %d State=0x%2.2x StatusCode=0x%4.4x : %s\n", 126 | i, slave->state, slave->ALstatuscode, ec_ALstatuscode2string(slave->ALstatuscode)); 127 | } 128 | } 129 | } 130 | printf("\nRequest init state for all slaves\n"); 131 | ctx.slavelist[0].state = EC_STATE_INIT; 132 | /* request INIT state for all slaves */ 133 | ecx_writestate(&ctx, 0); 134 | } 135 | else 136 | { 137 | printf("No slaves found!\n"); 138 | } 139 | printf("End eni test, close socket\n"); 140 | /* stop SOEM, close socket */ 141 | ecx_close(&ctx); 142 | } 143 | else 144 | { 145 | printf("No socket connection on %s\nExecute as root\n", ifname); 146 | } 147 | } 148 | 149 | OSAL_THREAD_FUNC ecatcheck(void *ptr) 150 | { 151 | int slaveix; 152 | (void)ptr; /* Not used */ 153 | 154 | while (1) 155 | { 156 | if (inOP && ((wkc < expectedWKC) || ctx.grouplist[currentgroup].docheckstate)) 157 | { 158 | printf("check wkc=%d/%d docheckstate=%d!\n", wkc, expectedWKC, ctx.grouplist[currentgroup].docheckstate); 159 | if (needlf) 160 | { 161 | needlf = FALSE; 162 | printf("\n"); 163 | } 164 | /* one or more slaves are not responding */ 165 | ctx.grouplist[currentgroup].docheckstate = FALSE; 166 | ecx_readstate(&ctx); 167 | for (slaveix = 1; slaveix <= ctx.slavecount; slaveix++) 168 | { 169 | ec_slavet *slave = &ctx.slavelist[slaveix]; 170 | 171 | if ((slave->group == currentgroup) && (slave->state != EC_STATE_OPERATIONAL)) 172 | { 173 | ctx.grouplist[currentgroup].docheckstate = TRUE; 174 | if (slave->state == (EC_STATE_SAFE_OP + EC_STATE_ERROR)) 175 | { 176 | printf("ERROR : slave %d is in SAFE_OP + ERROR, attempting ack.\n", slaveix); 177 | slave->state = (EC_STATE_SAFE_OP + EC_STATE_ACK); 178 | ecx_writestate(&ctx, slaveix); 179 | } 180 | else if (slave->state == EC_STATE_SAFE_OP) 181 | { 182 | printf("WARNING : slave %d is in SAFE_OP, change to OPERATIONAL.\n", slaveix); 183 | slave->state = EC_STATE_OPERATIONAL; 184 | if (slave->mbxhandlerstate == ECT_MBXH_LOST) slave->mbxhandlerstate = ECT_MBXH_CYCLIC; 185 | ecx_writestate(&ctx, slaveix); 186 | } 187 | else if (slave->state > EC_STATE_NONE) 188 | { 189 | if (ecx_reconfig_slave(&ctx, slaveix, EC_TIMEOUTMON) >= EC_STATE_PRE_OP) 190 | { 191 | slave->islost = FALSE; 192 | printf("MESSAGE : slave %d reconfigured\n", slaveix); 193 | } 194 | } 195 | else if (!slave->islost) 196 | { 197 | /* re-check state */ 198 | ecx_statecheck(&ctx, slaveix, EC_STATE_OPERATIONAL, EC_TIMEOUTRET); 199 | if (slave->state == EC_STATE_NONE) 200 | { 201 | slave->islost = TRUE; 202 | slave->mbxhandlerstate = ECT_MBXH_LOST; 203 | /* zero input data for this slave */ 204 | if (slave->Ibytes) 205 | { 206 | memset(slave->inputs, 0x00, slave->Ibytes); 207 | printf("zero inputs %p %d\n\r", slave->inputs, slave->Ibytes); 208 | } 209 | printf("ERROR : slave %d lost\n", slaveix); 210 | } 211 | } 212 | } 213 | if (slave->islost) 214 | { 215 | if (slave->state <= EC_STATE_INIT) 216 | { 217 | if (ecx_recover_slave(&ctx, slaveix, EC_TIMEOUTMON)) 218 | { 219 | slave->islost = FALSE; 220 | printf("MESSAGE : slave %d recovered\n", slaveix); 221 | } 222 | } 223 | else 224 | { 225 | slave->islost = FALSE; 226 | printf("MESSAGE : slave %d found\n", slaveix); 227 | } 228 | } 229 | } 230 | if (!ctx.grouplist[currentgroup].docheckstate) 231 | printf("OK : all slaves resumed OPERATIONAL.\n"); 232 | } 233 | osal_usleep(10000); 234 | } 235 | } 236 | 237 | int main(int argc, char *argv[]) 238 | { 239 | printf("SOEM (Simple Open EtherCAT Master)\nENI test\n"); 240 | 241 | if (argc > 1) 242 | { 243 | /* create thread to handle slave error handling in OP */ 244 | osal_thread_create(&thread1, 128000, &ecatcheck, NULL); 245 | /* start cyclic part */ 246 | eni_test(argv[1]); 247 | } 248 | else 249 | { 250 | ec_adaptert *adapter = NULL; 251 | ec_adaptert *head = NULL; 252 | printf("Usage: eni_test ifname1\nifname = eth0 for example\n"); 253 | 254 | printf("\nAvailable adapters:\n"); 255 | head = adapter = ec_find_adapters(); 256 | while (adapter != NULL) 257 | { 258 | printf(" - %s (%s)\n", adapter->name, adapter->desc); 259 | adapter = adapter->next; 260 | } 261 | ec_free_adapters(head); 262 | } 263 | 264 | printf("End program\n"); 265 | return (0); 266 | } 267 | --------------------------------------------------------------------------------