/*FUNCTION**************************************************************** * * Function Name : WDOG_DRV_Init * Description : Initialize watchdog * This function is used to initialize the WDOG, after called, the WDOG * will run immediately according to the configure. * *END*********************************************************************/ void WDOG_DRV_Init(const wdog_user_config_t* userConfigPtr) { assert(userConfigPtr); wdog_common_config wdogCommonConfig; uint32_t coreClockHz, busClockHz; CLOCK_SYS_GetFreq(kCoreClock, &coreClockHz); CLOCK_SYS_GetFreq(kBusClock, &busClockHz); wdogWctInstructionCount = ((coreClockHz/busClockHz) << 8); /* WCT is 256 bus clock */ wdogCommonConfig.U = 0x0U; wdogCommonConfig.commonConfig.workInWaitModeEnable = (uint8_t)userConfigPtr->workInWaitModeEnable; wdogCommonConfig.commonConfig.workInDebugModeEnable = (uint8_t)userConfigPtr->workInDebugModeEnable; wdogCommonConfig.commonConfig.workInStopModeEnable = (uint8_t)userConfigPtr->workInStopModeEnable; wdogCommonConfig.commonConfig.clockSource = (uint8_t)userConfigPtr->clockSource; wdogCommonConfig.commonConfig.interruptEnable = (uint8_t)false; wdogCommonConfig.commonConfig.windowModeEnable = (uint8_t)(0 != userConfigPtr->windowValue); wdogCommonConfig.commonConfig.updateRegisterEnable = (uint8_t)userConfigPtr->updateRegisterEnable; wdogCommonConfig.commonConfig.wdogEnable = (uint8_t)(true); WDOG_DRV_Unlock(); WDOG_HAL_SetTimeoutValue(g_wdogBaseAddr[0], userConfigPtr->timeoutValue); WDOG_HAL_SetWindowValue(g_wdogBaseAddr[0], userConfigPtr->windowValue); WDOG_HAL_SetClockPrescalerValueMode(g_wdogBaseAddr[0], userConfigPtr->clockPrescalerValue); WDOG_HAL_ClearIntFlag(g_wdogBaseAddr[0]); WDOG_HAL_SetCommonConfig(g_wdogBaseAddr[0], wdogCommonConfig); WDOG_DRV_WaitWctClose(); }
/*FUNCTION********************************************************************** * * Function Name : WDOG_HAL_Init * Description : Initialize WDOG peripheral to workable state. * *END**************************************************************************/ void WDOG_HAL_Init(WDOG_Type * base) { wdog_work_mode_t initWorkmode; #if FSL_FEATURE_WDOG_HAS_WAITEN initWorkmode.kWdogEnableInWaitMode = true; #endif initWorkmode.kWdogEnableInStopMode = false; initWorkmode.kWdogEnableInDebugMode = false; wdog_config_t initConfig; initConfig.wdogEnable = true; initConfig.clkSrc = kWdogLpoClkSrc; initConfig.prescaler = kWdogClkPrescalerDivide1; initConfig.workMode = initWorkmode; initConfig.updateEnable = true; initConfig.intEnable = false; initConfig.winEnable = false; WDOG_HAL_Unlock(base); WDOG_HAL_SetTimeoutValue(base, 0x004C4B4C); WDOG_HAL_SetWindowValue(base, 0); WDOG_HAL_SetConfig(base, &initConfig); }