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

Subversion Repositories mpmc8

[/] [mpmc8/] [trunk/] [rtl/] [mpmc10/] [mpmc10_state_machine.sv] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 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 mpmc10_pkg::*;
38
 
39
module mpmc10_state_machine(rst, clk, to, rdy, wdf_rdy, fifo_empty, rd_fifo, fifo_out, state,
40
        num_strips, req_strip_cnt, resp_strip_cnt, rd_data_valid, wway);
41
input rst;
42
input clk;
43
input to;                                                       // state machine time-out
44
input rdy;
45
input wdf_rdy;
46
input fifo_empty;
47
output reg rd_fifo;
48
input axi_request_readwrite256_t fifo_out;
49
output reg [3:0] state;
50
input [5:0] num_strips;
51
input [5:0] req_strip_cnt;
52
input [5:0] resp_strip_cnt;
53
input rd_data_valid;
54
output reg [1:0] wway;
55
 
56
reg [3:0] next_state;
57
reg next_rd_fifo;
58
 
59
always_ff @(posedge clk)
60
        state <= next_state;
61
always_ff @(posedge clk)
62
        rd_fifo <= next_rd_fifo;
63
always_ff @(posedge clk)
64
if (rst)
65
        wway <= 2'd0;
66
else begin
67
        if (state==PRESET1)
68
                wway <= wway + 2'd1;
69
end
70
 
71
always_comb
72
if (rst) begin
73
        next_state <= IDLE;
74
        next_rd_fifo <= 1'b0;
75
end
76
else begin
77
        next_rd_fifo <= 1'b0;
78
        case(state)
79
        IDLE:
80
                begin
81
                        if (!fifo_empty) begin
82
                                next_rd_fifo <= 1'b1;
83
                                next_state <= PRESET1;
84
                        end
85
                end
86
        PRESET1:
87
                next_state <= PRESET2;
88
        PRESET2:
89
                next_state <= PRESET3;
90
        PRESET3:
91
                if (fifo_out.write.WVALID)
92
                        next_state <= WRITE_DATA0;
93
                else
94
                        next_state <= READ_DATA0;
95
        // Write data to the data fifo
96
        // Write occurs when app_wdf_wren is true and app_wdf_rdy is true
97
        WRITE_DATA0:
98
                // Issue a write command if the fifo is full.
99
        //      if (!app_wdf_rdy)
100
        //              next_state <= WRITE_DATA1;
101
        //      else
102
                if (wdf_rdy)// && req_strip_cnt==num_strips)
103
                        next_state <= WRITE_DATA1;
104
                else
105
                        next_state <= WRITE_DATA0;
106
        WRITE_DATA1:
107
                next_state <= WRITE_DATA2;
108
        WRITE_DATA2:
109
                if (rdy)
110
                        next_state <= WRITE_DATA3;
111
                else
112
                        next_state <= WRITE_DATA2;
113
        WRITE_DATA3:
114
                next_state <= IDLE;
115
 
116
        // There could be multiple read requests submitted before any response occurs.
117
        // Stay in the SET_CMD_RD until all requested strips have been processed.
118
        READ_DATA0:
119
                next_state <= READ_DATA1;
120
        // Could it take so long to do the request that we start getting responses
121
        // back?
122
        READ_DATA1:
123
                if (rdy && req_strip_cnt==num_strips)
124
                        next_state <= READ_DATA2;
125
                else
126
                        next_state <= READ_DATA1;
127
        // Wait for incoming responses, but only for so long to prevent a hang.
128
        READ_DATA2:
129
                if (rd_data_valid && resp_strip_cnt==num_strips)
130
                        next_state <= WAIT_NACK;
131
                else
132
                        next_state <= READ_DATA2;
133
 
134
        WAIT_NACK:
135
                // If we're not seeing a nack and there is a channel selected, then the
136
                // cache tag must not have updated correctly.
137
                // For writes, assume a nack by now.
138
                next_state <= IDLE;
139
 
140
        default:        next_state <= IDLE;
141
        endcase
142
 
143
        // Is the state machine hung?
144
        if (to)
145
                next_state <= IDLE;
146
end
147
 
148
endmodule

powered by: WebSVN 2.1.0

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