---- MODULE FlashMemory ----
EXTENDS TLC, Naturals, Integers
CONSTANTS N, Length
VARIABLES Programmed, SectorState
ASSUME N \in Nat /\ Length \in Nat
----
Sectors == 1..N
AddressSpace == 1..(N * Length)
----
Init == /\ Programmed = {}
/\ SectorState = [i \in Sectors |-> "unknown"]
TypeOk == /\ Programmed \subseteq AddressSpace
/\ \A s \in Sectors :SectorState[s] \in {"unknown", "erased", "programmed"}
SectorBytes == [s \in Sectors |-> (1 + (s-1)*Length)..(s*Length)]
ByteRange(start, n) == start..(start+n-1)
Write(start, n) == LET Bytes == ByteRange(start, n)
WriteSectors == {s \in Sectors : SectorBytes[s] \cap Bytes /= {}}
IN
/\ Bytes \subseteq AddressSpace \* Cannot write outside the range
/\ \A s \in WriteSectors : SectorState[s] /= "unknown" \* Only program sectors in a known state
/\ Programmed \cap Bytes = {} \* Cannot reprogram locations
/\ SectorState' = [s \in WriteSectors |-> "programmed"] @@ SectorState
/\ Programmed' = Programmed \cup Bytes
(* Erase a sector, clearing all programmed locations and setting the sector state *)
Erase(s) == /\ SectorState' = [SectorState EXCEPT ![s] = "erased"]
/\ Programmed' = Programmed \ SectorBytes[s]
Next == (\E start, len \in AddressSpace : Write(start, len)) \/ (\E sect \in Sectors : Erase(sect))
====
--
You received this message because you are subscribed to the Google Groups "tlaplus" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tlaplus+u...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/tlaplus/e14dd319-6f38-421a-9259-fe0bd08d119dn%40googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/tlaplus/6bdfc51e-b221-4da1-b29d-29c9a1a75d07n%40googlegroups.com.