commit e7c4f797717d914098690a2f168c1e04237c8913
Author: Thomas Schöpping <tschoepp@cit-ec.uni-bielefeld.de>
Date:   Wed Jul 29 09:54:51 2020 +0200

    Merged several modifications from master-branch.

diff --git a/core/inc/aos_thread.h b/core/inc/aos_thread.h
index ed5f586..28152d6 100644
--- a/core/inc/aos_thread.h
+++ b/core/inc/aos_thread.h
@@ -125,6 +125,10 @@ extern "C" {
 #if ((AMIROOS_CFG_DBG == true) && (CH_DBG_FILL_THREADS == TRUE)) || defined(__DOXYGEN__)
   size_t aosThdGetStackPeakUtilization(thread_t* thread);
 #endif /* (AMIROOS_CFG_DBG == true) && (CH_DBG_FILL_THREADS == TRUE) */
+#if ((CH_CFG_USE_REGISTRY == TRUE) || (CH_CFG_USE_THREADHIERARCHY == TRUE)) || defined(__DOXYGEN__)
+  thread_t* aosThreadGetFirst(void);
+  thread_t* aosThreadGetNext(thread_t* thread);
+#endif /* (CH_CFG_USE_REGISTRY == TRUE) || (CH_CFG_USE_THREADHIERARCHY == TRUE) */
 #if defined(__cplusplus)
 }
 #endif /* defined(_cplusplus) */
diff --git a/core/src/aos_system.c b/core/src/aos_system.c
index 1f86aef..720df61 100644
--- a/core/src/aos_system.c
+++ b/core/src/aos_system.c
@@ -88,9 +88,9 @@ aos_system_t aos;
 static int _shellcmd_configcb(BaseSequentialStream* stream, int argc, char* argv[]);
 static int _shellcmd_infocb(BaseSequentialStream* stream, int argc, char* argv[]);
 static int _shellcmd_shutdowncb(BaseSequentialStream* stream, int argc, char* argv[]);
-#if ((CH_CFG_USE_REGISTRY == TRUE) && (CH_DBG_STATISTICS == TRUE)) || defined(__DOXYGEN__)
+#if (((CH_CFG_USE_REGISTRY == TRUE) || (CH_CFG_USE_THREADHIERARCHY == TRUE)) && (CH_DBG_STATISTICS == TRUE)) || defined(__DOXYGEN__)
 static int _shellcmd_cpuloadcb(BaseSequentialStream* stream, int argc, char* argv[]);
-#endif /* (CH_CFG_USE_REGISTRY == TRUE) && (CH_DBG_STATISTICS == TRUE) */
+#endif /* ((CH_CFG_USE_REGISTRY == TRUE) || (CH_CFG_USE_THREADHIERARCHY == TRUE)) && (CH_DBG_STATISTICS == TRUE) */
 #if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
 static int _shellcmd_kerneltestcb(BaseSequentialStream* stream, int argc, char* argv[]);
 #endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
