Skip to content

Commit

Permalink
Merge pull request eclipse-4diac#74 from eclipse-4diac/develop
Browse files Browse the repository at this point in the history
Merge Develop to Freeze
  • Loading branch information
azoitl authored Apr 10, 2024
2 parents 2ee5548 + 8c15717 commit 249049e
Show file tree
Hide file tree
Showing 117 changed files with 4,972 additions and 980 deletions.
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
42 changes: 30 additions & 12 deletions .github/workflows/cmake-multi-platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@ jobs:
#
# To add more build types (Release, Debug, RelWithDebInfo, etc.) customize the build_type list.
matrix:
#os: [ubuntu-latest, windows-latest]
os: [ubuntu-latest]
os: [ubuntu-latest, windows-latest]
build_type: [Debug]
c_compiler: [gcc, clang, cl]
include:
# - os: windows-latest
# c_compiler: cl
# cpp_compiler: cl
# architecture: "Win32"
- os: windows-latest
c_compiler: cl
cpp_compiler: cl
architecture: "Win32"
- os: ubuntu-latest
c_compiler: gcc
cpp_compiler: g++
Expand All @@ -41,10 +40,10 @@ jobs:
cpp_compiler: clang++
architecture: "Posix"
exclude:
# - os: windows-latest
# c_compiler: gcc
# - os: windows-latest
# c_compiler: clang
- os: windows-latest
c_compiler: gcc
- os: windows-latest
c_compiler: clang
- os: ubuntu-latest
c_compiler: cl

Expand All @@ -58,9 +57,14 @@ jobs:
run: |
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
- name: Install libboost
- name: Install libboost (Linux)
if: ${{ matrix.os != 'windows-latest' }}
run: sudo apt-get install -y libboost-all-dev

- name: Install boost (Windows)
if: ${{ matrix.os == 'windows-latest' }}
run: nuget install boost -Version 1.84.0

- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
Expand All @@ -72,7 +76,21 @@ jobs:
-S ${{ github.workspace }}
-DFORTE_ARCHITECTURE=${{ matrix.architecture }}
-DFORTE_COM_ETH=ON
-DFORTE_COM_FBDK=ON
-DFORTE_COM_HTTP=ON
-DFORTE_COM_LOCAL=ON
-DFORTE_COM_RAW=ON
-DFORTE_COM_SER=ON
-DFORTE_COM_STRUCT_MEMBER=ON
-DFORTE_IO=ON
-DFORTE_MODULE_CONVERT=ON
-DFORTE_MODULE_IEC61131=ON
-DFORTE_MODULE_RECONFIGURATION=ON
-DFORTE_MODULE_RT_Events=ON
-DFORTE_MODULE_SIGNALPROCESSING=ON
-DFORTE_MODULE_UTILS=ON
-DFORTE_TESTS=ON
${{ matrix.os == 'windows-latest' && format('-DFORTE_TESTS_INC_DIRS={0}/boost.1.84.0/lib/native/include', github.workspace) || '' }}
- name: Build
# Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
Expand All @@ -82,4 +100,4 @@ jobs:
working-directory: ${{ steps.strings.outputs.build-output-dir }}
# Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest --build-config ${{ matrix.build_type }}
run: ctest --build-config ${{ matrix.build_type }} --output-on-failure
4 changes: 0 additions & 4 deletions buildsupport/forte.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,8 @@ MACRO(forte_add_directory_module)
forte_add_module(${MODULENAME} OFF ${DESCRIPTION})
ENDMACRO(forte_add_directory_module)

#MACRO(forte_add_io NAME DIRECTORY DESCRIPTION)
MACRO(forte_add_io NAME DESCRIPTION)
set(FORTE_IO_${NAME} OFF CACHE BOOL "${DESCRIPTION}")
if(NOT FORTE_IO_${NAME})
return()
endif(NOT FORTE_IO_${NAME})
ENDMACRO(forte_add_io)

