Function pointer within isr

Joel Sherrill joel.sherrill at oarcorp.com
Mon Jun 30 18:41:36 UTC 2014


On 6/30/2014 1:08 PM, Andre Marques wrote:
> On 06/30/14 18:07, Gedare Bloom wrote:
>> On Mon, Jun 30, 2014 at 12:52 PM, Wendell Silva <silvawp at gmail.com> wrote:
>>> André,
>>>
>>> Technically, you should be able to call functions (directly or indirectly)
>>> in any point of your program. AFAIK, there are only a subset of RTEMS
>>> directives you shouldn't call from an ISR.
>> If the function does not 'sleep' it should be ok. Some other issues
>> involve whether you try to access the executing task context, which
>> may not work right. The full set of safe RTEMS functions are:
>> http://rtems.org/onlinedocs/doc-current/share/rtems/html/c_user/Interrupt-Manager-Directives-Allowed-from-an-ISR.html#Interrupt-Manager-Directives-Allowed-from-an-ISR
>>
>> In general, you should be able to call a function. Make sure the
>> function pointer is valid (points to a function you expect). If the
>> function is calling printf then you may definitely have a problem.
>>
>> -Gedare
> I found the problem to be in the arguments received by the handler
> (which include the function pointer).
>
> I am installing the handler using rtems_interrupt_handler_install, and I
> am passing two arguments to the handler (which receives void*) through a
> struct:
>
> struct handler_arguments
> {
>     int pin_number;
>
>     void (*handler) (void);
> } h_args;
>
> I call rtems_interrupt_handler_install and send the handler arguments
> with &h_args. In the handler function I dereference the void pointer with:
>
> void handler (void* arg)
> {
>     struct handler_arguments* h_args;
>
>     h_args = (struct handler_arguments*) arg;
>
> What happens is that if I call the handler function myself the function
> receives the arguments as they were sent, but if the handler is called
> by an interrupt then it does not receive what it was supposed to.
>
>    I have looked at the rtems_interrupt_handler_install and could not
> understand why that happens.
Can you break with a debugger (or use printk) to see if the "void *arg"
pointer matches what you passed into the install?

And then if the contents of *h_args matches?

Is your "struct handler_arguments" declared on the stack (e.g. an
automatic variable)? If so, then the memory is likely clobbered by
the time the ISR runs.


>>> What kind of error have you got? BSP?
> No error, just hanged. I am using the Raspberry Pi BSP.
>
>>> --Wendell.
>>>
>>>
>>>
>>> 2014-06-30 13:47 GMT-03:00 Andre Marques <andre.lousa.marques at gmail.com>:
>>>
>>>> Hello,
>>>>
>>>> I am trying to call a function through a function pointer from an
>>>> interrupt handler, but I am not sure if this is even possible as the system
>>>> hangs at that point. If not, is there any way in RTEMS to have that function
>>>> executed outside the isr?
>>>>
>>>> Thanks,
>>>> André Marques.
>>>>
>>>>
>>>> _______________________________________________
>>>> devel mailing list
>>>> devel at rtems.org
>>>> http://lists.rtems.org/mailman/listinfo/devel
>>>
>>> _______________________________________________
>>> devel mailing list
>>> devel at rtems.org
>>> http://lists.rtems.org/mailman/listinfo/devel
> _______________________________________________
> devel mailing list
> devel at rtems.org
> http://lists.rtems.org/mailman/listinfo/devel


-- 
Joel Sherrill, Ph.D.             Director of Research & Development
joel.sherrill at OARcorp.com        On-Line Applications Research
Ask me about RTEMS: a free RTOS  Huntsville AL 35805
Support Available                (256) 722-9985




More information about the devel mailing list