/* * The order defined here is found in 3.1.5/EcuM2411 */ void EcuM_StartupTwo(void) { //TODO: Validate that we are in state STARTUP_ONE. #if defined(USE_NVM) extern CounterType Os_Arc_OsTickCounter; TickType tickTimerStart, tickTimerElapsed; static NvM_RequestResultType readAllResult; TickType tickTimer; StatusType tickTimerStatus; #endif set_current_state(ECUM_STATE_STARTUP_TWO); // Initialize the BSW scheduler #if defined(USE_SCHM) SchM_Init(); #endif #if defined(USE_WDGM) if( EcuM_World.config->EcuMWdgMConfig != NULL ) { WdgM_SetMode(EcuM_World.config->EcuMWdgMConfig->EcuMWdgMStartupMode); } #endif // Initialize drivers that don't need NVRAM data EcuM_AL_DriverInitTwo(EcuM_World.config); #if defined(USE_NVM) // Start timer to wait for NVM job to complete tickTimerStart = GetOsTick(); #endif // Prepare the system to startup RTE // TODO EcuM_OnRTEStartup(); #if defined(USE_RTE) Rte_Start(); #endif #if defined(USE_NVM) /* Wait for the NVM job (NvM_ReadAll) to terminate. This assumes that: * - A task runs the memory MainFunctions, e.g. Ea_MainFunction(), Eep_MainFunction() * are run in a higher priority task that the task that executes this code. */ do { /* Read the multiblock status */ NvM_GetErrorStatus(0, &readAllResult); tickTimerElapsed = OS_TICKS2MS_OS_TICK(GetOsTick() - tickTimerStart); /* The timeout EcuMNvramReadAllTimeout is in ms */ } while( (readAllResult == NVM_REQ_PENDING) && (tickTimerElapsed < EcuM_World.config->EcuMNvramReadAllTimeout) ); #endif // Initialize drivers that need NVRAM data EcuM_AL_DriverInitThree(EcuM_World.config); // TODO: Indicate mode change to RTE EcuM_enter_run_mode(); }
/* Blocks the thread while waiting for the semaphore to be signaled. If the "timeout" argument is non-zero, the thread should only be blocked for the specified time (measured in milliseconds). If the timeout argument is non-zero, the return value is the number of milliseconds spent waiting for the semaphore to be signaled. If the semaphore wasn't signaled within the specified time, the return value is SYS_ARCH_TIMEOUT. If the thread didn't have to wait for the semaphore (i.e., it was already signaled), the function may return zero. */ uint32 usb_sem_wait(semaphore *sem, uint32 timeout) { TickType StartTime, EndTime, Elapsed; irqmask im; StartTime = GetOsTick(); if( timeout != 0) { while( UsbGetSem( *sem) != E_OK ) { // Sleep(1); EndTime = GetOsTick(); Elapsed = EndTime - StartTime; if(Elapsed > timeout) { return SEM_TIMEOUT; } } EndTime = GetOsTick(); Elapsed = EndTime - StartTime; if( Elapsed == 0 ) { Elapsed = 1; } return (Elapsed); // return time blocked TBD test } else // must block without a timeout { while( UsbGetSem(*sem) != E_OK ) { TaskType TaskID; im = disable(); // int intNestCnt = OS_SYS_PTR->intNestCnt; // if(intNestCnt > 0){ // OS_SYS_PTR->intNestCnt = 0; // } GetTaskID(&TaskID); semlist_usb[*sem].task[semlist_usb[*sem].taskIndex++] = TaskID; // if(intNestCnt > 0){ // OS_SYS_PTR->intNestCnt = intNestCnt; // } restore(im); WaitEvent(semlist_usb[*sem].event); ClearEvent(semlist_usb[*sem].event); } EndTime = GetOsTick(); Elapsed = EndTime - StartTime; if( Elapsed == 0 ) { Elapsed = 1; } return ( Elapsed ); // return time blocked } }