commit 64fde4ba8a5626d6254acb6ec59c8f5b8566433b
Author: skenneweg <skenneweg@techfak.uni-bielefeld.de>
Date:   Sun May 31 14:59:56 2020 +0200

    Started to write the core and node functions

diff --git a/Makefile b/Makefile
index c7998f5..ce6ab92 100644
--- a/Makefile
+++ b/Makefile
@@ -30,7 +30,9 @@ URTWARE_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
 
 # include paths
 URTWARE_INC = $(URTWARE_DIR:/=) \
-              $(URTWARE_DIR)inc
+              $(URTWARE_DIR)inc \
+							$(URTWARE_DIR)inc/urt_core.h \
+							$(URTWARE_DIR)inc/urt_node.h
 
 # C sources
 URTWARE_CSRC = $(URTWARE_DIR)src/urt_core.c \
diff --git a/inc/urt_node.h b/inc/urt_node.h
index 22d4baf..ee9df81 100644
--- a/inc/urt_node.h
+++ b/inc/urt_node.h
@@ -22,7 +22,6 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #ifndef URTWARE_NODE_H
 #define URTWARE_NODE_H
 
-#include <urt_types.h>
 #include <urtware.h>
 
 /******************************************************************************/
@@ -42,27 +41,6 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 /******************************************************************************/
 
 /**
- * @brief  node
- */
-typedef struct urt_node
-{
-  urt_node_t* next;
-  urt_osThread_t* thread;
-  urt_nodeSetupCallback_t* setupcallback;
-  void* setupparams;
-  urt_nodeLoopCallback_t* loopcallback;
-  void* loopparams;
-  urt_nodeShutdownCallback_t* shutdowncallback;
-  void* shutdownparams;
-  urt_nodestage_t stage;
-  urt_osEventListener_t listener;
-  #if (URT_CFG_PUBSUB_PROFILING || URT_CFG_RPC_PROFILING)
-    uint64_t loops;
-  #endif /* URT_CFG_PUBSUB_PROFILING || URT_CFG_RPC_PROFILING */
-}urt_node_t;
-
-
-/**
  * @brief
  *
  * @param[in]   node   .
@@ -72,7 +50,7 @@ typedef struct urt_node
  * @return    .
  *
  */
-typedef void (*urt_nodeShutdownCallback_t)(urt_node_t* node, urt_status_t cause, void* arg);
+typedef void (*urt_nodeShutdownCallback_t)(struct urt_node* node, urt_status_t cause, void* arg);
 
 
 /**
@@ -84,7 +62,7 @@ typedef void (*urt_nodeShutdownCallback_t)(urt_node_t* node, urt_status_t cause,
  * @return    .
  *
  */
-typedef urt_osEventMask_t (*urt_nodeSetupCallback_t)(urt_node_t* node, void* arg);
+typedef urt_osEventMask_t (*urt_nodeSetupCallback_t)(struct urt_node* node, void* arg);
 
 
 /**
@@ -96,7 +74,28 @@ typedef urt_osEventMask_t (*urt_nodeSetupCallback_t)(urt_node_t* node, void* arg
  *
  * @return    .
  */
-typedef urt_osEventMask_t (*urt_nodeLoopCallback_t)(urt_node_t* node, urt_osEventMask_t events, void* arg);
+typedef urt_osEventMask_t (*urt_nodeLoopCallback_t)(struct urt_node* node, urt_osEventMask_t events, void* arg);
+
+/**
+ * @brief  node
+ */
+typedef struct urt_node
+{
+  struct urt_node* next;
+  urt_osThread_t* thread;
+  urt_nodeSetupCallback_t* setupcallback;
+  void* setupparams;
+  urt_nodeLoopCallback_t* loopcallback;
+  void* loopparams;
+  urt_nodeShutdownCallback_t* shutdowncallback;
+  void* shutdownparams;
+  urt_nodestage_t stage;
+  urt_osEventListener_t listener;
+  #if (URT_CFG_PUBSUB_PROFILING || URT_CFG_RPC_PROFILING)
+    uint64_t loops;
+  #endif /* URT_CFG_PUBSUB_PROFILING || URT_CFG_RPC_PROFILING */
+}urt_node_t;
+
 
 /******************************************************************************/
 /* MACROS                                                                     */