@@ -147,14 +147,14 @@ static AOS_SHELL_COMMAND(_shellcmd_shutdown, "system:shutdown", _shellcmd_shutdo
 static AOS_SHELL_COMMAND(_shellcmd_shutdown, "module:shutdown", _shellcmd_shutdowncb);
 #endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */
 
-#if ((CH_CFG_USE_REGISTRY == TRUE) && (CH_DBG_STATISTICS == TRUE)) || defined(__DOXYGEN__)
+#if (((CH_CFG_USE_REGISTRY == TRUE) || (CH_CFG_USE_THREADHIERARCHY == TRUE)) && (CH_DBG_STATISTICS == TRUE)) || defined(__DOXYGEN__)
 
 /**
  * @brief   Shell command to read out CPU load.
  */
 static AOS_SHELL_COMMAND(_shellcmd_cpuload, "module:cpuload", _shellcmd_cpuloadcb);
 
-#endif /* (CH_CFG_USE_REGISTRY == TRUE) && (CH_DBG_STATISTICS == TRUE) */
+#endif /* ((CH_CFG_USE_REGISTRY == TRUE) || (CH_CFG_USE_THREADHIERARCHY == TRUE)) && (CH_DBG_STATISTICS == TRUE) */
 
 #if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
 
@@ -643,7 +643,7 @@ static int _shellcmd_shutdowncb(BaseSequentialStream* stream, int argc, char* ar
 #endif /* (AMIROOS_CFG_BOOTLOADER == X) */
 }
 
-#if ((CH_CFG_USE_REGISTRY == TRUE) && (CH_DBG_STATISTICS == TRUE)) || defined(__DOXYGEN__)
+#if (((CH_CFG_USE_REGISTRY == TRUE) || (CH_CFG_USE_THREADHIERARCHY == TRUE)) && (CH_DBG_STATISTICS == TRUE)) || defined(__DOXYGEN__)
 
 /**
  * @brief   Callback function for the module:cpuload shell command.
@@ -663,24 +663,28 @@ static int _shellcmd_cpuloadcb(BaseSequentialStream* stream, int argc, char* arg
 
   // local variables
   rttime_t sum = 0;
-  thread_t* thd = chRegFirstThread();
+  thread_t* thd = aosThreadGetFirst();
 
   // accumulate system load
   do {
     sum += thd->stats.cumulative;
-    thd = chRegNextThread(thd);
+    thd = aosThreadGetNext(thd);
   } while (thd);
   sum += ch.kernel_stats.m_crit_thd.cumulative;
   sum += ch.kernel_stats.m_crit_isr.cumulative;
 
   // retrieve, calculate and print performance measures
   chprintf(stream, "threads & critical zones:\n");
-  thd = chRegFirstThread();
+  thd = aosThreadGetFirst();
   do {
+#if (CH_CFG_USE_REGISTRY == TRUE)
     chprintf(stream, "\t%22s: %6.2f%%\n",
              (thd->name != NULL) ? thd->name : "<unnamed thread>",
              (double)((float)thd->stats.cumulative / (float)sum * 100.f));
-    thd = chRegNextThread(thd);
+#else
+    chprintf(stream, "\t     thread 0x%08X: %6.2f%%\n", (unsigned int)thd, (double)((float)thd->stats.cumulative / (float)sum * 100.f));
+#endif
+    thd = aosThreadGetNext(thd);
   } while (thd);
   chprintf(stream, "\t%22s: %6.2f%%\n",
            "thread critical zones",
@@ -701,7 +705,7 @@ static int _shellcmd_cpuloadcb(BaseSequentialStream* stream, int argc, char* arg
   return 0;
 }
 
-#endif /* (CH_CFG_USE_REGISTRY == TRUE) && (CH_DBG_STATISTICS == TRUE) */
+#endif /* ((CH_CFG_USE_REGISTRY == TRUE) || (CH_CFG_USE_THREADHIERARCHY == TRUE)) && (CH_DBG_STATISTICS == TRUE) */
 
 #if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
 
@@ -780,39 +784,11 @@ static size_t _numActiveThreads(void)
 {
   size_t threads = 0;
 
-#if (CH_CFG_USE_REGISTRY == TRUE)
-  thread_t* tp = chRegFirstThread();
+  thread_t* tp = aosThreadGetFirst();
   while (tp) {
     threads += (tp->state != CH_STATE_FINAL) ? 1 : 0;
-    tp = chRegNextThread(tp);
+    tp = aosThreadGetNext(tp);
   }
-#elif (CH_CFG_USE_THREADHIERARCHY == TRUE)
-  enum {
-    TRAVERSE_DOWN,
-    TRAVERSE_UP,
-  } traverse = TRAVERSE_UP;
-  thread_t* tp = chThdGetSelfX();
-  // traverse to root thread
-  while (tp->parent) {
-    tp = tp->parent;
-  }
-  // systematically count all threads
-  traverse = TRAVERSE_DOWN;
-  while (tp) {
-    if (traverse == TRAVERSE_DOWN && tp->children) {
-      tp = tp->children;
-    } else {
-      threads += (tp->state != CH_STATE_FINAL) ? 1 : 0;
-      if (tp->sibling) {
-        tp = tp->sibling;
-        traverse = TRAVERSE_DOWN;
-      } else {
-        tp = tp->parent;
-        traverse = TRAVERSE_UP;
-      }
-    }
-  }
-#endif
 
   return threads;
 }
@@ -870,9 +846,9 @@ void aosSysInit(const char* shellPrompt)
   aosShellAddCommand(&aos.shell, &_shellcmd_config);
   aosShellAddCommand(&aos.shell, &_shellcmd_info);
   aosShellAddCommand(&aos.shell, &_shellcmd_shutdown);
-#if ((CH_CFG_USE_REGISTRY == TRUE) && (CH_DBG_STATISTICS == TRUE)) || defined(__DOXYGEN__)
+#if (((CH_CFG_USE_REGISTRY == TRUE) || (CH_CFG_USE_THREADHIERARCHY == TRUE)) && (CH_DBG_STATISTICS == TRUE)) || defined(__DOXYGEN__)
   aosShellAddCommand(&aos.shell, &_shellcmd_cpuload);
-#endif /* (CH_CFG_USE_REGISTRY == TRUE) && (CH_DBG_STATISTICS == TRUE) */
+#endif /* ((CH_CFG_USE_REGISTRY == TRUE) || (CH_CFG_USE_THREADHIERARCHY == TRUE)) && (CH_DBG_STATISTICS == TRUE) */
 #if (AMIROOS_CFG_TESTS_ENABLE == true)
   aosShellAddCommand(&aos.shell, &_shellcmd_kerneltest);
 #endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
diff --git a/core/src/aos_thread.c b/core/src/aos_thread.c
index b5f483d..cc71570 100644
--- a/core/src/aos_thread.c
+++ b/core/src/aos_thread.c
@@ -103,4 +103,51 @@ size_t aosThdGetStackPeakUtilization(thread_t* thread)
 }
 #endif /* (AMIROOS_CFG_DBG == true) && (CH_DBG_FILL_THREADS == TRUE) */
 
