Skip to content

Instantly share code, notes, and snippets.

@sonOfRa
Last active December 21, 2017 16:25
Show Gist options
  • Select an option

  • Save sonOfRa/5545fc3d5ef522f6b86f663bbb66c10e to your computer and use it in GitHub Desktop.

Select an option

Save sonOfRa/5545fc3d5ef522f6b86f663bbb66c10e to your computer and use it in GitHub Desktop.
module Memory where
import CLaSH.Prelude
import Types
initData :: Memory
initData = replicate d80 0
-- Memory state machine.
-- The state of the machine consists of the memory itself, and the
-- most recently read value
-- Outputs the requested value on read, and keeps outputting it
-- until the next read
--
-- For DUMP:
-- Either (Value Vec 80 (Unsigned))
-- Either.isLeft isRight
mem :: State -> (Addr, Control, Value) -> (State, Value)
mem (m, v) (a, c, i)
| c >= Types.read = ((m, m !! a), m !! a)
| c >= Types.write = ((replace a i m, v), v)
| c >= Types.reset = ((replicate d80 0, v), v)
| c >= Types.init = ((initData, v), v)
| c >= Types.dump = ((m, v), v)
| otherwise = ((m, v), v)
-- Initialize memory with all zeroes. Starting output value is also 0
topEntity :: Signal (Addr, Control, Value) -> Signal (Value)
topEntity = mealy mem $ (replicate d80 0, 0)
-- For some reason, using Types.read etc instead of 16, 8, etc here
-- results in a ghci error during VHDL generation. Using the literal values works
testInput :: Signal (Addr, Control, Value)
testInput = stimuliGenerator $(listToVecTH [(0, Types.read, 0),(0, Types.write, 1), (0, Types.read, 0), (1, Types.write, 0) :: (Addr, Control, Value)])
-- This version works correctly:
-- testInput = stimuliGenerator $(listToVecTH [(0, 16, 0),(0, 8, 1), (0, 16, 0), (1, 16, 0) :: (Addr, Control, Value)])
expectedOutput :: Signal (Value) -> Signal Bool
expectedOutput = outputVerifier $(listToVecTH [0, 0, 1, 0 :: Value])
CLaSHi, version 0.7.2 (using clash-lib, version 0.7.1):
http://www.clash-lang.org/ :? for help
[1 of 2] Compiling Types ( Types.hs, interpreted ) [GHC.TypeLits.Normalise changed]
[2 of 2] Compiling Memory ( memory.hs, interpreted )
Ok, modules loaded: Memory, Types.
*Memory> :vhdl
ByteCodeLink.lookupCE
During interactive linking, GHCi couldn't find the following symbol:
Types_write_closure
This may be due to you not asking GHCi to load extra object files,
archives or DLLs needed by your current session. Restart GHCi, specifying
the missing library using the -L/path/to/object/dir and -lmissinglibname
flags, or simply by naming the relevant files on the GHCi command line.
Alternatively, this link failure might indicate a bug in GHCi.
If you suspect the latter, please send a bug report to:
[email protected]
*Memory>
module Types where
import CLaSH.Prelude
type Control = Unsigned 5
read :: Control
read = 16
write :: Control
write = 8
reset :: Control
reset = 4
init :: Control
init = 2
dump :: Control
dump = 1
type Memory = Vec 80 (Unsigned 8)
type Addr = Unsigned 8
type Value = Unsigned 8
type State = (Memory, Value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment