void EcuM_AL_DriverInitOne(const EcuM_ConfigType* configPtr) { /* provide a proper clock */ Mcu_Init(configPtr->bsw_driver.init_one.mcu_cfg); Mcu_InitClock(0); Mcu_DistributePllClock(); /* ----------------------------------------------------------------------- Interrupt System: ----------------------------------------------------------------------- - four arbitration cycles (max. 255 interrupt sources) - two clocks per arbitration cycle */ __mtcr(0xFE2C, 0x00000000); /* load CPU interrupt control register */ __isync(); /* ----------------------------------------------------------------------- Peripheral Control Processor (PCP): ----------------------------------------------------------------------- - the PCP internal clock is always running - use Full Context save area (R[0] - R[7]) - start progam counter as left by last invocation - channel watchdog is disabled - maximum channel number checking is disabled */ /* - four arbitration cycles (max. 255 PCP channels) */ /* - two clocks per arbitration cycle */ PCP_ICR.U = 0x00000000; /* load PCP interrupt control register */ /* - the PCP warning mechanism is disabled */ PCP_ITR.U = 0x00000000; /* load PCP interrupt threshold register */ /* - type of service of PCP node 4 is CPU interrupt */ PCP_SRC4.U = 0x00001000; /* load service request control register 4 */ /* - type of service of PCP node 5 is CPU interrupt */ PCP_SRC5.U = 0x00001000; /* load service request control register 5 */ /* - type of service of PCP node 6 is CPU interrupt */ PCP_SRC6.U = 0x00001000; /* load service request control register 6 */ /* - type of service of PCP node 7 is CPU interrupt */ PCP_SRC7.U = 0x00001000; /* load service request control register 7 */ /* - type of service of PCP node 8 is CPU interrupt */ PCP_SRC8.U = 0x00001000; /* load service request control register 8 */ ts_initGPTAInt(); Port_Init(configPtr->bsw_driver.init_one.port_cfg); Adc_Init(configPtr->bsw_driver.init_one.adc_cfg); Fls_Init(configPtr->bsw_driver.init_one.fls_cfg); Gpt_Init(configPtr->bsw_driver.init_one.gpt_cfg); Pwm_Init(configPtr->bsw_driver.init_one.pwm_cfg); Spi_Init(configPtr->bsw_driver.init_one.spi_cfg); Wdg_Init(configPtr->bsw_driver.init_one.wdg_cfg); #ifdef ECUM_WDGM_INCLUDED WdgM_Init(configPtr->bsw_driver.init_one.wdgm_cfg); #endif /* setup end of init protected registers for OS */ ts_endinit_clear(); osInitProtected(); ts_endinit_set(); /* Overlay Ram: * Init registers and mem areas for switching from * working page (overlay ram) <-> reference page (flash) */ RAM_OverlayRamReset(); /* - the CPU interrupt system is globally disabled */ __enable(); Spi_SetAsyncMode(SPI_INTERRUPT_MODE); Adc_StartGroupConversion(0); Adc_StartGroupConversion(1); EcuM_SelectApplicationMode(OSDEFAULTAPPMODE); }
/** * Initialize EcuM. */ void EcuM_Init(void) { Std_ReturnType status; set_current_state(ECUM_STATE_STARTUP_ONE); // Initialize drivers that are needed to determine PostBuild configuration EcuM_AL_DriverInitZero(); // Initialize the OS InitOS(); // Setup interrupts Os_IsrInit(); // Determine PostBuild configuration EcuM_World.config = EcuM_DeterminePbConfiguration(); // TODO: Check consistency of PB configuration // Initialize drivers needed before the OS-starts EcuM_AL_DriverInitOne(EcuM_World.config); // Determine the reset/wakeup reason switch (Mcu_GetResetReason()) { case MCU_POWER_ON_RESET: EcuM_SetWakeupEvent(ECUM_WKSOURCE_POWER); break; case MCU_SW_RESET: EcuM_SetWakeupEvent(ECUM_WKSOURCE_RESET); break; case MCU_RESET_UNDEFINED: break; case MCU_WATCHDOG_RESET: EcuM_SetWakeupEvent(ECUM_WKSOURCE_INTERNAL_WDG); break; default: assert(0); break; } // Moved this here because EcuM_SelectShutdownTarget needs us to be initilized. EcuM_World.initiated = TRUE; // Set default shutdown target status = EcuM_SelectShutdownTarget( EcuM_World.config->EcuMDefaultShutdownTarget, EcuM_World.config->EcuMDefaultSleepMode);/** @req EcuM2181 */ if (status != E_OK) { //TODO: Report error. } // Set default application mode status = EcuM_SelectApplicationMode( EcuM_World.config->EcuMDefaultAppMode); if (status != E_OK) { //TODO: Report error. } #if defined(USE_COMM) EcuM_World.run_comm_requests = 0; #endif EcuM_World.run_requests = 0; EcuM_World.postrun_requests = 0; // Start this baby up AppModeType appMode; status = EcuM_GetApplicationMode(&appMode); if (status != E_OK) { //TODO: Report error. } StartOS(appMode); /** @req EcuM2141 */ }