2014-05-07 40 views
1

我從堪薩斯州熔岩紙得到了一段代碼,可行。哈斯克爾/堪薩斯熔岩移位寄存器錯誤

counter :: Signal CLK Bool -> Signal CLK Bool -> Signal CLK Int 
counter restart inc = loop 
    where 
    reg = register 0 loop 
    reg' = mux restart (0, reg) 
    loop = mux inc (reg' + 1, reg') 

現在我試圖在另一個功能,與另一個功能,這是行不通的。

shiftReg_d2f :: Signal CLK Bool -> Signal CLK Bool -> [Signal CLK Bool] -> [Signal CLK Bool] -> [Signal CLK Bool] 
shiftReg_d2f load shift wordIn fieldIn = fieldOut 
    where 
    fieldOut = register 0 fieldOut'' 
    shiftField = drop (length wordIn) fieldOut ++ wordIn 
    fieldOut' = muxl shift fieldOut shiftField 
    fieldOut'' = muxl load fieldOut' fieldIn 

現在,我得到了以下錯誤:

  • 無法匹配,期望與實際類型Signal clk0 a0(3次)
  • 無法比擬預期型Signal i0 Bool與實際類型[Signal i0 Bool][Signal i0 Bool]
  • 無法匹配預期類型Signal i Bool -> Signal i Bool -> Signal i Bool與實際類型Signal i Bool

我該怎麼做?

感謝您的幫助

回答

1

問題是你與[Signal clk a]混合起來Signal clk [a]。前者在HDL環境中基本上不可行,因爲它的寬度是無界的,並且可能隨着週期而變化。

你可以做的是定義fieldOut線控。

shiftReg_d2f :: Signal CLK Bool -> Signal CLK Bool -> [Signal CLK Bool] -> [Signal CLK Bool] -> [Signal CLK Bool] 
shiftReg_d2f load shift wordIn fieldIn = fieldOut 
    where 
    fieldOut = zipWith toOutput fieldIn (drop (length wordIn) fieldOut ++ wordIn) 
    toOutput input shifted = r 
     where 
     r = register False $ mux load (mux shift (r, shifted), input) 
:關鍵的見解是,因此,通過壓縮和解了 fieldIndrop (length wordIn) fieldOut ++ wordIn我們可以生成一點一滴給定輸入

fieldIn = [x0, x1, x2, x3] 
wordIn = [w0, w1, w2] 
fieldOut = [y0, y1, y2, y3] 

輸出要求是

if load: [x0, x1, x2, x3] = fieldIn 
if shift: [y3, w0, w1, w2] = drop (lenght wordIn) fieldOut ++ wordIn 
otherwise: [y0, y1, y2, y3] = fieldOut 

一個