1 /*!
2     \file    gd32e50x_wwdgt.h
3     \brief   definitions for the WWDGT
4 
5     \version 2020-03-10, V1.0.0, firmware for GD32E50x
6     \version 2020-08-26, V1.1.0, firmware for GD32E50x
7     \version 2021-03-23, V1.2.0, firmware for GD32E50x
8 */
9 
10 /*
11     Copyright (c) 2021, GigaDevice Semiconductor Inc.
12 
13     Redistribution and use in source and binary forms, with or without modification,
14 are permitted provided that the following conditions are met:
15 
16     1. Redistributions of source code must retain the above copyright notice, this
17        list of conditions and the following disclaimer.
18     2. Redistributions in binary form must reproduce the above copyright notice,
19        this list of conditions and the following disclaimer in the documentation
20        and/or other materials provided with the distribution.
21     3. Neither the name of the copyright holder nor the names of its contributors
22        may be used to endorse or promote products derived from this software without
23        specific prior written permission.
24 
25     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
27 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28 IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
29 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
32 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
34 OF SUCH DAMAGE.
35 */
36 
37 
38 #ifndef GD32E50X_WWDGT_H
39 #define GD32E50X_WWDGT_H
40 
41 #include "gd32e50x.h"
42 
43 /* WWDGT definitions */
44 #define WWDGT                       WWDGT_BASE
45 
46 /* registers definitions */
47 #define WWDGT_CTL                   REG32((WWDGT) + 0x00000000U)              /*!< WWDGT control register */
48 #define WWDGT_CFG                   REG32((WWDGT) + 0x00000004U)              /*!< WWDGT configuration register */
49 #define WWDGT_STAT                  REG32((WWDGT) + 0x00000008U)              /*!< WWDGT status register */
50 
51 /* bits definitions */
52 /* WWDGT_CTL */
53 #define WWDGT_CTL_CNT               BITS(0,6)                                 /*!< WWDGT counter value */
54 #define WWDGT_CTL_WDGTEN            BIT(7)                                    /*!< WWDGT counter enable */
55 
56 /* WWDGT_CFG */
57 #define WWDGT_CFG_WIN               BITS(0,6)                                 /*!< WWDGT counter window value */
58 #define WWDGT_CFG_PSC               BITS(7,8)                                 /*!< WWDGT prescaler divider value */
59 #define WWDGT_CFG_EWIE              BIT(9)                                    /*!< early wakeup interrupt enable */
60 
61 /* WWDGT_STAT */
62 #define WWDGT_STAT_EWIF             BIT(0)                                    /*!< early wakeup interrupt flag */
63 
64 /* constants definitions */
65 #define CFG_PSC(regval)             (BITS(7,8) & ((uint32_t)(regval) << 7))   /*!< write value to WWDGT_CFG_PSC bit field */
66 #define WWDGT_CFG_PSC_DIV1          CFG_PSC(0)                                /*!< the time base of WWDGT = (PCLK1/4096)/1 */
67 #define WWDGT_CFG_PSC_DIV2          CFG_PSC(1)                                /*!< the time base of WWDGT = (PCLK1/4096)/2 */
68 #define WWDGT_CFG_PSC_DIV4          CFG_PSC(2)                                /*!< the time base of WWDGT = (PCLK1/4096)/4 */
69 #define WWDGT_CFG_PSC_DIV8          CFG_PSC(3)                                /*!< the time base of WWDGT = (PCLK1/4096)/8 */
70 
71 /* function declarations */
72 /* reset the WWDGT configuration */
73 void wwdgt_deinit(void);
74 /* start the WWDGT counter */
75 void wwdgt_enable(void);
76 
77 /* configure the WWDGT counter value */
78 void wwdgt_counter_update(uint16_t counter_value);
79 /* configure counter value, window value, and prescaler divider value */
80 void wwdgt_config(uint16_t counter, uint16_t window, uint32_t prescaler);
81 
82 /* enable early wakeup interrupt of WWDGT */
83 void wwdgt_interrupt_enable(void);
84 /* check early wakeup interrupt state of WWDGT */
85 FlagStatus wwdgt_flag_get(void);
86 /* clear early wakeup interrupt state of WWDGT */
87 void wwdgt_flag_clear(void);
88 
89 #endif /* GD32E50X_WWDGT_H */
90