fsl_dmamux.c 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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_dmamux.h"
  35. /*******************************************************************************
  36. * Definitions
  37. ******************************************************************************/
  38. /*******************************************************************************
  39. * Prototypes
  40. ******************************************************************************/
  41. /*!
  42. * @brief Get instance number for DMAMUX.
  43. *
  44. * @param base DMAMUX peripheral base address.
  45. */
  46. static uint32_t DMAMUX_GetInstance(DMAMUX_Type *base);
  47. /*******************************************************************************
  48. * Variables
  49. ******************************************************************************/
  50. /*! @brief Array to map DMAMUX instance number to base pointer. */
  51. static DMAMUX_Type *const s_dmamuxBases[] = DMAMUX_BASE_PTRS;
  52. #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
  53. /*! @brief Array to map DMAMUX instance number to clock name. */
  54. static const clock_ip_name_t s_dmamuxClockName[] = DMAMUX_CLOCKS;
  55. #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
  56. /*******************************************************************************
  57. * Code
  58. ******************************************************************************/
  59. static uint32_t DMAMUX_GetInstance(DMAMUX_Type *base)
  60. {
  61. uint32_t instance;
  62. /* Find the instance index from base address mappings. */
  63. for (instance = 0; instance < ARRAY_SIZE(s_dmamuxBases); instance++)
  64. {
  65. if (s_dmamuxBases[instance] == base)
  66. {
  67. break;
  68. }
  69. }
  70. assert(instance < ARRAY_SIZE(s_dmamuxBases));
  71. return instance;
  72. }
  73. void DMAMUX_Init(DMAMUX_Type *base)
  74. {
  75. #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
  76. CLOCK_EnableClock(s_dmamuxClockName[DMAMUX_GetInstance(base)]);
  77. #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
  78. }
  79. void DMAMUX_Deinit(DMAMUX_Type *base)
  80. {
  81. #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
  82. CLOCK_DisableClock(s_dmamuxClockName[DMAMUX_GetInstance(base)]);
  83. #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
  84. }