1 /**************************************************************************//**
2 * @file wdt.c
3 * @version V3.00
4 * @brief Watchdog Timer(WDT) driver source file
5 *
6 * @copyright SPDX-License-Identifier: Apache-2.0
7 * @copyright Copyright (C) 2020 Nuvoton Technology Corp. All rights reserved.
8 *****************************************************************************/
9 #include "NuMicro.h"
10
11
12 /** @addtogroup Standard_Driver Standard Driver
13 @{
14 */
15
16 /** @addtogroup WDT_Driver WDT Driver
17 @{
18 */
19
20 /** @addtogroup WDT_EXPORTED_FUNCTIONS WDT Exported Functions
21 @{
22 */
23
24 /**
25 * @brief Initialize WDT and start counting
26 *
27 * @param[in] u32TimeoutInterval Time-out interval period of WDT module. Valid values are:
28 * - \ref WDT_TIMEOUT_2POW4
29 * - \ref WDT_TIMEOUT_2POW6
30 * - \ref WDT_TIMEOUT_2POW8
31 * - \ref WDT_TIMEOUT_2POW10
32 * - \ref WDT_TIMEOUT_2POW12
33 * - \ref WDT_TIMEOUT_2POW14
34 * - \ref WDT_TIMEOUT_2POW16
35 * - \ref WDT_TIMEOUT_2POW18
36 * - \ref WDT_TIMEOUT_2POW20
37 * @param[in] u32ResetDelay Configure WDT time-out reset delay period. Valid values are:
38 * - \ref WDT_RESET_DELAY_1026CLK
39 * - \ref WDT_RESET_DELAY_130CLK
40 * - \ref WDT_RESET_DELAY_18CLK
41 * - \ref WDT_RESET_DELAY_3CLK
42 * @param[in] u32EnableReset Enable WDT time-out reset system function. Valid values are TRUE and FALSE.
43 * @param[in] u32EnableWakeup Enable WDT time-out wake-up system function. Valid values are TRUE and FALSE.
44 *
45 * @return None
46 *
47 * @details This function makes WDT module start counting with different time-out interval, reset delay period and choose to \n
48 * enable or disable WDT time-out reset system or wake-up system.
49 * @note Please make sure that Register Write-Protection Function has been disabled before using this function.
50 */
WDT_Open(uint32_t u32TimeoutInterval,uint32_t u32ResetDelay,uint32_t u32EnableReset,uint32_t u32EnableWakeup)51 void WDT_Open(uint32_t u32TimeoutInterval,
52 uint32_t u32ResetDelay,
53 uint32_t u32EnableReset,
54 uint32_t u32EnableWakeup)
55 {
56 WDT->ALTCTL = u32ResetDelay;
57
58 WDT->CTL = u32TimeoutInterval | WDT_CTL_WDTEN_Msk |
59 (u32EnableReset << WDT_CTL_RSTEN_Pos) |
60 (u32EnableWakeup << WDT_CTL_WKEN_Pos);
61
62 while((WDT->CTL & WDT_CTL_SYNC_Msk) == WDT_CTL_SYNC_Msk) {} /* Wait enable WDTEN bit completed, it needs 2 * WDT_CLK. */
63 }
64
65 /**@}*/ /* end of group WDT_EXPORTED_FUNCTIONS */
66
67 /**@}*/ /* end of group WDT_Driver */
68
69 /**@}*/ /* end of group Standard_Driver */
70