Exemple #1
0
EXTERN_C
void Mcu_Init(const Mcu_ConfigType* McuConfig)
{
  static_cast<void>(McuConfig);

  mcal::cpu::init(nullptr);
  mcal::osc::init(nullptr);

  // Initialize the MCU clock.
  Mcu_InitClock(static_cast<Mcu_ClockType>(0));

  // Wait for PLL lock.
  while(MCU_PLL_LOCKED != Mcu_GetPllStatus())
  {
    mcal::cpu::nop();
  }
}
Std_ReturnType Mcu_InitClock(const Mcu_ClockType ClockSetting)
{
  const Mcu_ClockSettingConfigType *clockSettingsPtr;
  VALIDATE_W_RV( ( 1 == Mcu_Global.initRun ), MCU_INITCLOCK_SERVICE_ID, MCU_E_UNINIT, E_NOT_OK );
  VALIDATE_W_RV( ( ClockSetting < Mcu_Global.config->McuClockSettings ), MCU_INITCLOCK_SERVICE_ID, MCU_E_PARAM_CLOCK, E_NOT_OK );

  Mcu_Global.clockSetting = ClockSetting;
  clockSettingsPtr = &Mcu_Global.config->McuClockSettingConfig[Mcu_Global.clockSetting];

  CLKSEL &= ~BM_PLLSEL; // Turn off PLL
  PLLCTL |= BM_PLLON+BM_AUTO;  // Enable PLL module, Auto Mode

  REFDV = clockSettingsPtr->Pll1;  // Set reference divider
  SYNR = clockSettingsPtr->Pll2;  // Set synthesizer multiplier

  while (Mcu_GetPllStatus() != MCU_PLL_LOCKED) ;
  CLKSEL |= BM_PLLSEL; // Switch to PLL clock

  return E_OK;
}
void EcuM_CheckWakeup(EcuM_WakeupSourceType source) {

	/* Re-enable PLL again */
	EcuM_ConfigType *ecuMConfigPtr;
	ecuMConfigPtr = EcuM_DeterminePbConfiguration();
	(void) Mcu_InitClock(ecuMConfigPtr->McuConfig->McuDefaultClockSettings);

	// Wait for PLL to sync.
	while (Mcu_GetPllStatus() != MCU_PLL_LOCKED) {
		;
	}

	/* ADD CODE BELOW */
#if 0
	/* Example */
	if (ECUM_WKSOURCE_SWITCH & wakeupSource) {
		if (CRP.PSCR.R & 0x00020000) {
			EcuM_SetWakeupEvent(ECUM_WKSOURCE_SWITCH);
		}
	}
#endif

}
Exemple #4
0
Std_ReturnType Mcu_InitClock(const Mcu_ClockType ClockSetting)
{
    const Mcu_ClockSettingConfigType *clockSettingsPtr;
    VALIDATE_W_RV( ( 1 == Mcu_Global.initRun ), MCU_INITCLOCK_SERVICE_ID, MCU_E_UNINIT, E_NOT_OK );
    VALIDATE_W_RV( ( ClockSetting < Mcu_Global.config->McuClockSettings ), MCU_INITCLOCK_SERVICE_ID, MCU_E_PARAM_CLOCK, E_NOT_OK );

    Mcu_Global.clockSetting = ClockSetting;
    clockSettingsPtr = &Mcu_Global.config->McuClockSettingConfig[Mcu_Global.clockSetting];

    Mcu_Arc_InitClockPre(clockSettingsPtr);

    // TODO: find out if the 5554 really works like the 5516 here
    // All three (16, 54, 67) used to run the same code here though, so i'm sticking it with 5516
#if defined(CFG_MPC5516) || defined(CFG_MPC5554) || defined(CFG_MPC5668)
    /* 5516clock info:
     * Fsys - System frequency ( CPU + all periperals? )
     *
     *  Fsys = EXTAL_FREQ *(  (emfd+16) / ( (eprediv+1) * ( erfd+1 )) ) )
     */
    // Check ranges...
    assert((clockSettingsPtr->Pll2>=32) && (clockSettingsPtr->Pll2<=132));
    assert( (clockSettingsPtr->Pll1 != 6) &&
            (clockSettingsPtr->Pll1 != 8) &&
            (clockSettingsPtr->Pll1 < 10) );
    assert( clockSettingsPtr->Pll3 & 1); // Must be odd
#elif defined(CFG_MPC5567) || defined(CFG_MPC563XM)
    /* 5567 clock info:
     *  Fsys = EXTAL_FREQ *(  (emfd+4) / ( (eprediv+1) * ( 2^erfd )) ) )
     */
    // Check ranges...
    assert(clockSettingsPtr->Pll2 < 16);
    assert(clockSettingsPtr->Pll1 <= 4);
    assert(clockSettingsPtr->Pll3 < 8);
#endif

#if defined(USE_LDEBUG_PRINTF)
    {
    	uint32  extal = Mcu_Global.config->McuClockSettingConfig[Mcu_Global.clockSetting].McuClockReferencePointFrequency;
    	uint32  f_sys;

    	f_sys = CALC_SYSTEM_CLOCK( extal,
    		clockSettingsPtr->Pll2,
    		clockSettingsPtr->Pll1,
    		clockSettingsPtr->Pll3 );

        //DEBUG(DEBUG_HIGH,"/drivers/mcu: F_sys will be:%08d Hz\n",f_sys);
    }
#endif

#if defined(CFG_MPC5516) || defined(CFG_MPC5668)

    // set post divider to next valid value to ensure that an overshoot during lock phase
    // won't result in a too high freq
    FMPLL.ESYNCR2.B.ERFD = (clockSettingsPtr->Pll3 + 1) | 1;

    // External crystal PLL mode.
    FMPLL.ESYNCR1.B.CLKCFG = 7; //TODO: Hur ställa detta för 5567?

    // Write pll parameters.
    FMPLL.ESYNCR1.B.EPREDIV = clockSettingsPtr->Pll1;
    FMPLL.ESYNCR1.B.EMFD    = clockSettingsPtr->Pll2;

#if defined(CFG_SIMULATOR)
    FMPLL.SYNSR.B.LOCK = 1;
#endif

    while(FMPLL.SYNSR.B.LOCK != 1) {};

    FMPLL.ESYNCR2.B.ERFD    = clockSettingsPtr->Pll3;
    // Connect SYSCLK to FMPLL
    SIU.SYSCLK.B.SYSCLKSEL = SYSCLOCK_SELECT_PLL;

 #elif defined(CFG_MPC5554) || defined(CFG_MPC5567)
    // Partially following the steps in MPC5567 RM..
    FMPLL.SYNCR.B.DEPTH	= 0;
    FMPLL.SYNCR.B.LOLRE	= 0;
    FMPLL.SYNCR.B.LOLIRQ = 0;

    FMPLL.SYNCR.B.PREDIV 	= clockSettingsPtr->Pll1;
    FMPLL.SYNCR.B.MFD		= clockSettingsPtr->Pll2;
    FMPLL.SYNCR.B.RFD    	= clockSettingsPtr->Pll3;

	// Wait for PLL to sync.
    while (Mcu_GetPllStatus() != MCU_PLL_LOCKED) ;

    FMPLL.SYNCR.B.LOLIRQ	= 1;
#elif defined(CFG_MPC563XM)

   FMPLL.SYNCR.B.PREDIV 	= clockSettingsPtr->Pll1;
   FMPLL.SYNCR.B.MFD		= clockSettingsPtr->Pll2;
   FMPLL.SYNCR.B.RFD    	= clockSettingsPtr->Pll3;

	// Wait for PLL to sync.
   while (Mcu_GetPllStatus() != MCU_PLL_LOCKED) ;

   FMPLL.SYNCR.B.LOLIRQ	= 1;
#endif

    Mcu_Arc_InitClockPost(clockSettingsPtr);

    return E_OK;
}
/**
 * Part of STARTUP I
 *
 * @param ConfigPtr
 */
