CapXilinx 12 years ago
parent
commit
e428c78d9d
95 changed files with 2236 additions and 116 deletions
  1. 4 2
      .gitignore
  2. 303 0
      CMakeCache.txt
  3. 0 43
      buildsupport/OpENer.cmake
  4. 13 42
      source/CMakeLists.txt
  5. 17 0
      source/buildsupport/LM3S8962/OpENer_PLATFORM_INCLUDES.cmake
  6. 71 0
      source/buildsupport/OpENer.cmake
  7. 0 0
      source/buildsupport/OpENer_CIP_Object_generator.cmake
  8. 0 0
      source/buildsupport/OpENer_Tests.cmake
  9. 12 0
      source/buildsupport/OpENer_function_checks.cmake
  10. 0 0
      source/buildsupport/POSIX/OpENer_PLATFORM_INCLUDES.cmake
  11. 71 0
      source/buildsupport/Toolchain/Toolchain-EABI-ARM-Generic.cmake
  12. 0 0
      source/buildsupport/WIN32/OpENer_PLATFORM_INCLUDES.cmake
  13. 0 0
      source/contrib/msinttypes/README
  14. 0 0
      source/contrib/msinttypes/inttypes.h
  15. 0 0
      source/doc/coding_rules/opener_coding_rules.pdf
  16. 0 0
      source/doc/coding_rules/src/opener_coding_rules.tex
  17. 0 0
      source/opener.doxyfile
  18. 19 0
      source/src/CMakeLists.txt
  19. 0 0
      source/src/cip/CMakeLists.txt
  20. 0 0
      source/src/cip/appcontype.c
  21. 0 0
      source/src/cip/appcontype.h
  22. 0 0
      source/src/cip/cipassembly.c
  23. 0 0
      source/src/cip/cipassembly.h
  24. 0 0
      source/src/cip/cipclass3connection.c
  25. 0 0
      source/src/cip/cipclass3connection.h
  26. 0 0
      source/src/cip/cipcommon.c
  27. 0 0
      source/src/cip/cipcommon.h
  28. 0 0
      source/src/cip/cipconnectionmanager.c
  29. 0 0
      source/src/cip/cipconnectionmanager.h
  30. 0 0
      source/src/cip/ciperror.h
  31. 0 0
      source/src/cip/cipethernetlink.c
  32. 0 0
      source/src/cip/cipethernetlink.h
  33. 0 0
      source/src/cip/cipidentity.c
  34. 0 0
      source/src/cip/cipidentity.h
  35. 0 0
      source/src/cip/cipioconnection.c
  36. 0 0
      source/src/cip/cipioconnection.h
  37. 0 0
      source/src/cip/cipmessagerouter.c
  38. 0 0
      source/src/cip/cipmessagerouter.h
  39. 0 0
      source/src/cip/ciptcpipinterface.c
  40. 0 0
      source/src/cip/ciptcpipinterface.h
  41. 0 0
      source/src/cip/ciptypes.h
  42. 0 0
      source/src/cip_objects/CMakeLists.txt
  43. 0 0
      source/src/enet_encap/CMakeLists.txt
  44. 0 0
      source/src/enet_encap/cpf.c
  45. 0 0
      source/src/enet_encap/cpf.h
  46. 0 0
      source/src/enet_encap/encap.c
  47. 0 0
      source/src/enet_encap/encap.h
  48. 0 0
      source/src/enet_encap/endianconv.c
  49. 0 0
      source/src/enet_encap/endianconv.h
  50. 0 0
      source/src/opener_api.h
  51. 0 0
      source/src/ports/CMakeLists.txt
  52. 41 0
      source/src/ports/LM3S8962/CMakeLists.txt
  53. 69 0
      source/src/ports/LM3S8962/README
  54. 33 0
      source/src/ports/LM3S8962/archnw.h
  55. 148 0
      source/src/ports/LM3S8962/basiccip.c
  56. 9 0
      source/src/ports/LM3S8962/config.h
  57. 130 0
      source/src/ports/LM3S8962/flashmgr.c
  58. 8 0
      source/src/ports/LM3S8962/flashmgr.h
  59. 426 0
      source/src/ports/LM3S8962/networkhandler.c
  60. 18 0
      source/src/ports/LM3S8962/networkhandler.h
  61. 12 0
      source/src/ports/LM3S8962/sample_application/CMakeLists.txt
  62. 337 0
      source/src/ports/LM3S8962/sample_application/main.c
  63. 194 0
      source/src/ports/LM3S8962/sample_application/opener_user_conf.h
  64. 80 0
      source/src/ports/LM3S8962/stubs.c
  65. 0 0
      source/src/ports/POSIX/CMakeLists.txt
  66. 0 0
      source/src/ports/POSIX/main.c
  67. 0 0
      source/src/ports/POSIX/networkhandler.c
  68. 0 0
      source/src/ports/POSIX/networkhandler.h
  69. 0 0
      source/src/ports/POSIX/sample_application/CMakeLists.txt
  70. 0 0
      source/src/ports/POSIX/sample_application/opener_user_conf.h
  71. 0 0
      source/src/ports/POSIX/sample_application/sampleapplication.c
  72. 0 0
      source/src/ports/WIN32/CMakeLists.txt
  73. 0 0
      source/src/ports/WIN32/main.c
  74. 0 0
      source/src/ports/WIN32/networkhandler.c
  75. 0 0
      source/src/ports/WIN32/networkhandler.h
  76. 0 0
      source/src/ports/WIN32/sample_application/CMakeLists.txt
  77. 0 0
      source/src/ports/WIN32/sample_application/opener_user_conf.h
  78. 0 0
      source/src/ports/WIN32/sample_application/sampleapplication.c
  79. 0 0
      source/src/trace.h
  80. 0 0
      source/src/typedefs.h
  81. 7 0
      source/src/utils/CMakeLists.txt
  82. 15 0
      source/src/utils/random.c
  83. 25 0
      source/src/utils/random.h
  84. 32 0
      source/src/utils/xorshiftrandom.c
  85. 30 0
      source/src/utils/xorshiftrandom.h
  86. 27 0
      source/tests/CMakeLists.txt
  87. 1 0
      source/tests/CTestCustom.cmake
  88. 1 3
      source/tests/OpENerTests.cpp
  89. 4 0
      source/tests/OpENerTests.h
  90. 8 0
      source/tests/utils/CMakeLists.txt
  91. 28 0
      source/tests/utils/randomTests.cpp
  92. 43 0
      source/tests/utils/xorshiftrandomtests.cpp
  93. 0 12
      src/tests/CMakeLists.txt
  94. 0 3
      src/tests/utils/CMakeLists.txt
  95. 0 11
      src/tests/utils/MTRandomTests.cpp

+ 4 - 2
.gitignore

@@ -1,7 +1,9 @@
 bin/
 doc/
