diff options
author | David A. Mellis <d.mellis@arduino.cc> | 2009-03-25 10:50:00 +0000 |
---|---|---|
committer | David A. Mellis <d.mellis@arduino.cc> | 2009-03-25 10:50:00 +0000 |
commit | a42326aba2fd9696a4b2e1239a5a222014056ff5 (patch) | |
tree | 69288e62749704d81d7ab11079e5868022bdc174 /cores/arduino/WInterrupts.c | |
parent | b89ee8da481d7b9c360b689f367b7a234ec7cb11 (diff) |
Adding support for the Arduino Mega (ATmega1280) to the core and bootloader.
Diffstat (limited to 'cores/arduino/WInterrupts.c')
-rwxr-xr-x | cores/arduino/WInterrupts.c | 140 |
1 files changed, 129 insertions, 11 deletions
diff --git a/cores/arduino/WInterrupts.c b/cores/arduino/WInterrupts.c index 8b9003f..69a78b0 100755 --- a/cores/arduino/WInterrupts.c +++ b/cores/arduino/WInterrupts.c @@ -44,29 +44,101 @@ 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. - EICRA = (EICRA & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00); + // 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. + + // Enable the interrupt. - // Enable the interrupt. + switch (interruptNum) { +#if defined(__AVR_ATmega1280__) + case 2: + EICRA = (EICRA & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00); + EIMSK |= (1 << INT0); + break; + case 3: + EICRA = (EICRA & ~((1 << ISC10) | (1 << ISC11))) | (mode << ISC10); + EIMSK |= (1 << INT1); + break; + case 4: + EICRA = (EICRA & ~((1 << ISC20) | (1 << ISC21))) | (mode << ISC20); + EIMSK |= (1 << INT2); + break; + case 5: + EICRA = (EICRA & ~((1 << ISC30) | (1 << ISC31))) | (mode << ISC30); + EIMSK |= (1 << INT3); + break; + case 0: + EICRB = (EICRB & ~((1 << ISC40) | (1 << ISC41))) | (mode << ISC40); + EIMSK |= (1 << INT4); + break; + case 1: + EICRB = (EICRB & ~((1 << ISC50) | (1 << ISC51))) | (mode << ISC50); + EIMSK |= (1 << INT5); + break; + case 6: + EICRB = (EICRB & ~((1 << ISC60) | (1 << ISC61))) | (mode << ISC60); + EIMSK |= (1 << INT6); + break; + case 7: + EICRB = (EICRB & ~((1 << ISC70) | (1 << ISC71))) | (mode << ISC70); + EIMSK |= (1 << INT7); + break; +#else + case 0: + EICRA = (EICRA & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00); EIMSK |= (1 << INT0); - } else { + break; + case 1: EICRA = (EICRA & ~((1 << ISC10) | (1 << ISC11))) | (mode << ISC10); EIMSK |= (1 << INT1); + break; +#endif } } } void detachInterrupt(uint8_t interruptNum) { if(interruptNum < EXTERNAL_NUM_INTERRUPTS) { - if (interruptNum == 0) - // Disable the interrupt. + // Disable the interrupt. (We can't assume that interruptNum is equal + // to the number of the EIMSK bit to clear, as this isn't true on the + // ATmega8. There, INT0 is 6 and INT1 is 7.) + switch (interruptNum) { +#if defined(__AVR_ATmega1280__) + case 2: + EIMSK &= ~(1 << INT0); + break; + case 3: + EIMSK &= ~(1 << INT1); + break; + case 4: + EIMSK &= ~(1 << INT2); + break; + case 5: + EIMSK &= ~(1 << INT3); + break; + case 0: + EIMSK &= ~(1 << INT4); + break; + case 1: + EIMSK &= ~(1 << INT5); + break; + case 6: + EIMSK &= ~(1 << INT6); + break; + case 7: + EIMSK &= ~(1 << INT7); + break; +#else + case 0: EIMSK &= ~(1 << INT0); - else + break; + case 1: EIMSK &= ~(1 << INT1); + break; +#endif + } intFunc[interruptNum] = 0; } @@ -78,6 +150,50 @@ void attachInterruptTwi(void (*userFunc)(void) ) { } */ +#if defined(__AVR_ATmega1280__) + +SIGNAL(INT0_vect) { + if(intFunc[EXTERNAL_INT_2]) + intFunc[EXTERNAL_INT_2](); +} + +SIGNAL(INT1_vect) { + if(intFunc[EXTERNAL_INT_3]) + intFunc[EXTERNAL_INT_3](); +} + +SIGNAL(INT2_vect) { + if(intFunc[EXTERNAL_INT_4]) + intFunc[EXTERNAL_INT_4](); +} + +SIGNAL(INT3_vect) { + if(intFunc[EXTERNAL_INT_5]) + intFunc[EXTERNAL_INT_5](); +} + +SIGNAL(INT4_vect) { + if(intFunc[EXTERNAL_INT_0]) + intFunc[EXTERNAL_INT_0](); +} + +SIGNAL(INT5_vect) { + if(intFunc[EXTERNAL_INT_1]) + intFunc[EXTERNAL_INT_1](); +} + +SIGNAL(INT6_vect) { + if(intFunc[EXTERNAL_INT_6]) + intFunc[EXTERNAL_INT_6](); +} + +SIGNAL(INT7_vect) { + if(intFunc[EXTERNAL_INT_7]) + intFunc[EXTERNAL_INT_7](); +} + +#else + SIGNAL(INT0_vect) { if(intFunc[EXTERNAL_INT_0]) intFunc[EXTERNAL_INT_0](); @@ -88,6 +204,8 @@ SIGNAL(INT1_vect) { intFunc[EXTERNAL_INT_1](); } +#endif + /* SIGNAL(SIG_2WIRE_SERIAL) { if(twiIntFunc) |