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 48

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 48 alirezamon
    parameter JTAG_CONNECT= "ALTERA_JTAG_WB",//"DISABLED", "ALTERA_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 38 alirezamon
    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 48 alirezamon
    parameter JTAG_CONNECT= "ALTERA_JTAG_WB",//"DISABLED", "ALTERA_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 38 alirezamon
    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 48 alirezamon
  /* verilator lint_off WIDTH */
211 38 alirezamon
  localparam  BYTE_ENw= ( BYTE_WR_EN == "YES")? Dw/8 : 1;
212 48 alirezamon
  /* verilator lint_on WIDTH */
213 38 alirezamon
 
214
input                           clk,reset;
215
input  [Dw-1   :   0]  data_a;
216
input  [Aw-1   :   0]  addr_a;
217
input                     we_a;
218
input  [BYTE_ENw-1   :   0] byteena_a;
219
output [Dw-1    :   0]  q_a;
220
 
221
 
222
 
223
    function   [15:0]i2s;
224
        input   integer c;  integer i;  integer tmp; begin
225
        tmp =0;
226
        for (i=0; i<2; i=i+1'b1) begin
227
            tmp = tmp + (((c % 10)   + 6'd48) << i*8);
228
            c = c/10;
229
        end
230
        i2s = tmp[15:0];
231
        end
232
    endfunction //i2s
233
 
234
    function integer log2;
235
        input integer number; begin
236
        log2=0;
237
        while(2**log2<number) begin
238
             log2=log2+1;
239
        end
240
        end
241
    endfunction // log2 
242
 
243
 
244
 
245
 
246
 
247
 
248
wire            [Dw-1   :   0]   data_b;
249
wire            [Aw-1   :   0]   addr_b;
250
wire                             we_b;
251
wire            [Dw-1   :   0]  q_b;
252
 
253
 
254
 
255
 
256
generate
257 48 alirezamon
/* verilator lint_off WIDTH */
258 38 alirezamon
if(FPGA_VENDOR=="ALTERA")begin:altera_fpga
259 48 alirezamon
/* verilator lint_on WIDTH */
260 38 alirezamon
 localparam  RAM_TAG_STRING=i2s(JTAG_INDEX);
261
localparam  RAM_ID =(JTAG_CONNECT== "ALTERA_IMCE") ?  {"ENABLE_RUNTIME_MOD=YES,INSTANCE_NAME=",RAM_TAG_STRING}
262
                                    : {"ENABLE_RUNTIME_MOD=NO"};
263 48 alirezamon
    /* verilator lint_off WIDTH */
264
    if(JTAG_CONNECT== "ALTERA_JTAG_WB")begin:dual_ram
265
    /* verilator lint_on WIDTH */
266 38 alirezamon
// aletra dual port ram 
267
        altsyncram #(
268
            .operation_mode("BIDIR_DUAL_PORT"),
269
            .address_reg_b("CLOCK0"),
270
            .wrcontrol_wraddress_reg_b("CLOCK0"),
271
            .indata_reg_b("CLOCK0"),
272
            .outdata_reg_a("UNREGISTERED"),
273
            .outdata_reg_b("UNREGISTERED"),
274
            .width_a(Dw),
275
            .width_b(Dw),
276
            .lpm_hint(RAM_ID),
277
            .read_during_write_mode_mixed_ports("DONT_CARE"),
278
            .widthad_a(Aw),
279
            .widthad_b(Aw),
280
            .width_byteena_a(BYTE_ENw),
281
            .init_file(INIT_FILE)
282
 
283
        ) ram_inst(
284
            .clock0         (clk),
285
 
286
            .address_a      (addr_a),
287
            .wren_a         (we_a),
288
            .data_a         (data_a),
289
            .q_a            (q_a),
290
            .byteena_a      (byteena_a),
291
 
292
 
293
            .address_b      (addr_b),
294
            .wren_b         (we_b),
295
            .data_b         (data_b),
296
            .q_b            (q_b),
297
            .byteena_b      (1'b1),
298
 
299
 
300
            .rden_a         (1'b1),
301
            .rden_b         (1'b1),
302
            .clock1         (1'b1),
303
            .clocken0       (1'b1),
304
            .clocken1       (1'b1),
305
            .clocken2       (1'b1),
306
            .clocken3       (1'b1),
307
            .aclr0          (1'b0),
308
            .aclr1          (1'b0),
309
            .addressstall_a     (1'b0),
310
            .addressstall_b     (1'b0),
311
            .eccstatus      (    )
312
 
313
        );
314
 
315
    // jtag_wb
316
    end else begin:  single_ram //JTAG_CONNECT= "DISABLED", "ALTERA_IMCE"
317
 
318
 
319
 
320
        altsyncram #(
321
            .operation_mode("SINGLE_PORT"),
322
            .width_a(Dw),
323
            .lpm_hint(RAM_ID),
324
            .read_during_write_mode_mixed_ports("DONT_CARE"),
325
            .widthad_a(Aw),
326
            .width_byteena_a(BYTE_ENw),
327
            .init_file(INIT_FILE)
328
        )
329
        ram_inst
330
        (
331
            .clock0         (clk),
332
            .address_a      (addr_a),
333
            .wren_a         (we_a),
334
            .data_a         (data_a),
335
            .q_a            (q_a),
336
            .byteena_a      (byteena_a),
337
 
338
            .wren_b         (    ),
339
            .rden_a         (    ),
340
            .rden_b         (    ),
341
            .data_b         (    ),
342
            .address_b      (    ),
343
            .clock1         (    ),
344
            .clocken0       (    ),
345
            .clocken1       (    ),
346
            .clocken2       (    ),
347
            .clocken3       (    ),
348
            .aclr0          (    ),
349
            .aclr1          (    ),
350
            .byteena_b      (    ),
351
            .addressstall_a     (    ),
352
            .addressstall_b     (    ),
353
            .q_b            (    ),
354
            .eccstatus      (    )
355
        );
356
 
357
    end
358
end
359 48 alirezamon
/* verilator lint_off WIDTH */
360 38 alirezamon
else if(FPGA_VENDOR=="GENERIC")begin:generic_ram
361 48 alirezamon
    if(JTAG_CONNECT== "ALTERA_JTAG_WB")begin:dual_ram
362
/* verilator lint_on WIDTH */
363 38 alirezamon
 
364
        generic_dual_port_ram #(
365
            .Dw(Dw),
366
            .Aw(Aw),
367
            .BYTE_WR_EN(BYTE_WR_EN),
368
            .INITIAL_EN(INITIAL_EN),
369
            .INIT_FILE(INIT_FILE)
370
        )
371
        ram_inst
372
        (
373
            .data_a     (data_a),
374
            .data_b     (data_b),
375
            .addr_a     (addr_a),
376
            .addr_b     (addr_b),
377
            .byteena_a  (byteena_a ),
378
            .byteena_b  ({BYTE_ENw{1'b1}}),
379
            .we_a       (we_a),
380
            .we_b       (we_b),
381
            .clk        (clk),
382
            .q_a        (q_a),
383
            .q_b        (q_b)
384
 
385
        );
386
 
387
 
388
    end else begin
389
 
390
 
391
 
392
        generic_single_port_ram #(
393
            .Dw(Dw),
394
            .Aw(Aw),
395
            .BYTE_WR_EN(BYTE_WR_EN),
396
            .INITIAL_EN(INITIAL_EN),
397
            .INIT_FILE(INIT_FILE)
398
        )
399
        ram_inst
400
        (
401
            .data     (data_a),
402
            .addr     (addr_a),
403
            .byteen   (byteena_a ),
404
            .we       (we_a),
405
            .clk      (clk),
406
            .q        (q_a)
407
 
408
        );
409
 
410
    end//jtag_wb
411
end //Generic
412
 
413 48 alirezamon
/* verilator lint_off WIDTH */
414
if(JTAG_CONNECT == "ALTERA_JTAG_WB")begin:jtag_wb
415
/* verilator lint_on WIDTH */
416 38 alirezamon
    reg jtag_ack;
417
    wire    jtag_we_o, jtag_stb_o;
418
 
419
    localparam Sw= log2(Aw+1);
420
    localparam [Sw-1    :   0] ST = Aw;
421
    vjtag_wb #(
422
        .VJTAG_INDEX(JTAG_INDEX),
423
        .DW(Dw),
424
        .AW(Aw),
425
        .SW(Sw),
426
 
427
        //wishbone port parameters
428
            .M_Aw(Aw),
429
            .TAGw(3)
430
    )
431
    vjtag_inst
432
    (
433
        .clk(clk),
434
        .reset(reset),
435
        .status_i(ST), // Jtag can read memory size as status
436
         //wishbone master interface signals
437
        .m_sel_o(),
438
        .m_dat_o(data_b),
439
        .m_addr_o(addr_b),
440
        .m_cti_o(),
441
        .m_stb_o(jtag_stb_o),
442
        .m_cyc_o(),
443
        .m_we_o(jtag_we_o),
444
        .m_dat_i(q_b),
445
        .m_ack_i(jtag_ack)
446
 
447
    );
448
 
449
    assign we_b = jtag_stb_o & jtag_we_o;
450
 
451
    always @(posedge clk )begin
452
        jtag_ack<=jtag_stb_o;
453
    end
454
end//jtag_wb
455
 
456
endgenerate
457
 
458
 
459
 
460
endmodule
461
 
462
 
463
 
464
 
465
 
466
 
467
 
468
 
469
 

powered by: WebSVN 2.1.0

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