Prechádzať zdrojové kódy

Merge arduino and freeRTOS arch

Jose Cabral 6 rokov pred
rodič
commit
8f3547b1dc

+ 12 - 1
arch/CMakeLists.txt

@@ -4,7 +4,18 @@ ua_include_directories(${CMAKE_CURRENT_SOURCE_DIR}) #to have access to ua_networ
 
 add_subdirectory(posix)
 add_subdirectory(win32)
-add_subdirectory(arduino)
 add_subdirectory(freertosLWIP)
 add_subdirectory(vxworks)
 add_subdirectory(eCos)
+
+SET(UA_ARCH_EXTRA_INCLUDES "" CACHE STRING "Folders to include from the architecture")
+ua_include_directories(${UA_ARCH_EXTRA_INCLUDES})
+
+SET(UA_ARCH_REMOVE_FLAGS "" CACHE STRING "Flags to be removed from compilation that depends on the architecure")
+ua_architecture_remove_definitions(${UA_ARCH_REMOVE_FLAGS})
+
+SET(UA_ARCH_ADD_FLAGS "" CACHE STRING "Flags to be added to compilation that depends on the architecure")
+ua_architecture_add_definitions(${UA_ARCH_ADD_FLAGS})
+
+SET(UA_ARCH_LINKER_FLAGS "" CACHE STRING "Linker Flags to be added to compilation that depends on the architecure")
+ua_architecture_append_to_library(${UA_ARCH_LINKER_FLAGS})

+ 0 - 15
arch/arduino/CMakeLists.txt

@@ -1,15 +0,0 @@
-SET(SOURCE_GROUP ${SOURCE_GROUP}\\arduino)
-
-ua_add_architecture("arduino")
-
-list (FIND UA_AMALGAMATION_ARCHITECUTRES "arduino" _index)
-if (${_index} GREATER -1 OR "${UA_ARCHITECTURE}" STREQUAL "arduino")
-
-    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 "arduino")
-        ua_include_directories(${CMAKE_CURRENT_SOURCE_DIR})
-    endif()
-
-endif()

+ 0 - 39
arch/arduino/ua_architecture_functions.c