set(FORTE_SRC_DIR ${CMAKE_CURRENT_LIST_DIR}/../src CACHE INTERNAL "")
Expand Down
23 changes: 16 additions & 7 deletions setup_zephyr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,35 @@ if [ -d "$forte_bin_dir" ]; then
-DFORTE_ARCHITECTURE=Zephyr \
-DFORTE_TESTS=OFF \
-DFORTE_SUPPORT_BOOT_FILE=ON \
-DFORTE_MODULE_CONVERT=ON \
-DFORTE_BUILD_EXECUTABLE=OFF \
-DFORTE_BUILD_STATIC_LIBRARY=ON \
-DFORTE_MODULE_CONVERT=ON \
-DFORTE_MODULE_IEC61131=ON \
-DCMAKE_C_FLAGS_DEBUG="-g" \
-DCMAKE_BUILD_TYPE=MINSIZEREL \
-DFORTE_LOGLEVEL=NOLOG \
-DFORTE_IO=ON \
-DFORTE_IO_ZEPHYR=ON \
-DFORTE_COM_ETH=ON \
-DFORTE_COM_FBDK=ON \
-DFORTE_COM_LOCAL=ON \
-DFORTE_MODULE_UTILS=ON \
-DFORTE_SOURCE_DIR="${forte_src_dir}" \
-DFORTE_TESTS_INC_DIRS="${forte_boost_test_inc_dirs}" \
-DFORTE_TESTS_LINK_DIRS="${forte_boost_test_inc_dirs}" \
-DFORTE_EXTERNAL_MODULES_DIRECTORY="${forte_external_modules_dir}" \
-DCMAKE_C_COMPILER="${CMAKE_C_COMPILER}" \
-DCMAKE_CXX_COMPILER="${CMAKE_CXX_COMPILER}" \
-DFORTE_LOGLEVEL=LOGINFO \
-DCMAKE_BUILD_TYPE=MINSIZEREL \
-DCMAKE_C_FLAGS="${CMAKE_C_FLAGS}" \
-DCMAKE_C_FLAGS_DEBUG="-g ${CMAKE_C_FLAGS}" \
-DCMAKE_C_FLAGS_MINSIZEREL="-Os -DNDEBUG ${CMAKE_C_FLAGS}" \
-DCMAKE_C_FLAGS_RELEASE="-O3 -DNDEBUG ${CMAKE_C_FLAGS}" \
-DCMAKE_C_FLAGS_RELWITHDEBINFO="-O2 -g -DNDEBUG ${CMAKE_C_FLAGS}" \
-DCMAKE_CXX_FLAGS="${CMAKE_CXX_FLAGS}" \
-DCMAKE_CXX_FLAGS_DEBUG="-g ${CMAKE_CXX_FLAGS}" \
-DCMAKE_CXX_FLAGS_MINSIZEREL="-Os -DNDEBUG ${CMAKE_CXX_FLAGS}" \
-DCMAKE_CXX_FLAGS_RELEASE="-O3 -DNDEBUG ${CMAKE_CXX_FLAGS}" \
-DCMAKE_CXX_FLAGS_RELWITHDEBINFO="-O2 -g -DNDEBUG ${CMAKE_CXX_FLAGS}" \
-DFORTE_ZEPHYR_INCLUDES="${FORTE_ZEPHYR_INCLUDES}" \
-DFORTE_SOURCE_DIR="${forte_src_dir}" \
-DFORTE_TESTS_INC_DIRS="${forte_boost_test_inc_dirs}" \
-DFORTE_TESTS_LINK_DIRS="${forte_boost_test_inc_dirs}" \
../../

else
Expand Down
14 changes: 10 additions & 4 deletions src/arch/bsdsocketinterf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ int CBSDSocketInterface::receiveDataFromTCP(TSocketDescriptor paSockD, char* paD
int nRetVal;
do{
nRetVal = static_cast<int>(recv(paSockD, paData, paBufSize, 0));
} while((-1 == nRetVal) && (EINTR == errno)); // recv got interrupt / recieving again
} while((-1 == nRetVal) && (EINTR == errno)); // recv got interrupt / receiving again

