I’ve got two AutoReg questions:
Is there a reason there’s no instance for RamOp
, other than no one’s written it? (I have now…*)
And it seems beneficial for there to be a version of mealy which uses AutoReg internally, is there a good reason that doesn’t exist, other than no one’s written it? (and the explosion of mealy
functions after mealyB
, mealyS
and mealySB
…).
Am I missing anything obvious?
*Implementation below:
instance (AutoReg a, KnownNat n) => AutoReg (RamOp n a) where
autoReg clk rst en initVal input =
createRamOp <$> tagR <*> valAddr <*> valValue
where
tag = toTag <$> input
toTag = \case
RamNoOp -> 0b00 :: BitVector 2
RamRead{} -> 0b01
RamWrite{} -> 0b10
tagInit = toTag initVal
tagR = register clk rst en tagInit tag
toAddr = \case
RamNoOp -> deepErrorX "autoReg'.ramOpAddr"
RamRead addr -> addr
RamWrite addr _ -> addr
toValue = \case
RamWrite _ a -> a
_ -> deepErrorX "autoReg'.ramOpValue"
ramOpAddr = toAddr <$> input
ramOpValue = toValue <$> input
addrInit = toAddr initVal
valInit = toValue initVal
valAddr = autoReg clk rst (andEnable en ((/=0) <$> tag)) addrInit ramOpAddr
valValue = autoReg clk rst (andEnable en (bitToBool . msb <$> tag)) valInit ramOpValue
createRamOp t addr val = case t of
0 -> RamNoOp
1 -> RamRead addr
2 -> RamWrite addr val
_ -> deepErrorX "autoReg'.createRamOp: impossible"
{-# INLINE autoReg #-}