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

Subversion Repositories vg_z80_sbc

[/] [vg_z80_sbc/] [trunk/] [rtl/] [wb_sram.v] - Blame information for rev 35

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 hharte
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3 19 hharte
////  $Id: wb_sram.v,v 1.4 2008-12-13 21:04:13 hharte Exp $       ////
4 17 hharte
////  wb_sram.v - SRAM with Wishbone Slave interface.             ////
5 4 hharte
////                                                              ////
6
////  This file is part of the Vector Graphic Z80 SBC Project     ////
7
////  http://www.opencores.org/projects/vg_z80_sbc/               ////
8
////                                                              ////
9
////  Author:                                                     ////
10
////      - Howard M. Harte (hharte@opencores.org)                ////
11
////                                                              ////
12
//////////////////////////////////////////////////////////////////////
13
////                                                              ////
14
//// Copyright (C) 2008 Howard M. Harte                           ////
15
////                                                              ////
16
//// This source file may be used and distributed without         ////
17
//// restriction provided that this copyright statement is not    ////
18
//// removed from the file and that any derivative work contains  ////
19
//// the original copyright notice and the associated disclaimer. ////
20
////                                                              ////
21
//// This source file is free software; you can redistribute it   ////
22
//// and/or modify it under the terms of the GNU Lesser General   ////
23
//// Public License as published by the Free Software Foundation; ////
24
//// either version 2.1 of the License, or (at your option) any   ////
25
//// later version.                                               ////
26
////                                                              ////
27
//// This source is distributed in the hope that it will be       ////
28
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
29
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
30
//// PURPOSE.  See the GNU Lesser General Public License for more ////
31
//// details.                                                     ////
32
////                                                              ////
33
//// You should have received a copy of the GNU Lesser General    ////
34
//// Public License along with this source; if not, download it   ////
35
//// from http://www.opencores.org/lgpl.shtml                     ////
36
////                                                              ////
37
//////////////////////////////////////////////////////////////////////
38 17 hharte
module wb_sram
39 11 hharte
#(
40
    parameter mem_file_name = "none",
41
    parameter adr_width = 14,
42 19 hharte
    parameter dat_width = 8,
43
    parameter dw = 32 //number of data-bits
44 11 hharte
) (
45 4 hharte
    // Generic synchronous single-port RAM interface
46
    clk_i, nrst_i, wb_adr_i, wb_dat_o, wb_dat_i, wb_sel_i, wb_we_i,
47
    wb_stb_i, wb_cyc_i, wb_ack_o
48
);
49
 
50
    //
51
    // Default address and data buses width
52
    //
53
 
54
    //
55
    // Generic synchronous single-port RAM interface
56
    //
57
    input            clk_i;
58
    input            nrst_i;
59 19 hharte
    input   [adr_width-1:0] wb_adr_i;
60 4 hharte
    output  [dw-1:0] wb_dat_o;
61
    input   [dw-1:0] wb_dat_i;
62
    input      [3:0] wb_sel_i;
63
    input            wb_we_i;
64
    input            wb_stb_i;
65
    input            wb_cyc_i;
66
    output reg       wb_ack_o;
67
 
68
    //
69
    // generate wishbone register bank writes
70
    wire wb_acc = wb_cyc_i & wb_stb_i;    // WISHBONE access
71
    wire wb_wr  = wb_acc & wb_we_i;       // WISHBONE write access
72
    wire [3:0] xram_we;
73
 
74
    // generate ack_o
75
    always @(posedge clk_i)
76
        wb_ack_o <= #1 wb_acc & !wb_ack_o;
77
 
78
    wire       [1:0] adr_low;
79
    wire       [7:0] sram_dat_o;
80
    wire       [7:0] sram_dat_i;
81
 
82
    assign adr_low = wb_sel_i == 4'b0001 ? 2'b00 : wb_sel_i == 4'b0010 ? 2'b01 : wb_sel_i == 4'b0100 ? 2'b10 : 2'b11;
83
    assign wb_dat_o = {sram_dat_o, sram_dat_o, sram_dat_o, sram_dat_o};
84
    assign sram_dat_i = wb_sel_i == 4'b0001 ? wb_dat_i[7:0] : wb_sel_i == 4'b0010 ? wb_dat_i[15:8] : wb_sel_i == 4'b0100 ? wb_dat_i[23:16] : wb_dat_i[31:24];
85
 
86 11 hharte
// Instantiate the memory using Block RAM
87
// synthesis attribute ram_style of sram_block is block
88
sram_block #(
89
    .mem_file_name(mem_file_name),
90
    .adr_width(adr_width),
91
    .dat_width(dat_width)
92
) sram_block0 (
93 4 hharte
    .clk(clk_i),
94 11 hharte
    .adr({wb_adr_i[adr_width-1:2],adr_low}),
95 4 hharte
    .dout(sram_dat_o),
96
    .din(sram_dat_i),
97
    .we(wb_wr)
98
);
99
 
100
endmodule
101
 
102 11 hharte
module sram_block
103 4 hharte
#(
104
    parameter mem_file_name = "none",
105
    parameter adr_width = 14,
106
    parameter dat_width = 8
107
) (
108
    input                       clk,
109
    input      [adr_width-1:0]  adr,
110
    input                       we,
111
    input      [dat_width-1:0]  din,
112
    output reg [dat_width-1:0]  dout
113
);
114
 
115
parameter depth = (1 << adr_width);
116
 
117
// RAM Array 
118
reg [dat_width-1:0] ram [0:depth-1];
119
 
120
always @(posedge clk)
121
begin
122
    if (we)
123
        ram[adr] <= din;
124
 
125
    dout <= ram[adr];
126
end
127
 
128
//------------------------------------------------------------------
129
// Initialize contents of RAM from file
130
//------------------------------------------------------------------
131
integer i;
132
 
133
initial
134
begin
135
    if (mem_file_name != "none")
136
    begin
137
        $readmemh(mem_file_name, ram);
138
    end
139
    else begin
140
        for(i=0; i<depth; i=i+1)
141
            ram[i] <= 'b0;
142
    end
143
 
144
end
145
 
146
endmodule

powered by: WebSVN 2.1.0

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