Thursday, July 30, 2020

MasterSar: Initialize one

main()
{

EcuM_Init();

}

-- Bsw/EcuM/EcuM.c --

EcuM_Init()
{
    /* Set the current state of the EcuM to STARTUP */
    ECUM_STATE_STARTUP;

EcuM_AL_SetProgrammableInterrupts(); /* Source/EcuM_Callout_stubs.c */

    ECUM_DRIVERINITLIST_ZERO(); /* EcuM_AL_DriverInitZero() */

    /* Clear wakeups from all sources */
    EcuM_InternalClearWakeupEvent(ECUM_WKSOURCE_ALL_SOURCES); /*   Clear EcuM_BswM_BufferedWakeups & EcuM_ValidatedWakeups */

    /* Set the current state of the EcuM */
    EcuM_SetModuleState(ECUM_STATE_STARTUP_ONE);

    /* configuration pointer of the module */
    ECUM_DRIVERINITLIST_ONE(); /* Source/EcuM_Callout_stubs.c */

    EcuM_ValidatedWakeups |= ECUM_WKSOURCE_RESET;

    /* Store this source in the BufferedWakeups to validate it at the end of EcuM_StartupTwo */
    EcuM_BswM_BufferedWakeups |= ECUM_WKSOURCE_RESET;

    /* the global variables must be set directly at this place. */
    EcuM_CurrentShutdownTarget = EcuM_GetDefaultShutdownTarget();
    EcuM_CurrentShutdownMode = EcuM_GetDefaultShutdownMode();

    /* Start the AUTOSAR OS with the corresponding default appmode */
    EcuM_StartOS(EcuM_GetDefaultAppMode()); /* Source/EcuMCalloutStubs.c */

}

-- Source/EcuM_Callout_stubs.c --
FUNC(void, ECUM_CODE) EcuM_AL_DriverInitZero(void)
{
  ComM_InitMemory(); /* ComM/ComM.c */ ComM_InitStatus = COMM_UNINIT
  CanSM_InitMemory(); /* CanSM/CanSM.c */ CanSM_IsInitialized = CANSM_INITFUNCTION_NOT_CALLED;
  Com_InitMemory();   /* Com/Com.c */   Com_SetInitialized(FALSE);
  PduR_InitMemory(); /* PduR/PduR.c */  PduR_SetInitialized(FALSE);
  CanTrcv_30_Tja1145_InitMemory();
  BswM_InitMemory();  /* BswM/BswM.c */ BswM_SetInitialized(FALSE);
  Dem_InitMemory();   /* Dem/Dem.c */ Dem_InitState = DEM_INIT_UNINITIALIZED;
  Can_InitMemory(); /* Can/Can.c */   canConfigInitFlag = CAN_STATUS_UNINIT;  /* CAN103 */
  CanNm_InitMemory(); /* CanNM/CanNM.c */ CanNm_GetSizeOfNmState times CanNm_SetNmState(i, NM_STATE_UNINIT);
  CanTp_InitMemory(); /* CanTp/CanTp.c */ CanTp_Data_InitState() = CANTP_STATUS_NOT_INITIALIZED;
  Dem_PreInit( Dem_Config_Ptr ); /* Null */
  CanIf_InitMemory(); /* CanIf/CanIf.c */  CanIf_GetCtrlMode(CanIf_Controller_Value_Local) = CANIF_CS_UNINIT;
  Rte_InitMemory(); /* Gendata/src/Rte.c */   Rte_InitState = RTE_STATE_UNINIT; RteMemClr;
fc_sys_SetBrdID(); /* PF_SYS_MNG/src/SysGetUp.c */
fs_sys_CacheOn();
fc_sys_ResetStart();
fc_sys_AccStart( TRUE );
fc_iop_AccOn(); /* PrjMnGb/CNF/CnfIopTb.c */
fs_wrp_IniFlgSts();/*PF_SYS_WRP/Src/WrpSysCall.c */

}

/* Dem/Dem.c */
Dem_PreInit()
{
    Dem_Queue_PreInit(); -> EventCount = 5, Just initializing 5 variables to 0.
Dem_Mem_PreInit(); -> Initializing to 0.
    Dem_Esm_PreInit(); -> Setting debouncing values to 0.
    Dem_DtcSettingDisabled = FALSE;
    /* At this point:
       - BSW error reporting is enabled (Dem_ReportErrorStatus)
       - NvM has write access to RAM buffers (Dem may not access them!) */
    Dem_InitState = DEM_INIT_PREINITIALIZED;


}

