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

Subversion Repositories ssbcc

[/] [ssbcc/] [trunk/] [core/] [9x8/] [peripherals/] [tb/] [AXI4_Lite_Master/] [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 master peripheral.
6
 *
7
 ******************************************************************************/
8
 
9
`timescale 1ns/1ps
10
 
11
module tb;
12
 
13
localparam L_RESP_OKAY = 2'b00;
14
 
15
// 100 MHz clock
16
reg s_clk = 1'b1;
17
always @ (s_clk)
18
  s_clk <= #5 ~s_clk;
19
 
20
reg s_rst = 1'b1;
21
initial begin
22
  repeat (5) @ (posedge s_clk);
23
  s_rst = 1'b0;
24
end
25
 
26
// AXI4-Lite signals
27
wire            s_alm_aresetn   = ~s_rst;
28
wire            s_alm_aclk      = s_clk;
29
wire            s_alm_awvalid;
30
reg             s_alm_awready;
31
wire      [6:0] s_alm_awaddr;
32
wire            s_alm_wvalid;
33
reg             s_alm_wready;
34
wire     [31:0] s_alm_wdata;
35
wire      [3:0] s_alm_wstrb;
36
reg       [1:0] s_alm_bresp     = L_RESP_OKAY;
37
reg             s_alm_bvalid;
38
wire            s_alm_bready;
39
wire            s_alm_arvalid;
40
reg             s_alm_arready;
41
wire      [6:0] s_alm_araddr;
42
reg             s_alm_rvalid;
43
wire            s_alm_rready;
44
reg      [31:0] s_alm_rdata;
45
reg       [1:0] s_alm_rresp     = L_RESP_OKAY;
46
 
47
// diagnostic signals
48
wire      [7:0] s_diag_data;
49
wire            s_diag_wr;
50
wire            s_done;
51
 
52
tb_AXI4_Lite_Master uut(
53
  // synchronous reset and processor clock
54
  .i_rst                (s_rst),
55
  .i_clk                (s_clk),
56
  // AXI4-Lite Master
57
  .i_alm_aresetn        (s_alm_aresetn),
58
  .i_alm_aclk           (s_alm_aclk),
59
  .o_alm_awvalid        (s_alm_awvalid),
60
  .i_alm_awready        (s_alm_awready),
61
  .o_alm_awaddr         (s_alm_awaddr),
62
  .o_alm_wvalid         (s_alm_wvalid),
63
  .i_alm_wready         (s_alm_wready),
64
  .o_alm_wdata          (s_alm_wdata),
65
  .o_alm_wstrb          (s_alm_wstrb),
66
  .i_alm_bresp          (s_alm_bresp),
67
  .i_alm_bvalid         (s_alm_bvalid),
68
  .o_alm_bready         (s_alm_bready),
69
  .o_alm_arvalid        (s_alm_arvalid),
70
  .i_alm_arready        (s_alm_arready),
71
  .o_alm_araddr         (s_alm_araddr),
72
  .i_alm_rvalid         (s_alm_rvalid),
73
  .o_alm_rready         (s_alm_rready),
74
  .i_alm_rdata          (s_alm_rdata),
75
  .i_alm_rresp          (s_alm_rresp),
76
  // diagnostic output
77
  .o_diag_data          (s_diag_data),
78
  .o_diag_wr            (s_diag_wr),
79
  // program termination
80
  .o_done               (s_done)
81
);
82
 
83
// declare the memory
84
 
85
reg [7:0] s_mem[127:0];
86
 
87
//
88
// Acknowledge write signals.
89
//
90
 
91
initial s_alm_awready = 1'b0;
92
always @ (posedge s_alm_aclk)
93
  if (~s_alm_aresetn)
94
    s_alm_awready <= 1'b0;
95
  else
96
    s_alm_awready <= s_alm_awvalid && ~s_alm_awready;
97
 
98
initial s_alm_wready = 1'b0;
99
always @ (posedge s_alm_aclk)
100
  if (~s_alm_aresetn)
101
    s_alm_wready <= 1'b0;
102
  else
103
    s_alm_wready <= s_alm_wvalid && ~s_alm_wready;
104
 
105
initial s_alm_bvalid = 1'b0;
106
integer ix_write;
107
always @ (posedge s_alm_aclk)
108
  if (~s_alm_aresetn)
109
    s_alm_bvalid <= 1'b0;
110
  else if (s_alm_awvalid && s_alm_awready) begin
111
    s_alm_bvalid <= 1'b1;
112
    for (ix_write=0; ix_write<4; ix_write=ix_write+1)
113
      if (s_alm_wstrb[ix_write])
114
        s_mem[{ s_alm_awaddr[6:2], ix_write[1:0] }] <= s_alm_wdata[8*ix_write+:8];
115
  end else if (s_alm_bready)
116
    s_alm_bvalid <= 1'b0;
117
  else
118
    s_alm_bvalid <= s_alm_bvalid;
119
 
120
always @ (posedge s_alm_aclk) begin
121
  if (s_alm_awvalid && s_alm_awready) $display("%14d -- awready issued : 0x%h", $time, s_alm_awaddr);
122
  if (s_alm_wvalid && s_alm_wready) $display("%14d -- wready issued : 0x%h 0x%h", $time, s_alm_wdata, s_alm_wstrb);
123
  if (s_alm_bready && s_alm_bvalid) $display("%14d -- bvalid issued", $time);
124
end
125
 
126
//
127
// Acknowledge read.
128
//
129
 
130
initial s_alm_arready = 1'b0;
131
always @ (posedge s_alm_aclk)
132
  if (~s_alm_aresetn)
133
    s_alm_arready <= 1'b0;
134
  else
135
    s_alm_arready <= s_alm_arvalid && ~s_alm_arready;
136
 
137
localparam L_XOR_CONSTANT = 32'h5A5A_5A5A;
138
initial s_alm_rdata = 32'd0;
139
integer ix_read;
140
always @ (posedge s_alm_aclk)
141
  if (~s_alm_aresetn)
142
    s_alm_rdata <= 32'd0;
143
  else if (s_alm_arvalid && s_alm_arready)
144
    for (ix_read=0; ix_read<4; ix_read=ix_read+1)
145
      s_alm_rdata[8*ix_read+:8] <= s_mem[{ s_alm_araddr[6:2], ix_read[1:0] }];
146
  else
147
    s_alm_rdata <= s_alm_rdata;
148
 
149
initial s_alm_rvalid = 1'b0;
150
always @ (posedge s_alm_aclk)
151
  if (~s_alm_aresetn)
152
    s_alm_rvalid <= 1'b0;
153
  else if (s_alm_arready && s_alm_arvalid)
154
    s_alm_rvalid <= 1'b1;
155
  else
156
    s_alm_rvalid <= s_alm_rvalid && ~s_alm_rready;
157
 
158
always @ (posedge s_alm_aclk) begin
159
  if (s_alm_arvalid && s_alm_arready) $display("%14d -- arready issued : 0x%h", $time, s_alm_araddr);
160
  if (s_alm_rready && s_alm_rvalid) $display("%14d -- rready recieved : 0x%8h", $time, s_alm_rdata);
161
end
162
 
163
//
164
// Diagnostic printout.
165
//
166
 
167
always @ (posedge s_clk)
168
  if (s_diag_wr)
169
    $display("%14d : 0x%02h", $time, s_diag_data);
170
 
171
//
172
// Termination criterion.
173
//
174
 
175
always @ (posedge s_clk)
176
  if (s_done)
177
    $finish;
178
 
179
endmodule

powered by: WebSVN 2.1.0

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