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 11

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 robfinch
`timescale 1ns / 1ps
2
// ============================================================================
3
//        __
4 11 robfinch
//   \\__/ o\    (C) 2015-2023  Robert Finch, Waterloo
5 5 robfinch
//    \  __ /    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 7 robfinch
module mpmc10_state_machine_wb(rst, clk, calib_complete, to, rdy, wdf_rdy, fifo_empty,
40 5 robfinch
        rd_rst_busy, fifo_out, state,
41 11 robfinch
        num_strips, req_strip_cnt, resp_strip_cnt, rd_data_valid, rmw_hit);
42 5 robfinch
input rst;
43
input clk;
44 7 robfinch
input calib_complete;
45 5 robfinch
input to;                                                       // state machine time-out
46
input rdy;
47
input wdf_rdy;
48
input fifo_empty;
49
input rd_rst_busy;
50 11 robfinch
input wb_cmd_request128_t fifo_out;
51 7 robfinch
output mpmc10_state_t state;
52 5 robfinch
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 11 robfinch
input rmw_hit;
57 5 robfinch
 
58 7 robfinch
mpmc10_state_t next_state;
59 5 robfinch
 
60
always_ff @(posedge clk)
61
        state <= next_state;
62
 
63
always_comb
64 7 robfinch
if (rst)
65
        next_state <= IDLE;
66 5 robfinch
else begin
67
        case(state)
68 7 robfinch
        IDLE:
69
                if (!fifo_empty && !rd_rst_busy && calib_complete)
70
                        next_state <= PRESET1;
71 5 robfinch
                else
72 7 robfinch
                        next_state <= IDLE;
73
        PRESET1:
74
                next_state <= PRESET2;
75
        PRESET2:
76
                next_state <= PRESET3;
77
        PRESET3:
78 11 robfinch
                if (fifo_out.stb && fifo_out.cmd==CMD_STORE)
79 7 robfinch
                        next_state <= WRITE_DATA0;
80 5 robfinch
                else
81 7 robfinch
                        next_state <= READ_DATA0;
82 11 robfinch
        // Write command to the command fifo
83
        // Write occurs when app_rdy is true
84 7 robfinch
        WRITE_DATA0:
85 11 robfinch
                if (rdy)// && req_strip_cnt==num_strips)
86 7 robfinch
                        next_state <= WRITE_DATA1;
87 5 robfinch
                else
88 7 robfinch
                        next_state <= WRITE_DATA0;
89
        WRITE_DATA1:
90
                next_state <= WRITE_DATA2;
91
        WRITE_DATA2:
92 5 robfinch
                if (rdy)
93 7 robfinch
                        next_state <= WRITE_DATA3;
94 5 robfinch
                else
95 7 robfinch
                        next_state <= WRITE_DATA2;
96 11 robfinch
        // Write data to the data fifo
97
        // Write occurs when app_wdf_wren is true and app_wdf_rdy is true
98 7 robfinch
        WRITE_DATA3:
99 11 robfinch
                if (wdf_rdy)
100
                        next_state <= IDLE;
101
                else
102
                        next_state <= WRITE_DATA3;
103 5 robfinch
 
104
        // There could be multiple read requests submitted before any response occurs.
105
        // Stay in the SET_CMD_RD until all requested strips have been processed.
106 7 robfinch
        READ_DATA0:
107
                next_state <= READ_DATA1;
108 5 robfinch
        // Could it take so long to do the request that we start getting responses
109
        // back?
110 7 robfinch
        READ_DATA1:
111 5 robfinch
                if (rdy && req_strip_cnt==num_strips)
112 7 robfinch
                        next_state <= READ_DATA2;
113 5 robfinch
                else
114 7 robfinch
                        next_state <= READ_DATA1;
115 5 robfinch
        // Wait for incoming responses, but only for so long to prevent a hang.
116 7 robfinch
        READ_DATA2:
117 11 robfinch
                if (rd_data_valid && resp_strip_cnt==num_strips) begin
118
                        case(fifo_out.cmd)
119
                        CMD_LOAD,CMD_LOADZ:
120
                                next_state <= WAIT_NACK;
121
                        CMD_ADD,CMD_OR,CMD_AND,CMD_EOR,CMD_ASL,CMD_LSR,
122
                        CMD_MIN,CMD_MAX,CMD_MINU,CMD_MAXU,CMD_CAS:
123
                                next_state <= ALU;
124
                        default:
125
                                next_state <= WAIT_NACK;
126
                        endcase
127
                end
128 5 robfinch
                else
129 7 robfinch
                        next_state <= READ_DATA2;
130 11 robfinch
 
131
        ALU:
132
                if (rmw_hit)
133
                        next_state <= ALU1;
134
        ALU1:
135
                next_state <= ALU2;
136
        ALU2:
137
                next_state <= ALU3;
138
        ALU3:
139
                next_state <= ALU4;
140
        ALU4:
141
                next_state <= WRITE_TRAMP1;
142
 
143
        WRITE_TRAMP1:
144
                next_state <= WRITE_DATA0;
145 5 robfinch
 
146 7 robfinch
        WAIT_NACK:
147 5 robfinch
                // If we're not seeing a nack and there is a channel selected, then the
148
                // cache tag must not have updated correctly.
149
                // For writes, assume a nack by now.
150 7 robfinch
                next_state <= IDLE;
151 5 robfinch
 
152 7 robfinch
        default:        next_state <= IDLE;
153 5 robfinch
        endcase
154
 
155 7 robfinch
        // Is the state machine hung? Do not time out during calibration.
156
        if (to && calib_complete)
157
                next_state <= IDLE;
158 5 robfinch
end
159
 
160
endmodule

powered by: WebSVN 2.1.0

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