pull/343/merge
Hans-Erik Floryd 2019-11-14 15:35:08 +01:00 committed by GitHub
commit 754863236f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
44 changed files with 731 additions and 1747 deletions

View File

@ -1,103 +1,101 @@
cmake_minimum_required(VERSION 2.8.12)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules")
# Licensed under the GNU General Public License version 2 with exceptions. See
# LICENSE file in the project root for full license information
cmake_minimum_required(VERSION 3.12)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
project(SOEM C)
# Default to installing in SOEM source directory
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
# Default to installing in SOEM source directory
set(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR}/install)
set(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR}/install
CACHE PATH "Default install path" FORCE)
endif()
set(SOEM_INCLUDE_INSTALL_DIR include/soem)
set(SOEM_LIB_INSTALL_DIR lib)
set(BUILD_TESTS TRUE)
# Let platforms disable building of executables
set(BUILD_EXECUTABLES TRUE)
if(WIN32)
set(OS "win32")
include_directories(oshw/win32/wpcap/Include)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
link_directories(${CMAKE_SOURCE_DIR}/oshw/win32/wpcap/Lib/x64)
elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
link_directories(${CMAKE_SOURCE_DIR}/oshw/win32/wpcap/Lib)
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /D _CRT_SECURE_NO_WARNINGS")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX")
set(OS_LIBS wpcap.lib Packet.lib Ws2_32.lib Winmm.lib)
elseif(UNIX AND NOT APPLE)
set(OS "linux")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Werror")
set(OS_LIBS pthread rt)
elseif(APPLE)
# This must come *before* linux or MacOSX will identify as Unix.
set(OS "macosx")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Werror")
set(OS_LIBS pthread pcap)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "rt-kernel")
set(OS "rtk")
message("ARCH is ${ARCH}")
message("BSP is ${BSP}")
include_directories(oshw/${OS}/${ARCH})
file(GLOB OSHW_EXTRA_SOURCES oshw/${OS}/${ARCH}/*.c)
set(OSHW_SOURCES "${OS_HW_SOURCES} ${OSHW_ARCHSOURCES}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Werror")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-but-set-variable")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-function")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-format")
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")
elseif(${CMAKE_SYSTEM_NAME} MATCHES "rtems")
message("Building for RTEMS")
set(OS "rtems")
set(SOEM_LIB_INSTALL_DIR ${LIB_DIR})
set(BUILD_TESTS FALSE)
endif()
# Always use standard .o suffix
set(CMAKE_C_OUTPUT_EXTENSION_REPLACE 1)
set(CMAKE_CXX_OUTPUT_EXTENSION_REPLACE 1)
message("OS is ${OS}")
file(GLOB SOEM_SOURCES soem/*.c)
file(GLOB OSAL_SOURCES osal/${OS}/*.c)
file(GLOB OSHW_SOURCES oshw/${OS}/*.c)
file(GLOB SOEM_HEADERS soem/*.h)
file(GLOB OSAL_HEADERS osal/osal.h osal/${OS}/*.h)
file(GLOB OSHW_HEADERS oshw/${OS}/*.h)
add_library(soem STATIC
${SOEM_SOURCES}
${OSAL_SOURCES}
${OSHW_SOURCES}
${OSHW_EXTRA_SOURCES})
target_link_libraries(soem ${OS_LIBS})
add_library(soem
soem/ethercatbase.c
soem/ethercatbase.h
soem/ethercatcoe.c
soem/ethercatcoe.h
soem/ethercatconfig.c
soem/ethercatconfig.h
soem/ethercatconfiglist.h
soem/ethercatdc.c
soem/ethercatdc.h
soem/ethercateoe.c
soem/ethercateoe.h
soem/ethercatfoe.c
soem/ethercatfoe.h
soem/ethercat.h
soem/ethercatmain.c
soem/ethercatmain.h
soem/ethercatprint.c
soem/ethercatprint.h
soem/ethercatsoe.c
soem/ethercatsoe.h
soem/ethercattype.h
util/slaveinfo/slaveinfo.c
util/slaveinfo/slaveinfo.h
util/simple_test/simple_test.c
util/simple_test/simple_test.h
util/eepromtool/eepromtool.c
util/eepromtool/eepromtool.h
)
target_include_directories(soem PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/soem>
$<INSTALL_INTERFACE:include/soem>)
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/soem>
$<INSTALL_INTERFACE:include/soem>
)
target_include_directories(soem PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/osal>
$<INSTALL_INTERFACE:include/soem>)
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/util>
$<INSTALL_INTERFACE:include/soem>
)
target_include_directories(soem PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/osal/${OS}>
$<INSTALL_INTERFACE:include/soem>)
target_include_directories(soem
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/oshw/${OS}>
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/osal>
$<INSTALL_INTERFACE:include/soem>
)
message("LIB_DIR: ${SOEM_LIB_INSTALL_DIR}")
include(${CMAKE_SYSTEM_NAME})
install(TARGETS soem EXPORT soemConfig DESTINATION ${SOEM_LIB_INSTALL_DIR})
install(
TARGETS soem
EXPORT soemConfig
DESTINATION lib
)
install(EXPORT soemConfig DESTINATION ${SOEM_LIB_INSTALL_DIR}/cmake)
install(
EXPORT soemConfig
DESTINATION cmake
)
install(FILES
${SOEM_HEADERS}
${OSAL_HEADERS}
${OSHW_HEADERS}
DESTINATION ${SOEM_INCLUDE_INSTALL_DIR})
soem/ethercatbase.h
soem/ethercatcoe.h
soem/ethercatconfig.h
soem/ethercatconfiglist.h
soem/ethercatdc.h
soem/ethercateoe.h
soem/ethercatfoe.h
soem/ethercat.h
soem/ethercatmain.h
soem/ethercatprint.h
soem/ethercatsoe.h
soem/ethercattype.h
util/slaveinfo/slaveinfo.h
util/simple_test/simple_test.h
util/eepromtool/eepromtool.h
osal/osal.h
DESTINATION include/soem
)
if(BUILD_TESTS)
add_subdirectory(test/linux/slaveinfo)
add_subdirectory(test/linux/eepromtool)
add_subdirectory(test/linux/simple_test)
if(BUILD_EXECUTABLES)
add_subdirectory(util/slaveinfo)
add_subdirectory(util/eepromtool)
add_subdirectory(util/simple_test)
endif()

View File

@ -29,6 +29,17 @@ Linux & macOS
* `cmake ..`
* `make`
rt-kernel
---------
* `mkdir build`
* `cd build`
* `export COMPILERS=/opt/rt-tools/compilers`
* `export RTK=/path/to/rt-kernel`
* `export BSP=<bsp>`
* `cmake .. -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchain/rt-kernel-<arch>.cmake -G "Unix Makefiles"`
* `make`
ERIKA Enterprise RTOS
---------------------

32
cmake/Darwin.cmake 100644
View File

@ -0,0 +1,32 @@
# Licensed under the GNU General Public License version 2 with exceptions. See
# LICENSE file in the project root for full license information
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
target_sources(soem PRIVATE
osal/macosx/osal.c
osal/macosx/osal_defs.h
oshw/macosx/oshw.c
oshw/macosx/oshw.h
oshw/macosx/nicdrv.c
oshw/macosx/nicdrv.h
)
target_include_directories(soem PUBLIC
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/osal/macosx>
$<INSTALL_INTERFACE:include/soem>
)
target_include_directories(soem PUBLIC
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/oshw/macosx>
$<INSTALL_INTERFACE:include/soem>
)
add_definitions(-Wall -Wextra -Werror)
target_link_libraries(soem PUBLIC pthread pcap)
install(FILES
osal/macosx/osal_defs.h
DESTINATION include/soem
)

32
cmake/Linux.cmake 100644
View File

@ -0,0 +1,32 @@
# Licensed under the GNU General Public License version 2 with exceptions. See
# LICENSE file in the project root for full license information
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
target_sources(soem PRIVATE
osal/linux/osal.c
osal/linux/osal_defs.h
oshw/linux/oshw.c
oshw/linux/oshw.h
oshw/linux/nicdrv.c
oshw/linux/nicdrv.h
)
target_include_directories(soem PUBLIC
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/osal/linux>
$<INSTALL_INTERFACE:include/soem>
)
target_include_directories(soem PUBLIC
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/oshw/linux>
$<INSTALL_INTERFACE:include/soem>
)
add_definitions(-Wall -Wextra -Werror)
target_link_libraries(soem PUBLIC pthread rt)
install(FILES
osal/linux/osal_defs.h
DESTINATION include/soem
)

View File

@ -1,13 +0,0 @@
message("rt-kernel-C.cmake")
# Determine toolchain
include(CMakeForceCompiler)
if(${ARCH} MATCHES "kinetis")
cmake_force_c_compiler(arm-eabi-gcc GNU)
cmake_force_cxx_compiler(arm-eabi-g++ GNU)
elseif(${ARCH} MATCHES "bfin")
cmake_force_c_compiler(bfin-elf-gcc GNU)
cmake_force_cxx_compiler(bfin-elf-g++ GNU)
endif()

View File

@ -1,3 +0,0 @@
set(MACHINE "-mcpu=bf537")
set(LDFLAGS "-T${RT_KERNEL_PATH}/bsp/${BSP}/${BSP}.ld")

View File

@ -1,7 +0,0 @@
message("rt-kernel-gcc-kinetis.cmake")
#SET_PROPERTY(GLOBAL PROPERTY ARCH kinetis)
#SET_PROPERTY(GLOBAL PROPERTY BSP twrk60)
set(MACHINE "-mfpu=vfp -mcpu=cortex-m3 -mthumb")

View File

@ -1,19 +0,0 @@
message("rt-kernel-gcc.cmake")
set(CMAKE_C_OUTPUT_EXTENSION .o)
set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS FALSE)
set(CFLAGS "${CFLAGS} -Wall -Wextra -Wno-unused-parameter -Werror")
set(CFLAGS "${CFLAGS} -fomit-frame-pointer -fno-strict-aliasing -fshort-wchar")
#set(CFLAGS" ${CFLAGS} -B$(GCC_PATH)/libexec/gcc")
set(CXXFLAGS "${CXXFLAGS} -fno-rtti -fno-exceptions")
set(LDFLAGS "${LDFLAGS} -nostartfiles")
set(CMAKE_C_FLAGS "${CFLAGS} ${MACHINE}" CACHE STRING "")
set(CMAKE_EXE_LINKER_FLAGS "${MACHINE} ${LDFLAGS}" CACHE STRING "")

View File

@ -1,20 +0,0 @@
if(__RTK_CMAKE_INCLUDED)
return()
endif()
set(__RTK_CMAKE_INCLUDED TRUE)
message("rt-kernel.cmake")
include_directories(
${RT_KERNEL_PATH}/include
${RT_KERNEL_PATH}/include/kern
${RT_KERNEL_PATH}/kern
${RT_KERNEL_PATH}/include/drivers
${RT_KERNEL_PATH}/include/arch/${ARCH}
${RT_KERNEL_PATH}/bsp/${BSP}/include
${RT_KERNEL_PATH}/lwip/src/include
${RT_KERNEL_PATH}/lwip/src/include/ipv4
)
link_directories(
${RT_KERNEL_PATH}/lib/${ARCH}
)

View File

@ -0,0 +1,70 @@
# Licensed under the GNU General Public License version 2 with exceptions. See
# LICENSE file in the project root for full license information
# Guard against multiple inclusion
if(_RT_KERNEL_CMAKE_)
return()
endif()
set(_RT_KERNEL_CMAKE_ TRUE)
cmake_minimum_required (VERSION 3.1.2)
# Avoid warning when re-running cmake
set(DUMMY ${CMAKE_TOOLCHAIN_FILE})
# No support for shared libs
set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS FALSE)
set(CMAKE_STATIC_LIBRARY_PREFIX "lib")
set(CMAKE_STATIC_LIBRARY_SUFFIX ".a")
set(CMAKE_EXECUTABLE_SUFFIX ".elf")
# Get environment variables
set(RTK $ENV{RTK} CACHE STRING
"Location of rt-kernel tree")
set(COMPILERS $ENV{COMPILERS} CACHE STRING
"Location of compiler toolchain")
set(BSP $ENV{BSP} CACHE STRING
"The name of the BSP to build for")
# Common flags
add_definitions(-fomit-frame-pointer -fno-strict-aliasing -fshort-wchar)
# Common includes
include_directories(
$ENV{RTK}/include
$ENV{RTK}/include/kern
$ENV{RTK}/include/drivers
$ENV{RTK}/include/arch/${ARCH}
$ENV{RTK}/bsp/${BSP}/include
$ENV{RTK}/lwip/src/include
)
link_libraries(
shell
dev
block
fs
usb
lwip
eth
i2c
rtc
can
nand
spi
nor
pwm
adc
trace
sio
kern
${ARCH}
${BSP}
c
m
)
set(CMAKE_CXX_LINK_EXECUTABLE "<CMAKE_CXX_COMPILER> <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> -nostartfiles -L${RTK}/lib/${ARCH}/${VARIANT}/${CPU} -T${RTK}/bsp/${BSP}/${BSP}.ld -Wl,--gc-sections -Wl,--start-group <LINK_LIBRARIES> -Wl,--end-group")
set(CMAKE_C_LINK_EXECUTABLE "<CMAKE_C_COMPILER> <FLAGS> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> -nostartfiles -L${RTK}/lib/${ARCH}/${VARIANT}/${CPU} -T${RTK}/bsp/${BSP}/${BSP}.ld -Wl,--gc-sections -Wl,--start-group <LINK_LIBRARIES> -Wl,--end-group")

View File

@ -8,15 +8,5 @@ set(CMAKE_CXX_COMPILER_FORCED true)
set(CMAKE_C_COMPILER ${RTEMS_TOOLS_PATH}/bin/${ARCH}-gcc)
set(CMAKE_CXX_COMPILER ${RTEMS_TOOLS_PATH}/bin/${ARCH}-g++)
set(SOEM_INCLUDE_INSTALL_DIR ${INCLUDE_DIR}/soem)
set(SOEM_LIB_INSTALL_DIR ${LIB_DIR})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${HOST_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${HOST_CXX_FLAGS}")
if(NOT ${HOST_LIBS} STREQUAL "")
set(OS_LIBS "rtemscpu bsd ${HOST_LIBS}")
else()
set(OS_LIBS "-lrtemscpu -lbsd")
endif()

View File

@ -1,9 +0,0 @@
message("rt-kernel-kinetis.cmake")
set(CMAKE_SYSTEM_NAME rt-kernel)
set(CMAKE_SYSTEM_VERSION 1)
set(CMAKE_SYSTEM_PROCESSOR bfin)
set(ARCH bfin CACHE STRING "Architecture")
set(BSP stamp537 CACHE STRING "Board")

View File

@ -1,9 +0,0 @@
message("rt-kernel-kinetis.cmake")
set(CMAKE_SYSTEM_NAME rt-kernel)
set(CMAKE_SYSTEM_VERSION 1)
set(CMAKE_SYSTEM_PROCESSOR kinetis)
set(ARCH kinetis CACHE STRING "Architecture")
set(BSP twrk60 CACHE STRING "Board")

View File

@ -0,0 +1,46 @@
# Licensed under the GNU General Public License version 2 with exceptions. See
# LICENSE file in the project root for full license information
target_sources(soem PRIVATE
osal/win32/osal.c
osal/win32/osal_defs.h
oshw/win32/oshw.c
oshw/win32/oshw.h
oshw/win32/nicdrv.c
oshw/win32/nicdrv.h
)
target_include_directories(soem PUBLIC
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/osal/win32>
$<INSTALL_INTERFACE:include/soem>
)
target_include_directories(soem PUBLIC
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/oshw/win32>
$<INSTALL_INTERFACE:include/soem>
)
target_include_directories(soem PUBLIC
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/oshw/win32/wpcap/Include>
$<INSTALL_INTERFACE:include/soem>
)
add_definitions(/D _CRT_SECURE_NO_WARNINGS /WX)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(WPCAP_LIB_PATH ${CMAKE_SOURCE_DIR}/oshw/win32/wpcap/Lib/x64)
elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(WPCAP_LIB_PATH ${CMAKE_SOURCE_DIR}/oshw/win32/wpcap/Lib)
endif()
target_link_libraries(soem PUBLIC
${WPCAP_LIB_PATH}/wpcap.lib
${WPCAP_LIB_PATH}/Packet.lib
Ws2_32.lib
Winmm.lib
)
install(FILES
osal/win32/osal_defs.h
DESTINATION include/soem
)

View File

@ -0,0 +1,41 @@
# Licensed under the GNU General Public License version 2 with exceptions. See
# LICENSE file in the project root for full license information
target_sources(soem PRIVATE
osal/rtk/osal.c
osal/rtk/osal_defs.h
osal/rtk/soem_cmds.c
oshw/rtk/oshw.c
oshw/rtk/oshw.h
oshw/rtk/nicdrv.c
oshw/rtk/nicdrv.h
oshw/rtk/lw_mac/lw_emac.c
oshw/rtk/fec/fec_ecat.c
oshw/rtk/fec/fec_ecat.h
)
target_include_directories(soem PUBLIC
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/osal/rtk>
$<INSTALL_INTERFACE:include/soem>
)
target_include_directories(soem PUBLIC
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/oshw/rtk>
$<INSTALL_INTERFACE:include/soem>
)
add_definitions(
-D${BSP}
-g
-Wall
-Wextra
-Werror
-Wno-unused-parameter
-Wno-format
)
install(FILES
osal/rtk/osal_defs.h
osal/rtk/soem_cmds.h
DESTINATION include/soem
)

33
cmake/rtems.cmake 100644
View File

@ -0,0 +1,33 @@
# Licensed under the GNU General Public License version 2 with exceptions. See
# LICENSE file in the project root for full license information
set(BUILD_EXECUTABLES FALSE)
target_sources(soem PRIVATE
osal/rtems/osal.c
osal/rtems/osal_defs.h
oshw/rtems/oshw.c
oshw/rtems/oshw.h
oshw/rtems/nicdrv.c
oshw/rtems/nicdrv.h
)
target_include_directories(soem PUBLIC
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/osal/rtems>
$<INSTALL_INTERFACE:include/soem>
)
target_include_directories(soem PUBLIC
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/oshw/rtems>
$<INSTALL_INTERFACE:include/soem>
)
add_definitions(-Wall -Wextra -Werror)
target_link_libraries(soem PUBLIC rtemscpu bsd ${HOST_LIBS})
install(FILES
osal/rtems/osal_defs.h
DESTINATION include/soem
)

View File

@ -0,0 +1,23 @@
# Licensed under the GNU General Public License version 2 with exceptions. See
# LICENSE file in the project root for full license information
# the name of the target operating system
set(CMAKE_SYSTEM_NAME rt-kernel)
# which compiler to use
set(CMAKE_C_COMPILER $ENV{COMPILERS}/bfin-elf/bin/bfin-elf-gcc)
set(CMAKE_CXX_COMPILER $ENV{COMPILERS}/bfin-elf/bin/bfin-elf-gcc)
if(CMAKE_HOST_WIN32)
set(CMAKE_C_COMPILER ${CMAKE_C_COMPILER}.exe)
set(CMAKE_CXX_COMPILER ${CMAKE_CXX_COMPILER}.exe)
endif(CMAKE_HOST_WIN32)
set(ARCH bfin)
set(CPU bfin)
list(APPEND MACHINE
-mcpu=bf537
)
add_definitions(${MACHINE})
add_link_options(${MACHINE})

View File

@ -0,0 +1,31 @@
# Licensed under the GNU General Public License version 2 with exceptions. See
# LICENSE file in the project root for full license information
# Guard against multiple inclusion
if(_RT_KERNEL_IMX6_CMAKE_)
return()
endif()
set(_RT_KERNEL_IMX6_CMAKE_ TRUE)
# the name of the target operating system
set(CMAKE_SYSTEM_NAME rt-kernel)
# which compiler to use
set(CMAKE_C_COMPILER $ENV{COMPILERS}/arm-eabi/bin/arm-eabi-gcc)
set(CMAKE_CXX_COMPILER $ENV{COMPILERS}/arm-eabi/bin/arm-eabi-gcc)
if(CMAKE_HOST_WIN32)
set(CMAKE_C_COMPILER ${CMAKE_C_COMPILER}.exe)
set(CMAKE_CXX_COMPILER ${CMAKE_CXX_COMPILER}.exe)
endif(CMAKE_HOST_WIN32)
set(ARCH imx6)
set(CPU cortex-a9-vfp)
list(APPEND MACHINE
-mcpu=cortex-a9
-mfpu=vfpv3-d16
-mfloat-abi=hard
)
add_definitions(${MACHINE})
add_link_options(${MACHINE})

View File

@ -52,6 +52,10 @@ void osal_time_diff(ec_timet *start, ec_timet *end, ec_timet *diff);
int osal_thread_create(void *thandle, int stacksize, void *func, void *param);
int osal_thread_create_rt(void *thandle, int stacksize, void *func, void *param);
#ifndef OSAL_MAIN
#define OSAL_MAIN main
#endif /* OSAL_MAIN */
#ifdef __cplusplus
}
#endif