diff --git a/src/urt_core.c b/src/urt_core.c
index f79d522..b05186b 100644
--- a/src/urt_core.c
+++ b/src/urt_core.c
@@ -33,6 +33,8 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 /* LOCAL TYPES                                                                */
 /******************************************************************************/
 
+urt_core_t core;
+
 /******************************************************************************/
 /* LOCAL VARIABLES                                                            */
 /******************************************************************************/
@@ -50,15 +52,15 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 void urtCoreInit(void)
 {
-  urt_core_t._nodes = NULL;
-  urt_core_t._status = URT_STATUS_OK;
-  urtEventSourceInit(urt_core_t._evtSource);
-  urtMutexInit(urt_core_t._lock);
+  core._nodes = NULL;
+  core._status = URT_STATUS_OK;
+  urtEventSourceInit(core._evtSource);
+  urtMutexInit(&core._lock);
   #if (URT_CFG_PUBSUB_ENABLED)
-    urt_core_t._topics = NULL;
+    core._topics = NULL;
   #endif /* URT_CFG_PUBSUB_ENABLED */
   #if (URT_CFG_RPC_ENABLED)
-    urt_core_t.urt_service_t = NULL;
+    core.urt_service_t = NULL;
   #endif /* URT_CFG_RPC_ENABLED */
   return;
 }
@@ -68,12 +70,26 @@ void urtCoreInit(void)
  *
  * @return  Current system status.
  */
-urt_status_t urtCoreGetStatus(void) {return URT_STATUS_OK;}
+urt_status_t urtCoreGetStatus(void)
+{
+  return core._status;
+}
 
 /**
  * @brief   Start threads of all nodes of the Core.
  */
-void urtCoreStartNodes(void) {return;}
+void urtCoreStartNodes(void)
+{
+  //TODO: Lock core
+  urt_node_t* node = core._nodes;
+  while (node)
+  {
+    urtThreadStart(node->thread);
+    node = node->next;
+  }
+  //TODO: Unlock core
+  return;
+}
 
 /**
  * @brief   Synchronize all nodes of the core.
@@ -85,7 +101,32 @@ void urtCoreStartNodes(void) {return;}
  *          Returns URT_STATUS_SYNC_PENDING if there are nodes left to synchronize.
  *          In the latter case, the node thread must still wait for the control event (proceed) to synchronize.
  */
-urt_status_t urtCoreSynchronize(urt_node_t* node) {return URT_STATUS_OK;}
+urt_status_t urtCoreSynchronize(urt_node_t* node)
+{
+  //TODO: Lock core
+  //TODO: Increment node's stage value
+  urt_node_t* nodeFromCore = core._nodes;
+  while (nodeFromCore /*stage equals stage*/)
+  {
+    nodeFromCore = nodeFromCore->next;
+  }
+  bool temp = false;
+  if (temp/*all nodes are the same stage*/)
+  {
+    //TODO: Unlock core
+    return URT_STATUS_OK;
+  }
+  else if (temp/*stage of the last checked node was one less than the argument*/)
+  {
+    //TODO: Unlock core
+    return URT_STATUS_SYNC_PENDING;
+  }
+  else
+  {
+      urtCoreStopNodes(URT_STATUS_SYNC_ERROR);
+      return URT_STATUS_SYNC_ERROR;
+  }
+}
 
 /**
  * @brief   Stop threads of all nodes of the Core.
@@ -95,7 +136,37 @@ urt_status_t urtCoreSynchronize(urt_node_t* node) {return URT_STATUS_OK;}
  * @return  Returns URT_STATUS_OK if there was no call with another reason than URT_STATUS_OK before.
  *          If the function has been called before with a different reason, that reason is returned.
  */
