gd32e23x_fwdgt.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*!
  2. \file gd32e23x_fwdgt.h
  3. \brief definitions for the FWDGT
  4. \version 2019-02-19, V1.0.0, firmware for GD32E23x
  5. \version 2020-12-12, V1.1.0, firmware for GD32E23x
  6. */
  7. /*
  8. Copyright (c) 2020, GigaDevice Semiconductor Inc.
  9. All rights reserved.
  10. Redistribution and use in source and binary forms, with or without modification,
  11. are permitted provided that the following conditions are met:
  12. 1. Redistributions of source code must retain the above copyright notice, this
  13. list of conditions and the following disclaimer.
  14. 2. Redistributions in binary form must reproduce the above copyright notice,
  15. this list of conditions and the following disclaimer in the documentation
  16. and/or other materials provided with the distribution.
  17. 3. Neither the name of the copyright holder nor the names of its contributors
  18. may be used to endorse or promote products derived from this software without
  19. specific prior written permission.
  20. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  21. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  22. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  23. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  24. INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  25. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  26. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  27. WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  28. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  29. OF SUCH DAMAGE.
  30. */
  31. #ifndef GD32E23X_FWDGT_H
  32. #define GD32E23X_FWDGT_H
  33. #include "gd32e23x.h"
  34. /* FWDGT definitions */
  35. #define FWDGT FWDGT_BASE
  36. /* registers definitions */
  37. #define FWDGT_CTL REG32((FWDGT) + 0x00000000U) /*!< FWDGT control register */
  38. #define FWDGT_PSC REG32((FWDGT) + 0x00000004U) /*!< FWDGT prescaler register */
  39. #define FWDGT_RLD REG32((FWDGT) + 0x00000008U) /*!< FWDGT reload register */
  40. #define FWDGT_STAT REG32((FWDGT) + 0x0000000CU) /*!< FWDGT status register */
  41. #define FWDGT_WND REG32((FWDGT) + 0x00000010U) /*!< FWDGT window register */
  42. /* bits definitions */
  43. /* FWDGT_CTL */
  44. #define FWDGT_CTL_CMD BITS(0,15) /*!< FWDGT command value */
  45. /* FWDGT_PSC */
  46. #define FWDGT_PSC_PSC BITS(0,2) /*!< FWDGT prescaler divider value */
  47. /* FWDGT_RLD */
  48. #define FWDGT_RLD_RLD BITS(0,11) /*!< FWDGT counter reload value */
  49. /* FWDGT_STAT */
  50. #define FWDGT_STAT_PUD BIT(0) /*!< FWDGT prescaler divider value update */
  51. #define FWDGT_STAT_RUD BIT(1) /*!< FWDGT counter reload value update */
  52. #define FWDGT_STAT_WUD BIT(2) /*!< FWDGT counter window value update */
  53. /* FWDGT_WND */
  54. #define FWDGT_WND_WND BITS(0,11) /*!< FWDGT counter window value */
  55. /* constants definitions */
  56. /* FWDGT_PSC register value */
  57. #define PSC_PSC(regval) (BITS(0,2) & ((uint32_t)(regval) << 0U))
  58. #define FWDGT_PSC_DIV4 ((uint8_t)PSC_PSC(0)) /*!< FWDGT prescaler set to 4 */
  59. #define FWDGT_PSC_DIV8 ((uint8_t)PSC_PSC(1)) /*!< FWDGT prescaler set to 8 */
  60. #define FWDGT_PSC_DIV16 ((uint8_t)PSC_PSC(2)) /*!< FWDGT prescaler set to 16 */
  61. #define FWDGT_PSC_DIV32 ((uint8_t)PSC_PSC(3)) /*!< FWDGT prescaler set to 32 */
  62. #define FWDGT_PSC_DIV64 ((uint8_t)PSC_PSC(4)) /*!< FWDGT prescaler set to 64 */
  63. #define FWDGT_PSC_DIV128 ((uint8_t)PSC_PSC(5)) /*!< FWDGT prescaler set to 128 */
  64. #define FWDGT_PSC_DIV256 ((uint8_t)PSC_PSC(6)) /*!< FWDGT prescaler set to 256 */
  65. /* control value */
  66. #define FWDGT_WRITEACCESS_ENABLE ((uint16_t)0x00005555U) /*!< FWDGT_CTL bits write access enable value */
  67. #define FWDGT_WRITEACCESS_DISABLE ((uint16_t)0x00000000U) /*!< FWDGT_CTL bits write access disable value */
  68. #define FWDGT_KEY_RELOAD ((uint16_t)0x0000AAAAU) /*!< FWDGT_CTL bits fwdgt counter reload value */
  69. #define FWDGT_KEY_ENABLE ((uint16_t)0x0000CCCCU) /*!< FWDGT_CTL bits fwdgt counter enable value */
  70. /* FWDGT timeout value */
  71. #define FWDGT_WND_TIMEOUT ((uint32_t)0x000FFFFFU) /*!< FWDGT_WND register write operation state flag timeout */
  72. #define FWDGT_PSC_TIMEOUT ((uint32_t)0x000FFFFFU) /*!< FWDGT_PSC register write operation state flag timeout */
  73. #define FWDGT_RLD_TIMEOUT ((uint32_t)0x000FFFFFU) /*!< FWDGT_RLD register write operation state flag timeout */
  74. /* FWDGT flag definitions */
  75. #define FWDGT_FLAG_PUD FWDGT_STAT_PUD /*!< a write operation to FWDGT_PSC register is on going */
  76. #define FWDGT_FLAG_RUD FWDGT_STAT_RUD /*!< a write operation to FWDGT_RLD register is on going */
  77. #define FWDGT_FLAG_WUD FWDGT_STAT_WUD /*!< a write operation to FWDGT_WND register is on going */
  78. /* write value to FWDGT_RLD_RLD bit field */
  79. #define RLD_RLD(regval) (BITS(0,11) & ((uint32_t)(regval) << 0))
  80. /* write value to FWDGT_WND_WND bit field */
  81. #define WND_WND(regval) (BITS(0,11) & ((uint32_t)(regval) << 0U))
  82. /* function declarations */
  83. /* enable write access to FWDGT_PSC and FWDGT_RLD and FWDGT_WND */
  84. void fwdgt_write_enable(void);
  85. /* disable write access to FWDGT_PSC,FWDGT_RLD and FWDGT_WND */
  86. void fwdgt_write_disable(void);
  87. /* start the free watchdog timer counter */
  88. void fwdgt_enable(void);
  89. /* configure the free watchdog timer counter prescaler value */
  90. ErrStatus fwdgt_prescaler_value_config(uint16_t prescaler_value);
  91. /* configure the free watchdog timer counter reload value */
  92. ErrStatus fwdgt_reload_value_config(uint16_t reload_value);
  93. /* configure the free watchdog timer counter window value */
  94. ErrStatus fwdgt_window_value_config(uint16_t window_value);
  95. /* reload the counter of FWDGT */
  96. void fwdgt_counter_reload(void);
  97. /* configure counter reload value, and prescaler divider value */
  98. ErrStatus fwdgt_config(uint16_t reload_value, uint8_t prescaler_div);
  99. /* get flag state of FWDGT */
  100. FlagStatus fwdgt_flag_get(uint16_t flag);
  101. #endif /* GD32E23X_FWDGT_H */