-src/cip_objects/*
-!src/cip_objects/CMakeLists.txt
+contrib/
+source/src/cip_objects/
+!source/src/cip_objects/CMakeLists.txt
 .project
 .cproject
 *.*~
+*~

+ 303 - 0
CMakeCache.txt

@@ -0,0 +1,303 @@
+# This is the CMakeCache file.
+# For build in directory: /cygdrive/c/workspace/opener
+# It was generated by CMake: /usr/bin/cmake.exe
+# You can edit this file to change values found and used by cmake.
+# If you do not want to change any of the values, simply exit the editor.
+# If you do want to change a value, simply edit, save, and exit the editor.
+# The syntax for the file is as follows:
+# KEY:TYPE=VALUE
+# KEY is the name of a variable in the cache.
+# TYPE is a hint to GUI's for the type of VALUE, DO NOT EDIT TYPE!.
+# VALUE is the current value for the KEY.
+
+########################
+# EXTERNAL cache entries
+########################
+
+//Dependencies for target
+CIP_LIB_DEPENDS:STATIC=
+
+//Path to a program.
+CMAKE_AR:FILEPATH=/usr/bin/ar.exe
+
+//Choose the type of build, options are: None(CMAKE_CXX_FLAGS or
+// CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel.
+CMAKE_BUILD_TYPE:STRING=
+
+//Enable/Disable color output during build.
+CMAKE_COLOR_MAKEFILE:BOOL=ON
+
+//C compiler.
+CMAKE_C_COMPILER:FILEPATH=/usr/bin/gcc.exe
+
+//Flags used by the compiler during all build types.
+CMAKE_C_FLAGS:STRING=
+
+//Flags used by the compiler during debug builds.
+CMAKE_C_FLAGS_DEBUG:STRING=-g
+
+//Flags used by the compiler during release minsize builds.
+CMAKE_C_FLAGS_MINSIZEREL:STRING=-Os -DNDEBUG
+
+//Flags used by the compiler during release builds (/MD /Ob1 /Oi
+// /Ot /Oy /Gs will produce slightly less optimized but smaller
+// files).
+CMAKE_C_FLAGS_RELEASE:STRING=-O3 -DNDEBUG
+
+//Flags used by the compiler during Release with Debug Info builds.
+CMAKE_C_FLAGS_RELWITHDEBINFO:STRING=-O2 -g
+
+//Flags used by the linker.
+CMAKE_EXE_LINKER_FLAGS:STRING='-Wl,--enable-auto-import '
+
+//Flags used by the linker during debug builds.
+CMAKE_EXE_LINKER_FLAGS_DEBUG:STRING=
+
+//Flags used by the linker during release minsize builds.
+CMAKE_EXE_LINKER_FLAGS_MINSIZEREL:STRING=
+
+//Flags used by the linker during release builds.
+CMAKE_EXE_LINKER_FLAGS_RELEASE:STRING=
+
+//Flags used by the linker during Release with Debug Info builds.
+CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO:STRING=
+
+//Enable/Disable output of compile commands during generation.
+CMAKE_EXPORT_COMPILE_COMMANDS:BOOL=OFF
+
+//Install path prefix, prepended onto install directories.
+CMAKE_INSTALL_PREFIX:PATH=/usr/local
+
+//Path to a program.
+CMAKE_LINKER:FILEPATH=/usr/bin/ld.exe
+
+//Path to a program.
+CMAKE_MAKE_PROGRAM:FILEPATH=/usr/bin/make.exe
+
+//Flags used by the linker during the creation of modules.
+CMAKE_MODULE_LINKER_FLAGS:STRING=' '
+
+//Flags used by the linker during debug builds.
+CMAKE_MODULE_LINKER_FLAGS_DEBUG:STRING=
+
+//Flags used by the linker during release minsize builds.
+CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL:STRING=
+
+//Flags used by the linker during release builds.
+CMAKE_MODULE_LINKER_FLAGS_RELEASE:STRING=
+
+//Flags used by the linker during Release with Debug Info builds.
+CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO:STRING=
+
+//Path to a program.
+CMAKE_NM:FILEPATH=/usr/bin/nm.exe
+
+//Path to a program.
+CMAKE_OBJCOPY:FILEPATH=/usr/bin/objcopy.exe
+
+//Path to a program.
+CMAKE_OBJDUMP:FILEPATH=/usr/bin/objdump.exe
+
+//Value Computed by CMake
+CMAKE_PROJECT_NAME:STATIC=OpENer
+
+//Path to a program.
+CMAKE_RANLIB:FILEPATH=/usr/bin/ranlib.exe
+
+//RC compiler.
+CMAKE_RC_COMPILER:FILEPATH=/usr/bin/windres.exe
+
+//Flags for Fortran compiler.
+CMAKE_RC_FLAGS:STRING=' '
+
+//Flags used by the linker during the creation of dll's.
+CMAKE_SHARED_LINKER_FLAGS:STRING=' '
+
+//Flags used by the linker during debug builds.
+CMAKE_SHARED_LINKER_FLAGS_DEBUG:STRING=
+
+//Flags used by the linker during release minsize builds.
+CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL:STRING=
+
+//Flags used by the linker during release builds.
+CMAKE_SHARED_LINKER_FLAGS_RELEASE:STRING=
+
+//Flags used by the linker during Release with Debug Info builds.
+CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO:STRING=
+
+//If set, runtime paths are not added when installing shared libraries,
+// but are added when building.
+CMAKE_SKIP_INSTALL_RPATH:BOOL=NO
+
+//If set, runtime paths are not added when using shared libraries.
+CMAKE_SKIP_RPATH:BOOL=NO
+
+//Path to a program.
+CMAKE_STRIP:FILEPATH=/usr/bin/strip.exe
+
+//If true, cmake will use relative paths in makefiles and projects.
+CMAKE_USE_RELATIVE_PATHS:BOOL=OFF
+
+//If this value is on, makefiles will be generated without the
+// .SILENT directive, and all commands will be echoed to the console
+// during the make.  This is useful for debugging only. With Visual
+// Studio IDE projects all commands are done without /nologo.
+CMAKE_VERBOSE_MAKEFILE:BOOL=FALSE
+
+//Dependencies for target
+ENET_ENCAP_LIB_DEPENDS:STATIC=
+
+//Dependencies for target
+LM3S8962PLATFORM_LIB_DEPENDS:STATIC=
+
+//Contrib folder of the used LM3S0862 board
+LM3S8962_CONTRIB_DIR:PATH=
+
+//Value Computed by CMake
+OpENer_BINARY_DIR:STATIC=/cygdrive/c/workspace/opener
+
+//Path to a file.
+OpENer_BUILDSUPPORT_DIR:PATH=/cygdrive/c/workspace/opener/source/buildsupport
+
+//Platform OpENer will be built for
+OpENer_PLATFORM:STRING=LM3S8962
+
+//Value Computed by CMake
+OpENer_SOURCE_DIR:STATIC=/cygdrive/c/workspace/opener/source
+
+//Enable tests to be built
+OpENer_TESTS:BOOL=OFF
+
+//Activate OpENer traces
+OpENer_TRACES:BOOL=OFF
+
+//Dependencies for target
+Utils_LIB_DEPENDS:STATIC=
+
+
+########################
+# INTERNAL cache entries
+########################
+
+//ADVANCED property for variable: CMAKE_AR
+CMAKE_AR-ADVANCED:INTERNAL=1
+//ADVANCED property for variable: CMAKE_BUILD_TOOL
+CMAKE_BUILD_TOOL-ADVANCED:INTERNAL=1
+//What is the target build tool cmake is generating for.
+CMAKE_BUILD_TOOL:INTERNAL=/usr/bin/make.exe
+//This is the directory where this CMakeCache.txt was created
+CMAKE_CACHEFILE_DIR:INTERNAL=/cygdrive/c/workspace/opener
+//Major version of cmake used to create the current loaded cache
+CMAKE_CACHE_MAJOR_VERSION:INTERNAL=2
+//Minor version of cmake used to create the current loaded cache
+CMAKE_CACHE_MINOR_VERSION:INTERNAL=8
+//Patch version of cmake used to create the current loaded cache
+CMAKE_CACHE_PATCH_VERSION:INTERNAL=9
+//ADVANCED property for variable: CMAKE_COLOR_MAKEFILE
+CMAKE_COLOR_MAKEFILE-ADVANCED:INTERNAL=1
+//Path to CMake executable.
+CMAKE_COMMAND:INTERNAL=/usr/bin/cmake.exe
+//Path to cpack program executable.
+CMAKE_CPACK_COMMAND:INTERNAL=/usr/bin/cpack.exe
+//Path to ctest program executable.
+CMAKE_CTEST_COMMAND:INTERNAL=/usr/bin/ctest.exe
+//ADVANCED property for variable: CMAKE_C_COMPILER
+CMAKE_C_COMPILER-ADVANCED:INTERNAL=1
+CMAKE_C_COMPILER_WORKS:INTERNAL=1
+//ADVANCED property for variable: CMAKE_C_FLAGS
+CMAKE_C_FLAGS-ADVANCED:INTERNAL=1
+//ADVANCED property for variable: CMAKE_C_FLAGS_DEBUG
+CMAKE_C_FLAGS_DEBUG-ADVANCED:INTERNAL=1
+//ADVANCED property for variable: CMAKE_C_FLAGS_MINSIZEREL
+CMAKE_C_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1
+//ADVANCED property for variable: CMAKE_C_FLAGS_RELEASE
+CMAKE_C_FLAGS_RELEASE-ADVANCED:INTERNAL=1
+//ADVANCED property for variable: CMAKE_C_FLAGS_RELWITHDEBINFO
+CMAKE_C_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1
+//Result of TRY_COMPILE
+CMAKE_DETERMINE_C_ABI_COMPILED:INTERNAL=TRUE
+//Path to cache edit program executable.
+CMAKE_EDIT_COMMAND:INTERNAL=/usr/bin/ccmake.exe
+//Executable file format
+CMAKE_EXECUTABLE_FORMAT:INTERNAL=Unknown
+//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS
+CMAKE_EXE_LINKER_FLAGS-ADVANCED:INTERNAL=1
+//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_DEBUG
+CMAKE_EXE_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1
+//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_MINSIZEREL
+CMAKE_EXE_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1
+//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_RELEASE
+CMAKE_EXE_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1
+//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO
+CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1
+//ADVANCED property for variable: CMAKE_EXPORT_COMPILE_COMMANDS
+CMAKE_EXPORT_COMPILE_COMMANDS-ADVANCED:INTERNAL=1
+//Name of generator.
+CMAKE_GENERATOR:INTERNAL=Unix Makefiles
+//Start directory with the top level CMakeLists.txt file for this
+// project
+CMAKE_HOME_DIRECTORY:INTERNAL=/cygdrive/c/workspace/opener/source
+//ADVANCED property for variable: CMAKE_LINKER
+CMAKE_LINKER-ADVANCED:INTERNAL=1
+//ADVANCED property for variable: CMAKE_MAKE_PROGRAM
+CMAKE_MAKE_PROGRAM-ADVANCED:INTERNAL=1
+//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS
+CMAKE_MODULE_LINKER_FLAGS-ADVANCED:INTERNAL=1
+//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_DEBUG
+CMAKE_MODULE_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1
+//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL
+CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1
+//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_RELEASE
+CMAKE_MODULE_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1
+//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO
+CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1
+//ADVANCED property for variable: CMAKE_NM
+CMAKE_NM-ADVANCED:INTERNAL=1
+//number of local generators
+CMAKE_NUMBER_OF_LOCAL_GENERATORS:INTERNAL=9
+//ADVANCED property for variable: CMAKE_OBJCOPY
+CMAKE_OBJCOPY-ADVANCED:INTERNAL=1
+//ADVANCED property for variable: CMAKE_OBJDUMP
+CMAKE_OBJDUMP-ADVANCED:INTERNAL=1
+//ADVANCED property for variable: CMAKE_RANLIB
+CMAKE_RANLIB-ADVANCED:INTERNAL=1
+//ADVANCED property for variable: CMAKE_RC_COMPILER
+CMAKE_RC_COMPILER-ADVANCED:INTERNAL=1
+CMAKE_RC_COMPILER_WORKS:INTERNAL=1
+//ADVANCED property for variable: CMAKE_RC_FLAGS
+CMAKE_RC_FLAGS-ADVANCED:INTERNAL=1
+//Path to CMake installation.
+CMAKE_ROOT:INTERNAL=/usr/share/cmake-2.8.9
+//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS
+CMAKE_SHARED_LINKER_FLAGS-ADVANCED:INTERNAL=1
+//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_DEBUG
+CMAKE_SHARED_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1
+//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL
+CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1
+//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_RELEASE
+CMAKE_SHARED_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1
+//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO
+CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1
+//ADVANCED property for variable: CMAKE_SKIP_INSTALL_RPATH
+CMAKE_SKIP_INSTALL_RPATH-ADVANCED:INTERNAL=1
+//ADVANCED property for variable: CMAKE_SKIP_RPATH
+CMAKE_SKIP_RPATH-ADVANCED:INTERNAL=1
+//ADVANCED property for variable: CMAKE_STRIP
+CMAKE_STRIP-ADVANCED:INTERNAL=1
+//uname command
+CMAKE_UNAME:INTERNAL=/usr/bin/uname.exe
+//ADVANCED property for variable: CMAKE_USE_RELATIVE_PATHS
+CMAKE_USE_RELATIVE_PATHS-ADVANCED:INTERNAL=1
+//ADVANCED property for variable: CMAKE_VERBOSE_MAKEFILE
+CMAKE_VERBOSE_MAKEFILE-ADVANCED:INTERNAL=1
+//Have function rand
+HAVE_RAND:INTERNAL=1
+//Have function srand
+HAVE_SRAND:INTERNAL=1
+//STRING
+OpENer_ADD_CIP_OBJECTS:INTERNAL=
+//MODIFIED property for variable: OpENer_PLATFORM
+OpENer_PLATFORM-MODIFIED:INTERNAL=ON
+//STRINGS property for variable: OpENer_PLATFORM
+OpENer_PLATFORM-STRINGS:INTERNAL=POSIX;WIN32;LM3S8962
+

+ 0 - 43
buildsupport/OpENer.cmake

@@ -1,43 +0,0 @@
-FUNCTION(opener_add_definition)
-  FOREACH(ARG ${ARGV})
-    set_property(GLOBAL APPEND PROPERTY OPENER_DEFINITION ${ARG})
-  ENDFOREACH(ARG)
-ENDFUNCTION(opener_add_definition)
-
-##############################################
-# Adds platform specific include directories #
-############################################## 
-macro(opener_platform_support ARGS)
-
-  if(OpENer_PLATFORM STREQUAL "")
-    message(FATAL_ERROR "No platform selected!")  
-  endif(OpENer_PLATFORM STREQUAL "")
-
-  include( ${OpENer_BUILDSUPPORT_DIR}/${OpENer_PLATFORM}/OpENer_PLATFORM_${ARGS}.cmake)
-  opener_platform_spec()
-endmacro(opener_platform_support ARGS)
-
-
-#######################################
-# Adds common Include directories     #
-####################################### 
-macro(opener_common_includes)
-  set( SRC_DIR "${PROJECT_SOURCE_DIR}" )
-  set( CIP_SRC_DIR "${PROJECT_SOURCE_DIR}/cip" )
-  set( ENET_ENCAP_SRC_DIR "${PROJECT_SOURCE_DIR}/enet_encap" )
-  set( PORTS_SRC_DIR "${PROJECT_SOURCE_DIR}/ports")
-
-  include_directories( ${PROJECT_SOURCE_DIR} ${SRC_DIR} ${CIP_SRC_DIR} ${ENET_ENCAP_SRC_DIR} ${PORTS_SRC_DIR} )
-endmacro(opener_common_includes)
-
-MACRO(opener_add_cip_object NAME DESCRIPTION)
-  set(OpENer_CIP_OBJECT_${NAME} OFF CACHE BOOL "${DESCRIPTION}")
-  FOREACH(dependencies ${ARGN})
-	if(NOT ${dependencies})
-	return()
-	endif(NOT ${dependencies})
-  ENDFOREACH(dependencies)
-  if(NOT OpENer_CIP_OBJECT_${NAME})
-    return()
-  endif(NOT OpENer_CIP_OBJECT_${NAME})
-ENDMACRO(opener_add_cip_object)

+ 13 - 42
src/CMakeLists.txt → source/CMakeLists.txt

@@ -14,45 +14,29 @@ project( OpENer C )
 set( OpENer_VERSION_MAJOR 1 )
 set( OpENer_VERSION_MINOR 2 )
 
-find_path( OpENer_BUILDSUPPORT_DIR OpENer.cmake ${PROJECT_SOURCE_DIR}/../buildsupport)
+find_path( OpENer_BUILDSUPPORT_DIR OpENer.cmake ${PROJECT_SOURCE_DIR}/buildsupport )
  
-INCLUDE( ${OpENer_BUILDSUPPORT_DIR}/OpENer.cmake)
+INCLUDE( ${OpENer_BUILDSUPPORT_DIR}/OpENer.cmake )
 
 #######################################
 # Platform switches                   #
 #######################################
-set( OpENer_KNOWN_PLATFORMS "POSIX" "WIN32" )
+set( OpENer_KNOWN_PLATFORMS "POSIX" "WIN32" "LM3S8962" )
 
 set( OpENer_PLATFORM CACHE STRINGS "Platform OpENer will be built for" )
 set_property(CACHE OpENer_PLATFORM PROPERTY STRINGS ${OpENer_KNOWN_PLATFORMS} )
 
+#######################################
+# Platform-dependent functions check  #
+#######################################
+INCLUDE( ${OpENer_BUILDSUPPORT_DIR}/OpENer_function_checks.cmake )
+
 #######################################
 # OpENer tracer switches              #
 #######################################
 set( OpENer_TRACES OFF CACHE BOOL "Activate OpENer traces" )
 if(OpENer_TRACES)
-  add_definitions( -DOPENER_WITH_TRACES )
-  set( TRACE_LEVEL 0 )
-  set( OpENer_TRACE_LEVEL_ERROR ON CACHE BOOL "Error trace level" )
-  set( OpENer_TRACE_LEVEL_WARNING ON CACHE BOOL "Warning trace level" )
-  set( OpENer_TRACE_LEVEL_STATE ON CACHE BOOL "State trace level" )
-  set( OpENer_TRACE_LEVEL_INFO ON CACHE BOOL "Info trace level" )
-  
-  if(OpENer_TRACE_LEVEL_ERROR)
-    math( EXPR TRACE_LEVEL "${TRACE_LEVEL} + 1" ) #First (LS) bit in the trace level selection code
-  endif(OpENer_TRACE_LEVEL_ERROR)
-  if(OpENer_TRACE_LEVEL_WARNING)
-    math( EXPR TRACE_LEVEL "${TRACE_LEVEL} + 2" ) #Second bit in the trace level selection code
-  endif(OpENer_TRACE_LEVEL_WARNING)
-  if(OpENer_TRACE_LEVEL_STATE)
-    math( EXPR TRACE_LEVEL "${TRACE_LEVEL} + 4" ) #Third bit in the trace level selection code
-  endif(OpENer_TRACE_LEVEL_STATE)
-  if(OpENer_TRACE_LEVEL_INFO)
-    math( EXPR TRACE_LEVEL "${TRACE_LEVEL} + 8" ) #Forth (MS) bit in the trace level selection code
-  endif(OpENer_TRACE_LEVEL_INFO)
-  
-  add_definitions(-DOPENER_TRACE_LEVEL=${TRACE_LEVEL})
-  
+  createTraceLevelOptions()
 endif(OpENer_TRACES)
 
 #######################################
@@ -60,6 +44,7 @@ endif(OpENer_TRACES)
 #######################################
 set( OpENer_TESTS OFF CACHE BOOL "Enable tests to be built" )
 if( OpENer_TESTS )
+  enable_testing()
   enable_language( CXX )
   set( CPPUTEST_HOME "" CACHE PATH "Path to CppUTest directory" )
   INCLUDE( ${OpENer_BUILDSUPPORT_DIR}/OpENer_Tests.cmake )
@@ -79,24 +64,10 @@ set( OpENer_ADD_CIP_OBJECTS "" CACHE INTERNAL STRING )
 #######################################
 # Add custom CIP objects              #
 #######################################
-set( OpENer_CIP_OBJECTS_DIR ${PROJECT_SOURCE_DIR}/cip_objects )
-include( ${OpENer_BUILDSUPPORT_DIR}/OpENer_CIP_Object_generator.cmake )
+set( OpENer_CIP_OBJECTS_DIR ${PROJECT_SOURCE_DIR}/src/cip_objects )
+include(${OpENer_BUILDSUPPORT_DIR}/OpENer_CIP_Object_generator.cmake)
 
 #######################################
 # Add subdirectories                  #
 #######################################
-add_subdirectory( cip )
-add_subdirectory( cip_objects )
-add_subdirectory( enet_encap )
-add_subdirectory( ports )
-
-#######################################
-# Add common includes                 #
-#######################################
-opener_common_includes()
-
-#######################################
-# Add platfrom specific things        #
-#######################################
-
-opener_platform_support( "INCLUDES" )
+add_subdirectory( src )

+ 17 - 0
source/buildsupport/LM3S8962/OpENer_PLATFORM_INCLUDES.cmake

@@ -0,0 +1,17 @@
+macro(opener_platform_spec)
+  set( LM3S8962_CONTRIB_DIR "" CACHE PATH "Contrib folder of the used LM3S0862 board")
+  include_directories(${PORTS_SRC_DIR}/${OpENer_PLATFORM} 
+			${PORTS_SRC_DIR}/${OpENer_PLATFORM}/sample_application 
+			${LM3S8962_CONTRIB_DIR}
+			${LM3S8962_CONTRIB_DIR}/utils 
+			${LM3S8962_CONTRIB_DIR}/boards/rdk-bldc/qs-bldc/
+			${LM3S8962_CONTRIB_DIR}/boards/ek-lm3s8962
+			${LM3S8962_CONTRIB_DIR}/boards/ek-lm3s8962/enet_lwip/
+			${LM3S8962_CONTRIB_DIR}/third_party/lwip-1.3.2/src/include
+			${LM3S8962_CONTRIB_DIR}/third_party/lwip-1.3.2/ports/stellaris/include/
+			${LM3S8962_CONTRIB_DIR}/third_party/lwip-1.3.2/src/include/ipv4/
+			${LM3S8962_CONTRIB_DIR}/inc/)
+  set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ansi -std=c99 -mfpu=fpv4-sp-d16 -DGCC_ARMCM3_LM3S102 -Dgcc -DEIP_DEBUG=0" )
+  set( PLATFORM_LINKER_FLAGS "-Wl,--no-gc-sections -nostartfiles" )
+endmacro(opener_platform_spec)
+

+ 71 - 0
source/buildsupport/OpENer.cmake

@@ -0,0 +1,71 @@
+FUNCTION(opener_add_definition)
+  FOREACH(ARG ${ARGV})
+    set_property(GLOBAL APPEND PROPERTY OPENER_DEFINITION ${ARG})
+  ENDFOREACH(ARG)
+ENDFUNCTION(opener_add_definition)
+
+##############################################
+# Adds platform specific include directories #
+############################################## 
+macro(opener_platform_support ARGS)
+
+  if(OpENer_PLATFORM STREQUAL "")
+    message(FATAL_ERROR "No platform selected!")  
+  endif(OpENer_PLATFORM STREQUAL "")
+
+  include( ${OpENer_BUILDSUPPORT_DIR}/${OpENer_PLATFORM}/OpENer_PLATFORM_${ARGS}.cmake)
+  opener_platform_spec()
+endmacro(opener_platform_support ARGS)
+
+
+#######################################
+# Adds common Include directories     #
+####################################### 
+macro(opener_common_includes)
+  set( SRC_DIR "${PROJECT_SOURCE_DIR}/src" )
+  set( CIP_SRC_DIR "${SRC_DIR}/cip" )
+  set( ENET_ENCAP_SRC_DIR "${SRC_DIR}/enet_encap" )
+  set( PORTS_SRC_DIR "${SRC_DIR}/ports")
+  set( UTILS_SRC_DIR "${SRC_DIR}/utils")
+
+  include_directories( ${PROJECT_SOURCE_DIR} ${SRC_DIR} ${CIP_SRC_DIR} ${ENET_ENCAP_SRC_DIR} ${PORTS_SRC_DIR} ${UTILS_SRC_DIR} ${OpENer_CIP_OBJECTS_DIR} )
+endmacro(opener_common_includes)
+
+MACRO(opener_add_cip_object NAME DESCRIPTION)
+  set(OpENer_CIP_OBJECT_${NAME} OFF CACHE BOOL "${DESCRIPTION}")
+  FOREACH(dependencies ${ARGN})
+	if(NOT ${dependencies})
+	return()
+	endif(NOT ${dependencies})
+  ENDFOREACH(dependencies)
+  if(NOT OpENer_CIP_OBJECT_${NAME})
+    return()
+  endif(NOT OpENer_CIP_OBJECT_${NAME})
+ENDMACRO(opener_add_cip_object)
+
+#######################################
+# Creates options for trace level     #
+####################################### 
+macro(createTraceLevelOptions)
+  add_definitions( -DOPENER_WITH_TRACES )
+  set( TRACE_LEVEL 0 )
+  set( OpENer_TRACE_LEVEL_ERROR ON CACHE BOOL "Error trace level" )
+  set( OpENer_TRACE_LEVEL_WARNING ON CACHE BOOL "Warning trace level" )
+  set( OpENer_TRACE_LEVEL_STATE ON CACHE BOOL "State trace level" )
+  set( OpENer_TRACE_LEVEL_INFO ON CACHE BOOL "Info trace level" )
+  
+  if(OpENer_TRACE_LEVEL_ERROR)
+    math( EXPR TRACE_LEVEL "${TRACE_LEVEL} + 1" )
+  endif(OpENer_TRACE_LEVEL_ERROR)
+  if(OpENer_TRACE_LEVEL_WARNING)
+    math( EXPR TRACE_LEVEL "${TRACE_LEVEL} + 2" )
+  endif(OpENer_TRACE_LEVEL_WARNING)
+  if(OpENer_TRACE_LEVEL_STATE)
+    math( EXPR TRACE_LEVEL "${TRACE_LEVEL} + 4" )
+  endif(OpENer_TRACE_LEVEL_STATE)
+  if(OpENer_TRACE_LEVEL_INFO)
+    math( EXPR TRACE_LEVEL "${TRACE_LEVEL} + 8" )
+  endif(OpENer_TRACE_LEVEL_INFO)
+  
+  add_definitions(-DOPENER_TRACE_LEVEL=${TRACE_LEVEL})
+endmacro(createTraceLevelOptions)

+ 0 - 0
buildsupport/OpENer_CIP_Object_generator.cmake → source/buildsupport/OpENer_CIP_Object_generator.cmake


+ 0 - 0
buildsupport/OpENer_Tests.cmake → source/buildsupport/OpENer_Tests.cmake


+ 12 - 0
source/buildsupport/OpENer_function_checks.cmake

@@ -0,0 +1,12 @@
+########################################
+# Check if functions exist on platform #
+########################################
+
+include (CheckFunctionExists)
+
+check_function_exists( srand HAVE_SRAND )
+check_function_exists( rand HAVE_RAND )
+
+if( (NOT(HAVE_SRAND)) OR (NOT(HAVE_RAND)) )
+  
+endif( (NOT(HAVE_SRAND)) OR (NOT(HAVE_RAND)) )

+ 0 - 0
buildsupport/POSIX/OpENer_PLATFORM_INCLUDES.cmake → source/buildsupport/POSIX/OpENer_PLATFORM_INCLUDES.cmake


+ 71 - 0
source/buildsupport/Toolchain/Toolchain-EABI-ARM-Generic.cmake

@@ -0,0 +1,71 @@
+INCLUDE(CMakeForceCompiler)
+
+# Embedded System - No OS
+SET(CMAKE_SYSTEM_NAME Generic)
+# Specifiy CPU
+set(CMAKE_SYSTEM_PROCESSOR cortex-m3)
+
+# specify the cross compiler
+CMAKE_FORCE_C_COMPILER(arm-none-eabi-gcc GNU)
+CMAKE_FORCE_CXX_COMPILER(arm-none-eabi-g++ GNU)
+
+# Find the target environment prefix..
+# First see where gcc is keeping libc.a
+execute_process(
+  COMMAND ${CMAKE_C_COMPILER} -print-file-name=libc.a
+  OUTPUT_VARIABLE CMAKE_INSTALL_PREFIX
+  OUTPUT_STRIP_TRAILING_WHITESPACE
+)
+
+# Strip the filename off
+get_filename_component(CMAKE_INSTALL_PREFIX
+  "${CMAKE_INSTALL_PREFIX}" PATH
+)
+
+# Then find the canonical path to the directory one up from there
+get_filename_component(CMAKE_INSTALL_PREFIX
+  "${CMAKE_INSTALL_PREFIX}/.." REALPATH
+)
+
+set(CMAKE_INSTALL_PREFIX  ${CMAKE_INSTALL_PREFIX} CACHE FILEPATH
+    "Install path prefix, prepended onto install directories.")
+
+message(STATUS "Cross-compiling with the gcc-arm-embedded toolchain")
+message(STATUS "Toolchain prefix: ${CMAKE_INSTALL_PREFIX}")
+
+set(CMAKE_FIND_ROOT_PATH  ${CMAKE_INSTALL_PREFIX})
+
+set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
+set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
+set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
+
+set(CMAKE_C_FLAGS
+  "${CMAKE_C_FLAGS}"
+  "-fno-common"
+  "-Wstrict-prototypes -ffunction-sections -fdata-sections"
+)
+
+if (CMAKE_SYSTEM_PROCESSOR STREQUAL "cortex-m3")
+
+  set(CMAKE_C_FLAGS
+    "${CMAKE_C_FLAGS}"
+    "-mcpu=cortex-m3 -march=armv7-m -mthumb"
+    "-msoft-float"
+    "-ffunction-sections -fdata-sections"
+  )
+endif()
+
+if (NOT DEFINED CMAKE_SYSTEM_PROCESSOR)
+  message(WARNING
+    "Processor not recognised in toolchain file, "
+    "compiler flags not configured."
+  )
+endif ()
+
+# When we break up long strings in CMake we get semicolon
+# separated lists, undo this here...
+string(REGEX REPLACE ";" " " CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
+
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "")
+
+set(BUILD_SHARED_LIBS OFF)

+ 0 - 0
buildsupport/WIN32/OpENer_PLATFORM_INCLUDES.cmake → source/buildsupport/WIN32/OpENer_PLATFORM_INCLUDES.cmake


+ 0 - 0
contrib/msinttypes/README → source/contrib/msinttypes/README


+ 0 - 0
contrib/msinttypes/inttypes.h → source/contrib/msinttypes/inttypes.h


+ 0 - 0
doc/coding_rules/opener_coding_rules.pdf → source/doc/coding_rules/opener_coding_rules.pdf


+ 0 - 0
doc/coding_rules/src/opener_coding_rules.tex → source/doc/coding_rules/src/opener_coding_rules.tex


+ 0 - 0
opener.doxyfile → source/opener.doxyfile


+ 19 - 0
source/src/CMakeLists.txt

@@ -0,0 +1,19 @@
+#######################################
+# Add subdirectories                  #
+#######################################
+add_subdirectory( cip )
+add_subdirectory( cip_objects )
+add_subdirectory( enet_encap )
+add_subdirectory( ports )
+add_subdirectory( utils )
+
+#######################################
+# Add common includes                 #
+#######################################
+opener_common_includes()
+
+#######################################
+# Add platfrom specific things        #
+#######################################
+
+opener_platform_support( "INCLUDES" )

+ 0 - 0
src/cip/CMakeLists.txt → source/src/cip/CMakeLists.txt


+ 0 - 0
src/cip/appcontype.c → source/src/cip/appcontype.c


+ 0 - 0
src/cip/appcontype.h → source/src/cip/appcontype.h


+ 0 - 0
src/cip/cipassembly.c → source/src/cip/cipassembly.c


+ 0 - 0
src/cip/cipassembly.h → source/src/cip/cipassembly.h


+ 0 - 0
src/cip/cipclass3connection.c → source/src/cip/cipclass3connection.c


+ 0 - 0
src/cip/cipclass3connection.h → source/src/cip/cipclass3connection.h


+ 0 - 0
src/cip/cipcommon.c → source/src/cip/cipcommon.c


+ 0 - 0
src/cip/cipcommon.h → source/src/cip/cipcommon.h


+ 0 - 0
src/cip/cipconnectionmanager.c → source/src/cip/cipconnectionmanager.c


+ 0 - 0
src/cip/cipconnectionmanager.h → source/src/cip/cipconnectionmanager.h


+ 0 - 0
src/cip/ciperror.h → source/src/cip/ciperror.h


+ 0 - 0
src/cip/cipethernetlink.c → source/src/cip/cipethernetlink.c


+ 0 - 0
src/cip/cipethernetlink.h → source/src/cip/cipethernetlink.h


+ 0 - 0
src/cip/cipidentity.c → source/src/cip/cipidentity.c


+ 0 - 0
src/cip/cipidentity.h → source/src/cip/cipidentity.h


+ 0 - 0
src/cip/cipioconnection.c → source/src/cip/cipioconnection.c


+ 0 - 0
src/cip/cipioconnection.h → source/src/cip/cipioconnection.h


+ 0 - 0
src/cip/cipmessagerouter.c → source/src/cip/cipmessagerouter.c


+ 0 - 0
src/cip/cipmessagerouter.h → source/src/cip/cipmessagerouter.h


+ 0 - 0
src/cip/ciptcpipinterface.c → source/src/cip/ciptcpipinterface.c


+ 0 - 0
src/cip/ciptcpipinterface.h → source/src/cip/ciptcpipinterface.h


+ 0 - 0
src/cip/ciptypes.h → source/src/cip/ciptypes.h


+ 0 - 0
src/cip_objects/CMakeLists.txt → source/src/cip_objects/CMakeLists.txt


+ 0 - 0
src/enet_encap/CMakeLists.txt → source/src/enet_encap/CMakeLists.txt


+ 0 - 0
src/enet_encap/cpf.c → source/src/enet_encap/cpf.c


+ 0 - 0
src/enet_encap/cpf.h → source/src/enet_encap/cpf.h


+ 0 - 0
src/enet_encap/encap.c → source/src/enet_encap/encap.c


+ 0 - 0
src/enet_encap/encap.h → source/src/enet_encap/encap.h


+ 0 - 0
src/enet_encap/endianconv.c → source/src/enet_encap/endianconv.c


+ 0 - 0
src/enet_encap/endianconv.h → source/src/enet_encap/endianconv.h


+ 0 - 0
src/opener_api.h → source/src/opener_api.h


+ 0 - 0
src/ports/CMakeLists.txt → source/src/ports/CMakeLists.txt


+ 41 - 0
source/src/ports/LM3S8962/CMakeLists.txt

@@ -0,0 +1,41 @@
+add_subdirectory(sample_application)
+
+#######################################
+# Platform specific options           #
+#######################################
+set( USE_STATIC_IP OFF CACHE BOOL "Use the static IP defined in main.c" )
+
+if( USE_STATIC_IP )
+  add_definitions( -DuseStaticIP=1 )
+else( USE_STATIC_IP )
+  add_definitions( -DuseStaticIP=0 )
+endif( USE_STATIC_IP )
+
+set( NEWLIB_SRC "" CACHE PATH "Path to NewLib source directory" )
+
+set( PLATFORM_SPEC_SRC networkhandler.c basiccip.c flashmgr.c stubs.c startup_gcc.c )
+set( SBRK_SRC ${NEWLIB_SRC}/libgloss/libnosys/sbrk.c)
+
+add_library(sbrk ${SBRK_SRC} )
+
+#######################################
+# Add common includes                 #
+#######################################
+opener_common_includes()
+
+#######################################
+# Add platform-specific includes      #
+#######################################
+opener_platform_support("INCLUDES")
+
+include_directories(${CIP_ELECTRICAL_ENERGY_INCLUDE})
+set (PLATFORMLIBNAME ${OpENer_PLATFORM}PLATFORM)
+
+link_directories( ${LM3S8962_CONTRIB_DIR}/driverlib/gcc-cm3 )
+
+add_library( ${PLATFORMLIBNAME} ${PLATFORM_SPEC_SRC} )
+
+add_executable( OpENer ${LM3S8962_CONTRIB_DIR}/utils/lwiplib.c )
+
+target_link_libraries( OpENer SAMPLE_APP CIP ENET_ENCAP Utils ${PLATFORMLIBNAME} ${PLATFORM_SPEC_LIBS} )
+target_link_libraries( OpENer ${OpENer_ADD_CIP_OBJECTS} ${PLATFORM_LINKER_FLAGS} driver-cm3 m gcc c sbrk "-T ${CMAKE_CURRENT_SOURCE_DIR}/stellaris.ld")

+ 69 - 0
source/src/ports/LM3S8962/README

@@ -0,0 +1,69 @@
+README for the usage of OpENer with a LM3S8962 kit:
+
+Depending on which eval kit you may have please install the kit
+
+For example the eval kits for the Luminary/Texas Instruments(R)
+LM3S8962 eval kit (display board or brushless DC boards) can 
+be found here:
+	http://www.ti.com/tool/sw-ek-lm3s8962
+	http://www.ti.com/tool/sw-rdk-bldc
+
+This port uses the MentorGraphics(R) Code Sourcery Lite ARM-NONE-EABI toolchain
+ which can be found here: 
+http://www.mentor.com/embedded-software/sourcery-tools/sourcery-codebench/overview
+
+On Debian 7+ you need to install ia32-libs before you can install the
+MentorGraphics(R) Code Sourcery Lite ARM-NONE-EABI toolchain. This manual can 
+also be found at the MentorGraphics(R) website:
+
+To install the ia32-libs enter the following commands, which must be executed
+as root:
+
+  dpkg --add-architecture i386
+  apt-get update
+  apt-get install ia32-libs ia32-libs-gtk
+
+This part was also stated in the manual at MentorGraphics(R) but didn't work
+for me, but I was able to install the toolchain anyhow
+
+  wget https://sourcery.mentor.com/GNUToolchain/kbattach150/getlibs-all.deb
+  sudo dpkg -i getlibs-all.deb
+  sudo getlibs -p xulrunner-1.9.2
+  export MOZILLA_FIVE_HOME=/usr/lib32/xulrunner-1.9.2.X
+
+In addition the _sbrk function must be provided. An _sbrk implementation can
+be found in newlib/libgloss/libnosys. The CMake script allows to enter the path
+to the newlib source. The newlib source can be found at:
+  https://sourceware.org/newlib/
+
+If you are using newlib you have to add a user heap section to your linker 
+script like the one provided here:
+
+	/* User_heap_stack section, used to check that there is enough RAM 
+	left */
+	  ._user_heap_stack :
+	  {
+	    . = ALIGN(4);
+	    PROVIDE ( end = . );
+	    PROVIDE ( _end = . );
+	    _heap_start_ = .;
+	    . = . + _Min_Heap_Size;
+	    _heap_end_ = .;
+	    _stack_start_ = .;
+	    . = . + _Min_Stack_Size;
+	    _stack_end_ = .;
+	    . = ALIGN(4);
+	  } > SRAM 
+
+Alternatively, the myLib provided on the CD of the board can be used 
+instead of the newLib and the add-on to the linker script.
+
+Unfortunatly, the myLib isn't provided in the offical download (at the time I 
+was looking it up it was SW-EK-LM3S8962-10636) of the evaluation kit at the 
+Texas Instruments(R) homepage.
+
+Last, but not least, you place the your startup_gcc.c and linker script in the 
+opener/source/src/ports/LM3S8962 directory.
+
+If something in this README isn't clear please put your question here:
+  https://github.com/EIPStackGroup/OpENer

