\r
\r
\r
+\r
#ifndef OS_H_\r
#define OS_H_\r
\r
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
#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
//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
\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
#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