ccm_pll.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. * Copyright (c) 2012, Freescale Semiconductor, Inc.
  3. * All rights reserved.
  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 Freescale Semiconductor, Inc. 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. #ifndef _CCM_PLL_H_
  31. #define _CCM_PLL_H_
  32. #include "sdk_types.h"
  33. //! @addtogroup diag_clocks
  34. //! @{
  35. ////////////////////////////////////////////////////////////////////////////////
  36. // Definitions
  37. ////////////////////////////////////////////////////////////////////////////////
  38. #define CLK_SRC_32K 32768
  39. //! @brief Create a clock gate bit mask value.
  40. //! @param x 0..15, for CG0 to CG15
  41. #define CG(x) (3 << (x*2))
  42. //! @brief Constants for CCM CCGR register fields.
  43. enum _clock_gate_constants
  44. {
  45. CLOCK_ON = 0x3, //!< Clock always on in both run and stop modes.
  46. CLOCK_ON_RUN = 0x1, //!< Clock on only in run mode.
  47. CLOCK_OFF = 0x0 //!< Clocked gated off.
  48. };
  49. //! @brief Low power mdoes.
  50. typedef enum _lp_modes {
  51. RUN_MODE,
  52. WAIT_MODE,
  53. STOP_MODE,
  54. } lp_modes_t;
  55. //! @brief Main clock sources.
  56. typedef enum _main_clocks {
  57. CPU_CLK,
  58. AXI_CLK,
  59. MMDC_CH0_AXI_CLK,
  60. AHB_CLK,
  61. IPG_CLK,
  62. IPG_PER_CLK,
  63. MMDC_CH1_AXI_CLK,
  64. } main_clocks_t;
  65. //! @brief Peripheral clocks.
  66. typedef enum _peri_clocks {
  67. UART1_MODULE_CLK,
  68. UART2_MODULE_CLK,
  69. UART3_MODULE_CLK,
  70. UART4_MODULE_CLK,
  71. UART5_MODULE_CLK,
  72. UART6_MODULE_CLK,
  73. UART7_MODULE_CLK,
  74. UART8_MODULE_CLK,
  75. SSI1_BAUD,
  76. SSI2_BAUD,
  77. CSI_BAUD,
  78. MSTICK1_CLK,
  79. MSTICK2_CLK,
  80. RAWNAND_CLK,
  81. USB_CLK,
  82. VPU_CLK,
  83. SPI_CLK,
  84. CAN_CLK
  85. } peri_clocks_t;
  86. //! @brief Available PLLs.
  87. typedef enum plls {
  88. PLL1,
  89. PLL2,
  90. PLL3,
  91. PLL4,
  92. PLL5,
  93. } plls_t;
  94. extern const uint32_t PLL1_OUTPUT;
  95. extern const uint32_t PLL2_OUTPUT[];
  96. extern const uint32_t PLL3_OUTPUT[];
  97. extern const uint32_t PLL4_OUTPUT;
  98. extern const uint32_t PLL5_OUTPUT;
  99. ////////////////////////////////////////////////////////////////////////////////
  100. // API
  101. ////////////////////////////////////////////////////////////////////////////////
  102. #if defined(__cplusplus)
  103. extern "C" {
  104. #endif
  105. //! @brief Set/unset clock gating for a peripheral.
  106. //! @param base_address configure clock gating for that module from the base address.
  107. //! @param gating_mode clock gating mode: CLOCK_ON or CLOCK_OFF.
  108. void clock_gating_config(uint32_t base_address, uint32_t gating_mode);
  109. //! @brief Returns the frequency of a clock in megahertz.
  110. uint32_t get_main_clock(main_clocks_t clk);
  111. //! @brief Returns the frequency of a clock in megahertz.
  112. uint32_t get_peri_clock(peri_clocks_t clk);
  113. //! @brief Inits clock sources.
  114. void ccm_init(void);
  115. //! @brief Prepare and enter in a low power mode.
  116. //! @param lp_mode low power mode : WAIT_MODE or STOP_MODE.
  117. void ccm_enter_low_power(lp_modes_t lp_mode);
  118. //! @brief Mask/unmask an interrupt source that can wake up the processor when in a
  119. //! low power mode.
  120. //!
  121. //! @param irq_id ID of the interrupt to mask/unmask.
  122. //! @param doEnable Pass true to unmask the source ID.
  123. void ccm_set_lpm_wakeup_source(uint32_t irq_id, bool doEnable);
  124. #if defined(__cplusplus)
  125. }
  126. #endif
  127. //! @}
  128. #endif
  129. ////////////////////////////////////////////////////////////////////////////////
  130. // EOF
  131. ////////////////////////////////////////////////////////////////////////////////