1
0

syscon_8xx.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  1. /*
  2. * @brief LPC8xx System & Control driver inclusion file
  3. *
  4. * @note
  5. * Copyright(C) NXP Semiconductors, 2012
  6. * All rights reserved.
  7. *
  8. * @par
  9. * Software that is described herein is for illustrative purposes only
  10. * which provides customers with programming information regarding the
  11. * LPC products. This software is supplied "AS IS" without any warranties of
  12. * any kind, and NXP Semiconductors and its licensor disclaim any and
  13. * all warranties, express or implied, including all implied warranties of
  14. * merchantability, fitness for a particular purpose and non-infringement of
  15. * intellectual property rights. NXP Semiconductors assumes no responsibility
  16. * or liability for the use of the software, conveys no license or rights under any
  17. * patent, copyright, mask work right, or any other intellectual property rights in
  18. * or to any products. NXP Semiconductors reserves the right to make changes
  19. * in the software without notification. NXP Semiconductors also makes no
  20. * representation or warranty that such application will be suitable for the
  21. * specified use without further testing or modification.
  22. *
  23. * @par
  24. * Permission to use, copy, modify, and distribute this software and its
  25. * documentation is hereby granted, under NXP Semiconductors' and its
  26. * licensor's relevant copyrights in the software, without fee, provided that it
  27. * is used in conjunction with NXP Semiconductors microcontrollers. This
  28. * copyright, permission, and disclaimer notice must appear in all copies of
  29. * this code.
  30. */
  31. #ifndef __SYSCTL_8XX_H_
  32. #define __SYSCTL_8XX_H_
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. /** @defgroup SYSCTL_8XX CHIP: LPC8xx System and Control Driver
  37. * @ingroup CHIP_8XX_Drivers
  38. * @{
  39. */
  40. /**
  41. * System reset status values
  42. */
  43. #define SYSCTL_RST_POR (1 << 0) /*!< POR reset status */
  44. #define SYSCTL_RST_EXTRST (1 << 1) /*!< External reset status */
  45. #define SYSCTL_RST_WDT (1 << 2) /*!< Watchdog reset status */
  46. #define SYSCTL_RST_BOD (1 << 3) /*!< Brown-out detect reset status */
  47. #define SYSCTL_RST_SYSRST (1 << 4) /*!< software system reset status */
  48. /**
  49. * Peripheral interrupt wakeup events values
  50. */
  51. #define SYSCTL_WAKEUP_SPI0TINT (1 << 0) /*!< SPI0 interrupt wake-up */
  52. #define SYSCTL_WAKEUP_SPI1INT (1 << 1) /*!< SPI0 interrupt wake-up */
  53. #define SYSCTL_WAKEUP_USART0INT (1 << 3) /*!< USART0 interrupt wake-up */
  54. #define SYSCTL_WAKEUP_USART1INT (1 << 4) /*!< USART1 interrupt wake-up */
  55. #define SYSCTL_WAKEUP_USART2INT (1 << 5) /*!< USART2 interrupt wake-up */
  56. #define SYSCTL_WAKEUP_I2C0INT (1 << 8) /*!< I2C0 interrupt wake-up */
  57. #define SYSCTL_WAKEUP_I2C1INT (1 << 7) /*!< I2C1 interrupt wake-up [Available only on LPC82X] */
  58. #define SYSCTL_WAKEUP_I2C2INT (1 << 21) /*!< I2C2 interrupt wake-up [Available only on LPC82X] */
  59. #define SYSCTL_WAKEUP_I2C3INT (1 << 22) /*!< I2C3 interrupt wake-up [Available only on LPC82X] */
  60. #define SYSCTL_WAKEUP_WWDTINT (1 << 12) /*!< WWDT interrupt wake-up */
  61. #define SYSCTL_WAKEUP_BODINT (1 << 13) /*!< Brown Out Detect (BOD) interrupt wake-up */
  62. #define SYSCTL_WAKEUP_WKTINT (1 << 15) /*!< Self wake-up timer interrupt wake-up */
  63. #define SYSCTL_WAKEUP_I2CINT SYSCTL_WAKEUP_I2C0INT /*!< Same as #SYSCTL_WAKEUP_I2CINT */
  64. /**
  65. * Deep sleep setup values
  66. */
  67. #define SYSCTL_DEEPSLP_BOD_PD (1 << 3) /*!< BOD power-down control in Deep-sleep mode, powered down */
  68. #define SYSCTL_DEEPSLP_WDTOSC_PD (1 << 6) /*!< Watchdog oscillator power control in Deep-sleep, powered down */
  69. /**
  70. * Deep sleep to wakeup and power state setup values
  71. */
  72. #define SYSCTL_SLPWAKE_IRCOUT_PD (1 << 0) /*!< IRC oscillator output wake-up configuration */
  73. #define SYSCTL_SLPWAKE_IRC_PD (1 << 1) /*!< IRC oscillator power-down wake-up configuration */
  74. #define SYSCTL_SLPWAKE_FLASH_PD (1 << 2) /*!< Flash wake-up configuration */
  75. #define SYSCTL_SLPWAKE_BOD_PD (1 << 3) /*!< BOD wake-up configuration */
  76. #define SYSCTL_SLPWAKE_ADC_PD (1 << 4) /*!< ADC wake-up configuration [Available only on LPC82x] */
  77. #define SYSCTL_SLPWAKE_SYSOSC_PD (1 << 5) /*!< System oscillator wake-up configuration */
  78. #define SYSCTL_SLPWAKE_WDTOSC_PD (1 << 6) /*!< Watchdog oscillator wake-up configuration */
  79. #define SYSCTL_SLPWAKE_SYSPLL_PD (1 << 7) /*!< System PLL wake-up configuration */
  80. #define SYSCTL_SLPWAKE_ACMP_PD (1 << 15) /*!< Analog comparator wake-up configuration */
  81. /**
  82. * Non-Maskable Interrupt Enable/Disable value
  83. */
  84. #define SYSCTL_NMISRC_ENABLE ((uint32_t) 1 << 31) /*!< Enable the Non-Maskable Interrupt (NMI) source */
  85. /**
  86. * @brief LPC8XX System Control and Clock register block structure
  87. */
  88. typedef struct {
  89. __IO uint32_t SYSMEMREMAP; /*!< Offset: 0x000 System memory remap (R/W) */
  90. __IO uint32_t PRESETCTRL; /*!< Offset: 0x004 Peripheral reset control (R/W) */
  91. __IO uint32_t SYSPLLCTRL; /*!< Offset: 0x008 System PLL control (R/W) */
  92. __IO uint32_t SYSPLLSTAT; /*!< Offset: 0x00C System PLL status (R/W ) */
  93. uint32_t RESERVED0[4];
  94. __IO uint32_t SYSOSCCTRL; /*!< Offset: 0x020 System oscillator control (R/W) */
  95. __IO uint32_t WDTOSCCTRL; /*!< Offset: 0x024 Watchdog oscillator control (R/W) */
  96. __IO uint32_t IRCCTRL; /*!< Offset: 0x028 IRC Control Register (Available only in LPC82X) */
  97. uint32_t RESERVED1[1];
  98. __IO uint32_t SYSRSTSTAT; /*!< Offset: 0x030 System reset status Register (R/W ) */
  99. uint32_t RESERVED2[3];
  100. __IO uint32_t SYSPLLCLKSEL; /*!< Offset: 0x040 System PLL clock source select (R/W) */
  101. __IO uint32_t SYSPLLCLKUEN; /*!< Offset: 0x044 System PLL clock source update enable (R/W) */
  102. uint32_t RESERVED3[10];
  103. __IO uint32_t MAINCLKSEL; /*!< Offset: 0x070 Main clock source select (R/W) */
  104. __IO uint32_t MAINCLKUEN; /*!< Offset: 0x074 Main clock source update enable (R/W) */
  105. __IO uint32_t SYSAHBCLKDIV; /*!< Offset: 0x078 System AHB clock divider (R/W) */
  106. uint32_t RESERVED4[1];
  107. __IO uint32_t SYSAHBCLKCTRL; /*!< Offset: 0x080 System AHB clock control (R/W) */
  108. uint32_t RESERVED5[4];
  109. __IO uint32_t UARTCLKDIV; /*!< Offset: 0x094 UART clock divider (R/W) */
  110. uint32_t RESERVED6[18];
  111. __IO uint32_t CLKOUTSEL; /*!< Offset: 0x0E0 CLKOUT clock source select (R/W) */
  112. __IO uint32_t CLKOUTUEN; /*!< Offset: 0x0E4 CLKOUT clock source update enable (R/W) */
  113. __IO uint32_t CLKOUTDIV; /*!< Offset: 0x0E8 CLKOUT clock divider (R/W) */
  114. uint32_t RESERVED7;
  115. __IO uint32_t UARTFRGDIV; /*!< Offset: 0x0F0 UART fractional divider SUB(R/W) */
  116. __IO uint32_t UARTFRGMULT; /*!< Offset: 0x0F4 UART fractional divider ADD(R/W) */
  117. uint32_t RESERVED8[1];
  118. __IO uint32_t EXTTRACECMD; /*!< Offset: 0x0FC External trace buffer command register */
  119. __IO uint32_t PIOPORCAP0; /*!< Offset: 0x100 POR captured PIO status 0 (R/ ) */
  120. uint32_t RESERVED9[12];
  121. __IO uint32_t IOCONCLKDIV[7]; /*!< Offset: 0x134 Peripheral clock x to the IOCON block for programmable glitch filter */
  122. __IO uint32_t BODCTRL; /*!< Offset: 0x150 BOD control (R/W) */
  123. __IO uint32_t SYSTCKCAL; /*!< Offset: 0x154 System tick counter calibration (R/W) */
  124. uint32_t RESERVED10[6];
  125. __IO uint32_t IRQLATENCY; /*!< Offset: 0x170 IRQ delay */
  126. __IO uint32_t NMISRC; /*!< Offset: 0x174 NMI Source Control */
  127. __IO uint32_t PINTSEL[8]; /*!< Offset: 0x178 GPIO Pin Interrupt Select register 0 */
  128. uint32_t RESERVED11[27];
  129. __IO uint32_t STARTERP0; /*!< Offset: 0x204 Start logic signal enable Register 0 (R/W) */
  130. uint32_t RESERVED12[3];
  131. __IO uint32_t STARTERP1; /*!< Offset: 0x214 Start logic signal enable Register 0 (R/W) */
  132. uint32_t RESERVED13[6];
  133. __IO uint32_t PDSLEEPCFG; /*!< Offset: 0x230 Power-down states in Deep-sleep mode (R/W) */
  134. __IO uint32_t PDAWAKECFG; /*!< Offset: 0x234 Power-down states after wake-up (R/W) */
  135. __IO uint32_t PDRUNCFG; /*!< Offset: 0x238 Power-down configuration Register (R/W) */
  136. uint32_t RESERVED14[111];
  137. __I uint32_t DEVICEID; /*!< Offset: 0x3F8 Device ID (R/ ) */
  138. } LPC_SYSCTL_T;
  139. /**
  140. * @brief IOCON Perpipheral Clock divider selction for input filter
  141. * sampling clock
  142. */
  143. typedef enum CHIP_PIN_CLKDIV {
  144. IOCONCLKDIV0 = 0, /*!< Clock divider 0 */
  145. IOCONCLKDIV1, /*!< Clock divider 1 */
  146. IOCONCLKDIV2, /*!< Clock divider 2 */
  147. IOCONCLKDIV3, /*!< Clock divider 3 */
  148. IOCONCLKDIV4, /*!< Clock divider 4 */
  149. IOCONCLKDIV5, /*!< Clock divider 5 */
  150. IOCONCLKDIV6, /*!< Clock divider 6 */
  151. IOCONCLK_MAX = IOCONCLKDIV6 /*!< Top value used to reverse the dividers */
  152. } CHIP_PIN_CLKDIV_T;
  153. /* Reserved bits masks for registers */
  154. #define SYSCTL_SYSMEMREMAP_RESERVED (~3)
  155. #define SYSCTL_SYSPLLCTRL_RESERVED (~0x7f)
  156. #define SYSCTL_SYSPLLSTAT_RESERVED (~1)
  157. #define SYSCTL_SYSOSCCTRL_RESERVED (~3)
  158. #define SYSCTL_WDTOSCCTRL_RESERVED (~0x1ff)
  159. #define SYSCTL_SYSRSTSTAT_RESERVED (~0x1f)
  160. #define SYSCTL_SYSPLLCLKSEL_RESERVED (~3)
  161. #define SYSCTL_SYSPLLCLKUEN_RESERVED (~1)
  162. #define SYSCTL_MAINCLKSEL_RESERVED (~3)
  163. #define SYSCTL_MAINCLKUEN_RESERVED (~1)
  164. #define SYSCTL_SYSAHBCLKDIV_RESERVED (~0xff)
  165. #define SYSCTL_UARTCLKDIV_RESERVED (~0xff)
  166. #define SYSCTL_CLKOUTSEL_RESERVED (~3)
  167. #define SYSCTL_CLKOUTUEN_RESERVED (~1)
  168. #define SYSCTL_CLKOUTDIV_RESERVED (~0xff)
  169. #define SYSCTL_UARTFRGDIV_RESERVED (~0xff)
  170. #define SYSCTL_UARTFRGMULT_RESERVED (~0xff)
  171. #define SYSCTL_EXTTRACECMD_RESERVED (~3)
  172. #define SYSCTL_IOCONCLKDIV_RESERVED (~0xff)
  173. #define SYSCTL_BODCTRL_RESERVED (~0x1f)
  174. #define SYSCTL_SYSTCKCAL_RESERVED 0xfc000000
  175. #define SYSCTL_IRQLATENCY_RESERVED (~0xff)
  176. #define SYSCTL_NMISRC_RESERVED (~(0x1f|(1u<<31)))
  177. #define SYSCTL_PINTSEL_RESERVED (~0x3f)
  178. #define SYSCTL_STARTERP0_RESERVED (~0xff)
  179. #if defined(CHIP_LPC82X)
  180. #define SYSCTL_PRESETCTRL_RESERVED 0xfffe2000
  181. #define SYSCTL_SYSAHBCLKCTRL_RESERVED 0xda100000
  182. #define SYSCTL_PIOPORCAP0_RESERVED 0xfffc0000
  183. #define SYSCTL_STARTERP1_RESERVED ((1<<2)|(1<<6)|(7<<9)|(1<<14)|0xff9f0000)
  184. #else
  185. #define SYSCTL_PRESETCTRL_RESERVED 0xffffe000
  186. #define SYSCTL_SYSAHBCLKCTRL_RESERVED 0xfff00000
  187. #define SYSCTL_PIOPORCAP0_RESERVED 0xffffc000
  188. #define SYSCTL_STARTERP1_RESERVED ((1<<2)|(3<<6)|(7<<9)|(1<<14)|(0x1f<<16)|0xff800000)
  189. #endif
  190. /* The following have reserved bits, but they are specially handled elsewhere. */
  191. /* #define SYSCTL_PDSLEEPCFG_RESERVED (~(1<<3)|(3<<4)|(1<<6)) */
  192. /* #define SYSCTL_PDAWAKECFG_RESERVED */
  193. /* #define SYSCTL_PDRUNCFG_RESERVED */
  194. /**
  195. * System memory remap modes used to remap interrupt vectors
  196. */
  197. typedef enum CHIP_SYSCTL_BOOT_MODE_REMAP {
  198. REMAP_BOOT_LOADER_MODE, /*!< Interrupt vectors are re-mapped to Boot ROM */
  199. REMAP_USER_RAM_MODE, /*!< Interrupt vectors are re-mapped to user Static RAM */
  200. REMAP_USER_FLASH_MODE /*!< Interrupt vectors are not re-mapped and reside in Flash */
  201. } CHIP_SYSCTL_BOOT_MODE_REMAP_T;
  202. /**
  203. * Peripheral reset identifiers
  204. */
  205. typedef enum {
  206. RESET_SPI0, /*!< SPI0 reset control */
  207. RESET_SPI1, /*!< SPI1 reset control */
  208. RESET_UARTFBRG, /*!< UART fractional baud rate generator reset control */
  209. RESET_USART0, /*!< USART0 reset control */
  210. RESET_USART1, /*!< USART1 reset control */
  211. RESET_USART2, /*!< USART2 reset control */
  212. RESET_I2C0, /*!< I2C0 reset control */
  213. RESET_MRT, /*!< MRT reset control */
  214. RESET_SCT, /*!< SCT reset control */
  215. RESET_WKT, /*!< Self wake-up timer (WKT) control */
  216. RESET_GPIO, /*!< GPIO reset control */
  217. RESET_FLASH, /*!< FLASH reset control */
  218. RESET_ACMP, /*!< ACMP reset control */
  219. RESET_I2C1 = 14, /*!< I2C1 reset control [Available only in LPC82x] */
  220. RESET_I2C2, /*!< I2C2 reset control [Available only in LPC82x] */
  221. RESET_I2C3, /*!< I2C3 reset control [Available only in LPC82x] */
  222. } CHIP_SYSCTL_PERIPH_RESET_T;
  223. /* Reset Alias */
  224. #define RESET_I2C RESET_I2C0
  225. /**
  226. * Brown-out detector reset level
  227. */
  228. typedef enum CHIP_SYSCTL_BODRSTLVL {
  229. SYSCTL_BODRSTLVL_0, /*!< Brown-out reset at 1.46 ~ 1.63v */
  230. SYSCTL_BODRSTLVL_1, /*!< Brown-out reset at 2.06v ~ 2.15v */
  231. SYSCTL_BODRSTLVL_2, /*!< Brown-out reset at 2.35v ~ 2.43v */
  232. SYSCTL_BODRSTLVL_3, /*!< Brown-out reset at 2.63v ~ 2.71v */
  233. } CHIP_SYSCTL_BODRSTLVL_T;
  234. /**
  235. * Brown-out detector interrupt level
  236. */
  237. typedef enum CHIP_SYSCTL_BODRINTVAL {
  238. SYSCTL_BODINTVAL_LVL0, /* Brown-out interrupt at 1.65 ~ 1.80v */
  239. SYSCTL_BODINTVAL_LVL1, /* Brown-out interrupt at 2.22v ~ 2.35v*/
  240. SYSCTL_BODINTVAL_LVL2, /* Brown-out interrupt at 2.52v ~ 2.66v */
  241. SYSCTL_BODINTVAL_LVL3, /* Brown-out interrupt at 2.80v ~ 2.90v */
  242. } CHIP_SYSCTL_BODRINTVAL_T;
  243. /**
  244. * @brief Re-map interrupt vectors
  245. * @param remap : system memory map value
  246. * @return Nothing
  247. */
  248. STATIC INLINE void Chip_SYSCTL_Map(CHIP_SYSCTL_BOOT_MODE_REMAP_T remap)
  249. {
  250. LPC_SYSCTL->SYSMEMREMAP = (uint32_t) remap;
  251. }
  252. /**
  253. * @brief Assert reset for a peripheral
  254. * @param periph : Peripheral to assert reset for
  255. * @return Nothing
  256. * @note The peripheral will stay in reset until reset is de-asserted. Call
  257. * Chip_SYSCTL_DeassertPeriphReset() to de-assert the reset
  258. */
  259. STATIC INLINE void Chip_SYSCTL_AssertPeriphReset(CHIP_SYSCTL_PERIPH_RESET_T periph)
  260. {
  261. LPC_SYSCTL->PRESETCTRL &= ~((1 << (uint32_t) periph) | SYSCTL_PRESETCTRL_RESERVED);
  262. }
  263. /**
  264. * @brief De-assert reset for a peripheral
  265. * @param periph : Peripheral to de-assert reset for
  266. * @return Nothing
  267. */
  268. STATIC INLINE void Chip_SYSCTL_DeassertPeriphReset(CHIP_SYSCTL_PERIPH_RESET_T periph)
  269. {
  270. LPC_SYSCTL->PRESETCTRL = (1 << (uint32_t) periph) | (LPC_SYSCTL->PRESETCTRL & ~SYSCTL_PRESETCTRL_RESERVED);
  271. }
  272. /**
  273. * @brief Resets a peripheral
  274. * @param periph : Peripheral to reset
  275. * @return Nothing
  276. */
  277. STATIC INLINE void Chip_SYSCTL_PeriphReset(CHIP_SYSCTL_PERIPH_RESET_T periph)
  278. {
  279. Chip_SYSCTL_AssertPeriphReset(periph);
  280. Chip_SYSCTL_DeassertPeriphReset(periph);
  281. }
  282. /**
  283. * @brief Get system reset status
  284. * @return An Or'ed value of SYSCTL_RST_*
  285. * @note This function returns the detected reset source(s).
  286. */
  287. STATIC INLINE uint32_t Chip_SYSCTL_GetSystemRSTStatus(void)
  288. {
  289. return LPC_SYSCTL->SYSRSTSTAT & ~SYSCTL_SYSRSTSTAT_RESERVED;
  290. }
  291. /**
  292. * @brief Clear system reset status
  293. * @param reset : An Or'ed value of SYSCTL_RST_* status to clear
  294. * @return Nothing
  295. * @note This function clears the specified reset source(s).
  296. */
  297. STATIC INLINE void Chip_SYSCTL_ClearSystemRSTStatus(uint32_t reset)
  298. {
  299. LPC_SYSCTL->SYSRSTSTAT = reset;
  300. }
  301. /**
  302. * @brief Read POR captured PIO status
  303. * @return captured POR PIO status
  304. * @note Some devices only support index 0.
  305. */
  306. STATIC INLINE uint32_t Chip_SYSCTL_GetPORPIOStatus(void)
  307. {
  308. return LPC_SYSCTL->PIOPORCAP0 & ~SYSCTL_PIOPORCAP0_RESERVED;
  309. }
  310. /**
  311. * @brief Set brown-out detection interrupt and reset levels
  312. * @param rstlvl : Brown-out detector reset level
  313. * @param intlvl : Brown-out interrupt level
  314. * @return Nothing
  315. * @note Brown-out detection reset will be disabled upon exiting this function.
  316. * Use Chip_SYSCTL_EnableBODReset() to re-enable
  317. */
  318. STATIC INLINE void Chip_SYSCTL_SetBODLevels(CHIP_SYSCTL_BODRSTLVL_T rstlvl,
  319. CHIP_SYSCTL_BODRINTVAL_T intlvl)
  320. {
  321. LPC_SYSCTL->BODCTRL = ((uint32_t) rstlvl) | (((uint32_t) intlvl) << 2);
  322. }
  323. /**
  324. * @brief Enable brown-out detection reset
  325. * @return Nothing
  326. */
  327. STATIC INLINE void Chip_SYSCTL_EnableBODReset(void)
  328. {
  329. LPC_SYSCTL->BODCTRL = (1 << 4) | (LPC_SYSCTL->BODCTRL & ~SYSCTL_BODCTRL_RESERVED);
  330. }
  331. /**
  332. * @brief Disable brown-out detection reset
  333. * @return Nothing
  334. */
  335. STATIC INLINE void Chip_SYSCTL_DisableBODReset(void)
  336. {
  337. LPC_SYSCTL->BODCTRL &= ~((1 << 4) | SYSCTL_BODCTRL_RESERVED);
  338. }
  339. /**
  340. * @brief Set System tick timer calibration value
  341. * @param sysCalVal : System tick timer calibration value
  342. * @return Nothing
  343. */
  344. STATIC INLINE void Chip_SYSCTL_SetSYSTCKCAL(uint32_t sysCalVal)
  345. {
  346. LPC_SYSCTL->SYSTCKCAL = sysCalVal;
  347. }
  348. /**
  349. * @brief Set System IRQ latency
  350. * @param latency : Latency in clock ticks
  351. * @return Nothing
  352. * @note Sets the IRQ latency, a value between 0 and 255 clocks. Lower
  353. * values allow better latency
  354. */
  355. STATIC INLINE void Chip_SYSCTL_SetIRQLatency(uint32_t latency)
  356. {
  357. LPC_SYSCTL->IRQLATENCY = latency;
  358. }
  359. /**
  360. * @brief Get System IRQ latency value
  361. * @return IRQ Latency in clock ticks
  362. */
  363. STATIC INLINE uint32_t Chip_SYSCTL_GetIRQLatency(void)
  364. {
  365. return LPC_SYSCTL->IRQLATENCY & ~SYSCTL_IRQLATENCY_RESERVED;
  366. }
  367. /**
  368. * @brief Set source for non-maskable interrupt (NMI)
  369. * @param intsrc : IRQ number to assign to the NMI
  370. * @return Nothing
  371. * @note The NMI source will be disabled upon exiting this function. Use the
  372. * Chip_SYSCTL_EnableNMISource() function to enable the NMI source
  373. */
  374. STATIC INLINE void Chip_SYSCTL_SetNMISource(uint32_t intsrc)
  375. {
  376. /* Disable NMI first */
  377. LPC_SYSCTL->NMISRC &= ~(SYSCTL_NMISRC_ENABLE | SYSCTL_NMISRC_RESERVED);
  378. /* Set new NMI source. */
  379. LPC_SYSCTL->NMISRC = intsrc;
  380. }
  381. /**
  382. * @brief Enable interrupt used for NMI source
  383. * @return Nothing
  384. */
  385. STATIC INLINE void Chip_SYSCTL_EnableNMISource(void)
  386. {
  387. LPC_SYSCTL->NMISRC = SYSCTL_NMISRC_ENABLE | (LPC_SYSCTL->NMISRC & ~SYSCTL_NMISRC_RESERVED);
  388. }
  389. /**
  390. * @brief Disable interrupt used for NMI source
  391. * @return Nothing
  392. */
  393. STATIC INLINE void Chip_SYSCTL_DisableNMISource(void)
  394. {
  395. LPC_SYSCTL->NMISRC &= ~(SYSCTL_NMISRC_ENABLE | SYSCTL_NMISRC_RESERVED);
  396. }
  397. /**
  398. * @brief Setup a pin source for the pin interrupts (0-7)
  399. * @param intno : IRQ number
  400. * @param pin : pin number (see comments)
  401. * @return Nothing
  402. * @note For each pin (0-7) that supports an interrupt, the pin number is assigned
  403. * to that interrupt with this function. Values 0-17 map to pins PIO0-0 to
  404. * PIO0-17 (For LPC82X Values from 0-28 could be used for PIO0-28).
  405. */
  406. STATIC INLINE void Chip_SYSCTL_SetPinInterrupt(uint32_t intIndex, uint32_t pinNum)
  407. {
  408. LPC_SYSCTL->PINTSEL[intIndex] = (uint32_t) pinNum;
  409. }
  410. /**
  411. * @brief Enables a pin's (PINT) wakeup logic
  412. * @param pin : pin number
  413. * @return Nothing
  414. * @note Different devices support different pins, see the user manual
  415. * for supported pins
  416. */
  417. STATIC INLINE void Chip_SYSCTL_EnablePINTWakeup(uint32_t pin)
  418. {
  419. LPC_SYSCTL->STARTERP0 = (1 << pin) | (LPC_SYSCTL->STARTERP0 & ~SYSCTL_STARTERP0_RESERVED);
  420. }
  421. /**
  422. * @brief Disables a pin's (PINT) wakeup logic
  423. * @param pin : pin number
  424. * @return Nothing
  425. * @note Different devices support different pins, see the user manual for supported pins.
  426. */
  427. STATIC INLINE void Chip_SYSCTL_DisablePINTWakeup(uint32_t pin)
  428. {
  429. LPC_SYSCTL->STARTERP0 &= ~((1 << pin) | SYSCTL_STARTERP0_RESERVED);
  430. }
  431. /**
  432. * @brief Enables peripheral's wakeup logic
  433. * @param periphmask : OR'ed values of SYSCTL_WAKEUP_* for wakeup
  434. * @return Nothing
  435. */
  436. STATIC INLINE void Chip_SYSCTL_EnablePeriphWakeup(uint32_t periphmask)
  437. {
  438. LPC_SYSCTL->STARTERP1 = periphmask | (LPC_SYSCTL->STARTERP0 & ~SYSCTL_STARTERP0_RESERVED);
  439. }
  440. /**
  441. * @brief Disables peripheral's wakeup logic
  442. * @param periphmask : OR'ed values of SYSCTL_WAKEUP_* for wakeup
  443. * @return Nothing
  444. */
  445. STATIC INLINE void Chip_SYSCTL_DisablePeriphWakeup(uint32_t periphmask)
  446. {
  447. LPC_SYSCTL->STARTERP1 &= ~(periphmask | SYSCTL_STARTERP1_RESERVED);
  448. }
  449. /**
  450. * @brief Returns current deep sleep mask
  451. * @return OR'ed values of SYSCTL_DEEPSLP_* values
  452. * @note A high bit indicates the peripheral will power down on deep sleep.
  453. */
  454. STATIC INLINE uint32_t Chip_SYSCTL_GetDeepSleepPD(void)
  455. {
  456. return LPC_SYSCTL->PDSLEEPCFG;
  457. }
  458. /**
  459. * @brief Return current wakup mask
  460. * @return OR'ed values of SYSCTL_SLPWAKE_* values
  461. * @note A high state indicates the peripehral will powerup on wakeup.
  462. */
  463. STATIC INLINE uint32_t Chip_SYSCTL_GetWakeup(void)
  464. {
  465. return LPC_SYSCTL->PDAWAKECFG;
  466. }
  467. /**
  468. * @brief Power up one or more blocks or peripherals
  469. * @return OR'ed values of SYSCTL_SLPWAKE_* values
  470. * @note A high state indicates the peripheral is powered down.
  471. */
  472. STATIC INLINE uint32_t Chip_SYSCTL_GetPowerStates(void)
  473. {
  474. return LPC_SYSCTL->PDRUNCFG;
  475. }
  476. /**
  477. * @brief Return the device ID
  478. * @return Device ID
  479. */
  480. STATIC INLINE uint32_t Chip_SYSCTL_GetDeviceID(void)
  481. {
  482. return LPC_SYSCTL->DEVICEID;
  483. }
  484. /**
  485. * @brief Setup deep sleep behaviour for power down
  486. * @param sleepmask : OR'ed values of SYSCTL_DEEPSLP_* values (high to powerdown on deepsleep)
  487. * @return Nothing
  488. * @note This must be setup prior to using deep sleep. See the user manual
  489. * *(PDSLEEPCFG register) for more info on setting this up. This function selects
  490. * which peripherals are powered down on deep sleep.
  491. * This function should only be called once with all options for power-down
  492. * in that call
  493. */
  494. void Chip_SYSCTL_SetDeepSleepPD(uint32_t sleepmask);
  495. /**
  496. * @brief Setup wakeup behaviour from deep sleep
  497. * @param wakeupmask : OR'ed values of SYSCTL_SLPWAKE_* values (high is powered down)
  498. * @return Nothing
  499. * @note This must be setup prior to using deep sleep. See the user manual
  500. * *(PDWAKECFG register) for more info on setting this up. This function selects
  501. * which peripherals are powered up on exit from deep sleep.
  502. * This function should only be called once with all options for wakeup
  503. * in that call
  504. */
  505. void Chip_SYSCTL_SetWakeup(uint32_t wakeupmask);
  506. /**
  507. * @brief Power down one or more blocks or peripherals
  508. * @param powerdownmask : OR'ed values of SYSCTL_SLPWAKE_* values
  509. * @return Nothing
  510. */
  511. void Chip_SYSCTL_PowerDown(uint32_t powerdownmask);
  512. /**
  513. * @brief Power up one or more blocks or peripherals
  514. * @param powerupmask : OR'ed values of SYSCTL_SLPWAKE_* values
  515. * @return Nothing
  516. */
  517. void Chip_SYSCTL_PowerUp(uint32_t powerupmask);
  518. /**
  519. * @}
  520. */
  521. #ifdef __cplusplus
  522. }
  523. #endif
  524. #endif /* __SYSCTL_8XX_H_ */