commit cda1472944648652764c6980f5ee3f3e91459ef3
Author: Thomas Schöpping <tschoepp@cit-ec.uni-bielefeld.de>
Date:   Mon Oct 28 11:15:03 2019 +0100

    Major SSSP overhaul:
    - SSSP no works even without Bootloader (AMiRo-OS implements startup and shutdown phases)
    - MSI and calendar synchronization are currently not available (WIP)
    - lots of minor changes

diff --git a/core/inc/aos_system.h b/core/inc/aos_system.h
index 890a91a..e2d77b6 100644
--- a/core/inc/aos_system.h
+++ b/core/inc/aos_system.h
@@ -40,49 +40,34 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #define AOS_SYSTEM_TIME_RESOLUTION              ((MICROSECONDS_PER_SECOND + CH_CFG_ST_FREQUENCY - 1) / CH_CFG_ST_FREQUENCY)
 
 /**
- * @brief   System event flag which is emitted when a shutdown was initiated.
+ * @brief   System event flag mask for shutdown related events.
  */
-#define AOS_SYSTEM_EVENTFLAGS_SHUTDOWN          (eventflags_t)(1 << 0)
+#define AOS_SYSTEM_EVENTFLAGS_SHUTDOWN_MASK     ((eventflags_t)0x1F)
+
+/**
+ * @brief   System event flag which is emitted when a passive shutdown was initiated.
+ */
+#define AOS_SYSTEM_EVENTFLAGS_SHUTDOWN_PASSIVE  ((eventflags_t)(1 << 0))
 
 /**
  * @brief   System event flag which is emitted when a shutdown to transportation mode was initiated.
  */
-#define AOS_SYSTEM_EVENTFLAGS_TRANSPORTATION    (AOS_SYSTEM_EVENTFLAGS_SHUTDOWN | (eventflags_t)(1 << 1))
+#define AOS_SYSTEM_EVENTFLAGS_SHUTDOWN_TRANSPORTATION ((eventflags_t)(1 << 1))
 
 /**
  * @brief   System event flag which is emitted when a shutdown to deepsleep mode was initiated.
  */
-#define AOS_SYSTEM_EVENTFLAGS_DEEPSLEEP         (AOS_SYSTEM_EVENTFLAGS_SHUTDOWN | (eventflags_t)(1 << 2))
+#define AOS_SYSTEM_EVENTFLAGS_SHUTDOWN_DEEPSLEEP ((eventflags_t)(1 << 2))
 
 /**
  * @brief   System event flag which is emitted when a shutdown to hibernate mode was initiated.
  */
-#define AOS_SYSTEM_EVENTFLAGS_HIBERNATE         (AOS_SYSTEM_EVENTFLAGS_SHUTDOWN | (eventflags_t)(1 << 3))
+#define AOS_SYSTEM_EVENTFLAGS_SHUTDOWN_HIBERNATE ((eventflags_t)(1 << 3))
 
 /**
  * @brief   System event flag which is emitted when a system restart was initiated.
  */
-#define AOS_SYSTEM_EVENTFLAGS_RESTART           (AOS_SYSTEM_EVENTFLAGS_SHUTDOWN | (eventflags_t)(1 << 4))
-
-#if (AMIROOS_CFG_SSSP_ENABLE == true) || defined(__DOXYGEN__)
-
-/**
- * @brief   Major version of the implemented SSSP.
- */
-#define AOS_SYSTEM_SSSP_VERSION_MAJOR           1
-
-/**
- * @brief   Minor version of the implemented SSSP.
- */
-#define AOS_SYSTEM_SSSP_VERSION_MINOR           4
-
-/**
- * @brief   Timeout delay according to SSSP.
- * @details SSSP defines timeouts to be ten times longer than the signal delay time.
- */
-#define AOS_SYSTEM_SSSP_TIMEOUT                 (10 * AMIROOS_CFG_SSSP_SIGNALDELAY)
-
-#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */
+#define AOS_SYSTEM_EVENTFLAGS_SHUTDOWN_RESTART ((eventflags_t)(1 << 4))
 
 /******************************************************************************/
 /* SETTINGS                                                                   */
