irq: Add a warning if the name is NULL
[simavr] / simavr / sim / sim_irq.c
index 662a997..16e3418 100644 (file)
@@ -71,10 +71,14 @@ avr_init_irq(
 
        for (int i = 0; i < count; i++) {
                irq[i].irq = base + i;
+               irq[i].flags = IRQ_FLAG_INIT;
                if (pool)
                        _avr_irq_pool_add(pool, &irq[i]);
                if (names && names[i])
                        irq[i].name = strdup(names[i]);
+               else {
+                       printf("WARNING %s() with NULL name for irq %d.\n", __func__, irq[i].irq);
+               }
        }
 }
 
@@ -164,8 +168,7 @@ avr_irq_unregister_notify(
        hook = irq->hook;
        prev = NULL;
        while (hook) {
-               if (hook->notify == notify && hook->param == param)
-               {
+               if (hook->notify == notify && hook->param == param) {
                        if ( prev )
                                prev->next = hook->next;
                        else
@@ -186,8 +189,11 @@ avr_raise_irq(
        if (!irq)
                return ;
        uint32_t output = (irq->flags & IRQ_FLAG_NOT) ? !value : value;
-       if (irq->value == output && (irq->flags & IRQ_FLAG_FILTERED))
+       // if value is the same but it's the first time, raise it anyway
+       if (irq->value == output &&
+                       (irq->flags & IRQ_FLAG_FILTERED) && !(irq->flags & IRQ_FLAG_INIT))
                return;
+       irq->flags &= ~IRQ_FLAG_INIT;
        avr_irq_hook_t *hook = irq->hook;
        while (hook) {
                avr_irq_hook_t * next = hook->next;
@@ -214,7 +220,7 @@ avr_connect_irq(
                avr_irq_t * dst)
 {
        if (!src || !dst || src == dst) {
-               printf("avr_connect_irq invalid irq %p/%p", src, dst);
+               fprintf(stderr, "error: %s invalid irq %p/%p", __FUNCTION__, src, dst);
                return;
        }
        avr_irq_hook_t *hook = src->hook;
@@ -235,14 +241,13 @@ avr_unconnect_irq(
        avr_irq_hook_t *hook, *prev;
 
        if (!src || !dst || src == dst) {
-               printf("error: avr_connect_irq invalid irq %p/%p", src, dst); fflush(stdout);
+               fprintf(stderr, "error: %s invalid irq %p/%p", __FUNCTION__, src, dst);
                return;
        }
        hook = src->hook;
        prev = NULL;
        while (hook) {
-               if (hook->chain == dst)
-               {
+               if (hook->chain == dst) {
                        if ( prev )
                                prev->next = hook->next;
                        else