/**
 * \file    drv_wdt.h
 * \brief   watchdog timer definition
 *
 * \par     Copyright (c) 2018 UWE Technologies Corp., Ltd. All Rights Reserved.
 * \author  James
 * \date    2018-03-17
 * \version 
 * 
 * \history 
 *  Date        Note
 *  2018-03-17  Original Creation
 * 
 */
 
#ifndef __DRV_WDT_H_
#define __DRV_WDT_H_


#include "types.h"
#include "drv_reg_intf.h"
#include "reg_def_wdt.h"
#include "drv_chip.h"

#define DRV_WDT_MAX_TIMEOUT     ((double)0xFFFFFFFFUL/drv_chip_freq_get()*1000)

extern volatile u8_t g_wdt_rst_record;

/** \brief Generate the service sequence to reload the timer.
 *
 */
void drv_wdt_feed(void);

/** \brief Configure the watch dog timer and start it
 *
 * \param timeout   Watch dog timer time out value (unit is millisecond),
 *                  the maximal timeout value is 129,453 at 33.1776MHz 
 * \param enable    Enable watch dog.
 */
void drv_wdt_init(u32_t timeout, bool_t enable);

/** \brief Get the watch dog timeout value
 *
 * \return          Watch dog timer time out value (unit is millisecond).
 */
u32_t drv_wdt_timeout_get(void);

/** \brief Get the watch dog enable status
 *
 * \return          0: watch dog disabled, 1: watch dog enabled.
 */
#define drv_wdt_enable_get()    (DRV_REG_FIELD_GET(WDT_CTRL_REG,WDT_ENA))

/** \brief Get the watch dog reset flag
 *
 * \return          0: without watch dog timeout, 1: Indicate the watch dog timer timeout occurred.
 */
//#define drv_wdt_reset_flag_get()    (DRV_REG_FIELD_GET(WDT_CTRL_REG,WDT_RST_RECORD))
#define drv_wdt_reset_flag_get()        (g_wdt_rst_record)


#endif /* #ifndef __DRV_WDT_H_ */

