sama_rstc.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /*
  2. ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. /**
  14. * @file SAMA5D2x/sama_rstc.h
  15. * @brief SAMA RSTC helper driver header.
  16. *
  17. * @addtogroup SAMA5D2x_RSTC
  18. * @{
  19. */
  20. #ifndef _SAMA_RSTC_
  21. #define _SAMA_RSTC_
  22. /*===========================================================================*/
  23. /* Driver constants. */
  24. /*===========================================================================*/
  25. /**
  26. * @name RESET SOURCE MACROS
  27. * @{
  28. */
  29. /**
  30. * @brief No access allowed.
  31. */
  32. #define RSTC_GENERAL 0x0U
  33. /**
  34. * @brief Only write access allowed.
  35. */
  36. #define RSTC_WKUP 0x1U
  37. /**
  38. * @brief Only read access allowed.
  39. */
  40. #define RSTC_WDT 0x2U
  41. /**
  42. * @brief Read and Write access allowed.
  43. */
  44. #define RSTC_SOFT 0x3U
  45. /**
  46. * @brief Read and Write access allowed.
  47. */
  48. #define RSTC_USER 0x4U
  49. /** @} */
  50. /*===========================================================================*/
  51. /* Driver pre-compile time settings. */
  52. /*===========================================================================*/
  53. /*===========================================================================*/
  54. /* Derived constants and error checks. */
  55. /*===========================================================================*/
  56. /*===========================================================================*/
  57. /* Driver data structures and types. */
  58. /*===========================================================================*/
  59. /*===========================================================================*/
  60. /* Driver macros. */
  61. /*===========================================================================*/
  62. /**
  63. * @name Generic RSTC operations
  64. * @{
  65. */
  66. /**
  67. * @brief Enable/Disable the detection of a low level on the pin NRST
  68. * as User Reset.
  69. * @param[in] enable
  70. */
  71. #define rstcSetUserResetEnable(enable) { \
  72. if (enable) { \
  73. RSTC->RSTC_MR |= RSTC_MR_URSTEN | RSTC_MR_KEY_PASSWD; \
  74. } else { \
  75. RSTC->RSTC_MR &= ~RSTC_MR_URSTEN; \
  76. RSTC->RSTC_MR |= RSTC_MR_KEY_PASSWD; \
  77. } \
  78. }
  79. /**
  80. * @brief Enable/Disable the interrupt of a User Reset.
  81. * @param[in] enable
  82. */
  83. #define rstcSetUserResetInterruptEnable(enable) { \
  84. if (enable) { \
  85. RSTC->RSTC_MR |= RSTC_MR_URSTIEN | RSTC_MR_KEY_PASSWD; \
  86. } else { \
  87. RSTC->RSTC_MR &= ~RSTC_MR_URSTIEN; \
  88. RSTC->RSTC_MR |= RSTC_MR_KEY_PASSWD; \
  89. } \
  90. }
  91. /**
  92. * @brief Perform a processor and peripheral reset.
  93. *
  94. * @notapi
  95. */
  96. #define rstcResetProcessorAndPeripheral() { \
  97. RSTC->RSTC_CR = RSTC_CR_PERRST | RSTC_CR_PROCRST | RSTC_MR_KEY_PASSWD; \
  98. }
  99. /**
  100. * @brief Perform a processor reset.
  101. *
  102. * @notapi
  103. */
  104. #define rstcResetProcessor() { \
  105. RSTC->RSTC_CR = RSTC_CR_PROCRST | RSTC_CR_KEY_PASSWD; \
  106. }
  107. /**
  108. * @brief Perform a peripheral reset.
  109. *
  110. * @notapi
  111. */
  112. #define rstcResetPeripheral() { \
  113. RSTC->RSTC_CR = RSTC_CR_PERRST | RSTC_MR_KEY_PASSWD; \
  114. }
  115. /**
  116. * @brief Report the cause of the last processor reset.
  117. *
  118. * @param[out] status Cause of the reset
  119. *
  120. * @notapi
  121. */
  122. #define rstcGetStatus(status) { \
  123. uint32_t sr = RSTC->RSTC_SR & RSTC_SR_RSTTYP_Msk; \
  124. switch (sr) { \
  125. case RSTC_SR_RSTTYP_GENERAL_RST: \
  126. status = RSTC_GENERAL; \
  127. break; \
  128. case RSTC_SR_RSTTYP_WKUP_RST: \
  129. status = RSTC_WKUP; \
  130. break; \
  131. case RSTC_SR_RSTTYP_WDT_RST: \
  132. status = RSTC_WDT; \
  133. break; \
  134. case RSTC_SR_RSTTYP_SOFT_RST: \
  135. status = RSTC_SOFT; \
  136. break; \
  137. case RSTC_SR_RSTTYP_USER_RST: \
  138. status = RSTC_USER; \
  139. break; \
  140. default: \
  141. break; \
  142. } \
  143. }
  144. /** @} */
  145. /*===========================================================================*/
  146. /* External declarations. */
  147. /*===========================================================================*/
  148. #ifdef __cplusplus
  149. extern "C" {
  150. #endif
  151. #ifdef __cplusplus
  152. }
  153. #endif
  154. #endif /* SAMA_RSTC_H */
  155. /** @} */