[PicForth] Re: multitasker.fs question
Alex Holden
alex at linuxhacker.org
Mon Dec 6 10:22:35 CET 2004
David McNab wrote:
> Just one question - given that the return stack on PIC16F chips is
> totally non-addressible, does this mean that 'yield' instructions may
> only occur in the very top level of each task?
Yep, it's a pretty annoying limitation of the architecture. And for the
same reason the task is always reentered at the start of the toplevel
word, not at the word after the yield. I was doing stuff like this until
I realised from reading the generated assembly that there's no need for
the outer loop because the multitasker will just reenter at the
beginning of the word:
task : fred
begin
barney
yield
again
;
> In other words, would I crap on the return stack if task 'fred' calls
> word 'mary', and 'mary' sits in a loop periodically executing a 'yield'?
Yep. I have a task which polls a piece of hardware ten times a second
and another which talks to a user via a serial terminal. When the user
executes a command which requires the task to accept a string, the task
sits around in 'accept' indefinitely and the hardware servicing stops
for the duration. Calling yield if key? returns false would be ideal but
that won't work so I've decided to simply document the fact that normal
operation of the system ceases while user interaction is taking place
(it only happens when the system is being configured so it's not really
a big deal in this case).
> If this is the case (I expect it would be), then it might be worth a
> mention in the doco.
It is, in the second sentence. "It allows you to relinquish the CPU
whenever you want, provided that you are not in the middle of a call
(context-switch only occurs during top level calls)."
--
------------ Alex Holden - http://www.linuxhacker.org ------------
If it doesn't work, you're not hitting it with a big enough hammer
More information about the PicForth
mailing list