fsl_xbarb.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * Copyright (c) 2015, Freescale Semiconductor, Inc.
  3. * Copyright 2016-2019 NXP
  4. * All rights reserved.
  5. *
  6. * SPDX-License-Identifier: BSD-3-Clause
  7. */
  8. #include "fsl_xbarb.h"
  9. /*******************************************************************************
  10. * Definitions
  11. ******************************************************************************/
  12. /* Component ID definition, used by tools. */
  13. #ifndef FSL_COMPONENT_ID
  14. #define FSL_COMPONENT_ID "platform.drivers.xbarb"
  15. #endif
  16. typedef union
  17. {
  18. uint8_t _u8[2];
  19. uint16_t _u16;
  20. } xbarb_u8_u16_t;
  21. /*******************************************************************************
  22. * Prototypes
  23. ******************************************************************************/
  24. /*!
  25. * @brief Get the XBARB instance from peripheral base address.
  26. *
  27. * @param base XBARB peripheral base address.
  28. * @return XBARB instance.
  29. */
  30. static uint32_t XBARB_GetInstance(XBARB_Type *base);
  31. /*******************************************************************************
  32. * Variables
  33. ******************************************************************************/
  34. /* Array of XBARB peripheral base address. */
  35. static XBARB_Type *const s_xbarbBases[] = XBARB_BASE_PTRS;
  36. #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
  37. /* Array of XBARB clock name. */
  38. static const clock_ip_name_t s_xbarbClock[] = XBARB_CLOCKS;
  39. #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
  40. /*******************************************************************************
  41. * Code
  42. ******************************************************************************/
  43. static uint32_t XBARB_GetInstance(XBARB_Type *base)
  44. {
  45. uint32_t instance;
  46. /* Find the instance index from base address mappings. */
  47. for (instance = 0; instance < ARRAY_SIZE(s_xbarbBases); instance++)
  48. {
  49. if (s_xbarbBases[instance] == base)
  50. {
  51. break;
  52. }
  53. }
  54. assert(instance < ARRAY_SIZE(s_xbarbBases));
  55. return instance;
  56. }
  57. /*!
  58. * brief Initializes the XBARB module.
  59. *
  60. * This function un-gates the XBARB clock.
  61. *
  62. * param base XBARB peripheral address.
  63. */
  64. void XBARB_Init(XBARB_Type *base)
  65. {
  66. #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
  67. /* Enable XBARB module clock. */
  68. CLOCK_EnableClock(s_xbarbClock[XBARB_GetInstance(base)]);
  69. #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
  70. }
  71. /*!
  72. * brief Shuts down the XBARB module.
  73. *
  74. * This function disables XBARB clock.
  75. *
  76. * param base XBARB peripheral address.
  77. */
  78. void XBARB_Deinit(XBARB_Type *base)
  79. {
  80. #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
  81. /* Disable XBARB module clock. */
  82. CLOCK_DisableClock(s_xbarbClock[XBARB_GetInstance(base)]);
  83. #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
  84. }
  85. /*!
  86. * brief Configures a connection between the selected XBARB_IN[*] input and the XBARB_OUT[*] output signal.
  87. *
  88. * This function configures which XBARB input is connected to the selected XBARB output.
  89. * If more than one XBARB module is available, only the inputs and outputs from the same module
  90. * can be connected.
  91. *
  92. * param base XBARB peripheral address.
  93. * param input XBARB input signal.
  94. * param output XBARB output signal.
  95. */
  96. void XBARB_SetSignalsConnection(XBARB_Type *base, xbar_input_signal_t input, xbar_output_signal_t output)
  97. {
  98. xbarb_u8_u16_t regVal;
  99. uint8_t byteInReg;
  100. uint8_t outputIndex = (uint8_t)output;
  101. byteInReg = outputIndex % 2U;
  102. regVal._u16 = XBARB_SELx(base, outputIndex);
  103. regVal._u8[byteInReg] = (uint8_t)input;
  104. XBARB_SELx(base, outputIndex) = regVal._u16;
  105. }