gd32f30x_fwdgt.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*!
  2. \file gd32f30x_fwdgt.h
  3. \brief definitions for the FWDGT
  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_FWDGT_H
  33. #define GD32F30X_FWDGT_H
  34. #include "gd32f30x.h"
  35. /* FWDGT definitions */
  36. #define FWDGT FWDGT_BASE /*!< FWDGT base address */
  37. /* registers definitions */
  38. #define FWDGT_CTL REG32((FWDGT) + 0x00U) /*!< FWDGT control register */
  39. #define FWDGT_PSC REG32((FWDGT) + 0x04U) /*!< FWDGT prescaler register */
  40. #define FWDGT_RLD REG32((FWDGT) + 0x08U) /*!< FWDGT reload register */
  41. #define FWDGT_STAT REG32((FWDGT) + 0x0CU) /*!< FWDGT status 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. /* constants definitions */
  53. /* psc register value */
  54. #define PSC_PSC(regval) (BITS(0,2) & ((uint32_t)(regval) << 0))
  55. #define FWDGT_PSC_DIV4 ((uint8_t)PSC_PSC(0)) /*!< FWDGT prescaler set to 4 */
  56. #define FWDGT_PSC_DIV8 ((uint8_t)PSC_PSC(1)) /*!< FWDGT prescaler set to 8 */
  57. #define FWDGT_PSC_DIV16 ((uint8_t)PSC_PSC(2)) /*!< FWDGT prescaler set to 16 */
  58. #define FWDGT_PSC_DIV32 ((uint8_t)PSC_PSC(3)) /*!< FWDGT prescaler set to 32 */
  59. #define FWDGT_PSC_DIV64 ((uint8_t)PSC_PSC(4)) /*!< FWDGT prescaler set to 64 */
  60. #define FWDGT_PSC_DIV128 ((uint8_t)PSC_PSC(5)) /*!< FWDGT prescaler set to 128 */
  61. #define FWDGT_PSC_DIV256 ((uint8_t)PSC_PSC(6)) /*!< FWDGT prescaler set to 256 */
  62. /* control value */
  63. #define FWDGT_WRITEACCESS_ENABLE ((uint16_t)0x5555U) /*!< FWDGT_CTL bits write access enable value */
  64. #define FWDGT_WRITEACCESS_DISABLE ((uint16_t)0x0000U) /*!< FWDGT_CTL bits write access disable value */
  65. #define FWDGT_KEY_RELOAD ((uint16_t)0xAAAAU) /*!< FWDGT_CTL bits fwdgt counter reload value */
  66. #define FWDGT_KEY_ENABLE ((uint16_t)0xCCCCU) /*!< FWDGT_CTL bits fwdgt counter enable value */
  67. /* FWDGT timeout value */
  68. #define FWDGT_PSC_TIMEOUT ((uint32_t)0x000FFFFFU) /*!< FWDGT_PSC register write operation state flag timeout */
  69. #define FWDGT_RLD_TIMEOUT ((uint32_t)0x000FFFFFU) /*!< FWDGT_RLD register write operation state flag timeout */
  70. /* FWDGT flag definitions */
  71. #define FWDGT_FLAG_PUD FWDGT_STAT_PUD /*!< FWDGT prescaler divider value update flag */
  72. #define FWDGT_FLAG_RUD FWDGT_STAT_RUD /*!< FWDGT counter reload value update flag */
  73. /* write value to FWDGT_RLD_RLD bit field */
  74. #define RLD_RLD(regval) (BITS(0,11) & ((uint32_t)(regval) << 0))
  75. /* function declarations */
  76. /* enable write access to FWDGT_PSC and FWDGT_RLD */
  77. void fwdgt_write_enable(void);
  78. /* disable write access to FWDGT_PSC and FWDGT_RLD */
  79. void fwdgt_write_disable(void);
  80. /* start the free watchdog timer counter */
  81. void fwdgt_enable(void);
  82. /* configure the free watchdog timer counter prescaler value */
  83. ErrStatus fwdgt_prescaler_value_config(uint16_t prescaler_value);
  84. /* configure the free watchdog timer counter reload value */
  85. ErrStatus fwdgt_reload_value_config(uint16_t reload_value);
  86. /* reload the counter of FWDGT */
  87. void fwdgt_counter_reload(void);
  88. /* configure counter reload value, and prescaler divider value */
  89. ErrStatus fwdgt_config(uint16_t reload_value, uint8_t prescaler_div);
  90. /* get flag state of FWDGT */
  91. FlagStatus fwdgt_flag_get(uint16_t flag);
  92. #endif /* GD32F30X_FWDGT_H */