-
Notifications
You must be signed in to change notification settings - Fork 2
/
spi_shift_reg_tb.v
170 lines (153 loc) · 3.07 KB
/
spi_shift_reg_tb.v
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
`include "spi_defines.v"
`timescale 1us/1ns
module spi_shift_reg_tb;
reg rx_negedge,
tx_negedge,
wb_clk_in,
wb_rst,
go,
miso,
lsb,
sclk,
cpol_0,
cpol_1;
reg [3:0] byte_sel,latch ;
reg [`SPI_CHAR_LEN_BITS-1:0] len;
reg [`SPI_MAX_CHAR-1:0] p_in;
wire [`SPI_MAX_CHAR-1:0]p_out;
wire tip,mosi;
wire last;
parameter T = 10;
parameter [`SPI_DIVIDER_LEN-1:0] divider_value = 4'b0010;
// Instantiate the DUT
spi_shift_reg DUT (rx_negedge,
tx_negedge,
byte_sel,
latch,
len,
p_in,
wb_clk_in,
wb_rst,
go,
miso,
lsb,
sclk,
cpol_0,
cpol_1,
p_out,
last,
mosi,
tip);
initial
begin
wb_clk_in = 1'b0;
forever
#(T/2) wb_clk_in = ~wb_clk_in;
end
initial
begin
sclk = 1'b0;
forever
begin
repeat(divider_value + 1)
@(posedge wb_clk_in);
sclk = ~sclk;
end
end
task rst();
begin
wb_rst = 1'b1;
#13;
wb_rst = 1'b0;
end
endtask
initial
begin
cpol_1 = 1'b0;
forever
begin
repeat(divider_value*2 + 1)
@(posedge wb_clk_in);
cpol_1 = 1'b1;
@(posedge wb_clk_in)
cpol_1 = 1'b0;
repeat(divider_value*2 + 1)
@(posedge wb_clk_in);
cpol_1 = 1'b1;
@(posedge wb_clk_in)
cpol_1 = 1'b0;
end
end
initial
begin
cpol_0 = 1'b0;
repeat(divider_value)
@(posedge wb_clk_in);
cpol_0 = 1'b1;
@(posedge wb_clk_in)
cpol_0 = 1'b0;
forever
begin
repeat(divider_value*2 + 1)
@(posedge wb_clk_in);
cpol_0 = 1'b1;
@(posedge wb_clk_in)
cpol_0 = 1'b0;
end
end
task t1;
begin
@(negedge wb_clk_in)
rx_negedge = 1'b1;
tx_negedge = 1'b0;
end
endtask
task t2;
begin
@(negedge wb_clk_in)
rx_negedge = 1'b0;
tx_negedge = 1'b1;
end
endtask
task initialize;
begin
len = 3'b000;
lsb = 1'b0;
p_in = 32'h0000;
byte_sel = 4'b0000;
latch = 4'b0000;
go = 1'b0;
miso = 1'b0;
cpol_1 = 1'b0;
cpol_0 = 1'b0;
end
endtask
initial
begin
initialize;
rst;
@(negedge wb_clk_in)
len = 32'h0004;
lsb = 1'b1;
p_in = 32'haa55;
latch = 4'b0001;
byte_sel = 4'b0001;
t1;
#10;
go = 1'b1;
#40;
miso = 1'b1;
#20;
miso = 1'b0;
#20;
miso = 1'b1;
#20;
miso = 1'b0;
#20;
miso = 1'b1;
#60;
miso = 1'b0;
#30;
#100;
end
endmodule