@@ -1,39 +0,0 @@
-/* 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
- *    Copyright 2018 (c) Stefan Profanter, fortiss GmbH
- */
-
-#ifdef UA_ARCHITECTURE_ARDUINO
-
-#include "ua_types.h"
-
-unsigned int UA_socket_set_blocking(UA_SOCKET sockfd){
-  int on = 0;
-  if(lwip_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(lwip_ioctl(sockfd, FIONBIO, &on) < 0)
-    return UA_STATUSCODE_BADINTERNALERROR;
-  return UA_STATUSCODE_GOOD;
-}
-
-int gethostname_freertos(char* name, size_t len){
-    // use UA_ServerConfig_set_customHostname to set your hostname as the IP
-  return -1;
-}
-
-void UA_initialize_architecture_network(void){
-  return;
-}
-
-void UA_deinitialize_architecture_network(void){
-  return;
-}
-
-#endif /* UA_ARCHITECTURE_ARDUINO */

+ 0 - 60
arch/arduino/ua_clock.c

@@ -1,60 +0,0 @@
-/* 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
- *    Copyright 2017 (c) Thomas Stalder
- */
-
-#ifdef UA_ARCHITECTURE_ARDUINO
-
-/* Enable POSIX features */
-#if !defined(_XOPEN_SOURCE)
-# define _XOPEN_SOURCE 600
-#endif
-#ifndef _DEFAULT_SOURCE
-# define _DEFAULT_SOURCE
-#endif
-/* On older systems we need to define _BSD_SOURCE.
- * _DEFAULT_SOURCE is an alias for that. */
-#ifndef _BSD_SOURCE
-# define _BSD_SOURCE
-#endif
-
-#include <time.h>
-#include <sys/time.h>
-
-#include "ua_types.h"
-
-#include <freertos/FreeRTOS.h>
-#include <freertos/task.h>
-
-UA_DateTime UA_DateTime_now(void) {
-    struct timeval tv;
-    gettimeofday(&tv, NULL);
-    return (tv.tv_sec * UA_DATETIME_SEC) + (tv.tv_usec * UA_DATETIME_USEC) + UA_DATETIME_UNIX_EPOCH;
-}
-
-/* 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) {
-    portTickType TaskTime = xTaskGetTickCount();
-    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);
-}
-
-#endif /* UA_ARCHITECTURE_ARDUINO */

+ 50 - 0
arch/common/freeRTOS62541.h

@@ -0,0 +1,50 @@
+/* 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
+ */
+
+#ifndef ARCH_COMMON_FREERTOS62541_H_
+#define ARCH_COMMON_FREERTOS62541_H_
+
+#define UA_THREAD_LOCAL
+
+#include <stdlib.h>
+#include <string.h>
+
+#ifdef BYTE_ORDER
+# undef BYTE_ORDER
+#endif
+
+#include <unistd.h> // read, write, close
+
+#define UA_sleep_ms(X) vTaskDelay(pdMS_TO_TICKS(X))
+
+#ifdef OPEN62541_FEERTOS_USE_OWN_MEM
+# define UA_free vPortFree
+# define UA_malloc pvPortMalloc
+# define UA_calloc pvPortCalloc
+# define UA_realloc pvPortRealloc
+#else
+# define UA_free free
+# define UA_malloc malloc
+# define UA_calloc calloc
+# define UA_realloc realloc
+#endif
+
+#define UA_access access
+
+// No log colors on freeRTOS
+// #define UA_ENABLE_LOG_COLORS
+
+#include <stdio.h>
+#define UA_snprintf snprintf
+
+#define UA_LOG_SOCKET_ERRNO_WRAP(LOG) { \
+    char *errno_str = ""; \
+    LOG; \
+}
+
+#define UA_LOG_SOCKET_ERRNO_GAI_WRAP UA_LOG_SOCKET_ERRNO_WRAP
+
+#endif /* ARCH_COMMON_FREERTOS62541_H_ */

+ 6 - 46
arch/arduino/ua_architecture.h

@@ -1,46 +1,28 @@
 /* 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-2018 (c) Stefan Profanter, fortiss GmbH
+ *    Copyright 2018 (c) Jose Cabral, fortiss GmbH
  */
 
-#ifdef UA_ARCHITECTURE_ARDUINO
-
-#ifndef PLUGINS_ARCH_ARDUINO_UA_ARCHITECTURE_H_
-#define PLUGINS_ARCH_ARDUINO_UA_ARCHITECTURE_H_
-
-#define UA_THREAD_LOCAL
-
-#include <stdlib.h>
-#include <string.h>
+#ifndef ARCH_COMMON_LWIP62541_H_
+#define ARCH_COMMON_LWIP62541_H_
 
 #define LWIP_TIMEVAL_PRIVATE 0
-//#define LWIP_COMPAT_MUTEX 0
 #define LWIP_POSIX_SOCKETS_IO_NAMES 0
 #ifdef LWIP_COMPAT_SOCKETS
 #undef LWIP_COMPAT_SOCKETS
 #endif
 #define LWIP_COMPAT_SOCKETS 0
-//#define __USE_W32_SOCKETS 1 //needed to avoid redefining of select in sys/select.h
 
 #include <lwip/tcpip.h>
 #include <lwip/netdb.h>
 #define sockaddr_storage sockaddr
-#ifdef BYTE_ORDER
-# undef BYTE_ORDER
-#endif
-#define UA_sleep_ms(X) vTaskDelay(pdMS_TO_TICKS(X))
 
 #define OPTVAL_TYPE int
 
-#include <unistd.h> // read, write, close
-
 #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 access
-
 #define UA_IPV6 0
 #define UA_SOCKET int
 #define UA_INVALID_SOCKET -1
@@ -51,9 +33,6 @@
 #define UA_WOULDBLOCK EWOULDBLOCK
 #define UA_ERR_CONNECTION_PROGRESS EINPROGRESS
 
-// No log colors on Arduino
-// #define UA_ENABLE_LOG_COLORS
-
 #define UA_send lwip_send
 #define UA_recv lwip_recv
 #define UA_close lwip_close