+ 33 - 0
source/src/ports/LM3S8962/archnw.h

@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * Copyright (c) 2009, Rockwell Automation, Inc.
+ * All rights reserved.
+ *
+ ******************************************************************************/
+
+#ifndef ARCHNW_H_
+#define ARCHNW_H_
+
+#include "lwiplib.h"
+
+extern void *mycalloc(unsigned);
+#define cip_calloc(x,y) mycalloc((unsigned)((x)*(y)))
+
+#define INLINE inline
+
+#define SOCKET_ERROR -1
+
+#define TIMERTICK 10 /* time between calls of manageConnections() in Milliseconds */
+
+// define the socket address structure -- it is different between Berkley sockets and LWIP
+
+typedef unsigned short int sa_family_t;
+typedef unsigned short int in_port_t;
+typedef unsigned int in_addr_t;
+
+#define PF_INET         2					// protocol family
+#define AF_INET         PF_INET					// address family
+#define SOCK_DGRAM	2
+#define SHUT_RDWR	2
+#define INADDR_ANY	0
+
+#endif /*ARCHNW_H_*/

+ 148 - 0
source/src/ports/LM3S8962/basiccip.c

@@ -0,0 +1,148 @@
+/*******************************************************************************
+ * Copyright (c) 2009, Rockwell Automation, Inc.
+ * All rights reserved. 
+ *
+ ******************************************************************************/
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include "networkhandler.h"
+#include "opener_api.h"
+#include "cipcommon.h"
+#include "trace.h"
+
+#define DEMO_APP_INPUT_ASSEMBLY_NUM                0x301
+#define DEMO_APP_OUTPUT_ASSEMBLY_NUM               0x302
+#define DEMO_APP_CONFIG_ASSEMBLY_NUM               0x303
+#define DEMO_APP_HEARBEAT_INPUT_ONLY_ASSEMBLY_NUM  0x304
+#define DEMO_APP_HEARBEAT_LISTEN_ONLY_ASSEMBLY_NUM 0x305
+#define DEMO_APP_EXPLICT_ASSEMBLY_NUM              0x306
+
+
+/* global variables for demo application (4 assembly data fields) */
+EIP_UINT8 g_assemblydata301[32]; /* Input */
+EIP_UINT8 g_assemblydata302[32]; /* Output */
+EIP_UINT8 g_assemblydata303[10]; /* Config */
+EIP_UINT8 g_assemblydata306[32]; /* Explicit */
+
+extern int newfd;
+
+
+EIP_STATUS
+IApp_Init(void)
+{
+//  CIP_Motion_Init();
+
+  /* create 3 assembly object instances*/
+  /*INPUT*/
+  createAssemblyObject(DEMO_APP_INPUT_ASSEMBLY_NUM, &g_assemblydata301[0], sizeof(g_assemblydata301));
+
+  /*OUTPUT*/
+  createAssemblyObject(DEMO_APP_OUTPUT_ASSEMBLY_NUM, &g_assemblydata302[0], sizeof(g_assemblydata302));
+
+  /*CONFIG*/
+  createAssemblyObject(DEMO_APP_CONFIG_ASSEMBLY_NUM, &g_assemblydata303[0], sizeof(g_assemblydata303));
+
+  /*Heart-beat output assembly for Input only connections */
+  createAssemblyObject(DEMO_APP_HEARBEAT_INPUT_ONLY_ASSEMBLY_NUM, 0, 0);
+
+  /*Heart-beat output assembly for Listen only connections */
+  createAssemblyObject(DEMO_APP_HEARBEAT_LISTEN_ONLY_ASSEMBLY_NUM, 0, 0);
+
+  /* assembly for explicit messaging */
+  createAssemblyObject(DEMO_APP_EXPLICT_ASSEMBLY_NUM, &g_assemblydata306[0], sizeof(g_assemblydata306));
+
+  configureExclusiveOwnerConnectionPoint(0, DEMO_APP_OUTPUT_ASSEMBLY_NUM, DEMO_APP_INPUT_ASSEMBLY_NUM, DEMO_APP_CONFIG_ASSEMBLY_NUM);
+  configureInputOnlyConnectionPoint(0, DEMO_APP_HEARBEAT_INPUT_ONLY_ASSEMBLY_NUM, DEMO_APP_INPUT_ASSEMBLY_NUM, DEMO_APP_CONFIG_ASSEMBLY_NUM);
+  configureListenOnlyConnectionPoint(0, DEMO_APP_HEARBEAT_LISTEN_ONLY_ASSEMBLY_NUM, DEMO_APP_INPUT_ASSEMBLY_NUM, DEMO_APP_CONFIG_ASSEMBLY_NUM);
+
+  return EIP_OK;
+}
+
+void
+IApp_IOConnectionEvent(unsigned int pa_unOutputAssembly,
+    unsigned int pa_unInputAssembly, EIOConnectionEvent pa_eIOConnectionEvent)
+{
+  /* maintain a correct output state according to the connection state*/
+
+  (void) pa_unOutputAssembly; /* suppress compiler warning */
+  pa_unInputAssembly = pa_unInputAssembly; /* suppress compiler warning */
+  pa_eIOConnectionEvent = pa_eIOConnectionEvent; /* suppress compiler warning */
+}
+
+EIP_STATUS
+IApp_AfterAssemblyDataReceived(S_CIP_Instance *pa_pstInstance)
+{
+  /*handle the data received e.g., update outputs of the device */
+
+  if (pa_pstInstance->nInstanceNr == DEMO_APP_OUTPUT_ASSEMBLY_NUM)
+    {
+      /* Data for the output assembly has been received.
+       * Mirror it to the inputs */
+      memcpy(&g_assemblydata301[0], &g_assemblydata302[0], sizeof(g_assemblydata301));
+    }
+  else if (pa_pstInstance->nInstanceNr == DEMO_APP_EXPLICT_ASSEMBLY_NUM)
+    {
+      /* do something interesting with the new data from
+       * the explicit set-data-attribute message */
+    }
+
+  return EIP_OK;
+}
+
+EIP_BOOL8
+IApp_BeforeAssemblyDataSend(S_CIP_Instance *pa_pstInstance)
+{
+  /*update data to be sent e.g., read inputs of the device */
+  /*In this sample app we mirror the data from out to inputs on data receive
+   * therefore we need nothing to do here. Just return true to inform that
+   * the data is new.
+   */
+
+  if (pa_pstInstance->nInstanceNr == DEMO_APP_EXPLICT_ASSEMBLY_NUM)
+    {
+      /* do something interesting with the existing data
+       * for the explicit get-data-attribute message */
+    }
+  return true;
+}
+
+EIP_STATUS
+IApp_ResetDevice(void)
+{
+  /* add reset code here*/
+  return EIP_OK;
+}
+
+EIP_STATUS
+IApp_ResetDeviceToInitialConfiguration(void)
+{
+  /*rest the parameters and than perform device reset*/
+  return EIP_OK;
+}
+
+void *
+IApp_CipCalloc(unsigned pa_nNumberOfElements, unsigned pa_nSizeOfElement)
+{
+  return mem_calloc(pa_nNumberOfElements, pa_nSizeOfElement);
+}
+
+void
+IApp_CipFree(void *pa_poData)
+{
+  mem_free(pa_poData);
+}
+
+void
+IApp_RunIdleChanged(EIP_UINT32 pa_nRunIdleValue)
+{
+  (void) pa_nRunIdleValue;
+}
+
+void
+IApp_HandleApplication(void)
+{
+  /* check if application needs to trigger an connection */
+}
+

