pinint_8xx.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. /*
  2. * @brief LPC8xx Pin Interrupt and Pattern Match Registers and driver
  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 __PININT_8XX_H_
  32. #define __PININT_8XX_H_
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. /** @defgroup PININT_8XX CHIP: LPC8xx Pin Interrupt and Pattern Match driver
  37. * @ingroup CHIP_8XX_Drivers
  38. * @{
  39. */
  40. /**
  41. * @brief LPC8xx Pin Interrupt and Pattern Match register block structure
  42. */
  43. typedef struct { /*!< (@ 0xA0004000) PIN_INT Structure */
  44. __IO uint32_t ISEL; /*!< (@ 0xA0004000) Pin Interrupt Mode register */
  45. __IO uint32_t IENR; /*!< (@ 0xA0004004) Pin Interrupt Enable (Rising) register */
  46. __IO uint32_t SIENR; /*!< (@ 0xA0004008) Set Pin Interrupt Enable (Rising) register */
  47. __IO uint32_t CIENR; /*!< (@ 0xA000400C) Clear Pin Interrupt Enable (Rising) register */
  48. __IO uint32_t IENF; /*!< (@ 0xA0004010) Pin Interrupt Enable Falling Edge / Active Level register */
  49. __IO uint32_t SIENF; /*!< (@ 0xA0004014) Set Pin Interrupt Enable Falling Edge / Active Level register */
  50. __IO uint32_t CIENF; /*!< (@ 0xA0004018) Clear Pin Interrupt Enable Falling Edge / Active Level address */
  51. __IO uint32_t RISE; /*!< (@ 0xA000401C) Pin Interrupt Rising Edge register */
  52. __IO uint32_t FALL; /*!< (@ 0xA0004020) Pin Interrupt Falling Edge register */
  53. __IO uint32_t IST; /*!< (@ 0xA0004024) Pin Interrupt Status register */
  54. __IO uint32_t PMCTRL; /*!< (@ 0xA0004028) GPIO pattern match interrupt control register */
  55. __IO uint32_t PMSRC; /*!< (@ 0xA000402C) GPIO pattern match interrupt bit-slice source register */
  56. __IO uint32_t PMCFG; /*!< (@ 0xA0004030) GPIO pattern match interrupt bit slice configuration register */
  57. } LPC_PININT_T;
  58. /* Reserved bits masks for registers */
  59. #define PININT_ISEL_RESERVED (~0xff)
  60. #define PININT_IENR_RESERVED (~0xff)
  61. #define PININT_SIENR_RESERVED (~0xff)
  62. #define PININT_CIENR_RESERVED (~0xff)
  63. #define PININT_IENF_RESERVED (~0xff)
  64. #define PININT_SIENF_RESERVED (~0xff)
  65. #define PININT_CIENF_RESERVED (~0xff)
  66. #define PININT_RISE_RESERVED (~0xff)
  67. #define PININT_FALL_RESERVED (~0xff)
  68. #define PININT_IST_RESERVED (~0xff)
  69. #define PININT_PMCTRL_RESERVED (~0xff000003)
  70. #define PININT_PMSRC_RESERVED 0xff
  71. #define PININT_PMCFG_RESERVED (1<<7)
  72. /**
  73. * LPC8xx Pin Interrupt and Pattern match engine register
  74. * bit fields and macros
  75. */
  76. /* PININT interrupt control register */
  77. #define PININT_PMCTRL_PMATCH_SEL (1 << 0)
  78. #define PININT_PMCTRL_RXEV_ENA (1 << 1)
  79. /* PININT Bit slice source register bits */
  80. #define PININT_SRC_BITSOURCE_START 8
  81. #define PININT_SRC_BITSOURCE_MASK 7
  82. /* PININT Bit slice configuration register bits */
  83. #define PININT_SRC_BITCFG_START 8
  84. #define PININT_SRC_BITCFG_MASK 7
  85. /**
  86. * LPC8xx Pin Interrupt channel values
  87. */
  88. #define PININTCH0 (1 << 0)
  89. #define PININTCH1 (1 << 1)
  90. #define PININTCH2 (1 << 2)
  91. #define PININTCH3 (1 << 3)
  92. #define PININTCH4 (1 << 4)
  93. #define PININTCH5 (1 << 5)
  94. #define PININTCH6 (1 << 6)
  95. #define PININTCH7 (1 << 7)
  96. #define PININTCH(ch) (1 << (ch))
  97. /**
  98. * LPC8xx Pin Matching Interrupt bit slice enum values
  99. */
  100. typedef enum Chip_PININT_BITSLICE {
  101. PININTBITSLICE0 = 0, /*!< PININT Bit slice 0 */
  102. PININTBITSLICE1 = 1, /*!< PININT Bit slice 1 */
  103. PININTBITSLICE2 = 2, /*!< PININT Bit slice 2 */
  104. PININTBITSLICE3 = 3, /*!< PININT Bit slice 3 */
  105. PININTBITSLICE4 = 4, /*!< PININT Bit slice 4 */
  106. PININTBITSLICE5 = 5, /*!< PININT Bit slice 5 */
  107. PININTBITSLICE6 = 6, /*!< PININT Bit slice 6 */
  108. PININTBITSLICE7 = 7 /*!< PININT Bit slice 7 */
  109. } Chip_PININT_BITSLICE_T;
  110. /**
  111. * LPC8xx Pin Matching Interrupt bit slice configuration enum values
  112. */
  113. typedef enum Chip_PININT_BITSLICE_CFG {
  114. PININT_PATTERNCONST1 = 0x0, /*!< Contributes to product term match */
  115. PININT_PATTERNRISING = 0x1, /*!< Rising edge */
  116. PININT_PATTERNFALLING = 0x2, /*!< Falling edge */
  117. PININT_PATTERNRISINGRFALLING = 0x3, /*!< Rising or Falling edge */
  118. PININT_PATTERNHIGH = 0x4, /*!< High level */
  119. PININT_PATTERNLOW = 0x5, /*!< Low level */
  120. PININT_PATTERCONST0 = 0x6, /*!< Never contributes for match */
  121. PININT_PATTEREVENT = 0x7 /*!< Match occurs on event */
  122. } Chip_PININT_BITSLICE_CFG_T;
  123. /**
  124. * @brief Initialize Pin interrupt block
  125. * @param pPININT : The base address of Pin interrupt block
  126. * @return Nothing
  127. * @note This function should be used after the Chip_GPIO_Init() function.
  128. */
  129. STATIC INLINE void Chip_PININT_Init(LPC_PININT_T *pPININT) {}
  130. /**
  131. * @brief De-Initialize Pin interrupt block
  132. * @param pPININT : The base address of Pin interrupt block
  133. * @return Nothing
  134. */
  135. STATIC INLINE void Chip_PININT_DeInit(LPC_PININT_T *pPININT) {}
  136. /**
  137. * @brief Configure the pins as edge sensitive in Pin interrupt block
  138. * @param pPININT : The base address of Pin interrupt block
  139. * @param pins : Pins (ORed value of PININTCH*)
  140. * @return Nothing
  141. */
  142. STATIC INLINE void Chip_PININT_SetPinModeEdge(LPC_PININT_T *pPININT, uint32_t pins)
  143. {
  144. pPININT->ISEL &= ~(pins | PININT_ISEL_RESERVED);
  145. }
  146. /**
  147. * @brief Configure the pins as level sensitive in Pin interrupt block
  148. * @param pPININT : The base address of Pin interrupt block
  149. * @param pins : Pins (ORed value of PININTCH*)
  150. * @return Nothing
  151. */
  152. STATIC INLINE void Chip_PININT_SetPinModeLevel(LPC_PININT_T *pPININT, uint32_t pins)
  153. {
  154. pPININT->ISEL = pins | (pPININT->ISEL & ~PININT_ISEL_RESERVED);
  155. pPININT->SIENR = pins;
  156. }
  157. /**
  158. * @brief Return current PININT rising edge or high level interrupt enable state
  159. * @param pPININT : The base address of Pin interrupt block
  160. * @return A bifield containing the high edge/level interrupt enables for each
  161. * interrupt. Bit 0 = PININT0, 1 = PININT1, etc.
  162. * For each bit, a 0 means the high edge/level interrupt is disabled, while a 1
  163. * means it's enabled.
  164. */
  165. STATIC INLINE uint32_t Chip_PININT_GetHighEnabled(LPC_PININT_T *pPININT)
  166. {
  167. return pPININT->IENR & ~PININT_IENR_RESERVED;
  168. }
  169. /**
  170. * @brief Enable high edge/level PININT interrupts for pins
  171. * @param pPININT : The base address of Pin interrupt block
  172. * @param pins : Pins to enable (ORed value of PININTCH*)
  173. * @return Nothing
  174. */
  175. STATIC INLINE void Chip_PININT_EnableIntHigh(LPC_PININT_T *pPININT, uint32_t pins)
  176. {
  177. pPININT->SIENR = pins;
  178. }
  179. /**
  180. * @brief Select high/low level for level sensitive PININT interrupts
  181. * @param pPININT : The base address of Pin interrupt block
  182. * @param pins : Pins to enable (ORed value of PININTCH*)
  183. * @return Nothing
  184. */
  185. STATIC INLINE void Chip_PININT_SelectLevel(LPC_PININT_T *pPININT, uint32_t pins, bool isHigh)
  186. {
  187. if (isHigh)
  188. pPININT->SIENF = pins;
  189. else
  190. pPININT->CIENF = pins;
  191. }
  192. /**
  193. * @brief Disable high edge/level PININT interrupts for pins
  194. * @param pPININT : The base address of Pin interrupt block
  195. * @param pins : Pins to disable (ORed value of PININTCH*)
  196. * @return Nothing
  197. */
  198. STATIC INLINE void Chip_PININT_DisableIntHigh(LPC_PININT_T *pPININT, uint32_t pins)
  199. {
  200. pPININT->CIENR = pins;
  201. }
  202. /**
  203. * @brief Return current PININT falling edge or low level interrupt enable state
  204. * @param pPININT : The base address of Pin interrupt block
  205. * @return A bifield containing the low edge/level interrupt enables for each
  206. * interrupt. Bit 0 = PININT0, 1 = PININT1, etc.
  207. * For each bit, a 0 means the low edge/level interrupt is disabled, while a 1
  208. * means it's enabled.
  209. */
  210. STATIC INLINE uint32_t Chip_PININT_GetLowEnabled(LPC_PININT_T *pPININT)
  211. {
  212. return pPININT->IENF & ~PININT_IENF_RESERVED;
  213. }
  214. /**
  215. * @brief Enable low edge/level PININT interrupts for pins
  216. * @param pPININT : The base address of Pin interrupt block
  217. * @param pins : Pins to enable (ORed value of PININTCH*)
  218. * @return Nothing
  219. */
  220. STATIC INLINE void Chip_PININT_EnableIntLow(LPC_PININT_T *pPININT, uint32_t pins)
  221. {
  222. pPININT->SIENF = pins;
  223. }
  224. /**
  225. * @brief Disable low edge/level PININT interrupts for pins
  226. * @param pPININT : The base address of Pin interrupt block
  227. * @param pins : Pins to disable (ORed value of PININTCH*)
  228. * @return Nothing
  229. */
  230. STATIC INLINE void Chip_PININT_DisableIntLow(LPC_PININT_T *pPININT, uint32_t pins)
  231. {
  232. pPININT->CIENF = pins;
  233. }
  234. /**
  235. * @brief Return pin states that have a detected latched high edge (RISE) state
  236. * @param pPININT : The base address of Pin interrupt block
  237. * @return PININT states (bit n = high) with a latched rise state detected
  238. */
  239. STATIC INLINE uint32_t Chip_PININT_GetRiseStates(LPC_PININT_T *pPININT)
  240. {
  241. return pPININT->RISE & ~PININT_RISE_RESERVED;
  242. }
  243. /**
  244. * @brief Clears pin states that had a latched high edge (RISE) state
  245. * @param pPININT : The base address of Pin interrupt block
  246. * @param pins : Pins with latched states to clear
  247. * @return Nothing
  248. */
  249. STATIC INLINE void Chip_PININT_ClearRiseStates(LPC_PININT_T *pPININT, uint32_t pins)
  250. {
  251. pPININT->RISE = pins;
  252. }
  253. /**
  254. * @brief Return pin states that have a detected latched falling edge (FALL) state
  255. * @param pPININT : The base address of Pin interrupt block
  256. * @return PININT states (bit n = high) with a latched rise state detected
  257. */
  258. STATIC INLINE uint32_t Chip_PININT_GetFallStates(LPC_PININT_T *pPININT)
  259. {
  260. return pPININT->FALL & ~PININT_FALL_RESERVED;
  261. }
  262. /**
  263. * @brief Clears pin states that had a latched falling edge (FALL) state
  264. * @param pPININT : The base address of Pin interrupt block
  265. * @param pins : Pins with latched states to clear
  266. * @return Nothing
  267. */
  268. STATIC INLINE void Chip_PININT_ClearFallStates(LPC_PININT_T *pPININT, uint32_t pins)
  269. {
  270. pPININT->FALL = pins;
  271. }
  272. /**
  273. * @brief Get interrupt status from Pin interrupt block
  274. * @param pPININT : The base address of Pin interrupt block
  275. * @return Interrupt status (bit n for PININTn = high means interrupt ie pending)
  276. */
  277. STATIC INLINE uint32_t Chip_PININT_GetIntStatus(LPC_PININT_T *pPININT)
  278. {
  279. return pPININT->IST& ~PININT_IST_RESERVED;
  280. }
  281. /**
  282. * @brief Clear interrupt status in Pin interrupt block
  283. * @param pPININT : The base address of Pin interrupt block
  284. * @param pins : Pin interrupts to clear (ORed value of PININTCH*)
  285. * @return Nothing
  286. */
  287. STATIC INLINE void Chip_PININT_ClearIntStatus(LPC_PININT_T *pPININT, uint32_t pins)
  288. {
  289. pPININT->IST = pins;
  290. }
  291. /**
  292. * @brief Set source for pattern match in Pin interrupt block
  293. * @param pPININT : The base address of Pin interrupt block
  294. * @param chan : PININT channel number (From 0 to 7)
  295. * @param slice : PININT slice number
  296. * @return Nothing
  297. */
  298. void Chip_PININT_SetPatternMatchSrc(LPC_PININT_T *pPININT, uint8_t chan, Chip_PININT_BITSLICE_T slice);
  299. /**
  300. * @brief Configure the pattern matcch in Pin interrupt block
  301. * @param pPININT : The base address of Pin interrupt block
  302. * @param slice : PININT slice number
  303. * @param slice_cfg : PININT slice configuration value (enum Chip_PININT_BITSLICE_CFG_T)
  304. * @param end_point : If true, current slice is final component
  305. * @return Nothing
  306. */
  307. void Chip_PININT_SetPatternMatchConfig(LPC_PININT_T *pPININT, Chip_PININT_BITSLICE_T slice,
  308. Chip_PININT_BITSLICE_CFG_T slice_cfg, bool end_point);
  309. /**
  310. * @brief Enable pattern match interrupts in Pin interrupt block
  311. * @param pPININT : The base address of Pin interrupt block
  312. * @return Nothing
  313. */
  314. STATIC INLINE void Chip_PININT_EnablePatternMatch(LPC_PININT_T *pPININT)
  315. {
  316. pPININT->PMCTRL = PININT_PMCTRL_PMATCH_SEL | (pPININT->PMCTRL & ~PININT_PMCTRL_RESERVED);
  317. }
  318. /**
  319. * @brief Disable pattern match interrupts in Pin interrupt block
  320. * @param pPININT : The base address of Pin interrupt block
  321. * @return Nothing
  322. */
  323. STATIC INLINE void Chip_PININT_DisablePatternMatch(LPC_PININT_T *pPININT)
  324. {
  325. pPININT->PMCTRL &= ~(PININT_PMCTRL_PMATCH_SEL | PININT_PMCTRL_RESERVED);
  326. }
  327. /**
  328. * @brief Enable RXEV output in Pin interrupt block
  329. * @param pPININT : The base address of Pin interrupt block
  330. * @return Nothing
  331. */
  332. STATIC INLINE void Chip_PININT_EnablePatternMatchRxEv(LPC_PININT_T *pPININT)
  333. {
  334. pPININT->PMCTRL = PININT_PMCTRL_RXEV_ENA | (pPININT->PMCTRL & ~PININT_PMCTRL_RESERVED);
  335. }
  336. /**
  337. * @brief Disable RXEV output in Pin interrupt block
  338. * @param pPININT : The base address of Pin interrupt block
  339. * @return Nothing
  340. */
  341. STATIC INLINE void Chip_PININT_DisablePatternMatchRxEv(LPC_PININT_T *pPININT)
  342. {
  343. pPININT->PMCTRL &= ~(PININT_PMCTRL_RXEV_ENA | PININT_PMCTRL_RESERVED);
  344. }
  345. /**
  346. * @}
  347. */
  348. #ifdef __cplusplus
  349. }
  350. #endif
  351. #endif /* __PININT_8XX_H_ */