Enum type as array range

Discussion in 'VHDL' started by rickman, Jul 14, 2004.

  1. rickman

    rickman Guest

    Maybe I am being a little dense, but I can't find anything on this in my
    VHDL books and the LRM is pretty esoteric in this section.

    I am writing some code to help me simplify simulation data display and I
    want to have some SLV constants in an array. These constants relate to
    defined states of a combination of signals and have names associated
    with them. To get the names to show up in the simulation, I want to use
    an enumerated type which then corresponds to the index of the constant
    array.

    Can I directly use this enumerated type as the index? I am still a day
    or so from having some code to try. Am I barking up the wrong tree with
    this? Should I convert my enum variable to an int and use that as the
    array index?


    subtype ALUSLV is SLV07;
    subtype ALUTyp is (AD, ADC, SU, SUC, CM, CMC, AN, LOR, LXR, SR, SC,
    AER);

    type ALUstyles is array (ALUTyp) of ALUSLV := (
    "00100XX", ...


    --

    Rick "rickman" Collins


    Ignore the reply address. To email me use the above address with the XY
    removed.

    Arius - A Signal Processing Solutions Company
    Specializing in DSP and FPGA design URL http://www.arius.com
    4 King Ave 301-682-7772 Voice
    Frederick, MD 21701-3110 301-682-7666 FAX
     
    rickman, Jul 14, 2004
    #1
    1. Advertising

  2. rickman wrote:

    >
    > I am writing some code to help me simplify simulation data display and I
    > want to have some SLV constants in an array. These constants relate to
    > defined states of a combination of signals and have names associated
    > with them. To get the names to show up in the simulation, I want to use
    > an enumerated type which then corresponds to the index of the constant
    > array.
    > Can I directly use this enumerated type as the index?


    yes

    > I am still a day
    > or so from having some code to try. Am I barking up the wrong tree with
    > this?


    No, it's a good idea.

    > Should I convert my enum variable to an int and use that as the
    > array index?
    > subtype ALUSLV is SLV07;
    > subtype ALUTyp is (AD, ADC, SU, SUC, CM, CMC, AN, LOR, LXR, SR, SC,AER);
    >
    > type ALUstyles is array (ALUTyp) of ALUSLV := (
    > "00100XX", ...


    I see. Maybe like this:
    -------------------------------------------------------------------------------
    library ieee;
    use ieee.std_logic_1164.all;
    entity alu_test is
    end alu_test;
    -------------------------------------------------------------------------------
    architecture sim of alu_test is
    subtype ALUSLV is std_logic_vector(7 downto 0);
    type ALUTyp is (AD, ADC, SU, SUC, CM, CMC, AN, LOR, LXR, SR, SC, AER);
    type ALUstyles is array (ALUTyp'left to ALUTyp'right) of ALUSLV;
    constant init : ALUstyles := (AD => x"42", ADC => x"ff", others => x"00");
    begin
    -- sim processes
    end architecture sim;

    -- Mike Treseler
     
    Mike Treseler, Jul 15, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. -

    enum within an enum

    -, Jun 12, 2005, in forum: Java
    Replies:
    6
    Views:
    580
  2. Eric Sosman
    Replies:
    3
    Views:
    800
    Mayeul
    Feb 26, 2010
  3. Wojtek
    Replies:
    1
    Views:
    517
  4. Lew
    Replies:
    0
    Views:
    552
  5. Roedy Green
    Replies:
    0
    Views:
    752
    Roedy Green
    Feb 27, 2010
Loading...

Share This Page