-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelay.vhd
80 lines (61 loc) · 2.13 KB
/
delay.vhd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
-- Greg Stitt
-- University of Florida
--
-- Entity: delay
-- Description: This entity delays an input by a specified number of cycles,
-- while also allowing stalls and specific output values on reset.
library ieee;
use ieee.std_logic_1164.all;
-------------------------------------------------------------------------------
-- Generic Descriptions
-- cycles : The length of the delay in cycles (required)
-- width : The width of the input signal (required)
-- init : An initial value (of width bits) for the first "cycles" output
-- after a reset (required)
-------------------------------------------------------------------------------
------------------------------------------------------------------------------
-- Port Description
-- clk : clock
-- rst : reset
-- en : enable (active high), '0' stalls the delay pipeline
-- input : The input to be delayed
-- output : The input after "cycles" pass (assuming no stalls from en='0')
-------------------------------------------------------------------------------
entity delay is
generic(cycles : natural;
width : positive;
init : std_logic_vector);
port( clk : in std_logic;
rst : in std_logic;
en : in std_logic := '1';
input : in std_logic_vector(width-1 downto 0);
output : out std_logic_vector(width-1 downto 0));
end delay;
architecture FF of delay is
type reg_array is array (0 to cycles-1) of std_logic_vector(width-1 downto 0);
signal regs : reg_array;
begin -- BHV
U_CYCLES_GT_0 : if cycles > 0 generate
process(clk, rst)
begin
if (rst = '1') then
for i in 0 to cycles-1 loop
regs(i) <= init;
end loop;
elsif (clk'event and clk = '1') then
if (en = '1') then
regs(0) <= input;
end if;
for i in 0 to cycles-2 loop
if (en = '1') then
regs(i+1) <= regs(i);
end if;
end loop;
end if;
end process;
output <= regs(cycles-1);
end generate U_CYCLES_GT_0;
U_CYCLES_EQ_0 : if cycles = 0 generate
output <= input;
end generate U_CYCLES_EQ_0;
end FF;