FPGA Central - World's 1st FPGA / CPLD Portal

FPGA Central

World's 1st FPGA Portal

 

Go Back   FPGA Groups > NewsGroup > Verilog

Verilog comp.lang.verilog newsgroup / usenet

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-28-2003, 12:53 AM
Peng Yu
Guest
 
Posts: n/a
Default What's the format of multidimensional data file for $readmemh?

Hi,
Do somebody know what's the format of multidimensional data file for $readmemh?
For example, I have a memory
reg [1:0] mem [0:2][0:3];
How to write the file for the initialization of the memory.
$readmemh("mem.data", mem);
Best wishes,
Peng
Reply With Quote
  #2 (permalink)  
Old 07-28-2003, 08:57 PM
Steven Sharp
Guest
 
Posts: n/a
Default Re: What's the format of multidimensional data file for $readmemh?

[email protected] (Peng Yu) wrote in message news:<[email protected] com>...

> Do somebody know what's the format of multidimensional data file for $readmemh?
> For example, I have a memory
> reg [1:0] mem [0:2][0:3];
> How to write the file for the initialization of the memory.
> $readmemh("mem.data", mem);


There is no such format. $readmem was defined to read memories,
which are 1-dimensional arrays. It is not defined to read the
multi-dimensional arrays that were added in Verilog-2001. If
you want to use $readmem, then you will have to flatten your
array into a 1-dimensional array.

If you want to use multi-dimensional arrays, then you cannot
use $readmem to read values into them. However, Verilog-2001
also added general file reading capabilities to the language.
This allows you to write your own Verilog code to read data
files into your multi-dimensional arrays. For example, you
could write

integer i,j,fd,rv;

initial
begin
fd = $fopen( "mem.data", "r");
for (i = 0; i < 4; i = i + 1)
for (j = 0; j < 3; j = j + 1)
rv = $fscanf(fd, "%h", mem[j][i]);
end

Your code determines what order the elements will be read
and what format the input data must be in. If you wanted
to add more complex capabilities like embedding addresses
in the file, you could do so, but you would have to write
the Verilog code to parse and interpret the contents of
the file for yourself.

If your simulator supports Verilog-2001 multi-dimensional
arrays but does not support Verilog-2001 file I/O routines,
then you have a problem. I suppose you could write VPI to
do the job, assuming that your simulator supports VPI and
VPI access to multi-dimensional arrays.
Reply With Quote
  #3 (permalink)  
Old 07-30-2003, 07:07 AM
Peng Yu
Guest
 
Posts: n/a
Default Re: What's the format of multidimensional data file for $readmemh?

> integer i,j,fd,rv;
>
> initial
> begin
> fd = $fopen( "mem.data", "r");
> for (i = 0; i < 4; i = i + 1)
> for (j = 0; j < 3; j = j + 1)
> rv = $fscanf(fd, "%h", mem[j][i]);/* #1 rv = $fscanf(fd, "%h", mem[j][i]);*/
> end

Do I need to add some delay to the line with comment? Otherwise, it doesn't work.
Peng
Reply With Quote
  #4 (permalink)  
Old 07-30-2003, 11:13 PM
Steven Sharp
Guest
 
Posts: n/a
Default Re: What's the format of multidimensional data file for $readmemh?

[email protected] (Peng Yu) wrote in message news:<[email protected] om>...
> >
> > rv = $fscanf(fd, "%h", mem[j][i]);/* #1 rv = $fscanf(fd, "%h", mem[j][i]);*/
> > end

> Do I need to add some delay to the line with comment? Otherwise, it doesn't work.


There is no reason to add a delay to the line. Presumably you want the
entire memory initialized at once at the start of the simulation, not
one location at a time. For a large memory, the later locations in the
memory wouldn't get initialized until a long time into the simulation
if you added a delay between initializing each location.

If it isn't working without a delay, then your simulator is broken.
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 10:16 PM.


Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
Copyright 2008 @ FPGA Central. All rights reserved