So the compiler is telling you:
I expect a Signal
in the clock domain dom
of type (BlockRamOp addr0 Acc_sub)
But you are giving me:
a (BlockRamOp addr0 Acc_sub)
The latter is a singular value, while a Signal
is essentially a stream of values changing over time (in clock cycles).
You could use the pure
function that can turn any value a
into a Signal dom a
, but if you would hook that up to the block ram, you would be writing the same value to the same location at every clock cycle, which is not very useful.
You said that you want to write the result of your calculation to the blockram, so I expect you have some function with one input a - > b
, or multiple inputs a -> b -> c
etc that you want to apply to some input.
Let’s for now assume you want to simply apply a -> b
to the input of your circuit and store the result. and let’s assume that for now your circuit receive a new value every clock cycle, then your input looks like: Signal dom a
.
Here the Signal dom
means that you get a new value for every clock cycle of the clock in domain dom
. The a
is the type of your input value.
If we want to apply our function and simply write the result to address 0
, we could do that as follows:
myCircuit ::
(HiddenClockResetEnable dom, Num b) =>
-- | Initial content of the blockram, containing `n` values of type `b`
Vec 16 b ->
-- | Input signal with values of type `a`
Signal dom a ->
-- | Output signal with values of type `b`
Signal dom b
myCircuit bramInit a = blockRamOut
where
-- Apply the function `f` to the values in our input signal,
-- this creates a combinatorial circuit.
functionResult = fmap f a
-- The blockram expects `Signal dom (Maybe (addr, b))` as input,
-- so we have to tell it that we want to write our `b` to some address
blockRamIn = fmap (\b -> Just (0 :: Index 16, b)) functionResult
-- Connect the signal that writes to the blockram to the blockram.
-- Continuously read the value at address 0 from the blockram.
blockRamOut = blockRam bramInit (pure 0) blockRamIn
Note that I hardcoded the size of the blockram to 16 elements for this example and the first arguments sets the initial contents of the blockram.