1 /**************************************************************************//**
2  * @file     wwdt.h
3  * @version  V3.00
4  * @brief    M480 series WWDT driver header file
5  *
6  * SPDX-License-Identifier: Apache-2.0
7  * @copyright (C) 2016-2020 Nuvoton Technology Corp. All rights reserved.
8  *****************************************************************************/
9 #ifndef __WWDT_H__
10 #define __WWDT_H__
11 
12 #ifdef __cplusplus
13 extern "C"
14 {
15 #endif
16 
17 
18 /** @addtogroup Standard_Driver Standard Driver
19   @{
20 */
21 
22 /** @addtogroup WWDT_Driver WWDT Driver
23   @{
24 */
25 
26 /** @addtogroup WWDT_EXPORTED_CONSTANTS WWDT Exported Constants
27   @{
28 */
29 /*---------------------------------------------------------------------------------------------------------*/
30 /*  WWDT Prescale Period Constant Definitions                                                              */
31 /*---------------------------------------------------------------------------------------------------------*/
32 #define WWDT_PRESCALER_1        (0 << WWDT_CTL_PSCSEL_Pos)  /*!< Select max time-out period to 1 * (64*WWDT_CLK) \hideinitializer */
33 #define WWDT_PRESCALER_2        (1 << WWDT_CTL_PSCSEL_Pos)  /*!< Select max time-out period to 2 * (64*WWDT_CLK) \hideinitializer */
34 #define WWDT_PRESCALER_4        (2 << WWDT_CTL_PSCSEL_Pos)  /*!< Select max time-out period to 4 * (64*WWDT_CLK) \hideinitializer */
35 #define WWDT_PRESCALER_8        (3 << WWDT_CTL_PSCSEL_Pos)  /*!< Select max time-out period to 8 * (64*WWDT_CLK) \hideinitializer */
36 #define WWDT_PRESCALER_16       (4 << WWDT_CTL_PSCSEL_Pos)  /*!< Select max time-out period to 16 * (64*WWDT_CLK) \hideinitializer */
37 #define WWDT_PRESCALER_32       (5 << WWDT_CTL_PSCSEL_Pos)  /*!< Select max time-out period to 32 * (64*WWDT_CLK) \hideinitializer */
38 #define WWDT_PRESCALER_64       (6 << WWDT_CTL_PSCSEL_Pos)  /*!< Select max time-out period to 64 * (64*WWDT_CLK) \hideinitializer */
39 #define WWDT_PRESCALER_128      (7 << WWDT_CTL_PSCSEL_Pos)  /*!< Select max time-out period to 128 * (64*WWDT_CLK) \hideinitializer */
40 #define WWDT_PRESCALER_192      (8 << WWDT_CTL_PSCSEL_Pos)  /*!< Select max time-out period to 192 * (64*WWDT_CLK) \hideinitializer */
41 #define WWDT_PRESCALER_256      (9 << WWDT_CTL_PSCSEL_Pos)  /*!< Select max time-out period to 256 * (64*WWDT_CLK) \hideinitializer */
42 #define WWDT_PRESCALER_384      (10 << WWDT_CTL_PSCSEL_Pos) /*!< Select max time-out period to 384 * (64*WWDT_CLK) \hideinitializer */
43 #define WWDT_PRESCALER_512      (11 << WWDT_CTL_PSCSEL_Pos) /*!< Select max time-out period to 512 * (64*WWDT_CLK) \hideinitializer */
44 #define WWDT_PRESCALER_768      (12 << WWDT_CTL_PSCSEL_Pos) /*!< Select max time-out period to 768 * (64*WWDT_CLK) \hideinitializer */
45 #define WWDT_PRESCALER_1024     (13 << WWDT_CTL_PSCSEL_Pos) /*!< Select max time-out period to 1024 * (64*WWDT_CLK) \hideinitializer */
46 #define WWDT_PRESCALER_1536     (14 << WWDT_CTL_PSCSEL_Pos) /*!< Select max time-out period to 1536 * (64*WWDT_CLK) \hideinitializer */
47 #define WWDT_PRESCALER_2048     (15 << WWDT_CTL_PSCSEL_Pos) /*!< Select max time-out period to 2048 * (64*WWDT_CLK) \hideinitializer */
48 
49 /*---------------------------------------------------------------------------------------------------------*/
50 /*  WWDT Reload Counter Keyword Constant Definitions                                                       */
51 /*---------------------------------------------------------------------------------------------------------*/
52 #define WWDT_RELOAD_WORD        (0x00005AA5)                /*!< Fill this value to WWDT_RLDCNT register to reload WWDT counter \hideinitializer */
53 
54 /*@}*/ /* end of group WWDT_EXPORTED_CONSTANTS */
55 
56 
57 /** @addtogroup WWDT_EXPORTED_FUNCTIONS WWDT Exported Functions
58   @{
59 */
60 
61 /**
62   * @brief      Clear WWDT Reset System Flag
63   *
64   * @param      None
65   *
66   * @return     None
67   *
68   * @details    This macro is used to clear WWDT time-out reset system flag.
69   * \hideinitializer
70   */
71 #define WWDT_CLEAR_RESET_FLAG()     (WWDT->STATUS = WWDT_STATUS_WWDTRF_Msk)
72 
73 /**
74   * @brief      Clear WWDT Compared Match Interrupt Flag
75   *
76   * @param      None
77   *
78   * @return     None
79   *
80   * @details    This macro is used to clear WWDT compared match interrupt flag.
81   * \hideinitializer
82   */
83 #define WWDT_CLEAR_INT_FLAG()       (WWDT->STATUS = WWDT_STATUS_WWDTIF_Msk)
84 
85 /**
86   * @brief      Get WWDT Reset System Flag
87   *
88   * @param      None
89   *
90   * @retval     0   WWDT time-out reset system did not occur
91   * @retval     1   WWDT time-out reset system occurred
92   *
93   * @details    This macro is used to indicate system has been reset by WWDT time-out reset or not.
94   * \hideinitializer
95   */
96 #define WWDT_GET_RESET_FLAG()       ((WWDT->STATUS & WWDT_STATUS_WWDTRF_Msk)? 1 : 0)
97 
98 /**
99   * @brief      Get WWDT Compared Match Interrupt Flag
100   *
101   * @param      None
102   *
103   * @retval     0   WWDT compare match interrupt did not occur
104   * @retval     1   WWDT compare match interrupt occurred
105   *
106   * @details    This macro is used to indicate WWDT counter value matches CMPDAT value or not.
107   * \hideinitializer
108   */
109 #define WWDT_GET_INT_FLAG()         ((WWDT->STATUS & WWDT_STATUS_WWDTIF_Msk)? 1 : 0)
110 
111 /**
112   * @brief      Get WWDT Counter
113   *
114   * @param      None
115   *
116   * @return     WWDT Counter Value
117   *
118   * @details    This macro reflects the current WWDT counter value.
119   * \hideinitializer
120   */
121 #define WWDT_GET_COUNTER()          (WWDT->CNT)
122 
123 /**
124   * @brief      Reload WWDT Counter
125   *
126   * @param      None
127   *
128   * @return     None
129   *
130   * @details    This macro is used to reload the WWDT counter value to 0x3F.
131   * @note       User can only write WWDT_RLDCNT register to reload WWDT counter value when current WWDT counter value \n
132   *             between 0 and CMPDAT value. If user writes WWDT_RLDCNT when current WWDT counter value is larger than CMPDAT, \n
133   *             WWDT reset signal will generate immediately to reset system.
134   * \hideinitializer
135   */
136 #define WWDT_RELOAD_COUNTER()       (WWDT->RLDCNT = WWDT_RELOAD_WORD)
137 
138 void WWDT_Open(uint32_t u32PreScale, uint32_t u32CmpValue, uint32_t u32EnableInt);
139 
140 /*@}*/ /* end of group WWDT_EXPORTED_FUNCTIONS */
141 
142 /*@}*/ /* end of group WWDT_Driver */
143 
144 /*@}*/ /* end of group Standard_Driver */
145 
146 #ifdef __cplusplus
147 }
148 #endif
149 
150 #endif /* __WWDT_H__ */
151 
152 /*** (C) COPYRIGHT 2016 Nuvoton Technology Corp. ***/
153