aboutsummaryrefslogtreecommitdiff
path: root/targets/arduino/WInterrupts.c
diff options
context:
space:
mode:
authorDavid A. Mellis <d.mellis@arduino.cc>2007-10-06 14:09:02 +0000
committerDavid A. Mellis <d.mellis@arduino.cc>2007-10-06 14:09:02 +0000
commit72e9f39fbde96b484338cbbd785680e5ab4a2e72 (patch)
treebd441d569bf70c9697ccfbee7c70fa26d67be3a0 /targets/arduino/WInterrupts.c
parentb86a6e051920a4ffdb92bc5b8de7260ff3978117 (diff)
Renaming core to targets.
Diffstat (limited to 'targets/arduino/WInterrupts.c')
-rwxr-xr-xtargets/arduino/WInterrupts.c98
1 files changed, 98 insertions, 0 deletions
diff --git a/targets/arduino/WInterrupts.c b/targets/arduino/WInterrupts.c
new file mode 100755
index 0000000..38992ee
--- /dev/null
+++ b/targets/arduino/WInterrupts.c
@@ -0,0 +1,98 @@
+/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */
+
+/*
+ Part of the Wiring project - http://wiring.uniandes.edu.co
+
+ Copyright (c) 2004-05 Hernando Barragan
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General
+ Public License along with this library; if not, write to the
+ Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ Boston, MA 02111-1307 USA
+
+ Modified 24 November 2006 by David A. Mellis
+*/
+
+#include <inttypes.h>
+#include <avr/io.h>
+#include <avr/interrupt.h>
+#include <avr/signal.h>
+#include <avr/pgmspace.h>
+#include <stdio.h>
+
+#include "WConstants.h"
+#include "wiring_private.h"
+
+volatile static voidFuncPtr intFunc[EXTERNAL_NUM_INTERRUPTS];
+// volatile static voidFuncPtr twiIntFunc;
+
+#if defined(__AVR_ATmega168__)
+#define MCUCR EICRA
+#define GICR EIMSK
+#endif
+
+void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode) {
+ if(interruptNum < EXTERNAL_NUM_INTERRUPTS) {
+ intFunc[interruptNum] = userFunc;
+
+ if (interruptNum == 0) {
+ // Configure the interrupt mode (trigger on low input, any change, rising
+ // edge, or falling edge). The mode constants were chosen to correspond
+ // to the configuration bits in the hardware register, so we simply shift
+ // the mode into place.
+ MCUCR = (MCUCR & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00);
+
+ // Enable the interrupt.
+ GICR |= (1 << INT0);
+ } else {
+ MCUCR = (MCUCR & ~((1 << ISC10) | (1 << ISC11))) | (mode << ISC10);
+ GICR |= (1 << INT1);
+ }
+ }
+}
+
+void detachInterrupt(uint8_t interruptNum) {
+ if(interruptNum < EXTERNAL_NUM_INTERRUPTS) {
+ if (interruptNum == 0)
+ // Disable the interrupt.
+ GICR &= ~(1 << INT0);
+ else
+ GICR &= ~(1 << INT1);
+
+ intFunc[interruptNum] = 0;
+ }
+}
+
+/*
+void attachInterruptTwi(void (*userFunc)(void) ) {
+ twiIntFunc = userFunc;
+}
+*/
+
+SIGNAL(SIG_INTERRUPT0) {
+ if(intFunc[EXTERNAL_INT_0])
+ intFunc[EXTERNAL_INT_0]();
+}
+
+SIGNAL(SIG_INTERRUPT1) {
+ if(intFunc[EXTERNAL_INT_1])
+ intFunc[EXTERNAL_INT_1]();
+}
+
+/*
+SIGNAL(SIG_2WIRE_SERIAL) {
+ if(twiIntFunc)
+ twiIntFunc();
+}
+*/
+