1. Will nested ISRs pose a problem ? I will have to pop the stack an
extra to void the previous command....
Yes and thats a bug in my ISR code, There isn't a
re_init_appropriate_globals(); when the sleep command is encountered,
to re-init the user space stack.
2. Will the fact that the ISR routine disables all interrupts upon
iwhen its commencement pose a problem?
Yes that is a problem.
I hoped to avoid nested ISR issues and ISR disabling issues by having a
distinct isr_receiver and command_executer that communicate via some
variables. How does your micro-controller exit the disabled interupt
state? Is it tied to the return from ISR instruction or can it be done
without having to return from the ISR ?
another issue:
Suppose your code looks like:
void massive_isr_routine_that_does_everything(void)
{
int a= 10; /* init variable a which is kept in a stack frame */
int b= 45; /* init variable b which is kept in a stack frame */
int x= 67; /* init variable x which is kept is a stack frame */
/* reset the stack */
...
/* remove ISR execution protection */
...
/* normal code */
...
}
So when you reset the stack, what do you set it to? And you have
variables that were already initialized on the stack. They now need to
be initialized on the new stack.
Ok fine so you can change the code to read
void massive_isr_routine_that_does_everything(void)
{
int a; /* init variable a which is kept in a stack frame */
int b; /* init variable b which is kept in a stack frame */
int x; /* init variable x which is kept is a stack frame */
/* reset the stack */
...
a= 10; /* init variable a which is kept in a stack frame */
b= 45; /* init variable b which is kept in a stack frame */
x= 67; /* init variable x which is kept is a stack frame */
/* remove ISR execution protection */
...
/* normal code */
...
}
But how do you know its not being optimized into the first routine?
Another issue:
Suppose when there are no variables on the stack and you have to
re-init it to be 0x1000.
Now that there are 3 variables you'll have to re-init it to 0x1000 - 3
* sizeof(int)
Everytime you add a variable you need to know if its going to end up on
the stack and adjust the stack init appropriately.
Thats another reason I like having the command_reciever be a supreme
ISR in asm: it can re-init the user space stack pointer every time to
0x1000 without worrying about what command_executer is going to do with
it.
rover8898 wrote:
Thank you both Samuel and Hubble.
Both are good solutions to my problem.
I like the setjmp.h's setjmp and longjmp instructions. They are what I
was initially looking for: a non-local goto.
However, looking at Samuel code made me realize that my code
architecture is wrong. Now: My command handling+exution is done outside
of an ISR. It uses as parameter the contents of the reception buffer.
What is should be: My command handling+exution should be in an ISR.
However it brings 2 questions to mind:
1. Will nested ISRs pose a problem ? I will have to pop the stack an
extra to void the previous command....
2. Will the fact that the ISR routine disables all interrupts upon
iwhen its commencement pose a problem?
Those are minor problems. I am certain I will be able to resolve them.
Thanks guys.
-Roger