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

Subversion Repositories mpmc8

[/] [mpmc8/] [trunk/] [rtl/] [mpmc8_state_machine.sv] - Blame information for rev 3

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

Line No. Rev Author Line
1 2 robfinch
`timescale 1ns / 1ps
2
// ============================================================================
3
//        __
4
//   \\__/ o\    (C) 2015-2022  Robert Finch, Waterloo
5
//    \  __ /    All rights reserved.
6
//     \/_//     robfinch@finitron.ca
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
import mpmc8_pkg::*;
38
 
39
module mpmc8_state_machine(rst, clk, ch,
40
        acki0, acki1, acki2, acki3, acki4, acki5, acki6, acki7,
41
        ch0_taghit, ch1_taghit, ch2_taghit, ch3_taghit, ch4_taghit, ch5_taghit,
42
        ch6_taghit, ch7_taghit, wdf_rdy, rdy, do_wr, rd_data_valid,
43
        num_strips, req_strip_cnt, resp_strip_cnt, to,
44
        cr1, cr7, adr1, adr7,
45
        resv_ch, resv_adr,
46
        state
47
);
48
input rst;
49
input clk;
50
input [3:0] ch;
51
input acki0;
52
input acki1;
53
input acki2;
54
input acki3;
55
input acki4;
56
input acki5;
57
input acki6;
58
input acki7;
59
input ch0_taghit;
60
input ch1_taghit;
61
input ch2_taghit;
62
input ch3_taghit;
63
input ch4_taghit;
64
input ch5_taghit;
65
input ch6_taghit;
66
input ch7_taghit;
67
input wdf_rdy;
68
input rdy;
69
input do_wr;
70
input rd_data_valid;
71
input [2:0] num_strips;
72
input [2:0] req_strip_cnt;
73
input [2:0] resp_strip_cnt;
74
input to;
75
input cr1;
76
input cr7;
77
input [31:0] adr1;
78
input [31:0] adr7;
79
input [3:0] resv_ch [0:NAR-1];
80
input [31:0] resv_adr [0:NAR-1];
81
output reg [3:0] state;
82
 
83
reg [3:0] next_state;
84
 
85
// State machine
86
always_ff @(posedge clk)
87
        state <= next_state;
88
 
89
integer n3;
90
always_comb
91
if (rst)
92
        next_state <= IDLE;
93
else begin
94
case(state)
95
IDLE:
96
        begin
97
                next_state <= IDLE;
98
          // According to the docs there's no need to wait for calib complete.
99
          // Calib complete goes high in sim about 111 us.
100
          // Simulation setting must be set to FAST.
101
                //if (calib_complete)
102
                case(ch)
103
                3'd0:   if (!acki0) next_state <= PRESET1;
104
                3'd1:
105
                        if (!acki1) begin
106
                    if (cr1) begin
107
                next_state <= IDLE;
108
                        for (n3 = 0; n3 < NAR; n3 = n3 + 1)
109
                        if ((resv_ch[n3]==4'd1) && (resv_adr[n3][31:4]==adr1[31:4]))
110
                        next_state <= PRESET1;
111
                    end
112
                    else
113
                next_state <= PRESET1;
114
            end
115
                3'd2:   if (!acki2) next_state <= PRESET1;
116
                3'd3:   if (!acki3) next_state <= PRESET1;
117
                3'd4:   if (!acki4) next_state <= PRESET1;
118
                3'd5:   if (!acki5) next_state <= PRESET1;
119
                3'd6:   if (!acki6) next_state <= PRESET1;
120
                3'd7:
121
                        if (!acki7) begin
122
                    if (cr7) begin
123
                next_state <= IDLE;
124
                        for (n3 = 0; n3 < NAR; n3 = n3 + 1)
125
                        if ((resv_ch[n3]==4'd7) && (resv_adr[n3][31:4]==adr7[31:4]))
126
                    next_state <= PRESET1;
127
                    end
128
                    else
129
                next_state <= PRESET1;
130
            end
131
                default:        ;       // no channel selected -> stay in IDLE state
132
                endcase
133
        end
134
// If an ack is received during a preset cycle it is likely a read cycle that
135
// acked a cycle late. Abort the cycle.
136
PRESET1:
137
        case(ch)
138
        4'd0:   if (ch0_taghit) next_state <= IDLE; else next_state <= PRESET2;
139
        4'd1:   if (ch1_taghit) next_state <= IDLE; else next_state <= PRESET2;
140
        4'd2:   if (ch2_taghit) next_state <= IDLE; else next_state <= PRESET2;
141
        4'd3:   if (ch3_taghit) next_state <= IDLE; else next_state <= PRESET2;
142
        4'd4:   if (ch4_taghit) next_state <= IDLE; else next_state <= PRESET2;
143
        4'd5:   if (ch5_taghit) next_state <= IDLE; else next_state <= PRESET2;
144
        4'd6:   if (ch6_taghit) next_state <= IDLE; else next_state <= PRESET2;
145
        4'd7:   if (ch7_taghit) next_state <= IDLE; else next_state <= PRESET2;
146
        default:        next_state <= PRESET2;
147
        endcase
148
// The valid data, data mask and address are placed in app_wdf_data, app_wdf_mask,
149
// and memm_addr ahead of time.
150
PRESET2:
151
        case(ch)
152
        4'd0:   if (ch0_taghit) next_state <= IDLE; else next_state <= PRESET3;
153
        4'd1:   if (ch1_taghit) next_state <= IDLE; else next_state <= PRESET3;
154
        4'd2:   if (ch2_taghit) next_state <= IDLE; else next_state <= PRESET3;
155
        4'd3:   if (ch3_taghit) next_state <= IDLE; else next_state <= PRESET3;
156
        4'd4:   if (ch4_taghit) next_state <= IDLE; else next_state <= PRESET3;
157
        4'd5:   if (ch5_taghit) next_state <= IDLE; else next_state <= PRESET3;
158
        4'd6:   if (ch6_taghit) next_state <= IDLE; else next_state <= PRESET3;
159
        4'd7:   if (ch7_taghit) next_state <= IDLE; else next_state <= PRESET3;
160
        default:        next_state <= PRESET3;
161
        endcase
162
// PRESET3 determines the read or write command
163
PRESET3:
164
        if (do_wr && !RMW)
165
                next_state <= WRITE_DATA0;
166
        else begin
167
                next_state <= READ_DATA0;
168
                case(ch)
169
                4'd0:   if (ch0_taghit) next_state <= IDLE; else next_state <= READ_DATA0;
170
                4'd1:   if (ch1_taghit) next_state <= IDLE; else next_state <= READ_DATA0;
171
                4'd2:   if (ch2_taghit) next_state <= IDLE; else next_state <= READ_DATA0;
172
                4'd3:   if (ch3_taghit) next_state <= IDLE; else next_state <= READ_DATA0;
173
                4'd4:   if (ch4_taghit) next_state <= IDLE; else next_state <= READ_DATA0;
174
                4'd5:   if (ch5_taghit) next_state <= IDLE; else next_state <= READ_DATA0;
175
                4'd6:   if (ch6_taghit) next_state <= IDLE; else next_state <= READ_DATA0;
176
                4'd7:   if (ch7_taghit) next_state <= IDLE; else next_state <= READ_DATA0;
177
                default:        next_state <= READ_DATA0;
178
                endcase
179
        end
180
 
181
// Write data to the data fifo
182
// Write occurs when app_wdf_wren is true and app_wdf_rdy is true
183
WRITE_DATA0:
184
        // Issue a write command if the fifo is full.
185
//      if (!app_wdf_rdy)
186
//              next_state <= WRITE_DATA1;
187
//      else
188
        if (wdf_rdy)// && req_strip_cnt==num_strips)
189
                next_state <= WRITE_DATA1;
190
        else
191
                next_state <= WRITE_DATA0;
192
WRITE_DATA1:
193
        next_state <= WRITE_DATA2;
194
WRITE_DATA2:
195
        if (rdy)
196
                next_state <= WRITE_DATA3;
197
        else
198
                next_state <= WRITE_DATA2;
199
WRITE_DATA3:
200
        next_state <= IDLE;
201
        /*
202
        if (req_strip_cnt==num_strips)
203
                next_state <= IDLE;
204
        else
205
                next_state <= WRITE_DATA0;
206
        */
207
// There could be multiple read requests submitted before any response occurs.
208
// Stay in the SET_CMD_RD until all requested strips have been processed.
209
READ_DATA0:
210
        next_state <= READ_DATA1;
211
// Could it take so long to do the request that we start getting responses
212
// back?
213
READ_DATA1:
214
        if (rdy && req_strip_cnt==num_strips)
215
                next_state <= READ_DATA2;
216
        else
217
                next_state <= READ_DATA1;
218
// Wait for incoming responses, but only for so long to prevent a hang.
219
READ_DATA2:
220
        if (rd_data_valid && resp_strip_cnt==num_strips)
221
                next_state <= WAIT_NACK;
222
        else
223
                next_state <= READ_DATA2;
224
 
225
WAIT_NACK:
226
        // If we're not seeing a nack and there is a channel selected, then the
227
        // cache tag must not have updated correctly.
228
        // For writes, assume a nack by now.
229
        next_state <= IDLE;
230
        /*
231
        case(ch)
232
        3'd0:   if (ne_acki0) next_state <= IDLE;
233
        3'd1:   if (ne_acki1) next_state <= IDLE;
234
        3'd2:   if (ne_acki2) next_state <= IDLE;
235
        3'd3:   if (ne_acki3) next_state <= IDLE;
236
        3'd4:   if (ne_acki4) next_state <= IDLE;
237
        3'd5:   if (ne_acki5) next_state <= IDLE;
238
        3'd6:   if (ne_acki6) next_state <= IDLE;
239
        3'd7:   if (ne_acki7) next_state <= IDLE;
240
        default:        next_state <= IDLE;
241
        endcase
242
        */
243
default:        next_state <= IDLE;
244
endcase
245
 
246
// Is the state machine hung?
247
if (to)
248
        next_state <= IDLE;
249
end
250
 
251
endmodule

powered by: WebSVN 2.1.0

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