]> rtime.felk.cvut.cz Git - arc.git/blobdiff - system/EcuM/EcuM.c
EcuM: More EcuM fixes.
[arc.git] / system / EcuM / EcuM.c
index 634f9469eb2c80f8a41e40f204b65c1715b5fa31..d2c009accdac43edcd4295d0ae4e123d3d5a38b2 100644 (file)
  * for more details.\r
  * -------------------------------- Arctic Core ------------------------------*/\r
 \r
+\r
+/** @reqSettings DEFAULT_SPECIFICATION_REVISION=3.1.5 */\r
+\r
+/* ----------------------------[information]----------------------------------*/\r
+/*\r
+ * Author: ?+mahi\r
+ *\r
+ * Part of Release:\r
+ *   3.1.5\r
+ *\r
+ * Description:\r
+ *   Implements the Can Driver module\r
+ *\r
+ * Support:\r
+ *   General                  Have Support\r
+ *   -------------------------------------------\r
+ *   ECUM_TTII_ENABLED                         N\r
+ *   ECUM_DEV_ERROR_DETECT                             Y\r
+ *   ECUM_VERSION_INFO_API                             Y\r
+ *   ECUM_INCLUDE_DEM                                  N (controlled by USE_x macro's instead)\r
+ *   ECUM_INCLUDE_NVRAM_MGR                            N (controlled by USE_x macro's instead)\r
+ *   ECUM_INLCUDE_DET                                  N (controlled by USE_x macro's instead)\r
+ *   ECUM_MAIN_FUNCTION_PERDIOD                        Y\r
+ *   ECUM_TTII_WKSOURCE                                        N\r
+ *\r
+ *   Configuration            Have Support\r
+ *   -------------------------------------------\r
+ *   ECUM_SLEEP_ACTIVITY_PERIOD                        ?\r
+ *   ECUM_CONFIGCONSISTENCY_HASH               N\r
+ *   ECUM_RUN_SELF_REQUEST_PERIOD              ?\r
+ *   ECUM_NVRAM_WRITEALL_TIMEOUT               Y\r
+ *   ECUM_DEFAULT_APP_MODE                             ?\r
+ *\r
+ *\r
+ *   DefaultShutdownTarget\r
+ *   -------------------------------------------\r
+ *   ECUM_DEFAULT_SHUTDOWN_TARGET              N\r
+ *\r
+ *\r
+ * Things to start with:\r
+ * - EcuM2181\r
+ * - EcuM2861 , Watchdog\r
+ * - ComM_EcuM_RunModeIndication()  not called, See Figure 8 (Seems that the ComM does not do much either)\r
+ *\r
+ *\r
+ *\r
+ */\r
+\r
 //lint -emacro(904,VALIDATE,VALIDATE_RV,VALIDATE_NO_RV) //904 PC-Lint exception to MISRA 14.7 (validate macros).\r
 \r
+\r
+/* ----------------------------[includes]------------------------------------*/\r
+\r
+#include "Std_Types.h"\r
 #include "EcuM.h"\r
 #include "Modules.h"\r
 #include <string.h>\r
 #include <Os.h>\r
-#include "isr.h"\r
+#include "EcuM_Generated_Types.h"\r
 #include "EcuM_Internals.h"\r
 #include "EcuM_Cbk.h"\r
+#include "SchM_EcuM.h"\r
+#include "MemMap.h"\r
 #include "Mcu.h"\r
+#include "ComStack_Types.h"\r
+#if defined(USE_DET)\r
 #include "Det.h"\r
+#endif\r
 #include "isr.h"\r
 #if defined(USE_NVM)\r
-#include "Nvm.h"\r
+#include "NvM.h"\r
 #endif\r
 #if defined(USE_RTE)\r
 #include "Rte_Main.h"\r
 #endif\r
+#if defined(USE_SCHM)\r
+#include "SchM.h"\r
+#endif\r
+\r
+\r
+/* ----------------------------[private define]------------------------------*/\r
+/* ----------------------------[private macro]-------------------------------*/\r
+/* ----------------------------[private typedef]-----------------------------*/\r
+/* ----------------------------[private function prototypes]-----------------*/\r
+/* ----------------------------[private variables]---------------------------*/\r
 \r
 EcuM_GlobalType internal_data;\r
 \r
