cwd   wd+   wd-

cwd ( ---)

Specific Flash Forth

Clear the WatchDog counter.

The word cwd is called in all loops which risk To block. Typical case: waiting for a character or a signal.

Some words also reset the watchdog: emit key pause.

wd+ ( n -- )

Specific Flash Forth

Start watchdog timer, n must be less than 8.

Possible values:

value WDP2 WDP1 WDP0 time out
(ms)
0000 16
1001 32
2010 64
3011 125
4100 250
5101 500
6110 1000
7111 2000

The value of n indicates the delay between the execution of cwd and the restarting FlashForth:

: infinite ( ---)
    begin again ;
cwd 7 wd+ infinite
\ normally, FlashForth will restar after 2 seconds

WARNING: if your loop sends characters, the watchdog will be inoperative, because emit executes a cwd in its code.

Likewise, entering a character at the keyboard also performs a cwd.

wd- ( -- )

Specific Flash Forth

Stop the watchdog. Example:

: tempKey ( ---)
    7 wd+
    begin 
        key? dup
        if 
            drop
            key emit
            wd-
            exit
        then
    until
 ;

Execution off tempKey:

\ press 'h' key on keyboard before 2 secnds delay
tempKey h ok<#,ram>
 
\ press no key, restart after 2 seconds
tempKey W FlashForth 5 ATmega328 13.01.2019

If a word is stored in the turnkey vector, it will be executed on restart:

: test ."  -> restart" cr ; 
' test is turnkey

Now we execute tempKey without pressing a key, we have:

tempKey W FlashForth 5 ATmega328 13.01.2019
ESC -> restart