catch_interrupt.c

来自「这是leon3处理器的交叉编译链」· C语言 代码 · 共 102 行

C
102
字号
/*    LEON2/3 LIBIO low-level routines     Written by Jiri Gaisler.    Copyright (C) 2004  Gaisler Research AB    This program is free software; you can redistribute it and/or modify    it under the terms of the GNU General Public License as published by    the Free Software Foundation; either version 2 of the License, or    (at your option) any later version.    This program is distributed in the hope that it will be useful,    but WITHOUT ANY WARRANTY; without even the implied warranty of    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    GNU General Public License for more details.    You should have received a copy of the GNU General Public License    along with this program; if not, write to the Free Software    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA*/#include <asm-leon/leonstack.h>#include <asm-leon/irq.h>#define NULL 0struct irqaction *_irqtbl[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};struct irqaction _oirqtbl[16] = { INIT_IRQACTION,INIT_IRQACTION,INIT_IRQACTION,INIT_IRQACTION,				  INIT_IRQACTION,INIT_IRQACTION,INIT_IRQACTION,INIT_IRQACTION,				  INIT_IRQACTION,INIT_IRQACTION,INIT_IRQACTION,INIT_IRQACTION,				  INIT_IRQACTION,INIT_IRQACTION,INIT_IRQACTION,INIT_IRQACTION };int catch_interrupt (int func, int irq) {  struct irqaction *a = _irqtbl[irq];  struct irqaction *n = &_oirqtbl[irq];  while (a) {    if (a == n) {      int tmp = (int) a->handler;      a->handler = (irqhandler)func;      return tmp;    }    a = a ->next;  }  n->handler = (irqhandler)func;  chained_catch_interrupt(irq,n);  return 0;}void chained_catch_interrupt (int irq, struct irqaction *a ) {  a ->next = _irqtbl[irq];  _irqtbl[irq] = a;}int inirq = 0;handler_irq (int irq, struct leonbare_pt_regs *pt_regs) {   struct irqaction *a = _irqtbl[irq];  while (a) {    if (a->handler) {#ifndef CONFIG_LEONBARE_NONESTEDIRQ      if (!inirq) {#endif      	inirq = 1;	a->handler(irq, a->dev_id, pt_regs);	inirq = 0;#ifndef CONFIG_LEONBARE_NONESTEDIRQ      }#endif          }    a = a ->next;  }}schedulehandler schedule_callback = 0;// '''''''''''''''''''''''''''''''''''''''''''''''''''''TAILQ_HEAD(pending_queue,pendingaction) pending = TAILQ_HEAD_INITIALIZER(pending); void add_pending(struct pendingaction *a) {  unsigned long old = leonbare_disable_traps();  TAILQ_INSERT_TAIL(&pending,a,next);  leonbare_enable_traps(old);}struct pendingaction *get_pending() {  struct pendingaction *a = 0;  unsigned long old = leonbare_disable_traps();  if (a = TAILQ_FIRST(&pending)) {    TAILQ_REMOVE(&pending,a,next);  }  leonbare_enable_traps(old);  return a;}void process_pending() {  struct pendingaction *a;  while(a = get_pending()) {    if (a->handler) {      a->handler(a->arg);    }  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?