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

Subversion Repositories aor3000

[/] [aor3000/] [trunk/] [rtl/] [memory/] [memory_ram.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 alfik
/*
2
 * This file is subject to the terms and conditions of the BSD License. See
3
 * the file "LICENSE" in the main directory of this archive for more details.
4
 *
5
 * Copyright (C) 2014 Aleksander Osman
6
 */
7
 
8
`include "defines.v"
9
 
10
module memory_ram(
11
    input               clk,
12
    input               rst_n,
13
 
14
    //
15
    input               config_switch_caches,
16
 
17
    //
18
    input       [8:0]   fetch_cache_read_address,
19
    output      [53:0]  fetch_cache_q,
20
 
21
    input       [8:0]   fetch_cache_write_address,
22
    input               fetch_cache_write_enable,
23
    input       [53:0]  fetch_cache_data,
24
 
25
    //
26
    input       [8:0]   data_cache_read_address,
27
    output      [53:0]  data_cache_q,
28
 
29
    input       [8:0]   data_cache_write_address,
30
    input               data_cache_write_enable,
31
    input       [53:0]  data_cache_data,
32
 
33
    //
34
    input               ram_fifo_rdreq,
35
    input               ram_fifo_wrreq,
36
    input       [66:0]  ram_fifo_data,
37
 
38
    output              ram_fifo_empty,
39
    output              ram_fifo_full,
40
    output      [66:0]  ram_fifo_q,
41
 
42
    //
43
    output reg  [4:0]   write_buffer_counter
44
);
45
 
46
//------------------------------------------------------------------------------
47
 
48
/*
49
vpn/pfn        offset
50
------20------ ---12---
51
tag             index
52
------21------- --9-- -2-
53
 
54
[53]    valid
55
[52:32] tag
56
[31:0]  data
57
*/
58
 
59
wire [8:0] address_1_r = (config_switch_caches)? fetch_cache_read_address  : data_cache_read_address;
60
wire [8:0] address_1_w = (config_switch_caches)? fetch_cache_write_address : data_cache_write_address;
61
 
62
wire [8:0] address_2_r = (config_switch_caches)? data_cache_read_address  : fetch_cache_read_address;
63
wire [8:0] address_2_w = (config_switch_caches)? data_cache_write_address : fetch_cache_write_address;
64
 
65
wire wren_1 = (config_switch_caches)? fetch_cache_write_enable : data_cache_write_enable;
66
wire wren_2 = (config_switch_caches)? data_cache_write_enable  : fetch_cache_write_enable;
67
 
68
wire [53:0] data_1 = (config_switch_caches)? fetch_cache_data : data_cache_data;
69
wire [53:0] data_2 = (config_switch_caches)? data_cache_data  : fetch_cache_data;
70
 
71
wire [53:0] q_1;
72
wire [53:0] q_2;
73
 
74
model_simple_dual_ram #(
75
    .width          (54),
76
    .widthad        (9)
77
)
78
cache_1_inst(
79
    .clk            (clk),
80
 
81
    //
82
    .address_a      (address_1_r),  //input [9:0]
83
    .q_a            (q_1),          //output [53:0]
84
 
85
    //
86
    .address_b      (address_1_w),  //input [9:0]
87
    .wren_b         (wren_1),       //input
88
    .data_b         (data_1)        //input [53:0]
89
);
90
 
91
model_simple_dual_ram #(
92
    .width          (54),
93
    .widthad        (9)
94
)
95
cache_2_inst(
96
    .clk            (clk),
97
 
98
    //
99
    .address_a      (address_2_r),  //input [9:0]
100
    .q_a            (q_2),          //output [53:0]
101
 
102
    //
103
    .address_b      (address_2_w),  //input [9:0]
104
    .wren_b         (wren_2),       //input
105
    .data_b         (data_2)        //input [53:0]
106
);
107
 
108
reg [8:0]  address_1_w_reg;
109
reg [8:0]  address_1_r_reg;
110
reg [8:0]  address_2_w_reg;
111
reg [8:0]  address_2_r_reg;
112
reg        wren_1_reg;
113
reg        wren_2_reg;
114
reg        config_switch_caches_reg;
115
reg [53:0] data_1_reg;
116
reg [53:0] data_2_reg;
117
 
118
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) address_1_w_reg          <= 9'd0;   else address_1_w_reg          <= address_1_w;          end
119
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) address_1_r_reg          <= 9'd0;   else address_1_r_reg          <= address_1_r;          end
120
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) address_2_w_reg          <= 9'd0;   else address_2_w_reg          <= address_2_w;          end
121
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) address_2_r_reg          <= 9'd0;   else address_2_r_reg          <= address_2_r;          end
122
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) wren_1_reg               <= `FALSE; else wren_1_reg               <= wren_1;               end
123
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) wren_2_reg               <= `FALSE; else wren_2_reg               <= wren_2;               end
124
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) config_switch_caches_reg <= `FALSE; else config_switch_caches_reg <= config_switch_caches; end
125
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) data_1_reg               <= 54'd0;  else data_1_reg               <= data_1;               end
126
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) data_2_reg               <= 54'd0;  else data_2_reg               <= data_2;               end
127
 
