#include "../include/hal_lksmcu_iwdg.h"
#include "../include/hal_lksmcu_reg.h"
#include "hal_lks32mc09x.h"
/**
 * @brief 模块复位
 * @param iwdg 看门狗模块
 */
void HAL_IWDG_Reset(HAL_IWDG_x iwdg)
{
    HAL_IWDG_Disable(iwdg);
}

/**
 * @brief 模块打开
 * @param iwdg 看门狗模块
 */
void HAL_IWDG_Enable(HAL_IWDG_x iwdg)
{
    HAL_REG_SYS_UNLOCK();
    HAL_REG_SET(HAL_SYS[0]->SFT_RST, BIT0);
    HAL_REG_SYS_LOCK();
}

/**
 * @brief 模块关闭
 * @param iwdg 看门狗模块
 */
void HAL_IWDG_Disable(HAL_IWDG_x iwdg)
{
    HAL_REG_SYS_UNLOCK();
    HAL_REG_RESET(HAL_SYS[0]->CLK_FEN, BIT0);
    HAL_REG_SYS_LOCK();
}

/**
 * @brief 设置看门狗超时复位时间
 * @param iwdg 看门狗模块
 * @param ms 超时复位时间，单位mS
 */
void HAL_IWDG_SetResetTimemS(HAL_IWDG_x iwdg, int32_t ms)
{
    uint32_t th;
    th = ((uint32_t)(64 * ms + 0x800) & 0x1ff000);
    HAL_REG_WRITE(HAL_IWDG[0]->RTH, th);
}
/**
 * @brief 设置看门狗唤醒时间
 * @param iwdg 看门狗模块
 * @param ms 唤醒时间，单位mS
 */
void HAL_IWDG_SetWeakTimemS(HAL_IWDG_x iwdg, int32_t ms)
{
}

/**
 * @brief 喂狗
 * @param iwdg 看门狗模块
 */
void HAL_IWDG_Feed(HAL_IWDG_x iwdg)
{
    HAL_REG_WRITE(HAL_IWDG[0]->PSW, 0xA6B4);
    HAL_REG_WRITE(HAL_IWDG[0]->CLR, 0x798D);
}
