1 /*! 2 \file gd32f4xx_wwdgt.h 3 \brief definitions for the WWDGT 4 5 \version 2016-08-15, V1.0.0, firmware for GD32F4xx 6 \version 2018-12-12, V2.0.0, firmware for GD32F4xx 7 \version 2020-09-30, V2.1.0, firmware for GD32F4xx 8 \version 2022-03-09, V3.0.0, firmware for GD32F4xx 9 */ 10 11 /* 12 Copyright (c) 2022, GigaDevice Semiconductor Inc. 13 14 Redistribution and use in source and binary forms, with or without modification, 15 are permitted provided that the following conditions are met: 16 17 1. Redistributions of source code must retain the above copyright notice, this 18 list of conditions and the following disclaimer. 19 2. Redistributions in binary form must reproduce the above copyright notice, 20 this list of conditions and the following disclaimer in the documentation 21 and/or other materials provided with the distribution. 22 3. Neither the name of the copyright holder nor the names of its contributors 23 may be used to endorse or promote products derived from this software without 24 specific prior written permission. 25 26 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 27 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 28 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 29 IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 30 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 31 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 32 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 33 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 35 OF SUCH DAMAGE. 36 */ 37 38 #ifndef GD32F4XX_WWDGT_H 39 #define GD32F4XX_WWDGT_H 40 41 #include "gd32f4xx.h" 42 43 /* WWDGT definitions */ 44 #define WWDGT WWDGT_BASE 45 46 /* registers definitions */ 47 #define WWDGT_CTL REG32((WWDGT) + 0x00U) /*!< WWDGT control register */ 48 #define WWDGT_CFG REG32((WWDGT) + 0x04U) /*!< WWDGT configuration register */ 49 #define WWDGT_STAT REG32((WWDGT) + 0x08U) /*!< 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 window watchdog timer configuration */ 73 void wwdgt_deinit(void); 74 /* start the window watchdog timer counter */ 75 void wwdgt_enable(void); 76 77 /* configure the window watchdog timer 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 /* check early wakeup interrupt state of WWDGT */ 83 FlagStatus wwdgt_flag_get(void); 84 /* clear early wakeup interrupt state of WWDGT */ 85 void wwdgt_flag_clear(void); 86 /* enable early wakeup interrupt of WWDGT */ 87 void wwdgt_interrupt_enable(void); 88 89 #endif /* GD32F4XX_WWDGT_H */ 90