Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
10 years ago

Defining an array of bytes with a dynamically allocated size

Hello,

Can anyone tell me how to define an output to an entity, which is an array of bytes and has a size specified by a generic parameter. I have written a code snippet below which doesn't work but demonstrates what I want to do, and another code snippet which does work but is not generic and cannot be altered dynamically.

What I want, but does not work

    library ieee;
        use IEEE.numeric_std.all ;
    entity My_entity is
        generic (No_of_Bytes : integer := 5);
        port (Entity_output : out array(No_of_Bytes-1 downto 0) of unsigned(7 downto 0) );
    end entity;

Works but is not generic

    library ieee;
        use IEEE.numeric_std.all ;
    package Array_Type_Definition is
        constant No_of_Bytes : integer := 5 ;
        type TArray is array(No_of_Bytes-1 downto 0) of unsigned(7 downto 0) ;
    end package Array_Type_Definition ;
    library ieee;
        use IEEE.numeric_std.all ;
        use work.Array_Type_Definition.All ;
    entity My_entity is
        port (Entity_output : out TArray);
    end entity;

2 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    arrays can be defined in a package without a length (as long as the "internal" arrays are all length defined pre VHDL2008)

    type TArray is array(integer range <>) of unsigned(7 downto 0) ;

    and then in the entitiy

    
    entity My_entity is
            generic (No_of_Bytes : integer := 5);
            port (Entity_output : out TArray(No_of_Bytes-1 downto 0);
        end entity;