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

Subversion Repositories wf3d

[/] [wf3d/] [trunk/] [scenario/] [3d/] [sram_slave_wb.v] - Blame information for rev 9

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 specular
//=======================================================================
2
// Project Monophony
3
//   Wire-Frame 3D Graphics Accelerator IP Core
4
//
5
// File:
6
//   sram_slave_wb.v
7
//
8
// Abstract:
9
//   SRAM slave model with random read data delay.
10
//   for WISHBONE bus simulation
11
// Author:
12 9 specular
//   Kenji Ishimaru (info.info.wf3d@gmail.com)
13 2 specular
//
14
//======================================================================
15
//
16
// Copyright (c) 2015, Kenji Ishimaru
17
// All rights reserved.
18
//
19
// Redistribution and use in source and binary forms, with or without
20
// modification, are permitted provided that the following conditions are met:
21
//
22
//  -Redistributions of source code must retain the above copyright notice,
23
//   this list of conditions and the following disclaimer.
24
//  -Redistributions in binary form must reproduce the above copyright notice,
25
//   this list of conditions and the following disclaimer in the documentation
26
//   and/or other materials provided with the distribution.
27
//
28
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
30
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
31
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
32
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
33
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
34
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
35
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
36
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
37
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
38
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39
//
40
// Revision History
41
 
42
module sram_slave_wb #(
43
  parameter P_ADRS_WIDTH = 24,
44
  parameter P_BE_WIDTH   = 4,
45
  parameter P_DATA_WIDTH = 32,
46
  parameter P_BLEN_WIDTH = 6,
47
  parameter P_SEED = 'd0
48
)
49
  (
50
    input clk_core,
51
    input rst_x,
52
    input i_req,
53
    input i_wr,
54
    input [P_ADRS_WIDTH-1:0] i_adrs,
55
    input [P_BLEN_WIDTH-1:0] i_blen,
56
    output o_ack,
57
    input i_strw,
58
    input [P_BE_WIDTH-1:0]   i_be,
59
    input [P_DATA_WIDTH-1:0] i_dbw,
60
    output o_ackw,
61
    output o_strr,
62
    output [P_DATA_WIDTH-1:0] o_dbr
63
 );
64
 
65
//////////////////////////////////
66
// parameter
67
//////////////////////////////////
68
  localparam P_IDLE     = 2'h0;
69
  localparam P_IN_WRITE = 2'h1;
70
  localparam P_IN_READ  = 2'h2;
71
 
72
  localparam P_READ_DELAY  = 'd15;
73
 
74
//////////////////////////////////
75
// wire 
76
//////////////////////////////////
77
    wire           w_req;
78
    wire [29:0]
79
                   w_fifo_cin;
80
    wire [29:0]
81
                   w_fifo_cout;
82
    wire [32+4-1:0]
83
                   w_fifo_din;
84
    wire [32+4-1:0]
85
                   w_fifo_dout;
86
    wire           w_cfifo_ack;
87
    wire           w_dfifo_ack;
88
    wire           w_read_req;
89
    wire [1:0]     w_mcmd_f;
90
    wire [P_ADRS_WIDTH-1:0]
91
                   w_maddr_f;
92
    wire [P_BLEN_WIDTH-1:0]
93
                   w_mburst_length_f;
94
    wire           w_command_valid;
95
    wire           w_burst_end;
96
    wire [P_ADRS_WIDTH-1:0]
97
                   w_sram_addr;
98
    wire [P_BE_WIDTH-1:0]
99
                   w_sram_byte_en;
100
    wire [P_DATA_WIDTH-1:0]
101
                   w_sram_wdata;
102
    wire [P_DATA_WIDTH-1:0]
103
                   w_sram_rdata;
104
    wire           w_sram_write;
105
    wire           w_datain_valid;
106
    wire           w_dfifi_idle_ack;
107
    wire [P_DATA_WIDTH-1:0] w_dbr;
108
    wire           w_act;
109
//////////////////////////////////
110
// reg 
111
//////////////////////////////////
112
    reg  [1:0]     r_state;
113
    reg  [P_ADRS_WIDTH-1:0]
114
                   r_maddr;
