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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
`timescale 1ns/1ps
module chdr_32f_to_16sc_tb();
reg clk = 0;
reg reset = 1;
//generate clock
always #10 clk = ~clk;
initial $dumpfile("chdr_32f_to_16sc_tb.vcd");
initial $dumpvars(0,chdr_32f_to_16sc_tb);
//tells when to finish
initial
begin
#50 reset = 0;
#50000;
$finish;
end
//setting registers and wire
reg [63:0] i_tdata;
reg i_tlast = 0;
reg i_tvalid = 0;
wire i_tready;
wire [63:0] o_tdata;
wire o_tlast;
wire o_tvalid;
reg o_tready;
reg [7:0] set_addr;
reg [31:0] set_data;
reg set_stb;
chdr_32f_to_16sc #(.BASE(89))dut
(.clk(clk), .reset(reset),
.set_data(set_data), .set_stb(set_stb), .set_addr(set_addr),
.i_tdata(i_tdata), .i_tlast(i_tlast), .i_tvalid(i_tvalid), .i_tready(i_tready),
.o_tdata(o_tdata), .o_tlast(o_tlast), .o_tvalid(o_tvalid), .o_tready(o_tready), .debug());
reg [31:0]data[0:7];
initial $readmemh("iq_to_float_output.txt", data);
task test_packet;
input [15:0] len;
input [31:0] sid;
reg [4:0] index;
begin
index <= 0;
@(posedge clk) ;
//send header
i_tdata <= {1'b0, 1'b0, 1'b1, 1'b0, 12'h0, (len + 16'd16), sid};
i_tvalid <= 1;
i_tlast <= 0;
@(posedge clk);
while (i_tready != 1)
@(posedge clk);
i_tdata <= {64'b0};
@(posedge clk);
while (i_tready != 1)
@(posedge clk);
//-1 for last bit accounting
repeat (len[15:3] + (len[2]|len[1]|len[0]) - 1)
begin
i_tdata <= {data[index],data[index+1]};
index <= index+2;
@(posedge clk);
while (i_tready != 1)
@(posedge clk);
end
i_tlast <= 1'b1;
i_tdata <= {data[index], data[index+1]};
@(posedge clk);
while (i_tready != 1)
@(posedge clk);
i_tvalid <= 0;
end
endtask // test_packet
task test_destination;
input enable;
input [15:0] dest_home;
begin
@(posedge clk);
set_data <= {enable,dest_home};
set_addr <= 89;
set_stb <= 1;
@(posedge clk);
set_stb <= 0;
end
endtask
initial
begin
i_tvalid <= 0;
o_tready <= 1;
i_tdata <= 0;
@(negedge reset);
@(posedge clk);
@(posedge clk);
test_destination(1,16'hFEED);
test_packet(4, 32'hDEAD_BEEF);
test_destination(1,16'hFEED);
test_packet(8, 32'hDEAD_BEEF);
test_destination(1,16'hFEED);
test_packet(16, 32'hDEAD_BEEF);
test_destination(1,16'hFEED);
test_packet(20, 32'hDEAD_BEEF);
test_destination(1,16'hFEED);
test_packet(24, 32'hDEAD_BEEF);
test_destination(1,16'hFEED);
test_packet(28, 32'hDEAD_BEEF);
end
endmodule
|