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

Subversion Repositories wf3d

[/] [wf3d/] [trunk/] [scenario/] [3d/] [sram_slave.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.v
7
//
8
// Abstract:
9
//   SRAM slave model with random read data delay.
10
//
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 #(
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_clength;
117
    reg  [P_BLEN_WIDTH-1:0]
118
                   r_mburst_length;
119
    reg            r_read_req_1z;
120
    reg            r_read_req_2z;
121
    reg [7:0]       r_rand;
122
    reg [7:0]       r_rand_rd;
123
    reg [31:0]      r_rand_seed;
124
    reg [31:0]      r_rand_rd_seed;
125
//////////////////////////////////
126
// assign 
127
//////////////////////////////////
128
//    assign o_strr = r_read_req_2z;
129
    assign w_burst_end = (r_mburst_length == r_clength);
130
    assign w_sram_addr = (r_state == P_IDLE) ? i_adrs : r_maddr;
131
    assign w_sram_write = ((r_state == P_IN_WRITE)&i_strw) |
132
                               (i_req & i_wr & o_ack &  w_act);
133
    assign o_ack = (r_state == P_IDLE) & w_act;
134
    assign o_ackw = 1'b1;
135
    assign  w_read_req = (i_req & !i_wr & o_ack & w_act) | (r_state == P_IN_READ);
136
    assign w_act = (r_rand < 'h80);
137
//////////////////////////////////
138
// always 
139
//////////////////////////////////
140
 
141
  initial begin
142
    $display("RANDOM SEED = %d %m",P_SEED);
143
    r_rand_seed = P_SEED;
144
    r_rand_rd_seed = P_SEED;
145
  end
146
  always @(negedge clk_core) begin
147
    r_rand <= $random(r_rand_seed);
148
    //r_rand <= 1;
149
  end
150
 
151
  always @(posedge clk_core or negedge rst_x) begin
152
    if (~rst_x) begin
153
      r_state <= P_IDLE;
154
    end else begin
155
      case (r_state)
156
        P_IDLE : begin
157
          if (i_req & (i_blen != 'd1) & w_act) begin
158
           if (i_wr == 'd1) begin
159
             r_state <= P_IN_WRITE;
160
           end else begin
161
             r_rand_rd <= $random(r_rand_rd_seed);
162
             //r_rand_rd <= 0;
163
             r_state <= P_IN_READ;
164
           end
165
         end
166
       end
167
       P_IN_WRITE : begin
168
         if ((w_burst_end)&i_strw) r_state <= P_IDLE;
169
       end
170
       P_IN_READ : begin
171
         if (w_burst_end) r_state <= P_IDLE;
172
       end
173
     endcase
174
   end
175
 end
176
 
177
always @(posedge clk_core) begin
178
  if ((r_state == P_IDLE)&i_req & w_act) begin
179
    r_maddr <= i_adrs + 1'b1;
180
    r_mburst_length <= i_blen;
181
    r_clength <= 'd2;
182
  end else if (r_state == P_IN_WRITE) begin
183
    if (i_strw) begin
184
      r_maddr <= r_maddr + 1'b1;
185
      r_clength <= r_clength + 1'b1;
186
    end
187
  end else begin
188
    r_maddr <= r_maddr + 1'b1;
189
    r_clength <= r_clength + 1'b1;
190
  end
191
end
192
 
193
 
194
  always @(posedge clk_core or negedge rst_x) begin
195
    if (~rst_x) begin
196
      r_read_req_1z <= 1'b0;
197
      r_read_req_2z <= 1'b0;
198
    end else begin
199
      r_read_req_1z <= w_read_req;
200
      r_read_req_2z <= r_read_req_1z;
201
    end
202
  end
203
 
204
//////////////////////////////////
205
// module instantiation
206
//////////////////////////////////
207
// delay module
208
 
209
rand_delay # (1,16) u_delay_strr (
210
  .clk_core(clk_core),
211
  .rst_x(rst_x),
212
  .i_en(r_read_req_2z),
213
  .i_delay(r_rand_rd),
214
  .i_data(r_read_req_2z),
215
  .o_data(),
216
  .o_en(o_strr)
217
);
218
 
219
rand_delay #(P_DATA_WIDTH,16) u_delay_dbr (
220
  .clk_core(clk_core),
221
  .rst_x(rst_x),
222
  .i_en(r_read_req_2z),
223
  .i_delay(r_rand_rd),
224
  .i_data(w_dbr),
225
  .o_data(o_dbr),
226
  .o_en()
227
);
228
 
229
 
230
memory_sram #(P_ADRS_WIDTH)  u_memory (
231
  .clk(clk_core),
232
  .adr(w_sram_addr),
233
  .din(i_dbw),
234
  .be(i_be),
235
  .dout(w_dbr),
236
  .rdb(~w_read_req),
237
  .wrb(~w_sram_write),
238
  .rstb(rst_x)
239
);
240
 
241
endmodule

powered by: WebSVN 2.1.0

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