+#if ((CH_CFG_USE_REGISTRY == TRUE) || (CH_CFG_USE_THREADHIERARCHY == TRUE)) || defined(__DOXYGEN__)
+
+/**
+ * @brief   Retrieve the first/root thread in the system.
+ *
+ * @return  Pointer to the first/root thread.
+ */
+thread_t* aosThreadGetFirst(void)
+{
+#if (CH_CFG_USE_REGISTRY == TRUE)
+  return chRegFirstThread();
+#elif (CH_CFG_USE_THREADHIERARCHY == TRUE)
+  thread_t* tp = chThdGetSelfX();
+  while (tp->parent) {
+    tp = tp->parent;
+  }
+  return tp;
+#endif
+}
+
+/**
+ * @brief   Retrieve the next thread in the system.
+ *
+ * @param[in] thread  Current thread to retrieve the 'successor' to.
+ *
+ * @return  Pointer to the next thread, or NULL if there are no further threads.
+ */
+thread_t* aosThreadGetNext(thread_t* thread)
+{
+  aosDbgCheck(thread != NULL);
+
+#if (CH_CFG_USE_REGISTRY == TRUE)
+  return chRegNextThread(thread);
+#elif (CH_CFG_USE_THREADHIERARCHY == TRUE)
+  if (thread->children != NULL) {
+    return thread->children;
+  } else {
+    while (thread != NULL && thread->sibling == NULL) {
+      thread = thread->parent;
+    }
+    return (thread != NULL) ? thread->sibling : NULL;
+  }
+#endif
+}
+
+#endif /* (CH_CFG_USE_REGISTRY == TRUE) || (CH_CFG_USE_THREADHIERARCHY == TRUE) */
+
 /** @} */
diff --git a/modules/aos_chconf.h b/modules/aos_chconf.h
index e373324..5f53125 100644
--- a/modules/aos_chconf.h
+++ b/modules/aos_chconf.h
@@ -165,7 +165,11 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
  * @note    The default is @p TRUE.
  */
 #if !defined(CH_CFG_USE_TM)
-#define CH_CFG_USE_TM                       TRUE
+#if ((AMIROOS_CFG_DBG == true) || (AMIROOS_CFG_PROFILE == true)) || defined(__DOXYGEN__)
+  #define CH_CFG_USE_TM                     TRUE
+#else
+  #define CH_CFG_USE_TM                     FALSE
+#endif
 #endif
 
 /**
@@ -270,11 +274,11 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
  * @details If enabled then the conditional variables APIs with timeout
  *          specification are included in the kernel.
  *
- * @note    The default is @p TRUE.
+ * @note    The default is @p FALSE.
  * @note    Requires @p CH_CFG_USE_CONDVARS.
  */
 #if !defined(CH_CFG_USE_CONDVARS_TIMEOUT)
-#define CH_CFG_USE_CONDVARS_TIMEOUT         TRUE
+#define CH_CFG_USE_CONDVARS_TIMEOUT         FALSE
 #endif
 
 /**
@@ -492,7 +496,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
  * @note    The default is @p FALSE.
  */
 #if !defined(CH_DBG_STATISTICS)
-#if ((CH_CFG_USE_TM == TRUE) && ((AMIROOS_CFG_DBG == true) || AMIROOS_CFG_PROFILE == true)) || defined(__DOXYGEN__)
+#if ((CH_CFG_USE_TM == TRUE) && ((AMIROOS_CFG_DBG == true) || (AMIROOS_CFG_PROFILE == true))) || defined(__DOXYGEN__)
   #define CH_DBG_STATISTICS                 TRUE
 #else
   #define CH_DBG_STATISTICS                 FALSE
