-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathdec_vector_tb.vhd
More file actions
138 lines (128 loc) · 2.8 KB
/
Copy pathdec_vector_tb.vhd
File metadata and controls
138 lines (128 loc) · 2.8 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
-- testbench for the vector decoder
--
-- Copyright 2019 Ahmet Inan <inan@aicodix.de>
library ieee;
use ieee.std_logic_1164.all;
use std.textio.all;
use work.ldpc_scalar.all;
entity dec_vector_tb is
end dec_vector_tb;
architecture behavioral of dec_vector_tb is
signal clock : std_logic := '0';
signal reset : std_logic := '1';
signal done : boolean := false;
signal dec_ready : boolean;
signal dec_istart : boolean := false;
signal dec_ostart : boolean;
signal dec_isoft : soft_scalar := 0;
signal dec_osoft : soft_scalar;
begin
dec_inst : entity work.dec_vector
port map (clock, dec_ready,
dec_istart, dec_ostart,
dec_isoft, dec_osoft);
clk_gen : process
begin
while not done loop
wait for 5 ns;
clock <= not clock;
end loop;
wait;
end process;
rst_gen : process
begin
wait for 100 ns;
reset <= '0';
wait;
end process;
end_sim : process (reset, clock)
constant max : positive := 3*code_scalars;
variable num : natural range 0 to max;
begin
if reset = '1' then
num := 0;
elsif rising_edge(clock) then
if not dec_ready then
num := 0;
elsif num < max then
num := num + 1;
else
done <= true;
end if;
end if;
end process;
counter : process (reset, clock)
variable num : natural;
begin
if reset = '1' then
num := 0;
elsif rising_edge(clock) then
if dec_istart then
if num >= code_scalars then
report natural'image(num) & " clock cycles";
end if;
num := 0;
else
num := num + 1;
end if;
end if;
end process;
soft_input : process (reset, clock)
file input : text open read_mode is "dec_vector_tb_inp.txt";
variable buf : line;
variable val : soft_scalar;
variable pos : natural range 0 to code_scalars;
variable eof : boolean := false;
begin
if reset = '1' then
pos := 0;
elsif rising_edge(clock) and dec_ready then
if pos = 0 then
if not eof then
readline(input, buf);
end if;
dec_istart <= true;
else
dec_istart <= false;
if eof then
val := 0;
else
read(buf, val);
end if;
dec_isoft <= val;
end if;
if pos = code_scalars then
if not eof then
pos := 0;
end if;
if endfile(input) then
eof := true;
end if;
else
pos := pos + 1;
end if;
end if;
end process;
soft_output : process (reset, clock)
file output : text open write_mode is "dec_vector_tb_out.txt";
variable buf : line;
variable val : soft_scalar;
variable pos : natural range 0 to code_scalars;
begin
if reset = '1' then
pos := code_scalars;
elsif rising_edge(clock) then
if dec_ostart then
pos := 0;
elsif pos < code_scalars then
val := dec_osoft;
write(buf, HT);
write(buf, val);
pos := pos + 1;
if pos = code_scalars then
writeline(output, buf);
end if;
end if;
end if;
end process;
end behavioral;