115
    reg  [P_BLEN_WIDTH-1:0]
116
                   r_mburst_length;
117
    reg            r_read_req_1z;
118
    reg            r_read_req_2z;
119
    reg [7:0]       r_rand;
120
    reg [7:0]       r_rand_rd;
121
    reg [31:0]      r_rand_seed;
122
    reg [31:0]      r_rand_rd_seed;
123
    wire           w_ack;
124
 
125
//////////////////////////////////
126
// assign 
127
//////////////////////////////////
128
    assign w_sram_addr = (r_state == P_IDLE) ? i_adrs : r_maddr;
129
    assign w_sram_write = ((r_state == P_IN_WRITE)&i_strw);
130
    assign w_ack = (r_state == P_IDLE) & w_act;
131
    assign o_ack = (r_state == P_IN_WRITE) | ((r_state == P_IN_READ) & o_strr);
132
 
133
    assign o_ackw = 1'b1;
134
    assign  w_read_req = (i_req & !i_wr & w_ack & w_act) ;
135
    assign w_act = (r_rand < 'h80);
136
//////////////////////////////////
137
// always 
138
//////////////////////////////////
139
 
140
  initial begin
141
    $display("RANDOM SEED = %d %m",P_SEED);
142
    r_rand_seed = P_SEED;
143
    r_rand_rd_seed = P_SEED;
144
  end
145
  always @(negedge clk_core) begin
146
    r_rand <= $random(r_rand_seed);
147
    //r_rand <= 1;
148
  end
149
 
150
  always @(posedge clk_core or negedge rst_x) begin
151
    if (~rst_x) begin
152
      r_state <= P_IDLE;
153
    end else begin
154
      case (r_state)
155
        P_IDLE : begin
156
          if (i_req & w_act) begin
157
           if (i_wr == 'd1) begin
158
             r_state <= P_IN_WRITE;
159
           end else begin
160
             //r_rand_rd <= 0;
161
             r_rand_rd <= $random(r_rand_rd_seed);
162
             r_state <= P_IN_READ;
163
           end
164
         end
165
       end
166
       P_IN_WRITE : begin
167
         if (i_strw) r_state <= P_IDLE;
168
       end
169
       P_IN_READ : begin
170
         if (o_strr) r_state <= P_IDLE;
171
       end
172
     endcase
173
   end
174
 end
175
 
176
always @(posedge clk_core) begin
177
  if ((r_state == P_IDLE)&i_req & w_act) begin
178
    r_maddr <= i_adrs;
179
  end
180
end
181
 
182
 
183
  always @(posedge clk_core or negedge rst_x) begin
184
    if (~rst_x) begin
185
      r_read_req_1z <= 1'b0;
186
      r_read_req_2z <= 1'b0;
187
    end else begin
188
      r_read_req_1z <= w_read_req;
189
      r_read_req_2z <= r_read_req_1z;
190
    end
191
  end
192
 
193
//////////////////////////////////
194
// module instantiation
195
//////////////////////////////////
196
// delay module
197
 
198
rand_delay # (1,16) u_delay_strr (
199
  .clk_core(clk_core),
200
  .rst_x(rst_x),
201
  .i_en(r_read_req_2z),
202
  .i_delay(r_rand_rd),
203
  .i_data(r_read_req_2z),
204
  .o_data(),
205
  .o_en(o_strr)
206
);
207
 
208
rand_delay #(P_DATA_WIDTH,16) u_delay_dbr (
209
  .clk_core(clk_core),
210
  .rst_x(rst_x),
211
  .i_en(r_read_req_2z),
212
  .i_delay(r_rand_rd),
213
  .i_data(w_dbr),
214
  .o_data(o_dbr),
215
  .o_en()
216
);
217
 
218
 
219
memory_sram #(P_ADRS_WIDTH) u_memory (
220
  .clk(clk_core),
221
  .adr(w_sram_addr),
222
  .din(i_dbw),
223
  .be(i_be),
224
  .dout(w_dbr),
225
  .rdb(~w_read_req),
226
  .wrb(~w_sram_write),
227
  .rstb(rst_x)
228
);
229
 
230
endmodule

powered by: WebSVN 2.1.0

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