Page 1 of 1

IRQs...

Posted: Sun Nov 11, 2007 9:28 am
by kapitan_hak
Hi!
I have this code:

Code: Select all

void *irq_routines[16] =
{
    0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0
};

/* This installs a custom IRQ handler for the given IRQ */
void irq_install_handler(int irq, void (*handler)(struct regs *r))
{
    irq_routines[irq] = (void *)handler;
}
//...
void irq_handler(regs *r)
{
    /* This is a blank function pointer */
    void (*handler)(void *r);

    /* Find out if we have a custom handler to run for this
    *  IRQ, and then finally, run it */
    handler = irq_routines[r->int_no - 32];
    if (handler)
    {
        handler(r);
    }
//...
}
My problem is compiler error:
sysapi.cpp:149: error: invalid conversion from ‘void*’ to ‘void (*)(void*)’
Line 149 is "handler = irq_routines[r->int_no - 32]"
How repair this error? Thanks(); :) k_h;

Posted: Sun Nov 11, 2007 9:55 am
by RedEagle
You have to use a pointer to a function, not a pointer to void.

Here some code from my OS:

Code: Select all

typedef void(*ISR)();

Code: Select all

ISR isr_exception[20];

void nullexp()
{
 rr::LogV1(RRFID_ERROR, "Nicht installierte Exception!\n");
 while(true);
}

//...

for(int i=0; i<20; i++)isr_exception[i] = (ISR)nullexp;
and with

Code: Select all

isr_exceotion[0]();
you can call one of the functions