/* Source/EcuMCalloutStubs.c */
void EcuM_StartOS(AppModeType appMode)
{
    fs_wrp_MemLibInit(); /* PF_SYS_WRP/src/WrpMemLb.c */ /* All (fixed) memory pools (like descriptors) for applications */

    fc_swc_MngInit(); /* PF_SWC_APL/src/SwcMng.c */

    /* Start OS must be called for each core */
    StartOS(appMode); appMode = 1, /* _osStartOSasm(); BSW/Os/Osekasm.s79 */

}

-- BSW/Os/Osekasm.s79 --
_osStartOSasm:;   - assembler part of startup code
   ; disable all interrupts
   ; set stack pointer to system stack
   ; set GBR register
   ; initialize minimun interrupts in interrupt priority table ;_osIPRInit
   ; jump to C part of StartOS
   osStartOSc();

/* BSW/Os/Osek.c */
osqFunc1 void osqFunc2 osStartOSc(void)
{
    osInitialize();
    osDisableLevel(); /* set_imask */

   osInitTCBs(); /* 53 Tasks */  osTcbActivationCount[nt]= 0; /* 42 priorities osQReadyTaskHead[np]= osQReadyTaskTail[np]= 0; */

   /* KB begin osekHWosFillTaskStacks (default) */
   osFillTaskStacks();
   osLastActiveTaskIndex = 0;
   osActiveTaskPrio = osHighReadyTaskPrio = osdNoActivePrio; /* mark as invalid for a nested interrupt */
   osActiveTaskIndex = osHighReadyTaskIndex = osdNoActiveTask;
   osIntNestingDepth = 0;
   osStartDispatcher = 0;
   osLockDispatcher = 1; /* lock dispatcher during StartOS */

   /* fullfills [SR:167] of $\AutosarOS\general\Generation5\_doc\12_SystemRequirements\RequirementsSpec_MicrosarOS.doc */
   osActiveISRID = INVALID_ISR;
   osIntAPIStatus = 0;
   /* assure that OS variables are really linked to RAM, osIntAPIStatus is volatile so compiler optimizations do not disturb */
   osIntAPIStatus = 7;
   osIntAPIStatus = 0;
   osResGlobalOccupationCounter = 0;

   for (nr=0; nr<osrNumberOfAllResources; nr++) { /* 36 */
         osResOccupationCounter[nr] = 0;
         osResActualTask[nr] = osdNoActiveTask;
   }

   /* activate all autostart tasks: Only one activated */
   for (nt= 0; nt < osrNumberOfAllTasks; nt++)
   {
      osTcbTaskState[nt] = SUSPENDED;
      if ((oskTcbAutoStart[nt] & osActiveAppMode) != 0)
      {
         (void) osSysActivateTask(nt);
      }

    osInitAlarms();

    /* setting up the task switch interrupt (alias dispatcher interrupt alias delayed interrupt) */
    osInitDelayedInt(); /* Gendata/Src/tcp.c */

   osInitTimer(); /* initialization of the hardware timer now after the startup-hook */

   /* free dispatcher (after osSysActivateTask for AutoStart-Tasks and after StartupHook */
   osLockDispatcher = 0;

   /* enable task level interrupt */
   osEnableLevel(); 

   osDispatch(); /* BSW\Os\osekext.h */ Executes the first task Init_Taskfunc */

}

/* BSW/Os/Osektask.c */
osqFunc2 osSysActivateTask(TaskType taskIndex) { /* PRQA S 1503 */
    priority = oskTcbHomePrio[taskIndex];
    osTcbTaskState[taskIndex] = PRE_READY;
    osTcbActivationCount[taskIndex]++;
    oskQActivationQueues[priority][osQReadyTaskTail[priority]]= taskIndex;
    osQReadyPrios[oskTcbReadyPrioOffset[taskIndex]]|= oskTcbReadyPrioMask[taskIndex];
    osQReadyTaskTail[priority]++;
    /* start dispatcher only if new task has greater prio */
    if (priority < osHighReadyTaskPrio)
    {
        osHighReadyTaskPrio   = priority;
        osHighReadyTaskIndex  = taskIndex;
        osStartDispatcher= osdTRUE;     /* for return from idle loop */
    }
    return E_OK;
}

/* BSW/os/OsekTime.c */
osInitAlarms()
{
    osInitMinHeap();
   /* for (alarmID= 0; alarmID < osrNumberOfAlarms; alarmID++) */
   initialize to 0
}

No comments:

Post a Comment