From aed543e5c5cdb78b437b6ff3f04d0fd893694f82 Mon Sep 17 00:00:00 2001 From: Jasper Vinkenvleugel Date: Fri, 21 Jun 2024 10:13:09 +0200 Subject: [PATCH] Move EbTb out of Sgmii --- clash-cores/clash-cores.cabal | 10 +++--- .../src/Clash/Cores/{Sgmii => }/EbTb.hs | 34 ++++++++++++++++--- .../Clash/Cores/{Sgmii => }/EbTb/Decoder.hs | 2 +- .../Clash/Cores/{Sgmii => }/EbTb/Encoder.hs | 2 +- .../src/Clash/Cores/{Sgmii => }/Sgmii.hs | 3 +- clash-cores/src/Clash/Cores/Sgmii/Common.hs | 28 +-------------- .../src/Clash/Cores/Sgmii/PcsReceive.hs | 1 + .../Cores/Sgmii/PcsTransmit/CodeGroup.hs | 2 +- clash-cores/src/Clash/Cores/Sgmii/Sync.hs | 2 +- .../test/Test/Cores/{Sgmii => }/EbTb.hs | 4 +-- .../test/Test/Cores/Sgmii/PcsReceive.hs | 2 +- clash-cores/test/Test/Cores/Sgmii/Sgmii.hs | 1 + clash-cores/test/Test/Cores/Sgmii/Sync.hs | 2 +- clash-cores/test/unittests.hs | 5 ++- 14 files changed, 50 insertions(+), 48 deletions(-) rename clash-cores/src/Clash/Cores/{Sgmii => }/EbTb.hs (73%) rename clash-cores/src/Clash/Cores/{Sgmii => }/EbTb/Decoder.hs (99%) rename clash-cores/src/Clash/Cores/{Sgmii => }/EbTb/Encoder.hs (99%) rename clash-cores/src/Clash/Cores/{Sgmii => }/Sgmii.hs (97%) rename clash-cores/test/Test/Cores/{Sgmii => }/EbTb.hs (97%) diff --git a/clash-cores/clash-cores.cabal b/clash-cores/clash-cores.cabal index 8fe39919e2..13645433df 100644 --- a/clash-cores/clash-cores.cabal +++ b/clash-cores/clash-cores.cabal @@ -126,20 +126,22 @@ library Clash.Cores.Crc Clash.Cores.Crc.Internal Clash.Cores.Crc.Catalog + Clash.Cores.EbTb + Clash.Cores.EbTb.Decoder + Clash.Cores.EbTb.Encoder Clash.Cores.LatticeSemi.ECP5.Blackboxes.IO Clash.Cores.LatticeSemi.ECP5.IO Clash.Cores.LatticeSemi.ICE40.Blackboxes.IO Clash.Cores.LatticeSemi.ICE40.IO + Clash.Cores.Sgmii Clash.Cores.Sgmii.AutoNeg Clash.Cores.Sgmii.BitSlip Clash.Cores.Sgmii.Common - Clash.Cores.Sgmii.EbTb Clash.Cores.Sgmii.Gearbox Clash.Cores.Sgmii.PcsReceive Clash.Cores.Sgmii.PcsTransmit Clash.Cores.Sgmii.PcsTransmit.CodeGroup Clash.Cores.Sgmii.PcsTransmit.OrderedSet - Clash.Cores.Sgmii.Sgmii Clash.Cores.Sgmii.Sync Clash.Cores.SPI Clash.Cores.UART @@ -173,8 +175,6 @@ library Clash.Cores.Xilinx.Xpm.Cdc.SyncRst other-modules: - Clash.Cores.Sgmii.EbTb.Decoder - Clash.Cores.Sgmii.EbTb.Encoder Data.Text.Extra ghc-options: @@ -207,12 +207,12 @@ test-suite unittests other-Modules: Test.Cores.Crc + Test.Cores.EbTb Test.Cores.Internal.SampleSPI Test.Cores.Internal.Signals Test.Cores.Sgmii.AutoNeg Test.Cores.Sgmii.BitSlip Test.Cores.Sgmii.Common - Test.Cores.Sgmii.EbTb Test.Cores.Sgmii.Gearbox Test.Cores.Sgmii.PcsReceive Test.Cores.Sgmii.PcsTransmit diff --git a/clash-cores/src/Clash/Cores/Sgmii/EbTb.hs b/clash-cores/src/Clash/Cores/EbTb.hs similarity index 73% rename from clash-cores/src/Clash/Cores/Sgmii/EbTb.hs rename to clash-cores/src/Clash/Cores/EbTb.hs index abe0203f73..fa7e99fead 100644 --- a/clash-cores/src/Clash/Cores/Sgmii/EbTb.hs +++ b/clash-cores/src/Clash/Cores/EbTb.hs @@ -1,12 +1,38 @@ {-# LANGUAGE CPP #-} -module Clash.Cores.Sgmii.EbTb where +module Clash.Cores.EbTb where -import Clash.Cores.Sgmii.Common -import qualified Clash.Cores.Sgmii.EbTb.Decoder as Dec -import qualified Clash.Cores.Sgmii.EbTb.Encoder as Enc +import qualified Clash.Cores.EbTb.Decoder as Dec +import qualified Clash.Cores.EbTb.Encoder as Enc import Clash.Prelude +-- | Data type that contains a 'BitVector 8' with the corresponding error +-- condition of the decode function +data DataWord + = Dw (BitVector 8) + | Cw (BitVector 8) + | DwError (BitVector 8) + | RdError (BitVector 8) + deriving (Generic, NFDataX, Eq, Show) + +-- | Function to check whether a 'DataWord' results in a data word +isDw :: DataWord -> Bool +isDw (Dw _) = True +isDw _ = False + +-- | Function to check whether a 'DataWord' results in a data word or +-- control word +isValidDw :: DataWord -> Bool +isValidDw (Cw _) = True +isValidDw dw = isDw dw + +-- | Function to convert a 'DataWord' to a plain 'BitVector 8' +fromDw :: DataWord -> BitVector 8 +fromDw dw = case dw of + Dw _dw -> _dw + Cw _dw -> _dw + _ -> 0 + -- | Take the running disparity and the current code group, and return a tuple -- containing the new running disparity and a 'DataWord' containing the -- decoded value. This function uses a 'MemBlob' to store the decoder lookup diff --git a/clash-cores/src/Clash/Cores/Sgmii/EbTb/Decoder.hs b/clash-cores/src/Clash/Cores/EbTb/Decoder.hs similarity index 99% rename from clash-cores/src/Clash/Cores/Sgmii/EbTb/Decoder.hs rename to clash-cores/src/Clash/Cores/EbTb/Decoder.hs index e23fbb61ca..74c89c22c7 100644 --- a/clash-cores/src/Clash/Cores/Sgmii/EbTb/Decoder.hs +++ b/clash-cores/src/Clash/Cores/EbTb/Decoder.hs @@ -1,4 +1,4 @@ -module Clash.Cores.Sgmii.EbTb.Decoder where +module Clash.Cores.EbTb.Decoder where import Clash.Prelude diff --git a/clash-cores/src/Clash/Cores/Sgmii/EbTb/Encoder.hs b/clash-cores/src/Clash/Cores/EbTb/Encoder.hs similarity index 99% rename from clash-cores/src/Clash/Cores/Sgmii/EbTb/Encoder.hs rename to clash-cores/src/Clash/Cores/EbTb/Encoder.hs index 67b9498fa3..1586ac31e7 100644 --- a/clash-cores/src/Clash/Cores/Sgmii/EbTb/Encoder.hs +++ b/clash-cores/src/Clash/Cores/EbTb/Encoder.hs @@ -1,4 +1,4 @@ -module Clash.Cores.Sgmii.EbTb.Encoder where +module Clash.Cores.EbTb.Encoder where import Clash.Prelude diff --git a/clash-cores/src/Clash/Cores/Sgmii/Sgmii.hs b/clash-cores/src/Clash/Cores/Sgmii.hs similarity index 97% rename from clash-cores/src/Clash/Cores/Sgmii/Sgmii.hs rename to clash-cores/src/Clash/Cores/Sgmii.hs index 6acbfb5c5b..4b33fb37a1 100644 --- a/clash-cores/src/Clash/Cores/Sgmii/Sgmii.hs +++ b/clash-cores/src/Clash/Cores/Sgmii.hs @@ -1,5 +1,6 @@ -module Clash.Cores.Sgmii.Sgmii where +module Clash.Cores.Sgmii where +import Clash.Cores.EbTb import Clash.Cores.Sgmii.AutoNeg import Clash.Cores.Sgmii.BitSlip import Clash.Cores.Sgmii.Common diff --git a/clash-cores/src/Clash/Cores/Sgmii/Common.hs b/clash-cores/src/Clash/Cores/Sgmii/Common.hs index cb88025fa6..ca3906a92d 100644 --- a/clash-cores/src/Clash/Cores/Sgmii/Common.hs +++ b/clash-cores/src/Clash/Cores/Sgmii/Common.hs @@ -1,37 +1,11 @@ module Clash.Cores.Sgmii.Common where +import Clash.Cores.EbTb import Clash.Prelude -- | Format of rxConfReg and txConfReg, size of two data words type ConfReg = BitVector 16 --- | Data type that contains a 'BitVector 8' with the corresponding error --- condition of the decode function -data DataWord - = Dw (BitVector 8) - | Cw (BitVector 8) - | DwError (BitVector 8) - | RdError (BitVector 8) - deriving (Generic, NFDataX, Eq, Show) - --- | Function to check whether a 'DataWord' results in a data word -isDw :: DataWord -> Bool -isDw (Dw _) = True -isDw _ = False - --- | Function to check whether a 'DataWord' results in a data word or --- control word -isValidDw :: DataWord -> Bool -isValidDw (Cw _) = True -isValidDw dw = isDw dw - --- | Function to convert a 'DataWord' to a plain 'BitVector 8' -fromDw :: DataWord -> BitVector 8 -fromDw dw = case dw of - Dw _dw -> _dw - Cw _dw -> _dw - _ -> 0 - -- | Defines the possible values for the RUDI output signal of the PCS Receive -- block as defined in IEEE 802.3 Clause 36 data Rudi = C | I | Invalid diff --git a/clash-cores/src/Clash/Cores/Sgmii/PcsReceive.hs b/clash-cores/src/Clash/Cores/Sgmii/PcsReceive.hs index 5d0a3b6453..40354ef55c 100644 --- a/clash-cores/src/Clash/Cores/Sgmii/PcsReceive.hs +++ b/clash-cores/src/Clash/Cores/Sgmii/PcsReceive.hs @@ -2,6 +2,7 @@ module Clash.Cores.Sgmii.PcsReceive where +import Clash.Cores.EbTb import Clash.Cores.Sgmii.Common import Clash.Prelude diff --git a/clash-cores/src/Clash/Cores/Sgmii/PcsTransmit/CodeGroup.hs b/clash-cores/src/Clash/Cores/Sgmii/PcsTransmit/CodeGroup.hs index 4e226baa4c..72f41f5ce8 100644 --- a/clash-cores/src/Clash/Cores/Sgmii/PcsTransmit/CodeGroup.hs +++ b/clash-cores/src/Clash/Cores/Sgmii/PcsTransmit/CodeGroup.hs @@ -2,8 +2,8 @@ module Clash.Cores.Sgmii.PcsTransmit.CodeGroup where +import Clash.Cores.EbTb import Clash.Cores.Sgmii.Common -import Clash.Cores.Sgmii.EbTb import Clash.Prelude -- | State type of 'codeGroupT' as defined in IEEE 802.3 Clause 36, with the diff --git a/clash-cores/src/Clash/Cores/Sgmii/Sync.hs b/clash-cores/src/Clash/Cores/Sgmii/Sync.hs index 46526b21e6..f59380729c 100644 --- a/clash-cores/src/Clash/Cores/Sgmii/Sync.hs +++ b/clash-cores/src/Clash/Cores/Sgmii/Sync.hs @@ -3,8 +3,8 @@ module Clash.Cores.Sgmii.Sync where +import Clash.Cores.EbTb import Clash.Cores.Sgmii.Common -import Clash.Cores.Sgmii.EbTb import Clash.Prelude -- | State type of the output queue for 'sync' diff --git a/clash-cores/test/Test/Cores/Sgmii/EbTb.hs b/clash-cores/test/Test/Cores/EbTb.hs similarity index 97% rename from clash-cores/test/Test/Cores/Sgmii/EbTb.hs rename to clash-cores/test/Test/Cores/EbTb.hs index ca72d7b3f0..b709b7bf7f 100644 --- a/clash-cores/test/Test/Cores/Sgmii/EbTb.hs +++ b/clash-cores/test/Test/Cores/EbTb.hs @@ -1,7 +1,7 @@ -module Test.Cores.Sgmii.EbTb where +module Test.Cores.EbTb where +import Clash.Cores.EbTb import Clash.Cores.Sgmii.Common -import Clash.Cores.Sgmii.EbTb import Clash.Hedgehog.Sized.BitVector import qualified Hedgehog as H import qualified Hedgehog.Gen as Gen diff --git a/clash-cores/test/Test/Cores/Sgmii/PcsReceive.hs b/clash-cores/test/Test/Cores/Sgmii/PcsReceive.hs index a0ff2fd073..16fdf52d83 100644 --- a/clash-cores/test/Test/Cores/Sgmii/PcsReceive.hs +++ b/clash-cores/test/Test/Cores/Sgmii/PcsReceive.hs @@ -2,8 +2,8 @@ module Test.Cores.Sgmii.PcsReceive where +import Clash.Cores.EbTb import Clash.Cores.Sgmii.Common -import Clash.Cores.Sgmii.EbTb import Clash.Cores.Sgmii.PcsReceive import Clash.Hedgehog.Sized.BitVector import qualified Clash.Prelude as C diff --git a/clash-cores/test/Test/Cores/Sgmii/Sgmii.hs b/clash-cores/test/Test/Cores/Sgmii/Sgmii.hs index bdb593515f..9218709162 100644 --- a/clash-cores/test/Test/Cores/Sgmii/Sgmii.hs +++ b/clash-cores/test/Test/Cores/Sgmii/Sgmii.hs @@ -2,6 +2,7 @@ module Test.Cores.Sgmii.Sgmii where +import Clash.Cores.EbTb import Clash.Cores.Sgmii.AutoNeg import Clash.Cores.Sgmii.BitSlip import Clash.Cores.Sgmii.Common diff --git a/clash-cores/test/Test/Cores/Sgmii/Sync.hs b/clash-cores/test/Test/Cores/Sgmii/Sync.hs index 1f6b6a8deb..77961b7873 100644 --- a/clash-cores/test/Test/Cores/Sgmii/Sync.hs +++ b/clash-cores/test/Test/Cores/Sgmii/Sync.hs @@ -1,7 +1,7 @@ module Test.Cores.Sgmii.Sync where +import Clash.Cores.EbTb import Clash.Cores.Sgmii.Common -import Clash.Cores.Sgmii.EbTb import Clash.Cores.Sgmii.Sync import Clash.Hedgehog.Sized.BitVector import qualified Clash.Prelude as C diff --git a/clash-cores/test/unittests.hs b/clash-cores/test/unittests.hs index a385cdbffd..9ca1fcc60b 100644 --- a/clash-cores/test/unittests.hs +++ b/clash-cores/test/unittests.hs @@ -11,9 +11,9 @@ import Prelude import Test.Tasty import qualified Test.Cores.Crc +import qualified Test.Cores.EbTb import qualified Test.Cores.Sgmii.AutoNeg import qualified Test.Cores.Sgmii.BitSlip -import qualified Test.Cores.Sgmii.EbTb import qualified Test.Cores.Sgmii.Gearbox import qualified Test.Cores.Sgmii.PcsReceive import qualified Test.Cores.Sgmii.PcsTransmit @@ -29,10 +29,9 @@ import qualified Test.Cores.Xilinx.DnaPortE2 tests :: TestTree tests = testGroup "Unittests" [ Test.Cores.Crc.tests - , Test.Cores.Sgmii.EbTb.tests + , Test.Cores.EbTb.tests , Test.Cores.Sgmii.AutoNeg.tests , Test.Cores.Sgmii.BitSlip.tests - , Test.Cores.Sgmii.EbTb.tests , Test.Cores.Sgmii.Gearbox.tests , Test.Cores.Sgmii.PcsReceive.tests , Test.Cores.Sgmii.PcsTransmit.tests