Google 그룹스는 더 이상 새로운 유즈넷 게시물 또는 구독을 지원하지 않습니다. 과거의 콘텐츠는 계속 볼 수 있습니다.

$fread - Invalid second parameter

조회수 428회
읽지 않은 첫 메시지로 건너뛰기

Dave Gowans

읽지 않음,
2005. 10. 16. 오후 3:44:1505. 10. 16.
받는사람
Hi

I've been trying to read a binary file into memory using the $fread system
task but on both ModelSim and Veritak simulators I get an error telling me
the second parameter/argument is wrong. I can't find any documentation that
specifies exactly how $fread should be used, though, and experimentation has
got me nowhere!

I'm currently using the follwoing code:
`define EOF 32'HFFFF_FFFF
`define MEM_SIZE 200_000

module load_mem;

integer file, i;
reg [7:0] mem[0:`MEM_SIZE];
reg [80*8:1] file_name;

initial
begin
file_name = "data.bin";
file = $fopen(file_name);
i = $fread(file, mem[0]);
$display("Loaded %0d entries \n", i);
// i = $fclose(file);
$stop;
end

endmodule // load_mem


and Veritak gives me the error:
VPI ERROR $fread: invalid second parameter (must be variable).
Loaded 0 entries

I'd appreciate any help anyone could give (or any working $fread code I
could take a look at).

Cheers

Dave


Ajeetha

읽지 않음,
2005. 10. 17. 오전 1:49:3505. 10. 17.
받는사람
Dave,
From V2K LRM, $fread works as follows:

$fread(mem_or_reg, file_descriptor);

With respect to your Veritak error, perhaps they don't support mem as
argument, try reading it to a reg and assign it to mem.

HTH
Ajeetha
--
www.noveldv.com
Interested in expert PSL/SVA training in Bangalore?
Visit www.noveldv.com/cvc.html

A simple working code (in VCS) is:

module load_mem;
integer file, i;
reg [7:0] mem[0:`MEM_SIZE];
reg [80*8:1] file_name;

initial
begin
file_name = "data.bin";

file = $fopen(file_name, "r");
i = $fread(mem, file);

sh...@cadence.com

읽지 않음,
2005. 10. 17. 오후 1:30:4105. 10. 17.
받는사람
As Ajeetha says, the file_descriptor is the second argument, not the
first. The first argument is the memory or reg to be read into. There
are also optional additional arguments to be used with memories,
providing a starting address in the memory and a count of memory words
to be read.

Another issue is that the $fopen must include a second argument "r" to
open the file in read mode. Without it, the file will be opened in
write mode, and instead of a file descriptor you will get an old-style
multi-channel-descriptor, which cannot be used with the newer file I/O
routines.

tak.s

읽지 않음,
2005. 10. 18. 오전 10:27:3305. 10. 18.
받는사람
Dave-san,

Veritak can handle Ajeetha-san's bench with one exception below.


file = $fopen(file_name, "r");

It is important to use "rb"/"wb" instead of "r"/"w" in
reading/writing BINARY format in Windows.

See example below.
http://www.sugawara-systems.com/verilog-2001/fileio.htm

Veritak project file can be found in your installed folder of
"regression_test/fileio" for that sample.

Tak

새 메시지 0개