1 /*
2 * @brief Pin Interrupt example
3 *
4 * @note
5 * Copyright(C) NXP Semiconductors, 2013
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
32 #include "board.h"
33 #include "chip.h"
34 #include <stdio.h>
35
36 /*****************************************************************************
37 * Private types/enumerations/variables
38 ****************************************************************************/
39
40 #if defined(BOARD_NXP_LPCXPRESSO_1549)
41 /* GPIO pin for PININT interrupt. This is SW1-WAKE button switch input. */
42 #define TEST_INPUT_PIN 17 /* GPIO pin number mapped to PININT */
43 #define TEST_INPUT_PORT 0 /* GPIO port number mapped to PININT */
44 #define TEST_INPUT_PIN_PORT 0
45 #define TEST_INPUT_PIN_BIT 17
46 #define PININT_INDEX 0 /* PININT index used for GPIO mapping */
47 #define PININT_IRQ_HANDLER PIN_INT0_IRQHandler /* GPIO interrupt IRQ function name */
48 #define PININT_NVIC_NAME PIN_INT0_IRQn /* GPIO interrupt NVIC interrupt name */
49
50 #else
51 #error "PININT Interrupt not configured for this example"
52 #endif /* defined(BOARD_NXP_LPCXPRESSO_1549) */
53
54 /*****************************************************************************
55 * Public types/enumerations/variables
56 ****************************************************************************/
57
58 /*****************************************************************************
59 * Private functions
60 ****************************************************************************/
61
62 /*****************************************************************************
63 * Public functions
64 ****************************************************************************/
65
66 /**
67 * @brief Handle interrupt from GPIO pin or GPIO pin mapped to PININT
68 * @return Nothing
69 */
PININT_IRQ_HANDLER(void)70 void PININT_IRQ_HANDLER(void)
71 {
72 Chip_PININT_ClearIntStatus(LPC_GPIO_PIN_INT, PININTCH(PININT_INDEX));
73 Board_LED_Toggle(0);
74 }
75
76 /**
77 * @brief Main program body
78 * @return Does not return
79 */
main(void)80 int main(void)
81 {
82 SystemCoreClockUpdate();
83 Board_Init();
84 Board_LED_Set(0, false);
85
86 /* Initialize PININT driver */
87 Chip_PININT_Init(LPC_GPIO_PIN_INT);
88
89 /* Set pin back to GPIO (on some boards may have been changed to something
90 else by Board_Init()) */
91 Chip_IOCON_PinMuxSet(LPC_IOCON, TEST_INPUT_PIN_PORT, TEST_INPUT_PIN_BIT,
92 (IOCON_DIGMODE_EN | IOCON_MODE_INACT) );
93
94 /* Configure GPIO pin as input */
95 Chip_GPIO_SetPinDIRInput(LPC_GPIO, TEST_INPUT_PORT, TEST_INPUT_PIN);
96
97 /* Enable PININT clock */
98 Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_PININT);
99
100 /* Reset the PININT block */
101 Chip_SYSCTL_PeriphReset(RESET_PININT);
102
103 /* Configure interrupt channel for the GPIO pin in INMUX block */
104 Chip_INMUX_PinIntSel(PININT_INDEX, TEST_INPUT_PORT, TEST_INPUT_PIN);
105
106 /* Configure channel interrupt as edge sensitive and falling edge interrupt */
107 Chip_PININT_ClearIntStatus(LPC_GPIO_PIN_INT, PININTCH(PININT_INDEX));
108 Chip_PININT_SetPinModeEdge(LPC_GPIO_PIN_INT, PININTCH(PININT_INDEX));
109 Chip_PININT_EnableIntLow(LPC_GPIO_PIN_INT, PININTCH(PININT_INDEX));
110
111 /* Enable interrupt in the NVIC */
112 NVIC_ClearPendingIRQ(PININT_NVIC_NAME);
113 NVIC_EnableIRQ(PININT_NVIC_NAME);
114
115 /* Spin in a loop here. All the work is done in ISR. */
116 while (1) {}
117
118 return 0;
119 }
120