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

Subversion Repositories rf6809

[/] [rf6809/] [trunk/] [rtl/] [CmodA7/] [cs02memInterface.sv] - Blame information for rev 17

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

Line No. Rev Author Line
1 16 robfinch
// ============================================================================
2
//        __
3
//   \\__/ o\    (C) 2019-2022  Robert Finch, Waterloo
4
//    \  __ /    All rights reserved.
5
//     \/_//     robfinch@finitron.ca
6
//       ||
7
//
8
//
9
// BSD 3-Clause License
10
// Redistribution and use in source and binary forms, with or without
11
// modification, are permitted provided that the following conditions are met:
12
//
13
// 1. Redistributions of source code must retain the above copyright notice, this
14
//    list of conditions and the following disclaimer.
15
//
16
// 2. Redistributions in binary form must reproduce the above copyright notice,
17
//    this list of conditions and the following disclaimer in the documentation
18
//    and/or other materials provided with the distribution.
19
//
20
// 3. Neither the name of the copyright holder nor the names of its
21
//    contributors may be used to endorse or promote products derived from
22
//    this software without specific prior written permission.
23
//
24
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
//
35
// ============================================================================
36
//
37
module cs02memInterface(rst_i, clk_i, cpuclk_i,
38
        cs_i, cyc_i, stb_i, ack_o, we_i, adr_i, dat_i, dat_o,
39
        RamCEn, RamWEn, RamOEn, MemAdr, MemDBo, MemDBi);
40
input rst_i;
41
input clk_i;          // 100 MHz
42
input cpuclk_i;
43
input cs_i;
44
input cyc_i;
45
input stb_i;
46
output ack_o;
47
input we_i;
48
input [23:0] adr_i;
49
input [11:0] dat_i;
50
output reg [11:0] dat_o;
51
output reg RamCEn;
52
output reg RamWEn;
53
output reg RamOEn;
54
output reg [18:0] MemAdr;
55
output reg [7:0] MemDBo;
56
input [7:0] MemDBi;
57
parameter HIGH = 1'b1;
58
parameter LOW = 1'b0;
59
 
60
reg [3:0] state;
61
parameter IDLE = 4'd0;
62
parameter WRF1 = 4'd1;
63
parameter WRF2 = 4'd2;
64
parameter WRF3 = 4'd3;
65
parameter WRF4 = 4'd4;
66
parameter WRF5 = 4'd5;
67
parameter WRF6 = 4'd6;
68
parameter WRF7 = 4'd7;
69
parameter WRF8 = 4'd8;
70
parameter RRF1 = 4'd9;
71
parameter RRF2 = 4'd10;
72
parameter RRF3 = 4'd11;
73
parameter RRF4 = 4'd12;
74
 
75
wire cs = cs_i & stb_i & cyc_i;
76
reg ack;
77
wire hit;
78
 
79
ack_gen #(
80
        .READ_STAGES(2),
81
        .WRITE_STAGES(1),
82
        .REGISTER_OUTPUT(1)
