flash.txt


\ flashio
needs double
hex

fffff304. 2constant IMR
fffff110. 2constant CSA0
10c00000. 2constant FLASH

2variable irq-save
2variable ftgt
2variable fdata

: 2and rot and rot rot and swap ;
: 2or  rot or rot rot or swap ;

: c@f FLASH d+ c@a ;
: c!f FLASH d+ c!a ;
: @f FLASH d+ @a ;
: !f FLASH d+ !a ;

: flash-open  ( -- )
  hex  IMR 2@a irq-save 2!
  00ffffff. IMR 2!a
  CSA0 2@a fffffff7.
  2and CSA0 2!a ;

: flash-close  ( -- )
  irq-save 2@ IMR 2!a
  CSA0 2@a 8. 2or CSA0 2!a  ;

: flash-cmd  ( d -- )
  0aa  aaa.  !f  055  554.  !f  aaa.  !f ;

: flash-check  ( a. -- flag )
  2dup 10d40000.  d<  if
    2drop false
  else 10e00000.  d< if
    true
  else false then then ;

: flash-is-present ( -- flag )
 flash-open  090 flash-cmd
 1.  c@f 1 = if
    2. @f 02249 =  if
      true
    else false then
  else false then
  0f0 0. c!f flash-close ;

: f-data-toggle  ( -- flag )
  ftgt 2@ @a 040 and
  ftgt 2@ @a 040 and  =   ;

: f-timeout  ( -- flag )
  ftgt 2@ @a 020 and 020 = ;

: f-erased  ( -- flag )
  ftgt 2@ @a 080 and 080 = ;

: !!f  ( d a. -- )
  3 enough?   ftgt 2! fdata !
  ftgt 2@ flash-check if
    ftgt 2@ @a fdata @ <> if
      flash-open
      0a0 flash-cmd fdata @ ftgt 2@ !a
      begin f-data-toggle f-timeout or
      until  f-data-toggle 0=
      flash-close if -15 throw then
    then
  else -9 throw then ;

: !!fse  ( a. -- )
  2 enough? ftgt 2!
  ftgt 2@ flash-check if
    flash-open  080 flash-cmd
    0aa  aaa.  !f  055  554.  !f
    030  ftgt 2@  !a
    begin f-erased f-timeout or until
    f-erased 0=
    flash-close if -15 throw then
  else -9 throw then ;


  HTMLized by Forth2HTML