In reply to dave_59:
In reply to rgarcia07:
Any of the file I/O system routines can use
$ferror get the return code and string message from the last routine executed.
Hi Dave is possible to share a quick snippet showing how to use $ferror along with $readmem*, from the LRM I see it requires a file descriptor but $readmem* system functions/tasks do not seem to return any compared to $fopen, ideally I don’t want to use $fopen + $fclose and then $readmemh just to have a “tool independent” mechanism for ensuring that if the file does not exist an error is raised.
For example:
module test();
integer fd;
integer errno;
string error_msg;
bit [31:0] mem_array[];
string filename = "mem.hex";
initial begin
// fd = $readmemh(filename, mem_array); // Compile error
$readmemh(filename, mem_array); //Tool dependant some give warning others error
// fd = $fopen("mem.hex", "r"); //This works as the file is not existing
errno = $ferror(fd, error_msg); // what to pass as first argument after using $readmem*
$display("ERROR NUM = %0d MSG = %s", errno, error_msg);
end
endmodule
Apologies if my requirement is not clear
-R