bs_bcu_app/drv/drv_wdog.c

53 lines
1.6 KiB
C
Raw Permalink Normal View History

2024-11-07 17:24:19 +08:00
/*******************************************************************************
**
** :bsp_wdog.c
**:2015.10.15
**:
**:
** :V1.0
** :
*******************************************************************************/
#include <stddef.h>
#include "drv_wdog.h"
#include "kit_debug.h"
#include "stm32f4xx.h"
#include "bsp_malloc.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;
}