Use a generic to determine (de)mux size in VHDL?

后端 未结 3 893
走了就别回头了
走了就别回头了 2021-01-20 03:39

I want to use a generic \'p\' to define how many outputs a demux will have. Input and all outputs are 1 bit. The outputs, control, and input can be something simple like:<

3条回答
  •  粉色の甜心
    2021-01-20 03:44

    No generics required:

    library ieee;
    use ieee.std_logic_1164.all;
    use ieee.numeric_std.all;
    entity demux is
        port(
            control : in unsigned;
            input   : in std_logic;
            outputs : out std_logic_vector
            );
    end entity demux;
    
    architecture rtl of demux is
        -- Check size of input vectors
        assert 2**control'length = outputs'length 
               report "outputs length must be 2**control length" 
               severity failure;
        -- actually do the demuxing - this will cause feedback latches to be inferred
        outputs(to_integer(unsigned(control)) <= input;
    
    end architecture;
    

    (Untested, just typed in off the top of my head...)

    This will infer latches though - is that what you want?

提交回复
热议问题