select file soorce/destination at simulation start

Discussion in 'VHDL' started by Niv (KP), Nov 7, 2008.

  1. Niv (KP)

    Niv (KP) Guest

    Hi, I currently set a generic to select between two groups of files,
    as below:

    ARCHITECTURE behave OF mystuff IS
    -----------------------------------------------------------------------------------------------------
    FUNCTION assign_rd_file(select : BOOLEAN) RETURN STRING IS
    BEGIN
    IF select THEN
    RETURN "../file1.txt";
    ELSE
    RETURN "../file2.txt";
    END IF;
    END assign_rd_file;
    ----------------------------------------------------------------------------------------------------------

    BEGIN -- The Architecture

    main : PROCESS
    FILE f_rd : TEXT OPEN read_mode IS
    assign_rd_file(select ) ;
    BEGIN

    -- do stuff with read file here

    END PROCESS main;

    END ARCHITECTURE behave;

    All well and good, but I would prefer to make the selection after i've
    invoked ModelSim, rather than compile with different generic each time
    I want different file choice.

    I can use something like:

    -----------------------------------------------------------------------------------------------
    simulation_type_proc : PROCESS

    VARIABLE line_out : LINE;
    VARIABLE line_in : LINE;
    VARIABLE key_press : CHARACTER;
    CONSTANT question : STRING := "Enter 'y' for file set 1, anything
    else for file set 2";

    BEGIN
    write(line_out, question); -- ask the question
    writeline(output, line_out);
    readline(input, line_in); -- get the answer
    read(line_in, key_press);
    IF key_press = 'y' THEN
    select <= TRUE;
    ELSE
    select <= FALSE;
    END IF;
    WAIT;
    END PROCESS simulation_type_proc;
    -------------------------------------------------------------------------------------

    which will set a "select" variable, but this obviously wont overwrite
    the generic.

    Any ideas please?

    TIA, Niv.
    Niv (KP), Nov 7, 2008
    #1
    1. Advertising

  2. Niv (KP)

    Tricky Guest

    On 7 Nov, 07:59, "Niv (KP)" <> wrote:
    > Hi,  I currently set a generic to select between two groups of files,
    > as below:
    >
    > ARCHITECTURE behave OF mystuff IS
    > -----------------------------------------------------------------------------------------------------
    > FUNCTION assign_rd_file(select : BOOLEAN) RETURN STRING IS
    >   BEGIN
    >     IF select THEN
    >       RETURN "../file1.txt";
    >     ELSE
    >       RETURN "../file2.txt";
    >     END IF;
    > END assign_rd_file;
    > ----------------------------------------------------------------------------------------------------------
    >
    > BEGIN -- The Architecture
    >
    > main : PROCESS
    >   FILE f_rd           : TEXT OPEN read_mode  IS
    > assign_rd_file(select ) ;
    > BEGIN
    >
    > -- do stuff with read file here
    >
    > END PROCESS main;
    >
    > END ARCHITECTURE behave;
    >
    > All well and good, but I would prefer to make the selection after i've
    > invoked ModelSim, rather than compile with different generic each time
    > I want different file choice.
    >
    > I can use something like:
    >
    > -----------------------------------------------------------------------------------------------
    > simulation_type_proc : PROCESS
    >
    >         VARIABLE line_out : LINE;
    >         VARIABLE line_in : LINE;
    >         VARIABLE key_press : CHARACTER;
    >         CONSTANT question : STRING := "Enter 'y' for file set 1, anything
    > else for file set 2";
    >
    >         BEGIN
    >         write(line_out, question);      -- ask the question
    >         writeline(output, line_out);
    >         readline(input, line_in);       -- get the answer
    >         read(line_in, key_press);
    >         IF key_press = 'y' THEN
    >                 select <= TRUE;
    >         ELSE
    >                 select  <= FALSE;
    >         END IF;
    >         WAIT;
    > END PROCESS simulation_type_proc;
    > -------------------------------------------------------------------------------------
    >
    > which will set a "select" variable, but this obviously wont overwrite
    > the generic.
    >
    > Any ideas please?
    >
    > TIA, Niv.



    If you're running from the modelsim GUI, you dont need to re-run vsim
    every time you recompile. just use the "restart" command and it re-
    initialises any recompiled files (picking up your new file choice).
    THis is the method I use - A whole bunch of generics on the testbench
    set for that given simulation.

    As for you're second method - you will need to go about the file
    selection differently. Scrap the generic, as you can use that for the
    method above. What you'll have is:

    architecture sim of my_ent is
    begin

    process
    variable select : boolean;
    file myfile : text;


    VARIABLE line_out : LINE;
    VARIABLE line_in : LINE;
    VARIABLE key_press : CHARACTER;
    CONSTANT question : STRING := "Enter 'y' for file set 1, anything
    else for file set 2";
    begin

    write(line_out, question); -- ask the question
    writeline(output, line_out);
    readline(input, line_in); -- get the answer
    read(line_in, key_press);
    IF key_press = 'y' THEN
    select := TRUE;
    ELSE
    select := FALSE;
    END IF;

    FILE_OPEN( f => myfile,
    external_name => assign_rd_file(select),
    open_kind => READ_MODE);

    ..
    --Do whatever you want with the file
    ..


    FILE_CLOSE(myfile); --Important, otherwise you may lock the file as
    opened in the OS (sim should clear up after itself, but best be
    careful)
    wait;
    end process;


    but you have to restart the simulation to get a different file choice
    every time anyway, so I dont see how this method would be any better.
    Tricky, Nov 7, 2008
    #2
    1. Advertising

  3. Niv (KP)

    jtw Guest

    Use the form: vsim -g[generic name]=[generic value]

    Of course, use all other necessary parameters.

    You can only change the value of the generics at the start of a
    simulation--not to be confused with when you start the simulator (Modelsim.)

    JTW


    "Niv (KP)" <> wrote in message
    news:...
    > Hi, I currently set a generic to select between two groups of files,
    > as below:
    >
    > ARCHITECTURE behave OF mystuff IS
    > -----------------------------------------------------------------------------------------------------
    > FUNCTION assign_rd_file(select : BOOLEAN) RETURN STRING IS
    > BEGIN
    > IF select THEN
    > RETURN "../file1.txt";
    > ELSE
    > RETURN "../file2.txt";
    > END IF;
    > END assign_rd_file;
    > ----------------------------------------------------------------------------------------------------------
    >
    > BEGIN -- The Architecture
    >
    > main : PROCESS
    > FILE f_rd : TEXT OPEN read_mode IS
    > assign_rd_file(select ) ;
    > BEGIN
    >
    > -- do stuff with read file here
    >
    > END PROCESS main;
    >
    > END ARCHITECTURE behave;
    >
    > All well and good, but I would prefer to make the selection after i've
    > invoked ModelSim, rather than compile with different generic each time
    > I want different file choice.
    >
    > I can use something like:
    >
    > -----------------------------------------------------------------------------------------------
    > simulation_type_proc : PROCESS
    >
    > VARIABLE line_out : LINE;
    > VARIABLE line_in : LINE;
    > VARIABLE key_press : CHARACTER;
    > CONSTANT question : STRING := "Enter 'y' for file set 1, anything
    > else for file set 2";
    >
    > BEGIN
    > write(line_out, question); -- ask the question
    > writeline(output, line_out);
    > readline(input, line_in); -- get the answer
    > read(line_in, key_press);
    > IF key_press = 'y' THEN
    > select <= TRUE;
    > ELSE
    > select <= FALSE;
    > END IF;
    > WAIT;
    > END PROCESS simulation_type_proc;
    > -------------------------------------------------------------------------------------
    >
    > which will set a "select" variable, but this obviously wont overwrite
    > the generic.
    >
    > Any ideas please?
    >
    > TIA, Niv.
    jtw, Nov 13, 2008
    #3
    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. John
    Replies:
    1
    Views:
    369
    Joerg Jooss
    Jun 26, 2005
  2. Replies:
    3
    Views:
    328
    Vinay Sajip
    Apr 23, 2008
  3. jasperng
    Replies:
    0
    Views:
    1,293
    jasperng
    Nov 27, 2008
  4. John
    Replies:
    1
    Views:
    97
    Patrice
    May 3, 2006
  5. palmiere
    Replies:
    1
    Views:
    384
    Erwin Moller
    Feb 9, 2004
Loading...

Share This Page