if(nRetVal == -1){
DEVLOG_ERROR("CBSDSocketInterface: TCP-Socket recv() failed: %s\n", strerror(errno));
Expand Down Expand Up @@ -175,7 +175,11 @@ CBSDSocketInterface::TSocketDescriptor CBSDSocketInterface::openUDPSendPort(char
DEVLOG_WARNING("CBSDSocketInterface: setsockopt(IP_MULTICAST_IF) failed: %s\n", strerror(errno));
}
}
#endif
#else // __ZEPHYR__
if (paMCInterface) {
setupMulticastGroup(paIPAddr, paMCInterface);
}
#endif // __ZEPHYR__

#ifdef NET_OS
/* following is typedef void TM_fAR * in treck/include/trsocket.h */
Expand Down Expand Up @@ -239,7 +243,9 @@ CBSDSocketInterface::TSocketDescriptor CBSDSocketInterface::openUDPReceivePort(c
//if this fails we may have given a non multicasting addr. For now we accept this. May need to be changed in the future.
DEVLOG_WARNING("CBSDSocketInterface: setsockopt(IP_ADD_MEMBERSHIP) failed: %s\n", strerror(errno));
}
#endif
#else // __ZEPHYR__
setupMulticastGroup(paIPAddr, paMCInterface);
#endif // __ZEPHYR__

nRetVal = nSocket;
}
Expand Down Expand Up @@ -282,7 +288,7 @@ int CBSDSocketInterface::receiveDataFromUDP(TSocketDescriptor paSockD, char* paD
int nRetVal;
do{
nRetVal = static_cast<int>(recvfrom(paSockD, paData, paBufSize, 0, nullptr, nullptr));
} while((-1 == nRetVal) && (EINTR == errno)); // recv got interrupt / recieving again
} while((-1 == nRetVal) && (EINTR == errno)); // recv got interrupt / receiving again

