ih_at91twi.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_at91twi.c,v $
00036  * Revision 1.1  2007/09/06 19:36:00  olereinhardt
00037  * First checkin, new twi driver for at91 (currently SAM7X256 is supported
00038  * only)
00039  *
00040  *
00041  */
00042 
00043 #include <arch/arm.h>
00044 #include <dev/irqreg.h>
00045 
00046 #if defined(TWI_ID)
00047 
00048 #ifndef NUT_IRQPRI_TWI
00049 #define NUT_IRQPRI_TWI  4
00050 #endif
00051 
00052 static int TwoWireIrqCtl(int cmd, void *param);
00053 
00054 IRQ_HANDLER sig_TWI = {
00055 #ifdef NUT_PERFMON
00056     0,                  /* Interrupt counter, ir_count. */
00057 #endif
00058     NULL,               /* Passed argument, ir_arg. */
00059     NULL,               /* Handler subroutine, ir_handler. */
00060     TwoWireIrqCtl       /* Interrupt control, ir_ctl. */
00061 };
00062 
00066 static void TwoWireIrqEntry(void) __attribute__ ((naked));
00067 void TwoWireIrqEntry(void)
00068 {
00069     IRQ_ENTRY();
00070 #ifdef NUT_PERFMON
00071     sig_TWI.ir_count++;
00072 #endif
00073     if (sig_TWI.ir_handler) {
00074         (sig_TWI.ir_handler) (sig_TWI.ir_arg);
00075     }
00076     IRQ_EXIT();
00077 }
00078 
00094 static int TwoWireIrqCtl(int cmd, void *param)
00095 {
00096     int rc = 0;
00097     u_int *ival = (u_int *)param;
00098     int enabled = inr(AIC_IMR) & _BV(TWI_ID);
00099 
00100     /* Disable interrupt. */
00101     if (enabled) {
00102         outr(AIC_IDCR, _BV(TWI_ID));
00103     }
00104 
00105     switch(cmd) {
00106     case NUT_IRQCTL_INIT:
00107         /* Set the vector. */
00108         outr(AIC_SVR(TWI_ID), (unsigned int)TwoWireIrqEntry);
00109         /* Initialize to edge triggered with defined priority. */
00110         outr(AIC_SMR(TWI_ID), AIC_SRCTYPE_INT_EDGE_TRIGGERED | NUT_IRQPRI_TWI);
00111         /* Clear interrupt */
00112         outr(AIC_ICCR, _BV(TWI_ID));
00113         break;
00114     case NUT_IRQCTL_STATUS:
00115         if (enabled) {
00116             *ival |= 1;
00117         }
00118         else {
00119             *ival &= ~1;
00120         }
00121         break;
00122     case NUT_IRQCTL_ENABLE:
00123         enabled = 1;
00124         break;
00125     case NUT_IRQCTL_DISABLE:
00126         enabled = 0;
00127         break;
00128     case NUT_IRQCTL_GETPRIO:
00129         *ival = inr(AIC_SMR(TWI_ID)) & AIC_PRIOR;
00130         break;
00131     case NUT_IRQCTL_SETPRIO:
00132         outr(AIC_SMR(TWI_ID), (inr(AIC_SMR(TWI_ID)) & ~AIC_PRIOR) | *ival);
00133         break;
00134 #ifdef NUT_PERFMON
00135     case NUT_IRQCTL_GETCOUNT:
00136         *ival = (u_int)sig_TWI.ir_count;
00137         sig_TWI.ir_count = 0;
00138         break;
00139 #endif
00140     default:
00141         rc = -1;
00142         break;
00143     }
00144 
00145     /* Enable interrupt. */
00146     if (enabled) {
00147         outr(AIC_IECR, _BV(TWI_ID));
00148     }
00149     return rc;
00150 }
00151 
00152 #endif /* TWI_ID */

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