Subsections

- Name
- Synopsys
- Description
- Parameters
- Example
- Errors
- See Also

##
Multiplexor

### Name

Mux - Easy way to instantiate a multiplexor

### Synopsys

    netOut <= netCmd.Mux ( arg )

### Description

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.

### Parameters

- List :
  For each value of the command, the corresponding net is specified. All values must be specified.
  For example :

      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

- Dictionnary :
  A dictionnary makes the correspondance between a value of the command and the corresponding net.
  For example :

      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
    For example :

        out <= cmd.Mux ( {"0" : in0, "default" : in1} )

    This notation corresponds to :

        if cmd == 0 : out <= in0
        else        : out <= in1

    Note 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
    For example :

        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
    For example :

        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

### Example

    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
                                 } )

### Errors

Some errors may occur :

- `[Stratus ERROR] Mux : all the nets must have the same lenght.`
  All the input nets pust have the same lenght.
- `[Stratus ERROR] Mux : there are no input nets.`
  The input nets seem to have been forgotten.
- `[Stratus ERROR] Mux : wrong argument type.`
  The connections of the buses are not described by a list nor a dictionnary.
- `[Stratus ERROR] Mux :`
  `the number of nets does not match with the lenght of the command.`
  When using a list, the number of nets has to correspond to the number of possible values of the command.
- `[Stratus ERROR] Mux : wrong key.`
  One of the key of the dictionnary is not un number, neither a list or an interval.
- `[Stratus ERROR] Mux :`
  `when an interval is specified, the second number of the interval`
  `must be greater than the first one.`
  When creating an interval with "-", the second number has to be greater than the first one.
- `[Stratus ERROR] Mux :`
  `the binary number does not match with the lenght of the command.`
  When using the `#` 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.`
  When using the `#` notation, the number has to be binary : one can use 0, 1 or ?.

### See Also

Introduction Netlist Instanciation of a shifter Instanciation of a register Instanciation of constants Boolean operations Arithmetical operations Comparison operations