mailbox_5410x.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /*
  2. * @brief LPC5410X Mailbox M4/M0+ driver
  3. *
  4. * @note
  5. * Copyright(C) NXP Semiconductors, 2014
  6. * All rights reserved.
  7. *
  8. * @par
  9. * Software that is described herein is for illustrative purposes only
  10. * which provides customers with programming information regarding the
  11. * LPC products. This software is supplied "AS IS" without any warranties of
  12. * any kind, and NXP Semiconductors and its licensor disclaim any and
  13. * all warranties, express or implied, including all implied warranties of
  14. * merchantability, fitness for a particular purpose and non-infringement of
  15. * intellectual property rights. NXP Semiconductors assumes no responsibility
  16. * or liability for the use of the software, conveys no license or rights under any
  17. * patent, copyright, mask work right, or any other intellectual property rights in
  18. * or to any products. NXP Semiconductors reserves the right to make changes
  19. * in the software without notification. NXP Semiconductors also makes no
  20. * representation or warranty that such application will be suitable for the
  21. * specified use without further testing or modification.
  22. *
  23. * @par
  24. * Permission to use, copy, modify, and distribute this software and its
  25. * documentation is hereby granted, under NXP Semiconductors' and its
  26. * licensor's relevant copyrights in the software, without fee, provided that it
  27. * is used in conjunction with NXP Semiconductors microcontrollers. This
  28. * copyright, permission, and disclaimer notice must appear in all copies of
  29. * this code.
  30. */
  31. #ifndef __MAILBOX_5410X_H_
  32. #define __MAILBOX_5410X_H_
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. /** @defgroup MAILBOX_5410X CHIP: LPC5410X Mailbox M4/M0+ driver
  37. * @ingroup CHIP_5410X_DRIVERS
  38. * @{
  39. */
  40. /* Mailbox indexes */
  41. typedef enum {
  42. MAILBOX_CM0PLUS = 0,
  43. MAILBOX_CM4
  44. } MBOX_IDX_T;
  45. #define MAILBOX_AVAIL (MAILBOX_CM4 + 1) /* Number of available mailboxes */
  46. /** Individual mailbox IRQ structure */
  47. typedef struct {
  48. __IO uint32_t IRQ; /*!< Mailbox data */
  49. __O uint32_t IRQSET; /*!< Mailbox data set bits only */
  50. __O uint32_t IRQCLR; /*!< Mailbox dataclearset bits only */
  51. __I uint32_t RESERVED;
  52. } LPC_MBOXIRQ_T;
  53. /** Mailbox register structure */
  54. typedef struct { /*!< Mailbox register structure */
  55. LPC_MBOXIRQ_T BOX[MAILBOX_AVAIL]; /*!< Mailbox, offset 0 = M0+, offset 1 = M4 */
  56. LPC_MBOXIRQ_T RESERVED1[15 - MAILBOX_AVAIL];
  57. __I uint32_t RESERVED2[2];
  58. __IO uint32_t MUTEX; /*!< Mutex */
  59. } LPC_MBOX_T;
  60. /**
  61. * @brief Initialize mailbox
  62. * @param pMBOX : Pointer to the mailbox register structure
  63. * @return Nothing
  64. * @note Even if both cores use the amilbox, only 1 core should initialize it.
  65. */
  66. STATIC INLINE void Chip_MBOX_Init(LPC_MBOX_T *pMBOX)
  67. {
  68. Chip_Clock_EnablePeriphClock(SYSCON_CLOCK_MAILBOX);
  69. Chip_SYSCON_PeriphReset(RESET_MAILBOX);
  70. }
  71. /**
  72. * @brief Shutdown mailbox
  73. * @param pMBOX : Pointer to the mailbox register structure
  74. * @return Nothing
  75. */
  76. STATIC INLINE void Chip_MBOX_DeInit(LPC_MBOX_T *pMBOX)
  77. {
  78. Chip_Clock_DisablePeriphClock(SYSCON_CLOCK_MAILBOX);
  79. }
  80. /**
  81. * @brief Set data value in the mailbox based on the CPU ID
  82. * @param pMBOX : Pointer to the mailbox register structure
  83. * @param cpu_id : MAILBOX_CM0PLUS is M0+ or MAILBOX_CM4 is M4
  84. * @param mboxData : data to send in the mailbox
  85. * @return Nothing
  86. * @note Sets a data value to send via the MBOX to the other core.
  87. */
  88. STATIC INLINE void Chip_MBOX_SetValue(LPC_MBOX_T *pMBOX, uint32_t cpu_id, uint32_t mboxData)
  89. {
  90. pMBOX->BOX[cpu_id].IRQ = mboxData;
  91. }
  92. /**
  93. * @brief Set data bits in the mailbox based on the CPU ID
  94. * @param pMBOX : Pointer to the mailbox register structure
  95. * @param cpu_id : MAILBOX_CM0PLUS is M0+ or MAILBOX_CM4 is M4
  96. * @param mboxSetBits : data bits to set in the mailbox
  97. * @return Nothing
  98. * @note Sets data bits to send via the MBOX to the other core, A value of 0 will
  99. * do nothing. Only sets bits selected with a 1 in it's bit position.
  100. */
  101. STATIC INLINE void Chip_MBOX_SetValueBits(LPC_MBOX_T *pMBOX, uint32_t cpu_id, uint32_t mboxSetBits)
  102. {
  103. pMBOX->BOX[cpu_id].IRQSET = mboxSetBits;
  104. }
  105. /**
  106. * @brief Clear data bits in the mailbox based on the CPU ID
  107. * @param pMBOX : Pointer to the mailbox register structure
  108. * @param cpu_id : MAILBOX_CM0PLUS is M0+ or MAILBOX_CM4 is M4
  109. * @param mboxClrBits : data bits to clear in the mailbox
  110. * @return Nothing
  111. * @note Clear data bits to send via the MBOX to the other core. A value of 0 will
  112. * do nothing. Only clears bits selected with a 1 in it's bit position.
  113. */
  114. STATIC INLINE void Chip_MBOX_ClearValueBits(LPC_MBOX_T *pMBOX, uint32_t cpu_id, uint32_t mboxClrBits)
  115. {
  116. pMBOX->BOX[cpu_id].IRQCLR = mboxClrBits;
  117. }
  118. /**
  119. * @brief Get data in the mailbox based on the cpu_id
  120. * @param pMBOX : Pointer to the mailbox register structure
  121. * @param cpu_id : MAILBOX_CM0PLUS is M0+ or MAILBOX_CM4 is M4
  122. * @return Current mailbox data
  123. */
  124. STATIC INLINE uint32_t Chip_MBOX_GetValue(LPC_MBOX_T *pMBOX, uint32_t cpu_id)
  125. {
  126. return pMBOX->BOX[cpu_id].IRQ;
  127. }
  128. /**
  129. * @brief Get MUTEX state and lock mutex
  130. * @param pMBOX : Pointer to the mailbox register structure
  131. * @return See note
  132. * @note Returns '1' if the mutex was taken or '0' if another resources has the
  133. * mutex locked. Once a mutex is taken, it can be returned with the Chip_MBOX_SetMutex()
  134. * function.
  135. */
  136. STATIC INLINE uint32_t Chip_MBOX_GetMutex(LPC_MBOX_T *pMBOX)
  137. {
  138. return pMBOX->MUTEX;
  139. }
  140. /**
  141. * @brief Set MUTEX state
  142. * @param pMBOX : Pointer to the mailbox register structure
  143. * @return Nothing
  144. * @note Sets mutex state to '1' and allows other resources to get the mutex
  145. */
  146. STATIC INLINE void Chip_MBOX_SetMutex(LPC_MBOX_T *pMBOX)
  147. {
  148. pMBOX->MUTEX = 1;
  149. }
  150. /**
  151. * @}
  152. */
  153. #ifdef __cplusplus
  154. }
  155. #endif
  156. #endif /* __MAILBOX_5410X_H_ */