石原 博の覚書

電子工作に関する日々の覚書を記載します

FORTHでマルチタスク

2021-09-26 14:33:19 | 日記

CP/Mには割り込みがないが、F83でもマルチタスクが可能(cooperative型)。しかし色々調べてみたが有効な利用方法が見つからない。画面の一部に時計を出そうと思ってもCP/Mには時計はないし、プリンタをつないでいるわけでもないのでプリンタスプーラ的なことも出来ない。せいぜいバックグラウンドでカウントアップさせるタスクを動かして、定期的に見ることぐらいでしか確認出来ない。
これでは面白くないので、Arduino+FlashForthでLチカなるものでマルチタスクを試してみた。(FlashForthはAVRやPICで使えるらしい)

ハードウエアは Arduino pro mini 5V 16MHz。書き込みはUSBASP+avrdude。

ff5.0.zipをダウンロードして展開すると、hexファイルがあるので328-16MHz-38400.hexを使用した。(アセンブルからしても良いのだけどAVRStudioとか必要そうなので後回し)

通常どおり、Vcc, GND, MISO, MOSI, SCK, RSTを接続してEPROMへ書き込み。

$ avrdude -c usbasp -p m328p -U flash:w:328-16MHz-38400.hex 

avrdude: warning: cannot set sck period. please check for usbasp firmware update.
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: warning: cannot set sck period. please check for usbasp firmware update.
avrdude: reading input file "328-16MHz-38400.hex"
avrdude: input file 328-16MHz-38400.hex auto detected as Intel Hex
avrdude: writing flash (32608 bytes):

Writing | ################################################## | 100% 4.30s

avrdude: 32608 bytes of flash written
avrdude: verifying flash memory against 328-16MHz-38400.hex:
avrdude: load data flash data from input file 328-16MHz-38400.hex:
avrdude: input file 328-16MHz-38400.hex auto detected as Intel Hex
avrdude: input file 328-16MHz-38400.hex contains 32608 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 2.43s

avrdude: verifying ...
avrdude: 32608 bytes of flash verified

avrdude: safemode: Fuses OK (E:FD, H:DA, L:FF)

avrdude done.  Thank you.


後はputty等でシリアルに接続してOK

注意点
 ANS に準拠しているらしいが、FlashFothはF83とはいろいろ違う。
 ・F83のようなITC(Indirect Threaded Code)やDTC(Direct Threaded Code)ではなくSTC(Subroutine Threded Code)
 ・forgetがない。marker を使う。
 ・do loopがない。for next を使う。
 ・F83で便利に使っていた see がない。
 ・組み込みなのでファイルシステムがない。エディタもないしloadも出来ない。
 ・定義したワードはepromに書かれるので電源を切っても保存される。
 ・最小限のワードだけ定義されており、必要に応じて同梱されている定義、do loop(doloop.fs)とか、アセンブラ(asm.fs, asm2.fs)とか、see(see.fs, see2.fs)とか、マルチタスク(task.fs)とか。
 ・母艦のエディタでプログラムを作成し、putty等で貼り付ければ良いと考えたが、puttyのShift-INSでは書き込みが速すぎて文字の取りこぼしが出る。->同梱されている ff-shell.tclやff-shell.pyを使用する必要がある(linux)

マルチタスクの例
FlashForth Shellからtask.fs をsendしてから以下を入力

-------------
marker -test

$23 constant PINB
$24 constant DDRB
$20 constant PORT5

PORT5 DDRB c!
: ledOnOff 10 for PORT5 PINB c! 1000 ms next ;

0 20 20 0 task: led_flash
: start ['] ledOnOff led_flash tinit led_flash run  ;
--------------

マルチタスクでAruduino Pro miniのLEDが点滅することが確認出来た。



最新の画像もっと見る

コメントを投稿