1
/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */
4
Part of the Wiring project - http://wiring.uniandes.edu.co
6
Copyright (c) 2004-05 Hernando Barragan
8
This library is free software; you can redistribute it and/or
9
modify it under the terms of the GNU Lesser General Public
10
License as published by the Free Software Foundation; either
11
version 2.1 of the License, or (at your option) any later version.
13
This library is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
Lesser General Public License for more details.
18
You should have received a copy of the GNU Lesser General
19
Public License along with this library; if not, write to the
20
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
21
Boston, MA 02111-1307 USA
23
Modified 24 November 2006 by David A. Mellis
28
#include <avr/interrupt.h>
29
#include <avr/pgmspace.h>
32
#include "WConstants.h"
33
#include "wiring_private.h"
35
volatile static voidFuncPtr intFunc[EXTERNAL_NUM_INTERRUPTS];
36
// volatile static voidFuncPtr twiIntFunc;
38
#if defined(__AVR_ATmega8__)
43
void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode) {
44
if(interruptNum < EXTERNAL_NUM_INTERRUPTS) {
45
intFunc[interruptNum] = userFunc;
47
// Configure the interrupt mode (trigger on low input, any change, rising
48
// edge, or falling edge). The mode constants were chosen to correspond
49
// to the configuration bits in the hardware register, so we simply shift
50
// the mode into place.
52
// Enable the interrupt.
54
switch (interruptNum) {
55
#if defined(__AVR_ATmega1280__)
57
EICRA = (EICRA & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00);
61
EICRA = (EICRA & ~((1 << ISC10) | (1 << ISC11))) | (mode << ISC10);
65
EICRA = (EICRA & ~((1 << ISC20) | (1 << ISC21))) | (mode << ISC20);
69
EICRA = (EICRA & ~((1 << ISC30) | (1 << ISC31))) | (mode << ISC30);
73
EICRB = (EICRB & ~((1 << ISC40) | (1 << ISC41))) | (mode << ISC40);
77
EICRB = (EICRB & ~((1 << ISC50) | (1 << ISC51))) | (mode << ISC50);
81
EICRB = (EICRB & ~((1 << ISC60) | (1 << ISC61))) | (mode << ISC60);
85
EICRB = (EICRB & ~((1 << ISC70) | (1 << ISC71))) | (mode << ISC70);
90
EICRA = (EICRA & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00);
94
EICRA = (EICRA & ~((1 << ISC10) | (1 << ISC11))) | (mode << ISC10);
102
void detachInterrupt(uint8_t interruptNum) {
103
if(interruptNum < EXTERNAL_NUM_INTERRUPTS) {
104
// Disable the interrupt. (We can't assume that interruptNum is equal
105
// to the number of the EIMSK bit to clear, as this isn't true on the
106
// ATmega8. There, INT0 is 6 and INT1 is 7.)
107
switch (interruptNum) {
108
#if defined(__AVR_ATmega1280__)
110
EIMSK &= ~(1 << INT0);
113
EIMSK &= ~(1 << INT1);
116
EIMSK &= ~(1 << INT2);
119
EIMSK &= ~(1 << INT3);
122
EIMSK &= ~(1 << INT4);
125
EIMSK &= ~(1 << INT5);
128
EIMSK &= ~(1 << INT6);
131
EIMSK &= ~(1 << INT7);
135
EIMSK &= ~(1 << INT0);
138
EIMSK &= ~(1 << INT1);
143
intFunc[interruptNum] = 0;
148
void attachInterruptTwi(void (*userFunc)(void) ) {
149
twiIntFunc = userFunc;
153
#if defined(__AVR_ATmega1280__)
156
if(intFunc[EXTERNAL_INT_2])
157
intFunc[EXTERNAL_INT_2]();
161
if(intFunc[EXTERNAL_INT_3])
162
intFunc[EXTERNAL_INT_3]();
166
if(intFunc[EXTERNAL_INT_4])
167
intFunc[EXTERNAL_INT_4]();
171
if(intFunc[EXTERNAL_INT_5])
172
intFunc[EXTERNAL_INT_5]();
176
if(intFunc[EXTERNAL_INT_0])
177
intFunc[EXTERNAL_INT_0]();
181
if(intFunc[EXTERNAL_INT_1])
182
intFunc[EXTERNAL_INT_1]();
186
if(intFunc[EXTERNAL_INT_6])
187
intFunc[EXTERNAL_INT_6]();
191
if(intFunc[EXTERNAL_INT_7])
192
intFunc[EXTERNAL_INT_7]();
198
if(intFunc[EXTERNAL_INT_0])
199
intFunc[EXTERNAL_INT_0]();
203
if(intFunc[EXTERNAL_INT_1])
204
intFunc[EXTERNAL_INT_1]();
210
SIGNAL(SIG_2WIRE_SERIAL) {