Re: [Amforth] AVR8 watchdog (reset and interrupt) atmega328p

2017-05-07 Thread MIchael Kalus
Müsste es dann nicht c!wd heißen?
Michael

2017-05-07 15:42 GMT+02:00 Matthias Trute :

> Hi Tristan,
>
> I've put your code online, revision 2252 contains the new
> file. There is only one change: I renamed the wd! into !wdc.
> It tells "store to watchdog control" and follows the more
> or less informal convention that ! and @ can be preceeded
> with size information and followed by location information.
> Just like c!e or @i. Hope that's ok for you.
>
> http://amforth.sourceforge.net/TG/recipes/Watchdog.html
>
> Thank you
> Matthias
> 
> --
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> ___
> Amforth-devel mailing list for http://amforth.sf.net/
> Amforth-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/amforth-devel
>
--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Amforth-devel mailing list for http://amforth.sf.net/
Amforth-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/amforth-devel


Re: [Amforth] AVR8 watchdog (reset and interrupt) atmega328p

2017-05-07 Thread Matthias Trute
Hi Tristan,

I've put your code online, revision 2252 contains the new
file. There is only one change: I renamed the wd! into !wdc.
It tells "store to watchdog control" and follows the more
or less informal convention that ! and @ can be preceeded
with size information and followed by location information.
Just like c!e or @i. Hope that's ok for you.

http://amforth.sourceforge.net/TG/recipes/Watchdog.html

Thank you
Matthias
--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Amforth-devel mailing list for http://amforth.sf.net/
Amforth-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/amforth-devel


Re: [Amforth] AVR8 watchdog (reset and interrupt) atmega328p

2017-05-03 Thread Tristan Williams
Hello Matthias,

> I'll look at them in the next few days. Since we've just discovered
> some interrupt related bugs so maybe I'll ask you to do some
> tests with the code I will checkin. Is this ok for you? 

Absolutely fine.

Tristan



--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Amforth-devel mailing list for http://amforth.sf.net/
Amforth-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/amforth-devel


Re: [Amforth] AVR8 watchdog (reset and interrupt) atmega328p

2017-05-02 Thread Matthias Trute
Hi Tristan,

> > 
> > It would be a great contribution for the cookbook. Esp if it works
> > with
> > Forth code.
> This made me think that writing 4 or 5 assembler words was not the
> best way. Instead, have one assembler word wd! to perform the timed
> write to WDTCSR and then have forth words for -wdt +wdt -wdi +wdi
> wd.delay!

That makes sense.

>  I think this was the approach (one assembler word) used in
> 2013 with assembler.frt so had I read it better I might have got
> there
> more quickly.
> 
> https://sourceforge.net/p/amforth/mailman/message/31512894/
> 
> Included below are three files wdwrite.asm, wd.forth and
> wd-example.forth. Regarding wdwrite.asm, it is the first time I have
> used assembler since 1985. wd.forth has more comments than code and
> wd-example.forth may not be up to cookbook standards, though it has a
> number of examples. Many of these examples intentionally result in
> the
> avr microprocessor being reset on the watchdog timeout...

I'll look at them in the next few days. Since we've just discovered
some interrupt related bugs so maybe I'll ask you to do some
tests with the code I will checkin. Is this ok for you? At the
first glance I'd like to reorder some instructions, but its
already late in the evening now, so ... ;)

The text for the cookbook will be my poor English, so it's up
to you to make it better ;)

Thank you indeed
Matthias
--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Amforth-devel mailing list for http://amforth.sf.net/
Amforth-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/amforth-devel


Re: [Amforth] AVR8 watchdog (reset and interrupt) atmega328p

2017-05-02 Thread Tristan Williams
Hello Matthias,

> IIRC only the "disable watchdog" sequence is timing critical (the
> 4 cpu cycles you mention). All other tasks can be performed at
> lower speed, so a forth implementation should be fine.

My atmega328p seems to require any change to WDTCSR to be completed
within 4 cycles (I have tried), so I do not think a pure forth
solution (excluding using assembler.frt) is possible.
 
> It would be a great contribution for the cookbook. Esp if it works with
> Forth code.

This made me think that writing 4 or 5 assembler words was not the
best way. Instead, have one assembler word wd! to perform the timed
write to WDTCSR and then have forth words for -wdt +wdt -wdi +wdi
wd.delay! I think this was the approach (one assembler word) used in
2013 with assembler.frt so had I read it better I might have got there
more quickly.

https://sourceforge.net/p/amforth/mailman/message/31512894/

