00001 /* 00002 * Copyright (C) 2001-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.8 2009/03/05 22:16:57 freckle 00037 * use __NUT_EMULATION instead of __APPLE__, __linux__, or __CYGWIN__ 00038 * 00039 * Revision 1.7 2008/07/26 09:38:02 haraldkipp 00040 * Added support for NUT_IRQMODE_NONE and NUT_IRQMODE_LEVEL. 00041 * 00042 * Revision 1.6 2006/10/08 16:48:09 haraldkipp 00043 * Documentation fixed 00044 * 00045 * Revision 1.5 2006/01/05 16:51:54 haraldkipp 00046 * NutIrqSetPriority() didn't correctly return the previous priority. This 00047 * bug has been fixed. 00048 * New function NutIrqSetMode() allows to modify the interrupt modes. 00049 * 00050 * Revision 1.4 2005/10/24 10:17:24 haraldkipp 00051 * New API functions added to create platform independant drivers. 00052 * Interrupt counting requires NUT_PERFMON to be defined. 00053 * 00054 * Revision 1.3 2005/08/02 17:46:47 haraldkipp 00055 * Major API documentation update. 00056 * 00057 * Revision 1.2 2005/07/26 16:30:58 haraldkipp 00058 * Copyright added. 00059 * Temporarily exclude NutRegisterIrqHandler() from Linux builds. 00060 * 00061 */ 00062 00063 #include <sys/atom.h> 00064 #include <dev/irqreg.h> 00065 00070 00074 void CallHandler(IRQ_HANDLER * irh) 00075 { 00076 #ifdef NUT_PERFMON 00077 irh->ir_count++; 00078 #endif 00079 if (irh->ir_handler) 00080 (irh->ir_handler) (irh->ir_arg); 00081 } 00082 00097 #ifndef __NUT_EMULATION__ 00098 int NutRegisterIrqHandler(IRQ_HANDLER * irq, void (*handler) (void *), void *arg) 00099 { 00100 int rc = 0; 00101 00102 /* Initialize this interrupt. */ 00103 if (irq->ir_ctl) { 00104 rc = (irq->ir_ctl) (NUT_IRQCTL_INIT, NULL); 00105 } 00106 00107 /* Set the interrupt handler. */ 00108 irq->ir_arg = arg; 00109 irq->ir_handler = handler; 00110 00111 return rc; 00112 } 00113 00121 int NutIrqEnable(IRQ_HANDLER * irq) 00122 { 00123 int rc = -1; 00124 00125 if (irq->ir_ctl) { 00126 rc = (irq->ir_ctl) (NUT_IRQCTL_ENABLE, NULL); 00127 } 00128 return rc; 00129 } 00130 00138 int NutIrqDisable(IRQ_HANDLER * irq) 00139 { 00140 int rc = -1; 00141 00142 if (irq->ir_ctl) { 00143 rc = (irq->ir_ctl) (NUT_IRQCTL_DISABLE, NULL); 00144 } 00145 return rc; 00146 } 00147 00163 int NutIrqSetPriority(IRQ_HANDLER * irq, int level) 00164 { 00165 int rc = -1; 00166 00167 if (irq->ir_ctl) { 00168 int prev; 00169 00170 rc = (irq->ir_ctl) (NUT_IRQCTL_GETPRIO, &prev); 00171 if (rc == 0 && (rc = (irq->ir_ctl) (NUT_IRQCTL_SETPRIO, &level)) == 0) { 00172 rc = prev; 00173 } 00174 } 00175 return rc; 00176 } 00177 00201 int NutIrqSetMode(IRQ_HANDLER * irq, int mode) 00202 { 00203 int rc = -1; 00204 00205 if (irq->ir_ctl) { 00206 int prev; 00207 00208 rc = (irq->ir_ctl) (NUT_IRQCTL_GETMODE, &prev); 00209 if (rc == 0 && (mode == NUT_IRQMODE_NONE || (rc = (irq->ir_ctl) (NUT_IRQCTL_SETMODE, &mode)) == 0)) { 00210 rc = prev; 00211 } 00212 } 00213 return rc; 00214 } 00215 00216 #endif 00217