Re: goto across functions/isrs?





Tim Wescott wrote:

galapogos wrote:
I have an isr that is called every 20ms that checks if something is
connected. If so it changes a global state variable to "connected". In
my main() I have a loop that checks if the device is connected.


Implement the processing function as a thread. Kill the thread if the device gets disconnected.

That assumes that the OP is using an OS. If he's got a task loop in main() that kind of implies no OS.

This can be done by a manipulation with the CPU context in SST-like pseudo RTOS or even without RTOS. A hack just for mental exercise. :)

Actually, if he had decided to use an SST-like pseudo RTOS (or real time pseudo OS, to be more precise), it wouldn't be a problem because he would never stop in the middle of the loop -- the function would do one operation, change its state, and return. So checking for a disconnect would be simple.

Here is another solution: run the processing loop as the very bottom task in the SST, and run everything else as the different SST tasks. In this case, one can alter the context of main() while keepeng everything else alive. This requires hacking of the stack frame.


One of the responses in this thread did make me think that you could arrange the ISR to load the stack with just the right evil combination of stuff such that when you hit the 'iret' instruction you'd be in main() right before the while loop.

That would be difficult if there are any other interrupts and tasks. Also it is very position dependent.


Vladimir Vassilevsky

DSP and Mixed Signal Design Consultant

http://www.abvolt.com
.



Relevant Pages

  • Re: Why does returning from a block cause a LocalJumpError
    ... If I understand correctly, even though b is defined inside the loop, a ... and b are both stored in the same stack frame when this method is ... I see your logic -- you're trying to look at how the language runtime ... Maybe I'm perseverating on this point, but I'm curious about how Ruby ...
    (comp.lang.ruby)
  • Re: Garbage collection question?
    ... In the example you present, the Object created at the top of each loop iteration becomes eligible for GC as soon as a new reference is assigned to variable o, *provided that* the old Object's reference has not been assigned to some object that persists across loop iterations. ... Even if different slots were used, the stack frame size is fixed at compile time, so an infinite loop will quickly have to start reusing variable slots, so you will not get a memory leak from this direction. ... When a thread returns from a method, its stack frame for that method invocation is popped, freeing all the memory occupied by the local variables of that method for that invocation. ...
    (comp.lang.java.programmer)
  • Re: Code efficiency - declare variable sinside or outdie a loop.
    ... > MY concern was that inside the loop, ... > Was trying to avoid allocate/deallocate loop ... The compiler will allocate stack frame slots according ...
    (comp.lang.java.programmer)
  • Re: Tail call optimization and OO
    ... Just using a loop instead is not really the right thing. ... other code, not using foo ... current function's stack frame and other local variables: ... Maybe this bigFunCall() is even ...
    (comp.lang.lisp)
  • Re: Resume after exception
    ... Basically the stack frame gets unwound to the point where the exception is caught. ... ex: # blah blah if ans!= tkMessageBox.YES: ... Just stick the relevant code inside a loop, much like that above, and break out of the loop when things succeed. ...
    (comp.lang.python)