if(nRetVal == -1){ //
DEVLOG_ERROR("CBSDSocketInterface: UDP-Socket recvfrom() failed: %s\n", strerror(errno));
Expand Down
6 changes: 5 additions & 1 deletion src/arch/devlog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
#endif // FORTE_STACKTRACE_CXX23
#endif // FORTE_STACKTRACE

#ifdef __ZEPHYR__
#include <zephyr/logging/log.h>
#endif // __ZEPHYR__

static const char* scLogLevel[] = { "INFO", "WARNING", "ERROR", "DEBUG", "TRACE" };

//this define allows to provide an own log handler (see LMS for an example of this)
Expand Down Expand Up @@ -96,7 +100,7 @@ void printLogMessage(E_MsgLevel paLevel, const char *paMessage) {
#ifndef __ZEPHYR__
fprintf(stderr, "%s: T#%" PRIuFAST64 ": %s", scLogLevel[static_cast<int>(paLevel)], getNanoSecondsMonotonic(), paMessage);
#else
printk("%s: T#%" PRIuFAST64 ": %s", scLogLevel[static_cast<int>(paLevel)], getNanoSecondsMonotonic(), paMessage);
LOG_PRINTK("%s: T#%" PRIuFAST64 ": %s", scLogLevel[static_cast<int>(paLevel)], getNanoSecondsMonotonic(), paMessage);
#endif // __ZEPHYR__
}

Expand Down
2 changes: 1 addition & 1 deletion src/arch/ecos/nios2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ if("${FORTE_ARCHITECTURE}" STREQUAL "Nios2")
else(FORTE_FAKE_TIME)
forte_add_sourcefile_hcpp(../ecostiha)
endif(FORTE_FAKE_TIME)
forte_add_sourcefile_cpp(../../posix/forte_architecture_time.cpp)
forte_add_sourcefile_cpp(../../posix/forte_architecture_time.cpp ../../forte_standard_time.cpp)

forte_add_sourcefile_cpp(../ecoscppinit.cpp ../../genforte_printer.cpp ../forte_architecture.cpp)
forte_add_sourcefile_h(../../forte_architecture_time.h)
Expand Down
2 changes: 1 addition & 1 deletion src/arch/ecos/phycoreat91/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ if("${FORTE_ARCHITECTURE}" STREQUAL "Phycore AT91")
else(FORTE_FAKE_TIME)
forte_add_sourcefile_hcpp(../ecostiha)
endif(FORTE_FAKE_TIME)
forte_add_sourcefile_cpp(../../posix/forte_architecture_time.cpp)
forte_add_sourcefile_cpp(../../posix/forte_architecture_time.cpp ../../forte_standard_time.cpp)

forte_add_sourcefile_cpp(../../genforte_printer.cpp)
forte_add_sourcefile_h(../../forte_architecture_time.h)
Expand Down
27 changes: 27 additions & 0 deletions src/arch/forte_standard_time.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*******************************************************************************
* Copyright (c) 2024 Samator Indo Gas
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Ketut Kumajaya - Create a common standard C++ time implementation
*******************************************************************************/

#include <chrono>

using namespace std::chrono;

#include "forte_architecture_time.h"

#ifndef FORTE_FAKE_TIME
uint_fast64_t getNanoSecondsMonotonic() {
return static_cast<uint_fast64_t>(duration_cast<nanoseconds>(steady_clock::now().time_since_epoch()).count());
}

uint_fast64_t getNanoSecondsRealtime() {
return static_cast<uint_fast64_t>(duration_cast<nanoseconds>(system_clock::now().time_since_epoch()).count());
}
#endif
4 changes: 2 additions & 2 deletions src/arch/fortenew.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* TODO try std new with nothrow.
*/

#if __cplusplus >= 201103L //stdc11
#if __cplusplus >= 201103L || _MSVC_LANG >= 201103L //stdc11
inline
void* operator new(size_t paSize) {
return forte_malloc(paSize);
Expand All @@ -57,7 +57,7 @@ void operator delete[](void* paData) noexcept{
}
}

# if __cplusplus >= 201402L //stdc14
# if __cplusplus >= 201402L || _MSVC_LANG >= 201402L //stdc14
inline
void operator delete(void* paData, std::size_t) noexcept{
if (paData){
Expand Down
2 changes: 1 addition & 1 deletion src/arch/macos/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ if("${FORTE_ARCHITECTURE}" STREQUAL "MacOs")
else(FORTE_FAKE_TIME)
forte_set_timer(../posix/pctimeha)
endif(FORTE_FAKE_TIME)
forte_add_sourcefile_cpp(../posix/forte_architecture_time.cpp)
forte_add_sourcefile_cpp(../posix/forte_architecture_time.cpp ../forte_standard_time.cpp)

forte_add_sourcefile_hcpp(../posix/forte_thread forte_sync forte_sem)
forte_add_sourcefile_cpp(../genforte_printer.cpp)
Expand Down
2 changes: 1 addition & 1 deletion src/arch/plcnext/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ if("${FORTE_ARCHITECTURE}" STREQUAL "PLCnext")
else(FORTE_FAKE_TIME)
forte_set_timer(../posix/pctimeha)
endif(FORTE_FAKE_TIME)
forte_add_sourcefile_cpp(../posix/forte_architecture_time.cpp)
forte_add_sourcefile_cpp(../posix/forte_architecture_time.cpp ../forte_standard_time.cpp)

forte_add_sourcefile_hcpp(../posix/forte_thread ../posix/forte_sync ../posix/forte_sem)
forte_add_sourcefile_cpp(../genforte_printer.cpp)
Expand Down
2 changes: 1 addition & 1 deletion src/arch/posix/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ if("${FORTE_ARCHITECTURE}" STREQUAL "Posix")
else(FORTE_FAKE_TIME)
forte_set_timer(pctimeha)
endif(FORTE_FAKE_TIME)
forte_add_sourcefile_cpp(forte_architecture_time.cpp)
forte_add_sourcefile_cpp(forte_architecture_time.cpp ../forte_standard_time.cpp)

forte_add_sourcefile_hcpp(forte_thread forte_sync forte_sem)
forte_add_sourcefile_cpp(../genforte_printer.cpp)
Expand Down
20 changes: 2 additions & 18 deletions src/arch/posix/forte_architecture_time.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*******************************************************************************
* Copyright (c) 2019 TU Wien/ACIN
* 2023 Martin Erich Jobst
* 2024 Samator Indo Gas
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
Expand All @@ -10,29 +11,12 @@
* Contributors:
* Martin Melik Merkumians - Adds getNanoSecondsMonotonic
* Martin Jobst - add high-resolution realtime clock
* Ketut Kumajaya - Use the standard C++ time implementation
*******************************************************************************/

#include <time.h>

#include "forte_architecture_time.h"
#include "forte_constants.h"

#ifndef FORTE_FAKE_TIME
uint_fast64_t getNanoSecondsMonotonic() {
struct timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
return static_cast<uint_fast64_t>(now.tv_nsec) + static_cast<uint_fast64_t>(now.tv_sec) *
static_cast<uint_fast64_t>(forte::core::constants::cNanosecondsPerSecond);
}

uint_fast64_t getNanoSecondsRealtime() {
struct timespec now;
clock_gettime(CLOCK_REALTIME, &now);
return static_cast<uint_fast64_t>(now.tv_nsec) + static_cast<uint_fast64_t>(now.tv_sec) *
static_cast<uint_fast64_t>(forte::core::constants::cNanosecondsPerSecond);
}
#endif

time_t forte_timegm(struct tm *pa_tm) {
return timegm(pa_tm);
}
Expand Down
2 changes: 1 addition & 1 deletion src/arch/win32/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ if("${FORTE_ARCHITECTURE}" STREQUAL "Win32")
else()
forte_add_sourcefile_cpp(forte_sync.cpp)
endif()
forte_add_sourcefile_cpp(forte_architecture.cpp winforte_printer.cpp forte_architecture_time.cpp)
forte_add_sourcefile_cpp(forte_architecture.cpp winforte_printer.cpp forte_architecture_time.cpp ../forte_standard_time.cpp)
forte_add_sourcefile_cpp(../genforte_fileio.cpp)
forte_add_sourcefile_cpp(../genforte_realFunctions.cpp)

Expand Down
34 changes: 5 additions & 29 deletions src/arch/win32/forte_architecture_time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Copyright (c) 2019 TU Wien/ACIN
* 2022 Primetals Technologies Austria GmbH
* 2023 Martin Erich Jobst
* 2024 Samator Indo Gas
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
Expand All @@ -12,40 +13,15 @@
* Martin Melik Merkumians - Adds getNanoSecondsMonotonic
* - Optimize order of operations for time result
* Martin Jobst - add high-resolution realtime clock
* Ketut Kumajaya - Use the standard C++ time functions, fix pre Windows 8/
* Server 2012 compatibility issue
* - Move the standard C++ time functions as a common time
* implementation
*******************************************************************************/

#include <windows.h>

#include "forte_architecture_time.h"
#include "forte_constants.h"

#ifndef FORTE_FAKE_TIME
uint_fast64_t getNanoSecondsMonotonic() {
LARGE_INTEGER performance_counter;
LARGE_INTEGER performance_frequency;

QueryPerformanceCounter(&performance_counter);
QueryPerformanceFrequency(&performance_frequency);

// The clock frequency for Win10 on the Performance Timer is 10Mhz or less
// in previous versions accoording to
// https://stackoverflow.com/questions/63205226/better-than-100ns-resolution-timers-in-windows
// so it is safe to assume that forte::core::constants::cNanosecondsPerSecond >> performance_frequency.QuadPart
const uint_fast64_t timeFactor = static_cast<uint_fast64_t>(forte::core::constants::cNanosecondsPerSecond) / static_cast<uint_fast64_t>(performance_frequency.QuadPart);
return static_cast<uint_fast64_t>(performance_counter.QuadPart) * timeFactor;
}

uint_fast64_t getNanoSecondsRealtime() {
FILETIME filetime;

GetSystemTimePreciseAsFileTime(&filetime);

// The FILETIME struct stores the number of 100-nanosecond intervals since January 1, 1601 (UTC).
uint_fast64_t time = static_cast<uint_fast64_t>(filetime.dwHighDateTime) << 32 | static_cast<uint_fast64_t>(filetime.dwLowDateTime);
return (time - 116444736000000000LL) * 100LL; // convert to Unix Epoch and nanoseconds
}
#endif

time_t forte_timegm(struct tm *pa_tm) {
return _mkgmtime(pa_tm);
}
Expand Down
Loading

0 comments on commit 249049e

Please sign in to comment.