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