commit 1678f27084400f39b41adccc3089d38a26b1597f
Author: Simon Welzel <simonwelzel@live.de>
Date:   Thu Jan 24 17:22:04 2019 +0100

    Re-Added files to a newer version of AMiRo-OS

diff --git a/core/src/aos_main.cpp b/core/src/aos_main.cpp
index 9fb60dd..654be93 100644
--- a/core/src/aos_main.cpp
+++ b/core/src/aos_main.cpp
@@ -1,6 +1,6 @@
 /*
 AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
-Copyright (C) 2016..2018  Thomas Schöpping et al.
+Copyright (C) 2016..2019  Thomas Schöpping et al.
 
 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
@@ -61,7 +61,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 #define DELAYEVENT_MASK                         EVENT_MASK(4)
 
-#if (AMIROOS_CFG_SSSP_ENABLE == true)
+#if (AMIROOS_CFG_SSSP_ENABLE == true) || defined(__DOXYGEN__)
 
 /**
  * @brief   CAN message identifier for initialization of the SSSP stack initialization sequence.
@@ -78,7 +78,14 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 #define SSSP_STACKINIT_CANMSGID_ABORT           0x001
 
-#endif
+#else /* AMIROOS_CFG_SSSP_ENABLE == false */
+
+/**
+ * @brief   Default shutdown mode if SSSP is unavailable.
+ */
+#define AOS_SHUTDOWN_DEFAULT                    AOS_SHUTDOWN_DEEPSLEEP
+
+#endif /* AMIROOS_CFG_SSSP_ENABLE */
 
 /**
  * @brief   CAN message identifier for calender synchronization message.
@@ -106,8 +113,8 @@ static AosIOChannel _stdiochannel;
  * @brief   I/O shell channel for the programmer interface.
  */
 static AosShellChannel _stdshellchannel;
-#endif
-#endif
+#endif /* AMIROOS_CFG_SHELL_ENABLE == true */
+#endif /* defined(MODULE_HAL_PROGIF) */
 
 /*
  * hook to add further static variables
@@ -125,16 +132,15 @@ AMIROOS_CFG_MAIN_EXTRA_STATIC_VARIABLES
 static inline void _unexpectedEventError(const eventmask_t mask, const eventflags_t flags)
 {
 #if (AMIROOS_CFG_DBG == true)
-    aosprintf("CTRL: unexpected/unknown event received. mask: 0x%08X; flags: 0x%08X\n", mask, flags);
+  aosprintf("CTRL: unexpected/unknown event received. mask: 0x%08X; flags: 0x%08X\n", mask, flags);
 #else
-    (void)(mask);
-    (void)(flags);
+  (void)(mask);
+  (void)(flags);
 #endif
-    return;
+  return;
 }
 
-
-#if (AMIROOS_CFG_SSSP_ENABLE == true)
+#if (AMIROOS_CFG_SSSP_ENABLE == true) || defined(__DOXYGEN__)
 /**
  * @brief   Callback function to be used during SSSP stack initialization sequence.
  *
@@ -142,15 +148,16 @@ static inline void _unexpectedEventError(const eventmask_t mask, const eventflag
  */
 static void _ssspTimerCallback(void* par)
 {
-    aosDbgCheck(par != NULL);
+  aosDbgCheck(par != NULL);
 
-    chSysLockFromISR();
-    chEvtBroadcastI((event_source_t*)par);
-    chSysUnlockFromISR();
+  chSysLockFromISR();
+  chEvtBroadcastI((event_source_t*)par);
+  chSysUnlockFromISR();
 
-    return;
+  return;
 }
-#endif
+#endif /* AMIROOS_CFG_SSSP_ENABLE == true */
+
 /**
  * @brief   Helper function to serialize data.
  *
@@ -160,14 +167,14 @@ static void _ssspTimerCallback(void* par)
  */
 inline void _serialize(uint8_t* dst, const uint64_t src, const uint8_t n)
 {
-    aosDbgCheck(dst != NULL);
-    aosDbgCheck(n > 0 && n <= 8);
+  aosDbgCheck(dst != NULL);
+  aosDbgCheck(n > 0 && n <= 8);
 
-    for (uint8_t byte = 0; byte < n; ++byte) {
-        dst[byte] = (uint8_t)((src >> (byte * 8)) & 0xFF);
-    }
+  for (uint8_t byte = 0; byte < n; ++byte) {
+    dst[byte] = (uint8_t)((src >> (byte * 8)) & 0xFF);
+  }
 
-    return;
+  return;
 }
 
 /**
@@ -180,15 +187,15 @@ inline void _serialize(uint8_t* dst, const uint64_t src, const uint8_t n)
  */
 inline uint64_t _deserialize(uint8_t* src, const uint8_t n)
 {
-    aosDbgCheck(src != NULL);
-    aosDbgCheck(n > 0 && n <= 8);
+  aosDbgCheck(src != NULL);
+  aosDbgCheck(n > 0 && n <= 8);
 
-    uint64_t result = 0;
-    for (uint8_t byte = 0; byte < n; ++byte) {
-        result |= ((uint64_t)src[byte]) << (byte * 8);
-    }
+  uint64_t result = 0;
+  for (uint8_t byte = 0; byte < n; ++byte) {
+    result |= ((uint64_t)src[byte]) << (byte * 8);
+  }
 
-    return result;
+  return result;
 }
 
 /**
@@ -210,17 +217,17 @@ inline uint64_t _deserialize(uint8_t* src, const uint8_t n)
  */
 inline uint64_t _TM2U64(struct tm* src)
 {
-    aosDbgCheck(src != NULL);
-
-    return (((uint64_t)(src->tm_sec  & 0x0000003F) << (0))               |
-            ((uint64_t)(src->tm_min  & 0x0000003F) << (6))               |
-            ((uint64_t)(src->tm_hour & 0x0000001F) << (12))              |
-            ((uint64_t)(src->tm_mday & 0x0000001F) << (17))              |
-            ((uint64_t)(src->tm_mon  & 0x0000000F) << (22))              |
-            ((uint64_t)(src->tm_year & 0x00FFFFFF) << (26))              |
-            ((uint64_t)(src->tm_wday & 0x00000007) << (50))              |
-            ((uint64_t)(src->tm_yday & 0x000001FF) << (53))              |
-            ((uint64_t)((src->tm_isdst == 0) ? 0 : (src->tm_isdst > 0) ? 1 : 2) << (62)));
+  aosDbgCheck(src != NULL);
+
+  return (((uint64_t)(src->tm_sec  & 0x0000003F) << (0))               |
+          ((uint64_t)(src->tm_min  & 0x0000003F) << (6))               |
+          ((uint64_t)(src->tm_hour & 0x0000001F) << (12))              |
+          ((uint64_t)(src->tm_mday & 0x0000001F) << (17))              |
+          ((uint64_t)(src->tm_mon  & 0x0000000F) << (22))              |
+          ((uint64_t)(src->tm_year & 0x00FFFFFF) << (26))              |
+          ((uint64_t)(src->tm_wday & 0x00000007) << (50))              |
+          ((uint64_t)(src->tm_yday & 0x000001FF) << (53))              |
+          ((uint64_t)((src->tm_isdst == 0) ? 0 : (src->tm_isdst > 0) ? 1 : 2) << (62)));
 }
 
 /**
@@ -233,21 +240,22 @@ inline uint64_t _TM2U64(struct tm* src)
  */
 inline void _U642TM(struct tm* dst, const uint64_t src)
 {
-    aosDbgCheck(dst != NULL);
-
-    dst->tm_sec  = (src >> 0)  & 0x0000003F;
-    dst->tm_min  = (src >> 6)  & 0x0000003F;
-    dst->tm_hour = (src >> 12) & 0x0000001F;
-    dst->tm_mday = (src >> 17) & 0x0000001F;
-    dst->tm_mon  = (src >> 22) & 0x0000000F;
-    dst->tm_year = (src >> 26) & 0x00FFFFFF;
-    dst->tm_wday = (src >> 50) & 0x00000007;
-    dst->tm_yday = (src >> 53) & 0x000001FF;
-    dst->tm_isdst = (((src >> 62) & 0x03) == 0) ? 0 : (((src >> 62) & 0x03) > 0) ? 1 : -1;
-
-    return;
+  aosDbgCheck(dst != NULL);
+
+  dst->tm_sec  = (src >> 0)  & 0x0000003F;
+  dst->tm_min  = (src >> 6)  & 0x0000003F;
+  dst->tm_hour = (src >> 12) & 0x0000001F;
+  dst->tm_mday = (src >> 17) & 0x0000001F;
+  dst->tm_mon  = (src >> 22) & 0x0000000F;
+  dst->tm_year = (src >> 26) & 0x00FFFFFF;
+  dst->tm_wday = (src >> 50) & 0x00000007;
+  dst->tm_yday = (src >> 53) & 0x000001FF;
+  dst->tm_isdst = (((src >> 62) & 0x03) == 0) ? 0 : (((src >> 62) & 0x03) > 0) ? 1 : -1;
+
+  return;
 }
