aboutsummaryrefslogtreecommitdiff
path: root/amforth-6.5/avr8/lib/hardware/flash-block.frt
diff options
context:
space:
mode:
Diffstat (limited to 'amforth-6.5/avr8/lib/hardware/flash-block.frt')
-rw-r--r--amforth-6.5/avr8/lib/hardware/flash-block.frt37
1 files changed, 37 insertions, 0 deletions
diff --git a/amforth-6.5/avr8/lib/hardware/flash-block.frt b/amforth-6.5/avr8/lib/hardware/flash-block.frt
new file mode 100644
index 0000000..661e3b4
--- /dev/null
+++ b/amforth-6.5/avr8/lib/hardware/flash-block.frt
@@ -0,0 +1,37 @@
+\
+\ flash-block
+\ contiguous flash region used a block storage
+\
+\ requires blocks.frt (for init and blocksize)
+\
+
+\ start address for blocks.
+\ the block data starts at
+\ flash.base-addr + (blocknum*blocksize)
+\ it could be beyond the 128K limit, if the
+\ !i and @i are replaced by words which take a
+\ doube cell address or handle the block at once
+\ (preferred)
+\
+variable flash.base-addr
+
+\ remember a flash cell contains 2 bytes
+
+: flash.load-buffer ( a-addr u -- )
+ 1- blocksize 2/ * flash.base-addr @ +
+ blocksize 2/ bounds ?do i @i over ! cell+ loop drop
+;
+
+: flash.save-buffer ( a-addr u -- )
+ 1- blocksize 2/ * flash.base-addr @ +
+ ." still debugging. no actual flash write!"
+ blocksize 2/ bounds ?do dup @ i 2drop ( !i) cell+ loop drop
+;
+
+\ for turnkey
+: flash.init ( -- )
+ ['] flash.load-buffer is load-buffer
+ ['] flash.save-buffer is save-buffer
+ 0 flash.base-addr !
+ block:init
+;