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 7

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 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 7 robfinch
        num_strips, req_strip_cnt, resp_strip_cnt, rd_data_valid);
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
input wb_write_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
 
57 7 robfinch
mpmc10_state_t next_state;
58 5 robfinch
 
59
always_ff @(posedge clk)
60
        state <= next_state;
61
 
62
always_comb
63 7 robfinch
if (rst)
64
        next_state <= IDLE;
65 5 robfinch
else begin
66
        case(state)
67 7 robfinch
        IDLE:
68
                if (!fifo_empty && !rd_rst_busy && calib_complete)
69
                        next_state <= PRESET1;
70 5 robfinch
                else
71 7 robfinch
                        next_state <= IDLE;
72
        PRESET1:
73
                next_state <= PRESET2;
74
        PRESET2:
75
                next_state <= PRESET3;
76
        PRESET3:
77 5 robfinch
                if (fifo_out.stb & fifo_out.we)
78 7 robfinch
                        next_state <= WRITE_DATA0;
79 5 robfinch
                else
80 7 robfinch
                        next_state <= READ_DATA0;
81 5 robfinch
        // Write data to the data fifo
82
        // Write occurs when app_wdf_wren is true and app_wdf_rdy is true
83 7 robfinch
        WRITE_DATA0:
84 5 robfinch
                // Issue a write command if the fifo is full.
85
        //      if (!app_wdf_rdy)
86
        //              next_state <= WRITE_DATA1;
87
        //      else
88
                if (wdf_rdy)// && req_strip_cnt==num_strips)
89 7 robfinch
                        next_state <= WRITE_DATA1;
90 5 robfinch
                else
91 7 robfinch
                        next_state <= WRITE_DATA0;
92
        WRITE_DATA1:
93
                next_state <= WRITE_DATA2;
94
        WRITE_DATA2:
95 5 robfinch
                if (rdy)
96 7 robfinch
                        next_state <= WRITE_DATA3;
97 5 robfinch
                else
98 7 robfinch
                        next_state <= WRITE_DATA2;
99
        WRITE_DATA3:
100
                next_state <= IDLE;
101 5 robfinch
 
102
        // There could be multiple read requests submitted before any response occurs.
103
        // Stay in the SET_CMD_RD until all requested strips have been processed.
104 7 robfinch
        READ_DATA0:
105
                next_state <= READ_DATA1;
106 5 robfinch
        // Could it take so long to do the request that we start getting responses
107
        // back?
108 7 robfinch
        READ_DATA1:
109 5 robfinch
                if (rdy && req_strip_cnt==num_strips)
110 7 robfinch
                        next_state <= READ_DATA2;
111 5 robfinch
                else
112 7 robfinch
                        next_state <= READ_DATA1;
113 5 robfinch
        // Wait for incoming responses, but only for so long to prevent a hang.
114 7 robfinch
        READ_DATA2:
115 5 robfinch
                if (rd_data_valid && resp_strip_cnt==num_strips)
116 7 robfinch
                        next_state <= WAIT_NACK;
117 5 robfinch
                else
118 7 robfinch
                        next_state <= READ_DATA2;
119 5 robfinch
 
120 7 robfinch
        WAIT_NACK:
121 5 robfinch
                // If we're not seeing a nack and there is a channel selected, then the
122
                // cache tag must not have updated correctly.
123
                // For writes, assume a nack by now.
124 7 robfinch
                next_state <= IDLE;
125 5 robfinch
 
126 7 robfinch
        default:        next_state <= IDLE;
127 5 robfinch
        endcase
128
 
129 7 robfinch
        // Is the state machine hung? Do not time out during calibration.
130
        if (to && calib_complete)
131
                next_state <= IDLE;
132 5 robfinch
end
133
 
134
endmodule

powered by: WebSVN 2.1.0

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