@@ -67,28 +46,9 @@
 #define UA_getsockopt lwip_getsockopt
 #define UA_setsockopt lwip_setsockopt
 #define UA_freeaddrinfo lwip_freeaddrinfo
-#define UA_gethostname gethostname_freertos
+#define UA_gethostname gethostname_lwip
 #define UA_getaddrinfo lwip_getaddrinfo
 
-#define UA_free free
-#define UA_malloc malloc
-#define UA_calloc calloc
-#define UA_realloc realloc
-
-#include <stdio.h>
-#define UA_snprintf snprintf
-
-int gethostname_freertos(char* name, size_t len);
-
-#define UA_LOG_SOCKET_ERRNO_WRAP(LOG) { \
-    char *errno_str = ""; \
-    LOG; \
-}
-
-#define UA_LOG_SOCKET_ERRNO_GAI_WRAP UA_LOG_SOCKET_ERRNO_WRAP
-
-#include "../ua_architecture_functions.h"
-
-#endif /* PLUGINS_ARCH_ARDUINO_UA_ARCHITECTURE_H_ */
+int gethostname_lwip(char* name, size_t len);
 
-#endif /* UA_ARCHITECTURE_ARDUINO */
+#endif /* ARCH_COMMON_LWIP62541_H_ */

+ 4 - 12
arch/freertosLWIP/CMakeLists.txt

@@ -9,18 +9,10 @@ if (${_index} GREATER -1 OR "${UA_ARCHITECTURE}" STREQUAL "freertosLWIP")
     ua_add_architecture_file(${CMAKE_CURRENT_SOURCE_DIR}/ua_architecture_functions.c)
 
     if("${UA_ARCHITECTURE}" STREQUAL "freertosLWIP")
-
         ua_include_directories(${CMAKE_CURRENT_SOURCE_DIR})
-
-        SET(UA_FREERTOS_INCLUDES "" CACHE STRING "Folders to include from the freeRTOS OS")
-        ua_include_directories(${UA_FREERTOS_INCLUDES})
-
-        ua_architecture_remove_definitions(-Wconversion )
-        ua_architecture_add_definitions(-mthumb -mcpu=cortex-m3) #CPU dependant
-        ua_architecture_add_definitions(-ffunction-sections -fdata-sections -fstack-usage -Wall -specs=nano.specs
-                     -fno-exceptions -Wno-unused-variable -Wno-format -Wno-format-security -Wno-format-nonliteral)
-
-        set(UA_FREERTOS_HOSTNAME "freertosLWIP-host" CACHE STRING "Define a custom hostname/ip for the endpoint.")
-        ua_architecture_add_definitions(-DUA_FREERTOS_HOSTNAME="${UA_FREERTOS_HOSTNAME}")
+        set(UA_ARCH_FREERTOS_USE_OWN_MEMORY_FUNCTIONS OFF CACHE BOOL "Enable free/malloc/etc from own implementation")
+        if(UA_ARCH_FREERTOS_USE_OWN_MEMORY_FUNCTIONS)
+          ua_architecture_add_definitions("-DOPEN62541_FEERTOS_USE_OWN_MEM")
+        endif(UA_ARCH_FREERTOS_USE_OWN_MEMORY_FUNCTIONS)
     endif()
 endif()

+ 5 - 78
arch/freertosLWIP/ua_architecture.h

@@ -8,87 +8,14 @@
 
 #ifdef UA_ARCHITECTURE_FREERTOSLWIP
 
-#ifndef PLUGINS_ARCH_FREERTOS_UA_ARCHITECTURE_H_
-#define PLUGINS_ARCH_FREERTOS_UA_ARCHITECTURE_H_
+#ifndef PLUGINS_ARCH_FREERTOSLWIP_UA_ARCHITECTURE_H_
+#define PLUGINS_ARCH_FREERTOSLWIP_UA_ARCHITECTURE_H_
 
