Created
January 22, 2015 18:56
-
-
Save cfelton/c328b143d49cd1db7fc4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from myhdl import * | |
class Mux(object): | |
def __init__(self, inputs, output, sel): | |
self.nports = len(inputs) | |
self.inputs = inputs | |
self.output = output | |
self.sel = sel | |
def logic(self): | |
""" | |
note note convertible, to make convertible, move ports from | |
the object instantiation to the MyHDL module (function that | |
returns MyHDL generators). | |
""" | |
@always_comb | |
def rtl(): | |
self.output = self.inputs[self.sel] | |
return rtl |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Mux( Model ): | |
def __init__( s, nbits = 1, nports = 2 ): | |
s.nports = nports | |
s.nsel = get_sel_nbits( nports ) | |
s.in_ = [ InPort( nbits ) for x in xrange( nports ) ] | |
s.sel = InPort ( s.nsel ) | |
s.out = OutPort ( nbits ) | |
def elaborate_logic( s ): | |
@s.combinational | |
def comb_logic(): | |
assert s.sel < s.nports | |
s.out.v = s.in_[ s.sel ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment