+f=.
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\section{Exceptions for IEC 61499 Elements}
+
+\subsection{Naming of IEC 61499 Objects}
+
+All identifiers corresponding to IEC 61499 objecets (ressources) should be named as defined
+in the IEC 61499 Standard. So they are execepted from the rules in sections 3 to 6. This has two advantages:
+\begin{itemize}
+\item No parsing/substitution of names in the code files is needed
+\item It helps to differentiate between "runtime-code" and "user-code"
+\end{itemize}
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\section{Performance and Size Considerations}
+
+
+
+\subsection{Function Inlining}
+Our experience showed that functions shorter than 4 to 3 line should be inlined. This nearly always reduces the size of FORTE and therefore should increase its performance. However your mileage may vary. So please use it wisely and make tests and measurements
+
+
+\subsection{Local Static Variables}
+Local static variables can be rather helpful for implementing certain features. However be warned that they may have side effects. First of all modern C++ compilers will add code from \verb=libsupc++.a= which will protect them against multi threaded access. Depending on other features you use from the standard C++ library this can result in several kilobytes of binary image size increase. The compiler flag \verb=-fno-threadsafe-statics= can help here. But be warned that you may run in trouble with this flag.
+
+Currently FORTE is using just one local static variable, namely in the singleton pattern. For these it is safe to use the \verb=-fno-threadsafe-statics= flag. And because of other optimizations done to remove the standard lib parts this will significantly reduce your image size.
+
+Summarizing this short excursus better think twice before using a local static variable. FORTE will try to avoid them and future version will very likely not use them any more and so should you.
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\appendix
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\section{Examples}
+\subsection{File Header} \label{subsec:FileHeader}
+
+\begin{lstlisting}[frame=trbl]{}
+/*******************************************************************************
+ * Copyright (c) 2007 4DIAC - consortium.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************
+#ifndef _FILENAME_H_
+#define _FILENAME_H_
+
+//! short class description
+/*! long class description
+ */
+class CFooSpace {
+ public:
+ //! short description
+ int foo(void); /*!< long description
+ */
+ protected:
+ //! short description
+ void bar(void); /*!> long description
+ */
+ private:
+ //! short member var description
+ int m_nIsBar; /*!> long description
+ */
+};
+
+#endif
+\end{lstlisting}
+
+\newpage
+\subsection{Indention and Blocks} \label{subsec:IndentionAndBlocks}
+\begin{lstlisting}[frame=trbl]{}
+int CFooSpace::foo(void){
+ if(m_nIsBar){
+ bar();
+ return 1;
+ }
+ else {
+ megaBar();
+ }
+
+ if(!m_nIsBar){
+ notBar();
+ }
+
+ return 0;
+}
+\end{lstlisting}
+
+\end{document}
\ No newline at end of file
diff --git a/doc/coding_rules/src/forte_coding_rules.tps b/doc/coding_rules/src/forte_coding_rules.tps
new file mode 100644
index 000000000..a598f95b6
--- /dev/null
+++ b/doc/coding_rules/src/forte_coding_rules.tps
@@ -0,0 +1,38 @@
+[FormatInfo]
+Type=TeXnicCenterProjectSessionInformation
+Version=2
+
+[SessionInfo]
+ActiveTab=0
+FrameCount=1
+ActiveFrame=0
+
+[Frame0]
+Columns=1
+Rows=1
+Flags=2
+ShowCmd=3
+MinPos.x=-1
+MinPos.y=-1
+MaxPos.x=-4
+MaxPos.y=-23
+NormalPos.left=22
+NormalPos.top=25
+NormalPos.right=849
+NormalPos.bottom=513
+Class=CLatexEdit
+Document=forte_coding_rules.tex
+
+[Frame0_Row0]
+cyCur=609
+cyMin=10
+
+[Frame0_Col0]
+cxCur=1300
+cxMin=10
+
+[Frame0_View0,0]
+Cursor.row=95
+Cursor.column=11
+TopSubLine=90
+
diff --git a/epl-v10.html b/epl-v10.html
new file mode 100644
index 000000000..3998fcebe
--- /dev/null
+++ b/epl-v10.html
@@ -0,0 +1,261 @@
+
+
+
+
+
+
+Eclipse Public License - Version 1.0
+
+
+
+
+
+
+Eclipse Public License - v 1.0
+
+THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE
+PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR
+DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS
+AGREEMENT.
+
+1. DEFINITIONS
+
+"Contribution" means:
+
+a) in the case of the initial Contributor, the initial
+code and documentation distributed under this Agreement, and
+b) in the case of each subsequent Contributor:
+i) changes to the Program, and
+ii) additions to the Program;
+where such changes and/or additions to the Program
+originate from and are distributed by that particular Contributor. A
+Contribution 'originates' from a Contributor if it was added to the
+Program by such Contributor itself or anyone acting on such
+Contributor's behalf. Contributions do not include additions to the
+Program which: (i) are separate modules of software distributed in
+conjunction with the Program under their own license agreement, and (ii)
+are not derivative works of the Program.
+
+"Contributor" means any person or entity that distributes
+the Program.
+
+"Licensed Patents" mean patent claims licensable by a
+Contributor which are necessarily infringed by the use or sale of its
+Contribution alone or when combined with the Program.
+
+"Program" means the Contributions distributed in accordance
+with this Agreement.
+
+"Recipient" means anyone who receives the Program under
+this Agreement, including all Contributors.
+
+2. GRANT OF RIGHTS
+
+a) Subject to the terms of this Agreement, each
+Contributor hereby grants Recipient a non-exclusive, worldwide,
+royalty-free copyright license to reproduce, prepare derivative works
+of, publicly display, publicly perform, distribute and sublicense the
+Contribution of such Contributor, if any, and such derivative works, in
+source code and object code form.
+
+b) Subject to the terms of this Agreement, each
+Contributor hereby grants Recipient a non-exclusive, worldwide,
+royalty-free patent license under Licensed Patents to make, use, sell,
+offer to sell, import and otherwise transfer the Contribution of such
+Contributor, if any, in source code and object code form. This patent
+license shall apply to the combination of the Contribution and the
+Program if, at the time the Contribution is added by the Contributor,
+such addition of the Contribution causes such combination to be covered
+by the Licensed Patents. The patent license shall not apply to any other
+combinations which include the Contribution. No hardware per se is
+licensed hereunder.
+
+c) Recipient understands that although each Contributor
+grants the licenses to its Contributions set forth herein, no assurances
+are provided by any Contributor that the Program does not infringe the
+patent or other intellectual property rights of any other entity. Each
+Contributor disclaims any liability to Recipient for claims brought by
+any other entity based on infringement of intellectual property rights
+or otherwise. As a condition to exercising the rights and licenses
+granted hereunder, each Recipient hereby assumes sole responsibility to
+secure any other intellectual property rights needed, if any. For
+example, if a third party patent license is required to allow Recipient
+to distribute the Program, it is Recipient's responsibility to acquire
+that license before distributing the Program.
+
+d) Each Contributor represents that to its knowledge it
+has sufficient copyright rights in its Contribution, if any, to grant
+the copyright license set forth in this Agreement.
+
+3. REQUIREMENTS
+
+A Contributor may choose to distribute the Program in object code
+form under its own license agreement, provided that:
+
+a) it complies with the terms and conditions of this
+Agreement; and
+
+b) its license agreement:
+
+i) effectively disclaims on behalf of all Contributors
+all warranties and conditions, express and implied, including warranties
+or conditions of title and non-infringement, and implied warranties or
+conditions of merchantability and fitness for a particular purpose;
+
+ii) effectively excludes on behalf of all Contributors
+all liability for damages, including direct, indirect, special,
+incidental and consequential damages, such as lost profits;
+
+iii) states that any provisions which differ from this
+Agreement are offered by that Contributor alone and not by any other
+party; and
+
+iv) states that source code for the Program is available
+from such Contributor, and informs licensees how to obtain it in a
+reasonable manner on or through a medium customarily used for software
+exchange.
+
+When the Program is made available in source code form:
+
+a) it must be made available under this Agreement; and
+
+b) a copy of this Agreement must be included with each
+copy of the Program.
+
+Contributors may not remove or alter any copyright notices contained
+within the Program.
+
+Each Contributor must identify itself as the originator of its
+Contribution, if any, in a manner that reasonably allows subsequent
+Recipients to identify the originator of the Contribution.
+
+4. COMMERCIAL DISTRIBUTION
+
+Commercial distributors of software may accept certain
+responsibilities with respect to end users, business partners and the
+like. While this license is intended to facilitate the commercial use of
+the Program, the Contributor who includes the Program in a commercial
+product offering should do so in a manner which does not create
+potential liability for other Contributors. Therefore, if a Contributor
+includes the Program in a commercial product offering, such Contributor
+("Commercial Contributor") hereby agrees to defend and
+indemnify every other Contributor ("Indemnified Contributor")
+against any losses, damages and costs (collectively "Losses")
+arising from claims, lawsuits and other legal actions brought by a third
+party against the Indemnified Contributor to the extent caused by the
+acts or omissions of such Commercial Contributor in connection with its
+distribution of the Program in a commercial product offering. The
+obligations in this section do not apply to any claims or Losses
+relating to any actual or alleged intellectual property infringement. In
+order to qualify, an Indemnified Contributor must: a) promptly notify
+the Commercial Contributor in writing of such claim, and b) allow the
+Commercial Contributor to control, and cooperate with the Commercial
+Contributor in, the defense and any related settlement negotiations. The
+Indemnified Contributor may participate in any such claim at its own
+expense.
+
+For example, a Contributor might include the Program in a commercial
+product offering, Product X. That Contributor is then a Commercial
+Contributor. If that Commercial Contributor then makes performance
+claims, or offers warranties related to Product X, those performance
+claims and warranties are such Commercial Contributor's responsibility
+alone. Under this section, the Commercial Contributor would have to
+defend claims against the other Contributors related to those
+performance claims and warranties, and if a court requires any other
+Contributor to pay any damages as a result, the Commercial Contributor
+must pay those damages.
+
+5. NO WARRANTY
+
+EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS
+PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
+OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION,
+ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY
+OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely
+responsible for determining the appropriateness of using and
+distributing the Program and assumes all risks associated with its
+exercise of rights under this Agreement , including but not limited to
+the risks and costs of program errors, compliance with applicable laws,
+damage to or loss of data, programs or equipment, and unavailability or
+interruption of operations.
+
+6. DISCLAIMER OF LIABILITY
+
+EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT
+NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING
+WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR
+DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
+HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+
+7. GENERAL
+
+If any provision of this Agreement is invalid or unenforceable under
+applicable law, it shall not affect the validity or enforceability of
+the remainder of the terms of this Agreement, and without further action
+by the parties hereto, such provision shall be reformed to the minimum
+extent necessary to make such provision valid and enforceable.
+
+If Recipient institutes patent litigation against any entity
+(including a cross-claim or counterclaim in a lawsuit) alleging that the
+Program itself (excluding combinations of the Program with other
+software or hardware) infringes such Recipient's patent(s), then such
+Recipient's rights granted under Section 2(b) shall terminate as of the
+date such litigation is filed.
+
+All Recipient's rights under this Agreement shall terminate if it
+fails to comply with any of the material terms or conditions of this
+Agreement and does not cure such failure in a reasonable period of time
+after becoming aware of such noncompliance. If all Recipient's rights
+under this Agreement terminate, Recipient agrees to cease use and
+distribution of the Program as soon as reasonably practicable. However,
+Recipient's obligations under this Agreement and any licenses granted by
+Recipient relating to the Program shall continue and survive.
+
+Everyone is permitted to copy and distribute copies of this
+Agreement, but in order to avoid inconsistency the Agreement is
+copyrighted and may only be modified in the following manner. The
+Agreement Steward reserves the right to publish new versions (including
+revisions) of this Agreement from time to time. No one other than the
+Agreement Steward has the right to modify this Agreement. The Eclipse
+Foundation is the initial Agreement Steward. The Eclipse Foundation may
+assign the responsibility to serve as the Agreement Steward to a
+suitable separate entity. Each new version of the Agreement will be
+given a distinguishing version number. The Program (including
+Contributions) may always be distributed subject to the version of the
+Agreement under which it was received. In addition, after a new version
+of the Agreement is published, Contributor may elect to distribute the
+Program (including its Contributions) under the new version. Except as
+expressly stated in Sections 2(a) and 2(b) above, Recipient receives no
+rights or licenses to the intellectual property of any Contributor under
+this Agreement, whether expressly, by implication, estoppel or
+otherwise. All rights in the Program not expressly granted under this
+Agreement are reserved.
+
+This Agreement is governed by the laws of the State of New York and
+the intellectual property laws of the United States of America. No party
+to this Agreement will bring a legal action under this Agreement more
+than one year after the cause of action arose. Each party waives its
+rights to a jury trial in any resulting litigation.
+
+
+
+
\ No newline at end of file
diff --git a/forte_config.h.in b/forte_config.h.in
new file mode 100644
index 000000000..43eb31cd2
--- /dev/null
+++ b/forte_config.h.in
@@ -0,0 +1,92 @@
+/*******************************************************************************
+ * Copyright (c) 2005 - 2014 ACIN, Profactor GmbH, fortiss GmbH
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl, Martin Melik Merkumians, Ingo Hegny, Michael Hofmann
+ * - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#ifndef _CONFIG_H_
+#define _CONFIG_H_
+
+#undef IN
+#undef OUT
+
+
+#include
+
+/*!Define the number of times the CTimerHandler will be called per second.
+ *
+ * FORTE will use this information to calculate time values.
+ */
+const TForteUInt32 cg_nForteTicksPerSecond = ${FORTE_TicksPerSecond};
+
+/*! \brief Defines the time base in units per second that will be used in the TIME data type
+ *
+ * The default value will be 1 000 000 000, which means that the time bas is 1 ns.
+ * For Smaller devices which do not use 64 bit datatypes a time base of 1000 (i.e., 1ms)
+ * or 1000000 (i.e., 1micro s) may be suitable.
+ */
+#define FORTE_TIME_BASE_UNITS_PER_SECOND ${FORTE_TimeBaseUnitsPerSecond}
+
+
+/*! Define the initial size of the event chain list used in the event chain execution thread.
+ *
+ */
+const unsigned int cg_nEventChainEventListSize = ${FORTE_EventChainEventListSize};
+
+
+/*! Define the initial size of the event chain's external event list.
+ */
+const unsigned int cg_nEventChainExternalEventListSize = ${FORTE_EventChainExternalEventListSize};
+
+
+/*! Defines the number of pending communication messages can be handled by a communication function block
+ *
+ */
+const unsigned int cg_unCommunicationInterruptQueueSize = ${FORTE_CommunicationInterruptQueueSize};
+
+
+/*! Buffer size in bytes to be used by the ip layer as receive buffer.
+ *
+ */
+const unsigned int cg_unIPLayerRecvBufferSize = ${FORTE_IPLayerRecvBufferSize};
+
+/*! \brief Define the management encapsulation protocol
+ *
+ * Currently two protocols are supported:
+ * # DEV_MGR for FBDK compliant XML encoded commands
+ * # WBXML_DEV_MGR for WAP Binary XML encoded commands
+ */
+#define FORTE_MGM_COMMAND_PROTOCOL ${FORTE_MGMCOMMANDPROTOCOL}
+
+//! Max supported hierarchy that can be provided in a management commands
+#define FORTE_MGM_MAX_SUPPORTED_NAME_HIERARCHY ${FORTE_MGM_MAX_SUPPOERTED_NAME_HIERACHY}
+
+/*! \brief FORTE string dict's initial string buffer size
+ *
+ * Depending on the FORTE_STRING_DICT_FIXED_MEMORY flag the string dict will reallocate if necessary.
+ */
+const TForteUInt32 cg_unStringDictInitialStringBufSize = ${FORTE_STRINGDICTINITIALSTRINGBUFSIZE};
+
+/*! \brief FORTE string dict's initial max nr of strings
+ *
+ * Depending on the FORTE_STRING_DICT_FIXED_MEMORY flag the string dict will reallocate if necessary.
+ */
+const TForteUInt32 cg_unStringDictInitialMaxNrOfStrings = ${FORTE_STRINGDICTINITIALMAXNROFSTRINGS};
+
+
+#ifdef FORTE_SUPPORT_BOOT_FILE
+
+/*!Define the path to the Bootfile
+ */
+#define FORTE_BOOT_FILE_LOCATION "${FORTE_BootfileLocation}forte.fboot"
+
+const unsigned int cg_unBootFileLineBufSize = ${FORTE_BOOTFILELINEBUFSIZE};
+
+#endif
+
+#endif
diff --git a/fortestyle.xml b/fortestyle.xml
new file mode 100644
index 000000000..892ca4d38
--- /dev/null
+++ b/fortestyle.xml
@@ -0,0 +1,166 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/notice.html b/notice.html
new file mode 100644
index 000000000..c3d34c3c2
--- /dev/null
+++ b/notice.html
@@ -0,0 +1,107 @@
+
+
+
+
+
+Eclipse Foundation Software User Agreement
+
+
+
+Eclipse Foundation Software User Agreement
+April 9, 2014
+
+Usage Of Content
+
+THE ECLIPSE FOUNDATION MAKES AVAILABLE SOFTWARE, DOCUMENTATION, INFORMATION AND/OR OTHER MATERIALS FOR OPEN SOURCE PROJECTS
+ (COLLECTIVELY "CONTENT"). USE OF THE CONTENT IS GOVERNED BY THE TERMS AND CONDITIONS OF THIS AGREEMENT AND/OR THE TERMS AND
+ CONDITIONS OF LICENSE AGREEMENTS OR NOTICES INDICATED OR REFERENCED BELOW. BY USING THE CONTENT, YOU AGREE THAT YOUR USE
+ OF THE CONTENT IS GOVERNED BY THIS AGREEMENT AND/OR THE TERMS AND CONDITIONS OF ANY APPLICABLE LICENSE AGREEMENTS OR
+ NOTICES INDICATED OR REFERENCED BELOW. IF YOU DO NOT AGREE TO THE TERMS AND CONDITIONS OF THIS AGREEMENT AND THE TERMS AND
+ CONDITIONS OF ANY APPLICABLE LICENSE AGREEMENTS OR NOTICES INDICATED OR REFERENCED BELOW, THEN YOU MAY NOT USE THE CONTENT.
+
+Applicable Licenses
+
+Unless otherwise indicated, all Content made available by the Eclipse Foundation is provided to you under the terms and conditions of the Eclipse Public License Version 1.0
+ ("EPL"). A copy of the EPL is provided with this Content and is also available at http://www.eclipse.org/legal/epl-v10.html.
+ For purposes of the EPL, "Program" will mean the Content.
+
+Content includes, but is not limited to, source code, object code, documentation and other files maintained in the Eclipse Foundation source code
+ repository ("Repository") in software modules ("Modules") and made available as downloadable archives ("Downloads").
+
+
+ - Content may be structured and packaged into modules to facilitate delivering, extending, and upgrading the Content. Typical modules may include plug-ins ("Plug-ins"), plug-in fragments ("Fragments"), and features ("Features").
+ - Each Plug-in or Fragment may be packaged as a sub-directory or JAR (Java™ ARchive) in a directory named "plugins".
+ - A Feature is a bundle of one or more Plug-ins and/or Fragments and associated material. Each Feature may be packaged as a sub-directory in a directory named "features". Within a Feature, files named "feature.xml" may contain a list of the names and version numbers of the Plug-ins
+ and/or Fragments associated with that Feature.
+ - Features may also include other Features ("Included Features"). Within a Feature, files named "feature.xml" may contain a list of the names and version numbers of Included Features.
+
+
+The terms and conditions governing Plug-ins and Fragments should be contained in files named "about.html" ("Abouts"). The terms and conditions governing Features and
+Included Features should be contained in files named "license.html" ("Feature Licenses"). Abouts and Feature Licenses may be located in any directory of a Download or Module
+including, but not limited to the following locations:
+
+
+ - The top-level (root) directory
+ - Plug-in and Fragment directories
+ - Inside Plug-ins and Fragments packaged as JARs
+ - Sub-directories of the directory named "src" of certain Plug-ins
+ - Feature directories
+
+
+Note: if a Feature made available by the Eclipse Foundation is installed using the Provisioning Technology (as defined below), you must agree to a license ("Feature Update License") during the
+installation process. If the Feature contains Included Features, the Feature Update License should either provide you with the terms and conditions governing the Included Features or
+inform you where you can locate them. Feature Update Licenses may be found in the "license" property of files named "feature.properties" found within a Feature.
+Such Abouts, Feature Licenses, and Feature Update Licenses contain the terms and conditions (or references to such terms and conditions) that govern your use of the associated Content in
+that directory.
+
+THE ABOUTS, FEATURE LICENSES, AND FEATURE UPDATE LICENSES MAY REFER TO THE EPL OR OTHER LICENSE AGREEMENTS, NOTICES OR TERMS AND CONDITIONS. SOME OF THESE
+OTHER LICENSE AGREEMENTS MAY INCLUDE (BUT ARE NOT LIMITED TO):
+
+
+
+IT IS YOUR OBLIGATION TO READ AND ACCEPT ALL SUCH TERMS AND CONDITIONS PRIOR TO USE OF THE CONTENT. If no About, Feature License, or Feature Update License is provided, please
+contact the Eclipse Foundation to determine what terms and conditions govern that particular Content.
+
+
+Use of Provisioning Technology
+
+The Eclipse Foundation makes available provisioning software, examples of which include, but are not limited to, p2 and the Eclipse
+ Update Manager ("Provisioning Technology") for the purpose of allowing users to install software, documentation, information and/or
+ other materials (collectively "Installable Software"). This capability is provided with the intent of allowing such users to
+ install, extend and update Eclipse-based products. Information about packaging Installable Software is available at http://eclipse.org/equinox/p2/repository_packaging.html
+ ("Specification").
+
+You may use Provisioning Technology to allow other parties to install Installable Software. You shall be responsible for enabling the
+ applicable license agreements relating to the Installable Software to be presented to, and accepted by, the users of the Provisioning Technology
+ in accordance with the Specification. By using Provisioning Technology in such a manner and making it available in accordance with the
+ Specification, you further acknowledge your agreement to, and the acquisition of all necessary rights to permit the following:
+
+
+ - A series of actions may occur ("Provisioning Process") in which a user may execute the Provisioning Technology
+ on a machine ("Target Machine") with the intent of installing, extending or updating the functionality of an Eclipse-based
+ product.
+ - During the Provisioning Process, the Provisioning Technology may cause third party Installable Software or a portion thereof to be
+ accessed and copied to the Target Machine.
+ - Pursuant to the Specification, you will provide to the user the terms and conditions that govern the use of the Installable
+ Software ("Installable Software Agreement") and such Installable Software Agreement shall be accessed from the Target
+ Machine in accordance with the Specification. Such Installable Software Agreement must inform the user of the terms and conditions that govern
+ the Installable Software and must solicit acceptance by the end user in the manner prescribed in such Installable Software Agreement. Upon such
+ indication of agreement by the user, the provisioning Technology will complete installation of the Installable Software.
+
+
+Cryptography
+
+Content may contain encryption software. The country in which you are currently may have restrictions on the import, possession, and use, and/or re-export to
+ another country, of encryption software. BEFORE using any encryption software, please check the country's laws, regulations and policies concerning the import,
+ possession, or use, and re-export of encryption software, to see if this is permitted.
+
+Java and all Java-based trademarks are trademarks of Oracle Corporation in the United States, other countries, or both.
+
+
diff --git a/setup_digime74.sh b/setup_digime74.sh
new file mode 100644
index 000000000..ee59e0515
--- /dev/null
+++ b/setup_digime74.sh
@@ -0,0 +1,6 @@
+#!/bin/sh
+echo "----------------------------------------------------------------------------"
+echo "BUILD-SYSTEM was switched from automake to cmake"
+echo "----------------------------------------------------------------------------"
+echo ""
+echo "run cmake or cmake-gui to set up development environment"
\ No newline at end of file
diff --git a/setup_phycoreat91.sh b/setup_phycoreat91.sh
new file mode 100644
index 000000000..ee59e0515
--- /dev/null
+++ b/setup_phycoreat91.sh
@@ -0,0 +1,6 @@
+#!/bin/sh
+echo "----------------------------------------------------------------------------"
+echo "BUILD-SYSTEM was switched from automake to cmake"
+echo "----------------------------------------------------------------------------"
+echo ""
+echo "run cmake or cmake-gui to set up development environment"
\ No newline at end of file
diff --git a/setup_posix-ppc.sh b/setup_posix-ppc.sh
new file mode 100644
index 000000000..189fd1d8c
--- /dev/null
+++ b/setup_posix-ppc.sh
@@ -0,0 +1,7 @@
+#!/bin/bash
+#!/bin/bash
+echo "----------------------------------------------------------------------------"
+echo "BUILD-SYSTEM was switched from automake to cmake"
+echo "----------------------------------------------------------------------------"
+echo ""
+echo "run cmake or cmake-gui to set up development environment"
\ No newline at end of file
diff --git a/setup_posix.sh b/setup_posix.sh
new file mode 100644
index 000000000..22cdf43d5
--- /dev/null
+++ b/setup_posix.sh
@@ -0,0 +1,38 @@
+#!/bin/bash
+echo "----------------------------------------------------------------------------"
+echo " Automatically set up development environment for POSIX-platform"
+echo "----------------------------------------------------------------------------"
+echo ""
+echo " Includes 64bit-datatypes, float-datatypes, Ethernet-Interface,"
+echo " ASN1-encoding, ..."
+echo ""
+echo " To include tests set directories for boost-test-framework and "
+echo " set FORTE_TESTS-option to 'ON'"
+echo ""
+echo "----------------------------------------------------------------------------"
+
+export forte_bin_dir="bin/posix"
+
+#set to boost-include directory
+export forte_boost_test_inc_dirs=""
+#set to boost-library directory
+export forte_boost_test_lib_dirs=""
+
+if [ ! -d "$forte_bin_dir" ]; then
+ mkdir -p "$forte_bin_dir"
+fi
+
+if [ -d "$forte_bin_dir" ]; then
+
+ echo "For building forte go to $forte_bin_dir and execute \"make\""
+ echo "forte can be found at ${forte_bin_dir}/src"
+ echo "forte_tests can be found at ${forte_bin_dir}/tests"
+
+
+ cd "./$forte_bin_dir"
+
+ cmake -G "Unix Makefiles" -DFORTE_ARCHITECTURE=Posix -DFORTE_COM_ETH=ON -DFORTE_COM_FBDK=ON -DFORTE_COM_LOCAL=ON -DFORTE_TESTS=OFF -DFORTE_TESTS_INC_DIRS=${forte_boost_test_inc_dirs} -DFORTE_TESTS_LINK_DIRS=${forte_boost_test_inc_dirs} -DFORTE_MODULE_CONVERT=ON -DFORTE_MODULE_MATH=ON -DFORTE_MODULE_IEC61131=ON -DFORTE_MODULE_OSCAT=ON -DFORTE_MODULE_Test=ON -DFORTE_MODULE_UTILS=ON ../../
+else
+ echo "unable to create ${forte_bin_dir}"
+ exit 1
+fi
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
new file mode 100644
index 000000000..01f21d2fc
--- /dev/null
+++ b/src/CMakeLists.txt
@@ -0,0 +1,283 @@
+#*******************************************************************************
+# * Copyright (c) 2010 - 2014 Profactor GmbH, ACIN, nxtControl GmbH, fortiss GmbH
+# * All rights reserved. This program and the accompanying materials
+# * are made available under the terms of the Eclipse Public License v1.0
+# * which accompanies this distribution, and is available at
+# * http://www.eclipse.org/legal/epl-v10.html
+# *
+# * Contributors:
+# * Micheal Hofmann, Alois Zoitl, Stanislav Meduna, Gerhard Ebenhofer,
+# * Matthias Plasch
+# * - initial API and implementation and/or initial documentation
+# *******************************************************************************/
+
+
+forte_create_modules_file(${CMAKE_CURRENT_SOURCE_DIR}/modules/)
+forte_add_subdirectory(arch)
+forte_add_subdirectory(core)
+forte_add_subdirectory(modules)
+forte_add_subdirectory(stdfblib)
+
+SET(SOURCE_GROUP core)
+forte_add_sourcefile_with_path_hcpp(${FORTE_BINARY_DIR}/stringlist)
+set_source_files_properties(${FORTE_BINARY_DIR}/stringlist.h PROPERTIES GENERATED TRUE)
+set_source_files_properties(${FORTE_BINARY_DIR}/stringlist.cpp PROPERTIES GENERATED TRUE)
+
+
+if(${FORTE_BUILD_TYPE} STREQUAL STATIC_LIBRARY OR ${FORTE_BUILD_TYPE} STREQUAL SHARED_LIBRARY)
+ forte_add_sourcefile_with_path_hcpp(${FORTE_BINARY_DIR}/forteinit)
+ set_source_files_properties(${FORTE_BINARY_DIR}/forteinit.h PROPERTIES GENERATED TRUE)
+ set_source_files_properties(${FORTE_BINARY_DIR}/forteinit.cpp PROPERTIES GENERATED TRUE)
+ENDIF(${FORTE_BUILD_TYPE} STREQUAL STATIC_LIBRARY OR ${FORTE_BUILD_TYPE} STREQUAL SHARED_LIBRARY)
+
+#######################################################################################
+# Define global Include-directorys
+#######################################################################################
+GET_PROPERTY(INCLUDE_DIRECTORIES GLOBAL PROPERTY FORTE_INCLUDE_DIRECTORIES)
+LIST(LENGTH INCLUDE_DIRECTORIES len)
+IF(len GREATER 0)
+ LIST(REMOVE_DUPLICATES INCLUDE_DIRECTORIES)
+ LIST(REVERSE INCLUDE_DIRECTORIES) # bugfix, for replaced include files
+ENDIF(len GREATER 0)
+INCLUDE_DIRECTORIES(${INCLUDE_DIRECTORIES})
+INCLUDE_DIRECTORIES(./)
+INCLUDE_DIRECTORIES(${FORTE_BINARY_DIR})
+INCLUDE_DIRECTORIES(${FORTE_BINARY_DIR}/src_gen)
+#######################################################################################
+# Define directories for Libraries
+#######################################################################################
+GET_PROPERTY(LINK_DIRECTORIES GLOBAL PROPERTY FORTE_LINK_DIRECTORIES)
+LIST(LENGTH LINK_DIRECTORIES len)
+IF(len GREATER 0)
+ LIST(REMOVE_DUPLICATES LINK_DIRECTORIES)
+ENDIF(len GREATER 0)
+LINK_DIRECTORIES(${LINK_DIRECTORIES})
+
+#######################################################################################
+# Define directories for Libraries
+#######################################################################################
+GET_PROPERTY(DEFINITION GLOBAL PROPERTY FORTE_DEFINITION)
+ADD_DEFINITIONS (${DEFINITION})
+
+#######################################################################################
+# Exclude FBs
+#######################################################################################
+set(FORTE_EXCLUDE_FBS "" CACHE STRING "Exclude Function blocks")
+mark_as_advanced(FORTE_EXCLUDE_FBS)
+
+IF(FORTE_EXCLUDE_FBS)
+ STRING(REGEX MATCHALL "[^ ,;][^ ,;]*" FBLIST ${FORTE_EXCLUDE_FBS})
+
+ FOREACH(FB ${FBLIST})
+ forte_remove_sourcefile_h(${FB}.h)
+ forte_remove_sourcefile_cpp(${FB}.cpp)
+ ENDFOREACH(FB)
+ENDIF(FORTE_EXCLUDE_FBS)
+
+GET_PROPERTY(PLATFORM_REMOVES GLOBAL PROPERTY FORTE_PLATFORM_REMOVES)
+FOREACH(FB ${PLATFORM_REMOVES})
+ forte_remove_sourcefile_h(${FB}.h)
+ forte_remove_sourcefile_cpp(${FB}.cpp)
+ENDFOREACH(FB)
+
+#######################################################################################
+# Setup Forte-Executeable with all Functionblocks
+#######################################################################################
+
+GET_PROPERTY(SOURCE_H GLOBAL PROPERTY FORTE_SOURCE_H)
+GET_PROPERTY(SOURCE_H_GROUP GLOBAL PROPERTY FORTE_SOURCE_H_GROUP)
+LIST(APPEND SOURCE_FILES ${SOURCE_H})
+LIST(APPEND SOURCE_FILES_GROUP ${SOURCE_H_GROUP})
+
+GET_PROPERTY(SOURCE_CPP GLOBAL PROPERTY FORTE_SOURCE_CPP)
+GET_PROPERTY(SOURCE_CPP_GROUP_STRUCT GLOBAL PROPERTY FORTE_SOURCE_CPP_GROUP)
+LIST(APPEND SOURCE_FILES ${SOURCE_CPP})
+LIST(APPEND SOURCE_FILES_GROUP ${SOURCE_CPP_GROUP_STRUCT})
+
+GET_PROPERTY(SOURCE_C GLOBAL PROPERTY FORTE_SOURCE_C)
+GET_PROPERTY(SOURCE_C_GROUP_STRUCT GLOBAL PROPERTY FORTE_SOURCE_C_GROUP)
+LIST(APPEND SOURCE_FILES ${SOURCE_C})
+LIST(APPEND SOURCE_FILES_GROUP ${SOURCE_C_GROUP_STRUCT})
+
+#FOREACH(FILE ${SOURCE_H})
+ # Do not pars stringlist, as these files will be generated
+# STRING(REGEX MATCH ".*stringlist\\.(cpp|h).*" REGEX_STRINGS ${FBLIB_FILE})
+# IF(NOT REGEX_STRINGS)
+# ENDIF(NOT REGEX_STRINGS)
+#ENDFOREACH(FILE)
+
+#############################################################################
+# Configure Network Layers
+#############################################################################
+
+GET_PROPERTY(LAYER_CLASS GLOBAL PROPERTY FORTE_LAYER_CLASS)
+GET_PROPERTY(LAYER_CONFIGNAME GLOBAL PROPERTY FORTE_LAYER_CONFIGNAME)
+GET_PROPERTY(LAYER_FILENAME GLOBAL PROPERTY FORTE_LAYER_FILENAME)
+LIST(LENGTH LAYER_CLASS LAYER_CLASS_LEN)
+math(EXPR LAYER_CLASS_LEN ${LAYER_CLASS_LEN}-1)
+
+SET(LAYERMANAGER_INCLUDE "")
+SET(LAYERMANAGER_INSTANCE "if(false){}")
+
+FOREACH(POS RANGE ${LAYER_CLASS_LEN}-1)
+ LIST(GET LAYER_CLASS ${POS} CLASS)
+ LIST(GET LAYER_CONFIGNAME ${POS} CONFIGNAME)
+ LIST(GET LAYER_FILENAME ${POS} FILENAME)
+ SET(LAYERMANAGER_INCLUDE "${LAYERMANAGER_INCLUDE}#include<${FILENAME}>\n")
+ SET(LAYERMANAGER_INSTANCE "${LAYERMANAGER_INSTANCE}\nelse if(0 == strcmp(\"${CONFIGNAME}\", pa_acLayerIdentifier)){\nm_poNewLayer = new ${CLASS}(pa_poUpperLayer, pa_poComFB);\n}\n")
+ENDFOREACH(POS)
+
+CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/core/cominfra/comlayersmanager.cpp.in ${CMAKE_BINARY_DIR}/core/cominfra/comlayersmanager_new.cpp)
+forte_replacefile_if_changed(${CMAKE_BINARY_DIR}/core/cominfra/comlayersmanager_new.cpp ${CMAKE_BINARY_DIR}/core/cominfra/comlayersmanager.cpp)
+file(REMOVE ${CMAKE_BINARY_DIR}/core/cominfra/comlayersmanager_new.cpp)
+
+#############################################################################
+# Load FORTE Extension Files
+#############################################################################
+
+GET_PROPERTY(EXTENSION_FILES GLOBAL PROPERTY FORTE_EXTENSION_FILES)
+LIST(LENGTH EXTENSION_FILES len)
+IF(len GREATER 0)
+ LIST(REMOVE_DUPLICATES EXTENSION_FILES)
+ FOREACH(FILE ${EXTENSION_FILES})
+ INCLUDE("${FILE}")
+ ENDFOREACH(FILE)
+ENDIF(len GREATER 0)
+
+#############################################################################
+# Add Files to source-group
+#############################################################################
+LIST(LENGTH SOURCE_FILES SOURCE_LEN)
+LIST(LENGTH SOURCE_FILES_GROUP SOURCE_GROUP_LEN)
+math(EXPR SOURCE_LEN ${SOURCE_LEN}-1)
+math(EXPR SOURCE_GROUP_LEN ${SOURCE_GROUP_LEN}-1)
+
+FOREACH(POS RANGE ${SOURCE_LEN}-1)
+ LIST(GET SOURCE_FILES ${POS} FILE)
+ LIST(GET SOURCE_FILES_GROUP ${POS} GROUP)
+ source_group(${GROUP} FILES ${FILE})
+ENDFOREACH(POS)
+
+# remove duplicate entries
+LIST(LENGTH SOURCE_FILES len)
+IF(len GREATER 0)
+ LIST(REMOVE_DUPLICATES SOURCE_FILES)
+ENDIF(len GREATER 0)
+
+SET(WRITE_FILE "")
+FOREACH(FILE ${SOURCE_FILES})
+ SET(WRITE_FILE "${WRITE_FILE}${FILE}\n")
+ENDFOREACH(FILE)
+FILE(WRITE ${CMAKE_BINARY_DIR}/file_list.txt "${WRITE_FILE}")
+
+######################################################################################
+# Architecutre to build forte on
+######################################################################################
+set(FORTE_ARCHITECTURE "None" CACHE STRING "Architecture to build FORTE on")
+GET_PROPERTY(architectures GLOBAL PROPERTY FORTE_ARCHITECTURES)
+list(SORT architectures)
+set_property(CACHE FORTE_ARCHITECTURE PROPERTY STRINGS None ${architectures})
+
+
+#######################################################################################
+# Create Exe File
+#######################################################################################
+#ADD_EXECUTABLE (forte ${SOURCE_CPP} ${SOURCE_H})
+
+#######################################################################################
+# Create Files
+#######################################################################################
+if(${FORTE_BUILD_TYPE} STREQUAL EXECUTABLE)
+ADD_EXECUTABLE (forte ${SOURCE_CPP} ${SOURCE_C} ${SOURCE_H})
+ENDIF(${FORTE_BUILD_TYPE} STREQUAL EXECUTABLE)
+
+if(${FORTE_BUILD_TYPE} STREQUAL STATIC_LIBRARY)
+ADD_LIBRARY (forte STATIC ${SOURCE_CPP} ${SOURCE_C} ${SOURCE_H})
+forte_add_definition("-DFORTE_STATIC_LIB")
+ADD_DEFINITIONS(-DFORTE_STATIC_LIB)
+ENDIF(${FORTE_BUILD_TYPE} STREQUAL STATIC_LIBRARY)
+
+if(${FORTE_BUILD_TYPE} STREQUAL SHARED_LIBRARY)
+ADD_LIBRARY (forte SHARED ${SOURCE_CPP} ${SOURCE_C} ${SOURCE_H} )
+forte_add_definition("-DFORTE_STATIC_LIB")
+forte_add_definition("-DFORTE_SHARED_LIB")
+ADD_DEFINITIONS(-DFORTE_STATIC_LIB)
+ADD_DEFINITIONS(-DFORTE_SHARED_LIB)
+ENDIF(${FORTE_BUILD_TYPE} STREQUAL SHARED_LIBRARY)
+
+if("${FORTE_ARCHITECTURE}" STREQUAL "Win32")
+ ADD_DEFINITIONS (-D_CRT_SECURE_NO_DEPRECATE)
+ ADD_DEFINITIONS (-D_CRT_NONSTDC_NO_DEPRECATE)
+ ADD_DEFINITIONS (-D_SCL_SECURE_NO_WARNINGS)
+ ADD_DEFINITIONS (-D_CRT_SECURE_NO_WARNINGS)
+endif()
+
+get_target_property(existing_link_flags forte LINK_FLAGS)
+if(existing_link_flags)
+ set_property(GLOBAL APPEND PROPERTY FORTE_LINK_FLAGS ${existing_link_flags})
+endif()
+
+GET_PROPERTY(link_flags GLOBAL PROPERTY FORTE_LINK_FLAGS)
+
+set_target_properties(forte PROPERTIES LINK_FLAGS "${link_flags}")
+
+install(TARGETS forte RUNTIME DESTINATION bin)
+
+#######################################################################################
+# Link Libraries to the Executeable
+#######################################################################################
+# get Linker-Direcotries from Modules
+get_property(LINK_LIBRARY GLOBAL PROPERTY FORTE_LINK_LIBRARY)
+TARGET_LINK_LIBRARIES (forte ${LINK_LIBRARY} )
+
+#######################################################################################
+# Generate stringlist and modules
+#######################################################################################
+
+if(${FORTE_BUILD_TYPE} STREQUAL STATIC_LIBRARY OR ${FORTE_BUILD_TYPE} STREQUAL SHARED_LIBRARY) #No reason to do this if we're building an executable...
+ Message("lib")
+ ADD_CUSTOM_TARGET(forte_init_generator COMMAND ${CMAKE_COMMAND} -DFORTE_STATIC_LIB:STRING="TRUE" -DFORTE_BINARY_DIR:STRING="${CMAKE_BINARY_DIR}" -DFORTE_SOURCE_DIR:STRING="${CMAKE_SOURCE_DIR}" -DFORTE_USE_64BIT_DATATYPES:STRING="${FORTE_USE_64BIT_DATATYPES}" -DFORTE_USE_REAL_DATATYPE:STRING="${FORTE_USE_REAL_DATATYPE}" -DFORTE_USE_LREAL_DATATYPE:STRING="${FORTE_USE_LREAL_DATATYPE}" -DFORTE_SUPPORT_ARRAYS:STRING="${FORTE_SUPPORT_ARRAYS}" -DFORTE_LITTLE_ENDIAN:STRING=${FORTE_LITTLE_ENDIAN} -DFORTE_BIG_ENDIAN:STRING=${FORTE_BIG_ENDIAN} -DFORTE_LOGLEVEL:STRING="${FORTE_LOGLEVEL}" -P ${FORTE_BUILDSUPPORT_DIRECTORY}/generate_init.cmake) #
+ ADD_DEPENDENCIES (forte forte_init_generator)
+ ADD_DEPENDENCIES (forte_init_generator forte_generate_modules_cmake_files)
+endif(${FORTE_BUILD_TYPE} STREQUAL STATIC_LIBRARY OR ${FORTE_BUILD_TYPE} STREQUAL SHARED_LIBRARY)
+
+ADD_CUSTOM_TARGET(forte_generate_modules_cmake_files COMMAND ${CMAKE_COMMAND} -DFORTE_MODULE_DIR:STRING=${CMAKE_CURRENT_SOURCE_DIR}/modules/ -P ${FORTE_BUILDSUPPORT_DIRECTORY}/generate_modules_cmake_file.cmake)
+ADD_DEPENDENCIES (forte forte_generate_modules_cmake_files)
+ADD_CUSTOM_TARGET(forte_stringlist_generator COMMAND ${CMAKE_COMMAND} -DFORTE_LINKED_STRINGDICT:STRING="${FORTE_LINKED_STRINGDICT}" -DFORTE_BINARY_DIR:STRING="${CMAKE_BINARY_DIR}" -DFORTE_SOURCE_DIR:STRING="${CMAKE_CURRENT_SOURCE_DIR}" -P ${FORTE_BUILDSUPPORT_DIRECTORY}/generate_stringlist.cmake)
+ADD_DEPENDENCIES (forte forte_stringlist_generator)
+ADD_DEPENDENCIES (forte_stringlist_generator forte_generate_modules_cmake_files)
+
+#######################################################################################
+# Generate stringlist for every source file
+#######################################################################################
+if(FORTE_LINKED_STRINGDICT)
+ set(ENABLE_GENERATED_SOURCE_CPP ON)
+ ADD_DEPENDENCIES (forte forte_stringlist_externals)
+endif(FORTE_LINKED_STRINGDICT)
+
+#######################################################################################
+# Enable autogenerated source files
+#######################################################################################
+if(ENABLE_GENERATED_SOURCE_CPP)
+ ADD_DEFINITIONS ("-DFORTE_ENABLE_GENERATED_SOURCE_CPP")
+endif(ENABLE_GENERATED_SOURCE_CPP)
+
+
+#######################################################################################
+# Link everything together
+#######################################################################################
+# link libraries to executeable
+GET_PROPERTY(LINK_LIBRARY GLOBAL PROPERTY MODULE_LINK_LIBRARY)
+TARGET_LINK_LIBRARIES (forte ${LINK_LIBRARY} )
+
+
+#######################################################################################
+# Add post build commands
+#######################################################################################
+GET_PROPERTY(POST_BUILD_COM GLOBAL PROPERTY FORTE_POST_BUILD_COMMAND)
+STRING(LENGTH "${POST_BUILD_COM}" LEN_POST_BUILD_COM)
+if(NOT LEN_POST_BUILD_COM EQUAL 0)
+ ADD_CUSTOM_COMMAND(TARGET forte POST_BUILD ${POST_BUILD_COM})
+endif(NOT LEN_POST_BUILD_COM EQUAL 0)
+
+
diff --git a/src/arch/CMakeLists.txt b/src/arch/CMakeLists.txt
new file mode 100644
index 000000000..dc918ec52
--- /dev/null
+++ b/src/arch/CMakeLists.txt
@@ -0,0 +1,22 @@
+#*******************************************************************************
+# * Copyright (c) 2010 - 2012 ACIN
+# * All rights reserved. This program and the accompanying materials
+# * are made available under the terms of the Eclipse Public License v1.0
+# * which accompanies this distribution, and is available at
+# * http://www.eclipse.org/legal/epl-v10.html
+# *
+# * Contributors:
+# * Alois Zoitl, Patrick Smejkal
+# * - initial API and implementation and/or initial documentation
+# *******************************************************************************/
+forte_add_include_directories(${CMAKE_CURRENT_SOURCE_DIR})
+SET(SOURCE_GROUP ${SOURCE_GROUP}\\arch)
+
+add_subdirectory(ecos)
+add_subdirectory(netos)
+add_subdirectory(posix)
+add_subdirectory(win32)
+add_subdirectory(be_m1)
+
+forte_add_sourcefile_hcpp(timerha devlog)
+
diff --git a/src/arch/be_m1/BE_RMT_DEV.cpp b/src/arch/be_m1/BE_RMT_DEV.cpp
new file mode 100644
index 000000000..3b95f9a5a
--- /dev/null
+++ b/src/arch/be_m1/BE_RMT_DEV.cpp
@@ -0,0 +1,21 @@
+/*******************************************************************************
+ * Copyright (c) 2011 ACIN
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#include "BE_RMT_DEV.h"
+
+BE_RMT_DEV::BE_RMT_DEV(CFORTEModule &pa_roModule) :
+ RMT_DEV(), m_roModule(pa_roModule){
+
+}
+
+BE_RMT_DEV::~BE_RMT_DEV(){
+
+}
+
diff --git a/src/arch/be_m1/BE_RMT_DEV.h b/src/arch/be_m1/BE_RMT_DEV.h
new file mode 100644
index 000000000..f0da9568d
--- /dev/null
+++ b/src/arch/be_m1/BE_RMT_DEV.h
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * Copyright (c) 2011 ACIN
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#ifndef BE_RMT_DEV_H_
+#define BE_RMT_DEV_H_
+
+#include "../../../stdfblib/ita/RMT_DEV.h"
+#include
+
+class BE_RMT_DEV : public RMT_DEV{
+ public:
+ BE_RMT_DEV(CFORTEModule &pa_roModule);
+
+ virtual ~BE_RMT_DEV();
+
+ CFORTEModule & getModule() const{
+ return m_roModule;
+ }
+ protected:
+ private:
+ CFORTEModule & m_roModule;
+};
+
+#endif /* BE_RMT_DEV_H_ */
diff --git a/src/arch/be_m1/BE_SVIFB.cpp b/src/arch/be_m1/BE_SVIFB.cpp
new file mode 100644
index 000000000..9034b2025
--- /dev/null
+++ b/src/arch/be_m1/BE_SVIFB.cpp
@@ -0,0 +1,84 @@
+/*******************************************************************************
+ * Copyright (c) 2011 ACIN
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#include "BE_SVIFB.h"
+#include "BE_RMT_DEV.h"
+
+const TForteUInt32 BE_SVIFB::scm_anBE_SVI_Types[] = { SVI_F_UNKNOWN, // e_ANY,
+ SVI_F_BOOL8, // e_BOOL,
+ SVI_F_SINT8, // e_SINT,
+ SVI_F_SINT16, // e_INT,
+ SVI_F_SINT32, // e_DINT,
+ SVI_F_SINT64, // e_LINT,
+ SVI_F_UINT8, // e_USINT,
+ SVI_F_UINT16, // e_UINT,
+ SVI_F_UINT32, // e_UDINT,
+ SVI_F_UINT64, // e_ULINT,
+ SVI_F_UINT8, // e_BYTE,
+ SVI_F_UINT16, // e_WORD,
+ SVI_F_UINT32, // e_DWORD,
+ SVI_F_UINT64, // e_LWORD,
+ SVI_F_SINT64, // e_DATE,
+ SVI_F_SINT64, // e_TIME_OF_DAY,
+ SVI_F_SINT64, // e_DATE_AND_TIME,
+ SVI_F_SINT64, // e_TIME, //until here simple Datatypes
+ SVI_F_REAL32, // e_REAL,
+ SVI_F_REAL64, // e_LREAL,
+ SVI_F_STRINGLSTBASE, // e_STRING,
+ SVI_F_STRINGLSTBASE, // e_WSTRING,
+ SVI_F_UNKNOWN, // e_DerivedData,
+ SVI_F_UNKNOWN, // e_DirectlyDerivedData,
+ SVI_F_UNKNOWN, // e_EnumeratedData,
+ SVI_F_UNKNOWN, // e_SubrangeData,
+ SVI_F_UNKNOWN, // e_ARRAY, //according to the compliance profile
+ SVI_F_UNKNOWN // e_STRUCT,
+ // e_External = 256, // Base for CIEC_ANY based types outside of the forte base
+ // e_Max = 65535 // Guarantees at least 16 bits - otherwise gcc will optimizes on some platforms
+ };
+
+const TForteUInt32 BE_SVIFB::scm_anBE_SVI_VarSizes[] = { 0, // e_ANY,
+ 1, // e_BOOL,
+ 1, // e_SINT,
+ 2, // e_INT,
+ 4, // e_DINT,
+ 8, // e_LINT,
+ 1, // e_USINT,
+ 2, // e_UINT,
+ 4, // e_UDINT,
+ 8, // e_ULINT,
+ 1, // e_BYTE,
+ 2, // e_WORD,
+ 4, // e_DWORD,
+ 8, // e_LWORD,
+ 8, // e_DATE,
+ 8, // e_TIME_OF_DAY,
+ 8, // e_DATE_AND_TIME,
+ 8, // e_TIME, //until here simple Datatypes
+ 4, // e_REAL,
+ 8, // e_LREAL,
+ 4, // e_STRING,
+ 4, // e_WSTRING,
+ 0, // e_DerivedData,
+ 0, // e_DirectlyDerivedData,
+ 0, // e_EnumeratedData,
+ 0, // e_SubrangeData,
+ 0, // e_ARRAY, //according to the compliance profile
+ 0 // e_STRUCT,
+ // e_External = 256, // Base for CIEC_ANY based types outside of the forte base
+ // e_Max = 65535 // Guarantees at least 16 bits - otherwise gcc will optimizes on some platforms
+ };
+
+bool BE_SVIFB::registerSVIvar(const CIEC_STRING& pa_roID, CIEC_ANY& pa_roValue, const TForteUInt32 pa_nMode){
+ BE_RMT_DEV& roDev(static_cast(getResource().getDevice()));
+
+ bool bRetVal = (OK == roDev.getModule().GetSVIHandler().AddGlobVar(((CHAR *) pa_roID.getValue()), pa_nMode | scm_anBE_SVI_Types[pa_roValue.getDataTypeID()], scm_anBE_SVI_VarSizes[pa_roValue.getDataTypeID()], (UINT32*) (pa_roValue.getDataPtr()), 0, 0));
+ roDev.getModule().CfgRead();
+ return bRetVal;
+}
diff --git a/src/arch/be_m1/BE_SVIFB.h b/src/arch/be_m1/BE_SVIFB.h
new file mode 100644
index 000000000..425f8589e
--- /dev/null
+++ b/src/arch/be_m1/BE_SVIFB.h
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2011 ACIN
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#ifndef BE_SVIFB_H_
+#define BE_SVIFB_H_
+
+#include
+#include "funcbloc.h"
+
+class BE_SVIFB : public CFunctionBlock{
+ public:
+ BE_SVIFB(CResource *pa_poSrcRes, const SFBInterfaceSpec *pa_pstInterfaceSpec, const CStringDictionary::TStringId pa_nInstanceNameId, TForteByte *pa_acFBConnData, TForteByte *pa_acFBVarsData) :
+ CFunctionBlock(pa_poSrcRes, pa_pstInterfaceSpec, pa_nInstanceNameId, pa_acFBConnData, pa_acFBVarsData){
+ }
+
+ protected:
+ bool registerSVIvar(const CIEC_STRING& pa_roID, CIEC_ANY& pa_roValue, const TForteUInt32 pa_nMode);
+
+ private:
+ static const TForteUInt32 scm_anBE_SVI_Types[];
+ static const TForteUInt32 scm_anBE_SVI_VarSizes[];
+
+};
+
+#endif /* BE_SVIFB_H_ */
diff --git a/src/arch/be_m1/CMakeLists.txt b/src/arch/be_m1/CMakeLists.txt
new file mode 100644
index 000000000..dbe39c377
--- /dev/null
+++ b/src/arch/be_m1/CMakeLists.txt
@@ -0,0 +1,94 @@
+#*******************************************************************************
+# * Copyright (c) 2012 - 2105 ACIN and fortiss GmbH
+# * All rights reserved. This program and the accompanying materials
+# * are made available under the terms of the Eclipse Public License v1.0
+# * which accompanies this distribution, and is available at
+# * http://www.eclipse.org/legal/epl-v10.html
+# *
+# * Contributors:
+# * Alois Zoitl - initial API and implementation and/or initial documentation
+# *******************************************************************************/
+
+SET(SOURCE_GROUP ${SOURCE_GROUP}\\be_m1)
+
+forte_add_architecture("Bachmann M1")
+
+if("${FORTE_ARCHITECTURE}" STREQUAL "Bachmann M1")
+
+
+ forte_add_include_directories(${CMAKE_CURRENT_SOURCE_DIR})
+
+ forte_add_sourcefile_hcpp(thread vxworkstimeha sync)
+ forte_add_sourcefile_hcpp(fortemodule)
+
+ forte_add_sourcefile_h(stdint.h)
+
+ forte_add_sourcefile_hcpp(GET_CHAN_INFO)
+ forte_add_sourcefile_hcpp(GET_VALUE)
+ forte_add_sourcefile_hcpp(SET_VALUE)
+ forte_add_sourcefile_hcpp(BE_SVIFB SVIsend_1 SVIreceive_1 BE_RMT_DEV)
+
+
+ if(FORTE_COM_ETH)
+ forte_add_sourcefile_hcpp( ../fdselecthand ../bsdsocketinterf)
+ forte_add_sourcefile_h(../gensockhand.h)
+ forte_add_sourcefile_h(sockhand.h)
+ endif(FORTE_COM_ETH)
+
+ forte_add_include_directories(../${CMAKE_CURRENT_SOURCE_DIR})
+ forte_add_include_directories(${CMAKE_CURRENT_SOURCE_DIR})
+
+ forte_add_definition("-W -Wall -Wextra -Woverloaded-virtual -Wconversion -DFORTE_LITTLE_ENDIAN -DVXWORKS -O0 -ggdb")
+ forte_add_definition("-fno-rtti")
+
+ forte_add_link_flags("-Wl,-M -Wl,-Map -Wl,forte.map -Wl,-cref")
+
+ CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/forte.ver.in ${CMAKE_BINARY_DIR}/forte.new.ver)
+ forte_replacefile_if_changed(${CMAKE_BINARY_DIR}/forte.new.ver ${CMAKE_BINARY_DIR}/forte.ver)
+ CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/CPPLIB.ver.in ${CMAKE_BINARY_DIR}/CPPLIB.new.ver)
+ forte_replacefile_if_changed(${CMAKE_BINARY_DIR}/CPPLIB.new.ver ${CMAKE_BINARY_DIR}/CPPLIB.ver)
+
+
+ set(GNU_TOOLS C:/bachmann/SolutionCenter/V1.70Release/cutils/GnuTools)
+ set(MSYS_PATH C:/bachmann/SolutionCenter/V1.70Release/cutils/mcsdk/msys)
+ set(GNU_TOOLS_PATH ${GNU_TOOLS}/../GnuTools-4.1.2)
+ set(MSYS_UTILS_PATH ${MSYS_PATH}/utl)
+
+# Base directory of the compiler installation
+ set(GCC_BASE ${GNU_TOOLS_PATH})
+ set(CPU_FAMILY I80X86)
+
+# Some settings need to be overwritten
+ set(GCC_BIN_DIR ${GCC_BASE}/bin)
+ set(BINUTILS_BIN_DIR ${GCC_BASE}/bin)
+ set(GCC_EXEC_PREFIX ${GCC_BASE}/lib/gcc/i386-wrs-vxworks/4.1.2/)
+ set(COMPILER_LIB_PATHS -L "${GCC_EXEC_PREFIX}" -L "${GCC_BASE}/i386-wrs-vxworks/lib")
+ set(BASE_LIB_PATH -L "${GNU_TOOLS_PATH}/lib")
+ set(M1_LD_PATH ${BASE_LIB_PATH} ${COMPILER_LIB_PATHS})
+
+# Names of compiler frontends and linkers have changed
+ set(M1_CC "${GCC_BIN_DIR}/i386-wrs-vxworks-gcc")
+ set(M1_CPP "${GCC_BIN_DIR}/i386-wrs-vxworks-g++")
+ set(M1_LD "${BINUTILS_BIN_DIR}/i386-wrs-vxworks-ld")
+ set(M1_AR "${BINUTILS_BIN_DIR}/i386-wrs-vxworks-ar")
+ set(M1_NM "${BINUTILS_BIN_DIR}/i386-wrs-vxworks-nm")
+ set(M1_MUNCH "${MSYS_UTILS_PATH}/munch-new")
+ set(M1_MBIND "${MSYS_UTILS_PATH}/mbind")
+ set(M1_CONFC "${MSYS_UTILS_PATH}/confc")
+ set(M1_SYMCONV "${MSYS_UTILS_PATH}/symconv")
+
+ forte_add_post_build_command(COMMAND ${M1_CONFC} ${CMAKE_CURRENT_SOURCE_DIR}/forte.cru forte.bcr
+ COMMAND ${M1_LD} ${M1_LD_PATH} -r -d -o forte_all.o --whole-archive libforte.a ${CMAKE_CURRENT_SOURCE_DIR}/forte.lk
+ COMMAND ${M1_SYMCONV} forte_all.o -i
+ COMMAND ${M1_NM} forte_all.o > symbols.txt
+ COMMAND ${M1_MUNCH} -c symbols.txt > ctdt.c
+ COMMAND ${M1_CC} -Wall -Wno-pointer-sign -march=pentium -nostdinc -fno-common -O0 -fno-builtin -fno-defer-pop -DCPU_FAMILY=I80X86 -DFORTE_LITTLE_ENDIAN -D_POSIX_THREAD_ATTR_STACKSIZE -DFORTE_USE_WSTRING_DATATYPE -g -c -o ctdt.o ctdt.c
+ COMMAND ${M1_LD} ${M1_LD_PATH} -S -r -d -o forte.o forte_all.o ctdt.o
+ COMMAND ${M1_MBIND} forte -c ${CMAKE_CURRENT_SOURCE_DIR}/forte.mbs)
+
+#TODO add dbo generation for debugging:
+# Create a *.dbo file for debugging
+#%.dbo: $(OBJECTS) $(LINKER_SCRIPT)
+# $(LD) $(LDFLAGS) -r -d -o "$@" "$(COMPOUND_OBJECT)" $(AUXILIARY_OBJECTS)
+
+endif()
diff --git a/src/arch/be_m1/CPPLIB.ver.in b/src/arch/be_m1/CPPLIB.ver.in
new file mode 100644
index 000000000..f8dbf50bc
--- /dev/null
+++ b/src/arch/be_m1/CPPLIB.ver.in
@@ -0,0 +1 @@
+"V4.1"
diff --git a/src/arch/be_m1/GET_CHAN_INFO.cpp b/src/arch/be_m1/GET_CHAN_INFO.cpp
new file mode 100644
index 000000000..2a9826993
--- /dev/null
+++ b/src/arch/be_m1/GET_CHAN_INFO.cpp
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * Copyright (c) 2011 ACIN
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#include "GET_CHAN_INFO.h"
+#include /* M1 include files */
+#include
+#include
+#include
+
+DEFINE_FIRMWARE_FB(FORTE_GET_CHAN_INFO, g_nStringIdGET_CHAN_INFO)
+
+const CStringDictionary::TStringId FORTE_GET_CHAN_INFO::scm_anDataInputNames[] = { g_nStringIdSYMB_NAME };
+
+const CStringDictionary::TStringId FORTE_GET_CHAN_INFO::scm_anDataInputTypeIds[] = { g_nStringIdSTRING };
+
+const CStringDictionary::TStringId FORTE_GET_CHAN_INFO::scm_anDataOutputNames[] = { g_nStringIdRET_CODE, g_nStringIdMOD_NB, g_nStringIdCHAN_NB };
+
+const CStringDictionary::TStringId FORTE_GET_CHAN_INFO::scm_anDataOutputTypeIds[] = { g_nStringIdINT, g_nStringIdINT, g_nStringIdINT };
+
+const TForteInt16 FORTE_GET_CHAN_INFO::scm_anEIWithIndexes[] = { 0 };
+const TDataIOID FORTE_GET_CHAN_INFO::scm_anEIWith[] = { 0, 255 };
+const CStringDictionary::TStringId FORTE_GET_CHAN_INFO::scm_anEventInputNames[] = { g_nStringIdINIT };
+
+const TDataIOID FORTE_GET_CHAN_INFO::scm_anEOWith[] = { 0, 1, 2, 255 };
+const TForteInt16 FORTE_GET_CHAN_INFO::scm_anEOWithIndexes[] = { 0, -1 };
+const CStringDictionary::TStringId FORTE_GET_CHAN_INFO::scm_anEventOutputNames[] = { g_nStringIdINITO };
+
+const SFBInterfaceSpec FORTE_GET_CHAN_INFO::scm_stFBInterfaceSpec = { 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, 3, scm_anDataOutputNames, scm_anDataOutputTypeIds, 0, 0 };
+
+void FORTE_GET_CHAN_INFO::executeEvent(int pa_nEIID){
+ switch (pa_nEIID){
+ case scm_nEventINITID:
+ if(init()){
+ sendOutputEvent(scm_nEventINITOID);
+ }
+ break;
+ }
+}
+
+bool FORTE_GET_CHAN_INFO::init(){
+ SINT32 retCode = getChannelInfo();
+ return retCode == 0;
+}
+
+SINT32 FORTE_GET_CHAN_INFO::getChannelInfo(){
+ VOID *DrvId;
+ UINT32 Type;
+ UINT32 CardNb;
+ UINT32 ChanNb;
+
+ CHAR* symbolicName = (CHAR*) (const char*) SYMB_NAME().getValue();
+ SINT32 retCode = mio_GetDrvByName(symbolicName, &DrvId, &Type, &CardNb, &ChanNb, NULL);
+
+ CHAN_NB() = ChanNb;
+ MOD_NB() = CardNb;
+ return retCode;
+}
diff --git a/src/arch/be_m1/GET_CHAN_INFO.h b/src/arch/be_m1/GET_CHAN_INFO.h
new file mode 100644
index 000000000..4cc5ff2c1
--- /dev/null
+++ b/src/arch/be_m1/GET_CHAN_INFO.h
@@ -0,0 +1,70 @@
+/*******************************************************************************
+ * Copyright (c) 2011 ACIN
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#ifndef _GET_CHAN_INFO_H_
+#define _GET_CHAN_INFO_H_
+
+#include
+#include
+#include
+#include
+
+class FORTE_GET_CHAN_INFO: public CFunctionBlock{
+ DECLARE_FIRMWARE_FB(FORTE_GET_CHAN_INFO)
+
+private:
+ static const CStringDictionary::TStringId scm_anDataInputNames[];
+ static const CStringDictionary::TStringId scm_anDataInputTypeIds[];
+ CIEC_STRING &SYMB_NAME() {
+ return *static_cast(getDI(0));
+ };
+
+ static const CStringDictionary::TStringId scm_anDataOutputNames[];
+ static const CStringDictionary::TStringId scm_anDataOutputTypeIds[];
+ CIEC_INT &RET_CODE() {
+ return *static_cast(getDO(0));
+ };
+
+ CIEC_INT &MOD_NB() {
+ return *static_cast(getDO(1));
+ };
+
+ CIEC_INT &CHAN_NB() {
+ return *static_cast(getDO(2));
+ };
+
+ static const TEventID scm_nEventINITID = 0;
+ static const TForteInt16 scm_anEIWithIndexes[];
+ static const TDataIOID scm_anEIWith[];
+ static const CStringDictionary::TStringId scm_anEventInputNames[];
+
+ static const TEventID scm_nEventINITOID = 0;
+ static const TForteInt16 scm_anEOWithIndexes[];
+ static const TDataIOID scm_anEOWith[];
+ static const CStringDictionary::TStringId scm_anEventOutputNames[];
+
+ static const SFBInterfaceSpec scm_stFBInterfaceSpec;
+
+ FORTE_FB_DATA_ARRAY(1, 1, 3, 0);
+
+ void executeEvent(int pa_nEIID);
+
+ bool init();
+ SINT32 getChannelInfo();
+
+public:
+ FUNCTION_BLOCK_CTOR(FORTE_GET_CHAN_INFO){
+ };
+
+ virtual ~FORTE_GET_CHAN_INFO(){};
+};
+
+#endif //close the ifdef sequence from the beginning of the file
+
diff --git a/src/arch/be_m1/GET_VALUE.cpp b/src/arch/be_m1/GET_VALUE.cpp
new file mode 100644
index 000000000..76e669c15
--- /dev/null
+++ b/src/arch/be_m1/GET_VALUE.cpp
@@ -0,0 +1,70 @@
+/*******************************************************************************
+ * Copyright (c) 2011 ACIN
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#include "GET_VALUE.h"
+
+#include /* M1 include files */
+#include
+#include
+#include
+
+DEFINE_FIRMWARE_FB(FORTE_GET_VALUE, g_nStringIdGET_VALUE)
+
+const CStringDictionary::TStringId FORTE_GET_VALUE::scm_anDataInputNames[] = {g_nStringIdMOD_NB, g_nStringIdCHAN_NB};
+
+const CStringDictionary::TStringId FORTE_GET_VALUE::scm_anDataInputTypeIds[] = {g_nStringIdINT, g_nStringIdINT};
+
+const CStringDictionary::TStringId FORTE_GET_VALUE::scm_anDataOutputNames[] = {g_nStringIdRET_CODE, g_nStringIdVALUE};
+
+const CStringDictionary::TStringId FORTE_GET_VALUE::scm_anDataOutputTypeIds[] = {g_nStringIdINT, g_nStringIdSINT};
+
+const TForteInt16 FORTE_GET_VALUE::scm_anEIWithIndexes[] = {0, 2};
+const TDataIOID FORTE_GET_VALUE::scm_anEIWith[] = {0, 255, 1, 255};
+const CStringDictionary::TStringId FORTE_GET_VALUE::scm_anEventInputNames[] = {g_nStringIdINIT, g_nStringIdREQ};
+
+const TDataIOID FORTE_GET_VALUE::scm_anEOWith[] = {0, 255, 0, 1, 255};
+const TForteInt16 FORTE_GET_VALUE::scm_anEOWithIndexes[] = {0, 2, -1};
+const CStringDictionary::TStringId FORTE_GET_VALUE::scm_anEventOutputNames[] = {g_nStringIdINITO, g_nStringIdCNF};
+
+const SFBInterfaceSpec FORTE_GET_VALUE::scm_stFBInterfaceSpec = {
+ 2, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes,
+ 2, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 2, scm_anDataInputNames, scm_anDataInputTypeIds,
+ 2, scm_anDataOutputNames, scm_anDataOutputTypeIds,
+ 0, 0
+};
+
+
+void FORTE_GET_VALUE::executeEvent(int pa_nEIID){
+ switch(pa_nEIID){
+ case scm_nEventINITID:
+ if (init()) {
+ sendOutputEvent(scm_nEventINITOID);
+ }
+ break;
+ case scm_nEventREQID:
+ RET_CODE() = read();
+ sendOutputEvent(scm_nEventCNFID);
+ break;
+ }
+}
+
+bool FORTE_GET_VALUE::init() {
+ driverId = mio_GetDrv(static_cast(MOD_NB()));
+ return driverId != NULL;
+}
+
+SINT32 FORTE_GET_VALUE::read() {
+ SINT32 myValue;
+ SINT32 retCode = mio_GetValue(driverId, CHAN_NB(), &myValue);
+ VALUE() = myValue;
+ return retCode;
+}
+
+
diff --git a/src/arch/be_m1/GET_VALUE.h b/src/arch/be_m1/GET_VALUE.h
new file mode 100644
index 000000000..ec385c492
--- /dev/null
+++ b/src/arch/be_m1/GET_VALUE.h
@@ -0,0 +1,80 @@
+/*******************************************************************************
+ * Copyright (c) 2011 ACIN
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#ifndef _GET_VALUE_H_
+#define _GET_VALUE_H_
+
+#include
+#include
+#include
+#include
+#include
+
+class FORTE_GET_VALUE : public CFunctionBlock{
+ DECLARE_FIRMWARE_FB(FORTE_GET_VALUE)
+
+ private:
+ static const CStringDictionary::TStringId scm_anDataInputNames[];
+ static const CStringDictionary::TStringId scm_anDataInputTypeIds[];
+ CIEC_INT &MOD_NB(){
+ return *static_cast(getDI(0));
+ }
+ ;
+
+ CIEC_INT &CHAN_NB(){
+ return *static_cast(getDI(1));
+ }
+ ;
+
+ static const CStringDictionary::TStringId scm_anDataOutputNames[];
+ static const CStringDictionary::TStringId scm_anDataOutputTypeIds[];
+ CIEC_INT &RET_CODE(){
+ return *static_cast(getDO(0));
+ }
+ ;
+
+ CIEC_SINT &VALUE(){
+ return *static_cast(getDO(1));
+ }
+ ;
+
+ static const TEventID scm_nEventINITID = 0;
+ static const TEventID scm_nEventREQID = 1;
+ static const TForteInt16 scm_anEIWithIndexes[];
+ static const TDataIOID scm_anEIWith[];
+ static const CStringDictionary::TStringId scm_anEventInputNames[];
+
+ static const TEventID scm_nEventINITOID = 0;
+ static const TEventID scm_nEventCNFID = 1;
+ static const TForteInt16 scm_anEOWithIndexes[];
+ static const TDataIOID scm_anEOWith[];
+ static const CStringDictionary::TStringId scm_anEventOutputNames[];
+
+ static const SFBInterfaceSpec scm_stFBInterfaceSpec;
+
+ FORTE_FB_DATA_ARRAY(2, 2, 2, 0)
+ ;
+
+ void executeEvent(int pa_nEIID);
+
+ void *driverId;
+
+ bool init();
+ SINT32 read();
+
+ public:
+ FUNCTION_BLOCK_CTOR(FORTE_GET_VALUE){
+ };
+
+ virtual ~FORTE_GET_VALUE(){};
+
+};
+
+#endif //close the ifdef sequence from the beginning of the file
diff --git a/src/arch/be_m1/SET_VALUE.cpp b/src/arch/be_m1/SET_VALUE.cpp
new file mode 100644
index 000000000..0bc5d3e8d
--- /dev/null
+++ b/src/arch/be_m1/SET_VALUE.cpp
@@ -0,0 +1,59 @@
+/*******************************************************************************
+ * Copyright (c) 2011 ACIN
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#include "SET_VALUE.h"
+#include /* M1 include files */
+#include
+#include
+#include
+
+DEFINE_FIRMWARE_FB(FORTE_SET_VALUE, g_nStringIdSET_VALUE)
+
+const CStringDictionary::TStringId FORTE_SET_VALUE::scm_anDataInputNames[] = { g_nStringIdMOD_NB, g_nStringIdCHAN_NB, g_nStringIdVALUE };
+
+const CStringDictionary::TStringId FORTE_SET_VALUE::scm_anDataInputTypeIds[] = { g_nStringIdINT, g_nStringIdINT, g_nStringIdSINT };
+
+const CStringDictionary::TStringId FORTE_SET_VALUE::scm_anDataOutputNames[] = { g_nStringIdRET_CODE };
+
+const CStringDictionary::TStringId FORTE_SET_VALUE::scm_anDataOutputTypeIds[] = { g_nStringIdINT };
+
+const TForteInt16 FORTE_SET_VALUE::scm_anEIWithIndexes[] = { 0, 2 };
+const TDataIOID FORTE_SET_VALUE::scm_anEIWith[] = { 0, 255, 2, 1, 255 };
+const CStringDictionary::TStringId FORTE_SET_VALUE::scm_anEventInputNames[] = { g_nStringIdINIT, g_nStringIdREQ };
+
+const TDataIOID FORTE_SET_VALUE::scm_anEOWith[] = { 0, 255, 0, 255 };
+const TForteInt16 FORTE_SET_VALUE::scm_anEOWithIndexes[] = { 0, 2, -1 };
+const CStringDictionary::TStringId FORTE_SET_VALUE::scm_anEventOutputNames[] = { g_nStringIdINITO, g_nStringIdCNF };
+
+const SFBInterfaceSpec FORTE_SET_VALUE::scm_stFBInterfaceSpec = { 2, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, 2, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 3, scm_anDataInputNames, scm_anDataInputTypeIds, 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, 0, 0 };
+
+void FORTE_SET_VALUE::executeEvent(int pa_nEIID){
+ switch (pa_nEIID){
+ case scm_nEventINITID:
+ if(init()){
+ sendOutputEvent(scm_nEventINITOID);
+ }
+ break;
+ case scm_nEventREQID:
+ RET_CODE() = write();
+ sendOutputEvent(scm_nEventCNFID);
+ break;
+ }
+}
+
+bool FORTE_SET_VALUE::init(){
+ driverId = mio_GetDrv((short) MOD_NB());
+ return driverId != NULL;
+}
+
+SINT32 FORTE_SET_VALUE::write(){
+ return mio_SetValue(driverId, static_cast(CHAN_NB()), VALUE());
+}
+
diff --git a/src/arch/be_m1/SET_VALUE.h b/src/arch/be_m1/SET_VALUE.h
new file mode 100644
index 000000000..bd9548033
--- /dev/null
+++ b/src/arch/be_m1/SET_VALUE.h
@@ -0,0 +1,80 @@
+/*******************************************************************************
+ * Copyright (c) 2011 ACIN
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#ifndef _SET_VALUE_H_
+#define _SET_VALUE_H_
+
+#include /* M1 include files */
+#include
+#include
+#include
+#include
+
+class FORTE_SET_VALUE : public CFunctionBlock{
+ DECLARE_FIRMWARE_FB(FORTE_SET_VALUE)
+
+ private:
+ static const CStringDictionary::TStringId scm_anDataInputNames[];
+ static const CStringDictionary::TStringId scm_anDataInputTypeIds[];
+ CIEC_INT &MOD_NB(){
+ return *static_cast(getDI(0));
+ }
+ ;
+
+ CIEC_INT &CHAN_NB(){
+ return *static_cast(getDI(1));
+ }
+ ;
+
+ CIEC_SINT &VALUE(){
+ return *static_cast(getDI(2));
+ }
+ ;
+
+ static const CStringDictionary::TStringId scm_anDataOutputNames[];
+ static const CStringDictionary::TStringId scm_anDataOutputTypeIds[];
+ CIEC_INT &RET_CODE(){
+ return *static_cast(getDO(0));
+ }
+ ;
+
+ static const TEventID scm_nEventINITID = 0;
+ static const TEventID scm_nEventREQID = 1;
+ static const TForteInt16 scm_anEIWithIndexes[];
+ static const TDataIOID scm_anEIWith[];
+ static const CStringDictionary::TStringId scm_anEventInputNames[];
+
+ static const TEventID scm_nEventINITOID = 0;
+ static const TEventID scm_nEventCNFID = 1;
+ static const TForteInt16 scm_anEOWithIndexes[];
+ static const TDataIOID scm_anEOWith[];
+ static const CStringDictionary::TStringId scm_anEventOutputNames[];
+
+ static const SFBInterfaceSpec scm_stFBInterfaceSpec;
+
+ FORTE_FB_DATA_ARRAY(2, 3, 1, 0)
+ ;
+
+ void executeEvent(int pa_nEIID);
+
+ void *driverId;
+
+ bool init();
+ SINT32 write();
+
+ public:
+ FUNCTION_BLOCK_CTOR(FORTE_SET_VALUE){
+ };
+
+ virtual ~FORTE_SET_VALUE(){};
+
+};
+
+#endif //close the ifdef sequence from the beginning of the file
diff --git a/src/arch/be_m1/SVIreceive_1.cpp b/src/arch/be_m1/SVIreceive_1.cpp
new file mode 100644
index 000000000..91ddf04a8
--- /dev/null
+++ b/src/arch/be_m1/SVIreceive_1.cpp
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * Copyright (c) 2011 ACIN
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#include "SVIreceive_1.h"
+
+DEFINE_FIRMWARE_FB(FORTE_SVIreceive_1, g_nStringIdSVIreceive_1)
+
+const CStringDictionary::TStringId FORTE_SVIreceive_1::scm_anDataInputNames[] = { g_nStringIdQI, g_nStringIdID };
+
+const CStringDictionary::TStringId FORTE_SVIreceive_1::scm_anDataInputTypeIds[] = { g_nStringIdBOOL, g_nStringIdSTRING };
+
+const CStringDictionary::TStringId FORTE_SVIreceive_1::scm_anDataOutputNames[] = { g_nStringIdQO, g_nStringIdRD_1 };
+
+const CStringDictionary::TStringId FORTE_SVIreceive_1::scm_anDataOutputTypeIds[] = { g_nStringIdBOOL, g_nStringIdANY };
+
+const TForteInt16 FORTE_SVIreceive_1::scm_anEIWithIndexes[] = { 0, 3 };
+const TDataIOID FORTE_SVIreceive_1::scm_anEIWith[] = { 0, 1, 255, 0, 255 };
+const CStringDictionary::TStringId FORTE_SVIreceive_1::scm_anEventInputNames[] = { g_nStringIdINIT, g_nStringIdREQ };
+
+const TDataIOID FORTE_SVIreceive_1::scm_anEOWith[] = { 0, 255, 0, 1, 255 };
+const TForteInt16 FORTE_SVIreceive_1::scm_anEOWithIndexes[] = { 0, 2, -1 };
+const CStringDictionary::TStringId FORTE_SVIreceive_1::scm_anEventOutputNames[] = { g_nStringIdINITO, g_nStringIdCNF };
+
+const SFBInterfaceSpec FORTE_SVIreceive_1::scm_stFBInterfaceSpec = { 2, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, 2, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 2, scm_anDataInputNames, scm_anDataInputTypeIds, 2, scm_anDataOutputNames, scm_anDataOutputTypeIds, 0, 0 };
+
+void FORTE_SVIreceive_1::executeEvent(int pa_nEIID){
+ switch (pa_nEIID){
+ case scm_nEventINITID:
+ if(true == QI()){
+ QO() = registerSVIvar(ID(), RD_1(), SVI_F_IN);
+ }
+ sendOutputEvent(scm_nEventINITOID);
+ break;
+
+ case scm_nEventREQID:
+ sendOutputEvent(scm_nEventCNFID);
+ break;
+ default:
+ break;
+ }
+}
+
diff --git a/src/arch/be_m1/SVIreceive_1.h b/src/arch/be_m1/SVIreceive_1.h
new file mode 100644
index 000000000..a28096c74
--- /dev/null
+++ b/src/arch/be_m1/SVIreceive_1.h
@@ -0,0 +1,70 @@
+/*******************************************************************************
+ * Copyright (c) 2011 ACIN
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#ifndef _SVIRECEIVE_1_H_
+#define _SVIRECEIVE_1_H_
+
+#include "BE_SVIFB.h"
+#include
+#include
+#include
+
+class FORTE_SVIreceive_1: public BE_SVIFB{
+ DECLARE_FIRMWARE_FB(FORTE_SVIreceive_1)
+
+private:
+ static const CStringDictionary::TStringId scm_anDataInputNames[];
+ static const CStringDictionary::TStringId scm_anDataInputTypeIds[];
+ CIEC_BOOL &QI() {
+ return *static_cast(getDI(0));
+ };
+
+ CIEC_STRING &ID() {
+ return *static_cast(getDI(1));
+ };
+
+ static const CStringDictionary::TStringId scm_anDataOutputNames[];
+ static const CStringDictionary::TStringId scm_anDataOutputTypeIds[];
+ CIEC_BOOL &QO() {
+ return *static_cast(getDO(0));
+ };
+
+ CIEC_ANY &RD_1() {
+ return *static_cast(getDO(1));
+ };
+
+ static const TEventID scm_nEventINITID = 0;
+ static const TEventID scm_nEventREQID = 1;
+ static const TForteInt16 scm_anEIWithIndexes[];
+ static const TDataIOID scm_anEIWith[];
+ static const CStringDictionary::TStringId scm_anEventInputNames[];
+
+ static const TEventID scm_nEventINITOID = 0;
+ static const TEventID scm_nEventCNFID = 1;
+ static const TForteInt16 scm_anEOWithIndexes[];
+ static const TDataIOID scm_anEOWith[];
+ static const CStringDictionary::TStringId scm_anEventOutputNames[];
+
+ static const SFBInterfaceSpec scm_stFBInterfaceSpec;
+
+ FORTE_FB_DATA_ARRAY(2, 2, 2, 0);
+
+ void executeEvent(int pa_nEIID);
+
+public:
+ FORTE_SVIreceive_1(const CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes) :
+ BE_SVIFB( pa_poSrcRes, &scm_stFBInterfaceSpec, pa_nInstanceNameId, m_anFBConnData, m_anFBVarsData){
+ };
+ virtual ~FORTE_SVIreceive_1(){};
+
+};
+
+#endif //close the ifdef sequence from the beginning of the file
+
diff --git a/src/arch/be_m1/SVIsend_1.cpp b/src/arch/be_m1/SVIsend_1.cpp
new file mode 100644
index 000000000..eff01734f
--- /dev/null
+++ b/src/arch/be_m1/SVIsend_1.cpp
@@ -0,0 +1,62 @@
+/*******************************************************************************
+ * Copyright (c) 2011 ACIN
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#include "SVIsend_1.h"
+
+DEFINE_FIRMWARE_FB(FORTE_SVIsend_1, g_nStringIdSVIsend_1)
+
+const CStringDictionary::TStringId FORTE_SVIsend_1::scm_anDataInputNames[] = {g_nStringIdQI, g_nStringIdID, g_nStringIdSD_1};
+
+const CStringDictionary::TStringId FORTE_SVIsend_1::scm_anDataInputTypeIds[] = {g_nStringIdBOOL, g_nStringIdSTRING, g_nStringIdANY};
+
+const CStringDictionary::TStringId FORTE_SVIsend_1::scm_anDataOutputNames[] = {g_nStringIdQO};
+
+const CStringDictionary::TStringId FORTE_SVIsend_1::scm_anDataOutputTypeIds[] = {g_nStringIdBOOL};
+
+const TForteInt16 FORTE_SVIsend_1::scm_anEIWithIndexes[] = {0, 4};
+const TDataIOID FORTE_SVIsend_1::scm_anEIWith[] = {0, 1, 2, 255, 0, 1, 2, 255};
+const CStringDictionary::TStringId FORTE_SVIsend_1::scm_anEventInputNames[] = {g_nStringIdINIT, g_nStringIdREQ};
+
+const TDataIOID FORTE_SVIsend_1::scm_anEOWith[] = {0, 255, 0, 255};
+const TForteInt16 FORTE_SVIsend_1::scm_anEOWithIndexes[] = {0, 2, -1};
+const CStringDictionary::TStringId FORTE_SVIsend_1::scm_anEventOutputNames[] = {g_nStringIdINITO, g_nStringIdCNF};
+
+const SFBInterfaceSpec FORTE_SVIsend_1::scm_stFBInterfaceSpec = {
+ 2, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes,
+ 2, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 3, scm_anDataInputNames, scm_anDataInputTypeIds,
+ 1, scm_anDataOutputNames, scm_anDataOutputTypeIds,
+ 0, 0
+};
+
+
+void FORTE_SVIsend_1::executeEvent(int pa_nEIID){
+ switch(pa_nEIID){
+ case scm_nEventINITID:
+ if(true == QI()){
+ QO() = registerSVIvar(ID(),SD_1(),SVI_F_OUT);
+ }
+ sendOutputEvent(scm_nEventINITOID);
+ if (true == QO()) {
+ printf("Alles OK send\n");
+ } else {
+ printf("Alles FALSCH send\n");
+ }
+ break;
+
+ case scm_nEventREQID:
+ sendOutputEvent(scm_nEventCNFID);
+ break;
+ default:
+ break;
+ }
+}
+
+
+
diff --git a/src/arch/be_m1/SVIsend_1.h b/src/arch/be_m1/SVIsend_1.h
new file mode 100644
index 000000000..7a57cb5e2
--- /dev/null
+++ b/src/arch/be_m1/SVIsend_1.h
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * Copyright (c) 2011 ACIN
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#ifndef _SVISEND_1_H_
+#define _SVISEND_1_H_
+
+#include "BE_SVIFB.h"
+#include
+#include
+#include
+
+class FORTE_SVIsend_1: public BE_SVIFB{
+ DECLARE_FIRMWARE_FB(FORTE_SVIsend_1)
+
+private:
+ static const CStringDictionary::TStringId scm_anDataInputNames[];
+ static const CStringDictionary::TStringId scm_anDataInputTypeIds[];
+ CIEC_BOOL &QI() {
+ return *static_cast(getDI(0));
+ };
+
+ CIEC_STRING &ID() {
+ return *static_cast(getDI(1));
+ };
+
+ CIEC_ANY &SD_1() {
+ return *static_cast(getDI(2));
+ };
+
+ static const CStringDictionary::TStringId scm_anDataOutputNames[];
+ static const CStringDictionary::TStringId scm_anDataOutputTypeIds[];
+ CIEC_BOOL &QO() {
+ return *static_cast(getDO(0));
+ };
+
+ static const TEventID scm_nEventINITID = 0;
+ static const TEventID scm_nEventREQID = 1;
+ static const TForteInt16 scm_anEIWithIndexes[];
+ static const TDataIOID scm_anEIWith[];
+ static const CStringDictionary::TStringId scm_anEventInputNames[];
+
+ static const TEventID scm_nEventINITOID = 0;
+ static const TEventID scm_nEventCNFID = 1;
+ static const TForteInt16 scm_anEOWithIndexes[];
+ static const TDataIOID scm_anEOWith[];
+ static const CStringDictionary::TStringId scm_anEventOutputNames[];
+
+ static const SFBInterfaceSpec scm_stFBInterfaceSpec;
+
+ FORTE_FB_DATA_ARRAY(2, 3, 1, 0);
+
+ void executeEvent(int pa_nEIID);
+
+public:
+ FORTE_SVIsend_1(const CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes) :
+ BE_SVIFB( pa_poSrcRes, &scm_stFBInterfaceSpec, pa_nInstanceNameId, m_anFBConnData, m_anFBVarsData){
+ };
+
+ virtual ~FORTE_SVIsend_1(){};
+
+};
+
+#endif //close the ifdef sequence from the beginning of the file
+
diff --git a/src/arch/be_m1/forte.cru b/src/arch/be_m1/forte.cru
new file mode 100644
index 000000000..7ec46e7a9
--- /dev/null
+++ b/src/arch/be_m1/forte.cru
@@ -0,0 +1,42 @@
+MODUL forte
+VERSION 120
+PROPERTY RECONF
+ROOT
+ (OwnParms)
+ DelayTime = UINT32(5 .. 100)[25]
+END_ROOT
+
+DESC(049)
+ OwnParms = "Applikationsspezifische Parameter"
+ OwnParms.DelayTime = "Zykluszeit in ms"
+END_DESC
+
+DESC(001)
+ OwnParms = "Application specific parameters"
+ OwnParms.DelayTime = "Access cyclic time in ms"
+END_DESC
+
+HELP(049)
+ "Allgemein:"
+ " Dieses Software-Modul implementiert ein IEC 61499 Laufzeitsystem"
+ " basierend auf dem Source Code FORTE aus dem 4DIAC - Framework for"
+ " Distributed Industrial Automation and Control (www.fordiac.org)."
+ ""
+ "SVI:"
+ " Dieses Software-Modul verfuegt ueber einen SVI-Server. Prozesswerte"
+ " koennen damit online ausgelesen oder geaendert werden."
+ ""
+END_HELP
+
+HELP(001)
+ "Introduction:"
+ " This software module enables IEC 61499 functionality based on the open"
+ " source environment FORTE from 4DIAC - Framework for Distributed "
+ " Industrial Automation and Control (www.fordiac.org)"
+ ""
+ "SVI:"
+ " This software module has an SVI server, that permits online changes of"
+ " parameters. The number and name of the parameters depedends on the "
+ " IEC 61499 control application loaded into this module."
+ ""
+END_HELP
diff --git a/src/arch/be_m1/forte.lk b/src/arch/be_m1/forte.lk
new file mode 100644
index 000000000..3ad7b9343
--- /dev/null
+++ b/src/arch/be_m1/forte.lk
@@ -0,0 +1 @@
+GROUP("befc\libbefc_1.0.0.a")
\ No newline at end of file
diff --git a/src/arch/be_m1/forte.mbs b/src/arch/be_m1/forte.mbs
new file mode 100644
index 000000000..c6ff6141f
--- /dev/null
+++ b/src/arch/be_m1/forte.mbs
@@ -0,0 +1,34 @@
+;Script for MBIND to build forte.m
+;
+;Header
+;
+ModuleType = VXW
+Version = ../forte.ver
+Reentrant = FALSE
+NoOnlineConfig = FALSE
+NoOnlineInstall = FALSE
+NoOnlineDeinstall = FALSE
+DebugInfo = TRUE
+ErrorTolerant = FALSE
+NoAutoInstall = FALSE
+SystemModule = FALSE
+;
+;Object-Code
+;
+ObjectType = OBJ
+ObjectMode = NORMAL
+Version = ../forte.ver
+ObjectName = forte.o
+;
+;Configuration-Rule
+;
+ObjectType = BCRU
+ObjectName = forte.bcr
+;
+;Source-Code
+;
+;ObjectType = C-ZIP
+;ObjectName = forte.tgz
+ObjectType = SWREQ
+Version = ../CPPLIB.ver
+ObjectName = CPPLIB
diff --git a/src/arch/be_m1/forte.ver.in b/src/arch/be_m1/forte.ver.in
new file mode 100644
index 000000000..31f54fdb3
--- /dev/null
+++ b/src/arch/be_m1/forte.ver.in
@@ -0,0 +1 @@
+"V1.00.01 Alpha"
diff --git a/src/arch/be_m1/fortealloc.h b/src/arch/be_m1/fortealloc.h
new file mode 100644
index 000000000..25842787d
--- /dev/null
+++ b/src/arch/be_m1/fortealloc.h
@@ -0,0 +1,99 @@
+/*******************************************************************************
+ * Copyright (c) 2012, 2013 ACIN and fortiss GmbH
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#ifndef FORTEALLOC_H_
+#define FORTEALLOC_H_
+
+#include "datatype.h"
+#include
+#include
+#include
+#include
+#include
+
+//--- SW-Module memory partition, needed for new operator
+extern UINT32 FORTE_MemPart;
+
+inline
+void forte_free(void *pa_pvData){
+ sys_MemXFree(pa_pvData);
+}
+
+inline
+void *forte_malloc(size_t pa_nSize){
+ void * pTemp;
+
+ pTemp = sys_MemXPAlloc(FORTE_MemPart, pa_nSize);
+
+ if (pTemp == NULL)
+ {
+ /* no memory, suspend task to avoid a NULL exception*/
+ log_Err(
+ "forte_malloc: unable to allocate 0x%x bytes in partition %d, Suspend task!",
+ pa_nSize, FORTE_MemPart);
+ taskSuspend(taskIdSelf());
+ }
+
+ return pTemp;
+}
+
+inline
+void *forte_realloc(void *pa_pvData, size_t pa_nSize){
+ //FIXME add realloc implementation for BE_M1 platform
+ return realloc(pa_pvData, pa_nSize);
+}
+
+
+inline
+void* operator new(size_t pa_nSize) throw(std::bad_alloc) {
+ return forte_malloc(pa_nSize);
+}
+
+inline
+void* operator new[](size_t pa_nSize) throw(std::bad_alloc) {
+ return forte_malloc(pa_nSize);
+}
+
+inline
+void operator delete(void* pa_pvData) throw() {
+ sys_MemXFree(pa_pvData);
+}
+
+inline
+void operator delete[](void* pa_pvData) throw() {
+ sys_MemXFree(pa_pvData);
+}
+
+/*! \brief Placement new operator
+ *
+ * Will use the given buffer as memory region. The need size will be ignored.
+ * Objects created with this new must not deleted only invoke the destructor
+ *
+ * @param pa_pData
+ */
+inline
+void * operator new(size_t, TForteByte *pa_pData) throw() {
+ return pa_pData;
+}
+
+inline
+void * operator new[](size_t, TForteByte *pa_pData) throw() {
+ return pa_pData;
+}
+
+inline
+void operator delete(void *, TForteByte *) throw() {
+}
+
+inline
+void operator delete[](void *, TForteByte *) throw() {
+}
+
+#endif /* FORTEALLOC_H_ */
diff --git a/src/arch/be_m1/fortemodule.cpp b/src/arch/be_m1/fortemodule.cpp
new file mode 100644
index 000000000..33d1d33ad
--- /dev/null
+++ b/src/arch/be_m1/fortemodule.cpp
@@ -0,0 +1,322 @@
+/*******************************************************************************
+ * Copyright (c) 2012 ACIN
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#include
+#include
+#include
+#include
+#include
+
+#include "fortemodule.h"
+
+#include
+#include "BE_RMT_DEV.h"
+#include
+
+#define MIO_VERS_LEN 24
+#define FORTE_DELAY 25 // Access cycle time in ms
+#define FORTE_C_PARMS "OwnParms" // Group in mconfig.ini
+#define FORTE_C_DELAY "DelayTime" // Keyword in mconfig.ini
+
+MLOCAL CHAR FORTE_Version[MIO_VERS_LEN] =
+#include "forte.ver"
+;
+
+extern UINT32 FORTE_MemPart;
+
+//--- Function definitions
+MLOCAL VOID ExcHandler(SINT32 Signal);
+MLOCAL VOID PanicHandler(UINT32 PanicMode);
+
+//--- Forward declaration
+class CFORTEModule;
+
+//--- globals
+CFORTEModule* g_poMainModule;
+
+//--- SW-Module memory partition, needed for new operator
+UINT32 FORTE_MemPart = 0;
+
+/*--------------------------------------------------------------------------
+ * Desc: This function is the entry point to the module.
+ * After module loading this function will be called as part
+ * of the module handler.
+ * This function has to initialize the interfaces to the
+ * environment (SMI, SVI) so that they are ready to operate.
+ *
+ *
+ * InP: pConf Parameter for configuration (data from MCONFIG.INI).
+ * InP: pLoad Parameter from module loading.
+ * OutP:
+ *
+ * Ret: >0 Task-Id, module initialized correctly.
+ * <0 Error during initialization.
+ *-------------------------------------------------------------------------*/
+extern "C" SINT32 forte_Init(MOD_CONF *pConf, MOD_LOAD *pLoad){
+ //--- store memory partition, needed for new operator
+ FORTE_MemPart = pConf->MemPart;
+
+ //--- Create new application class.
+ g_poMainModule = new CFORTEModule();
+
+ //--- Close application if an error is occurred.
+ if(g_poMainModule == NULL
+ )
+ return ERROR;
+
+ //--- Initialize software module.
+ SINT32 TaskId = g_poMainModule->Init(pConf, pLoad, CFORTEModule::MINVERS, CFORTEModule::MAXVERS, 10000, FORTE_Version, "FORTE", (VOIDFUNCPTR) PanicHandler, (VOIDFUNCPTR) ExcHandler);
+
+ //--- Close application if an error is occurred.
+ if(TaskId == ERROR)
+ SAFE_DELETE(g_poMainModule);
+
+ return TaskId;
+}
+
+/*--------------------------------------------------------------------------
+ * Desc: Handler for CPU exception signal if not in debug mode.
+ *
+ * InP: Signal Signal number (M_SIGEXCEPT)
+ * OutP:
+ *
+ * Ret:
+ *-------------------------------------------------------------------------*/
+MLOCAL VOID ExcHandler(SINT32 Signal){
+ DEVLOG_INFO("%s: Signal %d received by task %x.", g_poMainModule->GetAppName(), Signal, taskIdSelf());
+
+ //--- Deinit application task and resources.
+ g_poMainModule->AppExcHandler(Signal);
+}
+
+/*--------------------------------------------------------------------------
+ * Desc: Handler for panic situation.
+ *
+ * InP: PanicMode Type of panic situation (SYS_APPPANIC, ...)
+ * OutP:
+ *
+ * Ret:
+ *-------------------------------------------------------------------------*/
+MLOCAL VOID PanicHandler(UINT32 PanicMode){
+ // Bring critical parts to a predefined state. For example save
+ // data to NV-RAM or close open files.
+ //
+ // ATTENTION: Leave this function as fast as possible in order to
+ // give all other modules also the chance to work off
+ // there panic handler!
+
+ g_poMainModule->AppPanicHandler(PanicMode);
+}
+
+/*--------------------------------------------------------------------------
+ * Desc: Constructor of application class.
+ *
+ * InP:
+ * OutP:
+ *
+ * Ret:
+ *-------------------------------------------------------------------------*/
+CFORTEModule::CFORTEModule() :
+ m_poDev(NULL){
+ forteInit::initForte();
+}
+
+/*--------------------------------------------------------------------------
+ * Desc: Destructor of application class.
+ *
+ * InP:
+ * OutP:
+ *
+ * Ret:
+ *-------------------------------------------------------------------------*/
+CFORTEModule::~CFORTEModule(){
+ if(GetDebugLevel() & APP_DBG_INFO1)
+ DEVLOG_INFO("FORTE_mod: Destruct done.");
+}
+
+/*--------------------------------------------------------------------------
+ * Desc: This virtual function will be called as a part of the
+ forte_Init function after loading of the software module.
+ *
+ * InP:
+ * OutP:
+ *
+ * Ret: 0 Everything is Ok
+ * <0 Error occurred
+ *-------------------------------------------------------------------------*/
+SINT32 CFORTEModule::AppEarlyInit(VOID){
+ return (0);
+}
+
+/*--------------------------------------------------------------------------
+ * Desc: This virtual function will be called after loading of the
+ * software module.
+ *
+ * InP:
+ * OutP:
+ *
+ * Ret: 0 Everything is Ok
+ * <0 Error occurred
+ *-------------------------------------------------------------------------*/
+SINT32 CFORTEModule::AppInit(VOID){
+ m_unFORTEstartOK = 1;
+ //--- Add global variables for values that have to be exported via SVI.
+ if(GetSVIHandler().AddGlobVar("FORTEstart", SVI_F_INOUT | SVI_F_UINT32, 4, &(m_unFORTEstartOK), 0, 0) != OK){
+ DEVLOG_ERROR("FORTE_mod::APPINIT: Can't add SVI variable 'FORTEstart'!");
+ }
+
+ DEVLOG_INFO("appInit of forte\n");
+ if(0 == m_poDev){
+ m_poDev = new BE_RMT_DEV(*this);
+ DEVLOG_INFO("appInit after new BE_RMT_DEV");
+ }
+
+ //--- Read configuration file
+ CfgRead();
+ return (0);
+}
+
+/*--------------------------------------------------------------------------
+ * Desc: This virtual function will be called bevor the application will
+ * be removed.
+ *
+ * InP:
+ * OutP:
+ *
+ * Ret: 0 Everything ok
+ * <0 Error occurred
+ *-------------------------------------------------------------------------*/
+SINT32 CFORTEModule::AppDeInit(VOID){
+ //--- Delete walking light class
+ SAFE_DELETE(m_poDev);
+ return (0);
+}
+
+/*--------------------------------------------------------------------------
+ * Desc: This virtual function will be called bevor the application will
+ * be removed.
+ *
+ * InP:
+ * OutP:
+ *
+ * Ret: 0 Everything ok
+ * <0 Error occurred
+ *-------------------------------------------------------------------------*/
+SINT32 CFORTEModule::AppLateDeInit(VOID){
+ return (0);
+}
+
+/*--------------------------------------------------------------------------
+ * Desc: This virtual function will be called when the 'End of Init'
+ * signal will be sent by the system.
+ *
+ * InP:
+ * OutP:
+ *
+ * Ret: 0 Everything ok
+ * <0 Error occurred
+ *-------------------------------------------------------------------------*/
+SINT32 CFORTEModule::AppEOI(VOID){
+ CHAR connectionString[16];
+ if(0 != m_poDev){
+ m_poDev->startDevice();
+ DEVLOG_INFO("m_poDev started\n");
+ }
+ else{
+ DEVLOG_ERROR("no m_poDev preset\n");
+ }
+
+ return (0);
+}
+
+/*--------------------------------------------------------------------------
+ * Desc: This is a dummy method which will be called when the signal
+ * 'stop' is received from the system.
+ *
+ * InP:
+ * OutP:
+ * Throws:
+ * Ret: OK Everything ok
+ * ERROR An error occurred
+ *-------------------------------------------------------------------------*/
+SINT32 CFORTEModule::AppStop(VOID){
+ if(0 != m_poDev){
+ m_poDev->changeFBExecutionState(cg_nMGM_CMD_Stop);
+ }
+
+ return OK;
+}
+
+/*--------------------------------------------------------------------------
+ * Desc: This is a dummy method which will be called when the signal
+ * 'run' is received from the system.
+ *
+ * InP:
+ * OutP:
+ * Throws:
+ * Ret: OK Everything ok
+ * ERROR An error occurred
+ *-------------------------------------------------------------------------*/
+SINT32 CFORTEModule::AppRun(VOID){
+
+ return OK;
+}
+
+/*--------------------------------------------------------------------------
+ * Desc: This virtual function will be called if a panic situation
+ * appears in the system.
+ *
+ * InP:
+ * OutP:
+ *
+ * Ret: 0 Everything ok
+ * <0 Error occurred
+ *-------------------------------------------------------------------------*/
+VOID CFORTEModule::AppPanicHandler(UINT32 PanicMode){
+ sys_Printf("%s AppPanicHandler", GetAppName());
+}
+
+/*--------------------------------------------------------------------------
+ * Desc: This method handles the RPC call 'RpcNewCfg'.
+ *
+ * InP: pMsg Message data from RPC call.
+ * OutP:
+ * Throws:
+ * Ret:
+ *-------------------------------------------------------------------------*/
+VOID CFORTEModule::RpcNewCfg(SMI_MSG *pMsg){
+ SMI_NEWCFG_R Reply;
+
+ if(GetModState() == RES_S_STOP || GetModState() == RES_S_RUN){
+ //--- Read configuration file
+ CfgRead();
+
+ Reply.RetCode = SMI_E_OK;
+ }
+ else
+ Reply.RetCode = SMI_E_FAILED;
+
+ smi_FreeData(pMsg);
+ smi_SendCReply(GetSmiID(), pMsg, SMI_E_OK, &Reply, sizeof(Reply));
+}
+
+/*---------------------------------------------------------------------------
+ * Desc: This function reads the configuration from the given
+ * configuration file.
+ *
+ * InP:
+ * OutP:
+ * Ret:
+ *--------------------------------------------------------------------------*/
+VOID CFORTEModule::CfgRead(VOID){
+ //--- Get the delay time for my application.
+ pf_GetInt(GetAppName(), FORTE_C_PARMS, FORTE_C_DELAY, FORTE_DELAY, (SINT32 *) &m_unFORTEstartOK, GetCfgLine(), GetProfileName());
+}
+
diff --git a/src/arch/be_m1/fortemodule.h b/src/arch/be_m1/fortemodule.h
new file mode 100644
index 000000000..7bc6bc142
--- /dev/null
+++ b/src/arch/be_m1/fortemodule.h
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * Copyright (c) 2012 ACIN
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#ifndef __FORTE_MODULE_H__
+#define __FORTE_MODULE_H__
+
+#include
+#include
+#include
+
+
+class BE_RMT_DEV;
+
+class CFORTEModule : public BEModule{
+ public:
+ CFORTEModule();
+ virtual ~CFORTEModule();
+
+ static const UINT32 MINVERS = 2;
+ static const UINT32 MAXVERS = 2;
+
+ virtual VOID AppPanicHandler(UINT32 PanicMode);
+ VOID CfgRead(VOID);
+
+ private:
+ virtual SINT32 AppEarlyInit(VOID);
+ virtual SINT32 AppInit(VOID);
+ virtual SINT32 AppDeInit(VOID);
+ virtual SINT32 AppLateDeInit(VOID);
+ virtual SINT32 AppEOI(VOID);
+ virtual SINT32 AppStop(VOID);
+ virtual SINT32 AppRun(VOID);
+ virtual VOID RpcNewCfg(SMI_MSG *pMsg);
+
+ BE_RMT_DEV *m_poDev;
+
+ UINT32 m_unFORTEstartOK;
+};
+
+
+#endif // __FORTE_MODULE_H__
diff --git a/src/arch/be_m1/sockhand.h b/src/arch/be_m1/sockhand.h
new file mode 100644
index 000000000..d6e764d0b
--- /dev/null
+++ b/src/arch/be_m1/sockhand.h
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * Copyright (c) 2012, 2015 ACIN and fortiss GmbH
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#ifndef SOCKHAND_H_
+#define SOCKHAND_H_
+
+
+#include
+#include
+#include
+#include
+#include
+
+//these include needs to be last
+#include "../fdselecthand.h"
+#include "../bsdsocketinterf.h"
+#include "../gensockhand.h"
+
+typedef CGenericIPComSocketHandler CIPComSocketHandler;
+
+#endif /* SOCKHAND_H_ */
diff --git a/src/arch/be_m1/stdint.h b/src/arch/be_m1/stdint.h
new file mode 100644
index 000000000..771c69f35
--- /dev/null
+++ b/src/arch/be_m1/stdint.h
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * Copyright (c) 2012 ACIN
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl, Stefano Campanelli - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#ifndef _STDINT_H_
+#define _STDINT_H_
+
+#include
+
+#define UINT8_MIN _ARCH_UCHAR_MIN
+#define UINT8_MAX _ARCH_UCHAR_MAX
+#define INT8_MIN _ARCH_CHAR_MIN
+#define INT8_MAX _ARCH_CHAR_MAX
+
+#define INT16_MIN _ARCH_SHRT_MIN
+#define INT16_MAX _ARCH_SHRT_MAX
+#define UINT16_MIN _ARCH_USHRT_MIN
+#define UINT16_MAX _ARCH_USHRT_MAX
+
+#define INT32_MIN _ARCH_INT_MIN
+#define INT32_MAX _ARCH_INT_MAX
+#define UINT32_MIN _ARCH_UINT_MIN
+#define UINT32_MAX _ARCH_UINT_MAX
+
+#define UINT64_MIN 0ULL // 0
+#define UINT64_MAX 18446744073709551615ULL // 2^64 -1
+#define INT64_MIN (-9223372036854775807LL - 1) // -2^63
+#define INT64_MAX 9223372036854775807LL // 2^63-1
+
+#endif
diff --git a/src/arch/be_m1/sync.cpp b/src/arch/be_m1/sync.cpp
new file mode 100644
index 000000000..a7e3ab39b
--- /dev/null
+++ b/src/arch/be_m1/sync.cpp
@@ -0,0 +1,19 @@
+/*******************************************************************************
+ * Copyright (c) 2012 ACIN
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#include "sync.h"
+
+CVXWorksSyncObject::CVXWorksSyncObject(){
+ m_oSemBinary = semMCreate(SEM_Q_PRIORITY);
+}
+
+CVXWorksSyncObject::~CVXWorksSyncObject(){
+ semDelete (m_oSemBinary);
+}
diff --git a/src/arch/be_m1/sync.h b/src/arch/be_m1/sync.h
new file mode 100644
index 000000000..99b5cde38
--- /dev/null
+++ b/src/arch/be_m1/sync.h
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * Copyright (c) 2012 ACIN
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#ifndef _SYNC_H_
+#define _SYNC_H_
+
+#include "vxWorks.h"
+#include "taskLib.h"
+#include "semLib.h"
+
+#define CSyncObject CVXWorksSyncObject //allows that doxygen can generate better documentation
+
+/*! \ingroup bem1_hal
+ * \brief The sync object implementation for the Bachmann electronic M1 interface
+ *
+ * In the Bachmann electronic M1 version we use a binary semaphore provided from vxWorks
+ *
+ */
+
+class CVXWorksSyncObject{
+ public:
+ CVXWorksSyncObject();
+ virtual ~CVXWorksSyncObject();
+
+ void lock(void){
+ semTake(m_oSemBinary, WAIT_FOREVER);
+ }
+
+ void unlock(void){
+ semGive(m_oSemBinary);
+ }
+
+ private:
+ SEM_ID m_oSemBinary;
+
+};
+
+#endif /*SYNC_H_*/
diff --git a/src/arch/be_m1/thread.cpp b/src/arch/be_m1/thread.cpp
new file mode 100644
index 000000000..270aa3f0c
--- /dev/null
+++ b/src/arch/be_m1/thread.cpp
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * Copyright (c) 2012 ACIN
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#include "thread.h"
+#include "../devlog.h"
+#include
+#include
+
+void CBEThread::Main(VOID){
+ m_bAlive = true;
+ run();
+}
+
+bool CBEThread::destroy(void){
+ end();
+ return true;
+}
+
+CBEThread::CBEThread() :
+ mTskName(0){
+ m_bAlive = false;
+ m_nDeadline = 0;
+}
+
+CBEThread::~CBEThread(){
+ destroy();
+}
+
+bool CBEThread::isAlive(void){
+ return m_bAlive;
+}
+
+void CBEThread::setDeadline(TForteUInt32 pa_nVal){
+ m_nDeadline = pa_nVal;
+ //TODO implement priority assignment similar to threadx and ecos
+}
+
+TForteUInt32 CBEThread::getDeadline(void){
+ return m_nDeadline;
+}
+
+void CBEThread::start(void){
+ if(Spawn(0, 0, 130, VX_FP_TASK, APP_TSK_STACK) == ERROR){
+ log_Err("test8_mod::APPLATEINIT: Error in TaskSpawn; '%s'!", "tForteTask");
+ }
+}
+
+void CBEThread::selfSuspend(void){
+ Suspend();
+}
+
+void CBEThread::resumeSelfSuspend(void){
+ Resume();
+}
+
+void CBEThread::end(void){
+ m_bAlive = false;
+ resumeSelfSuspend();
+ join();
+}
+
+void CBEThread::join(void){
+ Delete();
+}
diff --git a/src/arch/be_m1/thread.h b/src/arch/be_m1/thread.h
new file mode 100644
index 000000000..f290716c4
--- /dev/null
+++ b/src/arch/be_m1/thread.h
@@ -0,0 +1,130 @@
+/*******************************************************************************
+ * Copyright (c) 2012 ACIN
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#ifndef _THREAD_H_
+#define _THREAD_H_
+
+#include
+#include
+#include
+#include
+#include
+#include "../datatype.h"
+
+#define CThread CBEThread //allows that doxygen can generate better documentation
+
+/** \ingroup FORTE-HAL
+ * \defgroup bem1_hal Bachmann electronic M1 FORTE Hardware Abstraction Layer
+ *
+ * \brief The FORTE-HAL implementation for normal Bachmann electronic M1 PLCs
+ */
+
+/*! \ingroup bem1_hal
+ * \brief The thread implementation for the task class provided by Bachmann electronic.
+ *
+ * TODO implement priority assignment for realtime event chains.
+ */
+class CBEThread : public BETask{
+
+ public:
+ /*! \brief Constructor of the Thread class
+ *
+ * Does all the neccessary steps in order to get the thread running with the start()-method
+ */
+ CBEThread();
+ char * mTskName;
+
+ /*! \brief Stops and destroys thread.
+ *
+ * Will stop the execution if running and destroy the thread including all system specific data.
+ */
+ virtual ~CBEThread();
+
+ /*! \brief Indicates if the thread is allowed to execute.
+ *
+ * This functions checks if the Thread is still executing user code in its run()-method.
+ * \return true if there the run method is acitve.
+ */
+ bool isAlive(void);
+
+ void setDeadline(TForteUInt32 pa_nVal); //!Set the deadline of the thread.
+ TForteUInt32 getDeadline(void); //!Get the current deadline of the thread.
+
+ virtual void Main(VOID);
+
+ /*! \brief starts the Thread
+ *
+ * By calling this method the execution in the run()-Method will be started. If necessary additional data
+ * can be created here. Because of inheritance resons the best place for executing create is in this method.
+ * For details ask AZ.
+ */
+ void start(void);
+
+ /*! \brief Resumes a suspended Thread
+ *
+ *
+ */
+ void resumeSelfSuspend(void);
+
+ /*! \brief Stops the execution of the thread
+ *
+ * This function imidiatly stops the execution of the thread (seting m_bAlive to false) and waits till
+ * this is finished.
+ */
+ void end(void);
+
+ /*! \brief Waits for the Thread to finish its execution.
+ *
+ * This function waits till the execution in the thread decides to end the execution. Blocks the caller!!!
+ */
+ void join(void); // Waits
+ protected:
+ /*! \brief Suspends the thread.
+ *
+ * Suspends the execution of the thread until resumeSelfSuspend(), end(), or join() is called.
+ */
+ void selfSuspend(void);
+
+ private:
+ /*! \brief Abstract method for the code to execute in the thread.
+ *
+ * This thread class has to provide means that the code a inheriting class will add to the run()-method will
+ * be executed in a seperated thread regarding the creator of the CThread class.
+ *
+ * The inheriting class has to fullfill the folloing rules when using the run method:
+ * - To end the thread execution simple leave the run()-method
+ * - In order to allow the deletion and stopping of the thread add frequent checks to isAlive and end the
+ * execution if isAlive() returns false.
+ *
+ * \return true if thread execution ended successfull
+ */
+ virtual void run() = 0;
+
+ /*! \brief Destroies the thread
+ *
+ * This function destroies all the data structures created in the creation phase. All used memory is freed.
+ */
+ bool destroy(void);
+
+ /*! \brief Flag that indicates if the Thread is alive.
+ *
+ * This flag has two main purposes:
+ * -# indicate for other classes if the thread is still executing
+ * -# use in the run()-method to check if the thread is still allowed to execute (e.g. while(isAlive()) ).
+ * This is important for stopping and destroying threads.
+ */
+ bool m_bAlive;
+
+ TForteUInt32 m_nDeadline; //!deadline the thread needs to be finish its exectuion. 0 means unconstraint.
+
+};
+
+#endif /*THREAD_H_*/
+
diff --git a/src/arch/be_m1/vxworkstimeha.cpp b/src/arch/be_m1/vxworkstimeha.cpp
new file mode 100644
index 000000000..98836f050
--- /dev/null
+++ b/src/arch/be_m1/vxworkstimeha.cpp
@@ -0,0 +1,56 @@
+/*******************************************************************************
+ * Copyright (c) 2012, 2013 ACIN and fortiss GmbH
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#include
+#include "vxworkstimeha.h"
+#include "../../core/devexec.h"
+#include
+
+
+void CTimerHandler::createTimerHandler(void){
+ if(0 == sm_poFORTETimer)
+ sm_poFORTETimer = new CPCTimerHandler();
+}
+
+CPCTimerHandler::CPCTimerHandler(){
+}
+
+CPCTimerHandler::~CPCTimerHandler(){
+ std::cout << "~CPCTimerHandler()" << std::endl;
+ disableHandler();
+}
+
+void CPCTimerHandler::run(){
+ struct timespec stReq;
+ stReq.tv_sec = 0;
+ stReq.tv_nsec = (1000000 / getTicksPerSecond()) * 1000;
+
+ while(isAlive()){
+ nanosleep(&stReq, NULL);
+ nextTick();
+ }
+}
+
+void CPCTimerHandler::enableHandler(void){
+ start();
+}
+
+void CPCTimerHandler::disableHandler(void){
+ end();
+}
+
+void CPCTimerHandler::setPriority(int pa_nPriority){
+ //TODO think on hwo to handle this.
+}
+
+int CPCTimerHandler::getPriority(void) const{
+ //TODO think on hwo to handle this.
+ return 1;
+}
diff --git a/src/arch/be_m1/vxworkstimeha.h b/src/arch/be_m1/vxworkstimeha.h
new file mode 100644
index 000000000..f79480f27
--- /dev/null
+++ b/src/arch/be_m1/vxworkstimeha.h
@@ -0,0 +1,55 @@
+/*******************************************************************************
+ * Copyright (c) 2012 ACIN
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#ifndef _PCTIMEHA_H_
+#define _PCTIMEHA_H_
+
+#include "thread.h"
+#include "../timerha.h"
+
+/*! \ingroup bem1_hal
+ *\ingroup EXTEVHAND
+ *\brief the timer handler for the Bachmann electronic M1 architecture.
+ */
+class CPCTimerHandler : public CTimerHandler, private CThread{
+ public:
+ virtual ~CPCTimerHandler();
+
+ virtual void run();
+
+ /*!\brief Enables this event source
+ *
+ */
+ virtual void enableHandler(void);
+
+ /*!\brief Disable this event source
+ */
+ virtual void disableHandler(void);
+
+ /*!\brief Sets the priority of the event source
+ *
+ * \param pa_nPriority new priority of the event source
+ */
+ virtual void setPriority(int pa_nPriority);
+
+ /*!\brief Get the current priority of the event source
+ *
+ * \return current priority
+ */
+ virtual int getPriority(void) const;
+
+ private:
+ CPCTimerHandler();
+
+ friend class CTimerHandler;
+
+};
+
+#endif /*PCTIMEHA_H_*/
diff --git a/src/arch/bsdsocketinterf.cpp b/src/arch/bsdsocketinterf.cpp
new file mode 100644
index 000000000..64dfc0cc2
--- /dev/null
+++ b/src/arch/bsdsocketinterf.cpp
@@ -0,0 +1,255 @@
+/*******************************************************************************
+ * Copyright (c) 2010 - 2015 ACIN, Profactor GmbH, AIT, fortiss GmbH
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl, Ingo Hegny, Gerhard Ebenhofer, Thomas Strasser
+ * - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#include //needs to be first pulls in the platform specific includes
+#include "bsdsocketinterf.h"
+#include "devlog.h"
+#include
+
+void CBSDSocketInterface::closeSocket(TSocketDescriptor pa_nSockD){
+#if defined(WIN32) || defined(NET_OS)
+ closesocket(pa_nSockD);
+#else
+ close(pa_nSockD);
+#endif
+}
+
+CBSDSocketInterface::TSocketDescriptor CBSDSocketInterface::openTCPServerConnection(
+ char *pa_acIPAddr, unsigned short pa_nPort){
+ TSocketDescriptor nRetVal = -1;
+
+ DEVLOG_INFO("CBSDSocketInterface: Opening TCP-Server connection at: %s:%d\n", pa_acIPAddr, pa_nPort);
+
+ TSocketDescriptor nSocket = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
+
+ if(-1 != nSocket){
+ struct sockaddr_in stSockAddr;
+ memset(&(stSockAddr), '\0', sizeof(sockaddr_in));
+ stSockAddr.sin_family = AF_INET;
+ stSockAddr.sin_port = htons(pa_nPort);
+ stSockAddr.sin_addr.s_addr = htonl(INADDR_ANY );
+
+ int nOptVal = 1;
+ if (setsockopt(nSocket, SOL_SOCKET, SO_REUSEADDR, (char *)&nOptVal, sizeof(nOptVal)) == -1){
+ DEVLOG_ERROR("CBSDSocketInterface: could not set socket option SO_REUSEADDR: %s\n", strerror(errno));
+ }
+
+ if(0 == bind(nSocket, (struct sockaddr *) &stSockAddr, sizeof(struct sockaddr))){
+ if(-1 == listen(nSocket, 1)){ // for the classic IEC 61499 server only one connection at the same time is accepted TODO mayb make this adjustable for future extensions
+ DEVLOG_ERROR("CBSDSocketInterface: listen() failed: %s\n", strerror(errno));
+ }
+ else{
+ nRetVal = nSocket;
+ }
+ }
+ else{
+ DEVLOG_ERROR("CBSDSocketInterface: bind() failed: %s\n", strerror(errno));
+ }
+ }
+ else{
+ DEVLOG_ERROR("CBSDSocketInterface: Couldn't create socket: %s\n", strerror(errno));
+ }
+ return nRetVal;
+}
+
+CBSDSocketInterface::TSocketDescriptor CBSDSocketInterface::openTCPClientConnection(
+ char *pa_acIPAddr, unsigned short pa_nPort){
+ TSocketDescriptor nRetVal = -1;
+ TSocketDescriptor nSocket = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
+
+ DEVLOG_INFO("CBSDSocketInterface: Opening TCP-Client connection at: %s:%d\n", pa_acIPAddr, pa_nPort);
+
+ if(-1 != nSocket){
+ struct sockaddr_in stSockAddr;
+ stSockAddr.sin_family = AF_INET;
+ stSockAddr.sin_port = htons(pa_nPort);
+ stSockAddr.sin_addr.s_addr = inet_addr(pa_acIPAddr);
+ memset(&(stSockAddr.sin_zero), '\0', sizeof(stSockAddr.sin_zero));
+
+ if(-1 == connect(nSocket, (struct sockaddr *) &stSockAddr, sizeof(struct sockaddr))){
+ DEVLOG_ERROR("CBSDSocketInterface: connect() failed: %s\n", strerror(errno));
+ }
+ else{
+ nRetVal = nSocket;
+ }
+ }
+ else{
+ DEVLOG_ERROR("CBSDSocketInterface: Couldn't create socket: %s\n", strerror(errno));
+ }
+ return nRetVal;
+}
+
+CBSDSocketInterface::TSocketDescriptor CBSDSocketInterface::acceptTCPConnection(
+ TSocketDescriptor pa_nListeningSockD){
+ struct sockaddr client_addr;
+ int sin_size = sizeof(struct sockaddr);
+ TSocketDescriptor nRetVal;
+
+#if defined(WIN32) || defined(NET_OS) || defined (VXWORKS)
+ nRetVal = accept(pa_nListeningSockD, &client_addr, &sin_size);
+#else
+ nRetVal = accept(pa_nListeningSockD, &client_addr, (socklen_t*) &sin_size);
+#endif
+ return nRetVal;
+}
+
+int CBSDSocketInterface::sendDataOnTCP(TSocketDescriptor pa_nSockD, char* pa_pcData,
+ unsigned int pa_unSize){
+ // This function sends all data in the buffer before it returns!
+ int nToSend = pa_unSize;
+ int nRetVal = 0;
+
+ while(0 < nToSend){
+ //TODO: check if open connection (socket might be closed by peer)
+ nRetVal = static_cast(send(pa_nSockD, pa_pcData, nToSend, 0));
+ if(nRetVal <= 0){
+ DEVLOG_ERROR("TCP-Socket Send failed: %s\n", strerror(errno));
+ break;
+ }
+ nToSend -= nRetVal;
+ pa_pcData += nRetVal;
+ }
+ return nRetVal;
+}
+
+int CBSDSocketInterface::receiveDataFromTCP(TSocketDescriptor pa_nSockD, char* pa_pcData,
+ unsigned int pa_unBufSize){
+ int nRetVal;
+ do{
+ nRetVal = static_cast(recv(pa_nSockD, pa_pcData, pa_unBufSize, 0));
+#ifdef WIN32
+ }while((-1 == nRetVal) && (WSAEINTR == h_errno)); // recv got interrupt / recieving again
+#else
+ } while((-1 == nRetVal) && (EINTR == errno)); // recv got interrupt / recieving again
+#endif
+ if(nRetVal == -1){
+#ifdef WIN32
+ DEVLOG_ERROR("CBSDSocketInterface: TCP-Socket recv() failed: %d\n", WSAGetLastError());
+ if(WSAECONNRESET == WSAGetLastError()){
+ nRetVal = 0; //inform higher levels that the peer closed connection
+ }
+#else
+ DEVLOG_ERROR("CBSDSocketInterface: TCP-Socket recv() failed: %s\n", strerror(errno));
+#endif
+ }
+ return nRetVal;
+}
+
+CBSDSocketInterface::TSocketDescriptor CBSDSocketInterface::openUDPSendPort(char *pa_acIPAddr,
+ unsigned short pa_nPort, TUDPDestAddr *m_ptDestAddr){
+ DEVLOG_INFO("CBSDSocketInterface: Opening UDP sending connection at: %s:%d\n", pa_acIPAddr, pa_nPort);
+ TSocketDescriptor nRetVal;
+
+ nRetVal = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
+
+ if(-1 != nRetVal){
+ m_ptDestAddr->sin_family = AF_INET;
+ m_ptDestAddr->sin_port = htons(pa_nPort);
+ m_ptDestAddr->sin_addr.s_addr = inet_addr(pa_acIPAddr);
+ memset(&(m_ptDestAddr->sin_zero), '\0', sizeof(m_ptDestAddr->sin_zero));
+
+#ifdef NET_OS
+ /* following is typedef void TM_fAR * in treck/include/trsocket.h */
+ int nIfCount;
+ int nRunner = 0;
+ unsigned long nLocalInAddr;
+ ttUserInterface *pIfList;
+ ttUserInterface stInterfaceHandle; /* gets recast as above */
+
+ /*get interfaces */
+ pIfList = tfGetInterfaceList(&nIfCount);
+ while (nIfCount--){
+ stInterfaceHandle = pIfList[nRunner++];
+ if (tfGetIpAddress(stInterfaceHandle, &nLocalInAddr, 0) == 0){ //get IPv4 Address of interface
+ /* bind socket to all available IPv4 addresses for multicast */
+ setsockopt (nRetVal, IPPROTO_IP, IP_MULTICAST_IF, (char *) &nLocalInAddr, sizeof (nLocalInAddr));
+ }
+ }
+#endif
+
+ }
+ return nRetVal;
+}
+
+CBSDSocketInterface::TSocketDescriptor CBSDSocketInterface::openUDPReceivePort(char *pa_acIPAddr,
+ unsigned short pa_nPort){
+ DEVLOG_INFO("CBSDSocketInterface: Opening UDP receiving connection at: %s:%d\n", pa_acIPAddr, pa_nPort);
+ TSocketDescriptor nRetVal = -1;
+ TSocketDescriptor nSocket = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
+
+ if(-1 != nSocket){
+ int nReuseAddrVal = 1;
+ if(0
+ <= setsockopt(nSocket, SOL_SOCKET, SO_REUSEADDR, (char *) &nReuseAddrVal, sizeof(nReuseAddrVal))){
+ struct sockaddr_in stSockAddr;
+ stSockAddr.sin_family = AF_INET;
+ stSockAddr.sin_port = htons(pa_nPort);
+ stSockAddr.sin_addr.s_addr = htonl(INADDR_ANY);
+ memset(&(stSockAddr.sin_zero), '\0', sizeof(stSockAddr.sin_zero));
+ if(0 == bind(nSocket, (struct sockaddr *) &stSockAddr, sizeof(struct sockaddr))){
+ // setting up multicast group
+ struct ip_mreq stMReq;
+ stMReq.imr_multiaddr.s_addr = inet_addr(pa_acIPAddr);
+ stMReq.imr_interface.s_addr = htonl(INADDR_ANY);
+ setsockopt(nSocket, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char*) &stMReq, sizeof(stMReq));
+ //if this fails we may have given a non multicasting addr. For now we accept this. May need to be changed in the future.
+
+ nRetVal = nSocket;
+ }
+ else{
+ DEVLOG_ERROR("CBSDSocketInterface: bind() failed: %s\n", strerror(errno));
+ }
+ }
+ else{
+ DEVLOG_ERROR("CBSDSocketInterface: setsockopt(SO_REUSEADDR) failed: %s\n", strerror(errno));
+ }
+ }
+ else{
+ DEVLOG_ERROR("CBSDSocketInterface: Couldn't create socket: %s\n", strerror(errno));
+ }
+ return nRetVal;
+}
+
+int CBSDSocketInterface::sendDataOnUDP(TSocketDescriptor pa_nSockD, TUDPDestAddr *pa_ptDestAddr,
+ char* pa_pcData, unsigned int pa_unSize){
+ // This function sends all data in the buffer before it returns!
+ int nToSend = pa_unSize;
+ int nRetVal = 0;
+
+ while(0 < nToSend){
+ //TODO: check if open connection (socket might be closed by peer)
+ nRetVal = static_cast(
+ sendto(pa_nSockD, pa_pcData, nToSend, 0, (struct sockaddr *) pa_ptDestAddr, sizeof(struct sockaddr)));
+ if(nRetVal <= 0){
+ DEVLOG_ERROR("CBSDSocketInterface: UDP-Socket Send failed: %s\n", strerror(errno));
+ break;
+ }
+ nToSend -= nRetVal;
+ pa_pcData += nRetVal;
+ }
+ return nRetVal;
+}
+
+int CBSDSocketInterface::receiveDataFromUDP(TSocketDescriptor pa_nSockD, char* pa_pcData,
+ unsigned int pa_unBufSize){
+ int nRetVal;
+ do{
+ nRetVal = static_cast(recvfrom(pa_nSockD, pa_pcData, pa_unBufSize, 0, 0, 0));
+#ifdef WIN32
+ }while((-1 == nRetVal) && (WSAEINTR == h_errno)); // recv got interrupt / recieving again
+#else
+ } while((-1 == nRetVal) && (EINTR == errno)); // recv got interrupt / recieving again
+#endif
+ if(nRetVal == -1){ //
+ DEVLOG_ERROR("CBSDSocketInterface: UDP-Socket recvfrom() failed: %s\n", strerror(errno));
+ }
+ return nRetVal;
+}
diff --git a/src/arch/bsdsocketinterf.h b/src/arch/bsdsocketinterf.h
new file mode 100644
index 000000000..09212c7a9
--- /dev/null
+++ b/src/arch/bsdsocketinterf.h
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * Copyright (c) 2010 - 2014 ACIN, fortiss GmbH
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl, Ingo Hegny - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#ifndef BSDSOCKETINTERF_H_
+#define BSDSOCKETINTERF_H_
+
+
+class CBSDSocketInterface{
+ public:
+ typedef int TSocketDescriptor;
+ typedef struct sockaddr_in TUDPDestAddr;
+
+ static void closeSocket(TSocketDescriptor pa_nSockD);
+ static TSocketDescriptor openTCPServerConnection(char *pa_acIPAddr, unsigned short pa_nPort);
+ static TSocketDescriptor openTCPClientConnection(char *pa_acIPAddr, unsigned short pa_nPort);
+ static TSocketDescriptor acceptTCPConnection(TSocketDescriptor pa_nListeningSockD);
+ static int sendDataOnTCP(TSocketDescriptor pa_nSockD, char* pa_pcData, unsigned int pa_unSize);
+ static int receiveDataFromTCP(TSocketDescriptor pa_nSockD, char* pa_pcData, unsigned int pa_unBufSize);
+
+ static TSocketDescriptor openUDPSendPort(char *pa_acIPAddr, unsigned short pa_nPort, TUDPDestAddr *m_ptDestAddr);
+ static TSocketDescriptor openUDPReceivePort(char *pa_acIPAddr, unsigned short pa_nPort);
+ static int sendDataOnUDP(TSocketDescriptor pa_nSockD, TUDPDestAddr *pa_ptDestAddr, char* pa_pcData, unsigned int pa_unSize);
+ static int receiveDataFromUDP(TSocketDescriptor pa_nSockD, char* pa_pcData, unsigned int pa_unBufSize);
+
+ private:
+ CBSDSocketInterface(); //this function is not implemented as we don't want instances of this class
+};
+
+#endif /* BSDSOCKETINTERF_H_ */
diff --git a/src/arch/datatype.h b/src/arch/datatype.h
new file mode 100644
index 000000000..bdabc3972
--- /dev/null
+++ b/src/arch/datatype.h
@@ -0,0 +1,56 @@
+/*******************************************************************************
+ * Copyright (c) 2005 - 2015 ACIN, Profactor GmbH, fortiss GmbH
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Rene Smodic, Alois Zoitl, Thomas Strasser, Martin Melik Merkumians,
+ * Ingo Hegny
+ * - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#ifndef _DATATYPES_H_
+#define _DATATYPES_H_
+
+
+// this define is required to get the limit macros
+#define __STDC_LIMIT_MACROS
+
+#include
+
+/*! \ingroup FORTE-HAL
+ * \brief This are the device-independent data types used by FORTE.
+ */
+
+/***************************************************************************
+ type definitions
+ ***************************************************************************/
+
+typedef uint8_t TForteByte; /**< 8 bit unsigned */
+typedef uint16_t TForteWord; /**< 16 bit unsigned */
+typedef uint32_t TForteDWord; /**< 32 bit unsigned */
+typedef uint64_t TForteLWord; /**< 64 bit unsigned */
+
+typedef int8_t TForteInt8; /**< 8 bit signed */
+typedef int16_t TForteInt16; /**< 16 bit signed */
+typedef int32_t TForteInt32; /**< 32 bit signed */
+typedef int64_t TForteInt64; /**< 64 bit signed */
+
+typedef uint8_t TForteUInt8; /**< 8 bit unsigned */
+typedef uint16_t TForteUInt16; /**< 16 bit unsigned */
+typedef uint32_t TForteUInt32; /**< 32 bit unsigned */
+typedef uint64_t TForteUInt64; /**< 64 bit unsigned */
+
+typedef float TForteFloat; /**< single precision IEEE float (32 Bit) */
+typedef double TForteDFloat; /**< double precision IEEE float (64 bit) */
+
+const unsigned int cg_nIdentifierLength = 32; //!
+#include
+#include
+
+#ifndef NOLOG
+
+static const char* cg_acLogLevel[] = {"INFO", "WARNING", "ERROR", "DEBUG", "TRACE" };
+
+//this define allows to provide an own log handler (see LMS for an example of this)
+#ifndef FORTE_EXTERNAL_LOG_HANDLER
+
+/*! \brief print the given log message with the error level and a time stamp
+ *
+ * @param pa_ecLevel the message's log level
+ * @param pa_acMessage the message to log
+ */
+void printLogMessage(E_MsgLevel pa_eLevel, const char *pa_acMessage);
+
+static const int scm_nMsgBufSize = 300;
+static char sm_acMsgBuf[scm_nMsgBufSize]; //!getForteTime().m_nUpperValue, CTimerHandler::sm_poFORTETimer->getForteTime().m_nLowerValue);
+ }
+ else{
+ fprintf(stderr,": T#notime: ");
+ }
+ fprintf(stderr, pa_acMessage);
+}
+
+#endif
+#endif
diff --git a/src/arch/devlog.h b/src/arch/devlog.h
new file mode 100644
index 000000000..b58e939bb
--- /dev/null
+++ b/src/arch/devlog.h
@@ -0,0 +1,88 @@
+/*******************************************************************************
+ * Copyright (c) 2005 - 2013 ACIN, Profactor GmbH, fortiss GmbH
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Rene Smodic, Thomas Strasser, Alois Zoitl, Ingo Hegny, Monika Wenger
+ * - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#ifndef _DEVLOG_H_
+#define _DEVLOG_H_
+
+/*!\ingroup FORTE_HAL
+ * \brief CDeviceLog is the entity that logs messages created by the FORTE Runtime system.
+ * They can be printed to a console or archived somewhere (This is implementation dependent).
+ */
+#include "datatype.h"
+#include "../core/utils/singlet.h"
+#include
+
+enum E_MsgLevel {E_INFO, E_WARNING, E_ERROR, E_DEBUG, E_TRACE};
+
+// possible loglevels: NOLOG, LOGERROR, LOGWARNING, LOGINFO, LOGDEBUG
+/* Meaning:
+ * LOGERROR: log only error messages
+ * LOGWARNING: log error and warning messages
+ * LOGINFO: log error, warning, and info messages
+ * LOGDEBUG: log all messages: error, warning, info, and debug
+ * NOLOG: log no messages
+ */
+
+#if !(defined(NOLOG) || defined(LOGERROR) || defined(LOGWARNING) || defined(LOGINFO) || defined(LOGDEBUG))
+/* Set default loglevel */
+# define LOGDEBUG
+#endif
+
+#ifdef LOGDEBUG
+ #define DEVLOG_ERROR(...) logMessage(E_ERROR, __VA_ARGS__)
+ #define DEVLOG_WARNING(...) logMessage(E_WARNING, __VA_ARGS__)
+ #define DEVLOG_INFO(...) logMessage(E_INFO, __VA_ARGS__)
+ #define DEVLOG_DEBUG(...) logMessage(E_DEBUG, __VA_ARGS__)
+#endif
+
+#ifdef LOGERROR
+ #define DEVLOG_ERROR(...) logMessage(E_ERROR, __VA_ARGS__)
+ #define DEVLOG_WARNING(...)
+ #define DEVLOG_INFO(...)
+ #define DEVLOG_DEBUG(...)
+#endif
+
+#ifdef LOGWARNING
+ #define DEVLOG_ERROR(...) logMessage(E_ERROR, __VA_ARGS__)
+ #define DEVLOG_WARNING(...) logMessage(E_WARNING, __VA_ARGS__)
+ #define DEVLOG_INFO(...)
+ #define DEVLOG_DEBUG(...)
+#endif
+
+#ifdef LOGINFO
+ #define DEVLOG_ERROR(...) logMessage(E_ERROR, __VA_ARGS__)
+ #define DEVLOG_WARNING(...) logMessage(E_WARNING, __VA_ARGS__)
+ #define DEVLOG_INFO(...) logMessage(E_INFO, __VA_ARGS__)
+ #define DEVLOG_DEBUG(...)
+#endif
+
+#ifdef NOLOG
+ #define DEVLOG_INFO(...)
+ #define DEVLOG_WARNING(...)
+ #define DEVLOG_ERROR(...)
+ #define DEVLOG_DEBUG(...)
+#endif
+
+#if (defined(FORTE_TRACE_EVENTS) && !defined(NOLOG))
+ #define FORTE_TRACE(...) logMessage(E_TRACE, __VA_ARGS__)
+#else
+ #define FORTE_TRACE(...)
+#endif
+
+#ifndef NOLOG
+
+/*! \brief Adds an Entry to the LogBook
+ *
+ */
+ void logMessage(E_MsgLevel pa_eLevel, const char *pa_acMessage, ...);
+#endif
+
+#endif //_DEVLOG_H_
diff --git a/src/arch/ecos/CMakeLists.txt b/src/arch/ecos/CMakeLists.txt
new file mode 100644
index 000000000..a3319169a
--- /dev/null
+++ b/src/arch/ecos/CMakeLists.txt
@@ -0,0 +1,14 @@
+#*******************************************************************************
+# * Copyright (c) 2010 ACIN
+# * All rights reserved. This program and the accompanying materials
+# * are made available under the terms of the Eclipse Public License v1.0
+# * which accompanies this distribution, and is available at
+# * http://www.eclipse.org/legal/epl-v10.html
+# *
+# * Contributors:
+# * Alois Zoitl - initial API and implementation and/or initial documentation
+# *******************************************************************************/
+
+add_subdirectory(phycoreat91)
+
+#as LMS is added differently it is not put here as sub directory
diff --git a/src/arch/ecos/ecoscppinit.cpp b/src/arch/ecos/ecoscppinit.cpp
new file mode 100644
index 000000000..c2d99278b
--- /dev/null
+++ b/src/arch/ecos/ecoscppinit.cpp
@@ -0,0 +1,20 @@
+/*******************************************************************************
+ * Copyright (c) 2010 - 2011 ACIN
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#include
+
+//current tests have shown that this works only if it is in the main.cpp file
+//I don't know why. The best is to copy or include it into your specific main file
+
+//Workaround for an ecos problem
+extern "C" void
+__cxa_pure_virtual(void) {
+ //TODO maybe add some exception handling reporting here
+}
diff --git a/src/arch/ecos/ecostiha.cpp b/src/arch/ecos/ecostiha.cpp
new file mode 100644
index 000000000..f5f063957
--- /dev/null
+++ b/src/arch/ecos/ecostiha.cpp
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * Copyright (c) 2006 - 2013 ACIN, fortiss GmbH
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#include
+#include "ecostiha.h"
+#include "../../core/devexec.h"
+
+cyg_sem_t CECOSTimerHandler::m_stSemaphore;
+
+void CTimerHandler::createTimerHandler(void){
+ if(0 == sm_poFORTETimer){
+ sm_poFORTETimer = new CECOSTimerHandler();
+ static_cast(sm_poFORTETimer)->start();
+ }
+}
+
+CECOSTimerHandler::CECOSTimerHandler(){
+ cyg_semaphore_init(&m_stSemaphore, 0);
+
+ m_stSystemclockHandle = cyg_real_time_clock();
+ cyg_clock_to_counter(m_stSystemclockHandle, &m_stCounterHandle);
+
+ cyg_alarm_create(m_stCounterHandle, timerHandlerFunc, (cyg_addrword_t) 0, &m_stAlarmHandle, &m_stAlarm);
+}
+
+CECOSTimerHandler::~CECOSTimerHandler(){
+ cyg_semaphore_destroy(&m_stSemaphore);
+}
+
+void CECOSTimerHandler::enableHandler(void){
+ cyg_alarm_initialize(m_stAlarmHandle, cyg_current_time() + 1, 1);
+}
+
+void CECOSTimerHandler::disableHandler(void){
+ cyg_alarm_disable(m_stAlarmHandle);
+}
+
+void CECOSTimerHandler::setPriority(int ){
+
+}
+
+int CECOSTimerHandler::getPriority(void) const{
+ return 0;
+}
+
+void CECOSTimerHandler::run(void){
+ CECOSThread::setPriority(0); //we want to be a very important thread
+ while(isAlive()){
+ cyg_semaphore_wait(&m_stSemaphore);
+ //FIXME add compensation code for timer activation jitter similar to the code in the posix architecture
+ sm_poFORTETimer->nextTick();
+ }
+}
+
diff --git a/src/arch/ecos/ecostiha.h b/src/arch/ecos/ecostiha.h
new file mode 100644
index 000000000..dde483eda
--- /dev/null
+++ b/src/arch/ecos/ecostiha.h
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * Copyright (c) 2006 - 2011 ACIN
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#ifndef _ECOSTIMEHA_H_
+#define _ECOSTIMEHA_H_
+
+#include
+#include "../timerha.h"
+#include "thread.h"
+
+/*! \brief External event handler for the eCos Timer.
+ * \ingroup ECOS-HAL
+ *
+ */
+class CECOSTimerHandler : public CTimerHandler, private CThread{
+ public:
+ virtual ~CECOSTimerHandler();
+
+ /*!\brief Enables this event source
+ *
+ */
+ virtual void enableHandler(void);
+ /*!\brief Disable this event source
+ */
+ virtual void disableHandler(void);
+ /*!\brief Sets the priority of the event source
+ *
+ * \param pa_nPriority new priority of the event source
+ */
+ virtual void setPriority(int pa_nPriority);
+ /*!\brief Get the current priority of the event source
+ *
+ * \return current priority
+ */
+ virtual int getPriority(void) const;
+
+ private:
+
+ static cyg_sem_t m_stSemaphore;
+
+ /*!\brief callback function for the system timer
+ */
+ static void timerHandlerFunc(cyg_handle_t , cyg_addrword_t ){
+ cyg_semaphore_post(&m_stSemaphore);
+ }
+
+ CECOSTimerHandler();
+ virtual void run(void);
+
+ cyg_handle_t m_stAlarmHandle;
+ cyg_handle_t m_stCounterHandle, m_stSystemclockHandle;
+ cyg_alarm m_stAlarm;
+
+ friend class CTimerHandler;
+};
+
+#endif /*_ECOSTIMEHA_H_*/
diff --git a/src/arch/ecos/fortealloc.h b/src/arch/ecos/fortealloc.h
new file mode 100644
index 000000000..11c05a9b0
--- /dev/null
+++ b/src/arch/ecos/fortealloc.h
@@ -0,0 +1,17 @@
+/*******************************************************************************
+ * Copyright (c) 2010 ACIN
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#ifndef FORTEALLOC_H_
+#define FORTEALLOC_H_
+
+//on ecos environments we are typically happy with the generic alloc implementation based on malloc and free
+#include "../genfortealloc.h"
+
+#endif /* FORTEALLOC_H_ */
diff --git a/src/arch/ecos/phycoreat91/CMakeLists.txt b/src/arch/ecos/phycoreat91/CMakeLists.txt
new file mode 100644
index 000000000..22686a134
--- /dev/null
+++ b/src/arch/ecos/phycoreat91/CMakeLists.txt
@@ -0,0 +1,41 @@
+#*******************************************************************************
+# * Copyright (c) 2010 -2105 ACIN, fortiss GmbH
+# * All rights reserved. This program and the accompanying materials
+# * are made available under the terms of the Eclipse Public License v1.0
+# * which accompanies this distribution, and is available at
+# * http://www.eclipse.org/legal/epl-v10.html
+# *
+# * Contributors:
+# * Alois Zoitl - initial API and implementation and/or initial documentation
+# *******************************************************************************/
+
+SET(SOURCE_GROUP ${SOURCE_GROUP}\\phycoreat91)
+
+forte_add_architecture("Phycore AT91")
+
+if("${FORTE_ARCHITECTURE}" STREQUAL "Phycore AT91")
+
+ forte_add_include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..)
+
+ forte_add_sourcefile_hcpp(../thread ../ecostiha ../sync)
+ forte_add_sourcefile_cpp(phycoreAT91main.cpp)
+
+ if(FORTE_COM_ETH)
+ forte_add_sourcefile_hcpp( ../../fdselecthand ../../bsdsocketinterf)
+ forte_add_sourcefile_h(../gensockhand.h)
+ forte_add_sourcefile_h(../sockhand.h)
+ endif(FORTE_COM_ETH)
+
+ forte_add_include_directories(../${CMAKE_CURRENT_SOURCE_DIR})
+
+ forte_add_definition("-Wpointer-arith -Wundef -Woverloaded-virtual -Wno-write-strings")
+ forte_add_definition("-W -Wall -Wextra -D_KERNEL -D__ECOS -DFORTE_LITTLE_ENDIAN")
+ forte_add_definition("-mcpu=arm7tdmi -msoft-float -mno-thumb-interwork -g -O2")
+ forte_add_definition("-ffunction-sections -fdata-sections -fno-threadsafe-statics -fno-rtti -fno-exceptions")
+
+
+ forte_add_link_flags("-mcpu=arm7tdmi -msoft-float -W,--gc-sections -g -nostartfiles -nostdlib -fno-threadsafe-statics -mno-thumb-interwork -Wl,-static -Wl,-M -Wl,-Map -Wl,forte.map -Wl,-cref")
+
+
+
+endif()
\ No newline at end of file
diff --git a/src/arch/ecos/phycoreat91/phycoreAT91main.cpp b/src/arch/ecos/phycoreat91/phycoreAT91main.cpp
new file mode 100644
index 000000000..6d7fcfbc4
--- /dev/null
+++ b/src/arch/ecos/phycoreat91/phycoreAT91main.cpp
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2007, 2010 ACIN
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#include
+#include
+#include
+#include
+#include // IO macros
+
+externC void
+cyg_user_start( void );
+
+void cyg_user_start(void){
+ RMT_DEV *dev = new RMT_DEV; //otherwise we would loose the var if it is only on the stack
+ dev->startDevice();
+}
+
+//get the stuff that fixes some ecos cpp problems which have to be near the main
+#include "../ecoscppinit.cpp"
diff --git a/src/arch/ecos/sockhand.h b/src/arch/ecos/sockhand.h
new file mode 100644
index 000000000..8d4631f94
--- /dev/null
+++ b/src/arch/ecos/sockhand.h
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * Copyright (c) 2010 - 2015 ACIN, fortiss GmbH
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#ifndef SOCKHAND_H_
+#define SOCKHAND_H_
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+//these include needs to be last
+#include "../fdselecthand.h"
+#include "../bsdsocketinterf.h"
+#include "../gensockhand.h"
+
+typedef CGenericIPComSocketHandler CIPComSocketHandler;
+
+#endif /* SOCKHAND_H_ */
diff --git a/src/arch/ecos/sync.cpp b/src/arch/ecos/sync.cpp
new file mode 100644
index 000000000..af7582cd6
--- /dev/null
+++ b/src/arch/ecos/sync.cpp
@@ -0,0 +1,20 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2007 ACIN
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#include "sync.h"
+
+CECOSSyncObject::CECOSSyncObject(){
+ cyg_mutex_init(&m_oMutexHandle);
+ cyg_mutex_set_protocol(&m_oMutexHandle, CYG_MUTEX_NONE);
+}
+
+CECOSSyncObject::~CECOSSyncObject(){
+ cyg_mutex_destroy(&m_oMutexHandle);
+}
diff --git a/src/arch/ecos/sync.h b/src/arch/ecos/sync.h
new file mode 100644
index 000000000..91b8767ce
--- /dev/null
+++ b/src/arch/ecos/sync.h
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2007 ACIN
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#ifndef _SYNC_H_
+#define _SYNC_H_
+
+#include
+
+#define CSyncObject CECOSSyncObject //allows that doxygen can generate better documenation
+
+/*! \ingroup ECOS-HAL
+ * \brief The sync object implementation for eCos.
+ *
+ * In the eCos version a mutex is used for the sync object.
+ */
+class CECOSSyncObject{
+ private:
+ protected:
+ //! The posix thread mutex handle of the operating system.
+ cyg_mutex_t m_oMutexHandle;
+ public:
+ CECOSSyncObject();
+ ~CECOSSyncObject();
+ /*!\brief Lock the resource coming after the lock command
+ *
+ * This function blocks until it will get the lock for the coming critical section.
+ */
+ void lock(void){
+ cyg_mutex_lock(&m_oMutexHandle);
+ };
+ //!Freee the resource coming after the lock command
+ void unlock(void){
+ cyg_mutex_unlock(&m_oMutexHandle);
+ };
+};
+
+#endif /*SYNC_H_*/
diff --git a/src/arch/ecos/thread.cpp b/src/arch/ecos/thread.cpp
new file mode 100644
index 000000000..955f96990
--- /dev/null
+++ b/src/arch/ecos/thread.cpp
@@ -0,0 +1,112 @@
+/*******************************************************************************
+ * Copyright (c) 2006 - 2014 ACIN, fortiss GmbH
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#include
+#include
+#include "thread.h"
+
+TCECOSThreadPtr CECOSThread::sm_aoThreadList[CECOSThread::scm_nThreadListSize] ={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
+CSyncObject CECOSThread::sm_oThreadListLock;
+
+bool CECOSThread::create(void){
+ // Get new Thread
+ cyg_thread_create(scm_nThreadListSize + 2, //lowest priority in ecos
+ threadFunction, (cyg_addrword_t)(this),
+ "Test Name", m_cStack,
+ m_nStackSize,
+ &m_stHandle,
+ &m_stThread);
+
+//setup the signals for the join implementation
+ return true;
+}
+
+void CECOSThread::threadFunction(cyg_addrword_t data){
+ // Get pointer to CThread object out of void pointer
+ CECOSThread *pThread = (CECOSThread *)(data);
+
+ // if pointer is ok
+ if (pThread){
+ CCriticalRegion criticalRegion(pThread->m_stResLock);
+ pThread->m_bAlive = true;
+ pThread->run();
+ pThread->m_bAlive = false;
+ }
+ cyg_thread_exit();
+}
+
+CECOSThread::CECOSThread(long pa_nStackSize){
+ m_bAlive = false;
+ m_nStackSize = pa_nStackSize;
+ m_cStack = new unsigned char[m_nStackSize];
+ cyg_semaphore_init(&m_stSuspendSem, 0);
+}
+
+CECOSThread::~CECOSThread(){
+ end();
+ cyg_semaphore_destroy(&m_stSuspendSem);
+ delete[] m_cStack;
+}
+
+void CECOSThread::setDeadline(const CIEC_TIME &pa_roVal){
+ int i, ii;
+ CCriticalRegion criticalRegion(sm_oThreadListLock);
+ DEVLOG_DEBUG(">>>>Thread: Set Deadline: %lu\n", pa_roVal.operator TValueType ());
+ m_oDeadLine = pa_roVal;
+ //first of all check if this thread is already in the list and remove it from the list
+ for(i = 0; i < scm_nThreadListSize; i++){
+ if(0 == sm_aoThreadList[i])
+ break;
+ else
+ if(this == sm_aoThreadList[i]){
+ for(ii = i; ii < scm_nThreadListSize - 1; ii++){
+ if(0 == sm_aoThreadList[ii + 1])
+ break;
+ sm_aoThreadList[ii + 1]->setPriority(ii + 2);
+ sm_aoThreadList[ii] = sm_aoThreadList[ii + 1];
+ }
+ break;
+ }
+ }
+
+ if(0 == m_oDeadLine)
+ setPriority(scm_nThreadListSize + 2); // use the lowest user priority
+ else{
+ for(i = 0; i < scm_nThreadListSize; i++){
+ if(0 == sm_aoThreadList[i]){
+ sm_aoThreadList[i] = this;
+ setPriority( i + 2);
+ break;
+ }
+ else
+ if(m_oDeadLine < sm_aoThreadList[i]->getDeadline()){
+ CECOSThread *poRBuf, *poSBuf= sm_aoThreadList[i];
+ sm_aoThreadList[i] = this;
+ setPriority( i + 2);
+ for(ii = i + 1; ii < scm_nThreadListSize; ii++){
+ poSBuf->setPriority(ii + 2);
+ poRBuf = sm_aoThreadList[ii];
+ sm_aoThreadList[ii] = poSBuf;
+ if(0 == poRBuf)
+ break;
+ poSBuf = poRBuf;
+ }
+ break;
+ }
+ }
+ }
+}
+
+void CECOSThread::join(void){
+ if(isAlive()){
+ {CCriticalRegion criticalRegion(m_stResLock); }
+ cyg_thread_delete(m_stHandle);
+ }
+}
diff --git a/src/arch/ecos/thread.h b/src/arch/ecos/thread.h
new file mode 100644
index 000000000..f0f3b2934
--- /dev/null
+++ b/src/arch/ecos/thread.h
@@ -0,0 +1,185 @@
+/*******************************************************************************
+ * Copyright (c) 2006 - 2015 ACIN, fortiss GmbH
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl, Carolyn Oates - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#ifndef _THREAD_H_
+#define _THREAD_H_
+
+#include
+#include "../datatype.h"
+#include "sync.h"
+#include "../devlog.h"
+#include "../../core/datatypes/forte_time.h"
+
+#define CThread CECOSThread //allows that doxygen can generate better documentation
+class CECOSThread;
+
+typedef CECOSThread *TCECOSThreadPtr;
+
+/** \defgroup ECOS-HAL eCos FORTE Hardware Abstraction Layer
+ *\ingroup FORTE-HAL
+ * \brief The FORTE-HAL implementation for the eCos operating system.
+ *
+ *
+ */
+/*! \ingroup ECOS-HAL
+ * \brief This class is a wrapper class the eCos multitasking support
+ */
+class CECOSThread {
+ public:
+ /*! \brief Constructor of the Thread class
+ *
+ * Does all the necessary steps in order to get the thread running with the start()-method
+ * @param pa_nStackSize the Size of the stack the thread is allowed to use. this class will
+ * allocate the stack size in bytes from the heap
+ */
+ CECOSThread(long pa_nStackSize = CYGNUM_HAL_STACK_SIZE_TYPICAL); // may need adjustment for small platforms
+
+ /*! \brief Stops and destroys thread.
+ *
+ * Will stop the execution if running and destroy the thread including all system specific data.
+ */
+ virtual ~CECOSThread();
+
+ /*! \brief Indicates if the thread is allowed to execute.
+ *
+ * This functions checks if the Thread is still executing user code in its run()-method.
+ * \return true if there the run method is active.
+ */
+ bool isAlive(void) const {
+ return m_bAlive;
+ }
+
+ //!Set the deadline of the thread.
+ void setDeadline(const CIEC_TIME &pa_roVal);
+
+ //!Get the current deadline of the thread.
+ const CIEC_TIME &getDeadline(void) const {
+ return m_oDeadLine;
+ }
+
+
+ /*! \brief starts the Thread
+ *
+ * By calling this method the execution in the run()-Method will be started. If necessary additional data
+ * can be created here. Because of inheritance reasons the best place for executing create is in this method.
+ */
+ void start(void){
+ create();
+ cyg_thread_resume(m_stHandle);
+ }
+
+ /*! \brief Resumes a suspended Thread
+ *
+ *
+ */
+ void resumeSelfSuspend(void){
+ cyg_semaphore_post(&m_stSuspendSem);
+ }
+
+ /*! \brief Stops the execution of the thread
+ *
+ * This function imidiatly stops the execution of the thread (seting m_bAlive to false) and waits till
+ * this is finished.
+ */
+ void end(void){
+ m_bAlive = false;
+ resumeSelfSuspend();
+ join();
+ }
+
+ /*! \brief Waits for the Thread to finish its execution.
+ *
+ * This function waits till the execution in the thread decides to end the execution. Blocks the caller!!!
+ */
+ void join(void);
+ protected:
+ /*! \brief Suspends the thread.
+ *
+ * Suspends the execution of the thread until resumeSelfSuspend(), end(), or join() is called.
+ */
+
+ void selfSuspend(void){
+ cyg_semaphore_wait(&m_stSuspendSem);
+ }
+
+ void setPriority(cyg_priority_t pa_nPriority) {
+ DEVLOG_DEBUG(">>>>Thread: Set Priority: %d\n", pa_nPriority);
+ cyg_thread_set_priority(m_stHandle, pa_nPriority);
+ }
+
+ private:
+ /*!\brief Function that is given to the system thread support that should be called for the thread.
+ *
+ * this function will call the run method of the thread instance.
+ */
+ static void threadFunction(cyg_addrword_t data);
+
+ /*! \brief Abstract method for the code to execute in the thread.
+ *
+ * This thread class has to provide means that the code a inheriting class will add to the run()-method will
+ * be executed in a separated thread regarding the creator of the CThread class.
+ *
+ * The inheriting class has to fulfill the following rules when using the run method:
+ * - To end the thread execution simple leave the run()-method
+ * - In order to allow the deletion and stopping of the thread add frequent checks to isAlive and end the
+ * execution if isAlive() returns false.
+ */
+ virtual void run() = 0;
+
+ /*! \brief Creates a new thread.
+ *
+ * With this function all the setup things for a new thread are done. The Thread created is initial
+ * suspended and with the start() method the execution of the code in the run() method is started.
+ */
+ bool create(void);
+
+ /*! \brief Destroys the thread
+ *
+ * This function destroys all the data structures created in the creation phase. All used memory is freed.
+ */
+ bool destroy(void);
+
+
+ static const int scm_nThreadListSize = 27;
+ static TCECOSThreadPtr sm_aoThreadList[scm_nThreadListSize];
+ static CSyncObject sm_oThreadListLock;
+
+ /*! \brief data needed for ecos to identify the thread.
+ */
+ cyg_handle_t m_stHandle;
+ cyg_thread m_stThread;
+ //! used for providing the join function
+ CSyncObject m_stResLock;
+
+ /*! \brief Size of the stack used by this thread.
+ */
+ long m_nStackSize;
+ unsigned char *m_cStack;
+ CIEC_TIME m_oDeadLine;
+ cyg_sem_t m_stSuspendSem; //! Semaphore for implementing the self suspend
+
+
+ /*! \brief Flag that indicates if the Thread is alive.
+ *
+ * This flag has two main purposes:
+ * -# indicate for other classes if the thread is still executing
+ * -# use in the run()-method to check if the thread is still allowed to execute (e.g. while(isAlive()) ).
+ * This is important for stopping and destroying threads.
+ */
+ bool m_bAlive;
+
+ //we don't want that threads can be copied or assigned therefore the copy constructor and assignment operator are declared private
+ //but not implemented
+ CECOSThread(const CECOSThread&);
+ CECOSThread& operator = (const CECOSThread &);
+
+};
+
+#endif /*THREAD_H_*/
diff --git a/src/arch/fdselecthand.cpp b/src/arch/fdselecthand.cpp
new file mode 100644
index 000000000..c4af2bd5c
--- /dev/null
+++ b/src/arch/fdselecthand.cpp
@@ -0,0 +1,165 @@
+/*******************************************************************************
+ * Copyright (c) 2010 - 2014 ACIN, Profactor GmbH, fortiss GmbH
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny
+ * - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#include //needs to be first pulls in the platform specific includes
+#include "fdselecthand.h"
+#include "../core/devexec.h"
+#include "devlog.h"
+#include "../core/cominfra/commfb.h"
+#include
+
+
+DEFINE_SINGLETON(CFDSelectHandler);
+
+CFDSelectHandler::CFDSelectHandler(){
+ m_bConnectionListChanged = false;
+#ifdef WIN32
+ // Windows Socket Startupcode
+ WORD wVersionRequested;
+ WSADATA wsaData;
+ int err;
+
+ /* Use the MAKEWORD(lowbyte, highbyte) macro declared in Windef.h */
+ wVersionRequested = MAKEWORD(2, 2);
+
+ err = WSAStartup(wVersionRequested, &wsaData);
+#endif
+}
+
+CFDSelectHandler::~CFDSelectHandler(){
+ this->end();
+#ifdef WIN32
+ WSACleanup();
+#endif
+}
+
+// single-threaded-network-code
+void CFDSelectHandler::run(void){
+
+ struct timeval tv;
+ fd_set anFDSet;
+ fd_set anFDSetMaster;
+
+ int nHighestFDID = 0;
+ int retval = 0;
+
+ FD_ZERO(&anFDSetMaster);
+
+ while(isAlive()){
+ // TODO: create method to prevent 100ms timeout on reconnection
+ m_oSync.lock();
+ if(m_lstConnectionsList.isEmpty()){
+ m_oSync.unlock();
+ selfSuspend();
+ m_oSync.lock();
+ }
+
+ if(true == m_bConnectionListChanged){
+ nHighestFDID = createFDSet(&anFDSetMaster);
+ }
+ anFDSet = anFDSetMaster;
+ m_oSync.unlock();
+
+ tv.tv_sec = 1; //TODO : To be set!
+ tv.tv_usec = 1000;
+
+ if(0 != nHighestFDID){
+ retval = select(nHighestFDID + 1, &anFDSet, NULL, NULL, &tv);
+ }
+ else{
+ retval = 0;
+ }
+
+ if(retval > 0){
+ m_oSync.lock();
+ TConnectionContainer::Iterator itEnd(m_lstConnectionsList.end());
+ for(TConnectionContainer::Iterator itRunner = m_lstConnectionsList.begin(); itRunner != itEnd;){
+ // need to retrieve the callee as the iterator may get invalid in the recvDat function below in case of connection closing
+ forte::com_infra::CComLayer *comLayer = itRunner->m_poCallee;
+ TFileDescriptor sockDes = itRunner->m_nSockDes;
+ ++itRunner;
+
+ if((0 != FD_ISSET(sockDes, &anFDSet)) && (0 != comLayer)){
+ m_oSync.unlock();
+ if(forte::com_infra::e_Nothing != comLayer->recvData(&sockDes,0)){
+ startNewEventChain(comLayer->getCommFB());
+ }
+ m_oSync.lock();
+ }
+ }
+ m_oSync.unlock();
+ }
+ else{
+ if(retval == 0){
+// printf(".");
+ }
+ else{
+#ifdef WIN32
+ DEVLOG_ERROR("Select failed: %d", WSAGetLastError());
+#else
+ DEVLOG_ERROR("Select failed: %s", strerror(errno));
+#endif
+ }
+ }
+ }
+}
+
+void CFDSelectHandler::addComCallback(TFileDescriptor pa_nFD, forte::com_infra::CComLayer *pa_poComLayer){
+ {
+ CCriticalRegion criticalRegion(m_oSync);
+ TConnContType stNewNode = { pa_nFD, pa_poComLayer };
+ m_lstConnectionsList.push_back(stNewNode);
+ m_bConnectionListChanged = true;
+ }
+ if(!isAlive()){
+ this->start();
+ }
+ resumeSelfSuspend();
+}
+
+void CFDSelectHandler::removeComCallback(TFileDescriptor pa_nFD){
+ CCriticalRegion criticalRegion(m_oSync);
+
+ TConnectionContainer::Iterator itRunner(m_lstConnectionsList.begin());
+ TConnectionContainer::Iterator itRefNode(m_lstConnectionsList.end());
+ TConnectionContainer::Iterator itEnd(m_lstConnectionsList.end());
+
+ while(itRunner != itEnd){
+ if(itRunner->m_nSockDes == pa_nFD){
+ if(itRefNode ==itEnd){
+ m_lstConnectionsList.pop_front();
+ }
+ else{
+ m_lstConnectionsList.eraseAfter(itRefNode);
+ }
+ break;
+ }
+
+ itRefNode = itRunner;
+ ++itRunner;
+ }
+
+ m_bConnectionListChanged = true;
+}
+
+CFDSelectHandler::TFileDescriptor CFDSelectHandler::createFDSet(fd_set *m_panFDSet){
+ TFileDescriptor nRetVal = 0;
+ FD_ZERO(m_panFDSet);
+ TConnectionContainer::Iterator itEnd(m_lstConnectionsList.end());
+ for(TConnectionContainer::Iterator itRunner = m_lstConnectionsList.begin(); itRunner != itEnd; ++itRunner){
+ FD_SET(itRunner->m_nSockDes, m_panFDSet);
+ if(itRunner->m_nSockDes > nRetVal){
+ nRetVal = itRunner->m_nSockDes;
+ }
+ }
+ m_bConnectionListChanged = false;
+ return nRetVal;
+}
diff --git a/src/arch/fdselecthand.h b/src/arch/fdselecthand.h
new file mode 100644
index 000000000..e5bc6fa7a
--- /dev/null
+++ b/src/arch/fdselecthand.h
@@ -0,0 +1,79 @@
+/*******************************************************************************
+ * Copyright (c) 2010 - 2014 ACIN, fortiss GmbH
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl, Patrick Smejkal
+ * - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#ifndef _FDHAND_H_
+#define _FDHAND_H_
+
+#include "../core/fortelist.h"
+#include "../core/extevhan.h"
+#include "../core/cominfra/comlayer.h"
+#include "../core/utils/singlet.h"
+#include
+#include
+
+#if !defined(WIN32) && !defined(NET_OS) && !defined(VXWORKS)
+#include
+#endif
+
+/*!\brief An external event handler for file descriptor based external events.
+ *
+ * This handler uses a thread and the select function to monitor given file descriptors on
+ * data reception. Examples for possible file descriptors are sockets or com re
+ */
+
+class CFDSelectHandler : public CExternalEventHandler, private CThread{
+ DECLARE_SINGLETON(CFDSelectHandler)
+ ;
+ public:
+ typedef int TFileDescriptor; //!< General type definition for a file descriptor. To be used by the callback classes.
+ static const TFileDescriptor scm_nInvalidFileDescriptor = -1;
+
+ void addComCallback(TFileDescriptor pa_nFD, forte::com_infra::CComLayer *pa_poComLayer);
+ void removeComCallback(TFileDescriptor pa_nFD);
+
+ /* functions needed for the external event handler interface */
+ void enableHandler(void){
+ start();
+ }
+
+ void disableHandler(void){
+ end();
+ }
+
+ void setPriority(int ){
+ //currently we are doing nothing here.
+ //TODO We should adjust the thread priority.
+ }
+
+ int getPriority(void) const {
+ //the same as for setPriority
+ return 0;
+ }
+
+ protected:
+ virtual void run(void);
+
+ private:
+ struct TConnContType{
+ TFileDescriptor m_nSockDes;
+ forte::com_infra::CComLayer * m_poCallee;
+ };
+
+ typedef CSinglyLinkedList TConnectionContainer;
+
+ TFileDescriptor createFDSet(fd_set *m_panFDSet);
+
+ TConnectionContainer m_lstConnectionsList;
+ CSyncObject m_oSync;
+ bool m_bConnectionListChanged;
+};
+
+#endif
diff --git a/src/arch/genfortealloc.h b/src/arch/genfortealloc.h
new file mode 100644
index 000000000..16c96cb3a
--- /dev/null
+++ b/src/arch/genfortealloc.h
@@ -0,0 +1,91 @@
+/*******************************************************************************
+ * Copyright (c) 2010 - 2013 ACIN, nxtcontrol GmbH, fortiss GmbH
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl, Stanislav Meduna, Monika Wenger
+ * - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#ifndef GENFORTEALLOC_H_
+#define GENFORTEALLOC_H_
+
+#include "datatype.h"
+#include
+#include
+
+
+inline
+void forte_free(void *pa_pvData){
+ free(pa_pvData);
+}
+
+inline
+void *forte_malloc(size_t pa_nSize){
+ return malloc(pa_nSize);
+}
+
+inline
+void *forte_realloc(void *pa_pvData, size_t pa_nSize){
+ return realloc(pa_pvData, pa_nSize);
+}
+
+/*! \file genfortealloc.h
+ * Collection of new and delete operators used by forte for dynamically allocating memory.
+ *
+ * The generic implementation uses malloc and free in order to not introduce any std c++ overhead
+ * other implementations are also fine.
+ *
+ * TODO try std new with nothrow.
+ */
+
+inline
+void* operator new(size_t pa_nSize) throw (std::bad_alloc){
+ return malloc(pa_nSize);
+}
+
+inline
+void* operator new[](size_t pa_nSize) throw (std::bad_alloc){
+ return malloc(pa_nSize ? pa_nSize : 1);
+}
+
+inline
+void operator delete(void* pa_pvData) throw(){
+ if (pa_pvData)
+ free(pa_pvData);
+}
+
+inline
+void operator delete[](void* pa_pvData) throw(){
+ if (pa_pvData)
+ free(pa_pvData);
+}
+
+/*! \brief Placement new operator
+ *
+ * Will use the given buffer as memory region. The need size will be ignored.
+ * Objects created with this new must not deleted only invoke the destructor
+ *
+ * @param pa_pData
+ */
+inline
+void * operator new(size_t, TForteByte *pa_pData){
+ return pa_pData;
+}
+
+inline
+void * operator new[](size_t, TForteByte *pa_pData){
+ return pa_pData;
+}
+
+inline
+void operator delete(void *, TForteByte *){
+}
+
+inline
+void operator delete[](void *, TForteByte *){
+}
+
+#endif /* GENFORTEALLOC_H_ */
diff --git a/src/arch/gensockhand.h b/src/arch/gensockhand.h
new file mode 100644
index 000000000..45ef8c6f5
--- /dev/null
+++ b/src/arch/gensockhand.h
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * Copyright (c) 2015 fortiss GmbH
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#ifndef _GENSOCKHAND_H_
+#define _GENSOCKHAND_H_
+
+
+/*!\brief Template class allowing to easily setup IP communication socket handlers.
+ *
+ * There are two template parameters:
+ * - THandler an external event handler which allows Comlayers to register with a descriptor and get notifications on received messages
+ * - TSocektCreator a class providing methods for creating and deleting tcp and udp sockets
+ */
+template
+class CGenericIPComSocketHandler : public THandler, public TSocketCreator{
+ public:
+ //! Type needed by the class CIPCommLayer
+ typedef typename THandler::TFileDescriptor TSocketDescriptor;
+
+ static const TSocketDescriptor scm_nInvalidSocketDescriptor = THandler::scm_nInvalidFileDescriptor;
+ private:
+ //as this class is just a place holder for the others we don't want to have an instance of it
+ CGenericIPComSocketHandler();
+ CGenericIPComSocketHandler(const CGenericIPComSocketHandler&);
+ CGenericIPComSocketHandler& operator =(const CGenericIPComSocketHandler &);
+ ~CGenericIPComSocketHandler();
+};
+
+
+#endif /* _GENSOCKHAND_H_ */
diff --git a/src/arch/netos/CMakeLists.txt b/src/arch/netos/CMakeLists.txt
new file mode 100644
index 000000000..f871114de
--- /dev/null
+++ b/src/arch/netos/CMakeLists.txt
@@ -0,0 +1,15 @@
+#*******************************************************************************
+# * Copyright (c) 2011 ACIN
+# * All rights reserved. This program and the accompanying materials
+# * are made available under the terms of the Eclipse Public License v1.0
+# * which accompanies this distribution, and is available at
+# * http://www.eclipse.org/legal/epl-v10.html
+# *
+# * Contributors:
+# * Alois Zoitl, Patrick Smejkal
+# * - initial API and implementation and/or initial documentation
+# *******************************************************************************/
+
+#add_subdirectory(netos73)
+add_subdirectory(netos74)
+
diff --git a/src/arch/netos/fortealloc.h b/src/arch/netos/fortealloc.h
new file mode 100644
index 000000000..04036ce09
--- /dev/null
+++ b/src/arch/netos/fortealloc.h
@@ -0,0 +1,17 @@
+/*******************************************************************************
+ * Copyright (c) 2010 ACIN
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#ifndef FORTEALLOC_H_
+#define FORTEALLOC_H_
+
+//on threadx environments we are typically happy with the generic alloc implementation based on malloc and free
+#include "../genfortealloc.h"
+
+#endif /* FORTEALLOC_H_ */
diff --git a/src/arch/netos/netos74/CMakeLists.txt b/src/arch/netos/netos74/CMakeLists.txt
new file mode 100644
index 000000000..a1daba61e
--- /dev/null
+++ b/src/arch/netos/netos74/CMakeLists.txt
@@ -0,0 +1,125 @@
+#*******************************************************************************
+# * Copyright (c) 2011, 2014 ACIN, fortiss GmbH
+# * All rights reserved. This program and the accompanying materials
+# * are made available under the terms of the Eclipse Public License v1.0
+# * which accompanies this distribution, and is available at
+# * http://www.eclipse.org/legal/epl-v10.html
+# *
+# * Contributors:
+# * Alois Zoitl, Patrick Smejkal - initial API and implementation and/or initial documentation
+# *******************************************************************************/
+
+SET(SOURCE_GROUP ${SOURCE_GROUP}\\netos74)
+
+forte_add_architecture("NetOS 7.4")
+
+if("${FORTE_ARCHITECTURE}" STREQUAL "NetOs 7.4")
+
+
+#######################################################################################
+# Buffer root path and convert it to Cygwin format
+#######################################################################################
+ set(NETOS_ROOT_PATH_WIN ${CMAKE_FIND_ROOT_PATH})
+ execute_process(COMMAND cygpath ${CMAKE_FIND_ROOT_PATH} OUTPUT_VARIABLE NETOS_ROOT_PATH_CYG)
+ string(REPLACE "\n" "" NETOS_ROOT_PATH_CYG ${NETOS_ROOT_PATH_CYG})
+
+
+#######################################################################################
+# Look for available Board support packages
+#######################################################################################
+ set(FORTE_NETOS74_BSP "connectme" CACHE STRING "Select NetOS Board Support Package")
+ execute_process(COMMAND ls ${NETOS_ROOT_PATH_CYG}/lib/arm7/32b/gnu/bsp OUTPUT_VARIABLE LS_BSP)
+ execute_process(COMMAND echo -n ${LS_BSP} OUTPUT_VARIABLE ECHO_BSP)
+ string(LENGTH "${ECHO_BSP}" LEN_BSP)
+ if(LEN_BSP EQUAL 0)
+ message(FATAL_ERROR "No Board Support Package found! Have you installed Digi NET+OS toolchain and set CMAKE_FIND_ROOT_PATH to the root directory of it (default C:\\netos74)?")
+ endif(LEN_BSP EQUAL 0)
+ string(REPLACE " " ";" AVAILABLE_BSP ${ECHO_BSP})
+ set_property(CACHE FORTE_NETOS74_BSP PROPERTY STRINGS ${AVAILABLE_BSP})
+
+
+#######################################################################################
+# Add commands for creating target image
+#######################################################################################
+ forte_add_post_build_command(COMMAND arm-elf-objcopy.exe ARGS -Obinary src/forte src/forte.uncompressed
+ COMMAND ${NETOS_ROOT_PATH_WIN}/bin/compress.exe ARGS src/forte.uncompressed src/forte.compressed
+ COMMAND ${NETOS_ROOT_PATH_WIN}/bin/boothdr.exe ARGS ${NETOS_ROOT_PATH_WIN}/src/bsp/platforms/${FORTE_NETOS74_BSP}/bootldr.dat src/forte.compressed src/forte.bin connectme_rfid
+ COMMAND cp src/forte.bin image.bin
+ WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+ COMMENT "Create target image (image.bin)...")
+
+
+#######################################################################################
+# COMPILER FLAGS - INCLUDE DIRS
+#######################################################################################
+ forte_add_include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..)
+
+ forte_add_sourcefile_hcpp(../thread ../txtimeha ../sync)
+ forte_add_sourcefile_cpp(appconf_api.c ../root.cpp)
+
+ if(FORTE_COM_ETH)
+ forte_add_sourcefile_hcpp( ../../fdselecthand ../../bsdsocketinterf)
+ forte_add_sourcefile_h(../gensockhand.h)
+ forte_add_sourcefile_h(../sockhand.h)
+ endif(FORTE_COM_ETH)
+
+ forte_add_include_directories(${CMAKE_CURRENT_SOURCE_DIR})
+
+ # Include-Dirs for NetOS
+ forte_add_include_directories(${NETOS_ROOT_PATH_CYG}/h)
+ forte_add_include_directories(${NETOS_ROOT_PATH_CYG}/h/shared)
+ forte_add_include_directories(${NETOS_ROOT_PATH_CYG}/h/threadx)
+ forte_add_include_directories(${NETOS_ROOT_PATH_CYG}/h/tcpip)
+ forte_add_include_directories(${NETOS_ROOT_PATH_CYG}/h/snmp)
+ forte_add_include_directories(${NETOS_ROOT_PATH_CYG}/h/rphttpd)
+ forte_add_include_directories(${NETOS_ROOT_PATH_CYG}/h/fs_intf)
+ forte_add_include_directories(${NETOS_ROOT_PATH_CYG}/h/wln)
+ forte_add_include_directories(${NETOS_ROOT_PATH_CYG}/h/wps)
+ forte_add_include_directories(${NETOS_ROOT_PATH_CYG}/src/treck/include)
+ forte_add_include_directories(${NETOS_ROOT_PATH_CYG}/src/treck/source/ossupport)
+ forte_add_include_directories(${NETOS_ROOT_PATH_CYG}/src/treck/source/ossupport/netos)
+
+ forte_add_definition(-Wpointer-arith -Wundef -Woverloaded-virtual -Wno-write-strings)
+ forte_add_definition(-W -Wall -Wextra -DFORTE_BIG_ENDIAN -DIAM_ENABLED)
+ forte_add_definition(-D__GNU__ -DNETOS_GNU_TOOLS -DNETOS_GNU_CLIB_REENT -DNET_OS -DNET_WORKS -D_POSIX_SOURCE)
+ #forte_add_definition(-DBOOT_LOADER)
+ forte_add_definition(-DIAM_ENABLED -DNET_OS_SPECIFIC -DFUSION=0 -DTRECK=1 -DNETWORK_STACK=1)
+ forte_add_definition(-mbig-endian -mcpu=arm7tdmi -g -O2)
+ forte_add_definition(-ffunction-sections -fdata-sections -fno-threadsafe-statics -fno-rtti -fno-exceptions)
+
+
+#######################################################################################
+# LINKER FLAGS
+#######################################################################################
+ # Linker-Flags for NetOS
+ forte_add_link_directories(${NETOS_ROOT_PATH_CYG}/lib/arm7/32b/gnu)
+ forte_add_link_directories(${NETOS_ROOT_PATH_CYG}/lib/32b/gnu)
+ forte_add_link_directories(${NETOS_ROOT_PATH_CYG}/lib/arm7/32b/gnu/bsp/${FORTE_NETOS74_BSP})
+
+ forte_add_link_library(-Wl,--start-group)
+
+ # Look for reset.o
+ if(EXISTS ${NETOS_ROOT_PATH_WIN}/lib/arm7/32b/gnu/bsp/${FORTE_NETOS74_BSP}/reset.o)
+ forte_add_link_library(${NETOS_ROOT_PATH_CYG}/lib/arm7/32b/gnu/bsp/${FORTE_NETOS74_BSP}/reset.o)
+ else(EXISTS ${NETOS_ROOT_PATH_WIN}/lib/arm7/32b/gnu/bsp/${FORTE_NETOS74_BSP}/reset.o)
+ message(WARNING "reset.o wasn't found where it is expected (${NETOS_ROOT_PATH_WIN}/lib/arm7/32b/gnu/bsp/${FORTE_NETOS74_BSP}/reset.o). Your program maybe won't work without this object. Build BSP first! For further information please refer to the Digi support.")
+ endif(EXISTS ${NETOS_ROOT_PATH_WIN}/lib/arm7/32b/gnu/bsp/${FORTE_NETOS74_BSP}/reset.o)
+
+ forte_add_link_library(${NETOS_ROOT_PATH_CYG}/lib/32b/gnu/crt0.o)
+ forte_add_link_library(${NETOS_ROOT_PATH_CYG}/lib/32b/gnu/crti.o)
+ forte_add_link_library(${NETOS_ROOT_PATH_CYG}/lib/32b/gnu/crtbegin.o)
+ forte_add_link_library(${NETOS_ROOT_PATH_CYG}/lib/32b/gnu/crtend.o)
+ forte_add_link_library(${NETOS_ROOT_PATH_CYG}/lib/32b/gnu/crtn.o)
+ forte_add_link_library(-lbsp -lftpsvr -lflash -lfilesys -lposix -ltx -ldnsclnt -laddp -ltcpip -ltelnsvr)
+ forte_add_link_library(-lc -lgcc -lm -lstdc++)
+ forte_add_link_library(-Wl,--end-group)
+
+ # Look for image.ld
+ if(EXISTS ${NETOS_ROOT_PATH_WIN}/src/bsp/platforms/${FORTE_NETOS74_BSP}/image.ld)
+ forte_add_link_flags("-mbig-endian -nostartfiles -nostdlib -mcpu=arm7tdmi -T ${NETOS_ROOT_PATH_CYG}/src/bsp/platforms/${FORTE_NETOS74_BSP}/image.ld")
+ else(EXISTS ${NETOS_ROOT_PATH_WIN}/src/bsp/platforms/${FORTE_NETOS74_BSP}/image.ld)
+ message(WARNING "image.ld wasn't found where it is expected (${NETOS_ROOT_PATH_WIN}/src/bsp/platforms/${FORTE_NETOS74_BSP}/image.ld). Your program maybe won't work without this object. Build BSP first! For further information please refer to the Digi support.")
+ forte_add_link_flags("-mbig-endian -nostartfiles -nostdlib -mcpu=arm7tdmi -T")
+ endif(EXISTS ${NETOS_ROOT_PATH_WIN}/src/bsp/platforms/${FORTE_NETOS74_BSP}/image.ld)
+
+endif()
\ No newline at end of file
diff --git a/src/arch/netos/root.cpp b/src/arch/netos/root.cpp
new file mode 100644
index 000000000..4b0593fda
--- /dev/null
+++ b/src/arch/netos/root.cpp
@@ -0,0 +1,101 @@
+/*******************************************************************************
+ * Copyright (c) 2006 - 2011 Profactor GmbH, ACIN
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Thomas Strasser, Rene Smodic, Alois Zoitl, Ingo Hegny
+ * - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#include
+#include
+#include
+#include "appconf_api.h"
+#include "../../forte.h"
+#include
+#include
+#include
+
+/*
+ * Set this to 1 to run the system POST tests during startup.
+ */
+const int APP_POST = 0;
+
+/*
+ * Set this to 1 to run the manufacturing burn in tests.
+ */
+int APP_BURN_IN_TEST = 0;
+
+/*
+ * Function: void applicationTcpDown (void)
+ *
+ * Description:
+ *
+ * This routine will be called by the NET+OS root thread once every
+ * clock tick while it is waiting for the TCP/IP stack to come up.
+ *
+ * This routone is called to print the application name and then
+ * to print the '.' every second.
+ *
+ * This function will not be called once the stack has started.
+ *
+ * This function uses the global C++ object PrintApplicationDown app_down.
+ *
+ * Parameters:
+ *
+ * none
+ *
+ * Return Values:
+ *
+ * none
+ */
+extern "C"
+void applicationTcpDown(void) {
+ static int ticksPassed = 0;
+ ticksPassed++;
+}
+
+
+/*
+ * Function: void applicationStart (void)
+ *
+ * Description:
+ *
+ * This routine is responsible for starting the user application. It should
+ * create any threads or other resources the application needs.
+ *
+ * ThreadX, the NET+OS device drivers, and the TCP/IP stack will be running
+ * when this function is called.
+ *
+ * This function uses global C++ object:
+ * PrintApplicationDown app_down.
+ *
+ * Parameters:
+ *
+ * none
+ *
+ * Return Values:
+ *
+ * none
+ */
+
+extern "C"
+void applicationStart(void) {
+ DEVLOG_INFO("\n\nStarting FTP-Server\n\n");
+ naFtpDlInit(NA_FTP_DEF_USERS);
+
+ DEVLOG_INFO("\n\nStarting forteMain()\n\n");
+
+ // Starting Runtime
+ RMT_DEV dev;
+ dev.startDevice();
+ dev.MGR.getResourceEventExecution()->join();
+ tx_thread_suspend(tx_thread_identify());
+}
+
+
+
+
+
diff --git a/src/arch/netos/sockhand.h b/src/arch/netos/sockhand.h
new file mode 100644
index 000000000..eb262e01e
--- /dev/null
+++ b/src/arch/netos/sockhand.h
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * Copyright (c) 2010 - 2015 ACIN, fortiss GmbH
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#ifndef SOCKHAND_H_
+#define SOCKHAND_H_
+
+#include
+#include
+#include
+//these include needs to be last
+#include "../fdselecthand.h"
+#include "../bsdsocketinterf.h"
+#include "../gensockhand.h"
+
+typedef CGenericIPComSocketHandler CIPComSocketHandler;
+
+
+#endif /* SOCKHAND_H_ */
diff --git a/src/arch/netos/sync.cpp b/src/arch/netos/sync.cpp
new file mode 100644
index 000000000..df5c55258
--- /dev/null
+++ b/src/arch/netos/sync.cpp
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * Copyright (c) 2006 - 2010 ACIN, Profactor GmbH
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl, Thomas Strasser
+ * - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#include "sync.h"
+
+CTXSyncObject::CTXSyncObject(){
+ tx_mutex_create(&m_stMutex, "Test Mutex", TX_INHERIT);
+ //TODO handle return value
+}
+
+CTXSyncObject::~CTXSyncObject(){
+ tx_mutex_delete(&m_stMutex);
+ //TODO handle return value
+}
diff --git a/src/arch/netos/sync.h b/src/arch/netos/sync.h
new file mode 100644
index 000000000..be535f6de
--- /dev/null
+++ b/src/arch/netos/sync.h
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * Copyright (c) 2006 - 2010 ACIN
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl
+ * - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#ifndef _SYNC_H_
+#define _SYNC_H_
+
+#include
+
+#define CSyncObject CTXSyncObject //allows that doxygen can generate better documenation
+
+/*! \ingroup tnetos_hal
+ * \brief The sync object implementation for NET+OS.
+ *
+ * In the NET+OS version a mutex is used for the sync object.
+ *
+ * @author AZ
+ */
+class CTXSyncObject{
+ private:
+ protected:
+ TX_MUTEX m_stMutex;
+ public:
+ CTXSyncObject();
+ ~CTXSyncObject();
+ /*!\brief Lock the resource coming after the lock command
+ *
+ * This function blocks until it will get the lock for the coming critical section.
+ */
+ void lock(void){
+ tx_mutex_get(&m_stMutex, TX_WAIT_FOREVER);
+ //TODO handle return value
+ };
+ //!Freee the resource coming after the lock command
+ void unlock(void){
+ tx_mutex_put(&m_stMutex);
+ //TODO handle return value
+ };
+};
+
+#endif /*SYNC_H_*/
diff --git a/src/arch/netos/thread.cpp b/src/arch/netos/thread.cpp
new file mode 100644
index 000000000..0aa75d653
--- /dev/null
+++ b/src/arch/netos/thread.cpp
@@ -0,0 +1,147 @@
+/*******************************************************************************
+ * Copyright (c) 2006 - 2011 ACIN, Profactor GmbH
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl, Thomas Strasser, Rene Smodic, Ingo Hegny
+ * - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#include "thread.h"
+
+const char *CTXThread::csm_cName = { "Test Name" };
+
+const int CTXThread::scm_nThreadListSize = 27;
+TCTXThreadPtr CTXThread::sm_aoThreadList[27] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+
+bool CTXThread::create(void) {
+ // Get new Thread
+
+ if (m_stThread.tx_thread_id != 0)
+ return true;
+ if (TX_SUCCESS == tx_thread_create(&m_stThread, m_acThreadName, threadFunction, (ULONG)(this), m_cStack, m_nStackSize, scm_nThreadListSize + 3, scm_nThreadListSize + 3, //disable preemption threshhold
+ TX_NO_TIME_SLICE, //disable timeslicing
+ TX_AUTO_START))// we start manually
+ {
+ tx_thread_sleep(1);
+ //TODO check return values
+ return true;
+ }
+ else {
+ DEVLOG_DEBUG("Error while creating thread with ID: %d\n",(int)m_stThread.tx_thread_id);
+ return false;
+ }
+}
+
+void CTXThread::threadFunction(ULONG data) {
+ // Get pointer to CThread object out of void pointer
+ CTXThread *pThread = (CTXThread*) (data);
+ // if pointer is ok
+ if (pThread) {
+ tx_mutex_get(&(pThread->m_stMutex), TX_WAIT_FOREVER);
+ pThread->m_bAlive = true;
+ pThread->run();
+ pThread->m_bAlive = false;
+ tx_mutex_put(&(pThread->m_stMutex));
+ }
+}
+
+CTXThread::CTXThread(long pa_nStackSize, char * pa_acThreadName) {
+ m_bAlive = false;
+ m_nStackSize = pa_nStackSize;
+ m_cStack = malloc(m_nStackSize);
+ m_acThreadName = pa_acThreadName;
+ memset((void *) &m_stThread, 0, sizeof(m_stThread));
+
+ tx_mutex_create(&m_stMutex, "test", TX_NO_INHERIT);
+ tx_semaphore_create(&m_stSemaphore, "hugo", 0);
+}
+
+CTXThread::~CTXThread() {
+ end();
+ tx_mutex_delete(&m_stMutex);
+ tx_semaphore_delete(&m_stSemaphore);
+}
+
+void CTXThread::setDeadline(const CIEC_TIME &pa_roVal) {
+ int i;
+ int ii;
+ m_oDeadLine = pa_roVal;
+ //first of all check if this thread is already in the list and remove it from the list
+ for (i = 0; i < scm_nThreadListSize; i++) {
+ if (0 == sm_aoThreadList[i])
+ break;
+ else
+ if (this == sm_aoThreadList[i]) {
+ for (ii = i; ii < scm_nThreadListSize - 1; ii++) {
+ if (0 == sm_aoThreadList[ii + 1])
+ break;
+ sm_aoThreadList[ii + 1]->setPriority(ii + 2);
+ sm_aoThreadList[ii] = sm_aoThreadList[ii + 1];
+ }
+ break;
+ }
+ }
+
+ if (0 == m_oDeadLine)
+ setPriority(scm_nThreadListSize + 2);
+ else {
+ for (i = 0; i < scm_nThreadListSize; i++) {
+ if (0 == sm_aoThreadList[i]) {
+ sm_aoThreadList[i] = this;
+ setPriority(i + 2);
+ break;
+ }
+ else
+ if (m_oDeadLine < sm_aoThreadList[i]->getDeadline()) {
+ CTXThread *poRBuf, *poSBuf = sm_aoThreadList[i];
+ sm_aoThreadList[i] = this;
+ setPriority(i + 2);
+ for (ii = i + 1; ii < scm_nThreadListSize; ii++) {
+ poSBuf->setPriority(ii + 2);
+ poRBuf = sm_aoThreadList[ii];
+ sm_aoThreadList[ii] = poSBuf;
+ if (0 == poRBuf)
+ break;
+ poSBuf = poRBuf;
+ }
+ break;
+ }
+ }
+ }
+}
+
+void CTXThread::end(void) {
+ DEVLOG_INFO("entering end ID: %d\n", (int) m_stThread.tx_thread_id);
+ m_bAlive = false;
+ resumeSelfSuspend();
+ join();
+}
+
+void CTXThread::join(void) {
+ if (0 != m_stThread.tx_thread_id) {
+ //wait till the thread is up and running
+ while (!m_bAlive) {
+ tx_thread_sleep(1);
+ }
+
+ tx_mutex_get(&m_stMutex, TX_WAIT_FOREVER);
+ tx_mutex_put(&m_stMutex);
+ tx_thread_delete(&m_stThread);
+ m_stThread.tx_thread_id = 0;
+ }
+}
+
+// function for output of the semaphore status, for debugging
+void CTXThread::printseminfo(TX_SEMAPHORE *pa_stSemaphore) {
+ CHAR *name;
+ ULONG current_value;
+ TX_THREAD *first_suspended;
+ ULONG suspended_count;
+ TX_SEMAPHORE *next_semaphore;
+ UINT status;
+ status = tx_semaphore_info_get(pa_stSemaphore, &name, ¤t_value, &first_suspended, &suspended_count, &next_semaphore);
+ //DEVLOG_DEBUG_2(cg_nID_CThread, 0x01,"Seminfo: Name : %s, Value : %d, First Susp. Thread: %d, status : %d\n", name, (int)current_value, (int)first_suspended->tx_thread_id, status);
+}
diff --git a/src/arch/netos/thread.h b/src/arch/netos/thread.h
new file mode 100644
index 000000000..e075b182c
--- /dev/null
+++ b/src/arch/netos/thread.h
@@ -0,0 +1,190 @@
+/*******************************************************************************
+ * Copyright (c) 2006 - 2015 ACIN, Profactor GmbH, fortiss GmbH
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl, Thomas Strasser, Rene Smodic, Ingo Hegny
+ * - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#ifndef _THREAD_H_
+#define _THREAD_H_
+
+#include "../datatype.h"
+#include
+#include <../devlog.h>
+#include
+#include
+#include
+#include "../../core/datatypes/forte_time.h"
+
+#define CThread CTXThread //allows that doxygen can generate better documenation
+class CTXThread;
+typedef CTXThread *TCTXThreadPtr;
+
+/** \ingroup FORTE-HAL
+ * \defgroup netos_hal NET+OS Hardware Abstraction Layer
+ *
+ * \brief The FORTE-HAL implemenation for the NET+OS operating system
+ *
+ *
+ */
+
+/*! \ingroup netos_hal
+ * \brief Multithreading implementation for NET+OS.
+ *
+ */
+class CTXThread {
+ public:
+ /*! \brief Constructor of the Thread class
+ *
+ * Does all the neccessary steps in order to get the thread running with the start()-method
+ * @param pa_nStackSize the Size of the stack the thread is allowed to use. 0 means use system default stack size.
+ * @param pa_acThreadName the name of the thread
+ */
+ CTXThread(long pa_nStackSize = 32384, char* pa_acThreadName = "Event Execution Thread");
+
+ /*! \brief Stops and destroys thread.
+ *
+ * Will stop the execution if running and destroy the thread including all system specific data.
+ */
+ virtual ~CTXThread();
+
+ /*! \brief Indicates if the thread is allowed to execute.
+ *
+ * This functions checks if the Thread is still executing user code in its run()-method.
+ * \return true if there the run method is acitve.
+ */
+ bool isAlive(void) const {
+ return m_bAlive;
+ }
+
+ //!Set the deadline of the thread.
+ void setDeadline(const CIEC_TIME &pa_roVal);
+ //!Get the current deadline of the thread.
+ const CIEC_TIME &getDeadline(void) const {
+ return m_oDeadLine;
+ }
+
+ /*! \brief starts the Thread
+ *
+ * By calling this method the execution in the run()-Method will be started. If necessary additional data
+ * can be created here. Because of inheritance resons the best place for executing create is in this method.
+ * For details ask AZ.
+ */
+ void start(void) {
+ create();
+ }
+
+ /*! \brief Resumes a suspended Thread
+ *
+ *
+ */
+ void resumeSelfSuspend(void) {
+ // if the thread is not created yet, we do this here
+ tx_semaphore_put(&m_stSemaphore);
+ }
+
+ /*! \brief Stops the execution of the thread
+ *
+ * This function imidiatly stops the execution of the thread (seting m_bAlive to false) and waits till
+ * this is finished.
+ */
+ void end(void);
+
+ /*! \brief Waits for the Thread to finish its execution.
+ *
+ * This function waits till the execution in the thread decides to end the execution. Blocks the caller!!!
+ */
+ void join(void);
+ protected:
+
+ /*! \brief Suspends the thread.
+ *
+ * Suspends the execution of the thread until resumeSelfSuspend(), end(), or join() is called.
+ */
+ void selfSuspend(void) {
+ tx_semaphore_get(&m_stSemaphore, TX_WAIT_FOREVER);
+ }
+
+ private:
+ /*!\brief Funciton that is given to the system thread support that should be called for the thread.
+ *
+ * this function will call the run method of the thread instance.
+ */
+ static void threadFunction(ULONG data);
+
+ /*! \brief Abstract method for the code to execute in the thread.
+ *
+ * This thread class has to provide means that the code a inheriting class will add to the run()-method will
+ * be executed in a seperated thread regarding the creator of the CThread class.
+ *
+ * The inheriting class has to fullfill the folloing rules when using the run method:
+ * - To end the thread execution simple leave the run()-method
+ * - In order to allow the deletion and stopping of the thread add frequent checks to isAlive and end the
+ * execution if isAlive() returns false.
+ */
+ virtual void run() = 0;
+
+ void setPriority(UINT pa_nPriority) {
+ UINT nOldPrio;
+ tx_thread_priority_change(&m_stThread, pa_nPriority, &nOldPrio);
+ }
+
+ /*! \brief Creates a new thread.
+ *
+ * With this function all the setup things for a new thread are done. The Thread created is initialy
+ * suspended and with the start() method the execution of the code in the run() method is started.
+ */
+ bool create(void);
+
+ /*! \brief Destroies the thread
+ *
+ * This function destroies all the data structures created in the creation phase. All used memory is freed.
+ */
+ bool destroy(void);
+
+ void printseminfo(TX_SEMAPHORE *pa_stSemaphore);
+
+ //!deadline the thread needs to be finish its execution. 0 means unconstrained.
+ CIEC_TIME m_oDeadLine;
+
+ /*! \brief data neede for ecos to identify the thread.
+ */
+ TX_THREAD m_stThread;
+
+ TX_MUTEX m_stMutex; //!< used for join function
+
+ TX_SEMAPHORE m_stSemaphore; //!< used for resume/suspend
+
+ /*! \brief Size of the stack used by this thread.
+ */
+ long m_nStackSize;
+ void *m_cStack;
+ static const char *csm_cName;
+
+ char *m_acThreadName;
+
+ static const int scm_nThreadListSize;
+ static TCTXThreadPtr sm_aoThreadList[27];
+
+ /*! \brief Flag that indicates if the Thread is alive.
+ *
+ * This flag has two main purposes:
+ * -# indicate for other classes if the thread is still executing
+ * -# use in the run()-method to check if the thread is still allowed to execute (e.g. while(isAlive()) ).
+ * This is important for stopping and destroying threads.
+ */
+ bool m_bAlive;
+
+ //we don't want that threads can be copied or assigned therefore the copy constructor and assignment operator are declared private
+ //but not implemented
+ CTXThread(const CTXThread&);
+ CTXThread& operator = (const CTXThread &);
+
+};
+
+#endif /*THREAD_H_*/
+
diff --git a/src/arch/netos/txtimeha.cpp b/src/arch/netos/txtimeha.cpp
new file mode 100644
index 000000000..5d65a72d3
--- /dev/null
+++ b/src/arch/netos/txtimeha.cpp
@@ -0,0 +1,59 @@
+/*******************************************************************************
+ * Copyright (c) 2006 - 2013 ACIN, Profactor GmbH, fortiss GmbH
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl, Thomas Strasser, Rene Smodic, Ingo Hegny
+ * - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#include
+#include "txtimeha.h"
+#include "../../core/devexec.h"
+
+
+void CTimerHandler::createTimerHandler(void){
+ if(0 == sm_poFORTETimer)
+ sm_poFORTETimer = new CTXTimerHandler();
+}
+
+CTXTimerHandler::CTXTimerHandler(){
+// setup the handler for recieving the timer calls
+ //TODO handle ticks per second correctly here
+ UINT status = tx_timer_create(&m_stTimer, "FORTE timer", &timerHandlerFunc, 0, 1, 1, TX_NO_ACTIVATE);
+ if (status == TX_SUCCESS)
+ DEVLOG_DEBUG("Timer created\n");
+ else
+ DEVLOG_DEBUG("Error creating timer\n");
+
+ //TODO handle retval
+}
+
+CTXTimerHandler::~CTXTimerHandler(){
+ disableHandler();
+ tx_timer_delete(&m_stTimer);
+}
+
+void CTXTimerHandler::enableHandler(void){
+ UINT status = tx_timer_activate(&m_stTimer);
+ if (status == TX_SUCCESS)
+ DEVLOG_DEBUG("Timer activated\n");
+ else
+ DEVLOG_DEBUG("Error activating timer\n");
+
+ //TODO handle retval
+}
+
+void CTXTimerHandler::disableHandler(void){
+ tx_timer_deactivate(&m_stTimer);
+ //TODO handle retval
+}
+
+void CTXTimerHandler::setPriority(int pa_nPriority){
+}
+
+int CTXTimerHandler::getPriority(void) const {
+ return 0;
+}
diff --git a/src/arch/netos/txtimeha.h b/src/arch/netos/txtimeha.h
new file mode 100644
index 000000000..4f6d4f329
--- /dev/null
+++ b/src/arch/netos/txtimeha.h
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * Copyright (c) 2006 - 2013 ACIN, Profactor GmbH, fortiss GmbH
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl, Thomas Strasser, Ingo Hegny
+ * - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#ifndef _TXTIMEHA_H_
+#define _TXTIMEHA_H_
+
+#include
+#include "../timerha.h"
+#include "../devlog.h"
+
+/*! \ingroup netos_hal
+ * \ingroup EXTEVHAND
+ * \brief Timerhandler for NET+OS.
+ *
+ */
+class CTXTimerHandler : public CTimerHandler{
+ public:
+ virtual ~CTXTimerHandler();
+
+ /*!\brief Enables this event source
+ *
+ */
+ virtual void enableHandler(void);
+ /*!\brief Disable this event source
+ */
+ virtual void disableHandler(void);
+ /*!\brief Sets the priority of the event source
+ *
+ * \param pa_nPriority new priority of the event source
+ */
+ virtual void setPriority(int pa_nPriority);
+ /*!\brief Get the current priority of the event source
+ *
+ * \return current priority
+ */
+ virtual int getPriority(void) const;
+ private:
+ /*!\brief callback function for the system timer
+ */
+ static void timerHandlerFunc(ULONG data){
+ sm_poFORTETimer->nextTick();
+ }
+ ;
+
+ CTXTimerHandler();
+
+ TX_TIMER m_stTimer;
+
+ friend class CTimerHandler;
+};
+
+#endif /*PCTIMEHA_H_*/
diff --git a/src/arch/posix/CMakeLists.txt b/src/arch/posix/CMakeLists.txt
new file mode 100644
index 000000000..66414356d
--- /dev/null
+++ b/src/arch/posix/CMakeLists.txt
@@ -0,0 +1,55 @@
+#*******************************************************************************
+# * Copyright (c) 2010 - 2015 ACIN, Profactor GmbH, fortiss GmbH
+# * All rights reserved. This program and the accompanying materials
+# * are made available under the terms of the Eclipse Public License v1.0
+# * which accompanies this distribution, and is available at
+# * http://www.eclipse.org/legal/epl-v10.html
+# *
+# * Contributors:
+# * Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny, Martin Melik Merkumians
+# * - initial API and implementation and/or initial documentation
+# *******************************************************************************/
+
+SET(SOURCE_GROUP ${SOURCE_GROUP}\\posix)
+
+forte_add_architecture(Posix)
+
+if("${FORTE_ARCHITECTURE}" STREQUAL "Posix")
+
+ forte_add_include_directories(${CMAKE_CURRENT_SOURCE_DIR})
+
+ forte_add_sourcefile_hcpp(thread pctimeha sync)
+ forte_add_sourcefile_cpp(main.cpp)
+
+ if(FORTE_COM_ETH)
+ forte_add_sourcefile_hcpp( ../fdselecthand ../bsdsocketinterf)
+ forte_add_sourcefile_h(../gensockhand.h)
+ forte_add_sourcefile_h(sockhand.h)
+ endif(FORTE_COM_ETH)
+
+ forte_add_include_directories(../${CMAKE_CURRENT_SOURCE_DIR})
+ forte_add_include_directories(${CMAKE_CURRENT_SOURCE_DIR})
+ #forte_add_link_library(pthread)
+
+ forte_add_definition("-W -Wall -Wextra -Woverloaded-virtual -Wconversion -DFORTE_LITTLE_ENDIAN -ggdb")
+
+ set(FORTE_RTTI_AND_EXCEPTIONS FALSE CACHE BOOL "Enable RTTI and Exceptions")
+ mark_as_advanced(FORTE_RTTI_AND_EXCEPTIONS)
+ IF(NOT FORTE_RTTI_AND_EXCEPTIONS)
+ forte_add_definition("-fno-rtti -fno-exceptions")
+ ENDIF(NOT FORTE_RTTI_AND_EXCEPTIONS)
+
+
+ set(FORTE_POSIX_GENERATE_MAP_FILE FALSE CACHE BOOL "Enable the generation of map files")
+ mark_as_advanced(FORTE_POSIX_GENERATE_MAP_FILE)
+ IF(FORTE_POSIX_GENERATE_MAP_FILE)
+ forte_add_link_flags("-Wl,-M -Wl,-Map -Wl,forte.map -Wl,-cref")
+ ENDIF(FORTE_POSIX_GENERATE_MAP_FILE)
+
+ forte_add_link_library("-lpthread")
+
+
+ forte_add_network_layer(SER OFF "ser" CSerCommLayer sercommlayer "Enable Forte serial line communication")
+ forte_add_network_layer(MUXSER OFF "muxser" CMuxedSerCommLayer muxedsercommlayer "Enable Forte multiplexed serial line communication")
+
+endif()
\ No newline at end of file
diff --git a/src/arch/posix/fortealloc.h b/src/arch/posix/fortealloc.h
new file mode 100644
index 000000000..eab852529
--- /dev/null
+++ b/src/arch/posix/fortealloc.h
@@ -0,0 +1,17 @@
+/*******************************************************************************
+ * Copyright (c) 2010 ACIN
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#ifndef FORTEALLOC_H_
+#define FORTEALLOC_H_
+
+//on posix environments we are typically happy with the generic alloc implementation based on malloc and free
+#include "../genfortealloc.h"
+
+#endif /* FORTEALLOC_H_ */
diff --git a/src/arch/posix/main.cpp b/src/arch/posix/main.cpp
new file mode 100644
index 000000000..b2402a4ee
--- /dev/null
+++ b/src/arch/posix/main.cpp
@@ -0,0 +1,128 @@
+/*******************************************************************************
+ * Copyright (c) 2006 - 2014 ACIN, Profactor GmbH, AIT, fortiss GmbH
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl, Gerhard Ebenhofer, Thomas Strasser, Rene Smodic,
+ * Martin Melik Merkumians, Ingo Hegny, Filip Andren - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#include
+#include
+#include
+#include
+
+#ifdef CONFIG_POWERLINK_USERSTACK
+#include
+#endif
+
+/*!\brief Check if the correct endianess has been configured.
+ *
+ * If the right endianess is not set this function will end FORTE.
+ */
+void checkEndianess();
+
+//this keeps away a lot of rtti and exception handling stuff
+extern "C" void __cxa_pure_virtual(void){
+ //TODO maybe add some reporting here
+ //Although we should never get here
+ //if we are here something very very bad has happened e.g., stack overflow or other memory corruption
+
+}
+
+RMT_DEV *poDev = 0;
+
+void endForte(int pa_nSig){
+ (void) pa_nSig;
+ if(0 != poDev){
+ poDev->changeFBExecutionState(cg_nMGM_CMD_Kill);
+ }
+}
+
+/*!\brief Creates the Device-Object
+ * \param pa_acMGRID A string containing IP and Port like [IP]:[Port]
+ */
+void createDev(const char *pa_acMGRID){
+
+ signal(SIGINT, endForte);
+ signal(SIGTERM, endForte);
+ signal(SIGHUP, endForte);
+
+#ifdef CONFIG_POWERLINK_USERSTACK
+ CEplStackWrapper::eplMainInit();
+#endif
+
+ poDev = new RMT_DEV;
+
+ poDev->setMGR_ID(pa_acMGRID);
+ poDev->startDevice();
+ poDev->MGR.getResourceEventExecution()->joinEventChainExecutionThread();
+ delete poDev;
+}
+
+/*!\brief Lists the help for FORTE
+ *
+ */
+void listHelp(){
+ printf("\nUsage of FORTE:\n");
+ printf(" -h\t lists this help.\n");
+ printf("\n");
+ printf(" -c\t sets the destination for the connection.\n");
+ printf(" \t Usage: forte -c :");
+ printf("\n");
+}
+
+int main(int argc, char *arg[]){
+
+ checkEndianess();
+
+ DEVLOG_INFO("Memory size CFunctionBlock : %d \n", sizeof(CFunctionBlock));
+ DEVLOG_INFO("Memory size CDevice : %d \n", sizeof(CDevice));
+ DEVLOG_INFO("Memory size CResource : %d \n", sizeof(CResource));
+ DEVLOG_INFO("Memory size CConnection : %d \n", sizeof(CConnection));
+ DEVLOG_INFO("Memory size CDataConnection : %d \n", sizeof(CDataConnection));
+ DEVLOG_INFO("Memory size CEventConnection : %d \n", sizeof(CEventConnection));
+
+ DEVLOG_INFO("Memory size int : %d \n", sizeof(int));
+ DEVLOG_INFO("Memory size long : %d \n", sizeof(long));
+
+ DEVLOG_INFO("Memory size int8_t : %d \n", sizeof(int8_t));
+ DEVLOG_INFO("Memory size int16_t : %d \n", sizeof(int16_t));
+ DEVLOG_INFO("Memory size int32_t : %d \n", sizeof(int32_t));
+ DEVLOG_INFO("Memory size int64_t : %d \n", sizeof(int64_t));
+
+ if(argc <= 1){ //! Default Value (localhost:61499)
+ createDev("localhost:61499");
+ }
+ else{
+ if(strcmp("-c", arg[1]) == 0){ //! sets the destination for the connection
+ createDev(arg[2]);
+ }
+ else{ //! Lists the help for FORTE
+ listHelp();
+ }
+ }
+ return 0;
+}
+
+void checkEndianess(){
+ int i = 1;
+ char *p = (char *) &i;
+ if(p[0] == 1){
+ //we are on a little endian platform
+#ifdef FORTE_BIG_ENDIAN
+ DEVLOG_ERROR("Wrong endianess configured! You are on a little endian platform and have configured big endian!\n");
+ exit(-1);
+#endif
+ }
+ else{
+ //we are on a big endian platform
+#ifdef FORTE_LITTLE_ENDIAN
+ DEVLOG_ERROR("Wrong endianess configured! You are on a big endian platform and have configured little endian!\n");
+ exit(-1);
+#endif
+ }
+}
+
diff --git a/src/arch/posix/muxedsercommlayer.cpp b/src/arch/posix/muxedsercommlayer.cpp
new file mode 100644
index 000000000..b8e30d49f
--- /dev/null
+++ b/src/arch/posix/muxedsercommlayer.cpp
@@ -0,0 +1,264 @@
+/*******************************************************************************
+ * Copyright (c) 2012 - 2015 ACIN, fortiss GmbH
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#include "muxedsercommlayer.h"
+#include "commfb.h"
+#include "../devlog.h"
+#include
+#include
+#include
+#include
+#include
+#include
+
+using namespace forte::com_infra;
+
+CMuxedSerCommLayer::CMuxedSerPortsManager CMuxedSerCommLayer::sm_oMuxedSerPortsManager;
+
+CMuxedSerCommLayer::CMuxedSerCommLayer(CComLayer* pa_poUpperLayer, CCommFB * pa_poFB) :
+ CComLayer(pa_poUpperLayer, pa_poFB), m_unBufFillSize(0){
+
+}
+
+CMuxedSerCommLayer::~CMuxedSerCommLayer(){
+ closeConnection();
+}
+
+void CMuxedSerCommLayer::closeConnection(){
+ if(CFDSelectHandler::scm_nInvalidFileDescriptor != m_nFD){
+ sm_oMuxedSerPortsManager.removeMuxedSerLayer(m_nFD, this);
+ m_nFD = CFDSelectHandler::scm_nInvalidFileDescriptor;
+ }
+}
+
+EComResponse CMuxedSerCommLayer::sendData(void *pa_pvData, unsigned int pa_unSize){
+ if(CFDSelectHandler::scm_nInvalidFileDescriptor != m_nFD){
+ //first send id
+
+ m_acRecvBuffer[0] = m_unSerMuxId;
+ memcpy(&(m_acRecvBuffer[1]), pa_pvData, pa_unSize);
+ pa_unSize++;
+
+ ssize_t nSentBytes;
+ ssize_t nToSend = pa_unSize;
+ while(0 < nToSend){
+ nSentBytes = write(m_nFD, &(m_acRecvBuffer[0]), nToSend);
+ if(nSentBytes <= 0){
+ DEVLOG_ERROR("CMuxedSerCommLayer: Send failed: %s\n", strerror(errno));
+ return e_ProcessDataSendFailed;
+ }
+ nToSend -= nSentBytes;
+ pa_pvData = static_cast(pa_pvData) + nSentBytes;
+ }
+ }
+
+ return e_ProcessDataOk;
+}
+
+EComResponse CMuxedSerCommLayer::recvData(const void *, unsigned int){
+ ssize_t nReadCount = read(m_nFD, &m_acRecvBuffer[m_unBufFillSize], cg_unIPLayerRecvBufferSize - m_unBufFillSize);
+
+ switch (nReadCount){
+ case 0:
+ DEVLOG_INFO("CMuxedSerCommLayer: Connection closed by peer\n");
+ m_eInterruptResp = e_InitTerminated;
+ closeConnection();
+ break;
+ case -1:
+ DEVLOG_ERROR("CMuxedSerCommLayer: read failed: %s\n", strerror(errno));
+ m_eInterruptResp = e_ProcessDataRecvFaild;
+ break;
+ default:
+ //we successfully received data
+ m_unBufFillSize += nReadCount;
+ m_eInterruptResp = e_ProcessDataOk;
+ break;
+ }
+
+ m_poFb->interruptCommFB(this);
+ return m_eInterruptResp;
+}
+
+EComResponse CMuxedSerCommLayer::processInterrupt(){
+ if(e_ProcessDataOk == m_eInterruptResp){
+ m_eInterruptResp = m_poTopLayer->recvData(m_acRecvBuffer, m_unBufFillSize);
+ m_unBufFillSize = 0;
+ }
+ return m_eInterruptResp;
+}
+
+EComResponse CMuxedSerCommLayer::openConnection(char *pa_acLayerParameter){
+ EComResponse eRetVal = e_InitInvalidId;
+
+ char *acPort = strchr(pa_acLayerParameter, ':');
+ if(0 != acPort){
+ *acPort = '\0';
+ ++acPort;
+ m_unSerMuxId = static_cast(forte::core::util::strtoul(acPort, 0, 10));
+ m_nFD = sm_oMuxedSerPortsManager.addMuxedSerLayer(pa_acLayerParameter, this);
+ if(CFDSelectHandler::scm_nInvalidFileDescriptor != m_nFD){
+ eRetVal = e_InitOk;
+ }
+ }
+
+ return eRetVal;
+}
+
+//**************************************************************************************************************************
+CMuxedSerCommLayer::CMuxedSerPortsManager::CMuxedSerPortsManager(){
+
+}
+
+CFDSelectHandler::TFileDescriptor CMuxedSerCommLayer::CMuxedSerPortsManager::addMuxedSerLayer(char* pa_acSerPort, CMuxedSerCommLayer *pa_poComCallBack){
+ CCriticalRegion criticalRegion(m_oSync);
+ CFDSelectHandler::TFileDescriptor nRetVal = CFDSelectHandler::scm_nInvalidFileDescriptor;
+ SSerPortEntry *m_pstSerPortEntry = getSerPortEntry(pa_acSerPort);
+ if(0 != m_pstSerPortEntry){
+ m_pstSerPortEntry->m_lstConnectionsList.push_back(pa_poComCallBack);
+ nRetVal = m_pstSerPortEntry->m_nFD;
+ }
+ return nRetVal;
+}
+
+void CMuxedSerCommLayer::CMuxedSerPortsManager::removeMuxedSerLayer(CFDSelectHandler::TFileDescriptor m_nFD, CMuxedSerCommLayer *pa_poComCallBack){
+ CCriticalRegion criticalRegion(m_oSync);
+ SSerPortEntry *m_pstSerPortEntry = getOpendSerPortEntry(m_nFD);
+ if(0 != m_pstSerPortEntry){
+ TConnectionContainer::Iterator itRunner(m_pstSerPortEntry->m_lstConnectionsList.begin());
+ TConnectionContainer::Iterator itRevNode(m_pstSerPortEntry->m_lstConnectionsList.end());
+ TConnectionContainer::Iterator itEnd(m_pstSerPortEntry->m_lstConnectionsList.end());
+
+ while(itRunner != itEnd){
+ if((*itRunner) == pa_poComCallBack){
+ if(itRevNode == itEnd){
+ m_pstSerPortEntry->m_lstConnectionsList.pop_front();
+ }else{
+ m_pstSerPortEntry->m_lstConnectionsList.eraseAfter(itRevNode);
+ }
+ break;
+ }
+
+ itRevNode = itRunner;
+ ++itRunner;
+ }
+
+ if(m_pstSerPortEntry->m_lstConnectionsList.isEmpty()){
+ closePort(m_pstSerPortEntry);
+ }
+ }
+}
+
+EComResponse CMuxedSerCommLayer::CMuxedSerPortsManager::SSerPortEntry::recvData(const void *, unsigned int){
+ EComResponse eRetVal = e_Nothing;
+ char nID;
+
+ ssize_t nReadCount = read(m_nFD, &nID, 1);
+
+ if(1 == nReadCount){
+
+ TConnectionContainer::Iterator itEnd(m_lstConnectionsList.end());
+ for(TConnectionContainer::Iterator itRunner = m_lstConnectionsList.begin(), itCurrent = m_lstConnectionsList.begin(); itRunner != itEnd;){
+ itCurrent = itRunner;
+ ++itRunner;
+ if(nID == itCurrent->getSerMuxId()){
+ eRetVal = itCurrent->recvData(0,0);
+ if(e_Nothing != eRetVal){
+ m_poFb = itCurrent->getCommFB();
+ }
+ break;
+ }
+ }
+ }
+ else{
+ //FIXME handle error close connections and inform FBs
+ }
+
+ return eRetVal;
+}
+
+EComResponse CMuxedSerCommLayer::CMuxedSerPortsManager::SSerPortEntry::processInterrupt(){
+ return e_Nothing;
+}
+
+CMuxedSerCommLayer::CMuxedSerPortsManager::SSerPortEntry *CMuxedSerCommLayer::CMuxedSerPortsManager::getSerPortEntry(char* pa_acSerPort){
+ for(TSerPortList::Iterator itRunner = m_lstPortList.begin(); itRunner != m_lstPortList.end(); ++itRunner){
+ if(0 == strcmp(itRunner->m_acSerPort, pa_acSerPort)){
+ return &(*itRunner);
+ }
+ }
+
+ TSerPortList::Iterator itRef(m_lstPortList.back());
+//this port is not yet managed by us
+ m_lstPortList.push_back(SSerPortEntry());
+ TSerPortList::Iterator itCurrent(m_lstPortList.back());
+ SSerPortEntry *pstRetVal = &(*itCurrent);
+ openPort(pa_acSerPort, pstRetVal);
+ if(CFDSelectHandler::scm_nInvalidFileDescriptor == pstRetVal->m_nFD){
+ if(itCurrent == m_lstPortList.begin()){
+ m_lstPortList.pop_front();
+ }
+ else{
+ m_lstPortList.eraseAfter(itRef);
+ }
+ pstRetVal = 0;
+ }
+ else{
+ pstRetVal->m_acSerPort = new char[strlen(pa_acSerPort) + 1];
+ strcpy(pstRetVal->m_acSerPort, pa_acSerPort);
+ }
+ return pstRetVal;
+}
+
+CMuxedSerCommLayer::CMuxedSerPortsManager::SSerPortEntry *CMuxedSerCommLayer::CMuxedSerPortsManager::getOpendSerPortEntry(CFDSelectHandler::TFileDescriptor pa_nFD){
+ SSerPortEntry *pstRetVal = 0;
+ for(TSerPortList::Iterator itRunner = m_lstPortList.begin(); itRunner != m_lstPortList.end(); ++itRunner){
+ if(pa_nFD == itRunner->m_nFD){
+ pstRetVal = &(*itRunner);
+ break;
+ }
+ }
+ return pstRetVal;
+}
+
+void CMuxedSerCommLayer::CMuxedSerPortsManager::openPort(char* pa_acSerPort, SSerPortEntry *pa_pstPortEntry){
+ pa_pstPortEntry->m_nFD = open(pa_acSerPort, O_RDWR | O_NOCTTY);
+
+ if(CFDSelectHandler::scm_nInvalidFileDescriptor != pa_pstPortEntry->m_nFD){
+ CFDSelectHandler::getInstance().addComCallback(pa_pstPortEntry->m_nFD, pa_pstPortEntry);
+ }
+ else{
+ DEVLOG_ERROR("CSerCommLayer: open failed: %s\n", strerror(errno));
+ }
+}
+
+void CMuxedSerCommLayer::CMuxedSerPortsManager::closePort(SSerPortEntry *pa_pstSerPortEntry){
+ CFDSelectHandler::getInstance().removeComCallback(pa_pstSerPortEntry->m_nFD);
+ close(pa_pstSerPortEntry->m_nFD);
+
+ delete[] pa_pstSerPortEntry->m_acSerPort;
+
+ TSerPortList::Iterator itRunner(m_lstPortList.begin());
+ TSerPortList::Iterator itRefNode(m_lstPortList.end());
+
+ while(itRunner != m_lstPortList.end()){
+ if(itRunner->m_nFD == pa_pstSerPortEntry->m_nFD){
+ if(itRefNode == m_lstPortList.end()){
+ m_lstPortList.pop_front();
+ }
+ else{
+ m_lstPortList.eraseAfter(itRefNode);
+ }
+ break;
+ }
+
+ itRefNode = itRunner;
+ ++itRunner;
+ }
+}
diff --git a/src/arch/posix/muxedsercommlayer.h b/src/arch/posix/muxedsercommlayer.h
new file mode 100644
index 000000000..aa62eb997
--- /dev/null
+++ b/src/arch/posix/muxedsercommlayer.h
@@ -0,0 +1,99 @@
+/*******************************************************************************
+ * Copyright (c) 2012, 2014 ACIN, fortiss GmbH
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#ifndef _MUXEDSERCOMMLAYER_H_
+#define _MUXEDSERCOMMLAYER_H_
+
+#include "comlayer.h"
+#include "fdselecthand.h"
+
+class CMuxedSerCommLayer : public forte::com_infra::CComLayer{
+ public:
+ CMuxedSerCommLayer(forte::com_infra::CComLayer* pa_poUpperLayer, forte::com_infra::CCommFB * pa_poFB);
+ virtual ~CMuxedSerCommLayer();
+
+ virtual void closeConnection();
+ virtual forte::com_infra::EComResponse sendData(void *pa_pvData, unsigned int pa_unSize);
+ virtual forte::com_infra::EComResponse recvData(const void *pa_pvData, unsigned int pa_unSize);
+
+ virtual forte::com_infra::EComResponse processInterrupt();
+
+ TForteUInt8 getSerMuxId() const{
+ return m_unSerMuxId;
+ }
+
+ protected:
+ private:
+ virtual forte::com_infra::EComResponse openConnection(char *pa_acLayerParameter);
+
+ forte::com_infra::EComResponse m_eInterruptResp;
+ char m_acRecvBuffer[cg_unIPLayerRecvBufferSize];
+ unsigned int m_unBufFillSize;
+ TForteUInt8 m_unSerMuxId;
+ CFDSelectHandler::TFileDescriptor m_nFD; //!< file descriptor for accessing the serial device
+
+ class CMuxedSerPortsManager{
+
+ public:
+
+ CFDSelectHandler::TFileDescriptor addMuxedSerLayer(char* pa_acSerPort, CMuxedSerCommLayer *pa_poComCallBack);
+ void removeMuxedSerLayer(CFDSelectHandler::TFileDescriptor m_nFD, CMuxedSerCommLayer *pa_poComCallBack);
+
+ private:
+
+ typedef CSinglyLinkedList TConnectionContainer;
+ class SSerPortEntry : public forte::com_infra::CComLayer{
+ public:
+ SSerPortEntry(): forte::com_infra::CComLayer(0, 0){
+ }
+
+ char* m_acSerPort;
+ CFDSelectHandler::TFileDescriptor m_nFD;
+ TConnectionContainer m_lstConnectionsList;
+
+ virtual void closeConnection(){}
+
+ virtual forte::com_infra::EComResponse sendData(void *, unsigned int ){
+ return forte::com_infra::e_Nothing;
+ }
+
+ virtual forte::com_infra::EComResponse recvData(const void *pa_pvData, unsigned int pa_unSize);
+ virtual forte::com_infra::EComResponse processInterrupt();
+
+ private:
+ virtual forte::com_infra::EComResponse openConnection(char *){
+ return forte::com_infra::e_Nothing;
+ }
+ };
+
+ typedef CSinglyLinkedList TSerPortList;
+
+ CMuxedSerPortsManager();
+ SSerPortEntry *getSerPortEntry(char* pa_acSerPort);
+ SSerPortEntry *getOpendSerPortEntry(CFDSelectHandler::TFileDescriptor pa_nFD);
+ void openPort(char* pa_acSerPort, SSerPortEntry *pa_pstPortEntry);
+ void closePort(SSerPortEntry *pa_pstSerPortEntry);
+
+ TSerPortList m_lstPortList;
+
+ CSyncObject m_oSync;
+
+ //needed so that CLMSUSBLayer can have a static member variable holding the manager.
+ friend class CMuxedSerCommLayer;
+
+ //not to be implemented
+ CMuxedSerPortsManager(const CMuxedSerPortsManager &);
+ CMuxedSerPortsManager &operator =(const CMuxedSerPortsManager&);
+ };
+
+ static CMuxedSerPortsManager sm_oMuxedSerPortsManager;
+};
+
+#endif /* MUXEDSERCOMMLAYER_H_ */
diff --git a/src/arch/posix/pctimeha.cpp b/src/arch/posix/pctimeha.cpp
new file mode 100644
index 000000000..1b1a2c6e3
--- /dev/null
+++ b/src/arch/posix/pctimeha.cpp
@@ -0,0 +1,78 @@
+/*******************************************************************************
+ * Copyright (c) 2005 - 2013 ACIN, fortiss GmbH
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#include
+#include "pctimeha.h"
+#include "../../core/devexec.h"
+#include
+#include
+
+void CTimerHandler::createTimerHandler(void){
+ if(0 == sm_poFORTETimer)
+ sm_poFORTETimer = new CPCTimerHandler();
+}
+
+CPCTimerHandler::CPCTimerHandler(){
+}
+
+CPCTimerHandler::~CPCTimerHandler(){
+ disableHandler();
+}
+
+void CPCTimerHandler::run(){
+ struct timespec stReq;
+ stReq.tv_sec = 0;
+ stReq.tv_nsec = (1000000 / getTicksPerSecond()) * 1000;
+
+ struct timeval stOldTime;
+ struct timeval stNewTime;
+ struct timeval stReqTime;
+ // Timer interval is 1ms
+ stReqTime.tv_sec = 0;
+ stReqTime.tv_usec = (1000 / getTicksPerSecond()) * 1000;
+ struct timeval stDiffTime;
+ struct timeval stRemainingTime;
+ timerclear(&stRemainingTime);
+
+ gettimeofday(&stOldTime, 0);
+ while(isAlive()){
+
+ nanosleep(&stReq, NULL);
+
+ gettimeofday(&stNewTime, 0);
+
+ timersub(&stNewTime, &stOldTime, &stDiffTime);
+
+ timeradd(&stRemainingTime, &stDiffTime, &stRemainingTime);
+
+ while(!timercmp(&stRemainingTime, &stReqTime, <)){
+ nextTick();
+ timersub(&stRemainingTime, &stReqTime, &stRemainingTime);
+ }
+ stOldTime = stNewTime; // in c++ this should work fine
+ }
+}
+
+void CPCTimerHandler::enableHandler(void){
+ start();
+}
+
+void CPCTimerHandler::disableHandler(void){
+ end();
+}
+
+void CPCTimerHandler::setPriority(int ){
+ //TODO think on hwo to handle this.
+}
+
+int CPCTimerHandler::getPriority(void) const {
+ //TODO think on hwo to handle this.
+ return 1;
+}
diff --git a/src/arch/posix/pctimeha.h b/src/arch/posix/pctimeha.h
new file mode 100644
index 000000000..851f8f8cd
--- /dev/null
+++ b/src/arch/posix/pctimeha.h
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * Copyright (c) 2005 - 2011 ACIN
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#ifndef _PCTIMEHA_H_
+#define _PCTIMEHA_H_
+
+#include "thread.h"
+#include "../timerha.h"
+
+/*! \ingroup posix_hal
+ *\ingroup EXTEVHAND
+ *\brief the timer handler for the pc architecture.
+ */
+class CPCTimerHandler : public CTimerHandler, private CThread{
+ public:
+ virtual ~CPCTimerHandler();
+
+ virtual void run();
+
+ /*!\brief Enables this event source
+ *
+ */
+ virtual void enableHandler(void);
+ /*!\brief Disable this event source
+ */
+ virtual void disableHandler(void);
+ /*!\brief Sets the priority of the event source
+ *
+ * \param pa_nPriority new priority of the event source
+ */
+ virtual void setPriority(int pa_nPriority);
+ /*!\brief Get the current priority of the event source
+ *
+ * \return current priority
+ */
+ virtual int getPriority(void) const;
+ private:
+ CPCTimerHandler();
+
+ friend class CTimerHandler;
+
+};
+
+#endif /*PCTIMEHA_H_*/
diff --git a/src/arch/posix/sercommlayer.cpp b/src/arch/posix/sercommlayer.cpp
new file mode 100644
index 000000000..1bad94298
--- /dev/null
+++ b/src/arch/posix/sercommlayer.cpp
@@ -0,0 +1,142 @@
+/*******************************************************************************
+ * Copyright (c) 2012, 2014 ACIN, fortiss GmbH
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#include "sercommlayer.h"
+#include "commfb.h"
+#include "../devlog.h"
+#include
+#include
+#include
+#include
+#include
+#include
+
+using namespace forte::com_infra;
+
+CSerCommLayer::CSerCommLayer(CComLayer* pa_poUpperLayer, CCommFB * pa_poFB) :
+ CComLayer(pa_poUpperLayer, pa_poFB), m_nFD(CFDSelectHandler::scm_nInvalidFileDescriptor), m_unBufFillSize(0){
+
+}
+
+CSerCommLayer::~CSerCommLayer(){
+ closeConnection();
+}
+
+void CSerCommLayer::closeConnection(){
+ if(CFDSelectHandler::scm_nInvalidFileDescriptor != m_nFD){
+ CFDSelectHandler::getInstance().removeComCallback(m_nFD);
+ tcsetattr(m_nFD, TCSANOW, &m_stOldTIO);
+ close(m_nFD);
+ m_nFD = CFDSelectHandler::scm_nInvalidFileDescriptor;
+ }
+}
+
+forte::com_infra::EComResponse CSerCommLayer::sendData(void *pa_pvData, unsigned int pa_unSize){
+ if(CFDSelectHandler::scm_nInvalidFileDescriptor != m_nFD){
+ ssize_t nSentBytes;
+ ssize_t nToSend = pa_unSize;
+ while(0 < nToSend){
+ nSentBytes = write(m_nFD, pa_pvData, nToSend);
+ if(nSentBytes <= 0){
+ DEVLOG_ERROR("CSerCommLayer: Send failed: %s\n", strerror(errno));
+ return e_ProcessDataSendFailed;
+ }
+ nToSend -= nSentBytes;
+ pa_pvData = static_cast(pa_pvData) + nSentBytes;
+ }
+ }
+
+ return e_ProcessDataOk;
+}
+
+forte::com_infra::EComResponse CSerCommLayer::recvData(const void *, unsigned int){
+ ssize_t nReadCount = read(m_nFD, &m_acRecvBuffer[m_unBufFillSize], cg_unIPLayerRecvBufferSize - m_unBufFillSize);
+
+ switch (nReadCount){
+ case 0:
+ DEVLOG_INFO("Connection closed by peer\n");
+ m_eInterruptResp = e_InitTerminated;
+ closeConnection();
+ break;
+ case -1:
+ DEVLOG_ERROR("CSerCommLayer: read failed: %s\n", strerror(errno));
+ m_eInterruptResp = e_ProcessDataRecvFaild;
+ break;
+ default:
+ //we successfully received data
+ m_unBufFillSize += nReadCount;
+ m_eInterruptResp = e_ProcessDataOk;
+ break;
+ }
+
+ m_poFb->interruptCommFB(this);
+ return m_eInterruptResp;
+}
+
+forte::com_infra::EComResponse CSerCommLayer::processInterrupt(){
+ if(e_ProcessDataOk == m_eInterruptResp){
+ m_eInterruptResp = m_poTopLayer->recvData(m_acRecvBuffer, m_unBufFillSize);
+ m_unBufFillSize = 0;
+ }
+ return m_eInterruptResp;
+}
+
+forte::com_infra::EComResponse CSerCommLayer::openConnection(char *pa_acLayerParameter){
+ EComResponse eRetVal = e_InitInvalidId;
+
+ //as first shot take the serial interface device as param (e.g., /dev/ttyS0 )
+ m_nFD = open(pa_acLayerParameter, O_RDWR | O_NOCTTY);
+
+ if(CFDSelectHandler::scm_nInvalidFileDescriptor != m_nFD){
+ tcgetattr(m_nFD, &m_stOldTIO);
+ struct termios stNewTIO;
+ memset(&stNewTIO, 0, sizeof(stNewTIO));
+
+ //TODO make more of these flags setable by the user, current baudrate is suitable for lms usb serial communication
+ stNewTIO.c_cflag = B115200 | CS8 | CLOCAL | CREAD;
+
+ stNewTIO.c_iflag = IGNPAR | ICRNL;
+
+ stNewTIO.c_oflag = 0; //raw output
+
+ stNewTIO.c_lflag = ICANON; // enable canonical input, disable echo func and don't send signals to calling programm
+
+ stNewTIO.c_cc[VINTR] = 0; /* Ctrl-c */
+ stNewTIO.c_cc[VQUIT] = 0; /* Ctrl-\ */
+ stNewTIO.c_cc[VERASE] = 0; /* del */
+ stNewTIO.c_cc[VKILL] = 0; /* @ */
+ stNewTIO.c_cc[VEOF] = 4; /* Ctrl-d */
+ stNewTIO.c_cc[VTIME] = 0; /* inter-character timer unused */
+ stNewTIO.c_cc[VMIN] = 1; /* blocking read until 1 character arrives */
+ stNewTIO.c_cc[VSWTC] = 0; /* '\0' */
+ stNewTIO.c_cc[VSTART] = 0; /* Ctrl-q */
+ stNewTIO.c_cc[VSTOP] = 0; /* Ctrl-s */
+ stNewTIO.c_cc[VSUSP] = 0; /* Ctrl-z */
+ stNewTIO.c_cc[VEOL] = 0; /* '\0' */
+ stNewTIO.c_cc[VREPRINT] = 0; /* Ctrl-r */
+ stNewTIO.c_cc[VDISCARD] = 0; /* Ctrl-u */
+ stNewTIO.c_cc[VWERASE] = 0; /* Ctrl-w */
+ stNewTIO.c_cc[VLNEXT] = 0; /* Ctrl-v */
+ stNewTIO.c_cc[VEOL2] = 0; /* '\0' */
+
+ tcflush(m_nFD, TCIFLUSH);
+ tcsetattr(m_nFD, TCSANOW, &stNewTIO);
+
+ CFDSelectHandler::getInstance().addComCallback(m_nFD, this);
+ eRetVal = e_InitOk;
+
+ }
+ else{
+ DEVLOG_ERROR("CSerCommLayer: open failed: %s\n", strerror(errno));
+ }
+
+ return eRetVal;
+}
+
diff --git a/src/arch/posix/sercommlayer.h b/src/arch/posix/sercommlayer.h
new file mode 100644
index 000000000..fe6da0a00
--- /dev/null
+++ b/src/arch/posix/sercommlayer.h
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * Copyright (c) 2012, 2014 ACIN, fortiss GmbH
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#ifndef _SERCOMMLAYER_H_
+#define _SERCOMMLAYER_H_
+
+#include "comlayer.h"
+#include "../fdselecthand.h"
+#include
+
+class CSerCommLayer : public forte::com_infra::CComLayer{
+ public:
+ CSerCommLayer(forte::com_infra::CComLayer* pa_poUpperLayer, forte::com_infra::CCommFB * pa_poFB);
+ virtual ~CSerCommLayer();
+
+ virtual void closeConnection();
+ virtual forte::com_infra::EComResponse sendData(void *pa_pvData, unsigned int pa_unSize);
+ virtual forte::com_infra::EComResponse recvData(const void *pa_pvData, unsigned int pa_unSize);
+
+ virtual forte::com_infra::EComResponse processInterrupt();
+
+ protected:
+ private:
+ virtual forte::com_infra::EComResponse openConnection(char *pa_acLayerParameter);
+
+ CFDSelectHandler::TFileDescriptor m_nFD; //!< file descriptor for accessing the serial device
+
+ forte::com_infra::EComResponse m_eInterruptResp;
+ char m_acRecvBuffer[cg_unIPLayerRecvBufferSize];
+ unsigned int m_unBufFillSize;
+ struct termios m_stOldTIO; //!< buffer for the existing sercom settings
+
+};
+
+#endif /* CSERCOMMLAYER_H_ */
diff --git a/src/arch/posix/sockhand.h b/src/arch/posix/sockhand.h
new file mode 100644
index 000000000..2df95e2f1
--- /dev/null
+++ b/src/arch/posix/sockhand.h
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2010 - 2015 ACIN, fortiss GmbH
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#ifndef SOCKHAND_H_
+#define SOCKHAND_H_
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+
+//these include needs to be last
+#include "../fdselecthand.h"
+#include "../bsdsocketinterf.h"
+#include "../gensockhand.h"
+
+typedef CGenericIPComSocketHandler CIPComSocketHandler;
+
+#endif /* SOCKHAND_H_ */
diff --git a/src/arch/posix/sync.cpp b/src/arch/posix/sync.cpp
new file mode 100644
index 000000000..90efbf665
--- /dev/null
+++ b/src/arch/posix/sync.cpp
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * Copyright (c) 2005 - 2010 ACIN
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl, Rene Smodic - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#include "sync.h"
+
+CPCSyncObject::CPCSyncObject(){
+// m_oMutexHandle = PTHREAD_MUTEX_INITIALIZER;
+
+ pthread_mutexattr_t attr;
+ pthread_mutexattr_init(&attr);
+
+ #ifdef __CYGWIN__
+ pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
+ #else
+ pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE_NP);
+ #endif
+
+ pthread_mutex_init(&m_oMutexHandle, &attr);
+ //TODO handle return value
+ pthread_mutexattr_destroy(&attr);
+}
+
+CPCSyncObject::~CPCSyncObject(){
+ pthread_mutex_destroy(&m_oMutexHandle);
+ //TODO handle return value
+}
diff --git a/src/arch/posix/sync.h b/src/arch/posix/sync.h
new file mode 100644
index 000000000..b8faa9717
--- /dev/null
+++ b/src/arch/posix/sync.h
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * Copyright (c) 2005 - 2011 ACIN
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#ifndef _SYNC_H_
+#define _SYNC_H_
+
+#include
+
+#define CSyncObject CPCSyncObject //allows that doxygen can generate better documenation
+
+
+/*! \ingroup posix_hal
+ * \brief The sync object implementation for the posix thread interface.
+ *
+ * In the posix version a mutex is used for the sync object.
+ *
+ */
+
+class CPCSyncObject{
+ private:
+ protected:
+ //! The posix thread mutex handle of the operating system.
+ pthread_mutex_t m_oMutexHandle;
+ public:
+ CPCSyncObject();
+ ~CPCSyncObject();
+ /*!\brief Lock the resource coming after the lock command
+ *
+ * This function blocks until it will get the lock for the coming critical section.
+ */
+ void lock(void){
+ pthread_mutex_lock(&m_oMutexHandle);
+ //TODO handle return value
+ };
+ //!Freee the resource coming after the lock command
+ void unlock(void){
+ pthread_mutex_unlock(&m_oMutexHandle);
+ //TODO handle return value
+ };
+};
+
+#endif /*SYNC_H_*/
diff --git a/src/arch/posix/thread.cpp b/src/arch/posix/thread.cpp
new file mode 100644
index 000000000..ec064dfbc
--- /dev/null
+++ b/src/arch/posix/thread.cpp
@@ -0,0 +1,129 @@
+/*******************************************************************************
+ * Copyright (c) 2005 - 2014 ACIN, fortiss GmbH
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl, Rene Smodic, Martin Melik Merkiumians - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#include
+#include "thread.h"
+#include "../devlog.h"
+#include
+#include
+#include
+#include
+#include
+#include
+
+void CPosixThread::start(void){
+ // Get new Thread
+ if(0 == m_stThreadID){
+
+ //If the stackSize is not 0 we have to set it
+ if(m_nStackSize){
+ pthread_attr_t stAttr;
+
+ if(pthread_attr_init(&stAttr)){
+ DEVLOG_ERROR("Error could not get the default thread attributes! %s\n", strerror(errno));
+ return;
+ }
+ #ifdef __CYGWIN__
+ if (pthread_attr_setstacksize (&stAttr, m_nStackSize)){
+ DEVLOG_ERROR("Error could not set the stacksize for the thread! %s\n", strerror(errno));
+ return;
+ }
+ #else
+ //if (pthread_attr_setstacksize(&stAttr, m_nStackSize)) {
+ if(pthread_attr_setstack(&stAttr, m_pacStack, m_nStackSize)){
+ DEVLOG_ERROR("Error could not set the stacksize for the thread! %s\n", strerror(errno));
+ return;
+ }
+ #endif
+ if(pthread_create(&m_stThreadID, &stAttr, threadFunction, this)){
+ DEVLOG_ERROR("Error could not create the thread! %s\n", strerror(errno));
+ return;
+ }
+ if(pthread_attr_destroy(&stAttr)){
+ DEVLOG_ERROR("Error could not free the thread attributes! %s\n", strerror(errno));
+ return;
+ }
+ }
+ else{
+ if(pthread_create(&m_stThreadID, NULL, threadFunction, this)){
+ DEVLOG_ERROR("Error could not create the thread! %s\n", strerror(errno));
+ return;
+ }
+ }
+ }
+ //wait till the thread is up and running
+ do{
+ //pthread_yield();
+ sleep(1);
+ }while(!isAlive());
+}
+
+void * CPosixThread::threadFunction(void *arguments){
+ // Get pointer to CThread object out of void pointer
+ CPosixThread *pThread = (CPosixThread *) arguments;
+
+ // if pointer is ok
+ if(0 != pThread){
+ CCriticalRegion criticalRegion(pThread->mJoinMutex);
+ pThread->m_bAlive = true;
+ pThread->run();
+ pThread->m_bAlive = false;
+ pThread->m_stThreadID = 0;
+ }
+ else{
+ DEVLOG_ERROR("pThread pointer is 0!");
+ }
+ return 0;
+}
+
+CPosixThread::CPosixThread(long pa_nStackSize) :
+ m_bAlive(false), m_stThreadID(0), m_nStackSize(pa_nStackSize), m_pacStack(0){
+
+ if(0 != m_nStackSize){
+ m_pacStack = new char[m_nStackSize];
+ }
+
+ if(-1 == sem_init(&m_stSuspendSemaphore, 0, 0)){
+ DEVLOG_ERROR("Could not initialize suspend sempaphore: %s\n", strerror(errno));
+ }
+}
+
+CPosixThread::~CPosixThread(){
+ if(0 != m_stThreadID){
+ end();
+ }
+ if(0 != m_nStackSize){
+ delete[] m_pacStack;
+ }
+ sem_destroy(&m_stSuspendSemaphore);
+}
+
+void CPosixThread::setDeadline(const CIEC_TIME &pa_roVal){
+ m_oDeadline = pa_roVal;
+ //under the posix pthread implemention currently it makes no sense to set any priority.
+ //It will not be considered.
+}
+
+void CPosixThread::resumeSelfSuspend(void){
+ sem_post(&m_stSuspendSemaphore);
+}
+
+void CPosixThread::join(void){
+ if(0 != m_stThreadID){
+ CCriticalRegion criticalRegion(mJoinMutex);
+ }
+}
+
+void CPosixThread::selfSuspend(void) {
+ int n;
+ do{
+ n = sem_wait(&m_stSuspendSemaphore);
+ }while( (-1 == n) && (errno == EINTR) ); //handle interrupts from signals
+}
diff --git a/src/arch/posix/thread.h b/src/arch/posix/thread.h
new file mode 100644
index 000000000..f9c8798bd
--- /dev/null
+++ b/src/arch/posix/thread.h
@@ -0,0 +1,161 @@
+/*******************************************************************************
+ * Copyright (c) 2006 - 2015 ACIN, fortiss GmbH
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl, Rene Smodic, Ingo Hegny, Martin Melik Merkiumians - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#ifndef _THREAD_H_
+#define _THREAD_H_
+
+#include
+#include
+#include "../datatype.h"
+#include "../../core/datatypes/forte_time.h"
+#include
+
+/** \ingroup FORTE-HAL
+ * \defgroup posix_hal PC FORTE Hardware Abstraction Layer
+ *
+ * \brief The FORTE-HAL implementation for normal PCs
+ *
+ * It will mainly work under linux or linux similar environments like cygwin.
+ */
+
+/*! \ingroup posix_hal
+ * \brief The thread implementation for the posix thread interface.
+ */
+class CPosixThread {
+ public:
+ /*! \brief Constructor of the Thread class
+ *
+ * Does all the necessary steps in order to get the thread running with the start()-method
+ * @param pa_nStackSize the Size of the stack the thread is allowed to use. 0 means use system default stack size.
+ * If you like to set this value it is best to use the form: PTHREAD_STACK_MIN + additional bytes you need.
+ */
+ CPosixThread(long pa_nStackSize = 0);
+
+ /*! \brief Stops and destroys thread.
+ *
+ * Will stop the execution if running and destroy the thread including all system specific data.
+ */
+ virtual ~CPosixThread();
+
+ /*! \brief Indicates if the thread is allowed to execute.
+ *
+ * This functions checks if the Thread is still executing user code in its run()-method.
+ * \return true if there the run method is active.
+ */
+ bool isAlive(void) const {
+ return m_bAlive;
+ }
+ //!Set the deadline of the thread.
+ void setDeadline(const CIEC_TIME &pa_roVal);
+
+ //!Get the current deadline of the thread.
+ const CIEC_TIME &getDeadline(void) const {
+ return m_oDeadline;
+ }
+
+ /*! \brief starts the Thread
+ *
+ * By calling this method the execution in the run()-Method will be started.
+ */
+ void start(void);
+
+ /*! \brief Resumes a suspended Thread
+ *
+ *
+ */
+ void resumeSelfSuspend(void);
+
+ /*! \brief Stops the execution of the thread
+ *
+ * This function immediately stops the execution of the thread (setting m_bAlive to false) and waits till
+ * this is finished.
+ */
+ void end(void){
+ m_bAlive = false;
+ resumeSelfSuspend();
+ join();
+ }
+
+ /*! \brief Waits for the Thread to finish its execution.
+ *
+ * This function waits till the execution in the thread decides to end the execution. Blocks the caller!!!
+ */
+ void join(void); // Waits
+ protected:
+ /*! \brief Suspends the thread.
+ *
+ * Suspends the execution of the thread until resumeSelfSuspend(), end(), or join() is called.
+ */
+ void selfSuspend();
+
+ void setAlive(bool paAlive){
+ m_bAlive = paAlive;
+ }
+
+ private:
+ /*!\brief Function that is given to the system thread support that should be called for the thread.
+ *
+ * this function will call the run method of the thread instance.
+ */
+ static void * threadFunction(void *arguments);
+
+ /*! \brief Abstract method for the code to execute in the thread.
+ *
+ * This thread class has to provide means that the code a inheriting class will add to the run()-method will
+ * be executed in a separated thread regarding the creator of the CThread class.
+ *
+ * The inheriting class has to fulfill the following rules when using the run method:
+ * - To end the thread execution simple leave the run()-method
+ * - In order to allow the deletion and stopping of the thread add frequent checks to isAlive and end the
+ * execution if isAlive() returns false.
+ */
+ virtual void run() = 0;
+
+ /*! \brief Flag that indicates if the Thread is alive.
+ *
+ * This flag has two main purposes:
+ * -# indicate for other classes if the thread is still executing
+ * -# use in the run()-method to check if the thread is still allowed to execute (e.g. while(isAlive()) ).
+ * This is important for stopping and destroying threads.
+ */
+ bool m_bAlive;
+
+ //!deadline the thread needs to be finish its execution. 0 means unconstrained.
+ CIEC_TIME m_oDeadline;
+
+ sem_t m_stSuspendSemaphore;
+
+ CPCSyncObject mJoinMutex;
+
+ /*! \brief data needed for posix scheduling system to identify the thread.
+ */
+ pthread_t m_stThreadID;
+ /*! \brief Size of the stack used by this thread.
+ */
+ long m_nStackSize;
+
+ /*! \brief Pointer to the memory to be used for this thread'm_stSuspendSemaphore stack
+ *
+ * This pointer is only not 0 if m_nStackSize is not 0
+ */
+ char *m_pacStack;
+
+ //we don't want that threads can be copied or assigned therefore the copy constructor and assignment operator are declared private
+ //but not implemented
+ CPosixThread(const CPosixThread&);
+ CPosixThread& operator = (const CPosixThread &);
+
+};
+
+
+typedef CPosixThread CThread; //allows that doxygen can generate better documentation
+
+#endif /*THREAD_H_*/
+
diff --git a/src/arch/timerha.cpp b/src/arch/timerha.cpp
new file mode 100644
index 000000000..67052f93a
--- /dev/null
+++ b/src/arch/timerha.cpp
@@ -0,0 +1,113 @@
+/*******************************************************************************
+ * Copyright (c) 2005 - 2015 ACIN, Profactor GmbH, fortiss GmbH
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl, Rene Smodic, Thomas Strasser, Ingo Hegny
+ * - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#include "timerha.h"
+#include "../core/devexec.h"
+#include "../core/esfb.h"
+#include
+
+CTimerHandler *CTimerHandler::sm_poFORTETimer = 0;
+
+void CTimerHandler::registerTimedFB(STimedFBListEntry *pa_pstTimerListEntry, const CIEC_TIME &pa_roTimeInterval) {
+ //calculate the correct interval based on time-base and timer ticks per seconds
+ pa_pstTimerListEntry->m_nInterval = static_cast((pa_roTimeInterval * getTicksPerSecond()) / FORTE_TIME_BASE_UNITS_PER_SECOND);
+ {
+ CCriticalRegion criticalRegion(m_oSync);
+ addTimedFBEntry(pa_pstTimerListEntry);
+ }
+}
+
+void CTimerHandler::addTimedFBEntry(STimedFBListEntry *pa_pstTimerListEntry) {
+ pa_pstTimerListEntry->m_stTimeOut = m_stForteTime;
+ pa_pstTimerListEntry->m_stTimeOut += pa_pstTimerListEntry->m_nInterval; // the next activationtime of this FB
+ pa_pstTimerListEntry->m_pstNext = 0;
+
+ // Correct null intervals that can lead to event queue overflow to 10 ms
+ if (pa_pstTimerListEntry->m_nInterval == 0)
+ pa_pstTimerListEntry->m_stTimeOut += getTicksPerSecond() > 100 ? getTicksPerSecond() / 100 : 1;
+
+ if (0 == m_pstTimedFBList) {
+ m_pstTimedFBList = pa_pstTimerListEntry;
+ } else {
+ if (m_pstTimedFBList->m_stTimeOut > pa_pstTimerListEntry->m_stTimeOut) {
+ pa_pstTimerListEntry->m_pstNext = m_pstTimedFBList;
+ m_pstTimedFBList = pa_pstTimerListEntry;
+ } else {
+ STimedFBListEntry *runner = m_pstTimedFBList;
+ while (0 != runner->m_pstNext) {
+ if (runner->m_pstNext->m_stTimeOut > pa_pstTimerListEntry->m_stTimeOut) {
+ pa_pstTimerListEntry->m_pstNext = runner->m_pstNext;
+ runner->m_pstNext = pa_pstTimerListEntry;
+ break;
+ }
+ runner = runner->m_pstNext;
+ }
+ runner->m_pstNext = pa_pstTimerListEntry;
+ }
+ }
+}
+
+void CTimerHandler::unregisterTimedFB(CEventSourceFB *pa_poTimedFB) {
+ CCriticalRegion criticalRegion(m_oSync);
+ STimedFBListEntry *buffer = 0;
+ if (0 != m_pstTimedFBList) {
+ if (m_pstTimedFBList->m_poTimedFB == pa_poTimedFB) {
+ buffer = m_pstTimedFBList;
+ m_pstTimedFBList = m_pstTimedFBList->m_pstNext;
+ buffer->m_pstNext = 0;
+ buffer->m_stTimeOut.m_nLowerValue = 0;
+ buffer->m_stTimeOut.m_nUpperValue = 0;
+ } else {
+ STimedFBListEntry *runner = m_pstTimedFBList;
+ while (0 != runner->m_pstNext) {
+ if (runner->m_pstNext->m_poTimedFB == pa_poTimedFB) {
+ buffer = runner->m_pstNext;
+ runner->m_pstNext = runner->m_pstNext->m_pstNext;
+ buffer->m_pstNext = 0;
+ buffer->m_stTimeOut.m_nLowerValue = 0;
+ buffer->m_stTimeOut.m_nUpperValue = 0;
+ break;
+ }
+ runner = runner->m_pstNext;
+ }
+ }
+ }
+}
+
+void CTimerHandler::nextTick(void) {
+ ++m_stForteTime;
+ getDeviceExecution()->notifyTime(m_stForteTime); //notify the device execution that one tick passed by.
+ {
+ CCriticalRegion criticalRegion(m_oSync);
+ while (0 != m_pstTimedFBList) {
+ if (m_pstTimedFBList->m_stTimeOut > m_stForteTime) {
+ break;
+ }
+ getDeviceExecution()->startNewEventChain(m_pstTimedFBList->m_poTimedFB);
+ STimedFBListEntry *buffer = m_pstTimedFBList;
+ m_pstTimedFBList = m_pstTimedFBList->m_pstNext;
+
+ switch (buffer->m_eType) {
+ case e_Periodic:
+ addTimedFBEntry(buffer); //reregister the timed FB
+ break;
+ case e_SingleShot:
+ // nothing special is to do up to now
+ default:
+ buffer->m_pstNext = 0;
+ buffer->m_stTimeOut.m_nLowerValue = 0;
+ buffer->m_stTimeOut.m_nUpperValue = 0;
+ break;
+ }
+ }
+ }
+}
+
diff --git a/src/arch/timerha.h b/src/arch/timerha.h
new file mode 100644
index 000000000..d484c3cce
--- /dev/null
+++ b/src/arch/timerha.h
@@ -0,0 +1,176 @@
+/*******************************************************************************
+ * Copyright (c) 2005 - 2015 ACIN, Profactor GmbH, fortiss GmbH
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl, Thomas Strasser, Rene Smodic, Monika Wenger, Ingo Hegny
+ * - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#ifndef _TIMERHA_H_
+#define _TIMERHA_H_
+
+#include
+#include "../core/extevhan.h"
+#include "../core/utils/singlet.h"
+#include "../core/datatypes/forte_time.h"
+#include
+
+class CEventSourceFB;
+
+enum ETimerActivationType{
+ e_SingleShot, e_Periodic
+};
+
+struct SForteTime{
+ TForteUInt32 m_nLowerValue;
+ TForteUInt32 m_nUpperValue;
+
+ SForteTime(){
+ m_nLowerValue = m_nUpperValue = 0;
+ }
+
+ SForteTime &operator++(){ //++i;
+ ++m_nLowerValue;
+ if(0 == m_nLowerValue)
+ ++m_nUpperValue;
+ return *this;
+ }
+ SForteTime& operator=(const SForteTime &pa_stRightVal){
+ m_nLowerValue = pa_stRightVal.m_nLowerValue;
+ m_nUpperValue = pa_stRightVal.m_nUpperValue;
+ return *this;
+ }
+
+ SForteTime& operator+=(TForteUInt32 pa_nRightVal){
+ TForteUInt32 nBuf = m_nLowerValue;
+ m_nLowerValue += pa_nRightVal;
+ if(nBuf > m_nLowerValue)
+ ++m_nUpperValue;
+ return *this;
+ }
+
+ SForteTime& operator-=(TForteUInt32 pa_nRightVal){
+ TForteUInt32 nBuf = m_nLowerValue;
+ m_nLowerValue -= pa_nRightVal;
+ if(nBuf < m_nLowerValue)
+ --m_nUpperValue;
+ return *this;
+ }
+
+ SForteTime& operator-=(const SForteTime& pa_nRightVal){
+ m_nUpperValue -= pa_nRightVal.m_nUpperValue;
+ if(m_nLowerValue < pa_nRightVal.m_nLowerValue){
+ --m_nUpperValue;
+ --m_nLowerValue;
+ }
+ m_nLowerValue -= pa_nRightVal.m_nLowerValue;
+ return *this;
+ }
+
+ bool operator>(const SForteTime &pa_stRightVal) const{
+ bool bRetVal = false;
+ if((m_nUpperValue > pa_stRightVal.m_nUpperValue) || ((m_nUpperValue == pa_stRightVal.m_nUpperValue) && (m_nLowerValue > pa_stRightVal.m_nLowerValue))){
+ bRetVal = true;
+ }
+ return bRetVal;
+ }
+
+ bool operator==(const SForteTime &pa_stRightVal) const{
+ return m_nUpperValue == pa_stRightVal.m_nUpperValue && m_nLowerValue == pa_stRightVal.m_nLowerValue;
+ }
+};
+
+inline const SForteTime operator-(const SForteTime &pa_nLeftVal, const SForteTime &pa_nRightVal){
+ SForteTime oRetVal(pa_nLeftVal);
+ oRetVal -= pa_nRightVal;
+ return oRetVal;
+}
+
+//! Data stored for each FB that is registered to the timer handler
+struct STimedFBListEntry{
+ SForteTime m_stTimeOut; //!< absolut time when the next trigger of the FB should occure
+ CEventSourceFB *m_poTimedFB; //!< Functionblock to be triggered
+ TForteUInt32 m_nInterval; //!< relative time between FB trigger points (mainly needed for the different periodic timed FBs)
+ ETimerActivationType m_eType; //!< type of activation. e.g. singleshot, periodic, ...
+ STimedFBListEntry *m_pstNext; //!< pointer to the next entry in the list
+};
+
+/*! \brief External event handler for the Timer.
+ * \ingroup EXTEVHAND
+ */
+class CTimerHandler : public CExternalEventHandler{
+ public:
+
+ virtual ~CTimerHandler(){
+ }
+ ;
+
+ /*!\brief Pointer to the instance of the concrete forte timer
+ */
+ static CTimerHandler *sm_poFORTETimer;
+ /*!\brief create the timer handler and set the pointer of sm_poFORTETimer to the new timer handler.
+ *
+ * This function is not implemented in the standardtimerhandler and has to be implemented in the specific implementation.
+ * implementations should check that not two timerhanlders can be created.
+ */
+ static void createTimerHandler(void);
+
+ /*!\brief Sets the priority of the event source
+ *
+ * \param pa_nPriority new priority of the event source
+ */
+ virtual void setPriority(int pa_nPriority) = 0;
+ /*!\brief Get the current priority of the event source
+ *
+ * \return current priority
+ */
+ virtual int getPriority(void) const = 0;
+
+ /*! \brief Get the time base of the runtime
+ *
+ * \return internal runtime ticks per second
+ */
+ static TForteUInt32 getTicksPerSecond(void){
+ return cg_nForteTicksPerSecond;
+ }
+ ;
+
+ /*!\brief Register an Event source Functionblock to this external event source.
+ *
+ * \param pa_pstTimerListEntry TimerListEntry data
+ * \param pa_roTimeInterval time interval to next event
+ */
+ void registerTimedFB(STimedFBListEntry *pa_pstTimerListEntry, const CIEC_TIME &pa_roTimeInterval);
+ /*!\brief Unregister an FB from an the timmer
+ *
+ * \param pa_poTimedFB FB to unregister from this external event handler
+ */
+ void unregisterTimedFB(CEventSourceFB *pa_poTimedFB);
+ //! one tick of time elapsed. Implementations should call this function on each tick.
+ void nextTick(void);
+ //! returns the time since startup of FORTE
+ const SForteTime &getForteTime() const{
+ return m_stForteTime;
+ }
+ protected:
+ CSyncObject m_oSync;
+
+ //! private constructor that allows that no other object can create an timerhandler
+ CTimerHandler() : m_pstTimedFBList(0){
+ }
+ ;
+ private:
+ /*!\brief The runtime time in tics till last reboot.
+ */
+ SForteTime m_stForteTime;
+ //! List of function blocks currently registered to the timer handler
+ STimedFBListEntry *m_pstTimedFBList;
+ //!Add an entry to the timed list.
+ void addTimedFBEntry(STimedFBListEntry *pa_pstTimerListEntry);
+
+};
+
+#endif /*TIMERHA_H_*/
diff --git a/src/arch/win32/CMakeLists.txt b/src/arch/win32/CMakeLists.txt
new file mode 100644
index 000000000..b28a4eec1
--- /dev/null
+++ b/src/arch/win32/CMakeLists.txt
@@ -0,0 +1,60 @@
+#*******************************************************************************
+# * Copyright (c) 2010 - 2015 ACIN, Profactor GmbH, fortiss GmbH
+# * All rights reserved. This program and the accompanying materials
+# * are made available under the terms of the Eclipse Public License v1.0
+# * which accompanies this distribution, and is available at
+# * http://www.eclipse.org/legal/epl-v10.html
+# *
+# * Contributors:
+# * Alois Zoitl, Gerhard Ebenhofer, Martin Melik-Merkumians - initial API and implementation and/or initial documentation
+# *******************************************************************************/
+
+SET(SOURCE_GROUP ${SOURCE_GROUP}\\win32)
+
+forte_add_architecture(Win32)
+
+if("${FORTE_ARCHITECTURE}" STREQUAL "Win32")
+
+ add_subdirectory ( serlayer )
+ forte_add_include_directories(${CMAKE_CURRENT_SOURCE_DIR})
+
+ forte_add_sourcefile_h(fortealloc.h)
+ forte_add_sourcefile_hcpp(thread sync)
+ forte_add_sourcefile_cpp(main.cpp)
+
+ if(${FORTE_BUILD_TYPE} STREQUAL SHARED_LIBRARY)
+ set(FORTE_EXTERNAL_TIMEHA ON CACHE BOOL "Use External Time Handler")
+ if(FORTE_EXTERNAL_TIMEHA)
+ forte_add_sourcefile_hcpp(externtimeha)
+ else(FORTE_EXTERNAL_TIMEHA)
+ forte_add_sourcefile_hcpp(pctimeha)
+ endif(FORTE_EXTERNAL_TIMEHA)
+ else(${FORTE_BUILD_TYPE} STREQUAL SHARED_LIBRARY)
+ unset(FORTE_EXTERNAL_TIMEHA CACHE)
+ forte_add_sourcefile_hcpp(pctimeha)
+ endif(${FORTE_BUILD_TYPE} STREQUAL SHARED_LIBRARY)
+
+
+ if(FORTE_COM_ETH)
+ forte_add_sourcefile_hcpp( ../fdselecthand ../bsdsocketinterf)
+ forte_add_sourcefile_h(../gensockhand.h)
+ forte_add_sourcefile_h(sockhand.h)
+ endif(FORTE_COM_ETH)
+
+ forte_add_include_directories(../${CMAKE_CURRENT_SOURCE_DIR})
+ forte_add_include_directories(${CMAKE_CURRENT_SOURCE_DIR})
+
+ SET(CMAKE_CXX_FLAGS_RELEASE "/MT" )
+ forte_add_definition("-DFORTE_LITTLE_ENDIAN") # -DNONAMESPACE -DWITH_NONAMESPACES)
+
+# TODO this flag was originaly wrongly added to the definitions. May be necessary to be added as link flag. However currently working fine.
+# forte_add_link_flags("/NODEFAULTLIB:MSVCRT.lib")
+
+ forte_add_link_library(comctl32.lib)
+ forte_add_link_library(rpcrt4.lib)
+ forte_add_link_library(winmm.lib)
+ forte_add_link_library(Ws2_32.lib)
+ forte_add_link_library(version.lib)
+
+
+endif()
diff --git a/src/arch/win32/externtimeha.cpp b/src/arch/win32/externtimeha.cpp
new file mode 100644
index 000000000..fe3f6d8e5
--- /dev/null
+++ b/src/arch/win32/externtimeha.cpp
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * Copyright (c) 2011, 2013 Profactor GmbH, fortiss GmbH
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Gerhard Ebenhofer, Alois Zoitl - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#include "externtimeha.h"
+#include "../../core/devexec.h"
+#include
+
+
+const TForteInt32 CExternTimerHandler::csm_nTicksPerSecond = 1000;
+
+extern "C" __declspec(dllexport)
+void __stdcall nextTick(void){
+ CExternTimerHandler::externNextTick();
+}
+
+extern "C" __declspec(dllexport)
+unsigned int __stdcall getTicksPerSecond(){
+ return CExternTimerHandler::getExternTicksPerSecond();
+}
+
+void CTimerHandler::createTimerHandler(void){
+ if(0 == sm_poFORTETimer)
+ sm_poFORTETimer = new CExternTimerHandler();
+
+}
+
+CExternTimerHandler::CExternTimerHandler(){
+}
+
+CExternTimerHandler::~CExternTimerHandler(){
+ disableHandler();
+}
+
+void CExternTimerHandler::externNextTick(){
+ if(0 != sm_poFORTETimer){
+ sm_poFORTETimer->nextTick();
+ }
+}
+
+
+void CExternTimerHandler::enableHandler(void){
+ //TODO think on hwo to handle this.
+}
+
+void CExternTimerHandler::disableHandler(void){
+ //TODO think on hwo to handle this.
+}
+
+void CExternTimerHandler::setPriority(int pa_nPriority){
+ //TODO think on hwo to handle this.
+}
+
+int CExternTimerHandler::getPriority(void) const{
+ //TODO think on hwo to handle this.
+ return 1;
+}
diff --git a/src/arch/win32/externtimeha.h b/src/arch/win32/externtimeha.h
new file mode 100644
index 000000000..e38fd2fa9
--- /dev/null
+++ b/src/arch/win32/externtimeha.h
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Profactor GmbH
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Gerhard Ebenhofer - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#ifndef _PCTIMEHA_H_
+#define _PCTIMEHA_H_
+
+#include "timerha.h"
+
+/*! \ingroup pc_hal
+ *\ingroup EXTEVHAND
+ *\brief the timer handler for the pc architecture.
+*/
+class CExternTimerHandler : public CTimerHandler{
+ private:
+ /*!\brief default time base of the used timer. in useconds.
+ */
+ static const TForteInt32 csm_nTicksPerSecond;
+ /*!\brief callback function for the system timer
+ */
+
+ public:
+ static void externNextTick();
+ static TForteUInt32 getExternTicksPerSecond(void){ return csm_nTicksPerSecond; };
+ CExternTimerHandler();
+
+ virtual ~CExternTimerHandler();
+
+
+ /*!\brief Enables this event source
+ *
+ */
+ virtual void enableHandler(void);
+ /*!\brief Disable this event source
+ */
+ virtual void disableHandler(void);
+ /*!\brief Sets the priority of the event source
+ *
+ * \param pa_nPriority new priority of the event source
+ */
+ virtual void setPriority(int pa_nPriority);
+ /*!\brief Get the current priority of the event source
+ *
+ * \return current priority
+ */
+ virtual int getPriority(void) const;
+
+ /*! \brief Get the time base of the runtime
+ *
+ * \return internal runtime ticks per millisecond
+ */
+ virtual TForteUInt32 getTicksPerSecond(void){ return csm_nTicksPerSecond; };
+
+
+};
+
+#endif /*PCTIMEHA_H_*/
diff --git a/src/arch/win32/fortealloc.h b/src/arch/win32/fortealloc.h
new file mode 100644
index 000000000..eb53c165c
--- /dev/null
+++ b/src/arch/win32/fortealloc.h
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Copyright (c) 2010 - 2014 ACIN, Profactor GmbH, fortiss GmbH
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl, Gerhard Ebenhofer - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#ifndef FORTEALLOC_H_
+#define FORTEALLOC_H_
+
+//on win32 environments use default new operator
+#include
+#include
+
+inline
+void forte_free(void *pa_pvData){
+ free(pa_pvData);
+}
+
+inline
+void *forte_malloc(size_t pa_nSize){
+ return malloc(pa_nSize);
+}
+
+inline
+void *forte_realloc(void *pa_pvData, size_t pa_nSize){
+ return realloc(pa_pvData, pa_nSize);
+}
+
+
+#endif /* FORTEALLOC_H_ */
diff --git a/src/arch/win32/main.cpp b/src/arch/win32/main.cpp
new file mode 100644
index 000000000..47bb8a54b
--- /dev/null
+++ b/src/arch/win32/main.cpp
@@ -0,0 +1,104 @@
+/*******************************************************************************
+ * Copyright (c) 2010 - 2012 ACIN, Profactor GmbH
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl, Ingo Hegny, Gerhard Ebenhofer - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#include
+#include
+#include
+#include
+#ifdef WIN32
+#include
+#endif
+#ifdef FORTE_FBTESTS
+#include
+#endif
+
+//this keeps away a lot of rtti and exception handling stuff
+extern "C" void
+__cxa_pure_virtual(void) {
+ //TODO maybe add some reporting here
+ //Although we should never get here
+ //if we are here something very very bad has happened e.g., stack overflow or other memory corruption
+
+}
+
+RMT_DEV *poDev = 0;
+
+void endForte(int pa_nSig){
+ (void)pa_nSig;
+ if(0 != poDev){
+ poDev->changeFBExecutionState(cg_nMGM_CMD_Kill);
+ }
+}
+
+/*!\brief Creates the Device-Object
+ * \param pa_acMGRID A string containing IP and Port like [IP]:[Port]
+ */
+void createDev(const char *pa_acMGRID) {
+
+ signal(SIGINT, endForte);
+ signal(SIGTERM, endForte);
+
+ poDev = new RMT_DEV;
+
+ #ifdef FORTE_FBTESTS
+ CFBTestsManager::getInstance().runAllTests();
+ #endif
+
+ poDev->setMGR_ID(pa_acMGRID);
+ poDev->startDevice();
+ poDev->MGR.getResourceEventExecution()->joinEventChainExecutionThread();
+ delete poDev;
+}
+
+/*!\brief Lists the help for FORTE
+ *
+ */
+void listHelp() {
+ printf("\nUsage of FORTE:\n");
+ printf(" -h\t lists this help.\n");
+ printf("\n");
+ printf(" -c\t sets the destination for the connection.\n");
+ printf(" \t Usage: forte -c :");
+ printf("\n");
+}
+
+#ifdef FORTE_SHARED_LIB
+extern "C" __declspec(dllexport) int __stdcall main(int argc, char *arg[]) {
+#else
+ int main(int argc, char *arg[]) {
+#endif
+ #ifdef WIN32
+ // Windows Socket Startupcode
+ WORD wVersionRequested;
+ WSADATA wsaData;
+
+ /* Use the MAKEWORD(lowbyte, highbyte) macro declared in Windef.h */
+ wVersionRequested = MAKEWORD(2, 2);
+
+ WSAStartup(wVersionRequested, &wsaData);
+ #endif
+
+ if (argc <= 1) { //! Default Value (localhost:61499)
+ createDev("localhost:61499");
+ }
+ else {
+ if (strcmp("-c", arg[1]) == 0) { //! sets the destination for the connection
+ createDev(arg[2]);
+ }
+ else { //! Lists the help for FORTE
+ listHelp();
+ }
+ }
+
+ #ifdef WIN32
+ WSACleanup();
+ #endif
+ return 0;
+}
diff --git a/src/arch/win32/pctimeha.cpp b/src/arch/win32/pctimeha.cpp
new file mode 100644
index 000000000..864ff4b4f
--- /dev/null
+++ b/src/arch/win32/pctimeha.cpp
@@ -0,0 +1,137 @@
+/*******************************************************************************
+ * Copyright (c) 2010, 2011 ACIN, Profactor GmbH
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl, Gerhard Ebenhofer - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#include "pctimeha.h"
+#include "../../core/devexec.h"
+//#include
+#define WIN32_LEAN_AND_MEAN
+#include
+
+const TForteInt32 CPCTimerHandler::csm_nTicksPerSecond = 1000;
+
+void CTimerHandler::createTimerHandler(void){
+ if(0 == sm_poFORTETimer)
+ sm_poFORTETimer = new CPCTimerHandler();
+
+}
+
+CPCTimerHandler::CPCTimerHandler(){
+}
+
+CPCTimerHandler::~CPCTimerHandler(){
+ disableHandler();
+}
+
+/*
+ HANDLE gDoneEvent;
+
+ VOID CALLBACK TimerRoutine(PVOID lpParam, BOOLEAN TimerOrWaitFired)
+ {
+ CPCTimerHandler *timerHandler = (CPCTimerHandler*) lpParam;
+ if(timerHandler != 0){
+ if(timerHandler->isAlive() ){
+ timerHandler->nextTick();
+ }
+ else{
+ SetEvent(gDoneEvent);
+ }
+ }
+ }
+
+
+ bool CPCTimerHandler::run(){
+
+ HANDLE hTimer = NULL;
+
+ // Use an event object to track the TimerRoutine execution
+ gDoneEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
+ if (NULL == gDoneEvent){
+ return false;
+ }
+
+ // Set a timer to call the timer routine in 10 seconds.
+ if (!CreateTimerQueueTimer( &hTimer, 0, (WAITORTIMERCALLBACK)TimerRoutine, this, 0, 1000 / CPCTimerHandler::csm_nTicksPerSecond, 0))
+ {
+ return false;
+ }
+
+ if (WaitForSingleObject(gDoneEvent, INFINITE) != WAIT_OBJECT_0)
+ return false;
+
+ DeleteTimerQueueTimer(0, hTimer,0);
+
+ CloseHandle(gDoneEvent);
+
+
+ return true;
+ }*/
+
+void CPCTimerHandler::run(){
+ DWORD stReq = 0; // in us
+ LARGE_INTEGER stReqTimeVal = { 0, 0 };
+
+ LARGE_INTEGER stFrequenzy = { 0, 0 }; // clocks per second
+ LARGE_INTEGER stElapsed1 = { 0, 0 };
+ LARGE_INTEGER stElapsed2 = { 0, 0 };
+ LARGE_INTEGER stError = { 0, 0 };
+ LARGE_INTEGER stISum = { 0, 0 };
+ LARGE_INTEGER stWaittime = { 0, 0 };
+
+ QueryPerformanceFrequency(&stFrequenzy);
+ QueryPerformanceCounter(&stElapsed1);
+
+ stReqTimeVal.QuadPart = stFrequenzy.QuadPart / CPCTimerHandler::csm_nTicksPerSecond;
+ //stReqTimeVal = 1000000 / CPCTimerHandler::csm_nTicksPerSecond;
+
+ while(m_bAlive){
+ stWaittime.QuadPart *= 1000; // calculate in ms, not sec
+ stReq = (stWaittime.QuadPart / stFrequenzy.QuadPart); // calculate elapsed time in ms
+
+ // dont give up the thread if we still have to do some ticks(some os have 10ms minimum threadtime)
+ if(stReq > 0){
+ Sleep(stReq);
+ }
+ nextTick();
+
+ // sample new time
+ stElapsed2.QuadPart = stElapsed1.QuadPart;
+ QueryPerformanceCounter(&stElapsed1);
+
+ // calulate controler error: Diff - Setupvalue = Error
+ stError.QuadPart = stElapsed1.QuadPart - stElapsed2.QuadPart;
+ stError.QuadPart = stReqTimeVal.QuadPart - stError.QuadPart;
+
+ // I-controller
+ stISum.QuadPart += stError.QuadPart;
+
+ // calculate new Output
+ stWaittime.QuadPart = stReqTimeVal.QuadPart + stISum.QuadPart;
+ if(stWaittime.QuadPart < 0){
+ stWaittime.QuadPart = 0;
+ }
+ }
+}
+
+void CPCTimerHandler::enableHandler(void){
+ start();
+}
+
+void CPCTimerHandler::disableHandler(void){
+ end();
+}
+
+void CPCTimerHandler::setPriority(int pa_nPriority){
+ //TODO think on hwo to handle this.
+}
+
+int CPCTimerHandler::getPriority(void) const{
+ //TODO think on hwo to handle this.
+ return 1;
+}
diff --git a/src/arch/win32/pctimeha.h b/src/arch/win32/pctimeha.h
new file mode 100644
index 000000000..c709059e9
--- /dev/null
+++ b/src/arch/win32/pctimeha.h
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * Copyright (c) 2010, 2011 ACIN, Profactor GmbH
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl, Gerhard Ebenhofer - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#ifndef _PCTIMEHA_H_
+#define _PCTIMEHA_H_
+
+#include "thread.h"
+#include "../timerha.h"
+
+/*! \ingroup win32_hal
+ *\ingroup EXTEVHAND
+ *\brief the timer handler for the pc architecture.
+*/
+class CPCTimerHandler : public CTimerHandler, public CThread{
+ private:
+ /*!\brief default time base of the used timer. in useconds.
+ */
+ static const TForteInt32 csm_nTicksPerSecond;
+ /*!\brief callback function for the system timer
+ */
+
+ public:
+ CPCTimerHandler();
+
+ virtual ~CPCTimerHandler();
+
+ virtual void run();
+
+ /*!\brief Enables this event source
+ *
+ */
+ virtual void enableHandler(void);
+ /*!\brief Disable this event source
+ */
+ virtual void disableHandler(void);
+ /*!\brief Sets the priority of the event source
+ *
+ * \param pa_nPriority new priority of the event source
+ */
+ virtual void setPriority(int pa_nPriority);
+ /*!\brief Get the current priority of the event source
+ *
+ * \return current priority
+ */
+ virtual int getPriority(void) const;
+
+ /*! \brief Get the time base of the runtime
+ *
+ * \return internal runtime ticks per millisecond
+ */
+ virtual TForteUInt32 getTicksPerSecond(void){ return csm_nTicksPerSecond; };
+
+
+};
+
+#endif /*PCTIMEHA_H_*/
diff --git a/src/arch/win32/serlayer/CMakeLists.txt b/src/arch/win32/serlayer/CMakeLists.txt
new file mode 100644
index 000000000..dbf20a43e
--- /dev/null
+++ b/src/arch/win32/serlayer/CMakeLists.txt
@@ -0,0 +1,15 @@
+#*******************************************************************************
+# * Copyright (c) 2013 ACIN
+# * All rights reserved. This program and the accompanying materials
+# * are made available under the terms of the Eclipse Public License v1.0
+# * which accompanies this distribution, and is available at
+# * http://www.eclipse.org/legal/epl-v10.html
+# *
+# * Contributors:
+# * Martin Melik-Merkumians - initial API and implementation and/or initial documentation
+# *******************************************************************************/
+forte_add_network_layer(SER OFF "ser" CWin32SerComLayer cwin32sercomlayer "Enable Forte serial line communication")
+if(FORTE_COM_SER)
+ forte_add_sourcefile_hcpp( cwin32sercomhandler )
+ forte_add_include_directories(${CMAKE_CURRENT_SOURCE_DIR})
+endif(FORTE_COM_SER)
\ No newline at end of file
diff --git a/src/arch/win32/serlayer/cwin32sercomhandler.cpp b/src/arch/win32/serlayer/cwin32sercomhandler.cpp
new file mode 100644
index 000000000..95bb4a5f8
--- /dev/null
+++ b/src/arch/win32/serlayer/cwin32sercomhandler.cpp
@@ -0,0 +1,84 @@
+/*******************************************************************************
+ * Copyright (c) 2013, 2014 ACIN, fortiss GmbH
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Melik-Merkumians, Alois Zoitl - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#include "cwin32sercomhandler.h"
+#include "cwin32sercomlayer.h"
+#include
+#include
+#define WIN32_LEAN_AND_MEAN
+#include
+
+DEFINE_SINGLETON(CWin32SerComHandler);
+
+CWin32SerComHandler::CWin32SerComHandler() {
+}
+
+CWin32SerComHandler::~CWin32SerComHandler(){
+ this->end();
+}
+
+void CWin32SerComHandler::registerSerComLayer(CWin32SerComLayer *pa_poComLayer){
+ m_oSync.lock();
+ m_lstComLayerList.push_back(pa_poComLayer);
+ m_oSync.unlock();
+ if(!isAlive()){
+ this->start();
+ }
+ resumeSelfSuspend();
+}
+
+void CWin32SerComHandler::unregisterSerComLayer(CWin32SerComLayer *pa_poComLayer){
+ m_oSync.lock();
+
+ TCWin32SerComLayerContainer::Iterator itRunner(m_lstComLayerList.begin());
+ TCWin32SerComLayerContainer::Iterator itRefNode(m_lstComLayerList.end());
+ TCWin32SerComLayerContainer::Iterator itEnd(m_lstComLayerList.end());
+
+ while(itRunner != itEnd){
+ if(*itRunner == pa_poComLayer){
+ if(itRefNode == itEnd){
+ m_lstComLayerList.pop_front();
+ }
+ else{
+ m_lstComLayerList.eraseAfter(itRefNode);
+ }
+ break;
+ }
+
+ itRefNode = itRunner;
+ ++itRunner;
+ }
+ m_oSync.unlock();
+}
+
+void CWin32SerComHandler::run(){
+ while(isAlive()){
+
+ if(true == m_lstComLayerList.isEmpty()){
+ selfSuspend();
+ }
+
+ m_oSync.lock();
+ TCWin32SerComLayerContainer::Iterator itEnd(m_lstComLayerList.end());
+ for(TCWin32SerComLayerContainer::Iterator itRunner = m_lstComLayerList.begin(), itCurrent = m_lstComLayerList.begin(); itRunner != itEnd;){
+ itCurrent = itRunner;
+ ++itRunner;
+
+ m_oSync.unlock();
+ if(forte::com_infra::e_Nothing != (*itCurrent)->recvData(0,0)){
+ startNewEventChain((*itCurrent)->getCommFB());
+ }
+ m_oSync.lock();
+ }
+ m_oSync.unlock();
+ Sleep(1000);
+ }
+
+}
diff --git a/src/arch/win32/serlayer/cwin32sercomhandler.h b/src/arch/win32/serlayer/cwin32sercomhandler.h
new file mode 100644
index 000000000..746b7944d
--- /dev/null
+++ b/src/arch/win32/serlayer/cwin32sercomhandler.h
@@ -0,0 +1,57 @@
+/*******************************************************************************
+ * Copyright (c) 2013 ACIN
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Melik-Merkumians - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#include
+#include
+#include <../../../core/extevhan.h>
+#include <../../../core/utils/singlet.h>
+#include "../../../core/fortelist.h"
+
+#ifndef CWIN32SERCOMHANDLER_H_
+#define CWIN32SERCOMHANDLER_H_
+
+class CWin32SerComLayer;
+
+class CWin32SerComHandler : public CExternalEventHandler, public CThread{
+ DECLARE_SINGLETON(CWin32SerComHandler)
+ public:
+
+ void registerSerComLayer(CWin32SerComLayer *pa_poComLayer);
+ void unregisterSerComLayer(CWin32SerComLayer *pa_poComLayer);
+
+ /* functions needed for the external event handler interface */
+ void enableHandler(void){
+ start();
+ }
+
+ void disableHandler(void){
+ end();
+ }
+
+ void setPriority(int){
+ //currently we are doing nothing here.
+ //TODO We should adjust the thread priority.
+ }
+
+ int getPriority(void) const{
+ //the same as for setPriority
+ return 0;
+ }
+
+ private:
+ void run();
+
+ typedef CSinglyLinkedList TCWin32SerComLayerContainer;
+
+ TCWin32SerComLayerContainer m_lstComLayerList;
+ CSyncObject m_oSync;
+};
+
+#endif /* CWIN32SERCOMLAYER_H_ */
diff --git a/src/arch/win32/serlayer/cwin32sercomlayer.cpp b/src/arch/win32/serlayer/cwin32sercomlayer.cpp
new file mode 100644
index 000000000..acf08f481
--- /dev/null
+++ b/src/arch/win32/serlayer/cwin32sercomlayer.cpp
@@ -0,0 +1,160 @@
+/*******************************************************************************
+ * Copyright (c) 2013, 2014 ACIN, fortiss GmbH
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Melik-Merkumians, Alois Zoitl - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#include "cwin32sercomlayer.h"
+#include
+#include
+#include "cwin32sercomhandler.h"
+
+CWin32SerComLayer::CWin32SerComLayer(forte::com_infra::CComLayer* pa_poUpperLayer,
+ forte::com_infra::CCommFB * pa_poFB) :
+ forte::com_infra::CComLayer(pa_poUpperLayer, pa_poFB), m_unBufFillSize(0) {
+ m_hSerial = INVALID_HANDLE_VALUE;
+}
+
+CWin32SerComLayer::~CWin32SerComLayer() {
+ closeConnection();
+}
+
+
+forte::com_infra::EComResponse CWin32SerComLayer::recvData(const void *, unsigned int ) {
+ m_eInterruptResp = forte::com_infra::e_Nothing;
+
+ DWORD dwBytesRead = 0;
+ if(ReadFile(m_hSerial, m_acRecvBuffer, m_unMaxRecvBuffer-1, &dwBytesRead, NULL))
+ { //TODO: Failure handling and send INITO-
+ if (0 < dwBytesRead)
+ {
+ m_unBufFillSize = dwBytesRead;
+ m_eInterruptResp = forte::com_infra::e_ProcessDataOk;
+ m_poFb->interruptCommFB(this);
+ } else{
+ m_eInterruptResp = forte::com_infra::e_ProcessDataRecvFaild;
+ }
+ }
+ return m_eInterruptResp;
+}
+
+forte::com_infra::EComResponse CWin32SerComLayer::processInterrupt(){
+ if(forte::com_infra::e_ProcessDataOk == m_eInterruptResp){
+ switch (m_eConnectionState){
+ case forte::com_infra::e_Connected:
+ if (0 == m_poTopLayer) {
+ CIEC_ANY *apoRDs = m_poFb->getRDs();
+ unsigned int nrRDs = m_poFb->getNumRD();
+ switch(apoRDs[0].getDataTypeID()) {
+ case CIEC_ANY::e_STRING:
+ static_cast(apoRDs[0]).fromUTF8(m_acRecvBuffer, m_unBufFillSize, false);
+ break;
+ }
+ }
+ else if((0 < m_unBufFillSize) && (0 != m_poTopLayer)) {
+ m_eInterruptResp = m_poTopLayer->recvData(m_acRecvBuffer, m_unBufFillSize);
+ m_unBufFillSize = 0;
+ }
+ break;
+ case forte::com_infra::e_Disconnected:
+ case forte::com_infra::e_Listening:
+ case forte::com_infra::e_ConnectedAndListening:
+ default:
+ break;
+ }
+ }
+ return m_eInterruptResp;
+}
+
+void CWin32SerComLayer::closeConnection() {
+ CWin32SerComHandler::getInstance().unregisterSerComLayer(this);
+ CloseHandle(m_hSerial);
+}
+
+forte::com_infra::EComResponse CWin32SerComLayer::sendData(void *pa_pvData, unsigned int pa_unSize)
+{
+ DWORD dwBytesWritten= 0, dwWaitResult = 0;
+ TConstIEC_ANYPtr apoSDs = static_cast (pa_pvData);
+ for (unsigned int i = 0; i < pa_unSize; ++i)
+ {
+ if (apoSDs[i].getDataTypeID() == CIEC_ANY::e_STRING)
+ {
+ unsigned int nToBeSent= static_cast(apoSDs[i]).length();
+ if(!WriteFile(m_hSerial, static_cast(apoSDs[i]).getValue(), nToBeSent, &dwBytesWritten, NULL))
+ {
+ return forte::com_infra::e_ProcessDataSendFailed;
+ }
+ if(dwBytesWritten != static_cast(apoSDs[i]).length())
+ {
+ return forte::com_infra::e_ProcessDataSendFailed;
+ }
+ }
+ }
+ return forte::com_infra::e_ProcessDataOk;
+}
+
+
+forte::com_infra::EComResponse CWin32SerComLayer::openConnection(char *pa_acLayerParameter) {
+ //Create Serial Com Handle
+ m_hSerial = CreateFile(pa_acLayerParameter,
+ GENERIC_READ | GENERIC_WRITE,
+ 0,
+ 0,
+ OPEN_EXISTING,
+ FILE_ATTRIBUTE_NORMAL,
+ 0);
+ if(INVALID_HANDLE_VALUE == m_hSerial) {
+ if(ERROR_FILE_NOT_FOUND == GetLastError()) {
+ return forte::com_infra::e_ProcessDataNoSocket;
+ }
+ return forte::com_infra::e_ProcessDataInvalidObject;
+ }
+
+ DCB dcbSerialParams = {0};
+
+ dcbSerialParams.DCBlength = sizeof(dcbSerialParams);
+
+ if(!GetCommState(m_hSerial, &dcbSerialParams)) {
+ return forte::com_infra::e_ProcessDataNoSocket;
+ }
+
+ dcbSerialParams.BaudRate = CBR_19200;
+ dcbSerialParams.ByteSize = 8;
+ dcbSerialParams.StopBits = ONESTOPBIT;
+ dcbSerialParams.Parity = NOPARITY;
+
+ if(!SetCommState(m_hSerial, &dcbSerialParams)) {
+ return forte::com_infra::e_ProcessDataNoSocket;
+ }
+
+ //Timeouts for non-blocking behaviour
+ COMMTIMEOUTS timeouts = {0};
+ //Read timeouts
+ timeouts.ReadIntervalTimeout = 50;
+ timeouts.ReadTotalTimeoutConstant = 50;
+ timeouts.ReadTotalTimeoutMultiplier = 10;
+ //Write timeouts
+ timeouts.WriteTotalTimeoutConstant = 50;
+ timeouts.WriteTotalTimeoutMultiplier = 10;
+
+ if(!SetCommTimeouts(m_hSerial, &timeouts)) {
+ return forte::com_infra::e_ProcessDataNoSocket;
+ }
+
+ switch (m_poFb->getComServiceType()){
+ case forte::com_infra::e_Server:
+ case forte::com_infra::e_Client:
+ CWin32SerComHandler::getInstance().registerSerComLayer(this);
+ m_eConnectionState = forte::com_infra::e_Connected;
+ break;
+ case forte::com_infra::e_Publisher:
+ break;
+ case forte::com_infra::e_Subscriber:
+ break;
+ }
+ return forte::com_infra::e_InitOk;
+}
diff --git a/src/arch/win32/serlayer/cwin32sercomlayer.h b/src/arch/win32/serlayer/cwin32sercomlayer.h
new file mode 100644
index 000000000..aef5d7381
--- /dev/null
+++ b/src/arch/win32/serlayer/cwin32sercomlayer.h
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * Copyright (c) 2013, 2014 ACIN, fortiss GmbH
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Melik-Merkumians, Alois Zoitl - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#include
+#include
+
+#include
+
+#ifndef CWIN32SERCOMLAYER_H_
+#define CWIN32SERCOMLAYER_H_
+
+class CEventSourceFB;
+
+class CWin32SerComLayer : public forte::com_infra::CComLayer{
+ public:
+ CWin32SerComLayer(forte::com_infra::CComLayer* pa_poUpperLayer, forte::com_infra::CCommFB * pa_poFB);
+ virtual ~CWin32SerComLayer ();
+
+ virtual forte::com_infra::EComResponse processInterrupt();
+
+ virtual void closeConnection();
+ virtual forte::com_infra::EComResponse sendData(void *pa_pvData, unsigned int pa_unSize);
+ /*! \brief Perform reading from serial interface
+ *
+ * @return if not e_Nothing something was read and the FB should get an external event
+ */
+ virtual forte::com_infra::EComResponse recvData(const void *pa_pvData, unsigned int pa_unSize);
+
+ protected:
+ private:
+ virtual forte::com_infra::EComResponse openConnection(char *pa_acLayerParameter);
+ HANDLE m_hSerial;
+ static const unsigned int m_unMaxRecvBuffer = 22;
+
+ forte::com_infra::EComResponse m_eInterruptResp;
+ char m_acRecvBuffer[m_unMaxRecvBuffer];
+ unsigned int m_unBufFillSize;
+
+};
+
+#endif /* CWIN32SERCOMLAYER_H_ */
diff --git a/src/arch/win32/sockhand.h b/src/arch/win32/sockhand.h
new file mode 100644
index 000000000..7a49bb140
--- /dev/null
+++ b/src/arch/win32/sockhand.h
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2010 - 2015 ACIN, Profactor GmbH, fortiss GmbH
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl, Gerhard Ebenhofer - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#ifndef SOCKHAND_H_
+#define SOCKHAND_H_
+
+#ifndef IN
+#define IN
+#endif
+
+#ifndef OUT
+#define OUT
+#endif
+
+#include
+#include
+#include
+//these include needs to be last
+#include "../fdselecthand.h"
+#include "../bsdsocketinterf.h"
+#include "../gensockhand.h"
+
+typedef CGenericIPComSocketHandler CIPComSocketHandler;
+
+#endif /* SOCKHAND_H_ */
diff --git a/src/arch/win32/sync.cpp b/src/arch/win32/sync.cpp
new file mode 100644
index 000000000..7e50e0b29
--- /dev/null
+++ b/src/arch/win32/sync.cpp
@@ -0,0 +1,20 @@
+/*******************************************************************************
+ * Copyright (c) 2010, 2011 ACIN, Profactor GmbH
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl, Gerhard Ebenhofer - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#include "sync.h"
+
+CPCSyncObject::CPCSyncObject(){
+ InitializeCriticalSection(&m_oMutexHandle);
+}
+
+CPCSyncObject::~CPCSyncObject(){
+ DeleteCriticalSection(&m_oMutexHandle);
+ //TODO handle return value
+}
diff --git a/src/arch/win32/sync.h b/src/arch/win32/sync.h
new file mode 100644
index 000000000..a113d52bc
--- /dev/null
+++ b/src/arch/win32/sync.h
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * Copyright (c) 2010 - 2013 ACIN, Profactor GmbH
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl, Gerhard Ebenhofer, Martin Melik-Merkumians - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#ifndef _SYNC_H_
+#define _SYNC_H_
+
+#define WIN32_LEAN_AND_MEAN
+ #include
+
+#define CSyncObject CPCSyncObject //allows that doxygen can generate better documenation
+
+
+/*! \ingroup win32_hal
+ * \brief The sync object implementation for the win32 thread interface.
+ *
+ * In the win32 version a CRITICAL_SECTION is used for the sync object.
+ *
+ */
+
+class CPCSyncObject{
+ private:
+ protected:
+ //! The win32 CRITICAL_SECTION handle of the operating system.
+ CRITICAL_SECTION m_oMutexHandle;
+
+ public:
+ CPCSyncObject();
+ ~CPCSyncObject();
+ /*!\brief Lock the resource coming after the lock command
+ *
+ * This function blocks until it will get the lock for the coming critical section.
+ */
+ void lock(void){
+ EnterCriticalSection(&m_oMutexHandle);
+ //TODO handle return value
+ };
+ //!Free the resource coming after the lock command
+ void unlock(void){
+ LeaveCriticalSection(&m_oMutexHandle);
+ //TODO handle return value
+ };
+};
+
+#endif /*SYNC_H_*/
diff --git a/src/arch/win32/thread.cpp b/src/arch/win32/thread.cpp
new file mode 100644
index 000000000..04de5ff50
--- /dev/null
+++ b/src/arch/win32/thread.cpp
@@ -0,0 +1,97 @@
+/*******************************************************************************
+ * Copyright (c) 2010 - 2014 ACIN, Profactor GmbH, AIT, fortiss GmbH
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl, Gerhard Ebenhofer, Thomas Strasser - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#include "thread.h"
+#include "../devlog.h"
+
+DWORD WINAPI CWin32Thread::threadFunction(LPVOID arguments){
+ // Get pointer to CThread object out of void pointer
+ CWin32Thread *pThread = (CWin32Thread *) arguments;
+
+ // if pointer is ok
+ if(0 != pThread){
+ pThread->m_bAlive = true;
+ pThread->run();
+ pThread->m_bAlive = false;
+ pThread->m_nThreadHandle = 0;
+ }
+ else{
+ DEVLOG_ERROR("pThread pointer is 0!");
+ }
+ return 0;
+}
+
+CWin32Thread::CWin32Thread(long pa_nStackSize) :
+ m_bAlive(false), m_nThreadHandle(0), m_nStackSize(pa_nStackSize), m_nThreadID(~0x0ul){
+
+ m_hSelfSuspendSemaphore = CreateSemaphore(NULL, 0, 10, NULL);
+
+ if(0 == m_hSelfSuspendSemaphore){
+ DEVLOG_ERROR("Could not initialize suspend semphore: %d\n", GetLastError());
+ }
+}
+
+CWin32Thread::~CWin32Thread(){
+ if(0 != m_nThreadHandle){
+ end();
+ }
+ CloseHandle(m_hSelfSuspendSemaphore);
+}
+
+bool CWin32Thread::isAlive(void) const{
+ return m_bAlive;
+}
+
+void CWin32Thread::setDeadline(const CIEC_TIME &pa_roVal){
+ m_oDeadline = pa_roVal;
+//under the win32 currently it makes no sense to set any priority.
+//It will not be considered.
+}
+
+const CIEC_TIME &CWin32Thread::getDeadline(void) const{
+ return m_oDeadline;
+}
+
+void CWin32Thread::start(void){
+ if(0 == m_nThreadHandle){
+
+ m_nThreadHandle = CreateThread(0, // default security attributes
+ m_nStackSize, // use default stack size
+ threadFunction, // thread function name
+ this, // argument to thread function
+ 0, // use default creation flags
+ &m_nThreadID); // returns the thread identifier
+
+ if(0 == m_nThreadHandle){
+ DEVLOG_ERROR("Error could not create the thread!");
+ }
+ }
+}
+
+void CWin32Thread::selfSuspend(void){
+ WaitForSingleObject(m_hSelfSuspendSemaphore, INFINITE);
+}
+
+void CWin32Thread::resumeSelfSuspend(void){
+ ReleaseSemaphore(m_hSelfSuspendSemaphore, 1, 0);
+}
+
+void CWin32Thread::end(void){
+ m_bAlive = false;
+ resumeSelfSuspend();
+ join();
+}
+
+void CWin32Thread::join(void){
+ //check if the thread is still running and that we are not calling join from inside the thread
+ if((0 != m_nThreadHandle) && (GetCurrentThreadId() != m_nThreadID)){
+ WaitForSingleObject(m_nThreadHandle, INFINITE);
+ }
+}
diff --git a/src/arch/win32/thread.h b/src/arch/win32/thread.h
new file mode 100644
index 000000000..528d6b0c9
--- /dev/null
+++ b/src/arch/win32/thread.h
@@ -0,0 +1,146 @@
+/*******************************************************************************
+ * Copyright (c) 2010 - 2015 ACIN, Profactor GmbH, AIT, fortiss GmbH
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl, Gerhard Ebenhofer, Thomas Strasser - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#ifndef _THREAD_H_
+#define _THREAD_H_
+
+#define WIN32_LEAN_AND_MEAN
+#include
+#include "../datatype.h"
+#include "../../core/datatypes/forte_time.h"
+
+
+/** \ingroup FORTE-HAL
+ * \defgroup win32_hal PC FORTE Hardware Abstraction Layer
+ *
+ * \brief The FORTE-HAL implementation for normal win32
+ *
+ */
+
+/*! \ingroup win32_hal
+ * \brief The thread implementation for the win32 thread interface.
+ *
+ */
+class CWin32Thread{
+ public:
+ /*! \brief Constructor of the Thread class
+ *
+ * Does all the necessary steps in order to get the thread running with the start()-method
+ * @param pa_nStackSize the Size of the stack the thread is allowed to use. 0 means use system default stack size.
+ */
+ CWin32Thread(long pa_nStackSize = 0);
+
+ /*! \brief Stops and destroys thread.
+ *
+ * Will stop the execution if running and destroy the thread including all system specific data.
+ */
+ virtual ~CWin32Thread();
+
+ /*! \brief Indicates if the thread is allowed to execute.
+ *
+ * This functions checks if the Thread is still executing user code in its run()-method.
+ * \return true if there the run method is active.
+ */
+ bool isAlive(void) const;
+
+ //!Set the deadline of the thread.
+ void setDeadline(const CIEC_TIME &m_roVal);
+
+ //!Get the current deadline of the thread.
+ const CIEC_TIME &getDeadline(void) const;
+
+ /*! \brief starts the Thread
+ *
+ * By calling this method the execution in the run()-Method will be started. If necessary additional data
+ * can be created here. Because of inheritance reasons the best place for executing create is in this method.
+ */
+ void start();
+
+ /*! \brief Resumes a suspended Thread
+ */
+ void resumeSelfSuspend();
+
+ /*! \brief Stops the execution of the thread
+ *
+ * This function immediately stops the execution of the thread (setting m_bAlive to false) and waits till
+ * this is finished.
+ */
+ void end(void);
+
+ /*! \brief Waits for the Thread to finish its execution.
+ *
+ * This function waits till the execution in the thread decides to end the execution. Blocks the caller!!!
+ */
+ void join(void); // Waits
+
+ protected:
+ /*! \brief Flag that indicates if the Thread is alive.
+ *
+ * This flag has two main purposes:
+ * -# indicate for other classes if the thread is still executing
+ * -# use in the run()-method to check if the thread is still allowed to execute (e.g. while(isAlive()) ).
+ * This is important for stopping and destroying threads.
+ */
+ bool m_bAlive;
+
+ /*!\brief Function that is given to the system thread support that should be called for the thread.
+ *
+ * this function will call the run method of the thread instance.
+ */
+ //static void * threadFunction(void *arguments);
+ static DWORD WINAPI threadFunction(LPVOID arguments);
+
+ /*! \brief Suspends the thread.
+ *
+ * Suspends the execution of the thread until resumeSelfSuspend(), end(), or join() is called.
+ */
+ void selfSuspend(void);
+
+ private:
+ /*! \brief Abstract method for the code to execute in the thread.
+ *
+ * This thread class has to provide means that the code a inheriting class will add to the run()-method will
+ * be executed in a separated thread regarding the creator of the CThread class.
+ *
+ * The inheriting class has to fulfill the following rules when using the run method:
+ * - To end the thread execution simple leave the run()-method
+ * - In order to allow the deletion and stopping of the thread add frequent checks to isAlive and end the
+ * execution if isAlive() returns false.
+ */
+ virtual void run() = 0;
+
+ //!deadline the thread needs to be finish its execution. 0 means unconstrained.
+ CIEC_TIME m_oDeadline;
+
+ /*! \brief data needed for win32 scheduling system to identify the thread.
+ */
+ HANDLE m_nThreadHandle;
+
+ /*! \brief the 'real' thread ID of the started thread
+ */
+ DWORD m_nThreadID;
+
+ //! Semaphore to handle the self suspend mechanism required for FORTE-Threads more reliable
+ HANDLE m_hSelfSuspendSemaphore;
+
+ /*! \brief Size of the stack used by this thread.
+ */
+ long m_nStackSize;
+
+ //we don't want that threads can be copied or assigned therefore the copy constructor and assignment operator are declared private
+ //but not implemented
+ CWin32Thread(const CWin32Thread&);
+ CWin32Thread& operator = (const CWin32Thread &);
+};
+
+typedef CWin32Thread CThread; //allows that doxygen can generate better documentation
+
+#endif /*THREAD_H_*/
+
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt
new file mode 100644
index 000000000..7004b3c64
--- /dev/null
+++ b/src/core/CMakeLists.txt
@@ -0,0 +1,33 @@
+#*******************************************************************************
+# * Copyright (c) 2010 - 2015 Profactor GmbH, ACIN, fortiss GmbH
+# * All rights reserved. This program and the accompanying materials
+# * are made available under the terms of the Eclipse Public License v1.0
+# * which accompanies this distribution, and is available at
+# * http://www.eclipse.org/legal/epl-v10.html
+# *
+# * Contributors:
+# * Micheal Hofmann, Alois Zoitl, Gerhard Ebenhofer, Monika Wenger
+# * - initial implementation and rework communication infrastructure
+# *******************************************************************************/
+#############################################################################
+# Core
+#############################################################################
+forte_add_include_directories(${CMAKE_CURRENT_SOURCE_DIR})
+
+forte_add_subdirectory(cominfra)
+forte_add_subdirectory(datatypes)
+forte_add_subdirectory(utils)
+
+forte_add_sourcefile_hcpp(conn dataconn eventconn)
+
+forte_add_sourcefile_h (esfb.h event.h mgmcmd.h fortenode.h fortelist.h convert_functions.h)
+forte_add_sourcefile_hcpp(basicfb cfb device devexec )
+forte_add_sourcefile_hcpp(extevhan funcbloc fbcontainer if2indco )
+forte_add_sourcefile_hcpp(resource stringdict typelib ecet)
+forte_add_sourcefile_hcpp(adapterconn adapter iec61131_functions)
+
+if(FORTE_SUPPORT_MONITORING)
+ forte_add_sourcefile_hcpp(monitoring)
+endif(FORTE_SUPPORT_MONITORING)
+
+
diff --git a/src/core/adapter.cpp b/src/core/adapter.cpp
new file mode 100644
index 000000000..18cffca41
--- /dev/null
+++ b/src/core/adapter.cpp
@@ -0,0 +1,105 @@
+/*******************************************************************************
+ * Copyright (c) 2008 - 2015 ACIN, fortiss GmbH
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Ingo Hegny, Alois Zoitl
+ * - initial implementation and rework communication infrastructure
+ *******************************************************************************/
+#include
+#include "adapter.h"
+#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP
+#include "adapter_gen.cpp"
+#endif
+#include "adapterconn.h"
+#include "ecet.h"
+
+CAdapter::CAdapter(CResource *pa_poSrcRes,
+ const SFBInterfaceSpec *pa_pstInterfaceSpecSocket, const CStringDictionary::TStringId pa_nInstanceNameId, const SFBInterfaceSpec *pa_pstInterfaceSpecPlug,
+ bool pa_bIsPlug, TForteByte *pa_acFBConnData, TForteByte *pa_acFBVarsData) :
+ CFunctionBlock( pa_poSrcRes,
+ (pa_bIsPlug) ? pa_pstInterfaceSpecPlug : pa_pstInterfaceSpecSocket, pa_nInstanceNameId, pa_acFBConnData, pa_acFBVarsData),
+ m_bIsPlug(pa_bIsPlug),
+ m_poPeer(0),
+ m_aoLocalDIs(m_aoDIs),
+ m_poAdapterConn(0){
+
+ setupEventEntryList();
+}
+
+CAdapter::~CAdapter() {
+ if (m_bIsPlug) {
+ if (m_poAdapterConn != 0) {
+ delete m_poAdapterConn;
+ }
+ }
+ else {
+ if (m_poAdapterConn != 0) {
+ m_poAdapterConn->setSocket(0);
+ }
+ }
+ delete[] m_astEventEntry;
+}
+
+void CAdapter::setParentFB(CFunctionBlock *pa_poParentFB, TForteUInt8 pa_nParentAdapterlistID) {
+ m_nParentAdapterListEventID = static_cast((pa_nParentAdapterlistID+1)<<8);;
+
+ for(TForteUInt16 i = 0; i < m_pstInterfaceSpec->m_nNumEOs; ++i){
+ m_astEventEntry[i].mFB = pa_poParentFB;
+ m_astEventEntry[i].mPortId = static_cast(m_nParentAdapterListEventID + i);
+ }
+
+ if(isPlug()){
+ //the plug is in charge of managing the adapter connection
+ m_poAdapterConn = new CAdapterConnection(this, pa_nParentAdapterlistID, this);
+ }
+}
+
+bool CAdapter::connect(CAdapter *pa_poPeer, CAdapterConnection *pa_poAdConn) {
+ bool bRetVal = false;
+ if (m_poPeer == 0) {
+ m_poPeer = pa_poPeer;
+ m_aoDIs = pa_poPeer->m_aoDOs; //TODO: change is adapters of subtypes may be connected
+ m_poAdapterConn = pa_poAdConn;
+ bRetVal = true;
+ }
+
+ return bRetVal;
+}
+
+bool CAdapter::disconnect(CAdapterConnection *pa_poAdConn) {
+ if ((pa_poAdConn!=0) && (pa_poAdConn != m_poAdapterConn)){
+ return false; //connection requesting disconnect is not equal to established connection
+ }
+ m_poPeer=0;
+ m_aoDIs = m_aoLocalDIs;
+ if(isSocket()){
+ m_poAdapterConn = 0;
+ }
+ return true;
+}
+
+bool CAdapter::isCompatible(CAdapter *pa_poPeer) {
+ //Need to check any adapter here as we don't know which adapter side is used for checking compatibility
+ return ((getFBTypeId() == pa_poPeer->getFBTypeId()) ||
+ ((getFBTypeId() == g_nStringIdANY_ADAPTER) && (g_nStringIdANY_ADAPTER != pa_poPeer->getFBTypeId())) ||
+ ((getFBTypeId() != g_nStringIdANY_ADAPTER) && (g_nStringIdANY_ADAPTER == pa_poPeer->getFBTypeId())));
+}
+
+void CAdapter::executeEvent(int pa_nEIID) {
+ if (0 != m_poPeer) {
+ if (0 != m_poPeer->m_astEventEntry[pa_nEIID].mFB) {
+ m_poInvokingExecEnv->addEventEntry(&(m_poPeer->m_astEventEntry[pa_nEIID]));
+ } else {
+ m_poPeer->m_poInvokingExecEnv = m_poInvokingExecEnv;
+ m_poPeer->sendOutputEvent(pa_nEIID);
+ }
+ }
+}
+
+void CAdapter::setupEventEntryList(){
+ m_astEventEntry = new SEventEntry[m_pstInterfaceSpec->m_nNumEOs];
+}
diff --git a/src/core/adapter.h b/src/core/adapter.h
new file mode 100644
index 000000000..ea0fac55f
--- /dev/null
+++ b/src/core/adapter.h
@@ -0,0 +1,133 @@
+/*******************************************************************************
+ * Copyright (c) 2008 - 2015 ACIN, fortiss GmbH
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Ingo Hegny, Alois Zoitl, Martin Melik Merkumians
+ * - initial implementation and rework communication infrastructure
+ *******************************************************************************/
+#ifndef _ADAPTER_H_
+#define _ADAPTER_H_
+
+#include "funcbloc.h"
+
+class CAdapterConnection;
+
+#define ADAPTER_CTOR(fbclass) \
+ fbclass(CStringDictionary::TStringId pa_anAdapterInstanceName, CResource *pa_poSrcRes, bool pa_bIsPlug) : \
+ CAdapter( pa_poSrcRes, &scm_stFBInterfaceSpecSocket, pa_anAdapterInstanceName, &scm_stFBInterfaceSpecPlug, pa_bIsPlug, m_anFBConnData, m_anFBVarsData)
+
+
+#define FORTE_ADAPTER_DATA_ARRAY(a_nNumEIs, a_nNumEOs, a_nNumDIs, a_nNumDOs, a_nNumAdapters) \
+ union{ \
+ TForteByte m_anFBConnData[genAdapterFBConnDataSizeTemplate