-
Notifications
You must be signed in to change notification settings - Fork 66
STM8 eForth Idle Task
STM8 eForth can run code when the console is idle. It's almost as easy to use as the Background Task but it runs in the console context and it has no time guarantees.
Possible applications are fast protocol handlers, interpreters, state machines, and tasks with best-effort fast response in embedded systems. It's even possible to use the interpreter in an Idle Task with the STM8 eForth library word EVALUATE
!
IDLE feature was added With issue #187 (Release 2.2.22).
Here is an example:
#require 'IDLE
\ note: 'IDLE is "$0066 CONSTANT 'IDLE" (fixed memory address)
VARIABLE tally
: idletask ( -- )
\ idle code must be stack neutral!
tally @ 1+ DUP TALLY ! $F000 AND 0= OUT!
;
' idletask 'IDLE ! \ set IDLE execution vector to word idletask
When the console waits for input, idletask
makes a board outputs flash (e.g. LED). An STM8 with 16MHz clock flashes the LED about 34 times per minute. This means that one IDLE loop iteration takes about 8.65µs = 34s/60/65536.
In an 'IDLE
task, Forth interpreter words can be used with the help of the EVALUATE feature.
For an example it's possible to evaluate strings sent from a guest, e.g. via a wireless interface. Under very specific conditions it's even possible to compile code to NVM
memory.
The following restrictions apply:
- the execution time of an idle task must not exceed 1ms (character rate at 9600 baud)
- character output should first switch the 'EMIT vector (sometimes just printing to the console is OK for debugging)