void EcuM_AL_DriverInitOne(const EcuM_ConfigType *ConfigPtr)
{
	(void)ConfigPtr;

#if defined(USE_MCU)
	Mcu_Init(ConfigPtr->McuConfig);

	/* Set up default clock (Mcu_InitClock requires initRun==1) */
	/* Ignoring return value */
	(void) Mcu_InitClock(ConfigPtr->McuConfig->McuDefaultClockSettings);

	// Wait for PLL to sync.
	while (Mcu_GetPllStatus() != MCU_PLL_LOCKED) {
		;
	}

	Mcu_DistributePllClock();
#endif

#if defined(USE_DEM)
	// Preinitialize DEM
	NO_DRIVER(Dem_PreInit(ConfigPtr->DemConfig));
#endif

#if defined(USE_PORT)
	// Setup Port
	Port_Init(ConfigPtr->PortConfig);
#endif

#if defined(USE_DIO)
    // Setup Dio
    Dio_Init(ConfigPtr->DioCfg);
#endif

#if defined(USE_GPT)
	// Setup the GPT
	Gpt_Init(ConfigPtr->GptConfig);
#endif

	// Setup watchdog
#if defined(USE_WDG)
	Wdg_Init(ConfigPtr->WdgConfig);
#endif
#if defined(USE_WDGM)
	NO_DRIVER(WdgM_Init(ConfigPtr->WdgMConfig));
#endif

#if defined(USE_DMA)
	// Setup DMA
	Dma_Init(ConfigPtr->DmaConfig);
#endif

#if defined(USE_ADC)
	// Setup ADC
	Adc_Init(ConfigPtr->AdcConfig);
#endif

#if defined(USE_BSWM)
	// Setup BSWM - not supporting configustructure for BswM
	BswM_Init(NULL);
#endif

	// Setup ICU
#if defined(USE_ICU)
     Icu_Init(ConfigPtr->IcuConfig);
#endif

	// Setup PWM
#if defined(USE_PWM)
	// Setup PWM
	Pwm_Init(ConfigPtr->PwmConfig);
#endif

    // Setup OCU
#if defined(USE_OCU)
	 Ocu_Init(ConfigPtr->OcuConfig);
#endif

#if defined(CFG_SHELL)
	SHELL_Init();
#endif
}
/**
 * Part of STARTUP I
 *
 * @param ConfigPtr
 */
