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