Go to the documentation of this file.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
00029
00030
00031
00032
00033
00076 #include <dev/irqreg.h>
00077
00082
00083 static int AvrInterrupt1Ctl(int cmd, void *param);
00084
00085 IRQ_HANDLER sig_INTERRUPT1 = {
00086 #ifdef NUT_PERFMON
00087 0,
00088 #endif
00089 NULL,
00090 NULL,
00091 AvrInterrupt1Ctl
00092 };
00093
00111 static int AvrInterrupt1Ctl(int cmd, void *param)
00112 {
00113 int rc = 0;
00114 unsigned int *ival = (unsigned int *) param;
00115 int_fast8_t enabled = bit_is_set(EIMSK, INT1);
00116
00117
00118 cbi(EIMSK, INT1);
00119
00120 switch (cmd) {
00121 case NUT_IRQCTL_INIT:
00122 #ifdef __AVR_ENHANCED__
00123
00124 cbi(EICRA, ISC10);
00125 cbi(EICRA, ISC11);
00126 #endif
00127 case NUT_IRQCTL_CLEAR:
00128 #ifdef __AVR_ENHANCED__
00129
00130 outb(EIFR, _BV(INTF1));
00131 #endif
00132 break;
00133 case NUT_IRQCTL_STATUS:
00134 #ifdef __AVR_ENHANCED__
00135 if (bit_is_set(EIFR, INTF1)) {
00136 *ival = 1;
00137 } else {
00138 *ival = 0;
00139 }
00140 #else
00141 *ival = 0;
00142 #endif
00143 if (enabled) {
00144 *ival |= 0x80;
00145 }
00146 break;
00147 case NUT_IRQCTL_ENABLE:
00148 enabled = 1;
00149 break;
00150 case NUT_IRQCTL_DISABLE:
00151 enabled = 0;
00152 break;
00153 case NUT_IRQCTL_GETMODE:
00154 #ifdef __AVR_ENHANCED__
00155 {
00156 uint8_t bval = inb(EICRA) & (_BV(ISC11) | _BV(ISC10));
00157 if (bval == _BV(ISC11)) {
00158 *ival = NUT_IRQMODE_FALLINGEDGE;
00159 } else if (bval == _BV(ISC11 | ISC10)) {
00160 *ival = NUT_IRQMODE_RISINGEDGE;
00161 } else {
00162 *ival = NUT_IRQMODE_LOWLEVEL;
00163 }
00164 }
00165 #else
00166 *ival = NUT_IRQMODE_LOWLEVEL;
00167 #endif
00168 break;
00169 case NUT_IRQCTL_SETMODE:
00170 #ifdef __AVR_ENHANCED__
00171 if (*ival == NUT_IRQMODE_LOWLEVEL) {
00172 cbi(EICRA, ISC10);
00173 cbi(EICRA, ISC11);
00174 } else if (*ival == NUT_IRQMODE_FALLINGEDGE) {
00175 cbi(EICRA, ISC10);
00176 sbi(EICRA, ISC11);
00177 } else if (*ival == NUT_IRQMODE_RISINGEDGE) {
00178 sbi(EICRA, ISC10);
00179 sbi(EICRA, ISC11);
00180 } else {
00181 rc = -1;
00182 }
00183 #else
00184 if (*ival != NUT_IRQMODE_LOWLEVEL) {
00185 rc = -1;
00186 }
00187 #endif
00188 break;
00189 case NUT_IRQCTL_GETPRIO:
00190 *ival = 1;
00191 break;
00192 #ifdef NUT_PERFMON
00193 case NUT_IRQCTL_GETCOUNT:
00194 *ival = (unsigned int) sig_INTERRUPT1.ir_count;
00195 sig_INTERRUPT1.ir_count = 0;
00196 break;
00197 #endif
00198 default:
00199 rc = -1;
00200 break;
00201 }
00202
00203
00204 if (enabled) {
00205 sbi(EIMSK, INT1);
00206 }
00207 return rc;
00208 }
00209
00213 #ifdef __IMAGECRAFT__
00214 #pragma interrupt_handler SIG_INTERRUPT1:iv_INT1
00215 #endif
00216 NUTSIGNAL(SIG_INTERRUPT1, sig_INTERRUPT1)
00217
00218