gd32f30x_wwdgt.h 4.7 KB

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