fsl_clock.h 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288
  1. /*
  2. * Copyright (c) 2017 - 2018 , NXP
  3. * All rights reserved.
  4. *
  5. * SPDX-License-Identifier: BSD-3-Clause
  6. */
  7. #ifndef _FSL_CLOCK_H_
  8. #define _FSL_CLOCK_H_
  9. #include "fsl_device_registers.h"
  10. #include <stdint.h>
  11. #include <stdbool.h>
  12. #include <assert.h>
  13. /*! @addtogroup clock */
  14. /*! @{ */
  15. /*! @file */
  16. /*******************************************************************************
  17. * Definitions
  18. *****************************************************************************/
  19. /*! @name Driver version */
  20. /*@{*/
  21. /*! @brief CLOCK driver version 2.0.3. */
  22. #define FSL_CLOCK_DRIVER_VERSION (MAKE_VERSION(2, 0, 3))
  23. /*@}*/
  24. /*! @brief Configure whether driver controls clock
  25. *
  26. * When set to 0, peripheral drivers will enable clock in initialize function
  27. * and disable clock in de-initialize function. When set to 1, peripheral
  28. * driver will not control the clock, application could control the clock out of
  29. * the driver.
  30. *
  31. * @note All drivers share this feature switcher. If it is set to 1, application
  32. * should handle clock enable and disable for all drivers.
  33. */
  34. #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL))
  35. #define FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL 0
  36. #endif
  37. /*!
  38. * @brief User-defined the size of cache for CLOCK_PllGetConfig() function.
  39. *
  40. * Once define this MACRO to be non-zero value, CLOCK_PllGetConfig() function
  41. * would cache the recent calulation and accelerate the execution to get the
  42. * right settings.
  43. */
  44. #ifndef CLOCK_USR_CFG_PLL_CONFIG_CACHE_COUNT
  45. #define CLOCK_USR_CFG_PLL_CONFIG_CACHE_COUNT 2U
  46. #endif
  47. /*! @brief Clock ip name array for ROM. */
  48. #define ROM_CLOCKS \
  49. { \
  50. kCLOCK_Rom \
  51. }
  52. /*! @brief Clock ip name array for SRAM. */
  53. #define SRAM_CLOCKS \
  54. { \
  55. kCLOCK_Sram1, kCLOCK_Sram2, kCLOCK_Sram3, kCLOCK_Sram4 \
  56. }
  57. /*! @brief Clock ip name array for FLASH. */
  58. #define FLASH_CLOCKS \
  59. { \
  60. kCLOCK_Flash \
  61. }
  62. /*! @brief Clock ip name array for FMC. */
  63. #define FMC_CLOCKS \
  64. { \
  65. kCLOCK_Fmc \
  66. }
  67. /*! @brief Clock ip name array for INPUTMUX. */
  68. #define INPUTMUX_CLOCKS \
  69. { \
  70. kCLOCK_InputMux0, kCLOCK_InputMux1 \
  71. }
  72. /*! @brief Clock ip name array for IOCON. */
  73. #define IOCON_CLOCKS \
  74. { \
  75. kCLOCK_Iocon \
  76. }
  77. /*! @brief Clock ip name array for GPIO. */
  78. #define GPIO_CLOCKS \
  79. { \
  80. kCLOCK_Gpio0, kCLOCK_Gpio1, kCLOCK_Gpio2, kCLOCK_Gpio3, kCLOCK_Gpio4, kCLOCK_Gpio5 \
  81. }
  82. /*! @brief Clock ip name array for PINT. */
  83. #define PINT_CLOCKS \
  84. { \
  85. kCLOCK_Pint \
  86. }
  87. /*! @brief Clock ip name array for GINT. */
  88. #define GINT_CLOCKS \
  89. { \
  90. kCLOCK_Gint, kCLOCK_Gint \
  91. }
  92. /*! @brief Clock ip name array for DMA. */
  93. #define DMA_CLOCKS \
  94. { \
  95. kCLOCK_Dma0, kCLOCK_Dma1 \
  96. }
  97. /*! @brief Clock ip name array for CRC. */
  98. #define CRC_CLOCKS \
  99. { \
  100. kCLOCK_Crc \
  101. }
  102. /*! @brief Clock ip name array for WWDT. */
  103. #define WWDT_CLOCKS \
  104. { \
  105. kCLOCK_Wwdt \
  106. }
  107. /*! @brief Clock ip name array for RTC. */
  108. #define RTC_CLOCKS \
  109. { \
  110. kCLOCK_Rtc \
  111. }
  112. /*! @brief Clock ip name array for Mailbox. */
  113. #define MAILBOX_CLOCKS \
  114. { \
  115. kCLOCK_Mailbox \
  116. }
  117. /*! @brief Clock ip name array for LPADC. */
  118. #define LPADC_CLOCKS \
  119. { \
  120. kCLOCK_Adc0 \
  121. }
  122. /*! @brief Clock ip name array for MRT. */
  123. #define MRT_CLOCKS \
  124. { \
  125. kCLOCK_Mrt \
  126. }
  127. /*! @brief Clock ip name array for OSTIMER. */
  128. #define OSTIMER_CLOCKS \
  129. { \
  130. kCLOCK_OsTimer0 \
  131. }
  132. /*! @brief Clock ip name array for SCT0. */
  133. #define SCT_CLOCKS \
  134. { \
  135. kCLOCK_Sct0 \
  136. }
  137. /*! @brief Clock ip name array for SCTIPU. */
  138. #define SCTIPU_CLOCKS \
  139. { \
  140. kCLOCK_Sctipu \
  141. }
  142. /*! @brief Clock ip name array for UTICK. */
  143. #define UTICK_CLOCKS \
  144. { \
  145. kCLOCK_Utick0 \
  146. }
  147. /*! @brief Clock ip name array for FLEXCOMM. */
  148. #define FLEXCOMM_CLOCKS \
  149. { \
  150. kCLOCK_FlexComm0, kCLOCK_FlexComm1, kCLOCK_FlexComm2, kCLOCK_FlexComm3, kCLOCK_FlexComm4, kCLOCK_FlexComm5, \
  151. kCLOCK_FlexComm6, kCLOCK_FlexComm7, kCLOCK_Hs_Lspi \
  152. }
  153. /*! @brief Clock ip name array for LPUART. */
  154. #define LPUART_CLOCKS \
  155. { \
  156. kCLOCK_MinUart0, kCLOCK_MinUart1, kCLOCK_MinUart2, kCLOCK_MinUart3, kCLOCK_MinUart4, kCLOCK_MinUart5, \
  157. kCLOCK_MinUart6, kCLOCK_MinUart7 \
  158. }
  159. /*! @brief Clock ip name array for BI2C. */
  160. #define BI2C_CLOCKS \
  161. { \
  162. kCLOCK_BI2c0, kCLOCK_BI2c1, kCLOCK_BI2c2, kCLOCK_BI2c3, kCLOCK_BI2c4, kCLOCK_BI2c5, kCLOCK_BI2c6, kCLOCK_BI2c7 \
  163. }
  164. /*! @brief Clock ip name array for LSPI. */
  165. #define LPSPI_CLOCKS \
  166. { \
  167. kCLOCK_LSpi0, kCLOCK_LSpi1, kCLOCK_LSpi2, kCLOCK_LSpi3, kCLOCK_LSpi4, kCLOCK_LSpi5, kCLOCK_LSpi6, kCLOCK_LSpi7 \
  168. }
  169. /*! @brief Clock ip name array for FLEXI2S. */
  170. #define FLEXI2S_CLOCKS \
  171. { \
  172. kCLOCK_FlexI2s0, kCLOCK_FlexI2s1, kCLOCK_FlexI2s2, kCLOCK_FlexI2s3, kCLOCK_FlexI2s4, kCLOCK_FlexI2s5, \
  173. kCLOCK_FlexI2s6, kCLOCK_FlexI2s7 \
  174. }
  175. /*! @brief Clock ip name array for USBTYPC. */
  176. #define USBTYPC_CLOCKS \
  177. { \
  178. kCLOCK_UsbTypc \
  179. }
  180. /*! @brief Clock ip name array for CTIMER. */
  181. #define CTIMER_CLOCKS \
  182. { \
  183. kCLOCK_Timer0, kCLOCK_Timer1, kCLOCK_Timer2, kCLOCK_Timer3, kCLOCK_Timer4 \
  184. }
  185. /*! @brief Clock ip name array for PVT */
  186. #define PVT_CLOCKS \
  187. { \
  188. kCLOCK_Pvt \
  189. }
  190. /*! @brief Clock ip name array for EZHA */
  191. #define EZHA_CLOCKS \
  192. { \
  193. kCLOCK_Ezha \
  194. }
  195. /*! @brief Clock ip name array for EZHB */
  196. #define EZHB_CLOCKS \
  197. { \
  198. kCLOCK_Ezhb \
  199. }
  200. /*! @brief Clock ip name array for COMP */
  201. #define COMP_CLOCKS \
  202. { \
  203. kCLOCK_Comp \
  204. }
  205. /*! @brief Clock ip name array for SDIO. */
  206. #define SDIO_CLOCKS \
  207. { \
  208. kCLOCK_Sdio \
  209. }
  210. /*! @brief Clock ip name array for USB1CLK. */
  211. #define USB1CLK_CLOCKS \
  212. { \
  213. kCLOCK_Usb1Clk \
  214. }
  215. /*! @brief Clock ip name array for FREQME. */
  216. #define FREQME_CLOCKS \
  217. { \
  218. kCLOCK_Freqme \
  219. }
  220. /*! @brief Clock ip name array for USBRAM. */
  221. #define USBRAM_CLOCKS \
  222. { \
  223. kCLOCK_UsbRam1 \
  224. }
  225. /*! @brief Clock ip name array for OTP. */
  226. #define OTP_CLOCKS \
  227. { \
  228. kCLOCK_Otp \
  229. }
  230. /*! @brief Clock ip name array for RNG. */
  231. #define RNG_CLOCKS \
  232. { \
  233. kCLOCK_Rng \
  234. }
  235. /*! @brief Clock ip name array for USBHMR0. */
  236. #define USBHMR0_CLOCKS \
  237. { \
  238. kCLOCK_Usbhmr0 \
  239. }
  240. /*! @brief Clock ip name array for USBHSL0. */
  241. #define USBHSL0_CLOCKS \
  242. { \
  243. kCLOCK_Usbhsl0 \
  244. }
  245. /*! @brief Clock ip name array for HashCrypt. */
  246. #define HASHCRYPT_CLOCKS \
  247. { \
  248. kCLOCK_HashCrypt \
  249. }
  250. /*! @brief Clock ip name array for PowerQuad. */
  251. #define POWERQUAD_CLOCKS \
  252. { \
  253. kCLOCK_PowerQuad \
  254. }
  255. /*! @brief Clock ip name array for PLULUT. */
  256. #define PLULUT_CLOCKS \
  257. { \
  258. kCLOCK_PluLut \
  259. }
  260. /*! @brief Clock ip name array for PUF. */
  261. #define PUF_CLOCKS \
  262. { \
  263. kCLOCK_Puf \
  264. }
  265. /*! @brief Clock ip name array for CASPER. */
  266. #define CASPER_CLOCKS \
  267. { \
  268. kCLOCK_Casper \
  269. }
  270. /*! @brief Clock ip name array for ANALOGCTRL. */
  271. #define ANALOGCTRL_CLOCKS \
  272. { \
  273. kCLOCK_AnalogCtrl \
  274. }
  275. /*! @brief Clock ip name array for HS_LSPI. */
  276. #define HS_LSPI_CLOCKS \
  277. { \
  278. kCLOCK_Hs_Lspi \
  279. }
  280. /*! @brief Clock ip name array for GPIO_SEC. */
  281. #define GPIO_SEC_CLOCKS \
  282. { \
  283. kCLOCK_Gpio_Sec \
  284. }
  285. /*! @brief Clock ip name array for GPIO_SEC_INT. */
  286. #define GPIO_SEC_INT_CLOCKS \
  287. { \
  288. kCLOCK_Gpio_Sec_Int \
  289. }
  290. /*! @brief Clock ip name array for USBD. */
  291. #define USBD_CLOCKS \
  292. { \
  293. kCLOCK_Usbd0, kCLOCK_Usbh1, kCLOCK_Usbd1 \
  294. }
  295. /*! @brief Clock ip name array for USBH. */
  296. #define USBH_CLOCKS \
  297. { \
  298. kCLOCK_Usbh1 \
  299. }
  300. #define PLU_CLOCKS \
  301. { \
  302. kCLOCK_PluLut \
  303. }
  304. #define SYSCTL_CLOCKS \
  305. { \
  306. kCLOCK_Sysctl \
  307. }
  308. /*! @brief Clock gate name used for CLOCK_EnableClock/CLOCK_DisableClock. */
  309. /*------------------------------------------------------------------------------
  310. clock_ip_name_t definition:
  311. ------------------------------------------------------------------------------*/
  312. #define CLK_GATE_REG_OFFSET_SHIFT 8U
  313. #define CLK_GATE_REG_OFFSET_MASK 0xFFFFFF00U
  314. #define CLK_GATE_BIT_SHIFT_SHIFT 0U
  315. #define CLK_GATE_BIT_SHIFT_MASK 0x000000FFU
  316. #define CLK_GATE_DEFINE(reg_offset, bit_shift) \
  317. ((((reg_offset) << CLK_GATE_REG_OFFSET_SHIFT) & CLK_GATE_REG_OFFSET_MASK) | \
  318. (((bit_shift) << CLK_GATE_BIT_SHIFT_SHIFT) & CLK_GATE_BIT_SHIFT_MASK))
  319. #define CLK_GATE_ABSTRACT_REG_OFFSET(x) (((uint32_t)(x)&CLK_GATE_REG_OFFSET_MASK) >> CLK_GATE_REG_OFFSET_SHIFT)
  320. #define CLK_GATE_ABSTRACT_BITS_SHIFT(x) (((uint32_t)(x)&CLK_GATE_BIT_SHIFT_MASK) >> CLK_GATE_BIT_SHIFT_SHIFT)
  321. #define AHB_CLK_CTRL0 0
  322. #define AHB_CLK_CTRL1 1
  323. #define AHB_CLK_CTRL2 2
  324. /*! @brief Clock gate name used for CLOCK_EnableClock/CLOCK_DisableClock. */
  325. typedef enum _clock_ip_name
  326. {
  327. kCLOCK_IpInvalid = 0U,
  328. kCLOCK_Rom = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 1),
  329. kCLOCK_Sram1 = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 3),
  330. kCLOCK_Sram2 = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 4),
  331. kCLOCK_Sram3 = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 5),
  332. kCLOCK_Sram4 = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 6),
  333. kCLOCK_Flash = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 7),
  334. kCLOCK_Fmc = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 8),
  335. kCLOCK_InputMux = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 11),
  336. kCLOCK_Iocon = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 13),
  337. kCLOCK_Gpio0 = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 14),
  338. kCLOCK_Gpio1 = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 15),
  339. kCLOCK_Gpio2 = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 16),
  340. kCLOCK_Gpio3 = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 17),
  341. kCLOCK_Pint = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 18),
  342. kCLOCK_Gint = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 19),
  343. kCLOCK_Dma0 = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 20),
  344. kCLOCK_Crc = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 21),
  345. kCLOCK_Wwdt = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 22),
  346. kCLOCK_Rtc = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 23),
  347. kCLOCK_Mailbox = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 26),
  348. kCLOCK_Adc0 = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 27),
  349. kCLOCK_Mrt = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 0),
  350. kCLOCK_OsTimer0 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 1),
  351. kCLOCK_Sct0 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 2),
  352. kCLOCK_Sctipu = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 6),
  353. kCLOCK_Utick0 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 10),
  354. kCLOCK_FlexComm0 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 11),
  355. kCLOCK_FlexComm1 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 12),
  356. kCLOCK_FlexComm2 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 13),
  357. kCLOCK_FlexComm3 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 14),
  358. kCLOCK_FlexComm4 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 15),
  359. kCLOCK_FlexComm5 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 16),
  360. kCLOCK_FlexComm6 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 17),
  361. kCLOCK_FlexComm7 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 18),
  362. kCLOCK_MinUart0 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 11),
  363. kCLOCK_MinUart1 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 12),
  364. kCLOCK_MinUart2 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 13),
  365. kCLOCK_MinUart3 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 14),
  366. kCLOCK_MinUart4 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 15),
  367. kCLOCK_MinUart5 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 16),
  368. kCLOCK_MinUart6 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 17),
  369. kCLOCK_MinUart7 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 18),
  370. kCLOCK_LSpi0 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 11),
  371. kCLOCK_LSpi1 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 12),
  372. kCLOCK_LSpi2 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 13),
  373. kCLOCK_LSpi3 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 14),
  374. kCLOCK_LSpi4 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 15),
  375. kCLOCK_LSpi5 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 16),
  376. kCLOCK_LSpi6 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 17),
  377. kCLOCK_LSpi7 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 18),
  378. kCLOCK_BI2c0 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 11),
  379. kCLOCK_BI2c1 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 12),
  380. kCLOCK_BI2c2 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 13),
  381. kCLOCK_BI2c3 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 14),
  382. kCLOCK_BI2c4 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 15),
  383. kCLOCK_BI2c5 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 16),
  384. kCLOCK_BI2c6 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 17),
  385. kCLOCK_BI2c7 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 18),
  386. kCLOCK_FlexI2s0 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 11),
  387. kCLOCK_FlexI2s1 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 12),
  388. kCLOCK_FlexI2s2 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 13),
  389. kCLOCK_FlexI2s3 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 14),
  390. kCLOCK_FlexI2s4 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 15),
  391. kCLOCK_FlexI2s5 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 16),
  392. kCLOCK_FlexI2s6 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 17),
  393. kCLOCK_FlexI2s7 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 18),
  394. kCLOCK_UsbTypc = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 20),
  395. kCLOCK_Timer2 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 22),
  396. kCLOCK_Usbd0 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 25),
  397. kCLOCK_Timer0 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 26),
  398. kCLOCK_Timer1 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 27),
  399. kCLOCK_Pvt = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 28),
  400. kCLOCK_Ezha = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 30),
  401. kCLOCK_Ezhb = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 31),
  402. kCLOCK_Dma1 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 1),
  403. kCLOCK_Comp = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 2),
  404. kCLOCK_Sdio = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 3),
  405. kCLOCK_Usbh1 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 4),
  406. kCLOCK_Usbd1 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 5),
  407. kCLOCK_UsbRam1 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 6),
  408. kCLOCK_Usb1Clk = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 7),
  409. kCLOCK_Freqme = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 8),
  410. kCLOCK_Gpio4 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 9),
  411. kCLOCK_Gpio5 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 10),
  412. kCLOCK_Otp = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 12),
  413. kCLOCK_Rng = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 13),
  414. kCLOCK_InputMux1 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 14),
  415. kCLOCK_Sysctl = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 15),
  416. kCLOCK_Usbhmr0 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 16),
  417. kCLOCK_Usbhsl0 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 17),
  418. kCLOCK_HashCrypt = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 18),
  419. kCLOCK_PowerQuad = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 19),
  420. kCLOCK_PluLut = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 20),
  421. kCLOCK_Timer3 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 21),
  422. kCLOCK_Timer4 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 22),
  423. kCLOCK_Puf = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 23),
  424. kCLOCK_Casper = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 24),
  425. kCLOCK_AnalogCtrl = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 27),
  426. kCLOCK_Hs_Lspi = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 28),
  427. kCLOCK_Gpio_Sec = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 29),
  428. kCLOCK_Gpio_sec_Int = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 30)
  429. } clock_ip_name_t;
  430. /*! @brief Peripherals clock source definition. */
  431. #define BUS_CLK kCLOCK_BusClk
  432. #define I2C0_CLK_SRC BUS_CLK
  433. /*! @brief Clock name used to get clock frequency. */
  434. typedef enum _clock_name
  435. {
  436. kCLOCK_CoreSysClk, /*!< Core/system clock (aka MAIN_CLK) */
  437. kCLOCK_BusClk, /*!< Bus clock (AHB clock) */
  438. kCLOCK_ClockOut, /*!< CLOCKOUT */
  439. kCLOCK_FroHf, /*!< FRO48/96 */
  440. kCLOCK_Adc, /*!< ADC */
  441. kCLOCK_Usb0, /*!< USB0 */
  442. kCLOCK_Usb1, /*!< USB1 */
  443. kCLOCK_Pll1Out, /*!< PLL1 Output */
  444. kCLOCK_Mclk, /*!< MCLK */
  445. kCLOCK_Sct, /*!< SCT */
  446. kCLOCK_SDio, /*!< SDIO */
  447. kCLOCK_Fro12M, /*!< FRO12M */
  448. kCLOCK_ExtClk, /*!< External Clock */
  449. kCLOCK_Pll0Out, /*!< PLL0 Output */
  450. kCLOCK_WdtClk, /*!< Watchdog clock */
  451. kCLOCK_FlexI2S, /*!< FlexI2S clock */
  452. kCLOCK_Flexcomm0, /*!< Flexcomm0Clock */
  453. kCLOCK_Flexcomm1, /*!< Flexcomm1Clock */
  454. kCLOCK_Flexcomm2, /*!< Flexcomm2Clock */
  455. kCLOCK_Flexcomm3, /*!< Flexcomm3Clock */
  456. kCLOCK_Flexcomm4, /*!< Flexcomm4Clock */
  457. kCLOCK_Flexcomm5, /*!< Flexcomm5Clock */
  458. kCLOCK_Flexcomm6, /*!< Flexcomm6Clock */
  459. kCLOCK_Flexcomm7, /*!< Flexcomm7Clock */
  460. kCLOCK_HsLspi, /*!< HS LPSPI Clock */
  461. kCLOCK_CTmier0, /*!< CTmier0Clock */
  462. kCLOCK_CTmier1, /*!< CTmier1Clock */
  463. kCLOCK_CTmier2, /*!< CTmier2Clock */
  464. kCLOCK_CTmier3, /*!< CTmier3Clock */
  465. kCLOCK_CTmier4, /*!< CTmier4Clock */
  466. kCLOCK_Systick0, /*!< System Tick 0 Clock */
  467. kCLOCK_Systick1, /*!< System Tick 1 Clock */
  468. } clock_name_t;
  469. /*! @brief Clock Mux Switches
  470. * The encoding is as follows each connection identified is 32bits wide while 24bits are valuable
  471. * starting from LSB upwards
  472. *
  473. * [4 bits for choice, 0 means invalid choice] [8 bits mux ID]*
  474. *
  475. */
  476. #define CLK_ATTACH_ID(mux, sel, pos) (((mux << 0U) | ((sel + 1) & 0xFU) << 8U) << (pos * 12U))
  477. #define MUX_A(mux, sel) CLK_ATTACH_ID(mux, sel, 0U)
  478. #define MUX_B(mux, sel, selector) (CLK_ATTACH_ID(mux, sel, 1U) | (selector << 24U))
  479. #define GET_ID_ITEM(connection) ((connection)&0xFFFU)
  480. #define GET_ID_NEXT_ITEM(connection) ((connection) >> 12U)
  481. #define GET_ID_ITEM_MUX(connection) ((connection)&0xFFU)
  482. #define GET_ID_ITEM_SEL(connection) ((((connection)&0xF00U) >> 8U) - 1U)
  483. #define GET_ID_SELECTOR(connection) ((connection)&0xF000000U)
  484. #define CM_SYSTICKCLKSEL0 0
  485. #define CM_SYSTICKCLKSEL1 1
  486. #define CM_TRACECLKSEL 2
  487. #define CM_CTIMERCLKSEL0 3
  488. #define CM_CTIMERCLKSEL1 4
  489. #define CM_CTIMERCLKSEL2 5
  490. #define CM_CTIMERCLKSEL3 6
  491. #define CM_CTIMERCLKSEL4 7
  492. #define CM_MAINCLKSELA 8
  493. #define CM_MAINCLKSELB 9
  494. #define CM_CLKOUTCLKSEL 10
  495. #define CM_PLL0CLKSEL 12
  496. #define CM_PLL1CLKSEL 13
  497. #define CM_ADCASYNCCLKSEL 17
  498. #define CM_USB0CLKSEL 18
  499. #define CM_FXCOMCLKSEL0 20
  500. #define CM_FXCOMCLKSEL1 21
  501. #define CM_FXCOMCLKSEL2 22
  502. #define CM_FXCOMCLKSEL3 23
  503. #define CM_FXCOMCLKSEL4 24
  504. #define CM_FXCOMCLKSEL5 25
  505. #define CM_FXCOMCLKSEL6 26
  506. #define CM_FXCOMCLKSEL7 27
  507. #define CM_HSLSPICLKSEL 28
  508. #define CM_MCLKCLKSEL 32
  509. #define CM_SCTCLKSEL 36
  510. #define CM_SDIOCLKSEL 38
  511. #define CM_RTCOSC32KCLKSEL 63
  512. typedef enum _clock_attach_id
  513. {
  514. kFRO12M_to_MAIN_CLK = MUX_A(CM_MAINCLKSELA, 0) | MUX_B(CM_MAINCLKSELB, 0, 0),
  515. kEXT_CLK_to_MAIN_CLK = MUX_A(CM_MAINCLKSELA, 1) | MUX_B(CM_MAINCLKSELB, 0, 0),
  516. kFRO1M_to_MAIN_CLK = MUX_A(CM_MAINCLKSELA, 2) | MUX_B(CM_MAINCLKSELB, 0, 0),
  517. kFRO_HF_to_MAIN_CLK = MUX_A(CM_MAINCLKSELA, 3) | MUX_B(CM_MAINCLKSELB, 0, 0),
  518. kPLL0_to_MAIN_CLK = MUX_A(CM_MAINCLKSELA, 0) | MUX_B(CM_MAINCLKSELB, 1, 0),
  519. kPLL1_to_MAIN_CLK = MUX_A(CM_MAINCLKSELA, 0) | MUX_B(CM_MAINCLKSELB, 2, 0),
  520. kOSC32K_to_MAIN_CLK = MUX_A(CM_MAINCLKSELA, 0) | MUX_B(CM_MAINCLKSELB, 3, 0),
  521. kMAIN_CLK_to_CLKOUT = MUX_A(CM_CLKOUTCLKSEL, 0),
  522. kPLL0_to_CLKOUT = MUX_A(CM_CLKOUTCLKSEL, 1),
  523. kEXT_CLK_to_CLKOUT = MUX_A(CM_CLKOUTCLKSEL, 2),
  524. kFRO_HF_to_CLKOUT = MUX_A(CM_CLKOUTCLKSEL, 3),
  525. kFRO1M_to_CLKOUT = MUX_A(CM_CLKOUTCLKSEL, 4),
  526. kPLL1_to_CLKOUT = MUX_A(CM_CLKOUTCLKSEL, 5),
  527. kOSC32K_to_CLKOUT = MUX_A(CM_CLKOUTCLKSEL, 6),
  528. kNONE_to_SYS_CLKOUT = MUX_A(CM_CLKOUTCLKSEL, 7),
  529. kFRO12M_to_PLL0 = MUX_A(CM_PLL0CLKSEL, 0),
  530. kEXT_CLK_to_PLL0 = MUX_A(CM_PLL0CLKSEL, 1),
  531. kFRO1M_to_PLL0 = MUX_A(CM_PLL0CLKSEL, 2),
  532. kOSC32K_to_PLL0 = MUX_A(CM_PLL0CLKSEL, 3),
  533. kNONE_to_PLL0 = MUX_A(CM_PLL0CLKSEL, 7),
  534. kMAIN_CLK_to_ADC_CLK = MUX_A(CM_ADCASYNCCLKSEL, 0),
  535. kPLL0_to_ADC_CLK = MUX_A(CM_ADCASYNCCLKSEL, 1),
  536. kFRO_HF_to_ADC_CLK = MUX_A(CM_ADCASYNCCLKSEL, 2),
  537. kFRO1M_to_ADC_CLK = MUX_A(CM_ADCASYNCCLKSEL, 3), /* Need confirm */
  538. kNONE_to_ADC_CLK = MUX_A(CM_ADCASYNCCLKSEL, 7),
  539. kMAIN_CLK_to_USB0_CLK = MUX_A(CM_USB0CLKSEL, 0),
  540. kPLL0_to_USB0_CLK = MUX_A(CM_USB0CLKSEL, 1),
  541. kFRO_HF_to_USB0_CLK = MUX_A(CM_USB0CLKSEL, 3),
  542. kPLL1_to_USB0_CLK = MUX_A(CM_USB0CLKSEL, 5),
  543. kNONE_to_USB0_CLK = MUX_A(CM_USB0CLKSEL, 7),
  544. kMAIN_CLK_to_FLEXCOMM0 = MUX_A(CM_FXCOMCLKSEL0, 0),
  545. kPLL0_DIV_to_FLEXCOMM0 = MUX_A(CM_FXCOMCLKSEL0, 1),
  546. kFRO12M_to_FLEXCOMM0 = MUX_A(CM_FXCOMCLKSEL0, 2),
  547. kFRO_HF_DIV_to_FLEXCOMM0 = MUX_A(CM_FXCOMCLKSEL0, 3),
  548. kFRO1M_to_FLEXCOMM0 = MUX_A(CM_FXCOMCLKSEL0, 4),
  549. kMCLK_to_FLEXCOMM0 = MUX_A(CM_FXCOMCLKSEL0, 5),
  550. kOSC32K_to_FLEXCOMM0 = MUX_A(CM_FXCOMCLKSEL0, 6),
  551. kNONE_to_FLEXCOMM0 = MUX_A(CM_FXCOMCLKSEL0, 7),
  552. kMAIN_CLK_to_FLEXCOMM1 = MUX_A(CM_FXCOMCLKSEL1, 0),
  553. kPLL0_DIV_to_FLEXCOMM1 = MUX_A(CM_FXCOMCLKSEL1, 1),
  554. kFRO12M_to_FLEXCOMM1 = MUX_A(CM_FXCOMCLKSEL1, 2),
  555. kFRO_HF_DIV_to_FLEXCOMM1 = MUX_A(CM_FXCOMCLKSEL1, 3),
  556. kFRO1M_to_FLEXCOMM1 = MUX_A(CM_FXCOMCLKSEL1, 4),
  557. kMCLK_to_FLEXCOMM1 = MUX_A(CM_FXCOMCLKSEL1, 5),
  558. kOSC32K_to_FLEXCOMM1 = MUX_A(CM_FXCOMCLKSEL1, 6),
  559. kNONE_to_FLEXCOMM1 = MUX_A(CM_FXCOMCLKSEL1, 7),
  560. kMAIN_CLK_to_FLEXCOMM2 = MUX_A(CM_FXCOMCLKSEL2, 0),
  561. kPLL0_DIV_to_FLEXCOMM2 = MUX_A(CM_FXCOMCLKSEL2, 1),
  562. kFRO12M_to_FLEXCOMM2 = MUX_A(CM_FXCOMCLKSEL2, 2),
  563. kFRO_HF_DIV_to_FLEXCOMM2 = MUX_A(CM_FXCOMCLKSEL2, 3),
  564. kFRO1M_to_FLEXCOMM2 = MUX_A(CM_FXCOMCLKSEL2, 4),
  565. kMCLK_to_FLEXCOMM2 = MUX_A(CM_FXCOMCLKSEL2, 5),
  566. kOSC32K_to_FLEXCOMM2 = MUX_A(CM_FXCOMCLKSEL2, 6),
  567. kNONE_to_FLEXCOMM2 = MUX_A(CM_FXCOMCLKSEL2, 7),
  568. kMAIN_CLK_to_FLEXCOMM3 = MUX_A(CM_FXCOMCLKSEL3, 0),
  569. kPLL0_DIV_to_FLEXCOMM3 = MUX_A(CM_FXCOMCLKSEL3, 1),
  570. kFRO12M_to_FLEXCOMM3 = MUX_A(CM_FXCOMCLKSEL3, 2),
  571. kFRO_HF_DIV_to_FLEXCOMM3 = MUX_A(CM_FXCOMCLKSEL3, 3),
  572. kFRO1M_to_FLEXCOMM3 = MUX_A(CM_FXCOMCLKSEL3, 4),
  573. kMCLK_to_FLEXCOMM3 = MUX_A(CM_FXCOMCLKSEL3, 5),
  574. kOSC32K_to_FLEXCOMM3 = MUX_A(CM_FXCOMCLKSEL3, 6),
  575. kNONE_to_FLEXCOMM3 = MUX_A(CM_FXCOMCLKSEL3, 7),
  576. kMAIN_CLK_to_FLEXCOMM4 = MUX_A(CM_FXCOMCLKSEL4, 0),
  577. kPLL0_DIV_to_FLEXCOMM4 = MUX_A(CM_FXCOMCLKSEL4, 1),
  578. kFRO12M_to_FLEXCOMM4 = MUX_A(CM_FXCOMCLKSEL4, 2),
  579. kFRO_HF_DIV_to_FLEXCOMM4 = MUX_A(CM_FXCOMCLKSEL4, 3),
  580. kFRO1M_to_FLEXCOMM4 = MUX_A(CM_FXCOMCLKSEL4, 4),
  581. kMCLK_to_FLEXCOMM4 = MUX_A(CM_FXCOMCLKSEL4, 5),
  582. kOSC32K_to_FLEXCOMM4 = MUX_A(CM_FXCOMCLKSEL4, 6),
  583. kNONE_to_FLEXCOMM4 = MUX_A(CM_FXCOMCLKSEL4, 7),
  584. kMAIN_CLK_to_FLEXCOMM5 = MUX_A(CM_FXCOMCLKSEL5, 0),
  585. kPLL0_DIV_to_FLEXCOMM5 = MUX_A(CM_FXCOMCLKSEL5, 1),
  586. kFRO12M_to_FLEXCOMM5 = MUX_A(CM_FXCOMCLKSEL5, 2),
  587. kFRO_HF_DIV_to_FLEXCOMM5 = MUX_A(CM_FXCOMCLKSEL5, 3),
  588. kFRO1M_to_FLEXCOMM5 = MUX_A(CM_FXCOMCLKSEL5, 4),
  589. kMCLK_to_FLEXCOMM5 = MUX_A(CM_FXCOMCLKSEL5, 5),
  590. kOSC32K_to_FLEXCOMM5 = MUX_A(CM_FXCOMCLKSEL5, 6),
  591. kNONE_to_FLEXCOMM5 = MUX_A(CM_FXCOMCLKSEL5, 7),
  592. kMAIN_CLK_to_FLEXCOMM6 = MUX_A(CM_FXCOMCLKSEL6, 0),
  593. kPLL0_DIV_to_FLEXCOMM6 = MUX_A(CM_FXCOMCLKSEL6, 1),
  594. kFRO12M_to_FLEXCOMM6 = MUX_A(CM_FXCOMCLKSEL6, 2),
  595. kFRO_HF_DIV_to_FLEXCOMM6 = MUX_A(CM_FXCOMCLKSEL6, 3),
  596. kFRO1M_to_FLEXCOMM6 = MUX_A(CM_FXCOMCLKSEL6, 4),
  597. kMCLK_to_FLEXCOMM6 = MUX_A(CM_FXCOMCLKSEL6, 5),
  598. kOSC32K_to_FLEXCOMM6 = MUX_A(CM_FXCOMCLKSEL6, 6),
  599. kNONE_to_FLEXCOMM6 = MUX_A(CM_FXCOMCLKSEL6, 7),
  600. kMAIN_CLK_to_FLEXCOMM7 = MUX_A(CM_FXCOMCLKSEL7, 0),
  601. kPLL0_DIV_to_FLEXCOMM7 = MUX_A(CM_FXCOMCLKSEL7, 1),
  602. kFRO12M_to_FLEXCOMM7 = MUX_A(CM_FXCOMCLKSEL7, 2),
  603. kFRO_HF_DIV_to_FLEXCOMM7 = MUX_A(CM_FXCOMCLKSEL7, 3),
  604. kFRO1M_to_FLEXCOMM7 = MUX_A(CM_FXCOMCLKSEL7, 4),
  605. kMCLK_to_FLEXCOMM7 = MUX_A(CM_FXCOMCLKSEL7, 5),
  606. kOSC32K_to_FLEXCOMM7 = MUX_A(CM_FXCOMCLKSEL7, 6),
  607. kNONE_to_FLEXCOMM7 = MUX_A(CM_FXCOMCLKSEL7, 7),
  608. kMAIN_CLK_to_HSLSPI = MUX_A(CM_HSLSPICLKSEL, 0),
  609. kPLL0_DIV_to_HSLSPI = MUX_A(CM_HSLSPICLKSEL, 1),
  610. kFRO12M_to_HSLSPI = MUX_A(CM_HSLSPICLKSEL, 2),
  611. kFRO_HF_DIV_to_HSLSPI = MUX_A(CM_HSLSPICLKSEL, 3),
  612. kFRO1M_to_HSLSPI = MUX_A(CM_HSLSPICLKSEL, 4),
  613. kOSC32K_to_HSLSPI = MUX_A(CM_HSLSPICLKSEL, 6),
  614. kNONE_to_HSLSPI = MUX_A(CM_HSLSPICLKSEL, 7),
  615. kFRO_HF_to_MCLK = MUX_A(CM_MCLKCLKSEL, 0),
  616. kPLL0_to_MCLK = MUX_A(CM_MCLKCLKSEL, 1),
  617. kFRO1M_to_MCLK = MUX_A(CM_MCLKCLKSEL, 2), /* Need confirm */
  618. kMAIN_CLK_to_MCLK = MUX_A(CM_MCLKCLKSEL, 3), /* Need confirm */
  619. kNONE_to_MCLK = MUX_A(CM_MCLKCLKSEL, 7),
  620. kMAIN_CLK_to_SCT_CLK = MUX_A(CM_SCTCLKSEL, 0),
  621. kPLL0_to_SCT_CLK = MUX_A(CM_SCTCLKSEL, 1),
  622. kEXT_CLK_to_SCT_CLK = MUX_A(CM_SCTCLKSEL, 2),
  623. kFRO_HF_to_SCT_CLK = MUX_A(CM_SCTCLKSEL, 3),
  624. kMCLK_to_SCT_CLK = MUX_A(CM_SCTCLKSEL, 5),
  625. kNONE_to_SCT_CLK = MUX_A(CM_SCTCLKSEL, 7),
  626. kMAIN_CLK_to_SDIO_CLK = MUX_A(CM_SDIOCLKSEL, 0),
  627. kPLL0_to_SDIO_CLK = MUX_A(CM_SDIOCLKSEL, 1),
  628. kFRO_HF_to_SDIO_CLK = MUX_A(CM_SDIOCLKSEL, 3),
  629. kPLL1_to_SDIO_CLK = MUX_A(CM_SDIOCLKSEL, 5),
  630. kNONE_to_SDIO_CLK = MUX_A(CM_SDIOCLKSEL, 7),
  631. kFRO32K_to_OSC32K = MUX_A(CM_RTCOSC32KCLKSEL, 0),
  632. kXTAL32K_to_OSC32K = MUX_A(CM_RTCOSC32KCLKSEL, 1),
  633. kTRACE_DIV_to_TRACE = MUX_A(CM_TRACECLKSEL, 0),
  634. kFRO1M_to_TRACE = MUX_A(CM_TRACECLKSEL, 1),
  635. kOSC32K_to_TRACE = MUX_A(CM_TRACECLKSEL, 2),
  636. kNONE_to_TRACE = MUX_A(CM_TRACECLKSEL, 7),
  637. kSYSTICK_DIV0_to_SYSTICK0 = MUX_A(CM_SYSTICKCLKSEL0, 0),
  638. kFRO1M_to_SYSTICK0 = MUX_A(CM_SYSTICKCLKSEL0, 1),
  639. kOSC32K_to_SYSTICK0 = MUX_A(CM_SYSTICKCLKSEL0, 2),
  640. kNONE_to_SYSTICK0 = MUX_A(CM_SYSTICKCLKSEL0, 7),
  641. kSYSTICK_DIV1_to_SYSTICK1 = MUX_A(CM_SYSTICKCLKSEL1, 0),
  642. kFRO1M_to_SYSTICK1 = MUX_A(CM_SYSTICKCLKSEL1, 1),
  643. kOSC32K_to_SYSTICK1 = MUX_A(CM_SYSTICKCLKSEL1, 2),
  644. kNONE_to_SYSTICK1 = MUX_A(CM_SYSTICKCLKSEL1, 7),
  645. kFRO12M_to_PLL1 = MUX_A(CM_PLL1CLKSEL, 0),
  646. kEXT_CLK_to_PLL1 = MUX_A(CM_PLL1CLKSEL, 1),
  647. kFRO1M_to_PLL1 = MUX_A(CM_PLL1CLKSEL, 2),
  648. kOSC32K_to_PLL1 = MUX_A(CM_PLL1CLKSEL, 3),
  649. kNONE_to_PLL1 = MUX_A(CM_PLL1CLKSEL, 7),
  650. kMAIN_CLK_to_CTIMER0 = MUX_A(CM_CTIMERCLKSEL0, 0),
  651. kPLL0_to_CTIMER0 = MUX_A(CM_CTIMERCLKSEL0, 1),
  652. kFRO_HF_to_CTIMER0 = MUX_A(CM_CTIMERCLKSEL0, 3),
  653. kFRO1M_to_CTIMER0 = MUX_A(CM_CTIMERCLKSEL0, 4),
  654. kMCLK_to_CTIMER0 = MUX_A(CM_CTIMERCLKSEL0, 5),
  655. kOSC32K_to_CTIMER0 = MUX_A(CM_CTIMERCLKSEL0, 6),
  656. kNONE_to_CTIMER0 = MUX_A(CM_CTIMERCLKSEL0, 7),
  657. kMAIN_CLK_to_CTIMER1 = MUX_A(CM_CTIMERCLKSEL1, 0),
  658. kPLL0_to_CTIMER1 = MUX_A(CM_CTIMERCLKSEL1, 1),
  659. kFRO_HF_to_CTIMER1 = MUX_A(CM_CTIMERCLKSEL1, 3),
  660. kFRO1M_to_CTIMER1 = MUX_A(CM_CTIMERCLKSEL1, 4),
  661. kMCLK_to_CTIMER1 = MUX_A(CM_CTIMERCLKSEL1, 5),
  662. kOSC32K_to_CTIMER1 = MUX_A(CM_CTIMERCLKSEL1, 6),
  663. kNONE_to_CTIMER1 = MUX_A(CM_CTIMERCLKSEL1, 7),
  664. kMAIN_CLK_to_CTIMER2 = MUX_A(CM_CTIMERCLKSEL2, 0),
  665. kPLL0_to_CTIMER2 = MUX_A(CM_CTIMERCLKSEL2, 1),
  666. kFRO_HF_to_CTIMER2 = MUX_A(CM_CTIMERCLKSEL2, 3),
  667. kFRO1M_to_CTIMER2 = MUX_A(CM_CTIMERCLKSEL2, 4),
  668. kMCLK_to_CTIMER2 = MUX_A(CM_CTIMERCLKSEL2, 5),
  669. kOSC32K_to_CTIMER2 = MUX_A(CM_CTIMERCLKSEL2, 6),
  670. kNONE_to_CTIMER2 = MUX_A(CM_CTIMERCLKSEL2, 7),
  671. kMAIN_CLK_to_CTIMER3 = MUX_A(CM_CTIMERCLKSEL3, 0),
  672. kPLL0_to_CTIMER3 = MUX_A(CM_CTIMERCLKSEL3, 1),
  673. kFRO_HF_to_CTIMER3 = MUX_A(CM_CTIMERCLKSEL3, 3),
  674. kFRO1M_to_CTIMER3 = MUX_A(CM_CTIMERCLKSEL3, 4),
  675. kMCLK_to_CTIMER3 = MUX_A(CM_CTIMERCLKSEL3, 5),
  676. kOSC32K_to_CTIMER3 = MUX_A(CM_CTIMERCLKSEL3, 6),
  677. kNONE_to_CTIMER3 = MUX_A(CM_CTIMERCLKSEL3, 7),
  678. kMAIN_CLK_to_CTIMER4 = MUX_A(CM_CTIMERCLKSEL4, 0),
  679. kPLL0_to_CTIMER4 = MUX_A(CM_CTIMERCLKSEL4, 1),
  680. kFRO_HF_to_CTIMER4 = MUX_A(CM_CTIMERCLKSEL4, 3),
  681. kFRO1M_to_CTIMER4 = MUX_A(CM_CTIMERCLKSEL4, 4),
  682. kMCLK_to_CTIMER4 = MUX_A(CM_CTIMERCLKSEL4, 5),
  683. kOSC32K_to_CTIMER4 = MUX_A(CM_CTIMERCLKSEL4, 6),
  684. kNONE_to_CTIMER4 = MUX_A(CM_CTIMERCLKSEL4, 7),
  685. kNONE_to_NONE = (int)0x80000000U,
  686. } clock_attach_id_t;
  687. /* Clock dividers */
  688. typedef enum _clock_div_name
  689. {
  690. kCLOCK_DivSystickClk0 = 0,
  691. kCLOCK_DivSystickClk1 = 1,
  692. kCLOCK_DivArmTrClkDiv = 2,
  693. kCLOCK_DivFlexFrg0 = 8,
  694. kCLOCK_DivFlexFrg1 = 9,
  695. kCLOCK_DivFlexFrg2 = 10,
  696. kCLOCK_DivFlexFrg3 = 11,
  697. kCLOCK_DivFlexFrg4 = 12,
  698. kCLOCK_DivFlexFrg5 = 13,
  699. kCLOCK_DivFlexFrg6 = 14,
  700. kCLOCK_DivFlexFrg7 = 15,
  701. kCLOCK_DivAhbClk = 32,
  702. kCLOCK_DivClkOut = 33,
  703. kCLOCK_DivFrohfClk = 34,
  704. kCLOCK_DivWdtClk = 35,
  705. kCLOCK_DivAdcAsyncClk = 37,
  706. kCLOCK_DivUsb0Clk = 38,
  707. kCLOCK_DivMClk = 43,
  708. kCLOCK_DivSctClk = 45,
  709. kCLOCK_DivSdioClk = 47,
  710. kCLOCK_DivPll0Clk = 49
  711. } clock_div_name_t;
  712. /*******************************************************************************
  713. * API
  714. ******************************************************************************/
  715. #if defined(__cplusplus)
  716. extern "C" {
  717. #endif /* __cplusplus */
  718. /**
  719. * @brief Enable the clock for specific IP.
  720. * @param name : Clock to be enabled.
  721. * @return Nothing
  722. */
  723. static inline void CLOCK_EnableClock(clock_ip_name_t clk)
  724. {
  725. uint32_t index = CLK_GATE_ABSTRACT_REG_OFFSET(clk);
  726. SYSCON->AHBCLKCTRLSET[index] = (1U << CLK_GATE_ABSTRACT_BITS_SHIFT(clk));
  727. }
  728. /**
  729. * @brief Disable the clock for specific IP.
  730. * @param name : Clock to be Disabled.
  731. * @return Nothing
  732. */
  733. static inline void CLOCK_DisableClock(clock_ip_name_t clk)
  734. {
  735. uint32_t index = CLK_GATE_ABSTRACT_REG_OFFSET(clk);
  736. SYSCON->AHBCLKCTRLCLR[index] = (1U << CLK_GATE_ABSTRACT_BITS_SHIFT(clk));
  737. }
  738. /**
  739. * @brief Initialize the Core clock to given frequency (12, 48 or 96 MHz).
  740. * Turns on FRO and uses default CCO, if freq is 12000000, then high speed output is off, else high speed output is
  741. * enabled.
  742. * @param iFreq : Desired frequency (must be one of #CLK_FRO_12MHZ or #CLK_FRO_48MHZ or #CLK_FRO_96MHZ)
  743. * @return returns success or fail status.
  744. */
  745. status_t CLOCK_SetupFROClocking(uint32_t iFreq);
  746. /**
  747. * @brief Set the flash wait states for the input freuqency.
  748. * @param iFreq : Input frequency
  749. * @return Nothing
  750. */
  751. void CLOCK_SetFLASHAccessCyclesForFreq(uint32_t iFreq);
  752. /**
  753. * @brief Initialize the external osc clock to given frequency.
  754. * @param iFreq : Desired frequency (must be equal to exact rate in Hz)
  755. * @return returns success or fail status.
  756. */
  757. status_t CLOCK_SetupExtClocking(uint32_t iFreq);
  758. /**
  759. * @brief Initialize the I2S MCLK clock to given frequency.
  760. * @param iFreq : Desired frequency (must be equal to exact rate in Hz)
  761. * @return returns success or fail status.
  762. */
  763. status_t CLOCK_SetupI2SMClkClocking(uint32_t iFreq);
  764. /**
  765. * @brief Configure the clock selection muxes.
  766. * @param connection : Clock to be configured.
  767. * @return Nothing
  768. */
  769. void CLOCK_AttachClk(clock_attach_id_t connection);
  770. /**
  771. * @brief Get the actual clock attach id.
  772. * This fuction uses the offset in input attach id, then it reads the actual source value in
  773. * the register and combine the offset to obtain an actual attach id.
  774. * @param attachId : Clock attach id to get.
  775. * @return Clock source value.
  776. */
  777. clock_attach_id_t CLOCK_GetClockAttachId(clock_attach_id_t attachId);
  778. /**
  779. * @brief Setup peripheral clock dividers.
  780. * @param div_name : Clock divider name
  781. * @param divided_by_value: Value to be divided
  782. * @param reset : Whether to reset the divider counter.
  783. * @return Nothing
  784. */
  785. void CLOCK_SetClkDiv(clock_div_name_t div_name, uint32_t divided_by_value, bool reset);
  786. /**
  787. * @brief Setup rtc 1khz clock divider.
  788. * @param divided_by_value: Value to be divided
  789. * @return Nothing
  790. */
  791. void CLOCK_SetRtc1khzClkDiv(uint32_t divided_by_value);
  792. /**
  793. * @brief Setup rtc 1hz clock divider.
  794. * @param divided_by_value: Value to be divided
  795. * @return Nothing
  796. */
  797. void CLOCK_SetRtc1hzClkDiv(uint32_t divided_by_value);
  798. /**
  799. * @brief Set the flexcomm output frequency.
  800. * @param id : flexcomm instance id
  801. * freq : output frequency
  802. * @return 0 : the frequency range is out of range.
  803. * 1 : switch successfully.
  804. */
  805. uint32_t CLOCK_SetFlexCommClock(uint32_t id, uint32_t freq);
  806. /*! @brief Return Frequency of flexcomm input clock
  807. * @param id : flexcomm instance id
  808. * @return Frequency value
  809. */
  810. uint32_t CLOCK_GetFlexCommInputClock(uint32_t id);
  811. /*! @brief Return Frequency of selected clock
  812. * @return Frequency of selected clock
  813. */
  814. uint32_t CLOCK_GetFreq(clock_name_t clockName);
  815. /*! @brief Return Frequency of FRO 12MHz
  816. * @return Frequency of FRO 12MHz
  817. */
  818. uint32_t CLOCK_GetFro12MFreq(void);
  819. /*! @brief Return Frequency of FRO 1MHz
  820. * @return Frequency of FRO 1MHz
  821. */
  822. uint32_t CLOCK_GetFro1MFreq(void);
  823. /*! @brief Return Frequency of ClockOut
  824. * @return Frequency of ClockOut
  825. */
  826. uint32_t CLOCK_GetClockOutClkFreq(void);
  827. /*! @brief Return Frequency of Adc Clock
  828. * @return Frequency of Adc.
  829. */
  830. uint32_t CLOCK_GetAdcClkFreq(void);
  831. /*! @brief Return Frequency of Usb0 Clock
  832. * @return Frequency of Usb0 Clock.
  833. */
  834. uint32_t CLOCK_GetUsb0ClkFreq(void);
  835. /*! @brief Return Frequency of Usb1 Clock
  836. * @return Frequency of Usb1 Clock.
  837. */
  838. uint32_t CLOCK_GetUsb1ClkFreq(void);
  839. /*! @brief Return Frequency of MClk Clock
  840. * @return Frequency of MClk Clock.
  841. */
  842. uint32_t CLOCK_GetMclkClkFreq(void);
  843. /*! @brief Return Frequency of SCTimer Clock
  844. * @return Frequency of SCTimer Clock.
  845. */
  846. uint32_t CLOCK_GetSctClkFreq(void);
  847. /*! @brief Return Frequency of SDIO Clock
  848. * @return Frequency of SDIO Clock.
  849. */
  850. uint32_t CLOCK_GetSdioClkFreq(void);
  851. /*! @brief Return Frequency of External Clock
  852. * @return Frequency of External Clock. If no external clock is used returns 0.
  853. */
  854. uint32_t CLOCK_GetExtClkFreq(void);
  855. /*! @brief Return Frequency of Watchdog
  856. * @return Frequency of Watchdog
  857. */
  858. uint32_t CLOCK_GetWdtClkFreq(void);
  859. /*! @brief Return Frequency of High-Freq output of FRO
  860. * @return Frequency of High-Freq output of FRO
  861. */
  862. uint32_t CLOCK_GetFroHfFreq(void);
  863. /*! @brief Return Frequency of PLL
  864. * @return Frequency of PLL
  865. */
  866. uint32_t CLOCK_GetPll0OutFreq(void);
  867. /*! @brief Return Frequency of USB PLL
  868. * @return Frequency of PLL
  869. */
  870. uint32_t CLOCK_GetPll1OutFreq(void);
  871. /*! @brief Return Frequency of 32kHz osc
  872. * @return Frequency of 32kHz osc
  873. */
  874. uint32_t CLOCK_GetOsc32KFreq(void);
  875. /*! @brief Return Frequency of Core System
  876. * @return Frequency of Core System
  877. */
  878. uint32_t CLOCK_GetCoreSysClkFreq(void);
  879. /*! @brief Return Frequency of I2S MCLK Clock
  880. * @return Frequency of I2S MCLK Clock
  881. */
  882. uint32_t CLOCK_GetI2SMClkFreq(void);
  883. /*! @brief Return Frequency of CTimer functional Clock
  884. * @return Frequency of CTimer functional Clock
  885. */
  886. uint32_t CLOCK_GetCTimerClkFreq(uint32_t id);
  887. /*! @brief Return Frequency of SystickClock
  888. * @return Frequency of Systick Clock
  889. */
  890. uint32_t CLOCK_GetSystickClkFreq(uint32_t id);
  891. /*! @brief Return PLL0 input clock rate
  892. * @return PLL0 input clock rate
  893. */
  894. uint32_t CLOCK_GetPLL0InClockRate(void);
  895. /*! @brief Return PLL1 input clock rate
  896. * @return PLL1 input clock rate
  897. */
  898. uint32_t CLOCK_GetPLL1InClockRate(void);
  899. /*! @brief Return PLL0 output clock rate
  900. * @param recompute : Forces a PLL rate recomputation if true
  901. * @return PLL0 output clock rate
  902. * @note The PLL rate is cached in the driver in a variable as
  903. * the rate computation function can take some time to perform. It
  904. * is recommended to use 'false' with the 'recompute' parameter.
  905. */
  906. uint32_t CLOCK_GetPLL0OutClockRate(bool recompute);
  907. /*! @brief Return PLL1 output clock rate
  908. * @param recompute : Forces a PLL rate recomputation if true
  909. * @return PLL1 output clock rate
  910. * @note The PLL rate is cached in the driver in a variable as
  911. * the rate computation function can take some time to perform. It
  912. * is recommended to use 'false' with the 'recompute' parameter.
  913. */
  914. uint32_t CLOCK_GetPLL1OutClockRate(bool recompute);
  915. /*! @brief Enables and disables PLL0 bypass mode
  916. * @brief bypass : true to bypass PLL0 (PLL0 output = PLL0 input, false to disable bypass
  917. * @return PLL0 output clock rate
  918. */
  919. __STATIC_INLINE void CLOCK_SetBypassPLL0(bool bypass)
  920. {
  921. if (bypass)
  922. {
  923. SYSCON->PLL0CTRL |= (1UL << SYSCON_PLL0CTRL_BYPASSPLL_SHIFT);
  924. }
  925. else
  926. {
  927. SYSCON->PLL0CTRL &= ~(1UL << SYSCON_PLL0CTRL_BYPASSPLL_SHIFT);
  928. }
  929. }
  930. /*! @brief Enables and disables PLL1 bypass mode
  931. * @brief bypass : true to bypass PLL1 (PLL1 output = PLL1 input, false to disable bypass
  932. * @return PLL1 output clock rate
  933. */
  934. __STATIC_INLINE void CLOCK_SetBypassPLL1(bool bypass)
  935. {
  936. if (bypass)
  937. {
  938. SYSCON->PLL1CTRL |= (1UL << SYSCON_PLL1CTRL_BYPASSPLL_SHIFT);
  939. }
  940. else
  941. {
  942. SYSCON->PLL1CTRL &= ~(1UL << SYSCON_PLL1CTRL_BYPASSPLL_SHIFT);
  943. }
  944. }
  945. /*! @brief Check if PLL is locked or not
  946. * @return true if the PLL is locked, false if not locked
  947. */
  948. __STATIC_INLINE bool CLOCK_IsPLL0Locked(void)
  949. {
  950. return (bool)((SYSCON->PLL0STAT & SYSCON_PLL0STAT_LOCK_MASK) != 0);
  951. }
  952. /*! @brief Check if PLL1 is locked or not
  953. * @return true if the PLL1 is locked, false if not locked
  954. */
  955. __STATIC_INLINE bool CLOCK_IsPLL1Locked(void)
  956. {
  957. return (bool)((SYSCON->PLL1STAT & SYSCON_PLL1STAT_LOCK_MASK) != 0);
  958. }
  959. /*! @brief Store the current PLL rate
  960. * @param rate: Current rate of the PLL
  961. * @return Nothing
  962. **/
  963. void CLOCK_SetStoredPLLClockRate(uint32_t rate);
  964. /*! @brief PLL configuration structure flags for 'flags' field
  965. * These flags control how the PLL configuration function sets up the PLL setup structure.<br>
  966. *
  967. * When the PLL_CONFIGFLAG_USEINRATE flag is selected, the 'InputRate' field in the
  968. * configuration structure must be assigned with the expected PLL frequency. If the
  969. * PLL_CONFIGFLAG_USEINRATE is not used, 'InputRate' is ignored in the configuration
  970. * function and the driver will determine the PLL rate from the currently selected
  971. * PLL source. This flag might be used to configure the PLL input clock more accurately
  972. * when using the WDT oscillator or a more dyanmic CLKIN source.<br>
  973. *
  974. * When the PLL_CONFIGFLAG_FORCENOFRACT flag is selected, the PLL hardware for the
  975. * automatic bandwidth selection, Spread Spectrum (SS) support, and fractional M-divider
  976. * are not used.<br>
  977. */
  978. #define PLL_CONFIGFLAG_USEINRATE (1 << 0) /*!< Flag to use InputRate in PLL configuration structure for setup */
  979. #define PLL_CONFIGFLAG_FORCENOFRACT (1 << 2)
  980. /*!< Force non-fractional output mode, PLL output will not use the fractional, automatic bandwidth, or SS hardware */
  981. /*! @brief PLL Spread Spectrum (SS) Programmable modulation frequency
  982. * See (MF) field in the PLL0SSCG1 register in the UM.
  983. */
  984. typedef enum _ss_progmodfm
  985. {
  986. kSS_MF_512 = (0 << 20), /*!< Nss = 512 (fm ? 3.9 - 7.8 kHz) */
  987. kSS_MF_384 = (1 << 20), /*!< Nss ?= 384 (fm ? 5.2 - 10.4 kHz) */
  988. kSS_MF_256 = (2 << 20), /*!< Nss = 256 (fm ? 7.8 - 15.6 kHz) */
  989. kSS_MF_128 = (3 << 20), /*!< Nss = 128 (fm ? 15.6 - 31.3 kHz) */
  990. kSS_MF_64 = (4 << 20), /*!< Nss = 64 (fm ? 32.3 - 64.5 kHz) */
  991. kSS_MF_32 = (5 << 20), /*!< Nss = 32 (fm ? 62.5- 125 kHz) */
  992. kSS_MF_24 = (6 << 20), /*!< Nss ?= 24 (fm ? 83.3- 166.6 kHz) */
  993. kSS_MF_16 = (7 << 20) /*!< Nss = 16 (fm ? 125- 250 kHz) */
  994. } ss_progmodfm_t;
  995. /*! @brief PLL Spread Spectrum (SS) Programmable frequency modulation depth
  996. * See (MR) field in the PLL0SSCG1 register in the UM.
  997. */
  998. typedef enum _ss_progmoddp
  999. {
  1000. kSS_MR_K0 = (0 << 23), /*!< k = 0 (no spread spectrum) */
  1001. kSS_MR_K1 = (1 << 23), /*!< k = 1 */
  1002. kSS_MR_K1_5 = (2 << 23), /*!< k = 1.5 */
  1003. kSS_MR_K2 = (3 << 23), /*!< k = 2 */
  1004. kSS_MR_K3 = (4 << 23), /*!< k = 3 */
  1005. kSS_MR_K4 = (5 << 23), /*!< k = 4 */
  1006. kSS_MR_K6 = (6 << 23), /*!< k = 6 */
  1007. kSS_MR_K8 = (7 << 23) /*!< k = 8 */
  1008. } ss_progmoddp_t;
  1009. /*! @brief PLL Spread Spectrum (SS) Modulation waveform control
  1010. * See (MC) field in the PLL0SSCG1 register in the UM.<br>
  1011. * Compensation for low pass filtering of the PLL to get a triangular
  1012. * modulation at the output of the PLL, giving a flat frequency spectrum.
  1013. */
  1014. typedef enum _ss_modwvctrl
  1015. {
  1016. kSS_MC_NOC = (0 << 26), /*!< no compensation */
  1017. kSS_MC_RECC = (2 << 26), /*!< recommended setting */
  1018. kSS_MC_MAXC = (3 << 26), /*!< max. compensation */
  1019. } ss_modwvctrl_t;
  1020. /*! @brief PLL configuration structure
  1021. *
  1022. * This structure can be used to configure the settings for a PLL
  1023. * setup structure. Fill in the desired configuration for the PLL
  1024. * and call the PLL setup function to fill in a PLL setup structure.
  1025. */
  1026. typedef struct _pll_config
  1027. {
  1028. uint32_t desiredRate; /*!< Desired PLL rate in Hz */
  1029. uint32_t inputRate; /*!< PLL input clock in Hz, only used if PLL_CONFIGFLAG_USEINRATE flag is set */
  1030. uint32_t flags; /*!< PLL configuration flags, Or'ed value of PLL_CONFIGFLAG_* definitions */
  1031. ss_progmodfm_t ss_mf; /*!< SS Programmable modulation frequency, only applicable when not using
  1032. PLL_CONFIGFLAG_FORCENOFRACT flag */
  1033. ss_progmoddp_t ss_mr; /*!< SS Programmable frequency modulation depth, only applicable when not using
  1034. PLL_CONFIGFLAG_FORCENOFRACT flag */
  1035. ss_modwvctrl_t
  1036. ss_mc; /*!< SS Modulation waveform control, only applicable when not using PLL_CONFIGFLAG_FORCENOFRACT flag */
  1037. bool mfDither; /*!< false for fixed modulation frequency or true for dithering, only applicable when not using
  1038. PLL_CONFIGFLAG_FORCENOFRACT flag */
  1039. } pll_config_t;
  1040. /*! @brief PLL setup structure flags for 'flags' field
  1041. * These flags control how the PLL setup function sets up the PLL
  1042. */
  1043. #define PLL_SETUPFLAG_POWERUP (1 << 0) /*!< Setup will power on the PLL after setup */
  1044. #define PLL_SETUPFLAG_WAITLOCK (1 << 1) /*!< Setup will wait for PLL lock, implies the PLL will be pwoered on */
  1045. #define PLL_SETUPFLAG_ADGVOLT (1 << 2) /*!< Optimize system voltage for the new PLL rate */
  1046. #define PLL_SETUPFLAG_USEFEEDBACKDIV2 (1 << 3) /*!< Use feedback divider by 2 in divider path */
  1047. /*! @brief PLL0 setup structure
  1048. * This structure can be used to pre-build a PLL setup configuration
  1049. * at run-time and quickly set the PLL to the configuration. It can be
  1050. * populated with the PLL setup function. If powering up or waiting
  1051. * for PLL lock, the PLL input clock source should be configured prior
  1052. * to PLL setup.
  1053. */
  1054. typedef struct _pll_setup
  1055. {
  1056. uint32_t pllctrl; /*!< PLL control register PLL0CTRL */
  1057. uint32_t pllndec; /*!< PLL NDEC register PLL0NDEC */
  1058. uint32_t pllpdec; /*!< PLL PDEC register PLL0PDEC */
  1059. uint32_t pllmdec; /*!< PLL MDEC registers PLL0PDEC */
  1060. uint32_t pllsscg[2]; /*!< PLL SSCTL registers PLL0SSCG*/
  1061. uint32_t pllRate; /*!< Acutal PLL rate */
  1062. uint32_t flags; /*!< PLL setup flags, Or'ed value of PLL_SETUPFLAG_* definitions */
  1063. } pll_setup_t;
  1064. /*! @brief PLL status definitions
  1065. */
  1066. typedef enum _pll_error
  1067. {
  1068. kStatus_PLL_Success = MAKE_STATUS(kStatusGroup_Generic, 0), /*!< PLL operation was successful */
  1069. kStatus_PLL_OutputTooLow = MAKE_STATUS(kStatusGroup_Generic, 1), /*!< PLL output rate request was too low */
  1070. kStatus_PLL_OutputTooHigh = MAKE_STATUS(kStatusGroup_Generic, 2), /*!< PLL output rate request was too high */
  1071. kStatus_PLL_InputTooLow = MAKE_STATUS(kStatusGroup_Generic, 3), /*!< PLL input rate is too low */
  1072. kStatus_PLL_InputTooHigh = MAKE_STATUS(kStatusGroup_Generic, 4), /*!< PLL input rate is too high */
  1073. kStatus_PLL_OutsideIntLimit = MAKE_STATUS(kStatusGroup_Generic, 5), /*!< Requested output rate isn't possible */
  1074. kStatus_PLL_CCOTooLow = MAKE_STATUS(kStatusGroup_Generic, 6), /*!< Requested CCO rate isn't possible */
  1075. kStatus_PLL_CCOTooHigh = MAKE_STATUS(kStatusGroup_Generic, 7) /*!< Requested CCO rate isn't possible */
  1076. } pll_error_t;
  1077. /*! @brief USB FS clock source definition. */
  1078. typedef enum _clock_usbfs_src
  1079. {
  1080. kCLOCK_UsbfsSrcFro = (uint32_t)kCLOCK_FroHf, /*!< Use FRO 96 MHz. */
  1081. kCLOCK_UsbfsSrcPll0 = (uint32_t)kCLOCK_Pll0Out, /*!< Use PLL0 output. */
  1082. kCLOCK_UsbfsSrcMainClock = (uint32_t)kCLOCK_CoreSysClk, /*!< Use Main clock. */
  1083. kCLOCK_UsbfsSrcPll1 = (uint32_t)kCLOCK_Pll1Out, /*!< Use PLL1 clock. */
  1084. kCLOCK_UsbfsSrcNone =
  1085. SYSCON_USB0CLKSEL_SEL(7) /*!<this may be selected in order to reduce power when no output is needed. */
  1086. } clock_usbfs_src_t;
  1087. /*! @brief USBhs clock source definition. */
  1088. typedef enum _clock_usbhs_src
  1089. {
  1090. kCLOCK_UsbSrcUnused = 0xFFFFFFFFU, /*!< Used when the function does not
  1091. care the clock source. */
  1092. } clock_usbhs_src_t;
  1093. /*! @brief Source of the USB HS PHY. */
  1094. typedef enum _clock_usb_phy_src
  1095. {
  1096. kCLOCK_UsbPhySrcExt = 0U, /*!< Use external crystal. */
  1097. } clock_usb_phy_src_t;
  1098. /*! @brief Return System PLL output clock rate from setup structure
  1099. * @param pSetup : Pointer to a PLL setup structure
  1100. * @return System PLL output clock rate the setup structure will generate
  1101. */
  1102. uint32_t CLOCK_GetPLL0OutFromSetup(pll_setup_t *pSetup);
  1103. /*! @brief Set PLL output based on the passed PLL setup data
  1104. * @param pControl : Pointer to populated PLL control structure to generate setup with
  1105. * @param pSetup : Pointer to PLL setup structure to be filled
  1106. * @return PLL_ERROR_SUCCESS on success, or PLL setup error code
  1107. * @note Actual frequency for setup may vary from the desired frequency based on the
  1108. * accuracy of input clocks, rounding, non-fractional PLL mode, etc.
  1109. */
  1110. pll_error_t CLOCK_SetupPLLData(pll_config_t *pControl, pll_setup_t *pSetup);
  1111. /*! @brief Set PLL output from PLL setup structure (precise frequency)
  1112. * @param pSetup : Pointer to populated PLL setup structure
  1113. * @param flagcfg : Flag configuration for PLL config structure
  1114. * @return PLL_ERROR_SUCCESS on success, or PLL setup error code
  1115. * @note This function will power off the PLL, setup the PLL with the
  1116. * new setup data, and then optionally powerup the PLL, wait for PLL lock,
  1117. * and adjust system voltages to the new PLL rate. The function will not
  1118. * alter any source clocks (ie, main systen clock) that may use the PLL,
  1119. * so these should be setup prior to and after exiting the function.
  1120. */
  1121. pll_error_t CLOCK_SetupPLL0Prec(pll_setup_t *pSetup, uint32_t flagcfg);
  1122. /**
  1123. * @brief Set PLL output from PLL setup structure (precise frequency)
  1124. * @param pSetup : Pointer to populated PLL setup structure
  1125. * @return kStatus_PLL_Success on success, or PLL setup error code
  1126. * @note This function will power off the PLL, setup the PLL with the
  1127. * new setup data, and then optionally powerup the PLL, wait for PLL lock,
  1128. * and adjust system voltages to the new PLL rate. The function will not
  1129. * alter any source clocks (ie, main systen clock) that may use the PLL,
  1130. * so these should be setup prior to and after exiting the function.
  1131. */
  1132. pll_error_t CLOCK_SetPLL0Freq(const pll_setup_t *pSetup);
  1133. /**
  1134. * @brief Set PLL output from PLL setup structure (precise frequency)
  1135. * @param pSetup : Pointer to populated PLL setup structure
  1136. * @return kStatus_PLL_Success on success, or PLL setup error code
  1137. * @note This function will power off the PLL, setup the PLL with the
  1138. * new setup data, and then optionally powerup the PLL, wait for PLL lock,
  1139. * and adjust system voltages to the new PLL rate. The function will not
  1140. * alter any source clocks (ie, main systen clock) that may use the PLL,
  1141. * so these should be setup prior to and after exiting the function.
  1142. */
  1143. pll_error_t CLOCK_SetPLL1Freq(const pll_setup_t *pSetup);
  1144. /*! @brief Set PLL output based on the multiplier and input frequency
  1145. * @param multiply_by : multiplier
  1146. * @param input_freq : Clock input frequency of the PLL
  1147. * @return Nothing
  1148. * @note Unlike the Chip_Clock_SetupSystemPLLPrec() function, this
  1149. * function does not disable or enable PLL power, wait for PLL lock,
  1150. * or adjust system voltages. These must be done in the application.
  1151. * The function will not alter any source clocks (ie, main systen clock)
  1152. * that may use the PLL, so these should be setup prior to and after
  1153. * exiting the function.
  1154. */
  1155. void CLOCK_SetupPLL0Mult(uint32_t multiply_by, uint32_t input_freq);
  1156. /*! @brief Disable USB clock.
  1157. *
  1158. * Disable USB clock.
  1159. */
  1160. static inline void CLOCK_DisableUsbDevicefs0Clock(clock_ip_name_t clk)
  1161. {
  1162. CLOCK_DisableClock(clk);
  1163. }
  1164. /*! @brief Enable USB Device FS clock.
  1165. * @param src : clock source
  1166. * @param freq: clock frequency
  1167. * Enable USB Device Full Speed clock.
  1168. */
  1169. bool CLOCK_EnableUsbfs0DeviceClock(clock_usbfs_src_t src, uint32_t freq);
  1170. /*! @brief Enable USB HOST FS clock.
  1171. * @param src : clock source
  1172. * @param freq: clock frequency
  1173. * Enable USB HOST Full Speed clock.
  1174. */
  1175. bool CLOCK_EnableUsbfs0HostClock(clock_usbfs_src_t src, uint32_t freq);
  1176. /*! @brief Enable USB phy clock.
  1177. * Enable USB phy clock.
  1178. */
  1179. bool CLOCK_EnableUsbhs0PhyPllClock(clock_usb_phy_src_t src, uint32_t freq);
  1180. /*! @brief Enable USB Device HS clock.
  1181. * Enable USB Device High Speed clock.
  1182. */
  1183. bool CLOCK_EnableUsbhs0DeviceClock(clock_usbhs_src_t src, uint32_t freq);
  1184. /*! @brief Enable USB HOST HS clock.
  1185. * Enable USB HOST High Speed clock.
  1186. */
  1187. bool CLOCK_EnableUsbhs0HostClock(clock_usbhs_src_t src, uint32_t freq);
  1188. #if defined(__cplusplus)
  1189. }
  1190. #endif /* __cplusplus */
  1191. /*! @} */
  1192. #endif /* _FSL_CLOCK_H_ */