{-# OPTIONS --safe --cubical #-}
module Spartan6.Primitive.BlockRAM where
open import Spartan6.Prelude
open import Spartan6.Evidence
using (SemanticStatus; documentedUnspecified;
SupportStatus; unsupportedFeature)
import Spartan6.Foundation.Memory as Memory
data WriteMode : Type₀ where
WRITE_FIRST : WriteMode
READ_FIRST : WriteMode
NO_CHANGE : WriteMode
record SinglePortState (depth width : ℕ) : Type₀ where
constructor singlePortState
field
memoryContents : Memory.Memory depth width
outputLatch : Word width
open SinglePortState public
record PortCommand (depth width : ℕ) : Type₀ where
constructor portCommand
field
commandAddress : Fin depth
commandInput : Word width
commandEnable : Bit
commandWriteEnable : Bit
open PortCommand public
clockEdge : ∀ {depth width}
→ WriteMode
→ PortCommand depth width
→ SinglePortState depth width
→ SinglePortState depth width
clockEdge mode
(portCommand address inputValue false writeEnabled)
state =
state
clockEdge mode
(portCommand address inputValue true false)
state =
singlePortState
(memoryContents state)
(Memory.read address (memoryContents state))
clockEdge WRITE_FIRST
(portCommand address inputValue true true)
state =
singlePortState
(Memory.write address inputValue (memoryContents state))
inputValue
clockEdge READ_FIRST
(portCommand address inputValue true true)
state =
singlePortState
(Memory.write address inputValue (memoryContents state))
(Memory.read address (memoryContents state))
clockEdge NO_CHANGE
(portCommand address inputValue true true)
state =
singlePortState
(Memory.write address inputValue (memoryContents state))
(outputLatch state)
disabled-holds : ∀ {depth width}
(mode : WriteMode) (address : Fin depth) (inputValue : Word width)
(writeEnabled : Bit) (state : SinglePortState depth width)
→ clockEdge mode
(portCommand address inputValue low writeEnabled) state
≡ state
disabled-holds mode address inputValue writeEnabled state = refl
read-loads-latch : ∀ {depth width}
(mode : WriteMode) (address : Fin depth) (inputValue : Word width)
(state : SinglePortState depth width)
→ outputLatch
(clockEdge mode (portCommand address inputValue high low) state)
≡ Memory.read address (memoryContents state)
read-loads-latch mode address inputValue state = refl
write-first-output : ∀ {depth width}
(address : Fin depth) (inputValue : Word width)
(state : SinglePortState depth width)
→ outputLatch
(clockEdge WRITE_FIRST
(portCommand address inputValue high high) state)
≡ inputValue
write-first-output address inputValue state = refl
read-first-output : ∀ {depth width}
(address : Fin depth) (inputValue : Word width)
(state : SinglePortState depth width)
→ outputLatch
(clockEdge READ_FIRST
(portCommand address inputValue high high) state)
≡ Memory.read address (memoryContents state)
read-first-output address inputValue state = refl
no-change-output : ∀ {depth width}
(address : Fin depth) (inputValue : Word width)
(state : SinglePortState depth width)
→ outputLatch
(clockEdge NO_CHANGE
(portCommand address inputValue high high) state)
≡ outputLatch state
no-change-output address inputValue state = refl
write-stores : ∀ {depth width}
(mode : WriteMode) (address : Fin depth) (inputValue : Word width)
(state : SinglePortState depth width)
→ Memory.read address
(memoryContents
(clockEdge mode
(portCommand address inputValue high high) state))
≡ inputValue
write-stores WRITE_FIRST address inputValue state =
Memory.read-after-write-same address inputValue (memoryContents state)
write-stores READ_FIRST address inputValue state =
Memory.read-after-write-same address inputValue (memoryContents state)
write-stores NO_CHANGE address inputValue state =
Memory.read-after-write-same address inputValue (memoryContents state)
nineKbInitializationStatus : SemanticStatus
nineKbInitializationStatus = documentedUnspecified
nineKbConfigurationReadbackStatus : SupportStatus
nineKbConfigurationReadbackStatus = unsupportedFeature
nineKb-initialization-is-unspecified :
nineKbInitializationStatus ≡ documentedUnspecified
nineKb-initialization-is-unspecified = refl
nineKb-readback-is-unsupported :
nineKbConfigurationReadbackStatus ≡ unsupportedFeature
nineKb-readback-is-unsupported = refl
exampleMemory : Memory.Memory 2 2
exampleMemory =
(low ∷ low ∷ []) ∷
(high ∷ low ∷ []) ∷
[]
exampleState : SinglePortState 2 2
exampleState = singlePortState exampleMemory (low ∷ high ∷ [])
exampleWrite : PortCommand 2 2
exampleWrite = portCommand fzero (high ∷ high ∷ []) high high
example-write-first :
outputLatch (clockEdge WRITE_FIRST exampleWrite exampleState)
≡ (high ∷ high ∷ [])
example-write-first = refl
example-read-first :
outputLatch (clockEdge READ_FIRST exampleWrite exampleState)
≡ (low ∷ low ∷ [])
example-read-first = refl
example-no-change :
outputLatch (clockEdge NO_CHANGE exampleWrite exampleState)
≡ (low ∷ high ∷ [])
example-no-change = refl
example-write-stored :
Memory.read fzero
(memoryContents (clockEdge NO_CHANGE exampleWrite exampleState))
≡ (high ∷ high ∷ [])
example-write-stored = refl