1 ------------------------------------------------------------------------------- 3 --! @author Hipolito Guzman-Miranda 4 --! @brief Writes circuit output to file 5 ------------------------------------------------------------------------------- 7 --! Use IEEE standard definitions library 9 --! Use std_logic* signal types 10 use ieee.std_logic_1164.
all;
11 --! Allows use of arithmetical operations between integers and vectors 13 -- Allows writing strings to lines and lines to files 15 -- Allows converting std_logic_vector(s) to strings (BIN, HEX, OCT) 16 --use work.image_pkg.all; 17 -- Allows writing std_logic_vector(s) to line(s) in BIN, HEX, OCT and reading BIN, HEX, OCT vector(s) from line(s) 18 use ieee.std_logic_textio.
all;
19 -- For print() function 22 --! @brief Writes circuit output data to file 24 --! @detailed Creates (overwriting if it exists) a file at \c OUTPUT_FILE, 25 --! writing \c OUTPUT_NIBBLES chars in each line. Data will be written in hex 26 --! format: 4 bits per character (nibble). Reads \c DATA_WIDTH - bit input \c data 27 --! and internally reorders it to form complete lines. \c data is only sampled 28 --! when \c valid is active. 31 SIMULATION_LABEL : := "datawrite";
--! Allow to separate messages from different instances in SIMULATION 32 VERBOSE : := false;
--! Print more internal details 33 DEBUG : := false;
--! Print debug info (developers only) 34 OUTPUT_FILE : := "./output/datawrite_test.txt";
--! File where data will be stored 39 clk : in ;
--! Will sample input on rising_edge of this clock 41 valid : in ;
--! Active high, indicates data is valid 42 endsim : in --! Active high, tells the process to close its open files 46 --! @brief Architecture accumulates input data in a vector which will be written to the output file 51 signal received_data : := 0;
56 report "datawrite(" & SIMULATION_LABEL & "): OUTPUT_NIBBLES must be a positive non-zero integer" 60 report "datawrite(" & SIMULATION_LABEL & "): DATA_WIDTH must be a positive non-zero integer" 71 --! @brief Accumulates data to form a line, when line is complete it gets written to the output file 73 --! @detailed Also reports errors and checks for unexpected conditions 74 datawrite_read :
process 76 file file_pointer : text;
77 variable current_line : line;
78 variable expected_data : (OUTPUT_NIBBLES*4-1 downto 0);
-- Data read from file 79 variable current_data : (OUTPUT_NIBBLES*4-1 downto 0);
-- Data read from input 80 variable chunk_idx : range 0 to NUM_CHUNKS := 0;
-- Points to current data chunk in line 81 variable error_count : := 0;
-- Store differences between received and expected data 82 variable correct_count : := 0;
-- Store number of correct data 88 file_open(file_pointer, OUTPUT_FILE, WRITE_MODE);
95 wait until (rising_edge(clk) or endsim = '1');
99 chunk_idx := chunk_idx + 1;
100 received_data <= received_data + 1;
104 if (chunk_idx /= NUM_CHUNKS and chunk_idx /= 0) then 105 print ("datawrite(" & SIMULATION_LABEL & "): warning: endsim received whilst line not completed. (chunk_idx = " & 'image(chunk_idx) & "). Some data may be lost" );
108 -- Avoid writing twice the last line 111 hwrite(current_line, current_data);
112 writeline(file_pointer, current_line);
115 current_data := (others => 'U');
123 file_close(file_pointer);
127 end process datawrite_read;
129 end pack_lines_and_write;
in datastd_logic_vector( DATA_WIDTH- 1 downto 0)
Data to write to file.
DATA_WIDTHinteger := 8
Width of input data.
SIMULATION_LABELstring := "datawrite"
Allow to separate messages from different instances in SIMULATION.
OUTPUT_FILEstring := "./output/datawrite_test.txt"
File where data will be stored.
Writes circuit output data to file.
in validstd_logic
Active high, indicates data is valid.
VERBOSEboolean := false
Print more internal details.
in endsimstd_logic
Active high, tells the process to close its open files.
integer := 4* OUTPUT_NIBBLES/ DATA_WIDTH NUM_CHUNKS
Each line in output file equals to NUM_CHUNKS data of DATA_WIDTH.
OUTPUT_NIBBLESinteger := 2
Hex chars on each output line.
in clkstd_logic
Will sample input on rising_edge of this clock.
Allows for text output in simulation.
DEBUGboolean := false
Print debug info (developers only)
_library_ ieeeieee
Use IEEE standard definitions library.