-#if (AMIROOS_CFG_SSSP_ENABLE == true)
+
+#if (AMIROOS_CFG_SSSP_ENABLE == true) || defined(__DOXYGEN__)
 /**
  * @brief   Implementation of the SSSP module stack initialization sequence (startup phase 3).
  *
@@ -257,67 +265,68 @@ inline void _U642TM(struct tm* dst, const uint64_t src)
  */
 aos_shutdown_t _ssspModuleStackInitialization(void)
 {
-    // local types
-    /**
+  // local types
+  /**
    * @brief   States for the internal state machine to implement SSSP startup stage 3.
    */
-    typedef enum {
-        STAGE_3_1,                  /**< Initiation of SSSP startup stage 3. */
-        STAGE_3_2,                  /**< Starting the sequence and broadcasting the first ID. */
-        STAGE_3_3_WAITFORFIRSTID,   /**< Waiting for first ID after initiation. */
-        STAGE_3_3_WAITFORIDORSIG,   /**< Waiting for next ID or activation of neighbor signal. */
-        STAGE_3_3_WAITFORID,        /**< Waiting for next ID (after the module has set its own ID). */
-        STAGE_3_4_FINISH,           /**< Successful finish of stage 3. */
-        STAGE_3_4_ABORT_ACTIVE,     /**< Aborting stage 3 (active). */
-        STAGE_3_4_ABORT,            /**< Aborting stage 3 (passive). */
-    } sssp_modulestackinitstage_t;
-
-    typedef struct {
-        bool loop     : 1;
-        bool wfe      : 1;
-        bool wfe_next : 1;
-    } flags_t;
-
-    // local variables
-    aos_shutdown_t shutdown = AOS_SHUTDOWN_NONE;
-    sssp_modulestackinitstage_t stage = STAGE_3_1;
-    eventmask_t eventmask = 0;
-    eventflags_t ioflags;
-    event_source_t eventSourceTimeout;
-    event_source_t eventSourceDelay;
-    event_listener_t eventListenerTimeout;
-    event_listener_t eventListenerDelay;
-    event_listener_t eventListenerCan;
-    virtual_timer_t timerTimeout;
-    virtual_timer_t timerDelay;
-    CANTxFrame canTxFrame;
-    CANRxFrame canRxFrame;
+  typedef enum {
+    STAGE_3_1,                  /**< Initiation of SSSP startup stage 3. */
+    STAGE_3_2,                  /**< Starting the sequence and broadcasting the first ID. */
+    STAGE_3_3_WAITFORFIRSTID,   /**< Waiting for first ID after initiation. */
+    STAGE_3_3_WAITFORIDORSIG,   /**< Waiting for next ID or activation of neighbor signal. */
+    STAGE_3_3_WAITFORID,        /**< Waiting for next ID (after the module has set its own ID). */
+    STAGE_3_4_FINISH,           /**< Successful finish of stage 3. */
+    STAGE_3_4_ABORT_ACTIVE,     /**< Aborting stage 3 (active). */
+    STAGE_3_4_ABORT,            /**< Aborting stage 3 (passive). */
+  } sssp_modulestackinitstage_t;
+
+  typedef struct {
+    bool loop     : 1;
+    bool wfe      : 1;
+    bool wfe_next : 1;
+  } flags_t;
+
+  // local variables
+  aos_shutdown_t shutdown = AOS_SHUTDOWN_NONE;
+  sssp_modulestackinitstage_t stage = STAGE_3_1;
+  eventmask_t eventmask = 0;
+  eventflags_t ioflags = 0;
+  event_source_t eventSourceTimeout;
+  event_source_t eventSourceDelay;
+  event_listener_t eventListenerTimeout;
+  event_listener_t eventListenerDelay;
+  event_listener_t eventListenerCan;
+  virtual_timer_t timerTimeout;
+  virtual_timer_t timerDelay;
+  CANTxFrame canTxFrame;
+  CANRxFrame canRxFrame;
 #if (AMIROOS_CFG_SSSP_STACK_START != true) || (AMIROOS_CFG_DBG == true)
-    aos_ssspmoduleid_t lastid = 0;
-#endif
-    flags_t flags;
-
-    // initialize local varibles
-    chEvtObjectInit(&eventSourceTimeout);
-    chEvtObjectInit(&eventSourceDelay);
-    chVTObjectInit(&timerTimeout);
-    chVTObjectInit(&timerDelay);
-    canTxFrame.RTR = CAN_RTR_DATA;
-    canTxFrame.IDE = CAN_IDE_STD;
-    flags.loop = true;
-    flags.wfe = false; // do not wait for events in the initial iteration of the FSM loop
-    flags.wfe_next = true;
-
-    // initialize system variables
-    aos.sssp.stage = AOS_SSSP_STARTUP_3_1;
-    aos.sssp.moduleId = 0;
-
-    // listen to events (timout, delay, CAN receive)
-    chEvtRegisterMask(&eventSourceTimeout, &eventListenerTimeout, TIMEOUTEVENT_MASK);
-    chEvtRegisterMask(&eventSourceDelay, &eventListenerDelay, DELAYEVENT_MASK);
-    chEvtRegisterMask(&MODULE_HAL_CAN.rxfull_event, &eventListenerCan, CANEVENT_MASK);
-
-    /*
+  aos_ssspmoduleid_t lastid = 0;
+#endif
+  flags_t flags;
+  aos_timestamp_t uptime;
+
+  // initialize local varibles
+  chEvtObjectInit(&eventSourceTimeout);
+  chEvtObjectInit(&eventSourceDelay);
+  chVTObjectInit(&timerTimeout);
+  chVTObjectInit(&timerDelay);
+  canTxFrame.RTR = CAN_RTR_DATA;
+  canTxFrame.IDE = CAN_IDE_STD;
+  flags.loop = true;
+  flags.wfe = false; // do not wait for events in the initial iteration of the FSM loop
+  flags.wfe_next = true;
+
+  // initialize system variables
+  aos.sssp.stage = AOS_SSSP_STARTUP_3_1;
+  aos.sssp.moduleId = 0;
+
+  // listen to events (timout, delay, CAN receive)
+  chEvtRegisterMask(&eventSourceTimeout, &eventListenerTimeout, TIMEOUTEVENT_MASK);
+  chEvtRegisterMask(&eventSourceDelay, &eventListenerDelay, DELAYEVENT_MASK);
+  chEvtRegisterMask(&MODULE_HAL_CAN.rxfull_event, &eventListenerCan, CANEVENT_MASK);
+
+  /*
    * FSM in a loop.
    *
    * This is a fully event-based FSM for the module stack initialization
@@ -344,894 +353,905 @@ aos_shutdown_t _ssspModuleStackInitialization(void)
    *  delays:     Depending on the current state, delays are required by SSSP
    *              for timing of the sequential activation of signals.
    */
-    aosDbgPrintf("SSSP stack initialization sequence:\n");
-    while (flags.loop) {
+  aosDbgPrintf("SSSP stack initialization sequence:\n");
+  while (flags.loop) {
 #if (AMIROOS_CFG_DBG == true)
-        switch (stage) {
-        case STAGE_3_1:
-            aosDbgPrintf(">>> 3-1\n");
-            break;
-        case STAGE_3_2:
-            aosDbgPrintf(">>> 3-2\n");
-            break;
-        case STAGE_3_3_WAITFORFIRSTID:
-            aosDbgPrintf(">>> 3-3 (1st ID)\n");
-            break;
-        case STAGE_3_3_WAITFORIDORSIG:
-            aosDbgPrintf(">>> 3-3 (ID/sig)\n");
-            break;
-        case STAGE_3_3_WAITFORID:
-            aosDbgPrintf(">>> 3-3 (ID)\n");
-            break;
-        case STAGE_3_4_FINISH:
-            aosDbgPrintf(">>> 3-4 (finish)\n");
-            break;
-        case STAGE_3_4_ABORT_ACTIVE:
-            aosDbgPrintf(">>> 3-4 (active abort)\n");
-            break;
-        case STAGE_3_4_ABORT:
-            aosDbgPrintf(">>> 3-4 (abort)\n");
-            break;
-        }
+    switch (stage) {
+      case STAGE_3_1:
+        aosDbgPrintf(">>> 3-1\n");
+        break;
+      case STAGE_3_2:
+        aosDbgPrintf(">>> 3-2\n");
+        break;
+      case STAGE_3_3_WAITFORFIRSTID:
+        aosDbgPrintf(">>> 3-3 (1st ID)\n");
+        break;
+      case STAGE_3_3_WAITFORIDORSIG:
+        aosDbgPrintf(">>> 3-3 (ID/sig)\n");
+        break;
+      case STAGE_3_3_WAITFORID:
+        aosDbgPrintf(">>> 3-3 (ID)\n");
+        break;
+      case STAGE_3_4_FINISH:
+        aosDbgPrintf(">>> 3-4 (finish)\n");
+        break;
+      case STAGE_3_4_ABORT_ACTIVE:
+        aosDbgPrintf(">>> 3-4 (active abort)\n");
+        break;
+      case STAGE_3_4_ABORT:
+        aosDbgPrintf(">>> 3-4 (abort)\n");
+        break;
+    }
 #endif
 
-        // reset wfe flag for the next iteration
-        flags.wfe_next = true;
+    // reset wfe flag for the next iteration
+    flags.wfe_next = true;
 
-        // waiting for events may be skipped
-        if (flags.wfe) {
-            // wait for any event to occur
-            aosDbgPrintf("WFE...");
-            eventmask = chEvtWaitAnyTimeout(ALL_EVENTS, chTimeUS2I(AOS_SYSTEM_SSSP_TIMEOUT));
-            aosDbgPrintf("\t0x%08X", eventmask);
-        } else {
-            aosDbgPrintf("WFE skipped");
-        }
-        aos_timestamp_t uptime;
-        aosSysGetUptime(&uptime);
-        aosDbgPrintf("\t%04ums\n", (uint32_t)(uptime / 1000));
+    // waiting for events (may be skipped)
+    if (flags.wfe) {
+      // wait for any event to occur
+      aosDbgPrintf("WFE...");
+      eventmask = chEvtWaitAnyTimeout(ALL_EVENTS, chTimeUS2I(AOS_SYSTEM_SSSP_TIMEOUT));
+      aosDbgPrintf("\t0x%08X", eventmask);
+    } else {
+      aosDbgPrintf("WFE skipped");
+      eventmask = 0;
+    }
+    aosSysGetUptime(&uptime);
+    aosDbgPrintf("\t%04ums\n", (uint32_t)(uptime / MICROSECONDS_PER_MILLISECOND));
 
-        /*
+    /*
      * execute some general tasks and high priority events
      */
-        // no event occurred at all
-        if ((flags.wfe) && (eventmask == 0)) {
-            aosDbgPrintf("ERR: no evt\n");
-            // enforce timeout event
-            chEvtBroadcast(&eventSourceTimeout);
-            continue;
-        }
-        // if an IO event occurred
-        if (eventmask & _eventListenerIO.events) {
-            ioflags = chEvtGetAndClearFlags(&_eventListenerIO);
-            aosDbgPrintf("INFO: IO evt (0x%08X)\n", ioflags);
-            // a power-down event occurred
-            if (ioflags & MODULE_SSSP_EVENTFLAGS_PD) {
-                aosDbgPrintf("PD evt\n");
-                // deactivate S and UP
-                apalControlGpioSet(&moduleSsspGpioSync, APAL_GPIO_OFF);
+    // no event occurred at all
+    if ((flags.wfe) && (eventmask == 0)) {
+      aosDbgPrintf("ERR: no evt\n");
+      // enforce timeout event
+      chEvtBroadcast(&eventSourceTimeout);
+      continue;
+    }
+    // if an IO event occurred
+    if (eventmask & _eventListenerIO.events) {
+      ioflags = chEvtGetAndClearFlags(&_eventListenerIO);
+      aosDbgPrintf("INFO: IO evt (0x%08X)\n", ioflags);
+      // a power-down event occurred
+      if (ioflags & MODULE_SSSP_EVENTFLAGS_PD) {
+        aosDbgPrintf("PD evt\n");
+        // deactivate S and UP
+        aosDbgPrintf("disabling S\n");
+        apalControlGpioSet(&moduleSsspGpioSync, APAL_GPIO_OFF);
 #if (AMIROOS_CFG_SSSP_STACK_END != true)
-                apalControlGpioSet(&moduleSsspGpioUp, APAL_GPIO_OFF);
-#endif
-                // set shutdown flag and exit the loop
-                shutdown = AOS_SHUTDOWN_PASSIVE;
-                break;
-            }
-            // the S signal was deactivated
-            if (ioflags & MODULE_SSSP_EVENTFLAGS_SYNC) {
-                apalControlGpioState_t sstate;
-                apalControlGpioGet(&moduleSsspGpioSync, &sstate);
-                if (sstate == APAL_GPIO_OFF) {
-                    aosDbgPrintf("-S evt\n");
-                    // either finish or abort
-                    if ((stage == STAGE_3_3_WAITFORID) && (aos.sssp.moduleId != 0)) {
-                        stage = STAGE_3_4_FINISH;
-                    } else if (stage != STAGE_3_4_ABORT) {
-                        stage = STAGE_3_4_ABORT_ACTIVE;
-                    }
-                }
-            }
+        aosDbgPrintf("disabling UP\n");
+        apalControlGpioSet(&moduleSsspGpioUp, APAL_GPIO_OFF);
+#endif
+        // set shutdown flag and exit the loop
+        shutdown = AOS_SHUTDOWN_PASSIVE;
+        break;
+      }
+      // the S signal was deactivated
+      if (ioflags & MODULE_SSSP_EVENTFLAGS_SYNC) {
+        apalControlGpioState_t sstate;
+        apalControlGpioGet(&moduleSsspGpioSync, &sstate);
+        if (sstate == APAL_GPIO_ON) {
+          aosDbgPrintf("S evt (enabled)\n");
+        } else {
+          aosDbgPrintf("S evt (disabled)\n");
+          // either finish or abort
+          if ((stage == STAGE_3_3_WAITFORID) && (aos.sssp.moduleId != 0)) {
+            stage = STAGE_3_4_FINISH;
+          } else if (stage != STAGE_3_4_ABORT) {
+            stage = STAGE_3_4_ABORT_ACTIVE;
+          }
         }
-        // an OS event occurred
-        if (eventmask & _eventListenerOS.events) {
-            aosDbgPrintf("WARN: OS evt\n");
-            // get the flags
-            eventflags_t oseventflags = chEvtGetAndClearFlags(&_eventListenerOS);
-            // there should be no OS events at this point
+      }
+    }
+    // an OS event occurred
+    if (eventmask & _eventListenerOS.events) {
+      aosDbgPrintf("WARN: OS evt\n");
+      // get the flags
+      eventflags_t oseventflags = chEvtGetAndClearFlags(&_eventListenerOS);
+      // there should be no OS events at this point
 #ifdef MODULE_SSSP_STARTUP_3_OSEVENT_HOOK
-            MODULE_SSSP_STARTUP_3_OSEVENT_HOOK(eventmask, eventflags);
+      MODULE_SSSP_STARTUP_3_OSEVENT_HOOK(eventmask, eventflags);
 #else
-            _unexpectedEventError(eventmask, oseventflags);
+      _unexpectedEventError(eventmask, oseventflags);
 #endif
-        }
-        // if a CAN event occurred
-        if ((eventmask & eventListenerCan.events)) {
-            // fetch message
-            if (flags.wfe) {
-                canReceiveTimeout(&MODULE_HAL_CAN, CAN_ANY_MAILBOX, &canRxFrame, TIME_IMMEDIATE);
-                aosDbgPrintf("CAN <- 0x%03X\n", canRxFrame.SID);
-            }
-            // identify and handle abort messgaes
-            if (canRxFrame.SID == SSSP_STACKINIT_CANMSGID_ABORT) {
-                stage = STAGE_3_4_ABORT;
-            }
-            // warn if a unexpected message was received
-            else if ((canRxFrame.SID != SSSP_STACKINIT_CANMSGID_INIT) &&
-                     (canRxFrame.SID != SSSP_STACKINIT_CANMSGID_MODULEID)) {
-                aosDbgPrintf("WARN: unknown msg\n");
-            }
-            // any further pending messages are fetched at the end of the loop
-        }
-        // if a timeout event occurred
-        if (eventmask & eventListenerTimeout.events) {
-            // is handled at the end of the loop (or must be cleared by FSM)
-        }
-        // if a delay event occurred
-        if (eventmask & eventListenerDelay.events) {
-            // is handled by FSM
-        }
+    }
+    // if a CAN event occurred
+    if ((eventmask & eventListenerCan.events)) {
+      aosDbgPrintf("CAN evt\n");
+      // fetch message
+      if (flags.wfe) {
+        canReceiveTimeout(&MODULE_HAL_CAN, CAN_ANY_MAILBOX, &canRxFrame, TIME_IMMEDIATE);
+        aosDbgPrintf("CAN <- 0x%03X\n", canRxFrame.SID);
+      }
+      // identify and handle abort messgaes
+      if (canRxFrame.SID == SSSP_STACKINIT_CANMSGID_ABORT) {
+        stage = STAGE_3_4_ABORT;
+      }
+      // warn if a unexpected message was received
+      else if ((canRxFrame.SID != SSSP_STACKINIT_CANMSGID_INIT) &&
+               (canRxFrame.SID != SSSP_STACKINIT_CANMSGID_MODULEID)) {
+        aosDbgPrintf("WARN: unknown msg\n");
+      }
+      // any further pending messages are fetched at the end of the loop
+    }
+    // if a timeout event occurred
+    if (eventmask & eventListenerTimeout.events) {
+      aosDbgPrintf("timeout evt\n");
+      // is handled at the end of the loop (or must be cleared by FSM)
+    }
+    // if a delay event occurred
+    if (eventmask & eventListenerDelay.events) {
+      aosDbgPrintf("delay evt\n");
+      // is handled by FSM
+    }
 
-        /*
+    /*
      * this is the actual FSM
      */
-        switch (stage) {
-        case STAGE_3_1:
-        {
-            aos.sssp.stage = AOS_SSSP_STARTUP_3_1;
+    switch (stage) {
+      case STAGE_3_1:
+      {
+        aos.sssp.stage = AOS_SSSP_STARTUP_3_1;
 
-            // there was no event at all (skipped wfe)
-            if (eventmask == 0 && flags.wfe == false) {
+        // there was no event at all (skipped wfe)
+        if (eventmask == 0 && flags.wfe == false) {
 #if (AMIROOS_CFG_SSSP_MASTER == true)
-                // initialize the stage by transmitting an according CAN message
-                aosDbgPrintf("CAN -> init\n");
-                canTxFrame.DLC = 0;
-                canTxFrame.SID = SSSP_STACKINIT_CANMSGID_INIT;
-                if (canTransmitTimeout(&MODULE_HAL_CAN, CAN_ANY_MAILBOX, &canTxFrame, TIME_IMMEDIATE) != MSG_OK) {
-                    chEvtBroadcast(&eventSourceTimeout);
-                    break;
-                }
-                // activate S
-                aosDbgPrintf("S+\n");
-                apalControlGpioSet(&moduleSsspGpioSync, APAL_GPIO_ON);
+          // initialize the stage by transmitting an according CAN message
+          aosDbgPrintf("CAN -> init\n");
+          canTxFrame.DLC = 0;
+          canTxFrame.SID = SSSP_STACKINIT_CANMSGID_INIT;
+          if (canTransmitTimeout(&MODULE_HAL_CAN, CAN_ANY_MAILBOX, &canTxFrame, TIME_IMMEDIATE) != MSG_OK) {
+            chEvtBroadcast(&eventSourceTimeout);
+            break;
+          }
+          // activate S
+          aosDbgPrintf("enabling S\n");
+          apalControlGpioSet(&moduleSsspGpioSync, APAL_GPIO_ON);
 #if (AMIROOS_CFG_SSSP_STACK_START == true)
-                // proceed immediately
-                stage = STAGE_3_2;
-                flags.wfe_next = false;
+          // proceed immediately
+          stage = STAGE_3_2;
+          flags.wfe_next = false;
 #else
-                // set the timeout timer
-                chVTSet(&timerTimeout, chTimeUS2I(AOS_SYSTEM_SSSP_TIMEOUT), _ssspTimerCallback, &eventSourceTimeout);
-                // proceed
-                stage = STAGE_3_3_WAITFORFIRSTID;
+          // set the timeout timer
+          chVTSet(&timerTimeout, chTimeUS2I(AOS_SYSTEM_SSSP_TIMEOUT), _ssspTimerCallback, &eventSourceTimeout);
+          // proceed
+          stage = STAGE_3_3_WAITFORFIRSTID;
 #endif
 #else
-                // set the timeout timer
-                chVTSet(&timerTimeout, chTimeUS2I(AOS_SYSTEM_SSSP_TIMEOUT), _ssspTimerCallback, &eventSourceTimeout);
+          // set the timeout timer
+          chVTSet(&timerTimeout, chTimeUS2I(AOS_SYSTEM_SSSP_TIMEOUT), _ssspTimerCallback, &eventSourceTimeout);
 #endif
-            }
+        }
 
 #if (AMIROOS_CFG_SSSP_MASTER != true)
-            // a CAN message was received
-            else if (eventmask & eventListenerCan.events) {
-                // if an initiation message was received
-                if (canRxFrame.DLC == 0 &&
-                        canRxFrame.RTR == CAN_RTR_DATA &&
-                        canRxFrame.IDE == CAN_IDE_STD &&
-                        canRxFrame.SID == SSSP_STACKINIT_CANMSGID_INIT) {
-                    aosDbgPrintf("init msg\n");
-                    // reset the timeout timer and clear pending flags
-                    chVTReset(&timerTimeout);
-                    chEvtWaitAnyTimeout(eventListenerTimeout.events, TIME_IMMEDIATE);
-                    eventmask &= ~(eventListenerTimeout.events);
-                    // activate S
-                    aosDbgPrintf("S+\n");
-                    apalControlGpioSet(&moduleSsspGpioSync, APAL_GPIO_ON);
+        // a CAN message was received
+        else if (eventmask & eventListenerCan.events) {
+          // if an initiation message was received
+          if (canRxFrame.DLC == 0 &&
+              canRxFrame.RTR == CAN_RTR_DATA &&
+              canRxFrame.IDE == CAN_IDE_STD &&
+              canRxFrame.SID == SSSP_STACKINIT_CANMSGID_INIT) {
+            aosDbgPrintf("init msg\n");
+            // reset the timeout timer and clear pending flags
+            chVTReset(&timerTimeout);
+            chEvtWaitAnyTimeout(eventListenerTimeout.events, TIME_IMMEDIATE);
+            eventmask &= ~(eventListenerTimeout.events);
+            // activate S
+            aosDbgPrintf("enabling S\n");
+            apalControlGpioSet(&moduleSsspGpioSync, APAL_GPIO_ON);
 #if (AMIROOS_CFG_SSSP_STACK_START == true)
-                    // proceed
-                    stage = STAGE_3_2;
-                    flags.wfe_next = false;
+            // proceed
+            stage = STAGE_3_2;
+            flags.wfe_next = false;
 #else
-                    // set the timeout timer
-                    chVTSet(&timerTimeout, chTimeUS2I(AOS_SYSTEM_SSSP_TIMEOUT), _ssspTimerCallback, &eventSourceTimeout);
-                    // proceed
-                    stage = STAGE_3_3_WAITFORFIRSTID;
+            // set the timeout timer
+            chVTSet(&timerTimeout, chTimeUS2I(AOS_SYSTEM_SSSP_TIMEOUT), _ssspTimerCallback, &eventSourceTimeout);
+            // proceed
+            stage = STAGE_3_3_WAITFORFIRSTID;
 #endif
-                }
-            }
+          }
+        }
 #endif
 
-            break;
-        } /* end of STAGE_3_1 */
+        break;
+      } /* end of STAGE_3_1 */
 
-        case STAGE_3_2:
-        {
+      case STAGE_3_2:
+      {
 #if (AMIROOS_CFG_SSSP_STACK_START == true)
-            aos.sssp.stage = AOS_SSSP_STARTUP_3_2;
-
-            // if this stage was just entered
-            if (flags.wfe == false) {
-                // set the module ID
-                aos.sssp.moduleId = 1;
-                // broadcast module ID
-                aosDbgPrintf("CAN -> ID (%u)\n", aos.sssp.moduleId);
-                canTxFrame.DLC = 4;
-                canTxFrame.SID = SSSP_STACKINIT_CANMSGID_MODULEID;
-                _serialize(canTxFrame.data8, aos.sssp.moduleId, 4);
-                if (canTransmitTimeout(&MODULE_HAL_CAN, CAN_ANY_MAILBOX, &canTxFrame, TIME_IMMEDIATE) != MSG_OK) {
-                    chEvtBroadcast(&eventSourceTimeout);
-                    break;
-                }
+        aos.sssp.stage = AOS_SSSP_STARTUP_3_2;
+
+        // if this stage was just entered
+        if (flags.wfe == false) {
+          // set the module ID
+          aos.sssp.moduleId = 1;
+          // broadcast module ID
+          aosDbgPrintf("CAN -> ID (%u)\n", aos.sssp.moduleId);
+          canTxFrame.DLC = 4;
+          canTxFrame.SID = SSSP_STACKINIT_CANMSGID_MODULEID;
+          _serialize(canTxFrame.data8, aos.sssp.moduleId, 4);
+          if (canTransmitTimeout(&MODULE_HAL_CAN, CAN_ANY_MAILBOX, &canTxFrame, TIME_IMMEDIATE) != MSG_OK) {
+            chEvtBroadcast(&eventSourceTimeout);
+            break;
+          }
 #if (AMIROOS_CFG_SSSP_STACK_START != true) || (AMIROOS_CFG_DBG == true)
-                lastid = aos.sssp.moduleId;
+          lastid = aos.sssp.moduleId;
 #endif
 #if (AMIROOS_CFG_SSSP_STACK_END == true)
-                // sequence is already over
-                // deactivate S
-                aosDbgPrintf("S-\n");
-                apalControlGpioSet(&moduleSsspGpioSync, APAL_GPIO_OFF);
-                // proceed
-                stage = STAGE_3_3_WAITFORID;
+          // sequence is already over
+          // deactivate S
+          aosDbgPrintf("disabling S\n");
+          apalControlGpioSet(&moduleSsspGpioSync, APAL_GPIO_OFF);
+          // proceed
+          stage = STAGE_3_3_WAITFORID;
 #else
-                // set the delay timer so the UP signal is activated later
-                chVTSet(&timerDelay, chTimeUS2I(AMIROOS_CFG_SSSP_SIGNALDELAY), _ssspTimerCallback, &eventSourceDelay);
+          // set the delay timer so the UP signal is activated later
+          chVTSet(&timerDelay, chTimeUS2I(AMIROOS_CFG_SSSP_SIGNALDELAY), _ssspTimerCallback, &eventSourceDelay);
 #endif
-            }
+        }
 
-            // if a delay event occurred
-            if (eventmask & eventListenerDelay.events) {
-                // activate UP
-                aosDbgPrintf("UP+\n");
-                apalControlGpioSet(&moduleSsspGpioUp, APAL_GPIO_ON);
-                // deactivate S
-                aosDbgPrintf("S-\n");
-                apalControlGpioSet(&moduleSsspGpioSync, APAL_GPIO_OFF);
-                // explicitely clear timeout event flag
-                chEvtWaitAnyTimeout(eventListenerTimeout.events, TIME_IMMEDIATE);
-                eventmask &= ~(eventListenerTimeout.events);
-                // proceed
-                stage = STAGE_3_3_WAITFORID;
-            }
+        // if a delay event occurred
+        if (eventmask & eventListenerDelay.events) {
+          // activate UP
+          aosDbgPrintf("enabling UP\n");
+          apalControlGpioSet(&moduleSsspGpioUp, APAL_GPIO_ON);
+          // deactivate S
+          aosDbgPrintf("disabling S\n");
+          apalControlGpioSet(&moduleSsspGpioSync, APAL_GPIO_OFF);
+          // explicitely clear timeout event flag
+          chEvtWaitAnyTimeout(eventListenerTimeout.events, TIME_IMMEDIATE);
+          eventmask &= ~(eventListenerTimeout.events);
+          // proceed
+          stage = STAGE_3_3_WAITFORID;
+        }
 #endif
 
-            break;
-        } /* end of STAGE_3_2 */
+        break;
+      } /* end of STAGE_3_2 */
 
-        case STAGE_3_3_WAITFORFIRSTID:
-        {
+      case STAGE_3_3_WAITFORFIRSTID:
+      {
 #if (AMIROOS_CFG_SSSP_STACK_START != true)
-            aos.sssp.stage = AOS_SSSP_STARTUP_3_3;
-
-            // a CAN message was received
-            if (eventmask & eventListenerCan.events) {
-                // if an ID message was received
-                if (canRxFrame.DLC == 4 &&
-                        canRxFrame.RTR == CAN_RTR_DATA &&
-                        canRxFrame.IDE == CAN_IDE_STD &&
-                        canRxFrame.SID == SSSP_STACKINIT_CANMSGID_MODULEID) {
-                    aosDbgPrintf("ID (%u)\n", (uint32_t)_deserialize(canRxFrame.data8, 4));
-                    // validate received ID
-                    if (lastid < _deserialize(canRxFrame.data8, 4)) {
-                        // store received ID
-                        lastid = _deserialize(canRxFrame.data8, 4);
-                        // restart timeout timer
-                        chVTSet(&timerTimeout, chTimeUS2I(AOS_SYSTEM_SSSP_TIMEOUT), _ssspTimerCallback, &eventSourceTimeout);
-                        // proceed
-                        stage = STAGE_3_3_WAITFORIDORSIG;
-                    } else {
-                        aosDbgPrintf("ERR: invalid ID\n");
-                        // abort
-                        stage = STAGE_3_4_ABORT_ACTIVE;
-                        flags.wfe_next = false;
-                    }
-                    // explicitely clear timeout event flag
-                    chEvtWaitAnyTimeout(eventListenerTimeout.events, TIME_IMMEDIATE);
-                    eventmask &= ~(eventListenerTimeout.events);
-                }
+        aos.sssp.stage = AOS_SSSP_STARTUP_3_3;
+
+        // a CAN message was received
+        if (eventmask & eventListenerCan.events) {
+          // if an ID message was received
+          if (canRxFrame.DLC == 4 &&
+              canRxFrame.RTR == CAN_RTR_DATA &&
+              canRxFrame.IDE == CAN_IDE_STD &&
+              canRxFrame.SID == SSSP_STACKINIT_CANMSGID_MODULEID) {
+            aosDbgPrintf("ID (%u)\n", (uint32_t)_deserialize(canRxFrame.data8, 4));
+            // validate received ID
+            if (lastid < _deserialize(canRxFrame.data8, 4)) {
+              // store received ID
+              lastid = _deserialize(canRxFrame.data8, 4);
+              // restart timeout timer
+              chVTSet(&timerTimeout, chTimeUS2I(AOS_SYSTEM_SSSP_TIMEOUT), _ssspTimerCallback, &eventSourceTimeout);
+              // proceed
+              stage = STAGE_3_3_WAITFORIDORSIG;
+            } else {
+              aosDbgPrintf("ERR: invalid ID\n");
+              // abort
+              stage = STAGE_3_4_ABORT_ACTIVE;
+              flags.wfe_next = false;
             }
+            // explicitely clear timeout event flag
+            chEvtWaitAnyTimeout(eventListenerTimeout.events, TIME_IMMEDIATE);
+            eventmask &= ~(eventListenerTimeout.events);
+          }
+        }
 #endif
-            break;
-        } /* end of STAGE_3_3_WAITFORFIRSTID */
+        break;
+      } /* end of STAGE_3_3_WAITFORFIRSTID */
 
-        case STAGE_3_3_WAITFORIDORSIG:
-        {
+      case STAGE_3_3_WAITFORIDORSIG:
+      {
 #if (AMIROOS_CFG_SSSP_STACK_START != true)
-            aos.sssp.stage = AOS_SSSP_STARTUP_3_3;
-
-            // a CAN message was received
-            if (eventmask & eventListenerCan.events) {
-                // if an ID message was received
-                if (canRxFrame.DLC == 4 &&
-                        canRxFrame.RTR == CAN_RTR_DATA &&
-                        canRxFrame.IDE == CAN_IDE_STD &&
-                        canRxFrame.SID == SSSP_STACKINIT_CANMSGID_MODULEID) {
-                    aosDbgPrintf("ID (%u)\n", (uint32_t)_deserialize(canRxFrame.data8, 4));
-                    // validate received ID
-                    if (lastid < _deserialize(canRxFrame.data8, 4)) {
-                        // store received ID
-                        lastid = _deserialize(canRxFrame.data8, 4);
-                        // restart timeout timer
-                        chVTSet(&timerTimeout, chTimeUS2I(AOS_SYSTEM_SSSP_TIMEOUT), _ssspTimerCallback, &eventSourceTimeout);
-                    } else {
-                        aosDbgPrintf("ERR: invalid ID\n");
-                        // abort
-                        stage = STAGE_3_4_ABORT_ACTIVE;
-                        flags.wfe_next = false;
-                    }
-                    // explicitely clear timeout event flag
-                    chEvtWaitAnyTimeout(eventListenerTimeout.events, TIME_IMMEDIATE);
-                    eventmask &= ~(eventListenerTimeout.events);
-                }
+        aos.sssp.stage = AOS_SSSP_STARTUP_3_3;
+
+        // a CAN message was received
+        if (eventmask & eventListenerCan.events) {
+          // if an ID message was received
+          if (canRxFrame.DLC == 4 &&
+              canRxFrame.RTR == CAN_RTR_DATA &&
+              canRxFrame.IDE == CAN_IDE_STD &&
+              canRxFrame.SID == SSSP_STACKINIT_CANMSGID_MODULEID) {
+            aosDbgPrintf("ID (%u)\n", (uint32_t)_deserialize(canRxFrame.data8, 4));
+            // validate received ID
+            if (lastid < _deserialize(canRxFrame.data8, 4)) {
+              // store received ID
+              lastid = _deserialize(canRxFrame.data8, 4);
+              // restart timeout timer
+              chVTSet(&timerTimeout, chTimeUS2I(AOS_SYSTEM_SSSP_TIMEOUT), _ssspTimerCallback, &eventSourceTimeout);
+            } else {
+              aosDbgPrintf("ERR: invalid ID\n");
+              // abort
+              stage = STAGE_3_4_ABORT_ACTIVE;
+              flags.wfe_next = false;
             }
+            // explicitely clear timeout event flag
+            chEvtWaitAnyTimeout(eventListenerTimeout.events, TIME_IMMEDIATE);
+            eventmask &= ~(eventListenerTimeout.events);
+          }
+        }
 
-            // if an IO event was received (DN signal)
-            if ((eventmask & _eventListenerIO.events) && (ioflags & MODULE_SSSP_EVENTFLAGS_DN)) {
-                aosDbgPrintf("DN <-\n");
-                // reset timeout timer
-                chVTReset(&timerTimeout);
-                chEvtWaitAnyTimeout(eventListenerTimeout.events, TIME_IMMEDIATE);
-                eventmask &= ~(eventListenerTimeout.events);
-                // increment and broadcast ID
-                aos.sssp.moduleId = lastid + 1;
-                aosDbgPrintf("CAN -> ID (%u)\n", aos.sssp.moduleId);
-                canTxFrame.DLC = 4;
-                canTxFrame.SID = SSSP_STACKINIT_CANMSGID_MODULEID;
-                _serialize(canTxFrame.data8, aos.sssp.moduleId, 4);
-                if (canTransmitTimeout(&MODULE_HAL_CAN, CAN_ANY_MAILBOX, &canTxFrame, TIME_IMMEDIATE) != MSG_OK) {
-                    chEvtBroadcast(&eventSourceTimeout);
-                    break;
-                }
-                // set delay timer
-                chVTSet(&timerDelay, chTimeUS2I(AMIROOS_CFG_SSSP_SIGNALDELAY), _ssspTimerCallback, &eventSourceDelay);
-            }
+        // if an IO event was received (DN signal)
+        if ((eventmask & _eventListenerIO.events) && (ioflags & MODULE_SSSP_EVENTFLAGS_DN)) {
+          aosDbgPrintf("DN evt\n");
+          // reset timeout timer
+          chVTReset(&timerTimeout);
+          chEvtWaitAnyTimeout(eventListenerTimeout.events, TIME_IMMEDIATE);
+          eventmask &= ~(eventListenerTimeout.events);
+          // increment and broadcast ID
+          aos.sssp.moduleId = lastid + 1;
+          aosDbgPrintf("CAN -> ID (%u)\n", aos.sssp.moduleId);
+          canTxFrame.DLC = 4;
+          canTxFrame.SID = SSSP_STACKINIT_CANMSGID_MODULEID;
+          _serialize(canTxFrame.data8, aos.sssp.moduleId, 4);
+          if (canTransmitTimeout(&MODULE_HAL_CAN, CAN_ANY_MAILBOX, &canTxFrame, TIME_IMMEDIATE) != MSG_OK) {
+            chEvtBroadcast(&eventSourceTimeout);
+            break;
+          }
+          // set delay timer
+          chVTSet(&timerDelay, chTimeUS2I(AMIROOS_CFG_SSSP_SIGNALDELAY), _ssspTimerCallback, &eventSourceDelay);
+        }
 
-            // if a delay event occurred
-            if (eventmask & eventListenerDelay.events) {
+        // if a delay event occurred
+        if (eventmask & eventListenerDelay.events) {
 #if (AMIROOS_CFG_SSSP_STACK_END != true)
-                // activate UP
-                aosDbgPrintf("UP+\n");
-                apalControlGpioSet(&moduleSsspGpioUp, APAL_GPIO_ON);
-#endif
-                // deactivate S
-                aosDbgPrintf("S-\n");
-                apalControlGpioSet(&moduleSsspGpioSync, APAL_GPIO_OFF);
-                // reset the timeout timer
-                chVTSet(&timerTimeout, chTimeUS2I(AOS_SYSTEM_SSSP_TIMEOUT), _ssspTimerCallback, &eventSourceTimeout);
-                chEvtWaitAnyTimeout(eventListenerTimeout.events, TIME_IMMEDIATE);
-                eventmask &= ~(eventListenerTimeout.events);
-                // proceed
-                stage = STAGE_3_3_WAITFORID;
-            }
+          // activate UP
+          aosDbgPrintf("enabling UP\n");
+          apalControlGpioSet(&moduleSsspGpioUp, APAL_GPIO_ON);
+#endif
+          // deactivate S
+          aosDbgPrintf("disabling S\n");
+          apalControlGpioSet(&moduleSsspGpioSync, APAL_GPIO_OFF);
+          // reset the timeout timer
+          chVTSet(&timerTimeout, chTimeUS2I(AOS_SYSTEM_SSSP_TIMEOUT), _ssspTimerCallback, &eventSourceTimeout);
+          chEvtWaitAnyTimeout(eventListenerTimeout.events, TIME_IMMEDIATE);
+          eventmask &= ~(eventListenerTimeout.events);
+          // proceed
+          stage = STAGE_3_3_WAITFORID;
+        }
 #endif
 
-            break;
-        } /* end of STAGE_3_3_WAITFORIDORSIG */
+        break;
+      } /* end of STAGE_3_3_WAITFORIDORSIG */
 
-        case STAGE_3_3_WAITFORID:
-        {
-            aos.sssp.stage = AOS_SSSP_STARTUP_3_3;
+      case STAGE_3_3_WAITFORID:
+      {
+        aos.sssp.stage = AOS_SSSP_STARTUP_3_3;
 
 #if (AMIROOS_CFG_SSSP_STACK_END != true)
-            // a CAN message was received
-            if (eventmask & eventListenerCan.events) {
-                // if an ID message was received
-                if (canRxFrame.DLC == 4 &&
-                        canRxFrame.RTR == CAN_RTR_DATA &&
-                        canRxFrame.IDE == CAN_IDE_STD &&
-                        canRxFrame.SID == SSSP_STACKINIT_CANMSGID_MODULEID) {
+        // a CAN message was received
+        if (eventmask & eventListenerCan.events) {
+          // if an ID message was received
+          if (canRxFrame.DLC == 4 &&
+              canRxFrame.RTR == CAN_RTR_DATA &&
+              canRxFrame.IDE == CAN_IDE_STD &&
+              canRxFrame.SID == SSSP_STACKINIT_CANMSGID_MODULEID) {
 #if (AMIROOS_CFG_SSSP_STACK_START != true) || (AMIROOS_CFG_DBG == true)
-                    // Plausibility of the received ID is not checked at this point but is done by other modules still in a previous stage.
-                    lastid = _deserialize(canRxFrame.data8, 4);
-                    aosDbgPrintf("ID (%u)\n", lastid);
-#endif
-                    // restart timeout timer
-                    chVTSet(&timerTimeout, chTimeUS2I(AOS_SYSTEM_SSSP_TIMEOUT), _ssspTimerCallback, &eventSourceTimeout);
-                    chEvtWaitAnyTimeout(eventListenerTimeout.events, TIME_IMMEDIATE);
-                    eventmask &= ~(eventListenerTimeout.events);
-                }
-            }
+            // Plausibility of the received ID is not checked at this point but is done by other modules still in a previous stage.
+            lastid = _deserialize(canRxFrame.data8, 4);
+            aosDbgPrintf("ID (%u)\n", lastid);
+#endif
+            // restart timeout timer
+            chVTSet(&timerTimeout, chTimeUS2I(AOS_SYSTEM_SSSP_TIMEOUT), _ssspTimerCallback, &eventSourceTimeout);
+            chEvtWaitAnyTimeout(eventListenerTimeout.events, TIME_IMMEDIATE);
+            eventmask &= ~(eventListenerTimeout.events);
+          }
+        }
 #endif
 
-            break;
-        } /* end of STAGE_3_3_WAITFORID */
-
-        case STAGE_3_4_FINISH:
-        {
-            aos.sssp.stage = AOS_SSSP_STARTUP_3_4;
-
-            // if an IO event was received (S signal)
-            if ((eventmask & _eventListenerIO.events) && (ioflags & MODULE_SSSP_EVENTFLAGS_SYNC)) {
-                // reset the timeout timer
-                chVTReset(&timerTimeout);
-                chEvtWaitAnyTimeout(eventListenerTimeout.events, TIME_IMMEDIATE);
-                eventmask &= ~(eventListenerTimeout.events);
-                //set the delay timer
-                chVTSet(&timerDelay, chTimeUS2I(AOS_SYSTEM_SSSP_TIMEOUT), _ssspTimerCallback, &eventSourceDelay);
-            }
+        break;
+      } /* end of STAGE_3_3_WAITFORID */
 
-            // if a CAN event was received
-            if (eventmask & eventListenerCan.events) {
-                // if an abort message was received
-                if (canRxFrame.SID == SSSP_STACKINIT_CANMSGID_ABORT) {
-                    aosDbgPrintf("abort msg\n");
-                    // reset the delay timer
-                    chVTReset(&timerDelay);
-                    chEvtWaitAnyTimeout(eventListenerDelay.events, TIME_IMMEDIATE);
-                    eventmask &= ~(eventListenerDelay.events);
-                    // proceed
-                    stage = STAGE_3_4_ABORT;
-                }
-            }
+      case STAGE_3_4_FINISH:
+      {
+        aos.sssp.stage = AOS_SSSP_STARTUP_3_4;
 
-            // if a delay timer event occurred
-            if (eventmask & eventListenerDelay.events) {
-                aosDbgPrintf("sequence sucessful\n");
-                // sequence finished sucessfully
-                flags.loop = false;
-            }
+        // if an IO event was received (S signal)
+        if ((eventmask & _eventListenerIO.events) && (ioflags & MODULE_SSSP_EVENTFLAGS_SYNC)) {
+          // reset the timeout timer
+          chVTReset(&timerTimeout);
+          chEvtWaitAnyTimeout(eventListenerTimeout.events, TIME_IMMEDIATE);
+          eventmask &= ~(eventListenerTimeout.events);
+          //set the delay timer
+          chVTSet(&timerDelay, chTimeUS2I(AOS_SYSTEM_SSSP_TIMEOUT), _ssspTimerCallback, &eventSourceDelay);
+        }
 
-            break;
-        } /* end of STAGE_3_4_FINISH */
-
-        case STAGE_3_4_ABORT_ACTIVE:
-        {
-            aos.sssp.stage = AOS_SSSP_STARTUP_3_4;
-
-            // emit abort message
-            canTxFrame.DLC = 0;
-            canTxFrame.SID = SSSP_STACKINIT_CANMSGID_ABORT;
-            canTransmitTimeout(&MODULE_HAL_CAN, CAN_ANY_MAILBOX, &canTxFrame, TIME_INFINITE);
-            aosDbgPrintf("CAN -> abort\n");
-            // clear timeout flag
-            eventmask &= ~(eventListenerTimeout.events);
-            // proceed immediately
+        // if a CAN event was received
+        if (eventmask & eventListenerCan.events) {
+          // if an abort message was received
+          if (canRxFrame.SID == SSSP_STACKINIT_CANMSGID_ABORT) {
+            aosDbgPrintf("abort msg\n");
+            // reset the delay timer
+            chVTReset(&timerDelay);
+            chEvtWaitAnyTimeout(eventListenerDelay.events, TIME_IMMEDIATE);
+            eventmask &= ~(eventListenerDelay.events);
+            // proceed
             stage = STAGE_3_4_ABORT;
-            flags.wfe_next = false;
-            break;
-        } /* end of STAGE_3_4_ABORT_ACTIVE */
-
-        case STAGE_3_4_ABORT:
-        {
-            aos.sssp.stage = AOS_SSSP_STARTUP_3_4;
-
-            // deactivate S
-            aosDbgPrintf("S-\n");
-            apalControlGpioSet(&moduleSsspGpioSync, APAL_GPIO_OFF);
-            // invalidate module ID
-            aos.sssp.moduleId = 0;
-
-            // if an IO event was received (S signal)
-            if ((eventmask & _eventListenerIO.events) && (ioflags & MODULE_SSSP_EVENTFLAGS_SYNC)) {
-                aosDbgPrintf("sequence aborted\n");
-                // exit the sequence
-                flags.loop = false;
-            }
-
-            break;
-        } /* end of STAGE_3_4_ABORT */
+          }
         }
 
-        // fetch pending CAN message (if any)
-        if ((eventmask & eventListenerCan.events) && (canReceiveTimeout(&MODULE_HAL_CAN, CAN_ANY_MAILBOX, &canRxFrame, TIME_IMMEDIATE) == MSG_OK)) {
-            aosDbgPrintf("CAN <- 0x%03X\n", canRxFrame.SID);
-            flags.wfe_next = false;
+        // if a delay timer event occurred
+        if (eventmask & eventListenerDelay.events) {
+          aosDbgPrintf("sequence sucessful\n");
+          // sequence finished sucessfully
+          flags.loop = false;
         }
 
-        // handle unhandled timeout events
-        if (eventmask & eventListenerTimeout.events) {
-            aosDbgPrintf("ERR: timeout evt\n");
-            // abort
-            flags.wfe_next = false;
-            stage = STAGE_3_4_ABORT_ACTIVE;
+        break;
+      } /* end of STAGE_3_4_FINISH */
+
+      case STAGE_3_4_ABORT_ACTIVE:
+      {
+        aos.sssp.stage = AOS_SSSP_STARTUP_3_4;
+
+        // emit abort message
+        canTxFrame.DLC = 0;
+        canTxFrame.SID = SSSP_STACKINIT_CANMSGID_ABORT;
+        canTransmitTimeout(&MODULE_HAL_CAN, CAN_ANY_MAILBOX, &canTxFrame, TIME_INFINITE);
+        aosDbgPrintf("CAN -> abort\n");
+        // clear timeout flag
+        eventmask &= ~(eventListenerTimeout.events);
+        // proceed immediately
+        stage = STAGE_3_4_ABORT;
+        flags.wfe_next = false;
+        break;
+      } /* end of STAGE_3_4_ABORT_ACTIVE */
+
+      case STAGE_3_4_ABORT:
+      {
+        aos.sssp.stage = AOS_SSSP_STARTUP_3_4;
+
+        // deactivate S
+        aosDbgPrintf("disabling SYNC\n");
+        apalControlGpioSet(&moduleSsspGpioSync, APAL_GPIO_OFF);
+        // invalidate module ID
+        aos.sssp.moduleId = 0;
+
+        // if an IO event was received (S signal)
+        if ((eventmask & _eventListenerIO.events) && (ioflags & MODULE_SSSP_EVENTFLAGS_SYNC)) {
+          aosDbgPrintf("sequence aborted\n");
+          // exit the sequence
+          flags.loop = false;
         }
 
-        // apply wfe value for next iteration
-        flags.wfe = flags.wfe_next;
-    } /* end of FSM loop */
-    aosDbgPrintf("\n");
+        break;
+      } /* end of STAGE_3_4_ABORT */
+    } /* end of switch(stage) */
 
-    // unregister all events (timeout, delay, CAN receive)
-    chEvtUnregister(&eventSourceTimeout, &eventListenerTimeout);
-    chEvtUnregister(&eventSourceDelay, &eventListenerDelay);
-    chEvtUnregister(&MODULE_HAL_CAN.rxfull_event, &eventListenerCan);
-    // clear any pending events (timeout, delay, CAN receive)
-    chEvtWaitAllTimeout(TIMEOUTEVENT_MASK | DELAYEVENT_MASK | CANEVENT_MASK, TIME_IMMEDIATE);
+    // fetch pending CAN message (if any)
+    if ((eventmask & eventListenerCan.events) && (canReceiveTimeout(&MODULE_HAL_CAN, CAN_ANY_MAILBOX, &canRxFrame, TIME_IMMEDIATE) == MSG_OK)) {
+      aosDbgPrintf("CAN <- 0x%03X\n", canRxFrame.SID);
+      flags.wfe_next = false;
+    }
+
+    // handle unhandled timeout events
+    if (eventmask & eventListenerTimeout.events) {
+      aosDbgPrintf("ERR: timeout evt\n");
+      // abort
+      flags.wfe_next = false;
+      stage = STAGE_3_4_ABORT_ACTIVE;
+    }
 
-    // reset all control signals
+    // apply wfe value for next iteration
+    flags.wfe = flags.wfe_next;
+  } /* end of FSM loop */
+
+  // unregister all events (timeout, delay, CAN receive)
+  chEvtUnregister(&eventSourceTimeout, &eventListenerTimeout);
+  chEvtUnregister(&eventSourceDelay, &eventListenerDelay);
+  chEvtUnregister(&MODULE_HAL_CAN.rxfull_event, &eventListenerCan);
+  // clear any pending events (timeout, delay, CAN receive)
+  chEvtWaitAllTimeout(TIMEOUTEVENT_MASK | DELAYEVENT_MASK | CANEVENT_MASK, TIME_IMMEDIATE);
+
+  // reset all control signals
 #if (AMIROOS_CFG_SSSP_STACK_END != true)
-    apalControlGpioSet(&moduleSsspGpioUp, APAL_GPIO_OFF);
+  aosDbgPrintf("disabling UP\n");
+  apalControlGpioSet(&moduleSsspGpioUp, APAL_GPIO_OFF);
 #endif
-    apalControlGpioSet(&moduleSsspGpioSync, APAL_GPIO_OFF);
+  aosDbgPrintf("disabling S\n");
+  apalControlGpioSet(&moduleSsspGpioSync, APAL_GPIO_OFF);
+  aosSysGetUptime(&uptime);
+  aosDbgPrintf("done\t%04ums\n", (uint32_t)(uptime / MICROSECONDS_PER_MILLISECOND));
 
-    return shutdown;
+  return shutdown;
 }
-#endif
+#endif /* AMIROOS_CFG_SSSP_ENABLE == true */
+
 /**
  * @brief   Application entry point.
  */
 int main(void)
 {
-    // local variables
-    eventmask_t eventmask = 0;
-    eventflags_t eventflags = 0;
-    aos_shutdown_t shutdown = AOS_SHUTDOWN_NONE;
+  // local variables
+  eventmask_t eventmask = 0;
+  eventflags_t eventflags = 0;
+  eventflags_t ioeventflagsmask = AMIROOS_CFG_MAIN_LOOP_IOEVENT_MASK;
+  aos_shutdown_t shutdown = AOS_SHUTDOWN_NONE;
 #if defined(AMIROOS_CFG_MAIN_EXTRA_THREAD_VARIABLES)
-    AMIROOS_CFG_MAIN_EXTRA_THREAD_VARIABLES
-        #endif
-
-            /*
-           * ##########################################################################
-           * # system initialization                                                  #
-           * ##########################################################################
-           */
-
-        #if defined(AMIROOS_CFG_MAIN_INIT_HOOK_0)
-        #if defined(AMIROOS_CFG_MAIN_INIT_HOOK_0_ARGS)
-            AMIROOS_CFG_MAIN_INIT_HOOK_0(AMIROOS_CFG_MAIN_INIT_HOOK_0_ARGS);
+  AMIROOS_CFG_MAIN_EXTRA_THREAD_VARIABLES
+#endif
+
+  /*
+   * ##########################################################################
+   * # system initialization                                                  #
+   * ##########################################################################
+   */
+
+#if defined(AMIROOS_CFG_MAIN_INIT_HOOK_0)
+#if defined(AMIROOS_CFG_MAIN_INIT_HOOK_0_ARGS)
+  AMIROOS_CFG_MAIN_INIT_HOOK_0(AMIROOS_CFG_MAIN_INIT_HOOK_0_ARGS);
 #else
-            AMIROOS_CFG_MAIN_INIT_HOOK_0();
+  AMIROOS_CFG_MAIN_INIT_HOOK_0();
 #endif
 #endif
 
-    /* hardware, kernel, and operating system initialization */
-    // ChibiOS/HAL and custom hal additions (if any)
-    halInit();
+  /* hardware, kernel, and operating system initialization */
+  // ChibiOS/HAL and custom hal additions (if any)
+  halInit();
 #ifdef MODULE_INIT_HAL_EXTRA
-    MODULE_INIT_HAL_EXTRA();
+  MODULE_INIT_HAL_EXTRA();
 #endif
 
 #if defined(AMIROOS_CFG_MAIN_INIT_HOOK_1)
 #if defined(AMIROOS_CFG_MAIN_INIT_HOOK_1_ARGS)
-    AMIROOS_CFG_MAIN_INIT_HOOK_1(AMIROOS_CFG_MAIN_INIT_HOOK_1_ARGS);
+  AMIROOS_CFG_MAIN_INIT_HOOK_1(AMIROOS_CFG_MAIN_INIT_HOOK_1_ARGS);
 #else
-    AMIROOS_CFG_MAIN_INIT_HOOK_1();
+  AMIROOS_CFG_MAIN_INIT_HOOK_1();
 #endif
 #endif
 
-    // ChibiOS/RT kernel and custom kernel additions (if any)
-    chSysInit();
+  // ChibiOS/RT kernel and custom kernel additions (if any)
+  chSysInit();
 #ifdef MODULE_INIT_KERNEL_EXTRA
-    MODULE_INIT_KERNEL_EXTRA();
+  MODULE_INIT_KERNEL_EXTRA();
 #endif
 
 #if defined(AMIROOS_CFG_MAIN_INIT_HOOK_2)
 #if defined(AMIROOS_CFG_MAIN_INIT_HOOK_2_ARGS)
-    AMIROOS_CFG_MAIN_INIT_HOOK_2(AMIROOS_CFG_MAIN_INIT_HOOK_2_ARGS);
+  AMIROOS_CFG_MAIN_INIT_HOOK_2(AMIROOS_CFG_MAIN_INIT_HOOK_2_ARGS);
 #else
-    AMIROOS_CFG_MAIN_INIT_HOOK_2();
+  AMIROOS_CFG_MAIN_INIT_HOOK_2();
 #endif
 #endif
 
-    // AMiRo-OS and custom OS additions (if any)
+  // AMiRo-OS and custom OS additions (if any)
 #if (AMIROOS_CFG_SHELL_ENABLE == true)
-    aosSysInit(moduleShellPrompt);
+  aosSysInit(moduleShellPrompt);
 #else
-    aosSysInit();
+  aosSysInit();
 #endif
 #ifdef MODULE_INIT_OS_EXTRA
-    MODULE_INIT_OS_EXTRA();
+  MODULE_INIT_OS_EXTRA();
 #endif
 
 #if defined(AMIROOS_CFG_MAIN_INIT_HOOK_3)
 #if defined(AMIROOS_CFG_MAIN_INIT_HOOK_3_ARGS)
-    AMIROOS_CFG_MAIN_INIT_HOOK_3(AMIROOS_CFG_MAIN_INIT_HOOK_3_ARGS);
+  AMIROOS_CFG_MAIN_INIT_HOOK_3(AMIROOS_CFG_MAIN_INIT_HOOK_3_ARGS);
 #else
-    AMIROOS_CFG_MAIN_INIT_HOOK_3();
+  AMIROOS_CFG_MAIN_INIT_HOOK_3();
 #endif
 #endif
 
 #if (AMIROOS_CFG_TESTS_ENABLE == true)
 #if defined(MODULE_INIT_TESTS)
-    MODULE_INIT_TESTS();
+  MODULE_INIT_TESTS();
 #else
-#warning "MODULE_INIT_TESTS not defined"
+  #warning "MODULE_INIT_TESTS() not defined"
 #endif
 #endif
 
 #if defined(AMIROOS_CFG_MAIN_INIT_HOOK_4)
 #if defined(AMIROOS_CFG_MAIN_INIT_HOOK_4_ARGS)
-    AMIROOS_CFG_MAIN_INIT_HOOK_4(AMIROOS_CFG_MAIN_INIT_HOOK_4_ARGS);
+  AMIROOS_CFG_MAIN_INIT_HOOK_4(AMIROOS_CFG_MAIN_INIT_HOOK_4_ARGS);
 #else
-    AMIROOS_CFG_MAIN_INIT_HOOK_4();
+  AMIROOS_CFG_MAIN_INIT_HOOK_4();
 #endif
 #endif
 
+  /* event associations */
 #if (AMIROOS_CFG_SSSP_ENABLE == true)
-    /* event associations */
-#if (AMIROOS_CFG_SSSP_STACK_START == true) && (AMIROOS_CFG_SSSP_STACK_END == true)
-    chEvtRegisterMaskWithFlags(&aos.events.io, &_eventListenerIO, IOEVENT_MASK, MODULE_SSSP_EVENTFLAGS_PD | MODULE_SSSP_EVENTFLAGS_SYNC);
-#elif (AMIROOS_CFG_SSSP_STACK_START == true)
-    chEvtRegisterMaskWithFlags(&aos.events.io, &_eventListenerIO, IOEVENT_MASK, MODULE_SSSP_EVENTFLAGS_PD | MODULE_SSSP_EVENTFLAGS_SYNC | MODULE_SSSP_EVENTFLAGS_UP);
-#elif (AMIROOS_CFG_SSSP_STACK_END == true)
-    chEvtRegisterMaskWithFlags(&aos.events.io, &_eventListenerIO, IOEVENT_MASK, MODULE_SSSP_EVENTFLAGS_PD | MODULE_SSSP_EVENTFLAGS_SYNC | MODULE_SSSP_EVENTFLAGS_DN);
-#else
-    chEvtRegisterMaskWithFlags(&aos.events.io, &_eventListenerIO, IOEVENT_MASK, MODULE_SSSP_EVENTFLAGS_PD | MODULE_SSSP_EVENTFLAGS_SYNC | MODULE_SSSP_EVENTFLAGS_DN | MODULE_SSSP_EVENTFLAGS_UP);
+  ioeventflagsmask |= MODULE_SSSP_EVENTFLAGS_PD | MODULE_SSSP_EVENTFLAGS_SYNC;
+#if (AMIROOS_CFG_SSSP_STACK_START != true)
+  ioeventflagsmask |= MODULE_SSSP_EVENTFLAGS_DN;
 #endif
-#endif // end of AMIROOS_CFG_SSSP_ENABLE condition
-    chEvtRegisterMask(&aos.events.os, &_eventListenerOS, OSEVENT_MASK);
+#if (AMIROOS_CFG_SSSP_STACK_END != true)
+  ioeventflagsmask |= MODULE_SSSP_EVENTFLAGS_UP;
+#endif
+#endif /* AMIROOS_CFG_SSSP_ENABLE == true */
+  if (ioeventflagsmask != 0) {
+    chEvtRegisterMaskWithFlags(&aos.events.io, &_eventListenerIO, IOEVENT_MASK, ioeventflagsmask);
+  }
+  chEvtRegisterMask(&aos.events.os, &_eventListenerOS, OSEVENT_MASK);
 
 #if defined(AMIROOS_CFG_MAIN_INIT_HOOK_5)
 #if defined(AMIROOS_CFG_MAIN_INIT_HOOK_5_ARGS)
-    AMIROOS_CFG_MAIN_INIT_HOOK_5(AMIROOS_CFG_MAIN_INIT_HOOK_5_ARGS);
+  AMIROOS_CFG_MAIN_INIT_HOOK_5(AMIROOS_CFG_MAIN_INIT_HOOK_5_ARGS);
 #else
-    AMIROOS_CFG_MAIN_INIT_HOOK_5();
+  AMIROOS_CFG_MAIN_INIT_HOOK_5();
 #endif
 #endif
 
-    /* periphery communication initialization */
-    // CAN (mandatory)
-    canStart(&MODULE_HAL_CAN, &moduleHalCanConfig);
-
-    // module specific initialization (if any)
+  /* periphery communication initialization */
+  // CAN (mandatory)
+  canStart(&MODULE_HAL_CAN, &moduleHalCanConfig);
+  // module specific initialization (if any)
 #ifdef MODULE_INIT_PERIPHERY_COMM
-    MODULE_INIT_PERIPHERY_COMM();
+  MODULE_INIT_PERIPHERY_COMM();
 #endif
-    // user interface (if any)
+  // user interface (if any)
 #ifdef MODULE_HAL_PROGIF
-    aosIOChannelInit(&_stdiochannel, (BaseAsynchronousChannel*)&MODULE_HAL_PROGIF);
-    aosIOChannelOutputEnable(&_stdiochannel);
-    aosIOStreamAddChannel(&aos.iostream, &_stdiochannel);
+  aosIOChannelInit(&_stdiochannel, (BaseAsynchronousChannel*)&MODULE_HAL_PROGIF);
+  aosIOChannelOutputEnable(&_stdiochannel);
+  aosIOStreamAddChannel(&aos.iostream, &_stdiochannel);
 #if (AMIROOS_CFG_SHELL_ENABLE == true)
-    aosShellChannelInit(&_stdshellchannel, (BaseAsynchronousChannel*)&MODULE_HAL_PROGIF);
-    aosShellChannelInputEnable(&_stdshellchannel);
-    aosShellChannelOutputEnable(&_stdshellchannel);
-    aosShellStreamAddChannel(&aos.shell.stream, &_stdshellchannel);
+  aosShellChannelInit(&_stdshellchannel, (BaseAsynchronousChannel*)&MODULE_HAL_PROGIF);
+  aosShellChannelInputEnable(&_stdshellchannel);
+  aosShellChannelOutputEnable(&_stdshellchannel);
+  aosShellStreamAddChannel(&aos.shell.stream, &_stdshellchannel);
 #endif
 #endif
 
 #if defined(AMIROOS_CFG_MAIN_INIT_HOOK_6)
 #if defined(AMIROOS_CFG_MAIN_INIT_HOOK_6_ARGS)
-    AMIROOS_CFG_MAIN_INIT_HOOK_6(AMIROOS_CFG_MAIN_INIT_HOOK_6_ARGS);
+  AMIROOS_CFG_MAIN_INIT_HOOK_6(AMIROOS_CFG_MAIN_INIT_HOOK_6_ARGS);
 #else
-    AMIROOS_CFG_MAIN_INIT_HOOK_6();
-#endif
-#endif
-    //  for (unsigned int hase = 0; hase < 10; ++hase) {
-    //      //toggle LED
-    //      palClearLine(LINE_LED_GREEN);
-    //      chThdSleepMilliseconds(1500);
-    //      palSetLine(LINE_LED_GREEN);
-    //      chThdSleepMilliseconds(500);
-    //  }
-    //  chprintf((BaseSequentialStream*)&SD2, "Hallo Welt!\n");
-
-    /* module is ready -> print welcome prompt */
-    aosprintf("\n");
-    aosprintf("######################################################################\n");
-    aosprintf("# AMiRo-OS is an operating system designed for the Autonomous Mini   #\n");
-    aosprintf("# Robot (AMiRo) platform.                                            #\n");
-    aosprintf("# Copyright (C) 2016..2018  Thomas Schöpping et al.                  #\n");
-    aosprintf("#                                                                    #\n");
-    aosprintf("# This is free software; see the source for copying conditions.      #\n");
-    aosprintf("# There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR  #\n");
-    aosprintf("# A PARTICULAR PURPOSE.                                              #\n");
-    aosprintf("# The development of this software was supported by the Excellence   #\n");
-    aosprintf("# Cluster EXC 227 Cognitive Interaction Technology. The Excellence   #\n");
-    aosprintf("# Cluster EXC 227 is a grant of the Deutsche Forschungsgemeinschaft  #\n");
-    aosprintf("# (DFG) in the context of the German Excellence Initiative.          #\n");
-    aosprintf("######################################################################\n");
-    aosprintf("\n");
+  AMIROOS_CFG_MAIN_INIT_HOOK_6();
+#endif
+#endif
+
+  /* module is ready -> print welcome prompt */
+  aosprintf("\n");
+  aosprintf("######################################################################\n");
+  aosprintf("# AMiRo-OS is an operating system designed for the Autonomous Mini   #\n");
+  aosprintf("# Robot (AMiRo) platform.                                            #\n");
+  aosprintf("# Copyright (C) 2016..2019  Thomas Schöpping et al.                  #\n");
+  aosprintf("#                                                                    #\n");
+  aosprintf("# This is free software; see the source for copying conditions.      #\n");
+  aosprintf("# There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR  #\n");
+  aosprintf("# A PARTICULAR PURPOSE.                                              #\n");
+  aosprintf("# The development of this software was supported by the Excellence   #\n");
+  aosprintf("# Cluster EXC 227 Cognitive Interaction Technology. The Excellence   #\n");
+  aosprintf("# Cluster EXC 227 is a grant of the Deutsche Forschungsgemeinschaft  #\n");
+  aosprintf("# (DFG) in the context of the German Excellence Initiative.          #\n");
+  aosprintf("######################################################################\n");
+  aosprintf("\n");
 
 #if defined(AMIROOS_CFG_MAIN_INIT_HOOK_7)
 #if defined(AMIROOS_CFG_MAIN_INIT_HOOK_7_ARGS)
-    AMIROOS_CFG_MAIN_INIT_HOOK_7(AMIROOS_CFG_MAIN_INIT_HOOK_7_ARGS);
+  AMIROOS_CFG_MAIN_INIT_HOOK_7(AMIROOS_CFG_MAIN_INIT_HOOK_7_ARGS);
 #else
-    AMIROOS_CFG_MAIN_INIT_HOOK_7();
-#endif //AMIROOS_CFG_MAIN_INIT_HOOK_7
-#endif //AMIROOS_CFG_MAIN_INIT_HOOK_7_ARGS
+  AMIROOS_CFG_MAIN_INIT_HOOK_7();
+#endif
+#endif
 
 #if (AMIROOS_CFG_SSSP_ENABLE == true)
-    /* SSSP startup OS synchronization phase (end of startup stage 2) */
-    while ((shutdown == AOS_SHUTDOWN_NONE) && (eventmask = aosSysSsspStartupOsInitSyncCheck(&_eventListenerIO)) != 0) {
-        /*
+  /* SSSP startup OS synchronization phase (end of startup stage 2) */
+  while ((shutdown == AOS_SHUTDOWN_NONE) && (eventmask = aosSysSsspStartupOsInitSyncCheck(&_eventListenerIO)) != 0) {
+    /*
      * This code is executed if the received event was not about the SYS_SYNC control signal.
      * The returned event could be caused by any listener (not only the argument).
      */
-        // IO event
-        if (eventmask & _eventListenerIO.events) {
-            eventflags = chEvtGetAndClearFlags(&_eventListenerIO);
-            // PD event
-            if (eventflags & MODULE_SSSP_EVENTFLAGS_PD) {
-                shutdown = AOS_SHUTDOWN_PASSIVE;
-            } else {
+    // IO event
+    if (eventmask & _eventListenerIO.events) {
+      eventflags = chEvtGetAndClearFlags(&_eventListenerIO);
+      // PD event
+      if (eventflags & MODULE_SSSP_EVENTFLAGS_PD) {
+        shutdown = AOS_SHUTDOWN_PASSIVE;
+      } else {
 #ifdef MODULE_SSSP_STARTUP_2_2_IOEVENT_HOOK
-                MODULE_SSSP_STARTUP_2_2_IOEVENT_HOOK(eventmask, eventflags);
+        MODULE_SSSP_STARTUP_2_2_IOEVENT_HOOK(eventmask, eventflags);
 #else
-                // ignore any other IO events
+        // ignore any other IO events
 #endif
-
-            }
-
-        }
-        // OS event
-        else if (eventmask & _eventListenerOS.events) {
-            eventflags = chEvtGetAndClearFlags(&_eventListenerOS);
-            _unexpectedEventError(eventmask, eventflags);
-        }
-        // unknown event
-        else {
-            _unexpectedEventError(eventmask, 0);
-        }
+      }
     }
-#endif //AMIROOS_CFG_SSSP_ENABLE
-    /*
+    // OS event
+    else if (eventmask & _eventListenerOS.events) {
+      eventflags = chEvtGetAndClearFlags(&_eventListenerOS);
+      _unexpectedEventError(eventmask, eventflags);
+    }
+    // unknown event
+    else {
+      _unexpectedEventError(eventmask, 0);
+    }
+  }
+
+  /*
    * There must be no delays at this point, thus no hook is allowed.
    */
 
-#if (AMIROOS_CFG_SSSP_ENABLE == true)
-    /* SSSP startup stage 3 (module stack initialization) */
-    if (shutdown == AOS_SHUTDOWN_NONE) {
-        shutdown = _ssspModuleStackInitialization();
-    }
-#endif //AMIROOS_CFG_SSSP_ENABLE
+  /* SSSP startup stage 3 (module stack initialization) */
+  if (shutdown == AOS_SHUTDOWN_NONE) {
+    shutdown = _ssspModuleStackInitialization();
+  }
+#endif /* AMIROOS_CFG_SSSP_ENABLE == true */
 
-    /*
+  /*
    * There must be no delays at this point, thus no hook is allowed.
    */
+
 #if (AMIROOS_CFG_SSSP_ENABLE == true)
-    /* synchronize calendars */
-    if (shutdown == AOS_SHUTDOWN_NONE) {
+  /* synchronize calendars */
+  if (shutdown == AOS_SHUTDOWN_NONE) {
 #if (AMIROOS_CFG_SSSP_MASTER == true)
-        CANTxFrame frame;
-        struct tm t;
-        uint64_t encoded;
-
-        frame.DLC = 8;
-        frame.RTR = CAN_RTR_DATA;
-        frame.IDE = CAN_IDE_STD;
-        frame.SID = CALENDERSYNC_CANMSGID;
-
-        aosDbgPrintf("transmitting current date/time...\t");
-        // get current date & time
-        aosSysGetDateTime(&t);
-        // encode
-        encoded = _TM2U64(&t);
-        // serialize
-        _serialize(frame.data8, encoded, 8);
-        // transmit
-        canTransmitTimeout(&MODULE_HAL_CAN, CAN_ANY_MAILBOX, &frame, TIME_IMMEDIATE);
-
-        aosDbgPrintf("done\n");
+    CANTxFrame frame;
+    struct tm t;
+    uint64_t encoded;
+
+    frame.DLC = 8;
+    frame.RTR = CAN_RTR_DATA;
+    frame.IDE = CAN_IDE_STD;
+    frame.SID = CALENDERSYNC_CANMSGID;
+
+    aosDbgPrintf("transmitting current date/time...\t");
+    // get current date & time
+    aosSysGetDateTime(&t);
+    // encode
+    encoded = _TM2U64(&t);
+    // serialize
+    _serialize(frame.data8, encoded, 8);
+    // transmit
+    canTransmitTimeout(&MODULE_HAL_CAN, CAN_ANY_MAILBOX, &frame, TIME_IMMEDIATE);
+
+    aosDbgPrintf("done\n");
+#else /* AMIROOS_CFG_SSSP_MASTER == false */
+    CANRxFrame frame;
+    uint64_t encoded;
+    struct tm t;
+
+    aosDbgPrintf("receiving current date/time...\t");
+    // receive message
+#if (AMIROOS_CFG_DBG == true)
+    // increase timeout in debug mode due to additional delays introduced by the many prinf() calls
+    if (canReceiveTimeout(&MODULE_HAL_CAN, CAN_ANY_MAILBOX, &frame, chTimeUS2I(10 * AOS_SYSTEM_SSSP_TIMEOUT)) == MSG_OK) {
 #else
-        CANRxFrame frame;
-        uint64_t encoded;
-        struct tm t;
-
-        aosDbgPrintf("receiving current date/time...\t");
-        // receive message
-        if (canReceiveTimeout(&MODULE_HAL_CAN, CAN_ANY_MAILBOX, &frame, chTimeUS2I(AOS_SYSTEM_SSSP_TIMEOUT)) == MSG_OK) {
-            // validate message
-            if (frame.DLC == 8 &&
-                    frame.RTR == CAN_RTR_DATA &&
-                    frame.IDE == CAN_IDE_STD &&
-                    frame.SID == CALENDERSYNC_CANMSGID) {
-                // deserialize
-                encoded = _deserialize(frame.data8, 8);
-                // decode
-                _U642TM(&t, encoded);
-                // set current date & time
-                aosSysSetDateTime(&t);
-                aosDbgPrintf("success\n");
-            } else {
-                aosDbgPrintf("fail (invalid message)\n");
-            }
-        } else {
-            aosDbgPrintf("fail (timeout)\n");
-        }
-#endif //AMIROOS_CFG_SSSP_MASTER
-        aosDbgPrintf("\n");
+    if (canReceiveTimeout(&MODULE_HAL_CAN, CAN_ANY_MAILBOX, &frame, chTimeUS2I(AOS_SYSTEM_SSSP_TIMEOUT)) == MSG_OK) {
+#endif
+      // validate message
+      if (frame.DLC == 8 &&
+          frame.RTR == CAN_RTR_DATA &&
+          frame.IDE == CAN_IDE_STD &&
+          frame.SID == CALENDERSYNC_CANMSGID) {
+        // deserialize
+        encoded = _deserialize(frame.data8, 8);
+        // decode
+        _U642TM(&t, encoded);
+        // set current date & time
+        aosSysSetDateTime(&t);
+        aosDbgPrintf("success\n");
+      } else {
+        aosDbgPrintf("fail (invalid message)\n");
+      }
+    } else {
+      aosDbgPrintf("fail (timeout)\n");
     }
-#endif //AMIROOS_CFG_SSSP_ENABLE
-aosprintf("Line 1123\n");
-#if defined(AMIROOS_CFG_MAIN_INIT_HOOK_8)
+#endif /* AMIROOS_CFG_SSSP_MASTER == false */
+    aosDbgPrintf("\n");
+  }
+#endif /* AMIROOS_CFG_SSSP_ENABLE == true */
 
+#if defined(AMIROOS_CFG_MAIN_INIT_HOOK_8)
 #if defined(AMIROOS_CFG_MAIN_INIT_HOOK_8_ARGS)
-    AMIROOS_CFG_MAIN_INIT_HOOK_8(AMIROOS_CFG_MAIN_INIT_HOOK_8_ARGS);
+  AMIROOS_CFG_MAIN_INIT_HOOK_8(AMIROOS_CFG_MAIN_INIT_HOOK_8_ARGS);
 #else
-    AMIROOS_CFG_MAIN_INIT_HOOK_8();
-#endif //AMIROOS_CFG_MAIN_INIT_HOOK_8_ARGS
+  AMIROOS_CFG_MAIN_INIT_HOOK_8();
+#endif
 #endif
 
-
-
-    aosprintf("aosSysStart \n");
-    /* completely start AMiRo-OS */
-    if (shutdown == AOS_SHUTDOWN_NONE) {
-        aosSysStart();
-    }
-    aosprintf("aosSysStart done \n");
+  /* completely start AMiRo-OS */
+  if (shutdown == AOS_SHUTDOWN_NONE) {
+    aosSysStart();
+  }
 
 #if defined(AMIROOS_CFG_MAIN_INIT_HOOK_9)
 #if defined(AMIROOS_CFG_MAIN_INIT_HOOK_9_ARGS)
-    AMIROOS_CFG_MAIN_INIT_HOOK_9(AMIROOS_CFG_MAIN_INIT_HOOK_9_ARGS);
+  AMIROOS_CFG_MAIN_INIT_HOOK_9(AMIROOS_CFG_MAIN_INIT_HOOK_9_ARGS);
 #else
-    AMIROOS_CFG_MAIN_INIT_HOOK_9();
+  AMIROOS_CFG_MAIN_INIT_HOOK_9();
 #endif
 #endif
 
-    /*
+  /*
    * ##########################################################################
    * # infinite loop                                                          #
    * ##########################################################################
    */
 
-    // sleep until a shutdown event is received
-    while (shutdown == AOS_SHUTDOWN_NONE) {
-        // wait for an event
+  // sleep until a shutdown event is received
+  while (shutdown == AOS_SHUTDOWN_NONE) {
+    // wait for an event
 #if (AMIROOS_CFG_MAIN_LOOP_TIMEOUT != 0)
-        eventmask = chEvtWaitOneTimeout(ALL_EVENTS, chTimeUS2I(AMIROOS_CFG_MAIN_LOOP_TIMEOUT));
+    eventmask = chEvtWaitOneTimeout(ALL_EVENTS, chTimeUS2I(AMIROOS_CFG_MAIN_LOOP_TIMEOUT));
 #else
-        eventmask = chEvtWaitOne(ALL_EVENTS);
+    eventmask = chEvtWaitOne(ALL_EVENTS);
 #endif
 
 #if defined(AMIROOS_CFG_MAIN_LOOP_HOOK_0)
 #if defined(AMIROOS_CFG_MAIN_LOOP_HOOK_0_ARGS)
-        AMIROOS_CFG_MAIN_LOOP_HOOK_0(AMIROOS_CFG_MAIN_LOOP_HOOK_0_ARGS);
+    AMIROOS_CFG_MAIN_LOOP_HOOK_0(AMIROOS_CFG_MAIN_LOOP_HOOK_0_ARGS);
 #else
-        AMIROOS_CFG_MAIN_LOOP_HOOK_0();
+    AMIROOS_CFG_MAIN_LOOP_HOOK_0();
 #endif
 #endif
 
-
-        switch (eventmask) {
-        // if this was an I/O event
-        case IOEVENT_MASK:
-            // evaluate flags
-            eventflags = chEvtGetAndClearFlags(&_eventListenerIO);
-            // PD event
+    switch (eventmask) {
+      // if this was an I/O event
+      case IOEVENT_MASK:
+        // evaluate flags
+        eventflags = chEvtGetAndClearFlags(&_eventListenerIO);
 #if (AMIROOS_CFG_SSSP_ENABLE == true)
-            if (eventflags & MODULE_SSSP_EVENTFLAGS_PD) {
-                shutdown = AOS_SHUTDOWN_PASSIVE;
-            }
+        // PD event
+        if (eventflags & MODULE_SSSP_EVENTFLAGS_PD) {
+          shutdown = AOS_SHUTDOWN_PASSIVE;
+        }
+        // all other events
+#ifdef MODULE_MAIN_LOOP_IO_EVENT
+        else {
+          MODULE_MAIN_LOOP_IO_EVENT(eventflags);
+        }
 #endif
-            // all other events
+#else /* AMIROOS_CFG_SSSP_ENABLE == false */
 #ifdef MODULE_MAIN_LOOP_IO_EVENT
-            else {
-                MODULE_MAIN_LOOP_IO_EVENT(eventmask, eventflags);
-            }
+        MODULE_MAIN_LOOP_IO_EVENT(eventflags);
 #endif
-            break;
+#endif /* AMIROOS_CFG_SSSP_ENABLE */
+        break;
 
-            // if this was an OS event
-        case OSEVENT_MASK:
-            // evaluate flags
-            eventflags = chEvtGetAndClearFlags(&_eventListenerOS);
-            switch (eventflags) {
-            case AOS_SYSTEM_EVENTFLAGS_HIBERNATE:
-                shutdown = AOS_SHUTDOWN_HIBERNATE;
-                break;
-            case AOS_SYSTEM_EVENTFLAGS_DEEPSLEEP:
-                shutdown = AOS_SHUTDOWN_DEEPSLEEP;
-                break;
-            case AOS_SYSTEM_EVENTFLAGS_TRANSPORTATION:
-                shutdown = AOS_SHUTDOWN_TRANSPORTATION;
-                break;
-            case AOS_SYSTEM_EVENTFLAGS_RESTART:
-                shutdown = AOS_SHUTDOWN_RESTART;
-                break;
-            default:
-                _unexpectedEventError(eventmask, eventflags);
-                break;
-            }
+      // if this was an OS event
+      case OSEVENT_MASK:
+        // evaluate flags
+        eventflags = chEvtGetAndClearFlags(&_eventListenerOS);
+        switch (eventflags) {
+#if (AMIROOS_CFG_SSSP_ENABLE == true)
+          case AOS_SYSTEM_EVENTFLAGS_HIBERNATE:
+            shutdown = AOS_SHUTDOWN_HIBERNATE;
             break;
-
-            // if this was any other event (should be impossible to occur)
-        default:
-            eventflags = 0;
+          case AOS_SYSTEM_EVENTFLAGS_DEEPSLEEP:
+            shutdown = AOS_SHUTDOWN_DEEPSLEEP;
+            break;
+          case AOS_SYSTEM_EVENTFLAGS_TRANSPORTATION:
+            shutdown = AOS_SHUTDOWN_TRANSPORTATION;
+            break;
+          case AOS_SYSTEM_EVENTFLAGS_RESTART:
+            shutdown = AOS_SHUTDOWN_RESTART;
+            break;
+#else /* AMIROOS_CFG_SSSP_ENABLE == false */
+          case AOS_SYSTEM_EVENTFLAGS_SHUTDOWN:
+            shutdown = AOS_SHUTDOWN_DEFAULT;
+            break;
+#endif /* AMIROOS_CFG_SSSP_ENABLE */
+          default:
             _unexpectedEventError(eventmask, eventflags);
             break;
         }
+        break;
+
+      // if this was any other event (should be impossible to occur)
+      default:
+        eventflags = 0;
+#if (AMIROOS_CFG_MAIN_LOOP_TIMEOUT == 0)
+        _unexpectedEventError(eventmask, eventflags);
+#endif
+        break;
+    }
 
 #if defined(AMIROOS_CFG_MAIN_LOOP_HOOK_1)
 #if defined(AMIROOS_CFG_MAIN_LOOP_HOOK_1_ARGS)
-        AMIROOS_CFG_MAIN_LOOP_HOOK_1(AMIROOS_CFG_MAIN_LOOP_HOOK_1_ARGS);
+    AMIROOS_CFG_MAIN_LOOP_HOOK_1(AMIROOS_CFG_MAIN_LOOP_HOOK_1_ARGS);
 #else
-        AMIROOS_CFG_MAIN_LOOP_HOOK_1();
+    AMIROOS_CFG_MAIN_LOOP_HOOK_1();
 #endif
 #endif
+  }
 
-    }
-//#endif //DEBUG
-    aosprintf("Line 1224\n");
-    /*
+  /*
    * ##########################################################################
    * # system shutdown                                                        #
    * ##########################################################################
@@ -1245,8 +1265,8 @@ aosprintf("Line 1123\n");
 #endif
 #endif
 
-    // initialize/acknowledge shutdown
-    aosSysShutdownInit(shutdown);
+  // initialize/acknowledge shutdown
+  aosSysShutdownInit(shutdown);
 
 #if defined(AMIROOS_CFG_MAIN_SHUTDOWN_HOOK_1)
 #if defined(AMIROOS_CFG_MAIN_SHUTDOWN_HOOK_1_ARGS)
@@ -1256,8 +1276,8 @@ aosprintf("Line 1123\n");
 #endif
 #endif
 
-    // stop system threads
-    aosSysStop();
+  // stop system threads
+  aosSysStop();
 
 #if defined(AMIROOS_CFG_MAIN_SHUTDOWN_HOOK_2)
 #if defined(AMIROOS_CFG_MAIN_SHUTDOWN_HOOK_2_ARGS)
@@ -1267,8 +1287,8 @@ aosprintf("Line 1123\n");
 #endif
 #endif
 
-    // deinitialize system
-    aosSysDeinit();
+  // deinitialize system
+  aosSysDeinit();
 
 #if defined(AMIROOS_CFG_MAIN_SHUTDOWN_HOOK_3)
 #if defined(AMIROOS_CFG_MAIN_SHUTDOWN_HOOK_3_ARGS)
@@ -1278,11 +1298,11 @@ aosprintf("Line 1123\n");
 #endif
 #endif
 
-    /* stop all periphery communication */
-    // CAN (mandatory)
-    canStop(&MODULE_HAL_CAN);
+  /* stop all periphery communication */
+  // CAN (mandatory)
+  canStop(&MODULE_HAL_CAN);
 #ifdef MODULE_SHUTDOWN_PERIPHERY_COMM
-    MODULE_SHUTDOWN_PERIPHERY_COMM();
+  MODULE_SHUTDOWN_PERIPHERY_COMM();
 #endif
 
 #if defined(AMIROOS_CFG_MAIN_SHUTDOWN_HOOK_4)
@@ -1293,10 +1313,10 @@ aosprintf("Line 1123\n");
 #endif
 #endif
 
-    // finally hand over to bootloader
-    aosSysShutdownFinal(shutdown);
+  // finally hand over to bootloader
+  aosSysShutdownFinal(shutdown);
 
-    /*
+  /*
    * ##########################################################################
    * # after shutdown/restart                                                 #
    * ##########################################################################
@@ -1306,8 +1326,8 @@ aosprintf("Line 1123\n");
    *       which subsystems should NOT be shut down.
    */
 
-    // return an error, since this code should not be executed
-    return -1;
+  // return an error, since this code should not be executed
+  return -1;
 }
 
 /** @} */
