Note: it's very easy to crash FlashForth if you get something wrong. Use with caution!
Multitasking
By default, Flashforth is single tasking. Mikael Nordman has words that add multitasking capability to FlashForth, and this page documents how to use them.
First, download and add the words in task.txt to your dictionary.
See the header in this file for information on allocating space for tasks. |
|
Let's create two simple words to run as independent tasks:
: blinky \ blink the amber status LED
begin
blink
again
;
: shuffle \ shuffle the LED array
begin
$aaaa leds
200 ms
$5555 leds
200 ms
again
;
Next we need to create a new task entries in the flash memory, using the work task: and call the task entries task2 and task3. The task: word takes four parameters off the stack: input buffer size, stack size, return stack size and address size.
0 24 24 0 task: task2
0 24 24 0 task: task3
Next, we look up the address of the word blinky in the dictionary using ' and allocate it to task2 using tinit.
' blinky task2 tinit
And we allocate shuffle to task3:
' shuffle task3 tinit
To run blinky (task2):
task2 run
The amber status LED on your Scamp will blink as the task is running in the background.
To start shuffle (task3):
To start shuffle (task3):
task3 run
To view currently running tasks:
tasks
To kill a particular task:
task3 end
To kill all tasks except the operator task:
single