My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

lpc17xx_clkpwr.h 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. /**********************************************************************
  2. * $Id$ lpc17xx_clkpwr.h 2010-05-21
  3. *//**
  4. * @file lpc17xx_clkpwr.h
  5. * @brief Contains all macro definitions and function prototypes
  6. * support for Clock and Power Control firmware library on LPC17xx
  7. * @version 2.0
  8. * @date 21. May. 2010
  9. * @author NXP MCU SW Application Team
  10. *
  11. * Copyright(C) 2010, NXP Semiconductor
  12. * All rights reserved.
  13. *
  14. ***********************************************************************
  15. * Software that is described herein is for illustrative purposes only
  16. * which provides customers with programming information regarding the
  17. * products. This software is supplied "AS IS" without any warranties.
  18. * NXP Semiconductors assumes no responsibility or liability for the
  19. * use of the software, conveys no license or title under any patent,
  20. * copyright, or mask work right to the product. NXP Semiconductors
  21. * reserves the right to make changes in the software without
  22. * notification. NXP Semiconductors also make no representation or
  23. * warranty that such application will be suitable for the specified
  24. * use without further testing or modification.
  25. * Permission to use, copy, modify, and distribute this software and its
  26. * documentation is hereby granted, under NXP Semiconductors'
  27. * relevant copyright in the software, without fee, provided that it
  28. * is used in conjunction with NXP Semiconductors microcontrollers. This
  29. * copyright, permission, and disclaimer notice must appear in all copies of
  30. * this code.
  31. **********************************************************************/
  32. /* Peripheral group ----------------------------------------------------------- */
  33. /** @defgroup CLKPWR CLKPWR (Clock Power)
  34. * @ingroup LPC1700CMSIS_FwLib_Drivers
  35. * @{
  36. */
  37. #ifndef LPC17XX_CLKPWR_H_
  38. #define LPC17XX_CLKPWR_H_
  39. /* Includes ------------------------------------------------------------------- */
  40. #include "LPC17xx.h"
  41. #include "lpc_types.h"
  42. #ifdef __cplusplus
  43. extern "C"
  44. {
  45. #endif
  46. /* Public Macros -------------------------------------------------------------- */
  47. /** @defgroup CLKPWR_Public_Macros CLKPWR Public Macros
  48. * @{
  49. */
  50. /**********************************************************************
  51. * Peripheral Clock Selection Definitions
  52. **********************************************************************/
  53. /** Peripheral clock divider bit position for WDT */
  54. #define CLKPWR_PCLKSEL_WDT ((uint32_t)(0))
  55. /** Peripheral clock divider bit position for TIMER0 */
  56. #define CLKPWR_PCLKSEL_TIMER0 ((uint32_t)(2))
  57. /** Peripheral clock divider bit position for TIMER1 */
  58. #define CLKPWR_PCLKSEL_TIMER1 ((uint32_t)(4))
  59. /** Peripheral clock divider bit position for UART0 */
  60. #define CLKPWR_PCLKSEL_UART0 ((uint32_t)(6))
  61. /** Peripheral clock divider bit position for UART1 */
  62. #define CLKPWR_PCLKSEL_UART1 ((uint32_t)(8))
  63. /** Peripheral clock divider bit position for PWM1 */
  64. #define CLKPWR_PCLKSEL_PWM1 ((uint32_t)(12))
  65. /** Peripheral clock divider bit position for I2C0 */
  66. #define CLKPWR_PCLKSEL_I2C0 ((uint32_t)(14))
  67. /** Peripheral clock divider bit position for SPI */
  68. #define CLKPWR_PCLKSEL_SPI ((uint32_t)(16))
  69. /** Peripheral clock divider bit position for SSP1 */
  70. #define CLKPWR_PCLKSEL_SSP1 ((uint32_t)(20))
  71. /** Peripheral clock divider bit position for DAC */
  72. #define CLKPWR_PCLKSEL_DAC ((uint32_t)(22))
  73. /** Peripheral clock divider bit position for ADC */
  74. #define CLKPWR_PCLKSEL_ADC ((uint32_t)(24))
  75. /** Peripheral clock divider bit position for CAN1 */
  76. #define CLKPWR_PCLKSEL_CAN1 ((uint32_t)(26))
  77. /** Peripheral clock divider bit position for CAN2 */
  78. #define CLKPWR_PCLKSEL_CAN2 ((uint32_t)(28))
  79. /** Peripheral clock divider bit position for ACF */
  80. #define CLKPWR_PCLKSEL_ACF ((uint32_t)(30))
  81. /** Peripheral clock divider bit position for QEI */
  82. #define CLKPWR_PCLKSEL_QEI ((uint32_t)(32))
  83. /** Peripheral clock divider bit position for PCB */
  84. #define CLKPWR_PCLKSEL_PCB ((uint32_t)(36))
  85. /** Peripheral clock divider bit position for I2C1 */
  86. #define CLKPWR_PCLKSEL_I2C1 ((uint32_t)(38))
  87. /** Peripheral clock divider bit position for SSP0 */
  88. #define CLKPWR_PCLKSEL_SSP0 ((uint32_t)(42))
  89. /** Peripheral clock divider bit position for TIMER2 */
  90. #define CLKPWR_PCLKSEL_TIMER2 ((uint32_t)(44))
  91. /** Peripheral clock divider bit position for TIMER3 */
  92. #define CLKPWR_PCLKSEL_TIMER3 ((uint32_t)(46))
  93. /** Peripheral clock divider bit position for UART2 */
  94. #define CLKPWR_PCLKSEL_UART2 ((uint32_t)(48))
  95. /** Peripheral clock divider bit position for UART3 */
  96. #define CLKPWR_PCLKSEL_UART3 ((uint32_t)(50))
  97. /** Peripheral clock divider bit position for I2C2 */
  98. #define CLKPWR_PCLKSEL_I2C2 ((uint32_t)(52))
  99. /** Peripheral clock divider bit position for I2S */
  100. #define CLKPWR_PCLKSEL_I2S ((uint32_t)(54))
  101. /** Peripheral clock divider bit position for RIT */
  102. #define CLKPWR_PCLKSEL_RIT ((uint32_t)(58))
  103. /** Peripheral clock divider bit position for SYSCON */
  104. #define CLKPWR_PCLKSEL_SYSCON ((uint32_t)(60))
  105. /** Peripheral clock divider bit position for MC */
  106. #define CLKPWR_PCLKSEL_MC ((uint32_t)(62))
  107. /** Macro for Peripheral Clock Selection register bit values
  108. * Note: When CCLK_DIV_8, Peripheral�s clock is selected to
  109. * PCLK_xyz = CCLK/8 except for CAN1, CAN2, and CAN filtering
  110. * when �11�selects PCLK_xyz = CCLK/6 */
  111. /* Peripheral clock divider is set to 4 from CCLK */
  112. #define CLKPWR_PCLKSEL_CCLK_DIV_4 ((uint32_t)(0))
  113. /** Peripheral clock divider is the same with CCLK */
  114. #define CLKPWR_PCLKSEL_CCLK_DIV_1 ((uint32_t)(1))
  115. /** Peripheral clock divider is set to 2 from CCLK */
  116. #define CLKPWR_PCLKSEL_CCLK_DIV_2 ((uint32_t)(2))
  117. /********************************************************************
  118. * Power Control for Peripherals Definitions
  119. **********************************************************************/
  120. /** Timer/Counter 0 power/clock control bit */
  121. #define CLKPWR_PCONP_PCTIM0 ((uint32_t)(1<<1))
  122. /* Timer/Counter 1 power/clock control bit */
  123. #define CLKPWR_PCONP_PCTIM1 ((uint32_t)(1<<2))
  124. /** UART0 power/clock control bit */
  125. #define CLKPWR_PCONP_PCUART0 ((uint32_t)(1<<3))
  126. /** UART1 power/clock control bit */
  127. #define CLKPWR_PCONP_PCUART1 ((uint32_t)(1<<4))
  128. /** PWM1 power/clock control bit */
  129. #define CLKPWR_PCONP_PCPWM1 ((uint32_t)(1<<6))
  130. /** The I2C0 interface power/clock control bit */
  131. #define CLKPWR_PCONP_PCI2C0 ((uint32_t)(1<<7))
  132. /** The SPI interface power/clock control bit */
  133. #define CLKPWR_PCONP_PCSPI ((uint32_t)(1<<8))
  134. /** The RTC power/clock control bit */
  135. #define CLKPWR_PCONP_PCRTC ((uint32_t)(1<<9))
  136. /** The SSP1 interface power/clock control bit */
  137. #define CLKPWR_PCONP_PCSSP1 ((uint32_t)(1<<10))
  138. /** A/D converter 0 (ADC0) power/clock control bit */
  139. #define CLKPWR_PCONP_PCAD ((uint32_t)(1<<12))
  140. /** CAN Controller 1 power/clock control bit */
  141. #define CLKPWR_PCONP_PCAN1 ((uint32_t)(1<<13))
  142. /** CAN Controller 2 power/clock control bit */
  143. #define CLKPWR_PCONP_PCAN2 ((uint32_t)(1<<14))
  144. /** GPIO power/clock control bit */
  145. #define CLKPWR_PCONP_PCGPIO ((uint32_t)(1<<15))
  146. /** Repetitive Interrupt Timer power/clock control bit */
  147. #define CLKPWR_PCONP_PCRIT ((uint32_t)(1<<16))
  148. /** Motor Control PWM */
  149. #define CLKPWR_PCONP_PCMC ((uint32_t)(1<<17))
  150. /** Quadrature Encoder Interface power/clock control bit */
  151. #define CLKPWR_PCONP_PCQEI ((uint32_t)(1<<18))
  152. /** The I2C1 interface power/clock control bit */
  153. #define CLKPWR_PCONP_PCI2C1 ((uint32_t)(1<<19))
  154. /** The SSP0 interface power/clock control bit */
  155. #define CLKPWR_PCONP_PCSSP0 ((uint32_t)(1<<21))
  156. /** Timer 2 power/clock control bit */
  157. #define CLKPWR_PCONP_PCTIM2 ((uint32_t)(1<<22))
  158. /** Timer 3 power/clock control bit */
  159. #define CLKPWR_PCONP_PCTIM3 ((uint32_t)(1<<23))
  160. /** UART 2 power/clock control bit */
  161. #define CLKPWR_PCONP_PCUART2 ((uint32_t)(1<<24))
  162. /** UART 3 power/clock control bit */
  163. #define CLKPWR_PCONP_PCUART3 ((uint32_t)(1<<25))
  164. /** I2C interface 2 power/clock control bit */
  165. #define CLKPWR_PCONP_PCI2C2 ((uint32_t)(1<<26))
  166. /** I2S interface power/clock control bit*/
  167. #define CLKPWR_PCONP_PCI2S ((uint32_t)(1<<27))
  168. /** GP DMA function power/clock control bit*/
  169. #define CLKPWR_PCONP_PCGPDMA ((uint32_t)(1<<29))
  170. /** Ethernet block power/clock control bit*/
  171. #define CLKPWR_PCONP_PCENET ((uint32_t)(1<<30))
  172. /** USB interface power/clock control bit*/
  173. #define CLKPWR_PCONP_PCUSB ((uint32_t)(1<<31))
  174. /**
  175. * @}
  176. */
  177. /* Private Macros ------------------------------------------------------------- */
  178. /** @defgroup CLKPWR_Private_Macros CLKPWR Private Macros
  179. * @{
  180. */
  181. /* --------------------- BIT DEFINITIONS -------------------------------------- */
  182. /*********************************************************************//**
  183. * Macro defines for Clock Source Select Register
  184. **********************************************************************/
  185. /** Internal RC oscillator */
  186. #define CLKPWR_CLKSRCSEL_CLKSRC_IRC ((uint32_t)(0x00))
  187. /** Main oscillator */
  188. #define CLKPWR_CLKSRCSEL_CLKSRC_MAINOSC ((uint32_t)(0x01))
  189. /** RTC oscillator */
  190. #define CLKPWR_CLKSRCSEL_CLKSRC_RTC ((uint32_t)(0x02))
  191. /** Clock source selection bit mask */
  192. #define CLKPWR_CLKSRCSEL_BITMASK ((uint32_t)(0x03))
  193. /*********************************************************************//**
  194. * Macro defines for Clock Output Configuration Register
  195. **********************************************************************/
  196. /* Clock Output Configuration register definition */
  197. /** Selects the CPU clock as the CLKOUT source */
  198. #define CLKPWR_CLKOUTCFG_CLKOUTSEL_CPU ((uint32_t)(0x00))
  199. /** Selects the main oscillator as the CLKOUT source */
  200. #define CLKPWR_CLKOUTCFG_CLKOUTSEL_MAINOSC ((uint32_t)(0x01))
  201. /** Selects the Internal RC oscillator as the CLKOUT source */
  202. #define CLKPWR_CLKOUTCFG_CLKOUTSEL_RC ((uint32_t)(0x02))
  203. /** Selects the USB clock as the CLKOUT source */
  204. #define CLKPWR_CLKOUTCFG_CLKOUTSEL_USB ((uint32_t)(0x03))
  205. /** Selects the RTC oscillator as the CLKOUT source */
  206. #define CLKPWR_CLKOUTCFG_CLKOUTSEL_RTC ((uint32_t)(0x04))
  207. /** Integer value to divide the output clock by, minus one */
  208. #define CLKPWR_CLKOUTCFG_CLKOUTDIV(n) ((uint32_t)((n&0x0F)<<4))
  209. /** CLKOUT enable control */
  210. #define CLKPWR_CLKOUTCFG_CLKOUT_EN ((uint32_t)(1<<8))
  211. /** CLKOUT activity indication */
  212. #define CLKPWR_CLKOUTCFG_CLKOUT_ACT ((uint32_t)(1<<9))
  213. /** Clock source selection bit mask */
  214. #define CLKPWR_CLKOUTCFG_BITMASK ((uint32_t)(0x3FF))
  215. /*********************************************************************//**
  216. * Macro defines for PPL0 Control Register
  217. **********************************************************************/
  218. /** PLL 0 control enable */
  219. #define CLKPWR_PLL0CON_ENABLE ((uint32_t)(0x01))
  220. /** PLL 0 control connect */
  221. #define CLKPWR_PLL0CON_CONNECT ((uint32_t)(0x02))
  222. /** PLL 0 control bit mask */
  223. #define CLKPWR_PLL0CON_BITMASK ((uint32_t)(0x03))
  224. /*********************************************************************//**
  225. * Macro defines for PPL0 Configuration Register
  226. **********************************************************************/
  227. /** PLL 0 Configuration MSEL field */
  228. #define CLKPWR_PLL0CFG_MSEL(n) ((uint32_t)(n&0x7FFF))
  229. /** PLL 0 Configuration NSEL field */
  230. #define CLKPWR_PLL0CFG_NSEL(n) ((uint32_t)((n<<16)&0xFF0000))
  231. /** PLL 0 Configuration bit mask */
  232. #define CLKPWR_PLL0CFG_BITMASK ((uint32_t)(0xFF7FFF))
  233. /*********************************************************************//**
  234. * Macro defines for PPL0 Status Register
  235. **********************************************************************/
  236. /** PLL 0 MSEL value */
  237. #define CLKPWR_PLL0STAT_MSEL(n) ((uint32_t)(n&0x7FFF))
  238. /** PLL NSEL get value */
  239. #define CLKPWR_PLL0STAT_NSEL(n) ((uint32_t)((n>>16)&0xFF))
  240. /** PLL status enable bit */
  241. #define CLKPWR_PLL0STAT_PLLE ((uint32_t)(1<<24))
  242. /** PLL status Connect bit */
  243. #define CLKPWR_PLL0STAT_PLLC ((uint32_t)(1<<25))
  244. /** PLL status lock */
  245. #define CLKPWR_PLL0STAT_PLOCK ((uint32_t)(1<<26))
  246. /*********************************************************************//**
  247. * Macro defines for PPL0 Feed Register
  248. **********************************************************************/
  249. /** PLL0 Feed bit mask */
  250. #define CLKPWR_PLL0FEED_BITMASK ((uint32_t)0xFF)
  251. /*********************************************************************//**
  252. * Macro defines for PLL1 Control Register
  253. **********************************************************************/
  254. /** USB PLL control enable */
  255. #define CLKPWR_PLL1CON_ENABLE ((uint32_t)(0x01))
  256. /** USB PLL control connect */
  257. #define CLKPWR_PLL1CON_CONNECT ((uint32_t)(0x02))
  258. /** USB PLL control bit mask */
  259. #define CLKPWR_PLL1CON_BITMASK ((uint32_t)(0x03))
  260. /*********************************************************************//**
  261. * Macro defines for PLL1 Configuration Register
  262. **********************************************************************/
  263. /** USB PLL MSEL set value */
  264. #define CLKPWR_PLL1CFG_MSEL(n) ((uint32_t)(n&0x1F))
  265. /** USB PLL PSEL set value */
  266. #define CLKPWR_PLL1CFG_PSEL(n) ((uint32_t)((n&0x03)<<5))
  267. /** USB PLL configuration bit mask */
  268. #define CLKPWR_PLL1CFG_BITMASK ((uint32_t)(0x7F))
  269. /*********************************************************************//**
  270. * Macro defines for PLL1 Status Register
  271. **********************************************************************/
  272. /** USB PLL MSEL get value */
  273. #define CLKPWR_PLL1STAT_MSEL(n) ((uint32_t)(n&0x1F))
  274. /** USB PLL PSEL get value */
  275. #define CLKPWR_PLL1STAT_PSEL(n) ((uint32_t)((n>>5)&0x03))
  276. /** USB PLL status enable bit */
  277. #define CLKPWR_PLL1STAT_PLLE ((uint32_t)(1<<8))
  278. /** USB PLL status Connect bit */
  279. #define CLKPWR_PLL1STAT_PLLC ((uint32_t)(1<<9))
  280. /** USB PLL status lock */
  281. #define CLKPWR_PLL1STAT_PLOCK ((uint32_t)(1<<10))
  282. /*********************************************************************//**
  283. * Macro defines for PLL1 Feed Register
  284. **********************************************************************/
  285. /** PLL1 Feed bit mask */
  286. #define CLKPWR_PLL1FEED_BITMASK ((uint32_t)0xFF)
  287. /*********************************************************************//**
  288. * Macro defines for CPU Clock Configuration Register
  289. **********************************************************************/
  290. /** CPU Clock configuration bit mask */
  291. #define CLKPWR_CCLKCFG_BITMASK ((uint32_t)(0xFF))
  292. /*********************************************************************//**
  293. * Macro defines for USB Clock Configuration Register
  294. **********************************************************************/
  295. /** USB Clock Configuration bit mask */
  296. #define CLKPWR_USBCLKCFG_BITMASK ((uint32_t)(0x0F))
  297. /*********************************************************************//**
  298. * Macro defines for IRC Trim Register
  299. **********************************************************************/
  300. /** IRC Trim bit mask */
  301. #define CLKPWR_IRCTRIM_BITMASK ((uint32_t)(0x0F))
  302. /*********************************************************************//**
  303. * Macro defines for Peripheral Clock Selection Register 0 and 1
  304. **********************************************************************/
  305. /** Peripheral Clock Selection 0 mask bit */
  306. #define CLKPWR_PCLKSEL0_BITMASK ((uint32_t)(0xFFF3F3FF))
  307. /** Peripheral Clock Selection 1 mask bit */
  308. #define CLKPWR_PCLKSEL1_BITMASK ((uint32_t)(0xFCF3F0F3))
  309. /** Macro to set peripheral clock of each type
  310. * p: position of two bits that hold divider of peripheral clock
  311. * n: value of divider of peripheral clock to be set */
  312. #define CLKPWR_PCLKSEL_SET(p,n) _SBF(p,n)
  313. /** Macro to mask peripheral clock of each type */
  314. #define CLKPWR_PCLKSEL_BITMASK(p) _SBF(p,0x03)
  315. /** Macro to get peripheral clock of each type */
  316. #define CLKPWR_PCLKSEL_GET(p, n) ((uint32_t)((n>>p)&0x03))
  317. /*********************************************************************//**
  318. * Macro defines for Power Mode Control Register
  319. **********************************************************************/
  320. /** Power mode control bit 0 */
  321. #define CLKPWR_PCON_PM0 ((uint32_t)(1<<0))
  322. /** Power mode control bit 1 */
  323. #define CLKPWR_PCON_PM1 ((uint32_t)(1<<1))
  324. /** Brown-Out Reduced Power Mode */
  325. #define CLKPWR_PCON_BODPDM ((uint32_t)(1<<2))
  326. /** Brown-Out Global Disable */
  327. #define CLKPWR_PCON_BOGD ((uint32_t)(1<<3))
  328. /** Brown Out Reset Disable */
  329. #define CLKPWR_PCON_BORD ((uint32_t)(1<<4))
  330. /** Sleep Mode entry flag */
  331. #define CLKPWR_PCON_SMFLAG ((uint32_t)(1<<8))
  332. /** Deep Sleep entry flag */
  333. #define CLKPWR_PCON_DSFLAG ((uint32_t)(1<<9))
  334. /** Power-down entry flag */
  335. #define CLKPWR_PCON_PDFLAG ((uint32_t)(1<<10))
  336. /** Deep Power-down entry flag */
  337. #define CLKPWR_PCON_DPDFLAG ((uint32_t)(1<<11))
  338. /*********************************************************************//**
  339. * Macro defines for Power Control for Peripheral Register
  340. **********************************************************************/
  341. /** Power Control for Peripherals bit mask */
  342. #define CLKPWR_PCONP_BITMASK 0xEFEFF7DE
  343. /**
  344. * @}
  345. */
  346. /* Public Functions ----------------------------------------------------------- */
  347. /** @defgroup CLKPWR_Public_Functions CLKPWR Public Functions
  348. * @{
  349. */
  350. void CLKPWR_SetPCLKDiv (uint32_t ClkType, uint32_t DivVal);
  351. uint32_t CLKPWR_GetPCLKSEL (uint32_t ClkType);
  352. uint32_t CLKPWR_GetPCLK (uint32_t ClkType);
  353. void CLKPWR_ConfigPPWR (uint32_t PPType, FunctionalState NewState);
  354. void CLKPWR_Sleep(void);
  355. void CLKPWR_DeepSleep(void);
  356. void CLKPWR_PowerDown(void);
  357. void CLKPWR_DeepPowerDown(void);
  358. /**
  359. * @}
  360. */
  361. #ifdef __cplusplus
  362. }
  363. #endif
  364. #endif /* LPC17XX_CLKPWR_H_ */
  365. /**
  366. * @}
  367. */
  368. /* --------------------------------- End Of File ------------------------------ */