1 /* -------------------------------- Arctic Core ------------------------------
\r
2 * Arctic Core - the open source AUTOSAR platform http://arccore.com
\r
4 * Copyright (C) 2009 ArcCore AB <contact@arccore.com>
\r
6 * This source code is free software; you can redistribute it and/or modify it
\r
7 * under the terms of the GNU General Public License version 2 as published by the
\r
8 * Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.
\r
10 * This program is distributed in the hope that it will be useful, but
\r
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\r
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
\r
14 * -------------------------------- Arctic Core ------------------------------*/
\r
19 #include "Std_Types.h"
\r
22 #if defined(USE_DEM)
\r
25 #include "mpc55xx.h"
\r
31 //#define USE_LDEBUG_PRINTF 1
\r
34 #define SYSCLOCK_SELECT_PLL 0x2
\r
36 #if defined(CFG_MPC5567)
\r
37 #define CALC_SYSTEM_CLOCK(_extal,_emfd,_eprediv,_erfd) \
\r
38 ( (_extal) * ((_emfd)+4) / (((_eprediv)+1)*(1<<(_erfd))) )
\r
39 #elif defined(CFG_MPC5606S)
\r
40 #define CALC_SYSTEM_CLOCK(_extal,_emfd,_eprediv,_erfd) \
\r
41 ( (_extal)*(_emfd) / ((_eprediv+1)*(2<<(_erfd))) )
\r
43 #define CALC_SYSTEM_CLOCK(_extal,_emfd,_eprediv,_erfd) \
\r
44 ( (_extal) * ((_emfd)+16) / (((_eprediv)+1)*((_erfd)+1)) )
\r
47 typedef void (*vfunc_t)();
\r
49 /* Function declarations. */
\r
50 static void Mcu_ConfigureFlash(void);
\r
53 uint32 lossOfLockCnt;
\r
54 uint32 lossOfClockCnt;
\r
58 * Type that holds all global data for Mcu
\r
62 // Set if Mcu_Init() have been called
\r
65 const Mcu_ConfigType *config;
\r
66 Mcu_ClockType clockSetting;
\r
70 /* Development error macros. */
\r
71 #if ( MCU_DEV_ERROR_DETECT == STD_ON )
\r
72 #define VALIDATE(_exp,_api,_err ) \
\r
74 Det_ReportError(MODULE_ID_MCU,0,_api,_err); \
\r
78 #define VALIDATE_W_RV(_exp,_api,_err,_rv ) \
\r
80 Det_ReportError(MODULE_ID_MCU,0,_api,_err); \
\r
84 #define VALIDATE(_exp,_api,_err )
\r
85 #define VALIDATE_W_RV(_exp,_api,_err,_rv )
\r
89 Mcu_GlobalType Mcu_Global =
\r
92 .config = &McuConfigData[0],
\r
95 //-------------------------------------------------------------------
\r
97 static void Mcu_LossOfLock( void ){
\r
98 #if defined(USE_DEM)
\r
99 Dem_ReportErrorStatus(MCU_E_CLOCK_FAILURE, DEM_EVENT_STATUS_FAILED);
\r
104 * This interrupt may be triggered more than expected.
\r
105 * If you are going to use this interrupt, see [Freescale Device Errata MPC5510ACE, Rev. 10 APR 2009, errata ID: 6764].
\r
108 #if defined(CFG_MPC5606S)
\r
111 Mcu_Global.stats.lossOfLockCnt++;
\r
113 FMPLL.SYNSR.B.LOLF = 1;
\r
117 //-------------------------------------------------------------------
\r
119 static void Mcu_LossOfCLock( void ){
\r
120 /* Should report MCU_E_CLOCK_FAILURE with DEM here */
\r
121 #if defined(CFG_MPC5606S)
\r
124 Mcu_Global.stats.lossOfClockCnt++;
\r
126 FMPLL.SYNSR.B.LOCF = 1;
\r
130 #define SPR_PIR 286
\r
131 #define SPR_PVR 287
\r
133 #define CORE_PVR_E200Z1 0x81440000UL
\r
134 #define CORE_PVR_E200Z0 0x81710000UL
\r
135 #define CORE_PVR_E200Z3 0x81120000UL
\r
136 #define CORE_PVR_E200Z6 0x81170000UL
\r
137 #define CORE_PVR_E200Z0H 0x817F0000UL
\r
149 cpu_info_t cpu_info_list[] = {
\r
150 #if defined(CFG_MPC5516)
\r
153 .pvr = CORE_PVR_E200Z1,
\r
157 .pvr = CORE_PVR_E200Z0,
\r
159 #elif defined(CFG_MPC5567)
\r
162 .pvr = CORE_PVR_E200Z6,
\r
164 #elif defined(CFG_MPC5633)
\r
167 .pvr = CORE_PVR_E200Z3,
\r
169 #elif defined(CFG_MPC5606S)
\r
171 .name = "MPC5606S",
\r
172 .pvr = CORE_PVR_E200Z0H,
\r
177 core_info_t core_info_list[] = {
\r
178 #if defined(CFG_MPC5516)
\r
180 .name = "CORE_E200Z1",
\r
181 .pvr = CORE_PVR_E200Z1,
\r
184 .name = "CORE_E200Z1",
\r
185 .pvr = CORE_PVR_E200Z1,
\r
187 #elif defined(CFG_MPC5567)
\r
189 .name = "CORE_E200Z6",
\r
190 .pvr = CORE_PVR_E200Z6,
\r
192 #elif defined(CFG_MPC5633)
\r
194 .name = "CORE_E200Z3",
\r
195 .pvr = CORE_PVR_E200Z3,
\r
197 #elif defined(CFG_MPC5606S)
\r
199 .name = "MPC5606S",
\r
200 .pvr = CORE_PVR_E200Z0H,
\r
206 #if !defined(ARRAY_SIZE)
\r
207 #define ARRAY_SIZE(_x) (sizeof(_x)/sizeof((_x)[0]))
\r
210 static cpu_info_t *Mcu_IdentifyCpu(uint32 pvr)
\r
214 for (i = 0; i < ARRAY_SIZE(cpu_info_list); i++) {
\r
215 if (cpu_info_list[i].pvr == pvr) {
\r
216 return &cpu_info_list[i];
\r
223 static core_info_t *Mcu_IdentifyCore(uint32 pvr)
\r
227 for (i = 0; i < ARRAY_SIZE(core_info_list); i++) {
\r
228 if (core_info_list[i].pvr == pvr) {
\r
229 return &core_info_list[i];
\r
236 static uint32 Mcu_CheckCpu( void ) {
\r
239 cpu_info_t *cpuType;
\r
240 core_info_t *coreType;
\r
242 // We have to registers to read here, PIR and PVR
\r
243 pir = get_spr(SPR_PIR);
\r
244 pvr = get_spr(SPR_PVR);
\r
246 cpuType = Mcu_IdentifyCpu(pvr);
\r
247 coreType = Mcu_IdentifyCore(pvr);
\r
249 if( (cpuType == NULL) || (coreType == NULL) ) {
\r
254 //DEBUG(DEBUG_HIGH,"/drivers/mcu: Cpu: %s( 0x%08x )\n",cpuType->name,pvr);
\r
255 //DEBUG(DEBUG_HIGH,"/drivers/mcu: Core: %s( 0x%08x )\n",coreType->name,pvr);
\r
260 //-------------------------------------------------------------------
\r
262 void Mcu_Init(const Mcu_ConfigType *configPtr)
\r
264 VALIDATE( ( NULL != configPtr ), MCU_INIT_SERVICE_ID, MCU_E_PARAM_CONFIG );
\r
266 if( !SIMULATOR() ) {
\r
270 memset(&Mcu_Global.stats,0,sizeof(Mcu_Global.stats));
\r
273 Mcu_ConfigureFlash();
\r
275 Mcu_Global.config = configPtr;
\r
277 #if defined(CFG_MPC5606S)
\r
278 /* Enable DRUN, RUN0, SAFE, RESET modes */
\r
279 ME.MER.R = 0x0000001D;
\r
282 Mcu_Global.initRun = 1;
\r
284 if( Mcu_Global.config->McuClockSrcFailureNotification == TRUE ) {
\r
285 #if defined(CFG_MPC5606S)
\r
288 Irq_AttachIsr1(Mcu_LossOfLock, NULL, PLL_SYNSR_LOLF,10 );
\r
289 #if defined(CFG_MPC5516)
\r
290 FMPLL.ESYNCR2.B.LOLIRQ = 1;
\r
291 #elif defined(CFG_MPC5554) || defined(CFG_MPC5567)
\r
292 FMPLL.SYNCR.B.LOLIRQ = 1;
\r
294 Irq_AttachIsr1(Mcu_LossOfCLock, NULL, PLL_SYNSR_LOCF,10 );
\r
295 #if defined(CFG_MPC5516)
\r
296 FMPLL.ESYNCR2.B.LOCIRQ = 1;
\r
297 #elif defined(CFG_MPC5554) || defined(CFG_MPC5567)
\r
298 FMPLL.SYNCR.B.LOCIRQ = 1;
\r
304 //-------------------------------------------------------------------
\r
308 Mcu_Global.initRun = FALSE; // Very simple Deinit. Should we do more?
\r
311 //-------------------------------------------------------------------
\r
313 Std_ReturnType Mcu_InitRamSection(const Mcu_RamSectionType RamSection)
\r
315 VALIDATE_W_RV( ( 1 == Mcu_Global.initRun ), MCU_INITRAMSECTION_SERVICE_ID, MCU_E_UNINIT, E_NOT_OK );
\r
316 VALIDATE_W_RV( ( RamSection <= Mcu_Global.config->McuRamSectors ), MCU_INITRAMSECTION_SERVICE_ID, MCU_E_PARAM_RAMSECTION, E_NOT_OK );
\r
318 /* NOT SUPPORTED, reason: no support for external RAM */
\r
323 //-------------------------------------------------------------------
\r
325 Std_ReturnType Mcu_InitClock(const Mcu_ClockType ClockSetting)
\r
327 Mcu_ClockSettingConfigType *clockSettingsPtr;
\r
328 VALIDATE_W_RV( ( 1 == Mcu_Global.initRun ), MCU_INITCLOCK_SERVICE_ID, MCU_E_UNINIT, E_NOT_OK );
\r
329 VALIDATE_W_RV( ( ClockSetting < Mcu_Global.config->McuClockSettings ), MCU_INITCLOCK_SERVICE_ID, MCU_E_PARAM_CLOCK, E_NOT_OK );
\r
331 Mcu_Global.clockSetting = ClockSetting;
\r
332 clockSettingsPtr = &Mcu_Global.config->McuClockSettingConfig[Mcu_Global.clockSetting];
\r
334 // TODO: find out if the 5554 really works like the 5516 here
\r
335 // All three (16, 54, 67) used to run the same code here though, so i'm sticking it with 5516
\r
336 #if defined(CFG_MPC5516) || defined(CFG_MPC5554)
\r
338 * Fsys - System frequency ( CPU + all periperals? )
\r
340 * Fsys = EXTAL_FREQ *( (emfd+16) / ( (eprediv+1) * ( erfd+1 )) ) )
\r
343 assert((clockSettingsPtr->Pll2>=32) && (clockSettingsPtr->Pll2<=132));
\r
344 assert( (clockSettingsPtr->Pll1 != 6) &&
\r
345 (clockSettingsPtr->Pll1 != 8) &&
\r
346 (clockSettingsPtr->Pll1 < 10) );
\r
347 assert( clockSettingsPtr->Pll3 & 1); // Must be odd
\r
348 #elif defined(CFG_MPC5567)
\r
349 /* 5567 clock info:
\r
350 * Fsys = EXTAL_FREQ *( (emfd+4) / ( (eprediv+1) * ( 2^erfd )) ) )
\r
353 assert(clockSettingsPtr->Pll2 < 16);
\r
354 assert(clockSettingsPtr->Pll1 <= 4);
\r
355 assert(clockSettingsPtr->Pll3 < 8);
\r
358 #if defined(USE_LDEBUG_PRINTF)
\r
360 uint32 extal = Mcu_Global.config->McuClockSettingConfig[Mcu_Global.clockSetting].McuClockReferencePointFrequency;
\r
363 f_sys = CALC_SYSTEM_CLOCK( extal,
\r
364 clockSettingsPtr->Pll2,
\r
365 clockSettingsPtr->Pll1,
\r
366 clockSettingsPtr->Pll3 );
\r
368 //DEBUG(DEBUG_HIGH,"/drivers/mcu: F_sys will be:%08d Hz\n",f_sys);
\r
372 #if defined(CFG_MPC5516)
\r
374 // External crystal PLL mode.
\r
375 FMPLL.ESYNCR1.B.CLKCFG = 7; //TODO: Hur ställa detta för 5567?
\r
377 // Write pll parameters.
\r
378 FMPLL.ESYNCR1.B.EPREDIV = clockSettingsPtr->Pll1;
\r
379 FMPLL.ESYNCR1.B.EMFD = clockSettingsPtr->Pll2;
\r
380 FMPLL.ESYNCR2.B.ERFD = clockSettingsPtr->Pll3;
\r
382 // Connect SYSCLK to FMPLL
\r
383 SIU.SYSCLK.B.SYSCLKSEL = SYSCLOCK_SELECT_PLL;
\r
384 #elif defined(CFG_MPC5606S)
\r
385 // Write pll parameters.
\r
386 CGM.FMPLL[0].CR.B.IDF = clockSettingsPtr->Pll1;
\r
387 CGM.FMPLL[0].CR.B.NDIV = clockSettingsPtr->Pll2;
\r
388 CGM.FMPLL[0].CR.B.ODF = clockSettingsPtr->Pll3;
\r
390 /* RUN0 cfg: 16MHzIRCON,OSC0ON,PLL0ON,syclk=PLL0 */
\r
391 ME.RUN[0].R = 0x001F0074;
\r
392 /* Peri. Cfg. 1 settings: only run in RUN0 mode */
\r
393 ME.RUNPC[1].R = 0x00000010;
\r
394 /* MPC56xxB/S: select ME.RUNPC[1] */
\r
395 ME.PCTL[68].R = 0x01; //SIUL control
\r
396 ME.PCTL[91].R = 0x01; //RTC/API control
\r
397 ME.PCTL[92].R = 0x01; //PIT_RTI control
\r
398 ME.PCTL[72].R = 0x01; //eMIOS0 control
\r
399 ME.PCTL[73].R = 0x01; //eMIOS1 control
\r
400 ME.PCTL[16].R = 0x01; //FlexCAN0 control
\r
401 ME.PCTL[17].R = 0x01; //FlexCAN1 control
\r
402 ME.PCTL[32].R = 0x01; //ADC0 control
\r
404 /* Mode Transition to enter RUN0 mode: */
\r
405 /* Enter RUN0 Mode & Key */
\r
406 ME.MCTL.R = 0x40005AF0;
\r
407 /* Enter RUN0 Mode & Inverted Key */
\r
408 ME.MCTL.R = 0x4000A50F;
\r
410 /* Wait for mode transition to complete */
\r
411 while (ME.GS.B.S_MTRANS) {}
\r
412 /* Verify RUN0 is the current mode */
\r
413 while(ME.GS.B.S_CURRENTMODE != 4) {}
\r
415 #elif defined(CFG_MPC5554) || defined(CFG_MPC5567)
\r
416 // Partially following the steps in MPC5567 RM..
\r
417 FMPLL.SYNCR.B.DEPTH = 0;
\r
418 FMPLL.SYNCR.B.LOLRE = 0;
\r
419 FMPLL.SYNCR.B.LOLIRQ = 0;
\r
421 FMPLL.SYNCR.B.PREDIV = clockSettingsPtr->Pll1;
\r
422 FMPLL.SYNCR.B.MFD = clockSettingsPtr->Pll2;
\r
423 FMPLL.SYNCR.B.RFD = clockSettingsPtr->Pll3;
\r
425 // Wait for PLL to sync.
\r
426 while (Mcu_GetPllStatus() != MCU_PLL_LOCKED)
\r
429 FMPLL.SYNCR.B.LOLIRQ = 1;
\r
435 //-------------------------------------------------------------------
\r
437 void Mcu_DistributePllClock(void)
\r
439 VALIDATE( ( 1 == Mcu_Global.initRun ), MCU_DISTRIBUTEPLLCLOCK_SERVICE_ID, MCU_E_UNINIT );
\r
440 #if defined(CFG_MPC5606S)
\r
441 VALIDATE( ( CGM.FMPLL[0].CR.B.S_LOCK == 1 ), MCU_DISTRIBUTEPLLCLOCK_SERVICE_ID, MCU_E_PLL_NOT_LOCKED );
\r
443 VALIDATE( ( FMPLL.SYNSR.B.LOCK == 1 ), MCU_DISTRIBUTEPLLCLOCK_SERVICE_ID, MCU_E_PLL_NOT_LOCKED );
\r
445 /* NOT IMPLEMENTED due to pointless function on this hardware */
\r
449 //-------------------------------------------------------------------
\r
451 Mcu_PllStatusType Mcu_GetPllStatus(void)
\r
453 VALIDATE_W_RV( ( 1 == Mcu_Global.initRun ), MCU_GETPLLSTATUS_SERVICE_ID, MCU_E_UNINIT, MCU_PLL_STATUS_UNDEFINED );
\r
454 Mcu_PllStatusType rv;
\r
458 #if defined(CFG_MPC5606S)
\r
459 if ( !CGM.FMPLL[0].CR.B.S_LOCK )
\r
461 rv = MCU_PLL_UNLOCKED;
\r
464 rv = MCU_PLL_LOCKED;
\r
467 if ( !FMPLL.SYNSR.B.LOCK )
\r
469 rv = MCU_PLL_UNLOCKED;
\r
472 rv = MCU_PLL_LOCKED;
\r
478 /* We are running on instruction set simulator. PLL is then always in sync... */
\r
479 rv = MCU_PLL_LOCKED;
\r
485 //-------------------------------------------------------------------
\r
487 Mcu_ResetType Mcu_GetResetReason(void)
\r
491 VALIDATE_W_RV( ( 1 == Mcu_Global.initRun ), MCU_GETRESETREASON_SERVICE_ID, MCU_E_UNINIT, MCU_RESET_UNDEFINED );
\r
493 #if defined(CFG_MPC5606S)
\r
494 if( RGM.FES.B.F_SOFT ) {
\r
496 } else if( RGM.DES.B.F_SWT ) {
\r
497 rv = MCU_WATCHDOG_RESET;
\r
498 } else if( RGM.DES.B.F_POR ) {
\r
499 rv = MCU_POWER_ON_RESET;
\r
501 rv = MCU_RESET_UNDEFINED;
\r
504 if( SIU.RSR.B.SSRS ) {
\r
506 } else if( SIU.RSR.B.WDRS ) {
\r
507 rv = MCU_WATCHDOG_RESET;
\r
508 } else if( SIU.RSR.B.PORS || SIU.RSR.B.ERS ) {
\r
509 rv = MCU_POWER_ON_RESET;
\r
511 rv = MCU_RESET_UNDEFINED;
\r
518 //-------------------------------------------------------------------
\r
520 Mcu_RawResetType Mcu_GetResetRawValue(void)
\r
522 VALIDATE_W_RV( ( 1 == Mcu_Global.initRun ), MCU_GETRESETREASON_SERVICE_ID, MCU_E_UNINIT, MCU_GETRESETRAWVALUE_UNINIT_RV );
\r
524 if( !Mcu_Global.initRun ) {
\r
525 return MCU_GETRESETRAWVALUE_UNINIT_RV;
\r
528 #if defined(CFG_MPC5606S)
\r
539 //-------------------------------------------------------------------
\r
541 #if ( MCU_PERFORM_RESET_API == STD_ON )
\r
542 void Mcu_PerformReset(void)
\r
544 VALIDATE( ( 1 == Mcu_Global.initRun ), MCU_PERFORMRESET_SERVICE_ID, MCU_E_UNINIT );
\r
547 #if defined(CFG_MPC5606S)
\r
548 ME.MCTL.R = 0x00005AF0;
\r
549 ME.MCTL.R = 0x0000A50F;
\r
551 while (ME.GS.B.S_MTRANS) {}
\r
552 while(ME.GS.B.S_CURRENTMODE != 0) {}
\r
554 SIU.SRCR.B.SSR = 1;
\r
560 //-------------------------------------------------------------------
\r
562 void Mcu_SetMode(const Mcu_ModeType McuMode)
\r
564 VALIDATE( ( 1 == Mcu_Global.initRun ), MCU_SETMODE_SERVICE_ID, MCU_E_UNINIT );
\r
565 // VALIDATE( ( McuMode <= Mcu_Global.config->McuNumberOfMcuModes ), MCU_SETMODE_SERVICE_ID, MCU_E_PARAM_MODE );
\r
568 /* NOT SUPPORTED */
\r
571 //-------------------------------------------------------------------
\r
574 * Get the system clock in Hz. It calculates the clock from the
\r
575 * different register settings in HW.
\r
577 uint32_t McuE_GetSystemClock(void)
\r
580 * System clock calculation
\r
582 * 5516 - f_sys = extal * (emfd+16) / ( (eprediv+1) * ( erfd+1 ));
\r
583 * 5567 - f_sys = extal * (emfd+4) / ( (eprediv+1) * ( 2^erfd ));
\r
584 * 563x - We run in legacy mode = 5567
\r
585 * 5606s - f_sys = extal * emfd / ((eprediv+1)*(2<<(erfd)));
\r
587 #if defined(CFG_MPC5516)
\r
588 uint32_t eprediv = FMPLL.ESYNCR1.B.EPREDIV;
\r
589 uint32_t emfd = FMPLL.ESYNCR1.B.EMFD;
\r
590 uint32_t erfd = FMPLL.ESYNCR2.B.ERFD;
\r
591 #elif defined(CFG_MPC5554) || defined(CFG_MPC5567) || defined(CFG_MPC5633)
\r
592 uint32_t eprediv = FMPLL.SYNCR.B.PREDIV;
\r
593 uint32_t emfd = FMPLL.SYNCR.B.MFD;
\r
594 uint32_t erfd = FMPLL.SYNCR.B.RFD;
\r
595 #elif defined(CFG_MPC5606S)
\r
596 uint32_t eprediv = CGM.FMPLL[0].CR.B.IDF;
\r
597 uint32_t emfd = CGM.FMPLL[0].CR.B.NDIV;
\r
598 uint32_t erfd = CGM.FMPLL[0].CR.B.ODF;
\r
602 uint32 extal = Mcu_Global.config->McuClockSettingConfig[Mcu_Global.clockSetting].McuClockReferencePointFrequency;
\r
604 f_sys = CALC_SYSTEM_CLOCK(extal,emfd,eprediv,erfd);
\r
609 imask_t McuE_EnterCriticalSection()
\r
611 uint32_t msr = get_msr();
\r
616 void McuE_ExitCriticalSection(uint32_t old_state)
\r
618 set_msr(old_state);
\r
622 * Get the peripheral clock in Hz for a specific device
\r
624 uint32_t McuE_GetPeripheralClock(McuE_PeriperalClock_t type)
\r
626 #if defined(CFG_MPC5567)
\r
627 // No peripheral dividers on 5567.
\r
628 return McuE_GetSystemClock();
\r
630 uint32_t sysClock = McuE_GetSystemClock();
\r
631 vuint32_t prescaler;
\r
633 // See table 3.1, section 3.4.5 Peripheral Clock dividers
\r
636 case PERIPHERAL_CLOCK_FLEXCAN_A:
\r
637 case PERIPHERAL_CLOCK_DSPI_A:
\r
638 #if defined(CFG_MPC5516)
\r
639 prescaler = SIU.SYSCLK.B.LPCLKDIV0;
\r
641 #elif defined(CFG_MPC5606S)
\r
642 prescaler = CGM.SC_DC[1].R;
\r
646 case PERIPHERAL_CLOCK_PIT:
\r
647 case PERIPHERAL_CLOCK_ESCI_A:
\r
648 case PERIPHERAL_CLOCK_IIC_A:
\r
649 #if defined(CFG_MPC5516)
\r
650 prescaler = SIU.SYSCLK.B.LPCLKDIV1;
\r
654 case PERIPHERAL_CLOCK_FLEXCAN_B:
\r
655 case PERIPHERAL_CLOCK_FLEXCAN_C:
\r
656 case PERIPHERAL_CLOCK_FLEXCAN_D:
\r
657 case PERIPHERAL_CLOCK_FLEXCAN_E:
\r
658 case PERIPHERAL_CLOCK_FLEXCAN_F:
\r
659 #if defined(CFG_MPC5516)
\r
660 prescaler = SIU.SYSCLK.B.LPCLKDIV2;
\r
662 #elif defined(CFG_MPC5606S)
\r
663 prescaler = CGM.SC_DC[1].R;
\r
667 case PERIPHERAL_CLOCK_DSPI_B:
\r
668 case PERIPHERAL_CLOCK_DSPI_C:
\r
669 case PERIPHERAL_CLOCK_DSPI_D:
\r
670 #if defined(CFG_MPC5516)
\r
671 prescaler = SIU.SYSCLK.B.LPCLKDIV3;
\r
675 case PERIPHERAL_CLOCK_ESCI_B:
\r
676 case PERIPHERAL_CLOCK_ESCI_C:
\r
677 case PERIPHERAL_CLOCK_ESCI_D:
\r
678 case PERIPHERAL_CLOCK_ESCI_E:
\r
679 case PERIPHERAL_CLOCK_ESCI_F:
\r
680 case PERIPHERAL_CLOCK_ESCI_G:
\r
681 case PERIPHERAL_CLOCK_ESCI_H:
\r
682 #if defined(CFG_MPC5516)
\r
683 prescaler = SIU.SYSCLK.B.LPCLKDIV4;
\r
687 #if defined(CFG_MPC5606S)
\r
688 case PERIPHERAL_CLOCK_EMIOS_0:
\r
689 prescaler = CGM.SC_DC[2].R;
\r
691 case PERIPHERAL_CLOCK_EMIOS_1:
\r
692 prescaler = CGM.SC_DC[2].R;
\r
695 case PERIPHERAL_CLOCK_EMIOS:
\r
696 #if defined(CFG_MPC5516)
\r
697 prescaler = SIU.SYSCLK.B.LPCLKDIV5;
\r
702 case PERIPHERAL_CLOCK_MLB:
\r
703 #if defined(CFG_MPC5516)
\r
704 prescaler = SIU.SYSCLK.B.LPCLKDIV6;
\r
713 return sysClock/(1<<prescaler);
\r
719 * Function to setup the internal flash for optimal performance
\r
722 static void Mcu_ConfigureFlash(void)
\r
724 /* These flash settings increases the CPU performance of 7 times compared
\r
725 to reset default settings!! */
\r
727 #if defined(CFG_MPC5516)
\r
728 /* Disable pipelined reads when flash options are changed. */
\r
729 FLASH.MCR.B.PRD = 1;
\r
731 /* Enable master prefetch for e200z1 and eDMA. */
\r
732 FLASH.PFCRP0.B.M0PFE = 1;
\r
733 FLASH.PFCRP0.B.M2PFE = 1;
\r
735 /* Address pipelining control. Must be set to the same value as RWSC. */
\r
736 FLASH.PFCRP0.B.APC = 2;
\r
737 FLASH.PFCRP0.B.RWSC = 2;
\r
739 /* Write wait states. */
\r
740 FLASH.PFCRP0.B.WWSC = 1;
\r
742 /* Enable data prefetch. */
\r
743 FLASH.PFCRP0.B.DPFEN = 1;
\r
745 /* Enable instruction prefetch. */
\r
746 FLASH.PFCRP0.B.IPFEN = 1;
\r
748 /* Prefetch algorithm. */
\r
749 /* TODO: Ask Freescale about this option. */
\r
750 FLASH.PFCRP0.B.PFLIM = 2;
\r
752 /* Enable line read buffers. */
\r
753 FLASH.PFCRP0.B.BFEN = 1;
\r
755 /* Enable pipelined reads again. */
\r
756 FLASH.MCR.B.PRD = 0;
\r
757 #elif defined(CFG_MPC5554) || defined(CFG_MPC5567)
\r
758 //TODO: Lägg till flash för mpc5554 &67
\r
762 void McuE_EnableInterrupts(void)
\r
767 void McuE_DisableInterrupts(void)
\r