+ 9 - 0
source/src/ports/LM3S8962/config.h

@@ -0,0 +1,9 @@
+/*******************************************************************************
+ * Copyright (c) 2009, Rockwell Automation, Inc.
+ * All rights reserved. 
+ *
+ ******************************************************************************/
+
+/*******************************************************************************
+ * Empty config.h file for _sbrk in newlib/libgloss/libnosys
+ ******************************************************************************/

+ 130 - 0
source/src/ports/LM3S8962/flashmgr.c

@@ -0,0 +1,130 @@
+/*******************************************************************************
+ * Copyright (c) 2009, Rockwell Automation, Inc.
+ * All rights reserved.
+ *
+ ******************************************************************************/
+
+#include <stdio.h>
+#include <string.h>
+#include <assert.h>
+#include <stdlib.h>
+
+#include "hw_memmap.h"
+#include "hw_types.h"
+#include "driverlib/flash.h"
+#include "driverlib/gpio.h"
+#include "lwiplib.h"
+
+/*
+ * This flash manager is rudimentary. It does wear leveling by allocating small chunks at a time.
+ * When a new parameter block is to be written the old one is erased by writing zeros to it. When
+ * there is no more space in the 1K chunk for a new parameter block the entire chunk is erased. 
+ *
+ * assumptions:
+ *   -- erased FLASH is all ones
+ *   -- bits in individual words can be written to zero
+ *   -- a word that is part ones and part zeros can be written to all zeros
+ *   -- to get any bits changed back to ones the entire chunk has to be erased
+ * 
+ * A parameter block starts with a one word size field. The size indicates the size of the following data.
+ * If the size field is zero, the block is erased. 
+ * 
+ * A chunk of flash can be in one of three states:
+ *   -- erased (all ones)
+ *   -- data (starts with a size word that is not 0 or 0xffffffff
+ *   -- zeroed (all zeros)
+ * 
+ */
+
+// This flash manger only supports one parameter block at a time.
+// It does not support multiple block types, or multiple instances of blocks.
+
+
+#define FLASHBASE ((unsigned long *)(255*1024))			// parameter sector is the last 1024 byte chunk of the program flash
+#define FLASHEND ((unsigned long *)(256*1024))
+#define CHUNKSIZE 1024
+static const int erasedFlashField = 0xffffffff;
+
+// erase everything in the parameters block
+static void eraseAllParameters(void)
+{
+	FlashErase((unsigned long)FLASHBASE);
+}
+
+// find the parameter block
+// returns the address of the parameter block, or zero if not found
+
+unsigned long* findNextEmptyParameterBlock(void)
+{
+	unsigned long* currentFlashAddress = FLASHBASE;
+	unsigned long* const noSpaceLeft = 0;
+
+	while (currentFlashAddress < FLASHEND)
+	{
+		if (0 == *currentFlashAddress)
+			++currentFlashAddress;
+		else if (erasedFlashField == *currentFlashAddress)
+			return noSpaceLeft;
+		else
+			return currentFlashAddress;
+	}
+	return noSpaceLeft;
+}
+
+// verify that the block to be written is erased
+static int parameterBlockIsEmpty(unsigned long *data, // pointer to are to be checked
+		int dataSize) // sizeof(struct)
+{
+	int const isNotEmpty = 0;
+	int const isEmpty = 1;
+	while (dataSize > 0)
+	{
+		if (*data++ != erasedFlashField)
+			return isNotEmpty;
+		dataSize -= 4;
+	}
+	return isEmpty;
+}
+
+// write a new parameter block
+void writeParameter(unsigned long *data, // pointer to struct to be saved
+		int dataSize) // sizeof(struct)
+{
+	unsigned long *currentParameterBlock = findNextEmptyParameterBlock(); // find the current parameter block;
+	unsigned long zero = 0;
+
+	if (currentParameterBlock) // if found, zero it
+	{
+		int lengthToBeErased = *currentParameterBlock + 4; // calc dataSize of region to be erased
+
+		if (currentParameterBlock + lengthToBeErased / 4 <= FLASHEND) // if properly formatted, zero the current block
+		{
+			while (lengthToBeErased > 0) //   for each word
+			{
+				FlashProgram(&zero, (unsigned long)currentParameterBlock, 4); // zero one word
+				currentParameterBlock++; //     advance to next word
+				lengthToBeErased -= 4; //     dec dataSize
+			}
+		}
+		else // else flash is corrupt -- erase it all
+		{
+			eraseAllParameters();
+			currentParameterBlock = FLASHBASE;
+		}
+	}
+
+	// at this point p should point to useable erased flash
+
+	// currentParameterBlock now points to the first unerased word
+
+	if (currentParameterBlock + dataSize/4 > FLASHEND // if flash is full
+			|| !parameterBlockIsEmpty(currentParameterBlock, dataSize)) // or not properly erased
+	{
+		eraseAllParameters(); // erase the entire block
+		currentParameterBlock = FLASHBASE; // start from the beginning
+	}
+
+	FlashProgram((unsigned long *)&dataSize, (unsigned long)currentParameterBlock, 4); // program the length
+	FlashProgram(data, (unsigned long)(currentParameterBlock+1), dataSize); // program the data
+}
+

