fsl_clock.h 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537
  1. /*
  2. * The Clear BSD License
  3. * Copyright (c) 2015, Freescale Semiconductor, Inc.
  4. * Copyright (c) 2016 - 2017 , NXP
  5. * All rights reserved.
  6. *
  7. *
  8. * Redistribution and use in source and binary forms, with or without modification,
  9. * are permitted (subject to the limitations in the disclaimer below) provided
  10. * that the following conditions are met:
  11. *
  12. * o Redistributions of source code must retain the above copyright notice, this list
  13. * of conditions and the following disclaimer.
  14. *
  15. * o Redistributions in binary form must reproduce the above copyright notice, this
  16. * list of conditions and the following disclaimer in the documentation and/or
  17. * other materials provided with the distribution.
  18. *
  19. * o Neither the name of copyright holder nor the names of its
  20. * contributors may be used to endorse or promote products derived from this
  21. * software without specific prior written permission.
  22. *
  23. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  25. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  26. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  27. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  28. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  29. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  30. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  31. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  32. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  33. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. */
  35. #ifndef _FSL_CLOCK_H_
  36. #define _FSL_CLOCK_H_
  37. #include "fsl_common.h"
  38. /*! @addtogroup clock */
  39. /*! @{ */
  40. /*! @file */
  41. /*******************************************************************************
  42. * Configurations
  43. ******************************************************************************/
  44. /*! @brief Configures whether to check a parameter in a function.
  45. *
  46. * Some MCG settings must be changed with conditions, for example:
  47. * 1. MCGIRCLK settings, such as the source, divider, and the trim value should not change when
  48. * MCGIRCLK is used as a system clock source.
  49. * 2. MCG_C7[OSCSEL] should not be changed when the external reference clock is used
  50. * as a system clock source. For example, in FBE/BLPE/PBE modes.
  51. * 3. The users should only switch between the supported clock modes.
  52. *
  53. * MCG functions check the parameter and MCG status before setting, if not allowed
  54. * to change, the functions return error. The parameter checking increases code size,
  55. * if code size is a critical requirement, change #MCG_CONFIG_CHECK_PARAM to 0 to
  56. * disable parameter checking.
  57. */
  58. #ifndef MCG_CONFIG_CHECK_PARAM
  59. #define MCG_CONFIG_CHECK_PARAM 0U
  60. #endif
  61. /*! @brief Configure whether driver controls clock
  62. *
  63. * When set to 0, peripheral drivers will enable clock in initialize function
  64. * and disable clock in de-initialize function. When set to 1, peripheral
  65. * driver will not control the clock, application could contol the clock out of
  66. * the driver.
  67. *
  68. * @note All drivers share this feature switcher. If it is set to 1, application
  69. * should handle clock enable and disable for all drivers.
  70. */
  71. #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL))
  72. #define FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL 0
  73. #endif
  74. /*******************************************************************************
  75. * Definitions
  76. ******************************************************************************/
  77. /*! @name Driver version */
  78. /*@{*/
  79. /*! @brief CLOCK driver version 2.2.1. */
  80. #define FSL_CLOCK_DRIVER_VERSION (MAKE_VERSION(2, 2, 1))
  81. /*@}*/
  82. /*! @brief External XTAL0 (OSC0) clock frequency.
  83. *
  84. * The XTAL0/EXTAL0 (OSC0) clock frequency in Hz. When the clock is set up, use the
  85. * function CLOCK_SetXtal0Freq to set the value in the clock driver. For example,
  86. * if XTAL0 is 8 MHz:
  87. * @code
  88. * CLOCK_InitOsc0(...); // Set up the OSC0
  89. * CLOCK_SetXtal0Freq(80000000); // Set the XTAL0 value to the clock driver.
  90. * @endcode
  91. *
  92. * This is important for the multicore platforms where only one core needs to set up the
  93. * OSC0 using the CLOCK_InitOsc0. All other cores need to call the CLOCK_SetXtal0Freq
  94. * to get a valid clock frequency.
  95. */
  96. extern uint32_t g_xtal0Freq;
  97. /*! @brief External XTAL32/EXTAL32/RTC_CLKIN clock frequency.
  98. *
  99. * The XTAL32/EXTAL32/RTC_CLKIN clock frequency in Hz. When the clock is set up, use the
  100. * function CLOCK_SetXtal32Freq to set the value in the clock driver.
  101. *
  102. * This is important for the multicore platforms where only one core needs to set up
  103. * the clock. All other cores need to call the CLOCK_SetXtal32Freq
  104. * to get a valid clock frequency.
  105. */
  106. extern uint32_t g_xtal32Freq;
  107. /*! @brief IRC48M clock frequency in Hz. */
  108. #define MCG_INTERNAL_IRC_48M 48000000U
  109. #if (defined(OSC) && !(defined(OSC0)))
  110. #define OSC0 OSC
  111. #endif
  112. /*! @brief Clock ip name array for DMAMUX. */
  113. #define DMAMUX_CLOCKS \
  114. { \
  115. kCLOCK_Dmamux0 \
  116. }
  117. /*! @brief Clock ip name array for RTC. */
  118. #define RTC_CLOCKS \
  119. { \
  120. kCLOCK_Rtc0 \
  121. }
  122. /*! @brief Clock ip name array for SAI. */
  123. #define SAI_CLOCKS \
  124. { \
  125. kCLOCK_Sai0 \
  126. }
  127. /*! @brief Clock ip name array for FLEXBUS. */
  128. #define FLEXBUS_CLOCKS \
  129. { \
  130. kCLOCK_Flexbus0 \
  131. }
  132. /*! @brief Clock ip name array for PORT. */
  133. #define PORT_CLOCKS \
  134. { \
  135. kCLOCK_PortA, kCLOCK_PortB, kCLOCK_PortC, kCLOCK_PortD, kCLOCK_PortE \
  136. }
  137. /*! @brief Clock ip name array for EWM. */
  138. #define EWM_CLOCKS \
  139. { \
  140. kCLOCK_Ewm0 \
  141. }
  142. /*! @brief Clock ip name array for PIT. */
  143. #define PIT_CLOCKS \
  144. { \
  145. kCLOCK_Pit0 \
  146. }
  147. /*! @brief Clock ip name array for SDHC. */
  148. #define SDHC_CLOCKS \
  149. { \
  150. kCLOCK_Sdhc0 \
  151. }
  152. /*! @brief Clock ip name array for DSPI. */
  153. #define DSPI_CLOCKS \
  154. { \
  155. kCLOCK_Spi0, kCLOCK_Spi1, kCLOCK_Spi2 \
  156. }
  157. /*! @brief Clock ip name array for LPTMR. */
  158. #define LPTMR_CLOCKS \
  159. { \
  160. kCLOCK_Lptmr0 \
  161. }
  162. /*! @brief Clock ip name array for FTM. */
  163. #define FTM_CLOCKS \
  164. { \
  165. kCLOCK_Ftm0, kCLOCK_Ftm1, kCLOCK_Ftm2, kCLOCK_Ftm3 \
  166. }
  167. /*! @brief Clock ip name array for EDMA. */
  168. #define EDMA_CLOCKS \
  169. { \
  170. kCLOCK_Dma0 \
  171. }
  172. /*! @brief Clock ip name array for MPU. */
  173. #define SYSMPU_CLOCKS \
  174. { \
  175. kCLOCK_Sysmpu0 \
  176. }
  177. /*! @brief Clock ip name array for DAC. */
  178. #define DAC_CLOCKS \
  179. { \
  180. kCLOCK_Dac0, kCLOCK_Dac1 \
  181. }
  182. /*! @brief Clock ip name array for ADC16. */
  183. #define ADC16_CLOCKS \
  184. { \
  185. kCLOCK_Adc0, kCLOCK_Adc1 \
  186. }
  187. /*! @brief Clock ip name array for VREF. */
  188. #define VREF_CLOCKS \
  189. { \
  190. kCLOCK_Vref0 \
  191. }
  192. /*! @brief Clock ip name array for CMT. */
  193. #define CMT_CLOCKS \
  194. { \
  195. kCLOCK_Cmt0 \
  196. }
  197. /*! @brief Clock ip name array for UART. */
  198. #define UART_CLOCKS \
  199. { \
  200. kCLOCK_Uart0, kCLOCK_Uart1, kCLOCK_Uart2, kCLOCK_Uart3, kCLOCK_Uart4, kCLOCK_Uart5 \
  201. }
  202. /*! @brief Clock ip name array for RNGA. */
  203. #define RNGA_CLOCKS \
  204. { \
  205. kCLOCK_Rnga0 \
  206. }
  207. /*! @brief Clock ip name array for CRC. */
  208. #define CRC_CLOCKS \
  209. { \
  210. kCLOCK_Crc0 \
  211. }
  212. /*! @brief Clock ip name array for I2C. */
  213. #define I2C_CLOCKS \
  214. { \
  215. kCLOCK_I2c0, kCLOCK_I2c1, kCLOCK_I2c2 \
  216. }
  217. /*! @brief Clock ip name array for PDB. */
  218. #define PDB_CLOCKS \
  219. { \
  220. kCLOCK_Pdb0 \
  221. }
  222. /*! @brief Clock ip name array for FLEXCAN. */
  223. #define FLEXCAN_CLOCKS \
  224. { \
  225. kCLOCK_Flexcan0 \
  226. }
  227. /*! @brief Clock ip name array for FTF. */
  228. #define FTF_CLOCKS \
  229. { \
  230. kCLOCK_Ftf0 \
  231. }
  232. /*! @brief Clock ip name array for CMP. */
  233. #define CMP_CLOCKS \
  234. { \
  235. kCLOCK_Cmp0, kCLOCK_Cmp1, kCLOCK_Cmp2 \
  236. }
  237. /*!
  238. * @brief LPO clock frequency.
  239. */
  240. #define LPO_CLK_FREQ 1000U
  241. /*! @brief Peripherals clock source definition. */
  242. #define SYS_CLK kCLOCK_CoreSysClk
  243. #define BUS_CLK kCLOCK_BusClk
  244. #define I2C0_CLK_SRC BUS_CLK
  245. #define I2C1_CLK_SRC BUS_CLK
  246. #define I2C2_CLK_SRC BUS_CLK
  247. #define DSPI0_CLK_SRC BUS_CLK
  248. #define DSPI1_CLK_SRC BUS_CLK
  249. #define DSPI2_CLK_SRC BUS_CLK
  250. #define UART0_CLK_SRC SYS_CLK
  251. #define UART1_CLK_SRC SYS_CLK
  252. #define UART2_CLK_SRC BUS_CLK
  253. #define UART3_CLK_SRC BUS_CLK
  254. #define UART4_CLK_SRC BUS_CLK
  255. #define UART5_CLK_SRC BUS_CLK
  256. /*! @brief Clock name used to get clock frequency. */
  257. typedef enum _clock_name
  258. {
  259. /* ----------------------------- System layer clock -------------------------------*/
  260. kCLOCK_CoreSysClk, /*!< Core/system clock */
  261. kCLOCK_PlatClk, /*!< Platform clock */
  262. kCLOCK_BusClk, /*!< Bus clock */
  263. kCLOCK_FlexBusClk, /*!< FlexBus clock */
  264. kCLOCK_FlashClk, /*!< Flash clock */
  265. kCLOCK_FastPeriphClk, /*!< Fast peripheral clock */
  266. kCLOCK_PllFllSelClk, /*!< The clock after SIM[PLLFLLSEL]. */
  267. /* ---------------------------------- OSC clock -----------------------------------*/
  268. kCLOCK_Er32kClk, /*!< External reference 32K clock (ERCLK32K) */
  269. kCLOCK_Osc0ErClk, /*!< OSC0 external reference clock (OSC0ERCLK) */
  270. kCLOCK_Osc1ErClk, /*!< OSC1 external reference clock (OSC1ERCLK) */
  271. kCLOCK_Osc0ErClkUndiv, /*!< OSC0 external reference undivided clock(OSC0ERCLK_UNDIV). */
  272. /* ----------------------------- MCG and MCG-Lite clock ---------------------------*/
  273. kCLOCK_McgFixedFreqClk, /*!< MCG fixed frequency clock (MCGFFCLK) */
  274. kCLOCK_McgInternalRefClk, /*!< MCG internal reference clock (MCGIRCLK) */
  275. kCLOCK_McgFllClk, /*!< MCGFLLCLK */
  276. kCLOCK_McgPll0Clk, /*!< MCGPLL0CLK */
  277. kCLOCK_McgPll1Clk, /*!< MCGPLL1CLK */
  278. kCLOCK_McgExtPllClk, /*!< EXT_PLLCLK */
  279. kCLOCK_McgPeriphClk, /*!< MCG peripheral clock (MCGPCLK) */
  280. kCLOCK_McgIrc48MClk, /*!< MCG IRC48M clock */
  281. /* --------------------------------- Other clock ----------------------------------*/
  282. kCLOCK_LpoClk, /*!< LPO clock */
  283. } clock_name_t;
  284. /*! @brief USB clock source definition. */
  285. typedef enum _clock_usb_src
  286. {
  287. kCLOCK_UsbSrcPll0 = SIM_SOPT2_USBSRC(1U) | SIM_SOPT2_PLLFLLSEL(1U), /*!< Use PLL0. */
  288. kCLOCK_UsbSrcIrc48M = SIM_SOPT2_USBSRC(1U) | SIM_SOPT2_PLLFLLSEL(3U), /*!< Use IRC48M. */
  289. kCLOCK_UsbSrcExt = SIM_SOPT2_USBSRC(0U) /*!< Use USB_CLKIN. */
  290. } clock_usb_src_t;
  291. /*------------------------------------------------------------------------------
  292. clock_gate_t definition:
  293. 31 16 0
  294. -----------------------------------------------------------------
  295. | SIM_SCGC register offset | control bit offset in SCGC |
  296. -----------------------------------------------------------------
  297. For example, the SDHC clock gate is controlled by SIM_SCGC3[17], the
  298. SIM_SCGC3 offset in SIM is 0x1030, then kCLOCK_GateSdhc0 is defined as
  299. kCLOCK_GateSdhc0 = (0x1030 << 16) | 17;
  300. ------------------------------------------------------------------------------*/
  301. #define CLK_GATE_REG_OFFSET_SHIFT 16U
  302. #define CLK_GATE_REG_OFFSET_MASK 0xFFFF0000U
  303. #define CLK_GATE_BIT_SHIFT_SHIFT 0U
  304. #define CLK_GATE_BIT_SHIFT_MASK 0x0000FFFFU
  305. #define CLK_GATE_DEFINE(reg_offset, bit_shift) \
  306. ((((reg_offset) << CLK_GATE_REG_OFFSET_SHIFT) & CLK_GATE_REG_OFFSET_MASK) | \
  307. (((bit_shift) << CLK_GATE_BIT_SHIFT_SHIFT) & CLK_GATE_BIT_SHIFT_MASK))
  308. #define CLK_GATE_ABSTRACT_REG_OFFSET(x) (((x)&CLK_GATE_REG_OFFSET_MASK) >> CLK_GATE_REG_OFFSET_SHIFT)
  309. #define CLK_GATE_ABSTRACT_BITS_SHIFT(x) (((x)&CLK_GATE_BIT_SHIFT_MASK) >> CLK_GATE_BIT_SHIFT_SHIFT)
  310. /*! @brief Clock gate name used for CLOCK_EnableClock/CLOCK_DisableClock. */
  311. typedef enum _clock_ip_name
  312. {
  313. kCLOCK_IpInvalid = 0U,
  314. kCLOCK_I2c2 = CLK_GATE_DEFINE(0x1028U, 6U),
  315. kCLOCK_Uart4 = CLK_GATE_DEFINE(0x1028U, 10U),
  316. kCLOCK_Uart5 = CLK_GATE_DEFINE(0x1028U, 11U),
  317. kCLOCK_Dac0 = CLK_GATE_DEFINE(0x102CU, 12U),
  318. kCLOCK_Dac1 = CLK_GATE_DEFINE(0x102CU, 13U),
  319. kCLOCK_Spi2 = CLK_GATE_DEFINE(0x1030U, 12U),
  320. kCLOCK_Sdhc0 = CLK_GATE_DEFINE(0x1030U, 17U),
  321. kCLOCK_Ftm3 = CLK_GATE_DEFINE(0x1030U, 25U),
  322. kCLOCK_Adc1 = CLK_GATE_DEFINE(0x1030U, 27U),
  323. kCLOCK_Ewm0 = CLK_GATE_DEFINE(0x1034U, 1U),
  324. kCLOCK_Cmt0 = CLK_GATE_DEFINE(0x1034U, 2U),
  325. kCLOCK_I2c0 = CLK_GATE_DEFINE(0x1034U, 6U),
  326. kCLOCK_I2c1 = CLK_GATE_DEFINE(0x1034U, 7U),
  327. kCLOCK_Uart0 = CLK_GATE_DEFINE(0x1034U, 10U),
  328. kCLOCK_Uart1 = CLK_GATE_DEFINE(0x1034U, 11U),
  329. kCLOCK_Uart2 = CLK_GATE_DEFINE(0x1034U, 12U),
  330. kCLOCK_Uart3 = CLK_GATE_DEFINE(0x1034U, 13U),
  331. kCLOCK_Usbfs0 = CLK_GATE_DEFINE(0x1034U, 18U),
  332. kCLOCK_Cmp0 = CLK_GATE_DEFINE(0x1034U, 19U),
  333. kCLOCK_Cmp1 = CLK_GATE_DEFINE(0x1034U, 19U),
  334. kCLOCK_Cmp2 = CLK_GATE_DEFINE(0x1034U, 19U),
  335. kCLOCK_Vref0 = CLK_GATE_DEFINE(0x1034U, 20U),
  336. kCLOCK_Lptmr0 = CLK_GATE_DEFINE(0x1038U, 0U),
  337. kCLOCK_PortA = CLK_GATE_DEFINE(0x1038U, 9U),
  338. kCLOCK_PortB = CLK_GATE_DEFINE(0x1038U, 10U),
  339. kCLOCK_PortC = CLK_GATE_DEFINE(0x1038U, 11U),
  340. kCLOCK_PortD = CLK_GATE_DEFINE(0x1038U, 12U),
  341. kCLOCK_PortE = CLK_GATE_DEFINE(0x1038U, 13U),
  342. kCLOCK_Ftf0 = CLK_GATE_DEFINE(0x103CU, 0U),
  343. kCLOCK_Dmamux0 = CLK_GATE_DEFINE(0x103CU, 1U),
  344. kCLOCK_Flexcan0 = CLK_GATE_DEFINE(0x103CU, 4U),
  345. kCLOCK_Rnga0 = CLK_GATE_DEFINE(0x103CU, 9U),
  346. kCLOCK_Spi0 = CLK_GATE_DEFINE(0x103CU, 12U),
  347. kCLOCK_Spi1 = CLK_GATE_DEFINE(0x103CU, 13U),
  348. kCLOCK_Sai0 = CLK_GATE_DEFINE(0x103CU, 15U),
  349. kCLOCK_Crc0 = CLK_GATE_DEFINE(0x103CU, 18U),
  350. kCLOCK_Usbdcd0 = CLK_GATE_DEFINE(0x103CU, 21U),
  351. kCLOCK_Pdb0 = CLK_GATE_DEFINE(0x103CU, 22U),
  352. kCLOCK_Pit0 = CLK_GATE_DEFINE(0x103CU, 23U),
  353. kCLOCK_Ftm0 = CLK_GATE_DEFINE(0x103CU, 24U),
  354. kCLOCK_Ftm1 = CLK_GATE_DEFINE(0x103CU, 25U),
  355. kCLOCK_Ftm2 = CLK_GATE_DEFINE(0x103CU, 26U),
  356. kCLOCK_Adc0 = CLK_GATE_DEFINE(0x103CU, 27U),
  357. kCLOCK_Rtc0 = CLK_GATE_DEFINE(0x103CU, 29U),
  358. kCLOCK_Flexbus0 = CLK_GATE_DEFINE(0x1040U, 0U),
  359. kCLOCK_Dma0 = CLK_GATE_DEFINE(0x1040U, 1U),
  360. kCLOCK_Sysmpu0 = CLK_GATE_DEFINE(0x1040U, 2U),
  361. } clock_ip_name_t;
  362. /*!@brief SIM configuration structure for clock setting. */
  363. typedef struct _sim_clock_config
  364. {
  365. uint8_t pllFllSel; /*!< PLL/FLL/IRC48M selection. */
  366. uint8_t er32kSrc; /*!< ERCLK32K source selection. */
  367. uint32_t clkdiv1; /*!< SIM_CLKDIV1. */
  368. } sim_clock_config_t;
  369. /*! @brief OSC work mode. */
  370. typedef enum _osc_mode
  371. {
  372. kOSC_ModeExt = 0U, /*!< Use an external clock. */
  373. #if (defined(MCG_C2_EREFS_MASK) && !(defined(MCG_C2_EREFS0_MASK)))
  374. kOSC_ModeOscLowPower = MCG_C2_EREFS_MASK, /*!< Oscillator low power. */
  375. #else
  376. kOSC_ModeOscLowPower = MCG_C2_EREFS0_MASK, /*!< Oscillator low power. */
  377. #endif
  378. kOSC_ModeOscHighGain = 0U
  379. #if (defined(MCG_C2_EREFS_MASK) && !(defined(MCG_C2_EREFS0_MASK)))
  380. |
  381. MCG_C2_EREFS_MASK
  382. #else
  383. |
  384. MCG_C2_EREFS0_MASK
  385. #endif
  386. #if (defined(MCG_C2_HGO_MASK) && !(defined(MCG_C2_HGO0_MASK)))
  387. |
  388. MCG_C2_HGO_MASK, /*!< Oscillator high gain. */
  389. #else
  390. |
  391. MCG_C2_HGO0_MASK, /*!< Oscillator high gain. */
  392. #endif
  393. } osc_mode_t;
  394. /*! @brief Oscillator capacitor load setting.*/
  395. enum _osc_cap_load
  396. {
  397. kOSC_Cap2P = OSC_CR_SC2P_MASK, /*!< 2 pF capacitor load */
  398. kOSC_Cap4P = OSC_CR_SC4P_MASK, /*!< 4 pF capacitor load */
  399. kOSC_Cap8P = OSC_CR_SC8P_MASK, /*!< 8 pF capacitor load */
  400. kOSC_Cap16P = OSC_CR_SC16P_MASK /*!< 16 pF capacitor load */
  401. };
  402. /*! @brief OSCERCLK enable mode. */
  403. enum _oscer_enable_mode
  404. {
  405. kOSC_ErClkEnable = OSC_CR_ERCLKEN_MASK, /*!< Enable. */
  406. kOSC_ErClkEnableInStop = OSC_CR_EREFSTEN_MASK /*!< Enable in stop mode. */
  407. };
  408. /*! @brief OSC configuration for OSCERCLK. */
  409. typedef struct _oscer_config
  410. {
  411. uint8_t enableMode; /*!< OSCERCLK enable mode. OR'ed value of @ref _oscer_enable_mode. */
  412. } oscer_config_t;
  413. /*!
  414. * @brief OSC Initialization Configuration Structure
  415. *
  416. * Defines the configuration data structure to initialize the OSC.
  417. * When porting to a new board, set the following members
  418. * according to the board setting:
  419. * 1. freq: The external frequency.
  420. * 2. workMode: The OSC module mode.
  421. */
  422. typedef struct _osc_config
  423. {
  424. uint32_t freq; /*!< External clock frequency. */
  425. uint8_t capLoad; /*!< Capacitor load setting. */
  426. osc_mode_t workMode; /*!< OSC work mode setting. */
  427. oscer_config_t oscerConfig; /*!< Configuration for OSCERCLK. */
  428. } osc_config_t;
  429. /*! @brief MCG FLL reference clock source select. */
  430. typedef enum _mcg_fll_src
  431. {
  432. kMCG_FllSrcExternal, /*!< External reference clock is selected */
  433. kMCG_FllSrcInternal /*!< The slow internal reference clock is selected */
  434. } mcg_fll_src_t;
  435. /*! @brief MCG internal reference clock select */
  436. typedef enum _mcg_irc_mode
  437. {
  438. kMCG_IrcSlow, /*!< Slow internal reference clock selected */
  439. kMCG_IrcFast /*!< Fast internal reference clock selected */
  440. } mcg_irc_mode_t;
  441. /*! @brief MCG DCO Maximum Frequency with 32.768 kHz Reference */
  442. typedef enum _mcg_dmx32
  443. {
  444. kMCG_Dmx32Default, /*!< DCO has a default range of 25% */
  445. kMCG_Dmx32Fine /*!< DCO is fine-tuned for maximum frequency with 32.768 kHz reference */
  446. } mcg_dmx32_t;
  447. /*! @brief MCG DCO range select */
  448. typedef enum _mcg_drs
  449. {
  450. kMCG_DrsLow, /*!< Low frequency range */
  451. kMCG_DrsMid, /*!< Mid frequency range */
  452. kMCG_DrsMidHigh, /*!< Mid-High frequency range */
  453. kMCG_DrsHigh /*!< High frequency range */
  454. } mcg_drs_t;
  455. /*! @brief MCG PLL reference clock select */
  456. typedef enum _mcg_pll_ref_src
  457. {
  458. kMCG_PllRefOsc0, /*!< Selects OSC0 as PLL reference clock */
  459. kMCG_PllRefOsc1 /*!< Selects OSC1 as PLL reference clock */
  460. } mcg_pll_ref_src_t;
  461. /*! @brief MCGOUT clock source. */
  462. typedef enum _mcg_clkout_src
  463. {
  464. kMCG_ClkOutSrcOut, /*!< Output of the FLL is selected (reset default) */
  465. kMCG_ClkOutSrcInternal, /*!< Internal reference clock is selected */
  466. kMCG_ClkOutSrcExternal, /*!< External reference clock is selected */
  467. } mcg_clkout_src_t;
  468. /*! @brief MCG Automatic Trim Machine Select */
  469. typedef enum _mcg_atm_select
  470. {
  471. kMCG_AtmSel32k, /*!< 32 kHz Internal Reference Clock selected */
  472. kMCG_AtmSel4m /*!< 4 MHz Internal Reference Clock selected */
  473. } mcg_atm_select_t;
  474. /*! @brief MCG OSC Clock Select */
  475. typedef enum _mcg_oscsel
  476. {
  477. kMCG_OscselOsc, /*!< Selects System Oscillator (OSCCLK) */
  478. kMCG_OscselRtc, /*!< Selects 32 kHz RTC Oscillator */
  479. kMCG_OscselIrc /*!< Selects 48 MHz IRC Oscillator */
  480. } mcg_oscsel_t;
  481. /*! @brief MCG PLLCS select */
  482. typedef enum _mcg_pll_clk_select
  483. {
  484. kMCG_PllClkSelPll0, /*!< PLL0 output clock is selected */
  485. kMCG_PllClkSelPll1 /* PLL1 output clock is selected */
  486. } mcg_pll_clk_select_t;
  487. /*! @brief MCG clock monitor mode. */
  488. typedef enum _mcg_monitor_mode
  489. {
  490. kMCG_MonitorNone, /*!< Clock monitor is disabled. */
  491. kMCG_MonitorInt, /*!< Trigger interrupt when clock lost. */
  492. kMCG_MonitorReset /*!< System reset when clock lost. */
  493. } mcg_monitor_mode_t;
  494. /*! @brief MCG status. */
  495. enum _mcg_status
  496. {
  497. kStatus_MCG_ModeUnreachable = MAKE_STATUS(kStatusGroup_MCG, 0), /*!< Can't switch to target mode. */
  498. kStatus_MCG_ModeInvalid = MAKE_STATUS(kStatusGroup_MCG, 1), /*!< Current mode invalid for the specific
  499. function. */
  500. kStatus_MCG_AtmBusClockInvalid = MAKE_STATUS(kStatusGroup_MCG, 2), /*!< Invalid bus clock for ATM. */
  501. kStatus_MCG_AtmDesiredFreqInvalid = MAKE_STATUS(kStatusGroup_MCG, 3), /*!< Invalid desired frequency for ATM. */
  502. kStatus_MCG_AtmIrcUsed = MAKE_STATUS(kStatusGroup_MCG, 4), /*!< IRC is used when using ATM. */
  503. kStatus_MCG_AtmHardwareFail = MAKE_STATUS(kStatusGroup_MCG, 5), /*!< Hardware fail occurs during ATM. */
  504. kStatus_MCG_SourceUsed = MAKE_STATUS(kStatusGroup_MCG, 6) /*!< Can't change the clock source because
  505. it is in use. */
  506. };
  507. /*! @brief MCG status flags. */
  508. enum _mcg_status_flags_t
  509. {
  510. kMCG_Osc0LostFlag = (1U << 0U), /*!< OSC0 lost. */
  511. kMCG_Osc0InitFlag = (1U << 1U), /*!< OSC0 crystal initialized. */
  512. kMCG_RtcOscLostFlag = (1U << 4U), /*!< RTC OSC lost. */
  513. kMCG_Pll0LostFlag = (1U << 5U), /*!< PLL0 lost. */
  514. kMCG_Pll0LockFlag = (1U << 6U), /*!< PLL0 locked. */
  515. };
  516. /*! @brief MCG internal reference clock (MCGIRCLK) enable mode definition. */
  517. enum _mcg_irclk_enable_mode
  518. {
  519. kMCG_IrclkEnable = MCG_C1_IRCLKEN_MASK, /*!< MCGIRCLK enable. */
  520. kMCG_IrclkEnableInStop = MCG_C1_IREFSTEN_MASK /*!< MCGIRCLK enable in stop mode. */
  521. };
  522. /*! @brief MCG PLL clock enable mode definition. */
  523. enum _mcg_pll_enable_mode
  524. {
  525. kMCG_PllEnableIndependent = MCG_C5_PLLCLKEN0_MASK, /*!< MCGPLLCLK enable independent of the
  526. MCG clock mode. Generally, the PLL
  527. is disabled in FLL modes
  528. (FEI/FBI/FEE/FBE). Setting the PLL clock
  529. enable independent, enables the
  530. PLL in the FLL modes. */
  531. kMCG_PllEnableInStop = MCG_C5_PLLSTEN0_MASK /*!< MCGPLLCLK enable in STOP mode. */
  532. };
  533. /*! @brief MCG mode definitions */
  534. typedef enum _mcg_mode
  535. {
  536. kMCG_ModeFEI = 0U, /*!< FEI - FLL Engaged Internal */
  537. kMCG_ModeFBI, /*!< FBI - FLL Bypassed Internal */
  538. kMCG_ModeBLPI, /*!< BLPI - Bypassed Low Power Internal */
  539. kMCG_ModeFEE, /*!< FEE - FLL Engaged External */
  540. kMCG_ModeFBE, /*!< FBE - FLL Bypassed External */
  541. kMCG_ModeBLPE, /*!< BLPE - Bypassed Low Power External */
  542. kMCG_ModePBE, /*!< PBE - PLL Bypassed External */
  543. kMCG_ModePEE, /*!< PEE - PLL Engaged External */
  544. kMCG_ModeError /*!< Unknown mode */
  545. } mcg_mode_t;
  546. /*! @brief MCG PLL configuration. */
  547. typedef struct _mcg_pll_config
  548. {
  549. uint8_t enableMode; /*!< Enable mode. OR'ed value of @ref _mcg_pll_enable_mode. */
  550. uint8_t prdiv; /*!< Reference divider PRDIV. */
  551. uint8_t vdiv; /*!< VCO divider VDIV. */
  552. } mcg_pll_config_t;
  553. /*! @brief MCG mode change configuration structure
  554. *
  555. * When porting to a new board, set the following members
  556. * according to the board setting:
  557. * 1. frdiv: If the FLL uses the external reference clock, set this
  558. * value to ensure that the external reference clock divided by frdiv is
  559. * in the 31.25 kHz to 39.0625 kHz range.
  560. * 2. The PLL reference clock divider PRDIV: PLL reference clock frequency after
  561. * PRDIV should be in the FSL_FEATURE_MCG_PLL_REF_MIN to
  562. * FSL_FEATURE_MCG_PLL_REF_MAX range.
  563. */
  564. typedef struct _mcg_config
  565. {
  566. mcg_mode_t mcgMode; /*!< MCG mode. */
  567. /* ----------------------- MCGIRCCLK settings ------------------------ */
  568. uint8_t irclkEnableMode; /*!< MCGIRCLK enable mode. */
  569. mcg_irc_mode_t ircs; /*!< Source, MCG_C2[IRCS]. */
  570. uint8_t fcrdiv; /*!< Divider, MCG_SC[FCRDIV]. */
  571. /* ------------------------ MCG FLL settings ------------------------- */
  572. uint8_t frdiv; /*!< Divider MCG_C1[FRDIV]. */
  573. mcg_drs_t drs; /*!< DCO range MCG_C4[DRST_DRS]. */
  574. mcg_dmx32_t dmx32; /*!< MCG_C4[DMX32]. */
  575. mcg_oscsel_t oscsel; /*!< OSC select MCG_C7[OSCSEL]. */
  576. /* ------------------------ MCG PLL settings ------------------------- */
  577. mcg_pll_config_t pll0Config; /*!< MCGPLL0CLK configuration. */
  578. } mcg_config_t;
  579. /*******************************************************************************
  580. * API
  581. ******************************************************************************/
  582. #if defined(__cplusplus)
  583. extern "C" {
  584. #endif /* __cplusplus */
  585. /*!
  586. * @brief Enable the clock for specific IP.
  587. *
  588. * @param name Which clock to enable, see \ref clock_ip_name_t.
  589. */
  590. static inline void CLOCK_EnableClock(clock_ip_name_t name)
  591. {
  592. uint32_t regAddr = SIM_BASE + CLK_GATE_ABSTRACT_REG_OFFSET((uint32_t)name);
  593. (*(volatile uint32_t *)regAddr) |= (1U << CLK_GATE_ABSTRACT_BITS_SHIFT((uint32_t)name));
  594. }
  595. /*!
  596. * @brief Disable the clock for specific IP.
  597. *
  598. * @param name Which clock to disable, see \ref clock_ip_name_t.
  599. */
  600. static inline void CLOCK_DisableClock(clock_ip_name_t name)
  601. {
  602. uint32_t regAddr = SIM_BASE + CLK_GATE_ABSTRACT_REG_OFFSET((uint32_t)name);
  603. (*(volatile uint32_t *)regAddr) &= ~(1U << CLK_GATE_ABSTRACT_BITS_SHIFT((uint32_t)name));
  604. }
  605. /*!
  606. * @brief Set ERCLK32K source.
  607. *
  608. * @param src The value to set ERCLK32K clock source.
  609. */
  610. static inline void CLOCK_SetEr32kClock(uint32_t src)
  611. {
  612. SIM->SOPT1 = ((SIM->SOPT1 & ~SIM_SOPT1_OSC32KSEL_MASK) | SIM_SOPT1_OSC32KSEL(src));
  613. }
  614. /*!
  615. * @brief Set debug trace clock source.
  616. *
  617. * @param src The value to set debug trace clock source.
  618. */
  619. static inline void CLOCK_SetTraceClock(uint32_t src)
  620. {
  621. SIM->SOPT2 = ((SIM->SOPT2 & ~SIM_SOPT2_TRACECLKSEL_MASK) | SIM_SOPT2_TRACECLKSEL(src));
  622. }
  623. /*!
  624. * @brief Set SDHC0 clock source.
  625. *
  626. * @param src The value to set SDHC0 clock source.
  627. */
  628. static inline void CLOCK_SetSdhc0Clock(uint32_t src)
  629. {
  630. SIM->SOPT2 = ((SIM->SOPT2 & ~SIM_SOPT2_SDHCSRC_MASK) | SIM_SOPT2_SDHCSRC(src));
  631. }
  632. /*!
  633. * @brief Set PLLFLLSEL clock source.
  634. *
  635. * @param src The value to set PLLFLLSEL clock source.
  636. */
  637. static inline void CLOCK_SetPllFllSelClock(uint32_t src)
  638. {
  639. SIM->SOPT2 = ((SIM->SOPT2 & ~SIM_SOPT2_PLLFLLSEL_MASK) | SIM_SOPT2_PLLFLLSEL(src));
  640. }
  641. /*!
  642. * @brief Set CLKOUT source.
  643. *
  644. * @param src The value to set CLKOUT source.
  645. */
  646. static inline void CLOCK_SetClkOutClock(uint32_t src)
  647. {
  648. SIM->SOPT2 = ((SIM->SOPT2 & ~SIM_SOPT2_CLKOUTSEL_MASK) | SIM_SOPT2_CLKOUTSEL(src));
  649. }
  650. /*!
  651. * @brief Set RTC_CLKOUT source.
  652. *
  653. * @param src The value to set RTC_CLKOUT source.
  654. */
  655. static inline void CLOCK_SetRtcClkOutClock(uint32_t src)
  656. {
  657. SIM->SOPT2 = ((SIM->SOPT2 & ~SIM_SOPT2_RTCCLKOUTSEL_MASK) | SIM_SOPT2_RTCCLKOUTSEL(src));
  658. }
  659. /*! @brief Enable USB FS clock.
  660. *
  661. * @param src USB FS clock source.
  662. * @param freq The frequency specified by src.
  663. * @retval true The clock is set successfully.
  664. * @retval false The clock source is invalid to get proper USB FS clock.
  665. */
  666. bool CLOCK_EnableUsbfs0Clock(clock_usb_src_t src, uint32_t freq);
  667. /*! @brief Disable USB FS clock.
  668. *
  669. * Disable USB FS clock.
  670. */
  671. static inline void CLOCK_DisableUsbfs0Clock(void)
  672. {
  673. CLOCK_DisableClock(kCLOCK_Usbfs0);
  674. }
  675. /*!
  676. * @brief System clock divider
  677. *
  678. * Set the SIM_CLKDIV1[OUTDIV1], SIM_CLKDIV1[OUTDIV2], SIM_CLKDIV1[OUTDIV3], SIM_CLKDIV1[OUTDIV4].
  679. *
  680. * @param outdiv1 Clock 1 output divider value.
  681. *
  682. * @param outdiv2 Clock 2 output divider value.
  683. *
  684. * @param outdiv3 Clock 3 output divider value.
  685. *
  686. * @param outdiv4 Clock 4 output divider value.
  687. */
  688. static inline void CLOCK_SetOutDiv(uint32_t outdiv1, uint32_t outdiv2, uint32_t outdiv3, uint32_t outdiv4)
  689. {
  690. SIM->CLKDIV1 = SIM_CLKDIV1_OUTDIV1(outdiv1) | SIM_CLKDIV1_OUTDIV2(outdiv2) | SIM_CLKDIV1_OUTDIV3(outdiv3) |
  691. SIM_CLKDIV1_OUTDIV4(outdiv4);
  692. }
  693. /*!
  694. * @brief Gets the clock frequency for a specific clock name.
  695. *
  696. * This function checks the current clock configurations and then calculates
  697. * the clock frequency for a specific clock name defined in clock_name_t.
  698. * The MCG must be properly configured before using this function.
  699. *
  700. * @param clockName Clock names defined in clock_name_t
  701. * @return Clock frequency value in Hertz
  702. */
  703. uint32_t CLOCK_GetFreq(clock_name_t clockName);
  704. /*!
  705. * @brief Get the core clock or system clock frequency.
  706. *
  707. * @return Clock frequency in Hz.
  708. */
  709. uint32_t CLOCK_GetCoreSysClkFreq(void);
  710. /*!
  711. * @brief Get the bus clock frequency.
  712. *
  713. * @return Clock frequency in Hz.
  714. */
  715. uint32_t CLOCK_GetBusClkFreq(void);
  716. /*!
  717. * @brief Get the flexbus clock frequency.
  718. *
  719. * @return Clock frequency in Hz.
  720. */
  721. uint32_t CLOCK_GetFlexBusClkFreq(void);
  722. /*!
  723. * @brief Get the flash clock frequency.
  724. *
  725. * @return Clock frequency in Hz.
  726. */
  727. uint32_t CLOCK_GetFlashClkFreq(void);
  728. /*!
  729. * @brief Get the output clock frequency selected by SIM[PLLFLLSEL].
  730. *
  731. * @return Clock frequency in Hz.
  732. */
  733. uint32_t CLOCK_GetPllFllSelClkFreq(void);
  734. /*!
  735. * @brief Get the external reference 32K clock frequency (ERCLK32K).
  736. *
  737. * @return Clock frequency in Hz.
  738. */
  739. uint32_t CLOCK_GetEr32kClkFreq(void);
  740. /*!
  741. * @brief Get the OSC0 external reference clock frequency (OSC0ERCLK).
  742. *
  743. * @return Clock frequency in Hz.
  744. */
  745. uint32_t CLOCK_GetOsc0ErClkFreq(void);
  746. /*!
  747. * @brief Set the clock configure in SIM module.
  748. *
  749. * This function sets system layer clock settings in SIM module.
  750. *
  751. * @param config Pointer to the configure structure.
  752. */
  753. void CLOCK_SetSimConfig(sim_clock_config_t const *config);
  754. /*!
  755. * @brief Set the system clock dividers in SIM to safe value.
  756. *
  757. * The system level clocks (core clock, bus clock, flexbus clock and flash clock)
  758. * must be in allowed ranges. During MCG clock mode switch, the MCG output clock
  759. * changes then the system level clocks may be out of range. This function could
  760. * be used before MCG mode change, to make sure system level clocks are in allowed
  761. * range.
  762. *
  763. * @param config Pointer to the configure structure.
  764. */
  765. static inline void CLOCK_SetSimSafeDivs(void)
  766. {
  767. SIM->CLKDIV1 = 0x01040000U;
  768. }
  769. /*! @name MCG frequency functions. */
  770. /*@{*/
  771. /*!
  772. * @brief Gets the MCG output clock (MCGOUTCLK) frequency.
  773. *
  774. * This function gets the MCG output clock frequency in Hz based on the current MCG
  775. * register value.
  776. *
  777. * @return The frequency of MCGOUTCLK.
  778. */
  779. uint32_t CLOCK_GetOutClkFreq(void);
  780. /*!
  781. * @brief Gets the MCG FLL clock (MCGFLLCLK) frequency.
  782. *
  783. * This function gets the MCG FLL clock frequency in Hz based on the current MCG
  784. * register value. The FLL is enabled in FEI/FBI/FEE/FBE mode and
  785. * disabled in low power state in other modes.
  786. *
  787. * @return The frequency of MCGFLLCLK.
  788. */
  789. uint32_t CLOCK_GetFllFreq(void);
  790. /*!
  791. * @brief Gets the MCG internal reference clock (MCGIRCLK) frequency.
  792. *
  793. * This function gets the MCG internal reference clock frequency in Hz based
  794. * on the current MCG register value.
  795. *
  796. * @return The frequency of MCGIRCLK.
  797. */
  798. uint32_t CLOCK_GetInternalRefClkFreq(void);
  799. /*!
  800. * @brief Gets the MCG fixed frequency clock (MCGFFCLK) frequency.
  801. *
  802. * This function gets the MCG fixed frequency clock frequency in Hz based
  803. * on the current MCG register value.
  804. *
  805. * @return The frequency of MCGFFCLK.
  806. */
  807. uint32_t CLOCK_GetFixedFreqClkFreq(void);
  808. /*!
  809. * @brief Gets the MCG PLL0 clock (MCGPLL0CLK) frequency.
  810. *
  811. * This function gets the MCG PLL0 clock frequency in Hz based on the current MCG
  812. * register value.
  813. *
  814. * @return The frequency of MCGPLL0CLK.
  815. */
  816. uint32_t CLOCK_GetPll0Freq(void);
  817. /*@}*/
  818. /*! @name MCG clock configuration. */
  819. /*@{*/
  820. /*!
  821. * @brief Enables or disables the MCG low power.
  822. *
  823. * Enabling the MCG low power disables the PLL and FLL in bypass modes. In other words,
  824. * in FBE and PBE modes, enabling low power sets the MCG to BLPE mode. In FBI and
  825. * PBI modes, enabling low power sets the MCG to BLPI mode.
  826. * When disabling the MCG low power, the PLL or FLL are enabled based on MCG settings.
  827. *
  828. * @param enable True to enable MCG low power, false to disable MCG low power.
  829. */
  830. static inline void CLOCK_SetLowPowerEnable(bool enable)
  831. {
  832. if (enable)
  833. {
  834. MCG->C2 |= MCG_C2_LP_MASK;
  835. }
  836. else
  837. {
  838. MCG->C2 &= ~MCG_C2_LP_MASK;
  839. }
  840. }
  841. /*!
  842. * @brief Configures the Internal Reference clock (MCGIRCLK).
  843. *
  844. * This function sets the \c MCGIRCLK base on parameters. It also selects the IRC
  845. * source. If the fast IRC is used, this function sets the fast IRC divider.
  846. * This function also sets whether the \c MCGIRCLK is enabled in stop mode.
  847. * Calling this function in FBI/PBI/BLPI modes may change the system clock. As a result,
  848. * using the function in these modes it is not allowed.
  849. *
  850. * @param enableMode MCGIRCLK enable mode, OR'ed value of @ref _mcg_irclk_enable_mode.
  851. * @param ircs MCGIRCLK clock source, choose fast or slow.
  852. * @param fcrdiv Fast IRC divider setting (\c FCRDIV).
  853. * @retval kStatus_MCG_SourceUsed Because the internall reference clock is used as a clock source,
  854. * the confuration should not be changed. Otherwise, a glitch occurs.
  855. * @retval kStatus_Success MCGIRCLK configuration finished successfully.
  856. */
  857. status_t CLOCK_SetInternalRefClkConfig(uint8_t enableMode, mcg_irc_mode_t ircs, uint8_t fcrdiv);
  858. /*!
  859. * @brief Selects the MCG external reference clock.
  860. *
  861. * Selects the MCG external reference clock source, changes the MCG_C7[OSCSEL],
  862. * and waits for the clock source to be stable. Because the external reference
  863. * clock should not be changed in FEE/FBE/BLPE/PBE/PEE modes, do not call this function in these modes.
  864. *
  865. * @param oscsel MCG external reference clock source, MCG_C7[OSCSEL].
  866. * @retval kStatus_MCG_SourceUsed Because the external reference clock is used as a clock source,
  867. * the confuration should not be changed. Otherwise, a glitch occurs.
  868. * @retval kStatus_Success External reference clock set successfully.
  869. */
  870. status_t CLOCK_SetExternalRefClkConfig(mcg_oscsel_t oscsel);
  871. /*!
  872. * @brief Set the FLL external reference clock divider value.
  873. *
  874. * Sets the FLL external reference clock divider value, the register MCG_C1[FRDIV].
  875. *
  876. * @param frdiv The FLL external reference clock divider value, MCG_C1[FRDIV].
  877. */
  878. static inline void CLOCK_SetFllExtRefDiv(uint8_t frdiv)
  879. {
  880. MCG->C1 = (MCG->C1 & ~MCG_C1_FRDIV_MASK) | MCG_C1_FRDIV(frdiv);
  881. }
  882. /*!
  883. * @brief Enables the PLL0 in FLL mode.
  884. *
  885. * This function sets us the PLL0 in FLL mode and reconfigures
  886. * the PLL0. Ensure that the PLL reference
  887. * clock is enabled before calling this function and that the PLL0 is not used as a clock source.
  888. * The function CLOCK_CalcPllDiv gets the correct PLL
  889. * divider values.
  890. *
  891. * @param config Pointer to the configuration structure.
  892. */
  893. void CLOCK_EnablePll0(mcg_pll_config_t const *config);
  894. /*!
  895. * @brief Disables the PLL0 in FLL mode.
  896. *
  897. * This function disables the PLL0 in FLL mode. It should be used together with the
  898. * @ref CLOCK_EnablePll0.
  899. */
  900. static inline void CLOCK_DisablePll0(void)
  901. {
  902. MCG->C5 &= ~(MCG_C5_PLLCLKEN0_MASK | MCG_C5_PLLSTEN0_MASK);
  903. }
  904. /*!
  905. * @brief Calculates the PLL divider setting for a desired output frequency.
  906. *
  907. * This function calculates the correct reference clock divider (\c PRDIV) and
  908. * VCO divider (\c VDIV) to generate a desired PLL output frequency. It returns the
  909. * closest frequency match with the corresponding \c PRDIV/VDIV
  910. * returned from parameters. If a desired frequency is not valid, this function
  911. * returns 0.
  912. *
  913. * @param refFreq PLL reference clock frequency.
  914. * @param desireFreq Desired PLL output frequency.
  915. * @param prdiv PRDIV value to generate desired PLL frequency.
  916. * @param vdiv VDIV value to generate desired PLL frequency.
  917. * @return Closest frequency match that the PLL was able generate.
  918. */
  919. uint32_t CLOCK_CalcPllDiv(uint32_t refFreq, uint32_t desireFreq, uint8_t *prdiv, uint8_t *vdiv);
  920. /*@}*/
  921. /*! @name MCG clock lock monitor functions. */
  922. /*@{*/
  923. /*!
  924. * @brief Sets the OSC0 clock monitor mode.
  925. *
  926. * This function sets the OSC0 clock monitor mode. See @ref mcg_monitor_mode_t for details.
  927. *
  928. * @param mode Monitor mode to set.
  929. */
  930. void CLOCK_SetOsc0MonitorMode(mcg_monitor_mode_t mode);
  931. /*!
  932. * @brief Sets the RTC OSC clock monitor mode.
  933. *
  934. * This function sets the RTC OSC clock monitor mode. See @ref mcg_monitor_mode_t for details.
  935. *
  936. * @param mode Monitor mode to set.
  937. */
  938. void CLOCK_SetRtcOscMonitorMode(mcg_monitor_mode_t mode);
  939. /*!
  940. * @brief Sets the PLL0 clock monitor mode.
  941. *
  942. * This function sets the PLL0 clock monitor mode. See @ref mcg_monitor_mode_t for details.
  943. *
  944. * @param mode Monitor mode to set.
  945. */
  946. void CLOCK_SetPll0MonitorMode(mcg_monitor_mode_t mode);
  947. /*!
  948. * @brief Gets the MCG status flags.
  949. *
  950. * This function gets the MCG clock status flags. All status flags are
  951. * returned as a logical OR of the enumeration @ref _mcg_status_flags_t. To
  952. * check a specific flag, compare the return value with the flag.
  953. *
  954. * Example:
  955. * @code
  956. // To check the clock lost lock status of OSC0 and PLL0.
  957. uint32_t mcgFlags;
  958. mcgFlags = CLOCK_GetStatusFlags();
  959. if (mcgFlags & kMCG_Osc0LostFlag)
  960. {
  961. // OSC0 clock lock lost. Do something.
  962. }
  963. if (mcgFlags & kMCG_Pll0LostFlag)
  964. {
  965. // PLL0 clock lock lost. Do something.
  966. }
  967. @endcode
  968. *
  969. * @return Logical OR value of the @ref _mcg_status_flags_t.
  970. */
  971. uint32_t CLOCK_GetStatusFlags(void);
  972. /*!
  973. * @brief Clears the MCG status flags.
  974. *
  975. * This function clears the MCG clock lock lost status. The parameter is a logical
  976. * OR value of the flags to clear. See @ref _mcg_status_flags_t.
  977. *
  978. * Example:
  979. * @code
  980. // To clear the clock lost lock status flags of OSC0 and PLL0.
  981. CLOCK_ClearStatusFlags(kMCG_Osc0LostFlag | kMCG_Pll0LostFlag);
  982. @endcode
  983. *
  984. * @param mask The status flags to clear. This is a logical OR of members of the
  985. * enumeration @ref _mcg_status_flags_t.
  986. */
  987. void CLOCK_ClearStatusFlags(uint32_t mask);
  988. /*@}*/
  989. /*!
  990. * @name OSC configuration
  991. * @{
  992. */
  993. /*!
  994. * @brief Configures the OSC external reference clock (OSCERCLK).
  995. *
  996. * This function configures the OSC external reference clock (OSCERCLK).
  997. * This is an example to enable the OSCERCLK in normal and stop modes and also set
  998. * the output divider to 1:
  999. *
  1000. @code
  1001. oscer_config_t config =
  1002. {
  1003. .enableMode = kOSC_ErClkEnable | kOSC_ErClkEnableInStop,
  1004. .erclkDiv = 1U,
  1005. };
  1006. OSC_SetExtRefClkConfig(OSC, &config);
  1007. @endcode
  1008. *
  1009. * @param base OSC peripheral address.
  1010. * @param config Pointer to the configuration structure.
  1011. */
  1012. static inline void OSC_SetExtRefClkConfig(OSC_Type *base, oscer_config_t const *config)
  1013. {
  1014. uint8_t reg = base->CR;
  1015. reg &= ~(OSC_CR_ERCLKEN_MASK | OSC_CR_EREFSTEN_MASK);
  1016. reg |= config->enableMode;
  1017. base->CR = reg;
  1018. }
  1019. /*!
  1020. * @brief Sets the capacitor load configuration for the oscillator.
  1021. *
  1022. * This function sets the specified capacitors configuration for the oscillator.
  1023. * This should be done in the early system level initialization function call
  1024. * based on the system configuration.
  1025. *
  1026. * @param base OSC peripheral address.
  1027. * @param capLoad OR'ed value for the capacitor load option, see \ref _osc_cap_load.
  1028. *
  1029. * Example:
  1030. @code
  1031. // To enable only 2 pF and 8 pF capacitor load, please use like this.
  1032. OSC_SetCapLoad(OSC, kOSC_Cap2P | kOSC_Cap8P);
  1033. @endcode
  1034. */
  1035. static inline void OSC_SetCapLoad(OSC_Type *base, uint8_t capLoad)
  1036. {
  1037. uint8_t reg = base->CR;
  1038. reg &= ~(OSC_CR_SC2P_MASK | OSC_CR_SC4P_MASK | OSC_CR_SC8P_MASK | OSC_CR_SC16P_MASK);
  1039. reg |= capLoad;
  1040. base->CR = reg;
  1041. }
  1042. /*!
  1043. * @brief Initializes the OSC0.
  1044. *
  1045. * This function initializes the OSC0 according to the board configuration.
  1046. *
  1047. * @param config Pointer to the OSC0 configuration structure.
  1048. */
  1049. void CLOCK_InitOsc0(osc_config_t const *config);
  1050. /*!
  1051. * @brief Deinitializes the OSC0.
  1052. *
  1053. * This function deinitializes the OSC0.
  1054. */
  1055. void CLOCK_DeinitOsc0(void);
  1056. /* @} */
  1057. /*!
  1058. * @name External clock frequency
  1059. * @{
  1060. */
  1061. /*!
  1062. * @brief Sets the XTAL0 frequency based on board settings.
  1063. *
  1064. * @param freq The XTAL0/EXTAL0 input clock frequency in Hz.
  1065. */
  1066. static inline void CLOCK_SetXtal0Freq(uint32_t freq)
  1067. {
  1068. g_xtal0Freq = freq;
  1069. }
  1070. /*!
  1071. * @brief Sets the XTAL32/RTC_CLKIN frequency based on board settings.
  1072. *
  1073. * @param freq The XTAL32/EXTAL32/RTC_CLKIN input clock frequency in Hz.
  1074. */
  1075. static inline void CLOCK_SetXtal32Freq(uint32_t freq)
  1076. {
  1077. g_xtal32Freq = freq;
  1078. }
  1079. /* @} */
  1080. /*!
  1081. * @name MCG auto-trim machine.
  1082. * @{
  1083. */
  1084. /*!
  1085. * @brief Auto trims the internal reference clock.
  1086. *
  1087. * This function trims the internal reference clock by using the external clock. If
  1088. * successful, it returns the kStatus_Success and the frequency after
  1089. * trimming is received in the parameter @p actualFreq. If an error occurs,
  1090. * the error code is returned.
  1091. *
  1092. * @param extFreq External clock frequency, which should be a bus clock.
  1093. * @param desireFreq Frequency to trim to.
  1094. * @param actualFreq Actual frequency after trimming.
  1095. * @param atms Trim fast or slow internal reference clock.
  1096. * @retval kStatus_Success ATM success.
  1097. * @retval kStatus_MCG_AtmBusClockInvalid The bus clock is not in allowed range for the ATM.
  1098. * @retval kStatus_MCG_AtmDesiredFreqInvalid MCGIRCLK could not be trimmed to the desired frequency.
  1099. * @retval kStatus_MCG_AtmIrcUsed Could not trim because MCGIRCLK is used as a bus clock source.
  1100. * @retval kStatus_MCG_AtmHardwareFail Hardware fails while trimming.
  1101. */
  1102. status_t CLOCK_TrimInternalRefClk(uint32_t extFreq, uint32_t desireFreq, uint32_t *actualFreq, mcg_atm_select_t atms);
  1103. /* @} */
  1104. /*! @name MCG mode functions. */
  1105. /*@{*/
  1106. /*!
  1107. * @brief Gets the current MCG mode.
  1108. *
  1109. * This function checks the MCG registers and determines the current MCG mode.
  1110. *
  1111. * @return Current MCG mode or error code; See @ref mcg_mode_t.
  1112. */
  1113. mcg_mode_t CLOCK_GetMode(void);
  1114. /*!
  1115. * @brief Sets the MCG to FEI mode.
  1116. *
  1117. * This function sets the MCG to FEI mode. If setting to FEI mode fails
  1118. * from the current mode, this function returns an error.
  1119. *
  1120. * @param dmx32 DMX32 in FEI mode.
  1121. * @param drs The DCO range selection.
  1122. * @param fllStableDelay Delay function to ensure that the FLL is stable. Passing
  1123. * NULL does not cause a delay.
  1124. * @retval kStatus_MCG_ModeUnreachable Could not switch to the target mode.
  1125. * @retval kStatus_Success Switched to the target mode successfully.
  1126. * @note If @p dmx32 is set to kMCG_Dmx32Fine, the slow IRC must not be trimmed
  1127. * to a frequency above 32768 Hz.
  1128. */
  1129. status_t CLOCK_SetFeiMode(mcg_dmx32_t dmx32, mcg_drs_t drs, void (*fllStableDelay)(void));
  1130. /*!
  1131. * @brief Sets the MCG to FEE mode.
  1132. *
  1133. * This function sets the MCG to FEE mode. If setting to FEE mode fails
  1134. * from the current mode, this function returns an error.
  1135. *
  1136. * @param frdiv FLL reference clock divider setting, FRDIV.
  1137. * @param dmx32 DMX32 in FEE mode.
  1138. * @param drs The DCO range selection.
  1139. * @param fllStableDelay Delay function to make sure FLL is stable. Passing
  1140. * NULL does not cause a delay.
  1141. *
  1142. * @retval kStatus_MCG_ModeUnreachable Could not switch to the target mode.
  1143. * @retval kStatus_Success Switched to the target mode successfully.
  1144. */
  1145. status_t CLOCK_SetFeeMode(uint8_t frdiv, mcg_dmx32_t dmx32, mcg_drs_t drs, void (*fllStableDelay)(void));
  1146. /*!
  1147. * @brief Sets the MCG to FBI mode.
  1148. *
  1149. * This function sets the MCG to FBI mode. If setting to FBI mode fails
  1150. * from the current mode, this function returns an error.
  1151. *
  1152. * @param dmx32 DMX32 in FBI mode.
  1153. * @param drs The DCO range selection.
  1154. * @param fllStableDelay Delay function to make sure FLL is stable. If the FLL
  1155. * is not used in FBI mode, this parameter can be NULL. Passing
  1156. * NULL does not cause a delay.
  1157. * @retval kStatus_MCG_ModeUnreachable Could not switch to the target mode.
  1158. * @retval kStatus_Success Switched to the target mode successfully.
  1159. * @note If @p dmx32 is set to kMCG_Dmx32Fine, the slow IRC must not be trimmed
  1160. * to frequency above 32768 Hz.
  1161. */
  1162. status_t CLOCK_SetFbiMode(mcg_dmx32_t dmx32, mcg_drs_t drs, void (*fllStableDelay)(void));
  1163. /*!
  1164. * @brief Sets the MCG to FBE mode.
  1165. *
  1166. * This function sets the MCG to FBE mode. If setting to FBE mode fails
  1167. * from the current mode, this function returns an error.
  1168. *
  1169. * @param frdiv FLL reference clock divider setting, FRDIV.
  1170. * @param dmx32 DMX32 in FBE mode.
  1171. * @param drs The DCO range selection.
  1172. * @param fllStableDelay Delay function to make sure FLL is stable. If the FLL
  1173. * is not used in FBE mode, this parameter can be NULL. Passing NULL
  1174. * does not cause a delay.
  1175. * @retval kStatus_MCG_ModeUnreachable Could not switch to the target mode.
  1176. * @retval kStatus_Success Switched to the target mode successfully.
  1177. */
  1178. status_t CLOCK_SetFbeMode(uint8_t frdiv, mcg_dmx32_t dmx32, mcg_drs_t drs, void (*fllStableDelay)(void));
  1179. /*!
  1180. * @brief Sets the MCG to BLPI mode.
  1181. *
  1182. * This function sets the MCG to BLPI mode. If setting to BLPI mode fails
  1183. * from the current mode, this function returns an error.
  1184. *
  1185. * @retval kStatus_MCG_ModeUnreachable Could not switch to the target mode.
  1186. * @retval kStatus_Success Switched to the target mode successfully.
  1187. */
  1188. status_t CLOCK_SetBlpiMode(void);
  1189. /*!
  1190. * @brief Sets the MCG to BLPE mode.
  1191. *
  1192. * This function sets the MCG to BLPE mode. If setting to BLPE mode fails
  1193. * from the current mode, this function returns an error.
  1194. *
  1195. * @retval kStatus_MCG_ModeUnreachable Could not switch to the target mode.
  1196. * @retval kStatus_Success Switched to the target mode successfully.
  1197. */
  1198. status_t CLOCK_SetBlpeMode(void);
  1199. /*!
  1200. * @brief Sets the MCG to PBE mode.
  1201. *
  1202. * This function sets the MCG to PBE mode. If setting to PBE mode fails
  1203. * from the current mode, this function returns an error.
  1204. *
  1205. * @param pllcs The PLL selection, PLLCS.
  1206. * @param config Pointer to the PLL configuration.
  1207. * @retval kStatus_MCG_ModeUnreachable Could not switch to the target mode.
  1208. * @retval kStatus_Success Switched to the target mode successfully.
  1209. *
  1210. * @note
  1211. * 1. The parameter \c pllcs selects the PLL. For platforms with
  1212. * only one PLL, the parameter pllcs is kept for interface compatibility.
  1213. * 2. The parameter \c config is the PLL configuration structure. On some
  1214. * platforms, it is possible to choose the external PLL directly, which renders the
  1215. * configuration structure not necessary. In this case, pass in NULL.
  1216. * For example: CLOCK_SetPbeMode(kMCG_OscselOsc, kMCG_PllClkSelExtPll, NULL);
  1217. */
  1218. status_t CLOCK_SetPbeMode(mcg_pll_clk_select_t pllcs, mcg_pll_config_t const *config);
  1219. /*!
  1220. * @brief Sets the MCG to PEE mode.
  1221. *
  1222. * This function sets the MCG to PEE mode.
  1223. *
  1224. * @retval kStatus_MCG_ModeUnreachable Could not switch to the target mode.
  1225. * @retval kStatus_Success Switched to the target mode successfully.
  1226. *
  1227. * @note This function only changes the CLKS to use the PLL/FLL output. If the
  1228. * PRDIV/VDIV are different than in the PBE mode, set them up
  1229. * in PBE mode and wait. When the clock is stable, switch to PEE mode.
  1230. */
  1231. status_t CLOCK_SetPeeMode(void);
  1232. /*!
  1233. * @brief Switches the MCG to FBE mode from the external mode.
  1234. *
  1235. * This function switches the MCG from external modes (PEE/PBE/BLPE/FEE) to the FBE mode quickly.
  1236. * The external clock is used as the system clock souce and PLL is disabled. However,
  1237. * the FLL settings are not configured. This is a lite function with a small code size, which is useful
  1238. * during the mode switch. For example, to switch from PEE mode to FEI mode:
  1239. *
  1240. * @code
  1241. * CLOCK_ExternalModeToFbeModeQuick();
  1242. * CLOCK_SetFeiMode(...);
  1243. * @endcode
  1244. *
  1245. * @retval kStatus_Success Switched successfully.
  1246. * @retval kStatus_MCG_ModeInvalid If the current mode is not an external mode, do not call this function.
  1247. */
  1248. status_t CLOCK_ExternalModeToFbeModeQuick(void);
  1249. /*!
  1250. * @brief Switches the MCG to FBI mode from internal modes.
  1251. *
  1252. * This function switches the MCG from internal modes (PEI/PBI/BLPI/FEI) to the FBI mode quickly.
  1253. * The MCGIRCLK is used as the system clock souce and PLL is disabled. However,
  1254. * FLL settings are not configured. This is a lite function with a small code size, which is useful
  1255. * during the mode switch. For example, to switch from PEI mode to FEE mode:
  1256. *
  1257. * @code
  1258. * CLOCK_InternalModeToFbiModeQuick();
  1259. * CLOCK_SetFeeMode(...);
  1260. * @endcode
  1261. *
  1262. * @retval kStatus_Success Switched successfully.
  1263. * @retval kStatus_MCG_ModeInvalid If the current mode is not an internal mode, do not call this function.
  1264. */
  1265. status_t CLOCK_InternalModeToFbiModeQuick(void);
  1266. /*!
  1267. * @brief Sets the MCG to FEI mode during system boot up.
  1268. *
  1269. * This function sets the MCG to FEI mode from the reset mode. It can also be used to
  1270. * set up MCG during system boot up.
  1271. *
  1272. * @param dmx32 DMX32 in FEI mode.
  1273. * @param drs The DCO range selection.
  1274. * @param fllStableDelay Delay function to ensure that the FLL is stable.
  1275. *
  1276. * @retval kStatus_MCG_ModeUnreachable Could not switch to the target mode.
  1277. * @retval kStatus_Success Switched to the target mode successfully.
  1278. * @note If @p dmx32 is set to kMCG_Dmx32Fine, the slow IRC must not be trimmed
  1279. * to frequency above 32768 Hz.
  1280. */
  1281. status_t CLOCK_BootToFeiMode(mcg_dmx32_t dmx32, mcg_drs_t drs, void (*fllStableDelay)(void));
  1282. /*!
  1283. * @brief Sets the MCG to FEE mode during system bootup.
  1284. *
  1285. * This function sets MCG to FEE mode from the reset mode. It can also be used to
  1286. * set up the MCG during system boot up.
  1287. *
  1288. * @param oscsel OSC clock select, OSCSEL.
  1289. * @param frdiv FLL reference clock divider setting, FRDIV.
  1290. * @param dmx32 DMX32 in FEE mode.
  1291. * @param drs The DCO range selection.
  1292. * @param fllStableDelay Delay function to ensure that the FLL is stable.
  1293. *
  1294. * @retval kStatus_MCG_ModeUnreachable Could not switch to the target mode.
  1295. * @retval kStatus_Success Switched to the target mode successfully.
  1296. */
  1297. status_t CLOCK_BootToFeeMode(
  1298. mcg_oscsel_t oscsel, uint8_t frdiv, mcg_dmx32_t dmx32, mcg_drs_t drs, void (*fllStableDelay)(void));
  1299. /*!
  1300. * @brief Sets the MCG to BLPI mode during system boot up.
  1301. *
  1302. * This function sets the MCG to BLPI mode from the reset mode. It can also be used to
  1303. * set up the MCG during sytem boot up.
  1304. *
  1305. * @param fcrdiv Fast IRC divider, FCRDIV.
  1306. * @param ircs The internal reference clock to select, IRCS.
  1307. * @param ircEnableMode The MCGIRCLK enable mode, OR'ed value of @ref _mcg_irclk_enable_mode.
  1308. *
  1309. * @retval kStatus_MCG_SourceUsed Could not change MCGIRCLK setting.
  1310. * @retval kStatus_Success Switched to the target mode successfully.
  1311. */
  1312. status_t CLOCK_BootToBlpiMode(uint8_t fcrdiv, mcg_irc_mode_t ircs, uint8_t ircEnableMode);
  1313. /*!
  1314. * @brief Sets the MCG to BLPE mode during sytem boot up.
  1315. *
  1316. * This function sets the MCG to BLPE mode from the reset mode. It can also be used to
  1317. * set up the MCG during sytem boot up.
  1318. *
  1319. * @param oscsel OSC clock select, MCG_C7[OSCSEL].
  1320. *
  1321. * @retval kStatus_MCG_ModeUnreachable Could not switch to the target mode.
  1322. * @retval kStatus_Success Switched to the target mode successfully.
  1323. */
  1324. status_t CLOCK_BootToBlpeMode(mcg_oscsel_t oscsel);
  1325. /*!
  1326. * @brief Sets the MCG to PEE mode during system boot up.
  1327. *
  1328. * This function sets the MCG to PEE mode from reset mode. It can also be used to
  1329. * set up the MCG during system boot up.
  1330. *
  1331. * @param oscsel OSC clock select, MCG_C7[OSCSEL].
  1332. * @param pllcs The PLL selection, PLLCS.
  1333. * @param config Pointer to the PLL configuration.
  1334. *
  1335. * @retval kStatus_MCG_ModeUnreachable Could not switch to the target mode.
  1336. * @retval kStatus_Success Switched to the target mode successfully.
  1337. */
  1338. status_t CLOCK_BootToPeeMode(mcg_oscsel_t oscsel, mcg_pll_clk_select_t pllcs, mcg_pll_config_t const *config);
  1339. /*!
  1340. * @brief Sets the MCG to a target mode.
  1341. *
  1342. * This function sets MCG to a target mode defined by the configuration
  1343. * structure. If switching to the target mode fails, this function
  1344. * chooses the correct path.
  1345. *
  1346. * @param config Pointer to the target MCG mode configuration structure.
  1347. * @return Return kStatus_Success if switched successfully; Otherwise, it returns an error code #_mcg_status.
  1348. *
  1349. * @note If the external clock is used in the target mode, ensure that it is
  1350. * enabled. For example, if the OSC0 is used, set up OSC0 correctly before calling this
  1351. * function.
  1352. */
  1353. status_t CLOCK_SetMcgConfig(mcg_config_t const *config);
  1354. /*@}*/
  1355. #if defined(__cplusplus)
  1356. }
  1357. #endif /* __cplusplus */
  1358. /*! @} */
  1359. #endif /* _FSL_CLOCK_H_ */