fsl_clock.h 53 KB

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