pinint_5410x.h 14 KB

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