OpenCores
URL https://opencores.org/ocsvn/ssbcc/ssbcc/trunk

Subversion Repositories ssbcc

[/] [ssbcc/] [trunk/] [core/] [9x8/] [peripherals/] [tb/] [AXI4_Lite_Slave_DualPortRAM/] [tb.v] - Blame information for rev 2

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 sinclairrf
/*******************************************************************************
2
 *
3
 * Copyright 2013, Sinclair R.F., Inc.
4
 *
5
 * Test bench for the AXI4-Lite slave dual-port-ram peripheral.
6
 *
7
 ******************************************************************************/
8
 
9
`timescale 1ns/1ps
10
 
11
module tb;
12
 
13
// 125 MHz clock
14
reg s_clk = 1'b1;
15
always @ (s_clk)
16
  s_clk <= #4 ~s_clk;
17
 
18
reg s_rst = 1'b1;
19
initial begin
20
  repeat (5) @ (posedge s_clk);
21
  s_rst = 1'b0;
22
end
23
 
24
//
25
// Simulate the AXI4-Lite master
26
//
27
 
28
reg s_aclk = 1'b1;
29
always @ (s_aclk)
30
  s_aclk <= #5 ~s_aclk;
31
 
32
// Command AXI4-Lite writes and reads.
33
reg s_wr_done;
34
reg s_rd_done;
35
reg  [6:0] s_wr_addr    = 7'd0;
36
reg [31:0] s_wr_data    = 32'd0;
37
reg  [3:0] s_wr_vld     = 4'b0000;
38
reg        s_wr_go      = 1'b0;
39
reg  [6:0] s_rd_addr    = 7'd0;
40
reg        s_rd_go      = 1'b0;
41
initial begin
42
  // 1-byte write
43
  repeat (1500) @ (posedge s_aclk);
44
  s_wr_addr <= 7'h03;
45
  s_wr_data <= 32'h03020100;
46
  s_wr_vld  <= 4'b1000;
47
  s_wr_go <= 1'b1; @ (posedge s_aclk); s_wr_go <= 1'b0; wait(s_wr_done); @ (posedge s_aclk);
48
  // 2-byte write
49
  repeat (100) @ (posedge s_aclk);
50
  s_wr_addr <= 7'h06;
51
  s_wr_data <= 32'h07060504;
52
  s_wr_vld  <= 4'b1100;
53
  s_wr_go <= 1'b1; @ (posedge s_aclk); s_wr_go <= 1'b0; wait(s_wr_done); @ (posedge s_aclk);
54
  // 2-byte write
55
  repeat (100) @ (posedge s_aclk);
56
  s_wr_addr <= 7'h08;
57
  s_wr_data <= 32'h0B0A0908;
58
  s_wr_vld  <= 4'b0011;
59
  s_wr_go <= 1'b1; @ (posedge s_aclk); s_wr_go <= 1'b0; wait(s_wr_done); @ (posedge s_aclk);
60
  // 4-byte write
61
  repeat (100) @ (posedge s_aclk);
62
  s_wr_addr <= 7'h0C;
63
  s_wr_data <= 32'h0F0E0D0C;
64
  s_wr_vld  <= 4'b0011;
65
  s_wr_go <= 1'b1; @ (posedge s_aclk); s_wr_go <= 1'b0; wait(s_wr_done); @ (posedge s_aclk);
66
  // isolated read
67
  repeat (100) @ (posedge s_aclk);
68
  s_rd_addr <= 7'd16;
69
  s_rd_go <= 1'b1; @ (posedge s_aclk); s_rd_go <= 1'b0; wait(s_rd_done); @ (posedge s_aclk);
70
  // simultaneous read and write
71
  repeat (100) @ (posedge s_aclk);
72
  s_wr_addr <= 7'h10;
73
  s_wr_data <= 32'h13121110;
74
  s_wr_vld  <= 4'b1111;
75
  s_rd_addr <= 7'd04;
76
  s_wr_go <= 1'b1; s_rd_go <= 1'b1; @ (posedge s_aclk); s_wr_go <= 1'b0; s_rd_go <= 1'b0; wait(s_wr_done); wait(s_rd_done); @ (posedge s_aclk);
77
  // read preceding write by 1 clock cycle
78
  repeat (100) @ (posedge s_aclk);
79
  s_rd_addr <= 7'd08;
80
  s_wr_addr <= 7'h14;
81
  s_wr_data <= 32'h17161514;
82
  s_wr_vld  <= 4'b1111;
83
  s_rd_go <= 1'b1; @ (posedge s_aclk); s_rd_go <= 1'b0;
84
  s_wr_go <= 1'b1; @ (posedge s_aclk); s_wr_go <= 1'b0;
85
  wait(s_rd_done); wait(s_wr_done); @ (posedge s_aclk);
86
  // signal termination to the micro controller by writing a 4 to the byte at address 16;
87
  repeat (100) @ (posedge s_aclk);
88
  s_wr_addr <= 7'h10;
89
  s_wr_data <= 32'h04;
90
  s_wr_vld  <= 4'b0001;
91
  s_rd_addr <= 7'd0;
92
  s_wr_go <= 1'b1; @ (posedge s_aclk); s_wr_go <= 1'b0; wait(s_wr_done); @ (posedge s_aclk);
93
end
94
 
95
// Initiate writes and indicate their termination.
96
initial s_wr_done = 1'b0;
97
reg  [2:0] s_wr_acks = 3'b000;
98
reg        s_awvalid = 1'b0;
99
reg        s_wvalid  = 1'b0;
100
reg        s_bready  = 1'b0;
101
wire       s_awready;
102
wire       s_wready;
103
wire       s_bvalid;
104
always @ (posedge s_aclk) begin
105
  s_wr_done <= 1'b0;
106
  s_wr_acks <= s_wr_acks;
107
  s_bready <= 1'b0;
108
  if (s_wr_acks == 3'b111) begin
109
    s_wr_done <= 1'b1;
110
    s_wr_acks <= 3'b000;
111
  end
112
  if (s_wr_go) begin
113
    s_awvalid <= 1'b1;
114
    s_wvalid  <= 1'b1;
115
  end
116
  if (s_awvalid && s_awready) begin
117
    s_awvalid <= 1'b0;
118
    s_wr_acks[0] <= 1'b1;
119
  end
120
  if (s_wvalid && s_wready) begin
121
    s_wvalid <= 1'b0;
122
    s_wr_acks[1] <= 1'b1;
123
  end
124
  if (s_bvalid && ~s_bready && ~s_wr_acks[2])
125
    s_bready <= 1'b1;
126
  if (s_bvalid && s_bready)
127
    s_wr_acks[2] <= 1'b1;
128
end
129
 
130
// Initiate reads and indicate their termination
131
initial s_rd_done = 1'b0;
132
reg  [1:0] s_rd_acks = 2'b00;
133
reg        s_arvalid = 1'b0;
134
reg        s_rready = 1'b0;
135
wire       s_arready;
136
wire       s_rvalid;
137
always @ (posedge s_aclk) begin
138
  s_rd_done <= 1'b0;
139
  s_rd_acks <= s_rd_acks;
140
  s_rready <= 1'b0;
141
  if (s_rd_acks == 2'b11) begin
142
    s_rd_done <= 1'b1;
143
    s_rd_acks <= 2'b00;
144
  end
145
  if (s_rd_go)
146
    s_arvalid <= 1'b1;
147
  if (s_arvalid && s_arready) begin
148
    s_arvalid <= 1'b0;
149
    s_rd_acks[0] <= 1'b1;
150
  end
151
  if (s_rvalid && ~s_rready && ~s_rd_acks[1])
152
    s_rready <= 1'b1;
153
  if (s_rvalid && s_rready)
154
    s_rd_acks[1] <= 1'b1;
155
end
156
 
157
//
158
// Instantiate the micro controller, its data output, and program termination.
159
//
160
 
161
wire  [1:0] s_bresp;
162
wire [31:0] s_rdata;
163
wire  [1:0] s_rresp;
164
wire  [7:0] s_addr;
165
wire  [7:0] s_data;
166
wire        s_data_wr;
167
wire        s_done;
168
tb_AXI4_Lite_Slave_DualPortRAM uut(
169
  // synchronous reset and processor clock
170
  .i_rst                (s_rst),
171
  .i_clk                (s_clk),
172
  // AXI4-Lite Slave I/F
173
  .i_axi_lite_aresetn   (1'b1),
174
  .i_axi_lite_aclk      (s_aclk),
175
  .i_axi_lite_awvalid   (s_awvalid),
176
  .o_axi_lite_awready   (s_awready),
177
  .i_axi_lite_awaddr    (s_wr_addr),
178
  .i_axi_lite_wvalid    (s_wvalid),
179
  .o_axi_lite_wready    (s_wready),
180
  .i_axi_lite_wdata     (s_wr_data),
181
  .i_axi_lite_wstrb     (s_wr_vld),
182
  .o_axi_lite_bresp     (s_bresp),
183
  .o_axi_lite_bvalid    (s_bvalid),
184
  .i_axi_lite_bready    (s_bready),
185
  .i_axi_lite_arvalid   (s_arvalid),
186
  .o_axi_lite_arready   (s_arready),
187
  .i_axi_lite_araddr    (7'd0),
188
  .o_axi_lite_rvalid    (s_rvalid),
189
  .i_axi_lite_rready    (s_rready),
190
  .o_axi_lite_rdata     (s_rdata),
191
  .o_axi_lite_rresp     (s_rresp),
192
  // diagnostic output
193
  .o_diag_addr          (s_addr),
194
  .o_diag_data          (s_data),
195
  .o_diag_wr            (s_data_wr),
196
  // program termination
197
  .o_done               (s_done)
198
);
199
 
200
always @ (posedge s_clk)
201
  if (s_data_wr)
202
    $display("%12d : %h %h", $time, s_addr, s_data);
203
 
204
always @ (posedge s_clk)
205
  if (s_done)
206
    $finish;
207
 
208
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.