Programming, for all ages and all languages.
InsightSoft
Member
Posts: 76 Joined: Mon Aug 18, 2008 6:17 am
Post
by InsightSoft » Fri Apr 24, 2009 6:26 pm
Hi,
I have this problem:
1--- the declaration
2--- the values
Code: Select all
void _cls_irq::InstallHandler(int irq, void (*handler)(tpRegistersStructure *))
{
irq_routines[irq] = (void *)handler;
}
and
Code: Select all
void handler_Timer(tpRegistersStructure *r)
{
blablabla
}
then
Code: Select all
IRQ.InstallHandler(0, handler_Timer); //get handler_timer function address and put on irq_routines[0]
3----- the problem (for every irq)
Code: Select all
void handler_IRQ(tpRegistersStructure *r)
{
void (*handler)(tpRegistersStructure *r); //pointer for incoming function with this format -> return (void *) and
//get (tpRegistersStructure *r) as parameters
handler = irq_routines[(r->int_no - 32)]; //with this index, get its correspondent function address
(this does not run!!!!!!!!!!!!!!!!!! -> Can you tel me why???
this simple example just works fine:
Code: Select all
void (*p)(int i);
p = myfunction;
(*p)(23); // call myfunction with 23 as parameter
[ JamesM: Added code tags. ]
pcmattman
Member
Posts: 2566 Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:
Post
by pcmattman » Fri Apr 24, 2009 6:29 pm
Firstly, please use code tags - they make it far easier to read your post!
Code: Select all
handler = irq_routines[(r->int_no - 32)]; //with this index, get its correspondent function address
Do you actually ever call the function?
InsightSoft
Member
Posts: 76 Joined: Mon Aug 18, 2008 6:17 am
Post
by InsightSoft » Fri Apr 24, 2009 6:32 pm
Yap...
Code: Select all
void handler_IRQ(tpRegistersStructure *r)
{
void (*handler)(tpRegistersStructure *r);
handler = irq_routines[(r->int_no - 32)]; //to discover in matrix that start from 0 index
if(handler)
{
handler(r); //execute this address
}
if(r->int_no >= 40)
{
Ports.SendByte(0xA0, 0x20);
}
Ports.SendByte(0x20, 0x20);
}
InsightSoft
Member
Posts: 76 Joined: Mon Aug 18, 2008 6:17 am
Post
by InsightSoft » Fri Apr 24, 2009 6:33 pm
The result is:
error C2440: '=' : cannot convert from 'void *' to 'void (__cdecl *)(tpRegistersStructure *)'
pcmattman
Member
Posts: 2566 Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:
Post
by pcmattman » Fri Apr 24, 2009 6:36 pm
Okay, that's because you've defined irq_handlers as:
Yet you want to use it as a:
Code: Select all
void (*handler)(tpRegistersStructure *)
You either need to use a cast when obtaining the IRQ handler from the array, or you need to typedef the handler function pointer type and use that instead of void*.
JamesM
Member
Posts: 2935 Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:
Post
by JamesM » Sat Apr 25, 2009 5:32 am
Hi,
Firstly, you didn't mention if the IRQ handler gets called at all - you only mentioned the IRQ dispatch afterwards. Does the function IRQ_Handler get called when an IRQ comes in?
If not, which is what I suspect, have you remapped the PIC? Have you enabled interrupts?
Cheers,
James
InsightSoft
Member
Posts: 76 Joined: Mon Aug 18, 2008 6:17 am
Post
by InsightSoft » Sat Apr 25, 2009 5:51 am
Yap...
...remember: that error is at compilation stage...
pcmattman
Member
Posts: 2566 Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:
Post
by pcmattman » Sat Apr 25, 2009 6:15 am
And I told you how to fix the compilation error. Read my post for the answer
InsightSoft
Member
Posts: 76 Joined: Mon Aug 18, 2008 6:17 am
Post
by InsightSoft » Sat Apr 25, 2009 6:20 am
Ya... I know... its what I am trying to do
InsightSoft
Member
Posts: 76 Joined: Mon Aug 18, 2008 6:17 am
Post
by InsightSoft » Sat Apr 25, 2009 8:17 am
pcmattman wrote: Okay, that's because you've defined irq_handlers as:
Yet you want to use it as a:
Code: Select all
void (*handler)(tpRegistersStructure *)
You either need to use a cast when obtaining the IRQ handler from the array, or you need to typedef the handler function pointer type and use that instead of void*.
And how to do that? can you help me?
Creature
Member
Posts: 548 Joined: Sat Dec 27, 2008 2:34 pm
Location: Belgium
Post
by Creature » Sat Apr 25, 2009 1:02 pm
Gah.. Please know your function pointers before you use them:
Code: Select all
typedef void (*FunctionPointerType)(tpRegistersStructure *);
FunctionPointerType ArrayOfFunctionPointers[16];
Now you (should) have an array of function pointers which point to a function with 'void' as return type and 1 argument, namely a 'tpRegistersStructure' pointer.
When the chance of succeeding is 99%, there is still a 50% chance of that success happening.
JamesM
Member
Posts: 2935 Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:
Post
by JamesM » Sun Apr 26, 2009 2:49 am
DeletedAccount
Member
Posts: 566 Joined: Tue Jun 20, 2006 9:17 am
Post
by DeletedAccount » Sun Apr 26, 2009 3:21 am
Hi,
This a a general 'C' question and has nothing to do with VC++ compiler . Bad topic
Regards
Shrek