Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move i2c to clash cores #2584

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
31 changes: 0 additions & 31 deletions clash-cores/src/Clash/Cores/I2C.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,6 @@ import Clash.Prelude hiding (read)
import Clash.Cores.I2C.BitMaster
import Clash.Cores.I2C.ByteMaster

{-# ANN i2c
(Synthesize
{ t_name = "i2c"
, t_inputs = [ PortName "clk"
, PortName "arst"
, PortName "rst"
, PortName "ena"
, PortName "clkCnt"
, PortName "start"
, PortName "stop"
, PortName "read"
, PortName "write"
, PortName "ackIn"
, PortName "din"
, PortProduct "i2c"
[ PortName "sda"
, PortName "sdaEn"]
]
, t_output = PortProduct ""
[ PortName "dout"
, PortName "hostAck"
, PortName "busy"
, PortName "al"
, PortName "ackOut"
, PortProduct "i2cO"
[ PortName "scl"
, PortName "sclOEn"
, PortName "sda"
, PortName "sdaOEn"
]]
}) #-}
-- | Core for I2C communication
i2c ::
forall dom .
Expand Down
29 changes: 1 addition & 28 deletions clash-cores/src/Clash/Cores/I2C/BitMaster.hs
Original file line number Diff line number Diff line change
Expand Up @@ -52,34 +52,7 @@ type BitMasterI = (Bool,Bool,Unsigned 16,BitCtrlSig,I2CIn)
-- 3. Contains the SCL and SDA output signals
type BitMasterO = (BitRespSig,Bool,I2COut)

{-# ANN bitMaster
(Synthesize
{ t_name = "bitmaster"
, t_inputs = [ PortName "clk"
, PortName "arst"
, PortName "gen"
, PortProduct ""
[ PortName "rst"
, PortName "ena"
, PortName "clkCnt"
, PortProduct ""
[ PortName "cmd"
, PortName "din" ]
, PortName "i2cI" ]
]
, t_output = PortProduct ""
[ PortProduct ""
[ PortName "cmdAck"
, PortName "al"
, PortName "dout" ]
, PortName "busy"
, PortProduct "i2c"
[ PortName "sda"
, PortName "sdaEn"
, PortName "scl"
, PortName "sclEn" ]
]
}) #-}

bitMaster
:: KnownDomain dom
=> Clock dom
Expand Down
23 changes: 0 additions & 23 deletions clash-cores/src/Clash/Cores/I2C/ByteMaster.hs
Original file line number Diff line number Diff line change
Expand Up @@ -48,29 +48,6 @@ type ByteMasterI = (Bool,Bool,Bool,Bool,Bool,Bool,BitVector 8,BitRespSig)
-- 4 Bitmaster control signals
type ByteMasterO = (Bool,Bool,BitVector 8,BitCtrlSig)

{-# ANN byteMaster
(Synthesize
{ t_name = "bytemaster"
, t_inputs = [ PortName "clk"
, PortName "arst"
, PortName "gen"
, PortProduct ""
[ PortName "rst"
, PortName "start"
, PortName "stop"
, PortName "read"
, PortName "write"
, PortName "ackIn"
, PortName "din"
, PortName "bitResp" ]
]
, t_output = PortProduct ""
[ PortName "hostAck"
, PortName "ackOut"
, PortName "dout"
, PortName "bitCtrl"
]
}) #-}
-- | Byte level controller, takes care of correctly executing i2c communication
-- based on the supplied control signals. It should be instantiated alongside 'bitMaster'.
-- The outgoing bitCtrl' controls the 'bitMaster' whose 'bitResp' should be supplied
Expand Down
2 changes: 1 addition & 1 deletion clash-cores/test/Test/Cores/I2C.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ system0 clk arst = bundle (registerFile,done,fault)
-- See: https://github.com/clash-lang/clash-compiler/pull/2511
{-# CLASH_OPAQUE system0 #-}

{-# ANN system Synthesize { t_name = "system", t_inputs = [], t_output = PortName "" } #-}
{-# ANN system (defSyn "system") #-}
system :: Signal System (Vec 16 (Unsigned 8), Bool, Bool)
system = system0 systemClockGen resetGen

Expand Down
18 changes: 0 additions & 18 deletions tests/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -158,24 +158,6 @@ runClashTest = defaultMain $ clashTestRoot
, clashTestGroup "crc32"
[ runTest "CRC32" def
]
, clashTestGroup "i2c"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The I2C test is:

  1. The only test in the clash testsuite that has multiple synthesize annotations
  2. Tests SimIO in a common user scenario.

So I would like it if this test wasn't removed. And given that the I2C core in clash cores has a new API, perhaps we can either just:

  1. Keep the old domain-monomorphic code in the examples directory
  2. Or move the old domain-monomorphic code to a test directory
    So that we still have a test with multiple Synthesize annotations.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Sounds like the best option to me!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also agree with 2, we can just put the old code in a test directory.

[ let _opts = def { clashFlags=["-O2","-fclash-component-prefix","test"]
, buildTargets=BuildSpecific ["test_i2c"]
, hdlSim=[]
}
in runTest "I2C" _opts
,
-- TODO: this uses finish_and_return, with is Icarus Verilog only.
-- see: https://github.com/clash-lang/clash-compiler/issues/2265
let _opts = def { buildTargets = BuildSpecific ["system"]
, hdlTargets = [Verilog]
, hdlLoad = [IVerilog]
, hdlSim = [IVerilog]
, vvpStdoutNonEmptyFail = False
}
in runTest "I2Ctest" _opts

]
]
, clashTestGroup "tests"
[ clashTestGroup "shouldfail"
Expand Down