├── .gitattributes ├── .gitignore ├── .travis.yml ├── CMakeLists.txt ├── ChangeLog ├── Doxyfile ├── LICENSE ├── README.md ├── appveyor.yml ├── cmake ├── Modules │ └── Platform │ │ ├── rt-kernel-C.cmake │ │ ├── rt-kernel-gcc-bfin.cmake │ │ ├── rt-kernel-gcc-kinetis.cmake │ │ ├── rt-kernel-gcc.cmake │ │ ├── rt-kernel.cmake │ │ └── rtems.cmake └── Toolchains │ ├── rt-kernel-bfin.cmake │ └── rt-kernel-kinetis.cmake ├── doc ├── images │ ├── legacy_iomap.png │ ├── memory_layout.png │ └── overlapping_iomap.png ├── soem.dox └── tutorial.txt ├── drvcomment.txt ├── fsoe ├── doc │ └── fsoe_refman.pdf ├── fsoeapp.h ├── fsoeexport.h ├── fsoemaster.h ├── fsoeoptions.h ├── fsoeslave.h ├── fsoetypes.h └── lib │ ├── linux │ └── libfsoe.a │ └── win32 │ └── fsoe.lib ├── osal ├── erika │ ├── osal.c │ └── osal_defs.h ├── intime │ ├── osal.c │ └── osal_defs.h ├── linux │ ├── osal.c │ └── osal_defs.h ├── macosx │ ├── osal.c │ └── osal_defs.h ├── osal.h ├── rtems │ ├── osal.c │ └── osal_defs.h ├── rtk │ ├── osal.c │ └── osal_defs.h ├── vxworks │ ├── osal.c │ └── osal_defs.h └── win32 │ ├── inttypes.h │ ├── osal.c │ ├── osal_defs.h │ ├── osal_win32.h │ └── stdint.h ├── oshw ├── erika │ ├── nicdrv.c │ ├── nicdrv.h │ ├── oshw.c │ └── oshw.h ├── intime │ ├── nicdrv.c │ ├── nicdrv.h │ ├── oshw.c │ └── oshw.h ├── linux │ ├── nicdrv.c │ ├── nicdrv.h │ ├── oshw.c │ └── oshw.h ├── macosx │ ├── nicdrv.c │ ├── nicdrv.h │ ├── oshw.c │ └── oshw.h ├── rtems │ ├── nicdrv.c │ ├── nicdrv.h │ ├── oshw.c │ └── oshw.h ├── rtk │ ├── fec │ │ ├── fec_ecat.c │ │ └── fec_ecat.h │ ├── lw_mac │ │ ├── lw_emac.c │ │ └── lw_emac.h │ ├── nicdrv.c │ ├── nicdrv.h │ ├── oshw.c │ └── oshw.h ├── vxworks │ ├── nicdrv.c │ ├── nicdrv.h │ ├── oshw.c │ └── oshw.h └── win32 │ ├── nicdrv.c │ ├── nicdrv.h │ ├── oshw.c │ ├── oshw.h │ └── wpcap │ ├── Include │ ├── Packet32.h │ ├── Win32-Extensions.h │ ├── bittypes.h │ ├── ip6_misc.h │ ├── pcap-bpf.h │ ├── pcap-namedb.h │ ├── pcap-stdinc.h │ ├── pcap.h │ ├── pcap │ │ ├── bluetooth.h │ │ ├── bpf.h │ │ ├── namedb.h │ │ ├── pcap.h │ │ ├── sll.h │ │ ├── usb.h │ │ └── vlan.h │ └── remote-ext.h │ └── Lib │ ├── Packet.lib │ ├── libpacket.a │ ├── libwpcap.a │ ├── wpcap.lib │ └── x64 │ ├── Packet.lib │ └── wpcap.lib ├── soem ├── ethercat.h ├── ethercatbase.c ├── ethercatbase.h ├── ethercatcoe.c ├── ethercatcoe.h ├── ethercatconfig.c ├── ethercatconfig.h ├── ethercatconfiglist.h ├── ethercatdc.c ├── ethercatdc.h ├── ethercateoe.c ├── ethercateoe.h ├── ethercatfoe.c ├── ethercatfoe.h ├── ethercatmain.c ├── ethercatmain.h ├── ethercatprint.c ├── ethercatprint.h ├── ethercatsoe.c ├── ethercatsoe.h └── ethercattype.h └── test ├── intime └── ec_master │ └── ec_master.c ├── linux ├── aliastool.c ├── ebox │ └── ebox.c ├── eepromtool │ ├── CMakeLists.txt │ └── eepromtool.c ├── eoe_test │ └── eoe_test.c ├── firm_update │ └── firm_update.c ├── fsoe_sample │ ├── CMakeLists.txt │ └── fsoe_sample.c ├── red_test │ └── red_test.c ├── simple_test │ ├── CMakeLists.txt │ └── simple_test.c └── slaveinfo │ ├── CMakeLists.txt │ └── slaveinfo.c ├── rtk ├── main.c └── schedule.tt └── win32 ├── ebox └── ebox.c ├── eepromtool └── eepromtool.c ├── firm_update └── firm_update.c ├── red_test └── red_test.c ├── simple_test └── simple_test.c └── slaveinfo └── slaveinfo.c /.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 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build* 2 | install 3 | *~ 4 | /doc/latex 5 | /doc/html 6 | tags 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | 3 | script: 4 | - mkdir build 5 | - pushd build 6 | - cmake .. -DCMAKE_BUILD_TYPE=Release 7 | - make install 8 | - popd 9 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.4) 2 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules") 3 | project(SOEM C) 4 | 5 | if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) 6 | # Default to installing in SOEM source directory 7 | set(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR}/install) 8 | endif() 9 | 10 | set(SOEM_INCLUDE_INSTALL_DIR include/soem) 11 | set(SOEM_LIB_INSTALL_DIR lib) 12 | set(BUILD_TESTS TRUE) 13 | 14 | if(WIN32) 15 | set(OS "win32") 16 | include_directories(oshw/win32/wpcap/Include) 17 | if(CMAKE_SIZEOF_VOID_P EQUAL 8) 18 | link_directories(${CMAKE_SOURCE_DIR}/oshw/win32/wpcap/Lib/x64) 19 | elseif(CMAKE_SIZEOF_VOID_P EQUAL 4) 20 | link_directories(${CMAKE_SOURCE_DIR}/oshw/win32/wpcap/Lib) 21 | endif() 22 | link_directories(${CMAKE_SOURCE_DIR}/fsoe/lib/win32) 23 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /D _CRT_SECURE_NO_WARNINGS") 24 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX") 25 | set(OS_LIBS wpcap.lib Packet.lib Ws2_32.lib Winmm.lib fsoe.lib) 26 | elseif(UNIX AND NOT APPLE) 27 | set(OS "linux") 28 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Werror") 29 | set(OS_LIBS pthread rt fsoe) 30 | link_directories(${CMAKE_SOURCE_DIR}/fsoe/lib/linux) 31 | elseif(APPLE) 32 | # This must come *before* linux or MacOSX will identify as Unix. 33 | set(OS "macosx") 34 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Werror") 35 | set(OS_LIBS pthread pcap) 36 | elseif(${CMAKE_SYSTEM_NAME} MATCHES "rt-kernel") 37 | set(OS "rtk") 38 | message("ARCH is ${ARCH}") 39 | message("BSP is ${BSP}") 40 | include_directories(oshw/${OS}/${ARCH}) 41 | file(GLOB OSHW_EXTRA_SOURCES oshw/${OS}/${ARCH}/*.c) 42 | set(OSHW_SOURCES "${OS_HW_SOURCES} ${OSHW_ARCHSOURCES}") 43 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Werror") 44 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-but-set-variable") 45 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-function") 46 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-format") 47 | set(OS_LIBS "-Wl,--start-group -l${BSP} -l${ARCH} -lkern -ldev -lsio -lblock -lfs -lusb -llwip -leth -li2c -lrtc -lcan -lnand -lspi -lnor -lpwm -ladc -ltrace -lc -lm -Wl,--end-group") 48 | elseif(${CMAKE_SYSTEM_NAME} MATCHES "rtems") 49 | message("Building for RTEMS") 50 | set(OS "rtems") 51 | set(SOEM_LIB_INSTALL_DIR ${LIB_DIR}) 52 | set(BUILD_TESTS FALSE) 53 | endif() 54 | 55 | message("OS is ${OS}") 56 | 57 | file(GLOB SOEM_SOURCES soem/*.c) 58 | file(GLOB OSAL_SOURCES osal/${OS}/*.c) 59 | file(GLOB OSHW_SOURCES oshw/${OS}/*.c) 60 | 61 | file(GLOB SOEM_HEADERS soem/*.h) 62 | file(GLOB OSAL_HEADERS osal/osal.h osal/${OS}/*.h) 63 | file(GLOB OSHW_HEADERS oshw/${OS}/*.h) 64 | 65 | include_directories(soem) 66 | include_directories(osal) 67 | include_directories(osal/${OS}) 68 | include_directories(oshw/${OS}) 69 | include_directories(fsoe) 70 | 71 | add_library(soem STATIC 72 | ${SOEM_SOURCES} 73 | ${OSAL_SOURCES} 74 | ${OSHW_SOURCES} 75 | ${OSHW_EXTRA_SOURCES}) 76 | target_link_libraries(soem ${OS_LIBS}) 77 | 78 | message("LIB_DIR: ${SOEM_LIB_INSTALL_DIR}") 79 | 80 | install(TARGETS soem DESTINATION ${SOEM_LIB_INSTALL_DIR}) 81 | install(FILES 82 | ${SOEM_HEADERS} 83 | ${OSAL_HEADERS} 84 | ${OSHW_HEADERS} 85 | DESTINATION ${SOEM_INCLUDE_INSTALL_DIR}) 86 | 87 | if(BUILD_TESTS) 88 | add_subdirectory(test/linux/slaveinfo) 89 | add_subdirectory(test/linux/eepromtool) 90 | add_subdirectory(test/linux/simple_test) 91 | add_subdirectory(test/linux/fsoe_sample) 92 | endif() 93 | -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- 1 | Version 1.1.2 : 2008-12-23 2 | - First public release 3 | Version 1.1.3 : 2009-01-18 4 | - Added CoE, RxPDO and TxPDO (still Beta) 5 | - Added FoE, Read and Write (still Beta) 6 | - Fixed BigEndian conversion missing in ethercatconfig.c (credit:Serge Bloch) 7 | - Fixed segmented transfer bug in ethercatcoe.c 8 | Version 1.1.4 : 2009-04-22 9 | - Changed FMMU configuration algorithm 10 | - Changed ec_slave structure around SM and FMMU storage 11 | - Added SYNC1 configuration 12 | - Fixed bug in FoE write 13 | Version 1.2.0 : 2009-09-12 14 | - Changed the license to GPLv2 only 15 | - Added note to usage terms (please read carefully) 16 | - Eeprom acces is released to slave after preop 17 | - Fixed linux-64 define bug (uint32 and int32) 18 | - Fixed maximum frame size 19 | Version 1.2.2 : 2010-02-22 20 | - Fixed bugs in ec_adddatagram. 21 | - Fixed several bugs in CoE object dictionary read functions. 22 | - Fixed bug in PDO mapping read function. 23 | - Changed ec_slave structure around topology and delay variables. 24 | - Added several constants in ethercattype.c 25 | Version 1.2.3 : 2010-03-07 26 | - Clear SM enable if size is 0, even if enable is set in SII. 27 | - Fixed bug in DC propagation delay calculation. Branches with only non DC slaves now correctly close root port. 28 | - Fixed bug in ec_receive_processdata(), wkc now checks for EC_NOFRAME instead of 0. 29 | - Fixed bug in makefile 30 | Version 1.2.4 : 2010-04-10 31 | - Added SoE, servo over EtherCAT support. 32 | - Added SoE read request and write request. 33 | - Added SoE segmented transfers. 34 | - Added SoE error response. 35 | - Added SoE errors to print module. 36 | - Added Auto config of SoE process data. 37 | Version 1.2.5 : 2011-06-13 38 | - Added eepromtool, it can read and write the ESC eeprom of a designated slave. 39 | - Rewrite of eeprom read/write functions. 40 | - Added infrastructure change to allow slave groups. 41 | - Added recovery and reconfiguration of slaves after connection loss. 42 | - Improved CoE PDO assignment read from slaves, no longer assume assign indexes as functionally fixed. 43 | - Fixed bugs in ec_config_map(). 44 | - Added EC_STATE_BOOT constant. 45 | - Fixed mailbox size bug, In and Out mailbox can now be of different size. 46 | - Fixed SM type bug. 47 | - Fixed FoE bugs. 48 | - Fixed siigetbyte() unaligned copy. 49 | - Fixed bug in nicdrv.c, socket handles are 0 included. 50 | - Fixed bug in ethercatconfig.c causing memory corruption. 51 | Version 1.2.8 : 2012-06-14 52 | - Changed directory structure. 53 | - Changed make file. 54 | - Moved hardware / OS dependend part in separate directories. 55 | - Added firm_update tool to upload firmware to slaves in Boot state, use with care. 56 | - Added DC for LRD/LWR case. 57 | - Separated expectedWKC to inputsWKC and outputsWKC. 58 | - Added PreOP->SafeOP hooks in configuration functions. 59 | - With CoE use expedited download if mailbox size is very small and object <= 4 bytes. 60 | - Fixed NetX mailbox configuration behaviour. 61 | - Fixed FoE write bug. 62 | - Added mailbox error handling. 63 | - Fixed SII string read bug. 64 | - Fixed bug in table lookup for printing 65 | - Rewrite of ec_recover_slave() and ec_reconfigure_slave() 66 | - Added -map option in slaveinfo, shows SOEM IO mapping of all slaves found. 67 | Version 1.3.0 : 2013-02-24 68 | - Added win32 target. 69 | - Added rtk target. 70 | - Compiles under gcc / visual-c / borland-c. 71 | - Multiple port support. One master can run concurrent stacks on multiple network ports. 72 | - All global vars are encapsulated in context struct. 73 | - All timing abstracted in osal.c. 74 | - Linux timing converted to get_clock(CLOCK_MONOTONIC). 75 | - Error messages updated to latest ETG1020 document. 76 | - FoE transfers now support busy response. 77 | - Fixed NetX100 configuration behaviour. 78 | - Fixed linux gettimeofday() to get_clock(). 79 | - Fixed eeprom cache flush on reinit. 80 | - Fixed make for new gcc linker version. 81 | Version 1.3.1 : 2015-03-11 82 | - Added intime target. 83 | - Added rtk\fec target. 84 | - Compiles under gcc / visual-c / borland-c / intime. 85 | - Added multi-threaded configuration for parallel configurations of slaves 86 | Version 1.3.2 : 2018-02-02 87 | - Made a mistake. DON'T USE! 88 | Version 1.3.3 : 2018-02-02 89 | - Added rtems target. 90 | - Added support for overlapping IOmap. 91 | 92 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | FSoE - FailSafe over EtherCAT libraries and headers 2 | 3 | Copyright (c) 2019 rt-labs AB, Sweden. 4 | FailSafe over EtherCAT libraries and headers are available under a commercial 5 | license. Please contact sales@rt-labs.com for further details. 6 | 7 | ----------------------------------------------------------------------------- 8 | 9 | Simple Open EtherCAT Master Library 10 | 11 | Copyright (C) 2005-2017 Speciaal Machinefabriek Ketels v.o.f. 12 | Copyright (C) 2005-2017 Arthur Ketels 13 | Copyright (C) 2008-2009 TU/e Technische Universiteit Eindhoven 14 | Copyright (C) 2009-2017 rt-labs AB, Sweden 15 | 16 | SOEM is free software; you can redistribute it and/or modify it under the terms 17 | of the GNU General Public License version 2 as published by the Free Software 18 | Foundation. 19 | 20 | SOEM is distributed in the hope that it will be useful, but WITHOUT ANY 21 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 22 | PARTICULAR PURPOSE. See the GNU General Public License for more details. 23 | 24 | As a special exception, if other files instantiate templates or use macros or 25 | inline functions from this file, or you compile this file and link it with other 26 | works to produce a work based on this file, this file does not by itself cause 27 | the resulting work to be covered by the GNU General Public License. However the 28 | source code for this file must still be made available in accordance with 29 | section (3) of the GNU General Public License. 30 | 31 | This exception does not invalidate any other reasons why a work based on this 32 | file might be covered by the GNU General Public License. 33 | 34 | The EtherCAT Technology, the trade name and logo "EtherCAT" are the intellectual 35 | property of, and protected by Beckhoff Automation GmbH. You can use SOEM for the 36 | sole purpose of creating, using and/or selling or otherwise distributing an 37 | EtherCAT network master provided that an EtherCAT Master License is obtained 38 | from Beckhoff Automation GmbH. 39 | 40 | In case you did not receive a copy of the EtherCAT Master License along with 41 | SOEM write to Beckhoff Automation GmbH, Eiserstrasse 5, D-33415 Verl, Germany 42 | (www.beckhoff.com). 43 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SOEM including Safety over EtherCAT (FSoE) DEMO 2 | 3 | IMPORTANT 4 | ======== 5 | * The FSoE sample is for demonstration purpose only, to implement an FSoE Device one must follow applicable guidelines and specifications. Good start: https://www.ethercat.org/ETG5101. 6 | * Build and run test\linux\fsoe_sample as legacy SOEM samples 7 | * The FSoE stack is provided as a pre-built library for Linux and Windows. For more information or support for other targets please visit: https://rt-labs.com/products/safety-over-ethercat-fsoe/ 8 | 9 | BUILDING 10 | ======== 11 | 12 | Prerequisites for all platforms 13 | ------------------------------- 14 | 15 | * CMake 2.8.0 or later 16 | 17 | 18 | Windows (Visual Studio) 19 | ----------------------- 20 | 21 | * Start a Visual Studio command prompt then: 22 | * `mkdir build` 23 | * `cd build` 24 | * `cmake .. -G "NMake Makefiles"` 25 | * `nmake` 26 | 27 | Linux 28 | -------------- 29 | 30 | * `mkdir build` 31 | * `cd build` 32 | * `cmake ..` 33 | * `make` 34 | 35 | Documentation 36 | ------------- 37 | 38 | SOEM See https://openethercatsociety.github.io/doc/soem/ 39 | 40 | FSoE See https://github.com/rtlabs-com/fsoe-soem-demo/blob/master/fsoe/doc/fsoe_refman.pdf 41 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | version: "{build}" 2 | 3 | install: 4 | - cmd: '"C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /x86' 5 | 6 | build_script: 7 | - cmd: mkdir build 8 | - cmd: cd build 9 | - cmd: cmake .. -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release 10 | - cmd: nmake install 11 | -------------------------------------------------------------------------------- /cmake/Modules/Platform/rt-kernel-C.cmake: -------------------------------------------------------------------------------- 1 | 2 | message("rt-kernel-C.cmake") 3 | 4 | # Determine toolchain 5 | include(CMakeForceCompiler) 6 | 7 | if(${ARCH} MATCHES "kinetis") 8 | cmake_force_c_compiler(arm-eabi-gcc GNU) 9 | cmake_force_cxx_compiler(arm-eabi-g++ GNU) 10 | elseif(${ARCH} MATCHES "bfin") 11 | cmake_force_c_compiler(bfin-elf-gcc GNU) 12 | cmake_force_cxx_compiler(bfin-elf-g++ GNU) 13 | endif() 14 | -------------------------------------------------------------------------------- /cmake/Modules/Platform/rt-kernel-gcc-bfin.cmake: -------------------------------------------------------------------------------- 1 | 2 | set(MACHINE "-mcpu=bf537") 3 | set(LDFLAGS "-T${RT_KERNEL_PATH}/bsp/${BSP}/${BSP}.ld") 4 | -------------------------------------------------------------------------------- /cmake/Modules/Platform/rt-kernel-gcc-kinetis.cmake: -------------------------------------------------------------------------------- 1 | 2 | message("rt-kernel-gcc-kinetis.cmake") 3 | 4 | #SET_PROPERTY(GLOBAL PROPERTY ARCH kinetis) 5 | #SET_PROPERTY(GLOBAL PROPERTY BSP twrk60) 6 | 7 | set(MACHINE "-mfpu=vfp -mcpu=cortex-m3 -mthumb") 8 | -------------------------------------------------------------------------------- /cmake/Modules/Platform/rt-kernel-gcc.cmake: -------------------------------------------------------------------------------- 1 | 2 | message("rt-kernel-gcc.cmake") 3 | 4 | set(CMAKE_C_OUTPUT_EXTENSION .o) 5 | set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS FALSE) 6 | 7 | set(CFLAGS "${CFLAGS} -Wall -Wextra -Wno-unused-parameter -Werror") 8 | set(CFLAGS "${CFLAGS} -fomit-frame-pointer -fno-strict-aliasing -fshort-wchar") 9 | #set(CFLAGS" ${CFLAGS} -B$(GCC_PATH)/libexec/gcc") 10 | 11 | set(CXXFLAGS "${CXXFLAGS} -fno-rtti -fno-exceptions") 12 | 13 | set(LDFLAGS "${LDFLAGS} -nostartfiles") 14 | 15 | set(CMAKE_C_FLAGS "${CFLAGS} ${MACHINE}" CACHE STRING "") 16 | set(CMAKE_EXE_LINKER_FLAGS "${MACHINE} ${LDFLAGS}" CACHE STRING "") 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /cmake/Modules/Platform/rt-kernel.cmake: -------------------------------------------------------------------------------- 1 | if(__RTK_CMAKE_INCLUDED) 2 | return() 3 | endif() 4 | set(__RTK_CMAKE_INCLUDED TRUE) 5 | message("rt-kernel.cmake") 6 | 7 | include_directories( 8 | ${RT_KERNEL_PATH}/include 9 | ${RT_KERNEL_PATH}/include/kern 10 | ${RT_KERNEL_PATH}/kern 11 | ${RT_KERNEL_PATH}/include/drivers 12 | ${RT_KERNEL_PATH}/include/arch/${ARCH} 13 | ${RT_KERNEL_PATH}/bsp/${BSP}/include 14 | ${RT_KERNEL_PATH}/lwip/src/include 15 | ${RT_KERNEL_PATH}/lwip/src/include/ipv4 16 | ) 17 | 18 | link_directories( 19 | ${RT_KERNEL_PATH}/lib/${ARCH} 20 | ) 21 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /cmake/Toolchains/rt-kernel-bfin.cmake: -------------------------------------------------------------------------------- 1 | 2 | message("rt-kernel-kinetis.cmake") 3 | 4 | set(CMAKE_SYSTEM_NAME rt-kernel) 5 | set(CMAKE_SYSTEM_VERSION 1) 6 | set(CMAKE_SYSTEM_PROCESSOR bfin) 7 | 8 | set(ARCH bfin CACHE STRING "Architecture") 9 | set(BSP stamp537 CACHE STRING "Board") 10 | -------------------------------------------------------------------------------- /cmake/Toolchains/rt-kernel-kinetis.cmake: -------------------------------------------------------------------------------- 1 | 2 | message("rt-kernel-kinetis.cmake") 3 | 4 | set(CMAKE_SYSTEM_NAME rt-kernel) 5 | set(CMAKE_SYSTEM_VERSION 1) 6 | set(CMAKE_SYSTEM_PROCESSOR kinetis) 7 | 8 | set(ARCH kinetis CACHE STRING "Architecture") 9 | set(BSP twrk60 CACHE STRING "Board") 10 | -------------------------------------------------------------------------------- /doc/images/legacy_iomap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rtlabs-com/fsoe-soem-demo/89cb5a926fd2310ff6c27660ecd328dc18467aec/doc/images/legacy_iomap.png -------------------------------------------------------------------------------- /doc/images/memory_layout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rtlabs-com/fsoe-soem-demo/89cb5a926fd2310ff6c27660ecd328dc18467aec/doc/images/memory_layout.png -------------------------------------------------------------------------------- /doc/images/overlapping_iomap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rtlabs-com/fsoe-soem-demo/89cb5a926fd2310ff6c27660ecd328dc18467aec/doc/images/overlapping_iomap.png -------------------------------------------------------------------------------- /drvcomment.txt: -------------------------------------------------------------------------------- 1 | For faster irq response through the NIC/NAPI/Socket layer set for TG3 (at eth0) 2 | ethtool -C eth0 rx-usecs 0 rx-frames 1 tx-usecs 0 tx-frames 1 3 | -------------------------------------------------------------------------------- /fsoe/doc/fsoe_refman.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rtlabs-com/fsoe-soem-demo/89cb5a926fd2310ff6c27660ecd328dc18467aec/fsoe/doc/fsoe_refman.pdf -------------------------------------------------------------------------------- /fsoe/fsoeexport.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef FSOE_EXPORT_H 3 | #define FSOE_EXPORT_H 4 | 5 | #ifdef FSOE_STATIC_DEFINE 6 | # define FSOE_EXPORT 7 | # define FSOE_NO_EXPORT 8 | #else 9 | # ifndef FSOE_EXPORT 10 | # ifdef fsoe_EXPORTS 11 | /* We are building this library */ 12 | # define FSOE_EXPORT 13 | # else 14 | /* We are using this library */ 15 | # define FSOE_EXPORT 16 | # endif 17 | # endif 18 | 19 | # ifndef FSOE_NO_EXPORT 20 | # define FSOE_NO_EXPORT 21 | # endif 22 | #endif 23 | 24 | #ifndef FSOE_DEPRECATED 25 | # define FSOE_DEPRECATED 26 | #endif 27 | 28 | #ifndef FSOE_DEPRECATED_EXPORT 29 | # define FSOE_DEPRECATED_EXPORT FSOE_EXPORT FSOE_DEPRECATED 30 | #endif 31 | 32 | #ifndef FSOE_DEPRECATED_NO_EXPORT 33 | # define FSOE_DEPRECATED_NO_EXPORT FSOE_NO_EXPORT FSOE_DEPRECATED 34 | #endif 35 | 36 | #if 0 /* DEFINE_NO_DEPRECATED */ 37 | # ifndef FSOE_NO_DEPRECATED 38 | # define FSOE_NO_DEPRECATED 39 | # endif 40 | #endif 41 | 42 | #endif /* FSOE_EXPORT_H */ 43 | -------------------------------------------------------------------------------- /fsoe/fsoeoptions.h: -------------------------------------------------------------------------------- 1 | #ifndef FSOEOPTIONS_H 2 | #define FSOEOPTIONS_H 3 | 4 | #define FSOEOPTIONS_H 5 | 6 | /* Maximum size of FSoE application parameters, in bytes */ 7 | #ifndef FSOE_APPLICATION_PARAMETERS_MAX_SIZE 8 | #define FSOE_APPLICATION_PARAMETERS_MAX_SIZE (256) 9 | #endif 10 | 11 | /* Maximum size of FSoE process data, in bytes */ 12 | #ifndef FSOE_PROCESS_DATA_MAX_SIZE 13 | #define FSOE_PROCESS_DATA_MAX_SIZE (126) 14 | #endif 15 | 16 | #endif /* FSOEOPTIONS_H */ 17 | -------------------------------------------------------------------------------- /fsoe/lib/linux/libfsoe.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rtlabs-com/fsoe-soem-demo/89cb5a926fd2310ff6c27660ecd328dc18467aec/fsoe/lib/linux/libfsoe.a -------------------------------------------------------------------------------- /fsoe/lib/win32/fsoe.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rtlabs-com/fsoe-soem-demo/89cb5a926fd2310ff6c27660ecd328dc18467aec/fsoe/lib/win32/fsoe.lib -------------------------------------------------------------------------------- /osal/erika/osal.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the GNU General Public License version 2 with exceptions. See 3 | * LICENSE file in the project root for full license information 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include "ee_x86_64_tsc.h" 14 | 15 | #define USECS_PER_SEC 1000000 16 | #define NSECS_PER_SEC 1000000000 17 | 18 | uint64_t osEE_x86_64_tsc_read(void); 19 | 20 | void ee_usleep(uint32 usec); 21 | 22 | inline int osal_usleep (uint32 usec) 23 | { 24 | ee_usleep(usec); 25 | return 0; 26 | } 27 | 28 | int osal_gettimeofday(struct timeval *tv, struct timezone *tz) 29 | { 30 | uint64_t time = osEE_x86_64_tsc_read(); 31 | tv->tv_sec = time/NSECS_PER_SEC; 32 | tv->tv_sec += 946684800UL; /* EtherCAT uses 2000-01-01 as epoch start */ 33 | tv->tv_usec = (time%NSECS_PER_SEC)/1000; 34 | return 0; 35 | } 36 | 37 | ec_timet osal_current_time(void) 38 | { 39 | struct timeval current_time; 40 | ec_timet ret; 41 | 42 | osal_gettimeofday(¤t_time, 0); 43 | ret.sec = current_time.tv_sec; 44 | ret.usec = current_time.tv_usec; 45 | return ret; 46 | } 47 | 48 | void osal_time_diff(ec_timet *start, ec_timet *end, ec_timet *diff) 49 | { 50 | if (end->usec < start->usec) { 51 | diff->sec = end->sec - start->sec - 1; 52 | diff->usec = end->usec + USECS_PER_SEC - start->usec; 53 | } else { 54 | diff->sec = end->sec - start->sec; 55 | diff->usec = end->usec - start->usec; 56 | } 57 | } 58 | 59 | void osal_timer_start(osal_timert *self, uint32 timeout_usec) 60 | { 61 | struct timeval start_time; 62 | struct timeval timeout; 63 | struct timeval stop_time; 64 | 65 | osal_gettimeofday(&start_time, 0); 66 | timeout.tv_sec = timeout_usec / USECS_PER_SEC; 67 | timeout.tv_usec = timeout_usec % USECS_PER_SEC; 68 | timeradd(&start_time, &timeout, &stop_time); 69 | 70 | self->stop_time.sec = stop_time.tv_sec; 71 | self->stop_time.usec = stop_time.tv_usec; 72 | } 73 | 74 | boolean osal_timer_is_expired (osal_timert *self) 75 | { 76 | struct timeval current_time; 77 | struct timeval stop_time; 78 | int is_not_yet_expired; 79 | 80 | osal_gettimeofday (¤t_time, 0); 81 | stop_time.tv_sec = self->stop_time.sec; 82 | stop_time.tv_usec = self->stop_time.usec; 83 | is_not_yet_expired = timercmp (¤t_time, &stop_time, <); 84 | /* OSEE_PRINT("current: %d:%d -- expire: %d:%d -- result: %d\n", */ 85 | /* current_time.tv_sec, */ 86 | /* current_time.tv_usec, */ 87 | /* stop_time.tv_sec, */ 88 | /* stop_time.tv_usec, */ 89 | /* is_not_yet_expired); */ 90 | 91 | return is_not_yet_expired == FALSE; 92 | } 93 | 94 | void *osal_malloc(size_t size) 95 | { 96 | return malloc(size); 97 | } 98 | 99 | void osal_free(void *ptr) 100 | { 101 | free(ptr); 102 | } 103 | 104 | -------------------------------------------------------------------------------- /osal/erika/osal_defs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the GNU General Public License version 2 with exceptions. See 3 | * LICENSE file in the project root for full license information 4 | */ 5 | 6 | #ifndef _osal_defs_ 7 | #define _osal_defs_ 8 | 9 | #ifdef __cplusplus 10 | extern "C" 11 | { 12 | #endif 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | // define if debug print is needed 19 | #define EC_DEBUG 20 | 21 | #ifdef EC_DEBUG 22 | #define EC_PRINT OSEE_PRINT 23 | #else 24 | #define EC_PRINT(...) do {} while (0) 25 | #endif 26 | 27 | #ifndef PACKED 28 | #define PACKED_BEGIN 29 | #define PACKED __attribute__((__packed__)) 30 | #define PACKED_END 31 | #endif 32 | 33 | int osal_gettimeofday(struct timeval *tv, struct timezone *tz); 34 | void *osal_malloc(size_t size); 35 | void osal_free(void *ptr); 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /osal/intime/osal.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the GNU General Public License version 2 with exceptions. See 3 | * LICENSE file in the project root for full license information 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | static int64_t sysfrequency; 11 | static double qpc2usec; 12 | 13 | #define USECS_PER_SEC 1000000 14 | 15 | int osal_gettimeofday (struct timeval *tv, struct timezone *tz) 16 | { 17 | return gettimeofday (tv, tz); 18 | } 19 | 20 | ec_timet osal_current_time (void) 21 | { 22 | struct timeval current_time; 23 | ec_timet return_value; 24 | 25 | osal_gettimeofday (¤t_time, 0); 26 | return_value.sec = current_time.tv_sec; 27 | return_value.usec = current_time.tv_usec; 28 | return return_value; 29 | } 30 | 31 | void osal_timer_start (osal_timert * self, uint32 timeout_usec) 32 | { 33 | struct timeval start_time; 34 | struct timeval timeout; 35 | struct timeval stop_time; 36 | 37 | osal_gettimeofday (&start_time, 0); 38 | timeout.tv_sec = timeout_usec / USECS_PER_SEC; 39 | timeout.tv_usec = timeout_usec % USECS_PER_SEC; 40 | timeradd (&start_time, &timeout, &stop_time); 41 | 42 | self->stop_time.sec = stop_time.tv_sec; 43 | self->stop_time.usec = stop_time.tv_usec; 44 | } 45 | 46 | boolean osal_timer_is_expired (osal_timert * self) 47 | { 48 | struct timeval current_time; 49 | struct timeval stop_time; 50 | int is_not_yet_expired; 51 | 52 | osal_gettimeofday (¤t_time, 0); 53 | stop_time.tv_sec = self->stop_time.sec; 54 | stop_time.tv_usec = self->stop_time.usec; 55 | is_not_yet_expired = timercmp (¤t_time, &stop_time, <); 56 | 57 | return is_not_yet_expired == FALSE; 58 | } 59 | 60 | int osal_usleep(uint32 usec) 61 | { 62 | RtSleepEx (usec / 1000); 63 | return 1; 64 | } 65 | 66 | /* Mutex is not needed when running single threaded */ 67 | 68 | void osal_mtx_lock(osal_mutex_t * mtx) 69 | { 70 | /* RtWaitForSingleObject((HANDLE)mtx, INFINITE); */ 71 | } 72 | 73 | void osal_mtx_unlock(osal_mutex_t * mtx) 74 | { 75 | /* RtReleaseMutex((HANDLE)mtx); */ 76 | } 77 | 78 | int osal_mtx_lock_timeout(osal_mutex_t * mtx, uint32_t time_ms) 79 | { 80 | /* return RtWaitForSingleObject((HANDLE)mtx, time_ms); */ 81 | return 0; 82 | } 83 | 84 | osal_mutex_t * osal_mtx_create(void) 85 | { 86 | /* return (void*)RtCreateMutex(NULL, FALSE, NULL); */ 87 | return (void *)0; 88 | } 89 | -------------------------------------------------------------------------------- /osal/intime/osal_defs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the GNU General Public License version 2 with exceptions. See 3 | * LICENSE file in the project root for full license information 4 | */ 5 | 6 | #ifndef _osal_defs_ 7 | #define _osal_defs_ 8 | 9 | #ifdef __cplusplus 10 | extern "C" 11 | { 12 | #endif 13 | 14 | // define if debug printf is needed 15 | //#define EC_DEBUG 16 | 17 | #ifdef EC_DEBUG 18 | #define EC_PRINT printf 19 | #else 20 | #define EC_PRINT(...) do {} while (0) 21 | #endif 22 | 23 | #ifndef PACKED 24 | #ifdef _MSC_VER 25 | #define PACKED_BEGIN __pragma(pack(push, 1)) 26 | #define PACKED 27 | #define PACKED_END __pragma(pack(pop)) 28 | #elif defined(__GNUC__) 29 | #define PACKED_BEGIN 30 | #define PACKED __attribute__((__packed__)) 31 | #define PACKED_END 32 | #endif 33 | #endif 34 | 35 | #define OSAL_THREAD_HANDLE RTHANDLE 36 | #define OSAL_THREAD_FUNC void 37 | #define OSAL_THREAD_FUNC_RT void 38 | 39 | #ifdef __cplusplus 40 | } 41 | #endif 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /osal/linux/osal.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the GNU General Public License version 2 with exceptions. See 3 | * LICENSE file in the project root for full license information 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #define USECS_PER_SEC 1000000 14 | 15 | int osal_usleep (uint32 usec) 16 | { 17 | struct timespec ts; 18 | ts.tv_sec = usec / USECS_PER_SEC; 19 | ts.tv_nsec = (usec % USECS_PER_SEC) * 1000; 20 | /* usleep is deprecated, use nanosleep instead */ 21 | return nanosleep(&ts, NULL); 22 | } 23 | 24 | int osal_gettimeofday(struct timeval *tv, struct timezone *tz) 25 | { 26 | struct timespec ts; 27 | int return_value; 28 | (void)tz; /* Not used */ 29 | 30 | /* Use clock_gettime to prevent possible live-lock. 31 | * Gettimeofday uses CLOCK_REALTIME that can get NTP timeadjust. 32 | * If this function preempts timeadjust and it uses vpage it live-locks. 33 | * Also when using XENOMAI, only clock_gettime is RT safe */ 34 | return_value = clock_gettime(CLOCK_MONOTONIC, &ts); 35 | tv->tv_sec = ts.tv_sec; 36 | tv->tv_usec = ts.tv_nsec / 1000; 37 | return return_value; 38 | } 39 | 40 | ec_timet osal_current_time(void) 41 | { 42 | struct timeval current_time; 43 | ec_timet return_value; 44 | 45 | osal_gettimeofday(¤t_time, 0); 46 | return_value.sec = current_time.tv_sec; 47 | return_value.usec = current_time.tv_usec; 48 | return return_value; 49 | } 50 | 51 | void osal_time_diff(ec_timet *start, ec_timet *end, ec_timet *diff) 52 | { 53 | if (end->usec < start->usec) { 54 | diff->sec = end->sec - start->sec - 1; 55 | diff->usec = end->usec + 1000000 - start->usec; 56 | } 57 | else { 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 | 89 | return is_not_yet_expired == FALSE; 90 | } 91 | 92 | void *osal_malloc(size_t size) 93 | { 94 | return malloc(size); 95 | } 96 | 97 | void osal_free(void *ptr) 98 | { 99 | free(ptr); 100 | } 101 | 102 | int osal_thread_create(void *thandle, int stacksize, void *func, void *param) 103 | { 104 | int ret; 105 | pthread_attr_t attr; 106 | pthread_t *threadp; 107 | 108 | threadp = thandle; 109 | pthread_attr_init(&attr); 110 | pthread_attr_setstacksize(&attr, stacksize); 111 | ret = pthread_create(threadp, &attr, func, param); 112 | if(ret < 0) 113 | { 114 | return 0; 115 | } 116 | return 1; 117 | } 118 | 119 | int osal_thread_create_rt(void *thandle, int stacksize, void *func, void *param) 120 | { 121 | int ret; 122 | pthread_attr_t attr; 123 | struct sched_param schparam; 124 | pthread_t *threadp; 125 | 126 | threadp = thandle; 127 | pthread_attr_init(&attr); 128 | pthread_attr_setstacksize(&attr, stacksize); 129 | ret = pthread_create(threadp, &attr, func, param); 130 | pthread_attr_destroy(&attr); 131 | if(ret < 0) 132 | { 133 | return 0; 134 | } 135 | memset(&schparam, 0, sizeof(schparam)); 136 | schparam.sched_priority = 40; 137 | ret = pthread_setschedparam(*threadp, SCHED_FIFO, &schparam); 138 | if(ret < 0) 139 | { 140 | return 0; 141 | } 142 | 143 | return 1; 144 | } 145 | -------------------------------------------------------------------------------- /osal/linux/osal_defs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the GNU General Public License version 2 with exceptions. See 3 | * LICENSE file in the project root for full license information 4 | */ 5 | 6 | #ifndef _osal_defs_ 7 | #define _osal_defs_ 8 | 9 | #ifdef __cplusplus 10 | extern "C" 11 | { 12 | #endif 13 | 14 | // define if debug printf is needed 15 | //#define EC_DEBUG 16 | 17 | #ifdef EC_DEBUG 18 | #define EC_PRINT printf 19 | #else 20 | #define EC_PRINT(...) do {} while (0) 21 | #endif 22 | 23 | #ifndef PACKED 24 | #define PACKED_BEGIN 25 | #define PACKED __attribute__((__packed__)) 26 | #define PACKED_END 27 | #endif 28 | 29 | #include 30 | #define OSAL_THREAD_HANDLE pthread_t * 31 | #define OSAL_THREAD_FUNC void 32 | #define OSAL_THREAD_FUNC_RT void 33 | 34 | #ifdef __cplusplus 35 | } 36 | #endif 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /osal/macosx/osal.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the GNU General Public License version 2 with exceptions. See 3 | * LICENSE file in the project root for full license information 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #define USECS_PER_SEC 1000000 14 | 15 | int osal_usleep (uint32 usec) 16 | { 17 | struct timespec ts; 18 | ts.tv_sec = usec / USECS_PER_SEC; 19 | ts.tv_nsec = (usec % USECS_PER_SEC) * 1000; 20 | /* usleep is deprecated, use nanosleep instead */ 21 | return nanosleep(&ts, NULL); 22 | } 23 | 24 | int osal_gettimeofday(struct timeval *tv, struct timezone *tz) 25 | { 26 | struct timespec ts; 27 | int return_value; 28 | (void)tz; /* Not used */ 29 | 30 | /* Use clock_gettime to prevent possible live-lock. 31 | * Gettimeofday uses CLOCK_REALTIME that can get NTP timeadjust. 32 | * If this function preempts timeadjust and it uses vpage it live-locks. 33 | * Also when using XENOMAI, only clock_gettime is RT safe */ 34 | return_value = clock_gettime(CLOCK_MONOTONIC, &ts); 35 | tv->tv_sec = ts.tv_sec; 36 | tv->tv_usec = ts.tv_nsec / 1000; 37 | return return_value; 38 | } 39 | 40 | ec_timet osal_current_time(void) 41 | { 42 | struct timeval current_time; 43 | ec_timet return_value; 44 | 45 | osal_gettimeofday(¤t_time, 0); 46 | return_value.sec = current_time.tv_sec; 47 | return_value.usec = current_time.tv_usec; 48 | return return_value; 49 | } 50 | 51 | void osal_time_diff(ec_timet *start, ec_timet *end, ec_timet *diff) 52 | { 53 | if (end->usec < start->usec) { 54 | diff->sec = end->sec - start->sec - 1; 55 | diff->usec = end->usec + 1000000 - start->usec; 56 | } 57 | else { 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 | 89 | return is_not_yet_expired == FALSE; 90 | } 91 | 92 | void *osal_malloc(size_t size) 93 | { 94 | return malloc(size); 95 | } 96 | 97 | void osal_free(void *ptr) 98 | { 99 | free(ptr); 100 | } 101 | 102 | int osal_thread_create(void *thandle, int stacksize, void *func, void *param) 103 | { 104 | int ret; 105 | pthread_attr_t attr; 106 | pthread_t *threadp; 107 | 108 | threadp = thandle; 109 | pthread_attr_init(&attr); 110 | pthread_attr_setstacksize(&attr, stacksize); 111 | ret = pthread_create(threadp, &attr, func, param); 112 | if(ret < 0) 113 | { 114 | return 0; 115 | } 116 | return 1; 117 | } 118 | 119 | int osal_thread_create_rt(void *thandle, int stacksize, void *func, void *param) 120 | { 121 | int ret; 122 | pthread_attr_t attr; 123 | struct sched_param schparam; 124 | pthread_t *threadp; 125 | 126 | threadp = thandle; 127 | pthread_attr_init(&attr); 128 | pthread_attr_setstacksize(&attr, stacksize); 129 | ret = pthread_create(threadp, &attr, func, param); 130 | pthread_attr_destroy(&attr); 131 | if(ret < 0) 132 | { 133 | return 0; 134 | } 135 | memset(&schparam, 0, sizeof(schparam)); 136 | schparam.sched_priority = 40; 137 | ret = pthread_setschedparam(*threadp, SCHED_FIFO, &schparam); 138 | if(ret < 0) 139 | { 140 | return 0; 141 | } 142 | 143 | return 1; 144 | } 145 | -------------------------------------------------------------------------------- /osal/macosx/osal_defs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the GNU General Public License version 2 with exceptions. See 3 | * LICENSE file in the project root for full license information 4 | */ 5 | 6 | #ifndef _osal_defs_ 7 | #define _osal_defs_ 8 | 9 | #ifdef __cplusplus 10 | extern "C" 11 | { 12 | #endif 13 | 14 | // define if debug printf is needed 15 | //#define EC_DEBUG 16 | 17 | #ifdef EC_DEBUG 18 | #define EC_PRINT printf 19 | #else 20 | #define EC_PRINT(...) do {} while (0) 21 | #endif 22 | 23 | #ifndef PACKED 24 | #define PACKED_BEGIN 25 | #define PACKED __attribute__((__packed__)) 26 | #define PACKED_END 27 | #endif 28 | 29 | #include 30 | #define OSAL_THREAD_HANDLE pthread_t * 31 | #define OSAL_THREAD_FUNC void 32 | #define OSAL_THREAD_FUNC_RT void 33 | 34 | #ifdef __cplusplus 35 | } 36 | #endif 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /osal/osal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the GNU General Public License version 2 with exceptions. See 3 | * LICENSE file in the project root for full license information 4 | */ 5 | 6 | #ifndef _osal_ 7 | #define _osal_ 8 | 9 | #ifdef __cplusplus 10 | extern "C" 11 | { 12 | #endif 13 | 14 | #include "osal_defs.h" 15 | #include 16 | 17 | /* General types */ 18 | #ifndef TRUE 19 | #define TRUE 1 20 | #endif 21 | #ifndef FALSE 22 | #define FALSE 0 23 | #endif 24 | typedef uint8_t boolean; 25 | typedef int8_t int8; 26 | typedef int16_t int16; 27 | typedef int32_t int32; 28 | typedef uint8_t uint8; 29 | typedef uint16_t uint16; 30 | typedef uint32_t uint32; 31 | typedef int64_t int64; 32 | typedef uint64_t uint64; 33 | typedef float float32; 34 | typedef double float64; 35 | 36 | typedef struct 37 | { 38 | uint32 sec; /*< Seconds elapsed since the Epoch (Jan 1, 1970) */ 39 | uint32 usec; /*< Microseconds elapsed since last second boundary */ 40 | } ec_timet; 41 | 42 | typedef struct osal_timer 43 | { 44 | ec_timet stop_time; 45 | } osal_timert; 46 | 47 | void osal_timer_start(osal_timert * self, uint32 timeout_us); 48 | boolean osal_timer_is_expired(osal_timert * self); 49 | int osal_usleep(uint32 usec); 50 | ec_timet osal_current_time(void); 51 | void osal_time_diff(ec_timet *start, ec_timet *end, ec_timet *diff); 52 | int osal_thread_create(void *thandle, int stacksize, void *func, void *param); 53 | int osal_thread_create_rt(void *thandle, int stacksize, void *func, void *param); 54 | 55 | #ifdef __cplusplus 56 | } 57 | #endif 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /osal/rtems/osal.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the GNU General Public License version 2 with exceptions. See 3 | * LICENSE file in the project root for full license information 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #define USECS_PER_SEC 1000000 14 | 15 | int osal_usleep (uint32 usec) 16 | { 17 | struct timespec ts; 18 | ts.tv_sec = usec / USECS_PER_SEC; 19 | ts.tv_nsec = (usec % USECS_PER_SEC) * 1000; 20 | /* usleep is deprecated, use nanosleep instead */ 21 | return nanosleep(&ts, NULL); 22 | } 23 | 24 | int osal_gettimeofday(struct timeval *tv, struct timezone *tz) 25 | { 26 | struct timespec ts; 27 | int return_value; 28 | (void)tz; /* Not used */ 29 | 30 | /* Use clock_gettime to prevent possible live-lock. 31 | * Gettimeofday uses CLOCK_REALTIME that can get NTP timeadjust. 32 | * If this function preempts timeadjust and it uses vpage it live-locks. 33 | * Also when using XENOMAI, only clock_gettime is RT safe */ 34 | return_value = clock_gettime(CLOCK_MONOTONIC, &ts); 35 | tv->tv_sec = ts.tv_sec; 36 | tv->tv_usec = ts.tv_nsec / 1000; 37 | return return_value; 38 | } 39 | 40 | ec_timet osal_current_time(void) 41 | { 42 | struct timeval current_time; 43 | ec_timet return_value; 44 | 45 | osal_gettimeofday(¤t_time, 0); 46 | return_value.sec = current_time.tv_sec; 47 | return_value.usec = current_time.tv_usec; 48 | return return_value; 49 | } 50 | 51 | void osal_time_diff(ec_timet *start, ec_timet *end, ec_timet *diff) 52 | { 53 | if (end->usec < start->usec) { 54 | diff->sec = end->sec - start->sec - 1; 55 | diff->usec = end->usec + 1000000 - start->usec; 56 | } 57 | else { 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 | 89 | return is_not_yet_expired == FALSE; 90 | } 91 | 92 | void *osal_malloc(size_t size) 93 | { 94 | return malloc(size); 95 | } 96 | 97 | void osal_free(void *ptr) 98 | { 99 | free(ptr); 100 | } 101 | 102 | int osal_thread_create(void *thandle, int stacksize, void *func, void *param) 103 | { 104 | int ret; 105 | pthread_attr_t attr; 106 | pthread_t *threadp; 107 | 108 | threadp = thandle; 109 | pthread_attr_init(&attr); 110 | pthread_attr_setstacksize(&attr, stacksize); 111 | ret = pthread_create(threadp, &attr, func, param); 112 | if(ret < 0) 113 | { 114 | return 0; 115 | } 116 | return 1; 117 | } 118 | 119 | int osal_thread_create_rt(void *thandle, int stacksize, void *func, void *param) 120 | { 121 | int ret; 122 | pthread_attr_t attr; 123 | struct sched_param schparam; 124 | pthread_t *threadp; 125 | 126 | threadp = thandle; 127 | pthread_attr_init(&attr); 128 | pthread_attr_setstacksize(&attr, stacksize); 129 | ret = pthread_create(threadp, &attr, func, param); 130 | pthread_attr_destroy(&attr); 131 | if(ret < 0) 132 | { 133 | return 0; 134 | } 135 | memset(&schparam, 0, sizeof(schparam)); 136 | schparam.sched_priority = 40; 137 | ret = pthread_setschedparam(*threadp, SCHED_FIFO, &schparam); 138 | if(ret < 0) 139 | { 140 | return 0; 141 | } 142 | 143 | return 1; 144 | } 145 | -------------------------------------------------------------------------------- /osal/rtems/osal_defs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the GNU General Public License version 2 with exceptions. See 3 | * LICENSE file in the project root for full license information 4 | */ 5 | 6 | #ifndef _osal_defs_ 7 | #define _osal_defs_ 8 | 9 | #ifdef __cplusplus 10 | extern "C" 11 | { 12 | #endif 13 | 14 | // define if debug printf is needed 15 | //#define EC_DEBUG 16 | 17 | #ifdef EC_DEBUG 18 | #define EC_PRINT printf 19 | #else 20 | #define EC_PRINT(...) do {} while (0) 21 | #endif 22 | 23 | #ifndef PACKED 24 | #define PACKED_BEGIN 25 | #define PACKED __attribute__((__packed__)) 26 | #define PACKED_END 27 | #endif 28 | 29 | #include 30 | #define OSAL_THREAD_HANDLE pthread_t * 31 | #define OSAL_THREAD_FUNC void 32 | #define OSAL_THREAD_FUNC_RT void 33 | 34 | #ifdef __cplusplus 35 | } 36 | #endif 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /osal/rtk/osal.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the GNU General Public License version 2 with exceptions. See 3 | * LICENSE file in the project root for full license information 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #define timercmp(a, b, CMP) \ 13 | (((a)->tv_sec == (b)->tv_sec) ? \ 14 | ((a)->tv_usec CMP (b)->tv_usec) : \ 15 | ((a)->tv_sec CMP (b)->tv_sec)) 16 | #define timeradd(a, b, result) \ 17 | do { \ 18 | (result)->tv_sec = (a)->tv_sec + (b)->tv_sec; \ 19 | (result)->tv_usec = (a)->tv_usec + (b)->tv_usec; \ 20 | if ((result)->tv_usec >= 1000000) \ 21 | { \ 22 | ++(result)->tv_sec; \ 23 | (result)->tv_usec -= 1000000; \ 24 | } \ 25 | } while (0) 26 | #define timersub(a, b, result) \ 27 | do { \ 28 | (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \ 29 | (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \ 30 | if ((result)->tv_usec < 0) { \ 31 | --(result)->tv_sec; \ 32 | (result)->tv_usec += 1000000; \ 33 | } \ 34 | } while (0) 35 | 36 | #define USECS_PER_SEC 1000000 37 | #define USECS_PER_TICK (USECS_PER_SEC / CFG_TICKS_PER_SECOND) 38 | 39 | 40 | /* Workaround for rt-labs defect 776. 41 | * Default implementation of udelay() didn't work correctly when tick was 42 | * shorter than one millisecond. 43 | */ 44 | void udelay (uint32_t us) 45 | { 46 | tick_t ticks = (us / USECS_PER_TICK) + 1; 47 | task_delay (ticks); 48 | } 49 | 50 | int gettimeofday(struct timeval *tp, void *tzp) 51 | { 52 | tick_t tick = tick_get(); 53 | tick_t ticks_left; 54 | 55 | ASSERT (tp != NULL); 56 | 57 | tp->tv_sec = tick / CFG_TICKS_PER_SECOND; 58 | 59 | ticks_left = tick % CFG_TICKS_PER_SECOND; 60 | tp->tv_usec = ticks_left * USECS_PER_TICK; 61 | ASSERT (tp->tv_usec < USECS_PER_SEC); 62 | 63 | return 0; 64 | } 65 | 66 | int osal_usleep (uint32 usec) 67 | { 68 | udelay(usec); 69 | return 0; 70 | } 71 | 72 | int osal_gettimeofday(struct timeval *tv, struct timezone *tz) 73 | { 74 | return gettimeofday(tv, tz); 75 | } 76 | 77 | ec_timet osal_current_time (void) 78 | { 79 | struct timeval current_time; 80 | ec_timet return_value; 81 | 82 | gettimeofday (¤t_time, 0); 83 | return_value.sec = current_time.tv_sec; 84 | return_value.usec = current_time.tv_usec; 85 | return return_value; 86 | } 87 | 88 | void osal_timer_start (osal_timert * self, uint32 timeout_usec) 89 | { 90 | struct timeval start_time; 91 | struct timeval timeout; 92 | struct timeval stop_time; 93 | 94 | gettimeofday (&start_time, 0); 95 | timeout.tv_sec = timeout_usec / USECS_PER_SEC; 96 | timeout.tv_usec = timeout_usec % USECS_PER_SEC; 97 | timeradd (&start_time, &timeout, &stop_time); 98 | 99 | self->stop_time.sec = stop_time.tv_sec; 100 | self->stop_time.usec = stop_time.tv_usec; 101 | } 102 | 103 | boolean osal_timer_is_expired (osal_timert * self) 104 | { 105 | struct timeval current_time; 106 | struct timeval stop_time; 107 | int is_not_yet_expired; 108 | 109 | gettimeofday (¤t_time, 0); 110 | stop_time.tv_sec = self->stop_time.sec; 111 | stop_time.tv_usec = self->stop_time.usec; 112 | is_not_yet_expired = timercmp (¤t_time, &stop_time, <); 113 | 114 | return is_not_yet_expired == false; 115 | } 116 | 117 | void *osal_malloc(size_t size) 118 | { 119 | return malloc(size); 120 | } 121 | 122 | void osal_free(void *ptr) 123 | { 124 | free(ptr); 125 | } 126 | 127 | int osal_thread_create(void *thandle, int stacksize, void *func, void *param) 128 | { 129 | thandle = task_spawn ("worker", func, 6,stacksize, param); 130 | if(!thandle) 131 | { 132 | return 0; 133 | } 134 | return 1; 135 | } 136 | 137 | int osal_thread_create_rt(void *thandle, int stacksize, void *func, void *param) 138 | { 139 | thandle = task_spawn ("worker_rt", func, 15 ,stacksize, param); 140 | if(!thandle) 141 | { 142 | return 0; 143 | } 144 | return 1; 145 | } 146 | -------------------------------------------------------------------------------- /osal/rtk/osal_defs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the GNU General Public License version 2 with exceptions. See 3 | * LICENSE file in the project root for full license information 4 | */ 5 | 6 | #ifndef _osal_defs_ 7 | #define _osal_defs_ 8 | 9 | #ifdef __cplusplus 10 | extern "C" 11 | { 12 | #endif 13 | 14 | // define if debug printf is needed 15 | //#define EC_DEBUG 16 | 17 | #ifdef EC_DEBUG 18 | #define EC_PRINT printf 19 | #else 20 | #define EC_PRINT(...) do {} while (0) 21 | #endif 22 | 23 | #ifndef PACKED 24 | #define PACKED_BEGIN 25 | #define PACKED __attribute__((__packed__)) 26 | #define PACKED_END 27 | #endif 28 | 29 | #define OSAL_THREAD_HANDLE task_t * 30 | #define OSAL_THREAD_FUNC void 31 | #define OSAL_THREAD_FUNC_RT void 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /osal/vxworks/osal.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the GNU General Public License version 2 with exceptions. See 3 | * LICENSE file in the project root for full license information 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | 17 | #define timercmp(a, b, CMP) \ 18 | (((a)->tv_sec == (b)->tv_sec) ? \ 19 | ((a)->tv_usec CMP (b)->tv_usec) : \ 20 | ((a)->tv_sec CMP (b)->tv_sec)) 21 | #define timeradd(a, b, result) \ 22 | do { \ 23 | (result)->tv_sec = (a)->tv_sec + (b)->tv_sec; \ 24 | (result)->tv_usec = (a)->tv_usec + (b)->tv_usec; \ 25 | if ((result)->tv_usec >= 1000000) \ 26 | { \ 27 | ++(result)->tv_sec; \ 28 | (result)->tv_usec -= 1000000; \ 29 | } \ 30 | } while (0) 31 | #define timersub(a, b, result) \ 32 | do { \ 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 | --(result)->tv_sec; \ 37 | (result)->tv_usec += 1000000; \ 38 | } \ 39 | } while (0) 40 | 41 | #define USECS_PER_SEC 1000000 42 | 43 | /* OBS! config worker threads must have higher prio that task running ec_configuration */ 44 | #define ECAT_TASK_PRIO_HIGH 20 /* Priority for high performance network task */ 45 | #define ECAT_TASK_PRIO_LOW 80 /* Priority for high performance network task */ 46 | #define ECAT_STACK_SIZE 10000 /* Stack size for high performance task */ 47 | static int ecatTaskOptions = VX_SUPERVISOR_MODE | VX_UNBREAKABLE; 48 | static int ecatTaskIndex = 0; 49 | 50 | #ifndef use_task_delay 51 | #define use_task_delay 1 52 | #endif 53 | 54 | int osal_usleep (uint32 usec) 55 | { 56 | #if (use_task_delay == 1) 57 | /* Task delay 0 only yields */ 58 | taskDelay(usec / 1000); 59 | return 0; 60 | #else 61 | /* The suspension may be longer than requested due to the rounding up of 62 | * the request to the timer's resolution or to other scheduling activities 63 | * (e.g., a higher priority task intervenes). 64 | */ 65 | struct timespec ts; 66 | ts.tv_sec = usec / USECS_PER_SEC; 67 | ts.tv_nsec = (usec % USECS_PER_SEC) * 1000; 68 | return nanosleep(&ts, NULL); 69 | #endif 70 | 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 | diff->sec = end->sec - start->sec - 1; 101 | diff->usec = end->usec + 1000000 - start->usec; 102 | } 103 | else { 104 | diff->sec = end->sec - start->sec; 105 | diff->usec = end->usec - start->usec; 106 | } 107 | } 108 | 109 | void osal_timer_start(osal_timert * self, uint32 timeout_usec) 110 | { 111 | struct timeval start_time; 112 | struct timeval timeout; 113 | struct timeval stop_time; 114 | 115 | osal_gettimeofday(&start_time, 0); 116 | timeout.tv_sec = timeout_usec / USECS_PER_SEC; 117 | timeout.tv_usec = timeout_usec % USECS_PER_SEC; 118 | timeradd(&start_time, &timeout, &stop_time); 119 | 120 | self->stop_time.sec = stop_time.tv_sec; 121 | self->stop_time.usec = stop_time.tv_usec; 122 | } 123 | 124 | boolean osal_timer_is_expired (osal_timert * self) 125 | { 126 | struct timeval current_time; 127 | struct timeval stop_time; 128 | int is_not_yet_expired; 129 | 130 | osal_gettimeofday(¤t_time, 0); 131 | stop_time.tv_sec = self->stop_time.sec; 132 | stop_time.tv_usec = self->stop_time.usec; 133 | is_not_yet_expired = timercmp(¤t_time, &stop_time, <); 134 | 135 | return is_not_yet_expired == FALSE; 136 | } 137 | 138 | void *osal_malloc(size_t size) 139 | { 140 | return malloc(size); 141 | } 142 | 143 | void osal_free(void *ptr) 144 | { 145 | free(ptr); 146 | } 147 | 148 | int osal_thread_create(void *thandle, int stacksize, void *func, void *param) 149 | { 150 | char task_name[20]; 151 | TASK_ID * tid = (TASK_ID *)thandle; 152 | FUNCPTR func_ptr = func; 153 | _Vx_usr_arg_t arg1 = (_Vx_usr_arg_t)param; 154 | 155 | snprintf(task_name,sizeof(task_name),"worker_%d",ecatTaskIndex++); 156 | 157 | *tid = taskSpawn (task_name, ECAT_TASK_PRIO_LOW, 158 | ecatTaskOptions, ECAT_STACK_SIZE, 159 | func_ptr, arg1, 0, 0, 0, 0, 0, 0, 0, 0, 0); 160 | if(*tid == TASK_ID_ERROR) 161 | { 162 | return 0; 163 | } 164 | 165 | return 1; 166 | } 167 | 168 | int osal_thread_create_rt(void *thandle, int stacksize, void *func, void *param) 169 | { 170 | char task_name[20]; 171 | TASK_ID * tid = (TASK_ID *)thandle; 172 | FUNCPTR func_ptr = func; 173 | _Vx_usr_arg_t arg1 = (_Vx_usr_arg_t)param; 174 | 175 | snprintf(task_name,sizeof(task_name),"worker_rt_%d",ecatTaskIndex++); 176 | 177 | *tid = taskSpawn (task_name, ECAT_TASK_PRIO_HIGH, 178 | ecatTaskOptions, ECAT_STACK_SIZE, 179 | func_ptr, arg1, 0, 0, 0, 0, 0, 0, 0, 0, 0); 180 | 181 | if(*tid == TASK_ID_ERROR) 182 | { 183 | return 0; 184 | } 185 | return 1; 186 | } 187 | 188 | -------------------------------------------------------------------------------- /osal/vxworks/osal_defs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the GNU General Public License version 2 with exceptions. See 3 | * LICENSE file in the project root for full license information 4 | */ 5 | 6 | #ifndef _osal_defs_ 7 | #define _osal_defs_ 8 | 9 | // define if debug printf is needed 10 | //#define EC_DEBUG 11 | 12 | #ifdef EC_DEBUG 13 | #define EC_PRINT printf 14 | #else 15 | #define EC_PRINT(...) do {} while (0) 16 | #endif 17 | 18 | #ifndef PACKED 19 | #define PACKED_BEGIN 20 | #define PACKED __attribute__((__packed__)) 21 | #define PACKED_END 22 | #endif 23 | 24 | #define OSAL_THREAD_HANDLE TASK_ID 25 | #define OSAL_THREAD_FUNC void 26 | #define OSAL_THREAD_FUNC_RT void 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /osal/win32/osal.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the GNU General Public License version 2 with exceptions. See 3 | * LICENSE file in the project root for full license information 4 | */ 5 | 6 | #include 7 | #include 8 | #include "osal_win32.h" 9 | 10 | static int64_t sysfrequency; 11 | static double qpc2usec; 12 | 13 | #define USECS_PER_SEC 1000000 14 | 15 | int osal_getrelativetime(struct timeval *tv, struct timezone *tz) 16 | { 17 | int64_t wintime, usecs; 18 | if(!sysfrequency) 19 | { 20 | timeBeginPeriod(1); 21 | QueryPerformanceFrequency((LARGE_INTEGER *)&sysfrequency); 22 | qpc2usec = 1000000.0 / sysfrequency; 23 | } 24 | QueryPerformanceCounter((LARGE_INTEGER *)&wintime); 25 | usecs = (int64_t)((double)wintime * qpc2usec); 26 | tv->tv_sec = (long)(usecs / 1000000); 27 | tv->tv_usec = (long)(usecs - (tv->tv_sec * 1000000)); 28 | 29 | return 1; 30 | } 31 | 32 | int osal_gettimeofday(struct timeval *tv, struct timezone *tz) 33 | { 34 | FILETIME system_time; 35 | int64 system_time64, usecs; 36 | 37 | /* The offset variable is required to switch from Windows epoch (January 1, 1601) to 38 | * Unix epoch (January 1, 1970). Number of days between both epochs: 134.774 39 | * 40 | * The time returned by GetSystemTimeAsFileTime() changes in 100 ns steps, so the 41 | * following factors are required for the conversion from days to 100 ns steps: 42 | * 43 | * 86.400 seconds per day; 1.000.000 microseconds per second; 10 * 100 ns per microsecond 44 | */ 45 | int64 offset = -134774LL * 86400LL * 1000000LL * 10LL; 46 | 47 | GetSystemTimeAsFileTime(&system_time); 48 | 49 | system_time64 = ((int64)(system_time.dwHighDateTime) << 32) + (int64)system_time.dwLowDateTime; 50 | system_time64 += offset; 51 | usecs = system_time64 / 10; 52 | 53 | tv->tv_sec = (long)(usecs / 1000000); 54 | tv->tv_usec = (long)(usecs - (tv->tv_sec * 1000000)); 55 | 56 | return 1; 57 | } 58 | 59 | ec_timet osal_current_time (void) 60 | { 61 | struct timeval current_time; 62 | ec_timet return_value; 63 | 64 | osal_gettimeofday (¤t_time, 0); 65 | return_value.sec = current_time.tv_sec; 66 | return_value.usec = current_time.tv_usec; 67 | return return_value; 68 | } 69 | 70 | void osal_time_diff(ec_timet *start, ec_timet *end, ec_timet *diff) 71 | { 72 | if (end->usec < start->usec) { 73 | diff->sec = end->sec - start->sec - 1; 74 | diff->usec = end->usec + 1000000 - start->usec; 75 | } 76 | else { 77 | diff->sec = end->sec - start->sec; 78 | diff->usec = end->usec - start->usec; 79 | } 80 | } 81 | 82 | void osal_timer_start (osal_timert *self, uint32 timeout_usec) 83 | { 84 | struct timeval start_time; 85 | struct timeval timeout; 86 | struct timeval stop_time; 87 | 88 | osal_getrelativetime (&start_time, 0); 89 | timeout.tv_sec = timeout_usec / USECS_PER_SEC; 90 | timeout.tv_usec = timeout_usec % USECS_PER_SEC; 91 | timeradd (&start_time, &timeout, &stop_time); 92 | 93 | self->stop_time.sec = stop_time.tv_sec; 94 | self->stop_time.usec = stop_time.tv_usec; 95 | } 96 | 97 | boolean osal_timer_is_expired (osal_timert *self) 98 | { 99 | struct timeval current_time; 100 | struct timeval stop_time; 101 | int is_not_yet_expired; 102 | 103 | osal_getrelativetime (¤t_time, 0); 104 | stop_time.tv_sec = self->stop_time.sec; 105 | stop_time.tv_usec = self->stop_time.usec; 106 | is_not_yet_expired = timercmp (¤t_time, &stop_time, <); 107 | 108 | return is_not_yet_expired == FALSE; 109 | } 110 | 111 | int osal_usleep(uint32 usec) 112 | { 113 | osal_timert qtime; 114 | osal_timer_start(&qtime, usec); 115 | if(usec >= 1000) 116 | { 117 | SleepEx(usec / 1000, FALSE); 118 | } 119 | while(!osal_timer_is_expired(&qtime)); 120 | return 1; 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 | *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 | -------------------------------------------------------------------------------- /osal/win32/osal_defs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the GNU General Public License version 2 with exceptions. See 3 | * LICENSE file in the project root for full license information 4 | */ 5 | 6 | #ifndef _osal_defs_ 7 | #define _osal_defs_ 8 | 9 | #ifdef __cplusplus 10 | extern "C" 11 | { 12 | #endif 13 | 14 | // define if debug printf is needed 15 | //#define EC_DEBUG 16 | 17 | #ifdef EC_DEBUG 18 | #define EC_PRINT printf 19 | #else 20 | #define EC_PRINT(...) do {} while (0) 21 | #endif 22 | 23 | #ifndef PACKED 24 | #define PACKED_BEGIN __pragma(pack(push, 1)) 25 | #define PACKED 26 | #define PACKED_END __pragma(pack(pop)) 27 | #endif 28 | 29 | #define OSAL_THREAD_HANDLE HANDLE 30 | #define OSAL_THREAD_FUNC void 31 | #define OSAL_THREAD_FUNC_RT void 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /osal/win32/osal_win32.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the GNU General Public License version 2 with exceptions. See 3 | * LICENSE file in the project root for full license information 4 | */ 5 | 6 | #ifndef _osal_win32_ 7 | #define _osal_win32_ 8 | 9 | /* Convenience macros for operations on timevals. 10 | NOTE: `timercmp' does not work for >= or <=. */ 11 | # define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec) 12 | # define timeradd(a, b, result) \ 13 | do { \ 14 | (result)->tv_sec = (a)->tv_sec + (b)->tv_sec; \ 15 | (result)->tv_usec = (a)->tv_usec + (b)->tv_usec; \ 16 | if ((result)->tv_usec >= 1000000) \ 17 | { \ 18 | ++(result)->tv_sec; \ 19 | (result)->tv_usec -= 1000000; \ 20 | } \ 21 | } while (0) 22 | # define timersub(a, b, result) \ 23 | do { \ 24 | (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \ 25 | (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \ 26 | if ((result)->tv_usec < 0) { \ 27 | --(result)->tv_sec; \ 28 | (result)->tv_usec += 1000000; \ 29 | } \ 30 | } while (0) 31 | 32 | int osal_gettimeofday (struct timeval *tv, struct timezone *tz); 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /oshw/erika/nicdrv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the GNU General Public License version 2 with exceptions. See 3 | * LICENSE file in the project root for full license information 4 | */ 5 | 6 | /** \file 7 | * \brief 8 | * Headerfile for nicdrv.c 9 | */ 10 | 11 | #ifndef _nicdrvh_ 12 | #define _nicdrvh_ 13 | 14 | #ifdef __cplusplus 15 | extern "C" 16 | { 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 | int 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 | #ifdef EC_VER1 92 | extern ecx_portt ecx_port; 93 | extern ecx_redportt ecx_redport; 94 | 95 | int ec_setupnic(const char * ifname, int secondary); 96 | int ec_closenic(void); 97 | void ec_setbufstat(int idx, int bufstat); 98 | int ec_getindex(void); 99 | int ec_outframe(int idx, int sock); 100 | int ec_outframe_red(int idx); 101 | int ec_waitinframe(int idx, int timeout); 102 | int ec_srconfirm(int idx,int timeout); 103 | int ec_inframe(int idx, int stacknumber); 104 | #endif 105 | 106 | void ec_setupheader(void *p); 107 | int ecx_setupnic(ecx_portt *port, const char *ifname, int secondary); 108 | int ecx_closenic(ecx_portt *port); 109 | void ecx_setbufstat(ecx_portt *port, int idx, int bufstat); 110 | int ecx_getindex(ecx_portt *port); 111 | int ecx_outframe(ecx_portt *port, int idx, int sock); 112 | int ecx_outframe_red(ecx_portt *port, int idx); 113 | int ecx_waitinframe(ecx_portt *port, int idx, int timeout); 114 | int ecx_srconfirm(ecx_portt *port, int idx,int timeout); 115 | 116 | int ecx_inframe(ecx_portt *port, int idx, int stacknumber); 117 | 118 | #ifdef __cplusplus 119 | } 120 | #endif 121 | 122 | #endif 123 | -------------------------------------------------------------------------------- /oshw/erika/oshw.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the GNU General Public License version 2 with exceptions. See 3 | * LICENSE file in the project root for full license information 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include "oshw.h" 12 | #include "intel_i210.h" 13 | #include "ethercat.h" 14 | 15 | #if !defined(__gnu_linux__) 16 | #include 17 | #else 18 | #include 19 | #define __htons(x) htobe16(x) 20 | #define __ntohs(x) be16toh(x) 21 | #endif 22 | 23 | ec_adaptert adapters [DEVS_MAX_NB]; 24 | 25 | /** 26 | * Host to Network byte order (i.e. to big endian). 27 | * 28 | * Note that Ethercat uses little endian byte order, except for the Ethernet 29 | * header which is big endian as usual. 30 | */ 31 | inline uint16 oshw_htons(uint16 host) 32 | { 33 | // __htons() is provided by the bare-metal x86 compiler 34 | return __htons(host); 35 | } 36 | 37 | /** 38 | * Network (i.e. big endian) to Host byte order. 39 | * 40 | * Note that Ethercat uses little endian byte order, except for the Ethernet 41 | * header which is big endian as usual. 42 | */ 43 | inline uint16 oshw_ntohs(uint16 network) 44 | { 45 | // __ntohs() is provided by the bare-metal x86 compiler 46 | return __ntohs(network); 47 | } 48 | 49 | /** Create list over available network adapters. 50 | * @return First element in linked list of adapters 51 | */ 52 | ec_adaptert* oshw_find_adapters(void) 53 | { 54 | ec_adaptert *ret = NULL; 55 | if (eth_discover_devices() >= 0) { 56 | for (int i = 0;; ++i) { 57 | struct eth_device *dev = eth_get_device(i); 58 | if (dev == NULL) { 59 | adapters[i-1].next = NULL; 60 | break; 61 | } 62 | strncpy(adapters[i].name, dev->name, MAX_DEVICE_NAME); 63 | adapters[i].next = &adapters[i+1]; 64 | } 65 | ret = &(adapters[0]); 66 | } 67 | return ret; 68 | } 69 | 70 | /** Free memory allocated memory used by adapter collection. 71 | * @param[in] adapter = First element in linked list of adapters 72 | * EC_NOFRAME. 73 | */ 74 | void oshw_free_adapters(ec_adaptert *adapter) 75 | { 76 | } 77 | 78 | extern int ec_slavecount; 79 | 80 | -------------------------------------------------------------------------------- /oshw/erika/oshw.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the GNU General Public License version 2 with exceptions. See 3 | * LICENSE file in the project root for full license information 4 | */ 5 | 6 | /** \file 7 | * \brief 8 | * Headerfile for ethercatbase.c 9 | */ 10 | 11 | #ifndef _oshw_ 12 | #define _oshw_ 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | #include "ethercattype.h" 19 | #include "nicdrv.h" 20 | #include "ethercatmain.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/intime/nicdrv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the GNU General Public License version 2 with exceptions. See 3 | * LICENSE file in the project root for full license information 4 | */ 5 | 6 | /** \file 7 | * \brief 8 | * Headerfile for nicdrv.c 9 | */ 10 | 11 | #ifndef _nicdrvh_ 12 | #define _nicdrvh_ 13 | 14 | #define HAVE_REMOTE 15 | 16 | #include 17 | #include "hpeif2.h" 18 | 19 | /** pointer structure to Tx and Rx stacks */ 20 | typedef struct 21 | { 22 | /** socket connection used */ 23 | int *sock; 24 | /** tx buffer */ 25 | ec_bufT (*txbuf)[EC_MAXBUF]; 26 | /** tx buffer lengths */ 27 | int (*txbuflength)[EC_MAXBUF]; 28 | /** temporary receive buffer */ 29 | ec_bufT *tempbuf; 30 | /** rx buffers */ 31 | ec_bufT (*rxbuf)[EC_MAXBUF]; 32 | /** rx buffer status fields */ 33 | int (*rxbufstat)[EC_MAXBUF]; 34 | /** received MAC source address (middle word) */ 35 | int (*rxsa)[EC_MAXBUF]; 36 | } ec_stackT; 37 | 38 | typedef struct 39 | { 40 | ec_stackT stack; 41 | /** rx buffers */ 42 | ec_bufT rxbuf[EC_MAXBUF]; 43 | /** rx buffer status */ 44 | int rxbufstat[EC_MAXBUF]; 45 | /** rx MAC source address */ 46 | int rxsa[EC_MAXBUF]; 47 | /** temporary rx buffer */ 48 | ec_bufT tempinbuf; 49 | /* Intime */ 50 | HPEHANDLE handle; 51 | HPERXBUFFERSET *rx_buffers; 52 | HPETXBUFFERSET *tx_buffers[EC_MAXBUF]; 53 | } ecx_redportt; 54 | 55 | typedef struct 56 | { 57 | ec_stackT stack; 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 | int lastidx; 78 | /** current redundancy state */ 79 | int redstate; 80 | /** pointer to redundancy port and buffers */ 81 | ecx_redportt *redport; 82 | RTHANDLE getindex_region; 83 | RTHANDLE tx_region; 84 | RTHANDLE rx_region; 85 | /* Intime */ 86 | HPEHANDLE handle; 87 | HPERXBUFFERSET *rx_buffers; 88 | HPETXBUFFERSET *tx_buffers[EC_MAXBUF]; 89 | } ecx_portt; 90 | 91 | extern const uint16 priMAC[3]; 92 | extern const uint16 secMAC[3]; 93 | 94 | //extern ecx_portt ecx_port; 95 | //extern ecx_redportt ecx_redport; 96 | 97 | int ec_setupnic(const char * ifname, int secondary); 98 | int ec_closenic(void); 99 | void ec_setupheader(void *p); 100 | void ec_setbufstat(int idx, int bufstat); 101 | int ec_getindex(void); 102 | int ec_outframe(int idx, int sock); 103 | int ec_outframe_red(int idx); 104 | int ec_waitinframe(int idx, int timeout); 105 | int ec_srconfirm(int idx,int timeout); 106 | 107 | int ecx_setupnic(ecx_portt *port, const char * ifname, int secondary); 108 | int ecx_closenic(ecx_portt *port); 109 | void ecx_setbufstat(ecx_portt *port, int idx, int bufstat); 110 | int ecx_getindex(ecx_portt *port); 111 | int ecx_outframe(ecx_portt *port, int idx, int sock); 112 | int ecx_outframe_red(ecx_portt *port, int idx); 113 | int ecx_waitinframe(ecx_portt *port, int idx, int timeout); 114 | int ecx_srconfirm(ecx_portt *port, int idx,int timeout); 115 | 116 | #endif 117 | -------------------------------------------------------------------------------- /oshw/intime/oshw.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the GNU General Public License version 2 with exceptions. See 3 | * LICENSE file in the project root for full license information 4 | */ 5 | 6 | #include 7 | #include "oshw.h" 8 | 9 | /** 10 | * Host to Network byte order (i.e. to big endian). 11 | * 12 | * Note that Ethercat uses little endian byte order, except for the Ethernet 13 | * header which is big endian as usual. 14 | */ 15 | uint16 oshw_htons (uint16 host) 16 | { 17 | uint16 network = htons (host); 18 | return network; 19 | } 20 | 21 | /** 22 | * Network (i.e. big endian) to Host byte order. 23 | * 24 | * Note that Ethercat uses little endian byte order, except for the Ethernet 25 | * header which is big endian as usual. 26 | */ 27 | uint16 oshw_ntohs (uint16 network) 28 | { 29 | uint16 host = ntohs (network); 30 | return host; 31 | } 32 | 33 | /* Create list over available network adapters. 34 | * @return First element in linked list of adapters 35 | */ 36 | ec_adaptert * oshw_find_adapters (void) 37 | { 38 | return NULL; 39 | } 40 | 41 | /** Free memory allocated memory used by adapter collection. 42 | * @param[in] adapter = First element in linked list of adapters 43 | * EC_NOFRAME. 44 | */ 45 | void oshw_free_adapters (ec_adaptert * adapter) 46 | { 47 | 48 | } 49 | -------------------------------------------------------------------------------- /oshw/intime/oshw.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the GNU General Public License version 2 with exceptions. See 3 | * LICENSE file in the project root for full license information 4 | */ 5 | 6 | /** \file 7 | * \brief 8 | * Headerfile for oshw.c 9 | */ 10 | 11 | #ifndef _oshw_ 12 | #define _oshw_ 13 | 14 | #include "ethercattype.h" 15 | #include "ethercatmain.h" 16 | #include "nicdrv.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 | -------------------------------------------------------------------------------- /oshw/linux/nicdrv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the GNU General Public License version 2 with exceptions. See 3 | * LICENSE file in the project root for full license information 4 | */ 5 | 6 | /** \file 7 | * \brief 8 | * Headerfile for nicdrv.c 9 | */ 10 | 11 | #ifndef _nicdrvh_ 12 | #define _nicdrvh_ 13 | 14 | #ifdef __cplusplus 15 | extern "C" 16 | { 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 | int 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 | #ifdef EC_VER1 93 | extern ecx_portt ecx_port; 94 | extern ecx_redportt ecx_redport; 95 | 96 | int ec_setupnic(const char * ifname, int secondary); 97 | int ec_closenic(void); 98 | void ec_setbufstat(int idx, int bufstat); 99 | int ec_getindex(void); 100 | int ec_outframe(int idx, int sock); 101 | int ec_outframe_red(int idx); 102 | int ec_waitinframe(int idx, int timeout); 103 | int ec_srconfirm(int idx,int timeout); 104 | #endif 105 | 106 | void ec_setupheader(void *p); 107 | int ecx_setupnic(ecx_portt *port, const char * ifname, int secondary); 108 | int ecx_closenic(ecx_portt *port); 109 | void ecx_setbufstat(ecx_portt *port, int idx, int bufstat); 110 | int ecx_getindex(ecx_portt *port); 111 | int ecx_outframe(ecx_portt *port, int idx, int sock); 112 | int ecx_outframe_red(ecx_portt *port, int idx); 113 | int ecx_waitinframe(ecx_portt *port, int idx, int timeout); 114 | int ecx_srconfirm(ecx_portt *port, int idx,int timeout); 115 | 116 | #ifdef __cplusplus 117 | } 118 | #endif 119 | 120 | #endif 121 | -------------------------------------------------------------------------------- /oshw/linux/oshw.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the GNU General Public License version 2 with exceptions. See 3 | * LICENSE file in the project root for full license information 4 | */ 5 | 6 | #include 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 | int string_len; 46 | struct if_nameindex *ids; 47 | ec_adaptert * adapter; 48 | ec_adaptert * prev_adapter; 49 | ec_adaptert * ret_adapter = NULL; 50 | 51 | 52 | /* Iterate all devices and create a local copy holding the name and 53 | * description. 54 | */ 55 | 56 | ids = if_nameindex (); 57 | for(i = 0; ids[i].if_index != 0; i++) 58 | { 59 | adapter = (ec_adaptert *)malloc(sizeof(ec_adaptert)); 60 | /* If we got more than one adapter save link list pointer to previous 61 | * adapter. 62 | * Else save as pointer to return. 63 | */ 64 | if (i) 65 | { 66 | prev_adapter->next = adapter; 67 | } 68 | else 69 | { 70 | ret_adapter = adapter; 71 | } 72 | 73 | /* fetch description and name, in Linux we use the same on both */ 74 | adapter->next = NULL; 75 | 76 | if (ids[i].if_name) 77 | { 78 | string_len = strlen(ids[i].if_name); 79 | if (string_len > (EC_MAXLEN_ADAPTERNAME - 1)) 80 | { 81 | string_len = EC_MAXLEN_ADAPTERNAME - 1; 82 | } 83 | strncpy(adapter->name, ids[i].if_name,string_len); 84 | adapter->name[string_len] = '\0'; 85 | strncpy(adapter->desc, ids[i].if_name,string_len); 86 | adapter->desc[string_len] = '\0'; 87 | } 88 | else 89 | { 90 | adapter->name[0] = '\0'; 91 | adapter->desc[0] = '\0'; 92 | } 93 | 94 | prev_adapter = adapter; 95 | } 96 | 97 | if_freenameindex (ids); 98 | 99 | return ret_adapter; 100 | } 101 | 102 | /** Free memory allocated memory used by adapter collection. 103 | * @param[in] adapter = First element in linked list of adapters 104 | * EC_NOFRAME. 105 | */ 106 | void oshw_free_adapters(ec_adaptert * adapter) 107 | { 108 | ec_adaptert * next_adapter; 109 | /* Iterate the linked list and free all elements holding 110 | * adapter information 111 | */ 112 | if(adapter) 113 | { 114 | next_adapter = adapter->next; 115 | free (adapter); 116 | while (next_adapter) 117 | { 118 | adapter = next_adapter; 119 | next_adapter = adapter->next; 120 | free (adapter); 121 | } 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /oshw/linux/oshw.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the GNU General Public License version 2 with exceptions. See 3 | * LICENSE file in the project root for full license information 4 | */ 5 | 6 | /** \file 7 | * \brief 8 | * Headerfile for ethercatbase.c 9 | */ 10 | 11 | #ifndef _oshw_ 12 | #define _oshw_ 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | #include "ethercattype.h" 19 | #include "nicdrv.h" 20 | #include "ethercatmain.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/macosx/nicdrv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the GNU General Public License version 2 with exceptions. See 3 | * LICENSE file in the project root for full license information 4 | */ 5 | 6 | /** \file 7 | * \brief 8 | * Headerfile for nicdrv.c 9 | */ 10 | 11 | #ifndef _nicdrvh_ 12 | #define _nicdrvh_ 13 | 14 | #ifdef __cplusplus 15 | extern "C" 16 | { 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 | int 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 | #ifdef EC_VER1 93 | extern ecx_portt ecx_port; 94 | extern ecx_redportt ecx_redport; 95 | 96 | int ec_setupnic(const char * ifname, int secondary); 97 | int ec_closenic(void); 98 | void ec_setbufstat(int idx, int bufstat); 99 | int ec_getindex(void); 100 | int ec_outframe(int idx, int sock); 101 | int ec_outframe_red(int idx); 102 | int ec_waitinframe(int idx, int timeout); 103 | int ec_srconfirm(int idx,int timeout); 104 | #endif 105 | 106 | void ec_setupheader(void *p); 107 | int ecx_setupnic(ecx_portt *port, const char * ifname, int secondary); 108 | int ecx_closenic(ecx_portt *port); 109 | void ecx_setbufstat(ecx_portt *port, int idx, int bufstat); 110 | int ecx_getindex(ecx_portt *port); 111 | int ecx_outframe(ecx_portt *port, int idx, int sock); 112 | int ecx_outframe_red(ecx_portt *port, int idx); 113 | int ecx_waitinframe(ecx_portt *port, int idx, int timeout); 114 | int ecx_srconfirm(ecx_portt *port, int idx,int timeout); 115 | 116 | #ifdef __cplusplus 117 | } 118 | #endif 119 | 120 | #endif 121 | -------------------------------------------------------------------------------- /oshw/macosx/oshw.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the GNU General Public License version 2 with exceptions. See 3 | * LICENSE file in the project root for full license information 4 | */ 5 | 6 | #include 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 | int string_len; 46 | struct if_nameindex *ids; 47 | ec_adaptert * adapter; 48 | ec_adaptert * prev_adapter; 49 | ec_adaptert * ret_adapter = NULL; 50 | 51 | 52 | /* Iterate all devices and create a local copy holding the name and 53 | * description. 54 | */ 55 | 56 | ids = if_nameindex (); 57 | for(i = 0; ids[i].if_index != 0; i++) 58 | { 59 | adapter = (ec_adaptert *)malloc(sizeof(ec_adaptert)); 60 | /* If we got more than one adapter save link list pointer to previous 61 | * adapter. 62 | * Else save as pointer to return. 63 | */ 64 | if (i) 65 | { 66 | prev_adapter->next = adapter; 67 | } 68 | else 69 | { 70 | ret_adapter = adapter; 71 | } 72 | 73 | /* fetch description and name, in Linux we use the same on both */ 74 | adapter->next = NULL; 75 | 76 | if (ids[i].if_name) 77 | { 78 | string_len = strlen(ids[i].if_name); 79 | if (string_len > (EC_MAXLEN_ADAPTERNAME - 1)) 80 | { 81 | string_len = EC_MAXLEN_ADAPTERNAME - 1; 82 | } 83 | strncpy(adapter->name, ids[i].if_name,string_len); 84 | adapter->name[string_len] = '\0'; 85 | strncpy(adapter->desc, ids[i].if_name,string_len); 86 | adapter->desc[string_len] = '\0'; 87 | } 88 | else 89 | { 90 | adapter->name[0] = '\0'; 91 | adapter->desc[0] = '\0'; 92 | } 93 | 94 | prev_adapter = adapter; 95 | } 96 | 97 | if_freenameindex (ids); 98 | 99 | return ret_adapter; 100 | } 101 | 102 | /** Free memory allocated memory used by adapter collection. 103 | * @param[in] adapter = First element in linked list of adapters 104 | * EC_NOFRAME. 105 | */ 106 | void oshw_free_adapters(ec_adaptert * adapter) 107 | { 108 | ec_adaptert * next_adapter; 109 | /* Iterate the linked list and free all elements holding 110 | * adapter information 111 | */ 112 | if(adapter) 113 | { 114 | next_adapter = adapter->next; 115 | free (adapter); 116 | while (next_adapter) 117 | { 118 | adapter = next_adapter; 119 | next_adapter = adapter->next; 120 | free (adapter); 121 | } 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /oshw/macosx/oshw.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the GNU General Public License version 2 with exceptions. See 3 | * LICENSE file in the project root for full license information 4 | */ 5 | 6 | /** \file 7 | * \brief 8 | * Headerfile for ethercatbase.c 9 | */ 10 | 11 | #ifndef _oshw_ 12 | #define _oshw_ 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | #include "ethercattype.h" 19 | #include "nicdrv.h" 20 | #include "ethercatmain.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/rtems/nicdrv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the GNU General Public License version 2 with exceptions. See 3 | * LICENSE file in the project root for full license information 4 | */ 5 | 6 | /** \file 7 | * \brief 8 | * Headerfile for nicdrv.c 9 | */ 10 | 11 | #ifndef _nicdrvh_ 12 | #define _nicdrvh_ 13 | 14 | #ifdef __cplusplus 15 | extern "C" 16 | { 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 | int 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 | #ifdef EC_VER1 93 | extern ecx_portt ecx_port; 94 | extern ecx_redportt ecx_redport; 95 | 96 | int ec_setupnic(const char * ifname, int secondary); 97 | int ec_closenic(void); 98 | void ec_setbufstat(int idx, int bufstat); 99 | int ec_getindex(void); 100 | int ec_outframe(int idx, int sock); 101 | int ec_outframe_red(int idx); 102 | int ec_waitinframe(int idx, int timeout); 103 | int ec_srconfirm(int idx,int timeout); 104 | #endif 105 | 106 | void ec_setupheader(void *p); 107 | int ecx_setupnic(ecx_portt *port, const char * ifname, int secondary); 108 | int ecx_closenic(ecx_portt *port); 109 | void ecx_setbufstat(ecx_portt *port, int idx, int bufstat); 110 | int ecx_getindex(ecx_portt *port); 111 | int ecx_outframe(ecx_portt *port, int idx, int sock); 112 | int ecx_outframe_red(ecx_portt *port, int idx); 113 | int ecx_waitinframe(ecx_portt *port, int idx, int timeout); 114 | int ecx_srconfirm(ecx_portt *port, int idx,int timeout); 115 | 116 | #ifdef __cplusplus 117 | } 118 | #endif 119 | 120 | #endif 121 | -------------------------------------------------------------------------------- /oshw/rtems/oshw.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the GNU General Public License version 2 with exceptions. See 3 | * LICENSE file in the project root for full license information 4 | */ 5 | 6 | #include 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 | int string_len; 46 | struct if_nameindex *ids; 47 | ec_adaptert * adapter; 48 | ec_adaptert * prev_adapter; 49 | ec_adaptert * ret_adapter = NULL; 50 | 51 | 52 | /* Iterate all devices and create a local copy holding the name and 53 | * description. 54 | */ 55 | 56 | ids = if_nameindex (); 57 | for(i = 0; ids[i].if_index != 0; i++) 58 | { 59 | adapter = (ec_adaptert *)malloc(sizeof(ec_adaptert)); 60 | /* If we got more than one adapter save link list pointer to previous 61 | * adapter. 62 | * Else save as pointer to return. 63 | */ 64 | if (i) 65 | { 66 | prev_adapter->next = adapter; 67 | } 68 | else 69 | { 70 | ret_adapter = adapter; 71 | } 72 | 73 | /* fetch description and name, in Linux we use the same on both */ 74 | adapter->next = NULL; 75 | 76 | if (ids[i].if_name) 77 | { 78 | string_len = strlen(ids[i].if_name); 79 | if (string_len > (EC_MAXLEN_ADAPTERNAME - 1)) 80 | { 81 | string_len = EC_MAXLEN_ADAPTERNAME - 1; 82 | } 83 | strncpy(adapter->name, ids[i].if_name,string_len); 84 | adapter->name[string_len] = '\0'; 85 | strncpy(adapter->desc, ids[i].if_name,string_len); 86 | adapter->desc[string_len] = '\0'; 87 | } 88 | else 89 | { 90 | adapter->name[0] = '\0'; 91 | adapter->desc[0] = '\0'; 92 | } 93 | 94 | prev_adapter = adapter; 95 | } 96 | 97 | if_freenameindex (ids); 98 | 99 | return ret_adapter; 100 | } 101 | 102 | /** Free memory allocated memory used by adapter collection. 103 | * @param[in] adapter = First element in linked list of adapters 104 | * EC_NOFRAME. 105 | */ 106 | void oshw_free_adapters(ec_adaptert * adapter) 107 | { 108 | ec_adaptert * next_adapter; 109 | /* Iterate the linked list and free all elements holding 110 | * adapter information 111 | */ 112 | if(adapter) 113 | { 114 | next_adapter = adapter->next; 115 | free (adapter); 116 | while (next_adapter) 117 | { 118 | adapter = next_adapter; 119 | next_adapter = adapter->next; 120 | free (adapter); 121 | } 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /oshw/rtems/oshw.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the GNU General Public License version 2 with exceptions. See 3 | * LICENSE file in the project root for full license information 4 | */ 5 | 6 | /** \file 7 | * \brief 8 | * Headerfile for ethercatbase.c 9 | */ 10 | 11 | #ifndef _oshw_ 12 | #define _oshw_ 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | #include "ethercattype.h" 19 | #include "nicdrv.h" 20 | #include "ethercatmain.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/rtk/fec/fec_ecat.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * * *** *** 3 | * *** *** *** 4 | * *** **** ********** *** ***** *** **** ***** 5 | * ********* ********** *** ********* ************ ********* 6 | * **** *** *** *** *** **** *** 7 | * *** *** ****** *** *********** *** **** ***** 8 | * *** *** ****** *** ************* *** **** ***** 9 | * *** **** **** *** *** *** **** *** 10 | * *** ******* ***** ************** ************* ********* 11 | * *** ***** *** ******* ** ** ****** ***** 12 | * t h e r e a l t i m e t a r g e t e x p e r t s 13 | * 14 | * http://www.rt-labs.com 15 | * Copyright (C) 2007. rt-labs AB, Sweden. All rights reserved. 16 | *------------------------------------------------------------------------------ 17 | * $Id: fec_ecat.h 91 2014-04-02 13:32:29Z rtlfrm $ 18 | *------------------------------------------------------------------------------ 19 | */ 20 | 21 | /** 22 | * \defgroup fec EtherCat Ethernet MAC driver for Frescale K60 SoCs. 23 | * 24 | * \{ 25 | */ 26 | 27 | #ifndef FEC_H 28 | #define FEC_H 29 | 30 | #include 31 | 32 | #ifdef __cplusplus 33 | extern "C" 34 | { 35 | #endif 36 | 37 | typedef struct fec_mac_address 38 | { 39 | uint8_t octet[6]; 40 | } fec_mac_address_t; 41 | 42 | int fec_ecat_init (const fec_mac_address_t * mac_address, bool phy_loopback_mode); 43 | 44 | int fec_ecat_send (const void *payload, size_t tot_len); 45 | 46 | int fec_ecat_recv (void * buffer, size_t buffer_length); 47 | 48 | #ifdef __cplusplus 49 | } 50 | #endif 51 | 52 | #endif /* FEC_H */ 53 | 54 | /** 55 | * \} 56 | */ 57 | -------------------------------------------------------------------------------- /oshw/rtk/lw_mac/lw_emac.h: -------------------------------------------------------------------------------- 1 | /* 2 | * author: Tomas Vestelind 3 | */ 4 | 5 | #ifndef LWIP_MAC_H 6 | #define LWIP_MAC_H 7 | 8 | int bfin_EMAC_init(uint8_t *enetaddr); 9 | int bfin_EMAC_send(void *packet, int length); 10 | int bfin_EMAC_recv(uint8_t * packet, size_t size); 11 | 12 | #endif /* LWIP_MAC_H */ 13 | -------------------------------------------------------------------------------- /oshw/rtk/nicdrv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the GNU General Public License version 2 with exceptions. See 3 | * LICENSE file in the project root for full license information 4 | */ 5 | 6 | /** \file 7 | * \brief 8 | * Headerfile for nicdrv.c 9 | */ 10 | 11 | #ifndef _nicdrvh_ 12 | #define _nicdrvh_ 13 | 14 | /** pointer structure to Tx and Rx stacks */ 15 | typedef struct 16 | { 17 | /** socket connection used */ 18 | int *sock; 19 | /** tx buffer */ 20 | ec_bufT (*txbuf)[EC_MAXBUF]; 21 | /** tx buffer lengths */ 22 | int (*txbuflength)[EC_MAXBUF]; 23 | /** temporary receive buffer */ 24 | ec_bufT *tempbuf; 25 | /** rx buffers */ 26 | ec_bufT (*rxbuf)[EC_MAXBUF]; 27 | /** rx buffer status fields */ 28 | int (*rxbufstat)[EC_MAXBUF]; 29 | /** received MAC source address (middle word) */ 30 | int (*rxsa)[EC_MAXBUF]; 31 | } ec_stackT; 32 | 33 | /** pointer structure to buffers for redundant port */ 34 | typedef struct 35 | { 36 | ec_stackT stack; 37 | int sockhandle; 38 | /** rx buffers */ 39 | ec_bufT rxbuf[EC_MAXBUF]; 40 | /** rx buffer status */ 41 | int rxbufstat[EC_MAXBUF]; 42 | /** rx MAC source address */ 43 | int rxsa[EC_MAXBUF]; 44 | /** temporary rx buffer */ 45 | ec_bufT tempinbuf; 46 | } ecx_redportt; 47 | 48 | /** pointer structure to buffers, vars and mutexes for port instantiation */ 49 | typedef struct 50 | { 51 | ec_stackT stack; 52 | int sockhandle; 53 | /** rx buffers */ 54 | ec_bufT rxbuf[EC_MAXBUF]; 55 | /** rx buffer status */ 56 | int rxbufstat[EC_MAXBUF]; 57 | /** rx MAC source address */ 58 | int rxsa[EC_MAXBUF]; 59 | /** temporary rx buffer */ 60 | ec_bufT tempinbuf; 61 | /** temporary rx buffer status */ 62 | int tempinbufs; 63 | /** transmit buffers */ 64 | ec_bufT txbuf[EC_MAXBUF]; 65 | /** transmit buffer lengths */ 66 | int txbuflength[EC_MAXBUF]; 67 | /** temporary tx buffer */ 68 | ec_bufT txbuf2; 69 | /** temporary tx buffer length */ 70 | int txbuflength2; 71 | /** last used frame index */ 72 | int lastidx; 73 | /** current redundancy state */ 74 | int redstate; 75 | /** pointer to redundancy port and buffers */ 76 | ecx_redportt *redport; 77 | mtx_t * getindex_mutex; 78 | mtx_t * tx_mutex; 79 | mtx_t * rx_mutex; 80 | } ecx_portt; 81 | 82 | extern const uint16 priMAC[3]; 83 | extern const uint16 secMAC[3]; 84 | 85 | #ifdef EC_VER1 86 | extern ecx_portt ecx_port; 87 | extern ecx_redportt ecx_redport; 88 | 89 | int ec_setupnic(const char * ifname, int secondary); 90 | int ec_closenic(void); 91 | void ec_setbufstat(int idx, int bufstat); 92 | int ec_getindex(void); 93 | int ec_outframe(int idx, int stacknumber); 94 | int ec_outframe_red(int idx); 95 | int ec_waitinframe(int idx, int timeout); 96 | int ec_srconfirm(int idx,int timeout); 97 | #endif 98 | 99 | void ec_setupheader(void *p); 100 | int ecx_setupnic(ecx_portt *port, const char * ifname, int secondary); 101 | int ecx_closenic(ecx_portt *port); 102 | void ecx_setbufstat(ecx_portt *port, int idx, int bufstat); 103 | int ecx_getindex(ecx_portt *port); 104 | int ecx_outframe(ecx_portt *port, int idx, int stacknumber); 105 | int ecx_outframe_red(ecx_portt *port, int idx); 106 | int ecx_waitinframe(ecx_portt *port, int idx, int timeout); 107 | int ecx_srconfirm(ecx_portt *port, int idx,int timeout); 108 | 109 | #endif 110 | -------------------------------------------------------------------------------- /oshw/rtk/oshw.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the GNU General Public License version 2 with exceptions. See 3 | * LICENSE file in the project root for full license information 4 | */ 5 | 6 | #include "oshw.h" 7 | #include 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(const 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(const 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 | ec_adaptert * ret_adapter = NULL; 40 | 41 | /* TODO if needed */ 42 | 43 | return ret_adapter; 44 | } 45 | 46 | /** Free memory allocated memory used by adapter collection. 47 | * @param[in] adapter = First element in linked list of adapters 48 | * EC_NOFRAME. 49 | */ 50 | void oshw_free_adapters(ec_adaptert * adapter) 51 | { 52 | /* TODO if needed */ 53 | } 54 | -------------------------------------------------------------------------------- /oshw/rtk/oshw.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the GNU General Public License version 2 with exceptions. See 3 | * LICENSE file in the project root for full license information 4 | */ 5 | 6 | /** \file 7 | * \brief 8 | * Headerfile for oshw.c 9 | */ 10 | 11 | #ifndef _oshw_ 12 | #define _oshw_ 13 | 14 | #ifdef __cplusplus 15 | extern "C" 16 | { 17 | #endif 18 | 19 | #include 20 | #include "ethercattype.h" 21 | #include "nicdrv.h" 22 | #include "ethercatmain.h" 23 | 24 | 25 | uint16 oshw_htons(uint16 host); 26 | uint16 oshw_ntohs(uint16 network); 27 | 28 | ec_adaptert * oshw_find_adapters(void); 29 | void oshw_free_adapters(ec_adaptert * adapter); 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /oshw/vxworks/nicdrv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the GNU General Public License version 2 with exceptions. See 3 | * LICENSE file in the project root for full license information 4 | */ 5 | 6 | /** \file 7 | * \brief 8 | * Headerfile for nicdrv.c 9 | */ 10 | 11 | #ifndef _nicdrvh_ 12 | #define _nicdrvh_ 13 | 14 | #ifdef __cplusplus 15 | extern "C" 16 | { 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 | int 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 | #ifdef EC_VER1 103 | extern ecx_portt ecx_port; 104 | extern ecx_redportt ecx_redport; 105 | 106 | int ec_setupnic(const char * ifname, int secondary); 107 | int ec_closenic(void); 108 | void ec_setbufstat(int idx, int bufstat); 109 | int ec_getindex(void); 110 | int ec_outframe(int idx, int sock); 111 | int ec_outframe_red(int idx); 112 | int ec_waitinframe(int idx, int timeout); 113 | int ec_srconfirm(int idx,int timeout); 114 | #endif 115 | 116 | void ec_setupheader(void *p); 117 | int ecx_setupnic(ecx_portt *port, const char * ifname, int secondary); 118 | int ecx_closenic(ecx_portt *port); 119 | void ecx_setbufstat(ecx_portt *port, int idx, int bufstat); 120 | int ecx_getindex(ecx_portt *port); 121 | int ecx_outframe(ecx_portt *port, int idx, int sock); 122 | int ecx_outframe_red(ecx_portt *port, int idx); 123 | int ecx_waitinframe(ecx_portt *port, int idx, int timeout); 124 | int ecx_srconfirm(ecx_portt *port, int idx,int timeout); 125 | 126 | #ifdef __cplusplus 127 | } 128 | #endif 129 | 130 | #endif 131 | -------------------------------------------------------------------------------- /oshw/vxworks/oshw.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the GNU General Public License version 2 with exceptions. See 3 | * LICENSE file in the project root for full license information 4 | */ 5 | 6 | #include 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 | ec_adaptert * ret_adapter = NULL; 46 | /* Not implemented */ 47 | assert(0); 48 | 49 | return ret_adapter; 50 | } 51 | 52 | /** Free memory allocated memory used by adapter collection. 53 | * @param[in] adapter = First element in linked list of adapters 54 | * EC_NOFRAME. 55 | */ 56 | void oshw_free_adapters(ec_adaptert * adapter) 57 | { 58 | /* Not implemented */ 59 | assert(0); 60 | } 61 | -------------------------------------------------------------------------------- /oshw/vxworks/oshw.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the GNU General Public License version 2 with exceptions. See 3 | * LICENSE file in the project root for full license information 4 | */ 5 | 6 | /** \file 7 | * \brief 8 | * Headerfile for oshw.c 9 | */ 10 | 11 | #ifndef _oshw_ 12 | #define _oshw_ 13 | 14 | #include "ethercattype.h" 15 | #include "nicdrv.h" 16 | #include "ethercatmain.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 | -------------------------------------------------------------------------------- /oshw/win32/nicdrv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the GNU General Public License version 2 with exceptions. See 3 | * LICENSE file in the project root for full license information 4 | */ 5 | 6 | /** \file 7 | * \brief 8 | * Headerfile for nicdrv.c 9 | */ 10 | 11 | #ifndef _nicdrvh_ 12 | #define _nicdrvh_ 13 | 14 | #ifdef __cplusplus 15 | extern "C" 16 | { 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 | } ec_stackT; 42 | 43 | /** pointer structure to buffers for redundant port */ 44 | typedef struct 45 | { 46 | ec_stackT stack; 47 | pcap_t *sockhandle; 48 | /** rx buffers */ 49 | ec_bufT rxbuf[EC_MAXBUF]; 50 | /** rx buffer status */ 51 | int rxbufstat[EC_MAXBUF]; 52 | /** rx MAC source address */ 53 | int rxsa[EC_MAXBUF]; 54 | /** temporary rx buffer */ 55 | ec_bufT tempinbuf; 56 | } ecx_redportt; 57 | 58 | /** pointer structure to buffers, vars and mutexes for port instantiation */ 59 | typedef struct 60 | { 61 | ec_stackT stack; 62 | pcap_t *sockhandle; 63 | /** rx buffers */ 64 | ec_bufT rxbuf[EC_MAXBUF]; 65 | /** rx buffer status */ 66 | int rxbufstat[EC_MAXBUF]; 67 | /** rx MAC source address */ 68 | int rxsa[EC_MAXBUF]; 69 | /** temporary rx buffer */ 70 | ec_bufT tempinbuf; 71 | /** temporary rx buffer status */ 72 | int tempinbufs; 73 | /** transmit buffers */ 74 | ec_bufT txbuf[EC_MAXBUF]; 75 | /** transmit buffer lengths */ 76 | int txbuflength[EC_MAXBUF]; 77 | /** temporary tx buffer */ 78 | ec_bufT txbuf2; 79 | /** temporary tx buffer length */ 80 | int txbuflength2; 81 | /** last used frame index */ 82 | int lastidx; 83 | /** current redundancy state */ 84 | int redstate; 85 | /** pointer to redundancy port and buffers */ 86 | ecx_redportt *redport; 87 | CRITICAL_SECTION getindex_mutex; 88 | CRITICAL_SECTION tx_mutex; 89 | CRITICAL_SECTION rx_mutex; 90 | } ecx_portt; 91 | 92 | extern const uint16 priMAC[3]; 93 | extern const uint16 secMAC[3]; 94 | 95 | #ifdef EC_VER1 96 | extern ecx_portt ecx_port; 97 | extern ecx_redportt ecx_redport; 98 | 99 | int ec_setupnic(const char * ifname, int secondary); 100 | int ec_closenic(void); 101 | void ec_setbufstat(int idx, int bufstat); 102 | int ec_getindex(void); 103 | int ec_outframe(int idx, int sock); 104 | int ec_outframe_red(int idx); 105 | int ec_waitinframe(int idx, int timeout); 106 | int ec_srconfirm(int idx,int timeout); 107 | #endif 108 | 109 | void ec_setupheader(void *p); 110 | int ecx_setupnic(ecx_portt *port, const char * ifname, int secondary); 111 | int ecx_closenic(ecx_portt *port); 112 | void ecx_setbufstat(ecx_portt *port, int idx, int bufstat); 113 | int ecx_getindex(ecx_portt *port); 114 | int ecx_outframe(ecx_portt *port, int idx, int sock); 115 | int ecx_outframe_red(ecx_portt *port, int idx); 116 | int ecx_waitinframe(ecx_portt *port, int idx, int timeout); 117 | int ecx_srconfirm(ecx_portt *port, int idx,int timeout); 118 | 119 | #ifdef __cplusplus 120 | } 121 | #endif 122 | 123 | #endif 124 | -------------------------------------------------------------------------------- /oshw/win32/oshw.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the GNU General Public License version 2 with exceptions. See 3 | * LICENSE file in the project root for full license information 4 | */ 5 | 6 | #include "oshw.h" 7 | 8 | /** 9 | * Host to Network byte order (i.e. to big endian). 10 | * 11 | * Note that Ethercat uses little endian byte order, except for the Ethernet 12 | * header which is big endian as usual. 13 | */ 14 | uint16 oshw_htons (uint16 host) 15 | { 16 | uint16 network = htons (host); 17 | return network; 18 | } 19 | 20 | /** 21 | * Network (i.e. big endian) to Host byte order. 22 | * 23 | * Note that Ethercat uses little endian byte order, except for the Ethernet 24 | * header which is big endian as usual. 25 | */ 26 | uint16 oshw_ntohs (uint16 network) 27 | { 28 | uint16 host = ntohs (network); 29 | return host; 30 | } 31 | 32 | /* Create list over available network adapters. 33 | * @return First element in linked list of adapters 34 | */ 35 | ec_adaptert * oshw_find_adapters (void) 36 | { 37 | int i = 0; 38 | int ret = 0; 39 | pcap_if_t *alldevs; 40 | pcap_if_t *d; 41 | ec_adaptert * adapter; 42 | ec_adaptert * prev_adapter; 43 | ec_adaptert * ret_adapter = NULL; 44 | char errbuf[PCAP_ERRBUF_SIZE]; 45 | size_t string_len; 46 | 47 | /* find all devices */ 48 | if (pcap_findalldevs(&alldevs, errbuf) == -1) 49 | { 50 | fprintf(stderr,"Error in pcap_findalldevs_ex: %s\n", errbuf); 51 | return (NULL); 52 | } 53 | /* Iterate all devices and create a local copy holding the name and 54 | * description. 55 | */ 56 | for(d= alldevs; d != NULL; d= d->next) 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 of the device from libpcap */ 73 | adapter->next = NULL; 74 | if (d->name) 75 | { 76 | string_len = strlen(d->name); 77 | if (string_len > (EC_MAXLEN_ADAPTERNAME - 1)) 78 | { 79 | string_len = EC_MAXLEN_ADAPTERNAME - 1; 80 | } 81 | strncpy(adapter->name, d->name,string_len); 82 | adapter->name[string_len] = '\0'; 83 | } 84 | else 85 | { 86 | adapter->name[0] = '\0'; 87 | } 88 | if (d->description) 89 | { 90 | string_len = strlen(d->description); 91 | if (string_len > (EC_MAXLEN_ADAPTERNAME - 1)) 92 | { 93 | string_len = EC_MAXLEN_ADAPTERNAME - 1; 94 | } 95 | strncpy(adapter->desc, d->description,string_len); 96 | adapter->desc[string_len] = '\0'; 97 | } 98 | else 99 | { 100 | adapter->desc[0] = '\0'; 101 | } 102 | prev_adapter = adapter; 103 | i++; 104 | } 105 | /* free all devices allocated */ 106 | pcap_freealldevs(alldevs); 107 | 108 | return ret_adapter; 109 | } 110 | 111 | /** Free memory allocated memory used by adapter collection. 112 | * @param[in] adapter = First element in linked list of adapters 113 | * EC_NOFRAME. 114 | */ 115 | void oshw_free_adapters (ec_adaptert * adapter) 116 | { 117 | ec_adaptert * next_adapter; 118 | /* Iterate the linked list and free all elements holding 119 | * adapter information 120 | */ 121 | if(adapter) 122 | { 123 | next_adapter = adapter->next; 124 | free (adapter); 125 | while (next_adapter) 126 | { 127 | adapter = next_adapter; 128 | next_adapter = adapter->next; 129 | free (adapter); 130 | } 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /oshw/win32/oshw.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the GNU General Public License version 2 with exceptions. See 3 | * LICENSE file in the project root for full license information 4 | */ 5 | 6 | /** \file 7 | * \brief 8 | * Headerfile for ethercatbase.c 9 | */ 10 | 11 | #ifndef _oshw_ 12 | #define _oshw_ 13 | 14 | #ifdef __cplusplus 15 | extern "C" 16 | { 17 | #endif 18 | 19 | #include "ethercattype.h" 20 | #include "nicdrv.h" 21 | #include "ethercatmain.h" 22 | 23 | uint16 oshw_htons (uint16 hostshort); 24 | uint16 oshw_ntohs (uint16 networkshort); 25 | ec_adaptert * oshw_find_adapters (void); 26 | void oshw_free_adapters (ec_adaptert * adapter); 27 | 28 | #ifdef __cplusplus 29 | } 30 | #endif 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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-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.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/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /oshw/win32/wpcap/Lib/Packet.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rtlabs-com/fsoe-soem-demo/89cb5a926fd2310ff6c27660ecd328dc18467aec/oshw/win32/wpcap/Lib/Packet.lib -------------------------------------------------------------------------------- /oshw/win32/wpcap/Lib/libpacket.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rtlabs-com/fsoe-soem-demo/89cb5a926fd2310ff6c27660ecd328dc18467aec/oshw/win32/wpcap/Lib/libpacket.a -------------------------------------------------------------------------------- /oshw/win32/wpcap/Lib/libwpcap.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rtlabs-com/fsoe-soem-demo/89cb5a926fd2310ff6c27660ecd328dc18467aec/oshw/win32/wpcap/Lib/libwpcap.a -------------------------------------------------------------------------------- /oshw/win32/wpcap/Lib/wpcap.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rtlabs-com/fsoe-soem-demo/89cb5a926fd2310ff6c27660ecd328dc18467aec/oshw/win32/wpcap/Lib/wpcap.lib -------------------------------------------------------------------------------- /oshw/win32/wpcap/Lib/x64/Packet.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rtlabs-com/fsoe-soem-demo/89cb5a926fd2310ff6c27660ecd328dc18467aec/oshw/win32/wpcap/Lib/x64/Packet.lib -------------------------------------------------------------------------------- /oshw/win32/wpcap/Lib/x64/wpcap.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rtlabs-com/fsoe-soem-demo/89cb5a926fd2310ff6c27660ecd328dc18467aec/oshw/win32/wpcap/Lib/x64/wpcap.lib -------------------------------------------------------------------------------- /soem/ethercat.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the GNU General Public License version 2 with exceptions. See 3 | * LICENSE file in the project root for full license information 4 | */ 5 | 6 | /** \file 7 | * \brief 8 | * Headerfile for all ethercat headers 9 | */ 10 | 11 | #ifndef _EC_ETHERCAT_H 12 | #define _EC_ETHERCAT_H 13 | 14 | #include "ethercattype.h" 15 | #include "nicdrv.h" 16 | #include "ethercatbase.h" 17 | #include "ethercatmain.h" 18 | #include "ethercatdc.h" 19 | #include "ethercatcoe.h" 20 | #include "ethercatfoe.h" 21 | #include "ethercatsoe.h" 22 | #include "ethercateoe.h" 23 | #include "ethercatconfig.h" 24 | #include "ethercatprint.h" 25 | 26 | #endif /* _EC_ETHERCAT_H */ 27 | -------------------------------------------------------------------------------- /soem/ethercatbase.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the GNU General Public License version 2 with exceptions. See 3 | * LICENSE file in the project root for full license information 4 | */ 5 | 6 | /** \file 7 | * \brief 8 | * Headerfile for ethercatbase.c 9 | */ 10 | 11 | #ifndef _ethercatbase_ 12 | #define _ethercatbase_ 13 | 14 | #ifdef __cplusplus 15 | extern "C" 16 | { 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 | int 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 EC_VER1 39 | int ec_setupdatagram(void *frame, uint8 com, uint8 idx, uint16 ADP, uint16 ADO, uint16 length, void *data); 40 | int ec_adddatagram(void *frame, uint8 com, uint8 idx, boolean more, uint16 ADP, uint16 ADO, uint16 length, void *data); 41 | int ec_BWR(uint16 ADP,uint16 ADO,uint16 length,void *data,int timeout); 42 | int ec_BRD(uint16 ADP,uint16 ADO,uint16 length,void *data,int timeout); 43 | int ec_APRD(uint16 ADP, uint16 ADO, uint16 length, void *data, int timeout); 44 | int ec_ARMW(uint16 ADP, uint16 ADO, uint16 length, void *data, int timeout); 45 | int ec_FRMW(uint16 ADP, uint16 ADO, uint16 length, void *data, int timeout); 46 | uint16 ec_APRDw(uint16 ADP, uint16 ADO, int timeout); 47 | int ec_FPRD(uint16 ADP, uint16 ADO, uint16 length, void *data, int timeout); 48 | uint16 ec_FPRDw(uint16 ADP, uint16 ADO, int timeout); 49 | int ec_APWRw(uint16 ADP, uint16 ADO, uint16 data, int timeout); 50 | int ec_APWR(uint16 ADP, uint16 ADO, uint16 length, void *data, int timeout); 51 | int ec_FPWRw(uint16 ADP, uint16 ADO, uint16 data, int timeout); 52 | int ec_FPWR(uint16 ADP, uint16 ADO, uint16 length, void *data, int timeout); 53 | int ec_LRW(uint32 LogAdr, uint16 length, void *data, int timeout); 54 | int ec_LRD(uint32 LogAdr, uint16 length, void *data, int timeout); 55 | int ec_LWR(uint32 LogAdr, uint16 length, void *data, int timeout); 56 | int ec_LRWDC(uint32 LogAdr, uint16 length, void *data, uint16 DCrs, int64 *DCtime, int timeout); 57 | #endif 58 | 59 | #ifdef __cplusplus 60 | } 61 | #endif 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /soem/ethercatcoe.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the GNU General Public License version 2 with exceptions. See 3 | * LICENSE file in the project root for full license information 4 | */ 5 | 6 | /** \file 7 | * \brief 8 | * Headerfile for ethercatcoe.c 9 | */ 10 | 11 | #ifndef _ethercatcoe_ 12 | #define _ethercatcoe_ 13 | 14 | #ifdef __cplusplus 15 | extern "C" 16 | { 17 | #endif 18 | 19 | /** max entries in Object Description list */ 20 | #define EC_MAXODLIST 1024 21 | 22 | /** max entries in Object Entry list */ 23 | #define EC_MAXOELIST 256 24 | 25 | /* Storage for object description list */ 26 | typedef struct 27 | { 28 | /** slave number */ 29 | uint16 Slave; 30 | /** number of entries in list */ 31 | uint16 Entries; 32 | /** array of indexes */ 33 | uint16 Index[EC_MAXODLIST]; 34 | /** array of datatypes, see EtherCAT specification */ 35 | uint16 DataType[EC_MAXODLIST]; 36 | /** array of object codes, see EtherCAT specification */ 37 | uint8 ObjectCode[EC_MAXODLIST]; 38 | /** number of subindexes for each index */ 39 | uint8 MaxSub[EC_MAXODLIST]; 40 | /** textual description of each index */ 41 | char Name[EC_MAXODLIST][EC_MAXNAME+1]; 42 | } ec_ODlistt; 43 | 44 | /* storage for object list entry information */ 45 | typedef struct 46 | { 47 | /** number of entries in list */ 48 | uint16 Entries; 49 | /** array of value infos, see EtherCAT specification */ 50 | uint8 ValueInfo[EC_MAXOELIST]; 51 | /** array of value infos, see EtherCAT specification */ 52 | uint16 DataType[EC_MAXOELIST]; 53 | /** array of bit lengths, see EtherCAT specification */ 54 | uint16 BitLength[EC_MAXOELIST]; 55 | /** array of object access bits, see EtherCAT specification */ 56 | uint16 ObjAccess[EC_MAXOELIST]; 57 | /** textual description of each index */ 58 | char Name[EC_MAXOELIST][EC_MAXNAME+1]; 59 | } ec_OElistt; 60 | 61 | #ifdef EC_VER1 62 | void ec_SDOerror(uint16 Slave, uint16 Index, uint8 SubIdx, int32 AbortCode); 63 | int ec_SDOread(uint16 slave, uint16 index, uint8 subindex, 64 | boolean CA, int *psize, void *p, int timeout); 65 | int ec_SDOwrite(uint16 Slave, uint16 Index, uint8 SubIndex, 66 | boolean CA, int psize, void *p, int Timeout); 67 | int ec_RxPDO(uint16 Slave, uint16 RxPDOnumber , int psize, void *p); 68 | int ec_TxPDO(uint16 slave, uint16 TxPDOnumber , int *psize, void *p, int timeout); 69 | int ec_readPDOmap(uint16 Slave, int *Osize, int *Isize); 70 | int ec_readPDOmapCA(uint16 Slave, int Thread_n, int *Osize, int *Isize); 71 | int ec_readODlist(uint16 Slave, ec_ODlistt *pODlist); 72 | int ec_readODdescription(uint16 Item, ec_ODlistt *pODlist); 73 | int ec_readOEsingle(uint16 Item, uint8 SubI, ec_ODlistt *pODlist, ec_OElistt *pOElist); 74 | int ec_readOE(uint16 Item, ec_ODlistt *pODlist, ec_OElistt *pOElist); 75 | #endif 76 | 77 | void ecx_SDOerror(ecx_contextt *context, uint16 Slave, uint16 Index, uint8 SubIdx, int32 AbortCode); 78 | int ecx_SDOread(ecx_contextt *context, uint16 slave, uint16 index, uint8 subindex, 79 | boolean CA, int *psize, void *p, int timeout); 80 | int ecx_SDOwrite(ecx_contextt *context, uint16 Slave, uint16 Index, uint8 SubIndex, 81 | boolean CA, int psize, void *p, int Timeout); 82 | int ecx_RxPDO(ecx_contextt *context, uint16 Slave, uint16 RxPDOnumber , int psize, void *p); 83 | int ecx_TxPDO(ecx_contextt *context, uint16 slave, uint16 TxPDOnumber , int *psize, void *p, int timeout); 84 | int ecx_readPDOmap(ecx_contextt *context, uint16 Slave, int *Osize, int *Isize); 85 | int ecx_readPDOmapCA(ecx_contextt *context, uint16 Slave, int Thread_n, int *Osize, int *Isize); 86 | int ecx_readODlist(ecx_contextt *context, uint16 Slave, ec_ODlistt *pODlist); 87 | int ecx_readODdescription(ecx_contextt *context, uint16 Item, ec_ODlistt *pODlist); 88 | int ecx_readOEsingle(ecx_contextt *context, uint16 Item, uint8 SubI, ec_ODlistt *pODlist, ec_OElistt *pOElist); 89 | int ecx_readOE(ecx_contextt *context, uint16 Item, ec_ODlistt *pODlist, ec_OElistt *pOElist); 90 | 91 | #ifdef __cplusplus 92 | } 93 | #endif 94 | 95 | #endif 96 | -------------------------------------------------------------------------------- /soem/ethercatconfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the GNU General Public License version 2 with exceptions. See 3 | * LICENSE file in the project root for full license information 4 | */ 5 | 6 | /** \file 7 | * \brief 8 | * Headerfile for ethercatconfig.c 9 | */ 10 | 11 | #ifndef _ethercatconfig_ 12 | #define _ethercatconfig_ 13 | 14 | #ifdef __cplusplus 15 | extern "C" 16 | { 17 | #endif 18 | 19 | #define EC_NODEOFFSET 0x1000 20 | #define EC_TEMPNODE 0xffff 21 | 22 | #ifdef EC_VER1 23 | int ec_config_init(uint8 usetable); 24 | int ec_config_map(void *pIOmap); 25 | int ec_config_overlap_map(void *pIOmap); 26 | int ec_config_map_group(void *pIOmap, uint8 group); 27 | int ec_config_overlap_map_group(void *pIOmap, uint8 group); 28 | int ec_config(uint8 usetable, void *pIOmap); 29 | int ec_config_overlap(uint8 usetable, void *pIOmap); 30 | int ec_recover_slave(uint16 slave, int timeout); 31 | int ec_reconfig_slave(uint16 slave, int timeout); 32 | #endif 33 | 34 | int ecx_config_init(ecx_contextt *context, uint8 usetable); 35 | int ecx_config_map_group(ecx_contextt *context, void *pIOmap, uint8 group); 36 | int ecx_config_overlap_map_group(ecx_contextt *context, void *pIOmap, uint8 group); 37 | int ecx_recover_slave(ecx_contextt *context, uint16 slave, int timeout); 38 | int ecx_reconfig_slave(ecx_contextt *context, uint16 slave, int timeout); 39 | 40 | #ifdef __cplusplus 41 | } 42 | #endif 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /soem/ethercatconfiglist.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the GNU General Public License version 2 with exceptions. See 3 | * LICENSE file in the project root for full license information 4 | */ 5 | 6 | /** \file 7 | * \brief 8 | * DEPRECATED Configuration list of known EtherCAT slave devices. 9 | * 10 | * If a slave is found in this list it is configured according to the parameters 11 | * in the list. Otherwise the configuration info is read directly from the slave 12 | * EEPROM (SII or Slave Information Interface). 13 | */ 14 | 15 | #ifndef _ethercatconfiglist_ 16 | #define _ethercatconfiglist_ 17 | 18 | #ifdef __cplusplus 19 | extern "C" 20 | { 21 | #endif 22 | 23 | /* 24 | explanation of dev: 25 | 1: static device with no IO mapping ie EK1100 26 | 2: input device no mailbox ie simple IO device 27 | 3: output device no mailbox 28 | 4: input device with mailbox configuration 29 | 5: output device with mailbox configuration 30 | 6: input/output device no mailbox 31 | 7: input.output device with mailbox configuration 32 | */ 33 | #define EC_CONFIGEND 0xffffffff 34 | 35 | ec_configlist_t ec_configlist[] = { 36 | {/*Man=*/0x00000000,/*ID=*/0x00000000,/*Name=*/"" ,/*dtype=*/0,/*Ibits=*/ 0,/*Obits=*/ 0,/*SM2a*/ 0,/*SM2f*/ 0,/*SM3a*/ 0,/*SM3f*/ 0,/*FM0ac*/0,/*FM1ac*/0}, 37 | {/*Man=*/0x00000002,/*ID=*/0x044c2c52,/*Name=*/"EK1100" ,/*dtype=*/1,/*Ibits=*/ 0,/*Obits=*/ 0,/*SM2a*/ 0,/*SM2f*/ 0,/*SM3a*/ 0,/*SM3f*/ 0,/*FM0ac*/0,/*FM1ac*/0}, 38 | {/*Man=*/0x00000002,/*ID=*/0x03ea3052,/*Name=*/"EL1002" ,/*dtype=*/2,/*Ibits=*/ 2,/*Obits=*/ 0,/*SM2a*/ 0,/*SM2f*/ 0,/*SM3a*/ 0,/*SM3f*/ 0,/*FM0ac*/0,/*FM1ac*/0}, 39 | {/*Man=*/0x00000002,/*ID=*/0x03ec3052,/*Name=*/"EL1004" ,/*dtype=*/2,/*Ibits=*/ 4,/*Obits=*/ 0,/*SM2a*/ 0,/*SM2f*/ 0,/*SM3a*/ 0,/*SM3f*/ 0,/*FM0ac*/0,/*FM1ac*/0}, 40 | {/*Man=*/0x00000002,/*ID=*/0x03f43052,/*Name=*/"EL1012" ,/*dtype=*/2,/*Ibits=*/ 2,/*Obits=*/ 0,/*SM2a*/ 0,/*SM2f*/ 0,/*SM3a*/ 0,/*SM3f*/ 0,/*FM0ac*/0,/*FM1ac*/0}, 41 | {/*Man=*/0x00000002,/*ID=*/0x03f63052,/*Name=*/"EL1014" ,/*dtype=*/2,/*Ibits=*/ 4,/*Obits=*/ 0,/*SM2a*/ 0,/*SM2f*/ 0,/*SM3a*/ 0,/*SM3f*/ 0,/*FM0ac*/0,/*FM1ac*/0}, 42 | {/*Man=*/0x00000002,/*ID=*/0x03fa3052,/*Name=*/"EL1018" ,/*dtype=*/2,/*Ibits=*/ 8,/*Obits=*/ 0,/*SM2a*/ 0,/*SM2f*/ 0,/*SM3a*/ 0,/*SM3f*/ 0,/*FM0ac*/0,/*FM1ac*/0}, 43 | {/*Man=*/0x00000002,/*ID=*/0x07d23052,/*Name=*/"EL2002" ,/*dtype=*/3,/*Ibits=*/ 0,/*Obits=*/ 2,/*SM2a*/ 0,/*SM2f*/ 0,/*SM3a*/ 0,/*SM3f*/ 0,/*FM0ac*/0,/*FM1ac*/0}, 44 | {/*Man=*/0x00000002,/*ID=*/0x07d43052,/*Name=*/"EL2004" ,/*dtype=*/3,/*Ibits=*/ 0,/*Obits=*/ 4,/*SM2a*/ 0,/*SM2f*/ 0,/*SM3a*/ 0,/*SM3f*/ 0,/*FM0ac*/0,/*FM1ac*/0}, 45 | {/*Man=*/0x00000002,/*ID=*/0x07d83052,/*Name=*/"EL2008" ,/*dtype=*/3,/*Ibits=*/ 0,/*Obits=*/ 8,/*SM2a*/ 0,/*SM2f*/ 0,/*SM3a*/ 0,/*SM3f*/ 0,/*FM0ac*/0,/*FM1ac*/0}, 46 | {/*Man=*/0x00000002,/*ID=*/0x07f03052,/*Name=*/"EL2032" ,/*dtype=*/6,/*Ibits=*/ 2,/*Obits=*/ 2,/*SM2a*/ 0,/*SM2f*/ 0,/*SM3a*/ 0,/*SM3f*/ 0,/*FM0ac*/0,/*FM1ac*/0}, 47 | {/*Man=*/0x00000002,/*ID=*/0x0c1e3052,/*Name=*/"EL3102" ,/*dtype=*/4,/*Ibits=*/48,/*Obits=*/ 0,/*SM2a*/0x1000,/*SM2f*/0x00000024,/*SM3a*/0x1100,/*SM3f*/0x00010020,/*FM0ac*/0,/*FM1ac*/1}, 48 | {/*Man=*/0x00000002,/*ID=*/0x0c283052,/*Name=*/"EL3112" ,/*dtype=*/4,/*Ibits=*/48,/*Obits=*/ 0,/*SM2a*/0x1000,/*SM2f*/0x00000024,/*SM3a*/0x1100,/*SM3f*/0x00010020,/*FM0ac*/0,/*FM1ac*/1}, 49 | {/*Man=*/0x00000002,/*ID=*/0x0c323052,/*Name=*/"EL3122" ,/*dtype=*/4,/*Ibits=*/48,/*Obits=*/ 0,/*SM2a*/0x1000,/*SM2f*/0x00000024,/*SM3a*/0x1100,/*SM3f*/0x00010020,/*FM0ac*/0,/*FM1ac*/1}, 50 | {/*Man=*/0x00000002,/*ID=*/0x0c463052,/*Name=*/"EL3142" ,/*dtype=*/4,/*Ibits=*/48,/*Obits=*/ 0,/*SM2a*/0x1000,/*SM2f*/0x00000024,/*SM3a*/0x1100,/*SM3f*/0x00010020,/*FM0ac*/0,/*FM1ac*/1}, 51 | {/*Man=*/0x00000002,/*ID=*/0x0c503052,/*Name=*/"EL3152" ,/*dtype=*/4,/*Ibits=*/48,/*Obits=*/ 0,/*SM2a*/0x1000,/*SM2f*/0x00000024,/*SM3a*/0x1100,/*SM3f*/0x00010020,/*FM0ac*/0,/*FM1ac*/1}, 52 | {/*Man=*/0x00000002,/*ID=*/0x0c5a3052,/*Name=*/"EL3162" ,/*dtype=*/4,/*Ibits=*/48,/*Obits=*/ 0,/*SM2a*/0x1000,/*SM2f*/0x00000024,/*SM3a*/0x1100,/*SM3f*/0x00010020,/*FM0ac*/0,/*FM1ac*/1}, 53 | {/*Man=*/0x00000002,/*ID=*/0x0fc03052,/*Name=*/"EL4032" ,/*dtype=*/5,/*Ibits=*/ 0,/*Obits=*/32,/*SM2a*/0x1100,/*SM2f*/0x00010024,/*SM3a*/0x1180,/*SM3f*/0x00000022,/*FM0ac*/1,/*FM1ac*/0}, 54 | {/*Man=*/0x00000002,/*ID=*/0x10063052,/*Name=*/"EL4102" ,/*dtype=*/5,/*Ibits=*/ 0,/*Obits=*/32,/*SM2a*/0x1000,/*SM2f*/0x00010024,/*SM3a*/0x1100,/*SM3f*/0x00000022,/*FM0ac*/1,/*FM1ac*/0}, 55 | {/*Man=*/0x00000002,/*ID=*/0x10103052,/*Name=*/"EL4112" ,/*dtype=*/5,/*Ibits=*/ 0,/*Obits=*/32,/*SM2a*/0x1000,/*SM2f*/0x00010024,/*SM3a*/0x1100,/*SM3f*/0x00000022,/*FM0ac*/1,/*FM1ac*/0}, 56 | {/*Man=*/0x00000002,/*ID=*/0x101a3052,/*Name=*/"EL4122" ,/*dtype=*/5,/*Ibits=*/ 0,/*Obits=*/32,/*SM2a*/0x1000,/*SM2f*/0x00010024,/*SM3a*/0x1100,/*SM3f*/0x00000022,/*FM0ac*/1,/*FM1ac*/0}, 57 | {/*Man=*/0x00000002,/*ID=*/0x10243052,/*Name=*/"EL4132" ,/*dtype=*/5,/*Ibits=*/ 0,/*Obits=*/32,/*SM2a*/0x1000,/*SM2f*/0x00010024,/*SM3a*/0x1100,/*SM3f*/0x00000022,/*FM0ac*/1,/*FM1ac*/0}, 58 | {/*Man=*/0x00000002,/*ID=*/0x13ed3052,/*Name=*/"EL5101" ,/*dtype=*/7,/*Ibits=*/40,/*Obits=*/24,/*SM2a*/0x1000,/*SM2f*/0x00010024,/*SM3a*/0x1100,/*SM3f*/0x00010020,/*FM0ac*/1,/*FM1ac*/1}, 59 | {/*Man=*/EC_CONFIGEND,/*ID=*/0x00000000,/*Name=*/"" ,/*dtype=*/0,/*Ibits=*/ 0,/*Obits=*/ 0,/*SM2a*/ 0,/*SM2f*/ 0,/*SM3a*/ 0,/*SM3f*/ 0,/*FM0ac*/0,/*FM1ac*/0} 60 | }; 61 | 62 | #ifdef __cplusplus 63 | } 64 | #endif 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /soem/ethercatdc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the GNU General Public License version 2 with exceptions. See 3 | * LICENSE file in the project root for full license information 4 | */ 5 | 6 | /** \file 7 | * \brief 8 | * Headerfile for ethercatdc.c 9 | */ 10 | 11 | #ifndef _EC_ECATDC_H 12 | #define _EC_ECATDC_H 13 | 14 | #ifdef __cplusplus 15 | extern "C" 16 | { 17 | #endif 18 | 19 | #ifdef EC_VER1 20 | boolean ec_configdc(); 21 | void ec_dcsync0(uint16 slave, boolean act, uint32 CyclTime, int32 CyclShift); 22 | void ec_dcsync01(uint16 slave, boolean act, uint32 CyclTime0, uint32 CyclTime1, int32 CyclShift); 23 | #endif 24 | 25 | boolean ecx_configdc(ecx_contextt *context); 26 | void ecx_dcsync0(ecx_contextt *context, uint16 slave, boolean act, uint32 CyclTime, int32 CyclShift); 27 | void ecx_dcsync01(ecx_contextt *context, uint16 slave, boolean act, uint32 CyclTime0, uint32 CyclTime1, int32 CyclShift); 28 | 29 | #ifdef __cplusplus 30 | } 31 | #endif 32 | 33 | #endif /* _EC_ECATDC_H */ 34 | -------------------------------------------------------------------------------- /soem/ethercateoe.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the GNU General Public License version 2 with exceptions. See 3 | * LICENSE file in the project root for full license information 4 | */ 5 | 6 | /** \file 7 | * \brief 8 | * Headerfile for ethercatfoe.c 9 | */ 10 | 11 | #ifndef _ethercateoe_ 12 | #define _ethercateoe_ 13 | 14 | #ifdef __cplusplus 15 | extern "C" 16 | { 17 | #endif 18 | 19 | #include 20 | 21 | /** DNS length according to ETG 1000.6 */ 22 | #define EOE_DNS_NAME_LENGTH 32 23 | /** Ethernet address length not including VLAN */ 24 | #define EOE_ETHADDR_LENGTH 6 25 | 26 | #define EOE_MAKEU32(a,b,c,d) (((uint32_t)((a) & 0xff) << 24) | \ 27 | ((uint32_t)((b) & 0xff) << 16) | \ 28 | ((uint32_t)((c) & 0xff) << 8) | \ 29 | (uint32_t)((d) & 0xff)) 30 | 31 | #if !defined(EC_BIG_ENDIAN) && defined(EC_LITTLE_ENDIAN) 32 | 33 | #define EOE_HTONS(x) ((((x) & 0x00ffUL) << 8) | (((x) & 0xff00UL) >> 8)) 34 | #define EOE_NTOHS(x) EOE_HTONS(x) 35 | #define EOE_HTONL(x) ((((x) & 0x000000ffUL) << 24) | \ 36 | (((x) & 0x0000ff00UL) << 8) | \ 37 | (((x) & 0x00ff0000UL) >> 8) | \ 38 | (((x) & 0xff000000UL) >> 24)) 39 | #define EOE_NTOHL(x) EOE_HTONL(x) 40 | #else 41 | #define EOE_HTONS(x) (x) 42 | #define EOE_NTOHS(x) (x) 43 | #define EOE_HTONL(x) (x) 44 | #define EOE_NTOHL(x) (x) 45 | #endif /* !defined(EC_BIG_ENDIAN) && defined(EC_LITTLE_ENDIAN) */ 46 | 47 | /** Get one byte from the 4-byte address */ 48 | #define eoe_ip4_addr1(ipaddr) (((const uint8_t*)(&(ipaddr)->addr))[0]) 49 | #define eoe_ip4_addr2(ipaddr) (((const uint8_t*)(&(ipaddr)->addr))[1]) 50 | #define eoe_ip4_addr3(ipaddr) (((const uint8_t*)(&(ipaddr)->addr))[2]) 51 | #define eoe_ip4_addr4(ipaddr) (((const uint8_t*)(&(ipaddr)->addr))[3]) 52 | 53 | /** Set an IP address given by the four byte-parts */ 54 | #define EOE_IP4_ADDR_TO_U32(ipaddr,a,b,c,d) \ 55 | (ipaddr)->addr = EOE_HTONL(EOE_MAKEU32(a,b,c,d)) 56 | 57 | /** Header frame info 1 */ 58 | #define EOE_HDR_FRAME_TYPE_OFFSET 0 59 | #define EOE_HDR_FRAME_TYPE (0xF << 0) 60 | #define EOE_HDR_FRAME_TYPE_SET(x) (((x) & 0xF) << 0) 61 | #define EOE_HDR_FRAME_TYPE_GET(x) (((x) >> 0) & 0xF) 62 | #define EOE_HDR_FRAME_PORT_OFFSET 4 63 | #define EOE_HDR_FRAME_PORT (0xF << 4) 64 | #define EOE_HDR_FRAME_PORT_SET(x) (((x) & 0xF) << 4) 65 | #define EOE_HDR_FRAME_PORT_GET(x) (((x) >> 4) & 0xF) 66 | #define EOE_HDR_LAST_FRAGMENT_OFFSET 8 67 | #define EOE_HDR_LAST_FRAGMENT (0x1 << 8) 68 | #define EOE_HDR_LAST_FRAGMENT_SET(x) (((x) & 0x1) << 8) 69 | #define EOE_HDR_LAST_FRAGMENT_GET(x) (((x) >> 8) & 0x1) 70 | #define EOE_HDR_TIME_APPEND_OFFSET 9 71 | #define EOE_HDR_TIME_APPEND (0x1 << 9) 72 | #define EOE_HDR_TIME_APPEND_SET(x) (((x) & 0x1) << 9) 73 | #define EOE_HDR_TIME_APPEND_GET(x) (((x) >> 9) & 0x1) 74 | #define EOE_HDR_TIME_REQUEST_OFFSET 10 75 | #define EOE_HDR_TIME_REQUEST (0x1 << 10) 76 | #define EOE_HDR_TIME_REQUEST_SET(x) (((x) & 0x1) << 10) 77 | #define EOE_HDR_TIME_REQUEST_GET(x) (((x) >> 10) & 0x1) 78 | 79 | /** Header frame info 2 */ 80 | #define EOE_HDR_FRAG_NO_OFFSET 0 81 | #define EOE_HDR_FRAG_NO (0x3F << 0) 82 | #define EOE_HDR_FRAG_NO_SET(x) (((x) & 0x3F) << 0) 83 | #define EOE_HDR_FRAG_NO_GET(x) (((x) >> 0) & 0x3F) 84 | #define EOE_HDR_FRAME_OFFSET_OFFSET 6 85 | #define EOE_HDR_FRAME_OFFSET (0x3F << 6) 86 | #define EOE_HDR_FRAME_OFFSET_SET(x) (((x) & 0x3F) << 6) 87 | #define EOE_HDR_FRAME_OFFSET_GET(x) (((x) >> 6) & 0x3F) 88 | #define EOE_HDR_FRAME_NO_OFFSET 12 89 | #define EOE_HDR_FRAME_NO (0xF << 12) 90 | #define EOE_HDR_FRAME_NO_SET(x) (((x) & 0xF) << 12) 91 | #define EOE_HDR_FRAME_NO_GET(x) (((x) >> 12) & 0xF) 92 | 93 | /** EOE param */ 94 | #define EOE_PARAM_OFFSET 4 95 | #define EOE_PARAM_MAC_INCLUDE (0x1 << 0) 96 | #define EOE_PARAM_IP_INCLUDE (0x1 << 1) 97 | #define EOE_PARAM_SUBNET_IP_INCLUDE (0x1 << 2) 98 | #define EOE_PARAM_DEFAULT_GATEWAY_INCLUDE (0x1 << 3) 99 | #define EOE_PARAM_DNS_IP_INCLUDE (0x1 << 4) 100 | #define EOE_PARAM_DNS_NAME_INCLUDE (0x1 << 5) 101 | 102 | /** EoE frame types */ 103 | #define EOE_FRAG_DATA 0 104 | #define EOE_INIT_RESP_TIMESTAMP 1 105 | #define EOE_INIT_REQ 2 /* Spec SET IP REQ */ 106 | #define EOE_INIT_RESP 3 /* Spec SET IP RESP */ 107 | #define EOE_SET_ADDR_FILTER_REQ 4 108 | #define EOE_SET_ADDR_FILTER_RESP 5 109 | #define EOE_GET_IP_PARAM_REQ 6 110 | #define EOE_GET_IP_PARAM_RESP 7 111 | #define EOE_GET_ADDR_FILTER_REQ 8 112 | #define EOE_GET_ADDR_FILTER_RESP 9 113 | 114 | /** EoE parameter result codes */ 115 | #define EOE_RESULT_SUCCESS 0x0000 116 | #define EOE_RESULT_UNSPECIFIED_ERROR 0x0001 117 | #define EOE_RESULT_UNSUPPORTED_FRAME_TYPE 0x0002 118 | #define EOE_RESULT_NO_IP_SUPPORT 0x0201 119 | #define EOE_RESULT_NO_DHCP_SUPPORT 0x0202 120 | #define EOE_RESULT_NO_FILTER_SUPPORT 0x0401 121 | 122 | 123 | /** EOE ip4 address in network order */ 124 | typedef struct eoe_ip4_addr { 125 | uint32_t addr; 126 | }eoe_ip4_addr_t; 127 | 128 | /** EOE ethernet address */ 129 | PACKED_BEGIN 130 | typedef struct PACKED eoe_ethaddr 131 | { 132 | uint8_t addr[EOE_ETHADDR_LENGTH]; 133 | } eoe_ethaddr_t; 134 | PACKED_END 135 | 136 | /** EoE IP request structure, storage only, no need to pack */ 137 | typedef struct eoe_param 138 | { 139 | uint8_t mac_set : 1; 140 | uint8_t ip_set : 1; 141 | uint8_t subnet_set : 1; 142 | uint8_t default_gateway_set : 1; 143 | uint8_t dns_ip_set : 1; 144 | uint8_t dns_name_set : 1; 145 | eoe_ethaddr_t mac; 146 | eoe_ip4_addr_t ip; 147 | eoe_ip4_addr_t subnet; 148 | eoe_ip4_addr_t default_gateway; 149 | eoe_ip4_addr_t dns_ip; 150 | char dns_name[EOE_DNS_NAME_LENGTH]; 151 | } eoe_param_t; 152 | 153 | /** EOE structure. 154 | * Used to interpret EoE mailbox packets. 155 | */ 156 | PACKED_BEGIN 157 | typedef struct PACKED 158 | { 159 | ec_mbxheadert mbxheader; 160 | uint16_t frameinfo1; 161 | union 162 | { 163 | uint16_t frameinfo2; 164 | uint16_t result; 165 | }; 166 | uint8 data[0]; 167 | } ec_EOEt; 168 | PACKED_END 169 | 170 | int ecx_EOEdefinehook(ecx_contextt *context, void *hook); 171 | int ecx_EOEsetIp(ecx_contextt *context, 172 | uint16 slave, 173 | uint8 port, 174 | eoe_param_t * ipparam, 175 | int timeout); 176 | int ecx_EOEgetIp(ecx_contextt *context, 177 | uint16 slave, 178 | uint8 port, 179 | eoe_param_t * ipparam, 180 | int timeout); 181 | int ecx_EOEsend(ecx_contextt *context, 182 | uint16 slave, 183 | uint8 port, 184 | int psize, 185 | void *p, 186 | int timeout); 187 | int ecx_EOErecv(ecx_contextt *context, 188 | uint16 slave, 189 | uint8 port, 190 | int * psize, 191 | void *p, 192 | int timeout); 193 | int ecx_EOEreadfragment( 194 | ec_mbxbuft * MbxIn, 195 | uint8 * rxfragmentno, 196 | uint16 * rxframesize, 197 | uint16 * rxframeoffset, 198 | uint16 * rxframeno, 199 | int * psize, 200 | void *p); 201 | 202 | #ifdef __cplusplus 203 | } 204 | #endif 205 | 206 | #endif 207 | -------------------------------------------------------------------------------- /soem/ethercatfoe.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the GNU General Public License version 2 with exceptions. See 3 | * LICENSE file in the project root for full license information 4 | */ 5 | 6 | /** \file 7 | * \brief 8 | * Headerfile for ethercatfoe.c 9 | */ 10 | 11 | #ifndef _ethercatfoe_ 12 | #define _ethercatfoe_ 13 | 14 | #ifdef __cplusplus 15 | extern "C" 16 | { 17 | #endif 18 | 19 | #ifdef EC_VER1 20 | int ec_FOEdefinehook(void *hook); 21 | int ec_FOEread(uint16 slave, char *filename, uint32 password, int *psize, void *p, int timeout); 22 | int ec_FOEwrite(uint16 slave, char *filename, uint32 password, int psize, void *p, int timeout); 23 | #endif 24 | 25 | int ecx_FOEdefinehook(ecx_contextt *context, void *hook); 26 | int ecx_FOEread(ecx_contextt *context, uint16 slave, char *filename, uint32 password, int *psize, void *p, int timeout); 27 | int ecx_FOEwrite(ecx_contextt *context, uint16 slave, char *filename, uint32 password, int psize, void *p, int timeout); 28 | 29 | #ifdef __cplusplus 30 | } 31 | #endif 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /soem/ethercatprint.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the GNU General Public License version 2 with exceptions. See 3 | * LICENSE file in the project root for full license information 4 | */ 5 | 6 | /** \file 7 | * \brief 8 | * Headerfile for ethercatprint.c 9 | */ 10 | 11 | #ifndef _ethercatprint_ 12 | #define _ethercatprint_ 13 | 14 | #ifdef __cplusplus 15 | extern "C" 16 | { 17 | #endif 18 | 19 | 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 EC_VER1 27 | char* ec_elist2string(void); 28 | #endif 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /soem/ethercatsoe.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the GNU General Public License version 2 with exceptions. See 3 | * LICENSE file in the project root for full license information 4 | */ 5 | 6 | /** \file 7 | * \brief 8 | * Headerfile for ethercatsoe.c 9 | */ 10 | 11 | #ifndef _ethercatsoe_ 12 | #define _ethercatsoe_ 13 | 14 | #ifdef __cplusplus 15 | extern "C" 16 | { 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_SOE_MAXNAME 60 29 | #define EC_SOE_MAXMAPPING 64 30 | 31 | #define EC_IDN_MDTCONFIG 24 32 | #define EC_IDN_ATCONFIG 16 33 | 34 | /** SoE name structure */ 35 | PACKED_BEGIN 36 | typedef struct PACKED 37 | { 38 | /** current length in bytes of list */ 39 | uint16 currentlength; 40 | /** maximum length in bytes of list */ 41 | uint16 maxlength; 42 | char name[EC_SOE_MAXNAME]; 43 | } ec_SoEnamet; 44 | PACKED_END 45 | 46 | /** SoE list structure */ 47 | PACKED_BEGIN 48 | typedef struct PACKED 49 | { 50 | /** current length in bytes of list */ 51 | uint16 currentlength; 52 | /** maximum length in bytes of list */ 53 | uint16 maxlength; 54 | union 55 | { 56 | uint8 byte[8]; 57 | uint16 word[4]; 58 | uint32 dword[2]; 59 | uint64 lword[1]; 60 | }; 61 | } ec_SoElistt; 62 | PACKED_END 63 | 64 | /** SoE IDN mapping structure */ 65 | PACKED_BEGIN 66 | typedef struct PACKED 67 | { 68 | /** current length in bytes of list */ 69 | uint16 currentlength; 70 | /** maximum length in bytes of list */ 71 | uint16 maxlength; 72 | uint16 idn[EC_SOE_MAXMAPPING]; 73 | } ec_SoEmappingt; 74 | PACKED_END 75 | 76 | #define EC_SOE_LENGTH_1 0x00 77 | #define EC_SOE_LENGTH_2 0x01 78 | #define EC_SOE_LENGTH_4 0x02 79 | #define EC_SOE_LENGTH_8 0x03 80 | #define EC_SOE_TYPE_BINARY 0x00 81 | #define EC_SOE_TYPE_UINT 0x01 82 | #define EC_SOE_TYPE_INT 0x02 83 | #define EC_SOE_TYPE_HEX 0x03 84 | #define EC_SOE_TYPE_STRING 0x04 85 | #define EC_SOE_TYPE_IDN 0x05 86 | #define EC_SOE_TYPE_FLOAT 0x06 87 | #define EC_SOE_TYPE_PARAMETER 0x07 88 | 89 | /** SoE attribute structure */ 90 | PACKED_BEGIN 91 | typedef struct PACKED 92 | { 93 | /** evaluation factor for display purposes */ 94 | uint32 evafactor :16; 95 | /** length of IDN element(s) */ 96 | uint32 length :2; 97 | /** IDN is list */ 98 | uint32 list :1; 99 | /** IDN is command */ 100 | uint32 command :1; 101 | /** datatype */ 102 | uint32 datatype :3; 103 | uint32 reserved1 :1; 104 | /** decimals to display if float datatype */ 105 | uint32 decimals :4; 106 | /** write protected in pre-op */ 107 | uint32 wppreop :1; 108 | /** write protected in safe-op */ 109 | uint32 wpsafeop :1; 110 | /** write protected in op */ 111 | uint32 wpop :1; 112 | uint32 reserved2 :1; 113 | } ec_SoEattributet; 114 | PACKED_END 115 | 116 | #ifdef EC_VER1 117 | int ec_SoEread(uint16 slave, uint8 driveNo, uint8 elementflags, uint16 idn, int *psize, void *p, int timeout); 118 | int ec_SoEwrite(uint16 slave, uint8 driveNo, uint8 elementflags, uint16 idn, int psize, void *p, int timeout); 119 | int ec_readIDNmap(uint16 slave, int *Osize, int *Isize); 120 | #endif 121 | 122 | int ecx_SoEread(ecx_contextt *context, uint16 slave, uint8 driveNo, uint8 elementflags, uint16 idn, int *psize, void *p, int timeout); 123 | int ecx_SoEwrite(ecx_contextt *context, uint16 slave, uint8 driveNo, uint8 elementflags, uint16 idn, int psize, void *p, int timeout); 124 | int ecx_readIDNmap(ecx_contextt *context, uint16 slave, int *Osize, int *Isize); 125 | 126 | #ifdef __cplusplus 127 | } 128 | #endif 129 | 130 | #endif -------------------------------------------------------------------------------- /test/linux/eepromtool/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set(SOURCES eepromtool.c) 3 | add_executable(eepromtool ${SOURCES}) 4 | target_link_libraries(eepromtool soem) 5 | install(TARGETS eepromtool DESTINATION bin) 6 | -------------------------------------------------------------------------------- /test/linux/firm_update/firm_update.c: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \brief Example code for Simple Open EtherCAT master 3 | * 4 | * Usage: firm_update ifname1 slave fname 5 | * ifname is NIC interface, f.e. eth0 6 | * slave = slave number in EtherCAT order 1..n 7 | * fname = binary file to store in slave 8 | * CAUTION! Using the wrong file can result in a bricked slave! 9 | * 10 | * This is a slave firmware update test. 11 | * 12 | * (c)Arthur Ketels 2011 13 | */ 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #include "ethercat.h" 22 | 23 | #define FWBUFSIZE (8 * 1024 * 1024) 24 | 25 | uint8 ob; 26 | uint16 ow; 27 | uint32 data; 28 | char filename[256]; 29 | char filebuffer[FWBUFSIZE]; // 8MB buffer 30 | int filesize; 31 | int j; 32 | uint16 argslave; 33 | 34 | int input_bin(char *fname, int *length) 35 | { 36 | FILE *fp; 37 | 38 | int cc = 0, c; 39 | 40 | fp = fopen(fname, "rb"); 41 | if(fp == NULL) 42 | return 0; 43 | while (((c = fgetc(fp)) != EOF) && (cc < FWBUFSIZE)) 44 | filebuffer[cc++] = (uint8)c; 45 | *length = cc; 46 | fclose(fp); 47 | return 1; 48 | } 49 | 50 | 51 | void boottest(char *ifname, uint16 slave, char *filename) 52 | { 53 | printf("Starting firmware update example\n"); 54 | 55 | /* initialise SOEM, bind socket to ifname */ 56 | if (ec_init(ifname)) 57 | { 58 | printf("ec_init on %s succeeded.\n",ifname); 59 | /* find and auto-config slaves */ 60 | 61 | 62 | if ( ec_config_init(FALSE) > 0 ) 63 | { 64 | printf("%d slaves found and configured.\n",ec_slavecount); 65 | 66 | printf("Request init state for slave %d\n", slave); 67 | ec_slave[slave].state = EC_STATE_INIT; 68 | ec_writestate(slave); 69 | 70 | /* wait for slave to reach INIT state */ 71 | ec_statecheck(slave, EC_STATE_INIT, EC_TIMEOUTSTATE * 4); 72 | printf("Slave %d state to INIT.\n", slave); 73 | 74 | /* read BOOT mailbox data, master -> slave */ 75 | data = ec_readeeprom(slave, ECT_SII_BOOTRXMBX, EC_TIMEOUTEEP); 76 | ec_slave[slave].SM[0].StartAddr = (uint16)LO_WORD(data); 77 | ec_slave[slave].SM[0].SMlength = (uint16)HI_WORD(data); 78 | /* store boot write mailbox address */ 79 | ec_slave[slave].mbx_wo = (uint16)LO_WORD(data); 80 | /* store boot write mailbox size */ 81 | ec_slave[slave].mbx_l = (uint16)HI_WORD(data); 82 | 83 | /* read BOOT mailbox data, slave -> master */ 84 | data = ec_readeeprom(slave, ECT_SII_BOOTTXMBX, EC_TIMEOUTEEP); 85 | ec_slave[slave].SM[1].StartAddr = (uint16)LO_WORD(data); 86 | ec_slave[slave].SM[1].SMlength = (uint16)HI_WORD(data); 87 | /* store boot read mailbox address */ 88 | ec_slave[slave].mbx_ro = (uint16)LO_WORD(data); 89 | /* store boot read mailbox size */ 90 | ec_slave[slave].mbx_rl = (uint16)HI_WORD(data); 91 | 92 | printf(" SM0 A:%4.4x L:%4d F:%8.8x\n", ec_slave[slave].SM[0].StartAddr, ec_slave[slave].SM[0].SMlength, 93 | (int)ec_slave[slave].SM[0].SMflags); 94 | printf(" SM1 A:%4.4x L:%4d F:%8.8x\n", ec_slave[slave].SM[1].StartAddr, ec_slave[slave].SM[1].SMlength, 95 | (int)ec_slave[slave].SM[1].SMflags); 96 | /* program SM0 mailbox in for slave */ 97 | ec_FPWR (ec_slave[slave].configadr, ECT_REG_SM0, sizeof(ec_smt), &ec_slave[slave].SM[0], EC_TIMEOUTRET); 98 | /* program SM1 mailbox out for slave */ 99 | ec_FPWR (ec_slave[slave].configadr, ECT_REG_SM1, sizeof(ec_smt), &ec_slave[slave].SM[1], EC_TIMEOUTRET); 100 | 101 | printf("Request BOOT state for slave %d\n", slave); 102 | ec_slave[slave].state = EC_STATE_BOOT; 103 | ec_writestate(slave); 104 | 105 | /* wait for slave to reach BOOT state */ 106 | if (ec_statecheck(slave, EC_STATE_BOOT, EC_TIMEOUTSTATE * 10) == EC_STATE_BOOT) 107 | { 108 | printf("Slave %d state to BOOT.\n", slave); 109 | 110 | if (input_bin(filename, &filesize)) 111 | { 112 | printf("File read OK, %d bytes.\n",filesize); 113 | printf("FoE write...."); 114 | j = ec_FOEwrite(slave, filename, 0, filesize , &filebuffer, EC_TIMEOUTSTATE); 115 | printf("result %d.\n",j); 116 | printf("Request init state for slave %d\n", slave); 117 | ec_slave[slave].state = EC_STATE_INIT; 118 | ec_writestate(slave); 119 | } 120 | else 121 | printf("File not read OK.\n"); 122 | } 123 | 124 | } 125 | else 126 | { 127 | printf("No slaves found!\n"); 128 | } 129 | printf("End firmware update example, close socket\n"); 130 | /* stop SOEM, close socket */ 131 | ec_close(); 132 | } 133 | else 134 | { 135 | printf("No socket connection on %s\nExcecute as root\n",ifname); 136 | } 137 | } 138 | 139 | int main(int argc, char *argv[]) 140 | { 141 | printf("SOEM (Simple Open EtherCAT Master)\nFirmware update example\n"); 142 | 143 | if (argc > 3) 144 | { 145 | argslave = atoi(argv[2]); 146 | boottest(argv[1], argslave, argv[3]); 147 | } 148 | else 149 | { 150 | printf("Usage: firm_update ifname1 slave fname\n"); 151 | printf("ifname = eth0 for example\n"); 152 | printf("slave = slave number in EtherCAT order 1..n\n"); 153 | printf("fname = binary file to store in slave\n"); 154 | printf("CAUTION! Using the wrong file can result in a bricked slave!\n"); 155 | } 156 | 157 | printf("End program\n"); 158 | return (0); 159 | } 160 | -------------------------------------------------------------------------------- /test/linux/fsoe_sample/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set(SOURCES fsoe_sample.c) 3 | add_executable(fsoe_sample ${SOURCES}) 4 | target_link_libraries(fsoe_sample soem) 5 | install(TARGETS fsoe_sample DESTINATION bin) 6 | -------------------------------------------------------------------------------- /test/linux/simple_test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set(SOURCES simple_test.c) 3 | add_executable(simple_test ${SOURCES}) 4 | target_link_libraries(simple_test soem) 5 | install(TARGETS simple_test DESTINATION bin) 6 | -------------------------------------------------------------------------------- /test/linux/slaveinfo/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set(SOURCES slaveinfo.c) 3 | add_executable(slaveinfo ${SOURCES}) 4 | target_link_libraries(slaveinfo soem) 5 | install(TARGETS slaveinfo DESTINATION bin) 6 | -------------------------------------------------------------------------------- /test/rtk/schedule.tt: -------------------------------------------------------------------------------- 1 | stack_size: 2048 2 | 3 | tasks: 4 | - name : tReadIO 5 | entry : read_io 6 | arg : 'NULL' 7 | 8 | schedules: 9 | - name : sched1 10 | period : 1 11 | events : 12 | - task : tReadIO 13 | start : 0 14 | stop : 1 -------------------------------------------------------------------------------- /test/win32/firm_update/firm_update.c: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \brief Example code for Simple Open EtherCAT master 3 | * 4 | * Usage: firm_update ifname1 slave fname 5 | * ifname is NIC interface, f.e. eth0 6 | * slave = slave number in EtherCAT order 1..n 7 | * fname = binary file to store in slave 8 | * CAUTION! Using the wrong file can result in a bricked slave! 9 | * 10 | * This is a slave firmware update test. 11 | * 12 | * (c)Arthur Ketels 2011 13 | */ 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #include "ethercat.h" 22 | 23 | #define FWBUFSIZE (8 * 1024 * 1024) 24 | 25 | uint8 ob; 26 | uint16 ow; 27 | uint32 data; 28 | char filename[256]; 29 | char filebuffer[FWBUFSIZE]; // 8MB buffer 30 | int filesize; 31 | int j; 32 | uint16 argslave; 33 | 34 | int input_bin(char *fname, int *length) 35 | { 36 | FILE *fp; 37 | 38 | int cc = 0, c; 39 | 40 | fp = fopen(fname, "rb"); 41 | if(fp == NULL) 42 | return 0; 43 | while (((c = fgetc(fp)) != EOF) && (cc < FWBUFSIZE)) 44 | filebuffer[cc++] = (uint8)c; 45 | *length = cc; 46 | fclose(fp); 47 | return 1; 48 | } 49 | 50 | 51 | void boottest(char *ifname, uint16 slave, char *filename) 52 | { 53 | printf("Starting firmware update example\n"); 54 | 55 | /* initialise SOEM, bind socket to ifname */ 56 | if (ec_init(ifname)) 57 | { 58 | printf("ec_init on %s succeeded.\n",ifname); 59 | /* find and auto-config slaves */ 60 | 61 | 62 | if ( ec_config_init(FALSE) > 0 ) 63 | { 64 | printf("%d slaves found and configured.\n",ec_slavecount); 65 | 66 | printf("Request init state for slave %d\n", slave); 67 | ec_slave[slave].state = EC_STATE_INIT; 68 | ec_writestate(slave); 69 | 70 | /* wait for slave to reach INIT state */ 71 | ec_statecheck(slave, EC_STATE_INIT, EC_TIMEOUTSTATE * 4); 72 | printf("Slave %d state to INIT.\n", slave); 73 | 74 | /* read BOOT mailbox data, master -> slave */ 75 | data = ec_readeeprom(slave, ECT_SII_BOOTRXMBX, EC_TIMEOUTEEP); 76 | ec_slave[slave].SM[0].StartAddr = (uint16)LO_WORD(data); 77 | ec_slave[slave].SM[0].SMlength = (uint16)HI_WORD(data); 78 | /* store boot write mailbox address */ 79 | ec_slave[slave].mbx_wo = (uint16)LO_WORD(data); 80 | /* store boot write mailbox size */ 81 | ec_slave[slave].mbx_l = (uint16)HI_WORD(data); 82 | 83 | /* read BOOT mailbox data, slave -> master */ 84 | data = ec_readeeprom(slave, ECT_SII_BOOTTXMBX, EC_TIMEOUTEEP); 85 | ec_slave[slave].SM[1].StartAddr = (uint16)LO_WORD(data); 86 | ec_slave[slave].SM[1].SMlength = (uint16)HI_WORD(data); 87 | /* store boot read mailbox address */ 88 | ec_slave[slave].mbx_ro = (uint16)LO_WORD(data); 89 | /* store boot read mailbox size */ 90 | ec_slave[slave].mbx_rl = (uint16)HI_WORD(data); 91 | 92 | printf(" SM0 A:%4.4x L:%4d F:%8.8x\n", ec_slave[slave].SM[0].StartAddr, ec_slave[slave].SM[0].SMlength, 93 | (int)ec_slave[slave].SM[0].SMflags); 94 | printf(" SM1 A:%4.4x L:%4d F:%8.8x\n", ec_slave[slave].SM[1].StartAddr, ec_slave[slave].SM[1].SMlength, 95 | (int)ec_slave[slave].SM[1].SMflags); 96 | /* program SM0 mailbox in for slave */ 97 | ec_FPWR (ec_slave[slave].configadr, ECT_REG_SM0, sizeof(ec_smt), &ec_slave[slave].SM[0], EC_TIMEOUTRET); 98 | /* program SM1 mailbox out for slave */ 99 | ec_FPWR (ec_slave[slave].configadr, ECT_REG_SM1, sizeof(ec_smt), &ec_slave[slave].SM[1], EC_TIMEOUTRET); 100 | 101 | printf("Request BOOT state for slave %d\n", slave); 102 | ec_slave[slave].state = EC_STATE_BOOT; 103 | ec_writestate(slave); 104 | 105 | /* wait for slave to reach BOOT state */ 106 | if (ec_statecheck(slave, EC_STATE_BOOT, EC_TIMEOUTSTATE * 10) == EC_STATE_BOOT) 107 | { 108 | printf("Slave %d state to BOOT.\n", slave); 109 | 110 | if (input_bin(filename, &filesize)) 111 | { 112 | printf("File read OK, %d bytes.\n",filesize); 113 | printf("FoE write...."); 114 | j = ec_FOEwrite(slave, filename, 0, filesize , &filebuffer, EC_TIMEOUTSTATE); 115 | printf("result %d.\n",j); 116 | printf("Request init state for slave %d\n", slave); 117 | ec_slave[slave].state = EC_STATE_INIT; 118 | ec_writestate(slave); 119 | } 120 | else 121 | printf("File not read OK.\n"); 122 | } 123 | 124 | } 125 | else 126 | { 127 | printf("No slaves found!\n"); 128 | } 129 | printf("End firmware update example, close socket\n"); 130 | /* stop SOEM, close socket */ 131 | ec_close(); 132 | } 133 | else 134 | { 135 | printf("No socket connection on %s\nExcecute as root\n",ifname); 136 | } 137 | } 138 | 139 | int main(int argc, char *argv[]) 140 | { 141 | printf("SOEM (Simple Open EtherCAT Master)\nFirmware update example\n"); 142 | 143 | if (argc > 3) 144 | { 145 | argslave = atoi(argv[2]); 146 | boottest(argv[1], argslave, argv[3]); 147 | } 148 | else 149 | { 150 | printf("Usage: firm_update ifname1 slave fname\n"); 151 | printf("ifname = eth0 for example\n"); 152 | printf("slave = slave number in EtherCAT order 1..n\n"); 153 | printf("fname = binary file to store in slave\n"); 154 | printf("CAUTION! Using the wrong file can result in a bricked slave!\n"); 155 | } 156 | 157 | printf("End program\n"); 158 | return (0); 159 | } 160 | -------------------------------------------------------------------------------- /test/win32/red_test/red_test.c: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \brief Example code for Simple Open EtherCAT master 3 | * 4 | * Usage : red_test [ifname1] [ifname2] [cycletime] 5 | * ifname is NIC interface, f.e. eth0 6 | * cycletime in us, f.e. 500 7 | * 8 | * This is a redundancy test. 9 | * 10 | * (c)Arthur Ketels 2008 11 | */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #include "ethercat.h" 25 | 26 | #define NSEC_PER_SEC 1000000000 27 | 28 | struct sched_param schedp; 29 | char IOmap[4096]; 30 | pthread_t thread1; 31 | struct timeval tv, t1, t2; 32 | int dorun = 0; 33 | int deltat, tmax = 0; 34 | int64 toff; 35 | int DCdiff; 36 | int os; 37 | uint8 ob; 38 | uint16 ob2; 39 | pthread_cond_t cond = PTHREAD_COND_INITIALIZER; 40 | pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; 41 | uint8 *digout = 0; 42 | int wcounter; 43 | 44 | void redtest(char *ifname, char *ifname2) 45 | { 46 | int cnt, i, j, oloop, iloop; 47 | 48 | printf("Starting Redundant test\n"); 49 | 50 | /* initialise SOEM, bind socket to ifname */ 51 | if (ec_init_redundant(ifname, ifname2)) 52 | { 53 | printf("ec_init on %s succeeded.\n",ifname); 54 | /* find and auto-config slaves */ 55 | if ( ec_config(FALSE, &IOmap) > 0 ) 56 | { 57 | printf("%d slaves found and configured.\n",ec_slavecount); 58 | /* wait for all slaves to reach SAFE_OP state */ 59 | ec_statecheck(0, EC_STATE_SAFE_OP, EC_TIMEOUTSTATE); 60 | 61 | /* configure DC options for every DC capable slave found in the list */ 62 | ec_configdc(); 63 | 64 | /* read indevidual slave state and store in ec_slave[] */ 65 | ec_readstate(); 66 | for(cnt = 1; cnt <= ec_slavecount ; cnt++) 67 | { 68 | printf("Slave:%d Name:%s Output size:%3dbits Input size:%3dbits State:%2d delay:%d.%d\n", 69 | cnt, ec_slave[cnt].name, ec_slave[cnt].Obits, ec_slave[cnt].Ibits, 70 | ec_slave[cnt].state, (int)ec_slave[cnt].pdelay, ec_slave[cnt].hasdc); 71 | printf(" Out:%8.8x,%4d In:%8.8x,%4d\n", 72 | (int)ec_slave[cnt].outputs, ec_slave[cnt].Obytes, (int)ec_slave[cnt].inputs, ec_slave[cnt].Ibytes); 73 | /* check for EL2004 or EL2008 */ 74 | if( !digout && ((ec_slave[cnt].eep_id == 0x07d43052) || (ec_slave[cnt].eep_id == 0x07d83052))) 75 | { 76 | digout = ec_slave[cnt].outputs; 77 | } 78 | } 79 | printf("Request operational state for all slaves\n"); 80 | ec_slave[0].state = EC_STATE_OPERATIONAL; 81 | /* request OP state for all slaves */ 82 | ec_writestate(0); 83 | /* wait for all slaves to reach OP state */ 84 | ec_statecheck(0, EC_STATE_OPERATIONAL, 5 * EC_TIMEOUTSTATE); 85 | oloop = ec_slave[0].Obytes; 86 | if ((oloop == 0) && (ec_slave[0].Obits > 0)) oloop = 1; 87 | if (oloop > 8) oloop = 8; 88 | iloop = ec_slave[0].Ibytes; 89 | if ((iloop == 0) && (ec_slave[0].Ibits > 0)) iloop = 1; 90 | if (iloop > 8) iloop = 8; 91 | if (ec_slave[0].state == EC_STATE_OPERATIONAL ) 92 | { 93 | printf("Operational state reached for all slaves.\n"); 94 | dorun = 1; 95 | /* acyclic loop 5000 x 20ms = 10s */ 96 | for(i = 1; i <= 5000; i++) 97 | { 98 | printf("Processdata cycle %5d , Wck %3d, DCtime %12lld, O:", dorun, wcounter , ec_DCtime); 99 | for(j = 0 ; j < oloop; j++) 100 | { 101 | printf(" %2.2x", *(ec_slave[0].outputs + j)); 102 | } 103 | printf(" I:"); 104 | for(j = 0 ; j < iloop; j++) 105 | { 106 | printf(" %2.2x", *(ec_slave[0].inputs + j)); 107 | } 108 | printf("\n"); 109 | usleep(20000); 110 | } 111 | dorun = 0; 112 | } 113 | else 114 | { 115 | printf("Not all slaves reached operational state.\n"); 116 | } 117 | printf("Request safe operational state for all slaves\n"); 118 | ec_slave[0].state = EC_STATE_SAFE_OP; 119 | /* request SAFE_OP state for all slaves */ 120 | ec_writestate(0); 121 | } 122 | else 123 | { 124 | printf("No slaves found!\n"); 125 | } 126 | printf("End redundant test, close socket\n"); 127 | /* stop SOEM, close socket */ 128 | ec_close(); 129 | } 130 | else 131 | { 132 | printf("No socket connection on %s\nExcecute as root\n",ifname); 133 | } 134 | } 135 | 136 | /* add ns to timespec */ 137 | void add_timespec(struct timespec *ts, int64 addtime) 138 | { 139 | int64 sec, nsec; 140 | 141 | nsec = addtime % NSEC_PER_SEC; 142 | sec = (addtime - nsec) / NSEC_PER_SEC; 143 | ts->tv_sec += sec; 144 | ts->tv_nsec += nsec; 145 | if ( ts->tv_nsec > NSEC_PER_SEC ) 146 | { 147 | nsec = ts->tv_nsec % NSEC_PER_SEC; 148 | ts->tv_sec += (ts->tv_nsec - nsec) / NSEC_PER_SEC; 149 | ts->tv_nsec = nsec; 150 | } 151 | } 152 | 153 | /* PI calculation to get linux time synced to DC time */ 154 | void ec_sync(int64 reftime, int64 cycletime , int64 *offsettime) 155 | { 156 | static int64 integral = 0; 157 | int64 delta; 158 | /* set linux sync point 50us later than DC sync, just as example */ 159 | delta = (reftime - 50000) % cycletime; 160 | if(delta> (cycletime / 2)) { delta= delta - cycletime; } 161 | if(delta>0){ integral++; } 162 | if(delta<0){ integral--; } 163 | *offsettime = -(delta / 100) - (integral / 20); 164 | } 165 | 166 | /* RT EtherCAT thread */ 167 | void ecatthread( void *ptr ) 168 | { 169 | struct timespec ts; 170 | struct timeval tp; 171 | int rc; 172 | int ht; 173 | int64 cycletime; 174 | 175 | rc = pthread_mutex_lock(&mutex); 176 | rc = gettimeofday(&tp, NULL); 177 | 178 | /* Convert from timeval to timespec */ 179 | ts.tv_sec = tp.tv_sec; 180 | ht = (tp.tv_usec / 1000) + 1; /* round to nearest ms */ 181 | ts.tv_nsec = ht * 1000000; 182 | cycletime = *(int*)ptr * 1000; /* cycletime in ns */ 183 | toff = 0; 184 | dorun = 0; 185 | while(1) 186 | { 187 | /* calculate next cycle start */ 188 | add_timespec(&ts, cycletime + toff); 189 | /* wait to cycle start */ 190 | rc = pthread_cond_timedwait(&cond, &mutex, &ts); 191 | if (dorun>0) 192 | { 193 | rc = gettimeofday(&tp, NULL); 194 | 195 | ec_send_processdata(); 196 | 197 | wcounter = ec_receive_processdata(EC_TIMEOUTRET); 198 | 199 | dorun++; 200 | /* if we have some digital output, cycle */ 201 | if( digout ) *digout = (uint8) ((dorun / 16) & 0xff); 202 | 203 | if (ec_slave[0].hasdc) 204 | { 205 | /* calulate toff to get linux time and DC synced */ 206 | ec_sync(ec_DCtime, cycletime, &toff); 207 | } 208 | } 209 | } 210 | } 211 | 212 | int main(int argc, char *argv[]) 213 | { 214 | int iret1; 215 | int ctime; 216 | struct sched_param param; 217 | int policy = SCHED_OTHER; 218 | 219 | printf("SOEM (Simple Open EtherCAT Master)\nRedundancy test\n"); 220 | 221 | memset(&schedp, 0, sizeof(schedp)); 222 | /* do not set priority above 49, otherwise sockets are starved */ 223 | schedp.sched_priority = 30; 224 | sched_setscheduler(0, SCHED_FIFO, &schedp); 225 | 226 | do 227 | { 228 | usleep(1000); 229 | } 230 | while (dorun); 231 | 232 | if (argc > 3) 233 | { 234 | dorun = 1; 235 | ctime = atoi(argv[3]); 236 | /* create RT thread */ 237 | iret1 = pthread_create( &thread1, NULL, (void *) &ecatthread, (void*) &ctime); 238 | memset(¶m, 0, sizeof(param)); 239 | /* give it higher priority */ 240 | param.sched_priority = 40; 241 | iret1 = pthread_setschedparam(thread1, policy, ¶m); 242 | 243 | /* start acyclic part */ 244 | redtest(argv[1],argv[2]); 245 | } 246 | else 247 | { 248 | printf("Usage: red_test ifname1 ifname2 cycletime\nifname = eth0 for example\ncycletime in us\n"); 249 | } 250 | 251 | schedp.sched_priority = 0; 252 | sched_setscheduler(0, SCHED_OTHER, &schedp); 253 | 254 | printf("End program\n"); 255 | 256 | return (0); 257 | } 258 | --------------------------------------------------------------------------------