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 17

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

Line No. Rev Author Line
1 4 hharte
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3 17 hharte
////  $Id: wb_sram.v,v 1.3 2008-12-08 06:55:36 hharte Exp $       ////
4
////  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
    parameter dat_width = 8
43
) (
44 4 hharte
    // Generic synchronous single-port RAM interface
45
    clk_i, nrst_i, wb_adr_i, wb_dat_o, wb_dat_i, wb_sel_i, wb_we_i,
46
    wb_stb_i, wb_cyc_i, wb_ack_o
47
);
48
 
49
    //
50
    // Default address and data buses width
51
    //
52
    parameter aw = 15; //number of address-bits
53
    parameter dw = 32; //number of data-bits
54
 
55
    //
56
    // Generic synchronous single-port RAM interface
57
    //
58
    input            clk_i;
59
    input            nrst_i;
60
    input   [aw-1:0] wb_adr_i;
61
    output  [dw-1:0] wb_dat_o;
62
    input   [dw-1:0] wb_dat_i;
63
    input      [3:0] wb_sel_i;
64
    input            wb_we_i;
65
    input            wb_stb_i;
66
    input            wb_cyc_i;
67
    output reg       wb_ack_o;
68
 
69
    //
70
    // generate wishbone register bank writes
71
    wire wb_acc = wb_cyc_i & wb_stb_i;    // WISHBONE access
72
    wire wb_wr  = wb_acc & wb_we_i;       // WISHBONE write access
73
    wire [3:0] xram_we;
74
 
75
    // generate ack_o
76
    always @(posedge clk_i)
77
        wb_ack_o <= #1 wb_acc & !wb_ack_o;
78
 
79
    wire       [1:0] adr_low;
80
    wire       [7:0] sram_dat_o;
81
    wire       [7:0] sram_dat_i;
82
 
83
    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;
84
    assign wb_dat_o = {sram_dat_o, sram_dat_o, sram_dat_o, sram_dat_o};
85
    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];
86
 
87 11 hharte
// Instantiate the memory using Block RAM
88
// synthesis attribute ram_style of sram_block is block
89
sram_block #(
90
    .mem_file_name(mem_file_name),
91
    .adr_width(adr_width),
92
    .dat_width(dat_width)
93
) sram_block0 (
94 4 hharte
    .clk(clk_i),
95 11 hharte
    .adr({wb_adr_i[adr_width-1:2],adr_low}),
96 4 hharte
    .dout(sram_dat_o),
97
    .din(sram_dat_i),
98
    .we(wb_wr)
99
);
100
 
101
endmodule
102
 
103 11 hharte
module sram_block
104 4 hharte
#(
105
    parameter mem_file_name = "none",
106
    parameter adr_width = 14,
107
    parameter dat_width = 8
108
) (
109
    input                       clk,
110
    input      [adr_width-1:0]  adr,
111
    input                       we,
112
    input      [dat_width-1:0]  din,
113
    output reg [dat_width-1:0]  dout
114
);
115
 
116
parameter depth = (1 << adr_width);
117
 
118
// RAM Array 
119
reg [dat_width-1:0] ram [0:depth-1];
120
 
121
always @(posedge clk)
122
begin
123
    if (we)
124
        ram[adr] <= din;
125
 
126
    dout <= ram[adr];
127
end
128
 
129
//------------------------------------------------------------------
130
// Initialize contents of RAM from file
131
//------------------------------------------------------------------
132
integer i;
133
 
134
initial
135
begin
136
    if (mem_file_name != "none")
137
    begin
138
        $readmemh(mem_file_name, ram);
139
    end
140
    else begin
141
        for(i=0; i<depth; i=i+1)
142
            ram[i] <= 'b0;
143
    end
144
 
145
end
146
 
147
endmodule

powered by: WebSVN 2.1.0

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