| 1 |
2 |
kdv |
/*
|
| 2 |
|
|
* framestore_response.v
|
| 3 |
|
|
*
|
| 4 |
|
|
* Copyright (c) 2007 Koen De Vleeschauwer.
|
| 5 |
|
|
*
|
| 6 |
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
| 7 |
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 8 |
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
| 9 |
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
| 10 |
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
| 11 |
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
| 12 |
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
| 13 |
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
| 14 |
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
| 15 |
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
| 16 |
|
|
* SUCH DAMAGE.
|
| 17 |
|
|
*/
|
| 18 |
|
|
|
| 19 |
|
|
/*
|
| 20 |
|
|
* Frame Store Response. Read response from memory controller.
|
| 21 |
|
|
*
|
| 22 |
|
|
* Receives data read from the memory controller;
|
| 23 |
|
|
* passes data read on to motion compensation or display.
|
| 24 |
|
|
*/
|
| 25 |
|
|
|
| 26 |
|
|
`include "timescale.v"
|
| 27 |
|
|
|
| 28 |
|
|
`undef DEBUG
|
| 29 |
|
|
//`define DEBUG 1
|
| 30 |
|
|
|
| 31 |
|
|
`undef CHECK
|
| 32 |
|
|
//`define CHECK 1
|
| 33 |
|
|
|
| 34 |
|
|
`ifdef __IVERILOG__
|
| 35 |
|
|
`define CHECK 1
|
| 36 |
|
|
`endif
|
| 37 |
|
|
|
| 38 |
|
|
//`define SIMULATION_ONLY
|
| 39 |
|
|
`ifdef __IVERILOG__
|
| 40 |
|
|
`define SIMULATION_ONLY 1
|
| 41 |
|
|
`endif
|
| 42 |
|
|
|
| 43 |
|
|
module framestore_response(rst, clk,
|
| 44 |
|
|
fwd_wr_dta_full, fwd_wr_dta_en, fwd_wr_dta_ack, fwd_wr_dta, fwd_wr_dta_almost_full,
|
| 45 |
|
|
bwd_wr_dta_full, bwd_wr_dta_en, bwd_wr_dta_ack, bwd_wr_dta, bwd_wr_dta_almost_full,
|
| 46 |
|
|
disp_wr_dta_full, disp_wr_dta_en, disp_wr_dta_ack, disp_wr_dta, disp_wr_dta_almost_full,
|
| 47 |
|
|
vbr_wr_full, vbr_wr_en, vbr_wr_ack, vbr_wr_dta, vbr_wr_almost_full,
|
| 48 |
|
|
mem_res_rd_dta, mem_res_rd_en, mem_res_rd_empty, mem_res_rd_valid,
|
| 49 |
|
|
tag_rd_dta, tag_rd_empty, tag_rd_en, tag_rd_valid
|
| 50 |
|
|
);
|
| 51 |
|
|
|
| 52 |
|
|
input rst;
|
| 53 |
|
|
input clk;
|
| 54 |
|
|
/* motion compensation: reading forward reference frame */
|
| 55 |
|
|
input fwd_wr_dta_full;
|
| 56 |
|
|
input fwd_wr_dta_almost_full;
|
| 57 |
|
|
output reg fwd_wr_dta_en;
|
| 58 |
|
|
input fwd_wr_dta_ack;
|
| 59 |
|
|
output reg [63:0]fwd_wr_dta;
|
| 60 |
|
|
/* motion compensation: reading backward reference frame */
|
| 61 |
|
|
input bwd_wr_dta_full;
|
| 62 |
|
|
input bwd_wr_dta_almost_full;
|
| 63 |
|
|
output reg bwd_wr_dta_en;
|
| 64 |
|
|
input bwd_wr_dta_ack;
|
| 65 |
|
|
output reg [63:0]bwd_wr_dta;
|
| 66 |
|
|
/* display: reading reconstructed frame */
|
| 67 |
|
|
input disp_wr_dta_full;
|
| 68 |
|
|
input disp_wr_dta_almost_full;
|
| 69 |
|
|
output reg disp_wr_dta_en;
|
| 70 |
|
|
input disp_wr_dta_ack;
|
| 71 |
|
|
output reg [63:0]disp_wr_dta;
|
| 72 |
|
|
/* video buffer: reading from circular buffer */
|
| 73 |
|
|
input vbr_wr_full;
|
| 74 |
|
|
input vbr_wr_almost_full;
|
| 75 |
|
|
output reg vbr_wr_en;
|
| 76 |
|
|
input vbr_wr_ack;
|
| 77 |
|
|
output reg [63:0]vbr_wr_dta;
|
| 78 |
|
|
|
| 79 |
|
|
/* memory response fifo */
|
| 80 |
|
|
input [63:0]mem_res_rd_dta;
|
| 81 |
|
|
output reg mem_res_rd_en;
|
| 82 |
|
|
input mem_res_rd_empty;
|
| 83 |
|
|
input mem_res_rd_valid;
|
| 84 |
|
|
|
| 85 |
|
|
/* tag fifo */
|
| 86 |
|
|
input [2:0]tag_rd_dta;
|
| 87 |
|
|
input tag_rd_empty;
|
| 88 |
|
|
output reg tag_rd_en;
|
| 89 |
|
|
input tag_rd_valid;
|
| 90 |
|
|
|
| 91 |
|
|
`include "mem_codes.v"
|
| 92 |
|
|
|
| 93 |
|
|
parameter [2:0]
|
| 94 |
|
|
STATE_INIT = 4'h0,
|
| 95 |
|
|
STATE_FLUSH = 4'h1,
|
| 96 |
|
|
STATE_WAIT = 4'h2,
|
| 97 |
|
|
STATE_READ = 4'h3,
|
| 98 |
|
|
STATE_WRITE = 4'h4;
|
| 99 |
|
|
|
| 100 |
|
|
reg [2:0]state;
|
| 101 |
|
|
reg [2:0]next;
|
| 102 |
|
|
|
| 103 |
|
|
reg [15:0]flush_counter;
|
| 104 |
|
|
|
| 105 |
|
|
always @(posedge clk)
|
| 106 |
|
|
if (~rst) flush_counter <= 0;
|
| 107 |
|
|
else if (state == STATE_FLUSH) flush_counter <= flush_counter + 16'd1;
|
| 108 |
|
|
else flush_counter <= flush_counter;
|
| 109 |
|
|
|
| 110 |
|
|
wire fifos_not_ready = fwd_wr_dta_full || bwd_wr_dta_full || disp_wr_dta_full || vbr_wr_full || tag_rd_empty || mem_res_rd_empty;
|
| 111 |
|
|
wire fifos_ready = ~fifos_not_ready;
|
| 112 |
|
|
|
| 113 |
|
|
/* next state logic */
|
| 114 |
|
|
always @*
|
| 115 |
|
|
case (state)
|
| 116 |
|
|
`ifdef SIMULATION_ONLY
|
| 117 |
|
|
STATE_INIT: next = STATE_WAIT;
|
| 118 |
|
|
`else
|
| 119 |
|
|
STATE_INIT: next = STATE_FLUSH;
|
| 120 |
|
|
`endif
|
| 121 |
|
|
|
| 122 |
|
|
STATE_FLUSH: if (flush_counter == 16'hffff) next = STATE_WAIT; // Flush any data in the memory response fifo's.
|
| 123 |
|
|
else next = STATE_FLUSH;
|
| 124 |
|
|
|
| 125 |
|
|
STATE_WAIT: if (fifos_not_ready) next = STATE_WAIT; // wait until all fifos available
|
| 126 |
|
|
else next = STATE_READ;
|
| 127 |
|
|
|
| 128 |
|
|
STATE_READ: next = STATE_WRITE;
|
| 129 |
|
|
|
| 130 |
|
|
STATE_WRITE: next = STATE_WAIT;
|
| 131 |
|
|
|
| 132 |
|
|
default next = STATE_WAIT;
|
| 133 |
|
|
|
| 134 |
|
|
endcase
|
| 135 |
|
|
|
| 136 |
|
|
/* state */
|
| 137 |
|
|
always @(posedge clk)
|
| 138 |
|
|
if(~rst) state <= STATE_INIT;
|
| 139 |
|
|
else state <= next;
|
| 140 |
|
|
|
| 141 |
|
|
/*
|
| 142 |
|
|
* read from memory response and tag fifos
|
| 143 |
|
|
*/
|
| 144 |
|
|
|
| 145 |
|
|
always @(posedge clk)
|
| 146 |
|
|
if (~rst) mem_res_rd_en <= 1'b0;
|
| 147 |
|
|
else if (state == STATE_FLUSH) mem_res_rd_en <= 1'b1;
|
| 148 |
|
|
else if (state == STATE_READ) mem_res_rd_en <= fifos_ready;
|
| 149 |
|
|
else mem_res_rd_en <= 1'b0;
|
| 150 |
|
|
|
| 151 |
|
|
always @(posedge clk)
|
| 152 |
|
|
if (~rst) tag_rd_en <= 1'b0;
|
| 153 |
|
|
else if (state == STATE_READ) tag_rd_en <= fifos_ready;
|
| 154 |
|
|
else tag_rd_en <= 1'b0;
|
| 155 |
|
|
|
| 156 |
|
|
/*
|
| 157 |
|
|
* second stage: if successful read from memory response fifo, write memory response data to fifo corresponding to tag (fwd, bwd, disp or vbr).
|
| 158 |
|
|
*/
|
| 159 |
|
|
|
| 160 |
|
|
always @(posedge clk)
|
| 161 |
|
|
if (~rst) fwd_wr_dta_en <= 1'b0;
|
| 162 |
|
|
else fwd_wr_dta_en <= (tag_rd_dta == TAG_FWD) && tag_rd_valid;
|
| 163 |
|
|
|
| 164 |
|
|
always @(posedge clk)
|
| 165 |
|
|
if (~rst) fwd_wr_dta <= 64'b0;
|
| 166 |
|
|
else if (mem_res_rd_valid) fwd_wr_dta <= mem_res_rd_dta;
|
| 167 |
|
|
else fwd_wr_dta <= fwd_wr_dta;
|
| 168 |
|
|
|
| 169 |
|
|
always @(posedge clk)
|
| 170 |
|
|
if (~rst) bwd_wr_dta_en <= 1'b0;
|
| 171 |
|
|
else bwd_wr_dta_en <= (tag_rd_dta == TAG_BWD) && tag_rd_valid;
|
| 172 |
|
|
|
| 173 |
|
|
always @(posedge clk)
|
| 174 |
|
|
if (~rst) bwd_wr_dta <= 64'b0;
|
| 175 |
|
|
else if (mem_res_rd_valid) bwd_wr_dta <= mem_res_rd_dta;
|
| 176 |
|
|
else bwd_wr_dta <= bwd_wr_dta;
|
| 177 |
|
|
|
| 178 |
|
|
always @(posedge clk)
|
| 179 |
|
|
if (~rst) disp_wr_dta_en <= 1'b0;
|
| 180 |
|
|
else disp_wr_dta_en <= (tag_rd_dta == TAG_DISP) && tag_rd_valid;
|
| 181 |
|
|
|
| 182 |
|
|
always @(posedge clk)
|
| 183 |
|
|
if (~rst) disp_wr_dta <= 64'b0;
|
| 184 |
|
|
else if (mem_res_rd_valid) disp_wr_dta <= mem_res_rd_dta;
|
| 185 |
|
|
else disp_wr_dta <= disp_wr_dta;
|
| 186 |
|
|
|
| 187 |
|
|
always @(posedge clk)
|
| 188 |
|
|
if (~rst) vbr_wr_en <= 1'b0;
|
| 189 |
|
|
else vbr_wr_en <= (tag_rd_dta == TAG_VBUF) && tag_rd_valid;
|
| 190 |
|
|
|
| 191 |
|
|
always @(posedge clk)
|
| 192 |
|
|
if (~rst) vbr_wr_dta <= 64'b0;
|
| 193 |
|
|
else if (mem_res_rd_valid) vbr_wr_dta <= mem_res_rd_dta;
|
| 194 |
|
|
else vbr_wr_dta <= vbr_wr_dta;
|
| 195 |
|
|
|
| 196 |
|
|
`ifdef DEBUG
|
| 197 |
|
|
|
| 198 |
|
|
always @(posedge clk)
|
| 199 |
|
|
case (state)
|
| 200 |
|
|
STATE_INIT: #0 $display("%m STATE_INIT");
|
| 201 |
|
|
STATE_WAIT: #0 $display("%m STATE_WAIT");
|
| 202 |
|
|
STATE_FLUSH: #0 $display("%m STATE_FLUSH");
|
| 203 |
|
|
STATE_READ: #0 $display("%m STATE_READ");
|
| 204 |
|
|
STATE_WRITE: #0 $display("%m STATE_WRITE");
|
| 205 |
|
|
default #0 $display("%m *** Error: unknown state %d", state);
|
| 206 |
|
|
endcase
|
| 207 |
|
|
|
| 208 |
|
|
always @(posedge clk)
|
| 209 |
|
|
$strobe("%m\tmem_res_rd_dta: %h mem_res_rd_valid: %h tag_rd_dta: %h tag_rd_valid: %h fifos_not_ready: %h mem_res_rd_en: %h", mem_res_rd_dta, mem_res_rd_valid, tag_rd_dta, tag_rd_valid, fifos_not_ready, mem_res_rd_en);
|
| 210 |
|
|
|
| 211 |
|
|
always @(posedge clk)
|
| 212 |
|
|
begin
|
| 213 |
|
|
$strobe("%m\tfwd_wr_dta: %h fwd_wr_dta_en: %h", fwd_wr_dta, fwd_wr_dta_en);
|
| 214 |
|
|
$strobe("%m\tbwd_wr_dta: %h bwd_wr_dta_en: %h", bwd_wr_dta, bwd_wr_dta_en);
|
| 215 |
|
|
$strobe("%m\tdisp_wr_dta: %h disp_wr_dta_en: %h", disp_wr_dta, disp_wr_dta_en);
|
| 216 |
|
|
$strobe("%m\tvbr_wr_dta: %h vbr_wr_en: %h", vbr_wr_dta, vbr_wr_en);
|
| 217 |
|
|
end
|
| 218 |
|
|
|
| 219 |
|
|
always @(posedge clk)
|
| 220 |
|
|
if (tag_rd_valid)
|
| 221 |
|
|
case (tag_rd_dta)
|
| 222 |
|
|
TAG_FWD: #0 $display ("%m\ttag_rd_dta: fwd");
|
| 223 |
|
|
TAG_BWD: #0 $display ("%m\ttag_rd_dta: bwd");
|
| 224 |
|
|
TAG_DISP: #0 $display ("%m\ttag_rd_dta: disp");
|
| 225 |
|
|
TAG_VBUF: #0 $display ("%m\ttag_rd_dta: vbuf");
|
| 226 |
|
|
default: #0 $display ("%m\t*** error: unknown tag %d ***", tag_rd_dta);
|
| 227 |
|
|
endcase
|
| 228 |
|
|
|
| 229 |
|
|
`endif
|
| 230 |
|
|
|
| 231 |
|
|
`ifdef CHECK
|
| 232 |
|
|
always @(posedge clk)
|
| 233 |
|
|
if (fwd_wr_dta_full) #0 $display ("%m\t*** warning: memory stall possible: fwd_wr_dta_full ***");
|
| 234 |
|
|
|
| 235 |
|
|
always @(posedge clk)
|
| 236 |
|
|
if (bwd_wr_dta_full) #0 $display ("%m\t*** warning: memory stall possible: bwd_wr_dta_full ***");
|
| 237 |
|
|
|
| 238 |
|
|
always @(posedge clk)
|
| 239 |
|
|
if (disp_wr_dta_full) #0 $display ("%m\t*** warning: memory stall possible: disp_wr_dta_full ***");
|
| 240 |
|
|
|
| 241 |
|
|
always @(posedge clk)
|
| 242 |
|
|
if (vbr_wr_full) #0 $display ("%m\t*** warning: memory stall possible: vbr_wr_full ***");
|
| 243 |
|
|
|
| 244 |
|
|
/*
|
| 245 |
|
|
* Should never happen, but doesn't hurt to check.
|
| 246 |
|
|
*/
|
| 247 |
|
|
|
| 248 |
|
|
always @(posedge clk)
|
| 249 |
|
|
if ((state == STATE_READ) && ((tag_rd_valid && ~mem_res_rd_valid) || (mem_res_rd_valid && ~tag_rd_valid)))
|
| 250 |
|
|
begin
|
| 251 |
|
|
#0 $display("%m\t*** error: tag and mem_res fifo unsynchronized tag_rd_valid: %d mem_res_rd_valid: %d ***", tag_rd_valid, mem_res_rd_valid);
|
| 252 |
|
|
$stop;
|
| 253 |
|
|
end
|
| 254 |
|
|
|
| 255 |
|
|
always @(posedge clk)
|
| 256 |
|
|
if (tag_rd_valid && (tag_rd_dta != TAG_FWD) && (tag_rd_dta != TAG_BWD) && (tag_rd_dta != TAG_DISP) && (tag_rd_dta != TAG_VBUF))
|
| 257 |
|
|
begin
|
| 258 |
|
|
#0 $display("%m\t*** error: unknown tag %d ***", tag_rd_dta);
|
| 259 |
|
|
$stop;
|
| 260 |
|
|
end
|
| 261 |
|
|
|
| 262 |
|
|
`endif
|
| 263 |
|
|
endmodule
|
| 264 |
|
|
/* not truncated */
|