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.6 2006/10/08 16:48:09 haraldkipp 00037 * Documentation fixed 00038 * 00039 * Revision 1.5 2006/01/05 16:51:54 haraldkipp 00040 * NutIrqSetPriority() didn't correctly return the previous priority. This 00041 * bug has been fixed. 00042 * New function NutIrqSetMode() allows to modify the interrupt modes. 00043 * 00044 * Revision 1.4 2005/10/24 10:17:24 haraldkipp 00045 * New API functions added to create platform independant drivers. 00046 * Interrupt counting requires NUT_PERFMON to be defined. 00047 * 00048 * Revision 1.3 2005/08/02 17:46:47 haraldkipp 00049 * Major API documentation update. 00050 * 00051 * Revision 1.2 2005/07/26 16:30:58 haraldkipp 00052 * Copyright added. 00053 * Temporarily exclude NutRegisterIrqHandler() from Linux builds. 00054 * 00055 */ 00056 00057 #include <sys/atom.h> 00058 #include <dev/irqreg.h> 00059 00064 00068 void CallHandler(IRQ_HANDLER * irh) 00069 { 00070 #ifdef NUT_PERFMON 00071 irh->ir_count++; 00072 #endif 00073 if (irh->ir_handler) 00074 (irh->ir_handler) (irh->ir_arg); 00075 } 00076 00091 #if !defined (__linux__) && !defined(__APPLE__) && !defined(__CYGWIN__) 00092 int NutRegisterIrqHandler(IRQ_HANDLER * irq, void (*handler) (void *), void *arg) 00093 { 00094 int rc = 0; 00095 00096 /* Initialize this interrupt. */ 00097 if (irq->ir_ctl) { 00098 rc = (irq->ir_ctl) (NUT_IRQCTL_INIT, NULL); 00099 } 00100 00101 /* Set the interrupt handler. */ 00102 irq->ir_arg = arg; 00103 irq->ir_handler = handler; 00104 00105 return rc; 00106 } 00107 00115 int NutIrqEnable(IRQ_HANDLER * irq) 00116 { 00117 int rc = -1; 00118 00119 if (irq->ir_ctl) { 00120 rc = (irq->ir_ctl) (NUT_IRQCTL_ENABLE, NULL); 00121 } 00122 return rc; 00123 } 00124 00132 int NutIrqDisable(IRQ_HANDLER * irq) 00133 { 00134 int rc = -1; 00135 00136 if (irq->ir_ctl) { 00137 rc = (irq->ir_ctl) (NUT_IRQCTL_DISABLE, NULL); 00138 } 00139 return rc; 00140 } 00141 00157 int NutIrqSetPriority(IRQ_HANDLER * irq, int level) 00158 { 00159 int rc = -1; 00160 00161 if (irq->ir_ctl) { 00162 int prev; 00163 00164 rc = (irq->ir_ctl) (NUT_IRQCTL_GETPRIO, &prev); 00165 if (rc == 0 && (rc = (irq->ir_ctl) (NUT_IRQCTL_SETPRIO, &level)) == 0) { 00166 rc = prev; 00167 } 00168 } 00169 return rc; 00170 } 00171 00187 int NutIrqSetMode(IRQ_HANDLER * irq, int mode) 00188 { 00189 int rc = -1; 00190 00191 if (irq->ir_ctl) { 00192 int prev; 00193 00194 rc = (irq->ir_ctl) (NUT_IRQCTL_GETMODE, &prev); 00195 if (rc == 0 && (rc = (irq->ir_ctl) (NUT_IRQCTL_SETMODE, &mode)) == 0) { 00196 rc = prev; 00197 } 00198 } 00199 return rc; 00200 } 00201 00202 #endif 00203