]> rtime.felk.cvut.cz Git - arc.git/commitdiff
Small Nvm fix
authormahi <devnull@localhost>
Wed, 7 Mar 2012 10:29:20 +0000 (11:29 +0100)
committermahi <devnull@localhost>
Wed, 7 Mar 2012 10:29:20 +0000 (11:29 +0100)
include/Os.h
memory/NvM/NvM.c
system/EcuM/EcuM.c

index 65442783cfbd8d8cecf05035c79ca41efb5c86ed..f0146ac95ccef54e77cd6cfa6441d3ceee5d09d9 100644 (file)
@@ -15,6 +15,7 @@
 \r
 \r
 \r
+\r
 #ifndef OS_H_\r
 #define OS_H_\r
 \r
@@ -346,6 +347,19 @@ void Os_SysTickStart(TickType period_ticks);
 TickType Os_SysTickGetValue( void );\r
 TickType Os_SysTickGetElapsedValue( TickType preValue );\r
 \r
+/* Return a value that is always a free running timer */\r
+TickType GetOsTick( void );\r
+\r
+/* Since this is based on SW ticks, no use to have ns resolution */\r
+#define OSTICKDURATION_US              (OSTICKDURATION/1000UL)\r
+\r
+/* Have special macros to always get the OsTick */\r
+#define OS_TICKS2SEC_OsTick(_ticks)            ( (OSTICKDURATION_US * (_ticks))/1000000UL )\r
+#define OS_TICKS2MS_OsTick(_ticks)             ( (OSTICKDURATION_US * (_ticks))/1000UL )\r
+#define OS_TICKS2US_OsTick(_ticks)             (OSTICKDURATION_US * (_ticks))\r
+#define OS_TICKS2NS_OsTick(_ticks)             (OSTICKDURATION * (_ticks))\r
+\r
+\r
 /*-------------------------------------------------------------------\r
  * Kernel extra\r
  *-----------------------------------------------------------------*/\r
index 59d483579d8427520835aa907b38fbdcce9181d1..7dcfb3ac1393664f691f0e9acdbc4e643022acd1 100644 (file)
 #include "Crc.h"\r
 #include <string.h>\r
 \r
-#define DEBUG_BLOCK    1\r
+//#define DEBUG_BLOCK  1\r
 #if defined(DEBUG_BLOCK)\r
 #define DEBUG_BLOCK_STATE(_str,_block,_state)       printf("%s BLOCK NR:%d STATE:%d\n",_str,_block, _state); fflush(stdout);\r
 #define DEBUG_STATE(_state,_substate)                          printf("MAIN_STATE:%s/%d\n",StateToStr[_state],_substate); fflush(stdout);\r
 #define DEBUG_PRINTF(format,...)                                       printf(format,## __VA_ARGS__ ); fflush(stdout);\r
 #define DEBUG_CHECKSUM(_str,_crc)                                      printf("%s crc=%x\n",_str,_crc);\r
+#else\r
+#define DEBUG_BLOCK_STATE(_str,_block,_state)\r
+#define DEBUG_STATE(_state,_substate)\r
+#define DEBUG_PRINTF(format,...)\r
+#define DEBUG_CHECKSUM(_str,_crc)\r
 #endif\r
 \r
 \r
index 7443d184b17632a096d1d954fdba16076329abdf..a3337ea95dcb731bb7d3750f085c46707667bb1f 100644 (file)
@@ -103,9 +103,10 @@ void EcuM_StartupTwo(void)
        //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
        set_current_state(ECUM_STATE_STARTUP_TWO);\r
@@ -118,10 +119,7 @@ void EcuM_StartupTwo(void)
 \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
@@ -131,15 +129,33 @@ void EcuM_StartupTwo(void)
 #endif\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