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