Rocksolid Light

Welcome to Rocksolid Light

mail  files  register  newsreader  groups  login

Message-ID:  

Remember, UNIX spelled backwards is XINU. -- Mt.


devel / comp.lang.forth / Dynamic declarations

SubjectAuthor
* Dynamic declarationsniclash
`* Re: Dynamic declarationsAnton Ertl
 `- Re: Dynamic declarationsniclash

1
Dynamic declarations

<b3363194d8c775e9c0c894998c566f36@news.novabbs.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=25794&group=comp.lang.forth#25794

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!.POSTED!not-for-mail
From: niclas@hedhman.org (niclash)
Newsgroups: comp.lang.forth
Subject: Dynamic declarations
Date: Tue, 26 Dec 2023 15:50:17 +0000
Organization: novaBBS
Message-ID: <b3363194d8c775e9c0c894998c566f36@news.novabbs.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: i2pn2.org;
logging-data="1225176"; mail-complaints-to="usenet@i2pn2.org";
posting-account="t+lO0yBNO1zGxasPvGSZV1BRu71QKx+JE37DnW+83jQ";
User-Agent: Rocksolid Light
X-Rslight-Site: $2y$10$fNJgUzIZZ0eQollqAsk.z.5fhT9qyh2k.erHm2wK3J3sYMr6lC1uu
X-Rslight-Posting-User: 593246b2b536884b1d74fb8b09b3ff45cd9949a1
X-Spam-Checker-Version: SpamAssassin 4.0.0
 by: niclash - Tue, 26 Dec 2023 15:50 UTC

Hi, everyone.

I am using Forth on a piece of hardware that I have constructed. It has a "motherboard" with 0..N slots (connectors on a bus), where slot 0 is for the controlling microcontroller, and each other slot is to interface with the real world, such as Pt1000 sensors, 0-10V, 0-20mA, Triac outputs and so on.

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;

: (init) Called after each RESET of the board.

: (tick) Called periodically (~20ms) and used for scanning hardware and such

: (read) Reads and formats the inputs and places the result in buffers to be sent by LoraWAN

: (write) Takes values arrived over LoraWAN and make use of them to output to hardware (in (tick) )

So, the programs are executed by the main (slot0) microcontroller, on behalf of the expansion board.

Now, to keep it simple, I thought I just store the Forth source code in the EEPROM on the expansion board, read out the string and call "evaluate" and in principle that works.

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?

Thanks in advance for any suggestions

Re: Dynamic declarations

<2023Dec26.181753@mips.complang.tuwien.ac.at>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=25795&group=comp.lang.forth#25795

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: anton@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups: comp.lang.forth
Subject: Re: Dynamic declarations
Date: Tue, 26 Dec 2023 17:17:53 GMT
Organization: Institut fuer Computersprachen, Technische Universitaet Wien
Lines: 67
Message-ID: <2023Dec26.181753@mips.complang.tuwien.ac.at>
References: <b3363194d8c775e9c0c894998c566f36@news.novabbs.com>
Injection-Info: dont-email.me; posting-host="aa0bc3cd332af0409803ec13d8986224";
logging-data="3747273"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18UIXZl/9MnqZAI0UQ7mSG3"
Cancel-Lock: sha1:WhWkgGbIVIrKW4LziU1R2iyIPZA=
X-newsreader: xrn 10.11
 by: Anton Ertl - Tue, 26 Dec 2023 17:17 UTC

niclas@hedhman.org (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

Re: Dynamic declarations

<349e715574c95b95383185412f2ef841@news.novabbs.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=25797&group=comp.lang.forth#25797

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!.POSTED!not-for-mail
From: niclas@hedhman.org (niclash)
Newsgroups: comp.lang.forth
Subject: Re: Dynamic declarations
Date: Tue, 26 Dec 2023 20:15:43 +0000
Organization: novaBBS
Message-ID: <349e715574c95b95383185412f2ef841@news.novabbs.com>
References: <b3363194d8c775e9c0c894998c566f36@news.novabbs.com> <2023Dec26.181753@mips.complang.tuwien.ac.at>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: i2pn2.org;
logging-data="1246740"; mail-complaints-to="usenet@i2pn2.org";
posting-account="t+lO0yBNO1zGxasPvGSZV1BRu71QKx+JE37DnW+83jQ";
User-Agent: Rocksolid Light
X-Rslight-Site: $2y$10$80QW1/FmfNnVbFTQ51wc7.FRZBEjDLdsgHsBjZk5okUN/4DGK2FcO
X-Rslight-Posting-User: 593246b2b536884b1d74fb8b09b3ff45cd9949a1
X-Spam-Checker-Version: SpamAssassin 4.0.0
 by: niclash - Tue, 26 Dec 2023 20:15 UTC

Anton Ertl wrote:

> 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

Ahhhh! Why didn't I think of that!

SOLVED! Thanks.

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor