
#include "sr_wtd.h"


#ifdef SR_USE_IWDG

#include "n32l40x_iwdg.h"

void BspIwdgInit(uint32_t timeout)
{
    /* IWDG timeout = (RELOAD_VALUE ) * Prescaler / LSI  */
    /* Enable write access to IWDG_PR and IWDG_RLR registers */
    IWDG_WriteConfig(IWDG_WRITE_ENABLE);
    /* IWDG counter clock: LSI/32 */
    IWDG_SetPrescalerDiv(IWDG_PRESCALER_DIV32);
    /* Set counter reload value to obtain 250ms IWDG TimeOut.
       Counter Reload Value = (timeout/1000)*LSI/Prescaler
                            = (timeout/1000)*LSI/Prescaler
                            = timeout*LSI/(Prescaler*1000))
                            = timeout*SOC_LSI_FREQ/32000*/
                                                
    IWDG_CntReload(timeout*SOC_LSI_FREQ/32000);
    /* Reload IWDG counter */
    IWDG_ReloadKey();
    /* Enable IWDG (the LSI oscillator will be enabled by hardware) */
    IWDG_Enable();
}

#if  0
void BspIwdgFeed(void)
{
    IWDG_ReloadKey();
}
#endif

#endif  /* SR_USE_IWDG*/