fsl_mailbox.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /*
  2. * The Clear BSD License
  3. * Copyright(C) NXP Semiconductors, 2014
  4. * Copyright (c) 2016, Freescale Semiconductor, Inc.
  5. * Copyright 2016-2017 NXP
  6. * All rights reserved.
  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 the 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_MAILBOX_H_
  36. #define _FSL_MAILBOX_H_
  37. #include "fsl_common.h"
  38. /*!
  39. * @addtogroup mailbox
  40. * @{
  41. */
  42. /*! @file */
  43. /******************************************************************************
  44. * Definitions
  45. *****************************************************************************/
  46. /* Component ID definition, used by tools. */
  47. #ifndef FSL_COMPONENT_ID
  48. #define FSL_COMPONENT_ID "platform.drivers.mailbox"
  49. #endif
  50. /*! @name Driver version */
  51. /*@{*/
  52. /*! @brief MAILBOX driver version 2.0.0. */
  53. #define FSL_MAILBOX_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
  54. /*@}*/
  55. /*!
  56. * @brief CPU ID.
  57. */
  58. typedef enum _mailbox_cpu_id
  59. {
  60. kMAILBOX_CM0Plus = 0,
  61. kMAILBOX_CM4
  62. } mailbox_cpu_id_t;
  63. /*******************************************************************************
  64. * API
  65. ******************************************************************************/
  66. #ifdef __cplusplus
  67. extern "C" {
  68. #endif
  69. /*!
  70. * @name MAILBOX initialization
  71. * @{
  72. */
  73. /*!
  74. * @brief Initializes the MAILBOX module.
  75. *
  76. * This function enables the MAILBOX clock only.
  77. *
  78. * @param base MAILBOX peripheral base address.
  79. */
  80. static inline void MAILBOX_Init(MAILBOX_Type *base)
  81. {
  82. #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
  83. CLOCK_EnableClock(kCLOCK_Mailbox);
  84. #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
  85. }
  86. /*!
  87. * @brief De-initializes the MAILBOX module.
  88. *
  89. * This function disables the MAILBOX clock only.
  90. *
  91. * @param base MAILBOX peripheral base address.
  92. */
  93. static inline void MAILBOX_Deinit(MAILBOX_Type *base)
  94. {
  95. #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
  96. CLOCK_DisableClock(kCLOCK_Mailbox);
  97. #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
  98. }
  99. /* @} */
  100. /*!
  101. * @brief Set data value in the mailbox based on the CPU ID.
  102. *
  103. * @param base MAILBOX peripheral base address.
  104. * @param cpu_id CPU id, kMAILBOX_CM0Plus is M0+ or kMAILBOX_CM4 is M4.
  105. * @param mboxData Data to send in the mailbox.
  106. *
  107. * @note Sets a data value to send via the MAILBOX to the other core.
  108. */
  109. static inline void MAILBOX_SetValue(MAILBOX_Type *base, mailbox_cpu_id_t cpu_id, uint32_t mboxData)
  110. {
  111. assert((cpu_id == kMAILBOX_CM0Plus) || (cpu_id == kMAILBOX_CM4));
  112. base->MBOXIRQ[cpu_id].IRQ = mboxData;
  113. }
  114. /*!
  115. * @brief Get data in the mailbox based on the CPU ID.
  116. *
  117. * @param base MAILBOX peripheral base address.
  118. * @param cpu_id CPU id, kMAILBOX_CM0Plus is M0+ or kMAILBOX_CM4 is M4.
  119. *
  120. * @return Current mailbox data.
  121. */
  122. static inline uint32_t MAILBOX_GetValue(MAILBOX_Type *base, mailbox_cpu_id_t cpu_id)
  123. {
  124. assert((cpu_id == kMAILBOX_CM0Plus) || (cpu_id == kMAILBOX_CM4));
  125. return base->MBOXIRQ[cpu_id].IRQ;
  126. }
  127. /*!
  128. * @brief Set data bits in the mailbox based on the CPU ID.
  129. *
  130. * @param base MAILBOX peripheral base address.
  131. * @param cpu_id CPU id, kMAILBOX_CM0Plus is M0+ or kMAILBOX_CM4 is M4.
  132. * @param mboxSetBits Data bits to set in the mailbox.
  133. *
  134. * @note Sets data bits to send via the MAILBOX to the other core. A value of 0 will
  135. * do nothing. Only sets bits selected with a 1 in it's bit position.
  136. */
  137. static inline void MAILBOX_SetValueBits(MAILBOX_Type *base, mailbox_cpu_id_t cpu_id, uint32_t mboxSetBits)
  138. {
  139. assert((cpu_id == kMAILBOX_CM0Plus) || (cpu_id == kMAILBOX_CM4));
  140. base->MBOXIRQ[cpu_id].IRQSET = mboxSetBits;
  141. }
  142. /*!
  143. * @brief Clear data bits in the mailbox based on the CPU ID.
  144. *
  145. * @param base MAILBOX peripheral base address.
  146. * @param cpu_id CPU id, kMAILBOX_CM0Plus is M0+ or kMAILBOX_CM4 is M4.
  147. * @param mboxClrBits Data bits to clear in the mailbox.
  148. *
  149. * @note Clear data bits to send via the MAILBOX to the other core. A value of 0 will
  150. * do nothing. Only clears bits selected with a 1 in it's bit position.
  151. */
  152. static inline void MAILBOX_ClearValueBits(MAILBOX_Type *base, mailbox_cpu_id_t cpu_id, uint32_t mboxClrBits)
  153. {
  154. assert((cpu_id == kMAILBOX_CM0Plus) || (cpu_id == kMAILBOX_CM4));
  155. base->MBOXIRQ[cpu_id].IRQCLR = mboxClrBits;
  156. }
  157. /*!
  158. * @brief Get MUTEX state and lock mutex
  159. *
  160. * @param base MAILBOX peripheral base address.
  161. *
  162. * @return See note
  163. *
  164. * @note Returns '1' if the mutex was taken or '0' if another resources has the
  165. * mutex locked. Once a mutex is taken, it can be returned with the MAILBOX_SetMutex()
  166. * function.
  167. */
  168. static inline uint32_t MAILBOX_GetMutex(MAILBOX_Type *base)
  169. {
  170. return (base->MUTEX & MAILBOX_MUTEX_EX_MASK);
  171. }
  172. /*!
  173. * @brief Set MUTEX state
  174. *
  175. * @param base MAILBOX peripheral base address.
  176. *
  177. * @note Sets mutex state to '1' and allows other resources to get the mutex.
  178. */
  179. static inline void MAILBOX_SetMutex(MAILBOX_Type *base)
  180. {
  181. base->MUTEX = MAILBOX_MUTEX_EX_MASK;
  182. }
  183. #if defined(__cplusplus)
  184. }
  185. #endif /*_cplusplus*/
  186. /*@}*/
  187. #endif /* _FSL_MAILBOX_H_ */