void Wdg_Init (const Wdg_ConfigType* ConfigPtr) { /* Keep a pointer to the config. */ configWdgPtr = ConfigPtr; Wdg_SetMode(ConfigPtr->Wdg_ModeConfig->Wdg_DefaultMode); }
/** * Starts the watchdog * @param timeout - is in either ms or ticks */ static void StartWatchdog(uint32 timeout) { /*lint -save -e923 Ok, that casting is done in Freescale header file */ #if defined(CFG_MPC5567) (void)timeout; ECSM.SWTCR.R = 0x00D8; #elif defined(CFG_MPC563XM) SWT.TO.R = timeout;/* Timeout in ticks */ SWT.CR.R = 0x8000011BuL; #elif defined(CFG_MPC5777M) SWT.CR.R = 0xE000011BuL; /* Access for all cores */ #elif defined(CFG_MPC5644A) SWT.TO.R = timeout;/* Timeout in ticks */ SWT.MCR.R = 0x8000011BuL; #elif defined(CFG_MPC5744P) || defined(CFG_MPC5645S) || defined(CFG_MPC5643L) || defined(CFG_SPC56XL70) || defined(CFG_MPC560X) /* Clear soft lock */ SWT.SR.R = SOFTLOCK_WORD_1; /* Write keys to clear soft lock bit */ SWT.SR.R = SOFTLOCK_WORD_2; #if defined(CFG_MPC5645S) || defined(CFG_MPC560X) /* Clocked by 128 kHz IRC clock */ SWT.TO.R = timeout * 128u; /* Timeout in ms */ #else /* Clocked by 16 MHz IRC clock */ SWT.TO.R = timeout * 16000u; /* Timeout in ms */ #endif /* Enable Watchdog */ /*lint -e{970} Lint does not seem handle typeof well */ SWT.CR.B = (typeof(SWT.CR.B)){.RIA = 1, .SLK = 1, .FRZ = 1, .WEN = 1, .MAP0 = 1}; #elif defined(CFG_MPC5668) /* Clocked by 16 MHz IRC clock */ /* Clear softlock */ WRITE32(SWT_BASE + SWT_SR, SOFTLOCK_WORD_1); WRITE32(SWT_BASE + SWT_SR, SOFTLOCK_WORD_2); /* Write TMO */ WRITE32(SWT_BASE + SWT_TO, timeout * 16000 ); /* Timeout in ms */ /* Enable Watchdog */ WRITE32(SWT_BASE + SWT_CR,0x80000000UL + CR_RIA + CR_SLK + CR_CSL + CR_FRZ + CR_WEN); #elif defined(CFG_MPC5516) /* We running on system clock, ie SIU_SYSCLK.SWTCLKSEL, so get the value */ /* The timeout is 2^x, so get best possible value * Table for 80Mhz * ------------------ * 2^9 = 512 = 6.4 uS * 2^15 = 400 uS * 2^20 = 13 mS * 2^28 = 3.3 S * 2^31 = 26,84 S * * Formula: * 1/clock * 2^n = tmo_in_s * 2^n = tmo_in_s * clock -> n = log2(tmo_in_s * clock) = log2(tmo_in_ms * clock / 1000 ) * */ uint32 swtVal = ilog2( Mcu_Arc_GetSystemClock()/1000 * timeout ); /* Timeout in ms */ #if defined(CFG_WDG_TEST) MCM.SWTCR.R = (SWTCR_SWE + SWTCR_SWRI(WDG_SWRI_VAL) + swtVal); #else MCM.SWTCR.R = (SWTCR_SWE + SWTCR_SWRI(2) + swtVal); #endif #else MCM.SWTCR.R = 0x00D8u; #endif /*lint -restore */ } /** * Stops the watchdog */ static void StopWatchdog(void) { /*lint -save -e923 Ok, the casting is done in Freesacale header file */ #if defined(CFG_MPC5567) ECSM.SWTCR.R = 0x0059u; #elif defined(CFG_MPC560X) || defined(CFG_MPC5668) || defined(CFG_MPC563XM) || defined(CFG_MPC5744P) || defined(CFG_MPC5645S) || defined(CFG_MPC5643L) || defined(CFG_SPC56XL70) SWT.SR.R = SOFTLOCK_WORD_1; /* Write keys to clear soft lock bit */ SWT.SR.R = SOFTLOCK_WORD_2; /*lint -e{970} Lint does not seem handle typeof well */ SWT.CR.B = (typeof(SWT.CR.B)){.RIA = 1, .FRZ = 1, .WEN = 0, .MAP0 = 1}; #elif defined(CFG_MPC5777M) SWT.SR.R = SOFTLOCK_WORD_1; /* Write keys to clear soft lock bit */ SWT.SR.R = SOFTLOCK_WORD_2; SWT.CR.R = 0xE000010AuL; /* Access for all cores */ #elif defined(CFG_MPC5644A) SWT.SR.R = SOFTLOCK_WORD_1; /* Write keys to clear soft lock bit */ SWT.SR.R = SOFTLOCK_WORD_2; SWT.MCR.B = (typeof(SWT.MCR.B)){.RIA = 1, .FRZ = 1, .WEN = 0, .MAP0 = 1}; #elif defined(CFG_MPC5516) MCM.SWTCR.R = 0x0u; /* Disable the watchdog */ #else MCM.SWTCR.R = 0x0059u; #endif /*lint -restore */ } #if (WDG_VERSION_INFO_API == STD_ON) void Wdg_GetVersionInfo(Std_VersionInfoType* versioninfo) { /* @req SWS_Wdg_00174 */ VALIDATE(versioninfo != NULL, WDG_GET_VERSION_INFO_SERVICE_ID, WDG_E_PARAM_POINTER); versioninfo->vendorID = WDG_VENDOR_ID; versioninfo->moduleID = WDG_MODULE_ID; versioninfo->sw_major_version = WDG_SW_MAJOR_VERSION; versioninfo->sw_minor_version = WDG_SW_MINOR_VERSION; versioninfo->sw_patch_version = WDG_SW_PATCH_VERSION; } #endif void Wdg_Init (const Wdg_ConfigType* ConfigPtr) { /* @req SWS_Wdg_00001 */ /* @req SWS_Wdg_00100 */ /* @req SWS_Wdg_00101 */ /*@req SWS_Wdg_00089 */ VALIDATE(ConfigPtr != NULL, WDG_INIT_SERVICE_ID, WDG_E_PARAM_POINTER); /* @req SWS_Wdg_00010 */ VALIDATE(runTimeData.configWdgPtr == NULL, WDG_INIT_SERVICE_ID, WDG_E_DRIVER_STATE); /* Keep a pointer to the config. */ /* @req SWS_Wdg_00019 Always set regardless of DET or debugging support */ runTimeData.configWdgPtr = ConfigPtr; /* Ignoring return value, DET error set in Wdg_SetMode */ (void)Wdg_SetMode(ConfigPtr->Wdg_ModeConfig->Wdg_DefaultMode); }