2014-05-09 34 views
4

我在这里有一个约克熔岩函数,我想在堪萨斯熔岩重写。但它不想工作,我不知道我应该这样做。 有人可以帮助我吗?将约克熔岩函数转换为堪萨斯熔岩

{-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' 

这上面的函数给了我一些例子,这些正确的结果:

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

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

现在,我已经试过在堪萨斯熔岩写这个,他们是延迟功能,但我得到奇怪的结果。 下面这段代码生成我,用相同的参数,第一个例子:

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' 
+0

你能更具体一点关于正确的输出应该是什么? –

+0

n代表列表有多大 inp是输入低或高 输出比inp ++ n倍低值 out = [inp,low,low,low,...,n ] 示例:n = 2的 INP =高 OUT = [高,低] 第二个例子:N = 5 INP =低 OUT = [低,低,低,低,低] –

+0

(1)你确定最后的代码段与你粘贴的错误相符吗? (2)GHC(i)的类型是什么类型?我不知道'I'到'CLK'的专业化会导致'无法匹配预期类型'[Signal i0 Bool]',实际类型'Signal clk0 a0' )如果你暂时删除签名,推断“sipo”? – duplode

回答

2

你的代码工作完全按照预期。

尝试你的函数了从GHCI模拟器,其结果是:

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

读它的方式是:

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

这从熔岩模拟器输出装置的第一输出在第一个循环中为high,并且没有模拟器输入来告诉更多的值。同样,第二个输出在第一个周期中是未定义的,第二个输出是high;第三个输出未定义为两个周期,第三个输出为high

这很有道理,因为第二个输出在第一个周期中没有设置为任何值:延迟的输入信号尚未到达那里。

结果与York Lava不同的原因是York Lava的delay原始图似乎需要额外的价值才能在第一个时钟周期之前使用。不过,我不确定这是可综合的。