ih_at91piob.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2005-2007 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 THE COPYRIGHT HOLDERS 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 THE
00021  * COPYRIGHT OWNER 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  * $Id: ih_at91piob.c,v 1.1 2008/01/31 09:27:36 haraldkipp Exp $
00036  */
00037 
00038 #include <arch/arm.h>
00039 #include <dev/irqreg.h>
00040 
00041 #if defined(PIOB_ID)
00042 
00043 #ifndef NUT_IRQPRI_PIOB
00044 #define NUT_IRQPRI_PIOB  4
00045 #endif
00046 
00047 static int PortIoIrqCtl(int cmd, void *param);
00048 
00049 IRQ_HANDLER sig_PIOB = {
00050 #ifdef NUT_PERFMON
00051     0,                  /* Interrupt counter, ir_count. */
00052 #endif
00053     NULL,               /* Passed argument, ir_arg. */
00054     NULL,               /* Handler subroutine, ir_handler. */
00055     PortIoIrqCtl        /* Interrupt control, ir_ctl. */
00056 };
00057 
00061 static void PortIoIrqEntry(void) __attribute__ ((naked));
00062 void PortIoIrqEntry(void)
00063 {
00064     IRQ_ENTRY();
00065 #ifdef NUT_PERFMON
00066     sig_PIOB.ir_count++;
00067 #endif
00068     if (sig_PIOB.ir_handler) {
00069         (sig_PIOB.ir_handler) (sig_PIOB.ir_arg);
00070     }
00071     IRQ_EXIT();
00072 }
00073 
00089 static int PortIoIrqCtl(int cmd, void *param)
00090 {
00091     int rc = 0;
00092     u_int *ival = (u_int *)param;
00093     int enabled = inr(AIC_IMR) & _BV(PIOB_ID);
00094 
00095     /* Disable interrupt. */
00096     if (enabled) {
00097         outr(AIC_IDCR, _BV(PIOB_ID));
00098     }
00099 
00100     switch(cmd) {
00101     case NUT_IRQCTL_INIT:
00102         /* Set the vector. */
00103         outr(AIC_SVR(PIOB_ID), (unsigned int)PortIoIrqEntry);
00104         /* Initialize to edge triggered with defined priority. */
00105         outr(AIC_SMR(PIOB_ID), AIC_SRCTYPE_INT_EDGE_TRIGGERED | NUT_IRQPRI_PIOB);
00106         /* Clear interrupt */
00107         outr(AIC_ICCR, _BV(PIOB_ID));
00108         break;
00109     case NUT_IRQCTL_STATUS:
00110         if (enabled) {
00111             *ival |= 1;
00112         }
00113         else {
00114             *ival &= ~1;
00115         }
00116         break;
00117     case NUT_IRQCTL_ENABLE:
00118         enabled = 1;
00119         break;
00120     case NUT_IRQCTL_DISABLE:
00121         enabled = 0;
00122         break;
00123     case NUT_IRQCTL_GETPRIO:
00124         *ival = inr(AIC_SMR(PIOB_ID)) & AIC_PRIOR;
00125         break;
00126     case NUT_IRQCTL_SETPRIO:
00127         outr(AIC_SMR(PIOB_ID), (inr(AIC_SMR(PIOB_ID)) & ~AIC_PRIOR) | *ival);
00128         break;
00129 #ifdef NUT_PERFMON
00130     case NUT_IRQCTL_GETCOUNT:
00131         *ival = (u_int)sig_PIOB.ir_count;
00132         sig_PIOB.ir_count = 0;
00133         break;
00134 #endif
00135     default:
00136         rc = -1;
00137         break;
00138     }
00139 
00140     /* Enable interrupt. */
00141     if (enabled) {
00142         outr(AIC_IECR, _BV(PIOB_ID));
00143     }
00144     return rc;
00145 }
00146 
00147 #endif /* PIOB_ID */

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