4

I have here a York Lava function that I want to rewrite in Kansas Lava. But it doesn't want to work and I don't know I should do it actually. Can someone help me with this please?

{-Serial In - Parallel Out shiftregister. The serial bit is inserted at
the least significant bit position. The data is shifted LSB -> MSB
each and every clock cycle-}

sipo :: Int   -- ^ The number of bits in the output word.
     -> Bit   -- ^ The input bit.
     -> [Bit] -- ^ The output word.
sipo 1 inp = [inp]
sipo n inp = inp : rest
  where
    inp' = delay low inp
    rest = sipo (n-1) inp'

This above function gives me these correct results for some examples:

n = 3
inp = high
out = [high, low, low]

n= 5
inp = high
out = [high, low, low, low, low]

Now I've tried to write this in Kansas Lava, their is a delay function, but I get weird results. This code below generates me, with the same parameters as the first example:

n = 3
inp = high
out = [high?, high., high!] (don't know what that means)

sipo :: (Clock clk)
     => Int               -- ^ The number of bits in the output word.
     -> Signal clk Bool     -- ^ The input bit.
     -> [Signal clk Bool]   -- ^ The output word.
sipo 1 inp = [inp]
sipo n inp = inp : rest
  where
    inp' = delay inp
    rest = sipo (n-1) inp'   
Cactus
  • 27,075
  • 9
  • 69
  • 149
Daan Mouha
  • 580
  • 1
  • 6
  • 20
  • Can you be a little more specific about what the correct output should be? – Robert Harvey May 09 '14 at 16:42
  • n stands for how big the list wil be inp is the input in low or high The output is than inp ++ n times low values out = [inp, low, low, low, ..., n] Example: n = 2 inp = high out = [high, low] Second example: n = 5 inp = low out = [low, low, low, low, low] – Daan Mouha May 09 '14 at 17:27
  • (1) Are you sure the final snippet matches the error you pasted above it? I can't see how specialising `i` to `CLK` would lead to `Couldn't match expected type '[Signal i0 Bool]' with actual type 'Signal clk0 a0'.` (2) Which type does GHC(i) infer for `sipo` if you momentarily remove the signature? – duplode May 09 '14 at 19:25
  • Ok I was forgot to put something in comment in my code, so that error is not applied on this piece of code. But I don't get the right output – Daan Mouha May 11 '14 at 17:39

1 Answers1

2

Your code works exactly as expected.

Trying your function out in the simulator from GHCi, the result is:

*Main> sipo 3 (high :: Signal CLK Bool)
[high,? | high .,? | ? | high .]

The way to read it is:

 sipo 3 high !! 0 = high
 sipo 3 high !! 1 = ?    | high
 sipo 3 high !! 2 = ?    | ?    | high

This output from the Lava simulator means the first output is high in the first cycle, and there's no simulator input to tell futher values. Similarly, the second output is undefined in the first cycle and high in the second; and the third output is undefined for two cycles and high in the third.

This makes perfect sense, since the second output is not set to anything in the first cycle: the delayed input signal hasn't had time yet to get there.

The reason the result is different from York Lava is that York Lava's delay primitive seems to take an extra value to be used before the first clock cycle. I'm not sure that is synthesizable, though.

Cactus
  • 27,075
  • 9
  • 69
  • 149