#include "bsp_iwdg.h"

#include "bsp_uart.h"
#include "log.h"

#undef LOG_ENABLE
#define LOG_ENABLE 1

#undef LOG_TAG
#define LOG_TAG "idwg"

// 32k rc
// div 0:4  | 1:8   | 2:16  | 3:32  |
//     4:64 | 5:128 | 6:256 | 7:512 |
// reload max 4095

void ch59x_iwdg_init(uint8_t div, uint16_t reload)
{
    R32_IWDG_KR  = 0x5555;
    R32_IWDG_CFG = (RB_PR & (div << 12)) | (RB_STOP_EN) | (reload & RB_RLR);
    R32_IWDG_KR  = 0xcccc; // enable
}

