diff --git a/soem/CMakeLists.txt b/soem/CMakeLists.txt index 148ac5a08..faad444c9 100644 --- a/soem/CMakeLists.txt +++ b/soem/CMakeLists.txt @@ -1,24 +1,23 @@ -cmake_minimum_required(VERSION 2.8.4) -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules") -set(CMAKE_OSX_DEPLOYMENT_TARGET "10.9" CACHE STRING "Minimum OS X deployment version") +cmake_minimum_required(VERSION 2.8.12) +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/cmake/Modules") project(SOEM C) 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_CURRENT_LIST_DIR}/install) endif() set(SOEM_INCLUDE_INSTALL_DIR include/soem) set(SOEM_LIB_INSTALL_DIR lib) -set(BUILD_TESTS FALSE) +set(BUILD_TESTS 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) + link_directories(${CMAKE_CURRENT_LIST_DIR}/oshw/win32/wpcap/Lib/x64) elseif(CMAKE_SIZEOF_VOID_P EQUAL 4) - link_directories(${CMAKE_SOURCE_DIR}/oshw/win32/wpcap/Lib) + link_directories(${CMAKE_CURRENT_LIST_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") @@ -61,22 +60,36 @@ file(GLOB SOEM_HEADERS soem/*.h) file(GLOB OSAL_HEADERS osal/osal.h osal/${OS}/*.h) file(GLOB OSHW_HEADERS oshw/${OS}/*.h) -include_directories(soem) -include_directories(osal) -include_directories(osal/${OS}) -include_directories(oshw/${OS}) - add_library(soem STATIC ${SOEM_SOURCES} ${OSAL_SOURCES} ${OSHW_SOURCES} ${OSHW_EXTRA_SOURCES}) -set_property(TARGET soem PROPERTY POSITION_INDEPENDENT_CODE ON) target_link_libraries(soem ${OS_LIBS}) +target_include_directories(soem PUBLIC + $ + $) + +target_include_directories(soem PUBLIC + $ + $) + +target_include_directories(soem PUBLIC + $ + $) + +target_include_directories(soem + PUBLIC $ + $ + ) + message("LIB_DIR: ${SOEM_LIB_INSTALL_DIR}") -install(TARGETS soem DESTINATION ${SOEM_LIB_INSTALL_DIR}) +install(TARGETS soem EXPORT soemConfig DESTINATION ${SOEM_LIB_INSTALL_DIR}) + +install(EXPORT soemConfig DESTINATION share/soem/cmake) + install(FILES ${SOEM_HEADERS} ${OSAL_HEADERS} diff --git a/soem/README.md b/soem/README.md index e9e5cd660..aca9d90e4 100644 --- a/soem/README.md +++ b/soem/README.md @@ -1,6 +1,5 @@ # Simple Open EtherCAT Master Library -[![Build Status](https://travis-ci.org/OpenEtherCATsociety/SOEM.svg?branch=master)](https://travis-ci.org/OpenEtherCATsociety/SOEM) -[![Build status](https://ci.appveyor.com/api/projects/status/bqgirjsxog9k1odf?svg=true)](https://ci.appveyor.com/project/hefloryd/soem-5kq8b) +[![Build Status](https://github.com/OpenEtherCATsociety/SOEM/workflows/build/badge.svg?branch=master)](https://github.com/OpenEtherCATsociety/SOEM/actions?workflow=build) BUILDING ======== diff --git a/soem/appveyor.yml b/soem/appveyor.yml deleted file mode 100644 index 32acdb172..000000000 --- a/soem/appveyor.yml +++ /dev/null @@ -1,10 +0,0 @@ -version: "{build}" - -install: - - cmd: '"C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /x86' - -build_script: - - cmd: mkdir build - - cmd: cd build - - cmd: cmake .. -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release - - cmd: nmake install diff --git a/soem/generateVSSolution.bat b/soem/generateVSSolution.bat deleted file mode 100644 index 1be4f00cc..000000000 --- a/soem/generateVSSolution.bat +++ /dev/null @@ -1,2 +0,0 @@ -@echo off -cmake -H. -Bmsvc64 -G "Visual Studio 14 2015 Win64" \ No newline at end of file diff --git a/soem/linux/install/bin/eepromtool b/soem/linux/install/bin/eepromtool new file mode 100755 index 000000000..e6b057e8c Binary files /dev/null and b/soem/linux/install/bin/eepromtool differ diff --git a/soem/linux/install/bin/simple_test b/soem/linux/install/bin/simple_test new file mode 100755 index 000000000..0d545d6df Binary files /dev/null and b/soem/linux/install/bin/simple_test differ diff --git a/soem/linux/install/bin/slaveinfo b/soem/linux/install/bin/slaveinfo new file mode 100755 index 000000000..791694706 Binary files /dev/null and b/soem/linux/install/bin/slaveinfo differ diff --git a/soem/linux/install/include/soem/ethercatbase.h b/soem/linux/install/include/soem/ethercatbase.h index 2f6a90089..e1ee6876b 100644 --- a/soem/linux/install/include/soem/ethercatbase.h +++ b/soem/linux/install/include/soem/ethercatbase.h @@ -17,7 +17,7 @@ extern "C" #endif int ecx_setupdatagram(ecx_portt *port, void *frame, uint8 com, uint8 idx, uint16 ADP, uint16 ADO, uint16 length, void *data); -int ecx_adddatagram(ecx_portt *port, void *frame, uint8 com, uint8 idx, boolean more, uint16 ADP, uint16 ADO, uint16 length, void *data); +uint16 ecx_adddatagram(ecx_portt *port, void *frame, uint8 com, uint8 idx, boolean more, uint16 ADP, uint16 ADO, uint16 length, void *data); int ecx_BWR(ecx_portt *port, uint16 ADP,uint16 ADO,uint16 length,void *data,int timeout); int ecx_BRD(ecx_portt *port, uint16 ADP,uint16 ADO,uint16 length,void *data,int timeout); int ecx_APRD(ecx_portt *port, uint16 ADP, uint16 ADO, uint16 length, void *data, int timeout); @@ -37,7 +37,7 @@ int ecx_LRWDC(ecx_portt *port, uint32 LogAdr, uint16 length, void *data, uint16 #ifdef EC_VER1 int ec_setupdatagram(void *frame, uint8 com, uint8 idx, uint16 ADP, uint16 ADO, uint16 length, void *data); -int ec_adddatagram(void *frame, uint8 com, uint8 idx, boolean more, uint16 ADP, uint16 ADO, uint16 length, void *data); +uint16 ec_adddatagram(void *frame, uint8 com, uint8 idx, boolean more, uint16 ADP, uint16 ADO, uint16 length, void *data); int ec_BWR(uint16 ADP,uint16 ADO,uint16 length,void *data,int timeout); int ec_BRD(uint16 ADP,uint16 ADO,uint16 length,void *data,int timeout); int ec_APRD(uint16 ADP, uint16 ADO, uint16 length, void *data, int timeout); diff --git a/soem/linux/install/include/soem/ethercatcoe.h b/soem/linux/install/include/soem/ethercatcoe.h index 8a789c853..a237fb8e3 100644 --- a/soem/linux/install/include/soem/ethercatcoe.h +++ b/soem/linux/install/include/soem/ethercatcoe.h @@ -66,8 +66,8 @@ int ec_SDOwrite(uint16 Slave, uint16 Index, uint8 SubIndex, boolean CA, int psize, void *p, int Timeout); int ec_RxPDO(uint16 Slave, uint16 RxPDOnumber , int psize, void *p); int ec_TxPDO(uint16 slave, uint16 TxPDOnumber , int *psize, void *p, int timeout); -int ec_readPDOmap(uint16 Slave, int *Osize, int *Isize); -int ec_readPDOmapCA(uint16 Slave, int Thread_n, int *Osize, int *Isize); +int ec_readPDOmap(uint16 Slave, uint32 *Osize, uint32 *Isize); +int ec_readPDOmapCA(uint16 Slave, int Thread_n, uint32 *Osize, uint32 *Isize); int ec_readODlist(uint16 Slave, ec_ODlistt *pODlist); int ec_readODdescription(uint16 Item, ec_ODlistt *pODlist); int ec_readOEsingle(uint16 Item, uint8 SubI, ec_ODlistt *pODlist, ec_OElistt *pOElist); @@ -81,8 +81,8 @@ int ecx_SDOwrite(ecx_contextt *context, uint16 Slave, uint16 Index, uint8 SubInd boolean CA, int psize, void *p, int Timeout); int ecx_RxPDO(ecx_contextt *context, uint16 Slave, uint16 RxPDOnumber , int psize, void *p); int ecx_TxPDO(ecx_contextt *context, uint16 slave, uint16 TxPDOnumber , int *psize, void *p, int timeout); -int ecx_readPDOmap(ecx_contextt *context, uint16 Slave, int *Osize, int *Isize); -int ecx_readPDOmapCA(ecx_contextt *context, uint16 Slave, int Thread_n, int *Osize, int *Isize); +int ecx_readPDOmap(ecx_contextt *context, uint16 Slave, uint32 *Osize, uint32 *Isize); +int ecx_readPDOmapCA(ecx_contextt *context, uint16 Slave, int Thread_n, uint32 *Osize, uint32 *Isize); int ecx_readODlist(ecx_contextt *context, uint16 Slave, ec_ODlistt *pODlist); int ecx_readODdescription(ecx_contextt *context, uint16 Item, ec_ODlistt *pODlist); int ecx_readOEsingle(ecx_contextt *context, uint16 Item, uint8 SubI, ec_ODlistt *pODlist, ec_OElistt *pOElist); diff --git a/soem/linux/install/include/soem/ethercateoe.h b/soem/linux/install/include/soem/ethercateoe.h index b51739801..930403acb 100644 --- a/soem/linux/install/include/soem/ethercateoe.h +++ b/soem/linux/install/include/soem/ethercateoe.h @@ -16,12 +16,17 @@ extern "C" { #endif -#include +#include "ethercattype.h" + +/* use maximum size for EOE mailbox data */ +#define EC_MAXEOEDATA EC_MAXMBX /** DNS length according to ETG 1000.6 */ #define EOE_DNS_NAME_LENGTH 32 /** Ethernet address length not including VLAN */ #define EOE_ETHADDR_LENGTH 6 +/** IPv4 address length */ +#define EOE_IP4_LENGTH sizeof(uint32_t) #define EOE_MAKEU32(a,b,c,d) (((uint32_t)((a) & 0xff) << 24) | \ ((uint32_t)((b) & 0xff) << 16) | \ @@ -61,7 +66,7 @@ extern "C" #define EOE_HDR_FRAME_TYPE_GET(x) (((x) >> 0) & 0xF) #define EOE_HDR_FRAME_PORT_OFFSET 4 #define EOE_HDR_FRAME_PORT (0xF << 4) -#define EOE_HDR_FRAME_PORT_SET(x) (((x) & 0xF) << 4) +#define EOE_HDR_FRAME_PORT_SET(x) ((uint16)(((x) & 0xF) << 4)) #define EOE_HDR_FRAME_PORT_GET(x) (((x) >> 4) & 0xF) #define EOE_HDR_LAST_FRAGMENT_OFFSET 8 #define EOE_HDR_LAST_FRAGMENT (0x1 << 8) @@ -79,15 +84,15 @@ extern "C" /** Header frame info 2 */ #define EOE_HDR_FRAG_NO_OFFSET 0 #define EOE_HDR_FRAG_NO (0x3F << 0) -#define EOE_HDR_FRAG_NO_SET(x) (((x) & 0x3F) << 0) +#define EOE_HDR_FRAG_NO_SET(x) ((uint16)(((x) & 0x3F) << 0)) #define EOE_HDR_FRAG_NO_GET(x) (((x) >> 0) & 0x3F) #define EOE_HDR_FRAME_OFFSET_OFFSET 6 #define EOE_HDR_FRAME_OFFSET (0x3F << 6) -#define EOE_HDR_FRAME_OFFSET_SET(x) (((x) & 0x3F) << 6) +#define EOE_HDR_FRAME_OFFSET_SET(x) ((uint16)(((x) & 0x3F) << 6)) #define EOE_HDR_FRAME_OFFSET_GET(x) (((x) >> 6) & 0x3F) #define EOE_HDR_FRAME_NO_OFFSET 12 #define EOE_HDR_FRAME_NO (0xF << 12) -#define EOE_HDR_FRAME_NO_SET(x) (((x) & 0xF) << 12) +#define EOE_HDR_FRAME_NO_SET(x) ((uint16)(((x) & 0xF) << 12)) #define EOE_HDR_FRAME_NO_GET(x) (((x) >> 12) & 0xF) /** EOE param */ @@ -163,7 +168,7 @@ typedef struct PACKED uint16_t frameinfo2; uint16_t result; }; - uint8 data[0]; + uint8 data[EC_MAXEOEDATA]; } ec_EOEt; PACKED_END diff --git a/soem/linux/install/include/soem/ethercatmain.h b/soem/linux/install/include/soem/ethercatmain.h index 7001572a0..915b9d428 100644 --- a/soem/linux/install/include/soem/ethercatmain.h +++ b/soem/linux/install/include/soem/ethercatmain.h @@ -340,6 +340,7 @@ typedef struct ec_idxstack uint8 idx[EC_MAXBUF]; void *data[EC_MAXBUF]; uint16 length[EC_MAXBUF]; + uint16 dcoffset[EC_MAXBUF]; } ec_idxstackT; /** ringbuf for error storage */ @@ -407,10 +408,6 @@ struct ecx_context ec_idxstackT *idxstack; /** reference to ecaterror state */ boolean *ecaterror; - /** internal, position of DC datagram in process data packet */ - uint16 DCtO; - /** internal, length of DC datagram */ - uint16 DCl; /** reference to last DC time from slaves */ int64 *DCtime; /** internal, SM buffer */ @@ -429,6 +426,8 @@ struct ecx_context int (*EOEhook)(ecx_contextt * context, uint16 slave, void * eoembx); /** flag to control legacy automatic state change or manual state change */ int manualstatechange; + /** additional misc handle */ + void* misc; }; #ifdef EC_VER1 @@ -456,7 +455,7 @@ void ec_siistring(char *str, uint16 slave, uint16 Sn); uint16 ec_siiFMMU(uint16 slave, ec_eepromFMMUt* FMMU); uint16 ec_siiSM(uint16 slave, ec_eepromSMt* SM); uint16 ec_siiSMnext(uint16 slave, ec_eepromSMt* SM, uint16 n); -int ec_siiPDO(uint16 slave, ec_eepromPDOt* PDO, uint8 t); +uint32 ec_siiPDO(uint16 slave, ec_eepromPDOt* PDO, uint8 t); int ec_readstate(void); int ec_writestate(uint16 slave); uint16 ec_statecheck(uint16 slave, uint16 reqstate, int timeout); @@ -499,7 +498,7 @@ void ecx_siistring(ecx_contextt *context, char *str, uint16 slave, uint16 Sn); uint16 ecx_siiFMMU(ecx_contextt *context, uint16 slave, ec_eepromFMMUt* FMMU); uint16 ecx_siiSM(ecx_contextt *context, uint16 slave, ec_eepromSMt* SM); uint16 ecx_siiSMnext(ecx_contextt *context, uint16 slave, ec_eepromSMt* SM, uint16 n); -int ecx_siiPDO(ecx_contextt *context, uint16 slave, ec_eepromPDOt* PDO, uint8 t); +uint32 ecx_siiPDO(ecx_contextt *context, uint16 slave, ec_eepromPDOt* PDO, uint8 t); int ecx_readstate(ecx_contextt *context); int ecx_writestate(ecx_contextt *context, uint16 slave); uint16 ecx_statecheck(ecx_contextt *context, uint16 slave, uint16 reqstate, int timeout); diff --git a/soem/linux/install/include/soem/ethercatsoe.h b/soem/linux/install/include/soem/ethercatsoe.h index 42de4885e..35d76d146 100644 --- a/soem/linux/install/include/soem/ethercatsoe.h +++ b/soem/linux/install/include/soem/ethercatsoe.h @@ -116,12 +116,12 @@ PACKED_END #ifdef EC_VER1 int ec_SoEread(uint16 slave, uint8 driveNo, uint8 elementflags, uint16 idn, int *psize, void *p, int timeout); int ec_SoEwrite(uint16 slave, uint8 driveNo, uint8 elementflags, uint16 idn, int psize, void *p, int timeout); -int ec_readIDNmap(uint16 slave, int *Osize, int *Isize); +int ec_readIDNmap(uint16 slave, uint32 *Osize, uint32 *Isize); #endif int ecx_SoEread(ecx_contextt *context, uint16 slave, uint8 driveNo, uint8 elementflags, uint16 idn, int *psize, void *p, int timeout); int ecx_SoEwrite(ecx_contextt *context, uint16 slave, uint8 driveNo, uint8 elementflags, uint16 idn, int psize, void *p, int timeout); -int ecx_readIDNmap(ecx_contextt *context, uint16 slave, int *Osize, int *Isize); +int ecx_readIDNmap(ecx_contextt *context, uint16 slave, uint32 *Osize, uint32 *Isize); #ifdef __cplusplus } diff --git a/soem/linux/install/include/soem/ethercattype.h b/soem/linux/install/include/soem/ethercattype.h index 6b4d17cd6..527ccd7ae 100644 --- a/soem/linux/install/include/soem/ethercattype.h +++ b/soem/linux/install/include/soem/ethercattype.h @@ -506,6 +506,10 @@ typedef struct } ec_errort; /** Helper macros */ + +/** Set the count value in the Mailbox header */ +#define MBX_HDR_SET_CNT(cnt) ((uint8)((cnt) << 4)) + /** Macro to make a word from 2 bytes */ #define MK_WORD(msb, lsb) ((((uint16)(msb))<<8) | (lsb)) /** Macro to get hi byte of a word */ diff --git a/soem/linux/install/include/soem/nicdrv.h b/soem/linux/install/include/soem/nicdrv.h index a64af17b1..c2dd209c0 100644 --- a/soem/linux/install/include/soem/nicdrv.h +++ b/soem/linux/install/include/soem/nicdrv.h @@ -76,7 +76,7 @@ typedef struct /** temporary tx buffer length */ int txbuflength2; /** last used frame index */ - int lastidx; + uint8 lastidx; /** current redundancy state */ int redstate; /** pointer to redundancy port and buffers */ @@ -95,23 +95,23 @@ extern ecx_redportt ecx_redport; int ec_setupnic(const char * ifname, int secondary); int ec_closenic(void); -void ec_setbufstat(int idx, int bufstat); -int ec_getindex(void); -int ec_outframe(int idx, int sock); -int ec_outframe_red(int idx); -int ec_waitinframe(int idx, int timeout); -int ec_srconfirm(int idx,int timeout); +void ec_setbufstat(uint8 idx, int bufstat); +uint8 ec_getindex(void); +int ec_outframe(uint8 idx, int sock); +int ec_outframe_red(uint8 idx); +int ec_waitinframe(uint8 idx, int timeout); +int ec_srconfirm(uint8 idx,int timeout); #endif void ec_setupheader(void *p); int ecx_setupnic(ecx_portt *port, const char * ifname, int secondary); int ecx_closenic(ecx_portt *port); -void ecx_setbufstat(ecx_portt *port, int idx, int bufstat); -int ecx_getindex(ecx_portt *port); -int ecx_outframe(ecx_portt *port, int idx, int sock); -int ecx_outframe_red(ecx_portt *port, int idx); -int ecx_waitinframe(ecx_portt *port, int idx, int timeout); -int ecx_srconfirm(ecx_portt *port, int idx,int timeout); +void ecx_setbufstat(ecx_portt *port, uint8 idx, int bufstat); +uint8 ecx_getindex(ecx_portt *port); +int ecx_outframe(ecx_portt *port, uint8 idx, int sock); +int ecx_outframe_red(ecx_portt *port, uint8 idx); +int ecx_waitinframe(ecx_portt *port, uint8 idx, int timeout); +int ecx_srconfirm(ecx_portt *port, uint8 idx,int timeout); #ifdef __cplusplus } diff --git a/soem/linux/install/lib/libsoem.a b/soem/linux/install/lib/libsoem.a index ab4c1dfd3..d5e7dd1dd 100644 Binary files a/soem/linux/install/lib/libsoem.a and b/soem/linux/install/lib/libsoem.a differ diff --git a/soem/linux/install/share/soem/cmake/soemConfig-release.cmake b/soem/linux/install/share/soem/cmake/soemConfig-release.cmake new file mode 100644 index 000000000..59d9f3e80 --- /dev/null +++ b/soem/linux/install/share/soem/cmake/soemConfig-release.cmake @@ -0,0 +1,19 @@ +#---------------------------------------------------------------- +# Generated CMake target import file for configuration "Release". +#---------------------------------------------------------------- + +# Commands may need to know the format version. +set(CMAKE_IMPORT_FILE_VERSION 1) + +# Import target "soem" for configuration "Release" +set_property(TARGET soem APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE) +set_target_properties(soem PROPERTIES + IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "C" + IMPORTED_LOCATION_RELEASE "${_IMPORT_PREFIX}/lib/libsoem.a" + ) + +list(APPEND _IMPORT_CHECK_TARGETS soem ) +list(APPEND _IMPORT_CHECK_FILES_FOR_soem "${_IMPORT_PREFIX}/lib/libsoem.a" ) + +# Commands beyond this point should not need to know the version. +set(CMAKE_IMPORT_FILE_VERSION) diff --git a/soem/linux/install/share/soem/cmake/soemConfig.cmake b/soem/linux/install/share/soem/cmake/soemConfig.cmake new file mode 100644 index 000000000..3f552542c --- /dev/null +++ b/soem/linux/install/share/soem/cmake/soemConfig.cmake @@ -0,0 +1,99 @@ +# Generated by CMake + +if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" LESS 2.5) + message(FATAL_ERROR "CMake >= 2.6.0 required") +endif() +cmake_policy(PUSH) +cmake_policy(VERSION 2.6) +#---------------------------------------------------------------- +# Generated CMake target import file. +#---------------------------------------------------------------- + +# Commands may need to know the format version. +set(CMAKE_IMPORT_FILE_VERSION 1) + +# Protect against multiple inclusion, which would fail when already imported targets are added once more. +set(_targetsDefined) +set(_targetsNotDefined) +set(_expectedTargets) +foreach(_expectedTarget soem) + list(APPEND _expectedTargets ${_expectedTarget}) + if(NOT TARGET ${_expectedTarget}) + list(APPEND _targetsNotDefined ${_expectedTarget}) + endif() + if(TARGET ${_expectedTarget}) + list(APPEND _targetsDefined ${_expectedTarget}) + endif() +endforeach() +if("${_targetsDefined}" STREQUAL "${_expectedTargets}") + unset(_targetsDefined) + unset(_targetsNotDefined) + unset(_expectedTargets) + set(CMAKE_IMPORT_FILE_VERSION) + cmake_policy(POP) + return() +endif() +if(NOT "${_targetsDefined}" STREQUAL "") + message(FATAL_ERROR "Some (but not all) targets in this export set were already defined.\nTargets Defined: ${_targetsDefined}\nTargets not yet defined: ${_targetsNotDefined}\n") +endif() +unset(_targetsDefined) +unset(_targetsNotDefined) +unset(_expectedTargets) + + +# Compute the installation prefix relative to this file. +get_filename_component(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_FILE}" PATH) +get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH) +get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH) +get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH) +if(_IMPORT_PREFIX STREQUAL "/") + set(_IMPORT_PREFIX "") +endif() + +# Create imported target soem +add_library(soem STATIC IMPORTED) + +set_target_properties(soem PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include/soem;${_IMPORT_PREFIX}/include/soem;${_IMPORT_PREFIX}/include/soem;${_IMPORT_PREFIX}/include/soem" + INTERFACE_LINK_LIBRARIES "pthread;rt" +) + +if(CMAKE_VERSION VERSION_LESS 2.8.12) + message(FATAL_ERROR "This file relies on consumers using CMake 2.8.12 or greater.") +endif() + +# Load information for each installed configuration. +get_filename_component(_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) +file(GLOB CONFIG_FILES "${_DIR}/soemConfig-*.cmake") +foreach(f ${CONFIG_FILES}) + include(${f}) +endforeach() + +# Cleanup temporary variables. +set(_IMPORT_PREFIX) + +# Loop over all imported files and verify that they actually exist +foreach(target ${_IMPORT_CHECK_TARGETS} ) + foreach(file ${_IMPORT_CHECK_FILES_FOR_${target}} ) + if(NOT EXISTS "${file}" ) + message(FATAL_ERROR "The imported target \"${target}\" references the file + \"${file}\" +but this file does not exist. Possible reasons include: +* The file was deleted, renamed, or moved to another location. +* An install or uninstall procedure did not complete successfully. +* The installation package was faulty and contained + \"${CMAKE_CURRENT_LIST_FILE}\" +but not all the files it references. +") + endif() + endforeach() + unset(_IMPORT_CHECK_FILES_FOR_${target}) +endforeach() +unset(_IMPORT_CHECK_TARGETS) + +# This file does not depend on other imported targets which have +# been exported from the same project but in a separate export set. + +# Commands beyond this point should not need to know the version. +set(CMAKE_IMPORT_FILE_VERSION) +cmake_policy(POP) diff --git a/soem/msvc/install/bin/eepromtool.exe b/soem/msvc/install/bin/eepromtool.exe index 04d28af7b..088cac977 100644 Binary files a/soem/msvc/install/bin/eepromtool.exe and b/soem/msvc/install/bin/eepromtool.exe differ diff --git a/soem/msvc/install/bin/simple_test.exe b/soem/msvc/install/bin/simple_test.exe index d061a6be7..6b1b887be 100644 Binary files a/soem/msvc/install/bin/simple_test.exe and b/soem/msvc/install/bin/simple_test.exe differ diff --git a/soem/msvc/install/bin/slaveinfo.exe b/soem/msvc/install/bin/slaveinfo.exe index 5b7aee5d8..507f8a3b2 100644 Binary files a/soem/msvc/install/bin/slaveinfo.exe and b/soem/msvc/install/bin/slaveinfo.exe differ diff --git a/soem/msvc/install/include/soem/ethercatbase.h b/soem/msvc/install/include/soem/ethercatbase.h index 2f6a90089..e1ee6876b 100644 --- a/soem/msvc/install/include/soem/ethercatbase.h +++ b/soem/msvc/install/include/soem/ethercatbase.h @@ -17,7 +17,7 @@ extern "C" #endif int ecx_setupdatagram(ecx_portt *port, void *frame, uint8 com, uint8 idx, uint16 ADP, uint16 ADO, uint16 length, void *data); -int ecx_adddatagram(ecx_portt *port, void *frame, uint8 com, uint8 idx, boolean more, uint16 ADP, uint16 ADO, uint16 length, void *data); +uint16 ecx_adddatagram(ecx_portt *port, void *frame, uint8 com, uint8 idx, boolean more, uint16 ADP, uint16 ADO, uint16 length, void *data); int ecx_BWR(ecx_portt *port, uint16 ADP,uint16 ADO,uint16 length,void *data,int timeout); int ecx_BRD(ecx_portt *port, uint16 ADP,uint16 ADO,uint16 length,void *data,int timeout); int ecx_APRD(ecx_portt *port, uint16 ADP, uint16 ADO, uint16 length, void *data, int timeout); @@ -37,7 +37,7 @@ int ecx_LRWDC(ecx_portt *port, uint32 LogAdr, uint16 length, void *data, uint16 #ifdef EC_VER1 int ec_setupdatagram(void *frame, uint8 com, uint8 idx, uint16 ADP, uint16 ADO, uint16 length, void *data); -int ec_adddatagram(void *frame, uint8 com, uint8 idx, boolean more, uint16 ADP, uint16 ADO, uint16 length, void *data); +uint16 ec_adddatagram(void *frame, uint8 com, uint8 idx, boolean more, uint16 ADP, uint16 ADO, uint16 length, void *data); int ec_BWR(uint16 ADP,uint16 ADO,uint16 length,void *data,int timeout); int ec_BRD(uint16 ADP,uint16 ADO,uint16 length,void *data,int timeout); int ec_APRD(uint16 ADP, uint16 ADO, uint16 length, void *data, int timeout); diff --git a/soem/msvc/install/include/soem/ethercatcoe.h b/soem/msvc/install/include/soem/ethercatcoe.h index 8a789c853..a237fb8e3 100644 --- a/soem/msvc/install/include/soem/ethercatcoe.h +++ b/soem/msvc/install/include/soem/ethercatcoe.h @@ -66,8 +66,8 @@ int ec_SDOwrite(uint16 Slave, uint16 Index, uint8 SubIndex, boolean CA, int psize, void *p, int Timeout); int ec_RxPDO(uint16 Slave, uint16 RxPDOnumber , int psize, void *p); int ec_TxPDO(uint16 slave, uint16 TxPDOnumber , int *psize, void *p, int timeout); -int ec_readPDOmap(uint16 Slave, int *Osize, int *Isize); -int ec_readPDOmapCA(uint16 Slave, int Thread_n, int *Osize, int *Isize); +int ec_readPDOmap(uint16 Slave, uint32 *Osize, uint32 *Isize); +int ec_readPDOmapCA(uint16 Slave, int Thread_n, uint32 *Osize, uint32 *Isize); int ec_readODlist(uint16 Slave, ec_ODlistt *pODlist); int ec_readODdescription(uint16 Item, ec_ODlistt *pODlist); int ec_readOEsingle(uint16 Item, uint8 SubI, ec_ODlistt *pODlist, ec_OElistt *pOElist); @@ -81,8 +81,8 @@ int ecx_SDOwrite(ecx_contextt *context, uint16 Slave, uint16 Index, uint8 SubInd boolean CA, int psize, void *p, int Timeout); int ecx_RxPDO(ecx_contextt *context, uint16 Slave, uint16 RxPDOnumber , int psize, void *p); int ecx_TxPDO(ecx_contextt *context, uint16 slave, uint16 TxPDOnumber , int *psize, void *p, int timeout); -int ecx_readPDOmap(ecx_contextt *context, uint16 Slave, int *Osize, int *Isize); -int ecx_readPDOmapCA(ecx_contextt *context, uint16 Slave, int Thread_n, int *Osize, int *Isize); +int ecx_readPDOmap(ecx_contextt *context, uint16 Slave, uint32 *Osize, uint32 *Isize); +int ecx_readPDOmapCA(ecx_contextt *context, uint16 Slave, int Thread_n, uint32 *Osize, uint32 *Isize); int ecx_readODlist(ecx_contextt *context, uint16 Slave, ec_ODlistt *pODlist); int ecx_readODdescription(ecx_contextt *context, uint16 Item, ec_ODlistt *pODlist); int ecx_readOEsingle(ecx_contextt *context, uint16 Item, uint8 SubI, ec_ODlistt *pODlist, ec_OElistt *pOElist); diff --git a/soem/msvc/install/include/soem/ethercateoe.h b/soem/msvc/install/include/soem/ethercateoe.h index b51739801..930403acb 100644 --- a/soem/msvc/install/include/soem/ethercateoe.h +++ b/soem/msvc/install/include/soem/ethercateoe.h @@ -16,12 +16,17 @@ extern "C" { #endif -#include +#include "ethercattype.h" + +/* use maximum size for EOE mailbox data */ +#define EC_MAXEOEDATA EC_MAXMBX /** DNS length according to ETG 1000.6 */ #define EOE_DNS_NAME_LENGTH 32 /** Ethernet address length not including VLAN */ #define EOE_ETHADDR_LENGTH 6 +/** IPv4 address length */ +#define EOE_IP4_LENGTH sizeof(uint32_t) #define EOE_MAKEU32(a,b,c,d) (((uint32_t)((a) & 0xff) << 24) | \ ((uint32_t)((b) & 0xff) << 16) | \ @@ -61,7 +66,7 @@ extern "C" #define EOE_HDR_FRAME_TYPE_GET(x) (((x) >> 0) & 0xF) #define EOE_HDR_FRAME_PORT_OFFSET 4 #define EOE_HDR_FRAME_PORT (0xF << 4) -#define EOE_HDR_FRAME_PORT_SET(x) (((x) & 0xF) << 4) +#define EOE_HDR_FRAME_PORT_SET(x) ((uint16)(((x) & 0xF) << 4)) #define EOE_HDR_FRAME_PORT_GET(x) (((x) >> 4) & 0xF) #define EOE_HDR_LAST_FRAGMENT_OFFSET 8 #define EOE_HDR_LAST_FRAGMENT (0x1 << 8) @@ -79,15 +84,15 @@ extern "C" /** Header frame info 2 */ #define EOE_HDR_FRAG_NO_OFFSET 0 #define EOE_HDR_FRAG_NO (0x3F << 0) -#define EOE_HDR_FRAG_NO_SET(x) (((x) & 0x3F) << 0) +#define EOE_HDR_FRAG_NO_SET(x) ((uint16)(((x) & 0x3F) << 0)) #define EOE_HDR_FRAG_NO_GET(x) (((x) >> 0) & 0x3F) #define EOE_HDR_FRAME_OFFSET_OFFSET 6 #define EOE_HDR_FRAME_OFFSET (0x3F << 6) -#define EOE_HDR_FRAME_OFFSET_SET(x) (((x) & 0x3F) << 6) +#define EOE_HDR_FRAME_OFFSET_SET(x) ((uint16)(((x) & 0x3F) << 6)) #define EOE_HDR_FRAME_OFFSET_GET(x) (((x) >> 6) & 0x3F) #define EOE_HDR_FRAME_NO_OFFSET 12 #define EOE_HDR_FRAME_NO (0xF << 12) -#define EOE_HDR_FRAME_NO_SET(x) (((x) & 0xF) << 12) +#define EOE_HDR_FRAME_NO_SET(x) ((uint16)(((x) & 0xF) << 12)) #define EOE_HDR_FRAME_NO_GET(x) (((x) >> 12) & 0xF) /** EOE param */ @@ -163,7 +168,7 @@ typedef struct PACKED uint16_t frameinfo2; uint16_t result; }; - uint8 data[0]; + uint8 data[EC_MAXEOEDATA]; } ec_EOEt; PACKED_END diff --git a/soem/msvc/install/include/soem/ethercatmain.h b/soem/msvc/install/include/soem/ethercatmain.h index 7001572a0..915b9d428 100644 --- a/soem/msvc/install/include/soem/ethercatmain.h +++ b/soem/msvc/install/include/soem/ethercatmain.h @@ -340,6 +340,7 @@ typedef struct ec_idxstack uint8 idx[EC_MAXBUF]; void *data[EC_MAXBUF]; uint16 length[EC_MAXBUF]; + uint16 dcoffset[EC_MAXBUF]; } ec_idxstackT; /** ringbuf for error storage */ @@ -407,10 +408,6 @@ struct ecx_context ec_idxstackT *idxstack; /** reference to ecaterror state */ boolean *ecaterror; - /** internal, position of DC datagram in process data packet */ - uint16 DCtO; - /** internal, length of DC datagram */ - uint16 DCl; /** reference to last DC time from slaves */ int64 *DCtime; /** internal, SM buffer */ @@ -429,6 +426,8 @@ struct ecx_context int (*EOEhook)(ecx_contextt * context, uint16 slave, void * eoembx); /** flag to control legacy automatic state change or manual state change */ int manualstatechange; + /** additional misc handle */ + void* misc; }; #ifdef EC_VER1 @@ -456,7 +455,7 @@ void ec_siistring(char *str, uint16 slave, uint16 Sn); uint16 ec_siiFMMU(uint16 slave, ec_eepromFMMUt* FMMU); uint16 ec_siiSM(uint16 slave, ec_eepromSMt* SM); uint16 ec_siiSMnext(uint16 slave, ec_eepromSMt* SM, uint16 n); -int ec_siiPDO(uint16 slave, ec_eepromPDOt* PDO, uint8 t); +uint32 ec_siiPDO(uint16 slave, ec_eepromPDOt* PDO, uint8 t); int ec_readstate(void); int ec_writestate(uint16 slave); uint16 ec_statecheck(uint16 slave, uint16 reqstate, int timeout); @@ -499,7 +498,7 @@ void ecx_siistring(ecx_contextt *context, char *str, uint16 slave, uint16 Sn); uint16 ecx_siiFMMU(ecx_contextt *context, uint16 slave, ec_eepromFMMUt* FMMU); uint16 ecx_siiSM(ecx_contextt *context, uint16 slave, ec_eepromSMt* SM); uint16 ecx_siiSMnext(ecx_contextt *context, uint16 slave, ec_eepromSMt* SM, uint16 n); -int ecx_siiPDO(ecx_contextt *context, uint16 slave, ec_eepromPDOt* PDO, uint8 t); +uint32 ecx_siiPDO(ecx_contextt *context, uint16 slave, ec_eepromPDOt* PDO, uint8 t); int ecx_readstate(ecx_contextt *context); int ecx_writestate(ecx_contextt *context, uint16 slave); uint16 ecx_statecheck(ecx_contextt *context, uint16 slave, uint16 reqstate, int timeout); diff --git a/soem/msvc/install/include/soem/ethercatsoe.h b/soem/msvc/install/include/soem/ethercatsoe.h index 42de4885e..35d76d146 100644 --- a/soem/msvc/install/include/soem/ethercatsoe.h +++ b/soem/msvc/install/include/soem/ethercatsoe.h @@ -116,12 +116,12 @@ PACKED_END #ifdef EC_VER1 int ec_SoEread(uint16 slave, uint8 driveNo, uint8 elementflags, uint16 idn, int *psize, void *p, int timeout); int ec_SoEwrite(uint16 slave, uint8 driveNo, uint8 elementflags, uint16 idn, int psize, void *p, int timeout); -int ec_readIDNmap(uint16 slave, int *Osize, int *Isize); +int ec_readIDNmap(uint16 slave, uint32 *Osize, uint32 *Isize); #endif int ecx_SoEread(ecx_contextt *context, uint16 slave, uint8 driveNo, uint8 elementflags, uint16 idn, int *psize, void *p, int timeout); int ecx_SoEwrite(ecx_contextt *context, uint16 slave, uint8 driveNo, uint8 elementflags, uint16 idn, int psize, void *p, int timeout); -int ecx_readIDNmap(ecx_contextt *context, uint16 slave, int *Osize, int *Isize); +int ecx_readIDNmap(ecx_contextt *context, uint16 slave, uint32 *Osize, uint32 *Isize); #ifdef __cplusplus } diff --git a/soem/msvc/install/include/soem/ethercattype.h b/soem/msvc/install/include/soem/ethercattype.h index 6b4d17cd6..527ccd7ae 100644 --- a/soem/msvc/install/include/soem/ethercattype.h +++ b/soem/msvc/install/include/soem/ethercattype.h @@ -506,6 +506,10 @@ typedef struct } ec_errort; /** Helper macros */ + +/** Set the count value in the Mailbox header */ +#define MBX_HDR_SET_CNT(cnt) ((uint8)((cnt) << 4)) + /** Macro to make a word from 2 bytes */ #define MK_WORD(msb, lsb) ((((uint16)(msb))<<8) | (lsb)) /** Macro to get hi byte of a word */ diff --git a/soem/msvc/install/include/soem/nicdrv.h b/soem/msvc/install/include/soem/nicdrv.h index 20d5d519b..32103a3a9 100644 --- a/soem/msvc/install/include/soem/nicdrv.h +++ b/soem/msvc/install/include/soem/nicdrv.h @@ -79,7 +79,7 @@ typedef struct /** temporary tx buffer length */ int txbuflength2; /** last used frame index */ - int lastidx; + uint8 lastidx; /** current redundancy state */ int redstate; /** pointer to redundancy port and buffers */ @@ -98,23 +98,23 @@ extern ecx_redportt ecx_redport; int ec_setupnic(const char * ifname, int secondary); int ec_closenic(void); -void ec_setbufstat(int idx, int bufstat); -int ec_getindex(void); -int ec_outframe(int idx, int sock); -int ec_outframe_red(int idx); -int ec_waitinframe(int idx, int timeout); -int ec_srconfirm(int idx,int timeout); +void ec_setbufstat(uint8 idx, int bufstat); +uint8 ec_getindex(void); +int ec_outframe(uint8 idx, int sock); +int ec_outframe_red(uint8 idx); +int ec_waitinframe(uint8 idx, int timeout); +int ec_srconfirm(uint8 idx,int timeout); #endif void ec_setupheader(void *p); int ecx_setupnic(ecx_portt *port, const char * ifname, int secondary); int ecx_closenic(ecx_portt *port); -void ecx_setbufstat(ecx_portt *port, int idx, int bufstat); -int ecx_getindex(ecx_portt *port); -int ecx_outframe(ecx_portt *port, int idx, int sock); -int ecx_outframe_red(ecx_portt *port, int idx); -int ecx_waitinframe(ecx_portt *port, int idx, int timeout); -int ecx_srconfirm(ecx_portt *port, int idx,int timeout); +void ecx_setbufstat(ecx_portt *port, uint8 idx, int bufstat); +uint8 ecx_getindex(ecx_portt *port); +int ecx_outframe(ecx_portt *port, uint8 idx, int sock); +int ecx_outframe_red(ecx_portt *port, uint8 idx); +int ecx_waitinframe(ecx_portt *port, uint8 idx, int timeout); +int ecx_srconfirm(ecx_portt *port, uint8 idx,int timeout); #ifdef __cplusplus } diff --git a/soem/msvc/install/lib/soem.lib b/soem/msvc/install/lib/soem.lib index 79a505eb6..ff09862ba 100644 Binary files a/soem/msvc/install/lib/soem.lib and b/soem/msvc/install/lib/soem.lib differ diff --git a/soem/msvc/install/share/soem/cmake/soemConfig-release.cmake b/soem/msvc/install/share/soem/cmake/soemConfig-release.cmake new file mode 100644 index 000000000..9d937415a --- /dev/null +++ b/soem/msvc/install/share/soem/cmake/soemConfig-release.cmake @@ -0,0 +1,19 @@ +#---------------------------------------------------------------- +# Generated CMake target import file for configuration "Release". +#---------------------------------------------------------------- + +# Commands may need to know the format version. +set(CMAKE_IMPORT_FILE_VERSION 1) + +# Import target "soem" for configuration "Release" +set_property(TARGET soem APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE) +set_target_properties(soem PROPERTIES + IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "C" + IMPORTED_LOCATION_RELEASE "${_IMPORT_PREFIX}/lib/soem.lib" + ) + +list(APPEND _IMPORT_CHECK_TARGETS soem ) +list(APPEND _IMPORT_CHECK_FILES_FOR_soem "${_IMPORT_PREFIX}/lib/soem.lib" ) + +# Commands beyond this point should not need to know the version. +set(CMAKE_IMPORT_FILE_VERSION) diff --git a/soem/msvc/install/share/soem/cmake/soemConfig.cmake b/soem/msvc/install/share/soem/cmake/soemConfig.cmake new file mode 100644 index 000000000..b99f0cb6d --- /dev/null +++ b/soem/msvc/install/share/soem/cmake/soemConfig.cmake @@ -0,0 +1,99 @@ +# Generated by CMake + +if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" LESS 2.5) + message(FATAL_ERROR "CMake >= 2.6.0 required") +endif() +cmake_policy(PUSH) +cmake_policy(VERSION 2.6) +#---------------------------------------------------------------- +# Generated CMake target import file. +#---------------------------------------------------------------- + +# Commands may need to know the format version. +set(CMAKE_IMPORT_FILE_VERSION 1) + +# Protect against multiple inclusion, which would fail when already imported targets are added once more. +set(_targetsDefined) +set(_targetsNotDefined) +set(_expectedTargets) +foreach(_expectedTarget soem) + list(APPEND _expectedTargets ${_expectedTarget}) + if(NOT TARGET ${_expectedTarget}) + list(APPEND _targetsNotDefined ${_expectedTarget}) + endif() + if(TARGET ${_expectedTarget}) + list(APPEND _targetsDefined ${_expectedTarget}) + endif() +endforeach() +if("${_targetsDefined}" STREQUAL "${_expectedTargets}") + unset(_targetsDefined) + unset(_targetsNotDefined) + unset(_expectedTargets) + set(CMAKE_IMPORT_FILE_VERSION) + cmake_policy(POP) + return() +endif() +if(NOT "${_targetsDefined}" STREQUAL "") + message(FATAL_ERROR "Some (but not all) targets in this export set were already defined.\nTargets Defined: ${_targetsDefined}\nTargets not yet defined: ${_targetsNotDefined}\n") +endif() +unset(_targetsDefined) +unset(_targetsNotDefined) +unset(_expectedTargets) + + +# Compute the installation prefix relative to this file. +get_filename_component(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_FILE}" PATH) +get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH) +get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH) +get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH) +if(_IMPORT_PREFIX STREQUAL "/") + set(_IMPORT_PREFIX "") +endif() + +# Create imported target soem +add_library(soem STATIC IMPORTED) + +set_target_properties(soem PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include/soem;${_IMPORT_PREFIX}/include/soem;${_IMPORT_PREFIX}/include/soem;${_IMPORT_PREFIX}/include/soem" + INTERFACE_LINK_LIBRARIES "wpcap.lib;Packet.lib;Ws2_32.lib;Winmm.lib" +) + +if(CMAKE_VERSION VERSION_LESS 2.8.12) + message(FATAL_ERROR "This file relies on consumers using CMake 2.8.12 or greater.") +endif() + +# Load information for each installed configuration. +get_filename_component(_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) +file(GLOB CONFIG_FILES "${_DIR}/soemConfig-*.cmake") +foreach(f ${CONFIG_FILES}) + include(${f}) +endforeach() + +# Cleanup temporary variables. +set(_IMPORT_PREFIX) + +# Loop over all imported files and verify that they actually exist +foreach(target ${_IMPORT_CHECK_TARGETS} ) + foreach(file ${_IMPORT_CHECK_FILES_FOR_${target}} ) + if(NOT EXISTS "${file}" ) + message(FATAL_ERROR "The imported target \"${target}\" references the file + \"${file}\" +but this file does not exist. Possible reasons include: +* The file was deleted, renamed, or moved to another location. +* An install or uninstall procedure did not complete successfully. +* The installation package was faulty and contained + \"${CMAKE_CURRENT_LIST_FILE}\" +but not all the files it references. +") + endif() + endforeach() + unset(_IMPORT_CHECK_FILES_FOR_${target}) +endforeach() +unset(_IMPORT_CHECK_TARGETS) + +# This file does not depend on other imported targets which have +# been exported from the same project but in a separate export set. + +# Commands beyond this point should not need to know the version. +set(CMAKE_IMPORT_FILE_VERSION) +cmake_policy(POP) diff --git a/soem/oshw/erika/nicdrv.c b/soem/oshw/erika/nicdrv.c index bfe4c7c68..3ef4574b4 100644 --- a/soem/oshw/erika/nicdrv.c +++ b/soem/oshw/erika/nicdrv.c @@ -165,10 +165,10 @@ void ec_setupheader(void *p) * @param[in] port = port context struct * @return new index. */ -int ecx_getindex(ecx_portt *port) +uint8 ecx_getindex(ecx_portt *port) { - int idx; - int cnt = 0; + uint8 idx; + uint8 cnt = 0; ee_port_lock(); @@ -199,7 +199,7 @@ int ecx_getindex(ecx_portt *port) * @param[in] idx = index in buffer array * @param[in] bufstat = status to set */ -void ecx_setbufstat(ecx_portt *port, int idx, int bufstat) +void ecx_setbufstat(ecx_portt *port, uint8 idx, int bufstat) { port->rxbufstat[idx] = bufstat; if (port->redstate != ECT_RED_NONE) @@ -212,7 +212,7 @@ void ecx_setbufstat(ecx_portt *port, int idx, int bufstat) * @param[in] stacknumber = 0=Primary 1=Secondary stack * @return socket send result */ -int ecx_outframe(ecx_portt *port, int idx, int stacknumber) +int ecx_outframe(ecx_portt *port, uint8 idx, int stacknumber) { int lp; ec_stackT *stack; @@ -234,7 +234,7 @@ int ecx_outframe(ecx_portt *port, int idx, int stacknumber) * @param[in] idx = index in tx buffer array * @return socket send result */ -int ecx_outframe_red(ecx_portt *port, int idx) +int ecx_outframe_red(ecx_portt *port, uint8 idx) { ec_comt *datagramP; ec_etherheadert *ehp; @@ -300,11 +300,11 @@ static int ecx_recvpkt(ecx_portt *port, int stacknumber) * @return Workcounter if a frame is found with corresponding index, otherwise * EC_NOFRAME or EC_OTHERFRAME. */ -int ecx_inframe(ecx_portt *port, int idx, int stacknumber) +int ecx_inframe(ecx_portt *port, uint8 idx, int stacknumber) { uint16 l; int rval; - int idxf; + uint8 idxf; ec_etherheadert *ehp; ec_comt *ecp; ec_stackT *stack; @@ -389,7 +389,7 @@ int ecx_inframe(ecx_portt *port, int idx, int stacknumber) * @return Workcounter if a frame is found with corresponding index, otherwise * EC_NOFRAME. */ -static int ecx_waitinframe_red(ecx_portt *port, int idx, osal_timert *timer) +static int ecx_waitinframe_red(ecx_portt *port, uint8 idx, osal_timert *timer) { osal_timert timer2; int wkc = EC_NOFRAME; @@ -464,7 +464,7 @@ static int ecx_waitinframe_red(ecx_portt *port, int idx, osal_timert *timer) * @return Workcounter if a frame is found with corresponding index, otherwise * EC_NOFRAME. */ -int ecx_waitinframe(ecx_portt *port, int idx, int timeout) +int ecx_waitinframe(ecx_portt *port, uint8 idx, int timeout) { int wkc; osal_timert timer; @@ -487,7 +487,7 @@ int ecx_waitinframe(ecx_portt *port, int idx, int timeout) * @param[in] timeout = timeout in us * @return Workcounter or EC_NOFRAME */ -int ecx_srconfirm(ecx_portt *port, int idx, int timeout) +int ecx_srconfirm(ecx_portt *port, uint8 idx, int timeout) { int wkc = EC_NOFRAME; osal_timert timer1, timer2; @@ -529,32 +529,32 @@ int ec_getindex(void) return ecx_getindex(&ecx_port); } -void ec_setbufstat(int idx, int bufstat) +void ec_setbufstat(uint8 idx, int bufstat) { ecx_setbufstat(&ecx_port, idx, bufstat); } -int ec_outframe(int idx, int stacknumber) +int ec_outframe(uint8 idx, int stacknumber) { return ecx_outframe(&ecx_port, idx, stacknumber); } -int ec_outframe_red(int idx) +int ec_outframe_red(uint8 idx) { return ecx_outframe_red(&ecx_port, idx); } -int ec_inframe(int idx, int stacknumber) +int ec_inframe(uint8 idx, int stacknumber) { return ecx_inframe(&ecx_port, idx, stacknumber); } -int ec_waitinframe(int idx, int timeout) +int ec_waitinframe(uint8 idx, int timeout) { return ecx_waitinframe(&ecx_port, idx, timeout); } -int ec_srconfirm(int idx, int timeout) +int ec_srconfirm(uint8 idx, int timeout) { return ecx_srconfirm(&ecx_port, idx, timeout); } diff --git a/soem/oshw/erika/nicdrv.h b/soem/oshw/erika/nicdrv.h index 2398040e5..20e5d8248 100644 --- a/soem/oshw/erika/nicdrv.h +++ b/soem/oshw/erika/nicdrv.h @@ -73,7 +73,7 @@ typedef struct /** temporary tx buffer length */ int txbuflength2; /** last used frame index */ - int lastidx; + uint8 lastidx; /** current redundancy state */ int redstate; /** pointer to redundancy port and buffers */ @@ -94,26 +94,26 @@ extern ecx_redportt ecx_redport; int ec_setupnic(const char * ifname, int secondary); int ec_closenic(void); -void ec_setbufstat(int idx, int bufstat); -int ec_getindex(void); -int ec_outframe(int idx, int sock); -int ec_outframe_red(int idx); -int ec_waitinframe(int idx, int timeout); -int ec_srconfirm(int idx,int timeout); -int ec_inframe(int idx, int stacknumber); +void ec_setbufstat(uint8 idx, int bufstat); +uint8 ec_getindex(void); +int ec_outframe(uint8 idx, int sock); +int ec_outframe_red(uint8 idx); +int ec_waitinframe(uint8 idx, int timeout); +int ec_srconfirm(uint8 idx,int timeout); +int ec_inframe(uint8 idx, int stacknumber); #endif void ec_setupheader(void *p); int ecx_setupnic(ecx_portt *port, const char *ifname, int secondary); int ecx_closenic(ecx_portt *port); -void ecx_setbufstat(ecx_portt *port, int idx, int bufstat); -int ecx_getindex(ecx_portt *port); -int ecx_outframe(ecx_portt *port, int idx, int sock); -int ecx_outframe_red(ecx_portt *port, int idx); -int ecx_waitinframe(ecx_portt *port, int idx, int timeout); -int ecx_srconfirm(ecx_portt *port, int idx,int timeout); +void ecx_setbufstat(ecx_portt *port, uint8 idx, int bufstat); +uint8 ecx_getindex(ecx_portt *port); +int ecx_outframe(ecx_portt *port, uint8 idx, int sock); +int ecx_outframe_red(ecx_portt *port, uint8 idx); +int ecx_waitinframe(ecx_portt *port, uint8 idx, int timeout); +int ecx_srconfirm(ecx_portt *port, uint8 idx,int timeout); -int ecx_inframe(ecx_portt *port, int idx, int stacknumber); +int ecx_inframe(ecx_portt *port, uint8 idx, int stacknumber); #ifdef __cplusplus } diff --git a/soem/oshw/intime/nicdrv.c b/soem/oshw/intime/nicdrv.c index 7cb3516db..a7751d1ee 100644 --- a/soem/oshw/intime/nicdrv.c +++ b/soem/oshw/intime/nicdrv.c @@ -267,10 +267,10 @@ void ec_setupheader(void *p) /** Get new frame identifier index and allocate corresponding rx buffer. * @return new index. */ -int ecx_getindex(ecx_portt *port) +uint8 ecx_getindex(ecx_portt *port) { uint8 idx; - int cnt; + uint8 cnt; WaitForRtControl(port->getindex_region); @@ -307,7 +307,7 @@ int ecx_getindex(ecx_portt *port) * @param[in] idx = index in buffer array * @param[in] bufstat = status to set */ -void ecx_setbufstat(ecx_portt *port, int idx, int bufstat) +void ecx_setbufstat(ecx_portt *port, uint8 idx, int bufstat) { port->rxbufstat[idx] = bufstat; if (port->redstate != ECT_RED_NONE) @@ -321,7 +321,7 @@ void ecx_setbufstat(ecx_portt *port, int idx, int bufstat) * @param[in] stacknumber = 0=Primary 1=Secondary stack * @return socket send result */ -int ecx_outframe(ecx_portt *port, int idx, int stacknumber) +int ecx_outframe(ecx_portt *port, uint8 idx, int stacknumber) { HPESTATUS status; DWORD txstate; @@ -384,7 +384,7 @@ int ecx_outframe(ecx_portt *port, int idx, int stacknumber) * @param[in] idx = index in tx buffer array * @return socket send result */ -int ecx_outframe_red(ecx_portt *port, int idx) +int ecx_outframe_red(ecx_portt *port, uint8 idx) { HPESTATUS status; ec_comt *datagramP; @@ -471,7 +471,7 @@ static int ecx_recvpkt(ecx_portt *port, int stacknumber) * @return Workcounter if a frame is found with corresponding index, otherwise * EC_NOFRAME or EC_OTHERFRAME. */ -int ecx_inframe(ecx_portt *port, int idx, int stacknumber) +int ecx_inframe(ecx_portt *port, uint8 idx, int stacknumber) { uint16 l; int rval; @@ -560,7 +560,7 @@ int ecx_inframe(ecx_portt *port, int idx, int stacknumber) * @return Workcounter if a frame is found with corresponding index, otherwise * EC_NOFRAME. */ -static int ecx_waitinframe_red(ecx_portt *port, int idx, osal_timert *timer) +static int ecx_waitinframe_red(ecx_portt *port, uint8 idx, osal_timert *timer) { osal_timert timer2; int wkc = EC_NOFRAME; @@ -646,7 +646,7 @@ static int ecx_waitinframe_red(ecx_portt *port, int idx, osal_timert *timer) * @return Workcounter if a frame is found with corresponding index, otherwise * EC_NOFRAME. */ -int ecx_waitinframe(ecx_portt *port, int idx, int timeout) +int ecx_waitinframe(ecx_portt *port, uint8 idx, int timeout) { int wkc; osal_timert timer; @@ -681,7 +681,7 @@ int ecx_waitinframe(ecx_portt *port, int idx, int timeout) * @param[in] timeout = timeout in us * @return Workcounter or EC_NOFRAME */ -int ecx_srconfirm(ecx_portt *port, int idx, int timeout) +int ecx_srconfirm(ecx_portt *port, uint8 idx, int timeout) { int wkc = EC_NOFRAME; osal_timert timer1; @@ -706,37 +706,37 @@ int ec_closenic(void) return ecx_closenic(&ecx_port); } -int ec_getindex(void) +uint8 ec_getindex(void) { return ecx_getindex(&ecx_port); } -void ec_setbufstat(int idx, int bufstat) +void ec_setbufstat(uint8 idx, int bufstat) { ecx_setbufstat(&ecx_port, idx, bufstat); } -int ec_outframe(int idx, int stacknumber) +int ec_outframe(uint8 idx, int stacknumber) { return ecx_outframe(&ecx_port, idx, stacknumber); } -int ec_outframe_red(int idx) +int ec_outframe_red(uint8 idx) { return ecx_outframe_red(&ecx_port, idx); } -int ec_inframe(int idx, int stacknumber) +int ec_inframe(uint8 idx, int stacknumber) { return ecx_inframe(&ecx_port, idx, stacknumber); } -int ec_waitinframe(int idx, int timeout) +int ec_waitinframe(uint8 idx, int timeout) { return ecx_waitinframe(&ecx_port, idx, timeout); } -int ec_srconfirm(int idx, int timeout) +int ec_srconfirm(uint8 idx, int timeout) { return ecx_srconfirm(&ecx_port, idx, timeout); } diff --git a/soem/oshw/intime/nicdrv.h b/soem/oshw/intime/nicdrv.h index 7ae8ed309..8802d4eda 100644 --- a/soem/oshw/intime/nicdrv.h +++ b/soem/oshw/intime/nicdrv.h @@ -74,7 +74,7 @@ typedef struct /** temporary tx buffer length */ int txbuflength2; /** last used frame index */ - int lastidx; + uint8 lastidx; /** current redundancy state */ int redstate; /** pointer to redundancy port and buffers */ @@ -97,20 +97,20 @@ extern const uint16 secMAC[3]; int ec_setupnic(const char * ifname, int secondary); int ec_closenic(void); void ec_setupheader(void *p); -void ec_setbufstat(int idx, int bufstat); -int ec_getindex(void); -int ec_outframe(int idx, int sock); -int ec_outframe_red(int idx); -int ec_waitinframe(int idx, int timeout); -int ec_srconfirm(int idx,int timeout); +void ec_setbufstat(uint8 idx, int bufstat); +uint8 ec_getindex(void); +int ec_outframe(uint8 idx, int sock); +int ec_outframe_red(uint8 idx); +int ec_waitinframe(uint8 idx, int timeout); +int ec_srconfirm(uint8 idx,int timeout); int ecx_setupnic(ecx_portt *port, const char * ifname, int secondary); int ecx_closenic(ecx_portt *port); -void ecx_setbufstat(ecx_portt *port, int idx, int bufstat); -int ecx_getindex(ecx_portt *port); -int ecx_outframe(ecx_portt *port, int idx, int sock); -int ecx_outframe_red(ecx_portt *port, int idx); -int ecx_waitinframe(ecx_portt *port, int idx, int timeout); -int ecx_srconfirm(ecx_portt *port, int idx,int timeout); +void ecx_setbufstat(ecx_portt *port, uint8 idx, int bufstat); +uint8 ecx_getindex(ecx_portt *port); +int ecx_outframe(ecx_portt *port, uint8 idx, int sock); +int ecx_outframe_red(ecx_portt *port, uint8 idx); +int ecx_waitinframe(ecx_portt *port, uint8 idx, int timeout); +int ecx_srconfirm(ecx_portt *port, uint8 idx,int timeout); #endif diff --git a/soem/oshw/linux/nicdrv.c b/soem/oshw/linux/nicdrv.c index 6b72a0256..8391bfaf7 100644 --- a/soem/oshw/linux/nicdrv.c +++ b/soem/oshw/linux/nicdrv.c @@ -215,10 +215,10 @@ void ec_setupheader(void *p) * @param[in] port = port context struct * @return new index. */ -int ecx_getindex(ecx_portt *port) +uint8 ecx_getindex(ecx_portt *port) { - int idx; - int cnt; + uint8 idx; + uint8 cnt; pthread_mutex_lock( &(port->getindex_mutex) ); @@ -254,7 +254,7 @@ int ecx_getindex(ecx_portt *port) * @param[in] idx = index in buffer array * @param[in] bufstat = status to set */ -void ecx_setbufstat(ecx_portt *port, int idx, int bufstat) +void ecx_setbufstat(ecx_portt *port, uint8 idx, int bufstat) { port->rxbufstat[idx] = bufstat; if (port->redstate != ECT_RED_NONE) @@ -267,7 +267,7 @@ void ecx_setbufstat(ecx_portt *port, int idx, int bufstat) * @param[in] stacknumber = 0=Primary 1=Secondary stack * @return socket send result */ -int ecx_outframe(ecx_portt *port, int idx, int stacknumber) +int ecx_outframe(ecx_portt *port, uint8 idx, int stacknumber) { int lp, rval; ec_stackT *stack; @@ -296,7 +296,7 @@ int ecx_outframe(ecx_portt *port, int idx, int stacknumber) * @param[in] idx = index in tx buffer array * @return socket send result */ -int ecx_outframe_red(ecx_portt *port, int idx) +int ecx_outframe_red(ecx_portt *port, uint8 idx) { ec_comt *datagramP; ec_etherheadert *ehp; @@ -370,11 +370,11 @@ static int ecx_recvpkt(ecx_portt *port, int stacknumber) * @return Workcounter if a frame is found with corresponding index, otherwise * EC_NOFRAME or EC_OTHERFRAME. */ -int ecx_inframe(ecx_portt *port, int idx, int stacknumber) +int ecx_inframe(ecx_portt *port, uint8 idx, int stacknumber) { uint16 l; int rval; - int idxf; + uint8 idxf; ec_etherheadert *ehp; ec_comt *ecp; ec_stackT *stack; @@ -464,7 +464,7 @@ int ecx_inframe(ecx_portt *port, int idx, int stacknumber) * @return Workcounter if a frame is found with corresponding index, otherwise * EC_NOFRAME. */ -static int ecx_waitinframe_red(ecx_portt *port, int idx, osal_timert *timer) +static int ecx_waitinframe_red(ecx_portt *port, uint8 idx, osal_timert *timer) { osal_timert timer2; int wkc = EC_NOFRAME; @@ -547,7 +547,7 @@ static int ecx_waitinframe_red(ecx_portt *port, int idx, osal_timert *timer) * @return Workcounter if a frame is found with corresponding index, otherwise * EC_NOFRAME. */ -int ecx_waitinframe(ecx_portt *port, int idx, int timeout) +int ecx_waitinframe(ecx_portt *port, uint8 idx, int timeout) { int wkc; osal_timert timer; @@ -570,7 +570,7 @@ int ecx_waitinframe(ecx_portt *port, int idx, int timeout) * @param[in] timeout = timeout in us * @return Workcounter or EC_NOFRAME */ -int ecx_srconfirm(ecx_portt *port, int idx, int timeout) +int ecx_srconfirm(ecx_portt *port, uint8 idx, int timeout) { int wkc = EC_NOFRAME; osal_timert timer1, timer2; @@ -608,37 +608,37 @@ int ec_closenic(void) return ecx_closenic(&ecx_port); } -int ec_getindex(void) +uint8 ec_getindex(void) { return ecx_getindex(&ecx_port); } -void ec_setbufstat(int idx, int bufstat) +void ec_setbufstat(uint8 idx, int bufstat) { ecx_setbufstat(&ecx_port, idx, bufstat); } -int ec_outframe(int idx, int stacknumber) +int ec_outframe(uint8 idx, int stacknumber) { return ecx_outframe(&ecx_port, idx, stacknumber); } -int ec_outframe_red(int idx) +int ec_outframe_red(uint8 idx) { return ecx_outframe_red(&ecx_port, idx); } -int ec_inframe(int idx, int stacknumber) +int ec_inframe(uint8 idx, int stacknumber) { return ecx_inframe(&ecx_port, idx, stacknumber); } -int ec_waitinframe(int idx, int timeout) +int ec_waitinframe(uint8 idx, int timeout) { return ecx_waitinframe(&ecx_port, idx, timeout); } -int ec_srconfirm(int idx, int timeout) +int ec_srconfirm(uint8 idx, int timeout) { return ecx_srconfirm(&ecx_port, idx, timeout); } diff --git a/soem/oshw/linux/nicdrv.h b/soem/oshw/linux/nicdrv.h index a64af17b1..c2dd209c0 100644 --- a/soem/oshw/linux/nicdrv.h +++ b/soem/oshw/linux/nicdrv.h @@ -76,7 +76,7 @@ typedef struct /** temporary tx buffer length */ int txbuflength2; /** last used frame index */ - int lastidx; + uint8 lastidx; /** current redundancy state */ int redstate; /** pointer to redundancy port and buffers */ @@ -95,23 +95,23 @@ extern ecx_redportt ecx_redport; int ec_setupnic(const char * ifname, int secondary); int ec_closenic(void); -void ec_setbufstat(int idx, int bufstat); -int ec_getindex(void); -int ec_outframe(int idx, int sock); -int ec_outframe_red(int idx); -int ec_waitinframe(int idx, int timeout); -int ec_srconfirm(int idx,int timeout); +void ec_setbufstat(uint8 idx, int bufstat); +uint8 ec_getindex(void); +int ec_outframe(uint8 idx, int sock); +int ec_outframe_red(uint8 idx); +int ec_waitinframe(uint8 idx, int timeout); +int ec_srconfirm(uint8 idx,int timeout); #endif void ec_setupheader(void *p); int ecx_setupnic(ecx_portt *port, const char * ifname, int secondary); int ecx_closenic(ecx_portt *port); -void ecx_setbufstat(ecx_portt *port, int idx, int bufstat); -int ecx_getindex(ecx_portt *port); -int ecx_outframe(ecx_portt *port, int idx, int sock); -int ecx_outframe_red(ecx_portt *port, int idx); -int ecx_waitinframe(ecx_portt *port, int idx, int timeout); -int ecx_srconfirm(ecx_portt *port, int idx,int timeout); +void ecx_setbufstat(ecx_portt *port, uint8 idx, int bufstat); +uint8 ecx_getindex(ecx_portt *port); +int ecx_outframe(ecx_portt *port, uint8 idx, int sock); +int ecx_outframe_red(ecx_portt *port, uint8 idx); +int ecx_waitinframe(ecx_portt *port, uint8 idx, int timeout); +int ecx_srconfirm(ecx_portt *port, uint8 idx,int timeout); #ifdef __cplusplus } diff --git a/soem/oshw/linux/oshw.c b/soem/oshw/linux/oshw.c index 4526dfa2c..23f6f1973 100644 --- a/soem/oshw/linux/oshw.c +++ b/soem/oshw/linux/oshw.c @@ -42,7 +42,6 @@ uint16 oshw_ntohs(uint16 network) ec_adaptert * oshw_find_adapters(void) { int i; - int string_len; struct if_nameindex *ids; ec_adaptert * adapter; ec_adaptert * prev_adapter; @@ -75,15 +74,10 @@ ec_adaptert * oshw_find_adapters(void) if (ids[i].if_name) { - string_len = strlen(ids[i].if_name); - if (string_len > (EC_MAXLEN_ADAPTERNAME - 1)) - { - string_len = EC_MAXLEN_ADAPTERNAME - 1; - } - strncpy(adapter->name, ids[i].if_name,string_len); - adapter->name[string_len] = '\0'; - strncpy(adapter->desc, ids[i].if_name,string_len); - adapter->desc[string_len] = '\0'; + strncpy(adapter->name, ids[i].if_name, EC_MAXLEN_ADAPTERNAME); + adapter->name[EC_MAXLEN_ADAPTERNAME-1] = '\0'; + strncpy(adapter->desc, ids[i].if_name, EC_MAXLEN_ADAPTERNAME); + adapter->desc[EC_MAXLEN_ADAPTERNAME-1] = '\0'; } else { diff --git a/soem/oshw/macosx/nicdrv.c b/soem/oshw/macosx/nicdrv.c index d8b99af98..e202bb027 100644 --- a/soem/oshw/macosx/nicdrv.c +++ b/soem/oshw/macosx/nicdrv.c @@ -201,10 +201,10 @@ void ec_setupheader(void *p) * @param[in] port = port context struct * @return new index. */ -int ecx_getindex(ecx_portt *port) +uint8 ecx_getindex(ecx_portt *port) { - int idx; - int cnt; + uint8 idx; + uint8 cnt; pthread_mutex_lock(&(port->getindex_mutex)); @@ -240,7 +240,7 @@ int ecx_getindex(ecx_portt *port) * @param[in] idx = index in buffer array * @param[in] bufstat = status to set */ -void ecx_setbufstat(ecx_portt *port, int idx, int bufstat) +void ecx_setbufstat(ecx_portt *port, uint8 idx, int bufstat) { port->rxbufstat[idx] = bufstat; if (port->redstate != ECT_RED_NONE) @@ -253,7 +253,7 @@ void ecx_setbufstat(ecx_portt *port, int idx, int bufstat) * @param[in] stacknumber = 0=Primary 1=Secondary stack * @return socket send result */ -int ecx_outframe(ecx_portt *port, int idx, int stacknumber) +int ecx_outframe(ecx_portt *port, uint8 idx, int stacknumber) { int lp, rval; ec_stackT *stack; @@ -282,7 +282,7 @@ int ecx_outframe(ecx_portt *port, int idx, int stacknumber) * @param[in] idx = index in tx buffer array * @return socket send result */ -int ecx_outframe_red(ecx_portt *port, int idx) +int ecx_outframe_red(ecx_portt *port, uint8 idx) { ec_comt *datagramP; ec_etherheadert *ehp; @@ -371,11 +371,11 @@ static int ecx_recvpkt(ecx_portt *port, int stacknumber) * @return Workcounter if a frame is found with corresponding index, otherwise * EC_NOFRAME or EC_OTHERFRAME. */ -int ecx_inframe(ecx_portt *port, int idx, int stacknumber) +int ecx_inframe(ecx_portt *port, uint8 idx, int stacknumber) { uint16 l; int rval; - int idxf; + uint8 idxf; ec_etherheadert *ehp; ec_comt *ecp; ec_stackT *stack; @@ -440,7 +440,6 @@ int ecx_inframe(ecx_portt *port, int idx, int stacknumber) } else { - assert(0); /* strange things happened */ } } @@ -466,7 +465,7 @@ int ecx_inframe(ecx_portt *port, int idx, int stacknumber) * @return Workcounter if a frame is found with corresponding index, otherwise * EC_NOFRAME. */ -static int ecx_waitinframe_red(ecx_portt *port, int idx, osal_timert *timer) +static int ecx_waitinframe_red(ecx_portt *port, uint8 idx, osal_timert *timer) { osal_timert timer2; int wkc = EC_NOFRAME; @@ -549,7 +548,7 @@ static int ecx_waitinframe_red(ecx_portt *port, int idx, osal_timert *timer) * @return Workcounter if a frame is found with corresponding index, otherwise * EC_NOFRAME. */ -int ecx_waitinframe(ecx_portt *port, int idx, int timeout) +int ecx_waitinframe(ecx_portt *port, uint8 idx, int timeout) { int wkc; osal_timert timer; @@ -572,7 +571,7 @@ int ecx_waitinframe(ecx_portt *port, int idx, int timeout) * @param[in] timeout = timeout in us * @return Workcounter or EC_NOFRAME */ -int ecx_srconfirm(ecx_portt *port, int idx, int timeout) +int ecx_srconfirm(ecx_portt *port, uint8 idx, int timeout) { int wkc = EC_NOFRAME; osal_timert timer1, timer2; @@ -612,37 +611,37 @@ int ec_closenic(void) return ecx_closenic(&ecx_port); } -int ec_getindex(void) +uint8 ec_getindex(void) { return ecx_getindex(&ecx_port); } -void ec_setbufstat(int idx, int bufstat) +void ec_setbufstat(uint8 idx, int bufstat) { ecx_setbufstat(&ecx_port, idx, bufstat); } -int ec_outframe(int idx, int stacknumber) +int ec_outframe(uint8 idx, int stacknumber) { return ecx_outframe(&ecx_port, idx, stacknumber); } -int ec_outframe_red(int idx) +int ec_outframe_red(uint8 idx) { return ecx_outframe_red(&ecx_port, idx); } -int ec_inframe(int idx, int stacknumber) +int ec_inframe(uint8 idx, int stacknumber) { return ecx_inframe(&ecx_port, idx, stacknumber); } -int ec_waitinframe(int idx, int timeout) +int ec_waitinframe(uint8 idx, int timeout) { return ecx_waitinframe(&ecx_port, idx, timeout); } -int ec_srconfirm(int idx, int timeout) +int ec_srconfirm(uint8 idx, int timeout) { return ecx_srconfirm(&ecx_port, idx, timeout); } diff --git a/soem/oshw/macosx/nicdrv.h b/soem/oshw/macosx/nicdrv.h index 795cf27e1..45ac04ca5 100644 --- a/soem/oshw/macosx/nicdrv.h +++ b/soem/oshw/macosx/nicdrv.h @@ -76,7 +76,7 @@ typedef struct /** temporary tx buffer length */ int txbuflength2; /** last used frame index */ - int lastidx; + uint8 lastidx; /** current redundancy state */ int redstate; /** pointer to redundancy port and buffers */ @@ -95,23 +95,23 @@ extern ecx_redportt ecx_redport; int ec_setupnic(const char * ifname, int secondary); int ec_closenic(void); -void ec_setbufstat(int idx, int bufstat); -int ec_getindex(void); -int ec_outframe(int idx, int sock); -int ec_outframe_red(int idx); -int ec_waitinframe(int idx, int timeout); -int ec_srconfirm(int idx,int timeout); +void ec_setbufstat(uint8 idx, int bufstat); +uint8 ec_getindex(void); +int ec_outframe(uint8 idx, int sock); +int ec_outframe_red(uint8 idx); +int ec_waitinframe(uint8 idx, int timeout); +int ec_srconfirm(uint8 idx,int timeout); #endif void ec_setupheader(void *p); int ecx_setupnic(ecx_portt *port, const char * ifname, int secondary); int ecx_closenic(ecx_portt *port); -void ecx_setbufstat(ecx_portt *port, int idx, int bufstat); -int ecx_getindex(ecx_portt *port); -int ecx_outframe(ecx_portt *port, int idx, int sock); -int ecx_outframe_red(ecx_portt *port, int idx); -int ecx_waitinframe(ecx_portt *port, int idx, int timeout); -int ecx_srconfirm(ecx_portt *port, int idx,int timeout); +void ecx_setbufstat(ecx_portt *port, uint8 idx, int bufstat); +uint8 ecx_getindex(ecx_portt *port); +int ecx_outframe(ecx_portt *port, uint8 idx, int sock); +int ecx_outframe_red(ecx_portt *port, uint8 idx); +int ecx_waitinframe(ecx_portt *port, uint8 idx, int timeout); +int ecx_srconfirm(ecx_portt *port, uint8 idx,int timeout); #ifdef __cplusplus } diff --git a/soem/oshw/macosx/oshw.c b/soem/oshw/macosx/oshw.c index 4526dfa2c..90406ad3d 100644 --- a/soem/oshw/macosx/oshw.c +++ b/soem/oshw/macosx/oshw.c @@ -42,7 +42,6 @@ uint16 oshw_ntohs(uint16 network) ec_adaptert * oshw_find_adapters(void) { int i; - int string_len; struct if_nameindex *ids; ec_adaptert * adapter; ec_adaptert * prev_adapter; @@ -70,20 +69,15 @@ ec_adaptert * oshw_find_adapters(void) ret_adapter = adapter; } - /* fetch description and name, in Linux we use the same on both */ + /* fetch description and name, in macosx we use the same on both */ adapter->next = NULL; if (ids[i].if_name) { - string_len = strlen(ids[i].if_name); - if (string_len > (EC_MAXLEN_ADAPTERNAME - 1)) - { - string_len = EC_MAXLEN_ADAPTERNAME - 1; - } - strncpy(adapter->name, ids[i].if_name,string_len); - adapter->name[string_len] = '\0'; - strncpy(adapter->desc, ids[i].if_name,string_len); - adapter->desc[string_len] = '\0'; + strncpy(adapter->name, ids[i].if_name, EC_MAXLEN_ADAPTERNAME); + adapter->name[EC_MAXLEN_ADAPTERNAME-1] = '\0'; + strncpy(adapter->desc, ids[i].if_name, EC_MAXLEN_ADAPTERNAME); + adapter->desc[EC_MAXLEN_ADAPTERNAME-1] = '\0'; } else { diff --git a/soem/oshw/rtems/nicdrv.c b/soem/oshw/rtems/nicdrv.c index c7cb2da25..b2c9b2fed 100644 --- a/soem/oshw/rtems/nicdrv.c +++ b/soem/oshw/rtems/nicdrv.c @@ -260,10 +260,10 @@ void ec_setupheader(void *p) * @param[in] port = port context struct * @return new index. */ -int ecx_getindex(ecx_portt *port) +uint8 ecx_getindex(ecx_portt *port) { - int idx; - int cnt; + uint8 idx; + uint8 cnt; pthread_mutex_lock( &(port->getindex_mutex) ); @@ -299,7 +299,7 @@ int ecx_getindex(ecx_portt *port) * @param[in] idx = index in buffer array * @param[in] bufstat = status to set */ -void ecx_setbufstat(ecx_portt *port, int idx, int bufstat) +void ecx_setbufstat(ecx_portt *port, uint8 idx, int bufstat) { port->rxbufstat[idx] = bufstat; if (port->redstate != ECT_RED_NONE) @@ -312,7 +312,7 @@ void ecx_setbufstat(ecx_portt *port, int idx, int bufstat) * @param[in] stacknumber = 0=Primary 1=Secondary stack * @return socket send result */ -int ecx_outframe(ecx_portt *port, int idx, int stacknumber) +int ecx_outframe(ecx_portt *port, uint8 idx, int stacknumber) { int lp, rval; ec_stackT *stack; @@ -342,7 +342,7 @@ int ecx_outframe(ecx_portt *port, int idx, int stacknumber) * @param[in] idx = index in tx buffer array * @return socket send result */ -int ecx_outframe_red(ecx_portt *port, int idx) +int ecx_outframe_red(ecx_portt *port, uint8 idx) { ec_comt *datagramP; ec_etherheadert *ehp; @@ -418,11 +418,11 @@ static int ecx_recvpkt(ecx_portt *port, int stacknumber) * @return Workcounter if a frame is found with corresponding index, otherwise * EC_NOFRAME or EC_OTHERFRAME. */ -int ecx_inframe(ecx_portt *port, int idx, int stacknumber) +int ecx_inframe(ecx_portt *port, uint8 idx, int stacknumber) { uint16 l; int rval; - int idxf; + uint8 idxf; ec_etherheadert *ehp; ec_comt *ecp; ec_stackT *stack; @@ -515,7 +515,7 @@ int ecx_inframe(ecx_portt *port, int idx, int stacknumber) * @return Workcounter if a frame is found with corresponding index, otherwise * EC_NOFRAME. */ -static int ecx_waitinframe_red(ecx_portt *port, int idx, osal_timert *timer) +static int ecx_waitinframe_red(ecx_portt *port, uint8 idx, osal_timert *timer) { osal_timert timer2; int wkc = EC_NOFRAME; @@ -598,7 +598,7 @@ static int ecx_waitinframe_red(ecx_portt *port, int idx, osal_timert *timer) * @return Workcounter if a frame is found with corresponding index, otherwise * EC_NOFRAME. */ -int ecx_waitinframe(ecx_portt *port, int idx, int timeout) +int ecx_waitinframe(ecx_portt *port, uint8 idx, int timeout) { int wkc; osal_timert timer; @@ -621,7 +621,7 @@ int ecx_waitinframe(ecx_portt *port, int idx, int timeout) * @param[in] timeout = timeout in us * @return Workcounter or EC_NOFRAME */ -int ecx_srconfirm(ecx_portt *port, int idx, int timeout) +int ecx_srconfirm(ecx_portt *port, uint8 idx, int timeout) { int wkc = EC_NOFRAME; osal_timert timer1, timer2; @@ -659,37 +659,37 @@ int ec_closenic(void) return ecx_closenic(&ecx_port); } -int ec_getindex(void) +uint8 ec_getindex(void) { return ecx_getindex(&ecx_port); } -void ec_setbufstat(int idx, int bufstat) +void ec_setbufstat(uint8 idx, int bufstat) { ecx_setbufstat(&ecx_port, idx, bufstat); } -int ec_outframe(int idx, int stacknumber) +int ec_outframe(uint8 idx, int stacknumber) { return ecx_outframe(&ecx_port, idx, stacknumber); } -int ec_outframe_red(int idx) +int ec_outframe_red(uint8 idx) { return ecx_outframe_red(&ecx_port, idx); } -int ec_inframe(int idx, int stacknumber) +int ec_inframe(uint8 idx, int stacknumber) { return ecx_inframe(&ecx_port, idx, stacknumber); } -int ec_waitinframe(int idx, int timeout) +int ec_waitinframe(uint8 idx, int timeout) { return ecx_waitinframe(&ecx_port, idx, timeout); } -int ec_srconfirm(int idx, int timeout) +int ec_srconfirm(uint8 idx, int timeout) { return ecx_srconfirm(&ecx_port, idx, timeout); } diff --git a/soem/oshw/rtems/nicdrv.h b/soem/oshw/rtems/nicdrv.h index a64af17b1..c2dd209c0 100644 --- a/soem/oshw/rtems/nicdrv.h +++ b/soem/oshw/rtems/nicdrv.h @@ -76,7 +76,7 @@ typedef struct /** temporary tx buffer length */ int txbuflength2; /** last used frame index */ - int lastidx; + uint8 lastidx; /** current redundancy state */ int redstate; /** pointer to redundancy port and buffers */ @@ -95,23 +95,23 @@ extern ecx_redportt ecx_redport; int ec_setupnic(const char * ifname, int secondary); int ec_closenic(void); -void ec_setbufstat(int idx, int bufstat); -int ec_getindex(void); -int ec_outframe(int idx, int sock); -int ec_outframe_red(int idx); -int ec_waitinframe(int idx, int timeout); -int ec_srconfirm(int idx,int timeout); +void ec_setbufstat(uint8 idx, int bufstat); +uint8 ec_getindex(void); +int ec_outframe(uint8 idx, int sock); +int ec_outframe_red(uint8 idx); +int ec_waitinframe(uint8 idx, int timeout); +int ec_srconfirm(uint8 idx,int timeout); #endif void ec_setupheader(void *p); int ecx_setupnic(ecx_portt *port, const char * ifname, int secondary); int ecx_closenic(ecx_portt *port); -void ecx_setbufstat(ecx_portt *port, int idx, int bufstat); -int ecx_getindex(ecx_portt *port); -int ecx_outframe(ecx_portt *port, int idx, int sock); -int ecx_outframe_red(ecx_portt *port, int idx); -int ecx_waitinframe(ecx_portt *port, int idx, int timeout); -int ecx_srconfirm(ecx_portt *port, int idx,int timeout); +void ecx_setbufstat(ecx_portt *port, uint8 idx, int bufstat); +uint8 ecx_getindex(ecx_portt *port); +int ecx_outframe(ecx_portt *port, uint8 idx, int sock); +int ecx_outframe_red(ecx_portt *port, uint8 idx); +int ecx_waitinframe(ecx_portt *port, uint8 idx, int timeout); +int ecx_srconfirm(ecx_portt *port, uint8 idx,int timeout); #ifdef __cplusplus } diff --git a/soem/oshw/rtems/oshw.c b/soem/oshw/rtems/oshw.c index 4526dfa2c..f80757070 100644 --- a/soem/oshw/rtems/oshw.c +++ b/soem/oshw/rtems/oshw.c @@ -42,7 +42,6 @@ uint16 oshw_ntohs(uint16 network) ec_adaptert * oshw_find_adapters(void) { int i; - int string_len; struct if_nameindex *ids; ec_adaptert * adapter; ec_adaptert * prev_adapter; @@ -70,20 +69,15 @@ ec_adaptert * oshw_find_adapters(void) ret_adapter = adapter; } - /* fetch description and name, in Linux we use the same on both */ + /* fetch description and name, in rtems we use the same on both */ adapter->next = NULL; if (ids[i].if_name) { - string_len = strlen(ids[i].if_name); - if (string_len > (EC_MAXLEN_ADAPTERNAME - 1)) - { - string_len = EC_MAXLEN_ADAPTERNAME - 1; - } - strncpy(adapter->name, ids[i].if_name,string_len); - adapter->name[string_len] = '\0'; - strncpy(adapter->desc, ids[i].if_name,string_len); - adapter->desc[string_len] = '\0'; + strncpy(adapter->name, ids[i].if_name, EC_MAXLEN_ADAPTERNAME); + adapter->name[EC_MAXLEN_ADAPTERNAME-1] = '\0'; + strncpy(adapter->desc, ids[i].if_name, EC_MAXLEN_ADAPTERNAME); + adapter->desc[EC_MAXLEN_ADAPTERNAME-1] = '\0'; } else { diff --git a/soem/oshw/rtk/nicdrv.c b/soem/oshw/rtk/nicdrv.c index 537127dbd..5568d8463 100644 --- a/soem/oshw/rtk/nicdrv.c +++ b/soem/oshw/rtk/nicdrv.c @@ -192,10 +192,10 @@ void ec_setupheader(void *p) * @param[in] port = port context struct * @return new index. */ -int ecx_getindex(ecx_portt *port) +uint8 ecx_getindex(ecx_portt *port) { - int idx; - int cnt; + uint8 idx; + uint8 cnt; mtx_lock (port->getindex_mutex); @@ -233,7 +233,7 @@ int ecx_getindex(ecx_portt *port) * @param[in] idx = index in buffer array * @param[in] bufstat = status to set */ -void ecx_setbufstat(ecx_portt *port, int idx, int bufstat) +void ecx_setbufstat(ecx_portt *port, uint8 idx, int bufstat) { port->rxbufstat[idx] = bufstat; if (port->redstate != ECT_RED_NONE) @@ -248,7 +248,7 @@ void ecx_setbufstat(ecx_portt *port, int idx, int bufstat) * @param[in] stacknumber = 0=Primary 1=Secondary stack * @return socket send result */ -int ecx_outframe(ecx_portt *port, int idx, int stacknumber) +int ecx_outframe(ecx_portt *port, uint8 idx, int stacknumber) { int lp, rval; ec_stackT *stack; @@ -273,7 +273,7 @@ int ecx_outframe(ecx_portt *port, int idx, int stacknumber) * @param[in] idx = index in tx buffer array * @return socket send result */ -int ecx_outframe_red(ecx_portt *port, int idx) +int ecx_outframe_red(ecx_portt *port, uint8 idx) { ec_comt *datagramP; ec_etherheadert *ehp; @@ -347,7 +347,7 @@ static int ecx_recvpkt(ecx_portt *port, int stacknumber) * @return Workcounter if a frame is found with corresponding index, otherwise * EC_NOFRAME or EC_OTHERFRAME. */ -int ecx_inframe(ecx_portt *port, int idx, int stacknumber) +int ecx_inframe(ecx_portt *port, uint8 idx, int stacknumber) { uint16 l; int rval; @@ -441,7 +441,7 @@ int ecx_inframe(ecx_portt *port, int idx, int stacknumber) * @return Workcounter if a frame is found with corresponding index, otherwise * EC_NOFRAME. */ -static int ecx_waitinframe_red(ecx_portt *port, int idx, osal_timert timer) +static int ecx_waitinframe_red(ecx_portt *port, uint8 idx, osal_timert timer) { int wkc = EC_NOFRAME; int wkc2 = EC_NOFRAME; @@ -534,7 +534,7 @@ static int ecx_waitinframe_red(ecx_portt *port, int idx, osal_timert timer) * @return Workcounter if a frame is found with corresponding index, otherwise * EC_NOFRAME. */ -int ecx_waitinframe(ecx_portt *port, int idx, int timeout) +int ecx_waitinframe(ecx_portt *port, uint8 idx, int timeout) { int wkc; osal_timert timer; @@ -557,7 +557,7 @@ int ecx_waitinframe(ecx_portt *port, int idx, int timeout) * @param[in] timeout = timeout in us * @return Workcounter or EC_NOFRAME */ -int ecx_srconfirm(ecx_portt *port, int idx, int timeout) +int ecx_srconfirm(ecx_portt *port, uint8 idx, int timeout) { int wkc = EC_NOFRAME; osal_timert timer; @@ -590,37 +590,37 @@ int ec_closenic(void) return ecx_closenic(&ecx_port); } -int ec_getindex(void) +uint8 ec_getindex(void) { return ecx_getindex(&ecx_port); } -void ec_setbufstat(int idx, int bufstat) +void ec_setbufstat(uint8 idx, int bufstat) { ecx_setbufstat(&ecx_port, idx, bufstat); } -int ec_outframe(int idx, int stacknumber) +int ec_outframe(uint8 idx, int stacknumber) { return ecx_outframe(&ecx_port, idx, stacknumber); } -int ec_outframe_red(int idx) +int ec_outframe_red(uint8 idx) { return ecx_outframe_red(&ecx_port, idx); } -int ec_inframe(int idx, int stacknumber) +int ec_inframe(uint8 idx, int stacknumber) { return ecx_inframe(&ecx_port, idx, stacknumber); } -int ec_waitinframe(int idx, int timeout) +int ec_waitinframe(uint8 idx, int timeout) { return ecx_waitinframe(&ecx_port, idx, timeout); } -int ec_srconfirm(int idx, int timeout) +int ec_srconfirm(uint8 idx, int timeout) { return ecx_srconfirm(&ecx_port, idx, timeout); } diff --git a/soem/oshw/rtk/nicdrv.h b/soem/oshw/rtk/nicdrv.h index 900b3f570..b51fab89d 100644 --- a/soem/oshw/rtk/nicdrv.h +++ b/soem/oshw/rtk/nicdrv.h @@ -69,7 +69,7 @@ typedef struct /** temporary tx buffer length */ int txbuflength2; /** last used frame index */ - int lastidx; + uint8 lastidx; /** current redundancy state */ int redstate; /** pointer to redundancy port and buffers */ @@ -88,22 +88,22 @@ extern ecx_redportt ecx_redport; int ec_setupnic(const char * ifname, int secondary); int ec_closenic(void); -void ec_setbufstat(int idx, int bufstat); -int ec_getindex(void); -int ec_outframe(int idx, int stacknumber); -int ec_outframe_red(int idx); -int ec_waitinframe(int idx, int timeout); -int ec_srconfirm(int idx,int timeout); +void ec_setbufstat(uint8 idx, int bufstat); +uint8 ec_getindex(void); +int ec_outframe(uint8 idx, int stacknumber); +int ec_outframe_red(uint8 idx); +int ec_waitinframe(uint8 idx, int timeout); +int ec_srconfirm(uint8 idx,int timeout); #endif void ec_setupheader(void *p); int ecx_setupnic(ecx_portt *port, const char * ifname, int secondary); int ecx_closenic(ecx_portt *port); -void ecx_setbufstat(ecx_portt *port, int idx, int bufstat); -int ecx_getindex(ecx_portt *port); -int ecx_outframe(ecx_portt *port, int idx, int stacknumber); -int ecx_outframe_red(ecx_portt *port, int idx); -int ecx_waitinframe(ecx_portt *port, int idx, int timeout); -int ecx_srconfirm(ecx_portt *port, int idx,int timeout); +void ecx_setbufstat(ecx_portt *port, uint8 idx, int bufstat); +uint8 ecx_getindex(ecx_portt *port); +int ecx_outframe(ecx_portt *port, uint8 idx, int stacknumber); +int ecx_outframe_red(ecx_portt *port, uint8 idx); +int ecx_waitinframe(ecx_portt *port, uint8 idx, int timeout); +int ecx_srconfirm(ecx_portt *port, uint8 idx,int timeout); #endif diff --git a/soem/oshw/vxworks/nicdrv.c b/soem/oshw/vxworks/nicdrv.c index 0e4578790..3e3711802 100644 --- a/soem/oshw/vxworks/nicdrv.c +++ b/soem/oshw/vxworks/nicdrv.c @@ -371,10 +371,10 @@ void ec_setupheader(void *p) * @param[in] port = port context struct * @return new index. */ -int ecx_getindex(ecx_portt *port) +uint8 ecx_getindex(ecx_portt *port) { - int idx; - int cnt; + uint8 idx; + uint8 cnt; semTake(port->sem_get_index, WAIT_FOREVER); @@ -408,7 +408,7 @@ int ecx_getindex(ecx_portt *port) * @param[in] idx = index in buffer array * @param[in] bufstat = status to set */ -void ecx_setbufstat(ecx_portt *port, int idx, int bufstat) +void ecx_setbufstat(ecx_portt *port, uint8 idx, int bufstat) { port->rxbufstat[idx] = bufstat; if (port->redstate != ECT_RED_NONE) @@ -423,7 +423,7 @@ void ecx_setbufstat(ecx_portt *port, int idx, int bufstat) * @param[in] len = bytes to send * @return driver send result */ -static int ec_outfram_send(ETHERCAT_PKT_DEV * pPktDev, int idx, void * buf, int len) +static int ec_outfram_send(ETHERCAT_PKT_DEV * pPktDev, uint8 idx, void * buf, int len) { STATUS status = OK; M_BLK_ID pPacket = NULL; @@ -500,7 +500,7 @@ static int ec_outfram_send(ETHERCAT_PKT_DEV * pPktDev, int idx, void * buf, int * @param[in] stacknumber = 0=Primary 1=Secondary stack * @return socket send result */ -int ecx_outframe(ecx_portt *port, int idx, int stacknumber) +int ecx_outframe(ecx_portt *port, uint8 idx, int stacknumber) { int rval = 0; ec_stackT *stack; @@ -537,7 +537,7 @@ int ecx_outframe(ecx_portt *port, int idx, int stacknumber) * @param[in] idx = index in tx buffer array * @return socket send result */ -int ecx_outframe_red(ecx_portt *port, int idx) +int ecx_outframe_red(ecx_portt *port, uint8 idx) { ec_comt *datagramP; ec_etherheadert *ehp; @@ -581,7 +581,7 @@ int ecx_outframe_red(ecx_portt *port, int idx) static int mux_rx_callback(void* pCookie, long type, M_BLK_ID pMblk, LL_HDR_INFO *llHdrInfo, void *muxUserArg) { BOOL ret = FALSE; - int idxf; + uint8 idxf; ec_comt *ecp; ec_bufT * tempbuf; ecx_portt * port; @@ -678,7 +678,7 @@ static int mux_rx_callback(void* pCookie, long type, M_BLK_ID pMblk, LL_HDR_INFO * @param[in] timeout = timeout in us * @return >0 if frame is available and read */ -static int ecx_recvpkt(ecx_portt *port, int idx, int stacknumber, M_BLK_ID * pMblk, int timeout) +static int ecx_recvpkt(ecx_portt *port, uint8 idx, int stacknumber, M_BLK_ID * pMblk, int timeout) { int bytesrx = 0; MSG_Q_ID msgQId; @@ -728,7 +728,7 @@ static int ecx_recvpkt(ecx_portt *port, int idx, int stacknumber, M_BLK_ID * pMb * @return Workcounter if a frame is found with corresponding index, otherwise * EC_NOFRAME or EC_OTHERFRAME. */ -int ecx_inframe(ecx_portt *port, int idx, int stacknumber, int timeout) +int ecx_inframe(ecx_portt *port, uint8 idx, int stacknumber, int timeout) { uint16 l; int rval; @@ -792,7 +792,7 @@ int ecx_inframe(ecx_portt *port, int idx, int stacknumber, int timeout) * @return Workcounter if a frame is found with corresponding index, otherwise * EC_NOFRAME. */ -static int ecx_waitinframe_red(ecx_portt *port, int idx, osal_timert *timer, int timeout) +static int ecx_waitinframe_red(ecx_portt *port, uint8 idx, osal_timert *timer, int timeout) { osal_timert timer2; int wkc = EC_NOFRAME; @@ -881,7 +881,7 @@ static int ecx_waitinframe_red(ecx_portt *port, int idx, osal_timert *timer, int * @return Workcounter if a frame is found with corresponding index, otherwise * EC_NOFRAME. */ -int ecx_waitinframe(ecx_portt *port, int idx, int timeout) +int ecx_waitinframe(ecx_portt *port, uint8 idx, int timeout) { int wkc; osal_timert timer; @@ -904,7 +904,7 @@ int ecx_waitinframe(ecx_portt *port, int idx, int timeout) * @param[in] timeout = timeout in us * @return Workcounter or EC_NOFRAME */ -int ecx_srconfirm(ecx_portt *port, int idx, int timeout) +int ecx_srconfirm(ecx_portt *port, uint8 idx, int timeout) { int wkc = EC_NOFRAME; osal_timert timer1, timer2; @@ -943,37 +943,37 @@ int ec_closenic(void) return ecx_closenic(&ecx_port); } -int ec_getindex(void) +uint8 ec_getindex(void) { return ecx_getindex(&ecx_port); } -void ec_setbufstat(int idx, int bufstat) +void ec_setbufstat(uint8 idx, int bufstat) { ecx_setbufstat(&ecx_port, idx, bufstat); } -int ec_outframe(int idx, int stacknumber) +int ec_outframe(uint8 idx, int stacknumber) { return ecx_outframe(&ecx_port, idx, stacknumber); } -int ec_outframe_red(int idx) +int ec_outframe_red(uint8 idx) { return ecx_outframe_red(&ecx_port, idx); } -int ec_inframe(int idx, int stacknumber, int timeout) +int ec_inframe(uint8 idx, int stacknumber, int timeout) { return ecx_inframe(&ecx_port, idx, stacknumber, timeout); } -int ec_waitinframe(int idx, int timeout) +int ec_waitinframe(uint8 idx, int timeout) { return ecx_waitinframe(&ecx_port, idx, timeout); } -int ec_srconfirm(int idx, int timeout) +int ec_srconfirm(uint8 idx, int timeout) { return ecx_srconfirm(&ecx_port, idx, timeout); } diff --git a/soem/oshw/vxworks/nicdrv.h b/soem/oshw/vxworks/nicdrv.h index e009399b4..6bb34e539 100644 --- a/soem/oshw/vxworks/nicdrv.h +++ b/soem/oshw/vxworks/nicdrv.h @@ -85,7 +85,7 @@ typedef struct ecx_port /** temporary tx buffer length */ int txbuflength2; /** last used frame index */ - int lastidx; + uint8 lastidx; /** current redundancy state */ int redstate; /** pointer to redundancy port and buffers */ @@ -105,23 +105,23 @@ extern ecx_redportt ecx_redport; int ec_setupnic(const char * ifname, int secondary); int ec_closenic(void); -void ec_setbufstat(int idx, int bufstat); -int ec_getindex(void); -int ec_outframe(int idx, int sock); -int ec_outframe_red(int idx); -int ec_waitinframe(int idx, int timeout); -int ec_srconfirm(int idx,int timeout); +void ec_setbufstat(uint8 idx, int bufstat); +uint8 ec_getindex(void); +int ec_outframe(uint8 idx, int sock); +int ec_outframe_red(uint8 idx); +int ec_waitinframe(uint8 idx, int timeout); +int ec_srconfirm(uint8 idx,int timeout); #endif void ec_setupheader(void *p); int ecx_setupnic(ecx_portt *port, const char * ifname, int secondary); int ecx_closenic(ecx_portt *port); -void ecx_setbufstat(ecx_portt *port, int idx, int bufstat); -int ecx_getindex(ecx_portt *port); -int ecx_outframe(ecx_portt *port, int idx, int sock); -int ecx_outframe_red(ecx_portt *port, int idx); -int ecx_waitinframe(ecx_portt *port, int idx, int timeout); -int ecx_srconfirm(ecx_portt *port, int idx,int timeout); +void ecx_setbufstat(ecx_portt *port, uint8 idx, int bufstat); +uint8 ecx_getindex(ecx_portt *port); +int ecx_outframe(ecx_portt *port, uint8 idx, int sock); +int ecx_outframe_red(ecx_portt *port, uint8 idx); +int ecx_waitinframe(ecx_portt *port, uint8 idx, int timeout); +int ecx_srconfirm(ecx_portt *port, uint8 idx,int timeout); #ifdef __cplusplus } diff --git a/soem/oshw/win32/nicdrv.c b/soem/oshw/win32/nicdrv.c index 598e40795..7c9b11cd8 100644 --- a/soem/oshw/win32/nicdrv.c +++ b/soem/oshw/win32/nicdrv.c @@ -202,10 +202,10 @@ void ec_setupheader(void *p) * @param[in] port = port context struct * @return new index. */ -int ecx_getindex(ecx_portt *port) +uint8 ecx_getindex(ecx_portt *port) { - int idx; - int cnt; + uint8 idx; + uint8 cnt; EnterCriticalSection(&(port->getindex_mutex)); @@ -241,7 +241,7 @@ int ecx_getindex(ecx_portt *port) * @param[in] idx = index in buffer array * @param[in] bufstat = status to set */ -void ecx_setbufstat(ecx_portt *port, int idx, int bufstat) +void ecx_setbufstat(ecx_portt *port, uint8 idx, int bufstat) { port->rxbufstat[idx] = bufstat; if (port->redstate != ECT_RED_NONE) @@ -254,7 +254,7 @@ void ecx_setbufstat(ecx_portt *port, int idx, int bufstat) * @param[in] stacknumber = 0=Primary 1=Secondary stack * @return socket send result */ -int ecx_outframe(ecx_portt *port, int idx, int stacknumber) +int ecx_outframe(ecx_portt *port, uint8 idx, int stacknumber) { int lp, rval; ec_stackT *stack; @@ -283,7 +283,7 @@ int ecx_outframe(ecx_portt *port, int idx, int stacknumber) * @param[in] idx = index in tx buffer array * @return socket send result */ -int ecx_outframe_red(ecx_portt *port, int idx) +int ecx_outframe_red(ecx_portt *port, uint8 idx) { ec_comt *datagramP; ec_etherheadert *ehp; @@ -371,11 +371,11 @@ static int ecx_recvpkt(ecx_portt *port, int stacknumber) * @return Workcounter if a frame is found with corresponding index, otherwise * EC_NOFRAME or EC_OTHERFRAME. */ -int ecx_inframe(ecx_portt *port, int idx, int stacknumber) +int ecx_inframe(ecx_portt *port, uint8 idx, int stacknumber) { uint16 l; int rval; - int idxf; + uint8 idxf; ec_etherheadert *ehp; ec_comt *ecp; ec_stackT *stack; @@ -465,7 +465,7 @@ int ecx_inframe(ecx_portt *port, int idx, int stacknumber) * @return Workcounter if a frame is found with corresponding index, otherwise * EC_NOFRAME. */ -static int ecx_waitinframe_red(ecx_portt *port, int idx, osal_timert *timer) +static int ecx_waitinframe_red(ecx_portt *port, uint8 idx, osal_timert *timer) { osal_timert timer2; int wkc = EC_NOFRAME; @@ -548,7 +548,7 @@ static int ecx_waitinframe_red(ecx_portt *port, int idx, osal_timert *timer) * @return Workcounter if a frame is found with corresponding index, otherwise * EC_NOFRAME. */ -int ecx_waitinframe(ecx_portt *port, int idx, int timeout) +int ecx_waitinframe(ecx_portt *port, uint8 idx, int timeout) { int wkc; osal_timert timer; @@ -571,7 +571,7 @@ int ecx_waitinframe(ecx_portt *port, int idx, int timeout) * @param[in] timeout = timeout in us * @return Workcounter or EC_NOFRAME */ -int ecx_srconfirm(ecx_portt *port, int idx, int timeout) +int ecx_srconfirm(ecx_portt *port, uint8 idx, int timeout) { int wkc = EC_NOFRAME; osal_timert timer1, timer2; @@ -611,37 +611,37 @@ int ec_closenic(void) return ecx_closenic(&ecx_port); } -int ec_getindex(void) +uint8 ec_getindex(void) { return ecx_getindex(&ecx_port); } -void ec_setbufstat(int idx, int bufstat) +void ec_setbufstat(uint8 idx, int bufstat) { ecx_setbufstat(&ecx_port, idx, bufstat); } -int ec_outframe(int idx, int stacknumber) +int ec_outframe(uint8 idx, int stacknumber) { return ecx_outframe(&ecx_port, idx, stacknumber); } -int ec_outframe_red(int idx) +int ec_outframe_red(uint8 idx) { return ecx_outframe_red(&ecx_port, idx); } -int ec_inframe(int idx, int stacknumber) +int ec_inframe(uint8 idx, int stacknumber) { return ecx_inframe(&ecx_port, idx, stacknumber); } -int ec_waitinframe(int idx, int timeout) +int ec_waitinframe(uint8 idx, int timeout) { return ecx_waitinframe(&ecx_port, idx, timeout); } -int ec_srconfirm(int idx, int timeout) +int ec_srconfirm(uint8 idx, int timeout) { return ecx_srconfirm(&ecx_port, idx, timeout); } diff --git a/soem/oshw/win32/nicdrv.h b/soem/oshw/win32/nicdrv.h index 20d5d519b..32103a3a9 100644 --- a/soem/oshw/win32/nicdrv.h +++ b/soem/oshw/win32/nicdrv.h @@ -79,7 +79,7 @@ typedef struct /** temporary tx buffer length */ int txbuflength2; /** last used frame index */ - int lastidx; + uint8 lastidx; /** current redundancy state */ int redstate; /** pointer to redundancy port and buffers */ @@ -98,23 +98,23 @@ extern ecx_redportt ecx_redport; int ec_setupnic(const char * ifname, int secondary); int ec_closenic(void); -void ec_setbufstat(int idx, int bufstat); -int ec_getindex(void); -int ec_outframe(int idx, int sock); -int ec_outframe_red(int idx); -int ec_waitinframe(int idx, int timeout); -int ec_srconfirm(int idx,int timeout); +void ec_setbufstat(uint8 idx, int bufstat); +uint8 ec_getindex(void); +int ec_outframe(uint8 idx, int sock); +int ec_outframe_red(uint8 idx); +int ec_waitinframe(uint8 idx, int timeout); +int ec_srconfirm(uint8 idx,int timeout); #endif void ec_setupheader(void *p); int ecx_setupnic(ecx_portt *port, const char * ifname, int secondary); int ecx_closenic(ecx_portt *port); -void ecx_setbufstat(ecx_portt *port, int idx, int bufstat); -int ecx_getindex(ecx_portt *port); -int ecx_outframe(ecx_portt *port, int idx, int sock); -int ecx_outframe_red(ecx_portt *port, int idx); -int ecx_waitinframe(ecx_portt *port, int idx, int timeout); -int ecx_srconfirm(ecx_portt *port, int idx,int timeout); +void ecx_setbufstat(ecx_portt *port, uint8 idx, int bufstat); +uint8 ecx_getindex(ecx_portt *port); +int ecx_outframe(ecx_portt *port, uint8 idx, int sock); +int ecx_outframe_red(ecx_portt *port, uint8 idx); +int ecx_waitinframe(ecx_portt *port, uint8 idx, int timeout); +int ecx_srconfirm(ecx_portt *port, uint8 idx,int timeout); #ifdef __cplusplus } diff --git a/soem/oshw/win32/oshw.c b/soem/oshw/win32/oshw.c index e58f5faa4..c217baa90 100644 --- a/soem/oshw/win32/oshw.c +++ b/soem/oshw/win32/oshw.c @@ -42,7 +42,6 @@ ec_adaptert * oshw_find_adapters (void) ec_adaptert * prev_adapter; ec_adaptert * ret_adapter = NULL; char errbuf[PCAP_ERRBUF_SIZE]; - size_t string_len; /* find all devices */ if (pcap_findalldevs(&alldevs, errbuf) == -1) @@ -73,13 +72,8 @@ ec_adaptert * oshw_find_adapters (void) adapter->next = NULL; if (d->name) { - string_len = strlen(d->name); - if (string_len > (EC_MAXLEN_ADAPTERNAME - 1)) - { - string_len = EC_MAXLEN_ADAPTERNAME - 1; - } - strncpy(adapter->name, d->name,string_len); - adapter->name[string_len] = '\0'; + strncpy(adapter->name, d->name, EC_MAXLEN_ADAPTERNAME); + adapter->name[EC_MAXLEN_ADAPTERNAME-1] = '\0'; } else { @@ -87,13 +81,8 @@ ec_adaptert * oshw_find_adapters (void) } if (d->description) { - string_len = strlen(d->description); - if (string_len > (EC_MAXLEN_ADAPTERNAME - 1)) - { - string_len = EC_MAXLEN_ADAPTERNAME - 1; - } - strncpy(adapter->desc, d->description,string_len); - adapter->desc[string_len] = '\0'; + strncpy(adapter->desc, d->description, EC_MAXLEN_ADAPTERNAME); + adapter->desc[EC_MAXLEN_ADAPTERNAME-1] = '\0'; } else { diff --git a/soem/osx/install/bin/eepromtool b/soem/osx/install/bin/eepromtool new file mode 100755 index 000000000..cdb1a6fa6 Binary files /dev/null and b/soem/osx/install/bin/eepromtool differ diff --git a/soem/osx/install/bin/simple_test b/soem/osx/install/bin/simple_test new file mode 100755 index 000000000..6f0f08a04 Binary files /dev/null and b/soem/osx/install/bin/simple_test differ diff --git a/soem/osx/install/bin/slaveinfo b/soem/osx/install/bin/slaveinfo new file mode 100755 index 000000000..beb9f6a6a Binary files /dev/null and b/soem/osx/install/bin/slaveinfo differ diff --git a/soem/osx/install/include/soem/ethercatbase.h b/soem/osx/install/include/soem/ethercatbase.h index 2f6a90089..e1ee6876b 100644 --- a/soem/osx/install/include/soem/ethercatbase.h +++ b/soem/osx/install/include/soem/ethercatbase.h @@ -17,7 +17,7 @@ extern "C" #endif int ecx_setupdatagram(ecx_portt *port, void *frame, uint8 com, uint8 idx, uint16 ADP, uint16 ADO, uint16 length, void *data); -int ecx_adddatagram(ecx_portt *port, void *frame, uint8 com, uint8 idx, boolean more, uint16 ADP, uint16 ADO, uint16 length, void *data); +uint16 ecx_adddatagram(ecx_portt *port, void *frame, uint8 com, uint8 idx, boolean more, uint16 ADP, uint16 ADO, uint16 length, void *data); int ecx_BWR(ecx_portt *port, uint16 ADP,uint16 ADO,uint16 length,void *data,int timeout); int ecx_BRD(ecx_portt *port, uint16 ADP,uint16 ADO,uint16 length,void *data,int timeout); int ecx_APRD(ecx_portt *port, uint16 ADP, uint16 ADO, uint16 length, void *data, int timeout); @@ -37,7 +37,7 @@ int ecx_LRWDC(ecx_portt *port, uint32 LogAdr, uint16 length, void *data, uint16 #ifdef EC_VER1 int ec_setupdatagram(void *frame, uint8 com, uint8 idx, uint16 ADP, uint16 ADO, uint16 length, void *data); -int ec_adddatagram(void *frame, uint8 com, uint8 idx, boolean more, uint16 ADP, uint16 ADO, uint16 length, void *data); +uint16 ec_adddatagram(void *frame, uint8 com, uint8 idx, boolean more, uint16 ADP, uint16 ADO, uint16 length, void *data); int ec_BWR(uint16 ADP,uint16 ADO,uint16 length,void *data,int timeout); int ec_BRD(uint16 ADP,uint16 ADO,uint16 length,void *data,int timeout); int ec_APRD(uint16 ADP, uint16 ADO, uint16 length, void *data, int timeout); diff --git a/soem/osx/install/include/soem/ethercatcoe.h b/soem/osx/install/include/soem/ethercatcoe.h index 8a789c853..a237fb8e3 100644 --- a/soem/osx/install/include/soem/ethercatcoe.h +++ b/soem/osx/install/include/soem/ethercatcoe.h @@ -66,8 +66,8 @@ int ec_SDOwrite(uint16 Slave, uint16 Index, uint8 SubIndex, boolean CA, int psize, void *p, int Timeout); int ec_RxPDO(uint16 Slave, uint16 RxPDOnumber , int psize, void *p); int ec_TxPDO(uint16 slave, uint16 TxPDOnumber , int *psize, void *p, int timeout); -int ec_readPDOmap(uint16 Slave, int *Osize, int *Isize); -int ec_readPDOmapCA(uint16 Slave, int Thread_n, int *Osize, int *Isize); +int ec_readPDOmap(uint16 Slave, uint32 *Osize, uint32 *Isize); +int ec_readPDOmapCA(uint16 Slave, int Thread_n, uint32 *Osize, uint32 *Isize); int ec_readODlist(uint16 Slave, ec_ODlistt *pODlist); int ec_readODdescription(uint16 Item, ec_ODlistt *pODlist); int ec_readOEsingle(uint16 Item, uint8 SubI, ec_ODlistt *pODlist, ec_OElistt *pOElist); @@ -81,8 +81,8 @@ int ecx_SDOwrite(ecx_contextt *context, uint16 Slave, uint16 Index, uint8 SubInd boolean CA, int psize, void *p, int Timeout); int ecx_RxPDO(ecx_contextt *context, uint16 Slave, uint16 RxPDOnumber , int psize, void *p); int ecx_TxPDO(ecx_contextt *context, uint16 slave, uint16 TxPDOnumber , int *psize, void *p, int timeout); -int ecx_readPDOmap(ecx_contextt *context, uint16 Slave, int *Osize, int *Isize); -int ecx_readPDOmapCA(ecx_contextt *context, uint16 Slave, int Thread_n, int *Osize, int *Isize); +int ecx_readPDOmap(ecx_contextt *context, uint16 Slave, uint32 *Osize, uint32 *Isize); +int ecx_readPDOmapCA(ecx_contextt *context, uint16 Slave, int Thread_n, uint32 *Osize, uint32 *Isize); int ecx_readODlist(ecx_contextt *context, uint16 Slave, ec_ODlistt *pODlist); int ecx_readODdescription(ecx_contextt *context, uint16 Item, ec_ODlistt *pODlist); int ecx_readOEsingle(ecx_contextt *context, uint16 Item, uint8 SubI, ec_ODlistt *pODlist, ec_OElistt *pOElist); diff --git a/soem/osx/install/include/soem/ethercateoe.h b/soem/osx/install/include/soem/ethercateoe.h index b51739801..930403acb 100644 --- a/soem/osx/install/include/soem/ethercateoe.h +++ b/soem/osx/install/include/soem/ethercateoe.h @@ -16,12 +16,17 @@ extern "C" { #endif -#include +#include "ethercattype.h" + +/* use maximum size for EOE mailbox data */ +#define EC_MAXEOEDATA EC_MAXMBX /** DNS length according to ETG 1000.6 */ #define EOE_DNS_NAME_LENGTH 32 /** Ethernet address length not including VLAN */ #define EOE_ETHADDR_LENGTH 6 +/** IPv4 address length */ +#define EOE_IP4_LENGTH sizeof(uint32_t) #define EOE_MAKEU32(a,b,c,d) (((uint32_t)((a) & 0xff) << 24) | \ ((uint32_t)((b) & 0xff) << 16) | \ @@ -61,7 +66,7 @@ extern "C" #define EOE_HDR_FRAME_TYPE_GET(x) (((x) >> 0) & 0xF) #define EOE_HDR_FRAME_PORT_OFFSET 4 #define EOE_HDR_FRAME_PORT (0xF << 4) -#define EOE_HDR_FRAME_PORT_SET(x) (((x) & 0xF) << 4) +#define EOE_HDR_FRAME_PORT_SET(x) ((uint16)(((x) & 0xF) << 4)) #define EOE_HDR_FRAME_PORT_GET(x) (((x) >> 4) & 0xF) #define EOE_HDR_LAST_FRAGMENT_OFFSET 8 #define EOE_HDR_LAST_FRAGMENT (0x1 << 8) @@ -79,15 +84,15 @@ extern "C" /** Header frame info 2 */ #define EOE_HDR_FRAG_NO_OFFSET 0 #define EOE_HDR_FRAG_NO (0x3F << 0) -#define EOE_HDR_FRAG_NO_SET(x) (((x) & 0x3F) << 0) +#define EOE_HDR_FRAG_NO_SET(x) ((uint16)(((x) & 0x3F) << 0)) #define EOE_HDR_FRAG_NO_GET(x) (((x) >> 0) & 0x3F) #define EOE_HDR_FRAME_OFFSET_OFFSET 6 #define EOE_HDR_FRAME_OFFSET (0x3F << 6) -#define EOE_HDR_FRAME_OFFSET_SET(x) (((x) & 0x3F) << 6) +#define EOE_HDR_FRAME_OFFSET_SET(x) ((uint16)(((x) & 0x3F) << 6)) #define EOE_HDR_FRAME_OFFSET_GET(x) (((x) >> 6) & 0x3F) #define EOE_HDR_FRAME_NO_OFFSET 12 #define EOE_HDR_FRAME_NO (0xF << 12) -#define EOE_HDR_FRAME_NO_SET(x) (((x) & 0xF) << 12) +#define EOE_HDR_FRAME_NO_SET(x) ((uint16)(((x) & 0xF) << 12)) #define EOE_HDR_FRAME_NO_GET(x) (((x) >> 12) & 0xF) /** EOE param */ @@ -163,7 +168,7 @@ typedef struct PACKED uint16_t frameinfo2; uint16_t result; }; - uint8 data[0]; + uint8 data[EC_MAXEOEDATA]; } ec_EOEt; PACKED_END diff --git a/soem/osx/install/include/soem/ethercatmain.h b/soem/osx/install/include/soem/ethercatmain.h index 7001572a0..915b9d428 100644 --- a/soem/osx/install/include/soem/ethercatmain.h +++ b/soem/osx/install/include/soem/ethercatmain.h @@ -340,6 +340,7 @@ typedef struct ec_idxstack uint8 idx[EC_MAXBUF]; void *data[EC_MAXBUF]; uint16 length[EC_MAXBUF]; + uint16 dcoffset[EC_MAXBUF]; } ec_idxstackT; /** ringbuf for error storage */ @@ -407,10 +408,6 @@ struct ecx_context ec_idxstackT *idxstack; /** reference to ecaterror state */ boolean *ecaterror; - /** internal, position of DC datagram in process data packet */ - uint16 DCtO; - /** internal, length of DC datagram */ - uint16 DCl; /** reference to last DC time from slaves */ int64 *DCtime; /** internal, SM buffer */ @@ -429,6 +426,8 @@ struct ecx_context int (*EOEhook)(ecx_contextt * context, uint16 slave, void * eoembx); /** flag to control legacy automatic state change or manual state change */ int manualstatechange; + /** additional misc handle */ + void* misc; }; #ifdef EC_VER1 @@ -456,7 +455,7 @@ void ec_siistring(char *str, uint16 slave, uint16 Sn); uint16 ec_siiFMMU(uint16 slave, ec_eepromFMMUt* FMMU); uint16 ec_siiSM(uint16 slave, ec_eepromSMt* SM); uint16 ec_siiSMnext(uint16 slave, ec_eepromSMt* SM, uint16 n); -int ec_siiPDO(uint16 slave, ec_eepromPDOt* PDO, uint8 t); +uint32 ec_siiPDO(uint16 slave, ec_eepromPDOt* PDO, uint8 t); int ec_readstate(void); int ec_writestate(uint16 slave); uint16 ec_statecheck(uint16 slave, uint16 reqstate, int timeout); @@ -499,7 +498,7 @@ void ecx_siistring(ecx_contextt *context, char *str, uint16 slave, uint16 Sn); uint16 ecx_siiFMMU(ecx_contextt *context, uint16 slave, ec_eepromFMMUt* FMMU); uint16 ecx_siiSM(ecx_contextt *context, uint16 slave, ec_eepromSMt* SM); uint16 ecx_siiSMnext(ecx_contextt *context, uint16 slave, ec_eepromSMt* SM, uint16 n); -int ecx_siiPDO(ecx_contextt *context, uint16 slave, ec_eepromPDOt* PDO, uint8 t); +uint32 ecx_siiPDO(ecx_contextt *context, uint16 slave, ec_eepromPDOt* PDO, uint8 t); int ecx_readstate(ecx_contextt *context); int ecx_writestate(ecx_contextt *context, uint16 slave); uint16 ecx_statecheck(ecx_contextt *context, uint16 slave, uint16 reqstate, int timeout); diff --git a/soem/osx/install/include/soem/ethercatsoe.h b/soem/osx/install/include/soem/ethercatsoe.h index 42de4885e..35d76d146 100644 --- a/soem/osx/install/include/soem/ethercatsoe.h +++ b/soem/osx/install/include/soem/ethercatsoe.h @@ -116,12 +116,12 @@ PACKED_END #ifdef EC_VER1 int ec_SoEread(uint16 slave, uint8 driveNo, uint8 elementflags, uint16 idn, int *psize, void *p, int timeout); int ec_SoEwrite(uint16 slave, uint8 driveNo, uint8 elementflags, uint16 idn, int psize, void *p, int timeout); -int ec_readIDNmap(uint16 slave, int *Osize, int *Isize); +int ec_readIDNmap(uint16 slave, uint32 *Osize, uint32 *Isize); #endif int ecx_SoEread(ecx_contextt *context, uint16 slave, uint8 driveNo, uint8 elementflags, uint16 idn, int *psize, void *p, int timeout); int ecx_SoEwrite(ecx_contextt *context, uint16 slave, uint8 driveNo, uint8 elementflags, uint16 idn, int psize, void *p, int timeout); -int ecx_readIDNmap(ecx_contextt *context, uint16 slave, int *Osize, int *Isize); +int ecx_readIDNmap(ecx_contextt *context, uint16 slave, uint32 *Osize, uint32 *Isize); #ifdef __cplusplus } diff --git a/soem/osx/install/include/soem/ethercattype.h b/soem/osx/install/include/soem/ethercattype.h index 6b4d17cd6..527ccd7ae 100644 --- a/soem/osx/install/include/soem/ethercattype.h +++ b/soem/osx/install/include/soem/ethercattype.h @@ -506,6 +506,10 @@ typedef struct } ec_errort; /** Helper macros */ + +/** Set the count value in the Mailbox header */ +#define MBX_HDR_SET_CNT(cnt) ((uint8)((cnt) << 4)) + /** Macro to make a word from 2 bytes */ #define MK_WORD(msb, lsb) ((((uint16)(msb))<<8) | (lsb)) /** Macro to get hi byte of a word */ diff --git a/soem/osx/install/include/soem/nicdrv.h b/soem/osx/install/include/soem/nicdrv.h index 795cf27e1..45ac04ca5 100644 --- a/soem/osx/install/include/soem/nicdrv.h +++ b/soem/osx/install/include/soem/nicdrv.h @@ -76,7 +76,7 @@ typedef struct /** temporary tx buffer length */ int txbuflength2; /** last used frame index */ - int lastidx; + uint8 lastidx; /** current redundancy state */ int redstate; /** pointer to redundancy port and buffers */ @@ -95,23 +95,23 @@ extern ecx_redportt ecx_redport; int ec_setupnic(const char * ifname, int secondary); int ec_closenic(void); -void ec_setbufstat(int idx, int bufstat); -int ec_getindex(void); -int ec_outframe(int idx, int sock); -int ec_outframe_red(int idx); -int ec_waitinframe(int idx, int timeout); -int ec_srconfirm(int idx,int timeout); +void ec_setbufstat(uint8 idx, int bufstat); +uint8 ec_getindex(void); +int ec_outframe(uint8 idx, int sock); +int ec_outframe_red(uint8 idx); +int ec_waitinframe(uint8 idx, int timeout); +int ec_srconfirm(uint8 idx,int timeout); #endif void ec_setupheader(void *p); int ecx_setupnic(ecx_portt *port, const char * ifname, int secondary); int ecx_closenic(ecx_portt *port); -void ecx_setbufstat(ecx_portt *port, int idx, int bufstat); -int ecx_getindex(ecx_portt *port); -int ecx_outframe(ecx_portt *port, int idx, int sock); -int ecx_outframe_red(ecx_portt *port, int idx); -int ecx_waitinframe(ecx_portt *port, int idx, int timeout); -int ecx_srconfirm(ecx_portt *port, int idx,int timeout); +void ecx_setbufstat(ecx_portt *port, uint8 idx, int bufstat); +uint8 ecx_getindex(ecx_portt *port); +int ecx_outframe(ecx_portt *port, uint8 idx, int sock); +int ecx_outframe_red(ecx_portt *port, uint8 idx); +int ecx_waitinframe(ecx_portt *port, uint8 idx, int timeout); +int ecx_srconfirm(ecx_portt *port, uint8 idx,int timeout); #ifdef __cplusplus } diff --git a/soem/osx/install/lib/libsoem.a b/soem/osx/install/lib/libsoem.a index 829cbeef5..7592bd8fc 100644 Binary files a/soem/osx/install/lib/libsoem.a and b/soem/osx/install/lib/libsoem.a differ diff --git a/soem/osx/install/share/soem/cmake/soemConfig-release.cmake b/soem/osx/install/share/soem/cmake/soemConfig-release.cmake new file mode 100644 index 000000000..59d9f3e80 --- /dev/null +++ b/soem/osx/install/share/soem/cmake/soemConfig-release.cmake @@ -0,0 +1,19 @@ +#---------------------------------------------------------------- +# Generated CMake target import file for configuration "Release". +#---------------------------------------------------------------- + +# Commands may need to know the format version. +set(CMAKE_IMPORT_FILE_VERSION 1) + +# Import target "soem" for configuration "Release" +set_property(TARGET soem APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE) +set_target_properties(soem PROPERTIES + IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "C" + IMPORTED_LOCATION_RELEASE "${_IMPORT_PREFIX}/lib/libsoem.a" + ) + +list(APPEND _IMPORT_CHECK_TARGETS soem ) +list(APPEND _IMPORT_CHECK_FILES_FOR_soem "${_IMPORT_PREFIX}/lib/libsoem.a" ) + +# Commands beyond this point should not need to know the version. +set(CMAKE_IMPORT_FILE_VERSION) diff --git a/soem/osx/install/share/soem/cmake/soemConfig.cmake b/soem/osx/install/share/soem/cmake/soemConfig.cmake new file mode 100644 index 000000000..a2db2bb07 --- /dev/null +++ b/soem/osx/install/share/soem/cmake/soemConfig.cmake @@ -0,0 +1,99 @@ +# Generated by CMake + +if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" LESS 2.5) + message(FATAL_ERROR "CMake >= 2.6.0 required") +endif() +cmake_policy(PUSH) +cmake_policy(VERSION 2.6) +#---------------------------------------------------------------- +# Generated CMake target import file. +#---------------------------------------------------------------- + +# Commands may need to know the format version. +set(CMAKE_IMPORT_FILE_VERSION 1) + +# Protect against multiple inclusion, which would fail when already imported targets are added once more. +set(_targetsDefined) +set(_targetsNotDefined) +set(_expectedTargets) +foreach(_expectedTarget soem) + list(APPEND _expectedTargets ${_expectedTarget}) + if(NOT TARGET ${_expectedTarget}) + list(APPEND _targetsNotDefined ${_expectedTarget}) + endif() + if(TARGET ${_expectedTarget}) + list(APPEND _targetsDefined ${_expectedTarget}) + endif() +endforeach() +if("${_targetsDefined}" STREQUAL "${_expectedTargets}") + unset(_targetsDefined) + unset(_targetsNotDefined) + unset(_expectedTargets) + set(CMAKE_IMPORT_FILE_VERSION) + cmake_policy(POP) + return() +endif() +if(NOT "${_targetsDefined}" STREQUAL "") + message(FATAL_ERROR "Some (but not all) targets in this export set were already defined.\nTargets Defined: ${_targetsDefined}\nTargets not yet defined: ${_targetsNotDefined}\n") +endif() +unset(_targetsDefined) +unset(_targetsNotDefined) +unset(_expectedTargets) + + +# Compute the installation prefix relative to this file. +get_filename_component(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_FILE}" PATH) +get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH) +get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH) +get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH) +if(_IMPORT_PREFIX STREQUAL "/") + set(_IMPORT_PREFIX "") +endif() + +# Create imported target soem +add_library(soem STATIC IMPORTED) + +set_target_properties(soem PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include/soem;${_IMPORT_PREFIX}/include/soem;${_IMPORT_PREFIX}/include/soem;${_IMPORT_PREFIX}/include/soem" + INTERFACE_LINK_LIBRARIES "pthread;pcap" +) + +if(CMAKE_VERSION VERSION_LESS 2.8.12) + message(FATAL_ERROR "This file relies on consumers using CMake 2.8.12 or greater.") +endif() + +# Load information for each installed configuration. +get_filename_component(_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) +file(GLOB CONFIG_FILES "${_DIR}/soemConfig-*.cmake") +foreach(f ${CONFIG_FILES}) + include(${f}) +endforeach() + +# Cleanup temporary variables. +set(_IMPORT_PREFIX) + +# Loop over all imported files and verify that they actually exist +foreach(target ${_IMPORT_CHECK_TARGETS} ) + foreach(file ${_IMPORT_CHECK_FILES_FOR_${target}} ) + if(NOT EXISTS "${file}" ) + message(FATAL_ERROR "The imported target \"${target}\" references the file + \"${file}\" +but this file does not exist. Possible reasons include: +* The file was deleted, renamed, or moved to another location. +* An install or uninstall procedure did not complete successfully. +* The installation package was faulty and contained + \"${CMAKE_CURRENT_LIST_FILE}\" +but not all the files it references. +") + endif() + endforeach() + unset(_IMPORT_CHECK_FILES_FOR_${target}) +endforeach() +unset(_IMPORT_CHECK_TARGETS) + +# This file does not depend on other imported targets which have +# been exported from the same project but in a separate export set. + +# Commands beyond this point should not need to know the version. +set(CMAKE_IMPORT_FILE_VERSION) +cmake_policy(POP) diff --git a/soem/soem/ethercatbase.c b/soem/soem/ethercatbase.c index a3a8510e6..ba9256398 100644 --- a/soem/soem/ethercatbase.c +++ b/soem/soem/ethercatbase.c @@ -103,7 +103,7 @@ int ecx_setupdatagram(ecx_portt *port, void *frame, uint8 com, uint8 idx, uint16 * @param[in] data = databuffer to be copied in datagram * @return Offset to data in rx frame, usefull to retrieve data after RX. */ -int ecx_adddatagram(ecx_portt *port, void *frame, uint8 com, uint8 idx, boolean more, uint16 ADP, uint16 ADO, uint16 length, void *data) +uint16 ecx_adddatagram(ecx_portt *port, void *frame, uint8 com, uint8 idx, boolean more, uint16 ADP, uint16 ADO, uint16 length, void *data) { ec_comt *datagramP; uint8 *frameP; @@ -111,7 +111,7 @@ int ecx_adddatagram(ecx_portt *port, void *frame, uint8 com, uint8 idx, boolean frameP = frame; /* copy previous frame size */ - prevlength = port->txbuflength[idx]; + prevlength = (uint16)port->txbuflength[idx]; datagramP = (ec_comt*)&frameP[ETH_HEADERSIZE]; /* add new datagram to ethernet frame size */ datagramP->elength = htoes( etohs(datagramP->elength) + EC_HEADERSIZE + length ); @@ -541,7 +541,7 @@ int ec_setupdatagram(void *frame, uint8 com, uint8 idx, uint16 ADP, uint16 ADO, return ecx_setupdatagram (&ecx_port, frame, com, idx, ADP, ADO, length, data); } -int ec_adddatagram (void *frame, uint8 com, uint8 idx, boolean more, uint16 ADP, uint16 ADO, uint16 length, void *data) +uint16 ec_adddatagram (void *frame, uint8 com, uint8 idx, boolean more, uint16 ADP, uint16 ADO, uint16 length, void *data) { return ecx_adddatagram (&ecx_port, frame, com, idx, more, ADP, ADO, length, data); } diff --git a/soem/soem/ethercatbase.h b/soem/soem/ethercatbase.h index 2f6a90089..e1ee6876b 100644 --- a/soem/soem/ethercatbase.h +++ b/soem/soem/ethercatbase.h @@ -17,7 +17,7 @@ extern "C" #endif int ecx_setupdatagram(ecx_portt *port, void *frame, uint8 com, uint8 idx, uint16 ADP, uint16 ADO, uint16 length, void *data); -int ecx_adddatagram(ecx_portt *port, void *frame, uint8 com, uint8 idx, boolean more, uint16 ADP, uint16 ADO, uint16 length, void *data); +uint16 ecx_adddatagram(ecx_portt *port, void *frame, uint8 com, uint8 idx, boolean more, uint16 ADP, uint16 ADO, uint16 length, void *data); int ecx_BWR(ecx_portt *port, uint16 ADP,uint16 ADO,uint16 length,void *data,int timeout); int ecx_BRD(ecx_portt *port, uint16 ADP,uint16 ADO,uint16 length,void *data,int timeout); int ecx_APRD(ecx_portt *port, uint16 ADP, uint16 ADO, uint16 length, void *data, int timeout); @@ -37,7 +37,7 @@ int ecx_LRWDC(ecx_portt *port, uint32 LogAdr, uint16 length, void *data, uint16 #ifdef EC_VER1 int ec_setupdatagram(void *frame, uint8 com, uint8 idx, uint16 ADP, uint16 ADO, uint16 length, void *data); -int ec_adddatagram(void *frame, uint8 com, uint8 idx, boolean more, uint16 ADP, uint16 ADO, uint16 length, void *data); +uint16 ec_adddatagram(void *frame, uint8 com, uint8 idx, boolean more, uint16 ADP, uint16 ADO, uint16 length, void *data); int ec_BWR(uint16 ADP,uint16 ADO,uint16 length,void *data,int timeout); int ec_BRD(uint16 ADP,uint16 ADO,uint16 length,void *data,int timeout); int ec_APRD(uint16 ADP, uint16 ADO, uint16 length, void *data, int timeout); diff --git a/soem/soem/ethercatcoe.c b/soem/soem/ethercatcoe.c index 735304d15..e1a9ce3d0 100644 --- a/soem/soem/ethercatcoe.c +++ b/soem/soem/ethercatcoe.c @@ -142,7 +142,7 @@ int ecx_SDOread(ecx_contextt *context, uint16 slave, uint16 index, uint8 subinde /* get new mailbox count value, used as session handle */ cnt = ec_nextmbxcnt(context->slavelist[slave].mbx_cnt); context->slavelist[slave].mbx_cnt = cnt; - SDOp->MbxHeader.mbxtype = ECT_MBXT_COE + (cnt << 4); /* CoE */ + SDOp->MbxHeader.mbxtype = ECT_MBXT_COE + MBX_HDR_SET_CNT(cnt); /* CoE */ SDOp->CANOpen = htoes(0x000 + (ECT_COES_SDOREQ << 12)); /* number 9bits service upper 4 bits (SDO request) */ if (CA) { @@ -218,7 +218,7 @@ int ecx_SDOread(ecx_contextt *context, uint16 slave, uint16 index, uint8 subinde SDOp->MbxHeader.priority = 0x00; cnt = ec_nextmbxcnt(context->slavelist[slave].mbx_cnt); context->slavelist[slave].mbx_cnt = cnt; - SDOp->MbxHeader.mbxtype = ECT_MBXT_COE + (cnt << 4); /* CoE */ + SDOp->MbxHeader.mbxtype = ECT_MBXT_COE + MBX_HDR_SET_CNT(cnt); /* CoE */ SDOp->CANOpen = htoes(0x000 + (ECT_COES_SDOREQ << 12)); /* number 9bits service upper 4 bits (SDO request) */ SDOp->Command = ECT_SDO_SEG_UP_REQ + toggle; /* segment upload request */ SDOp->Index = htoes(index); @@ -331,10 +331,9 @@ int ecx_SDOwrite(ecx_contextt *context, uint16 Slave, uint16 Index, uint8 SubInd boolean CA, int psize, void *p, int Timeout) { ec_SDOt *SDOp, *aSDOp; - int wkc, maxdata; + int wkc, maxdata, framedatasize; ec_mbxbuft MbxIn, MbxOut; uint8 cnt, toggle; - uint16 framedatasize; boolean NotLast; uint8 *hp; @@ -354,7 +353,7 @@ int ecx_SDOwrite(ecx_contextt *context, uint16 Slave, uint16 Index, uint8 SubInd /* get new mailbox counter, used for session handle */ cnt = ec_nextmbxcnt(context->slavelist[Slave].mbx_cnt); context->slavelist[Slave].mbx_cnt = cnt; - SDOp->MbxHeader.mbxtype = ECT_MBXT_COE + (cnt << 4); /* CoE */ + SDOp->MbxHeader.mbxtype = ECT_MBXT_COE + MBX_HDR_SET_CNT(cnt); /* CoE */ SDOp->CANOpen = htoes(0x000 + (ECT_COES_SDOREQ << 12)); /* number 9bits service upper 4 bits */ SDOp->Command = ECT_SDO_DOWN_EXP | (((4 - psize) << 2) & 0x0c); /* expedited SDO download transfer */ SDOp->Index = htoes(Index); @@ -404,13 +403,13 @@ int ecx_SDOwrite(ecx_contextt *context, uint16 Slave, uint16 Index, uint8 SubInd framedatasize = maxdata; /* segmented transfer needed */ NotLast = TRUE; } - SDOp->MbxHeader.length = htoes(0x0a + framedatasize); + SDOp->MbxHeader.length = htoes((uint16)(0x0a + framedatasize)); SDOp->MbxHeader.address = htoes(0x0000); SDOp->MbxHeader.priority = 0x00; /* get new mailbox counter, used for session handle */ cnt = ec_nextmbxcnt(context->slavelist[Slave].mbx_cnt); context->slavelist[Slave].mbx_cnt = cnt; - SDOp->MbxHeader.mbxtype = ECT_MBXT_COE + (cnt << 4); /* CoE */ + SDOp->MbxHeader.mbxtype = ECT_MBXT_COE + MBX_HDR_SET_CNT(cnt); /* CoE */ SDOp->CANOpen = htoes(0x000 + (ECT_COES_SDOREQ << 12)); /* number 9bits service upper 4 bits */ if (CA) { @@ -466,18 +465,18 @@ int ecx_SDOwrite(ecx_contextt *context, uint16 Slave, uint16 Index, uint8 SubInd if (!NotLast && (framedatasize < 7)) { SDOp->MbxHeader.length = htoes(0x0a); /* minimum size */ - SDOp->Command = 0x01 + ((7 - framedatasize) << 1); /* last segment reduced octets */ + SDOp->Command = (uint8)(0x01 + ((7 - framedatasize) << 1)); /* last segment reduced octets */ } else { - SDOp->MbxHeader.length = htoes(framedatasize + 3); /* data + 2 CoE + 1 SDO */ + SDOp->MbxHeader.length = htoes((uint16)(framedatasize + 3)); /* data + 2 CoE + 1 SDO */ } SDOp->MbxHeader.address = htoes(0x0000); SDOp->MbxHeader.priority = 0x00; /* get new mailbox counter value */ cnt = ec_nextmbxcnt(context->slavelist[Slave].mbx_cnt); context->slavelist[Slave].mbx_cnt = cnt; - SDOp->MbxHeader.mbxtype = ECT_MBXT_COE + (cnt << 4); /* CoE */ + SDOp->MbxHeader.mbxtype = ECT_MBXT_COE + MBX_HDR_SET_CNT(cnt); /* CoE */ SDOp->CANOpen = htoes(0x000 + (ECT_COES_SDOREQ << 12)); /* number 9bits service upper 4 bits (SDO request) */ SDOp->Command = SDOp->Command + toggle; /* add toggle bit to command byte */ /* copy parameter data to mailbox */ @@ -552,10 +551,9 @@ int ecx_SDOwrite(ecx_contextt *context, uint16 Slave, uint16 Index, uint8 SubInd int ecx_RxPDO(ecx_contextt *context, uint16 Slave, uint16 RxPDOnumber, int psize, void *p) { ec_SDOt *SDOp; - int wkc, maxdata; + int wkc, maxdata, framedatasize; ec_mbxbuft MbxIn, MbxOut; uint8 cnt; - uint16 framedatasize; ec_clearmbx(&MbxIn); /* Empty slave out mailbox if something is in. Timeout set to 0 */ @@ -568,13 +566,13 @@ int ecx_RxPDO(ecx_contextt *context, uint16 Slave, uint16 RxPDOnumber, int psize { framedatasize = maxdata; /* limit transfer */ } - SDOp->MbxHeader.length = htoes(0x02 + framedatasize); + SDOp->MbxHeader.length = htoes((uint16)(0x02 + framedatasize)); SDOp->MbxHeader.address = htoes(0x0000); SDOp->MbxHeader.priority = 0x00; /* get new mailbox counter, used for session handle */ cnt = ec_nextmbxcnt(context->slavelist[Slave].mbx_cnt); context->slavelist[Slave].mbx_cnt = cnt; - SDOp->MbxHeader.mbxtype = ECT_MBXT_COE + (cnt << 4); /* CoE */ + SDOp->MbxHeader.mbxtype = ECT_MBXT_COE + MBX_HDR_SET_CNT(cnt); /* CoE */ SDOp->CANOpen = htoes((RxPDOnumber & 0x01ff) + (ECT_COES_RXPDO << 12)); /* number 9bits service upper 4 bits */ /* copy PDO data to mailbox */ memcpy(&SDOp->Command, p, framedatasize); @@ -616,7 +614,7 @@ int ecx_TxPDO(ecx_contextt *context, uint16 slave, uint16 TxPDOnumber , int *psi /* get new mailbox counter, used for session handle */ cnt = ec_nextmbxcnt(context->slavelist[slave].mbx_cnt); context->slavelist[slave].mbx_cnt = cnt; - SDOp->MbxHeader.mbxtype = ECT_MBXT_COE + (cnt << 4); /* CoE */ + SDOp->MbxHeader.mbxtype = ECT_MBXT_COE + MBX_HDR_SET_CNT(cnt); /* CoE */ SDOp->CANOpen = htoes((TxPDOnumber & 0x01ff) + (ECT_COES_TXPDO_RR << 12)); /* number 9bits service upper 4 bits */ wkc = ecx_mbxsend(context, slave, (ec_mbxbuft *)&MbxOut, EC_TIMEOUTTXM); if (wkc > 0) @@ -672,12 +670,13 @@ int ecx_TxPDO(ecx_contextt *context, uint16 slave, uint16 TxPDOnumber , int *psi * @param[in] PDOassign = PDO assign object * @return total bitlength of PDO assign */ -int ecx_readPDOassign(ecx_contextt *context, uint16 Slave, uint16 PDOassign) +uint32 ecx_readPDOassign(ecx_contextt *context, uint16 Slave, uint16 PDOassign) { uint16 idxloop, nidx, subidxloop, rdat, idx, subidx; uint8 subcnt; - int wkc, bsize = 0, rdl; + int wkc, rdl; int32 rdat2; + uint32 bsize = 0; rdl = sizeof(rdat); rdat = 0; /* read PDO assign subindex 0 ( = number of PDO's) */ @@ -737,11 +736,12 @@ int ecx_readPDOassign(ecx_contextt *context, uint16 Slave, uint16 PDOassign) * @param[in] PDOassign = PDO assign object * @return total bitlength of PDO assign */ -int ecx_readPDOassignCA(ecx_contextt *context, uint16 Slave, int Thread_n, +uint32 ecx_readPDOassignCA(ecx_contextt *context, uint16 Slave, int Thread_n, uint16 PDOassign) { uint16 idxloop, nidx, subidxloop, idx, subidx; - int wkc, bsize = 0, rdl; + int wkc, rdl; + uint32 bsize = 0; /* find maximum size of PDOassign buffer */ rdl = sizeof(ec_PDOassignt); @@ -807,12 +807,12 @@ int ecx_readPDOassignCA(ecx_contextt *context, uint16 Slave, int Thread_n, * @param[out] Isize = Size in bits of input mapping (txPDO) found * @return >0 if mapping successful. */ -int ecx_readPDOmap(ecx_contextt *context, uint16 Slave, int *Osize, int *Isize) +int ecx_readPDOmap(ecx_contextt *context, uint16 Slave, uint32 *Osize, uint32 *Isize) { int wkc, rdl; int retVal = 0; uint8 nSM, iSM, tSM; - int Tsize; + uint32 Tsize; uint8 SMt_bug_add; *Isize = 0; @@ -868,7 +868,7 @@ int ecx_readPDOmap(ecx_contextt *context, uint16 Slave, int *Osize, int *Isize) /* if a mapping is found */ if (Tsize) { - context->slavelist[Slave].SM[iSM].SMlength = htoes((Tsize + 7) / 8); + context->slavelist[Slave].SM[iSM].SMlength = htoes((uint16)((Tsize + 7) / 8)); if (tSM == 3) { /* we are doing outputs */ @@ -907,12 +907,12 @@ int ecx_readPDOmap(ecx_contextt *context, uint16 Slave, int *Osize, int *Isize) * @param[out] Isize = Size in bits of input mapping (txPDO) found * @return >0 if mapping successful. */ -int ecx_readPDOmapCA(ecx_contextt *context, uint16 Slave, int Thread_n, int *Osize, int *Isize) +int ecx_readPDOmapCA(ecx_contextt *context, uint16 Slave, int Thread_n, uint32 *Osize, uint32 *Isize) { int wkc, rdl; int retVal = 0; uint8 nSM, iSM, tSM; - int Tsize; + uint32 Tsize; uint8 SMt_bug_add; *Isize = 0; @@ -964,7 +964,7 @@ int ecx_readPDOmapCA(ecx_contextt *context, uint16 Slave, int Thread_n, int *Osi /* if a mapping is found */ if (Tsize) { - context->slavelist[Slave].SM[iSM].SMlength = htoes((Tsize + 7) / 8); + context->slavelist[Slave].SM[iSM].SMlength = htoes((uint16)((Tsize + 7) / 8)); if (tSM == 3) { /* we are doing outputs */ @@ -1019,7 +1019,7 @@ int ecx_readODlist(ecx_contextt *context, uint16 Slave, ec_ODlistt *pODlist) /* Get new mailbox counter value */ cnt = ec_nextmbxcnt(context->slavelist[Slave].mbx_cnt); context->slavelist[Slave].mbx_cnt = cnt; - SDOp->MbxHeader.mbxtype = ECT_MBXT_COE + (cnt << 4); /* CoE */ + SDOp->MbxHeader.mbxtype = ECT_MBXT_COE + MBX_HDR_SET_CNT(cnt); /* CoE */ SDOp->CANOpen = htoes(0x000 + (ECT_COES_SDOINFO << 12)); /* number 9bits service upper 4 bits */ SDOp->Opcode = ECT_GET_ODLIST_REQ; /* get object description list request */ SDOp->Reserved = 0; @@ -1139,7 +1139,7 @@ int ecx_readODdescription(ecx_contextt *context, uint16 Item, ec_ODlistt *pODlis /* Get new mailbox counter value */ cnt = ec_nextmbxcnt(context->slavelist[Slave].mbx_cnt); context->slavelist[Slave].mbx_cnt = cnt; - SDOp->MbxHeader.mbxtype = ECT_MBXT_COE + (cnt << 4); /* CoE */ + SDOp->MbxHeader.mbxtype = ECT_MBXT_COE + MBX_HDR_SET_CNT(cnt); /* CoE */ SDOp->CANOpen = htoes(0x000 + (ECT_COES_SDOINFO << 12)); /* number 9bits service upper 4 bits */ SDOp->Opcode = ECT_GET_OD_REQ; /* get object description request */ SDOp->Reserved = 0; @@ -1224,7 +1224,7 @@ int ecx_readOEsingle(ecx_contextt *context, uint16 Item, uint8 SubI, ec_ODlistt /* Get new mailbox counter value */ cnt = ec_nextmbxcnt(context->slavelist[Slave].mbx_cnt); context->slavelist[Slave].mbx_cnt = cnt; - SDOp->MbxHeader.mbxtype = ECT_MBXT_COE + (cnt << 4); /* CoE */ + SDOp->MbxHeader.mbxtype = ECT_MBXT_COE + MBX_HDR_SET_CNT(cnt); /* CoE */ SDOp->CANOpen = htoes(0x000 + (ECT_COES_SDOINFO << 12)); /* number 9bits service upper 4 bits */ SDOp->Opcode = ECT_GET_OE_REQ; /* get object entry description request */ SDOp->Reserved = 0; @@ -1408,7 +1408,7 @@ int ec_TxPDO(uint16 slave, uint16 TxPDOnumber , int *psize, void *p, int timeout * @param[in] PDOassign = PDO assign object * @return total bitlength of PDO assign */ -int ec_readPDOassign(uint16 Slave, uint16 PDOassign) +uint32 ec_readPDOassign(uint16 Slave, uint16 PDOassign) { return ecx_readPDOassign(&ecx_context, Slave, PDOassign); } @@ -1420,7 +1420,7 @@ int ec_readPDOassign(uint16 Slave, uint16 PDOassign) * @return total bitlength of PDO assign * @see ecx_readPDOmap */ -int ec_readPDOassignCA(uint16 Slave, uint16 PDOassign, int Thread_n) +uint32 ec_readPDOassignCA(uint16 Slave, uint16 PDOassign, int Thread_n) { return ecx_readPDOassignCA(&ecx_context, Slave, Thread_n, PDOassign); } @@ -1438,7 +1438,7 @@ int ec_readPDOassignCA(uint16 Slave, uint16 PDOassign, int Thread_n) * @param[out] Isize = Size in bits of input mapping (txPDO) found * @return >0 if mapping succesful. */ -int ec_readPDOmap(uint16 Slave, int *Osize, int *Isize) +int ec_readPDOmap(uint16 Slave, uint32 *Osize, uint32 *Isize) { return ecx_readPDOmap(&ecx_context, Slave, Osize, Isize); } @@ -1456,7 +1456,7 @@ int ec_readPDOmap(uint16 Slave, int *Osize, int *Isize) * @return >0 if mapping succesful. * @see ecx_readPDOmap ec_readPDOmapCA */ -int ec_readPDOmapCA(uint16 Slave, int Thread_n, int *Osize, int *Isize) +int ec_readPDOmapCA(uint16 Slave, int Thread_n, uint32 *Osize, uint32 *Isize) { return ecx_readPDOmapCA(&ecx_context, Slave, Thread_n, Osize, Isize); } diff --git a/soem/soem/ethercatcoe.h b/soem/soem/ethercatcoe.h index 8a789c853..a237fb8e3 100644 --- a/soem/soem/ethercatcoe.h +++ b/soem/soem/ethercatcoe.h @@ -66,8 +66,8 @@ int ec_SDOwrite(uint16 Slave, uint16 Index, uint8 SubIndex, boolean CA, int psize, void *p, int Timeout); int ec_RxPDO(uint16 Slave, uint16 RxPDOnumber , int psize, void *p); int ec_TxPDO(uint16 slave, uint16 TxPDOnumber , int *psize, void *p, int timeout); -int ec_readPDOmap(uint16 Slave, int *Osize, int *Isize); -int ec_readPDOmapCA(uint16 Slave, int Thread_n, int *Osize, int *Isize); +int ec_readPDOmap(uint16 Slave, uint32 *Osize, uint32 *Isize); +int ec_readPDOmapCA(uint16 Slave, int Thread_n, uint32 *Osize, uint32 *Isize); int ec_readODlist(uint16 Slave, ec_ODlistt *pODlist); int ec_readODdescription(uint16 Item, ec_ODlistt *pODlist); int ec_readOEsingle(uint16 Item, uint8 SubI, ec_ODlistt *pODlist, ec_OElistt *pOElist); @@ -81,8 +81,8 @@ int ecx_SDOwrite(ecx_contextt *context, uint16 Slave, uint16 Index, uint8 SubInd boolean CA, int psize, void *p, int Timeout); int ecx_RxPDO(ecx_contextt *context, uint16 Slave, uint16 RxPDOnumber , int psize, void *p); int ecx_TxPDO(ecx_contextt *context, uint16 slave, uint16 TxPDOnumber , int *psize, void *p, int timeout); -int ecx_readPDOmap(ecx_contextt *context, uint16 Slave, int *Osize, int *Isize); -int ecx_readPDOmapCA(ecx_contextt *context, uint16 Slave, int Thread_n, int *Osize, int *Isize); +int ecx_readPDOmap(ecx_contextt *context, uint16 Slave, uint32 *Osize, uint32 *Isize); +int ecx_readPDOmapCA(ecx_contextt *context, uint16 Slave, int Thread_n, uint32 *Osize, uint32 *Isize); int ecx_readODlist(ecx_contextt *context, uint16 Slave, ec_ODlistt *pODlist); int ecx_readODdescription(ecx_contextt *context, uint16 Item, ec_ODlistt *pODlist); int ecx_readOEsingle(ecx_contextt *context, uint16 Item, uint8 SubI, ec_ODlistt *pODlist, ec_OElistt *pOElist); diff --git a/soem/soem/ethercatconfig.c b/soem/soem/ethercatconfig.c index af667a628..f7c3125b5 100644 --- a/soem/soem/ethercatconfig.c +++ b/soem/soem/ethercatconfig.c @@ -484,7 +484,7 @@ int ecx_config_init(ecx_contextt *context, uint8 usetable) context->slavelist[slave].SM[1].SMlength = htoes(context->slavelist[slave].mbx_rl); context->slavelist[slave].SM[1].SMflags = htoel(EC_DEFAULTMBXSM1); eedat = ecx_readeeprom2(context, slave, EC_TIMEOUTEEP); - context->slavelist[slave].mbx_proto = etohl(eedat); + context->slavelist[slave].mbx_proto = (uint16)etohl(eedat); } cindex = 0; /* use configuration table ? */ @@ -607,7 +607,7 @@ int ecx_config_init(ecx_contextt *context, uint8 usetable) /* If slave has SII mapping and same slave ID done before, use previous mapping. * This is safe because SII mapping is constant for same slave ID. */ -static int ecx_lookup_mapping(ecx_contextt *context, uint16 slave, int *Osize, int *Isize) +static int ecx_lookup_mapping(ecx_contextt *context, uint16 slave, uint32 *Osize, uint32 *Isize) { int i, nSM; if ((slave > 1) && (*(context->slavecount) > 0)) @@ -629,8 +629,8 @@ static int ecx_lookup_mapping(ecx_contextt *context, uint16 slave, int *Osize, i } *Osize = context->slavelist[i].Obits; *Isize = context->slavelist[i].Ibits; - context->slavelist[slave].Obits = *Osize; - context->slavelist[slave].Ibits = *Isize; + context->slavelist[slave].Obits = (uint16)*Osize; + context->slavelist[slave].Ibits = (uint16)*Isize; EC_PRINT("Copy mapping slave %d from %d.\n", slave, i); return 1; } @@ -640,7 +640,7 @@ static int ecx_lookup_mapping(ecx_contextt *context, uint16 slave, int *Osize, i static int ecx_map_coe_soe(ecx_contextt *context, uint16 slave, int thread_n) { - int Isize, Osize; + uint32 Isize, Osize; int rval; ecx_statecheck(context, slave, EC_STATE_PRE_OP, EC_TIMEOUTSTATE); /* check state change pre-op */ @@ -675,18 +675,18 @@ static int ecx_map_coe_soe(ecx_contextt *context, uint16 slave, int thread_n) /* read PDO mapping via CoE */ rval = ecx_readPDOmap(context, slave, &Osize, &Isize); } - EC_PRINT(" CoE Osize:%d Isize:%d\n", Osize, Isize); + EC_PRINT(" CoE Osize:%u Isize:%u\n", Osize, Isize); } if ((!Isize && !Osize) && (context->slavelist[slave].mbx_proto & ECT_MBXPROT_SOE)) /* has SoE */ { /* read AT / MDT mapping via SoE */ rval = ecx_readIDNmap(context, slave, &Osize, &Isize); - context->slavelist[slave].SM[2].SMlength = htoes((Osize + 7) / 8); - context->slavelist[slave].SM[3].SMlength = htoes((Isize + 7) / 8); - EC_PRINT(" SoE Osize:%d Isize:%d\n", Osize, Isize); + context->slavelist[slave].SM[2].SMlength = htoes((uint16)((Osize + 7) / 8)); + context->slavelist[slave].SM[3].SMlength = htoes((uint16)((Isize + 7) / 8)); + EC_PRINT(" SoE Osize:%u Isize:%u\n", Osize, Isize); } - context->slavelist[slave].Obits = Osize; - context->slavelist[slave].Ibits = Isize; + context->slavelist[slave].Obits = (uint16)Osize; + context->slavelist[slave].Ibits = (uint16)Isize; } return 1; @@ -694,7 +694,7 @@ static int ecx_map_coe_soe(ecx_contextt *context, uint16 slave, int thread_n) static int ecx_map_sii(ecx_contextt *context, uint16 slave) { - int Isize, Osize; + uint32 Isize, Osize; int nSM; ec_eepromPDOt eepPDO; @@ -708,8 +708,8 @@ static int ecx_map_sii(ecx_contextt *context, uint16 slave) if (!Isize && !Osize) /* find PDO mapping by SII */ { memset(&eepPDO, 0, sizeof(eepPDO)); - Isize = (int)ecx_siiPDO(context, slave, &eepPDO, 0); - EC_PRINT(" SII Isize:%d\n", Isize); + Isize = ecx_siiPDO(context, slave, &eepPDO, 0); + EC_PRINT(" SII Isize:%u\n", Isize); for( nSM=0 ; nSM < EC_MAXSM ; nSM++ ) { if (eepPDO.SMbitsize[nSM] > 0) @@ -719,8 +719,8 @@ static int ecx_map_sii(ecx_contextt *context, uint16 slave) EC_PRINT(" SM%d length %d\n", nSM, eepPDO.SMbitsize[nSM]); } } - Osize = (int)ecx_siiPDO(context, slave, &eepPDO, 1); - EC_PRINT(" SII Osize:%d\n", Osize); + Osize = ecx_siiPDO(context, slave, &eepPDO, 1); + EC_PRINT(" SII Osize:%u\n", Osize); for( nSM=0 ; nSM < EC_MAXSM ; nSM++ ) { if (eepPDO.SMbitsize[nSM] > 0) @@ -731,8 +731,8 @@ static int ecx_map_sii(ecx_contextt *context, uint16 slave) } } } - context->slavelist[slave].Obits = Osize; - context->slavelist[slave].Ibits = Isize; + context->slavelist[slave].Obits = (uint16)Osize; + context->slavelist[slave].Ibits = (uint16)Isize; EC_PRINT(" ISIZE:%d %d OSIZE:%d\n", context->slavelist[slave].Ibits, Isize,context->slavelist[slave].Obits); @@ -897,9 +897,10 @@ static void ecx_config_create_input_mappings(ecx_contextt *context, void *pIOmap uint8 group, int16 slave, uint32 * LogAddr, uint8 * BitPos) { int BitCount = 0; - int ByteCount = 0; - int FMMUsize = 0; int FMMUdone = 0; + int AddToInputsWKC = 0; + uint16 ByteCount = 0; + uint16 FMMUsize = 0; uint8 SMc = 0; uint16 EndAddr; uint16 SMlength; @@ -962,7 +963,7 @@ static void ecx_config_create_input_mappings(ecx_contextt *context, void *pIOmap *LogAddr += 1; *BitPos -= 8; } - FMMUsize = *LogAddr - etohl(context->slavelist[slave].FMMU[FMMUc].LogStart) + 1; + FMMUsize = (uint16)(*LogAddr - etohl(context->slavelist[slave].FMMU[FMMUc].LogStart) + 1); context->slavelist[slave].FMMU[FMMUc].LogLength = htoes(FMMUsize); context->slavelist[slave].FMMU[FMMUc].LogEndbit = *BitPos; *BitPos += 1; @@ -986,7 +987,7 @@ static void ecx_config_create_input_mappings(ecx_contextt *context, void *pIOmap FMMUsize = ByteCount; if ((FMMUsize + FMMUdone)> (int)context->slavelist[slave].Ibytes) { - FMMUsize = context->slavelist[slave].Ibytes - FMMUdone; + FMMUsize = (uint16)(context->slavelist[slave].Ibytes - FMMUdone); } *LogAddr += FMMUsize; context->slavelist[slave].FMMU[FMMUc].LogLength = htoes(FMMUsize); @@ -1002,8 +1003,9 @@ static void ecx_config_create_input_mappings(ecx_contextt *context, void *pIOmap /* program FMMU for input */ ecx_FPWR(context->port, configadr, ECT_REG_FMMU0 + (sizeof(ec_fmmut) * FMMUc), sizeof(ec_fmmut), &(context->slavelist[slave].FMMU[FMMUc]), EC_TIMEOUTRET3); - /* add one for an input FMMU */ - context->grouplist[group].inputsWKC++; + /* Set flag to add one for an input FMMU, + a single ESC can only contribute once */ + AddToInputsWKC = 1; } if (!context->slavelist[slave].inputs) { @@ -1029,15 +1031,20 @@ static void ecx_config_create_input_mappings(ecx_contextt *context, void *pIOmap FMMUc++; } context->slavelist[slave].FMMUunused = FMMUc; + + /* Add one WKC for an input if flag is true */ + if (AddToInputsWKC) + context->grouplist[group].inputsWKC++; } static void ecx_config_create_output_mappings(ecx_contextt *context, void *pIOmap, uint8 group, int16 slave, uint32 * LogAddr, uint8 * BitPos) { int BitCount = 0; - int ByteCount = 0; - int FMMUsize = 0; int FMMUdone = 0; + int AddToOutputsWKC = 0; + uint16 ByteCount = 0; + uint16 FMMUsize = 0; uint8 SMc = 0; uint16 EndAddr; uint16 SMlength; @@ -1094,7 +1101,7 @@ static void ecx_config_create_output_mappings(ecx_contextt *context, void *pIOma *LogAddr += 1; *BitPos -= 8; } - FMMUsize = *LogAddr - etohl(context->slavelist[slave].FMMU[FMMUc].LogStart) + 1; + FMMUsize = (uint16)(*LogAddr - etohl(context->slavelist[slave].FMMU[FMMUc].LogStart) + 1); context->slavelist[slave].FMMU[FMMUc].LogLength = htoes(FMMUsize); context->slavelist[slave].FMMU[FMMUc].LogEndbit = *BitPos; *BitPos += 1; @@ -1118,7 +1125,7 @@ static void ecx_config_create_output_mappings(ecx_contextt *context, void *pIOma FMMUsize = ByteCount; if ((FMMUsize + FMMUdone)> (int)context->slavelist[slave].Obytes) { - FMMUsize = context->slavelist[slave].Obytes - FMMUdone; + FMMUsize = (uint16)(context->slavelist[slave].Obytes - FMMUdone); } *LogAddr += FMMUsize; context->slavelist[slave].FMMU[FMMUc].LogLength = htoes(FMMUsize); @@ -1126,13 +1133,18 @@ static void ecx_config_create_output_mappings(ecx_contextt *context, void *pIOma *BitPos = 0; } FMMUdone += FMMUsize; - context->slavelist[slave].FMMU[FMMUc].PhysStartBit = 0; - context->slavelist[slave].FMMU[FMMUc].FMMUtype = 2; - context->slavelist[slave].FMMU[FMMUc].FMMUactive = 1; - /* program FMMU for output */ - ecx_FPWR(context->port, configadr, ECT_REG_FMMU0 + (sizeof(ec_fmmut) * FMMUc), - sizeof(ec_fmmut), &(context->slavelist[slave].FMMU[FMMUc]), EC_TIMEOUTRET3); - context->grouplist[group].outputsWKC++; + if (context->slavelist[slave].FMMU[FMMUc].LogLength) + { + context->slavelist[slave].FMMU[FMMUc].PhysStartBit = 0; + context->slavelist[slave].FMMU[FMMUc].FMMUtype = 2; + context->slavelist[slave].FMMU[FMMUc].FMMUactive = 1; + /* program FMMU for output */ + ecx_FPWR(context->port, configadr, ECT_REG_FMMU0 + (sizeof(ec_fmmut) * FMMUc), + sizeof(ec_fmmut), &(context->slavelist[slave].FMMU[FMMUc]), EC_TIMEOUTRET3); + /* Set flag to add one for an output FMMU, + a single ESC can only contribute once */ + AddToOutputsWKC = 1; + } if (!context->slavelist[slave].outputs) { if (group) @@ -1158,6 +1170,9 @@ static void ecx_config_create_output_mappings(ecx_contextt *context, void *pIOma FMMUc++; } context->slavelist[slave].FMMUunused = FMMUc; + /* Add one WKC for an output if flag is true */ + if (AddToOutputsWKC) + context->grouplist[group].outputsWKC++; } /** Map all PDOs in one group of slaves to IOmap with Outputs/Inputs @@ -1244,7 +1259,7 @@ int ecx_config_map_group(ecx_contextt *context, void *pIOmap, uint8 group) context->grouplist[group].Obytes = LogAddr - context->grouplist[group].logstartaddr; context->grouplist[group].nsegments = currentsegment + 1; context->grouplist[group].Isegment = currentsegment; - context->grouplist[group].Ioffset = segmentsize; + context->grouplist[group].Ioffset = (uint16)segmentsize; if (!group) { context->slavelist[0].outputs = pIOmap; diff --git a/soem/soem/ethercateoe.c b/soem/soem/ethercateoe.c index 5a40b137f..b23773a36 100644 --- a/soem/soem/ethercateoe.c +++ b/soem/soem/ethercateoe.c @@ -87,52 +87,50 @@ int ecx_EOEsetIp(ecx_contextt *context, uint16 slave, uint8 port, eoe_param_t * cnt = ec_nextmbxcnt(context->slavelist[slave].mbx_cnt); context->slavelist[slave].mbx_cnt = cnt; - EOEp->mbxheader.mbxtype = ECT_MBXT_EOE + (cnt << 4); /* EoE */ + EOEp->mbxheader.mbxtype = ECT_MBXT_EOE + MBX_HDR_SET_CNT(cnt); /* EoE */ - EOEp->frameinfo1 = htoes(EOE_HDR_FRAME_TYPE_SET(EOE_INIT_REQ) | + EOEp->frameinfo1 = htoes(EOE_HDR_FRAME_TYPE_SET(EOE_INIT_REQ) | EOE_HDR_FRAME_PORT_SET(port) | EOE_HDR_LAST_FRAGMENT); EOEp->frameinfo2 = 0; - /* The EoE frame will include "empty" IP/DNS entries, makes wireshark happy. - * Specification say they are optional, TwinCAT include empty entries. - */ if (ipparam->mac_set) { flags |= EOE_PARAM_MAC_INCLUDE; memcpy(&EOEp->data[data_offset], ipparam->mac.addr, EOE_ETHADDR_LENGTH); + data_offset += EOE_ETHADDR_LENGTH; } - data_offset += EOE_ETHADDR_LENGTH; if (ipparam->ip_set) { flags |= EOE_PARAM_IP_INCLUDE; EOE_ip_uint32_to_byte(&ipparam->ip, &EOEp->data[data_offset]); + data_offset += EOE_IP4_LENGTH; } - data_offset += 4; if (ipparam->subnet_set) { flags |= EOE_PARAM_SUBNET_IP_INCLUDE; EOE_ip_uint32_to_byte(&ipparam->subnet, &EOEp->data[data_offset]); + data_offset += EOE_IP4_LENGTH; } - data_offset += 4; if (ipparam->default_gateway_set) { flags |= EOE_PARAM_DEFAULT_GATEWAY_INCLUDE; EOE_ip_uint32_to_byte(&ipparam->default_gateway, &EOEp->data[data_offset]); + data_offset += EOE_IP4_LENGTH; } - data_offset += 4; if (ipparam->dns_ip_set) { flags |= EOE_PARAM_DNS_IP_INCLUDE; EOE_ip_uint32_to_byte(&ipparam->dns_ip, &EOEp->data[data_offset]); + data_offset += EOE_IP4_LENGTH; } - data_offset += 4; if (ipparam->dns_name_set) { + /* TwinCAT include EOE_DNS_NAME_LENGTH chars even if name is shorter */ flags |= EOE_PARAM_DNS_NAME_INCLUDE; memcpy(&EOEp->data[data_offset], (void *)ipparam->dns_name, EOE_DNS_NAME_LENGTH); + data_offset += EOE_DNS_NAME_LENGTH; } - data_offset += EOE_DNS_NAME_LENGTH; EOEp->mbxheader.length = htoes(EOE_PARAM_OFFSET + data_offset); EOEp->data[0] = flags; @@ -200,9 +198,9 @@ int ecx_EOEgetIp(ecx_contextt *context, uint16 slave, uint8 port, eoe_param_t * cnt = ec_nextmbxcnt(context->slavelist[slave].mbx_cnt); context->slavelist[slave].mbx_cnt = cnt; - EOEp->mbxheader.mbxtype = ECT_MBXT_EOE + (cnt << 4); /* EoE */ + EOEp->mbxheader.mbxtype = ECT_MBXT_EOE + MBX_HDR_SET_CNT(cnt); /* EoE */ - EOEp->frameinfo1 = htoes(EOE_HDR_FRAME_TYPE_SET(EOE_GET_IP_PARAM_REQ) | + EOEp->frameinfo1 = htoes(EOE_HDR_FRAME_TYPE_SET(EOE_GET_IP_PARAM_REQ) | EOE_HDR_FRAME_PORT_SET(port) | EOE_HDR_LAST_FRAGMENT); EOEp->frameinfo2 = 0; @@ -231,10 +229,6 @@ int ecx_EOEgetIp(ecx_contextt *context, uint16 slave, uint8 port, eoe_param_t * } else { - /* The EoE frame will include "empty" IP/DNS entries, makes - * wireshark happy. Specification say they are optional, TwinCAT - * include empty entries. - */ flags = aEOEp->data[0]; if (flags & EOE_PARAM_MAC_INCLUDE) { @@ -242,36 +236,36 @@ int ecx_EOEgetIp(ecx_contextt *context, uint16 slave, uint8 port, eoe_param_t * &aEOEp->data[data_offset], EOE_ETHADDR_LENGTH); ipparam->mac_set = 1; + data_offset += EOE_ETHADDR_LENGTH; } - data_offset += EOE_ETHADDR_LENGTH; if (flags & EOE_PARAM_IP_INCLUDE) { EOE_ip_byte_to_uint32(&aEOEp->data[data_offset], &ipparam->ip); ipparam->ip_set = 1; + data_offset += EOE_IP4_LENGTH; } - data_offset += 4; if (flags & EOE_PARAM_SUBNET_IP_INCLUDE) { EOE_ip_byte_to_uint32(&aEOEp->data[data_offset], &ipparam->subnet); ipparam->subnet_set = 1; + data_offset += EOE_IP4_LENGTH; } - data_offset += 4; if (flags & EOE_PARAM_DEFAULT_GATEWAY_INCLUDE) { EOE_ip_byte_to_uint32(&aEOEp->data[data_offset], &ipparam->default_gateway); ipparam->default_gateway_set = 1; + data_offset += EOE_IP4_LENGTH; } - data_offset += 4; if (flags & EOE_PARAM_DNS_IP_INCLUDE) { EOE_ip_byte_to_uint32(&aEOEp->data[data_offset], &ipparam->dns_ip); ipparam->dns_ip_set = 1; + data_offset += EOE_IP4_LENGTH; } - data_offset += 4; if (flags & EOE_PARAM_DNS_NAME_INCLUDE) { uint16_t dns_len; @@ -286,8 +280,8 @@ int ecx_EOEgetIp(ecx_contextt *context, uint16 slave, uint8 port, eoe_param_t * /* Assume ZERO terminated string */ memcpy(ipparam->dns_name, &aEOEp->data[data_offset], dns_len); ipparam->dns_name_set = 1; + data_offset += EOE_DNS_NAME_LENGTH; } - data_offset += EOE_DNS_NAME_LENGTH; /* Something os not correct, flag the error */ if(data_offset > eoedatasize) { @@ -324,10 +318,9 @@ int ecx_EOEsend(ecx_contextt *context, uint16 slave, uint8 port, int psize, void ec_EOEt *EOEp; ec_mbxbuft MbxOut; uint16 frameinfo1, frameinfo2; - uint16 txframesize, txframeoffset; uint8 cnt, txfragmentno; boolean NotLast; - int wkc, maxdata; + int wkc, maxdata, txframesize, txframeoffset; const uint8 * buf = p; static uint8_t txframeno = 0; @@ -377,8 +370,8 @@ int ecx_EOEsend(ecx_contextt *context, uint16 slave, uint8 port, int psize, void cnt = ec_nextmbxcnt(context->slavelist[slave].mbx_cnt); context->slavelist[slave].mbx_cnt = cnt; - EOEp->mbxheader.length = htoes(4 + txframesize); /* no timestamp */ - EOEp->mbxheader.mbxtype = ECT_MBXT_EOE + (cnt << 4); /* EoE */ + EOEp->mbxheader.length = htoes((uint16)(4 + txframesize)); /* no timestamp */ + EOEp->mbxheader.mbxtype = ECT_MBXT_EOE + MBX_HDR_SET_CNT(cnt); /* EoE */ EOEp->frameinfo1 = htoes(frameinfo1); EOEp->frameinfo2 = htoes(frameinfo2); @@ -416,10 +409,10 @@ int ecx_EOErecv(ecx_contextt *context, uint16 slave, uint8 port, int * psize, vo { ec_EOEt *aEOEp; ec_mbxbuft MbxIn; - uint16 frameinfo1, frameinfo2, rxframesize, rxframeoffset, eoedatasize; + uint16 frameinfo1, frameinfo2; uint8 rxfragmentno, rxframeno; boolean NotLast; - int wkc, buffersize; + int wkc, buffersize, rxframesize, rxframeoffset, eoedatasize; uint8 * buf = p; ec_clearmbx(&MbxIn); @@ -579,7 +572,7 @@ int ecx_EOEreadfragment( /* Is it a new frame?*/ if (*rxfragmentno == 0) { - *rxframesize = (EOE_HDR_FRAME_OFFSET_GET(frameinfo2) << 5); + *rxframesize = (uint16)(EOE_HDR_FRAME_OFFSET_GET(frameinfo2) << 5); *rxframeoffset = 0; *rxframeno = EOE_HDR_FRAME_NO_GET(frameinfo2); } diff --git a/soem/soem/ethercateoe.h b/soem/soem/ethercateoe.h index b51739801..930403acb 100644 --- a/soem/soem/ethercateoe.h +++ b/soem/soem/ethercateoe.h @@ -16,12 +16,17 @@ extern "C" { #endif -#include +#include "ethercattype.h" + +/* use maximum size for EOE mailbox data */ +#define EC_MAXEOEDATA EC_MAXMBX /** DNS length according to ETG 1000.6 */ #define EOE_DNS_NAME_LENGTH 32 /** Ethernet address length not including VLAN */ #define EOE_ETHADDR_LENGTH 6 +/** IPv4 address length */ +#define EOE_IP4_LENGTH sizeof(uint32_t) #define EOE_MAKEU32(a,b,c,d) (((uint32_t)((a) & 0xff) << 24) | \ ((uint32_t)((b) & 0xff) << 16) | \ @@ -61,7 +66,7 @@ extern "C" #define EOE_HDR_FRAME_TYPE_GET(x) (((x) >> 0) & 0xF) #define EOE_HDR_FRAME_PORT_OFFSET 4 #define EOE_HDR_FRAME_PORT (0xF << 4) -#define EOE_HDR_FRAME_PORT_SET(x) (((x) & 0xF) << 4) +#define EOE_HDR_FRAME_PORT_SET(x) ((uint16)(((x) & 0xF) << 4)) #define EOE_HDR_FRAME_PORT_GET(x) (((x) >> 4) & 0xF) #define EOE_HDR_LAST_FRAGMENT_OFFSET 8 #define EOE_HDR_LAST_FRAGMENT (0x1 << 8) @@ -79,15 +84,15 @@ extern "C" /** Header frame info 2 */ #define EOE_HDR_FRAG_NO_OFFSET 0 #define EOE_HDR_FRAG_NO (0x3F << 0) -#define EOE_HDR_FRAG_NO_SET(x) (((x) & 0x3F) << 0) +#define EOE_HDR_FRAG_NO_SET(x) ((uint16)(((x) & 0x3F) << 0)) #define EOE_HDR_FRAG_NO_GET(x) (((x) >> 0) & 0x3F) #define EOE_HDR_FRAME_OFFSET_OFFSET 6 #define EOE_HDR_FRAME_OFFSET (0x3F << 6) -#define EOE_HDR_FRAME_OFFSET_SET(x) (((x) & 0x3F) << 6) +#define EOE_HDR_FRAME_OFFSET_SET(x) ((uint16)(((x) & 0x3F) << 6)) #define EOE_HDR_FRAME_OFFSET_GET(x) (((x) >> 6) & 0x3F) #define EOE_HDR_FRAME_NO_OFFSET 12 #define EOE_HDR_FRAME_NO (0xF << 12) -#define EOE_HDR_FRAME_NO_SET(x) (((x) & 0xF) << 12) +#define EOE_HDR_FRAME_NO_SET(x) ((uint16)(((x) & 0xF) << 12)) #define EOE_HDR_FRAME_NO_GET(x) (((x) >> 12) & 0xF) /** EOE param */ @@ -163,7 +168,7 @@ typedef struct PACKED uint16_t frameinfo2; uint16_t result; }; - uint8 data[0]; + uint8 data[EC_MAXEOEDATA]; } ec_EOEt; PACKED_END diff --git a/soem/soem/ethercatfoe.c b/soem/soem/ethercatfoe.c index 7bab98575..573cfc0c1 100644 --- a/soem/soem/ethercatfoe.c +++ b/soem/soem/ethercatfoe.c @@ -98,7 +98,7 @@ int ecx_FOEread(ecx_contextt *context, uint16 slave, char *filename, uint32 pass /* get new mailbox count value, used as session handle */ cnt = ec_nextmbxcnt(context->slavelist[slave].mbx_cnt); context->slavelist[slave].mbx_cnt = cnt; - FOEp->MbxHeader.mbxtype = ECT_MBXT_FOE + (cnt << 4); /* FoE */ + FOEp->MbxHeader.mbxtype = ECT_MBXT_FOE + MBX_HDR_SET_CNT(cnt); /* FoE */ FOEp->OpCode = ECT_FOE_READ; FOEp->Password = htoel(password); /* copy filename in mailbox */ @@ -138,7 +138,7 @@ int ecx_FOEread(ecx_contextt *context, uint16 slave, char *filename, uint32 pass /* get new mailbox count value */ cnt = ec_nextmbxcnt(context->slavelist[slave].mbx_cnt); context->slavelist[slave].mbx_cnt = cnt; - FOEp->MbxHeader.mbxtype = ECT_MBXT_FOE + (cnt << 4); /* FoE */ + FOEp->MbxHeader.mbxtype = ECT_MBXT_FOE + MBX_HDR_SET_CNT(cnt); /* FoE */ FOEp->OpCode = ECT_FOE_ACK; FOEp->PacketNumber = htoel(packetnumber); /* send FoE ack to slave */ @@ -227,7 +227,7 @@ int ecx_FOEwrite(ecx_contextt *context, uint16 slave, char *filename, uint32 pas /* get new mailbox count value, used as session handle */ cnt = ec_nextmbxcnt(context->slavelist[slave].mbx_cnt); context->slavelist[slave].mbx_cnt = cnt; - FOEp->MbxHeader.mbxtype = ECT_MBXT_FOE + (cnt << 4); /* FoE */ + FOEp->MbxHeader.mbxtype = ECT_MBXT_FOE + MBX_HDR_SET_CNT(cnt); /* FoE */ FOEp->OpCode = ECT_FOE_WRITE; FOEp->Password = htoel(password); /* copy filename in mailbox */ @@ -276,13 +276,13 @@ int ecx_FOEwrite(ecx_contextt *context, uint16 slave, char *filename, uint32 pas { dofinalzero = TRUE; } - FOEp->MbxHeader.length = htoes(0x0006 + segmentdata); + FOEp->MbxHeader.length = htoes((uint16)(0x0006 + segmentdata)); FOEp->MbxHeader.address = htoes(0x0000); FOEp->MbxHeader.priority = 0x00; /* get new mailbox count value */ cnt = ec_nextmbxcnt(context->slavelist[slave].mbx_cnt); context->slavelist[slave].mbx_cnt = cnt; - FOEp->MbxHeader.mbxtype = ECT_MBXT_FOE + (cnt << 4); /* FoE */ + FOEp->MbxHeader.mbxtype = ECT_MBXT_FOE + MBX_HDR_SET_CNT(cnt); /* FoE */ FOEp->OpCode = ECT_FOE_DATA; sendpacket++; FOEp->PacketNumber = htoel(sendpacket); diff --git a/soem/soem/ethercatmain.c b/soem/soem/ethercatmain.c index 124fccdb5..66268b6c4 100644 --- a/soem/soem/ethercatmain.c +++ b/soem/soem/ethercatmain.c @@ -110,8 +110,6 @@ ecx_contextt ecx_context = { &ec_elist, // .elist = &ec_idxstack, // .idxstack = &EcatError, // .ecaterror = - 0, // .DCtO = - 0, // .DCl = &ec_DCtime, // .DCtime = &ec_SMcommtype[0], // .SMcommtype = &ec_PDOassign[0], // .PDOassign = @@ -120,7 +118,8 @@ ecx_contextt ecx_context = { &ec_FMMU, // .eepFMMU = NULL, // .FOEhook() NULL, // .EOEhook() - 0 // .manualstatechange + 0, // .manualstatechange + NULL // .nomischandle }; #endif @@ -349,7 +348,7 @@ uint8 ecx_siigetbyte(ecx_contextt *context, uint16 slave, uint16 address) if (address < EC_MAXEEPBUF) { mapw = address >> 5; - mapb = address - (mapw << 5); + mapb = (uint16)(address - (mapw << 5)); if (context->esimap[mapw] & (uint32)(1 << mapb)) { /* byte is already in buffer */ @@ -377,7 +376,7 @@ uint8 ecx_siigetbyte(ecx_contextt *context, uint16 slave, uint16 address) } /* find bitmap location */ mapw = eadr >> 4; - mapb = (eadr << 1) - (mapw << 5); + mapb = (uint16)((eadr << 1) - (mapw << 5)); for(lp = 0 ; lp < cnt ; lp++) { /* set bitmap for each byte that is read */ @@ -552,7 +551,7 @@ uint16 ecx_siiSM(ecx_contextt *context, uint16 slave, ec_eepromSMt* SM) a = SM->Startpos; w = ecx_siigetbyte(context, slave, a++); w += (ecx_siigetbyte(context, slave, a++) << 8); - SM->nSM = (w / 4); + SM->nSM = (uint8)(w / 4); SM->PhStart = ecx_siigetbyte(context, slave, a++); SM->PhStart += (ecx_siigetbyte(context, slave, a++) << 8); SM->Plength = ecx_siigetbyte(context, slave, a++); @@ -611,7 +610,7 @@ uint16 ecx_siiSMnext(ecx_contextt *context, uint16 slave, ec_eepromSMt* SM, uint * @param[in] t = 0=RXPDO 1=TXPDO * @return mapping size in bits of PDO */ -int ecx_siiPDO(ecx_contextt *context, uint16 slave, ec_eepromPDOt* PDO, uint8 t) +uint32 ecx_siiPDO(ecx_contextt *context, uint16 slave, ec_eepromPDOt* PDO, uint8 t) { uint16 a , w, c, e, er, Size; uint8 eectl = context->slavelist[slave].eep_pdi; @@ -685,7 +684,7 @@ int ecx_FPRD_multi(ecx_contextt *context, int n, uint16 *configlst, ec_alstatust int wkc; uint8 idx; ecx_portt *port; - int sldatapos[MAX_FPRD_MULTI]; + uint16 sldatapos[MAX_FPRD_MULTI]; int slcnt; port = context->port; @@ -789,7 +788,7 @@ int ecx_readstate(ecx_contextt *context) fslave = 1; do { - lslave = *(context->slavecount); + lslave = (uint16)*(context->slavecount); if ((lslave - fslave) >= MAX_FPRD_MULTI) { lslave = fslave + MAX_FPRD_MULTI - 1; @@ -1113,8 +1112,7 @@ int ecx_mbxreceive(ecx_contextt *context, uint16 slave, ec_mbxbuft *mbx, int tim */ void ecx_esidump(ecx_contextt *context, uint16 slave, uint8 *esibuf) { - int address, incr; - uint16 configadr; + uint16 configadr, address, incr; uint64 *p64; uint16 *p16; uint64 edat; @@ -1242,7 +1240,8 @@ int ecx_eeprom2pdi(ecx_contextt *context, uint16 slave) uint16 ecx_eeprom_waitnotbusyAP(ecx_contextt *context, uint16 aiadr,uint16 *estat, int timeout) { - int wkc, cnt = 0, retval = 0; + int wkc, cnt = 0; + uint16 retval = 0; osal_timert timer; osal_timer_start(&timer, timeout); @@ -1411,7 +1410,8 @@ int ecx_writeeepromAP(ecx_contextt *context, uint16 aiadr, uint16 eeproma, uint1 uint16 ecx_eeprom_waitnotbusyFP(ecx_contextt *context, uint16 configadr,uint16 *estat, int timeout) { - int wkc, cnt = 0, retval = 0; + int wkc, cnt = 0; + uint16 retval = 0; osal_timert timer; osal_timer_start(&timer, timeout); @@ -1641,14 +1641,16 @@ uint32 ecx_readeeprom2(ecx_contextt *context, uint16 slave, int timeout) * @param[in] idx = Used datagram index. * @param[in] data = Pointer to process data segment. * @param[in] length = Length of data segment in bytes. + * @param[in] DCO = Offset position of DC frame. */ -static void ecx_pushindex(ecx_contextt *context, uint8 idx, void *data, uint16 length) +static void ecx_pushindex(ecx_contextt *context, uint8 idx, void *data, uint16 length, uint16 DCO) { if(context->idxstack->pushed < EC_MAXBUF) { context->idxstack->idx[context->idxstack->pushed] = idx; context->idxstack->data[context->idxstack->pushed] = data; context->idxstack->length[context->idxstack->pushed] = length; + context->idxstack->dcoffset[context->idxstack->pushed] = DCO; context->idxstack->pushed++; } } @@ -1698,13 +1700,15 @@ static int ecx_main_send_processdata(ecx_contextt *context, uint8 group, boolean { uint32 LogAdr; uint16 w1, w2; - int length, sublength; + int length; + uint16 sublength; uint8 idx; int wkc; uint8* data; boolean first=FALSE; uint16 currentsegment = 0; uint32 iomapinputoffset; + uint16 DCO; wkc = 0; if(context->grouplist[group].hasdc) @@ -1747,22 +1751,22 @@ static int ecx_main_send_processdata(ecx_contextt *context, uint8 group, boolean { if(currentsegment == context->grouplist[group].Isegment) { - sublength = context->grouplist[group].IOsegment[currentsegment++] - context->grouplist[group].Ioffset; + sublength = (uint16)(context->grouplist[group].IOsegment[currentsegment++] - context->grouplist[group].Ioffset); } else { - sublength = context->grouplist[group].IOsegment[currentsegment++]; + sublength = (uint16)context->grouplist[group].IOsegment[currentsegment++]; } /* get new index */ idx = ecx_getindex(context->port); w1 = LO_WORD(LogAdr); w2 = HI_WORD(LogAdr); + DCO = 0; ecx_setupdatagram(context->port, &(context->port->txbuf[idx]), EC_CMD_LRD, idx, w1, w2, sublength, data); if(first) { - context->DCl = sublength; /* FPRMW in second datagram */ - context->DCtO = ecx_adddatagram(context->port, &(context->port->txbuf[idx]), EC_CMD_FRMW, idx, FALSE, + DCO = ecx_adddatagram(context->port, &(context->port->txbuf[idx]), EC_CMD_FRMW, idx, FALSE, context->slavelist[context->grouplist[group].DCnext].configadr, ECT_REG_DCSYSTIME, sizeof(int64), context->DCtime); first = FALSE; @@ -1770,7 +1774,7 @@ static int ecx_main_send_processdata(ecx_contextt *context, uint8 group, boolean /* send frame */ ecx_outframe_red(context->port, idx); /* push index and data pointer on stack */ - ecx_pushindex(context, idx, data, sublength); + ecx_pushindex(context, idx, data, sublength, DCO); length -= sublength; LogAdr += sublength; data += sublength; @@ -1786,21 +1790,21 @@ static int ecx_main_send_processdata(ecx_contextt *context, uint8 group, boolean /* segment transfer if needed */ do { - sublength = context->grouplist[group].IOsegment[currentsegment++]; + sublength = (uint16)context->grouplist[group].IOsegment[currentsegment++]; if((length - sublength) < 0) { - sublength = length; + sublength = (uint16)length; } /* get new index */ idx = ecx_getindex(context->port); w1 = LO_WORD(LogAdr); w2 = HI_WORD(LogAdr); + DCO = 0; ecx_setupdatagram(context->port, &(context->port->txbuf[idx]), EC_CMD_LWR, idx, w1, w2, sublength, data); if(first) { - context->DCl = sublength; /* FPRMW in second datagram */ - context->DCtO = ecx_adddatagram(context->port, &(context->port->txbuf[idx]), EC_CMD_FRMW, idx, FALSE, + DCO = ecx_adddatagram(context->port, &(context->port->txbuf[idx]), EC_CMD_FRMW, idx, FALSE, context->slavelist[context->grouplist[group].DCnext].configadr, ECT_REG_DCSYSTIME, sizeof(int64), context->DCtime); first = FALSE; @@ -1808,7 +1812,7 @@ static int ecx_main_send_processdata(ecx_contextt *context, uint8 group, boolean /* send frame */ ecx_outframe_red(context->port, idx); /* push index and data pointer on stack */ - ecx_pushindex(context, idx, data, sublength); + ecx_pushindex(context, idx, data, sublength, DCO); length -= sublength; LogAdr += sublength; data += sublength; @@ -1831,17 +1835,17 @@ static int ecx_main_send_processdata(ecx_contextt *context, uint8 group, boolean /* segment transfer if needed */ do { - sublength = context->grouplist[group].IOsegment[currentsegment++]; + sublength = (uint16)context->grouplist[group].IOsegment[currentsegment++]; /* get new index */ idx = ecx_getindex(context->port); w1 = LO_WORD(LogAdr); w2 = HI_WORD(LogAdr); + DCO = 0; ecx_setupdatagram(context->port, &(context->port->txbuf[idx]), EC_CMD_LRW, idx, w1, w2, sublength, data); if(first) { - context->DCl = sublength; /* FPRMW in second datagram */ - context->DCtO = ecx_adddatagram(context->port, &(context->port->txbuf[idx]), EC_CMD_FRMW, idx, FALSE, + DCO = ecx_adddatagram(context->port, &(context->port->txbuf[idx]), EC_CMD_FRMW, idx, FALSE, context->slavelist[context->grouplist[group].DCnext].configadr, ECT_REG_DCSYSTIME, sizeof(int64), context->DCtime); first = FALSE; @@ -1853,7 +1857,7 @@ static int ecx_main_send_processdata(ecx_contextt *context, uint8 group, boolean * in the IOmap if we use an overlapping IOmap. If a regular IOmap * is used it should always be 0. */ - ecx_pushindex(context, idx, (data + iomapinputoffset), sublength); + ecx_pushindex(context, idx, (data + iomapinputoffset), sublength, DCO); length -= sublength; LogAdr += sublength; data += sublength; @@ -1909,56 +1913,57 @@ int ecx_send_processdata_group(ecx_contextt *context, uint8 group) */ int ecx_receive_processdata_group(ecx_contextt *context, uint8 group, int timeout) { - int pos, idx; + uint8 idx; + int pos; int wkc = 0, wkc2; uint16 le_wkc = 0; int valid_wkc = 0; int64 le_DCtime; - boolean first = FALSE; + ec_idxstackT *idxstack; + ec_bufT *rxbuf; - if(context->grouplist[group].hasdc) - { - first = TRUE; - } + /* just to prevent compiler warning for unused group */ + wkc2 = group; + + idxstack = context->idxstack; + rxbuf = context->port->rxbuf; /* get first index */ pos = ecx_pullindex(context); /* read the same number of frames as send */ while (pos >= 0) { - idx = context->idxstack->idx[pos]; - wkc2 = ecx_waitinframe(context->port, context->idxstack->idx[pos], timeout); + idx = idxstack->idx[pos]; + wkc2 = ecx_waitinframe(context->port, idx, timeout); /* check if there is input data in frame */ if (wkc2 > EC_NOFRAME) { - if((context->port->rxbuf[idx][EC_CMDOFFSET]==EC_CMD_LRD) || (context->port->rxbuf[idx][EC_CMDOFFSET]==EC_CMD_LRW)) + if((rxbuf[idx][EC_CMDOFFSET]==EC_CMD_LRD) || (rxbuf[idx][EC_CMDOFFSET]==EC_CMD_LRW)) { - if(first) + if(idxstack->dcoffset[pos] > 0) { - memcpy(context->idxstack->data[pos], &(context->port->rxbuf[idx][EC_HEADERSIZE]), context->DCl); - memcpy(&le_wkc, &(context->port->rxbuf[idx][EC_HEADERSIZE + context->DCl]), EC_WKCSIZE); + memcpy(idxstack->data[pos], &(rxbuf[idx][EC_HEADERSIZE]), idxstack->length[pos]); + memcpy(&le_wkc, &(rxbuf[idx][EC_HEADERSIZE + idxstack->length[pos]]), EC_WKCSIZE); wkc = etohs(le_wkc); - memcpy(&le_DCtime, &(context->port->rxbuf[idx][context->DCtO]), sizeof(le_DCtime)); + memcpy(&le_DCtime, &(rxbuf[idx][idxstack->dcoffset[pos]]), sizeof(le_DCtime)); *(context->DCtime) = etohll(le_DCtime); - first = FALSE; } else { /* copy input data back to process data buffer */ - memcpy(context->idxstack->data[pos], &(context->port->rxbuf[idx][EC_HEADERSIZE]), context->idxstack->length[pos]); + memcpy(idxstack->data[pos], &(rxbuf[idx][EC_HEADERSIZE]), idxstack->length[pos]); wkc += wkc2; } valid_wkc = 1; } - else if(context->port->rxbuf[idx][EC_CMDOFFSET]==EC_CMD_LWR) + else if(rxbuf[idx][EC_CMDOFFSET]==EC_CMD_LWR) { - if(first) + if(idxstack->dcoffset[pos] > 0) { - memcpy(&le_wkc, &(context->port->rxbuf[idx][EC_HEADERSIZE + context->DCl]), EC_WKCSIZE); + memcpy(&le_wkc, &(rxbuf[idx][EC_HEADERSIZE + idxstack->length[pos]]), EC_WKCSIZE); /* output WKC counts 2 times when using LRW, emulate the same for LWR */ wkc = etohs(le_wkc) * 2; - memcpy(&le_DCtime, &(context->port->rxbuf[idx][context->DCtO]), sizeof(le_DCtime)); + memcpy(&le_DCtime, &(rxbuf[idx][idxstack->dcoffset[pos]]), sizeof(le_DCtime)); *(context->DCtime) = etohll(le_DCtime); - first = FALSE; } else { @@ -2126,7 +2131,7 @@ uint16 ec_siiSMnext(uint16 slave, ec_eepromSMt* SM, uint16 n) * @return mapping size in bits of PDO * @see ecx_siiPDO */ -int ec_siiPDO(uint16 slave, ec_eepromPDOt* PDO, uint8 t) +uint32 ec_siiPDO(uint16 slave, ec_eepromPDOt* PDO, uint8 t) { return ecx_siiPDO (&ecx_context, slave, PDO, t); } diff --git a/soem/soem/ethercatmain.h b/soem/soem/ethercatmain.h index 7001572a0..915b9d428 100644 --- a/soem/soem/ethercatmain.h +++ b/soem/soem/ethercatmain.h @@ -340,6 +340,7 @@ typedef struct ec_idxstack uint8 idx[EC_MAXBUF]; void *data[EC_MAXBUF]; uint16 length[EC_MAXBUF]; + uint16 dcoffset[EC_MAXBUF]; } ec_idxstackT; /** ringbuf for error storage */ @@ -407,10 +408,6 @@ struct ecx_context ec_idxstackT *idxstack; /** reference to ecaterror state */ boolean *ecaterror; - /** internal, position of DC datagram in process data packet */ - uint16 DCtO; - /** internal, length of DC datagram */ - uint16 DCl; /** reference to last DC time from slaves */ int64 *DCtime; /** internal, SM buffer */ @@ -429,6 +426,8 @@ struct ecx_context int (*EOEhook)(ecx_contextt * context, uint16 slave, void * eoembx); /** flag to control legacy automatic state change or manual state change */ int manualstatechange; + /** additional misc handle */ + void* misc; }; #ifdef EC_VER1 @@ -456,7 +455,7 @@ void ec_siistring(char *str, uint16 slave, uint16 Sn); uint16 ec_siiFMMU(uint16 slave, ec_eepromFMMUt* FMMU); uint16 ec_siiSM(uint16 slave, ec_eepromSMt* SM); uint16 ec_siiSMnext(uint16 slave, ec_eepromSMt* SM, uint16 n); -int ec_siiPDO(uint16 slave, ec_eepromPDOt* PDO, uint8 t); +uint32 ec_siiPDO(uint16 slave, ec_eepromPDOt* PDO, uint8 t); int ec_readstate(void); int ec_writestate(uint16 slave); uint16 ec_statecheck(uint16 slave, uint16 reqstate, int timeout); @@ -499,7 +498,7 @@ void ecx_siistring(ecx_contextt *context, char *str, uint16 slave, uint16 Sn); uint16 ecx_siiFMMU(ecx_contextt *context, uint16 slave, ec_eepromFMMUt* FMMU); uint16 ecx_siiSM(ecx_contextt *context, uint16 slave, ec_eepromSMt* SM); uint16 ecx_siiSMnext(ecx_contextt *context, uint16 slave, ec_eepromSMt* SM, uint16 n); -int ecx_siiPDO(ecx_contextt *context, uint16 slave, ec_eepromPDOt* PDO, uint8 t); +uint32 ecx_siiPDO(ecx_contextt *context, uint16 slave, ec_eepromPDOt* PDO, uint8 t); int ecx_readstate(ecx_contextt *context); int ecx_writestate(ecx_contextt *context, uint16 slave); uint16 ecx_statecheck(ecx_contextt *context, uint16 slave, uint16 reqstate, int timeout); diff --git a/soem/soem/ethercatsoe.c b/soem/soem/ethercatsoe.c index 1fcc901b4..eb83a64dc 100644 --- a/soem/soem/ethercatsoe.c +++ b/soem/soem/ethercatsoe.c @@ -78,7 +78,7 @@ void ecx_SoEerror(ecx_contextt *context, uint16 Slave, uint16 idn, uint16 Error) int ecx_SoEread(ecx_contextt *context, uint16 slave, uint8 driveNo, uint8 elementflags, uint16 idn, int *psize, void *p, int timeout) { ec_SoEt *SoEp, *aSoEp; - uint16 totalsize, framedatasize; + int totalsize, framedatasize; int wkc; uint8 *bp; uint8 *mp; @@ -99,7 +99,7 @@ int ecx_SoEread(ecx_contextt *context, uint16 slave, uint8 driveNo, uint8 elemen /* get new mailbox count value, used as session handle */ cnt = ec_nextmbxcnt(context->slavelist[slave].mbx_cnt); context->slavelist[slave].mbx_cnt = cnt; - SoEp->MbxHeader.mbxtype = ECT_MBXT_SOE + (cnt << 4); /* SoE */ + SoEp->MbxHeader.mbxtype = ECT_MBXT_SOE + MBX_HDR_SET_CNT(cnt); /* SoE */ SoEp->opCode = ECT_SOE_READREQ; SoEp->incomplete = 0; SoEp->error = 0; @@ -200,7 +200,7 @@ int ecx_SoEread(ecx_contextt *context, uint16 slave, uint8 driveNo, uint8 elemen int ecx_SoEwrite(ecx_contextt *context, uint16 slave, uint8 driveNo, uint8 elementflags, uint16 idn, int psize, void *p, int timeout) { ec_SoEt *SoEp, *aSoEp; - uint16 framedatasize, maxdata; + int framedatasize, maxdata; int wkc; uint8 *mp; uint8 *hp; @@ -236,13 +236,13 @@ int ecx_SoEwrite(ecx_contextt *context, uint16 slave, uint8 driveNo, uint8 eleme framedatasize = maxdata; /* segmented transfer needed */ NotLast = TRUE; SoEp->incomplete = 1; - SoEp->fragmentsleft = psize / maxdata; + SoEp->fragmentsleft = (uint16)(psize / maxdata); } - SoEp->MbxHeader.length = htoes(sizeof(ec_SoEt) - sizeof(ec_mbxheadert) + framedatasize); + SoEp->MbxHeader.length = htoes((uint16)(sizeof(ec_SoEt) - sizeof(ec_mbxheadert) + framedatasize)); /* get new mailbox counter, used for session handle */ cnt = ec_nextmbxcnt(context->slavelist[slave].mbx_cnt); context->slavelist[slave].mbx_cnt = cnt; - SoEp->MbxHeader.mbxtype = ECT_MBXT_SOE + (cnt << 4); /* SoE */ + SoEp->MbxHeader.mbxtype = ECT_MBXT_SOE + MBX_HDR_SET_CNT(cnt); /* SoE */ /* copy parameter data to mailbox */ memcpy(mp, hp, framedatasize); hp += framedatasize; @@ -309,12 +309,12 @@ int ecx_SoEwrite(ecx_contextt *context, uint16 slave, uint8 driveNo, uint8 eleme * @param[out] Isize = Size in bits of input mapping (AT) found * @return >0 if mapping successful. */ -int ecx_readIDNmap(ecx_contextt *context, uint16 slave, int *Osize, int *Isize) +int ecx_readIDNmap(ecx_contextt *context, uint16 slave, uint32 *Osize, uint32 *Isize) { int retVal = 0; int wkc; int psize; - int driveNr; + uint8 driveNr; uint16 entries, itemcount; ec_SoEmappingt SoEmapping; ec_SoEattributet SoEattribute; @@ -329,7 +329,7 @@ int ecx_readIDNmap(ecx_contextt *context, uint16 slave, int *Osize, int *Isize) if ((wkc > 0) && (psize >= 4) && ((entries = etohs(SoEmapping.currentlength) / 2) > 0) && (entries <= EC_SOE_MAXMAPPING)) { /* command word (uint16) is always mapped but not in list */ - *Osize = 16; + *Osize += 16; for (itemcount = 0 ; itemcount < entries ; itemcount++) { psize = sizeof(SoEattribute); @@ -348,7 +348,7 @@ int ecx_readIDNmap(ecx_contextt *context, uint16 slave, int *Osize, int *Isize) if ((wkc > 0) && (psize >= 4) && ((entries = etohs(SoEmapping.currentlength) / 2) > 0) && (entries <= EC_SOE_MAXMAPPING)) { /* status word (uint16) is always mapped but not in list */ - *Isize = 16; + *Isize += 16; for (itemcount = 0 ; itemcount < entries ; itemcount++) { psize = sizeof(SoEattribute); @@ -382,7 +382,7 @@ int ec_SoEwrite(uint16 slave, uint8 driveNo, uint8 elementflags, uint16 idn, int return ecx_SoEwrite(&ecx_context, slave, driveNo, elementflags, idn, psize, p, timeout); } -int ec_readIDNmap(uint16 slave, int *Osize, int *Isize) +int ec_readIDNmap(uint16 slave, uint32 *Osize, uint32 *Isize) { return ecx_readIDNmap(&ecx_context, slave, Osize, Isize); } diff --git a/soem/soem/ethercatsoe.h b/soem/soem/ethercatsoe.h index 42de4885e..35d76d146 100644 --- a/soem/soem/ethercatsoe.h +++ b/soem/soem/ethercatsoe.h @@ -116,12 +116,12 @@ PACKED_END #ifdef EC_VER1 int ec_SoEread(uint16 slave, uint8 driveNo, uint8 elementflags, uint16 idn, int *psize, void *p, int timeout); int ec_SoEwrite(uint16 slave, uint8 driveNo, uint8 elementflags, uint16 idn, int psize, void *p, int timeout); -int ec_readIDNmap(uint16 slave, int *Osize, int *Isize); +int ec_readIDNmap(uint16 slave, uint32 *Osize, uint32 *Isize); #endif int ecx_SoEread(ecx_contextt *context, uint16 slave, uint8 driveNo, uint8 elementflags, uint16 idn, int *psize, void *p, int timeout); int ecx_SoEwrite(ecx_contextt *context, uint16 slave, uint8 driveNo, uint8 elementflags, uint16 idn, int psize, void *p, int timeout); -int ecx_readIDNmap(ecx_contextt *context, uint16 slave, int *Osize, int *Isize); +int ecx_readIDNmap(ecx_contextt *context, uint16 slave, uint32 *Osize, uint32 *Isize); #ifdef __cplusplus } diff --git a/soem/soem/ethercattype.h b/soem/soem/ethercattype.h index 6b4d17cd6..527ccd7ae 100644 --- a/soem/soem/ethercattype.h +++ b/soem/soem/ethercattype.h @@ -506,6 +506,10 @@ typedef struct } ec_errort; /** Helper macros */ + +/** Set the count value in the Mailbox header */ +#define MBX_HDR_SET_CNT(cnt) ((uint8)((cnt) << 4)) + /** Macro to make a word from 2 bytes */ #define MK_WORD(msb, lsb) ((((uint16)(msb))<<8) | (lsb)) /** Macro to get hi byte of a word */ diff --git a/soem/test/linux/red_test/red_test.c b/soem/test/linux/red_test/red_test.c index e8a601ff9..7e266adbf 100644 --- a/soem/test/linux/red_test/red_test.c +++ b/soem/test/linux/red_test/red_test.c @@ -164,7 +164,7 @@ void add_timespec(struct timespec *ts, int64 addtime) sec = (addtime - nsec) / NSEC_PER_SEC; ts->tv_sec += sec; ts->tv_nsec += nsec; - if ( ts->tv_nsec > NSEC_PER_SEC ) + if ( ts->tv_nsec >= NSEC_PER_SEC ) { nsec = ts->tv_nsec % NSEC_PER_SEC; ts->tv_sec += (ts->tv_nsec - nsec) / NSEC_PER_SEC; diff --git a/soem/test/linux/simple_test/simple_test.c b/soem/test/linux/simple_test/simple_test.c index 09c9032a2..3f0894cae 100644 --- a/soem/test/linux/simple_test/simple_test.c +++ b/soem/test/linux/simple_test/simple_test.c @@ -25,12 +25,6 @@ volatile int wkc; boolean inOP; uint8 currentgroup = 0; -int servo_setup(uint16 slave) -{ - return 0; -} - - void simpletest(char *ifname) { int i, j, oloop, iloop, chk; @@ -43,15 +37,15 @@ void simpletest(char *ifname) if (ec_init(ifname)) { printf("ec_init on %s succeeded.\n",ifname); - - /* find and auto-config slaves */ - if ( ec_config_init(FALSE) > 0 ) + /* find and auto-config slaves */ + + + if ( ec_config_init(FALSE) > 0 ) { printf("%d slaves found and configured.\n",ec_slavecount); - ec_slave[1].PO2SOconfig = &servo_setup; - // Setup IO map ec_config_map(&IOmap); + ec_configdc(); printf("Slaves mapped, state to SAFE_OP.\n"); @@ -85,29 +79,25 @@ void simpletest(char *ifname) ec_statecheck(0, EC_STATE_OPERATIONAL, 50000); } while (chk-- && (ec_slave[0].state != EC_STATE_OPERATIONAL)); - - if (ec_slave[0].state == EC_STATE_OPERATIONAL ) + if (ec_slave[0].state == EC_STATE_OPERATIONAL ) { printf("Operational state reached for all slaves.\n"); inOP = TRUE; - - /* cyclic loop */ - for(i = 1; i <= 5000; i++) + /* cyclic loop */ + for(i = 1; i <= 10000; i++) { - ec_send_processdata(); - wkc = ec_receive_processdata(EC_TIMEOUTRET); + ec_send_processdata(); + wkc = ec_receive_processdata(EC_TIMEOUTRET); if(wkc >= expectedWKC) { printf("Processdata cycle %4d, WKC %d , O:", i, wkc); - // Print current master outputs for(j = 0 ; j < oloop; j++) { printf(" %2.2x", *(ec_slave[0].outputs + j)); } - // Print current master inputs printf(" I:"); for(j = 0 ; j < iloop; j++) { @@ -116,7 +106,7 @@ void simpletest(char *ifname) printf(" T:%"PRId64"\r",ec_DCtime); needlf = TRUE; } - osal_usleep(1000); + osal_usleep(5000); } inOP = FALSE; @@ -149,7 +139,7 @@ void simpletest(char *ifname) } else { - printf("No socket connection on %s\nExcecute as root\n",ifname); + printf("No socket connection on %s\nExecute as root\n",ifname); } } @@ -234,47 +224,19 @@ int main(int argc, char *argv[]) { printf("SOEM (Simple Open EtherCAT Master)\nSimple test\n"); - ec_adaptert* it_adapter = NULL; - ec_adaptert* se_adapter = NULL; - - // Scan for adapters - it_adapter = ec_find_adapters(); - se_adapter = it_adapter; - int id = -1; - - // Print to screen - while (it_adapter != NULL) + if (argc > 1) { - // Print adapter info - id++; - printf("%d: Description : %s, Device to use for wpcap: %s\n", id, it_adapter->desc, it_adapter->name); - it_adapter = it_adapter->next; + /* 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); + /* start cyclic part */ + simpletest(argv[1]); } - - // Select the one to use - int s = -1; - while (s < 0 || s > id) + else { - printf("\nSelect ethernet adapter: "); - scanf("%d", &s); - getchar(); + printf("Usage: simple_test ifname1\nifname = eth0 for example\n"); } - // Iterate to the selected adapter - for (int i = 0; i < s; i++) - se_adapter = se_adapter->next; - - // Print adapter info - printf("\nSelected Adapter : %s\n\n", se_adapter->desc); - - /* 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); - - /* start cyclic part */ - simpletest(se_adapter->name); - - printf("Press any key to quit program"); - getchar(); + printf("End program\n"); return (0); } diff --git a/soem/test/linux/slaveinfo/slaveinfo.c b/soem/test/linux/slaveinfo/slaveinfo.c index 32ed57546..438027642 100644 --- a/soem/test/linux/slaveinfo/slaveinfo.c +++ b/soem/test/linux/slaveinfo/slaveinfo.c @@ -621,52 +621,30 @@ char ifbuf[1024]; int main(int argc, char *argv[]) { - ec_adaptert* it_adapter = NULL; - ec_adaptert* se_adapter = NULL; + ec_adaptert * adapter = NULL; + printf("SOEM (Simple Open EtherCAT Master)\nSlaveinfo\n"); - printf("SOEM (Simple Open EtherCAT Master)\nSlaveinfo\n\n"); - - // Set slave gather vars - for (int i = 1; i < argc; i++) + if (argc > 1) { - if ((strncmp(argv[i], "-sdo", sizeof("-sdo")) == 0)) printSDO = TRUE; - if ((strncmp(argv[i], "-map", sizeof("-map")) == 0)) printMAP = TRUE; + 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); } - - // Scan for adapters - it_adapter = ec_find_adapters(); - se_adapter = it_adapter; - int id = -1; - - // Print to screen - while (it_adapter != NULL) + else { - // Print adapter info - id++; - printf("%d: Description : %s, Device to use for wpcap: %s\n", id, it_adapter->desc, it_adapter->name); - it_adapter = it_adapter->next; - } + printf("Usage: slaveinfo ifname [options]\nifname = eth0 for example\nOptions :\n -sdo : print SDO info\n -map : print mapping\n"); - // Select the one to use - int s = -1; - while (s < 0 || s > id) - { - printf("\nSelect ethernet adapter: "); - scanf("%d", &s); - getchar(); + 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; + } } - // Iterate to the selected adapter - for(int i = 0; i < s; i++) - se_adapter = se_adapter->next; - - // Print adapter info - printf("\nSelected Adapter : %s\n\n", se_adapter->desc); - - // Get all network slave information - slaveinfo(se_adapter->name); - - printf("Press any key to quit program"); - getchar(); + printf("End program\n"); return (0); } diff --git a/soem/test/win32/eepromtool/CMakeLists.txt b/soem/test/win32/eepromtool/CMakeLists.txt deleted file mode 100644 index 92d6e1cf9..000000000 --- a/soem/test/win32/eepromtool/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ - -set(SOURCES eepromtool.c) -add_executable(eepromtool ${SOURCES}) -target_link_libraries(eepromtool soem) -install(TARGETS eepromtool DESTINATION bin) diff --git a/soem/test/win32/red_test/red_test.c b/soem/test/win32/red_test/red_test.c index 4bf970590..0a5d5e41f 100644 --- a/soem/test/win32/red_test/red_test.c +++ b/soem/test/win32/red_test/red_test.c @@ -142,7 +142,7 @@ void add_timespec(struct timespec *ts, int64 addtime) sec = (addtime - nsec) / NSEC_PER_SEC; ts->tv_sec += sec; ts->tv_nsec += nsec; - if ( ts->tv_nsec > NSEC_PER_SEC ) + if ( ts->tv_nsec >= NSEC_PER_SEC ) { nsec = ts->tv_nsec % NSEC_PER_SEC; ts->tv_sec += (ts->tv_nsec - nsec) / NSEC_PER_SEC; diff --git a/soem/test/win32/simple_test/CMakeLists.txt b/soem/test/win32/simple_test/CMakeLists.txt deleted file mode 100644 index 196e19966..000000000 --- a/soem/test/win32/simple_test/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ - -set(SOURCES simple_test.c) -add_executable(simple_test ${SOURCES}) -target_link_libraries(simple_test soem) -install(TARGETS simple_test DESTINATION bin) diff --git a/soem/test/win32/simple_test/simple_test.c b/soem/test/win32/simple_test/simple_test.c index dea4bb8a2..d38fbeba1 100644 --- a/soem/test/win32/simple_test/simple_test.c +++ b/soem/test/win32/simple_test/simple_test.c @@ -27,68 +27,95 @@ volatile int rtcnt; boolean inOP; uint8 currentgroup = 0; -typedef struct PACKED -{ - uint32_t mOperatingMode; - int32_t mRequestedPosition; - uint32_t mVelocity; - uint32_t mAcceleration; - uint32_t mTorque; - uint32_t mAnalogueInput; -} MAC_400_OUTPUTS; - -typedef struct PACKED -{ - uint32_t mOperatingMode; - int32_t mActualPosition; - uint32_t mActualVelocity; - uint32_t mAnalogueInput; - uint32_t mErrorStatus; - uint32_t mActualTorque; - uint32_t mFollowError; - uint32_t mActualTemperature; -} MAC_400_INPUTS; - /* 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]++; - // Read info - MAC_400_INPUTS* inputs = (MAC_400_INPUTS*)ec_slave[1].inputs; - inputs->mErrorStatus; - - // Write info - MAC_400_OUTPUTS* mac_outputs = (MAC_400_OUTPUTS*)ec_slave[1].outputs; - mac_outputs->mOperatingMode = 2; - mac_outputs->mRequestedPosition = -100000; - mac_outputs->mVelocity = 2700; - mac_outputs->mAcceleration = 360; - mac_outputs->mTorque = 341; - ec_send_processdata(); wkc = ec_receive_processdata(EC_TIMEOUTRET); rtcnt++; /* do RT control stuff here */ } -int MAC400_SETUP(uint16 slave) +int EL7031setup(uint16 slave) { - uint32_t new_pos = 0; - ec_SDOwrite(slave, 0x2012, 0x04, FALSE, sizeof(new_pos), &new_pos, EC_TIMEOUTSAFE); + 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; - // Force motor on zero. - uint32_t control_word = 0; - control_word |= 1UL << 6; - control_word |= 0x0 << 8; - ec_SDOwrite(slave, 0x2012, 0x24, FALSE, sizeof(control_word), &control_word, EC_TIMEOUTSAFE); + // 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; + int i, j, oloop, iloop, wkc_count, chk, slc; UINT mmResult; needlf = FALSE; @@ -102,14 +129,35 @@ void simpletest(char *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); - // Install configure callback - ec_slave[1].PO2SOconfig = &MAC400_SETUP; - - ec_config_map(&IOmap); + 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"); @@ -153,7 +201,7 @@ void simpletest(char *ifname) /* cyclic loop, reads data from RT thread */ - for(i = 1; i <= 1500; i++) + for(i = 1; i <= 500; i++) { if(wkc >= expectedWKC) { @@ -172,7 +220,7 @@ void simpletest(char *ifname) printf(" T:%lld\r",ec_DCtime); needlf = TRUE; } - osal_usleep(5000); + osal_usleep(50000); } inOP = FALSE; @@ -195,17 +243,9 @@ void simpletest(char *ifname) timeKillEvent(mmResult); printf("\nRequest init state for all slaves\n"); - - /* request INIT state for all slaves */ - chk = 200; - ec_slave[0].state = EC_STATE_INIT; + ec_slave[0].state = EC_STATE_INIT; + /* request INIT state for all slaves */ ec_writestate(0); - do - { - ec_statecheck(0, EC_STATE_INIT, 50000); - } while (chk-- && (ec_slave[0].state != EC_STATE_INIT)); - - } else { @@ -296,55 +336,38 @@ OSAL_THREAD_FUNC ecatcheck(void *lpParam) } osal_usleep(10000); } + + return 0; } char ifbuf[1024]; int main(int argc, char *argv[]) { - printf("SOEM (Simple Open EtherCAT Master)\nSimple test\n"); - - ec_adaptert* it_adapter = NULL; - ec_adaptert* se_adapter = NULL; - - // Scan for adapters - it_adapter = ec_find_adapters(); - se_adapter = it_adapter; - int id = -1; - - // Print to screen - while (it_adapter != NULL) - { - // Print adapter info - id++; - printf("%d: Description : %s, Device to use for wpcap: %s\n", id, it_adapter->desc, it_adapter->name); - it_adapter = it_adapter->next; - } - - // Select the one to use - int s = -1; - while (s < 0 || s > id) - { - printf("\nSelect ethernet adapter: "); - scanf("%d", &s); - getchar(); - } - - // Iterate to the selected adapter - for (int i = 0; i < s; i++) - se_adapter = se_adapter->next; - - // Print adapter info - printf("\nSelected Adapter : %s\n\n", se_adapter->desc); - - /* 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); - - /* start cyclic part */ - simpletest(se_adapter->name); - - printf("Press any key to quit program"); - getchar(); - return (0); + 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); } diff --git a/soem/test/win32/slaveinfo/CMakeLists.txt b/soem/test/win32/slaveinfo/CMakeLists.txt deleted file mode 100644 index dd594f2f4..000000000 --- a/soem/test/win32/slaveinfo/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ - -set(SOURCES slaveinfo.c) -add_executable(slaveinfo ${SOURCES}) -target_link_libraries(slaveinfo soem) -install(TARGETS slaveinfo DESTINATION bin) diff --git a/soem/test/win32/slaveinfo/slaveinfo.c b/soem/test/win32/slaveinfo/slaveinfo.c index 32ed57546..9485c5ad7 100644 --- a/soem/test/win32/slaveinfo/slaveinfo.c +++ b/soem/test/win32/slaveinfo/slaveinfo.c @@ -233,7 +233,7 @@ int si_PDOassign(uint16 slave, uint16 PDOassign, int mapoffset, int bitoffset) /* read PDO assign */ wkc = ec_SDOread(slave, PDOassign, (uint8)idxloop, FALSE, &rdl, &rdat, EC_TIMEOUTRXM); /* result is index of PDO */ - idx = etohs(rdat); + idx = etohl(rdat); if (idx > 0) { rdl = sizeof(subcnt); subcnt = 0; @@ -414,16 +414,12 @@ int si_siiPDO(uint16 slave, uint8 t, int mapoffset, int bitoffset) PDO->BitSize[PDO->nPDO] += bitlen; a += 2; - /* skip entry if filler (0x0000:0x00) */ - if(obj_idx || obj_subidx) - { - str_name[0] = 0; - if(obj_name) - ec_siistring(str_name, slave, obj_name); + 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); - } + 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; } @@ -558,14 +554,14 @@ void slaveinfo(char *ifname) 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, etohs(ec_slave[cnt].SM[nSM].StartAddr), etohs(ec_slave[cnt].SM[nSM].SMlength), - etohl(ec_slave[cnt].SM[nSM].SMflags), ec_slave[cnt].SMtype[nSM]); + 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, - etohl(ec_slave[cnt].FMMU[j].LogStart), etohs(ec_slave[cnt].FMMU[j].LogLength), ec_slave[cnt].FMMU[j].LogStartbit, - ec_slave[cnt].FMMU[j].LogEndbit, etohs(ec_slave[cnt].FMMU[j].PhysStart), ec_slave[cnt].FMMU[j].PhysStartBit, + (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", @@ -621,52 +617,30 @@ char ifbuf[1024]; int main(int argc, char *argv[]) { - ec_adaptert* it_adapter = NULL; - ec_adaptert* se_adapter = NULL; - - printf("SOEM (Simple Open EtherCAT Master)\nSlaveinfo\n\n"); - - // Set slave gather vars - for (int i = 1; i < argc; i++) - { - if ((strncmp(argv[i], "-sdo", sizeof("-sdo")) == 0)) printSDO = TRUE; - if ((strncmp(argv[i], "-map", sizeof("-map")) == 0)) printMAP = TRUE; - } - - // Scan for adapters - it_adapter = ec_find_adapters(); - se_adapter = it_adapter; - int id = -1; + ec_adaptert * adapter = NULL; + printf("SOEM (Simple Open EtherCAT Master)\nSlaveinfo\n"); - // Print to screen - while (it_adapter != NULL) + if (argc > 1) { - // Print adapter info - id++; - printf("%d: Description : %s, Device to use for wpcap: %s\n", id, it_adapter->desc, it_adapter->name); - it_adapter = it_adapter->next; + 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); } - - // Select the one to use - int s = -1; - while (s < 0 || s > id) + else { - printf("\nSelect ethernet adapter: "); - scanf("%d", &s); - getchar(); + 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; + } } - // Iterate to the selected adapter - for(int i = 0; i < s; i++) - se_adapter = se_adapter->next; - - // Print adapter info - printf("\nSelected Adapter : %s\n\n", se_adapter->desc); - - // Get all network slave information - slaveinfo(se_adapter->name); - - printf("Press any key to quit program"); - getchar(); + printf("End program\n"); return (0); }