00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include <avr/io.h>
00029 #include <avr/interrupt.h>
00030
00031 #include "global.h"
00032 #include "extint.h"
00033
00034
00035 typedef void (*voidFuncPtr)(void);
00036 volatile static voidFuncPtr ExtIntFunc[EXTINT_NUM_INTERRUPTS];
00037
00038
00039
00040
00041 void extintInit(void)
00042 {
00043 u08 intNum;
00044
00045 for(intNum=0; intNum<EXTINT_NUM_INTERRUPTS; intNum++)
00046 extintDetach(intNum);
00047
00048 }
00049
00050
00051
00052 void extintConfigure(u08 interruptNum, u08 configuration)
00053 {
00054 if(interruptNum == EXTINT0)
00055 {
00056 MCUCR &= ~((1<<ISC01) | (1<<ISC00));
00057 MCUCR |= configuration;
00058 }
00059 #ifdef SIG_INTERRUPT1
00060 else if(interruptNum == EXTINT1)
00061 {
00062 MCUCR &= ~((1<<ISC11) | (1<<ISC10));
00063 MCUCR |= configuration<<2;
00064 }
00065 #endif
00066 #ifdef SIG_INTERRUPT2
00067 else if(interruptNum == EXTINT2)
00068 {
00069 if(configuration == EXTINT_EDGE_RISING)
00070 sbi(MCUCSR, ISC2);
00071 else
00072 cbi(MCUCSR, ISC2);
00073 }
00074 #endif
00075
00076
00077
00078 }
00079
00080
00081 void extintAttach(u08 interruptNum, void (*userHandler)(void) )
00082 {
00083
00084 if(interruptNum < EXTINT_NUM_INTERRUPTS)
00085 {
00086
00087
00088 ExtIntFunc[interruptNum] = userHandler;
00089 }
00090 }
00091
00092
00093 void extintDetach(u08 interruptNum)
00094 {
00095
00096 if(interruptNum < EXTINT_NUM_INTERRUPTS)
00097 {
00098
00099
00100 ExtIntFunc[interruptNum] = 0;
00101 }
00102 }
00103
00104
00105 EXTINT_INTERRUPT_HANDLER(SIG_INTERRUPT0)
00106 {
00107
00108 if(ExtIntFunc[EXTINT0])
00109 ExtIntFunc[EXTINT0]();
00110 }
00111
00112 #ifdef SIG_INTERRUPT1
00113
00114 EXTINT_INTERRUPT_HANDLER(SIG_INTERRUPT1)
00115 {
00116
00117 if(ExtIntFunc[EXTINT1])
00118 ExtIntFunc[EXTINT1]();
00119 }
00120 #endif
00121
00122 #ifdef SIG_INTERRUPT2
00123
00124 EXTINT_INTERRUPT_HANDLER(SIG_INTERRUPT2)
00125 {
00126
00127 if(ExtIntFunc[EXTINT2])
00128 ExtIntFunc[EXTINT2]();
00129 }
00130 #endif
00131
00132 #ifdef SIG_INTERRUPT3
00133
00134 EXTINT_INTERRUPT_HANDLER(SIG_INTERRUPT3)
00135 {
00136
00137 if(ExtIntFunc[EXTINT3])
00138 ExtIntFunc[EXTINT3]();
00139 }
00140 #endif
00141
00142 #ifdef SIG_INTERRUPT4
00143
00144 EXTINT_INTERRUPT_HANDLER(SIG_INTERRUPT4)
00145 {
00146
00147 if(ExtIntFunc[EXTINT4])
00148 ExtIntFunc[EXTINT4]();
00149 }
00150 #endif
00151
00152 #ifdef SIG_INTERRUPT5
00153
00154 EXTINT_INTERRUPT_HANDLER(SIG_INTERRUPT5)
00155 {
00156
00157 if(ExtIntFunc[EXTINT5])
00158 ExtIntFunc[EXTINT5]();
00159 }
00160 #endif
00161
00162 #ifdef SIG_INTERRUPT6
00163
00164 EXTINT_INTERRUPT_HANDLER(SIG_INTERRUPT6)
00165 {
00166
00167 if(ExtIntFunc[EXTINT6])
00168 ExtIntFunc[EXTINT6]();
00169 }
00170 #endif
00171
00172 #ifdef SIG_INTERRUPT7
00173
00174 EXTINT_INTERRUPT_HANDLER(SIG_INTERRUPT7)
00175 {
00176
00177 if(ExtIntFunc[EXTINT7])
00178 ExtIntFunc[EXTINT7]();
00179 }
00180 #endif
00181