stm32_ota/ABM开发板(BOOT源码)/BOOTV2.1/SYSTEM/WATCHDOG/watchdog.c
2024-12-17 20:03:43 +08:00

39 lines
1.7 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "watchdog.h"
#include "stm32f10x_iwdg.h"
/********************************************************************************
* @file watchdog.c
* @author 晏诚科技 Mr.Wang
* @version V1.0.0
* @date 11-Dec-2018
* @brief 提供硬件看门狗相关驱动
******************************************************************************
* @驱动功能:
* 1、STM32硬件看门狗初始化
* 2、喂狗接口
*******************************************************************************/
/**************************************************************************************************
* 名 称: void Watchdog_Init( void )
* 功能说明: 看门狗功能块初始化
* 原理说明: STM32自带硬件看门狗程序定时调用 void Watchdog_Feed( void )函数喂狗放防止程序跑飞
*************************************************************************************************/
void Watchdog_Init( void )
{
IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);// 使能对寄存器IWDG_PR和IWDG_RLR的写操作*/
IWDG_SetPrescaler(IWDG_Prescaler_256); //看门狗时钟分频,40K/256=156HZ(6.4ms)
IWDG_SetReload(781); //喂狗时间 5s/6.4MS=781 .注意不能大于0xfff This parameter must be a number between 0 and 0x0FFF.
IWDG_ReloadCounter(); //照IWDG重装载寄存器的值重装载IWDG计数器
IWDG_Enable(); //使能IWDG
}
/**************************************************************************************************
* 名 称: void Watchdog_Feed( void )
* 功能说明: 喂狗函数
*************************************************************************************************/
void Watchdog_Feed( void )
{
IWDG_ReloadCounter(); //reload重新装载计数器
}