|
From: Martin W. <ic...@ma...> - 2018-01-08 23:03:06
|
Hello Brian,
The reason is that the Icarus implementation of $fgets is using fgets() to
read from the file, but is then using strlen() to determine the number of
characters read. It therefore discards characters when it encounters a null
character. So your first word is OK because it contains no null characters,
your second word stops after the third character, your third and fourth
words are OK, your fifth word stops after the first character, and so on.
The characters are stored in rdata starting at the LSB, and unused bytes
are padded with zeros.
This behaviour seems wrong - it certainly isn't what the 'C' fgets() does -
but I'd want to check what other Verilog simulators do before making any
changes.
To work round this, try using $fgetc.
Martin
Brian Kaczynski wrote:
> Hello,
>
> I am having weird problems reading the header of a .wav file in 32-bit
> words. The following code should read the whole header 32 bits at a time
> and store then in the 32-bit by 11-entry memory wavheader:
>
> integer ofile, i, r;
> reg [31:0] wavheader [10:0];
> reg [31:0] ifile, rdata;
> ifile = $fopen("input.wav","rb");
> for( i = 0; i < 11; i = i + 1 ) begin
> #10 r = $fgets(rdata, ifile);
> wavheader[i] = rdata;
> end
>
> Here are the first 32 bytes of the .wav file:
> 52 49 46 46 FC B6 3C 00 57 41 56 45 66 6D 74 20 10 00 00 00 01 00 01 00 80
> BB 00 00 80 32 02 00
>
> And here is a screen shot from gtkwave of what rdata[31:0] is assigned on
> each iteration:
> [image: Inline image 1]
>
> The first 32-bit word is correct, but the second one is getting messed up
> somehow (FCB63C00 is turning into 00FCB63C).
> The next two words are correct and then the fifth word is being read as
> little-endian (which is actually correct but I'm not sure how iverilog
> knows to do this)!
> The sixth word is a complete mystery to me -- it's 01000100 in the file and
> iverilog turns it into 00000001 -- again maybe reading it as little-endian
> but why is it dropping the "01" in the second little-endian byte?
> These errors continue...
>
> Can anyone explain why and even better, give some tips on how to read this
> .wav file correctly?
>
> Many thanks in advance!
>
>
>
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
>
>
>
> _______________________________________________
> Iverilog-devel mailing list
> Ive...@li...
> https://lists.sourceforge.net/lists/listinfo/iverilog-devel
>
|