Nut/OS  4.10.3
API Reference
ih_at91irq1.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$
00036  * Revision 1.5  2009/01/30 08:55:23  haraldkipp
00037  * Enable IRQ clocks.
00038  *
00039  * Revision 1.4  2008/08/11 06:59:10  haraldkipp
00040  * BSD types replaced by stdint types (feature request #1282721).
00041  *
00042  * Revision 1.3  2006/06/28 17:10:15  haraldkipp
00043  * Include more general header file for ARM.
00044  *
00045  * Revision 1.2  2006/04/07 12:21:43  haraldkipp
00046  * Added missing IRQ sense settings.
00047  *
00048  * Revision 1.1  2005/10/24 08:56:09  haraldkipp
00049  * First check in.
00050  *
00051  */
00052 
00053 #include <arch/arm.h>
00054 #include <dev/irqreg.h>
00055 
00056 #ifndef NUT_IRQPRI_IRQ1
00057 #define NUT_IRQPRI_IRQ1  4
00058 #endif
00059 
00060 static int Interrupt1Ctl(int cmd, void *param);
00061 
00062 IRQ_HANDLER sig_INTERRUPT1 = {
00063 #ifdef NUT_PERFMON
00064     0,                  /* Interrupt counter, ir_count. */
00065 #endif
00066     NULL,               /* Passed argument, ir_arg. */
00067     NULL,               /* Handler subroutine, ir_handler. */
00068     Interrupt1Ctl       /* Interrupt control, ir_ctl. */
00069 };
00070 
00074 static void Interrupt1Entry(void) __attribute__ ((naked));
00075 void Interrupt1Entry(void)
00076 {
00077     IRQ_ENTRY();
00078 #ifdef NUT_PERFMON
00079     sig_INTERRUPT1.ir_count++;
00080 #endif
00081     if (sig_INTERRUPT1.ir_handler) {
00082         (sig_INTERRUPT1.ir_handler) (sig_INTERRUPT1.ir_arg);
00083     }
00084     IRQ_EXIT();
00085 }
00086 
00102 static int Interrupt1Ctl(int cmd, void *param)
00103 {
00104     int rc = 0;
00105     unsigned int *ival = (unsigned int *)param;
00106     int_fast8_t enabled = inr(AIC_IMR) & _BV(IRQ1_ID);
00107 
00108     /* Disable interrupt. */
00109     if (enabled) {
00110         outr(AIC_IDCR, _BV(IRQ1_ID));
00111     }
00112 
00113     switch(cmd) {
00114     case NUT_IRQCTL_INIT:
00115         /* Set the vector. */
00116         outr(AIC_SVR(IRQ1_ID), (unsigned int)Interrupt1Entry);
00117         /* Initialize to edge triggered with defined priority. */
00118         outr(AIC_SMR(IRQ1_ID), AIC_SRCTYPE_EXT_HIGH_LEVEL | NUT_IRQPRI_IRQ1);
00119         /* Clear interrupt */
00120         outr(AIC_ICCR, _BV(IRQ1_ID));
00121         break;
00122     case NUT_IRQCTL_STATUS:
00123         if (enabled) {
00124             *ival |= 1;
00125         }
00126         else {
00127             *ival &= ~1;
00128         }
00129         break;
00130     case NUT_IRQCTL_ENABLE:
00131         enabled = 1;
00132         break;
00133     case NUT_IRQCTL_DISABLE:
00134         enabled = 0;
00135         break;
00136     case NUT_IRQCTL_GETMODE:
00137         {
00138             unsigned int val = inr(AIC_SMR(IRQ1_ID)) & AIC_SRCTYPE;
00139             if (val == AIC_SRCTYPE_EXT_LOW_LEVEL) {
00140                 *ival = NUT_IRQMODE_LOWLEVEL;
00141             } else if (val == AIC_SRCTYPE_EXT_HIGH_LEVEL) {
00142                 *ival = NUT_IRQMODE_HIGHLEVEL;
00143             } else if (val == AIC_SRCTYPE_EXT_POSITIVE_EDGE) {
00144                 *ival = NUT_IRQMODE_RISINGEDGE;
00145             } else  {
00146                 *ival = NUT_IRQMODE_FALLINGEDGE;
00147             }
00148         }
00149         break;
00150     case NUT_IRQCTL_SETMODE:
00151         if (*ival == NUT_IRQMODE_LOWLEVEL) {
00152             outr(AIC_SMR(IRQ1_ID), (inr(AIC_SMR(IRQ1_ID)) & ~AIC_SRCTYPE) | AIC_SRCTYPE_EXT_LOW_LEVEL);
00153         } else if (*ival == NUT_IRQMODE_HIGHLEVEL) {
00154             outr(AIC_SMR(IRQ1_ID), (inr(AIC_SMR(IRQ1_ID)) & ~AIC_SRCTYPE) | AIC_SRCTYPE_EXT_HIGH_LEVEL);
00155         } else if (*ival == NUT_IRQMODE_FALLINGEDGE) {
00156             outr(AIC_SMR(IRQ1_ID), (inr(AIC_SMR(IRQ1_ID)) & ~AIC_SRCTYPE) | AIC_SRCTYPE_EXT_NEGATIVE_EDGE);
00157         } else  if (*ival == NUT_IRQMODE_RISINGEDGE) {
00158             outr(AIC_SMR(IRQ1_ID), (inr(AIC_SMR(IRQ1_ID)) & ~AIC_SRCTYPE) | AIC_SRCTYPE_EXT_POSITIVE_EDGE);
00159         } else  {
00160             rc = -1;
00161         }
00162         break;
00163     case NUT_IRQCTL_GETPRIO:
00164         *ival = inr(AIC_SMR(IRQ1_ID)) & AIC_PRIOR;
00165         break;
00166     case NUT_IRQCTL_SETPRIO:
00167         outr(AIC_SMR(IRQ1_ID), (inr(AIC_SMR(IRQ1_ID)) & ~AIC_PRIOR) | *ival);
00168         break;
00169 #ifdef NUT_PERFMON
00170     case NUT_IRQCTL_GETCOUNT:
00171         *ival = (unsigned int)sig_INTERRUPT1.ir_count;
00172         sig_INTERRUPT1.ir_count = 0;
00173         break;
00174 #endif
00175     default:
00176         rc = -1;
00177         break;
00178     }
00179 
00180     /* Enable interrupt. */
00181     if (enabled) {
00182         outr(AIC_IECR, _BV(IRQ1_ID));
00183 #if defined(PMC_PCER)
00184         outr(PMC_PCER, _BV(IRQ1_ID));
00185 #endif
00186     }
00187     return rc;
00188 }
00189