select file soorce/destination at simulation start

N

Niv (KP)

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.
 
T

Tricky

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.
 
J

jtw

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top