@@ -101,66 +86,24 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 typedef enum aos_shutdown {
   AOS_SHUTDOWN_NONE,            /**< Default value if no shutdown action was initiated */
+#if (AMIROOS_CFG_SSSP_ENABLE == true) || defined(__DOXYGEN__)
   AOS_SHUTDOWN_PASSIVE,         /**< Passive shutdown (initiated by another module). */
+#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */
+#if (AMIROOS_CFG_BOOTLOADER == AOS_BOOTLOADER_NONE) || defined (__DOXYGEN__)
+  AOS_SHUTDOWN_ACTIVE,          /**< Active shutdown. */
+#endif /* (AMIROOS_CFG_BOOTLOADER == AOS_BOOTLOADER_NONE) */
+#if (AMIROOS_CFG_BOOTLOADER == AOS_BOOTLOADER_AMiRoBLT) || defined (__DOXYGEN__)
   AOS_SHUTDOWN_HIBERNATE,       /**< Active shutdown to hibernate mode. */
   AOS_SHUTDOWN_DEEPSLEEP,       /**< Active shutdown to deepsleep mode. */
   AOS_SHUTDOWN_TRANSPORTATION,  /**< Active shutdown to transportation mode. */
   AOS_SHUTDOWN_RESTART,         /**< Active saystem restart request. */
+#endif /* (AMIROOS_CFG_BOOTLOADER == AOS_BOOTLOADER_AMiRoBLT) */
 } aos_shutdown_t;
 
-#if (AMIROOS_CFG_SSSP_ENABLE == true) || defined(__DOXYGEN__)
-
-/**
- * @brief   Enumerator of the several stages of SSSP.
- */
-typedef enum aos_ssspstage {
-  AOS_SSSP_STARTUP_1_1  = 0x10, /**< Identifier of SSSP startup phase stage 1-1. */
-  AOS_SSSP_STARTUP_1_2  = 0x11, /**< Identifier of SSSP startup phase stage 1-2. */
-  AOS_SSSP_STARTUP_1_3  = 0x12, /**< Identifier of SSSP startup phase stage 1-3. */
-  AOS_SSSP_STARTUP_2_1  = 0x14, /**< Identifier of SSSP startup phase stage 2-1. */
-  AOS_SSSP_STARTUP_2_2  = 0x15, /**< Identifier of SSSP startup phase stage 2-2. */
-  AOS_SSSP_STARTUP_3_1  = 0x18, /**< Identifier of SSSP startup phase stage 3-1. */
-  AOS_SSSP_STARTUP_3_2  = 0x19, /**< Identifier of SSSP startup phase stage 3-2. */
-  AOS_SSSP_STARTUP_3_3  = 0x1A, /**< Identifier of SSSP startup phase stage 3-3. */
-  AOS_SSSP_STARTUP_3_4  = 0x1B, /**< Identifier of SSSP startup phase stage 3-4. */
-  AOS_SSSP_OPERATION    = 0x20, /**< Identifier of SSSP operation pahse. */
-  AOS_SSSP_SHUTDOWN_1_1 = 0x30, /**< Identifier of SSSP shutdown phase stage 1-1. */
-  AOS_SSSP_SHUTDOWN_1_2 = 0x31, /**< Identifier of SSSP shutdown phase stage 1-2. */
-  AOS_SSSP_SHUTDOWN_1_3 = 0x32, /**< Identifier of SSSP shutdown phase stage 1-3. */
-  AOS_SSSP_SHUTDOWN_2_1 = 0x34, /**< Identifier of SSSP shutdown phase stage 2-1. */
-  AOS_SSSP_SHUTDOWN_2_2 = 0x35, /**< Identifier of SSSP shutdown phase stage 2-2. */
-  AOS_SSSP_SHUTDOWN_3   = 0x38, /**< Identifier of SSSP shutdown phase stage 3. */
-} aos_ssspstage_t;
-
-/**
- * @brief   Type to represent module IDs.
- */
-typedef uint16_t aos_ssspmoduleid_t;
-
-#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */
-
 /**
  * @brief   AMiRo-OS base system structure.
  */
 typedef struct aos_system {
-#if (AMIROOS_CFG_SSSP_ENABLE == true) || defined(__DOXYGEN__)
-  /**
-   * @brief   SSSP relevant data.
-   */
-  struct {
-    /**
-     * @brief   Current SSSP stage of the system.
-     */
-    aos_ssspstage_t stage;
-
-    /**
-     * @brief   Module identifier.
-     * @details A value of 0 indicates an uninitialized ID.
-     *          The vlaues 0 and ~0 are reserved und must not be set.
-     */
-    aos_ssspmoduleid_t moduleId;
-  } sssp;
-#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */
 
   /**
    * @brief   System I/O stream.
@@ -173,9 +116,9 @@ typedef struct aos_system {
   struct {
 
     /**
-     * @brief   I/O event source.
+     * @brief   GPIO event source.
      */
-    event_source_t io;
+    event_source_t gpio;
 
     /**
      * @brief   OS event source.
@@ -183,14 +126,23 @@ typedef struct aos_system {
     event_source_t os;
   } events;
 
-#if (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
+#if (AMIROOS_CFG_SHELL_ENABLE == true) || defined(__DOXYGEN__)
 
   /**
    * @brief   Pointer to the shell object.
    */
   aos_shell_t shell;
 
-#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) */
+#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) */
+
+#if (AMIROOS_CFG_SSSP_ENABLE == true) || defined(__DOXYGEN__)
+
+  /**
+   * @brief   SSSP relevant data.
+   */
+  aos_ssspdata_t sssp;
+
+#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */
 
 } aos_system_t;
 
