Modelsim reading riting and rithmetic

B

Brad Smallridge

Guest
The code below is cut from a testbench I wrote that reads the header of a
BMP file, and writes another BMP file as output. I have tried to shorten
this code by putting the file reading, file writing, multiply and add in a
separate function, however I get an error saying that the read / write are
not somehow doable in a "pure" function. Obviously something is not going
on the way I expect a VHDL function to run like a string of operations like
in C.
Can somebody show me a readable and concise way of doing this?

Thanks,
Brad Smallridge

-- the next 4 bytes are the file size
read (my_file, my_char_v);
write(my_file2,my_char_v);
file_size := character'pos(my_char_v);

read (my_file, my_char_v);
write(my_file2,my_char_v);
file_size := file_size+ 256*(character'pos(my_char_v));

read (my_file, my_char_v);
write(my_file2,my_char_v);
file_size := file_size+ 256*256*(character'pos(my_char_v));

read (my_file, my_char_v);
write(my_file2,my_char_v);
file_size := file_size+ 256*256*256*(character'pos(my_char_v));

ETC. ETC. ETC. Very verbose.
 
I am no expert, but it seems that a PURE subroutine is one that does not
explicitly access signals and such. Are you using signals or files
without passing them into the function? Or can you just declare the
function as IMPURE?

How about an example of the function?


Brad Smallridge wrote:
The code below is cut from a testbench I wrote that reads the header of a
BMP file, and writes another BMP file as output. I have tried to shorten
this code by putting the file reading, file writing, multiply and add in a
separate function, however I get an error saying that the read / write are
not somehow doable in a "pure" function. Obviously something is not going
on the way I expect a VHDL function to run like a string of operations like
in C.
Can somebody show me a readable and concise way of doing this?

Thanks,
Brad Smallridge

-- the next 4 bytes are the file size
read (my_file, my_char_v);
write(my_file2,my_char_v);
file_size := character'pos(my_char_v);

read (my_file, my_char_v);
write(my_file2,my_char_v);
file_size := file_size+ 256*(character'pos(my_char_v));

read (my_file, my_char_v);
write(my_file2,my_char_v);
file_size := file_size+ 256*256*(character'pos(my_char_v));

read (my_file, my_char_v);
write(my_file2,my_char_v);
file_size := file_size+ 256*256*256*(character'pos(my_char_v));

ETC. ETC. ETC. Very verbose.
--

Rick "rickman" Collins

rick.collins@XYarius.com
Ignore the reply address. To email me use the above address with the XY
removed.

Arius - A Signal Processing Solutions Company
Specializing in DSP and FPGA design URL http://www.arius.com
4 King Ave 301-682-7772 Voice
Frederick, MD 21701-3110 301-682-7666 FAX
 
I suspect that Modelsim complained because the files are opened and closed
in the main body of the testbench and not in the function. So the function
doesn't know about the files. I did not know that I could declare a
function as IMPURE. I would show you the function but it has been awhile, I
had it working the verbose way, and I can't find it now. I am not sure if
a function is the way to go.

"rickman" <spamgoeshere4@yahoo.com> wrote in message
news:41C0FFE3.B36C839C@yahoo.com...
I am no expert, but it seems that a PURE subroutine is one that does not
explicitly access signals and such. Are you using signals or files
without passing them into the function? Or can you just declare the
function as IMPURE?

How about an example of the function?


Brad Smallridge wrote:
 
Brad Smallridge wrote:
The code below is cut from a testbench I wrote that reads the header of a
BMP file, and writes another BMP file as output. I have tried to shorten
this code by putting the file reading, file writing, multiply and add in a
separate function, however I get an error saying that the read / write are
not somehow doable in a "pure" function.
A plain function cannot read or write files.
Consider a procedure or impure function.

-- Mike Treseler
 

Welcome to EDABoard.com

Sponsor

Back
Top