+/* ----------------------------[private functions]---------------------------*/\r
+\r
+\r
+/* ----------------------------[public functions]----------------------------*/\r
+\r
+#if !defined(USE_DET) && defined(ECUM_DEV_ERROR_DETECT)\r
+#error EcuM configuration error. DET is not enabled when ECUM_DEV_ERROR_DETECT is set\r
+#endif\r
+\r
 void EcuM_Init( void )\r
 {\r
        Std_ReturnType status;\r
-       internal_data.current_state = ECUM_STATE_STARTUP_ONE;\r
+       set_current_state(ECUM_STATE_STARTUP_ONE);\r
 \r
        // Initialize drivers that are needed to determine PostBuild configuration\r
        EcuM_AL_DriverInitZero();\r
@@ -45,12 +121,13 @@ void EcuM_Init( void )
        // Initialize the OS\r
        InitOS();\r
 \r
-       // Enable interrupts\r
+       // Setup interrupts\r
        Os_IsrInit();\r
 \r
        // Determine PostBuild configuration\r
        internal_data.config = EcuM_DeterminePbConfiguration();\r
 \r
+\r
        // TODO: Check consistency of PB configuration\r
 \r
        // Initialize drivers needed before the OS-starts\r
@@ -75,7 +152,7 @@ void EcuM_Init( void )
                //TODO: Report error.\r
        }\r
 \r
-#if defined(USE_COMM)\r
+#if defined(USE_COMM) || defined(USE_ECUM_COMM)\r
        internal_data.run_comm_requests = 0;\r
 #endif\r
        internal_data.run_requests = 0;\r
@@ -83,34 +160,42 @@ void EcuM_Init( void )
 \r
        // Start this baby up\r
        AppModeType appMode;\r
-       EcuM_GetApplicationMode(&appMode);\r
+       status = EcuM_GetApplicationMode(&appMode);\r
+       if(status!=E_OK){\r
+               //TODO: Report error.\r
+       }\r
        StartOS(appMode); /** @req EcuM2141 */\r
 }\r
 \r
