2020-12-02 11:09:36 +01:00
|
|
|
library ieee;
|
|
|
|
use ieee.std_logic_1164.all,
|
|
|
|
ieee.numeric_std.all;
|
|
|
|
|
|
|
|
use std.textio.all;
|
|
|
|
|
|
|
|
entity sim is
|
|
|
|
generic (
|
2021-12-01 13:58:49 +01:00
|
|
|
OUTPUT_WIDTH : positive;
|
2020-12-02 11:09:36 +01:00
|
|
|
STEP : natural range 1 to 2
|
|
|
|
);
|
|
|
|
end entity;
|
|
|
|
|
2021-12-01 13:31:07 +01:00
|
|
|
architecture aoc_stdio of sim is
|
|
|
|
type char_file_t is file of character;
|
|
|
|
file stdin : char_file_t open READ_MODE is "STD_INPUT";
|
|
|
|
|
2020-12-02 11:09:36 +01:00
|
|
|
signal char_in : character;
|
2021-12-01 13:31:07 +01:00
|
|
|
signal clk, reset, input_valid, output_valid : std_logic;
|
|
|
|
signal output : unsigned(OUTPUT_WIDTH-1 downto 0);
|
2020-12-02 11:09:36 +01:00
|
|
|
|
|
|
|
procedure print(s: string) is
|
|
|
|
variable l : line;
|
|
|
|
begin
|
|
|
|
write(l, s);
|
2021-12-01 13:31:07 +01:00
|
|
|
writeline(std.textio.output, l);
|
2020-12-02 11:09:36 +01:00
|
|
|
end procedure;
|
2021-12-01 13:31:07 +01:00
|
|
|
|
|
|
|
component dut is
|
|
|
|
generic (
|
|
|
|
OUTPUT_WIDTH : positive;
|
|
|
|
STEP : natural range 1 to 2
|
|
|
|
);
|
|
|
|
port (
|
|
|
|
clk : in std_logic;
|
|
|
|
reset : in std_logic;
|
|
|
|
|
|
|
|
char : in character;
|
|
|
|
input_valid : in std_logic;
|
|
|
|
|
|
|
|
output : out unsigned(OUTPUT_WIDTH-1 downto 0);
|
|
|
|
output_valid : out std_logic
|
|
|
|
);
|
|
|
|
end component;
|
2020-12-02 11:09:36 +01:00
|
|
|
begin
|
|
|
|
process
|
|
|
|
variable current_char : character;
|
|
|
|
variable good : boolean;
|
|
|
|
|
|
|
|
procedure cycle_clock is
|
|
|
|
begin
|
|
|
|
wait for 10 ns;
|
|
|
|
clk <= '0';
|
|
|
|
wait for 10 ns;
|
|
|
|
clk <= '1';
|
|
|
|
wait for 0 ns;
|
|
|
|
end procedure;
|
|
|
|
begin
|
|
|
|
clk <= '0';
|
2021-12-01 13:31:07 +01:00
|
|
|
input_valid <= '0';
|
2020-12-02 11:09:36 +01:00
|
|
|
char_in <= NUL;
|
|
|
|
|
|
|
|
reset <= '1';
|
|
|
|
cycle_clock;
|
|
|
|
reset <= '0';
|
|
|
|
cycle_clock;
|
|
|
|
|
2021-12-01 13:31:07 +01:00
|
|
|
input_valid <= '1';
|
2020-12-02 11:09:36 +01:00
|
|
|
|
2021-12-01 13:31:07 +01:00
|
|
|
chars_loop: while not endfile(stdin) loop
|
|
|
|
read(stdin, current_char);
|
2020-12-02 11:09:36 +01:00
|
|
|
|
2021-12-01 13:31:07 +01:00
|
|
|
char_in <= current_char;
|
2020-12-02 11:09:36 +01:00
|
|
|
cycle_clock;
|
|
|
|
end loop;
|
|
|
|
|
2021-12-01 13:31:07 +01:00
|
|
|
input_valid <= '0';
|
|
|
|
cycle_clock;
|
2020-12-02 11:09:36 +01:00
|
|
|
cycle_clock;
|
|
|
|
|
2021-12-01 13:31:07 +01:00
|
|
|
assert output_valid report "Output was not valid at end of simulation" severity failure;
|
|
|
|
print(to_string(to_integer(output)));
|
2020-12-02 11:09:36 +01:00
|
|
|
|
|
|
|
wait;
|
|
|
|
end process;
|
|
|
|
|
2021-12-01 13:31:07 +01:00
|
|
|
dut_inst: dut
|
2020-12-02 11:09:36 +01:00
|
|
|
generic map (
|
2021-12-01 13:31:07 +01:00
|
|
|
OUTPUT_WIDTH => OUTPUT_WIDTH,
|
2020-12-02 11:09:36 +01:00
|
|
|
STEP => STEP
|
|
|
|
)
|
|
|
|
port map (
|
|
|
|
clk => clk,
|
|
|
|
reset => reset,
|
|
|
|
char => char_in,
|
2021-12-01 13:31:07 +01:00
|
|
|
input_valid => input_valid,
|
|
|
|
output => output,
|
|
|
|
output_valid => output_valid
|
2020-12-02 11:09:36 +01:00
|
|
|
);
|
|
|
|
end architecture;
|