-#define AI_PASSIVE 0x01
-
-#define UA_THREAD_LOCAL
-
-#include <stdlib.h>
-#include <string.h>
-
-#define LWIP_TIMEVAL_PRIVATE 0
-#define LWIP_POSIX_SOCKETS_IO_NAMES 0
-#ifdef LWIP_COMPAT_SOCKETS
-#undef LWIP_COMPAT_SOCKETS
-#endif
-#define LWIP_COMPAT_SOCKETS 0
-
-#include <lwip/tcpip.h>
-#include <lwip/netdb.h>
-#define sockaddr_storage sockaddr
-#ifdef BYTE_ORDER
-# undef BYTE_ORDER
-#endif
-#define UA_sleep_ms(X) vTaskDelay(pdMS_TO_TICKS(X))
-
-#define OPTVAL_TYPE int
-
-#include <unistd.h> // read, write, close
-
-#define UA_fd_set(fd, fds) FD_SET(fd, fds)
-#define UA_fd_isset(fd, fds) FD_ISSET(fd, fds)
-
-#define UA_access access
-
-#define UA_IPV6 0
-#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
-
-// No log colors on FreeRTOS
-// #define UA_ENABLE_LOG_COLORS
-
-#define UA_send lwip_send
-#define UA_recv lwip_recv
-#define UA_close lwip_close
-#define UA_select lwip_select
-#define UA_shutdown lwip_shutdown
-#define UA_socket lwip_socket
-#define UA_bind lwip_bind
-#define UA_listen lwip_listen
-#define UA_accept lwip_accept
-#define UA_connect lwip_connect
-#define UA_getsockopt lwip_getsockopt
-#define UA_setsockopt lwip_setsockopt
-#define UA_freeaddrinfo lwip_freeaddrinfo
-#define UA_gethostname gethostname_freertos
-
-#define UA_free vPortFree
-#define UA_malloc pvPortMalloc
-#define UA_calloc pvPortCalloc
-#define UA_realloc pvPortRealloc
-
-#include <stdio.h>
-#define UA_snprintf snprintf
-
-int gethostname_freertos(char* name, size_t len);
-
-#define UA_LOG_SOCKET_ERRNO_WRAP(LOG) { \
-    char *errno_str = ""; \
-    LOG; \
-}
-
-#define UA_LOG_SOCKET_ERRNO_GAI_WRAP UA_LOG_SOCKET_ERRNO_WRAP
+#include <../common/lwip62541.h>
+#include <../common/freeRTOS62541.h>
 
 #include "../ua_architecture_functions.h"
 
-#endif /* PLUGINS_ARCH_FREERTOS_UA_ARCHITECTURE_H_ */
+#endif /* PLUGINS_ARCH_FREERTOSLWIP_UA_ARCHITECTURE_H_ */
 
 #endif /* UA_ARCHITECTURE_FREERTOSLWIP */

+ 4 - 13
arch/freertosLWIP/ua_architecture_functions.c

@@ -2,6 +2,7 @@
  * See http://creativecommons.org/publicdomain/zero/1.0/ for more information.
  *
  *    Copyright 2018 (c) Jose Cabral, fortiss GmbH
+ *    Copyright 2018 (c) Stefan Profanter, fortiss GmbH
  */
 
 #ifdef UA_ARCHITECTURE_FREERTOSLWIP
@@ -22,19 +23,9 @@ unsigned int UA_socket_set_nonblocking(UA_SOCKET sockfd){
   return UA_STATUSCODE_GOOD;
 }
 
-int gethostname_freertos(char* name, size_t len){
-  if(strlen(UA_FREERTOS_HOSTNAME) > (len))
-    return -1;
-  strcpy(name, UA_FREERTOS_HOSTNAME);
-  return 0;
-}
-
-int UA_getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res){
-  if(NULL == node){
-    return lwip_getaddrinfo(UA_FREERTOS_HOSTNAME, service, hints, res);
-  }else{
-    return lwip_getaddrinfo(node, service, hints, res);
-  }
+int gethostname_lwip(char* name, size_t len){
+  // use UA_ServerConfig_set_customHostname to set your hostname as the IP
+  return -1;
 }
 
 void UA_initialize_architecture_network(void){