am_hal_reset.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. //*****************************************************************************
  2. //
  3. // am_hal_reset.c
  4. //! @file
  5. //!
  6. //! @brief Hardware abstraction layer for the Reset Generator module.
  7. //!
  8. //! @addtogroup rstgen2 Reset Generator (RSTGEN)
  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. #include "am_mcu_apollo.h"
  48. //*****************************************************************************
  49. //
  50. //! @brief Configure the Reset Generator.
  51. //!
  52. //! @param ui32Config - Or together the supplied macros to enable
  53. //! configurations to obtain the desired reset generator settings.
  54. //!
  55. //! This function will set the reset generator's configuration register based on
  56. //! the user's desired settings listed in the supplied arugment.
  57. //!
  58. //! @return None.
  59. //
  60. //*****************************************************************************
  61. void
  62. am_hal_reset_init(uint32_t ui32Config)
  63. {
  64. //
  65. // Write the configuration to the reset generator
  66. //
  67. AM_REG(RSTGEN, CFG) = ui32Config;
  68. }
  69. //*****************************************************************************
  70. //
  71. //! @brief Issue a POR (Apollo's last stage interrupt).
  72. //!
  73. //! This function will issue a POR reset.
  74. //! The Apollo chip has numerous stages of reset. POR is the last and is also
  75. //! the reset invoked by the chip's reset pin, the watchdog timer, the AIRCR
  76. //! reset, and the SWD debugger requested interrupt.
  77. //!
  78. //! The Debug Access Port in the M4 is not cleared by this reset.
  79. //!
  80. //! @return None.
  81. //
  82. //*****************************************************************************
  83. void am_hal_reset_por(void)
  84. {
  85. //
  86. // Write the POR key to the software POR register.
  87. //
  88. AM_REG(RSTGEN, SWPOR) =
  89. AM_REG_RSTGEN_SWPOR_SWPORKEY(AM_REG_RSTGEN_SWPOR_SWPORKEY_KEYVALUE);
  90. }
  91. //*****************************************************************************
  92. //
  93. //! @brief Issue a POI (Apollo's second stage interrupt).
  94. //!
  95. //! This function will issue a POI reset.
  96. //! The Apollo chip has numerous stages of reset. POI is the second stage.
  97. //! A few modules are reset by POI that are not reset by POR, notably POI
  98. //! causes the shadow registers to be reloaded from the OTP. A full power
  99. //! cycle or POI should be used after writing new flash, debug or SRAM
  100. //! protection bits into the OTP for these protections to take effect.
  101. //!
  102. //! The Debug Access Port in the M4 is not cleared by this reset.
  103. //!
  104. //! @return None.
  105. //
  106. //*****************************************************************************
  107. void am_hal_reset_poi(void)
  108. {
  109. //
  110. // Write the POI key to the software POI register.
  111. //
  112. AM_REG(RSTGEN, SWPOI) =
  113. AM_REG_RSTGEN_SWPOI_SWPOIKEY(AM_REG_RSTGEN_SWPOI_SWPOIKEY_KEYVALUE);
  114. }
  115. //*****************************************************************************
  116. //
  117. //! @brief Retrieve the status bits from the reset generator.
  118. //!
  119. //! This function will get the status bits from the reset generator.
  120. //! These bits are sticky and show the accumulation of reset types that the
  121. //! Apollo chip has experienced since power on. One should clear these out
  122. //! after reading them.
  123. //!
  124. //! @return None.
  125. //
  126. //*****************************************************************************
  127. uint32_t am_hal_reset_status_get(void)
  128. {
  129. //
  130. // Retrieve the reset generator status bits
  131. //
  132. return AM_REG(RSTGEN, STAT);
  133. }
  134. //*****************************************************************************
  135. //
  136. //! @brief Clear ALL of the status bits in the reset generator.
  137. //!
  138. //! This function will clear all status bits in the reset generator status.
  139. //!
  140. //! @return None.
  141. //
  142. //*****************************************************************************
  143. void am_hal_reset_status_clear(void)
  144. {
  145. AM_REG(RSTGEN, CLRSTAT) = AM_REG_RSTGEN_CLRSTAT_CLRSTAT(1);
  146. }
  147. //*****************************************************************************
  148. //
  149. // End Doxygen group.
  150. //! @}
  151. //
  152. //*****************************************************************************