1 /** mbed Microcontroller Library 2 ****************************************************************************** 3 * @file wdt_api.c 4 * @author 5 * @version V1.0.0 6 * @date 2016-08-01 7 * @brief This file provides mbed API for WDG. 8 ****************************************************************************** 9 * @attention 10 * 11 * This module is a confidential and proprietary property of RealTek and 12 * possession or use of this module requires written permission of RealTek. 13 * 14 * Copyright(c) 2016, Realtek Semiconductor Corporation. All rights reserved. 15 ****************************************************************************** 16 */ 17 18 #include "objects.h" 19 #include "ameba_soc.h" 20 #include "wdt_api.h" 21 #include "cmsis.h" 22 23 /** @addtogroup AmebaD_Mbed_API 24 * @{ 25 */ 26 27 /** @defgroup MBED_WDG 28 * @brief MBED_WDG driver modules. 29 * @{ 30 */ 31 32 /** @defgroup MBED_WDG_Exported_Functions MBED_WDG Exported Functions 33 * @{ 34 */ 35 36 /** 37 * @brief Initializes the watch dog, include time setting, mode register 38 * @param timeout_ms: the watch-dog timer timeout value, in ms. 39 * default action of timeout is to reset the whole system. 40 * @retval none 41 */ watchdog_init(uint32_t timeout_ms)42void watchdog_init(uint32_t timeout_ms) 43 { 44 WDG_InitTypeDef WDG_InitStruct; 45 u32 CountProcess; 46 u32 DivFacProcess; 47 48 WDG_Scalar(timeout_ms, &CountProcess, &DivFacProcess); 49 50 WDG_InitStruct.CountProcess = CountProcess; 51 WDG_InitStruct.DivFacProcess = DivFacProcess; 52 53 WDG_Init(&WDG_InitStruct); 54 } 55 56 /** 57 * @brief Start the watchdog counting 58 * @param None 59 * @retval none 60 */ watchdog_start(void)61void watchdog_start(void) 62 { 63 WDG_Cmd(ENABLE); 64 } 65 66 /** 67 * @brief Stop the watchdog counting 68 * @param None 69 * @retval none 70 */ watchdog_stop(void)71void watchdog_stop(void) 72 { 73 WDG_Cmd(DISABLE); 74 } 75 76 /** 77 * @brief Refresh the watchdog counting to prevent WDT timeout 78 * @param None 79 * @retval none 80 */ watchdog_refresh(void)81void watchdog_refresh(void) 82 { 83 WDG_Refresh(); 84 } 85 86 /** 87 * @brief Switch the watchdog timer to interrupt mode and 88 * register a watchdog timer timeout interrupt handler. 89 * The interrupt handler will be called when the watch-dog 90 * timer is timeout. 91 * @param handler: the callback function for WDT timeout interrupt. 92 * @param id: the parameter for the callback function 93 * @retval none 94 */ watchdog_irq_init(wdt_irq_handler handler,uint32_t id)95void watchdog_irq_init(wdt_irq_handler handler, uint32_t id) 96 { 97 WDG_IrqInit((VOID*)handler, (u32)id); 98 } 99 /** 100 * @} 101 */ 102 103 /** 104 * @} 105 */ 106 107 /** 108 * @} 109 */