| 1 |
/* Copyright (c) 1999, 2000, 2001, 2002, Rich Neswold |
/* Copyright (c) 1999, 2000, 2001, 2002, 2005 Rich Neswold |
| 2 |
All rights reserved. |
All rights reserved. |
| 3 |
|
|
| 4 |
Redistribution and use in source and binary forms, with or without |
Redistribution and use in source and binary forms, with or without |
| 43 |
compiler-generated code. It's important that these registers, as well as the |
compiler-generated code. It's important that these registers, as well as the |
| 44 |
status register, get saved and restored. The extra code needed to do this is |
status register, get saved and restored. The extra code needed to do this is |
| 45 |
enabled by tagging the interrupt function with |
enabled by tagging the interrupt function with |
| 46 |
<tt>__attribute__((interrupt))</tt>. |
<tt>__attribute__((signal))</tt>. |
| 47 |
|
|
| 48 |
These details seem to make interrupt routines a little messy, but all these |
These details seem to make interrupt routines a little messy, but all these |
| 49 |
details are handled by the Interrupt API. An interrupt routine is defined with |
details are handled by the Interrupt API. An interrupt routine is defined with |
| 50 |
one of two macros, INTERRUPT() and SIGNAL(). These macros register and mark |
SIGNAL(). This macro register and mark |
| 51 |
the routine as an interrupt handler for the specified peripheral. The |
the routine as an interrupt handler for the specified peripheral. The |
| 52 |
following is an example definition of a handler for the ADC interrupt. |
following is an example definition of a handler for the ADC interrupt. |
| 53 |
|
|
| 54 |
\code |
\code |
| 55 |
#include <avr/signal.h> |
#include <avr/signal.h> |
| 56 |
|
|
| 57 |
INTERRUPT(SIG_ADC) |
SIGNAL(SIG_ADC) |
| 58 |
{ |
{ |
| 59 |
// user code here |
// user code here |
| 60 |
} |
} |
| 66 |
If an unexpected interrupt occurs (interrupt is enabled and no handler is |
If an unexpected interrupt occurs (interrupt is enabled and no handler is |
| 67 |
installed, which usually indicates a bug), then the default action is to reset |
installed, which usually indicates a bug), then the default action is to reset |
| 68 |
the device by jumping to the reset vector. You can override this by supplying |
the device by jumping to the reset vector. You can override this by supplying |
| 69 |
a function named \c __vector_default which should be defined with either |
a function named \c __vector_default which should be defined with |
| 70 |
SIGNAL() or INTERRUPT() as such. |
SIGNAL() as such. |
| 71 |
|
|
| 72 |
\code |
\code |
| 73 |
#include <avr/signal.h> |
#include <avr/signal.h> |
| 83 |
signals might not be available. Check the data sheet for the device you are |
signals might not be available. Check the data sheet for the device you are |
| 84 |
using. |
using. |
| 85 |
|
|
| 86 |
<b>[FIXME: Fill in the blanks! Gotta read those durn data sheets ;-)]</b> |
\note The SIGNAL() macro cannot really spell-check |
|
\note The SIGNAL() and INTERRUPT() macros currently cannot spell-check |
|
| 87 |
the argument passed to them. Thus, by misspelling one of the names |
the argument passed to them. Thus, by misspelling one of the names |
| 88 |
below in a call to SIGNAL() or INTERRUPT(), a function will be created |
below in a call to SIGNAL(), a function will be created |
| 89 |
that, while possibly being usable as an interrupt function, is not |
that, while possibly being usable as an interrupt function, is not |
| 90 |
actually wired into the interrupt vector table. No warning will be |
actually wired into the interrupt vector table. The compiler will |
| 91 |
given about this situation. |
generate a warning if it detects a suspiciously looking name of a |
| 92 |
|
SIGNAL() function (i.e. one that after macro replacement does not |
| 93 |
|
start with "__vector_"). |
| 94 |
|
|
| 95 |
\anchor avr_signames |
\anchor avr_signames |
| 96 |
<small> |
<small> |