am_hal_wdt.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. //*****************************************************************************
  2. //
  3. // am_hal_wdt.h
  4. //! @file
  5. //!
  6. //! @brief Hardware abstraction layer for the Watchdog Timer module.
  7. //!
  8. //! @addtogroup wdt2 Watchdog Timer (WDT)
  9. //! @ingroup apollo2hal
  10. //! @{
  11. //
  12. //*****************************************************************************
  13. //*****************************************************************************
  14. //
  15. // Copyright (c) 2017, Ambiq Micro
  16. // All rights reserved.
  17. //
  18. // Redistribution and use in source and binary forms, with or without
  19. // modification, are permitted provided that the following conditions are met:
  20. //
  21. // 1. Redistributions of source code must retain the above copyright notice,
  22. // this list of conditions and the following disclaimer.
  23. //
  24. // 2. Redistributions in binary form must reproduce the above copyright
  25. // notice, this list of conditions and the following disclaimer in the
  26. // documentation and/or other materials provided with the distribution.
  27. //
  28. // 3. Neither the name of the copyright holder nor the names of its
  29. // contributors may be used to endorse or promote products derived from this
  30. // software without specific prior written permission.
  31. //
  32. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  33. // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  34. // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  35. // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  36. // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  37. // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  38. // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  39. // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  40. // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  41. // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  42. // POSSIBILITY OF SUCH DAMAGE.
  43. //
  44. // This is part of revision 1.2.11 of the AmbiqSuite Development Package.
  45. //
  46. //*****************************************************************************
  47. #ifndef AM_HAL_WDT_H
  48. #define AM_HAL_WDT_H
  49. #include <stdint.h>
  50. #include <stdbool.h>
  51. //*****************************************************************************
  52. //
  53. // Macro definitions
  54. //
  55. //*****************************************************************************
  56. //*****************************************************************************
  57. //
  58. //! @name WDT Clock Divider Selections.
  59. //! @brief Macro definitions for WDT clock frequencies.
  60. //!
  61. //! These macros may be used with the am_hal_wdt_config_t structure to set the
  62. //! clock frequency of the watch dog timer.
  63. //!
  64. //! @{
  65. //
  66. //*****************************************************************************
  67. #define AM_HAL_WDT_LFRC_CLK_DEFAULT AM_REG_WDT_CFG_CLKSEL_128HZ
  68. #define AM_HAL_WDT_LFRC_CLK_128HZ AM_REG_WDT_CFG_CLKSEL_128HZ
  69. #define AM_HAL_WDT_LFRC_CLK_16HZ AM_REG_WDT_CFG_CLKSEL_16HZ
  70. #define AM_HAL_WDT_LFRC_CLK_1HZ AM_REG_WDT_CFG_CLKSEL_1HZ
  71. #define AM_HAL_WDT_LFRC_CLK_1_16HZ AM_REG_WDT_CFG_CLKSEL_1_16HZ
  72. #define AM_HAL_WDT_LFRC_CLK_OFF AM_REG_WDT_CFG_CLKSEL_OFF
  73. //! @}
  74. //*****************************************************************************
  75. //
  76. //! @name WDT Enable Reset in the WDT Configuration.
  77. //! @brief Macro definitions for WDT Reset Enable.
  78. //!
  79. //! These macros may be used with the am_hal_wdt_config_t structure to enable
  80. //! the watch dog timer to generate resets to the chip.
  81. //!
  82. //! @{
  83. //
  84. //*****************************************************************************
  85. #define AM_HAL_WDT_ENABLE_RESET AM_REG_WDT_CFG_RESEN(1)
  86. #define AM_HAL_WDT_DISABLE_RESET AM_REG_WDT_CFG_RESEN(0)
  87. //! @}
  88. //*****************************************************************************
  89. //
  90. //! @name WDT Enable Interrupt Generation from the WDT Configuration.
  91. //! @brief Macro definitions for WDT Interrupt Enable.
  92. //!
  93. //! These macros may be used with the am_hal_wdt_config_t structure to enable
  94. //! the watch dog timer to generate generate WDT interrupts.
  95. //!
  96. //! @{
  97. //
  98. //*****************************************************************************
  99. #define AM_HAL_WDT_ENABLE_INTERRUPT AM_REG_WDT_CFG_INTEN(1)
  100. #define AM_HAL_WDT_DISABLE_INTERRUPT AM_REG_WDT_CFG_INTEN(0)
  101. //! @}
  102. //*****************************************************************************
  103. //
  104. //! @brief Watchdog timer configuration structure.
  105. //!
  106. //! This structure is made to be used with the am_hal_wdt_init() function. It
  107. //! describes the configuration of the watchdog timer.
  108. //
  109. //*****************************************************************************
  110. typedef struct
  111. {
  112. //! Configuration Values for watchdog timer
  113. //! event is generated.
  114. uint32_t ui32Config;
  115. //! Number of watchdog timer ticks allowed before a watchdog interrupt
  116. //! event is generated.
  117. uint16_t ui16InterruptCount;
  118. //! Number of watchdog timer ticks allowed before the watchdog will issue a
  119. //! system reset.
  120. uint16_t ui16ResetCount;
  121. }
  122. am_hal_wdt_config_t;
  123. //*****************************************************************************
  124. //
  125. //! @brief Restarts the watchdog timer ("Pets" the dog)
  126. //!
  127. //! This function restarts the watchdog timer from the beginning, preventing
  128. //! any interrupt or reset even from occuring until the next time the watchdog
  129. //! timer expires.
  130. //!
  131. //! @return None.
  132. //
  133. //*****************************************************************************
  134. #define am_hal_wdt_restart() \
  135. do \
  136. { \
  137. AM_REGn(WDT, 0, RSTRT) = AM_REG_WDT_RSTRT_RSTRT_KEYVALUE; \
  138. (void)AM_REGn(WDT, 0, RSTRT); \
  139. } \
  140. while(0)
  141. #ifdef __cplusplus
  142. extern "C"
  143. {
  144. #endif
  145. //*****************************************************************************
  146. //
  147. // External function definitions
  148. //
  149. //*****************************************************************************
  150. extern void am_hal_wdt_init(const am_hal_wdt_config_t *psConfig);
  151. extern void am_hal_wdt_start(void);
  152. extern void am_hal_wdt_halt(void);
  153. extern void am_hal_wdt_lock_and_start(void);
  154. extern void am_hal_wdt_int_enable(void);
  155. extern uint32_t am_hal_wdt_int_enable_get(void);
  156. extern void am_hal_wdt_int_disable(void);
  157. extern void am_hal_wdt_int_clear(void);
  158. extern void am_hal_wdt_int_set(void);
  159. extern uint32_t am_hal_wdt_int_status_get(bool bEnabledOnly);
  160. #ifdef __cplusplus
  161. }
  162. #endif
  163. #endif // AM_HAL_WDT_H
  164. //*****************************************************************************
  165. //
  166. // End Doxygen group.
  167. //! @}
  168. //
  169. //*****************************************************************************