+ 8 - 0
source/src/ports/LM3S8962/flashmgr.h

@@ -0,0 +1,8 @@
+/*******************************************************************************
+ * Copyright (c) 2009, Rockwell Automation, Inc.
+ * All rights reserved.
+ *
+ ******************************************************************************/
+
+extern unsigned long *findNextEmptyParameterBlock(void);
+extern void writeParameter(unsigned long *data, int dataSize);

+ 426 - 0
source/src/ports/LM3S8962/networkhandler.c

@@ -0,0 +1,426 @@
+/*******************************************************************************
+ * Copyright (c) 2009, Rockwell Automation, Inc.
+ * All rights reserved.
+ *
+ ******************************************************************************/
+
+#include <string.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <assert.h>
+
+#include "networkhandler.h"
+#include "cipcommon.h"
+#include "cipconnectionmanager.h"
+
+#include "encap.h"
+#include <trace.h>
+
+#define EIP_VERBOSE	2
+#define EIP_VVERBOSE	3
+#define EIP_TERSE	1
+
+#define MAX_RECEIVE_SIZE 512
+#define MAX_SEND_SIZE 512
+
+static EIP_UINT8 rxbuf[MAX_RECEIVE_SIZE]; // this appears to be the EIP command buffer
+EIP_UINT8 eip_reply_buf[MAX_SEND_SIZE]; // this appears to be the EthernetIP reply buffer
+
+extern void
+dump(unsigned char *p, int size);
+
+static struct tcp_pcb *TCPlistener;
+static struct udp_pcb *UDPlistener;
+
+#define MAX_NO_OF_TCP_SOCKETS 10
+
+struct sockaddr_in my_addr;
+
+struct tcp_pcb *g_pstCurrentTCP_PCB = NULL;
+
+// UDP UNSOLICITED DATA RECEIVE CALLBACK
+// The callback function is responsible for deallocating the pbuf.
+
+void
+udp_unsolicited_receive_callback(void * arg, // arg specified when the callback was registered
+    struct udp_pcb * pcb, // pcb handling the receive
+    struct pbuf * p, // the packet
+    struct ip_addr * addr, // source IP address
+    u16_t port) // source UDP port number
+{
+  EIP_UINT8 *rxp; // pointer into the receive buf
+  int rxlen; // size of the received message
+  int bytesleft; // bytes left (allows for multiple messages per packet)
+  int replylen;
+  err_t status;
+  struct pbuf * r; // reply buffer
+  struct sockaddr_in stFrom;
+
+  assert(p->tot_len <= sizeof(rxbuf)); // TODO this needs to be hardened
+  pbuf_copy_partial(p, rxbuf, sizeof(rxbuf), 0); // copy the packet into a contiguous receive buffer
+  rxlen = p->tot_len; // size of the received message
+  pbuf_free(p); // we no longer need the packet buffer
+
+  if (EIP_DEBUG > EIP_VVERBOSE)
+    {
+      OPENER_TRACE_INFO("Data received on UDP:\n");
+      dump(rxbuf, rxlen);
+    }
+
+  rxp = &rxbuf[0]; // point to the start of the message
+  do
+    {
+      stFrom.sin_family = AF_INET;
+      stFrom.sin_port = port;
+      stFrom.sin_addr.s_addr = addr->addr;
+      memset(&stFrom.sin_zero, 0, sizeof(stFrom.sin_zero));
+
+      replylen = handleReceivedExplictUDPData((unsigned) pcb, // bogus a socket fd (use the pcb address cast to an int)
+          &stFrom, rxp, rxlen, &bytesleft);
+
+      rxp += rxlen - bytesleft; // bump the buffer pointer by the amount of data that was eaten
+      rxlen = bytesleft; // dec the data size by the same amount
+
+      if (replylen > 0)
+        {
+          if (EIP_DEBUG >= EIP_VVERBOSE)
+            {
+              OPENER_TRACE_INFO("reply sent:\n");
+              dump(eip_reply_buf, replylen);
+            }
+
+          r = pbuf_alloc(PBUF_TRANSPORT, 0, PBUF_REF);
+          assert(r != 0); // TODO harden
+          //r->payload = &eip_reply_buf[0];
+          r->payload = &rxbuf[0];
+          r->len = r->tot_len = replylen;
+          status = udp_sendto(pcb, r, (struct ip_addr *) &addr->addr, port);
+          assert(status == 0); // TODO check for non-fatal status response?
+          pbuf_free(r); // reference counting makes sure the header does not get freed prematurely, but what about the replybuf?
+        }
+    }
+  while (rxlen > 0);
+}
+
+// UDP CONNECTED DATA CALLBACK
+
+void
+udp_registered_receive_callback(void * arg, // arg specified when the callback was registered
+    struct udp_pcb * pcb, // pcb handling the receive
+    struct pbuf * pbuf, // the packet
+    struct ip_addr * addr, // source IP address
+    u16_t port) // source UDP port number
+{
+  EIP_UINT8 *rxp; // pointer into the receive buf
+  int rxlen; // size of the received message
+  struct sockaddr_in stFrom;
+
+  //assert(pbuf->len == pbuf->tot_len);
+  assert(pbuf->tot_len <= MAX_RECEIVE_SIZE); // TODO this needs to be hardened
+  rxlen = pbuf_copy_partial(pbuf, rxbuf, MAX_RECEIVE_SIZE, 0); // copy the packet into a contiguous receive buffer
+  //assert(rxlen == pbuf->tot_len);
+  rxp = &rxbuf[0]; // point to the start of the message
+  pbuf_free(pbuf); // we no longer need the packet buffer
+
+  if (rxlen == 0)
+    {
+      OPENER_TRACE_ERR("connection closed by client\n");
+      udp_disconnect(pcb); /* close socket */
+      udp_remove(pcb);
+      return;
+    }
+  if (rxlen <= 0)
+    {
+      OPENER_TRACE_ERR("networkhandler: error on recv");
+      udp_disconnect(pcb); /* close socket */
+      udp_remove(pcb);
+      return;
+    }
+
+  stFrom.sin_family = AF_INET;
+  stFrom.sin_port = port;
+  stFrom.sin_addr.s_addr = addr->addr;
+  memset(&stFrom.sin_zero, 0, sizeof(stFrom.sin_zero));
+
+  handleReceivedConnectedData(rxbuf, rxlen, &stFrom);
+}
+
+// TCP DATA SENT CALLBACK
+
+err_t
+tcp_sent_callback(void * arg, struct tcp_pcb * tpcb, u16_t len)
+{
+  // TODO unlock the reply buf?
+
+  return ERR_OK;
+}
+
+
+
+// TCP DATA RECEIVE CALLBACK
+
+err_t
+tcp_receive_callback(void * arg, // arg specified earlier
+    struct tcp_pcb *pcb, // pcb that is delivering the data
+    struct pbuf *pbuf, // the packet
+    err_t err) // TCP uses this to tell us what's happening to the connection perhaps?
+{
+  EIP_UINT8 *rxp;
+  int rxlen;
+  int bytesread;
+  int bytesleft;
+  int replylen;
+  int txspace;
+  int rxoff = 0;
+  err_t status;
+
+  if (err != ERR_OK)
+    return err; // don't try to receive if error
+
+  if (pbuf == 0) // check if connection is closing
+    {
+      tcp_close(pcb); // close out end
+      return ERR_OK;
+    }
+
+  while (rxoff < pbuf->tot_len)
+    {
+      rxlen = pbuf_copy_partial(pbuf, rxbuf, 4, rxoff); // copy the first four words into the contiguous receive buffer
+      assert(rxlen == 4); //need at least four bytes of the header at this point
+      rxp = &rxbuf[2]; // at this place EIP stores the data length
+      rxlen = ltohs(&rxp) + ENCAPSULATION_HEADER_LENGTH - 4; // -4 is for the 4 bytes we have already read
+      // (NOTE this advances the buffer pointer)
+
+      if (rxlen + 4 > MAX_RECEIVE_SIZE)
+        { //TODO can this be handled in a better way?
+          OPENER_TRACE_ERR("too large packet received will be ignored\n"); // this may corrupt the connection ???
+          return EIP_ERROR;
+        }
+
+      bytesread = pbuf_copy_partial(pbuf, &rxbuf[4], rxlen, rxoff + 4); // copy the rest of the message into the contiguous receive buffer
+      assert(bytesread == rxlen);
+      rxlen += 4;
+      rxoff += rxlen;
+      tcp_recved(pcb, rxlen); // tell TCP we have received the data
+
+      if (EIP_DEBUG >= EIP_VVERBOSE)
+        {
+          OPENER_TRACE_INFO("Data received on tcp:\n");
+          dump(rxbuf, rxlen);
+        }
+
+      g_pstCurrentTCP_PCB = pcb;
+      replylen = handleReceivedExplictTCPData((unsigned) pcb, // bogus a socket fd (use the pcb address cast to an int) -- I do not think this is used anywhere
+          rxbuf, rxlen, &bytesleft);
+      g_pstCurrentTCP_PCB = NULL;
+      assert(bytesleft == 0);
+
+      if (replylen > 0)
+        {
+          if (EIP_DEBUG >= EIP_VVERBOSE)
+            {
+              OPENER_TRACE_INFO("reply sent:\n");
+              dump(eip_reply_buf, replylen);
+            }
+
+          txspace = tcp_sndbuf(pcb); // see how much data can be sent
+          assert(txspace >= replylen); // TODO harden this
+
+          status = tcp_write(pcb, rxbuf, replylen, TCP_WRITE_FLAG_COPY); // TODO need to examine serial reuse of the reply buf
+          if (status != ERR_OK)
+            {
+              OPENER_TRACE_ERR("TCP response was not sent OK: %d\n", status);
+            }
+          tcp_output(pcb); // push the data out
+        }
+    }
+
+  pbuf_free(pbuf); // we no longer need the packet buffer
+
+  return ERR_OK;
+}
+
+// TCP CONNECTION ACCEPT CALLBACK
+
+err_t
+tcp_connection_accept_callback(void *arg, // arg registered for this listener (ignored in this case)
+    struct tcp_pcb *newpcb, // pcb for new tcp connection
+    err_t err)
+{
+  OPENER_TRACE_INFO("networkhandler: new TCP connection\n");
+
+  tcp_accepted(TCPlistener); // tell the listener that the call was accepted
+
+  tcp_recv(newpcb, tcp_receive_callback); // set the callback for received data on the new connection
+  tcp_sent(newpcb, tcp_sent_callback); // set the callback for transmitted data on the new connection
+
+  return ERR_OK;
+}
+
+/* INT8 Start_NetworkHandler()
+ * 	start a TCP listening socket, accept connections, receive data in select loop, call manageConnections periodicaly.
+ * 	return status
+ * 			-1 .. error
+ */
+
+EIP_STATUS
+Start_NetworkHandler()
+{
+  err_t status;
+
+  my_addr.sin_family = AF_INET;
+  my_addr.sin_port = htons(OPENER_ETHERNET_PORT);
+  my_addr.sin_addr.s_addr = htonl(INADDR_ANY);
+  memset(&my_addr.sin_zero, 0, sizeof(my_addr.sin_zero));
+
+  /* create a new TCP listener socket */
+  TCPlistener = tcp_new();
+  assert(TCPlistener != 0);
+  status = tcp_bind(TCPlistener, INADDR_ANY, OPENER_ETHERNET_PORT);
+  assert(status == 0);
+  TCPlistener = tcp_listen(TCPlistener);
+  assert(TCPlistener != 0);
+  tcp_accept(TCPlistener, tcp_connection_accept_callback);
+
+  /* create a new UDP listener socket */
+  UDPlistener = udp_new();
+  assert(UDPlistener != 0);
+  udp_bind(UDPlistener, INADDR_ANY, OPENER_ETHERNET_PORT);
+  udp_recv(UDPlistener, udp_unsolicited_receive_callback, 0); // set the callback
+
+  return EIP_OK;
+}
+
+static elapsedtime = 0;
+
+// this gets called every 10 ms from the lwiptick handler, which is called from an Ethernet controller interrupt (SYSTICKHZ = 100)
+void
+CIPtick(int delta) // time since last tick in ms, probably 10
+{
+  /* call manage_connections() in connection manager every TIMERTICK ms */
+  elapsedtime += delta;
+  if (elapsedtime >= TIMERTICK)
+    {
+      manageConnections();
+      elapsedtime = 0;
+    }
+}
+
+/* INT8 registerCallbackFunc(int sockfd, struct sockaddr_in pa_addr, S_CIP_Class *p_stObject, INT8 (*pt2func)(S_CIP_Class *p_stObject, INT8 *data, UINT16 datalength))
+ *  register a callbackfuntion with the corresponding CIP object and socket handle.
+ * 	sockfd		sockethandle
+ * 	pa_addr		remote address for sending UDP packets
+ * 	p_stObject	pointer to CIP object which is to be registered
+ * 	(*pt2func)()	pointer to callbackfunktion which will be called if data arrive on sockfd
+ *
+ *	return status	0 .. success
+ * 			-1 .. error
+ */
+
+EIP_STATUS
+registerCallbackFunc(int sockfd, struct sockaddr_in *pa_addr,
+    S_CIP_Instance *pa_pstInstance, TCIPServiceFunc pa_ptfuncReceiveData)
+{
+  return EIP_OK;
+}
+
+EIP_STATUS
+unregisterCallbackFunc(S_CIP_Instance * pa_pstInstance)
+{
+  return EIP_OK;
+}
+
+/* INT8 sendUDPData(struct sockaddr_in pa_addr, int sockfd, INT8 *pa_data, UINT16 pa_datalength)
+ * send udp datagram to pa_addr on socket sockfd.
+ * 	 pa_addr	remote address
+ * 	 sockfd		sockethandle
+ * 	 pa_data	pointer to data which will be sent
+ * 	 pa_datalength	length of data ind pa_data
+ *
+ * return status	0 .. success
+ * 			-1 .. error
+ */
+
+EIP_STATUS
+IApp_SendUDPData(struct sockaddr_in *pa_addr, int sockfd, EIP_UINT8 *pa_data,
+    EIP_UINT16 pa_datalength)
+{
+  struct pbuf *r;
+  err_t status;
+  struct udp_pcb *pcb;
+
+  pcb = (struct udp_pcb *) sockfd;
+  r = pbuf_alloc(PBUF_TRANSPORT, 0, PBUF_REF);
+  assert(r != 0); // TODO harden
+  r->payload = pa_data;
+  r->len = r->tot_len = pa_datalength;
+  status = udp_sendto(pcb, r, (struct ip_addr *) &pa_addr->sin_addr,
+      htons(pa_addr->sin_port));
+  assert(status == 0); // TODO check for non-fatal status response?
+  pbuf_free(r); // reference counting make sure the header does not get freed prematurely, but what about the replybuf?
+
+  return EIP_OK;
+}
+
+// create a new UDP socket for the connection manager
+// returns the fd if successful, else -1
+
+int
+IApp_CreateUDPSocket(int pa_nDirection, // direction: CONSUMING or PRODUCING
+    struct sockaddr_in *pa_pstAddr) // bind address, used for producing only
+{
+  struct udp_pcb *pcb;
+
+  /* create a new UDP socket */
+  pcb = udp_new();
+  if (pcb == 0)
+    {
+      OPENER_TRACE_ERR("networkhandler: cannot create UDP socket\n");
+      return -1;
+    } OPENER_TRACE_INFO("networkhandler: created UDP socket %x\n", pcb);
+
+  /* check if it is sending or receiving */
+  if (pa_nDirection == CONSUMING)
+    { /* bind is only for consuming necessary */
+      struct ip_addr addr;
+
+      addr.addr = htonl(pa_pstAddr->sin_addr.s_addr);
+      if (udp_bind(pcb, &addr, htons(pa_pstAddr->sin_port)) != ERR_OK)
+        {
+          OPENER_TRACE_INFO("networkhandler: error on bind udp\n");
+          return -1;
+        }
+
+      OPENER_TRACE_INFO("networkhandler: bind UDP socket %08x port %d\n", pcb,
+          pa_pstAddr->sin_port);
+      udp_recv(pcb, udp_registered_receive_callback, 0); // set the callback
+    }
+
+
+  if ((pa_nDirection == CONSUMING) || (0 == pa_pstAddr->sin_addr.s_addr))
+    {
+      /* store the originators address */
+      pa_pstAddr->sin_addr.s_addr =  g_pstCurrentTCP_PCB->remote_ip.addr;
+    }
+
+  return (int) pcb;
+}
+
+void IApp_CloseSocket_udp(int fd)
+{
+  struct udp_pcb *pcb;
+
+  OPENER_TRACE_INFO("networkhandler: shutdown UDP socket %x\n", pcb);
+  pcb = (struct udp_pcb *) fd;
+  udp_remove(pcb);
+}
+
+void IApp_CloseSocket_tcp(int fd)
+{
+  struct tcp_pcb *pcb;
+
+  OPENER_TRACE_INFO("networkhandler: shutdown TCP socket %x\n", pcb);
+  pcb = (struct tcp_pcb *) fd;
+  tcp_close(pcb);
+}
+

