Function pointer within isr

Peter Dufault dufault at hda.com
Tue Jul 1 20:37:33 UTC 2014


On Jun 30, 2014, at 14:41 , Joel Sherrill <Joel.Sherrill at oarcorp.com> wrote:

> 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.

Not necessarily. A common method would be:

thread_to_process_something() {
	struct handler_arguments on_stack;
	install_isr_that_uses_on_stack();

	while (work_to_do_with_isr()) {
		receive_and_process_semaphore_from_isr();
	}
	shutdown_isr();
}

You just need to ensure that the stack isn't out of scope when the isr can fire.

You can't do this on systems that have per-thread stacks that are only mapped when the thread is active, but I don't know of any RTEMS usage of that.  I've used multi-processor systems that have that attribute.

Peter
-----------------
Peter Dufault
HD Associates, Inc.      Software and System Engineering



More information about the devel mailing list