1 #ifndef _BFLB_WDG_H 2 #define _BFLB_WDG_H 3 4 #include "bflb_core.h" 5 6 /** @addtogroup LHAL 7 * @{ 8 */ 9 10 /** @addtogroup WDG 11 * @{ 12 */ 13 14 #if !defined(BL702L) 15 #define WDG_CLKSRC_BCLK 0 16 #endif 17 #define WDG_CLKSRC_32K 1 18 #define WDG_CLKSRC_1K 2 19 #define WDG_CLKSRC_XTAL 3 20 #if !defined(BL702) && !defined(BL602) 21 #define WDG_CLKSRC_GPIO 4 22 #endif 23 #define WDG_CLKSRC_NO 5 24 25 /** @defgroup WDG_MODE Watch-dog reset/interrupt mode definition 26 * @{ 27 */ 28 #define WDG_MODE_INTERRUPT 0 29 #define WDG_MODE_RESET 1 30 /** 31 * @} 32 */ 33 34 /** 35 * @brief WDG configuration structure 36 * 37 * @param clock_source Wdg clock source, use BFLB_SYSTEM_* definition 38 * @param clock_div Wdg clock divison value, from 0 to 255 39 * @param comp_val Wdg compare value 40 * @param mode Wdg reset/interrupt mode 41 */ 42 struct bflb_wdg_config_s { 43 uint8_t clock_source; 44 uint8_t clock_div; 45 uint16_t comp_val; 46 uint8_t mode; 47 }; 48 49 #ifdef __cplusplus 50 extern "C" { 51 #endif 52 53 /** 54 * @brief Initialize watchdog. 55 * 56 * @param [in] dev device handle 57 * @param [in] config pointer to save watchdog config 58 */ 59 void bflb_wdg_init(struct bflb_device_s *dev, const struct bflb_wdg_config_s *config); 60 61 /** 62 * @brief Start watchdog. 63 * 64 * @param [in] dev device handle 65 */ 66 void bflb_wdg_start(struct bflb_device_s *dev); 67 68 /** 69 * @brief Stop watchdog. 70 * 71 * @param [in] dev device handle 72 */ 73 void bflb_wdg_stop(struct bflb_device_s *dev); 74 75 /** 76 * @brief Get watchdog counter value. 77 * 78 * @param [in] dev device handle 79 * @return counter value 80 */ 81 uint16_t bflb_wdg_get_countervalue(struct bflb_device_s *dev); 82 83 /** 84 * @brief Set watchdog counter value. 85 * 86 * @param [in] dev device handle 87 * @param [in] counter value 88 */ 89 void bflb_wdg_set_countervalue(struct bflb_device_s *dev, uint16_t value); 90 91 /** 92 * @brief Reset watchdog counter value. 93 * 94 * @param [in] dev device handle 95 */ 96 void bflb_wdg_reset_countervalue(struct bflb_device_s *dev); 97 98 /** 99 * @brief Clear watchdog compare interrupt status. 100 * 101 * @param [in] dev device handle 102 */ 103 void bflb_wdg_compint_clear(struct bflb_device_s *dev); 104 105 #ifdef __cplusplus 106 } 107 #endif 108 109 /** 110 * @} 111 */ 112 113 /** 114 * @} 115 */ 116 117 #endif 118