Mux - Easy way to instantiate a multiplexor
netOut <= netCmd.Mux ( arg )
This method is a method of net. The net which this method is applied to is the command of the multiplexor. The nets given as parameters are all the input nets. This method returns a net : the output net.
There are two ways to describe the multiplexor : the argument arg
can be a list or a dictionnary.
Note that it is possible to change the generator instanciated with the SetMux
method.
out <= cmd.Mux ( [in0, in1, in2, in3] )The net out is then initialised like this :
if cmd == 0 : out <= in0 if cmd == 1 : out <= in1 if cmd == 2 : out <= in2 if cmd == 3 : out <= in3
out <= cmd.Mux ( {"0" : in0, "1" : in1, "2" : in2, "3" : in3} )This initialisation corresponds to the one before. Thanks to the use of a dictionnary, the connections can be clearer :
'default'
: This key of the dictionnary corresponds to all the nets that are not specified
out <= cmd.Mux ( {"0" : in0, "default" : in1} )This notation corresponds to :
if cmd == 0 : out <= in0 else : out <= in1Note that if there is no
'default'
key specified and that not all the nets are specified, the non specified nets are set to 0.
#
and ?
: When a key of the dictionnary begins with #
, the number after the #
has to be binary and each ? in the number means that this bit is not precised
out <= cmd.Mux ( {"#01?" : in0, "default" : in1} )This notation corresponds to :
if cmd in ( 2, 3 ) : out <= in0 else : out <= in1
,
and -
: When keys contains thoses symbols, it permits to enumerate intervals
out <= cmd.Mux ( {"0,4" : in0, "1-3,5" : in1} )This notation corresponds to :
if cmd in ( 0, 4 ) : out <= in0 elif cmd in ( 1, 2, 3, 5) : out <= in1 else : out <= 0
class essai ( Model ) : def Interface ( self ) : self.A = SignalIn ( "a", 4 ) self.B = SignalIn ( "b", 4 ) self.C = SignalIn ( "c", 4 ) self.D = SignalIn ( "d", 4 ) self.Cmd1 = SignalIn ( "cmd1", 2 ) self.Cmd2 = SignalIn ( "cmd2", 4 ) self.S1 = SignalOut ( "s1", 4 ) self.S2 = SignalOut ( "s2", 4 ) self.Vdd = VddIn ( "vdd" ) self.Vss = VssIn ( "vss" ) def Netlist ( self ) : self.S1 <= self.Cmd1.Mux ( [sefl.A, self.B, self.C, self.D] ) self.S2 <= self.Cmd2.Mux ( { "0" : self.A , "1,5-7" : self.B , "#1?1?" : self.C , "default" : self.D } )
Some errors may occur :
[Stratus ERROR] Mux : all the nets must have the same lenght.
[Stratus ERROR] Mux : there are no input nets.
[Stratus ERROR] Mux : wrong argument type.
[Stratus ERROR] Mux :
the number of nets does not match with the lenght of the command.
[Stratus ERROR] Mux : wrong key.
[Stratus ERROR] Mux :
when an interval is specified, the second number of the interval
must be greater than the first one.
[Stratus ERROR] Mux :
the binary number does not match with the lenght of the command.
#
notation, each digit of the binary number corresponds to a wire of the cmd. The leghts have to correspond.
[Stratus ERROR] Mux : after #, the number has to be binary.
#
notation, the number has to be binary : one can use 0, 1 or ?.
Introduction Netlist Instanciation of a shifter Instanciation of a register Instanciation of constants Boolean operations Arithmetical operations Comparison operations
Sophie BELLOEIL