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

Subversion Repositories amber

[/] [amber/] [trunk/] [hw/] [vlog/] [system/] [main_mem.v] - Blame information for rev 35

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

Line No. Rev Author Line
1 2 csantifort
//////////////////////////////////////////////////////////////////
2
//                                                              //
3
//  Main memory for simulations.                                //
4
//                                                              //
5
//  This file is part of the Amber project                      //
6
//  http://www.opencores.org/project,amber                      //
7
//                                                              //
8
//  Description                                                 //
9
//  Non-synthesizable main memory. Holds 128MBytes              //
10
//  The memory path in this module is purely combinational.     //
11
//  Addresses and write_cmd_req data are registered as          //
12
//  the leave the execute module and read data is registered    //
13
//  as it enters the instruction_decode module.                 //
14
//                                                              //
15
//  Author(s):                                                  //
16
//      - Conor Santifort, csantifort.amber@gmail.com           //
17
//                                                              //
18
//////////////////////////////////////////////////////////////////
19
//                                                              //
20
// Copyright (C) 2010 Authors and OPENCORES.ORG                 //
21
//                                                              //
22
// This source file may be used and distributed without         //
23
// restriction provided that this copyright statement is not    //
24
// removed from the file and that any derivative work contains  //
25
// the original copyright notice and the associated disclaimer. //
26
//                                                              //
27
// This source file is free software; you can redistribute it   //
28
// and/or modify it under the terms of the GNU Lesser General   //
29
// Public License as published by the Free Software Foundation; //
30
// either version 2.1 of the License, or (at your option) any   //
31
// later version.                                               //
32
//                                                              //
33
// This source is distributed in the hope that it will be       //
34
// useful, but WITHOUT ANY WARRANTY; without even the implied   //
35
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
36
// PURPOSE.  See the GNU Lesser General Public License for more //
37
// details.                                                     //
38
//                                                              //
39
// You should have received a copy of the GNU Lesser General    //
40
// Public License along with this source; if not, download it   //
41
// from http://www.opencores.org/lgpl.shtml                     //
42
//                                                              //
43
//////////////////////////////////////////////////////////////////
44
 
45
 
46 35 csantifort
module main_mem#(
47
parameter WB_DWIDTH  = 32,
48
parameter WB_SWIDTH  = 4
49
)(
50 2 csantifort
input                          i_clk,
51 11 csantifort
input                          i_mem_ctrl,  // 0=128MB, 1=32MB
52 2 csantifort
// Wishbone Bus
53
input       [31:0]             i_wb_adr,
54 35 csantifort
input       [WB_SWIDTH-1:0]    i_wb_sel,
55 2 csantifort
input                          i_wb_we,
56 35 csantifort
output      [WB_DWIDTH-1:0]    o_wb_dat,
57
input       [WB_DWIDTH-1:0]    i_wb_dat,
58 2 csantifort
input                          i_wb_cyc,
59
input                          i_wb_stb,
60
output                         o_wb_ack,
61
output                         o_wb_err
62
 
63
);
64
 