+ 18 - 0
source/src/ports/LM3S8962/networkhandler.h

@@ -0,0 +1,18 @@
+/*******************************************************************************
+ * Copyright (c) 2009, Rockwell Automation, Inc.
+ * All rights reserved. 
+ *
+ ******************************************************************************/
+#ifndef NETWORKHANDLER_H_
+#define NETWORKHANDLER_H_
+
+#include "typedefs.h"
+
+
+/*! Start a TCP/UDP listening socket, accept connections, receive data in select loop, call manageConnections periodically.
+ *  @return status
+ *          EIP_ERROR .. error
+ */
+EIP_STATUS Start_NetworkHandler(void);
+
+#endif /*NETWORKHANDLER_H_*/

+ 12 - 0
source/src/ports/LM3S8962/sample_application/CMakeLists.txt

@@ -0,0 +1,12 @@
+
+#######################################
+# Add common includes                 #
+#######################################
+opener_common_includes()
+
+#######################################
+# Add platform-specific includes      #
+#######################################
+opener_platform_support("INCLUDES")
+
+add_library( SAMPLE_APP main.c )

+ 337 - 0
source/src/ports/LM3S8962/sample_application/main.c

@@ -0,0 +1,337 @@
+// Scraps of this module were pulled from the following demo program:
+
+//*****************************************************************************
+//
+// enet_lwip.c - Sample WebServer Application using lwIP.
+//
+// Copyright (c) 2007-2008 Luminary Micro, Inc.  All rights reserved.
+// Software License Agreement
+//
+// Luminary Micro, Inc. (LMI) is supplying this software for use solely and
+// exclusively on LMI's micro controller products.
+//
+// The software is owned by LMI and/or its suppliers, and is protected under
+// applicable copyright laws.  All rights are reserved.  You may not combine
+// this software with "viral" open-source software in order to form a larger
+// program.  Any use in violation of the foregoing restrictions may subject
+// the user to criminal sanctions under applicable laws, as well as to civil
+// liability for the breach of the terms and conditions of this license.
+//
+// THIS SOFTWARE IS PROVIDED "AS IS".  NO WARRANTIES, WHETHER EXPRESS, IMPLIED
+// OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
+// LMI SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
+// CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
+//
+// This is part of revision 3618 of the EK-LM3S6965 Rev C Firmware Package.
+//
+//*****************************************************************************
+
+#include <stdio.h>
+#include <string.h>
+#include <assert.h>
+#include <stdlib.h>
+#include <math.h>
+
+#include "hw_ints.h"
+#include "hw_memmap.h"
+#include "hw_nvic.h"
+#include "hw_types.h"
+#include "driverlib/ethernet.h"
+#include "driverlib/flash.h"
+#include "driverlib/gpio.h"
+#include "driverlib/interrupt.h"
+#include "driverlib/sysctl.h"
+#include "driverlib/systick.h"
+#include "lwiplib.h"
+
+#include "flashmgr.h"
+#include "networkhandler.h"
+#include <opener_api.h>
+#include "cipcommon.h"
+#include "random.h"
+#include <trace.h>
+
+//define here instead of ptpd.h
+volatile unsigned long g_ulSystemTimeSecfunctiononds;
+volatile unsigned long g_ulSystemTimeNanoSeconds;
+
+// cast an int as a struct_inaddr (check the "inet_ntoa" man page -- it wants a struct_inaddr passed by value, not an int)
+// static IP-Address?
+//#define useStaticIP 1
+#define useStaticIP 0
+
+#ifndef useStaticIP
+#error "useStaticIP undefined"
+#endif
+
+struct parm
+{
+  int useStatic; // 1 use static IP address, 0 use DHCP
+  unsigned long ip; // my ip address
+  unsigned long nm; // net mask
+  unsigned long gw; // gateway ip address
+};
+
+
+//*****************************************************************************
+//
+// Defines for setting up the system clock.
+//
+//*****************************************************************************
+#define SYSTICKHZ               100
+#define SYSTICKMS               (1000 / SYSTICKHZ)
+#define SYSTICKUS               (1000000 / SYSTICKHZ)
+#define SYSTICKNS               (1000000000 / SYSTICKHZ)
+
+
+//*****************************************************************************
+//
+// Interrupt priority definitions.  The top 3 bits of these values are
+// significant with lower values indicating higher priority interrupts.
+//
+//*****************************************************************************
+#define SYSTICK_INT_PRIORITY    0xF0
+#define ETHERNET_INT_PRIORITY   0xC2
+
+//*****************************************************************************
+//
+// The error routine that is called if the driver library encounters an error.
+//
+//*****************************************************************************
+#ifdef DEBUG
+void
+__error__(char *pcFilename, unsigned long ulLine)
+  {
+  }
+#endif
+
+// change my IP address etc.
+void
+setCIPaddress(unsigned long addr, // my IP address, in network order
+    unsigned long mask, // netmask, in network order
+    unsigned long gw) // gateway, in network order
+{
+  struct in_addr inAddr;
+  inAddr.s_addr = addr;
+  char acIPAddr[16];
+  strncpy(acIPAddr, inet_ntoa(inAddr), 16);
+  inAddr.s_addr = mask;
+  char acNetMask[16];
+  strncpy(acNetMask, inet_ntoa(inAddr), 16);
+  inAddr.s_addr = gw;
+  char acGW[16];
+  strncpy(acGW, inet_ntoa(inAddr), 16);
+
+  configureNetworkInterface(acIPAddr, acNetMask, acGW);
+  configureDomainName("test");
+  configureHostName("karl");
+}
+
+// this gets called every 100 usec by the lwip timer handler
+void
+lwIPHostTimerHandler(void)
+{
+  static unsigned long ulLastIPAddress = 0;
+  unsigned long ulIPAddress;
+  unsigned long ulNetmask;
+  unsigned long ulGateway;
+
+  ulIPAddress = lwIPLocalIPAddrGet();
+
+  if (ulLastIPAddress != ulIPAddress)
+    {
+      ulLastIPAddress = ulIPAddress;
+      ulNetmask = lwIPLocalNetMaskGet();
+      ulGateway = lwIPLocalGWAddrGet();
+      setCIPaddress(ulIPAddress, ulNetmask, ulGateway);
+    }
+}
+
+int
+main(void)
+{
+  int i;
+  unsigned long ulUser0, ulUser1;
+  unsigned char pucMACArray[8];
+
+  unsigned long ip, nm, gw;
+  int valid;
+
+  struct parm parm;
+  struct parm *p;
+  unsigned long *pl;
+
+  IntPriorityGroupingSet(4);
+
+  //
+  // Set the clocking to run directly from the crystal.
+  //
+  SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN
+                  | SYSCTL_XTAL_8MHZ);
+
+  SysCtlPeripheralEnable(SYSCTL_PERIPH_ETH);
+  SysCtlPeripheralReset(SYSCTL_PERIPH_ETH);
+
+  // Enable Port F for Ethernet LEDs.
+  //  LED0        Bit 3   Output
+  //  LED1        Bit 2   Output
+  //
+  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
+  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
+  GPIODirModeSet(GPIO_PORTF_BASE, GPIO_PIN_2 | GPIO_PIN_3, GPIO_DIR_MODE_HW);
+  GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_2 | GPIO_PIN_3,
+                  GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD);
+
+  //
+  // Configure the GPIOs used to read the state of the on-board push buttons.
+  //
+  GPIOPinTypeGPIOInput(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2
+                  | GPIO_PIN_3);
+  GPIOPadConfigSet(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2
+                  | GPIO_PIN_3, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
+  GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_1);
+  GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_1, GPIO_STRENGTH_2MA,
+                  GPIO_PIN_TYPE_STD_WPU);
+
+  // configure the user LED output
+  GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_0);
+  GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_0, 0);
+
+
+
+  //
+  // Configure SysTick for a 100 Hz (10 ms) interrupt.
+  //
+  SysTickPeriodSet(SysCtlClockGet() / SYSTICKHZ);
+  SysTickEnable();
+  SysTickIntEnable();
+
+  //
+  // Enable processor interrupts.
+  //
+  IntMasterEnable();
+
+  //
+  // Configure the hardware MAC address for Ethernet Controller filtering of
+  // incoming packets.
+  //
+  // For the LM3S6965 Evaluation Kit, the MAC address will be stored in the
+  // non-volatile USER0 and USER1 registers.  These registers can be read
+  // using the FlashUserGet function, as illustrated below.
+  //
+  FlashUserGet(&ulUser0, &ulUser1);
+  if ((ulUser0 == 0xffffffff) || (ulUser1 == 0xffffffff))
+    {
+      //
+      // We should never get here.  This is an error if the MAC address has
+      // not been programmed into the device.  Exit the program.
+      //
+
+      while (1)
+        {
+        }
+    }
+
+  //
+  // Convert the 24/24 split MAC address from NV ram into a 32/16 split MAC
+  // address needed to program the hardware registers, then program the MAC
+  // address into the Ethernet Controller registers.
+  //
+
+  pucMACArray[0] = ((ulUser0 >> 0) & 0xff);
+  pucMACArray[1] = ((ulUser0 >> 8) & 0xff);
+  pucMACArray[2] = ((ulUser0 >> 16) & 0xff);
+  pucMACArray[3] = ((ulUser1 >> 0) & 0xff);
+  pucMACArray[4] = ((ulUser1 >> 8) & 0xff);
+  pucMACArray[5] = ((ulUser1 >> 16) & 0xff);
+
+  //////////////////////////////////////////////////////////
+  // YOU MUST SET THESE TO VALID VALUES FOR YOUR LOCATION //
+  //////////////////////////////////////////////////////////
+  configureMACAddress(pucMACArray);
+
+  //
+  // Initialze the lwIP library
+  //
+
+
+  pl = findNextEmptyParameterBlock();
+  p = (struct parm *) (pl + 1);
+
+  if (useStaticIP)
+    {
+      OPENER_TRACE_INFO("using static IP address\n");
+
+      ip = 0x8083BAC9; //128.130.200.201
+      nm = 0xFFFFFF00;
+      gw = 0x8083BA01;
+      valid = 7;
+      lwIPInit(pucMACArray, ip, nm, gw, IPADDR_USE_STATIC);
+    }
+  else
+    {
+      //
+      // Initialze the lwIP library, using DHCP.
+      //
+      OPENER_TRACE_INFO("using DHCP\n");
+      valid = 0; //0
+      lwIPInit(pucMACArray, 0, 0, 0, IPADDR_USE_DHCP);
+    }
+
+    //change time-interval value for call of updateElMeasuringAndMeteringData
+    //in SysTickIntHandler-method to show/provide correct values (see line 370)
+
+  IntPrioritySet(INT_ETH, ETHERNET_INT_PRIORITY);
+  IntPrioritySet(FAULT_SYSTICK, SYSTICK_INT_PRIORITY);
+
+  /*for a real device the serial number should be unique per device */
+  setDeviceSerialNumber(123456789);
+
+  /* Setup the CIP Layer */
+  CIP_Init(365);
+  IntMasterDisable();
+
+  IntMasterEnable();
+  Start_NetworkHandler();
+
+  // this is a simple command interpreter which reads from serial port 0
+  // it is used to set a static IP address
+  while (1)
+    {
+
+    }
+}
+
+/* implement missing functions rand and srand */
+int _EXFUN(rand,(_VOID))
+{
+  return nextXorShiftUInt32();
+}
+
+_VOID   _EXFUN(srand,(unsigned __seed))
+{
+  setXorShiftSeed(__seed);
+}
+
+
+
+//*****************************************************************************
+//
+// The interrupt handler for the SysTick interrupt.
+// Entry here directly from the interrupt vector
+// This interrupt occurs once every 10 milliseconds
+//*****************************************************************************
+void SysTickIntHandler(void) {
+
+  //
+  // Update internal time and set PPS output, if needed.
+  //
+  g_ulSystemTimeNanoSeconds += SYSTICKNS;
+
+  //
+  // Call the lwIP timer handler.
+  //
+  lwIPTimer(SYSTICKMS);
+}
+

