Skip to content

Commit

Permalink
Merge branch 'master' into p2o_user_data
Browse files Browse the repository at this point in the history
  • Loading branch information
bnjmnp committed Mar 28, 2022
2 parents 473f90d + 9b6ebd6 commit 1540138
Show file tree
Hide file tree
Showing 46 changed files with 994 additions and 516 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: build
on: [push, pull_request]
env:
BUILD_TYPE: Release
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- ubuntu-latest
- ubuntu-20.04
- ubuntu-18.04
- macos-latest
- windows-latest
steps:
- uses: actions/checkout@v2
with:
submodules: true

- name: Configure
shell: bash
run: |
cmake -E make_directory $GITHUB_WORKSPACE/build
cmake -B $GITHUB_WORKSPACE/build -S $GITHUB_WORKSPACE \
-DCMAKE_BUILD_TYPE=$BUILD_TYPE
- name: Build
shell: bash
run: |
cmake --build $GITHUB_WORKSPACE/build -j4 --target install
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
build*
build*/
install
*~
/doc/latex
Expand Down
14 changes: 0 additions & 14 deletions .travis.yml

This file was deleted.

26 changes: 18 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
cmake_minimum_required(VERSION 2.8.12)
cmake_minimum_required(VERSION 3.9)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/cmake/Modules")
project(SOEM C)
project(SOEM
DESCRIPTION "Simple Open EtherCAT Master"
VERSION 1.4.0
LANGUAGES C)

if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
# Default to installing in SOEM source directory
Expand All @@ -9,7 +12,13 @@ endif()

set(SOEM_INCLUDE_INSTALL_DIR include/soem)
set(SOEM_LIB_INSTALL_DIR lib)
set(BUILD_TESTS TRUE)

if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
set(BUILD_TESTS TRUE)
else()
message(STATUS "SOEM: not building tests when built as dependency")
set(BUILD_TESTS FALSE)
endif()

if(WIN32)
set(OS "win32")
Expand All @@ -33,8 +42,8 @@ elseif(APPLE)
set(OS_LIBS pthread pcap)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "rt-kernel")
set(OS "rtk")
message("ARCH is ${ARCH}")
message("BSP is ${BSP}")
message(STATUS "ARCH is ${ARCH}")
message(STATUS "BSP is ${BSP}")
include_directories(oshw/${OS}/${ARCH})
file(GLOB OSHW_EXTRA_SOURCES oshw/${OS}/${ARCH}/*.c)
set(OSHW_SOURCES "${OS_HW_SOURCES} ${OSHW_ARCHSOURCES}")
Expand All @@ -44,13 +53,13 @@ elseif(${CMAKE_SYSTEM_NAME} MATCHES "rt-kernel")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-format")
set(OS_LIBS "-Wl,--start-group -l${BSP} -l${ARCH} -lkern -ldev -lsio -lblock -lfs -lusb -llwip -leth -li2c -lrtc -lcan -lnand -lspi -lnor -lpwm -ladc -ltrace -lc -lm -Wl,--end-group")
elseif(${CMAKE_SYSTEM_NAME} MATCHES "rtems")
message("Building for RTEMS")
message(STATUS "Building for RTEMS")
set(OS "rtems")
set(SOEM_LIB_INSTALL_DIR ${LIB_DIR})
set(BUILD_TESTS FALSE)
endif()

message("OS is ${OS}")
message(STATUS "OS is ${OS}")

file(GLOB SOEM_SOURCES soem/*.c)
file(GLOB OSAL_SOURCES osal/${OS}/*.c)
Expand Down Expand Up @@ -84,7 +93,7 @@ target_include_directories(soem
$<INSTALL_INTERFACE:include/soem>
)

message("LIB_DIR: ${SOEM_LIB_INSTALL_DIR}")
message(STATUS "LIB_DIR: ${SOEM_LIB_INSTALL_DIR}")

install(TARGETS soem EXPORT soemConfig DESTINATION ${SOEM_LIB_INSTALL_DIR})

Expand All @@ -97,6 +106,7 @@ install(FILES
DESTINATION ${SOEM_INCLUDE_INSTALL_DIR})

if(BUILD_TESTS)
add_subdirectory(test/simple_ng)
add_subdirectory(test/linux/slaveinfo)
add_subdirectory(test/linux/eepromtool)
add_subdirectory(test/linux/simple_test)
Expand Down
1 change: 1 addition & 0 deletions Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,7 @@ WARN_LOGFILE =
INPUT = doc/tutorial.txt \
doc/soem.dox \
soem \
test/simple_ng \
test/linux/ebox \
test/linux/eepromtool \
test/linux/red_test \
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
========
Expand All @@ -9,7 +8,7 @@ BUILDING
Prerequisites for all platforms
-------------------------------

* CMake 2.8.0 or later
* CMake 3.9 or later


Windows (Visual Studio)
Expand Down
10 changes: 0 additions & 10 deletions appveyor.yml

This file was deleted.

4 changes: 2 additions & 2 deletions doc/soem.dox
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@
*
* \section start Getting started
*
* For examples see simple_test.c in ~/test/linux/simple_test.
* First try (assume EtherCAT on eth0): sudo ./simple_test eth0
* For examples see simple_ng.c in ~/test/simple_ng.
* First try (assume EtherCAT on eth0): sudo ./simple_ng eth0
* As SOEM uses RAW sockets it will need to run as root.
*
* \section bugs Squashed bugs
Expand Down
42 changes: 21 additions & 21 deletions osal/linux/osal.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,15 @@ int osal_usleep (uint32 usec)
return nanosleep(&ts, NULL);
}

int osal_gettimeofday(struct timeval *tv, struct timezone *tz)
{
struct timespec ts;
int return_value;
(void)tz; /* Not used */

/* Use clock_gettime to prevent possible live-lock.
* Gettimeofday uses CLOCK_REALTIME that can get NTP timeadjust.
* If this function preempts timeadjust and it uses vpage it live-locks.
* Also when using XENOMAI, only clock_gettime is RT safe */
return_value = clock_gettime(CLOCK_MONOTONIC, &ts);
tv->tv_sec = ts.tv_sec;
tv->tv_usec = ts.tv_nsec / 1000;
return return_value;
}

