fsl_xbara.c 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /*
  2. * The Clear BSD License
  3. * Copyright (c) 2015, Freescale Semiconductor, Inc.
  4. * Copyright 2016-2017 NXP
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without modification,
  8. * are permitted (subject to the limitations in the disclaimer below) provided
  9. * that the following conditions are met:
  10. *
  11. * o Redistributions of source code must retain the above copyright notice, this list
  12. * of conditions and the following disclaimer.
  13. *
  14. * o Redistributions in binary form must reproduce the above copyright notice, this
  15. * list of conditions and the following disclaimer in the documentation and/or
  16. * other materials provided with the distribution.
  17. *
  18. * o Neither the name of the copyright holder nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  24. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  25. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  26. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  27. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  28. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  29. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  30. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  31. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  32. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #include "fsl_xbara.h"
  35. /*******************************************************************************
  36. * Definitions
  37. ******************************************************************************/
  38. /* Component ID definition, used by tools. */
  39. #ifndef FSL_COMPONENT_ID
  40. #define FSL_COMPONENT_ID "platform.drivers.xbara"
  41. #endif
  42. /*******************************************************************************
  43. * Prototypes
  44. ******************************************************************************/
  45. /*!
  46. * @brief Get the XBARA instance from peripheral base address.
  47. *
  48. * @param base XBARA peripheral base address.
  49. * @return XBARA instance.
  50. */
  51. static uint32_t XBARA_GetInstance(XBARA_Type *base);
  52. /*******************************************************************************
  53. * Variables
  54. ******************************************************************************/
  55. /* Array of XBARA peripheral base address. */
  56. static XBARA_Type *const s_xbaraBases[] = XBARA_BASE_PTRS;
  57. #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
  58. /* Array of XBARA clock name. */
  59. static const clock_ip_name_t s_xbaraClock[] = XBARA_CLOCKS;
  60. #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
  61. /*******************************************************************************
  62. * Code
  63. ******************************************************************************/
  64. static uint32_t XBARA_GetInstance(XBARA_Type *base)
  65. {
  66. uint32_t instance;
  67. /* Find the instance index from base address mappings. */
  68. for (instance = 0; instance < ARRAY_SIZE(s_xbaraBases); instance++)
  69. {
  70. if (s_xbaraBases[instance] == base)
  71. {
  72. break;
  73. }
  74. }
  75. assert(instance < ARRAY_SIZE(s_xbaraBases));
  76. return instance;
  77. }
  78. void XBARA_Init(XBARA_Type *base)
  79. {
  80. #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
  81. /* Enable XBARA module clock. */
  82. CLOCK_EnableClock(s_xbaraClock[XBARA_GetInstance(base)]);
  83. #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
  84. }
  85. void XBARA_Deinit(XBARA_Type *base)
  86. {
  87. #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
  88. /* Disable XBARA module clock. */
  89. CLOCK_DisableClock(s_xbaraClock[XBARA_GetInstance(base)]);
  90. #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
  91. }
  92. void XBARA_SetSignalsConnection(XBARA_Type *base, xbar_input_signal_t input, xbar_output_signal_t output)
  93. {
  94. XBARA_WR_SELx_SELx(base, (((uint16_t)input) & 0xFFU), (((uint16_t)output) & 0xFFU));
  95. }
  96. uint32_t XBARA_GetStatusFlags(XBARA_Type *base)
  97. {
  98. uint32_t status_flag;
  99. status_flag = ((base->CTRL0 & (XBARA_CTRL0_STS0_MASK | XBARA_CTRL0_STS1_MASK)) |
  100. ((base->CTRL1 & (XBARA_CTRL1_STS2_MASK | XBARA_CTRL1_STS3_MASK)) << 16U));
  101. return status_flag;
  102. }
  103. void XBARA_ClearStatusFlags(XBARA_Type *base, uint32_t mask)
  104. {
  105. uint16_t regVal;
  106. /* Assign regVal to CTRL0 register's value */
  107. regVal = (base->CTRL0);
  108. /* Perform this command to avoid writing 1 into interrupt flag bits */
  109. regVal &= (uint16_t)(~(XBARA_CTRL0_STS0_MASK | XBARA_CTRL0_STS1_MASK));
  110. /* Write 1 to interrupt flag bits corresponding to mask */
  111. regVal |= (uint16_t)(mask & (XBARA_CTRL0_STS0_MASK | XBARA_CTRL0_STS1_MASK));
  112. /* Write regVal value into CTRL0 register */
  113. base->CTRL0 = regVal;
  114. /* Assign regVal to CTRL1 register's value */
  115. regVal = (base->CTRL1);
  116. /* Perform this command to avoid writing 1 into interrupt flag bits */
  117. regVal &= (uint16_t)(~(XBARA_CTRL1_STS2_MASK | XBARA_CTRL1_STS3_MASK));
  118. /* Write 1 to interrupt flag bits corresponding to mask */
  119. regVal |= (uint16_t)((mask >> 16U) & (XBARA_CTRL1_STS2_MASK | XBARA_CTRL1_STS3_MASK));
  120. /* Write regVal value into CTRL1 register */
  121. base->CTRL1 = regVal;
  122. }
  123. void XBARA_SetOutputSignalConfig(XBARA_Type *base,
  124. xbar_output_signal_t output,
  125. const xbara_control_config_t *controlConfig)
  126. {
  127. uint16_t regVal;
  128. /* Set active edge for edge detection, set interrupt or DMA function. */
  129. switch ((uint16_t)output)
  130. {
  131. #if defined(FSL_FEATURE_XBARA_OUTPUT_DMA_CH_MUX_REQ_30) && FSL_FEATURE_XBARA_OUTPUT_DMA_CH_MUX_REQ_30
  132. case kXBARA1_OutputDmaChMuxReq30:
  133. #else
  134. case kXBARA_OutputDmamux18:
  135. #endif
  136. /* Assign regVal to CTRL0 register's value */
  137. regVal = (base->CTRL0);
  138. /* Perform this command to avoid writing 1 into interrupt flag bits and clears bit DEN0, IEN0 */
  139. regVal &= (uint16_t)(
  140. ~(XBARA_CTRL0_STS0_MASK | XBARA_CTRL0_STS1_MASK | XBARA_CTRL0_DEN0_MASK | XBARA_CTRL0_IEN0_MASK));
  141. /* Configure edge and request type */
  142. regVal |= (uint16_t)(XBARA_CTRL0_EDGE0(controlConfig->activeEdge) |
  143. ((controlConfig->requestType) << XBARA_CTRL0_DEN0_SHIFT));
  144. /* Write regVal value into CTRL0 register */
  145. base->CTRL0 = regVal;
  146. break;
  147. #if defined(FSL_FEATURE_XBARA_OUTPUT_DMA_CH_MUX_REQ_31) && FSL_FEATURE_XBARA_OUTPUT_DMA_CH_MUX_REQ_31
  148. case kXBARA1_OutputDmaChMuxReq31:
  149. #else
  150. case kXBARA_OutputDmamux19:
  151. #endif
  152. /* Assign regVal to CTRL0 register's value */
  153. regVal = (base->CTRL0);
  154. /* Perform this command to avoid writing 1 into interrupt flag bits and clears bit DEN1, IEN1 */
  155. regVal &= (uint16_t)(
  156. ~(XBARA_CTRL0_STS0_MASK | XBARA_CTRL0_STS1_MASK | XBARA_CTRL0_DEN1_MASK | XBARA_CTRL0_IEN1_MASK));
  157. /* Configure edge and request type */
  158. regVal |= (uint16_t)(XBARA_CTRL0_EDGE1(controlConfig->activeEdge) |
  159. ((controlConfig->requestType) << XBARA_CTRL0_DEN1_SHIFT));
  160. /* Write regVal value into CTRL0 register */
  161. base->CTRL0 = regVal;
  162. break;
  163. #if defined(FSL_FEATURE_XBARA_OUTPUT_DMA_CH_MUX_REQ_94) && FSL_FEATURE_XBARA_OUTPUT_DMA_CH_MUX_REQ_94
  164. case kXBARA1_OutputDmaChMuxReq94:
  165. #else
  166. case kXBARA_OutputDmamux20:
  167. #endif
  168. /* Assign regVal to CTRL1 register's value */
  169. regVal = (base->CTRL1);
  170. /* Perform this command to avoid writing 1 into interrupt flag bits and clears bit DEN2, IEN2 */
  171. regVal &= (uint16_t)(
  172. ~(XBARA_CTRL1_STS2_MASK | XBARA_CTRL1_STS3_MASK | XBARA_CTRL1_DEN2_MASK | XBARA_CTRL1_IEN2_MASK));
  173. /* Configure edge and request type */
  174. regVal |= (uint16_t)(XBARA_CTRL1_EDGE2(controlConfig->activeEdge) |
  175. ((controlConfig->requestType) << XBARA_CTRL1_DEN2_SHIFT));
  176. /* Write regVal value into CTRL1 register */
  177. base->CTRL1 = regVal;
  178. break;
  179. #if defined(FSL_FEATURE_XBARA_OUTPUT_DMA_CH_MUX_REQ_95) && FSL_FEATURE_XBARA_OUTPUT_DMA_CH_MUX_REQ_95
  180. case kXBARA1_OutputDmaChMuxReq95:
  181. #else
  182. case kXBARA_OutputDmamux21:
  183. #endif
  184. /* Assign regVal to CTRL1 register's value */
  185. regVal = (base->CTRL1);
  186. /* Perform this command to avoid writing 1 into interrupt flag bits and clears bit DEN3, IEN3 */
  187. regVal &= (uint16_t)(
  188. ~(XBARA_CTRL1_STS2_MASK | XBARA_CTRL1_STS3_MASK | XBARA_CTRL1_DEN3_MASK | XBARA_CTRL1_IEN3_MASK));
  189. /* Configure edge and request type */
  190. regVal |= (uint16_t)(XBARA_CTRL1_EDGE3(controlConfig->activeEdge) |
  191. ((controlConfig->requestType) << XBARA_CTRL1_DEN3_SHIFT));
  192. /* Write regVal value into CTRL1 register */
  193. base->CTRL1 = regVal;
  194. break;
  195. default:
  196. break;
  197. }
  198. }