ih_at91adc.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2001-2005 by EmbeddedIT, 
00003  * Ole Reinhardt <ole.reinhardt@embedded-it.de> All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * 1. Redistributions of source code must retain the above copyright
00010  *    notice, this list of conditions and the following disclaimer.
00011  * 2. Redistributions in binary form must reproduce the above copyright
00012  *    notice, this list of conditions and the following disclaimer in the
00013  *    documentation and/or other materials provided with the distribution.
00014  * 3. Neither the name of the copyright holders nor the names of
00015  *    contributors may be used to endorse or promote products derived
00016  *    from this software without specific prior written permission.
00017  *
00018  * THIS SOFTWARE IS PROVIDED BY EMBEDDED IT AND CONTRIBUTORS
00019  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00020  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00021  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL EMBEDDED IT
00022  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
00023  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
00024  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
00025  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
00026  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
00027  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
00028  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029  *
00030  * For additional information see http://www.ethernut.de/
00031  *
00032  */
00033 
00034 /*
00035  * $Log: ih_at91adc.c,v $
00036  * Revision 1.1  2007/12/09 21:36:05  olereinhardt
00037  * Initial checkin of adc irq handler
00038  *
00039  */
00040 
00041 #include <arch/arm.h>
00042 #include <dev/irqreg.h>
00043 
00044 #if defined(ADC_ID)
00045 
00046 #ifndef NUT_IRQPRI_ADC
00047 #define NUT_IRQPRI_ADC  4
00048 #endif
00049 
00050 static int AdcIrqCtl(int cmd, void *param);
00051 
00052 IRQ_HANDLER sig_ADC = {
00053 #ifdef NUT_PERFMON
00054     0,                  /* Interrupt counter, ir_count. */
00055 #endif
00056     NULL,               /* Passed argument, ir_arg. */
00057     NULL,               /* Handler subroutine, ir_handler. */
00058     AdcIrqCtl           /* Interrupt control, ir_ctl. */
00059 };
00060 
00064 static void AdcIrqEntry(void) __attribute__ ((naked));
00065 void AdcIrqEntry(void)
00066 {
00067     IRQ_ENTRY();
00068 #ifdef NUT_PERFMON
00069     sig_ADC.ir_count++;
00070 #endif
00071     if (sig_ADC.ir_handler) {
00072         (sig_ADC.ir_handler) (sig_ADC.ir_arg);
00073     }
00074     IRQ_EXIT();
00075 }
00076 
00092 static int AdcIrqCtl(int cmd, void *param)
00093 {
00094     int rc = 0;
00095     u_int *ival = (u_int *)param;
00096     int enabled = inr(AIC_IMR) & _BV(ADC_ID);
00097 
00098     /* Disable interrupt. */
00099     if (enabled) {
00100         outr(AIC_IDCR, _BV(ADC_ID));
00101     }
00102 
00103     switch(cmd) {
00104     case NUT_IRQCTL_INIT:
00105         /* Set the vector. */
00106         outr(AIC_SVR(ADC_ID), (unsigned int)AdcIrqEntry);
00107         /* Initialize to edge triggered with defined priority. */
00108         outr(AIC_SMR(ADC_ID), AIC_SRCTYPE_INT_EDGE_TRIGGERED | NUT_IRQPRI_ADC);
00109         /* Clear interrupt */
00110         outr(AIC_ICCR, _BV(ADC_ID));
00111         break;
00112     case NUT_IRQCTL_STATUS:
00113         if (enabled) {
00114             *ival |= 1;
00115         }
00116         else {
00117             *ival &= ~1;
00118         }
00119         break;
00120     case NUT_IRQCTL_ENABLE:
00121         enabled = 1;
00122         break;
00123     case NUT_IRQCTL_DISABLE:
00124         enabled = 0;
00125         break;
00126     case NUT_IRQCTL_GETPRIO:
00127         *ival = inr(AIC_SMR(ADC_ID)) & AIC_PRIOR;
00128         break;
00129     case NUT_IRQCTL_SETPRIO:
00130         outr(AIC_SMR(ADC_ID), (inr(AIC_SMR(ADC_ID)) & ~AIC_PRIOR) | *ival);
00131         break;
00132 #ifdef NUT_PERFMON
00133     case NUT_IRQCTL_GETCOUNT:
00134         *ival = (u_int)sig_ADC.ir_count;
00135         sig_ADC.ir_count = 0;
00136         break;
00137 #endif
00138     default:
00139         rc = -1;
00140         break;
00141     }
00142 
00143     /* Enable interrupt. */
00144     if (enabled) {
00145         outr(AIC_IECR, _BV(ADC_ID));
00146     }
00147     return rc;
00148 }
00149 
00150 #endif /* ADC_ID */

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