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: ihndlr.c,v $ 00036 * Revision 1.7 2008/07/26 09:38:02 haraldkipp 00037 * Added support for NUT_IRQMODE_NONE and NUT_IRQMODE_LEVEL. 00038 * 00039 * Revision 1.6 2006/10/08 16:48:09 haraldkipp 00040 * Documentation fixed 00041 * 00042 * Revision 1.5 2006/01/05 16:51:54 haraldkipp 00043 * NutIrqSetPriority() didn't correctly return the previous priority. This 00044 * bug has been fixed. 00045 * New function NutIrqSetMode() allows to modify the interrupt modes. 00046 * 00047 * Revision 1.4 2005/10/24 10:17:24 haraldkipp 00048 * New API functions added to create platform independant drivers. 00049 * Interrupt counting requires NUT_PERFMON to be defined. 00050 * 00051 * Revision 1.3 2005/08/02 17:46:47 haraldkipp 00052 * Major API documentation update. 00053 * 00054 * Revision 1.2 2005/07/26 16:30:58 haraldkipp 00055 * Copyright added. 00056 * Temporarily exclude NutRegisterIrqHandler() from Linux builds. 00057 * 00058 */ 00059 00060 #include <sys/atom.h> 00061 #include <dev/irqreg.h> 00062 00067 00071 void CallHandler(IRQ_HANDLER * irh) 00072 { 00073 #ifdef NUT_PERFMON 00074 irh->ir_count++; 00075 #endif 00076 if (irh->ir_handler) 00077 (irh->ir_handler) (irh->ir_arg); 00078 } 00079 00094 #if !defined (__linux__) && !defined(__APPLE__) && !defined(__CYGWIN__) 00095 int NutRegisterIrqHandler(IRQ_HANDLER * irq, void (*handler) (void *), void *arg) 00096 { 00097 int rc = 0; 00098 00099 /* Initialize this interrupt. */ 00100 if (irq->ir_ctl) { 00101 rc = (irq->ir_ctl) (NUT_IRQCTL_INIT, NULL); 00102 } 00103 00104 /* Set the interrupt handler. */ 00105 irq->ir_arg = arg; 00106 irq->ir_handler = handler; 00107 00108 return rc; 00109 } 00110 00118 int NutIrqEnable(IRQ_HANDLER * irq) 00119 { 00120 int rc = -1; 00121 00122 if (irq->ir_ctl) { 00123 rc = (irq->ir_ctl) (NUT_IRQCTL_ENABLE, NULL); 00124 } 00125 return rc; 00126 } 00127 00135 int NutIrqDisable(IRQ_HANDLER * irq) 00136 { 00137 int rc = -1; 00138 00139 if (irq->ir_ctl) { 00140 rc = (irq->ir_ctl) (NUT_IRQCTL_DISABLE, NULL); 00141 } 00142 return rc; 00143 } 00144 00160 int NutIrqSetPriority(IRQ_HANDLER * irq, int level) 00161 { 00162 int rc = -1; 00163 00164 if (irq->ir_ctl) { 00165 int prev; 00166 00167 rc = (irq->ir_ctl) (NUT_IRQCTL_GETPRIO, &prev); 00168 if (rc == 0 && (rc = (irq->ir_ctl) (NUT_IRQCTL_SETPRIO, &level)) == 0) { 00169 rc = prev; 00170 } 00171 } 00172 return rc; 00173 } 00174 00198 int NutIrqSetMode(IRQ_HANDLER * irq, int mode) 00199 { 00200 int rc = -1; 00201 00202 if (irq->ir_ctl) { 00203 int prev; 00204 00205 rc = (irq->ir_ctl) (NUT_IRQCTL_GETMODE, &prev); 00206 if (rc == 0 && (mode == NUT_IRQMODE_NONE || (rc = (irq->ir_ctl) (NUT_IRQCTL_SETMODE, &mode)) == 0)) { 00207 rc = prev; 00208 } 00209 } 00210 return rc; 00211 } 00212 00213 #endif 00214