Prechádzať zdrojové kódy

Add eCos architecture

Jose Cabral 6 rokov pred
rodič
commit
36a5faa679

+ 15 - 40
CMakeLists.txt

@@ -255,27 +255,6 @@ if(UA_ENABLE_ENCRYPTION)
     list(APPEND open62541_LIBRARIES ${MBEDTLS_LIBRARIES})
 endif()
 
-if(NOT WIN32)
-  if(QNXNTO)
-    list(APPEND open62541_LIBRARIES socket)
-    list(APPEND open62541_LIBRARIES c)
-    list(APPEND open62541_LIBRARIES stdc++)
-  else()
-    list(APPEND open62541_LIBRARIES m)
-    if(UA_ENABLE_MULTITHREADING OR UA_BUILD_UNIT_TESTS)
-      list(APPEND open62541_LIBRARIES pthread)
-    endif()
-    if(NOT APPLE AND (NOT ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD"))
-      list(APPEND open62541_LIBRARIES rt)
-    endif()
-  endif()
-else()
-  list(APPEND open62541_LIBRARIES ws2_32)
-    if(UA_ENABLE_DISCOVERY_MULTICAST OR UA_ENABLE_PUBSUB)
-        list(APPEND open62541_LIBRARIES iphlpapi)
-    endif()
-endif()
-
 #####################
 # Compiler Settings #
 #####################
@@ -297,10 +276,6 @@ if(NOT UA_COMPILE_AS_CXX AND (CMAKE_COMPILER_IS_GNUCC OR "x${CMAKE_C_COMPILER_ID
                     -Wundef
                     -Wc++-compat)
 
-    if(NOT WIN32 AND NOT CYGWIN AND NOT QNXNTO AND (NOT ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD"))
-        add_definitions(-Wshadow -Wconversion -fvisibility=hidden -fPIC)
-    endif()
-
     if(UA_ENABLE_AMALGAMATION)
         add_definitions(-Wno-unused-function)
     endif()
@@ -767,12 +742,25 @@ if (UA_ENABLE_DISCOVERY_MULTICAST)
     target_compile_definitions(open62541-object PRIVATE -DMDNSD_DYNAMIC_LINKING_EXPORT)
     target_compile_definitions(open62541 PRIVATE -DMDNSD_DYNAMIC_LINKING_EXPORT)
 endif()
+# Generate properly versioned shared library links on Linux
+SET_TARGET_PROPERTIES(open62541 PROPERTIES SOVERSION 0 VERSION "${OPEN62541_VER_MAJOR}.${OPEN62541_VER_MINOR}.${OPEN62541_VER_PATCH}")
+
+##################################
+#     Architectures changes      #
+##################################
+
+GET_PROPERTY(ua_architecture_add_definitions GLOBAL PROPERTY UA_ARCHITECTURE_ADD_DEFINITIONS)
+add_definitions(${ua_architecture_add_definitions})
+
+GET_PROPERTY(ua_architecture_remove_definitions GLOBAL PROPERTY UA_ARCHITECTURE_REMOVE_DEFINITIONS)
+remove_definitions(${ua_architecture_remove_definitions})
+
+GET_PROPERTY(ua_architecture_append_to_library GLOBAL PROPERTY UA_ARCHITECTURE_APPEND_TO_LIBRARY)
+list(APPEND open62541_LIBRARIES ${ua_architecture_append_to_library})
 
 # DLL requires linking to dependencies
 target_link_libraries(open62541 ${open62541_LIBRARIES})
 
-# Generate properly versioned shared library links on Linux
-SET_TARGET_PROPERTIES(open62541 PROPERTIES SOVERSION 0 VERSION "${OPEN62541_VER_MAJOR}.${OPEN62541_VER_MINOR}.${OPEN62541_VER_PATCH}")
 
 ##########################
 # Build Selected Targets #
@@ -926,16 +914,3 @@ set_target_properties(open62541-generator-namespace PROPERTIES FOLDER "open62541
 set_target_properties(open62541-generator-statuscode PROPERTIES FOLDER "open62541/generators")
 set_target_properties(open62541-generator-transport PROPERTIES FOLDER "open62541/generators")
 set_target_properties(open62541-generator-types PROPERTIES FOLDER "open62541/generators")
-
-##################################
-#     Architectures changes      #
-##################################
-
-GET_PROPERTY(ua_architecture_add_definitions GLOBAL PROPERTY UA_ARCHITECTURE_ADD_DEFINITIONS)
-add_definitions(${ua_architecture_add_definitions})
-
-GET_PROPERTY(ua_architecture_remove_definitions GLOBAL PROPERTY UA_ARCHITECTURE_REMOVE_DEFINITIONS)
-remove_definitions(${ua_architecture_remove_definitions})
-
-GET_PROPERTY(ua_architecture_append_to_library GLOBAL PROPERTY UA_ARCHITECTURE_APPEND_TO_LIBRARY)
-list(APPEND open62541_LIBRARIES ${ua_architecture_append_to_library})

+ 1 - 0
arch/CMakeLists.txt

@@ -7,3 +7,4 @@ add_subdirectory(win32)
 add_subdirectory(arduino)
 add_subdirectory(freertos)
 add_subdirectory(vxworks)
+add_subdirectory(eCos)

+ 20 - 0
arch/eCos/CMakeLists.txt

@@ -0,0 +1,20 @@
+SET(SOURCE_GROUP ${SOURCE_GROUP}\\eCos)
+
+ua_add_architecture("eCos")
+
+if("${UA_ARCHITECTURE}" STREQUAL "eCos")
+
+ua_include_directories(${CMAKE_CURRENT_SOURCE_DIR})
+ua_add_architecture_file(${CMAKE_CURRENT_SOURCE_DIR}/ua_clock.c)
+ua_add_architecture_file(${CMAKE_CURRENT_SOURCE_DIR}/ua_architecture_functions.c)
+
+ua_architecture_remove_definitions(-Wpedantic -Wno-static-in-inline -Wc++-compat)
+ua_architecture_add_definitions(-Wno-sign-conversion -fdata-sections -fno-exceptions -ffunction-sections -DSYSTEM_BUS_WIDTH=32  -mhw-mul -mno-hw-mulx -mhw-div -Wa,-relax-all -W -Wall -Wextra -D_KERNEL -D__ECOS -nostdlib -Wl,--gc-sections -Wl,-static)
+
+ua_architecture_append_to_library("-L${UA_ECOS_INCLUDES}/lib -Wl,-T,${UA_ECOS_INCLUDES}/lib/target.ld -nostartfiles") #for examples
+
+SET(UA_ECOS_INCLUDES "" CACHE STRING "Folders to include from the eCos OS")
+
+ua_include_directories(${UA_ECOS_INCLUDES}/include)
+
+endif()

+ 114 - 0
arch/eCos/ua_architecture.h

@@ -0,0 +1,114 @@
+/* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
+ * See http://creativecommons.org/publicdomain/zero/1.0/ for more information.
+ *
+ *    Copyright 2016-2017 (c) Julius Pfrommer, Fraunhofer IOSB
+ *    Copyright 2017 (c) Stefan Profanter, fortiss GmbH
+ */
+
+#ifndef PLUGINS_ARCH_POSIX_UA_ARCHITECTURE_H_
+#define PLUGINS_ARCH_POSIX_UA_ARCHITECTURE_H_
+
+#define UA_THREAD_LOCAL
+
+#define UA_ECOS_HOSTNAME "172.20.12.151"
+
+#include <pkgconf/system.h>
+#include <cyg/kernel/kapi.h>
+#include <cyg/io/io.h>
+
+#include <network.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <netinet/tcp.h>
+#include <stdlib.h>
+
+#define UA_sleep_ms(X) cyg_thread_delay(1 + ((1000 * X * CYGNUM_HAL_RTC_DENOMINATOR) / (CYGNUM_HAL_RTC_NUMERATOR / 1000)));
+
+#define OPTVAL_TYPE int
+
+#define UA_fd_set(fd, fds) FD_SET((unsigned int)fd, fds)
+#define UA_fd_isset(fd, fds) FD_ISSET((unsigned int)fd, fds)
+
+#define UA_access(x,y) 0
+
+#define UA_IPV6 1
+#define UA_SOCKET int
+#define UA_INVALID_SOCKET -1
+#define UA_ERRNO errno
+#define UA_INTERRUPTED EINTR
+#define UA_AGAIN EAGAIN
+#define UA_EAGAIN EAGAIN
+#define UA_WOULDBLOCK EWOULDBLOCK
+#define UA_ERR_CONNECTION_PROGRESS EINPROGRESS
+
+#define UA_getnameinfo getnameinfo
+#define UA_send send
+#define UA_recv recv
+#define UA_close close
+#define UA_select select
+#define UA_shutdown shutdown
+#define UA_socket socket
+#define UA_bind bind
+#define UA_listen listen
+#define UA_accept accept
+#define UA_connect connect
+#define UA_getaddrinfo getaddrinfo
+#define UA_getsockopt getsockopt
+#define UA_setsockopt setsockopt
+#define UA_freeaddrinfo freeaddrinfo
+#define UA_gethostname gethostname_ecos
+
+int gethostname_ecos(char* name, size_t len);
+
+#define UA_free free
+#define UA_malloc malloc
+#define UA_calloc calloc
+#define UA_realloc realloc
+
+#define UA_snprintf snprintf
+
+#define UA_LOG_SOCKET_ERRNO_WRAP(LOG) { \
+    char *errno_str = strerror(errno); \
+    LOG; \
+}
+#define UA_LOG_SOCKET_ERRNO_GAI_WRAP(LOG) { \
+    const char *errno_str = gai_strerror(errno); \
+    LOG; \
+}
+
+#include "../ua_architecture_functions.h"
+
+#undef SLIST_EMPTY
+#undef SLIST_FOREACH
+#undef SLIST_INIT
+#undef SLIST_REMOVE
+
+#undef LIST_EMPTY
+#undef LIST_FOREACH
+#undef LIST_INIT
+#undef LIST_REMOVE
+
+#undef TAILQ_EMPTY
+#undef TAILQ_FOREACH
+#undef TAILQ_INIT
+#undef TAILQ_REMOVE
+#undef TAILQ_FOREACH_REVERSE
+
+#undef CIRCLEQ_EMPTY
+#undef CIRCLEQ_FOREACH
+#undef CIRCLEQ_INIT
+#undef CIRCLEQ_FOREACH_REVERSE
+#undef CIRCLEQ_REMOVE
+#undef CIRCLEQ_INSERT_TAIL
+#undef CIRCLEQ_INSERT_HEAD
+#undef CIRCLEQ_INSERT_AFTER
+#undef CIRCLEQ_INSERT_BEFORE
+
+#undef _SYS_QUEUE_H_
+
+//#include "../deps/queue.h"  //in some compilers there's already a _SYS_QUEUE_H_ who is included first and doesn't have all functions
+
+
+
+#endif /* PLUGINS_ARCH_POSIX_UA_ARCHITECTURE_H_ */

+ 37 - 0
arch/eCos/ua_architecture_functions.c

@@ -0,0 +1,37 @@
+/* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
+ * See http://creativecommons.org/publicdomain/zero/1.0/ for more information.
+ *
+ *    Copyright 2018 (c) Jose Cabral, fortiss GmbH
+ */
+
+#include "ua_types.h"
+
+
+unsigned int UA_socket_set_blocking(UA_SOCKET sockfd){
+  int on = 0;
+  if(ioctl(sockfd, FIONBIO, &on) < 0)
+    return UA_STATUSCODE_BADINTERNALERROR;
+  return UA_STATUSCODE_GOOD;
+}
+
+unsigned int UA_socket_set_nonblocking(UA_SOCKET sockfd){
+  int on = 1;
+  if(ioctl(sockfd, FIONBIO, &on) < 0)
+    return UA_STATUSCODE_BADINTERNALERROR;
+  return UA_STATUSCODE_GOOD;
+}
+
+void UA_initialize_architecture_network(void){
+  return;
+}
+
+void UA_deinitialize_architecture_network(void){
+  return;
+}
+
+int gethostname_ecos(char* name, size_t len){
+  if(strlen(UA_ECOS_HOSTNAME) > (len))
+    return -1;
+  strcpy(name, UA_ECOS_HOSTNAME);
+  return 0;
+}

+ 35 - 0
arch/eCos/ua_clock.c

@@ -0,0 +1,35 @@
+/* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
+ * See http://creativecommons.org/publicdomain/zero/1.0/ for more information. 
+ *
+ *    Copyright 2018 (c) Jose Cabral, fortiss GmbH
+ */
+
+#include "ua_types.h"
+
+UA_DateTime UA_DateTime_now(void) {
+  return UA_DateTime_nowMonotonic();
+}
+
+/* Credit to https://stackoverflow.com/questions/13804095/get-the-time-zone-gmt-offset-in-c */
+UA_Int64 UA_DateTime_localTimeUtcOffset(void){
+  time_t gmt, rawtime = time(NULL);
+  struct tm *ptm;
+  struct tm gbuf;
+  ptm = gmtime_r(&rawtime, &gbuf);
+  // Request that mktime() looksup dst in timezone database
+  ptm->tm_isdst = -1;
+  gmt = mktime(ptm);
+  return (UA_Int64) (difftime(rawtime, gmt) * UA_DATETIME_SEC);
+}
+
+UA_DateTime UA_DateTime_nowMonotonic(void) {
+
+  cyg_tick_count_t TaskTime = cyg_current_time();
+
+  UA_DateTimeStruct UATime;
+  UATime.milliSec = (UA_UInt16) TaskTime;
+  struct timespec ts;
+  ts.tv_sec = UATime.milliSec / 1000;
+  ts.tv_nsec = (UATime.milliSec % 1000) * 1000000;
+  return (ts.tv_sec * UA_DATETIME_SEC) + (ts.tv_nsec / 100) + UA_DATETIME_UNIX_EPOCH;
+}

+ 1 - 1
arch/freertos/CMakeLists.txt

@@ -15,7 +15,7 @@ if (${_index} GREATER -1 OR "${UA_ARCHITECTURE}" STREQUAL "freertos")
         SET(UA_FREERTOS_INCLUDES "" CACHE STRING "Folders to include from the freeRTOS OS")
         ua_include_directories(${UA_FREERTOS_INCLUDES})
 
-        ua_architecture_remove_definitions(-fPIC -Wconversion )
+        ua_architecture_remove_definitions(-Wconversion )
         ua_architecture_add_definitions(-DUA_FREERTOS -mcpu=cortex-m3 -mthumb -g -Wall -O0 -specs=nano.specs
                     -ffunction-sections -fdata-sections  -fno-exceptions -fstack-usage -Wno-unused-variable -Wno-format -Wno-format-security -Wno-format-nonliteral)
         ua_architecture_append_to_library(c m stdc++ supc++)

+ 17 - 5
arch/posix/CMakeLists.txt

@@ -7,11 +7,23 @@ if (${_index} GREATER -1 OR "${UA_ARCHITECTURE}" STREQUAL "posix")
 
     ua_add_architecture_file(${CMAKE_CURRENT_SOURCE_DIR}/ua_clock.c)
     ua_add_architecture_file(${CMAKE_CURRENT_SOURCE_DIR}/ua_architecture_functions.c)
-
-    if("${UA_ARCHITECTURE}" STREQUAL "posix")
-
-        ua_include_directories(${CMAKE_CURRENT_SOURCE_DIR})
-
+    
+    if(NOT CYGWIN AND NOT QNXNTO AND (NOT ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD"))
+        add_definitions(-Wshadow -Wconversion -fvisibility=hidden -fPIC)
     endif()
+    
+    if(QNXNTO)
+      ua_architecture_append_to_library(socket c stdc++)
+    else()
+      ua_architecture_append_to_library(m)
+      if(UA_ENABLE_MULTITHREADING OR UA_BUILD_UNIT_TESTS)
+        ua_architecture_append_to_library(pthread)
+      endif()
+      if(NOT APPLE AND (NOT ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD"))
+        ua_architecture_append_to_library(rt)
+      endif()
+    endif()
+
+    ua_include_directories(${CMAKE_CURRENT_SOURCE_DIR})
 
 endif()

+ 0 - 6
arch/ua_architecture_functions.h

@@ -38,12 +38,6 @@ void* UA_realloc(void *ptr, size_t new_size);//re-allocate memory in the heap wi
 void UA_free(void* ptr); //de-allocate memory previously allocated with UA_malloc, UA_calloc or UA_realloc
 #endif
 
-/**
- * Memory Management
- * -----------------
- * The default is to use the malloc implementation from ``stdlib.h``. Override
- * if required. Changing the settings has no effect on a pre-compiled
- * library. */
 #ifndef UA_alloca
 # if defined(__GNUC__) || defined(__clang__)
 #  define UA_alloca(size) __builtin_alloca (size)

+ 1 - 1
arch/vxworks/CMakeLists.txt

@@ -12,7 +12,7 @@ if (${_index} GREATER -1 OR "${UA_ARCHITECTURE}" STREQUAL "vxworks")
 
         ua_include_directories(${CMAKE_CURRENT_SOURCE_DIR})
 
-        ua_architecture_remove_definitions(-Werror -Wpedantic -Wno-static-in-inline -fPIC)
+        ua_architecture_remove_definitions(-Werror -Wpedantic -Wno-static-in-inline)
         ua_architecture_add_definitions(-D_WRS_KERNEL)
 
     endif()

+ 6 - 2
arch/win32/CMakeLists.txt

@@ -9,9 +9,13 @@ if (${_index} GREATER -1 OR "${UA_ARCHITECTURE}" STREQUAL "win32")
     ua_add_architecture_file(${CMAKE_CURRENT_SOURCE_DIR}/ua_architecture_functions.c)
 
     if("${UA_ARCHITECTURE}" STREQUAL "win32")
+        ua_architecture_append_to_library(ws2_32)
+    endif()
 
-        ua_include_directories(${CMAKE_CURRENT_SOURCE_DIR})
-
+    if(UA_ENABLE_DISCOVERY_MULTICAST OR UA_ENABLE_PUBSUB)
+        ua_architecture_append_to_library(APPEND open62541_LIBRARIES iphlpapi)
     endif()
 
+    ua_include_directories(${CMAKE_CURRENT_SOURCE_DIR})
+
 endif()

+ 2 - 2
plugins/ua_config_default.c

@@ -439,7 +439,7 @@ UA_ServerConfig_new_basic256sha256(UA_UInt16 portNumber,
         return NULL;
     }
 
-    if(addDefaultNetworkLayers(conf, portNumber) != UA_STATUSCODE_GOOD) {
+    if(addDefaultNetworkLayers(conf, portNumber, 0, 0) != UA_STATUSCODE_GOOD) {
         UA_ServerConfig_delete(conf);
         return NULL;
     }
@@ -509,7 +509,7 @@ UA_ServerConfig_new_allSecurityPolicies(UA_UInt16 portNumber,
         return NULL;
     }
 
-    if(addDefaultNetworkLayers(conf, portNumber) != UA_STATUSCODE_GOOD) {
+    if(addDefaultNetworkLayers(conf, portNumber, 0, 0) != UA_STATUSCODE_GOOD) {
         UA_ServerConfig_delete(conf);
         return NULL;
     }

+ 1 - 1
plugins/ua_config_default.h

@@ -57,7 +57,7 @@ UA_ServerConfig_new_customBuffer(UA_UInt16 portNumber, const UA_ByteString *cert
  *        ``NULL``. */
 static UA_INLINE UA_ServerConfig *
 UA_ServerConfig_new_minimal(UA_UInt16 portNumber, const UA_ByteString *certificate) {
-    return UA_ServerConfig_new_customBuffer(4840, NULL, 0 ,0);
+    return UA_ServerConfig_new_customBuffer(portNumber, certificate, 0 ,0);
 }
 
 #ifdef UA_ENABLE_ENCRYPTION