Browse Source

fix irq.c

Signed-off-by: surenyi <surenyi82@qq.com>
bfsk
surenyi 3 years ago
parent
commit
36d412248a
  1. 37
      src/irq.c

37
src/irq.c

@ -1,4 +1,4 @@
#include <string.h> #include <stddef.h>
#include "platform.h" #include "platform.h"
#undef IRQ_VECTOR_MAX #undef IRQ_VECTOR_MAX
@ -97,11 +97,19 @@ static void __do_irq_vector(int index)
void irq_lowlevel_init() void irq_lowlevel_init()
{ {
int i;
struct irq_descr *irqd;
IRQ_resetAll(); IRQ_resetAll();
IRQ_globalDisable(); IRQ_globalDisable();
IRQ_nmiDisable(); IRQ_nmiDisable();
memset(&__irq_descr, 0, sizeof __irq_descr); for (i = 0; i < sizeof __irq_descr / sizeof __irq_descr[0]; ++i) {
irqd = &__irq_descr[i];
irqd->irq_handler = NULL;
irqd->args = NULL;
irqd->event_id = -1;
}
} }
unsigned int irq_global_disable() unsigned int irq_global_disable()
@ -119,7 +127,7 @@ void irq_global_enable()
IRQ_globalEnable(); IRQ_globalEnable();
} }
#if 0 #ifdef IRQ_CONFIG_HOOKUP
static int __hookup_irq(int vector_id, int event_id, void (*handler)(void *args), void *args) static int __hookup_irq(int vector_id, int event_id, void (*handler)(void *args), void *args)
{ {
void (*irqh)() = NULL; void (*irqh)() = NULL;
@ -183,16 +191,18 @@ int irq_attach(int vector_id, int event_id, void (*handler)(void *args), void *a
{ {
int r = 0; int r = 0;
Uint32 gie; Uint32 gie;
#if !defined(IRQ_CONFIG_HOOKUP)
struct irq_descr *irqd;
#if 1
if (vector_id < IRQ_VECTOR_START || vector_id >= (IRQ_VECTOR_MAX + IRQ_VECTOR_START)) { if (vector_id < IRQ_VECTOR_START || vector_id >= (IRQ_VECTOR_MAX + IRQ_VECTOR_START)) {
return -1; return -1;
} }
gie = irq_global_disable(); gie = irq_global_disable();
r = vector_id - IRQ_VECTOR_START; r = vector_id - IRQ_VECTOR_START;
__irq_descr[r].irq_handler = handler; irqd = &__irq_descr[r];
__irq_descr[r].args = args; irqd->irq_handler = handler;
__irq_descr[r].event_id = event_id; irqd->args = args;
irqd->event_id = event_id;
#else #else
gie = irq_global_disable(); gie = irq_global_disable();
if ((r = __hookup_irq(vector_id, event_id, handler, args))) { if ((r = __hookup_irq(vector_id, event_id, handler, args))) {
@ -215,15 +225,18 @@ int irq_dettach(int event_id, void (*handler)(void *args), void *args)
int i; int i;
int found = 0; int found = 0;
Uint32 gie = irq_global_disable(); Uint32 gie = irq_global_disable();
struct irq_descr *irqd;
for (i = 0; i < IRQ_VECTOR_MAX; ++i) { for (i = 0; i < IRQ_VECTOR_MAX; ++i) {
if (handler && (__irq_descr[i].irq_handler == handler)) { irqd = &__irq_descr[i];
if (args && (args != __irq_descr[i].args)) { if (handler && (irqd->irq_handler == handler) && (event_id == irqd->event_id)) {
if (args && (args != irqd->args)) {
continue; continue;
} }
irq_disable(__irq_descr[i].event_id); irq_disable(event_id);
__irq_descr[i].irq_handler = NULL; irqd->irq_handler = NULL;
__irq_descr[i].args = NULL; irqd->args = NULL;
irqd->event_id = -1;
found = 1; found = 1;
break; break;
} }

Loading…
Cancel
Save