Skip to content

Commit

Permalink
Multiplex (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
dopamane authored Aug 18, 2024
1 parent a7086dc commit 867c8c2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions bayeux.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ library
, Bayeux.Ice40.Spi
, Bayeux.Ice40.Spram
, Bayeux.Lp
, Bayeux.Mux
, Bayeux.Rtl
, Bayeux.Signal
, Bayeux.Tableaux
Expand Down
26 changes: 26 additions & 0 deletions lib/Bayeux/Mux.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
-- | [Multiplex](https://en.wikipedia.org/wiki/Multiplexer)
module Bayeux.Mux
( MonadMux(..)
) where

import Bayeux.Rtl hiding (mux)
import Bayeux.Signal
import Bayeux.Width
import Control.Monad.Writer
import Yosys.Rtl

class MonadMux m where
mux :: Width a
=> Sig a -- ^ 'False'
-> Sig a -- ^ 'True'
-> Sig Bool
-> m (Sig a)

instance MonadMux Rtl where
mux f t s = do
y <- freshWire w
cId <- freshCellId
tell [ModuleBodyCell $ muxC cId w (spec f) (spec t) (spec s) y]
return $ Sig y
where
w = width f
2 changes: 1 addition & 1 deletion lib/Bayeux/Rtl.hs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ instance MonadRtl Rtl where
y <- freshWire 1
tell [ModuleBodyConnStmt $ ConnStmt y (SigSpecSlice sigSpec ix Nothing)]
return y

mux w s a b = do
y <- freshWire w
cId <- freshCellId
Expand Down

0 comments on commit 867c8c2

Please sign in to comment.