+ 194 - 0
source/src/ports/LM3S8962/sample_application/opener_user_conf.h

@@ -0,0 +1,194 @@
+/*******************************************************************************
+ * Copyright (c) 2009, Rockwell Automation, Inc.
+ * All rights reserved. 
+ *
+ ******************************************************************************/
+#ifndef OPENER_USER_CONF_H_
+#define OPENER_USER_CONF_H_
+
+/*! \file
+ * \brief OpENer configuration setup
+ * 
+ * This file contains the general application specific configuration for OpENer.
+ * 
+ * Furthermore you have to specific platform specific network include files.
+ * OpENer needs definitions for the following data-types
+ * and functions:
+ *    - struct sockaddr_in
+ *    - AF_INET
+ *    - INADDR_ANY
+ *    - htons
+ *    - ntohl
+ *    - inet_addr
+ */
+
+
+#include "lwiplib.h"
+#include "archnw.h"
+
+/* members are in network byte order */
+struct sockaddr_in {
+  u8_t sin_len;
+  u8_t sin_family;
+  u16_t sin_port;
+  struct in_addr sin_addr;
+  char sin_zero[8];
+};
+
+struct sockaddr {
+  u8_t sa_len;
+  u8_t sa_family;
+  char sa_data[14];
+};
+
+#ifndef socklen_t
+#define socklen_t u32_t
+#endif
+
+
+#define SOCK_STREAM     1
+#define  SOL_SOCKET  0xfff    /* options for socket level */
+#define  SO_BROADCAST   0x0020 /* Unimplemented: permit sending of broadcast msgs */
+
+/*! Identity configuration of the device */
+#define OPENER_DEVICE_VENDOR_ID           1
+#define OPENER_DEVICE_TYPE               43
+#define OPENER_DEVICE_PRODUCT_CODE      0x01
+#define OPENER_DEVICE_MAJOR_REVISION      1
+#define OPENER_DEVICE_MINOR_REVISION      2
+#define OPENER_DEVICE_NAME      "OpENer Energy"
+
+/*! Define the number of objects that may be used in connections
+ *
+ *  This number needs only to consider additional objects. Connections to
+ *  the connection manager object as well as to the assembly object are supported
+ *  in any case.
+ */
+#define OPENER_CIP_NUM_APPLICATION_SPECIFIC_CONNECTABLE_OBJECTS 1
+
+/*! Define the number of supported explicit connections.
+ *  According to ODVA's PUB 70 this number should be greater than 6.
+ */  
+#define OPENER_CIP_NUM_EXPLICIT_CONNS 6
+
+/*! Define the number of supported exclusive owner connections.
+ *  Each of these connections has to be configured with the function
+ *  void configureExclusiveOwnerConnectionPoint(unsigned int pa_unConnNum, unsigned int pa_unOutputAssembly, unsigned int pa_unInputAssembly, unsigned int pa_unConfigAssembly)
+ *
+ */
+#define OPENER_CIP_NUM_EXLUSIVE_OWNER_CONNS 1
+
+/*! Define the number of supported input only connections.
+ *  Each of these connections has to be configured with the function
+ *  void configureInputOnlyConnectionPoint(unsigned int pa_unConnNum, unsigned int pa_unOutputAssembly, unsigned int pa_unInputAssembly, unsigned int pa_unConfigAssembly)
+ *
+ */
+#define OPENER_CIP_NUM_INPUT_ONLY_CONNS 1
+
+/*! Define the number of supported input only connections per connection path
+ */
+#define OPENER_CIP_NUM_INPUT_ONLY_CONNS_PER_CON_PATH 1
+
+
+/*! Define the number of supported listen only connections.
+ *  Each of these connections has to be configured with the function
+ *  void configureListenOnlyConnectionPoint(unsigned int pa_unConnNum, unsigned int pa_unOutputAssembly, unsigned int pa_unInputAssembly, unsigned int pa_unConfigAssembly)
+ *
+ */
+#define OPENER_CIP_NUM_LISTEN_ONLY_CONNS 1
+
+/*! Define the number of supported Listen only connections per connection path
+ */
+#define OPENER_CIP_NUM_LISTEN_ONLY_CONNS_PER_CON_PATH   1
+
+
+/*! The number of bytes used for the buffer that will be used for generating any
+ *  reply data of messages. There are two uses in OpENer:
+ *    1. Explicit messages will use this buffer to store the data generated by the request
+ *    2. I/O Connections will use this buffer for the produced data
+ */ 
+#define OPENER_MESSAGE_DATA_REPLY_BUFFER 250
+
+/*! Number of sessions that can be handled at the same time
+ */ 
+#define OPENER_NUMBER_OF_SUPPORTED_SESSIONS 4
+
+/*! The time in ms of the timer used in this implementations
+ */ 
+#define OPENER_TIMER_TICK 10 
+
+
+/*! Define if RUN IDLE data is sent with consumed data
+ */ 
+#define OPENER_CONSUMED_DATA_HAS_RUN_IDLE_HEADER 1
+
+/*! Define if RUN IDLE data is to be sent with produced data
+ *
+ * Per default we don't send run idle headers with produced data
+ */
+#define OPENER_PRODUCED_DATA_HAS_RUN_IDLE_HEADER 0
+
+#ifdef OPENER_WITH_TRACES
+/* If we have tracing enabled provide print tracing macro */
+#include <stdio.h>
+
+#define LOG_TRACE(args...)  fprintf(stderr,args)
+
+/*#define PRINT_TRACE(args...)  fprintf(stderr,args);*/
+
+
+/*! A specialized assertion command that will log the assertion and block
+ *  further execution in an while(1) loop.
+ */
+#define OPENER_ASSERT(assertion) \
+    do { \
+      if(!(assertion)) { \
+        LOG_TRACE("Assertion \"%s\" failed: file \"%s\", line %d\n", #assertion, __FILE__, __LINE__); \
+        while(1){;} \
+      } \
+    } while(0)
+
+/* else use standard assert() */
+//#include <assert.h>
+//#include <stdio.h>
+//#define OPENER_ASSERT(assertion) assert(assertion)
+
+#else
+
+/* for release builds execute the assertion, but don't test it */
+#define OPENER_ASSERT(assertion) assertion
+
+/* the above may result in "statement with no effect" warnings.
+ *  If you do not use assert()s to run functions, the an empty
+ *  macro can be used as below
+ */
+//#define OPENER_ASSERT(assertion)
+
+/* else if you still want assertions to stop execution but without tracing, use the following */
+//#define OPENER_ASSERT(assertion) do { if(!(assertion)) { while(1){;} } } while (0)
+
+/* else use standard assert() */
+//#include <assert.h>
+//#include <stdio.h>
+//#define OPENER_ASSERT(assertion) assert(assertion)
+
+
+#endif
+
+/*! The number of bytes used for the Ethernet message buffer on
+ * the pc port. For different platforms it may makes sense to 
+ * have more than one buffer.
+ *
+ *  This buffer size will be used for any received message.
+ *  The same buffer is used for the replied explicit message.
+ */ 
+#define PC_OPENER_ETHERNET_BUFFER_SIZE 512
+
+
+/*! If this define is here opener will enable 64Bit data type support.
+ *
+ */
+#define OPENER_SUPPORT_64BIT_DATATYPES 1
+
+
+#endif /*OPENER_USER_CONF_H_*/

+ 80 - 0
source/src/ports/LM3S8962/stubs.c

@@ -0,0 +1,80 @@
+/*******************************************************************************
+ * Copyright (c) 2009, Rockwell Automation, Inc.
+ * All rights reserved. 
+ *
+ ******************************************************************************/
+
+#include <string.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <assert.h>
+#include <trace.h>
+
+int __errno(void)
+  {
+    return 0;
+  }
+
+void raise(void)
+  {
+    while (1)
+      ;
+  }
+
+void abort(void)
+  {
+    while (1)
+      ;
+  }
+
+void BUG(char *s)
+  {
+    while (1)
+      ;
+  }
+
+static char dumpbuf[256];
+
+void __assert_func(const char *__file, int __line, const char *__function,
+    const char *__assertion)
+  {
+    snprintf(dumpbuf, 100,
+        "assert(%s) failed in function %s, file %s, at line %d\n", __assertion,
+        __function, __file, __line);
+
+    OPENER_TRACE_ERR(dumpbuf);
+    while (1)
+      ;
+  }
+
+void dump(unsigned char *p, int size)
+  {
+    int i;
+    char *b;
+
+    while (size>0)
+      {
+        b = dumpbuf;
+        for (i=0; i<16; i++)
+          {
+            if (i<size)
+              b += sprintf(b, "%02x ", p[i]);
+            else
+              b += sprintf(b, "   ");
+          }
+        b += sprintf(b, " |");
+        for (i=0; i<16; i++)
+          {
+            if (i<size)
+              {
+                if (' '<=p[i]&&p[i]<0x7f)
+                  b += sprintf(b, "%c", p[i]);
+                else
+                  b += sprintf(b, ".");
+              }
+          }
+        p += 16;
+        size -= 16;
+        OPENER_TRACE_INFO("%s\n", dumpbuf);
+      }
+  }

+ 0 - 0
src/ports/POSIX/CMakeLists.txt → source/src/ports/POSIX/CMakeLists.txt


+ 0 - 0
src/ports/POSIX/main.c → source/src/ports/POSIX/main.c


+ 0 - 0
src/ports/POSIX/networkhandler.c → source/src/ports/POSIX/networkhandler.c


+ 0 - 0
src/ports/POSIX/networkhandler.h → source/src/ports/POSIX/networkhandler.h


+ 0 - 0
src/ports/POSIX/sample_application/CMakeLists.txt → source/src/ports/POSIX/sample_application/CMakeLists.txt


+ 0 - 0
src/ports/POSIX/sample_application/opener_user_conf.h → source/src/ports/POSIX/sample_application/opener_user_conf.h


+ 0 - 0
src/ports/POSIX/sample_application/sampleapplication.c → source/src/ports/POSIX/sample_application/sampleapplication.c


+ 0 - 0
src/ports/WIN32/CMakeLists.txt → source/src/ports/WIN32/CMakeLists.txt


+ 0 - 0
src/ports/WIN32/main.c → source/src/ports/WIN32/main.c


+ 0 - 0
src/ports/WIN32/networkhandler.c → source/src/ports/WIN32/networkhandler.c


+ 0 - 0
src/ports/WIN32/networkhandler.h → source/src/ports/WIN32/networkhandler.h


+ 0 - 0
src/ports/WIN32/sample_application/CMakeLists.txt → source/src/ports/WIN32/sample_application/CMakeLists.txt


+ 0 - 0
src/ports/WIN32/sample_application/opener_user_conf.h → source/src/ports/WIN32/sample_application/opener_user_conf.h


+ 0 - 0
src/ports/WIN32/sample_application/sampleapplication.c → source/src/ports/WIN32/sample_application/sampleapplication.c


+ 0 - 0
src/trace.h → source/src/trace.h


+ 0 - 0
src/typedefs.h → source/src/typedefs.h


+ 7 - 0
source/src/utils/CMakeLists.txt

@@ -0,0 +1,7 @@
+
+opener_common_includes()
+opener_platform_spec()
+
+set( UTILS_SRC random.c xorshiftrandom.c)
+
+add_library( Utils ${UTILS_SRC} )

+ 15 - 0
source/src/utils/random.c

@@ -0,0 +1,15 @@
+/*
+ * random.cpp
+ *
+ *  Created on: Dec 16, 2013
+ *      Author: mmm
+ */
+
+#include "random.h"
+
+Random* random_new(setSeedfn pa_fnpSetSeed, getNextUInt32fn pa_fnGetNextUInt32)
+{
+	Random* out = malloc(sizeof(Random));
+	*out = (Random){.setSeed = pa_fnpSetSeed, .getNextUInt32 = pa_fnGetNextUInt32};
+	return out;
+}

+ 25 - 0
source/src/utils/random.h

@@ -0,0 +1,25 @@
+/*
+ * random.h
+ *
+ *  Created on: Dec 1, 2013
+ *      Author: mmm
+ */
+
+#ifndef RANDOM_H_
+#define RANDOM_H_
+
+#include <stdint.h>
+
+typedef void (*setSeedfn)(uint32_t pa_nSeed);
+typedef uint32_t (*getNextUInt32fn)(void);
+
+typedef struct
+{
+	uint32_t nXorShiftSeed; /**< Holds the current seed/random value */
+	setSeedfn setSeed; /**< Function pointer to setSeed function */
+	getNextUInt32fn getNextUInt32; /**< Function pointer to getNextUInt32 function */
+} Random;
+
+Random* random_new(setSeedfn, getNextUInt32fn);
+
+#endif /* RANDOM_H_ */

+ 32 - 0
source/src/utils/xorshiftrandom.c

@@ -0,0 +1,32 @@
+/*
+ * xorshiftrandom.c
+ *
+ *  Created on: Nov 28, 2013
+ *      Author: mmm
+ */
+
+#include "xorshiftrandom.h"
+
+static uint32_t nXorShiftSeed; /*! < File-global variable holding the current seed*/
+
+void setXorShiftSeed(uint32_t pa_nSeed)
+{
+	nXorShiftSeed = pa_nSeed;
+}
+
+/*!
+ * The algorithm used to create the pseudo-random numbers.
+ * Works directly on the file global variable
+ */
+void calculateNextSeed(void)
+{
+	nXorShiftSeed ^= nXorShiftSeed << 13;
+	nXorShiftSeed ^= nXorShiftSeed >> 17;
+	nXorShiftSeed ^= nXorShiftSeed << 5;
+}
+
+uint32_t nextXorShiftUInt32(void)
+{
+	calculateNextSeed();
+	return nXorShiftSeed;
+}

+ 30 - 0
source/src/utils/xorshiftrandom.h

@@ -0,0 +1,30 @@
+/*
+ * xorshiftrandom.h
+ *
+ *  Created on: Dec 1, 2013
+ *      Author: mmm
+ */
+
+/*!
+ * \file xorshiftrandom.h
+ *
+ * The public interface of the XOR shift pseudo-random number generator
+ */
+#include <stdint.h>
+
+#ifndef XORSHIFTRANDOM_H_
+#define XORSHIFTRANDOM_H_
+
+/*!
+ * Sets the initial seed for the XOR shift pseudo-random algorithm
+ * \param pa_nSeed The initial seed value
+ */
+void setXorShiftSeed(uint32_t pa_nSeed);
+
+/*!
+ * Returns the next generated pseudo-random number
+ * \return The next pseudo-random number
+ */
+uint32_t nextXorShiftUInt32(void);
+
+#endif /* XORSHIFTRANDOM_H_ */

+ 27 - 0
source/tests/CMakeLists.txt

@@ -0,0 +1,27 @@
+#######################################
+# Add test subdirectories             #
+#######################################
+
+#######################################
+# Add test includes                   #
+#######################################
+add_test_includes()
+
+
+###################################################
+# Copy custom test output file to binary location #
+###################################################
+configure_file( CTestCustom.cmake ${PROJECT_BINARY_DIR}/CTestCustom.cmake )
+
+add_subdirectory( utils )
+add_executable( OpENer_Tests OpENerTests.cpp )
+
+set( CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} ${CPPUTEST_HOME}/lib )
+
+target_link_libraries( OpENer_Tests CppUTest CppUTestExt )
+target_link_libraries( OpENer_Tests UtilsTest Utils )
+
+########################################
+# Adds test to CTest environment       #
+########################################
+add_test(OpENer_Tests ${EXECUTABLE_OUTPUT_PATH}/OpENer_Tests)

