From ff731f3678695e8b11f8bc3e3d982f357f5ea801 Mon Sep 17 00:00:00 2001 From: Brad Nelson Date: Sun, 11 Apr 2021 14:09:05 -0700 Subject: [PATCH] Adding 2@ and 2!, timers, shifts, mask ops. --- ueforth/Makefile | 4 ++-- ueforth/common/boot.fs | 8 +++++-- ueforth/common/opcodes.h | 2 ++ ueforth/esp32/registers.fs | 8 +++++++ ueforth/esp32/timers.fs | 44 +++++++++++++++++++++++++++++++++++++ ueforth/site/internals.html | 5 +++-- 6 files changed, 65 insertions(+), 6 deletions(-) create mode 100644 ueforth/esp32/registers.fs create mode 100644 ueforth/esp32/timers.fs diff --git a/ueforth/Makefile b/ueforth/Makefile index 1644860..d251365 100644 --- a/ueforth/Makefile +++ b/ueforth/Makefile @@ -145,10 +145,10 @@ ESP32_BOOT = common/boot.fs common/conditionals.fs common/vocabulary.fs \ esp32/bindings.fs common/highlevel.fs \ common/filetools.fs common/utils.fs common/locals.fs \ common/tasks.fs common/streams.fs esp32/web_interface.fs \ + esp32/registers.fs esp32/timers.fs \ esp32/bterm.fs esp32/telnetd.fs \ esp32/camera.fs common/blocks.fs \ - esp32/autoboot.fs \ - common/fini.fs + esp32/autoboot.fs common/fini.fs $(GEN)/esp32_boot.h: common/source_to_string.js $(ESP32_BOOT) | $(GEN) echo "ok" | cat $(ESP32_BOOT) - | $< boot $(VERSION) $(REVISION) >$@ diff --git a/ueforth/common/boot.fs b/ueforth/common/boot.fs index 6ee2012..5ed0049 100644 --- a/ueforth/common/boot.fs +++ b/ueforth/common/boot.fs @@ -1,8 +1,6 @@ : ( 41 parse drop drop ; immediate ( Useful Basic Compound Words ) -: 2drop ( n n -- ) drop drop ; -: 2dup ( a b -- a b a b ) over over ; : nip ( a b -- b ) swap drop ; : rdrop ( r: n n -- ) r> r> drop >r ; : */ ( n n n -- n ) */mod nip ; @@ -28,6 +26,12 @@ : 4* 4 * ; : 4/ 4 / ; : +! ( n a -- ) swap over @ + swap ! ; +( Double Words ) +: 2drop ( n n -- ) drop drop ; +: 2dup ( a b -- a b a b ) over over ; +: 2@ ( a -- lo hi ) dup @ swap cell+ @ ; +: 2! ( lo hi a -- ) dup >r cell+ ! r> ! ; + ( Line Comments ) : \ nl parse drop drop ; immediate diff --git a/ueforth/common/opcodes.h b/ueforth/common/opcodes.h index fdb19df..2ac7f73 100644 --- a/ueforth/common/opcodes.h +++ b/ueforth/common/opcodes.h @@ -39,6 +39,8 @@ typedef int64_t dcell_t; X("U/MOD", USMOD, w = *sp; *sp = (ucell_t) w % (ucell_t) tos; \ tos = (ucell_t) w / (ucell_t) tos) \ X("*/MOD", SSMOD, SSMOD_FUNC) \ + Y(LSHIFT, tos = (*sp-- << tos)) \ + Y(RSHIFT, tos = (*sp-- >> tos)) \ Y(AND, tos &= *sp--) \ Y(OR, tos |= *sp--) \ Y(XOR, tos ^= *sp--) \ diff --git a/ueforth/esp32/registers.fs b/ueforth/esp32/registers.fs new file mode 100644 index 0000000..cc6a187 --- /dev/null +++ b/ueforth/esp32/registers.fs @@ -0,0 +1,8 @@ +vocabulary registers registers definitions + +( Tools for working with bit masks ) +: m! ( val shift mask a -- ) + dup >r @ over invert and >r >r lshift r> and r> or r> ! ; +: m@ ( shift mask a -- val ) @ and swap rshift ; + +only forth definitions diff --git a/ueforth/esp32/timers.fs b/ueforth/esp32/timers.fs new file mode 100644 index 0000000..cba0b30 --- /dev/null +++ b/ueforth/esp32/timers.fs @@ -0,0 +1,44 @@ +vocabulary timers timers definitions also registers + +$3ff5f00 constant TIMG_BASE +( group n = 0/1, timer x = 0/1, watchdog m = 0-5 ) +: TIMGn ( n x -- a ) $10000 * + TIMG_BASE + ; +: TIMGn_Tx ( n x -- a ) $24 * swap TIMGn + ; +: TIMGn_TxCONFIG_REG ( n x -- a ) TIMGn_Tx 0 cells + ; +: TIMGn_TxLOHI_REG ( n x -- a ) TIMGn_Tx 1 cells + ; +: TIMGn_TxUPDATE_REG ( n x -- a ) TIMGn_Tx 3 cells + ; +: TIMGn_TxALARMLOHI_REG ( n x -- a ) TIMGn_Tx 4 cells + ; +: TIMGn_TxLOADLOHI_REG ( n x -- a ) TIMGn_Tx 6 cells + ; +: TIMGn_TxLOAD_REG ( n x -- a ) TIMGn_Tx 8 cells + ; + +: TIMGn_Tx_WDTCONFIGm_REG ( n m -- a ) swap TIMGn cells + $48 + ; +: TIMGn_Tx_WDTFEED_REG ( n -- a ) TIMGn $60 + ; +: TIMGn_Tx_WDTWPROTECT_REG ( n -- a ) TIMGn $6c + ; + +: TIMGn_RTCCALICFG_REG ( n -- a ) TIMGn $68 + ; +: TIMGn_RTCCALICFG1_REG ( n -- a ) TIMGn $6c + ; + +: TIMGn_Tx_INT_ENA_REG ( n -- a ) TIMGn $98 + ; +: TIMGn_Tx_INT_RAW_REG ( n -- a ) TIMGn $9c + ; +: TIMGn_Tx_INT_ST_REG ( n -- a ) TIMGn $a0 + ; +: TIMGn_Tx_INT_CLR_REG ( n -- a ) TIMGn $a4 + ; + +: t>nx ( t -- n x ) dup 2/ 1 and swap 1 and ; + +: timer@ ( t -- lo hi ) + dup t>nx TIMGn_TxUPDATE_REG 0 swap ! + t>nx TIMGn_TxLOHI_REG 2@ ; +: timer! ( lo hi t -- ) + dup >r t>nx TIMGn_TxLOADLOHI_REG 2! + r> t>nx TIMGn_TxLOAD_REG 0 swap ! ; +: alarm ( t -- a ) t>nx TIMGn_TxALARMLOHI_REG ; + +: enable! ( v t ) >r 31 $80000000 r> t>nx TIMGn_TxCONFIG_REG m! ; +: increase! ( v t ) >r 30 $40000000 r> t>nx TIMGn_TxCONFIG_REG m! ; +: autoreload! ( v t ) >r 29 $20000000 r> t>nx TIMGn_TxCONFIG_REG m! ; +: divider! ( v t ) >r 3 $1ffffff8 r> t>nx TIMGn_TxCONFIG_REG m! ; +: edgeint! ( v t ) >r 2 $4 r> t>nx TIMGn_TxCONFIG_REG m! ; +: levelint! ( v t ) >r 1 $2 r> t>nx TIMGn_TxCONFIG_REG m! ; +: alarm-enable! ( v t ) >r 0 $1 r> t>nx TIMGn_TxCONFIG_REG m! ; + +only forth definitions diff --git a/ueforth/site/internals.html b/ueforth/site/internals.html index f92afd0..8b807e9 100644 --- a/ueforth/site/internals.html +++ b/ueforth/site/internals.html @@ -70,8 +70,9 @@ are then used to build up a small set of core opcodes defined in 1-3 lines each:
 0= 0< + U/MOD */MOD   AND OR XOR
-DUP SWAP OVER DROP    @ L@ C@ ! L! C!
-SP@ SP! RP@ RP!       >R R> R@   : ; EXIT
+LSHIFT RSHIFT   DUP SWAP OVER DROP
+@ L@ C@ ! L! C!   SP@ SP! RP@ RP!
+>R R> R@   : ; EXIT
 EXECUTE BRANCH 0BRANCH DONEXT DOLIT
 ALITERAL CELL DOES> IMMEDIATE 'SYS