void EcuM_AL_DriverInitOne(const EcuM_ConfigType *ConfigPtr)
{
	(void)ConfigPtr;

//	VALIDATE_STATE( ECUM_STATE_STARTUP_ONE );

  //lint --e{715}       PC-Lint (715) - ConfigPtr usage depends on configuration of modules

#if defined(USE_MCU)
	Mcu_Init(ConfigPtr->McuConfig);

	/* Set up default clock (Mcu_InitClock requires initRun==1) */
	/* Ignoring return value */
	(void) Mcu_InitClock(ConfigPtr->McuConfig->McuDefaultClockSettings);

	// Wait for PLL to sync.
	while (Mcu_GetPllStatus() != MCU_PLL_LOCKED) {
		;
	}

	Mcu_DistributePllClock();
#endif

#if defined(USE_DEM)
	// Preinitialize DEM
	NO_DRIVER(Dem_PreInit(ConfigPtr->DemConfig));
#endif

#if defined(USE_PORT)
	// Setup Port
	Port_Init(ConfigPtr->PortConfig);
#endif

#if defined(USE_GPT)
	// Setup the GPT
	Gpt_Init(ConfigPtr->GptConfig);
#endif

	// Setup watchdog
#if defined(USE_WDG)
	Wdg_Init(ConfigPtr->WdgConfig);
#endif
#if defined(USE_WDGM)
	NO_DRIVER(WdgM_Init(ConfigPtr->WdgMConfig));
#endif

#if defined(USE_DMA)
	// Setup DMA
	Dma_Init(ConfigPtr->DmaConfig);
#endif

#if defined(USE_ADC)
	// Setup ADC
	Adc_Init(ConfigPtr->AdcConfig);
#endif

	// Setup ICU
	// TODO
	// Setup PWM
#if defined(USE_PWM)
	// Setup PWM
	Pwm_Init(ConfigPtr->PwmConfig);
#endif

#if defined(CFG_SHELL)
	SHELL_Init();
#endif


}