+ 1 - 0
source/tests/CTestCustom.cmake

@@ -0,0 +1 @@
+set( CTEST_CUSTOM_POST_TEST ${CTEST_CUSTOM_POST_TEST} "cat Testing/Temporary/LastTest.log" )

+ 1 - 3
src/tests/main.cpp → source/tests/OpENerTests.cpp

@@ -1,6 +1,4 @@
-#include "CppUTest/CommandLineTestRunner.h"
-
-IMPORT_TEST_GROUP(MTRandomTests);
+#include "OpENerTests.h"
 
 int main(int argc, char** argv)
 {

+ 4 - 0
source/tests/OpENerTests.h

@@ -0,0 +1,4 @@
+#include "CppUTest/CommandLineTestRunner.h"
+
+IMPORT_TEST_GROUP(RandomClass);
+IMPORT_TEST_GROUP(XorShiftRandom);

+ 8 - 0
source/tests/utils/CMakeLists.txt

@@ -0,0 +1,8 @@
+
+opener_common_includes()
+
+set( UtilsTestSrc randomTests.cpp xorshiftrandomtests.cpp)
+
+include_directories( ${SRC_DIR}/utils )
+
+add_library( UtilsTest ${UtilsTestSrc} )

+ 28 - 0
source/tests/utils/randomTests.cpp

@@ -0,0 +1,28 @@
+/*
+ * randomTests.cpp
+ *
+ *  Created on: Dec 16, 2013
+ *      Author: mmm
+ */
+
+#include <CppUTest/TestHarness.h>
+#include <stdint.h>
+
+extern "C"  {
+#include <random.h>
+#include <xorshiftrandom.h>
+}
+
+TEST_GROUP(RandomClass)
+{
+
+};
+
+TEST(RandomClass, CreateXOrShiftObject)
+{
+	Random* pRandom;
+	uint32_t nResult = 0;
+	pRandom = random_new(setXorShiftSeed, nextXorShiftUInt32);
+	POINTERS_EQUAL(setXorShiftSeed, pRandom->setSeed);
+	POINTERS_EQUAL(nextXorShiftUInt32, pRandom->getNextUInt32);
+}

+ 43 - 0
source/tests/utils/xorshiftrandomtests.cpp

@@ -0,0 +1,43 @@
+/*
+ * xorshiftrandomtests.c
+ *
+ *  Created on: Dec 1, 2013
+ *      Author: mmm
+ */
+
+#include <CppUTest/TestHarness.h>
+#include <stdint.h>
+
+extern "C"  {
+#include <xorshiftrandom.h>
+}
+
+TEST_GROUP(XorShiftRandom)
+{
+
+};
+
+/*This test should always return 0 as the next random number (see XorShift algorithm*/
+TEST(XorShiftRandom, SeedZeroInitResult)
+{
+	uint32_t nResult;
+	nResult = 1;
+	setXorShiftSeed(0);
+	nResult = nextXorShiftUInt32();
+	LONGS_EQUAL(0, nResult);
+}
+
+/*Characterization test*/
+TEST(XorShiftRandom, SeedOneCharacterization)
+{
+	uint32_t nResult;
+	setXorShiftSeed(1);
+	nResult = nextXorShiftUInt32();
+	LONGS_EQUAL(270369, nResult);
+	nResult = nextXorShiftUInt32();
+	LONGS_EQUAL(67634689, nResult);
+	nResult = nextXorShiftUInt32();
+	LONGS_EQUAL(2647435461, nResult);
+	nResult = nextXorShiftUInt32();
+	LONGS_EQUAL(307599695, nResult);
+}

+ 0 - 12
src/tests/CMakeLists.txt

@@ -1,12 +0,0 @@
-#######################################
-# Add test subdirectories             #
-#######################################
-
-add_test_includes()
-
-add_subdirectory( utils )
-add_executable( OpENer_Tests main.cpp )
-
-set( CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} ${CPPUTEST_HOME}/lib )
-
-target_link_libraries( OpENer_Tests CppUTest CppUTestExt UtilsTest )

+ 0 - 3
src/tests/utils/CMakeLists.txt

@@ -1,3 +0,0 @@
-set( UtilsTestSrc MTRandomTests.cpp )
-
-add_library( UtilsTest ${UtilsTestSrc} )

+ 0 - 11
src/tests/utils/MTRandomTests.cpp

@@ -1,11 +0,0 @@
-#include <CppUTest/TestHarness.h>
-
-TEST_GROUP(MTRandomTests)
-{
-};
-
-TEST(MTRandomTests, SeedTest)
-{
-  FAIL("Fail me!");
-}
-