83
) uag1
84
(
85
        .rst_i(rst_i),
86
        .clk_i(cpuclk_i),
87
        .ce_i(1'b1),
88
        .i(cs & hit & ~we_i),
89
        .we_i(cs & ack),
90
        .o(ack_o),
91
        .rid_i(0),
92
        .wid_i(0),
93
        .rid_o(),
94
        .wid_o()
95
);
96
 
97
reg wrc, inv;
98
wire [11:0] rdat;
99
 
100
A709_ReadCache urc1
101
(
102
        .rst(rst_i),
103
        .wclk(clk_i),
104
        .wr(wrc),
105
        .wa({5'h0,MemAdr[18:0]}),
106
        .wd(MemDBi[5:0]),
107
        .rclk(cpuclk_i),
108
        .ra(adr_i),
109
        .rd(rdat),
110
        .hit(hit),
111
        .inv(inv),
112
        .ia(adr_i)
113
);
114
 
115
always_ff @(posedge cpuclk_i)
116
if (cs)
117
        dat_o <= rdat;
118
else
119
        dat_o <= 12'h0;
120
 
121
reg [31:0] ctr; // ring counter
122
 
123
always_ff @(posedge clk_i)
124
if (rst_i) begin
125
        state <= IDLE;
126
        RamWEn <= HIGH;
127
        RamOEn <= HIGH;
128
        RamCEn <= HIGH;
129
        wrc <= 1'b0;
130
        ack <= 1'b0;
131
        inv <= 1'b0;
132
        ctr <= 33'h1;
133
end
134
else begin
135
wrc <= 1'b0;
136
inv <= 1'b0;
137
case(state)
138
IDLE:
139
        begin
140
                RamWEn <= HIGH;
141
                RamCEn <= HIGH;
142
                RamOEn <= HIGH;
143
                MemAdr[18:0] <= {adr_i[17:0],1'b0};
144
                MemDBo <= {2'b0,dat_i[5:0]};
145
                if (cs & we_i) begin
146
                        inv <= 1'b1;
147
                        RamCEn <= LOW;
148
                        state <= WRF1;
149
                end
150
                // Initiate a read, it might take several cycles before hit goes high,
151
                // so test for a hit at each stage.
152
                else if (cs & !hit) begin
153
                        RamCEn <= LOW;
154
                        RamOEn <= LOW;
155
                        MemAdr[4:0] <= 5'h0;
156
                        ctr <= 33'h1;
157
                        state <= RRF1;
158
                end
159
        end
160
WRF1:
161
        begin
162
                RamWEn <= LOW;
163
                state <= WRF2;
164
        end
165
WRF2:
166
        begin
167
                state <= WRF3;
168
        end
169
WRF3:
170
        begin
171
                RamWEn <= HIGH;
172
                state <= WRF4;
173
        end
174
WRF4:
175
        begin
176
                MemAdr[0] <= 1'b1;
177
                MemDBo <= {2'b0,dat_i[11:6]};
178
                state <= WRF5;
179
        end
180
WRF5:
181
        begin
182
                RamWEn <= LOW;
183
                state <= WRF6;
184
        end
185
WRF6:
186
        begin
187
                state <= WRF7;
188
        end
189
WRF7:
190
        begin
191
                RamWEn <= HIGH;
192
                ack <= 1'b1;
193
                state <= WRF8;
194
        end
195
WRF8:
196
        if (!cs) begin
197
                ack <= 1'b0;
198
                state <= IDLE;
199
        end
200
RRF1:
201
        begin
202
                if (hit)
203
                        state <= IDLE;
204
                else
205
                        state <= RRF2;
206
        end
207
RRF2:
208
        begin
209
                wrc <= 1'b1;
210
                if (hit)
211
                        state <= IDLE;
212
                else if (ctr[31])
213
                        state <= RRF4;
214
                else
215
                        state <= RRF3;
216
        end
217
RRF3:
218
        begin
219
                MemAdr[4:0] <= MemAdr[4:0] + 2'd1;
220
                ctr <= {ctr[30:0],ctr[31]};
221
                if (hit)
222
                        state <= IDLE;
223
                else
224
                        state <= RRF1;
225
        end
226
RRF4:
227
        begin
228
                wrc <= 1'b1;
229
                state <= IDLE;
230
        end
231
default:
232
        state <= IDLE;
233
endcase
234
end
235
endmodule
236
 
237
module A709_ReadCache(rst, wclk, wr, wa, wd, rclk, ra, rd, hit, inv, ia);
238
input rst;
239
input wclk;
240
input wr;
241
input [24:0] wa;
242
input [5:0] wd;
243
input rclk;
244
input [23:0] ra;
245
output reg [11:0] rd;
246
output reg hit;
247
input inv;
248
input [23:0] ia;
249
 
250
reg [11:0] mem [0:2047];
251
reg [10:0] rra;
252
 
253
always_ff @(posedge rclk)
254
        rra <= ra[10:0];
255
always_ff @(posedge rclk)
256
        rd <= mem[rra];
257
always_ff @(posedge wclk)
258
        if (wr & ~wa[0]) mem[wa[11:1]][5:0] <= wd;
259
always_ff @(posedge wclk)
260
        if (wr &  wa[0]) mem[wa[11:1]][11:6] <= wd;
261
 
262
reg [19:0] tagmem [127:0];
263
reg [127:0] valid;
264
 
265
reg [23:0] iar;
266
reg invr;
267
// register onto wclk domain
268
always_ff @(posedge wclk)
269
        iar <= ia;
270
always_ff @(posedge wclk)
271
        invr <= inv;
272
 
273
always_ff @(posedge wclk)
274
        if (wr && wa[4:0]==5'h1F)
275
                tagmem[wa[11:5]] <= wa[24:5];
276
 
277
always_ff @(posedge wclk)
278
if (rst)
279
        valid <= 128'd0;
280
else begin
281
if (invr)
282
        valid[iar[10:4]] <= tagmem[iar[10:4]]!=iar[23:4];
283
else if (wr && wa[4:0]==5'h1F)
284
        valid[wa[11:5]] <= 1'b1;
285
end
286
 
287
always_ff @(posedge rclk)
288
        hit <= valid[ra[10:4]] && tagmem[ra[10:4]]==ra[23:4];
289
 
290
endmodule

powered by: WebSVN 2.1.0

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