Contiki 3.x
nvic.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012, Texas Instruments Incorporated - http://www.ti.com/
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  *
14  * 3. Neither the name of the copyright holder nor the names of its
15  * contributors may be used to endorse or promote products derived
16  * from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
29  * OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 /**
32  * \addtogroup cc2538
33  * @{
34  *
35  * \defgroup cc2538-nvic cc2538 Nested Vectored Interrupt Controller
36  *
37  * Driver for the cc2538 NVIC controller
38  * @{
39  *
40  * \file
41  * Header file for the ARM Nested Vectored Interrupt Controller
42  */
43 #ifndef NVIC_H_
44 #define NVIC_H_
45 
46 #include <stdint.h>
47 /*---------------------------------------------------------------------------*/
48 /** \name NVIC Constants and Configuration
49  * @{
50  */
51 #define NVIC_INTERRUPT_ENABLED 0x00000001
52 #define NVIC_INTERRUPT_DISABLED 0x00000000
53 
54 #ifdef NVIC_CONF_VTABLE_ADDRESS
55 #define NVIC_VTABLE_ADDRESS NVIC_CONF_VTABLE_ADDRESS
56 #else
57 extern void(*const vectors[])(void);
58 #define NVIC_VTABLE_ADDRESS ((uint32_t)&vectors)
59 #endif
60 /** @} */
61 /*---------------------------------------------------------------------------*/
62 /** \name NVIC Interrupt assignments
63  * @{
64  */
65 #define NVIC_INT_GPIO_PORT_A 0 /**< GPIO port A */
66 #define NVIC_INT_GPIO_PORT_B 1 /**< GPIO port B */
67 #define NVIC_INT_GPIO_PORT_C 2 /**< GPIO port C */
68 #define NVIC_INT_GPIO_PORT_D 3 /**< GPIO port D */
69 #define NVIC_INT_UART0 5 /**< UART0 */
70 #define NVIC_INT_UART1 6 /**< UART1 */
71 #define NVIC_INT_SSI0 7 /**< SSI0 */
72 #define NVIC_INT_I2C 8 /**< I2C */
73 #define NVIC_INT_ADC 14 /**< ADC */
74 #define NVIC_INT_WDT 18 /**< Watchdog Timer */
75 #define NVIC_INT_GPTIMER_0A 19 /**< GPTimer 0A */
76 #define NVIC_INT_GPTIMER_0B 20 /**< GPTimer 0B */
77 #define NVIC_INT_GPTIMER_1A 21 /**< GPTimer 1A */
78 #define NVIC_INT_GPTIMER_1B 22 /**< GPTimer 1B */
79 #define NVIC_INT_GPTIMER_2A 23 /**< GPTimer 2A */
80 #define NVIC_INT_GPTIMER_2B 24 /**< GPTimer 2B */
81 #define NVIC_INT_ADC_CMP 25 /**< Analog Comparator */
82 #define NVIC_INT_RF_RXTX_ALT 26 /**< RF TX/RX (Alternate) */
83 #define NVIC_INT_RF_ERR_ALT 27 /**< RF Error (Alternate) */
84 #define NVIC_INT_SYS_CTRL 28 /**< System Control */
85 #define NVIC_INT_FLASH_CTRL 29 /**< Flash memory control */
86 #define NVIC_INT_AES_ALT 30 /**< AES (Alternate) */
87 #define NVIC_INT_PKA_ALT 31 /**< PKA (Alternate) */
88 #define NVIC_INT_SM_TIMER_ALT 32 /**< SM Timer (Alternate) */
89 #define NVIC_INT_MAC_TIMER_ALT 33 /**< MAC Timer (Alternate) */
90 #define NVIC_INT_SSI1 34 /**< SSI1 */
91 #define NVIC_INT_GPTIMER_3A 35 /**< GPTimer 3A */
92 #define NVIC_INT_GPTIMER_3B 36 /**< GPTimer 3B */
93 #define NVIC_INT_UDMA 46 /**< uDMA software */
94 #define NVIC_INT_UDMA_ERR 47 /**< uDMA error */
95 #define NVIC_INT_USB 140 /**< USB */
96 #define NVIC_INT_RF_RXTX 141 /**< RF Core Rx/Tx */
97 #define NVIC_INT_RF_ERR 142 /**< RF Core Error */
98 #define NVIC_INT_AES 143 /**< AES */
99 #define NVIC_INT_PKA 144 /**< PKA */
100 #define NVIC_INT_SM_TIMER 145 /**< SM Timer */
101 #define NVIC_INT_MACTIMER 146 /**< MAC Timer */
102 /** @} */
103 /*---------------------------------------------------------------------------*/
104 /** \name NVIC Register Declarations
105  * @{
106  */
107 #define NVIC_EN0 0xE000E100 /**< Interrupt 0-31 Set Enable */
108 #define NVIC_EN1 0xE000E104 /**< Interrupt 32-54 Set Enable */
109 #define NVIC_EN2 0xE000E108 /**< Interrupt 64-95 Set Enable */
110 #define NVIC_EN3 0xE000E10C /**< Interrupt 96-127 Set Enable */
111 #define NVIC_EN4 0xE000E110 /**< Interrupt 128-131 Set Enable */
112 #define NVIC_DIS0 0xE000E180 /**< Interrupt 0-31 Clear Enable */
113 #define NVIC_DIS1 0xE000E184 /**< Interrupt 32-54 Clear Enable */
114 #define NVIC_DIS2 0xE000E188 /**< Interrupt 64-95 Clear Enable */
115 #define NVIC_DIS3 0xE000E18C /**< Interrupt 96-127 Clear Enable */
116 #define NVIC_DIS4 0xE000E190 /**< Interrupt 128-131 Clear Enable */
117 #define NVIC_PEND0 0xE000E200 /**< Interrupt 0-31 Set Pending */
118 #define NVIC_PEND1 0xE000E204 /**< Interrupt 32-54 Set Pending */
119 #define NVIC_PEND2 0xE000E208 /**< Interrupt 64-95 Set Pending */
120 #define NVIC_PEND3 0xE000E20C /**< Interrupt 96-127 Set Pending */
121 #define NVIC_PEND4 0xE000E210 /**< Interrupt 128-131 Set Pending */
122 #define NVIC_UNPEND0 0xE000E280 /**< Interrupt 0-31 Clear Pending */
123 #define NVIC_UNPEND1 0xE000E284 /**< Interrupt 32-54 Clear Pending */
124 #define NVIC_UNPEND2 0xE000E288 /**< Interrupt 64-95 Clear Pending */
125 #define NVIC_UNPEND3 0xE000E28C /**< Interrupt 96-127 Clear Pending */
126 #define NVIC_UNPEND4 0xE000E290 /**< Interrupt 128-131 Clear Pending */
127 #define NVIC_ACTIVE0 0xE000E300 /**< Interrupt 0-31 Active Bit */
128 #define NVIC_ACTIVE1 0xE000E304 /**< Interrupt 32-54 Active Bit */
129 #define NVIC_ACTIVE2 0xE000E308 /**< Interrupt 64-95 Active Bit */
130 #define NVIC_ACTIVE3 0xE000E30C /**< Interrupt 96-127 Active Bit */
131 #define NVIC_ACTIVE4 0xE000E310 /**< Interrupt 128-131 Active Bit */
132 #define NVIC_PRI0 0xE000E400 /**< Interrupt 0-3 Priority */
133 #define NVIC_PRI1 0xE000E404 /**< Interrupt 4-7 Priority */
134 #define NVIC_PRI2 0xE000E408 /**< Interrupt 8-11 Priority */
135 #define NVIC_PRI3 0xE000E40C /**< Interrupt 12-15 Priority */
136 #define NVIC_PRI4 0xE000E410 /**< Interrupt 16-19 Priority */
137 #define NVIC_PRI5 0xE000E414 /**< Interrupt 20-23 Priority */
138 #define NVIC_PRI6 0xE000E418 /**< Interrupt 24-27 Priority */
139 #define NVIC_PRI7 0xE000E41C /**< Interrupt 28-31 Priority */
140 #define NVIC_PRI8 0xE000E420 /**< Interrupt 32-35 Priority */
141 #define NVIC_PRI9 0xE000E424 /**< Interrupt 36-39 Priority */
142 #define NVIC_PRI10 0xE000E428 /**< Interrupt 40-43 Priority */
143 #define NVIC_PRI11 0xE000E42C /**< Interrupt 44-47 Priority */
144 #define NVIC_PRI12 0xE000E430 /**< Interrupt 48-51 Priority */
145 #define NVIC_PRI13 0xE000E434 /**< Interrupt 52-53 Priority */
146 #define NVIC_PRI14 0xE000E438 /**< Interrupt 56-59 Priority */
147 #define NVIC_PRI15 0xE000E43C /**< Interrupt 60-63 Priority */
148 #define NVIC_PRI16 0xE000E440 /**< Interrupt 64-67 Priority */
149 #define NVIC_PRI17 0xE000E444 /**< Interrupt 68-71 Priority */
150 #define NVIC_PRI18 0xE000E448 /**< Interrupt 72-75 Priority */
151 #define NVIC_PRI19 0xE000E44C /**< Interrupt 76-79 Priority */
152 #define NVIC_PRI20 0xE000E450 /**< Interrupt 80-83 Priority */
153 #define NVIC_PRI21 0xE000E454 /**< Interrupt 84-87 Priority */
154 #define NVIC_PRI22 0xE000E458 /**< Interrupt 88-91 Priority */
155 #define NVIC_PRI23 0xE000E45C /**< Interrupt 92-95 Priority */
156 #define NVIC_PRI24 0xE000E460 /**< Interrupt 96-99 Priority */
157 #define NVIC_PRI25 0xE000E464 /**< Interrupt 100-103 Priority */
158 #define NVIC_PRI26 0xE000E468 /**< Interrupt 104-107 Priority */
159 #define NVIC_PRI27 0xE000E46C /**< Interrupt 108-111 Priority */
160 #define NVIC_PRI28 0xE000E470 /**< Interrupt 112-115 Priority */
161 #define NVIC_PRI29 0xE000E474 /**< Interrupt 116-119 Priority */
162 #define NVIC_PRI30 0xE000E478 /**< Interrupt 120-123 Priority */
163 #define NVIC_PRI31 0xE000E47C /**< Interrupt 124-127 Priority */
164 #define NVIC_PRI32 0xE000E480 /**< Interrupt 128-131 Priority */
165 #define NVIC_PRI33 0xE000E480 /**< Interrupt 132-135 Priority */
166 #define NVIC_PRI34 0xE000E484 /**< Interrupt 136-139 Priority */
167 #define NVIC_PRI35 0xE000E488 /**< Interrupt 140-143 Priority */
168 #define NVIC_PRI36 0xE000E48c /**< Interrupt 144-147 Priority */
169 /** @} */
170 /*---------------------------------------------------------------------------*/
171 /** \brief Initialises the NVIC driver */
172 void nvic_init();
173 
174 /**
175  * \brief Enables interrupt intr
176  * \param intr The interrupt number (NOT the vector number). For example,
177  * GPIO Port A interrupt is 0, not 16.
178  *
179  * Possible values for the \e intr param are defined as NVIC_INT_xyz. For
180  * instance, to enable the GPIO Port A interrupt, pass NVIC_INT_GPIO_PORT_A
181  */
182 void nvic_interrupt_enable(uint32_t intr);
183 
184 /**
185  * \brief Disables interrupt intr
186  * \param intr The interrupt number (NOT the vector number). For example,
187  * GPIO Port A interrupt is 0, not 16.
188  *
189  * Possible values for the \e intr param are defined as NVIC_INT_xyz. For
190  * instance, to disable the GPIO Port A interrupt, pass NVIC_INT_GPIO_PORT_A
191  */
192 void nvic_interrupt_disable(uint32_t intr);
193 
194 /**
195  * \brief Enables interrupt intr if v > 0
196  * \param intr The interrupt number (NOT the vector number). For example,
197  * GPIO Port A interrupt is 0, not 16.
198  * \param v 0: No effect, 1: Enables the interrupt
199  *
200  * This function is useful to restore an interrupt to a state previously
201  * saved by nvic_interrupt_en_save. Thus, if when nvic_interrupt_en_save was
202  * called the interrupt was enabled, this function will re-enabled it.
203  * Possible values for the \e intr param are defined as NVIC_INT_xyz. For
204  * instance, to disable the GPIO Port A interrupt, pass NVIC_INT_GPIO_PORT_A
205  */
206 void nvic_interrupt_en_restore(uint32_t intr, uint8_t v);
207 
208 /**
209  * \brief Checks the interrupt enabled status for intr
210  * \param intr The interrupt number (NOT the vector number). For example,
211  * GPIO Port A interrupt is 0, not 16.
212  * \return 1: Enabled, 0: Disabled
213  *
214  * Possible values for the \e intr param are defined as NVIC_INT_xyz. For
215  * instance, to disable the GPIO Port A interrupt, pass NVIC_INT_GPIO_PORT_A
216  */
217 uint8_t nvic_interrupt_en_save(uint32_t intr);
218 
219 /**
220  * \brief Sets intr to pending
221  * \param intr The interrupt number (NOT the vector number). For example,
222  * GPIO Port A interrupt is 0, not 16.
223  *
224  * Possible values for the \e intr param are defined as NVIC_INT_xyz. For
225  * instance, to enable the GPIO Port A interrupt, pass NVIC_INT_GPIO_PORT_A
226  */
227 void nvic_interrupt_pend(uint32_t intr);
228 
229 /**
230  * \brief Sets intr to no longer pending
231  * \param intr The interrupt number (NOT the vector number). For example,
232  * GPIO Port A interrupt is 0, not 16.
233  *
234  * Possible values for the \e intr param are defined as NVIC_INT_xyz. For
235  * instance, to disable the GPIO Port A interrupt, pass NVIC_INT_GPIO_PORT_A
236  */
237 void nvic_interrupt_unpend(uint32_t intr);
238 
239 #endif /* NVIC_H_ */
240 
241 /**
242  * @}
243  * @}
244  */
void nvic_init()
Initialises the NVIC driver.
Definition: nvic.c:52
void nvic_interrupt_unpend(uint32_t intr)
Sets intr to no longer pending.
Definition: nvic.c:106
uint8_t nvic_interrupt_en_save(uint32_t intr)
Checks the interrupt enabled status for intr.
Definition: nvic.c:88
void nvic_interrupt_pend(uint32_t intr)
Sets intr to pending.
Definition: nvic.c:99
void nvic_interrupt_enable(uint32_t intr)
Enables interrupt intr.
Definition: nvic.c:64
void nvic_interrupt_disable(uint32_t intr)
Disables interrupt intr.
Definition: nvic.c:71
void nvic_interrupt_en_restore(uint32_t intr, uint8_t v)
Enables interrupt intr if v > 0.
Definition: nvic.c:78