Inside of the function, at some point, he would like to modify the
message association table and then return (this return is not at the
end of the function). Then when another message comes in (we're back
looping in main() at this point), execution begins in the same
function right below where he returned. Thus, he would sort of emulate
a blocking read in a mult-tasking OS.
I don't think he needs to build a multi-tasking OS. For example, he
does not have to remember stack information, that is, do a real
context switch. I just thinks he has to store the instruction pointer
in that message association table and jump to the address upon receipt
of a message.
Does anyone have a slick way of doing this? Anyone have a snippet of
hc12 code that does something like this?
Thanks,
David
--
A wise man once said: If it didn't come with source, it's firmware not software.
David W. Bourgoyne
david.b...@bigfoot.com
Avoid it like the plague. Using such self-modifying code leads to
madness.
Instead, make the called routine a state machine. It needs only a
single state variable, which it sets on exit, and uses on entry.
In C, something like:
static enum {STATE0, STATE1, ... LASTSTATE} state;
void routine(...) {
switch state {
case STATE0 :
state = dostate0; break;
case STATE1 :
state = dostate1; break;
....
}
return;
}
--
Chuck F (cbfal...@yahoo.com) (cbfal...@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
Absolutely agreed. There's always a better way.
> Instead, make the called routine a state machine. It needs only a
> single state variable, which it sets on exit, and uses on entry.
... And I totally agree that a state machine is the better way :).
Steve
--
http://www.sfdesign.co.uk - SFD: Solutions by Design
http://www.fivetrees.com - ecommerce for independent musicians
--
Nuno Alves
nuno...@nunoalves.com
Cell Phone: 617-529-7597
Homepage: http://www.nunoalves.com
AOL Instant Messenger: nunoalves7
MS Windows Messenger: nuno...@nunoalves.com
"CBFalconer" <cbfal...@yahoo.com> wrote in message
news:3DB94E0E...@yahoo.com...
>
>A friend of mine is looking for a solution to a problem/code he
>inherited. This all runs on a hc12. His application is event driven.
>Basically main() is just a big loop waiting on messages. When a
>message comes in, he goes to a table and calls the function associated
>with a message. The function runs to completion. Here's the twist...
>
>Inside of the function, at some point, he would like to modify the
>message association table and then return (this return is not at the
>end of the function). Then when another message comes in (we're back
>looping in main() at this point), execution begins in the same
>function right below where he returned. Thus, he would sort of emulate
>a blocking read in a mult-tasking OS.
If you only need to switch between two functions, then a coroutine
structure could be used. In this an indirect subroutine call using
(and popping) the return address from the top of the stack will put
your own return address on top of the stack. To switch back, the other
function issues an identical indirect call.
I don't know if this can be done in the hc12.
It should be noted that the old return address must be first popped
from the stack before the indirect call is executed, effectively
replacing the old return address with your own. This can also be done
by pushing a copy of the original return address on the stack, replace
the original reply address with an address following the RTS
instruction and executing the RTS instruction. This will pop off the
copy of the original return address, leaving your own return address
on top of the stack.
Paul
although if that was his structure he probably wouldn't have asked the
question.
Ralph
"Steve Fairhead" <st...@deleteme-fivetrees.com> wrote in message
news:apbpoh$2dq$1$8302...@news.demon.co.uk...