128
assign fetch_cache_q =
129
    (config_switch_caches_reg && wren_1_reg && address_1_r_reg == address_1_w_reg)? data_1_reg :
130
    (config_switch_caches_reg)?                                                     q_1 :
131
    (wren_2_reg && address_2_r_reg == address_2_w_reg)?                             data_2_reg :
132
                                                                                    q_2;
133
 
134
assign data_cache_q =
135
    (config_switch_caches_reg && wren_2_reg && address_2_r_reg == address_2_w_reg)? data_2_reg :
136
    (config_switch_caches_reg)?                                                     q_2 :
137
    (wren_1_reg && address_1_r_reg == address_1_w_reg)?                             data_1_reg :
138
                                                                                    q_1;
139
 
140
//------------------------------------------------------------------------------
141
 
142
always @(posedge clk or negedge rst_n) begin
143
    if(rst_n == 1'b0)                                                                                                                       write_buffer_counter <= 5'd0;
144
    else if(ram_fifo_wrreq && ram_fifo_data[66]         && (ram_fifo_empty || ~(ram_fifo_rdreq) || (ram_fifo_rdreq && ~(ram_fifo_q[66]))))  write_buffer_counter <= write_buffer_counter + 5'd1;
145
    else if((~(ram_fifo_wrreq) || ~(ram_fifo_data[66])) && ram_fifo_rdreq && ram_fifo_q[66])                                                write_buffer_counter <= write_buffer_counter - 5'd1;
146
end
147
 
148
//------------------------------------------------------------------------------
149
 
150
wire [3:0] ram_fifo_usedw;
151
 
152
//{ [66] 1'b is_write, [65:36] 30'b address, [35:4] 32'b value, [3:0] 4'b byteena (4'b0000 - can burst 4 words) }
153
 
154
model_fifo #(
155
    .width          (67),
156
    .widthu         (4)
157
)
158
ram_fifo_inst(
159
    .clk            (clk),
160
    .rst_n          (rst_n),
161
 
162
    .sclr           (`FALSE),
163
 
164
    .rdreq          (ram_fifo_rdreq),   //input
165
    .wrreq          (ram_fifo_wrreq),   //input
166
    .data           (ram_fifo_data),    //input [66:0]
167
 
168
    .empty          (ram_fifo_empty),   //output
169
    .full           (ram_fifo_full),    //output
170
    .q              (ram_fifo_q),       //output [66:0]
171
    .usedw          (ram_fifo_usedw)    //output [3:0]
172
);
173
 
174
//------------------------------------------------------------------------------
175
// synthesis translate_off
176
wire _unused_ok = &{ 1'b0, ram_fifo_usedw,  1'b0 };
177
// synthesis translate_on
178
//------------------------------------------------------------------------------
179
 
180
endmodule

powered by: WebSVN 2.1.0

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