ih_int1.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2001-2005 by egnite Software GmbH. All rights reserved.
00003  *
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions
00006  * are met:
00007  *
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. Neither the name of the copyright holders nor the names of
00014  *    contributors may be used to endorse or promote products derived
00015  *    from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY EGNITE SOFTWARE GMBH AND CONTRIBUTORS
00018  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00019  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00020  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL EGNITE
00021  * SOFTWARE GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00022  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00023  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
00024  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
00025  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00026  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
00027  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00028  * SUCH DAMAGE.
00029  *
00030  * For additional information see http://www.ethernut.de/
00031  *
00032  */
00033 
00073 #include <dev/irqreg.h>
00074 
00079 
00080 static int AvrInterrupt1Ctl(int cmd, void *param);
00081 
00082 IRQ_HANDLER sig_INTERRUPT1 = {
00083 #ifdef NUT_PERFMON
00084     0,                          /* Interrupt counter, ir_count. */
00085 #endif
00086     NULL,                       /* Passed argument, ir_arg. */
00087     NULL,                       /* Handler subroutine, ir_handler. */
00088     AvrInterrupt1Ctl            /* Interrupt control, ir_ctl. */
00089 };
00090 
00108 static int AvrInterrupt1Ctl(int cmd, void *param)
00109 {
00110     int rc = 0;
00111     u_int *ival = (u_int *) param;
00112     int enabled = bit_is_set(EIMSK, INT1);
00113 
00114     /* Disable interrupt. */
00115     cbi(EIMSK, INT1);
00116 
00117     switch (cmd) {
00118     case NUT_IRQCTL_INIT:
00119 #ifdef __AVR_ENHANCED__
00120         /* Initialize to low level triggered. */
00121         cbi(EICRA, ISC10);
00122         cbi(EICRA, ISC11);
00123 #endif
00124     case NUT_IRQCTL_CLEAR:
00125 #ifdef __AVR_ENHANCED__
00126         /* Clear any pending interrupt. */
00127         outb(EIFR, _BV(INTF1));
00128 #endif /* __AVR_ENHANCED__ */
00129         break;
00130     case NUT_IRQCTL_STATUS:
00131 #ifdef __AVR_ENHANCED__
00132         if (bit_is_set(EIFR, INTF1)) {
00133             *ival = 1;
00134         } else {
00135             *ival = 0;
00136         }
00137 #else /* !__AVR_ENHANCED__ */
00138         *ival = 0;
00139 #endif /* __AVR_ENHANCED__ */
00140         if (enabled) {
00141             *ival |= 0x80;
00142         }
00143         break;
00144     case NUT_IRQCTL_ENABLE:
00145         enabled = 1;
00146         break;
00147     case NUT_IRQCTL_DISABLE:
00148         enabled = 0;
00149         break;
00150     case NUT_IRQCTL_GETMODE:
00151 #ifdef __AVR_ENHANCED__
00152         {
00153             u_char bval = inb(EICRA) & (_BV(ISC11) | _BV(ISC10));
00154             if (bval == _BV(ISC11)) {
00155                 *ival = NUT_IRQMODE_FALLINGEDGE;
00156             } else if (bval == _BV(ISC11 | ISC10)) {
00157                 *ival = NUT_IRQMODE_RISINGEDGE;
00158             } else {
00159                 *ival = NUT_IRQMODE_LOWLEVEL;
00160             }
00161         }
00162 #else /* !__AVR_ENHANCED__ */
00163         *ival = NUT_IRQMODE_LOWLEVEL;
00164 #endif /* __AVR_ENHANCED__ */
00165         break;
00166     case NUT_IRQCTL_SETMODE:
00167 #ifdef __AVR_ENHANCED__
00168         if (*ival == NUT_IRQMODE_LOWLEVEL) {
00169             cbi(EICRA, ISC10);
00170             cbi(EICRA, ISC11);
00171         } else if (*ival == NUT_IRQMODE_FALLINGEDGE) {
00172             cbi(EICRA, ISC10);
00173             sbi(EICRA, ISC11);
00174         } else if (*ival == NUT_IRQMODE_RISINGEDGE) {
00175             sbi(EICRA, ISC10);
00176             sbi(EICRA, ISC11);
00177         } else {
00178             rc = -1;
00179         }
00180 #else /* !__AVR_ENHANCED__ */
00181         if (*ival != NUT_IRQMODE_LOWLEVEL) {
00182             rc = -1;
00183         }
00184 #endif /* __AVR_ENHANCED__ */
00185         break;
00186     case NUT_IRQCTL_GETPRIO:
00187         *ival = 1;
00188         break;
00189 #ifdef NUT_PERFMON
00190     case NUT_IRQCTL_GETCOUNT:
00191         *ival = (u_int) sig_INTERRUPT1.ir_count;
00192         sig_INTERRUPT1.ir_count = 0;
00193         break;
00194 #endif
00195     default:
00196         rc = -1;
00197         break;
00198     }
00199 
00200     /* Enable interrupt. */
00201     if (enabled) {
00202         sbi(EIMSK, INT1);
00203     }
00204     return rc;
00205 }
00206 
00210 #ifdef __IMAGECRAFT__
00211 #pragma interrupt_handler SIG_INTERRUPT1:iv_INT1
00212 #endif
00213 NUTSIGNAL(SIG_INTERRUPT1, sig_INTERRUPT1)
00214 
00215 

© 2000-2007 by egnite Software GmbH - visit http://www.ethernut.de/