source: rtems/cpukit/score/cpu/avr/avr/interrupt.h @ 9b4422a2

4.115
Last change on this file since 9b4422a2 was 9b4422a2, checked in by Joel Sherrill <joel.sherrill@…>, on 05/03/12 at 15:09:24

Remove All CVS Id Strings Possible Using a Script

Script does what is expected and tries to do it as
smartly as possible.

+ remove occurrences of two blank comment lines

next to each other after Id string line removed.

+ remove entire comment blocks which only exited to

contain CVS Ids

+ If the processing left a blank line at the top of

a file, it was removed.

  • Property mode set to 100644
File size: 10.6 KB
Line 
1/* Copyright (c) 2002,2005,2007 Marek Michalkiewicz
2   Copyright (c) 2007, Dean Camera
3
4   All rights reserved.
5
6   Redistribution and use in source and binary forms, with or without
7   modification, are permitted provided that the following conditions are met:
8
9   * Redistributions of source code must retain the above copyright
10     notice, this list of conditions and the following disclaimer.
11
12   * Redistributions in binary form must reproduce the above copyright
13     notice, this list of conditions and the following disclaimer in
14     the documentation and/or other materials provided with the
15     distribution.
16
17   * Neither the name of the copyright holders nor the names of
18     contributors may be used to endorse or promote products derived
19     from this software without specific prior written permission.
20
21  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  POSSIBILITY OF SUCH DAMAGE. */
32
33
34#ifndef _AVR_INTERRUPT_H_
35#define _AVR_INTERRUPT_H_
36
37#include <avr/io.h>
38
39#if !defined(__DOXYGEN__) && !defined(__STRINGIFY)
40/* Auxiliary macro for ISR_ALIAS(). */
41#define __STRINGIFY(x) #x
42#endif /* !defined(__DOXYGEN__) */
43
44/**
45\file
46\@{
47*/
48
49
50/** \name Global manipulation of the interrupt flag
51
52    The global interrupt flag is maintained in the I bit of the status
53    register (SREG).
54*/
55
56#if defined(__DOXYGEN__)
57/** \def sei()
58    \ingroup avr_interrupts
59
60    \code #include <avr/interrupt.h> \endcode
61
62    Enables interrupts by setting the global interrupt mask. This function
63    actually compiles into a single line of assembly, so there is no function
64    call overhead. */
65#define sei()
66#else  /* !DOXYGEN */
67# define sei()  __asm__ __volatile__ ("sei" ::)
68#endif /* DOXYGEN */
69
70#if defined(__DOXYGEN__)
71/** \def cli()
72    \ingroup avr_interrupts
73
74    \code #include <avr/interrupt.h> \endcode
75
76    Disables all interrupts by clearing the global interrupt mask. This function
77    actually compiles into a single line of assembly, so there is no function
78    call overhead. */
79#define cli()
80#else  /* !DOXYGEN */
81# define cli()  __asm__ __volatile__ ("cli" ::)
82#endif /* DOXYGEN */
83
84
85/** \name Macros for writing interrupt handler functions */
86
87
88#if defined(__DOXYGEN__)
89/** \def ISR(vector [, attributes])
90    \ingroup avr_interrupts
91
92    \code #include <avr/interrupt.h> \endcode
93
94    Introduces an interrupt handler function (interrupt service
95    routine) that runs with global interrupts initially disabled
96    by default with no attributes specified.
97
98    The attributes are optional and alter the behaviour and resultant
99    generated code of the interrupt routine. Multiple attributes may
100    be used for a single function, with a space seperating each
101    attribute.
102
103    Valid attributes are ISR_BLOCK, ISR_NOBLOCK, ISR_NAKED and
104    ISR_ALIASOF(vect).
105
106    \c vector must be one of the interrupt vector names that are
107    valid for the particular MCU type.
108*/
109#  define ISR(vector, [attributes])
110#else  /* real code */
111
112#if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
113#  define __INTR_ATTRS used, externally_visible
114#else /* GCC < 4.1 */
115#  define __INTR_ATTRS used
116#endif
117
118#ifdef __cplusplus
119#  define ISR(vector, ...)            \
120    extern "C" void vector (void) __attribute__ ((signal,__INTR_ATTRS)) __VA_ARGS__; \
121    void vector (void)
122#else
123#  define ISR(vector, ...)            \
124    void vector (void) __attribute__ ((signal,__INTR_ATTRS)) __VA_ARGS__; \
125    void vector (void)
126#endif
127
128#endif /* DOXYGEN */
129
130#if defined(__DOXYGEN__)
131/** \def SIGNAL(vector)
132    \ingroup avr_interrupts
133
134    \code #include <avr/interrupt.h> \endcode
135
136    Introduces an interrupt handler function that runs with global interrupts
137    initially disabled.
138
139    This is the same as the ISR macro without optional attributes.
140    \deprecated Do not use SIGNAL() in new code. Use ISR() instead.
141*/
142#  define SIGNAL(vector)
143#else  /* real code */
144
145#ifdef __cplusplus
146#  define SIGNAL(vector)                                        \
147    extern "C" void vector(void) __attribute__ ((signal, __INTR_ATTRS));        \
148    void vector (void)
149#else
150#  define SIGNAL(vector)                                        \
151    void vector (void) __attribute__ ((signal, __INTR_ATTRS));          \
152    void vector (void)
153#endif
154
155#endif /* DOXYGEN */
156
157#if defined(__DOXYGEN__)
158/** \def EMPTY_INTERRUPT(vector)
159    \ingroup avr_interrupts
160
161    \code #include <avr/interrupt.h> \endcode
162
163    Defines an empty interrupt handler function. This will not generate
164    any prolog or epilog code and will only return from the ISR. Do not
165    define a function body as this will define it for you.
166    Example:
167    \code EMPTY_INTERRUPT(ADC_vect);\endcode */
168#  define EMPTY_INTERRUPT(vector)
169#else  /* real code */
170
171#ifdef __cplusplus
172#  define EMPTY_INTERRUPT(vector)                \
173    extern "C" void vector(void) __attribute__ ((signal,naked,__INTR_ATTRS));    \
174    void vector (void) {  __asm__ __volatile__ ("reti" ::); }
175#else
176#  define EMPTY_INTERRUPT(vector)                \
177    void vector (void) __attribute__ ((signal,naked,__INTR_ATTRS));    \
178    void vector (void) { __asm__ __volatile__ ("reti" ::); }
179#endif
180
181#endif /* DOXYGEN */
182
183#if defined(__DOXYGEN__)
184/** \def ISR_ALIAS(vector, target_vector)
185    \ingroup avr_interrupts
186
187    \code #include <avr/interrupt.h> \endcode
188
189    Aliases a given vector to another one in the same manner as the
190    ISR_ALIASOF attribute for the ISR() macro. Unlike the ISR_ALIASOF
191    attribute macro however, this is compatible for all versions of
192    GCC rather than just GCC version 4.2 onwards.
193
194    \note This macro creates a trampoline function for the aliased
195    macro.  This will result in a two cycle penalty for the aliased
196    vector compared to the ISR the vector is aliased to, due to the
197    JMP/RJMP opcode used.
198
199    \deprecated
200    For new code, the use of ISR(..., ISR_ALIASOF(...))  is
201    recommended.
202
203    Example:
204    \code
205    ISR(INT0_vect)
206    {
207        PORTB = 42;
208    }
209
210    ISR_ALIAS(INT1_vect, INT0_vect);
211    \endcode
212*/
213#  define ISR_ALIAS(vector, target_vector)
214#else /* real code */
215
216#ifdef __cplusplus
217#  if defined(__AVR_MEGA__) && __AVR_MEGA__
218#    define ISR_ALIAS(vector, tgt) extern "C" void vector (void) \
219        __attribute__((signal, naked, __INTR_ATTRS)); \
220        void vector (void) { __asm__ volatile ("jmp " __STRINGIFY(tgt) ::); }
221#  else /* !__AVR_MEGA */
222#    define ISR_ALIAS(vector, tgt) extern "C" void vector (void) \
223        __attribute__((signal, naked, __INTR_ATTRS)); \
224        void vector (void) { __asm__ volatile ("rjmp " __STRINGIFY(tgt) ::); }
225#  endif  /* __AVR_MEGA__ */
226#else     /* !__cplusplus */
227#  if defined(__AVR_MEGA__) && __AVR_MEGA__
228#  define ISR_ALIAS(vector, tgt) void vector (void) \
229        __attribute__((signal, naked, __INTR_ATTRS)); \
230        void vector (void) { __asm__ volatile ("jmp " __STRINGIFY(tgt) ::); }
231#  else /* !__AVR_MEGA */
232#  define ISR_ALIAS(vector, tgt) void vector (void) \
233        __attribute__((signal, naked, __INTR_ATTRS)); \
234        void vector (void) { __asm__ volatile ("rjmp " __STRINGIFY(tgt) ::); }
235#  endif  /* __AVR_MEGA__ */
236#endif  /* __cplusplus */
237
238#endif /* DOXYGEN */
239
240#if defined(__DOXYGEN__)
241/** \def reti()
242    \ingroup avr_interrupts
243
244    \code #include <avr/interrupt.h> \endcode
245
246    Returns from an interrupt routine, enabling global interrupts. This should
247    be the last command executed before leaving an ISR defined with the ISR_NAKED
248    attribute.
249
250    This macro actually compiles into a single line of assembly, so there is
251    no function call overhead.
252*/
253#  define reti()
254#else  /* !DOXYGEN */
255#  define reti()  __asm__ __volatile__ ("reti" ::)
256#endif /* DOXYGEN */
257
258#if defined(__DOXYGEN__)
259/** \def BADISR_vect
260    \ingroup avr_interrupts
261
262    \code #include <avr/interrupt.h> \endcode
263
264    This is a vector which is aliased to __vector_default, the vector
265    executed when an ISR fires with no accompanying ISR handler. This
266    may be used along with the ISR() macro to create a catch-all for
267    undefined but used ISRs for debugging purposes.
268*/
269#  define BADISR_vect
270#else  /* !DOXYGEN */
271#  define BADISR_vect __vector_default
272#endif /* DOXYGEN */
273
274/** \name ISR attributes */
275
276#if defined(__DOXYGEN__)
277/** \def ISR_BLOCK
278    \ingroup avr_interrupts
279
280    \code# include <avr/interrupt.h> \endcode
281
282    Identical to an ISR with no attributes specified. Global
283    interrupts are initially disabled by the AVR hardware when
284    entering the ISR, without the compiler modifying this state.
285
286    Use this attribute in the attributes parameter of the ISR macro.
287*/
288#  define ISR_BLOCK
289
290/** \def ISR_NOBLOCK
291    \ingroup avr_interrupts
292
293    \code# include <avr/interrupt.h> \endcode
294
295    ISR runs with global interrupts initially enabled.  The interrupt
296    enable flag is activated by the compiler as early as possible
297    within the ISR to ensure minimal processing delay for nested
298    interrupts.
299
300    This may be used to create nested ISRs, however care should be
301    taken to avoid stack overflows, or to avoid infinitely entering
302    the ISR for those cases where the AVR hardware does not clear the
303    respective interrupt flag before entering the ISR.
304
305    Use this attribute in the attributes parameter of the ISR macro.
306*/
307#  define ISR_NOBLOCK
308
309/** \def ISR_NAKED
310    \ingroup avr_interrupts
311
312    \code# include <avr/interrupt.h> \endcode
313
314    ISR is created with no prologue or epilogue code. The user code is
315    responsible for preservation of the machine state including the
316    SREG register, as well as placing a reti() at the end of the
317    interrupt routine.
318
319    Use this attribute in the attributes parameter of the ISR macro.
320*/
321#  define ISR_NAKED
322
323/** \def ISR_ALIASOF(target_vector)
324    \ingroup avr_interrupts
325
326    \code#include <avr/interrupt.h>\endcode
327
328    The ISR is linked to another ISR, specified by the vect parameter.
329    This is compatible with GCC 4.2 and greater only.
330
331    Use this attribute in the attributes parameter of the ISR macro.
332*/
333#  define ISR_ALIASOF(target_vector)
334#else  /* !DOXYGEN */
335#  define ISR_BLOCK
336#  define ISR_NOBLOCK    __attribute__((interrupt))
337#  define ISR_NAKED      __attribute__((naked))
338#  define ISR_ALIASOF(v) __attribute__((alias(__STRINGIFY(v))))
339#endif /* DOXYGEN */
340
341/* \@} */
342
343#endif
Note: See TracBrowser for help on using the repository browser.