fsl_reset.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. /*
  2. * The Clear BSD License
  3. * Copyright (c) 2016, Freescale Semiconductor, Inc.
  4. * Copyright (c) 2016, NXP
  5. * All rights reserved.
  6. *
  7. *
  8. * Redistribution and use in source and binary forms, with or without modification,
  9. * are permitted (subject to the limitations in the disclaimer below) provided
  10. * that the following conditions are met:
  11. *
  12. * o Redistributions of source code must retain the above copyright notice, this list
  13. * of conditions and the following disclaimer.
  14. *
  15. * o Redistributions in binary form must reproduce the above copyright notice, this
  16. * list of conditions and the following disclaimer in the documentation and/or
  17. * other materials provided with the distribution.
  18. *
  19. * o Neither the name of copyright holder nor the names of its
  20. * contributors may be used to endorse or promote products derived from this
  21. * software without specific prior written permission.
  22. *
  23. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  25. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  26. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  27. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  28. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  29. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  30. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  31. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  32. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  33. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. */
  35. #ifndef _FSL_RESET_H_
  36. #define _FSL_RESET_H_
  37. #include <assert.h>
  38. #include <stdbool.h>
  39. #include <stdint.h>
  40. #include <string.h>
  41. #include "fsl_device_registers.h"
  42. /*!
  43. * @addtogroup ksdk_common
  44. * @{
  45. */
  46. /*******************************************************************************
  47. * Definitions
  48. ******************************************************************************/
  49. /*! @name Driver version */
  50. /*@{*/
  51. /*! @brief reset driver version 2.0.0. */
  52. #define FSL_RESET_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
  53. /*@}*/
  54. /*!
  55. * @brief Enumeration for peripheral reset control bits
  56. *
  57. * Defines the enumeration for peripheral reset control bits in PRESETCTRL/ASYNCPRESETCTRL registers
  58. */
  59. typedef enum _SYSCON_RSTn
  60. {
  61. kFLASH_RST_SHIFT_RSTn = 0 | 7U, /**< Flash controller reset control */
  62. kFMC_RST_SHIFT_RSTn = 0 | 8U, /**< Flash accelerator reset control */
  63. kMUX_RST_SHIFT_RSTn = 0 | 11U, /**< Input mux reset control */
  64. kIOCON_RST_SHIFT_RSTn = 0 | 13U, /**< IOCON reset control */
  65. kGPIO0_RST_SHIFT_RSTn = 0 | 14U, /**< GPIO0 reset control */
  66. kGPIO1_RST_SHIFT_RSTn = 0 | 15U, /**< GPIO1 reset control */
  67. kPINT_RST_SHIFT_RSTn = 0 | 18U, /**< Pin interrupt (PINT) reset control */
  68. kGINT_RST_SHIFT_RSTn = 0 | 19U, /**< Grouped interrupt (PINT) reset control. */
  69. kDMA_RST_SHIFT_RSTn = 0 | 20U, /**< DMA reset control */
  70. kCRC_RST_SHIFT_RSTn = 0 | 21U, /**< CRC reset control */
  71. kWWDT_RST_SHIFT_RSTn = 0 | 22U, /**< Watchdog timer reset control */
  72. kADC0_RST_SHIFT_RSTn = 0 | 27U, /**< ADC0 reset control */
  73. kMRT_RST_SHIFT_RSTn = 65536 | 0U, /**< Multi-rate timer (MRT) reset control */
  74. kSCT0_RST_SHIFT_RSTn = 65536 | 2U, /**< SCTimer/PWM 0 (SCT0) reset control */
  75. kUTICK_RST_SHIFT_RSTn = 65536 | 10U, /**< Micro-tick timer reset control */
  76. kFC0_RST_SHIFT_RSTn = 65536 | 11U, /**< Flexcomm Interface 0 reset control */
  77. kFC1_RST_SHIFT_RSTn = 65536 | 12U, /**< Flexcomm Interface 1 reset control */
  78. kFC2_RST_SHIFT_RSTn = 65536 | 13U, /**< Flexcomm Interface 2 reset control */
  79. kFC3_RST_SHIFT_RSTn = 65536 | 14U, /**< Flexcomm Interface 3 reset control */
  80. kFC4_RST_SHIFT_RSTn = 65536 | 15U, /**< Flexcomm Interface 4 reset control */
  81. kFC5_RST_SHIFT_RSTn = 65536 | 16U, /**< Flexcomm Interface 5 reset control */
  82. kFC6_RST_SHIFT_RSTn = 65536 | 17U, /**< Flexcomm Interface 6 reset control */
  83. kFC7_RST_SHIFT_RSTn = 65536 | 18U, /**< Flexcomm Interface 7 reset control */
  84. kDMIC_RST_SHIFT_RSTn = 65536 | 19U, /**< Digital microphone interface reset control */
  85. kCT32B2_RST_SHIFT_RSTn = 65536 | 22U, /**< CT32B2 reset control */
  86. kUSB_RST_SHIFT_RSTn = 65536 | 25U, /**< USB reset control */
  87. kCT32B0_RST_SHIFT_RSTn = 65536 | 26U, /**< CT32B0 reset control */
  88. kCT32B1_RST_SHIFT_RSTn = 65536 | 27U, /**< CT32B1 reset control */
  89. kCT32B3_RST_SHIFT_RSTn = 67108864 | 13U, /**< CT32B3 reset control */
  90. kCT32B4_RST_SHIFT_RSTn = 67108864 | 14U, /**< CT32B4 reset control */
  91. } SYSCON_RSTn_t;
  92. /** Array initializers with peripheral reset bits **/
  93. #define ADC_RSTS \
  94. { \
  95. kADC0_RST_SHIFT_RSTn \
  96. } /* Reset bits for ADC peripheral */
  97. #define CRC_RSTS \
  98. { \
  99. kCRC_RST_SHIFT_RSTn \
  100. } /* Reset bits for CRC peripheral */
  101. #define DMA_RSTS \
  102. { \
  103. kDMA_RST_SHIFT_RSTn \
  104. } /* Reset bits for DMA peripheral */
  105. #define DMIC_RSTS \
  106. { \
  107. kDMIC_RST_SHIFT_RSTn \
  108. } /* Reset bits for ADC peripheral */
  109. #define FLEXCOMM_RSTS \
  110. { \
  111. kFC0_RST_SHIFT_RSTn, kFC1_RST_SHIFT_RSTn, kFC2_RST_SHIFT_RSTn, kFC3_RST_SHIFT_RSTn, kFC4_RST_SHIFT_RSTn, \
  112. kFC5_RST_SHIFT_RSTn, kFC6_RST_SHIFT_RSTn, kFC7_RST_SHIFT_RSTn \
  113. } /* Reset bits for FLEXCOMM peripheral */
  114. #define GINT_RSTS \
  115. { \
  116. kGINT_RST_SHIFT_RSTn, kGINT_RST_SHIFT_RSTn \
  117. } /* Reset bits for GINT peripheral. GINT0 & GINT1 share same slot */
  118. #define GPIO_RSTS \
  119. { \
  120. kGPIO0_RST_SHIFT_RSTn, kGPIO1_RST_SHIFT_RSTn \
  121. } /* Reset bits for GPIO peripheral */
  122. #define INPUTMUX_RSTS \
  123. { \
  124. kMUX_RST_SHIFT_RSTn \
  125. } /* Reset bits for INPUTMUX peripheral */
  126. #define IOCON_RSTS \
  127. { \
  128. kIOCON_RST_SHIFT_RSTn \
  129. } /* Reset bits for IOCON peripheral */
  130. #define FLASH_RSTS \
  131. { \
  132. kFLASH_RST_SHIFT_RSTn, kFMC_RST_SHIFT_RSTn \
  133. } /* Reset bits for Flash peripheral */
  134. #define MRT_RSTS \
  135. { \
  136. kMRT_RST_SHIFT_RSTn \
  137. } /* Reset bits for MRT peripheral */
  138. #define PINT_RSTS \
  139. { \
  140. kPINT_RST_SHIFT_RSTn \
  141. } /* Reset bits for PINT peripheral */
  142. #define SCT_RSTS \
  143. { \
  144. kSCT0_RST_SHIFT_RSTn \
  145. } /* Reset bits for SCT peripheral */
  146. #define CTIMER_RSTS \
  147. { \
  148. kCT32B0_RST_SHIFT_RSTn, kCT32B1_RST_SHIFT_RSTn, kCT32B2_RST_SHIFT_RSTn, kCT32B3_RST_SHIFT_RSTn, \
  149. kCT32B4_RST_SHIFT_RSTn \
  150. } /* Reset bits for TIMER peripheral */
  151. #define USB_RSTS \
  152. { \
  153. kUSB_RST_SHIFT_RSTn \
  154. } /* Reset bits for USB peripheral */
  155. #define UTICK_RSTS \
  156. { \
  157. kUTICK_RST_SHIFT_RSTn \
  158. } /* Reset bits for UTICK peripheral */
  159. #define WWDT_RSTS \
  160. { \
  161. kWWDT_RST_SHIFT_RSTn \
  162. } /* Reset bits for WWDT peripheral */
  163. typedef SYSCON_RSTn_t reset_ip_name_t;
  164. /*******************************************************************************
  165. * API
  166. ******************************************************************************/
  167. #if defined(__cplusplus)
  168. extern "C" {
  169. #endif
  170. /*!
  171. * @brief Assert reset to peripheral.
  172. *
  173. * Asserts reset signal to specified peripheral module.
  174. *
  175. * @param peripheral Assert reset to this peripheral. The enum argument contains encoding of reset register
  176. * and reset bit position in the reset register.
  177. */
  178. void RESET_SetPeripheralReset(reset_ip_name_t peripheral);
  179. /*!
  180. * @brief Clear reset to peripheral.
  181. *
  182. * Clears reset signal to specified peripheral module, allows it to operate.
  183. *
  184. * @param peripheral Clear reset to this peripheral. The enum argument contains encoding of reset register
  185. * and reset bit position in the reset register.
  186. */
  187. void RESET_ClearPeripheralReset(reset_ip_name_t peripheral);
  188. /*!
  189. * @brief Reset peripheral module.
  190. *
  191. * Reset peripheral module.
  192. *
  193. * @param peripheral Peripheral to reset. The enum argument contains encoding of reset register
  194. * and reset bit position in the reset register.
  195. */
  196. void RESET_PeripheralReset(reset_ip_name_t peripheral);
  197. /*!
  198. * @brief Set slave core to reset state and hold.
  199. */
  200. void RESET_SetSlaveCoreReset(void);
  201. /*!
  202. * @brief Release slave core from reset state.
  203. */
  204. void RESET_ClearSlaveCoreReset(void);
  205. /*!
  206. * @brief Reset slave core with the boot entry.
  207. */
  208. void RESET_SlaveCoreReset(uint32_t bootAddr, uint32_t bootStackPointer);
  209. #if defined(__cplusplus)
  210. }
  211. #endif
  212. /*! @} */
  213. #endif /* _FSL_RESET_H_ */