fsl_xbarb.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copyright (c) 2015, Freescale Semiconductor, Inc.
  3. * Copyright 2016-2017 NXP
  4. *
  5. * Redistribution and use in source and binary forms, with or without modification,
  6. * are permitted provided that the following conditions are met:
  7. *
  8. * o Redistributions of source code must retain the above copyright notice, this list
  9. * of conditions and the following disclaimer.
  10. *
  11. * o Redistributions in binary form must reproduce the above copyright notice, this
  12. * list of conditions and the following disclaimer in the documentation and/or
  13. * other materials provided with the distribution.
  14. *
  15. * o Neither the name of the copyright holder nor the names of its
  16. * contributors may be used to endorse or promote products derived from this
  17. * software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  20. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  23. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  24. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  25. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  26. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #include "fsl_xbarb.h"
  31. /*******************************************************************************
  32. * Definitions
  33. ******************************************************************************/
  34. /*******************************************************************************
  35. * Prototypes
  36. ******************************************************************************/
  37. /*!
  38. * @brief Get the XBARB instance from peripheral base address.
  39. *
  40. * @param base XBARB peripheral base address.
  41. * @return XBARB instance.
  42. */
  43. static uint32_t XBARB_GetInstance(XBARB_Type *base);
  44. /*******************************************************************************
  45. * Variables
  46. ******************************************************************************/
  47. /* Array of XBARB peripheral base address. */
  48. static XBARB_Type *const s_xbarbBases[] = XBARB_BASE_PTRS;
  49. #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
  50. /* Array of XBARB clock name. */
  51. static const clock_ip_name_t s_xbarbClock[] = XBARB_CLOCKS;
  52. #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
  53. /*******************************************************************************
  54. * Code
  55. ******************************************************************************/
  56. static uint32_t XBARB_GetInstance(XBARB_Type *base)
  57. {
  58. uint32_t instance;
  59. /* Find the instance index from base address mappings. */
  60. for (instance = 0; instance < ARRAY_SIZE(s_xbarbBases); instance++)
  61. {
  62. if (s_xbarbBases[instance] == base)
  63. {
  64. break;
  65. }
  66. }
  67. assert(instance < ARRAY_SIZE(s_xbarbBases));
  68. return instance;
  69. }
  70. void XBARB_Init(XBARB_Type *base)
  71. {
  72. #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
  73. /* Enable XBARB module clock. */
  74. CLOCK_EnableClock(s_xbarbClock[XBARB_GetInstance(base)]);
  75. #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
  76. }
  77. void XBARB_Deinit(XBARB_Type *base)
  78. {
  79. #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
  80. /* Disable XBARB module clock. */
  81. CLOCK_DisableClock(s_xbarbClock[XBARB_GetInstance(base)]);
  82. #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
  83. }
  84. void XBARB_SetSignalsConnection(XBARB_Type *base, xbar_input_signal_t input, xbar_output_signal_t output)
  85. {
  86. XBARB_WR_SELx_SELx(base, (((uint16_t)input) & 0xFFU), (((uint16_t)output) & 0xFFU));
  87. }