ih_at91fiq.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 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 
00034 /*
00035  * $Log: ih_at91fiq.c,v $
00036  * Revision 1.4  2008/07/26 09:43:01  haraldkipp
00037  * Added support for retrieving and setting the interrupt mode.
00038  *
00039  * Revision 1.3  2006/06/28 17:10:15  haraldkipp
00040  * Include more general header file for ARM.
00041  *
00042  * Revision 1.2  2006/04/07 12:19:51  haraldkipp
00043  * Fast interrupts are now enabled correctly.
00044  * Mode set/get ioctl added and priority set/get removed.
00045  * Interrupt entry will no longer push R8-R12 on stack.
00046  *
00047  * Revision 1.1  2005/10/24 08:56:09  haraldkipp
00048  * First check in.
00049  *
00050  */
00051 
00052 #include <arch/arm.h>
00053 #include <dev/irqreg.h>
00054 
00055 #ifndef NUT_IRQPRI_FIQ
00056 #define NUT_IRQPRI_FIQ  4
00057 #endif
00058 
00059 static int FastIrqCtl(int cmd, void *param);
00060 
00061 IRQ_HANDLER sig_FIQ = {
00062 #ifdef NUT_PERFMON
00063     0,              /* Interrupt counter, ir_count. */
00064 #endif
00065     NULL,           /* Passed argument, ir_arg. */
00066     NULL,           /* Handler subroutine, ir_handler. */
00067     FastIrqCtl      /* Interrupt control, ir_ctl. */
00068 };
00069 
00075 static void FastIrqEntry(void) __attribute__ ((naked));
00076 void FastIrqEntry(void)
00077 {
00078     FIQ_ENTRY();
00079 #ifdef NUT_PERFMON
00080     sig_FIQ.ir_count++;
00081 #endif
00082     if (sig_FIQ.ir_handler) {
00083         (sig_FIQ.ir_handler) (sig_FIQ.ir_arg);
00084     }
00085     FIQ_EXIT();
00086 }
00087 
00103 static int FastIrqCtl(int cmd, void *param)
00104 {
00105     int rc = 0;
00106     u_int *ival = (u_int *)param;
00107     int enabled = inr(AIC_IMR) & _BV(FIQ_ID);
00108 
00109     /* Disable interrupt. */
00110     if (enabled) {
00111         outr(AIC_IDCR, _BV(FIQ_ID));
00112     }
00113 
00114     switch(cmd) {
00115     case NUT_IRQCTL_INIT:
00116         /* Set the vector. */
00117         outr(AIC_SVR(FIQ_ID), (unsigned int)FastIrqEntry);
00118         /* Initialize to edge triggered with defined priority. */
00119         outr(AIC_SMR(FIQ_ID), AIC_SRCTYPE_EXT_NEGATIVE_EDGE | NUT_IRQPRI_FIQ);
00120         /* Clear interrupt */
00121         outr(AIC_ICCR, _BV(FIQ_ID));
00122         break;
00123     case NUT_IRQCTL_STATUS:
00124         if (enabled) {
00125             *ival |= 1;
00126         }
00127         else {
00128             *ival &= ~1;
00129         }
00130         break;
00131     case NUT_IRQCTL_ENABLE:
00132         enabled = 1;
00133         break;
00134     case NUT_IRQCTL_DISABLE:
00135         enabled = 0;
00136         break;
00137     case NUT_IRQCTL_GETMODE:
00138         {
00139             u_int val = inr(AIC_SMR(FIQ_ID)) & AIC_SRCTYPE;
00140             if (val == AIC_SRCTYPE_EXT_LOW_LEVEL) {
00141                 *ival = NUT_IRQMODE_LOWLEVEL;
00142             } else if (val == AIC_SRCTYPE_EXT_HIGH_LEVEL) {
00143                 *ival = NUT_IRQMODE_HIGHLEVEL;
00144             } else if (val == AIC_SRCTYPE_EXT_POSITIVE_EDGE) {
00145                 *ival = NUT_IRQMODE_RISINGEDGE;
00146             } else  {
00147                 *ival = NUT_IRQMODE_FALLINGEDGE;
00148             }
00149         }
00150         break;
00151     case NUT_IRQCTL_SETMODE:
00152         if (*ival == NUT_IRQMODE_LOWLEVEL) {
00153             outr(AIC_SMR(FIQ_ID), (inr(AIC_SMR(FIQ_ID)) & ~AIC_SRCTYPE) | AIC_SRCTYPE_EXT_LOW_LEVEL);
00154         } else if (*ival == NUT_IRQMODE_HIGHLEVEL) {
00155             outr(AIC_SMR(FIQ_ID), (inr(AIC_SMR(FIQ_ID)) & ~AIC_SRCTYPE) | AIC_SRCTYPE_EXT_HIGH_LEVEL);
00156         } else if (*ival == NUT_IRQMODE_FALLINGEDGE) {
00157             outr(AIC_SMR(FIQ_ID), (inr(AIC_SMR(FIQ_ID)) & ~AIC_SRCTYPE) | AIC_SRCTYPE_EXT_NEGATIVE_EDGE);
00158         } else  if (*ival == NUT_IRQMODE_RISINGEDGE) {
00159             outr(AIC_SMR(FIQ_ID), (inr(AIC_SMR(FIQ_ID)) & ~AIC_SRCTYPE) | AIC_SRCTYPE_EXT_POSITIVE_EDGE);
00160         } else  {
00161             rc = -1;
00162         }
00163         break;
00164 #ifdef NUT_PERFMON
00165     case NUT_IRQCTL_GETCOUNT:
00166         *ival = (u_int)sig_FIQ.ir_count;
00167         sig_FIQ.ir_count = 0;
00168         break;
00169 #endif
00170     default:
00171         rc = -1;
00172         break;
00173     }
00174 
00175     /* Enable interrupt. */
00176     if (enabled) {
00177         outr(AIC_IECR, _BV(FIQ_ID));
00178     }
00179     return rc;
00180 }

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