-urt_status_t urtCoreStopNodes(urt_status_t reason) {return URT_STATUS_OK;}
+urt_status_t urtCoreStopNodes(urt_status_t reason)
+{
+  //TODO: Lock core
+  if (core._status == URT_STATUS_OK)
+  {
+    if (core._nodes->thread->prio < URT_THREAD_PRIO_HIGH_MAX)
+    {
+      core._nodes->thread->prio = URT_THREAD_PRIO_HIGH_MAX;
+    }
+    else
+    {
+      core._status = reason;
+      urt_node_t* node = core._nodes;
+      while (node)
+      {
+        urt_node_t* tempNode = node;
+        tempNode = NULL;
+        node = node->next;
+      }
+      //TODO: broadcast control event (terminate)
+      //TODO:Unlock core
+      //TODO: Thread boosted its priority?
+    }
+  }
+  else
+  {
+      //TODO:Unlock core
+      return core._status;
+  }
+  return URT_STATUS_OK;
+}
 
 /**
  * @brief   Get the topic of the Core.
@@ -104,7 +175,10 @@ urt_status_t urtCoreStopNodes(urt_status_t reason) {return URT_STATUS_OK;}
  *
  * @return  Returns a pointer to the requested service. Returns NULL if no service matches the given ID.
  */
-urt_topic_t* urtCoreGetTopic(urt_topicid_t id) {return urt_topic_t;}
+#if (URT_CFG_PUBSUB_ENABLED)
+  urt_topic_t* urtCoreGetTopic(urt_topicid_t id) {return urt_topic_t;}
+#endif /* URT_CFG_PUBSUB_ENABLED */
+
 
 /**
  * @brief   Get the service of the Core.
@@ -112,6 +186,9 @@ urt_topic_t* urtCoreGetTopic(urt_topicid_t id) {return urt_topic_t;}
  * @param[in] id  Identifier of the service to retrieve.
  *
  * @return Returns a pointer to the requested service. Returns NULL if no service matches the given ID.
- */
-urt_service_t urtCoreGetService(urt_serviceid_t id) {return urt_service_t;}
+ */  
+#if (URT_CFG_RPC_ENABLED)
+  urt_service_t urtCoreGetService(urt_serviceid_t id) {return urt_service_t;}
+#endif /* URT_CFG_RPC_ENABLED */
+
 
diff --git a/src/urt_node.c b/src/urt_node.c
index a0bc902..e0c597b 100644
--- a/src/urt_node.c
+++ b/src/urt_node.c
@@ -69,17 +69,17 @@ void urtNodeInit(urt_node_t* node, urt_osThread_t* thread, urt_nodeSetupCallback
                  void* setupparams, urt_nodeLoopCallback_t* loopcallback, void* loopparams,
                  urt_nodeShutdownCallback_t* shutdowncallback, void* shutdownparams)
 {
-  urt_node_t.next = NULL;
-  urt_node_t.thread = thread;
-  urt_node_t.setupcallback = setupcallback;
-  urt_node_t.setupparams = setupparams;
-  urt_node_t.loopparams = loopparams;
-  urt_node_t.shutdowncallback = loopcallback;
-  urt_node_t.shutdownparams = loopparams;
-  urt_node_t.stage = 0;
+  node->next = NULL;
+  node->thread = thread;
+  node->setupcallback = setupcallback;
+  node->setupparams = setupparams;
+  node->loopparams = loopparams;
+  node->shutdowncallback = loopcallback;
+  node->shutdownparams = loopparams;
+  node->stage = 0;
   // add later: urteventlistenerinit
   #if (URT_CFG_PUBSUB_PROFILING || URT_CFG_RPC_PROFILING)
-    urt_node_t.loops = 0;
+    node->loops = 0;
   #endif /* URT_CFG_PUBSUB_PROFILING || URT_CFG_RPC_PROFILING */
     // add later: lock core,..
   return;
diff --git a/urtware.h b/urtware.h
index 95249c6..ebf58da 100644
--- a/urtware.h
+++ b/urtware.h
@@ -95,8 +95,8 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 /*
  * TODO: Add further µRtWare includes here (e.g. urt_core.h).
  */
-#include <urt_core.h>
+#include <apps_urtosal.h>
 #include <urt_node.h>
-
+#include <urt_core.h>
 
 #endif /* URTWARE_H */
