| 1 |
library ieee ; |
| 2 |
use ieee.std_logic_1164.all ; |
| 3 |
|
| 4 |
library std; |
| 5 |
use std.textio.all; |
| 6 |
|
| 7 |
|
| 8 |
-- Utility package |
| 9 |
package util is |
| 10 |
|
| 11 |
procedure nop( signal clock : in std_logic ; count : in natural ) ; |
| 12 |
|
| 13 |
end package ; |
| 14 |
|
| 15 |
package body util is |
| 16 |
|
| 17 |
procedure nop( signal clock : in std_logic ; count : in natural ) is |
| 18 |
begin |
| 19 |
for i in 1 to count loop |
| 20 |
wait until rising_edge( clock ) ; |
| 21 |
end loop ; |
| 22 |
end procedure ; |
| 23 |
|
| 24 |
end package body ; |
| 25 |
|
| 26 |
library ieee ; |
| 27 |
use ieee.std_logic_1164.all ; |
| 28 |
use ieee.numeric_std.all; |
| 29 |
library std; |
| 30 |
use std.textio.all; |
| 31 |
|
| 32 |
|
| 33 |
entity data_saver is |
| 34 |
generic( |
| 35 |
FILENAME : string := "file.dat"; |
| 36 |
DATA_WIDTH : natural := 16 |
| 37 |
); |
| 38 |
port( |
| 39 |
reset : in std_logic; |
| 40 |
clock : in std_logic; |
| 41 |
data : std_logic_vector(DATA_WIDTH-1 downto 0); |
| 42 |
data_valid : std_logic |
| 43 |
); |
| 44 |
end entity; |
| 45 |
|
| 46 |
|
| 47 |
architecture arch of data_saver is |
| 48 |
begin |
| 49 |
|
| 50 |
handler : process |
| 51 |
FILE fp : text; |
| 52 |
variable line_data : line; |
| 53 |
begin |
| 54 |
-- |
| 55 |
wait until falling_edge(reset); |
| 56 |
|
| 57 |
file_open(fp, FILENAME, WRITE_MODE); |
| 58 |
|
| 59 |
while (reset = '0') loop |
| 60 |
wait until rising_edge(data_valid); |
| 61 |
write(line_data, data); |
| 62 |
writeline(fp,line_data); |
| 63 |
end loop; |
| 64 |
file_close(fp); |
| 65 |
end process; |
| 66 |
end architecture; |
| 67 |
|
| 68 |
|
| 69 |
library ieee ; |
| 70 |
use ieee.std_logic_1164.all ; |
| 71 |
use ieee.numeric_std.all; |
| 72 |
library std; |
| 73 |
use std.textio.all; |
| 74 |
|
| 75 |
|
| 76 |
entity signed_saver is |
| 77 |
generic( |
| 78 |
FILENAME : string := "file.dat"; |
| 79 |
DATA_WIDTH : natural := 16 |
| 80 |
); |
| 81 |
port( |
| 82 |
reset : in std_logic; |
| 83 |
clock : in std_logic; |
| 84 |
data : signed(DATA_WIDTH-1 downto 0); |
| 85 |
data_valid : std_logic |
| 86 |
); |
| 87 |
end entity; |
| 88 |
|
| 89 |
|
| 90 |
architecture arch of signed_saver is |
| 91 |
begin |
| 92 |
|
| 93 |
handler : process |
| 94 |
FILE fp : text; |
| 95 |
variable line_data : line; |
| 96 |
begin |
| 97 |
-- |
| 98 |
wait until falling_edge(reset); |
| 99 |
|
| 100 |
file_open(fp, FILENAME, WRITE_MODE); |
| 101 |
|
| 102 |
while (reset = '0') loop |
| 103 |
wait until rising_edge(clock); |
| 104 |
|
| 105 |
if data_valid = '1' then |
| 106 |
write(line_data, (to_integer(data))); |
| 107 |
writeline(fp,line_data); |
| 108 |
end if; |
| 109 |
end loop; |
| 110 |
file_close(fp); |
| 111 |
end process; |
| 112 |
end architecture; |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
library ieee ; |
| 117 |
use ieee.std_logic_1164.all ; |
| 118 |
use ieee.numeric_std.all; |
| 119 |
library std; |
| 120 |
use std.textio.all; |
| 121 |
|
| 122 |
|
| 123 |
entity data_reader is |
| 124 |
generic( |
| 125 |
FILENAME : string := "file.dat"; |
| 126 |
DATA_WIDTH : natural := 16 |
| 127 |
); |
| 128 |
port( |
| 129 |
reset : in std_logic; |
| 130 |
clock : in std_logic; |
| 131 |
data_request : in std_logic; |
| 132 |
data : out std_logic_vector(DATA_WIDTH-1 downto 0); |
| 133 |
data_valid : out std_logic |
| 134 |
); |
| 135 |
end entity; |
| 136 |
|
| 137 |
|
| 138 |
architecture arch of data_reader is |
| 139 |
|
| 140 |
type character_array_t is array (natural range <>) of character; |
| 141 |
begin |
| 142 |
|
| 143 |
handler : process |
| 144 |
variable line_data : line; |
| 145 |
variable tmp : integer; |
| 146 |
variable c : character;--_array_t(0 to 3); |
| 147 |
|
| 148 |
type bin_t is file of character ; |
| 149 |
file fp : bin_t ; |
| 150 |
variable fs : file_open_status ; |
| 151 |
begin |
| 152 |
-- |
| 153 |
data <= (others => '0'); |
| 154 |
data_valid <= '0'; |
| 155 |
wait until falling_edge(reset); |
| 156 |
|
| 157 |
file_open(fs, fp, FILENAME, READ_MODE); |
| 158 |
|
| 159 |
if( fs /= OPEN_OK ) then |
| 160 |
report "File open issues" severity failure ; |
| 161 |
end if ; |
| 162 |
|
| 163 |
--readline(fp,line_data); |
| 164 |
while (reset = '0') loop |
| 165 |
|
| 166 |
wait until rising_edge(clock); |
| 167 |
data_valid <= '0'; |
| 168 |
|
| 169 |
if data_request = '1' then |
| 170 |
read(fp, c); |
| 171 |
tmp := integer(natural(character'pos(c))); |
| 172 |
data(7 downto 0) <= std_logic_vector(to_unsigned(tmp,8)); |
| 173 |
read(fp, c); |
| 174 |
tmp := integer(natural(character'pos(c))); |
| 175 |
data(15 downto 8) <= std_logic_vector(to_unsigned(tmp,8)); |
| 176 |
read(fp, c); |
| 177 |
tmp := integer(natural(character'pos(c))); |
| 178 |
data(23 downto 16) <= std_logic_vector(to_unsigned(tmp,8)); |
| 179 |
read(fp, c); |
| 180 |
tmp := integer(natural(character'pos(c))); |
| 181 |
data(31 downto 24) <= std_logic_vector(to_unsigned(tmp,8)); |
| 182 |
|
| 183 |
data_valid <= '1'; |
| 184 |
wait until rising_edge(clock); |
| 185 |
data_valid <= '0'; |
| 186 |
end if; |
| 187 |
|
| 188 |
end loop; |
| 189 |
file_close(fp); |
| 190 |
end process; |
| 191 |
end architecture; |