-
Notifications
You must be signed in to change notification settings - Fork 156
/
Copy pathFIR.hs
43 lines (37 loc) · 1.1 KB
/
FIR.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
{-# LANGUAGE CPP #-}
module FIR where
import Clash.Prelude
import Clash.Explicit.Testbench
dotp :: SaturatingNum a
=> Vec (n + 1) a
-> Vec (n + 1) a
-> a
dotp as bs = fold boundedAdd (zipWith boundedMul as bs)
fir
:: ( HiddenClockResetEnable tag
, Default a
, KnownNat n
, SaturatingNum a
, NFDataX a )
=> Vec (n + 1) a -> Signal tag a -> Signal tag a
fir coeffs x_t = y_t
where
y_t = dotp coeffs <$> bundle xs
xs = window x_t
topEntity
:: Clock System
-> Reset System
-> Enable System
-> Signal System (Signed 16)
-> Signal System (Signed 16)
topEntity = exposeClockResetEnable (fir (2:>3:>(-2):>8:>Nil))
-- See: https://github.com/clash-lang/clash-compiler/pull/2511
{-# CLASH_OPAQUE topEntity #-}
testBench :: Signal System Bool
testBench = done
where
testInput = stimuliGenerator clk rst (2:>3:>(-2):>8:>Nil)
expectedOutput = outputVerifier' clk rst (4:>12:>1:>20:>Nil)
done = expectedOutput (topEntity clk rst (enableGen) testInput)
clk = tbSystemClockGen (not <$> done)
rst = systemResetGen