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_VTABLE_IN_SRAM 0x20000000
52 #define NVIC_VTABLE_IN_CODE 0x00000000
53 
54 #define NVIC_INTERRUPT_ENABLED 0x00000001
55 #define NVIC_INTERRUPT_DISABLED 0x00000000
56 
57 #ifndef NVIC_CONF_VTABLE_BASE
58 #define NVIC_CONF_VTABLE_BASE NVIC_VTABLE_IN_CODE
59 #endif
60 
61 #ifndef NVIC_CONF_VTABLE_OFFSET
62 #define NVIC_CONF_VTABLE_OFFSET 0x200000
63 #endif
64 /** @} */
65 /*---------------------------------------------------------------------------*/
66 /** \name NVIC Interrupt assignments
67  * @{
68  */
69 #define NVIC_INT_GPIO_PORT_A 0 /**< GPIO port A */
70 #define NVIC_INT_GPIO_PORT_B 1 /**< GPIO port B */
71 #define NVIC_INT_GPIO_PORT_C 2 /**< GPIO port C */
72 #define NVIC_INT_GPIO_PORT_D 3 /**< GPIO port D */
73 #define NVIC_INT_UART0 5 /**< UART0 */
74 #define NVIC_INT_UART1 6 /**< UART1 */
75 #define NVIC_INT_SSI0 7 /**< SSI0 */
76 #define NVIC_INT_I2C 8 /**< I2C */
77 #define NVIC_INT_ADC 14 /**< ADC */
78 #define NVIC_INT_WDT 18 /**< Watchdog Timer */
79 #define NVIC_INT_GPTIMER_0A 19 /**< GPTimer 0A */
80 #define NVIC_INT_GPTIMER_0B 20 /**< GPTimer 0B */
81 #define NVIC_INT_GPTIMER_1A 21 /**< GPTimer 1A */
82 #define NVIC_INT_GPTIMER_1B 22 /**< GPTimer 1B */
83 #define NVIC_INT_GPTIMER_2A 23 /**< GPTimer 2A */
84 #define NVIC_INT_GPTIMER_2B 24 /**< GPTimer 2B */
85 #define NVIC_INT_ADC_CMP 25 /**< Analog Comparator */
86 #define NVIC_INT_RF_RXTX_ALT 26 /**< RF TX/RX (Alternate) */
87 #define NVIC_INT_RF_ERR_ALT 27 /**< RF Error (Alternate) */
88 #define NVIC_INT_SYS_CTRL 28 /**< System Control */
89 #define NVIC_INT_FLASH_CTRL 29 /**< Flash memory control */
90 #define NVIC_INT_AES_ALT 30 /**< AES (Alternate) */
91 #define NVIC_INT_PKA_ALT 31 /**< PKA (Alternate) */
92 #define NVIC_INT_SM_TIMER_ALT 32 /**< SM Timer (Alternate) */
93 #define NVIC_INT_MAC_TIMER_ALT 33 /**< MAC Timer (Alternate) */
94 #define NVIC_INT_SSI1 34 /**< SSI1 */
95 #define NVIC_INT_GPTIMER_3A 35 /**< GPTimer 3A */
96 #define NVIC_INT_GPTIMER_3B 36 /**< GPTimer 3B */
97 #define NVIC_INT_UDMA 46 /**< uDMA software */
98 #define NVIC_INT_UDMA_ERR 47 /**< uDMA error */
99 #define NVIC_INT_USB 140 /**< USB */
100 #define NVIC_INT_RF_RXTX 141 /**< RF Core Rx/Tx */
101 #define NVIC_INT_RF_ERR 142 /**< RF Core Error */
102 #define NVIC_INT_AES 143 /**< AES */
103 #define NVIC_INT_PKA 144 /**< PKA */
104 #define NVIC_INT_SM_TIMER 145 /**< SM Timer */
105 #define NVIC_INT_MACTIMER 146 /**< MAC Timer */
106 /** @} */
107 /*---------------------------------------------------------------------------*/
108 /** \name NVIC Register Declarations
109  * @{
110  */
111 #define NVIC_EN0 0xE000E100 /**< Interrupt 0-31 Set Enable */
112 #define NVIC_EN1 0xE000E104 /**< Interrupt 32-54 Set Enable */
113 #define NVIC_EN2 0xE000E108 /**< Interrupt 64-95 Set Enable */
114 #define NVIC_EN3 0xE000E10C /**< Interrupt 96-127 Set Enable */
115 #define NVIC_EN4 0xE000E110 /**< Interrupt 128-131 Set Enable */
116 #define NVIC_DIS0 0xE000E180 /**< Interrupt 0-31 Clear Enable */
117 #define NVIC_DIS1 0xE000E184 /**< Interrupt 32-54 Clear Enable */
118 #define NVIC_DIS2 0xE000E188 /**< Interrupt 64-95 Clear Enable */
119 #define NVIC_DIS3 0xE000E18C /**< Interrupt 96-127 Clear Enable */
120 #define NVIC_DIS4 0xE000E190 /**< Interrupt 128-131 Clear Enable */
121 #define NVIC_PEND0 0xE000E200 /**< Interrupt 0-31 Set Pending */
122 #define NVIC_PEND1 0xE000E204 /**< Interrupt 32-54 Set Pending */
123 #define NVIC_PEND2 0xE000E208 /**< Interrupt 64-95 Set Pending */
124 #define NVIC_PEND3 0xE000E20C /**< Interrupt 96-127 Set Pending */
125 #define NVIC_PEND4 0xE000E210 /**< Interrupt 128-131 Set Pending */
126 #define NVIC_UNPEND0 0xE000E280 /**< Interrupt 0-31 Clear Pending */
127 #define NVIC_UNPEND1 0xE000E284 /**< Interrupt 32-54 Clear Pending */
128 #define NVIC_UNPEND2 0xE000E288 /**< Interrupt 64-95 Clear Pending */
129 #define NVIC_UNPEND3 0xE000E28C /**< Interrupt 96-127 Clear Pending */
130 #define NVIC_UNPEND4 0xE000E290 /**< Interrupt 128-131 Clear Pending */
131 #define NVIC_ACTIVE0 0xE000E300 /**< Interrupt 0-31 Active Bit */
132 #define NVIC_ACTIVE1 0xE000E304 /**< Interrupt 32-54 Active Bit */
133 #define NVIC_ACTIVE2 0xE000E308 /**< Interrupt 64-95 Active Bit */
134 #define NVIC_ACTIVE3 0xE000E30C /**< Interrupt 96-127 Active Bit */
135 #define NVIC_ACTIVE4 0xE000E310 /**< Interrupt 128-131 Active Bit */
136 #define NVIC_PRI0 0xE000E400 /**< Interrupt 0-3 Priority */
137 #define NVIC_PRI1 0xE000E404 /**< Interrupt 4-7 Priority */
138 #define NVIC_PRI2 0xE000E408 /**< Interrupt 8-11 Priority */
139 #define NVIC_PRI3 0xE000E40C /**< Interrupt 12-15 Priority */
140 #define NVIC_PRI4 0xE000E410 /**< Interrupt 16-19 Priority */
141 #define NVIC_PRI5 0xE000E414 /**< Interrupt 20-23 Priority */
142 #define NVIC_PRI6 0xE000E418 /**< Interrupt 24-27 Priority */
143 #define NVIC_PRI7 0xE000E41C /**< Interrupt 28-31 Priority */
144 #define NVIC_PRI8 0xE000E420 /**< Interrupt 32-35 Priority */
145 #define NVIC_PRI9 0xE000E424 /**< Interrupt 36-39 Priority */
146 #define NVIC_PRI10 0xE000E428 /**< Interrupt 40-43 Priority */
147 #define NVIC_PRI11 0xE000E42C /**< Interrupt 44-47 Priority */
148 #define NVIC_PRI12 0xE000E430 /**< Interrupt 48-51 Priority */
149 #define NVIC_PRI13 0xE000E434 /**< Interrupt 52-53 Priority */
150 #define NVIC_PRI14 0xE000E438 /**< Interrupt 56-59 Priority */
151 #define NVIC_PRI15 0xE000E43C /**< Interrupt 60-63 Priority */
152 #define NVIC_PRI16 0xE000E440 /**< Interrupt 64-67 Priority */
153 #define NVIC_PRI17 0xE000E444 /**< Interrupt 68-71 Priority */
154 #define NVIC_PRI18 0xE000E448 /**< Interrupt 72-75 Priority */
155 #define NVIC_PRI19 0xE000E44C /**< Interrupt 76-79 Priority */
156 #define NVIC_PRI20 0xE000E450 /**< Interrupt 80-83 Priority */
157 #define NVIC_PRI21 0xE000E454 /**< Interrupt 84-87 Priority */
158 #define NVIC_PRI22 0xE000E458 /**< Interrupt 88-91 Priority */
159 #define NVIC_PRI23 0xE000E45C /**< Interrupt 92-95 Priority */
160 #define NVIC_PRI24 0xE000E460 /**< Interrupt 96-99 Priority */
161 #define NVIC_PRI25 0xE000E464 /**< Interrupt 100-103 Priority */
162 #define NVIC_PRI26 0xE000E468 /**< Interrupt 104-107 Priority */
163 #define NVIC_PRI27 0xE000E46C /**< Interrupt 108-111 Priority */
164 #define NVIC_PRI28 0xE000E470 /**< Interrupt 112-115 Priority */
165 #define NVIC_PRI29 0xE000E474 /**< Interrupt 116-119 Priority */
166 #define NVIC_PRI30 0xE000E478 /**< Interrupt 120-123 Priority */
167 #define NVIC_PRI31 0xE000E47C /**< Interrupt 124-127 Priority */
168 #define NVIC_PRI32 0xE000E480 /**< Interrupt 128-131 Priority */
169 #define NVIC_PRI33 0xE000E480 /**< Interrupt 132-135 Priority */
170 #define NVIC_PRI34 0xE000E484 /**< Interrupt 136-139 Priority */
171 #define NVIC_PRI35 0xE000E488 /**< Interrupt 140-143 Priority */
172 #define NVIC_PRI36 0xE000E48c /**< Interrupt 144-147 Priority */
173 /** @} */
174 /*---------------------------------------------------------------------------*/
175 /** \brief Initialises the NVIC driver */
176 void nvic_init();
177 
178 /**
179  * \brief Enables interrupt intr
180  * \param intr The interrupt number (NOT the vector number). For example,
181  * GPIO Port A interrupt is 0, not 16.
182  *
183  * Possible values for the \e intr param are defined as NVIC_INT_xyz. For
184  * instance, to enable the GPIO Port A interrupt, pass NVIC_INT_GPIO_PORT_A
185  */
186 void nvic_interrupt_enable(uint32_t intr);
187 
188 /**
189  * \brief Disables interrupt intr
190  * \param intr The interrupt number (NOT the vector number). For example,
191  * GPIO Port A interrupt is 0, not 16.
192  *
193  * Possible values for the \e intr param are defined as NVIC_INT_xyz. For
194  * instance, to disable the GPIO Port A interrupt, pass NVIC_INT_GPIO_PORT_A
195  */
196 void nvic_interrupt_disable(uint32_t intr);
197 
198 /**
199  * \brief Enables interrupt intr if v > 0
200  * \param intr The interrupt number (NOT the vector number). For example,
201  * GPIO Port A interrupt is 0, not 16.
202  * \param v 0: No effect, 1: Enables the interrupt
203  *
204  * This function is useful to restore an interrupt to a state previously
205  * saved by nvic_interrupt_en_save. Thus, if when nvic_interrupt_en_save was
206  * called the interrupt was enabled, this function will re-enabled it.
207  * Possible values for the \e intr param are defined as NVIC_INT_xyz. For
208  * instance, to disable the GPIO Port A interrupt, pass NVIC_INT_GPIO_PORT_A
209  */
210 void nvic_interrupt_en_restore(uint32_t intr, uint8_t v);
211 
212 /**
213  * \brief Checks the interrupt enabled status for intr
214  * \param intr The interrupt number (NOT the vector number). For example,
215  * GPIO Port A interrupt is 0, not 16.
216  * \return 1: Enabled, 0: Disabled
217  *
218  * Possible values for the \e intr param are defined as NVIC_INT_xyz. For
219  * instance, to disable the GPIO Port A interrupt, pass NVIC_INT_GPIO_PORT_A
220  */
221 uint8_t nvic_interrupt_en_save(uint32_t intr);
222 
223 /**
224  * \brief Sets intr to pending
225  * \param intr The interrupt number (NOT the vector number). For example,
226  * GPIO Port A interrupt is 0, not 16.
227  *
228  * Possible values for the \e intr param are defined as NVIC_INT_xyz. For
229  * instance, to enable the GPIO Port A interrupt, pass NVIC_INT_GPIO_PORT_A
230  */
231 void nvic_interrupt_pend(uint32_t intr);
232 
233 /**
234  * \brief Sets intr to no longer pending
235  * \param intr The interrupt number (NOT the vector number). For example,
236  * GPIO Port A interrupt is 0, not 16.
237  *
238  * Possible values for the \e intr param are defined as NVIC_INT_xyz. For
239  * instance, to disable the GPIO Port A interrupt, pass NVIC_INT_GPIO_PORT_A
240  */
241 void nvic_interrupt_unpend(uint32_t intr);
242 
243 #endif /* NVIC_H_ */
244 
245 /**
246  * @}
247  * @}
248  */
void nvic_interrupt_pend(uint32_t intr)
Sets intr to pending.
Definition: nvic.c:99
void nvic_interrupt_disable(uint32_t intr)
Disables interrupt intr.
Definition: nvic.c:71
void nvic_init()
Initialises the NVIC driver.
Definition: nvic.c:52
void nvic_interrupt_enable(uint32_t intr)
Enables interrupt intr.
Definition: nvic.c:64
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_en_restore(uint32_t intr, uint8_t v)
Enables interrupt intr if v &gt; 0.
Definition: nvic.c:78