fsl_mu.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752
  1. /*
  2. * Copyright (c) 2015, Freescale Semiconductor, Inc.
  3. * Copyright 2016-2021 NXP
  4. * All rights reserved.
  5. *
  6. * SPDX-License-Identifier: BSD-3-Clause
  7. */
  8. #ifndef _FSL_MU_H_
  9. #define _FSL_MU_H_
  10. #include "fsl_common.h"
  11. /*!
  12. * @addtogroup mu
  13. * @{
  14. */
  15. /******************************************************************************
  16. * Definitions
  17. *****************************************************************************/
  18. /* Compatibility Macros */
  19. #ifndef MU_CR_NMI_MASK
  20. #define MU_CR_NMI_MASK 0U
  21. #endif
  22. #if (defined(FSL_FEATURE_MU_HAS_RESET_INT) && FSL_FEATURE_MU_HAS_RESET_INT)
  23. #ifndef FSL_FEATURE_MU_HAS_RESET_ASSERT_INT
  24. #define FSL_FEATURE_MU_HAS_RESET_ASSERT_INT 1
  25. #endif
  26. #ifndef FSL_FEATURE_MU_HAS_RESET_DEASSERT_INT
  27. #define FSL_FEATURE_MU_HAS_RESET_DEASSERT_INT 1
  28. #endif
  29. #endif /* FSL_FEATURE_MU_HAS_RESET_INT */
  30. /*! @name Driver version */
  31. /*@{*/
  32. /*! @brief MU driver version. */
  33. #define FSL_MU_DRIVER_VERSION (MAKE_VERSION(2, 1, 0))
  34. /*@}*/
  35. /*!
  36. * @brief MU status flags.
  37. */
  38. enum _mu_status_flags
  39. {
  40. kMU_Tx0EmptyFlag = (1U << (MU_SR_TEn_SHIFT + 3U)), /*!< TX0 empty. */
  41. kMU_Tx1EmptyFlag = (1U << (MU_SR_TEn_SHIFT + 2U)), /*!< TX1 empty. */
  42. kMU_Tx2EmptyFlag = (1U << (MU_SR_TEn_SHIFT + 1U)), /*!< TX2 empty. */
  43. kMU_Tx3EmptyFlag = (1U << (MU_SR_TEn_SHIFT + 0U)), /*!< TX3 empty. */
  44. kMU_Rx0FullFlag = (1U << (MU_SR_RFn_SHIFT + 3U)), /*!< RX0 full. */
  45. kMU_Rx1FullFlag = (1U << (MU_SR_RFn_SHIFT + 2U)), /*!< RX1 full. */
  46. kMU_Rx2FullFlag = (1U << (MU_SR_RFn_SHIFT + 1U)), /*!< RX2 full. */
  47. kMU_Rx3FullFlag = (1U << (MU_SR_RFn_SHIFT + 0U)), /*!< RX3 full. */
  48. kMU_GenInt0Flag = (1U << (MU_SR_GIPn_SHIFT + 3U)), /*!< General purpose interrupt 0 pending. */
  49. kMU_GenInt1Flag = (1U << (MU_SR_GIPn_SHIFT + 2U)), /*!< General purpose interrupt 0 pending. */
  50. kMU_GenInt2Flag = (1U << (MU_SR_GIPn_SHIFT + 1U)), /*!< General purpose interrupt 0 pending. */
  51. kMU_GenInt3Flag = (1U << (MU_SR_GIPn_SHIFT + 0U)), /*!< General purpose interrupt 0 pending. */
  52. kMU_EventPendingFlag = MU_SR_EP_MASK, /*!< MU event pending. */
  53. kMU_FlagsUpdatingFlag = MU_SR_FUP_MASK, /*!< MU flags update is on-going. */
  54. #if (defined(FSL_FEATURE_MU_HAS_RESET_ASSERT_INT) && FSL_FEATURE_MU_HAS_RESET_ASSERT_INT)
  55. kMU_ResetAssertInterruptFlag = MU_SR_RAIP_MASK, /*!< The other core reset assert interrupt pending. */
  56. #endif
  57. #if (defined(FSL_FEATURE_MU_HAS_RESET_DEASSERT_INT) && FSL_FEATURE_MU_HAS_RESET_DEASSERT_INT)
  58. kMU_ResetDeassertInterruptFlag = MU_SR_RDIP_MASK, /*!< The other core reset de-assert interrupt pending. */
  59. #endif
  60. #if (defined(FSL_FEATURE_MU_HAS_SR_RS) && FSL_FEATURE_MU_HAS_SR_RS)
  61. kMU_OtherSideInResetFlag = MU_SR_RS_MASK, /*!< The other side is in reset. */
  62. #endif
  63. #if (defined(FSL_FEATURE_MU_HAS_SR_MURIP) && FSL_FEATURE_MU_HAS_SR_MURIP)
  64. kMU_MuResetInterruptFlag = MU_SR_MURIP_MASK, /*!< The other side initializes MU reset. */
  65. #endif
  66. #if (defined(FSL_FEATURE_MU_HAS_SR_HRIP) && FSL_FEATURE_MU_HAS_SR_HRIP)
  67. kMU_HardwareResetInterruptFlag = MU_SR_HRIP_MASK, /*!< Current side has been hardware reset by the other side. */
  68. #endif
  69. };
  70. /*!
  71. * @brief MU interrupt source to enable.
  72. */
  73. enum _mu_interrupt_enable
  74. {
  75. kMU_Tx0EmptyInterruptEnable = (1U << (MU_CR_TIEn_SHIFT + 3U)), /*!< TX0 empty. */
  76. kMU_Tx1EmptyInterruptEnable = (1U << (MU_CR_TIEn_SHIFT + 2U)), /*!< TX1 empty. */
  77. kMU_Tx2EmptyInterruptEnable = (1U << (MU_CR_TIEn_SHIFT + 1U)), /*!< TX2 empty. */
  78. kMU_Tx3EmptyInterruptEnable = (1U << (MU_CR_TIEn_SHIFT + 0U)), /*!< TX3 empty. */
  79. kMU_Rx0FullInterruptEnable = (1U << (MU_CR_RIEn_SHIFT + 3U)), /*!< RX0 full. */
  80. kMU_Rx1FullInterruptEnable = (1U << (MU_CR_RIEn_SHIFT + 2U)), /*!< RX1 full. */
  81. kMU_Rx2FullInterruptEnable = (1U << (MU_CR_RIEn_SHIFT + 1U)), /*!< RX2 full. */
  82. kMU_Rx3FullInterruptEnable = (1U << (MU_CR_RIEn_SHIFT + 0U)), /*!< RX3 full. */
  83. kMU_GenInt0InterruptEnable = (int)(1U << (MU_CR_GIEn_SHIFT + 3U)), /*!< General purpose interrupt 0. */
  84. kMU_GenInt1InterruptEnable = (1U << (MU_CR_GIEn_SHIFT + 2U)), /*!< General purpose interrupt 1. */
  85. kMU_GenInt2InterruptEnable = (1U << (MU_CR_GIEn_SHIFT + 1U)), /*!< General purpose interrupt 2. */
  86. kMU_GenInt3InterruptEnable = (1U << (MU_CR_GIEn_SHIFT + 0U)), /*!< General purpose interrupt 3. */
  87. #if (defined(FSL_FEATURE_MU_HAS_RESET_ASSERT_INT) && FSL_FEATURE_MU_HAS_RESET_ASSERT_INT)
  88. kMU_ResetAssertInterruptEnable = MU_CR_RAIE_MASK, /*!< The other core reset assert interrupt. */
  89. #endif
  90. #if (defined(FSL_FEATURE_MU_HAS_RESET_DEASSERT_INT) && FSL_FEATURE_MU_HAS_RESET_ASSERT_INT)
  91. kMU_ResetDeassertInterruptEnable = MU_CR_RDIE_MASK, /*!< The other core reset de-assert interrupt. */
  92. #endif
  93. #if (defined(FSL_FEATURE_MU_HAS_SR_MURIP) && FSL_FEATURE_MU_HAS_SR_MURIP)
  94. kMU_MuResetInterruptEnable = MU_CR_MURIE_MASK, /*!< The other side initializes MU reset. The interrupt
  95. is ORed with the general purpose interrupt 3. The
  96. general purpose interrupt 3 is issued when the other side
  97. set the MU reset and this interrupt is enabled. */
  98. #endif
  99. #if (defined(FSL_FEATURE_MU_HAS_SR_HRIP) && FSL_FEATURE_MU_HAS_SR_HRIP)
  100. kMU_HardwareResetInterruptEnable = MU_CR_HRIE_MASK, /*!< Current side has been hardware reset by the other side. */
  101. #endif
  102. };
  103. /*!
  104. * @brief MU interrupt that could be triggered to the other core.
  105. */
  106. enum _mu_interrupt_trigger
  107. {
  108. #if !(defined(FSL_FEATURE_MU_NO_NMI) && FSL_FEATURE_MU_NO_NMI)
  109. kMU_NmiInterruptTrigger = MU_CR_NMI_MASK, /*!< NMI interrupt. */
  110. #endif
  111. kMU_GenInt0InterruptTrigger = (1U << (MU_CR_GIRn_SHIFT + 3U)), /*!< General purpose interrupt 0. */
  112. kMU_GenInt1InterruptTrigger = (1U << (MU_CR_GIRn_SHIFT + 2U)), /*!< General purpose interrupt 1. */
  113. kMU_GenInt2InterruptTrigger = (1U << (MU_CR_GIRn_SHIFT + 1U)), /*!< General purpose interrupt 2. */
  114. kMU_GenInt3InterruptTrigger = (1U << (MU_CR_GIRn_SHIFT + 0U)) /*!< General purpose interrupt 3. */
  115. };
  116. /*!
  117. * @brief MU message register.
  118. */
  119. typedef enum _mu_msg_reg_index
  120. {
  121. kMU_MsgReg0 = 0,
  122. kMU_MsgReg1,
  123. kMU_MsgReg2,
  124. kMU_MsgReg3,
  125. } mu_msg_reg_index_t;
  126. /*******************************************************************************
  127. * API
  128. ******************************************************************************/
  129. #if defined(__cplusplus)
  130. extern "C" {
  131. #endif
  132. /*!
  133. * @name MU initialization.
  134. * @{
  135. */
  136. /*!
  137. * @brief Initializes the MU module.
  138. *
  139. * This function enables the MU clock only.
  140. *
  141. * @param base MU peripheral base address.
  142. */
  143. void MU_Init(MU_Type *base);
  144. /*!
  145. * @brief De-initializes the MU module.
  146. *
  147. * This function disables the MU clock only.
  148. *
  149. * @param base MU peripheral base address.
  150. */
  151. void MU_Deinit(MU_Type *base);
  152. /* @} */
  153. /*!
  154. * @name MU Message
  155. * @{
  156. */
  157. /*!
  158. * @brief Writes a message to the TX register.
  159. *
  160. * This function writes a message to the specific TX register. It does not check
  161. * whether the TX register is empty or not. The upper layer should make sure the TX
  162. * register is empty before calling this function. This function can be used
  163. * in ISR for better performance.
  164. *
  165. * @code
  166. * while (!(kMU_Tx0EmptyFlag & MU_GetStatusFlags(base))) { } Wait for TX0 register empty.
  167. * MU_SendMsgNonBlocking(base, kMU_MsgReg0, MSG_VAL); Write message to the TX0 register.
  168. * @endcode
  169. *
  170. * @param base MU peripheral base address.
  171. * @param regIndex TX register index, see @ref mu_msg_reg_index_t.
  172. * @param msg Message to send.
  173. */
  174. static inline void MU_SendMsgNonBlocking(MU_Type *base, uint32_t regIndex, uint32_t msg)
  175. {
  176. assert(regIndex < MU_TR_COUNT);
  177. base->TR[regIndex] = msg;
  178. }
  179. /*!
  180. * @brief Blocks to send a message.
  181. *
  182. * This function waits until the TX register is empty and sends the message.
  183. *
  184. * @param base MU peripheral base address.
  185. * @param regIndex MU message register, see @ref mu_msg_reg_index_t
  186. * @param msg Message to send.
  187. */
  188. void MU_SendMsg(MU_Type *base, uint32_t regIndex, uint32_t msg);
  189. /*!
  190. * @brief Reads a message from the RX register.
  191. *
  192. * This function reads a message from the specific RX register. It does not check
  193. * whether the RX register is full or not. The upper layer should make sure the RX
  194. * register is full before calling this function. This function can be used
  195. * in ISR for better performance.
  196. *
  197. * @code
  198. * uint32_t msg;
  199. * while (!(kMU_Rx0FullFlag & MU_GetStatusFlags(base)))
  200. * {
  201. * } Wait for the RX0 register full.
  202. *
  203. * msg = MU_ReceiveMsgNonBlocking(base, kMU_MsgReg0); Read message from RX0 register.
  204. * @endcode
  205. *
  206. * @param base MU peripheral base address.
  207. * @param RX register index, see @ref mu_msg_reg_index_t.
  208. * @return The received message.
  209. */
  210. static inline uint32_t MU_ReceiveMsgNonBlocking(MU_Type *base, uint32_t regIndex)
  211. {
  212. assert(regIndex < MU_TR_COUNT);
  213. return base->RR[regIndex];
  214. }
  215. /*!
  216. * @brief Blocks to receive a message.
  217. *
  218. * This function waits until the RX register is full and receives the message.
  219. *
  220. * @param base MU peripheral base address.
  221. * @param regIndex MU message register, see @ref mu_msg_reg_index_t
  222. * @return The received message.
  223. */
  224. uint32_t MU_ReceiveMsg(MU_Type *base, uint32_t regIndex);
  225. /* @} */
  226. /*!
  227. * @name MU Flags
  228. * @{
  229. */
  230. /*!
  231. * @brief Sets the 3-bit MU flags reflect on the other MU side.
  232. *
  233. * This function sets the 3-bit MU flags directly. Every time the 3-bit MU flags are changed,
  234. * the status flag \c kMU_FlagsUpdatingFlag asserts indicating the 3-bit MU flags are
  235. * updating to the other side. After the 3-bit MU flags are updated, the status flag
  236. * \c kMU_FlagsUpdatingFlag is cleared by hardware. During the flags updating period,
  237. * the flags cannot be changed. The upper layer should make sure the status flag
  238. * \c kMU_FlagsUpdatingFlag is cleared before calling this function.
  239. *
  240. * @code
  241. * while (kMU_FlagsUpdatingFlag & MU_GetStatusFlags(base))
  242. * {
  243. * } Wait for previous MU flags updating.
  244. *
  245. * MU_SetFlagsNonBlocking(base, 0U); Set the mU flags.
  246. * @endcode
  247. *
  248. * @param base MU peripheral base address.
  249. * @param flags The 3-bit MU flags to set.
  250. */
  251. static inline void MU_SetFlagsNonBlocking(MU_Type *base, uint32_t flags)
  252. {
  253. uint32_t reg = base->CR;
  254. reg = (reg & ~((MU_CR_GIRn_MASK | MU_CR_NMI_MASK) | MU_CR_Fn_MASK)) | MU_CR_Fn(flags);
  255. base->CR = reg;
  256. }
  257. /*!
  258. * @brief Blocks setting the 3-bit MU flags reflect on the other MU side.
  259. *
  260. * This function blocks setting the 3-bit MU flags. Every time the 3-bit MU flags are changed,
  261. * the status flag \c kMU_FlagsUpdatingFlag asserts indicating the 3-bit MU flags are
  262. * updating to the other side. After the 3-bit MU flags are updated, the status flag
  263. * \c kMU_FlagsUpdatingFlag is cleared by hardware. During the flags updating period,
  264. * the flags cannot be changed. This function waits for the MU status flag
  265. * \c kMU_FlagsUpdatingFlag cleared and sets the 3-bit MU flags.
  266. *
  267. * @param base MU peripheral base address.
  268. * @param flags The 3-bit MU flags to set.
  269. */
  270. void MU_SetFlags(MU_Type *base, uint32_t flags);
  271. /*!
  272. * @brief Gets the current value of the 3-bit MU flags set by the other side.
  273. *
  274. * This function gets the current 3-bit MU flags on the current side.
  275. *
  276. * @param base MU peripheral base address.
  277. * @return flags Current value of the 3-bit flags.
  278. */
  279. static inline uint32_t MU_GetFlags(MU_Type *base)
  280. {
  281. return (base->SR & MU_SR_Fn_MASK) >> MU_SR_Fn_SHIFT;
  282. }
  283. /* @} */
  284. /*!
  285. * @name Status and Interrupt.
  286. * @{
  287. */
  288. /*!
  289. * @brief Gets the MU status flags.
  290. *
  291. * This function returns the bit mask of the MU status flags. See _mu_status_flags.
  292. *
  293. * @code
  294. * uint32_t flags;
  295. * flags = MU_GetStatusFlags(base); Get all status flags.
  296. * if (kMU_Tx0EmptyFlag & flags)
  297. * {
  298. * The TX0 register is empty. Message can be sent.
  299. * MU_SendMsgNonBlocking(base, kMU_MsgReg0, MSG0_VAL);
  300. * }
  301. * if (kMU_Tx1EmptyFlag & flags)
  302. * {
  303. * The TX1 register is empty. Message can be sent.
  304. * MU_SendMsgNonBlocking(base, kMU_MsgReg1, MSG1_VAL);
  305. * }
  306. * @endcode
  307. *
  308. * @param base MU peripheral base address.
  309. * @return Bit mask of the MU status flags, see _mu_status_flags.
  310. */
  311. static inline uint32_t MU_GetStatusFlags(MU_Type *base)
  312. {
  313. return (base->SR & (MU_SR_TEn_MASK | MU_SR_RFn_MASK | MU_SR_GIPn_MASK | MU_SR_EP_MASK | MU_SR_FUP_MASK
  314. #if (defined(FSL_FEATURE_MU_HAS_SR_RS) && FSL_FEATURE_MU_HAS_SR_RS)
  315. | MU_SR_RS_MASK
  316. #endif
  317. #if (defined(FSL_FEATURE_MU_HAS_RESET_ASSERT_INT) && FSL_FEATURE_MU_HAS_RESET_ASSERT_INT)
  318. | MU_SR_RAIP_MASK
  319. #endif
  320. #if (defined(FSL_FEATURE_MU_HAS_RESET_DEASSERT_INT) && FSL_FEATURE_MU_HAS_RESET_ASSERT_INT)
  321. | MU_SR_RDIP_MASK
  322. #endif
  323. #if (defined(FSL_FEATURE_MU_HAS_SR_MURIP) && FSL_FEATURE_MU_HAS_SR_MURIP)
  324. | MU_SR_MURIP_MASK
  325. #endif
  326. #if (defined(FSL_FEATURE_MU_HAS_SR_HRIP) && FSL_FEATURE_MU_HAS_SR_HRIP)
  327. | MU_SR_HRIP_MASK
  328. #endif
  329. ));
  330. }
  331. /*!
  332. * @brief Gets the MU IRQ pending status.
  333. *
  334. * This function returns the bit mask of the pending MU IRQs.
  335. *
  336. * @param base MU peripheral base address.
  337. * @return Bit mask of the MU IRQs pending.
  338. */
  339. static inline uint32_t MU_GetInterruptsPending(MU_Type *base)
  340. {
  341. uint32_t irqMask = base->CR & (MU_CR_GIEn_MASK | MU_CR_TIEn_MASK | MU_CR_RIEn_MASK);
  342. return (base->SR & irqMask);
  343. }
  344. /*!
  345. * @brief Clears the specific MU status flags.
  346. *
  347. * This function clears the specific MU status flags. The flags to clear should
  348. * be passed in as bit mask. See _mu_status_flags.
  349. *
  350. * @code
  351. * Clear general interrupt 0 and general interrupt 1 pending flags.
  352. * MU_ClearStatusFlags(base, kMU_GenInt0Flag | kMU_GenInt1Flag);
  353. * @endcode
  354. *
  355. * @param base MU peripheral base address.
  356. * @param mask Bit mask of the MU status flags. See _mu_status_flags. The following
  357. * flags are cleared by hardware, this function could not clear them.
  358. * - kMU_Tx0EmptyFlag
  359. * - kMU_Tx1EmptyFlag
  360. * - kMU_Tx2EmptyFlag
  361. * - kMU_Tx3EmptyFlag
  362. * - kMU_Rx0FullFlag
  363. * - kMU_Rx1FullFlag
  364. * - kMU_Rx2FullFlag
  365. * - kMU_Rx3FullFlag
  366. * - kMU_EventPendingFlag
  367. * - kMU_FlagsUpdatingFlag
  368. * - kMU_OtherSideInResetFlag
  369. */
  370. static inline void MU_ClearStatusFlags(MU_Type *base, uint32_t mask)
  371. {
  372. /* regMask is the mask of w1c status bits. */
  373. uint32_t regMask = MU_SR_GIPn_MASK;
  374. #if (defined(FSL_FEATURE_MU_HAS_RESET_ASSERT_INT) && FSL_FEATURE_MU_HAS_RESET_ASSERT_INT)
  375. regMask |= MU_SR_RAIP_MASK;
  376. #endif
  377. #if (defined(FSL_FEATURE_MU_HAS_RESET_DEASSERT_INT) && FSL_FEATURE_MU_HAS_RESET_ASSERT_INT)
  378. regMask |= MU_SR_RDIP_MASK;
  379. #endif
  380. #if (defined(FSL_FEATURE_MU_HAS_SR_MURIP) && FSL_FEATURE_MU_HAS_SR_MURIP)
  381. regMask |= MU_SR_MURIP_MASK;
  382. #endif
  383. #if (defined(FSL_FEATURE_MU_HAS_SR_HRIP) && FSL_FEATURE_MU_HAS_SR_HRIP)
  384. regMask |= MU_SR_HRIP_MASK;
  385. #endif
  386. base->SR = (mask & regMask);
  387. }
  388. /*!
  389. * @brief Enables the specific MU interrupts.
  390. *
  391. * This function enables the specific MU interrupts. The interrupts to enable
  392. * should be passed in as bit mask. See _mu_interrupt_enable.
  393. *
  394. * @code
  395. * Enable general interrupt 0 and TX0 empty interrupt.
  396. * MU_EnableInterrupts(base, kMU_GenInt0InterruptEnable | kMU_Tx0EmptyInterruptEnable);
  397. * @endcode
  398. *
  399. * @param base MU peripheral base address.
  400. * @param mask Bit mask of the MU interrupts. See _mu_interrupt_enable.
  401. */
  402. static inline void MU_EnableInterrupts(MU_Type *base, uint32_t mask)
  403. {
  404. uint32_t reg = base->CR;
  405. reg = (reg & ~(MU_CR_GIRn_MASK | MU_CR_NMI_MASK)) | mask;
  406. base->CR = reg;
  407. }
  408. /*!
  409. * @brief Disables the specific MU interrupts.
  410. *
  411. * This function disables the specific MU interrupts. The interrupts to disable
  412. * should be passed in as bit mask. See _mu_interrupt_enable.
  413. *
  414. * @code
  415. * Disable general interrupt 0 and TX0 empty interrupt.
  416. * MU_DisableInterrupts(base, kMU_GenInt0InterruptEnable | kMU_Tx0EmptyInterruptEnable);
  417. * @endcode
  418. *
  419. * @param base MU peripheral base address.
  420. * @param mask Bit mask of the MU interrupts. See _mu_interrupt_enable.
  421. */
  422. static inline void MU_DisableInterrupts(MU_Type *base, uint32_t mask)
  423. {
  424. uint32_t reg = base->CR;
  425. reg &= ~((MU_CR_GIRn_MASK | MU_CR_NMI_MASK) | mask);
  426. base->CR = reg;
  427. }
  428. /*!
  429. * @brief Triggers interrupts to the other core.
  430. *
  431. * This function triggers the specific interrupts to the other core. The interrupts
  432. * to trigger are passed in as bit mask. See \ref _mu_interrupt_trigger.
  433. * The MU should not trigger an interrupt to the other core when the previous interrupt
  434. * has not been processed by the other core. This function checks whether the
  435. * previous interrupts have been processed. If not, it returns an error.
  436. *
  437. * @code
  438. * if (kStatus_Success != MU_TriggerInterrupts(base, kMU_GenInt0InterruptTrigger | kMU_GenInt2InterruptTrigger))
  439. * {
  440. * Previous general purpose interrupt 0 or general purpose interrupt 2
  441. * has not been processed by the other core.
  442. * }
  443. * @endcode
  444. *
  445. * @param base MU peripheral base address.
  446. * @param mask Bit mask of the interrupts to trigger. See _mu_interrupt_trigger.
  447. * @retval kStatus_Success Interrupts have been triggered successfully.
  448. * @retval kStatus_Fail Previous interrupts have not been accepted.
  449. */
  450. status_t MU_TriggerInterrupts(MU_Type *base, uint32_t mask);
  451. #if !(defined(FSL_FEATURE_MU_NO_NMI) && FSL_FEATURE_MU_NO_NMI)
  452. /*!
  453. * @brief Clear non-maskable interrupt (NMI) sent by the other core.
  454. *
  455. * This function clears non-maskable interrupt (NMI) sent by the other core.
  456. *
  457. * @param base MU peripheral base address.
  458. */
  459. static inline void MU_ClearNmi(MU_Type *base)
  460. {
  461. base->SR = MU_SR_NMIC_MASK;
  462. }
  463. #endif /* FSL_FEATURE_MU_NO_NMI */
  464. /* @} */
  465. /*!
  466. * @name MU misc functions
  467. * @{
  468. */
  469. #if !(defined(FSL_FEATURE_MU_NO_RSTH) && FSL_FEATURE_MU_NO_RSTH)
  470. /*!
  471. * @brief Boots the core at B side.
  472. *
  473. * This function sets the B side core's boot configuration and releases the
  474. * core from reset.
  475. *
  476. * @param base MU peripheral base address.
  477. * @param mode Core B boot mode.
  478. * @note Only MU side A can use this function.
  479. */
  480. void MU_BootCoreB(MU_Type *base, mu_core_boot_mode_t mode);
  481. /*!
  482. * @brief Holds the core reset of B side.
  483. *
  484. * This function causes the core of B side to be held in reset following any reset event.
  485. *
  486. * @param base MU peripheral base address.
  487. * @note Only A side could call this function.
  488. */
  489. static inline void MU_HoldCoreBReset(MU_Type *base)
  490. {
  491. #if (defined(FSL_FEATURE_MU_HAS_CCR) && FSL_FEATURE_MU_HAS_CCR)
  492. base->CCR |= MU_CCR_RSTH_MASK;
  493. #else /* FSL_FEATURE_MU_HAS_CCR */
  494. uint32_t reg = base->CR;
  495. reg = (reg & ~(MU_CR_GIRn_MASK | MU_CR_NMI_MASK)) | MU_CR_RSTH_MASK;
  496. base->CR = reg;
  497. #endif /* FSL_FEATURE_MU_HAS_CCR */
  498. }
  499. /*!
  500. * @brief Boots the other core.
  501. *
  502. * This function boots the other core with a boot configuration.
  503. *
  504. * @param base MU peripheral base address.
  505. * @param mode The other core boot mode.
  506. */
  507. void MU_BootOtherCore(MU_Type *base, mu_core_boot_mode_t mode);
  508. /*!
  509. * @brief Holds the other core reset.
  510. *
  511. * This function causes the other core to be held in reset following any reset event.
  512. *
  513. * @param base MU peripheral base address.
  514. */
  515. static inline void MU_HoldOtherCoreReset(MU_Type *base)
  516. {
  517. /*
  518. * MU_HoldOtherCoreReset and MU_HoldCoreBReset are the same, MU_HoldCoreBReset
  519. * is kept for compatible with older platforms.
  520. */
  521. MU_HoldCoreBReset(base);
  522. }
  523. #endif /* FSL_FEATURE_MU_NO_RSTH */
  524. #if !(defined(FSL_FEATURE_MU_NO_MUR) && FSL_FEATURE_MU_NO_MUR)
  525. /*!
  526. * @brief Resets the MU for both A side and B side.
  527. *
  528. * This function resets the MU for both A side and B side. Before reset, it is
  529. * recommended to interrupt processor B, because this function may affect the
  530. * ongoing processor B programs.
  531. *
  532. * @param base MU peripheral base address.
  533. * @note For some platforms, only MU side A could use this function, check
  534. * reference manual for details.
  535. */
  536. static inline void MU_ResetBothSides(MU_Type *base)
  537. {
  538. uint32_t reg = base->CR;
  539. reg = (reg & ~(MU_CR_GIRn_MASK | MU_CR_NMI_MASK)) | MU_CR_MUR_MASK;
  540. base->CR = reg;
  541. #if (defined(FSL_FEATURE_MU_HAS_SR_RS) && FSL_FEATURE_MU_HAS_SR_RS)
  542. /* Wait for the other side out of reset. */
  543. while (0U != (base->SR & MU_SR_RS_MASK))
  544. {
  545. }
  546. #endif /* FSL_FEATURE_MU_HAS_SR_RS */
  547. }
  548. #endif /* FSL_FEATURE_MU_NO_MUR */
  549. #if (defined(FSL_FEATURE_MU_HAS_HRM) && FSL_FEATURE_MU_HAS_HRM)
  550. /*!
  551. * @brief Mask hardware reset by the other core.
  552. *
  553. * The other core could call MU_HardwareResetOtherCore() to reset current core.
  554. * To mask the reset, call this function and pass in true.
  555. *
  556. * @param base MU peripheral base address.
  557. * @param mask Pass true to mask the hardware reset, pass false to unmask it.
  558. */
  559. static inline void MU_MaskHardwareReset(MU_Type *base, bool mask)
  560. {
  561. #if (defined(FSL_FEATURE_MU_HAS_CCR) && FSL_FEATURE_MU_HAS_CCR)
  562. if (mask)
  563. {
  564. base->CCR |= MU_CCR_HRM_MASK;
  565. }
  566. else
  567. {
  568. base->CCR &= ~MU_CCR_HRM_MASK;
  569. }
  570. #else /* FSL_FEATURE_MU_HAS_CCR */
  571. if (mask)
  572. {
  573. base->CR |= MU_CR_HRM_MASK;
  574. }
  575. else
  576. {
  577. base->CR &= ~MU_CR_HRM_MASK;
  578. }
  579. #endif /* FSL_FEATURE_MU_HAS_CCR */
  580. }
  581. #endif /* FSL_FEATURE_MU_HAS_HRM */
  582. #if !(defined(FSL_FEATURE_MU_NO_HR) && FSL_FEATURE_MU_NO_HR)
  583. /*!
  584. * @brief Hardware reset the other core.
  585. *
  586. * This function resets the other core, the other core could mask the
  587. * hardware reset by calling MU_MaskHardwareReset. The hardware reset
  588. * mask feature is only available for some platforms.
  589. * This function could be used together with MU_BootOtherCore to control the
  590. * other core reset workflow.
  591. *
  592. * Example 1: Reset the other core, and no hold reset
  593. * @code
  594. * MU_HardwareResetOtherCore(MU_A, true, false, bootMode);
  595. * @endcode
  596. * In this example, the core at MU side B will reset with the specified boot mode.
  597. *
  598. * Example 2: Reset the other core and hold it, then boot the other core later.
  599. * @code
  600. * Here the other core enters reset, and the reset is hold
  601. * MU_HardwareResetOtherCore(MU_A, true, true, modeDontCare);
  602. * Current core boot the other core when necessary.
  603. * MU_BootOtherCore(MU_A, bootMode);
  604. * @endcode
  605. *
  606. * @param base MU peripheral base address.
  607. * @param waitReset Wait the other core enters reset.
  608. * - true: Wait until the other core enters reset, if the other
  609. * core has masked the hardware reset, then this function will
  610. * be blocked.
  611. * - false: Don't wait the reset.
  612. * @param holdReset Hold the other core reset or not.
  613. * - true: Hold the other core in reset, this function returns
  614. * directly when the other core enters reset.
  615. * - false: Don't hold the other core in reset, this function
  616. * waits until the other core out of reset.
  617. * @param bootMode Boot mode of the other core, if @p holdReset is true, this
  618. * parameter is useless.
  619. */
  620. void MU_HardwareResetOtherCore(MU_Type *base, bool waitReset, bool holdReset, mu_core_boot_mode_t bootMode);
  621. #endif /* FSL_FEATURE_MU_NO_HR */
  622. #if !(defined(FSL_FEATURE_MU_NO_CLKE) && FSL_FEATURE_MU_NO_CLKE)
  623. /*!
  624. * @brief Enables or disables the clock on the other core.
  625. *
  626. * This function enables or disables the platform clock on the other core when
  627. * that core enters a stop mode. If disabled, the platform clock for the other
  628. * core is disabled when it enters stop mode. If enabled, the platform clock
  629. * keeps running on the other core in stop mode, until this core also enters
  630. * stop mode.
  631. *
  632. * @param base MU peripheral base address.
  633. * @param enable Enable or disable the clock on the other core.
  634. */
  635. static inline void MU_SetClockOnOtherCoreEnable(MU_Type *base, bool enable)
  636. {
  637. #if (defined(FSL_FEATURE_MU_HAS_CCR) && FSL_FEATURE_MU_HAS_CCR)
  638. if (enable)
  639. {
  640. base->CCR |= MU_CCR_CLKE_MASK;
  641. }
  642. else
  643. {
  644. base->CCR &= ~MU_CCR_CLKE_MASK;
  645. }
  646. #else /* FSL_FEATURE_MU_HAS_CCR */
  647. uint32_t reg = base->CR;
  648. reg &= ~(MU_CR_GIRn_MASK | MU_CR_NMI_MASK);
  649. if (enable)
  650. {
  651. reg |= MU_CR_CLKE_MASK;
  652. }
  653. else
  654. {
  655. reg &= ~MU_CR_CLKE_MASK;
  656. }
  657. base->CR = reg;
  658. #endif /* FSL_FEATURE_MU_HAS_CCR */
  659. }
  660. #endif /* FSL_FEATURE_MU_NO_CLKE */
  661. #if !(defined(FSL_FEATURE_MU_NO_PM) && FSL_FEATURE_MU_NO_PM)
  662. /*!
  663. * @brief Gets the power mode of the other core.
  664. *
  665. * This function gets the power mode of the other core.
  666. *
  667. * @param base MU peripheral base address.
  668. * @return Power mode of the other core.
  669. */
  670. static inline mu_power_mode_t MU_GetOtherCorePowerMode(MU_Type *base)
  671. {
  672. uint32_t ret = (base->SR & MU_SR_PM_MASK) >> MU_SR_PM_SHIFT;
  673. return (mu_power_mode_t)ret;
  674. }
  675. #endif /* FSL_FEATURE_MU_NO_PM */
  676. /* @} */
  677. #if defined(__cplusplus)
  678. }
  679. #endif /*_cplusplus*/
  680. /*@}*/
  681. #endif /* _FSL_MU_H_*/