2021 day1/vhdl: clean up
This commit is contained in:
parent
4e8d0e3f36
commit
fc223c2746
1 changed files with 11 additions and 11 deletions
|
@ -23,7 +23,7 @@ entity top is
|
||||||
end entity;
|
end entity;
|
||||||
|
|
||||||
architecture arch of top is
|
architecture arch of top is
|
||||||
function get_window_size return positive is
|
function WINDOW_SIZE return positive is
|
||||||
begin
|
begin
|
||||||
if STEP = 1 then
|
if STEP = 1 then
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -32,14 +32,13 @@ architecture arch of top is
|
||||||
end if;
|
end if;
|
||||||
end function;
|
end function;
|
||||||
|
|
||||||
constant WINDOW_SIZE : positive := get_window_size;
|
|
||||||
|
|
||||||
type number_t is array(MAX_INPUT_DIGITS-1 downto 0) of digit_t;
|
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;
|
type window_t is array(WINDOW_SIZE-1 downto 0) of number_t;
|
||||||
|
|
||||||
|
signal current_number : number_t;
|
||||||
signal window : window_t;
|
signal window : window_t;
|
||||||
|
|
||||||
signal window_countdown : natural range WINDOW_SIZE downto 0 := 0;
|
signal window_count : natural range 0 to WINDOW_SIZE := 0;
|
||||||
begin
|
begin
|
||||||
process(clk)
|
process(clk)
|
||||||
begin
|
begin
|
||||||
|
@ -47,23 +46,24 @@ begin
|
||||||
if reset then
|
if reset then
|
||||||
output <= (others => '0');
|
output <= (others => '0');
|
||||||
output_valid <= '1';
|
output_valid <= '1';
|
||||||
window_countdown <= 0;
|
window_count <= 0;
|
||||||
elsif input_valid then
|
elsif input_valid then
|
||||||
output_valid <= '0';
|
output_valid <= '0';
|
||||||
|
|
||||||
if char = LF then
|
if char = LF then
|
||||||
if window_countdown = WINDOW_SIZE then
|
if window_count = WINDOW_SIZE then
|
||||||
if window(0) > window(window'high) then
|
if current_number > window(window'high) then
|
||||||
output <= output + 1;
|
output <= output + 1;
|
||||||
end if;
|
end if;
|
||||||
output_valid <= '1';
|
output_valid <= '1';
|
||||||
else
|
else
|
||||||
window_countdown <= window_countdown + 1;
|
window_count <= window_count + 1;
|
||||||
end if;
|
end if;
|
||||||
|
|
||||||
window <= number_t'(others => 0) & window(0 to window'high-1);
|
window <= window(window'high-1 downto 0) & current_number;
|
||||||
|
current_number <= (others => 0);
|
||||||
else
|
else
|
||||||
window(0) <= window(0)(MAX_INPUT_DIGITS-2 downto 0) & char_to_digit(char);
|
current_number <= current_number(current_number'left-1 downto 0) & char_to_digit(char);
|
||||||
end if;
|
end if;
|
||||||
end if;
|
end if;
|
||||||
end if;
|
end if;
|
||||||
|
|
Loading…
Reference in a new issue