dpaul
Advanced Member level 5
In my test-bench I repeteadly call a procedure (while loop used). In this procedure a file is opened (if not already open) else it is opened in append mode. The logic in the procedure writes data to this file. For 1 complete simulation run, I gather all data, this works fine, I have no problems.
The problem occurs when I re-launch the simulation. In this case too data gets appended to the file after the old data. Note that I don't close this file anywhere.
But my wish is to remove all previous logged data from the file and write fresh data from the start of the file, whenever a new simulation is launched. How to achieve this?
Till now I am following the manual way of 'close simulation'(else Vivado keeps the file locked) and deleting the file from the dir, then running a fresh simulation.
The problem occurs when I re-launch the simulation. In this case too data gets appended to the file after the old data. Note that I don't close this file anywhere.
But my wish is to remove all previous logged data from the file and write fresh data from the start of the file, whenever a new simulation is launched. How to achieve this?
Till now I am following the manual way of 'close simulation'(else Vivado keeps the file locked) and deleting the file from the dir, then running a fresh simulation.
Code:
rx_tx : process
-- other procedures
procedure data_rx_ddf is
-- Write to file variables
variable outline : line ; -- line number declaration
file outfile : text ; -- Declare write file variable, file pointer
variable fstatus : FILE_OPEN_STATUS;
begin
report "Got status from file: '" & FILE_OPEN_STATUS'image(fstatus) & "'"; -- Always reports with 'open_ok'
-- Open/Append file for writing
if fstatus /= OPEN_OK then -- Seems like file is always open if it is not closed(?)
file_open(fstatus, outfile, "C:\Work\fpga_a7\sources\sim\dump_data_results.txt", write_mode);
else
file_open(fstatus, outfile, "C:\Work\fpga_a7\sources\sim\dump_data_results.txt", append_mode);
end if;
.
.
-- Remaining part where write-to-file operations are done based on some logic
-- file_close() is never called
end data_rx_ddf;
begin
procedure0;
wait for 10 ns;
procedure1;
if error = '0' then -- signal
procedure3;
wait for 10 ns;
start <= '1'; -- signal
wait for 1 us;
-- Check data repeteadly
while (start='1') loop
data_rx_ddf; -- procedure of interest
-- Reset signals
lf_byte_cnt <= (others => '0');
lf_total_byte_cnt <= (others =>'0');
lf_num <= (others => '0');
jf_rx_mtu <= (others => '0');
end loop;
wait;
else
wait; -- Do nothing in case of errors
end if;
end process rx_tx;