+/*\r
+ * The order defined here is found in 3.1.5/EcuM2411\r
+ */\r
 void EcuM_StartupTwo(void)\r
 {\r
        //TODO:  Validate that we are in state STARTUP_ONE.\r
 #if defined(USE_NVM)\r
        extern CounterType Os_Arc_OsTickCounter;\r
-       TickType tickTimerStart, tickTimer, tickTimerElapsed;\r
-       StatusType tickTimerStatus;\r
+       TickType tickTimerStart, tickTimerElapsed;\r
        static NvM_RequestResultType readAllResult;\r
+       TickType tickTimer;\r
+       StatusType tickTimerStatus;\r
 #endif\r
 \r
-       internal_data.current_state = ECUM_STATE_STARTUP_TWO;\r
-\r
        // Initialize the BSW scheduler\r
-       // TODO SchM_Init();\r
+#if defined(USE_SCHM)\r
+       SchM_Init();\r
+#endif\r
+\r
+#if defined(USE_WDGM)\r
+       WdgM_SetMode(internal_data.config->EcuMWdgMConfig->EcuMWdgMStartupMode);\r
+#endif\r
 \r
        // Initialize drivers that don't need NVRAM data\r
        EcuM_AL_DriverInitTwo(internal_data.config);\r
 \r
 #if defined(USE_NVM)\r
        // Start timer to wait for NVM job to complete\r
-       tickTimerStatus = GetCounterValue(Os_Arc_OsTickCounter , &tickTimerStart);\r
-       if (tickTimerStatus != E_OK) {\r
-               Det_ReportError(MODULE_ID_ECUM, 0, ECUM_ARC_STARTUPTWO_ID, ECUM_E_ARC_TIMERERROR);\r
-       }\r
+       tickTimerStart = GetOsTick();\r
 #endif\r
 \r
        // Prepare the system to startup RTE\r
@@ -119,20 +204,40 @@ void EcuM_StartupTwo(void)
        Rte_Start();\r
 #endif\r
 \r
+       set_current_state(ECUM_STATE_STARTUP_TWO);\r
+\r
 #if defined(USE_NVM)\r
-       // Wait for the NVM job (NvmReadAll) to terminate\r
+\r
+#if 0\r
+       /* Wait for the NVM job (NvmReadAll) to terminate. This assumes that:\r
+        * - A task runs the memory MainFunctions, e.g. Ea_MainFunction(), Eep_MainFunction()\r
+        *    Prio: HIGH\r
+        * - A task runs the service functions for EcuM, Nvm.\r
+        *    Prio: MIDDLE\r
+        * - This task:\r
+        *    Prio: LOW  (So that the service functions for the other may run)\r
+        */\r
        do {\r
-               NvM_GetErrorStatus(0, &readAllResult);  // Read the multiblock status\r
-               tickTimer = tickTimerStart;     // Save this because the GetElapsedCounterValue() will destroy it.\r
-               tickTimerStatus =  GetElapsedCounterValue(Os_Arc_OsTickCounter, &tickTimer, &tickTimerElapsed);\r
-               if (tickTimerStatus != E_OK) {\r
-                       Det_ReportError(MODULE_ID_ECUM, 0, ECUM_ARC_STARTUPTWO_ID, ECUM_E_ARC_TIMERERROR);\r
-               }\r
+               /* Read the multiblock status */\r
+               NvM_GetErrorStatus(0, &readAllResult);\r
+               tickTimerElapsed = OS_TICKS2MS_OsTick(GetOsTick() - tickTimerStart);\r
+               /* The timeout EcuMNvramReadAllTimeout is in ms */\r
        } while( (readAllResult == NVM_REQ_PENDING) && (tickTimerElapsed < internal_data.config->EcuMNvramReadAllTimeout) );\r
+#else\r
+       // Wait for the NVM job (NvmReadAll) to terminate\r
+               do {\r
+                       NvM_GetErrorStatus(0, &readAllResult);  // Read the multiblock status\r
+                       tickTimer = tickTimerStart;     // Save this because the GetElapsedCounterValue() will destroy it.\r
+                       tickTimerStatus =  GetElapsedCounterValue(Os_Arc_OsTickCounter, &tickTimer, &tickTimerElapsed);\r
+                       if (tickTimerStatus != E_OK) {\r
+                               DET_REPORTERROR(MODULE_ID_ECUM, 0, ECUM_ARC_STARTUPTWO_ID, ECUM_E_ARC_TIMERERROR);\r
+                       }\r
+               } while( (readAllResult == NVM_REQ_PENDING) && (tickTimerElapsed < internal_data.config->EcuMNvramReadAllTimeout) );\r
+#endif\r
+#endif\r
 \r
        // Initialize drivers that need NVRAM data\r
        EcuM_AL_DriverInitThree(internal_data.config);\r
-#endif\r
 \r
        // TODO: Indicate mode change to RTE\r
 \r
@@ -145,7 +250,7 @@ void EcuM_StartupTwo(void)
 // Typically called from OS shutdown hook\r
 void EcuM_Shutdown(void)\r
 {\r
-       internal_data.current_state = ECUM_STATE_GO_OFF_TWO;\r
+       set_current_state(ECUM_STATE_GO_OFF_TWO);\r
 \r
        // Let the last drivers do a nice shutdown\r
        EcuM_OnGoOffTwo();\r
@@ -263,7 +368,48 @@ Std_ReturnType EcuM_ReleaseRUN(EcuM_UserType user)
        return E_OK;\r
 }\r
 \r
-#if defined(USE_COMM)\r
+/**\r
+ *\r
+ */\r
+void EcuM_KillAllRUNRequests( void ) {\r
+       /* NOT IMPLEMENTED */\r
+}\r
+\r
+\r
+/**\r
+ *\r
+ * @param sources\r
+ */\r
+void EcuM_SetWakeupEvent(EcuM_WakeupSourceType sources) {\r
+       /* @req 3.1.5/EcuM2826 The function exists */\r
+       /* @req 3.1.5/EcuM2171 */\r
+\r
+       /* @req 3.1.5/EcuM2867 */\r
+#if  ( ECUM_DEV_ERROR_DETECT == STD_ON )\r
+       {\r
+               EcuM_WakeupSourceType wkSource;\r
+               const EcuM_SleepModeType *sleepModePtr;\r
+\r
+               sleepModePtr = &internal_data.config->EcuMSleepModeConfig[internal_data.sleep_mode];\r
+               wkSource =  sleepModePtr->EcuMWakeupSourceMask;\r
+\r
+               if( !((sources | wkSource) ==  wkSource)) {\r
+                       Det_ReportError(MODULE_ID_ECUM, 0, ECUM_VALIDATE_WAKEUP_EVENT_ID, ECUM_E_UNKNOWN_WAKEUP_SOURCE );\r
+                       return;\r
+               }\r
+       }\r
+#endif\r
+\r
+\r
+       /* @req 3.1.5/EcuM1117 */\r
+       internal_data.wakeupEvents |= sources;\r
+\r
+       /* @req 3.1.5/EcuM2707 @req 3.1.5/EcuM2709*/\r
+//     internal_data.wakeupTimer = ECUM_VALIDATION_TIMEOUT;\r
+\r
+}\r
+\r
+#if defined(USE_COMM) || defined(USE_ECUM_COMM)\r
 Std_ReturnType EcuM_ComM_RequestRUN(NetworkHandleType channel)\r
 {\r
        VALIDATE_RV(internal_data.initiated, ECUM_COMM_REQUESTRUN_ID, ECUM_E_NOT_INITIATED, E_NOT_OK);\r
@@ -313,3 +459,72 @@ Std_ReturnType EcuM_ReleasePOST_RUN(EcuM_UserType user)
        return E_OK;\r
 }\r
 \r
+/*\r
+ * TODO: Don't yet understand the use\r
+ */\r
+void EcuM_ClearWakeupEvent( EcuM_WakeupSourceType source )\r
+{\r
+       switch(source) {\r
+       case ECUM_WKSTATUS_NONE:\r
+               /* Seems quite pointless */\r
+               break;\r
+       case ECUM_WKSTATUS_PENDING:\r
+               break;\r
+       case ECUM_WKSTATUS_VALIDATED:\r
+               break;\r
+       case ECUM_WKSTATUS_EXPIRED:\r
+               break;\r
+       default:\r
+               break;\r
+       }\r
+}\r
+\r
+/**\r
+ * Get the pending wakeup events.\r
+ *\r
+ * @return\r
+ */\r
+EcuM_WakeupSourceType EcuM_GetPendingWakeupEvents( void ) {\r
+       /* @req 3.1.5/EcuM2827 API\r
+        * @req 3.1.5/EcuM2172 Callable from interrupt context\r
+        * */\r
+\r
+       /* @req 3.1.5/EcuM1156 */\r
+       return internal_data.wakeupEvents;\r
+\r
+}\r
+\r
+\r
+EcuM_WakeupSourceType EcuM_GetValidatedWakeupEvents( void ) {\r
+       // TODO:\r
+       return 0;\r
+}\r
+\r
+EcuM_WakeupStatusType EcuM_GetStatusOfWakeupSource( EcuM_WakeupSourceType sources ) {\r
+       return 0;\r
+}\r
+\r
+/**\r
+ *\r
+ * @param sources\r
+ */\r
+void EcuM_ValidateWakeupEvent(EcuM_WakeupSourceType sources) {\r
+\r
+       /* !req 3.1.5/EcuM2344 */\r
+       /* !req 3.1.5/EcuM2645 */\r
+       /* !req 3.1.5/EcuM2868 */\r
+       /* !req 3.1.5/EcuM2345 */\r
+\r
+/*\r
+#if defined(USE_COMM)\r
+       if( internal_data.config->)\r
+       ComM_EcuM_WakeUpIndication()\r
+#endif\r
+*/\r
+       /* !req 3.1.5/EcuM2790 */\r
+       /* !req 3.1.5/EcuM2791 */\r
+\r
+}\r
+\r
+\r
+\r