2021 day1/vhdl: add solution
This commit is contained in:
parent
d60b8c5371
commit
7a58f73e51
5 changed files with 147 additions and 0 deletions
2
2021/day1/vhdl/.gitignore
vendored
Normal file
2
2021/day1/vhdl/.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
day1
|
||||
workdir/
|
11
2021/day1/vhdl/day1.vhdl
Normal file
11
2021/day1/vhdl/day1.vhdl
Normal file
|
@ -0,0 +1,11 @@
|
|||
configuration day1 of sim is
|
||||
for aoc_stdio
|
||||
for dut_inst : dut
|
||||
use entity work.top generic map (
|
||||
MAX_INPUT_DIGITS => 6,
|
||||
OUTPUT_WIDTH => OUTPUT_WIDTH,
|
||||
STEP => STEP
|
||||
);
|
||||
end for;
|
||||
end for;
|
||||
end configuration;
|
8
2021/day1/vhdl/run.sh
Executable file
8
2021/day1/vhdl/run.sh
Executable file
|
@ -0,0 +1,8 @@
|
|||
#!/bin/bash
|
||||
|
||||
source "$COMMON_DIR/vhdl_run.sh"
|
||||
|
||||
cd "$(dirname "${BASH_SOURCE[0]}")"
|
||||
|
||||
DUT_OUTPUT_WIDTH=12
|
||||
test_sim day1 top.vhdl
|
55
2021/day1/vhdl/sim.gtkw
Normal file
55
2021/day1/vhdl/sim.gtkw
Normal file
|
@ -0,0 +1,55 @@
|
|||
[*]
|
||||
[*] GTKWave Analyzer v3.3.109 (w)1999-2020 BSI
|
||||
[*] Wed Dec 1 13:50:21 2021
|
||||
[*]
|
||||
[dumpfile] "/home/xiretza/dev/advent-of-code/2021/day1/vhdl/workdir/sim1.ghw"
|
||||
[dumpfile_mtime] "Wed Dec 1 13:48:36 2021"
|
||||
[dumpfile_size] 235598
|
||||
[savefile] "/home/xiretza/dev/advent-of-code/2021/day1/vhdl/sim.gtkw"
|
||||
[timestart] 11375200000
|
||||
[size] 1920 1035
|
||||
[pos] -1 -1
|
||||
*-26.627251 11673700000 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
|
||||
[treeopen] top.
|
||||
[treeopen] top.sim.
|
||||
[treeopen] top.sim.dut_inst.
|
||||
[treeopen] top.sim.dut_inst.window.
|
||||
[sst_width] 221
|
||||
[signals_width] 173
|
||||
[sst_expanded] 1
|
||||
[sst_vpaned_height] 296
|
||||
@28
|
||||
top.sim.clk
|
||||
top.sim.reset
|
||||
@420
|
||||
top.sim.char_in
|
||||
@200
|
||||
-
|
||||
@420
|
||||
top.sim.dut_inst.window[0][0]
|
||||
top.sim.dut_inst.window[0][1]
|
||||
top.sim.dut_inst.window[0][2]
|
||||
top.sim.dut_inst.window[0][3]
|
||||
top.sim.dut_inst.window[0][4]
|
||||
top.sim.dut_inst.window[0][5]
|
||||
@200
|
||||
-
|
||||
@420
|
||||
top.sim.dut_inst.window[1][0]
|
||||
top.sim.dut_inst.window[1][1]
|
||||
top.sim.dut_inst.window[1][2]
|
||||
@421
|
||||
top.sim.dut_inst.window[1][3]
|
||||
@420
|
||||
top.sim.dut_inst.window[1][4]
|
||||
top.sim.dut_inst.window[1][5]
|
||||
@200
|
||||
-
|
||||
@28
|
||||
top.sim.input_valid
|
||||
@22
|
||||
#{top.sim.output[11:0]} top.sim.output[11] top.sim.output[10] top.sim.output[9] top.sim.output[8] top.sim.output[7] top.sim.output[6] top.sim.output[5] top.sim.output[4] top.sim.output[3] top.sim.output[2] top.sim.output[1] top.sim.output[0]
|
||||
@28
|
||||
top.sim.output_valid
|
||||
[pattern_trace] 1
|
||||
[pattern_trace] 0
|
71
2021/day1/vhdl/top.vhdl
Normal file
71
2021/day1/vhdl/top.vhdl
Normal file
|
@ -0,0 +1,71 @@
|
|||
library ieee;
|
||||
use ieee.std_logic_1164.all,
|
||||
ieee.numeric_std.all;
|
||||
|
||||
use work.util.all;
|
||||
|
||||
entity top is
|
||||
generic (
|
||||
MAX_INPUT_DIGITS : positive;
|
||||
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 entity;
|
||||
|
||||
architecture arch of top is
|
||||
function get_window_size return positive is
|
||||
begin
|
||||
if STEP = 1 then
|
||||
return 1;
|
||||
else
|
||||
return 3;
|
||||
end if;
|
||||
end function;
|
||||
|
||||
constant WINDOW_SIZE : positive := get_window_size;
|
||||
|
||||
type number_t is array(MAX_INPUT_DIGITS-1 downto 0) of digit_t;
|
||||
type window_t is array(0 to WINDOW_SIZE) of number_t;
|
||||
|
||||
signal window : window_t;
|
||||
|
||||
signal window_countdown : natural range WINDOW_SIZE downto 0 := 0;
|
||||
begin
|
||||
process(clk)
|
||||
begin
|
||||
if rising_edge(clk) then
|
||||
if reset then
|
||||
output <= (others => '0');
|
||||
output_valid <= '1';
|
||||
window_countdown <= 0;
|
||||
elsif input_valid then
|
||||
output_valid <= '0';
|
||||
|
||||
if char = LF then
|
||||
if window_countdown = WINDOW_SIZE then
|
||||
if window(0) > window(window'high) then
|
||||
output <= output + 1;
|
||||
end if;
|
||||
output_valid <= '1';
|
||||
else
|
||||
window_countdown <= window_countdown + 1;
|
||||
end if;
|
||||
|
||||
window <= number_t'(others => 0) & window(0 to window'high-1);
|
||||
else
|
||||
window(0) <= window(0)(MAX_INPUT_DIGITS-2 downto 0) & char_to_digit(char);
|
||||
end if;
|
||||
end if;
|
||||
end if;
|
||||
end process;
|
||||
end architecture;
|
Loading…
Reference in a new issue