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

Subversion Repositories ao486

[/] [ao486/] [trunk/] [rtl/] [ao486/] [memory/] [memory_read.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 alfik
/*
2
 * Copyright (c) 2014, Aleksander Osman
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions are met:
7
 *
8
 * * Redistributions of source code must retain the above copyright notice, this
9
 *   list of conditions and the following disclaimer.
10
 *
11
 * * Redistributions in binary form must reproduce the above copyright notice,
12
 *   this list of conditions and the following disclaimer in the documentation
13
 *   and/or other materials provided with the distribution.
14
 *
15
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
19
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
 */
26
 
27
`include "defines.v"
28
 
29
//PARSED_COMMENTS: this file contains parsed script comments
30
 
31
module memory_read(
32
    // global
33
    input               clk,
34
    input               rst_n,
35
 
36
    // read step
37
    input               rd_reset,
38
 
39
    //RESP:
40
    input               read_do,
41
    output reg          read_done,
42
    output reg          read_page_fault,
43
    output reg          read_ac_fault,
44
 
45
    input       [1:0]   read_cpl,
46
    input       [31:0]  read_address,
47
    input       [3:0]   read_length,
48
    input               read_lock,
49
    input               read_rmw,
50
    output reg  [63:0]  read_data,
51
    //END
52
 
53
    //REQ:
54
    output              tlbread_do,
55
    input               tlbread_done,
56
    input               tlbread_page_fault,
57
    input               tlbread_ac_fault,
58
    input               tlbread_retry,
59
 
60
    output      [1:0]   tlbread_cpl,
61
    output      [31:0]  tlbread_address,
62
    output      [3:0]   tlbread_length,
63
    output      [3:0]   tlbread_length_full,
64
    output              tlbread_lock,
65
    output              tlbread_rmw,
66
    input       [63:0]  tlbread_data
67
    //END
68
);
69
 
70
//------------------------------------------------------------------------------
71
 
72
reg [1:0]   state;
73
 
74
reg [55:0]  buffer;
75
 
76
reg [3:0]   length_2_reg;
77
 
78
reg [31:0]  address_2_reg;
79
 
80
reg         reset_waiting;
81
 
82
//------------------------------------------------------------------------------
83
 
84
wire [63:0] merged;
85
 
86
wire [4:0]  left_in_line;
87
 
88
wire [3:0]  length_1;
89
 
90
wire [3:0]  length_2;
91
 
92
wire [31:0] address_2;
93
 
94
//------------------------------------------------------------------------------
95
 
96
localparam [1:0] STATE_IDLE        = 2'd0;
97
localparam [1:0] STATE_FIRST_WAIT  = 2'd1;
98
localparam [1:0] STATE_SECOND      = 2'd2;
99
 
100
//------------------------------------------------------------------------------
101
 
102
assign left_in_line = 5'd16 - { 1'b0, read_address[3:0] };
103
 
104
assign length_1 = (left_in_line >= { 1'd0, read_length })? read_length : left_in_line[3:0];
105
 
106
assign length_2 = read_length - length_1;
107
 
108
assign address_2 = { read_address[31:4], 4'd0 } + 32'd16;
109
 
110
assign tlbread_cpl         = read_cpl;
111
assign tlbread_length_full = read_length;
112
assign tlbread_lock        = read_lock;
113
assign tlbread_rmw         = read_rmw;
114
 
115
//------------------------------------------------------------------------------
116
 
117
assign merged =
118
    (length_1 == 4'd1)? { tlbread_data[55:0], buffer[7:0] } :
119
    (length_1 == 4'd2)? { tlbread_data[47:0], buffer[15:0] } :
120
    (length_1 == 4'd3)? { tlbread_data[39:0], buffer[23:0] } :
121
    (length_1 == 4'd4)? { tlbread_data[31:0], buffer[31:0] } :
122
    (length_1 == 4'd5)? { tlbread_data[23:0], buffer[39:0] } :
123
    (length_1 == 4'd6)? { tlbread_data[15:0], buffer[47:0] } :
124
                        { tlbread_data[7:0],  buffer[55:0] };
125
 
126
//------------------------------------------------------------------------------
127
 
128
always @(posedge clk or negedge rst_n) begin
129
    if(rst_n == 1'b0)                           reset_waiting <= `FALSE;
130
    else if(rd_reset && state != STATE_IDLE)    reset_waiting <= `TRUE;
131
    else if(state == STATE_IDLE)                reset_waiting <= `FALSE;
132
end
133
 
134
always @(posedge clk or negedge rst_n) begin
135
    if(rst_n == 1'b0)                               read_page_fault <= `FALSE;
136
    else if(rd_reset)                               read_page_fault <= `FALSE;
137
    else if(tlbread_page_fault && ~(reset_waiting)) read_page_fault <= `TRUE;
138
end
139
 
140
always @(posedge clk or negedge rst_n) begin
141
    if(rst_n == 1'b0)                               read_ac_fault <= `FALSE;
142
    else if(rd_reset)                               read_ac_fault <= `FALSE;
143
    else if(tlbread_ac_fault && ~(reset_waiting))   read_ac_fault <= `TRUE;
144
end
145
 
146
//------------------------------------------------------------------------------
147
 
148
// synthesis translate_off
149
wire _unused_ok = &{ 1'b0, address_2[3:0], 1'b0 };
150
// synthesis translate_on
151
 
152
//------------------------------------------------------------------------------
153
 
154
/*
155
tlbread_cpl             -- constant assign from read
156
tlbread_address         -- set
157
tlbread_length          -- set
158
tlbread_length_full     -- constant assign from read
159
tlbread_lock            -- constant assign from read
160
tlbread_rmw             -- constant assign from read
161
*/
162
 
163
/*******************************************************************************SCRIPT
164
 
165
IF(state == STATE_IDLE);
166
 
167
    SAVE(read_done, `FALSE);
168
 
169
    SAVE(length_2_reg,  length_2);
170
    SAVE(address_2_reg, { address_2[31:4], 4'd0 });
171
 
172
    SET(tlbread_address, read_address);
173
    SET(tlbread_length,  length_1);
174
 
175
    IF(read_do && ~(read_done) && ~(rd_reset) && ~(read_page_fault) && ~(read_ac_fault));
176
 
177
        SET(tlbread_do);
178
 
179
        SAVE(state, STATE_FIRST_WAIT);
180
    ENDIF();
181
ENDIF();
182
*/
183
 
184
/*******************************************************************************SCRIPT
185
 
186
IF(state == STATE_FIRST_WAIT);
187
 
188
    SET(tlbread_do);
189
 
190
    SET(tlbread_address, read_address);
191
    SET(tlbread_length,  length_1);
192
 
193
    IF(tlbread_page_fault || tlbread_ac_fault || (tlbread_retry && reset_waiting));
194
        SAVE(state, STATE_IDLE);
195
 
196
    ELSE_IF(tlbread_done && length_2_reg != 4'd0);
197
        SAVE(buffer, tlbread_data[55:0]);
198
 
199
        SAVE(state, STATE_SECOND);
200
 
201
    ELSE_IF(tlbread_done);
202
 
203
        IF(rd_reset == `FALSE && reset_waiting == `FALSE);
204
            SAVE(read_done, `TRUE);
205
            SAVE(read_data, tlbread_data);
206
        ENDIF();
207
 
208
        SAVE(state, STATE_IDLE);
209
    ENDIF();
210
ENDIF();
211
*/
212
 
213
/*******************************************************************************SCRIPT
214
 
215
IF(state == STATE_SECOND);
216
 
217
    SET(tlbread_address, address_2_reg);
218
    SET(tlbread_length,  length_2_reg);
219
 
220
    SET(tlbread_do);
221
 
222
    IF(tlbread_page_fault || tlbread_ac_fault || tlbread_done || (tlbread_retry && reset_waiting));
223
        SAVE(state, STATE_IDLE);
224
    ENDIF();
225
 
226
    IF(tlbread_done && rd_reset == `FALSE && reset_waiting == `FALSE);
227
        SAVE(read_done, `TRUE);
228
        SAVE(read_data, merged);
229
    ENDIF();
230
ENDIF();
231
*/
232
 
233
//------------------------------------------------------------------------------
234
 
235
`include "autogen/memory_read.v"
236
 
237
endmodule

powered by: WebSVN 2.1.0

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