OpenCores
URL https://opencores.org/ocsvn/an-fpga-implementation-of-low-latency-noc-based-mpsoc/an-fpga-implementation-of-low-latency-noc-based-mpsoc/trunk

Subversion Repositories an-fpga-implementation-of-low-latency-noc-based-mpsoc

[/] [an-fpga-implementation-of-low-latency-noc-based-mpsoc/] [trunk/] [mpsoc/] [src_c/] [jtag/] [test_rtl/] [jtag_ram_test/] [src_verilog/] [lib/] [wb_single_port_ram.v] - Blame information for rev 38

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

Line No. Rev Author Line
1 38 alirezamon
/**********************************************************************
2
**      File:  wb_dual_port_ram.v
3
**
4
**
5
**      Copyright (C) 2014-2017  Alireza Monemi
6
**
7
**      This file is part of ProNoC
8
**
9
**      ProNoC ( stands for Prototype Network-on-chip)  is free software:
10
**      you can redistribute it and/or modify it under the terms of the GNU
11
**      Lesser General Public License as published by the Free Software Foundation,
12
**      either version 2 of the License, or (at your option) any later version.
13
**
14
**      ProNoC is distributed in the hope that it will be useful, but WITHOUT
15
**      ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16
**      or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General
17
**      Public License for more details.
18
**
19
**      You should have received a copy of the GNU Lesser General Public
20
**      License along with ProNoC. If not, see <http:**www.gnu.org/licenses/>.
21
**
22
**
23
**      Description:
24
**      wishbone based single port ram
25
**
26
**
27
*******************************************************************/
28
 
29
 
