52 lines
1.6 KiB
C
52 lines
1.6 KiB
C
/*******************************************************************************
|
|
**
|
|
**文 件 名:bsp_wdog.c
|
|
**创建日期:2015.10.15
|
|
**文件说明:
|
|
**修改记录:
|
|
**版 本:V1.0
|
|
**备 注:
|
|
*******************************************************************************/
|
|
#include <stddef.h>
|
|
#include "drv_wdog.h"
|
|
#include "kit_debug.h"
|
|
#include "stm32f4xx.h"
|
|
|
|
#define KR_KEY_Reload ((uint16_t)0xAAAA)
|
|
#define KR_KEY_Enable ((uint16_t)0xCCCC)
|
|
#define IWDG_Prescaler_64 ((uint8_t)0x04)
|
|
#define IWDG_WriteAccess_Enable ((uint16_t)0x5555)
|
|
#define IWDG_WriteAccess_Disable ((uint16_t)0x0000)
|
|
|
|
/*****************************************************************************
|
|
* 初始化独立看门狗
|
|
* prer:分频数:0~7(只有低 3 位有效!)
|
|
* 分频因子=4*2^prer.但最大值只能是 256!
|
|
* rlr:重装载寄存器值:低 11 位有效.
|
|
* 时间计算(大概):Tout=((4*2^prer)*rlr)/40 (ms).
|
|
******************************************************************************/
|
|
/* KR register bit mask */
|
|
|
|
//每个tick时间 1000/(40000/64) = 1.6s
|
|
void drv_wdog_init(uint16_t idog_tick)
|
|
{
|
|
//使能对IWDG->PR和IWDG->RLR的写
|
|
IWDG->KR = IWDG_WriteAccess_Enable;
|
|
|
|
//40kHz/64= 625Hz
|
|
IWDG->PR = IWDG_Prescaler_64;
|
|
if(idog_tick > 4095)
|
|
idog_tick = 4095;
|
|
IWDG->RLR = idog_tick;
|
|
//必须reload 否则时间不对
|
|
IWDG->KR = KR_KEY_Reload;
|
|
IWDG->KR = KR_KEY_Enable;
|
|
IWDG->KR = IWDG_WriteAccess_Disable;
|
|
}
|
|
|
|
void drv_wdog_feed(void)
|
|
{
|
|
IWDG->KR = KR_KEY_Reload;
|
|
}
|
|
|