[email protected] (niclash) writes:
So the microcontroller shouldn't need to know in advance how to "handle" these expansion boards, and shouldn't need "upgrade" when a new type of expansion board comes into existance. And therefor the idea is to have a Forth program sitting in an EEPROM
on each expansion board, containing 4 words each;
This looks like a very similar problem to the one that was solved with
Open Firmware, so you might want to take a look at that. Note that
Open Firmware uses a tokenized form of source code, but from what I
read, it is still source code.
BUT, I can not write to program that executes the Forth words that are in the eeprom, since that doesn't exist yet. Here was my first attempt at this;
: slot-powerup ( slot# -- ) Called on Colibri powerup for each slot, ONLY ONCE.
dup slot-on 1 delay Power up the slot, wait
dup slot-reset 1 delay RESET cycle
dup slot-select Select slot
1 block-read read the EEPROM
if .yellow< ." EEPROM not present in slot. " >.
2dup #1024 evaluate execute forth code from EEPROM. EEPROM should have been filled with SPACE at end.
if swap ." Error interpreting EEPROM in slot " . free exit then EEPROM program must have ( slot# c-addr len -- err? )
dup 1- cells
attach hooks
' (init) over cells slot-init + !
' (tick) over cells slot-tick + !
' (read) over cells slot-read + !
' (write) over cells slot-write + !
slot-init @ execute call "init" for slot
( slot# channels )
;
(Variant; MECRISP Forth for STM32)
Basically, (init), (tick), (read) and (write) are "not found", and even if I "pre-define" them, this snippet of code will be pointing to the old ones, not the words that were just read out from the EEPROM.
So, can someone think of any smarter way to do this, before I try to manually walk the dictionary to locate the word I am looking for?
One way would be to use SEARCH-WORDLIST, FIND-NAME, FIND, or the like
in SLOT-POWERUP.
Alternatively, the EEPROM could contain source code that leaves the
xts of the four words you want on the stack, in addition to the other
values. Then the code above would look like
...
2dup #1024 evaluate ( xt-write xt-read xt-tick xt-init ... err? )
if swap ." Error interpreting EEPROM in slot " . free exit then
dup 1- cells
attach hooks >r ( xt-write xt-read xt-tick xt-init R: slot# )
r@ cells slot-init + !
r@ cells slot-tick + !
r@ cells slot-read + !
r@ cells slot-write + !
r>
...
- anton
--
M. Anton Ertl
http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs:
http://www.complang.tuwien.ac.at/forth/faq/toc.html
New standard:
https://forth-standard.org/
EuroForth 2023:
https://euro.theforth.net/2023
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)