65
`include "memory_configuration.v"
66
 
67
reg     [127:0]     ram   [2**(MAIN_MSB-2)-1:0];
68
wire                start_write;
69
wire                start_read;
70
reg                 start_read_d1;
71
reg                 start_read_d2;
72
wire    [127:0]     rd_data;
73
wire    [127:0]     masked_wdata;
74
 
75
reg                 wr_en           = 'd0;
76
reg     [15:0]      wr_mask         = 'd0;
77
reg     [127:0]     wr_data         = 'd0;
78
reg     [27:0]      addr_d1         = 'd0;
79
wire                busy;
80
genvar              i;
81
 
82
 
83
assign start_write = i_wb_stb &&  i_wb_we && !busy;
84
assign start_read  = i_wb_stb && !i_wb_we && !busy;
85
assign busy        = start_read_d1 || start_read_d2;
86
 
87
assign o_wb_err    = 'd0;
88
 
89
 
90 35 csantifort
generate
91
if (WB_DWIDTH == 128)
92
    begin : wb128
93
    reg     [127:0]      wb_rdata128 = 'd0;
94 11 csantifort
 
95 35 csantifort
    // ------------------------------------------------------
96
    // Write for 32-bit wishbone
97
    // ------------------------------------------------------
98
    always @( posedge i_clk )
99
        begin
100
        wr_en          <= start_write;
101
        wr_mask        <= ~ i_wb_sel;
102
        wr_data        <= i_wb_dat;
103 2 csantifort
 
104 35 csantifort
                          // Wrap the address at 32 MB, or full width
105
        addr_d1        <= i_mem_ctrl ? {5'd0, i_wb_adr[24:2]} : i_wb_adr[29:2];
106
 
107
        if ( wr_en )
108
            ram [addr_d1[27:2]]  <= masked_wdata;
109
        end
110 2 csantifort
 
111
 
112 35 csantifort
    for (i=0;i<16;i=i+1) begin : masked
113
        assign masked_wdata[8*i+7:8*i] = wr_mask[i] ? rd_data[8*i+7:8*i] : wr_data[8*i+7:8*i];
114
        end
115 2 csantifort
 
116 35 csantifort
 
117
    // ------------------------------------------------------
118
    // Read for 32-bit wishbone
119
    // ------------------------------------------------------
120
    assign rd_data = ram [addr_d1[27:2]];
121 2 csantifort
 
122 35 csantifort
    always @( posedge i_clk )
123
        begin
124
        start_read_d1   <= start_read;
125
        start_read_d2   <= start_read_d1;
126
        if ( start_read_d1 )
127
            begin
128
            wb_rdata128 <= rd_data;
129
            end
130
        end
131
    assign o_wb_dat = wb_rdata128 ;
132
    assign o_wb_ack = i_wb_stb && ( start_write || start_read_d2 );
133 2 csantifort
 
134 35 csantifort
    end
135
else
136
    begin : wb32
137
    reg     [31:0]      wb_rdata32 = 'd0;
138
 
139
    // ------------------------------------------------------
140
    // Write for 32-bit wishbone
141
    // ------------------------------------------------------
142
    always @( posedge i_clk )
143 2 csantifort
        begin
144 35 csantifort
        wr_en          <= start_write;
145
        wr_mask        <= i_wb_adr[3:2] == 2'd0 ? { 12'hfff, ~i_wb_sel          } :
146
                          i_wb_adr[3:2] == 2'd1 ? { 8'hff,   ~i_wb_sel, 4'hf    } :
147
                          i_wb_adr[3:2] == 2'd2 ? { 4'hf,    ~i_wb_sel, 8'hff   } :
148
                                                  {          ~i_wb_sel, 12'hfff } ;
149
        wr_data        <= {4{i_wb_dat}};
150
 
151
                          // Wrap the address at 32 MB, or full width
152
        addr_d1        <= i_mem_ctrl ? {5'd0, i_wb_adr[24:2]} : i_wb_adr[29:2];
153
 
154
        if ( wr_en )
155
            ram [addr_d1[27:2]]  <= masked_wdata;
156 2 csantifort
        end
157 35 csantifort
 
158
 
159
    for (i=0;i<16;i=i+1) begin : masked
160
        assign masked_wdata[8*i+7:8*i] = wr_mask[i] ? rd_data[8*i+7:8*i] : wr_data[8*i+7:8*i];
161
        end
162
 
163
    // ------------------------------------------------------
164
    // Read for 32-bit wishbone
165
    // ------------------------------------------------------
166
    assign rd_data = ram [addr_d1[27:2]];
167
 
168
    always @( posedge i_clk )
169
        begin
170
        start_read_d1   <= start_read;
171
        start_read_d2   <= start_read_d1;
172
        if ( start_read_d1 )
173
            begin
174
            wb_rdata32 <= addr_d1[1:0] == 2'd0 ? rd_data[ 31: 0] :
175
                          addr_d1[1:0] == 2'd1 ? rd_data[ 63:32] :
176
                          addr_d1[1:0] == 2'd2 ? rd_data[ 95:64] :
177
                                                 rd_data[127:96] ;
178
            end
179
        end
180
    assign o_wb_dat = wb_rdata32 ;
181
    assign o_wb_ack = i_wb_stb && ( start_write || start_read_d2 );
182 2 csantifort
    end
183 35 csantifort
endgenerate
184 2 csantifort
 
185
 
186
endmodule
187
 
188
 
189
 
190
 

powered by: WebSVN 2.1.0

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