30
`timescale 1ns / 1ps
31
 
32
 
33
 
34
module wb_single_port_ram #(
35
    parameter Dw=32, //RAM data_width in bits
36
    parameter Aw=10, //RAM address width
37
    parameter BYTE_WR_EN= "YES",//"YES","NO"
38
    parameter FPGA_VENDOR= "ALTERA",//"ALTERA","GENERIC"
39
    parameter JTAG_CONNECT= "JTAG_WB",//"DISABLED", "JTAG_WB" , "ALTERA_IMCE", if not disabled then the actual memory implements as a dual port RAM with the second port is connected either to In-System Memory Content Editor or Jtag_to_wb  
40
    parameter JTAG_INDEX= 0,
41
    parameter INITIAL_EN= "NO",
42
    parameter MEM_CONTENT_FILE_NAME= "ram0",// ram initial file name
43
    parameter INIT_FILE_PATH = "path_to/sw", // The sw folder path. It will be used for finding initial file. The path will be rewriten by the top module. 
44
    // wishbon bus param
45
    parameter   BURST_MODE= "DISABLED", // "DISABLED" , "ENABLED" wisbone bus burst mode 
46
    parameter   TAGw   =   3,
47
    parameter   SELw   =   Dw/8,
48
    parameter   CTIw   =   3,
49
    parameter   BTEw   =   2
50
 
51
 
52
    )
53
    (
54
        clk,
55
        reset,
56
 
57
        //wishbone bus interface
58
        sa_dat_i,
59
        sa_sel_i,
60
        sa_addr_i,
61
        sa_tag_i,
62
        sa_cti_i,
63
        sa_bte_i,
64
        sa_stb_i,
65
        sa_cyc_i,
66
        sa_we_i,
67
        sa_dat_o,
68
        sa_ack_o,
69
        sa_err_o,
70
        sa_rty_o
71
 
72
    );
73
 
74
 
75
 
76
 
77
    input                  clk;
78
    input                  reset;
79
 
80
 
81
 
82
 
83
     //wishbone bus interface
84
    input       [Dw-1       :   0]      sa_dat_i;
85
    input       [SELw-1     :   0]      sa_sel_i;
86
    input       [Aw-1       :   0]      sa_addr_i;
87
    input       [TAGw-1     :   0]      sa_tag_i;
88
    input                               sa_stb_i;
89
    input                               sa_cyc_i;
90
    input                               sa_we_i;
91
    input       [CTIw-1     :   0]      sa_cti_i;
92
    input       [BTEw-1     :   0]      sa_bte_i;
93
 
94
    output      [Dw-1       :   0]      sa_dat_o;
95
    output                              sa_ack_o;
96
    output                              sa_err_o;
97
    output                              sa_rty_o;
98
 
99
 
100
    wire            [Dw-1   :   0]   d;
101
    wire            [Aw-1   :   0]   addr;
102
    wire                             we;
103
    wire            [Dw-1   :   0]  q;
104
 
105
 
106
 
107
 
108
        localparam MEM_NAME = (FPGA_VENDOR== "ALTERA")? {MEM_CONTENT_FILE_NAME,".mif"} :
109
                                                        {MEM_CONTENT_FILE_NAME,".hex"}; //Generic
110
 
111
 
112
        localparam INIT_FILE =  {INIT_FILE_PATH,"/RAM/",MEM_NAME};
113
 
114
 
115
    wb_bram_ctrl #(
116
        .Dw(Dw),
117
        .Aw(Aw),
118
        .BURST_MODE(BURST_MODE),
119
        .SELw(SELw),
120
        .CTIw(CTIw),
121
        .BTEw(BTEw)
122
    )
123
   ctrl
124
   (
125
        .clk(clk),
126
        .reset(reset),
127
        .d(d),
128
        .addr(addr),
129
        .we(we),
130
        .q(q),
131
        .sa_dat_i(sa_dat_i),
132
        .sa_sel_i(sa_sel_i),
133
        .sa_addr_i(sa_addr_i),
134
        .sa_stb_i(sa_stb_i),
135
        .sa_cyc_i(sa_cyc_i),
136
        .sa_we_i(sa_we_i),
137
        .sa_cti_i(sa_cti_i),
138
        .sa_bte_i(sa_bte_i),
139
        .sa_dat_o(sa_dat_o),
140
        .sa_ack_o(sa_ack_o),
141
        .sa_err_o(sa_err_o),
142
        .sa_rty_o(sa_rty_o)
143
   );
144
 
145
 
146
 
147
 
148
 
149
    single_port_ram_top #(
150
        .Dw(Dw),
151
        .Aw(Aw),
152
        .BYTE_WR_EN(BYTE_WR_EN),
153
        .FPGA_VENDOR(FPGA_VENDOR),
154
        .JTAG_CONNECT(JTAG_CONNECT),
155
        .JTAG_INDEX(JTAG_INDEX),
156
        .INITIAL_EN(INITIAL_EN),
157
        .INIT_FILE(INIT_FILE)
158
    )
159
    ram_top
160
    (
161
        .reset(reset),
162
        .clk(clk),
163
        .data_a(d),
164
        .addr_a(addr),
165
        .we_a(we),
166
        .q_a(q),
167
        .byteena_a(sa_sel_i)
168
    );
169
 
170
 
171
endmodule
172
 
173
 
174
 
175
 
176
 
177
 
178
 
179
 
180
 
181
 
182
 
183
 
184
 
185
 
186
 
187
 
188
 
189
 
190
module single_port_ram_top #(
191
    parameter Dw=32, //RAM data_width in bits
192
    parameter Aw=10, //RAM address width
193
    parameter BYTE_WR_EN= "YES",//"YES","NO"
194
    parameter FPGA_VENDOR= "ALTERA",//"ALTERA","GENERIC"
195
    parameter JTAG_CONNECT= "JTAG_WB",//"DISABLED", "JTAG_WB" , "ALTERA_IMCE", if not disabled then the actual memory implements as a dual port RAM with the second port is connected either to In-System Memory Content Editor or Jtag_to_wb  
196
    parameter JTAG_INDEX= 0,
197
    parameter INITIAL_EN= "NO",
198
    parameter INIT_FILE= "sw/ram/ram0.txt"// ram initial file 
199
 
200
    )
201
    (
202
        reset,
203
        clk,
204
        data_a,
205
        addr_a,
206
        byteena_a,
207
        we_a,
208
        q_a
209
);
210
  localparam  BYTE_ENw= ( BYTE_WR_EN == "YES")? Dw/8 : 1;
211
 
212
input                           clk,reset;
213
input  [Dw-1   :   0]  data_a;
214
input  [Aw-1   :   0]  addr_a;
215
input                     we_a;
216
input  [BYTE_ENw-1   :   0] byteena_a;
217
output [Dw-1    :   0]  q_a;
218
 
219
 
220
 
221
    function   [15:0]i2s;
222
        input   integer c;  integer i;  integer tmp; begin
223
        tmp =0;
224
        for (i=0; i<2; i=i+1'b1) begin
225
            tmp = tmp + (((c % 10)   + 6'd48) << i*8);
226
            c = c/10;
227
        end
228
        i2s = tmp[15:0];
229
        end
230
    endfunction //i2s
231
 
232
    function integer log2;
233
        input integer number; begin
234
        log2=0;
235
        while(2**log2<number) begin
236
             log2=log2+1;
237
        end
238
        end
239
    endfunction // log2 
240
 
241
 
242
 
243
 
244
 
245
 
246
wire            [Dw-1   :   0]   data_b;
247
wire            [Aw-1   :   0]   addr_b;
248
wire                             we_b;
249
wire            [Dw-1   :   0]  q_b;
250
 
251
 
252
 
253
 
254
generate
255
if(FPGA_VENDOR=="ALTERA")begin:altera_fpga
256
 localparam  RAM_TAG_STRING=i2s(JTAG_INDEX);
257
localparam  RAM_ID =(JTAG_CONNECT== "ALTERA_IMCE") ?  {"ENABLE_RUNTIME_MOD=YES,INSTANCE_NAME=",RAM_TAG_STRING}
258
                                    : {"ENABLE_RUNTIME_MOD=NO"};
259
 
260
    if(JTAG_CONNECT== "JTAG_WB")begin:dual_ram
261
// aletra dual port ram 
262
        altsyncram #(
263
            .operation_mode("BIDIR_DUAL_PORT"),
264
            .address_reg_b("CLOCK0"),
265
            .wrcontrol_wraddress_reg_b("CLOCK0"),
266
            .indata_reg_b("CLOCK0"),
267
            .outdata_reg_a("UNREGISTERED"),
268
            .outdata_reg_b("UNREGISTERED"),
269
            .width_a(Dw),
270
            .width_b(Dw),
271
            .lpm_hint(RAM_ID),
272
            .read_during_write_mode_mixed_ports("DONT_CARE"),
273
            .widthad_a(Aw),
274
            .widthad_b(Aw),
275
            .width_byteena_a(BYTE_ENw),
276
            .init_file(INIT_FILE)
277
 
278
        ) ram_inst(
279
            .clock0         (clk),
280
 
281
            .address_a      (addr_a),
282
            .wren_a         (we_a),
283
            .data_a         (data_a),
284
            .q_a            (q_a),
285
            .byteena_a      (byteena_a),
286
 
287
 
288
            .address_b      (addr_b),
289
            .wren_b         (we_b),
290
            .data_b         (data_b),
291
            .q_b            (q_b),
292
            .byteena_b      (1'b1),
293
 
294
 
295
            .rden_a         (1'b1),
296
            .rden_b         (1'b1),
297
            .clock1         (1'b1),
298
            .clocken0       (1'b1),
299
            .clocken1       (1'b1),
300
            .clocken2       (1'b1),
301
            .clocken3       (1'b1),
302
            .aclr0          (1'b0),
303
            .aclr1          (1'b0),
304
            .addressstall_a     (1'b0),
305
            .addressstall_b     (1'b0),
306
            .eccstatus      (    )
307
 
308
        );
309
 
310
    // jtag_wb
311
    end else begin:  single_ram //JTAG_CONNECT= "DISABLED", "ALTERA_IMCE"
312
 
313
 
314
 
315
        altsyncram #(
316
            .operation_mode("SINGLE_PORT"),
317
            .width_a(Dw),
318
            .lpm_hint(RAM_ID),
319
            .read_during_write_mode_mixed_ports("DONT_CARE"),
320
            .widthad_a(Aw),
321
            .width_byteena_a(BYTE_ENw),
322
            .init_file(INIT_FILE)
323
        )
324
        ram_inst
325
        (
326
            .clock0         (clk),
327
            .address_a      (addr_a),
328
            .wren_a         (we_a),
329
            .data_a         (data_a),
330
            .q_a            (q_a),
331
            .byteena_a      (byteena_a),
332
 
333
            .wren_b         (    ),
334
            .rden_a         (    ),
335
            .rden_b         (    ),
336
            .data_b         (    ),
337
            .address_b      (    ),
338
            .clock1         (    ),
339
            .clocken0       (    ),
340
            .clocken1       (    ),
341
            .clocken2       (    ),
342
            .clocken3       (    ),
343
            .aclr0          (    ),
344
            .aclr1          (    ),
345
            .byteena_b      (    ),
346
            .addressstall_a     (    ),
347
            .addressstall_b     (    ),
348
            .q_b            (    ),
349
            .eccstatus      (    )
350
        );
351
 
352
    end
353
end
354
 
355
else if(FPGA_VENDOR=="GENERIC")begin:generic_ram
356
    if(JTAG_CONNECT== "JTAG_WB")begin:dual_ram
357
 
358
 
359
        generic_dual_port_ram #(
360
            .Dw(Dw),
361
            .Aw(Aw),
362
            .BYTE_WR_EN(BYTE_WR_EN),
363
            .INITIAL_EN(INITIAL_EN),
364
            .INIT_FILE(INIT_FILE)
365
        )
366
        ram_inst
367
        (
368
            .data_a     (data_a),
369
            .data_b     (data_b),
370
            .addr_a     (addr_a),
371
            .addr_b     (addr_b),
372
            .byteena_a  (byteena_a ),
373
            .byteena_b  ({BYTE_ENw{1'b1}}),
374
            .we_a       (we_a),
375
            .we_b       (we_b),
376
            .clk        (clk),
377
            .q_a        (q_a),
378
            .q_b        (q_b)
379
 
380
        );
381
 
382
 
383
    end else begin
384
 
385
 
386
 
387
        generic_single_port_ram #(
388
            .Dw(Dw),
389
            .Aw(Aw),
390
            .BYTE_WR_EN(BYTE_WR_EN),
391
            .INITIAL_EN(INITIAL_EN),
392
            .INIT_FILE(INIT_FILE)
393
        )
394
        ram_inst
395
        (
396
            .data     (data_a),
397
            .addr     (addr_a),
398
            .byteen   (byteena_a ),
399
            .we       (we_a),
400
            .clk      (clk),
401
            .q        (q_a)
402
 
403
        );
404
 
405
    end//jtag_wb
406
end //Generic
407
 
408
 
409
if(JTAG_CONNECT == "JTAG_WB")begin:jtag_wb
410
 
411
    reg jtag_ack;
412
    wire    jtag_we_o, jtag_stb_o;
413
 
414
    localparam Sw= log2(Aw+1);
415
    localparam [Sw-1    :   0] ST = Aw;
416
    vjtag_wb #(
417
        .VJTAG_INDEX(JTAG_INDEX),
418
        .DW(Dw),
419
        .AW(Aw),
420
        .SW(Sw),
421
 
422
        //wishbone port parameters
423
            .M_Aw(Aw),
424
            .TAGw(3)
425
    )
426
    vjtag_inst
427
    (
428
        .clk(clk),
429
        .reset(reset),
430
        .status_i(ST), // Jtag can read memory size as status
431
         //wishbone master interface signals
432
        .m_sel_o(),
433
        .m_dat_o(data_b),
434
        .m_addr_o(addr_b),
435
        .m_cti_o(),
436
        .m_stb_o(jtag_stb_o),
437
        .m_cyc_o(),
438
        .m_we_o(jtag_we_o),
439
        .m_dat_i(q_b),
440
        .m_ack_i(jtag_ack)
441
 
442
    );
443
 
444
    assign we_b = jtag_stb_o & jtag_we_o;
445
 
446
    always @(posedge clk )begin
447
        jtag_ack<=jtag_stb_o;
448
    end
449
end//jtag_wb
450
 
451
endgenerate
452
 
453
 
454
 
455
endmodule
456
 
457
 
458
 
459
 
460
 
461
 
462
 
463
 
464
 

powered by: WebSVN 2.1.0

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