-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathTest_bench.v
126 lines (94 loc) · 2.68 KB
/
Test_bench.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
module Test_bench ();
parameter SPI_MODE = 3;
parameter SPI_CLK_DELAY = 20; // 2.5 MHz
parameter MAIN_CLK_DELAY = 2; // 25 MHz
wire w_CPOL; // clock polarity
wire w_CPHA; // clock phase
assign w_CPOL = (SPI_MODE == 2) | (SPI_MODE == 3);
assign w_CPHA = (SPI_MODE == 1) | (SPI_MODE == 3);
reg r_Rst_L = 1'b0;
wire w_SPI_Clk;
reg r_Clk = 1'b0;
wire w_SPI_MOSI;
wire w_SPI_MISO;
// Master Specific
reg [7:0] r_Master_TX_Byte ;
reg r_Master_TX_DV = 1'b0;
reg r_Master_CS_n = 1'b1;
wire w_Master_TX_Ready;
wire r_Master_RX_DV;
wire [7:0] r_Master_RX_Byte;
// Slave Specific
wire w_Slave_RX_DV; reg r_Slave_TX_DV;
wire [7:0] w_Slave_RX_Byte; reg [7:0] r_Slave_TX_Byte;
// Clock Generators:
always #(MAIN_CLK_DELAY) r_Clk = ~r_Clk;
// Instantiate UUT
SPI_SLAVE #(.SPI_MODE(SPI_MODE)) SPI_Slave_UUT
(
.i_Rst_L(r_Rst_L),
.i_Clk(r_Clk),
.o_RX_DV(w_Slave_RX_DV),
.o_RX_Byte(w_Slave_RX_Byte),
.i_TX_DV(r_Slave_TX_DV),
.i_TX_Byte(r_Slave_TX_Byte),
// SPI Interface
.i_SPI_Clk(w_SPI_Clk),
.o_SPI_MISO(w_SPI_MISO),
.i_SPI_MOSI(w_SPI_MOSI),
.i_SPI_CS_n(r_Master_CS_n)
);
SPI_M
#(.SPI_MODE(SPI_MODE),
.CLKS_PER_HALF_BIT(2),
.NUM_SLAVES(1)) SPI_Master_UUT
(
.i_Rst_L(r_Rst_L),
.i_Clk(r_Clk),
.i_TX_Byte(r_Master_TX_Byte),
.i_TX_DV(r_Master_TX_DV),
.o_TX_Ready(w_Master_TX_Ready),
.o_RX_DV(r_Master_RX_DV),
.o_RX_Byte(r_Master_RX_Byte),
.o_SPI_Clk(w_SPI_Clk),
.i_SPI_MISO(w_SPI_MISO),
.o_SPI_MOSI(w_SPI_MOSI)
);
task SendSingleByte(input [7:0] data);begin
@(posedge r_Clk);
r_Master_TX_Byte <= data;
r_Master_TX_DV <= 1'b1;
r_Master_CS_n <= 1'b0;
@(posedge r_Clk);
r_Master_TX_DV <= 1'b0;
@(posedge w_Master_TX_Ready);
r_Master_CS_n <= 1'b1;
end
endtask
initial
begin
repeat(10) @(posedge r_Clk);
r_Rst_L = 1'b0;
r_Master_CS_n <= 1'b1;
repeat(10) @(posedge r_Clk);
r_Rst_L = 1'b1;
r_Master_CS_n <= 1'b0;
r_Slave_TX_Byte <= 8'h5A;
r_Slave_TX_DV <= 1'b1;
repeat(10) @(posedge r_Clk);
r_Master_CS_n<=1'b1;
r_Slave_TX_DV <= 1'b0;
SendSingleByte(8'hC1);
repeat(100) @(posedge r_Clk);
r_Rst_L = 1'b1;
r_Master_CS_n <= 1'b0;
r_Slave_TX_Byte <= 8'h2A;
r_Slave_TX_DV <= 1'b1;
repeat(10) @(posedge r_Clk);
r_Slave_TX_DV <= 1'b0;
r_Master_CS_n<=1'b1;
SendSingleByte(8'ha1);
repeat(100) @(posedge r_Clk);
$finish();
end
endmodule