fsl_xbarb.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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_xbarb.h"
  35. /*******************************************************************************
  36. * Definitions
  37. ******************************************************************************/
  38. /* Component ID definition, used by tools. */
  39. #ifndef FSL_COMPONENT_ID
  40. #define FSL_COMPONENT_ID "platform.drivers.xbarb"
  41. #endif
  42. /*******************************************************************************
  43. * Prototypes
  44. ******************************************************************************/
  45. /*!
  46. * @brief Get the XBARB instance from peripheral base address.
  47. *
  48. * @param base XBARB peripheral base address.
  49. * @return XBARB instance.
  50. */
  51. static uint32_t XBARB_GetInstance(XBARB_Type *base);
  52. /*******************************************************************************
  53. * Variables
  54. ******************************************************************************/
  55. /* Array of XBARB peripheral base address. */
  56. static XBARB_Type *const s_xbarbBases[] = XBARB_BASE_PTRS;
  57. #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
  58. /* Array of XBARB clock name. */
  59. static const clock_ip_name_t s_xbarbClock[] = XBARB_CLOCKS;
  60. #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
  61. /*******************************************************************************
  62. * Code
  63. ******************************************************************************/
  64. static uint32_t XBARB_GetInstance(XBARB_Type *base)
  65. {
  66. uint32_t instance;
  67. /* Find the instance index from base address mappings. */
  68. for (instance = 0; instance < ARRAY_SIZE(s_xbarbBases); instance++)
  69. {
  70. if (s_xbarbBases[instance] == base)
  71. {
  72. break;
  73. }
  74. }
  75. assert(instance < ARRAY_SIZE(s_xbarbBases));
  76. return instance;
  77. }
  78. void XBARB_Init(XBARB_Type *base)
  79. {
  80. #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
  81. /* Enable XBARB module clock. */
  82. CLOCK_EnableClock(s_xbarbClock[XBARB_GetInstance(base)]);
  83. #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
  84. }
  85. void XBARB_Deinit(XBARB_Type *base)
  86. {
  87. #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
  88. /* Disable XBARB module clock. */
  89. CLOCK_DisableClock(s_xbarbClock[XBARB_GetInstance(base)]);
  90. #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
  91. }
  92. void XBARB_SetSignalsConnection(XBARB_Type *base, xbar_input_signal_t input, xbar_output_signal_t output)
  93. {
  94. XBARB_WR_SELx_SELx(base, (((uint16_t)input) & 0xFFU), (((uint16_t)output) & 0xFFU));
  95. }