How can I change the stack return address to return to a common point.
I need to eit an interrupt and go to a fixed address.
many thanks
tom brown
tombrown@madasafish.com
Note that you have posted in the "Make the Switch to TI MCUs Success Stories" forum, but this is not a "success story" - is it?
Tom Brown1How can I change the stack return address to return to a common point.
This is an extremely common novice question and is (almost) invariably not the way to proceed at all!!
Tom Brown1I need to eit an interrupt and go to a fixed address.
Please state your actual goal; ie, what you're trying to achieve by this - it is almost certainly not a good way to -proceed!
http://www.catb.org/~esr/faqs/smart-questions.html#goal
If you're using Chrome then this is done automatically, provided you have the correct interrupt directives. Once the ISR finishes the previous PC is popped and returned to.
With assembly you only need to add the RETI instruction at the end. See the x2xx family guide for more information on how interrupts are handled.
Tony
Also there's usually a while(1) loop in the main to catch the returns from interrupt where you can do more logic and processing.
Hi, this practice has to be discouraged than you are writing a task switcher on a preemptive OS.
Changing return address need to know exactly what was in previous routine so a better signal or semaphore or a simple global volatile variable suffice more better and cost of logic is less than changing return value.
Also program is more and more reliable and readable too.
When you switch from one executing routine to another post activation code never can be executed and this waste stack space never return usable, new activation code is executed so some new stack is wasted and also some status remain undetermined. After a short while program run out of stack space and your code crash in a bad way.
_____________________________________________
_________________________________________________
As from good programming rules DON'T DO THAT!!!!!!
Regards
Roberto
Please login & click Verify Answer if this post answered your question.
You normally exit an ISR with the "RETI" instruction. This will pop the top of stack to SR and pop the next word to PC which brings it back to where it was before the interrupt. It sounds like you do not want that last action and want to go to somewhere else. Thus, thus instead of "RETI", you could do "POP SR" followed by "ADD #2,SP" and "BR #somewhere".
I do not see anything wrong in doing this. People normally do not do things like this because they normally do not have a need to do it. I would not be surprised at all if someone do have a need to do so under special situations. But I am very surprised that this someone can see the need and yet does not know how to do it. It is not a matter of style, trend, or fashion.
old_cow_yellowIt sounds like you do not want that last action and want to go to somewhere else. Thus, thus instead of "RETI", you could do "POP SR" followed by "ADD #2,SP" and "BR #somewhere".
Hi OCY, see the short example and do some consideration about, using assembly change detail but cannot remove problem:
----------------------------------------
int noo(int x; int y)
{ // <---- prolog executed here
int a,b,c,d,e;
.... code ...
Interrupt is fired HERE <-------
// epilogue
}
int main(void)
int a,b,c;
char str[80];
// some code here
a=noop(b,c);
------------------------------------------------------------------------------------------------------------------------------
Main prologue is executed, stack space and allocated to make space for all variables
Main code start execution...
noop called, so return address is on stack with parameters too
noop prolog is executed, stack space is allocated to make space for local variables and actual parameter preallocated by the call
-----------> interrupt is fired <--------------
return stack and status register are on stack but....
your code remove just them.. and all preallocated spaces? Two or three of these switch run stack out of space!!!!
No info on how many and what epilogue to be run to remove correct amount of stack space no way to determine how many return and parameter are on stack.
.....
In the case of assembly language some push register are necessary on top of routine so again undefined amount of stack space need to be freed by jump code.
change of compiler or version also affect amount of space allocated and position of variables.
I got a package that was modified in this way and was just crashing due to a different version number!!!!
IS THIS PRACTICE TO BE USED?????
Sorry but I discourage bad programming practices!!!
Roberto Romano IS THIS PRACTICE TO BE USED?????
However, on MSP, i tmakes no sense kicking a process. It is as useless as returning form main. If something goes wrong and an emergency exit has to be called, there are two ways to do it: either reset the MSP and try again, or to execute some specific code and then halt in an endless lopp or enter LPM for eternal sleep.
However, none of the two requires returning from an ISR to somewhere else than you were before the interrupt.
So you're completely right. The only use of this kind of programming that makes sense on an MSP (as far as I can think) is a task scheduler for multitasking. And indeed I use it for exactly this purpose (not an OS, jsut an isolated multitasking library). Every other problem I ever encountered never required it.
OCY: In most cases where this kind of technique is requested, people did not fully understand the purpose and scope of an ISR. An ISR does its job unnoticed from the current operation (except for the time that passed). Typically, they want to do something in the ISR that does not belong there: changing the main program flow due to an event.As you correctly noticed: those who have valid reasons to do such kind of manipulation shouldn't have to ask how it is done. And those who have to ask usually don't really need it. There's a reason why 'goto' doesn't work across function boundaries in the C language standard. The same applies to this kind of stack manipulation on assembly level.
_____________________________________Before posting bug reports or ask for help, do at least quick scan over this article. It applies to any kind of problem reporting. On any forum. And/or look here.If you cannot discuss your problem in the public, feel free to start a private conversation: click on my name and then 'start conversation'. But please do so only if you really cannot do it in a public thread, as I usually read all threads. And I prefer to answer where others can profit from it (or contribute to it) too.