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

Subversion Repositories mpmc8

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

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

powered by: WebSVN 2.1.0

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