View File

@ -9,44 +9,9 @@
#include <sys/time.h>
#include <config.h>
#define timercmp(a, b, CMP) \
(((a)->tv_sec == (b)->tv_sec) ? \
((a)->tv_usec CMP (b)->tv_usec) : \
((a)->tv_sec CMP (b)->tv_sec))
#define timeradd(a, b, result) \
do { \
(result)->tv_sec = (a)->tv_sec + (b)->tv_sec; \
(result)->tv_usec = (a)->tv_usec + (b)->tv_usec; \
if ((result)->tv_usec >= 1000000) \
{ \
++(result)->tv_sec; \
(result)->tv_usec -= 1000000; \
} \
} while (0)
#define timersub(a, b, result) \
do { \
(result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
(result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
if ((result)->tv_usec < 0) { \
--(result)->tv_sec; \
(result)->tv_usec += 1000000; \
} \
} while (0)
#define USECS_PER_SEC 1000000
#define USECS_PER_TICK (USECS_PER_SEC / CFG_TICKS_PER_SECOND)
/* Workaround for rt-labs defect 776.
* Default implementation of udelay() didn't work correctly when tick was
* shorter than one millisecond.
*/
void udelay (uint32_t us)
{
tick_t ticks = (us / USECS_PER_TICK) + 1;
task_delay (ticks);
}
int gettimeofday(struct timeval *tp, void *tzp)
{
tick_t tick = tick_get();
@ -65,7 +30,8 @@ int gettimeofday(struct timeval *tp, void *tzp)
int osal_usleep (uint32 usec)
{
udelay(usec);
tick_t ticks = (usec / USECS_PER_TICK) + 1;
task_delay (ticks);
return 0;
}
@ -85,6 +51,18 @@ ec_timet osal_current_time (void)
return return_value;
}
void osal_time_diff(ec_timet *start, ec_timet *end, ec_timet *diff)
{
if (end->usec < start->usec) {
diff->sec = end->sec - start->sec - 1;
diff->usec = end->usec + 1000000 - start->usec;
}
else {
diff->sec = end->sec - start->sec;
diff->usec = end->usec - start->usec;
}
}
void osal_timer_start (osal_timert * self, uint32 timeout_usec)
{
struct timeval start_time;

View File

@ -0,0 +1,71 @@
/*
* Licensed under the GNU General Public License version 2 with exceptions. See
* LICENSE file in the project root for full license information
*/
#include "slaveinfo/slaveinfo.h"
#include "simple_test/simple_test.h"
#include "eepromtool/eepromtool.h"
#include "soem_cmds.h"
static int _cmd_slaveinfo (int argc, char * argv[])
{
return slaveinfo (argc, argv);
}
static int _cmd_simple_test (int argc, char * argv[])
{
return simple_test (argc, argv);
}
static int _cmd_eepromtool (int argc, char * argv[])
{
return eepromtool (argc, argv);
}
const shell_cmd_t cmd_slaveinfo =
{
.cmd = _cmd_slaveinfo,
.name = "slaveinfo",
.help_short = "show EtherCAT slave info",
.help_long =
"Usage: slaveinfo ifname [options]\n"
"\n"
"Find all EtherCAT slaves and show slave configuration.\n"
"ifname will be ignored but must be given.\n"
"Options :\n"
" -sdo : print SDO info\n"
" -map : print mapping\n"
};
const shell_cmd_t cmd_simple_test =
{
.cmd = _cmd_simple_test,
.name = "simple_test",
.help_short = "EtherCAT process data test",
.help_long =
"Usage: simple_test ifname\n"
"\n"
"Send and receive (dummy) processdata on EtherCAT bus.\n"
"ifname will be ignored but must be given.\n"
};
const shell_cmd_t cmd_eepromtool =
{
.cmd = _cmd_eepromtool,
.name = "eepromtool",
.help_short = "program eeprom of EtherCAT slave",
.help_long =
"Usage: eepromtool ifname slave [options] fname|alias\n"
"\n"
"Program the EEPROM of an EtherCAT slave.\n"
"ifname will be ignored but must be given.\n"
"slave = slave number in EtherCAT order 1..n\n"
" -i display EEPROM information\n"
" -walias write slave alias\n"
" -r read EEPROM, output binary format\n"
" -ri read EEPROM, output Intel Hex format\n"
" -w write EEPROM, input binary format\n"
" -wi write EEPROM, input Intel Hex format\n"
};

View File

@ -0,0 +1,24 @@
/*
* Licensed under the GNU General Public License version 2 with exceptions. See
* LICENSE file in the project root for full license information
*/
#ifndef _SOEM_CMDS_H
#define _SOEM_CMDS_H
#ifdef __cplusplus
extern "C"
{
#endif
#include <shell.h>
extern const shell_cmd_t cmd_slaveinfo;
extern const shell_cmd_t cmd_simple_test;
extern const shell_cmd_t cmd_eepromtool;
#ifdef __cplusplus
}
#endif
#endif /* _SOEM_CMDS_H */

View File

@ -1,24 +1,19 @@
/******************************************************************************
* * *** ***
* *** *** ***
* *** **** ********** *** ***** *** **** *****
* ********* ********** *** ********* ************ *********
* **** *** *** *** *** **** ***
* *** *** ****** *** *********** *** **** *****
* *** *** ****** *** ************* *** **** *****
* *** **** **** *** *** *** **** ***
* *** ******* ***** ************** ************* *********
* *** ***** *** ******* ** ** ****** *****
* t h e r e a l t i m e t a r g e t e x p e r t s
*
* http://www.rt-labs.com
* Copyright (C) 2007. rt-labs AB, Sweden. All rights reserved.
*------------------------------------------------------------------------------
* $Id: fec_ecat.c 138 2014-04-11 09:11:48Z rtlfrm $
*------------------------------------------------------------------------------
*/
/*********************************************************************
* _ _ _
* _ __ | |_ _ | | __ _ | |__ ___
* | '__|| __|(_)| | / _` || '_ \ / __|
* | | | |_ _ | || (_| || |_) |\__ \
* |_| \__|(_)|_| \__,_||_.__/ |___/
*
* http://www.rt-labs.com
* Copyright 2011 rt-labs AB, Sweden.
* See LICENSE file in the project root for full license information.
********************************************************************/
#if defined (sabresd) || defined (twrk60f)
#include "fec_ecat.h"
#include "oshw.h"
#include <dev.h>
#include <kern.h>
@ -65,6 +60,20 @@
/* Note that the core clock and the system clock has the same clock frequency */
#define FEC_MODULE_CLOCK_Hz CFG_IPG_CLOCK
#if defined (sabresd)
extern phy_t * ar8031_init (const phy_cfg_t * cfg);
#define PHY_INIT ar8031_init
#define PHY_INTERFACE FEC_PHY_RGMII
#endif
#if defined (twrk60f)
#define PHY_INIT mii_init
#define PHY_INTERFACE FEC_PHY_RMII
#endif
//----------------------------------------------------------------------------//
typedef struct fec_mac_t
@ -223,6 +232,7 @@ COMPILETIME_ASSERT (offsetof (reg_fec_t, smac[3]) == 0x518);
/* Bit definitions and macros for FEC_ECR */
#define FEC_ECR_DBSWP (0x00000100)
#define FEC_ECR_SPEED (0x00000020)
#define FEC_ECR_ETHER_EN (0x00000002)
#define FEC_ECR_RESET (0x00000001)
@ -258,7 +268,7 @@ COMPILETIME_ASSERT (offsetof (reg_fec_t, smac[3]) == 0x518);
#define FEC_RCR_RMII_10T (0x00000200)
#define FEC_RCR_RMII_MODE (0x00000100)
#define FEC_RCR_SGMII_ENA (0x00000080)
#define FEC_RCR_RGMII_ENA (0x00000040)
#define FEC_RCR_RGMII_EN (0x00000040)
#define FEC_RCR_FCE (0x00000020)
#define FEC_RCR_BC_REJ (0x00000010)
#define FEC_RCR_PROM (0x00000008)
@ -514,17 +524,19 @@ static void fec_ecat_init_hw (const fec_mac_address_t * mac_address)
fec->base->mscr = (fec->base->mscr & (~0x7E)) | (mii_speed << 1);
// Receive control register
fec->base->rcr = FEC_RCR_MAX_FL(PKT_MAXBUF_SIZE) | FEC_RCR_MII_MODE;
fec->base->rcr = FEC_RCR_MAX_FL(PKT_MAXBUF_SIZE);
// set RMII mode in RCR register.
if (fec->phy_interface == FEC_PHY_RMII)
switch(fec->phy_interface)
{
fec->base->rcr |= FEC_RCR_RMII_MODE;
}
else if(fec->phy_interface == FEC_PHY_RGMII)
{
fec->base->rcr &= ~(FEC_RCR_RMII_MODE | FEC_RCR_MII_MODE );
fec->base->rcr |= (FEC_RCR_RGMII_ENA | FEC_RCR_MII_MODE);
case FEC_PHY_MII:
fec->base->rcr |= FEC_RCR_MII_MODE;
break;
case FEC_PHY_RMII:
fec->base->rcr |= (FEC_RCR_MII_MODE | FEC_RCR_RMII_MODE);
break;
case FEC_PHY_RGMII:
fec->base->rcr |= (FEC_RCR_MII_MODE | FEC_RCR_RGMII_EN);
break;
}
// Reset phy
@ -556,7 +568,7 @@ static void fec_ecat_init_hw (const fec_mac_address_t * mac_address)
fec->phy->ops->start (fec->phy);
}
int fec_ecat_send (const void *payload, size_t tot_len)
int oshw_mac_send (const void *payload, size_t tot_len)
{
fec_buffer_bd_t * bd;
@ -587,6 +599,7 @@ int fec_ecat_send (const void *payload, size_t tot_len)
fec_buffer_produce_tx (bd);
#if defined (twrk60f)
/* Wait for previous transmissions to complete.
*
* This is a workaround for Freescale Kinetis errata e6358.
@ -596,6 +609,7 @@ int fec_ecat_send (const void *payload, size_t tot_len)
{
;
}
#endif
/* Transmit frame */
fec->base->tdar = 1;
@ -603,7 +617,7 @@ int fec_ecat_send (const void *payload, size_t tot_len)
return tot_len;
}
int fec_ecat_recv (void * buffer, size_t buffer_length)
int oshw_mac_recv (void * buffer, size_t buffer_length)
{
fec_buffer_bd_t * bd;
int return_value;
@ -686,7 +700,7 @@ static void fec_ecat_hotplug (void)
fec->base->rcr |= FEC_RCR_DRT;
}
/* Set RMII 10-Mbps mode. */
/* Set link speed */
if (link_state & PHY_LINK_10MBIT)
{
fec->base->rcr |= FEC_RCR_RMII_10T;
@ -750,8 +764,7 @@ static dev_state_t fec_ecat_probe (void)
COMPILETIME_ASSERT (FEC_MODULE_CLOCK_Hz >= FEC_MIN_MODULE_CLOCK_Hz);
int fec_ecat_init (const fec_mac_address_t * mac_address,
bool phy_loopback_mode)
int oshw_mac_init (const uint8_t * mac_address)
{
dev_state_t state;
static const fec_cfg_t eth_cfg =
@ -760,17 +773,16 @@ int fec_ecat_init (const fec_mac_address_t * mac_address,
.clock = FEC_MODULE_CLOCK_Hz,
.tx_bd_base = fec_tx_bd,
.rx_bd_base = fec_rx_bd,
.phy_interface = FEC_PHY_RMII,
.phy_interface = PHY_INTERFACE,
};
static phy_cfg_t phy_cfg =
{
.address = ETH_PHY_ADDRESS,
.read = NULL, /* Set by MAC driver */
.write = NULL, /* Set by MAC driver */
.loopback_mode = false,
};
phy_cfg.loopback_mode = phy_loopback_mode;
/* Initialise buffers and buffer descriptors.*/
fec_buffer_init_tx (fec_tx_bd, fec_tx_data, NUM_BUFFERS);
fec_buffer_init_rx (fec_rx_bd, fec_rx_data, NUM_BUFFERS);
@ -778,19 +790,25 @@ int fec_ecat_init (const fec_mac_address_t * mac_address,
fec = malloc (sizeof (fec_t));
UASSERT (fec != NULL, EMEM);
#if defined (sabresd)
gpio_set (GPIO_RGMII_nRST, 0);
task_delay (500);
gpio_set (GPIO_RGMII_nRST, 1);
#endif
/* Initialise driver state */
fec->rx_bd_base = eth_cfg.rx_bd_base;
fec->tx_bd_base = eth_cfg.tx_bd_base;
fec->clock = eth_cfg.clock;
fec->base = (reg_fec_t *)eth_cfg.base;
fec->phy_interface = eth_cfg.phy_interface;
fec->phy = mii_init (&phy_cfg);
fec->phy = PHY_INIT (&phy_cfg);
fec->phy->arg = fec;
fec->phy->read = fec_ecat_read_phy;
fec->phy->write = fec_ecat_write_phy;
/* Initialize hardware */
fec_ecat_init_hw (mac_address);
fec_ecat_init_hw ((fec_mac_address_t *)mac_address);
state = StateDetached;
while (state == StateDetached)
{
@ -800,3 +818,5 @@ int fec_ecat_init (const fec_mac_address_t * mac_address,
return 0;
}
#endif

View File

@ -1,25 +1,17 @@
/******************************************************************************
* * *** ***
* *** *** ***
* *** **** ********** *** ***** *** **** *****
* ********* ********** *** ********* ************ *********
* **** *** *** *** *** **** ***
* *** *** ****** *** *********** *** **** *****
* *** *** ****** *** ************* *** **** *****
* *** **** **** *** *** *** **** ***
* *** ******* ***** ************** ************* *********
* *** ***** *** ******* ** ** ****** *****
* t h e r e a l t i m e t a r g e t e x p e r t s
*
* http://www.rt-labs.com
* Copyright (C) 2007. rt-labs AB, Sweden. All rights reserved.
*------------------------------------------------------------------------------
* $Id: fec_ecat.h 91 2014-04-02 13:32:29Z rtlfrm $
*------------------------------------------------------------------------------
*/
/*********************************************************************
* _ _ _
* _ __ | |_ _ | | __ _ | |__ ___
* | '__|| __|(_)| | / _` || '_ \ / __|
* | | | |_ _ | || (_| || |_) |\__ \
* |_| \__|(_)|_| \__,_||_.__/ |___/
*
* http://www.rt-labs.com
* Copyright 2011 rt-labs AB, Sweden.
* See LICENSE file in the project root for full license information.
********************************************************************/
/**
* \defgroup fec EtherCat Ethernet MAC driver for Frescale K60 SoCs.
* \defgroup fec EtherCat Ethernet MAC driver for Frescale SoCs.
*
* \{
*/
@ -39,12 +31,6 @@ typedef struct fec_mac_address
uint8_t octet[6];
} fec_mac_address_t;
int fec_ecat_init (const fec_mac_address_t * mac_address, bool phy_loopback_mode);
int fec_ecat_send (const void *payload, size_t tot_len);
int fec_ecat_recv (void * buffer, size_t buffer_length);
#ifdef __cplusplus
}
#endif

View File

@ -1,24 +1,16 @@
/******************************************************************************
* * *** ***
* *** *** ***
* *** **** ********** *** ***** *** **** *****
* ********* ********** *** ********* ************ *********
* **** *** *** *** *** **** ***
* *** *** ****** *** *********** *** **** *****
* *** *** ****** *** ************* *** **** *****
* *** **** **** *** *** *** **** ***
* *** ******* ***** ************** ************* *********
* *** ***** *** ******* ** ** ****** *****
* t h e r e a l t i m e t a r g e t e x p e r t s
/*********************************************************************
* _ _ _
* _ __ | |_ _ | | __ _ | |__ ___
* | '__|| __|(_)| | / _` || '_ \ / __|
* | | | |_ _ | || (_| || |_) |\__ \
* |_| \__|(_)|_| \__,_||_.__/ |___/
*
* http://www.rt-labs.com
* Copyright (C) 2006. rt-labs AB, Sweden. All rights reserved.
*------------------------------------------------------------------------------
* $Id: lw_emac.c 348 2012-10-18 16:41:14Z rtlfrm $
*
*
*------------------------------------------------------------------------------
*/
* Copyright 2010 rt-labs AB, Sweden.
* See LICENSE file in the project root for full license information.
********************************************************************/
#if defined (stamp537)
#include <bsp.h>
#include <kern.h>
@ -26,7 +18,7 @@
#include <bfin_dma.h>
#include <string.h>
#include "lw_emac.h"
#include "oshw.h"
/* MII standard registers.
See IEEE Std 802.3-2005 clause 22:
@ -187,7 +179,7 @@ static uint32_t lw_emac_read_phy_reg(uint8_t phy_addr, uint8_t reg_addr) {
}
/* Internal function that sets the MAC address */
static void lw_emac_set_mac_addr(uint8_t * ethAddr)
static void lw_emac_set_mac_addr(const uint8_t * ethAddr)
{
pEth->addrlo =
ethAddr[0] |
@ -199,7 +191,7 @@ static void lw_emac_set_mac_addr(uint8_t * ethAddr)
ethAddr[5] << 8;
}
static uint8_t lw_emac_init_registers(uint8_t * ethAddr) {
static uint8_t lw_emac_init_registers(const uint8_t * ethAddr) {
uint32_t clock_divisor, sysctl_mdcdiv, phy_stadat, counter;
/* CONFIGURE MAC MII PINS */
@ -285,7 +277,7 @@ static uint8_t lw_emac_init_registers(uint8_t * ethAddr) {
return 0;
}
int bfin_EMAC_init (uint8_t *ethAddr)
int oshw_mac_init (const uint8_t * ethAddr)
{
rxIdx = txIdx = 0;
@ -351,7 +343,8 @@ int bfin_EMAC_init (uint8_t *ethAddr)
return 0;
}
int bfin_EMAC_send (void *packet, int length)
int oshw_mac_send (const void *packet, size_t length)
{
UASSERT(length > 0, EARG);
UASSERT(length < ETH_FRAME_SIZE, EARG);
@ -381,7 +374,7 @@ int bfin_EMAC_send (void *packet, int length)
return 0;
}
int bfin_EMAC_recv (uint8_t * packet, size_t size)
int oshw_mac_recv (void * packet, size_t size)
{
uint32_t length;
uint32_t status = rxStatusWord[rxIdx];
@ -421,3 +414,4 @@ int bfin_EMAC_recv (uint8_t * packet, size_t size)
return length;
}
#endif

View File

@ -1,12 +0,0 @@
/*
* author: Tomas Vestelind
*/
#ifndef LWIP_MAC_H
#define LWIP_MAC_H
int bfin_EMAC_init(uint8_t *enetaddr);
int bfin_EMAC_send(void *packet, int length);
int bfin_EMAC_recv(uint8_t * packet, size_t size);
#endif /* LWIP_MAC_H */

View File

@ -38,9 +38,6 @@
#include "osal.h"
#include "oshw.h"
#include "lw_mac/lw_emac.h"
#ifndef MAX
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
@ -95,7 +92,7 @@ int ecx_setupnic(ecx_portt *port, const char *ifname, int secondary)
port->tx_mutex = mtx_create();
port->rx_mutex = mtx_create();
rVal = bfin_EMAC_init((uint8_t *)priMAC);
rVal = oshw_mac_init((uint8_t *)priMAC);
if (rVal != 0)
return 0;
@ -263,7 +260,7 @@ int ecx_outframe(ecx_portt *port, int idx, int stacknumber)
}
lp = (*stack->txbuflength)[idx];
(*stack->rxbufstat)[idx] = EC_BUF_TX;
rval = bfin_EMAC_send((*stack->txbuf)[idx], lp);
rval = oshw_mac_send((*stack->txbuf)[idx], lp);
return rval;
}
@ -299,7 +296,7 @@ int ecx_outframe_red(ecx_portt *port, int idx)
// OBS! redundant not ACTIVE for BFIN, just added to compile
ASSERT (0);
port->redport->rxbufstat[idx] = EC_BUF_TX;
bfin_EMAC_send(&(port->txbuf2), port->txbuflength2);
oshw_mac_send(&(port->txbuf2), port->txbuflength2);
mtx_unlock (port->tx_mutex);
}
@ -325,7 +322,7 @@ static int ecx_recvpkt(ecx_portt *port, int stacknumber)
stack = &(port->redport->stack);
}
lp = sizeof(port->tempinbuf);
bytesrx = bfin_EMAC_recv((*stack->tempbuf), lp);
bytesrx = oshw_mac_recv((*stack->tempbuf), lp);
port->tempinbufs = bytesrx;
return (bytesrx > 0);

View File

@ -11,6 +11,8 @@
#ifndef _nicdrvh_
#define _nicdrvh_
#include <kern.h>
/** pointer structure to Tx and Rx stacks */
typedef struct
{

View File

@ -21,6 +21,9 @@ extern "C"
#include "nicdrv.h"
#include "ethercatmain.h"
int oshw_mac_init (const uint8_t * mac_address);
int oshw_mac_send (const void *payload, size_t tot_len);
int oshw_mac_recv (void * buffer, size_t buffer_length);
uint16 oshw_htons(uint16 host);
uint16 oshw_ntohs(uint16 network);

View File

@ -1,388 +0,0 @@
/** \file
* \brief EEprom tool for Simple Open EtherCAT master
*
* Usage : eepromtool ifname slave OPTION fname
* ifname is NIC interface, f.e. eth0
* slave = slave number in EtherCAT order 1..n
* -r read EEPROM, output binary format
* -ri read EEPROM, output Intel Hex format
* -w write EEPROM, input binary format
* -wi write EEPROM, input Intel Hex format
*
* (c)Arthur Ketels 2010
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "ethercat.h"
#define MAXBUF 32768
#define STDBUF 2048
#define MINBUF 128
#define MODE_NONE 0
#define MODE_READBIN 1
#define MODE_READINTEL 2
#define MODE_WRITEBIN 3
#define MODE_WRITEINTEL 4
#define MAXSLENGTH 256
uint8 ebuf[MAXBUF];
uint8 ob;
uint16 ow;
int os;
int slave;
ec_timet tstart,tend, tdif;
int wkc;
int mode;
char sline[MAXSLENGTH];
#define IHEXLENGTH 0x20
int input_bin(char *fname, int *length)
{
FILE *fp;
int cc = 0, c;
fp = fopen(fname, "rb");
if(fp == NULL)
return 0;
while (((c = fgetc(fp)) != EOF) && (cc < MAXBUF))
ebuf[cc++] = (uint8)c;
*length = cc;
fclose(fp);
return 1;
}
int input_intelhex(char *fname, int *start, int *length)
{
FILE *fp;
int c, sc, retval = 1;
int ll, ladr, lt, sn, i, lval;
int hstart, hlength, sum;
fp = fopen(fname, "r");
if(fp == NULL)
return 0;
hstart = MAXBUF;
hlength = 0;
sum = 0;
do
{
memset(sline, 0x00, MAXSLENGTH);
sc = 0;
while (((c = fgetc(fp)) != EOF) && (c != 0x0A) && (sc < (MAXSLENGTH -1)))
sline[sc++] = (uint8)c;
if ((c != EOF) && ((sc < 11) || (sline[0] != ':')))
{
c = EOF;
retval = 0;
printf("Invalid Intel Hex format.\n");
}
if (c != EOF)
{
sn = sscanf(sline , ":%2x%4x%2x", &ll, &ladr, &lt);
if ((sn == 3) && ((ladr + ll) <= MAXBUF) && (lt == 0))
{
sum = ll + (ladr >> 8) + (ladr & 0xff) + lt;
if(ladr < hstart) hstart = ladr;
for(i = 0; i < ll ; i++)
{
sn = sscanf(&sline[9 + (i << 1)], "%2x", &lval);
ebuf[ladr + i] = (uint8)lval;
sum += (uint8)lval;
}
if(((ladr + ll) - hstart) > hlength)
hlength = (ladr + ll) - hstart;
sum = (0x100 - sum) & 0xff;
sn = sscanf(&sline[9 + (i << 1)], "%2x", &lval);
if (!sn || ((sum - lval) != 0))
{
c = EOF;
retval = 0;
printf("Invalid checksum.\n");
}
}
}
}
while (c != EOF);
if (retval)
{
*length = hlength;
*start = hstart;
}
fclose(fp);
return retval;
}
int output_bin(char *fname, int length)
{
FILE *fp;
int cc;
fp = fopen(fname, "wb");
if(fp == NULL)
return 0;
for (cc = 0 ; cc < length ; cc++)
fputc( ebuf[cc], fp);
fclose(fp);
return 1;
}
int output_intelhex(char *fname, int length)
{
FILE *fp;
int cc = 0, ll, sum, i;
fp = fopen(fname, "w");
if(fp == NULL)
return 0;
while (cc < length)
{
ll = length - cc;
if (ll > IHEXLENGTH) ll = IHEXLENGTH;
sum = ll + (cc >> 8) + (cc & 0xff);
fprintf(fp, ":%2.2X%4.4X00", ll, cc);
for (i = 0; i < ll; i++)
{
fprintf(fp, "%2.2X", ebuf[cc + i]);
sum += ebuf[cc + i];
}
fprintf(fp, "%2.2X\n", (0x100 - sum) & 0xff);
cc += ll;
}
fprintf(fp, ":00000001FF\n");
fclose(fp);
return 1;
}
int eeprom_read(int slave, int start, int length)
{
int i, wkc, ainc = 4;
uint16 estat, aiadr;
uint32 b4;
uint64 b8;
uint8 eepctl;
if((ec_slavecount >= slave) && (slave > 0) && ((start + length) <= MAXBUF))
{
aiadr = 1 - slave;
eepctl = 2;
wkc = ec_APWR(aiadr, ECT_REG_EEPCFG, sizeof(eepctl), &eepctl , EC_TIMEOUTRET3); /* force Eeprom from PDI */
eepctl = 0;
wkc = ec_APWR(aiadr, ECT_REG_EEPCFG, sizeof(eepctl), &eepctl , EC_TIMEOUTRET3); /* set Eeprom to master */
estat = 0x0000;
aiadr = 1 - slave;
wkc=ec_APRD(aiadr, ECT_REG_EEPSTAT, sizeof(estat), &estat, EC_TIMEOUTRET3); /* read eeprom status */
estat = etohs(estat);
if (estat & EC_ESTAT_R64)
{
ainc = 8;
for (i = start ; i < (start + length) ; i+=ainc)
{
b8 = ec_readeepromAP(aiadr, i >> 1 , EC_TIMEOUTEEP);
ebuf[i] = (uint8) b8;
ebuf[i+1] = (uint8) (b8 >> 8);
ebuf[i+2] = (uint8) (b8 >> 16);
ebuf[i+3] = (uint8) (b8 >> 24);
ebuf[i+4] = (uint8) (b8 >> 32);
ebuf[i+5] = (uint8) (b8 >> 40);
ebuf[i+6] = (uint8) (b8 >> 48);
ebuf[i+7] = (uint8) (b8 >> 56);
}
}
else
{
for (i = start ; i < (start + length) ; i+=ainc)
{
b4 = (uint32)ec_readeepromAP(aiadr, i >> 1 , EC_TIMEOUTEEP);
ebuf[i] = (uint8) b4;
ebuf[i+1] = (uint8) (b4 >> 8);
ebuf[i+2] = (uint8) (b4 >> 16);
ebuf[i+3] = (uint8) (b4 >> 24);
}
}
return 1;
}
return 0;
}
int eeprom_write(int slave, int start, int length)
{
int i, wkc, dc = 0;
uint16 aiadr, *wbuf;
uint8 eepctl;
int ret;
if((ec_slavecount >= slave) && (slave > 0) && ((start + length) <= MAXBUF))
{
aiadr = 1 - slave;
eepctl = 2;
wkc = ec_APWR(aiadr, ECT_REG_EEPCFG, sizeof(eepctl), &eepctl , EC_TIMEOUTRET3); /* force Eeprom from PDI */
eepctl = 0;
wkc = ec_APWR(aiadr, ECT_REG_EEPCFG, sizeof(eepctl), &eepctl , EC_TIMEOUTRET3); /* set Eeprom to master */
aiadr = 1 - slave;
wbuf = (uint16 *)&ebuf[0];
for (i = start ; i < (start + length) ; i+=2)
{
ret = ec_writeeepromAP(aiadr, i >> 1 , *(wbuf + (i >> 1)), EC_TIMEOUTEEP);
if (++dc >= 100)
{
dc = 0;
printf(".");
fflush(stdout);
}
}
return 1;
}
return 0;
}
void eepromtool(char *ifname, int slave, int mode, char *fname)
{
int w, rc = 0, estart, esize;
uint16 *wbuf;
/* initialise SOEM, bind socket to ifname */
if (ec_init(ifname))
{
printf("ec_init on %s succeeded.\n",ifname);
w = 0x0000;
wkc = ec_BRD(0x0000, ECT_REG_TYPE, sizeof(w), &w, EC_TIMEOUTSAFE); /* detect number of slaves */
if (wkc > 0)
{
ec_slavecount = wkc;
printf("%d slaves found.\n",ec_slavecount);
if((ec_slavecount >= slave) && (slave > 0))
{
if ((mode == MODE_READBIN) || (mode == MODE_READINTEL))
{
tstart = osal_current_time();
eeprom_read(slave, 0x0000, MINBUF); // read first 128 bytes
wbuf = (uint16 *)&ebuf[0];
printf("Slave %d data\n", slave);
printf(" PDI Control : %4.4X\n",*(wbuf + 0x00));
printf(" PDI Config : %4.4X\n",*(wbuf + 0x01));
printf(" Config Alias : %4.4X\n",*(wbuf + 0x04));
printf(" Checksum : %4.4X\n",*(wbuf + 0x07));
printf(" Vendor ID : %8.8X\n",*(uint32 *)(wbuf + 0x08));
printf(" Product Code : %8.8X\n",*(uint32 *)(wbuf + 0x0A));
printf(" Revision Number : %8.8X\n",*(uint32 *)(wbuf + 0x0C));
printf(" Serial Number : %8.8X\n",*(uint32 *)(wbuf + 0x0E));
printf(" Mailbox Protocol : %4.4X\n",*(wbuf + 0x1C));
esize = (*(wbuf + 0x3E) + 1) * 128;
if (esize > MAXBUF) esize = MAXBUF;
printf(" Size : %4.4X = %d bytes\n",*(wbuf + 0x3E), esize);
printf(" Version : %4.4X\n",*(wbuf + 0x3F));
if (esize > MINBUF)
eeprom_read(slave, MINBUF, esize - MINBUF); // read reminder
tend = osal_current_time();
osal_time_diff(&tstart, &tend, &tdif);
if (mode == MODE_READINTEL) output_intelhex(fname, esize);
if (mode == MODE_READBIN) output_bin(fname, esize);
printf("\nTotal EEPROM read time :%ldms\n", (tdif.usec+(tdif.sec*1000000L)) / 1000);
}
if ((mode == MODE_WRITEBIN) || (mode == MODE_WRITEINTEL))
{
estart = 0;
if (mode == MODE_WRITEINTEL) rc = input_intelhex(fname, &estart, &esize);
if (mode == MODE_WRITEBIN) rc = input_bin(fname, &esize);
if (rc > 0)
{
wbuf = (uint16 *)&ebuf[0];
printf("Slave %d\n", slave);
printf(" Vendor ID : %8.8X\n",*(uint32 *)(wbuf + 0x08));
printf(" Product Code : %8.8X\n",*(uint32 *)(wbuf + 0x0A));
printf(" Revision Number : %8.8X\n",*(uint32 *)(wbuf + 0x0C));
printf(" Serial Number : %8.8X\n",*(uint32 *)(wbuf + 0x0E));
printf("Busy");
fflush(stdout);
tstart = osal_current_time();
eeprom_write(slave, estart, esize);
tend = osal_current_time();
osal_time_diff(&tstart, &tend, &tdif);
printf("\nTotal EEPROM write time :%ldms\n", (tdif.usec+(tdif.sec*1000000L)) / 1000);
}
else
printf("Error reading file, abort.\n");
}
}
else
printf("Slave number outside range.\n");
}
else
printf("No slaves found!\n");
printf("End, close socket\n");
/* stop SOEM, close socket */
ec_close();
}
else
printf("No socket connection on %s\nExcecute as root\n",ifname);
}
int main(int argc, char *argv[])
{
ec_adaptert * adapter = NULL;
printf("SOEM (Simple Open EtherCAT Master)\nEEPROM tool\n");
if (argc > 4)
{
slave = atoi(argv[2]);
mode = MODE_NONE;
if ((strncmp(argv[3], "-r", sizeof("-r")) == 0)) mode = MODE_READBIN;
if ((strncmp(argv[3], "-ri", sizeof("-ri")) == 0)) mode = MODE_READINTEL;
if ((strncmp(argv[3], "-w", sizeof("-w")) == 0)) mode = MODE_WRITEBIN;
if ((strncmp(argv[3], "-wi", sizeof("-wi")) == 0)) mode = MODE_WRITEINTEL;
/* start tool */
eepromtool(argv[1],slave,mode,argv[4]);
}
else
{
printf("Usage: eepromtool ifname slave OPTION fname\n");
printf("ifname = adapter name\n");
printf("slave = slave number in EtherCAT order 1..n\n");
printf(" -r read EEPROM, output binary format\n");
printf(" -ri read EEPROM, output Intel Hex format\n");
printf(" -w write EEPROM, input binary format\n");
printf(" -wi write EEPROM, input Intel Hex format\n");
/* Print the list */
printf ("Available adapters\n");
adapter = ec_find_adapters ();
while (adapter != NULL)
{
printf ("Description : %s, Device to use for wpcap: %s\n", adapter->desc,adapter->name);
adapter = adapter->next;
}
}
printf("End program\n");
return (0);
}

View File

@ -1,373 +0,0 @@
/** \file
* \brief Example code for Simple Open EtherCAT master
*
* Usage : simple_test [ifname1]
* ifname is NIC interface, f.e. eth0
*
* This is a minimal test.
*
* (c)Arthur Ketels 2010 - 2011
*/
#include <stdio.h>
#include <string.h>
//#include <Mmsystem.h>
#include "osal.h"
#include "ethercat.h"
#define EC_TIMEOUTMON 500
char IOmap[4096];
OSAL_THREAD_HANDLE thread1;
int expectedWKC;
boolean needlf;
volatile int wkc;
volatile int rtcnt;
boolean inOP;
uint8 currentgroup = 0;
/* most basic RT thread for process data, just does IO transfer */
void CALLBACK RTthread(UINT uTimerID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2)
{
IOmap[0]++;
ec_send_processdata();
wkc = ec_receive_processdata(EC_TIMEOUTRET);
rtcnt++;
/* do RT control stuff here */
}
int EL7031setup(uint16 slave)
{
int retval;
uint16 u16val;
// map velocity
uint16 map_1c12[4] = {0x0003, 0x1601, 0x1602, 0x1604};
uint16 map_1c13[3] = {0x0002, 0x1a01, 0x1a03};
retval = 0;
// Set PDO mapping using Complete Access
// Strange, writing CA works, reading CA doesn't
// This is a protocol error of the slave.
retval += ec_SDOwrite(slave, 0x1c12, 0x00, TRUE, sizeof(map_1c12), &map_1c12, EC_TIMEOUTSAFE);
retval += ec_SDOwrite(slave, 0x1c13, 0x00, TRUE, sizeof(map_1c13), &map_1c13, EC_TIMEOUTSAFE);
// bug in EL7031 old firmware, CompleteAccess for reading is not supported even if the slave says it is.
ec_slave[slave].CoEdetails &= ~ECT_COEDET_SDOCA;
// set some motor parameters, just as example
u16val = 1200; // max motor current in mA
// retval += ec_SDOwrite(slave, 0x8010, 0x01, FALSE, sizeof(u16val), &u16val, EC_TIMEOUTSAFE);
u16val = 150; // motor coil resistance in 0.01ohm
// retval += ec_SDOwrite(slave, 0x8010, 0x04, FALSE, sizeof(u16val), &u16val, EC_TIMEOUTSAFE);
// set other nescessary parameters as needed
// .....
while(EcatError) printf("%s", ec_elist2string());
printf("EL7031 slave %d set, retval = %d\n", slave, retval);
return 1;
}
int AEPsetup(uint16 slave)
{
int retval;
uint8 u8val;
uint16 u16val;
retval = 0;
u8val = 0;
retval += ec_SDOwrite(slave, 0x1c12, 0x00, FALSE, sizeof(u8val), &u8val, EC_TIMEOUTRXM);
u16val = 0x1603;
retval += ec_SDOwrite(slave, 0x1c12, 0x01, FALSE, sizeof(u16val), &u16val, EC_TIMEOUTRXM);
u8val = 1;
retval += ec_SDOwrite(slave, 0x1c12, 0x00, FALSE, sizeof(u8val), &u8val, EC_TIMEOUTRXM);
u8val = 0;
retval += ec_SDOwrite(slave, 0x1c13, 0x00, FALSE, sizeof(u8val), &u8val, EC_TIMEOUTRXM);
u16val = 0x1a03;
retval += ec_SDOwrite(slave, 0x1c13, 0x01, FALSE, sizeof(u16val), &u16val, EC_TIMEOUTRXM);
u8val = 1;
retval += ec_SDOwrite(slave, 0x1c13, 0x00, FALSE, sizeof(u8val), &u8val, EC_TIMEOUTRXM);
u8val = 8;
retval += ec_SDOwrite(slave, 0x6060, 0x00, FALSE, sizeof(u8val), &u8val, EC_TIMEOUTRXM);
// set some motor parameters, just as example
u16val = 1200; // max motor current in mA
// retval += ec_SDOwrite(slave, 0x8010, 0x01, FALSE, sizeof(u16val), &u16val, EC_TIMEOUTSAFE);
u16val = 150; // motor coil resistance in 0.01ohm
// retval += ec_SDOwrite(slave, 0x8010, 0x04, FALSE, sizeof(u16val), &u16val, EC_TIMEOUTSAFE);
// set other nescessary parameters as needed
// .....
while(EcatError) printf("%s", ec_elist2string());
printf("AEP slave %d set, retval = %d\n", slave, retval);
return 1;
}
void simpletest(char *ifname)
{
int i, j, oloop, iloop, wkc_count, chk, slc;
UINT mmResult;
needlf = FALSE;
inOP = FALSE;
printf("Starting simple test\n");
/* initialise SOEM, bind socket to ifname */
if (ec_init(ifname))
{
printf("ec_init on %s succeeded.\n",ifname);
/* find and auto-config slaves */
if ( ec_config_init(FALSE) > 0 )
{
printf("%d slaves found and configured.\n",ec_slavecount);
if((ec_slavecount > 1))
{
for(slc = 1; slc <= ec_slavecount; slc++)
{
// beckhoff EL7031, using ec_slave[].name is not very reliable
if((ec_slave[slc].eep_man == 0x00000002) && (ec_slave[slc].eep_id == 0x1b773052))
{
printf("Found %s at position %d\n", ec_slave[slc].name, slc);
// link slave specific setup to preop->safeop hook
ec_slave[slc].PO2SOconfig = &EL7031setup;
}
// Copley Controls EAP, using ec_slave[].name is not very reliable
if((ec_slave[slc].eep_man == 0x000000ab) && (ec_slave[slc].eep_id == 0x00000380))
{
printf("Found %s at position %d\n", ec_slave[slc].name, slc);
// link slave specific setup to preop->safeop hook
ec_slave[slc].PO2SOconfig = &AEPsetup;
}
}
}
ec_config_map(&IOmap);
ec_configdc();
printf("Slaves mapped, state to SAFE_OP.\n");
/* wait for all slaves to reach SAFE_OP state */
ec_statecheck(0, EC_STATE_SAFE_OP, EC_TIMEOUTSTATE * 4);
oloop = ec_slave[0].Obytes;
if ((oloop == 0) && (ec_slave[0].Obits > 0)) oloop = 1;
if (oloop > 8) oloop = 8;
iloop = ec_slave[0].Ibytes;
if ((iloop == 0) && (ec_slave[0].Ibits > 0)) iloop = 1;
if (iloop > 8) iloop = 8;
printf("segments : %d : %d %d %d %d\n",ec_group[0].nsegments ,ec_group[0].IOsegment[0],ec_group[0].IOsegment[1],ec_group[0].IOsegment[2],ec_group[0].IOsegment[3]);
printf("Request operational state for all slaves\n");
expectedWKC = (ec_group[0].outputsWKC * 2) + ec_group[0].inputsWKC;
printf("Calculated workcounter %d\n", expectedWKC);
ec_slave[0].state = EC_STATE_OPERATIONAL;
/* send one valid process data to make outputs in slaves happy*/
ec_send_processdata();
ec_receive_processdata(EC_TIMEOUTRET);
/* start RT thread as periodic MM timer */
mmResult = timeSetEvent(1, 0, RTthread, 0, TIME_PERIODIC);
/* request OP state for all slaves */
ec_writestate(0);
chk = 200;
/* wait for all slaves to reach OP state */
do
{
ec_statecheck(0, EC_STATE_OPERATIONAL, 50000);
}
while (chk-- && (ec_slave[0].state != EC_STATE_OPERATIONAL));
if (ec_slave[0].state == EC_STATE_OPERATIONAL )
{
printf("Operational state reached for all slaves.\n");
wkc_count = 0;
inOP = TRUE;
/* cyclic loop, reads data from RT thread */
for(i = 1; i <= 500; i++)
{
if(wkc >= expectedWKC)
{
printf("Processdata cycle %4d, WKC %d , O:", rtcnt, wkc);
for(j = 0 ; j < oloop; j++)
{
printf(" %2.2x", *(ec_slave[0].outputs + j));
}
printf(" I:");
for(j = 0 ; j < iloop; j++)
{
printf(" %2.2x", *(ec_slave[0].inputs + j));
}
printf(" T:%lld\r",ec_DCtime);
needlf = TRUE;
}
osal_usleep(50000);
}
inOP = FALSE;
}
else
{
printf("Not all slaves reached operational state.\n");
ec_readstate();
for(i = 1; i<=ec_slavecount ; i++)
{
if(ec_slave[i].state != EC_STATE_OPERATIONAL)
{
printf("Slave %d State=0x%2.2x StatusCode=0x%4.4x : %s\n",
i, ec_slave[i].state, ec_slave[i].ALstatuscode, ec_ALstatuscode2string(ec_slave[i].ALstatuscode));
}
}
}
/* stop RT thread */
timeKillEvent(mmResult);
printf("\nRequest init state for all slaves\n");
ec_slave[0].state = EC_STATE_INIT;
/* request INIT state for all slaves */
ec_writestate(0);
}
else
{
printf("No slaves found!\n");
}
printf("End simple test, close socket\n");
/* stop SOEM, close socket */
ec_close();
}
else
{
printf("No socket connection on %s\nExcecute as root\n",ifname);
}
}
//DWORD WINAPI ecatcheck( LPVOID lpParam )
OSAL_THREAD_FUNC ecatcheck(void *lpParam)
{
int slave;
while(1)
{
if( inOP && ((wkc < expectedWKC) || ec_group[currentgroup].docheckstate))
{
if (needlf)
{
needlf = FALSE;
printf("\n");
}
/* one ore more slaves are not responding */
ec_group[currentgroup].docheckstate = FALSE;
ec_readstate();
for (slave = 1; slave <= ec_slavecount; slave++)
{
if ((ec_slave[slave].group == currentgroup) && (ec_slave[slave].state != EC_STATE_OPERATIONAL))
{
ec_group[currentgroup].docheckstate = TRUE;
if (ec_slave[slave].state == (EC_STATE_SAFE_OP + EC_STATE_ERROR))
{
printf("ERROR : slave %d is in SAFE_OP + ERROR, attempting ack.\n", slave);
ec_slave[slave].state = (EC_STATE_SAFE_OP + EC_STATE_ACK);
ec_writestate(slave);
}
else if(ec_slave[slave].state == EC_STATE_SAFE_OP)
{
printf("WARNING : slave %d is in SAFE_OP, change to OPERATIONAL.\n", slave);
ec_slave[slave].state = EC_STATE_OPERATIONAL;
ec_writestate(slave);
}
else if(ec_slave[slave].state > EC_STATE_NONE)
{
if (ec_reconfig_slave(slave, EC_TIMEOUTMON))
{
ec_slave[slave].islost = FALSE;
printf("MESSAGE : slave %d reconfigured\n",slave);
}
}
else if(!ec_slave[slave].islost)
{
/* re-check state */
ec_statecheck(slave, EC_STATE_OPERATIONAL, EC_TIMEOUTRET);
if (ec_slave[slave].state == EC_STATE_NONE)
{
ec_slave[slave].islost = TRUE;
printf("ERROR : slave %d lost\n",slave);
}
}
}
if (ec_slave[slave].islost)
{
if(ec_slave[slave].state == EC_STATE_NONE)
{
if (ec_recover_slave(slave, EC_TIMEOUTMON))
{
ec_slave[slave].islost = FALSE;
printf("MESSAGE : slave %d recovered\n",slave);
}
}
else
{
ec_slave[slave].islost = FALSE;
printf("MESSAGE : slave %d found\n",slave);
}
}
}
if(!ec_group[currentgroup].docheckstate)
printf("OK : all slaves resumed OPERATIONAL.\n");
}
osal_usleep(10000);
}
return 0;
}
char ifbuf[1024];
int main(int argc, char *argv[])
{
ec_adaptert * adapter = NULL;
printf("SOEM (Simple Open EtherCAT Master)\nSimple test\n");
if (argc > 1)
{
/* create thread to handle slave error handling in OP */
osal_thread_create(&thread1, 128000, &ecatcheck, (void*) &ctime);
strcpy(ifbuf, argv[1]);
/* start cyclic part */
simpletest(ifbuf);
}
else
{
printf("Usage: simple_test ifname1\n");
/* Print the list */
printf ("Available adapters\n");
adapter = ec_find_adapters ();
while (adapter != NULL)
{
printf ("Description : %s, Device to use for wpcap: %s\n", adapter->desc,adapter->name);
adapter = adapter->next;
}
}
printf("End program\n");
return (0);
}

View File

@ -1,646 +0,0 @@
/** \file
* \brief Example code for Simple Open EtherCAT master
*
* Usage : slaveinfo [ifname] [-sdo] [-map]
* Ifname is NIC interface, f.e. eth0.
* Optional -sdo to display CoE object dictionary.
* Optional -map to display slave PDO mapping
*
* This shows the configured slave data.
*
* (c)Arthur Ketels 2010 - 2011
*/
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#include "ethercat.h"
char IOmap[4096];
ec_ODlistt ODlist;
ec_OElistt OElist;
boolean printSDO = FALSE;
boolean printMAP = FALSE;
char usdo[128];
char hstr[1024];
char* dtype2string(uint16 dtype)
{
switch(dtype)
{
case ECT_BOOLEAN:
sprintf(hstr, "BOOLEAN");
break;
case ECT_INTEGER8:
sprintf(hstr, "INTEGER8");
break;
case ECT_INTEGER16:
sprintf(hstr, "INTEGER16");
break;
case ECT_INTEGER32:
sprintf(hstr, "INTEGER32");
break;
case ECT_INTEGER24:
sprintf(hstr, "INTEGER24");
break;
case ECT_INTEGER64:
sprintf(hstr, "INTEGER64");
break;
case ECT_UNSIGNED8:
sprintf(hstr, "UNSIGNED8");
break;
case ECT_UNSIGNED16:
sprintf(hstr, "UNSIGNED16");
break;
case ECT_UNSIGNED32:
sprintf(hstr, "UNSIGNED32");
break;
case ECT_UNSIGNED24:
sprintf(hstr, "UNSIGNED24");
break;
case ECT_UNSIGNED64:
sprintf(hstr, "UNSIGNED64");
break;
case ECT_REAL32:
sprintf(hstr, "REAL32");
break;
case ECT_REAL64:
sprintf(hstr, "REAL64");
break;
case ECT_BIT1:
sprintf(hstr, "BIT1");
break;
case ECT_BIT2:
sprintf(hstr, "BIT2");
break;
case ECT_BIT3:
sprintf(hstr, "BIT3");
break;
case ECT_BIT4:
sprintf(hstr, "BIT4");
break;
case ECT_BIT5:
sprintf(hstr, "BIT5");
break;
case ECT_BIT6:
sprintf(hstr, "BIT6");
break;
case ECT_BIT7:
sprintf(hstr, "BIT7");
break;
case ECT_BIT8:
sprintf(hstr, "BIT8");
break;
case ECT_VISIBLE_STRING:
sprintf(hstr, "VISIBLE_STRING");
break;
case ECT_OCTET_STRING:
sprintf(hstr, "OCTET_STRING");
break;
default:
sprintf(hstr, "Type 0x%4.4X", dtype);
}
return hstr;
}
char* SDO2string(uint16 slave, uint16 index, uint8 subidx, uint16 dtype)
{
int l = sizeof(usdo) - 1, i;
uint8 *u8;
int8 *i8;
uint16 *u16;
int16 *i16;
uint32 *u32;
int32 *i32;
uint64 *u64;
int64 *i64;
float *sr;
double *dr;
char es[32];
memset(&usdo, 0, 128);
ec_SDOread(slave, index, subidx, FALSE, &l, &usdo, EC_TIMEOUTRXM);
if (EcatError)
{
return ec_elist2string();
}
else
{
switch(dtype)
{
case ECT_BOOLEAN:
u8 = (uint8*) &usdo[0];
if (*u8) sprintf(hstr, "TRUE");
else sprintf(hstr, "FALSE");
break;
case ECT_INTEGER8:
i8 = (int8*) &usdo[0];
sprintf(hstr, "0x%2.2x %d", *i8, *i8);
break;
case ECT_INTEGER16:
i16 = (int16*) &usdo[0];
sprintf(hstr, "0x%4.4x %d", *i16, *i16);
break;
case ECT_INTEGER32:
case ECT_INTEGER24:
i32 = (int32*) &usdo[0];
sprintf(hstr, "0x%8.8x %d", *i32, *i32);
break;
case ECT_INTEGER64:
i64 = (int64*) &usdo[0];
sprintf(hstr, "0x%16.16"PRIx64" %"PRId64, *i64, *i64);
break;
case ECT_UNSIGNED8:
u8 = (uint8*) &usdo[0];
sprintf(hstr, "0x%2.2x %u", *u8, *u8);
break;
case ECT_UNSIGNED16:
u16 = (uint16*) &usdo[0];
sprintf(hstr, "0x%4.4x %u", *u16, *u16);
break;
case ECT_UNSIGNED32:
case ECT_UNSIGNED24:
u32 = (uint32*) &usdo[0];
sprintf(hstr, "0x%8.8x %u", *u32, *u32);
break;
case ECT_UNSIGNED64:
u64 = (uint64*) &usdo[0];
sprintf(hstr, "0x%16.16"PRIx64" %"PRIu64, *u64, *u64);
break;
case ECT_REAL32:
sr = (float*) &usdo[0];
sprintf(hstr, "%f", *sr);
break;
case ECT_REAL64:
dr = (double*) &usdo[0];
sprintf(hstr, "%f", *dr);
break;
case ECT_BIT1:
case ECT_BIT2:
case ECT_BIT3:
case ECT_BIT4:
case ECT_BIT5:
case ECT_BIT6:
case ECT_BIT7:
case ECT_BIT8:
u8 = (uint8*) &usdo[0];
sprintf(hstr, "0x%x", *u8);
break;
case ECT_VISIBLE_STRING:
strcpy(hstr, usdo);
break;
case ECT_OCTET_STRING:
hstr[0] = 0x00;
for (i = 0 ; i < l ; i++)
{
sprintf(es, "0x%2.2x ", usdo[i]);
strcat( hstr, es);
}
break;
default:
sprintf(hstr, "Unknown type");
}
return hstr;
}
}
/** Read PDO assign structure */
int si_PDOassign(uint16 slave, uint16 PDOassign, int mapoffset, int bitoffset)
{
uint16 idxloop, nidx, subidxloop, rdat, idx, subidx;
uint8 subcnt;
int wkc, bsize = 0, rdl;
int32 rdat2;
uint8 bitlen, obj_subidx;
uint16 obj_idx;
int abs_offset, abs_bit;
rdl = sizeof(rdat); rdat = 0;
/* read PDO assign subindex 0 ( = number of PDO's) */
wkc = ec_SDOread(slave, PDOassign, 0x00, FALSE, &rdl, &rdat, EC_TIMEOUTRXM);
rdat = etohs(rdat);
/* positive result from slave ? */
if ((wkc > 0) && (rdat > 0))
{
/* number of available sub indexes */
nidx = rdat;
bsize = 0;
/* read all PDO's */
for (idxloop = 1; idxloop <= nidx; idxloop++)
{
rdl = sizeof(rdat); rdat = 0;
/* read PDO assign */
wkc = ec_SDOread(slave, PDOassign, (uint8)idxloop, FALSE, &rdl, &rdat, EC_TIMEOUTRXM);
/* result is index of PDO */
idx = etohl(rdat);
if (idx > 0)
{
rdl = sizeof(subcnt); subcnt = 0;
/* read number of subindexes of PDO */
wkc = ec_SDOread(slave,idx, 0x00, FALSE, &rdl, &subcnt, EC_TIMEOUTRXM);
subidx = subcnt;
/* for each subindex */
for (subidxloop = 1; subidxloop <= subidx; subidxloop++)
{
rdl = sizeof(rdat2); rdat2 = 0;
/* read SDO that is mapped in PDO */
wkc = ec_SDOread(slave, idx, (uint8)subidxloop, FALSE, &rdl, &rdat2, EC_TIMEOUTRXM);
rdat2 = etohl(rdat2);
/* extract bitlength of SDO */
bitlen = LO_BYTE(rdat2);
bsize += bitlen;
obj_idx = (uint16)(rdat2 >> 16);
obj_subidx = (uint8)((rdat2 >> 8) & 0x000000ff);
abs_offset = mapoffset + (bitoffset / 8);
abs_bit = bitoffset % 8;
ODlist.Slave = slave;
ODlist.Index[0] = obj_idx;
OElist.Entries = 0;
wkc = 0;
/* read object entry from dictionary if not a filler (0x0000:0x00) */
if(obj_idx || obj_subidx)
wkc = ec_readOEsingle(0, obj_subidx, &ODlist, &OElist);
printf(" [0x%4.4X.%1d] 0x%4.4X:0x%2.2X 0x%2.2X", abs_offset, abs_bit, obj_idx, obj_subidx, bitlen);
if((wkc > 0) && OElist.Entries)
{
printf(" %-12s %s\n", dtype2string(OElist.DataType[obj_subidx]), OElist.Name[obj_subidx]);
}
else
printf("\n");
bitoffset += bitlen;
};
};
};
};
/* return total found bitlength (PDO) */
return bsize;
}
int si_map_sdo(int slave)
{
int wkc, rdl;
int retVal = 0;
uint8 nSM, iSM, tSM;
int Tsize, outputs_bo, inputs_bo;
uint8 SMt_bug_add;
printf("PDO mapping according to CoE :\n");
SMt_bug_add = 0;
outputs_bo = 0;
inputs_bo = 0;
rdl = sizeof(nSM); nSM = 0;
/* read SyncManager Communication Type object count */
wkc = ec_SDOread(slave, ECT_SDO_SMCOMMTYPE, 0x00, FALSE, &rdl, &nSM, EC_TIMEOUTRXM);
/* positive result from slave ? */
if ((wkc > 0) && (nSM > 2))
{
/* make nSM equal to number of defined SM */
nSM--;
/* limit to maximum number of SM defined, if true the slave can't be configured */
if (nSM > EC_MAXSM)
nSM = EC_MAXSM;
/* iterate for every SM type defined */
for (iSM = 2 ; iSM <= nSM ; iSM++)
{
rdl = sizeof(tSM); tSM = 0;
/* read SyncManager Communication Type */
wkc = ec_SDOread(slave, ECT_SDO_SMCOMMTYPE, iSM + 1, FALSE, &rdl, &tSM, EC_TIMEOUTRXM);
if (wkc > 0)
{
if((iSM == 2) && (tSM == 2)) // SM2 has type 2 == mailbox out, this is a bug in the slave!
{
SMt_bug_add = 1; // try to correct, this works if the types are 0 1 2 3 and should be 1 2 3 4
printf("Activated SM type workaround, possible incorrect mapping.\n");
}
if(tSM)
tSM += SMt_bug_add; // only add if SMt > 0
if (tSM == 3) // outputs
{
/* read the assign RXPDO */
printf(" SM%1d outputs\n addr b index: sub bitl data_type name\n", iSM);
Tsize = si_PDOassign(slave, ECT_SDO_PDOASSIGN + iSM, (int)(ec_slave[slave].outputs - (uint8 *)&IOmap[0]), outputs_bo );
outputs_bo += Tsize;
}
if (tSM == 4) // inputs
{
/* read the assign TXPDO */
printf(" SM%1d inputs\n addr b index: sub bitl data_type name\n", iSM);
Tsize = si_PDOassign(slave, ECT_SDO_PDOASSIGN + iSM, (int)(ec_slave[slave].inputs - (uint8 *)&IOmap[0]), inputs_bo );
inputs_bo += Tsize;
}
}
}
}
/* found some I/O bits ? */
if ((outputs_bo > 0) || (inputs_bo > 0))
retVal = 1;
return retVal;
}
int si_siiPDO(uint16 slave, uint8 t, int mapoffset, int bitoffset)
{
uint16 a , w, c, e, er, Size;
uint8 eectl;
uint16 obj_idx;
uint8 obj_subidx;
uint8 obj_name;
uint8 obj_datatype;
uint8 bitlen;
int totalsize;
ec_eepromPDOt eepPDO;
ec_eepromPDOt *PDO;
int abs_offset, abs_bit;
char str_name[EC_MAXNAME + 1];
eectl = ec_slave[slave].eep_pdi;
Size = 0;
totalsize = 0;
PDO = &eepPDO;
PDO->nPDO = 0;
PDO->Length = 0;
PDO->Index[1] = 0;
for (c = 0 ; c < EC_MAXSM ; c++) PDO->SMbitsize[c] = 0;
if (t > 1)
t = 1;
PDO->Startpos = ec_siifind(slave, ECT_SII_PDO + t);
if (PDO->Startpos > 0)
{
a = PDO->Startpos;
w = ec_siigetbyte(slave, a++);
w += (ec_siigetbyte(slave, a++) << 8);
PDO->Length = w;
c = 1;
/* traverse through all PDOs */
do
{
PDO->nPDO++;
PDO->Index[PDO->nPDO] = ec_siigetbyte(slave, a++);
PDO->Index[PDO->nPDO] += (ec_siigetbyte(slave, a++) << 8);
PDO->BitSize[PDO->nPDO] = 0;
c++;
/* number of entries in PDO */
e = ec_siigetbyte(slave, a++);
PDO->SyncM[PDO->nPDO] = ec_siigetbyte(slave, a++);
a++;
obj_name = ec_siigetbyte(slave, a++);
a += 2;
c += 2;
if (PDO->SyncM[PDO->nPDO] < EC_MAXSM) /* active and in range SM? */
{
str_name[0] = 0;
if(obj_name)
ec_siistring(str_name, slave, obj_name);
if (t)
printf(" SM%1d RXPDO 0x%4.4X %s\n", PDO->SyncM[PDO->nPDO], PDO->Index[PDO->nPDO], str_name);
else
printf(" SM%1d TXPDO 0x%4.4X %s\n", PDO->SyncM[PDO->nPDO], PDO->Index[PDO->nPDO], str_name);
printf(" addr b index: sub bitl data_type name\n");
/* read all entries defined in PDO */
for (er = 1; er <= e; er++)
{
c += 4;
obj_idx = ec_siigetbyte(slave, a++);
obj_idx += (ec_siigetbyte(slave, a++) << 8);
obj_subidx = ec_siigetbyte(slave, a++);
obj_name = ec_siigetbyte(slave, a++);
obj_datatype = ec_siigetbyte(slave, a++);
bitlen = ec_siigetbyte(slave, a++);
abs_offset = mapoffset + (bitoffset / 8);
abs_bit = bitoffset % 8;
PDO->BitSize[PDO->nPDO] += bitlen;
a += 2;
str_name[0] = 0;
if(obj_name)
ec_siistring(str_name, slave, obj_name);
printf(" [0x%4.4X.%1d] 0x%4.4X:0x%2.2X 0x%2.2X", abs_offset, abs_bit, obj_idx, obj_subidx, bitlen);
printf(" %-12s %s\n", dtype2string(obj_datatype), str_name);
bitoffset += bitlen;
totalsize += bitlen;
}
PDO->SMbitsize[ PDO->SyncM[PDO->nPDO] ] += PDO->BitSize[PDO->nPDO];
Size += PDO->BitSize[PDO->nPDO];
c++;
}
else /* PDO deactivated because SM is 0xff or > EC_MAXSM */
{
c += 4 * e;
a += 8 * e;
c++;
}
if (PDO->nPDO >= (EC_MAXEEPDO - 1)) c = PDO->Length; /* limit number of PDO entries in buffer */
}
while (c < PDO->Length);
}
if (eectl) ec_eeprom2pdi(slave); /* if eeprom control was previously pdi then restore */
return totalsize;
}
int si_map_sii(int slave)
{
int retVal = 0;
int Tsize, outputs_bo, inputs_bo;
printf("PDO mapping according to SII :\n");
outputs_bo = 0;
inputs_bo = 0;
/* read the assign RXPDOs */
Tsize = si_siiPDO(slave, 1, (int)(ec_slave[slave].outputs - (uint8*)&IOmap), outputs_bo );
outputs_bo += Tsize;
/* read the assign TXPDOs */
Tsize = si_siiPDO(slave, 0, (int)(ec_slave[slave].inputs - (uint8*)&IOmap), inputs_bo );
inputs_bo += Tsize;
/* found some I/O bits ? */
if ((outputs_bo > 0) || (inputs_bo > 0))
retVal = 1;
return retVal;
}
void si_sdo(int cnt)
{
int i, j;
ODlist.Entries = 0;
memset(&ODlist, 0, sizeof(ODlist));
if( ec_readODlist(cnt, &ODlist))
{
printf(" CoE Object Description found, %d entries.\n",ODlist.Entries);
for( i = 0 ; i < ODlist.Entries ; i++)
{
ec_readODdescription(i, &ODlist);
while(EcatError) printf("%s", ec_elist2string());
printf(" Index: %4.4x Datatype: %4.4x Objectcode: %2.2x Name: %s\n",
ODlist.Index[i], ODlist.DataType[i], ODlist.ObjectCode[i], ODlist.Name[i]);
memset(&OElist, 0, sizeof(OElist));
ec_readOE(i, &ODlist, &OElist);
while(EcatError) printf("%s", ec_elist2string());
for( j = 0 ; j < ODlist.MaxSub[i]+1 ; j++)
{
if ((OElist.DataType[j] > 0) && (OElist.BitLength[j] > 0))
{
printf(" Sub: %2.2x Datatype: %4.4x Bitlength: %4.4x Obj.access: %4.4x Name: %s\n",
j, OElist.DataType[j], OElist.BitLength[j], OElist.ObjAccess[j], OElist.Name[j]);
if ((OElist.ObjAccess[j] & 0x0007))
{
printf(" Value :%s\n", SDO2string(cnt, ODlist.Index[i], j, OElist.DataType[j]));
}
}
}
}
}
else
{
while(EcatError) printf("%s", ec_elist2string());
}
}
void slaveinfo(char *ifname)
{
int cnt, i, j, nSM;
uint16 ssigen;
int expectedWKC;
printf("Starting slaveinfo\n");
/* initialise SOEM, bind socket to ifname */
if (ec_init(ifname))
{
printf("ec_init on %s succeeded.\n",ifname);
/* find and auto-config slaves */
if ( ec_config(FALSE, &IOmap) > 0 )
{
ec_configdc();
while(EcatError) printf("%s", ec_elist2string());
printf("%d slaves found and configured.\n",ec_slavecount);
expectedWKC = (ec_group[0].outputsWKC * 2) + ec_group[0].inputsWKC;
printf("Calculated workcounter %d\n", expectedWKC);
/* wait for all slaves to reach SAFE_OP state */
ec_statecheck(0, EC_STATE_SAFE_OP, EC_TIMEOUTSTATE * 3);
if (ec_slave[0].state != EC_STATE_SAFE_OP )
{
printf("Not all slaves reached safe operational state.\n");
ec_readstate();
for(i = 1; i<=ec_slavecount ; i++)
{
if(ec_slave[i].state != EC_STATE_SAFE_OP)
{
printf("Slave %d State=%2x StatusCode=%4x : %s\n",
i, ec_slave[i].state, ec_slave[i].ALstatuscode, ec_ALstatuscode2string(ec_slave[i].ALstatuscode));
}
}
}
ec_readstate();
for( cnt = 1 ; cnt <= ec_slavecount ; cnt++)
{
printf("\nSlave:%d\n Name:%s\n Output size: %dbits\n Input size: %dbits\n State: %d\n Delay: %d[ns]\n Has DC: %d\n",
cnt, ec_slave[cnt].name, ec_slave[cnt].Obits, ec_slave[cnt].Ibits,
ec_slave[cnt].state, ec_slave[cnt].pdelay, ec_slave[cnt].hasdc);
if (ec_slave[cnt].hasdc) printf(" DCParentport:%d\n", ec_slave[cnt].parentport);
printf(" Activeports:%d.%d.%d.%d\n", (ec_slave[cnt].activeports & 0x01) > 0 ,
(ec_slave[cnt].activeports & 0x02) > 0 ,
(ec_slave[cnt].activeports & 0x04) > 0 ,
(ec_slave[cnt].activeports & 0x08) > 0 );
printf(" Configured address: %4.4x\n", ec_slave[cnt].configadr);
printf(" Man: %8.8x ID: %8.8x Rev: %8.8x\n", (int)ec_slave[cnt].eep_man, (int)ec_slave[cnt].eep_id, (int)ec_slave[cnt].eep_rev);
for(nSM = 0 ; nSM < EC_MAXSM ; nSM++)
{
if(ec_slave[cnt].SM[nSM].StartAddr > 0)
printf(" SM%1d A:%4.4x L:%4d F:%8.8x Type:%d\n",nSM, ec_slave[cnt].SM[nSM].StartAddr, ec_slave[cnt].SM[nSM].SMlength,
(int)ec_slave[cnt].SM[nSM].SMflags, ec_slave[cnt].SMtype[nSM]);
}
for(j = 0 ; j < ec_slave[cnt].FMMUunused ; j++)
{
printf(" FMMU%1d Ls:%8.8x Ll:%4d Lsb:%d Leb:%d Ps:%4.4x Psb:%d Ty:%2.2x Act:%2.2x\n", j,
(int)ec_slave[cnt].FMMU[j].LogStart, ec_slave[cnt].FMMU[j].LogLength, ec_slave[cnt].FMMU[j].LogStartbit,
ec_slave[cnt].FMMU[j].LogEndbit, ec_slave[cnt].FMMU[j].PhysStart, ec_slave[cnt].FMMU[j].PhysStartBit,
ec_slave[cnt].FMMU[j].FMMUtype, ec_slave[cnt].FMMU[j].FMMUactive);
}
printf(" FMMUfunc 0:%d 1:%d 2:%d 3:%d\n",
ec_slave[cnt].FMMU0func, ec_slave[cnt].FMMU1func, ec_slave[cnt].FMMU2func, ec_slave[cnt].FMMU3func);
printf(" MBX length wr: %d rd: %d MBX protocols : %2.2x\n", ec_slave[cnt].mbx_l, ec_slave[cnt].mbx_rl, ec_slave[cnt].mbx_proto);
ssigen = ec_siifind(cnt, ECT_SII_GENERAL);
/* SII general section */
if (ssigen)
{
ec_slave[cnt].CoEdetails = ec_siigetbyte(cnt, ssigen + 0x07);
ec_slave[cnt].FoEdetails = ec_siigetbyte(cnt, ssigen + 0x08);
ec_slave[cnt].EoEdetails = ec_siigetbyte(cnt, ssigen + 0x09);
ec_slave[cnt].SoEdetails = ec_siigetbyte(cnt, ssigen + 0x0a);
if((ec_siigetbyte(cnt, ssigen + 0x0d) & 0x02) > 0)
{
ec_slave[cnt].blockLRW = 1;
ec_slave[0].blockLRW++;
}
ec_slave[cnt].Ebuscurrent = ec_siigetbyte(cnt, ssigen + 0x0e);
ec_slave[cnt].Ebuscurrent += ec_siigetbyte(cnt, ssigen + 0x0f) << 8;
ec_slave[0].Ebuscurrent += ec_slave[cnt].Ebuscurrent;
}
printf(" CoE details: %2.2x FoE details: %2.2x EoE details: %2.2x SoE details: %2.2x\n",
ec_slave[cnt].CoEdetails, ec_slave[cnt].FoEdetails, ec_slave[cnt].EoEdetails, ec_slave[cnt].SoEdetails);
printf(" Ebus current: %d[mA]\n only LRD/LWR:%d\n",
ec_slave[cnt].Ebuscurrent, ec_slave[cnt].blockLRW);
if ((ec_slave[cnt].mbx_proto & ECT_MBXPROT_COE) && printSDO)
si_sdo(cnt);
if(printMAP)
{
if (ec_slave[cnt].mbx_proto & ECT_MBXPROT_COE)
si_map_sdo(cnt);
else
si_map_sii(cnt);
}
}
}
else
{
printf("No slaves found!\n");
}
printf("End slaveinfo, close socket\n");
/* stop SOEM, close socket */
ec_close();
}
else
{
printf("No socket connection on %s\nExcecute as root\n",ifname);
}
}
char ifbuf[1024];
int main(int argc, char *argv[])
{
ec_adaptert * adapter = NULL;
printf("SOEM (Simple Open EtherCAT Master)\nSlaveinfo\n");
if (argc > 1)
{
if ((argc > 2) && (strncmp(argv[2], "-sdo", sizeof("-sdo")) == 0)) printSDO = TRUE;
if ((argc > 2) && (strncmp(argv[2], "-map", sizeof("-map")) == 0)) printMAP = TRUE;
/* start slaveinfo */
strcpy(ifbuf, argv[1]);
slaveinfo(ifbuf);
}
else
{
printf("Usage: slaveinfo ifname [options]\nifname = eth0 for example\nOptions :\n -sdo : print SDO info\n -map : print mapping\n");
/* Print the list */
printf ("Available adapters\n");
adapter = ec_find_adapters ();
while (adapter != NULL)
{
printf ("Description : %s, Device to use for wpcap: %s\n", adapter->desc,adapter->name);
adapter = adapter->next;
}
}
printf("End program\n");
return (0);
}

View File

@ -1,5 +1,4 @@
set(SOURCES eepromtool.c)
add_executable(eepromtool ${SOURCES})
add_executable(eepromtool main.c)
target_link_libraries(eepromtool soem)
install(TARGETS eepromtool DESTINATION bin)

View File

@ -310,7 +310,7 @@ int eeprom_writealias(int slave, int alias, uint16 crc)
return 0;
}
void eepromtool(char *ifname, int slave, int mode, char *fname)
void do_eepromtool(char *ifname, int slave, int mode, char *fname)
{
int w, rc = 0, estart, esize;
uint16 *wbuf;
@ -430,8 +430,9 @@ void eepromtool(char *ifname, int slave, int mode, char *fname)
}
}
int main(int argc, char *argv[])
int eepromtool(int argc, char *argv[])
{
ec_adaptert * adapter = NULL;
printf("SOEM (Simple Open EtherCAT Master)\nEEPROM tool\n");
mode = MODE_NONE;
@ -452,7 +453,7 @@ int main(int argc, char *argv[])
}
}
/* start tool */
eepromtool(argv[1],slave,mode,argv[4]);
do_eepromtool(argv[1],slave,mode,argv[4]);
}
else
{
@ -465,6 +466,14 @@ int main(int argc, char *argv[])
printf(" -ri read EEPROM, output Intel Hex format\n");
printf(" -w write EEPROM, input binary format\n");
printf(" -wi write EEPROM, input Intel Hex format\n");
printf ("Available adapters\n");
adapter = ec_find_adapters ();
while (adapter != NULL)
{
printf ("Description : %s, Device to use for wpcap: %s\n", adapter->desc,adapter->name);
adapter = adapter->next;
}
}
printf("End program\n");

