reading files in vhdl

Discussion in 'VHDL' started by paris, Apr 21, 2004.

  1. paris

    paris Guest

    hi guys,

    im having some trouble with reading from a file, actually the thing is the
    opening part.
    the problem is that i "dont" know the name of the file to read before
    compiling, that is because i've a "configuration" file where i give
    commands, one of them being the name of the "input" file.

    i know i could use a function, but that only works when i've a small amount
    of data to read, cause otherwise, storing a HUGE array slows down the
    simulation, without saying that modelsim tells me that i has not enough
    memory and will start paging to disk and after a while it says that i got
    completely out of memory.

    Simulation works perfect if i read one line (of the input file) at the time,
    but that means that the filename has to be written on the code (at least
    that's how i've been doing, by using ' file fp : TEXT is in "input.dat"; ')

    now i need to open an arbitrary file, so i tried "file_open(fp,
    filenameString, READ_MODE);" the problem is that somehow it doesnt work, as
    it seems that if i open the file in one process (i have to open the file
    just once and read it till the end of the file at every rising_edge(clk), so
    that's two processes). It doesnt work cause it seems that the file is
    "closed" outside the process it was opened (i think i even read about that
    issue).

    Also i cant find "file_open" declaration.

    i also tried with a process like this: (im at home now, so i dont have the
    real sources, but i cant sleep so im writing to ask for help :) please)

    process
    begin

    if (filenameString /= nothing) then
    file_open(fp, filenameString, READ_MODE);

    while (not endfile(fp)) loop
    wait until rising_edge(clk);
    read(fp, data);
    etc, etc
    end loop;
    file_close(fp);
    end if;
    end process;

    that didnt work either, im not sure if it was because of the file_open part
    (i also did a check on the opening, it was succesful) or because the process
    get in an infinite loop, modelsim just stop responding (i think that endfile
    might return false if the file is not open, giving rise to the infinite
    loop, but the loop would at least be "waiting" for "clk" and it would
    actually read the data, but that doesnt happen). The file might get closed
    once "out" the process (like when another process gets executed) or
    something, i have no clue...

    do any of you knows or have faced already this kind of situation? namely,
    reading a file whose name's specified after compilation (by another file)
    line by line (that is, not using a function to read a whole chunk of data
    and storing it in an array)

    any comments will be appreciated, thanks



    Paris
    paris, Apr 21, 2004
    #1
    1. Advertising

  2. paris

    Jim Lewis Guest

    Paris,
    None of your solutions are that far away fronm working.

    > i know i could use a function, but that only works when i've a small amount
    > of data to read, cause otherwise, storing a HUGE array slows down the
    > simulation, without saying that modelsim tells me that i has not enough
    > memory and will start paging to disk and after a while it says that i got
    > completely out of memory.

    You could use a procedure and never exit.
    Pass out one set of data values on every clock.


    > now i need to open an arbitrary file, so i tried "file_open(fp,
    > filenameString, READ_MODE);" the problem is that somehow it doesnt work, as
    > it seems that if i open the file in one process (i have to open the file
    > just once and read it till the end of the file at every rising_edge(clk), so
    > that's two processes). It doesnt work cause it seems that the file is
    > "closed" outside the process it was opened (i think i even read about that
    > issue).

    I am guessing that your file handle declaration is in the process and
    not the architecture. If the file handle declaration were in the
    architecture, I suspect that this would work. With your file handle
    declaration in a process, only the process that declares the file handle
    can see it.


    > Also i cant find "file_open" declaration.

    It is built into the language.

    > i also tried with a process like this: (im at home now, so i dont have the
    > real sources, but i cant sleep so im writing to ask for help :) please)
    >
    > process
    > begin
    >
    > if (filenameString /= nothing) then
    > file_open(fp, filenameString, READ_MODE);
    >
    > while (not endfile(fp)) loop
    > wait until rising_edge(clk);
    > read(fp, data);
    > etc, etc
    > end loop;
    > file_close(fp);


    else
    wait ;

    > end if;
    > end process;

    This can work too, however, when filenameString = nothing,
    then the process goes into an infinite loop.
    If filenameString = nothing means do nothing forever,
    add an else branch with a wait statement in it as shown
    above.


    Cheers,
    Jim

    --
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Jim Lewis
    Director of Training mailto:
    SynthWorks Design Inc. http://www.SynthWorks.com
    1-503-590-4787

    Expert VHDL Training for Hardware Design and Verification
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Jim Lewis, Apr 21, 2004
    #2
    1. Advertising

  3. paris

    jtw Guest

    If you need to open an arbitrary file (like I often want to do), define it
    as a generic, with a default value. When you call the simulator (I've
    worked with Modelsim doing this), provide the generic as part of the call.
    E.g., vsim tb_config -ggeneric1=generic1value ... (other options.)

    Then you can set up a script (or batch file) with whatever value you need
    for the generic-- or just manually type in every time you run it.

    Jason
    "paris" <> wrote in message
    news:c64kuc$ut8$...
    > hi guys,
    >
    > im having some trouble with reading from a file, actually the thing is the
    > opening part.
    > the problem is that i "dont" know the name of the file to read before
    > compiling, that is because i've a "configuration" file where i give
    > commands, one of them being the name of the "input" file.
    >
    > i know i could use a function, but that only works when i've a small

    amount
    > of data to read, cause otherwise, storing a HUGE array slows down the
    > simulation, without saying that modelsim tells me that i has not enough
    > memory and will start paging to disk and after a while it says that i got
    > completely out of memory.
    >
    > Simulation works perfect if i read one line (of the input file) at the

    time,
    > but that means that the filename has to be written on the code (at least
    > that's how i've been doing, by using ' file fp : TEXT is in "input.dat";

    ')
    >
    > now i need to open an arbitrary file, so i tried "file_open(fp,
    > filenameString, READ_MODE);" the problem is that somehow it doesnt work,

    as
    > it seems that if i open the file in one process (i have to open the file
    > just once and read it till the end of the file at every rising_edge(clk),

    so
    > that's two processes). It doesnt work cause it seems that the file is
    > "closed" outside the process it was opened (i think i even read about that
    > issue).
    >
    > Also i cant find "file_open" declaration.
    >
    > i also tried with a process like this: (im at home now, so i dont have the
    > real sources, but i cant sleep so im writing to ask for help :) please)
    >
    > process
    > begin
    >
    > if (filenameString /= nothing) then
    > file_open(fp, filenameString, READ_MODE);
    >
    > while (not endfile(fp)) loop
    > wait until rising_edge(clk);
    > read(fp, data);
    > etc, etc
    > end loop;
    > file_close(fp);
    > end if;
    > end process;
    >
    > that didnt work either, im not sure if it was because of the file_open

    part
    > (i also did a check on the opening, it was succesful) or because the

    process
    > get in an infinite loop, modelsim just stop responding (i think that

    endfile
    > might return false if the file is not open, giving rise to the infinite
    > loop, but the loop would at least be "waiting" for "clk" and it would
    > actually read the data, but that doesnt happen). The file might get closed
    > once "out" the process (like when another process gets executed) or
    > something, i have no clue...
    >
    > do any of you knows or have faced already this kind of situation? namely,
    > reading a file whose name's specified after compilation (by another file)
    > line by line (that is, not using a function to read a whole chunk of data
    > and storing it in an array)
    >
    > any comments will be appreciated, thanks
    >
    >
    >
    > Paris
    >
    >
    >
    >
    jtw, Apr 23, 2004
    #3
  4. Hi,
    I used to do some thing similar, but then I figured out yet another
    easier way (atleast I find so). I refernce to a file named say
    "image_data.txt" inside my TB. Using a script around my simulator, I
    use UNIX links to simulate multiple images, infact you could do some
    thing like:


    ln -s image_0.txt image_data.txt
    run
    # End of 1 sim with image_0
    reset
    rm -f image_data.txt
    ln -s image_1.txt image_data.txt
    run
    # Second simulation with image 1!!

    I did this using NCSIM - FYI.

    HTH,
    Ajeetha,
    http://www.noveldv.com
    Co-Author: Using PSL/SUGAR for Formal and Dynamic Verification 2nd
    Edition.

    "jtw" <wrightjt @hotmail.invalid> wrote in message news:<h21ic.54437$>...
    > If you need to open an arbitrary file (like I often want to do), define it
    > as a generic, with a default value. When you call the simulator (I've
    > worked with Modelsim doing this), provide the generic as part of the call.
    > E.g., vsim tb_config -ggeneric1=generic1value ... (other options.)
    >
    > Then you can set up a script (or batch file) with whatever value you need
    > for the generic-- or just manually type in every time you run it.
    >
    > Jason
    >
    Ajeetha Kumari, Apr 23, 2004
    #4
  5. paris

    Sajan Guest

    ENTITY EX_TOP IS
    generic (
    outfilep_string : string :="results/CDAC_OUT.txt";
    inpfilen_string : string :="data/CDAC_IN.txt"
    );
    PORT(
    AVDD : IN real;
    AVDD_REF : IN real;
    AVSS : IN real;
    AVSS_REF : IN real;
    --input port list
    CDAC_OUTN : OUT real:= 0.0;
    CDAC_OUTP : OUT real:= 0.0
    );
    end;

    The idea is to make the file as generic(here i have a default value
    for the files). Then during instantiation you can change the name of
    the file as per your requirement. By this the idea is to have multiple
    testcases which actually feed different input data and dump out
    different output files.
    I hope this helps

    Best Regards,
    Sajan.



    "paris" <> wrote in message news:<c64kuc$ut8$>...
    > hi guys,
    >
    > im having some trouble with reading from a file, actually the thing is the
    > opening part.
    > the problem is that i "dont" know the name of the file to read before
    > compiling, that is because i've a "configuration" file where i give
    > commands, one of them being the name of the "input" file.
    >
    > i know i could use a function, but that only works when i've a small amount
    > of data to read, cause otherwise, storing a HUGE array slows down the
    > simulation, without saying that modelsim tells me that i has not enough
    > memory and will start paging to disk and after a while it says that i got
    > completely out of memory.
    >
    > Simulation works perfect if i read one line (of the input file) at the time,
    > but that means that the filename has to be written on the code (at least
    > that's how i've been doing, by using ' file fp : TEXT is in "input.dat"; ')
    >
    > now i need to open an arbitrary file, so i tried "file_open(fp,
    > filenameString, READ_MODE);" the problem is that somehow it doesnt work, as
    > it seems that if i open the file in one process (i have to open the file
    > just once and read it till the end of the file at every rising_edge(clk), so
    > that's two processes). It doesnt work cause it seems that the file is
    > "closed" outside the process it was opened (i think i even read about that
    > issue).
    >
    > Also i cant find "file_open" declaration.
    >
    > i also tried with a process like this: (im at home now, so i dont have the
    > real sources, but i cant sleep so im writing to ask for help :) please)
    >
    > process
    > begin
    >
    > if (filenameString /= nothing) then
    > file_open(fp, filenameString, READ_MODE);
    >
    > while (not endfile(fp)) loop
    > wait until rising_edge(clk);
    > read(fp, data);
    > etc, etc
    > end loop;
    > file_close(fp);
    > end if;
    > end process;
    >
    > that didnt work either, im not sure if it was because of the file_open part
    > (i also did a check on the opening, it was succesful) or because the process
    > get in an infinite loop, modelsim just stop responding (i think that endfile
    > might return false if the file is not open, giving rise to the infinite
    > loop, but the loop would at least be "waiting" for "clk" and it would
    > actually read the data, but that doesnt happen). The file might get closed
    > once "out" the process (like when another process gets executed) or
    > something, i have no clue...
    >
    > do any of you knows or have faced already this kind of situation? namely,
    > reading a file whose name's specified after compilation (by another file)
    > line by line (that is, not using a function to read a whole chunk of data
    > and storing it in an array)
    >
    > any comments will be appreciated, thanks
    >
    >
    >
    > Paris
    Sajan, Apr 24, 2004
    #5
    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. rob hadow

    JAR files reading list files

    rob hadow, May 21, 2004, in forum: Java
    Replies:
    4
    Views:
    4,766
    rob hadow
    May 21, 2004
  2. Replies:
    0
    Views:
    771
  3. afd
    Replies:
    1
    Views:
    8,270
    Colin Paul Gloster
    Mar 23, 2007
  4. gfandango
    Replies:
    1
    Views:
    2,340
    gfandango
    Feb 10, 2009
  5. Narendra Sisodiya

    Reading files inside zip files from Javascript

    Narendra Sisodiya, Dec 7, 2009, in forum: Javascript
    Replies:
    7
    Views:
    275
    Michael Haufe (\TNO\)
    Dec 8, 2009
Loading...

Share This Page