David,

> Now here's the really bizarre bit. When I boot my device when it's plugged
> in to my computer via USB (the way I usually interact with Forth) it runs
> fine and increments the value of ctr each time round the loop. But when I
> run it on batteries with the xbee plugged in, ctr doesn't get incremented -
> it stays at 6 (or whatever I set it to initially). If I change 's" inctr"
> evaluate' to just 'inctr' it increments it properly.

That sounds like a problem in evaluate, so I further shortened your 
excample to

variable ctr
: incr ctr @ 1 + ctr ! ;
: t1 ctr @ . s" incr" evaluate ctr @ . ;

and that works for me (I think, that my code does the
same as yours, except for the xbee stuff).

(ATmega16)> 0 ctr !
 ok
(ATmega16)> t1
0 1  ok
(ATmega16)> t1
1 2  ok
(ATmega16)> t1
2 3  ok
(ATmega16)> 

The evaluate, when using a compiled string (in a colon word) copies the
string when called to RAM at HERE. This is a memory region that is
supposed to be unused, PAD is defined as HERE + offset. So my first
guess is a memory corruption. It's a cruel tool, but you may use the
watcher.frt utility to add a breakpoint when something accesses either
your ctr or the HERE data (there is a recipe for it too)

Another guess is that the RAM may only look like beeing initialized
properly. We had such a situation with the multitasker some time ago.
It depends on some RAM data that was initialized when the program code
was loaded but not at reset. It was no problem during a normal debugging
session, since the data was still intact. Only after a (long) power off
it turned out to be a problem, but not always. So I'd recommend adding a
FILL with zeros of the memory region to your turnkey (or close to it
before the Xbee is started). The best would be a fill of all RAM, but
even when TURNKEY starts, some RAM is already initialized (buffer 
pointers, USER area), so I leave it to you to to get the addresses 
right.


> I'm running 5.1 because I'm having trouble compiling the later ones on
> Linux.

Could you elaborate this? I used both Ubuntu and Fedora (19,20) without
problems.

Matthias
------------------------------------------------------------------------------
Slashdot TV.  
Video for Nerds.  Stuff that matters.
http://tv.slashdot.org/
_______________________________________________
Amforth-devel mailing list for http://amforth.sf.net/
Amforth-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/amforth-devel

Reply via email to