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

Subversion Repositories ahb2wishbone

[/] [ahb2wishbone/] [trunk/] [bench/] [ahb2wb_tb.v] - Blame information for rev 11

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

Line No. Rev Author Line
1 2 toomuch
 
2
// Copyright (c) 2007 TooMuch Semiconductor Solutions Pvt Ltd.
3
 
4
 
5
//File name             :       ahb2wb_tb.v
6
//Designer              :       Manish Agarwal
7
//Date                  :       18 May, 2007
8
//Description   :       Test bench for AHB-Wishbone BRIDGE 
9
//Revision              :       1.0
10
 
11
 
12
//******************************************************************************************************
13
 
14
`include "../src/ahb2wb.v"
15
 
16
 
17
module ahb2wb_tb  ;
18
 
19
parameter DWIDTH =32;
20
parameter TON   = 5;
21
parameter TOFF  = 5 ;
22
parameter AWIDTH  = 16 ;
23
 
24
integer  address = 0;
25
integer data = 0;
26
 
27
  reg  [1:0]  htrans   ;
28
  reg  [DWIDTH-1:0]  dat_i   ;
29
  reg    hresetn   ;
30
  reg    hclk   ;
31
  reg    hwrite   ;
32
 
33
  wire  [DWIDTH-1:0]  hrdata   ;
34
  reg    hsel   ;
35
  wire    hready   ;
36
  wire  [DWIDTH-1:0]  dat_o   ;
37
  reg    ack_i   ;
38
  reg  [2:0]  hburst   ;
39
  reg  [DWIDTH-1:0]  hwdata   ;
40
  wire  [1:0]  hresp   ;
41
 
42
  wire    we_o   ;
43
  reg  [2:0]  hsize   ;
44
  reg  [AWIDTH-1:0]  haddr   ;
45
  wire  [AWIDTH-1:0]  adr_o   ;
46
  wire    cyc_o   ;
47
  wire    stb_o   ;
48
 
49
//module instantiation
50
 
51
  ahb2wb
52
   DUT  (
53
       .htrans (htrans ) ,
54
      .dat_i (dat_i ) ,
55
      .hresetn (hresetn ) ,
56
      .hclk (hclk ) ,
57
      .hwrite (hwrite ) ,
58
      .hrdata (hrdata ) ,
59
      .hsel (hsel ) ,
60
      .hready (hready ) ,
61
      .dat_o (dat_o ) ,
62
      .ack_i (ack_i ) ,
63
      .hburst (hburst ) ,
64
      .hwdata (hwdata ) ,
65
      .hresp (hresp ) ,
66
      .we_o (we_o ) ,
67
      .hsize (hsize ) ,
68
      .haddr (haddr ) ,
69
      .adr_o (adr_o ) ,
70
      .cyc_o (cyc_o ) ,
71
      .stb_o (stb_o ),
72
          .clk_i(),
73
          .rst_i());
74
 
75
// local memory in wishbone slave model
76
        reg [DWIDTH-1 : 0] wb_mem [AWIDTH-1 : 0];
77
 
78
 
79
//*************************************************
80
// Wishbone slave model
81
//*************************************************
82
 
83
        always @(stb_o or we_o or adr_o or dat_o) begin
84
 
85
                ack_i = 'b1;
86
 
87
                if (!stb_o) begin
88
                         ack_i = #2 'b0;
89
                end
90
 
91
                if (we_o) begin
92
                        wb_mem[adr_o] = dat_o;                                  // data stored in wb slave
93
                end
94
                else begin
95
                        dat_i = wb_mem[adr_o];
96
                end
97
 
98
        end
99
 
100
 
101
 
102
// Reset operation --as per wishbone requirement
103
        initial begin
104
                hresetn = 'b1;
105
                #3
106
                hresetn = 'b0;
107
                #10
108
                @(posedge hclk)
109
                hresetn = 'b1;
110
        end
111
 
112
 
113
// Clock operation
114
        always begin
115
                #TOFF
116
                hclk = 'b0;
117
                #TON
118
                hclk = 'b1;
119
        end
120
 
121
 
122
// signal states
123
        initial begin
124
                // deassertions
125
                htrans = 'b00;                                                          // default value - idle 
126
                @(negedge hresetn)
127
                @(posedge hclk) #1 hsel = 'b0;
128
 
129
                // assertions
130
                @(posedge hresetn)
131
                @(posedge hclk) #2 hsel = 'b1;
132
                ack_i = 'b0;
133
                hsize = 'b010;                                                          // 32 bit size (word transfer)
134
                hburst = 'b000;                                                         // single transfer
135
 
136
//*************************************
137
//Write cycle
138
//*************************************
139
                repeat(4) ahb_write;
140
 
141
// wait state inserted by wishbone slave
142
                #2 ack_i = 'b0;
143
 
144
                repeat(4) ahb_write;
145
 
146
                #2 ack_i = 'b1;
147
 
148
                repeat(4) ahb_write;
149
 
150
// wait state inserted by master AHB
151
 
152
                #2
153
                htrans = 'b01;
154
                #20
155
                htrans = 'b10;
156
 
157
                repeat(4) ahb_write;
158
 
159
// wait state inserted by master AHB
160
                #2
161
                htrans = 'b01;
162
                #20
163
                htrans = 'b10;
164
 
165
 
166
//*************************************
167
//Read cycle
168
//*************************************
169
                repeat(6) ahb_read;
170
 
171
// wait state inserted by master AHB
172
                #2
173
                htrans = 'b01;
174
                #20
175
                htrans = 'b10;
176
 
177
                repeat(3) ahb_read;
178
 
179
// wait state inserted by wishbone slave
180
                #2 ack_i = 'b0;
181
 
182
                repeat(3) ahb_read;
183
 
184
                #2 ack_i = 'b1;
185
 
186
 
187
//*************************************
188
//write cycle
189
//*************************************
190
                repeat(4) ahb_write;
191
 
192
                htrans = 'b00;          // bus idle
193
                #100 $stop;
194
        end
195
 
196
 
197
 
198
//*****************************************
199
//AHB  write cycle (master model)
200
//*****************************************
201
 
202
task ahb_write;
203
        begin
204
                @(posedge hclk) begin
205
                        if (hready) begin
206
                                #2
207
                                htrans = 'b10;                                          // non sequential transfer
208
                                address = address + 1;
209
                                hwrite = 'b1;
210
                                haddr =  address;                                       // address of current address phase
211
                                hwdata = data;                                          // data of previous address phase
212
                                data = data +1;
213
                        end
214
                end
215
        end
216
endtask
217
 
218
 
219
//*********************************************
220
// AHB read cycle (master model)
221
//*********************************************
222
 
223
task ahb_read;
224
        begin
225
                @(posedge hclk) begin
226
                        if (hready) begin
227
                                #2
228
                                htrans = 'b10;                                                          // non sequential transfer
229
                                hwrite = 'b0;
230
                                haddr = address;
231
                                address = address-1;
232
                        end
233
                end
234
        end
235
endtask
236
 
237
 
238
 
239
endmodule
240
 
241
 

powered by: WebSVN 2.1.0

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