Included below are three files wdwrite.asm, wd.forth and
wd-example.forth. Regarding wdwrite.asm, it is the first time I have
used assembler since 1985. wd.forth has more comments than code and
wd-example.forth may not be up to cookbook standards, though it has a
number of examples. Many of these examples intentionally result in the
avr microprocessor being reset on the watchdog timeout...

; wdwrite.asm
; 
; 
VE_WDWRITE:
.dw $ff03
.db "wd!"
.dw VE_HEAD
.set VE_HEAD = VE_WDWRITE
XT_WDWRITE:
.dw PFA_WDWRITE
PFA_WDWRITE:

 in temp1,SREG
 push temp1

 mov temp0, tosl

 cli
 ; Reset Watchdog Timer
 wdr
 ; Clear WDRF in MCUSR
 in temp1, MCUSR
 andi temp1, (0xff & (0 until\ exit after 6 sleeps
;

\ use watchdog interrupt and reset 

#include is.frt
#include values.frt
#include avr-values.frt
#include defers.frt

variable app-reg  \ my "application" status register
0 Evalue app-reg-save \ persistant EEPROM store for above
  \ to survive a reset
: panic

Re: [Amforth] AVR8 watchdog (reset and interrupt) atmega328p

2017-04-22 Thread Matthias Trute
Am Donnerstag, den 20.04.2017, 09:04 +0100 schrieb Tristan Williams:
> AVR8 watchdog (reset and interrupt) atmega328p
> 
> I wanted to use the 128 kHz watchdog oscillator as an additional
> timer.

The watchdog creates a full reset cycle, that means that the full
startup sequence is performed. Your turnkey action should take
care of this (register r10 holds the reset cause).

> 
> In the source tree there is an assembler word -wdt (no-wdt.asm),
> which
> writes $0 to WDTCSR (using the prescribed sequence), but I couldn't
> find something like a "+wdt". This may well be because I did not look
> hard enough, so my apologies if it was there all along.

IIRC only the "disable watchdog" sequence is timing critical (the
4 cpu cycles you mention). All other tasks can be performed at
lower speed, so a forth implementation should be fine.

> 
> Using -wdt as a template I have written four companion assembler
> words
> and a slightly modified version of -wdt (to leave the existing
> prescaler and WDIE bit unmodified).
> 
> +wdt ( -- )set WDE (System Reset Mode)   
> -wdt ( -- )unset WDE (leaves prescaler)  
> +wdi ( -- )set WDIE (Interrupt mode) 
> -wdi ( -- )unset WDIE (leaves prescaler) 
> wd.delay! ( n -- ) set prescaler , unset WDE and unset WDIE 
> 
> where n is the 4 bits representing the prescaler. 
> 
> With the 4 cycle write requirement dealt with by (optional at build
> time) built in words the 128kHz timer is accessible and adds a
> lot. Could similar words be added to AmForth or is this too
> device/application specific?

It would be a great contribution for the cookbook. Esp if it works with
Forth code.

Good work
Matthias
--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Amforth-devel mailing list for http://amforth.sf.net/
Amforth-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/amforth-devel


[Amforth] AVR8 watchdog (reset and interrupt) atmega328p

2017-04-20 Thread Tristan Williams
AVR8 watchdog (reset and interrupt) atmega328p

I wanted to use the 128 kHz watchdog oscillator as an additional
timer.  I saw that AVR8 watchdog timer and reset was addressed on the
mailing list in late 2013 using assembler.frt 

In the source tree there is an assembler word -wdt (no-wdt.asm), which
writes $0 to WDTCSR (using the prescribed sequence), but I couldn't
find something like a "+wdt". This may well be because I did not look
hard enough, so my apologies if it was there all along.

Using -wdt as a template I have written four companion assembler words
and a slightly modified version of -wdt (to leave the existing
prescaler and WDIE bit unmodified).

+wdt ( -- )set WDE (System Reset Mode)   
-wdt ( -- )unset WDE (leaves prescaler)  
+wdi ( -- )set WDIE (Interrupt mode) 
-wdi ( -- )unset WDIE (leaves prescaler) 
wd.delay! ( n -- ) set prescaler , unset WDE and unset WDIE 

where n is the 4 bits representing the prescaler. 

With the 4 cycle write requirement dealt with by (optional at build
time) built in words the 128kHz timer is accessible and adds a
lot. Could similar words be added to AmForth or is this too
device/application specific?






--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Amforth-devel mailing list for http://amforth.sf.net/
Amforth-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/amforth-devel