View File

@ -0,0 +1,20 @@
/*
* Licensed under the GNU General Public License version 2 with exceptions. See
* LICENSE file in the project root for full license information
*/
#ifndef _EEPROMTOOL_H
#define _EEPROMTOOL_H
#ifdef __cplusplus
extern "C"
{
#endif
int eepromtool(int argc, char *argv[]);
#ifdef __cplusplus
}
#endif
#endif /* _EEPROMTOOL_H */

View File

@ -0,0 +1,7 @@
#include "eepromtool.h"
#include "osal.h"
int OSAL_MAIN (int argc, char * argv[])
{
return eepromtool (argc, argv);
}

View File

@ -1,5 +1,4 @@
set(SOURCES simple_test.c)
add_executable(simple_test ${SOURCES})
add_executable(simple_test main.c)
target_link_libraries(simple_test soem)
install(TARGETS simple_test DESTINATION bin)

View File

@ -0,0 +1,7 @@
#include "simple_test.h"
#include "osal.h"
int OSAL_MAIN (int argc, char * argv[])
{
return simple_test (argc, argv);
}

View File

@ -25,7 +25,7 @@ volatile int wkc;
boolean inOP;
uint8 currentgroup = 0;
void simpletest(char *ifname)
void do_simpletest(char *ifname)
{
int i, j, oloop, iloop, chk;
needlf = FALSE;
@ -220,21 +220,29 @@ OSAL_THREAD_FUNC ecatcheck( void *ptr )
}
}
int main(int argc, char *argv[])
int simple_test(int argc, char *argv[])
{
ec_adaptert * adapter = NULL;
printf("SOEM (Simple Open EtherCAT Master)\nSimple test\n");
if (argc > 1)
{
/* create thread to handle slave error handling in OP */
// pthread_create( &thread1, NULL, (void *) &ecatcheck, (void*) &ctime);
osal_thread_create(&thread1, 128000, &ecatcheck, (void*) &ctime);
osal_thread_create(&thread1, 128000, &ecatcheck, NULL);
/* start cyclic part */
simpletest(argv[1]);
do_simpletest(argv[1]);
}
else
{
printf("Usage: simple_test ifname1\nifname = eth0 for example\n");
printf ("Available adapters\n");
adapter = ec_find_adapters ();
while (adapter != NULL)
{
printf ("Description : %s, Device to use for wpcap: %s\n", adapter->desc,adapter->name);
adapter = adapter->next;
}
}
printf("End program\n");

View File

@ -0,0 +1,20 @@
/*
* Licensed under the GNU General Public License version 2 with exceptions. See
* LICENSE file in the project root for full license information
*/
#ifndef _SIMPLE_TEST_H
#define _SIMPLE_TEST_H
#ifdef __cplusplus
extern "C"
{
#endif
int simple_test(int argc, char *argv[]);
#ifdef __cplusplus
}
#endif
#endif /* _SIMPLE_TEST_H */

View File

@ -1,5 +1,4 @@
set(SOURCES slaveinfo.c)
add_executable(slaveinfo ${SOURCES})
add_executable(slaveinfo main.c)
target_link_libraries(slaveinfo soem)
install(TARGETS slaveinfo DESTINATION bin)

View File

@ -0,0 +1,7 @@
#include "slaveinfo.h"
#include "osal.h"
int OSAL_MAIN (int argc, char * argv[])
{
return slaveinfo (argc, argv);
}

View File

@ -1,3 +1,8 @@
/*
* Licensed under the GNU General Public License version 2 with exceptions. See
* LICENSE file in the project root for full license information
*/
/** \file
* \brief Example code for Simple Open EtherCAT master
*
@ -7,10 +12,10 @@
* Optional -map to display slave PDO mapping
*
* This shows the configured slave data.
*
* (c)Arthur Ketels 2010 - 2011
*/
#include "slaveinfo.h"
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
@ -505,7 +510,7 @@ void si_sdo(int cnt)
}
}
void slaveinfo(char *ifname)
void do_slaveinfo(char *ifname)
{
int cnt, i, j, nSM;
uint16 ssigen;
@ -617,9 +622,7 @@ void slaveinfo(char *ifname)
}
}
char ifbuf[1024];
int main(int argc, char *argv[])
int slaveinfo(int argc, char *argv[])
{
ec_adaptert * adapter = NULL;
printf("SOEM (Simple Open EtherCAT Master)\nSlaveinfo\n");
@ -629,8 +632,7 @@ int main(int argc, char *argv[])
if ((argc > 2) && (strncmp(argv[2], "-sdo", sizeof("-sdo")) == 0)) printSDO = TRUE;
if ((argc > 2) && (strncmp(argv[2], "-map", sizeof("-map")) == 0)) printMAP = TRUE;
/* start slaveinfo */
strcpy(ifbuf, argv[1]);
slaveinfo(ifbuf);
do_slaveinfo(argv[1]);
}
else
{

View File

@ -0,0 +1,20 @@
/*
* Licensed under the GNU General Public License version 2 with exceptions. See
* LICENSE file in the project root for full license information
*/
#ifndef _SLAVEINFO_H
#define _SLAVEINFO_H
#ifdef __cplusplus
extern "C"
{
#endif
int slaveinfo(int argc, char *argv[]);
#ifdef __cplusplus
}
#endif
#endif /* _SLAVEINFO_H */