ec_timet osal_current_time(void)
{
struct timeval current_time;
struct timespec current_time;
ec_timet return_value;

osal_gettimeofday(&current_time, 0);
clock_gettime(CLOCK_REALTIME, &current_time);
return_value.sec = current_time.tv_sec;
return_value.usec = current_time.tv_usec;
return_value.usec = current_time.tv_nsec / 1000;

return return_value;
}

Expand All @@ -60,13 +45,28 @@ void osal_time_diff(ec_timet *start, ec_timet *end, ec_timet *diff)
}
}

/* Returns time from some unspecified moment in past,
* strictly increasing, used for time intervals measurement. */
static void osal_getrelativetime(struct timeval *tv)
{
struct timespec ts;

/* Use clock_gettime to prevent possible live-lock.
* Gettimeofday uses CLOCK_REALTIME that can get NTP timeadjust.
* If this function preempts timeadjust and it uses vpage it live-locks.
* Also when using XENOMAI, only clock_gettime is RT safe */
clock_gettime(CLOCK_MONOTONIC, &ts);
tv->tv_sec = ts.tv_sec;
tv->tv_usec = ts.tv_nsec / 1000;
}

void osal_timer_start(osal_timert * self, uint32 timeout_usec)
{
struct timeval start_time;
struct timeval timeout;
struct timeval stop_time;

osal_gettimeofday(&start_time, 0);
osal_getrelativetime(&start_time);
timeout.tv_sec = timeout_usec / USECS_PER_SEC;
timeout.tv_usec = timeout_usec % USECS_PER_SEC;
timeradd(&start_time, &timeout, &stop_time);
Expand All @@ -81,7 +81,7 @@ boolean osal_timer_is_expired (osal_timert * self)
struct timeval stop_time;
int is_not_yet_expired;

osal_gettimeofday(&current_time, 0);
osal_getrelativetime(&current_time);
stop_time.tv_sec = self->stop_time.sec;
stop_time.tv_usec = self->stop_time.usec;
is_not_yet_expired = timercmp(&current_time, &stop_time, <);
Expand Down
34 changes: 17 additions & 17 deletions oshw/erika/nicdrv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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)
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
Loading

0 comments on commit 1540138

Please sign in to comment.