@@ -217,25 +169,29 @@ extern aos_system_t aos;
 #if defined(__cplusplus)
 extern "C" {
 #endif /* defined(__cplusplus) */
-#if (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true)
+#if (AMIROOS_CFG_SHELL_ENABLE == true) || defined(__DOXYGEN__)
   void aosSysInit(const char* shellPrompt);
-#else /* (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) */
+#else /* (AMIROOS_CFG_SHELL_ENABLE == true) */
   void aosSysInit(void);
-#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) */
+#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) */
   void aosSysStart(void);
 #if (AMIROOS_CFG_SSSP_ENABLE == true) || defined (__DOXYGEN__)
-  eventmask_t aosSysSsspStartupOsInitSyncCheck(event_listener_t* syncEvtListener);
+  void aosSysStartUptime(void);
 #endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */
   void aosSysGetUptimeX(aos_timestamp_t* ut);
-#if (HAL_USE_RTC == TRUE)
+#if (HAL_USE_RTC == TRUE) || defined(__DOXYGEN__)
   void aosSysGetDateTime(struct tm* dt);
   void aosSysSetDateTime(struct tm* dt);
 #endif /* (HAL_USE_RTC == TRUE) */
   void aosSysShutdownInit(aos_shutdown_t shutdown);
   void aosSysStop(void);
   void aosSysDeinit(void);
-  void aosSysShutdownFinal(aos_shutdown_t shutdown);
-  palcallback_t aosSysGetStdExtiCallback(void);
+#if ((AMIROOS_CFG_SSSP_ENABLE == true) && (AMIROOS_CFG_SSSP_SHUTDOWN != true)) ||               \
+    ((AMIROOS_CFG_SSSP_ENABLE != true) && (AMIROOS_CFG_BOOTLOADER == AOS_BOOTLOADER_AMiRoBLT)) || \
+    defined(__DOXYGEN__)
+  void aosSysShutdownToBootloader(aos_shutdown_t shutdown);
+#endif /* ((AMIROOS_CFG_SSSP_ENABLE == true) && (AMIROOS_CFG_SSSP_SHUTDOWN != true)) || ((AMIROOS_CFG_SSSP_ENABLE != true) && (AMIROOS_CFG_BOOTLOADER == AOS_BOOTLOADER_AMiRoBLT)) */
+  palcallback_t aosSysGetStdGpioCallback(void);
 #if defined(__cplusplus)
 }
 #endif /* defined(__cplusplus) */
